@fenixforce/kernel 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/execution-result.d.ts +27 -0
- package/dist/agent-loop.d.ts +55 -0
- package/dist/api/dashboard.d.ts +260 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/middleware.d.ts +46 -0
- package/dist/api/openai-compat.d.ts +163 -0
- package/dist/api/server.d.ts +44 -0
- package/dist/api/streaming.d.ts +15 -0
- package/dist/api/webhook-triggers.d.ts +139 -0
- package/dist/billing/cost-meter.d.ts +123 -0
- package/dist/billing/index.d.ts +2 -0
- package/dist/boot.d.ts +109 -0
- package/dist/channels/discord.d.ts +99 -0
- package/dist/channels/email.d.ts +88 -0
- package/dist/channels/http-api.d.ts +155 -0
- package/dist/channels/index.d.ts +20 -0
- package/dist/channels/mcp-channel.d.ts +75 -0
- package/dist/channels/mobile-hil.d.ts +88 -0
- package/dist/channels/openai-compat.d.ts +42 -0
- package/dist/channels/registry.d.ts +80 -0
- package/dist/channels/signal.d.ts +75 -0
- package/dist/channels/slack.d.ts +115 -0
- package/dist/channels/teams.d.ts +106 -0
- package/dist/channels/telegram.d.ts +164 -0
- package/dist/channels/types.d.ts +71 -0
- package/dist/channels/whatsapp.d.ts +83 -0
- package/dist/checkpoint.d.ts +77 -0
- package/dist/config/canary.d.ts +74 -0
- package/dist/config/constitution.d.ts +57 -0
- package/dist/config/defaults.d.ts +17 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/provider-config.d.ts +29 -0
- package/dist/config/schema.d.ts +118 -0
- package/dist/config/steering-rules.d.ts +28 -0
- package/dist/content/chunker.d.ts +42 -0
- package/dist/content/entity-extractor.d.ts +58 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/ocr.d.ts +79 -0
- package/dist/content/pipeline.d.ts +153 -0
- package/dist/context-overflow.d.ts +19 -0
- package/dist/editions/mobile.d.ts +12 -0
- package/dist/editions/pro.d.ts +12 -0
- package/dist/editions/voices.d.ts +14 -0
- package/dist/events/block-manager.d.ts +37 -0
- package/dist/events/bus.d.ts +39 -0
- package/dist/events/index.d.ts +8 -0
- package/dist/events/session-manager.d.ts +59 -0
- package/dist/events/stream-adapter.d.ts +24 -0
- package/dist/events/types.d.ts +465 -0
- package/dist/events/websocket.d.ts +34 -0
- package/dist/extensions/defaults/05-session-repair.d.ts +6 -0
- package/dist/extensions/defaults/10-logging.d.ts +6 -0
- package/dist/extensions/defaults/15-loop-guard.d.ts +6 -0
- package/dist/extensions/defaults/20-cost-tracking.d.ts +7 -0
- package/dist/extensions/defaults/25-ssrf-protection.d.ts +6 -0
- package/dist/extensions/defaults/30-rate-limiting.d.ts +6 -0
- package/dist/extensions/defaults/35-shell-bleed.d.ts +6 -0
- package/dist/extensions/defaults/40-observation-capture.d.ts +7 -0
- package/dist/extensions/defaults/45-context-survival.d.ts +6 -0
- package/dist/extensions/defaults/50-context-budget.d.ts +6 -0
- package/dist/extensions/defaults/55-steering-rules.d.ts +7 -0
- package/dist/extensions/defaults/60-quality-gates.d.ts +7 -0
- package/dist/extensions/defaults/65-job-dispatch.d.ts +24 -0
- package/dist/extensions/defaults/70-skill-loader.d.ts +18 -0
- package/dist/extensions/hooks.d.ts +74 -0
- package/dist/extensions/index.d.ts +21 -0
- package/dist/extensions/intervention.d.ts +59 -0
- package/dist/extensions/manager.d.ts +63 -0
- package/dist/extensions/runner.d.ts +63 -0
- package/dist/hooks/hook-manager.d.ts +39 -0
- package/dist/hooks/hook-types.d.ts +60 -0
- package/dist/identity/assembler.d.ts +45 -0
- package/dist/identity/ccc-adapter.d.ts +33 -0
- package/dist/identity/index.d.ts +6 -0
- package/dist/identity/persona-parser.d.ts +24 -0
- package/dist/identity/soul-parser.d.ts +23 -0
- package/dist/identity/user-populator.d.ts +20 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +579 -0
- package/dist/interrupt.d.ts +84 -0
- package/dist/job-queue.d.ts +69 -0
- package/dist/jobs/index.d.ts +12 -0
- package/dist/jobs/memory-queue.d.ts +23 -0
- package/dist/jobs/planned-tasks.d.ts +121 -0
- package/dist/jobs/queue.d.ts +79 -0
- package/dist/jobs/router.d.ts +23 -0
- package/dist/jobs/synthesize-memories.d.ts +26 -0
- package/dist/jobs/types.d.ts +47 -0
- package/dist/jobs/worker-pool.d.ts +25 -0
- package/dist/jobs/worker.d.ts +40 -0
- package/dist/loop/autonomous-controller.d.ts +91 -0
- package/dist/loop/backpressure.d.ts +64 -0
- package/dist/loop/fresh-context.d.ts +48 -0
- package/dist/loop/prd-importer.d.ts +134 -0
- package/dist/loop/stop-controller.d.ts +31 -0
- package/dist/loop-guard.d.ts +32 -0
- package/dist/mcp/tool-executor.d.ts +57 -0
- package/dist/memory/brain-artifacts.d.ts +25 -0
- package/dist/memory/dual-search.d.ts +67 -0
- package/dist/memory/episodic.d.ts +45 -0
- package/dist/memory/index.d.ts +27 -0
- package/dist/memory/knowledge-graph.d.ts +89 -0
- package/dist/memory/markdown-store.d.ts +64 -0
- package/dist/memory/metadata-filter.d.ts +29 -0
- package/dist/memory/mid-conversation-saves.d.ts +17 -0
- package/dist/memory/note-parser.d.ts +34 -0
- package/dist/memory/observation-store.d.ts +36 -0
- package/dist/memory/observation-thresholds.d.ts +26 -0
- package/dist/memory/progressive-search.d.ts +25 -0
- package/dist/memory/synthesis.d.ts +36 -0
- package/dist/memory/tree-index.d.ts +104 -0
- package/dist/memory/write-gate.d.ts +63 -0
- package/dist/mission-control.d.ts +34 -0
- package/dist/pre-classifier-widgets.d.ts +40 -0
- package/dist/pre-classifier.d.ts +19 -0
- package/dist/prompt/context-budget.d.ts +68 -0
- package/dist/prompt/index.d.ts +3 -0
- package/dist/prompt/system-prompt.d.ts +32 -0
- package/dist/prompt/templates.d.ts +11 -0
- package/dist/providers/anthropic.d.ts +24 -0
- package/dist/providers/auto-detect.d.ts +16 -0
- package/dist/providers/auto-discover.d.ts +28 -0
- package/dist/providers/bedrock.d.ts +38 -0
- package/dist/providers/cache-strategy.d.ts +58 -0
- package/dist/providers/circuit-breaker.d.ts +33 -0
- package/dist/providers/cost-meter.d.ts +74 -0
- package/dist/providers/cost-tracking.d.ts +36 -0
- package/dist/providers/google.d.ts +35 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/interface.d.ts +98 -0
- package/dist/providers/json-repair.d.ts +10 -0
- package/dist/providers/key-rotation.d.ts +36 -0
- package/dist/providers/manager.d.ts +64 -0
- package/dist/providers/model-registry.d.ts +50 -0
- package/dist/providers/openai-compatible.d.ts +26 -0
- package/dist/providers/optimization-modes.d.ts +38 -0
- package/dist/providers/provider-manager.d.ts +71 -0
- package/dist/providers/runtime-crud.d.ts +68 -0
- package/dist/providers/sidecar-lifecycle.d.ts +40 -0
- package/dist/providers/stream-wrapper.d.ts +21 -0
- package/dist/providers/structured-verify.d.ts +31 -0
- package/dist/providers/versioning.d.ts +18 -0
- package/dist/quality-gates.d.ts +10 -0
- package/dist/scheduler/engine.d.ts +95 -0
- package/dist/scheduler/index.d.ts +4 -0
- package/dist/scheduler/webhook-handler.d.ts +37 -0
- package/dist/sdk/agent.d.ts +22 -0
- package/dist/sdk/cli.d.ts +2 -0
- package/dist/sdk/client.d.ts +19 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/jobs.d.ts +25 -0
- package/dist/sdk/memory.d.ts +18 -0
- package/dist/sdk/types.d.ts +69 -0
- package/dist/security/approval-gates.d.ts +166 -0
- package/dist/security/content-wrapper.d.ts +38 -0
- package/dist/security/guard-rails.d.ts +6 -0
- package/dist/security/index.d.ts +21 -0
- package/dist/security/instruction-hierarchy.d.ts +109 -0
- package/dist/security/pii-tokenizer.d.ts +30 -0
- package/dist/security/reputation.d.ts +53 -0
- package/dist/security/secret-store.d.ts +41 -0
- package/dist/security/security-engine.d.ts +53 -0
- package/dist/security/shell-bleed.d.ts +15 -0
- package/dist/security/ssrf.d.ts +12 -0
- package/dist/security/taint-tracker.d.ts +63 -0
- package/dist/security/tool-access-control.d.ts +114 -0
- package/dist/session-compaction.d.ts +20 -0
- package/dist/session-orient.d.ts +22 -0
- package/dist/session-repair.d.ts +6 -0
- package/dist/storage/index.d.ts +24 -0
- package/dist/storage/interface.d.ts +245 -0
- package/dist/storage/postgres.d.ts +6 -0
- package/dist/storage/sqlite.d.ts +2 -0
- package/dist/streaming/reasoning.d.ts +67 -0
- package/dist/task-tracker.d.ts +26 -0
- package/dist/testing/action-cache.d.ts +39 -0
- package/dist/testing/incident-eval.d.ts +49 -0
- package/dist/testing/workflow-evals.d.ts +73 -0
- package/dist/tools/access-control.d.ts +60 -0
- package/dist/tools/browser-engine.d.ts +73 -0
- package/dist/tools/builtins/jobs-router.d.ts +7 -0
- package/dist/tools/builtins/tasks-router.d.ts +25 -0
- package/dist/tools/index.d.ts +20 -0
- package/dist/tools/map-reduce.d.ts +64 -0
- package/dist/tools/registry.d.ts +39 -0
- package/dist/tools/router.d.ts +30 -0
- package/dist/tools/routers/browser-router.d.ts +12 -0
- package/dist/tools/routers/code-router.d.ts +34 -0
- package/dist/tools/routers/file-router.d.ts +35 -0
- package/dist/tools/routers/memory-router.d.ts +21 -0
- package/dist/tools/routers/schedule-router.d.ts +31 -0
- package/dist/tools/routers/search-backends.d.ts +47 -0
- package/dist/tools/routers/task-router.d.ts +32 -0
- package/dist/tools/routers/web-router.d.ts +36 -0
- package/dist/tools/skill-discovery.d.ts +32 -0
- package/dist/tools/skill-loader.d.ts +76 -0
- package/dist/tools/skill-types.d.ts +21 -0
- package/dist/voice/audio-intelligence.d.ts +42 -0
- package/dist/voice/barge-in.d.ts +51 -0
- package/dist/voice/index.d.ts +22 -0
- package/dist/voice/marker-parser.d.ts +31 -0
- package/dist/voice/sidecar-manager.d.ts +68 -0
- package/dist/voice/speaker-focus.d.ts +41 -0
- package/dist/voice/speaker-voiceprint.d.ts +47 -0
- package/dist/voice/speech-intent.d.ts +51 -0
- package/dist/voice/speechmatics-stt.d.ts +77 -0
- package/dist/voice/speechmatics-tts.d.ts +39 -0
- package/dist/voice/stt-provider.d.ts +40 -0
- package/dist/voice/transcript.d.ts +19 -0
- package/dist/voice/turn-detection.d.ts +53 -0
- package/dist/wrapup.d.ts +15 -0
- package/package.json +39 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Note } from "./note-parser.js";
|
|
2
|
+
import type { MetadataFilters } from "./metadata-filter.js";
|
|
3
|
+
export interface FileSystem {
|
|
4
|
+
readFile(path: string): Promise<string>;
|
|
5
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
6
|
+
exists(path: string): Promise<boolean>;
|
|
7
|
+
listFiles(dir: string, pattern?: string): Promise<string[]>;
|
|
8
|
+
}
|
|
9
|
+
export interface NoteIndex {
|
|
10
|
+
upsert(permalink: string, metadata: Record<string, unknown>): Promise<void>;
|
|
11
|
+
remove(permalink: string): Promise<void>;
|
|
12
|
+
search(query: string, filters?: MetadataFilters, limit?: number): Promise<NoteIndexResult[]>;
|
|
13
|
+
getByPermalink(permalink: string): Promise<NoteIndexResult | null>;
|
|
14
|
+
}
|
|
15
|
+
export interface NoteIndexResult {
|
|
16
|
+
permalink: string;
|
|
17
|
+
metadata: Record<string, unknown>;
|
|
18
|
+
score?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface FileWatcher {
|
|
21
|
+
watch(dir: string, handler: (filePath: string, event: "change" | "add" | "delete") => void): () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface MarkdownStoreConfig {
|
|
24
|
+
/** Root directory for markdown files. */
|
|
25
|
+
rootDir: string;
|
|
26
|
+
/** File system adapter. */
|
|
27
|
+
fs: FileSystem;
|
|
28
|
+
/** Database index for search. */
|
|
29
|
+
index: NoteIndex;
|
|
30
|
+
/** Optional file watcher for auto-reindex on external edits. */
|
|
31
|
+
watcher?: FileWatcher;
|
|
32
|
+
}
|
|
33
|
+
export type MarkdownStoreEventType = "note:written" | "note:read" | "note:reindexed" | "note:deleted";
|
|
34
|
+
export interface MarkdownStoreEvent {
|
|
35
|
+
type: MarkdownStoreEventType;
|
|
36
|
+
permalink: string;
|
|
37
|
+
timestamp: number;
|
|
38
|
+
}
|
|
39
|
+
export type MarkdownStoreEventHandler = (event: MarkdownStoreEvent) => void;
|
|
40
|
+
export declare class MarkdownStore {
|
|
41
|
+
private config;
|
|
42
|
+
private handlers;
|
|
43
|
+
private watchDisposer?;
|
|
44
|
+
constructor(config: MarkdownStoreConfig);
|
|
45
|
+
/** Write a note: serialize to Markdown, write file, upsert DB index. */
|
|
46
|
+
write(note: Note): Promise<void>;
|
|
47
|
+
/** Read a note from file (source of truth, not DB). */
|
|
48
|
+
read(permalink: string): Promise<Note | null>;
|
|
49
|
+
/** Search: DB for search, file for content. */
|
|
50
|
+
search(query: string, filters?: MetadataFilters, limit?: number): Promise<Note[]>;
|
|
51
|
+
/** Traverse [[WikiLinks]] to specified depth. */
|
|
52
|
+
traverse(permalink: string, depth: number): Promise<Note[]>;
|
|
53
|
+
/** Delete a note and remove from index. */
|
|
54
|
+
delete(permalink: string): Promise<void>;
|
|
55
|
+
/** Subscribe to store events. */
|
|
56
|
+
on(handler: MarkdownStoreEventHandler): () => void;
|
|
57
|
+
/** Stop file watcher and clean up. */
|
|
58
|
+
dispose(): void;
|
|
59
|
+
private traverseRecursive;
|
|
60
|
+
private reindexFile;
|
|
61
|
+
private permalinkToFilePath;
|
|
62
|
+
private filePathToPermalink;
|
|
63
|
+
private emit;
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type FilterValue = string | number | boolean | {
|
|
2
|
+
$in: (string | number)[];
|
|
3
|
+
} | {
|
|
4
|
+
$gt: number | string;
|
|
5
|
+
} | {
|
|
6
|
+
$gte: number | string;
|
|
7
|
+
} | {
|
|
8
|
+
$lt: number | string;
|
|
9
|
+
} | {
|
|
10
|
+
$lte: number | string;
|
|
11
|
+
} | {
|
|
12
|
+
$between: [number | string, number | string];
|
|
13
|
+
} | (string | number)[];
|
|
14
|
+
export type MetadataFilters = Record<string, FilterValue>;
|
|
15
|
+
export interface SQLClause {
|
|
16
|
+
where: string;
|
|
17
|
+
params: unknown[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert MetadataFilters to a PostgreSQL WHERE clause against
|
|
21
|
+
* a jsonb column. Dot notation maps to -> / ->> operators.
|
|
22
|
+
* All filters are AND-combined.
|
|
23
|
+
*/
|
|
24
|
+
export declare function filtersToSQL(filters: MetadataFilters, column?: string, paramOffset?: number): SQLClause;
|
|
25
|
+
/**
|
|
26
|
+
* Evaluate MetadataFilters against an in-memory metadata object.
|
|
27
|
+
* Returns true if all filters match.
|
|
28
|
+
*/
|
|
29
|
+
export declare function matchesFilters(metadata: Record<string, unknown>, filters: MetadataFilters): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StorageAdapter, MemorySegment } from "../storage/interface.js";
|
|
2
|
+
import type { AgentEvent } from "../events/types.js";
|
|
3
|
+
export interface ImmediateSaveInput {
|
|
4
|
+
userId: string;
|
|
5
|
+
content: string;
|
|
6
|
+
immediate: true;
|
|
7
|
+
tags: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ImmediateSaveContext {
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Save a fact directly into MTM, bypassing the async consolidation pipeline.
|
|
14
|
+
* Uses "fact" category with baseline heat for immediate persistence.
|
|
15
|
+
*/
|
|
16
|
+
export declare function immediateMemorySave(storage: StorageAdapter, input: ImmediateSaveInput): Promise<MemorySegment>;
|
|
17
|
+
export declare function immediateMemorySaveWithEvents(storage: StorageAdapter, input: ImmediateSaveInput, context?: ImmediateSaveContext): AsyncGenerator<AgentEvent, MemorySegment>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface NoteFrontmatter {
|
|
2
|
+
title: string;
|
|
3
|
+
type?: string;
|
|
4
|
+
tags?: string[];
|
|
5
|
+
permalink: string;
|
|
6
|
+
status?: string;
|
|
7
|
+
confidence?: number;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface Observation {
|
|
11
|
+
category: string;
|
|
12
|
+
content: string;
|
|
13
|
+
tags: string[];
|
|
14
|
+
context?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface NoteRelation {
|
|
17
|
+
relationType: string;
|
|
18
|
+
targetPermalink: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Note {
|
|
21
|
+
frontmatter: NoteFrontmatter;
|
|
22
|
+
body: string;
|
|
23
|
+
observations: Observation[];
|
|
24
|
+
relations: NoteRelation[];
|
|
25
|
+
raw: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function parseFrontmatter(raw: string): {
|
|
28
|
+
frontmatter: Record<string, unknown>;
|
|
29
|
+
body: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function parseObservations(body: string): Observation[];
|
|
32
|
+
export declare function parseRelations(body: string): NoteRelation[];
|
|
33
|
+
export declare function parseNote(raw: string): Note;
|
|
34
|
+
export declare function serializeNote(note: Note): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StorageAdapter, Observation } from "../storage/interface.js";
|
|
2
|
+
import type { AgentEvent } from "../events/types.js";
|
|
3
|
+
export type ObservationCategory = "factual" | "procedural" | "error" | "preference";
|
|
4
|
+
export interface ObservationInput {
|
|
5
|
+
userId: string;
|
|
6
|
+
conversationId: string;
|
|
7
|
+
content: string;
|
|
8
|
+
category: ObservationCategory;
|
|
9
|
+
/** Optional source tool name */
|
|
10
|
+
source?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ObservationStoreConfig {
|
|
13
|
+
/** Number of accesses before auto-promoting to MTM */
|
|
14
|
+
autoPromoteThreshold: number;
|
|
15
|
+
/** Whether to generate embeddings for observations */
|
|
16
|
+
generateEmbeddings: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_OBSERVATION_CONFIG: ObservationStoreConfig;
|
|
19
|
+
export declare function resetAccessCounts(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Record a new observation from a tool result or user interaction.
|
|
22
|
+
*/
|
|
23
|
+
export declare function recordObservation(storage: StorageAdapter, input: ObservationInput, config?: ObservationStoreConfig): Promise<Observation>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve observations for a user, tracking access counts.
|
|
26
|
+
* Observations that exceed the auto-promote threshold are promoted to MTM.
|
|
27
|
+
*/
|
|
28
|
+
export declare function retrieveObservations(storage: StorageAdapter, userId: string, config?: ObservationStoreConfig): Promise<{
|
|
29
|
+
observations: Observation[];
|
|
30
|
+
promoted: string[];
|
|
31
|
+
}>;
|
|
32
|
+
export declare function recordObservationWithEvents(storage: StorageAdapter, input: ObservationInput, config?: ObservationStoreConfig, sessionId?: string): AsyncGenerator<AgentEvent, Observation>;
|
|
33
|
+
export declare function retrieveObservationsWithEvents(storage: StorageAdapter, userId: string, config?: ObservationStoreConfig, sessionId?: string): AsyncGenerator<AgentEvent, {
|
|
34
|
+
observations: Observation[];
|
|
35
|
+
promoted: string[];
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observation thresholds — checks whether pending observations have
|
|
3
|
+
* crossed review thresholds during session orient.
|
|
4
|
+
*
|
|
5
|
+
* Detects tensions: pairs of pending observations in the same category
|
|
6
|
+
* whose content appears contradictory (one contains a negation keyword
|
|
7
|
+
* relative to the other).
|
|
8
|
+
*/
|
|
9
|
+
import type { StorageAdapter, Observation } from "../storage/interface.js";
|
|
10
|
+
export interface ObservationReviewConfig {
|
|
11
|
+
/** Number of pending observations that triggers a review. */
|
|
12
|
+
pendingThreshold: number;
|
|
13
|
+
/** Number of detected tensions that triggers a review. */
|
|
14
|
+
tensionThreshold: number;
|
|
15
|
+
/** When true, automatically surface review if any threshold is met. */
|
|
16
|
+
autoSurface: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_REVIEW_CONFIG: ObservationReviewConfig;
|
|
19
|
+
export interface ObservationReviewResult {
|
|
20
|
+
shouldReview: boolean;
|
|
21
|
+
pendingCount: number;
|
|
22
|
+
tensions: Observation[];
|
|
23
|
+
}
|
|
24
|
+
/** Two observations in the same category are in tension if one contains a negation word the other lacks. */
|
|
25
|
+
export declare function detectTensions(observations: Observation[]): Observation[];
|
|
26
|
+
export declare function checkObservationThresholds(storage: StorageAdapter, userId: string, config?: ObservationReviewConfig): Promise<ObservationReviewResult>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SearchResult {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
relevance: number;
|
|
5
|
+
source: "keyword" | "embedding";
|
|
6
|
+
}
|
|
7
|
+
export interface ProgressiveSearchConfig {
|
|
8
|
+
localHitThreshold: number;
|
|
9
|
+
localHitMinResults: number;
|
|
10
|
+
maxResults: number;
|
|
11
|
+
}
|
|
12
|
+
export type KeywordSearchFn = (query: string, limit: number) => Promise<SearchResult[]>;
|
|
13
|
+
export type EmbeddingSearchFn = (query: string, limit: number) => Promise<SearchResult[]>;
|
|
14
|
+
export declare class ProgressiveSearch {
|
|
15
|
+
readonly config: ProgressiveSearchConfig;
|
|
16
|
+
private keywordSearch;
|
|
17
|
+
private embeddingSearch;
|
|
18
|
+
constructor(keywordSearch: KeywordSearchFn, embeddingSearch: EmbeddingSearchFn, config?: Partial<ProgressiveSearchConfig>);
|
|
19
|
+
search(query: string): Promise<{
|
|
20
|
+
results: SearchResult[];
|
|
21
|
+
skippedEmbedding: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
meetsLocalHitThreshold(results: SearchResult[]): boolean;
|
|
24
|
+
private mergeResults;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StorageAdapter } from "../storage/interface.js";
|
|
2
|
+
export interface TaskDiary {
|
|
3
|
+
id: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
conversationId: string;
|
|
6
|
+
taskType: string;
|
|
7
|
+
/** Structured log of what happened during execution */
|
|
8
|
+
entries: DiaryEntry[];
|
|
9
|
+
/** Whether this diary has been synthesized */
|
|
10
|
+
synthesized: boolean;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
}
|
|
13
|
+
export interface DiaryEntry {
|
|
14
|
+
timestamp: string;
|
|
15
|
+
action: string;
|
|
16
|
+
result: "success" | "failure" | "skipped";
|
|
17
|
+
detail?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SynthesisResult {
|
|
20
|
+
patterns: SynthesizedPattern[];
|
|
21
|
+
diariesProcessed: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SynthesizedPattern {
|
|
24
|
+
content: string;
|
|
25
|
+
category: string;
|
|
26
|
+
confidence: number;
|
|
27
|
+
}
|
|
28
|
+
export type LLMSynthesizeFn = (prompt: string) => Promise<string>;
|
|
29
|
+
export declare const TASK_DIARY_SCHEMA = "\nCREATE TABLE IF NOT EXISTS task_diaries (\n id TEXT PRIMARY KEY,\n user_id TEXT NOT NULL,\n conversation_id TEXT NOT NULL,\n task_type TEXT NOT NULL,\n entries JSONB NOT NULL DEFAULT '[]',\n synthesized BOOLEAN NOT NULL DEFAULT false,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\n\nCREATE INDEX IF NOT EXISTS idx_task_diaries_user\n ON task_diaries (user_id, synthesized);\nCREATE INDEX IF NOT EXISTS idx_task_diaries_type\n ON task_diaries (task_type);\n";
|
|
30
|
+
export declare function writeTaskDiary(storage: StorageAdapter, input: {
|
|
31
|
+
userId: string;
|
|
32
|
+
conversationId: string;
|
|
33
|
+
taskType: string;
|
|
34
|
+
entries: DiaryEntry[];
|
|
35
|
+
}): Promise<TaskDiary>;
|
|
36
|
+
export declare function synthesizeMemories(storage: StorageAdapter, userId: string, llmSynthesize: LLMSynthesizeFn): Promise<SynthesisResult>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-Indexed RAG — vectorless reasoning-based retrieval using
|
|
3
|
+
* a hierarchical JSON tree index navigated by an LLM.
|
|
4
|
+
*
|
|
5
|
+
* Instead of embedding cosine distance, the LLM reads node summaries
|
|
6
|
+
* and decides which branch to descend. Ideal for structured corpora:
|
|
7
|
+
* language courses (800K+ words, 229 languages), financial reports,
|
|
8
|
+
* legal documents, technical manuals.
|
|
9
|
+
*
|
|
10
|
+
* Two phases:
|
|
11
|
+
* 1. Index generation (one-time, uses utility LLM)
|
|
12
|
+
* 2. Tree search (per query, uses chat LLM)
|
|
13
|
+
*/
|
|
14
|
+
export interface TreeNode {
|
|
15
|
+
/** Unique node identifier. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Human-readable summary of this subtree's content. */
|
|
18
|
+
summary: string;
|
|
19
|
+
/** Page/section range this node covers, e.g. "1-50" or "lessons 1-10". */
|
|
20
|
+
pageRange: string;
|
|
21
|
+
/** Child nodes (empty for leaf nodes). */
|
|
22
|
+
children: TreeNode[];
|
|
23
|
+
/** Full text content (leaf nodes only, null for branch nodes). */
|
|
24
|
+
content: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface TreeIndex {
|
|
27
|
+
/** Root node of the tree. */
|
|
28
|
+
root: TreeNode;
|
|
29
|
+
/** Source document identifier (links to content_sources). */
|
|
30
|
+
sourceId: string;
|
|
31
|
+
/** When this index was generated. */
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
/** Total number of leaf nodes. */
|
|
34
|
+
leafCount: number;
|
|
35
|
+
}
|
|
36
|
+
export interface NavigationStep {
|
|
37
|
+
/** Node ID visited at this step. */
|
|
38
|
+
nodeId: string;
|
|
39
|
+
/** Summary of the node. */
|
|
40
|
+
summary: string;
|
|
41
|
+
/** LLM reasoning for selecting this branch. */
|
|
42
|
+
reasoning: string;
|
|
43
|
+
/** Depth level (0 = root). */
|
|
44
|
+
depth: number;
|
|
45
|
+
}
|
|
46
|
+
export interface TreeSearchResult {
|
|
47
|
+
/** The answer synthesized from leaf content. */
|
|
48
|
+
answer: string;
|
|
49
|
+
/** Navigation path from root to selected leaf(s). */
|
|
50
|
+
path: NavigationStep[];
|
|
51
|
+
/** Leaf nodes selected as relevant. */
|
|
52
|
+
leafNodes: TreeNode[];
|
|
53
|
+
/** Total LLM calls made during navigation. */
|
|
54
|
+
llmCalls: number;
|
|
55
|
+
}
|
|
56
|
+
/** Utility LLM for index generation: summarize text into a short summary. */
|
|
57
|
+
export type SummarizeFn = (text: string, context?: string) => Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Chat LLM for tree navigation: given a query and child summaries,
|
|
60
|
+
* return the indices (0-based) of children to descend into.
|
|
61
|
+
*/
|
|
62
|
+
export type NavigateFn = (query: string, childSummaries: Array<{
|
|
63
|
+
index: number;
|
|
64
|
+
summary: string;
|
|
65
|
+
pageRange: string;
|
|
66
|
+
}>) => Promise<{
|
|
67
|
+
selectedIndices: number[];
|
|
68
|
+
reasoning: string;
|
|
69
|
+
}>;
|
|
70
|
+
export type TreeEventType = "index_start" | "index_node_created" | "index_done" | "retrieval:tree_step" | "retrieval:search_start" | "retrieval:search_done";
|
|
71
|
+
export interface TreeEvent {
|
|
72
|
+
type: TreeEventType;
|
|
73
|
+
timestamp: Date;
|
|
74
|
+
nodeId?: string;
|
|
75
|
+
detail: string;
|
|
76
|
+
}
|
|
77
|
+
export type TreeEventListener = (event: TreeEvent) => void;
|
|
78
|
+
export interface TreeIndexConfig {
|
|
79
|
+
/** LLM for summarization during index building. */
|
|
80
|
+
summarize: SummarizeFn;
|
|
81
|
+
/** LLM for navigation during search. */
|
|
82
|
+
navigate: NavigateFn;
|
|
83
|
+
/** Max children per internal node. Default 8. */
|
|
84
|
+
maxChildrenPerNode?: number;
|
|
85
|
+
/** Max characters per leaf chunk. Default 2000. */
|
|
86
|
+
maxLeafChars?: number;
|
|
87
|
+
/** Max tree depth for search traversal. Default 10. */
|
|
88
|
+
maxDepth?: number;
|
|
89
|
+
}
|
|
90
|
+
export interface TreeIndexManager {
|
|
91
|
+
/** Build a tree index from a document. */
|
|
92
|
+
buildIndex(sourceId: string, text: string): Promise<TreeIndex>;
|
|
93
|
+
/** Search a tree index with LLM-guided navigation. */
|
|
94
|
+
search(index: TreeIndex, query: string): Promise<TreeSearchResult>;
|
|
95
|
+
/** Serialize a tree index to JSON for storage. */
|
|
96
|
+
serialize(index: TreeIndex): string;
|
|
97
|
+
/** Deserialize a tree index from stored JSON. */
|
|
98
|
+
deserialize(json: string): TreeIndex;
|
|
99
|
+
/** Events. */
|
|
100
|
+
on(listener: TreeEventListener): void;
|
|
101
|
+
off(listener: TreeEventListener): void;
|
|
102
|
+
}
|
|
103
|
+
export declare function _resetTreeIds(): void;
|
|
104
|
+
export declare function createTreeIndexManager(config: TreeIndexConfig): TreeIndexManager;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write Gate + Temporal Validity — prevents memory bloat by gating
|
|
3
|
+
* what gets persisted to medium-term memory (MTM).
|
|
4
|
+
*
|
|
5
|
+
* Write Gate: Before persisting any observation to MTM, apply a
|
|
6
|
+
* lightweight utility LLM call: "Will this change how the agent
|
|
7
|
+
* reasons in future sessions?" Binary yes/no. Includes redundancy
|
|
8
|
+
* detection: merges observations expressing the same insight.
|
|
9
|
+
*
|
|
10
|
+
* Temporal Validity: Facts can expire or be superseded. Memory
|
|
11
|
+
* search filters out invalidated facts by default.
|
|
12
|
+
*
|
|
13
|
+
* ~80 lines of logic.
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMProvider } from "../providers/interface.js";
|
|
16
|
+
/** Temporal metadata attached to memory segments and knowledge graph relations. */
|
|
17
|
+
export interface TemporalValidity {
|
|
18
|
+
/** When this fact became valid (defaults to creation time). */
|
|
19
|
+
validFrom: Date;
|
|
20
|
+
/** When this fact was invalidated/superseded (null if still valid). */
|
|
21
|
+
invalidatedAt: Date | null;
|
|
22
|
+
/** ID of the observation that superseded this one, if any. */
|
|
23
|
+
supersededBy: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface WriteGateInput {
|
|
26
|
+
/** The new observation content to evaluate. */
|
|
27
|
+
content: string;
|
|
28
|
+
/** Category of the observation. */
|
|
29
|
+
category: string;
|
|
30
|
+
/** User ID (for scoping existing memories). */
|
|
31
|
+
userId: string;
|
|
32
|
+
}
|
|
33
|
+
export interface WriteGateResult {
|
|
34
|
+
/** Whether the observation should be persisted. */
|
|
35
|
+
persist: boolean;
|
|
36
|
+
/** Reason for the decision. */
|
|
37
|
+
reason: string;
|
|
38
|
+
/** If a redundant existing observation was found, its ID. */
|
|
39
|
+
mergeWith?: string;
|
|
40
|
+
/** Merged content if combining with existing observation. */
|
|
41
|
+
mergedContent?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Existing memory entry for redundancy checking. */
|
|
44
|
+
export interface ExistingMemory {
|
|
45
|
+
id: string;
|
|
46
|
+
content: string;
|
|
47
|
+
category: string;
|
|
48
|
+
}
|
|
49
|
+
export type FetchExistingFn = (userId: string) => Promise<ExistingMemory[]>;
|
|
50
|
+
export interface WriteGateConfig {
|
|
51
|
+
/** Utility LLM provider for gate decisions. */
|
|
52
|
+
provider: LLMProvider;
|
|
53
|
+
/** Function to fetch existing memories for redundancy check. */
|
|
54
|
+
fetchExisting: FetchExistingFn;
|
|
55
|
+
}
|
|
56
|
+
export declare function evaluateWriteGate(input: WriteGateInput, config: WriteGateConfig): Promise<WriteGateResult>;
|
|
57
|
+
export declare function createTemporalValidity(validFrom?: Date): TemporalValidity;
|
|
58
|
+
export declare function invalidate(tv: TemporalValidity, supersededBy?: string): TemporalValidity;
|
|
59
|
+
export declare function isValid(tv: TemporalValidity, asOf?: Date): boolean;
|
|
60
|
+
/** Filter a list of items with temporal validity, keeping only valid ones. */
|
|
61
|
+
export declare function filterValid<T extends {
|
|
62
|
+
temporal?: TemporalValidity;
|
|
63
|
+
}>(items: T[], asOf?: Date): T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mission Control — convenience wrapper around the Dashboard API.
|
|
3
|
+
* Provides a factory that wires the dashboard with sensible defaults
|
|
4
|
+
* for port, base path, and a logActivity shorthand.
|
|
5
|
+
*/
|
|
6
|
+
import type { Dashboard, DashboardConfig } from "./api/dashboard.js";
|
|
7
|
+
import type { ActivityEntry } from "./api/dashboard.js";
|
|
8
|
+
export interface MissionControlConfig {
|
|
9
|
+
/** Dashboard configuration. */
|
|
10
|
+
dashboard?: DashboardConfig;
|
|
11
|
+
/** Port to serve the dashboard API. Default 3100. */
|
|
12
|
+
port?: number;
|
|
13
|
+
/** Base path for dashboard API. Default "/api/v1/dashboard". */
|
|
14
|
+
basePath?: string;
|
|
15
|
+
/** Auth token for dashboard access. */
|
|
16
|
+
authToken?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MissionControl {
|
|
19
|
+
/** The underlying dashboard instance. */
|
|
20
|
+
readonly dashboard: Dashboard;
|
|
21
|
+
/** Port the dashboard serves on. */
|
|
22
|
+
readonly port: number;
|
|
23
|
+
/** Base path. */
|
|
24
|
+
readonly basePath: string;
|
|
25
|
+
/** Log an activity event (convenience). */
|
|
26
|
+
logActivity(eventType: string, summary: string, opts?: {
|
|
27
|
+
channel?: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
status?: ActivityEntry["status"];
|
|
30
|
+
payload?: Record<string, unknown>;
|
|
31
|
+
}): ActivityEntry;
|
|
32
|
+
}
|
|
33
|
+
/** Create a Mission Control instance with dashboard wired up. */
|
|
34
|
+
export declare function createMissionControl(config?: MissionControlConfig): MissionControl;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Widgets — when the pre-classifier detects a query
|
|
3
|
+
* answerable by multiple independent data sources, dispatch
|
|
4
|
+
* parallel tool calls and render results as independent blocks.
|
|
5
|
+
*
|
|
6
|
+
* Example: "What's the weather, news, and AAPL stock?"
|
|
7
|
+
* → 3 parallel widget fetches → 3 independent result blocks.
|
|
8
|
+
*
|
|
9
|
+
* ~60 lines of logic.
|
|
10
|
+
*/
|
|
11
|
+
import type { QueryClassification } from "./events/types.js";
|
|
12
|
+
export interface WidgetSource {
|
|
13
|
+
/** Unique source identifier (e.g. "weather", "news", "stocks"). */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Human-readable label. */
|
|
16
|
+
label: string;
|
|
17
|
+
/** Sub-query extracted for this source. */
|
|
18
|
+
query: string;
|
|
19
|
+
}
|
|
20
|
+
export interface WidgetResult {
|
|
21
|
+
/** Source that produced this result. */
|
|
22
|
+
sourceId: string;
|
|
23
|
+
/** Rendered content block. */
|
|
24
|
+
content: string;
|
|
25
|
+
/** Block type for structured rendering. */
|
|
26
|
+
blockType: "text" | "code" | "citation";
|
|
27
|
+
/** Whether this source succeeded. */
|
|
28
|
+
ok: boolean;
|
|
29
|
+
/** Error message if failed. */
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ParallelWidgetConfig {
|
|
33
|
+
/** Map of source ID → fetch function. */
|
|
34
|
+
sources: Map<string, (query: string) => Promise<string>>;
|
|
35
|
+
/** Maximum concurrent fetches. Default: 5. */
|
|
36
|
+
maxConcurrent?: number;
|
|
37
|
+
}
|
|
38
|
+
export type WidgetDetectFn = (query: string, classification: QueryClassification) => WidgetSource[];
|
|
39
|
+
export declare function detectWidgetSources(query: string, classification: QueryClassification): WidgetSource[];
|
|
40
|
+
export declare function dispatchWidgets(sources: WidgetSource[], config: ParallelWidgetConfig): Promise<WidgetResult[]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-Classifier (G26) — classifies incoming queries before the agent loop.
|
|
3
|
+
*
|
|
4
|
+
* Uses structured output (generateObject) to determine:
|
|
5
|
+
* - Query type (conversation, code, research, memory, creative)
|
|
6
|
+
* - Standalone rewrite for follow-up questions
|
|
7
|
+
* - Skip-agent flag for trivial queries answerable directly
|
|
8
|
+
*
|
|
9
|
+
* Yields query:classified event via the AgentLoopConfig.classifyQuery hook.
|
|
10
|
+
*/
|
|
11
|
+
import type { LLMProvider } from "./providers/interface.js";
|
|
12
|
+
import type { QueryClassificationResult } from "./agent-loop.js";
|
|
13
|
+
/**
|
|
14
|
+
* Create a pre-classifier function using the given provider.
|
|
15
|
+
* Returns a QueryClassifier compatible with AgentLoopConfig.classifyQuery.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createPreClassifier(provider: LLMProvider): (query: string, context: {
|
|
18
|
+
turnNumber?: number;
|
|
19
|
+
}) => Promise<QueryClassificationResult>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context budget — allocates token budget across prompt sections
|
|
3
|
+
* with priority-based distribution and graceful degradation.
|
|
4
|
+
*
|
|
5
|
+
* V1 (backward-compatible): fixed 4-category allocation.
|
|
6
|
+
* V2 (lane-based): dynamic lanes with overflow policies (AIRI ContextUpdate).
|
|
7
|
+
*
|
|
8
|
+
* Priority allocation (after fixed identity block):
|
|
9
|
+
* steering rules 20%
|
|
10
|
+
* memories 40%
|
|
11
|
+
* orient context 20%
|
|
12
|
+
* brain artifacts 20%
|
|
13
|
+
*
|
|
14
|
+
* If a section is empty, its budget is redistributed proportionally
|
|
15
|
+
* among the remaining non-empty sections.
|
|
16
|
+
*/
|
|
17
|
+
export interface BudgetAllocation {
|
|
18
|
+
identity: number;
|
|
19
|
+
steeringRules: number;
|
|
20
|
+
memories: number;
|
|
21
|
+
orientContext: number;
|
|
22
|
+
brainArtifacts: number;
|
|
23
|
+
total: number;
|
|
24
|
+
}
|
|
25
|
+
export interface SectionSizes {
|
|
26
|
+
steeringRules: number;
|
|
27
|
+
memories: number;
|
|
28
|
+
orientContext: number;
|
|
29
|
+
brainArtifacts: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ContextLane {
|
|
32
|
+
/** Unique lane identifier, e.g. "identity", "memory", "browser". */
|
|
33
|
+
id: string;
|
|
34
|
+
/** Module that owns this lane. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** Fraction of totalTokens (0.0 to 1.0). */
|
|
37
|
+
budgetShare: number;
|
|
38
|
+
/** How content is managed: replace fully or append incrementally. */
|
|
39
|
+
strategy: "replace" | "append";
|
|
40
|
+
/** Current content for this lane. */
|
|
41
|
+
content: string;
|
|
42
|
+
/** Higher priority lanes get their full share first. */
|
|
43
|
+
priority: number;
|
|
44
|
+
}
|
|
45
|
+
export type OverflowPolicy = "trim-lowest-priority" | "proportional-shrink";
|
|
46
|
+
export interface ContextBudgetV2 {
|
|
47
|
+
totalTokens: number;
|
|
48
|
+
defaultLanes: ContextLane[];
|
|
49
|
+
dynamicLanes: ContextLane[];
|
|
50
|
+
overflowPolicy: OverflowPolicy;
|
|
51
|
+
}
|
|
52
|
+
export declare function estimateTokens(text: string): number;
|
|
53
|
+
export declare function allocateBudget(totalBudget: number, sectionSizes: SectionSizes): BudgetAllocation;
|
|
54
|
+
export declare function truncateToTokenBudget(text: string, tokenBudget: number): string;
|
|
55
|
+
export declare function createDefaultLanes(): ContextLane[];
|
|
56
|
+
export declare function createBudgetV2(totalTokens: number, overflowPolicy?: OverflowPolicy): ContextBudgetV2;
|
|
57
|
+
/** Register a dynamic lane at runtime (tools, extensions, skills). */
|
|
58
|
+
export declare function registerLane(budget: ContextBudgetV2, lane: ContextLane): void;
|
|
59
|
+
/** Remove a dynamic lane. */
|
|
60
|
+
export declare function unregisterLane(budget: ContextBudgetV2, laneId: string): boolean;
|
|
61
|
+
export interface LaneAllocation {
|
|
62
|
+
laneId: string;
|
|
63
|
+
tokenBudget: number;
|
|
64
|
+
content: string;
|
|
65
|
+
trimmed: boolean;
|
|
66
|
+
}
|
|
67
|
+
/** Allocate tokens across all lanes, applying overflow policy when needed. */
|
|
68
|
+
export declare function allocateLanes(budget: ContextBudgetV2): LaneAllocation[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ANTI_VERBOSITY_MINIMAL, ANTI_VERBOSITY_NORMAL, ANTI_VERBOSITY_DETAILED, VERBOSITY_TEMPLATES, INSTRUCTION_HIERARCHY, BASE_IDENTITY, type VerbosityLevel, } from "./templates.js";
|
|
2
|
+
export { allocateBudget, estimateTokens, truncateToTokenBudget, type BudgetAllocation, type SectionSizes, } from "./context-budget.js";
|
|
3
|
+
export { buildSystemPrompt, type SystemPromptInput, } from "./system-prompt.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System prompt builder — assembles the full system prompt from all
|
|
3
|
+
* context sources with token budget enforcement.
|
|
4
|
+
*
|
|
5
|
+
* Budget allocation (configurable, default 4,000 tokens):
|
|
6
|
+
* Identity block: 800 tokens (from identity files)
|
|
7
|
+
* LPM traits: 400 tokens (user profile / long-term preferences)
|
|
8
|
+
* MTM memories: 1,600 tokens (mid-term memory segments)
|
|
9
|
+
* Steering rules: remaining (always + active conditional)
|
|
10
|
+
* Anti-verbosity: fixed (not counted against budget)
|
|
11
|
+
* Tool descriptions: fixed (not counted against budget)
|
|
12
|
+
* Mode instructions: fixed (not counted against budget)
|
|
13
|
+
* Brain artifacts: shares MTM budget overflow
|
|
14
|
+
*/
|
|
15
|
+
import type { AgentMode } from "../events/types.js";
|
|
16
|
+
import type { ToolDefinition as LLMToolDefinition } from "../providers/interface.js";
|
|
17
|
+
import type { UserProfile, MemorySegment, BrainArtifact, IdentityFile } from "../storage/interface.js";
|
|
18
|
+
import type { OrientResult } from "../session-orient.js";
|
|
19
|
+
import type { VerbosityLevel } from "./templates.js";
|
|
20
|
+
export interface SystemPromptInput {
|
|
21
|
+
verbosity: VerbosityLevel;
|
|
22
|
+
mode: AgentMode;
|
|
23
|
+
tools: LLMToolDefinition[];
|
|
24
|
+
profile: UserProfile | null;
|
|
25
|
+
memories: MemorySegment[];
|
|
26
|
+
orient: OrientResult;
|
|
27
|
+
steeringRules: string[];
|
|
28
|
+
identityFiles?: IdentityFile[];
|
|
29
|
+
brainArtifacts?: BrainArtifact[];
|
|
30
|
+
tokenBudget?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function buildSystemPrompt(input: SystemPromptInput): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt template strings — anti-verbosity presets, identity block,
|
|
3
|
+
* and instruction hierarchy markers.
|
|
4
|
+
*/
|
|
5
|
+
export type VerbosityLevel = "minimal" | "normal" | "detailed";
|
|
6
|
+
export declare const ANTI_VERBOSITY_MINIMAL: string;
|
|
7
|
+
export declare const ANTI_VERBOSITY_NORMAL: string;
|
|
8
|
+
export declare const ANTI_VERBOSITY_DETAILED: string;
|
|
9
|
+
export declare const VERBOSITY_TEMPLATES: Record<VerbosityLevel, string>;
|
|
10
|
+
export declare const INSTRUCTION_HIERARCHY: string;
|
|
11
|
+
export declare const BASE_IDENTITY: string;
|