@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/ask-tool.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { type AgentMessage, AgentToolPublicError } from "@sixb/core"
|
|
2
|
+
import {
|
|
3
|
+
AGENT_QUESTION_LIMITS,
|
|
4
|
+
type AgentQuestion,
|
|
5
|
+
agentQuestionsText,
|
|
6
|
+
isChildAskTool,
|
|
7
|
+
} from "@sixb/core/internal/agents"
|
|
8
|
+
import { assertJsonValue, isJsonObject, type JsonObject, type ModelTool } from "@sixb/core/models"
|
|
9
|
+
import { agentToolErrorText } from "./model-adapters"
|
|
10
|
+
import type { SubagentInbox } from "./subagent-inbox"
|
|
11
|
+
|
|
12
|
+
export const ASK_TOOL_NAME = "ask"
|
|
13
|
+
|
|
14
|
+
export interface AskInput {
|
|
15
|
+
readonly questions: readonly AgentQuestion[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** What a sub-agent's `ask` answers: its parent's answer, or that it comes in a later turn. */
|
|
19
|
+
export type AskParentOutput =
|
|
20
|
+
| { readonly answer: string }
|
|
21
|
+
/** `question`: its id, which the answer of a later turn replies to. */
|
|
22
|
+
| { readonly status: "deferred"; readonly question: string; readonly note: string }
|
|
23
|
+
/** It paused on a held call too: only a decision continues it, without an answer. */
|
|
24
|
+
| { readonly status: "unanswered"; readonly question: string; readonly note: string }
|
|
25
|
+
|
|
26
|
+
/** What the Agent's `ask` answers: the user sees the questions, and the turn ends. */
|
|
27
|
+
export interface AskUserOutput {
|
|
28
|
+
readonly status: "asked"
|
|
29
|
+
readonly note: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Read by the child only once it continues: its loop pauses right after the step that asked. */
|
|
33
|
+
const DEFERRED_NOTE =
|
|
34
|
+
"Your parent's turn ended before it could answer. You continue with its answer, a <sixb_parent_answer> block, once it has one."
|
|
35
|
+
|
|
36
|
+
const UNANSWERED_NOTE =
|
|
37
|
+
"Your parent's turn ended before it could answer, and you paused on a call that waits for the user's approval: you continue once the user decides, without an answer. Ask again if you still need one."
|
|
38
|
+
|
|
39
|
+
const ASKED_NOTE = "The user sees your questions. Their answer comes as their next message."
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What a question deferred in the step that held a call reads as once the child continues: the
|
|
43
|
+
* decision continues it, and no answer comes with it. Only a continuation reads it, as the child
|
|
44
|
+
* paused right after that step, so what its thread keeps may say so without changing a byte the
|
|
45
|
+
* model already read.
|
|
46
|
+
*/
|
|
47
|
+
export function unansweredQuestion<TMessage extends Pick<AgentMessage, "parts">>(
|
|
48
|
+
messages: readonly TMessage[]
|
|
49
|
+
): readonly TMessage[] {
|
|
50
|
+
return messages.map((message) => ({
|
|
51
|
+
...message,
|
|
52
|
+
parts: message.parts.map((part) =>
|
|
53
|
+
part.type === "tool-call" &&
|
|
54
|
+
isChildAskTool(part.toolName) &&
|
|
55
|
+
part.state === "output-available" &&
|
|
56
|
+
isJsonObject(part.output) &&
|
|
57
|
+
part.output.status === "deferred" &&
|
|
58
|
+
typeof part.output.question === "string"
|
|
59
|
+
? {
|
|
60
|
+
...part,
|
|
61
|
+
output: { status: "unanswered", question: part.output.question, note: UNANSWERED_NOTE },
|
|
62
|
+
}
|
|
63
|
+
: part
|
|
64
|
+
),
|
|
65
|
+
}))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A sub-agent's questions to its parent, which it waits for within its step. Its parent reads them
|
|
70
|
+
* as one text and answers with `message_agent`; when its turn ends first, the child pauses on them
|
|
71
|
+
* and a later turn continues it with the answer.
|
|
72
|
+
*/
|
|
73
|
+
export function createAskParentTool(inbox: SubagentInbox): ModelTool<AskInput> {
|
|
74
|
+
return {
|
|
75
|
+
name: ASK_TOOL_NAME,
|
|
76
|
+
strict: true,
|
|
77
|
+
description: [
|
|
78
|
+
"Ask your parent agent, and wait for its answer, which this tool returns.",
|
|
79
|
+
"Ask only when you cannot go on without a decision that only your parent or the user can make, never what the project's data or your task answers. Put related questions in one call.",
|
|
80
|
+
].join("\n"),
|
|
81
|
+
inputSchema: askInputSchema(),
|
|
82
|
+
parseInput: parseAskInput,
|
|
83
|
+
execute: async ({ questions }, { signal, callId, toolCallId }) => {
|
|
84
|
+
const reply = await inbox.ask(
|
|
85
|
+
agentQuestionsText(questions),
|
|
86
|
+
`${callId}:${toolCallId}`,
|
|
87
|
+
signal
|
|
88
|
+
)
|
|
89
|
+
const output: AskParentOutput =
|
|
90
|
+
reply.kind === "answer"
|
|
91
|
+
? { answer: reply.text }
|
|
92
|
+
: { status: "deferred", question: reply.questionId, note: DEFERRED_NOTE }
|
|
93
|
+
assertJsonValue(output)
|
|
94
|
+
return output
|
|
95
|
+
},
|
|
96
|
+
errorText: agentToolErrorText,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The Agent's questions to the user. The turn ends after the step that asks (see
|
|
102
|
+
* {@link stepAskedUser}); the app and the TUI show the questions with their choices, and the
|
|
103
|
+
* user's answer is their next message, which the next turn reads after this call.
|
|
104
|
+
*/
|
|
105
|
+
export function createAskUserTool(): ModelTool<AskInput> {
|
|
106
|
+
return {
|
|
107
|
+
name: ASK_TOOL_NAME,
|
|
108
|
+
strict: true,
|
|
109
|
+
description: [
|
|
110
|
+
"Ask the user, and end your turn: they see your questions with their choices, and their answer comes as their next message.",
|
|
111
|
+
"Ask only when you cannot go on without an answer only the user can give, never what the conversation, the project's data or the task answers: otherwise make a reasonable assumption and say it. Put related questions in one call.",
|
|
112
|
+
].join("\n"),
|
|
113
|
+
inputSchema: askInputSchema(),
|
|
114
|
+
parseInput: parseAskInput,
|
|
115
|
+
execute: async () => {
|
|
116
|
+
const output: AskUserOutput = { status: "asked", note: ASKED_NOTE }
|
|
117
|
+
return { ...output }
|
|
118
|
+
},
|
|
119
|
+
errorText: agentToolErrorText,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Whether a step of the Agent's asked the user: the turn ends after it. A call refused for its
|
|
125
|
+
* input did not ask: the model reads why and tries again.
|
|
126
|
+
*/
|
|
127
|
+
export function stepAskedUser(step: {
|
|
128
|
+
readonly content: readonly {
|
|
129
|
+
readonly type: string
|
|
130
|
+
readonly toolName?: string
|
|
131
|
+
readonly output?: { readonly type: string }
|
|
132
|
+
}[]
|
|
133
|
+
}): boolean {
|
|
134
|
+
return step.content.some(
|
|
135
|
+
(part) =>
|
|
136
|
+
part.type === "tool-result" && part.toolName === ASK_TOOL_NAME && part.output?.type === "json"
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function askInputSchema(): JsonObject {
|
|
141
|
+
return {
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
questions: {
|
|
145
|
+
type: "array",
|
|
146
|
+
minItems: 1,
|
|
147
|
+
maxItems: AGENT_QUESTION_LIMITS.questions,
|
|
148
|
+
description: `One to ${AGENT_QUESTION_LIMITS.questions} questions, asked together.`,
|
|
149
|
+
items: {
|
|
150
|
+
type: "object",
|
|
151
|
+
properties: {
|
|
152
|
+
question: { type: "string", minLength: 1, description: "One short question." },
|
|
153
|
+
choices: {
|
|
154
|
+
type: "array",
|
|
155
|
+
maxItems: AGENT_QUESTION_LIMITS.choices,
|
|
156
|
+
items: { type: "string", minLength: 1 },
|
|
157
|
+
description: `Up to ${AGENT_QUESTION_LIMITS.choices} answers to pick from, when there are a few. A typed answer is always possible.`,
|
|
158
|
+
},
|
|
159
|
+
multiple: {
|
|
160
|
+
type: "boolean",
|
|
161
|
+
description: "Several of the choices may be picked. Default: false.",
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
required: ["question"],
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
required: ["questions"],
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function parseAskInput(value: unknown): AskInput {
|
|
175
|
+
if (!isJsonObject(value) || Object.keys(value).some((key) => key !== "questions")) {
|
|
176
|
+
throw askError("ask expects { questions: [...] }.")
|
|
177
|
+
}
|
|
178
|
+
const { questions } = value
|
|
179
|
+
if (
|
|
180
|
+
!Array.isArray(questions) ||
|
|
181
|
+
questions.length === 0 ||
|
|
182
|
+
questions.length > AGENT_QUESTION_LIMITS.questions
|
|
183
|
+
) {
|
|
184
|
+
throw askError(`ask expects 1 to ${AGENT_QUESTION_LIMITS.questions} questions.`)
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
questions: questions.map((entry, index): AgentQuestion => {
|
|
188
|
+
const at = `questions[${index}]`
|
|
189
|
+
if (
|
|
190
|
+
!isJsonObject(entry) ||
|
|
191
|
+
Object.keys(entry).some((key) => !["question", "choices", "multiple"].includes(key))
|
|
192
|
+
) {
|
|
193
|
+
throw askError(`${at} must be { question, choices?, multiple? }.`)
|
|
194
|
+
}
|
|
195
|
+
if (typeof entry.question !== "string" || !entry.question.trim()) {
|
|
196
|
+
throw askError(`${at}.question must be a non-empty question.`)
|
|
197
|
+
}
|
|
198
|
+
const choices = entry.choices ?? []
|
|
199
|
+
if (
|
|
200
|
+
!Array.isArray(choices) ||
|
|
201
|
+
choices.length > AGENT_QUESTION_LIMITS.choices ||
|
|
202
|
+
choices.some((choice) => typeof choice !== "string" || !choice.trim())
|
|
203
|
+
) {
|
|
204
|
+
throw askError(
|
|
205
|
+
`${at}.choices must be up to ${AGENT_QUESTION_LIMITS.choices} non-empty answers.`
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
if (entry.multiple !== undefined && typeof entry.multiple !== "boolean") {
|
|
209
|
+
throw askError(`${at}.multiple must be true or false.`)
|
|
210
|
+
}
|
|
211
|
+
const picked = (choices as string[]).map((choice) => choice.trim())
|
|
212
|
+
return {
|
|
213
|
+
question: entry.question.trim(),
|
|
214
|
+
...(picked.length > 0 ? { choices: picked } : {}),
|
|
215
|
+
...(entry.multiple === true && picked.length > 0 ? { multiple: true } : {}),
|
|
216
|
+
}
|
|
217
|
+
}),
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function askError(message: string): AgentToolPublicError {
|
|
222
|
+
return new AgentToolPublicError(`[SixbAgent] ${message}`)
|
|
223
|
+
}
|
package/src/attachments.ts
CHANGED
|
@@ -28,10 +28,11 @@ const MAX_ASSISTANT_ATTACHMENTS = 50
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Where a parent finds what its children wrote to `out/`, a directory per spawn key, in the context
|
|
31
|
-
* directory: `
|
|
31
|
+
* directory: `wait` and `stop` copy them there, and later turns materialize them there again.
|
|
32
32
|
*/
|
|
33
33
|
export const CHILD_FILES_DIRECTORY = "children"
|
|
34
|
-
|
|
34
|
+
/** The tools whose results hold a child's files: `wait_agent` is what earlier threads hold. */
|
|
35
|
+
const CHILD_FILE_TOOLS: ReadonlySet<string> = new Set(["wait", "stop", "wait_agent"])
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* How many files, and bytes, a sandbox receives of a run's attachments: also what a parent Agent
|
|
@@ -385,7 +386,7 @@ async function prepareOneAttachment(input: {
|
|
|
385
386
|
mayInlineContent &&
|
|
386
387
|
remainingTextBytes > 0 &&
|
|
387
388
|
shouldAttemptTextInline(mediaType, fileName, stat.sizeBytes)
|
|
388
|
-
// A tool can return a file the sandbox holds already, such as an attachment
|
|
389
|
+
// A tool can return a file the sandbox holds already, such as an attachment read showed:
|
|
389
390
|
// its output named that path, and the file stays there once.
|
|
390
391
|
const alreadyAt =
|
|
391
392
|
item.origin === "tool-result-file" ? input.materialized.get(fileRefKey(fileRef)) : undefined
|
|
@@ -466,7 +467,7 @@ async function prepareOneAttachment(input: {
|
|
|
466
467
|
}
|
|
467
468
|
|
|
468
469
|
metadataNote = !item.inlineContent
|
|
469
|
-
? "[Historical file kept as metadata: use
|
|
470
|
+
? "[Historical file kept as metadata: use read with the sandbox path when its contents are needed.]"
|
|
470
471
|
: remainingTextBytes === 0 && shouldAttemptTextInline(mediaType, fileName, stat.sizeBytes)
|
|
471
472
|
? "[File not inlined: the attachment text budget is exhausted; use the sandbox path or content URL.]"
|
|
472
473
|
: "[File not inlined: available through the sandbox path or content URL.]"
|
|
@@ -912,7 +913,7 @@ function sandboxAttachmentPath(
|
|
|
912
913
|
/**
|
|
913
914
|
* Where the call that returned a tool file put it in the sandbox, as its output showed: a later
|
|
914
915
|
* turn materializes it there again, so the replayed output still names a file that exists.
|
|
915
|
-
* `
|
|
916
|
+
* `wait` copies a child's file under `children/<key>/`, its `logicalPath`; a tool that
|
|
916
917
|
* stored a file put it at its call's tool-file path.
|
|
917
918
|
*/
|
|
918
919
|
function toolResultSandboxPath(
|
|
@@ -922,7 +923,7 @@ function toolResultSandboxPath(
|
|
|
922
923
|
const { toolCall, fileRef } = item
|
|
923
924
|
if (!toolCall) return undefined
|
|
924
925
|
|
|
925
|
-
if (toolCall.toolName
|
|
926
|
+
if (CHILD_FILE_TOOLS.has(toolCall.toolName)) {
|
|
926
927
|
const path =
|
|
927
928
|
fileRef.logicalPath === undefined ? undefined : posix.normalize(fileRef.logicalPath)
|
|
928
929
|
if (!path || path.startsWith("/") || path === ".." || path.startsWith("../")) return undefined
|
|
@@ -8,7 +8,7 @@ import { type AgentSandboxHandle, contextPath } from "./sandbox-handle"
|
|
|
8
8
|
// A background command runs in the call that starts it, held open until it ends: a provider that
|
|
9
9
|
// kills what a call left behind once it returns (a cgroup, a PID namespace) leaves it alone, and
|
|
10
10
|
// it needs nothing of a provider but `runCommand`. It runs in a process group of its own, which
|
|
11
|
-
// `
|
|
11
|
+
// `stop` signals from inside the sandbox; the held call's abort is the fallback where another
|
|
12
12
|
// call cannot reach it. Its output goes to a file in the run's context directory, which the agent
|
|
13
13
|
// reads with `read` as any other file.
|
|
14
14
|
|
|
@@ -37,7 +37,7 @@ export type BackgroundCommandStatus = "running" | "exited" | "stopped"
|
|
|
37
37
|
|
|
38
38
|
/** A background command as its tools report it, and as a chat can show it. */
|
|
39
39
|
export interface BackgroundCommandState {
|
|
40
|
-
/** `bg_<hex>`: the id `
|
|
40
|
+
/** `bg_<hex>`: the id `wait` and `stop` take, never the same in two runs. */
|
|
41
41
|
readonly id: string
|
|
42
42
|
readonly command: string
|
|
43
43
|
readonly status: BackgroundCommandStatus
|
|
@@ -53,7 +53,7 @@ export interface BackgroundCommandState {
|
|
|
53
53
|
readonly outputPath: string
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/** What `
|
|
56
|
+
/** What `wait` and `stop` return of it: its state, and what it wrote since the last read. */
|
|
57
57
|
export interface BackgroundCommandOutput extends BackgroundCommandState {
|
|
58
58
|
/** What it wrote since the last read: its newest 20,000 bytes at most. */
|
|
59
59
|
readonly output: string
|
|
@@ -128,7 +128,7 @@ export class BackgroundCommands {
|
|
|
128
128
|
const running = [...this.#commands.values()].filter((entry) => entry.status === "running")
|
|
129
129
|
if (running.length >= MAX_RUNNING) {
|
|
130
130
|
throw new AgentToolPublicError(
|
|
131
|
-
`[SixbAgent] ${MAX_RUNNING} background commands are running already: stop one with
|
|
131
|
+
`[SixbAgent] ${MAX_RUNNING} background commands are running already: stop one with stop first.`
|
|
132
132
|
)
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -460,7 +460,7 @@ async function signalGroup(entry: BackgroundCommand, signal: "TERM" | "KILL"): P
|
|
|
460
460
|
/**
|
|
461
461
|
* Stop the commands a `sixb` that ended without stopping them left running: one killed, or that
|
|
462
462
|
* crashed. Their pid files are all that is left of them. Each group still running its command
|
|
463
|
-
* gets SIGTERM, then SIGKILL after the grace period `
|
|
463
|
+
* gets SIGTERM, then SIGKILL after the grace period `stop` gives, in one call.
|
|
464
464
|
*/
|
|
465
465
|
export async function stopLeftRunning(
|
|
466
466
|
sandbox: Sandbox,
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { type AgentMessage, stableJsonStringify } from "@sixb/core"
|
|
2
2
|
import type { ModelTool } from "@sixb/core/models"
|
|
3
3
|
import type { BackgroundCommandState, BackgroundCommands } from "./background-commands"
|
|
4
|
-
import {
|
|
5
|
-
import { BASH_TOOL_SPEC } from "./tools/bash"
|
|
4
|
+
import { reportedCommands } from "./tools/background"
|
|
6
5
|
|
|
7
6
|
/** A command's displayed form in a notice: its first line, cut. */
|
|
8
7
|
const NOTICE_COMMAND_CHARS = 80
|
|
9
8
|
|
|
10
|
-
/** The tools whose results report a background command's state. */
|
|
11
|
-
const STATE_TOOLS: ReadonlySet<string> = new Set([
|
|
12
|
-
BASH_TOOL_SPEC.name,
|
|
13
|
-
BASH_OUTPUT_TOOL_SPEC.name,
|
|
14
|
-
BASH_STOP_TOOL_SPEC.name,
|
|
15
|
-
])
|
|
16
|
-
|
|
17
9
|
/** A notice's line that tells a command ended, and its id. */
|
|
18
10
|
const ENDED_LINE = /^Background command (\S+) \(`.*?`\) (?:exited with code|was stopped)/gm
|
|
19
11
|
|
|
@@ -113,9 +105,10 @@ export function backgroundCommandsLeftRunning(
|
|
|
113
105
|
for (const part of message.parts) {
|
|
114
106
|
if (part.type !== "tool-call" || part.state !== "output-available") continue
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
108
|
+
for (const command of reportedCommands(part.toolName, part.output)) {
|
|
109
|
+
if (!isCommandState(command)) continue
|
|
110
|
+
if (command.status === "running") running.set(command.id, command)
|
|
111
|
+
else running.delete(command.id)
|
|
119
112
|
}
|
|
120
113
|
if (part.modelOutput?.type === "text") {
|
|
121
114
|
for (const [, id] of part.modelOutput.value.matchAll(ENDED_LINE)) {
|
package/src/child-files.ts
CHANGED
|
@@ -171,7 +171,7 @@ async function readHandedSources(
|
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* The child's side: the files its parent handed over, at the same paths in its sandbox, listed in
|
|
174
|
-
* `$SIXB_ATTACHMENTS` and readable with `
|
|
174
|
+
* `$SIXB_ATTACHMENTS` and readable with `read`.
|
|
175
175
|
*/
|
|
176
176
|
export async function prepareHandedFiles(input: {
|
|
177
177
|
readonly projectId: string
|
package/src/child-questions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A question a child asked: the id of its mail and what it asks. A child paused on it keeps both in
|
|
3
|
-
* its thread, the
|
|
3
|
+
* its thread, the questions as its `ask` call's input and the id in that call's output.
|
|
4
4
|
*/
|
|
5
5
|
export interface QuestionRef {
|
|
6
6
|
readonly id: string
|
|
@@ -1100,11 +1100,14 @@ function summaryReasoning(
|
|
|
1100
1100
|
* the provider cached. The instruction asks for text alone; a call the model makes anyway never
|
|
1101
1101
|
* runs.
|
|
1102
1102
|
*/
|
|
1103
|
-
function summaryTool(
|
|
1103
|
+
function summaryTool(
|
|
1104
|
+
tool: Pick<ModelTool, "name" | "description" | "inputSchema" | "strict">
|
|
1105
|
+
): ModelTool {
|
|
1104
1106
|
return {
|
|
1105
1107
|
name: tool.name,
|
|
1106
1108
|
description: tool.description,
|
|
1107
1109
|
inputSchema: tool.inputSchema,
|
|
1110
|
+
...(tool.strict ? { strict: true } : {}),
|
|
1108
1111
|
parseInput: (value) => value,
|
|
1109
1112
|
execute: async () => {
|
|
1110
1113
|
throw new Error("[SixbAgent] A context summary runs no tools.")
|