@futurelastic/colab-handbook 1.18.0-rc.5 → 1.18.0-rc.7

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 CHANGED
@@ -317,11 +317,27 @@ linked, so an existing machine changes nothing. Finding none, it installs for
317
317
  Claude Code and says so. The per-runtime facts live in [`engines/`](engines/),
318
318
  one file each — that folder is the source for the table above.
319
319
 
320
+ **Sessions that run in a private home** never see a user-level folder. For
321
+ those, copy the skills into the repo itself:
322
+
323
+ ```sh
324
+ ./install.sh --repo ~/code/app --engine opencode # → ~/code/app/.opencode/skills
325
+ ```
326
+
327
+ Every skill is copied as plain files (a linked folder or file is
328
+ dereferenced, never linked), with a manifest of what was copied. The command
329
+ prints each file it wrote, so you can commit them. A re-run refreshes the
330
+ copies the repo has not edited and leaves edited ones alone. `--check` reports
331
+ the copy and its version, and marks it ✗ behind once a skill changes in the
332
+ clone. Only agent runtimes whose `engines/` file names a `project_skills_dir`
333
+ have this route; today that is opencode.
334
+
320
335
  | Flag | What it does |
321
336
  |---|---|
322
337
  | *(none)* | Symlink `skills/` into each chosen agent runtime's user-level folder, so they are available in every repo you open. Asks at a terminal; otherwise keeps what is linked (see [*Choose your agent runtime*](#choose-your-agent-runtime)). |
323
338
  | `--engine <id>[,<id>]` | Install for these agent runtimes (`claude`, `codex`, `opencode` — the files in `engines/`), no question asked. |
324
339
  | `--skills-dir <path>` | Also install into this folder, for an agent `engines/` does not know. |
340
+ | `--repo <path> --engine <id>` | Instead of a user-level install, **copy** the skills into that repo's project skills folder, for sessions that run in a private home. Prints the files to commit. |
325
341
  | `--tools` | The `colab` CLI twice: a **symlink** at `~/.local/bin/colab` for your sessions (it prints the `PATH` line if needed), and a stamped **frozen copy** at `~/.colab/bin/colab` for always-on services. Also creates an empty `~/.colab/state.json` if there is none. |
326
342
  | `--hooks` | Point this clone's git at `.githooks/`: a gitleaks secret scan and an identity scan whose vocabulary you keep outside every repo (see [`templates/README.md`](templates/README.md)). |
327
343
  | `--fleet` | Seed `~/.colab/repos.txt` with format notes only, if absent. It stays machine-local because it names your private repos; `colab register` fills it. |
package/README.vi.md CHANGED
@@ -316,11 +316,26 @@ sẵn, nên máy đã cài không thay đổi gì. Không thấy agent runtime n
316
316
  Code và nói rõ điều đó. Thông tin từng agent runtime nằm trong [`engines/`](engines/),
317
317
  mỗi agent runtime một file — thư mục đó là nguồn của bảng trên.
318
318
 
319
+ **Phiên chạy trong một home riêng** không bao giờ thấy thư mục cấp user. Với
320
+ những phiên đó, hãy chép skill vào chính repo:
321
+
322
+ ```sh
323
+ ./install.sh --repo ~/code/app --engine opencode # → ~/code/app/.opencode/skills
324
+ ```
325
+
326
+ Mỗi skill được chép thành file thường (thư mục hay file là link thì được chép
327
+ nội dung, không bao giờ để link), kèm một manifest ghi những gì đã chép. Lệnh in
328
+ ra từng file nó đã ghi để bạn commit. Chạy lại thì làm mới các bản chép mà repo
329
+ chưa sửa, và để nguyên bản đã sửa. `--check` báo bản chép cùng phiên bản của nó,
330
+ và đánh ✗ (đã cũ) khi một skill trong clone thay đổi. Chỉ agent runtime nào có
331
+ file `engines/` khai `project_skills_dir` mới có đường này; hiện nay là opencode.
332
+
319
333
  | Flag | Làm gì |
320
334
  |---|---|
