@bluenyang/reins 0.3.3 → 0.3.4-rc.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.
package/README.md CHANGED
@@ -15,7 +15,7 @@ knowledge lost in gitignored space, copies that drift apart. The full list is in
15
15
 
16
16
  ## Status
17
17
 
18
- **0.3.3-rc.1 is the release candidate** (intent 023): `npx @bluenyang/reins@0.3.3-rc.1`. **0.3.2 is the latest release** (intents 019–022): `npx @bluenyang/reins install`. Up to 0.2.0, skills and hooks called `npx @bluenyang/reins` during work; 0.3 removes that, and `reins update` moves a 0.1.x or 0.2.0 install over. What changed in each version is in [CHANGELOG.md](CHANGELOG.md); what comes next is in the [roadmap](docs/ROADMAP.md).
18
+ **0.3.4-rc.1 is the release candidate** (intent 024): `npx @bluenyang/reins@0.3.4-rc.1`. **0.3.3 is the latest release** (intents 019–023): `npx @bluenyang/reins install`. Up to 0.2.0, skills and hooks called `npx @bluenyang/reins` during work; 0.3 removes that, and `reins update` moves a 0.1.x or 0.2.0 install over. What changed in each version is in [CHANGELOG.md](CHANGELOG.md); what comes next is in the [roadmap](docs/ROADMAP.md).
19
19
 
20
20
  ## How it works
21
21
 
@@ -68,7 +68,7 @@ To work on reins itself: `git clone https://github.com/bluenyang/reins.git`, the
68
68
  | `install` | places the harness, detects agent tools, confirms gates, writes the gate script `.agents/harness/run-gates.sh` (it runs the project's gate commands and keeps their output for the audit) and proposes the one hook line that calls it (`--hooks` adds it to husky), adds the onboarding note; `--mode manual\|auto`, `--dry-run`, `--json` |
69
69
  | `migrate` | moves an older harness or an `.ai/` workspace onto this layout and keeps the previous `AGENTS.md` aside for the PM to reconcile; `--legacy local\|committed`, `--dry-run` |
70
70
  | `update` | re-applies the packaged harness; asks before overwriting a generated file edited by hand (`--force`); moves a 0.1.x or 0.2.0 install to 0.3 and lists its old working files (`--yes` deletes them) |
71
- | `config` | a screen on a terminal: models and roles, agent tools, mode (single or multi), audit; `config bindings` and `config gates` take flags (`configure` is an alias). `config gates --refresh` finds the project's checks again, shows what differs from `gates.yaml` (new, changed, gone) and applies only what you pick (`--apply <name…|all>` without a terminal); the screen has a `gates` item for the same. A group or a role may name a fallback model (`config bindings --fallback <group>[.<role>]=<model>`): its call line goes into the delegation table, for when the first model cannot be called |
71
+ | `config` | a screen on a terminal: models and roles, agent tools, mode (single or multi), audit; `config bindings` and `config gates` take flags (`configure` is an alias). `config gates --refresh` finds the project's checks again (scripts by name and body, workspaces, CI), shows every gate and candidate with its state and reasons — applied, not applied, already run by another — leaves the same list in `.loctx/gates-refresh.md`, and changes `gates.yaml` only as you pick (`--apply <name…|all|remove:name>` without a terminal); it never calls a gate gone; the screen has a `gates` item for the same. A group or a role may name a fallback model (`config bindings --fallback <group>[.<role>]=<model>`): its call line goes into the delegation table, for when the first model cannot be called |
72
72
 
73
73
  ## Skills
74
74
 
@@ -1,9 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { applicable, formatGateDiff } from '../lib/gate-refresh.js';
3
+ import { actionsOf, formatGateRow } from '../lib/gate-refresh.js';
4
4
  import { GATE_SCRIPT } from '../lib/gate-script.js';
5
5
  import { BACK, EXIT } from '../lib/prompter.js';
6
- import { configureGates, fileGates, gateDiff } from './configure.js';
6
+ import { configureGates, fileGates, gateRows, REFRESH_LIST, writeRefreshList, } from './configure.js';
7
7
  import { hookTool } from './install.js';
8
8
  const GATES = '.agents/harness/gates.yaml';
9
9
  /** The gates as the project has them now: name, command, source, in order; and what runs them. */
@@ -20,26 +20,26 @@ export function formatGates(root) {
20
20
  return lines.join('\n');
21
21
  }
22
22
  /**
23
- * Run the discovery again and let the user pick which differences to apply (design §9). Nothing is
24
- * written unless something is picked. Returns `exit` when the user left with Ctrl-C.
23
+ * Run the discovery again, show every gate and candidate with its state (024 S-11), leave the same list in
24
+ * `.loctx/gates-refresh.md`, and let the user pick what to add, remove or replace (S-13). Nothing is written
25
+ * to gates.yaml unless something is picked. Returns `exit` when the user left with Ctrl-C.
25
26
  */
26
27
  export async function refreshGates(root, prompter) {
27
- const diff = gateDiff(root);
28
- if (!diff) {
28
+ const rows = gateRows(root);
29
+ if (!rows) {
29
30
  prompter.note('no gates.yaml — run `reins install`');
30
31
  return 'done';
31
32
  }
32
- const can = applicable(diff);
33
- const yours = diff.filter((d) => d.kind === 'yours');
34
- if (yours.length)
35
- prompter.note(yours.map(formatGateDiff).join('\n'));
36
- if (can.length === 0) {
37
- prompter.note('gates: up to date — the discovery finds what gates.yaml holds');
38
- return 'done';
39
- }
33
+ writeRefreshList(root, rows);
34
+ prompter.note([...rows.map(formatGateRow), `(the same list: ${REFRESH_LIST})`].join('\n'));
35
+ const options = rows.flatMap((r) => actionsOf(r).map((a) => ({
36
+ value: `${a}:${r.name}`,
37
+ label: `${a} ${r.name}`,
38
+ hint: a === 'replace' ? `${r.cmd} → ${r.found.cmd}` : r.cmd,
39
+ })));
40
40
  const picked = await prompter.multiselect({
41
- message: 'Differences to apply to gates.yaml (nothing is changed unless picked)',
42
- options: can.map((d) => ({ value: d.name, label: formatGateDiff(d) })),
41
+ message: 'What to apply to gates.yaml (nothing is changed unless picked)',
42
+ options,
43
43
  initial: [],
44
44
  });
45
45
  if (picked === EXIT)
@@ -48,10 +48,17 @@ export async function refreshGates(root, prompter) {
48
48
  prompter.note('gates: nothing changed');
49
49
  return 'done';
50
50
  }
51
- const r = configureGates({ cwd: root, refresh: true, apply: picked });
51
+ // remove and replace of one gate together: the removal wins
52
+ const names = new Map();
53
+ for (const p of picked) {
54
+ const name = p.slice(p.indexOf(':') + 1);
55
+ if (!names.has(name) || p.startsWith('remove:'))
56
+ names.set(name, p);
57
+ }
58
+ const r = configureGates({ cwd: root, refresh: true, apply: [...names.values()] });
52
59
  prompter.note(r.refused
53
60
  ? `not changed: ${r.refused}`
54
- : `gates: applied ${r.applied?.join(', ')} — gates.yaml and ${GATE_SCRIPT} written; commit them (the hook line stays as it is)`);
61
+ : `gates: ${r.applied?.join(', ')} — gates.yaml written; commit it (the gate script reads it, the hook line stays)`);
55
62
  return 'done';
56
63
  }
57
64
  /** The gates item of the config screen: see the gates, find them again, add subdirectory proposals. */
@@ -62,7 +69,11 @@ export async function gatesScreen(root, prompter) {
62
69
  message: 'Gates',
63
70
  options: [
64
71
  { value: 'back', label: '< Configuration' },
65
- { value: 'refresh', label: 'refresh', hint: 'find the gates again and pick what to apply' },
72
+ {
73
+ value: 'refresh',
74
+ label: 'refresh',
75
+ hint: 'find the gates again, see each state, pick what to apply',
76
+ },
66
77
  { value: 'add', label: 'add subdirectory proposals' },
67
78
  ],
68
79
  });
