@sixb/agent 0.2.5 → 0.2.7

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 (70) hide show
  1. package/dist/agent-prompt.d.ts +19 -3
  2. package/dist/agent-prompt.d.ts.map +1 -1
  3. package/dist/background-commands.d.ts +6 -2
  4. package/dist/background-commands.d.ts.map +1 -1
  5. package/dist/computer-runner.d.ts +12 -3
  6. package/dist/computer-runner.d.ts.map +1 -1
  7. package/dist/context-compaction.d.ts.map +1 -1
  8. package/dist/conversation-messages.d.ts +1 -1
  9. package/dist/conversation-messages.d.ts.map +1 -1
  10. package/dist/errors.d.ts +17 -2
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +693 -365
  15. package/dist/index.js.map +25 -25
  16. package/dist/login-shell.d.ts +18 -2
  17. package/dist/login-shell.d.ts.map +1 -1
  18. package/dist/model-adapters.d.ts +7 -2
  19. package/dist/model-adapters.d.ts.map +1 -1
  20. package/dist/model-lines.d.ts +1 -0
  21. package/dist/model-lines.d.ts.map +1 -1
  22. package/dist/run-agent-turn.d.ts +0 -4
  23. package/dist/run-agent-turn.d.ts.map +1 -1
  24. package/dist/run-child.d.ts +21 -4
  25. package/dist/run-child.d.ts.map +1 -1
  26. package/dist/run-conversation-turn.d.ts +10 -4
  27. package/dist/run-conversation-turn.d.ts.map +1 -1
  28. package/dist/run-environment.d.ts +15 -6
  29. package/dist/run-environment.d.ts.map +1 -1
  30. package/dist/run-fate.d.ts +2 -2
  31. package/dist/run-fate.d.ts.map +1 -1
  32. package/dist/run-sandbox.d.ts +39 -1
  33. package/dist/run-sandbox.d.ts.map +1 -1
  34. package/dist/run-subagent.d.ts.map +1 -1
  35. package/dist/sandbox-api-context.d.ts.map +1 -1
  36. package/dist/subagent-continuation.d.ts +13 -4
  37. package/dist/subagent-continuation.d.ts.map +1 -1
  38. package/dist/subagent-tools.d.ts +29 -2
  39. package/dist/subagent-tools.d.ts.map +1 -1
  40. package/dist/tools/bash.d.ts +1 -1
  41. package/dist/tools/bash.d.ts.map +1 -1
  42. package/dist/tools/model-spec.d.ts +2 -1
  43. package/dist/tools/model-spec.d.ts.map +1 -1
  44. package/dist/types.d.ts +9 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/package.json +6 -6
  47. package/src/agent-prompt.ts +150 -42
  48. package/src/background-commands.ts +63 -19
  49. package/src/background-notices.ts +3 -2
  50. package/src/computer-runner.ts +135 -80
  51. package/src/context-compaction.ts +1 -0
  52. package/src/conversation-messages.ts +11 -4
  53. package/src/errors.ts +18 -2
  54. package/src/index.ts +7 -2
  55. package/src/login-shell.ts +30 -3
  56. package/src/model-adapters.ts +32 -4
  57. package/src/model-lines.ts +1 -1
  58. package/src/run-agent-turn.ts +25 -3
  59. package/src/run-child.ts +52 -5
  60. package/src/run-conversation-turn.ts +50 -12
  61. package/src/run-environment.ts +95 -24
  62. package/src/run-fate.ts +8 -2
  63. package/src/run-sandbox.ts +110 -1
  64. package/src/run-subagent.ts +17 -7
  65. package/src/sandbox-api-context.ts +7 -1
  66. package/src/subagent-continuation.ts +33 -7
  67. package/src/subagent-tools.ts +141 -27
  68. package/src/tools/bash.ts +10 -11
  69. package/src/tools/model-spec.ts +3 -3
  70. package/src/types.ts +9 -0
@@ -132,7 +132,11 @@ export async function runSubagent(input: {
132
132
  : {}),
133
133
  })
134
134
  const sandboxReadiness = monitorSandboxReadiness(context.sandboxReady)
135
- const abortSignal = AbortSignal.any([runtime.signal, sandboxReadiness.signal])
135
+ const abortSignal = AbortSignal.any([
136
+ runtime.signal,
137
+ sandboxReadiness.signal,
138
+ ...(context.environmentFailureSignal ? [context.environmentFailureSignal] : []),
139
+ ])
136
140
  let chunkIndex = 0
