@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.
Files changed (213) hide show
  1. package/dist/agent/execution-result.d.ts +27 -0
  2. package/dist/agent-loop.d.ts +55 -0
  3. package/dist/api/dashboard.d.ts +260 -0
  4. package/dist/api/index.d.ts +9 -0
  5. package/dist/api/middleware.d.ts +46 -0
  6. package/dist/api/openai-compat.d.ts +163 -0
  7. package/dist/api/server.d.ts +44 -0
  8. package/dist/api/streaming.d.ts +15 -0
  9. package/dist/api/webhook-triggers.d.ts +139 -0
  10. package/dist/billing/cost-meter.d.ts +123 -0
  11. package/dist/billing/index.d.ts +2 -0
  12. package/dist/boot.d.ts +109 -0
  13. package/dist/channels/discord.d.ts +99 -0
  14. package/dist/channels/email.d.ts +88 -0
  15. package/dist/channels/http-api.d.ts +155 -0
  16. package/dist/channels/index.d.ts +20 -0
  17. package/dist/channels/mcp-channel.d.ts +75 -0
  18. package/dist/channels/mobile-hil.d.ts +88 -0
  19. package/dist/channels/openai-compat.d.ts +42 -0
  20. package/dist/channels/registry.d.ts +80 -0
  21. package/dist/channels/signal.d.ts +75 -0
  22. package/dist/channels/slack.d.ts +115 -0
  23. package/dist/channels/teams.d.ts +106 -0
  24. package/dist/channels/telegram.d.ts +164 -0
  25. package/dist/channels/types.d.ts +71 -0
  26. package/dist/channels/whatsapp.d.ts +83 -0
  27. package/dist/checkpoint.d.ts +77 -0
  28. package/dist/config/canary.d.ts +74 -0
  29. package/dist/config/constitution.d.ts +57 -0
  30. package/dist/config/defaults.d.ts +17 -0
  31. package/dist/config/index.d.ts +8 -0
  32. package/dist/config/loader.d.ts +11 -0
  33. package/dist/config/provider-config.d.ts +29 -0
  34. package/dist/config/schema.d.ts +118 -0
  35. package/dist/config/steering-rules.d.ts +28 -0
  36. package/dist/content/chunker.d.ts +42 -0
  37. package/dist/content/entity-extractor.d.ts +58 -0
  38. package/dist/content/index.d.ts +8 -0
  39. package/dist/content/ocr.d.ts +79 -0
  40. package/dist/content/pipeline.d.ts +153 -0
  41. package/dist/context-overflow.d.ts +19 -0
  42. package/dist/editions/mobile.d.ts +12 -0
  43. package/dist/editions/pro.d.ts +12 -0
  44. package/dist/editions/voices.d.ts +14 -0
  45. package/dist/events/block-manager.d.ts +37 -0
  46. package/dist/events/bus.d.ts +39 -0
  47. package/dist/events/index.d.ts +8 -0
  48. package/dist/events/session-manager.d.ts +59 -0
  49. package/dist/events/stream-adapter.d.ts +24 -0
  50. package/dist/events/types.d.ts +465 -0
  51. package/dist/events/websocket.d.ts +34 -0
  52. package/dist/extensions/defaults/05-session-repair.d.ts +6 -0
  53. package/dist/extensions/defaults/10-logging.d.ts +6 -0
  54. package/dist/extensions/defaults/15-loop-guard.d.ts +6 -0
  55. package/dist/extensions/defaults/20-cost-tracking.d.ts +7 -0
  56. package/dist/extensions/defaults/25-ssrf-protection.d.ts +6 -0
  57. package/dist/extensions/defaults/30-rate-limiting.d.ts +6 -0
  58. package/dist/extensions/defaults/35-shell-bleed.d.ts +6 -0
  59. package/dist/extensions/defaults/40-observation-capture.d.ts +7 -0
  60. package/dist/extensions/defaults/45-context-survival.d.ts +6 -0
  61. package/dist/extensions/defaults/50-context-budget.d.ts +6 -0
  62. package/dist/extensions/defaults/55-steering-rules.d.ts +7 -0
  63. package/dist/extensions/defaults/60-quality-gates.d.ts +7 -0
  64. package/dist/extensions/defaults/65-job-dispatch.d.ts +24 -0
  65. package/dist/extensions/defaults/70-skill-loader.d.ts +18 -0
  66. package/dist/extensions/hooks.d.ts +74 -0
  67. package/dist/extensions/index.d.ts +21 -0
  68. package/dist/extensions/intervention.d.ts +59 -0
  69. package/dist/extensions/manager.d.ts +63 -0
  70. package/dist/extensions/runner.d.ts +63 -0
  71. package/dist/hooks/hook-manager.d.ts +39 -0
  72. package/dist/hooks/hook-types.d.ts +60 -0
  73. package/dist/identity/assembler.d.ts +45 -0
  74. package/dist/identity/ccc-adapter.d.ts +33 -0
  75. package/dist/identity/index.d.ts +6 -0
  76. package/dist/identity/persona-parser.d.ts +24 -0
  77. package/dist/identity/soul-parser.d.ts +23 -0
  78. package/dist/identity/user-populator.d.ts +20 -0
  79. package/dist/index.d.ts +227 -0
  80. package/dist/index.js +579 -0
  81. package/dist/interrupt.d.ts +84 -0
  82. package/dist/job-queue.d.ts +69 -0
  83. package/dist/jobs/index.d.ts +12 -0
  84. package/dist/jobs/memory-queue.d.ts +23 -0
  85. package/dist/jobs/planned-tasks.d.ts +121 -0
  86. package/dist/jobs/queue.d.ts +79 -0
  87. package/dist/jobs/router.d.ts +23 -0
  88. package/dist/jobs/synthesize-memories.d.ts +26 -0
  89. package/dist/jobs/types.d.ts +47 -0
  90. package/dist/jobs/worker-pool.d.ts +25 -0
  91. package/dist/jobs/worker.d.ts +40 -0
  92. package/dist/loop/autonomous-controller.d.ts +91 -0
  93. package/dist/loop/backpressure.d.ts +64 -0
  94. package/dist/loop/fresh-context.d.ts +48 -0
  95. package/dist/loop/prd-importer.d.ts +134 -0
  96. package/dist/loop/stop-controller.d.ts +31 -0
  97. package/dist/loop-guard.d.ts +32 -0
  98. package/dist/mcp/tool-executor.d.ts +57 -0
  99. package/dist/memory/brain-artifacts.d.ts +25 -0
  100. package/dist/memory/dual-search.d.ts +67 -0
  101. package/dist/memory/episodic.d.ts +45 -0
  102. package/dist/memory/index.d.ts +27 -0
  103. package/dist/memory/knowledge-graph.d.ts +89 -0
  104. package/dist/memory/markdown-store.d.ts +64 -0
  105. package/dist/memory/metadata-filter.d.ts +29 -0
  106. package/dist/memory/mid-conversation-saves.d.ts +17 -0
  107. package/dist/memory/note-parser.d.ts +34 -0
  108. package/dist/memory/observation-store.d.ts +36 -0
  109. package/dist/memory/observation-thresholds.d.ts +26 -0
  110. package/dist/memory/progressive-search.d.ts +25 -0
  111. package/dist/memory/synthesis.d.ts +36 -0
  112. package/dist/memory/tree-index.d.ts +104 -0
  113. package/dist/memory/write-gate.d.ts +63 -0
  114. package/dist/mission-control.d.ts +34 -0
  115. package/dist/pre-classifier-widgets.d.ts +40 -0
  116. package/dist/pre-classifier.d.ts +19 -0
  117. package/dist/prompt/context-budget.d.ts +68 -0
  118. package/dist/prompt/index.d.ts +3 -0
  119. package/dist/prompt/system-prompt.d.ts +32 -0
  120. package/dist/prompt/templates.d.ts +11 -0
  121. package/dist/providers/anthropic.d.ts +24 -0
  122. package/dist/providers/auto-detect.d.ts +16 -0
  123. package/dist/providers/auto-discover.d.ts +28 -0
  124. package/dist/providers/bedrock.d.ts +38 -0
  125. package/dist/providers/cache-strategy.d.ts +58 -0
  126. package/dist/providers/circuit-breaker.d.ts +33 -0
  127. package/dist/providers/cost-meter.d.ts +74 -0
  128. package/dist/providers/cost-tracking.d.ts +36 -0
  129. package/dist/providers/google.d.ts +35 -0
  130. package/dist/providers/index.d.ts +32 -0
  131. package/dist/providers/interface.d.ts +98 -0
  132. package/dist/providers/json-repair.d.ts +10 -0
  133. package/dist/providers/key-rotation.d.ts +36 -0
  134. package/dist/providers/manager.d.ts +64 -0
  135. package/dist/providers/model-registry.d.ts +50 -0
  136. package/dist/providers/openai-compatible.d.ts +26 -0
  137. package/dist/providers/optimization-modes.d.ts +38 -0
  138. package/dist/providers/provider-manager.d.ts +71 -0
  139. package/dist/providers/runtime-crud.d.ts +68 -0
  140. package/dist/providers/sidecar-lifecycle.d.ts +40 -0
  141. package/dist/providers/stream-wrapper.d.ts +21 -0
  142. package/dist/providers/structured-verify.d.ts +31 -0
  143. package/dist/providers/versioning.d.ts +18 -0
  144. package/dist/quality-gates.d.ts +10 -0
  145. package/dist/scheduler/engine.d.ts +95 -0
  146. package/dist/scheduler/index.d.ts +4 -0
  147. package/dist/scheduler/webhook-handler.d.ts +37 -0
  148. package/dist/sdk/agent.d.ts +22 -0
  149. package/dist/sdk/cli.d.ts +2 -0
  150. package/dist/sdk/client.d.ts +19 -0
  151. package/dist/sdk/index.d.ts +24 -0
  152. package/dist/sdk/jobs.d.ts +25 -0
  153. package/dist/sdk/memory.d.ts +18 -0
  154. package/dist/sdk/types.d.ts +69 -0
  155. package/dist/security/approval-gates.d.ts +166 -0
  156. package/dist/security/content-wrapper.d.ts +38 -0
  157. package/dist/security/guard-rails.d.ts +6 -0
  158. package/dist/security/index.d.ts +21 -0
  159. package/dist/security/instruction-hierarchy.d.ts +109 -0
  160. package/dist/security/pii-tokenizer.d.ts +30 -0
  161. package/dist/security/reputation.d.ts +53 -0
  162. package/dist/security/secret-store.d.ts +41 -0
  163. package/dist/security/security-engine.d.ts +53 -0
  164. package/dist/security/shell-bleed.d.ts +15 -0
  165. package/dist/security/ssrf.d.ts +12 -0
  166. package/dist/security/taint-tracker.d.ts +63 -0
  167. package/dist/security/tool-access-control.d.ts +114 -0
  168. package/dist/session-compaction.d.ts +20 -0
  169. package/dist/session-orient.d.ts +22 -0
  170. package/dist/session-repair.d.ts +6 -0
  171. package/dist/storage/index.d.ts +24 -0
  172. package/dist/storage/interface.d.ts +245 -0
  173. package/dist/storage/postgres.d.ts +6 -0
  174. package/dist/storage/sqlite.d.ts +2 -0
  175. package/dist/streaming/reasoning.d.ts +67 -0
  176. package/dist/task-tracker.d.ts +26 -0
  177. package/dist/testing/action-cache.d.ts +39 -0
  178. package/dist/testing/incident-eval.d.ts +49 -0
  179. package/dist/testing/workflow-evals.d.ts +73 -0
  180. package/dist/tools/access-control.d.ts +60 -0
  181. package/dist/tools/browser-engine.d.ts +73 -0
  182. package/dist/tools/builtins/jobs-router.d.ts +7 -0
  183. package/dist/tools/builtins/tasks-router.d.ts +25 -0
  184. package/dist/tools/index.d.ts +20 -0
  185. package/dist/tools/map-reduce.d.ts +64 -0
  186. package/dist/tools/registry.d.ts +39 -0
  187. package/dist/tools/router.d.ts +30 -0
  188. package/dist/tools/routers/browser-router.d.ts +12 -0
  189. package/dist/tools/routers/code-router.d.ts +34 -0
  190. package/dist/tools/routers/file-router.d.ts +35 -0
  191. package/dist/tools/routers/memory-router.d.ts +21 -0
  192. package/dist/tools/routers/schedule-router.d.ts +31 -0
  193. package/dist/tools/routers/search-backends.d.ts +47 -0
  194. package/dist/tools/routers/task-router.d.ts +32 -0
  195. package/dist/tools/routers/web-router.d.ts +36 -0
  196. package/dist/tools/skill-discovery.d.ts +32 -0
  197. package/dist/tools/skill-loader.d.ts +76 -0
  198. package/dist/tools/skill-types.d.ts +21 -0
  199. package/dist/voice/audio-intelligence.d.ts +42 -0
  200. package/dist/voice/barge-in.d.ts +51 -0
  201. package/dist/voice/index.d.ts +22 -0
  202. package/dist/voice/marker-parser.d.ts +31 -0
  203. package/dist/voice/sidecar-manager.d.ts +68 -0
  204. package/dist/voice/speaker-focus.d.ts +41 -0
  205. package/dist/voice/speaker-voiceprint.d.ts +47 -0
  206. package/dist/voice/speech-intent.d.ts +51 -0
  207. package/dist/voice/speechmatics-stt.d.ts +77 -0
  208. package/dist/voice/speechmatics-tts.d.ts +39 -0
  209. package/dist/voice/stt-provider.d.ts +40 -0
  210. package/dist/voice/transcript.d.ts +19 -0
  211. package/dist/voice/turn-detection.d.ts +53 -0
  212. package/dist/wrapup.d.ts +15 -0
  213. package/package.json +39 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Per-Tool Access Control — tool registry ACL with per-agent,
