@loomwright/cli 1.1.0 → 1.3.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/CHANGELOG.md +37 -0
- package/README.md +50 -20
- package/dist/cli.js +803 -355
- package/dist/tui.js +58379 -0
- package/package.json +1 -1
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
|
|
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.
|
|
14772
|
+
var FACTORY_VERSION = "1.3.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
|
|
23577
|
-
import { join as
|
|
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
|
|
23606
|
-
import { join as
|
|
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 =
|
|
23644
|
-
if (!
|
|
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
|
|
23660
|
-
import { join as
|
|
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
|
|
23666
|
-
mkdirSync as
|
|
23667
|
-
readdirSync as
|
|
23756
|
+
existsSync as existsSync6,
|
|
23757
|
+
mkdirSync as mkdirSync3,
|
|
23758
|
+
readdirSync as readdirSync4,
|
|
23668
23759
|
rmdirSync,
|
|
23669
23760
|
rmSync as rmSync2,
|
|
23670
|
-
statSync as
|
|
23761
|
+
statSync as statSync3
|
|
23671
23762
|
} from "node:fs";
|
|
23672
|
-
import { join as
|
|
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) =>
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
23745
|
-
if (!
|
|
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
|
|
23750
|
-
const dir =
|
|
23751
|
-
if (!
|
|
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
|
|
23754
|
-
const abs =
|
|
23755
|
-
if (
|
|
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 (
|
|
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
|
|
23770
|
-
mkdirSync as
|
|
23860
|
+
existsSync as existsSync7,
|
|
23861
|
+
mkdirSync as mkdirSync4,
|
|
23771
23862
|
openSync,
|
|
23772
|
-
readFileSync as
|
|
23863
|
+
readFileSync as readFileSync5,
|
|
23773
23864
|
renameSync,
|
|
23774
23865
|
rmSync as rmSync3,
|
|
23775
|
-
statSync as
|
|
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
|
|
23780
|
-
var factoryDir = (root, ...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 (!
|
|
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(
|
|
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
|
-
|
|
23907
|
+
mkdirSync4(dirname3(path), { recursive: true });
|
|
23817
23908
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
23818
|
-
|
|
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(
|
|
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() -
|
|
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
|
-
|
|
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
|
-
|
|
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) =>
|
|
23879
|
-
var graphFile = (root) =>
|
|
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(
|
|
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 || !
|
|
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 (!
|
|
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 =
|
|
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() -
|
|
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 || !
|
|
24051
|
+
if (files.length === 0 || !existsSync8(graphFile(root)))
|
|
23961
24052
|
return out;
|
|
23962
|
-
const mtime =
|
|
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
|
|
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 (!
|
|
24315
|
+
if (!existsSync9(dir))
|
|
24225
24316
|
return scan;
|
|
24226
|
-
for (const f of
|
|
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
|
|
24333
|
-
import { join as
|
|
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
|
|
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
|
|
24434
|
+
return join9(root, ARTIFACTS_DIR, kind, name);
|
|
24344
24435
|
}
|
|
24345
|
-
var artifactDir = (root, kind) => kind === undefined ?
|
|
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 (!
|
|
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 (
|
|
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 (!
|
|
24470
|
+
if (!existsSync10(dir))
|
|
24380
24471
|
return snapshotWastedReads(root, id);
|
|
24381
24472
|
let n = 0;
|
|
24382
|
-
for (const f of
|
|
24383
|
-
for (const line of
|
|
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 (!
|
|
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 (!
|
|
24518
|
+
if (!existsSync10(dir))
|
|
24428
24519
|
continue;
|
|
24429
|
-
for (const name of
|
|
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 =
|
|
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
|
|
24573
|
-
import { dirname as
|
|
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 =
|
|
24660
|
-
|
|
24661
|
-
|
|
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 =
|
|
24667
|
-
|
|
24668
|
-
const existing =
|
|
24669
|
-
|
|
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
|
|
24764
|
+
import { join as join13 } from "node:path";
|
|
24674
24765
|
|
|
24675
24766
|
// packages/core/src/events/emitter.ts
|
|
24676
|
-
import { existsSync as
|
|
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
|
|
24682
|
-
mkdirSync as
|
|
24683
|
-
readFileSync as
|
|
24772
|
+
existsSync as existsSync12,
|
|
24773
|
+
mkdirSync as mkdirSync6,
|
|
24774
|
+
readFileSync as readFileSync9,
|
|
24684
24775
|
rmSync as rmSync6,
|
|
24685
|
-
statSync as
|
|
24776
|
+
statSync as statSync6,
|
|
24686
24777
|
truncateSync,
|
|
24687
|
-
writeFileSync as
|
|
24778
|
+
writeFileSync as writeFileSync4
|
|
24688
24779
|
} from "node:fs";
|
|
24689
|
-
import { dirname as
|
|
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 (!
|
|
24785
|
+
if (!existsSync12(path))
|
|
24695
24786
|
return 0;
|
|
24696
|
-
const text =
|
|
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
|
-
|
|
24719
|
-
const file =
|
|
24720
|
-
const offset =
|
|
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:
|
|
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
|
-
|
|
24739
|
-
if (!
|
|
24740
|
-
|
|
24829
|
+
mkdirSync6(dirname5(file), { recursive: true });
|
|
24830
|
+
if (!existsSync12(file)) {
|
|
24831
|
+
writeFileSync4(file, "");
|
|
24741
24832
|
return;
|
|
24742
24833
|
}
|
|
24743
|
-
const text =
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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 :
|
|
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 ||
|
|
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 (!
|
|
26513
|
-
const args = await refExists(p.root, `refs/heads/${changeBranch(id)}`) ? ["worktree", "add", "-q",
|
|
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
|
|
26738
|
-
mkdirSync as
|
|
26739
|
-
readdirSync as
|
|
26740
|
-
readFileSync as
|
|
26837
|
+
existsSync as existsSync22,
|
|
26838
|
+
mkdirSync as mkdirSync9,
|
|
26839
|
+
readdirSync as readdirSync8,
|
|
26840
|
+
readFileSync as readFileSync17,
|
|
26741
26841
|
rmSync as rmSync8,
|
|
26742
|
-
writeFileSync as
|
|
26842
|
+
writeFileSync as writeFileSync8
|
|
26743
26843
|
} from "node:fs";
|
|
26744
|
-
import { dirname as
|
|
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
|
|
26748
|
-
import { join as
|
|
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
|
|
26752
|
-
import { join as
|
|
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 :
|
|
26877
|
+
const abs = rel === "" ? root : join15(root, rel);
|
|
26778
26878
|
let names;
|
|
26779
26879
|
try {
|
|
26780
|
-
names =
|
|
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 =
|
|
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 (
|
|
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
|
|
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
|
|
26970
|
-
import { basename, join as
|
|
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
|
|
26974
|
-
import { join as
|
|
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
|
|
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
|
|
27220
|
+
return existsSync16(join18(dir, ".git"));
|
|
27121
27221
|
}
|
|
27122
27222
|
function readScripts(dir) {
|
|
27123
27223
|
try {
|
|
27124
|
-
const pkg = JSON.parse(
|
|
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 (
|
|
27231
|
+
if (existsSync16(join18(dir, "bun.lock")) || existsSync16(join18(dir, "bun.lockb")))
|
|
27132
27232
|
return "bun run";
|
|
27133
|
-
if (
|
|
27233
|
+
if (existsSync16(join18(dir, "pnpm-lock.yaml")))
|
|
27134
27234
|
return "pnpm run";
|
|
27135
|
-
if (
|
|
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 =
|
|
27147
|
-
if (!
|
|
27246
|
+
const path = join18(dir, file);
|
|
27247
|
+
if (!existsSync16(path))
|
|
27148
27248
|
continue;
|
|
27149
27249
|
try {
|
|
27150
|
-
const doc = $parse(
|
|
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 (!
|
|
27265
|
+
if (!existsSync16(join18(dir, file)))
|
|
27166
27266
|
continue;
|
|
27167
27267
|
try {
|
|
27168
|
-
const text =
|
|
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 =
|
|
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 =
|
|
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
|
|
27349
|
-
import { join as
|
|
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 =
|
|
27398
|
-
if (!
|
|
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(
|
|
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
|
|
27510
|
-
import { join as
|
|
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) => `${
|
|
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
|
|
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
|
|
27849
|
-
import { join as
|
|
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 (
|
|
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
|
|
27914
|
-
import { join as
|
|
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 (!
|
|
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
|
-
|
|
27954
|
-
const path =
|
|
28053
|
+
mkdirSync7(hooks, { recursive: true });
|
|
28054
|
+
const path = join21(hooks, "pre-push");
|
|
27955
28055
|
let status = "installed";
|
|
27956
|
-
if (
|
|
27957
|
-
const current =
|
|
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 =
|
|
27964
|
-
if (
|
|
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
|
-
|
|
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 =
|
|
27984
|
-
if (!
|
|
28083
|
+
const path = join21(hooks, "pre-push");
|
|
28084
|
+
if (!existsSync19(path))
|
|
27985
28085
|
return "missing";
|
|
27986
|
-
const text =
|
|
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
|
|
28103
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
28004
28104
|
import {
|
|
28005
|
-
existsSync as
|
|
28006
|
-
mkdirSync as
|
|
28105
|
+
existsSync as existsSync20,
|
|
28106
|
+
mkdirSync as mkdirSync8,
|
|
28007
28107
|
mkdtempSync as mkdtempSync2,
|
|
28008
|
-
readFileSync as
|
|
28108
|
+
readFileSync as readFileSync16,
|
|
28009
28109
|
renameSync as renameSync4,
|
|
28010
28110
|
rmSync as rmSync7,
|
|
28011
|
-
writeFileSync as
|
|
28111
|
+
writeFileSync as writeFileSync6
|
|
28012
28112
|
} from "node:fs";
|
|
28013
28113
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
28014
|
-
import { dirname as
|
|
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
|
|
28019
|
-
import { join as
|
|
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
|
|
@@ -29888,7 +29988,118 @@ function checkRecursiveSearch(state, base, args) {
|
|
|
29888
29988
|
block(\`searches \\\`\${root}\\\`, which contains secret file \\\`\${found}\\\`; search specific directories instead\`);
|
|
29889
29989
|
}
|
|
29890
29990
|
}
|
|
29891
|
-
var PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun", "bunx"]);
|
|
29991
|
+
var PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun", "bunx", "npx", "pnpx"]);
|
|
29992
|
+
var NPM_VALUE_FLAGS = new Set([
|
|
29993
|
+
"--_auth",
|
|
29994
|
+
"--access",
|
|
29995
|
+
"--allow-directory",
|
|
29996
|
+
"--allow-file",
|
|
29997
|
+
"--allow-git",
|
|
29998
|
+
"--allow-remote",
|
|
29999
|
+
"--allow-scripts",
|
|
30000
|
+
"--also",
|
|
30001
|
+
"--audit-level",
|
|
30002
|
+
"--auth-type",
|
|
30003
|
+
"--before",
|
|
30004
|
+
"--ca",
|
|
30005
|
+
"--cache",
|
|
30006
|
+
"--cache-max",
|
|
30007
|
+
"--cache-min",
|
|
30008
|
+
"--cafile",
|
|
30009
|
+
"--call",
|
|
30010
|
+
"--cert",
|
|
30011
|
+
"--cidr",
|
|
30012
|
+
"--cpu",
|
|
30013
|
+
"--depth",
|
|
30014
|
+
"--diff",
|
|
30015
|
+
"--diff-dst-prefix",
|
|
30016
|
+
"--diff-src-prefix",
|
|
30017
|
+
"--diff-unified",
|
|
30018
|
+
"--editor",
|
|
30019
|
+
"--enjoy-by",
|
|
30020
|
+
"--expect-result-count",
|
|
30021
|
+
"--expires",
|
|
30022
|
+
"--fetch-retries",
|
|
30023
|
+
"--fetch-retry-factor",
|
|
30024
|
+
"--fetch-retry-maxtimeout",
|
|
30025
|
+
"--fetch-retry-mintimeout",
|
|
30026
|
+
"--fetch-timeout",
|
|
30027
|
+
"--git",
|
|
30028
|
+
"--globalconfig",
|
|
30029
|
+
"--heading",
|
|
30030
|
+
"--https-proxy",
|
|
30031
|
+
"--include",
|
|
30032
|
+
"--init-author-email",
|
|
30033
|
+
"--init-author-name",
|
|
30034
|
+
"--init-author-url",
|
|
30035
|
+
"--init-license",
|
|
30036
|
+
"--init-module",
|
|
30037
|
+
"--init-type",
|
|
30038
|
+
"--init-version",
|
|
30039
|
+
"--init.author.email",
|
|
30040
|
+
"--init.author.name",
|
|
30041
|
+
"--init.author.url",
|
|
30042
|
+
"--init.license",
|
|
30043
|
+
"--init.module",
|
|
30044
|
+
"--init.version",
|
|
30045
|
+
"--install-strategy",
|
|
30046
|
+
"--key",
|
|
30047
|
+
"--libc",
|
|
30048
|
+
"--local-address",
|
|
30049
|
+
"--location",
|
|
30050
|
+
"--lockfile-version",
|
|
30051
|
+
"--loglevel",
|
|
30052
|
+
"--logs-dir",
|
|
30053
|
+
"--logs-max",
|
|
30054
|
+
"--maxsockets",
|
|
30055
|
+
"--message",
|
|
30056
|
+
"--min-release-age",
|
|
30057
|
+
"--name",
|
|
30058
|
+
"--node-gyp",
|
|
30059
|
+
"--node-options",
|
|
30060
|
+
"--noproxy",
|
|
30061
|
+
"--omit",
|
|
30062
|
+
"--only",
|
|
30063
|
+
"--orgs",
|
|
30064
|
+
"--orgs-permission",
|
|
30065
|
+
"--os",
|
|
30066
|
+
"--otp",
|
|
30067
|
+
"--pack-destination",
|
|
30068
|
+
"--package",
|
|
30069
|
+
"--packages",
|
|
30070
|
+
"--packages-and-scopes-permission",
|
|
30071
|
+
"--password",
|
|
30072
|
+
"--prefix",
|
|
30073
|
+
"--preid",
|
|
30074
|
+
"--provenance-file",
|
|
30075
|
+
"--proxy",
|
|
30076
|
+
"--reg",
|
|
30077
|
+
"--registry",
|
|
30078
|
+
"--replace-registry-host",
|
|
30079
|
+
"--save-prefix",
|
|
30080
|
+
"--sbom-format",
|
|
30081
|
+
"--sbom-type",
|
|
30082
|
+
"--scope",
|
|
30083
|
+
"--scopes",
|
|
30084
|
+
"--script-shell",
|
|
30085
|
+
"--searchexclude",
|
|
30086
|
+
"--searchlimit",
|
|
30087
|
+
"--searchopts",
|
|
30088
|
+
"--searchstaleness",
|
|
30089
|
+
"--shell",
|
|
30090
|
+
"--tag",
|
|
30091
|
+
"--tag-version-prefix",
|
|
30092
|
+
"--token-description",
|
|
30093
|
+
"--umask",
|
|
30094
|
+
"--user-agent",
|
|
30095
|
+
"--userconfig",
|
|
30096
|
+
"--viewer",
|
|
30097
|
+
"--which",
|
|
30098
|
+
"--workspace"
|
|
30099
|
+
]);
|
|
30100
|
+
var NPM_COLOR_VALUES = new Set(["always", "true", "false"]);
|
|
30101
|
+
var NPM_SHORT_VALUE_FLAGS = new Set(["c", "C", "L", "m", "w"]);
|
|
30102
|
+
var NPX_SHORT_VALUE_FLAGS = new Set([...NPM_SHORT_VALUE_FLAGS, "n", "p"]);
|
|
29892
30103
|
var BUN_GLOBAL_SUBCOMMANDS = new Set([
|
|
29893
30104
|
"install",
|
|
29894
30105
|
"i",
|
|
@@ -29934,11 +30145,167 @@ function bunRunScript(args, start) {
|
|
|
29934
30145
|
}
|
|
29935
30146
|
return;
|
|
29936
30147
|
}
|
|
30148
|
+
function npmSubcommands(args) {
|
|
30149
|
+
const found = new Map;
|
|
30150
|
+
const seen = new Set;
|
|
30151
|
+
const pending = [0];
|
|
30152
|
+
while (pending.length > 0) {
|
|
30153
|
+
const i = pending.pop();
|
|
30154
|
+
if (i === undefined || seen.has(i))
|
|
30155
|
+
continue;
|
|
30156
|
+
seen.add(i);
|
|
30157
|
+
if (i >= args.length)
|
|
30158
|
+
continue;
|
|
30159
|
+
const a = args[i] ?? "";
|
|
30160
|
+
if (a === "--") {
|
|
30161
|
+
const next = args[i + 1];
|
|
30162
|
+
if (next !== undefined)
|
|
30163
|
+
found.set(i + 1, { index: i + 1, word: next });
|
|
30164
|
+
continue;
|
|
30165
|
+
}
|
|
30166
|
+
if (!a.startsWith("-") || a === "-") {
|
|
30167
|
+
found.set(i, { index: i, word: a });
|
|
30168
|
+
continue;
|
|
30169
|
+
}
|
|
30170
|
+
if (a.startsWith("--")) {
|
|
30171
|
+
const next = args[i + 1] ?? "";
|
|
30172
|
+
if (a === "--color" && NPM_COLOR_VALUES.has(next))
|
|
30173
|
+
pending.push(i + 2);
|
|
30174
|
+
else if (a.includes("="))
|
|
30175
|
+
pending.push(i + 1);
|
|
30176
|
+
else if (NPM_VALUE_FLAGS.has(a) || a.startsWith("--fetch-"))
|
|
30177
|
+
pending.push(i + 2);
|
|
30178
|
+
else
|
|
30179
|
+
pending.push(i + 1, i + 2);
|
|
30180
|
+
continue;
|
|
30181
|
+
}
|
|
30182
|
+
let next;
|
|
30183
|
+
const letters = a.slice(1);
|
|
30184
|
+
for (let j = 0;j < letters.length; j++) {
|
|
30185
|
+
const ch = letters[j] ?? "";
|
|
30186
|
+
if (NPM_SHORT_VALUE_FLAGS.has(ch)) {
|
|
30187
|
+
next = letters.slice(j + 1) === "" ? i + 2 : i + 1;
|
|
30188
|
+
break;
|
|
30189
|
+
}
|
|
30190
|
+
}
|
|
30191
|
+
pending.push(next ?? i + 1);
|
|
30192
|
+
}
|
|
30193
|
+
return [...found.values()].sort((a, b) => a.index - b.index);
|
|
30194
|
+
}
|
|
30195
|
+
var NPX_RUNNER_FLAGS = {
|
|
30196
|
+
long: NPM_VALUE_FLAGS,
|
|
30197
|
+
short: NPX_SHORT_VALUE_FLAGS
|
|
30198
|
+
};
|
|
30199
|
+
var NPM_EXEC_RUNNER_FLAGS = {
|
|
30200
|
+
long: NPM_VALUE_FLAGS,
|
|
30201
|
+
short: NPM_SHORT_VALUE_FLAGS
|
|
30202
|
+
};
|
|
30203
|
+
function scanRunnerArgs(args, flags) {
|
|
30204
|
+
const starts = new Set;
|
|
30205
|
+
const calls = [];
|
|
30206
|
+
const seen = new Set;
|
|
30207
|
+
const pending = [0];
|
|
30208
|
+
while (pending.length > 0) {
|
|
30209
|
+
const i = pending.pop();
|
|
30210
|
+
if (i === undefined || seen.has(i))
|
|
30211
|
+
continue;
|
|
30212
|
+
seen.add(i);
|
|
30213
|
+
if (i >= args.length) {
|
|
30214
|
+
starts.add(i);
|
|
30215
|
+
continue;
|
|
30216
|
+
}
|
|
30217
|
+
const a = args[i] ?? "";
|
|
30218
|
+
if (a === "--") {
|
|
30219
|
+
starts.add(i + 1);
|
|
30220
|
+
continue;
|
|
30221
|
+
}
|
|
30222
|
+
if (!a.startsWith("-") || a === "-") {
|
|
30223
|
+
starts.add(i);
|
|
30224
|
+
continue;
|
|
30225
|
+
}
|
|
30226
|
+
if (a.startsWith("--")) {
|
|
30227
|
+
if (a === "--call") {
|
|
30228
|
+
calls.push(args[i + 1] ?? "");
|
|
30229
|
+
continue;
|
|
30230
|
+
}
|
|
30231
|
+
if (a.startsWith("--call=")) {
|
|
30232
|
+
calls.push(a.slice("--call=".length));
|
|
30233
|
+
continue;
|
|
30234
|
+
}
|
|
30235
|
+
const next = args[i + 1] ?? "";
|
|
30236
|
+
if (a === "--color" && NPM_COLOR_VALUES.has(next))
|
|
30237
|
+
pending.push(i + 2);
|
|
30238
|
+
else if (a.includes("="))
|
|
30239
|
+
pending.push(i + 1);
|
|
30240
|
+
else if (flags.long.has(a) || a.startsWith("--fetch-"))
|
|
30241
|
+
pending.push(i + 2);
|
|
30242
|
+
else
|
|
30243
|
+
pending.push(i + 1, i + 2);
|
|
30244
|
+
continue;
|
|
30245
|
+
}
|
|
30246
|
+
const letters = a.slice(1);
|
|
30247
|
+
let next;
|
|
30248
|
+
let called = false;
|
|
30249
|
+
for (let j = 0;j < letters.length; j++) {
|
|
30250
|
+
const ch = letters[j] ?? "";
|
|
30251
|
+
if (ch === "c") {
|
|
30252
|
+
const attached = letters.slice(j + 1).replace(/^=/, "");
|
|
30253
|
+
calls.push(attached !== "" ? attached : args[i + 1] ?? "");
|
|
30254
|
+
called = true;
|
|
30255
|
+
break;
|
|
30256
|
+
}
|
|
30257
|
+
if (flags.short.has(ch)) {
|
|
30258
|
+
next = letters.slice(j + 1) === "" ? i + 2 : i + 1;
|
|
30259
|
+
break;
|
|
30260
|
+
}
|
|
30261
|
+
}
|
|
30262
|
+
if (!called)
|
|
30263
|
+
pending.push(next ?? i + 1);
|
|
30264
|
+
}
|
|
30265
|
+
return { starts: [...starts].sort((a, b) => a - b), calls };
|
|
30266
|
+
}
|
|
30267
|
+
function checkPackageRunner(state, args, outer, flags) {
|
|
30268
|
+
const { starts, calls } = scanRunnerArgs(args, flags);
|
|
30269
|
+
for (const text of calls)
|
|
30270
|
+
checkScriptText(state, text, outer);
|
|
30271
|
+
for (const start of starts) {
|
|
30272
|
+
const wrapped = args.slice(start);
|
|
30273
|
+
if (wrapped.length === 0)
|
|
30274
|
+
continue;
|
|
30275
|
+
if (++state.depth > 25)
|
|
30276
|
+
block("command nests too deeply to inspect");
|
|
30277
|
+
try {
|
|
30278
|
+
scoped(state, () => checkSimple(state, {
|
|
30279
|
+
kind: "simple",
|
|
30280
|
+
assigns: [],
|
|
30281
|
+
words: wrapped,
|
|
30282
|
+
redirects: [...outer.redirects],
|
|
30283
|
+
substitutions: []
|
|
30284
|
+
}, outer.stdin));
|
|
30285
|
+
} finally {
|
|
30286
|
+
state.depth--;
|
|
30287
|
+
}
|
|
30288
|
+
}
|
|
30289
|
+
}
|
|
29937
30290
|
function checkPackageManager(state, tool, args, outer) {
|
|
29938
30291
|
if (tool === "bunx") {
|
|
29939
30292
|
checkPackageManager(state, "bun", ["x", ...args], outer);
|
|
29940
30293
|
return;
|
|
29941
30294
|
}
|
|
30295
|
+
if (tool === "npx" || tool === "pnpx") {
|
|
30296
|
+
checkPackageRunner(state, args, outer, NPX_RUNNER_FLAGS);
|
|
30297
|
+
return;
|
|
30298
|
+
}
|
|
30299
|
+
if (tool === "npm") {
|
|
30300
|
+
const runners = npmSubcommands(args).filter((c) => c.word === "exec" || c.word === "x");
|
|
30301
|
+
for (const cmd of runners) {
|
|
30302
|
+
for (const text of scanRunnerArgs(args.slice(0, cmd.index), NPM_EXEC_RUNNER_FLAGS).calls)
|
|
30303
|
+
checkScriptText(state, text, outer);
|
|
30304
|
+
checkPackageRunner(state, args.slice(cmd.index + 1), outer, NPM_EXEC_RUNNER_FLAGS);
|
|
30305
|
+
}
|
|
30306
|
+
if (runners.length > 0)
|
|
30307
|
+
return;
|
|
30308
|
+
}
|
|
29942
30309
|
const cmd = tool === "bun" ? bunSubcommand(args) : undefined;
|
|
29943
30310
|
const sub = cmd?.word;
|
|
29944
30311
|
const known = tool !== "bun" || sub !== undefined && BUN_BUILTINS.has(sub);
|
|
@@ -29984,7 +30351,7 @@ function expandScripts(state, dir, scripts, keys) {
|
|
|
29984
30351
|
block(\`script \\\`\${key}\\\` expands into itself\`);
|
|
29985
30352
|
state.expanding.add(expansion);
|
|
29986
30353
|
try {
|
|
29987
|
-
checkScript(state, body);
|
|
30354
|
+
scoped(state, () => checkScript(state, body));
|
|
29988
30355
|
} finally {
|
|
29989
30356
|
state.expanding.delete(expansion);
|
|
29990
30357
|
}
|
|
@@ -30119,7 +30486,7 @@ function checkMake(state, args) {
|
|
|
30119
30486
|
if (found)
|
|
30120
30487
|
block(\`make \${target}: \${found}\`);
|
|
30121
30488
|
} else
|
|
30122
|
-
checkScript(state, line.replaceAll(DOLLAR, "$"));
|
|
30489
|
+
scoped(state, () => checkScript(state, line.replaceAll(DOLLAR, "$")));
|
|
30123
30490
|
}
|
|
30124
30491
|
};
|
|
30125
30492
|
for (const t of targets.length > 0 ? targets : first === undefined ? [] : [first])
|
|
@@ -30648,7 +31015,7 @@ function unwrap(state, words, stdin) {
|
|
|
30648
31015
|
if (base === "flock") {
|
|
30649
31016
|
const c = rest.indexOf("-c");
|
|
30650
31017
|
if (c !== -1) {
|
|
30651
|
-
checkScript(state, rest[c + 1] ?? "");
|
|
31018
|
+
scoped(state, () => checkScript(state, rest[c + 1] ?? ""));
|
|
30652
31019
|
return [];
|
|
30653
31020
|
}
|
|
30654
31021
|
i += 1;
|
|
@@ -30662,7 +31029,7 @@ function unwrap(state, words, stdin) {
|
|
|
30662
31029
|
let i = 0;
|
|
30663
31030
|
while (i < rest.length && (rest[i] ?? "").startsWith("-"))
|
|
30664
31031
|
i += /^-(n|d)$/.test(rest[i] ?? "") ? 2 : 1;
|
|
30665
|
-
checkScript(state, rest.slice(i).join(" "));
|
|
31032
|
+
scoped(state, () => checkScript(state, rest.slice(i).join(" ")));
|
|
30666
31033
|
return [];
|
|
30667
31034
|
}
|
|
30668
31035
|
return w;
|
|
@@ -30814,18 +31181,26 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30814
31181
|
break;
|
|
30815
31182
|
}
|
|
30816
31183
|
const operand = args[i];
|
|
30817
|
-
if (c)
|
|
30818
|
-
|
|
30819
|
-
|
|
30820
|
-
|
|
30821
|
-
if (
|
|
30822
|
-
|
|
30823
|
-
|
|
30824
|
-
|
|
31184
|
+
if (c) {
|
|
31185
|
+
scoped(state, () => checkScript(state, operand ?? ""));
|
|
31186
|
+
return;
|
|
31187
|
+
}
|
|
31188
|
+
if (!fromStdin && operand !== undefined) {
|
|
31189
|
+
scoped(state, () => checkScriptFile(state, operand, "shell"));
|
|
31190
|
+
return;
|
|
31191
|
+
}
|
|
31192
|
+
if (heredoc !== undefined) {
|
|
31193
|
+
scoped(state, () => checkScript(state, heredoc));
|
|
31194
|
+
return;
|
|
31195
|
+
}
|
|
31196
|
+
if (inputFile !== undefined) {
|
|
31197
|
+
scoped(state, () => checkScriptFile(state, inputFile, "shell"));
|
|
31198
|
+
return;
|
|
31199
|
+
}
|
|
30825
31200
|
if (stdin === null)
|
|
30826
31201
|
block(\`pipes generated input into \${base}\`);
|
|
30827
31202
|
if (stdin !== undefined)
|
|
30828
|
-
checkScript(state, stdin);
|
|
31203
|
+
scoped(state, () => checkScript(state, stdin));
|
|
30829
31204
|
return;
|
|
30830
31205
|
}
|
|
30831
31206
|
if (base === "source" || base === ".") {
|
|
@@ -30843,9 +31218,11 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30843
31218
|
state.cwd = undefined;
|
|
30844
31219
|
return;
|
|
30845
31220
|
}
|
|
30846
|
-
|
|
30847
|
-
|
|
30848
|
-
|
|
31221
|
+
const at = base.lastIndexOf("@");
|
|
31222
|
+
const tool = at > 0 && PACKAGE_MANAGERS.has(base.slice(0, at)) ? base.slice(0, at) : base;
|
|
31223
|
+
if (PACKAGE_MANAGERS.has(tool))
|
|
31224
|
+
checkPackageManager(state, tool, args, { redirects: cmd.redirects, stdin });
|
|
31225
|
+
const interpreter = tool.replace(/\\d+(\\.\\d+)*$/, "");
|
|
30849
31226
|
if ((interpreter === "perl" || interpreter === "ruby") && args.some(isInPlaceFlag)) {
|
|
30850
31227
|
const operands = [];
|
|
30851
31228
|
let code = false;
|
|
@@ -30862,7 +31239,7 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30862
31239
|
for (const f of code ? operands : operands.slice(1))
|
|
30863
31240
|
checkWrite(state, f, \`\${interpreter} -i edits\`);
|
|
30864
31241
|
}
|
|
30865
|
-
const inline = INTERPRETERS[interpreter] ?? INTERPRETERS[
|
|
31242
|
+
const inline = INTERPRETERS[interpreter] ?? INTERPRETERS[tool];
|
|
30866
31243
|
if (inline) {
|
|
30867
31244
|
const i = args.findIndex((a) => inline.includes(a));
|
|
30868
31245
|
const joined = args.find((a) => inline.some((f) => f.startsWith("--") && a.startsWith(\`\${f}=\`)));
|
|
@@ -30874,7 +31251,7 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30874
31251
|
return;
|
|
30875
31252
|
}
|
|
30876
31253
|
const file = args.find((a) => !a.startsWith("-"));
|
|
30877
|
-
if (
|
|
31254
|
+
if (tool === "bun" && file !== undefined) {
|
|
30878
31255
|
checkPackageScript(state, "bun", args);
|
|
30879
31256
|
return;
|
|
30880
31257
|
}
|
|
@@ -30907,8 +31284,10 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30907
31284
|
checkSed(state, args);
|
|
30908
31285
|
if (base === "script") {
|
|
30909
31286
|
const c = args.findIndex((a) => a === "-c" || a === "--command");
|
|
30910
|
-
if (c !== -1)
|
|
30911
|
-
|
|
31287
|
+
if (c !== -1) {
|
|
31288
|
+
scoped(state, () => checkScript(state, args[c + 1] ?? ""));
|
|
31289
|
+
return;
|
|
31290
|
+
}
|
|
30912
31291
|
}
|
|
30913
31292
|
if (base === "fd" || base === "fdfind") {
|
|
30914
31293
|
const x = args.findIndex((a) => ["-x", "--exec", "-X", "--exec-batch"].includes(a));
|
|
@@ -30918,8 +31297,8 @@ function checkSimple(state, cmd, stdin) {
|
|
|
30918
31297
|
}
|
|
30919
31298
|
}
|
|
30920
31299
|
if (head.includes("/"))
|
|
30921
|
-
checkScriptFile(state, head, "shell");
|
|
30922
|
-
switch (
|
|
31300
|
+
scoped(state, () => checkScriptFile(state, head, "shell"));
|
|
31301
|
+
switch (tool) {
|
|
30923
31302
|
case "git":
|
|
30924
31303
|
return checkGit(state, args);
|
|
30925
31304
|
case "rm":
|
|
@@ -31050,7 +31429,7 @@ function checkSimple(state, cmd, stdin) {
|
|
|
31050
31429
|
case "pnpm":
|
|
31051
31430
|
case "yarn":
|
|
31052
31431
|
case "bun":
|
|
31053
|
-
checkPackageScript(state,
|
|
31432
|
+
checkPackageScript(state, tool, args);
|
|
31054
31433
|
return;
|
|
31055
31434
|
case "make":
|
|
31056
31435
|
case "gmake":
|
|
@@ -31124,10 +31503,11 @@ function literalOutput(cmd) {
|
|
|
31124
31503
|
return cmd.redirects.find((r) => r.body !== undefined)?.body;
|
|
31125
31504
|
return;
|
|
31126
31505
|
}
|
|
31127
|
-
function checkPipeline(state, pipeline) {
|
|
31506
|
+
function checkPipeline(state, pipeline, inherited) {
|
|
31128
31507
|
const { commands } = pipeline;
|
|
31129
31508
|
commands.forEach((cmd, i) => {
|
|
31130
31509
|
const prev = commands[i - 1];
|
|
31510
|
+
const input = prev === undefined ? inherited : undefined;
|
|
31131
31511
|
let stdin;
|
|
31132
31512
|
if (prev !== undefined) {
|
|
31133
31513
|
const prevWords = prev.kind === "simple" ? prev.words : [];
|
|
@@ -31139,33 +31519,44 @@ function checkPipeline(state, pipeline) {
|
|
|
31139
31519
|
}
|
|
31140
31520
|
}
|
|
31141
31521
|
stdin = literalOutput(prev) ?? null;
|
|
31522
|
+
} else if (input !== undefined) {
|
|
31523
|
+
stdin = input.stdin;
|
|
31142
31524
|
}
|
|
31525
|
+
const redirects = input === undefined ? cmd.redirects : [...cmd.redirects, ...input.redirects];
|
|
31143
31526
|
if (cmd.kind === "subshell") {
|
|
31144
|
-
checkRedirects(state,
|
|
31145
|
-
scoped(state, () => checkScriptAst(state, cmd.script));
|
|
31527
|
+
checkRedirects(state, redirects);
|
|
31528
|
+
scoped(state, () => checkScriptAst(state, cmd.script, { redirects, stdin }));
|
|
31146
31529
|
} else {
|
|
31147
|
-
checkSimple(state, cmd, stdin);
|
|
31530
|
+
checkSimple(state, { ...cmd, redirects }, stdin);
|
|
31148
31531
|
}
|
|
31149
31532
|
});
|
|
31150
31533
|
}
|
|
31151
31534
|
function scoped(state, fn) {
|
|
31152
31535
|
const cwd = state.cwd;
|
|
31536
|
+
const aliases = new Map(state.aliases);
|
|
31153
31537
|
try {
|
|
31154
31538
|
fn();
|
|
31155
31539
|
} finally {
|
|
31156
31540
|
state.cwd = cwd;
|
|
31541
|
+
state.aliases.clear();
|
|
31542
|
+
for (const [name, value] of aliases)
|
|
31543
|
+
state.aliases.set(name, value);
|
|
31157
31544
|
}
|
|
31158
31545
|
}
|
|
31159
|
-
function checkScriptAst(state, script) {
|
|
31546
|
+
function checkScriptAst(state, script, inherited) {
|
|
31160
31547
|
if (++state.depth > 25)
|
|
31161
31548
|
block("command nests too deeply to inspect");
|
|
31162
31549
|
try {
|
|
31163
31550
|
for (const p of script.pipelines)
|
|
31164
|
-
checkPipeline(state, p);
|
|
31551
|
+
checkPipeline(state, p, inherited);
|
|
31165
31552
|
} finally {
|
|
31166
31553
|
state.depth--;
|
|
31167
31554
|
}
|
|
31168
31555
|
}
|
|
31556
|
+
function checkScriptText(state, text, inherited) {
|
|
31557
|
+
scoped(state, () => checkScriptAst(state, parseScript(text), inherited));
|
|
31558
|
+
return;
|
|
31559
|
+
}
|
|
31169
31560
|
function checkScript(state, text) {
|
|
31170
31561
|
checkScriptAst(state, parseScript(text));
|
|
31171
31562
|
return;
|
|
@@ -31408,7 +31799,9 @@ function onShellCreate(workspace, event) {
|
|
|
31408
31799
|
}
|
|
31409
31800
|
if (process.env.AI_FACTORY_SANDBOX === "seatbelt") {
|
|
31410
31801
|
const shell = typeof event.shell === "string" && event.shell.startsWith("/") ? event.shell : "/bin/bash";
|
|
31411
|
-
event.command = sandboxCommand(seatbeltProfile(sandboxPolicy(workspace, ctx)), shell, event.command)
|
|
31802
|
+
event.command = \`export AI_FACTORY_SANDBOX=wrapped; \${sandboxCommand(seatbeltProfile(sandboxPolicy(workspace, ctx)), shell, event.command)}\`;
|
|
31803
|
+
if (event.env !== undefined)
|
|
31804
|
+
event.env.AI_FACTORY_SANDBOX = "wrapped";
|
|
31412
31805
|
}
|
|
31413
31806
|
}
|
|
31414
31807
|
var entry_default = {
|
|
@@ -33159,7 +33552,7 @@ function renderImplementer(config, repo) {
|
|
|
33159
33552
|
function renderCustomAgent(config, agent, root) {
|
|
33160
33553
|
const role = ROLE_FOR_PHASE[agent.phase] ?? "implementer";
|
|
33161
33554
|
const agentRole = agent.phase;
|
|
33162
|
-
const body = agent.prompt ?? (agent.promptFile !== undefined && root !== undefined ?
|
|
33555
|
+
const body = agent.prompt ?? (agent.promptFile !== undefined && root !== undefined ? readFileSync15(join22(root, agent.promptFile), "utf8") : `# Role: ${agent.id}
|
|
33163
33556
|
|
|
33164
33557
|
${agent.description}`);
|
|
33165
33558
|
const skills = skillsSection(agent.skills);
|
|
@@ -33361,7 +33754,7 @@ function renderWorkspace(config, options = {}) {
|
|
|
33361
33754
|
|
|
33362
33755
|
// packages/core/src/managed/sync.ts
|
|
33363
33756
|
function sha256(text) {
|
|
33364
|
-
return
|
|
33757
|
+
return createHash3("sha256").update(text, "utf8").digest("hex");
|
|
33365
33758
|
}
|
|
33366
33759
|
function markersFor(path) {
|
|
33367
33760
|
const markers = BLOCK_MARKERS[path.slice(path.lastIndexOf("/") + 1)];
|
|
@@ -33379,10 +33772,10 @@ function findBlock(text, markers) {
|
|
|
33379
33772
|
return { start, end: endMarker + markers.end.length };
|
|
33380
33773
|
}
|
|
33381
33774
|
function readOptional(abs) {
|
|
33382
|
-
return
|
|
33775
|
+
return existsSync20(abs) ? readFileSync16(abs, "utf8") : undefined;
|
|
33383
33776
|
}
|
|
33384
33777
|
function currentOwned(root, path, mode) {
|
|
33385
|
-
const text = readOptional(
|
|
33778
|
+
const text = readOptional(join23(root, path));
|
|
33386
33779
|
if (text === undefined || mode === "file")
|
|
33387
33780
|
return text;
|
|
33388
33781
|
const block = findBlock(text, markersFor(path));
|
|
@@ -33427,9 +33820,9 @@ function planSync(root, files, previous, options) {
|
|
|
33427
33820
|
return plan.sort((a, b) => a.path.localeCompare(b.path));
|
|
33428
33821
|
}
|
|
33429
33822
|
function writeAtomic(abs, text) {
|
|
33430
|
-
|
|
33823
|
+
mkdirSync8(dirname6(abs), { recursive: true });
|
|
33431
33824
|
const tmp = `${abs}.ai-factory-tmp`;
|
|
33432
|
-
|
|
33825
|
+
writeFileSync6(tmp, text);
|
|
33433
33826
|
renameSync4(tmp, abs);
|
|
33434
33827
|
}
|
|
33435
33828
|
function writeBlock(abs, path, block) {
|
|
@@ -33450,12 +33843,12 @@ ${block}
|
|
|
33450
33843
|
writeAtomic(abs, next);
|
|
33451
33844
|
}
|
|
33452
33845
|
function removeOwned(root, path, mode) {
|
|
33453
|
-
const abs =
|
|
33846
|
+
const abs = join23(root, path);
|
|
33454
33847
|
if (mode === "file") {
|
|
33455
33848
|
rmSync7(abs, { force: true });
|
|
33456
33849
|
return;
|
|
33457
33850
|
}
|
|
33458
|
-
const text =
|
|
33851
|
+
const text = readFileSync16(abs, "utf8");
|
|
33459
33852
|
const range = findBlock(text, markersFor(path));
|
|
33460
33853
|
if (range === undefined)
|
|
33461
33854
|
return;
|
|
@@ -33490,12 +33883,12 @@ class BlobStore {
|
|
|
33490
33883
|
}
|
|
33491
33884
|
const body = Buffer.from(content, "utf8");
|
|
33492
33885
|
const header = Buffer.from(`blob ${body.length}\x00`, "utf8");
|
|
33493
|
-
const oid =
|
|
33494
|
-
const file =
|
|
33495
|
-
if (!
|
|
33496
|
-
|
|
33497
|
-
const tmp =
|
|
33498
|
-
|
|
33886
|
+
const oid = createHash3("sha1").update(header).update(body).digest("hex");
|
|
33887
|
+
const file = join23(dir, oid.slice(0, 2), oid.slice(2));
|
|
33888
|
+
if (!existsSync20(file)) {
|
|
33889
|
+
mkdirSync8(dirname6(file), { recursive: true });
|
|
33890
|
+
const tmp = join23(dir, `tmp_loomwright_${process.pid}_${this.#seq++}`);
|
|
33891
|
+
writeFileSync6(tmp, deflateSync(Buffer.concat([header, body])));
|
|
33499
33892
|
renameSync4(tmp, file);
|
|
33500
33893
|
}
|
|
33501
33894
|
return oid;
|
|
@@ -33506,12 +33899,12 @@ async function blobText(root, blob) {
|
|
|
33506
33899
|
return res.code === 0 ? res.stdout : undefined;
|
|
33507
33900
|
}
|
|
33508
33901
|
async function mergeThree(root, ours, base, theirs) {
|
|
33509
|
-
const dir = mkdtempSync2(
|
|
33902
|
+
const dir = mkdtempSync2(join23(tmpdir2(), "ai-factory-merge-"));
|
|
33510
33903
|
try {
|
|
33511
|
-
const files = { ours:
|
|
33512
|
-
|
|
33513
|
-
|
|
33514
|
-
|
|
33904
|
+
const files = { ours: join23(dir, "ours"), base: join23(dir, "base"), theirs: join23(dir, "theirs") };
|
|
33905
|
+
writeFileSync6(files.ours, ours);
|
|
33906
|
+
writeFileSync6(files.base, base);
|
|
33907
|
+
writeFileSync6(files.theirs, theirs);
|
|
33515
33908
|
const res = await exec([
|
|
33516
33909
|
"git",
|
|
33517
33910
|
"merge-file",
|
|
@@ -33556,7 +33949,7 @@ async function executeSync(root, plan, previous, options = {}) {
|
|
|
33556
33949
|
if (file === undefined)
|
|
33557
33950
|
throw new Error(`no render for ${change.path}`);
|
|
33558
33951
|
if (change.action !== "unchanged") {
|
|
33559
|
-
const abs =
|
|
33952
|
+
const abs = join23(root, file.path);
|
|
33560
33953
|
if (file.mode === "block")
|
|
33561
33954
|
writeBlock(abs, file.path, file.content);
|
|
33562
33955
|
else
|
|
@@ -33574,7 +33967,7 @@ async function executeSync(root, plan, previous, options = {}) {
|
|
|
33574
33967
|
break;
|
|
33575
33968
|
}
|
|
33576
33969
|
const result = await mergeThree(root, ours, base, file.content);
|
|
33577
|
-
const abs =
|
|
33970
|
+
const abs = join23(root, file.path);
|
|
33578
33971
|
if (file.mode === "block")
|
|
33579
33972
|
writeBlock(abs, file.path, result.text.replace(/\n$/, ""));
|
|
33580
33973
|
else
|
|
@@ -33689,10 +34082,10 @@ async function syncWorkspace(root, config, options = {}) {
|
|
|
33689
34082
|
files: [...PONYTAIL.files]
|
|
33690
34083
|
}
|
|
33691
34084
|
} : {}, opencodeRequirement(config)?.min ?? OPENCODE.min);
|
|
33692
|
-
|
|
34085
|
+
writeFileSync7(join24(root, LOCK_FILE), serializeLock(lock));
|
|
33693
34086
|
const hooks = [];
|
|
33694
34087
|
for (const repo of config.repos) {
|
|
33695
|
-
hooks.push({ repo: repo.name, result: await installPrePush(
|
|
34088
|
+
hooks.push({ repo: repo.name, result: await installPrePush(join24(root, repo.path)) });
|
|
33696
34089
|
}
|
|
33697
34090
|
return { plan, lock, hooks, merged, conflicts };
|
|
33698
34091
|
}
|
|
@@ -33704,7 +34097,7 @@ async function dirtyInstallPaths(root, ignore = []) {
|
|
|
33704
34097
|
`).filter((l) => l.trim() !== "").map((l) => l.slice(3)).filter((p) => !ignore.includes(p));
|
|
33705
34098
|
}
|
|
33706
34099
|
function commitInstall(root, message) {
|
|
33707
|
-
return commitPaths(root, INSTALL_PATHS.filter((p) =>
|
|
34100
|
+
return commitPaths(root, INSTALL_PATHS.filter((p) => existsSync21(join24(root, p))), message);
|
|
33708
34101
|
}
|
|
33709
34102
|
|
|
33710
34103
|
// packages/core/src/update/update.ts
|
|
@@ -33740,7 +34133,7 @@ function changesInProgress(root) {
|
|
|
33740
34133
|
return [...ids].sort();
|
|
33741
34134
|
}
|
|
33742
34135
|
async function planUpdate(root, lock, options) {
|
|
33743
|
-
const original =
|
|
34136
|
+
const original = readFileSync17(join25(root, CONFIG_FILE), "utf8");
|
|
33744
34137
|
const migration = migrateConfigText(original);
|
|
33745
34138
|
const config = parseConfigText(migration.text, CONFIG_FILE);
|
|
33746
34139
|
const plan = planWorkspace(root, config, {
|
|
@@ -33800,20 +34193,20 @@ function formatPlan(plan) {
|
|
|
33800
34193
|
var backupsDir = (root) => factoryDir(root, "backups");
|
|
33801
34194
|
function backup(root, plan) {
|
|
33802
34195
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
33803
|
-
const dir =
|
|
34196
|
+
const dir = join25(backupsDir(root), stamp);
|
|
33804
34197
|
const files = [];
|
|
33805
34198
|
const created = [];
|
|
33806
34199
|
for (const rel of plan.touched) {
|
|
33807
|
-
const abs =
|
|
33808
|
-
if (!
|
|
34200
|
+
const abs = join25(root, rel);
|
|
34201
|
+
if (!existsSync22(abs)) {
|
|
33809
34202
|
created.push(rel);
|
|
33810
34203
|
continue;
|
|
33811
34204
|
}
|
|
33812
|
-
|
|
33813
|
-
cpSync(abs,
|
|
34205
|
+
mkdirSync9(dirname7(join25(dir, "files", rel)), { recursive: true });
|
|
34206
|
+
cpSync(abs, join25(dir, "files", rel), { recursive: true });
|
|
33814
34207
|
files.push(rel);
|
|
33815
34208
|
}
|
|
33816
|
-
writeJsonAtomic(
|
|
34209
|
+
writeJsonAtomic(join25(dir, "manifest.json"), {
|
|
33817
34210
|
at: new Date().toISOString(),
|
|
33818
34211
|
fromVersion: plan.fromVersion,
|
|
33819
34212
|
toVersion: plan.toVersion,
|
|
@@ -33824,28 +34217,28 @@ function backup(root, plan) {
|
|
|
33824
34217
|
}
|
|
33825
34218
|
function latestBackup(root) {
|
|
33826
34219
|
const base = backupsDir(root);
|
|
33827
|
-
if (!
|
|
34220
|
+
if (!existsSync22(base))
|
|
33828
34221
|
return;
|
|
33829
|
-
for (const name of
|
|
33830
|
-
const file =
|
|
33831
|
-
if (!
|
|
34222
|
+
for (const name of readdirSync8(base).sort().reverse()) {
|
|
34223
|
+
const file = join25(base, name, "manifest.json");
|
|
34224
|
+
if (!existsSync22(file))
|
|
33832
34225
|
continue;
|
|
33833
|
-
const manifest = JSON.parse(
|
|
34226
|
+
const manifest = JSON.parse(readFileSync17(file, "utf8"));
|
|
33834
34227
|
if (!manifest.restored)
|
|
33835
|
-
return { dir:
|
|
34228
|
+
return { dir: join25(base, name), manifest };
|
|
33836
34229
|
}
|
|
33837
34230
|
return;
|
|
33838
34231
|
}
|
|
33839
34232
|
async function restoreBackup(root, dir, manifest) {
|
|
33840
34233
|
for (const rel of manifest.created)
|
|
33841
|
-
rmSync8(
|
|
34234
|
+
rmSync8(join25(root, rel), { recursive: true, force: true });
|
|
33842
34235
|
for (const rel of manifest.files) {
|
|
33843
|
-
const target =
|
|
34236
|
+
const target = join25(root, rel);
|
|
33844
34237
|
rmSync8(target, { recursive: true, force: true });
|
|
33845
|
-
|
|
33846
|
-
cpSync(
|
|
34238
|
+
mkdirSync9(dirname7(target), { recursive: true });
|
|
34239
|
+
cpSync(join25(dir, "files", rel), target, { recursive: true });
|
|
33847
34240
|
}
|
|
33848
|
-
|
|
34241
|
+
writeFileSync8(join25(dir, "manifest.json"), `${JSON.stringify({ ...manifest, restored: true }, null, 2)}
|
|
33849
34242
|
`);
|
|
33850
34243
|
return [...manifest.files, ...manifest.created];
|
|
33851
34244
|
}
|
|
@@ -33864,9 +34257,33 @@ function requireInstalled(root) {
|
|
|
33864
34257
|
|
|
33865
34258
|
// packages/cli/src/command.ts
|
|
33866
34259
|
import { parseArgs } from "node:util";
|
|
34260
|
+
function bindHelpValue(args, options) {
|
|
34261
|
+
const bound = [];
|
|
34262
|
+
for (let i = 0;i < args.length; i++) {
|
|
34263
|
+
const arg = args[i];
|
|
34264
|
+
if (arg === "--") {
|
|
34265
|
+
bound.push(...args.slice(i));
|
|
34266
|
+
break;
|
|
34267
|
+
}
|
|
34268
|
+
const next = args[i + 1];
|
|
34269
|
+
if (arg !== undefined && next !== undefined && (next === "-h" || next === "--help") && arg.startsWith("--") && !arg.includes("=") && options[arg.slice(2)]?.type === "string") {
|
|
34270
|
+
bound.push(`${arg}=${next}`);
|
|
34271
|
+
i++;
|
|
34272
|
+
continue;
|
|
34273
|
+
}
|
|
34274
|
+
if (arg !== undefined)
|
|
34275
|
+
bound.push(arg);
|
|
34276
|
+
}
|
|
34277
|
+
return bound;
|
|
34278
|
+
}
|
|
33867
34279
|
function parseCommandArgs(command, args, options, allowPositionals = false) {
|
|
33868
34280
|
try {
|
|
33869
|
-
return parseArgs({
|
|
34281
|
+
return parseArgs({
|
|
34282
|
+
args: bindHelpValue(args, options),
|
|
34283
|
+
options,
|
|
34284
|
+
strict: true,
|
|
34285
|
+
allowPositionals
|
|
34286
|
+
});
|
|
33870
34287
|
} catch (err) {
|
|
33871
34288
|
const message = err instanceof Error ? err.message : String(err);
|
|
33872
34289
|
throw new UsageError(`${command}: ${message}`, [`see \`loomwright ${command} --help\``]);
|
|
@@ -33882,8 +34299,8 @@ import { existsSync as existsSync36, readdirSync as readdirSync14 } from "node:f
|
|
|
33882
34299
|
import { join as join47, relative as relative9 } from "node:path";
|
|
33883
34300
|
|
|
33884
34301
|
// packages/core/src/events/inbox.ts
|
|
33885
|
-
import { readdirSync as
|
|
33886
|
-
import { join as
|
|
34302
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, rmSync as rmSync9 } from "node:fs";
|
|
34303
|
+
import { join as join26 } from "node:path";
|
|
33887
34304
|
var commandsDir = (root, runId) => factoryDir(root, "commands", runId);
|
|
33888
34305
|
function writeCommand(root, command) {
|
|
33889
34306
|
const parsed = Command.parse(command);
|
|
@@ -33896,7 +34313,7 @@ function readCommands(root, runId) {
|
|
|
33896
34313
|
const dir = commandsDir(root, runId);
|
|
33897
34314
|
let names;
|
|
33898
34315
|
try {
|
|
33899
|
-
names =
|
|
34316
|
+
names = readdirSync9(dir);
|
|
33900
34317
|
} catch (err) {
|
|
33901
34318
|
if (isMissing(err))
|
|
33902
34319
|
return [];
|
|
@@ -33904,10 +34321,10 @@ function readCommands(root, runId) {
|
|
|
33904
34321
|
}
|
|
33905
34322
|
const files = [];
|
|
33906
34323
|
for (const name of names.filter((n) => n.endsWith(".json")).sort()) {
|
|
33907
|
-
const file =
|
|
34324
|
+
const file = join26(dir, name);
|
|
33908
34325
|
let raw;
|
|
33909
34326
|
try {
|
|
33910
|
-
raw = JSON.parse(
|
|
34327
|
+
raw = JSON.parse(readFileSync18(file, "utf8"));
|
|
33911
34328
|
} catch (err) {
|
|
33912
34329
|
files.push({ file, error: err instanceof Error ? err.message : String(err) });
|
|
33913
34330
|
continue;
|
|
@@ -33939,14 +34356,14 @@ function reportCommandProblem(pipeline, line) {
|
|
|
33939
34356
|
}
|
|
33940
34357
|
|
|
33941
34358
|
// packages/core/src/events/reader.ts
|
|
33942
|
-
import { readFileSync as
|
|
34359
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
33943
34360
|
var isMissingFile = (err) => typeof err === "object" && err !== null && ("code" in err) && err.code === "ENOENT";
|
|
33944
34361
|
var isEmpty = (value) => value.trim() === "";
|
|
33945
34362
|
function readEventLines(root, runId) {
|
|
33946
34363
|
const path = eventLogPath(root, runId);
|
|
33947
34364
|
let text;
|
|
33948
34365
|
try {
|
|
33949
|
-
text =
|
|
34366
|
+
text = readFileSync19(path, "utf8");
|
|
33950
34367
|
} catch (err) {
|
|
33951
34368
|
if (isMissingFile(err))
|
|
33952
34369
|
return { lines: [], missing: [], skipped: [] };
|
|
@@ -34174,97 +34591,6 @@ async function* tailEvents(root, runId, options = {}) {
|
|
|
34174
34591
|
import { existsSync as existsSync24, readFileSync as readFileSync21 } from "node:fs";
|
|
34175
34592
|
import { join as join28 } from "node:path";
|
|
34176
34593
|
|
|
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
34594
|
// packages/core/src/update/snapshot.ts
|
|
34269
34595
|
import { cpSync as cpSync2, existsSync as existsSync23, mkdirSync as mkdirSync10, readdirSync as readdirSync10, readFileSync as readFileSync20, rmSync as rmSync10 } from "node:fs";
|
|
34270
34596
|
import { join as join27 } from "node:path";
|
|
@@ -36013,7 +36339,10 @@ function realPathOf(abs, depth = 0) {
|
|
|
36013
36339
|
|
|
36014
36340
|
// packages/core/src/policy/sandbox.ts
|
|
36015
36341
|
var SANDBOX_EXEC = "/usr/bin/sandbox-exec";
|
|
36016
|
-
function sandboxEnabled(setting, platform = process.platform, exists = existsSync30) {
|
|
36342
|
+
function sandboxEnabled(setting, platform = process.platform, exists = existsSync30, env = process.env) {
|
|
36343
|
+
const marker = env.AI_FACTORY_SANDBOX;
|
|
36344
|
+
if (marker === "wrapped" || marker === "off")
|
|
36345
|
+
return false;
|
|
36017
36346
|
return setting !== "off" && platform === "darwin" && exists(SANDBOX_EXEC);
|
|
36018
36347
|
}
|
|
36019
36348
|
var regexPath = (p) => realPathOf(p).replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
@@ -36165,11 +36494,13 @@ function staleLockfileNote(paths) {
|
|
|
36165
36494
|
async function runOne(input, gate) {
|
|
36166
36495
|
const before = await snapshot2(input.worktree);
|
|
36167
36496
|
const bins = gate.binDirs.map((b) => join39(input.worktree, b));
|
|
36497
|
+
const sandboxed = sandboxEnabled(input.config.security.sandbox);
|
|
36168
36498
|
const env = {
|
|
36169
36499
|
...agentProcessEnv(),
|
|
36170
36500
|
...cacheEnv(input.root, input.repo.name),
|
|
36171
36501
|
...QUIET_ENV,
|
|
36172
36502
|
...gate.env ?? {},
|
|
36503
|
+
AI_FACTORY_SANDBOX: sandboxed ? "wrapped" : "off",
|
|
36173
36504
|
PATH: [...bins, process.env.PATH ?? ""].join(delimiter)
|
|
36174
36505
|
};
|
|
36175
36506
|
const argv = [
|
|
@@ -36179,7 +36510,7 @@ async function runOne(input, gate) {
|
|
|
36179
36510
|
${gate.setup}
|
|
36180
36511
|
${gate.command}`
|
|
36181
36512
|
];
|
|
36182
|
-
const res = await exec(
|
|
36513
|
+
const res = await exec(sandboxed ? sandboxArgv(seatbeltProfile(checkoutPolicy(input.root, input.worktree, [join39(input.root, ".factory", "cache")])), argv) : argv, {
|
|
36183
36514
|
cwd: join39(input.worktree, gate.cwd),
|
|
36184
36515
|
env,
|
|
36185
36516
|
replaceEnv: true,
|
|
@@ -42060,13 +42391,25 @@ async function checkRepos(c, root, config, uninitialised) {
|
|
|
42060
42391
|
}
|
|
42061
42392
|
return ready;
|
|
42062
42393
|
}
|
|
42394
|
+
function errnoOf(err) {
|
|
42395
|
+
return typeof err === "object" && err !== null && "code" in err ? err.code : undefined;
|
|
42396
|
+
}
|
|
42397
|
+
function messageOf(err) {
|
|
42398
|
+
return err instanceof Error ? err.message : String(err);
|
|
42399
|
+
}
|
|
42063
42400
|
function packageScript(dir, name) {
|
|
42401
|
+
let text;
|
|
42064
42402
|
try {
|
|
42065
|
-
|
|
42403
|
+
text = readFileSync36(join54(dir, "package.json"), "utf8");
|
|
42404
|
+
} catch (err) {
|
|
42405
|
+
return errnoOf(err) === "ENOENT" ? { kind: "absent" } : { kind: "unreadable", error: messageOf(err) };
|
|
42406
|
+
}
|
|
42407
|
+
try {
|
|
42408
|
+
const pkg = JSON.parse(text);
|
|
42066
42409
|
const value = pkg.scripts?.[name];
|
|
42067
|
-
return typeof value === "string" ? value :
|
|
42068
|
-
} catch {
|
|
42069
|
-
return;
|
|
42410
|
+
return typeof value === "string" ? { kind: "body", body: value } : { kind: "absent" };
|
|
42411
|
+
} catch (err) {
|
|
42412
|
+
return { kind: "unreadable", error: messageOf(err) };
|
|
42070
42413
|
}
|
|
42071
42414
|
}
|
|
42072
42415
|
var WRITE_FLAG = /(^|\s)(--write|--fix|--apply|-w)(\s|$)/;
|
|
@@ -42074,12 +42417,19 @@ function checkWriteModeScripts(c, root, config, repos) {
|
|
|
42074
42417
|
c.in("gates");
|
|
42075
42418
|
for (const repo of repos.filter((r) => r.role === "code")) {
|
|
42076
42419
|
const dir = join54(root, repo.path);
|
|
42077
|
-
for (const
|
|
42078
|
-
|
|
42420
|
+
for (const type of GATE_TYPES) {
|
|
42421
|
+
const name = config.gates.scripts[type];
|
|
42422
|
+
if (name === undefined)
|
|
42423
|
+
continue;
|
|
42424
|
+
if (config.gates.overrides[repo.name]?.[type] !== undefined)
|
|
42079
42425
|
continue;
|
|
42080
42426
|
const script = packageScript(dir, name);
|
|
42081
|
-
if (script
|
|
42082
|
-
c.add("warn", `${repo.name} ${type} script`,
|
|
42427
|
+
if (script.kind === "unreadable") {
|
|
42428
|
+
c.add("warn", `${repo.name} ${type} script`, `package.json cannot be read (${script.error}); the gate script cannot be checked`, "fix the JSON in package.json");
|
|
42429
|
+
continue;
|
|
42430
|
+
}
|
|
42431
|
+
if (script.kind === "body" && WRITE_FLAG.test(script.body)) {
|
|
42432
|
+
c.add("warn", `${repo.name} ${type} script`, `\`${name}\` writes files: ${script.body}`, `set gates.overrides.${repo.name}.${type} to a check-only variant (it replaces the script lookup), or point gates.scripts.${type} at a check-only variant`);
|
|
42083
42433
|
}
|
|
42084
42434
|
}
|
|
42085
42435
|
}
|
|
@@ -42400,7 +42750,7 @@ function checkSandbox(c, config) {
|
|
|
42400
42750
|
c.in("security");
|
|
42401
42751
|
if (config.security.sandbox === "off")
|
|
42402
42752
|
c.add("warn", "sandbox", "off: agent shells and gates run unsandboxed", 'set security.sandbox to "auto"');
|
|
42403
|
-
else if (sandboxEnabled(config.security.sandbox))
|
|
42753
|
+
else if (sandboxEnabled(config.security.sandbox, process.platform, existsSync40, {}))
|
|
42404
42754
|
c.add("ok", "sandbox", "agent shells and gates run under macOS sandbox-exec");
|
|
42405
42755
|
else
|
|
42406
42756
|
c.add("warn", "sandbox", `no OS sandbox on ${process.platform} yet: the shell parser, plugin, audit and git layers still apply`, "run the factory on macOS for the sandbox (ADR-0026)");
|
|
@@ -44845,6 +45195,102 @@ that were cancelled because of it. Continue the change with \`loomwright resume
|
|
|
44845
45195
|
}
|
|
44846
45196
|
};
|
|
44847
45197
|
|
|
45198
|
+
// packages/cli/src/commands/tui.ts
|
|
45199
|
+
import { accessSync, constants, existsSync as existsSync49, statSync as statSync12 } from "node:fs";
|
|
45200
|
+
import { resolve as resolve9 } from "node:path";
|
|
45201
|
+
import { fileURLToPath } from "node:url";
|
|
45202
|
+
|
|
45203
|
+
// packages/tui/src/strings.ts
|
|
45204
|
+
var TUI_SUMMARY = "Watch and drive runs in the terminal";
|
|
45205
|
+
function tuiHelp() {
|
|
45206
|
+
return `Usage: loomwright tui [--replay <file>] [--once] [--ascii]
|
|
45207
|
+
|
|
45208
|
+
Watch and drive runs in the terminal. On a terminal the run list opens, newest first.
|
|
45209
|
+
Without a terminal use \`status --watch\` or \`events --follow\` instead.
|
|
45210
|
+
|
|
45211
|
+
--replay <file> Render a recorded event stream instead of a workspace
|
|
45212
|
+
--once Render one frame and exit (requires --replay)
|
|
45213
|
+
--ascii Force the ASCII glyph set
|
|
45214
|
+
|
|
45215
|
+
Exit codes: 0 ok, 2 invalid flags or an unreadable --replay file.`;
|
|
45216
|
+
}
|
|
45217
|
+
|
|
45218
|
+
// packages/cli/src/commands/tui.ts
|
|
45219
|
+
var TUI_OPTIONS = {
|
|
45220
|
+
replay: {
|
|
45221
|
+
type: "string",
|
|
45222
|
+
description: "Render a recorded event stream instead of a workspace",
|
|
45223
|
+
complete: "file"
|
|
45224
|
+
},
|
|
45225
|
+
once: {
|
|
45226
|
+
type: "boolean",
|
|
45227
|
+
default: false,
|
|
45228
|
+
description: "Render one frame and exit"
|
|
45229
|
+
},
|
|
45230
|
+
ascii: {
|
|
45231
|
+
type: "boolean",
|
|
45232
|
+
default: false,
|
|
45233
|
+
description: "Force the ASCII glyph set"
|
|
45234
|
+
}
|
|
45235
|
+
};
|
|
45236
|
+
async function loadTui() {
|
|
45237
|
+
const sibling = new URL("./tui.js", import.meta.url);
|
|
45238
|
+
if (existsSync49(fileURLToPath(sibling))) {
|
|
45239
|
+
const href = sibling.href;
|
|
45240
|
+
return await import(href);
|
|
45241
|
+
}
|
|
45242
|
+
const specifier = "@loomwright/tui/entry";
|
|
45243
|
+
return await import(specifier);
|
|
45244
|
+
}
|
|
45245
|
+
var tuiCommand = {
|
|
45246
|
+
name: "tui",
|
|
45247
|
+
summary: TUI_SUMMARY,
|
|
45248
|
+
options: TUI_OPTIONS,
|
|
45249
|
+
help: tuiHelp(),
|
|
45250
|
+
async run(args, io) {
|
|
45251
|
+
const { values } = parseCommandArgs("tui", args, TUI_OPTIONS);
|
|
45252
|
+
const replay = typeof values.replay === "string" ? values.replay : undefined;
|
|
45253
|
+
const once = values.once === true;
|
|
45254
|
+
const ascii = values.ascii === true;
|
|
45255
|
+
if (once && replay === undefined) {
|
|
45256
|
+
throw new UsageError("tui: --once needs --replay", ["see `loomwright tui --help`"]);
|
|
45257
|
+
}
|
|
45258
|
+
const replayPath = replay === undefined ? undefined : resolve9(io.cwd, replay);
|
|
45259
|
+
if (replay !== undefined && replayPath !== undefined) {
|
|
45260
|
+
let regularFile = false;
|
|
45261
|
+
try {
|
|
45262
|
+
regularFile = statSync12(replayPath).isFile();
|
|
45263
|
+
accessSync(replayPath, constants.R_OK);
|
|
45264
|
+
} catch (err) {
|
|
45265
|
+
throw new UsageError(`tui: cannot read --replay ${replay}`, [
|
|
45266
|
+
err instanceof Error ? err.message : String(err)
|
|
45267
|
+
]);
|
|
45268
|
+
}
|
|
45269
|
+
if (!regularFile) {
|
|
45270
|
+
throw new UsageError(`tui: --replay ${replay} is not a regular file`);
|
|
45271
|
+
}
|
|
45272
|
+
}
|
|
45273
|
+
if (io.tty !== true && replay === undefined) {
|
|
45274
|
+
io.err("no terminal: `loomwright tui` needs a TTY to open the run list.");
|
|
45275
|
+
io.err("use `loomwright status <change-id> --watch` or `loomwright events <change-id> --follow`.");
|
|
45276
|
+
return ExitCode.Failure;
|
|
45277
|
+
}
|
|
45278
|
+
const workspace = replay === undefined ? await findWorkspaceRoot(io.cwd) ?? io.cwd : null;
|
|
45279
|
+
const { runTui } = await loadTui();
|
|
45280
|
+
const code = await runTui({
|
|
45281
|
+
workspace,
|
|
45282
|
+
...replayPath === undefined ? {} : { replay: replayPath },
|
|
45283
|
+
once,
|
|
45284
|
+
ascii,
|
|
45285
|
+
columns: process.stdout.columns ?? 80,
|
|
45286
|
+
rows: process.stdout.rows ?? 24,
|
|
45287
|
+
out: io.out,
|
|
45288
|
+
env: process.env
|
|
45289
|
+
});
|
|
45290
|
+
return code === ExitCode.Ok ? ExitCode.Ok : ExitCode.Failure;
|
|
45291
|
+
}
|
|
45292
|
+
};
|
|
45293
|
+
|
|
44848
45294
|
// packages/cli/src/commands/update.ts
|
|
44849
45295
|
import { rmSync as rmSync18, writeFileSync as writeFileSync22 } from "node:fs";
|
|
44850
45296
|
import { join as join64 } from "node:path";
|
|
@@ -45145,6 +45591,7 @@ var COMMANDS = [
|
|
|
45145
45591
|
reapproveCommand,
|
|
45146
45592
|
statusCommand,
|
|
45147
45593
|
eventsCommand,
|
|
45594
|
+
tuiCommand,
|
|
45148
45595
|
usageCommand,
|
|
45149
45596
|
gateCommand,
|
|
45150
45597
|
graphCommand,
|
|
@@ -45204,7 +45651,7 @@ async function askText(question, initial) {
|
|
|
45204
45651
|
rl.close();
|
|
45205
45652
|
}
|
|
45206
45653
|
}
|
|
45207
|
-
async function runCli(argv, io) {
|
|
45654
|
+
async function runCli(argv, io, commands = COMMANDS) {
|
|
45208
45655
|
let cwd = io.cwd;
|
|
45209
45656
|
let i = 0;
|
|
45210
45657
|
for (;i < argv.length; i++) {
|
|
@@ -45215,7 +45662,7 @@ async function runCli(argv, io) {
|
|
|
45215
45662
|
io.err("error: -C needs a directory");
|
|
45216
45663
|
return ExitCode.Usage;
|
|
45217
45664
|
}
|
|
45218
|
-
cwd =
|
|
45665
|
+
cwd = resolve10(cwd, dir);
|
|
45219
45666
|
} else if (arg === "-V" || arg === "--version") {
|
|
45220
45667
|
io.out(FACTORY_VERSION);
|
|
45221
45668
|
return ExitCode.Ok;
|
|
@@ -45231,7 +45678,7 @@ async function runCli(argv, io) {
|
|
|
45231
45678
|
io.err(usage());
|
|
45232
45679
|
return ExitCode.Usage;
|
|
45233
45680
|
}
|
|
45234
|
-
const command =
|
|
45681
|
+
const command = commands.find((c) => c.name === name);
|
|
45235
45682
|
if (command === undefined) {
|
|
45236
45683
|
io.err(`error: unknown command "${name}"
|
|
45237
45684
|
|
|
@@ -45239,7 +45686,8 @@ ${usage()}`);
|
|
|
45239
45686
|
return ExitCode.Usage;
|
|
45240
45687
|
}
|
|
45241
45688
|
const rest = argv.slice(i + 1);
|
|
45242
|
-
|
|
45689
|
+
const first = rest[0];
|
|
45690
|
+
if (command.hidden !== true && (first === "-h" || first === "--help")) {
|
|
45243
45691
|
io.out(command.help);
|
|
45244
45692
|
return ExitCode.Ok;
|
|
45245
45693
|
}
|