architecture-harness 0.27.0 → 0.28.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/package.json +3 -2
- package/src/cli/cli.test.mjs +8 -0
- package/src/cli/fleet-assign.mjs +12 -0
- package/src/cli/fleet-assign.test.mjs +24 -1
- package/src/cli/fleet-discover.mjs +137 -0
- package/src/cli/fleet-discover.test.mjs +213 -0
- package/src/cli/fleet-github.mjs +6 -0
- package/src/cli/fleet-github.test.mjs +17 -0
- package/src/cli/fleet-load.mjs +18 -0
- package/src/cli/fleet-load.test.mjs +13 -0
- package/src/cli/fleet-node.mjs +52 -10
- package/src/cli/fleet-node.test.mjs +113 -11
- package/src/cli/fleet.mjs +27 -12
- package/src/cli/fleet.test.mjs +78 -12
- package/src/cli/statusline.test.mjs +155 -0
- package/user-config/claude/statusline.js +47 -8
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { copyFileSync, mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync, symlinkSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
8
|
+
|
|
9
|
+
const script = fileURLToPath(new URL("../../../../user-config/claude/statusline.js", import.meta.url));
|
|
10
|
+
|
|
11
|
+
function fixture(t, { checkout = true, checkoutName = "project" } = {}) {
|
|
12
|
+
const root = mkdtempSync(path.join(tmpdir(), "qc-statusline-"));
|
|
13
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }));
|
|
14
|
+
const home = path.join(root, "home");
|
|
15
|
+
const cwd = path.join(root, checkoutName);
|
|
16
|
+
mkdirSync(home);
|
|
17
|
+
mkdirSync(cwd);
|
|
18
|
+
const installed = path.join(home, "statusline.cjs");
|
|
19
|
+
copyFileSync(script, installed);
|
|
20
|
+
if (checkout) execFileSync("git", ["init", "--quiet", cwd]);
|
|
21
|
+
const fleet = path.join(home, "fleet.json");
|
|
22
|
+
const nodeFile = path.join(cwd, ".git", "qc", "fleet", "node.json");
|
|
23
|
+
return {
|
|
24
|
+
fleet, cwd, root, home,
|
|
25
|
+
node(value) {
|
|
26
|
+
mkdirSync(path.dirname(nodeFile), { recursive: true });
|
|
27
|
+
writeFileSync(nodeFile, JSON.stringify(value));
|
|
28
|
+
},
|
|
29
|
+
run(dir = cwd, extraEnv = {}) {
|
|
30
|
+
const result = spawnSync(process.execPath, [installed], {
|
|
31
|
+
cwd: dir,
|
|
32
|
+
env: { ...process.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: path.join(home, ".claude"), QC_FLEET_FILE: fleet, ...extraEnv },
|
|
33
|
+
input: JSON.stringify({ workspace: { current_dir: dir } }), encoding: "utf8",
|
|
34
|
+
});
|
|
35
|
+
assert.equal(result.status, 0, result.stderr);
|
|
36
|
+
assert.equal(result.stderr, "");
|
|
37
|
+
return result.stdout.replace(/\x1b\[[0-9;]*m/g, "");
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
test("omits the fleet when its file is missing", t => {
|
|
43
|
+
assert.doesNotMatch(fixture(t).run(), /fleet /);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("silently omits unreadable, malformed, and invalid fleet settings", t => {
|
|
47
|
+
const f = fixture(t);
|
|
48
|
+
assert.throws(() => readFileSync(f.root, "utf8"), /EISDIR|EPERM|EACCES/);
|
|
49
|
+
assert.doesNotMatch(f.run(f.cwd, { QC_FLEET_FILE: f.root }), /fleet /);
|
|
50
|
+
for (const value of ["{", "null", "{}", ...["", "UPPER", "has space", "a".repeat(33), 123].map(self => JSON.stringify({ self }))]) {
|
|
51
|
+
writeFileSync(f.fleet, value);
|
|
52
|
+
assert.doesNotMatch(f.run(), /fleet /);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("uses the platform config directory when no fleet override is set", t => {
|
|
57
|
+
const f = fixture(t);
|
|
58
|
+
const xdg = path.join(f.root, "xdg");
|
|
59
|
+
const appdata = path.join(f.root, "appdata");
|
|
60
|
+
for (const [base, self] of [[xdg, "xdg-node"], [appdata, "windows-node"], [path.join(f.home, ".config"), "home-node"]]) {
|
|
61
|
+
mkdirSync(path.join(base, "qc"), { recursive: true });
|
|
62
|
+
writeFileSync(path.join(base, "qc", "fleet.json"), JSON.stringify({ self }));
|
|
63
|
+
}
|
|
64
|
+
assert.match(f.run(f.cwd, { QC_FLEET_FILE: "", XDG_CONFIG_HOME: xdg, APPDATA: appdata }),
|
|
65
|
+
process.platform === "win32" ? /fleet windows-node off / : /fleet xdg-node off /);
|
|
66
|
+
assert.match(f.run(f.cwd, { QC_FLEET_FILE: "", XDG_CONFIG_HOME: "", APPDATA: "" }), /fleet home-node off /);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("shows the name after git and no mark for a live follower", t => {
|
|
70
|
+
const f = fixture(t);
|
|
71
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
72
|
+
f.node({ pid: process.pid, leader: false });
|
|
73
|
+
assert.match(f.run(), / [^\n]+ fleet dev-1 /);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("marks a live leader", t => {
|
|
77
|
+
const f = fixture(t);
|
|
78
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
79
|
+
f.node({ pid: process.pid, leader: true });
|
|
80
|
+
assert.match(f.run(), /fleet dev-1 leader /);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("marks a live leader in a checkout whose path contains a newline", { skip: process.platform === "win32" }, t => {
|
|
84
|
+
const f = fixture(t, { checkoutName: "project\ncheckout" });
|
|
85
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
86
|
+
f.node({ pid: process.pid, leader: true });
|
|
87
|
+
assert.match(f.run(), /fleet dev-1 leader /);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("marks a live leader when git status fails with an invalid index", t => {
|
|
91
|
+
const f = fixture(t);
|
|
92
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
93
|
+
f.node({ pid: process.pid, leader: true });
|
|
94
|
+
assert.match(f.run(f.cwd, { GIT_INDEX_FILE: "/dev/null" }), /fleet dev-1 leader /);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("shows no fleet mark inside the git directory of a live leader", t => {
|
|
98
|
+
const f = fixture(t);
|
|
99
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
100
|
+
f.node({ pid: process.pid, leader: true });
|
|
101
|
+
const output = f.run(path.join(f.cwd, ".git"));
|
|
102
|
+
assert.match(output, /fleet dev-1 /);
|
|
103
|
+
assert.doesNotMatch(output, /fleet dev-1 (leader|off)/);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("marks a live leader through a symlinked checkout subfolder", t => {
|
|
107
|
+
const f = fixture(t);
|
|
108
|
+
const nested = path.join(f.cwd, "nested");
|
|
109
|
+
const linked = path.join(f.root, "linked-subfolder");
|
|
110
|
+
mkdirSync(nested);
|
|
111
|
+
symlinkSync(nested, linked, process.platform === "win32" ? "junction" : "dir");
|
|
112
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
113
|
+
f.node({ pid: process.pid, leader: true });
|
|
114
|
+
assert.match(f.run(linked), /fleet dev-1 leader /);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("shows no fleet mark outside GIT_WORK_TREE even with GIT_DIR set", t => {
|
|
118
|
+
const f = fixture(t);
|
|
119
|
+
const outside = path.join(f.root, "outside");
|
|
120
|
+
mkdirSync(outside);
|
|
121
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
122
|
+
f.node({ pid: process.pid, leader: true });
|
|
123
|
+
assert.match(f.run(outside, {
|
|
124
|
+
GIT_DIR: path.join(f.cwd, ".git"),
|
|
125
|
+
GIT_WORK_TREE: f.cwd,
|
|
126
|
+
}), /fleet dev-1 /);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("marks missing, malformed, and stopped nodes off", t => {
|
|
130
|
+
const f = fixture(t);
|
|
131
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
132
|
+
assert.match(f.run(), /fleet dev-1 off /);
|
|
133
|
+
for (const value of [null, {}, { pid: -1, leader: true }, { pid: 2147483647, leader: true }, { pid: String(process.pid), leader: true }]) {
|
|
134
|
+
f.node(value);
|
|
135
|
+
assert.match(f.run(), /fleet dev-1 off /);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("shows the fleet without a mark outside a checkout", t => {
|
|
140
|
+
const f = fixture(t, { checkout: false });
|
|
141
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
142
|
+
assert.match(f.run(), /fleet dev-1 /);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("reads the common directory from a linked worktree and nested folder", t => {
|
|
146
|
+
const f = fixture(t);
|
|
147
|
+
execFileSync("git", ["-C", f.cwd, "-c", "user.name=Test", "-c", "user.email=test@example.com", "commit", "--quiet", "--allow-empty", "-m", "fixture"]);
|
|
148
|
+
const linked = path.join(f.root, "linked");
|
|
149
|
+
execFileSync("git", ["-C", f.cwd, "worktree", "add", "--quiet", "--detach", linked]);
|
|
150
|
+
const nested = path.join(linked, "nested");
|
|
151
|
+
mkdirSync(nested);
|
|
152
|
+
writeFileSync(f.fleet, JSON.stringify({ self: "dev-1" }));
|
|
153
|
+
f.node({ pid: process.pid, leader: true });
|
|
154
|
+
assert.match(f.run(nested), /fleet dev-1 leader /);
|
|
155
|
+
});
|
|
@@ -21,6 +21,7 @@ const NAVY = [16, 26, 58];
|
|
|
21
21
|
const GREEN = [30, 120, 60];
|
|
22
22
|
const BLUE = [30, 80, 170];
|
|
23
23
|
const AMBER = [196, 110, 0];
|
|
24
|
+
const TEAL = [25, 110, 115];
|
|
24
25
|
|
|
25
26
|
function fg(rgb) { return `\x1b[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m`; }
|
|
26
27
|
function bg(rgb) { return `\x1b[48;2;${rgb[0]};${rgb[1]};${rgb[2]}m`; }
|
|
@@ -61,7 +62,7 @@ function gitInfo(dir) {
|
|
|
61
62
|
raw = execFileSync(
|
|
62
63
|
'git',
|
|
63
64
|
['-C', dir, '--no-optional-locks', 'status', '--porcelain=v2', '--branch'],
|
|
64
|
-
{ stdio: ['ignore', 'pipe', 'ignore'] }
|
|
65
|
+
{ stdio: ['ignore', 'pipe', 'ignore'], timeout: 500 }
|
|
65
66
|
).toString();
|
|
66
67
|
} catch {
|
|
67
68
|
return null; // Not a repository, or git is missing.
|
|
@@ -71,9 +72,12 @@ function gitInfo(dir) {
|
|
|
71
72
|
let ahead = 0;
|
|
72
73
|
let behind = 0;
|
|
73
74
|
let dirty = false;
|
|
75
|
+
let oid = '';
|
|
74
76
|
for (const line of raw.split('\n')) {
|
|
75
77
|
if (line.startsWith('# branch.head ')) {
|
|
76
78
|
branch = line.slice('# branch.head '.length).trim();
|
|
79
|
+
} else if (line.startsWith('# branch.oid ')) {
|
|
80
|
+
oid = line.slice('# branch.oid '.length).trim();
|
|
77
81
|
} else if (line.startsWith('# branch.ab ')) {
|
|
78
82
|
const m = line.match(/\+(\d+) -(\d+)/);
|
|
79
83
|
if (m) { ahead = Number(m[1]); behind = Number(m[2]); }
|
|
@@ -83,18 +87,52 @@ function gitInfo(dir) {
|
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
if (!branch || branch === '(detached)') {
|
|
86
|
-
|
|
87
|
-
branch = execFileSync(
|
|
88
|
-
'git',
|
|
89
|
-
['-C', dir, '--no-optional-locks', 'rev-parse', '--short', 'HEAD'],
|
|
90
|
-
{ stdio: ['ignore', 'pipe', 'ignore'] }
|
|
91
|
-
).toString().trim();
|
|
92
|
-
} catch { /* leave branch as whatever branch.head reported */ }
|
|
90
|
+
if (/^[a-f0-9]+$/.test(oid)) branch = oid.slice(0, 7);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
return { branch, ahead, behind, dirty };
|
|
96
94
|
}
|
|
97
95
|
|
|
96
|
+
// Let git resolve symlinks, linked worktrees, and repository environment variables.
|
|
97
|
+
function gitCommonDir(dir) {
|
|
98
|
+
try {
|
|
99
|
+
const output = execFileSync(
|
|
100
|
+
'git',
|
|
101
|
+
['-C', dir, 'rev-parse', '--is-inside-work-tree', '--path-format=absolute', '--git-common-dir'],
|
|
102
|
+
{ stdio: ['ignore', 'pipe', 'ignore'], timeout: 500 }
|
|
103
|
+
).toString();
|
|
104
|
+
const separator = output.indexOf('\n');
|
|
105
|
+
const commonDir = output.slice(separator + 1).replace(/\n$/, '');
|
|
106
|
+
return separator >= 0 && output.slice(0, separator) === 'true' ? commonDir || null : null;
|
|
107
|
+
} catch { return null; }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function fleetSegment(dir) {
|
|
111
|
+
try {
|
|
112
|
+
// Keep in sync with fleetPath in the CLI; this script runs standalone.
|
|
113
|
+
const base = process.platform === 'win32' && process.env.APPDATA
|
|
114
|
+
? process.env.APPDATA : process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');
|
|
115
|
+
const file = process.env.QC_FLEET_FILE || path.join(base, 'qc', 'fleet.json');
|
|
116
|
+
const self = JSON.parse(fs.readFileSync(file, 'utf8'))?.self;
|
|
117
|
+
if (typeof self !== 'string' || !/^[a-z0-9-]{1,32}$/.test(self)) return null;
|
|
118
|
+
let mark = '';
|
|
119
|
+
const commonDir = gitCommonDir(dir);
|
|
120
|
+
if (commonDir) {
|
|
121
|
+
mark = ' off';
|
|
122
|
+
try {
|
|
123
|
+
const node = JSON.parse(fs.readFileSync(path.join(commonDir, 'qc', 'fleet', 'node.json'), 'utf8'));
|
|
124
|
+
if (Number.isSafeInteger(node?.pid) && node.pid > 0) {
|
|
125
|
+
let alive = false;
|
|
126
|
+
try { process.kill(node.pid, 0); alive = true; }
|
|
127
|
+
catch (error) { alive = error.code === 'EPERM'; }
|
|
128
|
+
if (alive) mark = node.leader === true ? ' leader' : '';
|
|
129
|
+
}
|
|
130
|
+
} catch { /* missing or invalid node state means off */ }
|
|
131
|
+
}
|
|
132
|
+
return { text: `fleet ${self}${mark}`, color: TEAL };
|
|
133
|
+
} catch { return null; }
|
|
134
|
+
}
|
|
135
|
+
|
|
98
136
|
function gitSegmentText(info) {
|
|
99
137
|
let text = `${BRANCH_ICON} ${info.branch}`;
|
|
100
138
|
if (info.ahead > 0) text += ` ↑${info.ahead}`;
|
|
@@ -285,6 +323,7 @@ process.stdin.on('data', (d) => { raw += d; }).on('end', () => {
|
|
|
285
323
|
const line1 = [
|
|
286
324
|
{ text: tildePath(dir), color: ORANGE_BROWN },
|
|
287
325
|
git ? { text: gitSegmentText(git), color: DARK_GREY } : null,
|
|
326
|
+
fleetSegment(dir),
|
|
288
327
|
typeof ctxPct === 'number' ? { text: contextText(ctxPct, j.context_window?.context_window_size), color: SLATE } : null,
|
|
289
328
|
];
|
|
290
329
|
|