joycraft 1.5.0 → 1.5.2

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 CHANGED
@@ -113,6 +113,7 @@ consideration ([decision D6](docs/context/decision-log.md)).
113
113
  ```text
114
114
  We keep a wiki in <where>. Link it from the context map, and keep it up to date
115
115
  each time a feature is archived.
116
+ Do not commit, publish, or ask me for API keys.
116
117
  ```
117
118
 
118
119
  ### Settings
@@ -120,9 +121,11 @@ each time a feature is archived.
120
121
  Joycraft works with no settings. To change one, say what you want:
121
122
 
122
123
  ```text
123
- Keep Joycraft's briefs and specs in working/features.
124
- Whenever a feature is archived, run our wiki sync script.
125
- The page docs/context/auction-rules.md describes src/auction. Flag it when that code changes.
124
+ Change these Joycraft settings, and show me the change before you write it:
125
+ - Keep Joycraft's briefs and specs in working/features, and finished features in working/archive.
126
+ - Whenever a feature is archived, run our wiki sync script.
127
+ - The page docs/context/auction-rules.md describes src/auction. Flag it when that code changes.
128
+ Do not commit, publish, or ask me for API keys.
126
129
  ```
127
130
 
128
131
  The agent writes the change to `joycraft.yaml` at the project root, shows it to you
@@ -277,11 +280,12 @@ Joycraft's rule is that only an accepted review completes a spec. Without the
277
280
  gates, this rule is an instruction in a skill. An agent can forget the rule or skip
278
281
  it, for example late in a long session. The gates make the rule a check.
279
282
 
280
- **What the gate stops.** The gate check finds three problems:
283
+ **What the gate stops.** The gate check finds four problems:
281
284
 
282
285
  - A spec is marked done with no accepted review, no acceptance from you and no waiver.
283
286
  - A spec has one status in the queue and a different status in the spec file.
284
287
  - Joycraft cannot read a queue file or a spec file.
288
+ - You accepted old specs as they are, and the file with your words is missing or changed.
285
289
 
286
290
  It sends the agent back with the spec or file name and the next step. A spec that waits at
287
291
  `in-review` is not a problem.
@@ -289,14 +293,30 @@ It sends the agent back with the spec or file name and the next step. A spec tha
289
293
  **Why you want it.** Use the gates for long sessions and for sessions that you do
290
294
  not watch. A prompt tells the agent what to do, but a prompt is not a guarantee.
291
295
  With the gates on, Claude Code runs the check each time the agent tries to stop. The
292
- agent cannot stop until the problem is gone.
296
+ agent cannot stop until the problem is gone. The hook can stop the agent at a spec
297
+ marked done with no accepted review. Then the agent sets the spec back to `in-review`
298
+ without asking you.
293
299
 
294
300
  **Before you turn them on.** An older project can have specs marked done with no
295
- accepted review. The check sends each one back for a review. To see them first, say:
301
+ review on record, from the time before the gates. Turning on the gates runs the check
302
+ first. The hook goes in only after a clean check. The agent names these specs and asks
303
+ you one question: accept them as they are, or send them back for review.
304
+
305
+ - If you accept them, the agent writes your words, exactly as you said them, in a
306
+ decision file beside the queue. Commit that file. The agent then accepts the specs
307
+ with one command. The specs stay done.
308
+ - If you send them back, the agent sets each spec back to `in-review`.
309
+
310
+ The command refuses a spec that was submitted for review or that has a review report.
311
+ The runtime checks only the record. It cannot check that you said the words in the
312
+ file. The agent fixes the other problems itself, tells you what it changed, and checks
313
+ again. It stops and asks you only about a file that it cannot read. A look at the
314
+ problems first is optional. To see them, say:
296
315
 
297
316
  ```text
298
317
  Run Joycraft's gate check with `node .joycraft/runtime/gate.mjs check` and show me
299
- what it names. Change nothing yet.
318
+ what it names. Change nothing yet. For each spec it names, tell me what you recommend.
319
+ Do not commit, publish, or ask me for API keys.
300
320
  ```
301
321
 
302
322
  Do this also after you update an older project to 1.4.1 or later, because session
@@ -305,7 +325,9 @@ end now runs the same check.
305
325
  **Turn them on.** Say:
306
326
 
307
327
  ```text
308
- Turn on Joycraft's gates.
328
+ Turn on Joycraft's gates. Show me the change to .claude/settings.json on a page,
329
+ and write it only on my yes.
330
+ Do not commit, publish, or ask me for API keys.
309
331
  ```
310
332
 
311
333
  The agent shows you the change to `.claude/settings.json` on a page. It writes the
@@ -315,7 +337,8 @@ also offers the gates one time.
315
337
  **Turn them off.** Say:
316
338
 
