@boyingliu01/xp-gate 0.39.0 → 0.39.1
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 +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/claude-code/skills/reinstall-xp-gate/.architecture-skip +0 -8
- package/plugins/claude-code/skills/reinstall-xp-gate/.github/workflows/test.yml +0 -106
- package/plugins/claude-code/skills/reinstall-xp-gate/CHANGELOG.md +0 -379
- package/plugins/claude-code/skills/reinstall-xp-gate/LICENSE +0 -21
- package/plugins/claude-code/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +0 -173
- package/plugins/claude-code/skills/reinstall-xp-gate/README.md +0 -167
- package/plugins/claude-code/skills/reinstall-xp-gate/SKILL.md +0 -271
- package/plugins/claude-code/skills/reinstall-xp-gate/TODO.md +0 -253
- package/plugins/claude-code/skills/reinstall-xp-gate/VERSION +0 -1
- package/plugins/claude-code/skills/reinstall-xp-gate/package.json +0 -28
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/audit.mjs +0 -193
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/coverage.mjs +0 -140
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/hp-gate.mjs +0 -175
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/install.mjs +0 -64
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +0 -67
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agents.mjs +0 -247
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/backups.mjs +0 -96
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +0 -101
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +0 -124
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +0 -61
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +0 -108
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +0 -290
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +0 -37
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +0 -154
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/platform.mjs +0 -92
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/probes.mjs +0 -102
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/proc.mjs +0 -33
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/report.mjs +0 -29
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/residue.mjs +0 -188
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +0 -75
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/skills.mjs +0 -121
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +0 -161
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +0 -26
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/tools.mjs +0 -238
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/util.mjs +0 -33
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +0 -45
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/version.mjs +0 -29
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +0 -66
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/mutation.mjs +0 -132
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/preflight.mjs +0 -75
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/reinstall.mjs +0 -297
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/setup-wsl.sh +0 -633
- package/plugins/claude-code/skills/reinstall-xp-gate/scripts/verify.mjs +0 -222
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/agents.test.mjs +0 -168
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/baseline.test.mjs +0 -104
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/ccn.test.mjs +0 -87
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/cleanup.test.mjs +0 -128
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/coverage.test.mjs +0 -69
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/delphi.test.mjs +0 -78
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/fixtures.mjs +0 -61
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +0 -157
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +0 -57
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +0 -49
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +0 -58
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc.test.mjs +0 -243
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/report.test.mjs +0 -66
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/residue.test.mjs +0 -278
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/selfsync.test.mjs +0 -70
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/skills.test.mjs +0 -171
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/testreport.test.mjs +0 -40
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +0 -38
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +0 -323
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +0 -350
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools.test.mjs +0 -131
- package/plugins/claude-code/skills/reinstall-xp-gate/tests/util.test.mjs +0 -154
- package/plugins/opencode/skills/reinstall-xp-gate/.architecture-skip +0 -8
- package/plugins/opencode/skills/reinstall-xp-gate/.github/workflows/test.yml +0 -106
- package/plugins/opencode/skills/reinstall-xp-gate/CHANGELOG.md +0 -379
- package/plugins/opencode/skills/reinstall-xp-gate/LICENSE +0 -21
- package/plugins/opencode/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +0 -173
- package/plugins/opencode/skills/reinstall-xp-gate/README.md +0 -167
- package/plugins/opencode/skills/reinstall-xp-gate/SKILL.md +0 -271
- package/plugins/opencode/skills/reinstall-xp-gate/TODO.md +0 -253
- package/plugins/opencode/skills/reinstall-xp-gate/VERSION +0 -1
- package/plugins/opencode/skills/reinstall-xp-gate/package.json +0 -28
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/audit.mjs +0 -193
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/coverage.mjs +0 -140
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/hp-gate.mjs +0 -175
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/install.mjs +0 -64
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +0 -67
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agents.mjs +0 -247
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/backups.mjs +0 -96
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +0 -101
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +0 -124
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +0 -61
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +0 -108
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +0 -290
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +0 -37
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +0 -154
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/platform.mjs +0 -92
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/probes.mjs +0 -102
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/proc.mjs +0 -33
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/report.mjs +0 -29
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/residue.mjs +0 -188
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +0 -75
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/skills.mjs +0 -121
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +0 -161
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +0 -26
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/tools.mjs +0 -238
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/util.mjs +0 -33
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +0 -45
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/version.mjs +0 -29
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +0 -66
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/mutation.mjs +0 -132
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/preflight.mjs +0 -75
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/reinstall.mjs +0 -297
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/setup-wsl.sh +0 -633
- package/plugins/opencode/skills/reinstall-xp-gate/scripts/verify.mjs +0 -222
- package/plugins/opencode/skills/reinstall-xp-gate/tests/agents.test.mjs +0 -168
- package/plugins/opencode/skills/reinstall-xp-gate/tests/baseline.test.mjs +0 -104
- package/plugins/opencode/skills/reinstall-xp-gate/tests/ccn.test.mjs +0 -87
- package/plugins/opencode/skills/reinstall-xp-gate/tests/cleanup.test.mjs +0 -128
- package/plugins/opencode/skills/reinstall-xp-gate/tests/coverage.test.mjs +0 -69
- package/plugins/opencode/skills/reinstall-xp-gate/tests/delphi.test.mjs +0 -78
- package/plugins/opencode/skills/reinstall-xp-gate/tests/fixtures.mjs +0 -61
- package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +0 -157
- package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +0 -57
- package/plugins/opencode/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +0 -49
- package/plugins/opencode/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +0 -58
- package/plugins/opencode/skills/reinstall-xp-gate/tests/proc.test.mjs +0 -243
- package/plugins/opencode/skills/reinstall-xp-gate/tests/report.test.mjs +0 -66
- package/plugins/opencode/skills/reinstall-xp-gate/tests/residue.test.mjs +0 -278
- package/plugins/opencode/skills/reinstall-xp-gate/tests/selfsync.test.mjs +0 -70
- package/plugins/opencode/skills/reinstall-xp-gate/tests/skills.test.mjs +0 -171
- package/plugins/opencode/skills/reinstall-xp-gate/tests/testreport.test.mjs +0 -40
- package/plugins/opencode/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +0 -38
- package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +0 -323
- package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +0 -350
- package/plugins/opencode/skills/reinstall-xp-gate/tests/tools.test.mjs +0 -131
- package/plugins/opencode/skills/reinstall-xp-gate/tests/util.test.mjs +0 -154
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* hp-gate: Harness Plugin Gate.
|
|
4
|
-
*
|
|
5
|
-
* WHAT THIS IS
|
|
6
|
-
* ------------
|
|
7
|
-
* xp-gate is a JavaScript product whose own quality gates cannot read
|
|
8
|
-
* JavaScript. Gate 3 (complexity) and Gate 10 (SAST) filter files through
|
|
9
|
-
*
|
|
10
|
-
* const LIZARD_EXTENSIONS = /\.(ts|tsx|js|jsx|py|go|...)$/;
|
|
11
|
-
* const SEMGREP_EXTENSIONS = /\.(ts|tsx|js|jsx|py|go|...)$/;
|
|
12
|
-
*
|
|
13
|
-
* (xp-gate v0.38.74, `gates/common.ts`). Neither lists `mjs` or `cjs`. Measured
|
|
14
|
-
* on a throwaway repo with one trivial `src/a.mjs`:
|
|
15
|
-
*
|
|
16
|
-
* xp-gate check 3 -> "SKIPPED - Complexity (no source files to check)"
|
|
17
|
-
* xp-gate check 3 -> "PASSED" when the same function sits in `src/a.js`
|
|
18
|
-
*
|
|
19
|
-
* So on the upstream repository every `.mjs` file reports PASS/SKIP while nobody
|
|
20
|
-
* inspects it (upstream xp-gate#732). This script closes that hole for this
|
|
21
|
-
* repository by running the SAME tools xp-gate would run, on the `.mjs` sources
|
|
22
|
-
* xp-gate cannot see, using xp-gate's own thresholds so the verdict means the
|
|
23
|
-
* same thing.
|
|
24
|
-
*
|
|
25
|
-
* WHY NOT JUST RENAME FILES TO .js
|
|
26
|
-
* --------------------------------
|
|
27
|
-
* Considered and rejected: `.mjs` is what makes the ESM contract explicit, the
|
|
28
|
-
* package sets `"type": "module"`, and the sibling directories hold untracked
|
|
29
|
-
* `.js` copies that get committed by accident (`git add -A` staged 34 of them
|
|
30
|
-
* during this investigation). Renaming buys visibility inside one gate and
|
|
31
|
-
* loses a real signal elsewhere.
|
|
32
|
-
*
|
|
33
|
-
* USAGE
|
|
34
|
-
* node scripts/hp-gate.mjs # complexity + lint, human output
|
|
35
|
-
* node scripts/hp-gate.mjs --json # machine-readable
|
|
36
|
-
* node scripts/hp-gate.mjs --ccn 8 # override the CCN block threshold
|
|
37
|
-
*
|
|
38
|
-
* Exit 1 if any file violates a threshold.
|
|
39
|
-
*/
|
|
40
|
-
import path from 'node:path';
|
|
41
|
-
import { fileURLToPath } from 'node:url';
|
|
42
|
-
import { spawnSync } from 'node:child_process';
|
|
43
|
-
|
|
44
|
-
import { effectivePath } from './lib/proc.mjs';
|
|
45
|
-
import { listFiles } from './lib/util.mjs';
|
|
46
|
-
import { parseLizardCsv, ccnViolations } from './lib/ccn.mjs';
|
|
47
|
-
|
|
48
|
-
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
49
|
-
const argv = process.argv.slice(2);
|
|
50
|
-
const asJson = argv.includes('--json');
|
|
51
|
-
const ccnArg = argv.indexOf('--ccn');
|
|
52
|
-
/** Same default as Gate 3's `CCN_THRESHOLD`; only the ignore list is wider. */
|
|
53
|
-
const CCN_THRESHOLD = ccnArg >= 0 ? Number(argv[ccnArg + 1]) : 5;
|
|
54
|
-
|
|
55
|
-
const SOURCE_EXT = /\.(mjs|cjs)$/;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Collect the sources xp-gate cannot see.
|
|
59
|
-
*
|
|
60
|
-
* `tests/` is included deliberately: a copy of production logic in a test file
|
|
61
|
-
* is still a copy, and this repository's own history has a test that passed for
|
|
62
|
-
* the wrong reason.
|
|
63
|
-
*/
|
|
64
|
-
function sourceFiles(dir = root) {
|
|
65
|
-
return listFiles(dir)
|
|
66
|
-
.map((rel) => path.join(dir, rel))
|
|
67
|
-
.filter((abs) => SOURCE_EXT.test(abs) && !abs.split(path.sep).includes('node_modules'));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const ENV = { ...process.env, PATH: effectivePath() };
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Run lizard over the given files and return its CSV rows.
|
|
74
|
-
*
|
|
75
|
-
* `--csv` is not optional. Without it lizard prints a human table plus
|
|
76
|
-
* `... has N NLOC, M CCN ...` warnings on stderr, stdout stays empty, and the
|
|
77
|
-
* parser finds zero functions -- which the caller then reports as "every
|
|
78
|
-
* function within the threshold". Measured: without `--csv` this script passed
|
|
79
|
-
* a tree containing a CCN-22 function.
|
|
80
|
-
*
|
|
81
|
-
* `-C` sets the reporting cut-off. It is passed as the script's own threshold
|
|
82
|
-
* rather than a constant so the tool and the verdict cannot disagree.
|
|
83
|
-
*/
|
|
84
|
-
function lizardCsv(files) {
|
|
85
|
-
const r = spawnSync('lizard', ['--csv', '-l', 'javascript', '-C', String(CCN_THRESHOLD), ...files], {
|
|
86
|
-
encoding: 'utf8',
|
|
87
|
-
env: ENV,
|
|
88
|
-
timeout: 120000,
|
|
89
|
-
maxBuffer: 32 * 1024 * 1024,
|
|
90
|
-
});
|
|
91
|
-
const failure = describeSpawnFailure(r);
|
|
92
|
-
return failure ? { error: failure } : { csv: String(r.stdout || '') };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Turn a spawnSync result into one line a human can act on, or null on success. */
|
|
96
|
-
function describeSpawnFailure(r) {
|
|
97
|
-
if (r.error) return 'lizard not runnable: ' + r.error.message;
|
|
98
|
-
if (r.status === 0) return null;
|
|
99
|
-
return 'lizard exited ' + r.status + ': ' + firstLine(r.stderr);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** First non-empty line of a tool stderr, for a single-line error message. */
|
|
103
|
-
function firstLine(text) {
|
|
104
|
-
return String(text || '').split(String.fromCharCode(10)).map((l) => l.trim()).find(Boolean) || '';
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* `node --check` per file: the cheapest proof that nothing here would fail at
|
|
109
|
-
* parse time. xp-gate's Gate 1 skips `.mjs` for the same reason Gate 3 does, so
|
|
110
|
-
* a syntax error in this repository has no gate at all.
|
|
111
|
-
*/
|
|
112
|
-
function syntaxErrors(files) {
|
|
113
|
-
const out = [];
|
|
114
|
-
for (const file of files) {
|
|
115
|
-
const r = spawnSync(process.execPath, ['--check', file], { encoding: 'utf8', env: ENV, timeout: 30000 });
|
|
116
|
-
if (r.status !== 0) {
|
|
117
|
-
out.push({ file: path.relative(root, file), error: String(r.stderr || '').split(/\r?\n/).find(Boolean) || 'parse error' });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return out;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const files = sourceFiles();
|
|
124
|
-
const report = { threshold: CCN_THRESHOLD, files: files.length, violations: [], syntax: [], tools: {} };
|
|
125
|
-
|
|
126
|
-
const syntax = syntaxErrors(files);
|
|
127
|
-
report.syntax = syntax;
|
|
128
|
-
|
|
129
|
-
let ccn = [];
|
|
130
|
-
const liz = lizardCsv(files);
|
|
131
|
-
const lizardOk = !liz.error;
|
|
132
|
-
if (liz.error) report.tools.lizard = liz.error;
|
|
133
|
-
else report.tools.lizard = 'ok';
|
|
134
|
-
if (lizardOk) {
|
|
135
|
-
ccn = parseLizardCsv(liz.csv).map((row) => ({ ...row, file: path.relative(root, row.file).split(path.sep).join('/') }));
|
|
136
|
-
}
|
|
137
|
-
report.violations = ccnViolations(ccn, CCN_THRESHOLD);
|
|
138
|
-
|
|
139
|
-
// "Scanned 30 files and found 0 functions" is a parsing failure wearing a pass
|
|
140
|
-
// verdict. Treat a silent lizard as a hard error, not as clean code.
|
|
141
|
-
const scanBroken = files.length > 0 && lizardOk && ccn.length === 0;
|
|
142
|
-
|
|
143
|
-
if (asJson) {
|
|
144
|
-
console.log(JSON.stringify({ ...report, scanBroken, allFunctions: ccn }, null, 2));
|
|
145
|
-
} else {
|
|
146
|
-
console.log(`\n=== hp-gate: sources xp-gate cannot see (.mjs/.cjs) ===`);
|
|
147
|
-
console.log(` files scanned : ${report.files}`);
|
|
148
|
-
console.log(` lizard : ${report.tools.lizard}`);
|
|
149
|
-
console.log(` CCN threshold : > ${CCN_THRESHOLD} blocks (same as Gate 3)`);
|
|
150
|
-
console.log(` functions : ${ccn.length}`);
|
|
151
|
-
console.log(` syntax errors : ${syntax.length}`);
|
|
152
|
-
|
|
153
|
-
if (scanBroken) {
|
|
154
|
-
console.log('\n ✗ lizard returned no functions for a non-empty source set --');
|
|
155
|
-
console.log(' the scan is broken, which is not the same as the code being clean.');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (syntax.length) {
|
|
159
|
-
console.log('\n ✗ unparseable files');
|
|
160
|
-
for (const s of syntax) console.log(` ${s.file}: ${s.error}`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (report.violations.length) {
|
|
164
|
-
console.log(`\n ✗ ${report.violations.length} function(s) above CCN ${CCN_THRESHOLD}`);
|
|
165
|
-
for (const v of report.violations.sort((a, b) => b.ccn - a.ccn)) {
|
|
166
|
-
console.log(` ${String(v.ccn).padStart(3)} ${v.name} (${v.file}:${v.line})`);
|
|
167
|
-
}
|
|
168
|
-
} else if (!scanBroken) {
|
|
169
|
-
console.log(`\n ✓ every function within CCN ${CCN_THRESHOLD}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const ok = report.violations.length === 0 && syntax.length === 0 && !scanBroken;
|
|
174
|
-
if (!asJson) console.log(`\n ${ok ? '✓ hp-gate passed' : '✗ hp-gate failed'}\n`);
|
|
175
|
-
process.exit(ok ? 0 : 1);
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { HOME } from './lib/proc.mjs';
|
|
5
|
-
import { discoverSkillRoots, nativeDelphiAgents } from './lib/agents.mjs';
|
|
6
|
-
import { defaultSource, syncSelf } from './lib/selfsync.mjs';
|
|
7
|
-
import { isDir } from './lib/util.mjs';
|
|
8
|
-
import { sweepLegacySelfCopy } from './lib/residue.mjs';
|
|
9
|
-
import { section, table, note } from './lib/report.mjs';
|
|
10
|
-
|
|
11
|
-
const selfDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
const dryRun = args.includes('--dry-run');
|
|
14
|
-
const includeAll = args.includes('--include-all');
|
|
15
|
-
const source = defaultSource(selfDir);
|
|
16
|
-
const canonicalRoot = path.join(HOME, '.local', 'share', 'xp-gate', 'skills');
|
|
17
|
-
|
|
18
|
-
const allRoots = discoverSkillRoots();
|
|
19
|
-
const roots = (includeAll ? allRoots : allRoots.filter((r) => r.live)).map((r) => ({ ...r }));
|
|
20
|
-
if (!roots.some((r) => path.resolve(r.dir) === path.resolve(canonicalRoot))) {
|
|
21
|
-
roots.push({ agent: 'canonical (installer)', dir: canonicalRoot, official: false, live: true });
|
|
22
|
-
}
|
|
23
|
-
const dead = allRoots.filter((r) => !r.live);
|
|
24
|
-
|
|
25
|
-
section(`分发 reinstall-xp-gate${dryRun ? '(dry-run)' : ''}`);
|
|
26
|
-
console.log(` 源: ${source}`);
|
|
27
|
-
if (!isDir(source)) {
|
|
28
|
-
console.error(` 源目录不存在: ${source}`);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const results = syncSelf({ source, roots, dryRun });
|
|
33
|
-
table(
|
|
34
|
-
['agent', 'live', 'state', 'dir'],
|
|
35
|
-
results.map((r) => {
|
|
36
|
-
const hit = allRoots.find((x) => x.dir === r.dir);
|
|
37
|
-
return [r.agent, hit ? (hit.live ? 'yes' : 'no') : '-', r.state, r.dir];
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const pending = results.filter((r) => r.state !== 'ok' && r.state !== 'source');
|
|
42
|
-
if (dryRun) {
|
|
43
|
-
note(`dry-run:${pending.length} 个副本待写入,未改盘。`);
|
|
44
|
-
} else {
|
|
45
|
-
note(`已写入 ${pending.length} 个副本;内容与源一致的副本未被触碰。`);
|
|
46
|
-
// The skill was renamed in 2.0.0. A copy under the old name is not in the
|
|
47
|
-
// package any more, so nothing will ever update it again -- left alone it
|
|
48
|
-
// stays in every agent root forever, still looking like a live skill. Swept
|
|
49
|
-
// here, on every root including live ones, because pruneDeadRoots only ever
|
|
50
|
-
// sees agents judged dead.
|
|
51
|
-
const swept = roots.filter((r) => sweepLegacySelfCopy(r.dir) > 0).map((r) => r.agent);
|
|
52
|
-
if (swept.length) note(`已清理旧名副本(xp-gate-reinstall): ${swept.join(', ')}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (dead.length) {
|
|
56
|
-
section('已跳过(配置残留,agent 不在了)');
|
|
57
|
-
table(['agent', 'reason', 'dir'], dead.map((r) => [r.agent, r.reason, r.dir]));
|
|
58
|
-
note('确认仍是活的但被误判时,加 --include-all 强制分发。');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const natives = nativeDelphiAgents();
|
|
62
|
-
if (natives.length > 0) {
|
|
63
|
-
note(`注意:检测到 ${natives.length} 个 Qoder 原生 Delphi agent(external-only 下应为 0),重装后由 verify 复核。`);
|
|
64
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { HOME } from './proc.mjs';
|
|
3
|
-
import { isDir } from './util.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Turning a skills directory into a human label, and back into the agent's home.
|
|
7
|
-
*
|
|
8
|
-
* Split out of `agents.mjs` (Gate 4: 11 exports, maximum 10). These are pure
|
|
9
|
-
* path questions -- no probing, no spawning, nothing that needs the liveness
|
|
10
|
-
* machinery -- so they can be reasoned about on their own.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Agent labels for every config directory this skill knows about.
|
|
15
|
-
*
|
|
16
|
-
* These are DIRECTORY names, so they are matched case-insensitively against a
|
|
17
|
-
* path relative to HOME. Adding an agent here is what makes it report as
|
|
18
|
-
* "Trae CN" instead of "trae cn".
|
|
19
|
-
*/
|
|
20
|
-
const KNOWN_LABELS = {
|
|
21
|
-
'.agents': 'Generic agents',
|
|
22
|
-
'.claude': 'Claude Code',
|
|
23
|
-
'.cline': 'Cline',
|
|
24
|
-
'.codebuddy': 'CodeBuddy',
|
|
25
|
-
'.codex': 'Codex',
|
|
26
|
-
'.config/opencode': 'OpenCode',
|
|
27
|
-
'.dsh': 'DSH',
|
|
28
|
-
'.dws': 'DWS',
|
|
29
|
-
'.pi/agent': 'Pi',
|
|
30
|
-
'.qoder': 'Qoder',
|
|
31
|
-
'.qoder-cn': 'Qoder CN',
|
|
32
|
-
'.trae': 'Trae',
|
|
33
|
-
'.trae-cn': 'Trae CN',
|
|
34
|
-
'.trae-aicc': 'Trae AICC',
|
|
35
|
-
'.workbuddy': 'WorkBuddy',
|
|
36
|
-
doubaowork: 'Doubao Work',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/** xp-gate 的 installer 本身认识的平台;其余 agent 由本脚本直接复制。 */
|
|
40
|
-
export const OFFICIAL_ROOTS = new Set([
|
|
41
|
-
'.qoder/skills',
|
|
42
|
-
'.claude/skills',
|
|
43
|
-
'.config/opencode/skills',
|
|
44
|
-
'.dsh/skills',
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/** Path relative to HOME with forward slashes, which is what the tables use. */
|
|
49
|
-
export function relToHome(abs) {
|
|
50
|
-
return path.relative(HOME, abs).split(path.sep).join('/');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function labelFor(skillRoot) {
|
|
54
|
-
const base = relToHome(skillRoot).replace(/\/skills$/, '');
|
|
55
|
-
return KNOWN_LABELS[base.toLowerCase()] || base.replace(/^\./, '').replace(/[/-]+/g, ' ');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function isOfficialSkillRoot(skillRoot) {
|
|
59
|
-
return OFFICIAL_ROOTS.has(relToHome(skillRoot));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function agentHomeFor(skillRoot) {
|
|
63
|
-
const parts = path.relative(HOME, skillRoot).split(path.sep);
|
|
64
|
-
return parts[0] === '.config' && parts.length > 2
|
|
65
|
-
? path.join(HOME, parts[0], parts[1])
|
|
66
|
-
: path.join(HOME, parts[0]);
|
|
67
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { HOME, which } from './proc.mjs';
|
|
4
|
-
import { isDir } from './util.mjs';
|
|
5
|
-
import { relToHome, agentHomeFor, labelFor, isOfficialSkillRoot } from './agent-paths.mjs';
|
|
6
|
-
|
|
7
|
-
/** 桌面/IDE 安装目录:存在即说明 agent 还在用(配置目录卸载后常残留)。 */
|
|
8
|
-
const APP_PROBES = {
|
|
9
|
-
Qoder: ['AppData/Local/Programs/Qoder', 'AppData/Local/Qoder'],
|
|
10
|
-
'Qoder CN': ['AppData/Local/Qoder CN'],
|
|
11
|
-
Trae: ['AppData/Local/Programs/Trae'],
|
|
12
|
-
'Trae CN': ['AppData/Local/Programs/Trae CN', 'AppData/Local/Programs/TRAE SOLO CN'],
|
|
13
|
-
WorkBuddy: ['AppData/Local/WorkBuddy', 'AppData/Local/@genieworkbuddy-desktop-updater'],
|
|
14
|
-
CodeBuddy: ['AppData/Local/CodeBuddyExtension'],
|
|
15
|
-
'Doubao Work': ['AppData/Local/DoubaoWork'],
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/** CLI 类 agent:能从合并后的 PATH 解析到可执行文件才算还活着。 */
|
|
19
|
-
const CLI_PROBES = {
|
|
20
|
-
'Claude Code': 'claude',
|
|
21
|
-
Codex: 'codex',
|
|
22
|
-
OpenCode: 'opencode',
|
|
23
|
-
Cline: 'cline',
|
|
24
|
-
CodeBuddy: 'codebuddy',
|
|
25
|
-
DSH: 'dsh',
|
|
26
|
-
DWS: 'dws',
|
|
27
|
-
Pi: 'pi',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/** 多 agent 共用的技能仓库,不是某个 agent 的配置目录。 */
|
|
31
|
-
const SHARED_ROOTS = new Set(['.agents/skills']);
|
|
32
|
-
const cliCache = new Map();
|
|
33
|
-
|
|
34
|
-
const BACKUP_RE = /(^|[\\/])[^\\/]*(backup|bak|old|archive|snapshot|migration)[^\\/]*([\\/]|$)/i;
|
|
35
|
-
const SKIP_RE = /(^|[\\/])(node_modules|\.git|\.pnpm|skills-marketplace|connectors)([\\/]|$)/i;
|
|
36
|
-
|
|
37
|
-
/** Qoder's own Delphi agent files: `delphi-<seat>.md` in an `agents/` directory. */
|
|
38
|
-
const DELPHI_AGENT_RE = /^delphi-.*\.md$/i;
|
|
39
|
-
|
|
40
|
-
function safeReaddir(dir) {
|
|
41
|
-
try {
|
|
42
|
-
return fs.readdirSync(dir, { withFileTypes: true });
|
|
43
|
-
} catch {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 三级判活的证据之一:桌面/IDE 安装目录存在即说明 agent 还在用。
|
|
50
|
-
* @returns {string} 命中的绝对路径,未命中返回空串
|
|
51
|
-
*/
|
|
52
|
-
function appEvidence(agent) {
|
|
53
|
-
const relApp = (APP_PROBES[agent] || []).map((rel) => path.join(HOME, rel)).find(isDir);
|
|
54
|
-
return relApp || '';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 证据之二:CLI 能从合并后的 PATH 解析到。结果进缓存,因为 discoverSkillRoots
|
|
59
|
-
* 会对同一批 agent 反复调用,每次都 spawn 一次 where.exe 很慢。
|
|
60
|
-
* @returns {string} 可执行文件路径,未命中返回空串
|
|
61
|
-
*/
|
|
62
|
-
function cliEvidence(agent) {
|
|
63
|
-
const cli = CLI_PROBES[agent];
|
|
64
|
-
if (!cli) return '';
|
|
65
|
-
if (!cliCache.has(cli)) cliCache.set(cli, which(cli));
|
|
66
|
-
return cliCache.get(cli);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Whether an agent's CLI resolves on PATH right now.
|
|
71
|
-
*
|
|
72
|
-
* Needed because xp-gate's doctor hard-requires artefacts for agents that may
|
|
73
|
-
* simply not be installed: `doctor-tui.js` reports
|
|
74
|
-
* `TUI registration: FAIL / Not registered` whenever
|
|
75
|
-
* `~/.config/opencode/tui.json` is missing, without ever asking whether
|
|
76
|
-
* OpenCode exists. On a machine that has removed OpenCode the check is
|
|
77
|
-
* unsatisfiable by design -- the only way to "fix" it would be to reinstall the
|
|
78
|
-
* editor the user just deleted. Callers use this to report "not applicable"
|
|
79
|
-
* instead of inventing a failure.
|
|
80
|
-
*
|
|
81
|
-
* @returns {boolean} true when the CLI resolves
|
|
82
|
-
*/
|
|
83
|
-
export function agentInstalled(agent) {
|
|
84
|
-
return Boolean(cliEvidence(agent));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 证据之三:agent 配置目录近 N 天有写入。DSH 这类二进制不在 PATH 上的情况
|
|
89
|
-
* 只能靠它兜底。
|
|
90
|
-
* @returns {number} 距今天数;目录不可读时返回 Infinity
|
|
91
|
-
*/
|
|
92
|
-
export function idleDays(skillRoot) {
|
|
93
|
-
return daysSinceWrite(agentHomeFor(skillRoot));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Days since `dir` was last written, or Infinity when it cannot be read. */
|
|
97
|
-
function daysSinceWrite(dir) {
|
|
98
|
-
let mtime = 0;
|
|
99
|
-
try {
|
|
100
|
-
mtime = fs.statSync(dir).mtimeMs;
|
|
101
|
-
} catch {
|
|
102
|
-
/* 目录不可读按残留处理 */
|
|
103
|
-
}
|
|
104
|
-
return mtime ? Math.max(0, Math.floor((Date.now() - mtime) / 86400000)) : Infinity;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Format an idle-day count for the report; Infinity is not a number a human can read. */
|
|
108
|
-
function describeIdle(days) {
|
|
109
|
-
return Number.isFinite(days) ? `${days}d` : 'unknown';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 目录存在 ≠ agent 还在用:卸载后配置目录与 skills/ 会长期残留。
|
|
114
|
-
* 判活按「桌面安装目录 > CLI 可解析 > 配置目录近 N 天有写入」三级证据依次
|
|
115
|
-
* 短路,三级都不成立才判为残留。
|
|
116
|
-
*/
|
|
117
|
-
export function probeLiveness(entry, liveDays = 30, homeFor = agentHomeFor) {
|
|
118
|
-
const evidence = [
|
|
119
|
-
() => (SHARED_ROOTS.has(relToHome(entry.dir)) ? 'shared skill store' : ''),
|
|
120
|
-
() => wrap('app', appEvidence(entry.agent)),
|
|
121
|
-
() => wrap('cli', cliEvidence(entry.agent)),
|
|
122
|
-
() => recency(entry.dir, liveDays, homeFor),
|
|
123
|
-
];
|
|
124
|
-
for (const probe of evidence) {
|
|
125
|
-
const reason = probe();
|
|
126
|
-
if (reason) return { live: true, reason };
|
|
127
|
-
}
|
|
128
|
-
return { live: false, reason: `no app/cli, idle ${describeIdle(idleDays(entry.dir))}` };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Prefix a non-empty evidence path, or return '' so the next probe runs. */
|
|
132
|
-
function wrap(kind, value) {
|
|
133
|
-
return value ? `${kind}: ${value}` : '';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Names xp-gate itself writes into an agent home.
|
|
138
|
-
*
|
|
139
|
-
* `tui.json` is the plugin registration, `skills` is where this skill and the
|
|
140
|
-
* published bundle land. Anything else in the directory was put there by the
|
|
141
|
-
* agent or its user.
|
|
142
|
-
*/
|
|
143
|
-
const SELF_WRITTEN = new Set(['tui.json', 'skills']);
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* True when an agent home contains only files this toolchain wrote.
|
|
147
|
-
*
|
|
148
|
-
* Issue #4: recency reads the home's mtime, and creating tui.json or skills/
|
|
149
|
-
* refreshes it. An uninstalled OpenCode then looks active forever, because the
|
|
150
|
-
* evidence of use is the checker's own writes. A home holding nothing else is
|
|
151
|
-
* residue, not a sign the user came back.
|
|
152
|
-
*/
|
|
153
|
-
export function selfWrittenHome(dir) {
|
|
154
|
-
const names = safeReaddir(dir).map((entry) => entry.name);
|
|
155
|
-
return names.length > 0 && names.every((name) => SELF_WRITTEN.has(name));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Third evidence tier: the config dir was written recently enough to count as live. */
|
|
159
|
-
function recency(dir, liveDays, homeFor = agentHomeFor) {
|
|
160
|
-
const home = homeFor(dir);
|
|
161
|
-
if (selfWrittenHome(home)) return '';
|
|
162
|
-
const days = daysSinceWrite(home);
|
|
163
|
-
return days <= liveDays ? `active ${days}d ago` : '';
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function isDirEntry(entry) {
|
|
167
|
-
return entry.isDirectory() || entry.isSymbolicLink();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 扫描规则只依赖「<root>/<name>/SKILL.md」这个通用约定:
|
|
172
|
-
* - ~/<dir>/skills
|
|
173
|
-
* - ~/<dir>/agent/skills
|
|
174
|
-
* - ~/.config/<dir>/skills
|
|
175
|
-
* 新 agent 不需要改代码;备份目录与 marketplace/connectors 自动排除。
|
|
176
|
-
*/
|
|
177
|
-
export function discoverSkillRoots({ liveDays = 30 } = {}) {
|
|
178
|
-
const found = new Map();
|
|
179
|
-
for (const dir of candidateRoots()) {
|
|
180
|
-
const described = describeRoot(dir, liveDays);
|
|
181
|
-
if (described) found.set(described.abs, described.root);
|
|
182
|
-
}
|
|
183
|
-
return [...found.values()].sort((a, b) => a.agent.localeCompare(b.agent, 'en'));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** Every `skills/` directory the three documented patterns can produce. */
|
|
187
|
-
function candidateRoots() {
|
|
188
|
-
const bases = safeReaddir(HOME).filter(isDirEntry).map((e) => path.join(HOME, e.name));
|
|
189
|
-
const configDir = path.join(HOME, '.config');
|
|
190
|
-
const configs = safeReaddir(configDir).filter(isDirEntry).map((e) => path.join(configDir, e.name, 'skills'));
|
|
191
|
-
return [
|
|
192
|
-
...bases.flatMap((base) => [path.join(base, 'skills'), path.join(base, 'agent', 'skills')]),
|
|
193
|
-
...configs,
|
|
194
|
-
];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Decide whether one candidate path is a skill root, and whether it is live.
|
|
199
|
-
* Returns null for paths the filters exclude (backups, marketplaces, non-dirs).
|
|
200
|
-
* @returns {{abs:string, root:object}|null}
|
|
201
|
-
*/
|
|
202
|
-
/**
|
|
203
|
-
* 空目录也算:新装的 agent 常常先建好 skills/ 但还没有内容,恰恰是最需要分发的地方。
|
|
204
|
-
* 路径本身已由三条固定模式产生,不会误扫用户数据目录。
|
|
205
|
-
*/
|
|
206
|
-
function looksLikeSkillRoot(dir) {
|
|
207
|
-
return isDir(dir);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function describeRoot(dir, liveDays) {
|
|
211
|
-
const abs = path.resolve(dir);
|
|
212
|
-
if (BACKUP_RE.test(abs) || SKIP_RE.test(abs) || !looksLikeSkillRoot(abs)) return null;
|
|
213
|
-
const entry = { agent: labelFor(abs), dir: abs, official: isOfficialSkillRoot(abs) };
|
|
214
|
-
return { abs, root: { ...entry, ...probeLiveness(entry, liveDays) } };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/** Qoder 原生 Delphi agent(external-only 下应为 0)。 */
|
|
218
|
-
export function nativeDelphiAgents() {
|
|
219
|
-
return delphiAgentDirs().flatMap((dir) => safeReaddir(dir)
|
|
220
|
-
.filter((e) => e.isFile() && DELPHI_AGENT_RE.test(e.name))
|
|
221
|
-
.map((e) => path.join(dir, e.name)));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* The `delphi-*.md` files Qoder deploys itself. `install` writes these when the
|
|
226
|
-
* config asks for native Delphi seats; the external-only profile must have none.
|
|
227
|
-
*/
|
|
228
|
-
function delphiAgentDirs() {
|
|
229
|
-
return ['.qoder', '.qoder-cn'].map((base) => path.join(HOME, base, 'agents'));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** 每个 agent 可能存在的本地 hooks 模板目录。 */
|
|
233
|
-
export function hookTemplateDirs(roots) {
|
|
234
|
-
const dirs = new Set([
|
|
235
|
-
...roots.map((root) => path.join(path.dirname(root.dir), 'git-hooks-template')),
|
|
236
|
-
path.join(HOME, '.qoder', 'git-hooks-template'),
|
|
237
|
-
path.join(HOME, '.config', 'opencode', 'git-hooks-template'),
|
|
238
|
-
]);
|
|
239
|
-
return [...dirs].filter(isDir);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Labels, official roots and the HOME-relative path helpers live in
|
|
243
|
-
// `agent-paths.mjs`; re-exported so `agents.mjs` stays one import for a caller
|
|
244
|
-
// asking about agents.
|
|
245
|
-
export {
|
|
246
|
-
OFFICIAL_ROOTS, relToHome, labelFor, isOfficialSkillRoot, agentHomeFor,
|
|
247
|
-
} from './agent-paths.mjs';
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { isDir, rmrf } from './util.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Backup retention: how many copies of each agent's skill to keep.
|
|
7
|
-
*
|
|
8
|
-
* Split out of `util.mjs` (Gate 4: 13 exports, maximum 10). Retention is a
|
|
9
|
-
* POLICY with a documented rationale; the rest of `util.mjs` is filesystem
|
|
10
|
-
* primitives. Keeping them together meant every caller doing `isFile` also
|
|
11
|
-
* carried the ability to delete a directory of backups.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/** Read a directory, treating an unreadable one as empty. */
|
|
15
|
-
function dirents(dir) {
|
|
16
|
-
try {
|
|
17
|
-
return fs.readdirSync(dir, { withFileTypes: true });
|
|
18
|
-
} catch {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* How many backups to keep per label. Three is enough to undo the last few
|
|
25
|
-
* installs and small enough that the directory cannot grow without bound.
|
|
26
|
-
*/
|
|
27
|
-
export const BACKUP_KEEP = 3;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Delete all but the newest `keep` stamp-suffixed entries under `root`.
|
|
31
|
-
*
|
|
32
|
-
* WHY THIS EXISTS
|
|
33
|
-
* ---------------
|
|
34
|
-
* Every `install.mjs` run backs up the copy it is about to overwrite, and
|
|
35
|
-
* nothing ever removed those backups. Measured on this machine before the
|
|
36
|
-
* policy existed: 50 backups / 11 MB, dating back to v1.1.0, growing by one
|
|
37
|
-
* set per install. Unbounded maintenance state is a slow leak the installer
|
|
38
|
-
* itself creates, so the installer has to bound it.
|
|
39
|
-
*
|
|
40
|
-
* Only entries that parse as `<label>-YYYYMMDD-HHMMSS` are candidates: an
|
|
41
|
-
* unrelated directory an operator put there is never touched, and a directory
|
|
42
|
-
* this function does not recognise cannot be deleted by accident. Sorting is
|
|
43
|
-
* by the timestamp IN THE NAME rather than mtime, because a restored or copied
|
|
44
|
-
* directory carries an mtime that says nothing about which backup is newer.
|
|
45
|
-
*
|
|
46
|
-
* The cap is PER LABEL, not for the directory as a whole. One `install.mjs`
|
|
47
|
-
* run backs up all nine agent copies with the same timestamp, so a single
|
|
48
|
-
* global cap of 3 would delete six of the backups that run had just written --
|
|
49
|
-
* the retain count would be consumed by simultaneity rather than by history,
|
|
50
|
-
* and rolling back one agent would be impossible while its siblings survived.
|
|
51
|
-
*
|
|
52
|
-
* @returns {string[]} the directory names that were removed
|
|
53
|
-
*/
|
|
54
|
-
export function pruneBackups(root, keep = BACKUP_KEEP) {
|
|
55
|
-
if (!isDir(root) || keep < 1) return [];
|
|
56
|
-
const doomed = [...groupByLabel(root).values()].flatMap((names) => names.slice(keep));
|
|
57
|
-
for (const name of doomed) rmrf(path.join(root, name));
|
|
58
|
-
return doomed;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Group stamped backup directories by agent label, each list newest first.
|
|
63
|
-
*
|
|
64
|
-
* Unrecognised directories are absent from the result rather than collected
|
|
65
|
-
* into an "unknown" bucket: this function decides what gets deleted, so a name
|
|
66
|
-
* it does not understand has to mean "leave it alone".
|
|
67
|
-
* @returns {Map<string, string[]>}
|
|
68
|
-
*/
|
|
69
|
-
function groupByLabel(root) {
|
|
70
|
-
const groups = new Map();
|
|
71
|
-
for (const name of stampedNames(root)) {
|
|
72
|
-
const label = name.slice(0, -STAMP_LEN);
|
|
73
|
-
if (!groups.has(label)) groups.set(label, []);
|
|
74
|
-
groups.get(label).push(name);
|
|
75
|
-
}
|
|
76
|
-
for (const [label, names] of groups) groups.set(label, names.sort((a, b) => STAMP_TAIL(b).localeCompare(STAMP_TAIL(a))));
|
|
77
|
-
return groups;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Names of the immediate subdirectories that carry a backup stamp. */
|
|
81
|
-
function stampedNames(root) {
|
|
82
|
-
return dirents(root)
|
|
83
|
-
.filter((d) => d.isDirectory() && STAMPED.test(d.name))
|
|
84
|
-
.map((d) => d.name);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** `<label>-YYYYMMDD-HHMMSS`; the label may itself contain dashes. */
|
|
88
|
-
const STAMPED = /-\d{8}-\d{6}$/;
|
|
89
|
-
|
|
90
|
-
/** Length of `-YYYYMMDD-HHMMSS`, i.e. the stamp plus its leading dash. */
|
|
91
|
-
const STAMP_LEN = 15;
|
|
92
|
-
|
|
93
|
-
/** The sortable timestamp at the end of a stamped directory name. */
|
|
94
|
-
function STAMP_TAIL(name) {
|
|
95
|
-
return String(name).slice(-STAMP_LEN);
|
|
96
|
-
}
|