joycraft 1.3.0 → 1.5.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 +154 -4
- package/dist/joycraft-release.json +1 -1
- package/package.json +3 -3
- package/payload/.agents/skills/joycraft-context/SKILL.md +5 -6
- package/payload/.agents/skills/joycraft-decompose/SKILL.md +9 -8
- package/payload/.agents/skills/joycraft-entry/SKILL.md +8 -19
- package/payload/.agents/skills/joycraft-implement/SKILL.md +16 -17
- package/payload/.agents/skills/joycraft-session-end/SKILL.md +10 -15
- package/payload/.agents/skills/joycraft-testing/SKILL.md +3 -9
- package/payload/.agents/skills/joycraft-verify/SKILL.md +20 -21
- package/payload/.claude/agents/joycraft-implementer.md +5 -5
- package/payload/.claude/agents/joycraft-reviewer.md +3 -6
- package/payload/.joycraft/contracts/types.d.ts +18 -0
- package/payload/.joycraft/references/architecture.md +2 -4
- package/payload/.joycraft/references/completion.md +16 -21
- package/payload/.joycraft/references/context.md +11 -34
- package/payload/.joycraft/references/dispatch.md +7 -40
- package/payload/.joycraft/references/gates.md +60 -0
- package/payload/.joycraft/references/retro.md +6 -15
- package/payload/.joycraft/references/settings.md +6 -3
- package/payload/.joycraft/references/setup.md +4 -4
- package/payload/.joycraft/references/testing.md +21 -21
- package/payload/.joycraft/references/worktrees.md +1 -1
- package/payload/.joycraft/runtime/completion.mjs +92 -6
- package/payload/.joycraft/runtime/dispatch-preflight.mjs +1 -1
- package/payload/.joycraft/runtime/dispatch-start.mjs +61 -4
- package/payload/.joycraft/runtime/evidence.mjs +134 -0
- package/payload/.joycraft/runtime/gate.mjs +308 -0
- package/payload/.joycraft/runtime/identity.mjs +5 -1
- package/payload/.joycraft/runtime/queue-check.mjs +355 -0
- package/payload/.joycraft/runtime/status.mjs +46 -5
- package/payload/PIN +31 -28
- package/payload/scripts/export.mjs +5 -2
|
@@ -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
|
+
}
|
|
@@ -184,6 +184,9 @@ export function validateQueue(queue, { select } = {}) {
|
|
|
184
184
|
if (input.state !== undefined) requireValue(input.state === 'absent' && input.kind !== 'requirement', `Verification input ${inputPath} at index ${inputIndex} may use state: absent only for code, check or fixture inputs`);
|
|
185
185
|
}
|
|
186
186
|
if (spec.verification.changeScope !== undefined) validateChangeScope(spec.verification.changeScope, relativePath);
|
|
187
|
+
if (spec.submitted !== undefined) {
|
|
188
|
+
requireValue(isObject(spec.submitted) && Object.keys(spec.submitted).every(key => key === 'at') && nonempty(spec.submitted.at) && Number.isFinite(Date.parse(spec.submitted.at)), `Invalid submit record for spec ${spec.id}`);
|
|
189
|
+
}
|
|
187
190
|
if (spec.acceptedReport !== undefined) {
|
|
188
191
|
requireValue(isObject(spec.acceptedReport) && isSha256(spec.acceptedReport.sha256), `Invalid accepted report for spec ${spec.id}`);
|
|
189
192
|
relativePath(spec.acceptedReport.path);
|
|
@@ -240,10 +243,11 @@ export function subjectIdentity(subject) {
|
|
|
240
243
|
return sha256(canonical(fields));
|
|
241
244
|
}
|
|
242
245
|
|
|
243
|
-
/** Queue status and completion receipt metadata do not change reviewed requirements. */
|
|
246
|
+
/** Queue status, the submit record and completion receipt metadata do not change reviewed requirements. */
|
|
244
247
|
function queueSpecRequirements(spec) {
|
|
245
248
|
const requirements = { ...spec };
|
|
246
249
|
delete requirements.status;
|
|
250
|
+
delete requirements.submitted;
|
|
247
251
|
delete requirements.acceptedReport;
|
|
248
252
|
delete requirements.ownerAcceptance;
|
|
249
253
|
delete requirements.waiver;
|