pi-odd-worktree 3.3.0 → 3.4.0

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,6 +26,8 @@ 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 tags`, 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 tags`, 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).
30
+
29
31
  ## Quick Start
30
32
 
31
33
  | Requirement | Why it is needed |
@@ -71,6 +73,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
71
73
  - **Cards follow your shell.** Tool and warp cards use the card style Gentle Shell publishes, and a click expands that card only. See [card style](docs/reference.md#card-style-follows-your-shell).
72
74
  - **Tool headings can name the activity.** With `activity` chosen on the `Card tags` line, a bash card whose heading shows the whole command is headed with the family its command names (mark and word) instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring` instead of its own glyph and name, while a `read` — which runs no shell command — keeps the host's own card, colour and width; a bash command the classifier cannot name, or a heading that hides part of it, keeps the host's `$`. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
73
75
  - **File calls on a skill or an ODD are cards too.** While `Card tags` answers with `activity` for the tool being painted, a `read`, `edit` or `write` call whose path names a skill (anything below a `skills` folder) or an ODD (anything below an `odd` folder) heads as that file, with the tool, the path and a read's line range; its Markdown body — the whole document when expanded, the first rows when collapsed — is drawn by Pi's own renderer in the theme's Markdown roles, and an edit always keeps its diff. Any other file call, and every call while that line answers anything else, is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
76
+ - **Background-job tools are cards too.** While `Card tags` 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).
74
77
  - **`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, other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
75
78
  - **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` or `git worktree list` is refused in any cwd and pointed at `worktree_create` and `worktree_list`; 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).
76
79
  - **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).
@@ -9979,6 +9979,16 @@ function registerOddWorktreeSurfaceEntries(pi) {
9979
9979
  } catch {
9980
9980
  // The card is cosmetic.
9981
9981
  }
9982
+ // The jobs card, through the same host hook: `bash_background`, `monitor`, `job_stop` and
9983
+ // `job_list` have no renderer of their own, so Pi draws a plain box and the conversation's
9984
+ // card style never reaches them. While the bridge's `Card tags` line answers with this
9985
+ // package's activity design for the tool, they are drawn on the card substrate in the
9986
+ // shell's own style; any other answer leaves Pi's drawing exactly as it was.
9987
+ try {
9988
+ libRequire("jobs-card-resolver.js").registerJobsCard(pi, { metrics: () => resolveWorktreeToolCardMetrics() });
9989
+ } catch {
9990
+ // The card is cosmetic.
9991
+ }
9982
9992
  // The live-checkout scan is DISPATCHED and never awaited. Its only product is
9983
9993
  // `warpDiscoveryCache`, which nothing reads — every warp lists fresh before
9984
9994
  // acting — so the old "startup barrier" awaited three git reads for a result the
@@ -12,7 +12,7 @@
12
12
  // `/gentle:customize` → `Cards` (`default` | `activity`), it is read on every paint so cards
13
13
  // already on screen repaint when it changes, and extension load order does not matter.
14
14
  //
15
- // ONE line covers seven tools. `bash`'s heading names what its command does; the three read-only
15
+ // ONE line covers eleven tools. `bash`'s heading names what its command does; the three read-only
16
16
  // shell tools the line covers (`grep`, `find`, `ls`) only ever read, so their heading is always
17
17
  // `exploring` whatever their arguments are. `read`, `write` and `edit` are declared for a different reason:
18
18
  // the file card is painted only while the bridge's line resolves to this design for the tool being
@@ -46,6 +46,9 @@ const { SHELL_ACTIVITY_IDENTITY, inferBashActivity } = require('./bash-activity.
46
46
  // S6: the file card's own identity rule, reused and never copied — a path it claims is
47
47
  // the file card's row, so this design must leave it alone.
48
48
  const { fileCardIdentity, FILE_CARD_TOOLS } = require('./skill-odd-card.js');
49
+ // The four background-job tools: the jobs card (`lib/jobs-card.js`) draws them, and it is painted
50
+ // only while this line answers that this design draws the tool being drawn.
51
+ const { JOB_TOOLS } = require('./jobs-card.js');
49
52
  const { cardElapsed, charColumns, elapsedRow, paintFrame, rowColumns, sgrBefore, textColumns, visibleChars } = require('./bash-frame.js');
50
53
 
51
54
  const TOOL_NAME = 'bash';
@@ -105,7 +108,10 @@ const WRITE_TOOL = 'write';
105
108
  const EDIT_TOOL = 'edit';
106
109
  // The tools of the line, in the order they have always been declared; the scoped shape appends the
107
110
  // tool that only a scoped claim can carry.
108
- const LINE_TOOLS = [TOOL_NAME, ...READ_TOOL_GLYPHS.keys(), READ_TOOL, WRITE_TOOL];
111
+ // The background-job tools are declared for the same reason as `read` and `write`: the jobs card is the
112
+ // only surface that draws them, and it is painted only while this line resolves to this design for them.
113
+ // `computeActivity` knows no mark for them, so the design itself returns their rows exactly as drawn.
114
+ const LINE_TOOLS = [TOOL_NAME, ...READ_TOOL_GLYPHS.keys(), READ_TOOL, WRITE_TOOL, ...JOB_TOOLS];
109
115
 
110
116
  // The bridge keeps ONE persisted value per tool, in its own store (`bridge-tool-designs` →
111
117
  // `selections` → `{ "bash": <design id> }`, documented in the bridge's contract), and one per LINE
@@ -250,6 +250,10 @@ function registerFileCard(pi, deps = {}) {
250
250
  }
251
251
 
252
252
  module.exports = {
253
+ // The bridge's published object and this package's design id: the jobs card asks the same
254
+ // switch (`lib/jobs-card-resolver.js`) and must read it through the same gate.
255
+ ACTIVITY_DESIGN_ID,
256
+ bridgeApi,
253
257
  createFileCardResolver,
254
258
  registerFileCard,
255
259
  };
package/lib/file-card.js CHANGED
@@ -654,6 +654,14 @@ function fileResultSlot(tool, inherited, seams, shell) {
654
654
  module.exports = {
655
655
  FILE_TOOLS,
656
656
  PREVIEW_ROWS,
657
+ // The drawing helpers the jobs card (`lib/jobs-card.js`) shares, so the two cards can never
658
+ // disagree about a tone, a hint, a theme fallback or how a result's text is read.
659
+ cardTone,
660
+ component,
661
+ expandHint,
662
+ optionFlag,
663
+ resultText,
664
+ themeFor,
657
665
  fileCallRows,
658
666
  fileCallSlot,
659
667
  fileCardHeading,
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+ // The seam that makes `bash_background`, `monitor`, `job_stop` and `job_list` this package's
3
+ // jobs card (`lib/jobs-card.js`).
4
+ //
5
+ // Shaped like `lib/file-card-resolver.js`: the host resolves drawing through
6
+ // `pi.registerToolRenderer((toolName, next) => …)`, where `next()` is what the remaining
7
+ // resolvers and then the registered tool would draw. This module REGISTERS NOTHING, EXECUTES
8
+ // NOTHING and SHADOWS NOTHING: it chooses renderers for the four job tools and hands every
9
+ // other row back exactly as the chain resolved it.
10
+ //
11
+ // One difference from the file card, and it is deliberate. The file card forwards to the host's
12
+ // own renderers while its switch is off, so it can decide on every paint. These four tools have
13
+ // NO renderer of their own — Pi draws its plain default for them — so there is nothing to
14
+ // forward to. The switch is therefore read when the card is BUILT: any answer other than the
15
+ // activity design hands back exactly what the chain resolved, and Pi draws what it always drew.
16
+ // A switch flipped while a card is already on screen reaches the next job card, not that one.
17
+ //
18
+ // THE SWITCH is the bridge's `Card tags` line, read through its published reader, never a
19
+ // 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 leave
22
+ // Pi's drawing untouched, because here an unavailable answer must never change a row.
23
+
24
+ const { inheritedRenderers } = require('./file-card.js');
25
+ const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
26
+ const { CARD_CONTENT, cardContentLevel } = require('./card-content.js');
27
+ const { JOB_TOOLS, jobCallSlot, jobResultSlot } = require('./jobs-card.js');
28
+
29
+ const METRICS_FUNCTIONS = ['visibleWidth', 'truncateToWidth', 'wrapTextWithAnsi'];
30
+
31
+ const asObject = (value) => (value !== null && typeof value === 'object' ? value : {});
32
+ const hasFunction = (value, name) => value !== null && typeof value === 'object' && typeof value[name] === 'function';
33
+
34
+ /**
35
+ * Whether the activity design draws `tool` right now. Strict: anything but this package's own
36
+ * design as the line's answer is a no. The reader never throws on the bridge's side and this
37
+ * one does not either.
38
+ */
39
+ function jobsActivitySelected(tool) {
40
+ try {
41
+ const api = bridgeApi();
42
+ if (api === undefined || typeof api.resolveToolDesignSelection !== 'function') return false;
43
+ const answer = asObject(api.resolveToolDesignSelection(tool));
44
+ return answer.kind === 'design' && asObject(answer.design).id === ACTIVITY_DESIGN_ID;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ function assertMetrics(value) {
51
+ for (const name of METRICS_FUNCTIONS) {
52
+ if (!hasFunction(value, name)) throw new TypeError(`createJobsCardResolver requires metrics.${name} to be a function`);
53
+ }
54
+ return value;
55
+ }
56
+
57
+ /** The measurement seam, validated once: the object itself, or a function asked on every paint. */
58
+ function metricsSeam(value) {
59
+ if (typeof value === 'function') return value;
60
+ assertMetrics(value);
61
+ return () => value;
62
+ }
63
+
64
+ const usableMetrics = (value) => (METRICS_FUNCTIONS.every((name) => hasFunction(value, name)) ? value : undefined);
65
+
66
+ /**
67
+ * `createJobsCardResolver({ metrics, registerToolRenderer, theme })` — every host seam is an
68
+ * option, exactly as for the file card. Returns `{ registered, resolver }`; `resolver` is the
69
+ * function the host hook receives. An absent or throwing hook is no hook: nothing of ours is
70
+ * drawn, which is what an older host needs.
71
+ */
72
+ function createJobsCardResolver(options) {
73
+ const opts = asObject(options);
74
+ const metrics = metricsSeam(opts.metrics);
75
+ const seams = {
76
+ theme: opts.theme,
77
+ metrics() {
78
+ try {
79
+ return usableMetrics(metrics());
80
+ } catch {
81
+ return undefined;
82
+ }
83
+ },
84
+ /** The conversation's content level, read now: `minimal` or the safe `default`. */
85
+ content() {
86
+ try {
87
+ return cardContentLevel() === CARD_CONTENT.MINIMAL ? CARD_CONTENT.MINIMAL : CARD_CONTENT.DEFAULT;
88
+ } catch {
89
+ return CARD_CONTENT.DEFAULT;
90
+ }
91
+ },
92
+ };
93
+ const resolver = (toolName, next) => {
94
+ const inherited = inheritedRenderers(next);
95
+ // Every tool this card does not own goes back untouched, byte for byte.
96
+ if (!JOB_TOOLS.includes(toolName)) return inherited;
97
+ // Pi's own drawing stays unless the line says activity, and unless a card can be measured.
98
+ if (!jobsActivitySelected(toolName)) return inherited;
99
+ if (seams.metrics() === undefined) return inherited;
100
+ return {
101
+ // This card frames itself, so the host must not box it too.
102
+ renderShell: 'self',
103
+ renderCall: jobCallSlot(toolName, seams),
104
+ renderResult: jobResultSlot(toolName, seams),
105
+ };
106
+ };
107
+ const register = opts.registerToolRenderer;
108
+ if (typeof register !== 'function') return { registered: false, resolver };
109
+ try {
110
+ register(resolver);
111
+ return { registered: true, resolver };
112
+ } catch {
113
+ return { registered: false, resolver };
114
+ }
115
+ }
116
+
117
+ /**
118
+ * The extension's one-line wiring point: register through the host's hook when it has one and
119
+ * report the outcome rather than throwing. A host without `registerToolRenderer` draws its own
120
+ * rows and loses nothing.
121
+ */
122
+ function registerJobsCard(pi, deps = {}) {
123
+ if (typeof pi?.registerToolRenderer !== 'function') return { registered: false, resolver: undefined };
124
+ try {
125
+ return createJobsCardResolver({
126
+ metrics: deps.metrics,
127
+ theme: deps.theme,
128
+ registerToolRenderer: (resolver) => pi.registerToolRenderer(resolver),
129
+ });
130
+ } catch {
131
+ return { registered: false, resolver: undefined };
132
+ }
133
+ }
134
+
135
+ module.exports = {
136
+ createJobsCardResolver,
137
+ jobsActivitySelected,
138
+ registerJobsCard,
139
+ };
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+ // The jobs card: `bash_background`, `monitor`, `job_stop` and `job_list` drawn on this
3
+ // package's card substrate (`lib/shell-card.js`), in whichever style the shell has chosen.
4
+ //
5
+ // Gentle Shell registers those four tools with no renderer of their own, so Pi draws its
6
+ // plain default box and the conversation's card style (neon or float) never reaches them.
7
+ // This module is the drawing half; `lib/jobs-card-resolver.js` decides WHEN it is used — only
8
+ // while the bridge's `Card tags` line answers `activity` for the tool being drawn.
9
+ //
10
+ // It is shaped exactly like `lib/file-card.js` and shares its helpers (tone, expand hint,
11
+ // theme fallback, result text, the bounded body preview), so the two cards read as one family.
12
+ //
13
+ // What the card never decides:
14
+ // * COLOUR. Every cell is a theme role handed to the injected `theme.fg`; no palette and no
15
+ // raw escape sequence is written here, and the frame keeps the TONE's role whenever the
16
+ // tone owns the box, so a running or failed call is never painted in an identity colour.
17
+ // * MEASUREMENT. The substrate clips, wraps and pads plain text and paints it afterwards.
18
+ // * STATE. The tone follows the host's own flags (`isPartial`, `isError`), the expanded view
19
+ // is the host's own `expanded`, the elapsed time its own `durationMs`.
20
+ // * THE TOOL. Nothing is registered, executed or shadowed: the arguments are only read.
21
+ // * THE CONTENT LEVEL. The `minimal` card content level draws the call alone while collapsed;
22
+ // a failure still says why. It is read on every paint.
23
+ //
24
+ // Rendering never throws: a theme or an argument that fails draws no rows instead of breaking
25
+ // the session's transcript.
26
+
27
+ const {
28
+ cardAwaitingResult,
29
+ cardBodyRows,
30
+ cardBottom,
31
+ cardElapsed,
32
+ cardInnerWidth,
33
+ cardRunningLine,
34
+ cardTopLine,
35
+ cardTopRows,
36
+ floatRows,
37
+ markCardResult,
38
+ } = require('./shell-card.js');
39
+ const { PREVIEW_ROWS, cardTone, component, expandHint, fileResultRows, optionFlag, resultText, themeFor } = require('./file-card.js');
40
+ // The one reader of text as a card draws it: no terminal sequences, however the model wrote it.
41
+ const { cardText } = require('./codegraph-card-preview.js');
42
+
43
+ /** The four tools this card owns, in the order the bridge's `Card tags` line declares them. */
44
+ const JOB_TOOLS = Object.freeze(['bash_background', 'monitor', 'job_stop', 'job_list']);
45
+
46
+ // Each tool's mark, its one-word label and the theme role the heading wears.
47
+ const IDENTITY = Object.freeze({
48
+ bash_background: { glyph: '⧗', title: 'background', titleRole: 'bashMode' },
49
+ monitor: { glyph: '◉', title: 'monitor', titleRole: 'mdLink' },
50
+ job_stop: { glyph: '■', title: 'stop', titleRole: 'warning' },
51
+ job_list: { glyph: '≡', title: 'jobs', titleRole: 'syntaxFunction' },
52
+ });
53
+
54
+ const SUBTITLE_ROLE = 'accent';
55
+ const COMMAND_ROLE = 'dim';
56
+ const FALLBACK = Object.freeze({ bash_background: 'shell command', monitor: 'shell command', job_stop: 'a background job', job_list: 'this session' });
57
+
58
+ const asObject = (value) => (value !== null && typeof value === 'object' ? value : {});
59
+ // A model-written string as one plain line: terminal sequences gone, whitespace collapsed.
60
+ const oneLine = (value) => (typeof value === 'string' ? cardText(value).replace(/\s+/gu, ' ').trim() : '');
61
+
62
+ /** The command's lines as drawn: sequences gone, no blank rows around it, trailing space dropped. */
63
+ function commandLines(args) {
64
+ const command = asObject(args).command;
65
+ if (typeof command !== 'string') return [];
66
+ const lines = cardText(command).replace(/\r\n/g, '\n').split('\n').map((line) => line.trimEnd());
67
+ while (lines.length > 0 && lines[0].trim() === '') lines.shift();
68
+ while (lines.length > 0 && lines[lines.length - 1].trim() === '') lines.pop();
69
+ return lines;
70
+ }
71
+
72
+ /**
73
+ * What names one call: a job's label, else the first line of its command; a stop its job id;
74
+ * a listing its own scope. Never the JSON of the arguments.
75
+ */
76
+ function jobSubtitle(tool, args) {
77
+ const call = asObject(args);
78
+ if (tool === 'job_stop') return oneLine(call.job_id) || FALLBACK.job_stop;
79
+ if (tool === 'job_list') return FALLBACK.job_list;
80
+ const label = oneLine(call.label);
81
+ if (label !== '') return label;
82
+ const first = commandLines(args).find((line) => line.trim() !== '');
83
+ return first === undefined ? FALLBACK[tool] : oneLine(first);
84
+ }
85
+
86
+ /** The heading one call wears, or undefined for a tool this card does not own. */
87
+ function jobCardHeading(tool, args) {
88
+ const identity = IDENTITY[tool];
89
+ if (identity === undefined) return undefined;
90
+ const subtitle = jobSubtitle(tool, args);
91
+ return {
92
+ glyph: identity.glyph,
93
+ title: identity.title,
94
+ titleRole: identity.titleRole,
95
+ subtitle,
96
+ collapsed: subtitle,
97
+ labelBold: true,
98
+ subtitleSegments: [{ text: subtitle, role: SUBTITLE_ROLE }],
99
+ };
100
+ }
101
+
102
+ /**
103
+ * The rows of a call card: the mark and the name of the job, and — expanded — the whole
104
+ * command below it, every line. Plain rows built for one width, rebuilt on every frame.
105
+ */
106
+ function jobCallRows(tool, args, context, paint, metrics, width) {
107
+ const ctx = asObject(context);
108
+ const heading = jobCardHeading(tool, args);
109
+ if (heading === undefined) return [];
110
+ const expanded = ctx.expanded === true;
111
+ const pending = ctx.isPartial !== false;
112
+ const failed = ctx.isError === true;
113
+ const tone = cardTone(failed, pending);
114
+ // A running or failed call offers no expand affordance: nothing settled is behind it.
115
+ const hint = pending || failed ? undefined : expandHint(ctx, expanded);
116
+ const card = {
117
+ glyph: heading.glyph,
118
+ title: heading.title,
119
+ subtitle: heading.subtitle,
120
+ subtitleSegments: heading.subtitleSegments,
121
+ labelBold: heading.labelBold,
122
+ tone,
123
+ titleRole: heading.titleRole,
124
+ railRole: heading.titleRole,
125
+ };
126
+ return floatRows(tone, paint, width, (inner) => {
127
+ const head = expanded
128
+ ? cardTopRows(card, paint, inner, hint, metrics)
129
+ : [cardTopLine(card, paint, inner, hint, () => heading.collapsed, metrics)];
130
+ const command = expanded ? commandLines(args) : [];
131
+ const body = [
132
+ ...(command.length > 0 ? cardBodyRows(command, tone, paint, inner, { expanded: true, role: COMMAND_ROLE }, metrics) : []),
133
+ ...(pending && !failed ? [cardRunningLine(tone, paint, inner, metrics)] : []),
134
+ ];
135
+ // The result that follows owns the closing rule; a call still waiting for it closes its own.
136
+ const bottom = cardAwaitingResult(ctx) ? cardBottom(tone, paint, inner, undefined, metrics) : undefined;
137
+ return { head, body, bottom };
138
+ }, card.railRole);
139
+ }
140
+
141
+ /**
142
+ * The call slot. The seams are read on every frame, so a measurement seam that arrives late
143
+ * is used by the next paint rather than never.
144
+ */
145
+ function jobCallSlot(tool, seams) {
146
+ return (args, theme, context) => {
147
+ try {
148
+ const ctx = asObject(context);
149
+ const callArgs = args === undefined ? ctx.args : args;
150
+ const paint = themeFor(theme, seams.theme);
151
+ return component((width) => {
152
+ const metrics = seams.metrics();
153
+ return metrics === undefined ? [] : jobCallRows(tool, callArgs, ctx, paint, metrics, width);
154
+ });
155
+ } catch {
156
+ return { render: () => [], invalidate() {} };
157
+ }
158
+ };
159
+ }
160
+
161
+ /**
162
+ * The result slot: the job's own answer — a bounded preview collapsed, everything expanded —
163
+ * under the call, closing the frame the call left open.
164
+ */
165
+ function jobResultSlot(tool, seams) {
166
+ return (result, options, theme, context) => {
167
+ try {
168
+ const ctx = asObject(context);
169
+ const args = ctx.args;
170
+ const paint = themeFor(theme, seams.theme);
171
+ const failed = asObject(result).isError === true || optionFlag(options, ctx, 'isError');
172
+ const partial = optionFlag(options, ctx, 'isPartial');
173
+ const identity = IDENTITY[tool] ?? IDENTITY.bash_background;
174
+ return component((width) => {
175
+ const metrics = seams.metrics();
176
+ if (metrics === undefined) return [];
177
+ const expanded = optionFlag(options, ctx, 'expanded');
178
+ const tone = cardTone(failed, partial);
179
+ // One frame: from here on the call above is a heading and this card closes it.
180
+ markCardResult(ctx.state);
181
+ return floatRows(tone, paint, width, (inner) => {
182
+ const rows = fileResultRows({
183
+ text: resultText(result),
184
+ expanded,
185
+ failed,
186
+ content: seams.content(),
187
+ width: cardInnerWidth(inner),
188
+ theme: paint,
189
+ });
190
+ const role = rows.length > 0 ? rows[0].role : undefined;
191
+ const body = rows.length === 0
192
+ ? []
193
+ : cardBodyRows(
194
+ rows.map((row) => row.text),
195
+ tone,
196
+ paint,
197
+ inner,
198
+ expanded ? { expanded: true, role } : { previewRows: PREVIEW_ROWS, role },
199
+ metrics,
200
+ );
201
+ // A streamed result is not finished: the closing rule belongs to the final one.
202
+ const bottom = partial ? undefined : cardBottom(tone, paint, inner, cardElapsed(ctx.durationMs), metrics);
203
+ return { body, bottom, afterHeading: true };
204
+ }, identity.titleRole);
205
+ });
206
+ } catch {
207
+ return { render: () => [], invalidate() {} };
208
+ }
209
+ };
210
+ }
211
+
212
+ module.exports = {
213
+ JOB_TOOLS,
214
+ commandLines,
215
+ jobCallRows,
216
+ jobCallSlot,
217
+ jobCardHeading,
218
+ jobResultSlot,
219
+ jobSubtitle,
220
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-odd-worktree",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
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",
@@ -846,7 +846,7 @@ describe('the Card tags line', () => {
846
846
  // answers `undefined` for both (`computeActivity` knows only bash and the three read-only
847
847
  // shell marks), so their rows come back byte for byte and the host's own card is never lost.
848
848
  const design = designFor('0.6.0');
849
- assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write']);
849
+ assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
850
850
  const answer = (tool) => (design.tools.includes(tool) ? { kind: 'design', design } : { kind: 'not-covered' });
851
851
  assert.equal(answer('write').kind, 'design', 'a write is covered by the line');
852
852
  assert.equal(answer('write').design.id, BASH_DESIGN_ID);
@@ -866,7 +866,7 @@ describe('the Card tags line', () => {
866
866
  test('a 0.6.0 bridge gets ONE grouped registration over bash and the read-only tools', () => {
867
867
  const design = designFor('0.6.0');
868
868
  assert.equal(design.line, 'tags', 'the row the bridge derives is `Card tags` (S10)');
869
- assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write']);
869
+ assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
870
870
  assert.equal(Object.hasOwn(design, 'tool'), false, 'never both shapes');
871
871
  assert.equal(design.id, BASH_DESIGN_ID);
872
872
  assert.equal(design.label, BASH_DESIGN_LABEL);
@@ -1239,7 +1239,7 @@ describe('the scoped claim', () => {
1239
1239
 
1240
1240
  test('the line gains edit, and every other tool keeps its whole claim', () => {
1241
1241
  const design = toolsActivityDesign();
1242
- assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'edit']);
1242
+ assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list', 'edit']);
1243
1243
  for (const tool of ['bash', 'grep', 'find', 'ls', 'read']) {
1244
1244
  assert.equal(Object.hasOwn(design.scopes, tool), false, `${tool} is claimed for every call`);
1245
1245
  }
@@ -1273,7 +1273,7 @@ describe('the scoped claim', () => {
1273
1273
  assert.equal(design.scopes.write, design.scopes.edit, version);
1274
1274
  continue;
1275
1275
  }
1276
- assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], `${version}: today's tools`);
1276
+ assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], `${version}: today's tools`);
1277
1277
  assert.deepEqual(
1278
1278
  Object.keys(design).sort(),
1279
1279
  ['apply', 'description', 'id', 'label', 'line', 'name', 'preview', 'tools'],
@@ -1293,7 +1293,7 @@ describe('the scoped claim', () => {
1293
1293
  const design = calls.at(-1);
1294
1294
  assert.equal(design.line, 'tags', version);
1295
1295
  assert.equal(design.scopes, undefined, `${version}: a prerelease of 0.9.0 does not meet the 0.9.0 cutoff`);
1296
- assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], version);
1296
+ assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], version);
1297
1297
  }
