Skip to content

Core API Reference

import { Tabs, TabItem, Aside } from ‘@astrojs/starlight/components’;

The @ecuabyte/cortex-core package provides the fundamental building blocks for local context management.

MemoryStore

The primary class for managing persistent memories in SQLite.

add(memory)

Adds a new memory to the persistent store.

Parameters:

  • content (string): The memory payload.
  • type (MemoryType): One of fact, decision, code, config, note.
  • source (string): Origin of the memory (e.g., file path).
  • tags (string[]): Optional categorization tags.
```typescript import { MemoryStore } from '@ecuabyte/cortex-core'; const store = new MemoryStore(); const id = await store.add({ content: 'Use HSL for brand colors', type: 'decision', source: 'branding.css' }); ``` ```bash cortex add -c "Use HSL for brand colors" -t decision -s branding.css ```

search(query, options)

Performs an FTS5 keyword search.

Options:

  • type (MemoryType): Filter by type.
  • limit (number): Max results (default: 10).

ContextRouter

Intelligently selects relevant context for a specific task using semantic scoring.

route(options)

Options:

  • task (string): The goal description.
  • limit (number): Max items to return.

ContextFuser

Optimizes and merges multiple context sources into a single, token-efficient prompt.

fuse(options)

Options:

  • sources: Array of { type, query, path, weight }.
  • maxTokens: Token limit for the final output.
const result = await fuser.fuse({
sources: [
{ type: 'memory', query: 'auth logic', weight: 1.0 },
{ type: 'file', path: 'src/auth.ts', weight: 0.5 }
],
maxTokens: 2000
});
const context = await router.route({
task: 'Implement user authentication',
limit: 5
});

ContextGuard

DLP (Data Loss Prevention) pipeline for sanitizing AI inputs/outputs.

guard(content, options)

Filters: api_keys, secrets, pii, emails, urls_auth, credit_cards, phone_numbers, ip_addresses.

const result = guard.guard(rawContent, {
filters: ['api_keys', 'secrets'],
mode: 'redact'
});
if (result.wasFiltered) {
console.log(`Detected: ${result.filterDetails.length} items`);
}