@sixb/agent 0.2.5 → 0.2.6
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.
- package/dist/agent-prompt.d.ts +13 -3
- package/dist/agent-prompt.d.ts.map +1 -1
- package/dist/background-commands.d.ts +2 -2
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/conversation-messages.d.ts +1 -1
- package/dist/conversation-messages.d.ts.map +1 -1
- package/dist/index.js +339 -240
- package/dist/index.js.map +17 -17
- package/dist/login-shell.d.ts +18 -2
- package/dist/login-shell.d.ts.map +1 -1
- package/dist/model-adapters.d.ts +5 -2
- package/dist/model-adapters.d.ts.map +1 -1
- package/dist/model-lines.d.ts +1 -0
- package/dist/model-lines.d.ts.map +1 -1
- package/dist/run-conversation-turn.d.ts.map +1 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-sandbox.d.ts +11 -1
- package/dist/run-sandbox.d.ts.map +1 -1
- package/dist/run-subagent.d.ts.map +1 -1
- package/dist/sandbox-api-context.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +11 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/agent-prompt.ts +62 -28
- package/src/background-commands.ts +8 -6
- package/src/context-compaction.ts +1 -0
- package/src/conversation-messages.ts +11 -4
- package/src/login-shell.ts +30 -3
- package/src/model-adapters.ts +23 -4
- package/src/model-lines.ts +1 -1
- package/src/run-conversation-turn.ts +11 -2
- package/src/run-environment.ts +38 -11
- package/src/run-sandbox.ts +60 -1
- package/src/run-subagent.ts +8 -1
- package/src/sandbox-api-context.ts +7 -1
- package/src/subagent-tools.ts +23 -5
- package/src/tools/bash.ts +9 -10
package/src/model-adapters.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentMessagePart, JsonValue } from "@sixb/core"
|
|
2
|
-
import { AgentToolPublicError } from "@sixb/core"
|
|
2
|
+
import { AgentToolPublicError, SandboxNotRunningError } from "@sixb/core"
|
|
3
3
|
import {
|
|
4
4
|
type AgentToolCall,
|
|
5
5
|
type AgentToolCallFile,
|
|
@@ -267,7 +267,26 @@ function assertUnreachableModelPart(part: never, errorDetails?: AgentErrorDetail
|
|
|
267
267
|
)
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
/** What a tool says when its sandbox stopped: the run ends right after, so this is its last word. */
|
|
271
|
+
const SANDBOX_STOPPED_TOOL_TEXT =
|
|
272
|
+
"The sandbox stopped: commands and files are no longer available in it."
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Expose only failures that the tool author explicitly marked as safe for the model and storage,
|
|
276
|
+
* and a stopped sandbox, in fixed words, even when the tool wrapped it.
|
|
277
|
+
*/
|
|
278
|
+
export function agentToolErrorText(error: unknown, fallback = "An error occurred."): string {
|
|
279
|
+
if (error instanceof AgentToolPublicError) return error.message
|
|
280
|
+
if (foundSandboxStopped(error)) return SANDBOX_STOPPED_TOOL_TEXT
|
|
281
|
+
return fallback
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function foundSandboxStopped(error: unknown): boolean {
|
|
285
|
+
// Bounded: a cause chain can loop.
|
|
286
|
+
let cause = error
|
|
287
|
+
for (let depth = 0; depth < 8 && cause instanceof Error; depth++) {
|
|
288
|
+
if (cause instanceof SandboxNotRunningError) return true
|
|
289
|
+
cause = cause.cause
|
|
290
|
+
}
|
|
291
|
+
return false
|
|
273
292
|
}
|
package/src/model-lines.ts
CHANGED
|
@@ -23,6 +23,6 @@ export function renderModelLine(input: {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// A provider's catalog text may span lines; each model keeps to one.
|
|
26
|
-
function oneLine(text: string): string {
|
|
26
|
+
export function oneLine(text: string): string {
|
|
27
27
|
return text.replace(/\s+/g, " ").trim()
|
|
28
28
|
}
|
|
@@ -32,10 +32,15 @@ import {
|
|
|
32
32
|
type OpenRunSandbox,
|
|
33
33
|
} from "./run-environment"
|
|
34
34
|
import { recordFate } from "./run-fate"
|
|
35
|
+
import { sandboxStopOf, sandboxStoppedError } from "./run-sandbox"
|
|
35
36
|
import { SubagentCoordinator } from "./subagent-tools"
|
|
36
37
|
import { type AgentTurnRuntime, createAgentTurnRuntime } from "./turn-runtime"
|
|
37
38
|
import type { AgentExecutionContext, AgentRunSettings } from "./types"
|
|
38
39
|
|
|
40
|
+
/** Why a turn ended whose workspace, kept across turns, its provider stopped: as the chat offers. */
|
|
41
|
+
const SANDBOX_STOPPED_UNSAVED_MESSAGE =
|
|
42
|
+
"The sandbox stopped, so this turn ended here. To go on, pick up where it left off or start over."
|
|
43
|
+
|
|
39
44
|
// A conversation turn, from its claimed session to its end, whichever runner runs it: the worker,
|
|
40
45
|
// under a queue delivery, or a runner on a computer, over HTTP. The runner keeps what is its own:
|
|
41
46
|
// how it holds the run, where the turn's sandbox comes from, and where its children run.
|
|
@@ -113,7 +118,8 @@ export async function runConversationTurn(input: {
|
|
|
113
118
|
)
|
|
114
119
|
}
|
|
115
120
|
runner.startChild(child, family, environment.networkPolicy)
|
|
116
|
-
}
|
|
121
|
+
},
|
|
122
|
+
prepared.thread?.movedAt
|
|
117
123
|
)
|
|
118
124
|
// The Agent's own: its children, and its questions to the user, which end the turn.
|
|
119
125
|
const frameworkTools = [...(await delegation.createTools()), createAskUserTool()]
|
|
@@ -180,7 +186,10 @@ export async function runConversationTurn(input: {
|
|
|
180
186
|
await environment.beforeFinalize()
|
|
181
187
|
} catch (saveError) {
|
|
182
188
|
if (saveError instanceof AgentExecutionLostError) return
|
|
183
|
-
|
|
189
|
+
// A workspace its provider stopped cannot be cleaned and saved: it waits for its owner, and
|
|
190
|
+
// the run still says why it ended.
|
|
191
|
+
const stop = sandboxStopOf(error)
|
|
192
|
+
error = stop ? sandboxStoppedError(stop, SANDBOX_STOPPED_UNSAVED_MESSAGE) : saveError
|
|
184
193
|
environmentSaveFailed = true
|
|
185
194
|
}
|
|
186
195
|
}
|
package/src/run-environment.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path"
|
|
2
|
-
import type { Principal } from "@sixb/core"
|
|
2
|
+
import type { Principal, SandboxNotRunningError } from "@sixb/core"
|
|
3
3
|
import {
|
|
4
4
|
type AgentContextBudget,
|
|
5
5
|
type AgentRunArtifacts,
|
|
@@ -67,7 +67,9 @@ import {
|
|
|
67
67
|
type AcquiredRunSandbox,
|
|
68
68
|
acquireRunSandbox,
|
|
69
69
|
type BeforeFinalizeOptions,
|
|
70
|
+
endsWhenStopped,
|
|
70
71
|
type RunSandbox,
|
|
72
|
+
sandboxStoppedError,
|
|
71
73
|
} from "./run-sandbox"
|
|
72
74
|
import {
|
|
73
75
|
AGENT_ARTIFACTS_DIRECTORY,
|
|
@@ -115,6 +117,13 @@ import type { AgentTurnRuntime } from "./turn-runtime"
|
|
|
115
117
|
import type { AgentExecutionContext, AgentRunFiles, AgentTurnContext } from "./types"
|
|
116
118
|
import { prepareWorkflowInputAttachments } from "./workflow-input-attachments"
|
|
117
119
|
|
|
120
|
+
// What each kind of run says when its provider stopped its sandbox, to whoever goes on from it: the
|
|
121
|
+
// person in a conversation, the parent of a child, the run of a workflow step.
|
|
122
|
+
const SANDBOX_STOPPED_TURN_MESSAGE =
|
|
123
|
+
"The sandbox stopped, so this turn ended here. Its work so far is kept: send a message to go on."
|
|
124
|
+
const SANDBOX_STOPPED_CHILD_MESSAGE = "The sandbox stopped, so this agent ended here."
|
|
125
|
+
const SANDBOX_STOPPED_STEP_MESSAGE = "The sandbox stopped, so this step ended here."
|
|
126
|
+
|
|
118
127
|
export interface AgentExecutionEnvironment {
|
|
119
128
|
readonly turnContext: AgentTurnContext
|
|
120
129
|
/** The run's sandbox and file budget, for the files a parent and its children hand each other. */
|
|
@@ -405,13 +414,12 @@ export async function createConversationAgentEnvironment(
|
|
|
405
414
|
},
|
|
406
415
|
sandboxSignal,
|
|
407
416
|
failureSignal: failure.signal,
|
|
417
|
+
onSandboxStopped: (error) =>
|
|
418
|
+
failure.abort(sandboxStoppedError(error, SANDBOX_STOPPED_TURN_MESSAGE)),
|
|
408
419
|
context,
|
|
409
420
|
plan,
|
|
410
421
|
runId: run.id,
|
|
411
422
|
threadId: run.threadId,
|
|
412
|
-
...(input.thread?.movedAt
|
|
413
|
-
? { workspaceMovedAt: new Date(input.thread.movedAt).toISOString() }
|
|
414
|
-
: {}),
|
|
415
423
|
callTool: (call, options) => input.session.callTool(call, options),
|
|
416
424
|
webSearch: input.session.models.webSearch,
|
|
417
425
|
...(publishing ? { publishing } : {}),
|
|
@@ -477,7 +485,9 @@ export async function createConversationAgentEnvironment(
|
|
|
477
485
|
export async function createSubagentEnvironment(
|
|
478
486
|
input: CreateSubagentEnvironmentInput
|
|
479
487
|
): Promise<SubagentAgentExecutionEnvironment> {
|
|
480
|
-
// A child's workspace is blank, so it has no source credentials to lose.
|
|
488
|
+
// A child's workspace is blank, so it has no source credentials to lose. It ends only when its
|
|
489
|
+
// provider stops the sandbox.
|
|
490
|
+
const failure = new AbortController()
|
|
481
491
|
const { sandbox, resumed = false } = await input.openSandbox({
|
|
482
492
|
signal: input.signal ?? NEVER_ABORTED_SIGNAL,
|
|
483
493
|
onFailure: () => {},
|
|
@@ -496,6 +506,9 @@ export async function createSubagentEnvironment(
|
|
|
496
506
|
...input,
|
|
497
507
|
sandbox,
|
|
498
508
|
resumed,
|
|
509
|
+
failureSignal: failure.signal,
|
|
510
|
+
onSandboxStopped: (error) =>
|
|
511
|
+
failure.abort(sandboxStoppedError(error, SANDBOX_STOPPED_CHILD_MESSAGE)),
|
|
499
512
|
acquireBeforeStart: acquire,
|
|
500
513
|
acquire: () => {
|
|
501
514
|
provisioning = true
|
|
@@ -521,6 +534,9 @@ async function startSubagentEnvironment(
|
|
|
521
534
|
readonly sandbox: RunSandbox
|
|
522
535
|
/** Whether the sandbox is the workspace the paused run left: it holds its files already. */
|
|
523
536
|
readonly resumed: boolean
|
|
537
|
+
/** Ends the child when its provider stops the sandbox. */
|
|
538
|
+
readonly failureSignal: AbortSignal
|
|
539
|
+
readonly onSandboxStopped: (error: SandboxNotRunningError) => void
|
|
524
540
|
/** How the summary acquires the workspace its prompt describes, before the environment. */
|
|
525
541
|
readonly acquireBeforeStart: () => Promise<AcquiredRunSandbox>
|
|
526
542
|
/** How provisioning acquires it, which from then gives it back. */
|
|
@@ -683,6 +699,8 @@ async function startSubagentEnvironment(
|
|
|
683
699
|
...(networkPolicy ? { networkPolicy } : {}),
|
|
684
700
|
acquire: input.acquire,
|
|
685
701
|
sandboxSignal: input.signal,
|
|
702
|
+
failureSignal: input.failureSignal,
|
|
703
|
+
onSandboxStopped: input.onSandboxStopped,
|
|
686
704
|
context,
|
|
687
705
|
plan,
|
|
688
706
|
runId: run.id,
|
|
@@ -761,6 +779,8 @@ export async function createWorkflowAgentNodeEnvironment(
|
|
|
761
779
|
sandbox,
|
|
762
780
|
sandboxSignal,
|
|
763
781
|
failureSignal: failure.signal,
|
|
782
|
+
onSandboxStopped: (error) =>
|
|
783
|
+
failure.abort(sandboxStoppedError(error, SANDBOX_STOPPED_STEP_MESSAGE)),
|
|
764
784
|
context,
|
|
765
785
|
actorId: run.actorId,
|
|
766
786
|
plan,
|
|
@@ -798,6 +818,11 @@ interface AgentEnvironmentSetup
|
|
|
798
818
|
readonly sandboxSignal?: AbortSignal
|
|
799
819
|
/** Environment-owned failure, such as lost source credentials. */
|
|
800
820
|
readonly failureSignal?: AbortSignal
|
|
821
|
+
/**
|
|
822
|
+
* Ends the run when a command or a file write finds that the provider stopped the sandbox, such
|
|
823
|
+
* as at the end of a Vercel session: whichever tool met it, nothing more runs in it.
|
|
824
|
+
*/
|
|
825
|
+
readonly onSandboxStopped?: (error: SandboxNotRunningError) => void
|
|
801
826
|
/** How the run calls a project tool. */
|
|
802
827
|
readonly callTool: AgentToolCaller
|
|
803
828
|
/** How it searches the web, where the project is: `web_search` calls it. */
|
|
@@ -836,8 +861,6 @@ interface AgentEnvironmentSetup
|
|
|
836
861
|
}
|
|
837
862
|
/** A conversation's memory, or a child's to read: installed in the sandbox and in the prompt. */
|
|
838
863
|
readonly memory?: ConversationMemory
|
|
839
|
-
/** When the conversation's turns last moved to where they run now: see its `movedAt`. */
|
|
840
|
-
readonly workspaceMovedAt?: string
|
|
841
864
|
/** Who takes part in a conversation several people write in, for its prompt. */
|
|
842
865
|
readonly conversation?: string
|
|
843
866
|
}
|
|
@@ -995,6 +1018,7 @@ async function startAgentEnvironment(
|
|
|
995
1018
|
ontologyFiles: input.ontologyDocs?.files ?? [],
|
|
996
1019
|
...(installedArtifacts ? { artifacts: installedArtifacts } : {}),
|
|
997
1020
|
...(input.memory ? { memory: input.memory.repos } : {}),
|
|
1021
|
+
...(input.onSandboxStopped ? { onSandboxStopped: input.onSandboxStopped } : {}),
|
|
998
1022
|
})
|
|
999
1023
|
// Creation failure is surfaced where it is awaited (turn / sandbox tool / dispose); attach a no-op
|
|
1000
1024
|
// catch so a rejection observed by none of them is not reported as unhandled.
|
|
@@ -1024,7 +1048,6 @@ async function startAgentEnvironment(
|
|
|
1024
1048
|
plan,
|
|
1025
1049
|
...(input.ontologyDocs ? { ontologyDocs: input.ontologyDocs } : {}),
|
|
1026
1050
|
...(workspace ? { workspace } : {}),
|
|
1027
|
-
...(input.workspaceMovedAt ? { workspaceMovedAt: input.workspaceMovedAt } : {}),
|
|
1028
1051
|
...(input.conversation === undefined ? {} : { conversation: input.conversation }),
|
|
1029
1052
|
...(input.memory ? { memory: input.memory } : {}),
|
|
1030
1053
|
})
|
|
@@ -1108,7 +1131,6 @@ function measureEnvironmentSystemPrompt(input: {
|
|
|
1108
1131
|
readonly ontologyDocs?: RenderedOntologyDocs
|
|
1109
1132
|
/** The acquired workspace, when the prompt describes it. */
|
|
1110
1133
|
readonly workspace?: Pick<AcquiredRunSandbox, "promptContext" | "resetAt">
|
|
1111
|
-
readonly workspaceMovedAt?: string
|
|
1112
1134
|
readonly conversation?: string
|
|
1113
1135
|
readonly memory?: ConversationMemory
|
|
1114
1136
|
}): AgentSystemPromptSize {
|
|
@@ -1125,12 +1147,12 @@ function measureEnvironmentSystemPrompt(input: {
|
|
|
1125
1147
|
? { ontologyIndex: input.ontologyDocs.index }
|
|
1126
1148
|
: {}),
|
|
1127
1149
|
sandboxResetAt: workspace?.resetAt,
|
|
1128
|
-
...(input.workspaceMovedAt ? { workspaceMovedAt: input.workspaceMovedAt } : {}),
|
|
1129
1150
|
workspace: workspace?.promptContext,
|
|
1130
1151
|
facts: requester === undefined ? {} : { requester },
|
|
1131
1152
|
...(input.conversation === undefined ? {} : { conversation: input.conversation }),
|
|
1132
1153
|
...(plan.sandboxModels ? { sandboxModels: plan.sandboxModels } : {}),
|
|
1133
1154
|
...(input.memory ? { memory: input.memory.prompt } : {}),
|
|
1155
|
+
runningModel: plan.model,
|
|
1134
1156
|
})
|
|
1135
1157
|
}
|
|
1136
1158
|
|
|
@@ -1224,6 +1246,7 @@ interface ProvisionSandboxInput {
|
|
|
1224
1246
|
/** The conversation's artifacts, read while the sandbox starts. */
|
|
1225
1247
|
readonly artifacts?: Promise<MaterializedArtifacts>
|
|
1226
1248
|
readonly memory?: PrepareAgentSandboxApiContextInput["memory"]
|
|
1249
|
+
readonly onSandboxStopped?: (error: SandboxNotRunningError) => void
|
|
1227
1250
|
}
|
|
1228
1251
|
|
|
1229
1252
|
/** A sandbox acquired for the run, with the run's files installed in its context directory. */
|
|
@@ -1232,7 +1255,10 @@ type ProvisionedRunSandbox = AcquiredRunSandbox & AgentSandboxHandle
|
|
|
1232
1255
|
async function provisionSandbox(input: ProvisionSandboxInput): Promise<ProvisionedRunSandbox> {
|
|
1233
1256
|
const { context, actorId, run, apiBaseUrl, skills, ontologyFiles } = input
|
|
1234
1257
|
const acquired = await (input.acquire?.() ?? acquireRunSandbox(input.sandbox, input.signal))
|
|
1235
|
-
|
|
1258
|
+
// What the run's tools and files reach the sandbox through.
|
|
1259
|
+
const sandbox = input.onSandboxStopped
|
|
1260
|
+
? endsWhenStopped(acquired.sandbox, input.onSandboxStopped)
|
|
1261
|
+
: acquired.sandbox
|
|
1236
1262
|
const { contextDirectory } = input.sandbox
|
|
1237
1263
|
try {
|
|
1238
1264
|
const apiContext = await prepareAgentSandboxApiContext({
|
|
@@ -1256,6 +1282,7 @@ async function provisionSandbox(input: ProvisionSandboxInput): Promise<Provision
|
|
|
1256
1282
|
})
|
|
1257
1283
|
const provisioned = {
|
|
1258
1284
|
...acquired,
|
|
1285
|
+
sandbox,
|
|
1259
1286
|
contextDirectory,
|
|
1260
1287
|
env: { ...acquired.env, ...apiContext.env },
|
|
1261
1288
|
}
|
package/src/run-sandbox.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Sandbox, SandboxNotRunningError } from "@sixb/core"
|
|
2
|
+
import { createSixbError, withFailureMessage } from "@sixb/core/internal/errors"
|
|
2
3
|
import type { SandboxNetworkPolicy } from "@sixb/core/sandboxes"
|
|
3
4
|
import type { AgentWorkspacePromptContext } from "./agent-prompt"
|
|
4
5
|
import type { BackgroundCommands } from "./background-commands"
|
|
@@ -102,3 +103,61 @@ export async function acquireRunSandbox(
|
|
|
102
103
|
|
|
103
104
|
return { ...acquired, promptContext: { ...promptContext, instructions } }
|
|
104
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The run's sandbox, which calls `onStopped` each time a command or a file write finds that its
|
|
109
|
+
* provider stopped it, such as at the end of a Vercel session. Whichever tool met it, nothing more
|
|
110
|
+
* runs in it: the run ends instead of the model retrying there.
|
|
111
|
+
*/
|
|
112
|
+
export function endsWhenStopped(
|
|
113
|
+
session: Sandbox,
|
|
114
|
+
onStopped: (error: SandboxNotRunningError) => void
|
|
115
|
+
): Sandbox {
|
|
116
|
+
// Watched beside its caller, which gets the provider's own promise: its wait gains no step, and
|
|
117
|
+
// the run has ended before the caller reads the failure.
|
|
118
|
+
const watch = <T>(operation: () => Promise<T>): Promise<T> => {
|
|
119
|
+
const result = operation()
|
|
120
|
+
result.catch((error: unknown) => {
|
|
121
|
+
if (error instanceof SandboxNotRunningError) onStopped(error)
|
|
122
|
+
})
|
|
123
|
+
return result
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
id: session.id,
|
|
128
|
+
provider: session.provider,
|
|
129
|
+
get status() {
|
|
130
|
+
return session.status
|
|
131
|
+
},
|
|
132
|
+
workingDirectory: session.workingDirectory,
|
|
133
|
+
...(session.setRequestCredentials
|
|
134
|
+
? { setRequestCredentials: session.setRequestCredentials.bind(session) }
|
|
135
|
+
: {}),
|
|
136
|
+
...(session.credentialedUrl ? { credentialedUrl: session.credentialedUrl.bind(session) } : {}),
|
|
137
|
+
runCommand: (command, args, options) => watch(() => session.runCommand(command, args, options)),
|
|
138
|
+
writeFiles: (files) => watch(() => session.writeFiles(files)),
|
|
139
|
+
stop: () => session.stop(),
|
|
140
|
+
destroy: () => session.destroy(),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const stops = new WeakMap<Error, SandboxNotRunningError>()
|
|
145
|
+
|
|
146
|
+
/** Why a run whose sandbox stopped ended, in the words its run and its reader see. */
|
|
147
|
+
export function sandboxStoppedError(cause: SandboxNotRunningError, message: string): Error {
|
|
148
|
+
const error = withFailureMessage(
|
|
149
|
+
createSixbError(
|
|
150
|
+
"agent.execution_failed",
|
|
151
|
+
"[SixbAgent] The run's sandbox stopped; nothing more can run in it.",
|
|
152
|
+
{ cause }
|
|
153
|
+
),
|
|
154
|
+
message
|
|
155
|
+
)
|
|
156
|
+
stops.set(error, cause)
|
|
157
|
+
return error
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The provider's stop a run ended on, when `sandboxStoppedError` says that is why it ended. */
|
|
161
|
+
export function sandboxStopOf(error: unknown): SandboxNotRunningError | undefined {
|
|
162
|
+
return error instanceof Error ? stops.get(error) : undefined
|
|
163
|
+
}
|
package/src/run-subagent.ts
CHANGED
|
@@ -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([
|
|
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(
|
|
@@ -377,11 +382,13 @@ function subagentWorkMessages(
|
|
|
377
382
|
}
|
|
378
383
|
|
|
379
384
|
function assertSubagentCanFinalize(input: {
|
|
385
|
+
readonly context: AgentTurnContext
|
|
380
386
|
readonly runtime: AgentTurnRuntime
|
|
381
387
|
readonly sandboxReadiness: ReturnType<typeof monitorSandboxReadiness>
|
|
382
388
|
}): void {
|
|
383
389
|
throwIfExecutionLost(input.runtime.sourceSignal)
|
|
384
390
|
input.sandboxReadiness.throwIfFailed()
|
|
391
|
+
input.context.environmentFailureSignal?.throwIfAborted()
|
|
385
392
|
input.runtime.assertCanContinue()
|
|
386
393
|
}
|
|
387
394
|
|
|
@@ -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
|
-
'
|
|
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
|
"",
|
package/src/subagent-tools.ts
CHANGED
|
@@ -240,7 +240,9 @@ export class SubagentCoordinator {
|
|
|
240
240
|
* it claims the child's run, opens its session and environment, and records its fate.
|
|
241
241
|
* Starting a run already running is a no-op.
|
|
242
242
|
*/
|
|
243
|
-
private readonly startChild: (run: SubagentRunRecord, family: FamilyMailbox) => void
|
|
243
|
+
private readonly startChild: (run: SubagentRunRecord, family: FamilyMailbox) => void,
|
|
244
|
+
/** When the parent conversation last moved workspaces, so paused child sandboxes know. */
|
|
245
|
+
private readonly movedAt?: Date
|
|
244
246
|
) {
|
|
245
247
|
this.models = delegation.models
|
|
246
248
|
}
|
|
@@ -293,7 +295,8 @@ export class SubagentCoordinator {
|
|
|
293
295
|
for (const { child, outcomes } of paused) {
|
|
294
296
|
signal.throwIfAborted()
|
|
295
297
|
await this.clearDeadAttempts(child, signal)
|
|
296
|
-
const
|
|
298
|
+
const keepsWorkspace = await this.childKeepsWorkspace(child)
|
|
299
|
+
const { spec, continuation } = this.continuationOf(child, outcomes, keepsWorkspace)
|
|
297
300
|
await this.admitInTurn(() =>
|
|
298
301
|
this.admit(
|
|
299
302
|
createSubagentRunId(this.parentRun.id, child.spawnKey),
|
|
@@ -621,7 +624,8 @@ export class SubagentCoordinator {
|
|
|
621
624
|
)
|
|
622
625
|
}
|
|
623
626
|
await this.clearDeadAttempts(paused, signal)
|
|
624
|
-
const
|
|
627
|
+
const keepsWorkspace = await this.childKeepsWorkspace(paused)
|
|
628
|
+
const { spec, continuation } = this.continuationOf(paused, [answer], keepsWorkspace)
|
|
625
629
|
return this.admit(runId, key, spec, signal, continuation)
|
|
626
630
|
})
|
|
627
631
|
|
|
@@ -886,6 +890,19 @@ export class SubagentCoordinator {
|
|
|
886
890
|
return null
|
|
887
891
|
}
|
|
888
892
|
|
|
893
|
+
/**
|
|
894
|
+
* Whether a paused child finds its workspace where it left it: its provider keeps them, the
|
|
895
|
+
* conversation did not move to a computer since it paused, and it did not move to another
|
|
896
|
+
* workspace before that pause ended.
|
|
897
|
+
*/
|
|
898
|
+
private async childKeepsWorkspace(paused: SubagentRunRecord): Promise<boolean> {
|
|
899
|
+
if (!this.context.keepsChildWorkspaces) return false
|
|
900
|
+
const parent = await this.session.children.get(paused.parentRunId)
|
|
901
|
+
if (parent?.kind === "conversation" && parent.spec?.runsOn === "computer") return false
|
|
902
|
+
const pausedAt = paused.completedAt ?? paused.startedAt ?? paused.createdAt
|
|
903
|
+
return !this.movedAt || this.movedAt.getTime() <= pausedAt.getTime()
|
|
904
|
+
}
|
|
905
|
+
|
|
889
906
|
/**
|
|
890
907
|
* The run of this turn that continues `paused` in its thread: its model, task and files, this
|
|
891
908
|
* turn's mode, and a trigger of what it goes on with (the outcomes of its calls, or
|
|
@@ -893,7 +910,8 @@ export class SubagentCoordinator {
|
|
|
893
910
|
*/
|
|
894
911
|
private continuationOf(
|
|
895
912
|
paused: SubagentRunRecord,
|
|
896
|
-
goesOnWith: readonly AgentMessagePart[]
|
|
913
|
+
goesOnWith: readonly AgentMessagePart[],
|
|
914
|
+
keepsWorkspace: boolean
|
|
897
915
|
): {
|
|
898
916
|
readonly spec: SubagentRunSpec
|
|
899
917
|
readonly continuation: Pick<AgentChildDraft, "thread" | "trigger" | "createdAt">
|
|
@@ -910,7 +928,7 @@ export class SubagentCoordinator {
|
|
|
910
928
|
const parts = continuationTrigger({
|
|
911
929
|
goesOnWith,
|
|
912
930
|
paused,
|
|
913
|
-
keepsWorkspace
|
|
931
|
+
keepsWorkspace,
|
|
914
932
|
createdAt,
|
|
915
933
|
settings: sentSettings(spec, this.context),
|
|
916
934
|
})
|
package/src/tools/bash.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
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. */
|
|
@@ -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(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
timeout,
|
|
91
|
-
|
|
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
|
|