@bluenyang/reins 0.2.0 → 0.3.0-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.
Files changed (95) hide show
  1. package/README.md +50 -203
  2. package/cli/dist/commands/config-models.js +175 -126
  3. package/cli/dist/commands/config.js +96 -15
  4. package/cli/dist/commands/configure.js +165 -138
  5. package/cli/dist/commands/install.js +161 -217
  6. package/cli/dist/commands/migrate.js +23 -48
  7. package/cli/dist/commands/update.js +203 -30
  8. package/cli/dist/lib/agents-md.js +102 -0
  9. package/cli/dist/lib/bindings.js +227 -386
  10. package/cli/dist/lib/detect.js +7 -2
  11. package/cli/dist/lib/generate.js +56 -75
  12. package/cli/dist/lib/harness.js +0 -3
  13. package/cli/dist/lib/migrate-plan.js +3 -3
  14. package/cli/dist/lib/reader.js +20 -0
  15. package/cli/dist/lib/upstream.js +0 -17
  16. package/cli/dist/lib/vendor-write.js +9 -56
  17. package/cli/dist/reins.js +59 -270
  18. package/docs/README.ko.md +31 -204
  19. package/harness/CHANGELOG.md +7 -3
  20. package/harness/VERSION +1 -1
  21. package/harness/policy/common-red-lines.yaml +4 -4
  22. package/harness/roles/advisor.md +10 -14
  23. package/harness/roles/auditor.md +17 -0
  24. package/harness/roles/executor.md +32 -0
  25. package/harness/roles/implementer.md +23 -21
  26. package/harness/roles/pl.md +44 -21
  27. package/harness/roles/planner.md +17 -19
  28. package/harness/roles/pm.md +16 -21
  29. package/harness/schemas/bindings.schema.json +55 -0
  30. package/harness/schemas/install.schema.json +1 -2
  31. package/harness/schemas/intent.schema.json +1 -13
  32. package/harness/templates/agents-md-blocks.md +52 -17
  33. package/harness/templates/audit.md +25 -0
  34. package/harness/templates/history.md +14 -0
  35. package/harness/templates/intent.md +5 -0
  36. package/harness/templates/spec.md +4 -2
  37. package/package.json +1 -2
  38. package/skills/audit/SKILL.md +28 -0
  39. package/skills/implement/SKILL.md +30 -0
  40. package/skills/intent/SKILL.md +28 -0
  41. package/skills/merge/SKILL.md +26 -0
  42. package/skills/onboard/SKILL.md +29 -0
  43. package/skills/reins-setup/SKILL.md +16 -25
  44. package/skills/release/SKILL.md +26 -0
  45. package/skills/retro/SKILL.md +30 -0
  46. package/skills/review/SKILL.md +27 -0
  47. package/skills/roadmap/SKILL.md +29 -0
  48. package/skills/spec/SKILL.md +27 -0
  49. package/skills/test/SKILL.md +26 -0
  50. package/cli/dist/commands/check.js +0 -379
  51. package/cli/dist/commands/gate.js +0 -136
  52. package/cli/dist/commands/knowledge.js +0 -111
  53. package/cli/dist/commands/metrics.js +0 -138
  54. package/cli/dist/commands/new.js +0 -190
  55. package/cli/dist/commands/retro.js +0 -7
  56. package/cli/dist/commands/stages.js +0 -562
  57. package/cli/dist/commands/status.js +0 -281
  58. package/cli/dist/lib/enforcement.js +0 -125
  59. package/cli/dist/lib/memory.js +0 -96
  60. package/cli/dist/lib/metrics.js +0 -223
  61. package/cli/dist/lib/retro.js +0 -179
  62. package/cli/dist/lib/verdict.js +0 -15
  63. package/cli/dist/lib/work.js +0 -106
  64. package/cli/dist/scripts/enforcement.js +0 -24
  65. package/harness/policy/budget.yaml +0 -13
  66. package/harness/policy/enforcement.yaml +0 -98
  67. package/harness/policy/stops.yaml +0 -29
  68. package/harness/policy/transitions.yaml +0 -13
  69. package/harness/roles/code-review.md +0 -27
  70. package/harness/roles/deploy.md +0 -50
  71. package/harness/roles/docs.md +0 -19
  72. package/harness/roles/lookup.md +0 -22
  73. package/harness/roles/qa-design.md +0 -22
  74. package/harness/roles/qa-run.md +0 -19
  75. package/harness/roles/verify-tool.md +0 -21
  76. package/harness/schemas/bindings-local.schema.json +0 -21
  77. package/harness/schemas/bus-request.schema.json +0 -17
  78. package/harness/schemas/bus-response.schema.json +0 -14
  79. package/harness/schemas/enforcement.schema.json +0 -22
  80. package/harness/schemas/plan.schema.json +0 -10
  81. package/harness/schemas/ticket.schema.json +0 -15
  82. package/harness/templates/bus/request.yaml +0 -20
  83. package/harness/templates/bus/response.yaml +0 -10
  84. package/harness/templates/plan.md +0 -23
  85. package/harness/templates/ticket.md +0 -29
  86. package/skills/reins-implement/SKILL.md +0 -20
  87. package/skills/reins-intent/SKILL.md +0 -26
  88. package/skills/reins-loop/SKILL.md +0 -26
  89. package/skills/reins-loop/references/vendor-cli.md +0 -41
  90. package/skills/reins-release/SKILL.md +0 -18
  91. package/skills/reins-retro/SKILL.md +0 -20
  92. package/skills/reins-review/SKILL.md +0 -23
  93. package/skills/reins-roadmap/SKILL.md +0 -17
  94. package/skills/reins-spec/SKILL.md +0 -22
  95. package/skills/reins-test/SKILL.md +0 -18
