@sixb/agent 0.2.4 → 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 (90) hide show
  1. package/README.md +2 -2
  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.map +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +10590 -8888
  9. package/dist/index.js.map +30 -26
  10. package/dist/run-agent-turn.d.ts +3 -14
  11. package/dist/run-agent-turn.d.ts.map +1 -1
  12. package/dist/run-environment.d.ts.map +1 -1
  13. package/dist/run-subagent.d.ts.map +1 -1
  14. package/dist/sandbox-api-context.d.ts.map +1 -1
  15. package/dist/search-script.d.ts +7 -0
  16. package/dist/search-script.d.ts.map +1 -0
  17. package/dist/skills/built-in.d.ts.map +1 -1
  18. package/dist/tools/glob.d.ts +41 -0
  19. package/dist/tools/glob.d.ts.map +1 -0
  20. package/dist/tools/grep.d.ts +64 -0
  21. package/dist/tools/grep.d.ts.map +1 -0
  22. package/dist/tools/model-spec.d.ts.map +1 -1
  23. package/dist/tools/sandbox-search.d.ts +26 -0
  24. package/dist/tools/sandbox-search.d.ts.map +1 -0
  25. package/dist/tools/search/command.d.ts +15 -0
  26. package/dist/tools/search/command.d.ts.map +1 -0
  27. package/dist/tools/search/gitignore.d.ts +28 -0
  28. package/dist/tools/search/gitignore.d.ts.map +1 -0
  29. package/dist/tools/search/glob.d.ts +15 -0
  30. package/dist/tools/search/glob.d.ts.map +1 -0
  31. package/dist/tools/search/main.d.ts +2 -0
  32. package/dist/tools/search/main.d.ts.map +1 -0
  33. package/dist/tools/search/match.d.ts +30 -0
  34. package/dist/tools/search/match.d.ts.map +1 -0
  35. package/dist/tools/search/pattern.d.ts +19 -0
  36. package/dist/tools/search/pattern.d.ts.map +1 -0
  37. package/dist/tools/search/read.d.ts +62 -0
  38. package/dist/tools/search/read.d.ts.map +1 -0
  39. package/dist/tools/search/request.d.ts +80 -0
  40. package/dist/tools/search/request.d.ts.map +1 -0
  41. package/dist/tools/search/search.d.ts +4 -0
  42. package/dist/tools/search/search.d.ts.map +1 -0
  43. package/dist/tools/search/walk.d.ts +43 -0
  44. package/dist/tools/search/walk.d.ts.map +1 -0
  45. package/dist/tools/tool-outputs.d.ts.map +1 -1
  46. package/dist/turn-inbox.d.ts +75 -0
  47. package/dist/turn-inbox.d.ts.map +1 -0
  48. package/package.json +6 -4
  49. package/src/agent-prompt.ts +1 -0
  50. package/src/agent-runtime/preflight.ts +1 -0
  51. package/src/artifacts/layout-check/check.cjs +176 -95
  52. package/src/artifacts/layout-check/layout-check.ts +118 -76
  53. package/src/artifacts/publish-tool.ts +48 -99
  54. package/src/generated/search.mjs +985 -0
  55. package/src/index.ts +0 -1
  56. package/src/run-agent-turn.ts +85 -129
  57. package/src/run-conversation-turn.ts +4 -4
  58. package/src/run-environment.ts +4 -0
  59. package/src/run-subagent.ts +1 -1
  60. package/src/sandbox-api-context.ts +3 -0
  61. package/src/search-script-assets.d.ts +5 -0
  62. package/src/search-script.ts +9 -0
  63. package/src/skills/built-in.ts +16 -0
  64. package/src/skills/sixb-artifacts/SKILL.md +7 -7
  65. package/src/skills/sixb-artifacts/canvas.md +3 -2
  66. package/src/skills/sixb-artifacts/document.md +92 -5
  67. package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
  68. package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
  69. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
  70. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
  71. package/src/skills/sixb-artifacts/queries.md +2 -1
  72. package/src/tools/glob.ts +124 -0
  73. package/src/tools/grep.ts +190 -0
  74. package/src/tools/model-spec.ts +4 -0
  75. package/src/tools/sandbox-search.ts +219 -0
  76. package/src/tools/search/command.ts +116 -0
  77. package/src/tools/search/gitignore.ts +101 -0
  78. package/src/tools/search/glob.ts +90 -0
  79. package/src/tools/search/main.ts +9 -0
  80. package/src/tools/search/match.ts +278 -0
  81. package/src/tools/search/pattern.ts +178 -0
  82. package/src/tools/search/read.ts +237 -0
  83. package/src/tools/search/request.ts +101 -0
  84. package/src/tools/search/search.ts +297 -0
  85. package/src/tools/search/walk.ts +145 -0
  86. package/src/tools/tool-outputs.ts +7 -2
  87. package/src/turn-inbox.ts +283 -0
  88. package/dist/artifacts/board-previews.d.ts +0 -41
  89. package/dist/artifacts/board-previews.d.ts.map +0 -1
  90. package/src/artifacts/board-previews.ts +0 -218
