@sixb/agent 0.2.4 → 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/README.md +2 -2
- package/dist/agent-prompt.d.ts +13 -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.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.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11082 -9281
- package/dist/index.js.map +37 -33
- 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-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.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/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 +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/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/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/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +7 -5
- package/src/agent-prompt.ts +63 -28
- 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 +48 -99
- package/src/background-commands.ts +8 -6
- package/src/context-compaction.ts +1 -0
- package/src/conversation-messages.ts +11 -4
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +0 -1
- package/src/login-shell.ts +30 -3
- package/src/model-adapters.ts +23 -4
- package/src/model-lines.ts +1 -1
- package/src/run-agent-turn.ts +85 -129
- package/src/run-conversation-turn.ts +15 -6
- package/src/run-environment.ts +42 -11
- package/src/run-sandbox.ts +60 -1
- package/src/run-subagent.ts +9 -2
- package/src/sandbox-api-context.ts +10 -1
- 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 +7 -7
- package/src/skills/sixb-artifacts/canvas.md +3 -2
- 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/queries.md +2 -1
- package/src/subagent-tools.ts +23 -5
- package/src/tools/bash.ts +9 -10
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +4 -0
- 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 +7 -2
- 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/src/artifacts/board-previews.ts +0 -218
|
@@ -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
|