1298
1298
  });
1299
1299
 
@@ -1303,7 +1303,7 @@ describe('the scoped claim', () => {
1303
1303
  assert.equal(calls[0].id, 'odd-worktree.capability-probe', 'the grouped shape is still probed');
1304
1304
  const design = calls.at(-1);
1305
1305
  assert.equal(design.scopes, undefined, 'an unreadable release never takes a scoped registration');
1306
- assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write']);
1306
+ assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
1307
1307
  });
1308
1308
  });
1309
1309
 
@@ -1331,7 +1331,7 @@ describe('the release rule is semver order, on both lines at once (S6)', () => {
1331
1331
  try {
1332
1332
  assert.deepEqual(registration.seen.map((design) => design.line), ['tags'], `${version}: the grouped line, and no diff line`);
1333
1333
  assert.equal(registration.tags.scopes, undefined, `${version}: below 0.9.0, so no scope`);
1334
- assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], `${version}: six tools, no edit`);
1334
+ assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], `${version}: ten tools, no edit`);
1335
1335
  assert.equal(registration.diff, undefined, `${version}: nothing is offered for a row the bridge would refuse`);
1336
1336
  } finally {
1337
1337
  registration.dispose();
@@ -1345,7 +1345,7 @@ describe('the release rule is semver order, on both lines at once (S6)', () => {
1345
1345
  try {
1346
1346
  assert.deepEqual(registration.seen.map((design) => design.line), ['tags', 'diff'], `${version}: both lines`);
1347
1347
  assert.equal(registration.tags.scopes.write, registration.tags.scopes.edit, `${version}: the scope is on the line`);
1348
- assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'edit'], `${version}: seven tools`);
1348
+ assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list', 'edit'], `${version}: eleven tools`);
1349
1349
  assert.equal(registration.diff.id, 'odd-worktree.diff', version);
1350
1350
  assert.equal(registration.diff.label, 'color', version);
1351
1351
  assert.deepEqual([...registration.diff.tools], ['write', 'edit'], version);
@@ -0,0 +1,292 @@
1
+ 'use strict';
2
+ // The jobs card: `bash_background`, `monitor`, `job_stop` and `job_list` are registered by
3
+ // Gentle Shell with no renderer of their own, so Pi draws its plain default box and the
4
+ // conversation's card style never reaches them. While the bridge's `Card tags` line answers
5
+ // `activity` for the tool being drawn, this package draws them on its own card substrate
6
+ // (`lib/shell-card.js`), in whichever style the shell has chosen. Any other answer — and the
7
+ // absence of an answer — leaves Pi's own drawing exactly as it was.
8
+ //
9
+ // Every case goes through the public surface: the resolver, the slots it returns and the
10
+ // rows a component draws for a width. The text seam and the themes are the fakes
11
+ // `tools/file-card.test.js` uses; the bridge is the published object a process-wide slot holds.
12
+ const assert = require('node:assert/strict');
13
+ const { after, afterEach, beforeEach, test } = require('node:test');
14
+
15
+ const { JOB_TOOLS } = require('../lib/jobs-card.js');
16
+ const { createJobsCardResolver, registerJobsCard } = require('../lib/jobs-card-resolver.js');
17
+ const { applyBashActivityHeading, toolsActivityDesign } = require('../lib/bash-design.js');
18
+ const { CARD_CONTENT, CARD_CONTENT_SLOT } = require('../lib/card-content.js');
19
+ const { CARD_STYLE, CARD_STYLE_SLOT } = require('../lib/card-style.js');
20
+
21
+ const ANSI = /\x1b\[[0-9;]*m/g;
22
+ const stripAnsi = (value) => value.replace(ANSI, '');
23
+ const chars = (value) => [...stripAnsi(value)];
24
+
25
+ const metrics = {
26
+ visibleWidth: (value) => chars(value).length,
27
+ truncateToWidth(value, width, ellipsis = '') {
28
+ if (width <= 0) return '';
29
+ if (this.visibleWidth(value) <= width) return value;
30
+ const tail = ellipsis ?? '';
31
+ return chars(value).slice(0, Math.max(0, width - [...tail].length)).join('') + tail;
32
+ },
33
+ wrapTextWithAnsi(value, width) {
34
+ const text = stripAnsi(value);
35
+ if (width <= 0) return [text];
36
+ return text.split('\n').flatMap((line) => {
37
+ const lines = [];
38
+ let current = '';
39
+ for (const word of line.split(' ')) {
40
+ const candidate = current === '' ? word : `${current} ${word}`;
41
+ if ([...candidate].length <= width) { current = candidate; continue; }
42
+ if (current !== '') { lines.push(current); current = ''; }
43
+ const rest = [...word];
44
+ while (rest.length > width) lines.push(rest.splice(0, width).join(''));
45
+ current = rest.join('');
46
+ }
47
+ lines.push(current);
48
+ return lines;
49
+ });
50
+ },
51
+ };
52
+
53
+ const plainTheme = { fg: (_role, value) => value };
54
+ const taggedTheme = { fg: (role, value) => `<${role}>${value}</${role}>` };
55
+ const bandTheme = { fg: (_role, value) => value, bg: (_role, value) => `\x1b[48;5;240m${value}\x1b[49m` };
56
+ const unpaint = (value) => stripAnsi(value).replace(/<\/?[a-zA-Z][a-zA-Z0-9]*>/g, '');
57
+
58
+ const BRIDGE_API_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
59
+ const ACTIVITY = Object.freeze({ kind: 'design', design: { id: 'odd-worktree.bash-activity' } });
60
+
61
+ beforeEach(() => {
62
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
63
+ delete globalThis[CARD_CONTENT_SLOT];
64
+ delete globalThis[BRIDGE_API_SLOT];
65
+ });
66
+ afterEach(() => { delete globalThis[BRIDGE_API_SLOT]; });
67
+ after(() => {
68
+ delete globalThis[CARD_STYLE_SLOT];
69
+ delete globalThis[CARD_CONTENT_SLOT];
70
+ delete globalThis[BRIDGE_API_SLOT];
71
+ });
72
+
73
+ function publishBridge(selection, asked) {
74
+ const api = {
75
+ schema: 'gentle-shell-bridge/api',
76
+ version: 1,
77
+ VERSION: '0.10.0',
78
+ registerToolDesign: () => () => {},
79
+ resolveToolDesignSelection(tool) {
80
+ if (asked !== undefined) asked.push(tool);
81
+ if (typeof selection === 'function') return selection(tool);
82
+ return selection;
83
+ },
84
+ };
85
+ globalThis[BRIDGE_API_SLOT] = api;
86
+ return api;
87
+ }
88
+
89
+ function jobsResolver(options) {
90
+ const registered = [];
91
+ const cards = createJobsCardResolver({ metrics, theme: plainTheme, registerToolRenderer: (resolver) => registered.push(resolver), ...options });
92
+ assert.equal(cards.registered, true);
93
+ assert.equal(registered.length, 1);
94
+ return registered[0];
95
+ }
96
+
97
+ // What Pi would have drawn for a tool with no renderer of its own: whatever `next()` says.
98
+ const PI_DEFAULT = Object.freeze({ marker: 'pi default' });
99
+
100
+ const COMMAND = 'sleep 20; until [ "$(gh run list --repo acme/api)" ]; do sleep 1; done';
101
+ const LABEL = 'Release runs for 1.9.1';
102
+ const STARTED = [
103
+ 'Started background job job-2 ("Release runs for 1.9.1").',
104
+ 'Output: /tmp/gentle-jobs-1018kZ/job-2.log',
105
+ 'You will be notified once when it exits; keep working or end your turn. Stop it with job_stop.',
106
+ ].join('\n');
107
+
108
+ const slots = (resolver, tool) => resolver(tool, () => PI_DEFAULT);
109
+ const callRows = (resolver, tool, args, theme, width = 70, context = { isPartial: false }) =>
110
+ slots(resolver, tool).renderCall(args, theme, { args, ...context }).render(width);
111
+ const resultRows = (resolver, tool, args, text, options = { isPartial: false }, theme = plainTheme, width = 70, context = {}) =>
112
+ slots(resolver, tool).renderResult({ content: [{ type: 'text', text }], details: {} }, options, theme, { args, state: {}, ...context }).render(width);
113
+
114
+ function assertFramed(rows, width) {
115
+ for (const row of rows) assert.equal(metrics.visibleWidth(unpaint(row)), width, `"${unpaint(row)}" is not ${width} wide`);
116
+ }
117
+
118
+ // ---- the one switch ----
119
+
120
+ test('the card is drawn only while the Card tags line answers activity; every other answer leaves Pi\'s own drawing', () => {
121
+ const answers = [
122
+ ['no bridge published', undefined],
123
+ ['the bridge\'s native answer', { kind: 'native' }],
124
+ ['a tool the line does not cover', { kind: 'not-covered' }],
125
+ ['a design that has left the line', { kind: 'missing' }],
126
+ ['another plugin\'s design', { kind: 'design', design: { id: 'acme.tools' } }],
127
+ ['an answer nothing can read', 'garbage'],
128
+ ];
129
+ for (const [name, answer] of answers) {
130
+ if (answer !== undefined) publishBridge(answer);
131
+ for (const tool of JOB_TOOLS) assert.equal(slots(jobsResolver(), tool), PI_DEFAULT, `${name}: ${tool}`);
132
+ delete globalThis[BRIDGE_API_SLOT];
133
+ }
134
+ // A bridge too old to carry the reader, and one whose reader throws, are no answer either.
135
+ globalThis[BRIDGE_API_SLOT] = { schema: 'gentle-shell-bridge/api', version: 1, VERSION: '0.6.0', registerToolDesign: () => () => {} };
136
+ assert.equal(slots(jobsResolver(), 'bash_background'), PI_DEFAULT);
137
+ publishBridge(() => { throw new Error('boom'); });
138
+ assert.equal(slots(jobsResolver(), 'bash_background'), PI_DEFAULT);
139
+ });
140
+
141
+ test('while activity is selected the four job tools get a self-framed card and the bridge is asked per tool', () => {
142
+ const asked = [];
143
+ publishBridge(ACTIVITY, asked);
144
+ const resolver = jobsResolver();
145
+ for (const tool of JOB_TOOLS) {
146
+ const drawn = slots(resolver, tool);
147
+ assert.notEqual(drawn, PI_DEFAULT, tool);
148
+ assert.equal(drawn.renderShell, 'self', `${tool} frames itself`);
149
+ assert.equal(typeof drawn.renderCall, 'function');
150
+ assert.equal(typeof drawn.renderResult, 'function');
151
+ }
152
+ assert.deepEqual(asked, [...JOB_TOOLS]);
153
+ });
154
+
155
+ test('no other tool is ever claimed: bash, the file tools and an unknown tool come back as the chain resolved them', () => {
156
+ publishBridge(ACTIVITY);
157
+ const resolver = jobsResolver();
158
+ for (const tool of ['bash', 'read', 'write', 'edit', 'grep', 'codemode', 'job_unknown']) {
159
+ assert.equal(slots(resolver, tool), PI_DEFAULT, tool);
160
+ }
161
+ });
162
+
163
+ // ---- the call ----
164
+
165
+ test('a background job heads with its mark, its label and nothing it did not state', () => {
166
+ publishBridge(ACTIVITY);
167
+ const rows = callRows(jobsResolver(), 'bash_background', { command: COMMAND, label: LABEL }, taggedTheme);
168
+ assert.equal(rows.length, 1, 'collapsed, a finished call is one rule');
169
+ const text = unpaint(rows[0]);
170
+ assert.match(text, /^╭─ ⧗ background · Release runs for 1\.9\.1 /u, text);
171
+ assert.match(text, /╮$/u);
172
+ assert.ok(rows[0].includes('<bashMode>⧗</bashMode>'), 'the mark wears the identity role');
173
+ assert.doesNotMatch(text, /sleep 20/u, 'the command waits for the expanded view');
174
+ assertFramed(rows, 70);
175
+ });
176
+
177
+ test('without a label the first line of the command names the job; the other tools name their target', () => {
178
+ publishBridge(ACTIVITY);
179
+ const resolver = jobsResolver();
180
+ assert.match(unpaint(callRows(resolver, 'bash_background', { command: '\n npm test --silent\nnpm run lint' }, plainTheme)[0]), /⧗ background · npm test --silent/u);
181
+ assert.match(unpaint(callRows(resolver, 'monitor', { command: 'tail -f app.log', label: 'app log', timeout_seconds: 60 }, plainTheme)[0]), /◉ monitor · app log/u);
182
+ assert.match(unpaint(callRows(resolver, 'job_stop', { job_id: 'job-2' }, plainTheme)[0]), /■ stop · job-2/u);
183
+ assert.match(unpaint(callRows(resolver, 'job_list', {}, plainTheme)[0]), /≡ jobs · this session/u);
184
+ });
185
+
186
+ test('expanded, the whole command is stated below the heading, every line of it', () => {
187
+ publishBridge(ACTIVITY);
188
+ const rows = callRows(jobsResolver(), 'bash_background', { command: 'sleep 20\n\ngh run list --repo acme/api', label: LABEL }, plainTheme, 70, { isPartial: false, expanded: true }).map(unpaint);
189
+ const joined = rows.join('\n');
190
+ assert.match(joined, /Release runs for 1\.9\.1/u);
191
+ assert.match(joined, /│ sleep 20 +│/u);
192
+ assert.match(joined, /│ gh run list --repo acme\/api +│/u);
193
+ assertFramed(rows, 70);
194
+ });
195
+
196
+ test('a call still waiting for its result closes its own frame; once the result exists the result closes it', () => {
197
+ publishBridge(ACTIVITY);
198
+ const resolver = jobsResolver();
199
+ const state = {};
200
+ const running = slots(resolver, 'bash_background').renderCall({ command: COMMAND }, plainTheme, { isPartial: true, state }).render(70).map(unpaint);
201
+ assert.match(running.join('\n'), /running/iu);
202
+ assert.match(running.at(-1), /^╰/u, 'the running call closes itself');
203
+ const settled = callRows(resolver, 'bash_background', { command: COMMAND }, plainTheme, 70, { isPartial: false }).map(unpaint);
204
+ assert.doesNotMatch(settled.join('\n'), /^╰/mu, 'the result owns the closing rule');
205
+ });
206
+
207
+ // ---- the result ----
208
+
209
+ test('the result previews the first rows collapsed, everything expanded, and always closes the frame', () => {
210
+ publishBridge(ACTIVITY);
211
+ const resolver = jobsResolver();
212
+ const collapsed = resultRows(resolver, 'bash_background', { command: COMMAND }, `${STARTED}\nextra line four`).map(unpaint);
213
+ assert.match(collapsed.join('\n'), /Started background job job-2/u);
214
+ assert.doesNotMatch(collapsed.join('\n'), /extra line four/u, 'only the preview budget is drawn collapsed');
215
+ assert.match(collapsed.at(-1), /^╰/u);
216
+ const expanded = resultRows(resolver, 'bash_background', { command: COMMAND }, `${STARTED}\nextra line four`, { isPartial: false, expanded: true }).map(unpaint);
217
+ assert.match(expanded.join('\n'), /extra line four/u);
218
+ assert.match(expanded.at(-1), /^╰/u);
219
+ });
220
+
221
+ test('the minimal card content level draws the call alone, but a failure still says why', () => {
222
+ publishBridge(ACTIVITY);
223
+ globalThis[CARD_CONTENT_SLOT] = CARD_CONTENT.MINIMAL;
224
+ const resolver = jobsResolver();
225
+ const quiet = resultRows(resolver, 'bash_background', { command: COMMAND }, STARTED).map(unpaint);
226
+ assert.doesNotMatch(quiet.join('\n'), /Started background job/u);
227
+ assert.match(quiet.at(-1), /^╰/u, 'the frame still closes');
228
+ const failed = resultRows(resolver, 'job_stop', { job_id: 'job-9' }, 'No background job job-9 in this session.', { isPartial: false }, plainTheme, 70, { isError: true }).map(unpaint);
229
+ assert.match(failed.join('\n'), /No background job job-9 in this session\./u);
230
+ });
231
+
232
+ // ---- the style and the width ----
233
+
234
+ test('neon draws the outlined frame and float the borderless rail, whichever tool is drawn', () => {
235
+ publishBridge(ACTIVITY);
236
+ const resolver = jobsResolver();
237
+ for (const tool of JOB_TOOLS) {
238
+ const args = tool === 'job_stop' ? { job_id: 'job-2' } : tool === 'job_list' ? {} : { command: COMMAND, label: LABEL };
239
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
240
+ const neon = [...callRows(resolver, tool, args, bandTheme), ...resultRows(resolver, tool, args, STARTED, { isPartial: false }, bandTheme)].map(unpaint);
241
+ assert.match(neon[0], /^╭/u, `${tool} neon`);
242
+ assert.match(neon.at(-1), /^╰/u);
243
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.FLOAT;
244
+ const float = [...callRows(resolver, tool, args, bandTheme), ...resultRows(resolver, tool, args, STARTED, { isPartial: false }, bandTheme)].map(unpaint);
245
+ assert.doesNotMatch(float.join('\n'), /[╭╮╰╯]/u, `${tool} float draws no box`);
246
+ assert.match(float.join('\n'), /▎/u);
247
+ }
248
+ });
249
+
250
+ test('every row fits the width the host asked for, at narrow and wide terminals', () => {
251
+ publishBridge(ACTIVITY);
252
+ const resolver = jobsResolver();
253
+ for (const style of [CARD_STYLE.NEON, CARD_STYLE.FLOAT]) {
254
+ globalThis[CARD_STYLE_SLOT] = style;
255
+ for (const width of [24, 40, 70, 120]) {
256
+ const rows = [
257
+ ...callRows(resolver, 'bash_background', { command: COMMAND, label: LABEL }, bandTheme, width),
258
+ ...callRows(resolver, 'bash_background', { command: COMMAND, label: LABEL }, bandTheme, width, { isPartial: false, expanded: true }),
259
+ ...resultRows(resolver, 'bash_background', { command: COMMAND }, STARTED, { isPartial: false, expanded: true }, bandTheme, width),
260
+ ];
261
+ assertFramed(rows, width);
262
+ }
263
+ }
264
+ });
265
+
266
+ // ---- the wiring ----
267
+
268
+ test('registerJobsCard hands one resolver to the host hook and reports a host that has none', () => {
269
+ const handed = [];
270
+ const outcome = registerJobsCard({ registerToolRenderer: (resolver) => handed.push(resolver) }, { metrics });
271
+ assert.equal(outcome.registered, true);
272
+ assert.equal(handed.length, 1);
273
+ assert.deepEqual(registerJobsCard({}, { metrics }), { registered: false, resolver: undefined });
274
+ });
275
+
276
+ test('the Card tags line covers the four job tools, so the bridge can answer for them', () => {
277
+ for (const scopes of [true, false]) {
278
+ const design = toolsActivityDesign({ scopes });
279
+ for (const tool of JOB_TOOLS) assert.ok(design.tools.includes(tool), `${tool} (scopes: ${scopes})`);
280
+ for (const tool of ['bash', 'grep', 'find', 'ls', 'read', 'write']) assert.ok(design.tools.includes(tool), `${tool} stays covered`);
281
+ }
282
+ });
283
+
284
+ test('declaring the job tools on the line changes nothing the activity design draws: their rows come back exactly as given', () => {
285
+ const rows = ['\x1b[2m bash_background command="sleep 20" \x1b[22m', ' Started background job job-2. '];
286
+ for (const tool of JOB_TOOLS) {
287
+ for (const part of ['call', 'result']) {
288
+ const drawn = applyBashActivityHeading(rows, { width: 60, tool, theme: plainTheme, part, render: { args: { command: 'sleep 20' }, isPartial: false } });
289
+ assert.deepEqual(drawn, rows, `${tool} ${part}`);
290
+ }
291
+ }
292
+ });