pi-odd-worktree 2.1.0 → 3.0.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 +54 -319
- package/extensions/odd-worktree-tools.ts +4145 -2529
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S2 / S3 / S4 (T3): the DESTRUCTIVE evidence behind the bash card's `⚠ destructive`
|
|
3
|
+
// heading — the reader ported from the user's own gentle-shell branch
|
|
4
|
+
// (`cards-bash-v2`, `lib/destructive-card-activity.ts` plus the pure recognizer it
|
|
5
|
+
// reuses from `lib/destructive-command-guard.ts`, read read-only).
|
|
6
|
+
//
|
|
7
|
+
// This module is PRESENTATION evidence and nothing else: it decides the mark and the
|
|
8
|
+
// word one card heads with, and no permission, guard or execution decision in this
|
|
9
|
+
// package may ever read it. The rule it implements is the one a database client
|
|
10
|
+
// forces on any reader: a client is fed its statements through a pipe or a heredoc,
|
|
11
|
+
// so the WHOLE command has to be read to prove what it deletes — and anything this
|
|
12
|
+
// reader cannot prove answers "not proven", never "probably safe". Every "false"
|
|
13
|
+
// below therefore means "no evidence", which is what lets the call keep whatever
|
|
14
|
+
// other identity it has (or the generic `$ bash` card).
|
|
15
|
+
//
|
|
16
|
+
// Public surface only: the three exported readers. Nothing here spawns a process,
|
|
17
|
+
// reaches the network or touches a file.
|
|
18
|
+
const { test } = require('node:test');
|
|
19
|
+
const assert = require('node:assert/strict');
|
|
20
|
+
const { isDestructiveCommand, isDestructiveSegment, isSqlClientSegment } = require('../lib/bash-destructive.js');
|
|
21
|
+
|
|
22
|
+
// A statement a client is asked to run is data loss when it drops, truncates, or
|
|
23
|
+
// deletes everything: a `DELETE` with a clause that picks rows, and a read, prove
|
|
24
|
+
// nothing — so they are not evidence, and the card keeps its other identity.
|
|
25
|
+
test('a write payload is proven while a read or a scoped delete is not', () => {
|
|
26
|
+
for (const segment of [
|
|
27
|
+
`psql -c 'DROP TABLE users'`,
|
|
28
|
+
`psql -c "TRUNCATE TABLE logs"`,
|
|
29
|
+
`mysql -e 'DROP DATABASE app'`,
|
|
30
|
+
`sqlite3 app.db 'DROP TABLE t'`,
|
|
31
|
+
`psql -c 'DELETE FROM t'`,
|
|
32
|
+
`psql -c 'DELETE FROM t WHERE 1 = 1'`,
|
|
33
|
+
]) {
|
|
34
|
+
assert.equal(isDestructiveSegment(segment), true, segment);
|
|
35
|
+
}
|
|
36
|
+
for (const segment of [
|
|
37
|
+
`psql -c 'SELECT 1'`,
|
|
38
|
+
`psql -c 'SELECT * FROM users ORDER BY id'`,
|
|
39
|
+
`psql -c 'DELETE FROM t WHERE id = 1'`,
|
|
40
|
+
'psql',
|
|
41
|
+
]) {
|
|
42
|
+
assert.equal(isDestructiveSegment(segment), false, segment);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// The distinction the family exists for: the client's own segment states none of its
|
|
47
|
+
// statements, so only the whole command proves the deletion — and the whole command
|
|
48
|
+
// is what the card reads before it decides.
|
|
49
|
+
test('only the whole command proves what a client is fed', () => {
|
|
50
|
+
for (const command of [
|
|
51
|
+
`echo 'DROP TABLE t' | psql`,
|
|
52
|
+
`printf '%s' 'DROP TABLE t' | psql`,
|
|
53
|
+
"psql <<'SQL'\nDROP TABLE t;\nSQL",
|
|
54
|
+
]) {
|
|
55
|
+
assert.equal(isDestructiveCommand(command), true, command);
|
|
56
|
+
}
|
|
57
|
+
// What a program reads from a file it never shows is not evidence, so the client
|
|
58
|
+
// behind a `cat` proves nothing — the call keeps whatever else it can name.
|
|
59
|
+
assert.equal(isDestructiveCommand(`cat schema.sql | psql`), false);
|
|
60
|
+
// The client's own segment is a database client and nothing more: a reader that
|
|
61
|
+
// looked at it alone would file the deletion as a plain, unnamed shell command.
|
|
62
|
+
assert.equal(isSqlClientSegment('psql'), true);
|
|
63
|
+
assert.equal(isSqlClientSegment('psql -c \'SELECT 1\''), true);
|
|
64
|
+
assert.equal(isDestructiveSegment('psql'), false);
|
|
65
|
+
// The pipe carries the proof; the payload on its own is prose the shell prints.
|
|
66
|
+
assert.equal(isDestructiveCommand(`echo 'DROP TABLE t'`), false);
|
|
67
|
+
assert.equal(isDestructiveCommand(`psql -c 'SELECT 1'`), false);
|
|
68
|
+
// Prose that merely names a client is not a client.
|
|
69
|
+
assert.equal(isSqlClientSegment(`echo psql`), false);
|
|
70
|
+
assert.equal(isSqlClientSegment('node psql.js'), false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// "Not proven" is the answer wherever this reader cannot see the payload: an unknown
|
|
74
|
+
// wrapper, a client reading a file it never shows, a script of its own, a parameter
|
|
75
|
+
// that expands to a statement. None of them is "safe" — they are simply no evidence,
|
|
76
|
+
// and nothing here may be read as a permission verdict either way.
|
|
77
|
+
test('an unprovable payload answers no evidence rather than "probably safe"', () => {
|
|
78
|
+
for (const segment of ['xargs rm -rf', './scripts/clean.sh --all', 'psql -f drop.sql', 'psql -c "$STMT"']) {
|
|
79
|
+
assert.equal(isDestructiveSegment(segment), false, segment);
|
|
80
|
+
}
|
|
81
|
+
for (const command of ['cat drop.sql | psql', 'psql -f drop.sql', 'psql -c "$STMT"']) {
|
|
82
|
+
assert.equal(isDestructiveCommand(command), false, command);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Only a command-position word names a program, so prose a program merely receives is
|
|
87
|
+
// never a deletion — including the text of a commit message and a grep pattern.
|
|
88
|
+
test('quoted prose is never read as a deletion', () => {
|
|
89
|
+
for (const segment of [
|
|
90
|
+
`echo 'rm -rf /'`,
|
|
91
|
+
`printf 'git reset --hard'`,
|
|
92
|
+
`git commit -m "rm -rf /tmp"`,
|
|
93
|
+
`grep -rn 'DROP TABLE' docs`,
|
|
94
|
+
`echo 'DROP TABLE t'`,
|
|
95
|
+
]) {
|
|
96
|
+
assert.equal(isDestructiveSegment(segment), false, segment);
|
|
97
|
+
assert.equal(isDestructiveCommand(segment), false, segment);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// A program whose name is an inherited member of a lookup table, and an argument that
|
|
102
|
+
// is not a command line at all, must answer "no evidence" instead of throwing: the
|
|
103
|
+
// classifier runs synchronously on every bash row the host repaints.
|
|
104
|
+
test('hazardous and malformed input never throws', () => {
|
|
105
|
+
for (const segment of ['constructor -rf dist', '__proto__ rm -rf dist', 'toString -rf dist', 'hasOwnProperty -rf dist']) {
|
|
106
|
+
assert.equal(isDestructiveSegment(segment), false, segment);
|
|
107
|
+
assert.equal(isDestructiveCommand(segment), false, segment);
|
|
108
|
+
assert.equal(isSqlClientSegment(segment), false, segment);
|
|
109
|
+
}
|
|
110
|
+
for (const value of [undefined, null, 42, {}, []]) {
|
|
111
|
+
assert.equal(isDestructiveSegment(value), false, String(value));
|
|
112
|
+
assert.equal(isDestructiveCommand(value), false, String(value));
|
|
113
|
+
assert.equal(isSqlClientSegment(value), false, String(value));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// A removed checkout is the one git operation whose data is not in the repository at
|
|
118
|
+
// all, so it is proven from the verb alone; the verbs that create, move or record a
|
|
119
|
+
// checkout delete nothing and keep whatever identity the call has.
|
|
120
|
+
test('removing a checkout is proven while creating or recording one is not', () => {
|
|
121
|
+
for (const segment of [
|
|
122
|
+
'git worktree remove ../old',
|
|
123
|
+
'git worktree remove --force ../dirty',
|
|
124
|
+
'git worktree prune',
|
|
125
|
+
'git -C repo worktree remove ../old',
|
|
126
|
+
]) {
|
|
127
|
+
assert.equal(isDestructiveSegment(segment), true, segment);
|
|
128
|
+
}
|
|
129
|
+
for (const segment of [
|
|
130
|
+
'git worktree add ../new -b feat/x',
|
|
131
|
+
'git worktree move ../a ../b',
|
|
132
|
+
'git worktree lock ../old',
|
|
133
|
+
'git worktree unlock ../old',
|
|
134
|
+
'git worktree repair ../old',
|
|
135
|
+
'git worktree list',
|
|
136
|
+
]) {
|
|
137
|
+
assert.equal(isDestructiveSegment(segment), false, segment);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The conversation card content level: the one reader every card of this package shares. The level is the process-wide slot
|
|
3
|
+
// Gentle Shell publishes; a host without it, or a slot that holds anything else, reads as `default` and never throws.
|
|
4
|
+
const { test } = require('node:test');
|
|
5
|
+
const assert = require('node:assert/strict');
|
|
6
|
+
const { CARD_CONTENT, CARD_CONTENT_SLOT, cardContentLevel } = require('../lib/card-content.js');
|
|
7
|
+
|
|
8
|
+
test('the two levels are default and minimal', () => {
|
|
9
|
+
assert.deepEqual(CARD_CONTENT, { DEFAULT: 'default', MINIMAL: 'minimal' });
|
|
10
|
+
assert.equal(CARD_CONTENT_SLOT, Symbol.for('gentle-pi.card-content'));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('the slot decides the level, and anything but minimal is default', () => {
|
|
14
|
+
assert.equal(cardContentLevel({ [CARD_CONTENT_SLOT]: 'minimal' }), 'minimal');
|
|
15
|
+
assert.equal(cardContentLevel({ [CARD_CONTENT_SLOT]: 'default' }), 'default');
|
|
16
|
+
for (const junk of [undefined, null, '', 'MINIMAL', 1, {}, []]) {
|
|
17
|
+
assert.equal(cardContentLevel({ [CARD_CONTENT_SLOT]: junk }), 'default');
|
|
18
|
+
}
|
|
19
|
+
assert.equal(cardContentLevel({}), 'default');
|
|
20
|
+
assert.equal(cardContentLevel(undefined), 'default');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('the level is read on every call, so a switch applies to the next paint', () => {
|
|
24
|
+
const host = { [CARD_CONTENT_SLOT]: 'default' };
|
|
25
|
+
assert.equal(cardContentLevel(host), 'default');
|
|
26
|
+
host[CARD_CONTENT_SLOT] = 'minimal';
|
|
27
|
+
assert.equal(cardContentLevel(host), 'minimal');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('a hostile host never throws', () => {
|
|
31
|
+
const hostile = new Proxy({}, { get() { throw new Error('boom'); } });
|
|
32
|
+
assert.equal(cardContentLevel(hostile), 'default');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('with no argument it reads the process-wide slot', () => {
|
|
36
|
+
const before = globalThis[CARD_CONTENT_SLOT];
|
|
37
|
+
try {
|
|
38
|
+
globalThis[CARD_CONTENT_SLOT] = 'minimal';
|
|
39
|
+
assert.equal(cardContentLevel(), 'minimal');
|
|
40
|
+
} finally {
|
|
41
|
+
if (before === undefined) delete globalThis[CARD_CONTENT_SLOT];
|
|
42
|
+
else globalThis[CARD_CONTENT_SLOT] = before;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S5: the reader of the card style. Every case goes through the module's public
|
|
3
|
+
// surface — the process-wide slot Gentle Shell publishes, the strict preference
|
|
4
|
+
// document, and the decision that answers `neon`, `float` or the float default —
|
|
5
|
+
// and never through its module state.
|
|
6
|
+
//
|
|
7
|
+
// The document lives in a scratch directory (`GENTLE_PI_CONFIG_HOME`), so no case
|
|
8
|
+
// reads or writes the real user's preference, and the slot is restored after every
|
|
9
|
+
// case so one test can never decide another's style.
|
|
10
|
+
//
|
|
11
|
+
// There is no cache to reset between cases: the slot is a property read on every
|
|
12
|
+
// call, and the document is read from disk on every call the slot cannot answer.
|
|
13
|
+
const { test, before, after, beforeEach, afterEach } = require('node:test');
|
|
14
|
+
const assert = require('node:assert/strict');
|
|
15
|
+
const { mkdirSync, mkdtempSync, rmSync, writeFileSync } = require('node:fs');
|
|
16
|
+
const { homedir, tmpdir } = require('node:os');
|
|
17
|
+
const { join } = require('node:path');
|
|
18
|
+
const {
|
|
19
|
+
CARD_STYLE,
|
|
20
|
+
CARD_STYLE_FILE,
|
|
21
|
+
CARD_STYLE_SCHEMA,
|
|
22
|
+
CARD_STYLE_SLOT,
|
|
23
|
+
cardStyle,
|
|
24
|
+
cardStyleFile,
|
|
25
|
+
cardStyleHome,
|
|
26
|
+
parseCardStyleFile,
|
|
27
|
+
resolveCardStyle,
|
|
28
|
+
} = require('../lib/card-style.js');
|
|
29
|
+
|
|
30
|
+
const VALID = (style) => JSON.stringify({ schema: CARD_STYLE_SCHEMA, style });
|
|
31
|
+
|
|
32
|
+
let scratch;
|
|
33
|
+
const homeOf = (name) => join(scratch, name);
|
|
34
|
+
const documentIn = (home) => join(home, CARD_STYLE_FILE);
|
|
35
|
+
|
|
36
|
+
function newHome(name) {
|
|
37
|
+
const home = homeOf(name);
|
|
38
|
+
mkdirSync(home, { recursive: true });
|
|
39
|
+
return home;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeDocument(home, contents) {
|
|
43
|
+
writeFileSync(documentIn(home), typeof contents === 'string' ? contents : JSON.stringify(contents));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const savedEnv = {
|
|
47
|
+
GENTLE_PI_CONFIG_HOME: process.env.GENTLE_PI_CONFIG_HOME,
|
|
48
|
+
GENTLE_SHELL_CONFIG_HOME: process.env.GENTLE_SHELL_CONFIG_HOME,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function restoreEnv() {
|
|
52
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
53
|
+
if (value === undefined) delete process.env[key];
|
|
54
|
+
else process.env[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function useSlot(value) {
|
|
59
|
+
if (value === undefined) delete globalThis[CARD_STYLE_SLOT];
|
|
60
|
+
else globalThis[CARD_STYLE_SLOT] = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
before(() => {
|
|
64
|
+
scratch = mkdtempSync(join(tmpdir(), 'odd-card-style-'));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
useSlot(undefined);
|
|
69
|
+
delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
70
|
+
delete process.env.GENTLE_SHELL_CONFIG_HOME;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
useSlot(undefined);
|
|
75
|
+
restoreEnv();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
after(() => {
|
|
79
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ---- the two styles, the slot and the document ----
|
|
83
|
+
|
|
84
|
+
test('the reader names the two styles, the schema and the document', () => {
|
|
85
|
+
assert.deepEqual(CARD_STYLE, { NEON: 'neon', FLOAT: 'float' });
|
|
86
|
+
assert.equal(CARD_STYLE_SCHEMA, 'gentle-pi.card-style/v1');
|
|
87
|
+
assert.equal(CARD_STYLE_FILE, 'card-style.json');
|
|
88
|
+
assert.equal(CARD_STYLE_SLOT, Symbol.for('gentle-pi.card-style'), 'the slot is the symbol Gentle Shell resolves into');
|
|
89
|
+
for (const fn of [cardStyle, cardStyleFile, cardStyleHome, parseCardStyleFile, resolveCardStyle]) {
|
|
90
|
+
assert.equal(typeof fn, 'function');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('the document is strict: exactly the schema and one known style, or nothing', () => {
|
|
95
|
+
assert.equal(parseCardStyleFile(VALID(CARD_STYLE.NEON)), CARD_STYLE.NEON);
|
|
96
|
+
assert.equal(parseCardStyleFile(VALID(CARD_STYLE.FLOAT)), CARD_STYLE.FLOAT);
|
|
97
|
+
assert.equal(parseCardStyleFile(`${VALID(CARD_STYLE.NEON)}\n`), CARD_STYLE.NEON, 'a trailing newline is still the same document');
|
|
98
|
+
|
|
99
|
+
for (const raw of [
|
|
100
|
+
'',
|
|
101
|
+
' ',
|
|
102
|
+
'neon',
|
|
103
|
+
'{',
|
|
104
|
+
'null',
|
|
105
|
+
'[]',
|
|
106
|
+
'"float"',
|
|
107
|
+
'42',
|
|
108
|
+
JSON.stringify({ schema: CARD_STYLE_SCHEMA }),
|
|
109
|
+
JSON.stringify({ style: CARD_STYLE.NEON }),
|
|
110
|
+
JSON.stringify({ schema: 'gentle-pi.card-style/v2', style: CARD_STYLE.NEON }),
|
|
111
|
+
JSON.stringify({ schema: CARD_STYLE_SCHEMA, style: CARD_STYLE.NEON, extra: true }),
|
|
112
|
+
JSON.stringify({ schema: CARD_STYLE_SCHEMA, style: 'ultraviolet' }),
|
|
113
|
+
JSON.stringify({ schema: CARD_STYLE_SCHEMA, style: CARD_STYLE.NEON, other: 'x' }),
|
|
114
|
+
JSON.stringify({ schema: CARD_STYLE_SCHEMA, style: 1 }),
|
|
115
|
+
JSON.stringify([{ schema: CARD_STYLE_SCHEMA, style: CARD_STYLE.NEON }]),
|
|
116
|
+
]) {
|
|
117
|
+
assert.equal(parseCardStyleFile(raw), undefined, `${JSON.stringify(raw)} states no style`);
|
|
118
|
+
}
|
|
119
|
+
for (const value of [undefined, null, 1, {}]) {
|
|
120
|
+
assert.equal(parseCardStyleFile(value), undefined, 'a non-string is not a document');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ---- the decision order: slot → document → float ----
|
|
125
|
+
|
|
126
|
+
test('a missing document is the float default, and the reader says so', () => {
|
|
127
|
+
const home = newHome('missing');
|
|
128
|
+
const resolution = resolveCardStyle({ gentlePiConfigHome: home });
|
|
129
|
+
assert.deepEqual(resolution, { style: CARD_STYLE.FLOAT, source: 'default', reason: 'missing_file', slot: undefined, globalFile: documentIn(home) });
|
|
130
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a document that states a style is the answer when the slot is empty', () => {
|
|
134
|
+
for (const style of [CARD_STYLE.NEON, CARD_STYLE.FLOAT]) {
|
|
135
|
+
const home = newHome(`document-${style}`);
|
|
136
|
+
writeDocument(home, VALID(style));
|
|
137
|
+
assert.deepEqual(resolveCardStyle({ gentlePiConfigHome: home }), {
|
|
138
|
+
style,
|
|
139
|
+
source: 'file',
|
|
140
|
+
reason: null,
|
|
141
|
+
slot: undefined,
|
|
142
|
+
globalFile: documentIn(home),
|
|
143
|
+
});
|
|
144
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), style);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('a malformed or unreadable document falls back to float and names the reason', () => {
|
|
149
|
+
const malformed = newHome('malformed');
|
|
150
|
+
writeDocument(malformed, '{"schema":"gentle-pi.card-style/v1","style":"teal"}');
|
|
151
|
+
const bad = resolveCardStyle({ gentlePiConfigHome: malformed });
|
|
152
|
+
assert.equal(bad.style, CARD_STYLE.FLOAT);
|
|
153
|
+
assert.equal(bad.source, 'default');
|
|
154
|
+
assert.equal(bad.reason, 'malformed_file');
|
|
155
|
+
assert.equal(cardStyle({ gentlePiConfigHome: malformed }), CARD_STYLE.FLOAT);
|
|
156
|
+
|
|
157
|
+
// A document that cannot be read at all (here a directory wearing its name) is
|
|
158
|
+
// not a malformed document: it reports its own reason.
|
|
159
|
+
const unreadable = newHome('unreadable');
|
|
160
|
+
mkdirSync(documentIn(unreadable), { recursive: true });
|
|
161
|
+
const failure = resolveCardStyle({ gentlePiConfigHome: unreadable });
|
|
162
|
+
assert.equal(failure.style, CARD_STYLE.FLOAT);
|
|
163
|
+
assert.equal(failure.reason, 'unreadable_file');
|
|
164
|
+
assert.equal(cardStyle({ gentlePiConfigHome: unreadable }), CARD_STYLE.FLOAT);
|
|
165
|
+
|
|
166
|
+
// A document that goes bad between two calls is seen bad on the second one,
|
|
167
|
+
// with the reason, and still never throws.
|
|
168
|
+
const fading = newHome('malformed-live');
|
|
169
|
+
writeDocument(fading, VALID(CARD_STYLE.NEON));
|
|
170
|
+
assert.equal(cardStyle({ gentlePiConfigHome: fading }), CARD_STYLE.NEON);
|
|
171
|
+
writeDocument(fading, JSON.stringify({ schema: CARD_STYLE_SCHEMA }));
|
|
172
|
+
const broken = resolveCardStyle({ gentlePiConfigHome: fading });
|
|
173
|
+
assert.equal(broken.style, CARD_STYLE.FLOAT, 'the edited document is read by the next call');
|
|
174
|
+
assert.equal(broken.source, 'default');
|
|
175
|
+
assert.equal(broken.reason, 'malformed_file');
|
|
176
|
+
assert.equal(cardStyle({ gentlePiConfigHome: fading }), CARD_STYLE.FLOAT);
|
|
177
|
+
assert.deepEqual(
|
|
178
|
+
resolveCardStyle({ gentlePiConfigHome: unreadable + '-absent' }),
|
|
179
|
+
{ style: CARD_STYLE.FLOAT, source: 'default', reason: 'missing_file', slot: undefined, globalFile: documentIn(unreadable + '-absent') },
|
|
180
|
+
'a missing document is still float, and still says so',
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('the live slot wins over the document, because that is what the shell says', () => {
|
|
185
|
+
const home = newHome('slot-wins');
|
|
186
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
187
|
+
|
|
188
|
+
useSlot(CARD_STYLE.NEON);
|
|
189
|
+
const neon = resolveCardStyle({ gentlePiConfigHome: home });
|
|
190
|
+
assert.deepEqual(neon, {
|
|
191
|
+
style: CARD_STYLE.NEON,
|
|
192
|
+
source: 'slot',
|
|
193
|
+
reason: 'slot',
|
|
194
|
+
slot: CARD_STYLE.NEON,
|
|
195
|
+
globalFile: documentIn(home),
|
|
196
|
+
});
|
|
197
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.NEON);
|
|
198
|
+
|
|
199
|
+
// And a slot that says float overrules a document that says neon.
|
|
200
|
+
writeDocument(home, VALID(CARD_STYLE.NEON));
|
|
201
|
+
useSlot(CARD_STYLE.FLOAT);
|
|
202
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT);
|
|
203
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: home }).source, 'slot');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('a slot holding anything but a known style is not a decision', () => {
|
|
207
|
+
const home = newHome('slot-unknown');
|
|
208
|
+
writeDocument(home, VALID(CARD_STYLE.NEON));
|
|
209
|
+
for (const value of ['outline', '', 0, null, {}, [], 'NEON']) {
|
|
210
|
+
useSlot(value);
|
|
211
|
+
const resolution = resolveCardStyle({ gentlePiConfigHome: home });
|
|
212
|
+
assert.equal(resolution.style, CARD_STYLE.NEON, `the document answers for ${JSON.stringify(value)}`);
|
|
213
|
+
assert.equal(resolution.source, 'file');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('the slot is live: a change is seen on the next call, with no refresh', () => {
|
|
218
|
+
const home = newHome('live');
|
|
219
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
220
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT);
|
|
221
|
+
useSlot(CARD_STYLE.NEON);
|
|
222
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.NEON, 'the slot is read on every call');
|
|
223
|
+
useSlot(CARD_STYLE.FLOAT);
|
|
224
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('the document is live: an edit between two calls is seen by the second one, with no refresh', () => {
|
|
228
|
+
const home = newHome('document-live');
|
|
229
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
230
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT, 'the first call reads the float document');
|
|
231
|
+
|
|
232
|
+
writeDocument(home, VALID(CARD_STYLE.NEON));
|
|
233
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.NEON, 'the second call reads the edited document');
|
|
234
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: home }).source, 'file');
|
|
235
|
+
|
|
236
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
237
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.FLOAT, 'and the next edit is seen on the next call');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('the slot still wins when it is present, whatever the document says', () => {
|
|
241
|
+
const home = newHome('slot-still-wins');
|
|
242
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
243
|
+
useSlot(CARD_STYLE.NEON);
|
|
244
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.NEON);
|
|
245
|
+
|
|
246
|
+
// A document edit between calls cannot overrule the live slot.
|
|
247
|
+
writeDocument(home, VALID(CARD_STYLE.FLOAT));
|
|
248
|
+
assert.equal(cardStyle({ gentlePiConfigHome: home }), CARD_STYLE.NEON, 'the slot answers, not the document');
|
|
249
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: home }).source, 'slot');
|
|
250
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: home }).style, CARD_STYLE.NEON);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('one home never answers for another', () => {
|
|
254
|
+
const neonHome = newHome('home-neon');
|
|
255
|
+
const floatHome = newHome('home-float');
|
|
256
|
+
writeDocument(neonHome, VALID(CARD_STYLE.NEON));
|
|
257
|
+
writeDocument(floatHome, VALID(CARD_STYLE.FLOAT));
|
|
258
|
+
assert.equal(cardStyle({ gentlePiConfigHome: neonHome }), CARD_STYLE.NEON);
|
|
259
|
+
assert.equal(cardStyle({ gentlePiConfigHome: floatHome }), CARD_STYLE.FLOAT, 'each call reads its own document');
|
|
260
|
+
assert.equal(cardStyle({ gentlePiConfigHome: neonHome }), CARD_STYLE.NEON);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ---- `<home>` resolution: GENTLE_PI_CONFIG_HOME → GENTLE_SHELL_CONFIG_HOME → ~/.pi/gentle-ai ----
|
|
264
|
+
|
|
265
|
+
test('the config home resolves pi first, then the shell, then the user default', () => {
|
|
266
|
+
const piHome = newHome('env-pi');
|
|
267
|
+
const shellHome = newHome('env-shell');
|
|
268
|
+
|
|
269
|
+
process.env.GENTLE_PI_CONFIG_HOME = piHome;
|
|
270
|
+
process.env.GENTLE_SHELL_CONFIG_HOME = shellHome;
|
|
271
|
+
assert.equal(cardStyleHome(process.env), piHome);
|
|
272
|
+
assert.equal(cardStyleFile(), documentIn(piHome));
|
|
273
|
+
assert.equal(resolveCardStyle().globalFile, documentIn(piHome));
|
|
274
|
+
|
|
275
|
+
delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
276
|
+
assert.equal(cardStyleHome(process.env), shellHome);
|
|
277
|
+
assert.equal(cardStyleFile(), documentIn(shellHome));
|
|
278
|
+
assert.equal(resolveCardStyle().globalFile, documentIn(shellHome));
|
|
279
|
+
|
|
280
|
+
// A blank value is not a choice: the next source answers.
|
|
281
|
+
process.env.GENTLE_SHELL_CONFIG_HOME = ' ';
|
|
282
|
+
assert.equal(cardStyleHome(process.env), join(homedir(), '.pi', 'gentle-ai'));
|
|
283
|
+
assert.equal(cardStyleFile(), join(homedir(), '.pi', 'gentle-ai', CARD_STYLE_FILE));
|
|
284
|
+
assert.equal(resolveCardStyle().globalFile, join(homedir(), '.pi', 'gentle-ai', CARD_STYLE_FILE));
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('the reader falls back to float instead of throwing on unusable input', () => {
|
|
288
|
+
const home = newHome('hostile');
|
|
289
|
+
writeDocument(home, VALID(CARD_STYLE.NEON));
|
|
290
|
+
for (const options of [undefined, null, 42, 'x', {}, { gentlePiConfigHome: 7 }, { gentlePiConfigHome: '' }]) {
|
|
291
|
+
assert.doesNotThrow(() => resolveCardStyle(options));
|
|
292
|
+
assert.doesNotThrow(() => cardStyle(options));
|
|
293
|
+
assert.ok([CARD_STYLE.NEON, CARD_STYLE.FLOAT].includes(resolveCardStyle(options).style));
|
|
294
|
+
}
|
|
295
|
+
// A home that is a file, not a directory, has no document to read.
|
|
296
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: documentIn(home) }).reason, 'unreadable_file');
|
|
297
|
+
assert.equal(resolveCardStyle({ gentlePiConfigHome: documentIn(home) }).style, CARD_STYLE.FLOAT);
|
|
298
|
+
});
|