@sixb/agent 0.2.1 → 0.2.3

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 (107) hide show
  1. package/README.md +2 -1
  2. package/dist/agent-prompt.d.ts +13 -0
  3. package/dist/agent-prompt.d.ts.map +1 -1
  4. package/dist/agent-runtime/preflight.d.ts.map +1 -1
  5. package/dist/artifacts/board-previews.d.ts +41 -0
  6. package/dist/artifacts/board-previews.d.ts.map +1 -0
  7. package/dist/artifacts/layout-check/layout-check.d.ts +38 -6
  8. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
  9. package/dist/artifacts/layout-check/overview.d.ts +17 -0
  10. package/dist/artifacts/layout-check/overview.d.ts.map +1 -0
  11. package/dist/artifacts/materialize.d.ts +56 -24
  12. package/dist/artifacts/materialize.d.ts.map +1 -1
  13. package/dist/artifacts/publish-tool.d.ts +35 -9
  14. package/dist/artifacts/publish-tool.d.ts.map +1 -1
  15. package/dist/background-commands.d.ts +95 -0
  16. package/dist/background-commands.d.ts.map +1 -0
  17. package/dist/background-notices.d.ts +31 -0
  18. package/dist/background-notices.d.ts.map +1 -0
  19. package/dist/computer-runner.d.ts +63 -2
  20. package/dist/computer-runner.d.ts.map +1 -1
  21. package/dist/context-compaction.d.ts +3 -0
  22. package/dist/context-compaction.d.ts.map +1 -1
  23. package/dist/execution-plan.d.ts +12 -2
  24. package/dist/execution-plan.d.ts.map +1 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +11814 -8722
  28. package/dist/index.js.map +35 -23
  29. package/dist/login-shell.d.ts +16 -0
  30. package/dist/login-shell.d.ts.map +1 -0
  31. package/dist/run-child.d.ts +3 -0
  32. package/dist/run-child.d.ts.map +1 -1
  33. package/dist/run-conversation-turn.d.ts +6 -2
  34. package/dist/run-conversation-turn.d.ts.map +1 -1
  35. package/dist/run-environment.d.ts +12 -2
  36. package/dist/run-environment.d.ts.map +1 -1
  37. package/dist/run-sandbox.d.ts +23 -0
  38. package/dist/run-sandbox.d.ts.map +1 -1
  39. package/dist/sandbox-files.d.ts +19 -0
  40. package/dist/sandbox-files.d.ts.map +1 -1
  41. package/dist/subagent-tools.d.ts +3 -1
  42. package/dist/subagent-tools.d.ts.map +1 -1
  43. package/dist/tools/background.d.ts +50 -0
  44. package/dist/tools/background.d.ts.map +1 -0
  45. package/dist/tools/bash.d.ts +12 -4
  46. package/dist/tools/bash.d.ts.map +1 -1
  47. package/dist/tools/model-spec.d.ts +9 -2
  48. package/dist/tools/model-spec.d.ts.map +1 -1
  49. package/dist/tools/tool-files.d.ts.map +1 -1
  50. package/dist/tools/tool-outputs.d.ts +12 -2
  51. package/dist/tools/tool-outputs.d.ts.map +1 -1
  52. package/dist/tools/web-fetch/cache.d.ts +33 -0
  53. package/dist/tools/web-fetch/cache.d.ts.map +1 -0
  54. package/dist/tools/web-fetch/html-markdown.d.ts +25 -0
  55. package/dist/tools/web-fetch/html-markdown.d.ts.map +1 -0
  56. package/dist/tools/web-fetch/network.d.ts +55 -0
  57. package/dist/tools/web-fetch/network.d.ts.map +1 -0
  58. package/dist/tools/web-fetch/tool.d.ts +96 -0
  59. package/dist/tools/web-fetch/tool.d.ts.map +1 -0
  60. package/dist/tools/web-search.d.ts +40 -0
  61. package/dist/tools/web-search.d.ts.map +1 -0
  62. package/dist/types.d.ts +5 -4
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/workspace-instructions.d.ts +15 -0
  65. package/dist/workspace-instructions.d.ts.map +1 -0
  66. package/package.json +15 -5
  67. package/src/agent-prompt.ts +64 -5
  68. package/src/agent-runtime/preflight.ts +2 -1
  69. package/src/artifacts/board-previews.ts +218 -0
  70. package/src/artifacts/layout-check/check.cjs +304 -80
  71. package/src/artifacts/layout-check/layout-check.ts +123 -13
  72. package/src/artifacts/layout-check/overview.ts +291 -0
  73. package/src/artifacts/materialize.ts +181 -55
  74. package/src/artifacts/publish-tool.ts +459 -129
  75. package/src/background-commands.ts +573 -0
  76. package/src/background-notices.ts +178 -0
  77. package/src/computer-runner.ts +211 -9
  78. package/src/context-compaction.ts +4 -1
  79. package/src/execution-plan.ts +15 -2
  80. package/src/index.ts +4 -0
  81. package/src/login-shell.ts +18 -0
  82. package/src/run-child.ts +5 -0
  83. package/src/run-conversation-turn.ts +23 -4
  84. package/src/run-environment.ts +96 -17
  85. package/src/run-sandbox.ts +41 -0
  86. package/src/sandbox-api-context.ts +1 -1
  87. package/src/sandbox-files.ts +88 -1
  88. package/src/skills/sixb-artifacts/SKILL.md +48 -25
  89. package/src/skills/sixb-artifacts/canvas.md +140 -18
  90. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +1 -1
  91. package/src/skills/sixb-artifacts/page.md +1 -1
  92. package/src/skills/sixb-artifacts/references.md +15 -12
  93. package/src/skills/sixb-artifacts/sheet.md +1 -1
  94. package/src/skills/sixb-artifacts/slides.md +1 -1
  95. package/src/subagent-tools.ts +19 -7
  96. package/src/tools/background.ts +127 -0
  97. package/src/tools/bash.ts +80 -11
  98. package/src/tools/model-spec.ts +28 -5
  99. package/src/tools/tool-files.ts +3 -1
  100. package/src/tools/tool-outputs.ts +46 -6
  101. package/src/tools/web-fetch/cache.ts +91 -0
  102. package/src/tools/web-fetch/html-markdown.ts +479 -0
  103. package/src/tools/web-fetch/network.ts +452 -0
  104. package/src/tools/web-fetch/tool.ts +619 -0
  105. package/src/tools/web-search.ts +139 -0
  106. package/src/types.ts +5 -4
  107. package/src/workspace-instructions.ts +163 -0
