@bluenyang/reins 0.2.0 → 0.3.0-rc.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.
Files changed (97) hide show
  1. package/README.md +50 -203
  2. package/cli/dist/commands/config-models.js +206 -127
  3. package/cli/dist/commands/config.js +104 -16
  4. package/cli/dist/commands/configure.js +166 -134
  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 +111 -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/prompter.js +4 -4
  15. package/cli/dist/lib/reader.js +20 -0
  16. package/cli/dist/lib/upstream.js +0 -17
  17. package/cli/dist/lib/vendor-write.js +9 -56
  18. package/cli/dist/reins.js +59 -270
  19. package/docs/README.ko.md +31 -204
  20. package/harness/CHANGELOG.md +8 -3
  21. package/harness/VERSION +1 -1
  22. package/harness/models.yaml +8 -0
  23. package/harness/policy/common-red-lines.yaml +4 -4
  24. package/harness/roles/advisor.md +10 -14
  25. package/harness/roles/auditor.md +17 -0
  26. package/harness/roles/executor.md +32 -0
  27. package/harness/roles/implementer.md +23 -21
  28. package/harness/roles/pl.md +44 -21
  29. package/harness/roles/planner.md +17 -19
  30. package/harness/roles/pm.md +16 -21
  31. package/harness/schemas/bindings.schema.json +55 -0
  32. package/harness/schemas/install.schema.json +1 -2
  33. package/harness/schemas/intent.schema.json +1 -13
  34. package/harness/templates/agents-md-blocks.md +52 -17
  35. package/harness/templates/audit.md +25 -0
  36. package/harness/templates/history.md +14 -0
  37. package/harness/templates/intent.md +5 -0
  38. package/harness/templates/spec.md +4 -2
  39. package/package.json +1 -2
  40. package/skills/audit/SKILL.md +28 -0
  41. package/skills/implement/SKILL.md +30 -0
  42. package/skills/intent/SKILL.md +28 -0
  43. package/skills/merge/SKILL.md +26 -0
  44. package/skills/onboard/SKILL.md +31 -0
  45. package/skills/reins-setup/SKILL.md +16 -25
  46. package/skills/release/SKILL.md +26 -0
  47. package/skills/retro/SKILL.md +30 -0
  48. package/skills/review/SKILL.md +27 -0
  49. package/skills/roadmap/SKILL.md +29 -0
  50. package/skills/spec/SKILL.md +27 -0
  51. package/skills/test/SKILL.md +26 -0
  52. package/cli/dist/commands/check.js +0 -379
  53. package/cli/dist/commands/gate.js +0 -136
  54. package/cli/dist/commands/knowledge.js +0 -111
  55. package/cli/dist/commands/metrics.js +0 -138
  56. package/cli/dist/commands/new.js +0 -190
  57. package/cli/dist/commands/retro.js +0 -7
  58. package/cli/dist/commands/stages.js +0 -562
  59. package/cli/dist/commands/status.js +0 -281
  60. package/cli/dist/lib/enforcement.js +0 -125
  61. package/cli/dist/lib/memory.js +0 -96
  62. package/cli/dist/lib/metrics.js +0 -223
  63. package/cli/dist/lib/retro.js +0 -179
  64. package/cli/dist/lib/verdict.js +0 -15
  65. package/cli/dist/lib/work.js +0 -106
  66. package/cli/dist/scripts/enforcement.js +0 -24
  67. package/harness/policy/budget.yaml +0 -13
  68. package/harness/policy/enforcement.yaml +0 -98
  69. package/harness/policy/stops.yaml +0 -29
  70. package/harness/policy/transitions.yaml +0 -13
  71. package/harness/roles/code-review.md +0 -27
  72. package/harness/roles/deploy.md +0 -50
  73. package/harness/roles/docs.md +0 -19
  74. package/harness/roles/lookup.md +0 -22
  75. package/harness/roles/qa-design.md +0 -22
  76. package/harness/roles/qa-run.md +0 -19
  77. package/harness/roles/verify-tool.md +0 -21
  78. package/harness/schemas/bindings-local.schema.json +0 -21
  79. package/harness/schemas/bus-request.schema.json +0 -17
  80. package/harness/schemas/bus-response.schema.json +0 -14
  81. package/harness/schemas/enforcement.schema.json +0 -22
  82. package/harness/schemas/plan.schema.json +0 -10
  83. package/harness/schemas/ticket.schema.json +0 -15
  84. package/harness/templates/bus/request.yaml +0 -20
  85. package/harness/templates/bus/response.yaml +0 -10
  86. package/harness/templates/plan.md +0 -23
  87. package/harness/templates/ticket.md +0 -29
  88. package/skills/reins-implement/SKILL.md +0 -20
  89. package/skills/reins-intent/SKILL.md +0 -26
  90. package/skills/reins-loop/SKILL.md +0 -26
  91. package/skills/reins-loop/references/vendor-cli.md +0 -41
  92. package/skills/reins-release/SKILL.md +0 -18
  93. package/skills/reins-retro/SKILL.md +0 -20
  94. package/skills/reins-review/SKILL.md +0 -23
  95. package/skills/reins-roadmap/SKILL.md +0 -17
  96. package/skills/reins-spec/SKILL.md +0 -22
  97. package/skills/reins-test/SKILL.md +0 -18
