@cmodjs/core 4.3.1 → 4.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/commands.md CHANGED
@@ -65,13 +65,12 @@ Runs every check this machine can run on the mod at `path` (default: the current
65
65
  8. Writes the `cmod` dependency in `.claude-plugin/plugin.json` as `>=` the version of the `@cmodjs/core` the mod installed, such as `>=4.0.0`, so every newer cmod runs the mod. A mod still on `@cmodjs/core` 3 keeps its own range ([dependencies.md](dependencies.md#call-the-methods-mod-dependencies)).
66
66
  9. Checks its imports.
67
67
  10. Looks for prebuilt binaries outside `cli/`.
68
- 11. Bundles the hooks module as `cmod publish` does, and names each reason a bundle fails.
69
- 12. Validates it with Claude Code, `claude plugin validate --strict`.
70
- 13. Compiles it against Claude Code's API with `tsc`, with `tsconfig.json`, and then with `tests/tsconfig.json` when it exists. `cmod new` writes both: the root config leaves Bun out of `src/`, which runs inside Claude Code, and the tests config adds `bun-types`, so a test can run a real program with `Bun.spawn` or read files with `node:fs`. When `.claude-plugin/types/` is missing, as in a fresh clone or in CI, Claude Code writes it first: cmod loads the mod in one `claude -p` run with a config folder of its own and no model to reach, so the run sends nothing.
71
- 14. Lints it with `oxlint`.
72
- 15. Runs, with `bun test`, every test file that does not import `claude-code/testing`. When `bunfig.toml` names a `[test]` `root`, it runs only the test files under that folder, as `bun test` does.
73
- 16. Runs, with `claude plugin test`, the test files that import `claude-code/testing`. It skips this when none does.
74
- 17. Checks its name against other plugins. Only a project plugin, in `.claude/skills/<name>/` of a repository, runs this check: it fails when an installed or linked plugin has the same name and hides the project plugin. Any other mod passes it at once.
68
+ 11. Builds the release in a temporary folder as `cmod publish` builds it, with its `"files"` list and its bundled hooks module, and validates the release with Claude Code, `claude plugin validate --strict`. So it fails on a path `plugin.json` names that `"files"` leaves out, a `"files"` path that matches no file in the mod, and each reason a bundle fails, and prints every line the validator writes. Then it deletes the folder.
69
+ 12. Compiles it against Claude Code's API with `tsc`, with `tsconfig.json`, and then with `tests/tsconfig.json` when it exists. `cmod new` writes both: the root config leaves Bun out of `src/`, which runs inside Claude Code, and the tests config adds `bun-types`, so a test can run a real program with `Bun.spawn` or read files with `node:fs`. When `.claude-plugin/types/` is missing, as in a fresh clone or in CI, Claude Code writes it first: cmod loads the mod in one `claude -p` run with a config folder of its own and no model to reach, so the run sends nothing.
70
+ 13. Lints it with `oxlint`.
71
+ 14. Runs, with `bun test`, every test file that does not import `claude-code/testing`. When `bunfig.toml` names a `[test]` `root`, it runs only the test files under that folder, as `bun test` does.
72
+ 15. Runs, with `claude plugin test`, the test files that import `claude-code/testing`. It skips this when none does.
73
+ 16. Checks its name against other plugins. Only a project plugin, in `.claude/skills/<name>/` of a repository, runs this check: it fails when an installed or linked plugin has the same name and hides the project plugin. Any other mod passes it at once.
75
74
 
76
75
  `cmod check` fetches `tsc` 7.0.2 and `oxlint` 1.86.0 into the cmod store the first time. It ends with a count of passed, failed, and skipped checks, and exits 1 when one failed.
77
76
 
@@ -105,9 +104,9 @@ cmod publish [path] [--dry-run]
105
104
 
106
105
  Releases the mod at `path` (default: the current folder) at the version in its `plugin.json`. It refuses a `plugin.json` whose `userConfig` differs from the options `defineMod` declares, and says to run `cmod check` and commit `.claude-plugin/plugin.json`.
107
106
 
108
- 1. Builds the release from the committed files, leaving out `cli/`, `.github/`, and `.claude/`. A `"files"` list in `package.json` limits the release to the paths it lists, plus the folders of the install and uninstall steps, `.claude-plugin/`, `package.json`, `tsconfig.json`, the README, the license, and `CHANGELOG.md`, the way `npm publish` reads it. `tsconfig.json` holds the JSX settings the bundle in step 2 needs. List every folder the hooks module imports from, such as `"files": ["hooks", "src", "skills"]`, because the bundle in step 2 is built from the release.
107
+ 1. Builds the release from the files git does not ignore, leaving out `cli/`, `.github/`, and `.claude/`. A `"files"` list in `package.json` limits the release to the paths it lists, plus the folders of the install and uninstall steps, `.claude-plugin/`, `package.json`, `tsconfig.json`, the README, the license, and `CHANGELOG.md`, the way `npm publish` reads it. `tsconfig.json` holds the JSX settings the bundle in step 2 needs. List every folder the hooks module imports from, such as `"files": ["hooks", "src", "skills"]`, because the bundle in step 2 is built from the release.
109
108
  2. Bundles the hooks module that `hooks/hooks.json` names, with the mod's source and packages, into one readable `.js` file, writes each control character in it as a `\u` escape, and points `hooks/hooks.json` at it. Anthropic's plugin directory reads a repository without installing its packages, so it can follow a mod only when all its code is in one file. Without `"approve": true` in `package.json` `"cmod".permissions`, the bundle leaves out the code that allows and asks on Claude Code's permission check ([permissions.md](permissions.md)).
110
- 3. Checks the release with `claude plugin validate --strict`, and stops with the validator's message when it fails.
109
+ 3. Checks the release's `.claude-plugin/plugin.json`, and its `.claude-plugin/marketplace.json` when it has one, with `claude plugin validate --strict`, and stops with every line the validator writes when it fails. `cmod check` builds and validates the release the same way, so it fails first.
111
110
  4. Commits the release as the `release` branch, and builds the release archive from that commit.
112
111
  5. Builds the program `cli/` declares, and writes `SHA256SUMS` for every file of the release.
113
112
  6. Writes `.claude-plugin/marketplace.json`, listing the archive and the cmod plugin. The cmod entry points at the `release` branch of `heyJordanParker/cmod`, so the mod's `"cmod"` dependency resolves in this marketplace and follows each cmod release with no new publish of the mod.
@@ -118,19 +117,19 @@ The release keeps `package.json`, so Claude Code still installs the mod's packag
118
117
 
119
118
  It needs, and refuses to start without:
120
119
 
121
- - the mod's folder as the root of a git repository with at least one commit, because `git archive` builds from `HEAD`
120
+ - the mod's folder as the root of a git repository with at least one commit, because the release is committed as the `release` branch
122
121
  - a `## [<version>]` section with notes in the committed `CHANGELOG.md`
123
122
  - `node_modules` in the mod's folder, from `bun install`, when the hooks module imports a package
124
123
  - a `register` declared as a function in the hooks module, as `cmod new` writes it, because the validator refuses a bundled `register` that is not one
125
124
  - the `claude` command, which validates the release
126
125
  - an `origin` remote on GitHub
127
126
  - a `package.json` with no dependency on a `file:` or `link:` path, which no user has
128
- - a `"files"` list, when `package.json` has one, whose every path matches a committed file
127
+ - a `"files"` list, when `package.json` has one, whose every path matches a file in the mod
129
128
  - a `"program"` in the `cmod` key of `package.json` that names the program `cli/` declares, when `cli/` declares one
130
129
  - a `cmod` dependency in `.claude-plugin/plugin.json` of `>=` the `@cmodjs/core` the mod bundles, which `cmod check` writes
131
130
  - for a real publish, a working tree with no uncommitted changes, no `v<version>` or `<name>--v<version>` tag yet, a `git push` to `origin` that succeeds, and the `gh` command, which creates the GitHub release
132
131
 
133
- `--dry-run` builds everything into a temporary folder, and pushes nothing. It writes `marketplace.json` there too, so the working tree stays as it was. It allows uncommitted changes and an existing tag, and builds from the last commit. It prints the folder that holds the release, so you can read what the directory will read.
132
+ `--dry-run` builds everything into a temporary folder, and pushes nothing. It writes `marketplace.json` there too, so the working tree stays as it was. It allows uncommitted changes and an existing tag, and builds from the working tree, uncommitted changes included. It prints the folder that holds the release, so you can read what the directory will read.
134
133
 
135
134
  ## Install mods
136
135
 
package/docs/testing.md CHANGED
@@ -213,6 +213,8 @@ A `before` listener on the current session answers what `raise` asks, such as `t
213
213
 
214
214
  - `shown.page.lines()` draws the page the mod shows in the Sidebar now, and `shown.pane.lines()` the pane it shows now, and each returns its rows of text. Each rejects when the mod shows none, such as `No pane of notes shows. Open one with pane.open(), from a slash command, a hotkey, or setup.` A page gets `params`, `isFocused`, and `columns`, 80 unless `lines({ columns })` gives another. A pane gets `params`, `title`, `isFocused`, true once an `open` or `toggle` with `{ focus: true }` opened it, `bodyColumns`, which is the `columns` that `lines({ columns })` gives, else the pane's own `columns`, else 80, `placement: 'dock'`, `scroll: { offset: 0, bodyRows: 24 }`, and `view: {}`. `shown.page.id` and `shown.pane.id` name what shows, and `params` holds its params.
215
215
  - A `Markdown` element in the mod's pages, panes, and widgets draws through the mod's own markdown styles, as it does in a session. Other mods' styles are not drawn.
216
+ - A key in a page or widget draws as the cmod plugin gives it to Claude Code: `<mod>/<page>:<key>` in a page, `<mod>/<widget>:<key>` in a widget, and `<mod>/markdown:<scope>:<block>:<key>` in what a markdown style draws, where `<scope>` is the drawn key of the `Markdown` element that holds the block, or its place among the `Markdown` elements without a key, and `<block>` is the block's number in that element's markdown, each from `0`. In the mod's own pane, a style's key draws as `<scope>:<block>:<key>`, and in a reply as `<block>:<key>`. `press`, `input`, and `select` take the key the mod wrote, and a key two blocks share reaches the first.
217
+ - Claude Code refuses a whole tree in which two `Input`, `Select`, `Markdown`, `Client`, `Raster`, or `Image` elements have one key, anywhere in it, and a refused Sidebar draws blank for the session. So drawing a page, a pane, a widget area, or a style that does it rejects with Claude Code's own text, such as `cmod: returned a tree Pane refuses: Markdown "notes/all:item-text:0" is drawn twice; each takes its own key`. Elements of different types, such as a `Box` and a `Markdown`, may share a key.
216
218
  - A `Button` draws as Claude Code draws it: `[ Save ]`, or `1: Save` when it is `plain` with a `hotkey`, or `Save` when it is `plain` alone. Borders and colors are not drawn.
217
219
  - `lines(area)` draws the mod's widgets in that area, in the rows the person would see, and returns them. A new widget is in the first row of its first area. A layout given in `files` as `/test/home/.local/share/cmod/widgets.json` places the widgets another way. `{ columns }` sets the row's width, 80 by default. `lines(TurnEnd)` draws under the last turn that ended, and rejects when none has: end one with `tested.endTurn()` first.
218
220
  - `lines(kind, props, requestId?)` draws the mod's style of that kind with `props` and returns its rows. `Default` draws a plain listing of the props it gets, so a test sees what the style changed. Draw `Reply` with a reply's `text` to test a markdown style. Draws that pass one `requestId` grow one streamed reply.
package/docs/ui.md CHANGED
@@ -382,9 +382,11 @@ Each kind of markdown block of a reply is a kind of its own. `ui/markdown.js` ex
382
382
  - `ThematicBreak`: a `---` line.
383
383
  - `HtmlBlock`: an HTML block, with `value`.
384
384
 
385
- Every block's props hold `text`, its plain text, one line per list item, table row, or quoted line, and `source`, its markdown. `Default` draws the block as Claude Code would, and `<Default source="…" />` draws other markdown in its place. While a reply streams in, Claude Code draws a block that is not finished yet, and the mod draws it once it is.
385
+ Every block's props hold `text`, its plain text, one line per list item, table row, or quoted line, and `source`, its markdown. `Default` draws the block as Claude Code would, and `<Default source="…" />` draws other markdown in its place. A style may call `Default` once per part, such as once per list item, quoted line, or table cell. In a pane, where the mod draws a `Markdown` element with a `key` through its own styles, the first `Default` takes that key and each later one takes it with `:1`, `:2`, and so on, because Claude Code refuses two `Markdown` elements with one key. While a reply streams in, Claude Code draws a block that is not finished yet, and the mod draws it once it is.
386
386
 
387
- A markdown style draws wherever markdown shows: in Claude's replies and in every `Markdown` element any mod or cmod draws, in panes, pages, widgets, the Dashboard, Settings, and changelogs. A `Markdown` element goes through the styles of the mod that draws it first, then through each other mod's, in the order the mods added their first markdown style. A mod that removes its last markdown style and adds one again moves to the end. Another mod's style shows as soon as that mod has drawn the block, and Claude Code's drawing shows until then.
387
+ A markdown style draws wherever markdown shows: in Claude's replies and in every `Markdown` element any mod or cmod draws, in panes, pages, widgets, the Dashboard, Settings, and changelogs. A `Markdown` element goes through the styles of the mod that draws it first, then through each other mod's, in the order the mods added their first markdown style. A mod that removes its last markdown style and adds one again moves to the end. Another mod's style shows as soon as that mod has drawn the block, and Claude Code's drawing shows until then. When that mod does not answer, Claude Code's drawing stays, and cmod reports `The markdown style of <mod> drew nothing` to the Log, with the reason.
388
+
389
+ Claude Code refuses a whole drawing in which two `Input`, `Select`, `Markdown`, `Client`, `Raster`, or `Image` elements share a key. So cmod puts each block's place in front of every key its style draws, and the keys a style draws need be unique only within the one block it draws, as a component's keys are in React. The place is the block's number in its markdown, from `0`, after the `key` of the `Markdown` element that holds it, or that element's number among the ones drawn without a key. A block that draws again in its place keeps its keys, so Claude Code keeps what the person typed in its `Input`.
388
390
 
389
391
  ```tsx
390
392
  import type { RenderElement } from 'claude-code'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmodjs/core",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "Build Claude Code mods: hooks, panes, permissions, checks, and an install that just works.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/records.d.ts CHANGED
@@ -103,7 +103,7 @@ export type Preferences = {
103
103
  };
104
104
  export declare function parsePreferences(value: unknown, path: string): Preferences;
105
105
  export declare function parseConsent(value: unknown, path: string): Record<string, string[]>;
106
- export declare const coreVersion = "4.3.1";
106
+ export declare const coreVersion = "4.3.3";
107
107
  export declare function hotkeyCommand(mod: string, hotkey: string): string;
108
108
  export declare function hotkeyBindings(mod: string, hotkeys: Hotkeys | undefined): Record<string, string>;
109
109
  export declare function boundCombos(keybindings: unknown): Map<string, string>;
package/records.js CHANGED
@@ -294,7 +294,7 @@ function readHotkeys(hotkeys) {
294
294
  throw new Error(`package.json "cmod.hotkeys" is not a map of hotkeys to their title and optional default combo. ${fix}`);
295
295
  return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys) };
296
296
  }
297
- export const coreVersion = '4.3.1';
297
+ export const coreVersion = '4.3.3';
298
298
  export function hotkeyCommand(mod, hotkey) {
299
299
  return `${mod}--${hotkey}`;
300
300
  }
@@ -751,10 +751,10 @@ async function createMod(definition, runtime) {
751
751
  let hasEarlierPrompts = true;
752
752
  let agentType;
753
753
  let parts;
754
- const borrowed = (styler, cached, input) => {
754
+ const borrowed = (styler, cached, input, scope) => {
755
755
  const name = `The markdown style of ${styler}`;
756
756
  void parts?.fill(styler, cached, input, name)?.then(() => claude.ui.invalidate('ui.render'));
757
- return parts?.element(styler, cached, `${styler}/markdown:`, name, `markdown:${styler}`);
757
+ return parts?.element(styler, cached, `${styler}/markdown:${scope}:`, name, `markdown:${styler}`);
758
758
  };
759
759
  const area = createUi({ name: definition.name, claude, router, report, announce, mod: () => mod, borrowed, nextDraw: runtime.nextDraw });
760
760
  const askParent = async () => {
package/runtime/parts.js CHANGED
@@ -27,7 +27,7 @@ export function drawnParts({ claude, report, press }) {
27
27
  claude.cmod
28
28
  .call({ to: mod, method: partMethods.draw, input })
29
29
  .then((data) => keep((data ?? null)), (error) => {
30
- claude.ui.log(`cmod: ${name} drew nothing: ${messageOf(error)}`, { to: 'debug' });
30
+ report(`draw:${mod}`, `${name} drew nothing`, error);
31
31
  keep(drawn.get(key)?.data ?? null, messageOf(error));
32
32
  })
33
33
  .finally(() => drawing.delete(key));
package/runtime/ui.d.ts CHANGED
@@ -47,7 +47,7 @@ export type PartDraw = {
47
47
  } & StyledAt);
48
48
  export type BorrowedMarkdown = (mod: string, cached: string, input: {
49
49
  readonly markdown: string;
50
- } & StyledAt) => RenderElement | undefined;
50
+ } & StyledAt, scope: string) => RenderElement | undefined;
51
51
  export declare function viewportColumns(e: Frozen<Args<'ui.render'>>): number;
52
52
  export declare function styledAt(e: Frozen<Args<'ui.render'>>, columns?: number): StyledAt;
53
53
  export type PartPress = {
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/runtime/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAgB,aAAa,EAAE,MAAM,aAAa,CAAA;AACzG,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,EAAW,KAAK,IAAI,EAAmC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGrG,OAAO,EAAwG,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC5K,OAAO,EAA8C,KAAK,QAAQ,EAAkB,MAAM,iBAAiB,CAAA;AAG3G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,WAAW;aACtB,IAAI,EAAE,YAAY;aAClB,IAAI,EAAE,WAAW;aACjB,KAAK,EAAE,YAAY;aACnB,KAAK,EAAE,YAAY;aACnB,OAAO,EAAE,mBAAmB;aAC5B,OAAO,EAAE,sBAAsB;CACvB,CAAA;AAEV,eAAO,MAAM,UAAU,yEAAyE,CAAA;AAEhG,MAAM,MAAM,SAAS,GA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{ TurnEnd } from '../ui/areas.js';
3
- import { Box, drawWith, elementData, Markdown, Text } from '../ui/elements.js';
3
+ import { Box, drawKeyed, drawWith, elementData, Markdown, Text } from '../ui/elements.js';
4
4
  import { checkPane, checkPart, sizeKeys } from '../ui/panes.js';
5
5
  import { componentOf, nameOf } from '../ui/styles.js';
6
6
  import { messageOf } from '../utils/text.js';
@@ -50,7 +50,7 @@ async function drawComponent(table, draw, drawDefault) {
50
50
  let first;
51
51
  try {
52
52
  first = drawWith(table, () => draw(({ children, ...props }) => {
53
- const drawing = Box({});
53
+ const drawing = table.Box({});
54
54
  calls.push({ given: props, drawing });
55
55
  return drawing;
56
56
  }));
@@ -240,11 +240,11 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
240
240
  };
241
241
  };
242
242
  const renderOf = (type) => markdownRenders.get(type);
243
- const drawnBlock = (piece, at, drawClaudes, table) => {
243
+ const drawnBlock = (piece, at, drawClaudes, keyPrefix, table) => {
244
244
  if ('text' in piece)
245
245
  return drawClaudes(piece.text);
246
246
  const { render, props: block } = piece;
247
- const draw = () => render.Component({ ...block, ...at, Default: ({ source = block.source }) => drawClaudes(source) });
247
+ const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }) => drawClaudes(source) }));
248
248
  try {
249
249
  return table === undefined ? draw() : drawWith(table, draw);
250
250
  }
