@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.
Files changed (149) hide show
  1. package/README.md +3 -3
  2. package/dist/agent-prompt.d.ts.map +1 -1
  3. package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
  4. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
  5. package/dist/artifacts/publish-tool.d.ts +26 -44
  6. package/dist/artifacts/publish-tool.d.ts.map +1 -1
  7. package/dist/ask-tool.d.ts +62 -0
  8. package/dist/ask-tool.d.ts.map +1 -0
  9. package/dist/attachments.d.ts +1 -1
  10. package/dist/attachments.d.ts.map +1 -1
  11. package/dist/background-commands.d.ts +3 -3
  12. package/dist/background-commands.d.ts.map +1 -1
  13. package/dist/background-notices.d.ts.map +1 -1
  14. package/dist/child-files.d.ts +1 -1
  15. package/dist/child-questions.d.ts +1 -1
  16. package/dist/index.d.ts +1 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +10457 -7971
  19. package/dist/index.js.map +46 -38
  20. package/dist/run-agent-turn.d.ts +3 -14
  21. package/dist/run-agent-turn.d.ts.map +1 -1
  22. package/dist/run-conversation-turn.d.ts.map +1 -1
  23. package/dist/run-environment.d.ts +4 -1
  24. package/dist/run-environment.d.ts.map +1 -1
  25. package/dist/run-subagent.d.ts +1 -1
  26. package/dist/run-subagent.d.ts.map +1 -1
  27. package/dist/sandbox-api-context.d.ts.map +1 -1
  28. package/dist/search-script.d.ts +7 -0
  29. package/dist/search-script.d.ts.map +1 -0
  30. package/dist/skills/built-in.d.ts.map +1 -1
  31. package/dist/subagent-tools.d.ts +20 -1
  32. package/dist/subagent-tools.d.ts.map +1 -1
  33. package/dist/tools/background.d.ts +50 -18
  34. package/dist/tools/background.d.ts.map +1 -1
  35. package/dist/tools/bash.d.ts +1 -0
  36. package/dist/tools/bash.d.ts.map +1 -1
  37. package/dist/tools/edit-text.d.ts +22 -0
  38. package/dist/tools/edit-text.d.ts.map +1 -0
  39. package/dist/tools/edit.d.ts +54 -0
  40. package/dist/tools/edit.d.ts.map +1 -0
  41. package/dist/tools/file-writes.d.ts +52 -0
  42. package/dist/tools/file-writes.d.ts.map +1 -0
  43. package/dist/tools/glob.d.ts +41 -0
  44. package/dist/tools/glob.d.ts.map +1 -0
  45. package/dist/tools/grep.d.ts +64 -0
  46. package/dist/tools/grep.d.ts.map +1 -0
  47. package/dist/tools/model-spec.d.ts.map +1 -1
  48. package/dist/tools/read.d.ts +16 -3
  49. package/dist/tools/read.d.ts.map +1 -1
  50. package/dist/tools/sandbox-search.d.ts +26 -0
  51. package/dist/tools/sandbox-search.d.ts.map +1 -0
  52. package/dist/tools/search/command.d.ts +15 -0
  53. package/dist/tools/search/command.d.ts.map +1 -0
  54. package/dist/tools/search/gitignore.d.ts +28 -0
  55. package/dist/tools/search/gitignore.d.ts.map +1 -0
  56. package/dist/tools/search/glob.d.ts +15 -0
  57. package/dist/tools/search/glob.d.ts.map +1 -0
  58. package/dist/tools/search/main.d.ts +2 -0
  59. package/dist/tools/search/main.d.ts.map +1 -0
  60. package/dist/tools/search/match.d.ts +30 -0
  61. package/dist/tools/search/match.d.ts.map +1 -0
  62. package/dist/tools/search/pattern.d.ts +19 -0
  63. package/dist/tools/search/pattern.d.ts.map +1 -0
  64. package/dist/tools/search/read.d.ts +62 -0
  65. package/dist/tools/search/read.d.ts.map +1 -0
  66. package/dist/tools/search/request.d.ts +80 -0
  67. package/dist/tools/search/request.d.ts.map +1 -0
  68. package/dist/tools/search/search.d.ts +4 -0
  69. package/dist/tools/search/search.d.ts.map +1 -0
  70. package/dist/tools/search/walk.d.ts +43 -0
  71. package/dist/tools/search/walk.d.ts.map +1 -0
  72. package/dist/tools/tool-outputs.d.ts.map +1 -1
  73. package/dist/tools/view-file.d.ts +20 -23
  74. package/dist/tools/view-file.d.ts.map +1 -1
  75. package/dist/tools/web-fetch/tool.d.ts +1 -0
  76. package/dist/tools/web-fetch/tool.d.ts.map +1 -1
  77. package/dist/tools/web-search.d.ts +1 -0
  78. package/dist/tools/web-search.d.ts.map +1 -1
  79. package/dist/tools/write.d.ts +36 -0
  80. package/dist/tools/write.d.ts.map +1 -0
  81. package/dist/turn-inbox.d.ts +75 -0
  82. package/dist/turn-inbox.d.ts.map +1 -0
  83. package/package.json +6 -4
  84. package/src/agent-prompt.ts +10 -9
  85. package/src/agent-runtime/preflight.ts +1 -0
  86. package/src/artifacts/layout-check/check.cjs +176 -95
  87. package/src/artifacts/layout-check/layout-check.ts +118 -76
  88. package/src/artifacts/publish-tool.ts +123 -192
  89. package/src/ask-tool.ts +223 -0
  90. package/src/attachments.ts +7 -6
  91. package/src/background-commands.ts +5 -5
  92. package/src/background-notices.ts +5 -12
  93. package/src/child-files.ts +1 -1
  94. package/src/child-questions.ts +1 -1
  95. package/src/context-compaction.ts +4 -1
  96. package/src/generated/search.mjs +985 -0
  97. package/src/index.ts +1 -2
  98. package/src/run-agent-turn.ts +99 -133
  99. package/src/run-child.ts +1 -1
  100. package/src/run-conversation-turn.ts +8 -5
  101. package/src/run-environment.ts +40 -21
  102. package/src/run-subagent.ts +4 -4
  103. package/src/sandbox-api-context.ts +3 -0
  104. package/src/search-script-assets.d.ts +5 -0
  105. package/src/search-script.ts +9 -0
  106. package/src/skills/built-in.ts +16 -0
  107. package/src/skills/sixb-artifacts/SKILL.md +13 -13
  108. package/src/skills/sixb-artifacts/canvas.md +5 -4
  109. package/src/skills/sixb-artifacts/document.md +92 -5
  110. package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
  111. package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
  112. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
  113. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
  114. package/src/skills/sixb-artifacts/page.md +2 -2
  115. package/src/skills/sixb-artifacts/queries.md +2 -1
  116. package/src/skills/sixb-artifacts/slides.md +2 -2
  117. package/src/subagent-tools.ts +115 -81
  118. package/src/tools/background.ts +227 -67
  119. package/src/tools/bash.ts +2 -1
  120. package/src/tools/edit-text.ts +241 -0
  121. package/src/tools/edit.ts +166 -0
  122. package/src/tools/file-writes.ts +270 -0
  123. package/src/tools/glob.ts +124 -0
  124. package/src/tools/grep.ts +190 -0
  125. package/src/tools/model-spec.ts +13 -13
  126. package/src/tools/read.ts +75 -9
  127. package/src/tools/sandbox-search.ts +219 -0
  128. package/src/tools/search/command.ts +116 -0
  129. package/src/tools/search/gitignore.ts +101 -0
  130. package/src/tools/search/glob.ts +90 -0
  131. package/src/tools/search/main.ts +9 -0
  132. package/src/tools/search/match.ts +278 -0
  133. package/src/tools/search/pattern.ts +178 -0
  134. package/src/tools/search/read.ts +237 -0
  135. package/src/tools/search/request.ts +101 -0
  136. package/src/tools/search/search.ts +297 -0
  137. package/src/tools/search/walk.ts +145 -0
  138. package/src/tools/tool-outputs.ts +9 -4
  139. package/src/tools/view-file.ts +78 -80
  140. package/src/tools/web-fetch/tool.ts +2 -1
  141. package/src/tools/web-search.ts +1 -0
  142. package/src/tools/write.ts +95 -0
  143. package/src/turn-inbox.ts +283 -0
  144. package/dist/artifacts/board-previews.d.ts +0 -41
  145. package/dist/artifacts/board-previews.d.ts.map +0 -1
  146. package/dist/ask-parent-tool.d.ts +0 -36
  147. package/dist/ask-parent-tool.d.ts.map +0 -1
  148. package/src/artifacts/board-previews.ts +0 -218
  149. package/src/ask-parent-tool.ts +0 -100
