pi-odd-worktree 3.0.0 → 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 +107 -15
- package/lib/bash-activity.js +7 -5
- 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/lib/files-picker-view.js +22 -17
- package/lib/gh-issues.js +15 -1
- package/package.json +1 -1
- package/tools/bash-activity.test.js +6 -5
- package/tools/bash-design.test.js +308 -9
- package/tools/diff-design.test.js +635 -0
- package/tools/file-card.test.js +100 -7
- package/tools/files-command.test.js +4 -1
- package/tools/files-picker-view.test.js +23 -5
- package/tools/gh-issues.test.js +26 -0
- package/tools/issues-command.test.js +5 -1
- package/tools/issues-section.test.js +40 -0
- package/tools/package-surface.test.js +25 -5
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// * WHICH ROWS IT CLAIMS. `read`, `edit` and `write` only, and only when the host
|
|
14
14
|
// offers a usable measurement seam. Whether one particular CALL is this card's is
|
|
15
15
|
// decided per call, inside the slots (`lib/file-card.js`): the path's identity and
|
|
16
|
-
// the bridge's `Card
|
|
16
|
+
// the bridge's `Card tags` line are read on every paint, so a row whose path names
|
|
17
17
|
// neither is the chain's own drawing and a switch flipped while the transcript is
|
|
18
18
|
// on screen repaints the row already there.
|
|
19
19
|
// * THE SEAMS. Text measurement and Pi's Markdown renderer are injected, so a host
|
|
@@ -38,7 +38,7 @@ const { loadMarkdownClass } = require('./file-card-markdown.js');
|
|
|
38
38
|
// ---- the one switch (S1/S7) ----
|
|
39
39
|
//
|
|
40
40
|
// The file card no longer owns a preference: it is painted while the bridge's
|
|
41
|
-
// `Card
|
|
41
|
+
// `Card tags` line answers that this package's activity design draws the tool being
|
|
42
42
|
// drawn, and the host's own card is painted for every other value (the bridge's
|
|
43
43
|
// `native`, a design that has left the line, and a design that does not cover this
|
|
44
44
|
// tool alike).
|
|
@@ -74,12 +74,20 @@ function bridgeApi() {
|
|
|
74
74
|
* card. The bridge's reader never throws (an absent or unreadable store answers
|
|
75
75
|
* `native`), and this one does not either: an answer it cannot read keeps the card
|
|
76
76
|
* visible rather than hiding a row behind a version it does not know.
|
|
77
|
+
*
|
|
78
|
+
* S4: the call's own `args` travel with the question, because the line's claim on `write`
|
|
79
|
+
* and `edit` is a SCOPE (gentle-shell-bridge@0.9.0) — a predicate over `{ tool, args }`,
|
|
80
|
+
* answered per CALL. Without them the bridge cannot tell a skill's path from any other
|
|
81
|
+
* write, and this card would paint a call another line owns. The object is the host's
|
|
82
|
+
* own, by reference and never copied: the scope reads only its stable `path`. A bridge
|
|
83
|
+
* whose reader takes no second argument ignores it and answers exactly as before, and
|
|
84
|
+
* an older bridge reads the call as unknown, which is what it has always done.
|
|
77
85
|
*/
|
|
78
|
-
function activitySelected(tool) {
|
|
86
|
+
function activitySelected(tool, args) {
|
|
79
87
|
const api = bridgeApi();
|
|
80
88
|
if (api === undefined || typeof api.resolveToolDesignSelection !== 'function') return true;
|
|
81
89
|
try {
|
|
82
|
-
const selection = api.resolveToolDesignSelection(tool);
|
|
90
|
+
const selection = api.resolveToolDesignSelection(tool, args);
|
|
83
91
|
const answer = selection !== null && typeof selection === 'object' ? selection : {};
|
|
84
92
|
if (answer.kind === 'native' || answer.kind === 'missing' || answer.kind === 'not-covered') return false;
|
|
85
93
|
if (answer.kind !== 'design') return true;
|
|
@@ -153,13 +161,15 @@ function createFileCardResolver(options) {
|
|
|
153
161
|
}
|
|
154
162
|
},
|
|
155
163
|
/**
|
|
156
|
-
* The one switch, read now (S1/S7): the bridge's `Card
|
|
157
|
-
* activity design for `tool
|
|
158
|
-
*
|
|
164
|
+
* The one switch, read now (S1/S7): the bridge's `Card tags` line answers with the
|
|
165
|
+
* activity design for `tool` — and, since a claim can be scoped, for THIS call: the
|
|
166
|
+
* call's `args` are handed over with the question (S4). A bridge with no reader —
|
|
167
|
+
* older than 0.7.0, or none at all — paints the card, which is the behaviour it had
|
|
168
|
+
* before; a reader that takes one argument ignores the second and answers as it did.
|
|
159
169
|
*/
|
|
160
|
-
enabled(tool) {
|
|
170
|
+
enabled(tool, args) {
|
|
161
171
|
try {
|
|
162
|
-
return activitySelected(tool) === true;
|
|
172
|
+
return activitySelected(tool, args) === true;
|
|
163
173
|
} catch {
|
|
164
174
|
return true;
|
|
165
175
|
}
|
package/lib/file-card.js
CHANGED
|
@@ -521,7 +521,7 @@ function fileResultRows(input) {
|
|
|
521
521
|
/**
|
|
522
522
|
* The call slot. The identity and the ONE switch are both decided INSIDE the
|
|
523
523
|
* component's build, so the host's `render(width)` re-reads them on every frame: a card
|
|
524
|
-
* already on screen repaints when the bridge's `Card
|
|
524
|
+
* already on screen repaints when the bridge's `Card tags` line changes (L6), and the
|
|
525
525
|
* measurement seam is asked for at paint time rather than at construction.
|
|
526
526
|
*
|
|
527
527
|
* A path that names neither identity returns the chain's own component straight away,
|
|
@@ -544,7 +544,10 @@ function fileCallSlot(tool, inherited, seams, shell) {
|
|
|
544
544
|
return hostShellComponent(forwardedComponent(inherited, 'renderCall', [args, theme, context]), ctx, paint, seams, layout);
|
|
545
545
|
}
|
|
546
546
|
return component((width) => {
|
|
547
|
-
|
|
547
|
+
// S4: the call's own arguments travel with the question, so a SCOPE on the
|
|
548
|
+
// bridge's line (`write` and `edit`, paths under `skills/` or `odd/`) can answer
|
|
549
|
+
// for THIS call and no other.
|
|
550
|
+
if (!seams.enabled(tool, callArgs)) {
|
|
548
551
|
return hostShellRows(forwardedComponent(inherited, 'renderCall', [args, theme, context]), width, ctx, paint, seams, layout);
|
|
549
552
|
}
|
|
550
553
|
const metrics = seams.metrics();
|
|
@@ -583,7 +586,10 @@ function fileResultSlot(tool, inherited, seams, shell) {
|
|
|
583
586
|
return hostShellComponent(forwardedComponent(inherited, 'renderResult', slotArgs), boxContext, paint, seams, layout);
|
|
584
587
|
}
|
|
585
588
|
return component((width) => {
|
|
586
|
-
|
|
589
|
+
// S4: the result half asks the same question of the same call, with the arguments
|
|
590
|
+
// it holds (`ctx.args`), so both halves of one card are resolved against the same
|
|
591
|
+
// call and no half is asked a different question.
|
|
592
|
+
if (!seams.enabled(tool, args)) {
|
|
587
593
|
return hostShellRows(forwardedComponent(inherited, 'renderResult', slotArgs), width, boxContext, paint, seams, layout);
|
|
588
594
|
}
|
|
589
595
|
const metrics = seams.metrics();
|
package/lib/files-picker-view.js
CHANGED
|
@@ -44,6 +44,12 @@
|
|
|
44
44
|
// that held the file (S39), and the footer legend names the action it performs
|
|
45
45
|
// (S40).
|
|
46
46
|
//
|
|
47
|
+
// Round L22 (S43) gives `enter` back to inserting alone: it is the whole payload
|
|
48
|
+
// rule of S7 on a file row, and on a group row — never inserted, S24 and S38 stand —
|
|
49
|
+
// the Tab selection alone, so with no mark it sends nothing and the panel stays
|
|
50
|
+
// open. Folding belongs to `space` (S10, S32), `shift+space` (S39) and the click
|
|
51
|
+
// (S38) only, which is what the footer's `enter insert` has always said.
|
|
52
|
+
//
|
|
47
53
|
// The shapes it consumes are the module contracts in `odd/tasks/files-picker.md`:
|
|
48
54
|
// `loadEntries()` resolves `{ ok: true, entries } | { ok: false, message }` with
|
|
49
55
|
// entries already changed-first; `loadPreview(path)` resolves one
|
|
@@ -544,14 +550,14 @@ function createFilesPickerView(options = {}) {
|
|
|
544
550
|
}
|
|
545
551
|
|
|
546
552
|
/**
|
|
547
|
-
* space
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
553
|
+
* space folds a group (S10, S32). The cursor rests on a group row — every row of a
|
|
554
|
+
* tree order takes it (S38) — so the row folds itself; on a file row the group
|
|
555
|
+
* folded is the one HOLDING that file, its folder in `tree` and its extension group
|
|
556
|
+
* in `ext`. The toggled group row is then the row the cursor keeps, which is the IDE
|
|
557
|
+
* behaviour the reader asked for and a row that always paints. A file at the
|
|
558
|
+
* repository root has no folder to fold, a non-empty query holds every group open,
|
|
559
|
+
* and the flat `files` order paints no group at all, so the key is inert in all
|
|
560
|
+
* three cases. `enter` never folds (S43).
|
|
555
561
|
*/
|
|
556
562
|
function toggleFocusedGroup() {
|
|
557
563
|
if (order === FLAT_ORDER || query.length > 0) return false;
|
|
@@ -1291,13 +1297,12 @@ function createFilesPickerView(options = {}) {
|
|
|
1291
1297
|
return;
|
|
1292
1298
|
}
|
|
1293
1299
|
if (keyMatches(data, ['enter'])) {
|
|
1294
|
-
//
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
}
|
|
1300
|
+
// S43: enter is ONLY the insert key, in every order. On a file row the payload
|
|
1301
|
+
// is the Tab marks plus the focused file (S7); on a group row it is the Tab
|
|
1302
|
+
// marks alone, and `finish('insert')` sends nothing while none are marked. The
|
|
1303
|
+
// panel never folds here — folding stays on space (S10, S32), shift+space (S39)
|
|
1304
|
+
// and the click (S38).
|
|
1305
|
+
finish('insert');
|
|
1301
1306
|
return;
|
|
1302
1307
|
}
|
|
1303
1308
|
if (keyMatches(data, ['ctrl+e'])) {
|
|
@@ -1371,8 +1376,8 @@ function createFilesPickerView(options = {}) {
|
|
|
1371
1376
|
if (row !== undefined && row.kind === 'group') {
|
|
1372
1377
|
// S38: a click parks the cursor on the group row exactly as on a file row, and
|
|
1373
1378
|
// S10's fold still happens with it, so the reader lands on the row it clicked
|
|
1374
|
-
// and `space
|
|
1375
|
-
// only the focus moves then.
|
|
1379
|
+
// and `space` then has that row (S43 leaves `enter` to insert). A query holds
|
|
1380
|
+
// every group open, so only the focus moves then.
|
|
1376
1381
|
const focused = selectRow(hit.index);
|
|
1377
1382
|
if (query.length > 0) {
|
|
1378
1383
|
if (focused) repaint();
|
package/lib/gh-issues.js
CHANGED
|
@@ -759,6 +759,14 @@ async function runGh(argv, opts = {}) {
|
|
|
759
759
|
|
|
760
760
|
// Failure text for a non-zero `gh` exit: prefer stderr (where gh explains
|
|
761
761
|
// auth and resolution problems), fall back to the bare status.
|
|
762
|
+
// gh's own answer when the checkout has no remote at all: there is nothing to
|
|
763
|
+
// resolve FROM, so it cannot name a repository. It is a STATE of the checkout,
|
|
764
|
+
// not a failure of `gh` (authentication, network, a broken install), and a
|
|
765
|
+
// caller that draws states needs to tell the two apart. Matched on gh's text
|
|
766
|
+
// because that is all gh reports; an unknown wording just degrades to the
|
|
767
|
+
// failure it already was.
|
|
768
|
+
const NO_GIT_REMOTE_PATTERN = /no git remotes/i;
|
|
769
|
+
|
|
762
770
|
function exitError(outcome, what) {
|
|
763
771
|
const stderr = (outcome.stderr || '').trim();
|
|
764
772
|
if (stderr) return `${what}: ${stderr.split('\n')[0].slice(0, 500)}`;
|
|
@@ -1021,7 +1029,13 @@ async function reportedRepoName(opts = {}) {
|
|
|
1021
1029
|
// failure still prevents this gh call).
|
|
1022
1030
|
const repo = await runGh(['repo', 'view', '--json', 'nameWithOwner'], opts);
|
|
1023
1031
|
if (repo.error) return { ok: false, error: repo.error };
|
|
1024
|
-
if (repo.status !== 0)
|
|
1032
|
+
if (repo.status !== 0) {
|
|
1033
|
+
return {
|
|
1034
|
+
ok: false,
|
|
1035
|
+
error: exitError(repo, 'cannot resolve the repository'),
|
|
1036
|
+
...(NO_GIT_REMOTE_PATTERN.test(repo.stderr || '') ? { noRemote: true } : {}),
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1025
1039
|
const parsedRepo = parseJsonBody(repo.stdout, 'gh repo view');
|
|
1026
1040
|
if (!parsedRepo.ok) return parsedRepo;
|
|
1027
1041
|
const reported = parsedRepo.doc && typeof parsedRepo.doc.nameWithOwner === 'string'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.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",
|
|
@@ -70,9 +70,10 @@ test('every activity wears its own mark and a theme role', () => {
|
|
|
70
70
|
checking: { glyph: '✓', titleRole: 'mdHeading' },
|
|
71
71
|
formatting: { glyph: '≋', titleRole: 'syntaxFunction' },
|
|
72
72
|
// U+2692 is painted two cells wide by an emoji-fallback font while the host
|
|
73
|
-
// counts it as one,
|
|
74
|
-
//
|
|
75
|
-
|
|
73
|
+
// counts it as one, and that font eats the space right after it: two gaps are
|
|
74
|
+
// what leaves one VISIBLE column (`⚒ preparing`) while the counted width still
|
|
75
|
+
// matches what the terminal paints.
|
|
76
|
+
preparing: { glyph: '⚒ ', titleRole: 'syntaxFunction' },
|
|
76
77
|
publishing: { glyph: '↑', titleRole: 'success' },
|
|
77
78
|
versioning: { glyph: '⎇', titleRole: 'warning' },
|
|
78
79
|
// The native tool's own mark, so the shell call and the tool read as one card.
|
|
@@ -98,7 +99,7 @@ test('every activity wears its own mark and a theme role', () => {
|
|
|
98
99
|
test('a mark costs one counted column, plus preparing\'s declared gap', () => {
|
|
99
100
|
for (const activity of SHELL_ACTIVITIES) {
|
|
100
101
|
const { glyph } = SHELL_ACTIVITY_IDENTITY[activity];
|
|
101
|
-
assert.equal([...glyph].length, activity === 'preparing' ?
|
|
102
|
+
assert.equal([...glyph].length, activity === 'preparing' ? 3 : 1, `${activity}: one mark, plus its own gaps`);
|
|
102
103
|
assert.equal(glyph.trimStart(), glyph, `${activity}: a mark never starts with its gap`);
|
|
103
104
|
}
|
|
104
105
|
});
|
|
@@ -106,7 +107,7 @@ test('a mark costs one counted column, plus preparing\'s declared gap', () => {
|
|
|
106
107
|
test('the host measures every mark at the width the heading assumes', { skip: visibleWidth ? false : 'requires @earendil-works/pi-tui' }, () => {
|
|
107
108
|
for (const activity of SHELL_ACTIVITIES) {
|
|
108
109
|
const { glyph } = SHELL_ACTIVITY_IDENTITY[activity];
|
|
109
|
-
assert.equal(visibleWidth(glyph), activity === 'preparing' ?
|
|
110
|
+
assert.equal(visibleWidth(glyph), activity === 'preparing' ? 3 : 1, `${activity}: one counted column plus its own gaps`);
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
|
|
@@ -7,9 +7,14 @@ const {
|
|
|
7
7
|
BASH_DESIGN_LABEL,
|
|
8
8
|
applyBashActivityHeading,
|
|
9
9
|
bashActivityDesign,
|
|
10
|
+
carryOverLineSelection,
|
|
10
11
|
registerBashDesign,
|
|
11
12
|
seedBashDesignSelection,
|
|
13
|
+
toolsActivityDesign,
|
|
12
14
|
} = require('../lib/bash-design.js');
|
|
15
|
+
// The second line this package registers. Its own suite owns its drawing; the release rule below is
|
|
16
|
+
// here because one `VERSION` decides both lines at once.
|
|
17
|
+
const { registerDiffDesign } = require('../lib/diff-design.js');
|
|
13
18
|
|
|
14
19
|
const CALL = { tool: 'bash', part: 'call', width: 90 };
|
|
15
20
|
const strip = (row) => row.replace(/\u001b\[[0-9;]*m/g, '');
|
|
@@ -37,7 +42,9 @@ describe('the heading', () => {
|
|
|
37
42
|
});
|
|
38
43
|
|
|
39
44
|
test('the other families get their own mark and word', () => {
|
|
40
|
-
|
|
45
|
+
// `preparing` keeps TWO gaps after U+2692: an emoji-fallback font paints the
|
|
46
|
+
// glyph two cells wide and eats the first space, so one gap would read `⚒preparing`.
|
|
47
|
+
const cases = [['node --test tools/*.test.js', '✓ checking'], ['rm -rf build', '⚠ destructive'], ['git commit -m wip', '⎇ versioning'], ['pnpm install', '⚒ preparing']];
|
|
41
48
|
for (const [command, heading] of cases) {
|
|
42
49
|
const [out] = applyBashActivityHeading([neon(command)], CALL);
|
|
43
50
|
assert.ok(strip(out).includes(heading), `${command} -> ${heading}`);
|
|
@@ -831,7 +838,7 @@ const designFor = (version) => {
|
|
|
831
838
|
return seen.find((design) => design.id !== 'odd-worktree.capability-probe');
|
|
832
839
|
};
|
|
833
840
|
|
|
834
|
-
describe('the Card
|
|
841
|
+
describe('the Card tags line', () => {
|
|
835
842
|
test('the line declares `read` and `write` so the file card can be asked about them, and the design paints nothing for either', () => {
|
|
836
843
|
// S1: the file card is painted only while this line resolves to the activity design
|
|
837
844
|
// for the tool being drawn, and a bridge resolves coverage from the line's own
|
|
@@ -858,7 +865,7 @@ describe('the Card tools line', () => {
|
|
|
858
865
|
|
|
859
866
|
test('a 0.6.0 bridge gets ONE grouped registration over bash and the read-only tools', () => {
|
|
860
867
|
const design = designFor('0.6.0');
|
|
861
|
-
assert.equal(design.line, '
|
|
868
|
+
assert.equal(design.line, 'tags', 'the row the bridge derives is `Card tags` (S10)');
|
|
862
869
|
assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write']);
|
|
863
870
|
assert.equal(Object.hasOwn(design, 'tool'), false, 'never both shapes');
|
|
864
871
|
assert.equal(design.id, BASH_DESIGN_ID);
|
|
@@ -874,7 +881,7 @@ describe('the Card tools line', () => {
|
|
|
874
881
|
|
|
875
882
|
test('every release from 0.6.0 up gets the line', () => {
|
|
876
883
|
for (const version of ['0.6.0', '0.6.1', '0.10.0', '0.7.0-rc.1', '1.0.0', '0.6']) {
|
|
877
|
-
assert.equal(designFor(version).line, '
|
|
884
|
+
assert.equal(designFor(version).line, 'tags', version);
|
|
878
885
|
}
|
|
879
886
|
});
|
|
880
887
|
|
|
@@ -904,7 +911,7 @@ describe('the Card tools line', () => {
|
|
|
904
911
|
try {
|
|
905
912
|
assert.equal(registerBashDesign(api), dispose);
|
|
906
913
|
assert.equal(seen.length, 1);
|
|
907
|
-
assert.equal(seen[0].line, '
|
|
914
|
+
assert.equal(seen[0].line, 'tags');
|
|
908
915
|
} finally {
|
|
909
916
|
dispose();
|
|
910
917
|
}
|
|
@@ -1048,8 +1055,8 @@ describe('the seed runs before the registration', () => {
|
|
|
1048
1055
|
api.registerToolDesign = () => {
|
|
1049
1056
|
const selections = store['bridge-tool-designs']?.selections ?? {};
|
|
1050
1057
|
inherited.push(JSON.parse(JSON.stringify(selections)));
|
|
1051
|
-
if (typeof selections.bash === 'string' && selections.bash !== 'native' && selections.$lines?.
|
|
1052
|
-
store['bridge-tool-designs'] = { ...store['bridge-tool-designs'], selections: { ...selections, $lines: {
|
|
1058
|
+
if (typeof selections.bash === 'string' && selections.bash !== 'native' && selections.$lines?.tags === undefined) {
|
|
1059
|
+
store['bridge-tool-designs'] = { ...store['bridge-tool-designs'], selections: { ...selections, $lines: { tags: selections.bash } } };
|
|
1053
1060
|
}
|
|
1054
1061
|
return () => {};
|
|
1055
1062
|
};
|
|
@@ -1062,7 +1069,7 @@ describe('the seed runs before the registration', () => {
|
|
|
1062
1069
|
assert.equal(typeof dispose, 'function');
|
|
1063
1070
|
dispose();
|
|
1064
1071
|
assert.deepEqual(inherited[0], { bash: BASH_DESIGN_ID }, 'the seed was already stored when the bridge registered');
|
|
1065
|
-
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID, $lines: {
|
|
1072
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID, $lines: { tags: BASH_DESIGN_ID } });
|
|
1066
1073
|
});
|
|
1067
1074
|
|
|
1068
1075
|
test('a stored legacy choice is kept: the seed writes no selection and the line inherits that choice', () => {
|
|
@@ -1070,7 +1077,7 @@ describe('the seed runs before the registration', () => {
|
|
|
1070
1077
|
const dispose = registerBashDesign(api);
|
|
1071
1078
|
dispose();
|
|
1072
1079
|
assert.deepEqual(writes.filter(([store]) => store === SELECTIONS[0]), [], 'no selection was written');
|
|
1073
|
-
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: 'someone.else', $lines: {
|
|
1080
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: 'someone.else', $lines: { tags: 'someone.else' } });
|
|
1074
1081
|
});
|
|
1075
1082
|
|
|
1076
1083
|
test('the seed never writes the reserved line key itself', () => {
|
|
@@ -1081,6 +1088,18 @@ describe('the seed runs before the registration', () => {
|
|
|
1081
1088
|
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID }, 'no $lines from this package');
|
|
1082
1089
|
});
|
|
1083
1090
|
|
|
1091
|
+
test('a stored line choice survives the rename: the carry-over takes the key first', () => {
|
|
1092
|
+
// S10: a user who chose `default` on `Card tools` has `$lines.tools` = `native`, while the
|
|
1093
|
+
// first-run seed left `bash` = `activity`. A bare rename would leave `$lines.tags` absent and the
|
|
1094
|
+
// bridge's own migration would resurrect that stale `activity`; the carry-over makes it a no-op.
|
|
1095
|
+
const stored = { 'bridge-tool-designs': { selections: { bash: BASH_DESIGN_ID, $lines: { tools: 'native' } } } };
|
|
1096
|
+
const { api, files, inherited } = migratingBridge(stored);
|
|
1097
|
+
const dispose = registerBashDesign(api);
|
|
1098
|
+
dispose();
|
|
1099
|
+
assert.deepEqual(inherited[0].$lines, { tags: 'native' }, 'the bridge registered with the new key already taken');
|
|
1100
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID, $lines: { tags: 'native' } }, 'the user keeps `default`');
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1084
1103
|
test('an old bridge keeps today\'s per-tool choice, with no line value', () => {
|
|
1085
1104
|
const { api, files } = fakeBridge();
|
|
1086
1105
|
api.VERSION = '0.5.0';
|
|
@@ -1089,3 +1108,283 @@ describe('the seed runs before the registration', () => {
|
|
|
1089
1108
|
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID });
|
|
1090
1109
|
});
|
|
1091
1110
|
});
|
|
1111
|
+
|
|
1112
|
+
// S10: the row name is the bridge's, derived from the LINE KEY itself — `Card ` + the line, a line has
|
|
1113
|
+
// no label of its own — so
|
|
1114
|
+
// `Card tools` becoming `Card tags` is a rename of this package's line. The bridge has no rename or
|
|
1115
|
+
// alias path, and its own registration-time migration treats an ABSENT line key as "inherit the
|
|
1116
|
+
// joining tool's legacy per-tool value", which is exactly the `bash` = `activity` this package seeds
|
|
1117
|
+
// on a first run: a bare rename would hand `activity` back to a user who had chosen `default`. So the
|
|
1118
|
+
// package carries the stored value over itself, BEFORE it registers, and the bridge then finds the
|
|
1119
|
+
// line's key taken.
|
|
1120
|
+
describe('the `Card tools` -> `Card tags` carry-over', () => {
|
|
1121
|
+
const stored = (selections) => ({ 'bridge-tool-designs': { selections } });
|
|
1122
|
+
|
|
1123
|
+
test('a stored tools value becomes the tags value and the old key is gone', () => {
|
|
1124
|
+
for (const chosen of ['native', 'someone.else']) {
|
|
1125
|
+
const { api, files } = fakeBridge(stored({ bash: BASH_DESIGN_ID, $lines: { tools: chosen } }));
|
|
1126
|
+
assert.equal(carryOverLineSelection(api), true, chosen);
|
|
1127
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { bash: BASH_DESIGN_ID, $lines: { tags: chosen } }, chosen);
|
|
1128
|
+
assert.equal(Object.hasOwn(files['bridge-tool-designs'].selections.$lines, 'tools'), false, `${chosen}: no tools key is left`);
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
test('a store with no tools value writes nothing', () => {
|
|
1133
|
+
const untouched = [
|
|
1134
|
+
{},
|
|
1135
|
+
{ bash: 'native' },
|
|
1136
|
+
{ bash: 'native', $lines: {} },
|
|
1137
|
+
{ bash: 'native', $lines: { diff: 'odd-worktree.diff-color' } },
|
|
1138
|
+
];
|
|
1139
|
+
for (const selections of untouched) {
|
|
1140
|
+
const { api, files, writes } = fakeBridge(stored(selections));
|
|
1141
|
+
assert.equal(carryOverLineSelection(api), false, JSON.stringify(selections));
|
|
1142
|
+
assert.deepEqual(writes, [], JSON.stringify(selections));
|
|
1143
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, selections);
|
|
1144
|
+
}
|
|
1145
|
+
// No store file at all is the first run, not a rename.
|
|
1146
|
+
const fresh = fakeBridge();
|
|
1147
|
+
assert.equal(carryOverLineSelection(fresh.api), false);
|
|
1148
|
+
assert.deepEqual(fresh.writes, []);
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
test('an invalid stored value is never migrated: the document stays byte-identical and nothing is written', () => {
|
|
1152
|
+
// The bridge's own `storedId` reads a line value as a choice only when it is a non-empty,
|
|
1153
|
+
// non-blank id string (`native` included). Copying anything else would write garbage under the
|
|
1154
|
+
// new key and delete the old one, so an invalid value is NO migration at all.
|
|
1155
|
+
for (const chosen of [42, null, {}, ' ', '', ['native'], false]) {
|
|
1156
|
+
const selections = { bash: BASH_DESIGN_ID, $lines: { tools: chosen } };
|
|
1157
|
+
const before = JSON.stringify(selections);
|
|
1158
|
+
const { api, files, writes } = fakeBridge(stored(selections));
|
|
1159
|
+
assert.equal(carryOverLineSelection(api), false, JSON.stringify(chosen));
|
|
1160
|
+
assert.deepEqual(writes, [], `${JSON.stringify(chosen)}: nothing was written`);
|
|
1161
|
+
assert.equal(JSON.stringify(files['bridge-tool-designs'].selections), before, `${JSON.stringify(chosen)}: byte-identical`);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
test('a value already stored at tags is never overwritten', () => {
|
|
1166
|
+
const selections = { bash: BASH_DESIGN_ID, $lines: { tags: 'someone.else', tools: 'native' } };
|
|
1167
|
+
const { api, files, writes } = fakeBridge(stored(selections));
|
|
1168
|
+
assert.equal(carryOverLineSelection(api), false);
|
|
1169
|
+
assert.deepEqual(writes, [], 'nothing was written');
|
|
1170
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, selections, 'neither key is touched');
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
test('a malformed, foreign or refusing store writes nothing and never throws', () => {
|
|
1174
|
+
const foreign = [
|
|
1175
|
+
stored('oops'),
|
|
1176
|
+
stored({ $lines: 'oops' }),
|
|
1177
|
+
stored({ $lines: ['tools'] }),
|
|
1178
|
+
stored({ $lines: 42 }),
|
|
1179
|
+
{ 'someone-else': { selections: { $lines: { tools: 'native' } } } },
|
|
1180
|
+
{},
|
|
1181
|
+
];
|
|
1182
|
+
for (const files of foreign) {
|
|
1183
|
+
const { api, writes } = fakeBridge(files);
|
|
1184
|
+
assert.doesNotThrow(() => carryOverLineSelection(api), JSON.stringify(files));
|
|
1185
|
+
assert.equal(carryOverLineSelection(api), false, JSON.stringify(files));
|
|
1186
|
+
assert.deepEqual(writes, [], JSON.stringify(files));
|
|
1187
|
+
}
|
|
1188
|
+
const refusing = { createStore: () => { throw new Error('disk full'); } };
|
|
1189
|
+
assert.doesNotThrow(() => carryOverLineSelection(refusing));
|
|
1190
|
+
assert.equal(carryOverLineSelection(refusing), false);
|
|
1191
|
+
assert.equal(carryOverLineSelection({}), false);
|
|
1192
|
+
assert.equal(carryOverLineSelection(null), false);
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
test('it writes the bridge\'s own store and nothing else', () => {
|
|
1196
|
+
const { api, writes } = fakeBridge(stored({ $lines: { tools: 'native' } }));
|
|
1197
|
+
assert.equal(carryOverLineSelection(api), true);
|
|
1198
|
+
assert.deepEqual(writes, [SELECTIONS], 'one document, the bridge\'s, never a marker of ours');
|
|
1199
|
+
});
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
// S3/S6: the grouped `tags` line claims `write` and `edit` only for the paths the file card itself
|
|
1203
|
+
// claims — `lib/skill-odd-card.js`'s own rule, reused and never copied — so a skill or an ODD
|
|
1204
|
+
// artifact keeps the file card it has today while every other write is another line's call. The
|
|
1205
|
+
// scope is a 0.9.0 member, so the shape is decided before anything is registered: an older bridge
|
|
1206
|
+
// takes today's unscoped list, which is exactly the registration it has always accepted.
|
|
1207
|
+
describe('the scoped claim', () => {
|
|
1208
|
+
test('one shared scope owns exactly the paths under a skills/ or an odd/ folder', () => {
|
|
1209
|
+
const design = toolsActivityDesign();
|
|
1210
|
+
const scope = design.scopes.write;
|
|
1211
|
+
assert.equal(scope, design.scopes.edit, 'ONE shared scope object, so the two tools can never disagree');
|
|
1212
|
+
assert.equal(scope.description, 'paths under skills/ or odd/');
|
|
1213
|
+
assert.doesNotMatch(scope.description, /[\r\n]/u, 'the description is one line');
|
|
1214
|
+
const owned = [
|
|
1215
|
+
'skills/one/SKILL.md',
|
|
1216
|
+
'lib/skills/one/references/deep/x.md',
|
|
1217
|
+
'odd/tasks/a.md',
|
|
1218
|
+
'odd/work/a.md',
|
|
1219
|
+
'a\\skills\\b\\c.md',
|
|
1220
|
+
'ODD/tasks/a.md',
|
|
1221
|
+
];
|
|
1222
|
+
for (const path of owned) assert.equal(scope.matches({ tool: 'write', args: { path } }), true, path);
|
|
1223
|
+
const foreign = [
|
|
1224
|
+
'src/app.ts',
|
|
1225
|
+
'lib/bash-design.js',
|
|
1226
|
+
'lib/skillset/notes.md',
|
|
1227
|
+
'docs/oddity.md',
|
|
1228
|
+
'odd-work/a.md',
|
|
1229
|
+
'notes/SKILL.md',
|
|
1230
|
+
'skills',
|
|
1231
|
+
'',
|
|
1232
|
+
];
|
|
1233
|
+
for (const path of foreign) assert.equal(scope.matches({ tool: 'write', args: { path } }), false, JSON.stringify(path));
|
|
1234
|
+
// A call with no arguments, or with arguments that are not an object, names no file at all.
|
|
1235
|
+
for (const call of [undefined, null, {}, { tool: 'write' }, { tool: 'write', args: null }, { tool: 'write', args: 'src' }, { tool: 'write', args: 42 }]) {
|
|
1236
|
+
assert.equal(scope.matches(call), false, JSON.stringify(call));
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
|
|
1240
|
+
test('the line gains edit, and every other tool keeps its whole claim', () => {
|
|
1241
|
+
const design = toolsActivityDesign();
|
|
1242
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'edit']);
|
|
1243
|
+
for (const tool of ['bash', 'grep', 'find', 'ls', 'read']) {
|
|
1244
|
+
assert.equal(Object.hasOwn(design.scopes, tool), false, `${tool} is claimed for every call`);
|
|
1245
|
+
}
|
|
1246
|
+
for (const tool of ['write', 'edit']) assert.equal(Object.hasOwn(design.scopes, tool), true, tool);
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
const registering = (version) => {
|
|
1250
|
+
const calls = [];
|
|
1251
|
+
return {
|
|
1252
|
+
calls,
|
|
1253
|
+
api: {
|
|
1254
|
+
VERSION: version,
|
|
1255
|
+
registerToolDesign: (design) => {
|
|
1256
|
+
calls.push(design);
|
|
1257
|
+
return () => {};
|
|
1258
|
+
},
|
|
1259
|
+
},
|
|
1260
|
+
};
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
test('a bridge older than 0.9.0 registers today\'s unscoped line, without edit', () => {
|
|
1264
|
+
const cases = [['0.6.0', false], ['0.8.9', false], ['0.9.0', true], ['0.10.0', true], ['1.0.0', true]];
|
|
1265
|
+
for (const [version, scoped] of cases) {
|
|
1266
|
+
const { api, calls } = registering(version);
|
|
1267
|
+
registerBashDesign(api)();
|
|
1268
|
+
const design = calls.at(-1);
|
|
1269
|
+
assert.equal(Array.isArray(design.tools), true, `${version}: still the one line`);
|
|
1270
|
+
assert.equal(design.scopes !== undefined, scoped, version);
|
|
1271
|
+
assert.equal(design.tools.includes('edit'), scoped, version);
|
|
1272
|
+
if (scoped) {
|
|
1273
|
+
assert.equal(design.scopes.write, design.scopes.edit, version);
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1276
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], `${version}: today's tools`);
|
|
1277
|
+
assert.deepEqual(
|
|
1278
|
+
Object.keys(design).sort(),
|
|
1279
|
+
['apply', 'description', 'id', 'label', 'line', 'name', 'preview', 'tools'],
|
|
1280
|
+
`${version}: today's registration byte for byte`,
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
test('a prerelease or a build suffix of the cutoff never meets it: 0.9.0-rc.1 keeps the unscoped line', () => {
|
|
1286
|
+
// Semver puts a prerelease BELOW its own release, so `0.9.0-rc.1` carries no per-(`line`, `tool`)
|
|
1287
|
+
// scope even though its digits read 0.9.0; a build suffix is read the same conservative way. Its
|
|
1288
|
+
// numbers still clear the 0.6.0 line, so the grouped `Card tags` row is kept, unscoped.
|
|
1289
|
+
for (const version of ['0.9.0-rc.1', '0.9.0+build.7', '0.9.0-rc.1+sha.abc']) {
|
|
1290
|
+
const { api, calls } = registering(version);
|
|
1291
|
+
registerBashDesign(api)();
|
|
1292
|
+
assert.equal(calls.length, 1, `${version}: a readable release is never probed`);
|
|
1293
|
+
const design = calls.at(-1);
|
|
1294
|
+
assert.equal(design.line, 'tags', version);
|
|
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);
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
test('a release that cannot be read keeps the unscoped line', () => {
|
|
1301
|
+
const { api, calls } = registering('nightly');
|
|
1302
|
+
registerBashDesign(api)();
|
|
1303
|
+
assert.equal(calls[0].id, 'odd-worktree.capability-probe', 'the grouped shape is still probed');
|
|
1304
|
+
const design = calls.at(-1);
|
|
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']);
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
// S6: ONE rule for every cutoff this package reads — an advertised release meets a cutoff by semver
|
|
1311
|
+
// order, numbers first, and a prerelease or build suffix loses ONLY when the numbers are equal. Both
|
|
1312
|
+
// of this package's lines sit at the same `0.9.0` cutoff, so each version is read through both
|
|
1313
|
+
// registrations at once: a release that is below it keeps the unscoped `Card tags` line and gets no
|
|
1314
|
+
// `Card diff` row, and a newer one gets both the scope and the diff line.
|
|
1315
|
+
describe('the release rule is semver order, on both lines at once (S6)', () => {
|
|
1316
|
+
const registerBoth = (version) => {
|
|
1317
|
+
const seen = [];
|
|
1318
|
+
const api = { VERSION: version, registerToolDesign: (design) => { seen.push(design); return () => {}; } };
|
|
1319
|
+
const disposeTags = registerBashDesign(api);
|
|
1320
|
+
const disposeDiff = registerDiffDesign(api);
|
|
1321
|
+
const dispose = () => {
|
|
1322
|
+
if (typeof disposeTags === 'function') disposeTags();
|
|
1323
|
+
if (typeof disposeDiff === 'function') disposeDiff();
|
|
1324
|
+
};
|
|
1325
|
+
return { seen, dispose, tags: seen.find((design) => design.line === 'tags'), diff: seen.find((design) => design.line === 'diff') };
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
test('a prerelease or a build suffix of 0.9.0 is BELOW it: unscoped `Card tags`, no `Card diff`', () => {
|
|
1329
|
+
for (const version of ['0.9.0-rc.1', '0.9.0-beta.1+build', '0.9.0+workstation']) {
|
|
1330
|
+
const registration = registerBoth(version);
|
|
1331
|
+
try {
|
|
1332
|
+
assert.deepEqual(registration.seen.map((design) => design.line), ['tags'], `${version}: the grouped line, and no diff line`);
|
|
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`);
|
|
1335
|
+
assert.equal(registration.diff, undefined, `${version}: nothing is offered for a row the bridge would refuse`);
|
|
1336
|
+
} finally {
|
|
1337
|
+
registration.dispose();
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
test('a NEWER release carrying a suffix is ABOVE 0.9.0: the scoped `Card tags` line AND `Card diff`', () => {
|
|
1343
|
+
for (const version of ['0.9.1-rc.1', '0.10.0+local.2']) {
|
|
1344
|
+
const registration = registerBoth(version);
|
|
1345
|
+
try {
|
|
1346
|
+
assert.deepEqual(registration.seen.map((design) => design.line), ['tags', 'diff'], `${version}: both lines`);
|
|
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`);
|
|
1349
|
+
assert.equal(registration.diff.id, 'odd-worktree.diff', version);
|
|
1350
|
+
assert.equal(registration.diff.label, 'color', version);
|
|
1351
|
+
assert.deepEqual([...registration.diff.tools], ['write', 'edit'], version);
|
|
1352
|
+
} finally {
|
|
1353
|
+
registration.dispose();
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1358
|
+
test('0.6.0-rc.1 is BELOW 0.6.0, so it falls back to the single `tool: "bash"` design', () => {
|
|
1359
|
+
// Deliberate and more conservative than the base commit, which accepted the grouped shape here:
|
|
1360
|
+
// semver puts `0.6.0-rc.1` below `0.6.0`, and this package reads one rule at every cutoff. That
|
|
1361
|
+
// is the `Card bash` row over bash alone — never a grouped registration a 0.6.0 bridge would
|
|
1362
|
+
// accept but its own release ordering says came first.
|
|
1363
|
+
const registration = registerBoth('0.6.0-rc.1');
|
|
1364
|
+
try {
|
|
1365
|
+
assert.equal(registration.seen.length, 1, 'a readable release is never probed');
|
|
1366
|
+
const [design] = registration.seen;
|
|
1367
|
+
assert.equal(design.tool, 'bash', 'the single-tool shape');
|
|
1368
|
+
assert.equal(Object.hasOwn(design, 'tools'), false, 'never both shapes');
|
|
1369
|
+
assert.equal(Object.hasOwn(design, 'line'), false, 'the older bridge names the row itself, `Card bash`');
|
|
1370
|
+
assert.equal(design.id, 'odd-worktree.bash-activity');
|
|
1371
|
+
assert.equal(design.label, 'activity');
|
|
1372
|
+
assert.equal(registration.diff, undefined, 'and the diff line is not offered either');
|
|
1373
|
+
} finally {
|
|
1374
|
+
registration.dispose();
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
test('the ordinary releases still read as they always did', () => {
|
|
1379
|
+
// 0.6.0 itself, and anything above it, is the grouped line; 0.5.0 is the single one.
|
|
1380
|
+
for (const [version, shape] of [['0.5.0', 'bash'], ['0.6.0', 'tags'], ['0.9.0', 'tags']]) {
|
|
1381
|
+
const registration = registerBoth(version);
|
|
1382
|
+
try {
|
|
1383
|
+
assert.equal(registration.tags === undefined, shape === 'bash', version);
|
|
1384
|
+
assert.equal(registration.diff === undefined, version !== '0.9.0', version);
|
|
1385
|
+
} finally {
|
|
1386
|
+
registration.dispose();
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
});
|