@zenera/neo 1.1.54 → 1.1.56

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The five tools an agent gets. `search` and `load` are split because finding
2
+ * The six tools an agent gets. `search` and `load` are split because finding
3
3
  * is not reading — search returns stitched context the model never asked for,
4
4
  * and counting that as use would poison recency. `grep` is separate from
5
5
  * `search` because exactness is not a tuning of nearness: a ranking returns the
@@ -8,14 +8,17 @@
8
8
  * building it with three calls leaves the graph half-formed if the model stops
9
9
  * early. `forget` is separate because deleting rarely happens in the same
10
10
  * breath as creating, and a `forget` buried inside a truncated commit preview
11
- * would be both irreversible and invisible.
11
+ * would be both irreversible and invisible. `copy_file` is the only way a
12
+ * remembered file reaches the sandbox, which never mounts the memory.
12
13
  *
13
14
  * `audience` reaches the schema only when the binding grants more than one
14
15
  * label, and `sees` never does: an agent that could name its own audience
15
16
  * could read another agent's slice just by asking for it.
16
17
  */
17
18
  import { hash } from "../payload.js";
18
- import { MEMORY_COMMIT_TOOL, MEMORY_FORGET_TOOL, MEMORY_GREP_TOOL, MEMORY_LOAD_TOOL, MEMORY_SEARCH_TOOL, tool, withEffects, } from "../types.js";
19
+ import { MEMORY_COMMIT_TOOL, MEMORY_COPY_FILE_TOOL, MEMORY_FORGET_TOOL, MEMORY_GREP_TOOL, MEMORY_LOAD_TOOL, MEMORY_SEARCH_TOOL, tool, withEffects, } from "../types.js";
20
+ import { storedName } from "./files.js";
21
+ import { RevisionMismatch } from "./graph.js";
19
22
  import { GREP_FIELDS, grepMemory } from "./grep.js";
20
23
  import { renderRecollection } from "./render.js";
21
24
  import { canForget, canWrite, KIND_HELP, MemoryError, RELATION_HELP, } from "./types.js";
@@ -96,7 +99,7 @@ export function memoryTools(opts) {
96
99
  name: MEMORY_LOAD_TOOL,
97
100
  description: 'Read memories in full by id, using the ids from a ' +
98
101
  `${MEMORY_SEARCH_TOOL} legend. A remembered file comes back inline when it ` +
99
- 'is small, otherwise as a path under /memory you can open or run.',
102
+ `is small; to open or run it, copy it into the workspace with ${MEMORY_COPY_FILE_TOOL}.`,
100
103
  parameters: {
101
104
  type: 'object',
102
105
  properties: {
@@ -130,7 +133,7 @@ export function memoryTools(opts) {
130
133
  revision: l.node.revision,
131
134
  metadata: l.node.metadata,
132
135
  file: l.node.file
133
- ? { path: l.node.file.path, bytes: l.node.file.bytes }
136
+ ? { name: storedName(l.node.file), bytes: l.node.file.bytes }
134
137
  : undefined,
135
138
  content: l.content,
136
139
  })), { kind: 'memory_op', spec });
@@ -143,7 +146,7 @@ export function memoryTools(opts) {
143
146
  `instead of ${MEMORY_SEARCH_TOOL} when the answer has to be complete rather ` +
144
147
  'than close — whether something was already recorded, or where a name, path, ' +
145
148
  'id or command appears. This is the only correct way to search the memory ' +
146
- 'directly; never run a shell grep over /memory. Read a whole node with ' +
149
+ 'directly. Read a whole node with ' +
147
150
  `${MEMORY_LOAD_TOOL}.`,
148
151
  parameters: {
149
152
  type: 'object',
@@ -217,7 +220,7 @@ export function memoryTools(opts) {
217
220
  id: m.node.id,
218
221
  kind: m.node.kind,
219
222
  stale: m.stale || undefined,
220
- file: m.node.file?.path,
223
+ file: m.node.file && storedName(m.node.file),
221
224
  hits: m.hits.map((h) => ({ in: h.where, line: h.line, text: h.text })),
222
225
  more: m.more || undefined,
223
226
  })),
