@workit-dev/pi 2.29.1 → 2.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.js +24 -13
- package/dist/workit.js +532 -446
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -6814,17 +6814,17 @@ function explainInvalidOperation(family, request) {
|
|
|
6814
6814
|
return parsed.success ? null : invalidOperation(family, request, parsed.error);
|
|
6815
6815
|
}
|
|
6816
6816
|
// packages/workit-core/src/core/task-store.ts
|
|
6817
|
-
import { createHash as
|
|
6817
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
6818
6818
|
import * as fs14 from "node:fs";
|
|
6819
|
-
import
|
|
6819
|
+
import path19 from "node:path";
|
|
6820
6820
|
|
|
6821
6821
|
// packages/workit-core/src/host-session.ts
|
|
6822
|
-
import { createHash as
|
|
6822
|
+
import { createHash as createHash9, randomBytes, timingSafeEqual } from "node:crypto";
|
|
6823
6823
|
import fs7 from "node:fs";
|
|
6824
|
-
import
|
|
6824
|
+
import path13 from "node:path";
|
|
6825
6825
|
|
|
6826
6826
|
// packages/workit-core/src/core/branch.ts
|
|
6827
|
-
import { createHash as
|
|
6827
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
6828
6828
|
|
|
6829
6829
|
// packages/workit-core/src/core/branch-policy.ts
|
|
6830
6830
|
import { spawnSync } from "node:child_process";
|
|
@@ -7179,9 +7179,9 @@ var gitContext = (workspaceRoot, paths = []) => {
|
|
|
7179
7179
|
|
|
7180
7180
|
// packages/workit-core/src/core/workspaces.ts
|
|
7181
7181
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
7182
|
-
import { createHash as
|
|
7183
|
-
import { existsSync as existsSync4, lstatSync as
|
|
7184
|
-
import
|
|
7182
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
7183
|
+
import { existsSync as existsSync4, lstatSync as lstatSync4, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
7184
|
+
import path9 from "node:path";
|
|
7185
7185
|
|
|
7186
7186
|
// packages/workit-core/src/core/remotes.ts
|
|
7187
7187
|
import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
|
|
@@ -8368,6 +8368,172 @@ var pushTarget = (cwd, remote, replay = {}) => {
|
|
|
8368
8368
|
return { remotes };
|
|
8369
8369
|
};
|
|
8370
8370
|
|
|
8371
|
+
// packages/workit-core/src/core/grant-seal.ts
|
|
8372
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
8373
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
8374
|
+
import path8 from "node:path";
|
|
8375
|
+
|
|
8376
|
+
// packages/workit-core/src/core/safe-write.ts
|
|
8377
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
8378
|
+
import {
|
|
8379
|
+
closeSync,
|
|
8380
|
+
fchmodSync,
|
|
8381
|
+
fsyncSync,
|
|
8382
|
+
lstatSync as lstatSync3,
|
|
8383
|
+
mkdirSync as mkdirSync3,
|
|
8384
|
+
openSync,
|
|
8385
|
+
renameSync as renameSync2,
|
|
8386
|
+
unlinkSync,
|
|
8387
|
+
writeFileSync as writeFileSync3
|
|
8388
|
+
} from "node:fs";
|
|
8389
|
+
import path7 from "node:path";
|
|
8390
|
+
function writeFileAtomic(file, content, mode) {
|
|
8391
|
+
const absolute = path7.resolve(file);
|
|
8392
|
+
let parent = path7.dirname(absolute);
|
|
8393
|
+
const root = path7.parse(parent).root;
|
|
8394
|
+
for (;; ) {
|
|
8395
|
+
try {
|
|
8396
|
+
if (lstatSync3(parent).isSymbolicLink())
|
|
8397
|
+
throw new Error(`symlinked write path: ${parent}`);
|
|
8398
|
+
} catch (error) {
|
|
8399
|
+
if (error.code !== "ENOENT")
|
|
8400
|
+
throw error;
|
|
8401
|
+
}
|
|
8402
|
+
const next = path7.dirname(parent);
|
|
8403
|
+
if (parent === root || next === parent)
|
|
8404
|
+
break;
|
|
8405
|
+
parent = next;
|
|
8406
|
+
}
|
|
8407
|
+
const directory = path7.dirname(absolute);
|
|
8408
|
+
mkdirSync3(directory, { recursive: true });
|
|
8409
|
+
let existing = null;
|
|
8410
|
+
try {
|
|
8411
|
+
existing = lstatSync3(absolute);
|
|
8412
|
+
} catch (error) {
|
|
8413
|
+
if (error.code !== "ENOENT")
|
|
8414
|
+
throw error;
|
|
8415
|
+
}
|
|
8416
|
+
if (existing?.isSymbolicLink() || existing && !existing.isFile()) {
|
|
8417
|
+
throw new Error(`refusing to replace non-regular file: ${absolute}`);
|
|
8418
|
+
}
|
|
8419
|
+
const temporary = `${absolute}.${randomUUID2()}.tmp`;
|
|
8420
|
+
let fd;
|
|
8421
|
+
try {
|
|
8422
|
+
fd = openSync(temporary, "wx", mode ?? 438);
|
|
8423
|
+
writeFileSync3(fd, content, "utf8");
|
|
8424
|
+
if (existing)
|
|
8425
|
+
fchmodSync(fd, existing.mode & 511);
|
|
8426
|
+
fsyncSync(fd);
|
|
8427
|
+
closeSync(fd);
|
|
8428
|
+
fd = undefined;
|
|
8429
|
+
renameSync2(temporary, absolute);
|
|
8430
|
+
} catch (error) {
|
|
8431
|
+
if (fd !== undefined) {
|
|
8432
|
+
try {
|
|
8433
|
+
closeSync(fd);
|
|
8434
|
+
} catch {}
|
|
8435
|
+
}
|
|
8436
|
+
try {
|
|
8437
|
+
unlinkSync(temporary);
|
|
8438
|
+
} catch {}
|
|
8439
|
+
throw error;
|
|
8440
|
+
}
|
|
8441
|
+
}
|
|
8442
|
+
|
|
8443
|
+
// packages/workit-core/src/core/grant-seal.ts
|
|
8444
|
+
var SEAL_FILE = "workspaces.json.seal";
|
|
8445
|
+
var SEAL_VERSION = 2;
|
|
8446
|
+
var isSealVersion = (value) => value === 1 || value === 2;
|
|
8447
|
+
var SEAL_COMMAND = "workit workspace seal";
|
|
8448
|
+
var pick3 = (value, keys) => {
|
|
8449
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
8450
|
+
return;
|
|
8451
|
+
const out = Object.fromEntries(keys.flatMap((key) => {
|
|
8452
|
+
const item = value[key];
|
|
8453
|
+
return item === undefined ? [] : [[key, item]];
|
|
8454
|
+
}));
|
|
8455
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
8456
|
+
};
|
|
8457
|
+
var ENTRY_KEYS = [
|
|
8458
|
+
"name",
|
|
8459
|
+
"glob",
|
|
8460
|
+
"remotes",
|
|
8461
|
+
"externalRepos",
|
|
8462
|
+
"additiveRiskPaths",
|
|
8463
|
+
"vcs",
|
|
8464
|
+
"autonomy",
|
|
8465
|
+
"autoApprove",
|
|
8466
|
+
"defaultEndpoint",
|
|
8467
|
+
"verification",
|
|
8468
|
+
"youtrack"
|
|
8469
|
+
];
|
|
8470
|
+
var RELEASE_KEYS = [
|
|
8471
|
+
"releaseNotes",
|
|
8472
|
+
"releaseTagPrefix",
|
|
8473
|
+
"branchPolicy",
|
|
8474
|
+
"profiles",
|
|
8475
|
+
"defaultProfile",
|
|
8476
|
+
"releaseTracks",
|
|
8477
|
+
"releasePackages"
|
|
8478
|
+
];
|
|
8479
|
+
var keysOf = (version) => version >= 2 ? [...ENTRY_KEYS, ...RELEASE_KEYS] : ENTRY_KEYS;
|
|
8480
|
+
var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
|
|
8481
|
+
var sealProjection = (entries, version = SEAL_VERSION) => entries.map((entry) => {
|
|
8482
|
+
const keys = keysOf(version);
|
|
8483
|
+
const all = pick3(entry, keys) ?? {};
|
|
8484
|
+
return pick3({
|
|
8485
|
+
...all,
|
|
8486
|
+
vcs: pick3(all.vcs, IDENTITY_KEYS),
|
|
8487
|
+
youtrack: pick3(all.youtrack, ["writes", "autoHosts"]),
|
|
8488
|
+
...version >= 2 ? releaseLineMapping(entry, true) : {}
|
|
8489
|
+
}, keys);
|
|
8490
|
+
});
|
|
8491
|
+
var canonical3 = (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);
|
|
8492
|
+
var sealDigest = (projection) => createHash4("sha256").update(canonical3(projection)).digest("hex");
|
|
8493
|
+
var broken = (reason, sealed = null, version) => ({
|
|
8494
|
+
state: "broken",
|
|
8495
|
+
reason,
|
|
8496
|
+
sealed,
|
|
8497
|
+
...version ? { version } : {}
|
|
8498
|
+
});
|
|
8499
|
+
var PARTIAL_KEYS = ["releaseTracks", "branchPolicy", "profiles", "defaultProfile"];
|
|
8500
|
+
var sealedEntries = (projection, file) => {
|
|
8501
|
+
const partial = projection.map((entry) => pick3(entry, PARTIAL_KEYS));
|
|
8502
|
+
const validated = validateWorkspacesDocument({
|
|
8503
|
+
workspaces: projection.map((entry) => {
|
|
8504
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
8505
|
+
return entry;
|
|
8506
|
+
const rest = { ...entry };
|
|
8507
|
+
for (const key of PARTIAL_KEYS)
|
|
8508
|
+
delete rest[key];
|
|
8509
|
+
return rest;
|
|
8510
|
+
})
|
|
8511
|
+
}, file);
|
|
8512
|
+
if (validated.status !== "valid" || validated.entries.length !== projection.length)
|
|
8513
|
+
return null;
|
|
8514
|
+
return validated.entries.map((entry, at) => partial[at] === undefined ? entry : { ...entry, ...partial[at] });
|
|
8515
|
+
};
|
|
8516
|
+
function checkSeal(dir) {
|
|
8517
|
+
const file = path8.join(dir, SEAL_FILE);
|
|
8518
|
+
let seal;
|
|
8519
|
+
try {
|
|
8520
|
+
seal = JSON.parse(readFileSync4(file, "utf8"));
|
|
8521
|
+
} catch (error) {
|
|
8522
|
+
if (error.code === "ENOENT")
|
|
8523
|
+
return { state: "none" };
|
|
8524
|
+
return broken(`${SEAL_FILE} cannot be read`);
|
|
8525
|
+
}
|
|
8526
|
+
if (!isSealVersion(seal?.version) || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
|
|
8527
|
+
return broken(`${SEAL_FILE} is malformed`);
|
|
8528
|
+
const version = seal.version;
|
|
8529
|
+
const sealed = sealedEntries(seal.projection, file);
|
|
8530
|
+
if (!sealed)
|
|
8531
|
+
return broken(`${SEAL_FILE} is malformed`, null, version);
|
|
8532
|
+
const current = readWorkspacesResult(dir);
|
|
8533
|
+
const ok = current.status === "valid" || current.status === "missing";
|
|
8534
|
+
return ok && sealDigest(sealProjection(current.entries, version)) === seal.sha256 ? { state: "valid", version } : broken("workspaces.json changed since it was sealed", sealed, version);
|
|
8535
|
+
}
|
|
8536
|
+
|
|
8371
8537
|
// packages/workit-core/src/core/workspaces.ts
|
|
8372
8538
|
var nonBlank = string2().check(refine((value) => value.trim().length > 0, "must not be blank"));
|
|
8373
8539
|
var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
|
|
@@ -8433,7 +8599,7 @@ var releaseTrackSchema = looseObject({
|
|
|
8433
8599
|
});
|
|
8434
8600
|
}
|
|
8435
8601
|
}
|
|
8436
|
-
if (track.versionSource?.kind === "package-json" && (
|
|
8602
|
+
if (track.versionSource?.kind === "package-json" && (path9.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
|
|
8437
8603
|
context.addIssue({
|
|
8438
8604
|
code: "custom",
|
|
8439
8605
|
path: ["versionSource", "path"],
|
|
@@ -8532,7 +8698,7 @@ var workspacesFileSchema = looseObject({
|
|
|
8532
8698
|
names.add(workspace.name);
|
|
8533
8699
|
}
|
|
8534
8700
|
}));
|
|
8535
|
-
var workspacesRevision = (contents) =>
|
|
8701
|
+
var workspacesRevision = (contents) => createHash5("sha256").update(contents ?? "<missing>").digest("hex");
|
|
8536
8702
|
var validateWorkspacesDocument = (parsed, file) => {
|
|
8537
8703
|
if (!isConfigObject(parsed)) {
|
|
8538
8704
|
return {
|
|
@@ -8578,10 +8744,10 @@ var validateWorkspacesDocument = (parsed, file) => {
|
|
|
8578
8744
|
};
|
|
8579
8745
|
};
|
|
8580
8746
|
var readWorkspacesResult = (dir = configDir2()) => {
|
|
8581
|
-
const file =
|
|
8747
|
+
const file = path9.join(dir, "workspaces.json");
|
|
8582
8748
|
let raw;
|
|
8583
8749
|
try {
|
|
8584
|
-
raw =
|
|
8750
|
+
raw = readFileSync5(file, "utf8");
|
|
8585
8751
|
} catch (error) {
|
|
8586
8752
|
if (error.code === "ENOENT")
|
|
8587
8753
|
return {
|
|
@@ -8682,9 +8848,9 @@ var probeCheckout = (cwd) => {
|
|
|
8682
8848
|
const cached = probes.get(cwd);
|
|
8683
8849
|
if (cached !== undefined)
|
|
8684
8850
|
return cached;
|
|
8685
|
-
let dir =
|
|
8686
|
-
while (!existsSync4(
|
|
8687
|
-
if (["HEAD", "objects", "refs"].every((name) => existsSync4(
|
|
8851
|
+
let dir = path9.resolve(cwd);
|
|
8852
|
+
while (!existsSync4(path9.join(dir, ".git"))) {
|
|
8853
|
+
if (["HEAD", "objects", "refs"].every((name) => existsSync4(path9.join(dir, name)))) {
|
|
8688
8854
|
const real = realpathOf(dir);
|
|
8689
8855
|
const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
|
|
8690
8856
|
if (owner === null)
|
|
@@ -8693,7 +8859,7 @@ var probeCheckout = (cwd) => {
|
|
|
8693
8859
|
probes.set(cwd, probe);
|
|
8694
8860
|
return probe;
|
|
8695
8861
|
}
|
|
8696
|
-
const up =
|
|
8862
|
+
const up = path9.dirname(dir);
|
|
8697
8863
|
if (up === dir)
|
|
8698
8864
|
return null;
|
|
8699
8865
|
dir = up;
|
|
@@ -8722,9 +8888,9 @@ var probeCheckout = (cwd) => {
|
|
|
8722
8888
|
if (!gitDir || !common)
|
|
8723
8889
|
return failed;
|
|
8724
8890
|
let main = null;
|
|
8725
|
-
if (
|
|
8891
|
+
if (path9.resolve(gitDir) === path9.resolve(common)) {
|
|
8726
8892
|
const real = realpathOf(common);
|
|
8727
|
-
if (!ownGitDir(
|
|
8893
|
+
if (!ownGitDir(path9.join(dir, ".git"), real)) {
|
|
8728
8894
|
const owner = gitDirOwner(real);
|
|
8729
8895
|
if (owner === null)
|
|
8730
8896
|
return Error(`${cwd} uses the repository at ${real}, owned by no checkout workit can name`);
|
|
@@ -8743,7 +8909,7 @@ var probeCheckout = (cwd) => {
|
|
|
8743
8909
|
const list = git(["worktree", "list", "--porcelain"]);
|
|
8744
8910
|
if (list === null)
|
|
8745
8911
|
return failed;
|
|
8746
|
-
main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (
|
|
8912
|
+
main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path9.basename(common) === ".git" ? path9.dirname(common) : common);
|
|
8747
8913
|
}
|
|
8748
8914
|
const probe = { main, superproject: superproject || null };
|
|
8749
8915
|
probes.set(cwd, probe);
|
|
@@ -8751,7 +8917,7 @@ var probeCheckout = (cwd) => {
|
|
|
8751
8917
|
};
|
|
8752
8918
|
var ownGitDir = (dotGit, real) => {
|
|
8753
8919
|
try {
|
|
8754
|
-
return
|
|
8920
|
+
return lstatSync4(dotGit).isDirectory() && realpathOf(dotGit) === real;
|
|
8755
8921
|
} catch {
|
|
8756
8922
|
return false;
|
|
8757
8923
|
}
|
|
@@ -8760,9 +8926,9 @@ var INTERNALS = ["refs", "objects", "config", "packed-refs", "commondir"];
|
|
|
8760
8926
|
var ownInternals = (real) => {
|
|
8761
8927
|
let lender = null;
|
|
8762
8928
|
for (const name of INTERNALS) {
|
|
8763
|
-
const at =
|
|
8929
|
+
const at = path9.join(real, name);
|
|
8764
8930
|
try {
|
|
8765
|
-
|
|
8931
|
+
lstatSync4(at);
|
|
8766
8932
|
} catch {
|
|
8767
8933
|
continue;
|
|
8768
8934
|
}
|
|
@@ -8772,10 +8938,10 @@ var ownInternals = (real) => {
|
|
|
8772
8938
|
} catch {
|
|
8773
8939
|
return false;
|
|
8774
8940
|
}
|
|
8775
|
-
const rel =
|
|
8776
|
-
if (rel && !rel.startsWith("..") && !
|
|
8941
|
+
const rel = path9.relative(real, resolved);
|
|
8942
|
+
if (rel && !rel.startsWith("..") && !path9.isAbsolute(rel))
|
|
8777
8943
|
continue;
|
|
8778
|
-
const owner =
|
|
8944
|
+
const owner = path9.basename(resolved) === name ? gitDirOwner(path9.dirname(resolved)) : null;
|
|
8779
8945
|
if (owner === null || lender !== null && lender !== owner)
|
|
8780
8946
|
return false;
|
|
8781
8947
|
lender = owner;
|
|
@@ -8789,7 +8955,7 @@ var gitDirOwner = (real) => {
|
|
|
8789
8955
|
return null;
|
|
8790
8956
|
const rest = parts.slice(at + 1);
|
|
8791
8957
|
const module = rest[0] === "modules" || rest[0] === "worktrees" && rest[2] === "modules";
|
|
8792
|
-
return rest.length === 0 || module ? parts.slice(0, at).join(
|
|
8958
|
+
return rest.length === 0 || module ? parts.slice(0, at).join(path9.sep) || path9.sep : null;
|
|
8793
8959
|
};
|
|
8794
8960
|
var mainCheckoutOf = (cwd) => {
|
|
8795
8961
|
const probe = probeCheckout(cwd);
|
|
@@ -8913,11 +9079,11 @@ var resolveRuntimeWorkspaceVcs = (cwd) => resolveRuntimeWorkspaceCandidate(cwd,
|
|
|
8913
9079
|
var runtimeWorkspaceIndexSchema = looseObject({
|
|
8914
9080
|
workspaces: optional(array(looseObject({ name: nonBlank, glob: nonBlank })))
|
|
8915
9081
|
});
|
|
8916
|
-
var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
8917
|
-
const file =
|
|
9082
|
+
var matchRuntimeWorkspace = (cwd, dir = configDir2(), workspaceName = namedWorkspace()) => {
|
|
9083
|
+
const file = path9.join(dir, "workspaces.json");
|
|
8918
9084
|
let raw;
|
|
8919
9085
|
try {
|
|
8920
|
-
raw =
|
|
9086
|
+
raw = readFileSync5(file, "utf8");
|
|
8921
9087
|
} catch (error) {
|
|
8922
9088
|
if (error.code === "ENOENT")
|
|
8923
9089
|
return null;
|
|
@@ -8940,13 +9106,21 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
|
8940
9106
|
if (!glob.ok)
|
|
8941
9107
|
throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
|
|
8942
9108
|
}
|
|
8943
|
-
const
|
|
8944
|
-
|
|
9109
|
+
const matched = matchAmong(cwd, entries ?? [], workspaceName);
|
|
9110
|
+
return matched ? { file, ...matched } : null;
|
|
9111
|
+
};
|
|
9112
|
+
var namedWorkspace = () => process.env.WORKIT_WORKSPACE_NAME?.trim() || null;
|
|
9113
|
+
var matchAmong = (cwd, entries, workspaceName = namedWorkspace()) => {
|
|
9114
|
+
const selected = resolveWorkspaceFromEntries(cwd, entries, workspaceName ?? undefined, true);
|
|
8945
9115
|
if (!selected)
|
|
8946
9116
|
return null;
|
|
8947
|
-
const matches = matchingEntries(cwd, entries
|
|
8948
|
-
return {
|
|
9117
|
+
const matches = matchingEntries(cwd, entries);
|
|
9118
|
+
return { selected, matches: matches.length ? matches : [selected] };
|
|
8949
9119
|
};
|
|
9120
|
+
var chainOf = (matched) => matched ? [
|
|
9121
|
+
matched.selected,
|
|
9122
|
+
...matched.matches.filter((entry) => entry !== matched.selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob))
|
|
9123
|
+
] : [];
|
|
8950
9124
|
var resolveRuntimeReleaseTracks = (cwd) => {
|
|
8951
9125
|
const matched = matchRuntimeWorkspace(cwd);
|
|
8952
9126
|
return matched ? {
|
|
@@ -8963,11 +9137,9 @@ var inheritedSetting = (cwd, dir, has) => {
|
|
|
8963
9137
|
}
|
|
8964
9138
|
if (!matched)
|
|
8965
9139
|
return null;
|
|
8966
|
-
const { selected, matches } = matched;
|
|
8967
|
-
const enclosing = matches.filter((entry) => entry !== selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob));
|
|
8968
9140
|
return {
|
|
8969
|
-
workspace: selected.name,
|
|
8970
|
-
source:
|
|
9141
|
+
workspace: matched.selected.name,
|
|
9142
|
+
source: chainOf(matched).find(has) ?? null
|
|
8971
9143
|
};
|
|
8972
9144
|
};
|
|
8973
9145
|
var resolveRuntimeReleasePackages = (cwd, dir) => {
|
|
@@ -8997,6 +9169,47 @@ var changelogPathOf = (value) => {
|
|
|
8997
9169
|
return null;
|
|
8998
9170
|
return parts.includes("..") ? null : parts.join("/");
|
|
8999
9171
|
};
|
|
9172
|
+
var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9173
|
+
var pickSet = (value, keys) => isPlainRecord(value) ? Object.fromEntries(keys.filter((key) => value[key] !== undefined).map((key) => [key, value[key]])) : {};
|
|
9174
|
+
var mapRecord = (value, map) => Object.fromEntries(Object.entries(value).map(([name, item]) => [name, map(item)]));
|
|
9175
|
+
var TRACK_LINE_KEYS = [
|
|
9176
|
+
"tagNamespace",
|
|
9177
|
+
"productionBranch",
|
|
9178
|
+
"integrationBranch",
|
|
9179
|
+
"baseBranch",
|
|
9180
|
+
"mergeBackBranches",
|
|
9181
|
+
"pullRequestTarget",
|
|
9182
|
+
"naming",
|
|
9183
|
+
"strategy"
|
|
9184
|
+
];
|
|
9185
|
+
var releaseLineMapping = (entry, notes = false) => {
|
|
9186
|
+
if (!isPlainRecord(entry))
|
|
9187
|
+
return;
|
|
9188
|
+
const out = {};
|
|
9189
|
+
if (notes && entry.releaseNotes !== undefined)
|
|
9190
|
+
out.releaseNotes = entry.releaseNotes;
|
|
9191
|
+
if (entry.releaseTagPrefix !== undefined)
|
|
9192
|
+
out.releaseTagPrefix = entry.releaseTagPrefix;
|
|
9193
|
+
if (entry.defaultProfile !== undefined)
|
|
9194
|
+
out.defaultProfile = entry.defaultProfile;
|
|
9195
|
+
const policy = pickSet(entry.branchPolicy, ["releaseTagPrefix"]);
|
|
9196
|
+
if (Object.keys(policy).length)
|
|
9197
|
+
out.branchPolicy = policy;
|
|
9198
|
+
const profiles = Object.fromEntries(Object.entries(isPlainRecord(entry.profiles) ? entry.profiles : {}).flatMap(([name, profile]) => {
|
|
9199
|
+
const prefix = pickSet(isPlainRecord(profile) ? profile.branchPolicy : undefined, [
|
|
9200
|
+
"releaseTagPrefix"
|
|
9201
|
+
]);
|
|
9202
|
+
return Object.keys(prefix).length ? [[name, { branchPolicy: prefix }]] : [];
|
|
9203
|
+
}));
|
|
9204
|
+
if (Object.keys(profiles).length)
|
|
9205
|
+
out.profiles = profiles;
|
|
9206
|
+
const trackKeys = notes ? [...TRACK_LINE_KEYS, "releaseNotes"] : TRACK_LINE_KEYS;
|
|
9207
|
+
if (entry.releaseTracks !== undefined)
|
|
9208
|
+
out.releaseTracks = isPlainRecord(entry.releaseTracks) ? mapRecord(entry.releaseTracks, (track) => pickSet(track, trackKeys)) : entry.releaseTracks;
|
|
9209
|
+
if (entry.releasePackages !== undefined)
|
|
9210
|
+
out.releasePackages = isPlainRecord(entry.releasePackages) ? mapRecord(entry.releasePackages, (pkg) => pickSet(pkg, ["tagNamespace"])) : entry.releasePackages;
|
|
9211
|
+
return Object.keys(out).length ? out : undefined;
|
|
9212
|
+
};
|
|
9000
9213
|
var modelSources = (cwd, dir) => {
|
|
9001
9214
|
const out = [];
|
|
9002
9215
|
try {
|
|
@@ -9013,7 +9226,7 @@ var modelSources = (cwd, dir) => {
|
|
|
9013
9226
|
}
|
|
9014
9227
|
} catch {}
|
|
9015
9228
|
try {
|
|
9016
|
-
const document = JSON.parse(
|
|
9229
|
+
const document = JSON.parse(readFileSync5(path9.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
|
|
9017
9230
|
if (document && typeof document === "object" && !Array.isArray(document))
|
|
9018
9231
|
out.push({
|
|
9019
9232
|
name: "global",
|
|
@@ -9078,11 +9291,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
|
|
|
9078
9291
|
|
|
9079
9292
|
// packages/workit-core/src/core/vcs-config.ts
|
|
9080
9293
|
import fs4 from "node:fs";
|
|
9081
|
-
import
|
|
9294
|
+
import path10 from "node:path";
|
|
9082
9295
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
9083
9296
|
|
|
9084
9297
|
// packages/workit-core/src/core/release-tracks.ts
|
|
9085
|
-
import { createHash as
|
|
9298
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
9086
9299
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
9087
9300
|
class ReleaseTrackError extends Error {
|
|
9088
9301
|
}
|
|
@@ -9465,7 +9678,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
9465
9678
|
]) ?? "",
|
|
9466
9679
|
git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
|
|
9467
9680
|
] : [];
|
|
9468
|
-
key =
|
|
9681
|
+
key = createHash6("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
|
|
9469
9682
|
const hit = memo2.get(key);
|
|
9470
9683
|
if (hit)
|
|
9471
9684
|
return hit;
|
|
@@ -9480,7 +9693,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
9480
9693
|
}
|
|
9481
9694
|
|
|
9482
9695
|
// packages/workit-core/src/core/vcs-config.ts
|
|
9483
|
-
var workspacesPath = () =>
|
|
9696
|
+
var workspacesPath = () => path10.join(configDir2(), "workspaces.json");
|
|
9484
9697
|
var vcsCwd = (cwd) => cwd ?? process.env.WORKIT_WORKSPACE_ROOT ?? process.cwd();
|
|
9485
9698
|
var remoteProvider = (cwd) => {
|
|
9486
9699
|
const url = originUrl(cwd) ?? "";
|
|
@@ -9692,7 +9905,7 @@ function vcsConfig(mode, cwd, options = {}) {
|
|
|
9692
9905
|
const prov = cfg[provider] ?? {};
|
|
9693
9906
|
const out = {
|
|
9694
9907
|
ok: true,
|
|
9695
|
-
configPath:
|
|
9908
|
+
configPath: path10.resolve(cfgPath),
|
|
9696
9909
|
provider,
|
|
9697
9910
|
defaultTargetBranch: workspaceDefault,
|
|
9698
9911
|
pr: cfg.pr ?? {},
|
|
@@ -9930,7 +10143,7 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
|
|
|
9930
10143
|
const source = resolved.provenance.branchPolicy;
|
|
9931
10144
|
const allowed = branchPolicy.allowed.map((pattern) => `${pattern.source}/${pattern.flags}`).toSorted();
|
|
9932
10145
|
const protectedRefs = [...branchPolicy.protected].map((name) => name.toLowerCase()).toSorted();
|
|
9933
|
-
const fingerprint =
|
|
10146
|
+
const fingerprint = createHash7("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
|
|
9934
10147
|
return {
|
|
9935
10148
|
branchPolicy,
|
|
9936
10149
|
namePolicy: { allowed: branchPolicy.allowed, protected: branchPolicy.protected },
|
|
@@ -10066,7 +10279,7 @@ var homePattern = new RegExp(`${escapeRegExp2(os4.homedir())}(?=[/\\\\]|$)|\\$HO
|
|
|
10066
10279
|
// packages/workit-core/src/store/folder-store.ts
|
|
10067
10280
|
import fs5 from "node:fs";
|
|
10068
10281
|
import os5 from "node:os";
|
|
10069
|
-
import
|
|
10282
|
+
import path11 from "node:path";
|
|
10070
10283
|
var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
|
|
10071
10284
|
var MOVED_POINTER = "MOVED-TO-STATE.txt";
|
|
10072
10285
|
var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
|
|
@@ -10075,7 +10288,7 @@ var MARKER = "workspace.json";
|
|
|
10075
10288
|
var v2Workspace = (workit) => {
|
|
10076
10289
|
let bytes;
|
|
10077
10290
|
try {
|
|
10078
|
-
bytes = fs5.readFileSync(
|
|
10291
|
+
bytes = fs5.readFileSync(path11.join(workit, MARKER), "utf8");
|
|
10079
10292
|
} catch {
|
|
10080
10293
|
return null;
|
|
10081
10294
|
}
|
|
@@ -10124,7 +10337,7 @@ var strayEntries = (workit) => {
|
|
|
10124
10337
|
} catch {
|
|
10125
10338
|
return [];
|
|
10126
10339
|
}
|
|
10127
|
-
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(
|
|
10340
|
+
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path11.join(workit, name))) && !(name === "tasks" && onlyStubs(path11.join(workit, name))));
|
|
10128
10341
|
};
|
|
10129
10342
|
var folderStoreIo = {
|
|
10130
10343
|
rename: (from, to) => fs5.renameSync(from, to),
|
|
@@ -10132,13 +10345,13 @@ var folderStoreIo = {
|
|
|
10132
10345
|
judgedStale: () => {}
|
|
10133
10346
|
};
|
|
10134
10347
|
var tempSeq = 0;
|
|
10135
|
-
var tempBeside = (file) =>
|
|
10348
|
+
var tempBeside = (file) => path11.join(path11.dirname(file), `.${path11.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
|
|
10136
10349
|
var copyInto = (from, to) => {
|
|
10137
10350
|
const stat = fs5.lstatSync(from);
|
|
10138
10351
|
if (stat.isDirectory()) {
|
|
10139
10352
|
fs5.mkdirSync(to, { recursive: true });
|
|
10140
10353
|
for (const name of fs5.readdirSync(from))
|
|
10141
|
-
copyInto(
|
|
10354
|
+
copyInto(path11.join(from, name), path11.join(to, name));
|
|
10142
10355
|
return;
|
|
10143
10356
|
}
|
|
10144
10357
|
if (exists(to))
|
|
@@ -10189,7 +10402,7 @@ var merge2 = (from, to, rel, moved) => {
|
|
|
10189
10402
|
}
|
|
10190
10403
|
if (!isDir(from) || !isDir(to))
|
|
10191
10404
|
return [rel];
|
|
10192
|
-
const kept = fs5.readdirSync(from).flatMap((name) => merge2(
|
|
10405
|
+
const kept = fs5.readdirSync(from).flatMap((name) => merge2(path11.join(from, name), path11.join(to, name), `${rel}/${name}`, moved));
|
|
10193
10406
|
try {
|
|
10194
10407
|
if (fs5.readdirSync(from).length === 0)
|
|
10195
10408
|
fs5.rmdirSync(from);
|
|
@@ -10268,38 +10481,38 @@ var takeMoveLock = (target) => {
|
|
|
10268
10481
|
pause(25);
|
|
10269
10482
|
}
|
|
10270
10483
|
};
|
|
10271
|
-
var
|
|
10484
|
+
var canonical4 = (dir) => {
|
|
10272
10485
|
try {
|
|
10273
10486
|
return fs5.realpathSync.native(dir);
|
|
10274
10487
|
} catch {
|
|
10275
|
-
return
|
|
10488
|
+
return path11.resolve(dir);
|
|
10276
10489
|
}
|
|
10277
10490
|
};
|
|
10278
10491
|
var below = (parent, child) => {
|
|
10279
|
-
const rel =
|
|
10280
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
10492
|
+
const rel = path11.relative(parent, child);
|
|
10493
|
+
return rel !== "" && !rel.startsWith("..") && !path11.isAbsolute(rel);
|
|
10281
10494
|
};
|
|
10282
|
-
var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(
|
|
10495
|
+
var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical4(tempDir), canonical4(dir));
|
|
10283
10496
|
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
10284
10497
|
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
|
|
10285
10498
|
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
10286
10499
|
return null;
|
|
10287
|
-
const real =
|
|
10288
|
-
const tmp =
|
|
10500
|
+
const real = canonical4(folder);
|
|
10501
|
+
const tmp = canonical4(tempDir);
|
|
10289
10502
|
if (insideTempDir(folder, tempDir))
|
|
10290
10503
|
return null;
|
|
10291
|
-
return `workit test run (WORKIT_TEST_RUN): refusing to move ${
|
|
10504
|
+
return `workit test run (WORKIT_TEST_RUN): refusing to move ${path11.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)`;
|
|
10292
10505
|
};
|
|
10293
10506
|
function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
|
|
10294
10507
|
`)) {
|
|
10295
|
-
const workit =
|
|
10508
|
+
const workit = path11.join(folder, ".workit");
|
|
10296
10509
|
const names = strayEntries(workit);
|
|
10297
10510
|
const refusal = testRunFolderRefusal(folder, names.length > 0);
|
|
10298
10511
|
if (refusal) {
|
|
10299
10512
|
const run = process.env.WORKIT_TEST_RUN ?? "";
|
|
10300
|
-
if (
|
|
10513
|
+
if (path11.isAbsolute(run))
|
|
10301
10514
|
try {
|
|
10302
|
-
fs5.appendFileSync(
|
|
10515
|
+
fs5.appendFileSync(path11.join(run, TEST_RUN_REFUSALS), `${refusal}
|
|
10303
10516
|
`);
|
|
10304
10517
|
} catch {}
|
|
10305
10518
|
throw new Error(refusal);
|
|
@@ -10307,7 +10520,7 @@ function migrateFolderStore(folder, target, note = (line) => process.stderr.writ
|
|
|
10307
10520
|
if (names.length === 0 || v2Workspace(workit) === true)
|
|
10308
10521
|
return null;
|
|
10309
10522
|
try {
|
|
10310
|
-
fs5.mkdirSync(
|
|
10523
|
+
fs5.mkdirSync(path11.dirname(target), { recursive: true });
|
|
10311
10524
|
} catch {
|
|
10312
10525
|
return null;
|
|
10313
10526
|
}
|
|
@@ -10331,7 +10544,7 @@ function moveLocked(workit, target, note) {
|
|
|
10331
10544
|
}
|
|
10332
10545
|
const result = { from: workit, to: target, moved: [], kept: [] };
|
|
10333
10546
|
for (const name of names) {
|
|
10334
|
-
result.kept.push(...merge2(
|
|
10547
|
+
result.kept.push(...merge2(path11.join(workit, name), path11.join(target, name), name, result.moved));
|
|
10335
10548
|
}
|
|
10336
10549
|
const left = (() => {
|
|
10337
10550
|
try {
|
|
@@ -10340,13 +10553,13 @@ function moveLocked(workit, target, note) {
|
|
|
10340
10553
|
return [];
|
|
10341
10554
|
}
|
|
10342
10555
|
})();
|
|
10343
|
-
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(
|
|
10556
|
+
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path11.join(workit, name)));
|
|
10344
10557
|
if (!v2Left && result.kept.length === 0) {
|
|
10345
|
-
fs5.rmSync(
|
|
10346
|
-
if (generatedIgnore(
|
|
10347
|
-
fs5.rmSync(
|
|
10558
|
+
fs5.rmSync(path11.join(workit, MARKER), { force: true });
|
|
10559
|
+
if (generatedIgnore(path11.join(workit, ".gitignore")))
|
|
10560
|
+
fs5.rmSync(path11.join(workit, ".gitignore"), { force: true });
|
|
10348
10561
|
}
|
|
10349
|
-
const pointer =
|
|
10562
|
+
const pointer = path11.join(workit, MOVED_POINTER);
|
|
10350
10563
|
let wrote = false;
|
|
10351
10564
|
if (result.kept.length > 0) {
|
|
10352
10565
|
const text = `Workit keeps this folder's state in ${target}.
|
|
@@ -10373,9 +10586,9 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
|
|
|
10373
10586
|
|
|
10374
10587
|
// packages/workit-core/src/store/paths.ts
|
|
10375
10588
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
10376
|
-
import { createHash as
|
|
10589
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
10377
10590
|
import fs6 from "node:fs";
|
|
10378
|
-
import
|
|
10591
|
+
import path12 from "node:path";
|
|
10379
10592
|
var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
|
|
10380
10593
|
var gitRun = (cwd, args) => {
|
|
10381
10594
|
const run = spawnSync9("git", args, {
|
|
@@ -10400,7 +10613,7 @@ var gitRun = (cwd, args) => {
|
|
|
10400
10613
|
missing: error?.code === "ENOENT"
|
|
10401
10614
|
};
|
|
10402
10615
|
};
|
|
10403
|
-
var shortHash = (value) =>
|
|
10616
|
+
var shortHash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 12);
|
|
10404
10617
|
var real = (file) => {
|
|
10405
10618
|
try {
|
|
10406
10619
|
return fs6.realpathSync.native(file);
|
|
@@ -10417,14 +10630,14 @@ var DISCOVERY_ENV = [
|
|
|
10417
10630
|
];
|
|
10418
10631
|
var isGitDir = (dir) => {
|
|
10419
10632
|
try {
|
|
10420
|
-
return fs6.statSync(
|
|
10633
|
+
return fs6.statSync(path12.join(dir, "HEAD")).isFile() && fs6.statSync(path12.join(dir, "objects")).isDirectory() && fs6.statSync(path12.join(dir, "refs")).isDirectory();
|
|
10421
10634
|
} catch {
|
|
10422
10635
|
return false;
|
|
10423
10636
|
}
|
|
10424
10637
|
};
|
|
10425
10638
|
var reftableRefs = (common) => {
|
|
10426
10639
|
try {
|
|
10427
|
-
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(
|
|
10640
|
+
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path12.join(common, "config"), "utf8"));
|
|
10428
10641
|
} catch {
|
|
10429
10642
|
return false;
|
|
10430
10643
|
}
|
|
@@ -10444,7 +10657,7 @@ function fastGit(root) {
|
|
|
10444
10657
|
if (device !== null && stat.dev !== device)
|
|
10445
10658
|
return { kind: "none" };
|
|
10446
10659
|
device = stat.dev;
|
|
10447
|
-
const dotGit =
|
|
10660
|
+
const dotGit = path12.join(dir, ".git");
|
|
10448
10661
|
let entry = null;
|
|
10449
10662
|
try {
|
|
10450
10663
|
entry = fs6.statSync(dotGit);
|
|
@@ -10465,19 +10678,19 @@ function fastGit(root) {
|
|
|
10465
10678
|
const match = /^gitdir: (.+)$/mu.exec(text);
|
|
10466
10679
|
if (!match)
|
|
10467
10680
|
return null;
|
|
10468
|
-
gitDir =
|
|
10681
|
+
gitDir = path12.resolve(dir, match[1].trim());
|
|
10469
10682
|
} else
|
|
10470
10683
|
return null;
|
|
10471
|
-
if (!fs6.existsSync(
|
|
10684
|
+
if (!fs6.existsSync(path12.join(gitDir, "HEAD")))
|
|
10472
10685
|
return null;
|
|
10473
10686
|
} else if (isGitDir(dir))
|
|
10474
10687
|
gitDir = dir;
|
|
10475
10688
|
if (gitDir) {
|
|
10476
10689
|
let common = gitDir;
|
|
10477
10690
|
try {
|
|
10478
|
-
common =
|
|
10691
|
+
common = path12.resolve(gitDir, fs6.readFileSync(path12.join(gitDir, "commondir"), "utf8").trim());
|
|
10479
10692
|
} catch {}
|
|
10480
|
-
if (!fs6.existsSync(
|
|
10693
|
+
if (!fs6.existsSync(path12.join(common, "objects")))
|
|
10481
10694
|
return null;
|
|
10482
10695
|
return {
|
|
10483
10696
|
kind: "repo",
|
|
@@ -10487,7 +10700,7 @@ function fastGit(root) {
|
|
|
10487
10700
|
reftable: reftableRefs(common)
|
|
10488
10701
|
};
|
|
10489
10702
|
}
|
|
10490
|
-
const parent =
|
|
10703
|
+
const parent = path12.dirname(dir);
|
|
10491
10704
|
if (parent === dir)
|
|
10492
10705
|
return { kind: "none" };
|
|
10493
10706
|
dir = parent;
|
|
@@ -10499,7 +10712,7 @@ var outsideGit = (root) => {
|
|
|
10499
10712
|
return { dir, shared: false, top: null };
|
|
10500
10713
|
};
|
|
10501
10714
|
function resolveStore(root) {
|
|
10502
|
-
root =
|
|
10715
|
+
root = path12.resolve(root);
|
|
10503
10716
|
let stat = null;
|
|
10504
10717
|
try {
|
|
10505
10718
|
stat = fs6.statSync(root);
|
|
@@ -10507,13 +10720,13 @@ function resolveStore(root) {
|
|
|
10507
10720
|
if (!stat)
|
|
10508
10721
|
return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
|
|
10509
10722
|
if (!stat.isDirectory())
|
|
10510
|
-
return { dir:
|
|
10723
|
+
return { dir: path12.join(root, ".workit"), shared: false, top: null };
|
|
10511
10724
|
const fast = fastGit(root);
|
|
10512
10725
|
if (fast?.kind === "none")
|
|
10513
10726
|
return outsideGit(root);
|
|
10514
10727
|
if (fast?.kind === "repo")
|
|
10515
10728
|
return {
|
|
10516
|
-
dir:
|
|
10729
|
+
dir: path12.join(fast.common, "workit"),
|
|
10517
10730
|
shared: true,
|
|
10518
10731
|
top: fast.top,
|
|
10519
10732
|
git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
|
|
@@ -10523,7 +10736,7 @@ function resolveStore(root) {
|
|
|
10523
10736
|
if (run.ok && common) {
|
|
10524
10737
|
const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
|
|
10525
10738
|
return {
|
|
10526
|
-
dir:
|
|
10739
|
+
dir: path12.join(real(path12.resolve(root, common)), "workit"),
|
|
10527
10740
|
shared: true,
|
|
10528
10741
|
top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
|
|
10529
10742
|
};
|
|
@@ -10536,7 +10749,7 @@ function resolveStore(root) {
|
|
|
10536
10749
|
var rebasingBranch = (gitDir) => {
|
|
10537
10750
|
for (const state of ["rebase-merge", "rebase-apply"]) {
|
|
10538
10751
|
try {
|
|
10539
|
-
const ref = fs6.readFileSync(
|
|
10752
|
+
const ref = fs6.readFileSync(path12.join(gitDir, state, "head-name"), "utf8").trim();
|
|
10540
10753
|
const match = /^refs\/heads\/(.+)$/u.exec(ref);
|
|
10541
10754
|
if (match)
|
|
10542
10755
|
return match[1];
|
|
@@ -10551,7 +10764,7 @@ function resolveTaskKey(root, location) {
|
|
|
10551
10764
|
if (location.git && !location.git.reftable) {
|
|
10552
10765
|
let head = "";
|
|
10553
10766
|
try {
|
|
10554
|
-
head = fs6.readFileSync(
|
|
10767
|
+
head = fs6.readFileSync(path12.join(location.git.gitDir, "HEAD"), "utf8").trim();
|
|
10555
10768
|
} catch {}
|
|
10556
10769
|
const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
|
|
10557
10770
|
if (ref && ref[1] !== ".invalid")
|
|
@@ -10582,7 +10795,7 @@ function resolveTaskKey(root, location) {
|
|
|
10582
10795
|
return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
|
|
10583
10796
|
}
|
|
10584
10797
|
function checkoutRootOf(root, location) {
|
|
10585
|
-
const resolved =
|
|
10798
|
+
const resolved = path12.resolve(root);
|
|
10586
10799
|
let canonical = resolved;
|
|
10587
10800
|
try {
|
|
10588
10801
|
canonical = fs6.realpathSync(resolved);
|
|
@@ -10613,13 +10826,13 @@ function branchRenames(location) {
|
|
|
10613
10826
|
}
|
|
10614
10827
|
for (const entry of entries)
|
|
10615
10828
|
if (entry.isDirectory())
|
|
10616
|
-
walk(
|
|
10829
|
+
walk(path12.join(dir, entry.name));
|
|
10617
10830
|
else
|
|
10618
|
-
files.push(
|
|
10831
|
+
files.push(path12.join(dir, entry.name));
|
|
10619
10832
|
};
|
|
10620
|
-
walk(
|
|
10833
|
+
walk(path12.join(path12.dirname(location.dir), "logs", "refs", "heads"));
|
|
10621
10834
|
if (location.git)
|
|
10622
|
-
files.push(
|
|
10835
|
+
files.push(path12.join(location.git.gitDir, "logs", "HEAD"));
|
|
10623
10836
|
const seen = new Set;
|
|
10624
10837
|
const renames = [];
|
|
10625
10838
|
for (const file of files) {
|
|
@@ -10687,13 +10900,13 @@ function hostSessionFromEnv(env) {
|
|
|
10687
10900
|
}
|
|
10688
10901
|
var ISSUED_PER_LEAD = 64;
|
|
10689
10902
|
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
|
|
10690
|
-
var hash = (value) =>
|
|
10903
|
+
var hash = (value) => createHash9("sha256").update(value).digest("hex").slice(0, 32);
|
|
10691
10904
|
var PIN_FILE = "issued-registry";
|
|
10692
10905
|
var pinFiles = new Map;
|
|
10693
10906
|
var pinFile = (cwd) => {
|
|
10694
10907
|
if (cwd === undefined)
|
|
10695
10908
|
return null;
|
|
10696
|
-
const key =
|
|
10909
|
+
const key = path13.resolve(cwd);
|
|
10697
10910
|
const known = pinFiles.get(key);
|
|
10698
10911
|
if (known !== undefined)
|
|
10699
10912
|
return known;
|
|
@@ -10701,7 +10914,7 @@ var pinFile = (cwd) => {
|
|
|
10701
10914
|
const location = resolveStore(key);
|
|
10702
10915
|
if (location instanceof Error)
|
|
10703
10916
|
return null;
|
|
10704
|
-
const file = location.shared ?
|
|
10917
|
+
const file = location.shared ? path13.join(location.dir, "ledger", PIN_FILE) : null;
|
|
10705
10918
|
pinFiles.set(key, file);
|
|
10706
10919
|
return file;
|
|
10707
10920
|
} catch {
|
|
@@ -10714,32 +10927,32 @@ var pinnedStateDir = (cwd) => {
|
|
|
10714
10927
|
return null;
|
|
10715
10928
|
try {
|
|
10716
10929
|
const pinned = fs7.readFileSync(file, "utf8").trim();
|
|
10717
|
-
return
|
|
10930
|
+
return path13.isAbsolute(pinned) ? pinned : null;
|
|
10718
10931
|
} catch {
|
|
10719
10932
|
return null;
|
|
10720
10933
|
}
|
|
10721
10934
|
};
|
|
10722
10935
|
var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
|
|
10723
|
-
var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(
|
|
10936
|
+
var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path13.dirname(path13.dirname(path13.dirname(file))));
|
|
10724
10937
|
function pinIssuedRegistry(cwd) {
|
|
10725
10938
|
const file = pinFile(cwd);
|
|
10726
10939
|
if (file === null)
|
|
10727
10940
|
return;
|
|
10728
|
-
const state =
|
|
10941
|
+
const state = path13.resolve(resolveStateDir());
|
|
10729
10942
|
if (pinnedStateDir(cwd) === state)
|
|
10730
10943
|
return;
|
|
10731
10944
|
if (testRunSkipsPin(file))
|
|
10732
10945
|
return;
|
|
10733
10946
|
try {
|
|
10734
|
-
fs7.mkdirSync(
|
|
10947
|
+
fs7.mkdirSync(path13.dirname(file), { recursive: true });
|
|
10735
10948
|
const temp = `${file}.${process.pid}.tmp`;
|
|
10736
10949
|
fs7.writeFileSync(temp, `${state}
|
|
10737
10950
|
`, { mode: 420 });
|
|
10738
10951
|
fs7.renameSync(temp, file);
|
|
10739
10952
|
} catch {}
|
|
10740
10953
|
}
|
|
10741
|
-
var userIssuedRoot = (cwd) =>
|
|
10742
|
-
var userTokenRoot = (cwd) =>
|
|
10954
|
+
var userIssuedRoot = (cwd) => path13.join(registryDir(cwd), "issued");
|
|
10955
|
+
var userTokenRoot = (cwd) => path13.join(registryDir(cwd), "issued-tokens");
|
|
10743
10956
|
function migrateRepoIssued(cwd) {
|
|
10744
10957
|
if (cwd === undefined)
|
|
10745
10958
|
return;
|
|
@@ -10748,7 +10961,7 @@ function migrateRepoIssued(cwd) {
|
|
|
10748
10961
|
const location = resolveStore(cwd);
|
|
10749
10962
|
if (location instanceof Error)
|
|
10750
10963
|
return;
|
|
10751
|
-
old =
|
|
10964
|
+
old = path13.join(location.dir, "hooks", "issued");
|
|
10752
10965
|
if (!fs7.existsSync(old))
|
|
10753
10966
|
return;
|
|
10754
10967
|
} catch {
|
|
@@ -10756,19 +10969,19 @@ function migrateRepoIssued(cwd) {
|
|
|
10756
10969
|
}
|
|
10757
10970
|
for (const lead of safeList(old)) {
|
|
10758
10971
|
try {
|
|
10759
|
-
const from =
|
|
10972
|
+
const from = path13.join(old, lead);
|
|
10760
10973
|
if (!fs7.statSync(from).isDirectory())
|
|
10761
10974
|
continue;
|
|
10762
|
-
const to =
|
|
10975
|
+
const to = path13.join(userIssuedRoot(cwd), lead);
|
|
10763
10976
|
fs7.mkdirSync(to, { recursive: true, mode: 448 });
|
|
10764
10977
|
for (const id of fs7.readdirSync(from)) {
|
|
10765
10978
|
try {
|
|
10766
|
-
fs7.copyFileSync(
|
|
10979
|
+
fs7.copyFileSync(path13.join(from, id), path13.join(to, id), fs7.constants.COPYFILE_EXCL);
|
|
10767
10980
|
} catch (error) {
|
|
10768
10981
|
if (error.code !== "EEXIST")
|
|
10769
10982
|
throw error;
|
|
10770
10983
|
}
|
|
10771
|
-
fs7.rmSync(
|
|
10984
|
+
fs7.rmSync(path13.join(from, id), { force: true });
|
|
10772
10985
|
}
|
|
10773
10986
|
removeIfEmpty(from);
|
|
10774
10987
|
} catch {}
|
|
@@ -10787,7 +11000,7 @@ var removeIfEmpty = (dir) => {
|
|
|
10787
11000
|
fs7.rmdirSync(dir);
|
|
10788
11001
|
} catch {}
|
|
10789
11002
|
};
|
|
10790
|
-
var tokenHash = (token) =>
|
|
11003
|
+
var tokenHash = (token) => createHash9("sha256").update(token).digest("hex");
|
|
10791
11004
|
function recordIssuedSession(cwd, lead, issued) {
|
|
10792
11005
|
const token = randomBytes(18).toString("hex");
|
|
10793
11006
|
try {
|
|
@@ -10795,13 +11008,13 @@ function recordIssuedSession(cwd, lead, issued) {
|
|
|
10795
11008
|
migrateRepoIssued(cwd);
|
|
10796
11009
|
const own = hash(issued);
|
|
10797
11010
|
const state = resolveStateDir();
|
|
10798
|
-
const tokens =
|
|
11011
|
+
const tokens = path13.join(state, "issued-tokens", hash(lead));
|
|
10799
11012
|
fs7.mkdirSync(tokens, { recursive: true, mode: 448 });
|
|
10800
|
-
fs7.writeFileSync(
|
|
11013
|
+
fs7.writeFileSync(path13.join(tokens, own), `${tokenHash(token)}
|
|
10801
11014
|
`, { mode: 384, flag: "wx" });
|
|
10802
|
-
const dir =
|
|
11015
|
+
const dir = path13.join(state, "issued", hash(lead));
|
|
10803
11016
|
fs7.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
10804
|
-
fs7.writeFileSync(
|
|
11017
|
+
fs7.writeFileSync(path13.join(dir, own), `${ISSUED_SESSIONS_MARKER}
|
|
10805
11018
|
`, { mode: 384 });
|
|
10806
11019
|
pruneIssued(dir, own, tokens);
|
|
10807
11020
|
return token;
|
|
@@ -10831,10 +11044,10 @@ function pruneIssued(dir, own, tokens) {
|
|
|
10831
11044
|
const entries = fs7.readdirSync(dir);
|
|
10832
11045
|
if (entries.length <= ISSUED_PER_LEAD)
|
|
10833
11046
|
return;
|
|
10834
|
-
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs7.statSync(
|
|
11047
|
+
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs7.statSync(path13.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
|
|
10835
11048
|
for (const { name } of byAge.slice(0, entries.length - ISSUED_PER_LEAD)) {
|
|
10836
|
-
fs7.rmSync(
|
|
10837
|
-
fs7.rmSync(
|
|
11049
|
+
fs7.rmSync(path13.join(dir, name), { force: true });
|
|
11050
|
+
fs7.rmSync(path13.join(tokens, name), { force: true });
|
|
10838
11051
|
}
|
|
10839
11052
|
} catch {}
|
|
10840
11053
|
}
|
|
@@ -10844,7 +11057,7 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
10844
11057
|
return null;
|
|
10845
11058
|
migrateRepoIssued(cwd);
|
|
10846
11059
|
try {
|
|
10847
|
-
return fs7.readFileSync(
|
|
11060
|
+
return fs7.readFileSync(path13.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
10848
11061
|
} catch {
|
|
10849
11062
|
return null;
|
|
10850
11063
|
}
|
|
@@ -10854,9 +11067,9 @@ var issuedToken = (cwd, claimed) => {
|
|
|
10854
11067
|
const cut = claimed.lastIndexOf(":");
|
|
10855
11068
|
if (cut <= 0)
|
|
10856
11069
|
return { stored: null, leadBound: false };
|
|
10857
|
-
const dir =
|
|
11070
|
+
const dir = path13.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
|
|
10858
11071
|
try {
|
|
10859
|
-
const text = fs7.readFileSync(
|
|
11072
|
+
const text = fs7.readFileSync(path13.join(dir, hash(claimed)), "utf8");
|
|
10860
11073
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
10861
11074
|
} catch {
|
|
10862
11075
|
return { stored: null, leadBound: safeList(dir).length > 0 };
|
|
@@ -10880,9 +11093,9 @@ function childSessionId(lead, child) {
|
|
|
10880
11093
|
}
|
|
10881
11094
|
|
|
10882
11095
|
// packages/workit-core/src/store/event-log.ts
|
|
10883
|
-
import { randomUUID as
|
|
11096
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
10884
11097
|
import fs8 from "node:fs";
|
|
10885
|
-
import
|
|
11098
|
+
import path14 from "node:path";
|
|
10886
11099
|
var EVENT_VERSION = 1;
|
|
10887
11100
|
|
|
10888
11101
|
class LogDamage extends Error {
|
|
@@ -10993,11 +11206,11 @@ function appendEvent(file, event, validEnd) {
|
|
|
10993
11206
|
fs8.closeSync(fd);
|
|
10994
11207
|
}
|
|
10995
11208
|
if (created)
|
|
10996
|
-
fsyncDirectory(
|
|
11209
|
+
fsyncDirectory(path14.dirname(file));
|
|
10997
11210
|
return validEnd;
|
|
10998
11211
|
}
|
|
10999
11212
|
function replaceFile(file, bytes, durable) {
|
|
11000
|
-
const temporary = `${file}.${process.pid}.${
|
|
11213
|
+
const temporary = `${file}.${process.pid}.${randomUUID3()}.tmp`;
|
|
11001
11214
|
try {
|
|
11002
11215
|
const fd = fs8.openSync(temporary, "wx", 384);
|
|
11003
11216
|
try {
|
|
@@ -11009,7 +11222,7 @@ function replaceFile(file, bytes, durable) {
|
|
|
11009
11222
|
}
|
|
11010
11223
|
renameWithRetry(temporary, file);
|
|
11011
11224
|
if (durable)
|
|
11012
|
-
fsyncDirectory(
|
|
11225
|
+
fsyncDirectory(path14.dirname(file));
|
|
11013
11226
|
} catch (error) {
|
|
11014
11227
|
try {
|
|
11015
11228
|
fs8.unlinkSync(temporary);
|
|
@@ -11166,7 +11379,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
|
|
|
11166
11379
|
});
|
|
11167
11380
|
|
|
11168
11381
|
// packages/workit-core/src/store/reduce.ts
|
|
11169
|
-
import { createHash as
|
|
11382
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
11170
11383
|
var OPENING_TYPES = new Set([
|
|
11171
11384
|
"task.opened",
|
|
11172
11385
|
"task.imported",
|
|
@@ -11195,7 +11408,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
11195
11408
|
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");
|
|
11196
11409
|
var BLOB_REF = "$blob";
|
|
11197
11410
|
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;
|
|
11198
|
-
var blobDigest = (value) =>
|
|
11411
|
+
var blobDigest = (value) => createHash10("sha256").update(JSON.stringify(value)).digest("hex");
|
|
11199
11412
|
var toBlob = (value, blobs) => {
|
|
11200
11413
|
if (!isObject4(value))
|
|
11201
11414
|
return value;
|
|
@@ -11308,9 +11521,9 @@ var reportMigration = (report) => {
|
|
|
11308
11521
|
var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
|
|
11309
11522
|
|
|
11310
11523
|
// packages/workit-core/src/core/task-read.ts
|
|
11311
|
-
import { randomUUID as
|
|
11524
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
11312
11525
|
import * as fs13 from "node:fs";
|
|
11313
|
-
import
|
|
11526
|
+
import path18 from "node:path";
|
|
11314
11527
|
|
|
11315
11528
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
11316
11529
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -11361,7 +11574,7 @@ function sameFileIdentity(left, right, platform = process.platform) {
|
|
|
11361
11574
|
// node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
|
|
11362
11575
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
11363
11576
|
import fsSync from "node:fs";
|
|
11364
|
-
import
|
|
11577
|
+
import path15 from "node:path";
|
|
11365
11578
|
|
|
11366
11579
|
// node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
11367
11580
|
import fs9 from "node:fs";
|
|
@@ -11451,13 +11664,13 @@ ${ownershipToken}
|
|
|
11451
11664
|
return { raw, ownershipToken };
|
|
11452
11665
|
}
|
|
11453
11666
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
11454
|
-
const resolved =
|
|
11455
|
-
const lexicalRelative =
|
|
11456
|
-
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${
|
|
11457
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
11667
|
+
const resolved = path15.resolve(lockPath);
|
|
11668
|
+
const lexicalRelative = path15.relative(lockRoot.rootDir, resolved);
|
|
11669
|
+
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path15.sep}`) && !path15.isAbsolute(lexicalRelative) ? lexicalRelative : path15.relative(lockRoot.rootReal, resolved);
|
|
11670
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path15.sep}`) || path15.isAbsolute(relative)) {
|
|
11458
11671
|
throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
|
|
11459
11672
|
}
|
|
11460
|
-
return relative.split(
|
|
11673
|
+
return relative.split(path15.sep).join(path15.posix.sep);
|
|
11461
11674
|
}
|
|
11462
11675
|
function parseSidecarLockPayload(raw, parser) {
|
|
11463
11676
|
if (parser) {
|
|
@@ -11604,7 +11817,7 @@ function getFsSafeLockConfig() {
|
|
|
11604
11817
|
|
|
11605
11818
|
// node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
|
|
11606
11819
|
import fs11 from "node:fs";
|
|
11607
|
-
import
|
|
11820
|
+
import path16 from "node:path";
|
|
11608
11821
|
|
|
11609
11822
|
// node_modules/@openclaw/fs-safe/dist/timing.js
|
|
11610
11823
|
function sleepSync(ms) {
|
|
@@ -11695,26 +11908,26 @@ function canonicalLockParentSync(parent) {
|
|
|
11695
11908
|
return process.platform === "win32" ? fs11.realpathSync.native(parent) : fs11.realpathSync(parent);
|
|
11696
11909
|
}
|
|
11697
11910
|
function normalizeTargetPath(targetPath) {
|
|
11698
|
-
const resolved =
|
|
11699
|
-
fs11.mkdirSync(
|
|
11911
|
+
const resolved = path16.resolve(targetPath);
|
|
11912
|
+
fs11.mkdirSync(path16.dirname(resolved), { recursive: true });
|
|
11700
11913
|
try {
|
|
11701
|
-
return
|
|
11914
|
+
return path16.join(canonicalLockParentSync(path16.dirname(resolved)), path16.basename(resolved));
|
|
11702
11915
|
} catch {
|
|
11703
11916
|
return resolved;
|
|
11704
11917
|
}
|
|
11705
11918
|
}
|
|
11706
11919
|
function boundedLockPath(lockPath, lockRoot) {
|
|
11707
|
-
const resolved =
|
|
11920
|
+
const resolved = path16.resolve(lockPath);
|
|
11708
11921
|
if (!lockRoot)
|
|
11709
11922
|
return resolved;
|
|
11710
11923
|
relativeSidecarLockPath(lockRoot, resolved);
|
|
11711
|
-
const parent =
|
|
11924
|
+
const parent = path16.dirname(resolved);
|
|
11712
11925
|
const parentReal = canonicalLockParentSync(parent);
|
|
11713
|
-
const parentRelative =
|
|
11714
|
-
if (parentRelative === ".." || parentRelative.startsWith(`..${
|
|
11926
|
+
const parentRelative = path16.relative(lockRoot.rootReal, parentReal);
|
|
11927
|
+
if (parentRelative === ".." || parentRelative.startsWith(`..${path16.sep}`) || path16.isAbsolute(parentRelative)) {
|
|
11715
11928
|
throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
|
|
11716
11929
|
}
|
|
11717
|
-
return
|
|
11930
|
+
return path16.join(parentReal, path16.basename(resolved));
|
|
11718
11931
|
}
|
|
11719
11932
|
function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
11720
11933
|
const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
|
|
@@ -11915,20 +12128,20 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
11915
12128
|
}
|
|
11916
12129
|
// packages/workit-core/src/core/package-root.ts
|
|
11917
12130
|
import { existsSync as existsSync5 } from "node:fs";
|
|
11918
|
-
import
|
|
12131
|
+
import path17 from "node:path";
|
|
11919
12132
|
import { fileURLToPath } from "node:url";
|
|
11920
12133
|
var packageRoot = () => {
|
|
11921
|
-
let dir =
|
|
12134
|
+
let dir = path17.dirname(fileURLToPath(import.meta.url));
|
|
11922
12135
|
while (true) {
|
|
11923
|
-
const parent =
|
|
11924
|
-
if (existsSync5(
|
|
12136
|
+
const parent = path17.dirname(dir);
|
|
12137
|
+
if (existsSync5(path17.join(dir, "package.json")) || parent === dir)
|
|
11925
12138
|
return dir;
|
|
11926
12139
|
dir = parent;
|
|
11927
12140
|
}
|
|
11928
12141
|
};
|
|
11929
12142
|
var assetRoot = () => {
|
|
11930
12143
|
const root = packageRoot();
|
|
11931
|
-
const assets =
|
|
12144
|
+
const assets = path17.join(root, "assets");
|
|
11932
12145
|
return existsSync5(assets) ? assets : root;
|
|
11933
12146
|
};
|
|
11934
12147
|
|
|
@@ -12136,7 +12349,7 @@ var cachedRuntimeVersion = null;
|
|
|
12136
12349
|
var runtimeVersion = () => {
|
|
12137
12350
|
if (cachedRuntimeVersion === null) {
|
|
12138
12351
|
try {
|
|
12139
|
-
const pkg = JSON.parse(fs13.readFileSync(
|
|
12352
|
+
const pkg = JSON.parse(fs13.readFileSync(path18.join(packageRoot(), "package.json"), "utf8"));
|
|
12140
12353
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
12141
12354
|
} catch {
|
|
12142
12355
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -12165,7 +12378,7 @@ var readText2 = (file) => {
|
|
|
12165
12378
|
};
|
|
12166
12379
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
12167
12380
|
var branchStart = (location, branch, aliases) => {
|
|
12168
|
-
const first = readText2(
|
|
12381
|
+
const first = readText2(path18.join(path18.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
12169
12382
|
`, 1)[0];
|
|
12170
12383
|
const created = REFLOG_LINE.exec(first);
|
|
12171
12384
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -12175,7 +12388,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
12175
12388
|
return start;
|
|
12176
12389
|
if (!location.git)
|
|
12177
12390
|
return null;
|
|
12178
|
-
for (const line of readText2(
|
|
12391
|
+
for (const line of readText2(path18.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
12179
12392
|
`)) {
|
|
12180
12393
|
const entry = REFLOG_LINE.exec(line);
|
|
12181
12394
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -12185,14 +12398,14 @@ var branchStart = (location, branch, aliases) => {
|
|
|
12185
12398
|
}
|
|
12186
12399
|
return null;
|
|
12187
12400
|
};
|
|
12188
|
-
var refExists2 = (common, ref) => fs13.existsSync(
|
|
12401
|
+
var refExists2 = (common, ref) => fs13.existsSync(path18.join(common, ref)) || readText2(path18.join(common, "packed-refs")).includes(` ${ref}
|
|
12189
12402
|
`);
|
|
12190
12403
|
var origins = new Map;
|
|
12191
12404
|
var sameDirectoryIdentity = (left, right) => {
|
|
12192
|
-
if (!
|
|
12405
|
+
if (!path18.isAbsolute(left) || !path18.isAbsolute(right))
|
|
12193
12406
|
return false;
|
|
12194
|
-
const normalizedLeft =
|
|
12195
|
-
const normalizedRight =
|
|
12407
|
+
const normalizedLeft = path18.resolve(left);
|
|
12408
|
+
const normalizedRight = path18.resolve(right);
|
|
12196
12409
|
try {
|
|
12197
12410
|
const a = fs13.statSync(normalizedLeft, { bigint: true });
|
|
12198
12411
|
const b = fs13.statSync(normalizedRight, { bigint: true });
|
|
@@ -12226,14 +12439,14 @@ class TaskReader {
|
|
|
12226
12439
|
located;
|
|
12227
12440
|
migrationChecked = false;
|
|
12228
12441
|
constructor(root, options = {}) {
|
|
12229
|
-
const resolved =
|
|
12442
|
+
const resolved = path18.resolve(root);
|
|
12230
12443
|
this.origin = fs13.existsSync(resolved) ? fs13.realpathSync(resolved) : resolved;
|
|
12231
12444
|
this.located = resolveStore(this.origin);
|
|
12232
12445
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
12233
12446
|
this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
|
|
12234
12447
|
}
|
|
12235
12448
|
location() {
|
|
12236
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(
|
|
12449
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path18.join(this.root, ".git"))) {
|
|
12237
12450
|
this.located = undefined;
|
|
12238
12451
|
this.migrationChecked = false;
|
|
12239
12452
|
}
|
|
@@ -12391,14 +12604,14 @@ class TaskReader {
|
|
|
12391
12604
|
const branch = key.ok ? key.data.branch : null;
|
|
12392
12605
|
if (!branch || !location.ok)
|
|
12393
12606
|
return success(null, null, null);
|
|
12394
|
-
const common =
|
|
12395
|
-
const heads =
|
|
12396
|
-
const headLog = location.data.git ?
|
|
12607
|
+
const common = path18.dirname(location.data.dir);
|
|
12608
|
+
const heads = path18.join(common, "logs", "refs", "heads");
|
|
12609
|
+
const headLog = location.data.git ? path18.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
12397
12610
|
const signatures = [
|
|
12398
|
-
|
|
12611
|
+
path18.join(heads, branch),
|
|
12399
12612
|
headLog,
|
|
12400
12613
|
heads,
|
|
12401
|
-
|
|
12614
|
+
path18.join(common, "packed-refs")
|
|
12402
12615
|
].map((file) => fileSignature(file) ?? "-");
|
|
12403
12616
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
12404
12617
|
let resolved = origins.get(slot);
|
|
@@ -12410,7 +12623,7 @@ class TaskReader {
|
|
|
12410
12623
|
aliases.push(rename.from);
|
|
12411
12624
|
const start = branchStart(location.data, branch, aliases);
|
|
12412
12625
|
const slash = start?.indexOf("/") ?? -1;
|
|
12413
|
-
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(
|
|
12626
|
+
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path18.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
|
|
12414
12627
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
12415
12628
|
resolved = {
|
|
12416
12629
|
signature: signatures.join("|"),
|
|
@@ -12430,27 +12643,27 @@ class TaskReader {
|
|
|
12430
12643
|
}
|
|
12431
12644
|
paths() {
|
|
12432
12645
|
const location = this.location();
|
|
12433
|
-
const dir = location.ok ? location.data.dir :
|
|
12434
|
-
const checkout =
|
|
12646
|
+
const dir = location.ok ? location.data.dir : path18.join(this.root, ".workit");
|
|
12647
|
+
const checkout = path18.join(dir, "checkouts", checkoutSlug(this.root));
|
|
12435
12648
|
return {
|
|
12436
12649
|
dir,
|
|
12437
12650
|
shared: location.ok ? location.data.shared : false,
|
|
12438
|
-
marker:
|
|
12651
|
+
marker: path18.join(dir, "store.json"),
|
|
12439
12652
|
checkout,
|
|
12440
|
-
workspace:
|
|
12441
|
-
checkoutLock:
|
|
12442
|
-
tasks:
|
|
12443
|
-
index:
|
|
12444
|
-
blobs:
|
|
12445
|
-
legacy:
|
|
12446
|
-
v2:
|
|
12653
|
+
workspace: path18.join(checkout, "workspace.json"),
|
|
12654
|
+
checkoutLock: path18.join(checkout, "metadata.lock"),
|
|
12655
|
+
tasks: path18.join(dir, "tasks"),
|
|
12656
|
+
index: path18.join(dir, "task-index.json"),
|
|
12657
|
+
blobs: path18.join(dir, "blobs", "candidates"),
|
|
12658
|
+
legacy: path18.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
12659
|
+
v2: path18.join(this.root, ".workit")
|
|
12447
12660
|
};
|
|
12448
12661
|
}
|
|
12449
12662
|
eventsPath(taskId) {
|
|
12450
|
-
return
|
|
12663
|
+
return path18.join(this.paths().tasks, taskId, "events.jsonl");
|
|
12451
12664
|
}
|
|
12452
12665
|
snapshotPath(taskId) {
|
|
12453
|
-
return
|
|
12666
|
+
return path18.join(this.paths().tasks, taskId, "snapshot.json");
|
|
12454
12667
|
}
|
|
12455
12668
|
ready(write = false) {
|
|
12456
12669
|
const location = this.location();
|
|
@@ -12485,7 +12698,7 @@ class TaskReader {
|
|
|
12485
12698
|
return {
|
|
12486
12699
|
read: (digest) => {
|
|
12487
12700
|
try {
|
|
12488
|
-
return JSON.parse(fs13.readFileSync(
|
|
12701
|
+
return JSON.parse(fs13.readFileSync(path18.join(dir, `${digest}.json`), "utf8"));
|
|
12489
12702
|
} catch (error) {
|
|
12490
12703
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
12491
12704
|
}
|
|
@@ -12651,11 +12864,11 @@ class TaskReader {
|
|
|
12651
12864
|
return failure2("recovery_required", `${label} record does not satisfy its schema`);
|
|
12652
12865
|
}
|
|
12653
12866
|
v2Dirs() {
|
|
12654
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
12867
|
+
return [...new Set([this.root, this.origin])].map((dir) => path18.join(dir, ".workit"));
|
|
12655
12868
|
}
|
|
12656
12869
|
pendingMigrations() {
|
|
12657
12870
|
return this.v2Dirs().filter((dir) => {
|
|
12658
|
-
const raw = this.readV2Workspace(
|
|
12871
|
+
const raw = this.readV2Workspace(path18.join(dir, "workspace.json"));
|
|
12659
12872
|
return raw !== null && raw !== TOMBSTONE;
|
|
12660
12873
|
});
|
|
12661
12874
|
}
|
|
@@ -12671,7 +12884,7 @@ class TaskReader {
|
|
|
12671
12884
|
}
|
|
12672
12885
|
adoptStoreFrom(local) {
|
|
12673
12886
|
const dirs = this.paths();
|
|
12674
|
-
const marker =
|
|
12887
|
+
const marker = path18.join(local, "store.json");
|
|
12675
12888
|
if (!fs13.existsSync(marker))
|
|
12676
12889
|
return success(null, null, null);
|
|
12677
12890
|
return this.withLock(dirs.checkoutLock, () => {
|
|
@@ -12681,7 +12894,7 @@ class TaskReader {
|
|
|
12681
12894
|
try {
|
|
12682
12895
|
const merge = (from, to) => {
|
|
12683
12896
|
if (!fs13.existsSync(to)) {
|
|
12684
|
-
fs13.mkdirSync(
|
|
12897
|
+
fs13.mkdirSync(path18.dirname(to), { recursive: true });
|
|
12685
12898
|
try {
|
|
12686
12899
|
fs13.renameSync(from, to);
|
|
12687
12900
|
} catch {
|
|
@@ -12692,24 +12905,24 @@ class TaskReader {
|
|
|
12692
12905
|
}
|
|
12693
12906
|
if (fs13.lstatSync(from).isDirectory() && fs13.lstatSync(to).isDirectory())
|
|
12694
12907
|
for (const name of fs13.readdirSync(from))
|
|
12695
|
-
merge(
|
|
12908
|
+
merge(path18.join(from, name), path18.join(to, name));
|
|
12696
12909
|
};
|
|
12697
12910
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
12698
|
-
const from =
|
|
12911
|
+
const from = path18.join(local, sub);
|
|
12699
12912
|
if (!fs13.existsSync(from))
|
|
12700
12913
|
continue;
|
|
12701
12914
|
if (sub === "tasks") {
|
|
12702
12915
|
for (const name of fs13.readdirSync(from))
|
|
12703
|
-
if (validId(name) && !fs13.existsSync(
|
|
12916
|
+
if (validId(name) && !fs13.existsSync(path18.join(dirs.dir, sub, name)))
|
|
12704
12917
|
tasks += 1;
|
|
12705
12918
|
}
|
|
12706
|
-
merge(from,
|
|
12919
|
+
merge(from, path18.join(dirs.dir, sub));
|
|
12707
12920
|
}
|
|
12708
|
-
const ledger =
|
|
12709
|
-
if (fs13.existsSync(ledger) && !fs13.existsSync(
|
|
12710
|
-
merge(ledger,
|
|
12711
|
-
fs13.rmSync(
|
|
12712
|
-
fs13.renameSync(marker,
|
|
12921
|
+
const ledger = path18.join(local, "ledger");
|
|
12922
|
+
if (fs13.existsSync(ledger) && !fs13.existsSync(path18.join(dirs.dir, "ledger")))
|
|
12923
|
+
merge(ledger, path18.join(dirs.dir, "ledger"));
|
|
12924
|
+
fs13.rmSync(path18.join(local, "task-index.json"), { force: true });
|
|
12925
|
+
fs13.renameSync(marker, path18.join(local, "store.moved.json"));
|
|
12713
12926
|
} catch (error) {
|
|
12714
12927
|
return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
|
|
12715
12928
|
path: local
|
|
@@ -12747,7 +12960,7 @@ class TaskReader {
|
|
|
12747
12960
|
schemaVersion: SCHEMA_VERSION,
|
|
12748
12961
|
id: workspaceId ?? newId(),
|
|
12749
12962
|
revision: newRevision(),
|
|
12750
|
-
root:
|
|
12963
|
+
root: path18.dirname(v2),
|
|
12751
12964
|
runtime: { createdWith: version, updatedWith: version },
|
|
12752
12965
|
writer: null,
|
|
12753
12966
|
store: {
|
|
@@ -12759,11 +12972,11 @@ class TaskReader {
|
|
|
12759
12972
|
critical: ["store"]
|
|
12760
12973
|
};
|
|
12761
12974
|
fs13.mkdirSync(v2, { recursive: true });
|
|
12762
|
-
const ignore =
|
|
12975
|
+
const ignore = path18.join(v2, ".gitignore");
|
|
12763
12976
|
if (!fs13.existsSync(ignore))
|
|
12764
12977
|
fs13.writeFileSync(ignore, `*
|
|
12765
12978
|
`);
|
|
12766
|
-
replaceFile(
|
|
12979
|
+
replaceFile(path18.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
12767
12980
|
`, true);
|
|
12768
12981
|
}
|
|
12769
12982
|
initializeStorage() {
|
|
@@ -12795,7 +13008,7 @@ class TaskReader {
|
|
|
12795
13008
|
pid: process.pid,
|
|
12796
13009
|
processStart: processStartOf(process.pid),
|
|
12797
13010
|
host: localLockHost(),
|
|
12798
|
-
nonce:
|
|
13011
|
+
nonce: randomUUID4()
|
|
12799
13012
|
})
|
|
12800
13013
|
};
|
|
12801
13014
|
}
|
|
@@ -12822,7 +13035,7 @@ class TaskReader {
|
|
|
12822
13035
|
withLock(lockPath, operation) {
|
|
12823
13036
|
try {
|
|
12824
13037
|
this.initializeStorage();
|
|
12825
|
-
fs13.mkdirSync(
|
|
13038
|
+
fs13.mkdirSync(path18.dirname(lockPath), { recursive: true });
|
|
12826
13039
|
} catch (error) {
|
|
12827
13040
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
12828
13041
|
path: this.paths().dir
|
|
@@ -12860,7 +13073,7 @@ class TaskReader {
|
|
|
12860
13073
|
return result;
|
|
12861
13074
|
}
|
|
12862
13075
|
lockDirWritable(lockPath) {
|
|
12863
|
-
const probe = `${lockPath}.${process.pid}.${
|
|
13076
|
+
const probe = `${lockPath}.${process.pid}.${randomUUID4()}.probe`;
|
|
12864
13077
|
try {
|
|
12865
13078
|
fs13.closeSync(fs13.openSync(probe, "wx", 384));
|
|
12866
13079
|
} catch {
|
|
@@ -12885,7 +13098,7 @@ class TaskReader {
|
|
|
12885
13098
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
12886
13099
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
12887
13100
|
path: lockPath,
|
|
12888
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
13101
|
+
guidance: `Check permissions and the read-only attribute on ${path18.dirname(lockPath)}.`
|
|
12889
13102
|
});
|
|
12890
13103
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
12891
13104
|
let lock = null;
|
|
@@ -12940,7 +13153,7 @@ var moveInto = (from, to) => {
|
|
|
12940
13153
|
target = `${to}.dir`;
|
|
12941
13154
|
fs14.mkdirSync(target, { recursive: true });
|
|
12942
13155
|
for (const name of fs14.readdirSync(from))
|
|
12943
|
-
moveInto(
|
|
13156
|
+
moveInto(path19.join(from, name), path19.join(target, name));
|
|
12944
13157
|
fs14.rmdirSync(from);
|
|
12945
13158
|
return;
|
|
12946
13159
|
}
|
|
@@ -12951,13 +13164,13 @@ var moveInto = (from, to) => {
|
|
|
12951
13164
|
fs14.rmSync(from);
|
|
12952
13165
|
return;
|
|
12953
13166
|
}
|
|
12954
|
-
target = `${to}.${
|
|
13167
|
+
target = `${to}.${createHash11("sha256").update(bytes).digest("hex").slice(0, 12)}`;
|
|
12955
13168
|
if (fs14.existsSync(target)) {
|
|
12956
13169
|
fs14.rmSync(from);
|
|
12957
13170
|
return;
|
|
12958
13171
|
}
|
|
12959
13172
|
}
|
|
12960
|
-
fs14.mkdirSync(
|
|
13173
|
+
fs14.mkdirSync(path19.dirname(target), { recursive: true });
|
|
12961
13174
|
try {
|
|
12962
13175
|
fs14.renameSync(from, target);
|
|
12963
13176
|
} catch {
|
|
@@ -13025,7 +13238,7 @@ class TaskStore extends TaskReader {
|
|
|
13025
13238
|
const moved = this.bindLocked(again.data.id, key, input.now);
|
|
13026
13239
|
return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
|
|
13027
13240
|
}
|
|
13028
|
-
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" :
|
|
13241
|
+
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path19.basename(this.root) || this.root;
|
|
13029
13242
|
const intent = {
|
|
13030
13243
|
objective: input.objective?.trim() || `Work on ${label}`,
|
|
13031
13244
|
scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
|
|
@@ -13273,13 +13486,13 @@ class TaskStore extends TaskReader {
|
|
|
13273
13486
|
if (!ready.ok)
|
|
13274
13487
|
return ready;
|
|
13275
13488
|
const dirs = this.paths();
|
|
13276
|
-
const recovery = [
|
|
13489
|
+
const recovery = [path19.join(this.root, ".workit", "recovery"), path19.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
|
|
13277
13490
|
if (recovery) {
|
|
13278
13491
|
let files = 0;
|
|
13279
13492
|
let bytes = 0;
|
|
13280
13493
|
try {
|
|
13281
13494
|
for (const name of fs14.readdirSync(recovery)) {
|
|
13282
|
-
const stat = fs14.lstatSync(
|
|
13495
|
+
const stat = fs14.lstatSync(path19.join(recovery, name));
|
|
13283
13496
|
if (!stat.isFile())
|
|
13284
13497
|
continue;
|
|
13285
13498
|
files += 1;
|
|
@@ -13332,7 +13545,7 @@ class TaskStore extends TaskReader {
|
|
|
13332
13545
|
if (fs14.existsSync(dirs.blobs))
|
|
13333
13546
|
for (const name of fs14.readdirSync(dirs.blobs)) {
|
|
13334
13547
|
const digest = name.replace(/\.json$/, "");
|
|
13335
|
-
const file =
|
|
13548
|
+
const file = path19.join(dirs.blobs, name);
|
|
13336
13549
|
let stat;
|
|
13337
13550
|
try {
|
|
13338
13551
|
stat = fs14.lstatSync(file);
|
|
@@ -13350,7 +13563,7 @@ class TaskStore extends TaskReader {
|
|
|
13350
13563
|
}
|
|
13351
13564
|
return success(null, null, null);
|
|
13352
13565
|
};
|
|
13353
|
-
const swept = dryRun ? sweep() : this.withLock(
|
|
13566
|
+
const swept = dryRun ? sweep() : this.withLock(path19.join(dirs.dir, "gc.lock"), sweep);
|
|
13354
13567
|
if (!swept.ok)
|
|
13355
13568
|
return swept;
|
|
13356
13569
|
const temporaryDirs = [
|
|
@@ -13358,7 +13571,7 @@ class TaskStore extends TaskReader {
|
|
|
13358
13571
|
dirs.tasks,
|
|
13359
13572
|
dirs.blobs,
|
|
13360
13573
|
dirs.checkout,
|
|
13361
|
-
...names.map((name) =>
|
|
13574
|
+
...names.map((name) => path19.join(dirs.tasks, name))
|
|
13362
13575
|
];
|
|
13363
13576
|
for (const directory of temporaryDirs) {
|
|
13364
13577
|
if (!fs14.existsSync(directory))
|
|
@@ -13366,7 +13579,7 @@ class TaskStore extends TaskReader {
|
|
|
13366
13579
|
for (const name of fs14.readdirSync(directory)) {
|
|
13367
13580
|
if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
|
|
13368
13581
|
continue;
|
|
13369
|
-
const file =
|
|
13582
|
+
const file = path19.join(directory, name);
|
|
13370
13583
|
try {
|
|
13371
13584
|
const stat = fs14.lstatSync(file);
|
|
13372
13585
|
if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
|
|
@@ -13382,7 +13595,7 @@ class TaskStore extends TaskReader {
|
|
|
13382
13595
|
return success(null, null, report);
|
|
13383
13596
|
}
|
|
13384
13597
|
taskLockPath(taskId) {
|
|
13385
|
-
return
|
|
13598
|
+
return path19.join(this.paths().tasks, taskId, "lock");
|
|
13386
13599
|
}
|
|
13387
13600
|
settleMigrations(write) {
|
|
13388
13601
|
const moved = this.adoptLocalStore();
|
|
@@ -13411,7 +13624,7 @@ class TaskStore extends TaskReader {
|
|
|
13411
13624
|
return {
|
|
13412
13625
|
read: (digest) => reader.read(digest),
|
|
13413
13626
|
write: (digest, value) => {
|
|
13414
|
-
const file =
|
|
13627
|
+
const file = path19.join(dir, `${digest}.json`);
|
|
13415
13628
|
if (fs14.existsSync(file)) {
|
|
13416
13629
|
const stamp = new Date;
|
|
13417
13630
|
try {
|
|
@@ -13513,7 +13726,7 @@ class TaskStore extends TaskReader {
|
|
|
13513
13726
|
}
|
|
13514
13727
|
}
|
|
13515
13728
|
openTask(record, type, key, legacy = null) {
|
|
13516
|
-
const dir =
|
|
13729
|
+
const dir = path19.join(this.paths().tasks, record.id);
|
|
13517
13730
|
fs14.mkdirSync(dir, { recursive: true });
|
|
13518
13731
|
const blobs = this.blobStore();
|
|
13519
13732
|
const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
|
|
@@ -13593,8 +13806,8 @@ class TaskStore extends TaskReader {
|
|
|
13593
13806
|
}
|
|
13594
13807
|
}
|
|
13595
13808
|
withKeyLock(key, operation) {
|
|
13596
|
-
const digest =
|
|
13597
|
-
return this.withLock(
|
|
13809
|
+
const digest = createHash11("sha256").update(key).digest("hex").slice(0, 32);
|
|
13810
|
+
return this.withLock(path19.join(this.paths().dir, "keys", `${digest}.lock`), operation);
|
|
13598
13811
|
}
|
|
13599
13812
|
bindLocked(taskId, key, timestamp) {
|
|
13600
13813
|
const current = this.readWorkspace();
|
|
@@ -13735,7 +13948,7 @@ class TaskStore extends TaskReader {
|
|
|
13735
13948
|
writeWorkspace(record) {
|
|
13736
13949
|
const file = this.paths().workspace;
|
|
13737
13950
|
try {
|
|
13738
|
-
fs14.mkdirSync(
|
|
13951
|
+
fs14.mkdirSync(path19.dirname(file), { recursive: true });
|
|
13739
13952
|
replaceFile(file, `${canonicalJson(record)}
|
|
13740
13953
|
`, true);
|
|
13741
13954
|
return success(null, null, null);
|
|
@@ -13761,13 +13974,13 @@ class TaskStore extends TaskReader {
|
|
|
13761
13974
|
}
|
|
13762
13975
|
migrateV2(v2) {
|
|
13763
13976
|
const dirs = this.paths();
|
|
13764
|
-
const v2Workspace =
|
|
13765
|
-
const v2Tasks =
|
|
13766
|
-
const legacy =
|
|
13977
|
+
const v2Workspace = path19.join(v2, "workspace.json");
|
|
13978
|
+
const v2Tasks = path19.join(v2, "tasks");
|
|
13979
|
+
const legacy = path19.join(dirs.dir, "legacy", checkoutSlug(path19.dirname(v2)), "v2");
|
|
13767
13980
|
const raw = this.readV2Workspace(v2Workspace);
|
|
13768
13981
|
if (raw === null || raw === TOMBSTONE)
|
|
13769
13982
|
return success(null, null, null);
|
|
13770
|
-
return this.withLock(dirs.checkoutLock, () => this.withLock(
|
|
13983
|
+
return this.withLock(dirs.checkoutLock, () => this.withLock(path19.join(v2, "metadata.lock"), () => {
|
|
13771
13984
|
const workspace = this.readV2Workspace(v2Workspace);
|
|
13772
13985
|
if (workspace === null || workspace === TOMBSTONE)
|
|
13773
13986
|
return success(null, null, null);
|
|
@@ -13776,7 +13989,7 @@ class TaskStore extends TaskReader {
|
|
|
13776
13989
|
return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
|
|
13777
13990
|
let files = [];
|
|
13778
13991
|
try {
|
|
13779
|
-
files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(
|
|
13992
|
+
files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path19.join(v2Tasks, name)));
|
|
13780
13993
|
} catch {}
|
|
13781
13994
|
const current = this.readWorkspace();
|
|
13782
13995
|
if (!current.ok)
|
|
@@ -13794,21 +14007,21 @@ class TaskStore extends TaskReader {
|
|
|
13794
14007
|
let skipped = 0;
|
|
13795
14008
|
const done = new Map;
|
|
13796
14009
|
try {
|
|
13797
|
-
fs14.mkdirSync(
|
|
14010
|
+
fs14.mkdirSync(path19.join(legacy, "tasks"), { recursive: true });
|
|
13798
14011
|
for (const name of ["workspace.json", "index.json"])
|
|
13799
|
-
if (fs14.existsSync(
|
|
13800
|
-
fs14.copyFileSync(
|
|
14012
|
+
if (fs14.existsSync(path19.join(v2, name)))
|
|
14013
|
+
fs14.copyFileSync(path19.join(v2, name), path19.join(legacy, name));
|
|
13801
14014
|
for (const name of files) {
|
|
13802
14015
|
const id = name.slice(0, -5);
|
|
13803
|
-
const file =
|
|
14016
|
+
const file = path19.join(v2Tasks, name);
|
|
13804
14017
|
const bytes = fs14.readFileSync(file, "utf8");
|
|
13805
14018
|
const digest = sha256(bytes);
|
|
13806
|
-
fs14.writeFileSync(
|
|
14019
|
+
fs14.writeFileSync(path19.join(legacy, "tasks", name), bytes);
|
|
13807
14020
|
const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
|
|
13808
14021
|
if (!parsed.ok || parsed.data.id !== id)
|
|
13809
14022
|
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 });
|
|
13810
14023
|
const record = { ...parsed.data, workspaceId: target.id };
|
|
13811
|
-
const origin = { path:
|
|
14024
|
+
const origin = { path: path19.join(legacy, "tasks", name), digest };
|
|
13812
14025
|
if (!fs14.existsSync(this.eventsPath(id))) {
|
|
13813
14026
|
this.openTask(record, "migrated.from_v2", null, origin);
|
|
13814
14027
|
migrated += 1;
|
|
@@ -13844,7 +14057,7 @@ class TaskStore extends TaskReader {
|
|
|
13844
14057
|
try {
|
|
13845
14058
|
let complete = true;
|
|
13846
14059
|
for (const [name, digest] of done) {
|
|
13847
|
-
const file =
|
|
14060
|
+
const file = path19.join(v2Tasks, name);
|
|
13848
14061
|
if (sha256(fs14.readFileSync(file, "utf8")) !== digest) {
|
|
13849
14062
|
complete = false;
|
|
13850
14063
|
continue;
|
|
@@ -13858,7 +14071,7 @@ class TaskStore extends TaskReader {
|
|
|
13858
14071
|
return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
|
|
13859
14072
|
path: v2
|
|
13860
14073
|
});
|
|
13861
|
-
fs14.rmSync(
|
|
14074
|
+
fs14.rmSync(path19.join(v2, "index.json"), { force: true });
|
|
13862
14075
|
if (dirs.shared)
|
|
13863
14076
|
fs14.rmSync(v2Workspace, { force: true });
|
|
13864
14077
|
else
|
|
@@ -13883,8 +14096,8 @@ class TaskStore extends TaskReader {
|
|
|
13883
14096
|
const dirs = this.paths();
|
|
13884
14097
|
if (!dirs.shared)
|
|
13885
14098
|
return success(null, null, null);
|
|
13886
|
-
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(
|
|
13887
|
-
const ignore =
|
|
14099
|
+
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path19.join(v2, name)));
|
|
14100
|
+
const ignore = path19.join(v2, ".gitignore");
|
|
13888
14101
|
const onlyGeneratedIgnore = () => {
|
|
13889
14102
|
try {
|
|
13890
14103
|
return fs14.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs14.readFileSync(ignore, "utf8"));
|
|
@@ -13894,12 +14107,12 @@ class TaskStore extends TaskReader {
|
|
|
13894
14107
|
};
|
|
13895
14108
|
if (present().length === 0 && !onlyGeneratedIgnore())
|
|
13896
14109
|
return success(null, null, null);
|
|
13897
|
-
const backup =
|
|
14110
|
+
const backup = path19.join(dirs.dir, "legacy", checkoutSlug(path19.dirname(v2)), "v2");
|
|
13898
14111
|
return this.withLock(dirs.checkoutLock, () => {
|
|
13899
14112
|
let moved = 0;
|
|
13900
14113
|
try {
|
|
13901
14114
|
for (const name of present()) {
|
|
13902
|
-
const entry =
|
|
14115
|
+
const entry = path19.join(v2, name);
|
|
13903
14116
|
const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
|
|
13904
14117
|
const empty = fs14.lstatSync(entry).isDirectory() && fs14.readdirSync(entry).length === 0;
|
|
13905
14118
|
if (marker || empty) {
|
|
@@ -13908,18 +14121,18 @@ class TaskStore extends TaskReader {
|
|
|
13908
14121
|
}
|
|
13909
14122
|
if (name === "tasks" && fs14.lstatSync(entry).isDirectory()) {
|
|
13910
14123
|
for (const task of fs14.readdirSync(entry)) {
|
|
13911
|
-
const file =
|
|
14124
|
+
const file = path19.join(entry, task);
|
|
13912
14125
|
if (fs14.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
|
|
13913
14126
|
fs14.rmSync(file);
|
|
13914
14127
|
else {
|
|
13915
|
-
moveInto(file,
|
|
14128
|
+
moveInto(file, path19.join(backup, "tasks", task));
|
|
13916
14129
|
moved += 1;
|
|
13917
14130
|
}
|
|
13918
14131
|
}
|
|
13919
14132
|
fs14.rmdirSync(entry);
|
|
13920
14133
|
continue;
|
|
13921
14134
|
}
|
|
13922
|
-
moveInto(entry,
|
|
14135
|
+
moveInto(entry, path19.join(backup, name));
|
|
13923
14136
|
moved += 1;
|
|
13924
14137
|
}
|
|
13925
14138
|
if (onlyGeneratedIgnore())
|
|
@@ -13960,22 +14173,22 @@ var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
|
|
|
13960
14173
|
var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
|
|
13961
14174
|
|
|
13962
14175
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
13963
|
-
import { createHash as
|
|
14176
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
13964
14177
|
import * as fs18 from "node:fs";
|
|
13965
14178
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
13966
|
-
import
|
|
14179
|
+
import path25 from "node:path";
|
|
13967
14180
|
|
|
13968
14181
|
// packages/workit-core/src/check-config.ts
|
|
13969
14182
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
13970
14183
|
import fs15 from "node:fs";
|
|
13971
|
-
import
|
|
14184
|
+
import path20 from "node:path";
|
|
13972
14185
|
var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
|
|
13973
14186
|
var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
|
|
13974
14187
|
var CHECKS_FILE = ".workit/checks.json";
|
|
13975
14188
|
var LEGACY_CHECKS_FILE = "workit.checks.json";
|
|
13976
14189
|
function checksConfigFile(root) {
|
|
13977
|
-
const current =
|
|
13978
|
-
const legacy =
|
|
14190
|
+
const current = path20.join(root, CHECKS_FILE);
|
|
14191
|
+
const legacy = path20.join(root, LEGACY_CHECKS_FILE);
|
|
13979
14192
|
return !fs15.existsSync(current) && fs15.existsSync(legacy) ? legacy : current;
|
|
13980
14193
|
}
|
|
13981
14194
|
var GENERATED_GITIGNORES2 = new Set([`*
|
|
@@ -14044,10 +14257,10 @@ var git3 = (cwd, args) => {
|
|
|
14044
14257
|
return value || null;
|
|
14045
14258
|
};
|
|
14046
14259
|
function checkRoot(cwd) {
|
|
14047
|
-
return
|
|
14260
|
+
return path20.resolve(gitDirs(cwd)?.top ?? cwd);
|
|
14048
14261
|
}
|
|
14049
14262
|
var packageManager = (root) => {
|
|
14050
|
-
const has = (file) => fs15.existsSync(
|
|
14263
|
+
const has = (file) => fs15.existsSync(path20.join(root, file));
|
|
14051
14264
|
if (has("bun.lock") || has("bun.lockb"))
|
|
14052
14265
|
return "bun";
|
|
14053
14266
|
if (has("pnpm-lock.yaml"))
|
|
@@ -14067,7 +14280,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
|
|
|
14067
14280
|
function detectedChecks(root) {
|
|
14068
14281
|
const read = (file) => {
|
|
14069
14282
|
try {
|
|
14070
|
-
return fs15.readFileSync(
|
|
14283
|
+
return fs15.readFileSync(path20.join(root, file), "utf8");
|
|
14071
14284
|
} catch {
|
|
14072
14285
|
return null;
|
|
14073
14286
|
}
|
|
@@ -14142,10 +14355,10 @@ function configFileFor(root) {
|
|
|
14142
14355
|
if (fs15.existsSync(own))
|
|
14143
14356
|
return own;
|
|
14144
14357
|
const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
14145
|
-
if (!common ||
|
|
14358
|
+
if (!common || path20.basename(common) !== ".git")
|
|
14146
14359
|
return own;
|
|
14147
|
-
const main =
|
|
14148
|
-
if (
|
|
14360
|
+
const main = path20.dirname(common);
|
|
14361
|
+
if (path20.resolve(main) === path20.resolve(root))
|
|
14149
14362
|
return own;
|
|
14150
14363
|
const shared = checksConfigFile(main);
|
|
14151
14364
|
return fs15.existsSync(shared) ? shared : own;
|
|
@@ -14153,7 +14366,7 @@ function configFileFor(root) {
|
|
|
14153
14366
|
function loadCheckConfig(cwd) {
|
|
14154
14367
|
const root = checkRoot(cwd);
|
|
14155
14368
|
const file = configFileFor(root);
|
|
14156
|
-
const legacy =
|
|
14369
|
+
const legacy = path20.basename(file) === LEGACY_CHECKS_FILE;
|
|
14157
14370
|
const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
|
|
14158
14371
|
const note = legacy ? {
|
|
14159
14372
|
note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
|
|
@@ -14284,10 +14497,10 @@ function workitAvailable(env = process.env) {
|
|
|
14284
14497
|
return workitOnPath;
|
|
14285
14498
|
const windows = process.platform === "win32";
|
|
14286
14499
|
const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
14287
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
14500
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path20.delimiter).filter(Boolean);
|
|
14288
14501
|
workitOnPath = dirs.some((dir) => exts.some((ext) => {
|
|
14289
14502
|
try {
|
|
14290
|
-
return fs15.statSync(
|
|
14503
|
+
return fs15.statSync(path20.join(dir, `workit${ext}`)).isFile();
|
|
14291
14504
|
} catch {
|
|
14292
14505
|
return false;
|
|
14293
14506
|
}
|
|
@@ -14357,14 +14570,14 @@ var firstPositional = (words, from) => {
|
|
|
14357
14570
|
return index;
|
|
14358
14571
|
};
|
|
14359
14572
|
function fileTarget(word, cwd) {
|
|
14360
|
-
if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(
|
|
14573
|
+
if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(path20.sep))
|
|
14361
14574
|
return false;
|
|
14362
|
-
if (!/\.[A-Za-z0-9]+$/u.test(
|
|
14575
|
+
if (!/\.[A-Za-z0-9]+$/u.test(path20.basename(word)))
|
|
14363
14576
|
return false;
|
|
14364
14577
|
if (!cwd)
|
|
14365
14578
|
return true;
|
|
14366
14579
|
try {
|
|
14367
|
-
return !fs15.statSync(
|
|
14580
|
+
return !fs15.statSync(path20.resolve(cwd, word)).isDirectory();
|
|
14368
14581
|
} catch {
|
|
14369
14582
|
return true;
|
|
14370
14583
|
}
|
|
@@ -14432,13 +14645,13 @@ function lightCommand(argv, cwd) {
|
|
|
14432
14645
|
|
|
14433
14646
|
// packages/workit-core/src/core/policy/derive.ts
|
|
14434
14647
|
import { existsSync as existsSync9 } from "node:fs";
|
|
14435
|
-
import
|
|
14648
|
+
import path24 from "node:path";
|
|
14436
14649
|
|
|
14437
14650
|
// packages/workit-core/src/ledger.ts
|
|
14438
14651
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
14439
|
-
import { createHash as
|
|
14652
|
+
import { createHash as createHash13, randomBytes as randomBytes3 } from "node:crypto";
|
|
14440
14653
|
import fs17 from "node:fs";
|
|
14441
|
-
import
|
|
14654
|
+
import path23 from "node:path";
|
|
14442
14655
|
|
|
14443
14656
|
// packages/workit-core/src/core/policy/bookkeeping.ts
|
|
14444
14657
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
@@ -14518,8 +14731,8 @@ function bookkeepingPaths(cwd, input) {
|
|
|
14518
14731
|
}
|
|
14519
14732
|
|
|
14520
14733
|
// packages/workit-core/src/core/policy/lane.ts
|
|
14521
|
-
import { existsSync as existsSync8, readFileSync as
|
|
14522
|
-
import
|
|
14734
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
|
|
14735
|
+
import path21 from "node:path";
|
|
14523
14736
|
|
|
14524
14737
|
// packages/workit-core/src/git/default-base.ts
|
|
14525
14738
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
@@ -15910,7 +16123,7 @@ function computeLane(input) {
|
|
|
15910
16123
|
}
|
|
15911
16124
|
function untrackedStat(cwd, file) {
|
|
15912
16125
|
try {
|
|
15913
|
-
const bytes =
|
|
16126
|
+
const bytes = readFileSync8(path21.join(cwd, file));
|
|
15914
16127
|
if (bytes.includes(0))
|
|
15915
16128
|
return { path: file, added: 0, deleted: 0, binary: true };
|
|
15916
16129
|
const text = bytes.toString("utf8");
|
|
@@ -15942,7 +16155,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
15942
16155
|
let after = blobs.get(entry.newBlob);
|
|
15943
16156
|
if (!after && head === null && ABSENT.test(entry.newBlob))
|
|
15944
16157
|
try {
|
|
15945
|
-
after =
|
|
16158
|
+
after = readFileSync8(path21.join(cwd, entry.path));
|
|
15946
16159
|
} catch {
|
|
15947
16160
|
after = undefined;
|
|
15948
16161
|
}
|
|
@@ -16097,35 +16310,35 @@ function verdictDrift(cwd, input) {
|
|
|
16097
16310
|
}
|
|
16098
16311
|
|
|
16099
16312
|
// packages/workit-core/src/hooks/standing-signal.ts
|
|
16100
|
-
import { createHash as
|
|
16313
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
16101
16314
|
import fs16 from "node:fs";
|
|
16102
|
-
import
|
|
16315
|
+
import path22 from "node:path";
|
|
16103
16316
|
var gitStoreDir = (cwd) => {
|
|
16104
16317
|
try {
|
|
16105
|
-
for (let dir =
|
|
16106
|
-
const dotGit =
|
|
16318
|
+
for (let dir = path22.resolve(cwd);; dir = path22.dirname(dir)) {
|
|
16319
|
+
const dotGit = path22.join(dir, ".git");
|
|
16107
16320
|
if (fs16.existsSync(dotGit)) {
|
|
16108
16321
|
let gitDir = dotGit;
|
|
16109
16322
|
if (fs16.statSync(dotGit).isFile()) {
|
|
16110
16323
|
const target = /^gitdir:\s*(.+)$/mu.exec(fs16.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
16111
16324
|
if (!target)
|
|
16112
16325
|
return null;
|
|
16113
|
-
gitDir =
|
|
16114
|
-
const common =
|
|
16326
|
+
gitDir = path22.resolve(dir, target);
|
|
16327
|
+
const common = path22.join(gitDir, "commondir");
|
|
16115
16328
|
if (fs16.existsSync(common))
|
|
16116
|
-
gitDir =
|
|
16329
|
+
gitDir = path22.resolve(gitDir, fs16.readFileSync(common, "utf8").trim());
|
|
16117
16330
|
}
|
|
16118
|
-
return
|
|
16331
|
+
return path22.join(gitDir, "workit");
|
|
16119
16332
|
}
|
|
16120
|
-
if (
|
|
16333
|
+
if (path22.dirname(dir) === dir)
|
|
16121
16334
|
return null;
|
|
16122
16335
|
}
|
|
16123
16336
|
} catch {
|
|
16124
16337
|
return null;
|
|
16125
16338
|
}
|
|
16126
16339
|
};
|
|
16127
|
-
var standingRevFile = (store) =>
|
|
16128
|
-
var standingSeenFile = (store, session, agentId) =>
|
|
16340
|
+
var standingRevFile = (store) => path22.join(store, "standing", "rev");
|
|
16341
|
+
var standingSeenFile = (store, session, agentId) => path22.join(store, "standing", "seen", `${createHash12("sha256").update(`${session}\x00${agentId ?? ""}`).digest("hex").slice(0, 32)}.json`);
|
|
16129
16342
|
var readStandingRev = (store) => {
|
|
16130
16343
|
try {
|
|
16131
16344
|
return fs16.readFileSync(standingRevFile(store), "utf8").trim() || null;
|
|
@@ -16146,7 +16359,7 @@ var readStandingSeen = (file) => {
|
|
|
16146
16359
|
};
|
|
16147
16360
|
var writeStandingSeen = (file, seen) => {
|
|
16148
16361
|
try {
|
|
16149
|
-
fs16.mkdirSync(
|
|
16362
|
+
fs16.mkdirSync(path22.dirname(file), { recursive: true });
|
|
16150
16363
|
fs16.writeFileSync(file, JSON.stringify(seen));
|
|
16151
16364
|
} catch {}
|
|
16152
16365
|
};
|
|
@@ -16228,7 +16441,7 @@ var binaryRangeDiff = (cwd, base, head) => {
|
|
|
16228
16441
|
return diff.ok && diff.stdout ? diff.stdout : null;
|
|
16229
16442
|
};
|
|
16230
16443
|
var hashOfDiff = (diff) => {
|
|
16231
|
-
const hash =
|
|
16444
|
+
const hash = createHash13("sha256");
|
|
16232
16445
|
for (const line of diff.split(`
|
|
16233
16446
|
`)) {
|
|
16234
16447
|
if (line.startsWith("index "))
|
|
@@ -16261,14 +16474,14 @@ function cleanRebase(cwd, range) {
|
|
|
16261
16474
|
return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
|
|
16262
16475
|
}
|
|
16263
16476
|
function storeRoot(cwd) {
|
|
16264
|
-
const location = resolveStore(
|
|
16477
|
+
const location = resolveStore(path23.resolve(cwd));
|
|
16265
16478
|
if (location instanceof Error)
|
|
16266
16479
|
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");
|
|
16267
16480
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
16268
16481
|
}
|
|
16269
16482
|
function ledgerPath(cwd) {
|
|
16270
16483
|
const root = storeRoot(cwd);
|
|
16271
|
-
return root.ok ? { ok: true, value:
|
|
16484
|
+
return root.ok ? { ok: true, value: path23.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
16272
16485
|
}
|
|
16273
16486
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
|
|
16274
16487
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -16298,13 +16511,13 @@ var LOCK_STALE_MS2 = 30000;
|
|
|
16298
16511
|
var LOCK_OWNER = "owner";
|
|
16299
16512
|
var lockToken = (lock) => {
|
|
16300
16513
|
try {
|
|
16301
|
-
return fs17.readFileSync(
|
|
16514
|
+
return fs17.readFileSync(path23.join(lock, LOCK_OWNER), "utf8");
|
|
16302
16515
|
} catch {
|
|
16303
16516
|
return null;
|
|
16304
16517
|
}
|
|
16305
16518
|
};
|
|
16306
16519
|
var lockAgeMs = (lock) => {
|
|
16307
|
-
for (const target of [
|
|
16520
|
+
for (const target of [path23.join(lock, LOCK_OWNER), lock]) {
|
|
16308
16521
|
try {
|
|
16309
16522
|
return Date.now() - fs17.statSync(target).mtimeMs;
|
|
16310
16523
|
} catch {}
|
|
@@ -16321,7 +16534,7 @@ var ledgerLock = {
|
|
|
16321
16534
|
throw error;
|
|
16322
16535
|
}
|
|
16323
16536
|
const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
|
|
16324
|
-
fs17.writeFileSync(
|
|
16537
|
+
fs17.writeFileSync(path23.join(lock, LOCK_OWNER), token);
|
|
16325
16538
|
return token;
|
|
16326
16539
|
},
|
|
16327
16540
|
release(lock, token) {
|
|
@@ -16384,7 +16597,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2))
|
|
|
16384
16597
|
ledgerLock.release(lock, token);
|
|
16385
16598
|
}
|
|
16386
16599
|
}
|
|
16387
|
-
var sha2562 = (text) =>
|
|
16600
|
+
var sha2562 = (text) => createHash13("sha256").update(text).digest("hex");
|
|
16388
16601
|
var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
|
|
16389
16602
|
${body}`);
|
|
16390
16603
|
var TAIL_BYTES = 64 * 1024;
|
|
@@ -16446,8 +16659,8 @@ ${line.value}`);
|
|
|
16446
16659
|
}
|
|
16447
16660
|
};
|
|
16448
16661
|
try {
|
|
16449
|
-
fs17.mkdirSync(
|
|
16450
|
-
if (options.heldLock || !options.forceLock && !onNetworkFs(
|
|
16662
|
+
fs17.mkdirSync(path23.dirname(file), { recursive: true });
|
|
16663
|
+
if (options.heldLock || !options.forceLock && !onNetworkFs(path23.dirname(file)))
|
|
16451
16664
|
return write();
|
|
16452
16665
|
const locked = withLedgerLock(file, write);
|
|
16453
16666
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -16464,7 +16677,7 @@ var sealed = (row, id, at, previous) => {
|
|
|
16464
16677
|
` };
|
|
16465
16678
|
};
|
|
16466
16679
|
function appendRaw(cwd, row, options) {
|
|
16467
|
-
const file = options.store ? { ok: true, value:
|
|
16680
|
+
const file = options.store ? { ok: true, value: path23.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
|
|
16468
16681
|
if (!file.ok)
|
|
16469
16682
|
return file;
|
|
16470
16683
|
const id = newId2();
|
|
@@ -17127,7 +17340,7 @@ function remoteIdentity(cwd, hop = 0) {
|
|
|
17127
17340
|
return null;
|
|
17128
17341
|
if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
|
|
17129
17342
|
const local = raw.replace(/^file:\/\//u, "");
|
|
17130
|
-
const resolved =
|
|
17343
|
+
const resolved = path23.isAbsolute(local) ? local : path23.resolve(cwd, local);
|
|
17131
17344
|
if (fs17.existsSync(resolved))
|
|
17132
17345
|
return remoteIdentity(resolved, 1);
|
|
17133
17346
|
}
|
|
@@ -17148,8 +17361,8 @@ function verdictMirrorPath(cwd) {
|
|
|
17148
17361
|
}
|
|
17149
17362
|
if (!identity)
|
|
17150
17363
|
return null;
|
|
17151
|
-
const key =
|
|
17152
|
-
return
|
|
17364
|
+
const key = createHash13("sha256").update(identity).digest("hex").slice(0, 32);
|
|
17365
|
+
return path23.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
|
|
17153
17366
|
}
|
|
17154
17367
|
var importedStamp = new Map;
|
|
17155
17368
|
function importMirroredVerdicts(cwd, branch) {
|
|
@@ -17172,7 +17385,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
17172
17385
|
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
17173
17386
|
const added = new Set;
|
|
17174
17387
|
try {
|
|
17175
|
-
fs17.mkdirSync(
|
|
17388
|
+
fs17.mkdirSync(path23.dirname(local.value), { recursive: true });
|
|
17176
17389
|
} catch {
|
|
17177
17390
|
return [];
|
|
17178
17391
|
}
|
|
@@ -17398,7 +17611,7 @@ var productDecision = (task, ledger) => {
|
|
|
17398
17611
|
};
|
|
17399
17612
|
};
|
|
17400
17613
|
var planRecorded = (task, root) => {
|
|
17401
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(
|
|
17614
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path24.resolve(root, ref.path)));
|
|
17402
17615
|
if (cited)
|
|
17403
17616
|
return {
|
|
17404
17617
|
met: true,
|
|
@@ -17475,15 +17688,15 @@ function writeBlockers(task, root) {
|
|
|
17475
17688
|
}
|
|
17476
17689
|
|
|
17477
17690
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
17478
|
-
var digestBytes = (value) =>
|
|
17479
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
17480
|
-
var relative = (root, candidate) =>
|
|
17691
|
+
var digestBytes = (value) => createHash14("sha256").update(value).digest("hex");
|
|
17692
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path25.sep}`);
|
|
17693
|
+
var relative = (root, candidate) => path25.relative(root, candidate).split(path25.sep).join("/") || ".";
|
|
17481
17694
|
var canonicalPath = (value) => {
|
|
17482
17695
|
if (typeof value !== "string" || !value)
|
|
17483
17696
|
return null;
|
|
17484
17697
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
17485
17698
|
return null;
|
|
17486
|
-
const normalized =
|
|
17699
|
+
const normalized = path25.posix.normalize(value);
|
|
17487
17700
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
17488
17701
|
return null;
|
|
17489
17702
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -17531,14 +17744,14 @@ var gitPaths = (root) => {
|
|
|
17531
17744
|
git: !/not a git repository/i.test(stderr)
|
|
17532
17745
|
};
|
|
17533
17746
|
}
|
|
17534
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
17747
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")) : [];
|
|
17535
17748
|
const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
17536
17749
|
if (stagedDeleted.status !== 0) {
|
|
17537
17750
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
17538
17751
|
if (!/not a git repository/i.test(stderr))
|
|
17539
17752
|
return { paths, uncertain: true, git: true };
|
|
17540
17753
|
} else if (stagedDeleted.stdout) {
|
|
17541
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
17754
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")));
|
|
17542
17755
|
}
|
|
17543
17756
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
17544
17757
|
};
|
|
@@ -17553,7 +17766,7 @@ var walk = (root, directory, output) => {
|
|
|
17553
17766
|
for (const name of names) {
|
|
17554
17767
|
if (name === ".git" || name === ".workit")
|
|
17555
17768
|
continue;
|
|
17556
|
-
const target =
|
|
17769
|
+
const target = path25.join(directory, name);
|
|
17557
17770
|
let stat;
|
|
17558
17771
|
try {
|
|
17559
17772
|
stat = fs18.lstatSync(target);
|
|
@@ -17571,12 +17784,12 @@ var walk = (root, directory, output) => {
|
|
|
17571
17784
|
var scopeRoots = (root, scope) => {
|
|
17572
17785
|
const roots = [];
|
|
17573
17786
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
17574
|
-
const target =
|
|
17787
|
+
const target = path25.resolve(root, item);
|
|
17575
17788
|
if (!inside(root, target))
|
|
17576
17789
|
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` }] });
|
|
17577
17790
|
let ancestor = target;
|
|
17578
17791
|
while (!fs18.existsSync(ancestor) && ancestor !== root)
|
|
17579
|
-
ancestor =
|
|
17792
|
+
ancestor = path25.dirname(ancestor);
|
|
17580
17793
|
try {
|
|
17581
17794
|
if (!inside(root, fs18.realpathSync(ancestor)))
|
|
17582
17795
|
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` }] });
|
|
@@ -17628,7 +17841,7 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
17628
17841
|
for (const item of [...names].toSorted()) {
|
|
17629
17842
|
if (!scopeMatches(item, normalizedScope))
|
|
17630
17843
|
continue;
|
|
17631
|
-
const target =
|
|
17844
|
+
const target = path25.join(checkout, item);
|
|
17632
17845
|
try {
|
|
17633
17846
|
const stat = fs18.lstatSync(target);
|
|
17634
17847
|
if (stat.isSymbolicLink()) {
|
|
@@ -17812,23 +18025,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
17812
18025
|
continue;
|
|
17813
18026
|
if (!reference.digest)
|
|
17814
18027
|
return failure2("invalid_input", "document references require a byte digest");
|
|
17815
|
-
const target =
|
|
17816
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
18028
|
+
const target = path25.resolve(root, reference.path);
|
|
18029
|
+
if (target !== root && !target.startsWith(`${root}${path25.sep}`))
|
|
17817
18030
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
17818
18031
|
fields: [
|
|
17819
18032
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
17820
18033
|
]
|
|
17821
18034
|
});
|
|
17822
18035
|
try {
|
|
17823
|
-
const below =
|
|
18036
|
+
const below = path25.relative(root, target);
|
|
17824
18037
|
let current = root;
|
|
17825
|
-
for (const segment of below.split(
|
|
18038
|
+
for (const segment of below.split(path25.sep)) {
|
|
17826
18039
|
if (!segment)
|
|
17827
18040
|
continue;
|
|
17828
|
-
current =
|
|
18041
|
+
current = path25.join(current, segment);
|
|
17829
18042
|
const stat = fs18.lstatSync(current);
|
|
17830
18043
|
const real = fs18.realpathSync(current);
|
|
17831
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
18044
|
+
if (real !== root && !real.startsWith(`${root}${path25.sep}`))
|
|
17832
18045
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
17833
18046
|
fields: [
|
|
17834
18047
|
{
|
|
@@ -18193,9 +18406,9 @@ function briefInspectResult(request, result) {
|
|
|
18193
18406
|
}
|
|
18194
18407
|
|
|
18195
18408
|
// packages/workit-core/src/core/model-fallback.ts
|
|
18196
|
-
import { createHash as
|
|
18197
|
-
import { mkdirSync as
|
|
18198
|
-
import
|
|
18409
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
18410
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
18411
|
+
import path26 from "node:path";
|
|
18199
18412
|
var LIMITS_FILE = "model-limits.json";
|
|
18200
18413
|
var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
|
|
18201
18414
|
var KEEP_MS = 9 * 86400000;
|
|
@@ -18218,10 +18431,10 @@ var providerOf = (model, host) => {
|
|
|
18218
18431
|
return null;
|
|
18219
18432
|
};
|
|
18220
18433
|
var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
|
|
18221
|
-
var storePath = (stateDir) =>
|
|
18434
|
+
var storePath = (stateDir) => path26.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
|
|
18222
18435
|
var readStore = (stateDir) => {
|
|
18223
18436
|
try {
|
|
18224
|
-
const parsed = JSON.parse(
|
|
18437
|
+
const parsed = JSON.parse(readFileSync10(storePath(stateDir), "utf8"));
|
|
18225
18438
|
const store = empty();
|
|
18226
18439
|
for (const key of ["exhausted", "seen", "redispatched"])
|
|
18227
18440
|
if (parsed[key] && typeof parsed[key] === "object")
|
|
@@ -18242,11 +18455,11 @@ var writeStore = (store, now, stateDir) => {
|
|
|
18242
18455
|
delete store.exhausted[id];
|
|
18243
18456
|
try {
|
|
18244
18457
|
const file = storePath(stateDir);
|
|
18245
|
-
|
|
18458
|
+
mkdirSync6(path26.dirname(file), { recursive: true });
|
|
18246
18459
|
const temp = `${file}.${process.pid}.tmp`;
|
|
18247
|
-
|
|
18460
|
+
writeFileSync6(temp, `${JSON.stringify(store, null, 2)}
|
|
18248
18461
|
`);
|
|
18249
|
-
|
|
18462
|
+
renameSync5(temp, file);
|
|
18250
18463
|
} catch {}
|
|
18251
18464
|
};
|
|
18252
18465
|
var markExhausted = (key, until, reason, now = new Date, stateDir) => {
|
|
@@ -18278,7 +18491,7 @@ var firstSighting = (id, now = new Date, stateDir) => {
|
|
|
18278
18491
|
writeStore(store, now, stateDir);
|
|
18279
18492
|
return true;
|
|
18280
18493
|
};
|
|
18281
|
-
var promptKey = (prompt) =>
|
|
18494
|
+
var promptKey = (prompt) => createHash15("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
|
|
18282
18495
|
var claimRedispatch = (key, now = new Date, stateDir) => {
|
|
18283
18496
|
const store = readStore(stateDir);
|
|
18284
18497
|
if (store.redispatched[key])
|
|
@@ -18839,20 +19052,20 @@ import path29 from "node:path";
|
|
|
18839
19052
|
// packages/workit-core/src/core/eval-world.ts
|
|
18840
19053
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
18841
19054
|
import os6 from "node:os";
|
|
18842
|
-
import
|
|
19055
|
+
import path27 from "node:path";
|
|
18843
19056
|
var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
|
|
18844
19057
|
var EVAL_WORLD_MARKER = ".workit-eval-world";
|
|
18845
19058
|
var inside2 = (dir, file) => {
|
|
18846
|
-
const rel =
|
|
18847
|
-
return !rel.startsWith("..") && !
|
|
19059
|
+
const rel = path27.relative(dir, file);
|
|
19060
|
+
return !rel.startsWith("..") && !path27.isAbsolute(rel);
|
|
18848
19061
|
};
|
|
18849
19062
|
var evalWorld = (cwd) => {
|
|
18850
19063
|
const raw = process.env[EVAL_WORLD_ENV];
|
|
18851
|
-
if (!raw || !
|
|
19064
|
+
if (!raw || !path27.isAbsolute(raw))
|
|
18852
19065
|
return null;
|
|
18853
19066
|
try {
|
|
18854
19067
|
const world = realpathSync7(raw);
|
|
18855
|
-
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(
|
|
19068
|
+
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path27.join(world, EVAL_WORLD_MARKER)) ? world : null;
|
|
18856
19069
|
} catch {
|
|
18857
19070
|
return null;
|
|
18858
19071
|
}
|
|
@@ -18860,146 +19073,12 @@ var evalWorld = (cwd) => {
|
|
|
18860
19073
|
var evalWorldEntry = (cwd) => {
|
|
18861
19074
|
const world = evalWorld(cwd);
|
|
18862
19075
|
try {
|
|
18863
|
-
return world ? loadWorkspacesFrom(
|
|
19076
|
+
return world ? loadWorkspacesFrom(path27.join(world, "config"))[0] ?? null : null;
|
|
18864
19077
|
} catch {
|
|
18865
19078
|
return null;
|
|
18866
19079
|
}
|
|
18867
19080
|
};
|
|
18868
19081
|
|
|
18869
|
-
// packages/workit-core/src/core/grant-seal.ts
|
|
18870
|
-
import { createHash as createHash15 } from "node:crypto";
|
|
18871
|
-
import { readFileSync as readFileSync10 } from "node:fs";
|
|
18872
|
-
import path27 from "node:path";
|
|
18873
|
-
|
|
18874
|
-
// packages/workit-core/src/core/safe-write.ts
|
|
18875
|
-
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
18876
|
-
import {
|
|
18877
|
-
closeSync as closeSync2,
|
|
18878
|
-
fchmodSync,
|
|
18879
|
-
fsyncSync,
|
|
18880
|
-
lstatSync as lstatSync7,
|
|
18881
|
-
mkdirSync as mkdirSync6,
|
|
18882
|
-
openSync as openSync2,
|
|
18883
|
-
renameSync as renameSync5,
|
|
18884
|
-
unlinkSync,
|
|
18885
|
-
writeFileSync as writeFileSync6
|
|
18886
|
-
} from "node:fs";
|
|
18887
|
-
import path26 from "node:path";
|
|
18888
|
-
function writeFileAtomic(file, content, mode) {
|
|
18889
|
-
const absolute = path26.resolve(file);
|
|
18890
|
-
let parent = path26.dirname(absolute);
|
|
18891
|
-
const root = path26.parse(parent).root;
|
|
18892
|
-
for (;; ) {
|
|
18893
|
-
try {
|
|
18894
|
-
if (lstatSync7(parent).isSymbolicLink())
|
|
18895
|
-
throw new Error(`symlinked write path: ${parent}`);
|
|
18896
|
-
} catch (error) {
|
|
18897
|
-
if (error.code !== "ENOENT")
|
|
18898
|
-
throw error;
|
|
18899
|
-
}
|
|
18900
|
-
const next = path26.dirname(parent);
|
|
18901
|
-
if (parent === root || next === parent)
|
|
18902
|
-
break;
|
|
18903
|
-
parent = next;
|
|
18904
|
-
}
|
|
18905
|
-
const directory = path26.dirname(absolute);
|
|
18906
|
-
mkdirSync6(directory, { recursive: true });
|
|
18907
|
-
let existing = null;
|
|
18908
|
-
try {
|
|
18909
|
-
existing = lstatSync7(absolute);
|
|
18910
|
-
} catch (error) {
|
|
18911
|
-
if (error.code !== "ENOENT")
|
|
18912
|
-
throw error;
|
|
18913
|
-
}
|
|
18914
|
-
if (existing?.isSymbolicLink() || existing && !existing.isFile()) {
|
|
18915
|
-
throw new Error(`refusing to replace non-regular file: ${absolute}`);
|
|
18916
|
-
}
|
|
18917
|
-
const temporary = `${absolute}.${randomUUID4()}.tmp`;
|
|
18918
|
-
let fd;
|
|
18919
|
-
try {
|
|
18920
|
-
fd = openSync2(temporary, "wx", mode ?? 438);
|
|
18921
|
-
writeFileSync6(fd, content, "utf8");
|
|
18922
|
-
if (existing)
|
|
18923
|
-
fchmodSync(fd, existing.mode & 511);
|
|
18924
|
-
fsyncSync(fd);
|
|
18925
|
-
closeSync2(fd);
|
|
18926
|
-
fd = undefined;
|
|
18927
|
-
renameSync5(temporary, absolute);
|
|
18928
|
-
} catch (error) {
|
|
18929
|
-
if (fd !== undefined) {
|
|
18930
|
-
try {
|
|
18931
|
-
closeSync2(fd);
|
|
18932
|
-
} catch {}
|
|
18933
|
-
}
|
|
18934
|
-
try {
|
|
18935
|
-
unlinkSync(temporary);
|
|
18936
|
-
} catch {}
|
|
18937
|
-
throw error;
|
|
18938
|
-
}
|
|
18939
|
-
}
|
|
18940
|
-
|
|
18941
|
-
// packages/workit-core/src/core/grant-seal.ts
|
|
18942
|
-
var SEAL_FILE = "workspaces.json.seal";
|
|
18943
|
-
var SEAL_VERSION = 1;
|
|
18944
|
-
var SEAL_COMMAND = "workit workspace seal";
|
|
18945
|
-
var pick3 = (value, keys) => {
|
|
18946
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
18947
|
-
return;
|
|
18948
|
-
const out = Object.fromEntries(keys.flatMap((key) => {
|
|
18949
|
-
const item = value[key];
|
|
18950
|
-
return item === undefined ? [] : [[key, item]];
|
|
18951
|
-
}));
|
|
18952
|
-
return Object.keys(out).length > 0 ? out : undefined;
|
|
18953
|
-
};
|
|
18954
|
-
var ENTRY_KEYS = [
|
|
18955
|
-
"name",
|
|
18956
|
-
"glob",
|
|
18957
|
-
"remotes",
|
|
18958
|
-
"externalRepos",
|
|
18959
|
-
"additiveRiskPaths",
|
|
18960
|
-
"vcs",
|
|
18961
|
-
"autonomy",
|
|
18962
|
-
"autoApprove",
|
|
18963
|
-
"defaultEndpoint",
|
|
18964
|
-
"verification",
|
|
18965
|
-
"youtrack"
|
|
18966
|
-
];
|
|
18967
|
-
var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
|
|
18968
|
-
var sealProjection = (entries) => entries.map((entry) => {
|
|
18969
|
-
const all = pick3(entry, ENTRY_KEYS) ?? {};
|
|
18970
|
-
return pick3({
|
|
18971
|
-
...all,
|
|
18972
|
-
vcs: pick3(all.vcs, IDENTITY_KEYS),
|
|
18973
|
-
youtrack: pick3(all.youtrack, ["writes", "autoHosts"])
|
|
18974
|
-
}, ENTRY_KEYS);
|
|
18975
|
-
});
|
|
18976
|
-
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);
|
|
18977
|
-
var sealDigest = (projection) => createHash15("sha256").update(canonical4(projection)).digest("hex");
|
|
18978
|
-
var broken = (reason, sealed = null) => ({
|
|
18979
|
-
state: "broken",
|
|
18980
|
-
reason,
|
|
18981
|
-
sealed
|
|
18982
|
-
});
|
|
18983
|
-
function checkSeal(dir) {
|
|
18984
|
-
const file = path27.join(dir, SEAL_FILE);
|
|
18985
|
-
let seal;
|
|
18986
|
-
try {
|
|
18987
|
-
seal = JSON.parse(readFileSync10(file, "utf8"));
|
|
18988
|
-
} catch (error) {
|
|
18989
|
-
if (error.code === "ENOENT")
|
|
18990
|
-
return { state: "none" };
|
|
18991
|
-
return broken(`${SEAL_FILE} cannot be read`);
|
|
18992
|
-
}
|
|
18993
|
-
if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
|
|
18994
|
-
return broken(`${SEAL_FILE} is malformed`);
|
|
18995
|
-
const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
|
|
18996
|
-
if (sealed.status !== "valid")
|
|
18997
|
-
return broken(`${SEAL_FILE} is malformed`);
|
|
18998
|
-
const current = readWorkspacesResult(dir);
|
|
18999
|
-
const ok = current.status === "valid" || current.status === "missing";
|
|
19000
|
-
return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
|
|
19001
|
-
}
|
|
19002
|
-
|
|
19003
19082
|
// packages/workit-core/src/core/youtrack-ytrack.ts
|
|
19004
19083
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
19005
19084
|
|
|
@@ -19139,7 +19218,7 @@ var sealOf = () => {
|
|
|
19139
19218
|
var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
|
|
19140
19219
|
var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
|
|
19141
19220
|
var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never run), so grants, endpoint, verification and youtrack.writes stay at or below the D4 defaults; ${NO_SEAL_UNBLOCK}`;
|
|
19142
|
-
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;
|
|
19221
|
+
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, and a sealed releaseNotes review stays; ${SEAL_UNBLOCK}` : null;
|
|
19143
19222
|
var ASK = { mode: "ask" };
|
|
19144
19223
|
var youtrackOf = (entry) => entry?.youtrack;
|
|
19145
19224
|
var autoHostsOf = (entry) => {
|
|
@@ -19561,7 +19640,14 @@ var SCOPE_FIELDS = new Set([
|
|
|
19561
19640
|
"autoApprove",
|
|
19562
19641
|
"defaultEndpoint",
|
|
19563
19642
|
"verification",
|
|
19564
|
-
"youtrack"
|
|
19643
|
+
"youtrack",
|
|
19644
|
+
"releaseNotes",
|
|
19645
|
+
"releaseTagPrefix",
|
|
19646
|
+
"branchPolicy",
|
|
19647
|
+
"profiles",
|
|
19648
|
+
"defaultProfile",
|
|
19649
|
+
"releaseTracks",
|
|
19650
|
+
"releasePackages"
|
|
19565
19651
|
]);
|
|
19566
19652
|
|
|
19567
19653
|
// packages/workit-core/src/core/release-packages.ts
|