@loomwright/cli 1.1.0 → 1.2.0

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/dist/cli.js CHANGED
@@ -14708,7 +14708,7 @@ __export(exports_iso, {
14708
14708
  });
14709
14709
 
14710
14710
  // packages/cli/src/main.ts
14711
- import { resolve as resolve9 } from "node:path";
14711
+ import { resolve as resolve10 } from "node:path";
14712
14712
  import { createInterface } from "node:readline/promises";
14713
14713
 
14714
14714
  // packages/core/src/exit-codes.ts
@@ -14769,7 +14769,7 @@ class TransientError extends Error {
14769
14769
  }
14770
14770
 
14771
14771
  // packages/core/src/version.ts
14772
- var FACTORY_VERSION = "1.1.0";
14772
+ var FACTORY_VERSION = "1.2.0";
14773
14773
  var PACKAGE_NAME = "@loomwright/cli";
14774
14774
  var runVersion = (version) => `npx ${PACKAGE_NAME}@${version}`;
14775
14775
 
@@ -23573,8 +23573,99 @@ function section(text, heading) {
23573
23573
  }
23574
23574
 
23575
23575
  // packages/core/src/pipeline/design.ts
23576
- import { existsSync as existsSync13 } from "node:fs";
23577
- import { join as join13 } from "node:path";
23576
+ import { existsSync as existsSync14 } from "node:fs";
23577
+ import { join as join14 } from "node:path";
23578
+
23579
+ // packages/core/src/approval/approval.ts
23580
+ import { createHash } from "node:crypto";
23581
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync as readdirSync3, readFileSync as readFileSync4, statSync as statSync2, writeFileSync } from "node:fs";
23582
+ import { dirname as dirname2, join as join4 } from "node:path";
23583
+ function parseApproval(value) {
23584
+ if (typeof value !== "object" || value === null)
23585
+ return;
23586
+ const v = value;
23587
+ const ok = typeof v.changeId === "string" && typeof v.approver === "string" && typeof v.specCommit === "string" && /^[0-9a-f]{40,64}$/.test(v.specCommit) && typeof v.hash === "string" && /^[0-9a-f]{64}$/.test(v.hash) && typeof v.approvedAt === "string";
23588
+ if (!ok)
23589
+ return;
23590
+ if (v.history !== undefined) {
23591
+ if (!Array.isArray(v.history))
23592
+ return;
23593
+ for (const entry of v.history) {
23594
+ if (typeof entry !== "object" || entry === null)
23595
+ return;
23596
+ const e = entry;
23597
+ if (typeof e.hash !== "string" || !/^[0-9a-f]{64}$/.test(e.hash) || typeof e.specCommit !== "string" || !/^[0-9a-f]{40,64}$/.test(e.specCommit) || typeof e.at !== "string" || typeof e.reason !== "string")
23598
+ return;
23599
+ }
23600
+ }
23601
+ return value;
23602
+ }
23603
+ var changeDir = (root, id) => join4(root, "openspec", "changes", id);
23604
+ var approvalFile = (root, id) => join4(root, ".factory", "approvals", `${id}.json`);
23605
+ function writeApproval(root, approval) {
23606
+ const file = approvalFile(root, approval.changeId);
23607
+ mkdirSync2(dirname2(file), { recursive: true });
23608
+ writeFileSync(file, `${JSON.stringify(approval, null, 2)}
23609
+ `);
23610
+ return file;
23611
+ }
23612
+ function isSpecPath(file) {
23613
+ if (file === undefined)
23614
+ return false;
23615
+ const raw = file.replace(/\\/g, "/").replace(/^\.\//, "");
23616
+ const parts = raw.split("/");
23617
+ if (parts[0]?.toLowerCase() === "openspec")
23618
+ return true;
23619
+ return raw.startsWith("/") && parts.some((part) => part.toLowerCase() === "openspec");
23620
+ }
23621
+ function filesUnder(dir, prefix = "") {
23622
+ if (!existsSync4(dir))
23623
+ return [];
23624
+ return readdirSync3(dir).sort().flatMap((name) => {
23625
+ const rel = prefix === "" ? name : `${prefix}/${name}`;
23626
+ const abs = join4(dir, name);
23627
+ return statSync2(abs).isDirectory() ? filesUnder(abs, rel) : [rel];
23628
+ });
23629
+ }
23630
+ function approvedFiles(root, id) {
23631
+ const dir = changeDir(root, id);
23632
+ const top = ["proposal.md", "design.md", "tasks.md"].filter((f) => existsSync4(join4(dir, f)));
23633
+ const specs = filesUnder(join4(dir, "specs"), "specs").filter((f) => f.endsWith(".md"));
23634
+ return [...top, ...specs].sort();
23635
+ }
23636
+ function specHash(root, id) {
23637
+ const hash = createHash("sha256");
23638
+ const dir = changeDir(root, id);
23639
+ for (const rel of approvedFiles(root, id)) {
23640
+ let content = readFileSync4(join4(dir, rel), "utf8").replace(/\r\n/g, `
23641
+ `);
23642
+ if (rel === "tasks.md")
23643
+ content = normalizeCheckboxes(content);
23644
+ hash.update(rel).update("\x00").update(content).update("\x00");
23645
+ }
23646
+ return hash.digest("hex");
23647
+ }
23648
+ function readApproval(root, id) {
23649
+ const file = approvalFile(root, id);
23650
+ if (!existsSync4(file))
23651
+ return;
23652
+ try {
23653
+ return parseApproval(JSON.parse(readFileSync4(file, "utf8")));
23654
+ } catch {
23655
+ return;
23656
+ }
23657
+ }
23658
+ function checkApprovalHash(root, id) {
23659
+ const approval = readApproval(root, id);
23660
+ if (approval === undefined)
23661
+ return { valid: false, reason: `change ${id} is not approved` };
23662
+ if (approvedFiles(root, id).length === 0)
23663
+ return { valid: false, reason: `change ${id} has no spec files` };
23664
+ if (specHash(root, id) !== approval.hash) {
23665
+ return { valid: false, reason: `the spec of ${id} changed after approval; approve it again` };
23666
+ }
23667
+ return { valid: true, approval };
23668
+ }
23578
23669
 
23579
23670
  // packages/core/src/config/instructions.ts
23580
23671
  import { relative as relative2 } from "node:path";
@@ -23602,8 +23693,8 @@ function allInstructionPaths(config) {
23602
23693
  }
23603
23694
 
23604
23695
  // packages/core/src/git/branching.ts
23605
- import { existsSync as existsSync4 } from "node:fs";
23606
- import { join as join4 } from "node:path";
23696
+ import { existsSync as existsSync5 } from "node:fs";
23697
+ import { join as join5 } from "node:path";
23607
23698
  async function switchToChangeBranch(dir, branch, start) {
23608
23699
  if (await currentBranch(dir) === branch)
23609
23700
  return { created: false };
@@ -23640,8 +23731,8 @@ async function trackedBranch(root, path) {
23640
23731
  return;
23641
23732
  }
23642
23733
  async function branchSubmodule(root, repo, id) {
23643
- const dir = join4(root, repo.path);
23644
- if (!existsSync4(join4(dir, ".git"))) {
23734
+ const dir = join5(root, repo.path);
23735
+ if (!existsSync5(join5(dir, ".git"))) {
23645
23736
  throw new PreconditionError(`submodule ${repo.path} is not initialised`, [
23646
23737
  `run \`git submodule update --init ${repo.path}\``
23647
23738
  ]);
@@ -23656,20 +23747,20 @@ async function branchSubmodule(root, repo, id) {
23656
23747
  }
23657
23748
 
23658
23749
  // packages/core/src/graph/graph.ts
23659
- import { existsSync as existsSync7, readFileSync as readFileSync5, rmSync as rmSync4, statSync as statSync4 } from "node:fs";
23660
- import { join as join7 } from "node:path";
23750
+ import { existsSync as existsSync8, readFileSync as readFileSync6, rmSync as rmSync4, statSync as statSync5 } from "node:fs";
23751
+ import { join as join8 } from "node:path";
23661
23752
 
23662
23753
  // packages/core/src/logs/log.ts
23663
23754
  import {
23664
23755
  appendFileSync,
23665
- existsSync as existsSync5,
23666
- mkdirSync as mkdirSync2,
23667
- readdirSync as readdirSync3,
23756
+ existsSync as existsSync6,
23757
+ mkdirSync as mkdirSync3,
23758
+ readdirSync as readdirSync4,
23668
23759
  rmdirSync,
23669
23760
  rmSync as rmSync2,
23670
- statSync as statSync2
23761
+ statSync as statSync3
23671
23762
  } from "node:fs";
23672
- import { join as join5 } from "node:path";
23763
+ import { join as join6 } from "node:path";
23673
23764
 
23674
23765
  // packages/core/src/logs/redact.ts
23675
23766
  var MARK = (kind) => `[REDACTED:${kind}]`;
@@ -23727,37 +23818,37 @@ function redactValue(value, env, heuristic) {
23727
23818
  return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactValue(v, env, heuristic)]));
23728
23819
  return value;
23729
23820
  }
23730
- var logDir = (root, changeId) => join5(root, ".factory", "logs", changeId);
23821
+ var logDir = (root, changeId) => join6(root, ".factory", "logs", changeId);
23731
23822
  function appendLog(root, changeId, entry, options = {}) {
23732
23823
  const dir = logDir(root, changeId);
23733
- mkdirSync2(dir, { recursive: true });
23824
+ mkdirSync3(dir, { recursive: true });
23734
23825
  const at = new Date;
23735
23826
  const env = secretEnvValues(options.env ?? process.env);
23736
23827
  const line = JSON.stringify({
23737
23828
  at: at.toISOString(),
23738
23829
  ...redactValue(entry, env, options.redact ?? true)
23739
23830
  });
23740
- appendFileSync(join5(dir, `${at.toISOString().slice(0, 10)}.jsonl`), `${line}
23831
+ appendFileSync(join6(dir, `${at.toISOString().slice(0, 10)}.jsonl`), `${line}
23741
23832
  `);
23742
23833
  }
23743
23834
  function pruneLogs(root, retentionDays, now = Date.now()) {
23744
- const base = join5(root, ".factory", "logs");
23745
- if (!existsSync5(base))
23835
+ const base = join6(root, ".factory", "logs");
23836
+ if (!existsSync6(base))
23746
23837
  return [];
23747
23838
  const cutoff = now - retentionDays * 24 * 60 * 60 * 1000;
23748
23839
  const removed = [];
23749
- for (const change of readdirSync3(base)) {
23750
- const dir = join5(base, change);
23751
- if (!statSync2(dir).isDirectory())
23840
+ for (const change of readdirSync4(base)) {
23841
+ const dir = join6(base, change);
23842
+ if (!statSync3(dir).isDirectory())
23752
23843
  continue;
23753
- for (const file of readdirSync3(dir)) {
23754
- const abs = join5(dir, file);
23755
- if (statSync2(abs).mtimeMs < cutoff) {
23844
+ for (const file of readdirSync4(dir)) {
23845
+ const abs = join6(dir, file);
23846
+ if (statSync3(abs).mtimeMs < cutoff) {
23756
23847
  rmSync2(abs, { force: true });
23757
23848
  removed.push(abs);
23758
23849
  }
23759
23850
  }
23760
- if (readdirSync3(dir).length === 0)
23851
+ if (readdirSync4(dir).length === 0)
23761
23852
  rmdirSync(dir);
23762
23853
  }
23763
23854
  return removed;
@@ -23766,18 +23857,18 @@ function pruneLogs(root, retentionDays, now = Date.now()) {
23766
23857
  // packages/core/src/state/files.ts
23767
23858
  import {
23768
23859
  closeSync,
23769
- existsSync as existsSync6,
23770
- mkdirSync as mkdirSync3,
23860
+ existsSync as existsSync7,
23861
+ mkdirSync as mkdirSync4,
23771
23862
  openSync,
23772
- readFileSync as readFileSync4,
23863
+ readFileSync as readFileSync5,
23773
23864
  renameSync,
23774
23865
  rmSync as rmSync3,
23775
- statSync as statSync3,
23776
- writeFileSync
23866
+ statSync as statSync4,
23867
+ writeFileSync as writeFileSync2
23777
23868
  } from "node:fs";
23778
23869
  import { hostname } from "node:os";
23779
- import { dirname as dirname2, join as join6, relative as relative3 } from "node:path";
23780
- var factoryDir = (root, ...parts) => join6(root, ".factory", ...parts);
23870
+ import { dirname as dirname3, join as join7, relative as relative3 } from "node:path";
23871
+ var factoryDir = (root, ...parts) => join7(root, ".factory", ...parts);
23781
23872
 
23782
23873
  class CorruptStateError extends PreconditionError {
23783
23874
  file;
@@ -23789,12 +23880,12 @@ class CorruptStateError extends PreconditionError {
23789
23880
  }
23790
23881
  }
23791
23882
  function readState(root, path, schema, fix) {
23792
- if (!existsSync6(path))
23883
+ if (!existsSync7(path))
23793
23884
  return;
23794
23885
  const file = relative3(root, path);
23795
23886
  let raw;
23796
23887
  try {
23797
- raw = JSON.parse(readFileSync4(path, "utf8"));
23888
+ raw = JSON.parse(readFileSync5(path, "utf8"));
23798
23889
  } catch (err) {
23799
23890
  throw new CorruptStateError(file, err instanceof Error ? err.message : String(err), fix);
23800
23891
  }
@@ -23813,14 +23904,14 @@ function readOrCorrupt(read) {
23813
23904
  }
23814
23905
  }
23815
23906
  function writeJsonAtomic(path, value) {
23816
- mkdirSync3(dirname2(path), { recursive: true });
23907
+ mkdirSync4(dirname3(path), { recursive: true });
23817
23908
  const tmp = `${path}.${process.pid}.tmp`;
23818
- writeFileSync(tmp, `${JSON.stringify(value, null, 2)}
23909
+ writeFileSync2(tmp, `${JSON.stringify(value, null, 2)}
23819
23910
  `);
23820
23911
  renameSync(tmp, path);
23821
23912
  }
23822
23913
  function readJson(path) {
23823
- return JSON.parse(readFileSync4(path, "utf8"));
23914
+ return JSON.parse(readFileSync5(path, "utf8"));
23824
23915
  }
23825
23916
  function pidAlive(pid) {
23826
23917
  try {
@@ -23839,7 +23930,7 @@ function lockIsStale(path, staleAfterMs) {
23839
23930
  return Date.now() - owner.at > staleAfterMs;
23840
23931
  } catch {
23841
23932
  try {
23842
- return Date.now() - statSync3(path).mtimeMs > STALE_AFTER_MS;
23933
+ return Date.now() - statSync4(path).mtimeMs > STALE_AFTER_MS;
23843
23934
  } catch {
23844
23935
  return true;
23845
23936
  }
@@ -23847,12 +23938,12 @@ function lockIsStale(path, staleAfterMs) {
23847
23938
  }
23848
23939
  async function withFileLock(path, fn, timeoutMs = 1e4, options = {}) {
23849
23940
  const staleAfterMs = options.staleAfterMs ?? STALE_AFTER_MS;
23850
- mkdirSync3(dirname2(path), { recursive: true });
23941
+ mkdirSync4(dirname3(path), { recursive: true });
23851
23942
  const started = Date.now();
23852
23943
  for (let delay = 5;; delay = Math.min(delay * 2, 200)) {
23853
23944
  try {
23854
23945
  const fd = openSync(path, "wx");
23855
- writeFileSync(fd, JSON.stringify({ pid: process.pid, host: hostname(), at: Date.now() }));
23946
+ writeFileSync2(fd, JSON.stringify({ pid: process.pid, host: hostname(), at: Date.now() }));
23856
23947
  closeSync(fd);
23857
23948
  break;
23858
23949
  } catch (err) {
@@ -23875,12 +23966,12 @@ async function withFileLock(path, fn, timeoutMs = 1e4, options = {}) {
23875
23966
  }
23876
23967
 
23877
23968
  // packages/core/src/graph/graph.ts
23878
- var graphDir = (root) => join7(root, "graphify-out");
23879
- var graphFile = (root) => join7(graphDir(root), "graph.json");
23969
+ var graphDir = (root) => join8(root, "graphify-out");
23970
+ var graphFile = (root) => join8(graphDir(root), "graph.json");
23880
23971
  var metaFile = (root) => factoryDir(root, "graph-meta.json");
23881
23972
  function readGraph(root) {
23882
23973
  try {
23883
- return JSON.parse(readFileSync5(graphFile(root), "utf8"));
23974
+ return JSON.parse(readFileSync6(graphFile(root), "utf8"));
23884
23975
  } catch {
23885
23976
  return;
23886
23977
  }
@@ -23892,7 +23983,7 @@ function updateGraph(root, options = {}) {
23892
23983
  });
23893
23984
  }
23894
23985
  async function runGraphify(root, options) {
23895
- const full = options.full === true || !existsSync7(graphFile(root));
23986
+ const full = options.full === true || !existsSync8(graphFile(root));
23896
23987
  if (options.full)
23897
23988
  rmSync4(graphDir(root), { recursive: true, force: true });
23898
23989
  const started = Date.now();
@@ -23934,7 +24025,7 @@ function graphRebuildReason(status, installedGraphify) {
23934
24025
  return;
23935
24026
  }
23936
24027
  function graphStatus(root) {
23937
- if (!existsSync7(graphFile(root)))
24028
+ if (!existsSync8(graphFile(root)))
23938
24029
  return { state: "missing" };
23939
24030
  const doc = readGraph(root);
23940
24031
  const schema = doc?.graph?.schema_version;
@@ -23942,14 +24033,14 @@ function graphStatus(root) {
23942
24033
  return { state: "unsupported", schemaVersion: schema };
23943
24034
  let meta;
23944
24035
  try {
23945
- meta = existsSync7(metaFile(root)) ? readJson(metaFile(root)) : undefined;
24036
+ meta = existsSync8(metaFile(root)) ? readJson(metaFile(root)) : undefined;
23946
24037
  } catch {
23947
24038
  meta = undefined;
23948
24039
  }
23949
24040
  return {
23950
24041
  state: "ok",
23951
24042
  ...meta ? { meta } : {},
23952
- ageMs: Date.now() - statSync4(graphFile(root)).mtimeMs,
24043
+ ageMs: Date.now() - statSync5(graphFile(root)).mtimeMs,
23953
24044
  ...doc?.built_at_commit ? { builtAtCommit: doc.built_at_commit } : {}
23954
24045
  };
23955
24046
  }
@@ -23957,9 +24048,9 @@ var DEPENDENCY_RELATIONS = new Set(["calls", "imports", "imports_from", "referen
23957
24048
  var cache2;
23958
24049
  function dependentFiles(root, files) {
23959
24050
  const out = new Set;
23960
- if (files.length === 0 || !existsSync7(graphFile(root)))
24051
+ if (files.length === 0 || !existsSync8(graphFile(root)))
23961
24052
  return out;
23962
- const mtime = statSync4(graphFile(root)).mtimeMs;
24053
+ const mtime = statSync5(graphFile(root)).mtimeMs;
23963
24054
  if (cache2?.root !== root || cache2.mtime !== mtime) {
23964
24055
  const doc = readGraph(root);
23965
24056
  if (doc === undefined)
@@ -24087,7 +24178,7 @@ import { rmSync as rmSync5 } from "node:fs";
24087
24178
  import { hostname as hostname2 } from "node:os";
24088
24179
 
24089
24180
  // packages/core/src/state/run.ts
24090
- import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
24181
+ import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
24091
24182
  var PHASES = [
24092
24183
  "intake",
24093
24184
  "design",
@@ -24221,9 +24312,9 @@ function scanRuns(root) {
24221
24312
  runs: [],
24222
24313
  corrupt: []
24223
24314
  };
24224
- if (!existsSync8(dir))
24315
+ if (!existsSync9(dir))
24225
24316
  return scan;
24226
- for (const f of readdirSync4(dir).filter((n) => n.endsWith(".json"))) {
24317
+ for (const f of readdirSync5(dir).filter((n) => n.endsWith(".json"))) {
24227
24318
  const id = f.slice(0, -".json".length);
24228
24319
  try {
24229
24320
  const run = loadRun(root, id);
@@ -24329,20 +24420,20 @@ function dequeue(root) {
24329
24420
  }
24330
24421
 
24331
24422
  // packages/core/src/usage/usage.ts
24332
- import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync6, renameSync as renameSync2 } from "node:fs";
24333
- import { join as join9, relative as relative4 } from "node:path";
24423
+ import { existsSync as existsSync10, readdirSync as readdirSync6, readFileSync as readFileSync7, renameSync as renameSync2 } from "node:fs";
24424
+ import { join as join10, relative as relative4 } from "node:path";
24334
24425
 
24335
24426
  // packages/core/src/artifacts/paths.ts
24336
- import { join as join8 } from "node:path";
24427
+ import { join as join9 } from "node:path";
24337
24428
  var ARTIFACTS_DIR = "factory-records";
24338
24429
  var ARTIFACT_ID = /^[a-z0-9][a-z0-9-]*$/;
24339
24430
  function isArtifactId(id) {
24340
24431
  return ARTIFACT_ID.test(id);
24341
24432
  }
24342
24433
  function artifactFile(root, kind, name) {
24343
- return join8(root, ARTIFACTS_DIR, kind, name);
24434
+ return join9(root, ARTIFACTS_DIR, kind, name);
24344
24435
  }
24345
- var artifactDir = (root, kind) => kind === undefined ? join8(root, ARTIFACTS_DIR) : join8(root, ARTIFACTS_DIR, kind);
24436
+ var artifactDir = (root, kind) => kind === undefined ? join9(root, ARTIFACTS_DIR) : join9(root, ARTIFACTS_DIR, kind);
24346
24437
 
24347
24438
  // packages/core/src/usage/usage.ts
24348
24439
  var usageFile = (root, id) => factoryDir(root, "usage", `${id}.json`);
@@ -24357,14 +24448,14 @@ function readLedger(file) {
24357
24448
  function loadUsage(root, id) {
24358
24449
  const file = usageFile(root, id);
24359
24450
  const empty = { version: 1, changeId: id, entries: [] };
24360
- if (!existsSync9(file))
24451
+ if (!existsSync10(file))
24361
24452
  return empty;
24362
24453
  return readLedger(file) ?? empty;
24363
24454
  }
24364
24455
  function recordUsage(root, id, entry) {
24365
24456
  return withFileLock(`${usageFile(root, id)}.lock`, () => {
24366
24457
  const file = usageFile(root, id);
24367
- if (existsSync9(file) && readLedger(file) === undefined)
24458
+ if (existsSync10(file) && readLedger(file) === undefined)
24368
24459
  renameSync2(file, `${file}.corrupt`);
24369
24460
  const ledger = loadUsage(root, id);
24370
24461
  writeJsonAtomic(usageFile(root, id), { ...ledger, entries: [...ledger.entries, entry] });
@@ -24376,11 +24467,11 @@ var bump = (map, key, u) => {
24376
24467
  };
24377
24468
  function wastedReads(root, id) {
24378
24469
  const dir = factoryDir(root, "logs", id);
24379
- if (!existsSync9(dir))
24470
+ if (!existsSync10(dir))
24380
24471
  return snapshotWastedReads(root, id);
24381
24472
  let n = 0;
24382
- for (const f of readdirSync5(dir)) {
24383
- for (const line of readFileSync6(join9(dir, f), "utf8").split(`
24473
+ for (const f of readdirSync6(dir)) {
24474
+ for (const line of readFileSync7(join10(dir, f), "utf8").split(`
24384
24475
  `))
24385
24476
  if (line.includes('"kind":"waste"'))
24386
24477
  n++;
@@ -24389,7 +24480,7 @@ function wastedReads(root, id) {
24389
24480
  }
24390
24481
  function snapshotWastedReads(root, id) {
24391
24482
  const file = artifactFile(root, "usage", `${id}.json`);
24392
- if (!existsSync9(file))
24483
+ if (!existsSync10(file))
24393
24484
  return 0;
24394
24485
  const value = readLedger(file)?.wastedReads;
24395
24486
  return typeof value === "number" ? value : 0;
@@ -24424,15 +24515,15 @@ function summarizeUsage(root, id) {
24424
24515
  function usageFiles(root) {
24425
24516
  const files = new Map;
24426
24517
  for (const dir of [factoryDir(root, "usage"), artifactDir(root, "usage")]) {
24427
- if (!existsSync9(dir))
24518
+ if (!existsSync10(dir))
24428
24519
  continue;
24429
- for (const name of readdirSync5(dir)) {
24520
+ for (const name of readdirSync6(dir)) {
24430
24521
  if (!name.endsWith(".json"))
24431
24522
  continue;
24432
24523
  const id = name.slice(0, -".json".length);
24433
24524
  if (files.has(id))
24434
24525
  continue;
24435
- const file = join9(dir, name);
24526
+ const file = join10(dir, name);
24436
24527
  files.set(id, { id, file, ledger: readLedger(file) });
24437
24528
  }
24438
24529
  }
@@ -24569,8 +24660,8 @@ function usageReport(summary) {
24569
24660
  }
24570
24661
 
24571
24662
  // packages/core/src/pipeline/clarify.ts
24572
- import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "node:fs";
24573
- import { dirname as dirname3, join as join10 } from "node:path";
24663
+ import { existsSync as existsSync11, mkdirSync as mkdirSync5, readFileSync as readFileSync8, writeFileSync as writeFileSync3 } from "node:fs";
24664
+ import { dirname as dirname4, join as join11 } from "node:path";
24574
24665
  var START = "<!-- ai-factory:questions:start -->";
24575
24666
  var END = "<!-- ai-factory:questions:end -->";
24576
24667
  var key = (step, question) => `${step}\x00${question.trim()}`;
@@ -24656,44 +24747,44 @@ function writeClarifications(input) {
24656
24747
  if (input.records.length === 0)
24657
24748
  return;
24658
24749
  const block = renderQuestions(input.records);
24659
- const local = join10(input.root, ".factory", "clarifications", `${input.id}.md`);
24660
- mkdirSync4(dirname3(local), { recursive: true });
24661
- writeFileSync2(local, `# Clarifications: ${input.id}
24750
+ const local = join11(input.root, ".factory", "clarifications", `${input.id}.md`);
24751
+ mkdirSync5(dirname4(local), { recursive: true });
24752
+ writeFileSync3(local, `# Clarifications: ${input.id}
24662
24753
 
24663
24754
  ${block}`);
24664
24755
  if (input.specDir === undefined)
24665
24756
  return;
24666
- const file = join10(input.specDir, "openspec", "changes", input.id, "questions.md");
24667
- mkdirSync4(dirname3(file), { recursive: true });
24668
- const existing = existsSync10(file) ? readFileSync7(file, "utf8") : "";
24669
- writeFileSync2(file, mergeQuestionsBlock(existing, block));
24757
+ const file = join11(input.specDir, "openspec", "changes", input.id, "questions.md");
24758
+ mkdirSync5(dirname4(file), { recursive: true });
24759
+ const existing = existsSync11(file) ? readFileSync8(file, "utf8") : "";
24760
+ writeFileSync3(file, mergeQuestionsBlock(existing, block));
24670
24761
  }
24671
24762
 
24672
24763
  // packages/core/src/pipeline/context.ts
24673
- import { join as join12 } from "node:path";
24764
+ import { join as join13 } from "node:path";
24674
24765
 
24675
24766
  // packages/core/src/events/emitter.ts
24676
- import { existsSync as existsSync12 } from "node:fs";
24767
+ import { existsSync as existsSync13 } from "node:fs";
24677
24768
 
24678
24769
  // packages/core/src/events/jsonl.ts
24679
24770
  import {
24680
24771
  appendFileSync as appendFileSync2,
24681
- existsSync as existsSync11,
24682
- mkdirSync as mkdirSync5,
24683
- readFileSync as readFileSync8,
24772
+ existsSync as existsSync12,
24773
+ mkdirSync as mkdirSync6,
24774
+ readFileSync as readFileSync9,
24684
24775
  rmSync as rmSync6,
24685
- statSync as statSync5,
24776
+ statSync as statSync6,
24686
24777
  truncateSync,
24687
- writeFileSync as writeFileSync3
24778
+ writeFileSync as writeFileSync4
24688
24779
  } from "node:fs";
24689
- import { dirname as dirname4, join as join11 } from "node:path";
24780
+ import { dirname as dirname5, join as join12 } from "node:path";
24690
24781
  function eventLogPath(root, runId) {
24691
24782
  return factoryDir(root, "events", `${runId}.jsonl`);
24692
24783
  }
24693
24784
  function lastCompleteSeq(path) {
24694
- if (!existsSync11(path))
24785
+ if (!existsSync12(path))
24695
24786
  return 0;
24696
- const text = readFileSync8(path, "utf8");
24787
+ const text = readFileSync9(path, "utf8");
24697
24788
  const end = text.lastIndexOf(`
24698
24789
  `);
24699
24790
  if (end === -1)
@@ -24715,13 +24806,13 @@ function lastCompleteSeq(path) {
24715
24806
  function appendTruncatedValue(root, runId, at, json) {
24716
24807
  const date = at.toISOString().slice(0, 10);
24717
24808
  const dir = factoryDir(root, "logs", runId);
24718
- mkdirSync5(dir, { recursive: true });
24719
- const file = join11(dir, `${date}.jsonl`);
24720
- const offset = existsSync11(file) ? statSync5(file).size : 0;
24809
+ mkdirSync6(dir, { recursive: true });
24810
+ const file = join12(dir, `${date}.jsonl`);
24811
+ const offset = existsSync12(file) ? statSync6(file).size : 0;
24721
24812
  appendFileSync2(file, `${json}
24722
24813
  `);
24723
24814
  return {
24724
- path: join11(".factory", "logs", runId, `${date}.jsonl`),
24815
+ path: join12(".factory", "logs", runId, `${date}.jsonl`),
24725
24816
  offset,
24726
24817
  bytes: Buffer.byteLength(json)
24727
24818
  };
@@ -24735,12 +24826,12 @@ class JsonlSink {
24735
24826
  bind(target) {
24736
24827
  this.#root = target.root;
24737
24828
  const file = eventLogPath(this.#root, target.runId);
24738
- mkdirSync5(dirname4(file), { recursive: true });
24739
- if (!existsSync11(file)) {
24740
- writeFileSync3(file, "");
24829
+ mkdirSync6(dirname5(file), { recursive: true });
24830
+ if (!existsSync12(file)) {
24831
+ writeFileSync4(file, "");
24741
24832
  return;
24742
24833
  }
24743
- const text = readFileSync8(file, "utf8");
24834
+ const text = readFileSync9(file, "utf8");
24744
24835
  if (text === "" || text.endsWith(`
24745
24836
  `))
24746
24837
  return;
@@ -24754,7 +24845,7 @@ class JsonlSink {
24754
24845
  }
24755
24846
  write(event) {
24756
24847
  const file = eventLogPath(this.#root, event.runId);
24757
- mkdirSync5(dirname4(file), { recursive: true });
24848
+ mkdirSync6(dirname5(file), { recursive: true });
24758
24849
  appendFileSync2(file, `${JSON.stringify(event)}
24759
24850
  `);
24760
24851
  }
@@ -24877,6 +24968,7 @@ var EVENT_TYPES = [
24877
24968
  "install.failed",
24878
24969
  "question.raised",
24879
24970
  "question.answered",
24971
+ "approval.pending",
24880
24972
  "approval.requested",
24881
24973
  "approval.granted",
24882
24974
  "usage.delta",
@@ -24986,6 +25078,7 @@ var RunEvent = discriminatedUnion("type", [
24986
25078
  event("install.failed", InstallData),
24987
25079
  event("question.raised", QuestionData),
24988
25080
  event("question.answered", QuestionData),
25081
+ event("approval.pending", object({ specHash: string2(), changeDir: string2() })),
24989
25082
  event("approval.requested", object({ specHash: string2(), specCommit: string2() })),
24990
25083
  event("approval.granted", object({ approver: string2(), specHash: string2(), specCommit: string2() })),
24991
25084
  event("usage.delta", object({
@@ -25066,7 +25159,7 @@ class EventEmitter {
25066
25159
  if (this.#runId !== undefined)
25067
25160
  throw new Error(`event emitter is already bound to ${this.#runId}`);
25068
25161
  const path = eventLogPath(this.#root, runId);
25069
- this.#lastSeq = existsSync12(path) ? lastCompleteSeq(path) : 0;
25162
+ this.#lastSeq = existsSync13(path) ? lastCompleteSeq(path) : 0;
25070
25163
  this.#resumed = options.resumed === true && this.#lastSeq > 0;
25071
25164
  this.#runId = runId;
25072
25165
  const target = { root: this.#root, runId, verbosity: this.#verbosity };
@@ -25434,6 +25527,7 @@ class TerminalSink {
25434
25527
  case "phase.changed":
25435
25528
  case "question.raised":
25436
25529
  case "question.answered":
25530
+ case "approval.pending":
25437
25531
  case "approval.requested":
25438
25532
  case "approval.granted":
25439
25533
  case "usage.delta":
@@ -25964,7 +26058,7 @@ class Pipeline {
25964
26058
  return repo;
25965
26059
  }
25966
26060
  repoDir(repo) {
25967
- return join12(this.root, repo.path);
26061
+ return join13(this.root, repo.path);
25968
26062
  }
25969
26063
  out(line) {
25970
26064
  if (this.#bound === undefined)
@@ -26475,7 +26569,7 @@ Report only real mismatches between providers and consumers as findings, with \`
26475
26569
 
26476
26570
  // packages/core/src/pipeline/design.ts
26477
26571
  function specDir(p, draft) {
26478
- return draft === undefined ? p.root : join13(p.root, draft);
26572
+ return draft === undefined ? p.root : join14(p.root, draft);
26479
26573
  }
26480
26574
  function asker(p) {
26481
26575
  return p.config.workflow.refine && p.deps.clarify !== false ? p.deps.ask : undefined;
@@ -26494,7 +26588,7 @@ function slug(text) {
26494
26588
  return words.join("-") || "change";
26495
26589
  }
26496
26590
  function uniqueId(p, wanted) {
26497
- const taken = (id) => loadRun(p.root, id) !== undefined || existsSync13(factoryDir(p.root, "events", `${id}.jsonl`)) || existsSync13(join13(p.root, "openspec", "changes", id)) || existsSync13(join13(p.root, ".factory", "drafts", id));
26591
+ const taken = (id) => loadRun(p.root, id) !== undefined || existsSync14(factoryDir(p.root, "events", `${id}.jsonl`)) || existsSync14(join14(p.root, "openspec", "changes", id)) || existsSync14(join14(p.root, ".factory", "drafts", id));
26498
26592
  let id = wanted;
26499
26593
  for (let n = 2;taken(id); n++)
26500
26594
  id = `${wanted}-${n}`;
@@ -26509,8 +26603,8 @@ async function branchForDesign(p, id) {
26509
26603
  }
26510
26604
  const base = loadRun(p.root, occupiedBy)?.branches["."]?.base ?? await revParse(p.root, "HEAD");
26511
26605
  const draft = `.factory/drafts/${id}`;
26512
- if (!existsSync13(join13(p.root, draft))) {
26513
- const args = await refExists(p.root, `refs/heads/${changeBranch(id)}`) ? ["worktree", "add", "-q", join13(p.root, draft), changeBranch(id)] : ["worktree", "add", "-q", "-b", changeBranch(id), join13(p.root, draft), base];
26606
+ if (!existsSync14(join14(p.root, draft))) {
26607
+ const args = await refExists(p.root, `refs/heads/${changeBranch(id)}`) ? ["worktree", "add", "-q", join14(p.root, draft), changeBranch(id)] : ["worktree", "add", "-q", "-b", changeBranch(id), join14(p.root, draft), base];
26514
26608
  await gitOk(args, { cwd: p.root });
26515
26609
  }
26516
26610
  return { base, draft };
@@ -26728,28 +26822,34 @@ async function design(p, id) {
26728
26822
  });
26729
26823
  if (updated.phase === "paused" && updated.pausedReason !== undefined)
26730
26824
  p.emit("run.paused", { reason: updated.pausedReason });
26825
+ if (updated.phase === "awaiting-approval") {
26826
+ p.emit("approval.pending", {
26827
+ specHash: specHash(dir, id),
26828
+ changeDir: run.draft === undefined ? `openspec/changes/${id}` : `${run.draft}/openspec/changes/${id}`
26829
+ });
26830
+ }
26731
26831
  return { ok: issues.length === 0, issues };
26732
26832
  }
26733
26833
 
26734
26834
  // packages/core/src/update/update.ts
26735
26835
  import {
26736
26836
  cpSync,
26737
- existsSync as existsSync21,
26738
- mkdirSync as mkdirSync8,
26739
- readdirSync as readdirSync7,
26740
- readFileSync as readFileSync16,
26837
+ existsSync as existsSync22,
26838
+ mkdirSync as mkdirSync9,
26839
+ readdirSync as readdirSync8,
26840
+ readFileSync as readFileSync17,
26741
26841
  rmSync as rmSync8,
26742
- writeFileSync as writeFileSync7
26842
+ writeFileSync as writeFileSync8
26743
26843
  } from "node:fs";
26744
- import { dirname as dirname6, join as join24 } from "node:path";
26844
+ import { dirname as dirname7, join as join25 } from "node:path";
26745
26845
 
26746
26846
  // packages/core/src/detect/contracts.ts
26747
- import { readFileSync as readFileSync9 } from "node:fs";
26748
- import { join as join15 } from "node:path";
26847
+ import { readFileSync as readFileSync10 } from "node:fs";
26848
+ import { join as join16 } from "node:path";
26749
26849
 
26750
26850
  // packages/core/src/detect/walk.ts
26751
- import { existsSync as existsSync14, readdirSync as readdirSync6, statSync as statSync6 } from "node:fs";
26752
- import { join as join14 } from "node:path";
26851
+ import { existsSync as existsSync15, readdirSync as readdirSync7, statSync as statSync7 } from "node:fs";
26852
+ import { join as join15 } from "node:path";
26753
26853
  var SKIP_DIRS = new Set([
26754
26854
  ".git",
26755
26855
  "node_modules",
@@ -26774,10 +26874,10 @@ function listFiles(root, options) {
26774
26874
  for (let depth = 0;depth <= options.maxDepth && level.length > 0; depth++) {
26775
26875
  const next = [];
26776
26876
  for (const rel of level) {
26777
- const abs = rel === "" ? root : join14(root, rel);
26877
+ const abs = rel === "" ? root : join15(root, rel);
26778
26878
  let names;
26779
26879
  try {
26780
- names = readdirSync6(abs).sort();
26880
+ names = readdirSync7(abs).sort();
26781
26881
  } catch {
26782
26882
  continue;
26783
26883
  }
@@ -26785,14 +26885,14 @@ function listFiles(root, options) {
26785
26885
  const childRel = rel === "" ? name : `${rel}/${name}`;
26786
26886
  let stat;
26787
26887
  try {
26788
- stat = statSync6(join14(abs, name));
26888
+ stat = statSync7(join15(abs, name));
26789
26889
  } catch {
26790
26890
  continue;
26791
26891
  }
26792
26892
  if (stat.isDirectory()) {
26793
26893
  if (SKIP_DIRS.has(name) || options.skipPaths?.has(childRel))
26794
26894
  continue;
26795
- if (existsSync14(join14(abs, name, ".git")))
26895
+ if (existsSync15(join15(abs, name, ".git")))
26796
26896
  continue;
26797
26897
  next.push(childRel);
26798
26898
  } else if (stat.isFile()) {
@@ -26826,7 +26926,7 @@ var TEXT_FILE = /\.(json|ya?ml|toml|ts|tsx|js|jsx|mjs|cjs|go|py|rs|proto|md|txt|
26826
26926
  var LOCKFILE = /(^|\/)(package-lock\.json|bun\.lockb?|yarn\.lock|pnpm-lock\.yaml|go\.sum|Cargo\.lock|uv\.lock|poetry\.lock)$/;
26827
26927
  function read(root, rel) {
26828
26928
  try {
26829
- return readFileSync9(join15(root, rel), "utf8");
26929
+ return readFileSync10(join16(root, rel), "utf8");
26830
26930
  } catch {
26831
26931
  return;
26832
26932
  }
@@ -26966,12 +27066,12 @@ function contractKey(c) {
26966
27066
  }
26967
27067
 
26968
27068
  // packages/core/src/detect/workspace.ts
26969
- import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
26970
- import { basename, join as join17 } from "node:path";
27069
+ import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
27070
+ import { basename, join as join18 } from "node:path";
26971
27071
 
26972
27072
  // packages/core/src/detect/languages.ts
26973
- import { readFileSync as readFileSync10 } from "node:fs";
26974
- import { join as join16 } from "node:path";
27073
+ import { readFileSync as readFileSync11 } from "node:fs";
27074
+ import { join as join17 } from "node:path";
26975
27075
  var MAX_MANIFEST_BYTES = 256 * 1024;
26976
27076
  var MAX_YAML_CHECKS = 500;
26977
27077
  function sortLanguages(langs) {
@@ -26980,7 +27080,7 @@ function sortLanguages(langs) {
26980
27080
  }
26981
27081
  function readText(root, rel) {
26982
27082
  try {
26983
- return readFileSync10(join16(root, rel), "utf8");
27083
+ return readFileSync11(join17(root, rel), "utf8");
26984
27084
  } catch {
26985
27085
  return;
26986
27086
  }
@@ -27117,22 +27217,22 @@ async function defaultBranchOf(dir) {
27117
27217
  return current.code === 0 && branch !== "" ? branch : undefined;
27118
27218
  }
27119
27219
  function isInitialized(dir) {
27120
- return existsSync15(join17(dir, ".git"));
27220
+ return existsSync16(join18(dir, ".git"));
27121
27221
  }
27122
27222
  function readScripts(dir) {
27123
27223
  try {
27124
- const pkg = JSON.parse(readFileSync11(join17(dir, "package.json"), "utf8"));
27224
+ const pkg = JSON.parse(readFileSync12(join18(dir, "package.json"), "utf8"));
27125
27225
  return Object.fromEntries(Object.entries(pkg.scripts ?? {}).filter((entry) => typeof entry[1] === "string"));
27126
27226
  } catch {
27127
27227
  return {};
27128
27228
  }
27129
27229
  }
27130
27230
  function packageRunner(dir) {
27131
- if (existsSync15(join17(dir, "bun.lock")) || existsSync15(join17(dir, "bun.lockb")))
27231
+ if (existsSync16(join18(dir, "bun.lock")) || existsSync16(join18(dir, "bun.lockb")))
27132
27232
  return "bun run";
27133
- if (existsSync15(join17(dir, "pnpm-lock.yaml")))
27233
+ if (existsSync16(join18(dir, "pnpm-lock.yaml")))
27134
27234
  return "pnpm run";
27135
- if (existsSync15(join17(dir, "yarn.lock")))
27235
+ if (existsSync16(join18(dir, "yarn.lock")))
27136
27236
  return "yarn";
27137
27237
  return "npm run";
27138
27238
  }
@@ -27143,11 +27243,11 @@ function e2eScript(dir) {
27143
27243
  }
27144
27244
  function taskNames(dir) {
27145
27245
  for (const file of ["Taskfile.yml", "Taskfile.yaml"]) {
27146
- const path = join17(dir, file);
27147
- if (!existsSync15(path))
27246
+ const path = join18(dir, file);
27247
+ if (!existsSync16(path))
27148
27248
  continue;
27149
27249
  try {
27150
- const doc = $parse(readFileSync11(path, "utf8"), { logLevel: "silent" });
27250
+ const doc = $parse(readFileSync12(path, "utf8"), { logLevel: "silent" });
27151
27251
  return Object.keys(doc?.tasks ?? {}).sort();
27152
27252
  } catch {
27153
27253
  return [];
@@ -27162,10 +27262,10 @@ function readInstructions(dir) {
27162
27262
  ".opencode/opencode.json",
27163
27263
  ".opencode/opencode.jsonc"
27164
27264
  ]) {
27165
- if (!existsSync15(join17(dir, file)))
27265
+ if (!existsSync16(join18(dir, file)))
27166
27266
  continue;
27167
27267
  try {
27168
- const text = readFileSync11(join17(dir, file), "utf8");
27268
+ const text = readFileSync12(join18(dir, file), "utf8");
27169
27269
  const value = parseJsonc(text).value;
27170
27270
  const list = Array.isArray(value?.instructions) ? value.instructions : [];
27171
27271
  return list.filter((v) => typeof v === "string" && !v.startsWith("/") && !v.startsWith("~") && !v.includes("://") && !v.split("/").includes(".."));
@@ -27193,7 +27293,7 @@ async function detectWorkspace(root) {
27193
27293
  };
27194
27294
  const e2e = [];
27195
27295
  const tasks = [];
27196
- const submodules = existsSync15(join17(root, ".gitmodules")) ? await readSubmodules(root) : [];
27296
+ const submodules = existsSync16(join18(root, ".gitmodules")) ? await readSubmodules(root) : [];
27197
27297
  const layout = submodules.length > 0 ? "submodules" : "single";
27198
27298
  if (layout === "single") {
27199
27299
  const files = listFiles(root, WALK);
@@ -27211,7 +27311,7 @@ async function detectWorkspace(root) {
27211
27311
  taken.add("ai");
27212
27312
  repos.push({ name: "ai", path: ".", role: "orchestration", languages: [], initialized: true });
27213
27313
  for (const sub of submodules) {
27214
- const dir = join17(root, sub.path);
27314
+ const dir = join18(root, sub.path);
27215
27315
  const name = uniqueName(repoNameFrom(sub.path), taken);
27216
27316
  if (!isInitialized(dir)) {
27217
27317
  notes.push(`submodule ${sub.path} is not initialised; languages unknown (run \`git submodule update --init ${sub.path}\`)`);
@@ -27345,8 +27445,8 @@ function formatChange(change) {
27345
27445
  }
27346
27446
 
27347
27447
  // packages/core/src/lock/lock.ts
27348
- import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
27349
- import { join as join18 } from "node:path";
27448
+ import { existsSync as existsSync17, readFileSync as readFileSync13 } from "node:fs";
27449
+ import { join as join19 } from "node:path";
27350
27450
  var LOCK_FILE = "factory.lock.json";
27351
27451
  var LOCK_VERSION = 1;
27352
27452
  var LockEntry = strictObject({
@@ -27394,12 +27494,12 @@ function serializeLock(lock) {
27394
27494
  `;
27395
27495
  }
27396
27496
  function readLock(root) {
27397
- const file = join18(root, LOCK_FILE);
27398
- if (!existsSync16(file))
27497
+ const file = join19(root, LOCK_FILE);
27498
+ if (!existsSync17(file))
27399
27499
  return;
27400
27500
  let value;
27401
27501
  try {
27402
- value = JSON.parse(readFileSync12(file, "utf8"));
27502
+ value = JSON.parse(readFileSync13(file, "utf8"));
27403
27503
  } catch (err) {
27404
27504
  throw new ConfigError(`${LOCK_FILE} is not valid JSON`, [String(err)]);
27405
27505
  }
@@ -27506,8 +27606,8 @@ function migrateConfigText(text, migrations = MIGRATIONS) {
27506
27606
  }
27507
27607
 
27508
27608
  // packages/core/src/workspace/sync.ts
27509
- import { existsSync as existsSync20, writeFileSync as writeFileSync6 } from "node:fs";
27510
- import { join as join23 } from "node:path";
27609
+ import { existsSync as existsSync21, writeFileSync as writeFileSync7 } from "node:fs";
27610
+ import { join as join24 } from "node:path";
27511
27611
 
27512
27612
  // templates/addons/ponytail/.opencode/command/ponytail-review.md
27513
27613
  var ponytail_review_default = `---
@@ -27749,11 +27849,11 @@ The add-on above is advice about writing less code. Where it conflicts with the
27749
27849
  `;
27750
27850
 
27751
27851
  // packages/core/src/addons/hash.ts
27752
- import { createHash } from "node:crypto";
27852
+ import { createHash as createHash2 } from "node:crypto";
27753
27853
  function contentHash(files) {
27754
- const lines = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).map((f) => `${createHash("sha256").update(f.content).digest("hex")} ${f.path}
27854
+ const lines = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0).map((f) => `${createHash2("sha256").update(f.content).digest("hex")} ${f.path}
27755
27855
  `).join("");
27756
- return createHash("sha256").update(lines).digest("hex");
27856
+ return createHash2("sha256").update(lines).digest("hex");
27757
27857
  }
27758
27858
  function isText(bytes) {
27759
27859
  if (bytes.includes(0))
@@ -27845,8 +27945,8 @@ ${reviewChecklist()}`, REVIEWER_MAPPING);
27845
27945
  }
27846
27946
 
27847
27947
  // packages/core/src/git/commit.ts
27848
- import { existsSync as existsSync17 } from "node:fs";
27849
- import { join as join19 } from "node:path";
27948
+ import { existsSync as existsSync18 } from "node:fs";
27949
+ import { join as join20 } from "node:path";
27850
27950
  var TYPE_BY_VERB = [
27851
27951
  [/^(fix|correct|repair|resolve|handle)\b/i, "fix"],
27852
27952
  [/^(test|cover|verify)\b/i, "test"],
@@ -27889,7 +27989,7 @@ async function commitAll(dir, subject, trailers = {}) {
27889
27989
  async function commitPaths(dir, paths, subject, trailers = {}) {
27890
27990
  const usable = [];
27891
27991
  for (const p of paths) {
27892
- if (existsSync17(join19(dir, p)) || (await git(["ls-files", "--error-unmatch", "--", p], { cwd: dir })).code === 0)
27992
+ if (existsSync18(join20(dir, p)) || (await git(["ls-files", "--error-unmatch", "--", p], { cwd: dir })).code === 0)
27893
27993
  usable.push(p);
27894
27994
  }
27895
27995
  if (usable.length === 0)
@@ -27910,8 +28010,8 @@ function commitTask(worktree, id, task, title, type, style = {}) {
27910
28010
  }
27911
28011
 
27912
28012
  // packages/core/src/git/hooks.ts
27913
- import { chmodSync, existsSync as existsSync18, mkdirSync as mkdirSync6, readFileSync as readFileSync13, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
27914
- import { join as join20, relative as relative5 } from "node:path";
28013
+ import { chmodSync, existsSync as existsSync19, mkdirSync as mkdirSync7, readFileSync as readFileSync14, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "node:fs";
28014
+ import { join as join21, relative as relative5 } from "node:path";
27915
28015
  var HOOK_MARKER = "# ai-factory-hook v1";
27916
28016
  var CHAINED_HOOK = "pre-push.ai-factory-chained";
27917
28017
  var AGENT_MARKER_ENV = "AI_FACTORY_AGENT";
@@ -27939,7 +28039,7 @@ async function hooksDir(repoDir) {
27939
28039
  return { hooks, common };
27940
28040
  }
27941
28041
  async function installPrePush(repoDir) {
27942
- if (!existsSync18(join20(repoDir, ".git"))) {
28042
+ if (!existsSync19(join21(repoDir, ".git"))) {
27943
28043
  return { status: "skipped", reason: "not a checked-out git repository" };
27944
28044
  }
27945
28045
  const { hooks, common } = await hooksDir(repoDir);
@@ -27950,18 +28050,18 @@ async function installPrePush(repoDir) {
27950
28050
  reason: `core.hooksPath points outside .git (${hooks}); agents are still blocked by the git environment`
27951
28051
  };
27952
28052
  }
27953
- mkdirSync6(hooks, { recursive: true });
27954
- const path = join20(hooks, "pre-push");
28053
+ mkdirSync7(hooks, { recursive: true });
28054
+ const path = join21(hooks, "pre-push");
27955
28055
  let status = "installed";
27956
- if (existsSync18(path)) {
27957
- const current = readFileSync13(path, "utf8");
28056
+ if (existsSync19(path)) {
28057
+ const current = readFileSync14(path, "utf8");
27958
28058
  if (current === PRE_PUSH_HOOK)
27959
28059
  return { status: "unchanged", path };
27960
28060
  if (current.includes(HOOK_MARKER)) {
27961
28061
  status = "updated";
27962
28062
  } else {
27963
- const chained = join20(hooks, CHAINED_HOOK);
27964
- if (existsSync18(chained)) {
28063
+ const chained = join21(hooks, CHAINED_HOOK);
28064
+ if (existsSync19(chained)) {
27965
28065
  return {
27966
28066
  status: "skipped",
27967
28067
  reason: `both pre-push and ${CHAINED_HOOK} exist; resolve by hand`
@@ -27971,7 +28071,7 @@ async function installPrePush(repoDir) {
27971
28071
  status = "chained";
27972
28072
  }
27973
28073
  }
27974
- writeFileSync4(path, PRE_PUSH_HOOK);
28074
+ writeFileSync5(path, PRE_PUSH_HOOK);
27975
28075
  chmodSync(path, 493);
27976
28076
  return { status, path };
27977
28077
  }
@@ -27980,10 +28080,10 @@ async function prePushState(repoDir) {
27980
28080
  const rel = relative5(common, hooks);
27981
28081
  if (rel.startsWith("..") || rel.startsWith("/"))
27982
28082
  return "foreign-hooks-path";
27983
- const path = join20(hooks, "pre-push");
27984
- if (!existsSync18(path))
28083
+ const path = join21(hooks, "pre-push");
28084
+ if (!existsSync19(path))
27985
28085
  return "missing";
27986
- const text = readFileSync13(path, "utf8");
28086
+ const text = readFileSync14(path, "utf8");
27987
28087
  if (text === PRE_PUSH_HOOK)
27988
28088
  return "installed";
27989
28089
  return text.includes("# ai-factory-hook") ? "outdated" : "missing";
@@ -28000,23 +28100,23 @@ function agentGitEnv(base = process.env) {
28000
28100
  }
28001
28101
 
28002
28102
  // packages/core/src/managed/sync.ts
28003
- import { createHash as createHash2 } from "node:crypto";
28103
+ import { createHash as createHash3 } from "node:crypto";
28004
28104
  import {
28005
- existsSync as existsSync19,
28006
- mkdirSync as mkdirSync7,
28105
+ existsSync as existsSync20,
28106
+ mkdirSync as mkdirSync8,
28007
28107
  mkdtempSync as mkdtempSync2,
28008
- readFileSync as readFileSync15,
28108
+ readFileSync as readFileSync16,
28009
28109
  renameSync as renameSync4,
28010
28110
  rmSync as rmSync7,
28011
- writeFileSync as writeFileSync5
28111
+ writeFileSync as writeFileSync6
28012
28112
  } from "node:fs";
28013
28113
  import { tmpdir as tmpdir2 } from "node:os";
28014
- import { dirname as dirname5, join as join22, resolve as resolve2 } from "node:path";
28114
+ import { dirname as dirname6, join as join23, resolve as resolve2 } from "node:path";
28015
28115
  import { deflateSync } from "node:zlib";
28016
28116
 
28017
28117
  // packages/core/src/render/workspace.ts
28018
- import { readFileSync as readFileSync14 } from "node:fs";
28019
- import { join as join21 } from "node:path";
28118
+ import { readFileSync as readFileSync15 } from "node:fs";
28119
+ import { join as join22 } from "node:path";
28020
28120
 
28021
28121
  // templates/agents/architect.md
28022
28122
  var architect_default = `# Role: architect
@@ -33159,7 +33259,7 @@ function renderImplementer(config, repo) {
33159
33259
  function renderCustomAgent(config, agent, root) {
33160
33260
  const role = ROLE_FOR_PHASE[agent.phase] ?? "implementer";
33161
33261
  const agentRole = agent.phase;
33162
- const body = agent.prompt ?? (agent.promptFile !== undefined && root !== undefined ? readFileSync14(join21(root, agent.promptFile), "utf8") : `# Role: ${agent.id}
33262
+ const body = agent.prompt ?? (agent.promptFile !== undefined && root !== undefined ? readFileSync15(join22(root, agent.promptFile), "utf8") : `# Role: ${agent.id}
33163
33263
 
33164
33264
  ${agent.description}`);
33165
33265
  const skills = skillsSection(agent.skills);
@@ -33361,7 +33461,7 @@ function renderWorkspace(config, options = {}) {
33361
33461
 
33362
33462
  // packages/core/src/managed/sync.ts
33363
33463
  function sha256(text) {
33364
- return createHash2("sha256").update(text, "utf8").digest("hex");
33464
+ return createHash3("sha256").update(text, "utf8").digest("hex");
33365
33465
  }
33366
33466
  function markersFor(path) {
33367
33467
  const markers = BLOCK_MARKERS[path.slice(path.lastIndexOf("/") + 1)];
@@ -33379,10 +33479,10 @@ function findBlock(text, markers) {
33379
33479
  return { start, end: endMarker + markers.end.length };
33380
33480
  }
33381
33481
  function readOptional(abs) {
33382
- return existsSync19(abs) ? readFileSync15(abs, "utf8") : undefined;
33482
+ return existsSync20(abs) ? readFileSync16(abs, "utf8") : undefined;
33383
33483
  }
33384
33484
  function currentOwned(root, path, mode) {
33385
- const text = readOptional(join22(root, path));
33485
+ const text = readOptional(join23(root, path));
33386
33486
  if (text === undefined || mode === "file")
33387
33487
  return text;
33388
33488
  const block = findBlock(text, markersFor(path));
@@ -33427,9 +33527,9 @@ function planSync(root, files, previous, options) {
33427
33527
  return plan.sort((a, b) => a.path.localeCompare(b.path));
33428
33528
  }
33429
33529
  function writeAtomic(abs, text) {
33430
- mkdirSync7(dirname5(abs), { recursive: true });
33530
+ mkdirSync8(dirname6(abs), { recursive: true });
33431
33531
  const tmp = `${abs}.ai-factory-tmp`;
33432
- writeFileSync5(tmp, text);
33532
+ writeFileSync6(tmp, text);
33433
33533
  renameSync4(tmp, abs);
33434
33534
  }
33435
33535
  function writeBlock(abs, path, block) {
@@ -33450,12 +33550,12 @@ ${block}
33450
33550
  writeAtomic(abs, next);
33451
33551
  }
33452
33552
  function removeOwned(root, path, mode) {
33453
- const abs = join22(root, path);
33553
+ const abs = join23(root, path);
33454
33554
  if (mode === "file") {
33455
33555
  rmSync7(abs, { force: true });
33456
33556
  return;
33457
33557
  }
33458
- const text = readFileSync15(abs, "utf8");
33558
+ const text = readFileSync16(abs, "utf8");
33459
33559
  const range = findBlock(text, markersFor(path));
33460
33560
  if (range === undefined)
33461
33561
  return;
@@ -33490,12 +33590,12 @@ class BlobStore {
33490
33590
  }
33491
33591
  const body = Buffer.from(content, "utf8");
33492
33592
  const header = Buffer.from(`blob ${body.length}\x00`, "utf8");
33493
- const oid = createHash2("sha1").update(header).update(body).digest("hex");
33494
- const file = join22(dir, oid.slice(0, 2), oid.slice(2));
33495
- if (!existsSync19(file)) {
33496
- mkdirSync7(dirname5(file), { recursive: true });
33497
- const tmp = join22(dir, `tmp_loomwright_${process.pid}_${this.#seq++}`);
33498
- writeFileSync5(tmp, deflateSync(Buffer.concat([header, body])));
33593
+ const oid = createHash3("sha1").update(header).update(body).digest("hex");
33594
+ const file = join23(dir, oid.slice(0, 2), oid.slice(2));
33595
+ if (!existsSync20(file)) {
33596
+ mkdirSync8(dirname6(file), { recursive: true });
33597
+ const tmp = join23(dir, `tmp_loomwright_${process.pid}_${this.#seq++}`);
33598
+ writeFileSync6(tmp, deflateSync(Buffer.concat([header, body])));
33499
33599
  renameSync4(tmp, file);
33500
33600
  }
33501
33601
  return oid;
@@ -33506,12 +33606,12 @@ async function blobText(root, blob) {
33506
33606
  return res.code === 0 ? res.stdout : undefined;
33507
33607
  }
33508
33608
  async function mergeThree(root, ours, base, theirs) {
33509
- const dir = mkdtempSync2(join22(tmpdir2(), "ai-factory-merge-"));
33609
+ const dir = mkdtempSync2(join23(tmpdir2(), "ai-factory-merge-"));
33510
33610
  try {
33511
- const files = { ours: join22(dir, "ours"), base: join22(dir, "base"), theirs: join22(dir, "theirs") };
33512
- writeFileSync5(files.ours, ours);
33513
- writeFileSync5(files.base, base);
33514
- writeFileSync5(files.theirs, theirs);
33611
+ const files = { ours: join23(dir, "ours"), base: join23(dir, "base"), theirs: join23(dir, "theirs") };
33612
+ writeFileSync6(files.ours, ours);
33613
+ writeFileSync6(files.base, base);
33614
+ writeFileSync6(files.theirs, theirs);
33515
33615
  const res = await exec([
33516
33616
  "git",
33517
33617
  "merge-file",
@@ -33556,7 +33656,7 @@ async function executeSync(root, plan, previous, options = {}) {
33556
33656
  if (file === undefined)
33557
33657
  throw new Error(`no render for ${change.path}`);
33558
33658
  if (change.action !== "unchanged") {
33559
- const abs = join22(root, file.path);
33659
+ const abs = join23(root, file.path);
33560
33660
  if (file.mode === "block")
33561
33661
  writeBlock(abs, file.path, file.content);
33562
33662
  else
@@ -33574,7 +33674,7 @@ async function executeSync(root, plan, previous, options = {}) {
33574
33674
  break;
33575
33675
  }
33576
33676
  const result = await mergeThree(root, ours, base, file.content);
33577
- const abs = join22(root, file.path);
33677
+ const abs = join23(root, file.path);
33578
33678
  if (file.mode === "block")
33579
33679
  writeBlock(abs, file.path, result.text.replace(/\n$/, ""));
33580
33680
  else
@@ -33689,10 +33789,10 @@ async function syncWorkspace(root, config, options = {}) {
33689
33789
  files: [...PONYTAIL.files]
33690
33790
  }
33691
33791
  } : {}, opencodeRequirement(config)?.min ?? OPENCODE.min);
33692
- writeFileSync6(join23(root, LOCK_FILE), serializeLock(lock));
33792
+ writeFileSync7(join24(root, LOCK_FILE), serializeLock(lock));
33693
33793
  const hooks = [];
33694
33794
  for (const repo of config.repos) {
33695
- hooks.push({ repo: repo.name, result: await installPrePush(join23(root, repo.path)) });
33795
+ hooks.push({ repo: repo.name, result: await installPrePush(join24(root, repo.path)) });
33696
33796
  }
33697
33797
  return { plan, lock, hooks, merged, conflicts };
33698
33798
  }
@@ -33704,7 +33804,7 @@ async function dirtyInstallPaths(root, ignore = []) {
33704
33804
  `).filter((l) => l.trim() !== "").map((l) => l.slice(3)).filter((p) => !ignore.includes(p));
33705
33805
  }
33706
33806
  function commitInstall(root, message) {
33707
- return commitPaths(root, INSTALL_PATHS.filter((p) => existsSync20(join23(root, p))), message);
33807
+ return commitPaths(root, INSTALL_PATHS.filter((p) => existsSync21(join24(root, p))), message);
33708
33808
  }
33709
33809
 
33710
33810
  // packages/core/src/update/update.ts
@@ -33740,7 +33840,7 @@ function changesInProgress(root) {
33740
33840
  return [...ids].sort();
33741
33841
  }
33742
33842
  async function planUpdate(root, lock, options) {
33743
- const original = readFileSync16(join24(root, CONFIG_FILE), "utf8");
33843
+ const original = readFileSync17(join25(root, CONFIG_FILE), "utf8");
33744
33844
  const migration = migrateConfigText(original);
33745
33845
  const config = parseConfigText(migration.text, CONFIG_FILE);
33746
33846
  const plan = planWorkspace(root, config, {
@@ -33800,20 +33900,20 @@ function formatPlan(plan) {
33800
33900
  var backupsDir = (root) => factoryDir(root, "backups");
33801
33901
  function backup(root, plan) {
33802
33902
  const stamp = new Date().toISOString().replace(/[:.]/g, "-");
33803
- const dir = join24(backupsDir(root), stamp);
33903
+ const dir = join25(backupsDir(root), stamp);
33804
33904
  const files = [];
33805
33905
  const created = [];
33806
33906
  for (const rel of plan.touched) {
33807
- const abs = join24(root, rel);
33808
- if (!existsSync21(abs)) {
33907
+ const abs = join25(root, rel);
33908
+ if (!existsSync22(abs)) {
33809
33909
  created.push(rel);
33810
33910
  continue;
33811
33911
  }
33812
- mkdirSync8(dirname6(join24(dir, "files", rel)), { recursive: true });
33813
- cpSync(abs, join24(dir, "files", rel), { recursive: true });
33912
+ mkdirSync9(dirname7(join25(dir, "files", rel)), { recursive: true });
33913
+ cpSync(abs, join25(dir, "files", rel), { recursive: true });
33814
33914
  files.push(rel);
33815
33915
  }
33816
- writeJsonAtomic(join24(dir, "manifest.json"), {
33916
+ writeJsonAtomic(join25(dir, "manifest.json"), {
33817
33917
  at: new Date().toISOString(),
33818
33918
  fromVersion: plan.fromVersion,
33819
33919
  toVersion: plan.toVersion,
@@ -33824,28 +33924,28 @@ function backup(root, plan) {
33824
33924
  }
33825
33925
  function latestBackup(root) {
33826
33926
  const base = backupsDir(root);
33827
- if (!existsSync21(base))
33927
+ if (!existsSync22(base))
33828
33928
  return;
33829
- for (const name of readdirSync7(base).sort().reverse()) {
33830
- const file = join24(base, name, "manifest.json");
33831
- if (!existsSync21(file))
33929
+ for (const name of readdirSync8(base).sort().reverse()) {
33930
+ const file = join25(base, name, "manifest.json");
33931
+ if (!existsSync22(file))
33832
33932
  continue;
33833
- const manifest = JSON.parse(readFileSync16(file, "utf8"));
33933
+ const manifest = JSON.parse(readFileSync17(file, "utf8"));
33834
33934
  if (!manifest.restored)
33835
- return { dir: join24(base, name), manifest };
33935
+ return { dir: join25(base, name), manifest };
33836
33936
  }
33837
33937
  return;
33838
33938
  }
33839
33939
  async function restoreBackup(root, dir, manifest) {
33840
33940
  for (const rel of manifest.created)
33841
- rmSync8(join24(root, rel), { recursive: true, force: true });
33941
+ rmSync8(join25(root, rel), { recursive: true, force: true });
33842
33942
  for (const rel of manifest.files) {
33843
- const target = join24(root, rel);
33943
+ const target = join25(root, rel);
33844
33944
  rmSync8(target, { recursive: true, force: true });
33845
- mkdirSync8(dirname6(target), { recursive: true });
33846
- cpSync(join24(dir, "files", rel), target, { recursive: true });
33945
+ mkdirSync9(dirname7(target), { recursive: true });
33946
+ cpSync(join25(dir, "files", rel), target, { recursive: true });
33847
33947
  }
33848
- writeFileSync7(join24(dir, "manifest.json"), `${JSON.stringify({ ...manifest, restored: true }, null, 2)}
33948
+ writeFileSync8(join25(dir, "manifest.json"), `${JSON.stringify({ ...manifest, restored: true }, null, 2)}
33849
33949
  `);
33850
33950
  return [...manifest.files, ...manifest.created];
33851
33951
  }
@@ -33882,8 +33982,8 @@ import { existsSync as existsSync36, readdirSync as readdirSync14 } from "node:f
33882
33982
  import { join as join47, relative as relative9 } from "node:path";
33883
33983
 
33884
33984
  // packages/core/src/events/inbox.ts
33885
- import { readdirSync as readdirSync8, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
33886
- import { join as join25 } from "node:path";
33985
+ import { readdirSync as readdirSync9, readFileSync as readFileSync18, rmSync as rmSync9 } from "node:fs";
33986
+ import { join as join26 } from "node:path";
33887
33987
  var commandsDir = (root, runId) => factoryDir(root, "commands", runId);
33888
33988
  function writeCommand(root, command) {
33889
33989
  const parsed = Command.parse(command);
@@ -33896,7 +33996,7 @@ function readCommands(root, runId) {
33896
33996
  const dir = commandsDir(root, runId);
33897
33997
  let names;
33898
33998
  try {
33899
- names = readdirSync8(dir);
33999
+ names = readdirSync9(dir);
33900
34000
  } catch (err) {
33901
34001
  if (isMissing(err))
33902
34002
  return [];
@@ -33904,10 +34004,10 @@ function readCommands(root, runId) {
33904
34004
  }
33905
34005
  const files = [];
33906
34006
  for (const name of names.filter((n) => n.endsWith(".json")).sort()) {
33907
- const file = join25(dir, name);
34007
+ const file = join26(dir, name);
33908
34008
  let raw;
33909
34009
  try {
33910
- raw = JSON.parse(readFileSync17(file, "utf8"));
34010
+ raw = JSON.parse(readFileSync18(file, "utf8"));
33911
34011
  } catch (err) {
33912
34012
  files.push({ file, error: err instanceof Error ? err.message : String(err) });
33913
34013
  continue;
@@ -33939,14 +34039,14 @@ function reportCommandProblem(pipeline, line) {
33939
34039
  }
33940
34040
 
33941
34041
  // packages/core/src/events/reader.ts
33942
- import { readFileSync as readFileSync18 } from "node:fs";
34042
+ import { readFileSync as readFileSync19 } from "node:fs";
33943
34043
  var isMissingFile = (err) => typeof err === "object" && err !== null && ("code" in err) && err.code === "ENOENT";
33944
34044
  var isEmpty = (value) => value.trim() === "";
33945
34045
  function readEventLines(root, runId) {
33946
34046
  const path = eventLogPath(root, runId);
33947
34047
  let text;
33948
34048
  try {
33949
- text = readFileSync18(path, "utf8");
34049
+ text = readFileSync19(path, "utf8");
33950
34050
  } catch (err) {
33951
34051
  if (isMissingFile(err))
33952
34052
  return { lines: [], missing: [], skipped: [] };
@@ -34174,97 +34274,6 @@ async function* tailEvents(root, runId, options = {}) {
34174
34274
  import { existsSync as existsSync24, readFileSync as readFileSync21 } from "node:fs";
34175
34275
  import { join as join28 } from "node:path";
34176
34276
 
34177
- // packages/core/src/approval/approval.ts
34178
- import { createHash as createHash3 } from "node:crypto";
34179
- import { existsSync as existsSync22, mkdirSync as mkdirSync9, readdirSync as readdirSync9, readFileSync as readFileSync19, statSync as statSync7, writeFileSync as writeFileSync8 } from "node:fs";
34180
- import { dirname as dirname7, join as join26 } from "node:path";
34181
- function parseApproval(value) {
34182
- if (typeof value !== "object" || value === null)
34183
- return;
34184
- const v = value;
34185
- const ok = typeof v.changeId === "string" && typeof v.approver === "string" && typeof v.specCommit === "string" && /^[0-9a-f]{40,64}$/.test(v.specCommit) && typeof v.hash === "string" && /^[0-9a-f]{64}$/.test(v.hash) && typeof v.approvedAt === "string";
34186
- if (!ok)
34187
- return;
34188
- if (v.history !== undefined) {
34189
- if (!Array.isArray(v.history))
34190
- return;
34191
- for (const entry of v.history) {
34192
- if (typeof entry !== "object" || entry === null)
34193
- return;
34194
- const e = entry;
34195
- if (typeof e.hash !== "string" || !/^[0-9a-f]{64}$/.test(e.hash) || typeof e.specCommit !== "string" || !/^[0-9a-f]{40,64}$/.test(e.specCommit) || typeof e.at !== "string" || typeof e.reason !== "string")
34196
- return;
34197
- }
34198
- }
34199
- return value;
34200
- }
34201
- var changeDir = (root, id) => join26(root, "openspec", "changes", id);
34202
- var approvalFile = (root, id) => join26(root, ".factory", "approvals", `${id}.json`);
34203
- function writeApproval(root, approval) {
34204
- const file = approvalFile(root, approval.changeId);
34205
- mkdirSync9(dirname7(file), { recursive: true });
34206
- writeFileSync8(file, `${JSON.stringify(approval, null, 2)}
34207
- `);
34208
- return file;
34209
- }
34210
- function isSpecPath(file) {
34211
- if (file === undefined)
34212
- return false;
34213
- const raw = file.replace(/\\/g, "/").replace(/^\.\//, "");
34214
- const parts = raw.split("/");
34215
- if (parts[0]?.toLowerCase() === "openspec")
34216
- return true;
34217
- return raw.startsWith("/") && parts.some((part) => part.toLowerCase() === "openspec");
34218
- }
34219
- function filesUnder(dir, prefix = "") {
34220
- if (!existsSync22(dir))
34221
- return [];
34222
- return readdirSync9(dir).sort().flatMap((name) => {
34223
- const rel = prefix === "" ? name : `${prefix}/${name}`;
34224
- const abs = join26(dir, name);
34225
- return statSync7(abs).isDirectory() ? filesUnder(abs, rel) : [rel];
34226
- });
34227
- }
34228
- function approvedFiles(root, id) {
34229
- const dir = changeDir(root, id);
34230
- const top = ["proposal.md", "design.md", "tasks.md"].filter((f) => existsSync22(join26(dir, f)));
34231
- const specs = filesUnder(join26(dir, "specs"), "specs").filter((f) => f.endsWith(".md"));
34232
- return [...top, ...specs].sort();
34233
- }
34234
- function specHash(root, id) {
34235
- const hash = createHash3("sha256");
34236
- const dir = changeDir(root, id);
34237
- for (const rel of approvedFiles(root, id)) {
34238
- let content = readFileSync19(join26(dir, rel), "utf8").replace(/\r\n/g, `
34239
- `);
34240
- if (rel === "tasks.md")
34241
- content = normalizeCheckboxes(content);
34242
- hash.update(rel).update("\x00").update(content).update("\x00");
34243
- }
34244
- return hash.digest("hex");
34245
- }
34246
- function readApproval(root, id) {
34247
- const file = approvalFile(root, id);
34248
- if (!existsSync22(file))
34249
- return;
34250
- try {
34251
- return parseApproval(JSON.parse(readFileSync19(file, "utf8")));
34252
- } catch {
34253
- return;
34254
- }
34255
- }
34256
- function checkApprovalHash(root, id) {
34257
- const approval = readApproval(root, id);
34258
- if (approval === undefined)
34259
- return { valid: false, reason: `change ${id} is not approved` };
34260
- if (approvedFiles(root, id).length === 0)
34261
- return { valid: false, reason: `change ${id} has no spec files` };
34262
- if (specHash(root, id) !== approval.hash) {
34263
- return { valid: false, reason: `the spec of ${id} changed after approval; approve it again` };
34264
- }
34265
- return { valid: true, approval };
34266
- }
34267
-
34268
34277
  // packages/core/src/update/snapshot.ts
34269
34278
  import { cpSync as cpSync2, existsSync as existsSync23, mkdirSync as mkdirSync10, readdirSync as readdirSync10, readFileSync as readFileSync20, rmSync as rmSync10 } from "node:fs";
34270
34279
  import { join as join27 } from "node:path";
@@ -44845,6 +44854,102 @@ that were cancelled because of it. Continue the change with \`loomwright resume
44845
44854
  }
44846
44855
  };
44847
44856
 
44857
+ // packages/cli/src/commands/tui.ts
44858
+ import { accessSync, constants, existsSync as existsSync49, statSync as statSync12 } from "node:fs";
44859
+ import { resolve as resolve9 } from "node:path";
44860
+ import { fileURLToPath } from "node:url";
44861
+
44862
+ // packages/tui/src/strings.ts
44863
+ var TUI_SUMMARY = "Watch and drive runs in the terminal";
44864
+ function tuiHelp() {
44865
+ return `Usage: loomwright tui [--replay <file>] [--once] [--ascii]
44866
+
44867
+ Watch and drive runs in the terminal. On a terminal the run list opens, newest first.
44868
+ Without a terminal use \`status --watch\` or \`events --follow\` instead.
44869
+
44870
+ --replay <file> Render a recorded event stream instead of a workspace
44871
+ --once Render one frame and exit (requires --replay)
44872
+ --ascii Force the ASCII glyph set
44873
+
44874
+ Exit codes: 0 ok, 2 invalid flags or an unreadable --replay file.`;
44875
+ }
44876
+
44877
+ // packages/cli/src/commands/tui.ts
44878
+ var TUI_OPTIONS = {
44879
+ replay: {
44880
+ type: "string",
44881
+ description: "Render a recorded event stream instead of a workspace",
44882
+ complete: "file"
44883
+ },
44884
+ once: {
44885
+ type: "boolean",
44886
+ default: false,
44887
+ description: "Render one frame and exit"
44888
+ },
44889
+ ascii: {
44890
+ type: "boolean",
44891
+ default: false,
44892
+ description: "Force the ASCII glyph set"
44893
+ }
44894
+ };
44895
+ async function loadTui() {
44896
+ const sibling = new URL("./tui.js", import.meta.url);
44897
+ if (existsSync49(fileURLToPath(sibling))) {
44898
+ const href = sibling.href;
44899
+ return await import(href);
44900
+ }
44901
+ const specifier = "@loomwright/tui/entry";
44902
+ return await import(specifier);
44903
+ }
44904
+ var tuiCommand = {
44905
+ name: "tui",
44906
+ summary: TUI_SUMMARY,
44907
+ options: TUI_OPTIONS,
44908
+ help: tuiHelp(),
44909
+ async run(args, io) {
44910
+ const { values } = parseCommandArgs("tui", args, TUI_OPTIONS);
44911
+ const replay = typeof values.replay === "string" ? values.replay : undefined;
44912
+ const once = values.once === true;
44913
+ const ascii = values.ascii === true;
44914
+ if (once && replay === undefined) {
44915
+ throw new UsageError("tui: --once needs --replay", ["see `loomwright tui --help`"]);
44916
+ }
44917
+ const replayPath = replay === undefined ? undefined : resolve9(io.cwd, replay);
44918
+ if (replay !== undefined && replayPath !== undefined) {
44919
+ let regularFile = false;
44920
+ try {
44921
+ regularFile = statSync12(replayPath).isFile();
44922
+ accessSync(replayPath, constants.R_OK);
44923
+ } catch (err) {
44924
+ throw new UsageError(`tui: cannot read --replay ${replay}`, [
44925
+ err instanceof Error ? err.message : String(err)
44926
+ ]);
44927
+ }
44928
+ if (!regularFile) {
44929
+ throw new UsageError(`tui: --replay ${replay} is not a regular file`);
44930
+ }
44931
+ }
44932
+ if (io.tty !== true && replay === undefined) {
44933
+ io.err("no terminal: `loomwright tui` needs a TTY to open the run list.");
44934
+ io.err("use `loomwright status <change-id> --watch` or `loomwright events <change-id> --follow`.");
44935
+ return ExitCode.Failure;
44936
+ }
44937
+ const workspace = replay === undefined ? await findWorkspaceRoot(io.cwd) ?? io.cwd : null;
44938
+ const { runTui } = await loadTui();
44939
+ const code = await runTui({
44940
+ workspace,
44941
+ ...replayPath === undefined ? {} : { replay: replayPath },
44942
+ once,
44943
+ ascii,
44944
+ columns: process.stdout.columns ?? 80,
44945
+ rows: process.stdout.rows ?? 24,
44946
+ out: io.out,
44947
+ env: process.env
44948
+ });
44949
+ return code === ExitCode.Ok ? ExitCode.Ok : ExitCode.Failure;
44950
+ }
44951
+ };
44952
+
44848
44953
  // packages/cli/src/commands/update.ts
44849
44954
  import { rmSync as rmSync18, writeFileSync as writeFileSync22 } from "node:fs";
44850
44955
  import { join as join64 } from "node:path";
@@ -45145,6 +45250,7 @@ var COMMANDS = [
45145
45250
  reapproveCommand,
45146
45251
  statusCommand,
45147
45252
  eventsCommand,
45253
+ tuiCommand,
45148
45254
  usageCommand,
45149
45255
  gateCommand,
45150
45256
  graphCommand,
@@ -45215,7 +45321,7 @@ async function runCli(argv, io) {
45215
45321
  io.err("error: -C needs a directory");
45216
45322
  return ExitCode.Usage;
45217
45323
  }
45218
- cwd = resolve9(cwd, dir);
45324
+ cwd = resolve10(cwd, dir);
45219
45325
  } else if (arg === "-V" || arg === "--version") {
45220
45326
  io.out(FACTORY_VERSION);
45221
45327
  return ExitCode.Ok;