@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,166 @@
1
+ /**
2
+ * Approval Gates — channel-agnostic approval flow with
3
+ * Telegram inline keyboard support, HTTP pending-approval endpoint,
4
+ * 5-minute timeout, and pluggable persistence.
5
+ */
6
+ export type RiskLevel = "low" | "medium" | "high" | "critical";
7
+ export type ApprovalStatus = "pending" | "approved" | "denied" | "timeout" | "error";
8
+ export interface ApprovalRequest {
9
+ id: string;
10
+ toolName: string;
11
+ args: Record<string, unknown>;
12
+ userId: string;
13
+ chatId: string;
14
+ channel: string;
15
+ reason?: string;
16
+ riskLevel: RiskLevel;
17
+ status: ApprovalStatus;
18
+ createdAt: Date;
19
+ resolvedAt?: Date;
20
+ resolvedBy?: string;
21
+ timeoutMs: number;
22
+ }
23
+ export interface ApprovalResult {
24
+ approved: boolean;
25
+ request: ApprovalRequest;
26
+ }
27
+ export interface ApprovalPolicy {
28
+ /** Tool name pattern. Use "*" for all tools. */
29
+ toolName: string;
30
+ /** Minimum risk level that triggers approval. Default: all levels require it. */
31
+ riskLevel?: RiskLevel;
32
+ /** If true, this tool requires approval. */
33
+ requireApproval: boolean;
34
+ /** Users that are auto-approved (skip the gate). */
35
+ autoApproveForUsers?: string[];
36
+ }
37
+ export interface ChannelSender {
38
+ /** Send approval prompt to user via channel UI (e.g. Telegram inline keyboard). */
39
+ sendApproval(request: ApprovalRequest): Promise<void>;
40
+ /** Notify user that approval was resolved (optional). */
41
+ notifyResolved?(request: ApprovalRequest): Promise<void>;
42
+ }
43
+ export interface ApprovalStore {
44
+ save(request: ApprovalRequest): Promise<void>;
45
+ get(id: string): Promise<ApprovalRequest | undefined>;
46
+ update(id: string, updates: Partial<ApprovalRequest>): Promise<void>;
47
+ listPending(): Promise<ApprovalRequest[]>;
48
+ listByUser(userId: string): Promise<ApprovalRequest[]>;
49
+ listAll(): Promise<ApprovalRequest[]>;
50
+ }
51
+ export type ApprovalEventType = "approval_requested" | "approval_approved" | "approval_denied" | "approval_timeout" | "approval_error";
52
+ export interface ApprovalEvent {
53
+ type: ApprovalEventType;
54
+ request: ApprovalRequest;
55
+ timestamp: Date;
56
+ }
57
+ export type ApprovalEventListener = (event: ApprovalEvent) => void;
58
+ export interface HttpApprovalInfo {
59
+ id: string;
60
+ toolName: string;
61
+ args: Record<string, unknown>;
62
+ userId: string;
63
+ channel: string;
64
+ riskLevel: RiskLevel;
65
+ reason?: string;
66
+ createdAt: string;
67
+ expiresAt: string;
68
+ }
69
+ export interface ApprovalGateConfig {
70
+ /** Default timeout in ms. Default 300_000 (5 minutes). */
71
+ defaultTimeoutMs?: number;
72
+ /** Maximum pending approvals per agent/user. Default 5. */
73
+ maxPendingPerAgent?: number;
74
+ /** Pluggable persistence store. Defaults to in-memory. */
75
+ store?: ApprovalStore;
76
+ }
77
+ export interface ApprovalGate {
78
+ /** Request approval. Blocks until approved, denied, or timed out. */
79
+ requestApproval(opts: {
80
+ toolName: string;
81
+ args: Record<string, unknown>;
82
+ userId: string;
83
+ chatId: string;
84
+ channel: string;
85
+ reason?: string;
86
+ riskLevel?: RiskLevel;
87
+ timeoutMs?: number;
88
+ }): Promise<ApprovalResult>;
89
+ /** Resolve a pending approval externally (e.g. from callback query or HTTP). */
90
+ resolve(approvalId: string, decision: "approved" | "denied", resolvedBy?: string): void;
91
+ /** Get a single approval request. */
92
+ getRequest(id: string): ApprovalRequest | undefined;
93
+ /** All currently pending requests. */
94
+ listPending(): ApprovalRequest[];
95
+ /** Pending count for a specific user. */
96
+ pendingCountForUser(userId: string): number;
97
+ /** All requests for a user. */
98
+ listByUser(userId: string): ApprovalRequest[];
99
+ /** Pending approvals as HTTP-friendly JSON. */
100
+ listPendingHttp(): HttpApprovalInfo[];
101
+ /** Add or update a policy. */
102
+ addPolicy(policy: ApprovalPolicy): void;
103
+ /** Remove a policy for a tool name. */
104
+ removePolicy(toolName: string): boolean;
105
+ /** Check if a tool call needs approval for a given user. */
106
+ needsApproval(toolName: string, userId: string): boolean;
107
+ /** Register a channel sender (e.g. Telegram, Slack). */
108
+ registerChannel(channelName: string, sender: ChannelSender): void;
109
+ on(listener: ApprovalEventListener): void;
110
+ off(listener: ApprovalEventListener): void;
111
+ /** Clean up timers and resolve all pending as denied. */
112
+ dispose(): void;
113
+ }
114
+ export declare function _resetApprovalIds(): void;
115
+ export declare function createInMemoryApprovalStore(): ApprovalStore;
116
+ export declare function createApprovalGate(config?: ApprovalGateConfig): ApprovalGate;
117
+ /**
118
+ * Creates a ChannelSender that uses the Telegram adapter's
119
+ * sendApprovalKeyboard / sendMessage methods.
120
+ *
121
+ * The `onResolve` callback lets the Telegram adapter's callback-query
122
+ * handler call `gate.resolve()` when the user taps Approve/Deny.
123
+ */
124
+ export interface TelegramSenderConfig {
125
+ /** Send an inline keyboard approval prompt. */
126
+ sendApprovalKeyboard: (chatId: string, approvalId: string, toolName: string, args: Record<string, unknown>) => void;
127
+ /** Send a plain text message. */
128
+ sendMessage: (chatId: string, text: string) => Promise<void>;
129
+ }
130
+ export declare function createTelegramApprovalSender(config: TelegramSenderConfig): ChannelSender;
131
+ /**
132
+ * Creates a ChannelSender for voice-based approval: speaks the approval
133
+ * prompt and listens for a spoken "approve" or "deny" response.
134
+ */
135
+ export interface VoiceSenderConfig {
136
+ /** Speak a text prompt to the user. */
137
+ speak: (chatId: string, text: string) => Promise<void>;
138
+ /**
139
+ * Listen for a spoken confirmation. Should resolve to "approve" or "deny"
140
+ * (or any string — the sender maps to a decision).
141
+ * A timeout or unrecognised input should resolve to "deny".
142
+ */
143
+ listenForConfirmation: (chatId: string, timeoutMs: number) => Promise<string>;
144
+ }
145
+ export declare function createVoiceApprovalSender(config: VoiceSenderConfig, gate: ApprovalGate): ChannelSender;
146
+ /**
147
+ * Build HTTP handler functions for approval endpoints.
148
+ * These can be mounted on Hono, Express, or any HTTP framework.
149
+ */
150
+ export interface HttpApprovalHandlers {
151
+ /** GET /approvals — list pending approvals. */
152
+ listPending: () => HttpApprovalInfo[];
153
+ /** POST /approvals/:id/approve — approve a request. */
154
+ approve: (id: string, approvedBy?: string) => {
155
+ ok: boolean;
156
+ message: string;
157
+ };
158
+ /** POST /approvals/:id/deny — deny a request. */
159
+ deny: (id: string, deniedBy?: string) => {
160
+ ok: boolean;
161
+ message: string;
162
+ };
163
+ /** GET /approvals/:id — get a single approval. */
164
+ getApproval: (id: string) => HttpApprovalInfo | null;
165
+ }
166
+ export declare function createHttpApprovalHandlers(gate: ApprovalGate): HttpApprovalHandlers;
@@ -0,0 +1,38 @@
1
+ import type { ExtensionDefinition } from "../extensions/manager.js";
2
+ export interface ContentWrapperConfig {
3
+ enabled: boolean;
4
+ /** XML tag name for wrapping (default: "untrusted") */
5
+ wrapper: string;
6
+ /** Tool names whose output is trusted (injected directly) */
7
+ trustedSources: string[];
8
+ /** Extract URLs from untrusted content as [LINK: url] references */
9
+ treatLinksAsHostile: boolean;
10
+ /** User IDs whose messages are trusted in group contexts */
11
+ allowlistedUsers?: string[];
12
+ }
13
+ /**
14
+ * Standing instruction appended to system prompt when content wrapping is active.
15
+ */
16
+ export declare const UNTRUSTED_CONTENT_INSTRUCTION: string;
17
+ /**
18
+ * Determine whether a tool's output should be wrapped.
19
+ */
20
+ export declare function isTrustedSource(toolName: string, config: ContentWrapperConfig): boolean;
21
+ /**
22
+ * Wrap content in XML delimiters with source attribution.
23
+ */
24
+ export declare function wrapContent(content: string, source: string, config: ContentWrapperConfig): string;
25
+ /**
26
+ * Check if a user message in group context should be wrapped.
27
+ */
28
+ export declare function isAllowlistedUser(userId: string, config: ContentWrapperConfig): boolean;
29
+ /**
30
+ * Wrap a group message from a non-allowlisted user.
31
+ */
32
+ export declare function wrapGroupMessage(content: string, userId: string, config: ContentWrapperConfig): string;
33
+ /**
34
+ * Create the content wrapper as a guard-rails extension.
35
+ * Runs as a `tool:after` hook — wraps untrusted tool results
36
+ * before they enter the LLM context.
37
+ */
38
+ export declare function createContentWrapperExtension(config?: Partial<ContentWrapperConfig>): ExtensionDefinition;
@@ -0,0 +1,6 @@
1
+ import type { ExtensionDefinition } from "../extensions/manager.js";
2
+ /** Mark a session as unattended (no human in the loop). */
3
+ export declare function setSessionUnattended(sessionId: string, unattended: boolean): void;
4
+ export declare const guardRailsExtension: ExtensionDefinition;
5
+ /** Reset context tracking state (for tests). */
6
+ export declare function _resetGuardRailState(): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Security module — SSRF, shell bleed, taint tracking, approval gates,
3
+ * instruction hierarchy, secret store, tool access control.
4
+ */
5
+ export { validateUrl, validateUrlWithDns, } from "./ssrf.js";
6
+ export type { SsrfResult, DnsResolver } from "./ssrf.js";
7
+ export { TaintTracker, TaintSet, CLEAN } from "./taint-tracker.js";
8
+ export type { TaintLabel, OutputPolicy } from "./taint-tracker.js";
9
+ export { detectShellBleed, detectShellBleedWithEvents } from "./shell-bleed.js";
10
+ export type { ShellBleedAction, ShellBleedLeak, ShellBleedResult } from "./shell-bleed.js";
11
+ export { createApprovalGate, createInMemoryApprovalStore, createTelegramApprovalSender, createVoiceApprovalSender, createHttpApprovalHandlers, _resetApprovalIds, } from "./approval-gates.js";
12
+ export type { RiskLevel, ApprovalStatus, ApprovalRequest, ApprovalResult, ApprovalPolicy, ChannelSender, ApprovalStore, ApprovalEventType, ApprovalEvent, ApprovalEventListener, HttpApprovalInfo, ApprovalGateConfig, ApprovalGate, TelegramSenderConfig, VoiceSenderConfig, HttpApprovalHandlers, } from "./approval-gates.js";
13
+ export { createInstructionHierarchy, applyWebIsolation, containsWebIsolation, stripWebIsolation, WEB_ISOLATION_PREFIX, WEB_ISOLATION_SUFFIX, } from "./instruction-hierarchy.js";
14
+ export type { InstructionSource, TaggedContent, SensitiveAction, ConfirmationRequest, ConfirmationHandler, ValidationVerdict, ValidationResult, HierarchyEventType, HierarchyEvent, HierarchyEventListener, InstructionHierarchyConfig, InstructionHierarchy, } from "./instruction-hierarchy.js";
15
+ export { createSecretStore } from "./secret-store.js";
16
+ export type { EncryptedCredential, SecretStoreConfig, SecretStore } from "./secret-store.js";
17
+ export { guardRailsExtension, setSessionUnattended, _resetGuardRailState, } from "./guard-rails.js";
18
+ export { PIITokenizer, createPIITokenizerExtension } from "./pii-tokenizer.js";
19
+ export type { PIIPattern, TokenMap, PIIEventEmitter } from "./pii-tokenizer.js";
20
+ export { createToolAccessControl, EDITION_PRO, EDITION_MOBILE, EDITION_VOICES, } from "./tool-access-control.js";
21
+ export type { ToolCategory, ToolDefinition as AccessToolDefinition, EditionName, EditionManifest, AgentRole, AgentConfig, AccessVerdict, AccessCheckResult, AccessEventType, AccessEvent, AccessEventListener, ToolAccessControlConfig, ToolAccessControl, } from "./tool-access-control.js";
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Instruction Hierarchy — tag content with InstructionSource,
3
+ * enforce web content isolation markers, and require user
4
+ * confirmation for sensitive actions.
5
+ *
6
+ * Privilege levels (highest → lowest):
7
+ * system > user > tool > web
8
+ *
9
+ * Content from lower-privilege sources cannot override
10
+ * higher-privilege instructions. Web content is always
11
+ * isolated and cannot trigger sensitive actions directly.
12
+ */
13
+ /** Ordered from most to least privileged. */
14
+ export type InstructionSource = "system" | "user" | "tool" | "web";
15
+ export interface TaggedContent {
16
+ /** The raw content string. */
17
+ content: string;
18
+ /** Where this content originated. */
19
+ source: InstructionSource;
20
+ /** Whether web-isolation markers have been applied. */
21
+ isolated: boolean;
22
+ /** ISO timestamp of when this was tagged. */
23
+ taggedAt: string;
24
+ /** Optional label identifying the specific origin (e.g. URL, tool name). */
25
+ origin?: string;
26
+ }
27
+ export declare const WEB_ISOLATION_PREFIX = "<!-- [WEB_CONTENT_START] -->";
28
+ export declare const WEB_ISOLATION_SUFFIX = "<!-- [WEB_CONTENT_END] -->";
29
+ /**
30
+ * Wrap content with web-isolation markers so downstream processors
31
+ * can detect and sandbox web-sourced content.
32
+ */
33
+ export declare function applyWebIsolation(content: string, origin?: string): string;
34
+ /**
35
+ * Check if a string contains web-isolated content.
36
+ */
37
+ export declare function containsWebIsolation(text: string): boolean;
38
+ /**
39
+ * Strip web-isolation markers from content, returning the inner text.
40
+ */
41
+ export declare function stripWebIsolation(text: string): string;
42
+ export interface SensitiveAction {
43
+ /** Action/tool name pattern. Use "*" for all. */
44
+ action: string;
45
+ /** Human-readable description of why this is sensitive. */
46
+ reason: string;
47
+ /** Minimum source privilege required to execute without confirmation. */
48
+ minSource: InstructionSource;
49
+ }
50
+ export interface ConfirmationRequest {
51
+ action: string;
52
+ args: Record<string, unknown>;
53
+ triggeredBy: InstructionSource;
54
+ reason: string;
55
+ origin?: string;
56
+ }
57
+ export type ConfirmationHandler = (request: ConfirmationRequest) => Promise<boolean>;
58
+ export type ValidationVerdict = "allow" | "confirm" | "deny";
59
+ export interface ValidationResult {
60
+ verdict: ValidationVerdict;
61
+ reason: string;
62
+ action: string;
63
+ triggeredBy: InstructionSource;
64
+ requiredSource?: InstructionSource;
65
+ }
66
+ export type HierarchyEventType = "content_tagged" | "action_allowed" | "action_confirmed" | "action_denied" | "web_content_isolated" | "privilege_escalation_blocked";
67
+ export interface HierarchyEvent {
68
+ type: HierarchyEventType;
69
+ timestamp: Date;
70
+ source?: InstructionSource;
71
+ action?: string;
72
+ detail: string;
73
+ }
74
+ export type HierarchyEventListener = (event: HierarchyEvent) => void;
75
+ export interface InstructionHierarchyConfig {
76
+ /** Callback to ask user for confirmation on sensitive actions. */
77
+ confirmationHandler?: ConfirmationHandler;
78
+ /** If true, web-sourced content is always denied for sensitive actions
79
+ * regardless of confirmation. Default: true. */
80
+ strictWebIsolation?: boolean;
81
+ }
82
+ export interface InstructionHierarchy {
83
+ /** Tag content with its source. Web content gets isolation markers. */
84
+ tagContent(content: string, source: InstructionSource, origin?: string): TaggedContent;
85
+ /** Register a sensitive action that requires elevated privilege. */
86
+ addSensitiveAction(action: SensitiveAction): void;
87
+ /** Remove a sensitive action. */
88
+ removeSensitiveAction(actionName: string): boolean;
89
+ /** List all registered sensitive actions. */
90
+ listSensitiveActions(): SensitiveAction[];
91
+ /** Check if an action is registered as sensitive. */
92
+ isSensitive(actionName: string): boolean;
93
+ /** Validate whether a source can execute an action.
94
+ * Returns "allow", "confirm", or "deny". */
95
+ validate(actionName: string, triggeredBy: InstructionSource): ValidationResult;
96
+ /** Execute an action through the hierarchy — validates, confirms if
97
+ * needed, and returns whether the action was permitted. */
98
+ executeAction(actionName: string, args: Record<string, unknown>, triggeredBy: InstructionSource, origin?: string): Promise<{
99
+ permitted: boolean;
100
+ result: ValidationResult;
101
+ }>;
102
+ /** Check if one source has higher or equal privilege to another. */
103
+ hasPrivilege(source: InstructionSource, requiredSource: InstructionSource): boolean;
104
+ /** Get the privilege level (0-3) for a source. */
105
+ getPrivilegeLevel(source: InstructionSource): number;
106
+ on(listener: HierarchyEventListener): void;
107
+ off(listener: HierarchyEventListener): void;
108
+ }
109
+ export declare function createInstructionHierarchy(config?: InstructionHierarchyConfig): InstructionHierarchy;
@@ -0,0 +1,30 @@
1
+ import type { ExtensionDefinition } from "../extensions/manager.js";
2
+ export interface PIIPattern {
3
+ type: string;
4
+ regex: RegExp;
5
+ tokenPrefix: string;
6
+ }
7
+ export interface TokenMap {
8
+ tokenToValue: Map<string, string>;
9
+ valueToToken: Map<string, string>;
10
+ counters: Map<string, number>;
11
+ }
12
+ export type PIIEventEmitter = (event: string, payload: Record<string, unknown>) => void;
13
+ export declare class PIITokenizer {
14
+ private sessionMaps;
15
+ private patterns;
16
+ private emitEvent;
17
+ constructor(customPatterns?: PIIPattern[], emitEvent?: PIIEventEmitter);
18
+ /** Tokenize PII in text, returning sanitized text. */
19
+ tokenize(sessionId: string, text: string, toolName?: string): string;
20
+ /** Untokenize — restore real values from tokens. */
21
+ untokenize(sessionId: string, text: string): string;
22
+ /** Clear session token map (on session end). */
23
+ clearSession(sessionId: string): void;
24
+ /** Get token count for a session. */
25
+ getTokenCount(sessionId: string): number;
26
+ private getOrCreateMap;
27
+ }
28
+ export declare function createPIITokenizerExtension(tokenizer: PIITokenizer, opts?: {
29
+ privacyLevel?: string;
30
+ }): ExtensionDefinition;
@@ -0,0 +1,53 @@
1
+ import type { Severity } from "./security-engine.js";
2
+ import type { StorageAdapter } from "../storage/interface.js";
3
+ export type ReputationStatus = "trusted" | "normal" | "suspicious" | "blocklisted";
4
+ export interface ReputationRecord {
5
+ userId: string;
6
+ sessionCount: number;
7
+ securityEvents: SecurityEventEntry[];
8
+ trustScore: number;
9
+ status: ReputationStatus;
10
+ lastUpdated: Date;
11
+ }
12
+ export interface SecurityEventEntry {
13
+ severity: Severity;
14
+ module: string;
15
+ timestamp: Date;
16
+ }
17
+ export interface ReputationConfig {
18
+ /** Initial trust score for new users (default: 0.5) */
19
+ initialScore?: number;
20
+ /** TTL in days for inactive records (default: 90) */
21
+ ttlDays?: number;
22
+ /** Owner user IDs that bypass escalation */
23
+ ownerIds?: string[];
24
+ }
25
+ export declare class ReputationEngine {
26
+ private records;
27
+ private config;
28
+ private storage;
29
+ constructor(config?: ReputationConfig, storage?: StorageAdapter);
30
+ /**
31
+ * Record a security event and update the user's trust score.
32
+ */
33
+ recordEvent(userId: string, severity: Severity, module: string): Promise<ReputationRecord>;
34
+ /**
35
+ * Get the effective severity after reputation-based escalation.
36
+ * - Suspicious users: escalate by one level
37
+ * - Blocklisted users: always CRITICAL
38
+ * - Trusted users: de-escalate MEDIUM → LOW
39
+ * - Owners: ALLOW unless CRITICAL
40
+ */
41
+ adjustSeverity(userId: string, baseSeverity: Severity): Severity;
42
+ /** Get a user's current reputation record. */
43
+ getRecord(userId: string): Promise<ReputationRecord | null>;
44
+ /** Manually blocklist a user. */
45
+ blocklist(userId: string): Promise<void>;
46
+ /** Reset a user's reputation to initial state. */
47
+ reset(userId: string): Promise<void>;
48
+ /** Purge expired records (older than TTL). */
49
+ purgeExpired(): Promise<number>;
50
+ private getOrCreate;
51
+ private computeStatus;
52
+ private persist;
53
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Encrypted Credentials — AES-256-GCM encryption for API keys
3
+ * and credentials. Keys are encrypted with a workspace master key
4
+ * derived from an environment variable.
5
+ *
6
+ * Methods: store, retrieve, delete, list.
7
+ * Backed by an in-memory encrypted_credentials table.
8
+ */
9
+ export interface EncryptedCredential {
10
+ /** User ID. */
11
+ userId: string;
12
+ /** Provider name (e.g. "openai", "anthropic"). */
13
+ provider: string;
14
+ /** Base64-encoded encrypted data. */
15
+ encryptedData: string;
16
+ /** Base64-encoded initialization vector. */
17
+ iv: string;
18
+ /** Base64-encoded auth tag. */
19
+ authTag: string;
20
+ /** When this credential was stored. */
21
+ createdAt: Date;
22
+ /** When this credential was last updated. */
23
+ updatedAt: Date;
24
+ }
25
+ export interface SecretStoreConfig {
26
+ /** Master key for encryption (32 bytes as hex string or Uint8Array). */
27
+ masterKey: string | Uint8Array;
28
+ }
29
+ export interface SecretStore {
30
+ /** Store an encrypted credential. Overwrites if exists. */
31
+ store(userId: string, provider: string, key: string): Promise<void>;
32
+ /** Retrieve and decrypt a credential. Returns null if not found. */
33
+ retrieve(userId: string, provider: string): Promise<string | null>;
34
+ /** Delete a credential. */
35
+ delete(userId: string, provider: string): boolean;
36
+ /** List all providers with stored credentials for a user. */
37
+ list(userId: string): string[];
38
+ /** Check if a credential exists. */
39
+ has(userId: string, provider: string): boolean;
40
+ }
41
+ export declare function createSecretStore(config: SecretStoreConfig): SecretStore;
@@ -0,0 +1,53 @@
1
+ import type { EventBus } from "../events/bus.js";
2
+ export type Severity = "SAFE" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
3
+ export type ActionDisposition = "allow" | "log" | "warn" | "block";
4
+ export interface DetectionFinding {
5
+ module: string;
6
+ severity: Severity;
7
+ description: string;
8
+ evidence?: string;
9
+ }
10
+ export interface ValidationResult {
11
+ severity: Severity;
12
+ action: ActionDisposition;
13
+ findings: DetectionFinding[];
14
+ durationMs: number;
15
+ }
16
+ export interface SecurityEngineConfig {
17
+ /** Per-severity action overrides (workspace-level) */
18
+ actionMap?: Partial<Record<Severity, ActionDisposition>>;
19
+ /** Workspace root for policy file loading */
20
+ workspaceRoot?: string;
21
+ /** Custom deny patterns from workspace policy */
22
+ customDenyPatterns?: string[];
23
+ /** Trusted sources that skip content policy scanning */
24
+ trustedSources?: string[];
25
+ }
26
+ export interface ValidationInput {
27
+ /** What is being validated: tool call, tool result, user message */
28
+ kind: "tool-call" | "tool-result" | "user-message";
29
+ /** Tool name, if applicable */
30
+ toolName?: string;
31
+ /** Content to validate */
32
+ content: string;
33
+ /** Tool parameters, if applicable */
34
+ params?: Record<string, unknown>;
35
+ /** User/session ID for reputation lookup */
36
+ userId?: string;
37
+ }
38
+ export declare class SecurityEngine {
39
+ private actionMap;
40
+ private config;
41
+ private eventBus;
42
+ constructor(config?: SecurityEngineConfig, eventBus?: EventBus);
43
+ /**
44
+ * Validate input through all 6 detection modules in parallel.
45
+ * Returns aggregated severity with findings.
46
+ */
47
+ validate(input: ValidationInput): Promise<ValidationResult>;
48
+ /**
49
+ * Aggregate = max(individual severities), with escalation:
50
+ * 2+ HIGH findings → CRITICAL.
51
+ */
52
+ private aggregateSeverity;
53
+ }
@@ -0,0 +1,15 @@
1
+ import type { AgentEvent } from "../events/types.js";
2
+ export type ShellBleedAction = "warn" | "block";
3
+ export interface ShellBleedLeak {
4
+ variable: string;
5
+ line: number;
6
+ pattern: string;
7
+ }
8
+ export interface ShellBleedResult {
9
+ safe: boolean;
10
+ action: ShellBleedAction;
11
+ leaks: ShellBleedLeak[];
12
+ blocked: boolean;
13
+ }
14
+ export declare function detectShellBleed(script: string, action?: ShellBleedAction): ShellBleedResult;
15
+ export declare function detectShellBleedWithEvents(script: string, action?: ShellBleedAction, sessionId?: string): Generator<AgentEvent, ShellBleedResult>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SSRF protection — validates URLs against private IP ranges, cloud metadata
3
+ * endpoints, and DNS-rebinding attacks.
4
+ */
5
+ export interface SsrfResult {
6
+ safe: boolean;
7
+ reason?: string;
8
+ resolvedIP?: string;
9
+ }
10
+ export declare function validateUrl(url: string): SsrfResult;
11
+ export type DnsResolver = (hostname: string) => Promise<string[]>;
12
+ export declare function validateUrlWithDns(url: string, resolver?: DnsResolver): Promise<SsrfResult>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Taint Tracker — dynamic information flow tracking during a single
3
+ * agent turn. Prevents tainted data from reaching restricted outputs.
4
+ *
5
+ * Five taint labels: externalNetwork, userInput, pii, secret, untrustedAgent.
6
+ * When values combine, the result inherits the union of all label sets.
7
+ */
8
+ export type TaintLabel = "externalNetwork" | "userInput" | "pii" | "secret" | "untrustedAgent";
9
+ export declare const ALL_TAINT_LABELS: readonly TaintLabel[];
10
+ /** Immutable set of taint labels attached to a tracked value. */
11
+ export declare class TaintSet {
12
+ private readonly labels;
13
+ constructor(labels?: Iterable<TaintLabel>);
14
+ /** Check if this set contains a specific label. */
15
+ has(label: TaintLabel): boolean;
16
+ /** Check if any of the given labels are present. */
17
+ hasAny(labels: TaintLabel[]): boolean;
18
+ /** Return the union of this set with another. */
19
+ union(other: TaintSet): TaintSet;
20
+ /** Number of taint labels. */
21
+ get size(): number;
22
+ /** True if no taint labels are set. */
23
+ get clean(): boolean;
24
+ /** Return labels as a sorted array (for serialization/logging). */
25
+ toArray(): TaintLabel[];
26
+ }
27
+ /** Convenience: create an empty (clean) taint set. */
28
+ export declare const CLEAN: TaintSet;
29
+ export interface OutputPolicy {
30
+ /** Human-readable name for this output channel. */
31
+ name: string;
32
+ /** Taint labels that are BLOCKED from reaching this output. */
33
+ blocked: TaintLabel[];
34
+ }
35
+ export declare class TaintTracker {
36
+ private values;
37
+ private policies;
38
+ /** Register a tracked value with initial taint labels. */
39
+ track(id: string, labels: TaintLabel[]): void;
40
+ /** Get the taint set for a tracked value. Returns CLEAN if unknown. */
41
+ getTaint(id: string): TaintSet;
42
+ /**
43
+ * Combine multiple tracked values. The result inherits the union
44
+ * of all taint label sets. Registers the result under the given id.
45
+ */
46
+ combine(resultId: string, sourceIds: string[]): TaintSet;
47
+ /** Propagate taint from one value to another (add, don't replace). */
48
+ propagate(fromId: string, toId: string): void;
49
+ /** Register an output policy (defines which labels are blocked). */
50
+ registerOutput(outputId: string, policy: OutputPolicy): void;
51
+ /**
52
+ * Check if a tracked value is allowed to reach a registered output.
53
+ * Returns { allowed, violations } where violations lists the blocked labels found.
54
+ */
55
+ checkOutput(valueId: string, outputId: string): {
56
+ allowed: boolean;
57
+ violations: TaintLabel[];
58
+ };
59
+ /** Number of tracked values. */
60
+ get size(): number;
61
+ /** Reset all tracked values (start of new agent turn). */
62
+ clear(): void;
63
+ }