@vaubaan/harness 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -83
- package/dist/cli/index.js +4165 -843
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/harn-canvas.cmd.md +23 -0
- package/dist/commands/{decision.cmd.md → harn-decision.cmd.md} +6 -6
- package/dist/commands/{doc-audit.cmd.md → harn-doc-audit.cmd.md} +7 -7
- package/dist/commands/{drift.cmd.md → harn-drift.cmd.md} +6 -6
- package/dist/commands/{handbook.cmd.md → harn-handbook.cmd.md} +6 -6
- package/dist/commands/harn-improve.cmd.md +20 -0
- package/dist/commands/{intent.cmd.md → harn-intent.cmd.md} +9 -9
- package/dist/commands/{readme.cmd.md → harn-readme.cmd.md} +6 -6
- package/dist/commands/{spec.cmd.md → harn-spec.cmd.md} +6 -6
- package/dist/commands/{test-plan.cmd.md → harn-test-plan.cmd.md} +6 -6
- package/dist/commands/harn-upgrade.cmd.md +22 -0
- package/dist/commands/{workflow.cmd.md → harn-workflow.cmd.md} +6 -6
- package/dist/index.d.ts +32 -3
- package/dist/index.js +533 -96
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js +468 -93
- package/dist/init.js.map +1 -1
- package/dist/linters/index.d.ts +3 -34
- package/dist/linters/index.js +996 -554
- package/dist/linters/index.js.map +1 -1
- package/dist/parser/index.d.ts +96 -6
- package/dist/parser/index.js +220 -10
- package/dist/parser/index.js.map +1 -1
- package/dist/render-BhUar2gf.d.ts +81 -0
- package/dist/render.d.ts +1 -1
- package/dist/render.js +233 -22
- package/dist/render.js.map +1 -1
- package/dist/skills/harn-canvas-review.skill.md +87 -0
- package/dist/skills/{decision-record-writer.skill.md → harn-decision-record-writer.skill.md} +2 -1
- package/dist/skills/{doc-audit.skill.md → harn-doc-audit.skill.md} +75 -26
- package/dist/skills/{drift-detector.skill.md → harn-drift-detector.skill.md} +15 -14
- package/dist/skills/harn-guide.skill.md +137 -0
- package/dist/skills/{handbook-writer.skill.md → harn-handbook-writer.skill.md} +2 -1
- package/dist/skills/{intent-writer.skill.md → harn-intent-writer.skill.md} +83 -16
- package/dist/skills/{readme-writer.skill.md → harn-readme-writer.skill.md} +4 -4
- package/dist/skills/harn-self-improve.skill.md +84 -0
- package/dist/skills/{spec-writer.skill.md → harn-spec-writer.skill.md} +8 -8
- package/dist/skills/{test-plan-writer.skill.md → harn-test-plan-writer.skill.md} +6 -5
- package/dist/skills/harn-upgrade.skill.md +171 -0
- package/dist/skills/{workflow-writer.skill.md → harn-workflow-writer.skill.md} +6 -5
- package/dist/templates/decisions-index.md.tmpl +11 -0
- package/dist/templates/handbook-index.md.tmpl +8 -0
- package/dist/templates/profile.md.tmpl +30 -0
- package/dist/types-CfUByAIr.d.ts +35 -0
- package/dist/view/index.d.ts +117 -0
- package/dist/view/index.js +3987 -0
- package/dist/view/index.js.map +1 -0
- package/package.json +6 -2
- package/dist/render-CTx7VNOK.d.ts +0 -45
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "
|
|
2
|
+
var VERSION = "3.0.0";
|
|
3
3
|
|
|
4
4
|
// src/cli/init.ts
|
|
5
|
-
import { existsSync as
|
|
6
|
-
import { dirname as dirname6, join as
|
|
5
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync2, rmSync, writeFileSync as writeFileSync3 } from "fs";
|
|
6
|
+
import { dirname as dirname6, join as join13, resolve as resolve6 } from "path";
|
|
7
7
|
|
|
8
8
|
// src/cli/managed-paths.ts
|
|
9
9
|
import { lstatSync, realpathSync, statSync } from "fs";
|
|
@@ -12,11 +12,37 @@ var MANAGED_FILES = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"AGENTS.md",
|
|
13
13
|
"CLAUDE.md",
|
|
14
14
|
".harness-manifest.json",
|
|
15
|
-
//
|
|
15
|
+
// Indexes of the intents and profiles pillars, rendered while the pillar is active.
|
|
16
16
|
"docs/intents/README.md",
|
|
17
|
+
"docs/profiles/README.md",
|
|
17
18
|
// Its 2.2 location, kept managed so `update` can remove it (see MOVED_PATHS).
|
|
18
19
|
"docs/journeys/README.md"
|
|
19
20
|
]);
|
|
21
|
+
var RENAMED_IDS = /* @__PURE__ */ new Map([
|
|
22
|
+
["canvas-review", "harn-canvas-review"],
|
|
23
|
+
["decision-record-writer", "harn-decision-record-writer"],
|
|
24
|
+
["doc-audit", "harn-doc-audit"],
|
|
25
|
+
["drift-detector", "harn-drift-detector"],
|
|
26
|
+
["handbook-writer", "harn-handbook-writer"],
|
|
27
|
+
["harness-guide", "harn-guide"],
|
|
28
|
+
["harness-upgrade", "harn-upgrade"],
|
|
29
|
+
["intent-writer", "harn-intent-writer"],
|
|
30
|
+
["lesson-miner", "harn-self-improve"],
|
|
31
|
+
["readme-writer", "harn-readme-writer"],
|
|
32
|
+
["spec-writer", "harn-spec-writer"],
|
|
33
|
+
["test-plan-writer", "harn-test-plan-writer"],
|
|
34
|
+
["workflow-writer", "harn-workflow-writer"],
|
|
35
|
+
["canvas", "harn-canvas"],
|
|
36
|
+
["decision", "harn-decision"],
|
|
37
|
+
["drift", "harn-drift"],
|
|
38
|
+
["handbook", "harn-handbook"],
|
|
39
|
+
["intent", "harn-intent"],
|
|
40
|
+
["lessons", "harn-improve"],
|
|
41
|
+
["readme", "harn-readme"],
|
|
42
|
+
["spec", "harn-spec"],
|
|
43
|
+
["test-plan", "harn-test-plan"],
|
|
44
|
+
["workflow", "harn-workflow"]
|
|
45
|
+
]);
|
|
20
46
|
var MOVED_PATHS = /* @__PURE__ */ new Map([
|
|
21
47
|
// 2.3: the journeys pillar became the intents pillar.
|
|
22
48
|
["docs/journeys/README.md", "docs/intents/README.md"]
|
|
@@ -118,13 +144,13 @@ function readManifest(targetDir) {
|
|
|
118
144
|
}
|
|
119
145
|
|
|
120
146
|
// src/cli/plan-render.ts
|
|
121
|
-
import { existsSync as
|
|
122
|
-
import { dirname as dirname2, join as
|
|
147
|
+
import { existsSync as existsSync7 } from "fs";
|
|
148
|
+
import { dirname as dirname2, join as join8, resolve as resolve2 } from "path";
|
|
123
149
|
import { fileURLToPath } from "url";
|
|
124
150
|
|
|
125
151
|
// src/loader.ts
|
|
126
|
-
import { existsSync as
|
|
127
|
-
import { join as
|
|
152
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
153
|
+
import { join as join4 } from "path";
|
|
128
154
|
import fg from "fast-glob";
|
|
129
155
|
import { z as z3 } from "zod";
|
|
130
156
|
|
|
@@ -135,6 +161,101 @@ import matter from "gray-matter";
|
|
|
135
161
|
// src/parser/schemas.ts
|
|
136
162
|
import { z as z2 } from "zod";
|
|
137
163
|
|
|
164
|
+
// src/pillars.ts
|
|
165
|
+
import { existsSync as existsSync2, readdirSync, statSync as statSync2 } from "fs";
|
|
166
|
+
import { join as join3 } from "path";
|
|
167
|
+
var PILLAR_IDS = [
|
|
168
|
+
"readme",
|
|
169
|
+
"spec",
|
|
170
|
+
"decisions",
|
|
171
|
+
"handbook",
|
|
172
|
+
"tests",
|
|
173
|
+
"workflow",
|
|
174
|
+
"quality",
|
|
175
|
+
"skills",
|
|
176
|
+
"intents",
|
|
177
|
+
"profiles"
|
|
178
|
+
];
|
|
179
|
+
var PILLARS = [
|
|
180
|
+
{ id: "readme", core: true },
|
|
181
|
+
{ id: "spec", dir: "docs/spec", core: true },
|
|
182
|
+
{
|
|
183
|
+
id: "decisions",
|
|
184
|
+
dir: "docs/decisions",
|
|
185
|
+
core: false,
|
|
186
|
+
starters: [{ template: "decisions-index.md.tmpl", path: "docs/decisions/README.md" }],
|
|
187
|
+
next: "write the first decision with the `harn-decision-record-writer` skill (`/harn-decision`)"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: "handbook",
|
|
191
|
+
dir: "docs/handbook",
|
|
192
|
+
core: false,
|
|
193
|
+
starters: [{ template: "handbook-index.md.tmpl", path: "docs/handbook/README.md" }],
|
|
194
|
+
next: "write the first handbook with the `harn-handbook-writer` skill (`/harn-handbook`)"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: "tests",
|
|
198
|
+
dir: "docs/tests",
|
|
199
|
+
core: false,
|
|
200
|
+
starters: [
|
|
201
|
+
{ template: "integration-tests.md.tmpl", path: "docs/tests/integration-tests.md" },
|
|
202
|
+
{ template: "e2e-tests.md.tmpl", path: "docs/tests/e2e-tests.md" }
|
|
203
|
+
],
|
|
204
|
+
next: "fill both test plans with the `harn-test-plan-writer` skill (`/harn-test-plan`); the lint fails on their placeholders until then"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "workflow",
|
|
208
|
+
dir: "docs/workflow",
|
|
209
|
+
core: false,
|
|
210
|
+
starters: [{ template: "coding-workflow.md.tmpl", path: "docs/workflow/coding-workflow.md" }],
|
|
211
|
+
next: "fill the workflow with the `harn-workflow-writer` skill (`/harn-workflow`); the lint fails on its placeholders until then"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "quality",
|
|
215
|
+
dir: "docs/quality",
|
|
216
|
+
core: false,
|
|
217
|
+
starters: [{ template: "code-quality.md.tmpl", path: "docs/quality/code-quality.md" }],
|
|
218
|
+
next: "fill docs/quality/code-quality.md by hand: the tools, the project's rules, the accepted deviations"
|
|
219
|
+
},
|
|
220
|
+
// Active as soon as it holds a `*.skill.md`: nothing to add.
|
|
221
|
+
{ id: "skills", dir: "docs/skills", core: false },
|
|
222
|
+
{
|
|
223
|
+
id: "intents",
|
|
224
|
+
dir: "docs/intents",
|
|
225
|
+
core: false,
|
|
226
|
+
starters: [],
|
|
227
|
+
next: "write the first intent with the `harn-intent-writer` skill (`/harn-intent <verb + object>`)"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: "profiles",
|
|
231
|
+
dir: "docs/profiles",
|
|
232
|
+
core: false,
|
|
233
|
+
starters: [],
|
|
234
|
+
next: "describe the first profile with the `harn-intent-writer` skill, from the research you point it to"
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
var ADDABLE_PILLARS = PILLARS.filter(
|
|
238
|
+
(pillar) => pillar.starters !== void 0
|
|
239
|
+
);
|
|
240
|
+
function getPillar(id) {
|
|
241
|
+
return PILLARS.find((pillar) => pillar.id === id);
|
|
242
|
+
}
|
|
243
|
+
function isDirectory(path) {
|
|
244
|
+
return existsSync2(path) && statSync2(path).isDirectory();
|
|
245
|
+
}
|
|
246
|
+
function isPillarActive(repoRoot, id) {
|
|
247
|
+
const pillar = getPillar(id);
|
|
248
|
+
if (!pillar) return false;
|
|
249
|
+
if (pillar.core) return true;
|
|
250
|
+
return pillar.dir !== void 0 && isDirectory(join3(repoRoot, pillar.dir));
|
|
251
|
+
}
|
|
252
|
+
function activePillars(repoRoot) {
|
|
253
|
+
return new Set(PILLARS.filter((p) => isPillarActive(repoRoot, p.id)).map((p) => p.id));
|
|
254
|
+
}
|
|
255
|
+
function allPillars() {
|
|
256
|
+
return new Set(PILLAR_IDS);
|
|
257
|
+
}
|
|
258
|
+
|
|
138
259
|
// src/types.ts
|
|
139
260
|
var ENGINES = ["claude-code", "codex-cli", "opencode"];
|
|
140
261
|
var CAPABILITIES = ["multi-step", "slash-command", "inline-exec"];
|
|
@@ -154,6 +275,8 @@ var SkillFrontmatterSchema = z2.object({
|
|
|
154
275
|
description: z2.string().min(1),
|
|
155
276
|
engines: z2.array(z2.enum(ENGINES)).min(1).optional(),
|
|
156
277
|
requires: z2.array(z2.enum(CAPABILITIES)).optional(),
|
|
278
|
+
/** Rendered while one of these pillars is active; omitted = always. */
|
|
279
|
+
pillars: z2.array(z2.enum(PILLAR_IDS)).min(1).optional(),
|
|
157
280
|
tags: z2.array(z2.string()).optional()
|
|
158
281
|
}).strict();
|
|
159
282
|
var CmdArgEnumSchema = z2.object({
|
|
@@ -187,10 +310,18 @@ var IntentFrontmatterSchema = z2.object({
|
|
|
187
310
|
spec: z2.union([z2.string().min(1), z2.array(z2.string().min(1)).min(1)]),
|
|
188
311
|
last_reviewed: z2.union([z2.date(), z2.string().min(1)])
|
|
189
312
|
}).strict();
|
|
313
|
+
var PROFILE_STATUSES = ["hypothesis", "validated"];
|
|
314
|
+
var ProfileFrontmatterSchema = z2.object({
|
|
315
|
+
title: z2.string().min(1),
|
|
316
|
+
status: z2.enum(PROFILE_STATUSES),
|
|
317
|
+
evidence: z2.union([z2.string().min(1), z2.array(z2.string().min(1)).min(1)]).optional(),
|
|
318
|
+
last_reviewed: z2.union([z2.date(), z2.string().min(1)])
|
|
319
|
+
}).strict();
|
|
190
320
|
var Schemas = {
|
|
191
321
|
Skill: SkillFrontmatterSchema,
|
|
192
322
|
Cmd: CmdFrontmatterSchema,
|
|
193
|
-
Intent: IntentFrontmatterSchema
|
|
323
|
+
Intent: IntentFrontmatterSchema,
|
|
324
|
+
Profile: ProfileFrontmatterSchema
|
|
194
325
|
};
|
|
195
326
|
var ParseError = class extends Error {
|
|
196
327
|
constructor(file, issues) {
|
|
@@ -238,8 +369,8 @@ function parseYAML(source) {
|
|
|
238
369
|
// src/loader.ts
|
|
239
370
|
var DisableYamlSchema = z3.object({ disable: z3.array(z3.string()).optional() }).passthrough();
|
|
240
371
|
function loadHarness(packageDir, opts = {}) {
|
|
241
|
-
const skillsDir = opts.skillsDir ??
|
|
242
|
-
const commandsDir = opts.commandsDir ??
|
|
372
|
+
const skillsDir = opts.skillsDir ?? join4(packageDir, "skills");
|
|
373
|
+
const commandsDir = opts.commandsDir ?? join4(packageDir, "commands");
|
|
243
374
|
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
244
375
|
const cmdFiles = fg.sync("*.cmd.md", { cwd: commandsDir, absolute: true });
|
|
245
376
|
return {
|
|
@@ -248,21 +379,21 @@ function loadHarness(packageDir, opts = {}) {
|
|
|
248
379
|
};
|
|
249
380
|
}
|
|
250
381
|
function loadProjectSkills(targetDir) {
|
|
251
|
-
const skillsDir =
|
|
252
|
-
if (!
|
|
382
|
+
const skillsDir = join4(targetDir, "docs", "skills");
|
|
383
|
+
if (!existsSync3(skillsDir)) return [];
|
|
253
384
|
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
254
385
|
return skillFiles.map((f) => parseSkill(f, readFileSync3(f, "utf8")));
|
|
255
386
|
}
|
|
256
387
|
function loadOverrides(worktreeDir) {
|
|
257
|
-
const overridesDir =
|
|
258
|
-
if (!
|
|
388
|
+
const overridesDir = join4(worktreeDir, ".harness-overrides");
|
|
389
|
+
if (!existsSync3(overridesDir)) return void 0;
|
|
259
390
|
const added = loadHarness(overridesDir, {
|
|
260
|
-
skillsDir:
|
|
261
|
-
commandsDir:
|
|
391
|
+
skillsDir: join4(overridesDir, "skills"),
|
|
392
|
+
commandsDir: join4(overridesDir, "commands")
|
|
262
393
|
});
|
|
263
|
-
const disablePath =
|
|
394
|
+
const disablePath = join4(overridesDir, "disable.yaml");
|
|
264
395
|
let disable = [];
|
|
265
|
-
if (
|
|
396
|
+
if (existsSync3(disablePath)) {
|
|
266
397
|
try {
|
|
267
398
|
const parsed = DisableYamlSchema.safeParse(parseYAML(readFileSync3(disablePath, "utf8")));
|
|
268
399
|
if (parsed.success && parsed.data.disable) {
|
|
@@ -275,8 +406,8 @@ function loadOverrides(worktreeDir) {
|
|
|
275
406
|
}
|
|
276
407
|
|
|
277
408
|
// src/parser/intent.ts
|
|
278
|
-
import { existsSync as
|
|
279
|
-
import { basename as basename2, join as
|
|
409
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
|
|
410
|
+
import { basename as basename2, join as join5 } from "path";
|
|
280
411
|
import matter2 from "gray-matter";
|
|
281
412
|
var INTENTS_DIR = "docs/intents";
|
|
282
413
|
var INTENTS_INDEX_PATH = `${INTENTS_DIR}/README.md`;
|
|
@@ -286,7 +417,9 @@ var NODE_FIELDS = [
|
|
|
286
417
|
"anchors",
|
|
287
418
|
"acceptance",
|
|
288
419
|
"requires",
|
|
289
|
-
"creates"
|
|
420
|
+
"creates",
|
|
421
|
+
"relieves",
|
|
422
|
+
"delivers"
|
|
290
423
|
];
|
|
291
424
|
var MASKED_LINE = "\0";
|
|
292
425
|
var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
@@ -352,6 +485,8 @@ function newNode(title, level, line) {
|
|
|
352
485
|
acceptance: [],
|
|
353
486
|
requires: [],
|
|
354
487
|
creates: [],
|
|
488
|
+
relieves: [],
|
|
489
|
+
delivers: [],
|
|
355
490
|
unknownFields: []
|
|
356
491
|
};
|
|
357
492
|
}
|
|
@@ -451,14 +586,14 @@ function parseIntentFile(relPath, text) {
|
|
|
451
586
|
return { ...meta ? { meta } : {}, title, ...statement ? { statement } : {}, nodes, errors };
|
|
452
587
|
}
|
|
453
588
|
function listIntentFiles(targetDir) {
|
|
454
|
-
const dir =
|
|
455
|
-
if (!
|
|
456
|
-
return
|
|
589
|
+
const dir = join5(targetDir, INTENTS_DIR);
|
|
590
|
+
if (!existsSync4(dir) || !statSync3(dir).isDirectory()) return [];
|
|
591
|
+
return readdirSync2(dir).filter((f) => f.endsWith(".md") && f !== "README.md").filter((f) => statSync3(join5(dir, f)).isFile()).sort();
|
|
457
592
|
}
|
|
458
593
|
function readIntentFiles(targetDir) {
|
|
459
594
|
return listIntentFiles(targetDir).map((file) => {
|
|
460
595
|
const path = `${INTENTS_DIR}/${file}`;
|
|
461
|
-
const text = readFileSync4(
|
|
596
|
+
const text = readFileSync4(join5(targetDir, path), "utf8");
|
|
462
597
|
return { path, file, ...parseIntentFile(path, text) };
|
|
463
598
|
});
|
|
464
599
|
}
|
|
@@ -476,6 +611,112 @@ ${problems.join("\n")}`
|
|
|
476
611
|
return intentFiles;
|
|
477
612
|
}
|
|
478
613
|
|
|
614
|
+
// src/parser/profile.ts
|
|
615
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6, readdirSync as readdirSync3, statSync as statSync5 } from "fs";
|
|
616
|
+
import { basename as basename3, join as join7 } from "path";
|
|
617
|
+
import matter4 from "gray-matter";
|
|
618
|
+
|
|
619
|
+
// src/parser/docs.ts
|
|
620
|
+
function entitySlug(term) {
|
|
621
|
+
return term.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/linters/intent-util.ts
|
|
625
|
+
import { posix } from "path";
|
|
626
|
+
|
|
627
|
+
// src/linters/util.ts
|
|
628
|
+
import { execFileSync } from "child_process";
|
|
629
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, statSync as statSync4 } from "fs";
|
|
630
|
+
import { join as join6, relative } from "path";
|
|
631
|
+
import fg2 from "fast-glob";
|
|
632
|
+
import matter3 from "gray-matter";
|
|
633
|
+
|
|
634
|
+
// src/parser/profile.ts
|
|
635
|
+
var PROFILES_DIR = "docs/profiles";
|
|
636
|
+
var PROFILES_INDEX_PATH = `${PROFILES_DIR}/README.md`;
|
|
637
|
+
var PAINS_HEADING = /^(Pains|Irritants|Douleurs)\s*$/i;
|
|
638
|
+
var GAINS_HEADING = /^(Gains|B[ée]n[ée]fices)\s*$/i;
|
|
639
|
+
var BULLET = /^[-*]\s+(.*)$/;
|
|
640
|
+
var NAMED = /^\*\*([^*]+)\*\*/;
|
|
641
|
+
function parseFrontmatter2(text, errors) {
|
|
642
|
+
let data;
|
|
643
|
+
try {
|
|
644
|
+
data = matter4(text).data;
|
|
645
|
+
} catch (error) {
|
|
646
|
+
const reason = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
647
|
+
errors.push({ line: 1, message: `invalid frontmatter YAML: ${reason}` });
|
|
648
|
+
return void 0;
|
|
649
|
+
}
|
|
650
|
+
const result = Schemas.Profile.safeParse(data);
|
|
651
|
+
if (result.success) return result.data;
|
|
652
|
+
for (const issue of result.error.issues) {
|
|
653
|
+
const where = issue.path.length ? ` \`${issue.path.join(".")}\`` : "";
|
|
654
|
+
errors.push({ line: 1, message: `frontmatter${where}: ${issue.message}` });
|
|
655
|
+
}
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
function parseProfileFile(relPath, text) {
|
|
659
|
+
const errors = [];
|
|
660
|
+
const meta = parseFrontmatter2(text, errors);
|
|
661
|
+
const lines = maskFencedCode(text.split(/\r?\n/));
|
|
662
|
+
const pains = [];
|
|
663
|
+
const gains = [];
|
|
664
|
+
let h1;
|
|
665
|
+
let current;
|
|
666
|
+
let start = 0;
|
|
667
|
+
if (lines[0]?.trim() === "---") {
|
|
668
|
+
const end = lines.findIndex((line, i) => i > 0 && /^(---|\.\.\.)\s*$/.test(line));
|
|
669
|
+
start = end < 0 ? lines.length : end + 1;
|
|
670
|
+
}
|
|
671
|
+
for (let i = start; i < lines.length; i++) {
|
|
672
|
+
const line = lines[i] ?? "";
|
|
673
|
+
const heading = parseHeading(line);
|
|
674
|
+
if (heading) {
|
|
675
|
+
if (heading.depth === 1 && h1 === void 0) h1 = heading.title;
|
|
676
|
+
if (current && heading.depth > current.depth) continue;
|
|
677
|
+
if (PAINS_HEADING.test(heading.title)) {
|
|
678
|
+
current = { kind: "pain", depth: heading.depth, items: pains };
|
|
679
|
+
} else if (GAINS_HEADING.test(heading.title)) {
|
|
680
|
+
current = { kind: "gain", depth: heading.depth, items: gains };
|
|
681
|
+
} else {
|
|
682
|
+
current = void 0;
|
|
683
|
+
}
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
if (!current) continue;
|
|
687
|
+
const bullet = BULLET.exec(line)?.[1];
|
|
688
|
+
if (bullet === void 0) continue;
|
|
689
|
+
const name = NAMED.exec(bullet)?.[1]?.trim();
|
|
690
|
+
const slug = name ? entitySlug(name) : "";
|
|
691
|
+
if (!name || !slug) {
|
|
692
|
+
errors.push({ line: i + 1, message: `a ${current.kind} opens with its name in bold` });
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
if (current.items.some((item) => item.slug === slug)) {
|
|
696
|
+
errors.push({ line: i + 1, message: `duplicate ${current.kind} \`${slug}\`` });
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
current.items.push({ name, slug, line: i + 1 });
|
|
700
|
+
}
|
|
701
|
+
if (pains.length === 0 && gains.length === 0) {
|
|
702
|
+
errors.push({ message: "a profile names at least one pain or one gain" });
|
|
703
|
+
}
|
|
704
|
+
const title = meta?.title ?? h1 ?? basename3(relPath, ".md");
|
|
705
|
+
return { ...meta ? { meta } : {}, title, pains, gains, errors };
|
|
706
|
+
}
|
|
707
|
+
function listProfileFiles(targetDir) {
|
|
708
|
+
const dir = join7(targetDir, PROFILES_DIR);
|
|
709
|
+
if (!existsSync6(dir) || !statSync5(dir).isDirectory()) return [];
|
|
710
|
+
return readdirSync3(dir).filter((f) => f.endsWith(".md") && f !== "README.md").filter((f) => statSync5(join7(dir, f)).isFile()).sort();
|
|
711
|
+
}
|
|
712
|
+
function readProfileFiles(targetDir) {
|
|
713
|
+
return listProfileFiles(targetDir).map((file) => {
|
|
714
|
+
const path = `${PROFILES_DIR}/${file}`;
|
|
715
|
+
const text = readFileSync6(join7(targetDir, path), "utf8");
|
|
716
|
+
return { path, file, slug: basename3(file, ".md"), ...parseProfileFile(path, text) };
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
|
|
479
720
|
// src/renderers/common.ts
|
|
480
721
|
import { stringify as yamlStringify } from "yaml";
|
|
481
722
|
function checkSkillCapabilities(skill, engine) {
|
|
@@ -545,6 +786,10 @@ function buildUmbrellaBody(extras) {
|
|
|
545
786
|
const label = triggers.length > 0 ? `\`${s.meta.id}\` (${triggers.map((t) => `\`${t}\``).join(", ")})` : `\`${s.meta.id}\``;
|
|
546
787
|
return `- ${label} \u2014 ${s.meta.description.split("\n")[0]}`;
|
|
547
788
|
});
|
|
789
|
+
const has = (pillar) => extras.activePillars.has(pillar);
|
|
790
|
+
const exposes = (id) => extras.availableSkills.some((s) => s.meta.id === id);
|
|
791
|
+
const when = (condition, ...lines) => condition ? lines : [];
|
|
792
|
+
const inactive = ADDABLE_PILLARS.filter((pillar) => !has(pillar.id)).map((p) => `\`${p.id}\``);
|
|
548
793
|
const sections = [
|
|
549
794
|
"# How we work",
|
|
550
795
|
"",
|
|
@@ -554,29 +799,65 @@ function buildUmbrellaBody(extras) {
|
|
|
554
799
|
"",
|
|
555
800
|
"- `README.md` \u2014 pitch, quick start, scripts. Entry point.",
|
|
556
801
|
"- `docs/spec/<subsystem>.md` \u2014 *what* and *why* (tech-agnostic).",
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
...
|
|
562
|
-
|
|
802
|
+
...when(
|
|
803
|
+
has("handbook"),
|
|
804
|
+
"- `docs/handbook/<feature>.md` \u2014 what the code does not say: entry points, traps, settings outside the repo, manual procedures."
|
|
805
|
+
),
|
|
806
|
+
...when(
|
|
807
|
+
has("decisions"),
|
|
808
|
+
"- `docs/decisions/<slug>.md` \u2014 ADRs: structural choices and rejected alternatives."
|
|
809
|
+
),
|
|
810
|
+
...when(
|
|
811
|
+
has("tests"),
|
|
812
|
+
"- `docs/tests/integration-tests.md` & `e2e-tests.md` \u2014 test scope, stack, conventions, known gaps."
|
|
813
|
+
),
|
|
814
|
+
...when(
|
|
815
|
+
has("workflow"),
|
|
816
|
+
"- `docs/workflow/coding-workflow.md` \u2014 CI, branches, PR, release. How this team works: follow it."
|
|
817
|
+
),
|
|
818
|
+
...when(
|
|
819
|
+
extras.hasProjectSkills === true,
|
|
820
|
+
"- `docs/skills/*.skill.md` \u2014 the project's domain skills."
|
|
821
|
+
),
|
|
822
|
+
...when(
|
|
823
|
+
has("quality"),
|
|
563
824
|
"- `docs/quality/code-quality.md` \u2014 the project's code-quality rules: mechanical checks, judgment rules, accepted deviations. Read it before writing or auditing code."
|
|
564
|
-
|
|
565
|
-
...
|
|
825
|
+
),
|
|
826
|
+
...when(
|
|
827
|
+
has("intents"),
|
|
566
828
|
"- `docs/intents/<intent>.md` \u2014 user intents, one tree per level-1 intent, anchored to the code. `docs/intents/README.md` is the generated index."
|
|
567
|
-
|
|
829
|
+
),
|
|
830
|
+
...when(
|
|
831
|
+
has("profiles"),
|
|
832
|
+
"- `docs/profiles/<profile>.md` \u2014 who the project serves, their pains and gains. `docs/profiles/README.md` is the generated index: which intent serves which pain."
|
|
833
|
+
),
|
|
834
|
+
...when(
|
|
835
|
+
inactive.length > 0,
|
|
836
|
+
"",
|
|
837
|
+
`Not in this project yet: ${inactive.join(", ")}. A pillar is added the day the project needs it, with \`npx @vaubaan/harness add <pillar>\`${exposes("harn-guide") ? "; the `harn-guide` skill says when each one is worth it" : ""}. Propose it to the human, never create the folder unasked.`
|
|
838
|
+
),
|
|
568
839
|
"",
|
|
569
840
|
"## Doc-first",
|
|
570
841
|
"",
|
|
571
842
|
"The order is: **understand the docs \u2192 fill the gaps \u2192 code \u2192 update the docs \u2192 commit**. If the docs are silent or stale on something you change, fill the gap upfront with the doc-skill writers \u2014 not downstream, not after the fact.",
|
|
572
843
|
"",
|
|
573
|
-
...
|
|
574
|
-
"
|
|
575
|
-
|
|
844
|
+
...when(
|
|
845
|
+
has("intents"),
|
|
846
|
+
"- Visible change of behavior \u2192 a `proposed` intent first (`/harn-intent <verb + object>`), never the code first."
|
|
847
|
+
),
|
|
576
848
|
"- Missing spec for a subsystem you touch \u2192 **do not code**, report the gap.",
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
849
|
+
...when(
|
|
850
|
+
has("decisions"),
|
|
851
|
+
"- Implicit structural decision in your changes \u2192 an ADR (`/harn-decision`)."
|
|
852
|
+
),
|
|
853
|
+
...when(
|
|
854
|
+
has("handbook"),
|
|
855
|
+
"- Changed feature behavior \u2192 update the matching handbook (`/harn-handbook`)."
|
|
856
|
+
),
|
|
857
|
+
...when(
|
|
858
|
+
exposes("harn-drift-detector"),
|
|
859
|
+
"- Suspected code \u2194 doc drift \u2192 `/harn-drift` before moving on."
|
|
860
|
+
),
|
|
580
861
|
"",
|
|
581
862
|
"## Checks",
|
|
582
863
|
"",
|
|
@@ -585,7 +866,7 @@ function buildUmbrellaBody(extras) {
|
|
|
585
866
|
"The files the harness generates (`AGENTS.md`, `CLAUDE.md`, the `.claude/`, `.agents/` and `.opencode/` folders, `.harness-manifest.json`) are committed. Never edit them by hand: change their source in `docs/` or `.harness-overrides/`, run `npx @vaubaan/harness update .`, and commit the result. The linter fails when a generated file no longer matches its render."
|
|
586
867
|
];
|
|
587
868
|
if (skillLines.length > 0) {
|
|
588
|
-
sections.push("", "##
|
|
869
|
+
sections.push("", "## Skills", "", skillLines.join("\n"));
|
|
589
870
|
}
|
|
590
871
|
return `${sections.join("\n")}
|
|
591
872
|
`;
|
|
@@ -703,8 +984,10 @@ function getRenderer(engine) {
|
|
|
703
984
|
|
|
704
985
|
// src/renderers/intents-index.ts
|
|
705
986
|
var INTRO = "User intents of this project, anchored to the code. Generated by `@vaubaan/harness` from `docs/intents/*.md`: edit the intents, not this file, then run `npx @vaubaan/harness update .`.";
|
|
987
|
+
var EMPTY = "No intent yet. `/harn-intent <verb + object>` writes the first one, before the code.";
|
|
706
988
|
function buildIntentsIndex(intentFiles) {
|
|
707
989
|
const lines = ["# Intents", "", INTRO, ""];
|
|
990
|
+
if (intentFiles.length === 0) lines.push(EMPTY);
|
|
708
991
|
const sorted = [...intentFiles].sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0);
|
|
709
992
|
for (const intentFile of sorted) {
|
|
710
993
|
const status = intentFile.meta?.status ?? "proposed";
|
|
@@ -718,6 +1001,54 @@ function buildIntentsIndex(intentFiles) {
|
|
|
718
1001
|
`;
|
|
719
1002
|
}
|
|
720
1003
|
|
|
1004
|
+
// src/renderers/profiles-index.ts
|
|
1005
|
+
var INTRO2 = "Who this project serves, and what the intents do for them. Generated by `@vaubaan/harness` from `docs/profiles/*.md` and `docs/intents/*.md`: edit those, not this file, then run `npx @vaubaan/harness update .`.";
|
|
1006
|
+
var EMPTY2 = "No profile yet. The `harn-intent-writer` skill writes the first one from the research you point it to.";
|
|
1007
|
+
function buildProfilesIndex(profiles, intentFiles = []) {
|
|
1008
|
+
const lines = ["# Profiles", "", INTRO2];
|
|
1009
|
+
if (profiles.length === 0) lines.push("", EMPTY2);
|
|
1010
|
+
const sortedIntents = [...intentFiles].sort(
|
|
1011
|
+
(a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0
|
|
1012
|
+
);
|
|
1013
|
+
for (const profile of [...profiles].sort((a, b) => a.file < b.file ? -1 : 1)) {
|
|
1014
|
+
const theirs = sortedIntents.filter((file) => file.meta?.actors.includes(profile.slug));
|
|
1015
|
+
lines.push(
|
|
1016
|
+
"",
|
|
1017
|
+
`## [${profile.title}](./${profile.file}) \u2014 ${profile.meta?.status ?? "hypothesis"}`,
|
|
1018
|
+
""
|
|
1019
|
+
);
|
|
1020
|
+
lines.push(
|
|
1021
|
+
theirs.length ? `Intents: ${theirs.map((f) => `[${f.title}](../intents/${f.file})`).join(", ")}.` : "Intents: none names this profile yet."
|
|
1022
|
+
);
|
|
1023
|
+
const served = (kind, item) => {
|
|
1024
|
+
const by = [];
|
|
1025
|
+
for (const file of theirs) {
|
|
1026
|
+
for (const node of file.nodes) {
|
|
1027
|
+
if (node[kind].includes(item.slug)) {
|
|
1028
|
+
by.push(`[${node.title}](../intents/${file.file})`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
if (by.length) return by.join(", ");
|
|
1033
|
+
return kind === "relieves" ? "*no intent relieves it yet*" : "*no intent delivers it yet*";
|
|
1034
|
+
};
|
|
1035
|
+
if (profile.pains.length) {
|
|
1036
|
+
lines.push("", "Pains, most severe first:", "");
|
|
1037
|
+
for (const pain of profile.pains) {
|
|
1038
|
+
lines.push(`- **${pain.name}** (\`${pain.slug}\`) \u2014 ${served("relieves", pain)}`);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
if (profile.gains.length) {
|
|
1042
|
+
lines.push("", "Gains:", "");
|
|
1043
|
+
for (const gain of profile.gains) {
|
|
1044
|
+
lines.push(`- **${gain.name}** (\`${gain.slug}\`) \u2014 ${served("delivers", gain)}`);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return `${lines.join("\n")}
|
|
1049
|
+
`;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
721
1052
|
// src/render.ts
|
|
722
1053
|
var RenderError = class extends Error {
|
|
723
1054
|
constructor(message) {
|
|
@@ -749,13 +1080,21 @@ var CLAUDE_MD_STUB = "@AGENTS.md\n";
|
|
|
749
1080
|
function opencodeLast(engines) {
|
|
750
1081
|
return [...engines].sort((a, b) => Number(a === "opencode") - Number(b === "opencode"));
|
|
751
1082
|
}
|
|
1083
|
+
function servesAnActivePillar(skill, active) {
|
|
1084
|
+
return !skill.meta.pillars || skill.meta.pillars.some((pillar) => active.has(pillar));
|
|
1085
|
+
}
|
|
752
1086
|
function render(input) {
|
|
753
1087
|
const { engines } = input;
|
|
754
1088
|
if (engines.length === 0) {
|
|
755
1089
|
throw new RenderError("at least one engine must be selected");
|
|
756
1090
|
}
|
|
757
1091
|
const base = input.projectSkills?.length ? { ...input.harness, skills: mergeById(input.harness.skills, input.projectSkills) } : input.harness;
|
|
758
|
-
const
|
|
1092
|
+
const active = input.activePillars ?? allPillars();
|
|
1093
|
+
const merged = applyOverrides(base, input.overrides);
|
|
1094
|
+
const harness = {
|
|
1095
|
+
...merged,
|
|
1096
|
+
skills: merged.skills.filter((skill) => servesAnActivePillar(skill, active))
|
|
1097
|
+
};
|
|
759
1098
|
const files = [];
|
|
760
1099
|
const warnings = [];
|
|
761
1100
|
const exposedSkills = /* @__PURE__ */ new Map();
|
|
@@ -787,21 +1126,25 @@ function render(input) {
|
|
|
787
1126
|
availableSkills: Array.from(exposedSkills.values()),
|
|
788
1127
|
availableCommands: Array.from(exposedCmds.values()),
|
|
789
1128
|
hasProjectSkills: (input.projectSkills?.length ?? 0) > 0,
|
|
790
|
-
|
|
791
|
-
hasIntents: (input.intentFiles?.length ?? 0) > 0
|
|
1129
|
+
activePillars: active
|
|
792
1130
|
});
|
|
793
1131
|
files.push({ path: "AGENTS.md", content: umbrellaContent });
|
|
794
1132
|
if (engines.includes("claude-code")) {
|
|
795
1133
|
files.push({ path: "CLAUDE.md", content: CLAUDE_MD_STUB });
|
|
796
1134
|
}
|
|
797
|
-
if (input.intentFiles
|
|
1135
|
+
if (input.intentFiles) {
|
|
798
1136
|
files.push({ path: INTENTS_INDEX_PATH, content: buildIntentsIndex(input.intentFiles) });
|
|
799
1137
|
}
|
|
1138
|
+
if (input.profileFiles) {
|
|
1139
|
+
files.push({
|
|
1140
|
+
path: PROFILES_INDEX_PATH,
|
|
1141
|
+
content: buildProfilesIndex(input.profileFiles, input.intentFiles ?? [])
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
800
1144
|
return { files, warnings };
|
|
801
1145
|
}
|
|
802
1146
|
|
|
803
1147
|
// src/cli/plan-render.ts
|
|
804
|
-
var QUALITY_DOC_PATH = "docs/quality/code-quality.md";
|
|
805
1148
|
function resolveEngineList(requested) {
|
|
806
1149
|
if (!requested || requested.length === 0) {
|
|
807
1150
|
throw new Error(
|
|
@@ -818,7 +1161,7 @@ function resolveEngineList(requested) {
|
|
|
818
1161
|
}
|
|
819
1162
|
function defaultPackageDir() {
|
|
820
1163
|
const here = dirname2(fileURLToPath(import.meta.url));
|
|
821
|
-
if (
|
|
1164
|
+
if (existsSync7(join8(here, "skills"))) return here;
|
|
822
1165
|
return resolve2(here, "..");
|
|
823
1166
|
}
|
|
824
1167
|
function planInit(args) {
|
|
@@ -827,15 +1170,22 @@ function planInit(args) {
|
|
|
827
1170
|
const harness = loadHarness(packageDir);
|
|
828
1171
|
const overrides = args.overridesDir ? loadOverrides(args.overridesDir) : void 0;
|
|
829
1172
|
const projectSkills = loadProjectSkills(args.targetDir);
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
-
|
|
1173
|
+
const active = activePillars(args.targetDir);
|
|
1174
|
+
const output = render({
|
|
1175
|
+
harness,
|
|
1176
|
+
engines,
|
|
1177
|
+
overrides,
|
|
1178
|
+
projectSkills,
|
|
1179
|
+
activePillars: active,
|
|
1180
|
+
...active.has("intents") ? { intentFiles: loadIntentFiles(args.targetDir) } : {},
|
|
1181
|
+
...active.has("profiles") ? { profileFiles: readProfileFiles(args.targetDir) } : {}
|
|
1182
|
+
});
|
|
833
1183
|
return { engines, output };
|
|
834
1184
|
}
|
|
835
1185
|
|
|
836
1186
|
// src/cli/uninstall.ts
|
|
837
|
-
import { existsSync as
|
|
838
|
-
import { dirname as dirname3, join as
|
|
1187
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7, readdirSync as readdirSync4, rmdirSync, unlinkSync } from "fs";
|
|
1188
|
+
import { dirname as dirname3, join as join9, relative as relative2, resolve as resolve3 } from "path";
|
|
839
1189
|
function pruneEmptyDirs(root, leaves) {
|
|
840
1190
|
const candidates = /* @__PURE__ */ new Set();
|
|
841
1191
|
for (const leaf of leaves) {
|
|
@@ -848,10 +1198,10 @@ function pruneEmptyDirs(root, leaves) {
|
|
|
848
1198
|
const pruned = [];
|
|
849
1199
|
const sorted = [...candidates].sort((a, b) => b.length - a.length);
|
|
850
1200
|
for (const dir of sorted) {
|
|
851
|
-
if (!
|
|
852
|
-
if (
|
|
1201
|
+
if (!existsSync8(dir)) continue;
|
|
1202
|
+
if (readdirSync4(dir).length > 0) continue;
|
|
853
1203
|
rmdirSync(dir);
|
|
854
|
-
pruned.push(
|
|
1204
|
+
pruned.push(relative2(root, dir));
|
|
855
1205
|
}
|
|
856
1206
|
return pruned;
|
|
857
1207
|
}
|
|
@@ -865,28 +1215,28 @@ import {
|
|
|
865
1215
|
lstatSync as lstatSync2,
|
|
866
1216
|
mkdirSync,
|
|
867
1217
|
openSync,
|
|
868
|
-
readFileSync as
|
|
869
|
-
readdirSync as
|
|
1218
|
+
readFileSync as readFileSync8,
|
|
1219
|
+
readdirSync as readdirSync5,
|
|
870
1220
|
realpathSync as realpathSync2,
|
|
871
1221
|
rmdirSync as rmdirSync2,
|
|
872
1222
|
unlinkSync as unlinkSync2,
|
|
873
1223
|
writeFileSync as writeFileSync2
|
|
874
1224
|
} from "fs";
|
|
875
1225
|
import { homedir } from "os";
|
|
876
|
-
import { basename as
|
|
1226
|
+
import { basename as basename4, dirname as dirname4, isAbsolute as isAbsolute2, join as join10, relative as relative3, resolve as resolve4, sep } from "path";
|
|
877
1227
|
var MANIFEST_PATH = ".harness-manifest.json";
|
|
878
1228
|
var PRIVATE_FILES = /* @__PURE__ */ new Set([MANIFEST_PATH]);
|
|
879
1229
|
function canonicalRoot(root) {
|
|
880
1230
|
let ancestor = resolve4(root);
|
|
881
1231
|
const missing = [];
|
|
882
1232
|
while (!lstatSync2(ancestor, { throwIfNoEntry: false })) {
|
|
883
|
-
missing.unshift(
|
|
1233
|
+
missing.unshift(basename4(ancestor));
|
|
884
1234
|
ancestor = dirname4(ancestor);
|
|
885
1235
|
}
|
|
886
|
-
return
|
|
1236
|
+
return join10(realpathSync2(ancestor), ...missing);
|
|
887
1237
|
}
|
|
888
1238
|
function contains(parent, child) {
|
|
889
|
-
const path =
|
|
1239
|
+
const path = relative3(parent, child);
|
|
890
1240
|
return path === "" || !isAbsolute2(path) && path !== ".." && !path.startsWith(`..${sep}`);
|
|
891
1241
|
}
|
|
892
1242
|
function assertBackupLocation(root, backup) {
|
|
@@ -934,14 +1284,14 @@ function saveSnapshot(root, paths, backup) {
|
|
|
934
1284
|
createDirectories(dirname4(backup), [], 448);
|
|
935
1285
|
mkdirSync(backup, { mode: 448 });
|
|
936
1286
|
for (const path of paths) {
|
|
937
|
-
const full =
|
|
1287
|
+
const full = join10(root, path);
|
|
938
1288
|
const info = lstatSync2(full, { throwIfNoEntry: false });
|
|
939
1289
|
if (!info) {
|
|
940
1290
|
entries.push({ path, exists: false });
|
|
941
1291
|
continue;
|
|
942
1292
|
}
|
|
943
|
-
const content =
|
|
944
|
-
writeBackupFile(
|
|
1293
|
+
const content = readFileSync8(full);
|
|
1294
|
+
writeBackupFile(join10(backup, "files", path), content);
|
|
945
1295
|
entries.push({
|
|
946
1296
|
path,
|
|
947
1297
|
exists: true,
|
|
@@ -950,7 +1300,7 @@ function saveSnapshot(root, paths, backup) {
|
|
|
950
1300
|
});
|
|
951
1301
|
}
|
|
952
1302
|
writeBackupFile(
|
|
953
|
-
|
|
1303
|
+
join10(backup, "snapshot.json"),
|
|
954
1304
|
`${JSON.stringify({ version: 1, root, createdAt: (/* @__PURE__ */ new Date()).toISOString(), entries }, null, 2)}
|
|
955
1305
|
`
|
|
956
1306
|
);
|
|
@@ -965,14 +1315,14 @@ function rollback(root, backup, entries, touched, createdDirectories) {
|
|
|
965
1315
|
try {
|
|
966
1316
|
assertManagedPaths(root, [path]);
|
|
967
1317
|
const entry = entries.get(path);
|
|
968
|
-
const full =
|
|
1318
|
+
const full = join10(root, path);
|
|
969
1319
|
const current = lstatSync2(full, { throwIfNoEntry: false });
|
|
970
1320
|
if (!entry?.exists) {
|
|
971
1321
|
if (current) unlinkSync2(full);
|
|
972
1322
|
continue;
|
|
973
1323
|
}
|
|
974
|
-
const original =
|
|
975
|
-
if (!current || !
|
|
1324
|
+
const original = readFileSync8(join10(backup, "files", path));
|
|
1325
|
+
if (!current || !readFileSync8(full).equals(original)) {
|
|
976
1326
|
if (current) unlinkSync2(full);
|
|
977
1327
|
writeFileSync2(full, original, { mode: 384 });
|
|
978
1328
|
}
|
|
@@ -983,7 +1333,7 @@ function rollback(root, backup, entries, touched, createdDirectories) {
|
|
|
983
1333
|
}
|
|
984
1334
|
for (const directory of [...createdDirectories].reverse()) {
|
|
985
1335
|
try {
|
|
986
|
-
if (
|
|
1336
|
+
if (readdirSync5(directory).length === 0) rmdirSync2(directory);
|
|
987
1337
|
} catch (error) {
|
|
988
1338
|
errors.push(`${directory}: ${errorMessage(error)}`);
|
|
989
1339
|
}
|
|
@@ -995,7 +1345,7 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
995
1345
|
assertManagedPaths(root, paths);
|
|
996
1346
|
const target = canonicalRoot(root);
|
|
997
1347
|
const backup = resolve4(
|
|
998
|
-
backupDir ??
|
|
1348
|
+
backupDir ?? join10(homedir(), ".local", "state", "vaubaan-harness", "backups", randomUUID())
|
|
999
1349
|
);
|
|
1000
1350
|
assertBackupLocation(target, backup);
|
|
1001
1351
|
let snapshot;
|
|
@@ -1013,12 +1363,12 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
1013
1363
|
try {
|
|
1014
1364
|
assertManagedPaths(target, paths);
|
|
1015
1365
|
for (const path of removals) {
|
|
1016
|
-
if (!lstatSync2(
|
|
1366
|
+
if (!lstatSync2(join10(target, path), { throwIfNoEntry: false })) continue;
|
|
1017
1367
|
touched.add(path);
|
|
1018
|
-
unlinkSync2(
|
|
1368
|
+
unlinkSync2(join10(target, path));
|
|
1019
1369
|
}
|
|
1020
1370
|
for (const file of writes) {
|
|
1021
|
-
const full =
|
|
1371
|
+
const full = join10(target, file.path);
|
|
1022
1372
|
createDirectories(dirname4(full), createdDirectories);
|
|
1023
1373
|
touched.add(file.path);
|
|
1024
1374
|
const entry = entries.get(file.path);
|
|
@@ -1038,13 +1388,13 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
1038
1388
|
}
|
|
1039
1389
|
|
|
1040
1390
|
// src/cli/update.ts
|
|
1041
|
-
import { existsSync as
|
|
1042
|
-
import { dirname as dirname5, join as
|
|
1391
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10, readdirSync as readdirSync6, statSync as statSync6 } from "fs";
|
|
1392
|
+
import { dirname as dirname5, join as join12, resolve as resolve5 } from "path";
|
|
1043
1393
|
import { isDeepStrictEqual } from "util";
|
|
1044
1394
|
|
|
1045
1395
|
// src/cli/update-manifest.ts
|
|
1046
|
-
import { existsSync as
|
|
1047
|
-
import { join as
|
|
1396
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9 } from "fs";
|
|
1397
|
+
import { join as join11 } from "path";
|
|
1048
1398
|
import { z as z4 } from "zod";
|
|
1049
1399
|
var EngineSchema = z4.enum(ENGINES);
|
|
1050
1400
|
var LegacySchema = z4.object({
|
|
@@ -1056,10 +1406,10 @@ var LegacySchema = z4.object({
|
|
|
1056
1406
|
});
|
|
1057
1407
|
function readUpdateInstallation(root) {
|
|
1058
1408
|
assertManagedPaths(root, [MANIFEST_FILENAME]);
|
|
1059
|
-
if (!
|
|
1409
|
+
if (!existsSync9(join11(root, MANIFEST_FILENAME))) {
|
|
1060
1410
|
throw new Error("no harness manifest found; use init for a new installation");
|
|
1061
1411
|
}
|
|
1062
|
-
const raw = JSON.parse(
|
|
1412
|
+
const raw = JSON.parse(readFileSync9(join11(root, MANIFEST_FILENAME), "utf8"));
|
|
1063
1413
|
const sourceVersion = String(raw?.version);
|
|
1064
1414
|
let manifest;
|
|
1065
1415
|
if (["1", "2", "3"].includes(sourceVersion)) {
|
|
@@ -1084,7 +1434,7 @@ function readUpdateInstallation(root) {
|
|
|
1084
1434
|
var LEGACY_HOOK_FILES = [".claude/settings.json", ".codex/hooks.json"];
|
|
1085
1435
|
var LEGACY_HOOK_MARKER = "@vaubaan/harness stop-hook";
|
|
1086
1436
|
function currentContent(root, path) {
|
|
1087
|
-
return
|
|
1437
|
+
return existsSync10(join12(root, path)) ? readFileSync10(join12(root, path), "utf8") : void 0;
|
|
1088
1438
|
}
|
|
1089
1439
|
function checkArtifactConflicts(root, previous, writes, removals) {
|
|
1090
1440
|
const desired = new Map(writes.map((file) => [file.path, file.content]));
|
|
@@ -1118,7 +1468,7 @@ function carryMovedPaths(root, previous, warnings) {
|
|
|
1118
1468
|
let files = previous.files;
|
|
1119
1469
|
let fileHashes = previous.fileHashes;
|
|
1120
1470
|
for (const [from, to] of MOVED_PATHS) {
|
|
1121
|
-
if (!files.includes(from) ||
|
|
1471
|
+
if (!files.includes(from) || existsSync10(join12(root, from))) continue;
|
|
1122
1472
|
files = [...new Set(files.map((path) => path === from ? to : path))];
|
|
1123
1473
|
const hash = fileHashes?.[from];
|
|
1124
1474
|
if (fileHashes && hash !== void 0) {
|
|
@@ -1126,8 +1476,8 @@ function carryMovedPaths(root, previous, warnings) {
|
|
|
1126
1476
|
fileHashes = { ...rest, [to]: hash };
|
|
1127
1477
|
}
|
|
1128
1478
|
}
|
|
1129
|
-
const oldDir =
|
|
1130
|
-
if (
|
|
1479
|
+
const oldDir = join12(root, "docs/journeys");
|
|
1480
|
+
if (existsSync10(oldDir) && statSync6(oldDir).isDirectory() && readdirSync6(oldDir).length > 0) {
|
|
1131
1481
|
warnings.push(
|
|
1132
1482
|
"docs/journeys/ is now docs/intents/: run `git mv docs/journeys docs/intents`, then `npx @vaubaan/harness update .` again"
|
|
1133
1483
|
);
|
|
@@ -1141,12 +1491,33 @@ function legacyHookWarnings(root) {
|
|
|
1141
1491
|
const content = currentContent(root, path);
|
|
1142
1492
|
if (content?.includes(LEGACY_HOOK_MARKER)) {
|
|
1143
1493
|
warnings.push(
|
|
1144
|
-
`remove the harness Stop hook entry from ${path}: the
|
|
1494
|
+
`remove the harness Stop hook entry from ${path}: the stop-hook command was removed in 3.0 and the entry now fails; run \`npx @vaubaan/harness lint\` in CI and pre-commit instead`
|
|
1145
1495
|
);
|
|
1146
1496
|
}
|
|
1147
1497
|
}
|
|
1148
1498
|
return warnings;
|
|
1149
1499
|
}
|
|
1500
|
+
function renamedIdWarnings(root, overridesParent) {
|
|
1501
|
+
const used = loadProjectSkills(root).map((skill) => ({
|
|
1502
|
+
id: skill.meta.id,
|
|
1503
|
+
where: "docs/skills/"
|
|
1504
|
+
}));
|
|
1505
|
+
if (overridesParent) {
|
|
1506
|
+
const overrides = loadOverrides(overridesParent);
|
|
1507
|
+
for (const item of [...overrides?.add?.skills ?? [], ...overrides?.add?.cmds ?? []]) {
|
|
1508
|
+
used.push({ id: item.meta.id, where: ".harness-overrides/" });
|
|
1509
|
+
}
|
|
1510
|
+
for (const id of overrides?.disable ?? []) {
|
|
1511
|
+
used.push({ id, where: ".harness-overrides/disable.yaml" });
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return used.flatMap(({ id, where }) => {
|
|
1515
|
+
const renamed = RENAMED_IDS.get(id);
|
|
1516
|
+
return renamed ? [
|
|
1517
|
+
`${where} names \`${id}\`, renamed \`${renamed}\` in 3.0: it no longer replaces or disables the shipped one \u2014 rename it`
|
|
1518
|
+
] : [];
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1150
1521
|
function planInstallation(args, settings) {
|
|
1151
1522
|
const root = resolve5(args.targetDir);
|
|
1152
1523
|
const { engines } = settings;
|
|
@@ -1160,14 +1531,14 @@ function planInstallation(args, settings) {
|
|
|
1160
1531
|
assertManagedPaths(root, [...previous.files, ...preserved]);
|
|
1161
1532
|
const requestedOverrides = args.overridesDir ?? previous.overridesDir;
|
|
1162
1533
|
const overridesDir = args.overridesDir ? resolve5(args.overridesDir) : previous.overridesDir ? resolve5(root, previous.overridesDir) : root;
|
|
1163
|
-
if (requestedOverrides && !
|
|
1534
|
+
if (requestedOverrides && !existsSync10(join12(overridesDir, ".harness-overrides"))) {
|
|
1164
1535
|
throw new Error(`recorded overrides are missing: ${overridesDir}/.harness-overrides`);
|
|
1165
1536
|
}
|
|
1166
|
-
const hasOverrides =
|
|
1167
|
-
const disablePath =
|
|
1168
|
-
if (
|
|
1537
|
+
const hasOverrides = existsSync10(join12(overridesDir, ".harness-overrides"));
|
|
1538
|
+
const disablePath = join12(overridesDir, ".harness-overrides", "disable.yaml");
|
|
1539
|
+
if (existsSync10(disablePath)) {
|
|
1169
1540
|
try {
|
|
1170
|
-
DisableYamlSchema.parse(parseYAML(
|
|
1541
|
+
DisableYamlSchema.parse(parseYAML(readFileSync10(disablePath, "utf8")));
|
|
1171
1542
|
} catch {
|
|
1172
1543
|
throw new Error(`invalid override selection: ${disablePath}`);
|
|
1173
1544
|
}
|
|
@@ -1197,13 +1568,17 @@ function planInstallation(args, settings) {
|
|
|
1197
1568
|
...preserved.length ? { preservedFiles: preserved } : {}
|
|
1198
1569
|
};
|
|
1199
1570
|
const writes = output.filter((file) => currentContent(root, file.path) !== file.content);
|
|
1200
|
-
const existingRemovals = removals.filter((path) =>
|
|
1571
|
+
const existingRemovals = removals.filter((path) => existsSync10(join12(root, path)));
|
|
1201
1572
|
if (writes.length || existingRemovals.length || !isDeepStrictEqual(settings.previous, manifest)) {
|
|
1202
1573
|
manifest.renderedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1203
1574
|
writes.push({ path: MANIFEST_FILENAME, content: `${JSON.stringify(manifest, null, 2)}
|
|
1204
1575
|
` });
|
|
1205
1576
|
}
|
|
1206
|
-
warnings.push(
|
|
1577
|
+
warnings.push(
|
|
1578
|
+
...rendered.output.warnings,
|
|
1579
|
+
...legacyHookWarnings(root),
|
|
1580
|
+
...renamedIdWarnings(root, hasOverrides ? overridesDir : void 0)
|
|
1581
|
+
);
|
|
1207
1582
|
if (preserved.length) warnings.push(`preserved user-owned artifacts: ${preserved.join(", ")}`);
|
|
1208
1583
|
return { writes, removals: existingRemovals, owned, manifest, warnings };
|
|
1209
1584
|
}
|
|
@@ -1237,7 +1612,7 @@ function updateCommand(args) {
|
|
|
1237
1612
|
if (args.dryRun || plan.result.upToDate) return plan.result;
|
|
1238
1613
|
const root = resolve5(args.targetDir);
|
|
1239
1614
|
const { backupDir } = applyUpdateTransaction(root, plan.writes, plan.removals, args.backupDir);
|
|
1240
|
-
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname5(
|
|
1615
|
+
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname5(join12(root, path)))));
|
|
1241
1616
|
return { ...plan.result, backupDir };
|
|
1242
1617
|
}
|
|
1243
1618
|
|
|
@@ -1249,7 +1624,7 @@ function writeFilesToTarget(files, targetDir) {
|
|
|
1249
1624
|
);
|
|
1250
1625
|
const written = [];
|
|
1251
1626
|
for (const f of files) {
|
|
1252
|
-
const full =
|
|
1627
|
+
const full = join13(targetDir, f.path);
|
|
1253
1628
|
mkdirSync2(dirname6(full), { recursive: true });
|
|
1254
1629
|
writeFileSync3(full, f.content);
|
|
1255
1630
|
written.push(f.path);
|
|
@@ -1273,7 +1648,7 @@ function initCommand(args) {
|
|
|
1273
1648
|
{ previous, sourceVersion: previous.version, engines }
|
|
1274
1649
|
);
|
|
1275
1650
|
const touchedExisting = [...plan.writes.map((file) => file.path), ...plan.removals].some(
|
|
1276
|
-
(path) => path !== MANIFEST_FILENAME &&
|
|
1651
|
+
(path) => path !== MANIFEST_FILENAME && existsSync11(join13(root, path))
|
|
1277
1652
|
);
|
|
1278
1653
|
let backupDir;
|
|
1279
1654
|
if (plan.writes.length || plan.removals.length) {
|
|
@@ -1282,7 +1657,7 @@ function initCommand(args) {
|
|
|
1282
1657
|
rmSync(backupDir, { recursive: true, force: true });
|
|
1283
1658
|
backupDir = void 0;
|
|
1284
1659
|
}
|
|
1285
|
-
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname6(
|
|
1660
|
+
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname6(join13(root, path)))));
|
|
1286
1661
|
}
|
|
1287
1662
|
return {
|
|
1288
1663
|
filesWritten: plan.owned,
|
|
@@ -1292,8 +1667,70 @@ function initCommand(args) {
|
|
|
1292
1667
|
...backupDir ? { backupDir } : {}
|
|
1293
1668
|
};
|
|
1294
1669
|
}
|
|
1670
|
+
|
|
1671
|
+
// src/cli/add.ts
|
|
1672
|
+
import { existsSync as existsSync12, lstatSync as lstatSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync11, writeFileSync as writeFileSync4 } from "fs";
|
|
1673
|
+
import { dirname as dirname7, join as join14, resolve as resolve7 } from "path";
|
|
1674
|
+
var today = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1675
|
+
function assertPlainPath(root, path) {
|
|
1676
|
+
let current = root;
|
|
1677
|
+
for (const part of path.split("/")) {
|
|
1678
|
+
current = join14(current, part);
|
|
1679
|
+
const info = lstatSync3(current, { throwIfNoEntry: false });
|
|
1680
|
+
if (!info) return;
|
|
1681
|
+
if (info.isSymbolicLink()) throw new Error(`symbolic link in pillar path: ${path}`);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
function addCommand(args) {
|
|
1685
|
+
const root = resolve7(args.targetDir);
|
|
1686
|
+
const addable = ADDABLE_PILLARS.map((p) => p.id).join(", ");
|
|
1687
|
+
const pillar = getPillar(args.pillar);
|
|
1688
|
+
if (!pillar) throw new Error(`unknown pillar: ${args.pillar} (expected one of ${addable})`);
|
|
1689
|
+
if (pillar.core) throw new Error(`the ${pillar.id} pillar is always active: nothing to add`);
|
|
1690
|
+
if (!pillar.dir || pillar.starters === void 0) {
|
|
1691
|
+
throw new Error(
|
|
1692
|
+
`the ${pillar.id} pillar is not added: drop a file into ${pillar.dir}/ and run \`update\` (addable: ${addable})`
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
if (!existsSync12(root)) throw new Error(`target directory does not exist: ${root}`);
|
|
1696
|
+
const activated = !isPillarActive(root, pillar.id);
|
|
1697
|
+
assertPlainPath(root, pillar.dir);
|
|
1698
|
+
for (const starter of pillar.starters) assertPlainPath(root, starter.path);
|
|
1699
|
+
const templatesDir = join14(args.packageDir ?? defaultPackageDir(), "templates");
|
|
1700
|
+
const filesCreated = [];
|
|
1701
|
+
mkdirSync3(join14(root, pillar.dir), { recursive: true });
|
|
1702
|
+
for (const starter of pillar.starters) {
|
|
1703
|
+
const destination = join14(root, starter.path);
|
|
1704
|
+
if (existsSync12(destination)) continue;
|
|
1705
|
+
const content = readFileSync11(join14(templatesDir, starter.template), "utf8");
|
|
1706
|
+
mkdirSync3(dirname7(destination), { recursive: true });
|
|
1707
|
+
writeFileSync4(destination, content.replaceAll("<DATE>", today()));
|
|
1708
|
+
filesCreated.push(starter.path);
|
|
1709
|
+
}
|
|
1710
|
+
const next = pillar.next ?? "";
|
|
1711
|
+
if (!existsSync12(join14(root, MANIFEST_FILENAME))) {
|
|
1712
|
+
return {
|
|
1713
|
+
pillar: pillar.id,
|
|
1714
|
+
activated,
|
|
1715
|
+
filesCreated,
|
|
1716
|
+
next: `run \`npx @vaubaan/harness init . --engines=<list>\` to render the harness, then ${next}`
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
const update = updateCommand({
|
|
1720
|
+
targetDir: root,
|
|
1721
|
+
...args.packageDir ? { packageDir: args.packageDir } : {},
|
|
1722
|
+
...args.overridesDir ? { overridesDir: args.overridesDir } : {},
|
|
1723
|
+
...args.backupDir ? { backupDir: args.backupDir } : {}
|
|
1724
|
+
});
|
|
1725
|
+
return { pillar: pillar.id, activated, filesCreated, update, next };
|
|
1726
|
+
}
|
|
1295
1727
|
export {
|
|
1728
|
+
ADDABLE_PILLARS,
|
|
1729
|
+
PILLARS,
|
|
1730
|
+
PILLAR_IDS,
|
|
1296
1731
|
VERSION,
|
|
1732
|
+
activePillars,
|
|
1733
|
+
addCommand,
|
|
1297
1734
|
initCommand,
|
|
1298
1735
|
planInit,
|
|
1299
1736
|
planUpdate,
|