@@ -1,3 +1,4 @@
1
+ import { applyLocalForcePush, FORCE_WITH_LEASE_QUESTION, recordedForceWithLease, } from '../lib/local-settings.js';
1
2
  import { gatesScreen } from './config-gates.js';
2
3
  import { effectiveBindings, resolveRoles } from '../lib/bindings.js';
3
4
  import { newModelCache, vendors } from '../lib/detect.js';
@@ -5,7 +6,7 @@ import { repoRoot } from '../lib/git.js';
5
6
  import { groupLine, modelsScreen } from './config-models.js';
6
7
  import { configureBindings } from './configure.js';
7
8
  import { LOCAL_DELEGATION_NOTE } from '../lib/local-delegation.js';
8
- import { clackPrompter, isInteractive } from '../lib/prompter.js';
9
+ import { BACK, clackPrompter, EXIT, isInteractive } from '../lib/prompter.js';
9
10
  export const CONFIG_HINT = 'change with: reins config bindings --set <group|group.role>=<model> [--fallback <group|group.role>=<model|none>] [--local] (see: reins config bindings --help)';
10
11
  /** The effective settings as text: mode, audit, each role that is on. */
11
12
  export function formatBindings(doc) {
@@ -55,6 +56,7 @@ export async function runConfig(o = {}) {
55
56
  const detect = o.detectVendors ?? vendors;
56
57
  for (;;) {
57
58
  const doc = effectiveBindings(root);
59
+ const lease = recordedForceWithLease(root);
58
60
  const v = await prompter.select({
59
61
  message: 'Configuration',
60
62
  options: [
@@ -66,6 +68,11 @@ export async function runConfig(o = {}) {
66
68
  label: `audit: ${doc?.audit?.required === false ? 'off' : 'required'}`,
67
69
  },
68
70
  { value: 'gates', label: 'gates', hint: 'the project checks: see them, find them again' },
71
+ {
72
+ value: 'lease',
73
+ label: `force push with lease (this machine): ${lease === 'allow' ? 'not denied' : lease === 'deny' ? 'denied' : 'not asked yet'}`,
74
+ hint: 'local: .claude/settings.local.json',
75
+ },
69
76
  { value: 'exit', label: 'exit' },
70
77
  ],
71
78
  });
@@ -82,6 +89,19 @@ export async function runConfig(o = {}) {
82
89
  return 0;
83
90
  continue;
84
91
  }
92
+ if (v === 'lease') {
93
+ // personal, this machine only (024 S-26a)
94
+ const deny = await prompter.confirm({
95
+ message: FORCE_WITH_LEASE_QUESTION,
96
+ initial: lease !== 'allow',
97
+ });
98
+ if (deny === EXIT)
99
+ return 0;
100
+ if (deny === BACK)
101
+ continue;
102
+ prompter.note(applyLocalForcePush(root, deny ? 'deny' : 'allow').note);
103
+ continue;
104
+ }
85
105
  if (v === 'tools') {
86
106
  const found = detect();
87
107
  const picked = await prompter.multiselect({
@@ -1,8 +1,9 @@
1
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
3
  import { join } from 'node:path';
3
4
  import { isScalar, isSeq, parse, parseDocument } from 'yaml';
4
5
  import { discoverGates, subdirProposals, vendorOf, vendors, } from '../lib/detect.js';
5
- import { applicable, diffGates } from '../lib/gate-refresh.js';
6
+ import { actionsOf, formatGateRow, gateStatus, } from '../lib/gate-refresh.js';
6
7
  import { GROUP_ROLES, GROUPS, effectiveBindings, fallbackProblems, readLocalBindings, readTeam, resolveRoles, validateBindings, writeBindings, } from '../lib/bindings.js';
7
8
  import { modeChangedNote, placeNote, renderBlocks } from '../lib/agents-md.js';
8
9
  import { applyBlocks } from '../lib/blocks.js';
@@ -284,22 +285,49 @@ function appendOrder(doc, name) {
284
285
  const gates = doc.toJS()?.gates ?? {};
285
286
  doc.set('order', doc.createNode([...Object.keys(gates).filter((n) => n !== name), name]));
286
287
  }
287
- /** How gates.yaml differs from what the discovery of installation finds now (design §9). */
288
- export function gateDiff(root) {
288
+ /** The refresh rows of gates.yaml against the discovery (024 S-11), or null without gates.yaml. */
289
+ export function gateRows(root) {
289
290
  const path = join(root, GATES);
290
291
  if (!existsSync(path))
291
292
  return null;
292
- const found = discoverGates(root);
293
- return diffGates(root, fileGates(readFileSync(path, 'utf8')), [
294
- ...found.gates,
295
- ...found.proposals,
296
- ]);
293
+ return gateStatus(root, fileGates(readFileSync(path, 'utf8')), discoverGates(root).candidates);
294
+ }
295
+ /** Where a refresh leaves its rows for the agent who applies the user's picks (024 S-12). */
296
+ export const REFRESH_LIST = '.loctx/gates-refresh.md';
297
+ /** Write the rows to `.loctx/gates-refresh.md`, replacing the last list (024 S-12). */
298
+ export function writeRefreshList(root, rows) {
299
+ const text = readFileSync(join(root, GATES), 'utf8');
300
+ const body = [
301
+ '# gates refresh',
302
+ '',
303
+ `- made: ${new Date().toISOString()}`,
304
+ `- gates.yaml: sha256 ${createHash('sha256').update(text).digest('hex').slice(0, 16)}`,
305
+ '- The user picks from this list; an agent applies the picks to `.agents/harness/gates.yaml` in a commit of its own. The agent does not run reins.',
306
+ '',
307
+ ...rows.map((r) => `- ${formatGateRow(r)}`),
308
+ '',
309
+ ].join('\n');
310
+ mkdirSync(join(root, '.loctx'), { recursive: true });
311
+ writeFileSync(join(root, REFRESH_LIST), body);
312
+ }
313
+ /** The action a name passed to `--apply` asks for, or null when no row has it (024 S-13). */
314
+ function actionFor(rows, asked) {
315
+ const [verb, name] = asked.includes(':')
316
+ ? asked.split(/:(.*)/s)
317
+ : ['', asked];
318
+ const row = rows.find((r) => r.name === name);
319
+ if (!row)
320
+ return null;
321
+ const can = actionsOf(row);
322
+ if (verb === '')
323
+ return { action: can[0], row };
324
+ return can.includes(verb) ? { action: verb, row } : null;
297
325
  }
298
326
  /**
299
- * `reins config gates` (design §9). `--add <name>…` appends subdirectory proposals. `--refresh` runs the
300
- * discovery again and reports the differences; `--apply <name…|all>` applies the chosen ones: a new gate is
301
- * appended, a changed one gets its command and source, a gone one is removed. Comments and other keys stay,
302
- * a gate written by hand is never touched, and the gate script is rewritten when the file changes.
327
+ * `reins config gates` (design §9). `--add <name>…` appends offered candidates. `--refresh` runs the discovery
328
+ * again, writes every gate and candidate with its state to `.loctx/gates-refresh.md` (024 S-11, S-12) and, with
329
+ * `--apply <name…|all|remove:name>`, adds, removes or replaces only what is named (S-13). Comments and other keys
330
+ * stay; the gate script reads gates.yaml when it runs, so only gates.yaml changes (S-17).
303
331
  */
304
332
  export function configureGates(o = {}) {
305
333
  const root = repoRoot(o.cwd ?? process.cwd());
@@ -310,53 +338,61 @@ export function configureGates(o = {}) {
310
338
  const have = new Set(Object.keys(doc.toJS()?.gates ?? {}));
311
339
  const available = subdirProposals(root).filter((g) => !have.has(g.name));
312
340
  if (o.refresh || o.apply) {
313
- const diff = gateDiff(root) ?? [];
314
- const can = applicable(diff);
341
+ const rows = gateRows(root) ?? [];
342
+ writeRefreshList(root, rows);
315
343
  // every name is checked, `all` beside others too: one unknown name refuses the whole call
316
344
  const asked = [...new Set(o.apply ?? [])];
317
- const unknown = asked.filter((n) => n !== 'all' && !can.some((d) => d.name === n));
318
- const names = asked.includes('all') ? can.map((d) => d.name) : asked;
345
+ const unknown = asked.filter((n) => n !== 'all' && !actionFor(rows, n));
319
346
  if (unknown.length)
320
347
  return {
321
- refused: `nothing to apply under: ${unknown.join(', ')} — names: ${can.map((d) => d.name).join(', ') || 'none'}`,
348
+ refused: `nothing to apply under: ${unknown.join(', ')} — names: ${rows.map((r) => r.name).join(', ') || 'none'}`,
322
349
  code: 1,
323
350
  available,
324
351
  added: [],
325
- diff,
352
+ rows,
326
353
  applied: [],
327
354
  };
328
- for (const n of names) {
329
- const d = can.find((x) => x.name === n);
330
- if (d.kind === 'gone') {
331
- doc.deleteIn(['gates', d.name]);
355
+ const picks = asked.includes('all')
356
+ ? rows
357
+ .filter((r) => r.state === 'not applied')
358
+ .map((row) => ({ action: 'add', row }))
359
+ : [];
360
+ for (const n of asked.filter((x) => x !== 'all')) {
361
+ const p = actionFor(rows, n);
362
+ if (!picks.some((x) => x.row === p.row))
363
+ picks.push(p);
364
+ }
365
+ const applied = [];
366
+ for (const { action, row } of picks) {
367
+ if (action === 'remove') {
368
+ doc.deleteIn(['gates', row.name]);
332
369
  // every occurrence: a name left in `order` without its gate would dangle
333
370
  const order = doc.get('order');
334
371
  if (isSeq(order))
335
372
  for (let i = order.items.length - 1; i >= 0; i--) {
336
373
  const x = order.items[i];
337
- if ((isScalar(x) ? x.value : x) === d.name)
374
+ if ((isScalar(x) ? x.value : x) === row.name)
338
375
  order.delete(i);
339
376
  }
340
377
  }
341
- else if (d.kind === 'changed') {
342
- doc.setIn(['gates', d.name, 'cmd'], d.cmd);
343
- doc.setIn(['gates', d.name, 'from'], d.from);
378
+ else if (action === 'replace') {
379
+ doc.setIn(['gates', row.name, 'cmd'], row.found.cmd);
380
+ doc.setIn(['gates', row.name, 'from'], row.found.from);
344
381
  }
345
382
  else {
346
- doc.setIn(['gates', d.name], doc.createNode({ cmd: d.cmd, from: d.from, ...(d.optional ? { optional: true } : {}) }));
347
- appendOrder(doc, d.name);
383
+ doc.setIn(['gates', row.name], doc.createNode({
384
+ cmd: row.cmd,
385
+ from: row.from,
386
+ ...(row.optional ? { optional: true } : {}),
387
+ }));
388
+ appendOrder(doc, row.name);
348
389
  }
390
+ applied.push(`${action} ${row.name}`);
349
391
  }
350
- if (names.length) {
351
- writeFileSync(path, doc.toString());
352
- writeGenerated(root, generateVendorFiles(root), false);
353
- }
354
- return {
355
- available: available.filter((g) => !names.includes(g.name)),
356
- added: [],
357
- diff,
358
- applied: names,
359
- };
392
+ // the gate script reads gates.yaml when it runs, so only the file changes (024 S-17)
393
+ if (applied.length)
394
+ writeFileSync(path, doc.toString({ lineWidth: 0 }));
395
+ return { available, added: [], rows, applied };
360
396
  }
361
397
  const names = o.add ?? [];
362
398
  const unknown = names.filter((n) => !available.some((g) => g.name === n));
@@ -374,10 +410,7 @@ export function configureGates(o = {}) {
374
410
  appendOrder(doc, g.name);
375
411
  added.push(g.name);
376
412
  }
377
- if (added.length) {
378
- writeFileSync(path, doc.toString());
379
- // the gate script holds the commands of gates.yaml (design §6): it follows the file
380
- writeGenerated(root, generateVendorFiles(root), false);
381
- }
413
+ if (added.length)
414
+ writeFileSync(path, doc.toString({ lineWidth: 0 }));
382
415
  return { available: available.filter((g) => !added.includes(g.name)), added };
383
416
  }
@@ -9,12 +9,13 @@ import { apply, listFiles } from '../lib/fsx.js';
9
9
  import { repoRoot } from '../lib/git.js';
10
10
  import { harnessVersion, packageHarness, packageSkills, packageVersion } from '../lib/upstream.js';
11
11
  import { generateVendorFiles } from '../lib/generate.js';
12
- import { hookLine, requiredGates } from '../lib/gate-script.js';
12
+ import { GATE_SCRIPT, hookLine, requiredGates } from '../lib/gate-script.js';
13
13
  import { defaultBindings, readTeam } from '../lib/bindings.js';
14
14
  import { overlayReader, workTreeReader } from '../lib/reader.js';
15
15
  import { LOCAL_DELEGATION, ONBOARDING_PENDING, RECONCILE_PENDING, onboardingNote, placeNote, renderBlocks, tidyNote, } from '../lib/agents-md.js';
16
16
  import { syncLocalDelegation } from '../lib/local-delegation.js';
17
- import { writeGenerated } from '../lib/vendor-write.js';
17
+ import { readManifest, writeGenerated } from '../lib/vendor-write.js';
18
+ import { applyLocalForcePush, FORCE_WITH_LEASE_QUESTION, recordedForceWithLease, } from '../lib/local-settings.js';
18
19
  /** Upstream harness files installed into `.agents/harness/` (design §1): everything but seeds and the changelog. */
19
20
  export function harnessFiles(all) {
20
21
  return all.filter((f) => !f.startsWith('knowledge-seeds/') && f !== 'CHANGELOG.md');
@@ -59,7 +60,7 @@ export function buildGates(root, gates) {
59
60
  evidence: 'raw',
60
61
  };
61
62
  void root;
62
- return `# discovered by reins install — the loop reads only this file (design §5)\n${stringify(doc)}`;
63
+ return `# discovered by reins install — the loop reads only this file (design §5)\n${stringify(doc, { lineWidth: 0 })}`;
63
64
  }
64
65
  /** The stub install leaves; migrate may replace it with the project's real raw roadmap. */
65
66
  export const ROADMAP_STUB = '# ROADMAP (local)\n\n— 산발적 아이디어를 여기에. 확정되면 docs/ROADMAP.md\n';
@@ -80,6 +81,17 @@ const TOOL_NAMES = ['claude', 'openai', 'google', 'gemini', 'copilot', 'cursor']
80
81
  const HOOK_STAGES = ['pre-commit', 'pre-push'];
81
82
  /** A `reins:begin hooks` block in a hook file, with its body. */
82
83
  const HOOK_BLOCK = /# reins:begin hooks\n([\s\S]*?)# reins:end hooks/g;
84
+ /**
85
+ * Whether a hook file already runs the gate script for `stage` outside a reins block (024 S-19): a line
86
+ * that is not a comment and, trimmed, reads `sh <path> <stage>`, the path as written, with `./`, or quoted.
87
+ */
88
+ export function runsGateScript(text, stage) {
89
+ const paths = [GATE_SCRIPT, `./${GATE_SCRIPT}`].flatMap((p) => [p, `'${p}'`, `"${p}"`]);
90
+ return text
91
+ .split(/\r?\n/)
92
+ .map((l) => l.trim().replace(/\s+/g, ' '))
93
+ .some((l) => !l.startsWith('#') && paths.some((p) => l === `sh ${p} ${stage}`));
94
+ }
83
95
  /** A command that runs reins: what 0.x put into hooks and settings. */
84
96
  export const RUNS_REINS = /@bluenyang\/reins|reins\.js\b|(^|[\s;&|])reins\s+(check|hook|gate|status)\b/;
85
97
  /** `reins install` (design §9): place the harness, ask, propose hooks, mark onboarding. Never writes history. */
@@ -182,6 +194,7 @@ export async function runInstall(o) {
182
194
  }
183
195
  if (!hasGates) {
184
196
  const proposal = discoverGates(root);
197
+ const reasonsOf = (name) => proposal.candidates.find((c) => c.name === name)?.reasons ?? [];
185
198
  const gateList = proposal.gates.map((g) => `${g.name}=${g.cmd}`).join(', ') || 'none found';
186
199
  const gateQ = `gates found: ${gateList} — use them?`;
187
200
  const gateAns = await (screens ?? line).confirm({ message: gateQ, initial: true });
@@ -196,8 +209,12 @@ export async function runInstall(o) {
196
209
  let names;
197
210
  if (screens) {
198
211
  const picked = await screens.multiselect({
199
- message: 'Subdirectory gates to add',
200
- options: proposal.proposals.map((g) => ({ value: g.name, label: g.name, hint: g.cmd })),
212
+ message: 'Other gate candidates to add (not chosen by default)',
213
+ options: proposal.proposals.map((g) => ({
214
+ value: g.name,
215
+ label: g.name,
216
+ hint: [g.cmd, ...reasonsOf(g.name)].join(' — '),
217
+ })),
201
218
  initial: [],
202
219
  });
203
220
  if (isNav(picked))
@@ -226,6 +243,9 @@ export async function runInstall(o) {
226
243
  }
227
244
  for (const x of proposal.excluded)
228
245
  notes.push(`excluded from gates: ${x.name} (${x.why})`);
246
+ // what another script or gate already runs is shown, never chosen (024 S-9, S-10)
247
+ for (const c of proposal.candidates.filter((x) => x.status === 'covered'))
248
+ notes.push(`not a gate of its own: ${c.name} — ${c.reasons.join('; ')}`);
229
249
  add('.agents/harness/gates.yaml', buildGates(root, [...(gateAns ? proposal.gates : []), ...chosen]), 'declared gates');
230
250
  }
231
251
  // 3. settings: a new bindings file in single mode (an old one is converted by update)
@@ -278,7 +298,8 @@ export async function runInstall(o) {
278
298
  const p = join(root, '.husky', stage);
279
299
  return { stage, cur: existsSync(p) ? readFileSync(p, 'utf8') : '' };
280
300
  });
281
- const missing = files.filter((f) => !f.cur.includes('# reins:begin hooks'));
301
+ // a stage is hooked by a reins block or by the gate line written outside one (024 S-19)
302
+ const missing = files.filter((f) => !f.cur.includes('# reins:begin hooks') && !runsGateScript(f.cur, f.stage));
282
303
  let addHooks = !!o.hooks;
283
304
  if (missing.length && !addHooks && o.confirmHooks && !o.dryRun) {
284
305
  const yes = await o.confirmHooks.confirm({
@@ -306,7 +327,7 @@ export async function runInstall(o) {
306
327
  add(`.husky/${stage}`, next, 'hook: the gate script');
307
328
  notes.push(`.husky/${stage}: the reins hooks block now calls the gate script — it held: ${held.join(' && ')} (move a line of your own outside the block)`);
308
329
  }
309
- else if (addHooks)
330
+ else if (addHooks && !runsGateScript(cur, stage))
310
331
  add(`.husky/${stage}`, `${cur.replace(/\s*$/, '')}\n# reins:begin hooks\n${line}\n# reins:end hooks\n`.replace(/^\n/, ''), 'hook: the gate script');
311
332
  }
312
333
  if (missing.length && !addHooks)
@@ -376,6 +397,8 @@ export async function runInstall(o) {
376
397
  const rd = o.dryRun
377
398
  ? overlayReader(workTreeReader(root), [...(o.pending ?? []), ...writes], [...retired, ...(o.pendingDeletes ?? [])])
378
399
  : workTreeReader(root);
400
+ // the 0.3.3 team rule this run takes out of .claude/settings.json (024 revision 1)
401
+ const hadTeamLease = (readManifest(root).owned?.['.claude/settings.json'] ?? []).includes('Bash(git push --force-with-lease *)');
379
402
  const generated = writeGenerated(root, generateVendorFiles(root, rd), !!o.dryRun, !!o.force);
380
403
  if (generated) {
381
404
  // a generated file that was there before this run is a changed one, not a new one (022 S-28)
@@ -396,5 +419,20 @@ export async function runInstall(o) {
396
419
  applied.removed.push(LOCAL_DELEGATION);
397
420
  else if (local)
398
421
  (hadLocal ? applied.changed : applied.created).push(LOCAL_DELEGATION);
422
+ // 10. force push with lease, per person (024 S-26a): asked once, kept in .loctx, written to settings.local.json
423
+ const recorded = recordedForceWithLease(root);
424
+ let lease = o.forceWithLease ?? recorded;
425
+ let answered = !!o.forceWithLease || !!recorded;
426
+ // only on a terminal (screens, or the hook confirmation); piped answers keep the unrecorded default (review 6)
427
+ const asks = o.confirmHooks ?? screens;
428
+ if (!lease && asks && !o.dryRun) {
429
+ const yes = await asks.confirm({ message: FORCE_WITH_LEASE_QUESTION, initial: true });
430
+ if (yes === EXIT)
431
+ return cancelled();
432
+ lease = yes === false ? 'allow' : 'deny';
433
+ answered = true;
434
+ }
435
+ const fp = applyLocalForcePush(root, lease ?? 'deny', !!o.dryRun, answered);
436
+ notes.push(hadTeamLease ? `${fp.note} — the team .claude/settings.json no longer denies it` : fp.note);
399
437
  return { root, generation: gen, applied, generated, notes };
400
438
  }
@@ -9,6 +9,7 @@ import { repoRoot } from '../lib/git.js';
9
9
  import { BACK, EXIT } from '../lib/prompter.js';
10
10
  import { harnessVersion, packageHarness, packageVersion } from '../lib/upstream.js';
11
11
  import { RUNS_REINS, runInstall } from './install.js';
12
+ import { FORCE_WITH_LEASE_QUESTION, recordedForceWithLease, } from '../lib/local-settings.js';
12
13
  /** Numeric dotted-version compare; pre-release suffixes are ignored. */
13
14
  /** A 0.3 harness from before the AGENTS.md guide (0.3.0, 0.3.1 and their rcs); 0.x installs are reconciled instead. */
14
15
  export function beforeGuide(version) {
@@ -25,18 +26,29 @@ export function newer(a, b) {
25
26
  }
26
27
  return false;
27
28
  }
28
- /** Changelog entries for versions in (from, to]. */
29
- export function changesBetween(changelog, from, to) {
29
+ /**
30
+ * Changelog entries for versions in (from, to], grouped under their version in the changelog's order
31
+ * (newest first); a version without entries is left out (024 S-1).
32
+ */
33
+ export function changesByVersion(changelog, from, to) {
30
34
  const out = [];
31
- let take = false;
35
+ let cur = null;
32
36
  for (const line of changelog.split(/\r?\n/)) {
33
37
  const h = /^## (\S+)/.exec(line);
34
- if (h)
35
- take = newer(h[1] ?? '0', from) && !newer(h[1] ?? '0', to);
36
- else if (take && line.startsWith('- '))
37
- out.push(line.slice(2));
38
+ if (h) {
39
+ const v = h[1] ?? '0';
40
+ cur = newer(v, from) && !newer(v, to) ? { version: v, items: [] } : null;
41
+ if (cur)
42
+ out.push(cur);
43
+ }
44
+ else if (cur && line.startsWith('- '))
45
+ cur.items.push(line.slice(2));
38
46
  }
39
- return out;
47
+ return out.filter((g) => g.items.length > 0);
48
+ }
49
+ /** Changelog entries for versions in (from, to], as one flat list. */
50
+ export function changesBetween(changelog, from, to) {
51
+ return changesByVersion(changelog, from, to).flatMap((g) => g.items);
40
52
  }
41
53
  /** 0.x working files and folders under `.loctx/` that 0.3 no longer makes (design §7). */
42
54
  const LEGACY_LOCTX = [
@@ -161,8 +173,20 @@ export async function runUpdate(o) {
161
173
  plan.cleanup.length === 0 &&
162
174
  plan.handEdited.length === 0 &&
163
175
  (!a || a.created.length + a.changed.length + a.removed.length === 0);
164
- if (nothing)
176
+ // the force-with-lease question is asked once per machine, even when nothing else changes (024 S-26a)
177
+ const unanswered = !o.forceWithLease && !recordedForceWithLease(repoRoot(o.cwd ?? process.cwd()));
178
+ if (nothing && !unanswered)
165
179
  return plan;
180
+ if (nothing) {
181
+ const deny = await o.prompter.confirm({ message: FORCE_WITH_LEASE_QUESTION, initial: true });
182
+ if (deny === EXIT)
183
+ return { ...plan, declined: true };
184
+ return runUpdate({
185
+ ...o,
186
+ prompter: undefined,
187
+ forceWithLease: deny === false ? 'allow' : 'deny',
188
+ });
189
+ }
166
190
  o.show?.(plan);
167
191
  const ok = await o.prompter.confirm({ message: 'Apply this update?', initial: true });
168
192
  if (ok === BACK || ok === EXIT || !ok)
@@ -177,7 +201,15 @@ export async function runUpdate(o) {
177
201
  return { ...plan, declined: true };
178
202
  force = over === true;
179
203
  }
180
- return runUpdate({ ...o, prompter: undefined, yes: true, force });
204
+ // asked once per machine, before the run that writes (024 S-26a)
205
+ let forceWithLease = o.forceWithLease ?? recordedForceWithLease(repoRoot(o.cwd ?? process.cwd()));
206
+ if (!forceWithLease) {
207
+ const deny = await o.prompter.confirm({ message: FORCE_WITH_LEASE_QUESTION, initial: true });
208
+ if (deny === EXIT)
209
+ return { ...plan, declined: true };
210
+ forceWithLease = deny === false ? 'allow' : 'deny';
211
+ }
212
+ return runUpdate({ ...o, prompter: undefined, yes: true, force, forceWithLease });
181
213
  }
182
214
  return updateNow(o);
183
215
  }
@@ -186,6 +218,7 @@ async function updateNow(o) {
186
218
  const res = {
187
219
  root,
188
220
  changes: [],
221
+ changesByVersion: [],
189
222
  overrides: [],
190
223
  removed: [],
191
224
  cleanup: [],
@@ -204,8 +237,10 @@ async function updateNow(o) {
204
237
  res.cliFrom = pin.cli ? String(pin.cli) : 'none';
205
238
  res.cliTo = packageVersion();
206
239
  const cl = join(up, 'CHANGELOG.md');
207
- if (existsSync(cl) && newer(res.to, res.from))
208
- res.changes = changesBetween(readFileSync(cl, 'utf8'), res.from, res.to);
240
+ if (existsSync(cl) && newer(res.to, res.from)) {
241
+ res.changesByVersion = changesByVersion(readFileSync(cl, 'utf8'), res.from, res.to);
242
+ res.changes = res.changesByVersion.flatMap((g) => g.items);
243
+ }
209
244
  const agents = join(root, 'AGENTS.md');
210
245
  if (existsSync(agents))
211
246
  res.overrides = [...overrides(readFileSync(agents, 'utf8'))];
@@ -252,6 +287,7 @@ async function updateNow(o) {
252
287
  }
253
288
  }
254
289
  res.install = await runInstall({
290
+ forceWithLease: o.forceWithLease,
255
291
  mode: pin.mode ?? 'auto',
256
292
  asker: defaultsAsker,
257
293
  cwd: root,
@@ -279,15 +315,21 @@ export function updateNotes(r) {
279
315
  return (r.install?.notes ?? []).filter((n) => n.startsWith('.husky/') ||
280
316
  n.startsWith('hook proposal') ||
281
317
  n.startsWith('no hook tool found') ||
282
- (n.startsWith('left alone ') && !n.includes(': edited by hand')));
318
+ (n.startsWith('left alone ') && !n.includes(': edited by hand')) ||
319
+ // the personal force-with-lease line and its migration from the team file (024 S-26a, review 6)
320
+ n.startsWith('force push with lease') ||
321
+ n.startsWith('.claude/settings.local.json'));
283
322
  }
284
323
  /** The report `reins update` prints; with `dry` it is the plan shown before the confirmation. */
285
324
  export function formatUpdate(r, dry) {
286
325
  const out = [];
287
326
  const a = r.install?.applied;
288
327
  out.push(`reins update — cli ${r.cliFrom === 'none' ? 'none' : `v${r.cliFrom}`} → v${r.cliTo}, harness v${r.from} → v${r.to}${dry ? ' (dry run)' : ''}`);
289
- for (const c of r.changes)
290
- out.push(` · ${c}`);
328
+ for (const g of r.changesByVersion) {
329
+ out.push(` ${g.version}`);
330
+ for (const c of g.items)
331
+ out.push(` · ${c}`);
332
+ }
291
333
  if (r.converted) {
292
334
  out.push(`bindings: ${dry ? 'would convert' : 'converted'} version 1 → 2`);
293
335
  for (const n of r.converted)
@@ -58,7 +58,7 @@ function fallbackHow(doc, r) {
58
58
  export function renderDelegation(doc, local) {
59
59
  const lines = ['## Delegation', ''];
60
60
  if (!local)
61
- lines.push(`If \`${LOCAL_DELEGATION}\` exists, follow it instead of this section (your personal settings; \`reins config --local\` writes it).`, '');
61
+ lines.push(`If \`${LOCAL_DELEGATION}\` exists, follow it instead of this section (your personal settings; \`reins config --local\` writes it): open it before anything else and use its table.`, '');
62
62
  if (doc.mode !== 'multi') {
63
63
  lines.push(`Mode: **single** — you are the PM — the model in this conversation — and do every role yourself, stage by stage. You may use subagents of your own model for read-heavy work (research, large log summaries, review, audit) and, when urgent, for parallel work on independent units; keep connected work (plan and implementation of one feature) in one run. Switching to multi is the user's choice.`);
64
64
  }