@@ -0,0 +1,291 @@
1
+ import type { Canvas, CanvasEnd, CanvasItem } from "@sixb/core/artifacts"
2
+ import {
3
+ CANVAS_FIT_PADDING,
4
+ CANVAS_TEXT_PIXELS,
5
+ canvasArrowLine,
6
+ canvasNoteFontSize,
7
+ canvasShapeFontSize,
8
+ } from "@sixb/core/artifacts"
9
+
10
+ // The whole canvas as the app opens it, for the Agent to judge what reads at that zoom: fitted to
11
+ // everything in a laptop's window, with the boards as the check pictured them and every other item
12
+ // drawn at the app's sizes. It is an approximation: the app measures notes and texts once drawn,
13
+ // and these are reckoned from their words.
14
+
15
+ /** The window the canvas opens in: a laptop's. */
16
+ export const OVERVIEW_VIEWPORT = { width: 1440, height: 900 } as const
17
+
18
+ /** The canvas opens no closer than its actual size, and no further than this. */
19
+ const MAX_ZOOM = 1
20
+ const MIN_ZOOM = 0.04
21
+ /** An item's name shows above it from this zoom, at most this much larger, on so wide an item. */
22
+ const NAMES_FROM_ZOOM = 0.35
23
+ const MAX_NAME_SCALE = 2
24
+ const NAMED_FROM_WIDTH = 120
25
+
26
+ /** Colors a tone names that the frame's themes do not hold. */
27
+ const TONES: Readonly<Record<string, string>> = {
28
+ neutral: "var(--muted-foreground)",
29
+ positive: "#16a34a",
30
+ warning: "#f59e0b",
31
+ negative: "#dc2626",
32
+ }
33
+
34
+ interface Box {
35
+ readonly x: number
36
+ readonly y: number
37
+ readonly width: number
38
+ readonly height: number
39
+ }
40
+
41
+ /**
42
+ * The page the check screenshots as `overview.png`: the canvas fitted to the viewport as the
43
+ * app's opening fit does, in the theme's tokens, each board its picture at `image(id)`.
44
+ */
45
+ export function canvasOverviewHtml(input: {
46
+ readonly canvas: Canvas
47
+ readonly tokens: Readonly<Record<string, string>>
48
+ /** Where each board's picture is, relative to the page. */
49
+ readonly image: (boardId: string) => string
50
+ }): string {
51
+ const { canvas, tokens } = input
52
+ const boxes = new Map(
53
+ canvas.items.flatMap((item) => {
54
+ const box = itemBox(item)
55
+ return box ? [[item.id, box] as const] : []
56
+ })
57
+ )
58
+
59
+ const view = fitView([...boxes.values(), ...pointEnds(canvas)])
60
+ const nameScale =
61
+ view.zoom >= NAMES_FROM_ZOOM ? Math.min(MAX_NAME_SCALE, Math.max(1, 1 / view.zoom)) : null
62
+
63
+ // Sections behind everything, then the rest in the canvas's order, arrows over them all.
64
+ const items = [
65
+ ...canvas.items.filter((item) => item.type === "section"),
66
+ ...canvas.items.filter((item) => item.type !== "section" && item.type !== "arrow"),
67
+ ]
68
+ const drawn = items
69
+ .map((item) => drawItem(item, boxes.get(item.id), { ...input, zoom: view.zoom, nameScale }))
70
+ .join("\n")
71
+
72
+ const style = Object.entries(tokens)
73
+ .map(([name, value]) => `${name}: ${value};`)
74
+ .join(" ")
75
+
76
+ return `<!doctype html>
77
+ <html><head><meta charset="utf-8"><style>
78
+ :root { ${style} }
79
+ * { box-sizing: border-box; }
80
+ html, body { margin: 0; width: ${OVERVIEW_VIEWPORT.width}px; height: ${OVERVIEW_VIEWPORT.height}px; overflow: hidden; }
81
+ body { background: var(--background); color: var(--foreground); font-family: var(--font-sans, system-ui, sans-serif); }
82
+ .canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; transform: translate(${view.x}px, ${view.y}px) scale(${view.zoom}); }
83
+ .item { position: absolute; }
84
+ .surface { border-radius: 6px; background: var(--card); overflow: hidden; box-shadow: 0 0 0 1px color-mix(in oklab, var(--foreground) 9%, transparent), 0 1px 2px rgb(0 0 0 / 0.05), 0 20px 44px -28px rgb(0 0 0 / 0.35); }
85
+ .surface img { display: block; width: 100%; }
86
+ .name { position: absolute; left: 0; bottom: 100%; height: 28px; padding-bottom: 6px; display: flex; align-items: center; transform-origin: bottom left; font-size: 13px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
87
+ .heading { position: absolute; left: 0; top: 0; margin: 0; transform-origin: top left; font-size: 16px; line-height: 24px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
88
+ .note { border-radius: 4px; padding: 0.85em 1em; line-height: 1.4; font-weight: 500; white-space: pre-wrap; box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 10px 24px -14px rgb(0 0 0 / 0.28); }
89
+ .text { white-space: pre-wrap; }
90
+ .shape { display: flex; align-items: center; justify-content: center; }
91
+ .shape svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
92
+ .shape span { position: relative; text-align: center; line-height: 1.375; font-weight: 500; }
93
+ .arrows { position: absolute; left: 0; top: 0; overflow: visible; }
94
+ .label { position: absolute; transform: translate(-50%, -50%); border-radius: 999px; border: 1px solid var(--border); background: var(--background); padding: 2px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
95
+ </style></head>
96
+ <body><div class="canvas">
97
+ ${drawn}
98
+ ${drawArrows(canvas, boxes)}
99
+ </div></body></html>
100
+ `
101
+ }
102
+
103
+ /** Where the canvas sits in the window, as the app's fit puts it: centered, with its margin. */
104
+ function fitView(boxes: readonly Box[]): { x: number; y: number; zoom: number } {
105
+ const bounds = union(boxes)
106
+ const { width, height } = OVERVIEW_VIEWPORT
107
+ const zoom = clamp(
108
+ Math.min(
109
+ width / (bounds.width * (1 + CANVAS_FIT_PADDING)),
110
+ height / (bounds.height * (1 + CANVAS_FIT_PADDING))
111
+ ),
112
+ MIN_ZOOM,
113
+ MAX_ZOOM
114
+ )
115
+
116
+ return {
117
+ x: width / 2 - (bounds.x + bounds.width / 2) * zoom,
118
+ y: height / 2 - (bounds.y + bounds.height / 2) * zoom,
119
+ zoom,
120
+ }
121
+ }
122
+
123
+ /** An item's box before anything is measured: a note's height and a text's width are reckoned. */
124
+ function itemBox(item: CanvasItem): Box | null {
125
+ switch (item.type) {
126
+ case "arrow":
127
+ return null
128
+ case "text": {
129
+ const size = CANVAS_TEXT_PIXELS[item.size]
130
+ const width = item.w ?? Math.min(longestLine(item.text) * size * 0.55, 1600)
131
+ const lineHeight = size * (item.size === "s" || item.size === "m" ? 1.45 : 1.15)
132
+ return { x: item.x, y: item.y, width, height: lineHeight * lines(item.text, width, size) }
133
+ }
134
+ case "note": {
135
+ const size = canvasNoteFontSize(item.w)
136
+ const padding = size * 1.7
137
+ const written = size * 1.4 * lines(item.text, item.w - size * 2, size) + padding
138
+ const height = item.h ?? Math.max(Math.min(item.w, 112), written)
139
+ return { x: item.x, y: item.y, width: item.w, height }
140
+ }
141
+ default:
142
+ return { x: item.x, y: item.y, width: item.w, height: item.h }
143
+ }
144
+ }
145
+
146
+ /** The ends of arrows at a bare point, which the app's fit counts as one pixel there. */
147
+ function pointEnds(canvas: Canvas): Box[] {
148
+ return canvas.items.flatMap((item) =>
149
+ item.type === "arrow"
150
+ ? [item.from, item.to].flatMap((end) =>
151
+ typeof end === "string" ? [] : [{ x: end.x, y: end.y, width: 1, height: 1 }]
152
+ )
153
+ : []
154
+ )
155
+ }
156
+
157
+ function drawItem(
158
+ item: CanvasItem,
159
+ box: Box | undefined,
160
+ context: {
161
+ readonly image: (boardId: string) => string
162
+ readonly zoom: number
163
+ readonly nameScale: number | null
164
+ }
165
+ ): string {
166
+ if (!box) return ""
167
+ const place = `left: ${box.x}px; top: ${box.y}px; width: ${box.width}px; height: ${box.height}px;`
168
+ const named = (width: number) =>
169
+ context.nameScale !== null && width * context.zoom >= NAMED_FROM_WIDTH
170
+
171
+ switch (item.type) {
172
+ case "arrow":
173
+ return ""
174
+ case "board":
175
+ case "embed": {
176
+ const title = item.title ?? (item.type === "board" ? item.id : "")
177
+ const name =
178
+ title && named(box.width)
179
+ ? `<div class="name" style="width: ${box.width / (context.nameScale ?? 1)}px; transform: scale(${context.nameScale})">${escapeHtml(title)}</div>`
180
+ : ""
181
+ const inside =
182
+ item.type === "board"
183
+ ? `<img src="${escapeHtml(context.image(item.id))}" alt="">`
184
+ : `<div style="height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted-foreground); font-size: 14px">${escapeHtml(item.src)}</div>`
185
+ return `<div class="item" style="${place}">${name}<div class="surface" style="width: 100%; height: 100%">${inside}</div></div>`
186
+ }
187
+ case "section":
188
+ return item.title && context.nameScale !== null
189
+ ? `<div class="item" style="${place}"><h3 class="heading" style="max-width: ${box.width / context.nameScale}px; transform: scale(${context.nameScale})">${escapeHtml(item.title)}</h3></div>`
190
+ : ""
191
+ case "note": {
192
+ const tone = item.tone ?? "warning"
193
+ const background =
194
+ tone === "neutral"
195
+ ? "var(--card)"
196
+ : `color-mix(in oklab, ${toneColor(tone)} 20%, var(--card))`
197
+ return `<div class="item note" style="${place} font-size: ${canvasNoteFontSize(item.w)}px; background: ${background}">${escapeHtml(item.text)}</div>`
198
+ }
199
+ case "text": {
200
+ const weight = item.size === "xl" || item.size === "xxl" ? 700 : item.size === "l" ? 600 : 400
201
+ const color = item.size === "s" ? "var(--muted-foreground)" : "var(--foreground)"
202
+ const lineHeight = item.size === "s" || item.size === "m" ? 1.45 : 1.15
203
+ return `<div class="item text" style="${place} font-size: ${CANVAS_TEXT_PIXELS[item.size]}px; font-weight: ${weight}; line-height: ${lineHeight}; color: ${color}">${escapeHtml(item.text)}</div>`
204
+ }
205
+ case "shape": {
206
+ const fill = item.tone
207
+ ? `color-mix(in oklab, ${toneColor(item.tone)} 16%, var(--card))`
208
+ : "var(--card)"
209
+ const stroke = "color-mix(in oklab, var(--foreground) 32%, transparent)"
210
+ const paint = `style="fill: ${fill}; stroke: ${stroke}" stroke-width="1.5"`
211
+ const { w, h } = item
212
+ const outline =
213
+ item.shape === "ellipse"
214
+ ? `<ellipse cx="${w / 2}" cy="${h / 2}" rx="${w / 2}" ry="${h / 2}" ${paint}/>`
215
+ : item.shape === "diamond"
216
+ ? `<polygon points="${w / 2},0 ${w},${h / 2} ${w / 2},${h} 0,${h / 2}" ${paint} stroke-linejoin="round"/>`
217
+ : `<rect width="${w}" height="${h}" rx="10" ${paint}/>`
218
+ const words = item.text
219
+ ? `<span style="font-size: ${canvasShapeFontSize(w, h)}px; max-width: ${item.shape === "diamond" ? 60 : 80}%">${escapeHtml(item.text)}</span>`
220
+ : ""
221
+ return `<div class="item shape" style="${place}"><svg viewBox="0 0 ${w} ${h}">${outline}</svg>${words}</div>`
222
+ }
223
+ }
224
+ }
225
+
226
+ /** Each arrow from the edge of one item to the edge of the other, its label on its middle. */
227
+ function drawArrows(canvas: Canvas, boxes: ReadonlyMap<string, Box>): string {
228
+ const color = "color-mix(in oklab, var(--foreground) 62%, transparent)"
229
+ const endBox = (end: CanvasEnd): Box | undefined =>
230
+ typeof end === "string" ? boxes.get(end) : { x: end.x, y: end.y, width: 1, height: 1 }
231
+
232
+ const lines: string[] = []
233
+ const labels: string[] = []
234
+ for (const item of canvas.items) {
235
+ if (item.type !== "arrow") continue
236
+ const from = endBox(item.from)
237
+ const to = endBox(item.to)
238
+ if (!from || !to) continue
239
+
240
+ const { start, end } = canvasArrowLine(from, to)
241
+ lines.push(
242
+ `<line x1="${start.x}" y1="${start.y}" x2="${end.x}" y2="${end.y}" style="stroke: ${color}" stroke-width="2" stroke-linecap="round"${item.dashed ? ' stroke-dasharray="7 7"' : ""} marker-end="url(#head)"/>`
243
+ )
244
+ if (item.label) {
245
+ labels.push(
246
+ `<div class="label" style="left: ${(start.x + end.x) / 2}px; top: ${(start.y + end.y) / 2}px">${escapeHtml(item.label)}</div>`
247
+ )
248
+ }
249
+ }
250
+ if (lines.length === 0) return ""
251
+
252
+ return `<svg class="arrows" width="1" height="1"><defs><marker id="head" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" orient="auto-start-reverse"><path d="M 0 0 L 10 5 L 0 10 z" style="fill: ${color}"/></marker></defs>${lines.join("")}</svg>${labels.join("")}`
253
+ }
254
+
255
+ function union(boxes: readonly Box[]): Box {
256
+ if (boxes.length === 0) return { x: 0, y: 0, width: 1, height: 1 }
257
+
258
+ const left = Math.min(...boxes.map((box) => box.x))
259
+ const top = Math.min(...boxes.map((box) => box.y))
260
+ const right = Math.max(...boxes.map((box) => box.x + box.width))
261
+ const bottom = Math.max(...boxes.map((box) => box.y + box.height))
262
+ return { x: left, y: top, width: Math.max(1, right - left), height: Math.max(1, bottom - top) }
263
+ }
264
+
265
+ /** How many lines words take at a width, reckoned from an average letter's width. */
266
+ function lines(text: string, width: number, size: number): number {
267
+ const perLine = Math.max(1, Math.floor(width / (size * 0.55)))
268
+ return text
269
+ .split("\n")
270
+ .reduce((total, line) => total + Math.max(1, Math.ceil(line.length / perLine)), 0)
271
+ }
272
+
273
+ function longestLine(text: string): number {
274
+ return Math.max(...text.split("\n").map((line) => line.length))
275
+ }
276
+
277
+ function toneColor(tone: string): string {
278
+ return TONES[tone] ?? `var(--${tone})`
279
+ }
280
+
281
+ function clamp(value: number, min: number, max: number): number {
282
+ return Math.min(max, Math.max(min, value))
283
+ }
284
+
285
+ function escapeHtml(text: string): string {
286
+ return text
287
+ .replaceAll("&", "&amp;")
288
+ .replaceAll("<", "&lt;")
289
+ .replaceAll(">", "&gt;")
290
+ .replaceAll('"', "&quot;")
291
+ }