@caddis/cli 0.4.96 → 0.4.98

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 (55) hide show
  1. package/README.md +2 -0
  2. package/bundles/antigravity-plugin/plugin.json +1 -1
  3. package/bundles/antigravity-plugin/repo_hygiene.py +134 -20
  4. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_exit.cpython-311.pyc +0 -0
  5. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_file_lock.cpython-311.pyc +0 -0
  6. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_frontmatter.cpython-311.pyc +0 -0
  7. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_redact.cpython-311.pyc +0 -0
  8. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_roadmap.cpython-311.pyc +0 -0
  9. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_rows.cpython-311.pyc +0 -0
  10. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_status.cpython-311.pyc +0 -0
  11. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_tidy.cpython-311.pyc +0 -0
  12. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_todo.cpython-311.pyc +0 -0
  13. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_workstreams.cpython-311.pyc +0 -0
  14. package/bundles/antigravity-plugin/scripts/__pycache__/caddis_worktree_safety.cpython-311.pyc +0 -0
  15. package/bundles/antigravity-plugin/scripts/caddis_fleet.py +31 -21
  16. package/bundles/antigravity-plugin/scripts/caddis_gate.py +18 -1
  17. package/bundles/antigravity-plugin/scripts/caddis_guide.json +2 -2
  18. package/bundles/antigravity-plugin/scripts/caddis_handoff.py +235 -0
  19. package/bundles/antigravity-plugin/scripts/caddis_hub_collect.py +67 -15
  20. package/bundles/antigravity-plugin/scripts/caddis_lanes.py +154 -130
  21. package/bundles/antigravity-plugin/scripts/caddis_review.py +12 -0
  22. package/bundles/antigravity-plugin/scripts/caddis_tidy.py +152 -51
  23. package/bundles/antigravity-plugin/scripts/caddis_todo.py +314 -18
  24. package/bundles/antigravity-plugin/scripts/schemas/hub-collect.schema.json +117 -1
  25. package/bundles/antigravity-plugin/scripts/schemas/hub-plans.schema.json +117 -1
  26. package/bundles/antigravity-plugin/scripts/setup_project_ai.py +60 -2
  27. package/bundles/antigravity-plugin/scripts/templates/coordinator.md +3 -3
  28. package/bundles/antigravity-plugin/skills/coordinate/SKILL.md +4 -1
  29. package/bundles/antigravity-plugin/skills/cross-review/SKILL.md +6 -0
  30. package/bundles/antigravity-plugin/skills/handoff/SKILL.md +101 -23
  31. package/bundles/antigravity-plugin/skills/implement/SKILL.md +6 -0
  32. package/bundles/antigravity-plugin/skills/park/SKILL.md +7 -2
  33. package/bundles/antigravity-plugin/skills/pr-merge/SKILL.md +1 -0
  34. package/bundles/antigravity-plugin/skills/ship-pr/SKILL.md +1 -0
  35. package/bundles/manifest.json +2 -2
  36. package/dist/cli.js +276 -76
  37. package/dist/export/assets/export-B3cUoxL1.js +150 -0
  38. package/dist/export/assets/export-DQss44R1.css +1 -0
  39. package/dist/export/index.html +2 -2
  40. package/dist/ui/assets/Activity-CvEIJlnE.js +6 -0
  41. package/dist/ui/assets/{Guide-Czn5sK0f.js → Guide-BxS9L55s.js} +1 -1
  42. package/dist/ui/assets/Guide-DTd261-c.css +1 -0
  43. package/dist/ui/assets/RoadmapTab-CqlWs7dJ.js +31 -0
  44. package/dist/ui/assets/index-9pdDzLVp.css +1 -0
  45. package/dist/ui/assets/index-DSxeWPax.js +231 -0
  46. package/dist/ui/index.html +2 -2
  47. package/package.json +1 -1
  48. package/dist/export/assets/export-CMtV-slT.css +0 -1
  49. package/dist/export/assets/export-DtlDFN4L.js +0 -150
  50. package/dist/ui/assets/Activity-BDjet2xd.js +0 -6
  51. package/dist/ui/assets/Guide-D-Zy4cUT.css +0 -1
  52. package/dist/ui/assets/RoadmapTab-Bd8geyQx.js +0 -31
  53. package/dist/ui/assets/index-Bd0Z4jR8.css +0 -1
  54. package/dist/ui/assets/index-CmngQ8Mk.js +0 -231
  55. package/dist/ui/assets/time-D00tu2ZP.js +0 -1
package/dist/cli.js CHANGED
@@ -7014,7 +7014,7 @@ var init_agents = __esm({
7014
7014
  });
7015
7015
 
7016
7016
  // src/hub/sources/collector.ts
