@cybernetyx1/atlasflow-runtime 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.
@@ -0,0 +1,739 @@
1
+ import { c as AnyTool, d as AgentRuntimeConfig, C as CreatedAgent, W as WorkflowDef, E as EngineTool, R as Rule, e as AgentHooks, T as ToolDefinition, f as RawTool, S as Skill, g as ToolChoice, A as AgentEngine, h as CompactionConfig, i as EngineRunInput, j as EngineHooks, k as EngineRunResult } from './channel-Dv3Hv1ee.js';
2
+ export { l as AgentCreateContext, m as AgentDefinition, a as AgentProfile, n as ChannelAccepted, o as ChannelContext, b as ChannelDefinition, p as ChannelDispatch, q as ChannelMode, r as ChannelResult, s as ContextPack, t as ContextPackItem, u as DurabilityConfig, v as DurableExecutionMeta, D as DurableExecutionRunner, H as HookDecision, w as InvokeOptions, I as InvokeResult, P as ProviderModelSettings, x as ProviderSettings, y as RuleEnforcePoint, z as SlackRequestSignatureOptions, B as ToolApprovalPolicy, F as WorkflowContext, G as WorkflowDefSchema, J as WorkflowRunResult, K as WorkflowState, L as WorkflowStep, M as advanceWorkflow, N as applyProfile, O as approveGate, Q as createAgent, U as defaultEngine, V as defineAgent, X as defineAgentProfile, Y as defineChannel, Z as defineTool, _ as dispatchWorkflow, $ as genId, a0 as getDefaultPersistence, a1 as invokeAgent, a2 as isChannelDefinition, a3 as isCreatedAgent, a4 as isRawTool, a5 as parseWorkflowDef, a6 as rawTool, a7 as recoverRuns, a8 as recoverWorkflows, a9 as resolveAnyTool, aa as resolveTool, ab as startWorkflow, ac as verifyGithubWebhookSignature, ad as verifySlackRequestSignature, ae as waitingGate } from './channel-Dv3Hv1ee.js';
3
+ import * as v from 'valibot';
4
+ import { GenericSchema, InferOutput } from 'valibot';
5
+ import { b as SandboxFactory, c as SessionEnv, e as ShellResult, S as SandboxNetworkPolicy, C as Command, A as AtlasFs } from './command-kxrqWIH7.js';
6
+ export { B as BaseSandboxEnv, a as CommandExecutor, f as CommandExecutorResult, E as ExecOptions, F as FileStat, R as ResolvedSandboxAllowedUrl, g as ResolvedSandboxNetworkPolicy, h as SandboxAllowedUrl, i as SandboxAllowedUrlEntry, j as SandboxCascadeEntry, k as SandboxCascadeProvider, l as SandboxEnvHeaderRef, m as SandboxHeaderValue, n as SandboxHttpMethod, o as SandboxLifecycleDefinition, p as SandboxSessionContext, q as createCwdSessionEnv, r as createScopedSessionEnv, d as defineCommand, s as defineSandbox, t as isSandboxFactory, u as makeFs, v as mergeCommands, w as normalizeCommandExecutor, x as resolveSandboxNetworkPolicy, y as sandboxCascade, z as sandboxHeaderFromEnv, D as writeFileCreatingParents } from './command-kxrqWIH7.js';
7
+ import { E as EventBus, M as ModelConfig, T as ThinkingLevel, o as PromptImage, p as SessionStore, U as Usage, n as Message } from './index-UFTgKRK4.js';
8
+ export { q as AssistantMessage, A as AtlasEvent, C as CacheRetention, d as DurableStreamMessage, r as DurableStreamProducerState, e as DurableStreamProducerTuple, D as DurableStreamRecord, l as DurableStreamSubscriptionAckInput, k as DurableStreamSubscriptionClaim, h as DurableStreamSubscriptionCreateInput, s as DurableStreamSubscriptionError, t as DurableStreamSubscriptionErrorCode, u as DurableStreamSubscriptionLink, v as DurableStreamSubscriptionLinkType, j as DurableStreamSubscriptionRecord, i as DurableStreamSubscriptionResult, w as DurableStreamSubscriptionStatus, x as DurableStreamSubscriptionStoreBase, m as DurableStreamSubscriptionStreamInfo, y as DurableStreamSubscriptionType, z as EventSubscriber, I as InMemoryRunStore, B as InMemorySessionStore, F as InMemoryStreamStore, G as InMemorySubscriptionStore, K as KvLike, O as OperationKind, P as PersistenceAdapter, H as PersistenceAdapterOptions, R as RunRecord, a as RunStatus, J as RunStore, S as SessionData, L as StopReason, c as StreamAppendOptions, b as StreamCreateOptions, f as StreamProducerAppendResult, g as StreamProducerCloseResult, N as StreamProducerResult, Q as StreamStore, V as SubscriptionStore, W as ToolResultMessage, X as UserMessage, Y as WebhookDeliveryOptions, Z as WebhookHostResolver, _ as addUsage, $ as emptyUsage, a0 as inMemoryAdapter, a1 as isJsonStreamContentType, a2 as kvAdapter, a3 as normalizeStreamContentType, a4 as observe, a5 as streamMessageBytes } from './index-UFTgKRK4.js';
9
+ import { IFileSystem, BashOptions } from 'just-bash';
10
+ export { ProviderRegistration, ProviderRegistrationError, getRegisteredApiKey, getRegisteredStoreResponses, hasRegisteredProvider, registerProvider, resetProvidersForTests, resolveRegisteredModel } from './providers.js';
11
+ export { ApiProvider, getApiProvider, getApiProviders, registerApiProvider, unregisterApiProviders } from '@earendil-works/pi-ai';
12
+
13
+ /**
14
+ * Persona manifest — the frozen v1 schema (Atlas Brain compile target).
15
+ *
16
+ * A persona is DATA, not code: identity + loadout + connector slots, authored
17
+ * by the Brain UI (or by hand as JSON) and hydrated into a runnable agent by
18
+ * `personaAgent()`. This is the keystone of the Brain↔AtlasFlow interop:
19
+ * deploying a UI-built persona never requires writing TypeScript.
20
+ *
21
+ * Brain kind → manifest field
22
+ * ────────────────────────────────────────────
23
+ * Persona identity → identity.{role,disposition,voice,taste,instructions}
24
+ * Skills → loadout.skills (SKILL.md-compatible shape)
25
+ * Context packs → loadout.contextPacks (mount: context | sandbox)
26
+ * Standards → loadout.standards (advisory → system context)
27
+ * Rules → loadout.rules (binding → enforcement hooks)
28
+ * Workflows → loadout.workflows (gated, role-slotted; see workflow.ts)
29
+ * Sub-personas → loadout.personas (task-tool delegation targets)
30
+ * Triggers → loadout.triggers (webhook / cron intents)
31
+ * Connector slots → slots (credentials bound by the workspace, never carried)
32
+ * Provenance → provenance / per-artifact provenance (metadata only —
33
+ * AtlasFlow surfaces it, the Brain judges it)
34
+ */
35
+
36
+ declare const SlotSchema: v.ObjectSchema<{
37
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
38
+ readonly type: v.PicklistSchema<["credential", "mcp", "tool", "sandbox", "memory"], undefined>;
39
+ /** For credential slots: the env var the workspace must bind. */
40
+ readonly env: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
41
+ readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
42
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
43
+ }, undefined>;
44
+ declare const PersonaManifestSchema: v.ObjectSchema<{
45
+ /** Optional editor schema reference. Ignored by the runtime. */
46
+ readonly $schema: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
47
+ /** Manifest version. v1 is frozen; breaking changes bump it. */
48
+ readonly atlasflow: v.LiteralSchema<1, undefined>;
49
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
50
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
51
+ readonly identity: v.OptionalSchema<v.ObjectSchema<{
52
+ readonly role: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
53
+ readonly disposition: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
54
+ readonly voice: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
55
+ readonly taste: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
56
+ readonly instructions: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
57
+ }, undefined>, undefined>;
58
+ readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
59
+ readonly loadout: v.OptionalSchema<v.ObjectSchema<{
60
+ readonly skills: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
61
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
62
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
63
+ /** Alias accepted on import for agentskills.io round-tripping. */
64
+ readonly when_to_use: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
65
+ readonly body: v.StringSchema<undefined>;
66
+ readonly allowedTools: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
67
+ readonly provenance: v.OptionalSchema<v.PicklistSchema<["earned", "taught", "ingested", "researched", "inherited"], undefined>, "taught">;
68
+ }, undefined>, undefined>, undefined>;
69
+ readonly contextPacks: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
70
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
71
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
72
+ readonly version: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
73
+ readonly mount: v.OptionalSchema<v.PicklistSchema<["context", "sandbox"], undefined>, undefined>;
74
+ readonly items: v.ArraySchema<v.ObjectSchema<{
75
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
76
+ readonly content: v.StringSchema<undefined>;
77
+ }, undefined>, undefined>;
78
+ readonly provenance: v.OptionalSchema<v.PicklistSchema<["earned", "taught", "ingested", "researched", "inherited"], undefined>, "taught">;
79
+ }, undefined>, undefined>, undefined>;
80
+ readonly standards: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
81
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
82
+ readonly content: v.StringSchema<undefined>;
83
+ readonly provenance: v.OptionalSchema<v.PicklistSchema<["earned", "taught", "ingested", "researched", "inherited"], undefined>, "taught">;
84
+ }, undefined>, undefined>, undefined>;
85
+ readonly rules: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
86
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
87
+ readonly enforce: v.PicklistSchema<["before_prompt", "before_tool", "after_tool"], undefined>;
88
+ readonly tools: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
89
+ readonly pattern: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
90
+ readonly action: v.OptionalSchema<v.PicklistSchema<["block", "warn"], undefined>, "block">;
91
+ readonly message: v.StringSchema<undefined>;
92
+ readonly provenance: v.OptionalSchema<v.PicklistSchema<["earned", "taught", "ingested", "researched", "inherited"], undefined>, "taught">;
93
+ }, undefined>, undefined>, undefined>;
94
+ readonly workflows: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
95
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
96
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
97
+ readonly steps: v.SchemaWithPipe<readonly [v.ArraySchema<v.VariantSchema<"kind", [v.ObjectSchema<{
98
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
99
+ readonly kind: v.LiteralSchema<"prompt", undefined>;
100
+ readonly prompt: v.StringSchema<undefined>;
101
+ readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
102
+ readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
103
+ }, undefined>, v.ObjectSchema<{
104
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
105
+ readonly kind: v.LiteralSchema<"skill", undefined>;
106
+ readonly skill: v.StringSchema<undefined>;
107
+ readonly input: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
108
+ readonly persona: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
109
+ }, undefined>, v.ObjectSchema<{
110
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
111
+ readonly kind: v.LiteralSchema<"gate", undefined>;
112
+ readonly title: v.StringSchema<undefined>;
113
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
114
+ }, undefined>], undefined>, undefined>, v.MinLengthAction<({
115
+ id: string;
116
+ kind: "prompt";
117
+ prompt: string;
118
+ persona?: string | undefined;
119
+ model?: string | undefined;
120
+ } | {
121
+ id: string;
122
+ kind: "skill";
123
+ skill: string;
124
+ input?: string | undefined;
125
+ persona?: string | undefined;
126
+ } | {
127
+ id: string;
128
+ kind: "gate";
129
+ title: string;
130
+ description?: string | undefined;
131
+ })[], 1, undefined>]>;
132
+ readonly roleSlots: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
133
+ }, undefined>, undefined>, undefined>;
134
+ readonly personas: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
135
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
136
+ readonly model: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
137
+ readonly instructions: v.StringSchema<undefined>;
138
+ readonly provenance: v.OptionalSchema<v.PicklistSchema<["earned", "taught", "ingested", "researched", "inherited"], undefined>, "taught">;
139
+ }, undefined>, undefined>, undefined>;
140
+ readonly triggers: v.OptionalSchema<v.ObjectSchema<{
141
+ readonly webhook: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
142
+ readonly cron: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
143
+ }, undefined>, undefined>;
144
+ }, undefined>, undefined>;
145
+ readonly slots: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
146
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
147
+ readonly type: v.PicklistSchema<["credential", "mcp", "tool", "sandbox", "memory"], undefined>;
148
+ /** For credential slots: the env var the workspace must bind. */
149
+ readonly env: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
150
+ readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
151
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
152
+ }, undefined>, undefined>, undefined>;
153
+ readonly defaults: v.OptionalSchema<v.ObjectSchema<{
154
+ readonly thinkingLevel: v.OptionalSchema<v.PicklistSchema<["off", "minimal", "low", "medium", "high", "xhigh"], undefined>, undefined>;
155
+ readonly headless: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
156
+ readonly builtinTools: v.OptionalSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>, undefined>;
157
+ readonly compaction: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<false, undefined>, v.ObjectSchema<{
158
+ readonly threshold: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
159
+ readonly thresholdTokens: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
160
+ readonly keepRecent: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
161
+ }, undefined>], undefined>, undefined>;
162
+ readonly durability: v.OptionalSchema<v.ObjectSchema<{
163
+ readonly retry: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
164
+ readonly timeoutMs: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
165
+ }, undefined>, undefined>;
166
+ }, undefined>, undefined>;
167
+ /** Opaque Brain metadata (lineage, fork base, provenance summary). */
168
+ readonly provenance: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
169
+ }, undefined>;
170
+ type PersonaManifest = v.InferOutput<typeof PersonaManifestSchema>;
171
+ type PersonaSlot = v.InferOutput<typeof SlotSchema>;
172
+ declare function parsePersonaManifest(value: unknown): PersonaManifest;
173
+ interface PersonaBindings {
174
+ /** Sandbox for the persona's sandbox slot (workspace-bound, never carried). */
175
+ sandbox?: SandboxFactory | ((ctx: {
176
+ id: string;
177
+ env: Record<string, unknown>;
178
+ }) => SandboxFactory);
179
+ /**
180
+ * Extra tools bound by the workspace (e.g. MCP connections for mcp slots).
181
+ * Can be static, or a per-invocation factory so Workers can open MCP
182
+ * connections inside request scope and close them after the run settles.
183
+ * Kept for compatibility; prefer toolSlots for named connector slots.
184
+ */
185
+ tools?: PersonaToolsBinding;
186
+ /**
187
+ * Slot-scoped tool bindings keyed by manifest slot name. Use this for
188
+ * non-MCP integrations such as GitHub or Slack, and for multiple tool slots
189
+ * that must fail independently when one binding is missing.
190
+ */
191
+ toolSlots?: Record<string, PersonaToolsBinding>;
192
+ /** Override how manifest skills are exposed. Defaults to historical callable skill tools. */
193
+ skillLoading?: AgentRuntimeConfig["skillLoading"];
194
+ /** Override how manifest context packs are exposed. Defaults to historical eager context. */
195
+ contextLoading?: AgentRuntimeConfig["contextLoading"];
196
+ }
197
+ interface PersonaBindingContext {
198
+ id: string;
199
+ env: Record<string, unknown>;
200
+ manifest: PersonaManifest;
201
+ slot?: PersonaSlot;
202
+ }
203
+ interface PersonaToolBindingResult {
204
+ tools: AnyTool[];
205
+ /** Preferred cleanup hook for per-invocation resources. */
206
+ cleanup?: () => void | Promise<void>;
207
+ /** Alias for MCP-style connections. */
208
+ close?: () => Promise<void>;
209
+ }
210
+ type PersonaToolsBinding = AnyTool | AnyTool[] | PersonaToolBindingResult | ((ctx: PersonaBindingContext) => AnyTool | AnyTool[] | PersonaToolBindingResult | Promise<AnyTool | AnyTool[] | PersonaToolBindingResult>);
211
+ interface ResolvedPersonaToolBindings {
212
+ tools: AnyTool[];
213
+ toolsBySlot: Record<string, AnyTool[]>;
214
+ }
215
+ /** Validate that the workspace bound every required slot; throw listing gaps. */
216
+ declare function validateSlots(m: PersonaManifest, env: Record<string, unknown>, bindings?: PersonaBindings, resolvedTools?: ResolvedPersonaToolBindings): void;
217
+ /**
218
+ * Hydrate a persona manifest into a runnable agent. Slot validation happens
219
+ * at initialization (fail fast, before any model call).
220
+ */
221
+ declare function personaAgent(manifest: unknown, bindings?: PersonaBindings): CreatedAgent;
222
+ /** The persona's authored workflows, keyed by name (for createApp/executor). */
223
+ declare function personaWorkflows(manifest: unknown): Record<string, WorkflowDef>;
224
+ /**
225
+ * The persona's workflows as executor mounts: each carries the skills and
226
+ * default model the workflow's steps resolve against.
227
+ */
228
+ declare function personaWorkflowMounts(manifest: unknown): Record<string, {
229
+ def: WorkflowDef;
230
+ skills: {
231
+ name: string;
232
+ description: string;
233
+ body: string;
234
+ }[];
235
+ defaultModel: string;
236
+ defaultPersona: string;
237
+ profiles: {
238
+ name: string;
239
+ model?: string;
240
+ instructions: string;
241
+ }[];
242
+ }>;
243
+ /** The persona's trigger intents (manifest → deploy wiring). */
244
+ declare function personaTriggers(manifest: unknown): {
245
+ webhook?: boolean;
246
+ cron?: string;
247
+ };
248
+
249
+ /**
250
+ * Rule enforcement — the Atlas Brain normative·binding primitive at runtime.
251
+ *
252
+ * Declarative `Rule`s and programmatic `AgentHooks` compile into one guard
253
+ * with three enforcement points:
254
+ * before_prompt — blocks the run before any model call
255
+ * before_tool — blocks a tool call (the model sees the rule's message as
256
+ * a tool error and can adapt)
257
+ * after_tool — blocks a tool result from reaching the model
258
+ * `warn` rules emit a rule_triggered event and let the action proceed.
259
+ */
260
+
261
+ declare class RuleViolation extends Error {
262
+ rule: string;
263
+ code: string;
264
+ constructor(rule: string, message: string);
265
+ }
266
+ interface RuleGuard {
267
+ /** Throws RuleViolation when a before_prompt rule blocks. */
268
+ checkPrompt(text: string): Promise<void>;
269
+ /** Wrap a tool so before_tool/after_tool rules apply to every call. */
270
+ wrapTool(tool: EngineTool): EngineTool;
271
+ }
272
+ declare function makeRuleGuard(rules: Rule[], hooks: AgentHooks | undefined, bus: EventBus, runId: string | undefined): RuleGuard;
273
+
274
+ declare const MemorySearchParametersSchema: v.ObjectSchema<{
275
+ readonly query: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
276
+ readonly limit: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
277
+ readonly scope: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
278
+ }, undefined>;
279
+ type MemorySearchParameters = v.InferOutput<typeof MemorySearchParametersSchema>;
280
+ interface MemorySearchResult {
281
+ id?: string;
282
+ title?: string;
283
+ text: string;
284
+ score?: number;
285
+ metadata?: Record<string, unknown>;
286
+ }
287
+ interface MemoryConnectorOptions {
288
+ name?: string;
289
+ description?: string;
290
+ search: (args: MemorySearchParameters, signal?: AbortSignal) => MemorySearchResult[] | Promise<MemorySearchResult[]>;
291
+ }
292
+ /**
293
+ * Define a read-only memory retrieval tool for a persona `memory` slot.
294
+ *
295
+ * Memory stays workspace-bound: the manifest declares the slot, while the
296
+ * deployment supplies this tool through `bindings.toolSlots.<slotName>`.
297
+ */
298
+ declare function defineMemoryConnector(options: MemoryConnectorOptions): ToolDefinition<typeof MemorySearchParametersSchema>;
299
+
300
+ type HttpConnectionMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
301
+ interface HttpConnectionOperation {
302
+ name: string;
303
+ description: string;
304
+ method?: HttpConnectionMethod;
305
+ path: string;
306
+ /** JSON Schema for arguments passed to the operation. */
307
+ parameters?: Record<string, unknown>;
308
+ /** Args copied into URI template slots such as /repos/{owner}/{repo}. */
309
+ pathParams?: string[];
310
+ /** Args serialized as query parameters. Defaults to remaining args for GET/HEAD. */
311
+ queryParams?: string[];
312
+ /** Arg used as the request body. Defaults to remaining args for non-GET methods. */
313
+ bodyParam?: string;
314
+ /** Static or computed request body for operations with known payloads. */
315
+ body?: unknown | ((args: Record<string, unknown>, ctx: PersonaBindingContext) => unknown | Promise<unknown>);
316
+ headers?: Record<string, string> | ((ctx: PersonaBindingContext) => Record<string, string> | Promise<Record<string, string>>);
317
+ }
318
+ interface HttpConnectionOptions {
319
+ /** Connection/slot name, used as the default tool namespace. */
320
+ name: string;
321
+ /** Static endpoint root. Prefer baseUrlEnv for deployed apps. */
322
+ baseUrl?: string;
323
+ /** Env var holding the endpoint root. */
324
+ baseUrlEnv?: string;
325
+ headers?: Record<string, string> | ((ctx: PersonaBindingContext) => Record<string, string> | Promise<Record<string, string>>);
326
+ operations: HttpConnectionOperation[];
327
+ /**
328
+ * lazy: expose <name>__search and <name>__call only.
329
+ * direct: expose one tool per operation.
330
+ * both: expose both surfaces.
331
+ */
332
+ expose?: "lazy" | "direct" | "both";
333
+ fetch?: typeof fetch;
334
+ allowInsecureHttp?: boolean;
335
+ allowPrivateNetwork?: boolean;
336
+ }
337
+ declare function defineHttpConnection(options: HttpConnectionOptions): (ctx: PersonaBindingContext) => Promise<PersonaToolBindingResult>;
338
+
339
+ /**
340
+ * Built-in agent tools — read, write, edit, bash, grep, glob — implemented
341
+ * against the vendor-neutral SessionEnv, so they behave identically on the
342
+ * local sandbox, a remote connector (Docker/E2B/Daytona), or workerd.
343
+ *
344
+ * These are what make an AtlasFlow agent a *working* agent out of the box:
345
+ * any agent with a sandbox gets them automatically (config `builtinTools:
346
+ * false` opts out). The `task` tool is built in runtime.ts because it needs
347
+ * the engine; everything here needs only the sandbox.
348
+ */
349
+
350
+ interface BuiltinToolOptions {
351
+ /** Restrict to a subset of tool names (default: all). */
352
+ include?: string[];
353
+ /** Truncate tool output beyond this many characters (default 50_000). */
354
+ maxOutputChars?: number;
355
+ }
356
+ declare function builtinTools(env: SessionEnv, options?: BuiltinToolOptions): EngineTool[];
357
+ declare const BUILTIN_TOOL_NAMES: readonly ["read", "write", "edit", "bash", "grep", "glob", "task"];
358
+
359
+ /**
360
+ * MCP (Model Context Protocol) tool integration.
361
+ *
362
+ * `connectMcpServer` connects to an MCP server — a local process over stdio,
363
+ * or a remote server over streamable HTTP (with SSE fallback) — lists its
364
+ * tools, and returns them as RawTools usable directly in an agent's `tools`
365
+ * config. The connection's `close()` shuts the transport down.
366
+ */
367
+
368
+ interface McpServerOptions {
369
+ /** Executable to launch a stdio MCP server (e.g. "node", "npx"). */
370
+ command?: string;
371
+ args?: string[];
372
+ env?: Record<string, string>;
373
+ cwd?: string;
374
+ /** URL of a remote MCP server (streamable HTTP, with SSE fallback). */
375
+ url?: string;
376
+ /** Force a transport instead of inferring from command/url. */
377
+ transport?: "stdio" | "http" | "sse";
378
+ /** Extra headers for remote transports (e.g. authorization). */
379
+ headers?: Record<string, string>;
380
+ /** Client name reported to the server. */
381
+ name?: string;
382
+ /** Namespace tool names as `mcp__<prefix>__<tool>` to avoid collisions. */
383
+ prefix?: string;
384
+ /** Disable namespacing. Defaults to true for MCP safety. */
385
+ namespace?: boolean;
386
+ /** Additional request configuration for remote transports. */
387
+ requestInit?: RequestInit;
388
+ /** Custom fetch used by remote transports. */
389
+ fetch?: typeof fetch;
390
+ /** Per-request MCP timeout in milliseconds. */
391
+ timeoutMs?: number;
392
+ /** Reset request timeout when the server sends progress. */
393
+ resetTimeoutOnProgress?: boolean;
394
+ }
395
+ interface McpConnection {
396
+ name: string;
397
+ tools: RawTool[];
398
+ close(): Promise<void>;
399
+ }
400
+ declare function connectMcpServer(options: McpServerOptions): Promise<McpConnection>;
401
+
402
+ /**
403
+ * Runtime workspace context discovery.
404
+ *
405
+ * Agents should not have to hard-code every project instruction or local skill in
406
+ * their agent file. This discovers AGENTS.md/CLAUDE.md and lazy local skills from
407
+ * the sandbox cwd, providing a runtime context layer while
408
+ * keeping Atlas's persona/context-pack model intact.
409
+ */
410
+
411
+ interface WorkspaceSkill extends Skill {
412
+ readonly __atlasWorkspaceSkill: true;
413
+ readonly directory: string;
414
+ readonly skillMdPath: string;
415
+ }
416
+ interface DiscoveredSessionContext {
417
+ instructions?: string;
418
+ workspaceSkills: WorkspaceSkill[];
419
+ }
420
+ declare function isWorkspaceSkill(skill: Skill): skill is WorkspaceSkill;
421
+ declare function discoverSessionContext(env: SessionEnv, definitionSkills?: readonly Skill[]): Promise<DiscoveredSessionContext>;
422
+ declare function loadWorkspaceSkill(env: SessionEnv, skill: WorkspaceSkill): Promise<Skill>;
423
+ interface ParseSkillOptions {
424
+ directoryName: string;
425
+ path: string;
426
+ }
427
+ declare function parseSkillMarkdown(content: string, options: ParseSkillOptions): Skill;
428
+
429
+ /**
430
+ * Default virtual sandbox backed by just-bash.
431
+ *
432
+ * This gives agents a filesystem and shell without a host/container sandbox.
433
+ * It is intentionally in-memory and per session unless the caller supplies a
434
+ * Bash factory that shares its filesystem in the factory closure.
435
+ */
436
+
437
+ interface BashLike {
438
+ fs: IFileSystem;
439
+ exec(command: string, options?: {
440
+ cwd?: string;
441
+ env?: Record<string, string>;
442
+ signal?: AbortSignal;
443
+ }): Promise<ShellResult>;
444
+ getCwd(): string;
445
+ registerCommand?(command: {
446
+ name: string;
447
+ trusted?: boolean;
448
+ execute(args: string[], ctx?: {
449
+ signal?: AbortSignal;
450
+ }): Promise<ShellResult>;
451
+ }): void;
452
+ }
453
+ type BashFactory = () => BashLike | Promise<BashLike>;
454
+ interface VirtualSandboxOptions {
455
+ cwd?: string;
456
+ env?: Record<string, string>;
457
+ /**
458
+ * Network policy for shell network commands such as curl/wget. Header
459
+ * transforms are resolved outside the sandbox, so credentials do not enter
460
+ * the process environment.
461
+ */
462
+ network?: SandboxNetworkPolicy;
463
+ bash?: Omit<BashOptions, "cwd" | "env" | "fs">;
464
+ }
465
+ declare function bash(factory: BashFactory): SandboxFactory;
466
+ declare function bashFactoryToSessionEnv(factory: BashFactory): Promise<SessionEnv>;
467
+ declare function virtualSandbox(options?: VirtualSandboxOptions): SandboxFactory;
468
+
469
+ /**
470
+ * CallHandle — an awaitable that is also cancellable. `await session.prompt(...)`
471
+ * resolves the result; `.abort()` cancels in-flight model/tool work via the
472
+ * AbortSignal threaded into the engine.
473
+ */
474
+ interface CallHandle<T> extends PromiseLike<T> {
475
+ readonly signal: AbortSignal;
476
+ abort(reason?: unknown): void;
477
+ }
478
+ declare function makeCall<T>(run: (signal: AbortSignal) => Promise<T>, parentSignal?: AbortSignal): CallHandle<T>;
479
+
480
+ /**
481
+ * Session — one conversation thread with the model. Owns its message history
482
+ * (persisted via SessionStore) and exposes prompt / skill / task plus fs+shell.
483
+ */
484
+
485
+ interface RuntimeContext {
486
+ engine: AgentEngine;
487
+ model?: ModelConfig;
488
+ instructions?: string;
489
+ tools: EngineTool[];
490
+ skills: Map<string, Skill>;
491
+ thinkingLevel?: ThinkingLevel;
492
+ toolChoice?: ToolChoice;
493
+ env?: SessionEnv;
494
+ commands?: Command[];
495
+ sandboxTools?: (env: SessionEnv) => EngineTool[];
496
+ store: SessionStore;
497
+ bus: EventBus;
498
+ runId?: string;
499
+ agentName: string;
500
+ instanceId: string;
501
+ apiKey?: string;
502
+ /** Environment for provider credential resolution (threaded to the engine). */
503
+ envVars?: Record<string, unknown>;
504
+ /** Per-provider endpoint overrides (threaded to the engine). */
505
+ providers?: Record<string, {
506
+ baseUrl?: string;
507
+ headers?: Record<string, string>;
508
+ apiKey?: string;
509
+ }>;
510
+ compaction?: false | CompactionConfig;
511
+ }
512
+ interface CallOptions<TSchema extends GenericSchema = GenericSchema> {
513
+ result?: TSchema;
514
+ tools?: ToolDefinition[];
515
+ commands?: Command[];
516
+ model?: ModelConfig;
517
+ thinkingLevel?: ThinkingLevel;
518
+ toolChoice?: ToolChoice;
519
+ signal?: AbortSignal;
520
+ images?: PromptImage[];
521
+ }
522
+ interface Response<T = undefined> {
523
+ text: string;
524
+ data: T;
525
+ usage: Usage;
526
+ }
527
+ declare class Session {
528
+ #private;
529
+ readonly name: string;
530
+ readonly fs: AtlasFs;
531
+ constructor(name: string, ctx: RuntimeContext);
532
+ prompt(text: string, options?: CallOptions): CallHandle<Response>;
533
+ prompt<TSchema extends GenericSchema>(text: string, options: CallOptions<TSchema> & {
534
+ result: TSchema;
535
+ }): CallHandle<Response<InferOutput<TSchema>>>;
536
+ skill(ref: Skill | string, options?: CallOptions): CallHandle<Response<unknown>>;
537
+ task(text: string, options?: CallOptions): CallHandle<Response<unknown>>;
538
+ /** Branch this conversation: copy the current history into a new named session. */
539
+ fork(name: string): Promise<Session>;
540
+ shell(command: string, options?: {
541
+ cwd?: string;
542
+ timeoutMs?: number;
543
+ signal?: AbortSignal;
544
+ commands?: Command[];
545
+ }): CallHandle<ShellResult>;
546
+ delete(): Promise<void>;
547
+ /** Manually compact this session's history, keeping the most recent messages. */
548
+ compact(keepRecent?: number): Promise<void>;
549
+ }
550
+
551
+ /**
552
+ * Harness — the runtime an agent uses. Owns sessions, an out-of-band
553
+ * filesystem, and a shell. Built by the runtime from an agent's config.
554
+ */
555
+
556
+ declare class Harness {
557
+ #private;
558
+ readonly name: string;
559
+ readonly fs: AtlasFs;
560
+ constructor(name: string, ctx: RuntimeContext);
561
+ session(name?: string): Promise<Session>;
562
+ shell(command: string, options?: {
563
+ cwd?: string;
564
+ timeoutMs?: number;
565
+ signal?: AbortSignal;
566
+ commands?: Command[];
567
+ }): CallHandle<ShellResult>;
568
+ }
569
+
570
+ interface ToolApprovalRequest {
571
+ id: string;
572
+ baseId: string;
573
+ tool: string;
574
+ arguments: Record<string, unknown>;
575
+ reason?: string;
576
+ status: "pending" | "approved" | "rejected";
577
+ requestedAt: number;
578
+ decidedAt?: number;
579
+ consumedAt?: number;
580
+ resumeOnNextCall?: boolean;
581
+ note?: string;
582
+ }
583
+ interface ToolApprovalState {
584
+ kind: "tool_approval";
585
+ approvals: Record<string, ToolApprovalRequest>;
586
+ pending?: string;
587
+ }
588
+ declare class ToolApprovalRequiredError extends Error {
589
+ readonly runId: string;
590
+ readonly approval: ToolApprovalRequest;
591
+ code: string;
592
+ partialTranscript?: ToolApprovalPartialTranscript;
593
+ constructor(runId: string, approval: ToolApprovalRequest);
594
+ }
595
+ interface ToolApprovalPartialTranscript {
596
+ appended: Message[];
597
+ usage: Usage;
598
+ }
599
+ declare function isToolApprovalRequiredError(value: unknown): value is ToolApprovalRequiredError;
600
+
601
+ /**
602
+ * pi-ai implementation of AgentEngine.
603
+ *
604
+ * THIS IS THE ONLY FILE THAT IMPORTS pi-ai. It runs a streaming tool-calling
605
+ * agentic loop over pi-ai's `stream()`. To swap pi-ai for our own loop, write
606
+ * another AgentEngine and change the one reference in runtime.ts.
607
+ *
608
+ * Supports: streaming (text/thinking deltas), extended thinking (mapped to the
609
+ * provider's reasoning effort), and prompt caching (cacheRetention + sessionId).
610
+ */
611
+
612
+ declare class PiAgentEngine implements AgentEngine {
613
+ run(input: EngineRunInput, hooks: EngineHooks): Promise<EngineRunResult>;
614
+ }
615
+ /**
616
+ * Resolve the credential for a provider from an explicit env map. Known
617
+ * providers use their conventional variable; anything else falls back to
618
+ * `<PROVIDER>_API_KEY`.
619
+ */
620
+ declare function envApiKeyFor(provider: string, env: Record<string, unknown> | undefined): string | undefined;
621
+ declare class EngineError extends Error {
622
+ code: string;
623
+ constructor(code: string, message: string);
624
+ }
625
+
626
+ /**
627
+ * Cron triggers — a minimal 5-field cron matcher (minute hour day-of-month
628
+ * month day-of-week) plus the scheduler used by generated Node entries.
629
+ * Cloudflare entries instead export a `scheduled()` handler and let the
630
+ * platform fire it; both paths dispatch the same durable workflow runs.
631
+ *
632
+ * Supported syntax per field: asterisk, N, N-M, step suffixes (slash-S on a
633
+ * range or asterisk), and comma lists thereof. Names (JAN, MON) are not
634
+ * supported — use numbers.
635
+ */
636
+ declare function cronMatches(expr: string, date: Date): boolean;
637
+ interface CronJob {
638
+ /** 5-field cron expression (UTC). */
639
+ cron: string;
640
+ run: () => void | Promise<void>;
641
+ }
642
+ /**
643
+ * Start a minute-granularity scheduler (Node deploys). Fires each job whose
644
+ * expression matches the current UTC minute. Returns a stop function.
645
+ */
646
+ declare function startCronScheduler(jobs: CronJob[], opts?: {
647
+ onError?: (err: unknown, job: CronJob) => void;
648
+ }): () => void;
649
+
650
+ /**
651
+ * Testing utilities.
652
+ *
653
+ * Design note: a programmatic, API-free way to test agents.
654
+ * `fakeEngine` is an AgentEngine you script with canned turns, so you can unit
655
+ * test agent wiring, tools, structured results, and events without a real
656
+ * model. Inject it via `invokeAgent({ ..., engine: fakeEngine(...) })`.
657
+ */
658
+
659
+ interface FakeTurn {
660
+ text?: string;
661
+ toolCalls?: {
662
+ id?: string;
663
+ name: string;
664
+ arguments: Record<string, unknown>;
665
+ }[];
666
+ }
667
+ type FakeResponder = (input: EngineRunInput, turn: number) => FakeTurn;
668
+ type AgentEvalSeverity = "gate" | "warn";
669
+ interface AgentEvalExpect {
670
+ text?: string;
671
+ textIncludes?: string;
672
+ toolCalled?: string | string[];
673
+ noToolCalled?: string | string[];
674
+ toolResultIncludes?: string | string[] | Record<string, string>;
675
+ }
676
+ interface AgentEvalJudgeContext {
677
+ name: string;
678
+ agent: string;
679
+ message?: string;
680
+ payload?: unknown;
681
+ text: string;
682
+ runId: string;
683
+ events: Array<{
684
+ type?: string;
685
+ tool?: string;
686
+ }>;
687
+ toolResults: Array<{
688
+ tool: string;
689
+ text: string;
690
+ }>;
691
+ }
692
+ type AgentEvalJudgeResult = boolean | string | {
693
+ pass: boolean;
694
+ reason?: string;
695
+ score?: number;
696
+ metadata?: Record<string, unknown>;
697
+ };
698
+ type AgentEvalJudge = (ctx: AgentEvalJudgeContext) => AgentEvalJudgeResult | Promise<AgentEvalJudgeResult>;
699
+ interface AgentEvalCase {
700
+ name?: string;
701
+ agent?: string;
702
+ message?: string;
703
+ payload?: unknown;
704
+ turns?: FakeTurn[];
705
+ expect?: AgentEvalExpect;
706
+ /**
707
+ * Optional semantic judge. Return true or { pass: true } to pass. Return
708
+ * false, a string reason, or { pass: false } to fail. Use this to call a
709
+ * hosted judge model or any team-specific scorer from the eval module.
710
+ */
711
+ judge?: AgentEvalJudge;
712
+ /** "gate" failures fail the command; "warn" failures are reported but non-blocking. */
713
+ severity?: AgentEvalSeverity;
714
+ }
715
+ interface AgentEvalDef extends AgentEvalCase {
716
+ /** Dataset fan-out: each case inherits top-level agent/message/turns/expect defaults. */
717
+ cases?: AgentEvalCase[];
718
+ /** Alias for cases, for teams that store external datasets. */
719
+ dataset?: AgentEvalCase[];
720
+ }
721
+ declare function defineEval(def: AgentEvalDef): AgentEvalDef;
722
+ /** Build an AgentEngine that replays scripted turns (and runs real tools). */
723
+ declare function fakeEngine(responder: FakeResponder): AgentEngine;
724
+ interface SandboxConformanceOptions {
725
+ /** Stable session id passed to the SandboxFactory. */
726
+ id?: string;
727
+ /** Set false for providers that intentionally do not expose a POSIX shell. */
728
+ shell?: boolean;
729
+ /** Set false only while porting a provider that cannot enforce exec timeouts yet. */
730
+ timeout?: boolean;
731
+ }
732
+ /**
733
+ * Exercise the SessionEnv contract that built-in tools and context-pack mounts
734
+ * rely on. Connector packages can call this in their own tests to prove local,
735
+ * Docker, E2B, Daytona, Cloudflare, etc. behave the same at the AtlasFlow seam.
736
+ */
737
+ declare function assertSandboxConformance(factory: SandboxFactory, options?: SandboxConformanceOptions): Promise<void>;
738
+
739
+ export { AgentEngine, type AgentEvalCase, type AgentEvalDef, type AgentEvalExpect, type AgentEvalJudge, type AgentEvalJudgeContext, type AgentEvalJudgeResult, type AgentEvalSeverity, AgentHooks, AgentRuntimeConfig, AnyTool, AtlasFs, BUILTIN_TOOL_NAMES, type BashFactory, type BashLike, type BuiltinToolOptions, type CallHandle, type CallOptions, Command, CompactionConfig, CreatedAgent, type CronJob, type DiscoveredSessionContext, EngineError, EngineHooks, EngineRunInput, EngineRunResult, EngineTool, EventBus, type FakeResponder, type FakeTurn, Harness, type HttpConnectionMethod, type HttpConnectionOperation, type HttpConnectionOptions, type McpConnection, type McpServerOptions, type MemoryConnectorOptions, type MemorySearchParameters, MemorySearchParametersSchema, type MemorySearchResult, Message, ModelConfig, type PersonaBindingContext, type PersonaBindings, type PersonaManifest, PersonaManifestSchema, type PersonaSlot, type PersonaToolBindingResult, type PersonaToolsBinding, PiAgentEngine, PromptImage, RawTool, type ResolvedPersonaToolBindings, type Response, Rule, type RuleGuard, RuleViolation, type RuntimeContext, type SandboxConformanceOptions, SandboxFactory, SandboxNetworkPolicy, Session, SessionEnv, SessionStore, ShellResult, Skill, ThinkingLevel, type ToolApprovalRequest, ToolApprovalRequiredError, type ToolApprovalState, ToolChoice, ToolDefinition, Usage, type VirtualSandboxOptions, WorkflowDef, type WorkspaceSkill, assertSandboxConformance, bash, bashFactoryToSessionEnv, builtinTools, connectMcpServer, cronMatches, defineEval, defineHttpConnection, defineMemoryConnector, discoverSessionContext, envApiKeyFor, fakeEngine, isToolApprovalRequiredError, isWorkspaceSkill, loadWorkspaceSkill, makeCall, makeRuleGuard, parsePersonaManifest, parseSkillMarkdown, personaAgent, personaTriggers, personaWorkflowMounts, personaWorkflows, startCronScheduler, validateSlots, virtualSandbox };