@@ -1,281 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
- import { basename, join } from 'node:path';
3
- import { parse } from 'yaml';
4
- import { resolveBindings, roleStates, stateLabel } from '../lib/bindings.js';
5
- import { repoRoot } from '../lib/git.js';
6
- import { harnessVersion, packageHarness, packageVersion } from '../lib/upstream.js';
7
- import { candidateCount } from '../lib/retro.js';
8
- import { driftGenerated } from '../lib/vendor-write.js';
9
- import { report } from '../lib/verdict.js';
10
- import { historyPages, intentDir, intentFile, intentIds, openTickets, } from '../lib/work.js';
11
- import { driftConvention, driftFormat, driftMatch } from './check.js';
12
- import { ticketStart } from './stages.js';
13
- const TICKET_STATUSES = ['todo', 'doing', 'blocked', 'done'];
14
- const str = (v) => (typeof v === 'string' ? v : typeof v === 'number' ? String(v) : '');
15
- /** Strings and numbers of an array; anything else (objects, null) is dropped, so a malformed value cannot throw. */
16
- const list = (v) => Array.isArray(v)
17
- ? v.filter((x) => typeof x === 'string' || typeof x === 'number').map(String)
18
- : [];
19
- const distinct = (xs) => [...new Set(xs)];
20
- const mentions = (text, id) => new RegExp(`(?<![\\w-])${id.replace(/[-]/g, '\\-')}(?![\\w-])`).test(text);
21
- function safe(fn, fallback) {
22
- try {
23
- return fn();
24
- }
25
- catch {
26
- return fallback;
27
- }
28
- }
29
- function harnessStatus(root) {
30
- const pin = join(root, '.agents', 'harness', 'install.yaml');
31
- const none = { ok: true, reasons: [], findings: [] };
32
- if (!existsSync(pin))
33
- return {
34
- installed: false,
35
- tier: null,
36
- installedVersion: null,
37
- packageVersion: null,
38
- cliInstalled: null,
39
- cliPackage: null,
40
- drift: none,
41
- };
42
- const y = safe(() => parse(readFileSync(pin, 'utf8')) ?? {}, {});
43
- const findings = [driftFormat, driftConvention, driftMatch, driftGenerated].flatMap((f) => safe(() => f(root), []));
44
- return {
45
- installed: true,
46
- tier: str(y['tier']) || null,
47
- installedVersion: str(y['version']) || null,
48
- packageVersion: safe(() => harnessVersion(packageHarness()), null),
49
- cliInstalled: str(y['cli']) || null,
50
- cliPackage: safe(() => packageVersion(), null),
51
- drift: {
52
- ok: findings.length === 0,
53
- reasons: distinct(findings.map((f) => f.reason)),
54
- findings,
55
- },
56
- };
57
- }
58
- /** The S-3 table: the first row that matches wins. */
59
- export function nextForIntent(s) {
60
- if (s.intent === 'released')
61
- return '—';
62
- if (s.intent === 'draft')
63
- return 'user: approve the intent';
64
- if (s.intent === 'approved' && s.spec === null)
65
- return 'planner: write spec.md';
66
- if (s.spec === 'draft')
67
- return 'pm + qa-design: review the spec';
68
- if (s.spec === 'reviewed')
69
- return 'user: read summary_for_user (veto or accept)';
70
- if (s.spec === 'rejected')
71
- return 'planner: revise spec.md';
72
- if (s.spec === 'accepted' && s.plan === null)
73
- return 'pl: write plan.md';
74
- if (s.plan === 'draft')
75
- return 'qa-design: review the plan';
76
- const recorded = (t) => s.history.some((h) => mentions(h, t));
77
- const closed = (t) => !s.openIds.includes(t);
78
- if (s.plan !== null && s.planned.length > 0 && s.planned.every((t) => closed(t) && recorded(t)))
79
- return 'pm: close the rc (reins check --stage rc-close --release <version>)';
80
- if ((s.plan === 'reviewed' || s.plan === 'active') &&
81
- s.open === 0 &&
82
- s.planned.some((t) => closed(t) && !recorded(t)))
83
- return 'pl: create tickets';
84
- const first = [...(s.openTickets ?? [])].sort((a, b) => a.id.localeCompare(b.id, 'en', { numeric: true }))[0];
85
- if (s.open > 0 && first) {
86
- if (first.status === 'done')
87
- return `reins-review: close ${first.id}`;
88
- if (first.status === 'blocked')
89
- return `pl: unblock ${first.id}`;
90
- if (first.status === 'todo' || first.status === 'doing')
91
- return `implementer: ${first.id} (reins-implement)`;
92
- }
93
- if (s.broken.length > 0)
94
- return `invalid frontmatter (F2): ${s.broken.join(', ')}`;
95
- return '—';
96
- }
97
- function statusOf(f) {
98
- return f ? str(f.data['status']) || '?' : null;
99
- }
100
- function intentsStatus(root, tickets) {
101
- const history = safe(() => historyPages(root).map((h) => h.text), []);
102
- const intents = [];
103
- let superseded = 0;
104
- for (const id of intentIds(root)) {
105
- const i = intentFile(root, id, 'intent');
106
- if (i?.data['status'] === 'superseded') {
107
- superseded++;
108
- continue;
109
- }
110
- const spec = intentFile(root, id, 'spec');
111
- const plan = intentFile(root, id, 'plan');
112
- const planned = list(plan?.data['tickets']);
113
- const mine = tickets.filter((t) => str(t.data['intent']) === id);
114
- const open = mine.length;
115
- const dir = intentDir(root, id);
116
- intents.push({
117
- id,
118
- slug: str(i?.data['slug']) || (dir ? basename(dir).replace(/^\d{3}_?/, '') : ''),
119
- version: str(i?.data['version']) || null,
120
- intent: statusOf(i),
121
- spec: statusOf(spec),
122
- plan: statusOf(plan),
123
- tickets: { open, planned: planned.length },
124
- next: nextForIntent({
125
- intent: statusOf(i),
126
- spec: statusOf(spec),
127
- plan: statusOf(plan),
128
- open,
129
- openIds: tickets.map(ticketId),
130
- openTickets: mine.map((t) => ({ id: ticketId(t), status: str(t.data['status']) || null })),
131
- planned,
132
- history,
133
- broken: [i, spec, plan].filter((f) => !!f?.error).map((f) => f.path),
134
- }),
135
- });
136
- }
137
- return { intents, superseded };
138
- }
139
- const fileIdOf = (t) => /^([^_.]+)/.exec(basename(t.path))?.[1] ?? basename(t.path);
140
- const ticketId = (t) => str(t.data['id']) || fileIdOf(t);
141
- /** A ticket that cannot be read; shown as invalid so one bad file never hides the others. */
142
- function invalidTicket(t) {
143
- return {
144
- id: ticketId(t),
145
- path: t.path,
146
- status: null,
147
- role: null,
148
- intent: null,
149
- orphan: false,
150
- invalid: true,
151
- asks: [],
152
- t1: null,
153
- next: 'invalid (F2)',
154
- };
155
- }
156
- function ticketStatus(root, t) {
157
- try {
158
- return readTicket(root, t);
159
- }
160
- catch {
161
- return invalidTicket(t);
162
- }
163
- }
164
- function readTicket(root, t) {
165
- const fileId = fileIdOf(t);
166
- const id = ticketId(t);
167
- const status = str(t.data['status']) || null;
168
- const intent = str(t.data['intent']) || null;
169
- const role = str(t.data['role']) || null;
170
- const rawAsks = t.data['asks'];
171
- const asksOk = rawAsks === undefined ||
172
- rawAsks === null ||
173
- (Array.isArray(rawAsks) && rawAsks.every((a) => typeof a === 'string'));
174
- const asks = asksOk ? list(rawAsks) : [];
175
- const invalid = !!t.error || !asksOk || status === null || !TICKET_STATUSES.includes(status);
176
- const orphan = !intent || !intentDir(root, intent);
177
- const base = { id, path: t.path, status, role, intent, orphan, invalid, asks, t1: null };
178
- if (invalid)
179
- return { ...base, next: 'invalid (F2)' };
180
- if (status === 'todo') {
181
- const findings = safe(() => ticketStart(root, fileId), [
182
- { reason: 'F2', verdict: 'STOP', message: 'T1 could not run' },
183
- ]);
184
- const r = report('ticket-start', findings);
185
- const reasons = distinct(findings.filter((f) => f.verdict !== 'WARN').map((f) => f.reason));
186
- const next = r.verdict === 'CONTINUE'
187
- ? `${role ?? 'implementer'}: start`
188
- : `T1 ${r.verdict} (${reasons.join(', ')}) — reins check --stage ticket-start --ticket ${fileId}`;
189
- return { ...base, t1: { verdict: r.verdict, reasons }, next };
190
- }
191
- if (status === 'doing')
192
- return { ...base, next: `reins check --stage verdict --ticket ${id}` };
193
- if (status === 'blocked')
194
- return { ...base, next: `blocked — ${asks.length} open ask${asks.length === 1 ? '' : 's'}` };
195
- return { ...base, next: 'write history, delete the ticket' };
196
- }
197
- function busCount(root) {
198
- const dir = join(root, '.loctx', 'bus');
199
- return existsSync(dir) ? readdirSync(dir).filter((e) => e.endsWith('.yaml')).length : 0;
200
- }
201
- /** Everything `reins status` shows, as plain data. Reads only; never throws on malformed files. */
202
- export function collectStatus(root) {
203
- const open = safe(() => openTickets(root), []);
204
- const { intents, superseded } = safe(() => intentsStatus(root, open), {
205
- intents: [],
206
- superseded: 0,
207
- });
208
- const pages = safe(() => historyPages(root), []);
209
- return {
210
- harness: harnessStatus(root),
211
- intents,
212
- supersededIntents: superseded,
213
- tickets: open.map((t) => ticketStatus(root, t)),
214
- bus: safe(() => busCount(root), 0),
215
- lastHistory: pages.length ? basename(pages[pages.length - 1].path) : null,
216
- knowledgeCandidates: safe(() => candidateCount(root), 0),
217
- bindings: safe(() => (existsSync(join(root, '.agents/harness/bindings.yaml')) ? resolveBindings(root) : []), []),
218
- };
219
- }
220
- /** The text view of the same object `--json` prints. */
221
- export function formatStatus(d) {
222
- const out = [];
223
- const h = d.harness;
224
- if (!h.installed)
225
- out.push('harness: not installed — run reins install');
226
- else
227
- out.push(`harness: ${h.tier ?? '?'} v${h.installedVersion ?? '?'} (package harness v${h.packageVersion ?? '?'}) · cli ${h.cliInstalled ?? 'none'} (running ${h.cliPackage ?? '?'}) · drift: ${h.drift.ok ? 'ok' : h.drift.reasons.join(', ')}${h.drift.ok ? '' : ' (reins check --drift)'}`);
228
- out.push('');
229
- out.push('intents:');
230
- if (d.intents.length === 0)
231
- out.push(' none');
232
- for (const i of d.intents) {
233
- if (i.intent === 'released') {
234
- out.push(` ${i.id} ${i.slug}${i.version ? ` v${i.version}` : ''} — released`);
235
- continue;
236
- }
237
- out.push(` ${i.id} ${i.slug}${i.version ? ` v${i.version}` : ''} — intent: ${i.intent ?? '—'} · spec: ${i.spec ?? '—'} · plan: ${i.plan ?? '—'} · tickets: ${i.tickets.open} open / ${i.tickets.planned} planned`);
238
- out.push(` next: ${i.next}`);
239
- }
240
- if (d.supersededIntents > 0)
241
- out.push(` (${d.supersededIntents} superseded, hidden)`);
242
- out.push('');
243
- out.push('tickets:');
244
- if (d.tickets.length === 0)
245
- out.push(' none open');
246
- for (const t of d.tickets) {
247
- out.push(` ${t.id} — ${t.status ?? '?'} · ${t.role ?? '?'} · asks: ${t.asks.length}${t.orphan ? ' · orphan' : ''}`);
248
- out.push(` next: ${t.next}`);
249
- if (t.status === 'blocked' && !t.invalid)
250
- for (const a of t.asks)
251
- out.push(` ? ${a}`);
252
- }
253
- out.push('');
254
- out.push(`bus: ${d.bus} file${d.bus === 1 ? '' : 's'}`);
255
- out.push(`last history: ${d.lastHistory ?? '—'}`);
256
- out.push(`knowledge candidates: ${d.knowledgeCandidates}`);
257
- if (d.bindings.length) {
258
- out.push('');
259
- out.push('bindings (resolved):');
260
- for (const b of d.bindings)
261
- out.push(` ${b.role.padEnd(12)} ${b.vendor.padEnd(7)} ${b.model} (${b.source})${stateLabel(b) ? ` ${stateLabel(b)}` : ''}`);
262
- }
263
- return `${out.join('\n')}\n`;
264
- }
265
- /** `reins status [--json]`: exit 0 anywhere inside a git repository, 2 outside one. */
266
- export function runStatus(opts = {}) {
267
- let root;
268
- try {
269
- root = repoRoot(opts.cwd ?? process.cwd());
270
- }
271
- catch {
272
- return { code: 2, stdout: '', stderr: 'reins status: not inside a git repository\n' };
273
- }
274
- const data = collectStatus(root);
275
- const warnings = safe(() => roleStates(root).warnings, []);
276
- return {
277
- code: 0,
278
- stdout: opts.json ? `${JSON.stringify(data, null, 2)}\n` : formatStatus(data),
279
- stderr: warnings.map((w) => `${w}\n`).join(''),
280
- };
281
- }
@@ -1,125 +0,0 @@
1
- import { readFileSync, readdirSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { parse } from 'yaml';
4
- import { splitFrontmatter } from './skills.js';
5
- const HELD = ['blocked', 'checked', 'advised'];
6
- const WORDS = {
7
- en: { blocked: 'blocked', checked: 'checked', advised: 'advised' },
8
- ko: { blocked: '차단', checked: '검사', advised: '권고' },
9
- };
10
- const HEAD = {
11
- en: {
12
- main: ['id', 'held', 'by', 'gap'],
13
- role: ['role', 'blocked', 'checked', 'advised', 'blocked items'],
14
- budget: 'budget scopes',
15
- },
16
- ko: {
17
- main: ['id', '지킴', '수단', '빈틈'],
18
- role: ['역할', '차단', '검사', '권고', '차단되는 항목'],
19
- budget: '예산 범위',
20
- },
21
- };
22
- export function readRules(text) {
23
- const d = parse(text);
24
- return d?.rules ?? [];
25
- }
26
- /** `must_not` items of every role file in `<harness>/roles`, by role name. */
27
- export function roleMustNot(harness) {
28
- const out = new Map();
29
- const dir = join(harness, 'roles');
30
- for (const f of readdirSync(dir)
31
- .filter((x) => x.endsWith('.md'))
32
- .toSorted()) {
33
- const m = splitFrontmatter(readFileSync(join(dir, f), 'utf8')).data?.['must_not'];
34
- out.set(f.replace(/\.md$/, ''), Array.isArray(m) ? m.map(String) : []);
35
- }
36
- return out;
37
- }
38
- /** Every id the table must cover: policy files, role `must_not` items, budget scopes. */
39
- export function expectedIds(harness) {
40
- const y = (f) => parse(readFileSync(join(harness, 'policy', f), 'utf8'));
41
- const ids = [];
42
- for (const r of y('common-red-lines.yaml')['rules'] ?? [])
43
- ids.push(r.id);
44
- for (const s of y('stops.yaml')['stops'] ?? [])
45
- ids.push(s.id);
46
- for (const p of y('transitions.yaml')['points'] ?? [])
47
- ids.push(p.id);
48
- for (const [role, items] of roleMustNot(harness))
49
- items.forEach((_, i) => ids.push(`${role}#${i + 1}`));
50
- for (const s of y('budget.yaml')['scopes'] ?? [])
51
- ids.push(`budget:${s.name}`);
52
- return ids;
53
- }
54
- /** The rules of `enforcement.yaml`, each with its `must_not` text where it has one. */
55
- export function enforcementRows(harness) {
56
- const mustNot = roleMustNot(harness);
57
- return readRules(readFileSync(join(harness, 'policy', 'enforcement.yaml'), 'utf8')).map((r) => {
58
- const m = /^(.+)#(\d+)$/.exec(r.id);
59
- const text = m ? mustNot.get(m[1] ?? '')?.[Number(m[2]) - 1] : undefined;
60
- return text === undefined ? r : { ...r, text };
61
- });
62
- }
63
- const esc = (s) => s.replaceAll('|', '\\|');
64
- const table = (head, rows) => [
65
- `| ${head.join(' | ')} |`,
66
- `|${head.map(() => '---').join('|')}|`,
67
- ...rows.map((r) => `| ${r.map(esc).join(' | ')} |`),
68
- ];
69
- const isRole = (id) => id.includes('#');
70
- const isBudget = (id) => id.startsWith('budget:');
71
- function mainRows(rows, lang, pick) {
72
- return table(HEAD[lang].main, rows
73
- .filter((r) => pick(r.id))
74
- .map((r) => [
75
- r.id,
76
- WORDS[lang][r.held],
77
- r.by.map((b) => `\`${b}\``).join(', '),
78
- r.gap ?? '—',
79
- ]));
80
- }
81
- function roleRows(rows, lang) {
82
- const roles = new Map();
83
- for (const r of rows.filter((x) => isRole(x.id))) {
84
- const role = r.id.slice(0, r.id.indexOf('#'));
85
- roles.set(role, [...(roles.get(role) ?? []), r]);
86
- }
87
- const count = (rs, h) => String(rs.filter((r) => r.held === h).length);
88
- const body = [...roles].map(([role, rs]) => [
89
- role,
90
- ...HELD.map((h) => count(rs, h)),
91
- rs
92
- .filter((r) => r.held === 'blocked')
93
- .map((r) => r.text ?? r.id)
94
- .join('; ') || '—',
95
- ]);
96
- const budget = rows.filter((r) => isBudget(r.id));
97
- body.push([HEAD[lang].budget, ...HELD.map((h) => count(budget, h)), '—']);
98
- return table(HEAD[lang].role, body);
99
- }
100
- /** The Markdown tables between the `enforcement` markers; no trailing newline. */
101
- export function renderTable(rows, lang, view = 'all') {
102
- if (view === 'redlines')
103
- return mainRows(rows, lang, (id) => /^C\d+$/.test(id)).join('\n');
104
- if (view === 'stops')
105
- return mainRows(rows, lang, (id) => /^[ABDEFGPT]\d+$/.test(id)).join('\n');
106
- const main = mainRows(rows, lang, (id) => !isRole(id) && !isBudget(id));
107
- return [...main, '', ...roleRows(rows, lang)].join('\n');
108
- }
109
- const MARK = /(<!-- enforcement:begin(?: (\w+))? -->\n)([\s\S]*?)(\n<!-- enforcement:end -->)/g;
110
- /** Replaces the content of every `enforcement` marker pair with the rendered table; returns the text and how many pairs it found. */
111
- export function applyMarkers(text, lang, rows) {
112
- let pairs = 0;
113
- const out = text.replace(MARK, (_m, open, view, _body, close) => {
114
- pairs += 1;
115
- return `${open}${renderTable(rows, lang, view ?? 'all')}${close}`;
116
- });
117
- return { text: out, pairs };
118
- }
119
- /** Documents that carry markers, with their language and how many pairs each must hold. */
120
- export const MARKED_DOCS = [
121
- { file: 'README.md', lang: 'en', pairs: 1 },
122
- { file: 'docs/README.ko.md', lang: 'ko', pairs: 1 },
123
- { file: 'docs/design.md', lang: 'en', pairs: 2 },
124
- { file: 'docs/design.ko.md', lang: 'ko', pairs: 2 },
125
- ];
@@ -1,96 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { listFiles } from './fsx.js';
4
- import { isSecretPath } from './secrets.js';
5
- const slug = (rel) => rel
6
- .replace(/\.[^./]+$/, '')
7
- .toLowerCase()
8
- .replaceAll(/[^a-z0-9]+/g, '-')
9
- .replaceAll(/^-+|-+$/g, '') || 'note';
10
- /**
11
- * `.claude/memory/*` is someone's own memory, not a decision (design §7): it is never moved or
12
- * deleted. Each file becomes a knowledge draft the user may accept with `reins knowledge accept`.
13
- * Pure: reads, never writes. A draft that already exists is left alone.
14
- */
15
- export function planMemoryProposals(root, today) {
16
- const out = { writes: [], notes: [] };
17
- const dir = join(root, '.claude/memory');
18
- if (!existsSync(dir))
19
- return out;
20
- // a draft is identified by its `source:`, so names stay stable across runs
21
- const pdir = join(root, '.loctx/knowledge-proposals');
22
- const taken = new Set();
23
- const drafted = new Set();
24
- const srcOf = (file) => {
25
- let text;
26
- try {
27
- text = readFileSync(file, 'utf8');
28
- }
29
- catch {
30
- return null; // a directory or an unreadable entry names no source; its name stays taken
31
- }
32
- const m = /^source:\s*(.+)$/m.exec(text);
33
- return m ? m[1].trim().replace(/^"(.*)"$/, '$1') : null;
34
- };
35
- // an accepted entry keeps the source: its draft had, so accepting does not cause a re-draft
36
- const kdir = join(root, '.agents/knowledge');
37
- if (existsSync(kdir))
38
- for (const n of readdirSync(kdir)) {
39
- if (!n.endsWith('.md'))
40
- continue;
41
- const src = srcOf(join(kdir, n));
42
- if (src)
43
- drafted.add(src);
44
- }
45
- if (existsSync(pdir))
46
- for (const n of readdirSync(pdir)) {
47
- if (!/^memory-.*\.md$/.test(n))
48
- continue;
49
- taken.add(n.slice(0, -3));
50
- const src = srcOf(join(pdir, n));
51
- if (src)
52
- drafted.add(src);
53
- }
54
- for (const f of listFiles(dir)) {
55
- const source = `.claude/memory/${f}`;
56
- if (isSecretPath(source))
57
- continue;
58
- if (drafted.has(source))
59
- continue;
60
- const base = `memory-${slug(f)}`;
61
- let name = base;
62
- for (let i = 2; taken.has(name); i++)
63
- name = `${base}-${i}`;
64
- taken.add(name);
65
- const path = `.loctx/knowledge-proposals/${name}.md`;
66
- let text;
67
- try {
68
- text = readFileSync(join(dir, f), 'utf8');
69
- }
70
- catch {
71
- continue;
72
- }
73
- out.writes.push({
74
- path,
75
- why: 'memory draft',
76
- content: [
77
- '---',
78
- `id: ${today}_${name}`,
79
- 'kind: decision',
80
- 'status: active',
81
- 'supersedes: null',
82
- 'topics: []',
83
- 'decisions: []',
84
- 'symptoms: []',
85
- 'applies_to: all',
86
- `source: ${JSON.stringify(source)}`,
87
- '---',
88
- '## 결정',
89
- text.replace(/\s*$/, ''),
90
- '',
91
- ].join('\n'),
92
- });
93
- out.notes.push(`memory draft ${path} from ${source} (original kept) — promote with \`reins knowledge accept ${name}\``);
94
- }
95
- return out;
96
- }