@vaubaan/harness 1.4.0 → 2.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 +303 -167
- package/dist/cli/index.js +884 -1880
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +275 -1062
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +9 -23
- package/dist/init.js +268 -1034
- package/dist/init.js.map +1 -1
- package/dist/linters/index.js +687 -31
- package/dist/linters/index.js.map +1 -1
- package/dist/parser/index.d.ts +1 -26
- package/dist/parser/index.js +1 -17
- package/dist/parser/index.js.map +1 -1
- package/dist/{render-Cu2XrkkY.d.ts → render-C-FWmUfX.d.ts} +8 -15
- package/dist/render.d.ts +1 -1
- package/dist/render.js +16 -278
- package/dist/render.js.map +1 -1
- package/dist/skills/decision-record-writer.skill.md +3 -4
- package/dist/skills/doc-audit.skill.md +7 -7
- package/dist/skills/drift-detector.skill.md +1 -1
- package/dist/skills/handbook-writer.skill.md +2 -2
- package/dist/skills/readme-writer.skill.md +3 -3
- package/dist/skills/spec-writer.skill.md +89 -71
- package/dist/skills/test-plan-writer.skill.md +3 -3
- package/dist/skills/workflow-writer.skill.md +20 -3
- package/dist/templates/code-quality.md.tmpl +2 -2
- package/dist/templates/coding-workflow.md.tmpl +10 -0
- package/package.json +1 -1
- package/dist/agents/coding.agent.md +0 -182
- package/dist/agents/merge.agent.md +0 -139
- package/dist/agents/planning.agent.md +0 -194
- package/dist/agents/review.agent.md +0 -176
- package/dist/commands/clean-code.cmd.md +0 -26
- package/dist/skills/clean-code-guardian.skill.md +0 -391
package/dist/index.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "
|
|
2
|
+
var VERSION = "2.0.0";
|
|
3
3
|
|
|
4
4
|
// src/cli/init.ts
|
|
5
|
-
import { existsSync as
|
|
6
|
-
import { dirname as
|
|
5
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync2, rmSync, writeFileSync as writeFileSync3 } from "fs";
|
|
6
|
+
import { dirname as dirname6, join as join9, resolve as resolve6 } from "path";
|
|
7
7
|
|
|
8
8
|
// src/cli/managed-paths.ts
|
|
9
9
|
import { lstatSync, realpathSync, statSync } from "fs";
|
|
10
10
|
import { basename, dirname, isAbsolute, join, resolve, win32 } from "path";
|
|
11
|
-
var MANAGED_FILES = /* @__PURE__ */ new Set([
|
|
12
|
-
|
|
13
|
-
"CLAUDE.md",
|
|
11
|
+
var MANAGED_FILES = /* @__PURE__ */ new Set(["AGENTS.md", "CLAUDE.md", ".harness-manifest.json"]);
|
|
12
|
+
var RELEASED_PATHS = [
|
|
14
13
|
".mcp.json",
|
|
15
|
-
".harness-manifest.json",
|
|
16
|
-
".claude/settings.json",
|
|
17
14
|
".codex/config.toml",
|
|
18
|
-
".codex/hooks.json",
|
|
19
15
|
".opencode/opencode.json",
|
|
20
|
-
".opencode/mcp.json"
|
|
21
|
-
|
|
16
|
+
".opencode/mcp.json",
|
|
17
|
+
".claude/settings.json",
|
|
18
|
+
".codex/hooks.json"
|
|
19
|
+
];
|
|
22
20
|
var MANAGED_DIRECTORIES = [
|
|
23
21
|
".claude/agents/",
|
|
24
22
|
".claude/commands/",
|
|
@@ -78,128 +76,54 @@ function assertManagedPaths(root, files) {
|
|
|
78
76
|
|
|
79
77
|
// src/cli/manifest.ts
|
|
80
78
|
import { createHash } from "crypto";
|
|
81
|
-
import { chmodSync, existsSync
|
|
82
|
-
import { join as join4 } from "path";
|
|
83
|
-
import { z as z3 } from "zod";
|
|
84
|
-
|
|
85
|
-
// src/cli/opencode-config.ts
|
|
86
|
-
import { existsSync, readFileSync } from "fs";
|
|
79
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync } from "fs";
|
|
87
80
|
import { join as join2 } from "path";
|
|
88
|
-
import { isDeepStrictEqual } from "util";
|
|
89
81
|
import { z } from "zod";
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
path: CLAUDE_MCP_PATH,
|
|
102
|
-
key: "mcpServers",
|
|
103
|
-
label: "Claude Code"
|
|
104
|
-
};
|
|
105
|
-
var OpenCodeConfigOwnershipSchema = z.object({
|
|
106
|
-
createdFile: z.boolean(),
|
|
107
|
-
addedMcp: z.boolean(),
|
|
108
|
-
addedSchema: z.boolean(),
|
|
109
|
-
entries: z.record(ObjectSchema)
|
|
82
|
+
var MANIFEST_FILENAME = ".harness-manifest.json";
|
|
83
|
+
var MANIFEST_VERSION = "6";
|
|
84
|
+
var ManifestSchema = z.object({
|
|
85
|
+
version: z.enum(["4", "5", MANIFEST_VERSION]),
|
|
86
|
+
engines: z.array(z.string()),
|
|
87
|
+
renderedAt: z.string(),
|
|
88
|
+
files: z.array(z.string()),
|
|
89
|
+
harnessVersion: z.string().optional(),
|
|
90
|
+
overridesDir: z.string().optional(),
|
|
91
|
+
fileHashes: z.record(z.string().regex(/^[a-f0-9]{64}$/)).optional(),
|
|
92
|
+
preservedFiles: z.array(z.string()).optional()
|
|
110
93
|
});
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
const config = ObjectSchema.parse(JSON.parse(content));
|
|
114
|
-
if (Object.hasOwn(config, target.key)) ObjectSchema.parse(config[target.key]);
|
|
115
|
-
return config;
|
|
116
|
-
} catch {
|
|
117
|
-
throw new Error(`invalid ${target.path}: expected a JSON object with an MCP object`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function removeOwnedEntries(target, config, ownership, warnings) {
|
|
121
|
-
if (Object.hasOwn(config, target.key)) {
|
|
122
|
-
const mcp = ObjectSchema.parse(config[target.key]);
|
|
123
|
-
for (const [id, installed] of Object.entries(ownership.entries)) {
|
|
124
|
-
if (!Object.hasOwn(mcp, id)) continue;
|
|
125
|
-
if (isDeepStrictEqual(mcp[id], installed)) delete mcp[id];
|
|
126
|
-
else warnings.push(`preserved modified ${target.label} MCP server: ${id}`);
|
|
127
|
-
}
|
|
128
|
-
config[target.key] = mcp;
|
|
129
|
-
if (ownership.addedMcp && Object.keys(mcp).length === 0)
|
|
130
|
-
Reflect.deleteProperty(config, target.key);
|
|
131
|
-
}
|
|
132
|
-
if (target.schema && ownership.addedSchema && config.$schema === target.schema)
|
|
133
|
-
Reflect.deleteProperty(config, "$schema");
|
|
134
|
-
}
|
|
135
|
-
function addMissingEntries(target, config, desired, createdFile, warnings) {
|
|
136
|
-
const requested = ObjectSchema.parse(parseConfig(target, desired.content)[target.key]);
|
|
137
|
-
const mcp = ObjectSchema.parse(config[target.key] ?? {});
|
|
138
|
-
const entries = {};
|
|
139
|
-
for (const [id, entry] of Object.entries(requested)) {
|
|
140
|
-
if (Object.hasOwn(mcp, id)) {
|
|
141
|
-
if (!isDeepStrictEqual(mcp[id], entry)) {
|
|
142
|
-
warnings.push(
|
|
143
|
-
`preserved existing ${target.label} MCP server instead of replacing it: ${id}`
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
entries[id] = ObjectSchema.parse(entry);
|
|
149
|
-
mcp[id] = entry;
|
|
150
|
-
}
|
|
151
|
-
if (Object.keys(entries).length === 0) return void 0;
|
|
152
|
-
const ownership = {
|
|
153
|
-
createdFile,
|
|
154
|
-
addedMcp: !Object.hasOwn(config, target.key),
|
|
155
|
-
addedSchema: target.schema !== void 0 && !Object.hasOwn(config, "$schema"),
|
|
156
|
-
entries
|
|
157
|
-
};
|
|
158
|
-
config[target.key] = mcp;
|
|
159
|
-
if (target.schema && ownership.addedSchema) config.$schema = target.schema;
|
|
160
|
-
return ownership;
|
|
161
|
-
}
|
|
162
|
-
function planMcpJson(target, root, desired, previous) {
|
|
163
|
-
const warnings = [];
|
|
164
|
-
if (!desired && !previous) return { remove: false, warnings };
|
|
165
|
-
const path = join2(root, target.path);
|
|
166
|
-
const existed = existsSync(path);
|
|
167
|
-
if (!existed && !desired) return { remove: false, warnings };
|
|
168
|
-
const original = existed ? readFileSync(path, "utf8") : void 0;
|
|
169
|
-
const config = original === void 0 ? {} : parseConfig(target, original);
|
|
170
|
-
const before = structuredClone(config);
|
|
171
|
-
if (previous) removeOwnedEntries(target, config, previous, warnings);
|
|
172
|
-
const createdFile = !existed || previous?.createdFile === true;
|
|
173
|
-
const ownership = desired ? addMissingEntries(target, config, desired, createdFile, warnings) : void 0;
|
|
174
|
-
if (!ownership && createdFile && Object.keys(config).length === 0) {
|
|
175
|
-
return { remove: existed, warnings };
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
remove: false,
|
|
179
|
-
ownership,
|
|
180
|
-
warnings,
|
|
181
|
-
...!existed || !isDeepStrictEqual(before, config) ? { write: { path: target.path, content: `${JSON.stringify(config, null, 2)}
|
|
182
|
-
` } } : {}
|
|
183
|
-
};
|
|
94
|
+
function manifestPath(targetDir) {
|
|
95
|
+
return join2(targetDir, MANIFEST_FILENAME);
|
|
184
96
|
}
|
|
185
|
-
function
|
|
186
|
-
return
|
|
97
|
+
function hashContent(content) {
|
|
98
|
+
return createHash("sha256").update(content).digest("hex");
|
|
187
99
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
100
|
+
function readManifest(targetDir) {
|
|
101
|
+
assertManagedPaths(targetDir, [MANIFEST_FILENAME]);
|
|
102
|
+
const path = manifestPath(targetDir);
|
|
103
|
+
if (!existsSync(path)) return null;
|
|
104
|
+
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
105
|
+
return ManifestSchema.parse(raw);
|
|
190
106
|
}
|
|
191
107
|
|
|
192
|
-
// src/cli/
|
|
193
|
-
import { existsSync as
|
|
108
|
+
// src/cli/plan-render.ts
|
|
109
|
+
import { existsSync as existsSync3 } from "fs";
|
|
110
|
+
import { dirname as dirname2, join as join4, resolve as resolve2 } from "path";
|
|
111
|
+
import { fileURLToPath } from "url";
|
|
112
|
+
|
|
113
|
+
// src/loader.ts
|
|
114
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
|
|
194
115
|
import { join as join3 } from "path";
|
|
195
|
-
import
|
|
196
|
-
import { z as
|
|
116
|
+
import fg from "fast-glob";
|
|
117
|
+
import { z as z3 } from "zod";
|
|
197
118
|
|
|
198
|
-
// src/
|
|
199
|
-
import {
|
|
119
|
+
// src/parser/common.ts
|
|
120
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
121
|
+
import matter from "gray-matter";
|
|
122
|
+
|
|
123
|
+
// src/parser/schemas.ts
|
|
124
|
+
import { z as z2 } from "zod";
|
|
200
125
|
|
|
201
126
|
// src/types.ts
|
|
202
|
-
var AGENT_IDS = ["coding", "review", "merge", "planning"];
|
|
203
127
|
var ENGINES = ["claude-code", "codex-cli", "opencode"];
|
|
204
128
|
var CAPABILITIES = ["multi-step", "slash-command", "inline-exec"];
|
|
205
129
|
var CAPABILITIES_MATRIX = {
|
|
@@ -211,8 +135,122 @@ var DEGRADED_CAPABILITIES = {
|
|
|
211
135
|
"codex-cli": ["multi-step"]
|
|
212
136
|
};
|
|
213
137
|
|
|
138
|
+
// src/parser/schemas.ts
|
|
139
|
+
var IdSchema = z2.string().min(1).regex(/^[a-z][a-z0-9-]*$/, "id must be kebab-case (lowercase + digits + hyphens)");
|
|
140
|
+
var SkillFrontmatterSchema = z2.object({
|
|
141
|
+
id: IdSchema,
|
|
142
|
+
description: z2.string().min(1),
|
|
143
|
+
engines: z2.array(z2.enum(ENGINES)).min(1).optional(),
|
|
144
|
+
requires: z2.array(z2.enum(CAPABILITIES)).optional(),
|
|
145
|
+
tags: z2.array(z2.string()).optional()
|
|
146
|
+
}).strict();
|
|
147
|
+
var CmdArgEnumSchema = z2.object({
|
|
148
|
+
name: z2.string().min(1),
|
|
149
|
+
type: z2.literal("enum"),
|
|
150
|
+
values: z2.array(z2.string()).min(1),
|
|
151
|
+
default: z2.string().optional()
|
|
152
|
+
}).strict();
|
|
153
|
+
var CmdArgStringSchema = z2.object({
|
|
154
|
+
name: z2.string().min(1),
|
|
155
|
+
type: z2.literal("string"),
|
|
156
|
+
default: z2.string().optional()
|
|
157
|
+
}).strict();
|
|
158
|
+
var CmdArgSchema = z2.discriminatedUnion("type", [CmdArgEnumSchema, CmdArgStringSchema]);
|
|
159
|
+
var CmdFrontmatterSchema = z2.object({
|
|
160
|
+
id: IdSchema,
|
|
161
|
+
trigger: z2.string().regex(/^\/[a-z][a-z0-9-]*$/, "trigger must be /kebab-case"),
|
|
162
|
+
invokes_skill: IdSchema,
|
|
163
|
+
args: z2.array(CmdArgSchema).optional(),
|
|
164
|
+
description: z2.string().min(1)
|
|
165
|
+
}).strict();
|
|
166
|
+
var Schemas = {
|
|
167
|
+
Skill: SkillFrontmatterSchema,
|
|
168
|
+
Cmd: CmdFrontmatterSchema
|
|
169
|
+
};
|
|
170
|
+
var ParseError = class extends Error {
|
|
171
|
+
constructor(file, issues) {
|
|
172
|
+
const messages = issues.map((i) => ` - ${i.path.join(".") || "<root>"}: ${i.message}`).join("\n");
|
|
173
|
+
super(`Frontmatter validation failed for ${file}:
|
|
174
|
+
${messages}`);
|
|
175
|
+
this.file = file;
|
|
176
|
+
this.issues = issues;
|
|
177
|
+
this.name = "ParseError";
|
|
178
|
+
}
|
|
179
|
+
file;
|
|
180
|
+
issues;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/parser/common.ts
|
|
184
|
+
function parseWithSchema(filePath, source, schema) {
|
|
185
|
+
const parsed = matter(source);
|
|
186
|
+
const result = schema.safeParse(parsed.data);
|
|
187
|
+
if (!result.success) {
|
|
188
|
+
throw new ParseError(filePath, result.error.issues);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
meta: result.data,
|
|
192
|
+
body: parsed.content.trim(),
|
|
193
|
+
sourcePath: filePath
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/parser/cmd.ts
|
|
198
|
+
function parseCmd(filePath, source) {
|
|
199
|
+
return parseWithSchema(filePath, source, Schemas.Cmd);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/parser/skill.ts
|
|
203
|
+
function parseSkill(filePath, source) {
|
|
204
|
+
return parseWithSchema(filePath, source, Schemas.Skill);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/util/yaml.ts
|
|
208
|
+
import { parse as yamlParse } from "yaml";
|
|
209
|
+
function parseYAML(source) {
|
|
210
|
+
return yamlParse(source);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/loader.ts
|
|
214
|
+
var DisableYamlSchema = z3.object({ disable: z3.array(z3.string()).optional() }).passthrough();
|
|
215
|
+
function loadHarness(packageDir, opts = {}) {
|
|
216
|
+
const skillsDir = opts.skillsDir ?? join3(packageDir, "skills");
|
|
217
|
+
const commandsDir = opts.commandsDir ?? join3(packageDir, "commands");
|
|
218
|
+
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
219
|
+
const cmdFiles = fg.sync("*.cmd.md", { cwd: commandsDir, absolute: true });
|
|
220
|
+
return {
|
|
221
|
+
skills: skillFiles.map((f) => parseSkill(f, readFileSync3(f, "utf8"))),
|
|
222
|
+
cmds: cmdFiles.map((f) => parseCmd(f, readFileSync3(f, "utf8")))
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function loadProjectSkills(targetDir) {
|
|
226
|
+
const skillsDir = join3(targetDir, "docs", "skills");
|
|
227
|
+
if (!existsSync2(skillsDir)) return [];
|
|
228
|
+
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
229
|
+
return skillFiles.map((f) => parseSkill(f, readFileSync3(f, "utf8")));
|
|
230
|
+
}
|
|
231
|
+
function loadOverrides(worktreeDir) {
|
|
232
|
+
const overridesDir = join3(worktreeDir, ".harness-overrides");
|
|
233
|
+
if (!existsSync2(overridesDir)) return void 0;
|
|
234
|
+
const added = loadHarness(overridesDir, {
|
|
235
|
+
skillsDir: join3(overridesDir, "skills"),
|
|
236
|
+
commandsDir: join3(overridesDir, "commands")
|
|
237
|
+
});
|
|
238
|
+
const disablePath = join3(overridesDir, "disable.yaml");
|
|
239
|
+
let disable = [];
|
|
240
|
+
if (existsSync2(disablePath)) {
|
|
241
|
+
try {
|
|
242
|
+
const parsed = DisableYamlSchema.safeParse(parseYAML(readFileSync3(disablePath, "utf8")));
|
|
243
|
+
if (parsed.success && parsed.data.disable) {
|
|
244
|
+
disable = parsed.data.disable;
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { add: added, disable };
|
|
250
|
+
}
|
|
251
|
+
|
|
214
252
|
// src/renderers/common.ts
|
|
215
|
-
|
|
253
|
+
import { stringify as yamlStringify } from "yaml";
|
|
216
254
|
function checkSkillCapabilities(skill, engine) {
|
|
217
255
|
const blockingWarnings = [];
|
|
218
256
|
const degradedWarnings = [];
|
|
@@ -243,39 +281,6 @@ ${rendered}
|
|
|
243
281
|
---
|
|
244
282
|
`;
|
|
245
283
|
}
|
|
246
|
-
var SCALAR_NEEDS_QUOTE = /[^a-zA-Z0-9_./-]/;
|
|
247
|
-
function tomlEscapeString(s) {
|
|
248
|
-
return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
|
|
249
|
-
}
|
|
250
|
-
function tomlValue(v) {
|
|
251
|
-
if (Array.isArray(v)) {
|
|
252
|
-
return `[${v.map((x) => tomlValue(x)).join(", ")}]`;
|
|
253
|
-
}
|
|
254
|
-
if (typeof v === "string") {
|
|
255
|
-
if (v.includes("\n")) return tomlEscapeString(v);
|
|
256
|
-
return SCALAR_NEEDS_QUOTE.test(v) ? tomlEscapeString(v) : `"${v}"`;
|
|
257
|
-
}
|
|
258
|
-
if (typeof v === "boolean" || typeof v === "number") {
|
|
259
|
-
return String(v);
|
|
260
|
-
}
|
|
261
|
-
return tomlEscapeString(String(v));
|
|
262
|
-
}
|
|
263
|
-
function tomlMultilineString(s) {
|
|
264
|
-
const escaped = s.replace(/\\/g, "\\\\").replace(/"""/g, '""\\"');
|
|
265
|
-
return `"""
|
|
266
|
-
${escaped}
|
|
267
|
-
"""`;
|
|
268
|
-
}
|
|
269
|
-
function tomlQuoteString(s) {
|
|
270
|
-
return tomlValue(s);
|
|
271
|
-
}
|
|
272
|
-
function tomlInlineArray(items) {
|
|
273
|
-
return tomlValue([...items]);
|
|
274
|
-
}
|
|
275
|
-
function tomlInlineTable(table) {
|
|
276
|
-
const entries = Object.entries(table).map(([k, v]) => `${k} = ${tomlValue(v)}`);
|
|
277
|
-
return `{ ${entries.join(", ")} }`;
|
|
278
|
-
}
|
|
279
284
|
function frontmatterDataForSkill(skill) {
|
|
280
285
|
const data = {
|
|
281
286
|
name: skill.meta.id,
|
|
@@ -300,11 +305,7 @@ function frontmatterDataForCmd(cmd) {
|
|
|
300
305
|
}
|
|
301
306
|
return data;
|
|
302
307
|
}
|
|
303
|
-
function
|
|
304
|
-
return `${agent.body.trim()}
|
|
305
|
-
`;
|
|
306
|
-
}
|
|
307
|
-
function buildUmbrellaBody(_agents, extras) {
|
|
308
|
+
function buildUmbrellaBody(extras) {
|
|
308
309
|
const triggerBySkill = new Map(
|
|
309
310
|
extras.availableCommands.map((c) => [c.meta.invokes_skill, c.meta.trigger])
|
|
310
311
|
);
|
|
@@ -325,7 +326,7 @@ function buildUmbrellaBody(_agents, extras) {
|
|
|
325
326
|
"- `docs/handbook/<feature>.md` \u2014 *how it actually works* today.",
|
|
326
327
|
"- `docs/decisions/<slug>.md` \u2014 ADRs: structural choices and rejected alternatives.",
|
|
327
328
|
"- `docs/tests/integration-tests.md` & `e2e-tests.md` \u2014 core scenarios.",
|
|
328
|
-
"- `docs/workflow/coding-workflow.md` \u2014 CI, branches, PR, release.",
|
|
329
|
+
"- `docs/workflow/coding-workflow.md` \u2014 CI, branches, PR, release. How this team works: follow it.",
|
|
329
330
|
...extras.hasProjectSkills ? ["- `docs/skills/*.skill.md` \u2014 the project's domain skills."] : [],
|
|
330
331
|
...extras.hasQualityDoc ? [
|
|
331
332
|
"- `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."
|
|
@@ -338,7 +339,13 @@ function buildUmbrellaBody(_agents, extras) {
|
|
|
338
339
|
"- Missing spec for a subsystem you touch \u2192 **do not code**, report the gap.",
|
|
339
340
|
"- Implicit structural decision in your changes \u2192 an ADR (`/decision`).",
|
|
340
341
|
"- Changed feature behavior \u2192 update the matching handbook (`/handbook`).",
|
|
341
|
-
"- Suspected code \u2194 doc drift \u2192 `/drift` before moving on."
|
|
342
|
+
"- Suspected code \u2194 doc drift \u2192 `/drift` before moving on.",
|
|
343
|
+
"",
|
|
344
|
+
"## Checks",
|
|
345
|
+
"",
|
|
346
|
+
"Run `npx @vaubaan/harness lint` before you commit; CI runs the same linters on every pull request. Fix what it reports with the skill it suggests.",
|
|
347
|
+
"",
|
|
348
|
+
"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."
|
|
342
349
|
];
|
|
343
350
|
if (skillLines.length > 0) {
|
|
344
351
|
sections.push("", "## Doc-skills", "", skillLines.join("\n"));
|
|
@@ -379,60 +386,11 @@ ${cmd.body}
|
|
|
379
386
|
files: [{ path: `${BASE}/commands/${cmd.meta.id}.md`, content }],
|
|
380
387
|
warnings: []
|
|
381
388
|
};
|
|
382
|
-
},
|
|
383
|
-
renderAgents(agents) {
|
|
384
|
-
const files = [];
|
|
385
|
-
for (const agent of agents) {
|
|
386
|
-
const subagentFrontmatter = yamlFrontmatter({
|
|
387
|
-
name: agent.meta.id,
|
|
388
|
-
description: agent.meta.description
|
|
389
|
-
});
|
|
390
|
-
const body = buildAgentBody(agent);
|
|
391
|
-
const content = `${subagentFrontmatter}
|
|
392
|
-
${body}`;
|
|
393
|
-
files.push({ path: `${BASE}/agents/${agent.meta.id}.md`, content });
|
|
394
|
-
}
|
|
395
|
-
return { files, warnings: [] };
|
|
396
|
-
},
|
|
397
|
-
renderMcp(servers) {
|
|
398
|
-
if (servers.length === 0) return { files: [], warnings: [] };
|
|
399
|
-
const mcpServers = {};
|
|
400
|
-
for (const s of servers) {
|
|
401
|
-
const entry = { command: s.command, args: [...s.args] };
|
|
402
|
-
if (s.env) entry.env = s.env;
|
|
403
|
-
mcpServers[s.id] = entry;
|
|
404
|
-
}
|
|
405
|
-
const content = `${JSON.stringify({ mcpServers }, null, 2)}
|
|
406
|
-
`;
|
|
407
|
-
return { files: [{ path: ".mcp.json", content }], warnings: [] };
|
|
408
|
-
},
|
|
409
|
-
renderStopHook() {
|
|
410
|
-
const settings = {
|
|
411
|
-
hooks: {
|
|
412
|
-
Stop: [
|
|
413
|
-
{
|
|
414
|
-
matcher: "",
|
|
415
|
-
hooks: [
|
|
416
|
-
{
|
|
417
|
-
type: "command",
|
|
418
|
-
command: `npx -y ${STOP_HOOK_PACKAGE} stop-hook --engine claude`
|
|
419
|
-
}
|
|
420
|
-
]
|
|
421
|
-
}
|
|
422
|
-
]
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
return {
|
|
426
|
-
files: [{ path: `${BASE}/settings.json`, content: `${JSON.stringify(settings, null, 2)}
|
|
427
|
-
` }],
|
|
428
|
-
warnings: []
|
|
429
|
-
};
|
|
430
389
|
}
|
|
431
390
|
};
|
|
432
391
|
|
|
433
392
|
// src/renderers/codex-cli.ts
|
|
434
393
|
var ENGINE2 = "codex-cli";
|
|
435
|
-
var BASE2 = ".codex";
|
|
436
394
|
var SKILLS_BASE = ".agents/skills";
|
|
437
395
|
var codexCliRenderer = {
|
|
438
396
|
engine: ENGINE2,
|
|
@@ -458,62 +416,12 @@ ${skill.body}
|
|
|
458
416
|
// Codex custom prompts are deprecated in favour of skills: nothing to render.
|
|
459
417
|
renderCmd(_cmd) {
|
|
460
418
|
return { files: [], warnings: [] };
|
|
461
|
-
},
|
|
462
|
-
renderAgents(agents) {
|
|
463
|
-
const files = [];
|
|
464
|
-
for (const agent of agents) {
|
|
465
|
-
const content = [
|
|
466
|
-
`name = ${tomlQuoteString(agent.meta.id)}`,
|
|
467
|
-
`description = ${tomlQuoteString(agent.meta.description)}`,
|
|
468
|
-
`developer_instructions = ${tomlMultilineString(buildAgentBody(agent).trimEnd())}`,
|
|
469
|
-
""
|
|
470
|
-
].join("\n");
|
|
471
|
-
files.push({ path: `${BASE2}/agents/${agent.meta.id}.toml`, content });
|
|
472
|
-
}
|
|
473
|
-
return { files, warnings: [] };
|
|
474
|
-
},
|
|
475
|
-
renderMcp(servers) {
|
|
476
|
-
if (servers.length === 0) return { files: [], warnings: [] };
|
|
477
|
-
const blocks = [];
|
|
478
|
-
for (const s of servers) {
|
|
479
|
-
const lines = [
|
|
480
|
-
`[mcp_servers.${s.id}]`,
|
|
481
|
-
`command = ${tomlQuoteString(s.command)}`,
|
|
482
|
-
`args = ${tomlInlineArray([...s.args])}`
|
|
483
|
-
];
|
|
484
|
-
if (s.env) lines.push(`env = ${tomlInlineTable(s.env)}`);
|
|
485
|
-
blocks.push(lines.join("\n"));
|
|
486
|
-
}
|
|
487
|
-
const content = `${blocks.join("\n\n")}
|
|
488
|
-
`;
|
|
489
|
-
return { files: [{ path: `${BASE2}/config.toml`, content }], warnings: [] };
|
|
490
|
-
},
|
|
491
|
-
renderStopHook() {
|
|
492
|
-
const hooks = {
|
|
493
|
-
hooks: {
|
|
494
|
-
Stop: [
|
|
495
|
-
{
|
|
496
|
-
hooks: [
|
|
497
|
-
{
|
|
498
|
-
type: "command",
|
|
499
|
-
command: `npx -y ${STOP_HOOK_PACKAGE} stop-hook --engine codex`
|
|
500
|
-
}
|
|
501
|
-
]
|
|
502
|
-
}
|
|
503
|
-
]
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
return {
|
|
507
|
-
files: [{ path: `${BASE2}/hooks.json`, content: `${JSON.stringify(hooks, null, 2)}
|
|
508
|
-
` }],
|
|
509
|
-
warnings: []
|
|
510
|
-
};
|
|
511
419
|
}
|
|
512
420
|
};
|
|
513
421
|
|
|
514
422
|
// src/renderers/opencode.ts
|
|
515
423
|
var ENGINE3 = "opencode";
|
|
516
|
-
var
|
|
424
|
+
var BASE2 = ".opencode";
|
|
517
425
|
var opencodeRenderer = {
|
|
518
426
|
engine: ENGINE3,
|
|
519
427
|
renderSkill(skill) {
|
|
@@ -531,7 +439,7 @@ var opencodeRenderer = {
|
|
|
531
439
|
${skill.body}
|
|
532
440
|
`;
|
|
533
441
|
return {
|
|
534
|
-
files: [{ path: `${
|
|
442
|
+
files: [{ path: `${BASE2}/skills/${skill.meta.id}/SKILL.md`, content }],
|
|
535
443
|
warnings: check.degradedWarnings
|
|
536
444
|
};
|
|
537
445
|
},
|
|
@@ -540,106 +448,7 @@ ${skill.body}
|
|
|
540
448
|
${cmd.body}
|
|
541
449
|
`;
|
|
542
450
|
return {
|
|
543
|
-
files: [{ path: `${
|
|
544
|
-
warnings: []
|
|
545
|
-
};
|
|
546
|
-
},
|
|
547
|
-
renderAgents(agents) {
|
|
548
|
-
const files = [];
|
|
549
|
-
for (const agent of agents) {
|
|
550
|
-
const fm = yamlFrontmatter({
|
|
551
|
-
description: agent.meta.description,
|
|
552
|
-
mode: "all"
|
|
553
|
-
});
|
|
554
|
-
const body = buildAgentBody(agent);
|
|
555
|
-
files.push({ path: `${BASE3}/agents/${agent.meta.id}.md`, content: `${fm}
|
|
556
|
-
${body}` });
|
|
557
|
-
}
|
|
558
|
-
return { files, warnings: [] };
|
|
559
|
-
},
|
|
560
|
-
renderMcp(servers) {
|
|
561
|
-
if (servers.length === 0) return { files: [], warnings: [] };
|
|
562
|
-
const mcp = {};
|
|
563
|
-
for (const s of servers) {
|
|
564
|
-
const entry = {
|
|
565
|
-
type: "local",
|
|
566
|
-
command: [s.command, ...s.args],
|
|
567
|
-
enabled: true
|
|
568
|
-
};
|
|
569
|
-
if (s.env) entry.environment = s.env;
|
|
570
|
-
mcp[s.id] = entry;
|
|
571
|
-
}
|
|
572
|
-
const config = { $schema: "https://opencode.ai/config.json", mcp };
|
|
573
|
-
const content = `${JSON.stringify(config, null, 2)}
|
|
574
|
-
`;
|
|
575
|
-
return { files: [{ path: `${BASE3}/opencode.json`, content }], warnings: [] };
|
|
576
|
-
},
|
|
577
|
-
renderStopHook() {
|
|
578
|
-
const content = `import { spawnSync } from "node:child_process";
|
|
579
|
-
|
|
580
|
-
// Runs the harness lint and returns the report to inject, or "" when the
|
|
581
|
-
// turn may end.
|
|
582
|
-
const lintReport = (directory, sessionID) => {
|
|
583
|
-
const r = spawnSync(
|
|
584
|
-
"npx",
|
|
585
|
-
["-y", "${STOP_HOOK_PACKAGE}", "stop-hook", "--engine", "opencode", "--cwd", directory],
|
|
586
|
-
{ input: JSON.stringify({ sessionID }), encoding: "utf-8" },
|
|
587
|
-
);
|
|
588
|
-
const report = (r.stderr ?? "").trim();
|
|
589
|
-
return r.status === 2 ? report : "";
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
// OpenCode 1.x entry point, exposed as server() below.
|
|
593
|
-
const HarnessStopHook = async ({ client, directory }) => ({
|
|
594
|
-
event: async ({ event }) => {
|
|
595
|
-
if (event.type !== "session.idle") return;
|
|
596
|
-
const sessionID = event.properties?.sessionID;
|
|
597
|
-
if (!sessionID) return;
|
|
598
|
-
const report = lintReport(directory, sessionID);
|
|
599
|
-
if (report === "") return;
|
|
600
|
-
// OpenCode defaults to its build agent when a prompt omits agent.
|
|
601
|
-
// Preserve the last conversation persona, excluding compaction summaries.
|
|
602
|
-
const history = await client.session.messages({ path: { id: sessionID } }).catch(() => undefined);
|
|
603
|
-
if (history?.error || !Array.isArray(history?.data)) return;
|
|
604
|
-
const current = history.data.findLast(({ info }) =>
|
|
605
|
-
(info.role === "user" || (info.role === "assistant" && !info.summary)) &&
|
|
606
|
-
typeof info.agent === "string" && info.agent.trim() !== "",
|
|
607
|
-
);
|
|
608
|
-
if (!current) return;
|
|
609
|
-
await client.session.prompt({
|
|
610
|
-
path: { id: sessionID },
|
|
611
|
-
body: { agent: current.info.agent, parts: [{ type: "text", text: report }] },
|
|
612
|
-
});
|
|
613
|
-
},
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
// One default export for both majors: OpenCode 1.x calls server(),
|
|
617
|
-
// OpenCode 2.x calls setup(). A V2 session keeps its agent, so the report
|
|
618
|
-
// is sent without naming the persona.
|
|
619
|
-
export default {
|
|
620
|
-
id: "vaubaan-harness-stop-hook",
|
|
621
|
-
server: HarnessStopHook,
|
|
622
|
-
setup(context) {
|
|
623
|
-
const directory = context.location.directory;
|
|
624
|
-
const controller = new AbortController();
|
|
625
|
-
const listen = async () => {
|
|
626
|
-
for await (const event of context.event.subscribe({ signal: controller.signal })) {
|
|
627
|
-
if (event.type !== "session.idle") continue;
|
|
628
|
-
if (event.location?.directory && event.location.directory !== directory) continue;
|
|
629
|
-
const sessionID = event.data?.sessionID;
|
|
630
|
-
if (!sessionID) continue;
|
|
631
|
-
const report = lintReport(directory, sessionID);
|
|
632
|
-
if (report === "") continue;
|
|
633
|
-
await context.session.prompt({ sessionID, text: report }).catch(() => undefined);
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
listen().catch(() => undefined);
|
|
637
|
-
return () => controller.abort();
|
|
638
|
-
},
|
|
639
|
-
};
|
|
640
|
-
`;
|
|
641
|
-
return {
|
|
642
|
-
files: [{ path: `${BASE3}/plugins/harness-stop-hook.ts`, content }],
|
|
451
|
+
files: [{ path: `${BASE2}/commands/${cmd.meta.id}.md`, content }],
|
|
643
452
|
warnings: []
|
|
644
453
|
};
|
|
645
454
|
}
|
|
@@ -655,450 +464,6 @@ function getRenderer(engine) {
|
|
|
655
464
|
return RENDERERS[engine];
|
|
656
465
|
}
|
|
657
466
|
|
|
658
|
-
// src/cli/update-config.ts
|
|
659
|
-
var LEGACY_OPENCODE_CONFIG = ".opencode/mcp.json";
|
|
660
|
-
var SHARED_CONFIG_PATHS = [
|
|
661
|
-
".mcp.json",
|
|
662
|
-
".codex/config.toml",
|
|
663
|
-
OPENCODE_CONFIG_PATH,
|
|
664
|
-
LEGACY_OPENCODE_CONFIG,
|
|
665
|
-
".claude/settings.json",
|
|
666
|
-
".codex/hooks.json"
|
|
667
|
-
];
|
|
668
|
-
var ObjectSchema2 = z2.record(z2.unknown());
|
|
669
|
-
var HookEntrySchema = z2.object({ group: ObjectSchema2, hook: ObjectSchema2 });
|
|
670
|
-
var HookConfigOwnershipSchema = z2.object({
|
|
671
|
-
createdFile: z2.boolean(),
|
|
672
|
-
addedHooks: z2.boolean(),
|
|
673
|
-
addedStop: z2.boolean(),
|
|
674
|
-
entries: z2.array(HookEntrySchema)
|
|
675
|
-
});
|
|
676
|
-
var HookConfigsOwnershipSchema = z2.object({
|
|
677
|
-
".claude/settings.json": HookConfigOwnershipSchema.optional(),
|
|
678
|
-
".codex/hooks.json": HookConfigOwnershipSchema.optional()
|
|
679
|
-
}).strict();
|
|
680
|
-
var HOOK_ENGINES = {
|
|
681
|
-
".claude/settings.json": "claude-code",
|
|
682
|
-
".codex/hooks.json": "codex-cli"
|
|
683
|
-
};
|
|
684
|
-
function parseObject(content, path) {
|
|
685
|
-
try {
|
|
686
|
-
return ObjectSchema2.parse(JSON.parse(content));
|
|
687
|
-
} catch {
|
|
688
|
-
throw new Error(`invalid shared configuration ${path}: expected a JSON object`);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
function asObject(value) {
|
|
692
|
-
const parsed = ObjectSchema2.safeParse(value);
|
|
693
|
-
return parsed.success ? parsed.data : void 0;
|
|
694
|
-
}
|
|
695
|
-
function stopHooks(config, path) {
|
|
696
|
-
if (!Object.hasOwn(config, "hooks")) return [];
|
|
697
|
-
const hooks = asObject(config.hooks);
|
|
698
|
-
if (!hooks || Object.hasOwn(hooks, "Stop") && !Array.isArray(hooks.Stop)) {
|
|
699
|
-
throw new Error(`invalid shared configuration ${path}: expected hooks.Stop to be an array`);
|
|
700
|
-
}
|
|
701
|
-
return Array.isArray(hooks.Stop) ? hooks.Stop : [];
|
|
702
|
-
}
|
|
703
|
-
function groupMetadata(group) {
|
|
704
|
-
return Object.fromEntries(Object.entries(group).filter(([key]) => key !== "hooks"));
|
|
705
|
-
}
|
|
706
|
-
function sameEntry(left, right) {
|
|
707
|
-
return isDeepStrictEqual2(left.group, right.group) && isDeepStrictEqual2(left.hook, right.hook);
|
|
708
|
-
}
|
|
709
|
-
function appendEntry(entries, entry) {
|
|
710
|
-
if (!entries.some((existing) => sameEntry(existing, entry))) entries.push(entry);
|
|
711
|
-
}
|
|
712
|
-
function defaultStopGroup(engine) {
|
|
713
|
-
const file = getRenderer(engine).renderStopHook().files[0];
|
|
714
|
-
if (!file) throw new Error(`missing Stop hook renderer for ${engine}`);
|
|
715
|
-
const group = asObject(stopHooks(parseObject(file.content, file.path), file.path)[0]);
|
|
716
|
-
if (!group || !Array.isArray(group.hooks) || !asObject(group.hooks[0])) {
|
|
717
|
-
throw new Error(`invalid Stop hook renderer for ${engine}`);
|
|
718
|
-
}
|
|
719
|
-
return group;
|
|
720
|
-
}
|
|
721
|
-
function normalizeHarnessHooks(groups, expected, previous, claimExisting, warnings, path) {
|
|
722
|
-
const defaultHook = ObjectSchema2.parse(expected.hooks[0]);
|
|
723
|
-
const entries = [...previous?.entries ?? []];
|
|
724
|
-
let found = false;
|
|
725
|
-
const normalized = groups.map((value) => {
|
|
726
|
-
const group = asObject(value);
|
|
727
|
-
if (!group) return value;
|
|
728
|
-
const flat = group.type === "command" && group.command === defaultHook.command;
|
|
729
|
-
const hooks = flat ? [group] : Array.isArray(group.hooks) ? group.hooks : [];
|
|
730
|
-
const metadata = flat ? groupMetadata(expected) : groupMetadata(group);
|
|
731
|
-
for (const value2 of hooks) {
|
|
732
|
-
const hook = asObject(value2);
|
|
733
|
-
if (!hook || hook.type !== "command" || hook.command !== defaultHook.command) continue;
|
|
734
|
-
found = true;
|
|
735
|
-
const entry = { group: metadata, hook };
|
|
736
|
-
if (!claimExisting) continue;
|
|
737
|
-
if (previous && !previous.entries.some((old) => sameEntry(old, entry))) {
|
|
738
|
-
warnings.push(`preserved modified harness Stop hook: ${path}`);
|
|
739
|
-
} else {
|
|
740
|
-
appendEntry(entries, entry);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
return flat && claimExisting ? { ...metadata, hooks: [group] } : value;
|
|
744
|
-
});
|
|
745
|
-
if (!found && !previous?.entries.length) {
|
|
746
|
-
normalized.push(expected);
|
|
747
|
-
appendEntry(entries, { group: groupMetadata(expected), hook: defaultHook });
|
|
748
|
-
} else if (!found) {
|
|
749
|
-
warnings.push(`preserved removed or modified harness Stop hook: ${path}`);
|
|
750
|
-
}
|
|
751
|
-
return { groups: normalized, entries };
|
|
752
|
-
}
|
|
753
|
-
function removeOwnedHooks(config, ownership, path, warnings) {
|
|
754
|
-
const groups = stopHooks(config, path);
|
|
755
|
-
const remaining = [];
|
|
756
|
-
const matched = /* @__PURE__ */ new Set();
|
|
757
|
-
for (const value of groups) {
|
|
758
|
-
const group = asObject(value);
|
|
759
|
-
if (!group || !Array.isArray(group.hooks)) {
|
|
760
|
-
remaining.push(value);
|
|
761
|
-
continue;
|
|
762
|
-
}
|
|
763
|
-
const metadata = groupMetadata(group);
|
|
764
|
-
const hooks2 = group.hooks.filter((value2) => {
|
|
765
|
-
const hook = asObject(value2);
|
|
766
|
-
const entry = hook && ownership.entries.find((old) => sameEntry(old, { group: metadata, hook }));
|
|
767
|
-
if (entry) matched.add(entry);
|
|
768
|
-
return !entry;
|
|
769
|
-
});
|
|
770
|
-
if (hooks2.length > 0 || hooks2.length === group.hooks.length) {
|
|
771
|
-
remaining.push({ ...group, hooks: hooks2 });
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
if (matched.size < ownership.entries.length) {
|
|
775
|
-
warnings.push(`preserved removed or modified harness Stop hook: ${path}`);
|
|
776
|
-
}
|
|
777
|
-
const hooks = asObject(config.hooks);
|
|
778
|
-
if (!hooks) return;
|
|
779
|
-
if (ownership.addedStop && remaining.length === 0) Reflect.deleteProperty(hooks, "Stop");
|
|
780
|
-
else if (Object.hasOwn(hooks, "Stop")) hooks.Stop = remaining;
|
|
781
|
-
if (ownership.addedHooks && Object.keys(hooks).length === 0)
|
|
782
|
-
Reflect.deleteProperty(config, "hooks");
|
|
783
|
-
else config.hooks = hooks;
|
|
784
|
-
}
|
|
785
|
-
function recordMutation(plan, path, before, after, createdFile) {
|
|
786
|
-
if (createdFile && Object.keys(after).length === 0) {
|
|
787
|
-
if (before) plan.removals.push(path);
|
|
788
|
-
} else if (!isDeepStrictEqual2(before, after)) {
|
|
789
|
-
plan.writes.push({ path, content: `${JSON.stringify(after, null, 2)}
|
|
790
|
-
` });
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
function planHookConfigCleanup(root, ownership) {
|
|
794
|
-
const plan = { writes: [], removals: [], warnings: [] };
|
|
795
|
-
if (!ownership) return plan;
|
|
796
|
-
const validated = HookConfigsOwnershipSchema.parse(ownership);
|
|
797
|
-
assertManagedPaths(root, Object.keys(validated));
|
|
798
|
-
for (const path of Object.keys(HOOK_ENGINES)) {
|
|
799
|
-
const owned = validated[path];
|
|
800
|
-
if (!owned || !existsSync2(join3(root, path))) continue;
|
|
801
|
-
const before = parseObject(readFileSync2(join3(root, path), "utf8"), path);
|
|
802
|
-
const config = structuredClone(before);
|
|
803
|
-
removeOwnedHooks(config, owned, path, plan.warnings);
|
|
804
|
-
recordMutation(plan, path, before, config, owned.createdFile);
|
|
805
|
-
}
|
|
806
|
-
return plan;
|
|
807
|
-
}
|
|
808
|
-
function planActiveHook(root, path, previous, claimExisting, plan) {
|
|
809
|
-
assertManagedPaths(root, [path]);
|
|
810
|
-
const existed = existsSync2(join3(root, path));
|
|
811
|
-
if (!existed && previous?.entries.length) {
|
|
812
|
-
plan.warnings.push(`preserved removed harness Stop hook configuration: ${path}`);
|
|
813
|
-
return previous;
|
|
814
|
-
}
|
|
815
|
-
const before = existed ? parseObject(readFileSync2(join3(root, path), "utf8"), path) : void 0;
|
|
816
|
-
const config = structuredClone(before ?? {});
|
|
817
|
-
const groups = stopHooks(config, path);
|
|
818
|
-
const hooks = asObject(config.hooks) ?? {};
|
|
819
|
-
const normalized = normalizeHarnessHooks(
|
|
820
|
-
groups,
|
|
821
|
-
defaultStopGroup(HOOK_ENGINES[path]),
|
|
822
|
-
previous,
|
|
823
|
-
claimExisting,
|
|
824
|
-
plan.warnings,
|
|
825
|
-
path
|
|
826
|
-
);
|
|
827
|
-
const legacyWholeFile = !previous && claimExisting && existed;
|
|
828
|
-
const ownership = {
|
|
829
|
-
createdFile: !existed || previous?.createdFile === true || legacyWholeFile,
|
|
830
|
-
addedHooks: previous?.addedHooks ?? (legacyWholeFile || !Object.hasOwn(config, "hooks")),
|
|
831
|
-
addedStop: previous?.addedStop ?? (legacyWholeFile || !Object.hasOwn(hooks, "Stop")),
|
|
832
|
-
entries: normalized.entries
|
|
833
|
-
};
|
|
834
|
-
if (!isDeepStrictEqual2(groups, normalized.groups)) {
|
|
835
|
-
config.hooks = { ...hooks, Stop: normalized.groups };
|
|
836
|
-
}
|
|
837
|
-
recordMutation(plan, path, before, config, ownership.createdFile);
|
|
838
|
-
return ownership.entries.length > 0 ? ownership : void 0;
|
|
839
|
-
}
|
|
840
|
-
function planLegacyOpenCode(root, previous, plan) {
|
|
841
|
-
if (!previous.files.includes(LEGACY_OPENCODE_CONFIG)) return;
|
|
842
|
-
const legacyPath = join3(root, LEGACY_OPENCODE_CONFIG);
|
|
843
|
-
if (!existsSync2(legacyPath)) return;
|
|
844
|
-
assertManagedPaths(root, [LEGACY_OPENCODE_CONFIG, OPENCODE_CONFIG_PATH]);
|
|
845
|
-
const legacy = parseObject(readFileSync2(legacyPath, "utf8"), LEGACY_OPENCODE_CONFIG);
|
|
846
|
-
if (!asObject(legacy.mcp)) {
|
|
847
|
-
throw new Error(
|
|
848
|
-
`invalid shared configuration ${LEGACY_OPENCODE_CONFIG}: expected an MCP object`
|
|
849
|
-
);
|
|
850
|
-
}
|
|
851
|
-
const merged = planOpenCodeConfig(
|
|
852
|
-
root,
|
|
853
|
-
{ path: OPENCODE_CONFIG_PATH, content: JSON.stringify(legacy) },
|
|
854
|
-
void 0
|
|
855
|
-
);
|
|
856
|
-
if (merged.write) plan.writes.push(merged.write);
|
|
857
|
-
plan.warnings.push(...merged.warnings);
|
|
858
|
-
if (merged.ownership) {
|
|
859
|
-
const old = previous.opencodeConfig;
|
|
860
|
-
plan.opencodeConfig = {
|
|
861
|
-
createdFile: merged.ownership.createdFile || old?.createdFile === true,
|
|
862
|
-
addedMcp: merged.ownership.addedMcp || old?.addedMcp === true,
|
|
863
|
-
addedSchema: merged.ownership.addedSchema || old?.addedSchema === true,
|
|
864
|
-
entries: { ...old?.entries, ...merged.ownership.entries }
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
plan.removals.push(LEGACY_OPENCODE_CONFIG);
|
|
868
|
-
}
|
|
869
|
-
function planUpdateConfigs(root, previous, hookEngines) {
|
|
870
|
-
const plan = {
|
|
871
|
-
writes: [],
|
|
872
|
-
removals: [],
|
|
873
|
-
ownedFiles: [],
|
|
874
|
-
warnings: [],
|
|
875
|
-
...previous.opencodeConfig ? { opencodeConfig: previous.opencodeConfig } : {}
|
|
876
|
-
};
|
|
877
|
-
planLegacyOpenCode(root, previous, plan);
|
|
878
|
-
const hookConfigs = {};
|
|
879
|
-
for (const path of Object.keys(HOOK_ENGINES)) {
|
|
880
|
-
const owned = previous.hookConfigs?.[path];
|
|
881
|
-
if (hookEngines.includes(HOOK_ENGINES[path])) {
|
|
882
|
-
hookConfigs[path] = planActiveHook(
|
|
883
|
-
root,
|
|
884
|
-
path,
|
|
885
|
-
owned,
|
|
886
|
-
previous.files.includes(path) || Boolean(owned),
|
|
887
|
-
plan
|
|
888
|
-
);
|
|
889
|
-
} else if (owned) {
|
|
890
|
-
const cleanup = planHookConfigCleanup(root, { [path]: owned });
|
|
891
|
-
plan.writes.push(...cleanup.writes);
|
|
892
|
-
plan.removals.push(...cleanup.removals);
|
|
893
|
-
plan.warnings.push(...cleanup.warnings);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
if (Object.values(hookConfigs).some(Boolean)) plan.hookConfigs = hookConfigs;
|
|
897
|
-
if (hookEngines.includes("opencode")) {
|
|
898
|
-
const plugin = getRenderer("opencode").renderStopHook();
|
|
899
|
-
plan.writes.push(...plugin.files);
|
|
900
|
-
plan.ownedFiles.push(...plugin.files.map((file) => file.path));
|
|
901
|
-
plan.warnings.push(...plugin.warnings);
|
|
902
|
-
}
|
|
903
|
-
return plan;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// src/cli/manifest.ts
|
|
907
|
-
var MANIFEST_FILENAME = ".harness-manifest.json";
|
|
908
|
-
var MANIFEST_VERSION = "6";
|
|
909
|
-
var ManifestSchema = z3.object({
|
|
910
|
-
version: z3.enum(["4", "5", MANIFEST_VERSION]),
|
|
911
|
-
engines: z3.array(z3.string()),
|
|
912
|
-
renderedAt: z3.string(),
|
|
913
|
-
files: z3.array(z3.string()),
|
|
914
|
-
stopHookInstalled: z3.boolean().optional(),
|
|
915
|
-
stopHookEngines: z3.array(z3.string()).optional(),
|
|
916
|
-
opencodeConfig: OpenCodeConfigOwnershipSchema.optional(),
|
|
917
|
-
/** Entries the harness added to `.mcp.json` (Claude Code). */
|
|
918
|
-
mcpConfig: OpenCodeConfigOwnershipSchema.optional(),
|
|
919
|
-
hookConfigs: HookConfigsOwnershipSchema.optional(),
|
|
920
|
-
harnessVersion: z3.string().optional(),
|
|
921
|
-
overridesDir: z3.string().optional(),
|
|
922
|
-
fileHashes: z3.record(z3.string().regex(/^[a-f0-9]{64}$/)).optional(),
|
|
923
|
-
preservedFiles: z3.array(z3.string()).optional()
|
|
924
|
-
});
|
|
925
|
-
function manifestPath(targetDir) {
|
|
926
|
-
return join4(targetDir, MANIFEST_FILENAME);
|
|
927
|
-
}
|
|
928
|
-
function hashContent(content) {
|
|
929
|
-
return createHash("sha256").update(content).digest("hex");
|
|
930
|
-
}
|
|
931
|
-
function readManifest(targetDir) {
|
|
932
|
-
assertManagedPaths(targetDir, [MANIFEST_FILENAME]);
|
|
933
|
-
const path = manifestPath(targetDir);
|
|
934
|
-
if (!existsSync3(path)) return null;
|
|
935
|
-
const raw = JSON.parse(readFileSync3(path, "utf8"));
|
|
936
|
-
return ManifestSchema.parse(raw);
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
// src/cli/plan-render.ts
|
|
940
|
-
import { existsSync as existsSync5 } from "fs";
|
|
941
|
-
import { dirname as dirname2, join as join6, resolve as resolve2 } from "path";
|
|
942
|
-
import { fileURLToPath } from "url";
|
|
943
|
-
|
|
944
|
-
// src/loader.ts
|
|
945
|
-
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
946
|
-
import { join as join5 } from "path";
|
|
947
|
-
import fg from "fast-glob";
|
|
948
|
-
import { z as z5 } from "zod";
|
|
949
|
-
|
|
950
|
-
// src/parser/common.ts
|
|
951
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
952
|
-
import matter from "gray-matter";
|
|
953
|
-
|
|
954
|
-
// src/parser/schemas.ts
|
|
955
|
-
import { z as z4 } from "zod";
|
|
956
|
-
var IdSchema = z4.string().min(1).regex(/^[a-z][a-z0-9-]*$/, "id must be kebab-case (lowercase + digits + hyphens)");
|
|
957
|
-
var SkillFrontmatterSchema = z4.object({
|
|
958
|
-
id: IdSchema,
|
|
959
|
-
description: z4.string().min(1),
|
|
960
|
-
engines: z4.array(z4.enum(ENGINES)).min(1).optional(),
|
|
961
|
-
requires: z4.array(z4.enum(CAPABILITIES)).optional(),
|
|
962
|
-
tags: z4.array(z4.string()).optional()
|
|
963
|
-
}).strict();
|
|
964
|
-
var CmdArgEnumSchema = z4.object({
|
|
965
|
-
name: z4.string().min(1),
|
|
966
|
-
type: z4.literal("enum"),
|
|
967
|
-
values: z4.array(z4.string()).min(1),
|
|
968
|
-
default: z4.string().optional()
|
|
969
|
-
}).strict();
|
|
970
|
-
var CmdArgStringSchema = z4.object({
|
|
971
|
-
name: z4.string().min(1),
|
|
972
|
-
type: z4.literal("string"),
|
|
973
|
-
default: z4.string().optional()
|
|
974
|
-
}).strict();
|
|
975
|
-
var CmdArgSchema = z4.discriminatedUnion("type", [CmdArgEnumSchema, CmdArgStringSchema]);
|
|
976
|
-
var CmdFrontmatterSchema = z4.object({
|
|
977
|
-
id: IdSchema,
|
|
978
|
-
trigger: z4.string().regex(/^\/[a-z][a-z0-9-]*$/, "trigger must be /kebab-case"),
|
|
979
|
-
invokes_skill: IdSchema,
|
|
980
|
-
args: z4.array(CmdArgSchema).optional(),
|
|
981
|
-
description: z4.string().min(1)
|
|
982
|
-
}).strict();
|
|
983
|
-
var AgentFrontmatterSchema = z4.object({
|
|
984
|
-
id: z4.enum(AGENT_IDS),
|
|
985
|
-
description: z4.string().min(1)
|
|
986
|
-
}).strict();
|
|
987
|
-
var Schemas = {
|
|
988
|
-
Skill: SkillFrontmatterSchema,
|
|
989
|
-
Cmd: CmdFrontmatterSchema,
|
|
990
|
-
Agent: AgentFrontmatterSchema
|
|
991
|
-
};
|
|
992
|
-
var ParseError = class extends Error {
|
|
993
|
-
constructor(file, issues) {
|
|
994
|
-
const messages = issues.map((i) => ` - ${i.path.join(".") || "<root>"}: ${i.message}`).join("\n");
|
|
995
|
-
super(`Frontmatter validation failed for ${file}:
|
|
996
|
-
${messages}`);
|
|
997
|
-
this.file = file;
|
|
998
|
-
this.issues = issues;
|
|
999
|
-
this.name = "ParseError";
|
|
1000
|
-
}
|
|
1001
|
-
file;
|
|
1002
|
-
issues;
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
// src/parser/common.ts
|
|
1006
|
-
function parseWithSchema(filePath, source, schema) {
|
|
1007
|
-
const parsed = matter(source);
|
|
1008
|
-
const result = schema.safeParse(parsed.data);
|
|
1009
|
-
if (!result.success) {
|
|
1010
|
-
throw new ParseError(filePath, result.error.issues);
|
|
1011
|
-
}
|
|
1012
|
-
return {
|
|
1013
|
-
meta: result.data,
|
|
1014
|
-
body: parsed.content.trim(),
|
|
1015
|
-
sourcePath: filePath
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// src/parser/agent.ts
|
|
1020
|
-
function parseAgent(filePath, source) {
|
|
1021
|
-
return parseWithSchema(filePath, source, Schemas.Agent);
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
// src/parser/cmd.ts
|
|
1025
|
-
function parseCmd(filePath, source) {
|
|
1026
|
-
return parseWithSchema(filePath, source, Schemas.Cmd);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
// src/parser/skill.ts
|
|
1030
|
-
function parseSkill(filePath, source) {
|
|
1031
|
-
return parseWithSchema(filePath, source, Schemas.Skill);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// src/util/yaml.ts
|
|
1035
|
-
import { parse as yamlParse } from "yaml";
|
|
1036
|
-
function parseYAML(source) {
|
|
1037
|
-
return yamlParse(source);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// src/loader.ts
|
|
1041
|
-
var DisableYamlSchema = z5.object({ disable: z5.array(z5.string()).optional() }).passthrough();
|
|
1042
|
-
function loadHarness(packageDir, opts = {}) {
|
|
1043
|
-
const agentsDir = opts.agentsDir ?? join5(packageDir, "agents");
|
|
1044
|
-
const skillsDir = opts.skillsDir ?? join5(packageDir, "skills");
|
|
1045
|
-
const commandsDir = opts.commandsDir ?? join5(packageDir, "commands");
|
|
1046
|
-
const agentFiles = fg.sync("*.agent.md", { cwd: agentsDir, absolute: true });
|
|
1047
|
-
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
1048
|
-
const cmdFiles = fg.sync("*.cmd.md", { cwd: commandsDir, absolute: true });
|
|
1049
|
-
return {
|
|
1050
|
-
agents: agentFiles.map((f) => parseAgent(f, readFileSync5(f, "utf8"))),
|
|
1051
|
-
skills: skillFiles.map((f) => parseSkill(f, readFileSync5(f, "utf8"))),
|
|
1052
|
-
cmds: cmdFiles.map((f) => parseCmd(f, readFileSync5(f, "utf8")))
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
function loadProjectSkills(targetDir) {
|
|
1056
|
-
const skillsDir = join5(targetDir, "docs", "skills");
|
|
1057
|
-
if (!existsSync4(skillsDir)) return [];
|
|
1058
|
-
const skillFiles = fg.sync("*.skill.md", { cwd: skillsDir, absolute: true });
|
|
1059
|
-
return skillFiles.map((f) => parseSkill(f, readFileSync5(f, "utf8")));
|
|
1060
|
-
}
|
|
1061
|
-
function loadOverrides(worktreeDir) {
|
|
1062
|
-
const overridesDir = join5(worktreeDir, ".harness-overrides");
|
|
1063
|
-
if (!existsSync4(overridesDir)) return void 0;
|
|
1064
|
-
const added = loadHarness(overridesDir, {
|
|
1065
|
-
agentsDir: join5(overridesDir, "agents"),
|
|
1066
|
-
skillsDir: join5(overridesDir, "skills"),
|
|
1067
|
-
commandsDir: join5(overridesDir, "commands")
|
|
1068
|
-
});
|
|
1069
|
-
const disablePath = join5(overridesDir, "disable.yaml");
|
|
1070
|
-
let disable = [];
|
|
1071
|
-
if (existsSync4(disablePath)) {
|
|
1072
|
-
try {
|
|
1073
|
-
const parsed = DisableYamlSchema.safeParse(parseYAML(readFileSync5(disablePath, "utf8")));
|
|
1074
|
-
if (parsed.success && parsed.data.disable) {
|
|
1075
|
-
disable = parsed.data.disable;
|
|
1076
|
-
}
|
|
1077
|
-
} catch {
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return { add: added, disable };
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
// src/mcp.ts
|
|
1084
|
-
var MCP_SERVER_IDS = ["context7"];
|
|
1085
|
-
var MCP_SERVERS = {
|
|
1086
|
-
context7: {
|
|
1087
|
-
id: "context7",
|
|
1088
|
-
description: "Upstash Context7 \u2014 fetches up-to-date library docs via resolve-library-id + get-library-docs.",
|
|
1089
|
-
command: "npx",
|
|
1090
|
-
args: ["-y", "@upstash/context7-mcp"]
|
|
1091
|
-
}
|
|
1092
|
-
};
|
|
1093
|
-
function resolveMcpIds(requested) {
|
|
1094
|
-
return requested.map((id) => {
|
|
1095
|
-
if (!MCP_SERVER_IDS.includes(id)) {
|
|
1096
|
-
throw new Error(`unknown MCP server: ${id} (expected one of ${MCP_SERVER_IDS.join(", ")})`);
|
|
1097
|
-
}
|
|
1098
|
-
return id;
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
467
|
// src/render.ts
|
|
1103
468
|
var RenderError = class extends Error {
|
|
1104
469
|
constructor(message) {
|
|
@@ -1122,7 +487,6 @@ function removeByIds(items, disabled) {
|
|
|
1122
487
|
function applyOverrides(harness, overrides) {
|
|
1123
488
|
const disabled = overrides?.disable ?? [];
|
|
1124
489
|
return {
|
|
1125
|
-
agents: removeByIds(mergeById(harness.agents, overrides?.add?.agents), disabled),
|
|
1126
490
|
skills: removeByIds(mergeById(harness.skills, overrides?.add?.skills), disabled),
|
|
1127
491
|
cmds: removeByIds(mergeById(harness.cmds, overrides?.add?.cmds), disabled)
|
|
1128
492
|
};
|
|
@@ -1138,58 +502,37 @@ function render(input) {
|
|
|
1138
502
|
}
|
|
1139
503
|
const base = input.projectSkills?.length ? { ...input.harness, skills: mergeById(input.harness.skills, input.projectSkills) } : input.harness;
|
|
1140
504
|
const harness = applyOverrides(base, input.overrides);
|
|
1141
|
-
if (harness.agents.length === 0) {
|
|
1142
|
-
throw new RenderError("No agents found in harness");
|
|
1143
|
-
}
|
|
1144
505
|
const files = [];
|
|
1145
506
|
const warnings = [];
|
|
1146
507
|
const exposedSkills = /* @__PURE__ */ new Map();
|
|
1147
508
|
const exposedCmds = /* @__PURE__ */ new Map();
|
|
1148
509
|
for (const engine of opencodeLast(engines)) {
|
|
1149
510
|
const renderer = getRenderer(engine);
|
|
1150
|
-
const
|
|
511
|
+
const renderedSkillIds = /* @__PURE__ */ new Set();
|
|
1151
512
|
for (const skill of harness.skills) {
|
|
1152
513
|
const result = renderer.renderSkill(skill);
|
|
1153
514
|
warnings.push(...result.warnings);
|
|
1154
515
|
if (result.files.length > 0) {
|
|
1155
516
|
const alreadyVisible = engine === "opencode" && exposedSkills.has(skill.meta.id);
|
|
1156
517
|
if (!alreadyVisible) files.push(...result.files);
|
|
1157
|
-
|
|
518
|
+
renderedSkillIds.add(skill.meta.id);
|
|
1158
519
|
exposedSkills.set(skill.meta.id, skill);
|
|
1159
520
|
}
|
|
1160
521
|
}
|
|
1161
|
-
const renderedSkillIds = new Set(renderedSkills.map((s) => s.meta.id));
|
|
1162
|
-
const renderedCmds = [];
|
|
1163
522
|
for (const cmd of harness.cmds) {
|
|
1164
523
|
if (!renderedSkillIds.has(cmd.meta.invokes_skill)) continue;
|
|
1165
524
|
const result = renderer.renderCmd(cmd);
|
|
1166
525
|
warnings.push(...result.warnings);
|
|
1167
526
|
if (result.files.length > 0) {
|
|
1168
527
|
files.push(...result.files);
|
|
1169
|
-
renderedCmds.push(cmd);
|
|
1170
528
|
exposedCmds.set(cmd.meta.id, cmd);
|
|
1171
529
|
}
|
|
1172
530
|
}
|
|
1173
|
-
const agentsResult = renderer.renderAgents(harness.agents);
|
|
1174
|
-
warnings.push(...agentsResult.warnings);
|
|
1175
|
-
files.push(...agentsResult.files);
|
|
1176
|
-
if (input.mcpServers && input.mcpServers.length > 0) {
|
|
1177
|
-
const specs = input.mcpServers.map((id) => MCP_SERVERS[id]);
|
|
1178
|
-
const mcpResult = renderer.renderMcp(specs);
|
|
1179
|
-
warnings.push(...mcpResult.warnings);
|
|
1180
|
-
files.push(...mcpResult.files);
|
|
1181
|
-
}
|
|
1182
|
-
if (input.withStopHook !== false) {
|
|
1183
|
-
const hookResult = renderer.renderStopHook();
|
|
1184
|
-
warnings.push(...hookResult.warnings);
|
|
1185
|
-
files.push(...hookResult.files);
|
|
1186
|
-
}
|
|
1187
531
|
}
|
|
1188
|
-
const
|
|
1189
|
-
const umbrellaContent = buildUmbrellaBody(harness.agents, {
|
|
532
|
+
const umbrellaContent = buildUmbrellaBody({
|
|
1190
533
|
availableSkills: Array.from(exposedSkills.values()),
|
|
1191
534
|
availableCommands: Array.from(exposedCmds.values()),
|
|
1192
|
-
hasProjectSkills,
|
|
535
|
+
hasProjectSkills: (input.projectSkills?.length ?? 0) > 0,
|
|
1193
536
|
hasQualityDoc: input.hasQualityDoc === true
|
|
1194
537
|
});
|
|
1195
538
|
files.push({ path: "AGENTS.md", content: umbrellaContent });
|
|
@@ -1202,8 +545,11 @@ function render(input) {
|
|
|
1202
545
|
// src/cli/plan-render.ts
|
|
1203
546
|
var QUALITY_DOC_PATH = "docs/quality/code-quality.md";
|
|
1204
547
|
function resolveEngineList(requested) {
|
|
1205
|
-
if (!requested)
|
|
1206
|
-
|
|
548
|
+
if (!requested || requested.length === 0) {
|
|
549
|
+
throw new Error(
|
|
550
|
+
`no engine selected: pass --engines=<list> with one or more of ${ENGINES.join(", ")}`
|
|
551
|
+
);
|
|
552
|
+
}
|
|
1207
553
|
const engines = requested.map((e) => {
|
|
1208
554
|
if (!ENGINES.includes(e)) {
|
|
1209
555
|
throw new Error(`unknown engine: ${e} (expected one of ${ENGINES.join(", ")})`);
|
|
@@ -1214,7 +560,7 @@ function resolveEngineList(requested) {
|
|
|
1214
560
|
}
|
|
1215
561
|
function defaultPackageDir() {
|
|
1216
562
|
const here = dirname2(fileURLToPath(import.meta.url));
|
|
1217
|
-
if (
|
|
563
|
+
if (existsSync3(join4(here, "skills"))) return here;
|
|
1218
564
|
return resolve2(here, "..");
|
|
1219
565
|
}
|
|
1220
566
|
function planInit(args) {
|
|
@@ -1223,31 +569,14 @@ function planInit(args) {
|
|
|
1223
569
|
const harness = loadHarness(packageDir);
|
|
1224
570
|
const overrides = args.overridesDir ? loadOverrides(args.overridesDir) : void 0;
|
|
1225
571
|
const projectSkills = loadProjectSkills(args.targetDir);
|
|
1226
|
-
const hasQualityDoc =
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
const output = render({
|
|
1230
|
-
harness,
|
|
1231
|
-
engines,
|
|
1232
|
-
overrides,
|
|
1233
|
-
projectSkills,
|
|
1234
|
-
hasQualityDoc,
|
|
1235
|
-
mcpServers,
|
|
1236
|
-
withStopHook: stopHookInstalled
|
|
1237
|
-
});
|
|
1238
|
-
return { engines, output, stopHookInstalled };
|
|
572
|
+
const hasQualityDoc = existsSync3(join4(args.targetDir, QUALITY_DOC_PATH));
|
|
573
|
+
const output = render({ harness, engines, overrides, projectSkills, hasQualityDoc });
|
|
574
|
+
return { engines, output };
|
|
1239
575
|
}
|
|
1240
576
|
|
|
1241
577
|
// src/cli/uninstall.ts
|
|
1242
|
-
import {
|
|
1243
|
-
|
|
1244
|
-
readFileSync as readFileSync6,
|
|
1245
|
-
readdirSync,
|
|
1246
|
-
rmdirSync,
|
|
1247
|
-
unlinkSync,
|
|
1248
|
-
writeFileSync as writeFileSync2
|
|
1249
|
-
} from "fs";
|
|
1250
|
-
import { dirname as dirname3, join as join7, relative, resolve as resolve3 } from "path";
|
|
578
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, readdirSync, rmdirSync, unlinkSync } from "fs";
|
|
579
|
+
import { dirname as dirname3, join as join5, relative, resolve as resolve3 } from "path";
|
|
1251
580
|
function pruneEmptyDirs(root, leaves) {
|
|
1252
581
|
const candidates = /* @__PURE__ */ new Set();
|
|
1253
582
|
for (const leaf of leaves) {
|
|
@@ -1260,7 +589,7 @@ function pruneEmptyDirs(root, leaves) {
|
|
|
1260
589
|
const pruned = [];
|
|
1261
590
|
const sorted = [...candidates].sort((a, b) => b.length - a.length);
|
|
1262
591
|
for (const dir of sorted) {
|
|
1263
|
-
if (!
|
|
592
|
+
if (!existsSync4(dir)) continue;
|
|
1264
593
|
if (readdirSync(dir).length > 0) continue;
|
|
1265
594
|
rmdirSync(dir);
|
|
1266
595
|
pruned.push(relative(root, dir));
|
|
@@ -1277,25 +606,17 @@ import {
|
|
|
1277
606
|
lstatSync as lstatSync2,
|
|
1278
607
|
mkdirSync,
|
|
1279
608
|
openSync,
|
|
1280
|
-
readFileSync as
|
|
609
|
+
readFileSync as readFileSync5,
|
|
1281
610
|
readdirSync as readdirSync2,
|
|
1282
611
|
realpathSync as realpathSync2,
|
|
1283
612
|
rmdirSync as rmdirSync2,
|
|
1284
613
|
unlinkSync as unlinkSync2,
|
|
1285
|
-
writeFileSync as
|
|
614
|
+
writeFileSync as writeFileSync2
|
|
1286
615
|
} from "fs";
|
|
1287
616
|
import { homedir } from "os";
|
|
1288
|
-
import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute2, join as
|
|
617
|
+
import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute2, join as join6, relative as relative2, resolve as resolve4, sep } from "path";
|
|
1289
618
|
var MANIFEST_PATH = ".harness-manifest.json";
|
|
1290
|
-
var PRIVATE_FILES = /* @__PURE__ */ new Set([
|
|
1291
|
-
MANIFEST_PATH,
|
|
1292
|
-
".mcp.json",
|
|
1293
|
-
".codex/config.toml",
|
|
1294
|
-
".codex/hooks.json",
|
|
1295
|
-
".claude/settings.json",
|
|
1296
|
-
".opencode/opencode.json",
|
|
1297
|
-
".opencode/mcp.json"
|
|
1298
|
-
]);
|
|
619
|
+
var PRIVATE_FILES = /* @__PURE__ */ new Set([MANIFEST_PATH]);
|
|
1299
620
|
function canonicalRoot(root) {
|
|
1300
621
|
let ancestor = resolve4(root);
|
|
1301
622
|
const missing = [];
|
|
@@ -1303,7 +624,7 @@ function canonicalRoot(root) {
|
|
|
1303
624
|
missing.unshift(basename2(ancestor));
|
|
1304
625
|
ancestor = dirname4(ancestor);
|
|
1305
626
|
}
|
|
1306
|
-
return
|
|
627
|
+
return join6(realpathSync2(ancestor), ...missing);
|
|
1307
628
|
}
|
|
1308
629
|
function contains(parent, child) {
|
|
1309
630
|
const path = relative2(parent, child);
|
|
@@ -1343,7 +664,7 @@ function writeBackupFile(path, content) {
|
|
|
1343
664
|
createDirectories(dirname4(path), [], 448);
|
|
1344
665
|
const fd = openSync(path, "wx", 384);
|
|
1345
666
|
try {
|
|
1346
|
-
|
|
667
|
+
writeFileSync2(fd, content);
|
|
1347
668
|
fsyncSync(fd);
|
|
1348
669
|
} finally {
|
|
1349
670
|
closeSync(fd);
|
|
@@ -1354,14 +675,14 @@ function saveSnapshot(root, paths, backup) {
|
|
|
1354
675
|
createDirectories(dirname4(backup), [], 448);
|
|
1355
676
|
mkdirSync(backup, { mode: 448 });
|
|
1356
677
|
for (const path of paths) {
|
|
1357
|
-
const full =
|
|
678
|
+
const full = join6(root, path);
|
|
1358
679
|
const info = lstatSync2(full, { throwIfNoEntry: false });
|
|
1359
680
|
if (!info) {
|
|
1360
681
|
entries.push({ path, exists: false });
|
|
1361
682
|
continue;
|
|
1362
683
|
}
|
|
1363
|
-
const content =
|
|
1364
|
-
writeBackupFile(
|
|
684
|
+
const content = readFileSync5(full);
|
|
685
|
+
writeBackupFile(join6(backup, "files", path), content);
|
|
1365
686
|
entries.push({
|
|
1366
687
|
path,
|
|
1367
688
|
exists: true,
|
|
@@ -1370,7 +691,7 @@ function saveSnapshot(root, paths, backup) {
|
|
|
1370
691
|
});
|
|
1371
692
|
}
|
|
1372
693
|
writeBackupFile(
|
|
1373
|
-
|
|
694
|
+
join6(backup, "snapshot.json"),
|
|
1374
695
|
`${JSON.stringify({ version: 1, root, createdAt: (/* @__PURE__ */ new Date()).toISOString(), entries }, null, 2)}
|
|
1375
696
|
`
|
|
1376
697
|
);
|
|
@@ -1385,16 +706,16 @@ function rollback(root, backup, entries, touched, createdDirectories) {
|
|
|
1385
706
|
try {
|
|
1386
707
|
assertManagedPaths(root, [path]);
|
|
1387
708
|
const entry = entries.get(path);
|
|
1388
|
-
const full =
|
|
709
|
+
const full = join6(root, path);
|
|
1389
710
|
const current = lstatSync2(full, { throwIfNoEntry: false });
|
|
1390
711
|
if (!entry?.exists) {
|
|
1391
712
|
if (current) unlinkSync2(full);
|
|
1392
713
|
continue;
|
|
1393
714
|
}
|
|
1394
|
-
const original =
|
|
1395
|
-
if (!current || !
|
|
715
|
+
const original = readFileSync5(join6(backup, "files", path));
|
|
716
|
+
if (!current || !readFileSync5(full).equals(original)) {
|
|
1396
717
|
if (current) unlinkSync2(full);
|
|
1397
|
-
|
|
718
|
+
writeFileSync2(full, original, { mode: 384 });
|
|
1398
719
|
}
|
|
1399
720
|
chmodSync2(full, entry.mode);
|
|
1400
721
|
} catch (error) {
|
|
@@ -1415,7 +736,7 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
1415
736
|
assertManagedPaths(root, paths);
|
|
1416
737
|
const target = canonicalRoot(root);
|
|
1417
738
|
const backup = resolve4(
|
|
1418
|
-
backupDir ??
|
|
739
|
+
backupDir ?? join6(homedir(), ".local", "state", "vaubaan-harness", "backups", randomUUID())
|
|
1419
740
|
);
|
|
1420
741
|
assertBackupLocation(target, backup);
|
|
1421
742
|
let snapshot;
|
|
@@ -1433,18 +754,18 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
1433
754
|
try {
|
|
1434
755
|
assertManagedPaths(target, paths);
|
|
1435
756
|
for (const path of removals) {
|
|
1436
|
-
if (!lstatSync2(
|
|
757
|
+
if (!lstatSync2(join6(target, path), { throwIfNoEntry: false })) continue;
|
|
1437
758
|
touched.add(path);
|
|
1438
|
-
unlinkSync2(
|
|
759
|
+
unlinkSync2(join6(target, path));
|
|
1439
760
|
}
|
|
1440
761
|
for (const file of writes) {
|
|
1441
|
-
const full =
|
|
762
|
+
const full = join6(target, file.path);
|
|
1442
763
|
createDirectories(dirname4(full), createdDirectories);
|
|
1443
764
|
touched.add(file.path);
|
|
1444
765
|
const entry = entries.get(file.path);
|
|
1445
766
|
const mode = file.path === MANIFEST_PATH ? 384 : entry?.exists ? entry.mode : PRIVATE_FILES.has(file.path) ? 384 : 420;
|
|
1446
767
|
if (entry?.exists && file.path === MANIFEST_PATH) chmodSync2(full, mode);
|
|
1447
|
-
|
|
768
|
+
writeFileSync2(full, file.content, { mode });
|
|
1448
769
|
if (entry?.exists) chmodSync2(full, mode);
|
|
1449
770
|
}
|
|
1450
771
|
} catch (error) {
|
|
@@ -1458,36 +779,28 @@ function applyUpdateTransaction(root, writes, removals, backupDir) {
|
|
|
1458
779
|
}
|
|
1459
780
|
|
|
1460
781
|
// src/cli/update.ts
|
|
1461
|
-
import { existsSync as
|
|
1462
|
-
import { join as
|
|
1463
|
-
import { isDeepStrictEqual
|
|
782
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
783
|
+
import { dirname as dirname5, join as join8, resolve as resolve5 } from "path";
|
|
784
|
+
import { isDeepStrictEqual } from "util";
|
|
1464
785
|
|
|
1465
786
|
// src/cli/update-manifest.ts
|
|
1466
|
-
import { existsSync as
|
|
1467
|
-
import { join as
|
|
1468
|
-
import { z as
|
|
1469
|
-
var EngineSchema =
|
|
1470
|
-
var LegacySchema =
|
|
1471
|
-
version:
|
|
787
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
788
|
+
import { join as join7 } from "path";
|
|
789
|
+
import { z as z4 } from "zod";
|
|
790
|
+
var EngineSchema = z4.enum(ENGINES);
|
|
791
|
+
var LegacySchema = z4.object({
|
|
792
|
+
version: z4.enum(["1", "2", "3"]),
|
|
1472
793
|
engine: EngineSchema.optional(),
|
|
1473
|
-
engines:
|
|
1474
|
-
renderedAt:
|
|
1475
|
-
files:
|
|
794
|
+
engines: z4.array(EngineSchema).nonempty().optional(),
|
|
795
|
+
renderedAt: z4.string(),
|
|
796
|
+
files: z4.array(z4.string())
|
|
1476
797
|
});
|
|
1477
|
-
var HOOK_PATHS = {
|
|
1478
|
-
"claude-code": [".claude/settings.json"],
|
|
1479
|
-
"codex-cli": [".codex/hooks.json"],
|
|
1480
|
-
opencode: [
|
|
1481
|
-
".opencode/plugins/harness-stop-hook/index.ts",
|
|
1482
|
-
".opencode/plugins/harness-stop-hook.ts"
|
|
1483
|
-
]
|
|
1484
|
-
};
|
|
1485
798
|
function readUpdateInstallation(root) {
|
|
1486
799
|
assertManagedPaths(root, [MANIFEST_FILENAME]);
|
|
1487
|
-
if (!
|
|
800
|
+
if (!existsSync5(join7(root, MANIFEST_FILENAME))) {
|
|
1488
801
|
throw new Error("no harness manifest found; use init for a new installation");
|
|
1489
802
|
}
|
|
1490
|
-
const raw = JSON.parse(
|
|
803
|
+
const raw = JSON.parse(readFileSync6(join7(root, MANIFEST_FILENAME), "utf8"));
|
|
1491
804
|
const sourceVersion = String(raw?.version);
|
|
1492
805
|
let manifest;
|
|
1493
806
|
if (["1", "2", "3"].includes(sourceVersion)) {
|
|
@@ -1495,7 +808,7 @@ function readUpdateInstallation(root) {
|
|
|
1495
808
|
const engines2 = legacy.version === "1" ? [EngineSchema.parse(legacy.engine)] : legacy.engines;
|
|
1496
809
|
manifest = {
|
|
1497
810
|
version: "4",
|
|
1498
|
-
engines:
|
|
811
|
+
engines: z4.array(EngineSchema).nonempty().parse(engines2),
|
|
1499
812
|
files: legacy.files,
|
|
1500
813
|
renderedAt: legacy.renderedAt
|
|
1501
814
|
};
|
|
@@ -1504,32 +817,20 @@ function readUpdateInstallation(root) {
|
|
|
1504
817
|
if (!current) throw new Error("harness manifest disappeared during planning");
|
|
1505
818
|
manifest = current;
|
|
1506
819
|
}
|
|
1507
|
-
const engines = [...new Set(
|
|
1508
|
-
|
|
1509
|
-
(engine) => HOOK_PATHS[engine].some((path) => manifest.files.includes(path))
|
|
1510
|
-
);
|
|
1511
|
-
if (hookEngines.some((engine) => !engines.includes(engine))) {
|
|
1512
|
-
throw new Error("manifest stopHookEngines must be a subset of installed engines");
|
|
1513
|
-
}
|
|
1514
|
-
return { manifest, sourceVersion, engines, hookEngines: [...new Set(hookEngines)] };
|
|
820
|
+
const engines = [...new Set(z4.array(EngineSchema).nonempty().parse(manifest.engines))];
|
|
821
|
+
return { manifest, sourceVersion, engines };
|
|
1515
822
|
}
|
|
1516
823
|
|
|
1517
824
|
// src/cli/update.ts
|
|
1518
|
-
var
|
|
825
|
+
var LEGACY_HOOK_FILES = [".claude/settings.json", ".codex/hooks.json"];
|
|
826
|
+
var LEGACY_HOOK_MARKER = "@vaubaan/harness stop-hook";
|
|
1519
827
|
function currentContent(root, path) {
|
|
1520
|
-
return
|
|
1521
|
-
}
|
|
1522
|
-
function ownedUnchanged(root, previous, path) {
|
|
1523
|
-
const content = currentContent(root, path);
|
|
1524
|
-
if (content === void 0 || !previous.files.includes(path)) return false;
|
|
1525
|
-
const hash = previous.fileHashes?.[path];
|
|
1526
|
-
return hash === void 0 || hash === hashContent(content);
|
|
828
|
+
return existsSync6(join8(root, path)) ? readFileSync7(join8(root, path), "utf8") : void 0;
|
|
1527
829
|
}
|
|
1528
830
|
function checkArtifactConflicts(root, previous, writes, removals) {
|
|
1529
831
|
const desired = new Map(writes.map((file) => [file.path, file.content]));
|
|
1530
832
|
const conflicts = [];
|
|
1531
833
|
for (const path of [...desired.keys(), ...removals]) {
|
|
1532
|
-
if (SHARED_CONFIG_PATHS.includes(path)) continue;
|
|
1533
834
|
const content = currentContent(root, path);
|
|
1534
835
|
if (content === void 0 || content === desired.get(path)) continue;
|
|
1535
836
|
if (!previous.files.includes(path)) {
|
|
@@ -1546,92 +847,47 @@ move their content to docs/ or .harness-overrides/, or keep them as yours with -
|
|
|
1546
847
|
);
|
|
1547
848
|
}
|
|
1548
849
|
}
|
|
1549
|
-
function
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return void 0;
|
|
1554
|
-
return { createdFile: true, addedMcp: true, addedSchema: false, entries: servers };
|
|
1555
|
-
} catch {
|
|
1556
|
-
return void 0;
|
|
850
|
+
function releaseLegacyPaths(previous, warnings) {
|
|
851
|
+
const released = previous.files.filter((path) => RELEASED_PATHS.includes(path));
|
|
852
|
+
for (const path of released) {
|
|
853
|
+
warnings.push(`no longer managed by the harness, left in place: ${path}`);
|
|
1557
854
|
}
|
|
855
|
+
if (released.length === 0) return previous;
|
|
856
|
+
return { ...previous, files: previous.files.filter((path) => !released.includes(path)) };
|
|
1558
857
|
}
|
|
1559
|
-
function
|
|
1560
|
-
const
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
};
|
|
1568
|
-
const claudeOwnership = previous.mcpConfig ?? legacyMcpOwnership(root, previous);
|
|
1569
|
-
const codexOwned = ownedUnchanged(root, previous, CODEX_CONFIG_PATH);
|
|
1570
|
-
if (settings.mcpServers === void 0) {
|
|
1571
|
-
if (codexOwned) plan.owned.push(CODEX_CONFIG_PATH);
|
|
1572
|
-
plan.mcpConfig = claudeOwnership;
|
|
1573
|
-
return plan;
|
|
1574
|
-
}
|
|
1575
|
-
const desired = (path) => rendered.find((file) => file.path === path);
|
|
1576
|
-
if (!pendingWrites.some((file) => file.path === OPENCODE_CONFIG_PATH)) {
|
|
1577
|
-
plan.plannedOpenCode = true;
|
|
1578
|
-
if (previous.files.includes(OPENCODE_CONFIG_PATH) && !previous.opencodeConfig) {
|
|
1579
|
-
plan.warnings.push(`preserved legacy shared configuration: ${OPENCODE_CONFIG_PATH}`);
|
|
858
|
+
function legacyHookWarnings(root) {
|
|
859
|
+
const warnings = [];
|
|
860
|
+
for (const path of LEGACY_HOOK_FILES) {
|
|
861
|
+
const content = currentContent(root, path);
|
|
862
|
+
if (content?.includes(LEGACY_HOOK_MARKER)) {
|
|
863
|
+
warnings.push(
|
|
864
|
+
`remove the harness Stop hook entry from ${path}: the Stop hook was removed in 2.0, run \`npx @vaubaan/harness lint\` in CI and pre-commit instead`
|
|
865
|
+
);
|
|
1580
866
|
}
|
|
1581
|
-
const opencode = planOpenCodeConfig(
|
|
1582
|
-
root,
|
|
1583
|
-
desired(OPENCODE_CONFIG_PATH),
|
|
1584
|
-
previous.opencodeConfig
|
|
1585
|
-
);
|
|
1586
|
-
if (opencode.write) plan.writes.push(opencode.write);
|
|
1587
|
-
if (opencode.remove) plan.removals.push(OPENCODE_CONFIG_PATH);
|
|
1588
|
-
plan.opencodeConfig = opencode.ownership;
|
|
1589
|
-
plan.warnings.push(...opencode.warnings);
|
|
1590
867
|
}
|
|
1591
|
-
|
|
1592
|
-
if (claude.write) plan.writes.push(claude.write);
|
|
1593
|
-
if (claude.remove) plan.removals.push(CLAUDE_MCP_PATH);
|
|
1594
|
-
plan.mcpConfig = claude.ownership;
|
|
1595
|
-
plan.warnings.push(...claude.warnings);
|
|
1596
|
-
const codex = desired(CODEX_CONFIG_PATH);
|
|
1597
|
-
const codexExists = existsSync8(join10(root, CODEX_CONFIG_PATH));
|
|
1598
|
-
if (codex && (!codexExists || codexOwned)) {
|
|
1599
|
-
plan.writes.push(codex);
|
|
1600
|
-
plan.owned.push(CODEX_CONFIG_PATH);
|
|
1601
|
-
} else if (codex) {
|
|
1602
|
-
plan.warnings.push(
|
|
1603
|
-
`left ${CODEX_CONFIG_PATH} unchanged; add this block to it to enable MCP in Codex:
|
|
1604
|
-
${codex.content.trimEnd()}`
|
|
1605
|
-
);
|
|
1606
|
-
} else if (codexOwned) {
|
|
1607
|
-
plan.removals.push(CODEX_CONFIG_PATH);
|
|
1608
|
-
}
|
|
1609
|
-
return plan;
|
|
868
|
+
return warnings;
|
|
1610
869
|
}
|
|
1611
870
|
function planInstallation(args, settings) {
|
|
1612
871
|
const root = resolve5(args.targetDir);
|
|
1613
|
-
const {
|
|
872
|
+
const { engines } = settings;
|
|
873
|
+
const warnings = [];
|
|
874
|
+
const previous = releaseLegacyPaths(settings.previous, warnings);
|
|
1614
875
|
const preserved = [
|
|
1615
876
|
.../* @__PURE__ */ new Set([...previous.preservedFiles ?? [], ...args.preserveFiles ?? []])
|
|
1616
877
|
].sort();
|
|
1617
878
|
if (preserved.includes(MANIFEST_FILENAME))
|
|
1618
879
|
throw new Error("cannot preserve the harness manifest");
|
|
1619
|
-
|
|
1620
|
-
throw new Error(
|
|
1621
|
-
"--preserve applies to generated artifacts; shared configurations use entry-level preservation"
|
|
1622
|
-
);
|
|
1623
|
-
}
|
|
1624
|
-
assertManagedPaths(root, [...previous.files, ...preserved, ...SHARED_CONFIG_PATHS]);
|
|
880
|
+
assertManagedPaths(root, [...previous.files, ...preserved]);
|
|
1625
881
|
const requestedOverrides = args.overridesDir ?? previous.overridesDir;
|
|
1626
882
|
const overridesDir = args.overridesDir ? resolve5(args.overridesDir) : previous.overridesDir ? resolve5(root, previous.overridesDir) : root;
|
|
1627
|
-
if (requestedOverrides && !
|
|
883
|
+
if (requestedOverrides && !existsSync6(join8(overridesDir, ".harness-overrides"))) {
|
|
1628
884
|
throw new Error(`recorded overrides are missing: ${overridesDir}/.harness-overrides`);
|
|
1629
885
|
}
|
|
1630
|
-
const hasOverrides =
|
|
1631
|
-
const disablePath =
|
|
1632
|
-
if (
|
|
886
|
+
const hasOverrides = existsSync6(join8(overridesDir, ".harness-overrides"));
|
|
887
|
+
const disablePath = join8(overridesDir, ".harness-overrides", "disable.yaml");
|
|
888
|
+
if (existsSync6(disablePath)) {
|
|
1633
889
|
try {
|
|
1634
|
-
DisableYamlSchema.parse(parseYAML(
|
|
890
|
+
DisableYamlSchema.parse(parseYAML(readFileSync7(disablePath, "utf8")));
|
|
1635
891
|
} catch {
|
|
1636
892
|
throw new Error(`invalid override selection: ${disablePath}`);
|
|
1637
893
|
}
|
|
@@ -1640,40 +896,16 @@ function planInstallation(args, settings) {
|
|
|
1640
896
|
targetDir: root,
|
|
1641
897
|
packageDir: args.packageDir,
|
|
1642
898
|
engines,
|
|
1643
|
-
overridesDir: hasOverrides ? overridesDir : void 0
|
|
1644
|
-
mcpServers: settings.mcpServers,
|
|
1645
|
-
withStopHook: false
|
|
899
|
+
overridesDir: hasOverrides ? overridesDir : void 0
|
|
1646
900
|
});
|
|
1647
|
-
const
|
|
1648
|
-
|
|
901
|
+
const output = rendered.output.files.filter((file) => !preserved.includes(file.path));
|
|
902
|
+
const owned = output.map((file) => file.path).sort();
|
|
903
|
+
const removals = previous.files.filter(
|
|
904
|
+
(file) => !owned.includes(file) && !preserved.includes(file)
|
|
1649
905
|
);
|
|
1650
|
-
|
|
1651
|
-
const mcp = planMcp(root, settings, rendered.output.files, config.writes);
|
|
1652
|
-
const output = [...generated, ...config.writes, ...mcp.writes].filter(
|
|
1653
|
-
(file) => !preserved.includes(file.path)
|
|
1654
|
-
);
|
|
1655
|
-
const owned = [
|
|
1656
|
-
.../* @__PURE__ */ new Set([...generated.map((file) => file.path), ...config.ownedFiles, ...mcp.owned])
|
|
1657
|
-
].filter((file) => !preserved.includes(file)).sort();
|
|
1658
|
-
const removals = [
|
|
1659
|
-
.../* @__PURE__ */ new Set([
|
|
1660
|
-
...previous.files.filter(
|
|
1661
|
-
(file) => !owned.includes(file) && !SHARED_CONFIG_PATHS.includes(file)
|
|
1662
|
-
),
|
|
1663
|
-
...config.removals,
|
|
1664
|
-
...mcp.removals
|
|
1665
|
-
])
|
|
1666
|
-
].filter((file) => !preserved.includes(file));
|
|
1667
|
-
assertManagedPaths(root, [...output.map((file) => file.path), ...removals]);
|
|
906
|
+
assertManagedPaths(root, [...owned, ...removals]);
|
|
1668
907
|
checkArtifactConflicts(root, previous, output, removals);
|
|
1669
|
-
const hashes = Object.fromEntries(
|
|
1670
|
-
owned.map((path) => {
|
|
1671
|
-
const content = output.find((file) => file.path === path)?.content ?? currentContent(root, path);
|
|
1672
|
-
if (content === void 0) throw new Error(`missing planned harness file: ${path}`);
|
|
1673
|
-
return [path, hashContent(content)];
|
|
1674
|
-
})
|
|
1675
|
-
);
|
|
1676
|
-
const opencodeConfig = mcp.plannedOpenCode ? mcp.opencodeConfig : config.opencodeConfig;
|
|
908
|
+
const hashes = Object.fromEntries(output.map((file) => [file.path, hashContent(file.content)]));
|
|
1677
909
|
const manifest = {
|
|
1678
910
|
version: MANIFEST_VERSION,
|
|
1679
911
|
harnessVersion: VERSION,
|
|
@@ -1681,37 +913,30 @@ function planInstallation(args, settings) {
|
|
|
1681
913
|
renderedAt: previous.renderedAt,
|
|
1682
914
|
files: owned,
|
|
1683
915
|
fileHashes: hashes,
|
|
1684
|
-
stopHookInstalled: hookEngines.length > 0,
|
|
1685
|
-
stopHookEngines: [...hookEngines].sort(),
|
|
1686
916
|
...hasOverrides ? { overridesDir: overridesDir === root ? "." : overridesDir } : {},
|
|
1687
|
-
...preserved.length ? { preservedFiles: preserved } : {}
|
|
1688
|
-
...opencodeConfig ? { opencodeConfig } : {},
|
|
1689
|
-
...mcp.mcpConfig ? { mcpConfig: mcp.mcpConfig } : {},
|
|
1690
|
-
...config.hookConfigs ? { hookConfigs: config.hookConfigs } : {}
|
|
917
|
+
...preserved.length ? { preservedFiles: preserved } : {}
|
|
1691
918
|
};
|
|
1692
919
|
const writes = output.filter((file) => currentContent(root, file.path) !== file.content);
|
|
1693
|
-
const existingRemovals = removals.filter((path) =>
|
|
1694
|
-
if (writes.length || existingRemovals.length || !
|
|
920
|
+
const existingRemovals = removals.filter((path) => existsSync6(join8(root, path)));
|
|
921
|
+
if (writes.length || existingRemovals.length || !isDeepStrictEqual(settings.previous, manifest)) {
|
|
1695
922
|
manifest.renderedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1696
923
|
writes.push({ path: MANIFEST_FILENAME, content: `${JSON.stringify(manifest, null, 2)}
|
|
1697
924
|
` });
|
|
1698
925
|
}
|
|
1699
|
-
|
|
926
|
+
warnings.push(...rendered.output.warnings, ...legacyHookWarnings(root));
|
|
1700
927
|
if (preserved.length) warnings.push(`preserved user-owned artifacts: ${preserved.join(", ")}`);
|
|
1701
928
|
return { writes, removals: existingRemovals, owned, manifest, warnings };
|
|
1702
929
|
}
|
|
1703
930
|
function planUpdate(args) {
|
|
1704
931
|
const root = resolve5(args.targetDir);
|
|
1705
|
-
const { manifest: previous, sourceVersion, engines
|
|
1706
|
-
const plan = planInstallation(args, { previous, sourceVersion, engines
|
|
932
|
+
const { manifest: previous, sourceVersion, engines } = readUpdateInstallation(root);
|
|
933
|
+
const plan = planInstallation(args, { previous, sourceVersion, engines });
|
|
1707
934
|
const warnings = [...plan.warnings];
|
|
1708
935
|
if (!previous.fileHashes) {
|
|
1709
936
|
warnings.push(
|
|
1710
937
|
"legacy manifest has no file fingerprints: managed artifacts will be regenerated; backup preserves their previous contents"
|
|
1711
938
|
);
|
|
1712
939
|
}
|
|
1713
|
-
if (engines.includes("codex-cli"))
|
|
1714
|
-
warnings.push("ensure .agents/ is ignored by Git (run harness check)");
|
|
1715
940
|
return {
|
|
1716
941
|
writes: plan.writes,
|
|
1717
942
|
removals: plan.removals,
|
|
@@ -1730,12 +955,9 @@ function planUpdate(args) {
|
|
|
1730
955
|
function updateCommand(args) {
|
|
1731
956
|
const plan = planUpdate(args);
|
|
1732
957
|
if (args.dryRun || plan.result.upToDate) return plan.result;
|
|
1733
|
-
const
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
plan.removals,
|
|
1737
|
-
args.backupDir
|
|
1738
|
-
);
|
|
958
|
+
const root = resolve5(args.targetDir);
|
|
959
|
+
const { backupDir } = applyUpdateTransaction(root, plan.writes, plan.removals, args.backupDir);
|
|
960
|
+
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname5(join8(root, path)))));
|
|
1739
961
|
return { ...plan.result, backupDir };
|
|
1740
962
|
}
|
|
1741
963
|
|
|
@@ -1747,9 +969,9 @@ function writeFilesToTarget(files, targetDir) {
|
|
|
1747
969
|
);
|
|
1748
970
|
const written = [];
|
|
1749
971
|
for (const f of files) {
|
|
1750
|
-
const full =
|
|
1751
|
-
mkdirSync2(
|
|
1752
|
-
|
|
972
|
+
const full = join9(targetDir, f.path);
|
|
973
|
+
mkdirSync2(dirname6(full), { recursive: true });
|
|
974
|
+
writeFileSync3(full, f.content);
|
|
1753
975
|
written.push(f.path);
|
|
1754
976
|
}
|
|
1755
977
|
return written;
|
|
@@ -1760,7 +982,6 @@ function emptyManifest(engines) {
|
|
|
1760
982
|
function initCommand(args) {
|
|
1761
983
|
const root = resolve6(args.targetDir);
|
|
1762
984
|
const engines = resolveEngineList(args.engines);
|
|
1763
|
-
const stopHookInstalled = args.withStopHook !== false;
|
|
1764
985
|
const previous = readManifest(root) ?? emptyManifest(engines);
|
|
1765
986
|
const plan = planInstallation(
|
|
1766
987
|
{
|
|
@@ -1769,16 +990,10 @@ function initCommand(args) {
|
|
|
1769
990
|
overridesDir: args.overridesDir,
|
|
1770
991
|
preserveFiles: args.preserveFiles
|
|
1771
992
|
},
|
|
1772
|
-
{
|
|
1773
|
-
previous,
|
|
1774
|
-
sourceVersion: previous.version,
|
|
1775
|
-
engines,
|
|
1776
|
-
hookEngines: stopHookInstalled ? engines : [],
|
|
1777
|
-
mcpServers: args.mcpServers ?? []
|
|
1778
|
-
}
|
|
993
|
+
{ previous, sourceVersion: previous.version, engines }
|
|
1779
994
|
);
|
|
1780
995
|
const touchedExisting = [...plan.writes.map((file) => file.path), ...plan.removals].some(
|
|
1781
|
-
(path) => path !== MANIFEST_FILENAME &&
|
|
996
|
+
(path) => path !== MANIFEST_FILENAME && existsSync7(join9(root, path))
|
|
1782
997
|
);
|
|
1783
998
|
let backupDir;
|
|
1784
999
|
if (plan.writes.length || plan.removals.length) {
|
|
@@ -1787,14 +1002,12 @@ function initCommand(args) {
|
|
|
1787
1002
|
rmSync(backupDir, { recursive: true, force: true });
|
|
1788
1003
|
backupDir = void 0;
|
|
1789
1004
|
}
|
|
1790
|
-
pruneEmptyDirs(root, new Set(plan.removals.map((path) =>
|
|
1005
|
+
pruneEmptyDirs(root, new Set(plan.removals.map((path) => dirname6(join9(root, path)))));
|
|
1791
1006
|
}
|
|
1792
|
-
const sharedWritten = plan.writes.map((file) => file.path).filter((path) => SHARED_CONFIG_PATHS.includes(path) && !plan.owned.includes(path));
|
|
1793
1007
|
return {
|
|
1794
|
-
filesWritten:
|
|
1008
|
+
filesWritten: plan.owned,
|
|
1795
1009
|
staleFilesRemoved: plan.removals,
|
|
1796
1010
|
warnings: plan.warnings,
|
|
1797
|
-
stopHookInstalled,
|
|
1798
1011
|
engines,
|
|
1799
1012
|
...backupDir ? { backupDir } : {}
|
|
1800
1013
|
};
|