@dzhechkov/harness-cli 0.3.237 → 0.3.239
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/.dz-manifest.json +8 -8
- package/README.md +88 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +274 -7
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
- package/sbom.json +7 -7
- package/src/cli.ts +290 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dzhechkov/harness-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.239",
|
|
4
4
|
"description": "The dz CLI — install AI skills for Claude Code, Codex, OpenCode, Hermes, OpenClaude, GitHub Copilot. 35 commands, 13 presets, 6 platform targets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@dzhechkov/skills-reverse-engineering": "^0.1.0",
|
|
58
58
|
"@dzhechkov/skills-presentation-storyteller": "^0.1.0",
|
|
59
59
|
"@dzhechkov/skills-website-cloner": "^0.1.0",
|
|
60
|
-
"@dzhechkov/harness-core": "0.3.
|
|
60
|
+
"@dzhechkov/harness-core": "0.3.130"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^25.6.0",
|
package/sbom.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"hashes": [
|
|
26
26
|
{
|
|
27
27
|
"alg": "SHA-256",
|
|
28
|
-
"content": "
|
|
28
|
+
"content": "6cdf43e972df9144b6eb93beed515bb216c1545bdd69b696b773a3dbe2d5b679"
|
|
29
29
|
}
|
|
30
30
|
]
|
|
31
31
|
},
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"hashes": [
|
|
106
106
|
{
|
|
107
107
|
"alg": "SHA-256",
|
|
108
|
-
"content": "
|
|
108
|
+
"content": "dfb260e21d46dfc8020eef0bf5ba570f9c335964181cf90446c1c5d761626415"
|
|
109
109
|
}
|
|
110
110
|
]
|
|
111
111
|
},
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"hashes": [
|
|
116
116
|
{
|
|
117
117
|
"alg": "SHA-256",
|
|
118
|
-
"content": "
|
|
118
|
+
"content": "a5b7d2fc4f582c507dfab54f1cc4754ca6700f7e686a3c72871afa807cceac25"
|
|
119
119
|
}
|
|
120
120
|
]
|
|
121
121
|
},
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"hashes": [
|
|
126
126
|
{
|
|
127
127
|
"alg": "SHA-256",
|
|
128
|
-
"content": "
|
|
128
|
+
"content": "8fb0c46e092ac7240af9d254f272da649d911b3307b39dc60ac1ef43d349834f"
|
|
129
129
|
}
|
|
130
130
|
]
|
|
131
131
|
},
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"hashes": [
|
|
186
186
|
{
|
|
187
187
|
"alg": "SHA-256",
|
|
188
|
-
"content": "
|
|
188
|
+
"content": "82a481991b03522d4da62fe49c032c03445928a46a226e8cbb05498eb9321950"
|
|
189
189
|
}
|
|
190
190
|
]
|
|
191
191
|
},
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
"hashes": [
|
|
206
206
|
{
|
|
207
207
|
"alg": "SHA-256",
|
|
208
|
-
"content": "
|
|
208
|
+
"content": "ccb1af3966a258b17eed99ce8b830639166ad8a8a5075ca027d8f30077025d19"
|
|
209
209
|
}
|
|
210
210
|
]
|
|
211
211
|
},
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
"hashes": [
|
|
226
226
|
{
|
|
227
227
|
"alg": "SHA-256",
|
|
228
|
-
"content": "
|
|
228
|
+
"content": "3deb99917f3d8b4a5c9a3b0315bd65a3099ce2b508121cfa2bdeed19b7554d48"
|
|
229
229
|
}
|
|
230
230
|
]
|
|
231
231
|
},
|
package/src/cli.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
8
8
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
-
import { execSync } from 'node:child_process';
|
|
10
|
+
import { execSync, spawn } from 'node:child_process';
|
|
11
11
|
import { homedir, tmpdir } from 'node:os';
|
|
12
12
|
import { createRequire } from 'node:module';
|
|
13
13
|
|
|
@@ -64,6 +64,13 @@ import {
|
|
|
64
64
|
recallHybrid,
|
|
65
65
|
teachGuard,
|
|
66
66
|
mirrorPatternsToVector,
|
|
67
|
+
mirrorEntriesToVector,
|
|
68
|
+
patternVectorEntry,
|
|
69
|
+
readMemoryLearningConfig,
|
|
70
|
+
promotePatterns,
|
|
71
|
+
quarantineExpiryCandidates,
|
|
72
|
+
pruneQuarantinePatterns,
|
|
73
|
+
clearAgentdbQuarantine,
|
|
67
74
|
vectorMirrorEnabled,
|
|
68
75
|
vectorTierStatus,
|
|
69
76
|
resolveVectorEngine,
|
|
@@ -185,6 +192,11 @@ import {
|
|
|
185
192
|
classifyDelivery,
|
|
186
193
|
isUsablePlaneResult,
|
|
187
194
|
renderDeliveryReview,
|
|
195
|
+
scanSkillsLayout,
|
|
196
|
+
parseInitFacts,
|
|
197
|
+
verifyRegistration,
|
|
198
|
+
registrationExitCode,
|
|
199
|
+
renderRegistrationReport,
|
|
188
200
|
} from '@dzhechkov/harness-core';
|
|
189
201
|
import type { Family, ModelRung, Candidate as BtoCandidate, DimScores } from '@dzhechkov/harness-core';
|
|
190
202
|
import type { SetupSpec } from '@dzhechkov/harness-core';
|
|
@@ -215,11 +227,12 @@ Usage:
|
|
|
215
227
|
dz release [--filter <name>] [--tag] [--publish] [--json] [--dry-run] [--no-issue] (VERIFIED release: 4 HARD gates in FRONT of dz publish — full package test suites, audit >=high, node --check of every dist/bin file, bin smoke-boot via "node <bin> --help" — any red gate STOPS the release (exit 1) + best-effort gh issue; all green ⇒ re-sign reminder, then prints the ready dz publish command (or chains with --publish); never duplicates publish's own gates)
|
|
216
228
|
dz parity [--target <name>] [--json] (the honest feature×target map, COMPUTED from the capability model — which harness feature is full / manual / absent on each of the ${TARGET_NAMES.length} targets, and via which form)
|
|
217
229
|
dz delivery-check --slug <slug> [--context-only] [--findings <f.json>] [--strict] [--author <model>] [--json] (portable Step-10 Delivery Gate: prints the 4-plane review brief + artifact probes; --findings classifies a fed-back review into a fail-closed ready|blocked hand-off and writes features/<slug>/10_delivery_review.md; --strict exits 1 on blocked)
|
|
230
|
+
dz skills-verify [--dir <project>] [--expect a,b] [--static] [--strict] [--json] (does .claude/skills/ actually REGISTER? --static = instant layout scan for CI; default reads the authoritative system/init listing from a real session. exit 0 pass / 1 fail / 2 inconclusive — never a false pass)
|
|
218
231
|
dz setup --target <name> [--preset <name>] [--select id,id,...] [--skills-dir <dir>] [--project <dir>] [--memory agentdb] [--no-memory] [--no-hooks] [--install-driver] [--force] [--enrich]
|
|
219
232
|
dz teach "<pattern>" [--reward <0-1>] [--domain <name>] [--type rule|success-pattern|lesson-learned] [--project <dir>] [--no-mirror] (--project pins the learned store to <dir>/.dz, not the cwd — pin to a canonical brain)
|
|
220
233
|
dz teach --from-json <file> [--project <dir>] [--no-mirror] (bulk-import a 'dz recall --all --json' export — share a learned store across machines)
|
|
221
|
-
dz consolidate [--sessions-dir <dir>] [--project <dir>] [--no-mirror] [--prune-noise [--apply]] (
|
|
222
|
-
dz recall "<query>" [--limit <N>] [--semantic | --no-semantic] [--books [--book <slug>]] [--project <dir>] | dz recall --all [--json] | dz recall --usage [--json] | dz recall --forget <dzId>[,<dzId>] [--apply] (forget: dry-run default; snapshots before removing)
|
|
234
|
+
dz consolidate [--sessions-dir <dir>] [--project <dir>] [--no-mirror] [--prune-noise [--apply]] [--prune-quarantine [--apply]] (both prunes: DRY-RUN by default; --apply snapshots then deletes; prune-quarantine = expired unproven lessons ONLY, never coupled to noise)
|
|
235
|
+
dz recall "<query>" [--limit <N>] [--semantic | --no-semantic] [--books [--book <slug>]] [--project <dir>] | dz recall --all [--json] | dz recall --usage [--json] | dz recall --forget <dzId>[,<dzId>] [--apply] | dz recall --promote <dzId>[,<dzId>] [--apply] (forget/promote: dry-run default; forget snapshots before removing; promote lifts lesson-quarantine)
|
|
223
236
|
dz vector status [--project <dir>] [--json] (semantic tier: engine, mirrored vs lexical counts, pending queue)
|
|
224
237
|
dz vector reindex [--project <dir>] [--json] (snapshot, re-embed learned-pattern vectors, stamp current model)
|
|
225
238
|
dz vector export <path> [--project <dir>] (portable VECTOR form (.rvf, opt-in RVF engine); patterns ship via recall --all --json)
|
|
@@ -1515,6 +1528,16 @@ async function cmdTeach(options: Map<string, string>, flags: Set<string>, cwd: s
|
|
|
1515
1528
|
const receipt = await mirrorPatternsToVector(root, records, source);
|
|
1516
1529
|
if (receipt.mirrored > 0) write(` ↳ mirrored to vector tier (${receipt.engine ?? 'vector'})`);
|
|
1517
1530
|
};
|
|
1531
|
+
// lesson-quarantine FR-8: the fresh-teach mirror carries the qStatus marker so the hook daemon
|
|
1532
|
+
// (which reads only the mirror's metadata) can exclude unproven lessons from auto-inject.
|
|
1533
|
+
const emitMirrorQ = async (root: string, records: readonly PatternRecord[], source: string, quarantined: boolean): Promise<void> => {
|
|
1534
|
+
if (flags.has('no-mirror') || records.length === 0 || !vectorMirrorEnabled(root)) return;
|
|
1535
|
+
const entries = records
|
|
1536
|
+
.map((r) => patternVectorEntry(r, source, quarantined ? { quarantined: true } : {}))
|
|
1537
|
+
.filter((e): e is NonNullable<typeof e> => e !== undefined);
|
|
1538
|
+
const receipt = await mirrorEntriesToVector(root, entries);
|
|
1539
|
+
if (receipt.mirrored > 0) write(` ↳ mirrored to vector tier (${receipt.engine ?? 'vector'})${quarantined ? ' [quarantined]' : ''}`);
|
|
1540
|
+
};
|
|
1518
1541
|
|
|
1519
1542
|
// `dz teach --harmonize` — documented ALIAS of `dz vector harmonize`: SEMANTIC dedup of the
|
|
1520
1543
|
// learned store. ONE implementation (harmonizeVectorStore), two entry points (QR-6). Routed
|
|
@@ -1595,6 +1618,9 @@ async function cmdTeach(options: Map<string, string>, flags: Set<string>, cwd: s
|
|
|
1595
1618
|
const trained = await backend.train();
|
|
1596
1619
|
if (trained.flushed > 0) {
|
|
1597
1620
|
write(`↳ reinforced ${reinforce}`);
|
|
1621
|
+
// lesson-quarantine: reinforcement IS promotion — keep the hook daemon's mirror in step.
|
|
1622
|
+
const clearedQ = clearAgentdbQuarantine(projectRoot, [reinforce]);
|
|
1623
|
+
if (clearedQ.cleared > 0) write(` ↳ promoted out of quarantine (mirror updated)`);
|
|
1598
1624
|
return 0;
|
|
1599
1625
|
}
|
|
1600
1626
|
// HIGH-fix: a no-match must NOT auto-teach the raw argument — callers pass dzIds or truncated
|
|
@@ -1629,6 +1655,8 @@ async function cmdTeach(options: Map<string, string>, flags: Set<string>, cwd: s
|
|
|
1629
1655
|
// teach below so the lesson is NEVER silently discarded (the exact silent-drop the ADR forbids).
|
|
1630
1656
|
if (trained.flushed > 0) {
|
|
1631
1657
|
write(`↳ reinforced existing pattern ${verdict.dzId} (cos=${verdict.cosine.toFixed(2)}) — not re-added`);
|
|
1658
|
+
const clearedQ = clearAgentdbQuarantine(projectRoot, [verdict.dzId]);
|
|
1659
|
+
if (clearedQ.cleared > 0) write(' ↳ promoted out of quarantine (mirror updated)');
|
|
1632
1660
|
return 0;
|
|
1633
1661
|
}
|
|
1634
1662
|
write(`dz teach --guard: reinforce of ${verdict.dzId} did not flush (backend off or write failure) — teaching the lesson normally instead`);
|
|
@@ -1658,13 +1686,18 @@ async function cmdTeach(options: Map<string, string>, flags: Set<string>, cwd: s
|
|
|
1658
1686
|
// Tier-2 (ADR-005): persist through the unified @dzhechkov/memory store. recordPattern
|
|
1659
1687
|
// folds any legacy .dz/patterns.jsonl into the backend (idempotent) and returns the
|
|
1660
1688
|
// total count. The lossy `npx agentdb add` dual-write was removed in Tier-1 (audit #6).
|
|
1661
|
-
|
|
1689
|
+
// lesson-quarantine (opt-in): a fresh lesson is a HYPOTHESIS until it earns promotion.
|
|
1690
|
+
const quarantineOn = readMemoryLearningConfig(projectRoot).quarantine;
|
|
1691
|
+
const count = await recordPattern(projectRoot, entry, quarantineOn ? { quarantine: true } : {});
|
|
1662
1692
|
|
|
1663
1693
|
write(`Learned: "${pattern.slice(0, 60)}${pattern.length > 60 ? '...' : ''}"`);
|
|
1664
1694
|
write(` Domain: ${domain} Reward: ${reward} Backend: memory (@dzhechkov/memory)`);
|
|
1665
1695
|
write(` Total patterns: ${count}`);
|
|
1696
|
+
if (quarantineOn) {
|
|
1697
|
+
write(' ⚠ quarantined: excluded from auto-inject, damped in recall — promote by confirming it (dz teach --reinforce "<text>") or dz recall --promote <dzId> --apply');
|
|
1698
|
+
}
|
|
1666
1699
|
// The lexical write above is durable — the vector mirror is strictly best-effort (I-3).
|
|
1667
|
-
await
|
|
1700
|
+
await emitMirrorQ(projectRoot, [entry], 'dz-teach', quarantineOn);
|
|
1668
1701
|
return 0;
|
|
1669
1702
|
}
|
|
1670
1703
|
|
|
@@ -1673,6 +1706,23 @@ async function cmdConsolidate(options: Map<string, string>, flags: Set<string>,
|
|
|
1673
1706
|
const sessionsDirOpt = options.get('sessions-dir');
|
|
1674
1707
|
const pruneNoise = flags.has('prune-noise');
|
|
1675
1708
|
|
|
1709
|
+
// lesson-quarantine FR-7: expiry is a SEPARATE, explicit surface — never coupled to prune-noise
|
|
1710
|
+
// (the recalled decay-vs-noise lesson: valid-but-unproven is not garbage). Dry-run by default.
|
|
1711
|
+
if (flags.has('prune-quarantine')) {
|
|
1712
|
+
const cfg = readMemoryLearningConfig(projectRoot);
|
|
1713
|
+
const res = pruneQuarantinePatterns(projectRoot, { dryRun: !flags.has('apply'), expireDays: cfg.quarantineExpireDays });
|
|
1714
|
+
if (!flags.has('apply')) {
|
|
1715
|
+
write(`dz consolidate --prune-quarantine: DRY RUN — ${res.candidates.length} expired quarantined lesson(s) (> ${cfg.quarantineExpireDays}d, never reinforced)`);
|
|
1716
|
+
for (const c of res.candidates) write(` [${c.ageDays < 0 ? '?' : c.ageDays}d] ${c.dzId} ${c.text.slice(0, 70)}`);
|
|
1717
|
+
if (res.candidates.length > 0) write(' → re-run with --apply to remove (snapshots first); or promote keepers: dz recall --promote <dzId> --apply');
|
|
1718
|
+
return 0;
|
|
1719
|
+
}
|
|
1720
|
+
if (res.error !== undefined) { write(`dz consolidate --prune-quarantine: ${res.error}`); return 1; }
|
|
1721
|
+
write(`dz consolidate --prune-quarantine: removed ${res.removed} expired quarantined lesson(s)`);
|
|
1722
|
+
if (res.snapshot !== undefined) write(` snapshot: ${res.snapshot}`);
|
|
1723
|
+
return 0;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1676
1726
|
// --prune-noise: RETRO-PRUNE legacy noise (tool telemetry + system-wrapper "responses") from
|
|
1677
1727
|
// the lexical store AND the agentdb vector mirror BEFORE harvesting, so this run's watermark
|
|
1678
1728
|
// never re-learns from junk. Best-effort — a prune error is reported, never fatal.
|
|
@@ -1890,12 +1940,53 @@ async function cmdRecallForget(
|
|
|
1890
1940
|
return 0;
|
|
1891
1941
|
}
|
|
1892
1942
|
|
|
1943
|
+
/**
|
|
1944
|
+
* `dz recall --promote <dzId>[,<dzId>…] [--apply]` — lift quarantine from NAMED records
|
|
1945
|
+
* (lesson-quarantine FR-6b). Dry-run by default, the --forget symmetry. Also clears the
|
|
1946
|
+
* agentdb mirror's qStatus (best-effort) so the hook daemon stops excluding promoted lessons.
|
|
1947
|
+
*/
|
|
1948
|
+
async function cmdRecallPromote(
|
|
1949
|
+
options: Map<string, string>,
|
|
1950
|
+
flags: Set<string>,
|
|
1951
|
+
projectRoot: string,
|
|
1952
|
+
write: Write,
|
|
1953
|
+
): Promise<number> {
|
|
1954
|
+
const ids = (options.get('promote') ?? '').split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
1955
|
+
if (ids.length === 0) {
|
|
1956
|
+
write('dz recall --promote: no ids given (comma-separated dzIds; quarantined ones are marked ⚠q in recall)');
|
|
1957
|
+
return 1;
|
|
1958
|
+
}
|
|
1959
|
+
if (!flags.has('apply')) {
|
|
1960
|
+
const records = loadStoreRecords(projectRoot);
|
|
1961
|
+
const found = ids.filter((id) => records.some((r) => r.id === id));
|
|
1962
|
+
write(`dz recall --promote: DRY RUN — ${found.length}/${ids.length} id(s) match the store. Re-run with --apply to promote.`);
|
|
1963
|
+
return 0;
|
|
1964
|
+
}
|
|
1965
|
+
const res = await promotePatterns(projectRoot, ids);
|
|
1966
|
+
// Codex-QE finding 5: even on a mid-batch failure, the ALREADY-promoted records must get their
|
|
1967
|
+
// mirror rows cleared — otherwise the canonical store and the hook-visible mirror split-brain.
|
|
1968
|
+
if (res.promoted.length > 0) {
|
|
1969
|
+
const cleared = clearAgentdbQuarantine(projectRoot, res.promoted);
|
|
1970
|
+
if (cleared.cleared > 0) write(` ↳ mirror updated (${cleared.cleared} row(s) un-quarantined in agentdb)`);
|
|
1971
|
+
else if (cleared.error !== undefined) write(` ⚠ mirror not updated (${cleared.error}) — run dz vector reindex to resync`);
|
|
1972
|
+
}
|
|
1973
|
+
if (!res.ok) {
|
|
1974
|
+
write(`dz recall --promote: failed — ${res.error ?? 'unknown error'} (promoted so far: ${res.promoted.length})`);
|
|
1975
|
+
return 1;
|
|
1976
|
+
}
|
|
1977
|
+
write(`dz recall --promote: promoted ${res.promoted.length} record(s)`);
|
|
1978
|
+
if (res.notQuarantined.length > 0) write(` already promoted (not quarantined): ${res.notQuarantined.join(', ')}`);
|
|
1979
|
+
if (res.notFound.length > 0) write(` not found: ${res.notFound.join(', ')}`);
|
|
1980
|
+
return 0;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1893
1983
|
async function cmdRecall(options: Map<string, string>, flags: Set<string>, cwd: string, write: Write): Promise<number> {
|
|
1894
1984
|
const projectRoot = resolve(cwd, options.get('project') ?? '.');
|
|
1895
1985
|
const asJson = flags.has('json');
|
|
1896
1986
|
const all = flags.has('all');
|
|
1897
1987
|
if (flags.has('usage')) return cmdRecallUsage(options, flags, projectRoot, write);
|
|
1898
1988
|
if (options.has('forget')) return cmdRecallForget(options, flags, projectRoot, write);
|
|
1989
|
+
if (options.has('promote')) return cmdRecallPromote(options, flags, projectRoot, write);
|
|
1899
1990
|
|
|
1900
1991
|
// --all: dump the entire learned store (backend-agnostic, via loadStorePatternsSync).
|
|
1901
1992
|
// With --json this is the portable export the agentdb-memory MCP bridge consumes.
|
|
@@ -1994,9 +2085,16 @@ async function cmdRecall(options: Map<string, string>, flags: Set<string>, cwd:
|
|
|
1994
2085
|
const lexLabel = result.lexicalBackend === 'sqlite' ? 'SQLite FTS5' : 'keyword (JSON)';
|
|
1995
2086
|
const ranking = vectorOn ? `${lexLabel} + vector (${result.vectorEngine}) ranking` : `${lexLabel} ranking (lexical)`;
|
|
1996
2087
|
write(`dz recall "${query}" — ${hits.length} hit(s), ${ranking}`);
|
|
2088
|
+
let sawQuarantined = false;
|
|
1997
2089
|
for (const h of hits) {
|
|
1998
2090
|
const backendTag = vectorOn ? ` ⟨${h.backend}⟩` : '';
|
|
1999
|
-
|
|
2091
|
+
const qTag = h.quarantined === true ? ' ⚠q' : '';
|
|
2092
|
+
if (h.quarantined === true) sawQuarantined = true;
|
|
2093
|
+
write(` [${h.pattern.reward.toFixed(2)}] (${h.pattern.domain})${backendTag}${qTag} ${h.pattern.pattern.slice(0, 80)}`);
|
|
2094
|
+
}
|
|
2095
|
+
if (sawQuarantined) {
|
|
2096
|
+
// The loop stays VISIBLE (ADR D2): a quarantined hit is shown, marked, and explained.
|
|
2097
|
+
write(' ⚠q = quarantined (unproven hypothesis, rank damped) — confirm with dz teach --reinforce, or dz recall --promote <dzId> --apply');
|
|
2000
2098
|
}
|
|
2001
2099
|
if (result.vectorError !== undefined && mode !== 'lexical') {
|
|
2002
2100
|
// Engine present but the semantic leg failed/timed out — one honest line, exit 0 (05 §2.3).
|
|
@@ -5460,6 +5558,190 @@ function nameFor(t: { file: string; name?: string }, outcome: 'pass' | 'fail' |
|
|
|
5460
5558
|
* --author <model> cosmetic: the reviewer to dispatch, printed alongside the brief
|
|
5461
5559
|
* --json machine contract { planesChecked, planesSkipped, findings, handoff, artifact }
|
|
5462
5560
|
*/
|
|
5561
|
+
/**
|
|
5562
|
+
* Env vars an INHERITED Claude session leaks into a child. Left in place, the probe can silently
|
|
5563
|
+
* read the parent's project instead of the target — the exact confound that made a hand-rolled
|
|
5564
|
+
* 2026-07-23 probe untrustworthy until controls were added (feature skills-verify, ADR-001).
|
|
5565
|
+
*/
|
|
5566
|
+
const PROBE_SCRUB_ENV = [
|
|
5567
|
+
'CLAUDE_CODE_CHILD_SESSION',
|
|
5568
|
+
'CLAUDE_CODE_SESSION_ID',
|
|
5569
|
+
'CLAUDECODE',
|
|
5570
|
+
'CLAUDE_CODE_ENTRYPOINT',
|
|
5571
|
+
'CLAUDE_CODE_EXECPATH',
|
|
5572
|
+
'CLAUDE_PLUGIN_DATA',
|
|
5573
|
+
'AI_AGENT',
|
|
5574
|
+
];
|
|
5575
|
+
|
|
5576
|
+
/**
|
|
5577
|
+
* Start a real Claude session in `projectDir` and capture its stream until the `system/init` event
|
|
5578
|
+
* lands, then kill it — the model never answers, so the probe costs ~no tokens. Never throws:
|
|
5579
|
+
* every failure becomes an `error` string, which the pure classifier turns into `inconclusive`.
|
|
5580
|
+
*/
|
|
5581
|
+
function probeInitStream(projectDir: string, timeoutMs: number): Promise<{ stream: string; error: string | null }> {
|
|
5582
|
+
return new Promise((resolveProbe) => {
|
|
5583
|
+
const env: NodeJS.ProcessEnv = { ...process.env };
|
|
5584
|
+
for (const key of PROBE_SCRUB_ENV) delete env[key];
|
|
5585
|
+
env.CLAUDE_PROJECT_DIR = projectDir;
|
|
5586
|
+
|
|
5587
|
+
let out = '';
|
|
5588
|
+
let err = '';
|
|
5589
|
+
let settled = false;
|
|
5590
|
+
let child: ReturnType<typeof spawn>;
|
|
5591
|
+
|
|
5592
|
+
const finish = (error: string | null): void => {
|
|
5593
|
+
if (settled) return;
|
|
5594
|
+
settled = true;
|
|
5595
|
+
clearTimeout(timer);
|
|
5596
|
+
try {
|
|
5597
|
+
child?.kill('SIGTERM');
|
|
5598
|
+
} catch {
|
|
5599
|
+
/* the child may already be gone */
|
|
5600
|
+
}
|
|
5601
|
+
resolveProbe({ stream: out, error });
|
|
5602
|
+
};
|
|
5603
|
+
|
|
5604
|
+
const timer = setTimeout(
|
|
5605
|
+
() => finish(`no init event within ${Math.round(timeoutMs / 1000)}s (is \`claude\` logged in?)`),
|
|
5606
|
+
timeoutMs,
|
|
5607
|
+
);
|
|
5608
|
+
|
|
5609
|
+
try {
|
|
5610
|
+
// NOT `--bare`: that mode skips plugin credentials and fails with "Not logged in".
|
|
5611
|
+
child = spawn('claude', ['-p', 'ok', '--output-format', 'stream-json', '--verbose'], {
|
|
5612
|
+
cwd: projectDir,
|
|
5613
|
+
env,
|
|
5614
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
5615
|
+
});
|
|
5616
|
+
} catch (error) {
|
|
5617
|
+
finish(`cannot run \`claude\`: ${error instanceof Error ? error.message : String(error)}`);
|
|
5618
|
+
return;
|
|
5619
|
+
}
|
|
5620
|
+
|
|
5621
|
+
child.stdout?.on('data', (chunk: Buffer) => {
|
|
5622
|
+
out += chunk.toString();
|
|
5623
|
+
// Reuse the pure parser so a partially-flushed line simply waits for more data.
|
|
5624
|
+
if (parseInitFacts(out)) finish(null);
|
|
5625
|
+
});
|
|
5626
|
+
child.stderr?.on('data', (chunk: Buffer) => {
|
|
5627
|
+
err += chunk.toString();
|
|
5628
|
+
});
|
|
5629
|
+
child.on('error', (error: Error) => finish(`cannot run \`claude\`: ${error.message}`));
|
|
5630
|
+
child.on('close', (code) => {
|
|
5631
|
+
if (parseInitFacts(out)) finish(null);
|
|
5632
|
+
else finish(err.trim() || `\`claude\` exited ${code} without an init event`);
|
|
5633
|
+
});
|
|
5634
|
+
});
|
|
5635
|
+
}
|
|
5636
|
+
|
|
5637
|
+
/**
|
|
5638
|
+
* `dz skills-verify` — does this project's `.claude/skills/` actually REGISTER? (feature
|
|
5639
|
+
* skills-verify, ADR-001.) L1 static scan is instant and CI-safe; the live layer reads the
|
|
5640
|
+
* authoritative `system/init` listing. Fail-closed: unobservable ⇒ inconclusive, never pass.
|
|
5641
|
+
*/
|
|
5642
|
+
async function cmdSkillsVerify(
|
|
5643
|
+
options: Map<string, string>,
|
|
5644
|
+
flags: Set<string>,
|
|
5645
|
+
cwd: string,
|
|
5646
|
+
write: Write,
|
|
5647
|
+
): Promise<number> {
|
|
5648
|
+
const json = flags.has('json');
|
|
5649
|
+
if (flags.has('help')) {
|
|
5650
|
+
write('dz skills-verify [--dir <project>] [--expect a,b] [--static] [--strict] [--timeout <s>] [--json]');
|
|
5651
|
+
write(' Verifies that a project\'s .claude/skills/ actually register in Claude Code.');
|
|
5652
|
+
write(' --static layout scan only (no Claude session, CI-safe): flags dirs that can never register');
|
|
5653
|
+
write(' default also starts a real session and reads the authoritative system/init listing');
|
|
5654
|
+
write(' exit: 0 pass · 1 fail · 2 inconclusive (--strict makes inconclusive exit 1)');
|
|
5655
|
+
return 0;
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5658
|
+
const allowedFlags = new Set(['json', 'help', 'static', 'strict']);
|
|
5659
|
+
const allowedOptions = new Set(['dir', 'expect', 'timeout']);
|
|
5660
|
+
const usage = ' allowed: --dir <project>, --expect a,b, --timeout <s>, --static, --strict, --json';
|
|
5661
|
+
if (options.has('_positional_0')) {
|
|
5662
|
+
const message = `unexpected argument "${options.get('_positional_0')}"`;
|
|
5663
|
+
write(json ? JSON.stringify({ error: message, exitCode: 1 }) : `dz skills-verify: ${message}\n${usage}`);
|
|
5664
|
+
return 1;
|
|
5665
|
+
}
|
|
5666
|
+
for (const flag of flags) {
|
|
5667
|
+
if (!allowedFlags.has(flag)) {
|
|
5668
|
+
write(json ? JSON.stringify({ error: `unknown option --${flag}`, exitCode: 1 }) : `dz skills-verify: unknown option --${flag}\n${usage}`);
|
|
5669
|
+
return 1;
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
for (const key of options.keys()) {
|
|
5673
|
+
if (key.startsWith('_positional_')) continue;
|
|
5674
|
+
if (!allowedOptions.has(key)) {
|
|
5675
|
+
write(json ? JSON.stringify({ error: `unknown option --${key}`, exitCode: 1 }) : `dz skills-verify: unknown option --${key}\n${usage}`);
|
|
5676
|
+
return 1;
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
|
|
5680
|
+
const projectDir = resolve(cwd, options.get('dir') ?? '.');
|
|
5681
|
+
const scan = scanSkillsLayout(projectDir);
|
|
5682
|
+
|
|
5683
|
+
const expected = options.has('expect')
|
|
5684
|
+
? (options.get('expect') ?? '')
|
|
5685
|
+
.split(',')
|
|
5686
|
+
.map((s) => s.trim())
|
|
5687
|
+
.filter(Boolean)
|
|
5688
|
+
: scan.registrable;
|
|
5689
|
+
|
|
5690
|
+
// ── L1 only: deterministic, no session, safe for CI ──
|
|
5691
|
+
if (flags.has('static')) {
|
|
5692
|
+
const exitCode = scan.findings.length > 0 ? 1 : 0;
|
|
5693
|
+
if (json) {
|
|
5694
|
+
write(JSON.stringify({ mode: 'static', ...scan, expected, exitCode }, null, 2));
|
|
5695
|
+
} else {
|
|
5696
|
+
write(`dz skills-verify (static): ${scan.registrable.length} registrable skill dir(s) under ${scan.skillsRoot}`);
|
|
5697
|
+
if (!scan.exists) write(' no .claude/skills/ directory here');
|
|
5698
|
+
for (const f of scan.findings) write(` [${f.kind}] ${f.detail}`);
|
|
5699
|
+
write(scan.findings.length ? ` ${scan.findings.length} layout problem(s) — these can never register` : ' no layout problems found');
|
|
5700
|
+
write(' (static is a PROXY — run without --static to read the real registration listing)');
|
|
5701
|
+
}
|
|
5702
|
+
return exitCode;
|
|
5703
|
+
}
|
|
5704
|
+
|
|
5705
|
+
// ── L2: the authoritative listing ──
|
|
5706
|
+
const timeoutSec = Number(options.get('timeout') ?? '180');
|
|
5707
|
+
const timeoutMs = Number.isFinite(timeoutSec) && timeoutSec > 0 ? timeoutSec * 1000 : 180_000;
|
|
5708
|
+
if (!json) write(`dz skills-verify: starting a session in ${projectDir} to read the real registration listing…`);
|
|
5709
|
+
|
|
5710
|
+
const { stream, error } = await probeInitStream(projectDir, timeoutMs);
|
|
5711
|
+
|
|
5712
|
+
// `init.skills` carries names, not provenance: a USER-level skill of the same name would satisfy
|
|
5713
|
+
// the expectation while the project's own copy stays broken. Collect the collisions so the
|
|
5714
|
+
// classifier can refuse to attribute registration to this project (Codex QE #2).
|
|
5715
|
+
const userSkillsDir = join(homedir(), '.claude', 'skills');
|
|
5716
|
+
const ambiguous = expected.filter((name) => existsSync(join(userSkillsDir, name, 'SKILL.md')));
|
|
5717
|
+
|
|
5718
|
+
// realpath so a symlinked project still matches its canonical cwd (Codex QE #6).
|
|
5719
|
+
const canonical = (p: string): string => {
|
|
5720
|
+
try {
|
|
5721
|
+
return realpathSync(p);
|
|
5722
|
+
} catch {
|
|
5723
|
+
return resolve(p);
|
|
5724
|
+
}
|
|
5725
|
+
};
|
|
5726
|
+
|
|
5727
|
+
const result = verifyRegistration(
|
|
5728
|
+
{
|
|
5729
|
+
projectDir,
|
|
5730
|
+
scan,
|
|
5731
|
+
probe: error === null ? { ok: true, stream } : { ok: false, error },
|
|
5732
|
+
// The provenance check RAN (that is what `checked: true` asserts) — see `ambiguous` above.
|
|
5733
|
+
provenance: { checked: true, ambiguous },
|
|
5734
|
+
...(options.has('expect') ? { expected } : {}),
|
|
5735
|
+
},
|
|
5736
|
+
{ resolvePath: canonical },
|
|
5737
|
+
);
|
|
5738
|
+
const exitCode = registrationExitCode(result.verdict, flags.has('strict'));
|
|
5739
|
+
|
|
5740
|
+
if (json) write(JSON.stringify({ mode: 'live', ...result, skillsRoot: scan.skillsRoot, exitCode }, null, 2));
|
|
5741
|
+
else write(renderRegistrationReport(result, scan));
|
|
5742
|
+
return exitCode;
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5463
5745
|
function cmdDeliveryCheck(options: Map<string, string>, flags: Set<string>, cwd: string, write: Write): number {
|
|
5464
5746
|
let repoRoot = cwd;
|
|
5465
5747
|
try { repoRoot = execSync('git rev-parse --show-toplevel', { cwd, encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { /* not git */ }
|
|
@@ -6003,6 +6285,8 @@ export async function runCli(argv: string[], io: CliIo = {}): Promise<number> {
|
|
|
6003
6285
|
return cmdDiscriminationCheck(options, flags, cwd, write);
|
|
6004
6286
|
case 'delivery-check':
|
|
6005
6287
|
return cmdDeliveryCheck(options, flags, cwd, write);
|
|
6288
|
+
case 'skills-verify':
|
|
6289
|
+
return cmdSkillsVerify(options, flags, cwd, write);
|
|
6006
6290
|
case 'routing':
|
|
6007
6291
|
return cmdRouting(options, flags, cwd, write);
|
|
6008
6292
|
case 'bto-optimize':
|