@bluenyang/reins 0.1.3-rc.1 → 0.1.3-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.
@@ -1,9 +1,9 @@
1
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
2
2
  import { basename, join, relative, resolve } from 'node:path';
3
3
  import { repoRoot } from '../lib/git.js';
4
4
  import { harnessDir } from '../lib/harness.js';
5
5
  import { localIso } from '../lib/metrics.js';
6
- import { bareKey, collectRetro } from '../lib/retro.js';
6
+ import { bareKey, collectRetro, DISMISSED } from '../lib/retro.js';
7
7
  import { loadSchemas, validateFile } from '../lib/schema.js';
8
8
  export const PROPOSALS = '.loctx/knowledge-proposals';
9
9
  const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
@@ -92,3 +92,20 @@ export function acceptKnowledge(name, o = {}) {
92
92
  rmSync(draft);
93
93
  return { path: rel };
94
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
+ }
@@ -17,6 +17,15 @@ export function nextTicketNumber(intent, ...sources) {
17
17
  const ns = sources.flat().map((s) => Number(re.exec(s)?.[1] ?? 0));
18
18
  return Math.max(0, ...ns) + 1;
19
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
+ }
20
29
  /** Next two-digit bus number of a ticket, from the file names already in `.loctx/bus/`. */
21
30
  export function nextBusNumber(ticket, files) {
22
31
  const ns = files.map((f) => {
@@ -119,7 +128,7 @@ export function newTicket(root, intent, step, slug, o = {}) {
119
128
  ? plan.data['tickets'].map(String)
120
129
  : [];
121
130
  const open = openTickets(root).map((f) => String(f.data['id'] ?? ''));
122
- const n = nextTicketNumber(intent, open, historyTicketIds(root, intent), planned);
131
+ const n = ticketNumber(intent, planned, [...open, ...historyTicketIds(root, intent)]);
123
132
  const iSlug = idir
124
133
  .split('/')
125
134
  .pop()
@@ -3,6 +3,26 @@ import { join } from 'node:path';
3
3
  import { intentIds, historyPages, intentFile } from './work.js';
4
4
  import { readMetrics, summarize } from './metrics.js';
5
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('\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
+ }
6
26
  /** `stop:F2` → `F2`; a bare slug stays as it is. */
7
27
  export const bareKey = (k) => k.replace(/^(stop|reason|decision):/, '');
8
28
  /** `reasons:` lines of history pages: `reasons: a, b` (design §4, optional line after `decisions:`). */
@@ -107,7 +127,11 @@ export function collectRetro(root, opts = {}) {
107
127
  }))
108
128
  .toSorted((a, b) => b.units.length - a.units.length || a.key.localeCompare(b.key));
109
129
  const done = promotedSlugs(root);
110
- const candidates = keys.filter((k) => k.units.length >= 2 && !done.has(bareKey(k.key)));
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);
111
135
  return {
112
136
  release,
113
137
  stops: Object.fromEntries(Object.entries(stops).toSorted(([a], [b]) => a.localeCompare(b))),
@@ -115,6 +139,7 @@ export function collectRetro(root, opts = {}) {
115
139
  tokens: summarize(records).tokens,
116
140
  keys,
117
141
  candidates,
142
+ dismissed,
118
143
  };
119
144
  }
120
145
  /** The number `reins status` shows; the same count as `retro` over the whole record. */
@@ -142,8 +167,9 @@ export function formatRetro(r) {
142
167
  out.push(' —');
143
168
  for (const k of rows) {
144
169
  const cand = r.candidates.some((c) => c.key === k.key);
170
+ const dism = r.dismissed.some((c) => c.key === k.key);
145
171
  const shown = k.units.slice(0, 4).join(', ') + (k.units.length > 4 ? `, +${k.units.length - 4}` : '');
146
- out.push(` ${k.key} ×${k.units.length} (${shown})${cand ? '' : ' — promoted'}`);
172
+ out.push(` ${k.key} ×${k.units.length} (${shown})${cand ? '' : dism ? ' — dismissed' : ' — promoted'}`);
147
173
  }
148
174
  }
149
175
  out.push(`knowledge candidates: ${r.candidates.length}`);
package/cli/dist/reins.js CHANGED
@@ -4,7 +4,7 @@ import { Command } from 'commander';
4
4
  import { runCheck, STAGES } from './commands/check.js';
5
5
  import { runInstall } from './commands/install.js';
6
6
  import { runMigrate } from './commands/migrate.js';
7
- import { acceptKnowledge, proposeKnowledge } from './commands/knowledge.js';
7
+ import { acceptKnowledge, dismissKnowledge, proposeKnowledge } from './commands/knowledge.js';
8
8
  import { formatRetro, runRetro } from './commands/retro.js';
9
9
  import { runStatus } from './commands/status.js';
10
10
  import { runUpdate } from './commands/update.js';
@@ -315,6 +315,12 @@ knowledge
315
315
  .description('after the user approves: write .agents/knowledge/<date>_<slug>.md with approved')
316
316
  .argument('<draft>', 'the draft slug')
317
317
  .action((draft) => knowledgeDone('accept', acceptKnowledge(draft)));
318
+ knowledge
319
+ .command('dismiss')
320
+ .description('record that a candidate is not a lesson; it returns when it repeats further')
321
+ .argument('<key>', 'a candidate key as reins retro prints it')
322
+ .requiredOption('--reason <text>', 'why it is not a lesson')
323
+ .action((key, o) => knowledgeDone('dismiss', dismissKnowledge(key, o)));
318
324
  for (const n of ['recall', 'doctor'])
319
325
  program.command(n).allowUnknownOption().allowExcessArguments().action(notYet(n));
320
326
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluenyang/reins",
3
- "version": "0.1.3-rc.1",
3
+ "version": "0.1.3-rc.2",
4
4
  "description": "Installs, migrates and updates an agent harness (harness → loop → graph) that keeps coding agents inside their permitted roles.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,7 +10,7 @@ pm role. Run the CLI as `npx @bluenyang/reins@<v>` where `<v>` is `version` in `
10
10
  1. **Check first.** `reins status`. HOLD or STOP → follow it.
11
11
  2. **Aggregate.** `reins retro --release <v>` after an rc (or with no flag, any time). It counts repeats across units (a ticket counts once): stop ids, review reasons, decisions, failed rounds (HOLD/STOP), tokens by role, and promotion candidates (a key seen in 2+ units not yet in active knowledge). `--json` for machine reading.
12
12
  3. **Summarise for the user in their language**: stops, review findings, failed rounds, tokens, and the candidate list. Short; no raw dump.
13
- 4. **Propose.** For each candidate: `reins knowledge propose <key> --from <history pages>`. A key seen once but named by the user is proposed the same way, with its evidence in `--from`. This writes drafts to `.loctx/knowledge-proposals/` and records no approval. Show every draft to the user.
13
+ 4. **Propose.** For each candidate: `reins knowledge propose <key> --from <history pages>`. A key seen once but named by the user is proposed the same way, with its evidence in `--from`. This writes drafts to `.loctx/knowledge-proposals/` and records no approval. Show every draft to the user. A candidate you judge not to be a lesson: `reins knowledge dismiss <key> --reason <why>`, and tell the user; it comes back if it repeats in more units.
14
14
  5. **Approval gate.** Only after the user explicitly approves a draft, run `reins knowledge accept <draft>`, and commit the new `.agents/knowledge/` file with the trailer `Approved-by: user`. Declined or silent drafts are not accepted; never accept on your own, and no agent message counts as approval. An entry without `approved` stops the verifier.
15
15
  6. **Carry forward.** A generic lesson (not specific to one ticket) also becomes one line in `docs/ROADMAP.md` as a next-intent candidate.
16
16
  7. **Record.** Write a history page in `.loctx/history/` with a `decisions:` line (accepted keys) and a `reasons:` line (why declined or deferred).
@@ -6,7 +6,7 @@ description: Install reins in this repository, or move an existing harness onto
6
6
  # reins-setup
7
7
 
8
8
  You act as the **pm** role (`.agents/harness/roles/pm.md` once installed). The CLI does the work; you collect
9
- the answers only the user can give and report what happened. Run the CLI as `npx @bluenyang/reins@0.1.3-rc.1 …`
9
+ the answers only the user can give and report what happened. Run the CLI as `npx @bluenyang/reins@0.1.3-rc.2 …`
10
10
  (the version is pinned to this skill's release; inside the reins repository itself: `node cli/dist/reins.js …`).
11
11
 
12
12
  Defaults from the plugin settings: language `${user_config.language}`, install mode `${user_config.default_mode}`.