@@ -1,223 +0,0 @@
1
- import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { redLines, stops } from './harness.js';
4
- /** Metrics live next to the other local evidence; one JSON object per line (design §3, intent 002). */
5
- export const METRICS_FILE = '.loctx/reports/metrics.jsonl';
6
- export const METRIC_SCHEMA = 'reins/metric@1';
7
- const pad = (n) => String(n).padStart(2, '0');
8
- /** Local time to the second, with the UTC offset: `2026-10-25T14:03:07+09:00`. */
9
- export function localIso(d = new Date()) {
10
- const off = -d.getTimezoneOffset();
11
- const sign = off < 0 ? '-' : '+';
12
- const a = Math.abs(off);
13
- return (`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` +
14
- `T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` +
15
- `${sign}${pad(Math.floor(a / 60))}:${pad(a % 60)}`);
16
- }
17
- /** The intent number is the first three characters of a ticket id (`002-1` → `002`). */
18
- export function intentOf(ticket) {
19
- return ticket ? ticket.slice(0, 3) : undefined;
20
- }
21
- /** Fill `intent` from `ticket` and put the shared keys first. */
22
- function stamp(rec) {
23
- const { ticket, intent, ...rest } = rec;
24
- const out = { schema: METRIC_SCHEMA, ts: localIso(), ...rest };
25
- if (ticket)
26
- out['ticket'] = ticket;
27
- const i = ticket ? intentOf(ticket) : intent;
28
- if (i)
29
- out['intent'] = i;
30
- return out;
31
- }
32
- /**
33
- * Appends one line to the metrics file. A repository without `.loctx/` is skipped, and a write
34
- * error never escapes: the exit code and output of `check` and `gate` do not depend on metrics.
35
- * Returns whether a line was written.
36
- */
37
- export function appendMetric(root, rec) {
38
- try {
39
- if (!existsSync(join(root, '.loctx')))
40
- return false;
41
- const file = join(root, METRICS_FILE);
42
- mkdirSync(join(root, '.loctx', 'reports'), { recursive: true });
43
- appendFileSync(file, `${JSON.stringify(stamp(rec))}\n`);
44
- return true;
45
- }
46
- catch {
47
- return false;
48
- }
49
- }
50
- const strs = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');
51
- const opt = (v) => v === undefined || typeof v === 'string';
52
- function valid(o) {
53
- if (!o || typeof o !== 'object')
54
- return false;
55
- const r = o;
56
- if (r['schema'] !== METRIC_SCHEMA || typeof r['ts'] !== 'string')
57
- return false;
58
- if (!opt(r['ticket']) || !opt(r['intent']))
59
- return false;
60
- switch (r['kind']) {
61
- case 'check': {
62
- const s = r['stops'];
63
- return (typeof r['stage'] === 'string' &&
64
- typeof r['verdict'] === 'string' &&
65
- strs(r['reasons']) &&
66
- strs(r['warns']) &&
67
- !!s &&
68
- ['intent', 'knowledge', 'redline'].every((k) => Number.isInteger(s[k])));
69
- }
70
- case 'gate':
71
- return (typeof r['gate'] === 'string' &&
72
- typeof r['report'] === 'string' &&
73
- (r['exit'] === null || typeof r['exit'] === 'number'));
74
- case 'usage':
75
- return (typeof r['role'] === 'string' &&
76
- typeof r['vendor'] === 'string' &&
77
- typeof r['model'] === 'string' &&
78
- Number.isInteger(r['tokens']) &&
79
- r['tokens'] >= 0);
80
- default:
81
- return false;
82
- }
83
- }
84
- /** Reads every line; lines that are not a valid record are counted, not fatal. */
85
- export function readMetrics(root) {
86
- const file = join(root, METRICS_FILE);
87
- const records = [];
88
- let broken = 0;
89
- if (!existsSync(file))
90
- return { records, broken };
91
- let text = '';
92
- try {
93
- text = readFileSync(file, 'utf8');
94
- }
95
- catch {
96
- return { records, broken };
97
- }
98
- for (const line of text.split(/\r?\n/)) {
99
- if (!line.trim())
100
- continue;
101
- try {
102
- const o = JSON.parse(line);
103
- if (valid(o))
104
- records.push(o);
105
- else
106
- broken++;
107
- }
108
- catch {
109
- broken++;
110
- }
111
- }
112
- return { records, broken };
113
- }
114
- /** Stop ids renamed in harness 0.1.1: old records carry the red-line-looking C1 and C2. */
115
- const LEGACY_IDS = { C1: 'P1', C2: 'P2' };
116
- /**
117
- * Counts blocking reason ids by kind. An id found in stops.yaml counts as that stop's kind
118
- * (so P1 and P2 are knowledge stops; old C1 and C2 read as P1 and P2); otherwise an id in
119
- * common-red-lines.yaml is a redline;
120
- * an id in neither is not counted and stays in `reasons` only. Each distinct id counts once.
121
- */
122
- export function classify(reasons, harness) {
123
- const out = { intent: 0, knowledge: 0, redline: 0 };
124
- if (!harness)
125
- return out;
126
- let kinds = new Map();
127
- let lines = new Set();
128
- try {
129
- kinds = new Map(stops(harness).map((s) => [s.id, s.kind]));
130
- lines = new Set(redLines(harness).map((r) => r.id));
131
- }
132
- catch {
133
- return out;
134
- }
135
- for (const id of new Set(reasons.map((r) => LEGACY_IDS[r] ?? r))) {
136
- const k = kinds.get(id);
137
- if (k)
138
- out[k]++;
139
- else if (lines.has(id))
140
- out.redline++;
141
- }
142
- return out;
143
- }
144
- const sortKeys = (o) => Object.fromEntries(Object.entries(o).toSorted(([a], [b]) => a.localeCompare(b)));
145
- export function summarize(records, opts = {}) {
146
- const rs = opts.intent ? records.filter((r) => r.intent === opts.intent) : records;
147
- const counts = { check: 0, gate: 0, usage: 0 };
148
- const byRole = {};
149
- const byVendor = {};
150
- let total = 0;
151
- const tickets = new Map();
152
- const intents = new Map();
153
- const intentRow = (i) => {
154
- let row = intents.get(i);
155
- if (!row) {
156
- row = {
157
- intent: i,
158
- tokens: 0,
159
- checks: 0,
160
- stops: { intent: 0, knowledge: 0, redline: 0 },
161
- tickets: 0,
162
- knowledgeStopsPerTicket: null,
163
- seen: new Set(),
164
- };
165
- intents.set(i, row);
166
- }
167
- return row;
168
- };
169
- for (const r of rs) {
170
- counts[r.kind]++;
171
- const i = r.intent ? intentRow(r.intent) : undefined;
172
- let t;
173
- if (r.ticket) {
174
- t = tickets.get(r.ticket);
175
- if (!t) {
176
- t = {
177
- ticket: r.ticket,
178
- intent: r.intent ?? intentOf(r.ticket),
179
- tokens: 0,
180
- checks: 0,
181
- knowledgeStops: 0,
182
- };
183
- tickets.set(r.ticket, t);
184
- }
185
- i?.seen.add(r.ticket);
186
- }
187
- if (r.kind === 'usage') {
188
- total += r.tokens;
189
- byRole[r.role] = (byRole[r.role] ?? 0) + r.tokens;
190
- byVendor[r.vendor] = (byVendor[r.vendor] ?? 0) + r.tokens;
191
- if (t)
192
- t.tokens += r.tokens;
193
- if (i)
194
- i.tokens += r.tokens;
195
- }
196
- else if (r.kind === 'check') {
197
- if (t) {
198
- t.checks++;
199
- t.knowledgeStops += r.stops.knowledge;
200
- }
201
- if (i) {
202
- i.checks++;
203
- i.stops.intent += r.stops.intent;
204
- i.stops.knowledge += r.stops.knowledge;
205
- i.stops.redline += r.stops.redline;
206
- }
207
- }
208
- }
209
- const intentRows = [...intents.values()]
210
- .map(({ seen, ...row }) => ({
211
- ...row,
212
- tickets: seen.size,
213
- knowledgeStopsPerTicket: seen.size === 0 ? null : Math.round((row.stops.knowledge / seen.size) * 100) / 100,
214
- }))
215
- .toSorted((a, b) => a.intent.localeCompare(b.intent));
216
- return {
217
- counts,
218
- broken: opts.broken ?? 0,
219
- tokens: { total, byRole: sortKeys(byRole), byVendor: sortKeys(byVendor) },
220
- tickets: [...tickets.values()].toSorted((a, b) => a.ticket.localeCompare(b.ticket)),
221
- intents: intentRows,
222
- };
223
- }
@@ -1,179 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { intentIds, historyPages, intentFile } from './work.js';
4
- import { readMetrics, summarize } from './metrics.js';
5
- import { splitFrontmatter } from './skills.js';
6
- /** One line per dismissal: the key, how many units it had then, when and why. */
7
- export const DISMISSED = '.loctx/knowledge-proposals/dismissed.jsonl';
8
- /** The latest dismissal of each key; unreadable lines are skipped. */
9
- export function readDismissals(root) {
10
- const out = new Map();
11
- const f = join(root, DISMISSED);
12
- if (!existsSync(f))
13
- return out;
14
- for (const line of readFileSync(f, 'utf8').split(/\r?\n/)) {
15
- try {
16
- const d = JSON.parse(line);
17
- if (typeof d.key === 'string' && typeof d.units === 'number')
18
- out.set(d.key, d);
19
- }
20
- catch {
21
- // a blank or broken line dismisses nothing
22
- }
23
- }
24
- return out;
25
- }
26
- /** `stop:F2` → `F2`; a bare slug stays as it is. */
27
- export const bareKey = (k) => k.replace(/^(stop|reason|decision):/, '');
28
- /** `reasons:` lines of history pages: `reasons: a, b` (design §4, optional line after `decisions:`). */
29
- export function recordedReasons(root) {
30
- const out = [];
31
- for (const h of historyPages(root)) {
32
- const line = /^reasons:\s*(.+)$/m.exec(h.text)?.[1];
33
- if (line)
34
- for (const x of line.split(','))
35
- if (x.trim())
36
- out.push({ path: h.path, reason: x.trim() });
37
- }
38
- return out;
39
- }
40
- /** Slugs already promoted: `decisions` and `symptoms` of `status: active` knowledge entries. */
41
- export function promotedSlugs(root) {
42
- const dir = join(root, '.agents', 'knowledge');
43
- const out = new Set();
44
- if (!existsSync(dir))
45
- return out;
46
- for (const e of readdirSync(dir).filter((x) => x.endsWith('.md'))) {
47
- const { data } = splitFrontmatter(readFileSync(join(dir, e), 'utf8'));
48
- if (!data || data['status'] !== 'active')
49
- continue;
50
- for (const f of ['decisions', 'symptoms']) {
51
- const v = data[f];
52
- if (Array.isArray(v))
53
- for (const x of v)
54
- out.add(String(x));
55
- }
56
- }
57
- return out;
58
- }
59
- /** Pages the tool wrote itself (install, update, migrate): marked `source: tool`, or named so before the marker existed. */
60
- export const toolPage = (h) => /^source:\s*tool\s*$/m.test(h.text) ||
61
- (!ticketOfPage(h.path) && /_(install|update|migrate)-(harness|loop|graph)\.md$/.test(h.path));
62
- const ticketOfPage = (path) => /_(\d{3}-\d+)(?:-|\.|$)/.exec(path)?.[1];
63
- function releaseIntents(root, version) {
64
- const out = new Set();
65
- for (const id of intentIds(root)) {
66
- const v = intentFile(root, id, 'intent')?.data['version'];
67
- if (v !== undefined && String(v) === version)
68
- out.add(id);
69
- }
70
- return out;
71
- }
72
- export function collectRetro(root, opts = {}) {
73
- const release = opts.release ?? null;
74
- const scope = release ? releaseIntents(root, release) : null;
75
- const inScope = (intent) => !scope || (!!intent && scope.has(intent));
76
- const records = readMetrics(root).records.filter((r) => inScope(r.intent));
77
- const units = new Map();
78
- const add = (key, axis, unit, page) => {
79
- let e = units.get(key);
80
- if (!e)
81
- units.set(key, (e = { axis, units: new Set(), pages: new Set() }));
82
- e.units.add(unit);
83
- if (page)
84
- e.pages.add(page);
85
- };
86
- const stops = {};
87
- const failedRounds = { HOLD: 0, STOP: 0 };
88
- for (const r of records) {
89
- if (r.kind !== 'check')
90
- continue;
91
- if (r.verdict === 'HOLD' || r.verdict === 'STOP')
92
- failedRounds[r.verdict]++;
93
- for (const id of new Set(r.reasons)) {
94
- stops[id] = (stops[id] ?? 0) + 1;
95
- if (r.ticket)
96
- add(`stop:${id}`, 'stop', r.ticket);
97
- }
98
- }
99
- const pageIn = (path) => {
100
- const t = ticketOfPage(path);
101
- return !scope || (!!t && scope.has(t.slice(0, 3)));
102
- };
103
- for (const h of historyPages(root)) {
104
- if (!pageIn(h.path) || toolPage(h))
105
- continue;
106
- const unit = ticketOfPage(h.path) ?? h.path;
107
- for (const [axis, field] of [
108
- ['reason', 'reasons'],
109
- ['decision', 'decisions'],
110
- ]) {
111
- const line = new RegExp(`^${field}:\\s*(.+)$`, 'm').exec(h.text)?.[1];
112
- if (!line)
113
- continue;
114
- for (const x of line.split(',')) {
115
- const slug = x.trim();
116
- if (slug)
117
- add(`${axis}:${slug}`, axis, unit, h.path);
118
- }
119
- }
120
- }
121
- const keys = [...units]
122
- .map(([key, e]) => ({
123
- key,
124
- axis: e.axis,
125
- units: [...e.units].toSorted(),
126
- pages: [...e.pages].toSorted(),
127
- }))
128
- .toSorted((a, b) => b.units.length - a.units.length || a.key.localeCompare(b.key));
129
- const done = promotedSlugs(root);
130
- const dismissals = readDismissals(root);
131
- const isDismissed = (k) => k.units.length <= (dismissals.get(k.key)?.units ?? 0);
132
- const repeated = keys.filter((k) => k.units.length >= 2 && !done.has(bareKey(k.key)));
133
- const candidates = repeated.filter((k) => !isDismissed(k));
134
- const dismissed = repeated.filter(isDismissed);
135
- return {
136
- release,
137
- stops: Object.fromEntries(Object.entries(stops).toSorted(([a], [b]) => a.localeCompare(b))),
138
- failedRounds,
139
- tokens: summarize(records).tokens,
140
- keys,
141
- candidates,
142
- dismissed,
143
- };
144
- }
145
- /** The number `reins status` shows; the same count as `retro` over the whole record. */
146
- export const candidateCount = (root) => collectRetro(root).candidates.length;
147
- export function formatRetro(r) {
148
- const n = (x) => x.toLocaleString('en-US');
149
- const out = [`reins retro${r.release ? ` — release ${r.release}` : ''}`];
150
- out.push(`failed rounds: HOLD ${r.failedRounds.HOLD} · STOP ${r.failedRounds.STOP}`);
151
- out.push('stops by id');
152
- const s = Object.entries(r.stops);
153
- if (!s.length)
154
- out.push(' —');
155
- for (const [id, c] of s)
156
- out.push(` ${id.padEnd(8)} ${c}`);
157
- out.push(`tokens: ${n(r.tokens.total)}`);
158
- const roles = Object.entries(r.tokens.byRole);
159
- if (!roles.length)
160
- out.push(' —');
161
- for (const [k, v] of roles)
162
- out.push(` ${k.padEnd(14)} ${n(v).padStart(12)}`);
163
- for (const axis of ['stop', 'reason', 'decision']) {
164
- const rows = r.keys.filter((k) => k.axis === axis && k.units.length >= 2);
165
- out.push(`repeated ${axis} keys`);
166
- if (!rows.length)
167
- out.push(' —');
168
- for (const k of rows) {
169
- const cand = r.candidates.some((c) => c.key === k.key);
170
- const dism = r.dismissed.some((c) => c.key === k.key);
171
- const shown = k.units.slice(0, 4).join(', ') + (k.units.length > 4 ? `, +${k.units.length - 4}` : '');
172
- out.push(` ${k.key} ×${k.units.length} (${shown})${cand ? '' : dism ? ' — dismissed' : ' — promoted'}`);
173
- }
174
- }
175
- out.push(`knowledge candidates: ${r.candidates.length}`);
176
- for (const c of r.candidates)
177
- out.push(` ${c.key}`);
178
- return `${out.join('\n')}\n`;
179
- }
@@ -1,15 +0,0 @@
1
- export const EXIT = { CONTINUE: 0, HOLD: 10, STOP: 20, ESCALATE: 30 };
2
- const RANK = { CONTINUE: 0, STOP: 1, ESCALATE: 2, HOLD: 3 };
3
- /** The report's verdict is the most demanding of its findings; HOLD outranks all; WARN never stops. */
4
- export function report(stage, findings) {
5
- let verdict = 'CONTINUE';
6
- for (const f of findings)
7
- if (f.verdict !== 'WARN' && RANK[f.verdict] > RANK[verdict])
8
- verdict = f.verdict;
9
- const blocking = findings.filter((f) => f.verdict !== 'WARN');
10
- const warns = findings.length - blocking.length;
11
- const summary = blocking.length === 0
12
- ? `${stage}: ok${warns ? ` (${warns} warning${warns > 1 ? 's' : ''})` : ''}`
13
- : `${stage}: ${verdict} — ${blocking.map((f) => f.reason).join(', ')}`;
14
- return { schema: 'reins/bus/stop-report@1', stage, verdict, findings, summary };
15
- }
@@ -1,106 +0,0 @@
1
- import { execFileSync } from 'node:child_process';
2
- import { existsSync, readFileSync, readdirSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { parse } from 'yaml';
5
- import { relPath } from './fsx.js';
6
- import { splitFrontmatter } from './skills.js';
7
- function read(root, abs) {
8
- const { data, body, error } = splitFrontmatter(readFileSync(abs, 'utf8'));
9
- return { path: relPath(root, abs), data: data ?? {}, body, error };
10
- }
11
- const ls = (dir) => (existsSync(dir) ? readdirSync(dir).toSorted() : []);
12
- /** `.agents/intent/<id>_<slug>/` */
13
- export function intentDir(root, id) {
14
- const base = join(root, '.agents', 'intent');
15
- const d = ls(base).find((e) => e === id || e.startsWith(`${id}_`));
16
- return d ? join(base, d) : null;
17
- }
18
- export function intentIds(root) {
19
- return ls(join(root, '.agents', 'intent'))
20
- .map((e) => /^(\d{3})(_|$)/.exec(e)?.[1])
21
- .filter((x) => !!x);
22
- }
23
- /** intent.md, spec.md or plan.md of an intent, or null when the file is not written yet. */
24
- export function intentFile(root, id, kind) {
25
- const d = intentDir(root, id);
26
- const p = d && join(d, `${kind}.md`);
27
- return p && existsSync(p) ? read(root, p) : null;
28
- }
29
- /** `.loctx/ticket/<id>_<slug>.md` — a ticket that is done is deleted, so null may also mean done. */
30
- export function ticketFile(root, id) {
31
- const dir = join(root, '.loctx', 'ticket');
32
- const f = ls(dir).find((e) => e === `${id}.md` || e.startsWith(`${id}_`));
33
- return f ? read(root, join(dir, f)) : null;
34
- }
35
- export function openTickets(root) {
36
- const dir = join(root, '.loctx', 'ticket');
37
- return ls(dir)
38
- .filter((e) => e.endsWith('.md'))
39
- .map((e) => read(root, join(dir, e)));
40
- }
41
- function loadYaml(root, p, broken) {
42
- if (!existsSync(p))
43
- return null;
44
- try {
45
- return parse(readFileSync(p, 'utf8')) ?? null;
46
- }
47
- catch (e) {
48
- const message = (e.message ?? String(e)).split('\n')[0] ?? '';
49
- broken.push({ path: relPath(root, p), message });
50
- return null;
51
- }
52
- }
53
- /** Bus exchanges of one ticket, in request-id order (`<ticket>_<nn>`). */
54
- export function busFor(root, ticket) {
55
- const dir = join(root, '.loctx', 'bus');
56
- const ids = new Set(ls(dir)
57
- .map((e) => /^(.+)\.(request|response)\.yaml$/.exec(e)?.[1])
58
- .filter((x) => !!x && x.startsWith(`${ticket}_`)));
59
- return [...ids].toSorted().map((id) => {
60
- const broken = [];
61
- return {
62
- id,
63
- request: loadYaml(root, join(dir, `${id}.request.yaml`), broken),
64
- response: loadYaml(root, join(dir, `${id}.response.yaml`), broken),
65
- broken,
66
- };
67
- });
68
- }
69
- /** Every history page's text, newest last. */
70
- export function historyPages(root) {
71
- const dir = join(root, '.loctx', 'history');
72
- return ls(dir)
73
- .filter((e) => e.endsWith('.md'))
74
- .map((e) => ({ path: `.loctx/history/${e}`, text: readFileSync(join(dir, e), 'utf8') }));
75
- }
76
- /** Recorded decisions: knowledge `decisions:` entries and history `decisions:` lines, with where they live. */
77
- export function recordedDecisions(root) {
78
- const out = [];
79
- const kdir = join(root, '.agents', 'knowledge');
80
- for (const e of ls(kdir).filter((x) => x.endsWith('.md'))) {
81
- const d = read(root, join(kdir, e)).data['decisions'];
82
- if (Array.isArray(d))
83
- for (const x of d)
84
- out.push({ path: `.agents/knowledge/${e}`, decision: String(x) });
85
- }
86
- for (const h of historyPages(root)) {
87
- const line = /^decisions:\s*(.+)$/m.exec(h.text)?.[1];
88
- if (line)
89
- for (const x of line.split(','))
90
- out.push({ path: h.path, decision: x.trim() });
91
- }
92
- return out;
93
- }
94
- /** Commits that touched a path and carry an `Approved-by:` trailer (design §4: approval = frontmatter + trailer). */
95
- export function approvedBy(root, path) {
96
- try {
97
- const out = execFileSync('git', ['log', '--format=%(trailers:key=Approved-by,valueonly,separator=%x2C)', '--', path], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
98
- return out
99
- .split(/[\n,]/)
100
- .map((s) => s.trim())
101
- .filter(Boolean);
102
- }
103
- catch {
104
- return [];
105
- }
106
- }
@@ -1,24 +0,0 @@
1
- // Re-renders the enforcement tables between the `enforcement` markers of the README and design editions.
2
- // Run by `pnpm docs:enforcement`; the test in cli/test/enforcement.test.ts fails when they drift.
3
- import { readFileSync, writeFileSync } from 'node:fs';
4
- import { resolve } from 'node:path';
5
- import { fileURLToPath, pathToFileURL } from 'node:url';
6
- import { MARKED_DOCS, applyMarkers, enforcementRows } from '../lib/enforcement.js';
7
- // compiled to cli/dist/scripts/: the repository root is three levels up (or the first argument)
8
- const root = resolve(process.argv[2] ?? fileURLToPath(new URL('../../../', import.meta.url)));
9
- export function renderDocs() {
10
- const rows = enforcementRows(resolve(root, 'harness'));
11
- for (const d of MARKED_DOCS) {
12
- const path = resolve(root, d.file);
13
- const { text, pairs } = applyMarkers(readFileSync(path, 'utf8'), d.lang, rows);
14
- if (pairs !== d.pairs) {
15
- console.error(`enforcement: ${d.file} has ${pairs} marker pair(s), expected ${d.pairs}`);
16
- return 1;
17
- }
18
- writeFileSync(path, text);
19
- }
20
- console.log('enforcement tables rendered');
21
- return 0;
22
- }
23
- if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href)
24
- process.exitCode = renderDocs();
@@ -1,13 +0,0 @@
1
- schema: reins/policy/budget@1
2
- # Token budgets (design §3). The narrowest scope in effect wins; a scope with no value only warns.
3
- unit: tokens
4
- scopes: # shipped scopes; a project may add its own
5
- - { name: project, set_by: install, stored_in: this file }
6
- - { name: version, set_by: pm, stored_in: intent/<id>/plan.md }
7
- - { name: rc, set_by: user|pm, stored_in: .loctx/history }
8
- - { name: ticket, set_by: pl, stored_in: ticket frontmatter }
9
- - { name: session, set_by: user, stored_in: .loctx/context }
10
- - { name: role, set_by: user, stored_in: harness/bindings }
11
- precedence: [ticket, rc, version, project] # role caps apply in addition
12
- warn_at: 0.8
13
- defaults: {} # empty until measured on first use (R49)
@@ -1,98 +0,0 @@
1
- schema: reins/policy/enforcement@1
2
- # How each rule is held today (design §2·§3). One line per rule; this is a statement of fact, not of intent:
3
- # `stops.yaml` `detect:` says what the design wants, `held:` says what the code does.
4
- # held: blocked a script, hook or permission deny stops the action before it happens
5
- # checked a transition check, the drift check or CI catches it afterwards
6
- # advised written in a role or skill only; nothing in code catches it
7
- # The grade is the strongest part that really holds; what is left open goes in `gap:`.
8
- # by: deny · hook:pre-commit · hook:pre-push · check:<stage> · check:drift · gate · ci · agent-tools · role
9
- # Keys: C1–C10, A1–G2, T1–T6, `<role>#<n>` (n counts the role's `must_not` items from 1), `budget:<scope>`.
10
- # The tables in README.md, docs/README.ko.md and docs/design*.md are rendered from this file (`pnpm docs:enforcement`).
11
- rules:
12
- # common red lines
13
- - { id: C1, held: advised, by: [role], gap: "judged by reviewers only; nothing detects a hard-coded pass" }
14
- - { id: C2, held: blocked, by: [hook:pre-commit, check:drift], gap: "only when the hook is installed; the edit itself is not prevented" }
15
- - { id: C3, held: blocked, by: [hook:pre-commit, check:drift], gap: "only when the hook is installed; no deny rule covers .claude/settings.json itself" }
16
- - { id: C4, held: blocked, by: [deny, hook:pre-commit], gap: "Claude Code only; .env.* is a finite list, so names such as .env.custom have no deny rule; the hook sees staged paths, not reads" }
17
- - { id: C5, held: blocked, by: [deny, gate, check:verdict], gap: "combined or later-position forms such as git commit -nm are not denied" }
18
- - { id: C6, held: advised, by: [role], gap: "pre-push holds pushes to the default branch (A4) and the deny rules stop force and --no-verify pushes; any other push, PR, merge, release or tag is not blocked" }
19
- - { id: C7, held: advised, by: [role] }
20
- - { id: C8, held: advised, by: [role] }
21
- - { id: C9, held: advised, by: [role] }
22
- - { id: C10, held: advised, by: [role], gap: "T2 lists it but the pre-commit check does not compare the diff with plan.md" }
23
- # stop conditions
24
- - { id: A1, held: blocked, by: [deny, hook:pre-push], gap: "moving a published tag forward to a descendant passes the ancestry test" }
25
- - { id: A2, held: advised, by: [role] }
26
- - { id: A3, held: advised, by: [role] }
27
- - { id: A4, held: blocked, by: [hook:pre-push], gap: "only a push to the default branch is held; other ways of leaving the machine are not detected" }
28
- - { id: B1, held: checked, by: [check:ticket-start] }
29
- - { id: B2, held: advised, by: [role] }
30
- - { id: B3, held: advised, by: [role, check:ticket-start], gap: "the scope conflict is a role's judgement; ticket-start checks only the approval chain" }
31
- - { id: B4, held: advised, by: [role] }
32
- - { id: B5, held: advised, by: [role] }
33
- - { id: P1, held: advised, by: [role] }
34
- - { id: P2, held: checked, by: [check:ticket-start, check:rc-close], gap: "only ticket-in-plan; a diff is not compared with plan.md" }
35
- - { id: D1, held: checked, by: [check:verdict], gap: "does not tell a ticket before rc.1 from an rc after" }
36
- - { id: D2, held: advised, by: [role], gap: "no memory across runs" }
37
- - { id: D3, held: advised, by: [role], gap: "no alone-versus-full-run comparison" }
38
- - { id: D4, held: blocked, by: [gate, check:verdict], gap: "an empty gate output is only a WARN" }
39
- - { id: D5, held: checked, by: [check:verdict] }
40
- - { id: E1, held: advised, by: [role], gap: "nothing reads a budget or a token count" }
41
- - { id: E2, held: advised, by: [role], gap: "nothing reads a budget or a token count" }
42
- - { id: E3, held: advised, by: [role], gap: "T5 lists it but nothing reads a budget or a token count" }
43
- - { id: F1, held: advised, by: [role], gap: "the deny rules stop some attempts in Claude Code, but no stop is recorded" }
44
- - { id: F2, held: blocked, by: [hook:pre-commit, check:drift, check:ticket-start, check:rc-close] }
45
- - { id: F3, held: advised, by: [role] }
46
- - { id: G1, held: advised, by: [role], gap: "no signal handler and no resume record on an interrupt" }
47
- - { id: G2, held: advised, by: [role] }
48
- # transition points
49
- - { id: T1, held: checked, by: [check:ticket-start], gap: "budget-left is not implemented" }
50
- - { id: T2, held: blocked, by: [hook:pre-commit], gap: "only when the hook is installed; the P2 and C10 diff checks do not exist" }
51
- - { id: T3, held: checked, by: [check:verdict] }
52
- - { id: T4, held: blocked, by: [hook:pre-push], gap: "implements A1 and the default-branch push (A4); A2, A3, C6 and the loop-step check do not exist" }
53
- - { id: T5, held: checked, by: [check:rc-close], gap: "E3 is not implemented" }
54
- - { id: T6, held: advised, by: [role], gap: "no code runs on an interrupt or a violation signal" }
55
- # role must_not items, in file order
56
- - { id: "advisor#1", held: advised, by: [role] }
57
- - { id: "advisor#2", held: advised, by: [role] }
58
- - { id: "code-review#1", held: blocked, by: [agent-tools], gap: "Claude agent files only (disallowedTools); shell stays open, so a shell write is not stopped" }
59
- - { id: "code-review#2", held: advised, by: [role] }
60
- - { id: "code-review#3", held: advised, by: [role] }
61
- - { id: "deploy#1", held: advised, by: [role], gap: "the stable dispatch line is only printed on request, nothing refuses it" }
62
- - { id: "deploy#2", held: blocked, by: [deny, hook:pre-push], gap: "see A1" }
63
- - { id: "deploy#3", held: advised, by: [role] }
64
- - { id: "docs#1", held: advised, by: [role] }
65
- - { id: "docs#2", held: advised, by: [role] }
66
- - { id: "docs#3", held: advised, by: [role] }
67
- - { id: "implementer#1", held: advised, by: [role], gap: "see C10" }
68
- - { id: "implementer#2", held: advised, by: [role] }
69
- - { id: "implementer#3", held: advised, by: [role], gap: "see C1" }
70
- - { id: "implementer#4", held: advised, by: [role], gap: "see C6" }
71
- - { id: "implementer#5", held: advised, by: [role] }
72
- - { id: "lookup#1", held: blocked, by: [agent-tools], gap: "Claude agent files only" }
73
- - { id: "lookup#2", held: blocked, by: [agent-tools], gap: "Claude agent files only" }
74
- - { id: "lookup#3", held: blocked, by: [agent-tools], gap: "Claude agent files only" }
75
- - { id: "planner#1", held: advised, by: [role] }
76
- - { id: "planner#2", held: advised, by: [role], gap: "see C10" }
77
- - { id: "planner#3", held: advised, by: [role], gap: "ticket-start checks that the spec is accepted, not who accepted it" }
78
- - { id: "pl#1", held: advised, by: [role], gap: "see C6" }
79
- - { id: "pl#2", held: advised, by: [role] }
80
- - { id: "pl#3", held: advised, by: [role] }
81
- - { id: "pm#1", held: advised, by: [role] }
82
- - { id: "pm#2", held: checked, by: [check:ticket-start], gap: "needs a user entry in approvals and an Approved-by commit trailer; the trailer text can be written by anyone" }
83
- - { id: "pm#3", held: advised, by: [role], gap: "see C6" }
84
- - { id: "qa-design#1", held: advised, by: [role] }
85
- - { id: "qa-design#2", held: advised, by: [role] }
86
- - { id: "qa-design#3", held: advised, by: [role] }
87
- - { id: "qa-run#1", held: advised, by: [role] }
88
- - { id: "qa-run#2", held: advised, by: [role] }
89
- - { id: "verify-tool#1", held: advised, by: [role] }
90
- - { id: "verify-tool#2", held: checked, by: [check:verdict], gap: "evidence is text a role writes; the check reads its command line and exit code" }
91
- - { id: "verify-tool#3", held: checked, by: [check:verdict], gap: "evidence is text a role writes; the check reads its command line and exit code" }
92
- # budget scopes (budget.yaml)
93
- - { id: "budget:project", held: advised, by: [role], gap: "no defaults and no reader" }
94
- - { id: "budget:version", held: advised, by: [role], gap: "no reader" }
95
- - { id: "budget:rc", held: advised, by: [role], gap: "no reader" }
96
- - { id: "budget:ticket", held: advised, by: [role], gap: "no reader" }
97
- - { id: "budget:session", held: advised, by: [role], gap: "no reader" }
98
- - { id: "budget:role", held: advised, by: [role], gap: "no reader" }