@@ -227,6 +230,57 @@ export function memoryTools(opts) {
227
230
  }, { kind: 'memory_op', spec });
228
231
  },
229
232
  }),
233
+ // The one way a remembered file reaches the sandbox. Memory is never
234
+ // mounted, so the box only ever holds the workspace and the project's
235
+ // read-only trees, and the files stay with the graph that explains them.
236
+ // Reading memory is enough to copy from it: the write is the workspace's.
237
+ tool({
238
+ name: MEMORY_COPY_FILE_TOOL,
239
+ description: 'Copies a remembered file into the workspace so a command can open or run it. ' +
240
+ `Give the id of a node that holds a file, from ${MEMORY_SEARCH_TOOL} or ` +
241
+ `${MEMORY_LOAD_TOOL}. The copy is yours to edit; remembering the edited ` +
242
+ `version is a new ${MEMORY_COMMIT_TOOL}.`,
243
+ parameters: {
244
+ type: 'object',
245
+ properties: {
246
+ id: { type: 'string', description: 'the node that holds the file' },
247
+ to: {
248
+ type: 'string',
249
+ description: 'where in the workspace to put it; the file’s own name ' +
250
+ '(<id>.<ext>) at the workspace root when omitted',
251
+ },
252
+ overwrite: {
253
+ type: 'boolean',
254
+ description: 'replace a file already at that path',
255
+ },
256
+ },
257
+ required: ['id'],
258
+ additionalProperties: false,
259
+ },
260
+ execute: async (args, tc) => {
261
+ if (!tc.services.files) {
262
+ return {
263
+ error: 'this agent has no workspace to copy into',
264
+ hint: `read the file inline with ${MEMORY_LOAD_TOOL} instead`,
265
+ };
266
+ }
267
+ try {
268
+ const { file, bytes } = await index.fileOf(args.id, binding.sees);
269
+ const path = await tc.services.files.write(args.to?.trim() || storedName(file), bytes, {
270
+ overwrite: args.overwrite,
271
+ });
272
+ return { id: args.id, path, bytes: bytes.byteLength, copied: true };
273
+ }
274
+ catch (err) {
275
+ if (err instanceof MemoryError) {
276
+ return refusal(err);
277
+ }
278
+ // The workspace's refusals — read-only, outside, already there —
279
+ // are things the model can fix by choosing another `to`.
280
+ return { error: err instanceof Error ? err.message : String(err) };
281
+ }
282
+ },
283
+ }),
230
284
  ];