@@ -253,12 +253,15 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
253
253
  return drawClaudes(block.source);
254
254
  }
255
255
  };
256
- const othersFrom = (table, at, from) => (props) => {
256
+ const othersFrom = (table, at, from, unkeyedScope) => (props) => {
257
+ if (from >= stylers.length)
258
+ return table.Markdown(props);
259
+ const scope = props.key ?? unkeyedScope();
257
260
  for (const [index, styler] of stylers.entries()) {
258
261
  if (index < from)
259
262
  continue;
260
263
  const cached = `${stylersSeen}\u0000${at.surface}\u0000${at.columns}\u0000${props.text}`;
261
- const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }), othersFrom(table, at, index + 1));
264
+ const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), othersFrom(table, at, index + 1, unkeyedScope));
262
265
  if (drawn !== undefined)
263
266
  return drawn;
264
267
  }
@@ -266,14 +269,22 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
266
269
  };
267
270
  const markdownIn = (table, at) => {
268
271
  const reader = read;
269
- const others = othersFrom(table, at, 0);
272
+ let unkeyed = 0;
273
+ const unkeyedScope = () => String(unkeyed++);
274
+ const others = othersFrom(table, at, 0, unkeyedScope);
270
275
  if (reader === undefined)
271
276
  return stylers.length === 0 ? undefined : others;
272
277
  return (props) => {
273
278
  const pieces = reader(props.text, renderOf);
274
279
  if (pieces.every((piece) => 'text' in piece))
275
280
  return others(props);
276
- const drawings = pieces.map((piece) => drawnBlock(piece, at, (text) => others({ ...props, text }), table));
281
+ const scope = props.key ?? unkeyedScope();
282
+ let drawn = 0;
283
+ const drawClaudes = (text) => {
284
+ const index = drawn++;
285
+ return others(index === 0 || props.key === undefined ? { ...props, text } : { ...props, text, key: `${props.key}:${index}` });
286
+ };
287
+ const drawings = pieces.map((piece, index) => drawnBlock(piece, at, drawClaudes, `${scope}:${index}:`, table));
277
288
  return drawPieces(drawings.map((drawing) => ({ drawing, isClaudesRow: false })), 'pane');
278
289
  };
279
290
  };