137
141
  const generation = await runModelLoop({
138
142
  model: plan.model,
@@ -177,6 +181,7 @@ export async function runSubagent(input: {
177
181
  pauseAfterStep: async () =>
178
182
  inbox.deferred !== undefined || (await input.session.heldCalls.holdsRun()),
179
183
  }).catch((error: unknown) => {
184
+ context.environmentFailureSignal?.throwIfAborted()
180
185
  throw subagentContextFailure(error, run) ?? error
181
186
  })
182
187
  const work = subagentWorkMessages(
@@ -264,7 +269,8 @@ async function settleSubagent(
264
269
  * Keep the child's outcome: its answer, what it wrote under `out/`, and what it did as its thread's
265
270
  * next message. A paused child keeps its files too, for the run that continues it; `wait`
266
271
  * hands over only a finished child's, as an unfinished one's would pass for complete. Its `out/`
267
- * is stored even when its workspace is kept: a continuation that finds it lost gets it back.
272
+ * is stored even when its workspace is kept: a continuation that finds it lost gets it back. A
273
+ * child in its parent's workspace stores none: what it changed is there already.
268
274
  */
269
275
  async function finishSubagent(input: {
270
276
  readonly context: AgentTurnContext
@@ -281,11 +287,13 @@ async function finishSubagent(input: {
281
287
  readonly text?: string
282
288
  }): Promise<SubagentRunRecord> {
283
289
  const { context, run } = input
284
- const outputs = await storeChildOutputs({
285
- files: input.runFiles,
286
- handed: run.spec.files ?? [],
287
- signal: input.abortSignal,
288
- })
290
+ const outputs: Awaited<ReturnType<typeof storeChildOutputs>> = input.runFiles.inParentWorkspace
291
+ ? { files: [] }
292
+ : await storeChildOutputs({
293
+ files: input.runFiles,
294
+ handed: run.spec.files ?? [],
295
+ signal: input.abortSignal,
296
+ })
289
297
  input.runtime.assertCanContinue()
290
298
 
291
299
  // Before the terminal write, and after out/ was read: a paused child's workspace is kept for
@@ -377,11 +385,13 @@ function subagentWorkMessages(
377
385
  }
378
386
 
379
387
  function assertSubagentCanFinalize(input: {
388
+ readonly context: AgentTurnContext
380
389
  readonly runtime: AgentTurnRuntime
381
390
  readonly sandboxReadiness: ReturnType<typeof monitorSandboxReadiness>
382
391
  }): void {
383
392
  throwIfExecutionLost(input.runtime.sourceSignal)
384
393
  input.sandboxReadiness.throwIfFailed()
394
+ input.context.environmentFailureSignal?.throwIfAborted()
385
395
  input.runtime.assertCanContinue()
386
396
  }
387
397
 
@@ -130,12 +130,18 @@ export async function prepareAgentSandboxApiContext(
130
130
  { path: join(libDir, "search.mjs"), contents: SEARCH_SCRIPT_SOURCE, mode: 0o644 },
131
131
  { path: runContextPath, contents: runContext },
132
132
  { path: runtimeProbePath, contents: "first\nsixb-runtime-probe\nthird\n", mode: 0o644 },
133
+ // Bash reads this file in every non-interactive shell, nested ones included. Adding the CLI only
134
+ // when PATH lacks it leaves a nested shell's PATH as its parent ordered it: `bun run <script>`
135
+ // puts `node_modules/.bin` first, so a project's own `sixb` keeps running its scripts.
133
136
  {
134
137
  path: bashEnvPath,
135
138
  contents: [
136
139
  "# Installed by Sixb for every sandboxed bash command.",
137
140
  `if [ -n "\${SIXB_BIN_DIR:-}" ]; then`,
138
- ' export PATH="$SIXB_BIN_DIR:$PATH"',
141
+ ' case ":$PATH:" in',
142
+ ' *":$SIXB_BIN_DIR:"*) ;;',
143
+ ' *) export PATH="$SIXB_BIN_DIR:$PATH" ;;',
144
+ " esac",
139
145
  "fi",
140
146
  "export SIXB_BASH_ENV_READY=1",
141
147
  "",
@@ -26,28 +26,54 @@ export interface SubagentHistory extends AgentTurnHistory {
26
26
  * back to its new sandbox, and when it continues. It stays in
27
27
  * the thread, so a later continuation replays the same bytes.
28
28
  *
29
- * A child whose workspace is kept finds it as it left it, and is told nothing about it here. If
30
- * its files turn out lost, its system prompt says so, as a turn's does.
29
+ * A child whose workspace is kept, its own or its parent's, finds it as it left it, and is told
30
+ * nothing about it here. If its own workspace's files turn out lost, its system prompt says so, as
31
+ * a turn's does; if its parent's was recreated after it paused, this message says so.
31
32
  */
32
33
  export function continuationTrigger(input: {
33
34
  /** The outcomes as the child reads them, without their caller, or the answer's `mail` part. */
34
35
  readonly goesOnWith: readonly AgentMessagePart[]
35
36
  readonly paused: SubagentRunRecord
36
- /** Whether the sandbox provider keeps the child's workspace while it pauses. */
37
- readonly keepsWorkspace: boolean
37
+ readonly workspace: ContinuationWorkspace
38
38
  readonly createdAt: Date
39
39
  readonly settings: SentSettings
40
40
  }): readonly AgentMessagePart[] {
41
+ const told =
42
+ input.workspace === "restarted"
43
+ ? sandboxRestarted(input.paused)
44
+ : input.workspace === "left-parent"
45
+ ? LEFT_PARENT_WORKSPACE
46
+ : input.workspace === "parent-reset"
47
+ ? PARENT_WORKSPACE_RESET
48
+ : undefined
49
+
41
50
  return [
42
51
  ...input.goesOnWith,
43
52
  ...(input.paused.result?.unread ?? []).map((mail) => mailPart(mail)),
44
- ...(input.keepsWorkspace
45
- ? []
46
- : [{ type: "text" as const, text: sandboxRestarted(input.paused) }]),
53
+ ...(told === undefined ? [] : [{ type: "text" as const, text: told }]),
47
54
  { type: "text", text: `\n\n${renderCurrentTime(input.createdAt, input.settings)}` },
48
55
  ]
49
56
  }
50
57
 
58
+ /**
59
+ * Where a paused child continues: in its parent's workspace again, as it left it (`parent`) or
60
+ * recreated since (`parent-reset`); in its own sandbox, kept as it left it (`kept`) or started
61
+ * again (`restarted`); or, after working in its parent's workspace, in a blank sandbox of its own
62
+ * (`left-parent`), as once the conversation moved.
63
+ */
64
+ export type ContinuationWorkspace = "parent" | "parent-reset" | "kept" | "restarted" | "left-parent"
65
+
66
+ /** Whether a continuation runs in its parent's workspace, which the turn lends it. */
67
+ export function continuesInParentWorkspace(workspace: ContinuationWorkspace): boolean {
68
+ return workspace === "parent" || workspace === "parent-reset"
69
+ }
70
+
71
+ const PARENT_WORKSPACE_RESET =
72
+ "Your parent's workspace was recreated while you were paused: the changes you made there are gone. You still work in it, on its files as they are now: inspect them before relying on earlier tool results."
73
+
74
+ const LEFT_PARENT_WORKSPACE =
75
+ "You no longer work in your parent's workspace: you continue in a blank sandbox of your own, and the changes you made there are not here."
76
+
51
77
  function sandboxRestarted(paused: SubagentRunRecord): string {
52
78
  const outputsError = paused.result?.filesError
53
79
  return outputsError === undefined
@@ -56,7 +56,11 @@ import { ChildMailClosedError, FamilyMailbox } from "./family-mailbox"
56
56
  import { agentToolErrorText } from "./model-adapters"
57
57
  import { renderModelLine } from "./model-lines"
58
58
  import type { TurnChildren } from "./run-agent-turn"
59
- import { continuationTrigger } from "./subagent-continuation"
59
+ import {
60
+ type ContinuationWorkspace,
61
+ continuationTrigger,
62
+ continuesInParentWorkspace,
63
+ } from "./subagent-continuation"
60
64
  import type { WaitableChildren } from "./tools/background"
61
65
  import type { AgentRunFiles, AgentRunSettings } from "./types"
62
66
 
@@ -106,6 +110,8 @@ export interface SpawnSubagentInput {
106
110
  readonly maxSteps?: number
107
111
  /** Files and directories in the parent's sandbox, copied into the child's at the same paths. */
108
112
  readonly files?: readonly string[]
113
+ /** The child gets no `edit` and no `write` tool: it leaves the files as they are. */
114
+ readonly readOnly?: boolean
109
115
  }
110
116
 
111
117
  export interface SpawnSubagentOutput {
@@ -240,7 +246,14 @@ export class SubagentCoordinator {
240
246
  * it claims the child's run, opens its session and environment, and records its fate.
241
247
  * Starting a run already running is a no-op.
242
248
  */
243
- private readonly startChild: (run: SubagentRunRecord, family: FamilyMailbox) => void
249
+ private readonly startChild: (
250
+ run: SubagentRunRecord,
251
+ family: FamilyMailbox,
252
+ /** It runs in the turn's workspace, which the turn lends it. */
253
+ inParentWorkspace: boolean
254
+ ) => void,
255
+ /** When the parent conversation last moved workspaces, so paused child sandboxes know. */
256
+ private readonly movedAt?: Date
244
257
  ) {
245
258
  this.models = delegation.models
246
259
  }
@@ -293,14 +306,15 @@ export class SubagentCoordinator {
293
306
  for (const { child, outcomes } of paused) {
294
307
  signal.throwIfAborted()
295
308
  await this.clearDeadAttempts(child, signal)
296
- const { spec, continuation } = this.continuationOf(child, outcomes)
309
+ const workspace = await this.continuationWorkspace(child)
310
+ const { spec, continuation } = this.continuationOf(child, outcomes, workspace)
297
311
  await this.admitInTurn(() =>
298
312
  this.admit(
299
313
  createSubagentRunId(this.parentRun.id, child.spawnKey),
300
314
  child.spawnKey,
301
315
  spec,
302
316
  signal,
303
- continuation
317
+ { ...continuation, lends: continuesInParentWorkspace(workspace) }
304
318
  )
305
319
  )
306
320
  }
@@ -389,6 +403,7 @@ export class SubagentCoordinator {
389
403
  ...modelChoice(this.models).advice,
390
404
  OMIT_MODEL,
391
405
  `Pass files to copy files or directories of your sandbox into the child's, at the same paths, before it starts. What the child writes to out/ comes back with wait's result when it finishes, which lists where each file is.`,
406
+ "Pass readOnly for a review or an investigation that must leave the files as they are: the child gets no edit or write tool; its commands still run.",
392
407
  `A child that has not answered after ${this.models.maxSteps} steps (model calls) stops and fails with agent.step_limit_reached; pass maxSteps to stop it sooner.`,
393
408
  `At most ${this.context.subagentConcurrencyPerRun} child agents may be active for this run.`,
394
409
  ].join("\n"),
@@ -621,8 +636,12 @@ export class SubagentCoordinator {
621
636
  )
622
637
  }
623
638
  await this.clearDeadAttempts(paused, signal)
624
- const { spec, continuation } = this.continuationOf(paused, [answer])
625
- return this.admit(runId, key, spec, signal, continuation)
639
+ const workspace = await this.continuationWorkspace(paused)
640
+ const { spec, continuation } = this.continuationOf(paused, [answer], workspace)
641
+ return this.admit(runId, key, spec, signal, {
642
+ ...continuation,
643
+ lends: continuesInParentWorkspace(workspace),
644
+ })
626
645
  })
627
646
 
628
647
  const output: MessageSubagentOutput = {
@@ -795,12 +814,30 @@ export class SubagentCoordinator {
795
814
  const model = this.resolveModel(input.model)
796
815
  const reasoning = input.reasoning ?? model.defaultReasoning
797
816
  const maxSteps = this.resolveMaxSteps(input.maxSteps)
817
+ const readOnly = input.readOnly === true
818
+ // Recorded, so its continuations keep the kind of sandbox it started with.
819
+ const inParentWorkspace = this.lendsWorkspace()
820
+ // A child that works in this turn's workspace sees its files already.
821
+ if (input.files?.length && inParentWorkspace) {
822
+ throw new AgentToolPublicError(
823
+ "[SixbAgent] spawn_agent takes no files here: the child works in your workspace, on the same files. Name the paths it needs in its task instead."
824
+ )
825
+ }
798
826
  const sources = input.files?.length
799
827
  ? await listHandedSources({ files: this.runFiles(), paths: input.files, signal })
800
828
  : undefined
801
829
  const runId = createSubagentRunId(this.parentRun.id, key)
802
830
  const specWith = (files: readonly SubagentRunFile[] | undefined) =>
803
- this.childSpec({ task, model, tier: model.tier, reasoning, maxSteps, files })
831
+ this.childSpec({
832
+ task,
833
+ model,
834
+ tier: model.tier,
835
+ reasoning,
836
+ maxSteps,
837
+ files,
838
+ readOnly,
839
+ inParentWorkspace,
840
+ })
804
841
 
805
842
  // One admission at a time: only this turn adds children to it, so admission's answer is known
806
843
  // before any file is read, and a refused spawn reads and stores none.
@@ -886,6 +923,43 @@ export class SubagentCoordinator {
886
923
  return null
887
924
  }
888
925
 
926
+ /**
927
+ * Where a paused child continues: in the kind of sandbox it started with. One that worked in its
928
+ * parent's workspace goes on there while this turn lends it and the conversation did not move
929
+ * since it paused, and is told when the workspace was recreated meanwhile; otherwise it gets a
930
+ * blank sandbox of its own, and is told. One with a sandbox of its own keeps it, as
931
+ * `childKeepsWorkspace` says, whether this turn lends or not.
932
+ */
933
+ private async continuationWorkspace(paused: SubagentRunRecord): Promise<ContinuationWorkspace> {
934
+ if (paused.spec.inParentWorkspace) {
935
+ if (!this.lendsWorkspace() || this.movedSince(paused)) return "left-parent"
936
+
937
+ // Recreated after it paused: what it changed there is gone, and it is told.
938
+ const resetAt = await this.runFiles().workspaceResetAt?.()
939
+ return resetAt !== undefined && new Date(resetAt).getTime() > pausedAt(paused).getTime()
940
+ ? "parent-reset"
941
+ : "parent"
942
+ }
943
+ return (await this.childKeepsWorkspace(paused)) ? "kept" : "restarted"
944
+ }
945
+
946
+ /**
947
+ * Whether a paused child finds its own workspace where it left it: its provider keeps them, the
948
+ * conversation did not move to a computer since it paused, and it did not move to another
949
+ * workspace before that pause ended.
950
+ */
951
+ private async childKeepsWorkspace(paused: SubagentRunRecord): Promise<boolean> {
952
+ if (!this.context.keepsChildWorkspaces) return false
953
+ const parent = await this.session.children.get(paused.parentRunId)
954
+ if (parent?.kind === "conversation" && parent.spec?.runsOn === "computer") return false
955
+ return !this.movedSince(paused)
956
+ }
957
+
958
+ /** Whether the conversation moved to another workspace after `paused` paused. */
959
+ private movedSince(paused: SubagentRunRecord): boolean {
960
+ return this.movedAt !== undefined && this.movedAt.getTime() > pausedAt(paused).getTime()
961
+ }
962
+
889
963
  /**
890
964
  * The run of this turn that continues `paused` in its thread: its model, task and files, this
891
965
  * turn's mode, and a trigger of what it goes on with (the outcomes of its calls, or
@@ -893,7 +967,8 @@ export class SubagentCoordinator {
893
967
  */
894
968
  private continuationOf(
895
969
  paused: SubagentRunRecord,
896
- goesOnWith: readonly AgentMessagePart[]
970
+ goesOnWith: readonly AgentMessagePart[],
971
+ workspace: ContinuationWorkspace
897
972
  ): {
898
973
  readonly spec: SubagentRunSpec
899
974
  readonly continuation: Pick<AgentChildDraft, "thread" | "trigger" | "createdAt">
@@ -905,12 +980,15 @@ export class SubagentCoordinator {
905
980
  reasoning: paused.spec.reasoning,
906
981
  maxSteps: paused.spec.maxSteps,
907
982
  files: paused.spec.files,
983
+ readOnly: paused.spec.readOnly === true,
984
+ // Its thread's: where it works, and the run files its history names, wherever it continues.
985
+ inParentWorkspace: paused.spec.inParentWorkspace === true,
908
986
  })
909
987
  const createdAt = new Date()
910
988
  const parts = continuationTrigger({
911
989
  goesOnWith,
912
990
  paused,
913
- keepsWorkspace: this.context.keepsChildWorkspaces,
991
+ workspace,
914
992
  createdAt,
915
993
  settings: sentSettings(spec, this.context),
916
994
  })
@@ -932,8 +1010,11 @@ export class SubagentCoordinator {
932
1010
  readonly reasoning: AgentReasoning | undefined
933
1011
  readonly maxSteps: number | undefined
934
1012
  readonly files: readonly SubagentRunFile[] | undefined
1013
+ readonly readOnly: boolean
1014
+ /** Its thread works in its parent's workspace (`SubagentRunSpec.inParentWorkspace`). */
1015
+ readonly inParentWorkspace: boolean
935
1016
  }): SubagentRunSpec {
936
- const { task, model, tier, reasoning, maxSteps, files } = input
1017
+ const { task, model, tier, reasoning, maxSteps, files, readOnly, inParentWorkspace } = input
937
1018
  const { approvalMode, timeZone, locale } = this.parentRun.spec ?? {}
938
1019
  return {
939
1020
  model: { provider: model.provider, modelId: model.modelId },
@@ -946,37 +1027,51 @@ export class SubagentCoordinator {
946
1027
  ...(timeZone === undefined ? {} : { timeZone }),
947
1028
  ...(locale === undefined ? {} : { locale }),
948
1029
  ...(files === undefined ? {} : { files }),
1030
+ ...(readOnly ? { readOnly: true } : {}),
1031
+ ...(inParentWorkspace ? { inParentWorkspace: true } : {}),
949
1032
  }
950
1033
  }
951
1034
 
952
1035
  /**
953
1036
  * Admit a child of this turn. A spawned child works in a thread of its own, which starts with its
954
- * task and its files; a continuation goes into its thread with the outcomes it continues with.
1037
+ * task and its files, and in the turn's workspace when its spec says so; a continuation goes into
1038
+ * its thread with the outcomes it continues with, in the turn's workspace when `lends` says so.
955
1039
  */
956
1040
  private async admit(
957
1041
  runId: string,
958
1042
  key: string,
959
1043
  spec: SubagentRunSpec,
960
1044
  signal: AbortSignal,
961
- continuation?: Pick<AgentChildDraft, "thread" | "trigger" | "createdAt">
1045
+ continuation?: Pick<AgentChildDraft, "thread" | "trigger" | "createdAt"> & {
1046
+ readonly lends: boolean
1047
+ }
962
1048
  ): Promise<SpawnSubagentOutput> {
1049
+ const lends = continuation ? continuation.lends : spec.inParentWorkspace === true
963
1050
  let run: SubagentRunRecord
964
1051
  try {
965
1052
  run = await this.session.children.spawn({
966
1053
  spawnKey: key,
967
1054
  spec,
968
- ...(continuation ?? {
969
- thread: { create: true },
970
- trigger: {
971
- id: createAgentMessageId(),
972
- parts: [
973
- { type: "text", text: spec.task },
974
- ...(spec.files === undefined
975
- ? []
976
- : [{ type: "text" as const, text: renderHandedFiles(spec.files) }]),
977
- ],
978
- },
979
- }),
1055
+ ...(continuation
1056
+ ? {
1057
+ thread: continuation.thread,
1058
+ trigger: continuation.trigger,
1059
+ ...(continuation.createdAt === undefined
1060
+ ? {}
1061
+ : { createdAt: continuation.createdAt }),
1062
+ }
1063
+ : {
1064
+ thread: { create: true },
1065
+ trigger: {
1066
+ id: createAgentMessageId(),
1067
+ parts: [
1068
+ { type: "text", text: spec.task },
1069
+ ...(spec.files === undefined
1070
+ ? []
1071
+ : [{ type: "text" as const, text: renderHandedFiles(spec.files) }]),
1072
+ ],
1073
+ },
1074
+ }),
980
1075
  })
981
1076
  if (run.id !== runId) {
982
1077
  throw new Error(`[SixbAgent] Child '${key}' was admitted as '${run.id}', not '${runId}'.`)
@@ -986,7 +1081,7 @@ export class SubagentCoordinator {
986
1081
  }
987
1082
 
988
1083
  signal.throwIfAborted()
989
- if (run.status === "queued") this.startChild(run, this.#family)
1084
+ if (run.status === "queued") this.startChild(run, this.#family, lends)
990
1085
 
991
1086
  return {
992
1087
  runId: run.id,
@@ -1253,6 +1348,11 @@ export class SubagentCoordinator {
1253
1348
  }
1254
1349
  }
1255
1350
 
1351
+ /** Whether the turn lends its children its workspace: never before its environment started. */
1352
+ private lendsWorkspace(): boolean {
1353
+ return this.#runFiles?.lendsWorkspace === true
1354
+ }
1355
+
1256
1356
  private runFiles(): AgentRunFiles {
1257
1357
  if (!this.#runFiles) {
1258
1358
  throw new Error("[SixbAgent] Delegation tools ran before their run's environment.")
@@ -1411,6 +1511,11 @@ function spawnInputSchema(models: AgentRunDelegation): JsonObject {
1411
1511
  description:
1412
1512
  "Paths of files or directories in your sandbox, such as an attachment from $SIXB_ATTACHMENTS or out/chart.png.",
1413
1513
  },
1514
+ readOnly: {
1515
+ type: "boolean",
1516
+ description:
1517
+ "The child gets no edit or write tool, for a review or an investigation that must leave the files as they are; its commands still run.",
1518
+ },
1414
1519
  },
1415
1520
  required: ["key", "task"],
1416
1521
  additionalProperties: false,
@@ -1631,11 +1736,11 @@ function parseSpawnInput(value: unknown): SpawnSubagentInput {
1631
1736
  if (
1632
1737
  !isJsonObject(value) ||
1633
1738
  Object.keys(value).some(
1634
- (key) => !["key", "task", "model", "reasoning", "maxSteps", "files"].includes(key)
1739
+ (key) => !["key", "task", "model", "reasoning", "maxSteps", "files", "readOnly"].includes(key)
1635
1740
  )
1636
1741
  ) {
1637
1742
  throw new AgentToolPublicError(
1638
- "[SixbAgent] spawn_agent expects key, task, and optional model/reasoning/maxSteps/files."
1743
+ "[SixbAgent] spawn_agent expects key, task, and optional model/reasoning/maxSteps/files/readOnly."
1639
1744
  )
1640
1745
  }
1641
1746
  const key = requireNonEmpty("spawn_agent", value.key, "key", 128)
@@ -1671,6 +1776,9 @@ function parseSpawnInput(value: unknown): SpawnSubagentInput {
1671
1776
  ) {
1672
1777
  throw new AgentToolPublicError("[SixbAgent] spawn_agent maxSteps must be a positive integer.")
1673
1778
  }
1779
+ if (value.readOnly !== undefined && typeof value.readOnly !== "boolean") {
1780
+ throw new AgentToolPublicError("[SixbAgent] spawn_agent readOnly must be true or false.")
1781
+ }
1674
1782
  const files = parseSpawnFiles(value.files)
1675
1783
  return {
1676
1784
  key,
@@ -1679,6 +1787,7 @@ function parseSpawnInput(value: unknown): SpawnSubagentInput {
1679
1787
  ...(value.reasoning === undefined ? {} : { reasoning: value.reasoning }),
1680
1788
  ...(value.maxSteps === undefined ? {} : { maxSteps: value.maxSteps }),
1681
1789
  ...(files === undefined ? {} : { files }),
1790
+ ...(value.readOnly === true ? { readOnly: true } : {}),
1682
1791
  }
1683
1792
  }
1684
1793
 
@@ -1715,3 +1824,8 @@ function stoppedReading(error: unknown, key: string): unknown {
1715
1824
  `[SixbAgent] '${key}' stopped as you sent this, so it will not read it: it paused or ended. Wait for it with wait to see which.`
1716
1825
  )
1717
1826
  }
1827
+
1828
+ /** When a paused child stopped. */
1829
+ function pausedAt(paused: SubagentRunRecord): Date {
1830
+ return paused.completedAt ?? paused.startedAt ?? paused.createdAt
1831
+ }
package/src/tools/bash.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { AgentToolPublicError, type CommandResult } from "@sixb/core"
1
+ import type { CommandResult } from "@sixb/core"
2
2
  import type { JsonObject, JsonValue, ModelTool } from "@sixb/core/models"
3
3
  import type { BackgroundCommandState, BackgroundCommands } from "../background-commands"
4
- import { loginShellArgs } from "../login-shell"
4
+ import { commandDirectory, loginShellArgs } from "../login-shell"
5
+ import { agentToolErrorText } from "../model-adapters"
5
6
  import type { AgentSandboxHandle } from "../sandbox-handle"
6
7
 
7
8
  /** Long enough for a build or a test suite; the model asks for more when it expects longer. */
@@ -34,7 +35,7 @@ export const BASH_TOOL_SPEC = {
34
35
  run_in_background: {
35
36
  type: "boolean",
36
37
  description:
37
- "Run it in the background, returning at once with its id and output file: for servers, watchers, long builds. You are told when it ends; wait for it with wait, stop it with stop, or read its file. No timeout. It ends with the run, a pause for approval too, and its file with it; in the user's folder on their computer it runs until it exits, is stopped, or sixb quits.",
38
+ "Run it in the background, returning at once with its id and output file: for servers, watchers, long builds. You are told when it ends; wait for it with wait, stop it with stop, or read its file. No timeout, unless the sandbox limits how long a command runs: you are told if it stops there. It ends with the run, a pause for approval too, and its file with it; in the user's folder on their computer it runs until it exits, is stopped, or sixb quits.",
38
39
  },
39
40
  },
40
41
  required: ["command"],
@@ -84,12 +85,11 @@ export function createBashTool(
84
85
 
85
86
  const { sandbox, env } = await resolveSandbox()
86
87
  const timeout = normalizeTimeout(input.timeoutMs)
87
- const result = await sandbox.runCommand("bash", loginShellArgs(input.command), {
88
- cwd: input.cwd,
89
- env,
90
- timeout,
91
- signal,
92
- })
88
+ const result = await sandbox.runCommand(
89
+ "bash",
90
+ loginShellArgs(input.command, commandDirectory(sandbox.workingDirectory, input.cwd)),
91
+ { env, timeout, signal }
92
+ )
93
93
 
94
94
  const output: BashToolOutput = {
95
95
  ...result,
@@ -100,8 +100,7 @@ export function createBashTool(
100
100
  return output as unknown as JsonValue
101
101
  },
102
102
  // A background start says why it refused, such as too many running already.
103
- errorText: (error) =>
104
- error instanceof AgentToolPublicError ? error.message : "The command failed.",
103
+ errorText: (error) => agentToolErrorText(error, "The command failed."),
105
104
  }
106
105
  }
107
106
 
@@ -15,7 +15,7 @@ import { WRITE_TOOL_SPEC } from "./write"
15
15
  * Describe exactly the tools a conversational model receives, in its order, without starting its
16
16
  * sandbox. A conversation publishes artifacts once its run executes in a thread; it searches the
17
17
  * web when its plan names a search model, and fetches pages when its plan has web tools at all,
18
- * unless its sandbox's network is `none`.
18
+ * unless its sandbox's network is `none`. A read-only child has no `edit` and no `write`.
19
19
  */
20
20
  export function agentModelToolSpecs(
21
21
  projectTools: readonly AgentToolSpec[],
@@ -23,13 +23,13 @@ export function agentModelToolSpecs(
23
23
  readonly publishes?: boolean
24
24
  readonly web?: AgentRunWebPlan
25
25
  readonly networkPolicy?: SandboxNetworkPolicy
26
+ readonly readOnly?: boolean
26
27
  } = {}
27
28
  ): readonly AgentToolSpec[] {
28
29
  return [
29
30
  ...projectTools,
30
31
  READ_TOOL_SPEC,
31
- EDIT_TOOL_SPEC,
32
- WRITE_TOOL_SPEC,
32
+ ...(options.readOnly ? [] : [EDIT_TOOL_SPEC, WRITE_TOOL_SPEC]),
33
33
  GLOB_TOOL_SPEC,
34
34
  GREP_TOOL_SPEC,
35
35
  BASH_TOOL_SPEC,
package/src/types.ts CHANGED
@@ -82,6 +82,15 @@ export interface AgentRunFiles {
82
82
  readonly blobStorage: AgentRunFileStore
83
83
  /** Shared with every other file the run stores. */
84
84
  readonly budget: AgentFileBudget
85
+ /** Its children work in its workspace: they need no files handed over, and hand none back. */
86
+ readonly lendsWorkspace?: boolean
87
+ /** It works in its parent's workspace, which sees what it changes: it hands no files back. */
88
+ readonly inParentWorkspace?: boolean
89
+ /**
90
+ * When the workspace it lends was last recreated, as its opening read it: a child that paused
91
+ * before then finds none of its changes there.
92
+ */
93
+ workspaceResetAt?(): Promise<string | undefined>
85
94
  /**
86
95
  * Install the latest revision of each thread artifact the run's turn wrote, its children's
87
96
  * writes among them, in the run's `$SIXB_ARTIFACTS`, and in the folder the Agent last published