7017
- import { existsSync as existsSync8 } from "fs";
7017
+ import { existsSync as existsSync8, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "fs";
7018
7018
  import os5 from "os";
7019
7019
  import path17 from "path";
7020
7020
  function defaultScriptPath() {
@@ -7055,10 +7055,21 @@ function createCollectorSource(opts) {
7055
7055
  let lastRunOk = false;
7056
7056
  let running = null;
7057
7057
  let knownUnsupported = false;
7058
+ let prsFileUnsupported = false;
7059
+ let doneKnownUnsupported = false;
7058
7060
  const fail2 = (message3) => {
7059
7061
  lastError = message3;
7060
7062
  lastRunOk = false;
7061
7063
  };
7064
+ const withDone = (entry, old) => {
7065
+ const plans = entry.plans;
7066
+ const done = plans?.done;
7067
+ if (!plans || !done || typeof done !== "object" || done.unchanged !== true) return entry;
7068
+ const oldDone = old?.error === void 0 ? old?.plans?.done : void 0;
7069
+ const reuse = oldDone && typeof done.tree === "string" && oldDone.tree === done.tree && Array.isArray(oldDone.plans);
7070
+ if (reuse) return { ...entry, plans: { ...plans, done: oldDone } };
7071
+ return { ...entry, fingerprint: void 0, plans: { ...plans, done: { error: "done plans not cached" } } };
7072
+ };
7062
7073
  const ingest = (parsed, wanted) => {
7063
7074
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return fail2("collector output is not a JSON object");
7064
7075
  const out = parsed;
@@ -7084,7 +7095,7 @@ function createCollectorSource(opts) {
7084
7095
  if (!old || old.error !== void 0) cache2.set(entry.path, entry);
7085
7096
  continue;
7086
7097
  }
7087
- if (!old || old.error !== void 0 || old.fingerprint !== entry.fingerprint) cache2.set(entry.path, entry);
7098
+ if (!old || old.error !== void 0 || old.fingerprint !== entry.fingerprint) cache2.set(entry.path, withDone(entry, old));
7088
7099
  }
7089
7100
  const keepOrError = (next, old) => {
7090
7101
  if (!next || typeof next !== "object") return old;
@@ -7110,12 +7121,46 @@ function createCollectorSource(opts) {
7110
7121
  }
7111
7122
  const script = opts.scriptPath ?? defaultScriptPath();
7112
7123
  const known = [...cache2.values()].filter((r2) => !knownUnsupported && r2.error === void 0 && typeof r2.fingerprint === "string" && repos.includes(r2.path)).map((r2) => `${r2.path}=${r2.fingerprint}`);
7113
- const args = repos.length ? known.length ? [...pre, script, "--repos", ...repos, "--known", ...known, "--json"] : [...pre, script, "--repos", ...repos, "--json"] : [...pre, script, "--repos", path17.join(os5.tmpdir(), "caddis-hub-no-repos"), "--only", "spend,guide", "--json"];
7114
- let result = await spawn2(cmd, args, { timeoutMs: RUN_TIMEOUT_MS2 });
7115
- if (!result.ok && result.code === 2 && known.length && repos.length && /unrecognized arguments:.*--known/.test(result.stderr)) {
7116
- knownUnsupported = true;
7117
- log("caddis hub: the collector script does not know --known (old plugin); sending full runs. Update the plugin.");
7118
- result = await spawn2(cmd, [...pre, script, "--repos", ...repos, "--json"], { timeoutMs: RUN_TIMEOUT_MS2 });
7124
+ const doneKnown = [...cache2.values()].filter((r2) => !knownUnsupported && !doneKnownUnsupported && r2.error === void 0 && repos.includes(r2.path)).flatMap((r2) => {
7125
+ const tree = r2.plans?.done?.tree;
7126
+ return typeof tree === "string" && tree ? [`${r2.path}=${tree}`] : [];
7127
+ });
7128
+ let prsFlag = [];
7129
+ if (opts.prs && opts.prsFile && repos.length > 0 && !prsFileUnsupported) {
7130
+ try {
7131
+ mkdirSync7(path17.dirname(opts.prsFile), { recursive: true });
7132
+ writeFileSync5(opts.prsFile, JSON.stringify({ schema: 1, repos: opts.prs() }));
7133
+ prsFlag = ["--prs-file", opts.prsFile];
7134
+ } catch {
7135
+ }
7136
+ }
7137
+ const build = () => repos.length ? [
7138
+ ...pre,
7139
+ script,
7140
+ "--repos",
7141
+ ...repos,
7142
+ ...known.length ? ["--known", ...known] : [],
7143
+ ...doneKnown.length ? ["--done-known", ...doneKnown] : [],
7144
+ ...prsFlag,
7145
+ "--json"
7146
+ ] : [...pre, script, "--repos", path17.join(os5.tmpdir(), "caddis-hub-no-repos"), "--only", "spend,guide", "--json"];
7147
+ let result = await spawn2(cmd, build(), { timeoutMs: RUN_TIMEOUT_MS2 });
7148
+ for (let attempt = 0; attempt < 3 && !result.ok; attempt += 1) {
7149
+ if (prsFlag.length && /unrecognized arguments:.*--prs-file/.test(result.stderr)) {
7150
+ prsFileUnsupported = true;
7151
+ prsFlag = [];
7152
+ log("caddis hub: the collector script does not know --prs-file (old plugin); branch progress is off. Update the plugin.");
7153
+ } else if (result.code === 2 && known.length && repos.length && /unrecognized arguments:.*--known/.test(result.stderr)) {
7154
+ knownUnsupported = true;
7155
+ known.length = 0;
7156
+ doneKnown.length = 0;
7157
+ log("caddis hub: the collector script does not know --known (old plugin); sending full runs. Update the plugin.");
7158
+ } else if (result.code === 2 && doneKnown.length && /unrecognized arguments:.*--done-known/.test(result.stderr)) {
7159
+ doneKnownUnsupported = true;
7160
+ doneKnown.length = 0;
7161
+ log("caddis hub: the collector script does not know --done-known (old plugin); done plans are sent in full. Update the plugin.");
7162
+ } else break;
7163
+ result = await spawn2(cmd, build(), { timeoutMs: RUN_TIMEOUT_MS2 });
7119
7164
  }
7120
7165
  if (result.timedOut) return fail2(`collector timed out after ${RUN_TIMEOUT_MS2 / 1e3} s`);
7121
7166
  if (!result.ok) {
@@ -7271,6 +7316,24 @@ function accessError(owner, tried) {
7271
7316
  if (!tried.length) return `no gh account is logged in: run gh auth login -h github.com, then ${set}`;
7272
7317
  return `no access with account ${tried.join(", ")}: run gh auth login -h github.com, or ${set}`;
7273
7318
  }
7319
+ function prHeads(data) {
7320
+ if (!data) return {};
7321
+ const out = {};
7322
+ for (const slot of data.repos) {
7323
+ if (slot.reason === "no github remote") {
7324
+ out[slot.path] = [];
7325
+ } else if (Array.isArray(slot.prs)) {
7326
+ out[slot.path] = slot.prs.filter((pr) => Boolean(pr.head_ref)).map((pr) => ({
7327
+ number: pr.number,
7328
+ head_ref: pr.head_ref ?? "",
7329
+ draft: pr.draft,
7330
+ fork: pr.fork ?? true,
7331
+ updated_at: pr.updated_at ?? ""
7332
+ }));
7333
+ }
7334
+ }
7335
+ return out;
7336
+ }
7274
7337
  function createGithubSource(opts) {
7275
7338
  const now = opts.now ?? Date.now;
7276
7339
  const doFetch = opts.fetch ?? ((url, init2) => fetch(url, init2));
@@ -7353,10 +7416,14 @@ ${url}`;
7353
7416
  }
7354
7417
  }
7355
7418
  const checks = [...byName.values()];
7419
+ const headRepo = str4(rec2(rec2(p2.head).repo).full_name);
7420
+ const baseRepo = str4(rec2(rec2(p2.base).repo).full_name) ?? repo;
7356
7421
  prs.push({
7357
7422
  number: Number(p2.number),
7358
7423
  title: str4(p2.title) ?? "",
7359
7424
  head_sha: head,
7425
+ head_ref: str4(rec2(p2.head).ref) ?? "",
7426
+ fork: headRepo === null || headRepo.toLowerCase() !== baseRepo.toLowerCase(),
7360
7427
  author: str4(rec2(p2.user).login),
7361
7428
  draft: p2.draft === true,
7362
7429
  updated_at: str4(p2.updated_at),
@@ -7659,9 +7726,14 @@ function createHub(opts = {}) {
7659
7726
  readRegistry(home).value.repos.forEach((r2) => add(r2.path));
7660
7727
  return out;
7661
7728
  };
7662
- const collector = opts.collector ?? createCollectorSource({ repos: repoPaths, now });
7663
- const agents = opts.agents ?? createAgentsSource({ now, home });
7664
7729
  const github = opts.github ?? createGithubSource({ repos: repoPaths, accounts: () => readConfig(home).value.accounts, now });
7730
+ const collector = opts.collector ?? createCollectorSource({
7731
+ repos: repoPaths,
7732
+ now,
7733
+ prs: () => prHeads(github.get().data),
7734
+ prsFile: path19.join(hubDir(home), "collector-prs.json")
7735
+ });
7736
+ const agents = opts.agents ?? createAgentsSource({ now, home });
7665
7737
  const coordinator = opts.coordinator ?? createCoordinatorSource({ home, now });
7666
7738
  let versionsCache = null;
7667
7739
  const versions = () => {
@@ -7828,6 +7900,7 @@ var init_state = __esm({
7828
7900
  init_coordinator();
7829
7901
  init_github();
7830
7902
  init_bounded();
7903
+ init_paths();
7831
7904
  init_pkg();
7832
7905
  init_sessions();
7833
7906
  STATE_SCHEMA = 1;
@@ -8019,7 +8092,7 @@ var init_actions = __esm({
8019
8092
 
8020
8093
  // src/hub/auth.ts
8021
8094
  import { createHash as createHash2, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
8022
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync15, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "fs";
8095
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync15, renameSync as renameSync3, writeFileSync as writeFileSync6 } from "fs";
8023
8096
  import path21 from "path";
8024
8097
  function randomToken() {
8025
8098
  return randomBytes3(32).toString("base64url");
@@ -8117,8 +8190,8 @@ var init_auth = __esm({
8117
8190
  };
8118
8191
  const tmp = `${this.file}.${process.pid}.tmp`;
8119
8192
  try {
8120
- mkdirSync7(path21.dirname(this.file), { recursive: true });
8121
- writeFileSync5(tmp, JSON.stringify(body), { mode: 384 });
8193
+ mkdirSync8(path21.dirname(this.file), { recursive: true });
8194
+ writeFileSync6(tmp, JSON.stringify(body), { mode: 384 });
8122
8195
  renameSync3(tmp, this.file);
8123
8196
  for (const s of this.sessions) s.savedSeenAt = s.lastSeenAt;
8124
8197
  } catch {
@@ -8632,7 +8705,7 @@ __export(hub_exports, {
8632
8705
  });
8633
8706
  import http2 from "http";
8634
8707
  import path23 from "path";
8635
- import { mkdirSync as mkdirSync8, readFileSync as readFileSync16 } from "fs";
8708
+ import { mkdirSync as mkdirSync9, readFileSync as readFileSync16 } from "fs";
8636
8709
  import { randomBytes as randomBytes4 } from "crypto";
8637
8710
  function defaultVersions2() {
8638
8711
  return { cli: packageInfo().version, caddis: bundleManifest().poolVersion };
@@ -8925,7 +8998,7 @@ async function hubStart(deps = {}) {
8925
8998
  return 1;
8926
8999
  }
8927
9000
  const cwd = hubDir(home);
8928
- mkdirSync8(cwd, { recursive: true });
9001
+ mkdirSync9(cwd, { recursive: true });
8929
9002
  const child = await (deps.spawn ?? defaultSpawn)(process.execPath, [entry, "hub", "serve"], { cwd });
8930
9003
  let exited = false;
8931
9004
  let exitCode = null;
@@ -9201,9 +9274,32 @@ function plan(raw) {
9201
9274
  title: str5(p2.title),
9202
9275
  status: str5(p2.status),
9203
9276
  tracker: arr2(p2.tracker).map((t) => ({ phase: str5(rec3(t).phase), status: str5(rec3(t).status), state: str5(rec3(t).state) })),
9204
- open_rows: int(p2.open_rows)
9277
+ open_rows: int(p2.open_rows),
9278
+ overlay: planOverlay(p2.overlay)
9205
9279
  };
9206
9280
  }
9281
+ function dateText(v2) {
9282
+ if (typeof v2 !== "number" || !Number.isInteger(v2) || v2 < 0) return null;
9283
+ const d3 = new Date(v2 * 1e3);
9284
+ return Number.isNaN(d3.getTime()) ? null : d3.toISOString().slice(0, 10);
9285
+ }
9286
+ function donePlan(raw) {
9287
+ const p2 = rec3(raw);
9288
+ if (p2.error !== void 0 || !safePlanPath(str5(p2.path))) return null;
9289
+ return { path: str5(p2.path), title: str5(p2.title), closed_at: dateText(p2.closed_at), phases: int(p2.phases), pr: posInt(p2.pr) ? p2.pr : null };
9290
+ }
9291
+ function planOverlay(raw) {
9292
+ const o2 = rec3(raw);
9293
+ if (!posInt(o2.pr)) return null;
9294
+ return { pr: o2.pr, draft: o2.draft === true, also: arr2(o2.also).filter(posInt) };
9295
+ }
9296
+ function repoOverlay(raw) {
9297
+ const o2 = rec3(raw);
9298
+ if (o2.state !== "on" && o2.state !== "off") return null;
9299
+ const known = OVERLAY_REASONS.includes(o2.reason);
9300
+ const reason = o2.reason === null ? null : known ? o2.reason : "unknown";
9301
+ return { state: o2.state, reason, count: int(o2.count) };
9302
+ }
9207
9303
  function repoOf(collect) {
9208
9304
  const repos = arr2(rec3(collect).repos);
9209
9305
  if (repos.length !== 1) throw new Error("the collector output must hold exactly one repo");
@@ -9228,7 +9324,9 @@ function exportData(collect, opts) {
9228
9324
  github: opts.github,
9229
9325
  commit,
9230
9326
  roadmaps: arr2(slot.roadmaps).map(roadmap),
9231
- plans: arr2(rec3(repo.plans).plans).map(plan).filter((p2) => p2 !== null)
9327
+ plans: arr2(rec3(repo.plans).plans).map(plan).filter((p2) => p2 !== null),
9328
+ done_plans: arr2(rec3(rec3(repo.plans).done).plans).map(donePlan).filter((p2) => p2 !== null),
9329
+ overlay: repoOverlay(rec3(repo.plans).overlay)
9232
9330
  };
9233
9331
  }
9234
9332
  function derivedDeny(collect, machine) {
@@ -9264,10 +9362,11 @@ function derivedDeny(collect, machine) {
9264
9362
  if (!GENERIC_NAMES.has(machine.user.toLowerCase())) add(machine.user);
9265
9363
  return [...out];
9266
9364
  }
9267
- var GITHUB_RE, ERROR_TEXT, rec3, arr2, str5, strOrNull, int, shortSha, GENERIC_NAMES;
9365
+ var OVERLAY_REASONS, GITHUB_RE, ERROR_TEXT, rec3, arr2, str5, strOrNull, int, posInt, shortSha, GENERIC_NAMES;
9268
9366
  var init_data = __esm({
9269
9367
  "src/hub/export/data.ts"() {
9270
9368
  "use strict";
9369
+ OVERLAY_REASONS = ["no PR data", "PR data unreadable", "no git", "privacy hit in branch content"];
9271
9370
  GITHUB_RE = /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/;
9272
9371
  ERROR_TEXT = "could not be read";
9273
9372
  rec3 = (v2) => v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : {};
@@ -9275,6 +9374,7 @@ var init_data = __esm({
9275
9374
  str5 = (v2) => typeof v2 === "string" ? v2 : "";
9276
9375
  strOrNull = (v2) => typeof v2 === "string" && v2 ? v2 : null;
9277
9376
  int = (v2) => typeof v2 === "number" && Number.isInteger(v2) ? v2 : 0;
9377
+ posInt = (v2) => typeof v2 === "number" && Number.isInteger(v2) && v2 > 0;
9278
9378
  shortSha = (v2) => {
9279
9379
  const s = str5(v2);
9280
9380
  return /^[0-9a-fA-F]{7,}$/.test(s) ? s.slice(0, 7) : null;
@@ -9337,6 +9437,15 @@ function scanUrls(file, text2, opts, hits) {
9337
9437
  hits.push({ file, offset: m2.index ?? 0, rule: "url-not-allowed" });
9338
9438
  }
9339
9439
  }
9440
+ function isPrivateText(text2, deny) {
9441
+ if (PRIVATE_NAMES.some((name) => text2.includes(name))) return true;
9442
+ if (PATTERNS.some(({ re }) => new RegExp(re.source, re.flags.replace("g", "")).test(text2))) return true;
9443
+ return deny.some((value) => {
9444
+ if (value === "") return false;
9445
+ const re = isNumeric(value) ? new RegExp(`(?<![0-9])${escapeRe(value)}(?![0-9])`, "i") : new RegExp(escapeRe(value), "i");
9446
+ return re.test(text2);
9447
+ });
9448
+ }
9340
9449
  function scanExport(dir, opts) {
9341
9450
  const hits = [];
9342
9451
  for (const file of walk(dir)) {
@@ -9419,22 +9528,40 @@ __export(export_exports, {
9419
9528
  checkOut: () => checkOut,
9420
9529
  escapeJson: () => escapeJson,
9421
9530
  hubExport: () => hubExport,
9422
- notFoundPage: () => notFoundPage
9531
+ notFoundPage: () => notFoundPage,
9532
+ prsForCollector: () => prsForCollector
9423
9533
  });
9424
9534
  import { createHash as createHash3 } from "crypto";
9425
9535
  import {
9426
9536
  copyFileSync,
9427
9537
  existsSync as existsSync10,
9428
9538
  lstatSync as lstatSync2,
9429
- mkdirSync as mkdirSync9,
9539
+ mkdirSync as mkdirSync10,
9430
9540
  readdirSync as readdirSync6,
9431
9541
  readFileSync as readFileSync18,
9432
9542
  rmSync as rmSync4,
9433
9543
  statSync as statSync3,
9434
- writeFileSync as writeFileSync6
9544
+ writeFileSync as writeFileSync7
9435
9545
  } from "fs";
9436
9546
  import os6 from "os";
9437
9547
  import path25 from "path";
9548
+ function prsForCollector(gh, repo) {
9549
+ if (!Array.isArray(gh)) return null;
9550
+ const heads = [];
9551
+ for (const raw of gh) {
9552
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
9553
+ const it = raw;
9554
+ if (!isPosInt(it.number) || typeof it.headRefName !== "string" || !it.headRefName) continue;
9555
+ heads.push({
9556
+ number: it.number,
9557
+ head_ref: it.headRefName,
9558
+ draft: it.isDraft === true,
9559
+ fork: it.isCrossRepository !== false,
9560
+ updated_at: typeof it.updatedAt === "string" ? it.updatedAt : ""
9561
+ });
9562
+ }
9563
+ return { schema: 1, repos: { [repo]: heads } };
9564
+ }
9438
9565
  function holdsLink(dir) {
9439
9566
  for (const name of readdirSync6(dir)) {
9440
9567
  const full = path25.join(dir, name);
@@ -9482,9 +9609,9 @@ function notFoundPage() {
9482
9609
  `;
9483
9610
  }
9484
9611
  function copyFixedSet(dist, dest) {
9485
- mkdirSync9(path25.join(dest, "assets"), { recursive: true });
9486
- mkdirSync9(path25.join(dest, "fonts"), { recursive: true });
9487
- mkdirSync9(path25.join(dest, "licenses"), { recursive: true });
9612
+ mkdirSync10(path25.join(dest, "assets"), { recursive: true });
9613
+ mkdirSync10(path25.join(dest, "fonts"), { recursive: true });
9614
+ mkdirSync10(path25.join(dest, "licenses"), { recursive: true });
9488
9615
  copyFileSync(path25.join(dist, "index.html"), path25.join(dest, "index.html"));
9489
9616
  for (const name of readdirSync6(path25.join(dist, "assets"))) {
9490
9617
  const from = path25.join(dist, "assets", name);
@@ -9535,9 +9662,9 @@ async function hubExport(args, deps = {}) {
9535
9662
  err(`error: --check folder not found: ${args.check}`);
9536
9663
  return 1;
9537
9664
  }
9538
- const machine = machineOf(deps.machine, "");
9539
- const deny2 = derivedDeny({ repos: [] }, machine);
9540
- const hits = scanExport(dir, { deny: deny2, github: args.github ?? null, ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {} });
9665
+ const machine2 = machineOf(deps.machine, "");
9666
+ const deny = derivedDeny({ repos: [] }, machine2);
9667
+ const hits = scanExport(dir, { deny, github: args.github ?? null, ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {} });
9541
9668
  for (const h2 of hits) err(hitLine(h2));
9542
9669
  if (hits.length) {
9543
9670
  err(`[BLOCKED] ${hits.length} privacy hit(s)`);
@@ -9547,7 +9674,7 @@ async function hubExport(args, deps = {}) {
9547
9674
  return 0;
9548
9675
  }
9549
9676
  if (!args.repo || !args.out) {
9550
- err("usage: caddis hub export --repo <path> --out <dir> [--github <owner>/<repo>] [--commit <sha>] [--label <text>]");
9677
+ err("usage: caddis hub export --repo <path> --out <dir> [--github <owner>/<repo>] [--commit <sha>] [--label <text>] [--prs <file>]");
9551
9678
  return 2;
9552
9679
  }
9553
9680
  if (args.commit !== void 0 && !/^[0-9a-fA-F]{7,40}$/.test(args.commit)) {
@@ -9581,62 +9708,134 @@ async function hubExport(args, deps = {}) {
9581
9708
  cmd = found.cmd;
9582
9709
  pre = found.pre;
9583
9710
  }
9711
+ const python = cmd;
9584
9712
  const script = deps.scriptPath ?? defaultScriptPath();
9585
- const run2 = await spawn2(cmd, [...pre, script, "--repos", repo, "--only", "roadmaps,plans", "--json"], { timeoutMs: COLLECT_TIMEOUT_MS });
9586
- if (run2.timedOut || !run2.ok) {
9587
- err(`error: the collector ${run2.timedOut ? "timed out" : `failed (exit ${run2.code ?? "none"})`}`);
9588
- return 1;
9589
- }
9590
- let collect;
9591
- try {
9592
- collect = JSON.parse(run2.stdout);
9593
- } catch {
9594
- err("error: the collector output is not valid JSON");
9595
- return 1;
9713
+ const machine = machineOf(deps.machine, repo);
9714
+ const collectOnce = async (prsFile2) => {
9715
+ const extra = prsFile2 === null ? [] : ["--prs-file", prsFile2];
9716
+ const run2 = await spawn2(python, [...pre, script, "--repos", repo, "--only", "roadmaps,plans", ...extra, "--json"], { timeoutMs: COLLECT_TIMEOUT_MS });
9717
+ if (run2.timedOut || !run2.ok) {
9718
+ err(`error: the collector ${run2.timedOut ? "timed out" : `failed (exit ${run2.code ?? "none"})`}`);
9719
+ return null;
9720
+ }
9721
+ try {
9722
+ return { value: JSON.parse(run2.stdout) };
9723
+ } catch {
9724
+ err("error: the collector output is not valid JSON");
9725
+ return null;
9726
+ }
9727
+ };
9728
+ const dataOf = (collect) => {
9729
+ try {
9730
+ return exportData(collect, {
9731
+ label: args.label ?? null,
9732
+ github: args.github ?? null,
9733
+ commit: args.commit ?? null,
9734
+ now: now().toISOString().replace(/\.\d{3}Z$/, "Z")
9735
+ });
9736
+ } catch (error) {
9737
+ err(`error: ${error instanceof Error ? error.message : String(error)}`);
9738
+ return null;
9739
+ }
9740
+ };
9741
+ let prsFile = null;
9742
+ let prsUnreadable = false;
9743
+ if (args.prs !== void 0) {
9744
+ let gh = null;
9745
+ try {
9746
+ gh = JSON.parse(readFileSync18(path25.resolve(args.prs), "utf8"));
9747
+ } catch {
9748
+ gh = null;
9749
+ }
9750
+ const body = prsForCollector(gh, repo);
9751
+ if (body === null) {
9752
+ prsUnreadable = true;
9753
+ } else {
9754
+ prsFile = `${outDir}.prs-${process.pid}.json`;
9755
+ try {
9756
+ mkdirSync10(path25.dirname(prsFile), { recursive: true });
9757
+ writeFileSync7(prsFile, JSON.stringify(body));
9758
+ } catch (error) {
9759
+ rmSync4(prsFile, { force: true });
9760
+ err(`error: ${error instanceof Error ? error.message : String(error)}`);
9761
+ return 1;
9762
+ }
9763
+ }
9596
9764
  }
9597
- let data;
9598
9765
  try {
9599
- data = exportData(collect, {
9600
- label: args.label ?? null,
9766
+ const first = await collectOnce(prsFile);
9767
+ if (!first) return 1;
9768
+ let data = dataOf(first.value);
9769
+ if (!data) return 1;
9770
+ if (prsUnreadable) data.overlay = { state: "off", reason: "PR data unreadable", count: 0 };
9771
+ if (data.overlay?.state === "on") out(`[OVERLAY] on: ${data.overlay.count} plan(s) from PR branches`);
9772
+ else if (data.overlay?.state === "off") out(`[OVERLAY] off: ${data.overlay.reason ?? "unknown"}`);
9773
+ let deny = derivedDeny(first.value, machine);
9774
+ const dropPrivateDone = (page) => {
9775
+ const rows = page.done_plans ?? [];
9776
+ const kept = rows.filter((p2) => !isPrivateText(p2.path, deny) && !isPrivateText(p2.title, deny));
9777
+ if (kept.length === rows.length) return;
9778
+ page.done_plans = kept;
9779
+ out(`[DONE] ${rows.length - kept.length} done plan(s) left out: private words in the name`);
9780
+ };
9781
+ dropPrivateDone(data);
9782
+ const scanOpts = () => ({
9783
+ deny,
9601
9784
  github: args.github ?? null,
9602
- commit: args.commit ?? null,
9603
- now: now().toISOString().replace(/\.\d{3}Z$/, "Z")
9785
+ ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {}
9604
9786
  });
9605
- } catch (error) {
9606
- err(`error: ${error instanceof Error ? error.message : String(error)}`);
9607
- return 1;
9608
- }
9609
- const deny = derivedDeny(collect, machineOf(deps.machine, repo));
9610
- const staging = `${outDir}.staging-${process.pid}`;
9611
- rmSync4(staging, { recursive: true, force: true });
9612
- try {
9613
- copyFixedSet(dist, staging);
9614
- const indexPath = path25.join(staging, "index.html");
9615
- const html = readFileSync18(indexPath, "utf8");
9616
- if (!html.includes(PLACEHOLDER)) throw new Error("the built index.html has no data placeholder");
9617
- const block = `<script type="application/json" id="caddis-export-data">${escapeJson(JSON.stringify(data))}</script>`;
9618
- writeFileSync6(indexPath, html.replace(PLACEHOLDER, () => block));
9619
- writeFileSync6(path25.join(staging, "404.html"), notFoundPage());
9620
- const hits = scanExport(staging, { deny, github: args.github ?? null, ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {} });
9621
- if (hits.length) {
9622
- for (const h2 of hits) err(hitLine(h2));
9623
- err(`[BLOCKED] ${hits.length} privacy hit(s). Nothing was published.`);
9787
+ const staging = `${outDir}.staging-${process.pid}`;
9788
+ const build = (page) => {
9789
+ rmSync4(staging, { recursive: true, force: true });
9790
+ copyFixedSet(dist, staging);
9791
+ const indexPath = path25.join(staging, "index.html");
9792
+ const html = readFileSync18(indexPath, "utf8");
9793
+ if (!html.includes(PLACEHOLDER)) throw new Error("the built index.html has no data placeholder");
9794
+ const block = `<script type="application/json" id="caddis-export-data">${escapeJson(JSON.stringify(page))}</script>`;
9795
+ writeFileSync7(indexPath, html.replace(PLACEHOLDER, () => block));
9796
+ writeFileSync7(path25.join(staging, "404.html"), notFoundPage());
9797
+ };
9798
+ try {
9799
+ build(data);
9800
+ let hits = scanExport(staging, scanOpts());
9801
+ if (hits.length && data.overlay?.state === "on" && data.overlay.count > 0) {
9802
+ for (const h2 of hits) err(hitLine(h2));
9803
+ out("[OVERLAY] off: privacy hit in branch content");
9804
+ rmSync4(staging, { recursive: true, force: true });
9805
+ const second = await collectOnce(null);
9806
+ if (!second) return 1;
9807
+ const mainOnly = dataOf(second.value);
9808
+ if (!mainOnly) return 1;
9809
+ mainOnly.overlay = { state: "off", reason: "privacy hit in branch content", count: 0 };
9810
+ deny = [.../* @__PURE__ */ new Set([...deny, ...derivedDeny(second.value, machine)])];
9811
+ data = mainOnly;
9812
+ dropPrivateDone(data);
9813
+ build(data);
9814
+ hits = scanExport(staging, scanOpts());
9815
+ }
9816
+ if (hits.length) {
9817
+ for (const h2 of hits) err(hitLine(h2));
9818
+ err(`[BLOCKED] ${hits.length} privacy hit(s). Nothing was published.`);
9819
+ rmSync4(staging, { recursive: true, force: true });
9820
+ return 3;
9821
+ }
9822
+ mkdirSync10(path25.dirname(outDir), { recursive: true });
9823
+ if (existsSync10(outDir)) rmSync4(outDir, { recursive: true, force: true });
9824
+ renameWithRetry(staging, outDir);
9825
+ writeFileSync7(path25.join(outDir, MARKER), "written by caddis hub export\n");
9826
+ out(`[EXPORT] ${countFiles(outDir)} file(s) in ${outDir}`);
9827
+ return 0;
9828
+ } catch (error) {
9829
+ err(`error: ${error instanceof Error ? error.message : String(error)}`);
9830
+ return 1;
9831
+ } finally {
9624
9832
  rmSync4(staging, { recursive: true, force: true });
9625
- return 3;
9626
9833
  }
9627
- mkdirSync9(path25.dirname(outDir), { recursive: true });
9628
- if (existsSync10(outDir)) rmSync4(outDir, { recursive: true, force: true });
9629
- renameWithRetry(staging, outDir);
9630
- writeFileSync6(path25.join(outDir, MARKER), "written by caddis hub export\n");
9631
- out(`[EXPORT] ${countFiles(outDir)} file(s) in ${outDir}`);
9632
- return 0;
9633
- } catch (error) {
9634
- rmSync4(staging, { recursive: true, force: true });
9635
- err(`error: ${error instanceof Error ? error.message : String(error)}`);
9636
- return 1;
9834
+ } finally {
9835
+ if (prsFile !== null) rmSync4(prsFile, { force: true });
9637
9836
  }
9638
9837
  }
9639
- var MARKER, PLACEHOLDER, COLLECT_TIMEOUT_MS, FIXED_FILES, isDir2, samePath, isInside, NOT_FOUND_SCRIPT;
9838
+ var MARKER, PLACEHOLDER, COLLECT_TIMEOUT_MS, isPosInt, FIXED_FILES, isDir2, samePath, isInside, NOT_FOUND_SCRIPT;
9640
9839
  var init_export = __esm({
9641
9840
  "src/hub/export/export.ts"() {
9642
9841
  "use strict";
@@ -9649,6 +9848,7 @@ var init_export = __esm({
9649
9848
  MARKER = ".caddis-export";
9650
9849
  PLACEHOLDER = "<!--caddis-export-data-->";
9651
9850
  COLLECT_TIMEOUT_MS = 12e4;
9851
+ isPosInt = (v2) => typeof v2 === "number" && Number.isInteger(v2) && v2 > 0;
9652
9852
  FIXED_FILES = ["index.html", "404.html"];
9653
9853
  isDir2 = (p2) => {
9654
9854
  try {
@@ -10577,7 +10777,7 @@ hub.command("serve").description("run the hub in the foreground (used by start a
10577
10777
  const { hubServe: hubServe2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
10578
10778
  finish(await hubServe2());
10579
10779
  });
10580
- hub.command("export").description("build the static roadmap page for GitHub Pages: roadmap data only, privacy scan (exit 3 on a hit)").option("--repo <path>", "the git checkout with .caddis/roadmaps or .caddis/plans").option("--out <dir>", "the folder to write (emptied only if empty or made by this command)").option("--github <owner/repo>", "the public GitHub repo, for the PR links").option("--commit <sha>", "the commit the page is built from (cut to 7 hex)").option("--label <text>", "extra text for the banner").option("--check <dir>", "scan an already built folder and do nothing else").action(async (options) => {
10780
+ hub.command("export").description("build the static roadmap page for GitHub Pages: roadmap data only, privacy scan (exit 3 on a hit)").option("--repo <path>", "the git checkout with .caddis/roadmaps or .caddis/plans").option("--out <dir>", "the folder to write (emptied only if empty or made by this command)").option("--github <owner/repo>", "the public GitHub repo, for the PR links").option("--commit <sha>", "the commit the page is built from (cut to 7 hex)").option("--label <text>", "extra text for the banner").option("--check <dir>", "scan an already built folder and do nothing else").option("--prs <file>", "open PRs as JSON from gh pr list --json number,headRefName,isDraft,isCrossRepository,updatedAt; shows plan progress from PR branches").action(async (options) => {
10581
10781
  const { hubExport: hubExport2 } = await Promise.resolve().then(() => (init_export(), export_exports));
10582
10782
  finish(await hubExport2(options));
10583
10783
  });