317
339
  ```text
318
- Turn off Joycraft's gates.
340
+ Turn off Joycraft's gates. Remove only Joycraft's hook, and tell me what you removed.
341
+ Do not commit, publish, or ask me for API keys.
319
342
  ```
320
343
 
321
344
  The agent removes Joycraft's hook. Your own hooks stay. If you remove Joycraft from
@@ -396,7 +419,9 @@ always your choice.
396
419
  This is an instruction the agent follows, so it can forget. To check yourself, ask:
397
420
 
398
421
  ```text
399
- Check for a Joycraft update.
422
+ Check for a Joycraft update. If there is one, run
423
+ `npx joycraft@latest update . --plan --json`, show me what changes, and update on my yes.
424
+ Do not commit, publish, or ask me for API keys.
400
425
  ```
401
426
 
402
427
  ## Hosts
package/dist/cli.js CHANGED
@@ -1428,8 +1428,25 @@ function recoverLegacy(dir) {
1428
1428
  }
1429
1429
 
1430
1430
  // src/rollback.ts
1431
+ import { spawnSync } from "child_process";
1431
1432
  import { copyFileSync as copyFileSync3, existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, rmdirSync as rmdirSync2, rmSync as rmSync3, statSync } from "fs";
1432
1433
  import { dirname as dirname4, join as join4, relative, resolve as resolve3, sep as sep3 } from "path";
1434
+ var SETTINGS = ".claude/settings.json";
1435
+ var RUNTIME = ".joycraft/runtime/";
1436
+ var GATE = `${RUNTIME}gate.mjs`;
1437
+ var GATE_HOOK_COMMAND = 'node "$CLAUDE_PROJECT_DIR"/.joycraft/runtime/gate.mjs check --root "$CLAUDE_PROJECT_DIR"';
1438
+ function gateHookIn(root) {
1439
+ const file = join4(root, SETTINGS);
1440
+ if (!existsSync4(file)) return false;
1441
+ let data;
1442
+ try {
1443
+ data = JSON.parse(readFileSync4(file, "utf8").replace(/^\uFEFF/, ""));
1444
+ } catch {
1445
+ return false;
1446
+ }
1447
+ const stop = data?.hooks?.Stop;
1448
+ return Array.isArray(stop) && stop.some((group) => Array.isArray(group?.hooks) && group.hooks.some((hook) => hook?.type === "command" && hook.command === GATE_HOOK_COMMAND));
1449
+ }
1433
1450
  function inside3(root, path) {
1434
1451
  const full = resolve3(root, path);
1435
1452
  if (full !== root && !full.startsWith(root + sep3)) throw new Error(`Path escapes the project: ${path}`);
@@ -1473,12 +1490,14 @@ function planRollback(dir, stamp2, { force = false } = {}) {
1473
1490
  if (existsSync4(inside3(root, from)) && !removing.has(from)) blocked.push(from);
1474
1491
  else restore.push(from);
1475
1492
  }
1476
- return { root, backup, restore, remove, edited, blocked };
1493
+ const gateHook = !record.settingsBackup && remove.some((path) => path.startsWith(RUNTIME)) && gateHookIn(root);
1494
+ return { root, backup, restore, remove, edited, blocked, gateHook };
1477
1495
  }
1478
1496
  function formatRollback(plan) {
1479
1497
  return [
1480
1498
  `Roll back to before ${plan.backup}:`,
1481
1499
  ` restore ${plan.restore.length} 0.7 file(s) \xB7 remove ${plan.remove.length} 1.0 file(s)`,
1500
+ ...plan.gateHook ? [` remove Joycraft's gate Stop hook from ${SETTINGS}; rollback removes runtime files it needs`] : [],
1482
1501
  ...plan.edited.map((path) => ` kept, edited after the migration (use --force to remove): ${path}`),
1483
1502
  ...plan.blocked.map((path) => ` not restored, a file is already there: ${path}`),
1484
1503
  ` The backup stays in ${plan.backup}.`
@@ -1496,6 +1515,10 @@ function prune(root, path) {
1496
1515
  function applyRollback(plan) {
1497
1516
  const { root } = plan;
1498
1517
  const record = JSON.parse(readFileSync4(join4(root, plan.backup, MIGRATION_RECORD), "utf8"));
1518
+ if (plan.gateHook && existsSync4(join4(root, GATE))) {
1519
+ const off = spawnSync(process.execPath, [join4(root, GATE), "hook", "--off", "--root", root], { cwd: root, encoding: "utf8" });
1520
+ if (off.status !== 0) throw new Error(`Could not remove Joycraft's gate Stop hook from ${SETTINGS}; nothing was rolled back. ${off.stderr.trim()}`);
1521
+ }
1499
1522
  for (const path of plan.remove) {
1500
1523
  rmSync3(inside3(root, path), { force: true });
1501
1524
  prune(root, path);