231
285
  if (!canWrite(binding)) {
232
286
  return tools;
@@ -408,6 +462,7 @@ export function memoryTools(opts) {
408
462
  },
409
463
  execute: async (args, tc) => {
410
464
  const opId = memoryOpId(tc.state.runId, tc.callId);
465
+ index.refresh();
411
466
  const before = args.ids.flatMap((id) => {
412
467
  const node = index.graph.get(id);
413
468
  return node ? [{ id, kind: node.kind, revision: node.revision }] : [];
@@ -446,6 +501,12 @@ function refusal(err) {
446
501
  if (err instanceof MemoryError) {
447
502
  return { error: err.message, hint: err.hint };
448
503
  }
504
+ if (err instanceof RevisionMismatch) {
505
+ return {
506
+ error: err.message,
507
+ hint: `another run changed it; ${MEMORY_LOAD_TOOL} it again and commit against the new revision`,
508
+ };
509
+ }
449
510
  throw err;
450
511
  }
451
512
  function extractFilePath(raw) {
@@ -461,11 +522,11 @@ function extractFilePath(raw) {
461
522
  return '';
462
523
  }
463
524
  function source(tc, path) {
464
- if (!tc.services.resolveFile) {
525
+ if (!tc.services.files) {
465
526
  throw new MemoryError('this agent cannot remember files', 'commit the node without `file`, or give the agent a workspace');
466
527
  }
467
528
  try {
468
- return tc.services.resolveFile(path);
529
+ return tc.services.files.source(path);
469
530
  }
470
531
  catch (err) {
471
532
  if (err instanceof MemoryError) {
@@ -47,7 +47,7 @@ export declare class MemoryError extends Error {
47
47
  constructor(message: string, hint?: string);
48
48
  }
49
49
  export interface MemoryFile {
50
- /** what the agent sees, e.g. `/memory/01J8….py` — a mount path, not a host path */
50
+ /** `<id>.<ext>`; older graphs hold `/memory/<id>.<ext>` — read it through `storedName` */
51
51
  path: string;
52
52
  bytes: number;
53
53
  sha256: string;
@@ -46,7 +46,7 @@ export const KIND_HELP = {
46
46
  plan: 'an approach that worked, worth reusing on a similar request',
47
47
  fact: 'a durable truth about the environment or the domain',
48
48
  snippet: 'a short piece of code or configuration, too small to be a file',
49
- file: 'an artifact kept whole under /memory and re-runnable',
49
+ file: 'an artifact kept whole, to copy back into the workspace and run again',
50
50
  operation: 'an external call that was made — an endpoint, command or query',
51
51
  preference: 'a standing instruction from the user that applies to every run',
52
52
  };
@@ -348,30 +348,7 @@ export declare const projectSchema: z.ZodObject<{
348
348
  limit: z.ZodDefault<z.ZodInt>;
349
349
  }, z.core.$strict>]>>;
350
350
  }, z.core.$strict>>, unknown>>;
351
- sandbox: z.ZodOptional<z.ZodObject<{
352
- image: z.ZodOptional<z.ZodString>;
353
- build: z.ZodOptional<z.ZodObject<{
354
- dockerfile: z.ZodString;
355
- context: z.ZodOptional<z.ZodString>;
356
- }, z.core.$strict>>;
357
- cpus: z.ZodOptional<z.ZodNumber>;
358
- memory: z.ZodOptional<z.ZodInt>;
359
- network: z.ZodOptional<z.ZodEnum<{
360
- none: "none";
361
- host: "host";
362
- bridge: "bridge";
363
- }>>;
364
- workdir: z.ZodOptional<z.ZodString>;
365
- timeout: z.ZodOptional<z.ZodInt>;
366
- hardening: z.ZodOptional<z.ZodEnum<{
367
- strict: "strict";
368
- standard: "standard";
369
- }>>;
370
- user: z.ZodOptional<z.ZodString>;
371
- persist: z.ZodOptional<z.ZodBoolean>;
372
- env: z.ZodOptional<z.ZodArray<z.ZodString>>;
373
- keys: z.ZodOptional<z.ZodBoolean>;
374
- }, z.core.$strict>>;
351
+ sandbox: z.ZodOptional<z.ZodNever>;
375
352
  default: z.ZodOptional<z.ZodBoolean>;
376
353
  }, z.core.$strict>>;
377
354
  }, z.core.$strict>;
@@ -360,11 +360,16 @@ const agent = z
360
360
  .preprocess((v) => (typeof v === 'boolean' ? (v ? {} : undefined) : v), memoryBinding.optional())
361
361
  .optional(),
362
362
  /**
363
- * Overrides on the project's sandbox. An agent that overrides nothing
364
- * shares the container with everyone else, which is what a hand-off
365
- * usually wants; an agent that names its own image gets its own.
363
+ * Gone: a session has one sandbox, the project's, shared by every
364
+ * agent. Refused rather than ignored, so a project that relied on it
365
+ * hears where its settings have to go instead.
366
366
  */
367
- sandbox: sandbox.optional(),
367
+ sandbox: z
368
+ .never({
369
+ error: 'per-agent sandboxes were removed — a session has one sandbox, shared by ' +
370
+ "every agent; move these settings to the project's top-level `sandbox:`",
371
+ })
372
+ .optional(),
368
373
  /** entrypoint, when no top-level `default` is given */
369
374
  default: z.boolean().optional(),
370
375
  })
@@ -1,6 +1,7 @@
1
1
  import { Agent, AgentRegistry } from '../agent.ts';
2
2
  import type { Embedder } from '../embedding.ts';
3
3
  import { RunStream } from '../events.ts';
4
+ import type { WorkspaceFiles } from '../memory/files.ts';
4
5
  import { MemoryIndex } from '../memory/index.ts';
5
6
  import { ModelRegistry, type EmbeddingRef, type ModelRef, type ProviderSpec } from '../models/factory.ts';
6
7
  import type { PayloadStore } from '../payload.ts';
@@ -65,9 +66,7 @@ export interface ProjectOptions<TCtx = unknown> {
65
66
  memory?: MemoryIndex;
66
67
  /**
67
68
  * Another directory to keep the memory graph in, relative to the project
68
- * root when it is not absolute. Whoever sets it must mount that directory
69
- * as `/memory` too, or the agent reads its remembered files from one graph
70
- * and writes to another.
69
+ * root when it is not absolute.
71
70
  */
72
71
  memoryDir?: string;
73
72
  /**
@@ -77,8 +76,8 @@ export interface ProjectOptions<TCtx = unknown> {
77
76
  * warmed memory at once, which the directory lock otherwise forbids.
78
77
  */
79
78
  memoryReadOnly?: boolean;
80
- /** turns an agent-visible path into a host path, so files can be remembered */
81
- resolveFile?: (path: string) => string;
79
+ /** the agent's workspace, so files can be remembered and copied back */
80
+ files?: WorkspaceFiles;
82
81
  payloads?: PayloadStore;
83
82
  /** extra providers merged with the ones the project declares */
84
83
  skills?: SkillProvider[];
@@ -184,9 +183,8 @@ export declare class AgentProject<TCtx = unknown> {
184
183
  export declare function projectRegistry<TCtx>(config: ProjectConfig, opts?: ProjectOptions<TCtx>): ModelRegistry;
185
184
  /**
186
185
  * Where this project's memory lives, or `undefined` when it has none. Shared
187
- * with the front end, which has to mount the same directory into the sandbox:
188
- * two answers to this question would mean `/memory` pointing somewhere the
189
- * graph is not.
186
+ * with the front end, which reports and exports the same directory: two
187
+ * answers to this question would mean two graphs.
190
188
  *
191
189
  * `override` is the host pointing the run at another graph — `zen run
192
190
  * --memory`. It answers for a project that declares no memory at all, because
@@ -173,7 +173,7 @@ export class AgentProject {
173
173
  const runner = new AgentRunner({
174
174
  payloads: this.#options.payloads,
175
175
  memory: this.memory,
176
- resolveFile: this.#options.resolveFile,
176
+ files: this.#options.files,
177
177
  skills: [...this.skillProviders],
178
178
  ...overrides,
179
179
  });
@@ -530,9 +530,8 @@ function memoryFor(spec) {
530
530
  }
531
531
  /**
532
532
  * Where this project's memory lives, or `undefined` when it has none. Shared
533
- * with the front end, which has to mount the same directory into the sandbox:
534
- * two answers to this question would mean `/memory` pointing somewhere the
535
- * graph is not.
533
+ * with the front end, which reports and exports the same directory: two
534
+ * answers to this question would mean two graphs.
536
535
  *
537
536
  * `override` is the host pointing the run at another graph — `zen run
538
537
  * --memory`. It answers for a project that declares no memory at all, because
package/dist/runner.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Agent, AgentRegistry, type AgentOptions } from './agent.ts';
3
3
  import { type Architecture } from './architecture.ts';
4
4
  import { RunStream } from './events.ts';
5
5
  import { type IdClock } from './ids.ts';
6
+ import type { WorkspaceFiles } from './memory/files.ts';
6
7
  import type { MemoryIndex } from './memory/index.ts';
7
8
  import type { Model } from './model.ts';
8
9
  import { PayloadResolver, type PayloadStore } from './payload.ts';
@@ -10,7 +11,7 @@ import { Services } from './services.ts';
10
11
  import { type SkillProvider } from './skills.ts';
11
12
  import { type AgentState } from './state.ts';
12
13
  import { type HandoffNode, type TrajectoryNode } from './trajectory.ts';
13
- import { type Input, type TokenUsage } from './types.ts';
14
+ import { type Input, type ResumeAnswer, type TokenUsage } from './types.ts';
14
15
  /**
15
16
  * Collapsing history is two decisions, and they belong on different sides of
16
17
  * the I/O line: *which* nodes go (pure, so the kernel can stay pure) and *how*
@@ -42,8 +43,8 @@ export interface RunnerOptions<TCtx = unknown> {
42
43
  services?: Services;
43
44
  payloads?: PayloadStore | PayloadResolver;
44
45
  memory?: MemoryIndex;
45
- /** turns an agent-visible path into a host path, so files can be remembered */
46
- resolveFile?: (path: string) => string;
46
+ /** the agent's workspace, so files can be remembered and copied back */
47
+ files?: WorkspaceFiles;
47
48
  skills?: SkillProvider[];
48
49
  handoffPolicy?: HandoffPolicy;
49
50
  /** renders the nodes a policy selected; defaults to a structural note */
@@ -67,6 +68,15 @@ export interface RunOptions<T = string, TCtx = unknown> {
67
68
  signal?: AbortSignal;
68
69
  maxForkDepth?: number;
69
70
  }
71
+ export interface ResumeOptions<T = string, TCtx = unknown> extends RunOptions<T, TCtx> {
72
+ /**
73
+ * Answers to the calls the run is suspended on, by call id. A suspended call
74
+ * without an answer stays suspended: the run stops again at once.
75
+ */
76
+ answers?: Record<string, ResumeAnswer>;
77
+ }
78
+ /** What a new message says to a call still waiting for a person. */
79
+ export declare const SUPERSEDED_MESSAGE = "cancelled: the user sent a new message instead of answering this; continue without it";
70
80
  /**
71
81
  * The driver: it owns all nondeterminism and all I/O, and calls the kernel to
72
82
  * advance the state. Every checkpoint event carries a complete snapshot, so a
@@ -97,9 +107,16 @@ export declare class AgentRunner<TCtx = unknown> {
97
107
  * consumer sees (`run_created`) already carries a persistable snapshot.
98
108
  */
99
109
  run<T = string>(agent: Agent<TCtx> | string, input?: Input, opts?: RunOptions<T, TCtx>): RunStream<T>;
100
- /** Continues a persisted run from its own snapshot. */
101
- resume<T = string>(state: AgentState, opts?: RunOptions<T, TCtx>): RunStream<T>;
102
- /** Adds a follow-up message to a finished (or paused) run and continues it. */
110
+ /**
111
+ * Continues a persisted run from its own snapshot. A run that stopped
112
+ * `suspended` continues once `answers` answer its suspended calls.
113
+ */
114
+ resume<T = string>(state: AgentState, opts?: ResumeOptions<T, TCtx>): RunStream<T>;
115
+ /**
116
+ * Adds a follow-up message to a finished (or paused) run and continues it.
117
+ * Calls still suspended are cancelled first: the person chose to say
118
+ * something else rather than answer them.
119
+ */
103
120
  send<T = string>(state: AgentState, input: Input, opts?: RunOptions<T, TCtx>): RunStream<T>;
104
121
  }
105
122
  //# sourceMappingURL=runner.d.ts.map
package/dist/runner.js CHANGED
@@ -9,7 +9,7 @@ import { Services } from "./services.js";
9
9
  import { activeSkillNames } from "./skills.js";
10
10
  import { lastText } from "./state.js";
11
11
  import { lastOfType, projectMessages, } from "./trajectory.js";
12
- import { isToolReturn, stringify, zeroUsage, } from "./types.js";
12
+ import { isToolReturn, isToolSuspend, stringify, zeroUsage, } from "./types.js";
13
13
  const defaultJoinPolicy = {
14
14
  summarize: (child, services) => lastText(child, services.payloads),
15
15
  onBranchError: 'continue',
@@ -51,6 +51,8 @@ export function modelSummarizer(model, instructions = SUMMARY_INSTRUCTIONS) {
51
51
  },
52
52
  };
53
53
  }
54
+ /** What a new message says to a call still waiting for a person. */
55
+ export const SUPERSEDED_MESSAGE = 'cancelled: the user sent a new message instead of answering this; continue without it';
54
56
  // ---------------------------------------------------------------------------
55
57
  // Runner
56
58
  // ---------------------------------------------------------------------------
@@ -82,7 +84,7 @@ export class AgentRunner {
82
84
  new Services({
83
85
  payloads: opts.payloads,
84
86
  memory: opts.memory,
85
- resolveFile: opts.resolveFile,
87
+ files: opts.files,
86
88
  skills: opts.skills,
87
89
  clock: this.#clock,
88
90
  });
@@ -126,18 +128,59 @@ export class AgentRunner {
126
128
  // awaited, so building a RunStream costs nothing.
127
129
  return new RunStream(this.#start(agent, input, opts));
128
130
  }
129
- /** Continues a persisted run from its own snapshot. */
131
+ /**
132
+ * Continues a persisted run from its own snapshot. A run that stopped
133
+ * `suspended` continues once `answers` answer its suspended calls.
134
+ */
130
135
  resume(state, opts = {}) {
131
- return new RunStream(this.#drive(state, opts));
136
+ return new RunStream(this.#resumeAndDrive(state, opts));
132
137
  }
133
- /** Adds a follow-up message to a finished (or paused) run and continues it. */
138
+ /**
139
+ * Adds a follow-up message to a finished (or paused) run and continues it.
140
+ * Calls still suspended are cancelled first: the person chose to say
141
+ * something else rather than answer them.
142
+ */
134
143
  send(state, input, opts = {}) {
135
144
  return new RunStream(this.#sendAndDrive(state, input, opts));
136
145
  }
146
+ async *#resumeAndDrive(state, opts) {
147
+ const answered = yield* this.#answer(state, opts.answers ?? {}, opts);
148
+ return yield* this.#drive(answered, opts);
149
+ }
137
150
  async *#sendAndDrive(state, input, opts) {
138
- const next = await Kernel.applyUserInput(state, input, this.#env(opts));
151
+ const cancel = {};
152
+ for (const s of state.suspended ?? []) {
153
+ cancel[s.callId] = { status: 'cancelled', message: SUPERSEDED_MESSAGE };
154
+ }
155
+ const answered = yield* this.#answer(state, cancel, opts);
156
+ const next = await Kernel.applyUserInput(answered, input, this.#env(opts));
139
157
  return yield* this.#drive(next, opts);
140
158
  }
159
+ /** Applies answers to suspended calls; answers to anything else are ignored. */
160
+ async *#answer(initial, answers, opts) {
161
+ const env = this.#env(opts);
162
+ let state = initial;
163
+ for (const s of initial.suspended ?? []) {
164
+ const answer = answers[s.callId];
165
+ if (!answer) {
166
+ continue;
167
+ }
168
+ if (answer.status === 'resolved' && 'rerun' in answer) {
169
+ state = Kernel.releaseSuspension(state, s.callId);
170
+ continue;
171
+ }
172
+ const outcome = answer.status === 'resolved'
173
+ ? { output: stringify(answer.payload), isError: false }
174
+ : { output: answer.message ?? 'cancelled: nobody answered', isError: true };
175
+ const was = state;
176
+ state = await Kernel.applyToolResult(state, s.callId, outcome, env);
177
+ const node = appended(was, state).find((n) => n.type === 'tool_result');
178
+ if (node) {
179
+ yield tag(state, undefined, { type: 'after_tool_call', state, node });
180
+ }
181
+ }
182
+ return state;
183
+ }
141
184
  #env(opts) {
142
185
  return {
143
186
  services: this.services,
@@ -207,11 +250,23 @@ export class AgentRunner {
207
250
  break;
208
251
  }
209
252
  case 'tools': {
253
+ // A suspended call waits for `resume`; when nothing else is left
254
+ // to run, the run stops here and says what it waits for.
255
+ const waiting = new Set((state.suspended ?? []).map((x) => x.callId));
256
+ const runnable = action.calls.filter((c) => !waiting.has(c.callId));
257
+ if (!runnable.length) {
258
+ return yield* this.#finish(state, branch, 'suspended');
259
+ }
210
260
  const tools = await Kernel.resolveTools(state, this.registry, env);
211
- for (const call of action.calls) {
261
+ for (const call of runnable) {
212
262
  yield tag(state, branch, { type: 'before_tool_call', state, call });
213
263
  const was = state;
214
- const outcome = await this.#runTool(state, tools, call, opts);
264
+ const ran = await this.#runTool(state, tools, call, opts);
265
+ if ('suspend' in ran) {
266
+ state = Kernel.applySuspension(state, call, ran.suspend, this.#clock.now());
267
+ continue;
268
+ }
269
+ const outcome = ran;
215
270
  state = await Kernel.applyToolResult(state, call.callId, outcome, env);
216
271
  const added = appended(was, state);
217
272
  const node = added.find((n) => n.type === 'tool_result');
@@ -465,6 +520,15 @@ export class AgentRunner {
465
520
  services: this.services,
466
521
  signal: opts.signal,
467
522
  });
523
+ if (isToolSuspend(out)) {
524
+ // A branch runs alongside its siblings and is joined when all end:
525
+ // there is no run of its own to stop and resume.
526
+ // Its message still reaches the model, which can pass it on.
527
+ return opts.branch
528
+ ? fail(`error: ${def.name} needs a person and cannot wait inside a fork branch` +
529
+ (out.spec.message ? `: ${out.spec.message}` : ''))
530
+ : { suspend: out.spec };
531
+ }
468
532
  const effects = isToolReturn(out) ? out.effects : [];
469
533
  const value = isToolReturn(out) ? out.output : out;
470
534
  return {
@@ -1,5 +1,6 @@
1
1
  import { PayloadResolver, type PayloadStore } from './payload.ts';
2
2
  import { type IdClock } from './ids.ts';
3
+ import type { WorkspaceFiles } from './memory/files.ts';
3
4
  import type { MemoryIndex } from './memory/index.ts';
4
5
  import type { SkillProvider } from './skills.ts';
5
6
  /**
@@ -18,12 +19,13 @@ export declare class Services {
18
19
  /** the one memory graph, when the project has one */
19
20
  readonly memory?: MemoryIndex;
20
21
  /**
21
- * Turns a path the agent can see into a host path, for the one tool that
22
- * needs it: remembering a file. Supplied by whoever built the workspace,
23
- * because only it knows the mounts. Without it, files cannot be
24
- * remembered — which is a refusal, not a crash.
22
+ * The agent's workspace, for the two memory tools that cross into it:
23
+ * remembering a file reads from it, and copying a remembered file back
24
+ * writes to it — memory is never mounted, so that copy is the only way its
25
+ * files reach the sandbox. Supplied by whoever built the workspace, because
26
+ * only it knows the mounts. Without it both are refusals, not crashes.
25
27
  */
26
- readonly resolveFile?: (path: string) => string;
28
+ readonly files?: WorkspaceFiles;
27
29
  /** the driver's clock, so a tool that stamps a node stays replayable */
28
30
  readonly clock: IdClock;
29
31
  constructor(opts?: {
@@ -31,7 +33,7 @@ export declare class Services {
31
33
  memory?: MemoryIndex;
32
34
  skills?: SkillProvider[];
33
35
  clock?: IdClock;
34
- resolveFile?: (path: string) => string;
36
+ files?: WorkspaceFiles;
35
37
  });
36
38
  skillProvider(id: string): SkillProvider;
37
39
  hasMemory(): boolean;
package/dist/services.js CHANGED
@@ -18,12 +18,13 @@ export class Services {
18
18
  /** the one memory graph, when the project has one */
19
19
  memory;
20
20
  /**
21
- * Turns a path the agent can see into a host path, for the one tool that
22
- * needs it: remembering a file. Supplied by whoever built the workspace,
23
- * because only it knows the mounts. Without it, files cannot be
24
- * remembered — which is a refusal, not a crash.
21
+ * The agent's workspace, for the two memory tools that cross into it:
22
+ * remembering a file reads from it, and copying a remembered file back
23
+ * writes to it — memory is never mounted, so that copy is the only way its
24
+ * files reach the sandbox. Supplied by whoever built the workspace, because
25
+ * only it knows the mounts. Without it both are refusals, not crashes.
25
26
  */
26
- resolveFile;
27
+ files;
27
28
  /** the driver's clock, so a tool that stamps a node stays replayable */
28
29
  clock;
29
30
  #skills = new Map();
@@ -31,7 +32,7 @@ export class Services {
31
32
  const p = opts.payloads ?? new InMemoryPayloadStore();
32
33
  this.payloads = p instanceof PayloadResolver ? p : new PayloadResolver(p);
33
34
  this.memory = opts.memory;
34
- this.resolveFile = opts.resolveFile;
35
+ this.files = opts.files;
35
36
  this.clock = opts.clock ?? systemClock;
36
37
  for (const s of opts.skills ?? []) {
37
38
  this.#skills.set(s.id, s);
package/dist/state.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { PayloadResolver } from './payload.ts';
2
2
  import { type TrajectoryNode } from './trajectory.ts';
3
- import type { JsonSchema, TokenUsage } from './types.ts';
3
+ import type { JsonSchema, Suspension, TokenUsage } from './types.ts';
4
4
  export type RunPhase =
5
5
  /** initial context built, nothing executed */
6
6
  'created'
@@ -56,6 +56,11 @@ export interface AgentState {
56
56
  callId: string;
57
57
  branches: string[];
58
58
  };
59
+ /**
60
+ * Pending tool calls the run is suspended on, waiting for a person (see
61
+ * `suspend`). Each is also in `pendingToolCalls`; `runner.resume` answers them.
62
+ */
63
+ suspended?: Suspension[];
59
64
  /** derived cache; always recomputable from the trajectory */
60
65
  usage: TokenUsage;
61
66
  /** serialized user context (must be JSON) */
@@ -69,7 +74,8 @@ export interface RunResult<T = string> {
69
74
  agent: string;
70
75
  state: AgentState;
71
76
  usage: TokenUsage;
72
- stopReason: 'final' | 'aborted' | 'failed';
77
+ /** suspended: waiting on `state.suspended`; `runner.resume` continues it */
78
+ stopReason: 'final' | 'aborted' | 'failed' | 'suspended';
73
79
  }
74
80
  /**
75
81
  * Structural check for a rehydrated state. There is no prototype to restore —