@@ -281,7 +292,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
281
292
  const pieces = read === undefined ? [] : read(text, renderOf);
282
293
  if (pieces.every((piece) => 'text' in piece))
283
294
  return Markdown({ text });
284
- return drawPieces(pieces.map((piece) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source })), isClaudesRow: false })), 'pane');
295
+ return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source }), `${index}:`), isClaudesRow: false })), 'pane');
285
296
  };
286
297
  const routeMarkdown = (createReader) => {
287
298
  if (read !== undefined)
@@ -300,7 +311,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
300
311
  if ('text' in piece)
301
312
  return { drawing: await drawClaudes(piece.text, index === 0), isClaudesRow: true };
302
313
  const { render, props: block } = piece;
303
- const component = await drawComponent(table, (Default) => render.Component({ ...block, ...styledAt(e), id: e.requestId, Default }), ({ source = block.source }, isClaudesRow) => drawClaudes(source, index === 0 && isClaudesRow));
314
+ const component = await drawComponent(table, (Default) => drawKeyed(`${index}:`, () => render.Component({ ...block, ...styledAt(e), id: e.requestId, Default })), ({ source = block.source }, isClaudesRow) => drawClaudes(source, index === 0 && isClaudesRow));
304
315
  if (!('failure' in component))
305
316
  return component;
306
317
  render.log(component.failure);
package/src/records.ts CHANGED
@@ -339,7 +339,7 @@ function readHotkeys(hotkeys: unknown): Steps {
339
339
  return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
340
340
  }
341
341
 
342
- export const coreVersion = '4.3.1'
342
+ export const coreVersion = '4.3.3'
343
343
 
344
344
  export function hotkeyCommand(mod: string, hotkey: string): string {
345
345
  return `${mod}--${hotkey}`
@@ -804,10 +804,10 @@ async function createMod<State extends object, Declared extends Options>(definit
804
804
  let hasEarlierPrompts = true
805
805
  let agentType: string | undefined
806
806
  let parts: DrawnParts | undefined
807
- const borrowed: BorrowedMarkdown = (styler, cached, input) => {
807
+ const borrowed: BorrowedMarkdown = (styler, cached, input, scope) => {
808
808
  const name = `The markdown style of ${styler}`
809
809
  void parts?.fill(styler, cached, input, name)?.then(() => claude.ui.invalidate('ui.render'))
810
- return parts?.element(styler, cached, `${styler}/markdown:`, name, `markdown:${styler}`)
810
+ return parts?.element(styler, cached, `${styler}/markdown:${scope}:`, name, `markdown:${styler}`)
811
811
  }
812
812
  const area = createUi<State>({ name: definition.name, claude, router, report, announce, mod: () => mod, borrowed, nextDraw: runtime.nextDraw })
813
813
  const askParent = async (): Promise<string | undefined> => {
@@ -41,7 +41,7 @@ export function drawnParts({ claude, report, press }: { readonly claude: Claude;
41
41
  .then(
42
42
  (data) => keep((data ?? null) as DrawnPart | null),
43
43
  (error: unknown) => {
44
- claude.ui.log(`cmod: ${name} drew nothing: ${messageOf(error)}`, { to: 'debug' })
44
+ report(`draw:${mod}`, `${name} drew nothing`, error)
45
45
  keep(drawn.get(key)?.data ?? null, messageOf(error))
46
46
  },
47
47
  )
package/src/runtime/ui.ts CHANGED
@@ -2,7 +2,7 @@ import type { Args, ElementTable, Frozen, MarkdownProps, PaneOpenArgs, RenderEle
2
2
  import type { Mod, Turn } from '../mod.js'
3
3
  import { isObject } from '../records.js'
4
4
  import { TurnEnd, type Area, type Widget, type WidgetContext, type WidgetInit } from '../ui/areas.js'
5
- import { Box, drawWith, elementData, Markdown, Text, type Handler } from '../ui/elements.js'
5
+ import { Box, drawKeyed, drawWith, elementData, Markdown, Text, type Handler } from '../ui/elements.js'
6
6
  import type { Block, MarkdownPiece, MarkdownReader } from '../ui/markdown.js'
7
7
  import { checkPane, checkPart, sizeKeys, type OpenOptions, type Page, type PageInit, type Pane, type PaneInit, type ScrollOptions, type ScrollTarget } from '../ui/panes.js'
8
8
  import { componentOf, nameOf, type Kind, type Style, type StyledAt, type StyleInit } from '../ui/styles.js'
@@ -37,7 +37,7 @@ export type PartDraw =
37
37
  | { readonly page: string; readonly params: unknown; readonly columns: number; readonly isFocused: boolean }
38
38
  | ({ readonly markdown: string } & StyledAt)
39
39
 
40
- export type BorrowedMarkdown = (mod: string, cached: string, input: { readonly markdown: string } & StyledAt) => RenderElement | undefined
40
+ export type BorrowedMarkdown = (mod: string, cached: string, input: { readonly markdown: string } & StyledAt, scope: string) => RenderElement | undefined
41
41
 
42
42
  const unmeasuredColumns = 80
43
43
 
@@ -109,7 +109,7 @@ async function drawComponent<Given extends object>(
109
109
  try {
110
110
  first = drawWith(table, () =>
111
111
  draw(({ children, ...props }) => {
112
- const drawing = Box({})
112
+ const drawing = table.Box({})
113
113
  calls.push({ given: props as Given, drawing })
114
114
  return drawing
115
115
  }),
@@ -324,10 +324,10 @@ export function createUi<State extends object>({ name, claude, router, report, a
324
324
 
325
325
  const renderOf = (type: string) => markdownRenders.get(type)
326
326
 
327
- const drawnBlock = (piece: MarkdownPiece<MarkdownRender>, at: StyledAt, drawClaudes: (text: string) => RenderElement, table?: ElementTable): RenderElement => {
327
+ const drawnBlock = (piece: MarkdownPiece<MarkdownRender>, at: StyledAt, drawClaudes: (text: string) => RenderElement, keyPrefix: string, table?: ElementTable): RenderElement => {
328
328
  if ('text' in piece) return drawClaudes(piece.text)
329
329
  const { render, props: block } = piece
330
- const draw = () => render.Component({ ...block, ...at, Default: ({ source = block.source }: { readonly source?: string }) => drawClaudes(source) })
330
+ const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }: { readonly source?: string }) => drawClaudes(source) }))
331
331
  try {
332
332
  return table === undefined ? draw() : drawWith(table, draw)
333
333
  } catch (error) {
@@ -337,12 +337,14 @@ export function createUi<State extends object>({ name, claude, router, report, a
337
337
  }
338
338
 
339
339
  const othersFrom =
340
- (table: ElementTable, at: StyledAt, from: number) =>
340
+ (table: ElementTable, at: StyledAt, from: number, unkeyedScope: () => string) =>
341
341
  (props: MarkdownProps): RenderElement => {
342
+ if (from >= stylers.length) return table.Markdown(props)
343
+ const scope = props.key ?? unkeyedScope()
342
344
  for (const [index, styler] of stylers.entries()) {
343
345
  if (index < from) continue
344
346
  const cached = `${stylersSeen}\u0000${at.surface}\u0000${at.columns}\u0000${props.text}`
345
- const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }), othersFrom(table, at, index + 1))
347
+ const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), othersFrom(table, at, index + 1, unkeyedScope))
346
348
  if (drawn !== undefined) return drawn
347
349
  }
348
350
  return table.Markdown(props)
@@ -350,12 +352,20 @@ export function createUi<State extends object>({ name, claude, router, report, a
350
352
 
351
353
  const markdownIn = (table: ElementTable, at: StyledAt) => {
352
354
  const reader = read
353
- const others = othersFrom(table, at, 0)
355
+ let unkeyed = 0
356
+ const unkeyedScope = () => String(unkeyed++)
357
+ const others = othersFrom(table, at, 0, unkeyedScope)
354
358
  if (reader === undefined) return stylers.length === 0 ? undefined : others
355
359
  return (props: MarkdownProps) => {
356
360
  const pieces = reader(props.text, renderOf)
357
361
  if (pieces.every((piece) => 'text' in piece)) return others(props)
358
- const drawings = pieces.map((piece) => drawnBlock(piece, at, (text) => others({ ...props, text }), table))
362
+ const scope = props.key ?? unkeyedScope()
363
+ let drawn = 0
364
+ const drawClaudes = (text: string) => {
365
+ const index = drawn++
366
+ return others(index === 0 || props.key === undefined ? { ...props, text } : { ...props, text, key: `${props.key}:${index}` })
367
+ }
368
+ const drawings = pieces.map((piece, index) => drawnBlock(piece, at, drawClaudes, `${scope}:${index}:`, table))
359
369
  return drawPieces(drawings.map((drawing) => ({ drawing, isClaudesRow: false })), 'pane')
360
370
  }
361
371
  }
@@ -363,7 +373,7 @@ export function createUi<State extends object>({ name, claude, router, report, a
363
373
  const markdownDrawing = (text: string, at: StyledAt): RenderElement => {
364
374
  const pieces = read === undefined ? [] : read(text, renderOf)
365
375
  if (pieces.every((piece) => 'text' in piece)) return Markdown({ text })
366
- return drawPieces(pieces.map((piece) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source })), isClaudesRow: false })), 'pane')
376
+ return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source }), `${index}:`), isClaudesRow: false })), 'pane')
367
377
  }
