pi-odd-worktree 3.9.0 → 3.9.2
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 +1 -1
- 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/lib/modules.js +5 -0
- 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 +56 -10
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
|
|
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
|
|
package/lib/codegraph-card.js
CHANGED
|
@@ -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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
/**
|
|
386
|
-
|
|
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
|
|
391
|
-
|
|
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
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
//
|
|
407
|
-
//
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
/**
|
|
418
|
-
|
|
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
|
|
423
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
//
|
|
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) =>
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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;
|
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;
|