@holmes-lab/holmes-kit 0.40.1 → 0.41.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/CHANGELOG.md +86 -0
- package/README.md +12 -4
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/approve-context.js +4 -3
- package/dist/holmes/cli/approve.js +22 -12
- package/dist/holmes/cli/autonomy.d.ts +21 -0
- package/dist/holmes/cli/autonomy.js +35 -5
- package/dist/holmes/cli/doctor.js +58 -6
- package/dist/holmes/cli/index.js +371 -250
- package/dist/holmes/cli/init.js +26 -6
- package/dist/holmes/cli/ledger-witness.d.ts +61 -0
- package/dist/holmes/cli/ledger-witness.js +252 -0
- package/dist/holmes/cli/playbook-skills.d.ts +3 -56
- package/dist/holmes/cli/playbook-skills.js +63 -354
- package/dist/holmes/cli/test-platform.d.ts +6 -0
- package/dist/holmes/cli/test-platform.js +12 -0
- package/dist/holmes/config/config.d.ts +9 -1
- package/dist/holmes/config/config.js +10 -3
- package/dist/holmes/governance/approval-grants.d.ts +2 -0
- package/dist/holmes/governance/approval-grants.js +6 -5
- package/dist/holmes/governance/approval-queue.d.ts +65 -1
- package/dist/holmes/governance/approval-queue.js +279 -9
- package/dist/holmes/governance/autonomous-shell.d.ts +13 -1
- package/dist/holmes/governance/autonomous-shell.js +157 -4
- package/dist/holmes/governance/autonomy.d.ts +209 -0
- package/dist/holmes/governance/autonomy.js +1129 -6
- package/dist/holmes/governance/install-manifest.d.ts +7 -4
- package/dist/holmes/governance/install-manifest.js +159 -15
- package/dist/holmes/governance/ledger-witness.d.ts +63 -0
- package/dist/holmes/governance/ledger-witness.js +296 -0
- package/dist/holmes/governance/provenance-chain.d.ts +8 -1
- package/dist/holmes/governance/provenance-chain.js +23 -4
- package/dist/holmes/governance/recorded-pairs.d.ts +4 -0
- package/dist/holmes/governance/recorded-pairs.js +25 -1
- package/dist/holmes/governance/session-context.d.ts +7 -0
- package/dist/holmes/governance/session-context.js +34 -6
- package/dist/holmes/guardrail/anchor-scope-text.d.ts +9 -0
- package/dist/holmes/guardrail/anchor-scope-text.js +7 -0
- package/dist/holmes/guardrail/command-traits.d.ts +102 -0
- package/dist/holmes/guardrail/command-traits.js +379 -0
- package/dist/holmes/guardrail/fixtures/manager-builtins.json +23 -0
- package/dist/holmes/guardrail/fixtures/npm-commands.json +7 -0
- package/dist/holmes/guardrail/outward-acts.d.ts +47 -0
- package/dist/holmes/guardrail/outward-acts.js +1102 -0
- package/dist/holmes/guardrail/refusal-codes.js +8 -1
- package/dist/holmes/guardrail/refusal-templates.d.ts +15 -0
- package/dist/holmes/guardrail/refusal-templates.js +71 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +22 -6
- package/dist/holmes/guardrail/risk-classifier.js +12 -118
- package/dist/holmes/guardrail/shell-lexer.d.ts +69 -0
- package/dist/holmes/guardrail/shell-lexer.js +567 -0
- package/dist/holmes/guardrail/write-target.js +7 -1
- package/dist/holmes/hooks/pre-tool-use.d.ts +60 -0
- package/dist/holmes/hooks/pre-tool-use.js +1423 -10
- package/dist/holmes/hooks/session-start.js +11 -1
- package/dist/holmes/hooks/stop.d.ts +7 -0
- package/dist/holmes/hooks/stop.js +39 -2
- package/dist/holmes/mcp/elicit-approval.d.ts +0 -21
- package/dist/holmes/mcp/elicit-approval.js +5 -2
- package/dist/holmes/mcp/handlers/approval-ask.js +3 -2
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +1 -1
- package/dist/holmes/mcp/handlers/entity-integration.js +9 -6
- package/dist/holmes/mcp/handlers/entity-renumber.js +2 -1
- package/dist/holmes/mcp/handlers/entity-store.js +7 -2
- package/dist/holmes/mcp/handlers/operator-inspection.d.ts +2 -0
- package/dist/holmes/mcp/handlers/operator-inspection.js +25 -4
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +3 -1
- package/dist/holmes/mcp/handlers/spec-approval.js +28 -10
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +10 -7
- package/dist/holmes/mcp/handlers/test-execution.d.ts +6 -0
- package/dist/holmes/mcp/handlers/test-execution.js +37 -9
- package/dist/holmes/mcp/handlers.d.ts +5 -5
- package/dist/holmes/mcp/handlers.js +2 -1
- package/dist/holmes/mcp/tool-schemas.js +4 -4
- package/dist/holmes/project/playbook-reference.d.ts +50 -0
- package/dist/holmes/project/playbook-reference.js +259 -0
- package/dist/holmes/project/playbook-skill-states.d.ts +94 -0
- package/dist/holmes/project/playbook-skill-states.js +396 -0
- package/dist/holmes/project/root.d.ts +9 -1
- package/dist/holmes/project/root.js +23 -2
- package/dist/holmes/project/running-package.d.ts +15 -0
- package/dist/holmes/project/running-package.js +87 -0
- package/dist/holmes/review/head-worktree.js +9 -1
- package/dist/holmes/review/test-runner.d.ts +2 -0
- package/dist/holmes/review/test-runner.js +38 -11
- package/dist/holmes/spec/entity-integration-transaction.d.ts +19 -2
- package/dist/holmes/spec/entity-integration-transaction.js +68 -7
- package/package.json +5 -2
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.isOurs = void 0;
|
|
37
|
+
exports.installedSkillBytes = installedSkillBytes;
|
|
38
|
+
exports.invocableSkillName = invocableSkillName;
|
|
39
|
+
exports.skillPathFor = skillPathFor;
|
|
40
|
+
exports.playbookNames = playbookNames;
|
|
41
|
+
exports.aliasGroupsOf = aliasGroupsOf;
|
|
42
|
+
exports.aliasedNames = aliasedNames;
|
|
43
|
+
exports.skillsRootInside = skillsRootInside;
|
|
44
|
+
exports.playbookSkillStates = playbookSkillStates;
|
|
45
|
+
exports.classifyExtraEntries = classifyExtraEntries;
|
|
46
|
+
// @implements A-SPEC-794.101, A-SPEC-794.106, A-SPEC-794.108, A-SPEC-794.110
|
|
47
|
+
/**
|
|
48
|
+
* The recovery-skill verdict: what an installed skill's bytes should be, where it lives, and whether the copy in a
|
|
49
|
+
* target is still the running build's playbook. Moved below the cli layer (A-SPEC-794.101) so doctor and the
|
|
50
|
+
* product-installed judgement in governance (A-SPEC-794.100) call this one function; `cli/playbook-skills.ts`
|
|
51
|
+
* re-exports it and keeps installing and removing. The code came from that module (A-SPEC-190, A-SPEC-142,
|
|
52
|
+
* A-SPEC-172, A-SPEC-193); its per-block notes keep the spec that shaped them as `(origin: …)`.
|
|
53
|
+
*/
|
|
54
|
+
const fs = __importStar(require("node:fs"));
|
|
55
|
+
const path = __importStar(require("node:path"));
|
|
56
|
+
const installer_markers_1 = require("./installer-markers");
|
|
57
|
+
/**
|
|
58
|
+
* (origin: A-SPEC-190 round 7)
|
|
59
|
+
* The bytes an install writes. The marker used to go FIRST, which put it ahead of the playbook's
|
|
60
|
+
* YAML frontmatter — and frontmatter is only frontmatter when it starts at byte 0. Measured on this
|
|
61
|
+
* repository's own installed skills: the agent's skill list rendered
|
|
62
|
+
* `holmes-adopt: <!-- installed by holmes-kit; edits will be replaced on upgrade -->` for all three,
|
|
63
|
+
* i.e. the `description` that quotes the deny text — the entire reason this layer exists, since a
|
|
64
|
+
* refusal is supposed to summon the playbook by that sentence — was destroyed at install time,
|
|
65
|
+
* while doctor certified the layout as `current`. The marker now follows the frontmatter block.
|
|
66
|
+
*/
|
|
67
|
+
function installedSkillBytes(body) {
|
|
68
|
+
const end = (0, installer_markers_1.frontmatterEnd)(body);
|
|
69
|
+
if (end === null)
|
|
70
|
+
return `${installer_markers_1.PLAYBOOK_SKILL_MARKER}\n${body}`;
|
|
71
|
+
// The offset is computed on normalised text; a body with CRLF or a BOM is rewritten normalised so
|
|
72
|
+
// the marker cannot land inside the frontmatter it must follow.
|
|
73
|
+
const text = body.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
|
|
74
|
+
const head = text.slice(0, end);
|
|
75
|
+
return `${head}${head.endsWith('\n') ? '' : '\n'}${installer_markers_1.PLAYBOOK_SKILL_MARKER}\n${text.slice(end)}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* (origin: A-SPEC-172)
|
|
79
|
+
* What the user types to reach a playbook.
|
|
80
|
+
*
|
|
81
|
+
* The install directory is namespaced (`holmes-adopt`), but the internal playbook name is bare
|
|
82
|
+
* (`adopt`), and every message echoed the bare one. Measured 2026-08-12 on an installed tarball: init
|
|
83
|
+
* printed `Installed 3 recovery skill(s): adopt, author-slice, promote-slice` while nothing by those
|
|
84
|
+
* names existed. Anything shown to a user goes through here.
|
|
85
|
+
*/
|
|
86
|
+
function invocableSkillName(playbookName) {
|
|
87
|
+
return `holmes-${playbookName}`;
|
|
88
|
+
}
|
|
89
|
+
/** `<target>/.claude/skills/holmes-<name>/SKILL.md` */
|
|
90
|
+
function skillPathFor(target, playbookName) {
|
|
91
|
+
return path.join(target, '.claude', 'skills', invocableSkillName(playbookName), 'SKILL.md');
|
|
92
|
+
}
|
|
93
|
+
function playbookNames(packageRoot) {
|
|
94
|
+
const dir = path.join(packageRoot, 'playbooks');
|
|
95
|
+
try {
|
|
96
|
+
return fs.readdirSync(dir)
|
|
97
|
+
// Presence by lstat, not existsSync (round-8): existsSync follows links and needs read
|
|
98
|
+
// permission, so a DANGLING PLAYBOOK.md link or an unreadable playbook directory dropped the
|
|
99
|
+
// name from the shipped list — and a currently-installed skill of that name then read as
|
|
100
|
+
// `orphaned`, i.e. doctor told the operator to DELETE a skill the package still ships.
|
|
101
|
+
// A damaged source is reported as damage (`source-unreadable`), never as an orphan.
|
|
102
|
+
.filter((n) => { try {
|
|
103
|
+
fs.lstatSync(path.join(dir, n, 'PLAYBOOK.md'));
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
} })
|
|
109
|
+
.sort();
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return []; // no playbooks directory: nothing to install, not an error
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const isOurs = (file) => {
|
|
116
|
+
try {
|
|
117
|
+
return (0, installer_markers_1.carriesMarker)(fs.readFileSync(file, 'utf8'));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
exports.isOurs = isOurs;
|
|
124
|
+
/**
|
|
125
|
+
* (origin: A-SPEC-190 round 8)
|
|
126
|
+
* Which shipped names resolve to the SAME file as another (a link between skill directories, at file
|
|
127
|
+
* or directory level). Shared by install and by the state report so both say the same thing.
|
|
128
|
+
*/
|
|
129
|
+
function aliasGroupsOf(packageRoot, target) {
|
|
130
|
+
const names = playbookNames(packageRoot);
|
|
131
|
+
const realOf = (name) => {
|
|
132
|
+
const dest = skillPathFor(target, name);
|
|
133
|
+
try {
|
|
134
|
+
return fs.realpathSync(dest);
|
|
135
|
+
}
|
|
136
|
+
catch { /* not yet materialised */ }
|
|
137
|
+
try {
|
|
138
|
+
return path.join(fs.realpathSync(path.dirname(dest)), path.basename(dest));
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return dest;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// (origin: A-SPEC-190 §10 round 9) — identity is (dev, ino), not a path STRING. On a
|
|
145
|
+
// case-insensitive filesystem (macOS default) `…/holmes-Adopt/SKILL.md` and `…/holmes-adopt/SKILL.md`
|
|
146
|
+
// are one file with two spellings, so the string-keyed grouping saw two destinations and let one
|
|
147
|
+
// playbook's body overwrite the other's — the exact harm the round-8 pre-scan was added to stop.
|
|
148
|
+
const identity = (name) => {
|
|
149
|
+
const real = realOf(name);
|
|
150
|
+
// NTFS file IDs can exceed Number precision; rounded IDs alias unrelated files.
|
|
151
|
+
try {
|
|
152
|
+
const st = fs.statSync(real, { bigint: true });
|
|
153
|
+
return `${st.dev}:${st.ino}`;
|
|
154
|
+
}
|
|
155
|
+
catch { /* not yet there */ }
|
|
156
|
+
try {
|
|
157
|
+
const st = fs.statSync(path.dirname(real), { bigint: true });
|
|
158
|
+
return `${st.dev}:${st.ino}:${path.basename(real).toLowerCase()}`;
|
|
159
|
+
}
|
|
160
|
+
catch { /* dangling */ }
|
|
161
|
+
// round-9: a DANGLING directory link resolves to nothing, so the old fallback compared path
|
|
162
|
+
// STRINGS — two skills whose links point at one missing directory read as two destinations and
|
|
163
|
+
// one playbook's body overwrote the other's, exit 0. Follow the link TEXTUALLY: where it points
|
|
164
|
+
// is identity enough, even when nothing is there yet.
|
|
165
|
+
const dest = skillPathFor(target, name);
|
|
166
|
+
let dir = path.dirname(dest);
|
|
167
|
+
for (let hop = 0; hop < 10; hop++) {
|
|
168
|
+
try {
|
|
169
|
+
if (!fs.lstatSync(dir).isSymbolicLink())
|
|
170
|
+
break;
|
|
171
|
+
dir = path.resolve(path.dirname(dir), fs.readlinkSync(dir));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return path.join(dir, path.basename(dest)).toLowerCase();
|
|
178
|
+
};
|
|
179
|
+
const groups = new Map();
|
|
180
|
+
for (const name of names) {
|
|
181
|
+
const key = identity(name);
|
|
182
|
+
const g = groups.get(key);
|
|
183
|
+
if (g)
|
|
184
|
+
g.push(name);
|
|
185
|
+
else
|
|
186
|
+
groups.set(key, [name]);
|
|
187
|
+
}
|
|
188
|
+
const out = new Map();
|
|
189
|
+
for (const [, group] of groups) {
|
|
190
|
+
if (group.length < 2)
|
|
191
|
+
continue;
|
|
192
|
+
for (const n of group)
|
|
193
|
+
out.set(n, group.filter((o) => o !== n));
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
function aliasedNames(packageRoot, target) {
|
|
198
|
+
return new Set(aliasGroupsOf(packageRoot, target).keys());
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The skills root, but only if it is genuinely INSIDE the target.
|
|
202
|
+
*
|
|
203
|
+
* (origin: A-SPEC-190 §12 round 11) — the link was refused at `.claude/skills` and at each skill
|
|
204
|
+
* directory, and traversed one level ABOVE both: with `<target>/.claude` itself a link to a central
|
|
205
|
+
* store, install wrote five shipped skills into someone else's tree and reported success, and
|
|
206
|
+
* `--remove` then deleted marker-owned files there with `failed` empty. One containment question,
|
|
207
|
+
* asked once, cannot be walked around by moving the link up a level. It also names the component
|
|
208
|
+
* that is actually a link — the old wording blamed `.claude/skills` for `.claude`.
|
|
209
|
+
*/
|
|
210
|
+
function skillsRootInside(target) {
|
|
211
|
+
const dir = path.join(target, '.claude', 'skills');
|
|
212
|
+
let base;
|
|
213
|
+
try {
|
|
214
|
+
base = fs.realpathSync(target);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return { dir };
|
|
218
|
+
} // 타깃이 없으면 상류가 답한다
|
|
219
|
+
// (origin: A-SPEC-193 §7) — 묻는 것은 "링크인가"가 아니라 "**타깃 밖으로 나가는가**"다.
|
|
220
|
+
// 첫 판(§12)은 해소된 경로가 제자리와 다르기만 하면 거부했는데, 그것은 다중 에이전트의 표준
|
|
221
|
+
// 배치를 통째로 막는다: 원본을 `.agents/skills` 에 두고 `.claude/skills` 를 그리로 링크하는
|
|
222
|
+
// SSOT 는 타깃 **안**에 머문다(실측: 그 배치에서 written 0, 전 스킬 unresolvable). §12 가
|
|
223
|
+
// 막으려던 해악은 타깃 밖 중앙 저장소의 파괴였고, 그 해악은 아래 검사로 그대로 막힌다.
|
|
224
|
+
for (const rel of [path.join('.claude'), path.join('.claude', 'skills')]) {
|
|
225
|
+
const at = path.join(target, rel);
|
|
226
|
+
let real;
|
|
227
|
+
try {
|
|
228
|
+
real = fs.realpathSync(at);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
continue;
|
|
232
|
+
} // 아직 없는 것은 여기서 만든다
|
|
233
|
+
if (real !== base && !real.startsWith(base + path.sep)) {
|
|
234
|
+
return { refusal: `${at} 가 타깃(${target}) 밖(${real})을 가리킵니다 — 링크 너머의 파일을 쓰거나 지우지 않았습니다. 링크를 풀거나 그 저장소에서 직접 다루십시오` };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { dir };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* (origin: A-SPEC-190)
|
|
241
|
+
* Per-playbook state of the installed copy, judged against the bytes install would write NOW
|
|
242
|
+
* (`marker + '\n' + shipped body`). An installed skill is a COPY: the kit's conventions move on
|
|
243
|
+
* while the copy stays frozen at install time. Measured 2026-08-15 in this very repository: all
|
|
244
|
+
* three installed skills had drifted (diff 50/38/64 lines) and the author-slice copy still taught
|
|
245
|
+
* the abolished `A-SPEC-125.5 → T-SPEC-1255` id convention — while the count-only doctor check
|
|
246
|
+
* reported "3 of 3 … PASS". Equality with the reconstruction is the single source of truth; a
|
|
247
|
+
* version stamp or hash file would be a second truth that itself goes stale.
|
|
248
|
+
*
|
|
249
|
+
* A shipped body that cannot be read (a race — playbookNames just confirmed it) yields no entry
|
|
250
|
+
* for that name: silence beats a wrong repair hint.
|
|
251
|
+
*/
|
|
252
|
+
function playbookSkillStates(packageRoot, target, source) {
|
|
253
|
+
const out = [];
|
|
254
|
+
// (origin: A-SPEC-190 §20 round 13) — §12's fence went on install and remove, not on the
|
|
255
|
+
// function DOCTOR judges from. So with `<target>/.claude` linked outside the target, doctor read
|
|
256
|
+
// the files beyond the link, declared them drifted/missing, and prescribed `skills refresh` —
|
|
257
|
+
// which §12 refuses every time. A diagnosis whose remedy can never run is worse than no
|
|
258
|
+
// diagnosis: it teaches the operator to ignore the tool. Say the one thing that IS actionable.
|
|
259
|
+
const fenced = skillsRootInside(target);
|
|
260
|
+
const shippedNames = () => (source ? source.names() : playbookNames(packageRoot));
|
|
261
|
+
if ('refusal' in fenced) {
|
|
262
|
+
return shippedNames().map((name) => ({ name, state: 'unresolvable' }));
|
|
263
|
+
}
|
|
264
|
+
const shipped = shippedNames();
|
|
265
|
+
for (const name of shipped) {
|
|
266
|
+
let body;
|
|
267
|
+
// (origin: A-SPEC-190 round 7) — an unreadable SHIPPED playbook used to `continue`, so the
|
|
268
|
+
// name vanished from the report: doctor said PASS (or the nonsense '3 of 0') while the refresh
|
|
269
|
+
// it never advised exited 1 on the same target. The package's own damage gets its own state.
|
|
270
|
+
if (source) {
|
|
271
|
+
const b = source.body(name);
|
|
272
|
+
if (b === null) {
|
|
273
|
+
out.push({ name, state: 'source-unreadable' });
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
body = b;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
try {
|
|
280
|
+
body = fs.readFileSync(path.join(packageRoot, 'playbooks', name, 'PLAYBOOK.md'), 'utf8');
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
out.push({ name, state: 'source-unreadable' });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const dest = skillPathFor(target, name);
|
|
288
|
+
// (origin: A-SPEC-190 round 8) — two skills resolving to ONE file is a state, not just an
|
|
289
|
+
// install-time failure: doctor used to call one of them `drifted` and advise a refresh that
|
|
290
|
+
// could only ever exit 1. The operator has to unlink; say so.
|
|
291
|
+
if (aliasedNames(packageRoot, target).has(name)) {
|
|
292
|
+
out.push({ name, state: 'aliased' });
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
let installed;
|
|
296
|
+
try {
|
|
297
|
+
installed = fs.readFileSync(dest, 'utf8');
|
|
298
|
+
}
|
|
299
|
+
catch (err) {
|
|
300
|
+
// ENOENT alone is absence — but only when nothing occupies the path: readFileSync FOLLOWS
|
|
301
|
+
// symlinks, so a BROKEN link also reads ENOENT while install's lstat sees it present and
|
|
302
|
+
// skips it as foreign (round-3: doctor said 'missing', the advised refresh said 'yours' —
|
|
303
|
+
// an unresolvable loop). Presence is judged the way install judges it: by lstat. Any other
|
|
304
|
+
// read failure (EACCES, EISDIR, ELOOP…) means the marker cannot be read, and ownership is
|
|
305
|
+
// decided by the marker — a file we cannot prove ours is not ours to repair.
|
|
306
|
+
const lstatPresent = (() => {
|
|
307
|
+
try {
|
|
308
|
+
fs.lstatSync(dest);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
catch { /* fall through */ }
|
|
312
|
+
// round-8: the SKILLS directory itself may be a dangling link. Reading through it is ENOENT
|
|
313
|
+
// while install's mkdir/write is ENOENT too — the old 'missing' verdict advised a refresh
|
|
314
|
+
// that could only ever fail, the exact non-convergent loop rounds 3 and 5 closed one level
|
|
315
|
+
// deeper. Something occupies the path; it is not ours to repair.
|
|
316
|
+
try {
|
|
317
|
+
const skillsRoot = path.dirname(path.dirname(dest));
|
|
318
|
+
if (fs.lstatSync(skillsRoot).isSymbolicLink() && !fs.existsSync(skillsRoot))
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
catch { /* fall through */ }
|
|
322
|
+
// The skill DIRECTORY itself may be a (possibly dangling) symlink the user manages —
|
|
323
|
+
// read fails ENOENT through it while something clearly occupies the path (round-5:
|
|
324
|
+
// 'missing' here + install's skip = another unresolvable remedy loop).
|
|
325
|
+
try {
|
|
326
|
+
return fs.lstatSync(path.dirname(dest)).isSymbolicLink();
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
})();
|
|
332
|
+
out.push({ name, state: err.code === 'ENOENT' && !lstatPresent ? 'missing' : 'foreign' });
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const state = !(0, installer_markers_1.carriesMarker)(installed) ? 'foreign'
|
|
336
|
+
: installed === installedSkillBytes(body) ? 'current' : 'drifted';
|
|
337
|
+
out.push({ name, state });
|
|
338
|
+
}
|
|
339
|
+
// Marker-owned installs of names we no longer ship are STALE GUIDANCE — exactly REQ-190's problem
|
|
340
|
+
// class — yet the shipped loop above cannot see them. Markerless non-shipped entries are the
|
|
341
|
+
// user's own skills and stay off our list entirely.
|
|
342
|
+
const skillsDir = path.join(target, '.claude', 'skills');
|
|
343
|
+
let entries;
|
|
344
|
+
try {
|
|
345
|
+
entries = fs.readdirSync(skillsDir);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
entries = [];
|
|
349
|
+
}
|
|
350
|
+
for (const entry of classifyExtraEntries(entries, shipped, (entry2, canonical) => {
|
|
351
|
+
try {
|
|
352
|
+
const a = fs.statSync(path.join(skillsDir, entry2), { bigint: true });
|
|
353
|
+
const b = fs.statSync(path.join(skillsDir, canonical), { bigint: true });
|
|
354
|
+
return a.ino === b.ino && a.dev === b.dev;
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
}, (entry2) => (0, exports.isOurs)(path.join(skillsDir, entry2, 'SKILL.md')))) {
|
|
360
|
+
// The RAW directory name, case intact (round-6 HIGH): slicing the prefix folded
|
|
361
|
+
// `Holmes-adopt` to `adopt`, doctor re-prefixed it to `holmes-adopt`, and the orphan remedy
|
|
362
|
+
// told the operator to DELETE THE CURRENT SKILL on a case-sensitive FS.
|
|
363
|
+
out.push({ name: entry, state: 'orphaned' });
|
|
364
|
+
}
|
|
365
|
+
return out;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* (origin: A-SPEC-190 §6)
|
|
369
|
+
* Which extra `.claude/skills` entries are ORPHANED marker-owned installs? Pure — the fs facts
|
|
370
|
+
* (inode identity, marker ownership) come in as functions, so the case-SENSITIVE world is testable
|
|
371
|
+
* on any machine (round-5 HIGH lived exactly in the branch this box's case-folding FS cannot
|
|
372
|
+
* exercise: `Holmes-adopt` sliced to `adopt`, matched shipped, and was swallowed BEFORE the
|
|
373
|
+
* variant/inode logic — doctor printed PASS over stale marker-owned guidance).
|
|
374
|
+
*
|
|
375
|
+
* - exact canonical entries are the shipped loop's business (skip);
|
|
376
|
+
* - a case-variant with the SAME inode is the same physical dir (case-insensitive FS — skip;
|
|
377
|
+
* round-2: double-counting made the orphan remedy delete the current skill);
|
|
378
|
+
* - everything else marker-owned is orphaned; unreadable/markerless stays silent (ownership is
|
|
379
|
+
* the marker's job — user territory).
|
|
380
|
+
*/
|
|
381
|
+
function classifyExtraEntries(entries, shipped, sameInode, owned) {
|
|
382
|
+
const orphans = [];
|
|
383
|
+
for (const entry of [...entries].sort()) {
|
|
384
|
+
if (!entry.toLowerCase().startsWith('holmes-'))
|
|
385
|
+
continue; // 'Holmes-adopt' is still ours to judge
|
|
386
|
+
const name = entry.slice('holmes-'.length);
|
|
387
|
+
if (entry.startsWith('holmes-') && shipped.includes(name))
|
|
388
|
+
continue; // exact canonical only
|
|
389
|
+
const variantOf = shipped.find((s) => `holmes-${s}`.toLowerCase() === entry.toLowerCase());
|
|
390
|
+
if (variantOf && sameInode(entry, invocableSkillName(variantOf)) === true)
|
|
391
|
+
continue;
|
|
392
|
+
if (owned(entry))
|
|
393
|
+
orphans.push(entry); // RAW entry — the name the operator must act on
|
|
394
|
+
}
|
|
395
|
+
return orphans;
|
|
396
|
+
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare function cleanSubprocessEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @implements A-SPEC-794.119 — `opts.projectDir` is the tree the run executes in. Where `env` carries CLAUDE_PROJECT_DIR (the
|
|
4
|
+
* MCP server's names the live checkout), the child gets that tree's real path in its place — replaced, never added and
|
|
5
|
+
* never removed. Measured 2026-11-12/13: a full test_run in a HEAD worktree handed its children the checkout's path, and a
|
|
6
|
+
* test that started a stdio server judged the live work tree's specs, not the snapshot the evidence names.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cleanTestEnv(env?: NodeJS.ProcessEnv, opts?: {
|
|
9
|
+
projectDir?: string;
|
|
10
|
+
}): NodeJS.ProcessEnv;
|
|
3
11
|
/**
|
|
4
12
|
* Where a project begins, for a harness that must not require version control.
|
|
5
13
|
*
|
|
@@ -39,7 +39,7 @@ exports.cleanTestEnv = cleanTestEnv;
|
|
|
39
39
|
exports.isProjectDir = isProjectDir;
|
|
40
40
|
exports.sameCanonicalDirectory = sameCanonicalDirectory;
|
|
41
41
|
exports.resolveProjectRoot = resolveProjectRoot;
|
|
42
|
-
// @implements A-SPEC-205, A-SPEC-627, A-SPEC-734, A-SPEC-102.31, A-SPEC-102.32, A-SPEC-794.47, A-SPEC-794.57, A-SPEC-794.58
|
|
42
|
+
// @implements A-SPEC-205, A-SPEC-627, A-SPEC-734, A-SPEC-102.31, A-SPEC-102.32, A-SPEC-794.47, A-SPEC-794.57, A-SPEC-794.58, A-SPEC-794.119
|
|
43
43
|
// @implements A-SPEC-128
|
|
44
44
|
const fs = __importStar(require("node:fs"));
|
|
45
45
|
const path = __importStar(require("node:path"));
|
|
@@ -109,12 +109,33 @@ function cleanSubprocessEnv(env = process.env) {
|
|
|
109
109
|
// @implements A-SPEC-128.14 — V1: `PYTEST_ADDOPTS` narrowed a full run (`-k`, reviewer B M1); a test runner never takes it.
|
|
110
110
|
// @implements A-SPEC-128.15 — P3: nor `PYTEST_PLUGINS`, which loads a plugin the project did not declare.
|
|
111
111
|
const TEST_SCRUB_KEYS = new Set(['HOLMES_SPECS', 'HOLMES_GATE_BYPASS', 'HOLMES_MCP_AUTORELOAD', 'HOLMES_MCP_PROFILE', 'HOLMES_AUTONOMOUS_APPROVAL', 'NPM_CONFIG_DRY_RUN', 'PYTEST_ADDOPTS', 'PYTEST_PLUGINS']);
|
|
112
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @implements A-SPEC-794.119 — `opts.projectDir` is the tree the run executes in. Where `env` carries CLAUDE_PROJECT_DIR (the
|
|
114
|
+
* MCP server's names the live checkout), the child gets that tree's real path in its place — replaced, never added and
|
|
115
|
+
* never removed. Measured 2026-11-12/13: a full test_run in a HEAD worktree handed its children the checkout's path, and a
|
|
116
|
+
* test that started a stdio server judged the live work tree's specs, not the snapshot the evidence names.
|
|
117
|
+
*/
|
|
118
|
+
function cleanTestEnv(env = process.env, opts = {}) {
|
|
113
119
|
const cleaned = cleanSubprocessEnv(env);
|
|
114
120
|
for (const k of Object.keys(cleaned)) {
|
|
115
121
|
if (TEST_SCRUB_KEYS.has(k.toUpperCase()))
|
|
116
122
|
delete cleaned[k];
|
|
117
123
|
}
|
|
124
|
+
if (opts.projectDir !== undefined) {
|
|
125
|
+
// the names as the environment spells them (Windows keys are case-insensitive)
|
|
126
|
+
const carried = Object.keys(cleaned).filter((k) => k.toUpperCase() === 'CLAUDE_PROJECT_DIR');
|
|
127
|
+
if (carried.length > 0) {
|
|
128
|
+
for (const k of carried)
|
|
129
|
+
delete cleaned[k];
|
|
130
|
+
// a directory that cannot be resolved keeps its absolute spelling — still the run's tree, never the server's
|
|
131
|
+
let dir = path.resolve(opts.projectDir);
|
|
132
|
+
try {
|
|
133
|
+
dir = fs.realpathSync.native(dir);
|
|
134
|
+
}
|
|
135
|
+
catch { /* the absolute spelling above */ }
|
|
136
|
+
cleaned.CLAUDE_PROJECT_DIR = dir;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
118
139
|
return cleaned;
|
|
119
140
|
}
|
|
120
141
|
/** The marker directory that makes a directory a Holmes-Kit project. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The real path with the on-disk case, or the resolved path when it cannot be resolved (nothing exists there). */
|
|
2
|
+
export declare function realPathOf(p: string): string;
|
|
3
|
+
/** The package this module was loaded from: `<package>/dist/holmes/project` when built, `<package>/src/holmes/project` in source. */
|
|
4
|
+
export declare const RUNNING_PACKAGE_ROOT: string;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a package was installed by a package manager: its real path has a segment `node_modules`. A link named
|
|
7
|
+
* `node_modules/x` that points at a checkout is not deployed — the real path decides. Such a package's files are what
|
|
8
|
+
* the product is; any other package is a checkout (or was unpacked by hand), whose files the workspace may be editing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isDeployedPackage(packageRoot: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether `root` is the checkout the running gate is built from: the package is not deployed, and the real path of
|
|
13
|
+
* `root` is the package's root or lies inside it. No git command and no file of `root` is read.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ownRepoOf(root: string, packageRoot: string): boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RUNNING_PACKAGE_ROOT = void 0;
|
|
37
|
+
exports.realPathOf = realPathOf;
|
|
38
|
+
exports.isDeployedPackage = isDeployedPackage;
|
|
39
|
+
exports.ownRepoOf = ownRepoOf;
|
|
40
|
+
// @implements A-SPEC-794.111, A-SPEC-794.112
|
|
41
|
+
/**
|
|
42
|
+
* The one fact principle 7's root predicate and the recovery skills' binding read: the real path of the package the
|
|
43
|
+
* running module belongs to. It is fixed by this module's own location — not an argument of the gate, not an environment
|
|
44
|
+
* variable, not the working directory — so the workspace a gate judges cannot change it.
|
|
45
|
+
*
|
|
46
|
+
* Why not "a directory src/holmes exists under the root" (the earlier predicate): measured 2026-11-12 with the live
|
|
47
|
+
* hook, `mv src/holmes src/h2`, `git mv` and replacing the directory by a link are allowed, and one of them turned the
|
|
48
|
+
* write judgement, the commit judgement and Stop off. Enumerating the ways a directory can be renamed has no end.
|
|
49
|
+
*
|
|
50
|
+
* There is no setter and no switch here (A-SPEC-794.112): what ships cannot be told to answer differently. The suites
|
|
51
|
+
* whose fixtures are temporary directories replace this module in jest's module registry only
|
|
52
|
+
* (src/holmes/test-support, named by package.json's jest configuration).
|
|
53
|
+
*/
|
|
54
|
+
const fs = __importStar(require("node:fs"));
|
|
55
|
+
const path = __importStar(require("node:path"));
|
|
56
|
+
/** The real path with the on-disk case, or the resolved path when it cannot be resolved (nothing exists there). */
|
|
57
|
+
function realPathOf(p) {
|
|
58
|
+
// [no-substitution: nothing exists at the path → its spelling; the running package's own path always resolves (this
|
|
59
|
+
// module was loaded from it), and a root that does not exist holds nothing to judge]
|
|
60
|
+
try {
|
|
61
|
+
return fs.realpathSync.native(p);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return path.resolve(p);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** The package this module was loaded from: `<package>/dist/holmes/project` when built, `<package>/src/holmes/project` in source. */
|
|
68
|
+
exports.RUNNING_PACKAGE_ROOT = realPathOf(path.resolve(__dirname, '..', '..', '..'));
|
|
69
|
+
/**
|
|
70
|
+
* Whether a package was installed by a package manager: its real path has a segment `node_modules`. A link named
|
|
71
|
+
* `node_modules/x` that points at a checkout is not deployed — the real path decides. Such a package's files are what
|
|
72
|
+
* the product is; any other package is a checkout (or was unpacked by hand), whose files the workspace may be editing.
|
|
73
|
+
*/
|
|
74
|
+
function isDeployedPackage(packageRoot) {
|
|
75
|
+
return realPathOf(packageRoot).split(path.sep).includes('node_modules');
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether `root` is the checkout the running gate is built from: the package is not deployed, and the real path of
|
|
79
|
+
* `root` is the package's root or lies inside it. No git command and no file of `root` is read.
|
|
80
|
+
*/
|
|
81
|
+
function ownRepoOf(root, packageRoot) {
|
|
82
|
+
if (isDeployedPackage(packageRoot))
|
|
83
|
+
return false;
|
|
84
|
+
const pkg = realPathOf(packageRoot);
|
|
85
|
+
const r = realPathOf(root);
|
|
86
|
+
return r === pkg || r.startsWith(pkg.endsWith(path.sep) ? pkg : pkg + path.sep);
|
|
87
|
+
}
|
|
@@ -310,7 +310,15 @@ function openHeadWorktree(root, head, opts) {
|
|
|
310
310
|
return { ok: false, reason: linked };
|
|
311
311
|
}
|
|
312
312
|
const t1 = Date.now();
|
|
313
|
-
|
|
313
|
+
// @implements A-SPEC-794.123 — a config the caller could not read is the run's environment, as a failed prepare is
|
|
314
|
+
let prepare;
|
|
315
|
+
try {
|
|
316
|
+
prepare = opts.prepareOf(dir);
|
|
317
|
+
}
|
|
318
|
+
catch (e) {
|
|
319
|
+
close();
|
|
320
|
+
return { ok: false, reason: `testRun.prepare could not be read: ${firstLine(e instanceof Error ? e.message : String(e))}` };
|
|
321
|
+
}
|
|
314
322
|
if (prepare && prepare.length > 0) {
|
|
315
323
|
if (installPrepare(prepare)) {
|
|
316
324
|
close();
|
|
@@ -134,6 +134,8 @@ export interface TestRunOptions {
|
|
|
134
134
|
isIgnored?: (relPath: string) => boolean;
|
|
135
135
|
/** @implements A-SPEC-128.13 — the work tree a HEAD worktree run came from: pytest's interpreter (a .venv) is found there. */
|
|
136
136
|
sourceRoot?: string;
|
|
137
|
+
/** @implements A-SPEC-794.119 — the tree the run executes in; the test children's CLAUDE_PROJECT_DIR names it. */
|
|
138
|
+
projectRoot?: string;
|
|
137
139
|
}
|
|
138
140
|
/** @implements A-SPEC-128.9 — one unit's outcome in a full run. */
|
|
139
141
|
export interface UnitResult {
|