joycraft 1.2.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,308 @@
1
+ import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { isObject, localPath, parseJson, readLocal } from './identity.mjs';
5
+ import { accepted, projectStatus } from './status.mjs';
6
+
7
+ // The gate answers one question for a hook, CI or a person: does every done
8
+ // spec carry an acceptance, and do queue and spec frontmatter agree? A held
9
+ // in-review spec is never a failure. Queues written before schemaVersion 1 are
10
+ // skipped, so an old project does not block.
11
+
12
+ function legacySchema(queue) {
13
+ if (!isObject(queue)) return false;
14
+ const version = queue.schemaVersion;
15
+ if (version === undefined || version === null) return true;
16
+ if (typeof version === 'number') return version < 1;
17
+ return typeof version === 'string' && version.trim() !== '' && Number(version) < 1;
18
+ }
19
+
20
+ // A file that does not parse has one next step: repair it and tell the user.
21
+ const repair = (file, problem) => `Joycraft gate: ${file} does not parse: ${String(problem).replace(/\.$/, '')}. Repair ${file} and tell the user.`;
22
+
23
+ // Each drift kind in status.mjs has its own next step. status.mjs --fix repairs
24
+ // only an accepted spec without a pending journal; a pending journal needs
25
+ // completion.mjs recover and stops there; any other drift is set by hand to the queue's status,
26
+ // which is the status authority. An unaccepted done goes back to in-review first.
27
+ const setByHand = "set the spec frontmatter to the queue's status by hand and tell the user.";
28
+ function driftStep(item, { queuePath, pendingJournal }) {
29
+ if (pendingJournal) return `A completion journal is pending. Run node .joycraft/runtime/completion.mjs recover --queue ${queuePath}. If recovery reports a conflict or an invalid journal, stop and tell the user; do not edit a status.`;
30
+ if (item.fixable) return 'The queue records an accepted completion. Run node .joycraft/runtime/status.mjs --fix';
31
+ if (item.queue === 'done') return `The queue's done has no acceptance. First set the queue back to in-review, as the done line for this spec says. Then ${setByHand}`;
32
+ return setByHand[0].toUpperCase() + setByHand.slice(1);
33
+ }
34
+
35
+ function readRaw(root, queuePath) {
36
+ try { return parseJson(readLocal(root, queuePath), queuePath); } catch { return undefined; }
37
+ }
38
+
39
+ /** Gate findings for a project: unaccepted done specs, drift, and current-schema queues that do not parse. */
40
+ export function checkGates(root = process.cwd()) {
41
+ const status = projectStatus({ root });
42
+ const failures = [];
43
+ const skipped = [];
44
+ for (const problem of status.problems) {
45
+ if (problem.queuePath !== undefined) {
46
+ const raw = readRaw(root, problem.queuePath);
47
+ if (legacySchema(raw)) {
48
+ skipped.push({ queuePath: problem.queuePath, schemaVersion: raw.schemaVersion ?? null,
49
+ message: `Joycraft gate: skipped ${problem.queuePath}; ${raw.schemaVersion == null ? 'it has no schemaVersion' : `its schemaVersion ${JSON.stringify(raw.schemaVersion)} predates 1`}.` });
50
+ continue;
51
+ }
52
+ failures.push({ kind: 'queue', queuePath: problem.queuePath, message: repair(problem.queuePath, problem.problem) });
53
+ } else {
54
+ failures.push({ kind: 'spec', file: problem.specPath, message: repair(problem.specPath, problem.problem) });
55
+ }
56
+ }
57
+ for (const feature of status.features) {
58
+ const queue = parseJson(readLocal(root, feature.queuePath), feature.queuePath);
59
+ for (const spec of queue.specs) {
60
+ if (spec.status !== 'done' || accepted(spec)) continue;
61
+ const file = path.posix.join(path.posix.dirname(feature.queuePath), spec.file);
62
+ failures.push({ kind: 'unaccepted-done', feature: feature.feature, specId: spec.id, file, queuePath: feature.queuePath,
63
+ message: `Joycraft gate: ${feature.feature} spec ${spec.id} (${file}) is done with no accepted report, owner acceptance or waiver. `
64
+ + 'Set it back to in-review in the queue and the spec, get an independent review, then complete it with '
65
+ + `node .joycraft/runtime/completion.mjs finalize-review --queue ${feature.queuePath} --spec ${spec.id} --report <report.json>` });
66
+ }
67
+ }
68
+ const owner = new Map(status.features.flatMap(feature => feature.specs.map(row => [row.file, feature])));
69
+ for (const item of status.drift) {
70
+ const step = driftStep(item, owner.get(item.file));
71
+ failures.push({ kind: 'drift', feature: item.feature, specId: item.specId, file: item.file,
72
+ message: `Joycraft gate: ${item.feature} spec ${item.specId} (${item.file}) drifted: queue says ${item.queue}, spec frontmatter says ${item.frontmatter}. ${step}` });
73
+ }
74
+ return { failures, skipped };
75
+ }
76
+
77
+ // The Claude Code Stop hook. `.claude/settings.json` is the user's file: the
78
+ // hook subcommand edits its text in place, so every byte it does not own keeps
79
+ // its value. Joycraft's hook is the one whose command is exactly hookCommand.
80
+ // Claude Code sends the agent back only when a Stop hook exits 2, with the
81
+ // reason on stderr; `check` does that and reads nothing from stdin, so the
82
+ // result is the same when the event says stop_hook_active.
83
+ export const settingsFile = '.claude/settings.json';
84
+ export const hookCommand = 'node "$CLAUDE_PROJECT_DIR"/.joycraft/runtime/gate.mjs check --root "$CLAUDE_PROJECT_DIR"';
85
+ const hookGroup = { hooks: [{ type: 'command', command: hookCommand }] };
86
+ // What `--on` changed, so `--off` restores the earlier bytes when nobody edited the file since.
87
+ const stateFile = '.joycraft/local/gate-hook.json';
88
+
89
+ function claudeHost(root) {
90
+ try {
91
+ const manifest = JSON.parse(readFileSync(path.join(root, '.joycraft/installation.json'), 'utf8'));
92
+ return (Array.isArray(manifest?.hosts) ? manifest.hosts : [manifest?.harness]).includes('claude');
93
+ } catch { return false; }
94
+ }
95
+
96
+ // Offsets of every value in valid JSON text: objects and arrays keep their
97
+ // entries ({ key, start, end, value }) so one entry can be cut or added.
98
+ function locate(text) {
99
+ let index = 0;
100
+ const space = () => { while (index < text.length && /\s/.test(text[index])) index += 1; };
101
+ const string = () => {
102
+ const start = index;
103
+ for (index += 1; text[index] !== '"'; index += text[index] === '\\' ? 2 : 1);
104
+ index += 1;
105
+ return JSON.parse(text.slice(start, index));
106
+ };
107
+ const value = () => {
108
+ space();
109
+ const start = index;
110
+ const open = text[index];
111
+ if (open === '{' || open === '[') {
112
+ const entries = [];
113
+ index += 1;
114
+ space();
115
+ while (text[index] !== (open === '{' ? '}' : ']')) {
116
+ space();
117
+ const entryStart = index;
118
+ let key;
119
+ if (open === '{') { key = string(); space(); index += 1; }
120
+ const item = value();
121
+ entries.push({ key, start: entryStart, end: item.end, value: item });
122
+ space();
123
+ if (text[index] === ',') index += 1;
124
+ space();
125
+ }
126
+ index += 1;
127
+ return { type: open === '{' ? 'object' : 'array', start, end: index, entries };
128
+ }
129
+ if (open === '"') { string(); return { type: 'string', start, end: index }; }
130
+ while (index < text.length && !/[\s,\]}]/.test(text[index])) index += 1;
131
+ return { type: 'literal', start, end: index };
132
+ };
133
+ return value();
134
+ }
135
+
136
+ const member = (node, key) => node.entries.findLast(entry => entry.key === key);
137
+ const isOurs = (text, entry) => {
138
+ const hook = JSON.parse(text.slice(entry.value.start, entry.value.end));
139
+ return isObject(hook) && hook.type === 'command' && hook.command === hookCommand;
140
+ };
141
+
142
+ /** Insert one entry at the end of a container, indented like the file. */
143
+ function insert(text, container, value, key) {
144
+ const eol = text.includes('\r\n') ? '\r\n' : '\n';
145
+ const unit = /\n([ \t]+)\S/.exec(text)?.[1] ?? ' ';
146
+ const lineStart = text.lastIndexOf('\n', container.start) + 1;
147
+ const outer = /^[ \t]*/.exec(text.slice(lineStart))[0];
148
+ const inner = outer + unit;
149
+ const entry = `${key === undefined ? '' : `${JSON.stringify(key)}: `}${JSON.stringify(value, null, unit).split('\n').join(eol + inner)}`;
150
+ const last = container.entries.at(-1);
151
+ if (last) return text.slice(0, last.end) + `,${eol}${inner}${entry}` + text.slice(last.end);
152
+ const at = container.start + 1;
153
+ const closing = text.slice(at, container.end - 1).includes('\n') ? '' : eol + outer;
154
+ return text.slice(0, at) + eol + inner + entry + closing + text.slice(at);
155
+ }
156
+
157
+ /** Cut one entry and its separator out of a container. */
158
+ function cut(text, container, index) {
159
+ const { entries } = container;
160
+ if (index > 0) return text.slice(0, entries[index - 1].end) + text.slice(entries[index].end);
161
+ if (entries.length > 1) return text.slice(0, entries[0].start) + text.slice(entries[1].start);
162
+ return text.slice(0, container.start + 1) + text.slice(container.end - 1);
163
+ }
164
+
165
+ function readSettings(root) {
166
+ const file = localPath(root, settingsFile, true);
167
+ const before = existsSync(file) ? readFileSync(file, 'utf8') : null;
168
+ const text = before ?? '{}\n';
169
+ let data;
170
+ try { data = JSON.parse(text.replace(/^/, '')); } catch (error) { throw new Error(`${settingsFile} is not valid JSON (${error.message}); nothing was written`); }
171
+ if (!isObject(data)) throw new Error(`${settingsFile} is not a JSON object; nothing was written`);
172
+ return { file, before, text, data };
173
+ }
174
+
175
+ const hookOn = data => isObject(data.hooks) && Array.isArray(data.hooks.Stop)
176
+ && data.hooks.Stop.some(group => Array.isArray(group?.hooks) && group.hooks.some(hook => hook?.type === 'command' && hook.command === hookCommand));
177
+
178
+ /** The settings text with Joycraft's Stop hook added; change is 'none' when it is already there. */
179
+ export function planHook(root = process.cwd()) {
180
+ const { file, before, text, data } = readSettings(root);
181
+ if (hookOn(data)) return { file, before, after: before, change: 'none' };
182
+ const tree = locate(text);
183
+ const hooks = member(tree, 'hooks');
184
+ let after;
185
+ if (!hooks) after = insert(text, tree, { Stop: [hookGroup] }, 'hooks');
186
+ else if (hooks.value.type !== 'object') throw new Error(`"hooks" in ${settingsFile} is not an object; nothing was written`);
187
+ else {
188
+ const stop = member(hooks.value, 'Stop');
189
+ if (!stop) after = insert(text, hooks.value, [hookGroup], 'Stop');
190
+ else if (stop.value.type !== 'array') throw new Error(`"hooks.Stop" in ${settingsFile} is not an array; nothing was written`);
191
+ else after = insert(text, stop.value, hookGroup);
192
+ }
193
+ return { file, before, after, change: 'add' };
194
+ }
195
+
196
+ /** The settings text with every Joycraft Stop hook removed, and the containers it leaves empty, which `removed` names. */
197
+ function withoutHook(text) {
198
+ const removed = new Set();
199
+ for (;;) {
200
+ const tree = locate(text);
201
+ const hooks = member(tree, 'hooks');
202
+ const stop = hooks?.value.type === 'object' ? member(hooks.value, 'Stop') : undefined;
203
+ if (stop?.value.type !== 'array') return { text, removed: [...removed] };
204
+ const groups = stop.value.entries;
205
+ const groupIndex = groups.findIndex(group => group.value.type === 'object' && member(group.value, 'hooks')?.value.type === 'array'
206
+ && member(group.value, 'hooks').value.entries.some(entry => isOurs(text, entry)));
207
+ if (groupIndex === -1) return { text, removed: [...removed] };
208
+ const list = member(groups[groupIndex].value, 'hooks').value;
209
+ const ours = list.entries.findIndex(entry => isOurs(text, entry));
210
+ if (list.entries.length > 1) text = cut(text, list, ours);
211
+ else if (groups.length > 1) text = cut(text, stop.value, groupIndex);
212
+ else if (hooks.value.entries.length > 1) { text = cut(text, hooks.value, hooks.value.entries.indexOf(stop)); removed.add('the "hooks.Stop" list'); }
213
+ else { text = cut(text, tree, tree.entries.indexOf(hooks)); removed.add('the "hooks.Stop" list').add('the "hooks" object'); }
214
+ }
215
+ }
216
+
217
+ function writeState(root, value) {
218
+ const local = path.join(root, '.joycraft/local');
219
+ mkdirSync(local, { recursive: true });
220
+ if (!existsSync(path.join(local, '.gitignore'))) writeFileSync(path.join(local, '.gitignore'), '*\n');
221
+ writeFileSync(localPath(root, stateFile, true), `${JSON.stringify(value, null, 2)}\n`);
222
+ }
223
+
224
+ function readState(root) {
225
+ try { return JSON.parse(readFileSync(localPath(root, stateFile), 'utf8')); } catch { return null; }
226
+ }
227
+
228
+ const byHand = 'Run the check by hand: node .joycraft/runtime/gate.mjs check';
229
+
230
+ /** `hook --plan|--on|--off`: show, add or remove Joycraft's Stop hook in `.claude/settings.json`. */
231
+ export function hook(root, action) {
232
+ if (action !== 'off' && !claudeHost(root)) {
233
+ return { change: 'none', claude: false,
234
+ message: `The gate hook is for Claude Code only for now, and .joycraft/installation.json lists no claude host. Nothing was written. ${byHand}` };
235
+ }
236
+ if (action === 'off') {
237
+ const { file, before, data } = readSettings(root);
238
+ const state = readState(root);
239
+ if (before === null || !hookOn(data)) {
240
+ if (state) rmSync(localPath(root, stateFile));
241
+ return { file: settingsFile, change: 'none', message: `Joycraft's Stop hook is not in ${settingsFile}. Nothing was changed.` };
242
+ }
243
+ if (state?.after === before) {
244
+ if (state.before === null) rmSync(file); else writeFileSync(file, state.before);
245
+ rmSync(localPath(root, stateFile));
246
+ return { file: settingsFile, change: 'removed', message: `Removed Joycraft's Stop hook from ${settingsFile}. Every other line is as it was.` };
247
+ }
248
+ // No usable record: say what was cut, and claim nothing about the bytes before --on.
249
+ const { text: after, removed } = withoutHook(before);
250
+ writeFileSync(file, after);
251
+ if (state) rmSync(localPath(root, stateFile));
252
+ const empty = removed.length ? ` Without the hook, ${removed.join(' and ')} ${removed.length > 1 ? 'were' : 'was'} empty, so the command removed ${removed.length > 1 ? 'them' : 'it'} too.` : '';
253
+ return { file: settingsFile, change: 'removed', message: `Removed Joycraft's Stop hook from ${settingsFile}.${empty} No other setting was removed.` };
254
+ }
255
+ const plan = planHook(root);
256
+ if (plan.change === 'none') return { file: settingsFile, change: 'none', message: `Joycraft's Stop hook is already in ${settingsFile}. Nothing was changed.` };
257
+ if (action === 'plan') {
258
+ return { file: settingsFile, change: 'add', command: hookCommand, before: plan.before, after: plan.after,
259
+ message: `Plan only; nothing was written. Show this change to the user and run gate.mjs hook --on on their yes.` };
260
+ }
261
+ mkdirSync(path.dirname(plan.file), { recursive: true });
262
+ writeFileSync(localPath(root, settingsFile, true), plan.after);
263
+ writeState(root, { file: settingsFile, before: plan.before, after: plan.after });
264
+ return { file: settingsFile, change: 'added',
265
+ message: `Added Joycraft's Stop hook to ${settingsFile}. Claude Code now runs the gate check each time it ends a reply. Turn it off with: node .joycraft/runtime/gate.mjs hook --off` };
266
+ }
267
+
268
+ export function main(argv = process.argv.slice(2)) {
269
+ const usage = 'Usage: gate.mjs check [--root <project>] [--verbose] | gate.mjs hook --plan|--on|--off [--root <project>]';
270
+ if (argv[0] === 'hook') {
271
+ const actions = { '--plan': 'plan', '--on': 'on', '--off': 'off' };
272
+ let action;
273
+ let root;
274
+ for (let index = 1; index < argv.length; index += 1) {
275
+ if (actions[argv[index]] && action === undefined) { action = actions[argv[index]]; continue; }
276
+ if (argv[index] === '--root' && root === undefined && typeof argv[index + 1] === 'string' && !argv[index + 1].startsWith('--')) {
277
+ root = argv[index + 1]; index += 1; continue;
278
+ }
279
+ throw new Error(usage);
280
+ }
281
+ if (action === undefined) throw new Error(usage);
282
+ const result = hook(path.resolve(root ?? '.'), action);
283
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
284
+ process.exitCode = 0;
285
+ return result;
286
+ }
287
+ if (argv[0] !== 'check') throw new Error(usage);
288
+ const flags = {};
289
+ for (let index = 1; index < argv.length; index += 1) {
290
+ if (argv[index] === '--verbose' && !flags.verbose) { flags.verbose = true; continue; }
291
+ if (argv[index] === '--root' && flags.root === undefined && typeof argv[index + 1] === 'string' && !argv[index + 1].startsWith('--')) {
292
+ flags.root = argv[index + 1]; index += 1; continue;
293
+ }
294
+ throw new Error(usage);
295
+ }
296
+ const result = checkGates(path.resolve(flags.root ?? '.'));
297
+ const lines = [...(flags.verbose ? result.skipped.map(item => item.message) : []), ...result.failures.map(item => item.message)];
298
+ if (lines.length) process.stderr.write(`${lines.join('\n')}\n`);
299
+ process.exitCode = result.failures.length ? 2 : 0;
300
+ return result;
301
+ }
302
+
303
+ // Node runs the main module from its real path; a hook may name it through a symlinked project path.
304
+ const invoked = (() => { try { return realpathSync(process.argv[1]); } catch { return null; } })();
305
+ if (invoked && import.meta.url === pathToFileURL(invoked).href) {
306
+ const prefix = process.argv[2] === 'hook' ? 'Gate hook stopped' : 'Gate check stopped';
307
+ try { main(); } catch (error) { process.stderr.write(`${prefix}: ${error.message}\n`); process.exitCode = 1; }
308
+ }
@@ -20,7 +20,7 @@ function queuePaths(root) {
20
20
  .map(entry => `${featuresHome}/${entry.name}/${queueName}`).sort();
21
21
  }