321
335
  | *(không có)* | Symlink `skills/` vào thư mục cấp user của từng agent runtime đã chọn, để mở repo nào cũng có. Ở terminal thì hỏi; không thì giữ những gì đã link (xem [*Chọn agent runtime*](#chọn-agent-runtime)). |
322
336
  | `--engine <id>[,<id>]` | Cài cho các agent runtime này (`claude`, `codex`, `opencode` — các file trong `engines/`), không hỏi. |
323
337
  | `--skills-dir <path>` | Cài thêm vào thư mục này, cho agent mà `engines/` chưa biết. |
338
+ | `--repo <path> --engine <id>` | Thay cho cài cấp user: **chép** skill vào thư mục skill của project trong repo đó, cho phiên chạy trong một home riêng. In ra các file cần commit. |
324
339
  | `--tools` | CLI `colab` cài hai lần: một **symlink** ở `~/.local/bin/colab` cho các phiên làm việc của bạn (in sẵn dòng `PATH` nếu cần), và một **bản đóng băng** có đóng dấu ở `~/.colab/bin/colab` cho các service luôn-bật. Đồng thời tạo `~/.colab/state.json` rỗng nếu chưa có. |
325
340
  | `--hooks` | Trỏ git của clone này vào `.githooks/`: quét secret bằng gitleaks, và quét danh tính với danh sách từ khoá do bạn giữ NGOÀI mọi repo (xem [`templates/README.md`](templates/README.md)). |
326
341
  | `--fleet` | Tạo `~/.colab/repos.txt` chỉ chứa ghi chú định dạng, nếu chưa có. Nó cố tình nằm trên máy vì nó ghi tên các repo private của bạn; `colab register` mới là thứ điền vào. |
package/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.18.0-rc.5"
36
+ "version": "1.18.0-rc.7"
37
37
  }
package/tools/colab CHANGED
@@ -1483,7 +1483,11 @@ function measureCandidateConditions(repoAbs, { sha, lastFinal, at, readRuns, iss
1483
1483
  // #441: every migration file since the last final, destructive or not — an operator-granted
1484
1484
  // automatic final refuses an ungranted one (release-finalize.js migrationGrantVerdict).
1485
1485
  const migrations = changes === null ? null : changes.filter((c) => releaseCut.isMigrationPath(c.path, declared)).map((c) => c.path);
1486
- return { ci, suite, schema, switches, issues, migrations };
1486
+ // #671: could a migration have been seen at all? A declared prefix is a layout; otherwise the
1487
+ // default-layout reading above (null = unread, never "absent"). The grant gate fails closed
1488
+ // without one, so its empty list never reads "nothing read" as "nothing changed".
1489
+ const migrationLayout = declared.length ? true : layout;
1490
+ return { ci, suite, schema, switches, issues, migrations, migrationLayout };
1487
1491
  }
1488
1492
 
1489
1493
  /**
@@ -1621,7 +1625,7 @@ function finalTags(repoAbs, onlyTags = null) {
1621
1625
  * since the newest final. The version is computed here only to find that tracking issue; decide()
1622
1626
  * computes it again from the same inputs, so the two cannot disagree.
1623
1627
  */
1624
- function measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, auto, migrationPaths: paths, remoteTags = null }) {
1628
+ function measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, auto, migrationPaths: paths, migrationLayout = null, remoteTags = null }) {
1625
1629
  const grantDecl = policy.effective.finalGrant;
1626
1630
  const trust = trustAt(repoAbs, `${remote}/main`);
1627
1631
  const finalGrant = isGhUsable(repoAbs)
@@ -1641,7 +1645,7 @@ function measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, au
1641
1645
  : { ok: false, reason: 'no tracking issue yet to carry a grant' };
1642
1646
  if (grant && grant.ok) grant = { ...grant, issue: tracking.number };
1643
1647
  }
1644
- const migrations = { ...releaseFinalize.migrationGrantVerdict({ paths, grant, since: lastFinal }), paths: paths || null };
1648
+ const migrations = { ...releaseFinalize.migrationGrantVerdict({ paths, grant, since: lastFinal, layout: migrationLayout }), paths: paths || null };
1645
1649
  const spacing = releaseCut.spacingVerdict({ finals: finalTags(repoAbs, remoteTags), spacingHours: policy.effective.finalSpacingHours, now: new Date().toISOString() });
