@workit-dev/codex 2.22.0 → 2.22.2
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/.codex-plugin/plugin.json +1 -1
- package/bin/workit-paths.mjs +33 -1
- package/dist/launch-mcp.js +907 -631
- package/dist/{workit-hook-z09frbdk.js → workit-hook-0qpa9aa6.js} +5 -1
- package/dist/{workit-hook-52cm7mqd.js → workit-hook-2j7nwxvz.js} +3 -3
- package/dist/{workit-hook-sdmcdyrk.js → workit-hook-a7qmf2t8.js} +3 -3
- package/dist/{workit-hook-azjr1ew1.js → workit-hook-agyvx03a.js} +1 -1
- package/dist/{workit-hook-8nhm9sqf.js → workit-hook-at93rw3g.js} +933 -662
- package/dist/{workit-hook-ta5skes6.js → workit-hook-c490e5mm.js} +2 -2
- package/dist/{workit-hook-vmvv43m0.js → workit-hook-dv9s0sjq.js} +2 -2
- package/dist/{workit-hook-btkg30rw.js → workit-hook-mer435q8.js} +1 -1
- package/dist/{workit-hook-xdv92sjp.js → workit-hook-p972vv1e.js} +1 -1
- package/dist/{workit-hook-7jv519ep.js → workit-hook-sxyjantk.js} +14 -2
- package/dist/{workit-hook-x482fqpj.js → workit-hook-v0nvtq6s.js} +1 -1
- package/dist/{workit-hook-7dwf87hc.js → workit-hook-v7vytjn0.js} +4 -3
- package/dist/{workit-hook-dzfxvq92.js → workit-hook-yqe1kfrp.js} +2 -2
- package/dist/workit-hook.js +9 -9
- package/package.json +3 -3
package/dist/launch-mcp.js
CHANGED
|
@@ -6621,14 +6621,14 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
6621
6621
|
});
|
|
6622
6622
|
|
|
6623
6623
|
// packages/workit-codex/scripts/launch-mcp.ts
|
|
6624
|
-
import { existsSync as
|
|
6625
|
-
import
|
|
6624
|
+
import { existsSync as existsSync19, realpathSync as realpathSync13, statSync as statSync6 } from "node:fs";
|
|
6625
|
+
import path39 from "node:path";
|
|
6626
6626
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
6627
6627
|
|
|
6628
6628
|
// packages/workit-core/src/core.ts
|
|
6629
6629
|
import { spawnSync as spawnSync20 } from "node:child_process";
|
|
6630
|
-
import { existsSync as
|
|
6631
|
-
import
|
|
6630
|
+
import { existsSync as existsSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
6631
|
+
import path32 from "node:path";
|
|
6632
6632
|
|
|
6633
6633
|
// packages/workit-core/src/core/task-contract.ts
|
|
6634
6634
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -14033,23 +14033,25 @@ function explainInvalidOperation(family, request) {
|
|
|
14033
14033
|
return parsed.success ? null : invalidOperation(family, request, parsed.error);
|
|
14034
14034
|
}
|
|
14035
14035
|
// packages/workit-core/src/core/task-store.ts
|
|
14036
|
-
import { createHash as
|
|
14037
|
-
import * as
|
|
14038
|
-
import
|
|
14036
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
14037
|
+
import * as fs14 from "node:fs";
|
|
14038
|
+
import path17 from "node:path";
|
|
14039
14039
|
|
|
14040
14040
|
// packages/workit-core/src/host-session.ts
|
|
14041
|
-
import { createHash as
|
|
14042
|
-
import
|
|
14043
|
-
import
|
|
14041
|
+
import { createHash as createHash7, randomBytes, timingSafeEqual } from "node:crypto";
|
|
14042
|
+
import fs7 from "node:fs";
|
|
14043
|
+
import path11 from "node:path";
|
|
14044
14044
|
|
|
14045
14045
|
// packages/workit-core/src/core/branch-policy.ts
|
|
14046
14046
|
import { spawnSync } from "node:child_process";
|
|
14047
14047
|
|
|
14048
14048
|
// packages/workit-core/src/core/config.ts
|
|
14049
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14049
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
14050
14050
|
import path2 from "node:path";
|
|
14051
14051
|
|
|
14052
14052
|
// packages/workit-core/src/core/workit-paths.mjs
|
|
14053
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
14054
|
+
import { existsSync, lstatSync, mkdirSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
14053
14055
|
import os from "node:os";
|
|
14054
14056
|
import path from "node:path";
|
|
14055
14057
|
var WORKIT_DIR_OVERRIDES = {
|
|
@@ -14101,6 +14103,17 @@ var workitDir = (kind, env = process.env, platform = process.platform) => {
|
|
|
14101
14103
|
var configDir = (env, platform) => workitDir("config", env, platform);
|
|
14102
14104
|
var stateDir = (env, platform) => workitDir("state", env, platform);
|
|
14103
14105
|
var dataDir = (env, platform) => workitDir("data", env, platform);
|
|
14106
|
+
var folderSlug = (dir, platform = process.platform) => {
|
|
14107
|
+
let canonical = dir;
|
|
14108
|
+
try {
|
|
14109
|
+
canonical = realpathSync.native(dir);
|
|
14110
|
+
} catch {}
|
|
14111
|
+
if (platform === "win32")
|
|
14112
|
+
canonical = canonical.toLowerCase();
|
|
14113
|
+
const base = path.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
|
|
14114
|
+
return `${base}-${createHash2("sha256").update(canonical).digest("hex").slice(0, 12)}`;
|
|
14115
|
+
};
|
|
14116
|
+
var folderStoreDir = (dir, env, platform) => path.join(stateDir(env, platform), "folders", folderSlug(dir, platform));
|
|
14104
14117
|
|
|
14105
14118
|
// packages/workit-core/src/core/config.ts
|
|
14106
14119
|
var UPDATES_MODES = ["prompt", "auto", "off"];
|
|
@@ -14362,18 +14375,18 @@ var gitContext = (workspaceRoot, paths = []) => {
|
|
|
14362
14375
|
|
|
14363
14376
|
// packages/workit-core/src/core/workspaces.ts
|
|
14364
14377
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
14365
|
-
import { createHash as
|
|
14366
|
-
import { existsSync as
|
|
14378
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
14379
|
+
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
14367
14380
|
import path7 from "node:path";
|
|
14368
14381
|
|
|
14369
14382
|
// packages/workit-core/src/core/remotes.ts
|
|
14370
|
-
import { lstatSync, readFileSync as readFileSync3, realpathSync as
|
|
14383
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
|
|
14371
14384
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
14372
14385
|
import path6 from "node:path";
|
|
14373
14386
|
|
|
14374
14387
|
// packages/workit-core/src/git/rev.ts
|
|
14375
14388
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
14376
|
-
import { createHash as
|
|
14389
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
14377
14390
|
import fs3 from "node:fs";
|
|
14378
14391
|
import os2 from "node:os";
|
|
14379
14392
|
import path5 from "node:path";
|
|
@@ -14829,7 +14842,7 @@ function worktreeTree(cwd, options = {}) {
|
|
|
14829
14842
|
if (!tree)
|
|
14830
14843
|
return null;
|
|
14831
14844
|
const base = line(git(top, ["rev-parse", "--verify", "-q", "HEAD^{tree}"])) ?? emptyTree(top);
|
|
14832
|
-
const key = skipped.length ? `sha256:${
|
|
14845
|
+
const key = skipped.length ? `sha256:${createHash3("sha256").update(JSON.stringify({ tree, skipped })).digest("hex")}` : tree;
|
|
14833
14846
|
return { tree, key, dirty: tree !== base || skipped.length > 0, skipped };
|
|
14834
14847
|
} finally {
|
|
14835
14848
|
fs3.rmSync(scratch, { recursive: true, force: true });
|
|
@@ -14852,7 +14865,7 @@ function worktreeSignal(cwd, options = {}) {
|
|
|
14852
14865
|
});
|
|
14853
14866
|
if (!status.ok)
|
|
14854
14867
|
return null;
|
|
14855
|
-
const hash =
|
|
14868
|
+
const hash = createHash3("sha256");
|
|
14856
14869
|
hash.update(`${headSha(top) ?? "unborn"}\x00`);
|
|
14857
14870
|
for (const entry of status.stdout.split("\x00")) {
|
|
14858
14871
|
if (entry.length < 4)
|
|
@@ -15193,7 +15206,7 @@ function resolveSshHost(alias, sshConfig) {
|
|
|
15193
15206
|
|
|
15194
15207
|
// packages/workit-core/src/core/account-home.ts
|
|
15195
15208
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
15196
|
-
import { existsSync as
|
|
15209
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2 } from "node:fs";
|
|
15197
15210
|
import os3 from "node:os";
|
|
15198
15211
|
var WINDOWS = "C:\\Windows";
|
|
15199
15212
|
var SYSTEM32 = `${WINDOWS}\\System32\\`;
|
|
@@ -15285,7 +15298,7 @@ var canonical2 = (real) => {
|
|
|
15285
15298
|
};
|
|
15286
15299
|
var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
|
|
15287
15300
|
try {
|
|
15288
|
-
|
|
15301
|
+
lstatSync2(`${dir}/${name}`);
|
|
15289
15302
|
return true;
|
|
15290
15303
|
} catch {
|
|
15291
15304
|
return false;
|
|
@@ -15294,7 +15307,7 @@ var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
|
|
|
15294
15307
|
var gitDirAt = (at, depth = 0) => {
|
|
15295
15308
|
let real;
|
|
15296
15309
|
try {
|
|
15297
|
-
real =
|
|
15310
|
+
real = realpathSync3.native(at);
|
|
15298
15311
|
} catch {
|
|
15299
15312
|
return null;
|
|
15300
15313
|
}
|
|
@@ -15313,7 +15326,7 @@ var gitDirAt = (at, depth = 0) => {
|
|
|
15313
15326
|
common = readFileSync3(`${real}/commondir`, "utf8").trim();
|
|
15314
15327
|
} catch {}
|
|
15315
15328
|
if (common !== undefined) {
|
|
15316
|
-
|
|
15329
|
+
lstatSync2(`${real}/HEAD`);
|
|
15317
15330
|
return gitDirAt(path6.isAbsolute(common) ? common : `${real}/${common}`, depth + 1);
|
|
15318
15331
|
}
|
|
15319
15332
|
if (!isRepoDir(real))
|
|
@@ -15322,11 +15335,11 @@ var gitDirAt = (at, depth = 0) => {
|
|
|
15322
15335
|
for (const name of ["refs", "objects", "config", "packed-refs"]) {
|
|
15323
15336
|
const item = `${real}/${name}`;
|
|
15324
15337
|
try {
|
|
15325
|
-
|
|
15338
|
+
lstatSync2(item);
|
|
15326
15339
|
} catch {
|
|
15327
15340
|
continue;
|
|
15328
15341
|
}
|
|
15329
|
-
const resolved =
|
|
15342
|
+
const resolved = realpathSync3.native(item);
|
|
15330
15343
|
const rel = path6.relative(real, resolved);
|
|
15331
15344
|
if (rel && !rel.startsWith("..") && !path6.isAbsolute(rel))
|
|
15332
15345
|
continue;
|
|
@@ -15611,7 +15624,7 @@ var workspacesFileSchema = object({
|
|
|
15611
15624
|
names.add(workspace.name);
|
|
15612
15625
|
}
|
|
15613
15626
|
});
|
|
15614
|
-
var workspacesRevision = (contents) =>
|
|
15627
|
+
var workspacesRevision = (contents) => createHash4("sha256").update(contents ?? "<missing>").digest("hex");
|
|
15615
15628
|
var validateWorkspacesDocument = (parsed, file) => {
|
|
15616
15629
|
if (!isConfigObject(parsed)) {
|
|
15617
15630
|
return {
|
|
@@ -15762,8 +15775,8 @@ var probeCheckout = (cwd) => {
|
|
|
15762
15775
|
if (cached !== undefined)
|
|
15763
15776
|
return cached;
|
|
15764
15777
|
let dir = path7.resolve(cwd);
|
|
15765
|
-
while (!
|
|
15766
|
-
if (["HEAD", "objects", "refs"].every((name) =>
|
|
15778
|
+
while (!existsSync4(path7.join(dir, ".git"))) {
|
|
15779
|
+
if (["HEAD", "objects", "refs"].every((name) => existsSync4(path7.join(dir, name)))) {
|
|
15767
15780
|
const real = realpathOf(dir);
|
|
15768
15781
|
const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
|
|
15769
15782
|
if (owner === null)
|
|
@@ -15830,7 +15843,7 @@ var probeCheckout = (cwd) => {
|
|
|
15830
15843
|
};
|
|
15831
15844
|
var ownGitDir = (dotGit, real) => {
|
|
15832
15845
|
try {
|
|
15833
|
-
return
|
|
15846
|
+
return lstatSync3(dotGit).isDirectory() && realpathOf(dotGit) === real;
|
|
15834
15847
|
} catch {
|
|
15835
15848
|
return false;
|
|
15836
15849
|
}
|
|
@@ -15841,13 +15854,13 @@ var ownInternals = (real) => {
|
|
|
15841
15854
|
for (const name of INTERNALS) {
|
|
15842
15855
|
const at = path7.join(real, name);
|
|
15843
15856
|
try {
|
|
15844
|
-
|
|
15857
|
+
lstatSync3(at);
|
|
15845
15858
|
} catch {
|
|
15846
15859
|
continue;
|
|
15847
15860
|
}
|
|
15848
15861
|
let resolved;
|
|
15849
15862
|
try {
|
|
15850
|
-
resolved = (
|
|
15863
|
+
resolved = (realpathSync4.native ?? realpathSync4)(at);
|
|
15851
15864
|
} catch {
|
|
15852
15865
|
return false;
|
|
15853
15866
|
}
|
|
@@ -15905,7 +15918,7 @@ var matchingEntries = (cwd, entries) => {
|
|
|
15905
15918
|
return main ? match(main) : direct;
|
|
15906
15919
|
};
|
|
15907
15920
|
var realpathOf = (p) => {
|
|
15908
|
-
const real =
|
|
15921
|
+
const real = realpathSync4.native ?? realpathSync4;
|
|
15909
15922
|
try {
|
|
15910
15923
|
return real(p);
|
|
15911
15924
|
} catch {
|
|
@@ -16098,7 +16111,7 @@ import path8 from "node:path";
|
|
|
16098
16111
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
16099
16112
|
|
|
16100
16113
|
// packages/workit-core/src/core/release-tracks.ts
|
|
16101
|
-
import { createHash as
|
|
16114
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
16102
16115
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
16103
16116
|
var KNOWN_FIELDS = new Set([
|
|
16104
16117
|
"strategy",
|
|
@@ -16468,7 +16481,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
16468
16481
|
]) ?? "",
|
|
16469
16482
|
git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
|
|
16470
16483
|
] : [];
|
|
16471
|
-
key =
|
|
16484
|
+
key = createHash5("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
|
|
16472
16485
|
const hit = memo2.get(key);
|
|
16473
16486
|
if (hit)
|
|
16474
16487
|
return hit;
|
|
@@ -16862,9 +16875,289 @@ var redactSecrets = (value) => applyPatterns(value);
|
|
|
16862
16875
|
|
|
16863
16876
|
// packages/workit-core/src/store/paths.ts
|
|
16864
16877
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
16865
|
-
import { createHash as
|
|
16878
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
16879
|
+
import fs6 from "node:fs";
|
|
16880
|
+
import path10 from "node:path";
|
|
16881
|
+
|
|
16882
|
+
// packages/workit-core/src/store/folder-store.ts
|
|
16866
16883
|
import fs5 from "node:fs";
|
|
16884
|
+
import os5 from "node:os";
|
|
16867
16885
|
import path9 from "node:path";
|
|
16886
|
+
var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
|
|
16887
|
+
var MOVED_POINTER = "MOVED-TO-STATE.txt";
|
|
16888
|
+
var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
|
|
16889
|
+
var isV2TaskStub = (rel) => /^tasks[/\\][^/\\]+\.json$/u.test(rel);
|
|
16890
|
+
var MARKER = "workspace.json";
|
|
16891
|
+
var v2Workspace = (workit) => {
|
|
16892
|
+
let bytes;
|
|
16893
|
+
try {
|
|
16894
|
+
bytes = fs5.readFileSync(path9.join(workit, MARKER), "utf8");
|
|
16895
|
+
} catch {
|
|
16896
|
+
return null;
|
|
16897
|
+
}
|
|
16898
|
+
try {
|
|
16899
|
+
const value = JSON.parse(bytes);
|
|
16900
|
+
return value?.store?.format !== "workit-store";
|
|
16901
|
+
} catch {
|
|
16902
|
+
return true;
|
|
16903
|
+
}
|
|
16904
|
+
};
|
|
16905
|
+
var generatedIgnore = (file) => {
|
|
16906
|
+
try {
|
|
16907
|
+
return /^\*\n(!risk-paths\n)?$/u.test(fs5.readFileSync(file, "utf8"));
|
|
16908
|
+
} catch {
|
|
16909
|
+
return false;
|
|
16910
|
+
}
|
|
16911
|
+
};
|
|
16912
|
+
var exists = (file) => {
|
|
16913
|
+
try {
|
|
16914
|
+
fs5.lstatSync(file);
|
|
16915
|
+
return true;
|
|
16916
|
+
} catch {
|
|
16917
|
+
return false;
|
|
16918
|
+
}
|
|
16919
|
+
};
|
|
16920
|
+
var isDir = (file) => {
|
|
16921
|
+
try {
|
|
16922
|
+
return fs5.lstatSync(file).isDirectory();
|
|
16923
|
+
} catch {
|
|
16924
|
+
return false;
|
|
16925
|
+
}
|
|
16926
|
+
};
|
|
16927
|
+
var onlyStubs = (tasks) => {
|
|
16928
|
+
try {
|
|
16929
|
+
return fs5.readdirSync(tasks).every((entry) => isV2TaskStub(`tasks/${entry}`));
|
|
16930
|
+
} catch {
|
|
16931
|
+
return false;
|
|
16932
|
+
}
|
|
16933
|
+
};
|
|
16934
|
+
var strayEntries = (workit) => {
|
|
16935
|
+
if (!isDir(workit))
|
|
16936
|
+
return [];
|
|
16937
|
+
let names;
|
|
16938
|
+
try {
|
|
16939
|
+
names = fs5.readdirSync(workit);
|
|
16940
|
+
} catch {
|
|
16941
|
+
return [];
|
|
16942
|
+
}
|
|
16943
|
+
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path9.join(workit, name))) && !(name === "tasks" && onlyStubs(path9.join(workit, name))));
|
|
16944
|
+
};
|
|
16945
|
+
var folderStoreIo = {
|
|
16946
|
+
rename: (from, to) => fs5.renameSync(from, to),
|
|
16947
|
+
copyFile: (from, to) => fs5.copyFileSync(from, to, fs5.constants.COPYFILE_EXCL)
|
|
16948
|
+
};
|
|
16949
|
+
var tempSeq = 0;
|
|
16950
|
+
var tempBeside = (file) => path9.join(path9.dirname(file), `.${path9.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
|
|
16951
|
+
var copyInto = (from, to) => {
|
|
16952
|
+
const stat = fs5.lstatSync(from);
|
|
16953
|
+
if (stat.isDirectory()) {
|
|
16954
|
+
fs5.mkdirSync(to, { recursive: true });
|
|
16955
|
+
for (const name of fs5.readdirSync(from))
|
|
16956
|
+
copyInto(path9.join(from, name), path9.join(to, name));
|
|
16957
|
+
return;
|
|
16958
|
+
}
|
|
16959
|
+
if (exists(to))
|
|
16960
|
+
throw new Error(`${to} appeared during the move`);
|
|
16961
|
+
const temp = tempBeside(to);
|
|
16962
|
+
try {
|
|
16963
|
+
if (stat.isSymbolicLink())
|
|
16964
|
+
fs5.symlinkSync(fs5.readlinkSync(from), temp);
|
|
16965
|
+
else
|
|
16966
|
+
folderStoreIo.copyFile(from, temp);
|
|
16967
|
+
folderStoreIo.rename(temp, to);
|
|
16968
|
+
} catch (error) {
|
|
16969
|
+
fs5.rmSync(temp, { force: true });
|
|
16970
|
+
throw error;
|
|
16971
|
+
}
|
|
16972
|
+
};
|
|
16973
|
+
var sameFile = (left, right) => {
|
|
16974
|
+
try {
|
|
16975
|
+
const [a, b] = [fs5.lstatSync(left), fs5.lstatSync(right)];
|
|
16976
|
+
if (!a.isFile() || !b.isFile() || a.size !== b.size)
|
|
16977
|
+
return false;
|
|
16978
|
+
return fs5.readFileSync(left).equals(fs5.readFileSync(right));
|
|
16979
|
+
} catch {
|
|
16980
|
+
return false;
|
|
16981
|
+
}
|
|
16982
|
+
};
|
|
16983
|
+
var merge2 = (from, to, rel, moved) => {
|
|
16984
|
+
if (isV2TaskStub(rel))
|
|
16985
|
+
return [];
|
|
16986
|
+
if (!exists(to)) {
|
|
16987
|
+
try {
|
|
16988
|
+
folderStoreIo.rename(from, to);
|
|
16989
|
+
} catch {
|
|
16990
|
+
try {
|
|
16991
|
+
copyInto(from, to);
|
|
16992
|
+
fs5.rmSync(from, { recursive: true, force: true });
|
|
16993
|
+
} catch {
|
|
16994
|
+
return exists(from) ? [rel] : [];
|
|
16995
|
+
}
|
|
16996
|
+
}
|
|
16997
|
+
moved.push(rel);
|
|
16998
|
+
return [];
|
|
16999
|
+
}
|
|
17000
|
+
if (sameFile(from, to)) {
|
|
17001
|
+
fs5.rmSync(from, { force: true });
|
|
17002
|
+
moved.push(rel);
|
|
17003
|
+
return [];
|
|
17004
|
+
}
|
|
17005
|
+
if (!isDir(from) || !isDir(to))
|
|
17006
|
+
return [rel];
|
|
17007
|
+
const kept = fs5.readdirSync(from).flatMap((name) => merge2(path9.join(from, name), path9.join(to, name), `${rel}/${name}`, moved));
|
|
17008
|
+
try {
|
|
17009
|
+
if (fs5.readdirSync(from).length === 0)
|
|
17010
|
+
fs5.rmdirSync(from);
|
|
17011
|
+
} catch {}
|
|
17012
|
+
return kept;
|
|
17013
|
+
};
|
|
17014
|
+
var LOCK_STALE_MS = 1e4;
|
|
17015
|
+
var LOCK_WAIT_MS = 250;
|
|
17016
|
+
var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
17017
|
+
var staleLock = (lock) => {
|
|
17018
|
+
try {
|
|
17019
|
+
const stat = fs5.statSync(lock);
|
|
17020
|
+
if (Date.now() - stat.mtimeMs > LOCK_STALE_MS)
|
|
17021
|
+
return true;
|
|
17022
|
+
const pid = Number(fs5.readFileSync(lock, "utf8").trim());
|
|
17023
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
17024
|
+
return false;
|
|
17025
|
+
try {
|
|
17026
|
+
process.kill(pid, 0);
|
|
17027
|
+
return false;
|
|
17028
|
+
} catch (error) {
|
|
17029
|
+
return error.code === "ESRCH";
|
|
17030
|
+
}
|
|
17031
|
+
} catch {
|
|
17032
|
+
return false;
|
|
17033
|
+
}
|
|
17034
|
+
};
|
|
17035
|
+
var takeMoveLock = (target) => {
|
|
17036
|
+
const lock = `${target}.lock`;
|
|
17037
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
17038
|
+
for (;; ) {
|
|
17039
|
+
try {
|
|
17040
|
+
const fd = fs5.openSync(lock, "wx", 384);
|
|
17041
|
+
fs5.writeSync(fd, `${process.pid}
|
|
17042
|
+
`);
|
|
17043
|
+
fs5.closeSync(fd);
|
|
17044
|
+
return () => fs5.rmSync(lock, { force: true });
|
|
17045
|
+
} catch (error) {
|
|
17046
|
+
if (error.code !== "EEXIST")
|
|
17047
|
+
return null;
|
|
17048
|
+
}
|
|
17049
|
+
if (staleLock(lock)) {
|
|
17050
|
+
fs5.rmSync(lock, { force: true });
|
|
17051
|
+
continue;
|
|
17052
|
+
}
|
|
17053
|
+
if (Date.now() >= deadline)
|
|
17054
|
+
return null;
|
|
17055
|
+
pause(25);
|
|
17056
|
+
}
|
|
17057
|
+
};
|
|
17058
|
+
var canonical3 = (dir) => {
|
|
17059
|
+
try {
|
|
17060
|
+
return fs5.realpathSync.native(dir);
|
|
17061
|
+
} catch {
|
|
17062
|
+
return path9.resolve(dir);
|
|
17063
|
+
}
|
|
17064
|
+
};
|
|
17065
|
+
var below = (parent, child) => {
|
|
17066
|
+
const rel = path9.relative(parent, child);
|
|
17067
|
+
return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
|
|
17068
|
+
};
|
|
17069
|
+
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
17070
|
+
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
|
|
17071
|
+
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
17072
|
+
return null;
|
|
17073
|
+
const real = canonical3(folder);
|
|
17074
|
+
const tmp = canonical3(tempDir);
|
|
17075
|
+
if (below(tmp, real))
|
|
17076
|
+
return null;
|
|
17077
|
+
return `workit test run (WORKIT_TEST_RUN): refusing to move ${path9.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
|
|
17078
|
+
};
|
|
17079
|
+
function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
|
|
17080
|
+
`)) {
|
|
17081
|
+
const workit = path9.join(folder, ".workit");
|
|
17082
|
+
const names = strayEntries(workit);
|
|
17083
|
+
const refusal = testRunFolderRefusal(folder, names.length > 0);
|
|
17084
|
+
if (refusal) {
|
|
17085
|
+
const run = process.env.WORKIT_TEST_RUN ?? "";
|
|
17086
|
+
if (path9.isAbsolute(run))
|
|
17087
|
+
try {
|
|
17088
|
+
fs5.appendFileSync(path9.join(run, TEST_RUN_REFUSALS), `${refusal}
|
|
17089
|
+
`);
|
|
17090
|
+
} catch {}
|
|
17091
|
+
throw new Error(refusal);
|
|
17092
|
+
}
|
|
17093
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
17094
|
+
return null;
|
|
17095
|
+
try {
|
|
17096
|
+
fs5.mkdirSync(path9.dirname(target), { recursive: true });
|
|
17097
|
+
} catch {
|
|
17098
|
+
return null;
|
|
17099
|
+
}
|
|
17100
|
+
const release = takeMoveLock(target);
|
|
17101
|
+
if (!release)
|
|
17102
|
+
return null;
|
|
17103
|
+
try {
|
|
17104
|
+
return moveLocked(workit, target, note);
|
|
17105
|
+
} finally {
|
|
17106
|
+
release();
|
|
17107
|
+
}
|
|
17108
|
+
}
|
|
17109
|
+
function moveLocked(workit, target, note) {
|
|
17110
|
+
const names = strayEntries(workit);
|
|
17111
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
17112
|
+
return null;
|
|
17113
|
+
try {
|
|
17114
|
+
fs5.mkdirSync(target, { recursive: true });
|
|
17115
|
+
} catch {
|
|
17116
|
+
return null;
|
|
17117
|
+
}
|
|
17118
|
+
const result = { from: workit, to: target, moved: [], kept: [] };
|
|
17119
|
+
for (const name of names) {
|
|
17120
|
+
result.kept.push(...merge2(path9.join(workit, name), path9.join(target, name), name, result.moved));
|
|
17121
|
+
}
|
|
17122
|
+
const left = (() => {
|
|
17123
|
+
try {
|
|
17124
|
+
return fs5.readdirSync(workit);
|
|
17125
|
+
} catch {
|
|
17126
|
+
return [];
|
|
17127
|
+
}
|
|
17128
|
+
})();
|
|
17129
|
+
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path9.join(workit, name)));
|
|
17130
|
+
if (!v2Left && result.kept.length === 0) {
|
|
17131
|
+
fs5.rmSync(path9.join(workit, MARKER), { force: true });
|
|
17132
|
+
if (generatedIgnore(path9.join(workit, ".gitignore")))
|
|
17133
|
+
fs5.rmSync(path9.join(workit, ".gitignore"), { force: true });
|
|
17134
|
+
}
|
|
17135
|
+
const pointer = path9.join(workit, MOVED_POINTER);
|
|
17136
|
+
let wrote = false;
|
|
17137
|
+
if (result.kept.length > 0) {
|
|
17138
|
+
const text = `Workit keeps this folder's state in ${target}.
|
|
17139
|
+
Not moved, because the store there already has them or the move failed: ${result.kept.join(", ")}.
|
|
17140
|
+
Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
|
|
17141
|
+
`;
|
|
17142
|
+
try {
|
|
17143
|
+
if (!exists(pointer) || fs5.readFileSync(pointer, "utf8") !== text) {
|
|
17144
|
+
fs5.writeFileSync(pointer, text);
|
|
17145
|
+
wrote = true;
|
|
17146
|
+
}
|
|
17147
|
+
} catch {}
|
|
17148
|
+
} else {
|
|
17149
|
+
fs5.rmSync(pointer, { force: true });
|
|
17150
|
+
try {
|
|
17151
|
+
if (fs5.readdirSync(workit).length === 0)
|
|
17152
|
+
fs5.rmdirSync(workit);
|
|
17153
|
+
} catch {}
|
|
17154
|
+
}
|
|
17155
|
+
if (result.moved.length > 0 || wrote)
|
|
17156
|
+
note(result.kept.length > 0 ? `workit: moved ${workit} to ${target}; ${result.kept.length} path${result.kept.length === 1 ? "" : "s"} left in place, see ${pointer}` : `workit: moved ${workit} to ${target} (outside a git repository Workit keeps its state there)`);
|
|
17157
|
+
return result;
|
|
17158
|
+
}
|
|
17159
|
+
|
|
17160
|
+
// packages/workit-core/src/store/paths.ts
|
|
16868
17161
|
var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
|
|
16869
17162
|
var gitRun = (cwd, args) => {
|
|
16870
17163
|
const run = spawnSync9("git", args, {
|
|
@@ -16889,10 +17182,10 @@ var gitRun = (cwd, args) => {
|
|
|
16889
17182
|
missing: error?.code === "ENOENT"
|
|
16890
17183
|
};
|
|
16891
17184
|
};
|
|
16892
|
-
var shortHash = (value) =>
|
|
17185
|
+
var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
|
|
16893
17186
|
var real = (file) => {
|
|
16894
17187
|
try {
|
|
16895
|
-
return
|
|
17188
|
+
return fs6.realpathSync.native(file);
|
|
16896
17189
|
} catch {
|
|
16897
17190
|
return file;
|
|
16898
17191
|
}
|
|
@@ -16906,14 +17199,14 @@ var DISCOVERY_ENV = [
|
|
|
16906
17199
|
];
|
|
16907
17200
|
var isGitDir = (dir) => {
|
|
16908
17201
|
try {
|
|
16909
|
-
return
|
|
17202
|
+
return fs6.statSync(path10.join(dir, "HEAD")).isFile() && fs6.statSync(path10.join(dir, "objects")).isDirectory() && fs6.statSync(path10.join(dir, "refs")).isDirectory();
|
|
16910
17203
|
} catch {
|
|
16911
17204
|
return false;
|
|
16912
17205
|
}
|
|
16913
17206
|
};
|
|
16914
17207
|
var reftableRefs = (common) => {
|
|
16915
17208
|
try {
|
|
16916
|
-
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(
|
|
17209
|
+
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path10.join(common, "config"), "utf8"));
|
|
16917
17210
|
} catch {
|
|
16918
17211
|
return false;
|
|
16919
17212
|
}
|
|
@@ -16926,17 +17219,17 @@ function fastGit(root) {
|
|
|
16926
17219
|
for (;; ) {
|
|
16927
17220
|
let stat;
|
|
16928
17221
|
try {
|
|
16929
|
-
stat =
|
|
17222
|
+
stat = fs6.statSync(dir);
|
|
16930
17223
|
} catch {
|
|
16931
17224
|
return null;
|
|
16932
17225
|
}
|
|
16933
17226
|
if (device !== null && stat.dev !== device)
|
|
16934
17227
|
return { kind: "none" };
|
|
16935
17228
|
device = stat.dev;
|
|
16936
|
-
const dotGit =
|
|
17229
|
+
const dotGit = path10.join(dir, ".git");
|
|
16937
17230
|
let entry = null;
|
|
16938
17231
|
try {
|
|
16939
|
-
entry =
|
|
17232
|
+
entry = fs6.statSync(dotGit);
|
|
16940
17233
|
} catch {}
|
|
16941
17234
|
let gitDir = null;
|
|
16942
17235
|
let top = null;
|
|
@@ -16947,26 +17240,26 @@ function fastGit(root) {
|
|
|
16947
17240
|
else if (entry.isFile()) {
|
|
16948
17241
|
let text = "";
|
|
16949
17242
|
try {
|
|
16950
|
-
text =
|
|
17243
|
+
text = fs6.readFileSync(dotGit, "utf8");
|
|
16951
17244
|
} catch {
|
|
16952
17245
|
return null;
|
|
16953
17246
|
}
|
|
16954
17247
|
const match = /^gitdir: (.+)$/mu.exec(text);
|
|
16955
17248
|
if (!match)
|
|
16956
17249
|
return null;
|
|
16957
|
-
gitDir =
|
|
17250
|
+
gitDir = path10.resolve(dir, match[1].trim());
|
|
16958
17251
|
} else
|
|
16959
17252
|
return null;
|
|
16960
|
-
if (!
|
|
17253
|
+
if (!fs6.existsSync(path10.join(gitDir, "HEAD")))
|
|
16961
17254
|
return null;
|
|
16962
17255
|
} else if (isGitDir(dir))
|
|
16963
17256
|
gitDir = dir;
|
|
16964
17257
|
if (gitDir) {
|
|
16965
17258
|
let common = gitDir;
|
|
16966
17259
|
try {
|
|
16967
|
-
common =
|
|
17260
|
+
common = path10.resolve(gitDir, fs6.readFileSync(path10.join(gitDir, "commondir"), "utf8").trim());
|
|
16968
17261
|
} catch {}
|
|
16969
|
-
if (!
|
|
17262
|
+
if (!fs6.existsSync(path10.join(common, "objects")))
|
|
16970
17263
|
return null;
|
|
16971
17264
|
return {
|
|
16972
17265
|
kind: "repo",
|
|
@@ -16976,28 +17269,33 @@ function fastGit(root) {
|
|
|
16976
17269
|
reftable: reftableRefs(common)
|
|
16977
17270
|
};
|
|
16978
17271
|
}
|
|
16979
|
-
const parent =
|
|
17272
|
+
const parent = path10.dirname(dir);
|
|
16980
17273
|
if (parent === dir)
|
|
16981
17274
|
return { kind: "none" };
|
|
16982
17275
|
dir = parent;
|
|
16983
17276
|
}
|
|
16984
17277
|
}
|
|
17278
|
+
var outsideGit = (root) => {
|
|
17279
|
+
const dir = folderStoreDir(root);
|
|
17280
|
+
migrateFolderStore(root, dir);
|
|
17281
|
+
return { dir, shared: false, top: null };
|
|
17282
|
+
};
|
|
16985
17283
|
function resolveStore(root) {
|
|
16986
|
-
root =
|
|
17284
|
+
root = path10.resolve(root);
|
|
16987
17285
|
let stat = null;
|
|
16988
17286
|
try {
|
|
16989
|
-
stat =
|
|
17287
|
+
stat = fs6.statSync(root);
|
|
16990
17288
|
} catch {}
|
|
16991
17289
|
if (!stat)
|
|
16992
17290
|
return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
|
|
16993
17291
|
if (!stat.isDirectory())
|
|
16994
|
-
return { dir:
|
|
17292
|
+
return { dir: path10.join(root, ".workit"), shared: false, top: null };
|
|
16995
17293
|
const fast = fastGit(root);
|
|
16996
17294
|
if (fast?.kind === "none")
|
|
16997
|
-
return
|
|
17295
|
+
return outsideGit(root);
|
|
16998
17296
|
if (fast?.kind === "repo")
|
|
16999
17297
|
return {
|
|
17000
|
-
dir:
|
|
17298
|
+
dir: path10.join(fast.common, "workit"),
|
|
17001
17299
|
shared: true,
|
|
17002
17300
|
top: fast.top,
|
|
17003
17301
|
git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
|
|
@@ -17007,20 +17305,20 @@ function resolveStore(root) {
|
|
|
17007
17305
|
if (run.ok && common) {
|
|
17008
17306
|
const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
|
|
17009
17307
|
return {
|
|
17010
|
-
dir:
|
|
17308
|
+
dir: path10.join(real(path10.resolve(root, common)), "workit"),
|
|
17011
17309
|
shared: true,
|
|
17012
17310
|
top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
|
|
17013
17311
|
};
|
|
17014
17312
|
}
|
|
17015
17313
|
if (run.missing || !run.ok && NOT_A_REPO.test(run.stderr))
|
|
17016
|
-
return
|
|
17314
|
+
return outsideGit(root);
|
|
17017
17315
|
return new Error(`cannot locate the workit store: git rev-parse failed (${run.stderr.trim().split(`
|
|
17018
17316
|
`)[0] || "no output"}); fix the repository (git status should work here)`);
|
|
17019
17317
|
}
|
|
17020
17318
|
var rebasingBranch = (gitDir) => {
|
|
17021
17319
|
for (const state of ["rebase-merge", "rebase-apply"]) {
|
|
17022
17320
|
try {
|
|
17023
|
-
const ref =
|
|
17321
|
+
const ref = fs6.readFileSync(path10.join(gitDir, state, "head-name"), "utf8").trim();
|
|
17024
17322
|
const match = /^refs\/heads\/(.+)$/u.exec(ref);
|
|
17025
17323
|
if (match)
|
|
17026
17324
|
return match[1];
|
|
@@ -17035,7 +17333,7 @@ function resolveTaskKey(root, location) {
|
|
|
17035
17333
|
if (location.git && !location.git.reftable) {
|
|
17036
17334
|
let head = "";
|
|
17037
17335
|
try {
|
|
17038
|
-
head =
|
|
17336
|
+
head = fs6.readFileSync(path10.join(location.git.gitDir, "HEAD"), "utf8").trim();
|
|
17039
17337
|
} catch {}
|
|
17040
17338
|
const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
|
|
17041
17339
|
if (ref && ref[1] !== ".invalid")
|
|
@@ -17066,10 +17364,10 @@ function resolveTaskKey(root, location) {
|
|
|
17066
17364
|
return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
|
|
17067
17365
|
}
|
|
17068
17366
|
function checkoutRootOf(root, location) {
|
|
17069
|
-
const resolved =
|
|
17367
|
+
const resolved = path10.resolve(root);
|
|
17070
17368
|
let canonical = resolved;
|
|
17071
17369
|
try {
|
|
17072
|
-
canonical =
|
|
17370
|
+
canonical = fs6.realpathSync(resolved);
|
|
17073
17371
|
} catch {
|
|
17074
17372
|
return resolved;
|
|
17075
17373
|
}
|
|
@@ -17079,7 +17377,7 @@ function checkoutRootOf(root, location) {
|
|
|
17079
17377
|
if (real(canonical) === found.top)
|
|
17080
17378
|
return canonical;
|
|
17081
17379
|
try {
|
|
17082
|
-
return
|
|
17380
|
+
return fs6.realpathSync(found.top);
|
|
17083
17381
|
} catch {
|
|
17084
17382
|
return canonical;
|
|
17085
17383
|
}
|
|
@@ -17091,25 +17389,25 @@ function branchRenames(location) {
|
|
|
17091
17389
|
const walk = (dir) => {
|
|
17092
17390
|
let entries;
|
|
17093
17391
|
try {
|
|
17094
|
-
entries =
|
|
17392
|
+
entries = fs6.readdirSync(dir, { withFileTypes: true });
|
|
17095
17393
|
} catch {
|
|
17096
17394
|
return;
|
|
17097
17395
|
}
|
|
17098
17396
|
for (const entry of entries)
|
|
17099
17397
|
if (entry.isDirectory())
|
|
17100
|
-
walk(
|
|
17398
|
+
walk(path10.join(dir, entry.name));
|
|
17101
17399
|
else
|
|
17102
|
-
files.push(
|
|
17400
|
+
files.push(path10.join(dir, entry.name));
|
|
17103
17401
|
};
|
|
17104
|
-
walk(
|
|
17402
|
+
walk(path10.join(path10.dirname(location.dir), "logs", "refs", "heads"));
|
|
17105
17403
|
if (location.git)
|
|
17106
|
-
files.push(
|
|
17404
|
+
files.push(path10.join(location.git.gitDir, "logs", "HEAD"));
|
|
17107
17405
|
const seen = new Set;
|
|
17108
17406
|
const renames = [];
|
|
17109
17407
|
for (const file of files) {
|
|
17110
17408
|
let text = "";
|
|
17111
17409
|
try {
|
|
17112
|
-
text =
|
|
17410
|
+
text = fs6.readFileSync(file, "utf8");
|
|
17113
17411
|
} catch {
|
|
17114
17412
|
continue;
|
|
17115
17413
|
}
|
|
@@ -17134,13 +17432,7 @@ function followRenames(key, boundAt, renames) {
|
|
|
17134
17432
|
}
|
|
17135
17433
|
return current;
|
|
17136
17434
|
}
|
|
17137
|
-
var checkoutSlug = (root) =>
|
|
17138
|
-
let canonical = real(root);
|
|
17139
|
-
if (process.platform === "win32")
|
|
17140
|
-
canonical = canonical.toLowerCase();
|
|
17141
|
-
const base = path9.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
|
|
17142
|
-
return `${base}-${shortHash(canonical)}`;
|
|
17143
|
-
};
|
|
17435
|
+
var checkoutSlug = (root) => folderSlug(root);
|
|
17144
17436
|
|
|
17145
17437
|
// packages/workit-core/src/host-session.ts
|
|
17146
17438
|
var HOST_SESSION_VARS = [
|
|
@@ -17170,9 +17462,9 @@ function hostSessionFromEnv(env) {
|
|
|
17170
17462
|
}
|
|
17171
17463
|
return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
|
|
17172
17464
|
}
|
|
17173
|
-
var hash = (value) =>
|
|
17174
|
-
var userIssuedRoot = () =>
|
|
17175
|
-
var userTokenRoot = () =>
|
|
17465
|
+
var hash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 32);
|
|
17466
|
+
var userIssuedRoot = () => path11.join(resolveStateDir(), "issued");
|
|
17467
|
+
var userTokenRoot = () => path11.join(resolveStateDir(), "issued-tokens");
|
|
17176
17468
|
function migrateRepoIssued(cwd) {
|
|
17177
17469
|
if (cwd === undefined)
|
|
17178
17470
|
return;
|
|
@@ -17181,27 +17473,27 @@ function migrateRepoIssued(cwd) {
|
|
|
17181
17473
|
const location = resolveStore(cwd);
|
|
17182
17474
|
if (location instanceof Error)
|
|
17183
17475
|
return;
|
|
17184
|
-
old =
|
|
17185
|
-
if (!
|
|
17476
|
+
old = path11.join(location.dir, "hooks", "issued");
|
|
17477
|
+
if (!fs7.existsSync(old))
|
|
17186
17478
|
return;
|
|
17187
17479
|
} catch {
|
|
17188
17480
|
return;
|
|
17189
17481
|
}
|
|
17190
17482
|
for (const lead of safeList(old)) {
|
|
17191
17483
|
try {
|
|
17192
|
-
const from =
|
|
17193
|
-
if (!
|
|
17484
|
+
const from = path11.join(old, lead);
|
|
17485
|
+
if (!fs7.statSync(from).isDirectory())
|
|
17194
17486
|
continue;
|
|
17195
|
-
const to =
|
|
17196
|
-
|
|
17197
|
-
for (const id of
|
|
17487
|
+
const to = path11.join(userIssuedRoot(), lead);
|
|
17488
|
+
fs7.mkdirSync(to, { recursive: true, mode: 448 });
|
|
17489
|
+
for (const id of fs7.readdirSync(from)) {
|
|
17198
17490
|
try {
|
|
17199
|
-
|
|
17491
|
+
fs7.copyFileSync(path11.join(from, id), path11.join(to, id), fs7.constants.COPYFILE_EXCL);
|
|
17200
17492
|
} catch (error) {
|
|
17201
17493
|
if (error.code !== "EEXIST")
|
|
17202
17494
|
throw error;
|
|
17203
17495
|
}
|
|
17204
|
-
|
|
17496
|
+
fs7.rmSync(path11.join(from, id), { force: true });
|
|
17205
17497
|
}
|
|
17206
17498
|
removeIfEmpty(from);
|
|
17207
17499
|
} catch {}
|
|
@@ -17210,14 +17502,14 @@ function migrateRepoIssued(cwd) {
|
|
|
17210
17502
|
}
|
|
17211
17503
|
var safeList = (dir) => {
|
|
17212
17504
|
try {
|
|
17213
|
-
return
|
|
17505
|
+
return fs7.readdirSync(dir);
|
|
17214
17506
|
} catch {
|
|
17215
17507
|
return [];
|
|
17216
17508
|
}
|
|
17217
17509
|
};
|
|
17218
17510
|
var removeIfEmpty = (dir) => {
|
|
17219
17511
|
try {
|
|
17220
|
-
|
|
17512
|
+
fs7.rmdirSync(dir);
|
|
17221
17513
|
} catch {}
|
|
17222
17514
|
};
|
|
17223
17515
|
var issuedRecord = (cwd, claimed) => {
|
|
@@ -17226,7 +17518,7 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
17226
17518
|
return null;
|
|
17227
17519
|
migrateRepoIssued(cwd);
|
|
17228
17520
|
try {
|
|
17229
|
-
return
|
|
17521
|
+
return fs7.readFileSync(path11.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
17230
17522
|
} catch {
|
|
17231
17523
|
return null;
|
|
17232
17524
|
}
|
|
@@ -17236,9 +17528,9 @@ var issuedToken = (claimed) => {
|
|
|
17236
17528
|
const cut = claimed.lastIndexOf(":");
|
|
17237
17529
|
if (cut <= 0)
|
|
17238
17530
|
return { stored: null, leadBound: false };
|
|
17239
|
-
const dir =
|
|
17531
|
+
const dir = path11.join(userTokenRoot(), hash(claimed.slice(0, cut)));
|
|
17240
17532
|
try {
|
|
17241
|
-
const text =
|
|
17533
|
+
const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
|
|
17242
17534
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
17243
17535
|
} catch {
|
|
17244
17536
|
return { stored: null, leadBound: safeList(dir).length > 0 };
|
|
@@ -17257,8 +17549,8 @@ var OWN_CHILD_SHELL = new Set(["opencode", "pi"]);
|
|
|
17257
17549
|
|
|
17258
17550
|
// packages/workit-core/src/store/event-log.ts
|
|
17259
17551
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
17260
|
-
import
|
|
17261
|
-
import
|
|
17552
|
+
import fs8 from "node:fs";
|
|
17553
|
+
import path12 from "node:path";
|
|
17262
17554
|
var EVENT_VERSION = 1;
|
|
17263
17555
|
|
|
17264
17556
|
class LogDamage extends Error {
|
|
@@ -17287,7 +17579,7 @@ var parseEvent = (line, file, offset) => {
|
|
|
17287
17579
|
function readLog(file, from = 0, expectSeq = null) {
|
|
17288
17580
|
let fd;
|
|
17289
17581
|
try {
|
|
17290
|
-
fd =
|
|
17582
|
+
fd = fs8.openSync(file, "r");
|
|
17291
17583
|
} catch (error) {
|
|
17292
17584
|
if (error.code === "ENOENT")
|
|
17293
17585
|
return null;
|
|
@@ -17296,13 +17588,13 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
17296
17588
|
let bytes;
|
|
17297
17589
|
let size;
|
|
17298
17590
|
try {
|
|
17299
|
-
size =
|
|
17591
|
+
size = fs8.fstatSync(fd).size;
|
|
17300
17592
|
if (from > size)
|
|
17301
17593
|
throw new LogDamage(`${file}: shorter than its snapshot`);
|
|
17302
17594
|
bytes = Buffer.alloc(size - from);
|
|
17303
17595
|
let read = 0;
|
|
17304
17596
|
while (read < bytes.length) {
|
|
17305
|
-
const got =
|
|
17597
|
+
const got = fs8.readSync(fd, bytes, read, bytes.length - read, from + read);
|
|
17306
17598
|
if (got === 0)
|
|
17307
17599
|
break;
|
|
17308
17600
|
read += got;
|
|
@@ -17310,7 +17602,7 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
17310
17602
|
bytes = bytes.subarray(0, read);
|
|
17311
17603
|
size = from + read;
|
|
17312
17604
|
} finally {
|
|
17313
|
-
|
|
17605
|
+
fs8.closeSync(fd);
|
|
17314
17606
|
}
|
|
17315
17607
|
const events = [];
|
|
17316
17608
|
let start = 0;
|
|
@@ -17335,11 +17627,11 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
17335
17627
|
}
|
|
17336
17628
|
var fsyncDirectory = (dir) => {
|
|
17337
17629
|
try {
|
|
17338
|
-
const fd =
|
|
17630
|
+
const fd = fs8.openSync(dir, "r");
|
|
17339
17631
|
try {
|
|
17340
|
-
|
|
17632
|
+
fs8.fsyncSync(fd);
|
|
17341
17633
|
} finally {
|
|
17342
|
-
|
|
17634
|
+
fs8.closeSync(fd);
|
|
17343
17635
|
}
|
|
17344
17636
|
} catch (error) {
|
|
17345
17637
|
if (process.platform !== "win32")
|
|
@@ -17349,46 +17641,46 @@ var fsyncDirectory = (dir) => {
|
|
|
17349
17641
|
function appendEvent(file, event, validEnd) {
|
|
17350
17642
|
const line = Buffer.from(`${JSON.stringify(event)}
|
|
17351
17643
|
`, "utf8");
|
|
17352
|
-
const created = !
|
|
17353
|
-
if (!created &&
|
|
17354
|
-
const cut =
|
|
17644
|
+
const created = !fs8.existsSync(file);
|
|
17645
|
+
if (!created && fs8.statSync(file).size !== validEnd) {
|
|
17646
|
+
const cut = fs8.openSync(file, "r+");
|
|
17355
17647
|
try {
|
|
17356
|
-
|
|
17357
|
-
|
|
17648
|
+
fs8.ftruncateSync(cut, validEnd);
|
|
17649
|
+
fs8.fsyncSync(cut);
|
|
17358
17650
|
} finally {
|
|
17359
|
-
|
|
17651
|
+
fs8.closeSync(cut);
|
|
17360
17652
|
}
|
|
17361
17653
|
}
|
|
17362
|
-
const fd =
|
|
17654
|
+
const fd = fs8.openSync(file, "a", 384);
|
|
17363
17655
|
try {
|
|
17364
17656
|
let written = 0;
|
|
17365
17657
|
while (written < line.length)
|
|
17366
|
-
written +=
|
|
17367
|
-
|
|
17658
|
+
written += fs8.writeSync(fd, line, written, line.length - written);
|
|
17659
|
+
fs8.fsyncSync(fd);
|
|
17368
17660
|
} finally {
|
|
17369
|
-
|
|
17661
|
+
fs8.closeSync(fd);
|
|
17370
17662
|
}
|
|
17371
17663
|
if (created)
|
|
17372
|
-
fsyncDirectory(
|
|
17664
|
+
fsyncDirectory(path12.dirname(file));
|
|
17373
17665
|
return validEnd;
|
|
17374
17666
|
}
|
|
17375
17667
|
function replaceFile(file, bytes, durable) {
|
|
17376
17668
|
const temporary = `${file}.${process.pid}.${randomUUID2()}.tmp`;
|
|
17377
17669
|
try {
|
|
17378
|
-
const fd =
|
|
17670
|
+
const fd = fs8.openSync(temporary, "wx", 384);
|
|
17379
17671
|
try {
|
|
17380
|
-
|
|
17672
|
+
fs8.writeSync(fd, bytes);
|
|
17381
17673
|
if (durable)
|
|
17382
|
-
|
|
17674
|
+
fs8.fsyncSync(fd);
|
|
17383
17675
|
} finally {
|
|
17384
|
-
|
|
17676
|
+
fs8.closeSync(fd);
|
|
17385
17677
|
}
|
|
17386
17678
|
renameWithRetry(temporary, file);
|
|
17387
17679
|
if (durable)
|
|
17388
|
-
fsyncDirectory(
|
|
17680
|
+
fsyncDirectory(path12.dirname(file));
|
|
17389
17681
|
} catch (error) {
|
|
17390
17682
|
try {
|
|
17391
|
-
|
|
17683
|
+
fs8.unlinkSync(temporary);
|
|
17392
17684
|
} catch {}
|
|
17393
17685
|
throw error;
|
|
17394
17686
|
}
|
|
@@ -17413,7 +17705,7 @@ var retryTransient = (run) => {
|
|
|
17413
17705
|
}
|
|
17414
17706
|
}
|
|
17415
17707
|
};
|
|
17416
|
-
var renameWithRetry = (from, to) => retryTransient(() =>
|
|
17708
|
+
var renameWithRetry = (from, to) => retryTransient(() => fs8.renameSync(from, to));
|
|
17417
17709
|
|
|
17418
17710
|
// packages/workit-core/src/core/checkout-leftovers.ts
|
|
17419
17711
|
var CHECKOUT_LEFTOVERS = [
|
|
@@ -17542,7 +17834,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
|
|
|
17542
17834
|
});
|
|
17543
17835
|
|
|
17544
17836
|
// packages/workit-core/src/store/reduce.ts
|
|
17545
|
-
import { createHash as
|
|
17837
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
17546
17838
|
var OPENING_TYPES = new Set([
|
|
17547
17839
|
"task.opened",
|
|
17548
17840
|
"task.imported",
|
|
@@ -17571,7 +17863,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
17571
17863
|
var isKey = (value) => isObject4(value) && typeof value.key === "string" && (value.kind === "branch" || value.kind === "detached" || value.kind === "dir") && (value.branch === null || typeof value.branch === "string");
|
|
17572
17864
|
var BLOB_REF = "$blob";
|
|
17573
17865
|
var blobRef = (value) => isObject4(value) && Object.keys(value).length === 1 && typeof value[BLOB_REF] === "string" && /^[0-9a-f]{64}$/.test(value[BLOB_REF]) ? value[BLOB_REF] : null;
|
|
17574
|
-
var blobDigest = (value) =>
|
|
17866
|
+
var blobDigest = (value) => createHash8("sha256").update(JSON.stringify(value)).digest("hex");
|
|
17575
17867
|
var toBlob = (value, blobs) => {
|
|
17576
17868
|
if (!isObject4(value))
|
|
17577
17869
|
return value;
|
|
@@ -17685,8 +17977,8 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
|
|
|
17685
17977
|
|
|
17686
17978
|
// packages/workit-core/src/core/task-read.ts
|
|
17687
17979
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
17688
|
-
import * as
|
|
17689
|
-
import
|
|
17980
|
+
import * as fs13 from "node:fs";
|
|
17981
|
+
import path16 from "node:path";
|
|
17690
17982
|
|
|
17691
17983
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
17692
17984
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -17737,10 +18029,10 @@ function sameFileIdentity(left, right, platform = process.platform) {
|
|
|
17737
18029
|
// node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
|
|
17738
18030
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
17739
18031
|
import fsSync from "node:fs";
|
|
17740
|
-
import
|
|
18032
|
+
import path13 from "node:path";
|
|
17741
18033
|
|
|
17742
18034
|
// node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
17743
|
-
import
|
|
18035
|
+
import fs9 from "node:fs";
|
|
17744
18036
|
|
|
17745
18037
|
// node_modules/@openclaw/fs-safe/dist/byte-budget.js
|
|
17746
18038
|
function normalizeMaxBytes(value, options = {}) {
|
|
@@ -17777,7 +18069,7 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
17777
18069
|
let total = 0;
|
|
17778
18070
|
while (true) {
|
|
17779
18071
|
const length = nextReadLength(total, maxBytes, scratch.length);
|
|
17780
|
-
const bytesRead =
|
|
18072
|
+
const bytesRead = fs9.readSync(fd, scratch, 0, length, null);
|
|
17781
18073
|
if (bytesRead === 0) {
|
|
17782
18074
|
return Buffer.concat(chunks, total);
|
|
17783
18075
|
}
|
|
@@ -17786,9 +18078,9 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
17786
18078
|
}
|
|
17787
18079
|
|
|
17788
18080
|
// node_modules/@openclaw/fs-safe/dist/read-open-flags.js
|
|
17789
|
-
import
|
|
18081
|
+
import fs10 from "node:fs";
|
|
17790
18082
|
function resolveReadOpenFlags(options) {
|
|
17791
|
-
const constants = options?.constants ??
|
|
18083
|
+
const constants = options?.constants ?? fs10.constants;
|
|
17792
18084
|
const noFollow = process.platform !== "win32" && options?.followSymlinks !== true && typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
17793
18085
|
const nonBlocking = process.platform !== "win32" && typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;
|
|
17794
18086
|
return constants.O_RDONLY | noFollow | nonBlocking;
|
|
@@ -17827,13 +18119,13 @@ ${ownershipToken}
|
|
|
17827
18119
|
return { raw, ownershipToken };
|
|
17828
18120
|
}
|
|
17829
18121
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
17830
|
-
const resolved =
|
|
17831
|
-
const lexicalRelative =
|
|
17832
|
-
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${
|
|
17833
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
18122
|
+
const resolved = path13.resolve(lockPath);
|
|
18123
|
+
const lexicalRelative = path13.relative(lockRoot.rootDir, resolved);
|
|
18124
|
+
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path13.sep}`) && !path13.isAbsolute(lexicalRelative) ? lexicalRelative : path13.relative(lockRoot.rootReal, resolved);
|
|
18125
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path13.sep}`) || path13.isAbsolute(relative)) {
|
|
17834
18126
|
throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
|
|
17835
18127
|
}
|
|
17836
|
-
return relative.split(
|
|
18128
|
+
return relative.split(path13.sep).join(path13.posix.sep);
|
|
17837
18129
|
}
|
|
17838
18130
|
function parseSidecarLockPayload(raw, parser) {
|
|
17839
18131
|
if (parser) {
|
|
@@ -17979,8 +18271,8 @@ function getFsSafeLockConfig() {
|
|
|
17979
18271
|
}
|
|
17980
18272
|
|
|
17981
18273
|
// node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
|
|
17982
|
-
import
|
|
17983
|
-
import
|
|
18274
|
+
import fs11 from "node:fs";
|
|
18275
|
+
import path14 from "node:path";
|
|
17984
18276
|
|
|
17985
18277
|
// node_modules/@openclaw/fs-safe/dist/timing.js
|
|
17986
18278
|
function sleepSync(ms) {
|
|
@@ -18010,7 +18302,7 @@ function releaseAllSyncHeldLocks() {
|
|
|
18010
18302
|
}
|
|
18011
18303
|
try {
|
|
18012
18304
|
if (held.fd !== undefined)
|
|
18013
|
-
|
|
18305
|
+
fs11.closeSync(held.fd);
|
|
18014
18306
|
} catch {}
|
|
18015
18307
|
try {
|
|
18016
18308
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
@@ -18045,7 +18337,7 @@ function releaseSyncHeldLock(held) {
|
|
|
18045
18337
|
if (held.fd !== undefined) {
|
|
18046
18338
|
const fd = held.fd;
|
|
18047
18339
|
held.fd = undefined;
|
|
18048
|
-
|
|
18340
|
+
fs11.closeSync(fd);
|
|
18049
18341
|
}
|
|
18050
18342
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
18051
18343
|
heldLocks.delete(held.normalizedTargetPath);
|
|
@@ -18068,29 +18360,29 @@ function createSyncHeldLockHandle(held) {
|
|
|
18068
18360
|
};
|
|
18069
18361
|
}
|
|
18070
18362
|
function canonicalLockParentSync(parent) {
|
|
18071
|
-
return process.platform === "win32" ?
|
|
18363
|
+
return process.platform === "win32" ? fs11.realpathSync.native(parent) : fs11.realpathSync(parent);
|
|
18072
18364
|
}
|
|
18073
18365
|
function normalizeTargetPath(targetPath) {
|
|
18074
|
-
const resolved =
|
|
18075
|
-
|
|
18366
|
+
const resolved = path14.resolve(targetPath);
|
|
18367
|
+
fs11.mkdirSync(path14.dirname(resolved), { recursive: true });
|
|
18076
18368
|
try {
|
|
18077
|
-
return
|
|
18369
|
+
return path14.join(canonicalLockParentSync(path14.dirname(resolved)), path14.basename(resolved));
|
|
18078
18370
|
} catch {
|
|
18079
18371
|
return resolved;
|
|
18080
18372
|
}
|
|
18081
18373
|
}
|
|
18082
18374
|
function boundedLockPath(lockPath, lockRoot) {
|
|
18083
|
-
const resolved =
|
|
18375
|
+
const resolved = path14.resolve(lockPath);
|
|
18084
18376
|
if (!lockRoot)
|
|
18085
18377
|
return resolved;
|
|
18086
18378
|
relativeSidecarLockPath(lockRoot, resolved);
|
|
18087
|
-
const parent =
|
|
18379
|
+
const parent = path14.dirname(resolved);
|
|
18088
18380
|
const parentReal = canonicalLockParentSync(parent);
|
|
18089
|
-
const parentRelative =
|
|
18090
|
-
if (parentRelative === ".." || parentRelative.startsWith(`..${
|
|
18381
|
+
const parentRelative = path14.relative(lockRoot.rootReal, parentReal);
|
|
18382
|
+
if (parentRelative === ".." || parentRelative.startsWith(`..${path14.sep}`) || path14.isAbsolute(parentRelative)) {
|
|
18091
18383
|
throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
|
|
18092
18384
|
}
|
|
18093
|
-
return
|
|
18385
|
+
return path14.join(parentReal, path14.basename(resolved));
|
|
18094
18386
|
}
|
|
18095
18387
|
function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
18096
18388
|
const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
|
|
@@ -18100,7 +18392,7 @@ function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
|
18100
18392
|
}
|
|
18101
18393
|
function reclaimGuardExists(reclaimGuardPath) {
|
|
18102
18394
|
try {
|
|
18103
|
-
|
|
18395
|
+
fs11.lstatSync(reclaimGuardPath);
|
|
18104
18396
|
return true;
|
|
18105
18397
|
} catch (error) {
|
|
18106
18398
|
if (error.code === "ENOENT")
|
|
@@ -18164,19 +18456,19 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
18164
18456
|
const { raw, ownershipToken } = serializeSidecarLockPayload(payload);
|
|
18165
18457
|
let lockFileCreateDenied = false;
|
|
18166
18458
|
try {
|
|
18167
|
-
const noFollow = process.platform !== "win32" && typeof
|
|
18459
|
+
const noFollow = process.platform !== "win32" && typeof fs11.constants.O_NOFOLLOW === "number" ? fs11.constants.O_NOFOLLOW : 0;
|
|
18168
18460
|
try {
|
|
18169
|
-
fd =
|
|
18461
|
+
fd = fs11.openSync(lockPath, fs11.constants.O_WRONLY | fs11.constants.O_CREAT | fs11.constants.O_EXCL | noFollow, 384);
|
|
18170
18462
|
} catch (error) {
|
|
18171
18463
|
lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
|
|
18172
18464
|
throw error;
|
|
18173
18465
|
}
|
|
18174
|
-
|
|
18175
|
-
|
|
18466
|
+
fs11.writeFileSync(fd, raw, "utf8");
|
|
18467
|
+
fs11.fsyncSync(fd);
|
|
18176
18468
|
const snapshot = {
|
|
18177
18469
|
raw,
|
|
18178
18470
|
payload,
|
|
18179
|
-
stat:
|
|
18471
|
+
stat: fs11.fstatSync(fd),
|
|
18180
18472
|
ownershipToken
|
|
18181
18473
|
};
|
|
18182
18474
|
const createdHeld = {
|
|
@@ -18211,8 +18503,8 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
18211
18503
|
return returnedHandle;
|
|
18212
18504
|
} catch (error) {
|
|
18213
18505
|
if (fd !== undefined) {
|
|
18214
|
-
const failed = { payload: null, stat:
|
|
18215
|
-
|
|
18506
|
+
const failed = { payload: null, stat: fs11.fstatSync(fd) };
|
|
18507
|
+
fs11.closeSync(fd);
|
|
18216
18508
|
fd = undefined;
|
|
18217
18509
|
removeSidecarLockIfUnchangedSync(lockPath, failed);
|
|
18218
18510
|
}
|
|
@@ -18261,7 +18553,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
18261
18553
|
})) {
|
|
18262
18554
|
let ownsReclaimGuard = false;
|
|
18263
18555
|
try {
|
|
18264
|
-
|
|
18556
|
+
fs11.mkdirSync(reclaimGuardPath);
|
|
18265
18557
|
ownsReclaimGuard = true;
|
|
18266
18558
|
if (removeSidecarLockIfUnchangedSync(lockPath, snapshot))
|
|
18267
18559
|
continue;
|
|
@@ -18274,7 +18566,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
18274
18566
|
} finally {
|
|
18275
18567
|
if (ownsReclaimGuard) {
|
|
18276
18568
|
try {
|
|
18277
|
-
|
|
18569
|
+
fs11.rmdirSync(reclaimGuardPath);
|
|
18278
18570
|
} catch {}
|
|
18279
18571
|
}
|
|
18280
18572
|
}
|
|
@@ -18290,27 +18582,27 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
18290
18582
|
}
|
|
18291
18583
|
}
|
|
18292
18584
|
// packages/workit-core/src/core/package-root.ts
|
|
18293
|
-
import { existsSync as
|
|
18294
|
-
import
|
|
18585
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
18586
|
+
import path15 from "node:path";
|
|
18295
18587
|
import { fileURLToPath } from "node:url";
|
|
18296
18588
|
var packageRoot = () => {
|
|
18297
|
-
let dir =
|
|
18589
|
+
let dir = path15.dirname(fileURLToPath(import.meta.url));
|
|
18298
18590
|
while (true) {
|
|
18299
|
-
const parent =
|
|
18300
|
-
if (
|
|
18591
|
+
const parent = path15.dirname(dir);
|
|
18592
|
+
if (existsSync5(path15.join(dir, "package.json")) || parent === dir)
|
|
18301
18593
|
return dir;
|
|
18302
18594
|
dir = parent;
|
|
18303
18595
|
}
|
|
18304
18596
|
};
|
|
18305
18597
|
var assetRoot = () => {
|
|
18306
18598
|
const root = packageRoot();
|
|
18307
|
-
const assets =
|
|
18308
|
-
return
|
|
18599
|
+
const assets = path15.join(root, "assets");
|
|
18600
|
+
return existsSync5(assets) ? assets : root;
|
|
18309
18601
|
};
|
|
18310
18602
|
|
|
18311
18603
|
// packages/workit-core/src/core/store-lock.ts
|
|
18312
18604
|
import { spawnSync as spawnSync10 } from "node:child_process";
|
|
18313
|
-
import
|
|
18605
|
+
import fs12 from "node:fs";
|
|
18314
18606
|
import { hostname } from "node:os";
|
|
18315
18607
|
var metadataLockSchema = object({
|
|
18316
18608
|
pid: number2().int().nonnegative().safe(),
|
|
@@ -18353,7 +18645,7 @@ var parseProcStatStart = (stat) => {
|
|
|
18353
18645
|
};
|
|
18354
18646
|
var readProcStat = (pid) => {
|
|
18355
18647
|
try {
|
|
18356
|
-
return
|
|
18648
|
+
return fs12.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
18357
18649
|
} catch {
|
|
18358
18650
|
return null;
|
|
18359
18651
|
}
|
|
@@ -18382,7 +18674,7 @@ var processStartOf = (pid, deps = {}) => {
|
|
|
18382
18674
|
};
|
|
18383
18675
|
var readTrimmed = (file) => {
|
|
18384
18676
|
try {
|
|
18385
|
-
return
|
|
18677
|
+
return fs12.readFileSync(file, "utf8").trim() || null;
|
|
18386
18678
|
} catch {
|
|
18387
18679
|
return null;
|
|
18388
18680
|
}
|
|
@@ -18393,7 +18685,7 @@ var localLockHost = () => {
|
|
|
18393
18685
|
return cachedLockHost;
|
|
18394
18686
|
let pidns = null;
|
|
18395
18687
|
try {
|
|
18396
|
-
pidns = /\[(\d+)\]/.exec(
|
|
18688
|
+
pidns = /\[(\d+)\]/.exec(fs12.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
|
|
18397
18689
|
} catch {}
|
|
18398
18690
|
const boot = readTrimmed("/proc/sys/kernel/random/boot_id");
|
|
18399
18691
|
cachedLockHost = pidns || boot ? `${hostname()}#${pidns ?? "?"}:${boot ?? "?"}` : hostname();
|
|
@@ -18439,7 +18731,7 @@ var classifyLockOwner = (payload, ageMs, localHost = localLockHost(), options =
|
|
|
18439
18731
|
};
|
|
18440
18732
|
var ageOf = (file, nowMs) => {
|
|
18441
18733
|
try {
|
|
18442
|
-
return nowMs -
|
|
18734
|
+
return nowMs - fs12.lstatSync(file).mtimeMs;
|
|
18443
18735
|
} catch {
|
|
18444
18736
|
return null;
|
|
18445
18737
|
}
|
|
@@ -18450,7 +18742,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
|
|
|
18450
18742
|
if (age === null || age <= RECLAIM_GUARD_TTL_MS)
|
|
18451
18743
|
return false;
|
|
18452
18744
|
try {
|
|
18453
|
-
|
|
18745
|
+
fs12.rmdirSync(guard);
|
|
18454
18746
|
return true;
|
|
18455
18747
|
} catch {
|
|
18456
18748
|
return false;
|
|
@@ -18495,7 +18787,7 @@ var indexEntry = (task, key, legacy, file) => {
|
|
|
18495
18787
|
};
|
|
18496
18788
|
var fileSignature = (file) => {
|
|
18497
18789
|
try {
|
|
18498
|
-
const stat =
|
|
18790
|
+
const stat = fs13.statSync(file, { bigint: true });
|
|
18499
18791
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
18500
18792
|
} catch {
|
|
18501
18793
|
return null;
|
|
@@ -18512,7 +18804,7 @@ var cachedRuntimeVersion = null;
|
|
|
18512
18804
|
var runtimeVersion = () => {
|
|
18513
18805
|
if (cachedRuntimeVersion === null) {
|
|
18514
18806
|
try {
|
|
18515
|
-
const pkg = JSON.parse(
|
|
18807
|
+
const pkg = JSON.parse(fs13.readFileSync(path16.join(packageRoot(), "package.json"), "utf8"));
|
|
18516
18808
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
18517
18809
|
} catch {
|
|
18518
18810
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -18534,14 +18826,14 @@ var isNewerVersion = (candidate, current) => {
|
|
|
18534
18826
|
var validId = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value);
|
|
18535
18827
|
var readText2 = (file) => {
|
|
18536
18828
|
try {
|
|
18537
|
-
return
|
|
18829
|
+
return fs13.readFileSync(file, "utf8");
|
|
18538
18830
|
} catch {
|
|
18539
18831
|
return "";
|
|
18540
18832
|
}
|
|
18541
18833
|
};
|
|
18542
18834
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
18543
18835
|
var branchStart = (location, branch, aliases) => {
|
|
18544
|
-
const first = readText2(
|
|
18836
|
+
const first = readText2(path16.join(path16.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
18545
18837
|
`, 1)[0];
|
|
18546
18838
|
const created = REFLOG_LINE.exec(first);
|
|
18547
18839
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -18551,7 +18843,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
18551
18843
|
return start;
|
|
18552
18844
|
if (!location.git)
|
|
18553
18845
|
return null;
|
|
18554
|
-
for (const line of readText2(
|
|
18846
|
+
for (const line of readText2(path16.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
18555
18847
|
`)) {
|
|
18556
18848
|
const entry = REFLOG_LINE.exec(line);
|
|
18557
18849
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -18561,23 +18853,23 @@ var branchStart = (location, branch, aliases) => {
|
|
|
18561
18853
|
}
|
|
18562
18854
|
return null;
|
|
18563
18855
|
};
|
|
18564
|
-
var refExists2 = (common, ref) =>
|
|
18856
|
+
var refExists2 = (common, ref) => fs13.existsSync(path16.join(common, ref)) || readText2(path16.join(common, "packed-refs")).includes(` ${ref}
|
|
18565
18857
|
`);
|
|
18566
18858
|
var origins = new Map;
|
|
18567
18859
|
var sameDirectoryIdentity = (left, right) => {
|
|
18568
|
-
if (!
|
|
18860
|
+
if (!path16.isAbsolute(left) || !path16.isAbsolute(right))
|
|
18569
18861
|
return false;
|
|
18570
|
-
const normalizedLeft =
|
|
18571
|
-
const normalizedRight =
|
|
18862
|
+
const normalizedLeft = path16.resolve(left);
|
|
18863
|
+
const normalizedRight = path16.resolve(right);
|
|
18572
18864
|
try {
|
|
18573
|
-
const a =
|
|
18574
|
-
const b =
|
|
18865
|
+
const a = fs13.statSync(normalizedLeft, { bigint: true });
|
|
18866
|
+
const b = fs13.statSync(normalizedRight, { bigint: true });
|
|
18575
18867
|
if (!a.isDirectory() || !b.isDirectory())
|
|
18576
18868
|
return false;
|
|
18577
18869
|
if (process.platform === "win32" ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase() : normalizedLeft === normalizedRight)
|
|
18578
18870
|
return true;
|
|
18579
|
-
const canonicalLeft =
|
|
18580
|
-
const canonicalRight =
|
|
18871
|
+
const canonicalLeft = fs13.realpathSync(normalizedLeft);
|
|
18872
|
+
const canonicalRight = fs13.realpathSync(normalizedRight);
|
|
18581
18873
|
if (process.platform === "win32" ? canonicalLeft.toLowerCase() === canonicalRight.toLowerCase() : canonicalLeft === canonicalRight)
|
|
18582
18874
|
return true;
|
|
18583
18875
|
return a.dev === b.dev && a.ino !== 0n && a.ino === b.ino;
|
|
@@ -18602,14 +18894,14 @@ class TaskReader {
|
|
|
18602
18894
|
located;
|
|
18603
18895
|
migrationChecked = false;
|
|
18604
18896
|
constructor(root, options = {}) {
|
|
18605
|
-
const resolved =
|
|
18606
|
-
this.origin =
|
|
18897
|
+
const resolved = path16.resolve(root);
|
|
18898
|
+
this.origin = fs13.existsSync(resolved) ? fs13.realpathSync(resolved) : resolved;
|
|
18607
18899
|
this.located = resolveStore(this.origin);
|
|
18608
18900
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
18609
18901
|
this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
|
|
18610
18902
|
}
|
|
18611
18903
|
location() {
|
|
18612
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared &&
|
|
18904
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path16.join(this.root, ".git"))) {
|
|
18613
18905
|
this.located = undefined;
|
|
18614
18906
|
this.migrationChecked = false;
|
|
18615
18907
|
}
|
|
@@ -18673,7 +18965,7 @@ class TaskReader {
|
|
|
18673
18965
|
const tasksDir = this.paths().tasks;
|
|
18674
18966
|
let names;
|
|
18675
18967
|
try {
|
|
18676
|
-
names =
|
|
18968
|
+
names = fs13.existsSync(tasksDir) ? fs13.readdirSync(tasksDir).filter((name) => validId(name)) : [];
|
|
18677
18969
|
} catch (error) {
|
|
18678
18970
|
return failure2("storage_error", `unable to list tasks: ${String(error)}`, {
|
|
18679
18971
|
path: tasksDir
|
|
@@ -18714,7 +19006,7 @@ class TaskReader {
|
|
|
18714
19006
|
const file = this.paths().workspace;
|
|
18715
19007
|
let bytes;
|
|
18716
19008
|
try {
|
|
18717
|
-
bytes = retryTransient(() =>
|
|
19009
|
+
bytes = retryTransient(() => fs13.readFileSync(file, "utf8"));
|
|
18718
19010
|
} catch (error) {
|
|
18719
19011
|
if (error.code === "ENOENT")
|
|
18720
19012
|
return success(null, null, null);
|
|
@@ -18767,14 +19059,14 @@ class TaskReader {
|
|
|
18767
19059
|
const branch = key.ok ? key.data.branch : null;
|
|
18768
19060
|
if (!branch || !location.ok)
|
|
18769
19061
|
return success(null, null, null);
|
|
18770
|
-
const common =
|
|
18771
|
-
const heads =
|
|
18772
|
-
const headLog = location.data.git ?
|
|
19062
|
+
const common = path16.dirname(location.data.dir);
|
|
19063
|
+
const heads = path16.join(common, "logs", "refs", "heads");
|
|
19064
|
+
const headLog = location.data.git ? path16.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
18773
19065
|
const signatures = [
|
|
18774
|
-
|
|
19066
|
+
path16.join(heads, branch),
|
|
18775
19067
|
headLog,
|
|
18776
19068
|
heads,
|
|
18777
|
-
|
|
19069
|
+
path16.join(common, "packed-refs")
|
|
18778
19070
|
].map((file) => fileSignature(file) ?? "-");
|
|
18779
19071
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
18780
19072
|
let resolved = origins.get(slot);
|
|
@@ -18786,7 +19078,7 @@ class TaskReader {
|
|
|
18786
19078
|
aliases.push(rename.from);
|
|
18787
19079
|
const start = branchStart(location.data, branch, aliases);
|
|
18788
19080
|
const slash = start?.indexOf("/") ?? -1;
|
|
18789
|
-
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(
|
|
19081
|
+
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path16.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
|
|
18790
19082
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
18791
19083
|
resolved = {
|
|
18792
19084
|
signature: signatures.join("|"),
|
|
@@ -18806,27 +19098,27 @@ class TaskReader {
|
|
|
18806
19098
|
}
|
|
18807
19099
|
paths() {
|
|
18808
19100
|
const location = this.location();
|
|
18809
|
-
const dir = location.ok ? location.data.dir :
|
|
18810
|
-
const checkout =
|
|
19101
|
+
const dir = location.ok ? location.data.dir : path16.join(this.root, ".workit");
|
|
19102
|
+
const checkout = path16.join(dir, "checkouts", checkoutSlug(this.root));
|
|
18811
19103
|
return {
|
|
18812
19104
|
dir,
|
|
18813
19105
|
shared: location.ok ? location.data.shared : false,
|
|
18814
|
-
marker:
|
|
19106
|
+
marker: path16.join(dir, "store.json"),
|
|
18815
19107
|
checkout,
|
|
18816
|
-
workspace:
|
|
18817
|
-
checkoutLock:
|
|
18818
|
-
tasks:
|
|
18819
|
-
index:
|
|
18820
|
-
blobs:
|
|
18821
|
-
legacy:
|
|
18822
|
-
v2:
|
|
19108
|
+
workspace: path16.join(checkout, "workspace.json"),
|
|
19109
|
+
checkoutLock: path16.join(checkout, "metadata.lock"),
|
|
19110
|
+
tasks: path16.join(dir, "tasks"),
|
|
19111
|
+
index: path16.join(dir, "task-index.json"),
|
|
19112
|
+
blobs: path16.join(dir, "blobs", "candidates"),
|
|
19113
|
+
legacy: path16.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
19114
|
+
v2: path16.join(this.root, ".workit")
|
|
18823
19115
|
};
|
|
18824
19116
|
}
|
|
18825
19117
|
eventsPath(taskId) {
|
|
18826
|
-
return
|
|
19118
|
+
return path16.join(this.paths().tasks, taskId, "events.jsonl");
|
|
18827
19119
|
}
|
|
18828
19120
|
snapshotPath(taskId) {
|
|
18829
|
-
return
|
|
19121
|
+
return path16.join(this.paths().tasks, taskId, "snapshot.json");
|
|
18830
19122
|
}
|
|
18831
19123
|
ready(write = false) {
|
|
18832
19124
|
const location = this.location();
|
|
@@ -18836,7 +19128,7 @@ class TaskReader {
|
|
|
18836
19128
|
return success(null, null, null);
|
|
18837
19129
|
const dirs = this.paths();
|
|
18838
19130
|
try {
|
|
18839
|
-
const marker = JSON.parse(
|
|
19131
|
+
const marker = JSON.parse(fs13.readFileSync(dirs.marker, "utf8"));
|
|
18840
19132
|
if (typeof marker.version === "number" && marker.version > STORE_FORMAT)
|
|
18841
19133
|
return failure2("recovery_required", `the workit store at ${dirs.dir} has format ${marker.version}; upgrade Workit to use it`, { path: dirs.marker });
|
|
18842
19134
|
} catch {}
|
|
@@ -18861,7 +19153,7 @@ class TaskReader {
|
|
|
18861
19153
|
return {
|
|
18862
19154
|
read: (digest) => {
|
|
18863
19155
|
try {
|
|
18864
|
-
return JSON.parse(
|
|
19156
|
+
return JSON.parse(fs13.readFileSync(path16.join(dir, `${digest}.json`), "utf8"));
|
|
18865
19157
|
} catch (error) {
|
|
18866
19158
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
18867
19159
|
}
|
|
@@ -18948,7 +19240,7 @@ class TaskReader {
|
|
|
18948
19240
|
}
|
|
18949
19241
|
readSnapshot(taskId) {
|
|
18950
19242
|
try {
|
|
18951
|
-
const value = JSON.parse(
|
|
19243
|
+
const value = JSON.parse(fs13.readFileSync(this.snapshotPath(taskId), "utf8"));
|
|
18952
19244
|
if (!isObject5(value) || value.v !== 1 || value.task !== taskId || typeof value.seq !== "number" || typeof value.lastId !== "string" || typeof value.lastStart !== "number" || typeof value.end !== "number" || !isObject5(value.record))
|
|
18953
19245
|
return null;
|
|
18954
19246
|
return value;
|
|
@@ -18975,7 +19267,7 @@ class TaskReader {
|
|
|
18975
19267
|
}
|
|
18976
19268
|
readIndex() {
|
|
18977
19269
|
try {
|
|
18978
|
-
const value = JSON.parse(
|
|
19270
|
+
const value = JSON.parse(fs13.readFileSync(this.paths().index, "utf8"));
|
|
18979
19271
|
if (!isObject5(value) || value.version !== INDEX_VERSION || !isObject5(value.tasks))
|
|
18980
19272
|
return {};
|
|
18981
19273
|
const tasks = {};
|
|
@@ -18989,7 +19281,7 @@ class TaskReader {
|
|
|
18989
19281
|
}
|
|
18990
19282
|
writeIndex(entries) {
|
|
18991
19283
|
try {
|
|
18992
|
-
|
|
19284
|
+
fs13.mkdirSync(this.paths().tasks, { recursive: true });
|
|
18993
19285
|
replaceFile(this.paths().index, JSON.stringify({
|
|
18994
19286
|
version: INDEX_VERSION,
|
|
18995
19287
|
tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
|
|
@@ -19027,64 +19319,74 @@ class TaskReader {
|
|
|
19027
19319
|
return failure2("recovery_required", `${label} record does not satisfy its schema`);
|
|
19028
19320
|
}
|
|
19029
19321
|
v2Dirs() {
|
|
19030
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
19322
|
+
return [...new Set([this.root, this.origin])].map((dir) => path16.join(dir, ".workit"));
|
|
19031
19323
|
}
|
|
19032
19324
|
pendingMigrations() {
|
|
19033
19325
|
return this.v2Dirs().filter((dir) => {
|
|
19034
|
-
const raw = this.readV2Workspace(
|
|
19326
|
+
const raw = this.readV2Workspace(path16.join(dir, "workspace.json"));
|
|
19035
19327
|
return raw !== null && raw !== TOMBSTONE;
|
|
19036
19328
|
});
|
|
19037
19329
|
}
|
|
19038
19330
|
adoptLocalStore() {
|
|
19331
|
+
if (!this.paths().shared)
|
|
19332
|
+
return success(null, null, null);
|
|
19333
|
+
for (const local of [this.paths().v2, folderStoreDir(this.root)]) {
|
|
19334
|
+
const adopted = this.adoptStoreFrom(local);
|
|
19335
|
+
if (!adopted.ok)
|
|
19336
|
+
return adopted;
|
|
19337
|
+
}
|
|
19338
|
+
return success(null, null, null);
|
|
19339
|
+
}
|
|
19340
|
+
adoptStoreFrom(local) {
|
|
19039
19341
|
const dirs = this.paths();
|
|
19040
|
-
const marker =
|
|
19041
|
-
if (!
|
|
19342
|
+
const marker = path16.join(local, "store.json");
|
|
19343
|
+
if (!fs13.existsSync(marker))
|
|
19042
19344
|
return success(null, null, null);
|
|
19043
19345
|
return this.withLock(dirs.checkoutLock, () => {
|
|
19044
|
-
if (!
|
|
19346
|
+
if (!fs13.existsSync(marker))
|
|
19045
19347
|
return success(null, null, null);
|
|
19046
19348
|
let tasks = 0;
|
|
19047
19349
|
try {
|
|
19048
19350
|
const merge = (from, to) => {
|
|
19049
|
-
if (!
|
|
19050
|
-
|
|
19351
|
+
if (!fs13.existsSync(to)) {
|
|
19352
|
+
fs13.mkdirSync(path16.dirname(to), { recursive: true });
|
|
19051
19353
|
try {
|
|
19052
|
-
|
|
19354
|
+
fs13.renameSync(from, to);
|
|
19053
19355
|
} catch {
|
|
19054
|
-
|
|
19055
|
-
|
|
19356
|
+
fs13.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
19357
|
+
fs13.rmSync(from, { recursive: true, force: true });
|
|
19056
19358
|
}
|
|
19057
19359
|
return;
|
|
19058
19360
|
}
|
|
19059
|
-
if (
|
|
19060
|
-
for (const name of
|
|
19061
|
-
merge(
|
|
19361
|
+
if (fs13.lstatSync(from).isDirectory() && fs13.lstatSync(to).isDirectory())
|
|
19362
|
+
for (const name of fs13.readdirSync(from))
|
|
19363
|
+
merge(path16.join(from, name), path16.join(to, name));
|
|
19062
19364
|
};
|
|
19063
19365
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
19064
|
-
const from =
|
|
19065
|
-
if (!
|
|
19366
|
+
const from = path16.join(local, sub);
|
|
19367
|
+
if (!fs13.existsSync(from))
|
|
19066
19368
|
continue;
|
|
19067
19369
|
if (sub === "tasks") {
|
|
19068
|
-
for (const name of
|
|
19069
|
-
if (validId(name) && !
|
|
19370
|
+
for (const name of fs13.readdirSync(from))
|
|
19371
|
+
if (validId(name) && !fs13.existsSync(path16.join(dirs.dir, sub, name)))
|
|
19070
19372
|
tasks += 1;
|
|
19071
19373
|
}
|
|
19072
|
-
merge(from,
|
|
19374
|
+
merge(from, path16.join(dirs.dir, sub));
|
|
19073
19375
|
}
|
|
19074
|
-
const ledger =
|
|
19075
|
-
if (
|
|
19076
|
-
merge(ledger,
|
|
19077
|
-
|
|
19078
|
-
|
|
19376
|
+
const ledger = path16.join(local, "ledger");
|
|
19377
|
+
if (fs13.existsSync(ledger) && !fs13.existsSync(path16.join(dirs.dir, "ledger")))
|
|
19378
|
+
merge(ledger, path16.join(dirs.dir, "ledger"));
|
|
19379
|
+
fs13.rmSync(path16.join(local, "task-index.json"), { force: true });
|
|
19380
|
+
fs13.renameSync(marker, path16.join(local, "store.moved.json"));
|
|
19079
19381
|
} catch (error) {
|
|
19080
|
-
return failure2("storage_error", `cannot move ${
|
|
19081
|
-
path:
|
|
19382
|
+
return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
|
|
19383
|
+
path: local
|
|
19082
19384
|
});
|
|
19083
19385
|
}
|
|
19084
19386
|
reportMigration({
|
|
19085
|
-
from:
|
|
19387
|
+
from: local,
|
|
19086
19388
|
to: dirs.dir,
|
|
19087
|
-
backup:
|
|
19389
|
+
backup: local,
|
|
19088
19390
|
tasks,
|
|
19089
19391
|
skipped: 0,
|
|
19090
19392
|
workspace: false
|
|
@@ -19095,7 +19397,7 @@ class TaskReader {
|
|
|
19095
19397
|
readV2Workspace(file) {
|
|
19096
19398
|
let bytes;
|
|
19097
19399
|
try {
|
|
19098
|
-
bytes =
|
|
19400
|
+
bytes = fs13.readFileSync(file, "utf8");
|
|
19099
19401
|
} catch {
|
|
19100
19402
|
return null;
|
|
19101
19403
|
}
|
|
@@ -19113,7 +19415,7 @@ class TaskReader {
|
|
|
19113
19415
|
schemaVersion: SCHEMA_VERSION,
|
|
19114
19416
|
id: workspaceId ?? newId(),
|
|
19115
19417
|
revision: newRevision(),
|
|
19116
|
-
root:
|
|
19418
|
+
root: path16.dirname(v2),
|
|
19117
19419
|
runtime: { createdWith: version, updatedWith: version },
|
|
19118
19420
|
writer: null,
|
|
19119
19421
|
store: {
|
|
@@ -19124,47 +19426,21 @@ class TaskReader {
|
|
|
19124
19426
|
},
|
|
19125
19427
|
critical: ["store"]
|
|
19126
19428
|
};
|
|
19127
|
-
|
|
19128
|
-
const ignore =
|
|
19129
|
-
if (!
|
|
19130
|
-
|
|
19429
|
+
fs13.mkdirSync(v2, { recursive: true });
|
|
19430
|
+
const ignore = path16.join(v2, ".gitignore");
|
|
19431
|
+
if (!fs13.existsSync(ignore))
|
|
19432
|
+
fs13.writeFileSync(ignore, `*
|
|
19131
19433
|
`);
|
|
19132
|
-
replaceFile(
|
|
19434
|
+
replaceFile(path16.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
19133
19435
|
`, true);
|
|
19134
19436
|
}
|
|
19135
|
-
writeTombstoneIfMissing() {
|
|
19136
|
-
try {
|
|
19137
|
-
if (this.paths().shared)
|
|
19138
|
-
return;
|
|
19139
|
-
const v2 = path15.join(this.root, ".workit");
|
|
19140
|
-
if (fs12.existsSync(path15.join(v2, "workspace.json")))
|
|
19141
|
-
return;
|
|
19142
|
-
let id = null;
|
|
19143
|
-
try {
|
|
19144
|
-
id = JSON.parse(fs12.readFileSync(this.paths().workspace, "utf8")).id ?? null;
|
|
19145
|
-
} catch {}
|
|
19146
|
-
this.writeTombstone(v2, id);
|
|
19147
|
-
} catch {}
|
|
19148
|
-
}
|
|
19149
19437
|
initializeStorage() {
|
|
19150
19438
|
const dirs = this.paths();
|
|
19151
|
-
retryTransient(() =>
|
|
19152
|
-
retryTransient(() =>
|
|
19153
|
-
if (!
|
|
19439
|
+
retryTransient(() => fs13.mkdirSync(dirs.checkout, { recursive: true }));
|
|
19440
|
+
retryTransient(() => fs13.mkdirSync(dirs.tasks, { recursive: true }));
|
|
19441
|
+
if (!fs13.existsSync(dirs.marker))
|
|
19154
19442
|
replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
|
|
19155
19443
|
`, false);
|
|
19156
|
-
if (!dirs.shared) {
|
|
19157
|
-
const ignore = path15.join(dirs.dir, ".gitignore");
|
|
19158
|
-
let current = null;
|
|
19159
|
-
try {
|
|
19160
|
-
current = fs12.readFileSync(ignore, "utf8");
|
|
19161
|
-
} catch {}
|
|
19162
|
-
if (current !== `*
|
|
19163
|
-
`)
|
|
19164
|
-
retryTransient(() => fs12.writeFileSync(ignore, `*
|
|
19165
|
-
`));
|
|
19166
|
-
}
|
|
19167
|
-
this.writeTombstoneIfMissing();
|
|
19168
19444
|
}
|
|
19169
19445
|
lockOptions(lockPath) {
|
|
19170
19446
|
const inProcess = heldInProcess.has(lockPath);
|
|
@@ -19177,7 +19453,7 @@ class TaskReader {
|
|
|
19177
19453
|
shouldReclaim: ({ payload, nowMs }) => {
|
|
19178
19454
|
let ageMs = null;
|
|
19179
19455
|
try {
|
|
19180
|
-
ageMs = nowMs -
|
|
19456
|
+
ageMs = nowMs - fs13.lstatSync(lockPath).mtimeMs;
|
|
19181
19457
|
} catch {}
|
|
19182
19458
|
return classifyLockOwner(payload, ageMs, localLockHost(), TASK_STORE_LOCK).state === "stale";
|
|
19183
19459
|
},
|
|
@@ -19214,7 +19490,7 @@ class TaskReader {
|
|
|
19214
19490
|
withLock(lockPath, operation) {
|
|
19215
19491
|
try {
|
|
19216
19492
|
this.initializeStorage();
|
|
19217
|
-
|
|
19493
|
+
fs13.mkdirSync(path16.dirname(lockPath), { recursive: true });
|
|
19218
19494
|
} catch (error) {
|
|
19219
19495
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
19220
19496
|
path: this.paths().dir
|
|
@@ -19254,18 +19530,18 @@ class TaskReader {
|
|
|
19254
19530
|
lockDirWritable(lockPath) {
|
|
19255
19531
|
const probe = `${lockPath}.${process.pid}.${randomUUID3()}.probe`;
|
|
19256
19532
|
try {
|
|
19257
|
-
|
|
19533
|
+
fs13.closeSync(fs13.openSync(probe, "wx", 384));
|
|
19258
19534
|
} catch {
|
|
19259
19535
|
return false;
|
|
19260
19536
|
}
|
|
19261
19537
|
try {
|
|
19262
|
-
|
|
19538
|
+
fs13.rmSync(probe, { force: true });
|
|
19263
19539
|
} catch {}
|
|
19264
19540
|
return true;
|
|
19265
19541
|
}
|
|
19266
19542
|
lockHolderPresent(lockPath) {
|
|
19267
19543
|
try {
|
|
19268
|
-
|
|
19544
|
+
fs13.lstatSync(lockPath);
|
|
19269
19545
|
return true;
|
|
19270
19546
|
} catch (error) {
|
|
19271
19547
|
return error?.code !== "ENOENT";
|
|
@@ -19277,12 +19553,12 @@ class TaskReader {
|
|
|
19277
19553
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
19278
19554
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
19279
19555
|
path: lockPath,
|
|
19280
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
19556
|
+
guidance: `Check permissions and the read-only attribute on ${path16.dirname(lockPath)}.`
|
|
19281
19557
|
});
|
|
19282
19558
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
19283
19559
|
let lock = null;
|
|
19284
19560
|
try {
|
|
19285
|
-
lock = parseMetadataLockOrNull(
|
|
19561
|
+
lock = parseMetadataLockOrNull(fs13.readFileSync(lockPath, "utf8"));
|
|
19286
19562
|
} catch {}
|
|
19287
19563
|
return failure2("busy", `workit lock is held by another Workit call${lock ? ` (pid ${lock.pid} on ${lock.host})` : ""}; retry shortly`, {
|
|
19288
19564
|
outcome: "not_started",
|
|
@@ -19312,7 +19588,7 @@ var MARKER_FIELDS = {
|
|
|
19312
19588
|
};
|
|
19313
19589
|
var isKnownMarker = (file, kind) => {
|
|
19314
19590
|
try {
|
|
19315
|
-
const value = JSON.parse(
|
|
19591
|
+
const value = JSON.parse(fs14.readFileSync(file, "utf8"));
|
|
19316
19592
|
if (!isObject5(value))
|
|
19317
19593
|
return false;
|
|
19318
19594
|
const fields = MARKER_FIELDS[kind];
|
|
@@ -19326,35 +19602,35 @@ var isKnownMarker = (file, kind) => {
|
|
|
19326
19602
|
}
|
|
19327
19603
|
};
|
|
19328
19604
|
var moveInto = (from, to) => {
|
|
19329
|
-
if (
|
|
19605
|
+
if (fs14.lstatSync(from).isDirectory()) {
|
|
19330
19606
|
let target = to;
|
|
19331
|
-
if (
|
|
19607
|
+
if (fs14.existsSync(target) && !fs14.lstatSync(target).isDirectory())
|
|
19332
19608
|
target = `${to}.dir`;
|
|
19333
|
-
|
|
19334
|
-
for (const name of
|
|
19335
|
-
moveInto(
|
|
19336
|
-
|
|
19609
|
+
fs14.mkdirSync(target, { recursive: true });
|
|
19610
|
+
for (const name of fs14.readdirSync(from))
|
|
19611
|
+
moveInto(path17.join(from, name), path17.join(target, name));
|
|
19612
|
+
fs14.rmdirSync(from);
|
|
19337
19613
|
return;
|
|
19338
19614
|
}
|
|
19339
19615
|
let target = to;
|
|
19340
|
-
if (
|
|
19341
|
-
const bytes =
|
|
19342
|
-
if (
|
|
19343
|
-
|
|
19616
|
+
if (fs14.existsSync(target)) {
|
|
19617
|
+
const bytes = fs14.readFileSync(from);
|
|
19618
|
+
if (fs14.lstatSync(target).isFile() && bytes.equals(fs14.readFileSync(target))) {
|
|
19619
|
+
fs14.rmSync(from);
|
|
19344
19620
|
return;
|
|
19345
19621
|
}
|
|
19346
|
-
target = `${to}.${
|
|
19347
|
-
if (
|
|
19348
|
-
|
|
19622
|
+
target = `${to}.${createHash9("sha256").update(bytes).digest("hex").slice(0, 12)}`;
|
|
19623
|
+
if (fs14.existsSync(target)) {
|
|
19624
|
+
fs14.rmSync(from);
|
|
19349
19625
|
return;
|
|
19350
19626
|
}
|
|
19351
19627
|
}
|
|
19352
|
-
|
|
19628
|
+
fs14.mkdirSync(path17.dirname(target), { recursive: true });
|
|
19353
19629
|
try {
|
|
19354
|
-
|
|
19630
|
+
fs14.renameSync(from, target);
|
|
19355
19631
|
} catch {
|
|
19356
|
-
|
|
19357
|
-
|
|
19632
|
+
fs14.copyFileSync(from, target);
|
|
19633
|
+
fs14.rmSync(from);
|
|
19358
19634
|
}
|
|
19359
19635
|
};
|
|
19360
19636
|
var now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
@@ -19417,7 +19693,7 @@ class TaskStore extends TaskReader {
|
|
|
19417
19693
|
const moved = this.bindLocked(again.data.id, key, input.now);
|
|
19418
19694
|
return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
|
|
19419
19695
|
}
|
|
19420
|
-
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" :
|
|
19696
|
+
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path17.basename(this.root) || this.root;
|
|
19421
19697
|
const intent = {
|
|
19422
19698
|
objective: input.objective?.trim() || `Work on ${label}`,
|
|
19423
19699
|
scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
|
|
@@ -19665,13 +19941,13 @@ class TaskStore extends TaskReader {
|
|
|
19665
19941
|
if (!ready.ok)
|
|
19666
19942
|
return ready;
|
|
19667
19943
|
const dirs = this.paths();
|
|
19668
|
-
const recovery = [
|
|
19944
|
+
const recovery = [path17.join(this.root, ".workit", "recovery"), path17.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
|
|
19669
19945
|
if (recovery) {
|
|
19670
19946
|
let files = 0;
|
|
19671
19947
|
let bytes = 0;
|
|
19672
19948
|
try {
|
|
19673
|
-
for (const name of
|
|
19674
|
-
const stat =
|
|
19949
|
+
for (const name of fs14.readdirSync(recovery)) {
|
|
19950
|
+
const stat = fs14.lstatSync(path17.join(recovery, name));
|
|
19675
19951
|
if (!stat.isFile())
|
|
19676
19952
|
continue;
|
|
19677
19953
|
files += 1;
|
|
@@ -19680,17 +19956,17 @@ class TaskStore extends TaskReader {
|
|
|
19680
19956
|
} catch {}
|
|
19681
19957
|
const remove = options.pruneRecovery === true && !dryRun;
|
|
19682
19958
|
if (remove)
|
|
19683
|
-
|
|
19959
|
+
fs14.rmSync(recovery, { recursive: true, force: true });
|
|
19684
19960
|
report.legacyRecovery = { path: recovery, files, bytes, removed: remove };
|
|
19685
19961
|
}
|
|
19686
|
-
if (!
|
|
19962
|
+
if (!fs14.existsSync(dirs.tasks))
|
|
19687
19963
|
return success(null, null, report);
|
|
19688
|
-
const names =
|
|
19964
|
+
const names = fs14.readdirSync(dirs.tasks).filter((name) => validId(name));
|
|
19689
19965
|
for (const name of names) {
|
|
19690
19966
|
const file = this.eventsPath(name);
|
|
19691
19967
|
let size = 0;
|
|
19692
19968
|
try {
|
|
19693
|
-
size =
|
|
19969
|
+
size = fs14.statSync(file).size;
|
|
19694
19970
|
} catch {
|
|
19695
19971
|
continue;
|
|
19696
19972
|
}
|
|
@@ -19718,16 +19994,16 @@ class TaskStore extends TaskReader {
|
|
|
19718
19994
|
const references = new Set;
|
|
19719
19995
|
for (const name of names)
|
|
19720
19996
|
try {
|
|
19721
|
-
for (const match of
|
|
19997
|
+
for (const match of fs14.readFileSync(this.eventsPath(name), "utf8").matchAll(/"\$blob":"([0-9a-f]{64})"/g))
|
|
19722
19998
|
references.add(match[1]);
|
|
19723
19999
|
} catch {}
|
|
19724
|
-
if (
|
|
19725
|
-
for (const name of
|
|
20000
|
+
if (fs14.existsSync(dirs.blobs))
|
|
20001
|
+
for (const name of fs14.readdirSync(dirs.blobs)) {
|
|
19726
20002
|
const digest = name.replace(/\.json$/, "");
|
|
19727
|
-
const file =
|
|
20003
|
+
const file = path17.join(dirs.blobs, name);
|
|
19728
20004
|
let stat;
|
|
19729
20005
|
try {
|
|
19730
|
-
stat =
|
|
20006
|
+
stat = fs14.lstatSync(file);
|
|
19731
20007
|
} catch {
|
|
19732
20008
|
continue;
|
|
19733
20009
|
}
|
|
@@ -19738,11 +20014,11 @@ class TaskStore extends TaskReader {
|
|
|
19738
20014
|
report.blobs.removed += 1;
|
|
19739
20015
|
report.blobs.removedBytes += stat.size;
|
|
19740
20016
|
if (!dryRun)
|
|
19741
|
-
|
|
20017
|
+
fs14.rmSync(file, { force: true });
|
|
19742
20018
|
}
|
|
19743
20019
|
return success(null, null, null);
|
|
19744
20020
|
};
|
|
19745
|
-
const swept = dryRun ? sweep() : this.withLock(
|
|
20021
|
+
const swept = dryRun ? sweep() : this.withLock(path17.join(dirs.dir, "gc.lock"), sweep);
|
|
19746
20022
|
if (!swept.ok)
|
|
19747
20023
|
return swept;
|
|
19748
20024
|
const temporaryDirs = [
|
|
@@ -19750,17 +20026,17 @@ class TaskStore extends TaskReader {
|
|
|
19750
20026
|
dirs.tasks,
|
|
19751
20027
|
dirs.blobs,
|
|
19752
20028
|
dirs.checkout,
|
|
19753
|
-
...names.map((name) =>
|
|
20029
|
+
...names.map((name) => path17.join(dirs.tasks, name))
|
|
19754
20030
|
];
|
|
19755
20031
|
for (const directory of temporaryDirs) {
|
|
19756
|
-
if (!
|
|
20032
|
+
if (!fs14.existsSync(directory))
|
|
19757
20033
|
continue;
|
|
19758
|
-
for (const name of
|
|
20034
|
+
for (const name of fs14.readdirSync(directory)) {
|
|
19759
20035
|
if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
|
|
19760
20036
|
continue;
|
|
19761
|
-
const file =
|
|
20037
|
+
const file = path17.join(directory, name);
|
|
19762
20038
|
try {
|
|
19763
|
-
const stat =
|
|
20039
|
+
const stat = fs14.lstatSync(file);
|
|
19764
20040
|
if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
|
|
19765
20041
|
continue;
|
|
19766
20042
|
} catch {
|
|
@@ -19768,13 +20044,13 @@ class TaskStore extends TaskReader {
|
|
|
19768
20044
|
}
|
|
19769
20045
|
report.temporary.removed += 1;
|
|
19770
20046
|
if (!dryRun)
|
|
19771
|
-
|
|
20047
|
+
fs14.rmSync(file, { force: true });
|
|
19772
20048
|
}
|
|
19773
20049
|
}
|
|
19774
20050
|
return success(null, null, report);
|
|
19775
20051
|
}
|
|
19776
20052
|
taskLockPath(taskId) {
|
|
19777
|
-
return
|
|
20053
|
+
return path17.join(this.paths().tasks, taskId, "lock");
|
|
19778
20054
|
}
|
|
19779
20055
|
settleMigrations(write) {
|
|
19780
20056
|
const moved = this.adoptLocalStore();
|
|
@@ -19803,15 +20079,15 @@ class TaskStore extends TaskReader {
|
|
|
19803
20079
|
return {
|
|
19804
20080
|
read: (digest) => reader.read(digest),
|
|
19805
20081
|
write: (digest, value) => {
|
|
19806
|
-
const file =
|
|
19807
|
-
if (
|
|
20082
|
+
const file = path17.join(dir, `${digest}.json`);
|
|
20083
|
+
if (fs14.existsSync(file)) {
|
|
19808
20084
|
const stamp = new Date;
|
|
19809
20085
|
try {
|
|
19810
|
-
|
|
20086
|
+
fs14.utimesSync(file, stamp, stamp);
|
|
19811
20087
|
return;
|
|
19812
20088
|
} catch {}
|
|
19813
20089
|
}
|
|
19814
|
-
|
|
20090
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
19815
20091
|
replaceFile(file, JSON.stringify(value), true);
|
|
19816
20092
|
}
|
|
19817
20093
|
};
|
|
@@ -19905,8 +20181,8 @@ class TaskStore extends TaskReader {
|
|
|
19905
20181
|
}
|
|
19906
20182
|
}
|
|
19907
20183
|
openTask(record, type, key, legacy = null) {
|
|
19908
|
-
const dir =
|
|
19909
|
-
|
|
20184
|
+
const dir = path17.join(this.paths().tasks, record.id);
|
|
20185
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
19910
20186
|
const blobs = this.blobStore();
|
|
19911
20187
|
const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
|
|
19912
20188
|
const event = this.event(record.id, 1, type, {
|
|
@@ -19958,11 +20234,11 @@ class TaskStore extends TaskReader {
|
|
|
19958
20234
|
} catch {}
|
|
19959
20235
|
if (!latest || latest.events[0]?.id !== last.id)
|
|
19960
20236
|
return failure2("busy", "the task log changed during compaction; retry", { taskId });
|
|
19961
|
-
const appended =
|
|
20237
|
+
const appended = fs14.readFileSync(file).subarray(log.end, latest.end);
|
|
19962
20238
|
const bytes = Buffer.concat([Buffer.from(prefix, "utf8"), appended]);
|
|
19963
20239
|
replaceFile(file, bytes.toString("utf8"), true);
|
|
19964
20240
|
try {
|
|
19965
|
-
|
|
20241
|
+
fs14.rmSync(this.snapshotPath(taskId), { force: true });
|
|
19966
20242
|
} catch {}
|
|
19967
20243
|
const reloaded = this.load(taskId);
|
|
19968
20244
|
if (reloaded.ok && reloaded.data)
|
|
@@ -19975,7 +20251,7 @@ class TaskStore extends TaskReader {
|
|
|
19975
20251
|
}
|
|
19976
20252
|
countEvents(file) {
|
|
19977
20253
|
try {
|
|
19978
|
-
const bytes =
|
|
20254
|
+
const bytes = fs14.readFileSync(file);
|
|
19979
20255
|
let count = 0;
|
|
19980
20256
|
for (let index = bytes.indexOf(10);index >= 0; index = bytes.indexOf(10, index + 1))
|
|
19981
20257
|
count += 1;
|
|
@@ -19985,8 +20261,8 @@ class TaskStore extends TaskReader {
|
|
|
19985
20261
|
}
|
|
19986
20262
|
}
|
|
19987
20263
|
withKeyLock(key, operation) {
|
|
19988
|
-
const digest =
|
|
19989
|
-
return this.withLock(
|
|
20264
|
+
const digest = createHash9("sha256").update(key).digest("hex").slice(0, 32);
|
|
20265
|
+
return this.withLock(path17.join(this.paths().dir, "keys", `${digest}.lock`), operation);
|
|
19990
20266
|
}
|
|
19991
20267
|
bindLocked(taskId, key, timestamp) {
|
|
19992
20268
|
const current = this.readWorkspace();
|
|
@@ -20127,7 +20403,7 @@ class TaskStore extends TaskReader {
|
|
|
20127
20403
|
writeWorkspace(record) {
|
|
20128
20404
|
const file = this.paths().workspace;
|
|
20129
20405
|
try {
|
|
20130
|
-
|
|
20406
|
+
fs14.mkdirSync(path17.dirname(file), { recursive: true });
|
|
20131
20407
|
replaceFile(file, `${canonicalJson(record)}
|
|
20132
20408
|
`, true);
|
|
20133
20409
|
return success(null, null, null);
|
|
@@ -20153,13 +20429,13 @@ class TaskStore extends TaskReader {
|
|
|
20153
20429
|
}
|
|
20154
20430
|
migrateV2(v2) {
|
|
20155
20431
|
const dirs = this.paths();
|
|
20156
|
-
const v2Workspace =
|
|
20157
|
-
const v2Tasks =
|
|
20158
|
-
const legacy =
|
|
20432
|
+
const v2Workspace = path17.join(v2, "workspace.json");
|
|
20433
|
+
const v2Tasks = path17.join(v2, "tasks");
|
|
20434
|
+
const legacy = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
|
|
20159
20435
|
const raw = this.readV2Workspace(v2Workspace);
|
|
20160
20436
|
if (raw === null || raw === TOMBSTONE)
|
|
20161
20437
|
return success(null, null, null);
|
|
20162
|
-
return this.withLock(dirs.checkoutLock, () => this.withLock(
|
|
20438
|
+
return this.withLock(dirs.checkoutLock, () => this.withLock(path17.join(v2, "metadata.lock"), () => {
|
|
20163
20439
|
const workspace = this.readV2Workspace(v2Workspace);
|
|
20164
20440
|
if (workspace === null || workspace === TOMBSTONE)
|
|
20165
20441
|
return success(null, null, null);
|
|
@@ -20168,7 +20444,7 @@ class TaskStore extends TaskReader {
|
|
|
20168
20444
|
return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
|
|
20169
20445
|
let files = [];
|
|
20170
20446
|
try {
|
|
20171
|
-
files =
|
|
20447
|
+
files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path17.join(v2Tasks, name)));
|
|
20172
20448
|
} catch {}
|
|
20173
20449
|
const current = this.readWorkspace();
|
|
20174
20450
|
if (!current.ok)
|
|
@@ -20186,22 +20462,22 @@ class TaskStore extends TaskReader {
|
|
|
20186
20462
|
let skipped = 0;
|
|
20187
20463
|
const done = new Map;
|
|
20188
20464
|
try {
|
|
20189
|
-
|
|
20465
|
+
fs14.mkdirSync(path17.join(legacy, "tasks"), { recursive: true });
|
|
20190
20466
|
for (const name of ["workspace.json", "index.json"])
|
|
20191
|
-
if (
|
|
20192
|
-
|
|
20467
|
+
if (fs14.existsSync(path17.join(v2, name)))
|
|
20468
|
+
fs14.copyFileSync(path17.join(v2, name), path17.join(legacy, name));
|
|
20193
20469
|
for (const name of files) {
|
|
20194
20470
|
const id = name.slice(0, -5);
|
|
20195
|
-
const file =
|
|
20196
|
-
const bytes =
|
|
20471
|
+
const file = path17.join(v2Tasks, name);
|
|
20472
|
+
const bytes = fs14.readFileSync(file, "utf8");
|
|
20197
20473
|
const digest = sha256(bytes);
|
|
20198
|
-
|
|
20474
|
+
fs14.writeFileSync(path17.join(legacy, "tasks", name), bytes);
|
|
20199
20475
|
const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
|
|
20200
20476
|
if (!parsed.ok || parsed.data.id !== id)
|
|
20201
20477
|
return failure2("recovery_required", `cannot migrate 2.x task ${id}: ${parsed.ok ? "file name and record ID differ" : parsed.error}; move ${file} aside to continue`, { path: file });
|
|
20202
20478
|
const record = { ...parsed.data, workspaceId: target.id };
|
|
20203
|
-
const origin = { path:
|
|
20204
|
-
if (!
|
|
20479
|
+
const origin = { path: path17.join(legacy, "tasks", name), digest };
|
|
20480
|
+
if (!fs14.existsSync(this.eventsPath(id))) {
|
|
20205
20481
|
this.openTask(record, "migrated.from_v2", null, origin);
|
|
20206
20482
|
migrated += 1;
|
|
20207
20483
|
} else {
|
|
@@ -20236,13 +20512,13 @@ class TaskStore extends TaskReader {
|
|
|
20236
20512
|
try {
|
|
20237
20513
|
let complete = true;
|
|
20238
20514
|
for (const [name, digest] of done) {
|
|
20239
|
-
const file =
|
|
20240
|
-
if (sha256(
|
|
20515
|
+
const file = path17.join(v2Tasks, name);
|
|
20516
|
+
if (sha256(fs14.readFileSync(file, "utf8")) !== digest) {
|
|
20241
20517
|
complete = false;
|
|
20242
20518
|
continue;
|
|
20243
20519
|
}
|
|
20244
20520
|
if (dirs.shared)
|
|
20245
|
-
|
|
20521
|
+
fs14.rmSync(file);
|
|
20246
20522
|
else
|
|
20247
20523
|
replaceFile(file, this.stubFor(name.slice(0, -5)), false);
|
|
20248
20524
|
}
|
|
@@ -20250,9 +20526,9 @@ class TaskStore extends TaskReader {
|
|
|
20250
20526
|
return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
|
|
20251
20527
|
path: v2
|
|
20252
20528
|
});
|
|
20253
|
-
|
|
20529
|
+
fs14.rmSync(path17.join(v2, "index.json"), { force: true });
|
|
20254
20530
|
if (dirs.shared)
|
|
20255
|
-
|
|
20531
|
+
fs14.rmSync(v2Workspace, { force: true });
|
|
20256
20532
|
else
|
|
20257
20533
|
this.writeTombstone(v2, target.id);
|
|
20258
20534
|
} catch (error) {
|
|
@@ -20275,49 +20551,49 @@ class TaskStore extends TaskReader {
|
|
|
20275
20551
|
const dirs = this.paths();
|
|
20276
20552
|
if (!dirs.shared)
|
|
20277
20553
|
return success(null, null, null);
|
|
20278
|
-
const present = () => CHECKOUT_LEFTOVERS.filter((name) =>
|
|
20279
|
-
const ignore =
|
|
20554
|
+
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path17.join(v2, name)));
|
|
20555
|
+
const ignore = path17.join(v2, ".gitignore");
|
|
20280
20556
|
const onlyGeneratedIgnore = () => {
|
|
20281
20557
|
try {
|
|
20282
|
-
return
|
|
20558
|
+
return fs14.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs14.readFileSync(ignore, "utf8"));
|
|
20283
20559
|
} catch {
|
|
20284
20560
|
return false;
|
|
20285
20561
|
}
|
|
20286
20562
|
};
|
|
20287
20563
|
if (present().length === 0 && !onlyGeneratedIgnore())
|
|
20288
20564
|
return success(null, null, null);
|
|
20289
|
-
const backup =
|
|
20565
|
+
const backup = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
|
|
20290
20566
|
return this.withLock(dirs.checkoutLock, () => {
|
|
20291
20567
|
let moved = 0;
|
|
20292
20568
|
try {
|
|
20293
20569
|
for (const name of present()) {
|
|
20294
|
-
const entry =
|
|
20570
|
+
const entry = path17.join(v2, name);
|
|
20295
20571
|
const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
|
|
20296
|
-
const empty =
|
|
20572
|
+
const empty = fs14.lstatSync(entry).isDirectory() && fs14.readdirSync(entry).length === 0;
|
|
20297
20573
|
if (marker || empty) {
|
|
20298
|
-
|
|
20574
|
+
fs14.rmSync(entry, { recursive: true });
|
|
20299
20575
|
continue;
|
|
20300
20576
|
}
|
|
20301
|
-
if (name === "tasks" &&
|
|
20302
|
-
for (const task of
|
|
20303
|
-
const file =
|
|
20304
|
-
if (
|
|
20305
|
-
|
|
20577
|
+
if (name === "tasks" && fs14.lstatSync(entry).isDirectory()) {
|
|
20578
|
+
for (const task of fs14.readdirSync(entry)) {
|
|
20579
|
+
const file = path17.join(entry, task);
|
|
20580
|
+
if (fs14.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
|
|
20581
|
+
fs14.rmSync(file);
|
|
20306
20582
|
else {
|
|
20307
|
-
moveInto(file,
|
|
20583
|
+
moveInto(file, path17.join(backup, "tasks", task));
|
|
20308
20584
|
moved += 1;
|
|
20309
20585
|
}
|
|
20310
20586
|
}
|
|
20311
|
-
|
|
20587
|
+
fs14.rmdirSync(entry);
|
|
20312
20588
|
continue;
|
|
20313
20589
|
}
|
|
20314
|
-
moveInto(entry,
|
|
20590
|
+
moveInto(entry, path17.join(backup, name));
|
|
20315
20591
|
moved += 1;
|
|
20316
20592
|
}
|
|
20317
20593
|
if (onlyGeneratedIgnore())
|
|
20318
|
-
|
|
20319
|
-
if (
|
|
20320
|
-
|
|
20594
|
+
fs14.rmSync(ignore);
|
|
20595
|
+
if (fs14.readdirSync(v2).length === 0)
|
|
20596
|
+
fs14.rmdirSync(v2);
|
|
20321
20597
|
} catch (error) {
|
|
20322
20598
|
return failure2("storage_error", `cannot clear ${v2}: ${String(error)}`, { path: v2 });
|
|
20323
20599
|
}
|
|
@@ -20339,7 +20615,7 @@ class TaskStore extends TaskReader {
|
|
|
20339
20615
|
}
|
|
20340
20616
|
isStub(file) {
|
|
20341
20617
|
try {
|
|
20342
|
-
const value = JSON.parse(
|
|
20618
|
+
const value = JSON.parse(fs14.readFileSync(file, "utf8"));
|
|
20343
20619
|
return isObject5(value) && isObject5(value.store) && value.store.format === "workit-store";
|
|
20344
20620
|
} catch {
|
|
20345
20621
|
return false;
|
|
@@ -20352,23 +20628,23 @@ var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
|
|
|
20352
20628
|
var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
|
|
20353
20629
|
|
|
20354
20630
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
20355
|
-
import { createHash as
|
|
20356
|
-
import * as
|
|
20631
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
20632
|
+
import * as fs18 from "node:fs";
|
|
20357
20633
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
20358
|
-
import
|
|
20634
|
+
import path23 from "node:path";
|
|
20359
20635
|
|
|
20360
20636
|
// packages/workit-core/src/check-config.ts
|
|
20361
20637
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
20362
|
-
import
|
|
20363
|
-
import
|
|
20638
|
+
import fs15 from "node:fs";
|
|
20639
|
+
import path18 from "node:path";
|
|
20364
20640
|
var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
|
|
20365
20641
|
var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
|
|
20366
20642
|
var CHECKS_FILE = ".workit/checks.json";
|
|
20367
20643
|
var LEGACY_CHECKS_FILE = "workit.checks.json";
|
|
20368
20644
|
function checksConfigFile(root) {
|
|
20369
|
-
const current =
|
|
20370
|
-
const legacy =
|
|
20371
|
-
return !
|
|
20645
|
+
const current = path18.join(root, CHECKS_FILE);
|
|
20646
|
+
const legacy = path18.join(root, LEGACY_CHECKS_FILE);
|
|
20647
|
+
return !fs15.existsSync(current) && fs15.existsSync(legacy) ? legacy : current;
|
|
20372
20648
|
}
|
|
20373
20649
|
var GENERATED_GITIGNORES2 = new Set([`*
|
|
20374
20650
|
`, `*
|
|
@@ -20426,10 +20702,10 @@ var git3 = (cwd, args) => {
|
|
|
20426
20702
|
return value || null;
|
|
20427
20703
|
};
|
|
20428
20704
|
function checkRoot(cwd) {
|
|
20429
|
-
return
|
|
20705
|
+
return path18.resolve(gitDirs(cwd)?.top ?? cwd);
|
|
20430
20706
|
}
|
|
20431
20707
|
var packageManager = (root) => {
|
|
20432
|
-
const has = (file) =>
|
|
20708
|
+
const has = (file) => fs15.existsSync(path18.join(root, file));
|
|
20433
20709
|
if (has("bun.lock") || has("bun.lockb"))
|
|
20434
20710
|
return "bun";
|
|
20435
20711
|
if (has("pnpm-lock.yaml"))
|
|
@@ -20449,7 +20725,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
|
|
|
20449
20725
|
function detectedChecks(root) {
|
|
20450
20726
|
const read = (file) => {
|
|
20451
20727
|
try {
|
|
20452
|
-
return
|
|
20728
|
+
return fs15.readFileSync(path18.join(root, file), "utf8");
|
|
20453
20729
|
} catch {
|
|
20454
20730
|
return null;
|
|
20455
20731
|
}
|
|
@@ -20521,21 +20797,21 @@ function cleanupGlobs(value) {
|
|
|
20521
20797
|
}
|
|
20522
20798
|
function configFileFor(root) {
|
|
20523
20799
|
const own = checksConfigFile(root);
|
|
20524
|
-
if (
|
|
20800
|
+
if (fs15.existsSync(own))
|
|
20525
20801
|
return own;
|
|
20526
20802
|
const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
20527
|
-
if (!common ||
|
|
20803
|
+
if (!common || path18.basename(common) !== ".git")
|
|
20528
20804
|
return own;
|
|
20529
|
-
const main =
|
|
20530
|
-
if (
|
|
20805
|
+
const main = path18.dirname(common);
|
|
20806
|
+
if (path18.resolve(main) === path18.resolve(root))
|
|
20531
20807
|
return own;
|
|
20532
20808
|
const shared = checksConfigFile(main);
|
|
20533
|
-
return
|
|
20809
|
+
return fs15.existsSync(shared) ? shared : own;
|
|
20534
20810
|
}
|
|
20535
20811
|
function loadCheckConfig(cwd) {
|
|
20536
20812
|
const root = checkRoot(cwd);
|
|
20537
20813
|
const file = configFileFor(root);
|
|
20538
|
-
const legacy =
|
|
20814
|
+
const legacy = path18.basename(file) === LEGACY_CHECKS_FILE;
|
|
20539
20815
|
const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
|
|
20540
20816
|
const note = legacy ? {
|
|
20541
20817
|
note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
|
|
@@ -20551,7 +20827,7 @@ function loadCheckConfig(cwd) {
|
|
|
20551
20827
|
});
|
|
20552
20828
|
let text = null;
|
|
20553
20829
|
try {
|
|
20554
|
-
text =
|
|
20830
|
+
text = fs15.readFileSync(file, "utf8");
|
|
20555
20831
|
} catch (error) {
|
|
20556
20832
|
if (error.code !== "ENOENT")
|
|
20557
20833
|
return none(`cannot read ${label}: ${error.message}`);
|
|
@@ -20666,10 +20942,10 @@ function workitAvailable(env = process.env) {
|
|
|
20666
20942
|
return workitOnPath;
|
|
20667
20943
|
const windows = process.platform === "win32";
|
|
20668
20944
|
const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
20669
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
20945
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path18.delimiter).filter(Boolean);
|
|
20670
20946
|
workitOnPath = dirs.some((dir) => exts.some((ext) => {
|
|
20671
20947
|
try {
|
|
20672
|
-
return
|
|
20948
|
+
return fs15.statSync(path18.join(dir, `workit${ext}`)).isFile();
|
|
20673
20949
|
} catch {
|
|
20674
20950
|
return false;
|
|
20675
20951
|
}
|
|
@@ -20729,14 +21005,14 @@ var PM_RUN = new Set(["run", "run-script"]);
|
|
|
20729
21005
|
var PYTHON_RUNNERS = new Set(["uv", "poetry", "pipenv", "pdm", "hatch", "rye"]);
|
|
20730
21006
|
|
|
20731
21007
|
// packages/workit-core/src/core/policy/derive.ts
|
|
20732
|
-
import { existsSync as
|
|
20733
|
-
import
|
|
21008
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
21009
|
+
import path22 from "node:path";
|
|
20734
21010
|
|
|
20735
21011
|
// packages/workit-core/src/ledger.ts
|
|
20736
21012
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
20737
|
-
import { createHash as
|
|
20738
|
-
import
|
|
20739
|
-
import
|
|
21013
|
+
import { createHash as createHash10, randomBytes as randomBytes3 } from "node:crypto";
|
|
21014
|
+
import fs17 from "node:fs";
|
|
21015
|
+
import path21 from "node:path";
|
|
20740
21016
|
|
|
20741
21017
|
// packages/workit-core/src/core/policy/bookkeeping.ts
|
|
20742
21018
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
@@ -20816,8 +21092,8 @@ function bookkeepingPaths(cwd, input) {
|
|
|
20816
21092
|
}
|
|
20817
21093
|
|
|
20818
21094
|
// packages/workit-core/src/core/policy/lane.ts
|
|
20819
|
-
import { existsSync as
|
|
20820
|
-
import
|
|
21095
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
21096
|
+
import path19 from "node:path";
|
|
20821
21097
|
|
|
20822
21098
|
// packages/workit-core/src/git/default-base.ts
|
|
20823
21099
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
@@ -22205,7 +22481,7 @@ function computeLane(input) {
|
|
|
22205
22481
|
}
|
|
22206
22482
|
function untrackedStat(cwd, file) {
|
|
22207
22483
|
try {
|
|
22208
|
-
const bytes = readFileSync7(
|
|
22484
|
+
const bytes = readFileSync7(path19.join(cwd, file));
|
|
22209
22485
|
if (bytes.includes(0))
|
|
22210
22486
|
return { path: file, added: 0, deleted: 0, binary: true };
|
|
22211
22487
|
const text = bytes.toString("utf8");
|
|
@@ -22237,7 +22513,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
22237
22513
|
let after = blobs.get(entry.newBlob);
|
|
22238
22514
|
if (!after && head === null && ABSENT.test(entry.newBlob))
|
|
22239
22515
|
try {
|
|
22240
|
-
after = readFileSync7(
|
|
22516
|
+
after = readFileSync7(path19.join(cwd, entry.path));
|
|
22241
22517
|
} catch {
|
|
22242
22518
|
after = undefined;
|
|
22243
22519
|
}
|
|
@@ -22392,26 +22668,26 @@ function verdictDrift(cwd, input) {
|
|
|
22392
22668
|
}
|
|
22393
22669
|
|
|
22394
22670
|
// packages/workit-core/src/hooks/standing-signal.ts
|
|
22395
|
-
import
|
|
22396
|
-
import
|
|
22671
|
+
import fs16 from "node:fs";
|
|
22672
|
+
import path20 from "node:path";
|
|
22397
22673
|
var gitStoreDir = (cwd) => {
|
|
22398
22674
|
try {
|
|
22399
|
-
for (let dir =
|
|
22400
|
-
const dotGit =
|
|
22401
|
-
if (
|
|
22675
|
+
for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
|
|
22676
|
+
const dotGit = path20.join(dir, ".git");
|
|
22677
|
+
if (fs16.existsSync(dotGit)) {
|
|
22402
22678
|
let gitDir = dotGit;
|
|
22403
|
-
if (
|
|
22404
|
-
const target = /^gitdir:\s*(.+)$/mu.exec(
|
|
22679
|
+
if (fs16.statSync(dotGit).isFile()) {
|
|
22680
|
+
const target = /^gitdir:\s*(.+)$/mu.exec(fs16.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
22405
22681
|
if (!target)
|
|
22406
22682
|
return null;
|
|
22407
|
-
gitDir =
|
|
22408
|
-
const common =
|
|
22409
|
-
if (
|
|
22410
|
-
gitDir =
|
|
22683
|
+
gitDir = path20.resolve(dir, target);
|
|
22684
|
+
const common = path20.join(gitDir, "commondir");
|
|
22685
|
+
if (fs16.existsSync(common))
|
|
22686
|
+
gitDir = path20.resolve(gitDir, fs16.readFileSync(common, "utf8").trim());
|
|
22411
22687
|
}
|
|
22412
|
-
return
|
|
22688
|
+
return path20.join(gitDir, "workit");
|
|
22413
22689
|
}
|
|
22414
|
-
if (
|
|
22690
|
+
if (path20.dirname(dir) === dir)
|
|
22415
22691
|
return null;
|
|
22416
22692
|
}
|
|
22417
22693
|
} catch {
|
|
@@ -22484,7 +22760,7 @@ var binaryRangeDiff = (cwd, base, head) => {
|
|
|
22484
22760
|
return diff.ok && diff.stdout ? diff.stdout : null;
|
|
22485
22761
|
};
|
|
22486
22762
|
var hashOfDiff = (diff) => {
|
|
22487
|
-
const hash =
|
|
22763
|
+
const hash = createHash10("sha256");
|
|
22488
22764
|
for (const line of diff.split(`
|
|
22489
22765
|
`)) {
|
|
22490
22766
|
if (line.startsWith("index "))
|
|
@@ -22517,14 +22793,14 @@ function cleanRebase(cwd, range) {
|
|
|
22517
22793
|
return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
|
|
22518
22794
|
}
|
|
22519
22795
|
function storeRoot(cwd) {
|
|
22520
|
-
const location = resolveStore(
|
|
22796
|
+
const location = resolveStore(path21.resolve(cwd));
|
|
22521
22797
|
if (location instanceof Error)
|
|
22522
22798
|
return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), / does not exist /u.test(location.message) ? "run workit from a directory that exists" : "fix the repository (git status should work here) or run from a non-git directory");
|
|
22523
22799
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
22524
22800
|
}
|
|
22525
22801
|
function ledgerPath(cwd) {
|
|
22526
22802
|
const root = storeRoot(cwd);
|
|
22527
|
-
return root.ok ? { ok: true, value:
|
|
22803
|
+
return root.ok ? { ok: true, value: path21.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
22528
22804
|
}
|
|
22529
22805
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
|
|
22530
22806
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -22544,25 +22820,25 @@ var onNetworkFs = (dir) => {
|
|
|
22544
22820
|
if (process.platform !== "linux")
|
|
22545
22821
|
return false;
|
|
22546
22822
|
try {
|
|
22547
|
-
return isNetworkFsType(
|
|
22823
|
+
return isNetworkFsType(fs17.statfsSync(dir).type);
|
|
22548
22824
|
} catch {
|
|
22549
22825
|
return false;
|
|
22550
22826
|
}
|
|
22551
22827
|
};
|
|
22552
|
-
var
|
|
22553
|
-
var
|
|
22828
|
+
var LOCK_WAIT_MS2 = 5000;
|
|
22829
|
+
var LOCK_STALE_MS2 = 30000;
|
|
22554
22830
|
var LOCK_OWNER = "owner";
|
|
22555
22831
|
var lockToken = (lock) => {
|
|
22556
22832
|
try {
|
|
22557
|
-
return
|
|
22833
|
+
return fs17.readFileSync(path21.join(lock, LOCK_OWNER), "utf8");
|
|
22558
22834
|
} catch {
|
|
22559
22835
|
return null;
|
|
22560
22836
|
}
|
|
22561
22837
|
};
|
|
22562
22838
|
var lockAgeMs = (lock) => {
|
|
22563
|
-
for (const target of [
|
|
22839
|
+
for (const target of [path21.join(lock, LOCK_OWNER), lock]) {
|
|
22564
22840
|
try {
|
|
22565
|
-
return Date.now() -
|
|
22841
|
+
return Date.now() - fs17.statSync(target).mtimeMs;
|
|
22566
22842
|
} catch {}
|
|
22567
22843
|
}
|
|
22568
22844
|
return null;
|
|
@@ -22570,14 +22846,14 @@ var lockAgeMs = (lock) => {
|
|
|
22570
22846
|
var ledgerLock = {
|
|
22571
22847
|
acquire(lock) {
|
|
22572
22848
|
try {
|
|
22573
|
-
|
|
22849
|
+
fs17.mkdirSync(lock);
|
|
22574
22850
|
} catch (error) {
|
|
22575
22851
|
if (error.code === "EEXIST")
|
|
22576
22852
|
return null;
|
|
22577
22853
|
throw error;
|
|
22578
22854
|
}
|
|
22579
22855
|
const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
|
|
22580
|
-
|
|
22856
|
+
fs17.writeFileSync(path21.join(lock, LOCK_OWNER), token);
|
|
22581
22857
|
return token;
|
|
22582
22858
|
},
|
|
22583
22859
|
release(lock, token) {
|
|
@@ -22585,40 +22861,40 @@ var ledgerLock = {
|
|
|
22585
22861
|
return false;
|
|
22586
22862
|
const tomb = `${lock}.release-${randomBytes3(6).toString("hex")}`;
|
|
22587
22863
|
try {
|
|
22588
|
-
|
|
22864
|
+
fs17.renameSync(lock, tomb);
|
|
22589
22865
|
} catch {
|
|
22590
22866
|
return false;
|
|
22591
22867
|
}
|
|
22592
22868
|
if (lockToken(tomb) !== token) {
|
|
22593
22869
|
try {
|
|
22594
|
-
|
|
22870
|
+
fs17.renameSync(tomb, lock);
|
|
22595
22871
|
} catch {}
|
|
22596
22872
|
return false;
|
|
22597
22873
|
}
|
|
22598
|
-
|
|
22874
|
+
fs17.rmSync(tomb, { recursive: true, force: true });
|
|
22599
22875
|
return true;
|
|
22600
22876
|
},
|
|
22601
22877
|
token: lockToken,
|
|
22602
22878
|
reap(lock, observed) {
|
|
22603
22879
|
const tomb = `${lock}.reap-${randomBytes3(6).toString("hex")}`;
|
|
22604
22880
|
try {
|
|
22605
|
-
|
|
22881
|
+
fs17.renameSync(lock, tomb);
|
|
22606
22882
|
} catch {
|
|
22607
22883
|
return false;
|
|
22608
22884
|
}
|
|
22609
22885
|
if (lockToken(tomb) === observed) {
|
|
22610
|
-
|
|
22886
|
+
fs17.rmSync(tomb, { recursive: true, force: true });
|
|
22611
22887
|
return true;
|
|
22612
22888
|
}
|
|
22613
22889
|
try {
|
|
22614
|
-
|
|
22890
|
+
fs17.renameSync(tomb, lock);
|
|
22615
22891
|
} catch {
|
|
22616
|
-
|
|
22892
|
+
fs17.rmSync(tomb, { recursive: true, force: true });
|
|
22617
22893
|
}
|
|
22618
22894
|
return false;
|
|
22619
22895
|
}
|
|
22620
22896
|
};
|
|
22621
|
-
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(
|
|
22897
|
+
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2)) {
|
|
22622
22898
|
const lock = `${file}.lock`;
|
|
22623
22899
|
const deadline = Date.now() + waitMs;
|
|
22624
22900
|
let token = null;
|
|
@@ -22628,7 +22904,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
|
|
|
22628
22904
|
break;
|
|
22629
22905
|
const observed = lockToken(lock);
|
|
22630
22906
|
const age = lockAgeMs(lock);
|
|
22631
|
-
if (age !== null && age >
|
|
22907
|
+
if (age !== null && age > LOCK_STALE_MS2 && ledgerLock.reap(lock, observed))
|
|
22632
22908
|
continue;
|
|
22633
22909
|
if (Date.now() >= deadline)
|
|
22634
22910
|
return null;
|
|
@@ -22640,14 +22916,14 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
|
|
|
22640
22916
|
ledgerLock.release(lock, token);
|
|
22641
22917
|
}
|
|
22642
22918
|
}
|
|
22643
|
-
var sha2562 = (text) =>
|
|
22919
|
+
var sha2562 = (text) => createHash10("sha256").update(text).digest("hex");
|
|
22644
22920
|
var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
|
|
22645
22921
|
${body}`);
|
|
22646
22922
|
var TAIL_BYTES = 64 * 1024;
|
|
22647
22923
|
var lastLine = (fd, size) => {
|
|
22648
22924
|
for (let span = Math.min(size, TAIL_BYTES);span > 0; span = Math.min(size, span * 2)) {
|
|
22649
22925
|
const buffer = Buffer.alloc(span);
|
|
22650
|
-
|
|
22926
|
+
fs17.readSync(fd, buffer, 0, span, size - span);
|
|
22651
22927
|
const end = buffer.lastIndexOf(10);
|
|
22652
22928
|
if (end < 0) {
|
|
22653
22929
|
if (span === size)
|
|
@@ -22678,32 +22954,32 @@ var lastLine = (fd, size) => {
|
|
|
22678
22954
|
};
|
|
22679
22955
|
var tighten = (fd) => {
|
|
22680
22956
|
try {
|
|
22681
|
-
if ((
|
|
22682
|
-
|
|
22957
|
+
if ((fs17.fstatSync(fd).mode & 63) !== 0)
|
|
22958
|
+
fs17.fchmodSync(fd, 384);
|
|
22683
22959
|
} catch {}
|
|
22684
22960
|
};
|
|
22685
22961
|
function appendLine(file, build, options) {
|
|
22686
22962
|
const write = () => {
|
|
22687
|
-
const fd =
|
|
22963
|
+
const fd = fs17.openSync(file, "a+", 384);
|
|
22688
22964
|
try {
|
|
22689
22965
|
if (process.platform !== "win32")
|
|
22690
22966
|
tighten(fd);
|
|
22691
|
-
const line = build(lastLine(fd,
|
|
22967
|
+
const line = build(lastLine(fd, fs17.fstatSync(fd).size));
|
|
22692
22968
|
if (!line.ok)
|
|
22693
22969
|
return line;
|
|
22694
22970
|
const bytes = Buffer.from(`
|
|
22695
22971
|
${line.value}`);
|
|
22696
|
-
const written =
|
|
22972
|
+
const written = fs17.writeSync(fd, bytes);
|
|
22697
22973
|
if (written !== bytes.length)
|
|
22698
22974
|
return err("unavailable", `short write to ${file}: ${written} of ${bytes.length} bytes; the row is torn and will be skipped`);
|
|
22699
22975
|
return { ok: true, value: undefined };
|
|
22700
22976
|
} finally {
|
|
22701
|
-
|
|
22977
|
+
fs17.closeSync(fd);
|
|
22702
22978
|
}
|
|
22703
22979
|
};
|
|
22704
22980
|
try {
|
|
22705
|
-
|
|
22706
|
-
if (options.heldLock || !options.forceLock && !onNetworkFs(
|
|
22981
|
+
fs17.mkdirSync(path21.dirname(file), { recursive: true });
|
|
22982
|
+
if (options.heldLock || !options.forceLock && !onNetworkFs(path21.dirname(file)))
|
|
22707
22983
|
return write();
|
|
22708
22984
|
const locked = withLedgerLock(file, write);
|
|
22709
22985
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -22720,7 +22996,7 @@ var sealed = (row, id, at, previous) => {
|
|
|
22720
22996
|
` };
|
|
22721
22997
|
};
|
|
22722
22998
|
function appendRaw(cwd, row, options) {
|
|
22723
|
-
const file = options.store ? { ok: true, value:
|
|
22999
|
+
const file = options.store ? { ok: true, value: path21.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
|
|
22724
23000
|
if (!file.ok)
|
|
22725
23001
|
return file;
|
|
22726
23002
|
const id = newId2();
|
|
@@ -22774,8 +23050,8 @@ function readLedgerAt(cwd, file, options) {
|
|
|
22774
23050
|
let text = "";
|
|
22775
23051
|
let stat = null;
|
|
22776
23052
|
try {
|
|
22777
|
-
stat =
|
|
22778
|
-
text =
|
|
23053
|
+
stat = fs17.statSync(file);
|
|
23054
|
+
text = fs17.readFileSync(file, "utf8");
|
|
22779
23055
|
} catch (error) {
|
|
22780
23056
|
if (error.code === "ENOENT")
|
|
22781
23057
|
return {
|
|
@@ -22915,7 +23191,7 @@ function ledgerTampering(cwd) {
|
|
|
22915
23191
|
if (!file.ok)
|
|
22916
23192
|
return [];
|
|
22917
23193
|
try {
|
|
22918
|
-
const stat =
|
|
23194
|
+
const stat = fs17.statSync(file.value);
|
|
22919
23195
|
const cached = tamperCache.get(file.value);
|
|
22920
23196
|
if (cached && cached.size === stat.size && cached.stamp === fileStamp(stat))
|
|
22921
23197
|
return cached.breaks;
|
|
@@ -23382,8 +23658,8 @@ function remoteIdentity(cwd, hop = 0) {
|
|
|
23382
23658
|
return null;
|
|
23383
23659
|
if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
|
|
23384
23660
|
const local = raw.replace(/^file:\/\//u, "");
|
|
23385
|
-
const resolved =
|
|
23386
|
-
if (
|
|
23661
|
+
const resolved = path21.isAbsolute(local) ? local : path21.resolve(cwd, local);
|
|
23662
|
+
if (fs17.existsSync(resolved))
|
|
23387
23663
|
return remoteIdentity(resolved, 1);
|
|
23388
23664
|
}
|
|
23389
23665
|
const parsed = parseRemoteUrl(raw);
|
|
@@ -23403,8 +23679,8 @@ function verdictMirrorPath(cwd) {
|
|
|
23403
23679
|
}
|
|
23404
23680
|
if (!identity)
|
|
23405
23681
|
return null;
|
|
23406
|
-
const key =
|
|
23407
|
-
return
|
|
23682
|
+
const key = createHash10("sha256").update(identity).digest("hex").slice(0, 32);
|
|
23683
|
+
return path21.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
|
|
23408
23684
|
}
|
|
23409
23685
|
var importedStamp = new Map;
|
|
23410
23686
|
function importMirroredVerdicts(cwd, branch) {
|
|
@@ -23414,7 +23690,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
23414
23690
|
return [];
|
|
23415
23691
|
let stamp;
|
|
23416
23692
|
try {
|
|
23417
|
-
stamp = `${branch}\x00${fileStamp(
|
|
23693
|
+
stamp = `${branch}\x00${fileStamp(fs17.statSync(file))}`;
|
|
23418
23694
|
} catch {
|
|
23419
23695
|
return [];
|
|
23420
23696
|
}
|
|
@@ -23427,7 +23703,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
23427
23703
|
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
23428
23704
|
const added = new Set;
|
|
23429
23705
|
try {
|
|
23430
|
-
|
|
23706
|
+
fs17.mkdirSync(path21.dirname(local.value), { recursive: true });
|
|
23431
23707
|
} catch {
|
|
23432
23708
|
return [];
|
|
23433
23709
|
}
|
|
@@ -23631,7 +23907,7 @@ var productDecision = (task, ledger) => {
|
|
|
23631
23907
|
};
|
|
23632
23908
|
};
|
|
23633
23909
|
var planRecorded = (task, root) => {
|
|
23634
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" &&
|
|
23910
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path22.resolve(root, ref.path)));
|
|
23635
23911
|
if (cited)
|
|
23636
23912
|
return {
|
|
23637
23913
|
met: true,
|
|
@@ -23697,15 +23973,15 @@ function derivedRuleStatus(task, requirement, root, ledger) {
|
|
|
23697
23973
|
}
|
|
23698
23974
|
|
|
23699
23975
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
23700
|
-
var digestBytes = (value) =>
|
|
23701
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
23702
|
-
var relative = (root, candidate) =>
|
|
23976
|
+
var digestBytes = (value) => createHash11("sha256").update(value).digest("hex");
|
|
23977
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path23.sep}`);
|
|
23978
|
+
var relative = (root, candidate) => path23.relative(root, candidate).split(path23.sep).join("/") || ".";
|
|
23703
23979
|
var canonicalPath = (value) => {
|
|
23704
23980
|
if (typeof value !== "string" || !value)
|
|
23705
23981
|
return null;
|
|
23706
23982
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
23707
23983
|
return null;
|
|
23708
|
-
const normalized =
|
|
23984
|
+
const normalized = path23.posix.normalize(value);
|
|
23709
23985
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
23710
23986
|
return null;
|
|
23711
23987
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -23753,21 +24029,21 @@ var gitPaths = (root) => {
|
|
|
23753
24029
|
git: !/not a git repository/i.test(stderr)
|
|
23754
24030
|
};
|
|
23755
24031
|
}
|
|
23756
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
24032
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")) : [];
|
|
23757
24033
|
const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
23758
24034
|
if (stagedDeleted.status !== 0) {
|
|
23759
24035
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
23760
24036
|
if (!/not a git repository/i.test(stderr))
|
|
23761
24037
|
return { paths, uncertain: true, git: true };
|
|
23762
24038
|
} else if (stagedDeleted.stdout) {
|
|
23763
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
24039
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")));
|
|
23764
24040
|
}
|
|
23765
24041
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
23766
24042
|
};
|
|
23767
24043
|
var walk = (root, directory, output) => {
|
|
23768
24044
|
let names;
|
|
23769
24045
|
try {
|
|
23770
|
-
names =
|
|
24046
|
+
names = fs18.readdirSync(directory);
|
|
23771
24047
|
} catch {
|
|
23772
24048
|
return true;
|
|
23773
24049
|
}
|
|
@@ -23775,10 +24051,10 @@ var walk = (root, directory, output) => {
|
|
|
23775
24051
|
for (const name of names) {
|
|
23776
24052
|
if (name === ".git" || name === ".workit")
|
|
23777
24053
|
continue;
|
|
23778
|
-
const target =
|
|
24054
|
+
const target = path23.join(directory, name);
|
|
23779
24055
|
let stat;
|
|
23780
24056
|
try {
|
|
23781
|
-
stat =
|
|
24057
|
+
stat = fs18.lstatSync(target);
|
|
23782
24058
|
} catch {
|
|
23783
24059
|
uncertain = true;
|
|
23784
24060
|
continue;
|
|
@@ -23793,14 +24069,14 @@ var walk = (root, directory, output) => {
|
|
|
23793
24069
|
var scopeRoots = (root, scope) => {
|
|
23794
24070
|
const roots = [];
|
|
23795
24071
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
23796
|
-
const target =
|
|
24072
|
+
const target = path23.resolve(root, item);
|
|
23797
24073
|
if (!inside(root, target))
|
|
23798
24074
|
return failure2("invalid_input", `candidate scope escapes checkout: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} is outside the checkout` }] });
|
|
23799
24075
|
let ancestor = target;
|
|
23800
|
-
while (!
|
|
23801
|
-
ancestor =
|
|
24076
|
+
while (!fs18.existsSync(ancestor) && ancestor !== root)
|
|
24077
|
+
ancestor = path23.dirname(ancestor);
|
|
23802
24078
|
try {
|
|
23803
|
-
if (!inside(root,
|
|
24079
|
+
if (!inside(root, fs18.realpathSync(ancestor)))
|
|
23804
24080
|
return failure2("invalid_input", `candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] });
|
|
23805
24081
|
} catch {
|
|
23806
24082
|
return failure2("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
@@ -23812,7 +24088,7 @@ var scopeRoots = (root, scope) => {
|
|
|
23812
24088
|
function captureCandidate(root, scope, environment = []) {
|
|
23813
24089
|
let checkout;
|
|
23814
24090
|
try {
|
|
23815
|
-
checkout =
|
|
24091
|
+
checkout = fs18.realpathSync(root);
|
|
23816
24092
|
} catch {
|
|
23817
24093
|
return failure2("invalid_input", "candidate root does not exist");
|
|
23818
24094
|
}
|
|
@@ -23830,11 +24106,11 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
23830
24106
|
if (item === ".git" || item === ".workit")
|
|
23831
24107
|
continue;
|
|
23832
24108
|
names.add(item);
|
|
23833
|
-
if (!
|
|
24109
|
+
if (!fs18.existsSync(target))
|
|
23834
24110
|
continue;
|
|
23835
24111
|
let stat;
|
|
23836
24112
|
try {
|
|
23837
|
-
stat =
|
|
24113
|
+
stat = fs18.lstatSync(target);
|
|
23838
24114
|
} catch {
|
|
23839
24115
|
uncertain = true;
|
|
23840
24116
|
continue;
|
|
@@ -23850,17 +24126,17 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
23850
24126
|
for (const item of [...names].toSorted()) {
|
|
23851
24127
|
if (!scopeMatches(item, normalizedScope))
|
|
23852
24128
|
continue;
|
|
23853
|
-
const target =
|
|
24129
|
+
const target = path23.join(checkout, item);
|
|
23854
24130
|
try {
|
|
23855
|
-
const stat =
|
|
24131
|
+
const stat = fs18.lstatSync(target);
|
|
23856
24132
|
if (stat.isSymbolicLink()) {
|
|
23857
|
-
const link =
|
|
24133
|
+
const link = fs18.readlinkSync(target);
|
|
23858
24134
|
files.push({ path: item, kind: "symlink", digest: digestBytes(link), executable: null });
|
|
23859
24135
|
} else if (stat.isFile()) {
|
|
23860
24136
|
files.push({
|
|
23861
24137
|
path: item,
|
|
23862
24138
|
kind: "file",
|
|
23863
|
-
digest: digestBytes(
|
|
24139
|
+
digest: digestBytes(fs18.readFileSync(target)),
|
|
23864
24140
|
executable: (stat.mode & 73) !== 0
|
|
23865
24141
|
});
|
|
23866
24142
|
} else if (!stat.isDirectory()) {
|
|
@@ -24025,7 +24301,7 @@ var findingVerificationPasses = (findingCandidateId, evidence) => evidence.statu
|
|
|
24025
24301
|
var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
24026
24302
|
let root;
|
|
24027
24303
|
try {
|
|
24028
|
-
root =
|
|
24304
|
+
root = fs18.realpathSync(checkoutRoot);
|
|
24029
24305
|
} catch {
|
|
24030
24306
|
return failure2("permission_denied", "checkout root is unavailable");
|
|
24031
24307
|
}
|
|
@@ -24034,23 +24310,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
24034
24310
|
continue;
|
|
24035
24311
|
if (!reference.digest)
|
|
24036
24312
|
return failure2("invalid_input", "document references require a byte digest");
|
|
24037
|
-
const target =
|
|
24038
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
24313
|
+
const target = path23.resolve(root, reference.path);
|
|
24314
|
+
if (target !== root && !target.startsWith(`${root}${path23.sep}`))
|
|
24039
24315
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
24040
24316
|
fields: [
|
|
24041
24317
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
24042
24318
|
]
|
|
24043
24319
|
});
|
|
24044
24320
|
try {
|
|
24045
|
-
const below =
|
|
24321
|
+
const below = path23.relative(root, target);
|
|
24046
24322
|
let current = root;
|
|
24047
|
-
for (const segment of below.split(
|
|
24323
|
+
for (const segment of below.split(path23.sep)) {
|
|
24048
24324
|
if (!segment)
|
|
24049
24325
|
continue;
|
|
24050
|
-
current =
|
|
24051
|
-
const stat =
|
|
24052
|
-
const real =
|
|
24053
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
24326
|
+
current = path23.join(current, segment);
|
|
24327
|
+
const stat = fs18.lstatSync(current);
|
|
24328
|
+
const real = fs18.realpathSync(current);
|
|
24329
|
+
if (real !== root && !real.startsWith(`${root}${path23.sep}`))
|
|
24054
24330
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
24055
24331
|
fields: [
|
|
24056
24332
|
{
|
|
@@ -24066,7 +24342,7 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
24066
24342
|
if (current !== target && !stat.isDirectory())
|
|
24067
24343
|
return failure2("invalid_input", "document reference ancestor is not a directory");
|
|
24068
24344
|
}
|
|
24069
|
-
if (digestBytes(
|
|
24345
|
+
if (digestBytes(fs18.readFileSync(target)) !== reference.digest)
|
|
24070
24346
|
return failure2("permission_denied", "decision document bytes have changed");
|
|
24071
24347
|
} catch {
|
|
24072
24348
|
return failure2("invalid_input", "decision document is unavailable");
|
|
@@ -24415,8 +24691,8 @@ function briefInspectResult(request, result) {
|
|
|
24415
24691
|
}
|
|
24416
24692
|
|
|
24417
24693
|
// packages/workit-core/src/core/model-fallback.ts
|
|
24418
|
-
import { mkdirSync as
|
|
24419
|
-
import
|
|
24694
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync9, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
24695
|
+
import path24 from "node:path";
|
|
24420
24696
|
var LIMITS_FILE = "model-limits.json";
|
|
24421
24697
|
var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
|
|
24422
24698
|
var KEEP_MS = 9 * 86400000;
|
|
@@ -24439,7 +24715,7 @@ var providerOf = (model, host) => {
|
|
|
24439
24715
|
return null;
|
|
24440
24716
|
};
|
|
24441
24717
|
var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
|
|
24442
|
-
var storePath = (stateDir) =>
|
|
24718
|
+
var storePath = (stateDir) => path24.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
|
|
24443
24719
|
var readStore = (stateDir) => {
|
|
24444
24720
|
try {
|
|
24445
24721
|
const parsed = JSON.parse(readFileSync9(storePath(stateDir), "utf8"));
|
|
@@ -24856,26 +25132,26 @@ var exportDigest = (bundle) => sha256({
|
|
|
24856
25132
|
task: bundle.task
|
|
24857
25133
|
});
|
|
24858
25134
|
// packages/workit-core/src/autonomy.ts
|
|
24859
|
-
import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as
|
|
24860
|
-
import
|
|
25135
|
+
import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync12, openSync as openSync2 } from "node:fs";
|
|
25136
|
+
import path28 from "node:path";
|
|
24861
25137
|
|
|
24862
25138
|
// packages/workit-core/src/core/eval-world.ts
|
|
24863
|
-
import { existsSync as
|
|
24864
|
-
import
|
|
24865
|
-
import
|
|
25139
|
+
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
25140
|
+
import os6 from "node:os";
|
|
25141
|
+
import path25 from "node:path";
|
|
24866
25142
|
var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
|
|
24867
25143
|
var EVAL_WORLD_MARKER = ".workit-eval-world";
|
|
24868
25144
|
var inside2 = (dir, file) => {
|
|
24869
|
-
const rel =
|
|
24870
|
-
return !rel.startsWith("..") && !
|
|
25145
|
+
const rel = path25.relative(dir, file);
|
|
25146
|
+
return !rel.startsWith("..") && !path25.isAbsolute(rel);
|
|
24871
25147
|
};
|
|
24872
25148
|
var evalWorld = (cwd) => {
|
|
24873
25149
|
const raw = process.env[EVAL_WORLD_ENV];
|
|
24874
|
-
if (!raw || !
|
|
25150
|
+
if (!raw || !path25.isAbsolute(raw))
|
|
24875
25151
|
return null;
|
|
24876
25152
|
try {
|
|
24877
|
-
const world =
|
|
24878
|
-
return inside2(
|
|
25153
|
+
const world = realpathSync7(raw);
|
|
25154
|
+
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path25.join(world, EVAL_WORLD_MARKER)) ? world : null;
|
|
24879
25155
|
} catch {
|
|
24880
25156
|
return null;
|
|
24881
25157
|
}
|
|
@@ -24883,16 +25159,16 @@ var evalWorld = (cwd) => {
|
|
|
24883
25159
|
var evalWorldEntry = (cwd) => {
|
|
24884
25160
|
const world = evalWorld(cwd);
|
|
24885
25161
|
try {
|
|
24886
|
-
return world ? loadWorkspacesFrom(
|
|
25162
|
+
return world ? loadWorkspacesFrom(path25.join(world, "config"))[0] ?? null : null;
|
|
24887
25163
|
} catch {
|
|
24888
25164
|
return null;
|
|
24889
25165
|
}
|
|
24890
25166
|
};
|
|
24891
25167
|
|
|
24892
25168
|
// packages/workit-core/src/core/grant-seal.ts
|
|
24893
|
-
import { createHash as
|
|
25169
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
24894
25170
|
import { readFileSync as readFileSync10 } from "node:fs";
|
|
24895
|
-
import
|
|
25171
|
+
import path26 from "node:path";
|
|
24896
25172
|
var SEAL_FILE = "workspaces.json.seal";
|
|
24897
25173
|
var SEAL_VERSION = 1;
|
|
24898
25174
|
var SEAL_COMMAND = "workit workspace seal";
|
|
@@ -24926,15 +25202,15 @@ var sealProjection = (entries) => entries.map((entry) => {
|
|
|
24926
25202
|
youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
|
|
24927
25203
|
}, ENTRY_KEYS);
|
|
24928
25204
|
});
|
|
24929
|
-
var
|
|
24930
|
-
var sealDigest = (projection) =>
|
|
25205
|
+
var canonical4 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
|
|
25206
|
+
var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
|
|
24931
25207
|
var broken = (reason, sealed = null) => ({
|
|
24932
25208
|
state: "broken",
|
|
24933
25209
|
reason,
|
|
24934
25210
|
sealed
|
|
24935
25211
|
});
|
|
24936
25212
|
function checkSeal(dir) {
|
|
24937
|
-
const file =
|
|
25213
|
+
const file = path26.join(dir, SEAL_FILE);
|
|
24938
25214
|
let seal;
|
|
24939
25215
|
try {
|
|
24940
25216
|
seal = JSON.parse(readFileSync10(file, "utf8"));
|
|
@@ -24957,8 +25233,8 @@ function checkSeal(dir) {
|
|
|
24957
25233
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
24958
25234
|
|
|
24959
25235
|
// packages/workit-core/src/forge/exec.ts
|
|
24960
|
-
import
|
|
24961
|
-
import
|
|
25236
|
+
import fs19 from "node:fs";
|
|
25237
|
+
import path27 from "node:path";
|
|
24962
25238
|
|
|
24963
25239
|
// packages/workit-core/src/forge/redact.ts
|
|
24964
25240
|
var NAME = "[A-Za-z0-9_.-]";
|
|
@@ -24971,13 +25247,13 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u0
|
|
|
24971
25247
|
// packages/workit-core/src/forge/exec.ts
|
|
24972
25248
|
var MAX_BUFFER2 = 64 * 1024 * 1024;
|
|
24973
25249
|
function findExecutable(bin, env) {
|
|
24974
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
25250
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path27.delimiter).filter(Boolean);
|
|
24975
25251
|
const exts = process.platform === "win32" ? [".exe"] : [""];
|
|
24976
25252
|
for (const dir of dirs)
|
|
24977
25253
|
for (const ext of exts) {
|
|
24978
|
-
const candidate =
|
|
25254
|
+
const candidate = path27.join(dir, `${bin}${ext}`);
|
|
24979
25255
|
try {
|
|
24980
|
-
const stat =
|
|
25256
|
+
const stat = fs19.statSync(candidate);
|
|
24981
25257
|
if (stat.isFile())
|
|
24982
25258
|
return candidate;
|
|
24983
25259
|
} catch {}
|
|
@@ -25032,7 +25308,7 @@ var accountHomeDir = () => {
|
|
|
25032
25308
|
};
|
|
25033
25309
|
var deniedFile = (dir) => {
|
|
25034
25310
|
for (const name of ["workspaces.json", SEAL_FILE]) {
|
|
25035
|
-
const file =
|
|
25311
|
+
const file = path28.join(dir, name);
|
|
25036
25312
|
try {
|
|
25037
25313
|
closeSync2(openSync2(file, "r"));
|
|
25038
25314
|
} catch (error) {
|
|
@@ -25054,7 +25330,7 @@ var accountUnread = () => {
|
|
|
25054
25330
|
if (dir === null)
|
|
25055
25331
|
return NO_ACCOUNT;
|
|
25056
25332
|
const file = deniedFile(dir);
|
|
25057
|
-
return file === null ? null : `the account's ${
|
|
25333
|
+
return file === null ? null : `the account's ${path28.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
|
|
25058
25334
|
};
|
|
25059
25335
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
25060
25336
|
var fileSource = (dir = accountDir()) => ({
|
|
@@ -25075,7 +25351,7 @@ var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never r
|
|
|
25075
25351
|
var sealNote = (seal = sealOf()) => seal.state === "broken" ? `workspaces.json does not match its seal (${seal.reason}), so grants, endpoint, verification and youtrack.writes are the stricter of their current and last sealed values; ${SEAL_UNBLOCK}` : null;
|
|
25076
25352
|
var shownGrantsDir = () => {
|
|
25077
25353
|
const world = evalWorld(process.cwd());
|
|
25078
|
-
return world ?
|
|
25354
|
+
return world ? path28.join(world, "config") : accountDir();
|
|
25079
25355
|
};
|
|
25080
25356
|
var benchWorld = (cwd) => {
|
|
25081
25357
|
const entry = evalWorldEntry(cwd);
|
|
@@ -25099,10 +25375,10 @@ var grantsOverride = () => {
|
|
|
25099
25375
|
const shown = shownGrantsDir();
|
|
25100
25376
|
if (shown === null)
|
|
25101
25377
|
return accountUnread() ?? NO_ACCOUNT;
|
|
25102
|
-
const configured =
|
|
25103
|
-
return configured ===
|
|
25378
|
+
const configured = path28.resolve(resolveConfigDir());
|
|
25379
|
+
return configured === path28.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path28.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
|
|
25104
25380
|
};
|
|
25105
|
-
var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${
|
|
25381
|
+
var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${path28.join(grantsDir(), "workspaces.json")}`;
|
|
25106
25382
|
var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
|
|
25107
25383
|
var DEFAULT_GRANTS = Object.freeze({
|
|
25108
25384
|
push: true,
|
|
@@ -25503,7 +25779,7 @@ var BRANCH_RENAME = new Set(["-m", "-M", "--move", "-c", "-C", "--copy"]);
|
|
|
25503
25779
|
var WORKTREE_VALUES = new Set(["--reason"]);
|
|
25504
25780
|
var FETCH_VALUES = new Set(["--depth", "--deepen", "--shallow-since", "--shallow-exclude", "--refmap", "-j", "--jobs"].concat(["--upload-pack", "-o", "--server-option", "--negotiation-tip", "--filter"]).concat(["--recurse-submodules-default", "--submodule-prefix", "-s", "--strategy", "-X"]).concat(["--strategy-option"]));
|
|
25505
25781
|
// packages/workit-core/src/core/task-engine.ts
|
|
25506
|
-
import { realpathSync as
|
|
25782
|
+
import { realpathSync as realpathSync9 } from "node:fs";
|
|
25507
25783
|
|
|
25508
25784
|
// packages/workit-core/src/core/policy-resolver.ts
|
|
25509
25785
|
function resolvePolicy(input) {
|
|
@@ -25752,12 +26028,12 @@ var judgeInputSummary = (raw) => {
|
|
|
25752
26028
|
};
|
|
25753
26029
|
|
|
25754
26030
|
// packages/workit-core/src/core/task-view.ts
|
|
25755
|
-
import { realpathSync as
|
|
26031
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
25756
26032
|
var environment = () => [];
|
|
25757
26033
|
var sameSession2 = (value, context) => typeof value === "object" && value !== null && value.kind === "host" && value.host === context.caller.host && value.handle === context.caller.actor;
|
|
25758
26034
|
function contextRootError(store, context) {
|
|
25759
26035
|
try {
|
|
25760
|
-
|
|
26036
|
+
realpathSync8(context.root);
|
|
25761
26037
|
const root = checkoutRootOf(context.root);
|
|
25762
26038
|
if (root !== store.root && !sameDirectoryIdentity(root, store.root))
|
|
25763
26039
|
return failure2("invalid_input", "operation context root does not match the task store root");
|
|
@@ -27227,7 +27503,7 @@ class WorkitCore {
|
|
|
27227
27503
|
if (view.task.workspaceId !== view.workspace.id)
|
|
27228
27504
|
return failure2("invalid_input", "task and workspace bindings are invalid");
|
|
27229
27505
|
try {
|
|
27230
|
-
if (
|
|
27506
|
+
if (realpathSync9(view.workspace.root) !== this.store.root)
|
|
27231
27507
|
return failure2("invalid_input", "task view root does not match the task store");
|
|
27232
27508
|
} catch {
|
|
27233
27509
|
return failure2("invalid_input", "task view root cannot be resolved");
|
|
@@ -27478,8 +27754,8 @@ class WorkitCore {
|
|
|
27478
27754
|
}
|
|
27479
27755
|
// packages/workit-core/src/core/repo-context.ts
|
|
27480
27756
|
import { spawnSync as spawnSync17 } from "node:child_process";
|
|
27481
|
-
import { existsSync as
|
|
27482
|
-
import
|
|
27757
|
+
import { existsSync as existsSync13, readFileSync as readFileSync11, readdirSync as readdirSync4 } from "node:fs";
|
|
27758
|
+
import path29 from "node:path";
|
|
27483
27759
|
var isSafeContextRange = (value) => value.length <= 4096 && (() => {
|
|
27484
27760
|
try {
|
|
27485
27761
|
gitRevisionParts(value);
|
|
@@ -27623,13 +27899,13 @@ var findPrTemplate = (cwd) => {
|
|
|
27623
27899
|
for (const rel of PR_TEMPLATE_FILES) {
|
|
27624
27900
|
const parts = rel.split("/");
|
|
27625
27901
|
const base = parts[parts.length - 1];
|
|
27626
|
-
const dir = parts.length > 1 ?
|
|
27902
|
+
const dir = parts.length > 1 ? path29.join(cwd, ...parts.slice(0, -1)) : cwd;
|
|
27627
27903
|
const actual = probeCaseInsensitive(dir, base);
|
|
27628
27904
|
if (actual)
|
|
27629
27905
|
return [...parts.slice(0, -1), actual].join("/");
|
|
27630
27906
|
}
|
|
27631
27907
|
for (const rel of PR_TEMPLATE_DIRS) {
|
|
27632
|
-
const only = singleMarkdown(
|
|
27908
|
+
const only = singleMarkdown(path29.join(cwd, ...rel.split("/")));
|
|
27633
27909
|
if (only)
|
|
27634
27910
|
return `${rel}/${only}`;
|
|
27635
27911
|
}
|
|
@@ -27659,8 +27935,8 @@ var diffStatForRange = (cwd, range) => {
|
|
|
27659
27935
|
return runGit(cwd, ["diff", "--stat", "--"]).stdout;
|
|
27660
27936
|
};
|
|
27661
27937
|
var packageScripts = (cwd, keys) => {
|
|
27662
|
-
const pkgPath =
|
|
27663
|
-
if (!
|
|
27938
|
+
const pkgPath = path29.join(cwd, "package.json");
|
|
27939
|
+
if (!existsSync13(pkgPath))
|
|
27664
27940
|
return [];
|
|
27665
27941
|
try {
|
|
27666
27942
|
const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
|
|
@@ -27685,9 +27961,9 @@ var documentationFiles = (cwd) => {
|
|
|
27685
27961
|
if (entry.isDirectory()) {
|
|
27686
27962
|
if (excluded.has(entry.name))
|
|
27687
27963
|
continue;
|
|
27688
|
-
walk(
|
|
27964
|
+
walk(path29.join(dir, entry.name), depth + 1);
|
|
27689
27965
|
} else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
|
|
27690
|
-
matches.push("./" +
|
|
27966
|
+
matches.push("./" + path29.relative(cwd, path29.join(dir, entry.name)).replaceAll("\\", "/"));
|
|
27691
27967
|
}
|
|
27692
27968
|
}
|
|
27693
27969
|
};
|
|
@@ -27695,7 +27971,7 @@ var documentationFiles = (cwd) => {
|
|
|
27695
27971
|
return matches.toSorted().slice(0, 200);
|
|
27696
27972
|
};
|
|
27697
27973
|
var readTrimmed2 = (file, maxLines) => {
|
|
27698
|
-
if (!
|
|
27974
|
+
if (!existsSync13(file))
|
|
27699
27975
|
return "";
|
|
27700
27976
|
const lines = readFileSync11(file, "utf8").split(`
|
|
27701
27977
|
`);
|
|
@@ -27703,7 +27979,7 @@ var readTrimmed2 = (file, maxLines) => {
|
|
|
27703
27979
|
`);
|
|
27704
27980
|
};
|
|
27705
27981
|
function prReadyContext(root, range) {
|
|
27706
|
-
const cwd =
|
|
27982
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
27707
27983
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
27708
27984
|
return invalidRange(cwd);
|
|
27709
27985
|
let stdout = "";
|
|
@@ -27761,7 +28037,7 @@ ${status.stderr}` : "");
|
|
|
27761
28037
|
stdout += `template_path: ${template}
|
|
27762
28038
|
|
|
27763
28039
|
`;
|
|
27764
|
-
stdout += readTrimmed2(
|
|
28040
|
+
stdout += readTrimmed2(path29.join(cwd, template), 220);
|
|
27765
28041
|
} else {
|
|
27766
28042
|
stdout += `template_path: none
|
|
27767
28043
|
|
|
@@ -27771,7 +28047,7 @@ ${status.stderr}` : "");
|
|
|
27771
28047
|
stdout += `
|
|
27772
28048
|
`;
|
|
27773
28049
|
stdout += printSection("Recent Validation Signals");
|
|
27774
|
-
if (
|
|
28050
|
+
if (existsSync13(path29.join(cwd, "package.json"))) {
|
|
27775
28051
|
stdout += `package.json detected. Common scripts:
|
|
27776
28052
|
`;
|
|
27777
28053
|
const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
|
|
@@ -27780,7 +28056,7 @@ ${status.stderr}` : "");
|
|
|
27780
28056
|
`) + `
|
|
27781
28057
|
`;
|
|
27782
28058
|
}
|
|
27783
|
-
if (
|
|
28059
|
+
if (existsSync13(path29.join(cwd, "Cargo.toml")) || existsSync13(path29.join(cwd, "src-tauri/Cargo.toml"))) {
|
|
27784
28060
|
stdout += `Rust project detected.
|
|
27785
28061
|
`;
|
|
27786
28062
|
}
|
|
@@ -27813,7 +28089,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
|
|
|
27813
28089
|
- Apply with the host-native editor, preserving the repository changelog conventions.
|
|
27814
28090
|
- If Unreleased already has duplicate category headings, normalize_only first.`;
|
|
27815
28091
|
function changelogContext(root, range) {
|
|
27816
|
-
const cwd =
|
|
28092
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
27817
28093
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
27818
28094
|
return invalidRange(cwd);
|
|
27819
28095
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -27831,8 +28107,8 @@ function changelogContext(root, range) {
|
|
|
27831
28107
|
stdout += CHANGELOG_RULES + `
|
|
27832
28108
|
`;
|
|
27833
28109
|
stdout += printSection("Existing CHANGELOG.md");
|
|
27834
|
-
const changelogPath =
|
|
27835
|
-
if (
|
|
28110
|
+
const changelogPath = path29.join(cwd, "CHANGELOG.md");
|
|
28111
|
+
if (existsSync13(changelogPath)) {
|
|
27836
28112
|
stdout += readTrimmed2(changelogPath, 260) + `
|
|
27837
28113
|
`;
|
|
27838
28114
|
} else {
|
|
@@ -27851,7 +28127,7 @@ function changelogContext(root, range) {
|
|
|
27851
28127
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
27852
28128
|
}
|
|
27853
28129
|
function docsRefreshContext(root, range) {
|
|
27854
|
-
const cwd =
|
|
28130
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
27855
28131
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
27856
28132
|
return invalidRange(cwd);
|
|
27857
28133
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -27873,8 +28149,8 @@ function docsRefreshContext(root, range) {
|
|
|
27873
28149
|
`) + `
|
|
27874
28150
|
`;
|
|
27875
28151
|
stdout += printSection("README Preview");
|
|
27876
|
-
const readme =
|
|
27877
|
-
if (
|
|
28152
|
+
const readme = path29.join(cwd, "README.md");
|
|
28153
|
+
if (existsSync13(readme)) {
|
|
27878
28154
|
stdout += readTrimmed2(readme, 220) + `
|
|
27879
28155
|
`;
|
|
27880
28156
|
} else {
|
|
@@ -27882,8 +28158,8 @@ function docsRefreshContext(root, range) {
|
|
|
27882
28158
|
`;
|
|
27883
28159
|
}
|
|
27884
28160
|
stdout += printSection("Package Scripts");
|
|
27885
|
-
const pkgPath =
|
|
27886
|
-
if (
|
|
28161
|
+
const pkgPath = path29.join(cwd, "package.json");
|
|
28162
|
+
if (existsSync13(pkgPath)) {
|
|
27887
28163
|
try {
|
|
27888
28164
|
const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
|
|
27889
28165
|
stdout += JSON.stringify({ name: pkg.name, version: pkg.version, scripts: pkg.scripts }, null, 2) + `
|
|
@@ -27896,7 +28172,7 @@ function docsRefreshContext(root, range) {
|
|
|
27896
28172
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
27897
28173
|
}
|
|
27898
28174
|
function releaseNotesContext(root, rangeOrTag) {
|
|
27899
|
-
const cwd =
|
|
28175
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
27900
28176
|
if (!rangeOrTag) {
|
|
27901
28177
|
return {
|
|
27902
28178
|
stdout: "",
|
|
@@ -27939,7 +28215,7 @@ function releaseNotesContext(root, rangeOrTag) {
|
|
|
27939
28215
|
`;
|
|
27940
28216
|
stdout += printSection("Existing Release Files");
|
|
27941
28217
|
for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
|
|
27942
|
-
if (
|
|
28218
|
+
if (existsSync13(path29.join(cwd, rel)))
|
|
27943
28219
|
stdout += rel + `
|
|
27944
28220
|
`;
|
|
27945
28221
|
}
|
|
@@ -27970,8 +28246,8 @@ function releaseNotesContext(root, rangeOrTag) {
|
|
|
27970
28246
|
import { spawnSync as spawnSync19 } from "node:child_process";
|
|
27971
28247
|
|
|
27972
28248
|
// packages/workit-core/src/core/pr-create.ts
|
|
27973
|
-
import
|
|
27974
|
-
import
|
|
28249
|
+
import fs20 from "node:fs";
|
|
28250
|
+
import path30 from "node:path";
|
|
27975
28251
|
import { spawnSync as spawnSync18 } from "node:child_process";
|
|
27976
28252
|
// packages/workit-core/src/forge/pr-body.ts
|
|
27977
28253
|
function parseGhIssue(value) {
|
|
@@ -27991,13 +28267,13 @@ var LOCAL = bounded(20000);
|
|
|
27991
28267
|
var NETWORK = bounded(60000);
|
|
27992
28268
|
function whichOnPath(tool) {
|
|
27993
28269
|
const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
|
|
27994
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
28270
|
+
for (const dir of (process.env.PATH ?? "").split(path30.delimiter)) {
|
|
27995
28271
|
if (!dir)
|
|
27996
28272
|
continue;
|
|
27997
28273
|
for (const name of names) {
|
|
27998
|
-
const candidate =
|
|
28274
|
+
const candidate = path30.join(dir, name);
|
|
27999
28275
|
try {
|
|
28000
|
-
|
|
28276
|
+
fs20.accessSync(candidate, fs20.constants.X_OK);
|
|
28001
28277
|
return candidate;
|
|
28002
28278
|
} catch {}
|
|
28003
28279
|
}
|
|
@@ -28115,8 +28391,8 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
|
|
|
28115
28391
|
};
|
|
28116
28392
|
|
|
28117
28393
|
// packages/workit-core/src/core/youtrack.ts
|
|
28118
|
-
import
|
|
28119
|
-
import
|
|
28394
|
+
import fs21 from "node:fs";
|
|
28395
|
+
import path31 from "node:path";
|
|
28120
28396
|
|
|
28121
28397
|
// packages/workit-core/src/core/templates.ts
|
|
28122
28398
|
var repoRoot2 = assetRoot();
|
|
@@ -28128,14 +28404,14 @@ var resolveWorkspaceRoot = (explicit) => explicit || process.cwd();
|
|
|
28128
28404
|
|
|
28129
28405
|
// packages/workit-core/src/core/youtrack.ts
|
|
28130
28406
|
var ISSUE_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
|
|
28131
|
-
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ??
|
|
28407
|
+
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path31.join(resolveConfigDir(), "youtrack.json");
|
|
28132
28408
|
var readYouTrackContextConfig = () => {
|
|
28133
28409
|
const cfgPath = youTrackReadOnlyConfigPath();
|
|
28134
|
-
if (!
|
|
28410
|
+
if (!fs21.existsSync(cfgPath))
|
|
28135
28411
|
return { data: {} };
|
|
28136
28412
|
let parsed;
|
|
28137
28413
|
try {
|
|
28138
|
-
parsed = JSON.parse(
|
|
28414
|
+
parsed = JSON.parse(fs21.readFileSync(cfgPath, "utf8"));
|
|
28139
28415
|
} catch {
|
|
28140
28416
|
return { error: "YouTrack configuration is unavailable" };
|
|
28141
28417
|
}
|
|
@@ -28206,9 +28482,9 @@ function resolveYouTrackFromPaths(spec_path, plan_path, workspace_root) {
|
|
|
28206
28482
|
} catch {
|
|
28207
28483
|
continue;
|
|
28208
28484
|
}
|
|
28209
|
-
if (!
|
|
28485
|
+
if (!fs21.existsSync(full))
|
|
28210
28486
|
continue;
|
|
28211
|
-
const text =
|
|
28487
|
+
const text = fs21.readFileSync(full, "utf8");
|
|
28212
28488
|
const m = text.match(/^\*\*YouTrack:\*\*\s*`?([A-Z]+-\d+)`?/m);
|
|
28213
28489
|
if (m)
|
|
28214
28490
|
return m[1];
|
|
@@ -28480,22 +28756,22 @@ function resolveGitRevision(root, value) {
|
|
|
28480
28756
|
}
|
|
28481
28757
|
}
|
|
28482
28758
|
function resolveInside(root, candidate) {
|
|
28483
|
-
const base =
|
|
28484
|
-
const target =
|
|
28485
|
-
if (target !== base && !target.startsWith(base +
|
|
28759
|
+
const base = realpathSync10(root);
|
|
28760
|
+
const target = path32.resolve(base, candidate);
|
|
28761
|
+
if (target !== base && !target.startsWith(base + path32.sep)) {
|
|
28486
28762
|
throw new Error("path must stay inside repository root");
|
|
28487
28763
|
}
|
|
28488
28764
|
let ancestor = target;
|
|
28489
|
-
while (!
|
|
28490
|
-
ancestor =
|
|
28491
|
-
const canonicalAncestor =
|
|
28492
|
-
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base +
|
|
28765
|
+
while (!existsSync14(ancestor))
|
|
28766
|
+
ancestor = path32.dirname(ancestor);
|
|
28767
|
+
const canonicalAncestor = realpathSync10(ancestor);
|
|
28768
|
+
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path32.sep)) {
|
|
28493
28769
|
throw new Error("path must stay inside repository root");
|
|
28494
28770
|
}
|
|
28495
28771
|
return target;
|
|
28496
28772
|
}
|
|
28497
28773
|
function run2(root, executable, args, env = {}) {
|
|
28498
|
-
const cwd =
|
|
28774
|
+
const cwd = realpathSync10(root);
|
|
28499
28775
|
const result = spawnSync20(executable, args, {
|
|
28500
28776
|
cwd,
|
|
28501
28777
|
encoding: "utf8",
|
|
@@ -28510,18 +28786,18 @@ function run2(root, executable, args, env = {}) {
|
|
|
28510
28786
|
}
|
|
28511
28787
|
|
|
28512
28788
|
// packages/workit-core/src/core/cli-locate.ts
|
|
28513
|
-
import { closeSync as closeSync3, existsSync as
|
|
28514
|
-
import
|
|
28789
|
+
import { closeSync as closeSync3, existsSync as existsSync15, openSync as openSync3, readSync } from "node:fs";
|
|
28790
|
+
import path33 from "node:path";
|
|
28515
28791
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
28516
28792
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
28517
28793
|
var installRoot = (env, platform = process.platform) => {
|
|
28518
28794
|
if (env.WORKIT_INSTALL_ROOT)
|
|
28519
28795
|
return env.WORKIT_INSTALL_ROOT;
|
|
28520
28796
|
const data = dataDir(env, platform);
|
|
28521
|
-
return platform === "win32" ?
|
|
28797
|
+
return platform === "win32" ? path33.join(data, "install") : data;
|
|
28522
28798
|
};
|
|
28523
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
28524
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
28799
|
+
var ownedLauncherPath = (env, platform = process.platform) => path33.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
28800
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path33.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
28525
28801
|
var head = (file) => {
|
|
28526
28802
|
let fd;
|
|
28527
28803
|
try {
|
|
@@ -28539,7 +28815,7 @@ var head = (file) => {
|
|
|
28539
28815
|
var locateWorkitCli = (options = {}) => {
|
|
28540
28816
|
const env = options.env ?? process.env;
|
|
28541
28817
|
const platform = options.platform ?? process.platform;
|
|
28542
|
-
const exists = options.exists ??
|
|
28818
|
+
const exists = options.exists ?? existsSync15;
|
|
28543
28819
|
const read = options.read ?? head;
|
|
28544
28820
|
const node = options.node ?? process.execPath;
|
|
28545
28821
|
const launcher = ownedLauncherPath(env, platform);
|
|
@@ -28548,7 +28824,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
28548
28824
|
source: "owned-launcher",
|
|
28549
28825
|
command: launcher,
|
|
28550
28826
|
args: [],
|
|
28551
|
-
binDir:
|
|
28827
|
+
binDir: path33.dirname(launcher)
|
|
28552
28828
|
};
|
|
28553
28829
|
const current = ownedCurrentEntry(env, platform);
|
|
28554
28830
|
if (exists(current))
|
|
@@ -28577,7 +28853,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
28577
28853
|
if (located.binDir) {
|
|
28578
28854
|
const key = pathKey(env);
|
|
28579
28855
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
28580
|
-
const same = (dir) => platform === "win32" ?
|
|
28856
|
+
const same = (dir) => platform === "win32" ? path33.win32.normalize(dir).toLowerCase() === path33.win32.normalize(located.binDir).toLowerCase() : path33.posix.normalize(dir) === path33.posix.normalize(located.binDir);
|
|
28581
28857
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
28582
28858
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
28583
28859
|
}
|
|
@@ -28601,8 +28877,8 @@ var SUPPORT_MATRIX = {
|
|
|
28601
28877
|
};
|
|
28602
28878
|
|
|
28603
28879
|
// packages/workit-mcp/src/server.ts
|
|
28604
|
-
import { existsSync as
|
|
28605
|
-
import
|
|
28880
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12, realpathSync as realpathSync11 } from "node:fs";
|
|
28881
|
+
import path34 from "node:path";
|
|
28606
28882
|
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
28607
28883
|
function isZ4Schema(s) {
|
|
28608
28884
|
const schema = s;
|
|
@@ -30998,11 +31274,11 @@ var changedSourcesSinceLoad = (marker) => {
|
|
|
30998
31274
|
};
|
|
30999
31275
|
|
|
31000
31276
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
31001
|
-
import { createHash as
|
|
31277
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
31002
31278
|
var SAME_CALL_FAILED = "Same call failed twice:";
|
|
31003
31279
|
var MAX_SESSIONS = 256;
|
|
31004
31280
|
var stable = (value) => JSON.stringify(value, (_key, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([a], [b]) => a.localeCompare(b))) : entry) ?? "null";
|
|
31005
|
-
var hashOf = (call) =>
|
|
31281
|
+
var hashOf = (call) => createHash13("sha256").update(call).digest("hex").slice(0, 32);
|
|
31006
31282
|
var record3 = (memo, sessionId, call, failed, next) => {
|
|
31007
31283
|
const previous = memo.get(sessionId);
|
|
31008
31284
|
memo.delete(sessionId);
|
|
@@ -31067,13 +31343,13 @@ var rootVariants = (workspaceRoot) => {
|
|
|
31067
31343
|
if (!workspaceRoot)
|
|
31068
31344
|
return [];
|
|
31069
31345
|
const roots = new Set;
|
|
31070
|
-
for (const candidate of [workspaceRoot,
|
|
31071
|
-
if (
|
|
31346
|
+
for (const candidate of [workspaceRoot, path34.resolve(workspaceRoot)]) {
|
|
31347
|
+
if (path34.isAbsolute(candidate) && candidate !== path34.parse(candidate).root)
|
|
31072
31348
|
roots.add(candidate);
|
|
31073
31349
|
}
|
|
31074
31350
|
try {
|
|
31075
|
-
const canonical =
|
|
31076
|
-
if (canonical !==
|
|
31351
|
+
const canonical = realpathSync11(workspaceRoot);
|
|
31352
|
+
if (canonical !== path34.parse(canonical).root)
|
|
31077
31353
|
roots.add(canonical);
|
|
31078
31354
|
} catch {}
|
|
31079
31355
|
return [...roots].toSorted((left, right) => right.length - left.length);
|
|
@@ -31155,12 +31431,12 @@ var thrownResult = (tool, error, workspaceRoot) => {
|
|
|
31155
31431
|
};
|
|
31156
31432
|
function createMcpServer(host, contextProvider) {
|
|
31157
31433
|
assertMcpHost(host);
|
|
31158
|
-
const here =
|
|
31434
|
+
const here = path34.dirname(fileURLToPath2(import.meta.url));
|
|
31159
31435
|
const sourceMarker = markSourcesLoaded([
|
|
31160
|
-
|
|
31161
|
-
|
|
31162
|
-
|
|
31163
|
-
].filter((file) =>
|
|
31436
|
+
path34.join(here, "server.ts"),
|
|
31437
|
+
path34.join(here, "..", "..", "workit-core", "src", "core", "task-contract.ts"),
|
|
31438
|
+
path34.join(here, "..", "..", "workit-core", "src", "core", "task-engine.ts")
|
|
31439
|
+
].filter((file) => existsSync16(file)));
|
|
31164
31440
|
let staleWarned = false;
|
|
31165
31441
|
const failures = new Map;
|
|
31166
31442
|
const server = new Server({ name: "workit", version: VERSION }, { capabilities: { tools: {}, resources: {} } });
|
|
@@ -31542,7 +31818,7 @@ var COMPOSE_VALUES = new Set([
|
|
|
31542
31818
|
// packages/workit-core/src/core/heavy-words.ts
|
|
31543
31819
|
var HEAVY_WORDS = new Set(("npm npx pnpm pnpx yarn bun bunx deno corepack make gmake docker podman nerdctl " + "python python3 py uv poetry pdm pipenv hatch rye bundle rake nx " + "jest vitest mocha ava tap karma jasmine nyc c8 tsc vue-tsc svelte-check eslint stylelint " + "tslint webpack webpack-cli rollup parcel tsup vite next nuxt nuxi astro ng react-scripts " + "playwright cypress wdio testcafe turbo lerna sonar-scanner sonarless sonarless-mcp go " + "golangci-lint gotestsum staticcheck cargo mvn mvnw gradle gradlew ant sbt bazel bazelisk " + "buck2 dotnet msbuild pytest py.test tox nox mypy pyright pylint coverage maturin pip pip3 " + "rspec rails phpunit pest phpstan psalm composer mix swift xcodebuild flutter dart pod cmake " + "ninja meson ctest scons docker-compose buildah earthly").split(" "));
|
|
31544
31820
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
31545
|
-
import
|
|
31821
|
+
import path35 from "node:path";
|
|
31546
31822
|
|
|
31547
31823
|
// packages/workit-core/src/core/live-session.ts
|
|
31548
31824
|
import { spawnSync as spawnSync21 } from "node:child_process";
|
|
@@ -31584,7 +31860,7 @@ var PLACEHOLDERS = new WeakMap;
|
|
|
31584
31860
|
var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
31585
31861
|
var PUSHD2 = new Set(["pushd", "push-location"]);
|
|
31586
31862
|
var POPD2 = new Set(["popd", "pop-location"]);
|
|
31587
|
-
var UNKNOWN_DIR =
|
|
31863
|
+
var UNKNOWN_DIR = path35.resolve(path35.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
31588
31864
|
var DECLARERS = new Set(["export", "declare", "typeset", "local", "readonly"]);
|
|
31589
31865
|
var REBINDS_ANY = new Set([
|
|
31590
31866
|
"source",
|
|
@@ -31638,7 +31914,7 @@ var OPENS = new Set(["if", "for", "while", "until", "{"]);
|
|
|
31638
31914
|
var CLOSES = new Set(["fi", "done", "}"]);
|
|
31639
31915
|
var UNFOLLOWED = new Set(["case", "esac", "select", "function"]);
|
|
31640
31916
|
var TRANSPARENT = new Set(["builtin", "command", "time", "!"]);
|
|
31641
|
-
var UNKNOWN_VAR =
|
|
31917
|
+
var UNKNOWN_VAR = path35.resolve(path35.parse(process.cwd()).root, ".workit-unknown-var");
|
|
31642
31918
|
// packages/workit-core/src/core/skill-manifests.ts
|
|
31643
31919
|
if (false) {}
|
|
31644
31920
|
|
|
@@ -31679,16 +31955,16 @@ var PROMPT_INTENTS = [
|
|
|
31679
31955
|
].map(([name, pattern]) => [`workit-${name}`, pattern]);
|
|
31680
31956
|
var READERS = new Set("cat sed head tail less more bat nl get-content gc type".split(" "));
|
|
31681
31957
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
31682
|
-
import { existsSync as
|
|
31683
|
-
import
|
|
31958
|
+
import { existsSync as existsSync17, realpathSync as realpathSync12, statSync as statSync5 } from "node:fs";
|
|
31959
|
+
import path36 from "node:path";
|
|
31684
31960
|
var isRecord5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31685
31961
|
var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
31686
31962
|
var optionalText = (value) => typeof value === "string" ? value : null;
|
|
31687
31963
|
var existingDirectory = (value) => {
|
|
31688
|
-
if (!nonEmpty2(value) || !
|
|
31964
|
+
if (!nonEmpty2(value) || !path36.isAbsolute(value) || !existsSync17(value))
|
|
31689
31965
|
return null;
|
|
31690
31966
|
try {
|
|
31691
|
-
return statSync5(value).isDirectory() ?
|
|
31967
|
+
return statSync5(value).isDirectory() ? realpathSync12(value) : null;
|
|
31692
31968
|
} catch {
|
|
31693
31969
|
return null;
|
|
31694
31970
|
}
|
|
@@ -32483,13 +32759,13 @@ var PROCESS_START = performance.timeOrigin;
|
|
|
32483
32759
|
// packages/workit-core/src/hooks/run.ts
|
|
32484
32760
|
if (false) {}
|
|
32485
32761
|
// packages/workit-core/src/hooks/budget-signal.ts
|
|
32486
|
-
import { createHash as
|
|
32487
|
-
import
|
|
32488
|
-
import
|
|
32489
|
-
var hash2 = (text) =>
|
|
32490
|
-
var budgetDir = (store) =>
|
|
32491
|
-
var agentBase = (store, session, agentId) =>
|
|
32492
|
-
var spawnsFile = (store, session) =>
|
|
32762
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
32763
|
+
import fs22 from "node:fs";
|
|
32764
|
+
import path37 from "node:path";
|
|
32765
|
+
var hash2 = (text) => createHash14("sha256").update(text).digest("hex").slice(0, 32);
|
|
32766
|
+
var budgetDir = (store) => path37.join(store, "budget");
|
|
32767
|
+
var agentBase = (store, session, agentId) => path37.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
|
|
32768
|
+
var spawnsFile = (store, session) => path37.join(budgetDir(store), `spawns-${hash2(session)}.jsonl`);
|
|
32493
32769
|
var spawnBudget = (prompt) => {
|
|
32494
32770
|
const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
|
|
32495
32771
|
const n = found ? Number(found[1]) : NaN;
|
|
@@ -32500,14 +32776,14 @@ var noteSpawnBudget = (cwd, session, type, prompt) => {
|
|
|
32500
32776
|
const store = session ? gitStoreDir(cwd) : null;
|
|
32501
32777
|
if (!store)
|
|
32502
32778
|
return;
|
|
32503
|
-
|
|
32504
|
-
|
|
32779
|
+
fs22.mkdirSync(budgetDir(store), { recursive: true });
|
|
32780
|
+
fs22.appendFileSync(spawnsFile(store, session), `${JSON.stringify({ type: type ?? "", n: spawnBudget(prompt) })}
|
|
32505
32781
|
`);
|
|
32506
32782
|
} catch {}
|
|
32507
32783
|
};
|
|
32508
32784
|
var readBudget = (file) => {
|
|
32509
32785
|
try {
|
|
32510
|
-
const { limit, told } = JSON.parse(
|
|
32786
|
+
const { limit, told } = JSON.parse(fs22.readFileSync(file, "utf8"));
|
|
32511
32787
|
return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
|
|
32512
32788
|
} catch {
|
|
32513
32789
|
return null;
|
|
@@ -32519,13 +32795,13 @@ var claimSpawnBudget = (cwd, session, agentId, agentType) => {
|
|
|
32519
32795
|
if (!store)
|
|
32520
32796
|
return null;
|
|
32521
32797
|
const file = spawnsFile(store, session);
|
|
32522
|
-
const entries =
|
|
32798
|
+
const entries = fs22.readFileSync(file, "utf8").split(`
|
|
32523
32799
|
`).filter(Boolean).map((line) => JSON.parse(line));
|
|
32524
32800
|
const at = entries.findIndex((entry) => entry.type === (agentType ?? ""));
|
|
32525
32801
|
if (at < 0)
|
|
32526
32802
|
return null;
|
|
32527
32803
|
const [{ n }] = entries.splice(at, 1);
|
|
32528
|
-
|
|
32804
|
+
fs22.writeFileSync(file, entries.map((entry) => `${JSON.stringify(entry)}
|
|
32529
32805
|
`).join(""));
|
|
32530
32806
|
if (typeof n !== "number" || n <= 0)
|
|
32531
32807
|
return null;
|
|
@@ -32537,16 +32813,16 @@ var claimSpawnBudget = (cwd, session, agentId, agentType) => {
|
|
|
32537
32813
|
};
|
|
32538
32814
|
var startBudget = (store, session, agentId, n) => {
|
|
32539
32815
|
const dir = budgetDir(store);
|
|
32540
|
-
|
|
32816
|
+
fs22.mkdirSync(dir, { recursive: true });
|
|
32541
32817
|
const cutoff = Date.now() - 604800000;
|
|
32542
|
-
for (const name of
|
|
32818
|
+
for (const name of fs22.readdirSync(dir))
|
|
32543
32819
|
try {
|
|
32544
|
-
if (
|
|
32545
|
-
|
|
32820
|
+
if (fs22.statSync(path37.join(dir, name)).mtimeMs < cutoff)
|
|
32821
|
+
fs22.rmSync(path37.join(dir, name));
|
|
32546
32822
|
} catch {}
|
|
32547
32823
|
const base = agentBase(store, session, agentId);
|
|
32548
|
-
|
|
32549
|
-
|
|
32824
|
+
fs22.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
|
|
32825
|
+
fs22.rmSync(`${base}.calls`, { force: true });
|
|
32550
32826
|
};
|
|
32551
32827
|
var lineFor = (calls) => `Tool-call budget reached (${calls}): commit your work, write your report, stop.`;
|
|
32552
32828
|
var reachedOf = (cwd, session, agentId) => {
|
|
@@ -32555,20 +32831,20 @@ var reachedOf = (cwd, session, agentId) => {
|
|
|
32555
32831
|
const budget = base && readBudget(`${base}.json`);
|
|
32556
32832
|
if (!budget)
|
|
32557
32833
|
return null;
|
|
32558
|
-
return { base, budget, reached: Math.floor(
|
|
32834
|
+
return { base, budget, reached: Math.floor(fs22.statSync(`${base}.calls`).size / budget.limit) };
|
|
32559
32835
|
};
|
|
32560
32836
|
var dropBudget = (cwd, session, agentId) => {
|
|
32561
32837
|
const store = session ? gitStoreDir(cwd) : null;
|
|
32562
32838
|
if (store)
|
|
32563
32839
|
for (const ext of [".json", ".calls"])
|
|
32564
|
-
|
|
32840
|
+
fs22.rmSync(agentBase(store, session, agentId) + ext, { force: true });
|
|
32565
32841
|
};
|
|
32566
32842
|
var budgetLine = (cwd, session, agentId) => {
|
|
32567
32843
|
try {
|
|
32568
32844
|
const at = reachedOf(cwd, session, agentId);
|
|
32569
32845
|
if (!at || at.reached <= at.budget.told)
|
|
32570
32846
|
return null;
|
|
32571
|
-
|
|
32847
|
+
fs22.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
|
|
32572
32848
|
return lineFor(at.budget.limit * at.reached);
|
|
32573
32849
|
} catch {
|
|
32574
32850
|
return null;
|
|
@@ -32601,17 +32877,17 @@ if (false)
|
|
|
32601
32877
|
|
|
32602
32878
|
// packages/workit-codex/scripts/agents.ts
|
|
32603
32879
|
import {
|
|
32604
|
-
existsSync as
|
|
32605
|
-
lstatSync as
|
|
32606
|
-
mkdirSync as
|
|
32880
|
+
existsSync as existsSync18,
|
|
32881
|
+
lstatSync as lstatSync7,
|
|
32882
|
+
mkdirSync as mkdirSync6,
|
|
32607
32883
|
readdirSync as readdirSync5,
|
|
32608
32884
|
readFileSync as readFileSync13,
|
|
32609
|
-
renameSync as
|
|
32885
|
+
renameSync as renameSync5,
|
|
32610
32886
|
rmSync as rmSync3,
|
|
32611
|
-
writeFileSync as
|
|
32887
|
+
writeFileSync as writeFileSync6
|
|
32612
32888
|
} from "node:fs";
|
|
32613
|
-
import
|
|
32614
|
-
import
|
|
32889
|
+
import os7 from "node:os";
|
|
32890
|
+
import path38 from "node:path";
|
|
32615
32891
|
var CODEX_AGENT_ROLES = [
|
|
32616
32892
|
"verifier",
|
|
32617
32893
|
"reviewer",
|
|
@@ -32624,11 +32900,11 @@ var codexAgentName = (role) => `workit-${role}`;
|
|
|
32624
32900
|
var codexAgentFile = (role) => `${codexAgentName(role)}.toml`;
|
|
32625
32901
|
var tomlString = (value) => JSON.stringify(value);
|
|
32626
32902
|
var codexHomeOfInstall = (pluginRoot) => {
|
|
32627
|
-
const parts =
|
|
32903
|
+
const parts = path38.resolve(pluginRoot).split(path38.sep);
|
|
32628
32904
|
const cache = parts.length - 4;
|
|
32629
|
-
return cache >= 2 && parts[cache] === "cache" && parts[cache - 1] === "plugins" ? parts.slice(0, cache - 1).join(
|
|
32905
|
+
return cache >= 2 && parts[cache] === "cache" && parts[cache - 1] === "plugins" ? parts.slice(0, cache - 1).join(path38.sep) || path38.sep : null;
|
|
32630
32906
|
};
|
|
32631
|
-
var codexHomeFor = (pluginRoot, env) => codexHomeOfInstall(pluginRoot) ?? (env.CODEX_HOME ||
|
|
32907
|
+
var codexHomeFor = (pluginRoot, env) => codexHomeOfInstall(pluginRoot) ?? (env.CODEX_HOME || path38.join(env.HOME || os7.homedir(), ".codex"));
|
|
32632
32908
|
var withRoleModel = (content, file, models) => {
|
|
32633
32909
|
const role = CODEX_AGENT_ROLES.find((candidate) => codexAgentFile(candidate) === file);
|
|
32634
32910
|
const chosen = role ? models[role] : undefined;
|
|
@@ -32651,7 +32927,7 @@ var versionAtLeast = (version, min) => {
|
|
|
32651
32927
|
};
|
|
32652
32928
|
var pluginVersion = (pluginRoot) => {
|
|
32653
32929
|
try {
|
|
32654
|
-
const version = JSON.parse(readFileSync13(
|
|
32930
|
+
const version = JSON.parse(readFileSync13(path38.join(pluginRoot, "package.json"), "utf8")).version;
|
|
32655
32931
|
return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version) ? version.match(/^\d+\.\d+\.\d+/)[0] : null;
|
|
32656
32932
|
} catch {
|
|
32657
32933
|
return null;
|
|
@@ -32659,30 +32935,30 @@ var pluginVersion = (pluginRoot) => {
|
|
|
32659
32935
|
};
|
|
32660
32936
|
var lstatOrNull = (file) => {
|
|
32661
32937
|
try {
|
|
32662
|
-
return
|
|
32938
|
+
return lstatSync7(file);
|
|
32663
32939
|
} catch {
|
|
32664
32940
|
return null;
|
|
32665
32941
|
}
|
|
32666
32942
|
};
|
|
32667
32943
|
var installCodexAgents = (pluginRoot, codexHome, models = {}) => {
|
|
32668
|
-
const source =
|
|
32669
|
-
if (!
|
|
32944
|
+
const source = path38.join(pluginRoot, "agents");
|
|
32945
|
+
if (!existsSync18(source))
|
|
32670
32946
|
return [];
|
|
32671
32947
|
const version = pluginVersion(pluginRoot);
|
|
32672
|
-
const target =
|
|
32948
|
+
const target = path38.join(codexHome, "agents");
|
|
32673
32949
|
const results = [];
|
|
32674
32950
|
for (const file of readdirSync5(source).filter((name) => name.endsWith(".toml")).toSorted()) {
|
|
32675
|
-
const content = withRoleModel(stampCodexAgent(readFileSync13(
|
|
32676
|
-
const dest =
|
|
32951
|
+
const content = withRoleModel(stampCodexAgent(readFileSync13(path38.join(source, file), "utf8"), version), file, models);
|
|
32952
|
+
const dest = path38.join(target, file);
|
|
32677
32953
|
const stat = lstatOrNull(dest);
|
|
32678
32954
|
if (stat?.isSymbolicLink()) {
|
|
32679
32955
|
results.push({ file: dest, action: "skipped-symlink" });
|
|
32680
32956
|
continue;
|
|
32681
32957
|
}
|
|
32682
32958
|
if (!stat) {
|
|
32683
|
-
|
|
32959
|
+
mkdirSync6(target, { recursive: true });
|
|
32684
32960
|
try {
|
|
32685
|
-
|
|
32961
|
+
writeFileSync6(dest, content, { flag: "wx" });
|
|
32686
32962
|
results.push({ file: dest, action: "installed" });
|
|
32687
32963
|
} catch (error) {
|
|
32688
32964
|
if (error.code !== "EEXIST")
|
|
@@ -32709,10 +32985,10 @@ var installCodexAgents = (pluginRoot, codexHome, models = {}) => {
|
|
|
32709
32985
|
results.push({ file: dest, action: "kept-newer-version" });
|
|
32710
32986
|
continue;
|
|
32711
32987
|
}
|
|
32712
|
-
const temp =
|
|
32713
|
-
|
|
32988
|
+
const temp = path38.join(target, `.${file}.${process.pid}.${Date.now()}.tmp`);
|
|
32989
|
+
writeFileSync6(temp, content, { flag: "wx" });
|
|
32714
32990
|
try {
|
|
32715
|
-
|
|
32991
|
+
renameSync5(temp, dest);
|
|
32716
32992
|
} catch (error) {
|
|
32717
32993
|
rmSync3(temp, { force: true });
|
|
32718
32994
|
throw error;
|
|
@@ -32731,14 +33007,14 @@ var codexQualification = (host) => host === "codex_cli" ? { surface: host, cli:
|
|
|
32731
33007
|
var resolveCodexWorkspaceRoot = (pluginRoot, env) => {
|
|
32732
33008
|
const explicit = env.WORKIT_WORKSPACE_ROOT;
|
|
32733
33009
|
const inherited = env.PWD;
|
|
32734
|
-
const candidate = explicit ?? (inherited &&
|
|
32735
|
-
if (!candidate || !
|
|
33010
|
+
const candidate = explicit ?? (inherited && path39.resolve(inherited) !== path39.resolve(pluginRoot) ? inherited : undefined);
|
|
33011
|
+
if (!candidate || !path39.isAbsolute(candidate) || !existsSync19(candidate))
|
|
32736
33012
|
return null;
|
|
32737
33013
|
try {
|
|
32738
33014
|
if (!statSync6(candidate).isDirectory())
|
|
32739
33015
|
return null;
|
|
32740
|
-
const canonical =
|
|
32741
|
-
if (canonical ===
|
|
33016
|
+
const canonical = realpathSync13(candidate);
|
|
33017
|
+
if (canonical === realpathSync13(pluginRoot)) {
|
|
32742
33018
|
if (!explicit)
|
|
32743
33019
|
return null;
|
|
32744
33020
|
const workspace = new TaskStore(canonical).readWorkspace();
|
|
@@ -32771,7 +33047,7 @@ var codexContextProvider = (host = detectCodexSurface(process.env), root) => ({
|
|
|
32771
33047
|
};
|
|
32772
33048
|
}
|
|
32773
33049
|
});
|
|
32774
|
-
var pluginRoot = () =>
|
|
33050
|
+
var pluginRoot = () => path39.resolve(path39.dirname(fileURLToPath3(import.meta.url)), "..");
|
|
32775
33051
|
var codexRoleModels = (cwd) => {
|
|
32776
33052
|
const out = {};
|
|
32777
33053
|
for (const [file, role] of [
|