@sixb/agent 0.2.3 → 0.2.5
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/README.md +3 -3
- package/dist/agent-prompt.d.ts.map +1 -1
- package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
- package/dist/artifacts/publish-tool.d.ts +26 -44
- package/dist/artifacts/publish-tool.d.ts.map +1 -1
- package/dist/ask-tool.d.ts +62 -0
- package/dist/ask-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +1 -1
- package/dist/attachments.d.ts.map +1 -1
- package/dist/background-commands.d.ts +3 -3
- package/dist/background-commands.d.ts.map +1 -1
- package/dist/background-notices.d.ts.map +1 -1
- package/dist/child-files.d.ts +1 -1
- package/dist/child-questions.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10457 -7971
- package/dist/index.js.map +46 -38
- package/dist/run-agent-turn.d.ts +3 -14
- package/dist/run-agent-turn.d.ts.map +1 -1
- package/dist/run-conversation-turn.d.ts.map +1 -1
- package/dist/run-environment.d.ts +4 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-subagent.d.ts +1 -1
- package/dist/run-subagent.d.ts.map +1 -1
- package/dist/sandbox-api-context.d.ts.map +1 -1
- package/dist/search-script.d.ts +7 -0
- package/dist/search-script.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +20 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/background.d.ts +50 -18
- package/dist/tools/background.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -0
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/edit-text.d.ts +22 -0
- package/dist/tools/edit-text.d.ts.map +1 -0
- package/dist/tools/edit.d.ts +54 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/file-writes.d.ts +52 -0
- package/dist/tools/file-writes.d.ts.map +1 -0
- package/dist/tools/glob.d.ts +41 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +64 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts.map +1 -1
- package/dist/tools/read.d.ts +16 -3
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/sandbox-search.d.ts +26 -0
- package/dist/tools/sandbox-search.d.ts.map +1 -0
- package/dist/tools/search/command.d.ts +15 -0
- package/dist/tools/search/command.d.ts.map +1 -0
- package/dist/tools/search/gitignore.d.ts +28 -0
- package/dist/tools/search/gitignore.d.ts.map +1 -0
- package/dist/tools/search/glob.d.ts +15 -0
- package/dist/tools/search/glob.d.ts.map +1 -0
- package/dist/tools/search/main.d.ts +2 -0
- package/dist/tools/search/main.d.ts.map +1 -0
- package/dist/tools/search/match.d.ts +30 -0
- package/dist/tools/search/match.d.ts.map +1 -0
- package/dist/tools/search/pattern.d.ts +19 -0
- package/dist/tools/search/pattern.d.ts.map +1 -0
- package/dist/tools/search/read.d.ts +62 -0
- package/dist/tools/search/read.d.ts.map +1 -0
- package/dist/tools/search/request.d.ts +80 -0
- package/dist/tools/search/request.d.ts.map +1 -0
- package/dist/tools/search/search.d.ts +4 -0
- package/dist/tools/search/search.d.ts.map +1 -0
- package/dist/tools/search/walk.d.ts +43 -0
- package/dist/tools/search/walk.d.ts.map +1 -0
- package/dist/tools/tool-outputs.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts +20 -23
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools/web-fetch/tool.d.ts +1 -0
- package/dist/tools/web-fetch/tool.d.ts.map +1 -1
- package/dist/tools/web-search.d.ts +1 -0
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/write.d.ts +36 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/agent-prompt.ts +10 -9
- package/src/agent-runtime/preflight.ts +1 -0
- package/src/artifacts/layout-check/check.cjs +176 -95
- package/src/artifacts/layout-check/layout-check.ts +118 -76
- package/src/artifacts/publish-tool.ts +123 -192
- package/src/ask-tool.ts +223 -0
- package/src/attachments.ts +7 -6
- package/src/background-commands.ts +5 -5
- package/src/background-notices.ts +5 -12
- package/src/child-files.ts +1 -1
- package/src/child-questions.ts +1 -1
- package/src/context-compaction.ts +4 -1
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +1 -2
- package/src/run-agent-turn.ts +99 -133
- package/src/run-child.ts +1 -1
- package/src/run-conversation-turn.ts +8 -5
- package/src/run-environment.ts +40 -21
- package/src/run-subagent.ts +4 -4
- package/src/sandbox-api-context.ts +3 -0
- package/src/search-script-assets.d.ts +5 -0
- package/src/search-script.ts +9 -0
- package/src/skills/built-in.ts +16 -0
- package/src/skills/sixb-artifacts/SKILL.md +13 -13
- package/src/skills/sixb-artifacts/canvas.md +5 -4
- package/src/skills/sixb-artifacts/document.md +92 -5
- package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
- package/src/skills/sixb-artifacts/page.md +2 -2
- package/src/skills/sixb-artifacts/queries.md +2 -1
- package/src/skills/sixb-artifacts/slides.md +2 -2
- package/src/subagent-tools.ts +115 -81
- package/src/tools/background.ts +227 -67
- package/src/tools/bash.ts +2 -1
- package/src/tools/edit-text.ts +241 -0
- package/src/tools/edit.ts +166 -0
- package/src/tools/file-writes.ts +270 -0
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +13 -13
- package/src/tools/read.ts +75 -9
- package/src/tools/sandbox-search.ts +219 -0
- package/src/tools/search/command.ts +116 -0
- package/src/tools/search/gitignore.ts +101 -0
- package/src/tools/search/glob.ts +90 -0
- package/src/tools/search/main.ts +9 -0
- package/src/tools/search/match.ts +278 -0
- package/src/tools/search/pattern.ts +178 -0
- package/src/tools/search/read.ts +237 -0
- package/src/tools/search/request.ts +101 -0
- package/src/tools/search/search.ts +297 -0
- package/src/tools/search/walk.ts +145 -0
- package/src/tools/tool-outputs.ts +9 -4
- package/src/tools/view-file.ts +78 -80
- package/src/tools/web-fetch/tool.ts +2 -1
- package/src/tools/web-search.ts +1 -0
- package/src/tools/write.ts +95 -0
- package/src/turn-inbox.ts +283 -0
- package/dist/artifacts/board-previews.d.ts +0 -41
- package/dist/artifacts/board-previews.d.ts.map +0 -1
- package/dist/ask-parent-tool.d.ts +0 -36
- package/dist/ask-parent-tool.d.ts.map +0 -1
- package/src/artifacts/board-previews.ts +0 -218
- package/src/ask-parent-tool.ts +0 -100
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { waitForAbort } from "./abort"
|
|
2
2
|
export type { AgentWorkspacePromptContext } from "./agent-prompt"
|
|
3
|
-
export {
|
|
4
|
-
export { createAskParentTool } from "./ask-parent-tool"
|
|
3
|
+
export { createAskParentTool } from "./ask-tool"
|
|
5
4
|
export type { BackgroundCommandStatus } from "./background-commands"
|
|
6
5
|
export {
|
|
7
6
|
type ComputerBackgroundCommand,
|
package/src/run-agent-turn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentStepRequestSize } from "@sixb/core"
|
|
2
2
|
import {
|
|
3
3
|
type AgentContextBudget,
|
|
4
4
|
type AgentRunSession,
|
|
@@ -19,15 +19,16 @@ import {
|
|
|
19
19
|
type ConversationAgentRunRecord,
|
|
20
20
|
coerceAgentRunFinishReason,
|
|
21
21
|
} from "@sixb/core/storage"
|
|
22
|
+
import { stepAskedUser } from "./ask-tool"
|
|
22
23
|
import { createAgentContextGuard } from "./context-guard"
|
|
23
24
|
import { conversationModelMessages, conversationModelSettings } from "./conversation-messages"
|
|
24
25
|
import { AgentContextCompactionError, throwIfExecutionLost } from "./errors"
|
|
25
26
|
import type { ResolvedAgentExecutionPlan } from "./execution-plan"
|
|
26
27
|
import type { ConversationReaders } from "./message-authors"
|
|
27
|
-
import { agentTraceFromModelSteps, agentTraceFromPartialModelLoop } from "./model-adapters"
|
|
28
28
|
import type { ConversationAgentExecutionEnvironment } from "./run-environment"
|
|
29
29
|
import { monitorSandboxReadiness } from "./sandbox-readiness"
|
|
30
30
|
import type { LoadedAgentThreadModelContext } from "./thread-context"
|
|
31
|
+
import { TurnInbox, turnResultMessages, turnWorkMessages } from "./turn-inbox"
|
|
31
32
|
import { type AgentTurnRuntime, createAgentTurnRuntime } from "./turn-runtime"
|
|
32
33
|
import type { AgentTurnContext } from "./types"
|
|
33
34
|
|
|
@@ -68,10 +69,10 @@ export interface RunAgentTurnInput {
|
|
|
68
69
|
readonly compactInTurn?: ConversationAgentExecutionEnvironment["compactInTurn"]
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
|
-
* Handed the answer so far after each step that completed, as the
|
|
72
|
-
* append: a turn that fails then records
|
|
72
|
+
* Handed the answer so far after each step that completed, as the messages the turn would
|
|
73
|
+
* append: a turn that fails then records them with its failure, and keeps that work.
|
|
73
74
|
*/
|
|
74
|
-
readonly onWork?: (
|
|
75
|
+
readonly onWork?: (messages: readonly AppendAgentMessageInput[]) => void
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/**
|
|
@@ -117,7 +118,7 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
117
118
|
sandboxReadiness.signal,
|
|
118
119
|
...(context.environmentFailureSignal ? [context.environmentFailureSignal] : []),
|
|
119
120
|
])
|
|
120
|
-
let
|
|
121
|
+
let interruptedMessages: readonly AppendAgentMessageInput[] | undefined
|
|
121
122
|
const stopReason = () =>
|
|
122
123
|
stoppedByWorker(signal, input.stopSignal) ? { finishReason: "interrupted" as const } : {}
|
|
123
124
|
|
|
@@ -132,7 +133,7 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
132
133
|
run,
|
|
133
134
|
modelId: plan.model.modelId,
|
|
134
135
|
...stopReason(),
|
|
135
|
-
|
|
136
|
+
messages: interruptedMessages,
|
|
136
137
|
})
|
|
137
138
|
}
|
|
138
139
|
|
|
@@ -201,10 +202,19 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
201
202
|
return { ...prepared, ...guarded }
|
|
202
203
|
}
|
|
203
204
|
: context.prepareStep
|
|
205
|
+
const turnInbox = new TurnInbox(input.session, {
|
|
206
|
+
retainedMessages: input.threadContext.retainedMessages,
|
|
207
|
+
...(input.conversation === undefined ? {} : { conversation: input.conversation }),
|
|
208
|
+
project: { timeZone: context.projectTimeZone, locale: context.projectLocale },
|
|
209
|
+
})
|
|
204
210
|
const prepareStep = async (step: PrepareModelStepInput) => {
|
|
205
211
|
const prepared = await guardedStep?.(step)
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
const steers = await turnInbox.take(step.stepIndex)
|
|
213
|
+
const baseMessages = prepared?.messages ?? step.messages
|
|
214
|
+
const nextMessages = steers.length > 0 ? [...baseMessages, ...steers] : baseMessages
|
|
215
|
+
recordRequest(step.stepIndex, nextMessages)
|
|
216
|
+
if (steers.length === 0) return prepared
|
|
217
|
+
return { ...prepared, messages: nextMessages }
|
|
208
218
|
}
|
|
209
219
|
const recoverStep =
|
|
210
220
|
guard &&
|
|
@@ -214,37 +224,30 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
214
224
|
return recovered
|
|
215
225
|
})
|
|
216
226
|
|
|
217
|
-
// The answer so far, as one message whatever step it is at.
|
|
218
|
-
const workMessageId = createAgentMessageId()
|
|
219
227
|
const finishedSteps: ModelStep[] = []
|
|
220
228
|
const recordStep = (step: ModelStep) => {
|
|
221
229
|
finishedSteps.push(step)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
finishedSteps,
|
|
232
|
-
{ threadId: run.threadId, runId },
|
|
233
|
-
context.outputFileOf
|
|
234
|
-
),
|
|
235
|
-
guard?.reducedFromStep()
|
|
236
|
-
),
|
|
237
|
-
stepRequests
|
|
238
|
-
),
|
|
230
|
+
const snapshot = turnWorkMessages({
|
|
231
|
+
steps: finishedSteps,
|
|
232
|
+
run,
|
|
233
|
+
deliveries: turnInbox.deliveries,
|
|
234
|
+
...(guard?.reducedFromStep() === undefined
|
|
235
|
+
? {}
|
|
236
|
+
: { reducedFromStep: guard.reducedFromStep() }),
|
|
237
|
+
stepRequests,
|
|
238
|
+
...(context.outputFileOf === undefined ? {} : { outputFileOf: context.outputFileOf }),
|
|
239
239
|
...(context.authorPrincipal === undefined
|
|
240
240
|
? {}
|
|
241
241
|
: { authorPrincipal: context.authorPrincipal }),
|
|
242
242
|
})
|
|
243
|
+
interruptedMessages = snapshot
|
|
244
|
+
input.onWork?.(snapshot)
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
try {
|
|
246
248
|
let chunkIndex = 0
|
|
247
249
|
let result: PausableModelLoopResult
|
|
250
|
+
let askedUser = false
|
|
248
251
|
try {
|
|
249
252
|
result = await runModelLoop({
|
|
250
253
|
model: plan.model,
|
|
@@ -259,25 +262,30 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
259
262
|
prepareStep,
|
|
260
263
|
...(recoverStep ? { recoverStep } : {}),
|
|
261
264
|
onStepEnd: recordStep,
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
// Mid-run steers and unread child questions arrive before the answer ends the turn.
|
|
266
|
+
beforeComplete: async (_step, stepIndex) => {
|
|
267
|
+
const steers = await turnInbox.take(stepIndex + 1, { afterAnswer: true })
|
|
268
|
+
const unread = await input.children?.unread()
|
|
269
|
+
const followUp: ModelMessage[] = [
|
|
270
|
+
...steers,
|
|
271
|
+
...(unread
|
|
272
|
+
? [{ role: "user" as const, content: [{ type: "text" as const, text: unread }] }]
|
|
273
|
+
: []),
|
|
274
|
+
]
|
|
275
|
+
return followUp.length > 0 ? followUp : undefined
|
|
276
|
+
},
|
|
273
277
|
signal: abortSignal,
|
|
274
278
|
onEvent: async (chunk) => {
|
|
275
279
|
await input.session.events.publishUiChunk({ run, chunkIndex: chunkIndex++, chunk })
|
|
276
280
|
},
|
|
277
281
|
// The approval records decide, never the tool output: the model can send a command's
|
|
278
282
|
// output elsewhere, or print one of its own. A held call waits for the children still
|
|
279
|
-
// at work: pausing ends the turn, and that would cancel them.
|
|
280
|
-
|
|
283
|
+
// at work: pausing ends the turn, and that would cancel them. A question to the user ends
|
|
284
|
+
// the turn too: the answer is the user's next message.
|
|
285
|
+
pauseAfterStep: async (step) => {
|
|
286
|
+
if (stepAskedUser(step)) askedUser = true
|
|
287
|
+
return (await input.session.heldCalls.pausesAfterStep()) || askedUser
|
|
288
|
+
},
|
|
281
289
|
})
|
|
282
290
|
} catch (error) {
|
|
283
291
|
const interrupted = await finalizeIfInterrupted(error)
|
|
@@ -295,24 +303,18 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
295
303
|
throw error
|
|
296
304
|
}
|
|
297
305
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
context.outputFileOf
|
|
311
|
-
),
|
|
312
|
-
guard?.reducedFromStep()
|
|
313
|
-
),
|
|
314
|
-
stepRequests
|
|
315
|
-
)
|
|
306
|
+
interruptedMessages = turnResultMessages(result, {
|
|
307
|
+
run,
|
|
308
|
+
deliveries: turnInbox.deliveries,
|
|
309
|
+
...(guard?.reducedFromStep() === undefined
|
|
310
|
+
? {}
|
|
311
|
+
: { reducedFromStep: guard.reducedFromStep() }),
|
|
312
|
+
stepRequests,
|
|
313
|
+
...(context.outputFileOf === undefined ? {} : { outputFileOf: context.outputFileOf }),
|
|
314
|
+
...(context.authorPrincipal === undefined
|
|
315
|
+
? {}
|
|
316
|
+
: { authorPrincipal: context.authorPrincipal }),
|
|
317
|
+
})
|
|
316
318
|
|
|
317
319
|
const interruptedAfterModel = await finalizeIfInterrupted()
|
|
318
320
|
if (interruptedAfterModel) return interruptedAfterModel
|
|
@@ -323,7 +325,7 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
323
325
|
run,
|
|
324
326
|
modelId: plan.model.modelId,
|
|
325
327
|
...stopReason(),
|
|
326
|
-
|
|
328
|
+
messages: interruptedMessages,
|
|
327
329
|
})
|
|
328
330
|
}
|
|
329
331
|
|
|
@@ -340,16 +342,37 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
340
342
|
const interruptedWhileWaiting = await finalizeIfInterrupted()
|
|
341
343
|
if (interruptedWhileWaiting) return interruptedWhileWaiting
|
|
342
344
|
|
|
345
|
+
// A turn that stopped on its question alone simply ends: nothing waits for a decision.
|
|
346
|
+
const held = await input.session.heldCalls.holdsRun()
|
|
343
347
|
const finishReason =
|
|
344
|
-
result.status === "paused"
|
|
348
|
+
held || (result.status === "paused" && !askedUser)
|
|
345
349
|
? "awaiting_approval"
|
|
346
|
-
:
|
|
347
|
-
|
|
350
|
+
: result.status === "paused"
|
|
351
|
+
? "stop"
|
|
352
|
+
: (coerceAgentRunFinishReason(result.finishReason) ?? "unknown")
|
|
348
353
|
const diagnostics = [
|
|
349
354
|
outputLimitDiagnostic(finishReason),
|
|
350
355
|
finishReason === "awaiting_approval" ? undefined : stepLimitDiagnostic(result),
|
|
351
356
|
].filter((diagnostic) => diagnostic !== undefined)
|
|
352
|
-
const
|
|
357
|
+
const committedMessages: readonly AppendAgentMessageInput[] =
|
|
358
|
+
interruptedMessages !== undefined && interruptedMessages.length > 0
|
|
359
|
+
? interruptedMessages
|
|
360
|
+
: [
|
|
361
|
+
{
|
|
362
|
+
id: createAgentMessageId(),
|
|
363
|
+
projectId,
|
|
364
|
+
threadId: run.threadId,
|
|
365
|
+
runId,
|
|
366
|
+
role: "assistant" as const,
|
|
367
|
+
parts: [],
|
|
368
|
+
...(context.authorPrincipal === undefined
|
|
369
|
+
? {}
|
|
370
|
+
: { authorPrincipal: context.authorPrincipal }),
|
|
371
|
+
},
|
|
372
|
+
]
|
|
373
|
+
const lastAssistant = [...committedMessages]
|
|
374
|
+
.reverse()
|
|
375
|
+
.find((message) => message.role === "assistant")
|
|
353
376
|
|
|
354
377
|
const interruptedBeforeCommit = await finalizeIfInterrupted()
|
|
355
378
|
if (interruptedBeforeCommit) return interruptedBeforeCommit
|
|
@@ -362,22 +385,12 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
362
385
|
finishReason,
|
|
363
386
|
...(diagnostics.length === 0 ? {} : { diagnostics }),
|
|
364
387
|
},
|
|
365
|
-
|
|
366
|
-
{
|
|
367
|
-
id: assistantMessageId,
|
|
368
|
-
projectId,
|
|
369
|
-
threadId: run.threadId,
|
|
370
|
-
runId,
|
|
371
|
-
role: assistant.role,
|
|
372
|
-
parts: assistant.parts,
|
|
373
|
-
...(context.authorPrincipal === undefined
|
|
374
|
-
? {}
|
|
375
|
-
: { authorPrincipal: context.authorPrincipal }),
|
|
376
|
-
},
|
|
377
|
-
]
|
|
388
|
+
committedMessages
|
|
378
389
|
)
|
|
379
390
|
|
|
380
|
-
|
|
391
|
+
if (lastAssistant) {
|
|
392
|
+
await input.session.events.publishMessageFinalized({ run, messageId: lastAssistant.id })
|
|
393
|
+
}
|
|
381
394
|
await input.session.events.publishRunFinished(finalizedRun)
|
|
382
395
|
return finalizedRun
|
|
383
396
|
} finally {
|
|
@@ -390,43 +403,6 @@ export async function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRe
|
|
|
390
403
|
* waiting, or decided and not reported to the model yet, its children's included.
|
|
391
404
|
*/
|
|
392
405
|
|
|
393
|
-
/**
|
|
394
|
-
* Mark each step from `fromStep` on as answering a request the turn reduced, for the next turn's
|
|
395
|
-
* estimate not to go by what those calls read.
|
|
396
|
-
*/
|
|
397
|
-
export function markReducedSteps(
|
|
398
|
-
parts: readonly AgentMessagePart[],
|
|
399
|
-
fromStep: number | undefined
|
|
400
|
-
): readonly AgentMessagePart[] {
|
|
401
|
-
if (fromStep === undefined) return parts
|
|
402
|
-
|
|
403
|
-
let step = -1
|
|
404
|
-
return parts.map((part) => {
|
|
405
|
-
if (part.type !== "step-start") return part
|
|
406
|
-
|
|
407
|
-
step += 1
|
|
408
|
-
return step >= fromStep ? { type: "step-start", reducedRequest: true } : part
|
|
409
|
-
})
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Record on each step-start what its request carried, by step: the next turn's context meter
|
|
414
|
-
* reads the system prompt and tools the latest one sent.
|
|
415
|
-
*/
|
|
416
|
-
export function recordStepRequests(
|
|
417
|
-
parts: readonly AgentMessagePart[],
|
|
418
|
-
requests: readonly (AgentStepRequestSize | undefined)[]
|
|
419
|
-
): readonly AgentMessagePart[] {
|
|
420
|
-
let step = -1
|
|
421
|
-
return parts.map((part) => {
|
|
422
|
-
if (part.type !== "step-start") return part
|
|
423
|
-
|
|
424
|
-
step += 1
|
|
425
|
-
const request = requests[step]
|
|
426
|
-
return request ? { ...part, request } : part
|
|
427
|
-
})
|
|
428
|
-
}
|
|
429
|
-
|
|
430
406
|
/**
|
|
431
407
|
* Whether the worker's stop, rather than the user's, ended the turn. Whichever fired first wins:
|
|
432
408
|
* the combined turn signal carries the reason of the first source that aborted it.
|
|
@@ -471,10 +447,10 @@ async function finalizeInterruptedTurn(input: {
|
|
|
471
447
|
readonly run: ConversationAgentRunRecord
|
|
472
448
|
readonly modelId?: string
|
|
473
449
|
readonly finishReason?: "interrupted"
|
|
474
|
-
readonly
|
|
450
|
+
readonly messages?: readonly AppendAgentMessageInput[]
|
|
475
451
|
}): Promise<AgentRunRecord> {
|
|
476
452
|
const { session, context, run, modelId, finishReason } = input
|
|
477
|
-
const
|
|
453
|
+
const messages = input.messages && input.messages.length > 0 ? input.messages : undefined
|
|
478
454
|
|
|
479
455
|
await context.beforeFinalize?.()
|
|
480
456
|
|
|
@@ -483,27 +459,17 @@ async function finalizeInterruptedTurn(input: {
|
|
|
483
459
|
...(modelId === undefined ? {} : { modelId }),
|
|
484
460
|
...(finishReason === undefined ? {} : { finishReason }),
|
|
485
461
|
}
|
|
486
|
-
if (!
|
|
462
|
+
if (!messages) {
|
|
487
463
|
const finalizedRun = await session.finish(outcome)
|
|
488
464
|
await session.events.publishRunFinished(finalizedRun)
|
|
489
465
|
return finalizedRun
|
|
490
466
|
}
|
|
491
467
|
|
|
492
|
-
const
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
threadId: run.threadId,
|
|
498
|
-
runId: run.id,
|
|
499
|
-
role: "assistant",
|
|
500
|
-
parts,
|
|
501
|
-
...(context.authorPrincipal === undefined
|
|
502
|
-
? {}
|
|
503
|
-
: { authorPrincipal: context.authorPrincipal }),
|
|
504
|
-
},
|
|
505
|
-
])
|
|
506
|
-
await session.events.publishMessageFinalized({ run, messageId: assistantMessageId })
|
|
468
|
+
const finalizedRun = await session.finish(outcome, messages)
|
|
469
|
+
const lastAssistant = [...messages].reverse().find((message) => message.role === "assistant")
|
|
470
|
+
if (lastAssistant) {
|
|
471
|
+
await session.events.publishMessageFinalized({ run, messageId: lastAssistant.id })
|
|
472
|
+
}
|
|
507
473
|
await session.events.publishRunFinished(finalizedRun)
|
|
508
474
|
return finalizedRun
|
|
509
475
|
}
|
package/src/run-child.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
ExecutionRecord,
|
|
15
15
|
SubagentRunRecord,
|
|
16
16
|
} from "@sixb/core/storage"
|
|
17
|
-
import { createAskParentTool } from "./ask-
|
|
17
|
+
import { createAskParentTool } from "./ask-tool"
|
|
18
18
|
import { prepareAgentModel } from "./context-budget"
|
|
19
19
|
import { isLostExecution } from "./errors"
|
|
20
20
|
import { resolveRunPlan } from "./execution-plan"
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
ExecutionRecord,
|
|
19
19
|
SubagentRunRecord,
|
|
20
20
|
} from "@sixb/core/storage"
|
|
21
|
+
import { createAskUserTool } from "./ask-tool"
|
|
21
22
|
import { prepareAgentModel } from "./context-budget"
|
|
22
23
|
import { AgentEnvironmentSaveError, AgentRequesterLeftThreadError, isLostExecution } from "./errors"
|
|
23
24
|
import { resolveRunPlan } from "./execution-plan"
|
|
@@ -88,7 +89,7 @@ export async function runConversationTurn(input: {
|
|
|
88
89
|
let runtime: AgentTurnRuntime | null = null
|
|
89
90
|
let delegation: SubagentCoordinator | undefined
|
|
90
91
|
// The answer so far: a turn that fails keeps the steps it completed.
|
|
91
|
-
let work: AppendAgentMessageInput | undefined
|
|
92
|
+
let work: readonly AppendAgentMessageInput[] | undefined
|
|
92
93
|
// A user cancel joins the turn's abort sources, so it stops the model stream as a shutdown does.
|
|
93
94
|
const turnSignal = AbortSignal.any([signal, session.cancelled])
|
|
94
95
|
|
|
@@ -114,10 +115,12 @@ export async function runConversationTurn(input: {
|
|
|
114
115
|
runner.startChild(child, family, environment.networkPolicy)
|
|
115
116
|
}
|
|
116
117
|
)
|
|
117
|
-
|
|
118
|
+
// The Agent's own: its children, and its questions to the user, which end the turn.
|
|
119
|
+
const frameworkTools = [...(await delegation.createTools()), createAskUserTool()]
|
|
118
120
|
environment = await createConversationAgentEnvironment({
|
|
119
121
|
session,
|
|
120
122
|
frameworkTools,
|
|
123
|
+
children: delegation.waitable(),
|
|
121
124
|
thread: prepared.thread,
|
|
122
125
|
...(prepared.execution.requestedBy === undefined
|
|
123
126
|
? {}
|
|
@@ -161,8 +164,8 @@ export async function runConversationTurn(input: {
|
|
|
161
164
|
? {}
|
|
162
165
|
: { bytesPerToken: environment.bytesPerToken }),
|
|
163
166
|
},
|
|
164
|
-
onWork: (
|
|
165
|
-
work =
|
|
167
|
+
onWork: (messages) => {
|
|
168
|
+
work = messages
|
|
166
169
|
},
|
|
167
170
|
})
|
|
168
171
|
} catch (caughtError) {
|
|
@@ -194,7 +197,7 @@ export async function runConversationTurn(input: {
|
|
|
194
197
|
session,
|
|
195
198
|
aborted ? "cancelled" : "failed",
|
|
196
199
|
interrupted ? new AgentTurnInterruptedError(run.id) : error,
|
|
197
|
-
!aborted && work ?
|
|
200
|
+
!aborted && work && work.length > 0 ? work : undefined
|
|
198
201
|
)
|
|
199
202
|
if (finalized) {
|
|
200
203
|
if (finalized.run.status === "failed") {
|
package/src/run-environment.ts
CHANGED
|
@@ -87,10 +87,14 @@ import {
|
|
|
87
87
|
} from "./subagent-context"
|
|
88
88
|
import type { SubagentHistory } from "./subagent-continuation"
|
|
89
89
|
import { agentThreadModelContext, type LoadedAgentThreadModelContext } from "./thread-context"
|
|
90
|
-
import {
|
|
90
|
+
import { createStopTool, createWaitTool, type WaitableChildren } from "./tools/background"
|
|
91
91
|
import { createBashTool } from "./tools/bash"
|
|
92
|
+
import { createEditTool } from "./tools/edit"
|
|
93
|
+
import { FileReadLedger } from "./tools/file-writes"
|
|
94
|
+
import { createGlobTool } from "./tools/glob"
|
|
95
|
+
import { createGrepTool } from "./tools/grep"
|
|
92
96
|
import { agentModelToolSpecs, fetchesWeb } from "./tools/model-spec"
|
|
93
|
-
import { createReadTool } from "./tools/read"
|
|
97
|
+
import { createReadTool, READ_TOOL_SPEC } from "./tools/read"
|
|
94
98
|
import {
|
|
95
99
|
AgentToolResultMediaBridge,
|
|
96
100
|
allocateInlineImages,
|
|
@@ -103,9 +107,10 @@ import {
|
|
|
103
107
|
savedToolOutputFiles,
|
|
104
108
|
ToolOutputFiles,
|
|
105
109
|
} from "./tools/tool-outputs"
|
|
106
|
-
import {
|
|
110
|
+
import { LEGACY_VIEW_FILE_TOOL, type SandboxFileViewer } from "./tools/view-file"
|
|
107
111
|
import { createWebFetchTool } from "./tools/web-fetch/tool"
|
|
108
112
|
import { createWebSearchTool } from "./tools/web-search"
|
|
113
|
+
import { createWriteTool } from "./tools/write"
|
|
109
114
|
import type { AgentTurnRuntime } from "./turn-runtime"
|
|
110
115
|
import type { AgentExecutionContext, AgentRunFiles, AgentTurnContext } from "./types"
|
|
111
116
|
import { prepareWorkflowInputAttachments } from "./workflow-input-attachments"
|
|
@@ -184,6 +189,8 @@ export interface CreateConversationAgentEnvironmentInput extends CreateAgentEnvi
|
|
|
184
189
|
readonly history: AgentTurnHistory
|
|
185
190
|
/** Framework-owned tools of the conversational Agent: delegation. */
|
|
186
191
|
readonly frameworkTools?: readonly ModelTool[]
|
|
192
|
+
/** Its children, which `wait` and `stop` reach beside its background commands. */
|
|
193
|
+
readonly children?: WaitableChildren
|
|
187
194
|
}
|
|
188
195
|
|
|
189
196
|
export interface CreateSubagentEnvironmentInput extends CreateAgentEnvironmentInput {
|
|
@@ -198,7 +205,7 @@ export interface CreateSubagentEnvironmentInput extends CreateAgentEnvironmentIn
|
|
|
198
205
|
readonly requestedBy?: Principal
|
|
199
206
|
/** Its thread's messages, whose files are projected again, and the paused run it continues. */
|
|
200
207
|
readonly history: SubagentHistory
|
|
201
|
-
/** Framework-owned tools of a child: `
|
|
208
|
+
/** Framework-owned tools of a child: `ask`, to its parent. */
|
|
202
209
|
readonly frameworkTools?: readonly ModelTool[]
|
|
203
210
|
/** Weigh the thread before the first call, and compact it on the child's thread when needed. */
|
|
204
211
|
readonly preflight?: { readonly budget: AgentContextBudget; readonly runtime: AgentTurnRuntime }
|
|
@@ -415,6 +422,7 @@ export async function createConversationAgentEnvironment(
|
|
|
415
422
|
imageBudget,
|
|
416
423
|
ontologyDocs,
|
|
417
424
|
frameworkTools: input.frameworkTools,
|
|
425
|
+
...(input.children ? { children: input.children } : {}),
|
|
418
426
|
...(memory ? { memory } : {}),
|
|
419
427
|
...(conversation === undefined ? {} : { conversation }),
|
|
420
428
|
onDetachedTeardown: input.onDetachedTeardown,
|
|
@@ -814,6 +822,8 @@ interface AgentEnvironmentSetup
|
|
|
814
822
|
readonly ontologyDocs?: RenderedOntologyDocs
|
|
815
823
|
readonly errorDetails?: AgentErrorDetails
|
|
816
824
|
readonly frameworkTools?: readonly ModelTool[]
|
|
825
|
+
/** The Agent's children, which `wait` and `stop` reach beside its background commands. */
|
|
826
|
+
readonly children?: WaitableChildren
|
|
817
827
|
/**
|
|
818
828
|
* A conversation, or a child of one, publishes artifacts into its conversation, through its
|
|
819
829
|
* session, and edits them from their installed copies; other runs return text.
|
|
@@ -892,17 +902,15 @@ async function startAgentEnvironment(
|
|
|
892
902
|
}),
|
|
893
903
|
]
|
|
894
904
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
filesForToolCall
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
})
|
|
905
|
-
)
|
|
905
|
+
// How `read` shows an image, a PDF or another file that is not text: as itself, stored with
|
|
906
|
+
// the call, through the run's media bridge.
|
|
907
|
+
const fileViewer: SandboxFileViewer = {
|
|
908
|
+
attachments: attachmentContext,
|
|
909
|
+
registry: fileRegistry,
|
|
910
|
+
filesForToolCall: ({ toolCallId, signal }) =>
|
|
911
|
+
filesForToolCall({ toolName: READ_TOOL_SPEC.name, toolCallId, signal }),
|
|
912
|
+
toolResultToModelOutput: (output) => mediaBridge.toModelOutput(output),
|
|
913
|
+
}
|
|
906
914
|
const resolveSandbox = () => ready
|
|
907
915
|
// Its own budget: saving outputs never takes what published artifacts and tool files need.
|
|
908
916
|
const toolOutputFiles = new ToolOutputFiles({
|
|
@@ -918,10 +926,16 @@ async function startAgentEnvironment(
|
|
|
918
926
|
console.error("[SixbAgent] Could not stop the run's background commands:", error)
|
|
919
927
|
})
|
|
920
928
|
}
|
|
921
|
-
|
|
929
|
+
// One per run: `edit` and `write` change only files this run read, as it read them.
|
|
930
|
+
const fileReads = new FileReadLedger()
|
|
931
|
+
appendBuiltInTool(tools, createReadTool(resolveSandbox, fileReads, fileViewer))
|
|
932
|
+
appendBuiltInTool(tools, createEditTool(resolveSandbox, fileReads))
|
|
933
|
+
appendBuiltInTool(tools, createWriteTool(resolveSandbox, fileReads))
|
|
934
|
+
appendBuiltInTool(tools, createGlobTool(resolveSandbox))
|
|
935
|
+
appendBuiltInTool(tools, createGrepTool(resolveSandbox))
|
|
922
936
|
appendBuiltInTool(tools, createBashTool(resolveSandbox, background))
|
|
923
|
-
appendBuiltInTool(tools,
|
|
924
|
-
appendBuiltInTool(tools,
|
|
937
|
+
appendBuiltInTool(tools, createWaitTool(resolveSandbox, background, input.children))
|
|
938
|
+
appendBuiltInTool(tools, createStopTool(resolveSandbox, background, input.children))
|
|
925
939
|
if (plan.web?.search) {
|
|
926
940
|
appendBuiltInTool(tools, createWebSearchTool({ search: input.webSearch, web: plan.web }))
|
|
927
941
|
}
|
|
@@ -1141,11 +1155,16 @@ function agentSandboxPath(handle: AgentSandboxHandle, path: string): string {
|
|
|
1141
1155
|
}
|
|
1142
1156
|
|
|
1143
1157
|
/**
|
|
1144
|
-
* The tools whose images reach the model after their step: the project's and `
|
|
1145
|
-
* outputs go through the run's media bridge
|
|
1158
|
+
* The tools whose images reach the model after their step: the project's and `read`, whose
|
|
1159
|
+
* outputs go through the run's media bridge, and `view_file`, which earlier threads hold. A replay
|
|
1160
|
+
* asks the same of the stored trace.
|
|
1146
1161
|
*/
|
|
1147
1162
|
function suppliesToolFiles(plan: Pick<ResolvedAgentExecutionPlan, "tools">): SuppliesToolFiles {
|
|
1148
|
-
const names = new Set([
|
|
1163
|
+
const names = new Set([
|
|
1164
|
+
...plan.tools.map((tool) => tool.name),
|
|
1165
|
+
READ_TOOL_SPEC.name,
|
|
1166
|
+
LEGACY_VIEW_FILE_TOOL,
|
|
1167
|
+
])
|
|
1149
1168
|
return (toolName) => names.has(toolName)
|
|
1150
1169
|
}
|
|
1151
1170
|
|
package/src/run-subagent.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type SubagentRunRecord,
|
|
18
18
|
} from "@sixb/core/storage"
|
|
19
19
|
import { renderCurrentTime, sentSettings } from "./agent-prompt"
|
|
20
|
-
import { unansweredQuestion } from "./ask-
|
|
20
|
+
import { unansweredQuestion } from "./ask-tool"
|
|
21
21
|
import { storeChildOutputs } from "./child-files"
|
|
22
22
|
import { createAgentContextGuard } from "./context-guard"
|
|
23
23
|
import { throwIfExecutionLost } from "./errors"
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
agentTraceFromModelSteps,
|
|
28
28
|
agentTraceFromPartialModelLoop,
|
|
29
29
|
} from "./model-adapters"
|
|
30
|
-
import { markReducedSteps } from "./run-agent-turn"
|
|
31
30
|
import type { SubagentAgentExecutionEnvironment } from "./run-environment"
|
|
32
31
|
import { monitorSandboxReadiness } from "./sandbox-readiness"
|
|
33
32
|
import {
|
|
@@ -38,6 +37,7 @@ import {
|
|
|
38
37
|
} from "./subagent-context"
|
|
39
38
|
import type { SubagentHistory } from "./subagent-continuation"
|
|
40
39
|
import type { SubagentDelivery, SubagentInbox } from "./subagent-inbox"
|
|
40
|
+
import { markReducedSteps } from "./turn-inbox"
|
|
41
41
|
import type { AgentTurnRuntime } from "./turn-runtime"
|
|
42
42
|
import type { AgentRunFiles, AgentTurnContext } from "./types"
|
|
43
43
|
|
|
@@ -84,7 +84,7 @@ export async function runSubagent(input: {
|
|
|
84
84
|
readonly runFiles: AgentRunFiles
|
|
85
85
|
/**
|
|
86
86
|
* What its parent sends it while it runs, read before its next step, and the questions it asks,
|
|
87
|
-
* through the inbox's `
|
|
87
|
+
* through the inbox's `ask` among its tools.
|
|
88
88
|
*/
|
|
89
89
|
readonly inbox: SubagentInbox
|
|
90
90
|
}): Promise<SubagentRunRecord> {
|
|
@@ -262,7 +262,7 @@ async function settleSubagent(
|
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
264
|
* Keep the child's outcome: its answer, what it wrote under `out/`, and what it did as its thread's
|
|
265
|
-
* next message. A paused child keeps its files too, for the run that continues it; `
|
|
265
|
+
* next message. A paused child keeps its files too, for the run that continues it; `wait`
|
|
266
266
|
* hands over only a finished child's, as an unfinished one's would pass for complete. Its `out/`
|
|
267
267
|
* is stored even when its workspace is kept: a continuation that finds it lost gets it back.
|
|
268
268
|
*/
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
import { createSixbError } from "@sixb/core/internal/errors"
|
|
19
19
|
import type { MaterializedArtifacts } from "./artifacts/materialize"
|
|
20
20
|
import type { PreparedAgentAttachmentContext } from "./attachments"
|
|
21
|
+
import { SEARCH_SCRIPT_SOURCE } from "./search-script"
|
|
21
22
|
import { TOOL_OUTPUTS_DIRECTORY } from "./tools/tool-outputs"
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -125,6 +126,8 @@ export async function prepareAgentSandboxApiContext(
|
|
|
125
126
|
...installFiles(ontologyDir, input.ontologyFiles),
|
|
126
127
|
{ path: join(binDir, "sixb"), contents: cli.launcher, mode: 0o755 },
|
|
127
128
|
{ path: join(libDir, "sixb.mjs"), contents: cli.artifact, mode: 0o644 },
|
|
129
|
+
// What `glob` and `grep` run.
|
|
130
|
+
{ path: join(libDir, "search.mjs"), contents: SEARCH_SCRIPT_SOURCE, mode: 0o644 },
|
|
128
131
|
{ path: runContextPath, contents: runContext },
|
|
129
132
|
{ path: runtimeProbePath, contents: "first\nsixb-runtime-probe\nthird\n", mode: 0o644 },
|
|
130
133
|
{
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference path="./search-script-assets.d.ts" />
|
|
2
|
+
import script from "./generated/search.mjs" with { type: "text" }
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The engine of `glob` and `grep`, bundled from `tools/search/` by
|
|
6
|
+
* `bun run generate:search-script`. A run installs it at `lib/search.mjs` and runs it on Bun or
|
|
7
|
+
* Node. Part of this module, so that a program compiled to one file carries it too.
|
|
8
|
+
*/
|
|
9
|
+
export const SEARCH_SCRIPT_SOURCE: Uint8Array = new TextEncoder().encode(script)
|