@bluenyang/reins 0.1.5-rc.1 → 0.1.5

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.
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parse } from 'yaml';
4
4
  import { defaultsAsker } from '../lib/ask.js';
5
+ import { migrateDetected } from '../lib/bindings.js';
5
6
  import { overrides } from '../lib/blocks.js';
6
7
  import { repoRoot } from '../lib/git.js';
7
8
  import { harnessVersion, packageHarness, packageVersion } from '../lib/upstream.js';
@@ -58,6 +59,9 @@ export async function runUpdate(o) {
58
59
  const agents = join(root, 'AGENTS.md');
59
60
  if (existsSync(agents))
60
61
  res.overrides = [...overrides(readFileSync(agents, 'utf8'))];
62
+ const moved = migrateDetected(root, o.dryRun);
63
+ if (moved.length > 0)
64
+ res.bindingsMoved = moved;
61
65
  res.install = await runInstall({
62
66
  tier: pin.tier,
63
67
  mode: pin.mode,
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { parse, stringify } from 'yaml';
3
+ import { isMap, isScalar, parse, parseDocument, stringify } from 'yaml';
4
4
  import { Ajv2020 } from 'ajv/dist/2020.js';
5
5
  import { vendorOf, vendors } from './detect.js';
6
6
  import { packageHarness } from './upstream.js';
@@ -25,6 +25,10 @@ function localValid(doc) {
25
25
  }
26
26
  /** Tolerant: a missing file reads as empty; an invalid one is ignored with a warning, never a crash. */
27
27
  export function readLocal(root) {
28
+ return loadLocal(root) ?? { schema: 'reins/bindings-local@1', vendors: {}, roles: {} };
29
+ }
30
+ /** The local file, empty when absent; `null` (after a warning) when it exists but cannot be used. */
31
+ function loadLocal(root) {
28
32
  const out = { schema: 'reins/bindings-local@1', vendors: {}, roles: {} };
29
33
  const path = join(root, LOCAL_BINDINGS);
30
34
  if (!existsSync(path))
@@ -35,12 +39,12 @@ export function readLocal(root) {
35
39
  }
36
40
  catch (e) {
37
41
  process.stderr.write(`warning: ${LOCAL_BINDINGS} cannot be read (${e.message}) — ignored\n`);
38
- return out;
42
+ return null;
39
43
  }
40
44
  const bad = isObj(doc) ? localValid(doc) : 'not a mapping';
41
45
  if (bad !== null || !isObj(doc)) {
42
46
  process.stderr.write(`warning: ${LOCAL_BINDINGS} is invalid (${bad}) — ignored\n`);
43
- return out;
47
+ return null;
44
48
  }
45
49
  if (isObj(doc['vendors']))
46
50
  for (const [k, v] of Object.entries(doc['vendors']))
@@ -165,3 +169,75 @@ export function resolveBindings(root, detect = vendors) {
165
169
  out.push(role === 'pm' ? pmRes : one(role, pm));
166
170
  return out;
167
171
  }
172
+ const DETECT_KEYS = ['detected', 'at', 'detected_at', 'detectedAt', 'checked_at', 'checkedAt'];
173
+ /**
174
+ * 0.1.4 kept `vendors.<v>.detected` (and a timestamp) in the committed bindings.yaml. Moves them to the
175
+ * local file (a vendor the local file already has is kept as is) and removes just those keys from the
176
+ * committed one through the Document API, so comments, order and every other key stay as written.
177
+ * Returns the vendors moved; nothing is written when `dryRun`.
178
+ */
179
+ export function migrateDetected(root, dryRun = false) {
180
+ const path = join(root, '.agents/harness/bindings.yaml');
181
+ if (!existsSync(path))
182
+ return [];
183
+ const doc = parseDocument(readFileSync(path, 'utf8'));
184
+ if (doc.errors.length > 0)
185
+ return [];
186
+ const vs = doc.get('vendors', true);
187
+ if (!isMap(vs))
188
+ return [];
189
+ const found = {};
190
+ const touched = [];
191
+ for (const pair of vs.items) {
192
+ const name = isScalar(pair.key) ? String(pair.key.value) : undefined;
193
+ if (name === undefined || !isMap(pair.value))
194
+ continue;
195
+ const m = pair.value;
196
+ const keys = m.items.filter((i) => isScalar(i.key) && DETECT_KEYS.includes(String(i.key.value)));
197
+ if (keys.length === 0)
198
+ continue;
199
+ const val = (k) => {
200
+ const v = m.get(k);
201
+ return v;
202
+ };
203
+ const det = val('detected');
204
+ const at = ['at', 'detected_at', 'detectedAt', 'checked_at', 'checkedAt']
205
+ .map(val)
206
+ .find((x) => typeof x === 'string' || x instanceof Date);
207
+ if (typeof det !== 'boolean')
208
+ continue; // only a well-formed record is migrated
209
+ found[name] = {
210
+ detected: det,
211
+ ...(at === undefined ? {} : { at: at instanceof Date ? at.toISOString() : String(at) }),
212
+ };
213
+ touched.push(name);
214
+ }
215
+ if (touched.length === 0)
216
+ return [];
217
+ if (dryRun)
218
+ return touched;
219
+ const local = loadLocal(root);
220
+ if (local === null)
221
+ return []; // never overwrite a local file we cannot read
222
+ let add = false;
223
+ for (const [k, v] of Object.entries(found))
224
+ if (!local.vendors[k]) {
225
+ local.vendors[k] = v;
226
+ add = true;
227
+ }
228
+ if (add)
229
+ writeLocal(root, local);
230
+ for (const name of touched) {
231
+ const m = vs.get(name, true);
232
+ if (!isMap(m))
233
+ continue;
234
+ for (const k of DETECT_KEYS)
235
+ m.delete(k);
236
+ if (m.items.length === 0)
237
+ vs.delete(name);
238
+ }
239
+ if (vs.items.length === 0)
240
+ doc.delete('vendors');
241
+ writeFileSync(path, doc.toString());
242
+ return touched;
243
+ }
package/cli/dist/reins.js CHANGED
@@ -17,6 +17,12 @@ import { defaultsAsker, stdinAsker } from './lib/ask.js';
17
17
  import { EXIT } from './lib/verdict.js';
18
18
  // the version npm installed — cli/dist/reins.js sits two levels below package.json
19
19
  const VERSION = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
20
+ // every command: a reader that went away (`| head`) ends the run quietly with the exit code already set
21
+ process.stdout.on('error', (e) => {
22
+ if (e.code === 'EPIPE')
23
+ process.exit(process.exitCode ?? 0);
24
+ throw e;
25
+ });
20
26
  const program = new Command()
21
27
  .name('reins')
22
28
  .description('agent harness — install, migrate, update; check keeps agents inside their roles')
@@ -136,6 +142,8 @@ program
136
142
  process.stdout.write(`reins update — cli ${r.cliFrom === 'none' ? 'none' : `v${r.cliFrom}`} → v${r.cliTo}, harness v${r.from} → v${r.to}${o.dryRun ? ' (dry run)' : ''}\n`);
137
143
  for (const c of r.changes)
138
144
  process.stdout.write(` · ${c}\n`);
145
+ if (r.bindingsMoved)
146
+ process.stdout.write(`bindings: ${o.dryRun ? 'would move' : 'moved'} detected vendors (${r.bindingsMoved.join(', ')}) to .loctx/bindings.local.yaml\n`);
139
147
  if (a && a.created.length + a.changed.length + a.removed.length === 0)
140
148
  process.stdout.write('already up to date\n');
141
149
  else if (a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluenyang/reins",
3
- "version": "0.1.5-rc.1",
3
+ "version": "0.1.5",
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": {
@@ -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.5-rc.1 …`
9
+ the answers only the user can give and report what happened. Run the CLI as `npx @bluenyang/reins@0.1.5 …`
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}`.