1646
1650
  return { finalGrant, holds, migrations, spacing, tracking };
1647
1651
  }
@@ -1734,7 +1738,7 @@ function cmdReleaseCut(argv) {
1734
1738
  const tags = lines(git.git(['tag', '--list'], repoAbs)).filter(onRemote);
1735
1739
  const tagsAtSha = lines(git.git(['tag', '--points-at', sha], repoAbs)).filter(onRemote);
1736
1740
 
1737
- const { ci, suite, schema, switches, issues, migrations: migrationPathsSince } = measureCandidateConditions(repoAbs, {
1741
+ const { ci, suite, schema, switches, issues, migrations: migrationPathsSince, migrationLayout } = measureCandidateConditions(repoAbs, {
1738
1742
  sha, lastFinal, at, readRuns: () => releaseCut.withoutOwnWorkflow(git.ghRunsForCommit(repoAbs, 'main', sha)), // #425
1739
1743
  verifying: verifyingPolicy(repoAbs), // #624: the ship gate's rule for which runs may veto
1740
1744
  });
@@ -1750,7 +1754,7 @@ function cmdReleaseCut(argv) {
1750
1754
  // #446: route deploy-tag-fast — the grant, the human veto, the migration gate and the spacing are
1751
1755
  // measured only there, so every candidate route's run is what it was.
1752
1756
  const fast = releaseCut.isFastRoute(policy) && !policy.findings.length;
1753
- const fastFacts = fast ? measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, auto, migrationPaths: migrationPathsSince, remoteTags }) : {};
1757
+ const fastFacts = fast ? measureFastRoute(repoAbs, { policy, remote, issues, lastFinal, tags, auto, migrationPaths: migrationPathsSince, migrationLayout, remoteTags }) : {};
1754
1758
  if (fast && auto) auto.spacing = fastFacts.spacing;
1755
1759
  // #590: route library-fast — a final with nothing deployed. The release-hold veto is its one extra
1756
1760
  // read; a hand cut also needs MIGRATION.md for a manifest-declared major (--auto reads it already).
@@ -2237,7 +2241,7 @@ function cmdReleaseFinalize(argv) {
2237
2241
  const mg = tracking && tracking.number
2238
2242
  ? migrationGrant.evaluateIssue(rec, cand.version, tracking.number, labels.MIGRATION_GRANT_LABEL, { trust })
2239
2243
  : { ok: false, reason: 'no tracking issue yet to carry a grant' };
2240
- migrations = releaseFinalize.migrationGrantVerdict({ paths: conditions.migrations, grant: mg, since: releaseTag.latestReleaseTag(repoAbs, { ref: cand.sha, onlyTags: remoteTags }) });
2244
+ migrations = releaseFinalize.migrationGrantVerdict({ paths: conditions.migrations, grant: mg, since: releaseTag.latestReleaseTag(repoAbs, { ref: cand.sha, onlyTags: remoteTags }), layout: conditions.migrationLayout });
2241
2245
  }
2242
2246
  const verdict = releaseFinalize.decide({
2243
2247
  policy, selection: sel, tracking, supersededHeld, period, trunk, regressions,
@@ -10,6 +10,7 @@
10
10
 
11
11
  const fs = require('fs');
12
12
  const path = require('path');
13
+ const crypto = require('crypto');
13
14
 
14
15
  const REPEATABLE = new Set(['note', 'caveat']);
15
16
 
@@ -49,4 +50,55 @@ function rememberedDirs(colabHome) {
49
50
  return text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith('#'));
50
51
  }
51
52
 
52
- module.exports = { parseConf, expandHome, listEngines, rememberedDirs };
53
+ /**
54
+ * Per-repo copies (#664): `install.sh --repo <path> --engine <id>` copies the skills into the agent
55
+ * runtime's PROJECT skills folder (`project_skills_dir:`), for a runtime whose sessions run in a
56
+ * private home and never see a user-level install. Each copy is remembered in
57
+ * <COLAB_HOME>/skills-copies as one `<engine id>|<repo path>` line, so `--check` finds it.
58
+ */
59
+ function rememberedCopies(colabHome) {
60
+ let text = '';
61
+ try { text = fs.readFileSync(path.join(colabHome, 'skills-copies'), 'utf8'); } catch (_) { return []; }
62
+ return text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith('#') && l.includes('|'))
63
+ .map((l) => { const i = l.indexOf('|'); return { engine: l.slice(0, i), repo: l.slice(i + 1) }; });
64
+ }
65
+
66
+ /** The manifest install.sh writes beside the copies: what it copied, at which version, with what content. */
67
+ const COPY_MANIFEST = '.colab-handbook-skills';
68
+
69
+ /**
70
+ * A skill folder's content digest — the same algorithm as install.sh's tree_digest, and
71
+ * install-sh.test.js holds the two to it: sha256 over one `<sha256 of file> <relative path>\n`
72
+ * line per regular file, links followed, paths sorted bytewise (LC_ALL=C sort). Null when absent.
73
+ */
74
+ function treeDigest(dir) {
75
+ const files = [];
76
+ const walk = (rel) => {
77
+ for (const n of fs.readdirSync(path.join(dir, rel))) {
78
+ const r = rel ? `${rel}/${n}` : n;
79
+ const st = fs.statSync(path.join(dir, r)); // stat, not lstat: links are followed, as cp -RL does
80
+ if (st.isDirectory()) walk(r);
81
+ else if (st.isFile()) files.push(r);
82
+ }
83
+ };
84
+ try { if (!fs.statSync(dir).isDirectory()) return null; walk(''); } catch (_) { return null; }
85
+ files.sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
86
+ const sha = (buf) => crypto.createHash('sha256').update(buf).digest('hex');
87
+ return sha(files.map((f) => `${sha(fs.readFileSync(path.join(dir, f)))} ${f}\n`).join(''));
88
+ }
89
+
90
+ /** Parse a COPY_MANIFEST: its stamp version, engine, and `{ <skill>: <digest> }`. Null when absent. */
91
+ function readCopyManifest(dir) {
92
+ let text;
93
+ try { text = fs.readFileSync(path.join(dir, COPY_MANIFEST), 'utf8'); } catch (_) { return null; }
94
+ const out = { version: null, engine: null, skills: {} };
95
+ for (const l of text.split(/\r?\n/)) {
96
+ let m;
97
+ if ((m = /^#\s*colab-handbook:\s*skills\s*@\s*(\S+)/.exec(l))) out.version = m[1];
98
+ else if ((m = /^#\s*engine:\s*(\S+)/.exec(l))) out.engine = m[1];
99
+ else if ((m = /^([0-9a-f]{64}) (.+)$/.exec(l))) out.skills[m[2]] = m[1];
100
+ }
101
+ return out;
102
+ }
103
+
104
+ module.exports = { parseConf, expandHome, listEngines, rememberedDirs, rememberedCopies, COPY_MANIFEST, treeDigest, readCopyManifest };
@@ -157,7 +157,9 @@ function checkFrozen({ root, colabHome }) {
157
157
  function checkSkills({ root, home, colabHome }) {
158
158
  const src = path.join(root, 'skills');
159
159
  let skills = [];
160
- try { skills = fs.readdirSync(src, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort(); } catch (_) { /* none */ }
160
+ // stat, not the Dirent: a skill folder that is itself a link is a skill too, as install.sh's `*/` glob says (#664).
161
+ const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch (_) { return false; } };
162
+ try { skills = fs.readdirSync(src).filter((n) => isDir(path.join(src, n))).sort(); } catch (_) { /* none */ }
161
163
  const all = engines.listEngines(root);
162
164
  const byId = Object.fromEntries(all.map((e) => [e.id, e]));
163
165
  const targets = all.filter((e) => e.skills_dir).map((e) => ({ e, dir: engines.expandHome(e.skills_dir, home) }));
@@ -203,11 +205,68 @@ function checkSkills({ root, home, colabHome }) {
203
205
  for (const c of e.caveat || []) rows.push({ area: 'skills', severity: WARN, text: `${e.id}: ${c}` });
204
206
  if (e.verified && /^no\b/.test(e.verified)) rows.push({ area: 'skills', severity: WARN, text: `${e.id}: engine file not verified by a run yet — ${e.verified.replace(/^no\s*[—-]?\s*/, '')}` });
205
207
  }
206
- if (!rows.length) {
208
+ const copies = checkCopies({ root, colabHome, skills, byId });
209
+ if (!rows.length && !copies.length) {
207
210
  rows.push({ area: 'skills', severity: WARN, text: `not linked for any engine — ./install.sh asks which (or --engine <id> / --skills-dir <path>)` });
208
- } else if (notInstalled.length) {
211
+ } else if (rows.length && notInstalled.length) {
209
212
  rows.push({ area: 'skills', severity: OK, text: `not installed for: ${notInstalled.join(', ')} — fine if deliberate; ./install.sh --engine <id> adds one` });
210
213
  }
214
+ // An engine installed both ways states its caveats once.
215
+ const seen = new Set();
216
+ return [...rows, ...copies].filter((r) => (seen.has(r.text) ? false : (seen.add(r.text), true)));
217
+ }
218
+
219
+ /**
220
+ * Per-repo copies (#664), every one remembered in <COLAB_HOME>/skills-copies: the same row as a
221
+ * user-level install, plus the version the copy was stamped with. Per skill, three digests decide —
222
+ * the manifest's (what install.sh wrote), the copy's now, and this clone's skill now:
223
+ * copy ≠ manifest → edited in the repo (⚠: the repo owns its copy; a re-run leaves it alone)
224
+ * clone ≠ manifest = copy → behind (✗: installed, and the handbook has moved on — re-run)
225
+ * in the clone, not copied → missing (⚠, a skill added since — re-run), as for a link
226
+ * copied, gone from clone → behind too (✗, removed upstream — a re-run deletes it)
227
+ */
228
+ function checkCopies({ root, colabHome, skills, byId }) {
229
+ const src = path.join(root, 'skills');
230
+ const rows = [];
231
+ for (const { engine, repo } of engines.rememberedCopies(colabHome)) {
232
+ const e = byId[engine] || { id: engine, caveat: [] };
233
+ const rel = e.project_skills_dir;
234
+ const rerun = `./install.sh --repo '${repo}' --engine ${engine}`;
235
+ if (!rel) {
236
+ rows.push({ area: 'skills', severity: WARN, text: `${engine} copy in ${repo}: engines/${engine}.conf names no project_skills_dir any more — remove the line from ${path.join(colabHome, 'skills-copies')} if the copy is gone` });
237
+ continue;
238
+ }
239
+ const dir = path.join(repo, rel);
240
+ const man = engines.readCopyManifest(dir);
241
+ if (!man) {
242
+ rows.push({ area: 'skills', severity: WARN, text: `${engine} (${e.label || engine}) ${dir}: no ${engines.COPY_MANIFEST} — the copy is gone, or was not written by install.sh. Re-copy: ${rerun}, or drop the line from ${path.join(colabHome, 'skills-copies')}` });
243
+ continue;
244
+ }
245
+ const current = []; const behind = []; const edited = []; const missing = []; const removed = [];
246
+ for (const name of skills) {
247
+ const want = man.skills[name];
248
+ if (!want) { missing.push(name); continue; }
249
+ const now = engines.treeDigest(path.join(dir, name));
250
+ if (now !== want) { edited.push(name); continue; }
251
+ if (engines.treeDigest(path.join(src, name)) !== want) behind.push(name);
252
+ else current.push(name);
253
+ }
254
+ for (const name of Object.keys(man.skills)) {
255
+ if (skills.includes(name)) continue;
256
+ if (engines.treeDigest(path.join(dir, name)) === man.skills[name]) removed.push(name);
257
+ }
258
+ const parts = [`${current.length}/${skills.length} current`];
259
+ if (behind.length) parts.push(`BEHIND the handbook: ${behind.join(', ')} — re-run ${rerun}, then commit`);
260
+ if (removed.length) parts.push(`copies of skills the handbook no longer has: ${removed.join(', ')} — re-run ${rerun} to remove them`);
261
+ if (missing.length) parts.push(`missing ${missing.join(', ')} — re-run ${rerun}`);
262
+ if (edited.length) parts.push(`edited in the repo (left as is; a re-run will not refresh them): ${edited.join(', ')}`);
263
+ rows.push({
264
+ area: 'skills',
265
+ severity: (behind.length || removed.length) ? FAIL : (missing.length || edited.length) ? WARN : OK,
266
+ text: `${engine} (${e.label || engine}) ${dir} — copy @ ${man.version || 'unknown'}: ${parts.join('; ')}`,
267
+ });
268
+ for (const c of e.caveat || []) rows.push({ area: 'skills', severity: WARN, text: `${e.id}: ${c}` });
269
+ }
211
270
  return rows;
212
271
  }
213
272
 
@@ -352,5 +411,5 @@ if (require.main === module) {
352
411
 
353
412
  module.exports = {
354
413
  OK, WARN, FAIL,
355
- dispatchedCommands, checkSkills, checkLink, checkFrozen, checkState, checkFleet, checkHooks, checkNotify, runChecks, render,
414
+ dispatchedCommands, checkSkills, checkCopies, checkLink, checkFrozen, checkState, checkFleet, checkHooks, checkNotify, runChecks, render,
356
415
  };
@@ -560,11 +560,23 @@ function regressionVerdict(edges, { periodStart }) {
560
560
  * human gate. `paths` is every migration file changed since the last final (null = unread);
561
561
  * `grant` is migration-grant.js evaluateIssue() of the version's TRACKING issue, bound to the
562
562
  * version (`colab migration-grant <tracking> --branch vX.Y.Z`), or null when there was nothing to
563
- * evaluate. Returns { ok, detail }.
563
+ * evaluate. `layout` (#671) says whether a migration could have been seen at the candidate at all:
564
+ * true = a `migrations:` prefix is declared or a default layout (Laravel database/migrations/,
565
+ * Prisma prisma/migrations/) exists in the tree; false = neither, so an empty `paths` is "nothing
566
+ * read", not "nothing changed"; null/absent = the tree could not be read. An empty `paths` passes
567
+ * only with a layout. Returns { ok, detail } (+ unread: true when something could not be read).
564
568
  */
565
- function migrationGrantVerdict({ paths, grant, since }) {
569
+ function migrationGrantVerdict({ paths, grant, since, layout }) {
566
570
  if (paths === null || paths === undefined) return { ok: false, unread: true, detail: 'the migration files since the last final could not be read — an unread migration is not an absent one' };
567
- if (!paths.length) return { ok: true, detail: `no migration file changed since ${since || 'the first commit'}` };
571
+ if (!paths.length) {
572
+ // #671: fail closed where nothing could have been seen — an automatically deployed final never
573
+ // reads "nothing read" as "nothing changed". The way out is named in the detail, never implied —
574
+ // route-neutral: release finalize prints its own human command, and route deploy-tag-fast has none.
575
+ const wayOut = 'declare the migration directory as `migrations:` in .github/project.yml (project.schema.md `migrations`); until then the final is a human act, not the grant\'s — and a repo with no database has no layout to declare, so its final stays one';
576
+ if (layout === false) return { ok: false, detail: `no migration was read since ${since || 'the first commit'}: no \`migrations:\` declared and no Laravel database/migrations/ or Prisma prisma/migrations/ directory at the candidate, so a migration elsewhere would be invisible — ${wayOut}` };
577
+ if (layout !== true) return { ok: false, unread: true, detail: `the tree at the candidate could not be read for a migration layout, so an empty migration list since ${since || 'the first commit'} is not evidence that none changed — ${wayOut}` };
578
+ return { ok: true, detail: `no migration file changed since ${since || 'the first commit'}` };
579
+ }
568
580
  const list = paths.join(', ');
569
581
  if (grant && grant.ok) return { ok: true, detail: `${paths.length} migration file(s) since ${since || 'the first commit'} (${list}), granted on the tracking issue #${grant.issue}` };
570
582
  return {