22
22
 
23
- const accepted = spec => spec.status === 'done' && (isObject(spec.acceptedReport) || isObject(spec.ownerAcceptance) || isObject(spec.waiver));
23
+ export const accepted = spec => spec.status === 'done' && (isObject(spec.acceptedReport) || isObject(spec.ownerAcceptance) || isObject(spec.waiver));
24
24
 
25
25
  function openDecisions(root, folder) {
26
26
  const brief = `${folder}/brief.md`;
package/payload/PIN CHANGED
@@ -1,44 +1,46 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "source": "joycraft-prototype",
4
- "tag": "field-17",
5
- "commit": "0e88e6da3adc605a306db1ec058a4690b2eb5cb2",
4
+ "tag": "field-20",
5
+ "commit": "bc63e17a87ae0be86a87a44ac37c685eb72ead0a",
6
6
  "files": {
7
7
  ".agents/skills/joycraft-cleanup/SKILL.md": "99ce785e551be33412ac7a99ce44585a9b2be4440617caac273680383b4f7057",
8
- ".agents/skills/joycraft-context/SKILL.md": "e2f85baa47058fd61811fdb60d0cb41fb3f505f3957812d929db95bb99124f1b",
8
+ ".agents/skills/joycraft-context/SKILL.md": "8eb9374846b8f0d99280217b3fc73cfddac97d72f3ff6f3aca4a86af58dd8b85",
9
9
  ".agents/skills/joycraft-decompose/SKILL.md": "71b518d4fa8aeda5d1c0e72f34b3f7f846b3bba055adf509344b40bea35f070e",
10
- ".agents/skills/joycraft-entry/SKILL.md": "6b2ac0e52f0751c7b7587b495349c29f707c61421312dc9ad8d3821aec936855",
11
- ".agents/skills/joycraft-implement/SKILL.md": "65909a6e3a320d8c0591e10ea1fc26469facadc27dafd3060dd0eabaf06890d9",
10
+ ".agents/skills/joycraft-entry/SKILL.md": "2d9c665416715fb9adb389f57c9d2da97d3d59f577ca4caae9539c6b98cff83b",
11
+ ".agents/skills/joycraft-implement/SKILL.md": "7c7ed88f23103a973f1f275528b8011229d5dec0180910dd98498cff4f6f52c1",
12
12
  ".agents/skills/joycraft-retro/SKILL.md": "156f36cb047604c734bf273bd02822d964b6af86619ed6c2a30fa6d79eb9a986",
13
13
  ".agents/skills/joycraft-retro/agents/openai.yaml": "f0eb4732261635f41e08f0bbe9a931d62fd8ac645149d3406e6fc7e16a81750b",
14
- ".agents/skills/joycraft-session-end/SKILL.md": "e2661af991a72d51036d266b3ebeabcee44d5e602f7b35ea0e40c9c95c171a66",
15
- ".agents/skills/joycraft-testing/SKILL.md": "8c89f3aa996e7de0a0c05d00081a8f24077311c180638abff7aaac9b87f6f89e",
14
+ ".agents/skills/joycraft-session-end/SKILL.md": "e3ef930c1c528f7e6dd6a44a9cb1b352bc8a69d99832ffb1c954a532e036271f",
15
+ ".agents/skills/joycraft-testing/SKILL.md": "aa3b59c380a35a2199646009ccf9be7381edf290d1f07e56994d50b303a6ee12",
16
16
  ".agents/skills/joycraft-ui-slice/SKILL.md": "baf394edc4a31e582cb936c525d8ad28bea42a713ec3114f5921fa7e2bff833f",
17
17
  ".agents/skills/joycraft-ui-slice/scripts/serve.mjs": "c16858800b6fbe6f7a3a21b21e785ad70c9a89a3fe970bc08701fefeac5042fa",
18
- ".agents/skills/joycraft-verify/SKILL.md": "219f08d5f66d6c63338c7d4cc75e81fe7d2d993723728876136ab8ca5ed6f8c5",
18
+ ".agents/skills/joycraft-verify/SKILL.md": "6b3823751765636bae90b253fd8938dfacf96705296212856fe1ff22289e3176",
19
19
  ".claude/agents/joycraft-implementer.md": "30b26779bd49d2d66758bcb26442e78755b018a3830ac52ff634ebf057ce1cc5",
20
20
  ".claude/agents/joycraft-reviewer.md": "d671eb39827d5139d9d458d4cb7f5ce624bd40ec8cc5479f9d285bb787b5e5c6",
21
21
  ".joycraft/assets/artifacts/kit.css": "9c19cc52f16eb1d1beb6222ec4e206c567daf9952ff1f5597ea4d6050b72125a",
22
22
  ".joycraft/assets/artifacts/kit.js": "c60ae4441fb20146677313b27f949598889f40e8b90167b70db04f997854966d",
23
23
  ".joycraft/assets/artifacts/transports.js": "318e97895468b47f07febc913d3a6e100b0ad19b78b3a4fc51bebc488e67c25d",
24
24
  ".joycraft/contracts/types.d.ts": "e91f6a4199c0219cda3630a27ee0281ef94d4284221910840961061ee3b30d4f",
25
- ".joycraft/references/architecture.md": "52eaaa4b88053481c9f8cad2418ea0f1db880184c3a50c95901f30f24be75852",
25
+ ".joycraft/references/architecture.md": "4e225ba23ed72d3d7b1af9bfceeb708583eede79978c294724b917ad94674be9",
26
26
  ".joycraft/references/archive.md": "e9e662096f9e95d132c29e07d1a2624ca0826b5e9c1042f411e4ea2bf3805b67",
27
27
  ".joycraft/references/artifacts.md": "7fab219f6d6d8b23ef3b44a509f637b085b551b34f28622d6dc1167a7f484c6a",
28
28
  ".joycraft/references/cleanup.md": "aa784c63442a289c67de359d82c78abca3aa8cab5b5e2d91fcd731b45c209003",
29
29
  ".joycraft/references/completion.md": "7e6b1fe95aab6d97e514995a35f0f6cc67bdea18e4570565e2eef4900e0da01b",
30
- ".joycraft/references/context.md": "df72d3b59d55f0d9741234d4a3d7b56532f560d787c88d5d8630d954472bc430",
30
+ ".joycraft/references/context.md": "b94dd48a427aaafe826116bac100375cbae565b1ba3239fd7812c56eac724577",
31
31
  ".joycraft/references/delivery.md": "1afc417ee3922ebf5e84c0ae87796d6cb6305679c0257ed38a35f396949de5e8",
32
- ".joycraft/references/dispatch.md": "a1c03473f98b44e88de0d60829b5abc2a11537f53abd1d9c7f84a5a50a140a21",
32
+ ".joycraft/references/dispatch.md": "62e8ad3abf4700f63963fb21a17d03569b78b5100538c10bc37d559679db39b8",
33
33
  ".joycraft/references/doc-cleanup-LICENSE.md": "a9e210590e2d0ebf719fe3801f1c0fda8f940af28656ff36e908c4315d94f886",
34
+ ".joycraft/references/gates.md": "8061e2ecc74b494e21ab77c734d2ae591964af3211c76147bea9f915969c5932",
34
35
  ".joycraft/references/knowledge.md": "a08a117a5d0ae65a45dfd8ab3f3da92dd3c7aeedaa09ae1d71ddf3d6528c7f95",
35
36
  ".joycraft/references/recurring-failures.md": "7080f6c55492bc19c2897f4f0b128a830a71cdb516678c79ff6e97ffa1dc6b86",
36
- ".joycraft/references/retro.md": "f359eae19747777fb4687c1bc7eb280f0319ae629ee62913346e60fc56551562",
37
- ".joycraft/references/setup.md": "a9bd9072adc9f021b46287ff0422281ddb2285ac34738b6e29ad11cc60e8a6e5",
37
+ ".joycraft/references/retro.md": "5f24b942f1faf308308caf5d0c543320fedbb69c59c2c240ef979cab50bae211",
38
+ ".joycraft/references/settings.md": "efaa8ea977d7dab9ec011dc0f83f652eb0e7f0098994a89d2d0ee07027b137d6",
39
+ ".joycraft/references/setup.md": "993ae51a753f5d55e13452787fc3f4bfd3df930e0c29730331639007e2ac4812",
38
40
  ".joycraft/references/testing.md": "ddbc0e69212f4bf29f32f65e139c016b12eb40c29f621a99510129bedf292950",
39
41
  ".joycraft/references/update.md": "36af36ab3d47b5ea46a8f71090333771e5e1deaa6ca19739a75c9fd4aea14eba",
40
42
  ".joycraft/references/workflow.md": "5b330debc6759b8f7975b159632f51074802067291fe4f4bebfb344f5b60cc52",
41
- ".joycraft/references/worktrees.md": "fb18af0cd76d4e3c5d5b892a7ae10946f21f189e642243235c188b571635f735",
43
+ ".joycraft/references/worktrees.md": "ad5645d2811e59da682c03f1cbdd1fb15abcc094fba74542c848548033890dba",
42
44
  ".joycraft/runtime/archive.mjs": "82b4d9567942a4abd21594ea299c4d323a8306ec7545cb0030431c87bd37f8b2",
43
45
  ".joycraft/runtime/artifacts/cli.mjs": "b3472857b6f8f680dc0d8a7be6495c502a430f5d0c47c88d44b42217e541b528",
44
46
  ".joycraft/runtime/artifacts/decisions.mjs": "e54fe173ca9050d495fd20b05aaedee8c918f3074553b6b7292cb40f500cbcb2",
@@ -55,8 +57,9 @@
55
57
  ".joycraft/runtime/coordinator.mjs": "9252a40ee3a82808a780158427b02129d8075679ed329bce2dd74168c7eb42ab",
56
58
  ".joycraft/runtime/delivery.mjs": "4fe897714eec33b24003f0d69abe1522a5199193ab7333fa6421776ee048df1c",
57
59
  ".joycraft/runtime/dispatch-preflight.mjs": "a86736e013dcca9f1f8a2ab1abd42cb81e614373b2140b272ca6ac91a0525d34",
58
- ".joycraft/runtime/dispatch-start.mjs": "b8d27b53566062c79cb95bf3f89bcb3e4abc9dd9dc15612cfced8685cf3a1c41",
60
+ ".joycraft/runtime/dispatch-start.mjs": "fd3654e78cd5db9ada013ed95ea9259d53725e41bcee399ce2cb1a7d9e54a579",
59
61
  ".joycraft/runtime/evidence.mjs": "ee5bec5c9e5f1372a994a899b8161ff88d96a1d0ccf552d75de87a61c1c04bd3",
62
+ ".joycraft/runtime/gate.mjs": "c714f50f9c228cf45455976ac1e8a1d91fe3f478f4f9743b9e24d87ced232da2",
60
63
  ".joycraft/runtime/identity.mjs": "9854974dfb24f4469668e4db0dd6d2279bb2298157ff6262bb7864ef8e9ad174",
61
64
  ".joycraft/runtime/kickoff.mjs": "9d96998bff94662863182b9a922f26732c649b7a0b0130b6da7d63ec73eb3590",
62
65
  ".joycraft/runtime/redact.mjs": "cc8c0fe5e8d8fe78116ef126f6eee757a247739084e19c342bcf09a2b06524bc",
@@ -64,7 +67,7 @@
64
67
  ".joycraft/runtime/review-tools.json": "e0b0f5625654bba5f02d49710356aa1740fd42dd282eef6a29af361396915763",
65
68
  ".joycraft/runtime/review-tools.mjs": "15d426558a3884628147debb29136a20f746c3f184c52d6474ad59c222e5d8d5",
66
69
  ".joycraft/runtime/scope.mjs": "e2cdd929596246bf24e18850698db440119badc7068a3c5beab03ded45abbd65",
67
- ".joycraft/runtime/status.mjs": "3c5bc62c2c0b440da37af950c28f9278c1f743ff4566d3b6c5685465075239af",
70
+ ".joycraft/runtime/status.mjs": "916cd7e839a90878e0ffa4dd2e7367575ec541808293b5b377bf39331f727585",
68
71
  ".joycraft/runtime/trace.mjs": "b7924f759b07991f4135698df9c32654631a325957f0f8de5c2ca1262c0a836a",
69
72
  ".joycraft/runtime/update-check.mjs": "987b65605a26ea71b6417fda7b48753980e0d8afa20eadbd527143850a93319e",
70
73
  ".joycraft/runtime/wiring.mjs": "e08bcc604d40560f260edbc3499a4481a1efa7c7d2fa80545caa858827404667",
@@ -78,7 +81,7 @@
78
81
  ".joycraft/templates/queue.json": "88f922b6cc47b80befc27df86a143d6bae0b30869c46d712958b64291e5ebcc2",
79
82
  ".joycraft/templates/spec.md": "5f4b1490c2ba2e47ced1ef5b369fe3e41386eb61386c42c7a561b1e8af02ea5e",
80
83
  ".joycraft/templates/ui-slice.html": "0c3cf45709ff37815f8f0550b4b9431cb935589b282d40e8688b310a91de2274",
81
- "scripts/export.mjs": "016d675b19ba3122468ce34817b8a9c444be919aa4ec583842cd9bc16d299243",
84
+ "scripts/export.mjs": "085433a46d9bba37685d52611c881a1c4891c38d607453c6cbd47acb629054f8",
82
85
  "scripts/hook-paths.mjs": "fed8a147a9bf6501bfda1e4c7f015b41947277920dc2bf49c23ad826cfb0c724",
83
86
  "scripts/legacy-hooks.mjs": "d44f841e28d10b0a6aacf999bdd3e8bcec0feb742fa18c7459d6265d1d4776ba",
84
87
  "scripts/legacy-inventory.json": "92455cceac13cc8bd27a0cbd5c16df71a44a82bf7a18280f5ba05b5dde2908ba"
@@ -191,8 +191,11 @@ export async function exportBundle({ sourceRoot, targetRoot, check = false, hook
191
191
  const bytes = await readFile(join(source, path));
192
192
  return harness === 'claude' && path.endsWith('.md') ? Buffer.from(bytes.toString('utf8').replaceAll('.agents/skills/', '.claude/skills/')) : bytes;
193
193
  };
194
- // Native hooks are optional; their installer loads only when hooks are requested.
195
- const hookInstaller = hooks ? await import('./install-hooks.mjs') : null;
194
+ // Native hooks are optional and not part of every bundle. Their installer
195
+ // loads only when hooks are requested and it is present beside this script.
196
+ const hookInstallerUrl = new URL('./install-hooks.mjs', import.meta.url);
197
+ if (hooks && !(await statOrNull(fileURLToPath(hookInstallerUrl)))) throw new Error('Native hooks are not part of this bundle; export with --without-hooks');
198
+ const hookInstaller = hooks ? await import(hookInstallerUrl) : null;
196
199
  if (hooks && !files.includes(hookInstaller.hookRuntimePath)) throw new Error('The source bundle has no hook runtime');
197
200
  const installed = await readInstallationManifest(target);
198
201
  const legacy = upgrade ? await legacyPlan(target, installed, new Set(files.map(destinationPath))) : { archive: [], conflicts: [] };