@@ -1 +1 @@
1
- {"version":3,"file":"tool-outputs.d.ts","sourceRoot":"","sources":["../../src/tools/tool-outputs.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAI9B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,yBAAyB,EAE/B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,OAAO,EAAE,KAAK,kBAAkB,EAAe,MAAM,mBAAmB,CAAA;AAGxE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAI9C;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAAY,CAAA;AAEnD,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,iBAA+B,CAAA;AASlE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAmB,CAAA;AAmCtD;;;;;;GAMG;AACH,qBAAa,eAAe;;IAKxB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE;QACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAA;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eJ,KAAK;CAkCpB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GAAG,iBAAiB,EAAE,CAejG;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAC5C,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IACrD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,IAAI,CAAC,CAiChB;AAoCD,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpE"}
@@ -0,0 +1,75 @@
1
+ import type { AgentMessagePart, AgentStepRequestSize } from "@sixb/core";
2
+ import { type AgentRunSession, type PausableModelLoopResult } from "@sixb/core/internal/agents";
3
+ import type { ModelAssistantPart, ModelMessage, ModelStep } from "@sixb/core/models";
4
+ import type { AgentInboxItemRecord, AgentMessageRecord, AppendAgentMessageInput, ConversationAgentRunRecord, Principal } from "@sixb/core/storage";
5
+ import { type SentSettings } from "./agent-prompt";
6
+ import { type ConversationReaders } from "./message-authors";
7
+ import { type AgentToolOutputFileOf } from "./model-adapters";
8
+ /** A steer the turn read at one of its step boundaries: which step, and what it read. */
9
+ export interface TurnInboxDelivery {
10
+ /** The step the messages came after: its own count of the steps the turn completed. */
11
+ readonly afterSteps: number;
12
+ readonly items: readonly AgentInboxItemRecord[];
13
+ }
14
+ /** What a steer's message is projected from: the thread as the turn started, and who reads it. */
15
+ interface TurnInboxContext {
16
+ readonly retainedMessages: readonly AgentMessageRecord[];
17
+ readonly conversation?: ConversationReaders;
18
+ readonly project: SentSettings;
19
+ }
20
+ /**
21
+ * A turn's mid-run steers, drained from its session's inbox at step boundaries.
22
+ *
23
+ * Every item a turn reads is claimed by its run and its step, so a step that reads twice reads
24
+ * once, and a turn that never writes one releases it (see AgentRunSession.finish). The messages
25
+ * here are what the model read: its history plus the steer, projected the way the next turn's
26
+ * replay of `agent_messages` projects it, so both send the same bytes.
27
+ */
28
+ export declare class TurnInbox {
29
+ #private;
30
+ private readonly session;
31
+ constructor(session: AgentRunSession, context: TurnInboxContext);
32
+ /** What the turn read, in order. */
33
+ get deliveries(): readonly TurnInboxDelivery[];
34
+ /**
35
+ * The messages the model reads after `afterSteps` steps; none when nothing waits. `afterAnswer`
36
+ * marks a read that came as the model answered, which the next request follows with one more
37
+ * step.
38
+ */
39
+ take(afterSteps: number, options?: {
40
+ readonly afterAnswer?: boolean;
41
+ }): Promise<readonly ModelMessage[]>;
42
+ }
43
+ /**
44
+ * Slice the steps a turn completed, or the part of one it did not, around the steers it read, as
45
+ * `agent_messages` rows: one assistant message up to each delivery, the steer as its own user
46
+ * message, then the rest. A steer no step followed — the turn stopped before answering it — is
47
+ * left out, so finishing without its message releases it back to the thread's inbox.
48
+ */
49
+ export declare function turnWorkMessages(input: {
50
+ readonly steps: readonly ModelStep[];
51
+ /** What an aborted step streamed: the one step `steps` does not hold whole. */
52
+ readonly partialContent?: readonly ModelAssistantPart[];
53
+ readonly aborted?: boolean;
54
+ readonly run: ConversationAgentRunRecord;
55
+ readonly deliveries: readonly TurnInboxDelivery[];
56
+ /** The first step whose request the context guard reduced: it and those after it are marked. */
57
+ readonly reducedFromStep?: number;
58
+ readonly stepRequests: readonly (AgentStepRequestSize | undefined)[];
59
+ readonly outputFileOf?: AgentToolOutputFileOf;
60
+ readonly authorPrincipal?: Principal;
61
+ }): readonly AppendAgentMessageInput[];
62
+ /** The rows a turn finishes with, for the model loop it just ran. */
63
+ export declare function turnResultMessages(result: PausableModelLoopResult, input: Omit<Parameters<typeof turnWorkMessages>[0], "steps" | "partialContent" | "aborted">): readonly AppendAgentMessageInput[];
64
+ /**
65
+ * Mark each step from `fromStep` on as answering a request the turn reduced, for the next turn's
66
+ * estimate not to go by what those calls read.
67
+ */
68
+ export declare function markReducedSteps(parts: readonly AgentMessagePart[], fromStep: number | undefined): readonly AgentMessagePart[];
69
+ /**
70
+ * Record on each step-start what its request carried, by step: the next turn's context meter
71
+ * reads the system prompt and tools the latest one sent.
72
+ */
73
+ export declare function recordStepRequests(parts: readonly AgentMessagePart[], requests: readonly (AgentStepRequestSize | undefined)[]): readonly AgentMessagePart[];
74
+ export {};
75
+ //# sourceMappingURL=turn-inbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-inbox.d.ts","sourceRoot":"","sources":["../src/turn-inbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,uBAAuB,EAE7B,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,SAAS,EACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,KAAK,mBAAmB,EAAuB,MAAM,mBAAmB,CAAA;AACjF,OAAO,EACL,KAAK,qBAAqB,EAG3B,MAAM,kBAAkB,CAAA;AAEzB,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAChC,uFAAuF;IACvF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,oBAAoB,EAAE,CAAA;CAChD;AAED,kGAAkG;AAClG,UAAU,gBAAgB;IACxB,QAAQ,CAAC,gBAAgB,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACxD,QAAQ,CAA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,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAAC,GAC1F,SAAS,uBAAuB,EAAE,CASpC;AA2BD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAClC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,SAAS,gBAAgB,EAAE,CAU7B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAClC,QAAQ,EAAE,SAAS,CAAC,oBAAoB,GAAG,SAAS,CAAC,EAAE,GACtD,SAAS,gBAAgB,EAAE,CAS7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/agent",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "The Sixb agent harness: one loop, prompt and tools for every runner",
5
5
  "keywords": [
6
6
  "sixb",
@@ -29,18 +29,20 @@
29
29
  },
30
30
  "scripts": {
31
31
  "build": "bun ../../scripts/build-package.ts",
32
+ "generate:search-script": "bun ./scripts/generate-search-script.ts",
33
+ "check:search-script": "bun ./scripts/generate-search-script.ts --check",
32
34
  "typecheck": "tsc --noEmit",
33
35
  "test": "bun test",
34
36
  "test:e2e": "bun ../../scripts/ci-guard.ts --stall 120 --max 300 bun test ./tests/layout-check.e2e.ts",
35
37
  "prepack": "bun run build"
36
38
  },
37
39
  "peerDependencies": {
38
- "@sixb/core": "0.2.4"
40
+ "@sixb/core": "0.2.5"
39
41
  },
40
42
  "devDependencies": {
41
- "@sixb/core": "0.2.4",
43
+ "@sixb/core": "0.2.5",
42
44
  "@sixb/sandboxes-local": "0.2.0",
43
- "@sixb/vercel-ai-gateway": "0.2.4",
45
+ "@sixb/vercel-ai-gateway": "0.2.5",
44
46
  "@types/bun": "latest",
45
47
  "@types/hast": "^3.0.5",
46
48
  "@types/mdast": "^4.0.4",
@@ -401,6 +401,7 @@ function renderRuntimeContext(
401
401
  ...renderModelCommands(sandboxModels),
402
402
  ...fileContext,
403
403
  "With read, use relative paths from this prompt or sandboxPath values.",
404
+ "Find files with glob and text with grep before you read them. Read a file before you change it, and change files with edit and write rather than shell commands; a memory save stays one bash command that edits and saves.",
404
405
  ]
405
406
  return { base, skills: skillCatalog, ontology: ontologyCatalog }
406
407
  }
@@ -269,6 +269,7 @@ const LOCAL_BEHAVIOR_PROBE = `set -u
269
269
  [ "$(command -v sixb)" = "$SIXB_BIN_DIR/sixb" ] || exit 21
270
270
  [ -x "$SIXB_BIN_DIR/sixb" ] || exit 22
271
271
  [ -r "$SIXB_CONTEXT_DIR/lib/sixb.mjs" ] || exit 22
272
+ [ -r "$SIXB_CONTEXT_DIR/lib/search.mjs" ] || exit 22
272
273
  realpath_bin="$(command -v realpath)" || exit 23
273
274
  tail_bin="$(command -v tail)" || exit 23
274
275
  head_bin="$(command -v head)" || exit 23
@@ -4,19 +4,22 @@
4
4
  // slide is measured in each of its themes with the layout probe and screenshot in the first. A page
5
5
  // loads at 1280px and at a phone's 390px, is measured whole in each theme, its top 4000px, and
6
6
  // screenshot at each width. A canvas's boards load each at its own size, four at a time, measured
7
- // as a page is and screenshot as boards/<id>.png; a board boards.json marks `pictured` also in
8
- // each other theme, as boards/<id>.<theme>.png, and each of its pictures for readers also at most
9
- // `smallWidth` wide, as boards/<id>.<theme>.small.webp; a board whose page did not load whole is
10
- // not pictured, but listed in `unpictured`, as a broken picture would stay. With overview.html, the
11
- // whole canvas as it opens is screenshot as overview.png. It writes one line of JSON:
12
- // { layout, slides, problems, errors, screenshots, previews, unpictured, oversized, stalls,
13
- // overview?, stopped? } or
7
+ // in each theme as a page is and screenshot in the first as boards/<id>.png; the pictures readers
8
+ // see are the render worker's to take. With overview.html, the whole canvas as it opens is
9
+ // screenshot as overview.png. A designed document loads as one sheet
10
+ // at its paper's width, and is measured whole, as a page is, but not for what only a screen has,
11
+ // small text and small controls; without paper, that sheet is screenshot as document.png. It is
12
+ // measured the same way at a phone's 390px, as the app shows it there, and screenshot as
13
+ // phone.png. With paper, it is then cut into its pages, each checked for what runs past its edge,
14
+ // and screenshot as page-NN.png. It writes one line of JSON:
15
+ // { layout, slides, pages?, problems, errors, screenshots, oversized, stalls, overview?, stopped? }
16
+ // or
14
17
  // { skipped }.
15
18
  //
16
19
  // node check.cjs <directory> <output directory> <library directory> <deadline in ms> <layout>
17
20
  //
18
- // The library holds what the worker installs beside this script: deck.css, page.css, runtime.js,
19
- // probe.js. The output directory holds entries.json, each page the check opens by its path, with
21
+ // The library holds what the worker installs beside this script: deck.css, page.css,
22
+ // document.css, runtime.js, probe.js. The output directory holds entries.json, each page the check opens by its path, with
20
23
  // the kit and runtime in it; boards.json, a canvas's boards and their sizes; overview.html and
21
24
  // overview.json, a canvas's page of itself and the window it opens in; files.json,
22
25
  // the paths the version publishes: only those are served, since the reader gets only those; and
@@ -42,16 +45,25 @@ const DEADLINE_MS = Number(deadline) || 100_000
42
45
  const STEP_MS = 10_000
43
46
  const PROTOCOL = "sixb-frame/1"
44
47
  /** The frame's own files, served from the library as the API serves them beside a version's. */
45
- const FRAME_FILES = new Set(["/__sixb/deck.css", "/__sixb/page.css", "/__sixb/runtime.js"])
48
+ const FRAME_FILES = new Set([
49
+ "/__sixb/deck.css",
50
+ "/__sixb/page.css",
51
+ "/__sixb/document.css",
52
+ "/__sixb/runtime.js",
53
+ ])
46
54
  /** Where the runtime reads a query when it is opened on its own. */
47
55
  const QUERY_PATH = /^\/__sixb\/queries\/([a-z0-9][a-z0-9-]{0,63})\.json$/
56
+ /** A phone's screen, where pages and designed documents are checked too. */
57
+ const PHONE = { name: "phone", width: 390, height: 844 }
48
58
  /** The widths a page is checked at: a laptop's, and a phone's. */
49
- const VIEWS = [
50
- { name: "desktop", width: 1280, height: 800 },
51
- { name: "phone", width: 390, height: 844 },
52
- ]
59
+ const VIEWS = [{ name: "desktop", width: 1280, height: 800 }, PHONE]
53
60
  /** How much of a page the check measures and shows, from its top. */
54
61
  const PAGE_HEIGHT = 4000
62
+ /** How much of a designed document the check measures as one sheet, and how many pages it shoots. */
63
+ const DOCUMENT_HEIGHT = 16_000
64
+ const MAX_PAGES = 40
65
+ /** What the probe judges of a screen, which paper does not have. */
66
+ const SCREEN_ONLY = new Set(["small_text", "small_target"])
55
67
  const TYPES = {
56
68
  ".html": "text/html; charset=utf-8",
57
69
  ".css": "text/css; charset=utf-8",
@@ -99,7 +111,7 @@ const PAGE_OPTIONS = {
99
111
  deviceScaleFactor: 1,
100
112
  reducedMotion: "reduce",
101
113
  }
102
- const NOUN = { canvas: "the canvas", page: "the page" }[layout] ?? "the deck"
114
+ const NOUN = { canvas: "the canvas", page: "the page", document: "the document" }[layout] ?? "the deck"
103
115
 
104
116
  /** What the check has found so far, which a check that stops early reports. */
105
117
  const found = {
@@ -108,10 +120,7 @@ const found = {
108
120
  problems: [],
109
121
  errors: [],
110
122
  screenshots: [],
111
- // A canvas's: each board's picture in each theme the reader sees it in, the boards that stopped
112
- // answering, and the whole canvas as it opens.
113
- previews: [],
114
- unpictured: [],
123
+ // A canvas's: the boards that stopped answering, and the whole canvas as it opens.
115
124
  // A canvas's boards whose page draws larger than the board shows.
116
125
  oversized: [],
117
126
  stalls: [],
@@ -128,7 +137,6 @@ const findings = () => ({
128
137
  screenshots: [...found.screenshots].sort(
129
138
  (left, right) => byBoard({ board: shotBoard(left) }, { board: shotBoard(right) })
130
139
  ),
131
- previews: [...found.previews].sort(byBoard),
132
140
  })
133
141
  const shotBoard = (file) => path.basename(file, ".png")
134
142
 
@@ -235,10 +243,8 @@ function openTab(page, stepOf) {
235
243
  /**
236
244
  * A canvas's boards, each at its own size in each theme, a few at once. Each lane is a browser
237
245
  * context of its own, so a board that stops answering costs only its lane, which goes on in a new
238
- * one. A board's first theme is screenshot as boards/<id>.png; a board marked `pictured`, which
239
- * the reader sees as a picture until they open it, in every theme, the others as
240
- * boards/<id>.<theme>.png. Then the whole canvas as it opens, when overview.html says how. Returns
241
- * whether a board stalled.
246
+ * one. A board's first theme is screenshot as boards/<id>.png. Then the whole canvas as it opens,
247
+ * when overview.html says how. Returns whether a board stalled.
242
248
  */
243
249
  async function checkCanvas(browser, port, probe, themes) {
244
250
  const boards = JSON.parse(fs.readFileSync(path.join(out, "boards.json"), "utf8"))
@@ -261,7 +267,6 @@ async function checkCanvas(browser, port, probe, themes) {
261
267
  await tab.page.setViewportSize({ width: board.w, height: Math.min(board.h, PAGE_HEIGHT) })
262
268
  await tab.load(`http://127.0.0.1:${port}/${board.file.split("/").map(encodeURIComponent).join("/")}`)
263
269
 
264
- const pictures = []
265
270
  for (const [index, name] of names.entries()) {
266
271
  const step = tab.at(`board '${board.id}' in ${name} mode`)
267
272
  await tab.send("theme", themes[name])
@@ -269,35 +274,15 @@ async function checkCanvas(browser, port, probe, themes) {
269
274
  for (const problem of await within(step, tab.page.evaluate(`(${probe})("page")`))) {
270
275
  found.problems.push({ ...problem, board: board.id, theme: name })
271
276
  }
272
- if (index === 0) {
273
- const page = await within(step, tab.page.evaluate(contentSize))
274
- if (page.w > board.w + slack(board.w) || page.h > board.h + slack(board.h)) {
275
- found.oversized.push({ board: board.id, w: board.w, h: board.h, page })
276
- }
277
+ if (index > 0) continue
278
+ const page = await within(step, tab.page.evaluate(contentSize))
279
+ if (page.w > board.w + slack(board.w) || page.h > board.h + slack(board.h)) {
280
+ found.oversized.push({ board: board.id, w: board.w, h: board.h, page })
277
281
  }
278
-
279
- if (index > 0 && !board.pictured) continue
280
- const file = path.join(out, "boards", index === 0 ? `${board.id}.png` : `${board.id}.${name}.png`)
281
- const png = await tab.page.screenshot({ path: file, timeout: STEP_MS })
282
- if (index === 0) found.screenshots.push(file)
283
- if (!board.pictured || tab.failures.length > 0) continue
284
-
285
- const small = path.join(out, "boards", `${board.id}.${name}.small.webp`)
286
- await shrink(browser, png, board.smallWidth, small)
287
- pictures.push(
288
- { board: board.id, theme: name, size: "full", path: file, bytes: png.length },
289
- { board: board.id, theme: name, size: "small", path: small, bytes: fs.statSync(small).size }
290
- )
282
+ const file = path.join(out, "boards", `${board.id}.png`)
283
+ await tab.page.screenshot({ path: file, timeout: STEP_MS })
284
+ found.screenshots.push(file)
291
285
  }
292
-
293
- // A page that did not load whole is pictured broken, and its picture would stay: none is
294
- // taken, and the board keeps its outline until it loads.
295
- if (!board.pictured) return
296
- if (tab.failures.length > 0) {
297
- found.unpictured.push({ board: board.id, reason: tab.failures[0] })
298
- return
299
- }
300
- found.previews.push(...pictures)
301
286
  }
302
287
 
303
288
  const lane = async () => {
@@ -325,49 +310,6 @@ async function checkCanvas(browser, port, probe, themes) {
325
310
  return stalled
326
311
  }
327
312
 
328
- /** How a small picture's WebP is encoded: as sharp as text needs at its size, by eye. */
329
- const SMALL_QUALITY = 0.85
330
- /** A blank page where small pictures are encoded, apart from every board's scripts. */
331
- let encoder
332
-
333
- /**
334
- * A board's screenshot at most `width` wide, its aspect kept, as WebP in `file`: what a canvas
335
- * shows when it draws the board small. Encoded by the browser's own canvas.
336
- */
337
- async function shrink(browser, png, width, file) {
338
- encoder ??= within("the browser", browser.newContext()).then((context) =>
339
- within("the browser", context.newPage())
340
- )
341
- const page = await encoder
342
- const webp = await within(
343
- "a small picture",
344
- page.evaluate(
345
- async ({ data, width, quality }) => {
346
- const image = new Image()
347
- image.src = `data:image/png;base64,${data}`
348
- await image.decode()
349
- const scale = Math.min(1, width / image.naturalWidth)
350
- const canvas = document.createElement("canvas")
351
- canvas.width = Math.max(1, Math.round(image.naturalWidth * scale))
352
- canvas.height = Math.max(1, Math.round(image.naturalHeight * scale))
353
- const context = canvas.getContext("2d")
354
- context.imageSmoothingQuality = "high"
355
- context.drawImage(image, 0, 0, canvas.width, canvas.height)
356
- const blob = await new Promise((done) => canvas.toBlob(done, "image/webp", quality))
357
- if (blob?.type !== "image/webp") throw new Error("this browser does not encode WebP")
358
- const bytes = new Uint8Array(await blob.arrayBuffer())
359
- let binary = ""
360
- for (let at = 0; at < bytes.length; at += 0x8000) {
361
- binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000))
362
- }
363
- return btoa(binary)
364
- },
365
- { data: png.toString("base64"), width, quality: SMALL_QUALITY }
366
- )
367
- )
368
- fs.writeFileSync(file, Buffer.from(webp, "base64"))
369
- }
370
-
371
313
  /**
372
314
  * overview.html, the whole canvas as the app opens it with each board its picture, screenshot
373
315
  * as overview.png at the size overview.json gives. One that fails leaves the check as it is.
@@ -461,6 +403,10 @@ async function main() {
461
403
  () => step
462
404
  )
463
405
  const { problems, screenshots } = found
406
+ if (layout === "document") {
407
+ await checkDocument({ page, load, settle, send }, port, probe, themes, (next) => (step = next))
408
+ return findings()
409
+ }
464
410
  if (layout === "page") {
465
411
  for (const view of VIEWS) {
466
412
  step = `the page at ${view.width}px`
@@ -540,6 +486,141 @@ async function main() {
540
486
  }
541
487
  }
542
488
 
489
+ /**
490
+ * A designed document: as one sheet at its paper's width and at a phone's, measured whole up to its
491
+ * cut, then, with paper, as its pages, each checked for what runs past its edge and screenshot. In
492
+ * the first theme: the paper is white in any.
493
+ */
494
+ async function checkDocument({ page, load, settle, send }, port, probe, themes, at) {
495
+ const { problems, screenshots } = found
496
+ const theme = Object.keys(themes)[0]
497
+ at(NOUN)
498
+ await page.setViewportSize({ width: 1280, height: 900 })
499
+ await load(`http://127.0.0.1:${port}/document.html`)
500
+ const paper = await within(
501
+ NOUN,
502
+ page.evaluate(() =>
503
+ (document.querySelector("script[data-sixb-paper]")?.getAttribute("data-sixb-paper") ?? "")
504
+ .split(" ")
505
+ .map(Number)
506
+ )
507
+ )
508
+ const sheet = paper[0] > 0 ? paper[0] : 0
509
+ // The sheet and the stage around it, wider than a phone's layout.
510
+ const width = Math.max(Math.ceil(sheet || 816) + 64, 760)
511
+ await page.setViewportSize({ width, height: 900 })
512
+ await send("theme", themes[theme])
513
+ await settle()
514
+ const height = await within(NOUN, page.evaluate(() => document.documentElement.scrollHeight))
515
+ await page.setViewportSize({ width, height: Math.max(900, Math.min(DOCUMENT_HEIGHT, height)) })
516
+ await settle()
517
+ for (const problem of await within(NOUN, page.evaluate(`(${probe})("page")`))) {
518
+ if (!SCREEN_ONLY.has(problem.code)) problems.push({ ...problem, theme })
519
+ }
520
+ if (!sheet) {
521
+ const file = path.join(out, "document.png")
522
+ await page.screenshot({ path: file, timeout: STEP_MS })
523
+ screenshots.push(file)
524
+ }
525
+
526
+ // On a phone the app shows it as one sheet at the screen's width, where a fixed grid column
527
+ // or a wide table runs off the side.
528
+ at(`${NOUN} on a phone`)
529
+ await page.setViewportSize({ width: PHONE.width, height: PHONE.height })
530
+ await settle()
531
+ const tall = await within(NOUN, page.evaluate(() => document.documentElement.scrollHeight))
532
+ await page.setViewportSize({
533
+ width: PHONE.width,
534
+ height: Math.max(PHONE.height, Math.min(PAGE_HEIGHT, tall)),
535
+ })
536
+ await settle()
537
+ for (const problem of await within(NOUN, page.evaluate(`(${probe})("page")`))) {
538
+ if (!SCREEN_ONLY.has(problem.code)) problems.push({ ...problem, view: "phone", theme })
539
+ }
540
+ const phone = path.join(out, "phone.png")
541
+ await page.screenshot({ path: phone, timeout: STEP_MS })
542
+ screenshots.push(phone)
543
+ if (!sheet) return
544
+
545
+ at(`${NOUN}'s pages`)
546
+ await page.setViewportSize({ width, height: 1200 })
547
+ await load(`http://127.0.0.1:${port}/document.html?pages#sixb-pages`)
548
+ await send("theme", themes[theme])
549
+ await page.waitForSelector("html[data-sixb-pages]", { timeout: STEP_MS })
550
+ await settle()
551
+ found.pages = await within(
552
+ `${NOUN}'s pages`,
553
+ page.evaluate(() => Number(document.documentElement.dataset.sixbPages) || 0)
554
+ )
555
+ for (const problem of await within(`${NOUN}'s pages`, page.evaluate(pastPageEdges))) {
556
+ problems.push({ ...problem, theme })
557
+ }
558
+ const sheets = await page.$$(".sixb-paper")
559
+ for (const [index, each] of sheets.slice(0, MAX_PAGES).entries()) {
560
+ const file = path.join(out, `page-${String(index + 1).padStart(2, "0")}.png`)
561
+ // A sheet shows its page once it is in view.
562
+ await each.scrollIntoViewIfNeeded({ timeout: STEP_MS })
563
+ await each.waitForSelector(".sixb-flow", { state: "attached", timeout: STEP_MS })
564
+ await each.screenshot({ path: file, timeout: STEP_MS })
565
+ screenshots.push(file)
566
+ }
567
+ }
568
+
569
+ /**
570
+ * What runs past a page's content box, which cuts it off: on each page, each fragment of an element
571
+ * that sits on the page and reaches past its right or bottom edge, such as a table too wide or an
572
+ * image too tall for the page. Only the outermost of what nests: what it holds runs past with it,
573
+ * and the box that runs past is the one to fit. Run in the page, on the first sheet's flow, which
574
+ * lays out every page side by side, each its column.
575
+ */
576
+ function pastPageEdges() {
577
+ const problems = []
578
+ const flow = document.querySelector(".sixb-paper .sixb-flow")
579
+ const box = flow?.parentElement?.getBoundingClientRect()
580
+ if (!flow || !box) return problems
581
+ // In CSS pixels, and as the sheets are zoomed to fit.
582
+ const style = getComputedStyle(flow)
583
+ const scale = box.width / Number.parseFloat(style.width) || 1
584
+ const stride = box.width + (Number.parseFloat(style.columnGap) || 0) * scale
585
+ const pages = new Map()
586
+ for (const element of flow.querySelectorAll("*")) {
587
+ for (const rect of element.getClientRects()) {
588
+ if (rect.width < 1 || rect.height < 1) continue
589
+ const index = Math.max(0, Math.floor((rect.left - box.left + 1) / stride))
590
+ const left = box.left + index * stride
591
+ if (rect.right > left + box.width + 1 || rect.bottom > box.bottom + 1) {
592
+ const past = pages.get(index) ?? []
593
+ pages.set(index, past)
594
+ past.push({ element, rect, left })
595
+ break
596
+ }
597
+ }
598
+ }
599
+ for (const [index, past] of [...pages].sort(([a], [b]) => a - b)) {
600
+ const outermost = past.filter(
601
+ ({ element }) => !past.some((other) => other.element !== element && other.element.contains(element))
602
+ )
603
+ for (const { element, rect, left } of outermost.slice(0, 5)) {
604
+ const classes = Array.from(element.classList)
605
+ problems.push({
606
+ code: "outside",
607
+ page: index + 1,
608
+ rect: {
609
+ x: Math.round(rect.left - left),
610
+ y: Math.round(rect.top - box.top),
611
+ width: Math.round(rect.width),
612
+ height: Math.round(rect.height),
613
+ },
614
+ text:
615
+ (element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 60) ||
616
+ element.tagName.toLowerCase(),
617
+ selector: `${element.tagName.toLowerCase()}${classes.length > 0 ? `.${classes.join(".")}` : ""}`,
618
+ })
619
+ }
620
+ }
621
+ return problems.slice(0, 30)
622
+ }
623
+
543
624
  /**
544
625
  * Text over a photo, which the probe cannot judge from styles: each text whose center sits over
545
626
  * an image is hidden, the slide is shot without it, and the pixels under its box are read. The