@sixb/agent 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/abort.d.ts +6 -0
- package/dist/abort.d.ts.map +1 -0
- package/dist/agent-prompt.d.ts +120 -0
- package/dist/agent-prompt.d.ts.map +1 -0
- package/dist/agent-runtime/errors.d.ts +13 -0
- package/dist/agent-runtime/errors.d.ts.map +1 -0
- package/dist/agent-runtime/preflight.d.ts +18 -0
- package/dist/agent-runtime/preflight.d.ts.map +1 -0
- package/dist/agent-runtime/profile.d.ts +14 -0
- package/dist/agent-runtime/profile.d.ts.map +1 -0
- package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
- package/dist/artifacts/materialize.d.ts +115 -0
- package/dist/artifacts/materialize.d.ts.map +1 -0
- package/dist/artifacts/publish-tool.d.ts +86 -0
- package/dist/artifacts/publish-tool.d.ts.map +1 -0
- package/dist/ask-parent-tool.d.ts +36 -0
- package/dist/ask-parent-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +68 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/child-files.d.ts +96 -0
- package/dist/child-files.d.ts.map +1 -0
- package/dist/child-questions.d.ts +24 -0
- package/dist/child-questions.d.ts.map +1 -0
- package/dist/computer-runner.d.ts +65 -0
- package/dist/computer-runner.d.ts.map +1 -0
- package/dist/context-budget.d.ts +28 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-compaction.d.ts +48 -0
- package/dist/context-compaction.d.ts.map +1 -0
- package/dist/conversation-memory.d.ts +21 -0
- package/dist/conversation-memory.d.ts.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/execution-plan.d.ts +34 -0
- package/dist/execution-plan.d.ts.map +1 -0
- package/dist/failure.d.ts +14 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/family-mailbox.d.ts +60 -0
- package/dist/family-mailbox.d.ts.map +1 -0
- package/dist/file-ref.d.ts +6 -0
- package/dist/file-ref.d.ts.map +1 -0
- package/dist/image-attachments.d.ts +34 -0
- package/dist/image-attachments.d.ts.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12168 -0
- package/dist/index.js.map +65 -0
- package/dist/message-authors.d.ts +34 -0
- package/dist/message-authors.d.ts.map +1 -0
- package/dist/message-times.d.ts +8 -0
- package/dist/message-times.d.ts.map +1 -0
- package/dist/model-adapters.d.ts +55 -0
- package/dist/model-adapters.d.ts.map +1 -0
- package/dist/model-lines.d.ts +16 -0
- package/dist/model-lines.d.ts.map +1 -0
- package/dist/requester.d.ts +15 -0
- package/dist/requester.d.ts.map +1 -0
- package/dist/run-agent-turn.d.ts +63 -0
- package/dist/run-agent-turn.d.ts.map +1 -0
- package/dist/run-child.d.ts +77 -0
- package/dist/run-child.d.ts.map +1 -0
- package/dist/run-conversation-turn.d.ts +42 -0
- package/dist/run-conversation-turn.d.ts.map +1 -0
- package/dist/run-credential.d.ts +22 -0
- package/dist/run-credential.d.ts.map +1 -0
- package/dist/run-environment.d.ts +115 -0
- package/dist/run-environment.d.ts.map +1 -0
- package/dist/run-fate.d.ts +15 -0
- package/dist/run-fate.d.ts.map +1 -0
- package/dist/run-sandbox.d.ts +60 -0
- package/dist/run-sandbox.d.ts.map +1 -0
- package/dist/run-subagent.d.ts +51 -0
- package/dist/run-subagent.d.ts.map +1 -0
- package/dist/run-workflow-agent-node.d.ts +41 -0
- package/dist/run-workflow-agent-node.d.ts.map +1 -0
- package/dist/sandbox-api-context.d.ts +34 -0
- package/dist/sandbox-api-context.d.ts.map +1 -0
- package/dist/sandbox-file-registry.d.ts +9 -0
- package/dist/sandbox-file-registry.d.ts.map +1 -0
- package/dist/sandbox-files.d.ts +71 -0
- package/dist/sandbox-files.d.ts.map +1 -0
- package/dist/sandbox-handle.d.ts +15 -0
- package/dist/sandbox-handle.d.ts.map +1 -0
- package/dist/sandbox-readiness.d.ts +8 -0
- package/dist/sandbox-readiness.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts +15 -0
- package/dist/skills/built-in.d.ts.map +1 -0
- package/dist/subagent-continuation.d.ts +27 -0
- package/dist/subagent-continuation.d.ts.map +1 -0
- package/dist/subagent-inbox.d.ts +53 -0
- package/dist/subagent-inbox.d.ts.map +1 -0
- package/dist/subagent-tools.d.ts +282 -0
- package/dist/subagent-tools.d.ts.map +1 -0
- package/dist/thread-context.d.ts +12 -0
- package/dist/thread-context.d.ts.map +1 -0
- package/dist/tools/attachments.d.ts +11 -0
- package/dist/tools/attachments.d.ts.map +1 -0
- package/dist/tools/bash.d.ts +60 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts +4 -0
- package/dist/tools/model-spec.d.ts.map +1 -0
- package/dist/tools/read.d.ts +43 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/result-media.d.ts +22 -0
- package/dist/tools/result-media.d.ts.map +1 -0
- package/dist/tools/result-output.d.ts +18 -0
- package/dist/tools/result-output.d.ts.map +1 -0
- package/dist/tools/tool-files.d.ts +59 -0
- package/dist/tools/tool-files.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +40 -0
- package/dist/tools/view-file.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/turn-runtime.d.ts +19 -0
- package/dist/turn-runtime.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow-input-attachments.d.ts +18 -0
- package/dist/workflow-input-attachments.d.ts.map +1 -0
- package/package.json +59 -4
- package/src/abort.ts +40 -0
- package/src/agent-prompt.ts +758 -0
- package/src/agent-runtime/errors.ts +44 -0
- package/src/agent-runtime/preflight.ts +314 -0
- package/src/agent-runtime/profile.ts +23 -0
- package/src/artifacts/layout-check/check.cjs +478 -0
- package/src/artifacts/layout-check/layout-check.ts +460 -0
- package/src/artifacts/materialize.ts +380 -0
- package/src/artifacts/publish-tool.ts +700 -0
- package/src/ask-parent-tool.ts +100 -0
- package/src/attachments.ts +850 -0
- package/src/child-files.ts +540 -0
- package/src/child-questions.ts +42 -0
- package/src/computer-runner.ts +284 -0
- package/src/context-budget.ts +161 -0
- package/src/context-compaction.ts +529 -0
- package/src/conversation-memory.ts +45 -0
- package/src/errors.ts +85 -0
- package/src/execution-plan.ts +50 -0
- package/src/failure.ts +71 -0
- package/src/family-mailbox.ts +189 -0
- package/src/file-ref.ts +18 -0
- package/src/image-attachments.ts +322 -0
- package/src/index.ts +54 -0
- package/src/message-authors.ts +77 -0
- package/src/message-times.ts +21 -0
- package/src/model-adapters.ts +227 -0
- package/src/model-lines.ts +28 -0
- package/src/requester.ts +21 -0
- package/src/run-agent-turn.ts +347 -0
- package/src/run-child.ts +319 -0
- package/src/run-conversation-turn.ts +257 -0
- package/src/run-credential.ts +55 -0
- package/src/run-environment.ts +769 -0
- package/src/run-fate.ts +51 -0
- package/src/run-sandbox.ts +63 -0
- package/src/run-subagent.ts +347 -0
- package/src/run-workflow-agent-node.ts +270 -0
- package/src/sandbox-api-context.ts +234 -0
- package/src/sandbox-file-registry.ts +26 -0
- package/src/sandbox-files.ts +326 -0
- package/src/sandbox-handle.ts +19 -0
- package/src/sandbox-readiness.ts +22 -0
- package/src/skills/built-in.ts +183 -0
- package/src/skills/sixb-artifacts/SKILL.md +95 -0
- package/src/skills/sixb-artifacts/canvas.md +104 -0
- package/src/skills/sixb-artifacts/document.md +63 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
- package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
- package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
- package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
- package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
- package/src/skills/sixb-artifacts/file.md +17 -0
- package/src/skills/sixb-artifacts/page.md +215 -0
- package/src/skills/sixb-artifacts/queries.md +66 -0
- package/src/skills/sixb-artifacts/references.md +68 -0
- package/src/skills/sixb-artifacts/sheet.md +223 -0
- package/src/skills/sixb-artifacts/slides.md +137 -0
- package/src/skills/sixb-memory/SKILL.md +68 -0
- package/src/skills/text-assets.d.ts +25 -0
- package/src/subagent-continuation.ts +51 -0
- package/src/subagent-inbox.ts +101 -0
- package/src/subagent-tools.ts +1609 -0
- package/src/thread-context.ts +25 -0
- package/src/tools/attachments.ts +28 -0
- package/src/tools/bash.ts +217 -0
- package/src/tools/model-spec.ts +22 -0
- package/src/tools/read.ts +262 -0
- package/src/tools/result-media.ts +147 -0
- package/src/tools/result-output.ts +44 -0
- package/src/tools/tool-files.ts +204 -0
- package/src/tools/view-file.ts +155 -0
- package/src/turn-runtime.ts +33 -0
- package/src/types.ts +79 -0
- package/src/workflow-input-attachments.ts +140 -0
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { posix } from "node:path"
|
|
2
|
+
import type { Sandbox } from "@sixb/core"
|
|
3
|
+
import type { ArtifactTheme } from "@sixb/core/artifacts"
|
|
4
|
+
import {
|
|
5
|
+
FRAME_ASSETS,
|
|
6
|
+
FRAME_DEFAULT_THEMES,
|
|
7
|
+
type FrameLayout,
|
|
8
|
+
injectFrameAssets,
|
|
9
|
+
type LayoutProblem,
|
|
10
|
+
layoutProbe,
|
|
11
|
+
rewriteFrameReferences,
|
|
12
|
+
} from "@sixb/core/internal/artifacts/frames"
|
|
13
|
+
import { type AgentSandboxHandle, contextPath } from "../../sandbox-handle"
|
|
14
|
+
import checkScript from "./check.cjs" with { type: "text" }
|
|
15
|
+
|
|
16
|
+
/** The check's library and each check's files, in the run's context directory. */
|
|
17
|
+
const LIBRARY = "lib/layout-check"
|
|
18
|
+
const CHECKS = "checks"
|
|
19
|
+
/** Chromium's start, a deck's fonts, and two passes over up to 100 slides, or a page at two widths. */
|
|
20
|
+
const CHECK_TIMEOUT_MS = 120_000
|
|
21
|
+
/**
|
|
22
|
+
* Sandboxes the check's library is written in. The context directory lasts the run, and each run
|
|
23
|
+
* has its own sandbox object, a lasting sandbox's included, so the library is written once per run.
|
|
24
|
+
*/
|
|
25
|
+
const installed = new WeakSet<Sandbox>()
|
|
26
|
+
|
|
27
|
+
/** What the layout check found, for the publish tool to report beside the version. */
|
|
28
|
+
export type LayoutCheck =
|
|
29
|
+
| {
|
|
30
|
+
readonly status: "checked"
|
|
31
|
+
readonly warnings: readonly LayoutWarning[]
|
|
32
|
+
/** One per slide, or a page's at each width, as the agent names them. */
|
|
33
|
+
readonly screenshots: readonly string[]
|
|
34
|
+
}
|
|
35
|
+
| { readonly status: "skipped"; readonly reason: string }
|
|
36
|
+
|
|
37
|
+
export interface LayoutWarning {
|
|
38
|
+
readonly code: string
|
|
39
|
+
readonly message: string
|
|
40
|
+
/** The slide's number, or the width a page was checked at: `desktop` or `phone`. */
|
|
41
|
+
readonly part?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** What the check lays out: a deck, a page, or a canvas's boards, each a page at its own size. */
|
|
45
|
+
export type CheckLayout = FrameLayout | "canvas"
|
|
46
|
+
|
|
47
|
+
/** A canvas's board, as the check opens it. */
|
|
48
|
+
export interface CheckedBoard {
|
|
49
|
+
readonly id: string
|
|
50
|
+
/** Its HTML file, relative to the version's directory. */
|
|
51
|
+
readonly file: string
|
|
52
|
+
readonly w: number
|
|
53
|
+
readonly h: number
|
|
54
|
+
readonly html: Uint8Array
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface CheckReport {
|
|
58
|
+
/** The layout the check laid the entry out in, which says it ran to the end of its setup. */
|
|
59
|
+
readonly layout?: CheckLayout
|
|
60
|
+
readonly slides?: number
|
|
61
|
+
readonly problems?: readonly CheckedProblem[]
|
|
62
|
+
readonly errors?: readonly string[]
|
|
63
|
+
readonly screenshots?: readonly string[]
|
|
64
|
+
/** Why the check stopped before it finished; what it found until then is above. */
|
|
65
|
+
readonly stopped?: string
|
|
66
|
+
readonly skipped?: string
|
|
67
|
+
readonly detail?: string
|
|
68
|
+
readonly failed?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* What a page's `sixb.query(name)` reads in the check: the query route's JSON as it answers the
|
|
73
|
+
* requester, or why the query failed for them.
|
|
74
|
+
*/
|
|
75
|
+
export type CheckedQuery = { readonly result: unknown } | { readonly error: string }
|
|
76
|
+
|
|
77
|
+
/** A width a page is checked at, as a laptop and a phone show it. */
|
|
78
|
+
export type PageView = "desktop" | "phone"
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Lays a published deck, page, or canvas out in the sandbox's headless Chromium, as the app's
|
|
82
|
+
* frame does, and reports what a reader would find wrong: on each slide of a deck, on a page at a
|
|
83
|
+
* laptop's width and a phone's, or on each of a canvas's boards at its own size, with a screenshot
|
|
84
|
+
* of each for the Agent to look at. A sandbox without the agent image's browser skips it; so does
|
|
85
|
+
* a check that fails, which never costs the Agent its publish.
|
|
86
|
+
*/
|
|
87
|
+
export async function checkLayout(
|
|
88
|
+
input: {
|
|
89
|
+
readonly handle: AgentSandboxHandle
|
|
90
|
+
/** The version's directory in the sandbox. */
|
|
91
|
+
readonly directory: string
|
|
92
|
+
/** The paths the version publishes, relative to the directory: the check serves no others. */
|
|
93
|
+
readonly files: readonly string[]
|
|
94
|
+
/** Names the check's directory, so each version's screenshots stay apart. */
|
|
95
|
+
readonly name: string
|
|
96
|
+
/** The version's `theme.json`, which the reader's frame applies over the app's theme. */
|
|
97
|
+
readonly theme?: ArtifactTheme
|
|
98
|
+
/** The version's queries by name, served where the runtime reads them opened on its own. */
|
|
99
|
+
readonly queries?: Readonly<Record<string, CheckedQuery>>
|
|
100
|
+
readonly signal: AbortSignal
|
|
101
|
+
/** Test seam; production allows 120 seconds. */
|
|
102
|
+
readonly timeoutMs?: number
|
|
103
|
+
} & (
|
|
104
|
+
| { readonly layout: FrameLayout; readonly entry: Uint8Array }
|
|
105
|
+
| { readonly layout: "canvas"; readonly boards: readonly CheckedBoard[] }
|
|
106
|
+
)
|
|
107
|
+
): Promise<LayoutCheck> {
|
|
108
|
+
const { sandbox } = input.handle
|
|
109
|
+
const timeoutMs = input.timeoutMs ?? CHECK_TIMEOUT_MS
|
|
110
|
+
const library = contextPath(input.handle, LIBRARY)
|
|
111
|
+
const output = contextPath(input.handle, CHECKS, input.name)
|
|
112
|
+
// Each page to open, with the kit and the runtime as its frame serves them. The sandbox has no
|
|
113
|
+
// way to the API: what the version shows from other artifacts is a placeholder, and what its
|
|
114
|
+
// queries return is read beforehand.
|
|
115
|
+
const pages =
|
|
116
|
+
input.layout === "canvas"
|
|
117
|
+
? input.boards.map((board) => ({
|
|
118
|
+
path: board.file,
|
|
119
|
+
layout: "page" as const,
|
|
120
|
+
html: board.html,
|
|
121
|
+
}))
|
|
122
|
+
: [{ path: "index.html", layout: input.layout, html: input.entry }]
|
|
123
|
+
const entries = pages.map((page) => ({
|
|
124
|
+
path: page.path,
|
|
125
|
+
contents: injectFrameAssets(
|
|
126
|
+
rewriteFrameReferences(new TextDecoder().decode(page.html), [], page.path),
|
|
127
|
+
page.layout,
|
|
128
|
+
page.path
|
|
129
|
+
),
|
|
130
|
+
}))
|
|
131
|
+
await sandbox.writeFiles([
|
|
132
|
+
...(installed.has(sandbox)
|
|
133
|
+
? []
|
|
134
|
+
: [
|
|
135
|
+
{ path: posix.join(library, "check.cjs"), contents: checkScript },
|
|
136
|
+
{ path: posix.join(library, "deck.css"), contents: asset("__sixb/deck.css") },
|
|
137
|
+
{ path: posix.join(library, "page.css"), contents: asset("__sixb/page.css") },
|
|
138
|
+
{ path: posix.join(library, "runtime.js"), contents: asset("__sixb/runtime.js") },
|
|
139
|
+
{ path: posix.join(library, "probe.js"), contents: `(${layoutProbe.toString()})` },
|
|
140
|
+
]),
|
|
141
|
+
...entries.map((entry) => ({
|
|
142
|
+
path: posix.join(output, "entries", entry.path),
|
|
143
|
+
contents: entry.contents,
|
|
144
|
+
})),
|
|
145
|
+
{
|
|
146
|
+
path: posix.join(output, "entries.json"),
|
|
147
|
+
contents: JSON.stringify(
|
|
148
|
+
Object.fromEntries(entries.map((entry) => [entry.path, posix.join("entries", entry.path)]))
|
|
149
|
+
),
|
|
150
|
+
},
|
|
151
|
+
...(input.layout === "canvas"
|
|
152
|
+
? [
|
|
153
|
+
{
|
|
154
|
+
path: posix.join(output, "boards.json"),
|
|
155
|
+
contents: JSON.stringify(
|
|
156
|
+
input.boards.map(({ id, file, w, h }) => ({ id, file, w, h }))
|
|
157
|
+
),
|
|
158
|
+
},
|
|
159
|
+
]
|
|
160
|
+
: []),
|
|
161
|
+
{ path: posix.join(output, "themes.json"), contents: JSON.stringify(deckThemes(input.theme)) },
|
|
162
|
+
{ path: posix.join(output, "files.json"), contents: JSON.stringify(input.files) },
|
|
163
|
+
...queryFiles(output, input.queries ?? {}),
|
|
164
|
+
])
|
|
165
|
+
installed.add(sandbox)
|
|
166
|
+
// The check stops itself first, so it reports what it found and closes its browser, which a
|
|
167
|
+
// node killed at the timeout leaves running.
|
|
168
|
+
const deadlineMs = Math.floor((timeoutMs * 5) / 6)
|
|
169
|
+
const result = await sandbox.runCommand(
|
|
170
|
+
"bash",
|
|
171
|
+
[
|
|
172
|
+
"-lc",
|
|
173
|
+
'command -v node >/dev/null 2>&1 || { echo \'{"skipped":"no_node"}\'; exit 0; }; exec node "$SIXB_CHECK/check.cjs" "$SIXB_CHECK_DECK" "$SIXB_CHECK_OUT" "$SIXB_CHECK" "$SIXB_CHECK_DEADLINE_MS" "$SIXB_CHECK_LAYOUT"',
|
|
174
|
+
],
|
|
175
|
+
{
|
|
176
|
+
env: {
|
|
177
|
+
...input.handle.env,
|
|
178
|
+
SIXB_CHECK: library,
|
|
179
|
+
SIXB_CHECK_DECK: input.directory,
|
|
180
|
+
SIXB_CHECK_OUT: output,
|
|
181
|
+
SIXB_CHECK_DEADLINE_MS: String(deadlineMs),
|
|
182
|
+
SIXB_CHECK_LAYOUT: input.layout,
|
|
183
|
+
},
|
|
184
|
+
timeout: timeoutMs,
|
|
185
|
+
signal: input.signal,
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
input.signal.throwIfAborted()
|
|
189
|
+
// A report counts however the command ended: a check that printed one and then hung on its way
|
|
190
|
+
// out still found what it found.
|
|
191
|
+
const report = parseReport(result.stdout)
|
|
192
|
+
if (report?.skipped) {
|
|
193
|
+
return {
|
|
194
|
+
status: "skipped",
|
|
195
|
+
reason:
|
|
196
|
+
report.skipped === "no_node"
|
|
197
|
+
? "the sandbox has no Node.js"
|
|
198
|
+
: "the sandbox has no headless browser (the agent image has one)",
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!report || report.failed || report.layout !== input.layout) {
|
|
202
|
+
if (result.timedOut) {
|
|
203
|
+
return { status: "skipped", reason: `it took longer than ${timeoutMs / 1000} seconds` }
|
|
204
|
+
}
|
|
205
|
+
const detail = report?.failed ?? result.stderr.trim()
|
|
206
|
+
console.warn(`[SixbAgent] The layout check failed: ${detail.slice(0, 500)}`)
|
|
207
|
+
return { status: "skipped", reason: "the check failed in the sandbox" }
|
|
208
|
+
}
|
|
209
|
+
const noun = { deck: "deck", page: "page", canvas: "canvas" }[input.layout]
|
|
210
|
+
const reached = { deck: "Slides", page: "Widths", canvas: "Boards" }[input.layout]
|
|
211
|
+
const checks = posix.join(input.handle.contextDirectory, CHECKS, input.name)
|
|
212
|
+
const screenshots = (report.screenshots ?? []).map((path) =>
|
|
213
|
+
posix.join(checks, posix.relative(output, path))
|
|
214
|
+
)
|
|
215
|
+
return {
|
|
216
|
+
status: "checked",
|
|
217
|
+
screenshots,
|
|
218
|
+
warnings: [
|
|
219
|
+
...layoutWarnings(report.problems ?? []),
|
|
220
|
+
...(report.errors ?? []).map((error) => ({
|
|
221
|
+
code: "layout_load_error",
|
|
222
|
+
message: `While the ${noun} loaded: ${error.slice(0, 200)}.`,
|
|
223
|
+
})),
|
|
224
|
+
...(report.stopped === undefined
|
|
225
|
+
? []
|
|
226
|
+
: [
|
|
227
|
+
{
|
|
228
|
+
code: "layout_incomplete",
|
|
229
|
+
message: `The check stopped early: ${report.stopped.slice(0, 200)}. ${reached} it did not reach were not checked.`,
|
|
230
|
+
},
|
|
231
|
+
]),
|
|
232
|
+
],
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Each query's answer as `queries/<name>.json`, and `queries.json`, the status each is served
|
|
238
|
+
* with: a failed query answers with its error, which the runtime rejects the page's promise with.
|
|
239
|
+
*/
|
|
240
|
+
function queryFiles(
|
|
241
|
+
output: string,
|
|
242
|
+
queries: Readonly<Record<string, CheckedQuery>>
|
|
243
|
+
): { path: string; contents: string }[] {
|
|
244
|
+
const entries = Object.entries(queries)
|
|
245
|
+
return [
|
|
246
|
+
...entries.map(([name, query]) => ({
|
|
247
|
+
path: posix.join(output, "queries", `${name}.json`),
|
|
248
|
+
contents: JSON.stringify("error" in query ? { error: query.error } : query.result),
|
|
249
|
+
})),
|
|
250
|
+
{
|
|
251
|
+
path: posix.join(output, "queries.json"),
|
|
252
|
+
contents: JSON.stringify(
|
|
253
|
+
Object.fromEntries(entries.map(([name, query]) => [name, "error" in query ? 409 : 200]))
|
|
254
|
+
),
|
|
255
|
+
},
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The themes a reader sees the deck in: Sixb's light and dark, or only the mode its `theme.json`
|
|
261
|
+
* pins, each with the deck's tokens over Sixb's.
|
|
262
|
+
*/
|
|
263
|
+
function deckThemes(theme: ArtifactTheme | undefined) {
|
|
264
|
+
const modes = theme?.mode ? [theme.mode] : (["light", "dark"] as const)
|
|
265
|
+
return Object.fromEntries(
|
|
266
|
+
modes.map((mode) => {
|
|
267
|
+
const base = FRAME_DEFAULT_THEMES[mode]
|
|
268
|
+
return [mode, { ...base, tokens: { ...base.tokens, ...theme?.tokens } }]
|
|
269
|
+
})
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function asset(path: string): string {
|
|
274
|
+
const file = FRAME_ASSETS[path]
|
|
275
|
+
if (!file) throw new Error(`[SixbAgent] The frame has no '${path}'.`)
|
|
276
|
+
return file.body
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function parseReport(stdout: string): CheckReport | null {
|
|
280
|
+
const line = stdout.trim().split("\n").at(-1)
|
|
281
|
+
if (!line) return null
|
|
282
|
+
try {
|
|
283
|
+
const value: unknown = JSON.parse(line)
|
|
284
|
+
return typeof value === "object" && value !== null ? (value as CheckReport) : null
|
|
285
|
+
} catch {
|
|
286
|
+
return null
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The most a check reports; the screenshots show the rest. */
|
|
291
|
+
const MAX_WARNINGS = 12
|
|
292
|
+
const SEVERITY: readonly LayoutProblem["code"][] = [
|
|
293
|
+
"broken_image",
|
|
294
|
+
"outside",
|
|
295
|
+
"wide",
|
|
296
|
+
"footer",
|
|
297
|
+
"overlap",
|
|
298
|
+
"clipped",
|
|
299
|
+
"contrast",
|
|
300
|
+
"small_target",
|
|
301
|
+
"small_text",
|
|
302
|
+
]
|
|
303
|
+
const VIEWS: readonly PageView[] = ["desktop", "phone"]
|
|
304
|
+
|
|
305
|
+
/** A problem where the check found it: on a deck's slide, or on a page at one width. */
|
|
306
|
+
type CheckedProblem = LayoutProblem & {
|
|
307
|
+
readonly theme: "light" | "dark"
|
|
308
|
+
readonly slide?: number
|
|
309
|
+
readonly view?: PageView
|
|
310
|
+
/** The canvas's board it is on. */
|
|
311
|
+
readonly board?: string
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The problems as warnings, worst first. A layout break is one warning per element; small text,
|
|
316
|
+
* a small control, and low contrast with one cause, the same element at the same size or in the
|
|
317
|
+
* same colors, is one warning naming every slide or width it is at, so a deck's eyebrow at 17px
|
|
318
|
+
* is one line, not nine. Contrast says which theme it fails in when it fails in one.
|
|
319
|
+
*/
|
|
320
|
+
export function layoutWarnings(problems: readonly CheckedProblem[]): LayoutWarning[] {
|
|
321
|
+
const groups = new Map<
|
|
322
|
+
string,
|
|
323
|
+
{
|
|
324
|
+
problem: CheckedProblem
|
|
325
|
+
slides: Set<number>
|
|
326
|
+
views: Set<PageView>
|
|
327
|
+
boards: Set<string>
|
|
328
|
+
texts: Set<string>
|
|
329
|
+
themes: Set<string>
|
|
330
|
+
}
|
|
331
|
+
>()
|
|
332
|
+
for (const problem of problems) {
|
|
333
|
+
const at = problem.slide ?? problem.view ?? problem.board
|
|
334
|
+
const cause =
|
|
335
|
+
problem.code === "small_text" || problem.code === "small_target"
|
|
336
|
+
? `${problem.selector}|${problem.size}`
|
|
337
|
+
: problem.code === "contrast"
|
|
338
|
+
? `${problem.selector}|${problem.colors?.join("|")}`
|
|
339
|
+
: `${at}|${problem.selector}|${problem.text}|${problem.rect.x},${problem.rect.y}`
|
|
340
|
+
const key = `${problem.code}|${cause}`
|
|
341
|
+
const group = groups.get(key) ?? {
|
|
342
|
+
problem,
|
|
343
|
+
slides: new Set(),
|
|
344
|
+
views: new Set(),
|
|
345
|
+
boards: new Set(),
|
|
346
|
+
texts: new Set(),
|
|
347
|
+
themes: new Set(),
|
|
348
|
+
}
|
|
349
|
+
if (problem.slide !== undefined) group.slides.add(problem.slide)
|
|
350
|
+
if (problem.view) group.views.add(problem.view)
|
|
351
|
+
if (problem.board) group.boards.add(problem.board)
|
|
352
|
+
group.texts.add(problem.text)
|
|
353
|
+
group.themes.add(problem.theme)
|
|
354
|
+
groups.set(key, group)
|
|
355
|
+
}
|
|
356
|
+
// Boards in the order the check met them, as the canvas lists them.
|
|
357
|
+
const boardOrder = [
|
|
358
|
+
...new Set(problems.flatMap((problem) => (problem.board ? [problem.board] : []))),
|
|
359
|
+
]
|
|
360
|
+
const first = (group: { slides: Set<number>; views: Set<PageView>; boards: Set<string> }) =>
|
|
361
|
+
group.slides.size > 0
|
|
362
|
+
? Math.min(...group.slides)
|
|
363
|
+
: group.boards.size > 0
|
|
364
|
+
? Math.min(...[...group.boards].map((board) => boardOrder.indexOf(board)))
|
|
365
|
+
: Math.min(...[...group.views].map((view) => VIEWS.indexOf(view)))
|
|
366
|
+
const ordered = [...groups.values()].sort(
|
|
367
|
+
(a, b) =>
|
|
368
|
+
SEVERITY.indexOf(a.problem.code) - SEVERITY.indexOf(b.problem.code) || first(a) - first(b)
|
|
369
|
+
)
|
|
370
|
+
const warnings: LayoutWarning[] = ordered
|
|
371
|
+
.slice(0, MAX_WARNINGS)
|
|
372
|
+
.map(({ problem, slides, views, boards, texts, themes }) => {
|
|
373
|
+
const theme =
|
|
374
|
+
problem.code === "contrast" && themes.size === 1 ? ` in ${[...themes][0]} mode` : ""
|
|
375
|
+
const page = slides.size === 0
|
|
376
|
+
const onBoards = boardOrder.filter((board) => boards.has(board))
|
|
377
|
+
const where =
|
|
378
|
+
onBoards.length > 0
|
|
379
|
+
? boardList(onBoards)
|
|
380
|
+
: page
|
|
381
|
+
? viewList([...views])
|
|
382
|
+
: slideList([...slides])
|
|
383
|
+
return {
|
|
384
|
+
code: `layout_${problem.code}`,
|
|
385
|
+
part:
|
|
386
|
+
onBoards[0] ??
|
|
387
|
+
(page
|
|
388
|
+
? (VIEWS.find((view) => views.has(view)) ?? "desktop")
|
|
389
|
+
: String(Math.min(...slides))),
|
|
390
|
+
message: `${where}: ${describeProblem(problem, [...texts], page)}${theme}.`,
|
|
391
|
+
}
|
|
392
|
+
})
|
|
393
|
+
const more = ordered.length - warnings.length
|
|
394
|
+
if (more > 0) {
|
|
395
|
+
warnings.push({
|
|
396
|
+
code: "layout_more",
|
|
397
|
+
message: `${more} more layout problem${more === 1 ? "" : "s"}; the screenshots show them.`,
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
return warnings
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** `Board 'region'`, `Boards 'welcome' and 'region'`. */
|
|
404
|
+
function boardList(boards: readonly string[]): string {
|
|
405
|
+
const named = boards.map((board) => `'${board}'`)
|
|
406
|
+
if (named.length === 1) return `Board ${named[0]}`
|
|
407
|
+
return `Boards ${named.slice(0, -1).join(", ")} and ${named.at(-1)}`
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** `Slide 3`, `Slides 1–4 and 7`. */
|
|
411
|
+
function slideList(slides: number[]): string {
|
|
412
|
+
const sorted = [...slides].sort((a, b) => a - b)
|
|
413
|
+
const runs: string[] = []
|
|
414
|
+
for (let index = 0; index < sorted.length; ) {
|
|
415
|
+
let end = index
|
|
416
|
+
while (end + 1 < sorted.length && sorted[end + 1] === (sorted[end] ?? 0) + 1) end++
|
|
417
|
+
runs.push(end > index ? `${sorted[index]}–${sorted[end]}` : String(sorted[index]))
|
|
418
|
+
index = end + 1
|
|
419
|
+
}
|
|
420
|
+
const label = runs.length > 1 ? `${runs.slice(0, -1).join(", ")} and ${runs.at(-1)}` : runs[0]
|
|
421
|
+
return `${sorted.length === 1 ? "Slide" : "Slides"} ${label}`
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** `On a phone (390px)`, `At 1280px and on a phone`. */
|
|
425
|
+
function viewList(views: PageView[]): string {
|
|
426
|
+
if (views.length > 1) return "At 1280px and on a phone (390px)"
|
|
427
|
+
return views[0] === "phone" ? "On a phone (390px)" : "At 1280px"
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function describeProblem(problem: LayoutProblem, texts: readonly string[], page: boolean): string {
|
|
431
|
+
const { x, y, width, height } = problem.rect
|
|
432
|
+
const where = `at ${x},${y} (${width}×${height})`
|
|
433
|
+
const quoted = texts
|
|
434
|
+
.slice(0, 2)
|
|
435
|
+
.map((text) => `“${text}”`)
|
|
436
|
+
.join(", ")
|
|
437
|
+
const what = `${problem.selector} ${quoted}${texts.length > 2 ? ` and ${texts.length - 2} more` : ""}`
|
|
438
|
+
switch (problem.code) {
|
|
439
|
+
case "outside":
|
|
440
|
+
return `${what} runs past the slide's edge ${where}, which cuts it off`
|
|
441
|
+
case "footer":
|
|
442
|
+
return `${what} runs into the footer ${where}; keep content above the source line`
|
|
443
|
+
case "wide":
|
|
444
|
+
return `${what} runs past the screen's right edge ${where}, so the whole page scrolls sideways; let it wrap or shrink, or put it in a box that scrolls (.table-scroll)`
|
|
445
|
+
case "overlap":
|
|
446
|
+
return `${what} is drawn over “${problem.other}” ${where}`
|
|
447
|
+
case "clipped":
|
|
448
|
+
return `${what} is cut off by its own box ${where}`
|
|
449
|
+
case "small_text":
|
|
450
|
+
return page
|
|
451
|
+
? `${what} ${texts.length === 1 ? "is" : "are"} ${problem.size}px; nothing on a page may be under 12px`
|
|
452
|
+
: `${what} ${texts.length === 1 ? "is" : "are"} ${problem.size}px; nothing on a slide may be under 18px`
|
|
453
|
+
case "small_target":
|
|
454
|
+
return `${what} ${texts.length === 1 ? "is" : "are"} ${problem.size}px across; make each control at least 24px each way`
|
|
455
|
+
case "contrast":
|
|
456
|
+
return `${what} ${texts.length === 1 ? "has" : "have"} a contrast of ${problem.ratio}:1 (${problem.colors?.join(" on ")}), under WCAG AA`
|
|
457
|
+
case "broken_image":
|
|
458
|
+
return `the image ${quoted} did not load ${where}`
|
|
459
|
+
}
|
|
460
|
+
}
|