pi-odd-worktree 3.8.1 → 3.9.1

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/README.md CHANGED
@@ -26,7 +26,7 @@ The diff card is a design of the same kind, on a line of its own: `Card diff`, w
26
26
 
27
27
  The file cards are not a preference of this package either: they belong to that same `activity` value. While the bridge answers that `activity` draws the tool being painted, a `read`, `edit` or `write` call on a skill or an ODD artifact heads as that file — its own mark and label, the tool, the path and a read's line range, each in the theme role the reference design gives it — instead of a bare tool row, and its Markdown body is drawn by Pi's own renderer with the theme's Markdown roles. Choosing `default` on `Card activity`, or any other design on that line, gives every one of those calls back to the host. The question is asked of the bridge on every paint, so a mid-session switch repaints cards already on screen, and a bridge older than 0.7.0 — which cannot answer it — keeps the card it always had. See [the file cards](docs/reference.md#the-file-cards).
28
28
 
29
- The jobs card follows the same value. Gentle Shell registers `bash_background`, `monitor`, `job_stop` and `job_list` with no renderer of their own, so Pi draws them in a plain box and neither `neon` nor `float` ever reaches them. While the bridge answers that `activity` draws the tool being painted, they are drawn on the same card substrate in the style the shell has chosen: the job's mark and name (its label, else the first line of its command), the whole command when expanded, and the job's own answer below. Under the `minimal` card content level the call is drawn alone, and a failure still says why. Any other answer on `Card activity`, no bridge, or a bridge older than 0.7.0 leaves Pi's own box exactly as it was. Unlike the file cards, the answer is read when a job card is built, because there is no host drawing to hand back on a later paint: a switch made mid-session reaches the next job card. See [the jobs card](docs/reference.md#the-jobs-card).
29
+ The jobs card follows the same value. Gentle Shell registers `bash_background`, `monitor`, `job_stop` and `job_list` with no renderer of their own, so Pi draws them in a plain box and neither `neon` nor `float` ever reaches them. While the bridge answers that `activity` draws the tool being painted, they are drawn on the same card substrate in the style the shell has chosen: the job's mark and name (its label, else the first line of its command), the whole command when expanded, and the job's own answer below. Under the `minimal` card content level the call is drawn alone, and a failure still says why. Any other answer on `Card activity`, no bridge, or a bridge older than 0.7.0 leaves Pi's own box exactly as it was — the host's fallback row (`bash_background command=…`) inside the host's own padded box, reproduced by this package because these tools have no renderer to hand the row back to. The answer is read on every paint, inside the card the host already mounted, so flipping `Card activity` between `default` and `activity` repaints the job cards already on screen, exactly as it does for `bash`. See [the jobs card](docs/reference.md#the-jobs-card).
30
30
 