3
+ * per-edition configuration. Edition manifests declare available
4
+ * tool sets; agents receive a subset of those tools based on
5
+ * their role and explicit grants/denials.
6
+ *
7
+ * Access resolution order:
8
+ * 1. Tool must exist in the registry
9
+ * 2. Tool must be included in the active edition manifest
10
+ * 3. Agent must have access (explicit grant, role default, or wildcard)
11
+ * 4. Tool must not be in the agent's deny list
12
+ *
13
+ * A denied tool always wins over a grant (deny takes precedence).
14
+ */
15
+ export type ToolCategory = "llm" | "web" | "file" | "memory" | "browser" | "media" | "notification" | "admin" | "system";
16
+ export interface ToolDefinition {
17
+ /** Unique tool name (e.g. "file.read", "web.search"). */
18
+ name: string;
19
+ /** Human-readable description. */
20
+ description: string;
21
+ /** Tool category for bulk grants. */
22
+ category: ToolCategory;
23
+ /** Whether this tool has side effects (writes, sends, deletes). */
24
+ sideEffects: boolean;
25
+ /** Optional tags for fine-grained filtering. */
26
+ tags?: string[];
27
+ }
28
+ export type EditionName = "pro" | "mobile" | "voices" | string;
29
+ export interface EditionManifest {
30
+ /** Edition identifier. */
31
+ name: EditionName;
32
+ /** Human-readable label. */
33
+ label: string;
34
+ /** Tool names available in this edition. Use "*" for all. */
35
+ tools: string[];
36
+ /** Tool categories included (expanded to individual tools at check time). */
37
+ categories?: ToolCategory[];
38
+ /** Maximum number of concurrent workers. Informational. */
39
+ maxWorkers?: number;
40
+ }
41
+ export type AgentRole = "admin" | "standard" | "restricted" | "readonly";
42
+ export interface AgentConfig {
43
+ /** Unique agent identifier. */
44
+ agentId: string;
45
+ /** Human-readable name. */
46
+ name?: string;
47
+ /** Agent role — determines default access level. */
48
+ role: AgentRole;
49
+ /** Explicit tool grants (overrides role defaults).
50
+ * Use "*" for all tools, "category:<name>" for category grants. */
51
+ grants?: string[];
52
+ /** Explicit tool denials (always takes precedence over grants). */
53
+ denials?: string[];
54
+ }
55
+ export type AccessVerdict = "allow" | "deny";
56
+ export interface AccessCheckResult {
57
+ verdict: AccessVerdict;
58
+ toolName: string;
59
+ agentId: string;
60
+ edition: EditionName;
61
+ reason: string;
62
+ }
63
+ export type AccessEventType = "tool_registered" | "tool_removed" | "edition_set" | "agent_registered" | "agent_removed" | "access_allowed" | "access_denied";
64
+ export interface AccessEvent {
65
+ type: AccessEventType;
66
+ timestamp: Date;
67
+ detail: string;
68
+ toolName?: string;
69
+ agentId?: string;
70
+ edition?: EditionName;
71
+ }
72
+ export type AccessEventListener = (event: AccessEvent) => void;
73
+ export declare const EDITION_PRO: EditionManifest;
74
+ export declare const EDITION_MOBILE: EditionManifest;
75
+ export declare const EDITION_VOICES: EditionManifest;
76
+ export interface ToolAccessControlConfig {
77
+ /** The active edition manifest. */
78
+ edition: EditionManifest;
79
+ }
80
+ export interface ToolAccessControl {
81
+ /** Register a tool definition. */
82
+ registerTool(tool: ToolDefinition): void;
83
+ /** Remove a tool from the registry. */
84
+ removeTool(name: string): boolean;
85
+ /** Get a tool definition. */
86
+ getTool(name: string): ToolDefinition | undefined;
87
+ /** List all registered tools. */
88
+ listTools(): ToolDefinition[];
89
+ /** List tools by category. */
90
+ listToolsByCategory(category: ToolCategory): ToolDefinition[];
91
+ /** Get the active edition manifest. */
92
+ getEdition(): EditionManifest;
93
+ /** Set/switch the active edition manifest. */
94
+ setEdition(manifest: EditionManifest): void;
95
+ /** Check if a tool is available in the current edition. */
96
+ isToolInEdition(toolName: string): boolean;
97
+ /** List all tools available in the current edition. */
98
+ listEditionTools(): ToolDefinition[];
99
+ /** Register an agent with its access configuration. */
100
+ registerAgent(config: AgentConfig): void;
101
+ /** Remove an agent. */
102
+ removeAgent(agentId: string): boolean;
103
+ /** Get an agent's configuration. */
104
+ getAgent(agentId: string): AgentConfig | undefined;
105
+ /** List all agents. */
106
+ listAgents(): AgentConfig[];
107
+ /** Check if an agent can use a specific tool. */
108
+ checkAccess(agentId: string, toolName: string): AccessCheckResult;
109
+ /** List all tools an agent can use (intersection of edition + grants). */
110
+ listAccessibleTools(agentId: string): ToolDefinition[];
111
+ on(listener: AccessEventListener): void;
112
+ off(listener: AccessEventListener): void;
113
+ }
114
+ export declare function createToolAccessControl(config: ToolAccessControlConfig): ToolAccessControl;
@@ -0,0 +1,20 @@
1
+ import type { Message } from "./providers/interface.js";
2
+ import type { LLMProvider } from "./providers/interface.js";
3
+ import type { AgentEvent } from "./events/types.js";
4
+ export type CompactionStrategy = "summarize-all" | "summarize-oldest" | "hybrid";
5
+ export interface CompactionContext {
6
+ contextWindowTokens: number;
7
+ utilityProvider?: LLMProvider;
8
+ utilityModel?: string;
9
+ sessionId?: string;
10
+ }
11
+ export interface CompactionResult {
12
+ messages: Message[];
13
+ removed: number;
14
+ strategy: CompactionStrategy;
15
+ beforeTokens: number;
16
+ afterTokens: number;
17
+ }
18
+ export declare function shouldCompact(messages: Message[], context: CompactionContext): boolean;
19
+ export declare function sessionCompact(messages: Message[], context: CompactionContext): Promise<CompactionResult>;
20
+ export declare function sessionCompactWithEvents(messages: Message[], context: CompactionContext): AsyncGenerator<AgentEvent, CompactionResult>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Session orient — lightweight initialization that runs before the
3
+ * first LLM call in each conversation. Gathers user profile, pending
4
+ * jobs, observation thresholds, and brain artifacts into a single
5
+ * context object for system-prompt injection.
6
+ */
7
+ import type { StorageAdapter, UserProfile, BrainArtifact } from "./storage/interface.js";
8
+ import { type ObservationReviewResult } from "./memory/observation-thresholds.js";
9
+ export interface OrientContext {
10
+ userId: string;
11
+ conversationId: string;
12
+ storage: StorageAdapter;
13
+ }
14
+ export interface OrientResult {
15
+ profile: UserProfile | null;
16
+ pendingJobs: number;
17
+ nextJobAt: Date | null;
18
+ observationReview: ObservationReviewResult | null;
19
+ brainArtifacts: BrainArtifact[];
20
+ orientPromptSection: string;
21
+ }
22
+ export declare function sessionOrient(ctx: OrientContext): Promise<OrientResult>;
@@ -0,0 +1,6 @@
1
+ import type { Message } from "./providers/interface.js";
2
+ /**
3
+ * Runs all 7 repair phases on a message array.
4
+ * Mutates in-place for performance but returns the array for chaining.
5
+ */
6
+ export declare function repairSession(messages: Message[]): Message[];
@@ -0,0 +1,24 @@
1
+ import type { StorageAdapter } from "./interface.js";
2
+ export type { StorageAdapter } from "./interface.js";
3
+ export * from "./interface.js";
4
+ export { createPostgresStorage } from "./postgres.js";
5
+ export type { PostgresStorageConfig } from "./postgres.js";
6
+ export { createSqliteStorage } from "./sqlite.js";
7
+ export interface StorageConfig {
8
+ backend: "postgres" | "sqlite";
9
+ connectionString?: string;
10
+ /** Maximum pool size (postgres only). */
11
+ maxConnections?: number;
12
+ }
13
+ /**
14
+ * Create a StorageAdapter from config.
15
+ *
16
+ * ```ts
17
+ * const storage = createStorage({
18
+ * backend: "postgres",
19
+ * connectionString: process.env.DATABASE_URL,
20
+ * });
21
+ * await storage.initialize();
22
+ * ```
23
+ */
24
+ export declare function createStorage(config: StorageConfig): StorageAdapter;
@@ -0,0 +1,245 @@
1
+ export interface User {
2
+ id: string;
3
+ externalId: string;
4
+ platform: string;
5
+ displayName: string | null;
6
+ email: string | null;
7
+ metadata: Record<string, unknown>;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ }
11
+ export interface Conversation {
12
+ id: string;
13
+ userId: string;
14
+ title: string | null;
15
+ channel: string;
16
+ metadata: Record<string, unknown>;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ }
20
+ export interface Message {
21
+ id: string;
22
+ conversationId: string;
23
+ userId: string;
24
+ role: "user" | "assistant" | "system" | "tool";
25
+ content: string;
26
+ channel: string;
27
+ tokenCount: number | null;
28
+ metadata: Record<string, unknown>;
29
+ createdAt: Date;
30
+ }
31
+ export interface MemorySegment {
32
+ id: string;
33
+ userId: string;
34
+ content: string;
35
+ category: "fact" | "preference" | "experience" | "knowledge";
36
+ embedding: number[] | null;
37
+ heat: number;
38
+ accessCount: number;
39
+ lastAccessedAt: Date;
40
+ createdAt: Date;
41
+ updatedAt: Date;
42
+ }
43
+ export interface MemorySearchResult {
44
+ segment: MemorySegment;
45
+ score: number;
46
+ }
47
+ export interface UserProfile {
48
+ userId: string;
49
+ summary: string;
50
+ updatedAt: Date;
51
+ }
52
+ export interface Observation {
53
+ id: string;
54
+ userId: string;
55
+ conversationId: string | null;
56
+ content: string;
57
+ category: string;
58
+ reviewed: boolean;
59
+ createdAt: Date;
60
+ reviewedAt: Date | null;
61
+ }
62
+ export interface Entity {
63
+ id: string;
64
+ userId: string;
65
+ name: string;
66
+ entityType: string;
67
+ metadata: Record<string, unknown>;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ }
71
+ export interface Relation {
72
+ id: string;
73
+ userId: string;
74
+ sourceEntityId: string;
75
+ targetEntityId: string;
76
+ relationType: string;
77
+ strength: number;
78
+ metadata: Record<string, unknown>;
79
+ createdAt: Date;
80
+ }
81
+ export interface Checkpoint {
82
+ id: string;
83
+ conversationId: string;
84
+ summary: string;
85
+ tokensSaved: number;
86
+ createdAt: Date;
87
+ }
88
+ export interface BrainArtifact {
89
+ id: string;
90
+ conversationId: string;
91
+ artifactType: string;
92
+ title: string;
93
+ content: string;
94
+ metadata: Record<string, unknown>;
95
+ createdAt: Date;
96
+ updatedAt: Date;
97
+ }
98
+ export interface ApprovalRecord {
99
+ id: string;
100
+ userId: string;
101
+ conversationId: string;
102
+ action: string;
103
+ status: "pending" | "approved" | "denied";
104
+ payload: Record<string, unknown>;
105
+ decidedAt: Date | null;
106
+ createdAt: Date;
107
+ }
108
+ export interface CostLog {
109
+ id: string;
110
+ userId: string;
111
+ conversationId: string | null;
112
+ provider: string;
113
+ model: string;
114
+ inputTokens: number;
115
+ outputTokens: number;
116
+ costUsd: number;
117
+ createdAt: Date;
118
+ }
119
+ export interface CostEvent {
120
+ id: string;
121
+ userId: string;
122
+ eventType: string;
123
+ amount: number;
124
+ currency: string;
125
+ metadata: Record<string, unknown>;
126
+ createdAt: Date;
127
+ }
128
+ export type JobStatus = "pending" | "running" | "completed" | "failed" | "dead";
129
+ export interface Job {
130
+ id: string;
131
+ type: string;
132
+ status: JobStatus;
133
+ priority: number;
134
+ payload: Record<string, unknown>;
135
+ result: Record<string, unknown> | null;
136
+ error: string | null;
137
+ attempts: number;
138
+ maxAttempts: number;
139
+ claimedAt: Date | null;
140
+ completedAt: Date | null;
141
+ createdAt: Date;
142
+ updatedAt: Date;
143
+ }
144
+ export type ContentSourceStatus = "pending" | "crawling" | "chunking" | "ready" | "failed";
145
+ export interface ContentSource {
146
+ id: string;
147
+ userId: string;
148
+ sourceType: string;
149
+ uri: string;
150
+ status: ContentSourceStatus;
151
+ metadata: Record<string, unknown>;
152
+ createdAt: Date;
153
+ updatedAt: Date;
154
+ }
155
+ export interface ContentChunk {
156
+ id: string;
157
+ sourceId: string;
158
+ content: string;
159
+ embedding: number[] | null;
160
+ chunkIndex: number;
161
+ metadata: Record<string, unknown>;
162
+ createdAt: Date;
163
+ }
164
+ export interface ContentChunkSearchResult {
165
+ chunk: ContentChunk;
166
+ score: number;
167
+ }
168
+ export interface EncryptedCredential {
169
+ id: string;
170
+ userId: string;
171
+ provider: string;
172
+ encryptedData: Buffer;
173
+ iv: Buffer;
174
+ authTag: Buffer;
175
+ createdAt: Date;
176
+ updatedAt: Date;
177
+ }
178
+ export interface IdentityFile {
179
+ id: string;
180
+ workspaceId: string;
181
+ fileName: string;
182
+ content: string;
183
+ metadata: Record<string, unknown>;
184
+ createdAt: Date;
185
+ updatedAt: Date;
186
+ }
187
+ export interface PaginationOpts {
188
+ limit?: number;
189
+ offset?: number;
190
+ }
191
+ export interface CostQueryOpts {
192
+ userId: string;
193
+ startDate: Date;
194
+ endDate: Date;
195
+ }
196
+ export interface StorageAdapter {
197
+ /** Initialize connection pool and run migrations. */
198
+ initialize(): Promise<void>;
199
+ /** Graceful shutdown — drain connection pool. */
200
+ close(): Promise<void>;
201
+ saveMessage(msg: Omit<Message, "id" | "createdAt">): Promise<Message>;
202
+ getMessagesByConversation(conversationId: string, limit?: number): Promise<Message[]>;
203
+ getMessageById(id: string): Promise<Message | null>;
204
+ createConversation(conv: Omit<Conversation, "id" | "createdAt" | "updatedAt">): Promise<Conversation>;
205
+ listConversations(userId: string, opts?: PaginationOpts): Promise<Conversation[]>;
206
+ deleteConversation(id: string): Promise<void>;
207
+ saveMemorySegment(seg: Omit<MemorySegment, "id" | "createdAt" | "updatedAt" | "accessCount" | "lastAccessedAt">): Promise<MemorySegment>;
208
+ searchMemoryByEmbedding(userId: string, embedding: number[], limit?: number): Promise<MemorySearchResult[]>;
209
+ getProfile(userId: string): Promise<UserProfile | null>;
210
+ upsertProfile(userId: string, summary: string): Promise<UserProfile>;
211
+ updateHeatScores(segmentIds: string[], delta: number): Promise<void>;
212
+ saveObservation(obs: Omit<Observation, "id" | "createdAt" | "reviewed" | "reviewedAt">): Promise<Observation>;
213
+ listPendingObservations(userId: string, opts?: PaginationOpts): Promise<Observation[]>;
214
+ markObservationReviewed(id: string): Promise<void>;
215
+ saveBrainArtifact(artifact: Omit<BrainArtifact, "id" | "createdAt" | "updatedAt">): Promise<BrainArtifact>;
216
+ loadBrainArtifacts(conversationId: string): Promise<BrainArtifact[]>;
217
+ deleteBrainArtifact(id: string): Promise<void>;
218
+ insertCostLog(log: Omit<CostLog, "id" | "createdAt">): Promise<CostLog>;
219
+ queryCostLogs(opts: CostQueryOpts): Promise<CostLog[]>;
220
+ createJob(job: Omit<Job, "id" | "status" | "attempts" | "result" | "error" | "claimedAt" | "completedAt" | "createdAt" | "updatedAt">): Promise<Job>;
221
+ claimNextJob(types?: string[]): Promise<Job | null>;
222
+ updateJobStatus(id: string, status: JobStatus, result?: Record<string, unknown>, error?: string): Promise<Job>;
223
+ getJobById(id: string): Promise<Job | null>;
224
+ listJobs(filter: {
225
+ status?: JobStatus;
226
+ type?: string;
227
+ }, opts?: PaginationOpts): Promise<Job[]>;
228
+ markDeadJobs(timeoutSeconds: number): Promise<number>;
229
+ createContentSource(src: Omit<ContentSource, "id" | "createdAt" | "updatedAt">): Promise<ContentSource>;
230
+ updateContentSourceStatus(id: string, status: ContentSourceStatus): Promise<ContentSource>;
231
+ getContentSourceById(id: string): Promise<ContentSource | null>;
232
+ listContentSources(userId: string, opts?: PaginationOpts): Promise<ContentSource[]>;
233
+ bulkInsertContentChunks(chunks: Omit<ContentChunk, "id" | "createdAt">[]): Promise<ContentChunk[]>;
234
+ searchContentChunksByEmbedding(sourceIds: string[], embedding: number[], limit?: number): Promise<ContentChunkSearchResult[]>;
235
+ searchContentChunksByText(sourceIds: string[], query: string, limit?: number): Promise<ContentChunkSearchResult[]>;
236
+ deleteContentChunksBySource(sourceId: string): Promise<number>;
237
+ saveCredential(cred: Omit<EncryptedCredential, "id" | "createdAt" | "updatedAt">): Promise<EncryptedCredential>;
238
+ getCredential(userId: string, provider: string): Promise<EncryptedCredential | null>;
239
+ deleteCredential(id: string): Promise<void>;
240
+ listCredentials(userId: string): Promise<EncryptedCredential[]>;
241
+ saveIdentityFile(file: Omit<IdentityFile, "id" | "createdAt" | "updatedAt">): Promise<IdentityFile>;
242
+ getIdentityFile(workspaceId: string): Promise<IdentityFile | null>;
243
+ listIdentityFiles(): Promise<IdentityFile[]>;
244
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
245
+ }
@@ -0,0 +1,6 @@
1
+ import type { StorageAdapter } from "./interface.js";
2
+ export interface PostgresStorageConfig {
3
+ connectionString: string;
4
+ max?: number;
5
+ }
6
+ export declare function createPostgresStorage(config: PostgresStorageConfig): StorageAdapter;
@@ -0,0 +1,2 @@
1
+ import type { StorageAdapter } from "./interface.js";
2
+ export declare function createSqliteStorage(): StorageAdapter;
@@ -0,0 +1,67 @@
1
+ export interface ReasoningBlock {
2
+ type: "reasoning";
3
+ id: string;
4
+ /** True while still generating, false when committed */
5
+ isThinking: boolean;
6
+ /** Accumulated thinking text */
7
+ content: string;
8
+ /** Some providers redact thinking content */
9
+ redacted?: boolean;
10
+ /** Provider that produced this reasoning */
11
+ provider?: string;
12
+ /** Timestamp when reasoning started */
13
+ startedAt: number;
14
+ /** Timestamp when reasoning committed */
15
+ committedAt?: number;
16
+ }
17
+ export interface ReasoningConfig {
18
+ /** Forward reasoning blocks to client event stream */
19
+ showReasoning: boolean;
20
+ /** Store reasoning in brain artifacts for inspection */
21
+ storeInArtifacts: boolean;
22
+ }
23
+ export declare const DEFAULT_REASONING_CONFIG: ReasoningConfig;
24
+ export type ReasoningEventEmitter = (event: string, payload: Record<string, unknown>) => void;
25
+ export type ArtifactStoreFn = (key: string, content: string) => Promise<void>;
26
+ export declare class ReasoningProcessor {
27
+ private config;
28
+ private emit;
29
+ private storeArtifact;
30
+ private activeBlocks;
31
+ constructor(config?: Partial<ReasoningConfig>, opts?: {
32
+ emit?: ReasoningEventEmitter;
33
+ storeArtifact?: ArtifactStoreFn;
34
+ });
35
+ /**
36
+ * Extract reasoning from an Anthropic API response.
37
+ * Handles both extended thinking and encrypted (redacted) thinking.
38
+ */
39
+ processAnthropicResponse(sessionId: string, contentBlocks: AnthropicContentBlock[]): ReasoningBlock[];
40
+ /**
41
+ * Extract reasoning from an OpenAI reasoning model response (o3, o4-mini).
42
+ */
43
+ processOpenAIResponse(sessionId: string, message: OpenAIMessage): ReasoningBlock[];
44
+ /**
45
+ * Start a streaming reasoning block (for real-time thinking output).
46
+ */
47
+ startStreaming(sessionId: string, provider: string): ReasoningBlock;
48
+ /**
49
+ * Append content to a streaming reasoning block.
50
+ */
51
+ appendStreaming(blockId: string, text: string): void;
52
+ /**
53
+ * Commit a streaming reasoning block (thinking complete).
54
+ */
55
+ commitStreaming(blockId: string): Promise<ReasoningBlock | null>;
56
+ private createBlock;
57
+ }
58
+ export interface AnthropicContentBlock {
59
+ type: "text" | "thinking" | "redacted_thinking" | "tool_use";
60
+ text?: string;
61
+ thinking?: string;
62
+ }
63
+ export interface OpenAIMessage {
64
+ role: string;
65
+ content?: string;
66
+ reasoning_content?: string;
67
+ }
@@ -0,0 +1,26 @@
1
+ import type { TaskItem, TaskItemStatus, TaskTracker, AgentEvent } from "./events/types.js";
2
+ /** Reset counter for testing */
3
+ export declare function _resetTaskIdCounter(): void;
4
+ export declare class TaskTrackerImpl implements TaskTracker {
5
+ private _tasks;
6
+ get tasks(): readonly TaskItem[];
7
+ add(title: string): TaskItem;
8
+ update(id: string, status: TaskItemStatus): void;
9
+ current(): TaskItem | undefined;
10
+ /** Plan multiple tasks at once, returns all created items */
11
+ plan(titles: string[]): TaskItem[];
12
+ /** Mark a task as done */
13
+ complete(id: string): void;
14
+ /** Mark a task as blocked */
15
+ block(id: string): void;
16
+ /** Get summary counts */
17
+ summary(): {
18
+ total: number;
19
+ pending: number;
20
+ inProgress: number;
21
+ done: number;
22
+ blocked: number;
23
+ };
24
+ }
25
+ export declare function planWithEvents(tracker: TaskTrackerImpl, titles: string[], sessionId?: string): Generator<AgentEvent, TaskItem[]>;
26
+ export declare function updateWithEvents(tracker: TaskTrackerImpl, id: string, status: TaskItemStatus, sessionId?: string): Generator<AgentEvent>;
@@ -0,0 +1,39 @@
1
+ import type { StorageAdapter } from "../storage/interface.js";
2
+ export interface ActionRecord {
3
+ id: string;
4
+ sessionId: string;
5
+ turnIndex: number;
6
+ toolName: string;
7
+ toolInput: Record<string, unknown>;
8
+ toolOutput: unknown;
9
+ llmInput: string;
10
+ llmOutput: string;
11
+ timestamp: Date;
12
+ }
13
+ export interface ReplayMatch {
14
+ record: ActionRecord;
15
+ exact: boolean;
16
+ }
17
+ export interface ActionCacheConfig {
18
+ /** Recording mode — set by FENIX_RECORD=true */
19
+ record: boolean;
20
+ /** Replay mode — set by FENIX_REPLAY=<sessionId> */
21
+ replaySessionId: string | null;
22
+ }
23
+ export declare const ACTION_CACHE_SCHEMA = "\nCREATE TABLE IF NOT EXISTS action_cache (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n turn_index INTEGER NOT NULL,\n tool_name TEXT NOT NULL,\n tool_input JSONB NOT NULL,\n tool_output JSONB,\n llm_input TEXT NOT NULL,\n llm_output TEXT NOT NULL,\n input_hash TEXT NOT NULL,\n timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\n\nCREATE INDEX IF NOT EXISTS idx_action_cache_session\n ON action_cache (session_id, turn_index);\nCREATE INDEX IF NOT EXISTS idx_action_cache_lookup\n ON action_cache (session_id, turn_index, tool_name, input_hash);\n";
24
+ /** Stable JSON serialization with sorted keys and normalized timestamps. */
25
+ export declare function stableHash(input: Record<string, unknown>): string;
26
+ export declare class ActionCache {
27
+ private storage;
28
+ private config;
29
+ constructor(storage: StorageAdapter, config?: Partial<ActionCacheConfig>);
30
+ get isRecording(): boolean;
31
+ get isReplaying(): boolean;
32
+ get replaySessionId(): string | null;
33
+ /** Record an action (only in record mode). */
34
+ record(action: Omit<ActionRecord, "id" | "timestamp">): Promise<string | null>;
35
+ /** Look up a cached action for replay. Returns null if no match (partial replay). */
36
+ lookup(turnIndex: number, toolName: string, toolInput: Record<string, unknown>): Promise<ReplayMatch | null>;
37
+ /** Replay an entire session, optionally overriding specific turn inputs. */
38
+ replaySession(sessionId: string, inputOverrides?: Map<number, Record<string, unknown>>): Promise<ActionRecord[]>;
39
+ }
@@ -0,0 +1,49 @@
1
+ import type { EvalCase } from "./workflow-evals.js";
2
+ export type IncidentSeverity = "P0" | "P1" | "P2";
3
+ export interface ToolCall {
4
+ tool: string;
5
+ input: Record<string, unknown>;
6
+ output: unknown;
7
+ }
8
+ export interface IncidentArtifact {
9
+ id: string;
10
+ severity: IncidentSeverity;
11
+ description: string;
12
+ inputPrompt: string;
13
+ toolTrace: ToolCall[];
14
+ agentOutput: string;
15
+ expectedBehavior: string;
16
+ piiRedacted: boolean;
17
+ }
18
+ export interface IncidentEvalMetadata {
19
+ incidentId: string;
20
+ severity: IncidentSeverity;
21
+ createdAt: Date;
22
+ owner: string;
23
+ }
24
+ export interface SynthesizedEval {
25
+ evalCase: EvalCase;
26
+ metadata: IncidentEvalMetadata;
27
+ hash: string;
28
+ }
29
+ export type PIIRedactorFn = (text: string) => string;
30
+ export type LLMSynthesisFn = (prompt: string) => Promise<string>;
31
+ export type EvalStoreFn = (filename: string, content: string) => Promise<void>;
32
+ export type EvalHashLookupFn = (hash: string) => Promise<boolean>;
33
+ /**
34
+ * Convert an incident artifact into a regression eval case.
35
+ */
36
+ export declare function synthesizeEval(artifact: IncidentArtifact, owner: string, llmSynthesize: LLMSynthesisFn, redact?: PIIRedactorFn): Promise<SynthesizedEval>;
37
+ /**
38
+ * Store a synthesized eval case as a regression test file.
39
+ * Returns false if a duplicate already exists.
40
+ */
41
+ export declare function persistEval(synthesized: SynthesizedEval, store: EvalStoreFn, hashLookup: EvalHashLookupFn): Promise<boolean>;
42
+ /**
43
+ * Determine if a failing eval should block release based on severity.
44
+ */
45
+ export declare function shouldBlockRelease(severity: IncidentSeverity): boolean;
46
+ /**
47
+ * Determine if a failing eval should emit a warning.
48
+ */
49
+ export declare function shouldWarn(severity: IncidentSeverity): boolean;