@buffcore/cli 0.8.43 → 0.8.45

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 (65) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/commands/prototype/mark-shot.d.ts +31 -0
  3. package/dist/commands/prototype/mark-shot.js +149 -0
  4. package/dist/commands/ui/chat/approval-folders.d.ts +20 -0
  5. package/dist/commands/ui/chat/approval-folders.js +134 -0
  6. package/dist/commands/ui/chat/approval-text.d.ts +11 -0
  7. package/dist/commands/ui/chat/approval-text.js +69 -0
  8. package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
  9. package/dist/commands/ui/chat/approval-writes.js +179 -0
  10. package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
  11. package/dist/commands/ui/chat/claude-permissions.js +32 -4
  12. package/dist/commands/ui/chat/codex-idle.d.ts +1 -1
  13. package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
  14. package/dist/commands/ui/chat/commit-limits.js +164 -0
  15. package/dist/commands/ui/chat/fresh-critique.js +3 -1
  16. package/dist/commands/ui/chat/fresh-launch.d.ts +5 -0
  17. package/dist/commands/ui/chat/fresh-launch.js +7 -4
  18. package/dist/commands/ui/chat/fresh.js +7 -1
  19. package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
  20. package/dist/commands/ui/chat/gh-api-limits.js +74 -0
  21. package/dist/commands/ui/chat/git-words.d.ts +10 -0
  22. package/dist/commands/ui/chat/git-words.js +26 -0
  23. package/dist/commands/ui/chat/host-launched.d.ts +11 -0
  24. package/dist/commands/ui/chat/host-launched.js +35 -0
  25. package/dist/commands/ui/chat/limit-mentions.js +16 -2
  26. package/dist/commands/ui/chat/limit-text.d.ts +15 -0
  27. package/dist/commands/ui/chat/limit-text.js +36 -0
  28. package/dist/commands/ui/chat/limits-hook.js +2 -2
  29. package/dist/commands/ui/chat/limits.d.ts +7 -12
  30. package/dist/commands/ui/chat/limits.en.d.ts +2 -0
  31. package/dist/commands/ui/chat/limits.en.js +2 -0
  32. package/dist/commands/ui/chat/limits.es.js +2 -0
  33. package/dist/commands/ui/chat/limits.js +63 -59
  34. package/dist/commands/ui/chat/planning-limits.js +11 -0
  35. package/dist/commands/ui/chat/publish-limits.js +23 -7
  36. package/dist/commands/ui/chat/turn-guard.d.ts +8 -2
  37. package/dist/commands/ui/chat/turn-guard.js +8 -3
  38. package/dist/commands/ui/commands.en.d.ts +3 -0
  39. package/dist/commands/ui/commands.en.js +3 -0
  40. package/dist/commands/ui/commands.es.d.ts +3 -0
  41. package/dist/commands/ui/commands.es.js +3 -0
  42. package/dist/commands/ui/index.d.ts +42 -0
  43. package/dist/commands/ui/index.js +14 -2
  44. package/dist/commands/ui/plan-brief.d.ts +13 -0
  45. package/dist/commands/ui/plan-brief.js +91 -0
  46. package/dist/commands/ui/plan-files.d.ts +1 -11
  47. package/dist/commands/ui/plan-files.js +2 -48
  48. package/dist/commands/ui/prototype-main.d.ts +5 -0
  49. package/dist/commands/ui/prototype-shot-route.d.ts +16 -0
  50. package/dist/commands/ui/prototype-shot-route.js +98 -0
  51. package/dist/commands/ui/routes.d.ts +2 -0
  52. package/dist/commands/ui/server-core.js +2 -0
  53. package/dist/commands/ui/server-options.js +1 -0
  54. package/dist/commands/ui/server-request.js +5 -0
  55. package/dist/commands/ui/server.d.ts +7 -0
  56. package/dist/commands/ui/server.js +16 -1
  57. package/dist/commands/ui/studio-routes.d.ts +1 -0
  58. package/dist/commands/ui/studio-routes.js +3 -1
  59. package/dist/commands/ui/studio-state.d.ts +6 -0
  60. package/dist/ui/page.js +114 -95
  61. package/docs/PROTOTYPE.md +14 -2
  62. package/docs/WORKBENCH.md +12 -3
  63. package/package.json +11 -11
  64. package/skills/ape-plan-change/SKILL.md +8 -0
  65. package/templates/product/plan/brief.md +29 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,34 @@ One section per release (a git tag). **Upgrade notes** list anything that breaks
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## v0.8.45 (2026-12-03)
8
+
9
+ - The studio's Prototype is a workspace: along the top, the change and its version (Compare, Approve), **Customer app | Console**, **Mobile | Tablet | Desktop** (Rotate for a tablet) and the tools **Select | Comment | Draw | Area**; on the left, **Journeys** (from `plan/journeys.md`, by who does them and in which app, joined to the journeys the running app plays; the open one lists its steps to jump to) and **Screens**, with the sample data at the foot; in the middle, the app in its device, zoomed to fit, with a line saying what you see and the step bar (Back, the step, Play, Next) under it. The console is a second frame at the stack's admin address: switching keeps each one's step and never reloads the other. The rail folds to its icons on this page. At phone width a phone's app takes the page (a tablet or a desktop is drawn in its bezel, zoomed to fit), the device choice shows as icons, and a bar sits at the app's foot (Journeys, Back, the step, Next, Changes); on a touch screen the Comment hint says tap. The preview's Try a journey and Preview options menus, the canvas's Full screen button and the drawn-only full-screen scenes are gone.
10
+
11
+ **Upgrade notes** (hosts that build on `@buffcore/admin-shell/workbench`): the drawn-only full screen is removed from the public types: `LOOP_MOMENTS` (and so `LoopMoment`) no longer has `fs-tablet`, `fs-overview` or `fs-change`, `LoopSample` no longer has `fs`, and `FsSample` and `FsMark` are gone; delete them from your own sample data. The studio catalog's `studio.loop.proto.fullScreen` and `studio.loop.fs.*` messages are gone too, so drop any override of them. `ProtoSample` gains an optional `consoleOthers` (the console's scenes for the workspace's Screens).
12
+ - Marking in the Prototype workspace, with the bar's tools (or the keys V, C, P and R; Escape for Select) and their hint in the line above the device: Comment pins a numbered note on the part clicked (the running app names it, "Comment on Price", by its accessible label or test id, else "this spot"), Area drags a dashed box and Draw marks freehand. The marks are kept per change and version until sent and listed above the chat's box, each with its number, kind, screen and device (a mark records the app, the device, a turned tablet, and the journey step or sample data shown; a click shows them again), its note and Remove, with Clear all and a box for anything else. One **Send N changes** sends one message with every mark, its note and its place, and a picture of each marked screen, shot by the snapshot's browser at that device with the marks drawn (`POST /api/prototype/shot`); while the agent works it waits in the chat as one card (Edit, Back to the box) and goes when the turn ends. The bridge's new `ape:prototype:part` ask goes only on the private port of the current hello and its answer is read strictly: only a name and a box, never the app's data. At phone width the foot bar's Changes counts the marks. `TextArea` gains `labelHidden`; the icon set gains `tablet`. Known limits: marks go on the customer app only, so on the Console the marking tools are off and the line above the device says why (a picture of the console would need a signed-in browser); and the picture's browser refuses requests and WebSockets to other hosts and a page that ends on another address, but a redirect the app's own server answers is followed before that check (the app's server could fetch that address anyway).
13
+
14
+ **Upgrade notes** (every product): keep `@buffcore/app-shell` and `@buffcore/admin-shell` on the same release (`ape upgrade` does); an older prototype home does not answer the part ask, so a comment is on "this spot".
15
+ - The Brief reads short first: What it is; Who uses it as a table (role, where, what we know); Kind; How it earns with the money seal; Must have and Not now side by side, the first few of each with "N more"; Not this project, each line with Edit and Add a line (both a message to the agent, as adding was); the agent's questions. Each section's Read more opens its whole text from `plan/brief.md` in a reading sheet (headings, real lists, about 68 characters a line, the product's Markdown shown as text only), and the brief's other sections open from one Read the whole brief. The short form is the `> Summary:` line the agent writes under each heading (one per role in Who it is for, one per item in Must do and Later); a section without one shows its first sentence, and a section the brief does not have is not shown. The studio state's brief gains `parts` (each section's summaries and Markdown); `Markdown` reads numbered lists and takes `size="read"`, and `Sheet` takes `size="read"` and a `sub` line.
16
+
17
+ **Upgrade notes** (every product): the brief template and the `ape-plan-change` skill now ask for a `> Summary:` line under each heading of `plan/brief.md`; `ape upgrade` refreshes the skill. An existing brief works as it is (each section shows its first sentence); to read it short, ask the agent to add the summary lines.
18
+ - The studio's scroll bars are a little easier to find: the thumb is a little stronger than a border.
19
+
20
+ ## v0.8.44 (2026-12-02)
21
+
22
+ - A host whose own trusted launcher starts the agent's turns can say so: `createUiServer({ hostLaunched: true })`, or `APE_HOST_LAUNCHED=1` in the environment of `ape ui` (exactly `1`). Every Claude Code turn (coding, Build, design, validation, tests, fixes, planning on Autopilot) then launches exactly as a 0.8.41 turn did: no per-turn `--settings` file with the limits hook, no `--mcp-config` with the permission tool, no `--permission-prompt-tool` and no per-turn socket; `acceptEdits`, or `dontAsk` with hooks off for planning, at every level (never `auto` or `bypassPermissions`, Autopilot and Never ask included), with 0.8.41's allow and deny lists. Fresh turns (the review before Save and the critique) follow it: hooks off through the inline `--settings` JSON, no settings file and no `--setting-sources=`. Settings says once that the host starts the agents and applies their limits (English and Spanish), and the studio state gains an optional `hostLaunched`. Off by default: nothing changes for a host that passes nothing.
23
+
24
+ **Upgrade notes** (hosts that build their own studio server): with `hostLaunched` on, the studio's limits hook, its permission card and its later deny rules are not in the turns, so your launcher must enforce everything the hook does, through every wrapper and shell it reads: the limit commands (`git push`; downloads with `curl`, `wget`, `iwr`, `irm`, `Invoke-WebRequest`, `Invoke-RestMethod` and `Start-BitsTransfer`, which the hook holds for the person; `ape deploy` and `ape server deploy` however started; `npm publish` with npm's short forms `npm pu`, `npm pub`, `npm publ`, `npm publi` and `npm publis`, `pnpm publish`, `yarn publish` and `yarn npm publish`; `gh release create`, `new`, `upload`, `edit` and `delete`), reads and writes of production settings files (`.env.production`, `.env.prod*`, `.env.staging*`) and of the secret folders (`.ssh`, `.gnupg`, `.aws`, `.azure`, `.kube`, `.docker`, `.gcloud`, `.password-store`, `secrets`), WebFetch, and the calls it refuses when unsure: a command it cannot read or that is too long or too deeply nested, a here-document whose end line never comes, a shell or interpreter given its script on standard input, `Invoke-Expression` (`iex`), and a file pattern or mention that could reach a limit. The source of truth, which later releases add to, is the limits files in `packages/cli/src/commands/ui/chat/`: `limits.ts`, `planning-limits.ts`, `publish-limits.ts`, `limit-patterns.ts`, `limit-mentions.ts`, `stdin-shells.ts` and `secret-folders.ts`. Your launcher also checks the turn's arguments and decides which settings files a turn loads (the person's and the product's allow rules widen what a fresh turn's `dontAsk` runs unless it keeps them out). The mode belongs to the product folder of the `runner` you pass (`runner.cwd`), one mode per folder (the last server created for it decides), and ends when the server closes; build `ChatEngine` and `FreshLooks` on that same folder. `APE_HOST_LAUNCHED` counts only from the environment `ape ui` starts with, never from the product's `.env`.
25
+ - The studio's chat box empties the moment Send (or Enter) is pressed; the words show in the chat as sending, and a refused or interrupted send puts them back in the box, with the reason under it, never losing them: anything typed meanwhile follows them after a blank line.
26
+ - Play on the Journeys page opens the Prototype with that journey selected at its first step, once the app lists it (by its key, or else by its planned name).
27
+ - The Prototype preview's step bar (Back, the step and its caption, Next) sits under the device frame at every device and width, no longer over the app.
28
+ - Stepping through a journey, choosing one and choosing sample data no longer reload the app: the studio tells the running prototype home what to show by an `ape:prototype:show` message on the private port its hello opened, and the home answers the new step's caption on that port. A home that reloads itself gets the current choice again; one that does not say it plays (`ape:prototype:player`) is reloaded at each step, as before. The app reloads only when its address, the language or the mode changes. The message carries only a journey key and step, or a data state, and the studio still takes nothing from the app but its journey list, liveness and that caption.
29
+
30
+ **Upgrade notes** (every product): keep `@buffcore/app-shell` and `@buffcore/admin-shell` on the same release (`ape upgrade` does); an older prototype home still plays, reloading at each step.
31
+ - The studio's scroll bars are thin and drawn in the theme's colors, light and dark, in every panel inside the studio frame.
32
+ - An agent cannot make its own approval from the shell, "Never ask" included. A shell command that could write into the approval records, `prototype/versions/`, is refused at every level: a redirect into the folder (`>`, `>>`, `&>`, `2>`, `>|`), or any program that names a path in it other than a read (`cp`, `mv`, `tee`, `sed -i`, `node -e`, `python -c`, `git checkout … --`, `Set-Content`, `Out-File` and the rest), read against the shell's folder with `..`, case and patterns counted; on design and validation turns at any level, and planning and loop turns on Autopilot, so is a program that writes the paths it names aimed at a folder that holds the records, `prototype` taking only a single file copied in (`cp design/logo.svg prototype/`), and a patch or archive (`git apply`, `git am`, `patch`, `Expand-Archive`), with `$PWD`, `~+`, `$OLDPWD` and `(Get-Location)` read as folders (coding, tests and fixes turns keep writing their own tree; `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`, `git checkout <ref> -- .`, `find prototype … -delete` or `-exec`, `tar -x` or `unzip` into the shell's folder, `Copy-Item -Recurse … prototype`, `ls prototype | xargs rm`, `gci -r prototype | Set-Content`). A command whose text names both folders and looks like a write is refused when any part of it is more than a read, and goes to the card when every part only reads. A design or validation turn on Autopilot, and a planning or loop turn on Autopilot, (or one whose level the hook was not told) makes no commit and moves no branch: `git commit`, `commit-tree`, `update-ref`, `merge`, `cherry-pick`, `revert`, `rebase`, `am`, `pull`, `hash-object`, `fast-import`, `stash` (but `list` and `show`), `reset` to a commit, `branch -f`/`-M`/`-C`, `checkout -B`, `switch -C`, `fetch` into a branch, `git subtree add|merge|pull` and `split --rejoin`, and git with a configuration set anywhere in the command (`-c alias.…`, `-c include.path=…`, `export HOME=…`, `$env:GIT_CONFIG_GLOBAL=…`) beside a subcommand that commits or is not git's own are refused there (`export HOME=x; git log` runs), a git subcommand that is not git's own (an alias such as `git ci`) goes to the card, and a shape the parse cannot follow (`$g commit`) goes to the card; coding turns still commit in their own change tree. Reads still run, their output redirected anywhere else too (`cat`, `ls`, `grep`, `head`, `tail`, `wc`, `sed -n`, `awk`, `sort`, `find`, `git log --grep merge`, `git show`, `git diff`, `Get-Content`). The limit card names each: **Writing an approval record**, **Committing from a design step on Autopilot**; the chat contract's limit gains `approval` and `commit`. The limits hook now takes the turn's level after its work (`limits-hook.ts <work> <level>`). On those turns a write the parse cannot place goes to the card: a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x` and `7z x … -o…`; `sed` counts as a pipe writer only with `-i`, and `%`/`ForEach-Object` only when its block holds a writer. Not caught (known limits): a write that reaches the folder through a `cd` earlier in the same command and is otherwise only reads (it goes to the card); a variable, an alias, a function or a symbolic link set in an earlier call (`d=prototype/versions` then `cp x $d`, `ln -s prototype/versions v` then `cp x v/`); a path built from strings (`printf`, string joins in `node -e` or `python -c`); a script file written earlier and run later; a commit through an alias already in the product's own git configuration (it goes to the card), or through a tool other than git (a library from `node -e`); and OpenCode and planning turns below Autopilot, which use prefix rules and have none for these writes.
33
+ - More publishing commands are limits at every level, "Never ask" included: `bun publish`, `lerna publish` and `changeset publish` (also as `npx @changesets/cli publish`) are refused as publishing a package, and `gh api` calls that create or change a release (a method other than GET or HEAD on `repos/{owner}/{repo}/releases`, or fields or a body with no method named, an asset upload included) as publishing a release, through every wrapper the limits read. `gh api` reads of releases (`gh api repos/o/r/releases`, `-X GET … -f per_page=5`), `changeset version`, `lerna run` and `bun install` still run.
34
+
7
35
  ## v0.8.43 (2026-12-02)
8
36
 
9
37
  - Publishing is a limit at every level, "Never ask" included: `npm publish` (and the short names npm accepts, `npm pu` to `npm publis`), `pnpm publish`, `yarn publish`, `yarn npm publish` and `gh release create|new|upload|edit|delete` are refused through every wrapper the limits read; `npm view`, `gh release list` and other reads still run, and a command that only asks for `--help` runs. A command a limit refused now shows a card in the step's chat, **This can't be allowed here**, naming the limit and the command, with **Copy the command** and no Allow (Claude Code turns; the card is marked from the hook's own refusal). The chat contract's refused event gains an optional `limit`. Not caught: `bun publish`, `lerna publish`, `changeset publish` and `gh api` release calls.
@@ -0,0 +1,31 @@
1
+ import type { MarkShotBody } from '@buffcore/contracts/workbench';
2
+ import type { Browser } from 'playwright-core';
3
+ /** The running app's prototype home at the marked step or data, as the studio frames it. */
4
+ export declare function shotAddress(app: string, body: MarkShotBody, navigation: string): URL;
5
+ /**
6
+ * Runs inside the page (Playwright sends its source): one layer over the screen with each mark,
7
+ * an area dashed, a drawing as its line, and every mark's number in a dot. Only numbers are drawn:
8
+ * a note never reaches the page. The colors are fixed, not the app's: they must read on any app.
9
+ */
10
+ export declare function drawMarks(marks: MarkShotBody['marks']): void;
11
+ /** The whole picture (load, fonts, marks and the shot itself) is done within this, or refused (ms). */
12
+ export declare const SHOT_LIMIT = 30000;
13
+ /** The shot took longer than its limit: its context was closed. */
14
+ export declare class ShotTimeout extends Error {
15
+ }
16
+ /** A WebSocket address on the app's own origin: ws for http, wss for https, the same host. */
17
+ export declare function sameHost(socket: URL, app: URL): boolean;
18
+ /** The page left the app's own address before the shot. */
19
+ export declare class ShotMoved extends Error {
20
+ }
21
+ /**
22
+ * Runs inside the page: scrolls the page, and its tallest scroller, as the app was scrolled when
23
+ * marked (the same rule finds the scroller as the app's own answer does).
24
+ */
25
+ export declare function scrollTo(scroll: NonNullable<MarkShotBody['scroll']>): void;
26
+ /**
27
+ * Opens `url` at the marked size in a fresh context, scrolled as marked, draws the marks and returns
28
+ * the PNG, all within `limit` ms. The context reaches only the app's own origin: any request to
29
+ * another host is refused, and a page that left the address (a redirect) is not shot.
30
+ */
31
+ export declare function shootMarks(browser: Browser, url: URL, body: MarkShotBody, limit?: number): Promise<Buffer>;
@@ -0,0 +1,149 @@
1
+ /** How long the page's own requests get to settle before the picture is taken (ms). */
2
+ const SETTLE = 5_000;
3
+ /** The running app's prototype home at the marked step or data, as the studio frames it. */
4
+ export function shotAddress(app, body, navigation) {
5
+ const url = new URL(app);
6
+ url.pathname = `${url.pathname.replace(/\/+$/, '')}/prototype`;
7
+ url.search = new URLSearchParams({
8
+ embed: '1',
9
+ apeNav: navigation,
10
+ studioPreview: '1',
11
+ locale: body.locale,
12
+ mode: body.mode,
13
+ ...(body.journey ? { journey: body.journey, step: String(body.step ?? 0) } : {}),
14
+ ...(body.data ? { data: body.data } : {}),
15
+ }).toString();
16
+ url.hash = '';
17
+ return url;
18
+ }
19
+ /**
20
+ * Runs inside the page (Playwright sends its source): one layer over the screen with each mark,
21
+ * an area dashed, a drawing as its line, and every mark's number in a dot. Only numbers are drawn:
22
+ * a note never reaches the page. The colors are fixed, not the app's: they must read on any app.
23
+ */
24
+ export function drawMarks(marks) {
25
+ const svg = 'http://www.w3.org/2000/svg';
26
+ const layer = document.createElementNS(svg, 'svg');
27
+ layer.setAttribute('width', String(window.innerWidth));
28
+ layer.setAttribute('height', String(window.innerHeight));
29
+ layer.setAttribute('style', 'position:fixed;inset:0;z-index:2147483647;pointer-events:none;overflow:visible');
30
+ const add = (name, attributes) => {
31
+ const node = document.createElementNS(svg, name);
32
+ for (const [key, value] of Object.entries(attributes))
33
+ node.setAttribute(key, String(value));
34
+ layer.appendChild(node);
35
+ return node;
36
+ };
37
+ const line = { fill: 'none', stroke: '#2563eb', 'stroke-linecap': 'round' };
38
+ for (const mark of marks) {
39
+ if (mark.kind === 'area' && mark.box)
40
+ add('rect', {
41
+ ...line,
42
+ x: mark.box.x,
43
+ y: mark.box.y,
44
+ width: mark.box.w,
45
+ height: mark.box.h,
46
+ rx: 4,
47
+ 'stroke-width': 2,
48
+ 'stroke-dasharray': '6 4',
49
+ });
50
+ if (mark.kind === 'draw' && mark.points)
51
+ add('polyline', {
52
+ ...line,
53
+ points: mark.points.map(([x, y]) => `${x},${y}`).join(' '),
54
+ 'stroke-width': 3,
55
+ 'stroke-linejoin': 'round',
56
+ });
57
+ const [x, y] = mark.box ? [mark.box.x, mark.box.y] : (mark.points?.[0] ?? [0, 0]);
58
+ add('circle', { cx: x, cy: y, r: 12, fill: '#2563eb', stroke: '#ffffff', 'stroke-width': 2 });
59
+ const label = add('text', {
60
+ x,
61
+ y,
62
+ fill: '#ffffff',
63
+ 'font-family': 'system-ui, sans-serif',
64
+ 'font-size': 12,
65
+ 'font-weight': 700,
66
+ 'text-anchor': 'middle',
67
+ 'dominant-baseline': 'central',
68
+ });
69
+ label.textContent = String(mark.n);
70
+ }
71
+ document.body.appendChild(layer);
72
+ }
73
+ /** The whole picture (load, fonts, marks and the shot itself) is done within this, or refused (ms). */
74
+ export const SHOT_LIMIT = 30_000;
75
+ /** The shot took longer than its limit: its context was closed. */
76
+ export class ShotTimeout extends Error {
77
+ }
78
+ /** A WebSocket address on the app's own origin: ws for http, wss for https, the same host. */
79
+ export function sameHost(socket, app) {
80
+ const scheme = { 'ws:': 'http:', 'wss:': 'https:' }[socket.protocol];
81
+ return scheme === app.protocol && socket.host === app.host;
82
+ }
83
+ /** The page left the app's own address before the shot. */
84
+ export class ShotMoved extends Error {
85
+ }
86
+ /**
87
+ * Runs inside the page: scrolls the page, and its tallest scroller, as the app was scrolled when
88
+ * marked (the same rule finds the scroller as the app's own answer does).
89
+ */
90
+ export function scrollTo(scroll) {
91
+ window.scrollTo(scroll.page.x, scroll.page.y);
92
+ let tallest;
93
+ let most = 0;
94
+ const all = document.body?.querySelectorAll('*') ?? [];
95
+ for (let i = 0; i < all.length && i < 20_000; i++) {
96
+ const el = all[i];
97
+ const room = el.scrollHeight - el.clientHeight;
98
+ if (room > most && /auto|scroll|overlay/.test(getComputedStyle(el).overflowY)) {
99
+ most = room;
100
+ tallest = el;
101
+ }
102
+ }
103
+ tallest?.scrollTo(scroll.inner.x, scroll.inner.y);
104
+ }
105
+ /**
106
+ * Opens `url` at the marked size in a fresh context, scrolled as marked, draws the marks and returns
107
+ * the PNG, all within `limit` ms. The context reaches only the app's own origin: any request to
108
+ * another host is refused, and a page that left the address (a redirect) is not shot.
109
+ */
110
+ export async function shootMarks(browser, url, body, limit = SHOT_LIMIT) {
111
+ const context = await browser.newContext({
112
+ viewport: body.view,
113
+ deviceScaleFactor: 1,
114
+ colorScheme: body.mode,
115
+ locale: body.locale,
116
+ serviceWorkers: 'block',
117
+ });
118
+ let timer;
119
+ const expired = new Promise((_, reject) => {
120
+ timer = setTimeout(() => reject(new ShotTimeout(`no picture within ${limit} ms`)), limit);
121
+ });
122
+ const shot = async () => {
123
+ // tsx names functions with `__name`; functions sent to the page need it there too.
124
+ await context.addInitScript({ content: 'globalThis.__name = (fn) => fn;' });
125
+ await context.route('**/*', (route) => new URL(route.request().url()).origin === url.origin ? route.continue() : route.abort());
126
+ // A WebSocket to another host is closed before it connects; the app's own goes through.
127
+ await context.routeWebSocket((socket) => !sameHost(socket, url), (socket) => socket.close());
128
+ const page = await context.newPage();
129
+ await page.goto(url.href, { waitUntil: 'load', timeout: limit });
130
+ await page.waitForLoadState('networkidle', { timeout: SETTLE }).catch(() => undefined);
131
+ await page.evaluate(() => document.fonts?.ready.then(() => true));
132
+ if (body.scroll)
133
+ await page.evaluate(scrollTo, body.scroll);
134
+ await page.evaluate(drawMarks, body.marks);
135
+ if (new URL(page.url()).origin !== url.origin)
136
+ throw new ShotMoved(`the page left ${url.origin}`);
137
+ return await page.screenshot({ animations: 'disabled', type: 'png' });
138
+ };
139
+ const running = shot();
140
+ running.catch(() => undefined);
141
+ try {
142
+ return await Promise.race([running, expired]);
143
+ }
144
+ finally {
145
+ clearTimeout(timer);
146
+ // Closing the context ends whatever the shot was still waiting for.
147
+ await context.close().catch(() => undefined);
148
+ }
149
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * On the turns that write the product's own folder (design and validation at any level;
3
+ * planning and loop on Autopilot), a write aimed at a folder that holds the approval records is
4
+ * refused as well as one into them: `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`,
5
+ * `git checkout <ref> -- .`, `find prototype … -delete`, `tar -x` or `unzip` into the shell's
6
+ * folder, `Copy-Item -Recurse … prototype`. `prototype` itself takes a single file copied in
7
+ * (`cp design/logo.svg prototype/`); a whole folder copied, moved or linked there could become
8
+ * `prototype/versions`. A patch or an archive that could reach anywhere (`git apply`, `git am`,
9
+ * `patch`, `Expand-Archive`) is refused there outright. Plain Node only: the hook runs it.
10
+ */
11
+ /** True when a part writes into, or is aimed at, a folder that holds the approval records. */
12
+ export declare function folderWrite(words: string[], cwd: string): boolean;
13
+ /**
14
+ * What a design turn's command could write that the parse cannot place, for the person's card:
15
+ * a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x`, and
16
+ * `7z x … -o…` (its folder is fused to the option).
17
+ */
18
+ export declare function folderUnsure(parts: string[][]): boolean;
19
+ /** A word that names a folder holding the records (a pipe's source, for the fallback). */
20
+ export declare const holdsRecords: (word: string, cwd: string) => boolean;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * On the turns that write the product's own folder (design and validation at any level;
3
+ * planning and loop on Autopilot), a write aimed at a folder that holds the approval records is
4
+ * refused as well as one into them: `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`,
5
+ * `git checkout <ref> -- .`, `find prototype … -delete`, `tar -x` or `unzip` into the shell's
6
+ * folder, `Copy-Item -Recurse … prototype`. `prototype` itself takes a single file copied in
7
+ * (`cp design/logo.svg prototype/`); a whole folder copied, moved or linked there could become
8
+ * `prototype/versions`. A patch or an archive that could reach anywhere (`git apply`, `git am`,
9
+ * `patch`, `Expand-Archive`) is refused there outright. Plain Node only: the hook runs it.
10
+ */
11
+ import { FIND_WRITES, GIT_TREE_WRITES, programAt, segmentsOf, TREE_WRITES, wordPaths, } from './approval-writes.js';
12
+ import { programName } from './command-parts.js';
13
+ import { subcommandAt } from './git-words.js';
14
+ /**
15
+ * How far above `prototype/versions` a path lies: 1 for `prototype`, 2 and more for the folders
16
+ * above (`.`, `..`, `/`); nothing when it holds no records. The records' folder is the one below
17
+ * the shell's folder, or the one the shell's folder lies in.
18
+ */
19
+ function heightAbove(path, cwd) {
20
+ const { base, segments, could } = segmentsOf(path, cwd);
21
+ const lower = base.map((segment) => segment.toLowerCase());
22
+ const at = lower.findIndex((name, i) => name === 'prototype' && lower[i + 1] === 'versions');
23
+ const folders = [[...base, 'prototype', 'versions']];
24
+ if (at >= 0)
25
+ folders.push(base.slice(0, at + 2));
26
+ if (lower.at(-1) === 'prototype')
27
+ folders.push([...base, 'versions']);
28
+ const heights = folders
29
+ .filter((folder) => segments.length < folder.length &&
30
+ segments.every((_, index) => could(index, folder[index])))
31
+ .map((folder) => folder.length - segments.length);
32
+ return heights.length ? Math.max(...heights) : undefined;
33
+ }
34
+ /** `tar` extracts: `-x…` anywhere, `x…` bundled as its first word, `--extract`, `--get`. */
35
+ const tarExtracts = (rest) => /^[a-zA-Z]*x[a-zA-Z]*$/.test(rest[0] ?? '') ||
36
+ rest.some((word) => /^(?:-[a-zA-Z]*x[a-zA-Z]*|--extract|--get)$/.test(word));
37
+ /** The part writes the paths it names: a writing program, git or find writing, `tar -x`. */
38
+ function writesPaths(name, words, at) {
39
+ const rest = words.slice(at + 1);
40
+ if (TREE_WRITES.has(name))
41
+ return true;
42
+ if (name === 'find')
43
+ return rest.some((word) => FIND_WRITES.test(word));
44
+ if (name === 'sed' || name === 'perl')
45
+ return rest.some((word) => /^(?:-[a-zA-Z]*i|--in-place)/.test(word));
46
+ if (name === 'git')
47
+ return GIT_TREE_WRITES.has(subcommandAt(words, at + 1)?.name ?? '');
48
+ if (name === 'tar')
49
+ return tarExtracts(rest);
50
+ if (name === '7z')
51
+ return /^[ex]$/i.test(rest[0] ?? '');
52
+ return name === 'unzip';
53
+ }
54
+ /** An archive unpacked into the shell's folder: `tar -x` without `-C`, `unzip` without `-d`. */
55
+ function unpacksHere(name, rest) {
56
+ if (name === 'tar')
57
+ return tarExtracts(rest) && !rest.some((word) => /^(?:-[a-zA-Z]*C|--directory)/.test(word));
58
+ if (name === '7z')
59
+ return /^[ex]$/i.test(rest[0] ?? '') && !rest.some((w) => /^-o/.test(w));
60
+ // `unzip -l`, `-t`, `-v` and `-Z` list or test, writing nothing.
61
+ return name === 'unzip' && !rest.some((word) => /^-(?:[a-zA-Z]*[ltvZ]|d)/.test(word));
62
+ }
63
+ /** A patch or an archive whose own contents say where it writes. */
64
+ function writesAnywhere(name, words, at) {
65
+ if (name === 'patch' || name === 'expand-archive')
66
+ return true;
67
+ if (name !== 'git')
68
+ return false;
69
+ const sub = subcommandAt(words, at + 1);
70
+ if (sub?.name === 'am')
71
+ return true;
72
+ // `git apply --check` (or `--stat`, `--numstat`, `--summary`) only reads the patch.
73
+ return (sub?.name === 'apply' &&
74
+ !words.slice(sub.at + 1).some((word) => /^--(?:check|stat|numstat|summary)$/.test(word)));
75
+ }
76
+ /** A single file copied in: `cp`, `copy` or `Copy-Item`, nothing recursive. */
77
+ function copiesOneFile(name, rest) {
78
+ if (name === 'cp')
79
+ return !rest.some((word) => /^(?:-[a-zA-Z]*[rRa]|--(?:recursive|archive))/.test(word));
80
+ if (['copy', 'copy-item', 'cpi'].includes(name))
81
+ return !rest.some((word) => /^-rec/i.test(word));
82
+ return false;
83
+ }
84
+ /** True when a part writes into, or is aimed at, a folder that holds the approval records. */
85
+ export function folderWrite(words, cwd) {
86
+ const at = programAt(words);
87
+ const name = programName(words[at] ?? '');
88
+ const rest = words.slice(at + 1);
89
+ if (writesAnywhere(name, words, at))
90
+ return true;
91
+ if (unpacksHere(name, rest))
92
+ return true;
93
+ if (!writesPaths(name, words, at))
94
+ return false;
95
+ const single = copiesOneFile(name, rest);
96
+ return rest.some((word) => wordPaths(word).some((path) => {
97
+ const height = heightAbove(path, cwd);
98
+ return height !== undefined && (height > 1 || !single);
99
+ }));
100
+ }
101
+ /** A write after `cd` (or `pushd`, `Set-Location`) in the same command: its folder is unknown. */
102
+ const MOVES_FOLDER = new Set([
103
+ 'cd',
104
+ 'pushd',
105
+ 'popd',
106
+ 'set-location',
107
+ 'sl',
108
+ 'push-location',
109
+ 'chdir',
110
+ ]);
111
+ /**
112
+ * What a design turn's command could write that the parse cannot place, for the person's card:
113
+ * a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x`, and
114
+ * `7z x … -o…` (its folder is fused to the option).
115
+ */
116
+ export function folderUnsure(parts) {
117
+ let moved = false;
118
+ return parts.some((words) => {
119
+ const at = programAt(words);
120
+ const name = programName(words[at] ?? '');
121
+ const rest = words.slice(at + 1);
122
+ if (MOVES_FOLDER.has(name))
123
+ moved = true;
124
+ if (name === 'bsdtar')
125
+ return tarExtracts(rest);
126
+ if (name === '7z')
127
+ return /^[ex]$/i.test(rest[0] ?? '');
128
+ if (!writesPaths(name, words, at) && !writesAnywhere(name, words, at))
129
+ return false;
130
+ return moved || rest.some((word) => /\$(?!\()\{?\w/.test(word));
131
+ });
132
+ }
133
+ /** A word that names a folder holding the records (a pipe's source, for the fallback). */
134
+ export const holdsRecords = (word, cwd) => wordPaths(word).some((path) => heightAbove(path, cwd) !== undefined);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The approval records' fallbacks, for what one part's words cannot show. A pipe that hands a
3
+ * folder holding the records to a program that writes what it is given (`gci -r prototype |
4
+ * Set-Content`, `ls prototype | xargs rm`) is refused. A command whose text names both folders
5
+ * and looks like a write (a writing program, or a redirect to a path that names a folder, a
6
+ * variable or a pattern) is refused when any of its parts is more than a read, and sent to the
7
+ * card when every part only reads (`cd prototype; echo x > versions/a`). Plain Node only.
8
+ */
9
+ import { type Shell } from './command-parts.ts';
10
+ /** What the approval fallbacks say of a command: refuse, ask the person, or nothing. */
11
+ export declare function approvalText(command: string, shell: Shell, cwd: string, folders?: boolean): 'deny' | 'ask' | undefined;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The approval records' fallbacks, for what one part's words cannot show. A pipe that hands a
3
+ * folder holding the records to a program that writes what it is given (`gci -r prototype |
4
+ * Set-Content`, `ls prototype | xargs rm`) is refused. A command whose text names both folders
5
+ * and looks like a write (a writing program, or a redirect to a path that names a folder, a
6
+ * variable or a pattern) is refused when any of its parts is more than a read, and sent to the
7
+ * card when every part only reads (`cd prototype; echo x > versions/a`). Plain Node only.
8
+ */
9
+ import { folderUnsure, holdsRecords } from './approval-folders.js';
10
+ import { names, onlyReads, programAt, TREE_WRITES } from './approval-writes.js';
11
+ import { commandParts, partWords, programName } from './command-parts.js';
12
+ /** Programs that take the paths to write from a pipe: item cmdlets, `xargs`. */
13
+ const PIPED = new Set([...TREE_WRITES].filter((name) => !/^(?:tee|tee-object|out-file)$/.test(name)));
14
+ const EACH = new Set(['foreach-object', 'foreach', '%']);
15
+ /** A pipe's stage that writes what it is given: `sed -i`, a `%` block holding a writer. */
16
+ function pipeWriter(words) {
17
+ const at = programAt(words);
18
+ const name = programName(words[at] ?? '');
19
+ const rest = words.slice(at + 1);
20
+ if (name === 'sed')
21
+ return rest.some((word) => /^(?:-[a-zA-Z]*i|--in-place)/.test(word));
22
+ if (EACH.has(name))
23
+ return rest.some((word) => PIPED.has(programName(word.replace(/^[{(;]+/, ''))));
24
+ return PIPED.has(name);
25
+ }
26
+ /** The shell's folder named where a part's words cannot read it: `(Get-Location)`, `(pwd)`. */
27
+ const HERE = /\((?:get-location|gl|pwd)\)|\$\((?:pwd|get-location)\)/i;
28
+ /** A pipe from a folder holding the records into a program that writes what it is given. */
29
+ function pipedWrite(command, cwd, folders) {
30
+ return command.split(/\r?\n|;|&&|\|\|/).some((statement) => {
31
+ const stages = statement.split(/(?<!\|)\|(?!\|)/).map((stage) => partWords(stage));
32
+ return stages.some((words, index) => index > 0 &&
33
+ pipeWriter(words) &&
34
+ stages
35
+ .slice(0, index)
36
+ .some((earlier) => earlier.some((w) => names(w, cwd) || (folders && holdsRecords(w, cwd)))));
37
+ });
38
+ }
39
+ const PROTOTYPE = /(?<![\w.-])prototype(?![\w-])/i;
40
+ const VERSIONS = /(?<![\w.-])versions(?![\w.-])/i;
41
+ /** A redirect whose target names a folder, a variable or a pattern (not `/tmp/x`, `out.json`). */
42
+ const REDIRECT = /(?<![-=<>])>>?\|?(?![&=>])\s*(?:\S*(?:prototype|versions)|[$`*?{[%~])/i;
43
+ const WRITERS = new RegExp(`(?<![\\w.-])(?:${[
44
+ 'cp|mv|tee|dd|install|ln|rsync|touch|truncate|mkdir|rm|rmdir|unlink|tar|unzip|7z|patch',
45
+ 'perl|node|deno|bun|python[\\d.]*|py|ruby|php|copy|move|ren|rename|del|erase',
46
+ 'xcopy|robocopy|set-content|add-content|out-file|new-item|copy-item|move-item|rename-item',
47
+ 'remove-item|tee-object|sc|ac|ni|cpi|mi|rni|ri|checkout|restore|apply|am|stash|reset',
48
+ 'clean|switch|merge|pull|cherry-pick|revert|rebase|read-tree|checkout-index|update-index',
49
+ 'write(?:all|file)\\w*|append\\w*',
50
+ ].join('|')})(?![\\w-])|\\[(?:system\\.)?io\\.|(?<![\\w.-])(?:sed|perl)\\s[^|;&]*?\\s(?:-[a-zA-Z]*i|--in-place)`, 'i');
51
+ /** The text names both folders and looks like a write, its quotes and escapes taken out too. */
52
+ function looksLikeWrite(command) {
53
+ const joined = command.replace(/[\\`^]\r?\n/g, '');
54
+ const plain = joined.replace(/['"`^]/g, '').replace(/\\(?=[\w.])/g, '');
55
+ return [joined, plain].some((text) => PROTOTYPE.test(text) && VERSIONS.test(text) && (REDIRECT.test(text) || WRITERS.test(text)));
56
+ }
57
+ /** What the approval fallbacks say of a command: refuse, ask the person, or nothing. */
58
+ export function approvalText(command, shell, cwd, folders = false) {
59
+ if (pipedWrite(command, cwd, folders))
60
+ return 'deny';
61
+ if (folders && HERE.test(command) && WRITERS.test(command))
62
+ return 'deny';
63
+ const parts = commandParts(command, shell).map((part) => partWords(part));
64
+ if (looksLikeWrite(command))
65
+ return parts.every((words) => onlyReads(words)) ? 'ask' : 'deny';
66
+ // What a design turn writes where the parse cannot place it: the person's card.
67
+ if (folders && folderUnsure(parts))
68
+ return 'ask';
69
+ }
@@ -0,0 +1,32 @@
1
+ /** `find`'s actions that write, delete or run something. */
2
+ export declare const FIND_WRITES: RegExp;
3
+ /** git's subcommands that only read. */
4
+ export declare const GIT_READS: Set<string>;
5
+ /** git's subcommands that write the working tree's files. */
6
+ export declare const GIT_TREE_WRITES: Set<string>;
7
+ /** Programs that write, move or delete the paths they name (and PowerShell's aliases for them). */
8
+ export declare const TREE_WRITES: Set<string>;
9
+ /** A path's segments read against `cwd`; the first `literal` are the shell folder's own. */
10
+ export declare function segmentsOf(path: string, cwd: string): {
11
+ base: string[];
12
+ segments: string[];
13
+ could: (index: number, name: string) => boolean;
14
+ };
15
+ /** A path that is, or lies in, `prototype/versions`. */
16
+ export declare function inVersions(path: string, cwd: string): boolean;
17
+ /**
18
+ * A word's paths: the word, what follows an `=`, `:` or `,` in it (`HEAD:prototype/…`,
19
+ * `--target=…`), and each of its own words (a script's `w file`); an option is read only after
20
+ * its `=`.
21
+ */
22
+ export declare function wordPaths(word: string): string[];
23
+ export declare const names: (word: string, cwd: string) => boolean;
24
+ /** The index of the part's program: after `NAME=value` settings and runners (`env`, `xargs`). */
25
+ export declare function programAt(words: string[]): number;
26
+ /** The part only reads the paths it names: a read program, with none of its writing options. */
27
+ export declare function onlyReads(words: string[]): boolean;
28
+ /**
29
+ * True when a part's words could write into `prototype/versions` itself; a write aimed at a
30
+ * folder holding it is approval-folders.ts's, on the turns that keep that rule.
31
+ */
32
+ export declare function approvalWrite(words: string[], cwd: string): boolean;