31
31
  The two advisory messages Gentle Shell sends follow that same value, through the bridge's message-design surface rather than a tool renderer: `gentle-pi.exploration-budget` heads as `⌕ Exploration budget` and `gentle-pi.verifier-settle-reminder` as `⚑ Verifier reminder`, each with the numbers the message states as its detail, drawn on the same card substrate in the style the shell has chosen. Their body is never clipped — both are instructions the agent must read, so every row is drawn at any card content level, with no preview and no expand hint — and the bridge's own `[customType]` label row is dropped because the card's heading already names the alert. There is no second switch: each design FOLLOWS the `Card activity` line, so `activity` paints both alerts, live — flipping that line repaints the messages on screen and turns them off again — and `/gentle:customize` gains no row for them. A bridge older than `0.12.1` cannot keep that follow promise — `0.12.0` let a leftover stored value veto it — and gets no registration at all, so Pi's own box stays byte-identical; only a clean numeric release is trusted, and there is no capability probe. An inactive alert costs a registry walk and at most one tool-document read, and paints nothing. See [the message cards](docs/reference.md#the-message-cards).
32
32
 
@@ -79,6 +79,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
79
79
  - **Background-job tools are cards too.** While `Card activity` answers with `activity` for the tool being painted, `bash_background`, `monitor`, `job_stop` and `job_list` are drawn in the shell's own card style instead of Pi's plain box. Any other answer leaves Pi's box untouched. See [the jobs card](docs/reference.md#the-jobs-card).
80
80
  - **The two advisory messages are cards too.** While `Card activity` answers with `activity`, `gentle-pi.exploration-budget` and `gentle-pi.verifier-settle-reminder` are drawn as `⌕ Exploration budget` and `⚑ Verifier reminder` in the shell's own card style, the whole body at every content level. They follow that line — no second switch, no row added to `Cards`, and a flip repaints the messages on screen and turns them off again. Any other answer hands the message back as Pi drew it, for the price of a registry walk and at most one tool-document read, and a bridge older than `0.12.1` — or one whose release string is not a clean numeric release — registers nothing at all. See [the message cards](docs/reference.md#the-message-cards).
81
81
  - **`edit` and `write` cannot land in the principal checkout's default branch.** A write whose path is inside the principal checkout of the session's repository, while that checkout is on the default branch, is refused with one line pointing at `worktree_list` and `worktree_create`. Paths outside the repository, anything under the OS temp directories, ODD artifacts (any path below an `odd/` folder, on any branch), other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
82
+ - **A skill or an ODD is read whole.** A `read` of a `.md` below a `skills/` or an `odd/` folder drops its `offset` and `limit` before the tool runs, so the call delivers the whole document and never half a procedure. It follows the `Worktrees+` module, like the guards.
82
83
  - **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` is refused in any cwd and pointed at `worktree_create`; in the principal checkout, a switch that would leave the branch it is on is refused while that branch is the repository's default, and creating a branch is not blocked. See [the guards](docs/reference.md#the-bash-guards).
83
84
  - **Two blocks in the system prompt.** `## ODD worktrees` tells the agent how worktrees and ODDs work. `## CodeGraph` tells a session that already holds a CodeGraph tool how to use it, with one text per role. Both are appended after the host's own text, and `ODD_WORKTREE_PROMPT=0` suppresses them. See [the prompt blocks](docs/reference.md#the--odd-worktrees-block-in-the-system-prompt).
84
85
  - **CodeGraph stays fresh, only when its CLI is installed.** At session start the package creates or syncs the checkout's index and warms its daemon, and makes sure your global `mcp.json` has the `codegraph` entry (it adds it or fixes only the differing fields and keeps the rest). It also syncs after a compaction, after a native `codegraph init` and after an `edit` or `write`, in the background and without ever blocking you. See [CodeGraph](docs/reference.md#codegraph-index-daemon-and-mcp-entry). Its tool rows are drawn as a card.
@@ -3070,6 +3070,24 @@ function readCurrentBranch(git, root) {
3070
3070
  // command string, and only for the `bash` tool. Nothing is registered here either — no
3071
3071
  // command, no tool, no option and no setting — and `ODD_WORKTREE_GUARD=0`, the worktree
3072
3072
  // guard's own switch, turns this guard off the same way, read per call.
3073
+ // S1 (skill-read-full): a skill's or an ODD's Markdown is read WHOLE. The host's `read` takes `offset`
3074
+ // and `limit`, so a caller paging through a skill cuts it in half — and a half-read skill
3075
+ // states an incomplete procedure. This observation DROPS those two fields from the call the
3076
+ // host executes (`event.input` is the host's mutable seam; no re-validation follows), so the
3077
+ // read delivers the file from its first line to its last. It blocks nothing, answers nothing
3078
+ // and adds no tool: a call that is not a skill's Markdown is left byte-identical, and the
3079
+ // decision itself is `lib/skill-read-full.js`'s, which reads the file card's own identity.
3080
+ function keepSkillReadWholeCall(event) {
3081
+ try {
3082
+ if (!event || event.toolName !== "read") return undefined;
3083
+ libRequire("artifact-read-full.js").keepArtifactReadWhole("read", event.input);
3084
+ return undefined;
3085
+ } catch {
3086
+ // A read is never failed by a rule that only meant to complete it.
3087
+ return undefined;
3088
+ }
3089
+ }
3090
+
3073
3091
  function guardSkillReadBashCall(event) {
3074
3092
  try {
3075
3093
  if (process.env.ODD_WORKTREE_GUARD === "0") return undefined;
@@ -9934,7 +9952,14 @@ function registerOddWorktreeSurfaceEntries(pi) {
9934
9952
  // of the two, so a call that would break both shows the worktree refusal. It reads the
9935
9953
  // command text only, shares the same `ODD_WORKTREE_GUARD=0` switch, and adds no
9936
9954
  // command, tool, option or setting of its own.
9937
- pi.on("tool_call", (event) => guardSkillReadBashCall(event));
9955
+ // invariant 22 (S5 of skill-read-full): the skill-read guard is the second refusal — a
9956
+ // `bash` reader pointed at a skill file — and it follows the `Worktrees+` module, like every
9957
+ // other guard here: with that module off, neither refusal nor the read rule below exists.
9958
+ if (oddModules.worktrees) pi.on("tool_call", (event) => guardSkillReadBashCall(event));
9959
+ // S1/S2/S5 (skill-read-full): the other half of the same rule — a skill's or an ODD's
9960
+ // Markdown is read whole, so a `read` that pages through one has its range dropped before
9961
+ // the host runs it. Same switch: with `Worktrees+` off, a read is left as the host proposed it.
9962
+ if (oddModules.worktrees) pi.on("tool_call", (event) => keepSkillReadWholeCall(event));
9938
9963
  if (oddModules.worktrees) pi.on("tool_result", (event, ctx) => handleWorktreeOddEvent(event, ctx, pi, true));
9939
9964
  // S10 (T9): ONE `tool_result` observation for the rail's forced refresh. It
9940
9965
  // answers the `bash` tool only — every other tool returns before the classifier
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+ // S1/S5 (skill-read-full): a skill's or an ODD's Markdown is read WHOLE.
3
+ //
4
+ // The host's `read` tool takes `offset` and `limit`, and a caller that pages through a
5
+ // long file cuts a skill in half — the half that is read then states an incomplete
6
+ // procedure, which is worse than not reading it. So this module decides one thing: when
7
+ // a `read` call names a Markdown file below a `skills` or an `odd` folder, the call's
8
+ // `offset` and `limit` are DROPPED from the input the host executes.
9
+ //
10
+ // It blocks nothing and answers nothing. The decision is a mutation of the host's own
11
+ // `event.input`, the documented seam ("`event.input` is mutable... Mutations to
12
+ // `event.input` affect the actual tool execution"), and a call that is not a skill's
13
+ // Markdown is left byte-identical.
14
+ //
15
+ // "A skill's or an ODD's Markdown" is the file card's identity, reused and never copied
16
+ // (`lib/skill-odd-card.js`): the FOLDER decides, by path components, so
17
+ // `lib/skillset/notes.md` and `docs/oddity.md` are ordinary files. The host still applies its own read
18
+ // budget (2000 lines or 50 KB); a skill is far below both, and a file that size is not
19
+ // a skill anyone can follow.
20
+
21
+ const { ODD_FILE_CARD, SKILL_FILE_CARD, fileCardIdentity, isMarkdownFile } = require('./skill-odd-card.js');
22
+
23
+ const READ_TOOL = 'read';
24
+ // The two fields that cut a file. `path` is the only required one, so these are the
25
+ // whole difference between a whole read and a partial one.
26
+ const PARTIAL_FIELDS = Object.freeze(['offset', 'limit']);
27
+
28
+ /** The two identities whose Markdown is read whole: a skill's and an ODD's. */
29
+ const WHOLE_READ_IDENTITIES = Object.freeze([SKILL_FILE_CARD, ODD_FILE_CARD]);
30
+
31
+ /** Whether a path names a skill's or an ODD's Markdown: the folder decides, then the `.md` name. */
32
+ function isArtifactMarkdown(path) {
33
+ const identity = fileCardIdentity(path);
34
+ return isMarkdownFile(path) && identity !== undefined && WHOLE_READ_IDENTITIES.includes(identity);
35
+ }
36
+
37
+ /**
38
+ * Patch one `read` call before the host runs it: `{ patched, dropped }`, where `dropped`
39
+ * lists the fields this call no longer carries. A call that is not an artifact's Markdown, or
40
+ * that carries neither field, is untouched and reports `patched: false`. Mutates the
41
+ * object it is given, in place, and never throws — a `tool_call` handler that threw would
42
+ * fail the call it was only meant to improve.
43
+ */
44
+ function keepArtifactReadWhole(toolName, input) {
45
+ const answer = { patched: false, dropped: [] };
46
+ try {
47
+ if (toolName !== READ_TOOL) return answer;
48
+ if (input === null || typeof input !== 'object') return answer;
49
+ if (!isArtifactMarkdown(input.path)) return answer;
50
+ for (const field of PARTIAL_FIELDS) {
51
+ if (!Object.hasOwn(input, field)) continue;
52
+ delete input[field];
53
+ answer.dropped.push(field);
54
+ }
55
+ answer.patched = answer.dropped.length > 0;
56
+ return answer;
57
+ } catch {
58
+ return answer;
59
+ }
60
+ }
61
+
62
+ module.exports = {
63
+ PARTIAL_FIELDS,
64
+ READ_TOOL,
65
+ WHOLE_READ_IDENTITIES,
66
+ isArtifactMarkdown,
67
+ keepArtifactReadWhole,
68
+ };
@@ -57,6 +57,13 @@ const { CARD_CONTENT, CARD_CONTENT_SLOT, cardContentLevel } = require('./card-co
57
57
  // module switch of its own. It is asked on every paint and answered for this package's
58
58
  // own design id, so `native` (and every other answer) hands the rows back untouched.
59
59
  const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
60
+ // The host's own drawing, for the rows this card hands back while the line is off: its
61
+ // fallback text for a tool with no renderer, and the box a default-shell row is drawn in.
62
+ const {
63
+ hostFallbackRows,
64
+ hostShellRows,
65
+ inheritedShell,
66
+ } = require('./file-card.js');
60
67
  const {
61
68
  CODEGRAPH_MARK,
62
69
  CODEGRAPH_MCP_TOOL,
@@ -247,9 +254,9 @@ function codegraphCallIdent(shape) {
247
254
  const base = command.length > 0
248
255
  ? detail
249
256
  : codegraphCallDetail({ operation, ...(query === undefined ? {} : { query }) });
250
- const subtitle = project === undefined
251
- ? (base.length > 0 ? base : undefined)
252
- : (base.length > 0 ? `${base} · ${project}` : project);
257
+ // The heading states what the call names, then the explored checkout when it names one.
258
+ let subtitle = base.length > 0 ? base : undefined;
259
+ if (project !== undefined) subtitle = base.length > 0 ? `${base} · ${project}` : project;
253
260
  return {
254
261
  glyph: CODEGRAPH_MARK,
255
262
  title: CODEGRAPH_TOOL,
@@ -373,6 +380,48 @@ function forwardedComponent(inherited, slot, args) {
373
380
  }
374
381
  }
375
382
 
383
+ /** Whether the chain resolved a renderer of its own for this half — the host's fallback is drawn when it did not. */
384
+ function hasRenderer(inherited, slot) {
385
+ return typeof asObject(inherited)[slot] === 'function';
386
+ }
387
+
388
+ /**
389
+ * The rows of one half while the `Card activity` line says anything but `activity`: the
390
+ * chain's own renderer drawn as it resolved it at build time — or, for a tool that resolved
391
+ * none (Pi's own `codegraph` ships a definition with no renderer), the host's own fallback
392
+ * text inside the shell the definition declares, reproduced by `lib/file-card.js`.
393
+ */
394
+ function hostRows(input) {
395
+ const value = asObject(input);
396
+ // `slot` is the half as the HOST names it: it is both the chain's renderer and the
397
+ // fallback the host draws when the chain resolved none.
398
+ const isResult = value.slot === 'result';
399
+ const chainSlot = isResult ? 'renderResult' : 'renderCall';
400
+ if (hasRenderer(value.inherited, chainSlot)) {
401
+ try {
402
+ const drawn = asObject(value.inherited)[chainSlot](...value.slotArgs);
403
+ // A component draws its rows; anything else is no drawing at all.
404
+ if (hasFunction(drawn, 'render')) {
405
+ return hostShellRows(drawn, value.width, value.context, value.paint, value.seams, value.layout);
406
+ }
407
+ } catch {
408
+ // The host catches a renderer that throws and draws its own fallback in the same place
409
+ // (`ToolExecutionComponent.updateDisplay`): so does this, instead of losing the row.
410
+ }
411
+ }
412
+ return hostFallbackRows({
413
+ slot: value.slot,
414
+ tool: value.tool,
415
+ args: value.args,
416
+ result: value.result,
417
+ width: value.width,
418
+ context: value.context,
419
+ paint: value.paint,
420
+ seams: value.seams,
421
+ shell: value.shell,
422
+ });
423
+ }
424
+
376
425
  /** The renderers the rest of the resolver chain would use for this row, resolved once. */
377
426
  function inheritedRenderers(next) {
378
427
  try {
@@ -382,71 +431,158 @@ function inheritedRenderers(next) {
382
431
  }
383
432
  }
384
433
 
385
- /** The call slot: the CodeGraph heading, or the host's own drawing when this call is not CodeGraph's. */
386
- function callSlot(toolName, inherited, seams) {
434
+ /**
435
+ * The CodeGraph heading, drawn on the card substrate: the call's own rows, for one width.
436
+ * Decided inside the component's build, like every other switch of this package.
437
+ */
438
+ function callCardRows(shape, ctx, paint, metrics, width) {
439
+ const pending = ctx.isPartial !== false;
440
+ const failed = ctx.isError === true;
441
+ let tone = CARD_TONE.INFO;
442
+ if (failed) tone = CARD_TONE.ERROR;
443
+ else if (pending) tone = CARD_TONE.WARNING;
444
+ const expanded = ctx.expanded === true;
445
+ const hint = pending || failed ? undefined : expandHint(ctx, expanded);
446
+ const card = { ...codegraphCallIdent(shape), tone };
447
+ return floatRows(tone, paint, width, (inner) => {
448
+ const head = expanded
449
+ ? cardTopRows(card, paint, inner, hint, metrics)
450
+ : [cardTopLine(card, paint, inner, hint, undefined, metrics)];
451
+ const body = pending && !failed ? [cardRunningLine(tone, paint, inner, metrics)] : [];
452
+ // The result that follows owns the closing rule; a call still waiting for it
453
+ // closes its own frame, so a running row never floats outside one.
454
+ const bottom = cardAwaitingResult(ctx) ? cardBottom(tone, paint, inner, undefined, metrics) : undefined;
455
+ return { head, body, bottom };
456
+ }, card.railRole);
457
+ }
458
+
459
+ /**
460
+ * The result rows CodeGraph's own output supports, on the card substrate, for one width.
461
+ * One frame: from here on the call above is a heading and this card closes it.
462
+ */
463
+ function resultCardRows(shape, result, options, ctx, paint, metrics, width, content) {
464
+ const failed = asObject(result).isError === true || optionFlag(options, ctx, 'isError');
465
+ const partial = optionFlag(options, ctx, 'isPartial');
466
+ const expanded = optionFlag(options, ctx, 'expanded');
467
+ let tone = CARD_TONE.INFO;
468
+ if (failed) tone = CARD_TONE.ERROR;
469
+ else if (partial) tone = CARD_TONE.WARNING;
470
+ const text = resultText(result);
471
+ return floatRows(tone, paint, width, (inner) => {
472
+ // The level is asked for on every paint, so a preference switched on screen
473
+ // repaints the rows it decides.
474
+ const rows = codegraphResultRows({ shape, text, expanded, isPartial: partial, failed, content });
475
+ const role = rows.length > 0 ? rows[0].role : undefined;
476
+ const body = role === undefined
477
+ ? []
478
+ : cardBodyRows(rows.map((row) => row.text), tone, paint, inner, { expanded: true, role }, metrics);
479
+ // A streamed result is not finished: the closing rule (and the time on it)
480
+ // belongs to the final one, which the host renders when the call settles.
481
+ const bottom = partial ? undefined : cardBottom(tone, paint, inner, cardElapsed(ctx.durationMs), metrics);
482
+ // The call above owns the heading, so the float style still sets this body
483
+ // off from it with its separator row. The result continues the heading's card,
484
+ // so its sides and closing rule keep the CodeGraph role the box above wears.
485
+ return { body, bottom, afterHeading: true };
486
+ }, CODEGRAPH_TITLE_ROLE);
487
+ }
488
+
489
+ /**
490
+ * The call slot: the CodeGraph heading while the `Card activity` line says `activity`, and
491
+ * the chain's own drawing for every other answer — decided INSIDE the component's build,
492
+ * which the host runs on every frame, never when the resolver is asked. Pi resolves a
493
+ * tool's renderers once, when it mounts the card (`interactive-mode.js` hands the
494
+ * definition it resolved to `ToolExecutionComponent`), so a gate read here is the only one
495
+ * that can repaint a card already on screen.
496
+ */
497
+ function callSlot(toolName, inherited, seams, shell) {
387
498
  return (args, theme, context) => {
388
499
  try {
389
500
  const ctx = asObject(context);
390
- const shape = codegraphShape(toolName, args === undefined ? ctx.args : args, seams.cwd());
391
- if (shape === undefined) return forwardedComponent(inherited, 'renderCall', [args, theme, context]);
392
- const metrics = seams.metrics();
393
- if (metrics === undefined) return forwardedComponent(inherited, 'renderCall', [args, theme, context]);
501
+ const slotArgs = [args, theme, context];
502
+ const callArgs = args === undefined ? ctx.args : args;
394
503
  const paint = themeFor(theme, seams.theme);
395
- const pending = ctx.isPartial !== false;
396
- const failed = ctx.isError === true;
397
- const tone = failed ? CARD_TONE.ERROR : pending ? CARD_TONE.WARNING : CARD_TONE.INFO;
398
- const expanded = ctx.expanded === true;
399
- const hint = pending || failed ? undefined : expandHint(ctx, expanded);
400
- const card = { ...codegraphCallIdent(shape), tone };
401
- return component((width) => floatRows(tone, paint, width, (inner) => {
402
- const head = expanded
403
- ? cardTopRows(card, paint, inner, hint, metrics)
404
- : [cardTopLine(card, paint, inner, hint, undefined, metrics)];
405
- const body = pending && !failed ? [cardRunningLine(tone, paint, inner, metrics)] : [];
406
- // The result that follows owns the closing rule; a call still waiting for it
407
- // closes its own frame, so a running row never floats outside one.
408
- const bottom = cardAwaitingResult(ctx) ? cardBottom(tone, paint, inner, undefined, metrics) : undefined;
409
- return { head, body, bottom };
410
- }, card.railRole));
504
+ const shape = codegraphShape(toolName, callArgs, seams.cwd());
505
+ // A call this card does not draw at all — a bash command that runs no CodeGraph — is the
506
+ // chain's own component, handed back ITSELF: its rows, its mouse handling and every other
507
+ // behaviour stay exactly as the host resolved them, off and on alike.
508
+ if (shape === undefined) return forwardedComponent(inherited, 'renderCall', slotArgs);
509
+ // The host's box opens above the call, and closes below it only while no result follows:
510
+ // the result half carries the same closing blank in its place, so the call stops closing
511
+ // its own frame as soon as the host has BUILT the result (`markCardResult`).
512
+ const layout = { shell, leading: true, trailing: () => cardAwaitingResult(ctx) };
513
+ return component((width) => {
514
+ const metrics = seams.metrics();
515
+ // No seam and any answer but `activity` are the chain's own row — the one Pi drew
516
+ // before this design existed — decided here, on every paint, never at resolver time.
517
+ if (metrics === undefined || !activityDesignDraws(toolName, callArgs)) {
518
+ return hostRows({
519
+ slot: 'call',
520
+ tool: toolName,
521
+ args: callArgs,
522
+ inherited,
523
+ slotArgs,
524
+ width,
525
+ context: ctx,
526
+ paint,
527
+ seams,
528
+ shell,
529
+ layout,
530
+ });
531
+ }
532
+ return callCardRows(shape, ctx, paint, metrics, width);
533
+ });
411
534
  } catch {
412
535
  return EMPTY_COMPONENT;
413
536
  }
414
537
  };
415
538
  }
416
539
 
417
- /** The result slot: the rows CodeGraph's own output supports, or the host's own drawing for any other call. */
418
- function resultSlot(toolName, inherited, seams) {
540
+ /**
541
+ * The result slot: the rows CodeGraph's own output supports while the line says `activity`,
542
+ * and the chain's own drawing for any other answer — decided on every paint, for the reason
543
+ * the call slot states.
544
+ */
545
+ function resultSlot(toolName, inherited, seams, shell) {
419
546
  return (result, options, theme, context) => {
420
547
  try {
421
548
  const ctx = asObject(context);
422
- const shape = codegraphShape(toolName, ctx.args, seams.cwd());
423
- if (shape === undefined) return forwardedComponent(inherited, 'renderResult', [result, options, theme, context]);
424
- const metrics = seams.metrics();
425
- if (metrics === undefined) return forwardedComponent(inherited, 'renderResult', [result, options, theme, context]);
549
+ const slotArgs = [result, options, theme, context];
550
+ const args = ctx.args;
426
551
  const paint = themeFor(theme, seams.theme);
427
552
  const failed = asObject(result).isError === true || optionFlag(options, ctx, 'isError');
428
553
  const partial = optionFlag(options, ctx, 'isPartial');
429
- const expanded = optionFlag(options, ctx, 'expanded');
430
- const tone = failed ? CARD_TONE.ERROR : partial ? CARD_TONE.WARNING : CARD_TONE.INFO;
431
- const text = resultText(result);
432
- // One frame: from here on the call above is a heading and this card closes it.
554
+ // The state the host's own box is painted in, decided once per render exactly as the
555
+ // host decides its own background: still streaming, then failed, then success.
556
+ const boxContext = { ...ctx, isPartial: partial, isError: failed, expanded: optionFlag(options, ctx, 'expanded') };
557
+ // The box's closing blank belongs to the result, which follows the call above it.
558
+ const layout = { shell, leading: false, trailing: true };
559
+ const shape = codegraphShape(toolName, args, seams.cwd());
560
+ // A result half of a call this card does not draw is the chain's own component, itself.
561
+ if (shape === undefined) return forwardedComponent(inherited, 'renderResult', slotArgs);
562
+ // S4: both halves are resolved against the same call, with the arguments the context
563
+ // holds (`ctx.args`). One frame, marked when the host BUILDS this half — the host builds
564
+ // the result in `updateDisplay()` and renders the pass afterwards, so marking during the
565
+ // paint would leave the call above it closing the frame one extra time.
433
566
  markCardResult(ctx.state);
434
- return component((width) => floatRows(tone, paint, width, (inner) => {
435
- // The level is asked for on every paint, so a preference switched on screen
436
- // repaints the rows it decides.
437
- const rows = codegraphResultRows({ shape, text, expanded, isPartial: partial, failed, content: seams.content() });
438
- const role = rows.length > 0 ? rows[0].role : undefined;
439
- const body = role === undefined
440
- ? []
441
- : cardBodyRows(rows.map((row) => row.text), tone, paint, inner, { expanded: true, role }, metrics);
442
- // A streamed result is not finished: the closing rule (and the time on it)
443
- // belongs to the final one, which the host renders when the call settles.
444
- const bottom = partial ? undefined : cardBottom(tone, paint, inner, cardElapsed(ctx.durationMs), metrics);
445
- // The call above owns the heading, so the float style still sets this body
446
- // off from it with its separator row. The result continues the heading's card,
447
- // so its sides and closing rule keep the CodeGraph role the box above wears.
448
- return { body, bottom, afterHeading: true };
449
- }, CODEGRAPH_TITLE_ROLE));
567
+ return component((width) => {
568
+ const metrics = seams.metrics();
569
+ if (metrics === undefined || !activityDesignDraws(toolName, args)) {
570
+ return hostRows({
571
+ slot: 'result',
572
+ tool: toolName,
573
+ result,
574
+ inherited,
575
+ slotArgs,
576
+ width,
577
+ context: boxContext,
578
+ paint,
579
+ seams,
580
+ shell,
581
+ layout,
582
+ });
583
+ }
584
+ return resultCardRows(shape, result, options, ctx, paint, metrics, width, seams.content());
585
+ });
450
586
  } catch {
451
587
  return EMPTY_COMPONENT;
452
588
  }
@@ -501,20 +637,28 @@ function createCodegraphCardResolver(options) {
501
637
  // Every tool the card does not own goes back untouched: those rows are the
502
638
  // chain's, byte for byte, whatever this card would have drawn.
503
639
  if (!isCodeGraphCardTool(toolName) && toolName !== BASH_TOOL) return inherited;
504
- // S11: the `Card activity` line decides. `activity` selected is the card; every other
505
- // answer is the chain's own row, which is what Pi drew before this design existed.
506
- if (!activityDesignDraws(toolName)) return inherited;
507
640
  // This card frames itself, so the host must not frame it too: the host wraps every tool whose definition does not say
508
641
  // `renderShell: 'self'` in its own filled box, and a card drawn inside that box is two designs at once.
509
642
  if (toolName === BASH_TOOL) {
510
643
  // A bash row inside the host's own box stays the host's, as does a host with no bash renderer at all: with no
511
644
  // renderer to hand a non-CodeGraph command back to, every bash row would be drawn blank.
512
645
  if (inherited === undefined || inherited.renderShell !== 'self') return inherited;
646
+ // `bash` is decided per CALL, which a resolver never sees. A command that runs no
647
+ // CodeGraph must keep the host's own component — its rows, its mouse handling and every
648
+ // other behaviour — so this card wraps a bash row only while the line already claims it;
649
+ // a bash row's own repaint on a flip is the bridge's design pass, not this card's.
650
+ if (!activityDesignDraws(toolName, undefined)) return inherited;
513
651
  }
652
+ // S11, read INSIDE the slots and never here: Pi resolves a tool's renderers once,
653
+ // when it mounts the card (`interactive-mode.js`), and never asks again — so a
654
+ // `Card activity` gate read at this point could only ever reach the next card. The
655
+ // shell the chain's own renderer draws in is fixed per tool and they are captured
656
+ // here, by reference, for the rows handed back on every paint.
657
+ const shell = inheritedShell(inherited);
514
658
  return {
515
659
  renderShell: 'self',
516
- renderCall: callSlot(toolName, inherited, seams),
517
- renderResult: resultSlot(toolName, inherited, seams),
660
+ renderCall: callSlot(toolName, inherited, seams, shell),
661
+ renderResult: resultSlot(toolName, inherited, seams, shell),
518
662
  };
519
663
  };
520
664
  const register = opts.registerToolRenderer;