pi-odd-worktree 3.0.1 β 3.1.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 +12 -9
- package/extensions/odd-worktree-tools.ts +68 -3
- package/lib/bash-design.js +161 -38
- package/lib/diff-design.js +706 -0
- package/lib/file-card-resolver.js +19 -9
- package/lib/file-card.js +9 -3
- package/package.json +1 -1
- package/tools/bash-design.test.js +305 -8
- package/tools/diff-design.test.js +635 -0
- package/tools/file-card.test.js +100 -7
- package/tools/package-surface.test.js +25 -5
package/tools/file-card.test.js
CHANGED
|
@@ -25,7 +25,7 @@ const {
|
|
|
25
25
|
fileResultRows,
|
|
26
26
|
} = require('../lib/file-card.js');
|
|
27
27
|
const { createFileCardResolver, registerFileCard } = require('../lib/file-card-resolver.js');
|
|
28
|
-
// The design this package registers on the bridge's `Card
|
|
28
|
+
// The design this package registers on the bridge's `Card tags` line: the card's one
|
|
29
29
|
// switch is that line's answer for the tool being drawn, so the card is only painted
|
|
30
30
|
// for a tool the line actually covers.
|
|
31
31
|
const { toolsActivityDesign } = require('../lib/bash-design.js');
|
|
@@ -564,7 +564,7 @@ test('a foreign, hostile or unreadable bridge never hides the card', () => {
|
|
|
564
564
|
assert.match(draw(), /π odd/u, 'an unknown kind keeps the card');
|
|
565
565
|
});
|
|
566
566
|
|
|
567
|
-
test('S1: a write is covered by the Card
|
|
567
|
+
test('S1: a write is covered by the Card tags line, so its file card paints and `default` restores the host row', () => {
|
|
568
568
|
// A bridge answers from the design's own `tools` list, exactly as it resolves
|
|
569
569
|
// coverage: a tool the line does not name is `not-covered`, which is the host's own
|
|
570
570
|
// card. `write` is declared on that line so the file card can be asked about it.
|
|
@@ -573,15 +573,15 @@ test('S1: a write is covered by the Card tools line, so its file card paints and
|
|
|
573
573
|
publishBridge((tool) => (design.tools.includes(tool) ? { kind: 'design', design } : { kind: 'not-covered' }), asked);
|
|
574
574
|
const resolver = fileResolver();
|
|
575
575
|
for (const tool of ['read', 'write']) {
|
|
576
|
-
assert.equal(design.tools.includes(tool), true, `${tool} is covered by the Card
|
|
576
|
+
assert.equal(design.tools.includes(tool), true, `${tool} is covered by the Card tags line`);
|
|
577
577
|
const row = callRow(resolver, tool, { path: ODD, content: '# x\n' }, plainTheme);
|
|
578
578
|
assert.match(unpaint(row), /π odd/u, `${tool}: the file card paints its heading`);
|
|
579
579
|
assert.match(unpaint(row), new RegExp(`${tool} cards-skill-odd\\.md`, 'u'), `${tool}: and names the call`);
|
|
580
580
|
}
|
|
581
|
-
//
|
|
582
|
-
//
|
|
583
|
-
const edit = resolver
|
|
584
|
-
assert.
|
|
581
|
+
// S3: `edit` is on the line too, scoped to the paths this card claims, so an edit of an
|
|
582
|
+
// ODD artifact wears the file card where no unscoped line could have covered it before.
|
|
583
|
+
const edit = callRow(resolver, 'edit', { path: ODD, oldText: 'a', newText: 'b' }, plainTheme);
|
|
584
|
+
assert.match(unpaint(edit), /π odd/u, 'an edit of an ODD artifact is this card\'s row now');
|
|
585
585
|
assert.deepEqual(asked, ['read', 'write', 'edit'], 'each paint asked about the tool it draws');
|
|
586
586
|
|
|
587
587
|
// `default` is the bridge's `native`: the host draws every row again.
|
|
@@ -593,6 +593,99 @@ test('S1: a write is covered by the Card tools line, so its file card paints and
|
|
|
593
593
|
);
|
|
594
594
|
});
|
|
595
595
|
|
|
596
|
+
// ---- S3/S4/S8: the scoped claim, and the call's arguments that make it answer ----
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* The bridge's own resolution (gentle-shell-bridge 0.9.0), reduced to what this design declares: a
|
|
600
|
+
* tool no line names is `not-covered`; a scope that declines the call, and a call that arrives with
|
|
601
|
+
* no arguments at all, are `native`; everything else is the design.
|
|
602
|
+
*/
|
|
603
|
+
function scopedBridge(design, asked) {
|
|
604
|
+
return {
|
|
605
|
+
schema: 'gentle-shell-bridge/api',
|
|
606
|
+
version: 1,
|
|
607
|
+
VERSION: '0.9.0',
|
|
608
|
+
registerToolDesign: () => () => {},
|
|
609
|
+
resolveToolDesignSelection(tool, args) {
|
|
610
|
+
if (asked !== undefined) asked.push([tool, args]);
|
|
611
|
+
if (!design.tools.includes(tool)) return { kind: 'not-covered' };
|
|
612
|
+
const scopes = design.scopes === null || typeof design.scopes !== 'object' ? {} : design.scopes;
|
|
613
|
+
const scope = Object.hasOwn(scopes, tool) ? scopes[tool] : undefined;
|
|
614
|
+
if (scope === undefined) return { kind: 'design', design };
|
|
615
|
+
if (args === undefined) return { kind: 'native' };
|
|
616
|
+
return scope.matches({ tool, args }) === true ? { kind: 'design', design } : { kind: 'native' };
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function publishScoped(design, asked) {
|
|
622
|
+
const api = scopedBridge(design, asked);
|
|
623
|
+
globalThis[BRIDGE_API_SLOT] = api;
|
|
624
|
+
return api;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
test('S4: the gate asks the bridge with the call\'s own arguments', () => {
|
|
628
|
+
const asked = [];
|
|
629
|
+
publishScoped(toolsActivityDesign(), asked);
|
|
630
|
+
const resolver = fileResolver();
|
|
631
|
+
const callArgs = { path: SKILL, offset: 1, limit: 10 };
|
|
632
|
+
assert.match(unpaint(callRow(resolver, 'read', callArgs, plainTheme)), /β€ skill/u, 'the read card paints');
|
|
633
|
+
const resultArgs = { path: ODD, oldText: 'a', newText: 'b' };
|
|
634
|
+
resolver('edit', () => HOST).renderResult(textResult('ok'), { isPartial: false }, plainTheme, { args: resultArgs }).render(60);
|
|
635
|
+
assert.deepEqual(asked.map(([tool]) => tool), ['read', 'edit'], 'one question per painted tool');
|
|
636
|
+
// A scope is only answerable with the call in hand, so the SAME object the host holds travels
|
|
637
|
+
// with the question β the call's for the call half, the one the result half carries for its own.
|
|
638
|
+
assert.equal(asked[0][1], callArgs, 'the call half passes the arguments, by reference');
|
|
639
|
+
assert.equal(asked[1][1], resultArgs, 'the result half passes the ones it holds');
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
test('S3: a scoped claim paints a write and an edit of a skill or an ODD artifact, and only those', () => {
|
|
643
|
+
publishScoped(toolsActivityDesign());
|
|
644
|
+
const resolver = fileResolver();
|
|
645
|
+
const cases = [
|
|
646
|
+
[SKILL, { content: '# x\n' }, /β€ skill/u, /one\/SKILL\.md/u],
|
|
647
|
+
[ODD, { oldText: 'a', newText: 'b' }, /π odd/u, /cards-skill-odd\.md/u],
|
|
648
|
+
['odd/work/plan.md', { content: '# x\n' }, /π odd/u, /plan\.md/u],
|
|
649
|
+
['a/skills/b/references/deep/x.md', { oldText: 'a', newText: 'b' }, /β€ skill/u, /b\/references\/deep\/x\.md/u],
|
|
650
|
+
];
|
|
651
|
+
for (const [path, extra, identity, name] of cases) {
|
|
652
|
+
for (const tool of ['write', 'edit']) {
|
|
653
|
+
const row = callRow(resolver, tool, { path, ...extra }, plainTheme);
|
|
654
|
+
const text = unpaint(row);
|
|
655
|
+
assert.match(text, identity, `${tool} of ${path} wears its identity`);
|
|
656
|
+
assert.match(text, name, `${tool} of ${path} names its file`);
|
|
657
|
+
assert.ok(text.includes(tool), `${tool} of ${path} names the tool`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
// A path the scope does not claim is no file card's row, so the chain keeps it.
|
|
661
|
+
for (const path of ['src/app.ts', 'lib/skillset/notes.md', 'docs/oddity.md', 'notes/SKILL.md']) {
|
|
662
|
+
for (const tool of ['write', 'edit']) {
|
|
663
|
+
assert.deepEqual(
|
|
664
|
+
forwardedText(resolver(tool, () => HOST).renderCall({ path }, plainTheme, { isPartial: false }).render(60)),
|
|
665
|
+
['host read call'],
|
|
666
|
+
`${tool} of ${path}`,
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
test('S8: read keeps the claim it had, so its card is the scoped line\'s own rows unchanged', () => {
|
|
673
|
+
const draw = (design) => {
|
|
674
|
+
publishScoped(design);
|
|
675
|
+
const resolver = fileResolver();
|
|
676
|
+
return {
|
|
677
|
+
call: callRows(resolver, 'read', { path: SKILL, offset: 1, limit: 10 }, plainTheme),
|
|
678
|
+
result: resultRows(resolver, 'read', { path: SKILL }, textResult('# Design'), { isPartial: false }, plainTheme, 60),
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
const scoped = toolsActivityDesign();
|
|
682
|
+
// The registration an older bridge takes, and the one this card has always been painted by.
|
|
683
|
+
const legacy = toolsActivityDesign({ scopes: false });
|
|
684
|
+
assert.equal(Object.hasOwn(scoped.scopes, 'read'), false, 'read is claimed for every call, never scoped');
|
|
685
|
+
assert.deepEqual(draw(scoped), draw(legacy), 'the same call and result rows, byte for byte');
|
|
686
|
+
assert.match(unpaint(draw(scoped).call[0]), /β€ skill/u, 'and the card still paints its heading');
|
|
687
|
+
});
|
|
688
|
+
|
|
596
689
|
// ---- the host's own outer box, reproduced for every row this card hands back ----
|
|
597
690
|
|
|
598
691
|
test('a forwarded read call draws the host box\'s own blank rows around its rows', () => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// worktreeβissue association.
|
|
14
14
|
//
|
|
15
15
|
// The bash activity is not a preference here: it is a design on gentle-shell-bridge's
|
|
16
|
-
// own `Card
|
|
16
|
+
// own `Card tags` line, so the shipped surface is exactly four commands, two tools, one
|
|
17
17
|
// sidebar section, one tools design and the one `Cards` row group the two file-card
|
|
18
18
|
// switches carry.
|
|
19
19
|
//
|
|
@@ -23,7 +23,7 @@ const { test, describe, after } = require('node:test');
|
|
|
23
23
|
const assert = require('node:assert/strict');
|
|
24
24
|
const fs = require('node:fs');
|
|
25
25
|
const path = require('node:path');
|
|
26
|
-
const { LIB_DIR, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
|
|
26
|
+
const { BRIDGE_SLOT, LIB_DIR, defaultBridge, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
|
|
27
27
|
|
|
28
28
|
const ROOT = path.resolve(__dirname, '..');
|
|
29
29
|
const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
|
|
@@ -72,8 +72,8 @@ describe('manifest', () => {
|
|
|
72
72
|
// classifier and the one design registered on the bridge. The file cards add
|
|
73
73
|
// their own four modules β a classifier, the card, its resolver and the document
|
|
74
74
|
// body Pi's Markdown draws β and own no preference at all (S1): they are gated by
|
|
75
|
-
// the bridge's `Card
|
|
76
|
-
for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'bash-activity.js', 'bash-design.js', 'bash-frame.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
|
|
75
|
+
// the bridge's `Card tags` line, which is the bridge's, not ours.
|
|
76
|
+
for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'bash-activity.js', 'bash-design.js', 'bash-frame.js', 'diff-design.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
|
|
77
77
|
assert.ok(shipped.includes(kept), `lib/${kept} is shipped`);
|
|
78
78
|
}
|
|
79
79
|
for (const gone of ['card-files-mode.js', 'cards-customize.js']) {
|
|
@@ -106,7 +106,7 @@ describe('registration', () => {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// S1: the two file-card switches and their document are gone, and the extension
|
|
109
|
-
// names neither. The file card is gated by the bridge's own `Card
|
|
109
|
+
// names neither. The file card is gated by the bridge's own `Card tags` line.
|
|
110
110
|
assert.equal(source.includes('registerCardsCustomize'), false, 'no row provider is registered for a switch');
|
|
111
111
|
assert.equal(source.includes('card-files'), false, 'the extension never names their document');
|
|
112
112
|
const modules = fs.readdirSync(lib).filter((entry) => entry.endsWith('.js'));
|
|
@@ -137,6 +137,26 @@ describe('registration', () => {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
test('both Card rows are registered once each, observed through the bridge\'s own object', async () => {
|
|
141
|
+
// S2/S6: what a caller observes is the REGISTRATION, not a spelling in the source. A bridge
|
|
142
|
+
// that publishes the release both lines need sees one design per line, each with its own id and
|
|
143
|
+
// label, and nothing else β so a second registration, a renamed id or a third row fails here.
|
|
144
|
+
const bridge = defaultBridge();
|
|
145
|
+
bridge.api.VERSION = '0.9.0';
|
|
146
|
+
const previous = globalThis[BRIDGE_SLOT];
|
|
147
|
+
globalThis[BRIDGE_SLOT] = bridge.api;
|
|
148
|
+
try {
|
|
149
|
+
await loadExtension({});
|
|
150
|
+
assert.deepEqual(
|
|
151
|
+
bridge.designs.map((design) => [design.line, design.id, design.label]),
|
|
152
|
+
[['tags', 'odd-worktree.bash-activity', 'activity'], ['diff', 'odd-worktree.diff', 'color']],
|
|
153
|
+
'one design per line, once each',
|
|
154
|
+
);
|
|
155
|
+
} finally {
|
|
156
|
+
globalThis[BRIDGE_SLOT] = previous;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
140
160
|
test('the file cards register through one hook call and own no preference (T2)', async () => {
|
|
141
161
|
// S1/S7: the card is drawn through the host's `registerToolRenderer`, and the ONE switch
|
|
142
162
|
// it obeys is the bridge's own line, asked through the published reader on every paint.
|