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 +2 -1
- package/extensions/odd-worktree-tools.ts +26 -1
- package/lib/artifact-read-full.js +68 -0
- package/lib/codegraph-card.js +200 -56
- package/lib/file-card.js +180 -0
- package/lib/jobs-card-resolver.js +32 -15
- package/lib/jobs-card.js +53 -10
- package/package.json +1 -1
- package/tools/bash-activity.test.js +2 -2
- package/tools/codegraph-card.test.js +218 -5
- package/tools/jobs-card.test.js +205 -9
- package/tools/message-card.test.js +31 -0
- package/tools/modules-wiring.test.js +57 -13
- package/tools/package-surface.test.js +6 -5
- package/tools/skill-read-full.test.js +156 -0
package/lib/file-card.js
CHANGED
|
@@ -452,6 +452,178 @@ function hostShellComponent(drawn, context, paint, seams, layout) {
|
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
+
// ---- the host's own fallback row, for a tool with no renderer of its own ----
|
|
456
|
+
//
|
|
457
|
+
// A tool whose DEFINITION exists but which registers neither `renderCall` nor
|
|
458
|
+
// `renderResult` is drawn by the host's own fallback (`ToolExecutionComponent`):
|
|
459
|
+
// `createCallFallback()` — `formatToolCallWithArgs(toolName, args, theme, expanded)`,
|
|
460
|
+
// the bold tool name and the call's own `key=value` arguments — for the call, and
|
|
461
|
+
// `createResultFallback()` — the result's text in `toolOutput`, ten rows when the
|
|
462
|
+
// reader has not expanded the card, with the host's own expand hint when more is
|
|
463
|
+
// withheld — for the result, both inside the box reproduced above. Neither is
|
|
464
|
+
// published: the host builds them inside the component, so a row this package hands
|
|
465
|
+
// back while its switch is off has to reproduce them, exactly as it reproduces the
|
|
466
|
+
// host's box, and for the same reason — the row must be the one Pi would have drawn.
|
|
467
|
+
//
|
|
468
|
+
// The rows are the host's `Text(text, 0, 0)`: tabs are three spaces, the text is
|
|
469
|
+
// wrapped with the injected seam and every row is padded to the width, with no
|
|
470
|
+
// background and no padding of its own (the box above paints both).
|
|
471
|
+
|
|
472
|
+
const HOST_COLLAPSED_ARGS_CHARS = 100;
|
|
473
|
+
const HOST_FALLBACK_PREVIEW_ROWS = 10;
|
|
474
|
+
/** The blank lines and tab stops the host's own `Text` normalizes before it wraps. */
|
|
475
|
+
const HOST_TAB = /\t/g;
|
|
476
|
+
const HOST_CARRIAGE_RETURN = /\r/g;
|
|
477
|
+
|
|
478
|
+
// The host's own readers for a result's text, transcribed from its source: `stripAnsi`
|
|
479
|
+
// (`dist/utils/ansi.js`: OSC sequences up to their terminator, and CSI sequences with their
|
|
480
|
+
// private prefix, parameters and final byte) and `sanitizeBinaryOutput` (`dist/utils/shell.js`:
|
|
481
|
+
// these control characters and U+FFF9–U+FFFB), with `\r` removed afterwards. Reproduced here
|
|
482
|
+
// because the host's fallback text is `sanitizeBinaryOutput(stripAnsi(part.text))` and a card
|
|
483
|
+
// that read the text differently would not be the row Pi drew — note that the host KEEPS DEL
|
|
484
|
+
// (U+007F), which this package's own `cardText` drops.
|
|
485
|
+
const HOST_ANSI = /(?:\u001B\][\s\S]*?(?:\u0007|\u001B\\|\u009C))|(?:(?:\u001B\[|\u009B)[<=>]|[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?)[\dA-PR-TZcf-nq-uy=><~]/g;
|
|
486
|
+
const HOST_BINARY = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFF9-\uFFFB]/g;
|
|
487
|
+
|
|
488
|
+
/** One string as the host reads it: terminal sequences and binary controls gone, `\r` removed. */
|
|
489
|
+
function hostText(value) {
|
|
490
|
+
const text = typeof value === 'string' ? value : '';
|
|
491
|
+
const stripped = text.includes('\u001B') || text.includes('\u009B') ? text.replace(HOST_ANSI, '') : text;
|
|
492
|
+
return stripped.replace(HOST_BINARY, '').replace(HOST_CARRIAGE_RETURN, '');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** The host's bold, when the theme has one: a theme without it states the same text, unbolded. */
|
|
496
|
+
function boldText(paint, text) {
|
|
497
|
+
if (!hasFunction(paint, 'bold')) return text;
|
|
498
|
+
try {
|
|
499
|
+
const bold = paint.bold(text);
|
|
500
|
+
return typeof bold === 'string' ? bold : text;
|
|
501
|
+
} catch {
|
|
502
|
+
return text;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* The host's `formatToolCallWithArgs`, reproduced: the tool's own name in `toolTitle`,
|
|
508
|
+
* then the call's arguments as `key=value` pairs on the same row — or, expanded, one
|
|
509
|
+
* `key: value` row each, continuation lines indented under it.
|
|
510
|
+
*/
|
|
511
|
+
function hostCallFallbackText(tool, args, paint, expanded) {
|
|
512
|
+
const header = paint.fg('toolTitle', boldText(paint, typeof tool === 'string' ? tool : ''));
|
|
513
|
+
if (args === null || args === undefined) return header;
|
|
514
|
+
const entries = typeof args === 'object' && !Array.isArray(args) ? Object.entries(args) : [['args', args]];
|
|
515
|
+
if (entries.length === 0) return header;
|
|
516
|
+
if (expanded === true) {
|
|
517
|
+
const lines = entries.map(([key, value]) => {
|
|
518
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2) ?? String(value);
|
|
519
|
+
return ` ${key}: ${text.replace(HOST_TAB, ' ').replace(HOST_CARRIAGE_RETURN, '').split('\n').join('\n ')}`;
|
|
520
|
+
});
|
|
521
|
+
return `${header}\n${paint.fg('muted', lines.join('\n'))}`;
|
|
522
|
+
}
|
|
523
|
+
const pairs = entries.map(([key, value]) => `${key}=${JSON.stringify(value) ?? String(value)}`).join(' ');
|
|
524
|
+
const preview = pairs.length > HOST_COLLAPSED_ARGS_CHARS ? `${pairs.slice(0, HOST_COLLAPSED_ARGS_CHARS - 3)}...` : pairs;
|
|
525
|
+
return `${header} ${paint.fg('muted', preview)}`;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* The result's text as the host reads it: its `text` parts, terminal sequences and binary
|
|
530
|
+
* controls gone (`hostText`: the host's own `sanitizeBinaryOutput(stripAnsi(...))`), joined by
|
|
531
|
+
* one newline. Every other part (an image) contributes no row of its own, and a result that
|
|
532
|
+
* states nothing states nothing.
|
|
533
|
+
*/
|
|
534
|
+
function hostResultOutput(result) {
|
|
535
|
+
const value = asObject(result);
|
|
536
|
+
if (typeof value.text === 'string') return hostText(value.text);
|
|
537
|
+
const parts = Array.isArray(value.content) ? value.content : [];
|
|
538
|
+
return parts
|
|
539
|
+
.filter((part) => asObject(part).type === 'text')
|
|
540
|
+
.map((part) => hostText(asObject(part).text))
|
|
541
|
+
.join('\n');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The host's `createResultFallback`, reproduced — or `undefined` for a result that
|
|
546
|
+
* states nothing, which the host draws as no result row at all.
|
|
547
|
+
*/
|
|
548
|
+
function hostResultFallbackText(result, paint, context) {
|
|
549
|
+
const ctx = asObject(context);
|
|
550
|
+
const output = hostResultOutput(result);
|
|
551
|
+
if (output.length === 0) return undefined;
|
|
552
|
+
const lines = output.split('\n');
|
|
553
|
+
const shown = ctx.expanded === true ? lines : lines.slice(0, HOST_FALLBACK_PREVIEW_ROWS);
|
|
554
|
+
const remaining = lines.length - shown.length;
|
|
555
|
+
const text = shown.map((line) => paint.fg('toolOutput', line)).join('\n');
|
|
556
|
+
if (remaining <= 0) return text;
|
|
557
|
+
const hint = expandHint(ctx, false) ?? EXPAND_TEXT.collapsed;
|
|
558
|
+
return `${text}${paint.fg('muted', `\n... (${remaining} more lines,`)} ${hint}${paint.fg('muted', ')')}`;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* A host `Text(text, 0, 0)` component: tabs are three spaces, the text is wrapped
|
|
563
|
+
* with the injected seam and every row is padded to the width. A text that states
|
|
564
|
+
* nothing draws no row — and so no box around it, exactly as the host's own does.
|
|
565
|
+
*/
|
|
566
|
+
function hostTextComponent(text, seams) {
|
|
567
|
+
return {
|
|
568
|
+
render(width) {
|
|
569
|
+
try {
|
|
570
|
+
const value = typeof text === 'string' ? text : '';
|
|
571
|
+
if (value.trim() === '') return [];
|
|
572
|
+
const target = Math.max(0, Math.floor(Number.isFinite(width) ? width : 0));
|
|
573
|
+
const normalized = value.replace(HOST_TAB, ' ');
|
|
574
|
+
const metrics = seams.metrics();
|
|
575
|
+
// No seam, no measurement: the rows are stated unwrapped rather than not at all.
|
|
576
|
+
if (metrics === undefined) return normalized.split('\n');
|
|
577
|
+
const wrapped = metrics.wrapTextWithAnsi(normalized, Math.max(1, target));
|
|
578
|
+
const rows = Array.isArray(wrapped) ? wrapped : [];
|
|
579
|
+
return rows.map((row) => `${row}${' '.repeat(Math.max(0, target - metrics.visibleWidth(row)))}`);
|
|
580
|
+
} catch {
|
|
581
|
+
return [];
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
invalidate() {
|
|
585
|
+
// Nothing is cached: there is no measurement and no row to invalidate.
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* The host's own drawing for ONE half of a card whose tool has no renderer of its
|
|
592
|
+
* own: its fallback text, inside the shell the tool's definition declares — the box
|
|
593
|
+
* reproduced above for a default shell, untouched rows for one that frames itself.
|
|
594
|
+
*
|
|
595
|
+
* `input` is `{ slot, tool, args, result, width, context, paint, seams, shell }`:
|
|
596
|
+
* `slot` is `'call'` or `'result'`, and `args`/`result` are that half's own input.
|
|
597
|
+
* The call carries the box's leading blank row and closes the box while no result
|
|
598
|
+
* follows it; the result carries the closing blank (the host draws one box around
|
|
599
|
+
* both halves, and this is that box, split between the two slots the host asks for).
|
|
600
|
+
* A result that states nothing is no result row at all — the host draws no child for
|
|
601
|
+
* it — and the closing blank is then the one row that half still owes the box.
|
|
602
|
+
*/
|
|
603
|
+
function hostFallbackRows(input) {
|
|
604
|
+
const value = asObject(input);
|
|
605
|
+
const ctx = asObject(value.context);
|
|
606
|
+
const shell = value.shell === HOST_SHELL.SELF ? HOST_SHELL.SELF : HOST_SHELL.DEFAULT;
|
|
607
|
+
const result = value.slot === 'result';
|
|
608
|
+
const text = result
|
|
609
|
+
? hostResultFallbackText(value.result, value.paint, ctx)
|
|
610
|
+
: hostCallFallbackText(value.tool, value.args, value.paint, ctx.expanded === true);
|
|
611
|
+
if (typeof text !== 'string') {
|
|
612
|
+
return result && shell !== HOST_SHELL.SELF ? hostBoxBlankRow(value.width, ctx, value.paint) : [];
|
|
613
|
+
}
|
|
614
|
+
const layout = result
|
|
615
|
+
? { shell, leading: false, trailing: true }
|
|
616
|
+
: { shell, leading: true, trailing: () => cardAwaitingResult(ctx) };
|
|
617
|
+
return hostShellRows(hostTextComponent(text, value.seams), value.width, ctx, value.paint, value.seams, layout);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** The host box's own padding row: full-width spaces, painted in the box's background role. */
|
|
621
|
+
function hostBoxBlankRow(width, context, paint) {
|
|
622
|
+
const target = Math.max(0, Math.floor(Number.isFinite(width) ? width : 0));
|
|
623
|
+
if (target === 0) return [];
|
|
624
|
+
return [paintBackground(paint, hostBoxRole(context), ' '.repeat(target))];
|
|
625
|
+
}
|
|
626
|
+
|
|
455
627
|
/**
|
|
456
628
|
* The rows of a call card: the identity's heading over the file's own call line. Plain
|
|
457
629
|
* rows, built for one width, so the caller can rebuild them on every frame.
|
|
@@ -685,6 +857,14 @@ module.exports = {
|
|
|
685
857
|
fileResultRows,
|
|
686
858
|
fileResultSlot,
|
|
687
859
|
fileResultText,
|
|
860
|
+
// The host's own drawing, for the halves this package hands back while its switch is
|
|
861
|
+
// off: the box it wraps a default-shell row in, and the fallback text it draws for a
|
|
862
|
+
// tool with no renderer of its own (`lib/jobs-card.js`, `lib/codegraph-card.js`).
|
|
863
|
+
hostCallFallbackText,
|
|
864
|
+
hostFallbackRows,
|
|
865
|
+
hostResultFallbackText,
|
|
866
|
+
hostShellRows,
|
|
867
|
+
hostTextComponent,
|
|
688
868
|
inheritedRenderers,
|
|
689
869
|
inheritedShell,
|
|
690
870
|
};
|
|
@@ -8,20 +8,23 @@
|
|
|
8
8
|
// NOTHING and SHADOWS NOTHING: it chooses renderers for the four job tools and hands every
|
|
9
9
|
// other row back exactly as the chain resolved it.
|
|
10
10
|
//
|
|
11
|
-
// One difference from the file card
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
11
|
+
// One difference from the file card. The file card forwards to the host's own renderers while
|
|
12
|
+
// its switch is off; these four tools have NO renderer of their own — Pi draws its own plain
|
|
13
|
+
// fallback for them — so there is nothing to forward to. The card draws that fallback itself
|
|
14
|
+
// while the line says anything but `activity` (the host's box around the host's
|
|
15
|
+
// `createCallFallback()`/`createResultFallback()` text, reproduced in `lib/file-card.js`), and
|
|
16
|
+
// its own rows while the line says `activity`. Both are decided on EVERY paint, inside the
|
|
17
|
+
// component, because Pi resolves a tool's renderers ONCE when it mounts the card
|
|
18
|
+
// (`interactive-mode.js` builds `ToolExecutionComponent` with the definition it resolved) and
|
|
19
|
+
// never asks again: a switch flipped while a card is already on screen repaints that card.
|
|
17
20
|
//
|
|
18
21
|
// THE SWITCH is the bridge's `Card activity` line, read through its published reader, never a
|
|
19
22
|
// store path. It is strict: only the answer `design` carrying this package's activity design
|
|
20
|
-
// paints. No bridge, a bridge older than the reader, a reader that throws, `native`,
|
|
21
|
-
// `not-covered`, `missing`, another plugin's design and an answer nothing can read all
|
|
22
|
-
//
|
|
23
|
+
// paints the card. No bridge, a bridge older than the reader, a reader that throws, `native`,
|
|
24
|
+
// `not-covered`, `missing`, another plugin's design and an answer nothing can read all draw
|
|
25
|
+
// the host's own fallback, because here an unavailable answer must never change a row.
|
|
23
26
|
|
|
24
|
-
const { inheritedRenderers } = require('./file-card.js');
|
|
27
|
+
const { hostFallbackRows, inheritedRenderers, inheritedShell } = require('./file-card.js');
|
|
25
28
|
const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
|
|
26
29
|
const { CARD_CONTENT, cardContentLevel } = require('./card-content.js');
|
|
27
30
|
const { JOB_TOOLS, jobCallSlot, jobResultSlot } = require('./jobs-card.js');
|
|
@@ -89,19 +92,33 @@ function createJobsCardResolver(options) {
|
|
|
89
92
|
return CARD_CONTENT.DEFAULT;
|
|
90
93
|
}
|
|
91
94
|
},
|
|
95
|
+
/**
|
|
96
|
+
* Whether the activity design draws `tool` right now, asked inside the component's
|
|
97
|
+
* build and never cached: the line is what repaints a card already on screen, and Pi
|
|
98
|
+
* never re-resolves the renderers of a card it has already mounted.
|
|
99
|
+
*/
|
|
100
|
+
enabled(tool) {
|
|
101
|
+
return jobsActivitySelected(tool) === true;
|
|
102
|
+
},
|
|
92
103
|
};
|
|
93
104
|
const resolver = (toolName, next) => {
|
|
94
105
|
const inherited = inheritedRenderers(next);
|
|
95
106
|
// Every tool this card does not own goes back untouched, byte for byte.
|
|
96
107
|
if (!JOB_TOOLS.includes(toolName)) return inherited;
|
|
97
|
-
//
|
|
98
|
-
|
|
108
|
+
// A host that cannot measure draws its own rows: a card measured against nothing is
|
|
109
|
+
// worse than no card. A seam, not the switch: `enabled` is asked per paint.
|
|
99
110
|
if (seams.metrics() === undefined) return inherited;
|
|
111
|
+
// The shell the tool's own definition declares, read once because a resolver never sees
|
|
112
|
+
// a call's arguments: the host's box is reproduced for a default shell, and a tool that
|
|
113
|
+
// frames itself is handed back without one — exactly as the host decides.
|
|
114
|
+
const shell = inheritedShell(inherited);
|
|
115
|
+
// This card frames itself either way, so the host must not box the rows it draws — and,
|
|
116
|
+
// because Pi mounts this card once, the only place the line can still be read is inside
|
|
117
|
+
// it: the slots decide on every paint.
|
|
100
118
|
return {
|
|
101
|
-
// This card frames itself, so the host must not box it too.
|
|
102
119
|
renderShell: 'self',
|
|
103
|
-
renderCall: jobCallSlot(toolName, seams),
|
|
104
|
-
renderResult: jobResultSlot(toolName, seams),
|
|
120
|
+
renderCall: jobCallSlot(toolName, seams, shell),
|
|
121
|
+
renderResult: jobResultSlot(toolName, seams, shell),
|
|
105
122
|
};
|
|
106
123
|
};
|
|
107
124
|
const register = opts.registerToolRenderer;
|
package/lib/jobs-card.js
CHANGED
|
@@ -36,7 +36,17 @@ const {
|
|
|
36
36
|
floatRows,
|
|
37
37
|
markCardResult,
|
|
38
38
|
} = require('./shell-card.js');
|
|
39
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
PREVIEW_ROWS,
|
|
41
|
+
cardTone,
|
|
42
|
+
component,
|
|
43
|
+
expandHint,
|
|
44
|
+
fileResultRows,
|
|
45
|
+
hostFallbackRows,
|
|
46
|
+
optionFlag,
|
|
47
|
+
resultText,
|
|
48
|
+
themeFor,
|
|
49
|
+
} = require('./file-card.js');
|
|
40
50
|
// The one reader of text as a card draws it: no terminal sequences, however the model wrote it.
|
|
41
51
|
const { cardText } = require('./codegraph-card-preview.js');
|
|
42
52
|
|
|
@@ -144,10 +154,31 @@ function jobCallRows(tool, args, context, paint, metrics, width) {
|
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
/**
|
|
147
|
-
* The
|
|
148
|
-
*
|
|
157
|
+
* The rows Pi's own drawing states for one half of this tool while the `Card activity` line
|
|
158
|
+
* says anything but `activity`: the host's fallback text inside the host's own box (or bare,
|
|
159
|
+
* for a tool that frames itself), reproduced by `lib/file-card.js` because Pi builds them
|
|
160
|
+
* inside its own component and publishes neither.
|
|
161
|
+
*/
|
|
162
|
+
function hostRows(slot, tool, seams, shell, context, paint, width, input) {
|
|
163
|
+
return hostFallbackRows({
|
|
164
|
+
slot,
|
|
165
|
+
tool,
|
|
166
|
+
...input,
|
|
167
|
+
width,
|
|
168
|
+
context,
|
|
169
|
+
paint,
|
|
170
|
+
seams,
|
|
171
|
+
shell,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The call slot. The switch, the seams and the measurement are all read INSIDE the
|
|
177
|
+
* component's build, which the host runs on every frame: a card already on screen repaints
|
|
178
|
+
* when the bridge's `Card activity` line changes, and while it says anything but `activity`
|
|
179
|
+
* the component draws what Pi draws for a tool with no renderer at all.
|
|
149
180
|
*/
|
|
150
|
-
function jobCallSlot(tool, seams) {
|
|
181
|
+
function jobCallSlot(tool, seams, shell) {
|
|
151
182
|
return (args, theme, context) => {
|
|
152
183
|
try {
|
|
153
184
|
const ctx = asObject(context);
|
|
@@ -155,7 +186,10 @@ function jobCallSlot(tool, seams) {
|
|
|
155
186
|
const paint = themeFor(theme, seams.theme);
|
|
156
187
|
return component((width) => {
|
|
157
188
|
const metrics = seams.metrics();
|
|
158
|
-
|
|
189
|
+
if (metrics !== undefined && seams.enabled(tool) === true) {
|
|
190
|
+
return jobCallRows(tool, callArgs, ctx, paint, metrics, width);
|
|
191
|
+
}
|
|
192
|
+
return hostRows('call', tool, seams, shell, ctx, paint, width, { args: callArgs });
|
|
159
193
|
});
|
|
160
194
|
} catch {
|
|
161
195
|
return { render: () => [], invalidate() {} };
|
|
@@ -165,9 +199,10 @@ function jobCallSlot(tool, seams) {
|
|
|
165
199
|
|
|
166
200
|
/**
|
|
167
201
|
* The result slot: the job's own answer — a bounded preview collapsed, everything expanded —
|
|
168
|
-
* under the call, closing the frame the call left open.
|
|
202
|
+
* under the call, closing the frame the call left open. The switch is read in here too, for
|
|
203
|
+
* the reason the call slot states, and off it draws the host's own result fallback.
|
|
169
204
|
*/
|
|
170
|
-
function jobResultSlot(tool, seams) {
|
|
205
|
+
function jobResultSlot(tool, seams, shell) {
|
|
171
206
|
return (result, options, theme, context) => {
|
|
172
207
|
try {
|
|
173
208
|
const ctx = asObject(context);
|
|
@@ -175,14 +210,22 @@ function jobResultSlot(tool, seams) {
|
|
|
175
210
|
const paint = themeFor(theme, seams.theme);
|
|
176
211
|
const failed = asObject(result).isError === true || optionFlag(options, ctx, 'isError');
|
|
177
212
|
const partial = optionFlag(options, ctx, 'isPartial');
|
|
213
|
+
// The state the host's own box is painted in: still streaming, then failed, then success.
|
|
214
|
+
const boxContext = { ...ctx, isPartial: partial, isError: failed };
|
|
178
215
|
const identity = IDENTITY[tool] ?? IDENTITY.bash_background;
|
|
216
|
+
// One frame, marked when the host BUILDS this half and not while it paints it: the host
|
|
217
|
+
// builds the result component in `updateDisplay()` and only then renders the pass, so a
|
|
218
|
+
// mark made while painting would arrive after the call above already drew — one row too
|
|
219
|
+
// many on the first paint of a partial result.
|
|
220
|
+
markCardResult(ctx.state);
|
|
179
221
|
return component((width) => {
|
|
180
222
|
const metrics = seams.metrics();
|
|
181
|
-
if (metrics === undefined)
|
|
223
|
+
if (metrics === undefined || seams.enabled(tool) !== true) {
|
|
224
|
+
// `expanded` is the host's own, so a fallback result follows the card's expansion.
|
|
225
|
+
return hostRows('result', tool, seams, shell, { ...boxContext, expanded: optionFlag(options, ctx, 'expanded') }, paint, width, { result });
|
|
226
|
+
}
|
|
182
227
|
const expanded = optionFlag(options, ctx, 'expanded');
|
|
183
228
|
const tone = cardTone(failed, partial);
|
|
184
|
-
// One frame: from here on the call above is a heading and this card closes it.
|
|
185
|
-
markCardResult(ctx.state);
|
|
186
229
|
return floatRows(tone, paint, width, (inner) => {
|
|
187
230
|
const rows = fileResultRows({
|
|
188
231
|
text: resultText(result),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -1617,9 +1617,9 @@ test('the audit\'s real PR command names the publishing activity', () => {
|
|
|
1617
1617
|
|
|
1618
1618
|
The four tools are declared on the \`tags\` line so the bridge can answer for them; the activity design itself returns their rows exactly as drawn.
|
|
1619
1619
|
|
|
1620
|
-
##
|
|
1620
|
+
## Repaint
|
|
1621
1621
|
|
|
1622
|
-
The gate is read
|
|
1622
|
+
The gate is read on every paint, inside the component the host already mounted, so flipping \`Card activity\` between \`default\` and \`activity\` repaints the job cards already on screen. Off, the card draws the host's own fallback row and box, reproduced, because these tools have no host renderer to hand the row back to.
|
|
1623
1623
|
|
|
1624
1624
|
## Tests
|
|
1625
1625
|
|
|
@@ -100,6 +100,16 @@ const plainTheme = {
|
|
|
100
100
|
},
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
+
// The host's own palette, as far as a test can see it: every role is named and bold is its
|
|
104
|
+
// own tag, so the rows this package hands back can be compared with the host's drawing
|
|
105
|
+
// byte for byte.
|
|
106
|
+
const hostTheme = {
|
|
107
|
+
fg: (role, value) => `<${role}>${value}</${role}>`,
|
|
108
|
+
bg: (role, value) => `<${role}>${value}</${role}>`,
|
|
109
|
+
bold: (value) => `<bold>${value}</bold>`,
|
|
110
|
+
};
|
|
111
|
+
const hostRow = (role, text, width) => `<${role}>${text.padEnd(width)}</${role}>`;
|
|
112
|
+
|
|
103
113
|
/** A theme that can also paint the float background, so the text stays readable. */
|
|
104
114
|
function paintTheme() {
|
|
105
115
|
const roles = { fg: [], bg: [] };
|
|
@@ -210,6 +220,195 @@ after(() => {
|
|
|
210
220
|
delete globalThis[BRIDGE_API_SLOT];
|
|
211
221
|
});
|
|
212
222
|
|
|
223
|
+
/** A host that draws CodeGraph rows itself: the chain's renderers, captured when the card was built. */
|
|
224
|
+
const HOST_CODEGRAPH = {
|
|
225
|
+
renderShell: 'self',
|
|
226
|
+
renderCall: () => ({ render: (width) => [`host call ${width}`.padEnd(width, ' ')], invalidate() {} }),
|
|
227
|
+
renderResult: () => ({ render: (width) => [`host result ${width}`.padEnd(width, ' ')], invalidate() {} }),
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// ---- the switch, read per paint ----
|
|
231
|
+
//
|
|
232
|
+
// Pi resolves a tool's renderers ONCE, when it mounts the card
|
|
233
|
+
// (`interactive-mode.js` hands the resolved definition to `ToolExecutionComponent`), and
|
|
234
|
+
// never asks again. The bridge's `Card activity` line is therefore read INSIDE the
|
|
235
|
+
// component's build, which the host does run on every frame: the cases below mount one
|
|
236
|
+
// card, flip the line, and repaint that same component.
|
|
237
|
+
|
|
238
|
+
test('the line is read on every paint: a mounted card hands the row back to the chain and takes it again', () => {
|
|
239
|
+
publishBridge(ACTIVITY_ON);
|
|
240
|
+
const resolver = cardFor({ cwd: '/work/repo' });
|
|
241
|
+
const slot = renderersFor(resolver, CODEGRAPH_TOOL, HOST_CODEGRAPH);
|
|
242
|
+
const args = { operation: 'explore', query: 'auth login' };
|
|
243
|
+
const context = { args, isPartial: false };
|
|
244
|
+
// ONE card, mounted: the components the host built before any of this changed.
|
|
245
|
+
const call = slot.renderCall(args, hostTheme, context);
|
|
246
|
+
const result = slot.renderResult(textResult('found it'), { isPartial: false }, hostTheme, context);
|
|
247
|
+
const on = { call: call.render(60), result: result.render(60) };
|
|
248
|
+
assert.ok(on.call.length > 0, 'the card is drawn while the line says activity');
|
|
249
|
+
assert.ok(on.result.length > 0, 'and its result half too');
|
|
250
|
+
// The line is turned off, and the SAME mounted components are repainted.
|
|
251
|
+
publishBridge({ kind: 'native' });
|
|
252
|
+
assert.deepEqual(call.render(60), [`host call 60`.padEnd(60, ' ')], 'off, the chain\'s own renderer draws the row it captured at build time');
|
|
253
|
+
assert.deepEqual(result.render(60), [`host result 60`.padEnd(60, ' ')], 'the result half too');
|
|
254
|
+
// And back on, from the same two components.
|
|
255
|
+
publishBridge(ACTIVITY_ON);
|
|
256
|
+
assert.deepEqual(call.render(60), on.call, 'flipped back on, the card is drawn again, unchanged');
|
|
257
|
+
assert.deepEqual(result.render(60), on.result, 'the result half too');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('the line is read on every paint for all three surfaces and a bash call that runs CodeGraph', () => {
|
|
261
|
+
// The mounted-repaint contract (S1): ONE component per surface, mounted while the line says
|
|
262
|
+
// `activity`, repainted after the line is turned off and after it is turned back on.
|
|
263
|
+
const surfaces = [
|
|
264
|
+
[CODEGRAPH_TOOL, { operation: 'explore', query: 'auth login' }, 'the native tool'],
|
|
265
|
+
[CODEGRAPH_MCP_TOOL, { query: 'auth login' }, 'the MCP tool, bare name'],
|
|
266
|
+
[MCP_PREFIXED_TOOL, { query: 'auth login' }, 'the MCP tool, prefixed name'],
|
|
267
|
+
['bash', { command: 'codegraph explore -- auth login' }, 'a bash call that runs CodeGraph'],
|
|
268
|
+
];
|
|
269
|
+
const flips = [];
|
|
270
|
+
for (const [tool, args, label] of surfaces) {
|
|
271
|
+
publishBridge(ACTIVITY_ON);
|
|
272
|
+
const resolver = cardFor({ cwd: '/work/repo' });
|
|
273
|
+
const slot = renderersFor(resolver, tool, HOST_CODEGRAPH);
|
|
274
|
+
const context = { args, isPartial: false };
|
|
275
|
+
const call = slot.renderCall(args, hostTheme, context);
|
|
276
|
+
const on = call.render(60);
|
|
277
|
+
assert.ok(on.length > 0 && !on.join('\n').includes('host call'), `${label}: the card is drawn while the line says activity`);
|
|
278
|
+
publishBridge({ kind: 'native' });
|
|
279
|
+
assert.deepEqual(call.render(60), [`host call 60`.padEnd(60, ' ')], `${label}: flipped off, the chain's own rows are drawn`);
|
|
280
|
+
publishBridge(ACTIVITY_ON);
|
|
281
|
+
assert.deepEqual(call.render(60), on, `${label}: flipped back on, the card is drawn again, unchanged`);
|
|
282
|
+
flips.push(label);
|
|
283
|
+
}
|
|
284
|
+
assert.equal(flips.length, 4, 'four surfaces, four mounted repaints, each in both directions');
|
|
285
|
+
publishBridge(ACTIVITY_ON);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('a captured renderer that throws falls back to the host\'s own drawing', () => {
|
|
289
|
+
// Pi catches a renderer that throws and draws `createCallFallback()` in its place
|
|
290
|
+
// (`ToolExecutionComponent.updateDisplay`); the card must do the same rather than lose the row.
|
|
291
|
+
const throwing = {
|
|
292
|
+
renderShell: 'self',
|
|
293
|
+
renderCall() {
|
|
294
|
+
throw new Error('host renderer exploded');
|
|
295
|
+
},
|
|
296
|
+
renderResult() {
|
|
297
|
+
throw new Error('host renderer exploded');
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
publishBridge({ kind: 'native' });
|
|
301
|
+
try {
|
|
302
|
+
const resolver = cardFor({ cwd: '/work/repo' });
|
|
303
|
+
const call = renderersFor(resolver, CODEGRAPH_TOOL, throwing).renderCall({ operation: 'status' }, hostTheme, { isPartial: false }).render(120);
|
|
304
|
+
const title = `<toolTitle><bold>${CODEGRAPH_TOOL}</bold></title>`.replace('</title>', '</toolTitle>');
|
|
305
|
+
// The host's own fallback row; Pi prepends its one separator blank for a self-framed tool,
|
|
306
|
+
// which is the baseline's two rows.
|
|
307
|
+
assert.deepEqual(call, [`${title} <muted>operation="status"</muted>`.padEnd(120, ' ')]);
|
|
308
|
+
} finally {
|
|
309
|
+
publishBridge(ACTIVITY_ON);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('ordinary bash keeps the same clickable child while activity is off', () => {
|
|
314
|
+
// The verifier's own dispatch check, kept here so a future wrapper cannot silently swallow a
|
|
315
|
+
// click: with the line off the host mounts the child's component ITSELF, and its mouse handler
|
|
316
|
+
// is the one that runs.
|
|
317
|
+
publishBridge({ kind: 'native' });
|
|
318
|
+
try {
|
|
319
|
+
let clicks = 0;
|
|
320
|
+
const child = {
|
|
321
|
+
render: () => ['ordinary bash'],
|
|
322
|
+
invalidate() {},
|
|
323
|
+
handleMouse() { clicks += 1; return { handled: true }; },
|
|
324
|
+
};
|
|
325
|
+
const chain = { renderShell: 'self', renderCall: () => child };
|
|
326
|
+
const resolved = cardFor({ cwd: '/work/repo' })('bash', () => chain);
|
|
327
|
+
assert.equal(resolved, chain);
|
|
328
|
+
const mounted = resolved.renderCall({ command: 'printf ordinary' }, plainTheme, {});
|
|
329
|
+
assert.equal(mounted, child);
|
|
330
|
+
assert.deepEqual(mounted.handleMouse({ type: 'click', button: 'left' }), { handled: true });
|
|
331
|
+
assert.equal(clicks, 1);
|
|
332
|
+
} finally {
|
|
333
|
+
publishBridge(ACTIVITY_ON);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('with the line off a bash row is handed back untouched, never wrapped', () => {
|
|
338
|
+
// A bash call's own component is what the host mounts, so its rows, its mouse handling and
|
|
339
|
+
// every other behaviour stay exactly as Pi resolved them: off, this card adds no wrapper.
|
|
340
|
+
publishBridge({ kind: 'native' });
|
|
341
|
+
try {
|
|
342
|
+
const chain = {
|
|
343
|
+
renderShell: 'self',
|
|
344
|
+
renderCall: () => ({ render: () => ['the chain drew this'], invalidate() {} }),
|
|
345
|
+
renderResult: () => ({ render: () => ['the chain drew this too'], invalidate() {} }),
|
|
346
|
+
};
|
|
347
|
+
for (const command of ['pnpm test', 'codegraph status .']) {
|
|
348
|
+
assert.equal(cardFor({ cwd: '/work/repo' })('bash', () => chain), chain, command);
|
|
349
|
+
}
|
|
350
|
+
} finally {
|
|
351
|
+
publishBridge(ACTIVITY_ON);
|
|
352
|
+
}
|
|
353
|
+
// While the line says activity the card is the one answering, so a flip can repaint it.
|
|
354
|
+
const chain = { renderShell: 'self', renderCall: () => ({ render: () => [], invalidate() {} }), renderResult: () => ({ render: () => [], invalidate() {} }) };
|
|
355
|
+
assert.equal(cardFor({ cwd: '/work/repo' })('bash', () => chain).renderShell, 'self', 'activity on: the card answers the bash row');
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('a PARTIAL result draws the rows every later paint draws, on the FIRST paint', () => {
|
|
359
|
+
// Pi builds the result component when the update arrives (`updateDisplay`) and only then
|
|
360
|
+
// renders the pass. A mark made while painting lands after the call already drew, so the first
|
|
361
|
+
// partial paint carries one row too many (the verifier measured 5/4 neon, 8/7 float). The card
|
|
362
|
+
// marks during construction, like the baseline: the first paint is the one every paint repeats.
|
|
363
|
+
publishBridge(ACTIVITY_ON);
|
|
364
|
+
const resolver = cardFor({ cwd: '/work/repo' });
|
|
365
|
+
const args = { operation: 'explore', query: 'auth login' };
|
|
366
|
+
const text = textResult('found it');
|
|
367
|
+
for (const isPartial of [true, false]) {
|
|
368
|
+
const state = {};
|
|
369
|
+
const context = { args, isPartial, state };
|
|
370
|
+
// One card, built the way the host builds it: the result's component first, then the call's.
|
|
371
|
+
const slot = renderersFor(resolver, CODEGRAPH_TOOL, HOST_CODEGRAPH);
|
|
372
|
+
const result = slot.renderResult(text, { isPartial }, hostTheme, context);
|
|
373
|
+
const call = slot.renderCall(args, hostTheme, context);
|
|
374
|
+
const first = [...call.render(70), ...result.render(70)].map(unpaint);
|
|
375
|
+
const again = [...call.render(70), ...result.render(70)].map(unpaint);
|
|
376
|
+
assert.deepEqual(first, again, `isPartial=${isPartial}: the first paint is the one every later paint draws`);
|
|
377
|
+
const closers = first.filter((row) => row.startsWith('╰')).length;
|
|
378
|
+
assert.equal(closers, isPartial ? 0 : 1, `isPartial=${isPartial}: one frame, closed only by the settled result`);
|
|
379
|
+
assert.equal(call.render(70).map(unpaint).filter((row) => row.startsWith('╰')).length, 0, `isPartial=${isPartial}: the call never closes it`);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('with the line off and no renderer in the chain, the rows are the host\'s own fallback, byte for byte', () => {
|
|
384
|
+
publishBridge({ kind: 'native' });
|
|
385
|
+
try {
|
|
386
|
+
const resolver = cardFor({ cwd: '/work/repo' });
|
|
387
|
+
const args = { query: 'auth login' };
|
|
388
|
+
// The MCP tool's definition declares no shell, so Pi draws its fallback inside its own
|
|
389
|
+
// box: one painted blank row, the padded call, one painted blank row.
|
|
390
|
+
const mcp = renderersFor(resolver, MCP_PREFIXED_TOOL, undefined);
|
|
391
|
+
const boxed = mcp.renderCall(args, hostTheme, { args, isPartial: false, outputPad: 1 }).render(120);
|
|
392
|
+
const title = `<toolTitle><bold>${MCP_PREFIXED_TOOL}</bold></toolTitle>`;
|
|
393
|
+
// The call half opens the box; its closing blank belongs to the result half, which
|
|
394
|
+
// is where the host draws it once the result exists.
|
|
395
|
+
assert.deepEqual(boxed, [
|
|
396
|
+
hostRow('toolSuccessBg', ' '.repeat(120), 120),
|
|
397
|
+
hostRow('toolSuccessBg', ` ${title} <muted>query="auth login"</muted>`, 120),
|
|
398
|
+
]);
|
|
399
|
+
// The native tool frames itself (`renderShell: 'self'` in its own definition), and Pi
|
|
400
|
+
// draws no box around a tool that does: the fallback rows alone, padded.
|
|
401
|
+
const native = renderersFor(resolver, CODEGRAPH_TOOL, { renderShell: 'self' });
|
|
402
|
+
const bare = native.renderCall({ operation: 'status' }, hostTheme, { isPartial: false, outputPad: 1 }).render(120);
|
|
403
|
+
const nativeTitle = `<toolTitle><bold>${CODEGRAPH_TOOL}</bold></toolTitle>`;
|
|
404
|
+
assert.deepEqual(bare, [`${nativeTitle} <muted>operation="status"</muted>`.padEnd(120, ' ')]);
|
|
405
|
+
// A result that states nothing draws no row at all, exactly as the host's own fallback.
|
|
406
|
+
assert.deepEqual(native.renderResult(textResult(''), { isPartial: false }, hostTheme, { args: { operation: 'status' } }).render(60), []);
|
|
407
|
+
} finally {
|
|
408
|
+
publishBridge(ACTIVITY_ON);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
|
|
213
412
|
// ---- the resolver under test ----
|
|
214
413
|
|
|
215
414
|
/** No hook at all would be the host's own: every case here registers through the probe. */
|
|
@@ -987,23 +1186,37 @@ test('S11: `native`, `not-covered`, `missing`, another design and a throwing rea
|
|
|
987
1186
|
undefined,
|
|
988
1187
|
null,
|
|
989
1188
|
];
|
|
1189
|
+
// The chain's own drawing says which rows are which: this fake names itself in every row.
|
|
1190
|
+
const chain = {
|
|
1191
|
+
renderShell: 'self',
|
|
1192
|
+
renderCall: () => ({ render: (width) => [`host call ${width}`], invalidate() {} }),
|
|
1193
|
+
renderResult: () => ({ render: (width) => [`host result ${width}`], invalidate() {} }),
|
|
1194
|
+
};
|
|
1195
|
+
const call = (slot) => slot.renderCall({ operation: 'explore' }, plainTheme, { isPartial: false }).render(40);
|
|
1196
|
+
const result = (slot) => slot.renderResult(textResult('output'), { isPartial: false }, plainTheme, { args: { operation: 'explore' } }).render(40);
|
|
990
1197
|
for (const answer of answers) {
|
|
991
1198
|
publishBridge(() => answer);
|
|
992
1199
|
const resolver = cardFor();
|
|
993
1200
|
for (const tool of [CODEGRAPH_TOOL, CODEGRAPH_MCP_TOOL, 'bash']) {
|
|
994
|
-
|
|
1201
|
+
// The card is claimed — Pi resolves it once and would never ask again — and every
|
|
1202
|
+
// answer but `activity` draws the chain's own rows, on every paint.
|
|
1203
|
+
const slot = resolver(tool, () => chain);
|
|
1204
|
+
assert.equal(slot?.renderShell, 'self', `${tool} under ${JSON.stringify(answer)}`);
|
|
1205
|
+
assert.deepEqual(call(slot), ['host call 40'], `${tool} under ${JSON.stringify(answer)}`);
|
|
1206
|
+
assert.deepEqual(result(slot), ['host result 40'], `${tool} under ${JSON.stringify(answer)}`);
|
|
995
1207
|
}
|
|
996
1208
|
}
|
|
997
1209
|
publishBridge(() => { throw new Error('bridge exploded'); });
|
|
998
|
-
assert.
|
|
1210
|
+
assert.deepEqual(call(cardFor()(CODEGRAPH_TOOL, () => chain)), ['host call 40'], 'a throwing reader is a no');
|
|
999
1211
|
publishBridge(ACTIVITY_ON);
|
|
1000
1212
|
});
|
|
1001
1213
|
|
|
1002
|
-
test('S11: with no reader at all the
|
|
1214
|
+
test('S11: with no reader at all the chain\'s rows are drawn, and a host without the hook registers nothing', () => {
|
|
1215
|
+
const silent = (slot) => slot.renderCall({ operation: 'explore' }, plainTheme, { isPartial: false }).render(40);
|
|
1003
1216
|
globalThis[BRIDGE_API_SLOT] = { schema: 'gentle-shell-bridge/api', version: 1 };
|
|
1004
|
-
assert.
|
|
1217
|
+
assert.deepEqual(silent(cardFor()(CODEGRAPH_TOOL, () => HOST_BASH)), [], 'an older bridge has no switch to follow, so the host draws its own rows');
|
|
1005
1218
|
delete globalThis[BRIDGE_API_SLOT];
|
|
1006
|
-
assert.
|
|
1219
|
+
assert.deepEqual(silent(cardFor()(CODEGRAPH_TOOL, () => HOST_BASH)), [], 'no bridge, no switch, so the host still draws its own rows');
|
|
1007
1220
|
publishBridge(ACTIVITY_ON);
|
|
1008
1221
|
const { registerCodegraphCard } = require('../lib/codegraph-card.js');
|
|
1009
1222
|
assert.deepEqual(registerCodegraphCard({}, {}), { registered: false, resolver: undefined }, 'no host hook, no registration');
|