@@ -1,218 +0,0 @@
1
- import { posix } from "node:path"
2
- import type { BlobStorage, Sandbox } from "@sixb/core"
3
- import { ARTIFACT_THEME_FILE, CANVAS_FILE, parseArtifactTheme } from "@sixb/core/artifacts"
4
- import type { AgentRunMissingPreview } from "@sixb/core/internal/agents"
5
- import {
6
- artifactQueryName,
7
- BOARD_PREVIEW_MEDIA_TYPES,
8
- type BoardPreviewInput,
9
- MAX_BOARD_PREVIEW_BYTES,
10
- type MissingBoardPreview,
11
- type RefusedBoardPreview,
12
- } from "@sixb/core/internal/artifacts/publish"
13
- import type { ArtifactVersionRecord } from "@sixb/core/storage"
14
- import { SANDBOX_CONTEXT_DIRECTORY } from "../run-sandbox"
15
- import { readSandboxFiles } from "../sandbox-files"
16
- import type { AgentSandboxHandle } from "../sandbox-handle"
17
- import { type CheckedPreview, type CheckedQuery, checkLayout } from "./layout-check/layout-check"
18
- import { type PublishedArtifactFile, readArtifactVersionFiles } from "./materialize"
19
-
20
- // The pictures of a canvas's boards, which the app shows until a reader opens a board. The layout
21
- // check takes them as it checks each board; these read them out of the sandbox and store them as
22
- // blobs, for the version's previews. The agent worker renders the same way in a sandbox of its
23
- // own, for a version nobody rendered: one a person edited in the app.
24
-
25
- const READ_TIMEOUT_MS = 60_000
26
- /**
27
- * The most one command reads out of the sandbox, base64 on its stdout: a canvas of a hundred
28
- * boards' pictures takes a few commands, not one each.
29
- */
30
- const READ_BATCH_BYTES = 24 * 1024 * 1024
31
- /** Where the worker writes the version it renders, in its blank sandbox. */
32
- const WORK_DIRECTORY = "canvas"
33
-
34
- /** The pictures read and stored, and those that were not, with why. */
35
- export interface CheckedPreviews {
36
- readonly previews: readonly BoardPreviewInput[]
37
- readonly dropped: readonly RefusedBoardPreview[]
38
- }
39
-
40
- /**
41
- * The pictures the check took that `missing` asks for, read out of the sandbox a batch at a time
42
- * and each stored in `blobStorage`. A picture the check did not take is left out: the worker
43
- * renders it later. Each stands alone: one too large or that cannot be read or stored is dropped,
44
- * and returned with why, and the others are kept.
45
- */
46
- export async function storeCheckedPreviews(input: {
47
- readonly handle: AgentSandboxHandle
48
- readonly checked: readonly CheckedPreview[]
49
- readonly missing: readonly AgentRunMissingPreview[]
50
- readonly blobStorage: Pick<BlobStorage, "put">
51
- readonly signal: AbortSignal
52
- }): Promise<CheckedPreviews> {
53
- const wanted = new Set(
54
- input.missing.flatMap(({ board, themes }) => themes.map((theme) => `${board}\0${theme}`))
55
- )
56
- const pictures = input.checked.filter(({ board, theme }) => wanted.has(`${board}\0${theme}`))
57
-
58
- const previews: BoardPreviewInput[] = []
59
- const dropped: RefusedBoardPreview[] = []
60
- const drop = (picture: CheckedPreview, reason: string) => {
61
- const { board, theme, size } = picture
62
- dropped.push({ board, theme, size, reason })
63
- }
64
-
65
- for (const batch of readBatches(pictures)) {
66
- const read = await readSandboxFiles(input.handle, {
67
- paths: batch.map((picture) => picture.path),
68
- maxBytes: MAX_BOARD_PREVIEW_BYTES,
69
- signal: input.signal,
70
- timeoutMs: READ_TIMEOUT_MS,
71
- })
72
-
73
- for (const [index, picture] of batch.entries()) {
74
- const file = read[index]
75
- if (!file || "error" in file) {
76
- drop(
77
- picture,
78
- file?.error === "too_large"
79
- ? `it is past the ${MAX_BOARD_PREVIEW_BYTES} bytes kept`
80
- : "it could not be read"
81
- )
82
- continue
83
- }
84
-
85
- try {
86
- const stored = await input.blobStorage.put({
87
- body: file.bytes,
88
- expectedSizeBytes: file.bytes.byteLength,
89
- signal: input.signal,
90
- fileName: posix.basename(picture.path),
91
- mediaType: BOARD_PREVIEW_MEDIA_TYPES[picture.size],
92
- })
93
- previews.push({
94
- board: picture.board,
95
- theme: picture.theme,
96
- size: picture.size,
97
- file: stored,
98
- })
99
- } catch (error) {
100
- if (input.signal.aborted) throw error
101
- console.warn(`[SixbAgent] Could not store the picture '${picture.path}':`, error)
102
- drop(picture, "it could not be stored")
103
- }
104
- }
105
- }
106
-
107
- return { previews, dropped }
108
- }
109
-
110
- /** The pictures in batches of at most {@link READ_BATCH_BYTES}, as the check sized them. */
111
- function readBatches(pictures: readonly CheckedPreview[]): CheckedPreview[][] {
112
- const batches: CheckedPreview[][] = []
113
- let batch: CheckedPreview[] = []
114
- let bytes = 0
115
- for (const picture of pictures) {
116
- const size = picture.bytes ?? MAX_BOARD_PREVIEW_BYTES
117
- if (batch.length > 0 && bytes + size > READ_BATCH_BYTES) {
118
- batches.push(batch)
119
- batch = []
120
- bytes = 0
121
- }
122
- batch.push(picture)
123
- bytes += Math.min(size, MAX_BOARD_PREVIEW_BYTES)
124
- }
125
- if (batch.length > 0) batches.push(batch)
126
- return batches
127
- }
128
-
129
- /**
130
- * Renders the pictures a stored canvas version's boards miss, in `sandbox`, a blank one created
131
- * for it: the version's files are written there, each missing board is opened in every mode it
132
- * misses, and the pictures are stored in `blobStorage`. What the boards' queries return, `queries`
133
- * holds as the version's publisher read them. Without them a board that reads a query is not
134
- * pictured: it would show its queries rejecting, which no reader sees. A sandbox without the
135
- * agent image's browser renders nothing.
136
- */
137
- export async function renderBoardPreviews(input: {
138
- readonly sandbox: Sandbox
139
- readonly version: ArtifactVersionRecord
140
- readonly missing: readonly MissingBoardPreview[]
141
- readonly blobStorage: Pick<BlobStorage, "put" | "open" | "stat">
142
- readonly queries?: Readonly<Record<string, CheckedQuery>>
143
- readonly signal: AbortSignal
144
- }): Promise<CheckedPreviews> {
145
- const { sandbox, version, signal } = input
146
- if (input.missing.length === 0) return { previews: [], dropped: [] }
147
-
148
- const handle: AgentSandboxHandle = { sandbox, contextDirectory: SANDBOX_CONTEXT_DIRECTORY }
149
- const files = await readArtifactVersionFiles(input.blobStorage, version, signal)
150
- const bytesOf = (path: string) => files.find((file) => file.path === path)?.bytes
151
-
152
- const reading = input.queries ? undefined : boardsReadingQueries(files)
153
- const missing = input.missing.filter(({ board }) => !reading?.(board.file))
154
- if (missing.length === 0) return { previews: [], dropped: [] }
155
-
156
- const directory = posix.resolve(sandbox.workingDirectory, WORK_DIRECTORY)
157
- await sandbox.writeFiles(
158
- files
159
- .filter((file) => file.path !== CANVAS_FILE)
160
- .map((file) => ({ path: posix.join(directory, file.path), contents: file.bytes }))
161
- )
162
-
163
- const themeFile = bytesOf(ARTIFACT_THEME_FILE)
164
- const theme = themeFile ? parseArtifactTheme(new TextDecoder().decode(themeFile)) : null
165
- const check = await checkLayout({
166
- handle,
167
- layout: "canvas",
168
- boards: missing.flatMap(({ board }) => {
169
- const html = bytesOf(board.file)
170
- return html
171
- ? [{ id: board.id, file: board.file, w: board.w, h: board.h, html, pictured: true }]
172
- : []
173
- }),
174
- directory,
175
- files: files.map((file) => file.path),
176
- name: `${version.artifactId}-v${version.version}`,
177
- ...(theme && "theme" in theme ? { theme: theme.theme } : {}),
178
- ...(input.queries ? { queries: input.queries } : {}),
179
- signal,
180
- })
181
- if (check.status !== "checked") {
182
- console.warn(
183
- `[SixbAgent] The boards of version ${version.version} of '${version.artifactId}' were not pictured: ${check.reason}.`
184
- )
185
- return { previews: [], dropped: [] }
186
- }
187
-
188
- return storeCheckedPreviews({
189
- handle,
190
- checked: check.previews,
191
- missing: missing.map(({ board, themes }) => ({ board: board.id, themes })),
192
- blobStorage: input.blobStorage,
193
- signal,
194
- })
195
- }
196
-
197
- /**
198
- * Whether a board may read a query, for a version whose answers are not at hand: none when the
199
- * version holds no query; otherwise a board whose HTML names `query`, and every board once a
200
- * script beside them does, since which boards load it is not known. Erring on the side of reading
201
- * one only leaves a board its outline.
202
- */
203
- function boardsReadingQueries(
204
- files: readonly PublishedArtifactFile[]
205
- ): ((boardFile: string) => boolean) | undefined {
206
- if (!files.some((file) => artifactQueryName(file.path) !== undefined)) return undefined
207
-
208
- const names = (file: PublishedArtifactFile) =>
209
- /\bquery\b/.test(new TextDecoder().decode(file.bytes))
210
- if (files.some((file) => SCRIPT.test(file.path) && names(file))) return () => true
211
-
212
- return (boardFile) => {
213
- const html = files.find((file) => file.path === boardFile)
214
- return html === undefined || names(html)
215
- }
216
- }
217
-
218
- const SCRIPT = /\.m?js$/i
@@ -1,100 +0,0 @@
1
- import { type AgentMessage, AgentToolPublicError } from "@sixb/core"
2
- import { assertJsonValue, isJsonObject, type ModelTool } from "@sixb/core/models"
3
- import { agentToolErrorText } from "./model-adapters"
4
- import type { SubagentInbox } from "./subagent-inbox"
5
-
6
- export interface AskParentInput {
7
- readonly question: string
8
- }
9
-
10
- /** What `ask_parent` answers: the parent's answer, or that it comes in a later turn. */
11
- export type AskParentOutput =
12
- | { readonly answer: string }
13
- /** `question`: its id, which the answer of a later turn replies to. */
14
- | { readonly status: "deferred"; readonly question: string; readonly note: string }
15
- /** It paused on a held call too: only a decision continues it, without an answer. */
16
- | { readonly status: "unanswered"; readonly question: string; readonly note: string }
17
-
18
- /** Read by the child only once it continues: its loop pauses right after the step that asked. */
19
- const DEFERRED_NOTE =
20
- "Your parent's turn ended before it could answer. You continue with its answer, a <sixb_parent_answer> block, once it has one."
21
-
22
- const UNANSWERED_NOTE =
23
- "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."
24
-
25
- /**
26
- * What a question deferred in the step that held a call reads as once the child continues: the
27
- * decision continues it, and no answer comes with it. Only a continuation reads it, as the child
28
- * paused right after that step, so what its thread keeps may say so without changing a byte the
29
- * model already read.
30
- */
31
- export function unansweredQuestion<TMessage extends Pick<AgentMessage, "parts">>(
32
- messages: readonly TMessage[]
33
- ): readonly TMessage[] {
34
- return messages.map((message) => ({
35
- ...message,
36
- parts: message.parts.map((part) =>
37
- part.type === "tool-call" &&
38
- part.toolName === "ask_parent" &&
39
- part.state === "output-available" &&
40
- isJsonObject(part.output) &&
41
- part.output.status === "deferred" &&
42
- typeof part.output.question === "string"
43
- ? {
44
- ...part,
45
- output: { status: "unanswered", question: part.output.question, note: UNANSWERED_NOTE },
46
- }
47
- : part
48
- ),
49
- }))
50
- }
51
-
52
- /**
53
- * A child's question to its parent, which it waits for within its step. Its parent answers with
54
- * `message_agent`; when its turn ends first, the child pauses on the question and a later turn
55
- * continues it with the answer.
56
- */
57
- export function createAskParentTool(inbox: SubagentInbox): ModelTool<AskParentInput> {
58
- return {
59
- name: "ask_parent",
60
- description: [
61
- "Ask your parent agent a question and wait for its answer, which this tool returns.",
62
- "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. One question at a time.",
63
- ].join("\n"),
64
- inputSchema: {
65
- type: "object",
66
- properties: {
67
- question: {
68
- type: "string",
69
- minLength: 1,
70
- description: "One short question, with the choices you see when there are some.",
71
- },
72
- },
73
- required: ["question"],
74
- additionalProperties: false,
75
- },
76
- parseInput: parseAskParentInput,
77
- execute: async ({ question }, { signal, callId, toolCallId }) => {
78
- const reply = await inbox.ask(question, `${callId}:${toolCallId}`, signal)
79
- const output: AskParentOutput =
80
- reply.kind === "answer"
81
- ? { answer: reply.text }
82
- : { status: "deferred", question: reply.questionId, note: DEFERRED_NOTE }
83
- assertJsonValue(output)
84
- return output
85
- },
86
- errorText: agentToolErrorText,
87
- }
88
- }
89
-
90
- function parseAskParentInput(value: unknown): AskParentInput {
91
- if (
92
- !isJsonObject(value) ||
93
- Object.keys(value).some((key) => key !== "question") ||
94
- typeof value.question !== "string" ||
95
- !value.question.trim()
96
- ) {
97
- throw new AgentToolPublicError("[SixbAgent] ask_parent expects a non-empty question.")
98
- }
99
- return { question: value.question.trim() }
100
- }