368
378
 
369
379
  const routeMarkdown = (createReader: () => MarkdownReader) => {
@@ -382,7 +392,7 @@ export function createUi<State extends object>({ name, claude, router, report, a
382
392
  const { render, props: block } = piece
383
393
  const component = await drawComponent<{ readonly source?: string }>(
384
394
  table,
385
- (Default) => render.Component({ ...block, ...styledAt(e), id: e.requestId, Default }),
395
+ (Default) => drawKeyed(`${index}:`, () => render.Component({ ...block, ...styledAt(e), id: e.requestId, Default })),
386
396
  ({ source = block.source }, isClaudesRow) => drawClaudes(source, index === 0 && isClaudesRow),
387
397
  )
388
398
  if (!('failure' in component)) return component
@@ -6,6 +6,8 @@ const boxInsides = new WeakMap<object, Drawn>()
6
6
 
7
7
  const measuredProps = ['width', 'height', 'minWidth', 'minHeight'] as const
8
8
 
9
+ const oncePerKey: ReadonlySet<string> = new Set(['Input', 'Select', 'Markdown', 'Client', 'Raster', 'Image'])
10
+
9
11
  function element(type: string) {
10
12
  return (props: Record<string, unknown>): RenderElement => {
11
13
  const { children, ...rest } = props
@@ -38,17 +40,34 @@ export const elements: ElementTable = {
38
40
  Client: element('Client'),
39
41
  }
40
42
 
41
- export function findElement(node: RenderNode, type: string, key: string): Drawn['props'] | undefined {
42
- if (typeof node === 'string') return undefined
43
- const drawn = insideOf(node)
44
- if (drawn.type === type && (drawn.props['key'] === key || (type === 'Button' && drawn.props['label'] === key))) return drawn.props
45
- for (const child of drawn.children ?? []) {
46
- const found = findElement(child, type, key)
47
- if (found !== undefined) return found
43
+ export function findElement(node: RenderNode, type: string, key: string | ((drawnKey: string) => boolean)): Drawn['props'] | undefined {
44
+ const matches = (drawn: Drawn) => {
45
+ const drawnKey = drawn.props['key']
46
+ if (typeof key !== 'string') return typeof drawnKey === 'string' && key(drawnKey)
47
+ return drawnKey === key || (type === 'Button' && drawn.props['label'] === key)
48
48
  }
49
+ for (const drawn of drawnIn(node)) if (drawn.type === type && matches(drawn)) return drawn.props
49
50
  return undefined
50
51
  }
51
52
 
53
+ export function checkKeys(tree: RenderNode, plugin: string, component: string): void {
54
+ const seen = new Set<string>()
55
+ for (const { type, props } of drawnIn(tree)) {
56
+ const key = props['key']
57
+ if (!oncePerKey.has(type) || typeof key !== 'string') continue
58
+ const drawn = `${type}\u0000${key}`
59
+ if (seen.has(drawn)) throw new Error(`${plugin}: returned a tree ${component} refuses: ${type} "${key}" is drawn twice; each takes its own key`)
60
+ seen.add(drawn)
61
+ }
62
+ }
63
+
64
+ function* drawnIn(node: RenderNode): Generator<Drawn> {
65
+ if (typeof node === 'string') return
66
+ const drawn = insideOf(node)
67
+ yield drawn
68
+ for (const child of drawn.children ?? []) yield* drawnIn(child)
69
+ }
70
+
52
71
  export function rowsOf(node: RenderNode, width: number): string[] {
53
72
  const drawn = typeof node === 'string' ? undefined : insideOf(node)
54
73
  if (drawn?.type === 'Box') return boxRows(drawn, width)
package/src/testing.ts CHANGED
@@ -45,12 +45,12 @@ import { beforeEvents, processEvents, sessionEvents, type AnswerOf, type BeforeE
45
45
  import { ContextEnd } from './session/context/context.js'
46
46
  import { TaskStart } from './session/goal/task.js'
47
47
  import { calledAnswer, fakeClaude, type Fakes, type Shown as ShownByClaude, type TestCall } from './testing/fake-claude.js'
48
- import { elements, findElement, rowsOf } from './testing/fake-elements.js'
48
+ import { checkKeys, elements, findElement, rowsOf } from './testing/fake-elements.js'
49
49
  import { fakeFiles } from './testing/fake-files.js'
50
50
  import { fakeSessions, type FakeSession, type FakeSessions, type MessageDraft, type StartedTask } from './testing/fake-sessions.js'
51
51
  import { listed, messageOf } from './utils/text.js'
52
52
  import { componentOf, type KindProps, type Row, type StyledAt } from './ui/styles.js'
53
- import { areas, TurnEnd as TurnEndArea, type Area } from './ui/areas.js'
53
+ import { AbovePrompt, areas, BelowPrompt, Dashboard, TurnEnd as TurnEndArea, Working, type Area } from './ui/areas.js'
54
54
  import { drawWith, elementOf } from './ui/elements.js'
55
55
  import { drawnParts } from './runtime/parts.js'
56
56
  import { serveWidgets, type Widgets } from './runtime/widgets.js'
@@ -144,6 +144,17 @@ const presentation: CommandPresentation = { isFullscreen: false, columns: defaul
144
144
 
145
145
  const toolUseEvents: readonly string[] = ['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionDenied']
146
146
 
147
+ const areaComponents = { [AbovePrompt]: 'AbovePrompt', [BelowPrompt]: 'PromptHint', [Working]: 'Spinner', [TurnEndArea]: 'TurnDuration', [Dashboard]: 'Pane' } as const satisfies Readonly<Record<Area, RenderComponent>>
148
+
149
+ function drawnByStyle(key: string): (drawnKey: string) => boolean {
150
+ return (drawnKey) => {
151
+ if (!drawnKey.endsWith(`:${key}`)) return false
152
+ const scoped = drawnKey.slice(0, -key.length - 1)
153
+ const block = scoped.slice(scoped.lastIndexOf(':') + 1)
154
+ return block !== scoped && /^\d+$/.test(block)
155
+ }
156
+ }
157
+
147
158
  export function testMod<State extends object, Declared extends Options = Options>(definition: ModDefinition<State, string, Declared>, options: TestOptions<State, Declared> = {}): TestedMod<State> {
148
159
  installJsx()
149
160
  const name = definition.name
@@ -215,13 +226,18 @@ export function testMod<State extends object, Declared extends Options = Options
215
226
  if (requests !== undefined && requests.length > 0) await applyRequests(requests)
216
227
  }
217
228
  const pressPart = (input: PartPress) => callMod(partMethods.press, input).then((update) => updated((update ?? {}) as PartsUpdate))
218
- const markdownIn = (table: ElementTable, at: StyledAt) => (props: MarkdownProps): RenderElement => {
219
- const drawnAt = `${at.surface}\u0000${at.columns}\u0000${props.text}`
220
- const drawn = stylesMarkdown ? ownMarkdown.get(drawnAt) : null
221
- if (drawn === undefined) missedMarkdown.set(drawnAt, { markdown: props.text, ...at })
222
- if (drawn === undefined || drawn === null || drawn.tree === null) return table.Markdown(props)
223
- const { draw, tree } = drawn
224
- return drawWith(table, () => elementOf(tree, '', (handler, args) => void pressPart({ draw, handler, args }))) as RenderElement
229
+ const markdownIn = (table: ElementTable, at: StyledAt) => {
230
+ let unkeyed = 0
231
+ return (props: MarkdownProps): RenderElement => {
232
+ if (!stylesMarkdown) return table.Markdown(props)
233
+ const keyPrefix = `${name}/markdown:${props.key ?? unkeyed++}:`
234
+ const drawnAt = `${at.surface}\u0000${at.columns}\u0000${props.text}`
235
+ const drawn = ownMarkdown.get(drawnAt)
236
+ if (drawn === undefined) missedMarkdown.set(drawnAt, { markdown: props.text, ...at })
237
+ if (drawn === undefined || drawn === null || drawn.tree === null) return table.Markdown(props)
238
+ const { draw, tree } = drawn
239
+ return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args }))) as RenderElement
240
+ }
225
241
  }
226
242
  const withOwnMarkdown = async <Drawn>(draw: () => Promise<Drawn>): Promise<Drawn> => {
227
243
  const first = await draw()
@@ -338,6 +354,7 @@ export function testMod<State extends object, Declared extends Options = Options
338
354
  }
339
355
  const answer = await cmodPlugin.dispatch(event, input as Frozen<Args<N>>, (passed) => lifecycle.route(event, passed, async (e) => (await claudeCodeRuns(event, e, below)) as EventResult<N>))
340
356
  await fake.settle()
357
+ if (event === 'ui.render') checkKeys(answer as RenderElement, name, (input as Args<'ui.render'>).component)
341
358
  return answer
342
359
  }
343
360
 
@@ -395,7 +412,8 @@ export function testMod<State extends object, Declared extends Options = Options
395
412
  const drawn = (await callMod(partMethods.draw, { page: pageId, params: page.params, columns, isFocused: page.isFocused })) as DrawnPart | null
396
413
  await fake.settle()
397
414
  const tree = drawn?.tree ?? null
398
- const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(elements, () => elementOf(tree, '', (handler, args) => void pressPart({ draw: drawn.draw, handler, args })), markdownIn(elements, { surface: 'terminal', columns })) as RenderElement)
415
+ const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(elements, () => elementOf(tree, `${name}/${pageId}:`, (handler, args) => void pressPart({ draw: drawn.draw, handler, args })), markdownIn(elements, { surface: 'terminal', columns })) as RenderElement)
416
+ checkKeys(drawing, cmodPluginName, 'Pane')
399
417
  return { drawing, columns }
400
418
  }
401
419
 
@@ -418,7 +436,8 @@ export function testMod<State extends object, Declared extends Options = Options
418
436
  }
419
437
  const drawnElement = async (type: 'Button' | 'Input' | 'Select' | 'Markdown', key: string) => {
420
438
  const { id, drawing } = await draw()
421
- const props = findElement(drawing, type, key)
439
+ const keys = isPane ? [key] : [key, `${name}/${id}:${key}`]
440
+ const props = keys.map((each) => findElement(drawing, type, each)).find((found) => found !== undefined) ?? findElement(drawing, type, drawnByStyle(key))
422
441
  if (props === undefined) throw new Error(`The ${kind} "${id}" of ${name} draws no ${type} with the ${type === 'Button' ? 'key or label' : 'key'} "${key}".`)
423
442
  return { id, props }
424
443
  }
@@ -474,7 +493,9 @@ export function testMod<State extends object, Declared extends Options = Options
474
493
  if (area === TurnEndArea && turn?.closedAt === undefined) throw new Error(`${name} has no ended turn, so TurnEnd draws nothing. End one with tested.add({ type: Prompt, text: '…' }), then tested.endTurn().`)
475
494
  const drawn = await withOwnMarkdown(() => served.draw(area, elements, { surface: 'terminal', columns }, turn))
476
495
  await fake.settle()
477
- return { drawing: elements.Box({ flexDirection: 'column', children: [...drawn] }), columns }
496
+ const drawing = elements.Box({ flexDirection: 'column', children: [...drawn] })
497
+ checkKeys(drawing, cmodPluginName, areaComponents[area])
498
+ return { drawing, columns }
478
499
  }
479
500
 
480
501
  const drawSlot = async (component: RenderComponent, props: object, requestId = `${component}_${(slotDraws += 1)}`) => {
@@ -482,6 +503,7 @@ export function testMod<State extends object, Declared extends Options = Options
482
503
  const input = { surface: 'terminal', component, requestId, props } as Frozen<Args<'ui.render'>>
483
504
  const drawing = await lifecycle.route('ui.render', input, async (e) => plainOutput(e as Args<'ui.render'>))
484
505
  await fake.settle()
506
+ checkKeys(drawing, name, component)
485
507
  return { drawing, columns: defaultColumns }
486
508
  }
487
509
 
@@ -634,7 +656,7 @@ export function testMod<State extends object, Declared extends Options = Options
634
656
  async press(area: Area, key: string) {
635
657
  const { drawing } = await drawWidgets(area)
636
658
  const keys = [key, ...(await widgetsOf()).widgets().filter((widget) => widget.mod === name).map((widget) => `${widget.key}:${key}`)]
637
- const button = keys.map((each) => findElement(drawing, 'Button', each)).find((found) => found !== undefined)
659
+ const button = keys.map((each) => findElement(drawing, 'Button', each)).find((found) => found !== undefined) ?? findElement(drawing, 'Button', drawnByStyle(key))
638
660
  if (button === undefined) throw new Error(`The widgets of ${name} in ${area} draw no Button with the key or label "${key}".`)
639
661
  await (button['onPress'] as () => unknown)()
640
662
  await fake.settle()
@@ -41,6 +41,24 @@ function built(current: Drawing, value: unknown): unknown {
41
41
  return build(current, name, props)
42
42
  }
43
43
 
44
+ export function drawKeyed<Drawn>(keyPrefix: string, draw: () => Drawn): Drawn {
45
+ const outer = drawing
46
+ drawing = undefined
47
+ try {
48
+ return keyed(draw(), keyPrefix) as Drawn
49
+ } finally {
50
+ drawing = outer
51
+ }
52
+ }
53
+
54
+ function keyed(value: unknown, keyPrefix: string): unknown {
55
+ if (Array.isArray(value)) return value.map((each: unknown) => keyed(each, keyPrefix))
56
+ if (typeof value !== 'object' || value === null || !(unbuilt in value)) return value
57
+ const { name, props } = (value as Unbuilt)[unbuilt]
58
+ const prefixed = Object.fromEntries(Object.entries(props).map(([field, each]) => [field, field === 'key' && typeof each === 'string' ? `${keyPrefix}${each}` : keyed(each, keyPrefix)]))
59
+ return { [unbuilt]: { name, props: prefixed } } satisfies Unbuilt
60
+ }
61
+
44
62
  const elementKey = '$cmodElement'
45
63
 
46
64
  const handlerKey = '$cmodHandler'
@@ -5,7 +5,8 @@ type Drawn = {
5
5
  readonly children?: readonly RenderNode[];
6
6
  };
7
7
  export declare const elements: ElementTable;
8
- export declare function findElement(node: RenderNode, type: string, key: string): Drawn['props'] | undefined;
8
+ export declare function findElement(node: RenderNode, type: string, key: string | ((drawnKey: string) => boolean)): Drawn['props'] | undefined;
9
+ export declare function checkKeys(tree: RenderNode, plugin: string, component: string): void;
9
10
  export declare function rowsOf(node: RenderNode, width: number): string[];
10
11
  export declare function textOf(node: RenderNode): string;
11
12
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"fake-elements.d.ts","sourceRoot":"","sources":["../src/testing/fake-elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAiB,UAAU,EAAE,MAAM,aAAa,CAAA;AAE1E,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,QAAQ,CA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,UAAU,GAAG,MAAM,CAiB/C"}
@@ -1,5 +1,6 @@
1
1
  const boxInsides = new WeakMap();
2
2
  const measuredProps = ['width', 'height', 'minWidth', 'minHeight'];
3
+ const oncePerKey = new Set(['Input', 'Select', 'Markdown', 'Client', 'Raster', 'Image']);
3
4
  function element(type) {
4
5
  return (props) => {
5
6
  const { children, ...rest } = props;
@@ -33,17 +34,36 @@ export const elements = {
33
34
  Client: element('Client'),
34
35
  };
35
36
  export function findElement(node, type, key) {
37
+ const matches = (drawn) => {
38
+ const drawnKey = drawn.props['key'];
39
+ if (typeof key !== 'string')
40
+ return typeof drawnKey === 'string' && key(drawnKey);
41
+ return drawnKey === key || (type === 'Button' && drawn.props['label'] === key);
42
+ };
43
+ for (const drawn of drawnIn(node))
44
+ if (drawn.type === type && matches(drawn))
45
+ return drawn.props;
46
+ return undefined;
47
+ }
48
+ export function checkKeys(tree, plugin, component) {
49
+ const seen = new Set();
50
+ for (const { type, props } of drawnIn(tree)) {
51
+ const key = props['key'];
52
+ if (!oncePerKey.has(type) || typeof key !== 'string')
53
+ continue;
54
+ const drawn = `${type}\u0000${key}`;
55
+ if (seen.has(drawn))
56
+ throw new Error(`${plugin}: returned a tree ${component} refuses: ${type} "${key}" is drawn twice; each takes its own key`);
57
+ seen.add(drawn);
58
+ }
59
+ }
60
+ function* drawnIn(node) {
36
61
  if (typeof node === 'string')
37
- return undefined;
62
+ return;
38
63
  const drawn = insideOf(node);
39
- if (drawn.type === type && (drawn.props['key'] === key || (type === 'Button' && drawn.props['label'] === key)))
40
- return drawn.props;
41
- for (const child of drawn.children ?? []) {
42
- const found = findElement(child, type, key);
43
- if (found !== undefined)
44
- return found;
45
- }
46
- return undefined;
64
+ yield drawn;
65
+ for (const child of drawn.children ?? [])
66
+ yield* drawnIn(child);
47
67
  }
48
68
  export function rowsOf(node, width) {
49
69
  const drawn = typeof node === 'string' ? undefined : insideOf(node);
package/testing.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"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CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAA;IACzF,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC7E,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IACnC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CACtB,CAAA;AAqBD,wBAAgB,OAAO,CAAC,KAAK,SAAS,MAAM,EAAE,QAAQ,SAAS,OAAO,GAAG,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAoiBlM"}
package/testing.js CHANGED
@@ -17,12 +17,12 @@ import { beforeEvents, processEvents, sessionEvents } from './session/session.js
17
17
  import { ContextEnd } from './session/context/context.js';
18
18
  import { TaskStart } from './session/goal/task.js';
19
19
  import { calledAnswer, fakeClaude } from './testing/fake-claude.js';
20
- import { elements, findElement, rowsOf } from './testing/fake-elements.js';
20
+ import { checkKeys, elements, findElement, rowsOf } from './testing/fake-elements.js';
21
21
  import { fakeFiles } from './testing/fake-files.js';
22
22
  import { fakeSessions } from './testing/fake-sessions.js';
23
23
  import { listed, messageOf } from './utils/text.js';
24
24
  import { componentOf } from './ui/styles.js';
25
- import { areas, TurnEnd as TurnEndArea } from './ui/areas.js';
25
+ import { AbovePrompt, areas, BelowPrompt, Dashboard, TurnEnd as TurnEndArea, Working } from './ui/areas.js';
26
26
  import { drawWith, elementOf } from './ui/elements.js';
27
27
  import { drawnParts } from './runtime/parts.js';
28
28
  import { serveWidgets } from './runtime/widgets.js';
@@ -33,6 +33,16 @@ const defaultColumns = 80;
33
33
  const defaultRows = 24;
34
34
  const presentation = { isFullscreen: false, columns: defaultColumns };
35
35
  const toolUseEvents = ['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionDenied'];
36
+ const areaComponents = { [AbovePrompt]: 'AbovePrompt', [BelowPrompt]: 'PromptHint', [Working]: 'Spinner', [TurnEndArea]: 'TurnDuration', [Dashboard]: 'Pane' };
37
+ function drawnByStyle(key) {
38
+ return (drawnKey) => {
39
+ if (!drawnKey.endsWith(`:${key}`))
40
+ return false;
41
+ const scoped = drawnKey.slice(0, -key.length - 1);
42
+ const block = scoped.slice(scoped.lastIndexOf(':') + 1);
43
+ return block !== scoped && /^\d+$/.test(block);
44
+ };
45
+ }
36
46
  export function testMod(definition, options = {}) {
37
47
  installJsx();
38
48
  const name = definition.name;
@@ -113,15 +123,21 @@ export function testMod(definition, options = {}) {
113
123
  await applyRequests(requests);
114
124
  };
115
125
  const pressPart = (input) => callMod(partMethods.press, input).then((update) => updated((update ?? {})));
116
- const markdownIn = (table, at) => (props) => {
117
- const drawnAt = `${at.surface}\u0000${at.columns}\u0000${props.text}`;
118
- const drawn = stylesMarkdown ? ownMarkdown.get(drawnAt) : null;
119
- if (drawn === undefined)
120
- missedMarkdown.set(drawnAt, { markdown: props.text, ...at });
121
- if (drawn === undefined || drawn === null || drawn.tree === null)
122
- return table.Markdown(props);
123
- const { draw, tree } = drawn;
124
- return drawWith(table, () => elementOf(tree, '', (handler, args) => void pressPart({ draw, handler, args })));
126
+ const markdownIn = (table, at) => {
127
+ let unkeyed = 0;
128
+ return (props) => {
129
+ if (!stylesMarkdown)
130
+ return table.Markdown(props);
131
+ const keyPrefix = `${name}/markdown:${props.key ?? unkeyed++}:`;
132
+ const drawnAt = `${at.surface}\u0000${at.columns}\u0000${props.text}`;
133
+ const drawn = ownMarkdown.get(drawnAt);
134
+ if (drawn === undefined)
135
+ missedMarkdown.set(drawnAt, { markdown: props.text, ...at });
136
+ if (drawn === undefined || drawn === null || drawn.tree === null)
137
+ return table.Markdown(props);
138
+ const { draw, tree } = drawn;
139
+ return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args })));
140
+ };
125
141
  };
126
142
  const withOwnMarkdown = async (draw) => {
127
143
  const first = await draw();
@@ -244,6 +260,8 @@ export function testMod(definition, options = {}) {
244
260
  }
245
261
  const answer = await cmodPlugin.dispatch(event, input, (passed) => lifecycle.route(event, passed, async (e) => (await claudeCodeRuns(event, e, below))));
246
262
  await fake.settle();
263
+ if (event === 'ui.render')
264
+ checkKeys(answer, name, input.component);
247
265
  return answer;
248
266
  };
249
267
  const claudeCodeRuns = async (event, e, below) => {
@@ -302,7 +320,8 @@ export function testMod(definition, options = {}) {
302
320
  const drawn = (await callMod(partMethods.draw, { page: pageId, params: page.params, columns, isFocused: page.isFocused }));
303
321
  await fake.settle();
304
322
  const tree = drawn?.tree ?? null;
305
- const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(elements, () => elementOf(tree, '', (handler, args) => void pressPart({ draw: drawn.draw, handler, args })), markdownIn(elements, { surface: 'terminal', columns })));
323
+ const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(elements, () => elementOf(tree, `${name}/${pageId}:`, (handler, args) => void pressPart({ draw: drawn.draw, handler, args })), markdownIn(elements, { surface: 'terminal', columns })));
324
+ checkKeys(drawing, cmodPluginName, 'Pane');
306
325
  return { drawing, columns };
307
326
  };
308
327
  const shownNow = (isPane) => {
@@ -325,7 +344,8 @@ export function testMod(definition, options = {}) {
325
344
  };
326
345
  const drawnElement = async (type, key) => {
327
346
  const { id, drawing } = await draw();
328
- const props = findElement(drawing, type, key);
347
+ const keys = isPane ? [key] : [key, `${name}/${id}:${key}`];
348
+ const props = keys.map((each) => findElement(drawing, type, each)).find((found) => found !== undefined) ?? findElement(drawing, type, drawnByStyle(key));
329
349
  if (props === undefined)
330
350
  throw new Error(`The ${kind} "${id}" of ${name} draws no ${type} with the ${type === 'Button' ? 'key or label' : 'key'} "${key}".`);
331
351
  return { id, props };
@@ -387,13 +407,16 @@ export function testMod(definition, options = {}) {
387
407
  throw new Error(`${name} has no ended turn, so TurnEnd draws nothing. End one with tested.add({ type: Prompt, text: '…' }), then tested.endTurn().`);
388
408
  const drawn = await withOwnMarkdown(() => served.draw(area, elements, { surface: 'terminal', columns }, turn));
389
409
  await fake.settle();
390
- return { drawing: elements.Box({ flexDirection: 'column', children: [...drawn] }), columns };
410
+ const drawing = elements.Box({ flexDirection: 'column', children: [...drawn] });
411
+ checkKeys(drawing, cmodPluginName, areaComponents[area]);
412
+ return { drawing, columns };
391
413
  };
392
414
  const drawSlot = async (component, props, requestId = `${component}_${(slotDraws += 1)}`) => {
393
415
  await start();
394
416
  const input = { surface: 'terminal', component, requestId, props };
395
417
  const drawing = await lifecycle.route('ui.render', input, async (e) => plainOutput(e));
396
418
  await fake.settle();
419
+ checkKeys(drawing, name, component);
397
420
  return { drawing, columns: defaultColumns };
398
421
  };
399
422
  const fire = ((event, input, below) => {
@@ -551,7 +574,7 @@ export function testMod(definition, options = {}) {
551
574
  async press(area, key) {
552
575
  const { drawing } = await drawWidgets(area);
553
576
  const keys = [key, ...(await widgetsOf()).widgets().filter((widget) => widget.mod === name).map((widget) => `${widget.key}:${key}`)];
554
- const button = keys.map((each) => findElement(drawing, 'Button', each)).find((found) => found !== undefined);
577
+ const button = keys.map((each) => findElement(drawing, 'Button', each)).find((found) => found !== undefined) ?? findElement(drawing, 'Button', drawnByStyle(key));
555
578
  if (button === undefined)
556
579
  throw new Error(`The widgets of ${name} in ${area} draw no Button with the key or label "${key}".`);
557
580
  await button['onPress']();
package/ui/elements.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ElementTable, MarkdownProps, RenderElement } from 'claude-code';
2
2
  export declare function drawWith<Drawn>(table: ElementTable, draw: () => Drawn, markdown?: (props: MarkdownProps) => RenderElement): Drawn;
3
+ export declare function drawKeyed<Drawn>(keyPrefix: string, draw: () => Drawn): Drawn;
3
4
  export type Handler = (...args: unknown[]) => unknown;
4
5
  export declare function elementData(value: unknown, handlers: Handler[]): unknown;
5
6
  export declare function elementOf(data: unknown, keyPrefix: string, press: (handler: number, args: readonly unknown[]) => void): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/ui/elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAY,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAcpG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,GAAG,KAAK,CASjI;AAwBD,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;AAErD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAWxE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAa/H;AAED,eAAO,MAAM,GAAG,0EAAiB,CAAA;AACjC,eAAO,MAAM,IAAI,2EAAkB,CAAA;AACnC,eAAO,MAAM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ACnC,eAAO,MAAM,MAAM,6EAAoB,CAAA;AACvC,eAAO,MAAM,IAAI,2EAAkB,CAAA;AACnC,eAAO,MAAM,IAAI,2EAAkB,CAAA;AACnC,eAAO,MAAM,QAAQ,yDAAsB,CAAA;AAC3C,eAAO,MAAM,KAAK,4EAAmB,CAAA;AACrC,eAAO,MAAM,MAAM,6EAAoB,CAAA;AACvC,eAAO,MAAM,KAAK,4EAAmB,CAAA;AACrC,eAAO,MAAM,GAAG,0EAAiB,CAAA;AACjC,eAAO,MAAM,MAAM,6EAAoB,CAAA;AACvC,eAAO,MAAM,MAAM,6EAAoB,CAAA"}
package/ui/elements.js CHANGED
@@ -29,6 +29,25 @@ function built(current, value) {
29
29
  const { name, props } = value[unbuilt];
30
30
  return build(current, name, props);
31
31
  }
32
+ export function drawKeyed(keyPrefix, draw) {
33
+ const outer = drawing;
34
+ drawing = undefined;
35
+ try {
36
+ return keyed(draw(), keyPrefix);
37
+ }
38
+ finally {
39
+ drawing = outer;
40
+ }
41
+ }
42
+ function keyed(value, keyPrefix) {
43
+ if (Array.isArray(value))
44
+ return value.map((each) => keyed(each, keyPrefix));
45
+ if (typeof value !== 'object' || value === null || !(unbuilt in value))
46
+ return value;
47
+ const { name, props } = value[unbuilt];
48
+ const prefixed = Object.fromEntries(Object.entries(props).map(([field, each]) => [field, field === 'key' && typeof each === 'string' ? `${keyPrefix}${each}` : keyed(each, keyPrefix)]));
49
+ return { [unbuilt]: { name, props: prefixed } };
50
+ }
32
51
  const elementKey = '$cmodElement';
33
52
  const handlerKey = '$cmodHandler';
34
53
  export function elementData(value, handlers) {