@workit-dev/mcp 2.22.1 → 2.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +858 -553
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6620,11 +6620,11 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
6620
6620
|
|
|
6621
6621
|
// packages/workit-mcp/src/index.ts
|
|
6622
6622
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
6623
|
-
import
|
|
6623
|
+
import path32 from "node:path";
|
|
6624
6624
|
|
|
6625
6625
|
// packages/workit-mcp/src/server.ts
|
|
6626
|
-
import { existsSync as
|
|
6627
|
-
import
|
|
6626
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11, realpathSync as realpathSync11 } from "node:fs";
|
|
6627
|
+
import path31 from "node:path";
|
|
6628
6628
|
|
|
6629
6629
|
// node_modules/zod/v4/core/util.js
|
|
6630
6630
|
function getEnumValues(entries) {
|
|
@@ -14973,8 +14973,8 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
14973
14973
|
|
|
14974
14974
|
// packages/workit-core/src/core.ts
|
|
14975
14975
|
import { spawnSync as spawnSync20 } from "node:child_process";
|
|
14976
|
-
import { existsSync as
|
|
14977
|
-
import
|
|
14976
|
+
import { existsSync as existsSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
14977
|
+
import path30 from "node:path";
|
|
14978
14978
|
|
|
14979
14979
|
// packages/workit-core/src/core/task-contract.ts
|
|
14980
14980
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -16409,23 +16409,25 @@ function explainInvalidOperation(family, request) {
|
|
|
16409
16409
|
return parsed.success ? null : invalidOperation(family, request, parsed.error);
|
|
16410
16410
|
}
|
|
16411
16411
|
// packages/workit-core/src/core/task-store.ts
|
|
16412
|
-
import { createHash as
|
|
16413
|
-
import * as
|
|
16414
|
-
import
|
|
16412
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
16413
|
+
import * as fs14 from "node:fs";
|
|
16414
|
+
import path17 from "node:path";
|
|
16415
16415
|
|
|
16416
16416
|
// packages/workit-core/src/host-session.ts
|
|
16417
|
-
import { createHash as
|
|
16418
|
-
import
|
|
16419
|
-
import
|
|
16417
|
+
import { createHash as createHash7, randomBytes, timingSafeEqual } from "node:crypto";
|
|
16418
|
+
import fs7 from "node:fs";
|
|
16419
|
+
import path11 from "node:path";
|
|
16420
16420
|
|
|
16421
16421
|
// packages/workit-core/src/core/branch-policy.ts
|
|
16422
16422
|
import { spawnSync } from "node:child_process";
|
|
16423
16423
|
|
|
16424
16424
|
// packages/workit-core/src/core/config.ts
|
|
16425
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16425
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
16426
16426
|
import path2 from "node:path";
|
|
16427
16427
|
|
|
16428
16428
|
// packages/workit-core/src/core/workit-paths.mjs
|
|
16429
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
16430
|
+
import { existsSync, lstatSync, mkdirSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
16429
16431
|
import os from "node:os";
|
|
16430
16432
|
import path from "node:path";
|
|
16431
16433
|
var WORKIT_DIR_OVERRIDES = {
|
|
@@ -16476,6 +16478,17 @@ var workitDir = (kind, env = process.env, platform = process.platform) => {
|
|
|
16476
16478
|
};
|
|
16477
16479
|
var configDir = (env, platform) => workitDir("config", env, platform);
|
|
16478
16480
|
var stateDir = (env, platform) => workitDir("state", env, platform);
|
|
16481
|
+
var folderSlug = (dir, platform = process.platform) => {
|
|
16482
|
+
let canonical = dir;
|
|
16483
|
+
try {
|
|
16484
|
+
canonical = realpathSync.native(dir);
|
|
16485
|
+
} catch {}
|
|
16486
|
+
if (platform === "win32")
|
|
16487
|
+
canonical = canonical.toLowerCase();
|
|
16488
|
+
const base = path.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
|
|
16489
|
+
return `${base}-${createHash2("sha256").update(canonical).digest("hex").slice(0, 12)}`;
|
|
16490
|
+
};
|
|
16491
|
+
var folderStoreDir = (dir, env, platform) => path.join(stateDir(env, platform), "folders", folderSlug(dir, platform));
|
|
16479
16492
|
|
|
16480
16493
|
// packages/workit-core/src/core/config.ts
|
|
16481
16494
|
var UPDATES_MODES = ["prompt", "auto", "off"];
|
|
@@ -16737,18 +16750,18 @@ var gitContext = (workspaceRoot, paths = []) => {
|
|
|
16737
16750
|
|
|
16738
16751
|
// packages/workit-core/src/core/workspaces.ts
|
|
16739
16752
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
16740
|
-
import { createHash as
|
|
16741
|
-
import { existsSync as
|
|
16753
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
16754
|
+
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
16742
16755
|
import path7 from "node:path";
|
|
16743
16756
|
|
|
16744
16757
|
// packages/workit-core/src/core/remotes.ts
|
|
16745
|
-
import { lstatSync, readFileSync as readFileSync3, realpathSync as
|
|
16758
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
|
|
16746
16759
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
16747
16760
|
import path6 from "node:path";
|
|
16748
16761
|
|
|
16749
16762
|
// packages/workit-core/src/git/rev.ts
|
|
16750
16763
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
16751
|
-
import { createHash as
|
|
16764
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
16752
16765
|
import fs3 from "node:fs";
|
|
16753
16766
|
import os2 from "node:os";
|
|
16754
16767
|
import path5 from "node:path";
|
|
@@ -17204,7 +17217,7 @@ function worktreeTree(cwd, options = {}) {
|
|
|
17204
17217
|
if (!tree)
|
|
17205
17218
|
return null;
|
|
17206
17219
|
const base = line(git(top, ["rev-parse", "--verify", "-q", "HEAD^{tree}"])) ?? emptyTree(top);
|
|
17207
|
-
const key = skipped.length ? `sha256:${
|
|
17220
|
+
const key = skipped.length ? `sha256:${createHash3("sha256").update(JSON.stringify({ tree, skipped })).digest("hex")}` : tree;
|
|
17208
17221
|
return { tree, key, dirty: tree !== base || skipped.length > 0, skipped };
|
|
17209
17222
|
} finally {
|
|
17210
17223
|
fs3.rmSync(scratch, { recursive: true, force: true });
|
|
@@ -17227,7 +17240,7 @@ function worktreeSignal(cwd, options = {}) {
|
|
|
17227
17240
|
});
|
|
17228
17241
|
if (!status.ok)
|
|
17229
17242
|
return null;
|
|
17230
|
-
const hash =
|
|
17243
|
+
const hash = createHash3("sha256");
|
|
17231
17244
|
hash.update(`${headSha(top) ?? "unborn"}\x00`);
|
|
17232
17245
|
for (const entry of status.stdout.split("\x00")) {
|
|
17233
17246
|
if (entry.length < 4)
|
|
@@ -17568,7 +17581,7 @@ function resolveSshHost(alias, sshConfig) {
|
|
|
17568
17581
|
|
|
17569
17582
|
// packages/workit-core/src/core/account-home.ts
|
|
17570
17583
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
17571
|
-
import { existsSync as
|
|
17584
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2 } from "node:fs";
|
|
17572
17585
|
import os3 from "node:os";
|
|
17573
17586
|
var WINDOWS = "C:\\Windows";
|
|
17574
17587
|
var SYSTEM32 = `${WINDOWS}\\System32\\`;
|
|
@@ -17660,7 +17673,7 @@ var canonical2 = (real) => {
|
|
|
17660
17673
|
};
|
|
17661
17674
|
var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
|
|
17662
17675
|
try {
|
|
17663
|
-
|
|
17676
|
+
lstatSync2(`${dir}/${name}`);
|
|
17664
17677
|
return true;
|
|
17665
17678
|
} catch {
|
|
17666
17679
|
return false;
|
|
@@ -17669,7 +17682,7 @@ var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
|
|
|
17669
17682
|
var gitDirAt = (at, depth = 0) => {
|
|
17670
17683
|
let real;
|
|
17671
17684
|
try {
|
|
17672
|
-
real =
|
|
17685
|
+
real = realpathSync3.native(at);
|
|
17673
17686
|
} catch {
|
|
17674
17687
|
return null;
|
|
17675
17688
|
}
|
|
@@ -17688,7 +17701,7 @@ var gitDirAt = (at, depth = 0) => {
|
|
|
17688
17701
|
common = readFileSync3(`${real}/commondir`, "utf8").trim();
|
|
17689
17702
|
} catch {}
|
|
17690
17703
|
if (common !== undefined) {
|
|
17691
|
-
|
|
17704
|
+
lstatSync2(`${real}/HEAD`);
|
|
17692
17705
|
return gitDirAt(path6.isAbsolute(common) ? common : `${real}/${common}`, depth + 1);
|
|
17693
17706
|
}
|
|
17694
17707
|
if (!isRepoDir(real))
|
|
@@ -17697,11 +17710,11 @@ var gitDirAt = (at, depth = 0) => {
|
|
|
17697
17710
|
for (const name of ["refs", "objects", "config", "packed-refs"]) {
|
|
17698
17711
|
const item = `${real}/${name}`;
|
|
17699
17712
|
try {
|
|
17700
|
-
|
|
17713
|
+
lstatSync2(item);
|
|
17701
17714
|
} catch {
|
|
17702
17715
|
continue;
|
|
17703
17716
|
}
|
|
17704
|
-
const resolved =
|
|
17717
|
+
const resolved = realpathSync3.native(item);
|
|
17705
17718
|
const rel = path6.relative(real, resolved);
|
|
17706
17719
|
if (rel && !rel.startsWith("..") && !path6.isAbsolute(rel))
|
|
17707
17720
|
continue;
|
|
@@ -17986,7 +17999,7 @@ var workspacesFileSchema = object({
|
|
|
17986
17999
|
names.add(workspace.name);
|
|
17987
18000
|
}
|
|
17988
18001
|
});
|
|
17989
|
-
var workspacesRevision = (contents) =>
|
|
18002
|
+
var workspacesRevision = (contents) => createHash4("sha256").update(contents ?? "<missing>").digest("hex");
|
|
17990
18003
|
var validateWorkspacesDocument = (parsed, file) => {
|
|
17991
18004
|
if (!isConfigObject(parsed)) {
|
|
17992
18005
|
return {
|
|
@@ -18137,8 +18150,8 @@ var probeCheckout = (cwd) => {
|
|
|
18137
18150
|
if (cached !== undefined)
|
|
18138
18151
|
return cached;
|
|
18139
18152
|
let dir = path7.resolve(cwd);
|
|
18140
|
-
while (!
|
|
18141
|
-
if (["HEAD", "objects", "refs"].every((name) =>
|
|
18153
|
+
while (!existsSync4(path7.join(dir, ".git"))) {
|
|
18154
|
+
if (["HEAD", "objects", "refs"].every((name) => existsSync4(path7.join(dir, name)))) {
|
|
18142
18155
|
const real = realpathOf(dir);
|
|
18143
18156
|
const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
|
|
18144
18157
|
if (owner === null)
|
|
@@ -18205,7 +18218,7 @@ var probeCheckout = (cwd) => {
|
|
|
18205
18218
|
};
|
|
18206
18219
|
var ownGitDir = (dotGit, real) => {
|
|
18207
18220
|
try {
|
|
18208
|
-
return
|
|
18221
|
+
return lstatSync3(dotGit).isDirectory() && realpathOf(dotGit) === real;
|
|
18209
18222
|
} catch {
|
|
18210
18223
|
return false;
|
|
18211
18224
|
}
|
|
@@ -18216,13 +18229,13 @@ var ownInternals = (real) => {
|
|
|
18216
18229
|
for (const name of INTERNALS) {
|
|
18217
18230
|
const at = path7.join(real, name);
|
|
18218
18231
|
try {
|
|
18219
|
-
|
|
18232
|
+
lstatSync3(at);
|
|
18220
18233
|
} catch {
|
|
18221
18234
|
continue;
|
|
18222
18235
|
}
|
|
18223
18236
|
let resolved;
|
|
18224
18237
|
try {
|
|
18225
|
-
resolved = (
|
|
18238
|
+
resolved = (realpathSync4.native ?? realpathSync4)(at);
|
|
18226
18239
|
} catch {
|
|
18227
18240
|
return false;
|
|
18228
18241
|
}
|
|
@@ -18280,7 +18293,7 @@ var matchingEntries = (cwd, entries) => {
|
|
|
18280
18293
|
return main ? match(main) : direct;
|
|
18281
18294
|
};
|
|
18282
18295
|
var realpathOf = (p) => {
|
|
18283
|
-
const real =
|
|
18296
|
+
const real = realpathSync4.native ?? realpathSync4;
|
|
18284
18297
|
try {
|
|
18285
18298
|
return real(p);
|
|
18286
18299
|
} catch {
|
|
@@ -18445,7 +18458,7 @@ import path8 from "node:path";
|
|
|
18445
18458
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
18446
18459
|
|
|
18447
18460
|
// packages/workit-core/src/core/release-tracks.ts
|
|
18448
|
-
import { createHash as
|
|
18461
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
18449
18462
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
18450
18463
|
var KNOWN_FIELDS = new Set([
|
|
18451
18464
|
"strategy",
|
|
@@ -18815,7 +18828,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
18815
18828
|
]) ?? "",
|
|
18816
18829
|
git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
|
|
18817
18830
|
] : [];
|
|
18818
|
-
key =
|
|
18831
|
+
key = createHash5("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
|
|
18819
18832
|
const hit = memo2.get(key);
|
|
18820
18833
|
if (hit)
|
|
18821
18834
|
return hit;
|
|
@@ -19209,9 +19222,318 @@ var redactSecrets = (value) => applyPatterns(value);
|
|
|
19209
19222
|
|
|
19210
19223
|
// packages/workit-core/src/store/paths.ts
|
|
19211
19224
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
19212
|
-
import { createHash as
|
|
19225
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
19226
|
+
import fs6 from "node:fs";
|
|
19227
|
+
import path10 from "node:path";
|
|
19228
|
+
|
|
19229
|
+
// packages/workit-core/src/store/folder-store.ts
|
|
19213
19230
|
import fs5 from "node:fs";
|
|
19231
|
+
import os5 from "node:os";
|
|
19214
19232
|
import path9 from "node:path";
|
|
19233
|
+
var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
|
|
19234
|
+
var MOVED_POINTER = "MOVED-TO-STATE.txt";
|
|
19235
|
+
var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
|
|
19236
|
+
var isV2TaskStub = (rel) => /^tasks[/\\][^/\\]+\.json$/u.test(rel);
|
|
19237
|
+
var MARKER = "workspace.json";
|
|
19238
|
+
var v2Workspace = (workit) => {
|
|
19239
|
+
let bytes;
|
|
19240
|
+
try {
|
|
19241
|
+
bytes = fs5.readFileSync(path9.join(workit, MARKER), "utf8");
|
|
19242
|
+
} catch {
|
|
19243
|
+
return null;
|
|
19244
|
+
}
|
|
19245
|
+
try {
|
|
19246
|
+
const value = JSON.parse(bytes);
|
|
19247
|
+
return value?.store?.format !== "workit-store";
|
|
19248
|
+
} catch {
|
|
19249
|
+
return true;
|
|
19250
|
+
}
|
|
19251
|
+
};
|
|
19252
|
+
var generatedIgnore = (file) => {
|
|
19253
|
+
try {
|
|
19254
|
+
return /^\*\n(!risk-paths\n)?$/u.test(fs5.readFileSync(file, "utf8"));
|
|
19255
|
+
} catch {
|
|
19256
|
+
return false;
|
|
19257
|
+
}
|
|
19258
|
+
};
|
|
19259
|
+
var exists = (file) => {
|
|
19260
|
+
try {
|
|
19261
|
+
fs5.lstatSync(file);
|
|
19262
|
+
return true;
|
|
19263
|
+
} catch {
|
|
19264
|
+
return false;
|
|
19265
|
+
}
|
|
19266
|
+
};
|
|
19267
|
+
var isDir = (file) => {
|
|
19268
|
+
try {
|
|
19269
|
+
return fs5.lstatSync(file).isDirectory();
|
|
19270
|
+
} catch {
|
|
19271
|
+
return false;
|
|
19272
|
+
}
|
|
19273
|
+
};
|
|
19274
|
+
var onlyStubs = (tasks) => {
|
|
19275
|
+
try {
|
|
19276
|
+
return fs5.readdirSync(tasks).every((entry) => isV2TaskStub(`tasks/${entry}`));
|
|
19277
|
+
} catch {
|
|
19278
|
+
return false;
|
|
19279
|
+
}
|
|
19280
|
+
};
|
|
19281
|
+
var strayEntries = (workit) => {
|
|
19282
|
+
if (!isDir(workit))
|
|
19283
|
+
return [];
|
|
19284
|
+
let names;
|
|
19285
|
+
try {
|
|
19286
|
+
names = fs5.readdirSync(workit);
|
|
19287
|
+
} catch {
|
|
19288
|
+
return [];
|
|
19289
|
+
}
|
|
19290
|
+
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))));
|
|
19291
|
+
};
|
|
19292
|
+
var folderStoreIo = {
|
|
19293
|
+
rename: (from, to) => fs5.renameSync(from, to),
|
|
19294
|
+
copyFile: (from, to) => fs5.copyFileSync(from, to, fs5.constants.COPYFILE_EXCL),
|
|
19295
|
+
judgedStale: () => {}
|
|
19296
|
+
};
|
|
19297
|
+
var tempSeq = 0;
|
|
19298
|
+
var tempBeside = (file) => path9.join(path9.dirname(file), `.${path9.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
|
|
19299
|
+
var copyInto = (from, to) => {
|
|
19300
|
+
const stat = fs5.lstatSync(from);
|
|
19301
|
+
if (stat.isDirectory()) {
|
|
19302
|
+
fs5.mkdirSync(to, { recursive: true });
|
|
19303
|
+
for (const name of fs5.readdirSync(from))
|
|
19304
|
+
copyInto(path9.join(from, name), path9.join(to, name));
|
|
19305
|
+
return;
|
|
19306
|
+
}
|
|
19307
|
+
if (exists(to))
|
|
19308
|
+
throw new Error(`${to} appeared during the move`);
|
|
19309
|
+
const temp = tempBeside(to);
|
|
19310
|
+
try {
|
|
19311
|
+
if (stat.isSymbolicLink())
|
|
19312
|
+
fs5.symlinkSync(fs5.readlinkSync(from), temp);
|
|
19313
|
+
else
|
|
19314
|
+
folderStoreIo.copyFile(from, temp);
|
|
19315
|
+
folderStoreIo.rename(temp, to);
|
|
19316
|
+
} catch (error) {
|
|
19317
|
+
fs5.rmSync(temp, { force: true });
|
|
19318
|
+
throw error;
|
|
19319
|
+
}
|
|
19320
|
+
};
|
|
19321
|
+
var sameFile = (left, right) => {
|
|
19322
|
+
try {
|
|
19323
|
+
const [a, b] = [fs5.lstatSync(left), fs5.lstatSync(right)];
|
|
19324
|
+
if (!a.isFile() || !b.isFile() || a.size !== b.size)
|
|
19325
|
+
return false;
|
|
19326
|
+
return fs5.readFileSync(left).equals(fs5.readFileSync(right));
|
|
19327
|
+
} catch {
|
|
19328
|
+
return false;
|
|
19329
|
+
}
|
|
19330
|
+
};
|
|
19331
|
+
var merge2 = (from, to, rel, moved) => {
|
|
19332
|
+
if (isV2TaskStub(rel))
|
|
19333
|
+
return [];
|
|
19334
|
+
if (!exists(to)) {
|
|
19335
|
+
try {
|
|
19336
|
+
folderStoreIo.rename(from, to);
|
|
19337
|
+
} catch {
|
|
19338
|
+
try {
|
|
19339
|
+
copyInto(from, to);
|
|
19340
|
+
fs5.rmSync(from, { recursive: true, force: true });
|
|
19341
|
+
} catch {
|
|
19342
|
+
return exists(from) ? [rel] : [];
|
|
19343
|
+
}
|
|
19344
|
+
}
|
|
19345
|
+
moved.push(rel);
|
|
19346
|
+
return [];
|
|
19347
|
+
}
|
|
19348
|
+
if (sameFile(from, to)) {
|
|
19349
|
+
fs5.rmSync(from, { force: true });
|
|
19350
|
+
moved.push(rel);
|
|
19351
|
+
return [];
|
|
19352
|
+
}
|
|
19353
|
+
if (!isDir(from) || !isDir(to))
|
|
19354
|
+
return [rel];
|
|
19355
|
+
const kept = fs5.readdirSync(from).flatMap((name) => merge2(path9.join(from, name), path9.join(to, name), `${rel}/${name}`, moved));
|
|
19356
|
+
try {
|
|
19357
|
+
if (fs5.readdirSync(from).length === 0)
|
|
19358
|
+
fs5.rmdirSync(from);
|
|
19359
|
+
} catch {}
|
|
19360
|
+
return kept;
|
|
19361
|
+
};
|
|
19362
|
+
var LOCK_STALE_MS = 1e4;
|
|
19363
|
+
var LOCK_WAIT_MS = 250;
|
|
19364
|
+
var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
19365
|
+
var readLock = (lock) => fs5.readFileSync(lock, "utf8");
|
|
19366
|
+
var staleLock = (lock) => {
|
|
19367
|
+
try {
|
|
19368
|
+
const { mtimeMs } = fs5.statSync(lock);
|
|
19369
|
+
const text = readLock(lock);
|
|
19370
|
+
if (Date.now() - mtimeMs > LOCK_STALE_MS)
|
|
19371
|
+
return { text, mtimeMs };
|
|
19372
|
+
const pid = Number(text.trim().split(/\s+/u)[0]);
|
|
19373
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
19374
|
+
return null;
|
|
19375
|
+
try {
|
|
19376
|
+
process.kill(pid, 0);
|
|
19377
|
+
return null;
|
|
19378
|
+
} catch (error) {
|
|
19379
|
+
return error.code === "ESRCH" ? { text, mtimeMs } : null;
|
|
19380
|
+
}
|
|
19381
|
+
} catch {
|
|
19382
|
+
return null;
|
|
19383
|
+
}
|
|
19384
|
+
};
|
|
19385
|
+
var removeStaleLock = (lock, judged) => {
|
|
19386
|
+
const aside = `${lock}.stale-${process.pid}-${crypto.randomUUID()}`;
|
|
19387
|
+
try {
|
|
19388
|
+
fs5.renameSync(lock, aside);
|
|
19389
|
+
} catch {
|
|
19390
|
+
return false;
|
|
19391
|
+
}
|
|
19392
|
+
let same = false;
|
|
19393
|
+
try {
|
|
19394
|
+
same = fs5.statSync(aside).mtimeMs === judged.mtimeMs && readLock(aside) === judged.text;
|
|
19395
|
+
} catch {}
|
|
19396
|
+
if (!same)
|
|
19397
|
+
try {
|
|
19398
|
+
fs5.linkSync(aside, lock);
|
|
19399
|
+
} catch {}
|
|
19400
|
+
fs5.rmSync(aside, { force: true });
|
|
19401
|
+
return same;
|
|
19402
|
+
};
|
|
19403
|
+
var takeMoveLock = (target) => {
|
|
19404
|
+
const lock = `${target}.lock`;
|
|
19405
|
+
const mine = `${process.pid} ${crypto.randomUUID()}
|
|
19406
|
+
`;
|
|
19407
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
19408
|
+
for (;; ) {
|
|
19409
|
+
try {
|
|
19410
|
+
const fd = fs5.openSync(lock, "wx", 384);
|
|
19411
|
+
fs5.writeSync(fd, mine);
|
|
19412
|
+
fs5.closeSync(fd);
|
|
19413
|
+
return () => {
|
|
19414
|
+
try {
|
|
19415
|
+
if (readLock(lock) === mine)
|
|
19416
|
+
fs5.rmSync(lock, { force: true });
|
|
19417
|
+
} catch {}
|
|
19418
|
+
};
|
|
19419
|
+
} catch (error) {
|
|
19420
|
+
if (error.code !== "EEXIST")
|
|
19421
|
+
return null;
|
|
19422
|
+
}
|
|
19423
|
+
const stale = staleLock(lock);
|
|
19424
|
+
if (stale) {
|
|
19425
|
+
folderStoreIo.judgedStale();
|
|
19426
|
+
if (removeStaleLock(lock, stale))
|
|
19427
|
+
continue;
|
|
19428
|
+
}
|
|
19429
|
+
if (Date.now() >= deadline)
|
|
19430
|
+
return null;
|
|
19431
|
+
pause(25);
|
|
19432
|
+
}
|
|
19433
|
+
};
|
|
19434
|
+
var canonical3 = (dir) => {
|
|
19435
|
+
try {
|
|
19436
|
+
return fs5.realpathSync.native(dir);
|
|
19437
|
+
} catch {
|
|
19438
|
+
return path9.resolve(dir);
|
|
19439
|
+
}
|
|
19440
|
+
};
|
|
19441
|
+
var below = (parent, child) => {
|
|
19442
|
+
const rel = path9.relative(parent, child);
|
|
19443
|
+
return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
|
|
19444
|
+
};
|
|
19445
|
+
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
19446
|
+
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
|
|
19447
|
+
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
19448
|
+
return null;
|
|
19449
|
+
const real = canonical3(folder);
|
|
19450
|
+
const tmp = canonical3(tempDir);
|
|
19451
|
+
if (below(tmp, real))
|
|
19452
|
+
return null;
|
|
19453
|
+
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)`;
|
|
19454
|
+
};
|
|
19455
|
+
function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
|
|
19456
|
+
`)) {
|
|
19457
|
+
const workit = path9.join(folder, ".workit");
|
|
19458
|
+
const names = strayEntries(workit);
|
|
19459
|
+
const refusal = testRunFolderRefusal(folder, names.length > 0);
|
|
19460
|
+
if (refusal) {
|
|
19461
|
+
const run = process.env.WORKIT_TEST_RUN ?? "";
|
|
19462
|
+
if (path9.isAbsolute(run))
|
|
19463
|
+
try {
|
|
19464
|
+
fs5.appendFileSync(path9.join(run, TEST_RUN_REFUSALS), `${refusal}
|
|
19465
|
+
`);
|
|
19466
|
+
} catch {}
|
|
19467
|
+
throw new Error(refusal);
|
|
19468
|
+
}
|
|
19469
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
19470
|
+
return null;
|
|
19471
|
+
try {
|
|
19472
|
+
fs5.mkdirSync(path9.dirname(target), { recursive: true });
|
|
19473
|
+
} catch {
|
|
19474
|
+
return null;
|
|
19475
|
+
}
|
|
19476
|
+
const release = takeMoveLock(target);
|
|
19477
|
+
if (!release)
|
|
19478
|
+
return null;
|
|
19479
|
+
try {
|
|
19480
|
+
return moveLocked(workit, target, note);
|
|
19481
|
+
} finally {
|
|
19482
|
+
release();
|
|
19483
|
+
}
|
|
19484
|
+
}
|
|
19485
|
+
function moveLocked(workit, target, note) {
|
|
19486
|
+
const names = strayEntries(workit);
|
|
19487
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
19488
|
+
return null;
|
|
19489
|
+
try {
|
|
19490
|
+
fs5.mkdirSync(target, { recursive: true });
|
|
19491
|
+
} catch {
|
|
19492
|
+
return null;
|
|
19493
|
+
}
|
|
19494
|
+
const result = { from: workit, to: target, moved: [], kept: [] };
|
|
19495
|
+
for (const name of names) {
|
|
19496
|
+
result.kept.push(...merge2(path9.join(workit, name), path9.join(target, name), name, result.moved));
|
|
19497
|
+
}
|
|
19498
|
+
const left = (() => {
|
|
19499
|
+
try {
|
|
19500
|
+
return fs5.readdirSync(workit);
|
|
19501
|
+
} catch {
|
|
19502
|
+
return [];
|
|
19503
|
+
}
|
|
19504
|
+
})();
|
|
19505
|
+
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path9.join(workit, name)));
|
|
19506
|
+
if (!v2Left && result.kept.length === 0) {
|
|
19507
|
+
fs5.rmSync(path9.join(workit, MARKER), { force: true });
|
|
19508
|
+
if (generatedIgnore(path9.join(workit, ".gitignore")))
|
|
19509
|
+
fs5.rmSync(path9.join(workit, ".gitignore"), { force: true });
|
|
19510
|
+
}
|
|
19511
|
+
const pointer = path9.join(workit, MOVED_POINTER);
|
|
19512
|
+
let wrote = false;
|
|
19513
|
+
if (result.kept.length > 0) {
|
|
19514
|
+
const text = `Workit keeps this folder's state in ${target}.
|
|
19515
|
+
Not moved, because the store there already has them or the move failed: ${result.kept.join(", ")}.
|
|
19516
|
+
Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
|
|
19517
|
+
`;
|
|
19518
|
+
try {
|
|
19519
|
+
if (!exists(pointer) || fs5.readFileSync(pointer, "utf8") !== text) {
|
|
19520
|
+
fs5.writeFileSync(pointer, text);
|
|
19521
|
+
wrote = true;
|
|
19522
|
+
}
|
|
19523
|
+
} catch {}
|
|
19524
|
+
} else {
|
|
19525
|
+
fs5.rmSync(pointer, { force: true });
|
|
19526
|
+
try {
|
|
19527
|
+
if (fs5.readdirSync(workit).length === 0)
|
|
19528
|
+
fs5.rmdirSync(workit);
|
|
19529
|
+
} catch {}
|
|
19530
|
+
}
|
|
19531
|
+
if (result.moved.length > 0 || wrote)
|
|
19532
|
+
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)`);
|
|
19533
|
+
return result;
|
|
19534
|
+
}
|
|
19535
|
+
|
|
19536
|
+
// packages/workit-core/src/store/paths.ts
|
|
19215
19537
|
var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
|
|
19216
19538
|
var gitRun = (cwd, args) => {
|
|
19217
19539
|
const run = spawnSync9("git", args, {
|
|
@@ -19236,10 +19558,10 @@ var gitRun = (cwd, args) => {
|
|
|
19236
19558
|
missing: error?.code === "ENOENT"
|
|
19237
19559
|
};
|
|
19238
19560
|
};
|
|
19239
|
-
var shortHash = (value) =>
|
|
19561
|
+
var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
|
|
19240
19562
|
var real = (file) => {
|
|
19241
19563
|
try {
|
|
19242
|
-
return
|
|
19564
|
+
return fs6.realpathSync.native(file);
|
|
19243
19565
|
} catch {
|
|
19244
19566
|
return file;
|
|
19245
19567
|
}
|
|
@@ -19253,14 +19575,14 @@ var DISCOVERY_ENV = [
|
|
|
19253
19575
|
];
|
|
19254
19576
|
var isGitDir = (dir) => {
|
|
19255
19577
|
try {
|
|
19256
|
-
return
|
|
19578
|
+
return fs6.statSync(path10.join(dir, "HEAD")).isFile() && fs6.statSync(path10.join(dir, "objects")).isDirectory() && fs6.statSync(path10.join(dir, "refs")).isDirectory();
|
|
19257
19579
|
} catch {
|
|
19258
19580
|
return false;
|
|
19259
19581
|
}
|
|
19260
19582
|
};
|
|
19261
19583
|
var reftableRefs = (common) => {
|
|
19262
19584
|
try {
|
|
19263
|
-
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(
|
|
19585
|
+
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path10.join(common, "config"), "utf8"));
|
|
19264
19586
|
} catch {
|
|
19265
19587
|
return false;
|
|
19266
19588
|
}
|
|
@@ -19273,17 +19595,17 @@ function fastGit(root) {
|
|
|
19273
19595
|
for (;; ) {
|
|
19274
19596
|
let stat;
|
|
19275
19597
|
try {
|
|
19276
|
-
stat =
|
|
19598
|
+
stat = fs6.statSync(dir);
|
|
19277
19599
|
} catch {
|
|
19278
19600
|
return null;
|
|
19279
19601
|
}
|
|
19280
19602
|
if (device !== null && stat.dev !== device)
|
|
19281
19603
|
return { kind: "none" };
|
|
19282
19604
|
device = stat.dev;
|
|
19283
|
-
const dotGit =
|
|
19605
|
+
const dotGit = path10.join(dir, ".git");
|
|
19284
19606
|
let entry = null;
|
|
19285
19607
|
try {
|
|
19286
|
-
entry =
|
|
19608
|
+
entry = fs6.statSync(dotGit);
|
|
19287
19609
|
} catch {}
|
|
19288
19610
|
let gitDir = null;
|
|
19289
19611
|
let top = null;
|
|
@@ -19294,26 +19616,26 @@ function fastGit(root) {
|
|
|
19294
19616
|
else if (entry.isFile()) {
|
|
19295
19617
|
let text = "";
|
|
19296
19618
|
try {
|
|
19297
|
-
text =
|
|
19619
|
+
text = fs6.readFileSync(dotGit, "utf8");
|
|
19298
19620
|
} catch {
|
|
19299
19621
|
return null;
|
|
19300
19622
|
}
|
|
19301
19623
|
const match = /^gitdir: (.+)$/mu.exec(text);
|
|
19302
19624
|
if (!match)
|
|
19303
19625
|
return null;
|
|
19304
|
-
gitDir =
|
|
19626
|
+
gitDir = path10.resolve(dir, match[1].trim());
|
|
19305
19627
|
} else
|
|
19306
19628
|
return null;
|
|
19307
|
-
if (!
|
|
19629
|
+
if (!fs6.existsSync(path10.join(gitDir, "HEAD")))
|
|
19308
19630
|
return null;
|
|
19309
19631
|
} else if (isGitDir(dir))
|
|
19310
19632
|
gitDir = dir;
|
|
19311
19633
|
if (gitDir) {
|
|
19312
19634
|
let common = gitDir;
|
|
19313
19635
|
try {
|
|
19314
|
-
common =
|
|
19636
|
+
common = path10.resolve(gitDir, fs6.readFileSync(path10.join(gitDir, "commondir"), "utf8").trim());
|
|
19315
19637
|
} catch {}
|
|
19316
|
-
if (!
|
|
19638
|
+
if (!fs6.existsSync(path10.join(common, "objects")))
|
|
19317
19639
|
return null;
|
|
19318
19640
|
return {
|
|
19319
19641
|
kind: "repo",
|
|
@@ -19323,28 +19645,33 @@ function fastGit(root) {
|
|
|
19323
19645
|
reftable: reftableRefs(common)
|
|
19324
19646
|
};
|
|
19325
19647
|
}
|
|
19326
|
-
const parent =
|
|
19648
|
+
const parent = path10.dirname(dir);
|
|
19327
19649
|
if (parent === dir)
|
|
19328
19650
|
return { kind: "none" };
|
|
19329
19651
|
dir = parent;
|
|
19330
19652
|
}
|
|
19331
19653
|
}
|
|
19654
|
+
var outsideGit = (root) => {
|
|
19655
|
+
const dir = folderStoreDir(root);
|
|
19656
|
+
migrateFolderStore(root, dir);
|
|
19657
|
+
return { dir, shared: false, top: null };
|
|
19658
|
+
};
|
|
19332
19659
|
function resolveStore(root) {
|
|
19333
|
-
root =
|
|
19660
|
+
root = path10.resolve(root);
|
|
19334
19661
|
let stat = null;
|
|
19335
19662
|
try {
|
|
19336
|
-
stat =
|
|
19663
|
+
stat = fs6.statSync(root);
|
|
19337
19664
|
} catch {}
|
|
19338
19665
|
if (!stat)
|
|
19339
19666
|
return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
|
|
19340
19667
|
if (!stat.isDirectory())
|
|
19341
|
-
return { dir:
|
|
19668
|
+
return { dir: path10.join(root, ".workit"), shared: false, top: null };
|
|
19342
19669
|
const fast = fastGit(root);
|
|
19343
19670
|
if (fast?.kind === "none")
|
|
19344
|
-
return
|
|
19671
|
+
return outsideGit(root);
|
|
19345
19672
|
if (fast?.kind === "repo")
|
|
19346
19673
|
return {
|
|
19347
|
-
dir:
|
|
19674
|
+
dir: path10.join(fast.common, "workit"),
|
|
19348
19675
|
shared: true,
|
|
19349
19676
|
top: fast.top,
|
|
19350
19677
|
git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
|
|
@@ -19354,20 +19681,20 @@ function resolveStore(root) {
|
|
|
19354
19681
|
if (run.ok && common) {
|
|
19355
19682
|
const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
|
|
19356
19683
|
return {
|
|
19357
|
-
dir:
|
|
19684
|
+
dir: path10.join(real(path10.resolve(root, common)), "workit"),
|
|
19358
19685
|
shared: true,
|
|
19359
19686
|
top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
|
|
19360
19687
|
};
|
|
19361
19688
|
}
|
|
19362
19689
|
if (run.missing || !run.ok && NOT_A_REPO.test(run.stderr))
|
|
19363
|
-
return
|
|
19690
|
+
return outsideGit(root);
|
|
19364
19691
|
return new Error(`cannot locate the workit store: git rev-parse failed (${run.stderr.trim().split(`
|
|
19365
19692
|
`)[0] || "no output"}); fix the repository (git status should work here)`);
|
|
19366
19693
|
}
|
|
19367
19694
|
var rebasingBranch = (gitDir) => {
|
|
19368
19695
|
for (const state of ["rebase-merge", "rebase-apply"]) {
|
|
19369
19696
|
try {
|
|
19370
|
-
const ref =
|
|
19697
|
+
const ref = fs6.readFileSync(path10.join(gitDir, state, "head-name"), "utf8").trim();
|
|
19371
19698
|
const match = /^refs\/heads\/(.+)$/u.exec(ref);
|
|
19372
19699
|
if (match)
|
|
19373
19700
|
return match[1];
|
|
@@ -19382,7 +19709,7 @@ function resolveTaskKey(root, location) {
|
|
|
19382
19709
|
if (location.git && !location.git.reftable) {
|
|
19383
19710
|
let head = "";
|
|
19384
19711
|
try {
|
|
19385
|
-
head =
|
|
19712
|
+
head = fs6.readFileSync(path10.join(location.git.gitDir, "HEAD"), "utf8").trim();
|
|
19386
19713
|
} catch {}
|
|
19387
19714
|
const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
|
|
19388
19715
|
if (ref && ref[1] !== ".invalid")
|
|
@@ -19413,10 +19740,10 @@ function resolveTaskKey(root, location) {
|
|
|
19413
19740
|
return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
|
|
19414
19741
|
}
|
|
19415
19742
|
function checkoutRootOf(root, location) {
|
|
19416
|
-
const resolved =
|
|
19743
|
+
const resolved = path10.resolve(root);
|
|
19417
19744
|
let canonical = resolved;
|
|
19418
19745
|
try {
|
|
19419
|
-
canonical =
|
|
19746
|
+
canonical = fs6.realpathSync(resolved);
|
|
19420
19747
|
} catch {
|
|
19421
19748
|
return resolved;
|
|
19422
19749
|
}
|
|
@@ -19426,7 +19753,7 @@ function checkoutRootOf(root, location) {
|
|
|
19426
19753
|
if (real(canonical) === found.top)
|
|
19427
19754
|
return canonical;
|
|
19428
19755
|
try {
|
|
19429
|
-
return
|
|
19756
|
+
return fs6.realpathSync(found.top);
|
|
19430
19757
|
} catch {
|
|
19431
19758
|
return canonical;
|
|
19432
19759
|
}
|
|
@@ -19438,25 +19765,25 @@ function branchRenames(location) {
|
|
|
19438
19765
|
const walk = (dir) => {
|
|
19439
19766
|
let entries;
|
|
19440
19767
|
try {
|
|
19441
|
-
entries =
|
|
19768
|
+
entries = fs6.readdirSync(dir, { withFileTypes: true });
|
|
19442
19769
|
} catch {
|
|
19443
19770
|
return;
|
|
19444
19771
|
}
|
|
19445
19772
|
for (const entry of entries)
|
|
19446
19773
|
if (entry.isDirectory())
|
|
19447
|
-
walk(
|
|
19774
|
+
walk(path10.join(dir, entry.name));
|
|
19448
19775
|
else
|
|
19449
|
-
files.push(
|
|
19776
|
+
files.push(path10.join(dir, entry.name));
|
|
19450
19777
|
};
|
|
19451
|
-
walk(
|
|
19778
|
+
walk(path10.join(path10.dirname(location.dir), "logs", "refs", "heads"));
|
|
19452
19779
|
if (location.git)
|
|
19453
|
-
files.push(
|
|
19780
|
+
files.push(path10.join(location.git.gitDir, "logs", "HEAD"));
|
|
19454
19781
|
const seen = new Set;
|
|
19455
19782
|
const renames = [];
|
|
19456
19783
|
for (const file of files) {
|
|
19457
19784
|
let text = "";
|
|
19458
19785
|
try {
|
|
19459
|
-
text =
|
|
19786
|
+
text = fs6.readFileSync(file, "utf8");
|
|
19460
19787
|
} catch {
|
|
19461
19788
|
continue;
|
|
19462
19789
|
}
|
|
@@ -19481,13 +19808,7 @@ function followRenames(key, boundAt, renames) {
|
|
|
19481
19808
|
}
|
|
19482
19809
|
return current;
|
|
19483
19810
|
}
|
|
19484
|
-
var checkoutSlug = (root) =>
|
|
19485
|
-
let canonical = real(root);
|
|
19486
|
-
if (process.platform === "win32")
|
|
19487
|
-
canonical = canonical.toLowerCase();
|
|
19488
|
-
const base = path9.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
|
|
19489
|
-
return `${base}-${shortHash(canonical)}`;
|
|
19490
|
-
};
|
|
19811
|
+
var checkoutSlug = (root) => folderSlug(root);
|
|
19491
19812
|
|
|
19492
19813
|
// packages/workit-core/src/host-session.ts
|
|
19493
19814
|
var HOST_SESSION_VARS = [
|
|
@@ -19517,9 +19838,9 @@ function hostSessionFromEnv(env) {
|
|
|
19517
19838
|
}
|
|
19518
19839
|
return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
|
|
19519
19840
|
}
|
|
19520
|
-
var hash = (value) =>
|
|
19521
|
-
var userIssuedRoot = () =>
|
|
19522
|
-
var userTokenRoot = () =>
|
|
19841
|
+
var hash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 32);
|
|
19842
|
+
var userIssuedRoot = () => path11.join(resolveStateDir(), "issued");
|
|
19843
|
+
var userTokenRoot = () => path11.join(resolveStateDir(), "issued-tokens");
|
|
19523
19844
|
function migrateRepoIssued(cwd) {
|
|
19524
19845
|
if (cwd === undefined)
|
|
19525
19846
|
return;
|
|
@@ -19528,27 +19849,27 @@ function migrateRepoIssued(cwd) {
|
|
|
19528
19849
|
const location = resolveStore(cwd);
|
|
19529
19850
|
if (location instanceof Error)
|
|
19530
19851
|
return;
|
|
19531
|
-
old =
|
|
19532
|
-
if (!
|
|
19852
|
+
old = path11.join(location.dir, "hooks", "issued");
|
|
19853
|
+
if (!fs7.existsSync(old))
|
|
19533
19854
|
return;
|
|
19534
19855
|
} catch {
|
|
19535
19856
|
return;
|
|
19536
19857
|
}
|
|
19537
19858
|
for (const lead of safeList(old)) {
|
|
19538
19859
|
try {
|
|
19539
|
-
const from =
|
|
19540
|
-
if (!
|
|
19860
|
+
const from = path11.join(old, lead);
|
|
19861
|
+
if (!fs7.statSync(from).isDirectory())
|
|
19541
19862
|
continue;
|
|
19542
|
-
const to =
|
|
19543
|
-
|
|
19544
|
-
for (const id of
|
|
19863
|
+
const to = path11.join(userIssuedRoot(), lead);
|
|
19864
|
+
fs7.mkdirSync(to, { recursive: true, mode: 448 });
|
|
19865
|
+
for (const id of fs7.readdirSync(from)) {
|
|
19545
19866
|
try {
|
|
19546
|
-
|
|
19867
|
+
fs7.copyFileSync(path11.join(from, id), path11.join(to, id), fs7.constants.COPYFILE_EXCL);
|
|
19547
19868
|
} catch (error) {
|
|
19548
19869
|
if (error.code !== "EEXIST")
|
|
19549
19870
|
throw error;
|
|
19550
19871
|
}
|
|
19551
|
-
|
|
19872
|
+
fs7.rmSync(path11.join(from, id), { force: true });
|
|
19552
19873
|
}
|
|
19553
19874
|
removeIfEmpty(from);
|
|
19554
19875
|
} catch {}
|
|
@@ -19557,14 +19878,14 @@ function migrateRepoIssued(cwd) {
|
|
|
19557
19878
|
}
|
|
19558
19879
|
var safeList = (dir) => {
|
|
19559
19880
|
try {
|
|
19560
|
-
return
|
|
19881
|
+
return fs7.readdirSync(dir);
|
|
19561
19882
|
} catch {
|
|
19562
19883
|
return [];
|
|
19563
19884
|
}
|
|
19564
19885
|
};
|
|
19565
19886
|
var removeIfEmpty = (dir) => {
|
|
19566
19887
|
try {
|
|
19567
|
-
|
|
19888
|
+
fs7.rmdirSync(dir);
|
|
19568
19889
|
} catch {}
|
|
19569
19890
|
};
|
|
19570
19891
|
var issuedRecord = (cwd, claimed) => {
|
|
@@ -19573,7 +19894,7 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
19573
19894
|
return null;
|
|
19574
19895
|
migrateRepoIssued(cwd);
|
|
19575
19896
|
try {
|
|
19576
|
-
return
|
|
19897
|
+
return fs7.readFileSync(path11.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
19577
19898
|
} catch {
|
|
19578
19899
|
return null;
|
|
19579
19900
|
}
|
|
@@ -19583,9 +19904,9 @@ var issuedToken = (claimed) => {
|
|
|
19583
19904
|
const cut = claimed.lastIndexOf(":");
|
|
19584
19905
|
if (cut <= 0)
|
|
19585
19906
|
return { stored: null, leadBound: false };
|
|
19586
|
-
const dir =
|
|
19907
|
+
const dir = path11.join(userTokenRoot(), hash(claimed.slice(0, cut)));
|
|
19587
19908
|
try {
|
|
19588
|
-
const text =
|
|
19909
|
+
const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
|
|
19589
19910
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
19590
19911
|
} catch {
|
|
19591
19912
|
return { stored: null, leadBound: safeList(dir).length > 0 };
|
|
@@ -19604,8 +19925,8 @@ var OWN_CHILD_SHELL = new Set(["opencode", "pi"]);
|
|
|
19604
19925
|
|
|
19605
19926
|
// packages/workit-core/src/store/event-log.ts
|
|
19606
19927
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
19607
|
-
import
|
|
19608
|
-
import
|
|
19928
|
+
import fs8 from "node:fs";
|
|
19929
|
+
import path12 from "node:path";
|
|
19609
19930
|
var EVENT_VERSION = 1;
|
|
19610
19931
|
|
|
19611
19932
|
class LogDamage extends Error {
|
|
@@ -19634,7 +19955,7 @@ var parseEvent = (line, file, offset) => {
|
|
|
19634
19955
|
function readLog(file, from = 0, expectSeq = null) {
|
|
19635
19956
|
let fd;
|
|
19636
19957
|
try {
|
|
19637
|
-
fd =
|
|
19958
|
+
fd = fs8.openSync(file, "r");
|
|
19638
19959
|
} catch (error) {
|
|
19639
19960
|
if (error.code === "ENOENT")
|
|
19640
19961
|
return null;
|
|
@@ -19643,13 +19964,13 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
19643
19964
|
let bytes;
|
|
19644
19965
|
let size;
|
|
19645
19966
|
try {
|
|
19646
|
-
size =
|
|
19967
|
+
size = fs8.fstatSync(fd).size;
|
|
19647
19968
|
if (from > size)
|
|
19648
19969
|
throw new LogDamage(`${file}: shorter than its snapshot`);
|
|
19649
19970
|
bytes = Buffer.alloc(size - from);
|
|
19650
19971
|
let read = 0;
|
|
19651
19972
|
while (read < bytes.length) {
|
|
19652
|
-
const got =
|
|
19973
|
+
const got = fs8.readSync(fd, bytes, read, bytes.length - read, from + read);
|
|
19653
19974
|
if (got === 0)
|
|
19654
19975
|
break;
|
|
19655
19976
|
read += got;
|
|
@@ -19657,7 +19978,7 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
19657
19978
|
bytes = bytes.subarray(0, read);
|
|
19658
19979
|
size = from + read;
|
|
19659
19980
|
} finally {
|
|
19660
|
-
|
|
19981
|
+
fs8.closeSync(fd);
|
|
19661
19982
|
}
|
|
19662
19983
|
const events = [];
|
|
19663
19984
|
let start = 0;
|
|
@@ -19682,11 +20003,11 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
19682
20003
|
}
|
|
19683
20004
|
var fsyncDirectory = (dir) => {
|
|
19684
20005
|
try {
|
|
19685
|
-
const fd =
|
|
20006
|
+
const fd = fs8.openSync(dir, "r");
|
|
19686
20007
|
try {
|
|
19687
|
-
|
|
20008
|
+
fs8.fsyncSync(fd);
|
|
19688
20009
|
} finally {
|
|
19689
|
-
|
|
20010
|
+
fs8.closeSync(fd);
|
|
19690
20011
|
}
|
|
19691
20012
|
} catch (error) {
|
|
19692
20013
|
if (process.platform !== "win32")
|
|
@@ -19696,46 +20017,46 @@ var fsyncDirectory = (dir) => {
|
|
|
19696
20017
|
function appendEvent(file, event, validEnd) {
|
|
19697
20018
|
const line = Buffer.from(`${JSON.stringify(event)}
|
|
19698
20019
|
`, "utf8");
|
|
19699
|
-
const created = !
|
|
19700
|
-
if (!created &&
|
|
19701
|
-
const cut =
|
|
20020
|
+
const created = !fs8.existsSync(file);
|
|
20021
|
+
if (!created && fs8.statSync(file).size !== validEnd) {
|
|
20022
|
+
const cut = fs8.openSync(file, "r+");
|
|
19702
20023
|
try {
|
|
19703
|
-
|
|
19704
|
-
|
|
20024
|
+
fs8.ftruncateSync(cut, validEnd);
|
|
20025
|
+
fs8.fsyncSync(cut);
|
|
19705
20026
|
} finally {
|
|
19706
|
-
|
|
20027
|
+
fs8.closeSync(cut);
|
|
19707
20028
|
}
|
|
19708
20029
|
}
|
|
19709
|
-
const fd =
|
|
20030
|
+
const fd = fs8.openSync(file, "a", 384);
|
|
19710
20031
|
try {
|
|
19711
20032
|
let written = 0;
|
|
19712
20033
|
while (written < line.length)
|
|
19713
|
-
written +=
|
|
19714
|
-
|
|
20034
|
+
written += fs8.writeSync(fd, line, written, line.length - written);
|
|
20035
|
+
fs8.fsyncSync(fd);
|
|
19715
20036
|
} finally {
|
|
19716
|
-
|
|
20037
|
+
fs8.closeSync(fd);
|
|
19717
20038
|
}
|
|
19718
20039
|
if (created)
|
|
19719
|
-
fsyncDirectory(
|
|
20040
|
+
fsyncDirectory(path12.dirname(file));
|
|
19720
20041
|
return validEnd;
|
|
19721
20042
|
}
|
|
19722
20043
|
function replaceFile(file, bytes, durable) {
|
|
19723
20044
|
const temporary = `${file}.${process.pid}.${randomUUID2()}.tmp`;
|
|
19724
20045
|
try {
|
|
19725
|
-
const fd =
|
|
20046
|
+
const fd = fs8.openSync(temporary, "wx", 384);
|
|
19726
20047
|
try {
|
|
19727
|
-
|
|
20048
|
+
fs8.writeSync(fd, bytes);
|
|
19728
20049
|
if (durable)
|
|
19729
|
-
|
|
20050
|
+
fs8.fsyncSync(fd);
|
|
19730
20051
|
} finally {
|
|
19731
|
-
|
|
20052
|
+
fs8.closeSync(fd);
|
|
19732
20053
|
}
|
|
19733
20054
|
renameWithRetry(temporary, file);
|
|
19734
20055
|
if (durable)
|
|
19735
|
-
fsyncDirectory(
|
|
20056
|
+
fsyncDirectory(path12.dirname(file));
|
|
19736
20057
|
} catch (error) {
|
|
19737
20058
|
try {
|
|
19738
|
-
|
|
20059
|
+
fs8.unlinkSync(temporary);
|
|
19739
20060
|
} catch {}
|
|
19740
20061
|
throw error;
|
|
19741
20062
|
}
|
|
@@ -19760,7 +20081,7 @@ var retryTransient = (run) => {
|
|
|
19760
20081
|
}
|
|
19761
20082
|
}
|
|
19762
20083
|
};
|
|
19763
|
-
var renameWithRetry = (from, to) => retryTransient(() =>
|
|
20084
|
+
var renameWithRetry = (from, to) => retryTransient(() => fs8.renameSync(from, to));
|
|
19764
20085
|
|
|
19765
20086
|
// packages/workit-core/src/core/checkout-leftovers.ts
|
|
19766
20087
|
var CHECKOUT_LEFTOVERS = [
|
|
@@ -19889,7 +20210,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
|
|
|
19889
20210
|
});
|
|
19890
20211
|
|
|
19891
20212
|
// packages/workit-core/src/store/reduce.ts
|
|
19892
|
-
import { createHash as
|
|
20213
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
19893
20214
|
var OPENING_TYPES = new Set([
|
|
19894
20215
|
"task.opened",
|
|
19895
20216
|
"task.imported",
|
|
@@ -19918,7 +20239,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
19918
20239
|
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");
|
|
19919
20240
|
var BLOB_REF = "$blob";
|
|
19920
20241
|
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;
|
|
19921
|
-
var blobDigest = (value) =>
|
|
20242
|
+
var blobDigest = (value) => createHash8("sha256").update(JSON.stringify(value)).digest("hex");
|
|
19922
20243
|
var toBlob = (value, blobs) => {
|
|
19923
20244
|
if (!isObject4(value))
|
|
19924
20245
|
return value;
|
|
@@ -20032,8 +20353,8 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
|
|
|
20032
20353
|
|
|
20033
20354
|
// packages/workit-core/src/core/task-read.ts
|
|
20034
20355
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
20035
|
-
import * as
|
|
20036
|
-
import
|
|
20356
|
+
import * as fs13 from "node:fs";
|
|
20357
|
+
import path16 from "node:path";
|
|
20037
20358
|
|
|
20038
20359
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
20039
20360
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -20084,10 +20405,10 @@ function sameFileIdentity(left, right, platform = process.platform) {
|
|
|
20084
20405
|
// node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
|
|
20085
20406
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
20086
20407
|
import fsSync from "node:fs";
|
|
20087
|
-
import
|
|
20408
|
+
import path13 from "node:path";
|
|
20088
20409
|
|
|
20089
20410
|
// node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
20090
|
-
import
|
|
20411
|
+
import fs9 from "node:fs";
|
|
20091
20412
|
|
|
20092
20413
|
// node_modules/@openclaw/fs-safe/dist/byte-budget.js
|
|
20093
20414
|
function normalizeMaxBytes(value, options = {}) {
|
|
@@ -20124,7 +20445,7 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
20124
20445
|
let total = 0;
|
|
20125
20446
|
while (true) {
|
|
20126
20447
|
const length = nextReadLength(total, maxBytes, scratch.length);
|
|
20127
|
-
const bytesRead =
|
|
20448
|
+
const bytesRead = fs9.readSync(fd, scratch, 0, length, null);
|
|
20128
20449
|
if (bytesRead === 0) {
|
|
20129
20450
|
return Buffer.concat(chunks, total);
|
|
20130
20451
|
}
|
|
@@ -20133,9 +20454,9 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
20133
20454
|
}
|
|
20134
20455
|
|
|
20135
20456
|
// node_modules/@openclaw/fs-safe/dist/read-open-flags.js
|
|
20136
|
-
import
|
|
20457
|
+
import fs10 from "node:fs";
|
|
20137
20458
|
function resolveReadOpenFlags(options) {
|
|
20138
|
-
const constants = options?.constants ??
|
|
20459
|
+
const constants = options?.constants ?? fs10.constants;
|
|
20139
20460
|
const noFollow = process.platform !== "win32" && options?.followSymlinks !== true && typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
20140
20461
|
const nonBlocking = process.platform !== "win32" && typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;
|
|
20141
20462
|
return constants.O_RDONLY | noFollow | nonBlocking;
|
|
@@ -20174,13 +20495,13 @@ ${ownershipToken}
|
|
|
20174
20495
|
return { raw, ownershipToken };
|
|
20175
20496
|
}
|
|
20176
20497
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
20177
|
-
const resolved =
|
|
20178
|
-
const lexicalRelative =
|
|
20179
|
-
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${
|
|
20180
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
20498
|
+
const resolved = path13.resolve(lockPath);
|
|
20499
|
+
const lexicalRelative = path13.relative(lockRoot.rootDir, resolved);
|
|
20500
|
+
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path13.sep}`) && !path13.isAbsolute(lexicalRelative) ? lexicalRelative : path13.relative(lockRoot.rootReal, resolved);
|
|
20501
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path13.sep}`) || path13.isAbsolute(relative)) {
|
|
20181
20502
|
throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
|
|
20182
20503
|
}
|
|
20183
|
-
return relative.split(
|
|
20504
|
+
return relative.split(path13.sep).join(path13.posix.sep);
|
|
20184
20505
|
}
|
|
20185
20506
|
function parseSidecarLockPayload(raw, parser) {
|
|
20186
20507
|
if (parser) {
|
|
@@ -20326,8 +20647,8 @@ function getFsSafeLockConfig() {
|
|
|
20326
20647
|
}
|
|
20327
20648
|
|
|
20328
20649
|
// node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
|
|
20329
|
-
import
|
|
20330
|
-
import
|
|
20650
|
+
import fs11 from "node:fs";
|
|
20651
|
+
import path14 from "node:path";
|
|
20331
20652
|
|
|
20332
20653
|
// node_modules/@openclaw/fs-safe/dist/timing.js
|
|
20333
20654
|
function sleepSync(ms) {
|
|
@@ -20357,7 +20678,7 @@ function releaseAllSyncHeldLocks() {
|
|
|
20357
20678
|
}
|
|
20358
20679
|
try {
|
|
20359
20680
|
if (held.fd !== undefined)
|
|
20360
|
-
|
|
20681
|
+
fs11.closeSync(held.fd);
|
|
20361
20682
|
} catch {}
|
|
20362
20683
|
try {
|
|
20363
20684
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
@@ -20392,7 +20713,7 @@ function releaseSyncHeldLock(held) {
|
|
|
20392
20713
|
if (held.fd !== undefined) {
|
|
20393
20714
|
const fd = held.fd;
|
|
20394
20715
|
held.fd = undefined;
|
|
20395
|
-
|
|
20716
|
+
fs11.closeSync(fd);
|
|
20396
20717
|
}
|
|
20397
20718
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
20398
20719
|
heldLocks.delete(held.normalizedTargetPath);
|
|
@@ -20415,29 +20736,29 @@ function createSyncHeldLockHandle(held) {
|
|
|
20415
20736
|
};
|
|
20416
20737
|
}
|
|
20417
20738
|
function canonicalLockParentSync(parent) {
|
|
20418
|
-
return process.platform === "win32" ?
|
|
20739
|
+
return process.platform === "win32" ? fs11.realpathSync.native(parent) : fs11.realpathSync(parent);
|
|
20419
20740
|
}
|
|
20420
20741
|
function normalizeTargetPath(targetPath) {
|
|
20421
|
-
const resolved =
|
|
20422
|
-
|
|
20742
|
+
const resolved = path14.resolve(targetPath);
|
|
20743
|
+
fs11.mkdirSync(path14.dirname(resolved), { recursive: true });
|
|
20423
20744
|
try {
|
|
20424
|
-
return
|
|
20745
|
+
return path14.join(canonicalLockParentSync(path14.dirname(resolved)), path14.basename(resolved));
|
|
20425
20746
|
} catch {
|
|
20426
20747
|
return resolved;
|
|
20427
20748
|
}
|
|
20428
20749
|
}
|
|
20429
20750
|
function boundedLockPath(lockPath, lockRoot) {
|
|
20430
|
-
const resolved =
|
|
20751
|
+
const resolved = path14.resolve(lockPath);
|
|
20431
20752
|
if (!lockRoot)
|
|
20432
20753
|
return resolved;
|
|
20433
20754
|
relativeSidecarLockPath(lockRoot, resolved);
|
|
20434
|
-
const parent =
|
|
20755
|
+
const parent = path14.dirname(resolved);
|
|
20435
20756
|
const parentReal = canonicalLockParentSync(parent);
|
|
20436
|
-
const parentRelative =
|
|
20437
|
-
if (parentRelative === ".." || parentRelative.startsWith(`..${
|
|
20757
|
+
const parentRelative = path14.relative(lockRoot.rootReal, parentReal);
|
|
20758
|
+
if (parentRelative === ".." || parentRelative.startsWith(`..${path14.sep}`) || path14.isAbsolute(parentRelative)) {
|
|
20438
20759
|
throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
|
|
20439
20760
|
}
|
|
20440
|
-
return
|
|
20761
|
+
return path14.join(parentReal, path14.basename(resolved));
|
|
20441
20762
|
}
|
|
20442
20763
|
function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
20443
20764
|
const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
|
|
@@ -20447,7 +20768,7 @@ function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
|
20447
20768
|
}
|
|
20448
20769
|
function reclaimGuardExists(reclaimGuardPath) {
|
|
20449
20770
|
try {
|
|
20450
|
-
|
|
20771
|
+
fs11.lstatSync(reclaimGuardPath);
|
|
20451
20772
|
return true;
|
|
20452
20773
|
} catch (error) {
|
|
20453
20774
|
if (error.code === "ENOENT")
|
|
@@ -20511,19 +20832,19 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
20511
20832
|
const { raw, ownershipToken } = serializeSidecarLockPayload(payload);
|
|
20512
20833
|
let lockFileCreateDenied = false;
|
|
20513
20834
|
try {
|
|
20514
|
-
const noFollow = process.platform !== "win32" && typeof
|
|
20835
|
+
const noFollow = process.platform !== "win32" && typeof fs11.constants.O_NOFOLLOW === "number" ? fs11.constants.O_NOFOLLOW : 0;
|
|
20515
20836
|
try {
|
|
20516
|
-
fd =
|
|
20837
|
+
fd = fs11.openSync(lockPath, fs11.constants.O_WRONLY | fs11.constants.O_CREAT | fs11.constants.O_EXCL | noFollow, 384);
|
|
20517
20838
|
} catch (error) {
|
|
20518
20839
|
lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
|
|
20519
20840
|
throw error;
|
|
20520
20841
|
}
|
|
20521
|
-
|
|
20522
|
-
|
|
20842
|
+
fs11.writeFileSync(fd, raw, "utf8");
|
|
20843
|
+
fs11.fsyncSync(fd);
|
|
20523
20844
|
const snapshot = {
|
|
20524
20845
|
raw,
|
|
20525
20846
|
payload,
|
|
20526
|
-
stat:
|
|
20847
|
+
stat: fs11.fstatSync(fd),
|
|
20527
20848
|
ownershipToken
|
|
20528
20849
|
};
|
|
20529
20850
|
const createdHeld = {
|
|
@@ -20558,8 +20879,8 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
20558
20879
|
return returnedHandle;
|
|
20559
20880
|
} catch (error) {
|
|
20560
20881
|
if (fd !== undefined) {
|
|
20561
|
-
const failed = { payload: null, stat:
|
|
20562
|
-
|
|
20882
|
+
const failed = { payload: null, stat: fs11.fstatSync(fd) };
|
|
20883
|
+
fs11.closeSync(fd);
|
|
20563
20884
|
fd = undefined;
|
|
20564
20885
|
removeSidecarLockIfUnchangedSync(lockPath, failed);
|
|
20565
20886
|
}
|
|
@@ -20608,7 +20929,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
20608
20929
|
})) {
|
|
20609
20930
|
let ownsReclaimGuard = false;
|
|
20610
20931
|
try {
|
|
20611
|
-
|
|
20932
|
+
fs11.mkdirSync(reclaimGuardPath);
|
|
20612
20933
|
ownsReclaimGuard = true;
|
|
20613
20934
|
if (removeSidecarLockIfUnchangedSync(lockPath, snapshot))
|
|
20614
20935
|
continue;
|
|
@@ -20621,7 +20942,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
20621
20942
|
} finally {
|
|
20622
20943
|
if (ownsReclaimGuard) {
|
|
20623
20944
|
try {
|
|
20624
|
-
|
|
20945
|
+
fs11.rmdirSync(reclaimGuardPath);
|
|
20625
20946
|
} catch {}
|
|
20626
20947
|
}
|
|
20627
20948
|
}
|
|
@@ -20637,27 +20958,27 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
20637
20958
|
}
|
|
20638
20959
|
}
|
|
20639
20960
|
// packages/workit-core/src/core/package-root.ts
|
|
20640
|
-
import { existsSync as
|
|
20641
|
-
import
|
|
20961
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
20962
|
+
import path15 from "node:path";
|
|
20642
20963
|
import { fileURLToPath } from "node:url";
|
|
20643
20964
|
var packageRoot = () => {
|
|
20644
|
-
let dir =
|
|
20965
|
+
let dir = path15.dirname(fileURLToPath(import.meta.url));
|
|
20645
20966
|
while (true) {
|
|
20646
|
-
const parent =
|
|
20647
|
-
if (
|
|
20967
|
+
const parent = path15.dirname(dir);
|
|
20968
|
+
if (existsSync5(path15.join(dir, "package.json")) || parent === dir)
|
|
20648
20969
|
return dir;
|
|
20649
20970
|
dir = parent;
|
|
20650
20971
|
}
|
|
20651
20972
|
};
|
|
20652
20973
|
var assetRoot = () => {
|
|
20653
20974
|
const root = packageRoot();
|
|
20654
|
-
const assets =
|
|
20655
|
-
return
|
|
20975
|
+
const assets = path15.join(root, "assets");
|
|
20976
|
+
return existsSync5(assets) ? assets : root;
|
|
20656
20977
|
};
|
|
20657
20978
|
|
|
20658
20979
|
// packages/workit-core/src/core/store-lock.ts
|
|
20659
20980
|
import { spawnSync as spawnSync10 } from "node:child_process";
|
|
20660
|
-
import
|
|
20981
|
+
import fs12 from "node:fs";
|
|
20661
20982
|
import { hostname } from "node:os";
|
|
20662
20983
|
var metadataLockSchema = object({
|
|
20663
20984
|
pid: number2().int().nonnegative().safe(),
|
|
@@ -20700,7 +21021,7 @@ var parseProcStatStart = (stat) => {
|
|
|
20700
21021
|
};
|
|
20701
21022
|
var readProcStat = (pid) => {
|
|
20702
21023
|
try {
|
|
20703
|
-
return
|
|
21024
|
+
return fs12.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
20704
21025
|
} catch {
|
|
20705
21026
|
return null;
|
|
20706
21027
|
}
|
|
@@ -20729,7 +21050,7 @@ var processStartOf = (pid, deps = {}) => {
|
|
|
20729
21050
|
};
|
|
20730
21051
|
var readTrimmed = (file) => {
|
|
20731
21052
|
try {
|
|
20732
|
-
return
|
|
21053
|
+
return fs12.readFileSync(file, "utf8").trim() || null;
|
|
20733
21054
|
} catch {
|
|
20734
21055
|
return null;
|
|
20735
21056
|
}
|
|
@@ -20740,7 +21061,7 @@ var localLockHost = () => {
|
|
|
20740
21061
|
return cachedLockHost;
|
|
20741
21062
|
let pidns = null;
|
|
20742
21063
|
try {
|
|
20743
|
-
pidns = /\[(\d+)\]/.exec(
|
|
21064
|
+
pidns = /\[(\d+)\]/.exec(fs12.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
|
|
20744
21065
|
} catch {}
|
|
20745
21066
|
const boot = readTrimmed("/proc/sys/kernel/random/boot_id");
|
|
20746
21067
|
cachedLockHost = pidns || boot ? `${hostname()}#${pidns ?? "?"}:${boot ?? "?"}` : hostname();
|
|
@@ -20786,7 +21107,7 @@ var classifyLockOwner = (payload, ageMs, localHost = localLockHost(), options =
|
|
|
20786
21107
|
};
|
|
20787
21108
|
var ageOf = (file, nowMs) => {
|
|
20788
21109
|
try {
|
|
20789
|
-
return nowMs -
|
|
21110
|
+
return nowMs - fs12.lstatSync(file).mtimeMs;
|
|
20790
21111
|
} catch {
|
|
20791
21112
|
return null;
|
|
20792
21113
|
}
|
|
@@ -20797,7 +21118,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
|
|
|
20797
21118
|
if (age === null || age <= RECLAIM_GUARD_TTL_MS)
|
|
20798
21119
|
return false;
|
|
20799
21120
|
try {
|
|
20800
|
-
|
|
21121
|
+
fs12.rmdirSync(guard);
|
|
20801
21122
|
return true;
|
|
20802
21123
|
} catch {
|
|
20803
21124
|
return false;
|
|
@@ -20842,7 +21163,7 @@ var indexEntry = (task, key, legacy, file) => {
|
|
|
20842
21163
|
};
|
|
20843
21164
|
var fileSignature = (file) => {
|
|
20844
21165
|
try {
|
|
20845
|
-
const stat =
|
|
21166
|
+
const stat = fs13.statSync(file, { bigint: true });
|
|
20846
21167
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
20847
21168
|
} catch {
|
|
20848
21169
|
return null;
|
|
@@ -20859,7 +21180,7 @@ var cachedRuntimeVersion = null;
|
|
|
20859
21180
|
var runtimeVersion = () => {
|
|
20860
21181
|
if (cachedRuntimeVersion === null) {
|
|
20861
21182
|
try {
|
|
20862
|
-
const pkg = JSON.parse(
|
|
21183
|
+
const pkg = JSON.parse(fs13.readFileSync(path16.join(packageRoot(), "package.json"), "utf8"));
|
|
20863
21184
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
20864
21185
|
} catch {
|
|
20865
21186
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -20881,14 +21202,14 @@ var isNewerVersion = (candidate, current) => {
|
|
|
20881
21202
|
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);
|
|
20882
21203
|
var readText2 = (file) => {
|
|
20883
21204
|
try {
|
|
20884
|
-
return
|
|
21205
|
+
return fs13.readFileSync(file, "utf8");
|
|
20885
21206
|
} catch {
|
|
20886
21207
|
return "";
|
|
20887
21208
|
}
|
|
20888
21209
|
};
|
|
20889
21210
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
20890
21211
|
var branchStart = (location, branch, aliases) => {
|
|
20891
|
-
const first = readText2(
|
|
21212
|
+
const first = readText2(path16.join(path16.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
20892
21213
|
`, 1)[0];
|
|
20893
21214
|
const created = REFLOG_LINE.exec(first);
|
|
20894
21215
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -20898,7 +21219,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
20898
21219
|
return start;
|
|
20899
21220
|
if (!location.git)
|
|
20900
21221
|
return null;
|
|
20901
|
-
for (const line of readText2(
|
|
21222
|
+
for (const line of readText2(path16.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
20902
21223
|
`)) {
|
|
20903
21224
|
const entry = REFLOG_LINE.exec(line);
|
|
20904
21225
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -20908,23 +21229,23 @@ var branchStart = (location, branch, aliases) => {
|
|
|
20908
21229
|
}
|
|
20909
21230
|
return null;
|
|
20910
21231
|
};
|
|
20911
|
-
var refExists2 = (common, ref) =>
|
|
21232
|
+
var refExists2 = (common, ref) => fs13.existsSync(path16.join(common, ref)) || readText2(path16.join(common, "packed-refs")).includes(` ${ref}
|
|
20912
21233
|
`);
|
|
20913
21234
|
var origins = new Map;
|
|
20914
21235
|
var sameDirectoryIdentity = (left, right) => {
|
|
20915
|
-
if (!
|
|
21236
|
+
if (!path16.isAbsolute(left) || !path16.isAbsolute(right))
|
|
20916
21237
|
return false;
|
|
20917
|
-
const normalizedLeft =
|
|
20918
|
-
const normalizedRight =
|
|
21238
|
+
const normalizedLeft = path16.resolve(left);
|
|
21239
|
+
const normalizedRight = path16.resolve(right);
|
|
20919
21240
|
try {
|
|
20920
|
-
const a =
|
|
20921
|
-
const b =
|
|
21241
|
+
const a = fs13.statSync(normalizedLeft, { bigint: true });
|
|
21242
|
+
const b = fs13.statSync(normalizedRight, { bigint: true });
|
|
20922
21243
|
if (!a.isDirectory() || !b.isDirectory())
|
|
20923
21244
|
return false;
|
|
20924
21245
|
if (process.platform === "win32" ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase() : normalizedLeft === normalizedRight)
|
|
20925
21246
|
return true;
|
|
20926
|
-
const canonicalLeft =
|
|
20927
|
-
const canonicalRight =
|
|
21247
|
+
const canonicalLeft = fs13.realpathSync(normalizedLeft);
|
|
21248
|
+
const canonicalRight = fs13.realpathSync(normalizedRight);
|
|
20928
21249
|
if (process.platform === "win32" ? canonicalLeft.toLowerCase() === canonicalRight.toLowerCase() : canonicalLeft === canonicalRight)
|
|
20929
21250
|
return true;
|
|
20930
21251
|
return a.dev === b.dev && a.ino !== 0n && a.ino === b.ino;
|
|
@@ -20949,14 +21270,14 @@ class TaskReader {
|
|
|
20949
21270
|
located;
|
|
20950
21271
|
migrationChecked = false;
|
|
20951
21272
|
constructor(root, options = {}) {
|
|
20952
|
-
const resolved =
|
|
20953
|
-
this.origin =
|
|
21273
|
+
const resolved = path16.resolve(root);
|
|
21274
|
+
this.origin = fs13.existsSync(resolved) ? fs13.realpathSync(resolved) : resolved;
|
|
20954
21275
|
this.located = resolveStore(this.origin);
|
|
20955
21276
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
20956
21277
|
this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
|
|
20957
21278
|
}
|
|
20958
21279
|
location() {
|
|
20959
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared &&
|
|
21280
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path16.join(this.root, ".git"))) {
|
|
20960
21281
|
this.located = undefined;
|
|
20961
21282
|
this.migrationChecked = false;
|
|
20962
21283
|
}
|
|
@@ -21020,7 +21341,7 @@ class TaskReader {
|
|
|
21020
21341
|
const tasksDir = this.paths().tasks;
|
|
21021
21342
|
let names;
|
|
21022
21343
|
try {
|
|
21023
|
-
names =
|
|
21344
|
+
names = fs13.existsSync(tasksDir) ? fs13.readdirSync(tasksDir).filter((name) => validId(name)) : [];
|
|
21024
21345
|
} catch (error) {
|
|
21025
21346
|
return failure2("storage_error", `unable to list tasks: ${String(error)}`, {
|
|
21026
21347
|
path: tasksDir
|
|
@@ -21061,7 +21382,7 @@ class TaskReader {
|
|
|
21061
21382
|
const file = this.paths().workspace;
|
|
21062
21383
|
let bytes;
|
|
21063
21384
|
try {
|
|
21064
|
-
bytes = retryTransient(() =>
|
|
21385
|
+
bytes = retryTransient(() => fs13.readFileSync(file, "utf8"));
|
|
21065
21386
|
} catch (error) {
|
|
21066
21387
|
if (error.code === "ENOENT")
|
|
21067
21388
|
return success(null, null, null);
|
|
@@ -21114,14 +21435,14 @@ class TaskReader {
|
|
|
21114
21435
|
const branch = key.ok ? key.data.branch : null;
|
|
21115
21436
|
if (!branch || !location.ok)
|
|
21116
21437
|
return success(null, null, null);
|
|
21117
|
-
const common =
|
|
21118
|
-
const heads =
|
|
21119
|
-
const headLog = location.data.git ?
|
|
21438
|
+
const common = path16.dirname(location.data.dir);
|
|
21439
|
+
const heads = path16.join(common, "logs", "refs", "heads");
|
|
21440
|
+
const headLog = location.data.git ? path16.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
21120
21441
|
const signatures = [
|
|
21121
|
-
|
|
21442
|
+
path16.join(heads, branch),
|
|
21122
21443
|
headLog,
|
|
21123
21444
|
heads,
|
|
21124
|
-
|
|
21445
|
+
path16.join(common, "packed-refs")
|
|
21125
21446
|
].map((file) => fileSignature(file) ?? "-");
|
|
21126
21447
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
21127
21448
|
let resolved = origins.get(slot);
|
|
@@ -21133,7 +21454,7 @@ class TaskReader {
|
|
|
21133
21454
|
aliases.push(rename.from);
|
|
21134
21455
|
const start = branchStart(location.data, branch, aliases);
|
|
21135
21456
|
const slash = start?.indexOf("/") ?? -1;
|
|
21136
|
-
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(
|
|
21457
|
+
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)}"]`));
|
|
21137
21458
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
21138
21459
|
resolved = {
|
|
21139
21460
|
signature: signatures.join("|"),
|
|
@@ -21153,27 +21474,27 @@ class TaskReader {
|
|
|
21153
21474
|
}
|
|
21154
21475
|
paths() {
|
|
21155
21476
|
const location = this.location();
|
|
21156
|
-
const dir = location.ok ? location.data.dir :
|
|
21157
|
-
const checkout =
|
|
21477
|
+
const dir = location.ok ? location.data.dir : path16.join(this.root, ".workit");
|
|
21478
|
+
const checkout = path16.join(dir, "checkouts", checkoutSlug(this.root));
|
|
21158
21479
|
return {
|
|
21159
21480
|
dir,
|
|
21160
21481
|
shared: location.ok ? location.data.shared : false,
|
|
21161
|
-
marker:
|
|
21482
|
+
marker: path16.join(dir, "store.json"),
|
|
21162
21483
|
checkout,
|
|
21163
|
-
workspace:
|
|
21164
|
-
checkoutLock:
|
|
21165
|
-
tasks:
|
|
21166
|
-
index:
|
|
21167
|
-
blobs:
|
|
21168
|
-
legacy:
|
|
21169
|
-
v2:
|
|
21484
|
+
workspace: path16.join(checkout, "workspace.json"),
|
|
21485
|
+
checkoutLock: path16.join(checkout, "metadata.lock"),
|
|
21486
|
+
tasks: path16.join(dir, "tasks"),
|
|
21487
|
+
index: path16.join(dir, "task-index.json"),
|
|
21488
|
+
blobs: path16.join(dir, "blobs", "candidates"),
|
|
21489
|
+
legacy: path16.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
21490
|
+
v2: path16.join(this.root, ".workit")
|
|
21170
21491
|
};
|
|
21171
21492
|
}
|
|
21172
21493
|
eventsPath(taskId) {
|
|
21173
|
-
return
|
|
21494
|
+
return path16.join(this.paths().tasks, taskId, "events.jsonl");
|
|
21174
21495
|
}
|
|
21175
21496
|
snapshotPath(taskId) {
|
|
21176
|
-
return
|
|
21497
|
+
return path16.join(this.paths().tasks, taskId, "snapshot.json");
|
|
21177
21498
|
}
|
|
21178
21499
|
ready(write = false) {
|
|
21179
21500
|
const location = this.location();
|
|
@@ -21183,7 +21504,7 @@ class TaskReader {
|
|
|
21183
21504
|
return success(null, null, null);
|
|
21184
21505
|
const dirs = this.paths();
|
|
21185
21506
|
try {
|
|
21186
|
-
const marker = JSON.parse(
|
|
21507
|
+
const marker = JSON.parse(fs13.readFileSync(dirs.marker, "utf8"));
|
|
21187
21508
|
if (typeof marker.version === "number" && marker.version > STORE_FORMAT)
|
|
21188
21509
|
return failure2("recovery_required", `the workit store at ${dirs.dir} has format ${marker.version}; upgrade Workit to use it`, { path: dirs.marker });
|
|
21189
21510
|
} catch {}
|
|
@@ -21208,7 +21529,7 @@ class TaskReader {
|
|
|
21208
21529
|
return {
|
|
21209
21530
|
read: (digest) => {
|
|
21210
21531
|
try {
|
|
21211
|
-
return JSON.parse(
|
|
21532
|
+
return JSON.parse(fs13.readFileSync(path16.join(dir, `${digest}.json`), "utf8"));
|
|
21212
21533
|
} catch (error) {
|
|
21213
21534
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
21214
21535
|
}
|
|
@@ -21295,7 +21616,7 @@ class TaskReader {
|
|
|
21295
21616
|
}
|
|
21296
21617
|
readSnapshot(taskId) {
|
|
21297
21618
|
try {
|
|
21298
|
-
const value = JSON.parse(
|
|
21619
|
+
const value = JSON.parse(fs13.readFileSync(this.snapshotPath(taskId), "utf8"));
|
|
21299
21620
|
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))
|
|
21300
21621
|
return null;
|
|
21301
21622
|
return value;
|
|
@@ -21322,7 +21643,7 @@ class TaskReader {
|
|
|
21322
21643
|
}
|
|
21323
21644
|
readIndex() {
|
|
21324
21645
|
try {
|
|
21325
|
-
const value = JSON.parse(
|
|
21646
|
+
const value = JSON.parse(fs13.readFileSync(this.paths().index, "utf8"));
|
|
21326
21647
|
if (!isObject5(value) || value.version !== INDEX_VERSION || !isObject5(value.tasks))
|
|
21327
21648
|
return {};
|
|
21328
21649
|
const tasks = {};
|
|
@@ -21336,7 +21657,7 @@ class TaskReader {
|
|
|
21336
21657
|
}
|
|
21337
21658
|
writeIndex(entries) {
|
|
21338
21659
|
try {
|
|
21339
|
-
|
|
21660
|
+
fs13.mkdirSync(this.paths().tasks, { recursive: true });
|
|
21340
21661
|
replaceFile(this.paths().index, JSON.stringify({
|
|
21341
21662
|
version: INDEX_VERSION,
|
|
21342
21663
|
tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
|
|
@@ -21374,64 +21695,74 @@ class TaskReader {
|
|
|
21374
21695
|
return failure2("recovery_required", `${label} record does not satisfy its schema`);
|
|
21375
21696
|
}
|
|
21376
21697
|
v2Dirs() {
|
|
21377
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
21698
|
+
return [...new Set([this.root, this.origin])].map((dir) => path16.join(dir, ".workit"));
|
|
21378
21699
|
}
|
|
21379
21700
|
pendingMigrations() {
|
|
21380
21701
|
return this.v2Dirs().filter((dir) => {
|
|
21381
|
-
const raw = this.readV2Workspace(
|
|
21702
|
+
const raw = this.readV2Workspace(path16.join(dir, "workspace.json"));
|
|
21382
21703
|
return raw !== null && raw !== TOMBSTONE;
|
|
21383
21704
|
});
|
|
21384
21705
|
}
|
|
21385
21706
|
adoptLocalStore() {
|
|
21707
|
+
if (!this.paths().shared)
|
|
21708
|
+
return success(null, null, null);
|
|
21709
|
+
for (const local of [this.paths().v2, folderStoreDir(this.root)]) {
|
|
21710
|
+
const adopted = this.adoptStoreFrom(local);
|
|
21711
|
+
if (!adopted.ok)
|
|
21712
|
+
return adopted;
|
|
21713
|
+
}
|
|
21714
|
+
return success(null, null, null);
|
|
21715
|
+
}
|
|
21716
|
+
adoptStoreFrom(local) {
|
|
21386
21717
|
const dirs = this.paths();
|
|
21387
|
-
const marker =
|
|
21388
|
-
if (!
|
|
21718
|
+
const marker = path16.join(local, "store.json");
|
|
21719
|
+
if (!fs13.existsSync(marker))
|
|
21389
21720
|
return success(null, null, null);
|
|
21390
21721
|
return this.withLock(dirs.checkoutLock, () => {
|
|
21391
|
-
if (!
|
|
21722
|
+
if (!fs13.existsSync(marker))
|
|
21392
21723
|
return success(null, null, null);
|
|
21393
21724
|
let tasks = 0;
|
|
21394
21725
|
try {
|
|
21395
21726
|
const merge = (from, to) => {
|
|
21396
|
-
if (!
|
|
21397
|
-
|
|
21727
|
+
if (!fs13.existsSync(to)) {
|
|
21728
|
+
fs13.mkdirSync(path16.dirname(to), { recursive: true });
|
|
21398
21729
|
try {
|
|
21399
|
-
|
|
21730
|
+
fs13.renameSync(from, to);
|
|
21400
21731
|
} catch {
|
|
21401
|
-
|
|
21402
|
-
|
|
21732
|
+
fs13.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
21733
|
+
fs13.rmSync(from, { recursive: true, force: true });
|
|
21403
21734
|
}
|
|
21404
21735
|
return;
|
|
21405
21736
|
}
|
|
21406
|
-
if (
|
|
21407
|
-
for (const name of
|
|
21408
|
-
merge(
|
|
21737
|
+
if (fs13.lstatSync(from).isDirectory() && fs13.lstatSync(to).isDirectory())
|
|
21738
|
+
for (const name of fs13.readdirSync(from))
|
|
21739
|
+
merge(path16.join(from, name), path16.join(to, name));
|
|
21409
21740
|
};
|
|
21410
21741
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
21411
|
-
const from =
|
|
21412
|
-
if (!
|
|
21742
|
+
const from = path16.join(local, sub);
|
|
21743
|
+
if (!fs13.existsSync(from))
|
|
21413
21744
|
continue;
|
|
21414
21745
|
if (sub === "tasks") {
|
|
21415
|
-
for (const name of
|
|
21416
|
-
if (validId(name) && !
|
|
21746
|
+
for (const name of fs13.readdirSync(from))
|
|
21747
|
+
if (validId(name) && !fs13.existsSync(path16.join(dirs.dir, sub, name)))
|
|
21417
21748
|
tasks += 1;
|
|
21418
21749
|
}
|
|
21419
|
-
merge(from,
|
|
21750
|
+
merge(from, path16.join(dirs.dir, sub));
|
|
21420
21751
|
}
|
|
21421
|
-
const ledger =
|
|
21422
|
-
if (
|
|
21423
|
-
merge(ledger,
|
|
21424
|
-
|
|
21425
|
-
|
|
21752
|
+
const ledger = path16.join(local, "ledger");
|
|
21753
|
+
if (fs13.existsSync(ledger) && !fs13.existsSync(path16.join(dirs.dir, "ledger")))
|
|
21754
|
+
merge(ledger, path16.join(dirs.dir, "ledger"));
|
|
21755
|
+
fs13.rmSync(path16.join(local, "task-index.json"), { force: true });
|
|
21756
|
+
fs13.renameSync(marker, path16.join(local, "store.moved.json"));
|
|
21426
21757
|
} catch (error) {
|
|
21427
|
-
return failure2("storage_error", `cannot move ${
|
|
21428
|
-
path:
|
|
21758
|
+
return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
|
|
21759
|
+
path: local
|
|
21429
21760
|
});
|
|
21430
21761
|
}
|
|
21431
21762
|
reportMigration({
|
|
21432
|
-
from:
|
|
21763
|
+
from: local,
|
|
21433
21764
|
to: dirs.dir,
|
|
21434
|
-
backup:
|
|
21765
|
+
backup: local,
|
|
21435
21766
|
tasks,
|
|
21436
21767
|
skipped: 0,
|
|
21437
21768
|
workspace: false
|
|
@@ -21442,7 +21773,7 @@ class TaskReader {
|
|
|
21442
21773
|
readV2Workspace(file) {
|
|
21443
21774
|
let bytes;
|
|
21444
21775
|
try {
|
|
21445
|
-
bytes =
|
|
21776
|
+
bytes = fs13.readFileSync(file, "utf8");
|
|
21446
21777
|
} catch {
|
|
21447
21778
|
return null;
|
|
21448
21779
|
}
|
|
@@ -21460,7 +21791,7 @@ class TaskReader {
|
|
|
21460
21791
|
schemaVersion: SCHEMA_VERSION,
|
|
21461
21792
|
id: workspaceId ?? newId(),
|
|
21462
21793
|
revision: newRevision(),
|
|
21463
|
-
root:
|
|
21794
|
+
root: path16.dirname(v2),
|
|
21464
21795
|
runtime: { createdWith: version, updatedWith: version },
|
|
21465
21796
|
writer: null,
|
|
21466
21797
|
store: {
|
|
@@ -21471,47 +21802,21 @@ class TaskReader {
|
|
|
21471
21802
|
},
|
|
21472
21803
|
critical: ["store"]
|
|
21473
21804
|
};
|
|
21474
|
-
|
|
21475
|
-
const ignore =
|
|
21476
|
-
if (!
|
|
21477
|
-
|
|
21805
|
+
fs13.mkdirSync(v2, { recursive: true });
|
|
21806
|
+
const ignore = path16.join(v2, ".gitignore");
|
|
21807
|
+
if (!fs13.existsSync(ignore))
|
|
21808
|
+
fs13.writeFileSync(ignore, `*
|
|
21478
21809
|
`);
|
|
21479
|
-
replaceFile(
|
|
21810
|
+
replaceFile(path16.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
21480
21811
|
`, true);
|
|
21481
21812
|
}
|
|
21482
|
-
writeTombstoneIfMissing() {
|
|
21483
|
-
try {
|
|
21484
|
-
if (this.paths().shared)
|
|
21485
|
-
return;
|
|
21486
|
-
const v2 = path15.join(this.root, ".workit");
|
|
21487
|
-
if (fs12.existsSync(path15.join(v2, "workspace.json")))
|
|
21488
|
-
return;
|
|
21489
|
-
let id = null;
|
|
21490
|
-
try {
|
|
21491
|
-
id = JSON.parse(fs12.readFileSync(this.paths().workspace, "utf8")).id ?? null;
|
|
21492
|
-
} catch {}
|
|
21493
|
-
this.writeTombstone(v2, id);
|
|
21494
|
-
} catch {}
|
|
21495
|
-
}
|
|
21496
21813
|
initializeStorage() {
|
|
21497
21814
|
const dirs = this.paths();
|
|
21498
|
-
retryTransient(() =>
|
|
21499
|
-
retryTransient(() =>
|
|
21500
|
-
if (!
|
|
21815
|
+
retryTransient(() => fs13.mkdirSync(dirs.checkout, { recursive: true }));
|
|
21816
|
+
retryTransient(() => fs13.mkdirSync(dirs.tasks, { recursive: true }));
|
|
21817
|
+
if (!fs13.existsSync(dirs.marker))
|
|
21501
21818
|
replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
|
|
21502
21819
|
`, false);
|
|
21503
|
-
if (!dirs.shared) {
|
|
21504
|
-
const ignore = path15.join(dirs.dir, ".gitignore");
|
|
21505
|
-
let current = null;
|
|
21506
|
-
try {
|
|
21507
|
-
current = fs12.readFileSync(ignore, "utf8");
|
|
21508
|
-
} catch {}
|
|
21509
|
-
if (current !== `*
|
|
21510
|
-
`)
|
|
21511
|
-
retryTransient(() => fs12.writeFileSync(ignore, `*
|
|
21512
|
-
`));
|
|
21513
|
-
}
|
|
21514
|
-
this.writeTombstoneIfMissing();
|
|
21515
21820
|
}
|
|
21516
21821
|
lockOptions(lockPath) {
|
|
21517
21822
|
const inProcess = heldInProcess.has(lockPath);
|
|
@@ -21524,7 +21829,7 @@ class TaskReader {
|
|
|
21524
21829
|
shouldReclaim: ({ payload, nowMs }) => {
|
|
21525
21830
|
let ageMs = null;
|
|
21526
21831
|
try {
|
|
21527
|
-
ageMs = nowMs -
|
|
21832
|
+
ageMs = nowMs - fs13.lstatSync(lockPath).mtimeMs;
|
|
21528
21833
|
} catch {}
|
|
21529
21834
|
return classifyLockOwner(payload, ageMs, localLockHost(), TASK_STORE_LOCK).state === "stale";
|
|
21530
21835
|
},
|
|
@@ -21561,7 +21866,7 @@ class TaskReader {
|
|
|
21561
21866
|
withLock(lockPath, operation) {
|
|
21562
21867
|
try {
|
|
21563
21868
|
this.initializeStorage();
|
|
21564
|
-
|
|
21869
|
+
fs13.mkdirSync(path16.dirname(lockPath), { recursive: true });
|
|
21565
21870
|
} catch (error) {
|
|
21566
21871
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
21567
21872
|
path: this.paths().dir
|
|
@@ -21601,18 +21906,18 @@ class TaskReader {
|
|
|
21601
21906
|
lockDirWritable(lockPath) {
|
|
21602
21907
|
const probe = `${lockPath}.${process.pid}.${randomUUID3()}.probe`;
|
|
21603
21908
|
try {
|
|
21604
|
-
|
|
21909
|
+
fs13.closeSync(fs13.openSync(probe, "wx", 384));
|
|
21605
21910
|
} catch {
|
|
21606
21911
|
return false;
|
|
21607
21912
|
}
|
|
21608
21913
|
try {
|
|
21609
|
-
|
|
21914
|
+
fs13.rmSync(probe, { force: true });
|
|
21610
21915
|
} catch {}
|
|
21611
21916
|
return true;
|
|
21612
21917
|
}
|
|
21613
21918
|
lockHolderPresent(lockPath) {
|
|
21614
21919
|
try {
|
|
21615
|
-
|
|
21920
|
+
fs13.lstatSync(lockPath);
|
|
21616
21921
|
return true;
|
|
21617
21922
|
} catch (error) {
|
|
21618
21923
|
return error?.code !== "ENOENT";
|
|
@@ -21624,12 +21929,12 @@ class TaskReader {
|
|
|
21624
21929
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
21625
21930
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
21626
21931
|
path: lockPath,
|
|
21627
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
21932
|
+
guidance: `Check permissions and the read-only attribute on ${path16.dirname(lockPath)}.`
|
|
21628
21933
|
});
|
|
21629
21934
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
21630
21935
|
let lock = null;
|
|
21631
21936
|
try {
|
|
21632
|
-
lock = parseMetadataLockOrNull(
|
|
21937
|
+
lock = parseMetadataLockOrNull(fs13.readFileSync(lockPath, "utf8"));
|
|
21633
21938
|
} catch {}
|
|
21634
21939
|
return failure2("busy", `workit lock is held by another Workit call${lock ? ` (pid ${lock.pid} on ${lock.host})` : ""}; retry shortly`, {
|
|
21635
21940
|
outcome: "not_started",
|
|
@@ -21659,7 +21964,7 @@ var MARKER_FIELDS = {
|
|
|
21659
21964
|
};
|
|
21660
21965
|
var isKnownMarker = (file, kind) => {
|
|
21661
21966
|
try {
|
|
21662
|
-
const value = JSON.parse(
|
|
21967
|
+
const value = JSON.parse(fs14.readFileSync(file, "utf8"));
|
|
21663
21968
|
if (!isObject5(value))
|
|
21664
21969
|
return false;
|
|
21665
21970
|
const fields = MARKER_FIELDS[kind];
|
|
@@ -21673,35 +21978,35 @@ var isKnownMarker = (file, kind) => {
|
|
|
21673
21978
|
}
|
|
21674
21979
|
};
|
|
21675
21980
|
var moveInto = (from, to) => {
|
|
21676
|
-
if (
|
|
21981
|
+
if (fs14.lstatSync(from).isDirectory()) {
|
|
21677
21982
|
let target = to;
|
|
21678
|
-
if (
|
|
21983
|
+
if (fs14.existsSync(target) && !fs14.lstatSync(target).isDirectory())
|
|
21679
21984
|
target = `${to}.dir`;
|
|
21680
|
-
|
|
21681
|
-
for (const name of
|
|
21682
|
-
moveInto(
|
|
21683
|
-
|
|
21985
|
+
fs14.mkdirSync(target, { recursive: true });
|
|
21986
|
+
for (const name of fs14.readdirSync(from))
|
|
21987
|
+
moveInto(path17.join(from, name), path17.join(target, name));
|
|
21988
|
+
fs14.rmdirSync(from);
|
|
21684
21989
|
return;
|
|
21685
21990
|
}
|
|
21686
21991
|
let target = to;
|
|
21687
|
-
if (
|
|
21688
|
-
const bytes =
|
|
21689
|
-
if (
|
|
21690
|
-
|
|
21992
|
+
if (fs14.existsSync(target)) {
|
|
21993
|
+
const bytes = fs14.readFileSync(from);
|
|
21994
|
+
if (fs14.lstatSync(target).isFile() && bytes.equals(fs14.readFileSync(target))) {
|
|
21995
|
+
fs14.rmSync(from);
|
|
21691
21996
|
return;
|
|
21692
21997
|
}
|
|
21693
|
-
target = `${to}.${
|
|
21694
|
-
if (
|
|
21695
|
-
|
|
21998
|
+
target = `${to}.${createHash9("sha256").update(bytes).digest("hex").slice(0, 12)}`;
|
|
21999
|
+
if (fs14.existsSync(target)) {
|
|
22000
|
+
fs14.rmSync(from);
|
|
21696
22001
|
return;
|
|
21697
22002
|
}
|
|
21698
22003
|
}
|
|
21699
|
-
|
|
22004
|
+
fs14.mkdirSync(path17.dirname(target), { recursive: true });
|
|
21700
22005
|
try {
|
|
21701
|
-
|
|
22006
|
+
fs14.renameSync(from, target);
|
|
21702
22007
|
} catch {
|
|
21703
|
-
|
|
21704
|
-
|
|
22008
|
+
fs14.copyFileSync(from, target);
|
|
22009
|
+
fs14.rmSync(from);
|
|
21705
22010
|
}
|
|
21706
22011
|
};
|
|
21707
22012
|
var now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
@@ -21764,7 +22069,7 @@ class TaskStore extends TaskReader {
|
|
|
21764
22069
|
const moved = this.bindLocked(again.data.id, key, input.now);
|
|
21765
22070
|
return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
|
|
21766
22071
|
}
|
|
21767
|
-
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" :
|
|
22072
|
+
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path17.basename(this.root) || this.root;
|
|
21768
22073
|
const intent = {
|
|
21769
22074
|
objective: input.objective?.trim() || `Work on ${label}`,
|
|
21770
22075
|
scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
|
|
@@ -22012,13 +22317,13 @@ class TaskStore extends TaskReader {
|
|
|
22012
22317
|
if (!ready.ok)
|
|
22013
22318
|
return ready;
|
|
22014
22319
|
const dirs = this.paths();
|
|
22015
|
-
const recovery = [
|
|
22320
|
+
const recovery = [path17.join(this.root, ".workit", "recovery"), path17.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
|
|
22016
22321
|
if (recovery) {
|
|
22017
22322
|
let files = 0;
|
|
22018
22323
|
let bytes = 0;
|
|
22019
22324
|
try {
|
|
22020
|
-
for (const name of
|
|
22021
|
-
const stat =
|
|
22325
|
+
for (const name of fs14.readdirSync(recovery)) {
|
|
22326
|
+
const stat = fs14.lstatSync(path17.join(recovery, name));
|
|
22022
22327
|
if (!stat.isFile())
|
|
22023
22328
|
continue;
|
|
22024
22329
|
files += 1;
|
|
@@ -22027,17 +22332,17 @@ class TaskStore extends TaskReader {
|
|
|
22027
22332
|
} catch {}
|
|
22028
22333
|
const remove = options.pruneRecovery === true && !dryRun;
|
|
22029
22334
|
if (remove)
|
|
22030
|
-
|
|
22335
|
+
fs14.rmSync(recovery, { recursive: true, force: true });
|
|
22031
22336
|
report.legacyRecovery = { path: recovery, files, bytes, removed: remove };
|
|
22032
22337
|
}
|
|
22033
|
-
if (!
|
|
22338
|
+
if (!fs14.existsSync(dirs.tasks))
|
|
22034
22339
|
return success(null, null, report);
|
|
22035
|
-
const names =
|
|
22340
|
+
const names = fs14.readdirSync(dirs.tasks).filter((name) => validId(name));
|
|
22036
22341
|
for (const name of names) {
|
|
22037
22342
|
const file = this.eventsPath(name);
|
|
22038
22343
|
let size = 0;
|
|
22039
22344
|
try {
|
|
22040
|
-
size =
|
|
22345
|
+
size = fs14.statSync(file).size;
|
|
22041
22346
|
} catch {
|
|
22042
22347
|
continue;
|
|
22043
22348
|
}
|
|
@@ -22065,16 +22370,16 @@ class TaskStore extends TaskReader {
|
|
|
22065
22370
|
const references = new Set;
|
|
22066
22371
|
for (const name of names)
|
|
22067
22372
|
try {
|
|
22068
|
-
for (const match of
|
|
22373
|
+
for (const match of fs14.readFileSync(this.eventsPath(name), "utf8").matchAll(/"\$blob":"([0-9a-f]{64})"/g))
|
|
22069
22374
|
references.add(match[1]);
|
|
22070
22375
|
} catch {}
|
|
22071
|
-
if (
|
|
22072
|
-
for (const name of
|
|
22376
|
+
if (fs14.existsSync(dirs.blobs))
|
|
22377
|
+
for (const name of fs14.readdirSync(dirs.blobs)) {
|
|
22073
22378
|
const digest = name.replace(/\.json$/, "");
|
|
22074
|
-
const file =
|
|
22379
|
+
const file = path17.join(dirs.blobs, name);
|
|
22075
22380
|
let stat;
|
|
22076
22381
|
try {
|
|
22077
|
-
stat =
|
|
22382
|
+
stat = fs14.lstatSync(file);
|
|
22078
22383
|
} catch {
|
|
22079
22384
|
continue;
|
|
22080
22385
|
}
|
|
@@ -22085,11 +22390,11 @@ class TaskStore extends TaskReader {
|
|
|
22085
22390
|
report.blobs.removed += 1;
|
|
22086
22391
|
report.blobs.removedBytes += stat.size;
|
|
22087
22392
|
if (!dryRun)
|
|
22088
|
-
|
|
22393
|
+
fs14.rmSync(file, { force: true });
|
|
22089
22394
|
}
|
|
22090
22395
|
return success(null, null, null);
|
|
22091
22396
|
};
|
|
22092
|
-
const swept = dryRun ? sweep() : this.withLock(
|
|
22397
|
+
const swept = dryRun ? sweep() : this.withLock(path17.join(dirs.dir, "gc.lock"), sweep);
|
|
22093
22398
|
if (!swept.ok)
|
|
22094
22399
|
return swept;
|
|
22095
22400
|
const temporaryDirs = [
|
|
@@ -22097,17 +22402,17 @@ class TaskStore extends TaskReader {
|
|
|
22097
22402
|
dirs.tasks,
|
|
22098
22403
|
dirs.blobs,
|
|
22099
22404
|
dirs.checkout,
|
|
22100
|
-
...names.map((name) =>
|
|
22405
|
+
...names.map((name) => path17.join(dirs.tasks, name))
|
|
22101
22406
|
];
|
|
22102
22407
|
for (const directory of temporaryDirs) {
|
|
22103
|
-
if (!
|
|
22408
|
+
if (!fs14.existsSync(directory))
|
|
22104
22409
|
continue;
|
|
22105
|
-
for (const name of
|
|
22410
|
+
for (const name of fs14.readdirSync(directory)) {
|
|
22106
22411
|
if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
|
|
22107
22412
|
continue;
|
|
22108
|
-
const file =
|
|
22413
|
+
const file = path17.join(directory, name);
|
|
22109
22414
|
try {
|
|
22110
|
-
const stat =
|
|
22415
|
+
const stat = fs14.lstatSync(file);
|
|
22111
22416
|
if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
|
|
22112
22417
|
continue;
|
|
22113
22418
|
} catch {
|
|
@@ -22115,13 +22420,13 @@ class TaskStore extends TaskReader {
|
|
|
22115
22420
|
}
|
|
22116
22421
|
report.temporary.removed += 1;
|
|
22117
22422
|
if (!dryRun)
|
|
22118
|
-
|
|
22423
|
+
fs14.rmSync(file, { force: true });
|
|
22119
22424
|
}
|
|
22120
22425
|
}
|
|
22121
22426
|
return success(null, null, report);
|
|
22122
22427
|
}
|
|
22123
22428
|
taskLockPath(taskId) {
|
|
22124
|
-
return
|
|
22429
|
+
return path17.join(this.paths().tasks, taskId, "lock");
|
|
22125
22430
|
}
|
|
22126
22431
|
settleMigrations(write) {
|
|
22127
22432
|
const moved = this.adoptLocalStore();
|
|
@@ -22150,15 +22455,15 @@ class TaskStore extends TaskReader {
|
|
|
22150
22455
|
return {
|
|
22151
22456
|
read: (digest) => reader.read(digest),
|
|
22152
22457
|
write: (digest, value) => {
|
|
22153
|
-
const file =
|
|
22154
|
-
if (
|
|
22458
|
+
const file = path17.join(dir, `${digest}.json`);
|
|
22459
|
+
if (fs14.existsSync(file)) {
|
|
22155
22460
|
const stamp = new Date;
|
|
22156
22461
|
try {
|
|
22157
|
-
|
|
22462
|
+
fs14.utimesSync(file, stamp, stamp);
|
|
22158
22463
|
return;
|
|
22159
22464
|
} catch {}
|
|
22160
22465
|
}
|
|
22161
|
-
|
|
22466
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
22162
22467
|
replaceFile(file, JSON.stringify(value), true);
|
|
22163
22468
|
}
|
|
22164
22469
|
};
|
|
@@ -22252,8 +22557,8 @@ class TaskStore extends TaskReader {
|
|
|
22252
22557
|
}
|
|
22253
22558
|
}
|
|
22254
22559
|
openTask(record, type, key, legacy = null) {
|
|
22255
|
-
const dir =
|
|
22256
|
-
|
|
22560
|
+
const dir = path17.join(this.paths().tasks, record.id);
|
|
22561
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
22257
22562
|
const blobs = this.blobStore();
|
|
22258
22563
|
const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
|
|
22259
22564
|
const event = this.event(record.id, 1, type, {
|
|
@@ -22305,11 +22610,11 @@ class TaskStore extends TaskReader {
|
|
|
22305
22610
|
} catch {}
|
|
22306
22611
|
if (!latest || latest.events[0]?.id !== last.id)
|
|
22307
22612
|
return failure2("busy", "the task log changed during compaction; retry", { taskId });
|
|
22308
|
-
const appended =
|
|
22613
|
+
const appended = fs14.readFileSync(file).subarray(log.end, latest.end);
|
|
22309
22614
|
const bytes = Buffer.concat([Buffer.from(prefix, "utf8"), appended]);
|
|
22310
22615
|
replaceFile(file, bytes.toString("utf8"), true);
|
|
22311
22616
|
try {
|
|
22312
|
-
|
|
22617
|
+
fs14.rmSync(this.snapshotPath(taskId), { force: true });
|
|
22313
22618
|
} catch {}
|
|
22314
22619
|
const reloaded = this.load(taskId);
|
|
22315
22620
|
if (reloaded.ok && reloaded.data)
|
|
@@ -22322,7 +22627,7 @@ class TaskStore extends TaskReader {
|
|
|
22322
22627
|
}
|
|
22323
22628
|
countEvents(file) {
|
|
22324
22629
|
try {
|
|
22325
|
-
const bytes =
|
|
22630
|
+
const bytes = fs14.readFileSync(file);
|
|
22326
22631
|
let count = 0;
|
|
22327
22632
|
for (let index = bytes.indexOf(10);index >= 0; index = bytes.indexOf(10, index + 1))
|
|
22328
22633
|
count += 1;
|
|
@@ -22332,8 +22637,8 @@ class TaskStore extends TaskReader {
|
|
|
22332
22637
|
}
|
|
22333
22638
|
}
|
|
22334
22639
|
withKeyLock(key, operation) {
|
|
22335
|
-
const digest =
|
|
22336
|
-
return this.withLock(
|
|
22640
|
+
const digest = createHash9("sha256").update(key).digest("hex").slice(0, 32);
|
|
22641
|
+
return this.withLock(path17.join(this.paths().dir, "keys", `${digest}.lock`), operation);
|
|
22337
22642
|
}
|
|
22338
22643
|
bindLocked(taskId, key, timestamp) {
|
|
22339
22644
|
const current = this.readWorkspace();
|
|
@@ -22474,7 +22779,7 @@ class TaskStore extends TaskReader {
|
|
|
22474
22779
|
writeWorkspace(record) {
|
|
22475
22780
|
const file = this.paths().workspace;
|
|
22476
22781
|
try {
|
|
22477
|
-
|
|
22782
|
+
fs14.mkdirSync(path17.dirname(file), { recursive: true });
|
|
22478
22783
|
replaceFile(file, `${canonicalJson(record)}
|
|
22479
22784
|
`, true);
|
|
22480
22785
|
return success(null, null, null);
|
|
@@ -22500,13 +22805,13 @@ class TaskStore extends TaskReader {
|
|
|
22500
22805
|
}
|
|
22501
22806
|
migrateV2(v2) {
|
|
22502
22807
|
const dirs = this.paths();
|
|
22503
|
-
const v2Workspace =
|
|
22504
|
-
const v2Tasks =
|
|
22505
|
-
const legacy =
|
|
22808
|
+
const v2Workspace = path17.join(v2, "workspace.json");
|
|
22809
|
+
const v2Tasks = path17.join(v2, "tasks");
|
|
22810
|
+
const legacy = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
|
|
22506
22811
|
const raw = this.readV2Workspace(v2Workspace);
|
|
22507
22812
|
if (raw === null || raw === TOMBSTONE)
|
|
22508
22813
|
return success(null, null, null);
|
|
22509
|
-
return this.withLock(dirs.checkoutLock, () => this.withLock(
|
|
22814
|
+
return this.withLock(dirs.checkoutLock, () => this.withLock(path17.join(v2, "metadata.lock"), () => {
|
|
22510
22815
|
const workspace = this.readV2Workspace(v2Workspace);
|
|
22511
22816
|
if (workspace === null || workspace === TOMBSTONE)
|
|
22512
22817
|
return success(null, null, null);
|
|
@@ -22515,7 +22820,7 @@ class TaskStore extends TaskReader {
|
|
|
22515
22820
|
return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
|
|
22516
22821
|
let files = [];
|
|
22517
22822
|
try {
|
|
22518
|
-
files =
|
|
22823
|
+
files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path17.join(v2Tasks, name)));
|
|
22519
22824
|
} catch {}
|
|
22520
22825
|
const current = this.readWorkspace();
|
|
22521
22826
|
if (!current.ok)
|
|
@@ -22533,22 +22838,22 @@ class TaskStore extends TaskReader {
|
|
|
22533
22838
|
let skipped = 0;
|
|
22534
22839
|
const done = new Map;
|
|
22535
22840
|
try {
|
|
22536
|
-
|
|
22841
|
+
fs14.mkdirSync(path17.join(legacy, "tasks"), { recursive: true });
|
|
22537
22842
|
for (const name of ["workspace.json", "index.json"])
|
|
22538
|
-
if (
|
|
22539
|
-
|
|
22843
|
+
if (fs14.existsSync(path17.join(v2, name)))
|
|
22844
|
+
fs14.copyFileSync(path17.join(v2, name), path17.join(legacy, name));
|
|
22540
22845
|
for (const name of files) {
|
|
22541
22846
|
const id = name.slice(0, -5);
|
|
22542
|
-
const file =
|
|
22543
|
-
const bytes =
|
|
22847
|
+
const file = path17.join(v2Tasks, name);
|
|
22848
|
+
const bytes = fs14.readFileSync(file, "utf8");
|
|
22544
22849
|
const digest = sha256(bytes);
|
|
22545
|
-
|
|
22850
|
+
fs14.writeFileSync(path17.join(legacy, "tasks", name), bytes);
|
|
22546
22851
|
const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
|
|
22547
22852
|
if (!parsed.ok || parsed.data.id !== id)
|
|
22548
22853
|
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 });
|
|
22549
22854
|
const record = { ...parsed.data, workspaceId: target.id };
|
|
22550
|
-
const origin = { path:
|
|
22551
|
-
if (!
|
|
22855
|
+
const origin = { path: path17.join(legacy, "tasks", name), digest };
|
|
22856
|
+
if (!fs14.existsSync(this.eventsPath(id))) {
|
|
22552
22857
|
this.openTask(record, "migrated.from_v2", null, origin);
|
|
22553
22858
|
migrated += 1;
|
|
22554
22859
|
} else {
|
|
@@ -22583,13 +22888,13 @@ class TaskStore extends TaskReader {
|
|
|
22583
22888
|
try {
|
|
22584
22889
|
let complete = true;
|
|
22585
22890
|
for (const [name, digest] of done) {
|
|
22586
|
-
const file =
|
|
22587
|
-
if (sha256(
|
|
22891
|
+
const file = path17.join(v2Tasks, name);
|
|
22892
|
+
if (sha256(fs14.readFileSync(file, "utf8")) !== digest) {
|
|
22588
22893
|
complete = false;
|
|
22589
22894
|
continue;
|
|
22590
22895
|
}
|
|
22591
22896
|
if (dirs.shared)
|
|
22592
|
-
|
|
22897
|
+
fs14.rmSync(file);
|
|
22593
22898
|
else
|
|
22594
22899
|
replaceFile(file, this.stubFor(name.slice(0, -5)), false);
|
|
22595
22900
|
}
|
|
@@ -22597,9 +22902,9 @@ class TaskStore extends TaskReader {
|
|
|
22597
22902
|
return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
|
|
22598
22903
|
path: v2
|
|
22599
22904
|
});
|
|
22600
|
-
|
|
22905
|
+
fs14.rmSync(path17.join(v2, "index.json"), { force: true });
|
|
22601
22906
|
if (dirs.shared)
|
|
22602
|
-
|
|
22907
|
+
fs14.rmSync(v2Workspace, { force: true });
|
|
22603
22908
|
else
|
|
22604
22909
|
this.writeTombstone(v2, target.id);
|
|
22605
22910
|
} catch (error) {
|
|
@@ -22622,49 +22927,49 @@ class TaskStore extends TaskReader {
|
|
|
22622
22927
|
const dirs = this.paths();
|
|
22623
22928
|
if (!dirs.shared)
|
|
22624
22929
|
return success(null, null, null);
|
|
22625
|
-
const present = () => CHECKOUT_LEFTOVERS.filter((name) =>
|
|
22626
|
-
const ignore =
|
|
22930
|
+
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path17.join(v2, name)));
|
|
22931
|
+
const ignore = path17.join(v2, ".gitignore");
|
|
22627
22932
|
const onlyGeneratedIgnore = () => {
|
|
22628
22933
|
try {
|
|
22629
|
-
return
|
|
22934
|
+
return fs14.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs14.readFileSync(ignore, "utf8"));
|
|
22630
22935
|
} catch {
|
|
22631
22936
|
return false;
|
|
22632
22937
|
}
|
|
22633
22938
|
};
|
|
22634
22939
|
if (present().length === 0 && !onlyGeneratedIgnore())
|
|
22635
22940
|
return success(null, null, null);
|
|
22636
|
-
const backup =
|
|
22941
|
+
const backup = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
|
|
22637
22942
|
return this.withLock(dirs.checkoutLock, () => {
|
|
22638
22943
|
let moved = 0;
|
|
22639
22944
|
try {
|
|
22640
22945
|
for (const name of present()) {
|
|
22641
|
-
const entry =
|
|
22946
|
+
const entry = path17.join(v2, name);
|
|
22642
22947
|
const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
|
|
22643
|
-
const empty =
|
|
22948
|
+
const empty = fs14.lstatSync(entry).isDirectory() && fs14.readdirSync(entry).length === 0;
|
|
22644
22949
|
if (marker || empty) {
|
|
22645
|
-
|
|
22950
|
+
fs14.rmSync(entry, { recursive: true });
|
|
22646
22951
|
continue;
|
|
22647
22952
|
}
|
|
22648
|
-
if (name === "tasks" &&
|
|
22649
|
-
for (const task of
|
|
22650
|
-
const file =
|
|
22651
|
-
if (
|
|
22652
|
-
|
|
22953
|
+
if (name === "tasks" && fs14.lstatSync(entry).isDirectory()) {
|
|
22954
|
+
for (const task of fs14.readdirSync(entry)) {
|
|
22955
|
+
const file = path17.join(entry, task);
|
|
22956
|
+
if (fs14.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
|
|
22957
|
+
fs14.rmSync(file);
|
|
22653
22958
|
else {
|
|
22654
|
-
moveInto(file,
|
|
22959
|
+
moveInto(file, path17.join(backup, "tasks", task));
|
|
22655
22960
|
moved += 1;
|
|
22656
22961
|
}
|
|
22657
22962
|
}
|
|
22658
|
-
|
|
22963
|
+
fs14.rmdirSync(entry);
|
|
22659
22964
|
continue;
|
|
22660
22965
|
}
|
|
22661
|
-
moveInto(entry,
|
|
22966
|
+
moveInto(entry, path17.join(backup, name));
|
|
22662
22967
|
moved += 1;
|
|
22663
22968
|
}
|
|
22664
22969
|
if (onlyGeneratedIgnore())
|
|
22665
|
-
|
|
22666
|
-
if (
|
|
22667
|
-
|
|
22970
|
+
fs14.rmSync(ignore);
|
|
22971
|
+
if (fs14.readdirSync(v2).length === 0)
|
|
22972
|
+
fs14.rmdirSync(v2);
|
|
22668
22973
|
} catch (error) {
|
|
22669
22974
|
return failure2("storage_error", `cannot clear ${v2}: ${String(error)}`, { path: v2 });
|
|
22670
22975
|
}
|
|
@@ -22686,7 +22991,7 @@ class TaskStore extends TaskReader {
|
|
|
22686
22991
|
}
|
|
22687
22992
|
isStub(file) {
|
|
22688
22993
|
try {
|
|
22689
|
-
const value = JSON.parse(
|
|
22994
|
+
const value = JSON.parse(fs14.readFileSync(file, "utf8"));
|
|
22690
22995
|
return isObject5(value) && isObject5(value.store) && value.store.format === "workit-store";
|
|
22691
22996
|
} catch {
|
|
22692
22997
|
return false;
|
|
@@ -22699,23 +23004,23 @@ var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
|
|
|
22699
23004
|
var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
|
|
22700
23005
|
|
|
22701
23006
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
22702
|
-
import { createHash as
|
|
22703
|
-
import * as
|
|
23007
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
23008
|
+
import * as fs17 from "node:fs";
|
|
22704
23009
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
22705
|
-
import
|
|
23010
|
+
import path22 from "node:path";
|
|
22706
23011
|
|
|
22707
23012
|
// packages/workit-core/src/check-config.ts
|
|
22708
23013
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
22709
|
-
import
|
|
22710
|
-
import
|
|
23014
|
+
import fs15 from "node:fs";
|
|
23015
|
+
import path18 from "node:path";
|
|
22711
23016
|
var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
|
|
22712
23017
|
var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
|
|
22713
23018
|
var CHECKS_FILE = ".workit/checks.json";
|
|
22714
23019
|
var LEGACY_CHECKS_FILE = "workit.checks.json";
|
|
22715
23020
|
function checksConfigFile(root) {
|
|
22716
|
-
const current =
|
|
22717
|
-
const legacy =
|
|
22718
|
-
return !
|
|
23021
|
+
const current = path18.join(root, CHECKS_FILE);
|
|
23022
|
+
const legacy = path18.join(root, LEGACY_CHECKS_FILE);
|
|
23023
|
+
return !fs15.existsSync(current) && fs15.existsSync(legacy) ? legacy : current;
|
|
22719
23024
|
}
|
|
22720
23025
|
var GENERATED_GITIGNORES2 = new Set([`*
|
|
22721
23026
|
`, `*
|
|
@@ -22773,10 +23078,10 @@ var git3 = (cwd, args) => {
|
|
|
22773
23078
|
return value || null;
|
|
22774
23079
|
};
|
|
22775
23080
|
function checkRoot(cwd) {
|
|
22776
|
-
return
|
|
23081
|
+
return path18.resolve(gitDirs(cwd)?.top ?? cwd);
|
|
22777
23082
|
}
|
|
22778
23083
|
var packageManager = (root) => {
|
|
22779
|
-
const has = (file) =>
|
|
23084
|
+
const has = (file) => fs15.existsSync(path18.join(root, file));
|
|
22780
23085
|
if (has("bun.lock") || has("bun.lockb"))
|
|
22781
23086
|
return "bun";
|
|
22782
23087
|
if (has("pnpm-lock.yaml"))
|
|
@@ -22796,7 +23101,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
|
|
|
22796
23101
|
function detectedChecks(root) {
|
|
22797
23102
|
const read = (file) => {
|
|
22798
23103
|
try {
|
|
22799
|
-
return
|
|
23104
|
+
return fs15.readFileSync(path18.join(root, file), "utf8");
|
|
22800
23105
|
} catch {
|
|
22801
23106
|
return null;
|
|
22802
23107
|
}
|
|
@@ -22868,21 +23173,21 @@ function cleanupGlobs(value) {
|
|
|
22868
23173
|
}
|
|
22869
23174
|
function configFileFor(root) {
|
|
22870
23175
|
const own = checksConfigFile(root);
|
|
22871
|
-
if (
|
|
23176
|
+
if (fs15.existsSync(own))
|
|
22872
23177
|
return own;
|
|
22873
23178
|
const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
22874
|
-
if (!common ||
|
|
23179
|
+
if (!common || path18.basename(common) !== ".git")
|
|
22875
23180
|
return own;
|
|
22876
|
-
const main =
|
|
22877
|
-
if (
|
|
23181
|
+
const main = path18.dirname(common);
|
|
23182
|
+
if (path18.resolve(main) === path18.resolve(root))
|
|
22878
23183
|
return own;
|
|
22879
23184
|
const shared = checksConfigFile(main);
|
|
22880
|
-
return
|
|
23185
|
+
return fs15.existsSync(shared) ? shared : own;
|
|
22881
23186
|
}
|
|
22882
23187
|
function loadCheckConfig(cwd) {
|
|
22883
23188
|
const root = checkRoot(cwd);
|
|
22884
23189
|
const file = configFileFor(root);
|
|
22885
|
-
const legacy =
|
|
23190
|
+
const legacy = path18.basename(file) === LEGACY_CHECKS_FILE;
|
|
22886
23191
|
const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
|
|
22887
23192
|
const note = legacy ? {
|
|
22888
23193
|
note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
|
|
@@ -22898,7 +23203,7 @@ function loadCheckConfig(cwd) {
|
|
|
22898
23203
|
});
|
|
22899
23204
|
let text = null;
|
|
22900
23205
|
try {
|
|
22901
|
-
text =
|
|
23206
|
+
text = fs15.readFileSync(file, "utf8");
|
|
22902
23207
|
} catch (error) {
|
|
22903
23208
|
if (error.code !== "ENOENT")
|
|
22904
23209
|
return none(`cannot read ${label}: ${error.message}`);
|
|
@@ -23013,10 +23318,10 @@ function workitAvailable(env = process.env) {
|
|
|
23013
23318
|
return workitOnPath;
|
|
23014
23319
|
const windows = process.platform === "win32";
|
|
23015
23320
|
const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
23016
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
23321
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path18.delimiter).filter(Boolean);
|
|
23017
23322
|
workitOnPath = dirs.some((dir) => exts.some((ext) => {
|
|
23018
23323
|
try {
|
|
23019
|
-
return
|
|
23324
|
+
return fs15.statSync(path18.join(dir, `workit${ext}`)).isFile();
|
|
23020
23325
|
} catch {
|
|
23021
23326
|
return false;
|
|
23022
23327
|
}
|
|
@@ -23076,14 +23381,14 @@ var PM_RUN = new Set(["run", "run-script"]);
|
|
|
23076
23381
|
var PYTHON_RUNNERS = new Set(["uv", "poetry", "pipenv", "pdm", "hatch", "rye"]);
|
|
23077
23382
|
|
|
23078
23383
|
// packages/workit-core/src/core/policy/derive.ts
|
|
23079
|
-
import { existsSync as
|
|
23080
|
-
import
|
|
23384
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
23385
|
+
import path21 from "node:path";
|
|
23081
23386
|
|
|
23082
23387
|
// packages/workit-core/src/ledger.ts
|
|
23083
23388
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
23084
|
-
import { createHash as
|
|
23085
|
-
import
|
|
23086
|
-
import
|
|
23389
|
+
import { createHash as createHash10, randomBytes as randomBytes3 } from "node:crypto";
|
|
23390
|
+
import fs16 from "node:fs";
|
|
23391
|
+
import path20 from "node:path";
|
|
23087
23392
|
|
|
23088
23393
|
// packages/workit-core/src/core/policy/bookkeeping.ts
|
|
23089
23394
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
@@ -23163,8 +23468,8 @@ function bookkeepingPaths(cwd, input) {
|
|
|
23163
23468
|
}
|
|
23164
23469
|
|
|
23165
23470
|
// packages/workit-core/src/core/policy/lane.ts
|
|
23166
|
-
import { existsSync as
|
|
23167
|
-
import
|
|
23471
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
23472
|
+
import path19 from "node:path";
|
|
23168
23473
|
|
|
23169
23474
|
// packages/workit-core/src/git/default-base.ts
|
|
23170
23475
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
@@ -24552,7 +24857,7 @@ function computeLane(input) {
|
|
|
24552
24857
|
}
|
|
24553
24858
|
function untrackedStat(cwd, file) {
|
|
24554
24859
|
try {
|
|
24555
|
-
const bytes = readFileSync7(
|
|
24860
|
+
const bytes = readFileSync7(path19.join(cwd, file));
|
|
24556
24861
|
if (bytes.includes(0))
|
|
24557
24862
|
return { path: file, added: 0, deleted: 0, binary: true };
|
|
24558
24863
|
const text = bytes.toString("utf8");
|
|
@@ -24584,7 +24889,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
24584
24889
|
let after = blobs.get(entry.newBlob);
|
|
24585
24890
|
if (!after && head === null && ABSENT.test(entry.newBlob))
|
|
24586
24891
|
try {
|
|
24587
|
-
after = readFileSync7(
|
|
24892
|
+
after = readFileSync7(path19.join(cwd, entry.path));
|
|
24588
24893
|
} catch {
|
|
24589
24894
|
after = undefined;
|
|
24590
24895
|
}
|
|
@@ -24803,7 +25108,7 @@ var binaryRangeDiff = (cwd, base, head) => {
|
|
|
24803
25108
|
return diff.ok && diff.stdout ? diff.stdout : null;
|
|
24804
25109
|
};
|
|
24805
25110
|
var hashOfDiff = (diff) => {
|
|
24806
|
-
const hash =
|
|
25111
|
+
const hash = createHash10("sha256");
|
|
24807
25112
|
for (const line of diff.split(`
|
|
24808
25113
|
`)) {
|
|
24809
25114
|
if (line.startsWith("index "))
|
|
@@ -24836,14 +25141,14 @@ function cleanRebase(cwd, range) {
|
|
|
24836
25141
|
return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
|
|
24837
25142
|
}
|
|
24838
25143
|
function storeRoot(cwd) {
|
|
24839
|
-
const location = resolveStore(
|
|
25144
|
+
const location = resolveStore(path20.resolve(cwd));
|
|
24840
25145
|
if (location instanceof Error)
|
|
24841
25146
|
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");
|
|
24842
25147
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
24843
25148
|
}
|
|
24844
25149
|
function ledgerPath(cwd) {
|
|
24845
25150
|
const root = storeRoot(cwd);
|
|
24846
|
-
return root.ok ? { ok: true, value:
|
|
25151
|
+
return root.ok ? { ok: true, value: path20.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
24847
25152
|
}
|
|
24848
25153
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
|
|
24849
25154
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -24863,25 +25168,25 @@ var onNetworkFs = (dir) => {
|
|
|
24863
25168
|
if (process.platform !== "linux")
|
|
24864
25169
|
return false;
|
|
24865
25170
|
try {
|
|
24866
|
-
return isNetworkFsType(
|
|
25171
|
+
return isNetworkFsType(fs16.statfsSync(dir).type);
|
|
24867
25172
|
} catch {
|
|
24868
25173
|
return false;
|
|
24869
25174
|
}
|
|
24870
25175
|
};
|
|
24871
|
-
var
|
|
24872
|
-
var
|
|
25176
|
+
var LOCK_WAIT_MS2 = 5000;
|
|
25177
|
+
var LOCK_STALE_MS2 = 30000;
|
|
24873
25178
|
var LOCK_OWNER = "owner";
|
|
24874
25179
|
var lockToken = (lock) => {
|
|
24875
25180
|
try {
|
|
24876
|
-
return
|
|
25181
|
+
return fs16.readFileSync(path20.join(lock, LOCK_OWNER), "utf8");
|
|
24877
25182
|
} catch {
|
|
24878
25183
|
return null;
|
|
24879
25184
|
}
|
|
24880
25185
|
};
|
|
24881
25186
|
var lockAgeMs = (lock) => {
|
|
24882
|
-
for (const target of [
|
|
25187
|
+
for (const target of [path20.join(lock, LOCK_OWNER), lock]) {
|
|
24883
25188
|
try {
|
|
24884
|
-
return Date.now() -
|
|
25189
|
+
return Date.now() - fs16.statSync(target).mtimeMs;
|
|
24885
25190
|
} catch {}
|
|
24886
25191
|
}
|
|
24887
25192
|
return null;
|
|
@@ -24889,14 +25194,14 @@ var lockAgeMs = (lock) => {
|
|
|
24889
25194
|
var ledgerLock = {
|
|
24890
25195
|
acquire(lock) {
|
|
24891
25196
|
try {
|
|
24892
|
-
|
|
25197
|
+
fs16.mkdirSync(lock);
|
|
24893
25198
|
} catch (error) {
|
|
24894
25199
|
if (error.code === "EEXIST")
|
|
24895
25200
|
return null;
|
|
24896
25201
|
throw error;
|
|
24897
25202
|
}
|
|
24898
25203
|
const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
|
|
24899
|
-
|
|
25204
|
+
fs16.writeFileSync(path20.join(lock, LOCK_OWNER), token);
|
|
24900
25205
|
return token;
|
|
24901
25206
|
},
|
|
24902
25207
|
release(lock, token) {
|
|
@@ -24904,40 +25209,40 @@ var ledgerLock = {
|
|
|
24904
25209
|
return false;
|
|
24905
25210
|
const tomb = `${lock}.release-${randomBytes3(6).toString("hex")}`;
|
|
24906
25211
|
try {
|
|
24907
|
-
|
|
25212
|
+
fs16.renameSync(lock, tomb);
|
|
24908
25213
|
} catch {
|
|
24909
25214
|
return false;
|
|
24910
25215
|
}
|
|
24911
25216
|
if (lockToken(tomb) !== token) {
|
|
24912
25217
|
try {
|
|
24913
|
-
|
|
25218
|
+
fs16.renameSync(tomb, lock);
|
|
24914
25219
|
} catch {}
|
|
24915
25220
|
return false;
|
|
24916
25221
|
}
|
|
24917
|
-
|
|
25222
|
+
fs16.rmSync(tomb, { recursive: true, force: true });
|
|
24918
25223
|
return true;
|
|
24919
25224
|
},
|
|
24920
25225
|
token: lockToken,
|
|
24921
25226
|
reap(lock, observed) {
|
|
24922
25227
|
const tomb = `${lock}.reap-${randomBytes3(6).toString("hex")}`;
|
|
24923
25228
|
try {
|
|
24924
|
-
|
|
25229
|
+
fs16.renameSync(lock, tomb);
|
|
24925
25230
|
} catch {
|
|
24926
25231
|
return false;
|
|
24927
25232
|
}
|
|
24928
25233
|
if (lockToken(tomb) === observed) {
|
|
24929
|
-
|
|
25234
|
+
fs16.rmSync(tomb, { recursive: true, force: true });
|
|
24930
25235
|
return true;
|
|
24931
25236
|
}
|
|
24932
25237
|
try {
|
|
24933
|
-
|
|
25238
|
+
fs16.renameSync(tomb, lock);
|
|
24934
25239
|
} catch {
|
|
24935
|
-
|
|
25240
|
+
fs16.rmSync(tomb, { recursive: true, force: true });
|
|
24936
25241
|
}
|
|
24937
25242
|
return false;
|
|
24938
25243
|
}
|
|
24939
25244
|
};
|
|
24940
|
-
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(
|
|
25245
|
+
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2)) {
|
|
24941
25246
|
const lock = `${file}.lock`;
|
|
24942
25247
|
const deadline = Date.now() + waitMs;
|
|
24943
25248
|
let token = null;
|
|
@@ -24947,7 +25252,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
|
|
|
24947
25252
|
break;
|
|
24948
25253
|
const observed = lockToken(lock);
|
|
24949
25254
|
const age = lockAgeMs(lock);
|
|
24950
|
-
if (age !== null && age >
|
|
25255
|
+
if (age !== null && age > LOCK_STALE_MS2 && ledgerLock.reap(lock, observed))
|
|
24951
25256
|
continue;
|
|
24952
25257
|
if (Date.now() >= deadline)
|
|
24953
25258
|
return null;
|
|
@@ -24959,14 +25264,14 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
|
|
|
24959
25264
|
ledgerLock.release(lock, token);
|
|
24960
25265
|
}
|
|
24961
25266
|
}
|
|
24962
|
-
var sha2562 = (text) =>
|
|
25267
|
+
var sha2562 = (text) => createHash10("sha256").update(text).digest("hex");
|
|
24963
25268
|
var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
|
|
24964
25269
|
${body}`);
|
|
24965
25270
|
var TAIL_BYTES = 64 * 1024;
|
|
24966
25271
|
var lastLine = (fd, size) => {
|
|
24967
25272
|
for (let span = Math.min(size, TAIL_BYTES);span > 0; span = Math.min(size, span * 2)) {
|
|
24968
25273
|
const buffer = Buffer.alloc(span);
|
|
24969
|
-
|
|
25274
|
+
fs16.readSync(fd, buffer, 0, span, size - span);
|
|
24970
25275
|
const end = buffer.lastIndexOf(10);
|
|
24971
25276
|
if (end < 0) {
|
|
24972
25277
|
if (span === size)
|
|
@@ -24997,32 +25302,32 @@ var lastLine = (fd, size) => {
|
|
|
24997
25302
|
};
|
|
24998
25303
|
var tighten = (fd) => {
|
|
24999
25304
|
try {
|
|
25000
|
-
if ((
|
|
25001
|
-
|
|
25305
|
+
if ((fs16.fstatSync(fd).mode & 63) !== 0)
|
|
25306
|
+
fs16.fchmodSync(fd, 384);
|
|
25002
25307
|
} catch {}
|
|
25003
25308
|
};
|
|
25004
25309
|
function appendLine(file, build, options) {
|
|
25005
25310
|
const write = () => {
|
|
25006
|
-
const fd =
|
|
25311
|
+
const fd = fs16.openSync(file, "a+", 384);
|
|
25007
25312
|
try {
|
|
25008
25313
|
if (process.platform !== "win32")
|
|
25009
25314
|
tighten(fd);
|
|
25010
|
-
const line = build(lastLine(fd,
|
|
25315
|
+
const line = build(lastLine(fd, fs16.fstatSync(fd).size));
|
|
25011
25316
|
if (!line.ok)
|
|
25012
25317
|
return line;
|
|
25013
25318
|
const bytes = Buffer.from(`
|
|
25014
25319
|
${line.value}`);
|
|
25015
|
-
const written =
|
|
25320
|
+
const written = fs16.writeSync(fd, bytes);
|
|
25016
25321
|
if (written !== bytes.length)
|
|
25017
25322
|
return err("unavailable", `short write to ${file}: ${written} of ${bytes.length} bytes; the row is torn and will be skipped`);
|
|
25018
25323
|
return { ok: true, value: undefined };
|
|
25019
25324
|
} finally {
|
|
25020
|
-
|
|
25325
|
+
fs16.closeSync(fd);
|
|
25021
25326
|
}
|
|
25022
25327
|
};
|
|
25023
25328
|
try {
|
|
25024
|
-
|
|
25025
|
-
if (options.heldLock || !options.forceLock && !onNetworkFs(
|
|
25329
|
+
fs16.mkdirSync(path20.dirname(file), { recursive: true });
|
|
25330
|
+
if (options.heldLock || !options.forceLock && !onNetworkFs(path20.dirname(file)))
|
|
25026
25331
|
return write();
|
|
25027
25332
|
const locked = withLedgerLock(file, write);
|
|
25028
25333
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -25039,7 +25344,7 @@ var sealed = (row, id, at, previous) => {
|
|
|
25039
25344
|
` };
|
|
25040
25345
|
};
|
|
25041
25346
|
function appendRaw(cwd, row, options) {
|
|
25042
|
-
const file = options.store ? { ok: true, value:
|
|
25347
|
+
const file = options.store ? { ok: true, value: path20.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
|
|
25043
25348
|
if (!file.ok)
|
|
25044
25349
|
return file;
|
|
25045
25350
|
const id = newId2();
|
|
@@ -25093,8 +25398,8 @@ function readLedgerAt(cwd, file, options) {
|
|
|
25093
25398
|
let text = "";
|
|
25094
25399
|
let stat = null;
|
|
25095
25400
|
try {
|
|
25096
|
-
stat =
|
|
25097
|
-
text =
|
|
25401
|
+
stat = fs16.statSync(file);
|
|
25402
|
+
text = fs16.readFileSync(file, "utf8");
|
|
25098
25403
|
} catch (error) {
|
|
25099
25404
|
if (error.code === "ENOENT")
|
|
25100
25405
|
return {
|
|
@@ -25234,7 +25539,7 @@ function ledgerTampering(cwd) {
|
|
|
25234
25539
|
if (!file.ok)
|
|
25235
25540
|
return [];
|
|
25236
25541
|
try {
|
|
25237
|
-
const stat =
|
|
25542
|
+
const stat = fs16.statSync(file.value);
|
|
25238
25543
|
const cached = tamperCache.get(file.value);
|
|
25239
25544
|
if (cached && cached.size === stat.size && cached.stamp === fileStamp(stat))
|
|
25240
25545
|
return cached.breaks;
|
|
@@ -25701,8 +26006,8 @@ function remoteIdentity(cwd, hop = 0) {
|
|
|
25701
26006
|
return null;
|
|
25702
26007
|
if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
|
|
25703
26008
|
const local = raw.replace(/^file:\/\//u, "");
|
|
25704
|
-
const resolved =
|
|
25705
|
-
if (
|
|
26009
|
+
const resolved = path20.isAbsolute(local) ? local : path20.resolve(cwd, local);
|
|
26010
|
+
if (fs16.existsSync(resolved))
|
|
25706
26011
|
return remoteIdentity(resolved, 1);
|
|
25707
26012
|
}
|
|
25708
26013
|
const parsed = parseRemoteUrl(raw);
|
|
@@ -25722,8 +26027,8 @@ function verdictMirrorPath(cwd) {
|
|
|
25722
26027
|
}
|
|
25723
26028
|
if (!identity)
|
|
25724
26029
|
return null;
|
|
25725
|
-
const key =
|
|
25726
|
-
return
|
|
26030
|
+
const key = createHash10("sha256").update(identity).digest("hex").slice(0, 32);
|
|
26031
|
+
return path20.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
|
|
25727
26032
|
}
|
|
25728
26033
|
var importedStamp = new Map;
|
|
25729
26034
|
function importMirroredVerdicts(cwd, branch) {
|
|
@@ -25733,7 +26038,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
25733
26038
|
return [];
|
|
25734
26039
|
let stamp;
|
|
25735
26040
|
try {
|
|
25736
|
-
stamp = `${branch}\x00${fileStamp(
|
|
26041
|
+
stamp = `${branch}\x00${fileStamp(fs16.statSync(file))}`;
|
|
25737
26042
|
} catch {
|
|
25738
26043
|
return [];
|
|
25739
26044
|
}
|
|
@@ -25746,7 +26051,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
25746
26051
|
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
25747
26052
|
const added = new Set;
|
|
25748
26053
|
try {
|
|
25749
|
-
|
|
26054
|
+
fs16.mkdirSync(path20.dirname(local.value), { recursive: true });
|
|
25750
26055
|
} catch {
|
|
25751
26056
|
return [];
|
|
25752
26057
|
}
|
|
@@ -25950,7 +26255,7 @@ var productDecision = (task, ledger) => {
|
|
|
25950
26255
|
};
|
|
25951
26256
|
};
|
|
25952
26257
|
var planRecorded = (task, root) => {
|
|
25953
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" &&
|
|
26258
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path21.resolve(root, ref.path)));
|
|
25954
26259
|
if (cited)
|
|
25955
26260
|
return {
|
|
25956
26261
|
met: true,
|
|
@@ -26016,15 +26321,15 @@ function derivedRuleStatus(task, requirement, root, ledger) {
|
|
|
26016
26321
|
}
|
|
26017
26322
|
|
|
26018
26323
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
26019
|
-
var digestBytes = (value) =>
|
|
26020
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
26021
|
-
var relative = (root, candidate) =>
|
|
26324
|
+
var digestBytes = (value) => createHash11("sha256").update(value).digest("hex");
|
|
26325
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path22.sep}`);
|
|
26326
|
+
var relative = (root, candidate) => path22.relative(root, candidate).split(path22.sep).join("/") || ".";
|
|
26022
26327
|
var canonicalPath = (value) => {
|
|
26023
26328
|
if (typeof value !== "string" || !value)
|
|
26024
26329
|
return null;
|
|
26025
26330
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
26026
26331
|
return null;
|
|
26027
|
-
const normalized =
|
|
26332
|
+
const normalized = path22.posix.normalize(value);
|
|
26028
26333
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
26029
26334
|
return null;
|
|
26030
26335
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -26072,21 +26377,21 @@ var gitPaths = (root) => {
|
|
|
26072
26377
|
git: !/not a git repository/i.test(stderr)
|
|
26073
26378
|
};
|
|
26074
26379
|
}
|
|
26075
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
26380
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path22.sep).join("/")) : [];
|
|
26076
26381
|
const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
26077
26382
|
if (stagedDeleted.status !== 0) {
|
|
26078
26383
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
26079
26384
|
if (!/not a git repository/i.test(stderr))
|
|
26080
26385
|
return { paths, uncertain: true, git: true };
|
|
26081
26386
|
} else if (stagedDeleted.stdout) {
|
|
26082
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
26387
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path22.sep).join("/")));
|
|
26083
26388
|
}
|
|
26084
26389
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
26085
26390
|
};
|
|
26086
26391
|
var walk = (root, directory, output) => {
|
|
26087
26392
|
let names;
|
|
26088
26393
|
try {
|
|
26089
|
-
names =
|
|
26394
|
+
names = fs17.readdirSync(directory);
|
|
26090
26395
|
} catch {
|
|
26091
26396
|
return true;
|
|
26092
26397
|
}
|
|
@@ -26094,10 +26399,10 @@ var walk = (root, directory, output) => {
|
|
|
26094
26399
|
for (const name of names) {
|
|
26095
26400
|
if (name === ".git" || name === ".workit")
|
|
26096
26401
|
continue;
|
|
26097
|
-
const target =
|
|
26402
|
+
const target = path22.join(directory, name);
|
|
26098
26403
|
let stat;
|
|
26099
26404
|
try {
|
|
26100
|
-
stat =
|
|
26405
|
+
stat = fs17.lstatSync(target);
|
|
26101
26406
|
} catch {
|
|
26102
26407
|
uncertain = true;
|
|
26103
26408
|
continue;
|
|
@@ -26112,14 +26417,14 @@ var walk = (root, directory, output) => {
|
|
|
26112
26417
|
var scopeRoots = (root, scope) => {
|
|
26113
26418
|
const roots = [];
|
|
26114
26419
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
26115
|
-
const target =
|
|
26420
|
+
const target = path22.resolve(root, item);
|
|
26116
26421
|
if (!inside(root, target))
|
|
26117
26422
|
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` }] });
|
|
26118
26423
|
let ancestor = target;
|
|
26119
|
-
while (!
|
|
26120
|
-
ancestor =
|
|
26424
|
+
while (!fs17.existsSync(ancestor) && ancestor !== root)
|
|
26425
|
+
ancestor = path22.dirname(ancestor);
|
|
26121
26426
|
try {
|
|
26122
|
-
if (!inside(root,
|
|
26427
|
+
if (!inside(root, fs17.realpathSync(ancestor)))
|
|
26123
26428
|
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` }] });
|
|
26124
26429
|
} catch {
|
|
26125
26430
|
return failure2("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
@@ -26131,7 +26436,7 @@ var scopeRoots = (root, scope) => {
|
|
|
26131
26436
|
function captureCandidate(root, scope, environment = []) {
|
|
26132
26437
|
let checkout;
|
|
26133
26438
|
try {
|
|
26134
|
-
checkout =
|
|
26439
|
+
checkout = fs17.realpathSync(root);
|
|
26135
26440
|
} catch {
|
|
26136
26441
|
return failure2("invalid_input", "candidate root does not exist");
|
|
26137
26442
|
}
|
|
@@ -26149,11 +26454,11 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
26149
26454
|
if (item === ".git" || item === ".workit")
|
|
26150
26455
|
continue;
|
|
26151
26456
|
names.add(item);
|
|
26152
|
-
if (!
|
|
26457
|
+
if (!fs17.existsSync(target))
|
|
26153
26458
|
continue;
|
|
26154
26459
|
let stat;
|
|
26155
26460
|
try {
|
|
26156
|
-
stat =
|
|
26461
|
+
stat = fs17.lstatSync(target);
|
|
26157
26462
|
} catch {
|
|
26158
26463
|
uncertain = true;
|
|
26159
26464
|
continue;
|
|
@@ -26169,17 +26474,17 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
26169
26474
|
for (const item of [...names].toSorted()) {
|
|
26170
26475
|
if (!scopeMatches(item, normalizedScope))
|
|
26171
26476
|
continue;
|
|
26172
|
-
const target =
|
|
26477
|
+
const target = path22.join(checkout, item);
|
|
26173
26478
|
try {
|
|
26174
|
-
const stat =
|
|
26479
|
+
const stat = fs17.lstatSync(target);
|
|
26175
26480
|
if (stat.isSymbolicLink()) {
|
|
26176
|
-
const link =
|
|
26481
|
+
const link = fs17.readlinkSync(target);
|
|
26177
26482
|
files.push({ path: item, kind: "symlink", digest: digestBytes(link), executable: null });
|
|
26178
26483
|
} else if (stat.isFile()) {
|
|
26179
26484
|
files.push({
|
|
26180
26485
|
path: item,
|
|
26181
26486
|
kind: "file",
|
|
26182
|
-
digest: digestBytes(
|
|
26487
|
+
digest: digestBytes(fs17.readFileSync(target)),
|
|
26183
26488
|
executable: (stat.mode & 73) !== 0
|
|
26184
26489
|
});
|
|
26185
26490
|
} else if (!stat.isDirectory()) {
|
|
@@ -26344,7 +26649,7 @@ var findingVerificationPasses = (findingCandidateId, evidence) => evidence.statu
|
|
|
26344
26649
|
var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
26345
26650
|
let root;
|
|
26346
26651
|
try {
|
|
26347
|
-
root =
|
|
26652
|
+
root = fs17.realpathSync(checkoutRoot);
|
|
26348
26653
|
} catch {
|
|
26349
26654
|
return failure2("permission_denied", "checkout root is unavailable");
|
|
26350
26655
|
}
|
|
@@ -26353,23 +26658,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
26353
26658
|
continue;
|
|
26354
26659
|
if (!reference.digest)
|
|
26355
26660
|
return failure2("invalid_input", "document references require a byte digest");
|
|
26356
|
-
const target =
|
|
26357
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
26661
|
+
const target = path22.resolve(root, reference.path);
|
|
26662
|
+
if (target !== root && !target.startsWith(`${root}${path22.sep}`))
|
|
26358
26663
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
26359
26664
|
fields: [
|
|
26360
26665
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
26361
26666
|
]
|
|
26362
26667
|
});
|
|
26363
26668
|
try {
|
|
26364
|
-
const below =
|
|
26669
|
+
const below = path22.relative(root, target);
|
|
26365
26670
|
let current = root;
|
|
26366
|
-
for (const segment of below.split(
|
|
26671
|
+
for (const segment of below.split(path22.sep)) {
|
|
26367
26672
|
if (!segment)
|
|
26368
26673
|
continue;
|
|
26369
|
-
current =
|
|
26370
|
-
const stat =
|
|
26371
|
-
const real =
|
|
26372
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
26674
|
+
current = path22.join(current, segment);
|
|
26675
|
+
const stat = fs17.lstatSync(current);
|
|
26676
|
+
const real = fs17.realpathSync(current);
|
|
26677
|
+
if (real !== root && !real.startsWith(`${root}${path22.sep}`))
|
|
26373
26678
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
26374
26679
|
fields: [
|
|
26375
26680
|
{
|
|
@@ -26385,7 +26690,7 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
26385
26690
|
if (current !== target && !stat.isDirectory())
|
|
26386
26691
|
return failure2("invalid_input", "document reference ancestor is not a directory");
|
|
26387
26692
|
}
|
|
26388
|
-
if (digestBytes(
|
|
26693
|
+
if (digestBytes(fs17.readFileSync(target)) !== reference.digest)
|
|
26389
26694
|
return failure2("permission_denied", "decision document bytes have changed");
|
|
26390
26695
|
} catch {
|
|
26391
26696
|
return failure2("invalid_input", "decision document is unavailable");
|
|
@@ -27043,26 +27348,26 @@ var exportDigest = (bundle) => sha256({
|
|
|
27043
27348
|
task: bundle.task
|
|
27044
27349
|
});
|
|
27045
27350
|
// packages/workit-core/src/autonomy.ts
|
|
27046
|
-
import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as
|
|
27047
|
-
import
|
|
27351
|
+
import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync12, openSync as openSync2 } from "node:fs";
|
|
27352
|
+
import path26 from "node:path";
|
|
27048
27353
|
|
|
27049
27354
|
// packages/workit-core/src/core/eval-world.ts
|
|
27050
|
-
import { existsSync as
|
|
27051
|
-
import
|
|
27052
|
-
import
|
|
27355
|
+
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
27356
|
+
import os6 from "node:os";
|
|
27357
|
+
import path23 from "node:path";
|
|
27053
27358
|
var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
|
|
27054
27359
|
var EVAL_WORLD_MARKER = ".workit-eval-world";
|
|
27055
27360
|
var inside2 = (dir, file) => {
|
|
27056
|
-
const rel =
|
|
27057
|
-
return !rel.startsWith("..") && !
|
|
27361
|
+
const rel = path23.relative(dir, file);
|
|
27362
|
+
return !rel.startsWith("..") && !path23.isAbsolute(rel);
|
|
27058
27363
|
};
|
|
27059
27364
|
var evalWorld = (cwd) => {
|
|
27060
27365
|
const raw = process.env[EVAL_WORLD_ENV];
|
|
27061
|
-
if (!raw || !
|
|
27366
|
+
if (!raw || !path23.isAbsolute(raw))
|
|
27062
27367
|
return null;
|
|
27063
27368
|
try {
|
|
27064
|
-
const world =
|
|
27065
|
-
return inside2(
|
|
27369
|
+
const world = realpathSync7(raw);
|
|
27370
|
+
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path23.join(world, EVAL_WORLD_MARKER)) ? world : null;
|
|
27066
27371
|
} catch {
|
|
27067
27372
|
return null;
|
|
27068
27373
|
}
|
|
@@ -27070,16 +27375,16 @@ var evalWorld = (cwd) => {
|
|
|
27070
27375
|
var evalWorldEntry = (cwd) => {
|
|
27071
27376
|
const world = evalWorld(cwd);
|
|
27072
27377
|
try {
|
|
27073
|
-
return world ? loadWorkspacesFrom(
|
|
27378
|
+
return world ? loadWorkspacesFrom(path23.join(world, "config"))[0] ?? null : null;
|
|
27074
27379
|
} catch {
|
|
27075
27380
|
return null;
|
|
27076
27381
|
}
|
|
27077
27382
|
};
|
|
27078
27383
|
|
|
27079
27384
|
// packages/workit-core/src/core/grant-seal.ts
|
|
27080
|
-
import { createHash as
|
|
27385
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
27081
27386
|
import { readFileSync as readFileSync9 } from "node:fs";
|
|
27082
|
-
import
|
|
27387
|
+
import path24 from "node:path";
|
|
27083
27388
|
var SEAL_FILE = "workspaces.json.seal";
|
|
27084
27389
|
var SEAL_VERSION = 1;
|
|
27085
27390
|
var SEAL_COMMAND = "workit workspace seal";
|
|
@@ -27113,15 +27418,15 @@ var sealProjection = (entries) => entries.map((entry) => {
|
|
|
27113
27418
|
youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
|
|
27114
27419
|
}, ENTRY_KEYS);
|
|
27115
27420
|
});
|
|
27116
|
-
var
|
|
27117
|
-
var sealDigest = (projection) =>
|
|
27421
|
+
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);
|
|
27422
|
+
var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
|
|
27118
27423
|
var broken = (reason, sealed = null) => ({
|
|
27119
27424
|
state: "broken",
|
|
27120
27425
|
reason,
|
|
27121
27426
|
sealed
|
|
27122
27427
|
});
|
|
27123
27428
|
function checkSeal(dir) {
|
|
27124
|
-
const file =
|
|
27429
|
+
const file = path24.join(dir, SEAL_FILE);
|
|
27125
27430
|
let seal;
|
|
27126
27431
|
try {
|
|
27127
27432
|
seal = JSON.parse(readFileSync9(file, "utf8"));
|
|
@@ -27144,8 +27449,8 @@ function checkSeal(dir) {
|
|
|
27144
27449
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
27145
27450
|
|
|
27146
27451
|
// packages/workit-core/src/forge/exec.ts
|
|
27147
|
-
import
|
|
27148
|
-
import
|
|
27452
|
+
import fs18 from "node:fs";
|
|
27453
|
+
import path25 from "node:path";
|
|
27149
27454
|
|
|
27150
27455
|
// packages/workit-core/src/forge/redact.ts
|
|
27151
27456
|
var NAME = "[A-Za-z0-9_.-]";
|
|
@@ -27158,13 +27463,13 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u0
|
|
|
27158
27463
|
// packages/workit-core/src/forge/exec.ts
|
|
27159
27464
|
var MAX_BUFFER2 = 64 * 1024 * 1024;
|
|
27160
27465
|
function findExecutable(bin, env) {
|
|
27161
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
27466
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path25.delimiter).filter(Boolean);
|
|
27162
27467
|
const exts = process.platform === "win32" ? [".exe"] : [""];
|
|
27163
27468
|
for (const dir of dirs)
|
|
27164
27469
|
for (const ext of exts) {
|
|
27165
|
-
const candidate =
|
|
27470
|
+
const candidate = path25.join(dir, `${bin}${ext}`);
|
|
27166
27471
|
try {
|
|
27167
|
-
const stat =
|
|
27472
|
+
const stat = fs18.statSync(candidate);
|
|
27168
27473
|
if (stat.isFile())
|
|
27169
27474
|
return candidate;
|
|
27170
27475
|
} catch {}
|
|
@@ -27219,7 +27524,7 @@ var accountHomeDir = () => {
|
|
|
27219
27524
|
};
|
|
27220
27525
|
var deniedFile = (dir) => {
|
|
27221
27526
|
for (const name of ["workspaces.json", SEAL_FILE]) {
|
|
27222
|
-
const file =
|
|
27527
|
+
const file = path26.join(dir, name);
|
|
27223
27528
|
try {
|
|
27224
27529
|
closeSync2(openSync2(file, "r"));
|
|
27225
27530
|
} catch (error) {
|
|
@@ -27241,7 +27546,7 @@ var accountUnread = () => {
|
|
|
27241
27546
|
if (dir === null)
|
|
27242
27547
|
return NO_ACCOUNT;
|
|
27243
27548
|
const file = deniedFile(dir);
|
|
27244
|
-
return file === null ? null : `the account's ${
|
|
27549
|
+
return file === null ? null : `the account's ${path26.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
|
|
27245
27550
|
};
|
|
27246
27551
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
27247
27552
|
var fileSource = (dir = accountDir()) => ({
|
|
@@ -27262,7 +27567,7 @@ var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never r
|
|
|
27262
27567
|
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;
|
|
27263
27568
|
var shownGrantsDir = () => {
|
|
27264
27569
|
const world = evalWorld(process.cwd());
|
|
27265
|
-
return world ?
|
|
27570
|
+
return world ? path26.join(world, "config") : accountDir();
|
|
27266
27571
|
};
|
|
27267
27572
|
var benchWorld = (cwd) => {
|
|
27268
27573
|
const entry = evalWorldEntry(cwd);
|
|
@@ -27286,10 +27591,10 @@ var grantsOverride = () => {
|
|
|
27286
27591
|
const shown = shownGrantsDir();
|
|
27287
27592
|
if (shown === null)
|
|
27288
27593
|
return accountUnread() ?? NO_ACCOUNT;
|
|
27289
|
-
const configured =
|
|
27290
|
-
return configured ===
|
|
27594
|
+
const configured = path26.resolve(resolveConfigDir());
|
|
27595
|
+
return configured === path26.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 ${path26.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
|
|
27291
27596
|
};
|
|
27292
|
-
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 ${
|
|
27597
|
+
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 ${path26.join(grantsDir(), "workspaces.json")}`;
|
|
27293
27598
|
var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
|
|
27294
27599
|
var DEFAULT_GRANTS = Object.freeze({
|
|
27295
27600
|
push: true,
|
|
@@ -27690,7 +27995,7 @@ var BRANCH_RENAME = new Set(["-m", "-M", "--move", "-c", "-C", "--copy"]);
|
|
|
27690
27995
|
var WORKTREE_VALUES = new Set(["--reason"]);
|
|
27691
27996
|
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"]));
|
|
27692
27997
|
// packages/workit-core/src/core/task-engine.ts
|
|
27693
|
-
import { realpathSync as
|
|
27998
|
+
import { realpathSync as realpathSync9 } from "node:fs";
|
|
27694
27999
|
|
|
27695
28000
|
// packages/workit-core/src/core/policy-resolver.ts
|
|
27696
28001
|
function resolvePolicy(input) {
|
|
@@ -27939,12 +28244,12 @@ var judgeInputSummary = (raw) => {
|
|
|
27939
28244
|
};
|
|
27940
28245
|
|
|
27941
28246
|
// packages/workit-core/src/core/task-view.ts
|
|
27942
|
-
import { realpathSync as
|
|
28247
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
27943
28248
|
var environment = () => [];
|
|
27944
28249
|
var sameSession2 = (value, context) => typeof value === "object" && value !== null && value.kind === "host" && value.host === context.caller.host && value.handle === context.caller.actor;
|
|
27945
28250
|
function contextRootError(store, context) {
|
|
27946
28251
|
try {
|
|
27947
|
-
|
|
28252
|
+
realpathSync8(context.root);
|
|
27948
28253
|
const root = checkoutRootOf(context.root);
|
|
27949
28254
|
if (root !== store.root && !sameDirectoryIdentity(root, store.root))
|
|
27950
28255
|
return failure2("invalid_input", "operation context root does not match the task store root");
|
|
@@ -29414,7 +29719,7 @@ class WorkitCore {
|
|
|
29414
29719
|
if (view.task.workspaceId !== view.workspace.id)
|
|
29415
29720
|
return failure2("invalid_input", "task and workspace bindings are invalid");
|
|
29416
29721
|
try {
|
|
29417
|
-
if (
|
|
29722
|
+
if (realpathSync9(view.workspace.root) !== this.store.root)
|
|
29418
29723
|
return failure2("invalid_input", "task view root does not match the task store");
|
|
29419
29724
|
} catch {
|
|
29420
29725
|
return failure2("invalid_input", "task view root cannot be resolved");
|
|
@@ -29665,8 +29970,8 @@ class WorkitCore {
|
|
|
29665
29970
|
}
|
|
29666
29971
|
// packages/workit-core/src/core/repo-context.ts
|
|
29667
29972
|
import { spawnSync as spawnSync17 } from "node:child_process";
|
|
29668
|
-
import { existsSync as
|
|
29669
|
-
import
|
|
29973
|
+
import { existsSync as existsSync13, readFileSync as readFileSync10, readdirSync as readdirSync4 } from "node:fs";
|
|
29974
|
+
import path27 from "node:path";
|
|
29670
29975
|
var isSafeContextRange = (value) => value.length <= 4096 && (() => {
|
|
29671
29976
|
try {
|
|
29672
29977
|
gitRevisionParts(value);
|
|
@@ -29810,13 +30115,13 @@ var findPrTemplate = (cwd) => {
|
|
|
29810
30115
|
for (const rel of PR_TEMPLATE_FILES) {
|
|
29811
30116
|
const parts = rel.split("/");
|
|
29812
30117
|
const base = parts[parts.length - 1];
|
|
29813
|
-
const dir = parts.length > 1 ?
|
|
30118
|
+
const dir = parts.length > 1 ? path27.join(cwd, ...parts.slice(0, -1)) : cwd;
|
|
29814
30119
|
const actual = probeCaseInsensitive(dir, base);
|
|
29815
30120
|
if (actual)
|
|
29816
30121
|
return [...parts.slice(0, -1), actual].join("/");
|
|
29817
30122
|
}
|
|
29818
30123
|
for (const rel of PR_TEMPLATE_DIRS) {
|
|
29819
|
-
const only = singleMarkdown(
|
|
30124
|
+
const only = singleMarkdown(path27.join(cwd, ...rel.split("/")));
|
|
29820
30125
|
if (only)
|
|
29821
30126
|
return `${rel}/${only}`;
|
|
29822
30127
|
}
|
|
@@ -29846,8 +30151,8 @@ var diffStatForRange = (cwd, range) => {
|
|
|
29846
30151
|
return runGit(cwd, ["diff", "--stat", "--"]).stdout;
|
|
29847
30152
|
};
|
|
29848
30153
|
var packageScripts = (cwd, keys) => {
|
|
29849
|
-
const pkgPath =
|
|
29850
|
-
if (!
|
|
30154
|
+
const pkgPath = path27.join(cwd, "package.json");
|
|
30155
|
+
if (!existsSync13(pkgPath))
|
|
29851
30156
|
return [];
|
|
29852
30157
|
try {
|
|
29853
30158
|
const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
|
|
@@ -29872,9 +30177,9 @@ var documentationFiles = (cwd) => {
|
|
|
29872
30177
|
if (entry.isDirectory()) {
|
|
29873
30178
|
if (excluded.has(entry.name))
|
|
29874
30179
|
continue;
|
|
29875
|
-
walk(
|
|
30180
|
+
walk(path27.join(dir, entry.name), depth + 1);
|
|
29876
30181
|
} else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
|
|
29877
|
-
matches.push("./" +
|
|
30182
|
+
matches.push("./" + path27.relative(cwd, path27.join(dir, entry.name)).replaceAll("\\", "/"));
|
|
29878
30183
|
}
|
|
29879
30184
|
}
|
|
29880
30185
|
};
|
|
@@ -29882,7 +30187,7 @@ var documentationFiles = (cwd) => {
|
|
|
29882
30187
|
return matches.toSorted().slice(0, 200);
|
|
29883
30188
|
};
|
|
29884
30189
|
var readTrimmed2 = (file, maxLines) => {
|
|
29885
|
-
if (!
|
|
30190
|
+
if (!existsSync13(file))
|
|
29886
30191
|
return "";
|
|
29887
30192
|
const lines = readFileSync10(file, "utf8").split(`
|
|
29888
30193
|
`);
|
|
@@ -29890,7 +30195,7 @@ var readTrimmed2 = (file, maxLines) => {
|
|
|
29890
30195
|
`);
|
|
29891
30196
|
};
|
|
29892
30197
|
function prReadyContext(root, range) {
|
|
29893
|
-
const cwd =
|
|
30198
|
+
const cwd = path27.resolve(repoRoot(root));
|
|
29894
30199
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
29895
30200
|
return invalidRange(cwd);
|
|
29896
30201
|
let stdout = "";
|
|
@@ -29948,7 +30253,7 @@ ${status.stderr}` : "");
|
|
|
29948
30253
|
stdout += `template_path: ${template}
|
|
29949
30254
|
|
|
29950
30255
|
`;
|
|
29951
|
-
stdout += readTrimmed2(
|
|
30256
|
+
stdout += readTrimmed2(path27.join(cwd, template), 220);
|
|
29952
30257
|
} else {
|
|
29953
30258
|
stdout += `template_path: none
|
|
29954
30259
|
|
|
@@ -29958,7 +30263,7 @@ ${status.stderr}` : "");
|
|
|
29958
30263
|
stdout += `
|
|
29959
30264
|
`;
|
|
29960
30265
|
stdout += printSection("Recent Validation Signals");
|
|
29961
|
-
if (
|
|
30266
|
+
if (existsSync13(path27.join(cwd, "package.json"))) {
|
|
29962
30267
|
stdout += `package.json detected. Common scripts:
|
|
29963
30268
|
`;
|
|
29964
30269
|
const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
|
|
@@ -29967,7 +30272,7 @@ ${status.stderr}` : "");
|
|
|
29967
30272
|
`) + `
|
|
29968
30273
|
`;
|
|
29969
30274
|
}
|
|
29970
|
-
if (
|
|
30275
|
+
if (existsSync13(path27.join(cwd, "Cargo.toml")) || existsSync13(path27.join(cwd, "src-tauri/Cargo.toml"))) {
|
|
29971
30276
|
stdout += `Rust project detected.
|
|
29972
30277
|
`;
|
|
29973
30278
|
}
|
|
@@ -30000,7 +30305,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
|
|
|
30000
30305
|
- Apply with the host-native editor, preserving the repository changelog conventions.
|
|
30001
30306
|
- If Unreleased already has duplicate category headings, normalize_only first.`;
|
|
30002
30307
|
function changelogContext(root, range) {
|
|
30003
|
-
const cwd =
|
|
30308
|
+
const cwd = path27.resolve(repoRoot(root));
|
|
30004
30309
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
30005
30310
|
return invalidRange(cwd);
|
|
30006
30311
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -30018,8 +30323,8 @@ function changelogContext(root, range) {
|
|
|
30018
30323
|
stdout += CHANGELOG_RULES + `
|
|
30019
30324
|
`;
|
|
30020
30325
|
stdout += printSection("Existing CHANGELOG.md");
|
|
30021
|
-
const changelogPath =
|
|
30022
|
-
if (
|
|
30326
|
+
const changelogPath = path27.join(cwd, "CHANGELOG.md");
|
|
30327
|
+
if (existsSync13(changelogPath)) {
|
|
30023
30328
|
stdout += readTrimmed2(changelogPath, 260) + `
|
|
30024
30329
|
`;
|
|
30025
30330
|
} else {
|
|
@@ -30038,7 +30343,7 @@ function changelogContext(root, range) {
|
|
|
30038
30343
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
30039
30344
|
}
|
|
30040
30345
|
function docsRefreshContext(root, range) {
|
|
30041
|
-
const cwd =
|
|
30346
|
+
const cwd = path27.resolve(repoRoot(root));
|
|
30042
30347
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
30043
30348
|
return invalidRange(cwd);
|
|
30044
30349
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -30060,8 +30365,8 @@ function docsRefreshContext(root, range) {
|
|
|
30060
30365
|
`) + `
|
|
30061
30366
|
`;
|
|
30062
30367
|
stdout += printSection("README Preview");
|
|
30063
|
-
const readme =
|
|
30064
|
-
if (
|
|
30368
|
+
const readme = path27.join(cwd, "README.md");
|
|
30369
|
+
if (existsSync13(readme)) {
|
|
30065
30370
|
stdout += readTrimmed2(readme, 220) + `
|
|
30066
30371
|
`;
|
|
30067
30372
|
} else {
|
|
@@ -30069,8 +30374,8 @@ function docsRefreshContext(root, range) {
|
|
|
30069
30374
|
`;
|
|
30070
30375
|
}
|
|
30071
30376
|
stdout += printSection("Package Scripts");
|
|
30072
|
-
const pkgPath =
|
|
30073
|
-
if (
|
|
30377
|
+
const pkgPath = path27.join(cwd, "package.json");
|
|
30378
|
+
if (existsSync13(pkgPath)) {
|
|
30074
30379
|
try {
|
|
30075
30380
|
const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
|
|
30076
30381
|
stdout += JSON.stringify({ name: pkg.name, version: pkg.version, scripts: pkg.scripts }, null, 2) + `
|
|
@@ -30083,7 +30388,7 @@ function docsRefreshContext(root, range) {
|
|
|
30083
30388
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
30084
30389
|
}
|
|
30085
30390
|
function releaseNotesContext(root, rangeOrTag) {
|
|
30086
|
-
const cwd =
|
|
30391
|
+
const cwd = path27.resolve(repoRoot(root));
|
|
30087
30392
|
if (!rangeOrTag) {
|
|
30088
30393
|
return {
|
|
30089
30394
|
stdout: "",
|
|
@@ -30126,7 +30431,7 @@ function releaseNotesContext(root, rangeOrTag) {
|
|
|
30126
30431
|
`;
|
|
30127
30432
|
stdout += printSection("Existing Release Files");
|
|
30128
30433
|
for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
|
|
30129
|
-
if (
|
|
30434
|
+
if (existsSync13(path27.join(cwd, rel)))
|
|
30130
30435
|
stdout += rel + `
|
|
30131
30436
|
`;
|
|
30132
30437
|
}
|
|
@@ -30157,8 +30462,8 @@ function releaseNotesContext(root, rangeOrTag) {
|
|
|
30157
30462
|
import { spawnSync as spawnSync19 } from "node:child_process";
|
|
30158
30463
|
|
|
30159
30464
|
// packages/workit-core/src/core/pr-create.ts
|
|
30160
|
-
import
|
|
30161
|
-
import
|
|
30465
|
+
import fs19 from "node:fs";
|
|
30466
|
+
import path28 from "node:path";
|
|
30162
30467
|
import { spawnSync as spawnSync18 } from "node:child_process";
|
|
30163
30468
|
// packages/workit-core/src/forge/pr-body.ts
|
|
30164
30469
|
function parseGhIssue(value) {
|
|
@@ -30178,13 +30483,13 @@ var LOCAL = bounded(20000);
|
|
|
30178
30483
|
var NETWORK = bounded(60000);
|
|
30179
30484
|
function whichOnPath(tool) {
|
|
30180
30485
|
const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
|
|
30181
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
30486
|
+
for (const dir of (process.env.PATH ?? "").split(path28.delimiter)) {
|
|
30182
30487
|
if (!dir)
|
|
30183
30488
|
continue;
|
|
30184
30489
|
for (const name of names) {
|
|
30185
|
-
const candidate =
|
|
30490
|
+
const candidate = path28.join(dir, name);
|
|
30186
30491
|
try {
|
|
30187
|
-
|
|
30492
|
+
fs19.accessSync(candidate, fs19.constants.X_OK);
|
|
30188
30493
|
return candidate;
|
|
30189
30494
|
} catch {}
|
|
30190
30495
|
}
|
|
@@ -30302,8 +30607,8 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
|
|
|
30302
30607
|
};
|
|
30303
30608
|
|
|
30304
30609
|
// packages/workit-core/src/core/youtrack.ts
|
|
30305
|
-
import
|
|
30306
|
-
import
|
|
30610
|
+
import fs20 from "node:fs";
|
|
30611
|
+
import path29 from "node:path";
|
|
30307
30612
|
|
|
30308
30613
|
// packages/workit-core/src/core/templates.ts
|
|
30309
30614
|
var repoRoot2 = assetRoot();
|
|
@@ -30315,14 +30620,14 @@ var resolveWorkspaceRoot = (explicit) => explicit || process.cwd();
|
|
|
30315
30620
|
|
|
30316
30621
|
// packages/workit-core/src/core/youtrack.ts
|
|
30317
30622
|
var ISSUE_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
|
|
30318
|
-
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ??
|
|
30623
|
+
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path29.join(resolveConfigDir(), "youtrack.json");
|
|
30319
30624
|
var readYouTrackContextConfig = () => {
|
|
30320
30625
|
const cfgPath = youTrackReadOnlyConfigPath();
|
|
30321
|
-
if (!
|
|
30626
|
+
if (!fs20.existsSync(cfgPath))
|
|
30322
30627
|
return { data: {} };
|
|
30323
30628
|
let parsed;
|
|
30324
30629
|
try {
|
|
30325
|
-
parsed = JSON.parse(
|
|
30630
|
+
parsed = JSON.parse(fs20.readFileSync(cfgPath, "utf8"));
|
|
30326
30631
|
} catch {
|
|
30327
30632
|
return { error: "YouTrack configuration is unavailable" };
|
|
30328
30633
|
}
|
|
@@ -30393,9 +30698,9 @@ function resolveYouTrackFromPaths(spec_path, plan_path, workspace_root) {
|
|
|
30393
30698
|
} catch {
|
|
30394
30699
|
continue;
|
|
30395
30700
|
}
|
|
30396
|
-
if (!
|
|
30701
|
+
if (!fs20.existsSync(full))
|
|
30397
30702
|
continue;
|
|
30398
|
-
const text =
|
|
30703
|
+
const text = fs20.readFileSync(full, "utf8");
|
|
30399
30704
|
const m = text.match(/^\*\*YouTrack:\*\*\s*`?([A-Z]+-\d+)`?/m);
|
|
30400
30705
|
if (m)
|
|
30401
30706
|
return m[1];
|
|
@@ -30667,22 +30972,22 @@ function resolveGitRevision(root, value) {
|
|
|
30667
30972
|
}
|
|
30668
30973
|
}
|
|
30669
30974
|
function resolveInside(root, candidate) {
|
|
30670
|
-
const base =
|
|
30671
|
-
const target =
|
|
30672
|
-
if (target !== base && !target.startsWith(base +
|
|
30975
|
+
const base = realpathSync10(root);
|
|
30976
|
+
const target = path30.resolve(base, candidate);
|
|
30977
|
+
if (target !== base && !target.startsWith(base + path30.sep)) {
|
|
30673
30978
|
throw new Error("path must stay inside repository root");
|
|
30674
30979
|
}
|
|
30675
30980
|
let ancestor = target;
|
|
30676
|
-
while (!
|
|
30677
|
-
ancestor =
|
|
30678
|
-
const canonicalAncestor =
|
|
30679
|
-
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base +
|
|
30981
|
+
while (!existsSync14(ancestor))
|
|
30982
|
+
ancestor = path30.dirname(ancestor);
|
|
30983
|
+
const canonicalAncestor = realpathSync10(ancestor);
|
|
30984
|
+
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path30.sep)) {
|
|
30680
30985
|
throw new Error("path must stay inside repository root");
|
|
30681
30986
|
}
|
|
30682
30987
|
return target;
|
|
30683
30988
|
}
|
|
30684
30989
|
function run2(root, executable, args, env = {}) {
|
|
30685
|
-
const cwd =
|
|
30990
|
+
const cwd = realpathSync10(root);
|
|
30686
30991
|
const result = spawnSync20(executable, args, {
|
|
30687
30992
|
cwd,
|
|
30688
30993
|
encoding: "utf8",
|
|
@@ -30714,11 +31019,11 @@ var changedSourcesSinceLoad = (marker) => {
|
|
|
30714
31019
|
};
|
|
30715
31020
|
|
|
30716
31021
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
30717
|
-
import { createHash as
|
|
31022
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
30718
31023
|
var SAME_CALL_FAILED = "Same call failed twice:";
|
|
30719
31024
|
var MAX_SESSIONS = 256;
|
|
30720
31025
|
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";
|
|
30721
|
-
var hashOf = (call) =>
|
|
31026
|
+
var hashOf = (call) => createHash13("sha256").update(call).digest("hex").slice(0, 32);
|
|
30722
31027
|
var record3 = (memo, sessionId, call, failed, next) => {
|
|
30723
31028
|
const previous = memo.get(sessionId);
|
|
30724
31029
|
memo.delete(sessionId);
|
|
@@ -30783,13 +31088,13 @@ var rootVariants = (workspaceRoot) => {
|
|
|
30783
31088
|
if (!workspaceRoot)
|
|
30784
31089
|
return [];
|
|
30785
31090
|
const roots = new Set;
|
|
30786
|
-
for (const candidate of [workspaceRoot,
|
|
30787
|
-
if (
|
|
31091
|
+
for (const candidate of [workspaceRoot, path31.resolve(workspaceRoot)]) {
|
|
31092
|
+
if (path31.isAbsolute(candidate) && candidate !== path31.parse(candidate).root)
|
|
30788
31093
|
roots.add(candidate);
|
|
30789
31094
|
}
|
|
30790
31095
|
try {
|
|
30791
|
-
const canonical =
|
|
30792
|
-
if (canonical !==
|
|
31096
|
+
const canonical = realpathSync11(workspaceRoot);
|
|
31097
|
+
if (canonical !== path31.parse(canonical).root)
|
|
30793
31098
|
roots.add(canonical);
|
|
30794
31099
|
} catch {}
|
|
30795
31100
|
return [...roots].toSorted((left, right) => right.length - left.length);
|
|
@@ -30871,12 +31176,12 @@ var thrownResult = (tool, error, workspaceRoot) => {
|
|
|
30871
31176
|
};
|
|
30872
31177
|
function createMcpServer(host, contextProvider) {
|
|
30873
31178
|
assertMcpHost(host);
|
|
30874
|
-
const here =
|
|
31179
|
+
const here = path31.dirname(fileURLToPath2(import.meta.url));
|
|
30875
31180
|
const sourceMarker = markSourcesLoaded([
|
|
30876
|
-
|
|
30877
|
-
|
|
30878
|
-
|
|
30879
|
-
].filter((file) =>
|
|
31181
|
+
path31.join(here, "server.ts"),
|
|
31182
|
+
path31.join(here, "..", "..", "workit-core", "src", "core", "task-contract.ts"),
|
|
31183
|
+
path31.join(here, "..", "..", "workit-core", "src", "core", "task-engine.ts")
|
|
31184
|
+
].filter((file) => existsSync15(file)));
|
|
30880
31185
|
let staleWarned = false;
|
|
30881
31186
|
const failures = new Map;
|
|
30882
31187
|
const server = new Server({ name: "workit", version: VERSION }, { capabilities: { tools: {}, resources: {} } });
|
|
@@ -31058,8 +31363,8 @@ var main = async () => {
|
|
|
31058
31363
|
process.exitCode = 2;
|
|
31059
31364
|
}
|
|
31060
31365
|
};
|
|
31061
|
-
var entryPath = process.argv[1] ?
|
|
31062
|
-
if (entryPath ===
|
|
31366
|
+
var entryPath = process.argv[1] ? path32.resolve(process.argv[1]) : "";
|
|
31367
|
+
if (entryPath === path32.resolve(fileURLToPath3(import.meta.url)))
|
|
31063
31368
|
await main();
|
|
31064
31369
|
export {
|
|
31065
31370
|
McpCapabilityUnavailableError,
|