@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.
- package/README.md +50 -203
- package/cli/dist/commands/config-models.js +206 -127
- package/cli/dist/commands/config.js +104 -16
- package/cli/dist/commands/configure.js +166 -134
- package/cli/dist/commands/install.js +161 -217
- package/cli/dist/commands/migrate.js +23 -48
- package/cli/dist/commands/update.js +203 -30
- package/cli/dist/lib/agents-md.js +111 -0
- package/cli/dist/lib/bindings.js +227 -386
- package/cli/dist/lib/detect.js +7 -2
- package/cli/dist/lib/generate.js +56 -75
- package/cli/dist/lib/harness.js +0 -3
- package/cli/dist/lib/migrate-plan.js +3 -3
- package/cli/dist/lib/prompter.js +4 -4
- package/cli/dist/lib/reader.js +20 -0
- package/cli/dist/lib/upstream.js +0 -17
- package/cli/dist/lib/vendor-write.js +9 -56
- package/cli/dist/reins.js +59 -270
- package/docs/README.ko.md +31 -204
- package/harness/CHANGELOG.md +8 -3
- package/harness/VERSION +1 -1
- package/harness/models.yaml +8 -0
- package/harness/policy/common-red-lines.yaml +4 -4
- package/harness/roles/advisor.md +10 -14
- package/harness/roles/auditor.md +17 -0
- package/harness/roles/executor.md +32 -0
- package/harness/roles/implementer.md +23 -21
- package/harness/roles/pl.md +44 -21
- package/harness/roles/planner.md +17 -19
- package/harness/roles/pm.md +16 -21
- package/harness/schemas/bindings.schema.json +55 -0
- package/harness/schemas/install.schema.json +1 -2
- package/harness/schemas/intent.schema.json +1 -13
- package/harness/templates/agents-md-blocks.md +52 -17
- package/harness/templates/audit.md +25 -0
- package/harness/templates/history.md +14 -0
- package/harness/templates/intent.md +5 -0
- package/harness/templates/spec.md +4 -2
- package/package.json +1 -2
- package/skills/audit/SKILL.md +28 -0
- package/skills/implement/SKILL.md +30 -0
- package/skills/intent/SKILL.md +28 -0
- package/skills/merge/SKILL.md +26 -0
- package/skills/onboard/SKILL.md +31 -0
- package/skills/reins-setup/SKILL.md +16 -25
- package/skills/release/SKILL.md +26 -0
- package/skills/retro/SKILL.md +30 -0
- package/skills/review/SKILL.md +27 -0
- package/skills/roadmap/SKILL.md +29 -0
- package/skills/spec/SKILL.md +27 -0
- package/skills/test/SKILL.md +26 -0
- package/cli/dist/commands/check.js +0 -379
- package/cli/dist/commands/gate.js +0 -136
- package/cli/dist/commands/knowledge.js +0 -111
- package/cli/dist/commands/metrics.js +0 -138
- package/cli/dist/commands/new.js +0 -190
- package/cli/dist/commands/retro.js +0 -7
- package/cli/dist/commands/stages.js +0 -562
- package/cli/dist/commands/status.js +0 -281
- package/cli/dist/lib/enforcement.js +0 -125
- package/cli/dist/lib/memory.js +0 -96
- package/cli/dist/lib/metrics.js +0 -223
- package/cli/dist/lib/retro.js +0 -179
- package/cli/dist/lib/verdict.js +0 -15
- package/cli/dist/lib/work.js +0 -106
- package/cli/dist/scripts/enforcement.js +0 -24
- package/harness/policy/budget.yaml +0 -13
- package/harness/policy/enforcement.yaml +0 -98
- package/harness/policy/stops.yaml +0 -29
- package/harness/policy/transitions.yaml +0 -13
- package/harness/roles/code-review.md +0 -27
- package/harness/roles/deploy.md +0 -50
- package/harness/roles/docs.md +0 -19
- package/harness/roles/lookup.md +0 -22
- package/harness/roles/qa-design.md +0 -22
- package/harness/roles/qa-run.md +0 -19
- package/harness/roles/verify-tool.md +0 -21
- package/harness/schemas/bindings-local.schema.json +0 -21
- package/harness/schemas/bus-request.schema.json +0 -17
- package/harness/schemas/bus-response.schema.json +0 -14
- package/harness/schemas/enforcement.schema.json +0 -22
- package/harness/schemas/plan.schema.json +0 -10
- package/harness/schemas/ticket.schema.json +0 -15
- package/harness/templates/bus/request.yaml +0 -20
- package/harness/templates/bus/response.yaml +0 -10
- package/harness/templates/plan.md +0 -23
- package/harness/templates/ticket.md +0 -29
- package/skills/reins-implement/SKILL.md +0 -20
- package/skills/reins-intent/SKILL.md +0 -26
- package/skills/reins-loop/SKILL.md +0 -26
- package/skills/reins-loop/references/vendor-cli.md +0 -41
- package/skills/reins-release/SKILL.md +0 -18
- package/skills/reins-retro/SKILL.md +0 -20
- package/skills/reins-review/SKILL.md +0 -23
- package/skills/reins-roadmap/SKILL.md +0 -17
- package/skills/reins-spec/SKILL.md +0 -22
- package/skills/reins-test/SKILL.md +0 -18
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
|
|
2
|
-
import { basename, join, relative, resolve } from 'node:path';
|
|
3
|
-
import { repoRoot } from '../lib/git.js';
|
|
4
|
-
import { harnessDir } from '../lib/harness.js';
|
|
5
|
-
import { localIso } from '../lib/metrics.js';
|
|
6
|
-
import { bareKey, collectRetro, DISMISSED } from '../lib/retro.js';
|
|
7
|
-
import { loadSchemas, validateFile } from '../lib/schema.js';
|
|
8
|
-
export const PROPOSALS = '.loctx/knowledge-proposals';
|
|
9
|
-
const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
10
|
-
const today = () => localIso().slice(0, 10);
|
|
11
|
-
/** Replace the frontmatter line starting with `key:`; `null` removes it. */
|
|
12
|
-
function setLine(text, key, value) {
|
|
13
|
-
if (value === null)
|
|
14
|
-
return text.replace(new RegExp(`^${key}:.*\\n`, 'm'), '');
|
|
15
|
-
return text.replace(new RegExp(`^${key}:.*$`, 'm'), () => `${key}: ${value}`);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* `reins knowledge propose <key|slug> [--from <history>…]`: a draft from the knowledge template,
|
|
19
|
-
* `approved` left out. Writes only under `.loctx/knowledge-proposals/`.
|
|
20
|
-
*/
|
|
21
|
-
export function proposeKnowledge(key, o = {}) {
|
|
22
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
23
|
-
const slug = bareKey(key);
|
|
24
|
-
if (!SLUG.test(slug))
|
|
25
|
-
return { refused: `"${key}" is not a usable slug` };
|
|
26
|
-
const hd = harnessDir(root);
|
|
27
|
-
const tpl = hd && join(hd, 'templates', 'knowledge.md');
|
|
28
|
-
if (!tpl || !existsSync(tpl))
|
|
29
|
-
return { refused: 'no knowledge template — run reins install' };
|
|
30
|
-
const dest = join(root, PROPOSALS, `${slug}.md`);
|
|
31
|
-
if (existsSync(dest))
|
|
32
|
-
return { refused: `${PROPOSALS}/${slug}.md already exists` };
|
|
33
|
-
const hist = resolve(root, '.loctx', 'history');
|
|
34
|
-
const from = [];
|
|
35
|
-
for (const f of o.from ?? []) {
|
|
36
|
-
const abs = resolve(root, f.includes('/') ? f : join('.loctx', 'history', f));
|
|
37
|
-
const rel = relative(hist, abs);
|
|
38
|
-
if (rel.startsWith('..') || /[\\/]/.test(rel) || !existsSync(abs))
|
|
39
|
-
return { refused: `--from ${f}: not a page under .loctx/history/` };
|
|
40
|
-
const text = readFileSync(abs, 'utf8');
|
|
41
|
-
const lines = [...text.matchAll(/^(?:decisions|reasons):\s*(.+)$/gm)].flatMap((m) => m[1].split(',').map((x) => x.trim()));
|
|
42
|
-
const has = key.startsWith('stop:') ? text.includes(slug) : lines.includes(slug);
|
|
43
|
-
if (!has)
|
|
44
|
-
return { refused: `--from ${f}: does not contain "${slug}"` };
|
|
45
|
-
from.push(`.loctx/history/${rel}`);
|
|
46
|
-
}
|
|
47
|
-
if (from.length === 0)
|
|
48
|
-
from.push(...collectRetro(root)
|
|
49
|
-
.keys.filter((k) => bareKey(k.key) === slug)
|
|
50
|
-
.flatMap((k) => k.pages));
|
|
51
|
-
if (from.length === 0)
|
|
52
|
-
return { refused: `no record of "${slug}"; pass --from <history>…` };
|
|
53
|
-
const asSymptom = /^(stop|reason):/.test(key);
|
|
54
|
-
let t = readFileSync(tpl, 'utf8');
|
|
55
|
-
t = setLine(t, 'id', `${today()}_${slug}`);
|
|
56
|
-
t = setLine(t, 'decisions', asSymptom ? '[]' : `[${slug}]`);
|
|
57
|
-
t = setLine(t, 'symptoms', asSymptom ? `[${slug}]` : '[]');
|
|
58
|
-
t = setLine(t, 'source', JSON.stringify([...new Set(from)].join(', ')));
|
|
59
|
-
t = setLine(t, 'approved', null);
|
|
60
|
-
mkdirSync(join(root, PROPOSALS), { recursive: true });
|
|
61
|
-
writeFileSync(dest, t);
|
|
62
|
-
return { path: `${PROPOSALS}/${slug}.md` };
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* `reins knowledge accept <slug>`: the only way an `approved` field gets written. The skill calls
|
|
66
|
-
* it after the user's answer; the CLI cannot tell who ran it (design §8).
|
|
67
|
-
*/
|
|
68
|
-
export function acceptKnowledge(name, o = {}) {
|
|
69
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
70
|
-
const base = basename(name, '.md');
|
|
71
|
-
const slug = base.replace(/^\d{4}-\d{2}-\d{2}_/, '');
|
|
72
|
-
const draft = join(root, PROPOSALS, `${base}.md`);
|
|
73
|
-
if (!existsSync(draft))
|
|
74
|
-
return { refused: `no draft ${PROPOSALS}/${base}.md` };
|
|
75
|
-
const at = today();
|
|
76
|
-
let t = readFileSync(draft, 'utf8');
|
|
77
|
-
t = setLine(t, 'id', `${at}_${slug}`);
|
|
78
|
-
t = setLine(t, 'approved', null);
|
|
79
|
-
t = t.replace(/^(source:.*)$/m, (m) => `${m}\napproved: { by: user, at: ${at} }`);
|
|
80
|
-
const hd = harnessDir(root);
|
|
81
|
-
const v = hd ? loadSchemas(hd).get('knowledge') : undefined;
|
|
82
|
-
if (!v)
|
|
83
|
-
return { refused: 'no knowledge schema — run reins install' };
|
|
84
|
-
const issues = validateFile(v, draft, false, t);
|
|
85
|
-
if (issues.length)
|
|
86
|
-
return { refused: `draft is invalid: ${issues.map((i) => i.message).join('; ')}` };
|
|
87
|
-
const rel = `.agents/knowledge/${at}_${slug}.md`;
|
|
88
|
-
if (existsSync(join(root, rel)))
|
|
89
|
-
return { refused: `${rel} already exists` };
|
|
90
|
-
mkdirSync(join(root, '.agents', 'knowledge'), { recursive: true });
|
|
91
|
-
writeFileSync(join(root, rel), t);
|
|
92
|
-
rmSync(draft);
|
|
93
|
-
return { path: rel };
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* `reins knowledge dismiss <key> --reason <text>`: the pm judged a current candidate not to be a
|
|
97
|
-
* lesson. retro and status stop counting it until it shows up in more units than it had then.
|
|
98
|
-
*/
|
|
99
|
-
export function dismissKnowledge(key, o = {}) {
|
|
100
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
101
|
-
const reason = o.reason?.trim();
|
|
102
|
-
if (!reason)
|
|
103
|
-
return { refused: '--reason is required: say why it is not a lesson' };
|
|
104
|
-
const c = collectRetro(root).candidates.find((k) => k.key === key);
|
|
105
|
-
if (!c)
|
|
106
|
-
return { refused: `"${key}" is not a current candidate (reins retro lists them)` };
|
|
107
|
-
mkdirSync(join(root, PROPOSALS), { recursive: true });
|
|
108
|
-
const line = { key, units: c.units.length, at: today(), reason };
|
|
109
|
-
appendFileSync(join(root, DISMISSED), `${JSON.stringify(line)}\n`);
|
|
110
|
-
return { path: DISMISSED };
|
|
111
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { repoRoot } from '../lib/git.js';
|
|
4
|
-
import { harnessDir, readYaml } from '../lib/harness.js';
|
|
5
|
-
import { appendMetric, classify, METRICS_FILE, readMetrics, summarize, } from '../lib/metrics.js';
|
|
6
|
-
const TICKET = /^\d{3}-\d+$/;
|
|
7
|
-
const INTENT = /^\d{3}$/;
|
|
8
|
-
/**
|
|
9
|
-
* `reins metrics record` (S-3): one `usage` line for a role run. Anything doubtful is refused
|
|
10
|
-
* and nothing is written — a wrong number in the file is worse than a missing one.
|
|
11
|
-
*/
|
|
12
|
-
export function recordUsage(o) {
|
|
13
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
14
|
-
if (!o.role)
|
|
15
|
-
return { refused: '--role <role> is required' };
|
|
16
|
-
if (o.tokens === undefined)
|
|
17
|
-
return { refused: '--tokens <n> is required' };
|
|
18
|
-
if (!/^\d+$/.test(o.tokens.trim()))
|
|
19
|
-
return { refused: `--tokens must be a whole number ≥ 0 (got "${o.tokens}")` };
|
|
20
|
-
const tokens = Number(o.tokens.trim());
|
|
21
|
-
if (!Number.isSafeInteger(tokens))
|
|
22
|
-
return { refused: `--tokens is too large (got "${o.tokens}")` };
|
|
23
|
-
if (o.ticket !== undefined && !TICKET.test(o.ticket))
|
|
24
|
-
return { refused: `--ticket must look like 002-1 (got "${o.ticket}")` };
|
|
25
|
-
if (o.intent !== undefined && !INTENT.test(o.intent))
|
|
26
|
-
return { refused: `--intent must be three digits like 002 (got "${o.intent}")` };
|
|
27
|
-
if (o.ticket && o.intent && o.ticket.slice(0, 3) !== o.intent)
|
|
28
|
-
return {
|
|
29
|
-
refused: `--ticket ${o.ticket} belongs to intent ${o.ticket.slice(0, 3)}, not ${o.intent}`,
|
|
30
|
-
};
|
|
31
|
-
const dir = harnessDir(root);
|
|
32
|
-
const file = dir && join(dir, 'bindings.yaml');
|
|
33
|
-
if (!file || !existsSync(file))
|
|
34
|
-
return { refused: 'no bindings.yaml — run reins install' };
|
|
35
|
-
const roles = readYaml(file).roles ?? {};
|
|
36
|
-
const bound = Object.hasOwn(roles, o.role) ? roles[o.role] : undefined;
|
|
37
|
-
if (!bound)
|
|
38
|
-
return { refused: `unknown role "${o.role}" (roles: ${Object.keys(roles).join(', ')})` };
|
|
39
|
-
const vendor = o.vendor ?? bound.vendor;
|
|
40
|
-
const model = o.model ?? bound.model;
|
|
41
|
-
if (!vendor || !model)
|
|
42
|
-
return {
|
|
43
|
-
refused: `bindings.yaml has no vendor/model for ${o.role}; pass --vendor and --model`,
|
|
44
|
-
};
|
|
45
|
-
if (!existsSync(join(root, '.loctx')))
|
|
46
|
-
return { refused: 'no .loctx/ here — nothing recorded' };
|
|
47
|
-
const record = {
|
|
48
|
-
kind: 'usage',
|
|
49
|
-
role: o.role,
|
|
50
|
-
vendor,
|
|
51
|
-
model,
|
|
52
|
-
tokens,
|
|
53
|
-
...(o.ticket ? { ticket: o.ticket } : {}),
|
|
54
|
-
...(!o.ticket && o.intent ? { intent: o.intent } : {}),
|
|
55
|
-
...(o.note ? { note: o.note } : {}),
|
|
56
|
-
};
|
|
57
|
-
if (!appendMetric(root, record))
|
|
58
|
-
return { refused: `could not write ${METRICS_FILE}` };
|
|
59
|
-
return { record };
|
|
60
|
-
}
|
|
61
|
-
/** `reins metrics` (S-4): read-only. */
|
|
62
|
-
export function collectMetrics(o = {}) {
|
|
63
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
64
|
-
const present = existsSync(join(root, METRICS_FILE));
|
|
65
|
-
const { records, broken } = readMetrics(root);
|
|
66
|
-
return { present, intent: o.intent ?? null, ...summarize(records, { intent: o.intent, broken }) };
|
|
67
|
-
}
|
|
68
|
-
const n = (x) => x.toLocaleString('en-US');
|
|
69
|
-
export function formatMetrics(m) {
|
|
70
|
-
if (!m.present)
|
|
71
|
-
return 'no metrics yet\n';
|
|
72
|
-
const out = [];
|
|
73
|
-
out.push(`reins metrics${m.intent ? ` — intent ${m.intent}` : ''}`);
|
|
74
|
-
out.push(`records: check ${m.counts.check} · gate ${m.counts.gate} · usage ${m.counts.usage} · broken ${m.broken}`);
|
|
75
|
-
out.push(`tokens: ${n(m.tokens.total)}`);
|
|
76
|
-
const group = (title, g) => {
|
|
77
|
-
out.push(` ${title}`);
|
|
78
|
-
const rows = Object.entries(g);
|
|
79
|
-
if (!rows.length)
|
|
80
|
-
out.push(' —');
|
|
81
|
-
for (const [k, v] of rows)
|
|
82
|
-
out.push(` ${k.padEnd(14)} ${n(v).padStart(12)}`);
|
|
83
|
-
};
|
|
84
|
-
group('by role', m.tokens.byRole);
|
|
85
|
-
group('by vendor', m.tokens.byVendor);
|
|
86
|
-
out.push('tickets');
|
|
87
|
-
if (!m.tickets.length)
|
|
88
|
-
out.push(' —');
|
|
89
|
-
for (const t of m.tickets)
|
|
90
|
-
out.push(` ${t.ticket.padEnd(8)} tokens ${n(t.tokens).padStart(10)} · checks ${String(t.checks).padStart(3)} · knowledge stops ${t.knowledgeStops}`);
|
|
91
|
-
out.push('intents');
|
|
92
|
-
if (!m.intents.length)
|
|
93
|
-
out.push(' —');
|
|
94
|
-
for (const i of m.intents)
|
|
95
|
-
out.push(` ${i.intent.padEnd(8)} tokens ${n(i.tokens).padStart(10)} · checks ${String(i.checks).padStart(3)} · stops intent ${i.stops.intent} / knowledge ${i.stops.knowledge} / redline ${i.stops.redline} · tickets ${i.tickets} · knowledge stops per ticket ${i.knowledgeStopsPerTicket ?? '—'}`);
|
|
96
|
-
return `${out.join('\n')}\n`;
|
|
97
|
-
}
|
|
98
|
-
const uniq = (xs) => [...new Set(xs)];
|
|
99
|
-
/** The `check` line for a finished run; never throws, never changes the run's result. */
|
|
100
|
-
export function logCheck(r, o) {
|
|
101
|
-
try {
|
|
102
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
103
|
-
const reasons = uniq(r.findings.filter((f) => f.verdict !== 'WARN').map((f) => f.reason));
|
|
104
|
-
const warns = uniq(r.findings.filter((f) => f.verdict === 'WARN').map((f) => f.reason));
|
|
105
|
-
appendMetric(root, {
|
|
106
|
-
kind: 'check',
|
|
107
|
-
stage: r.stage,
|
|
108
|
-
...(o.ticket ? { ticket: o.ticket } : {}),
|
|
109
|
-
verdict: r.verdict,
|
|
110
|
-
reasons,
|
|
111
|
-
warns,
|
|
112
|
-
stops: classify(reasons, harnessDir(root)),
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// metrics never change what check reports
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/** One `gate` line per gate that actually ran (skipped and refused runs write nothing). */
|
|
120
|
-
export function logGates(runs, o) {
|
|
121
|
-
try {
|
|
122
|
-
const root = repoRoot(o.cwd ?? process.cwd());
|
|
123
|
-
for (const g of runs) {
|
|
124
|
-
if (g.exit === null)
|
|
125
|
-
continue;
|
|
126
|
-
appendMetric(root, {
|
|
127
|
-
kind: 'gate',
|
|
128
|
-
...(o.ticket ? { ticket: o.ticket } : {}),
|
|
129
|
-
gate: g.gate,
|
|
130
|
-
exit: g.exit,
|
|
131
|
-
report: g.report,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
// metrics never change what gate reports
|
|
137
|
-
}
|
|
138
|
-
}
|
package/cli/dist/commands/new.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { basename, dirname, join } from 'node:path';
|
|
3
|
-
import { harnessDir } from '../lib/harness.js';
|
|
4
|
-
import { loadSchemas, validateFile } from '../lib/schema.js';
|
|
5
|
-
import { intentDir, intentFile, intentIds, openTickets } from '../lib/work.js';
|
|
6
|
-
const fail = (m) => ({ code: 1, stdout: '', stderr: `reins new: ${m}\n` });
|
|
7
|
-
const pad = (n, w) => String(n).padStart(w, '0');
|
|
8
|
-
const ls = (d) => (existsSync(d) ? readdirSync(d).toSorted() : []);
|
|
9
|
-
// ---- numbering (pure) -------------------------------------------------------------------------
|
|
10
|
-
/** Next intent id: the highest number in `.agents/intent/` plus one, three digits. */
|
|
11
|
-
export function nextIntentId(existing) {
|
|
12
|
-
return pad(Math.max(0, ...existing.map(Number)) + 1, 3);
|
|
13
|
-
}
|
|
14
|
-
/** Next ticket number of an intent: the highest among open tickets, history records and the plan's ids, plus one. */
|
|
15
|
-
export function nextTicketNumber(intent, ...sources) {
|
|
16
|
-
const re = new RegExp(`^${intent}-(\\d+)$`);
|
|
17
|
-
const ns = sources.flat().map((s) => Number(re.exec(s)?.[1] ?? 0));
|
|
18
|
-
return Math.max(0, ...ns) + 1;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Number of a new ticket: the first id the plan's `tickets:` reserves that no open ticket or history
|
|
22
|
-
* page uses yet, so plan and files agree; once every reserved id is taken, the next free number.
|
|
23
|
-
*/
|
|
24
|
-
export function ticketNumber(intent, planned, used) {
|
|
25
|
-
const re = new RegExp(`^${intent}-(\\d+)$`);
|
|
26
|
-
const free = planned.find((id) => re.test(id) && !used.includes(id));
|
|
27
|
-
return free ? Number(re.exec(free)[1]) : nextTicketNumber(intent, used, planned);
|
|
28
|
-
}
|
|
29
|
-
/** Next two-digit bus number of a ticket, from the file names already in `.loctx/bus/`. */
|
|
30
|
-
export function nextBusNumber(ticket, files) {
|
|
31
|
-
const ns = files.map((f) => {
|
|
32
|
-
const m = /^(.+)_(\d+)\.(request|response)\.yaml$/.exec(f);
|
|
33
|
-
return m && m[1] === ticket ? Number(m[2]) : 0;
|
|
34
|
-
});
|
|
35
|
-
return pad(Math.max(0, ...ns) + 1, 2);
|
|
36
|
-
}
|
|
37
|
-
/** Ticket ids that history pages record, from their file names and first heading (`# 009-2 — …`). */
|
|
38
|
-
function historyTicketIds(root, intent) {
|
|
39
|
-
const dir = join(root, '.loctx', 'history');
|
|
40
|
-
const re = new RegExp(`(?<![0-9])(${intent}-\\d+)(?![0-9])`, 'g');
|
|
41
|
-
const out = [];
|
|
42
|
-
for (const f of ls(dir).filter((e) => e.endsWith('.md'))) {
|
|
43
|
-
const head = readFileSync(join(dir, f), 'utf8')
|
|
44
|
-
.split(/\r?\n/)
|
|
45
|
-
.find((l) => l.startsWith('# ')) ?? '';
|
|
46
|
-
for (const m of `${f}\n${head}`.matchAll(re))
|
|
47
|
-
out.push(m[1]);
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
50
|
-
}
|
|
51
|
-
/** How many numbered items the plan's order of work lists, or null when it cannot be read. */
|
|
52
|
-
export function planStepCount(body) {
|
|
53
|
-
const m = /^##\s+(?:작업 순서|order of work)[^\n]*\n([\s\S]*?)(?=^## |(?![\s\S]))/im.exec(body);
|
|
54
|
-
if (!m)
|
|
55
|
-
return null;
|
|
56
|
-
const n = (m[1].match(/^\d+\.\s/gm) ?? []).length;
|
|
57
|
-
return n || null;
|
|
58
|
-
}
|
|
59
|
-
// ---- writing ----------------------------------------------------------------------------------
|
|
60
|
-
/** Replaces top-level `key: value` lines of the frontmatter; the body stays as the template has it. */
|
|
61
|
-
function fill(text, values) {
|
|
62
|
-
const m = /^(---\n)([\s\S]*?\n)(---\n[\s\S]*)$/.exec(text);
|
|
63
|
-
const [head, mid, tail] = m ? [m[1], m[2], m[3]] : ['', text, ''];
|
|
64
|
-
const lines = mid.split('\n').map((l) => {
|
|
65
|
-
const k = /^([A-Za-z_]+):/.exec(l)?.[1];
|
|
66
|
-
return k && k in values ? `${k}: ${values[k]}` : l;
|
|
67
|
-
});
|
|
68
|
-
return `${head}${lines.join('\n')}${tail}`;
|
|
69
|
-
}
|
|
70
|
-
const q = (s) => JSON.stringify(s);
|
|
71
|
-
function emit(root, rel, content, schemaName, whole) {
|
|
72
|
-
const hd = harnessDir(root);
|
|
73
|
-
const v = hd ? loadSchemas(hd).get(schemaName) : undefined;
|
|
74
|
-
if (!v)
|
|
75
|
-
return fail(`no ${schemaName} schema in the harness`);
|
|
76
|
-
const issues = validateFile(v, rel, whole, content);
|
|
77
|
-
if (issues.length)
|
|
78
|
-
return fail(`output would not pass ${schemaName}: ${issues.map((i) => i.message).join('; ')}`);
|
|
79
|
-
const abs = join(root, rel);
|
|
80
|
-
if (existsSync(abs))
|
|
81
|
-
return fail(`${rel} already exists; not overwritten`);
|
|
82
|
-
mkdirSync(dirname(abs), { recursive: true });
|
|
83
|
-
writeFileSync(abs, content, { flag: 'wx' });
|
|
84
|
-
return { code: 0, stdout: `${rel}\n`, stderr: '' };
|
|
85
|
-
}
|
|
86
|
-
function template(root, rel) {
|
|
87
|
-
const hd = harnessDir(root);
|
|
88
|
-
const p = hd && join(hd, 'templates', rel);
|
|
89
|
-
return p && existsSync(p) ? readFileSync(p, 'utf8') : null;
|
|
90
|
-
}
|
|
91
|
-
const SLUG = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
92
|
-
export function newIntent(root, slug, o = {}) {
|
|
93
|
-
if (!SLUG.test(slug))
|
|
94
|
-
return fail(`slug must be kebab-case (got "${slug}")`);
|
|
95
|
-
const t = template(root, 'intent.md');
|
|
96
|
-
if (!t)
|
|
97
|
-
return fail('no intent template in the harness');
|
|
98
|
-
const id = nextIntentId(intentIds(root));
|
|
99
|
-
const vals = { id: q(id), slug, status: 'draft', approvals: '[]' };
|
|
100
|
-
if (o.version)
|
|
101
|
-
vals['version'] = q(o.version);
|
|
102
|
-
if (o.origin)
|
|
103
|
-
vals['origin'] = o.origin;
|
|
104
|
-
return emit(root, `.agents/intent/${id}_${slug}/intent.md`, fill(t, vals), 'intent', false);
|
|
105
|
-
}
|
|
106
|
-
export function newTicket(root, intent, step, slug, o = {}) {
|
|
107
|
-
if (!/^\d{3}$/.test(intent))
|
|
108
|
-
return fail(`intent must be three digits (got "${intent}")`);
|
|
109
|
-
if (!/^[1-9]\d*$/.test(step))
|
|
110
|
-
return fail(`step must be a positive integer (got "${step}")`);
|
|
111
|
-
if (!SLUG.test(slug))
|
|
112
|
-
return fail(`slug must be kebab-case (got "${slug}")`);
|
|
113
|
-
const idir = intentDir(root, intent);
|
|
114
|
-
if (!idir)
|
|
115
|
-
return fail(`no intent ${intent} in .agents/intent/`);
|
|
116
|
-
const plan = intentFile(root, intent, 'plan');
|
|
117
|
-
if (!plan)
|
|
118
|
-
return fail(`intent ${intent} has no plan.md; write the plan before its tickets`);
|
|
119
|
-
const max = planStepCount(plan.body);
|
|
120
|
-
if (max === null)
|
|
121
|
-
return fail(`plan.md of intent ${intent} has no readable order of work`);
|
|
122
|
-
if (Number(step) > max)
|
|
123
|
-
return fail(`step ${step} is outside the plan's order of work (1..${max})`);
|
|
124
|
-
const t = template(root, 'ticket.md');
|
|
125
|
-
if (!t)
|
|
126
|
-
return fail('no ticket template in the harness');
|
|
127
|
-
const planned = Array.isArray(plan?.data['tickets'])
|
|
128
|
-
? plan.data['tickets'].map(String)
|
|
129
|
-
: [];
|
|
130
|
-
const open = openTickets(root).map((f) => String(f.data['id'] ?? ''));
|
|
131
|
-
const n = ticketNumber(intent, planned, [...open, ...historyTicketIds(root, intent)]);
|
|
132
|
-
const iSlug = basename(idir).replace(/^\d{3}_/, '');
|
|
133
|
-
const branch = typeof plan.data['branch'] === 'string' ? plan.data['branch'] : `feat/${intent}-${iSlug}`;
|
|
134
|
-
const depends = (o.depends ?? '')
|
|
135
|
-
.split(',')
|
|
136
|
-
.map((s) => s.trim())
|
|
137
|
-
.filter(Boolean);
|
|
138
|
-
const vals = {
|
|
139
|
-
id: `${intent}-${n}`,
|
|
140
|
-
intent: q(intent),
|
|
141
|
-
plan_step: step,
|
|
142
|
-
depends: `[${depends.join(', ')}]`,
|
|
143
|
-
branch,
|
|
144
|
-
};
|
|
145
|
-
if (o.title)
|
|
146
|
-
vals['title'] = q(o.title);
|
|
147
|
-
if (o.release)
|
|
148
|
-
vals['release'] = o.release;
|
|
149
|
-
if (o.role)
|
|
150
|
-
vals['role'] = o.role;
|
|
151
|
-
return emit(root, `.loctx/ticket/${intent}-${n}_${slug}.md`, fill(t, vals), 'ticket', false);
|
|
152
|
-
}
|
|
153
|
-
const KIND_ROUTE = {
|
|
154
|
-
implement: { from: 'pl', to: 'implementer' },
|
|
155
|
-
verify: { from: 'pl', to: 'verify-tool' },
|
|
156
|
-
review: { from: 'pl', to: 'code-review' },
|
|
157
|
-
};
|
|
158
|
-
export function newRequest(root, ticket, kind, o = {}) {
|
|
159
|
-
if (!/^\d{3}-\d+$/.test(ticket))
|
|
160
|
-
return fail(`ticket must look like 011-1 (got "${ticket}")`);
|
|
161
|
-
const fixed = KIND_ROUTE[kind];
|
|
162
|
-
if (!fixed && kind !== 'question' && kind !== 'stop-report')
|
|
163
|
-
return fail(`kind must be implement, verify, review, question or stop-report (got "${kind}")`);
|
|
164
|
-
const from = o.from ?? fixed?.from;
|
|
165
|
-
if (!from)
|
|
166
|
-
return fail(`${kind} needs --from`);
|
|
167
|
-
const to = o.to ?? fixed?.to ?? 'pl';
|
|
168
|
-
const hd = harnessDir(root);
|
|
169
|
-
const roles = new Set(ls(hd ? join(hd, 'roles') : '').map((f) => f.replace(/\.md$/, '')));
|
|
170
|
-
for (const [flag, r] of [
|
|
171
|
-
['--from', from],
|
|
172
|
-
['--to', to],
|
|
173
|
-
])
|
|
174
|
-
if (!roles.has(r))
|
|
175
|
-
return fail(`${flag} "${r}" is not a harness role (${[...roles].join(', ')})`);
|
|
176
|
-
const t = template(root, 'bus/request.yaml');
|
|
177
|
-
if (!t)
|
|
178
|
-
return fail('no bus request template in the harness');
|
|
179
|
-
const nn = nextBusNumber(ticket, ls(join(root, '.loctx', 'bus')));
|
|
180
|
-
const id = `${ticket}_${nn}`;
|
|
181
|
-
const vals = {
|
|
182
|
-
id,
|
|
183
|
-
from,
|
|
184
|
-
to,
|
|
185
|
-
ticket,
|
|
186
|
-
intent: q(ticket.slice(0, 3)),
|
|
187
|
-
kind,
|
|
188
|
-
};
|
|
189
|
-
return emit(root, `.loctx/bus/${id}.request.yaml`, fill(t, vals), 'bus-request', true);
|
|
190
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { repoRoot } from '../lib/git.js';
|
|
2
|
-
import { collectRetro, formatRetro } from '../lib/retro.js';
|
|
3
|
-
/** `reins retro [--release <v>] [--json]` (design §8): counts only; the summary sentences are the pm's. */
|
|
4
|
-
export function runRetro(o = {}) {
|
|
5
|
-
return collectRetro(repoRoot(o.cwd ?? process.cwd()), { release: o.release });
|
|
6
|
-
}
|
|
7
|
-
export { formatRetro };
|