@workit-dev/opencode 2.29.0 → 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/plugin.js +1310 -747
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -6993,17 +6993,17 @@ function explainInvalidOperation(family, request) {
|
|
|
6993
6993
|
return parsed.success ? null : invalidOperation(family, request, parsed.error);
|
|
6994
6994
|
}
|
|
6995
6995
|
// packages/workit-core/src/core/task-store.ts
|
|
6996
|
-
import { createHash as
|
|
6996
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
6997
6997
|
import * as fs16 from "node:fs";
|
|
6998
|
-
import
|
|
6998
|
+
import path20 from "node:path";
|
|
6999
6999
|
|
|
7000
7000
|
// packages/workit-core/src/host-session.ts
|
|
7001
|
-
import { createHash as
|
|
7001
|
+
import { createHash as createHash11, randomBytes, timingSafeEqual } from "node:crypto";
|
|
7002
7002
|
import fs9 from "node:fs";
|
|
7003
|
-
import
|
|
7003
|
+
import path14 from "node:path";
|
|
7004
7004
|
|
|
7005
7005
|
// packages/workit-core/src/core/branch.ts
|
|
7006
|
-
import { createHash as
|
|
7006
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
7007
7007
|
|
|
7008
7008
|
// packages/workit-core/src/core/branch-policy.ts
|
|
7009
7009
|
import { spawnSync } from "node:child_process";
|
|
@@ -7379,9 +7379,9 @@ var gitContext = (workspaceRoot, paths = []) => {
|
|
|
7379
7379
|
|
|
7380
7380
|
// packages/workit-core/src/core/workspaces.ts
|
|
7381
7381
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
7382
|
-
import { createHash as
|
|
7383
|
-
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as
|
|
7384
|
-
import
|
|
7382
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
7383
|
+
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
7384
|
+
import path10 from "node:path";
|
|
7385
7385
|
|
|
7386
7386
|
// packages/workit-core/src/core/remotes.ts
|
|
7387
7387
|
import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
|
|
@@ -8697,6 +8697,103 @@ var pushTarget = (cwd, remote, replay = {}) => {
|
|
|
8697
8697
|
return { remotes };
|
|
8698
8698
|
};
|
|
8699
8699
|
|
|
8700
|
+
// packages/workit-core/src/core/grant-seal.ts
|
|
8701
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
8702
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
8703
|
+
import path9 from "node:path";
|
|
8704
|
+
var SEAL_FILE = "workspaces.json.seal";
|
|
8705
|
+
var SEAL_VERSION = 2;
|
|
8706
|
+
var isSealVersion = (value) => value === 1 || value === 2;
|
|
8707
|
+
var SEAL_COMMAND = "workit workspace seal";
|
|
8708
|
+
var pick3 = (value, keys) => {
|
|
8709
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
8710
|
+
return;
|
|
8711
|
+
const out = Object.fromEntries(keys.flatMap((key) => {
|
|
8712
|
+
const item = value[key];
|
|
8713
|
+
return item === undefined ? [] : [[key, item]];
|
|
8714
|
+
}));
|
|
8715
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
8716
|
+
};
|
|
8717
|
+
var ENTRY_KEYS = [
|
|
8718
|
+
"name",
|
|
8719
|
+
"glob",
|
|
8720
|
+
"remotes",
|
|
8721
|
+
"externalRepos",
|
|
8722
|
+
"additiveRiskPaths",
|
|
8723
|
+
"vcs",
|
|
8724
|
+
"autonomy",
|
|
8725
|
+
"autoApprove",
|
|
8726
|
+
"defaultEndpoint",
|
|
8727
|
+
"verification",
|
|
8728
|
+
"youtrack"
|
|
8729
|
+
];
|
|
8730
|
+
var RELEASE_KEYS = [
|
|
8731
|
+
"releaseNotes",
|
|
8732
|
+
"releaseTagPrefix",
|
|
8733
|
+
"branchPolicy",
|
|
8734
|
+
"profiles",
|
|
8735
|
+
"defaultProfile",
|
|
8736
|
+
"releaseTracks",
|
|
8737
|
+
"releasePackages"
|
|
8738
|
+
];
|
|
8739
|
+
var keysOf = (version) => version >= 2 ? [...ENTRY_KEYS, ...RELEASE_KEYS] : ENTRY_KEYS;
|
|
8740
|
+
var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
|
|
8741
|
+
var sealProjection = (entries, version = SEAL_VERSION) => entries.map((entry) => {
|
|
8742
|
+
const keys = keysOf(version);
|
|
8743
|
+
const all = pick3(entry, keys) ?? {};
|
|
8744
|
+
return pick3({
|
|
8745
|
+
...all,
|
|
8746
|
+
vcs: pick3(all.vcs, IDENTITY_KEYS),
|
|
8747
|
+
youtrack: pick3(all.youtrack, ["writes", "autoHosts"]),
|
|
8748
|
+
...version >= 2 ? releaseLineMapping(entry, true) : {}
|
|
8749
|
+
}, keys);
|
|
8750
|
+
});
|
|
8751
|
+
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);
|
|
8752
|
+
var sealDigest = (projection) => createHash6("sha256").update(canonical3(projection)).digest("hex");
|
|
8753
|
+
var broken = (reason, sealed = null, version) => ({
|
|
8754
|
+
state: "broken",
|
|
8755
|
+
reason,
|
|
8756
|
+
sealed,
|
|
8757
|
+
...version ? { version } : {}
|
|
8758
|
+
});
|
|
8759
|
+
var PARTIAL_KEYS = ["releaseTracks", "branchPolicy", "profiles", "defaultProfile"];
|
|
8760
|
+
var sealedEntries = (projection, file) => {
|
|
8761
|
+
const partial = projection.map((entry) => pick3(entry, PARTIAL_KEYS));
|
|
8762
|
+
const validated = validateWorkspacesDocument({
|
|
8763
|
+
workspaces: projection.map((entry) => {
|
|
8764
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
8765
|
+
return entry;
|
|
8766
|
+
const rest = { ...entry };
|
|
8767
|
+
for (const key of PARTIAL_KEYS)
|
|
8768
|
+
delete rest[key];
|
|
8769
|
+
return rest;
|
|
8770
|
+
})
|
|
8771
|
+
}, file);
|
|
8772
|
+
if (validated.status !== "valid" || validated.entries.length !== projection.length)
|
|
8773
|
+
return null;
|
|
8774
|
+
return validated.entries.map((entry, at) => partial[at] === undefined ? entry : { ...entry, ...partial[at] });
|
|
8775
|
+
};
|
|
8776
|
+
function checkSeal(dir) {
|
|
8777
|
+
const file = path9.join(dir, SEAL_FILE);
|
|
8778
|
+
let seal;
|
|
8779
|
+
try {
|
|
8780
|
+
seal = JSON.parse(readFileSync4(file, "utf8"));
|
|
8781
|
+
} catch (error) {
|
|
8782
|
+
if (error.code === "ENOENT")
|
|
8783
|
+
return { state: "none" };
|
|
8784
|
+
return broken(`${SEAL_FILE} cannot be read`);
|
|
8785
|
+
}
|
|
8786
|
+
if (!isSealVersion(seal?.version) || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
|
|
8787
|
+
return broken(`${SEAL_FILE} is malformed`);
|
|
8788
|
+
const version = seal.version;
|
|
8789
|
+
const sealed = sealedEntries(seal.projection, file);
|
|
8790
|
+
if (!sealed)
|
|
8791
|
+
return broken(`${SEAL_FILE} is malformed`, null, version);
|
|
8792
|
+
const current = readWorkspacesResult(dir);
|
|
8793
|
+
const ok = current.status === "valid" || current.status === "missing";
|
|
8794
|
+
return ok && sealDigest(sealProjection(current.entries, version)) === seal.sha256 ? { state: "valid", version } : broken("workspaces.json changed since it was sealed", sealed, version);
|
|
8795
|
+
}
|
|
8796
|
+
|
|
8700
8797
|
// packages/workit-core/src/core/workspaces.ts
|
|
8701
8798
|
var nonBlank = string2().check(refine((value) => value.trim().length > 0, "must not be blank"));
|
|
8702
8799
|
var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
|
|
@@ -8762,7 +8859,7 @@ var releaseTrackSchema = looseObject({
|
|
|
8762
8859
|
});
|
|
8763
8860
|
}
|
|
8764
8861
|
}
|
|
8765
|
-
if (track.versionSource?.kind === "package-json" && (
|
|
8862
|
+
if (track.versionSource?.kind === "package-json" && (path10.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
|
|
8766
8863
|
context.addIssue({
|
|
8767
8864
|
code: "custom",
|
|
8768
8865
|
path: ["versionSource", "path"],
|
|
@@ -8861,8 +8958,8 @@ var workspacesFileSchema = looseObject({
|
|
|
8861
8958
|
names.add(workspace.name);
|
|
8862
8959
|
}
|
|
8863
8960
|
}));
|
|
8864
|
-
var workspacesPath = () =>
|
|
8865
|
-
var workspacesRevision = (contents) =>
|
|
8961
|
+
var workspacesPath = () => path10.join(configDir2(), "workspaces.json");
|
|
8962
|
+
var workspacesRevision = (contents) => createHash7("sha256").update(contents ?? "<missing>").digest("hex");
|
|
8866
8963
|
var validateWorkspacesDocument = (parsed, file) => {
|
|
8867
8964
|
if (!isConfigObject(parsed)) {
|
|
8868
8965
|
return {
|
|
@@ -8908,10 +9005,10 @@ var validateWorkspacesDocument = (parsed, file) => {
|
|
|
8908
9005
|
};
|
|
8909
9006
|
};
|
|
8910
9007
|
var readWorkspacesResult = (dir = configDir2()) => {
|
|
8911
|
-
const file =
|
|
9008
|
+
const file = path10.join(dir, "workspaces.json");
|
|
8912
9009
|
let raw;
|
|
8913
9010
|
try {
|
|
8914
|
-
raw =
|
|
9011
|
+
raw = readFileSync5(file, "utf8");
|
|
8915
9012
|
} catch (error) {
|
|
8916
9013
|
if (error.code === "ENOENT")
|
|
8917
9014
|
return {
|
|
@@ -9012,9 +9109,9 @@ var probeCheckout = (cwd) => {
|
|
|
9012
9109
|
const cached = probes.get(cwd);
|
|
9013
9110
|
if (cached !== undefined)
|
|
9014
9111
|
return cached;
|
|
9015
|
-
let dir =
|
|
9016
|
-
while (!existsSync4(
|
|
9017
|
-
if (["HEAD", "objects", "refs"].every((name) => existsSync4(
|
|
9112
|
+
let dir = path10.resolve(cwd);
|
|
9113
|
+
while (!existsSync4(path10.join(dir, ".git"))) {
|
|
9114
|
+
if (["HEAD", "objects", "refs"].every((name) => existsSync4(path10.join(dir, name)))) {
|
|
9018
9115
|
const real = realpathOf(dir);
|
|
9019
9116
|
const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
|
|
9020
9117
|
if (owner === null)
|
|
@@ -9023,7 +9120,7 @@ var probeCheckout = (cwd) => {
|
|
|
9023
9120
|
probes.set(cwd, probe);
|
|
9024
9121
|
return probe;
|
|
9025
9122
|
}
|
|
9026
|
-
const up =
|
|
9123
|
+
const up = path10.dirname(dir);
|
|
9027
9124
|
if (up === dir)
|
|
9028
9125
|
return null;
|
|
9029
9126
|
dir = up;
|
|
@@ -9052,9 +9149,9 @@ var probeCheckout = (cwd) => {
|
|
|
9052
9149
|
if (!gitDir || !common)
|
|
9053
9150
|
return failed;
|
|
9054
9151
|
let main = null;
|
|
9055
|
-
if (
|
|
9152
|
+
if (path10.resolve(gitDir) === path10.resolve(common)) {
|
|
9056
9153
|
const real = realpathOf(common);
|
|
9057
|
-
if (!ownGitDir(
|
|
9154
|
+
if (!ownGitDir(path10.join(dir, ".git"), real)) {
|
|
9058
9155
|
const owner = gitDirOwner(real);
|
|
9059
9156
|
if (owner === null)
|
|
9060
9157
|
return Error(`${cwd} uses the repository at ${real}, owned by no checkout workit can name`);
|
|
@@ -9073,7 +9170,7 @@ var probeCheckout = (cwd) => {
|
|
|
9073
9170
|
const list = git(["worktree", "list", "--porcelain"]);
|
|
9074
9171
|
if (list === null)
|
|
9075
9172
|
return failed;
|
|
9076
|
-
main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (
|
|
9173
|
+
main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path10.basename(common) === ".git" ? path10.dirname(common) : common);
|
|
9077
9174
|
}
|
|
9078
9175
|
const probe = { main, superproject: superproject || null };
|
|
9079
9176
|
probes.set(cwd, probe);
|
|
@@ -9090,7 +9187,7 @@ var INTERNALS = ["refs", "objects", "config", "packed-refs", "commondir"];
|
|
|
9090
9187
|
var ownInternals = (real) => {
|
|
9091
9188
|
let lender = null;
|
|
9092
9189
|
for (const name of INTERNALS) {
|
|
9093
|
-
const at =
|
|
9190
|
+
const at = path10.join(real, name);
|
|
9094
9191
|
try {
|
|
9095
9192
|
lstatSync3(at);
|
|
9096
9193
|
} catch {
|
|
@@ -9102,10 +9199,10 @@ var ownInternals = (real) => {
|
|
|
9102
9199
|
} catch {
|
|
9103
9200
|
return false;
|
|
9104
9201
|
}
|
|
9105
|
-
const rel =
|
|
9106
|
-
if (rel && !rel.startsWith("..") && !
|
|
9202
|
+
const rel = path10.relative(real, resolved);
|
|
9203
|
+
if (rel && !rel.startsWith("..") && !path10.isAbsolute(rel))
|
|
9107
9204
|
continue;
|
|
9108
|
-
const owner =
|
|
9205
|
+
const owner = path10.basename(resolved) === name ? gitDirOwner(path10.dirname(resolved)) : null;
|
|
9109
9206
|
if (owner === null || lender !== null && lender !== owner)
|
|
9110
9207
|
return false;
|
|
9111
9208
|
lender = owner;
|
|
@@ -9119,7 +9216,7 @@ var gitDirOwner = (real) => {
|
|
|
9119
9216
|
return null;
|
|
9120
9217
|
const rest = parts.slice(at + 1);
|
|
9121
9218
|
const module = rest[0] === "modules" || rest[0] === "worktrees" && rest[2] === "modules";
|
|
9122
|
-
return rest.length === 0 || module ? parts.slice(0, at).join(
|
|
9219
|
+
return rest.length === 0 || module ? parts.slice(0, at).join(path10.sep) || path10.sep : null;
|
|
9123
9220
|
};
|
|
9124
9221
|
var mainCheckoutOf = (cwd) => {
|
|
9125
9222
|
const probe = probeCheckout(cwd);
|
|
@@ -9243,11 +9340,11 @@ var resolveRuntimeWorkspaceVcs = (cwd) => resolveRuntimeWorkspaceCandidate(cwd,
|
|
|
9243
9340
|
var runtimeWorkspaceIndexSchema = looseObject({
|
|
9244
9341
|
workspaces: optional(array(looseObject({ name: nonBlank, glob: nonBlank })))
|
|
9245
9342
|
});
|
|
9246
|
-
var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
9247
|
-
const file =
|
|
9343
|
+
var matchRuntimeWorkspace = (cwd, dir = configDir2(), workspaceName = namedWorkspace()) => {
|
|
9344
|
+
const file = path10.join(dir, "workspaces.json");
|
|
9248
9345
|
let raw;
|
|
9249
9346
|
try {
|
|
9250
|
-
raw =
|
|
9347
|
+
raw = readFileSync5(file, "utf8");
|
|
9251
9348
|
} catch (error) {
|
|
9252
9349
|
if (error.code === "ENOENT")
|
|
9253
9350
|
return null;
|
|
@@ -9270,13 +9367,21 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
|
9270
9367
|
if (!glob.ok)
|
|
9271
9368
|
throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
|
|
9272
9369
|
}
|
|
9273
|
-
const
|
|
9274
|
-
|
|
9370
|
+
const matched = matchAmong(cwd, entries ?? [], workspaceName);
|
|
9371
|
+
return matched ? { file, ...matched } : null;
|
|
9372
|
+
};
|
|
9373
|
+
var namedWorkspace = () => process.env.WORKIT_WORKSPACE_NAME?.trim() || null;
|
|
9374
|
+
var matchAmong = (cwd, entries, workspaceName = namedWorkspace()) => {
|
|
9375
|
+
const selected = resolveWorkspaceFromEntries(cwd, entries, workspaceName ?? undefined, true);
|
|
9275
9376
|
if (!selected)
|
|
9276
9377
|
return null;
|
|
9277
|
-
const matches = matchingEntries(cwd, entries
|
|
9278
|
-
return {
|
|
9378
|
+
const matches = matchingEntries(cwd, entries);
|
|
9379
|
+
return { selected, matches: matches.length ? matches : [selected] };
|
|
9279
9380
|
};
|
|
9381
|
+
var chainOf = (matched) => matched ? [
|
|
9382
|
+
matched.selected,
|
|
9383
|
+
...matched.matches.filter((entry) => entry !== matched.selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob))
|
|
9384
|
+
] : [];
|
|
9280
9385
|
var resolveRuntimeReleaseTracks = (cwd) => {
|
|
9281
9386
|
const matched = matchRuntimeWorkspace(cwd);
|
|
9282
9387
|
return matched ? {
|
|
@@ -9293,11 +9398,9 @@ var inheritedSetting = (cwd, dir, has) => {
|
|
|
9293
9398
|
}
|
|
9294
9399
|
if (!matched)
|
|
9295
9400
|
return null;
|
|
9296
|
-
const { selected, matches } = matched;
|
|
9297
|
-
const enclosing = matches.filter((entry) => entry !== selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob));
|
|
9298
9401
|
return {
|
|
9299
|
-
workspace: selected.name,
|
|
9300
|
-
source:
|
|
9402
|
+
workspace: matched.selected.name,
|
|
9403
|
+
source: chainOf(matched).find(has) ?? null
|
|
9301
9404
|
};
|
|
9302
9405
|
};
|
|
9303
9406
|
var resolveRuntimeReleasePackages = (cwd, dir) => {
|
|
@@ -9319,6 +9422,47 @@ var changelogPathOf = (value) => {
|
|
|
9319
9422
|
return null;
|
|
9320
9423
|
return parts.includes("..") ? null : parts.join("/");
|
|
9321
9424
|
};
|
|
9425
|
+
var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9426
|
+
var pickSet = (value, keys) => isPlainRecord(value) ? Object.fromEntries(keys.filter((key) => value[key] !== undefined).map((key) => [key, value[key]])) : {};
|
|
9427
|
+
var mapRecord = (value, map) => Object.fromEntries(Object.entries(value).map(([name, item]) => [name, map(item)]));
|
|
9428
|
+
var TRACK_LINE_KEYS = [
|
|
9429
|
+
"tagNamespace",
|
|
9430
|
+
"productionBranch",
|
|
9431
|
+
"integrationBranch",
|
|
9432
|
+
"baseBranch",
|
|
9433
|
+
"mergeBackBranches",
|
|
9434
|
+
"pullRequestTarget",
|
|
9435
|
+
"naming",
|
|
9436
|
+
"strategy"
|
|
9437
|
+
];
|
|
9438
|
+
var releaseLineMapping = (entry, notes = false) => {
|
|
9439
|
+
if (!isPlainRecord(entry))
|
|
9440
|
+
return;
|
|
9441
|
+
const out = {};
|
|
9442
|
+
if (notes && entry.releaseNotes !== undefined)
|
|
9443
|
+
out.releaseNotes = entry.releaseNotes;
|
|
9444
|
+
if (entry.releaseTagPrefix !== undefined)
|
|
9445
|
+
out.releaseTagPrefix = entry.releaseTagPrefix;
|
|
9446
|
+
if (entry.defaultProfile !== undefined)
|
|
9447
|
+
out.defaultProfile = entry.defaultProfile;
|
|
9448
|
+
const policy = pickSet(entry.branchPolicy, ["releaseTagPrefix"]);
|
|
9449
|
+
if (Object.keys(policy).length)
|
|
9450
|
+
out.branchPolicy = policy;
|
|
9451
|
+
const profiles = Object.fromEntries(Object.entries(isPlainRecord(entry.profiles) ? entry.profiles : {}).flatMap(([name, profile]) => {
|
|
9452
|
+
const prefix = pickSet(isPlainRecord(profile) ? profile.branchPolicy : undefined, [
|
|
9453
|
+
"releaseTagPrefix"
|
|
9454
|
+
]);
|
|
9455
|
+
return Object.keys(prefix).length ? [[name, { branchPolicy: prefix }]] : [];
|
|
9456
|
+
}));
|
|
9457
|
+
if (Object.keys(profiles).length)
|
|
9458
|
+
out.profiles = profiles;
|
|
9459
|
+
const trackKeys = notes ? [...TRACK_LINE_KEYS, "releaseNotes"] : TRACK_LINE_KEYS;
|
|
9460
|
+
if (entry.releaseTracks !== undefined)
|
|
9461
|
+
out.releaseTracks = isPlainRecord(entry.releaseTracks) ? mapRecord(entry.releaseTracks, (track) => pickSet(track, trackKeys)) : entry.releaseTracks;
|
|
9462
|
+
if (entry.releasePackages !== undefined)
|
|
9463
|
+
out.releasePackages = isPlainRecord(entry.releasePackages) ? mapRecord(entry.releasePackages, (pkg) => pickSet(pkg, ["tagNamespace"])) : entry.releasePackages;
|
|
9464
|
+
return Object.keys(out).length ? out : undefined;
|
|
9465
|
+
};
|
|
9322
9466
|
var modelSources = (cwd, dir) => {
|
|
9323
9467
|
const out = [];
|
|
9324
9468
|
try {
|
|
@@ -9335,7 +9479,7 @@ var modelSources = (cwd, dir) => {
|
|
|
9335
9479
|
}
|
|
9336
9480
|
} catch {}
|
|
9337
9481
|
try {
|
|
9338
|
-
const document = JSON.parse(
|
|
9482
|
+
const document = JSON.parse(readFileSync5(path10.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
|
|
9339
9483
|
if (document && typeof document === "object" && !Array.isArray(document))
|
|
9340
9484
|
out.push({
|
|
9341
9485
|
name: "global",
|
|
@@ -9400,11 +9544,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
|
|
|
9400
9544
|
|
|
9401
9545
|
// packages/workit-core/src/core/vcs-config.ts
|
|
9402
9546
|
import fs6 from "node:fs";
|
|
9403
|
-
import
|
|
9547
|
+
import path11 from "node:path";
|
|
9404
9548
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
9405
9549
|
|
|
9406
9550
|
// packages/workit-core/src/core/release-tracks.ts
|
|
9407
|
-
import { createHash as
|
|
9551
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
9408
9552
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
9409
9553
|
class ReleaseTrackError extends Error {
|
|
9410
9554
|
}
|
|
@@ -9787,7 +9931,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
9787
9931
|
]) ?? "",
|
|
9788
9932
|
git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
|
|
9789
9933
|
] : [];
|
|
9790
|
-
key =
|
|
9934
|
+
key = createHash8("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
|
|
9791
9935
|
const hit = memo2.get(key);
|
|
9792
9936
|
if (hit)
|
|
9793
9937
|
return hit;
|
|
@@ -9802,7 +9946,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
9802
9946
|
}
|
|
9803
9947
|
|
|
9804
9948
|
// packages/workit-core/src/core/vcs-config.ts
|
|
9805
|
-
var workspacesPath2 = () =>
|
|
9949
|
+
var workspacesPath2 = () => path11.join(configDir2(), "workspaces.json");
|
|
9806
9950
|
var vcsCwd = (cwd) => cwd ?? process.env.WORKIT_WORKSPACE_ROOT ?? process.cwd();
|
|
9807
9951
|
var remoteProvider = (cwd) => {
|
|
9808
9952
|
const url = originUrl(cwd) ?? "";
|
|
@@ -10014,7 +10158,7 @@ function vcsConfig(mode, cwd, options = {}) {
|
|
|
10014
10158
|
const prov = cfg[provider] ?? {};
|
|
10015
10159
|
const out = {
|
|
10016
10160
|
ok: true,
|
|
10017
|
-
configPath:
|
|
10161
|
+
configPath: path11.resolve(cfgPath),
|
|
10018
10162
|
provider,
|
|
10019
10163
|
defaultTargetBranch: workspaceDefault,
|
|
10020
10164
|
pr: cfg.pr ?? {},
|
|
@@ -10245,7 +10389,7 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
|
|
|
10245
10389
|
const source = resolved.provenance.branchPolicy;
|
|
10246
10390
|
const allowed = branchPolicy.allowed.map((pattern) => `${pattern.source}/${pattern.flags}`).toSorted();
|
|
10247
10391
|
const protectedRefs = [...branchPolicy.protected].map((name) => name.toLowerCase()).toSorted();
|
|
10248
|
-
const fingerprint =
|
|
10392
|
+
const fingerprint = createHash9("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
|
|
10249
10393
|
return {
|
|
10250
10394
|
branchPolicy,
|
|
10251
10395
|
namePolicy: { allowed: branchPolicy.allowed, protected: branchPolicy.protected },
|
|
@@ -10358,7 +10502,7 @@ var homePattern = new RegExp(`${escapeRegExp2(os4.homedir())}(?=[/\\\\]|$)|\\$HO
|
|
|
10358
10502
|
// packages/workit-core/src/store/folder-store.ts
|
|
10359
10503
|
import fs7 from "node:fs";
|
|
10360
10504
|
import os5 from "node:os";
|
|
10361
|
-
import
|
|
10505
|
+
import path12 from "node:path";
|
|
10362
10506
|
var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
|
|
10363
10507
|
var MOVED_POINTER = "MOVED-TO-STATE.txt";
|
|
10364
10508
|
var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
|
|
@@ -10367,7 +10511,7 @@ var MARKER = "workspace.json";
|
|
|
10367
10511
|
var v2Workspace = (workit) => {
|
|
10368
10512
|
let bytes;
|
|
10369
10513
|
try {
|
|
10370
|
-
bytes = fs7.readFileSync(
|
|
10514
|
+
bytes = fs7.readFileSync(path12.join(workit, MARKER), "utf8");
|
|
10371
10515
|
} catch {
|
|
10372
10516
|
return null;
|
|
10373
10517
|
}
|
|
@@ -10416,7 +10560,7 @@ var strayEntries = (workit) => {
|
|
|
10416
10560
|
} catch {
|
|
10417
10561
|
return [];
|
|
10418
10562
|
}
|
|
10419
|
-
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(
|
|
10563
|
+
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path12.join(workit, name))) && !(name === "tasks" && onlyStubs(path12.join(workit, name))));
|
|
10420
10564
|
};
|
|
10421
10565
|
var folderStoreIo = {
|
|
10422
10566
|
rename: (from, to) => fs7.renameSync(from, to),
|
|
@@ -10424,13 +10568,13 @@ var folderStoreIo = {
|
|
|
10424
10568
|
judgedStale: () => {}
|
|
10425
10569
|
};
|
|
10426
10570
|
var tempSeq = 0;
|
|
10427
|
-
var tempBeside = (file) =>
|
|
10571
|
+
var tempBeside = (file) => path12.join(path12.dirname(file), `.${path12.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
|
|
10428
10572
|
var copyInto = (from, to) => {
|
|
10429
10573
|
const stat = fs7.lstatSync(from);
|
|
10430
10574
|
if (stat.isDirectory()) {
|
|
10431
10575
|
fs7.mkdirSync(to, { recursive: true });
|
|
10432
10576
|
for (const name of fs7.readdirSync(from))
|
|
10433
|
-
copyInto(
|
|
10577
|
+
copyInto(path12.join(from, name), path12.join(to, name));
|
|
10434
10578
|
return;
|
|
10435
10579
|
}
|
|
10436
10580
|
if (exists(to))
|
|
@@ -10481,7 +10625,7 @@ var merge2 = (from, to, rel, moved) => {
|
|
|
10481
10625
|
}
|
|
10482
10626
|
if (!isDir(from) || !isDir(to))
|
|
10483
10627
|
return [rel];
|
|
10484
|
-
const kept = fs7.readdirSync(from).flatMap((name) => merge2(
|
|
10628
|
+
const kept = fs7.readdirSync(from).flatMap((name) => merge2(path12.join(from, name), path12.join(to, name), `${rel}/${name}`, moved));
|
|
10485
10629
|
try {
|
|
10486
10630
|
if (fs7.readdirSync(from).length === 0)
|
|
10487
10631
|
fs7.rmdirSync(from);
|
|
@@ -10560,38 +10704,38 @@ var takeMoveLock = (target) => {
|
|
|
10560
10704
|
pause(25);
|
|
10561
10705
|
}
|
|
10562
10706
|
};
|
|
10563
|
-
var
|
|
10707
|
+
var canonical4 = (dir) => {
|
|
10564
10708
|
try {
|
|
10565
10709
|
return fs7.realpathSync.native(dir);
|
|
10566
10710
|
} catch {
|
|
10567
|
-
return
|
|
10711
|
+
return path12.resolve(dir);
|
|
10568
10712
|
}
|
|
10569
10713
|
};
|
|
10570
10714
|
var below = (parent, child) => {
|
|
10571
|
-
const rel =
|
|
10572
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
10715
|
+
const rel = path12.relative(parent, child);
|
|
10716
|
+
return rel !== "" && !rel.startsWith("..") && !path12.isAbsolute(rel);
|
|
10573
10717
|
};
|
|
10574
|
-
var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(
|
|
10718
|
+
var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical4(tempDir), canonical4(dir));
|
|
10575
10719
|
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
10576
10720
|
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
|
|
10577
10721
|
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
10578
10722
|
return null;
|
|
10579
|
-
const real =
|
|
10580
|
-
const tmp =
|
|
10723
|
+
const real = canonical4(folder);
|
|
10724
|
+
const tmp = canonical4(tempDir);
|
|
10581
10725
|
if (insideTempDir(folder, tempDir))
|
|
10582
10726
|
return null;
|
|
10583
|
-
return `workit test run (WORKIT_TEST_RUN): refusing to move ${
|
|
10727
|
+
return `workit test run (WORKIT_TEST_RUN): refusing to move ${path12.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)`;
|
|
10584
10728
|
};
|
|
10585
10729
|
function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
|
|
10586
10730
|
`)) {
|
|
10587
|
-
const workit =
|
|
10731
|
+
const workit = path12.join(folder, ".workit");
|
|
10588
10732
|
const names = strayEntries(workit);
|
|
10589
10733
|
const refusal = testRunFolderRefusal(folder, names.length > 0);
|
|
10590
10734
|
if (refusal) {
|
|
10591
10735
|
const run = process.env.WORKIT_TEST_RUN ?? "";
|
|
10592
|
-
if (
|
|
10736
|
+
if (path12.isAbsolute(run))
|
|
10593
10737
|
try {
|
|
10594
|
-
fs7.appendFileSync(
|
|
10738
|
+
fs7.appendFileSync(path12.join(run, TEST_RUN_REFUSALS), `${refusal}
|
|
10595
10739
|
`);
|
|
10596
10740
|
} catch {}
|
|
10597
10741
|
throw new Error(refusal);
|
|
@@ -10599,7 +10743,7 @@ function migrateFolderStore(folder, target, note = (line) => process.stderr.writ
|
|
|
10599
10743
|
if (names.length === 0 || v2Workspace(workit) === true)
|
|
10600
10744
|
return null;
|
|
10601
10745
|
try {
|
|
10602
|
-
fs7.mkdirSync(
|
|
10746
|
+
fs7.mkdirSync(path12.dirname(target), { recursive: true });
|
|
10603
10747
|
} catch {
|
|
10604
10748
|
return null;
|
|
10605
10749
|
}
|
|
@@ -10623,7 +10767,7 @@ function moveLocked(workit, target, note) {
|
|
|
10623
10767
|
}
|
|
10624
10768
|
const result = { from: workit, to: target, moved: [], kept: [] };
|
|
10625
10769
|
for (const name of names) {
|
|
10626
|
-
result.kept.push(...merge2(
|
|
10770
|
+
result.kept.push(...merge2(path12.join(workit, name), path12.join(target, name), name, result.moved));
|
|
10627
10771
|
}
|
|
10628
10772
|
const left = (() => {
|
|
10629
10773
|
try {
|
|
@@ -10632,13 +10776,13 @@ function moveLocked(workit, target, note) {
|
|
|
10632
10776
|
return [];
|
|
10633
10777
|
}
|
|
10634
10778
|
})();
|
|
10635
|
-
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(
|
|
10779
|
+
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path12.join(workit, name)));
|
|
10636
10780
|
if (!v2Left && result.kept.length === 0) {
|
|
10637
|
-
fs7.rmSync(
|
|
10638
|
-
if (generatedIgnore(
|
|
10639
|
-
fs7.rmSync(
|
|
10781
|
+
fs7.rmSync(path12.join(workit, MARKER), { force: true });
|
|
10782
|
+
if (generatedIgnore(path12.join(workit, ".gitignore")))
|
|
10783
|
+
fs7.rmSync(path12.join(workit, ".gitignore"), { force: true });
|
|
10640
10784
|
}
|
|
10641
|
-
const pointer =
|
|
10785
|
+
const pointer = path12.join(workit, MOVED_POINTER);
|
|
10642
10786
|
let wrote = false;
|
|
10643
10787
|
if (result.kept.length > 0) {
|
|
10644
10788
|
const text = `Workit keeps this folder's state in ${target}.
|
|
@@ -10665,9 +10809,9 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
|
|
|
10665
10809
|
|
|
10666
10810
|
// packages/workit-core/src/store/paths.ts
|
|
10667
10811
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
10668
|
-
import { createHash as
|
|
10812
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
10669
10813
|
import fs8 from "node:fs";
|
|
10670
|
-
import
|
|
10814
|
+
import path13 from "node:path";
|
|
10671
10815
|
var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
|
|
10672
10816
|
var gitRun = (cwd, args) => {
|
|
10673
10817
|
const run = spawnSync9("git", args, {
|
|
@@ -10692,7 +10836,7 @@ var gitRun = (cwd, args) => {
|
|
|
10692
10836
|
missing: error?.code === "ENOENT"
|
|
10693
10837
|
};
|
|
10694
10838
|
};
|
|
10695
|
-
var shortHash = (value) =>
|
|
10839
|
+
var shortHash = (value) => createHash10("sha256").update(value).digest("hex").slice(0, 12);
|
|
10696
10840
|
var real = (file) => {
|
|
10697
10841
|
try {
|
|
10698
10842
|
return fs8.realpathSync.native(file);
|
|
@@ -10709,14 +10853,14 @@ var DISCOVERY_ENV = [
|
|
|
10709
10853
|
];
|
|
10710
10854
|
var isGitDir = (dir) => {
|
|
10711
10855
|
try {
|
|
10712
|
-
return fs8.statSync(
|
|
10856
|
+
return fs8.statSync(path13.join(dir, "HEAD")).isFile() && fs8.statSync(path13.join(dir, "objects")).isDirectory() && fs8.statSync(path13.join(dir, "refs")).isDirectory();
|
|
10713
10857
|
} catch {
|
|
10714
10858
|
return false;
|
|
10715
10859
|
}
|
|
10716
10860
|
};
|
|
10717
10861
|
var reftableRefs = (common) => {
|
|
10718
10862
|
try {
|
|
10719
|
-
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs8.readFileSync(
|
|
10863
|
+
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs8.readFileSync(path13.join(common, "config"), "utf8"));
|
|
10720
10864
|
} catch {
|
|
10721
10865
|
return false;
|
|
10722
10866
|
}
|
|
@@ -10736,7 +10880,7 @@ function fastGit(root) {
|
|
|
10736
10880
|
if (device !== null && stat.dev !== device)
|
|
10737
10881
|
return { kind: "none" };
|
|
10738
10882
|
device = stat.dev;
|
|
10739
|
-
const dotGit =
|
|
10883
|
+
const dotGit = path13.join(dir, ".git");
|
|
10740
10884
|
let entry = null;
|
|
10741
10885
|
try {
|
|
10742
10886
|
entry = fs8.statSync(dotGit);
|
|
@@ -10757,19 +10901,19 @@ function fastGit(root) {
|
|
|
10757
10901
|
const match = /^gitdir: (.+)$/mu.exec(text);
|
|
10758
10902
|
if (!match)
|
|
10759
10903
|
return null;
|
|
10760
|
-
gitDir =
|
|
10904
|
+
gitDir = path13.resolve(dir, match[1].trim());
|
|
10761
10905
|
} else
|
|
10762
10906
|
return null;
|
|
10763
|
-
if (!fs8.existsSync(
|
|
10907
|
+
if (!fs8.existsSync(path13.join(gitDir, "HEAD")))
|
|
10764
10908
|
return null;
|
|
10765
10909
|
} else if (isGitDir(dir))
|
|
10766
10910
|
gitDir = dir;
|
|
10767
10911
|
if (gitDir) {
|
|
10768
10912
|
let common = gitDir;
|
|
10769
10913
|
try {
|
|
10770
|
-
common =
|
|
10914
|
+
common = path13.resolve(gitDir, fs8.readFileSync(path13.join(gitDir, "commondir"), "utf8").trim());
|
|
10771
10915
|
} catch {}
|
|
10772
|
-
if (!fs8.existsSync(
|
|
10916
|
+
if (!fs8.existsSync(path13.join(common, "objects")))
|
|
10773
10917
|
return null;
|
|
10774
10918
|
return {
|
|
10775
10919
|
kind: "repo",
|
|
@@ -10779,7 +10923,7 @@ function fastGit(root) {
|
|
|
10779
10923
|
reftable: reftableRefs(common)
|
|
10780
10924
|
};
|
|
10781
10925
|
}
|
|
10782
|
-
const parent =
|
|
10926
|
+
const parent = path13.dirname(dir);
|
|
10783
10927
|
if (parent === dir)
|
|
10784
10928
|
return { kind: "none" };
|
|
10785
10929
|
dir = parent;
|
|
@@ -10791,7 +10935,7 @@ var outsideGit = (root) => {
|
|
|
10791
10935
|
return { dir, shared: false, top: null };
|
|
10792
10936
|
};
|
|
10793
10937
|
function resolveStore(root) {
|
|
10794
|
-
root =
|
|
10938
|
+
root = path13.resolve(root);
|
|
10795
10939
|
let stat = null;
|
|
10796
10940
|
try {
|
|
10797
10941
|
stat = fs8.statSync(root);
|
|
@@ -10799,13 +10943,13 @@ function resolveStore(root) {
|
|
|
10799
10943
|
if (!stat)
|
|
10800
10944
|
return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
|
|
10801
10945
|
if (!stat.isDirectory())
|
|
10802
|
-
return { dir:
|
|
10946
|
+
return { dir: path13.join(root, ".workit"), shared: false, top: null };
|
|
10803
10947
|
const fast = fastGit(root);
|
|
10804
10948
|
if (fast?.kind === "none")
|
|
10805
10949
|
return outsideGit(root);
|
|
10806
10950
|
if (fast?.kind === "repo")
|
|
10807
10951
|
return {
|
|
10808
|
-
dir:
|
|
10952
|
+
dir: path13.join(fast.common, "workit"),
|
|
10809
10953
|
shared: true,
|
|
10810
10954
|
top: fast.top,
|
|
10811
10955
|
git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
|
|
@@ -10815,7 +10959,7 @@ function resolveStore(root) {
|
|
|
10815
10959
|
if (run.ok && common) {
|
|
10816
10960
|
const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
|
|
10817
10961
|
return {
|
|
10818
|
-
dir:
|
|
10962
|
+
dir: path13.join(real(path13.resolve(root, common)), "workit"),
|
|
10819
10963
|
shared: true,
|
|
10820
10964
|
top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
|
|
10821
10965
|
};
|
|
@@ -10828,7 +10972,7 @@ function resolveStore(root) {
|
|
|
10828
10972
|
var rebasingBranch = (gitDir) => {
|
|
10829
10973
|
for (const state of ["rebase-merge", "rebase-apply"]) {
|
|
10830
10974
|
try {
|
|
10831
|
-
const ref = fs8.readFileSync(
|
|
10975
|
+
const ref = fs8.readFileSync(path13.join(gitDir, state, "head-name"), "utf8").trim();
|
|
10832
10976
|
const match = /^refs\/heads\/(.+)$/u.exec(ref);
|
|
10833
10977
|
if (match)
|
|
10834
10978
|
return match[1];
|
|
@@ -10843,7 +10987,7 @@ function resolveTaskKey(root, location) {
|
|
|
10843
10987
|
if (location.git && !location.git.reftable) {
|
|
10844
10988
|
let head = "";
|
|
10845
10989
|
try {
|
|
10846
|
-
head = fs8.readFileSync(
|
|
10990
|
+
head = fs8.readFileSync(path13.join(location.git.gitDir, "HEAD"), "utf8").trim();
|
|
10847
10991
|
} catch {}
|
|
10848
10992
|
const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
|
|
10849
10993
|
if (ref && ref[1] !== ".invalid")
|
|
@@ -10874,7 +11018,7 @@ function resolveTaskKey(root, location) {
|
|
|
10874
11018
|
return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
|
|
10875
11019
|
}
|
|
10876
11020
|
function checkoutRootOf(root, location) {
|
|
10877
|
-
const resolved =
|
|
11021
|
+
const resolved = path13.resolve(root);
|
|
10878
11022
|
let canonical = resolved;
|
|
10879
11023
|
try {
|
|
10880
11024
|
canonical = fs8.realpathSync(resolved);
|
|
@@ -10905,13 +11049,13 @@ function branchRenames(location) {
|
|
|
10905
11049
|
}
|
|
10906
11050
|
for (const entry of entries)
|
|
10907
11051
|
if (entry.isDirectory())
|
|
10908
|
-
walk(
|
|
11052
|
+
walk(path13.join(dir, entry.name));
|
|
10909
11053
|
else
|
|
10910
|
-
files.push(
|
|
11054
|
+
files.push(path13.join(dir, entry.name));
|
|
10911
11055
|
};
|
|
10912
|
-
walk(
|
|
11056
|
+
walk(path13.join(path13.dirname(location.dir), "logs", "refs", "heads"));
|
|
10913
11057
|
if (location.git)
|
|
10914
|
-
files.push(
|
|
11058
|
+
files.push(path13.join(location.git.gitDir, "logs", "HEAD"));
|
|
10915
11059
|
const seen = new Set;
|
|
10916
11060
|
const renames = [];
|
|
10917
11061
|
for (const file of files) {
|
|
@@ -10977,13 +11121,13 @@ function hostSessionFromEnv(env) {
|
|
|
10977
11121
|
}
|
|
10978
11122
|
return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
|
|
10979
11123
|
}
|
|
10980
|
-
var hash2 = (value) =>
|
|
11124
|
+
var hash2 = (value) => createHash11("sha256").update(value).digest("hex").slice(0, 32);
|
|
10981
11125
|
var PIN_FILE = "issued-registry";
|
|
10982
11126
|
var pinFiles = new Map;
|
|
10983
11127
|
var pinFile = (cwd) => {
|
|
10984
11128
|
if (cwd === undefined)
|
|
10985
11129
|
return null;
|
|
10986
|
-
const key =
|
|
11130
|
+
const key = path14.resolve(cwd);
|
|
10987
11131
|
const known = pinFiles.get(key);
|
|
10988
11132
|
if (known !== undefined)
|
|
10989
11133
|
return known;
|
|
@@ -10991,7 +11135,7 @@ var pinFile = (cwd) => {
|
|
|
10991
11135
|
const location = resolveStore(key);
|
|
10992
11136
|
if (location instanceof Error)
|
|
10993
11137
|
return null;
|
|
10994
|
-
const file = location.shared ?
|
|
11138
|
+
const file = location.shared ? path14.join(location.dir, "ledger", PIN_FILE) : null;
|
|
10995
11139
|
pinFiles.set(key, file);
|
|
10996
11140
|
return file;
|
|
10997
11141
|
} catch {
|
|
@@ -11004,14 +11148,14 @@ var pinnedStateDir = (cwd) => {
|
|
|
11004
11148
|
return null;
|
|
11005
11149
|
try {
|
|
11006
11150
|
const pinned = fs9.readFileSync(file, "utf8").trim();
|
|
11007
|
-
return
|
|
11151
|
+
return path14.isAbsolute(pinned) ? pinned : null;
|
|
11008
11152
|
} catch {
|
|
11009
11153
|
return null;
|
|
11010
11154
|
}
|
|
11011
11155
|
};
|
|
11012
11156
|
var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
|
|
11013
|
-
var userIssuedRoot = (cwd) =>
|
|
11014
|
-
var userTokenRoot = (cwd) =>
|
|
11157
|
+
var userIssuedRoot = (cwd) => path14.join(registryDir(cwd), "issued");
|
|
11158
|
+
var userTokenRoot = (cwd) => path14.join(registryDir(cwd), "issued-tokens");
|
|
11015
11159
|
function migrateRepoIssued(cwd) {
|
|
11016
11160
|
if (cwd === undefined)
|
|
11017
11161
|
return;
|
|
@@ -11020,7 +11164,7 @@ function migrateRepoIssued(cwd) {
|
|
|
11020
11164
|
const location = resolveStore(cwd);
|
|
11021
11165
|
if (location instanceof Error)
|
|
11022
11166
|
return;
|
|
11023
|
-
old =
|
|
11167
|
+
old = path14.join(location.dir, "hooks", "issued");
|
|
11024
11168
|
if (!fs9.existsSync(old))
|
|
11025
11169
|
return;
|
|
11026
11170
|
} catch {
|
|
@@ -11028,19 +11172,19 @@ function migrateRepoIssued(cwd) {
|
|
|
11028
11172
|
}
|
|
11029
11173
|
for (const lead of safeList(old)) {
|
|
11030
11174
|
try {
|
|
11031
|
-
const from =
|
|
11175
|
+
const from = path14.join(old, lead);
|
|
11032
11176
|
if (!fs9.statSync(from).isDirectory())
|
|
11033
11177
|
continue;
|
|
11034
|
-
const to =
|
|
11178
|
+
const to = path14.join(userIssuedRoot(cwd), lead);
|
|
11035
11179
|
fs9.mkdirSync(to, { recursive: true, mode: 448 });
|
|
11036
11180
|
for (const id of fs9.readdirSync(from)) {
|
|
11037
11181
|
try {
|
|
11038
|
-
fs9.copyFileSync(
|
|
11182
|
+
fs9.copyFileSync(path14.join(from, id), path14.join(to, id), fs9.constants.COPYFILE_EXCL);
|
|
11039
11183
|
} catch (error) {
|
|
11040
11184
|
if (error.code !== "EEXIST")
|
|
11041
11185
|
throw error;
|
|
11042
11186
|
}
|
|
11043
|
-
fs9.rmSync(
|
|
11187
|
+
fs9.rmSync(path14.join(from, id), { force: true });
|
|
11044
11188
|
}
|
|
11045
11189
|
removeIfEmpty(from);
|
|
11046
11190
|
} catch {}
|
|
@@ -11082,7 +11226,7 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
11082
11226
|
return null;
|
|
11083
11227
|
migrateRepoIssued(cwd);
|
|
11084
11228
|
try {
|
|
11085
|
-
return fs9.readFileSync(
|
|
11229
|
+
return fs9.readFileSync(path14.join(userIssuedRoot(cwd), hash2(claimed.slice(0, cut)), hash2(claimed)), "utf8");
|
|
11086
11230
|
} catch {
|
|
11087
11231
|
return null;
|
|
11088
11232
|
}
|
|
@@ -11092,9 +11236,9 @@ var issuedToken = (cwd, claimed) => {
|
|
|
11092
11236
|
const cut = claimed.lastIndexOf(":");
|
|
11093
11237
|
if (cut <= 0)
|
|
11094
11238
|
return { stored: null, leadBound: false };
|
|
11095
|
-
const dir =
|
|
11239
|
+
const dir = path14.join(userTokenRoot(cwd), hash2(claimed.slice(0, cut)));
|
|
11096
11240
|
try {
|
|
11097
|
-
const text = fs9.readFileSync(
|
|
11241
|
+
const text = fs9.readFileSync(path14.join(dir, hash2(claimed)), "utf8");
|
|
11098
11242
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
11099
11243
|
} catch {
|
|
11100
11244
|
return { stored: null, leadBound: safeList(dir).length > 0 };
|
|
@@ -11120,7 +11264,7 @@ function childSessionId(lead, child) {
|
|
|
11120
11264
|
// packages/workit-core/src/store/event-log.ts
|
|
11121
11265
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
11122
11266
|
import fs10 from "node:fs";
|
|
11123
|
-
import
|
|
11267
|
+
import path15 from "node:path";
|
|
11124
11268
|
var EVENT_VERSION = 1;
|
|
11125
11269
|
|
|
11126
11270
|
class LogDamage extends Error {
|
|
@@ -11231,7 +11375,7 @@ function appendEvent(file, event, validEnd) {
|
|
|
11231
11375
|
fs10.closeSync(fd);
|
|
11232
11376
|
}
|
|
11233
11377
|
if (created)
|
|
11234
|
-
fsyncDirectory(
|
|
11378
|
+
fsyncDirectory(path15.dirname(file));
|
|
11235
11379
|
return validEnd;
|
|
11236
11380
|
}
|
|
11237
11381
|
function replaceFile(file, bytes, durable) {
|
|
@@ -11247,7 +11391,7 @@ function replaceFile(file, bytes, durable) {
|
|
|
11247
11391
|
}
|
|
11248
11392
|
renameWithRetry(temporary, file);
|
|
11249
11393
|
if (durable)
|
|
11250
|
-
fsyncDirectory(
|
|
11394
|
+
fsyncDirectory(path15.dirname(file));
|
|
11251
11395
|
} catch (error) {
|
|
11252
11396
|
try {
|
|
11253
11397
|
fs10.unlinkSync(temporary);
|
|
@@ -11404,7 +11548,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
|
|
|
11404
11548
|
});
|
|
11405
11549
|
|
|
11406
11550
|
// packages/workit-core/src/store/reduce.ts
|
|
11407
|
-
import { createHash as
|
|
11551
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
11408
11552
|
var OPENING_TYPES = new Set([
|
|
11409
11553
|
"task.opened",
|
|
11410
11554
|
"task.imported",
|
|
@@ -11433,7 +11577,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
11433
11577
|
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");
|
|
11434
11578
|
var BLOB_REF = "$blob";
|
|
11435
11579
|
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;
|
|
11436
|
-
var blobDigest = (value) =>
|
|
11580
|
+
var blobDigest = (value) => createHash12("sha256").update(JSON.stringify(value)).digest("hex");
|
|
11437
11581
|
var toBlob = (value, blobs) => {
|
|
11438
11582
|
if (!isObject4(value))
|
|
11439
11583
|
return value;
|
|
@@ -11548,7 +11692,7 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
|
|
|
11548
11692
|
// packages/workit-core/src/core/task-read.ts
|
|
11549
11693
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
11550
11694
|
import * as fs15 from "node:fs";
|
|
11551
|
-
import
|
|
11695
|
+
import path19 from "node:path";
|
|
11552
11696
|
|
|
11553
11697
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
11554
11698
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -11599,7 +11743,7 @@ function sameFileIdentity(left, right, platform = process.platform) {
|
|
|
11599
11743
|
// node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
|
|
11600
11744
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
11601
11745
|
import fsSync from "node:fs";
|
|
11602
|
-
import
|
|
11746
|
+
import path16 from "node:path";
|
|
11603
11747
|
|
|
11604
11748
|
// node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
11605
11749
|
import fs11 from "node:fs";
|
|
@@ -11689,13 +11833,13 @@ ${ownershipToken}
|
|
|
11689
11833
|
return { raw, ownershipToken };
|
|
11690
11834
|
}
|
|
11691
11835
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
11692
|
-
const resolved =
|
|
11693
|
-
const lexicalRelative =
|
|
11694
|
-
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${
|
|
11695
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
11836
|
+
const resolved = path16.resolve(lockPath);
|
|
11837
|
+
const lexicalRelative = path16.relative(lockRoot.rootDir, resolved);
|
|
11838
|
+
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path16.sep}`) && !path16.isAbsolute(lexicalRelative) ? lexicalRelative : path16.relative(lockRoot.rootReal, resolved);
|
|
11839
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative)) {
|
|
11696
11840
|
throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
|
|
11697
11841
|
}
|
|
11698
|
-
return relative.split(
|
|
11842
|
+
return relative.split(path16.sep).join(path16.posix.sep);
|
|
11699
11843
|
}
|
|
11700
11844
|
function parseSidecarLockPayload(raw, parser) {
|
|
11701
11845
|
if (parser) {
|
|
@@ -11842,7 +11986,7 @@ function getFsSafeLockConfig() {
|
|
|
11842
11986
|
|
|
11843
11987
|
// node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
|
|
11844
11988
|
import fs13 from "node:fs";
|
|
11845
|
-
import
|
|
11989
|
+
import path17 from "node:path";
|
|
11846
11990
|
|
|
11847
11991
|
// node_modules/@openclaw/fs-safe/dist/timing.js
|
|
11848
11992
|
function sleepSync(ms) {
|
|
@@ -11933,26 +12077,26 @@ function canonicalLockParentSync(parent) {
|
|
|
11933
12077
|
return process.platform === "win32" ? fs13.realpathSync.native(parent) : fs13.realpathSync(parent);
|
|
11934
12078
|
}
|
|
11935
12079
|
function normalizeTargetPath(targetPath) {
|
|
11936
|
-
const resolved =
|
|
11937
|
-
fs13.mkdirSync(
|
|
12080
|
+
const resolved = path17.resolve(targetPath);
|
|
12081
|
+
fs13.mkdirSync(path17.dirname(resolved), { recursive: true });
|
|
11938
12082
|
try {
|
|
11939
|
-
return
|
|
12083
|
+
return path17.join(canonicalLockParentSync(path17.dirname(resolved)), path17.basename(resolved));
|
|
11940
12084
|
} catch {
|
|
11941
12085
|
return resolved;
|
|
11942
12086
|
}
|
|
11943
12087
|
}
|
|
11944
12088
|
function boundedLockPath(lockPath, lockRoot) {
|
|
11945
|
-
const resolved =
|
|
12089
|
+
const resolved = path17.resolve(lockPath);
|
|
11946
12090
|
if (!lockRoot)
|
|
11947
12091
|
return resolved;
|
|
11948
12092
|
relativeSidecarLockPath(lockRoot, resolved);
|
|
11949
|
-
const parent =
|
|
12093
|
+
const parent = path17.dirname(resolved);
|
|
11950
12094
|
const parentReal = canonicalLockParentSync(parent);
|
|
11951
|
-
const parentRelative =
|
|
11952
|
-
if (parentRelative === ".." || parentRelative.startsWith(`..${
|
|
12095
|
+
const parentRelative = path17.relative(lockRoot.rootReal, parentReal);
|
|
12096
|
+
if (parentRelative === ".." || parentRelative.startsWith(`..${path17.sep}`) || path17.isAbsolute(parentRelative)) {
|
|
11953
12097
|
throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
|
|
11954
12098
|
}
|
|
11955
|
-
return
|
|
12099
|
+
return path17.join(parentReal, path17.basename(resolved));
|
|
11956
12100
|
}
|
|
11957
12101
|
function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
11958
12102
|
const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
|
|
@@ -12153,20 +12297,20 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
12153
12297
|
}
|
|
12154
12298
|
// packages/workit-core/src/core/package-root.ts
|
|
12155
12299
|
import { existsSync as existsSync5 } from "node:fs";
|
|
12156
|
-
import
|
|
12300
|
+
import path18 from "node:path";
|
|
12157
12301
|
import { fileURLToPath } from "node:url";
|
|
12158
12302
|
var packageRoot = () => {
|
|
12159
|
-
let dir =
|
|
12303
|
+
let dir = path18.dirname(fileURLToPath(import.meta.url));
|
|
12160
12304
|
while (true) {
|
|
12161
|
-
const parent =
|
|
12162
|
-
if (existsSync5(
|
|
12305
|
+
const parent = path18.dirname(dir);
|
|
12306
|
+
if (existsSync5(path18.join(dir, "package.json")) || parent === dir)
|
|
12163
12307
|
return dir;
|
|
12164
12308
|
dir = parent;
|
|
12165
12309
|
}
|
|
12166
12310
|
};
|
|
12167
12311
|
var assetRoot = () => {
|
|
12168
12312
|
const root = packageRoot();
|
|
12169
|
-
const assets =
|
|
12313
|
+
const assets = path18.join(root, "assets");
|
|
12170
12314
|
return existsSync5(assets) ? assets : root;
|
|
12171
12315
|
};
|
|
12172
12316
|
|
|
@@ -12374,7 +12518,7 @@ var cachedRuntimeVersion = null;
|
|
|
12374
12518
|
var runtimeVersion = () => {
|
|
12375
12519
|
if (cachedRuntimeVersion === null) {
|
|
12376
12520
|
try {
|
|
12377
|
-
const pkg = JSON.parse(fs15.readFileSync(
|
|
12521
|
+
const pkg = JSON.parse(fs15.readFileSync(path19.join(packageRoot(), "package.json"), "utf8"));
|
|
12378
12522
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
12379
12523
|
} catch {
|
|
12380
12524
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -12403,7 +12547,7 @@ var readText2 = (file) => {
|
|
|
12403
12547
|
};
|
|
12404
12548
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
12405
12549
|
var branchStart = (location, branch, aliases) => {
|
|
12406
|
-
const first = readText2(
|
|
12550
|
+
const first = readText2(path19.join(path19.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
12407
12551
|
`, 1)[0];
|
|
12408
12552
|
const created = REFLOG_LINE.exec(first);
|
|
12409
12553
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -12413,7 +12557,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
12413
12557
|
return start;
|
|
12414
12558
|
if (!location.git)
|
|
12415
12559
|
return null;
|
|
12416
|
-
for (const line of readText2(
|
|
12560
|
+
for (const line of readText2(path19.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
12417
12561
|
`)) {
|
|
12418
12562
|
const entry = REFLOG_LINE.exec(line);
|
|
12419
12563
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -12423,14 +12567,14 @@ var branchStart = (location, branch, aliases) => {
|
|
|
12423
12567
|
}
|
|
12424
12568
|
return null;
|
|
12425
12569
|
};
|
|
12426
|
-
var refExists2 = (common, ref) => fs15.existsSync(
|
|
12570
|
+
var refExists2 = (common, ref) => fs15.existsSync(path19.join(common, ref)) || readText2(path19.join(common, "packed-refs")).includes(` ${ref}
|
|
12427
12571
|
`);
|
|
12428
12572
|
var origins = new Map;
|
|
12429
12573
|
var sameDirectoryIdentity = (left, right) => {
|
|
12430
|
-
if (!
|
|
12574
|
+
if (!path19.isAbsolute(left) || !path19.isAbsolute(right))
|
|
12431
12575
|
return false;
|
|
12432
|
-
const normalizedLeft =
|
|
12433
|
-
const normalizedRight =
|
|
12576
|
+
const normalizedLeft = path19.resolve(left);
|
|
12577
|
+
const normalizedRight = path19.resolve(right);
|
|
12434
12578
|
try {
|
|
12435
12579
|
const a = fs15.statSync(normalizedLeft, { bigint: true });
|
|
12436
12580
|
const b = fs15.statSync(normalizedRight, { bigint: true });
|
|
@@ -12464,14 +12608,14 @@ class TaskReader {
|
|
|
12464
12608
|
located;
|
|
12465
12609
|
migrationChecked = false;
|
|
12466
12610
|
constructor(root, options = {}) {
|
|
12467
|
-
const resolved =
|
|
12611
|
+
const resolved = path19.resolve(root);
|
|
12468
12612
|
this.origin = fs15.existsSync(resolved) ? fs15.realpathSync(resolved) : resolved;
|
|
12469
12613
|
this.located = resolveStore(this.origin);
|
|
12470
12614
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
12471
12615
|
this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
|
|
12472
12616
|
}
|
|
12473
12617
|
location() {
|
|
12474
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs15.existsSync(
|
|
12618
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs15.existsSync(path19.join(this.root, ".git"))) {
|
|
12475
12619
|
this.located = undefined;
|
|
12476
12620
|
this.migrationChecked = false;
|
|
12477
12621
|
}
|
|
@@ -12629,14 +12773,14 @@ class TaskReader {
|
|
|
12629
12773
|
const branch = key.ok ? key.data.branch : null;
|
|
12630
12774
|
if (!branch || !location.ok)
|
|
12631
12775
|
return success(null, null, null);
|
|
12632
|
-
const common =
|
|
12633
|
-
const heads =
|
|
12634
|
-
const headLog = location.data.git ?
|
|
12776
|
+
const common = path19.dirname(location.data.dir);
|
|
12777
|
+
const heads = path19.join(common, "logs", "refs", "heads");
|
|
12778
|
+
const headLog = location.data.git ? path19.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
12635
12779
|
const signatures = [
|
|
12636
|
-
|
|
12780
|
+
path19.join(heads, branch),
|
|
12637
12781
|
headLog,
|
|
12638
12782
|
heads,
|
|
12639
|
-
|
|
12783
|
+
path19.join(common, "packed-refs")
|
|
12640
12784
|
].map((file) => fileSignature(file) ?? "-");
|
|
12641
12785
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
12642
12786
|
let resolved = origins.get(slot);
|
|
@@ -12648,7 +12792,7 @@ class TaskReader {
|
|
|
12648
12792
|
aliases.push(rename.from);
|
|
12649
12793
|
const start = branchStart(location.data, branch, aliases);
|
|
12650
12794
|
const slash = start?.indexOf("/") ?? -1;
|
|
12651
|
-
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(
|
|
12795
|
+
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path19.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
|
|
12652
12796
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
12653
12797
|
resolved = {
|
|
12654
12798
|
signature: signatures.join("|"),
|
|
@@ -12668,27 +12812,27 @@ class TaskReader {
|
|
|
12668
12812
|
}
|
|
12669
12813
|
paths() {
|
|
12670
12814
|
const location = this.location();
|
|
12671
|
-
const dir = location.ok ? location.data.dir :
|
|
12672
|
-
const checkout =
|
|
12815
|
+
const dir = location.ok ? location.data.dir : path19.join(this.root, ".workit");
|
|
12816
|
+
const checkout = path19.join(dir, "checkouts", checkoutSlug(this.root));
|
|
12673
12817
|
return {
|
|
12674
12818
|
dir,
|
|
12675
12819
|
shared: location.ok ? location.data.shared : false,
|
|
12676
|
-
marker:
|
|
12820
|
+
marker: path19.join(dir, "store.json"),
|
|
12677
12821
|
checkout,
|
|
12678
|
-
workspace:
|
|
12679
|
-
checkoutLock:
|
|
12680
|
-
tasks:
|
|
12681
|
-
index:
|
|
12682
|
-
blobs:
|
|
12683
|
-
legacy:
|
|
12684
|
-
v2:
|
|
12822
|
+
workspace: path19.join(checkout, "workspace.json"),
|
|
12823
|
+
checkoutLock: path19.join(checkout, "metadata.lock"),
|
|
12824
|
+
tasks: path19.join(dir, "tasks"),
|
|
12825
|
+
index: path19.join(dir, "task-index.json"),
|
|
12826
|
+
blobs: path19.join(dir, "blobs", "candidates"),
|
|
12827
|
+
legacy: path19.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
12828
|
+
v2: path19.join(this.root, ".workit")
|
|
12685
12829
|
};
|
|
12686
12830
|
}
|
|
12687
12831
|
eventsPath(taskId) {
|
|
12688
|
-
return
|
|
12832
|
+
return path19.join(this.paths().tasks, taskId, "events.jsonl");
|
|
12689
12833
|
}
|
|
12690
12834
|
snapshotPath(taskId) {
|
|
12691
|
-
return
|
|
12835
|
+
return path19.join(this.paths().tasks, taskId, "snapshot.json");
|
|
12692
12836
|
}
|
|
12693
12837
|
ready(write = false) {
|
|
12694
12838
|
const location = this.location();
|
|
@@ -12723,7 +12867,7 @@ class TaskReader {
|
|
|
12723
12867
|
return {
|
|
12724
12868
|
read: (digest) => {
|
|
12725
12869
|
try {
|
|
12726
|
-
return JSON.parse(fs15.readFileSync(
|
|
12870
|
+
return JSON.parse(fs15.readFileSync(path19.join(dir, `${digest}.json`), "utf8"));
|
|
12727
12871
|
} catch (error) {
|
|
12728
12872
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
12729
12873
|
}
|
|
@@ -12889,11 +13033,11 @@ class TaskReader {
|
|
|
12889
13033
|
return failure2("recovery_required", `${label} record does not satisfy its schema`);
|
|
12890
13034
|
}
|
|
12891
13035
|
v2Dirs() {
|
|
12892
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
13036
|
+
return [...new Set([this.root, this.origin])].map((dir) => path19.join(dir, ".workit"));
|
|
12893
13037
|
}
|
|
12894
13038
|
pendingMigrations() {
|
|
12895
13039
|
return this.v2Dirs().filter((dir) => {
|
|
12896
|
-
const raw = this.readV2Workspace(
|
|
13040
|
+
const raw = this.readV2Workspace(path19.join(dir, "workspace.json"));
|
|
12897
13041
|
return raw !== null && raw !== TOMBSTONE;
|
|
12898
13042
|
});
|
|
12899
13043
|
}
|
|
@@ -12909,7 +13053,7 @@ class TaskReader {
|
|
|
12909
13053
|
}
|
|
12910
13054
|
adoptStoreFrom(local) {
|
|
12911
13055
|
const dirs = this.paths();
|
|
12912
|
-
const marker =
|
|
13056
|
+
const marker = path19.join(local, "store.json");
|
|
12913
13057
|
if (!fs15.existsSync(marker))
|
|
12914
13058
|
return success(null, null, null);
|
|
12915
13059
|
return this.withLock(dirs.checkoutLock, () => {
|
|
@@ -12919,7 +13063,7 @@ class TaskReader {
|
|
|
12919
13063
|
try {
|
|
12920
13064
|
const merge = (from, to) => {
|
|
12921
13065
|
if (!fs15.existsSync(to)) {
|
|
12922
|
-
fs15.mkdirSync(
|
|
13066
|
+
fs15.mkdirSync(path19.dirname(to), { recursive: true });
|
|
12923
13067
|
try {
|
|
12924
13068
|
fs15.renameSync(from, to);
|
|
12925
13069
|
} catch {
|
|
@@ -12930,24 +13074,24 @@ class TaskReader {
|
|
|
12930
13074
|
}
|
|
12931
13075
|
if (fs15.lstatSync(from).isDirectory() && fs15.lstatSync(to).isDirectory())
|
|
12932
13076
|
for (const name of fs15.readdirSync(from))
|
|
12933
|
-
merge(
|
|
13077
|
+
merge(path19.join(from, name), path19.join(to, name));
|
|
12934
13078
|
};
|
|
12935
13079
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
12936
|
-
const from =
|
|
13080
|
+
const from = path19.join(local, sub);
|
|
12937
13081
|
if (!fs15.existsSync(from))
|
|
12938
13082
|
continue;
|
|
12939
13083
|
if (sub === "tasks") {
|
|
12940
13084
|
for (const name of fs15.readdirSync(from))
|
|
12941
|
-
if (validId(name) && !fs15.existsSync(
|
|
13085
|
+
if (validId(name) && !fs15.existsSync(path19.join(dirs.dir, sub, name)))
|
|
12942
13086
|
tasks += 1;
|
|
12943
13087
|
}
|
|
12944
|
-
merge(from,
|
|
13088
|
+
merge(from, path19.join(dirs.dir, sub));
|
|
12945
13089
|
}
|
|
12946
|
-
const ledger =
|
|
12947
|
-
if (fs15.existsSync(ledger) && !fs15.existsSync(
|
|
12948
|
-
merge(ledger,
|
|
12949
|
-
fs15.rmSync(
|
|
12950
|
-
fs15.renameSync(marker,
|
|
13090
|
+
const ledger = path19.join(local, "ledger");
|
|
13091
|
+
if (fs15.existsSync(ledger) && !fs15.existsSync(path19.join(dirs.dir, "ledger")))
|
|
13092
|
+
merge(ledger, path19.join(dirs.dir, "ledger"));
|
|
13093
|
+
fs15.rmSync(path19.join(local, "task-index.json"), { force: true });
|
|
13094
|
+
fs15.renameSync(marker, path19.join(local, "store.moved.json"));
|
|
12951
13095
|
} catch (error) {
|
|
12952
13096
|
return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
|
|
12953
13097
|
path: local
|
|
@@ -12985,7 +13129,7 @@ class TaskReader {
|
|
|
12985
13129
|
schemaVersion: SCHEMA_VERSION,
|
|
12986
13130
|
id: workspaceId ?? newId(),
|
|
12987
13131
|
revision: newRevision(),
|
|
12988
|
-
root:
|
|
13132
|
+
root: path19.dirname(v2),
|
|
12989
13133
|
runtime: { createdWith: version, updatedWith: version },
|
|
12990
13134
|
writer: null,
|
|
12991
13135
|
store: {
|
|
@@ -12997,11 +13141,11 @@ class TaskReader {
|
|
|
12997
13141
|
critical: ["store"]
|
|
12998
13142
|
};
|
|
12999
13143
|
fs15.mkdirSync(v2, { recursive: true });
|
|
13000
|
-
const ignore =
|
|
13144
|
+
const ignore = path19.join(v2, ".gitignore");
|
|
13001
13145
|
if (!fs15.existsSync(ignore))
|
|
13002
13146
|
fs15.writeFileSync(ignore, `*
|
|
13003
13147
|
`);
|
|
13004
|
-
replaceFile(
|
|
13148
|
+
replaceFile(path19.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
13005
13149
|
`, true);
|
|
13006
13150
|
}
|
|
13007
13151
|
initializeStorage() {
|
|
@@ -13060,7 +13204,7 @@ class TaskReader {
|
|
|
13060
13204
|
withLock(lockPath, operation) {
|
|
13061
13205
|
try {
|
|
13062
13206
|
this.initializeStorage();
|
|
13063
|
-
fs15.mkdirSync(
|
|
13207
|
+
fs15.mkdirSync(path19.dirname(lockPath), { recursive: true });
|
|
13064
13208
|
} catch (error) {
|
|
13065
13209
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
13066
13210
|
path: this.paths().dir
|
|
@@ -13123,7 +13267,7 @@ class TaskReader {
|
|
|
13123
13267
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
13124
13268
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
13125
13269
|
path: lockPath,
|
|
13126
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
13270
|
+
guidance: `Check permissions and the read-only attribute on ${path19.dirname(lockPath)}.`
|
|
13127
13271
|
});
|
|
13128
13272
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
13129
13273
|
let lock = null;
|
|
@@ -13178,7 +13322,7 @@ var moveInto = (from, to) => {
|
|
|
13178
13322
|
target = `${to}.dir`;
|
|
13179
13323
|
fs16.mkdirSync(target, { recursive: true });
|
|
13180
13324
|
for (const name of fs16.readdirSync(from))
|
|
13181
|
-
moveInto(
|
|
13325
|
+
moveInto(path20.join(from, name), path20.join(target, name));
|
|
13182
13326
|
fs16.rmdirSync(from);
|
|
13183
13327
|
return;
|
|
13184
13328
|
}
|
|
@@ -13189,13 +13333,13 @@ var moveInto = (from, to) => {
|
|
|
13189
13333
|
fs16.rmSync(from);
|
|
13190
13334
|
return;
|
|
13191
13335
|
}
|
|
13192
|
-
target = `${to}.${
|
|
13336
|
+
target = `${to}.${createHash13("sha256").update(bytes).digest("hex").slice(0, 12)}`;
|
|
13193
13337
|
if (fs16.existsSync(target)) {
|
|
13194
13338
|
fs16.rmSync(from);
|
|
13195
13339
|
return;
|
|
13196
13340
|
}
|
|
13197
13341
|
}
|
|
13198
|
-
fs16.mkdirSync(
|
|
13342
|
+
fs16.mkdirSync(path20.dirname(target), { recursive: true });
|
|
13199
13343
|
try {
|
|
13200
13344
|
fs16.renameSync(from, target);
|
|
13201
13345
|
} catch {
|
|
@@ -13263,7 +13407,7 @@ class TaskStore extends TaskReader {
|
|
|
13263
13407
|
const moved = this.bindLocked(again.data.id, key, input.now);
|
|
13264
13408
|
return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
|
|
13265
13409
|
}
|
|
13266
|
-
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" :
|
|
13410
|
+
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path20.basename(this.root) || this.root;
|
|
13267
13411
|
const intent = {
|
|
13268
13412
|
objective: input.objective?.trim() || `Work on ${label}`,
|
|
13269
13413
|
scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
|
|
@@ -13511,13 +13655,13 @@ class TaskStore extends TaskReader {
|
|
|
13511
13655
|
if (!ready.ok)
|
|
13512
13656
|
return ready;
|
|
13513
13657
|
const dirs = this.paths();
|
|
13514
|
-
const recovery = [
|
|
13658
|
+
const recovery = [path20.join(this.root, ".workit", "recovery"), path20.join(dirs.legacy, "recovery")].find((dir) => fs16.existsSync(dir)) ?? null;
|
|
13515
13659
|
if (recovery) {
|
|
13516
13660
|
let files = 0;
|
|
13517
13661
|
let bytes = 0;
|
|
13518
13662
|
try {
|
|
13519
13663
|
for (const name of fs16.readdirSync(recovery)) {
|
|
13520
|
-
const stat = fs16.lstatSync(
|
|
13664
|
+
const stat = fs16.lstatSync(path20.join(recovery, name));
|
|
13521
13665
|
if (!stat.isFile())
|
|
13522
13666
|
continue;
|
|
13523
13667
|
files += 1;
|
|
@@ -13570,7 +13714,7 @@ class TaskStore extends TaskReader {
|
|
|
13570
13714
|
if (fs16.existsSync(dirs.blobs))
|
|
13571
13715
|
for (const name of fs16.readdirSync(dirs.blobs)) {
|
|
13572
13716
|
const digest = name.replace(/\.json$/, "");
|
|
13573
|
-
const file =
|
|
13717
|
+
const file = path20.join(dirs.blobs, name);
|
|
13574
13718
|
let stat;
|
|
13575
13719
|
try {
|
|
13576
13720
|
stat = fs16.lstatSync(file);
|
|
@@ -13588,7 +13732,7 @@ class TaskStore extends TaskReader {
|
|
|
13588
13732
|
}
|
|
13589
13733
|
return success(null, null, null);
|
|
13590
13734
|
};
|
|
13591
|
-
const swept = dryRun ? sweep() : this.withLock(
|
|
13735
|
+
const swept = dryRun ? sweep() : this.withLock(path20.join(dirs.dir, "gc.lock"), sweep);
|
|
13592
13736
|
if (!swept.ok)
|
|
13593
13737
|
return swept;
|
|
13594
13738
|
const temporaryDirs = [
|
|
@@ -13596,7 +13740,7 @@ class TaskStore extends TaskReader {
|
|
|
13596
13740
|
dirs.tasks,
|
|
13597
13741
|
dirs.blobs,
|
|
13598
13742
|
dirs.checkout,
|
|
13599
|
-
...names.map((name) =>
|
|
13743
|
+
...names.map((name) => path20.join(dirs.tasks, name))
|
|
13600
13744
|
];
|
|
13601
13745
|
for (const directory of temporaryDirs) {
|
|
13602
13746
|
if (!fs16.existsSync(directory))
|
|
@@ -13604,7 +13748,7 @@ class TaskStore extends TaskReader {
|
|
|
13604
13748
|
for (const name of fs16.readdirSync(directory)) {
|
|
13605
13749
|
if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
|
|
13606
13750
|
continue;
|
|
13607
|
-
const file =
|
|
13751
|
+
const file = path20.join(directory, name);
|
|
13608
13752
|
try {
|
|
13609
13753
|
const stat = fs16.lstatSync(file);
|
|
13610
13754
|
if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
|
|
@@ -13620,7 +13764,7 @@ class TaskStore extends TaskReader {
|
|
|
13620
13764
|
return success(null, null, report);
|
|
13621
13765
|
}
|
|
13622
13766
|
taskLockPath(taskId) {
|
|
13623
|
-
return
|
|
13767
|
+
return path20.join(this.paths().tasks, taskId, "lock");
|
|
13624
13768
|
}
|
|
13625
13769
|
settleMigrations(write) {
|
|
13626
13770
|
const moved = this.adoptLocalStore();
|
|
@@ -13649,7 +13793,7 @@ class TaskStore extends TaskReader {
|
|
|
13649
13793
|
return {
|
|
13650
13794
|
read: (digest) => reader.read(digest),
|
|
13651
13795
|
write: (digest, value) => {
|
|
13652
|
-
const file =
|
|
13796
|
+
const file = path20.join(dir, `${digest}.json`);
|
|
13653
13797
|
if (fs16.existsSync(file)) {
|
|
13654
13798
|
const stamp = new Date;
|
|
13655
13799
|
try {
|
|
@@ -13751,7 +13895,7 @@ class TaskStore extends TaskReader {
|
|
|
13751
13895
|
}
|
|
13752
13896
|
}
|
|
13753
13897
|
openTask(record, type, key, legacy = null) {
|
|
13754
|
-
const dir =
|
|
13898
|
+
const dir = path20.join(this.paths().tasks, record.id);
|
|
13755
13899
|
fs16.mkdirSync(dir, { recursive: true });
|
|
13756
13900
|
const blobs = this.blobStore();
|
|
13757
13901
|
const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
|
|
@@ -13831,8 +13975,8 @@ class TaskStore extends TaskReader {
|
|
|
13831
13975
|
}
|
|
13832
13976
|
}
|
|
13833
13977
|
withKeyLock(key, operation) {
|
|
13834
|
-
const digest =
|
|
13835
|
-
return this.withLock(
|
|
13978
|
+
const digest = createHash13("sha256").update(key).digest("hex").slice(0, 32);
|
|
13979
|
+
return this.withLock(path20.join(this.paths().dir, "keys", `${digest}.lock`), operation);
|
|
13836
13980
|
}
|
|
13837
13981
|
bindLocked(taskId, key, timestamp) {
|
|
13838
13982
|
const current = this.readWorkspace();
|
|
@@ -13973,7 +14117,7 @@ class TaskStore extends TaskReader {
|
|
|
13973
14117
|
writeWorkspace(record) {
|
|
13974
14118
|
const file = this.paths().workspace;
|
|
13975
14119
|
try {
|
|
13976
|
-
fs16.mkdirSync(
|
|
14120
|
+
fs16.mkdirSync(path20.dirname(file), { recursive: true });
|
|
13977
14121
|
replaceFile(file, `${canonicalJson(record)}
|
|
13978
14122
|
`, true);
|
|
13979
14123
|
return success(null, null, null);
|
|
@@ -13999,13 +14143,13 @@ class TaskStore extends TaskReader {
|
|
|
13999
14143
|
}
|
|
14000
14144
|
migrateV2(v2) {
|
|
14001
14145
|
const dirs = this.paths();
|
|
14002
|
-
const v2Workspace =
|
|
14003
|
-
const v2Tasks =
|
|
14004
|
-
const legacy =
|
|
14146
|
+
const v2Workspace = path20.join(v2, "workspace.json");
|
|
14147
|
+
const v2Tasks = path20.join(v2, "tasks");
|
|
14148
|
+
const legacy = path20.join(dirs.dir, "legacy", checkoutSlug(path20.dirname(v2)), "v2");
|
|
14005
14149
|
const raw = this.readV2Workspace(v2Workspace);
|
|
14006
14150
|
if (raw === null || raw === TOMBSTONE)
|
|
14007
14151
|
return success(null, null, null);
|
|
14008
|
-
return this.withLock(dirs.checkoutLock, () => this.withLock(
|
|
14152
|
+
return this.withLock(dirs.checkoutLock, () => this.withLock(path20.join(v2, "metadata.lock"), () => {
|
|
14009
14153
|
const workspace = this.readV2Workspace(v2Workspace);
|
|
14010
14154
|
if (workspace === null || workspace === TOMBSTONE)
|
|
14011
14155
|
return success(null, null, null);
|
|
@@ -14014,7 +14158,7 @@ class TaskStore extends TaskReader {
|
|
|
14014
14158
|
return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
|
|
14015
14159
|
let files = [];
|
|
14016
14160
|
try {
|
|
14017
|
-
files = fs16.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(
|
|
14161
|
+
files = fs16.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path20.join(v2Tasks, name)));
|
|
14018
14162
|
} catch {}
|
|
14019
14163
|
const current = this.readWorkspace();
|
|
14020
14164
|
if (!current.ok)
|
|
@@ -14032,21 +14176,21 @@ class TaskStore extends TaskReader {
|
|
|
14032
14176
|
let skipped = 0;
|
|
14033
14177
|
const done = new Map;
|
|
14034
14178
|
try {
|
|
14035
|
-
fs16.mkdirSync(
|
|
14179
|
+
fs16.mkdirSync(path20.join(legacy, "tasks"), { recursive: true });
|
|
14036
14180
|
for (const name of ["workspace.json", "index.json"])
|
|
14037
|
-
if (fs16.existsSync(
|
|
14038
|
-
fs16.copyFileSync(
|
|
14181
|
+
if (fs16.existsSync(path20.join(v2, name)))
|
|
14182
|
+
fs16.copyFileSync(path20.join(v2, name), path20.join(legacy, name));
|
|
14039
14183
|
for (const name of files) {
|
|
14040
14184
|
const id = name.slice(0, -5);
|
|
14041
|
-
const file =
|
|
14185
|
+
const file = path20.join(v2Tasks, name);
|
|
14042
14186
|
const bytes = fs16.readFileSync(file, "utf8");
|
|
14043
14187
|
const digest = sha256(bytes);
|
|
14044
|
-
fs16.writeFileSync(
|
|
14188
|
+
fs16.writeFileSync(path20.join(legacy, "tasks", name), bytes);
|
|
14045
14189
|
const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
|
|
14046
14190
|
if (!parsed.ok || parsed.data.id !== id)
|
|
14047
14191
|
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 });
|
|
14048
14192
|
const record = { ...parsed.data, workspaceId: target.id };
|
|
14049
|
-
const origin = { path:
|
|
14193
|
+
const origin = { path: path20.join(legacy, "tasks", name), digest };
|
|
14050
14194
|
if (!fs16.existsSync(this.eventsPath(id))) {
|
|
14051
14195
|
this.openTask(record, "migrated.from_v2", null, origin);
|
|
14052
14196
|
migrated += 1;
|
|
@@ -14082,7 +14226,7 @@ class TaskStore extends TaskReader {
|
|
|
14082
14226
|
try {
|
|
14083
14227
|
let complete = true;
|
|
14084
14228
|
for (const [name, digest] of done) {
|
|
14085
|
-
const file =
|
|
14229
|
+
const file = path20.join(v2Tasks, name);
|
|
14086
14230
|
if (sha256(fs16.readFileSync(file, "utf8")) !== digest) {
|
|
14087
14231
|
complete = false;
|
|
14088
14232
|
continue;
|
|
@@ -14096,7 +14240,7 @@ class TaskStore extends TaskReader {
|
|
|
14096
14240
|
return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
|
|
14097
14241
|
path: v2
|
|
14098
14242
|
});
|
|
14099
|
-
fs16.rmSync(
|
|
14243
|
+
fs16.rmSync(path20.join(v2, "index.json"), { force: true });
|
|
14100
14244
|
if (dirs.shared)
|
|
14101
14245
|
fs16.rmSync(v2Workspace, { force: true });
|
|
14102
14246
|
else
|
|
@@ -14121,8 +14265,8 @@ class TaskStore extends TaskReader {
|
|
|
14121
14265
|
const dirs = this.paths();
|
|
14122
14266
|
if (!dirs.shared)
|
|
14123
14267
|
return success(null, null, null);
|
|
14124
|
-
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs16.existsSync(
|
|
14125
|
-
const ignore =
|
|
14268
|
+
const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs16.existsSync(path20.join(v2, name)));
|
|
14269
|
+
const ignore = path20.join(v2, ".gitignore");
|
|
14126
14270
|
const onlyGeneratedIgnore = () => {
|
|
14127
14271
|
try {
|
|
14128
14272
|
return fs16.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs16.readFileSync(ignore, "utf8"));
|
|
@@ -14132,12 +14276,12 @@ class TaskStore extends TaskReader {
|
|
|
14132
14276
|
};
|
|
14133
14277
|
if (present().length === 0 && !onlyGeneratedIgnore())
|
|
14134
14278
|
return success(null, null, null);
|
|
14135
|
-
const backup =
|
|
14279
|
+
const backup = path20.join(dirs.dir, "legacy", checkoutSlug(path20.dirname(v2)), "v2");
|
|
14136
14280
|
return this.withLock(dirs.checkoutLock, () => {
|
|
14137
14281
|
let moved = 0;
|
|
14138
14282
|
try {
|
|
14139
14283
|
for (const name of present()) {
|
|
14140
|
-
const entry =
|
|
14284
|
+
const entry = path20.join(v2, name);
|
|
14141
14285
|
const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
|
|
14142
14286
|
const empty = fs16.lstatSync(entry).isDirectory() && fs16.readdirSync(entry).length === 0;
|
|
14143
14287
|
if (marker || empty) {
|
|
@@ -14146,18 +14290,18 @@ class TaskStore extends TaskReader {
|
|
|
14146
14290
|
}
|
|
14147
14291
|
if (name === "tasks" && fs16.lstatSync(entry).isDirectory()) {
|
|
14148
14292
|
for (const task of fs16.readdirSync(entry)) {
|
|
14149
|
-
const file =
|
|
14293
|
+
const file = path20.join(entry, task);
|
|
14150
14294
|
if (fs16.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
|
|
14151
14295
|
fs16.rmSync(file);
|
|
14152
14296
|
else {
|
|
14153
|
-
moveInto(file,
|
|
14297
|
+
moveInto(file, path20.join(backup, "tasks", task));
|
|
14154
14298
|
moved += 1;
|
|
14155
14299
|
}
|
|
14156
14300
|
}
|
|
14157
14301
|
fs16.rmdirSync(entry);
|
|
14158
14302
|
continue;
|
|
14159
14303
|
}
|
|
14160
|
-
moveInto(entry,
|
|
14304
|
+
moveInto(entry, path20.join(backup, name));
|
|
14161
14305
|
moved += 1;
|
|
14162
14306
|
}
|
|
14163
14307
|
if (onlyGeneratedIgnore())
|
|
@@ -14199,22 +14343,22 @@ var workerBlocksTransition = (transition, state) => transition === "pause" ? fal
|
|
|
14199
14343
|
var holdsLiveState = (state, dirty) => state === "running" || dirty === true;
|
|
14200
14344
|
|
|
14201
14345
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
14202
|
-
import { createHash as
|
|
14346
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
14203
14347
|
import * as fs19 from "node:fs";
|
|
14204
14348
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
14205
|
-
import
|
|
14349
|
+
import path25 from "node:path";
|
|
14206
14350
|
|
|
14207
14351
|
// packages/workit-core/src/check-config.ts
|
|
14208
14352
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
14209
14353
|
import fs17 from "node:fs";
|
|
14210
|
-
import
|
|
14354
|
+
import path21 from "node:path";
|
|
14211
14355
|
var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
|
|
14212
14356
|
var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
|
|
14213
14357
|
var CHECKS_FILE = ".workit/checks.json";
|
|
14214
14358
|
var LEGACY_CHECKS_FILE = "workit.checks.json";
|
|
14215
14359
|
function checksConfigFile(root) {
|
|
14216
|
-
const current =
|
|
14217
|
-
const legacy =
|
|
14360
|
+
const current = path21.join(root, CHECKS_FILE);
|
|
14361
|
+
const legacy = path21.join(root, LEGACY_CHECKS_FILE);
|
|
14218
14362
|
return !fs17.existsSync(current) && fs17.existsSync(legacy) ? legacy : current;
|
|
14219
14363
|
}
|
|
14220
14364
|
var GENERATED_GITIGNORES2 = new Set([`*
|
|
@@ -14283,10 +14427,10 @@ var git3 = (cwd, args) => {
|
|
|
14283
14427
|
return value || null;
|
|
14284
14428
|
};
|
|
14285
14429
|
function checkRoot(cwd) {
|
|
14286
|
-
return
|
|
14430
|
+
return path21.resolve(gitDirs(cwd)?.top ?? cwd);
|
|
14287
14431
|
}
|
|
14288
14432
|
var packageManager = (root) => {
|
|
14289
|
-
const has = (file) => fs17.existsSync(
|
|
14433
|
+
const has = (file) => fs17.existsSync(path21.join(root, file));
|
|
14290
14434
|
if (has("bun.lock") || has("bun.lockb"))
|
|
14291
14435
|
return "bun";
|
|
14292
14436
|
if (has("pnpm-lock.yaml"))
|
|
@@ -14306,7 +14450,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
|
|
|
14306
14450
|
function detectedChecks(root) {
|
|
14307
14451
|
const read = (file) => {
|
|
14308
14452
|
try {
|
|
14309
|
-
return fs17.readFileSync(
|
|
14453
|
+
return fs17.readFileSync(path21.join(root, file), "utf8");
|
|
14310
14454
|
} catch {
|
|
14311
14455
|
return null;
|
|
14312
14456
|
}
|
|
@@ -14381,10 +14525,10 @@ function configFileFor(root) {
|
|
|
14381
14525
|
if (fs17.existsSync(own))
|
|
14382
14526
|
return own;
|
|
14383
14527
|
const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
14384
|
-
if (!common ||
|
|
14528
|
+
if (!common || path21.basename(common) !== ".git")
|
|
14385
14529
|
return own;
|
|
14386
|
-
const main =
|
|
14387
|
-
if (
|
|
14530
|
+
const main = path21.dirname(common);
|
|
14531
|
+
if (path21.resolve(main) === path21.resolve(root))
|
|
14388
14532
|
return own;
|
|
14389
14533
|
const shared = checksConfigFile(main);
|
|
14390
14534
|
return fs17.existsSync(shared) ? shared : own;
|
|
@@ -14392,7 +14536,7 @@ function configFileFor(root) {
|
|
|
14392
14536
|
function loadCheckConfig(cwd) {
|
|
14393
14537
|
const root = checkRoot(cwd);
|
|
14394
14538
|
const file = configFileFor(root);
|
|
14395
|
-
const legacy =
|
|
14539
|
+
const legacy = path21.basename(file) === LEGACY_CHECKS_FILE;
|
|
14396
14540
|
const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
|
|
14397
14541
|
const note = legacy ? {
|
|
14398
14542
|
note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
|
|
@@ -14523,10 +14667,10 @@ function workitAvailable(env = process.env) {
|
|
|
14523
14667
|
return workitOnPath;
|
|
14524
14668
|
const windows = process.platform === "win32";
|
|
14525
14669
|
const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
14526
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
14670
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path21.delimiter).filter(Boolean);
|
|
14527
14671
|
workitOnPath = dirs.some((dir) => exts.some((ext) => {
|
|
14528
14672
|
try {
|
|
14529
|
-
return fs17.statSync(
|
|
14673
|
+
return fs17.statSync(path21.join(dir, `workit${ext}`)).isFile();
|
|
14530
14674
|
} catch {
|
|
14531
14675
|
return false;
|
|
14532
14676
|
}
|
|
@@ -14596,14 +14740,14 @@ var firstPositional = (words, from) => {
|
|
|
14596
14740
|
return index;
|
|
14597
14741
|
};
|
|
14598
14742
|
function fileTarget(word, cwd) {
|
|
14599
|
-
if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(
|
|
14743
|
+
if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(path21.sep))
|
|
14600
14744
|
return false;
|
|
14601
|
-
if (!/\.[A-Za-z0-9]+$/u.test(
|
|
14745
|
+
if (!/\.[A-Za-z0-9]+$/u.test(path21.basename(word)))
|
|
14602
14746
|
return false;
|
|
14603
14747
|
if (!cwd)
|
|
14604
14748
|
return true;
|
|
14605
14749
|
try {
|
|
14606
|
-
return !fs17.statSync(
|
|
14750
|
+
return !fs17.statSync(path21.resolve(cwd, word)).isDirectory();
|
|
14607
14751
|
} catch {
|
|
14608
14752
|
return true;
|
|
14609
14753
|
}
|
|
@@ -14671,13 +14815,13 @@ function lightCommand(argv, cwd) {
|
|
|
14671
14815
|
|
|
14672
14816
|
// packages/workit-core/src/core/policy/derive.ts
|
|
14673
14817
|
import { existsSync as existsSync9 } from "node:fs";
|
|
14674
|
-
import
|
|
14818
|
+
import path24 from "node:path";
|
|
14675
14819
|
|
|
14676
14820
|
// packages/workit-core/src/ledger.ts
|
|
14677
14821
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
14678
|
-
import { createHash as
|
|
14822
|
+
import { createHash as createHash14, randomBytes as randomBytes3 } from "node:crypto";
|
|
14679
14823
|
import fs18 from "node:fs";
|
|
14680
|
-
import
|
|
14824
|
+
import path23 from "node:path";
|
|
14681
14825
|
|
|
14682
14826
|
// packages/workit-core/src/core/policy/bookkeeping.ts
|
|
14683
14827
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
@@ -14757,8 +14901,8 @@ function bookkeepingPaths(cwd, input) {
|
|
|
14757
14901
|
}
|
|
14758
14902
|
|
|
14759
14903
|
// packages/workit-core/src/core/policy/lane.ts
|
|
14760
|
-
import { existsSync as existsSync8, readFileSync as
|
|
14761
|
-
import
|
|
14904
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
|
|
14905
|
+
import path22 from "node:path";
|
|
14762
14906
|
|
|
14763
14907
|
// packages/workit-core/src/git/default-base.ts
|
|
14764
14908
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
@@ -16149,7 +16293,7 @@ function computeLane(input) {
|
|
|
16149
16293
|
}
|
|
16150
16294
|
function untrackedStat(cwd, file) {
|
|
16151
16295
|
try {
|
|
16152
|
-
const bytes =
|
|
16296
|
+
const bytes = readFileSync8(path22.join(cwd, file));
|
|
16153
16297
|
if (bytes.includes(0))
|
|
16154
16298
|
return { path: file, added: 0, deleted: 0, binary: true };
|
|
16155
16299
|
const text = bytes.toString("utf8");
|
|
@@ -16181,7 +16325,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
16181
16325
|
let after = blobs.get(entry.newBlob);
|
|
16182
16326
|
if (!after && head === null && ABSENT.test(entry.newBlob))
|
|
16183
16327
|
try {
|
|
16184
|
-
after =
|
|
16328
|
+
after = readFileSync8(path22.join(cwd, entry.path));
|
|
16185
16329
|
} catch {
|
|
16186
16330
|
after = undefined;
|
|
16187
16331
|
}
|
|
@@ -16412,7 +16556,7 @@ var binaryRangeDiff = (cwd, base, head) => {
|
|
|
16412
16556
|
return diff.ok && diff.stdout ? diff.stdout : null;
|
|
16413
16557
|
};
|
|
16414
16558
|
var hashOfDiff = (diff) => {
|
|
16415
|
-
const hash =
|
|
16559
|
+
const hash = createHash14("sha256");
|
|
16416
16560
|
for (const line of diff.split(`
|
|
16417
16561
|
`)) {
|
|
16418
16562
|
if (line.startsWith("index "))
|
|
@@ -16445,14 +16589,14 @@ function cleanRebase(cwd, range) {
|
|
|
16445
16589
|
return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
|
|
16446
16590
|
}
|
|
16447
16591
|
function storeRoot(cwd) {
|
|
16448
|
-
const location = resolveStore(
|
|
16592
|
+
const location = resolveStore(path23.resolve(cwd));
|
|
16449
16593
|
if (location instanceof Error)
|
|
16450
16594
|
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");
|
|
16451
16595
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
16452
16596
|
}
|
|
16453
16597
|
function ledgerPath(cwd) {
|
|
16454
16598
|
const root = storeRoot(cwd);
|
|
16455
|
-
return root.ok ? { ok: true, value:
|
|
16599
|
+
return root.ok ? { ok: true, value: path23.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
16456
16600
|
}
|
|
16457
16601
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
|
|
16458
16602
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -16482,13 +16626,13 @@ var LOCK_STALE_MS2 = 30000;
|
|
|
16482
16626
|
var LOCK_OWNER = "owner";
|
|
16483
16627
|
var lockToken = (lock) => {
|
|
16484
16628
|
try {
|
|
16485
|
-
return fs18.readFileSync(
|
|
16629
|
+
return fs18.readFileSync(path23.join(lock, LOCK_OWNER), "utf8");
|
|
16486
16630
|
} catch {
|
|
16487
16631
|
return null;
|
|
16488
16632
|
}
|
|
16489
16633
|
};
|
|
16490
16634
|
var lockAgeMs = (lock) => {
|
|
16491
|
-
for (const target of [
|
|
16635
|
+
for (const target of [path23.join(lock, LOCK_OWNER), lock]) {
|
|
16492
16636
|
try {
|
|
16493
16637
|
return Date.now() - fs18.statSync(target).mtimeMs;
|
|
16494
16638
|
} catch {}
|
|
@@ -16505,7 +16649,7 @@ var ledgerLock = {
|
|
|
16505
16649
|
throw error;
|
|
16506
16650
|
}
|
|
16507
16651
|
const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
|
|
16508
|
-
fs18.writeFileSync(
|
|
16652
|
+
fs18.writeFileSync(path23.join(lock, LOCK_OWNER), token);
|
|
16509
16653
|
return token;
|
|
16510
16654
|
},
|
|
16511
16655
|
release(lock, token) {
|
|
@@ -16568,7 +16712,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2))
|
|
|
16568
16712
|
ledgerLock.release(lock, token);
|
|
16569
16713
|
}
|
|
16570
16714
|
}
|
|
16571
|
-
var sha2562 = (text) =>
|
|
16715
|
+
var sha2562 = (text) => createHash14("sha256").update(text).digest("hex");
|
|
16572
16716
|
var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
|
|
16573
16717
|
${body}`);
|
|
16574
16718
|
var TAIL_BYTES = 64 * 1024;
|
|
@@ -16630,8 +16774,8 @@ ${line.value}`);
|
|
|
16630
16774
|
}
|
|
16631
16775
|
};
|
|
16632
16776
|
try {
|
|
16633
|
-
fs18.mkdirSync(
|
|
16634
|
-
if (options.heldLock || !options.forceLock && !onNetworkFs(
|
|
16777
|
+
fs18.mkdirSync(path23.dirname(file), { recursive: true });
|
|
16778
|
+
if (options.heldLock || !options.forceLock && !onNetworkFs(path23.dirname(file)))
|
|
16635
16779
|
return write();
|
|
16636
16780
|
const locked = withLedgerLock(file, write);
|
|
16637
16781
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -16648,7 +16792,7 @@ var sealed = (row, id, at, previous) => {
|
|
|
16648
16792
|
` };
|
|
16649
16793
|
};
|
|
16650
16794
|
function appendRaw(cwd, row, options) {
|
|
16651
|
-
const file = options.store ? { ok: true, value:
|
|
16795
|
+
const file = options.store ? { ok: true, value: path23.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
|
|
16652
16796
|
if (!file.ok)
|
|
16653
16797
|
return file;
|
|
16654
16798
|
const id = newId2();
|
|
@@ -17311,7 +17455,7 @@ function remoteIdentity(cwd, hop = 0) {
|
|
|
17311
17455
|
return null;
|
|
17312
17456
|
if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
|
|
17313
17457
|
const local = raw.replace(/^file:\/\//u, "");
|
|
17314
|
-
const resolved =
|
|
17458
|
+
const resolved = path23.isAbsolute(local) ? local : path23.resolve(cwd, local);
|
|
17315
17459
|
if (fs18.existsSync(resolved))
|
|
17316
17460
|
return remoteIdentity(resolved, 1);
|
|
17317
17461
|
}
|
|
@@ -17332,8 +17476,8 @@ function verdictMirrorPath(cwd) {
|
|
|
17332
17476
|
}
|
|
17333
17477
|
if (!identity)
|
|
17334
17478
|
return null;
|
|
17335
|
-
const key =
|
|
17336
|
-
return
|
|
17479
|
+
const key = createHash14("sha256").update(identity).digest("hex").slice(0, 32);
|
|
17480
|
+
return path23.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
|
|
17337
17481
|
}
|
|
17338
17482
|
var importedStamp = new Map;
|
|
17339
17483
|
function importMirroredVerdicts(cwd, branch) {
|
|
@@ -17356,7 +17500,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
17356
17500
|
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
17357
17501
|
const added = new Set;
|
|
17358
17502
|
try {
|
|
17359
|
-
fs18.mkdirSync(
|
|
17503
|
+
fs18.mkdirSync(path23.dirname(local.value), { recursive: true });
|
|
17360
17504
|
} catch {
|
|
17361
17505
|
return [];
|
|
17362
17506
|
}
|
|
@@ -17582,7 +17726,7 @@ var productDecision = (task, ledger) => {
|
|
|
17582
17726
|
};
|
|
17583
17727
|
};
|
|
17584
17728
|
var planRecorded = (task, root) => {
|
|
17585
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(
|
|
17729
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path24.resolve(root, ref.path)));
|
|
17586
17730
|
if (cited)
|
|
17587
17731
|
return {
|
|
17588
17732
|
met: true,
|
|
@@ -17659,15 +17803,15 @@ function writeBlockers(task, root) {
|
|
|
17659
17803
|
}
|
|
17660
17804
|
|
|
17661
17805
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
17662
|
-
var digestBytes = (value) =>
|
|
17663
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
17664
|
-
var relative = (root, candidate) =>
|
|
17806
|
+
var digestBytes = (value) => createHash15("sha256").update(value).digest("hex");
|
|
17807
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path25.sep}`);
|
|
17808
|
+
var relative = (root, candidate) => path25.relative(root, candidate).split(path25.sep).join("/") || ".";
|
|
17665
17809
|
var canonicalPath = (value) => {
|
|
17666
17810
|
if (typeof value !== "string" || !value)
|
|
17667
17811
|
return null;
|
|
17668
17812
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
17669
17813
|
return null;
|
|
17670
|
-
const normalized =
|
|
17814
|
+
const normalized = path25.posix.normalize(value);
|
|
17671
17815
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
17672
17816
|
return null;
|
|
17673
17817
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -17715,14 +17859,14 @@ var gitPaths = (root) => {
|
|
|
17715
17859
|
git: !/not a git repository/i.test(stderr)
|
|
17716
17860
|
};
|
|
17717
17861
|
}
|
|
17718
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
17862
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")) : [];
|
|
17719
17863
|
const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
17720
17864
|
if (stagedDeleted.status !== 0) {
|
|
17721
17865
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
17722
17866
|
if (!/not a git repository/i.test(stderr))
|
|
17723
17867
|
return { paths, uncertain: true, git: true };
|
|
17724
17868
|
} else if (stagedDeleted.stdout) {
|
|
17725
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
17869
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")));
|
|
17726
17870
|
}
|
|
17727
17871
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
17728
17872
|
};
|
|
@@ -17737,7 +17881,7 @@ var walk = (root, directory, output) => {
|
|
|
17737
17881
|
for (const name of names) {
|
|
17738
17882
|
if (name === ".git" || name === ".workit")
|
|
17739
17883
|
continue;
|
|
17740
|
-
const target =
|
|
17884
|
+
const target = path25.join(directory, name);
|
|
17741
17885
|
let stat;
|
|
17742
17886
|
try {
|
|
17743
17887
|
stat = fs19.lstatSync(target);
|
|
@@ -17755,12 +17899,12 @@ var walk = (root, directory, output) => {
|
|
|
17755
17899
|
var scopeRoots = (root, scope) => {
|
|
17756
17900
|
const roots = [];
|
|
17757
17901
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
17758
|
-
const target =
|
|
17902
|
+
const target = path25.resolve(root, item);
|
|
17759
17903
|
if (!inside(root, target))
|
|
17760
17904
|
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` }] });
|
|
17761
17905
|
let ancestor = target;
|
|
17762
17906
|
while (!fs19.existsSync(ancestor) && ancestor !== root)
|
|
17763
|
-
ancestor =
|
|
17907
|
+
ancestor = path25.dirname(ancestor);
|
|
17764
17908
|
try {
|
|
17765
17909
|
if (!inside(root, fs19.realpathSync(ancestor)))
|
|
17766
17910
|
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` }] });
|
|
@@ -17812,7 +17956,7 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
17812
17956
|
for (const item of [...names].toSorted()) {
|
|
17813
17957
|
if (!scopeMatches(item, normalizedScope))
|
|
17814
17958
|
continue;
|
|
17815
|
-
const target =
|
|
17959
|
+
const target = path25.join(checkout, item);
|
|
17816
17960
|
try {
|
|
17817
17961
|
const stat = fs19.lstatSync(target);
|
|
17818
17962
|
if (stat.isSymbolicLink()) {
|
|
@@ -17996,23 +18140,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
17996
18140
|
continue;
|
|
17997
18141
|
if (!reference.digest)
|
|
17998
18142
|
return failure2("invalid_input", "document references require a byte digest");
|
|
17999
|
-
const target =
|
|
18000
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
18143
|
+
const target = path25.resolve(root, reference.path);
|
|
18144
|
+
if (target !== root && !target.startsWith(`${root}${path25.sep}`))
|
|
18001
18145
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
18002
18146
|
fields: [
|
|
18003
18147
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
18004
18148
|
]
|
|
18005
18149
|
});
|
|
18006
18150
|
try {
|
|
18007
|
-
const below =
|
|
18151
|
+
const below = path25.relative(root, target);
|
|
18008
18152
|
let current = root;
|
|
18009
|
-
for (const segment of below.split(
|
|
18153
|
+
for (const segment of below.split(path25.sep)) {
|
|
18010
18154
|
if (!segment)
|
|
18011
18155
|
continue;
|
|
18012
|
-
current =
|
|
18156
|
+
current = path25.join(current, segment);
|
|
18013
18157
|
const stat = fs19.lstatSync(current);
|
|
18014
18158
|
const real = fs19.realpathSync(current);
|
|
18015
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
18159
|
+
if (real !== root && !real.startsWith(`${root}${path25.sep}`))
|
|
18016
18160
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
18017
18161
|
fields: [
|
|
18018
18162
|
{
|
|
@@ -18373,9 +18517,9 @@ function boundTaskSummary(summary) {
|
|
|
18373
18517
|
}
|
|
18374
18518
|
|
|
18375
18519
|
// packages/workit-core/src/core/model-fallback.ts
|
|
18376
|
-
import { createHash as
|
|
18377
|
-
import { mkdirSync as mkdirSync5, readFileSync as
|
|
18378
|
-
import
|
|
18520
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
18521
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
18522
|
+
import path26 from "node:path";
|
|
18379
18523
|
var LIMITS_FILE = "model-limits.json";
|
|
18380
18524
|
var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
|
|
18381
18525
|
var KEEP_MS = 9 * 86400000;
|
|
@@ -18398,10 +18542,10 @@ var providerOf = (model, host) => {
|
|
|
18398
18542
|
return null;
|
|
18399
18543
|
};
|
|
18400
18544
|
var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
|
|
18401
|
-
var storePath = (stateDir) =>
|
|
18545
|
+
var storePath = (stateDir) => path26.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
|
|
18402
18546
|
var readStore = (stateDir) => {
|
|
18403
18547
|
try {
|
|
18404
|
-
const parsed = JSON.parse(
|
|
18548
|
+
const parsed = JSON.parse(readFileSync10(storePath(stateDir), "utf8"));
|
|
18405
18549
|
const store = empty();
|
|
18406
18550
|
for (const key of ["exhausted", "seen", "redispatched"])
|
|
18407
18551
|
if (parsed[key] && typeof parsed[key] === "object")
|
|
@@ -18422,7 +18566,7 @@ var writeStore = (store, now, stateDir) => {
|
|
|
18422
18566
|
delete store.exhausted[id];
|
|
18423
18567
|
try {
|
|
18424
18568
|
const file = storePath(stateDir);
|
|
18425
|
-
mkdirSync5(
|
|
18569
|
+
mkdirSync5(path26.dirname(file), { recursive: true });
|
|
18426
18570
|
const temp = `${file}.${process.pid}.tmp`;
|
|
18427
18571
|
writeFileSync5(temp, `${JSON.stringify(store, null, 2)}
|
|
18428
18572
|
`);
|
|
@@ -18450,7 +18594,7 @@ var exhaustionFor = (model, host, now = new Date, stateDir) => {
|
|
|
18450
18594
|
const keys = new Set([provider, ...family ? [`${provider}/${family}`] : []]);
|
|
18451
18595
|
return exhaustedProviders(now, stateDir).find((entry) => keys.has(entry.provider)) ?? null;
|
|
18452
18596
|
};
|
|
18453
|
-
var promptKey = (prompt) =>
|
|
18597
|
+
var promptKey = (prompt) => createHash16("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
|
|
18454
18598
|
var claimRedispatch = (key, now = new Date, stateDir) => {
|
|
18455
18599
|
const store = readStore(stateDir);
|
|
18456
18600
|
if (store.redispatched[key])
|
|
@@ -19044,20 +19188,20 @@ import path29 from "node:path";
|
|
|
19044
19188
|
// packages/workit-core/src/core/eval-world.ts
|
|
19045
19189
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
19046
19190
|
import os6 from "node:os";
|
|
19047
|
-
import
|
|
19191
|
+
import path27 from "node:path";
|
|
19048
19192
|
var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
|
|
19049
19193
|
var EVAL_WORLD_MARKER = ".workit-eval-world";
|
|
19050
19194
|
var inside2 = (dir, file) => {
|
|
19051
|
-
const rel =
|
|
19052
|
-
return !rel.startsWith("..") && !
|
|
19195
|
+
const rel = path27.relative(dir, file);
|
|
19196
|
+
return !rel.startsWith("..") && !path27.isAbsolute(rel);
|
|
19053
19197
|
};
|
|
19054
19198
|
var evalWorld = (cwd) => {
|
|
19055
19199
|
const raw = process.env[EVAL_WORLD_ENV];
|
|
19056
|
-
if (!raw || !
|
|
19200
|
+
if (!raw || !path27.isAbsolute(raw))
|
|
19057
19201
|
return null;
|
|
19058
19202
|
try {
|
|
19059
19203
|
const world = realpathSync7(raw);
|
|
19060
|
-
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(
|
|
19204
|
+
return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path27.join(world, EVAL_WORLD_MARKER)) ? world : null;
|
|
19061
19205
|
} catch {
|
|
19062
19206
|
return null;
|
|
19063
19207
|
}
|
|
@@ -19065,77 +19209,12 @@ var evalWorld = (cwd) => {
|
|
|
19065
19209
|
var evalWorldEntry = (cwd) => {
|
|
19066
19210
|
const world = evalWorld(cwd);
|
|
19067
19211
|
try {
|
|
19068
|
-
return world ? loadWorkspacesFrom(
|
|
19212
|
+
return world ? loadWorkspacesFrom(path27.join(world, "config"))[0] ?? null : null;
|
|
19069
19213
|
} catch {
|
|
19070
19214
|
return null;
|
|
19071
19215
|
}
|
|
19072
19216
|
};
|
|
19073
19217
|
|
|
19074
|
-
// packages/workit-core/src/core/grant-seal.ts
|
|
19075
|
-
import { createHash as createHash16 } from "node:crypto";
|
|
19076
|
-
import { readFileSync as readFileSync10 } from "node:fs";
|
|
19077
|
-
import path27 from "node:path";
|
|
19078
|
-
var SEAL_FILE = "workspaces.json.seal";
|
|
19079
|
-
var SEAL_VERSION = 1;
|
|
19080
|
-
var SEAL_COMMAND = "workit workspace seal";
|
|
19081
|
-
var pick3 = (value, keys) => {
|
|
19082
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
19083
|
-
return;
|
|
19084
|
-
const out = Object.fromEntries(keys.flatMap((key) => {
|
|
19085
|
-
const item = value[key];
|
|
19086
|
-
return item === undefined ? [] : [[key, item]];
|
|
19087
|
-
}));
|
|
19088
|
-
return Object.keys(out).length > 0 ? out : undefined;
|
|
19089
|
-
};
|
|
19090
|
-
var ENTRY_KEYS = [
|
|
19091
|
-
"name",
|
|
19092
|
-
"glob",
|
|
19093
|
-
"remotes",
|
|
19094
|
-
"externalRepos",
|
|
19095
|
-
"additiveRiskPaths",
|
|
19096
|
-
"vcs",
|
|
19097
|
-
"autonomy",
|
|
19098
|
-
"autoApprove",
|
|
19099
|
-
"defaultEndpoint",
|
|
19100
|
-
"verification",
|
|
19101
|
-
"youtrack"
|
|
19102
|
-
];
|
|
19103
|
-
var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
|
|
19104
|
-
var sealProjection = (entries) => entries.map((entry) => {
|
|
19105
|
-
const all = pick3(entry, ENTRY_KEYS) ?? {};
|
|
19106
|
-
return pick3({
|
|
19107
|
-
...all,
|
|
19108
|
-
vcs: pick3(all.vcs, IDENTITY_KEYS),
|
|
19109
|
-
youtrack: pick3(all.youtrack, ["writes", "autoHosts"])
|
|
19110
|
-
}, ENTRY_KEYS);
|
|
19111
|
-
});
|
|
19112
|
-
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);
|
|
19113
|
-
var sealDigest = (projection) => createHash16("sha256").update(canonical4(projection)).digest("hex");
|
|
19114
|
-
var broken = (reason, sealed = null) => ({
|
|
19115
|
-
state: "broken",
|
|
19116
|
-
reason,
|
|
19117
|
-
sealed
|
|
19118
|
-
});
|
|
19119
|
-
function checkSeal(dir) {
|
|
19120
|
-
const file = path27.join(dir, SEAL_FILE);
|
|
19121
|
-
let seal;
|
|
19122
|
-
try {
|
|
19123
|
-
seal = JSON.parse(readFileSync10(file, "utf8"));
|
|
19124
|
-
} catch (error) {
|
|
19125
|
-
if (error.code === "ENOENT")
|
|
19126
|
-
return { state: "none" };
|
|
19127
|
-
return broken(`${SEAL_FILE} cannot be read`);
|
|
19128
|
-
}
|
|
19129
|
-
if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
|
|
19130
|
-
return broken(`${SEAL_FILE} is malformed`);
|
|
19131
|
-
const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
|
|
19132
|
-
if (sealed.status !== "valid")
|
|
19133
|
-
return broken(`${SEAL_FILE} is malformed`);
|
|
19134
|
-
const current = readWorkspacesResult(dir);
|
|
19135
|
-
const ok = current.status === "valid" || current.status === "missing";
|
|
19136
|
-
return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
|
|
19137
|
-
}
|
|
19138
|
-
|
|
19139
19218
|
// packages/workit-core/src/core/youtrack-ytrack.ts
|
|
19140
19219
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
19141
19220
|
|
|
@@ -19348,7 +19427,7 @@ var sealOf = () => {
|
|
|
19348
19427
|
var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
|
|
19349
19428
|
var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
|
|
19350
19429
|
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}`;
|
|
19351
|
-
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;
|
|
19430
|
+
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;
|
|
19352
19431
|
var ASK = { mode: "ask" };
|
|
19353
19432
|
var youtrackOf = (entry) => entry?.youtrack;
|
|
19354
19433
|
var autoHostsOf = (entry) => {
|
|
@@ -19764,7 +19843,14 @@ var SCOPE_FIELDS = new Set([
|
|
|
19764
19843
|
"autoApprove",
|
|
19765
19844
|
"defaultEndpoint",
|
|
19766
19845
|
"verification",
|
|
19767
|
-
"youtrack"
|
|
19846
|
+
"youtrack",
|
|
19847
|
+
"releaseNotes",
|
|
19848
|
+
"releaseTagPrefix",
|
|
19849
|
+
"branchPolicy",
|
|
19850
|
+
"profiles",
|
|
19851
|
+
"defaultProfile",
|
|
19852
|
+
"releaseTracks",
|
|
19853
|
+
"releasePackages"
|
|
19768
19854
|
]);
|
|
19769
19855
|
|
|
19770
19856
|
// packages/workit-core/src/core/release-packages.ts
|
|
@@ -20171,9 +20257,9 @@ var arithmeticEnd = (command, start) => {
|
|
|
20171
20257
|
const end = substitutionEnd(command, start);
|
|
20172
20258
|
return command[end - 1] === ")" && end > start + 2 ? end : 0;
|
|
20173
20259
|
};
|
|
20174
|
-
var segmentsOf = (command, dialect = "posix") => {
|
|
20260
|
+
var segmentsOf = (command, dialect = "posix", options = {}) => {
|
|
20175
20261
|
try {
|
|
20176
|
-
return tokenize(command, dialect);
|
|
20262
|
+
return tokenize(command, dialect, options.spans === true);
|
|
20177
20263
|
} catch (error) {
|
|
20178
20264
|
const why = error instanceof ShellAnalysisError ? error.message : String(error);
|
|
20179
20265
|
return [{ words: [], redirects: [], unanalyzable: why }];
|
|
@@ -20183,12 +20269,14 @@ var afterEnv = (words) => {
|
|
|
20183
20269
|
const at = words.map((word) => word.split(/[\\/]/).at(-1)).lastIndexOf("env");
|
|
20184
20270
|
return at >= 0 && words.slice(at + 1).every((word, index, rest) => /^-|=/.test(word) || /^-[^-]*[uCS]$|^--(?:unset|chdir|split-string)$/.test(rest[index - 1] ?? ""));
|
|
20185
20271
|
};
|
|
20186
|
-
var tokenize = (command, dialect) => {
|
|
20272
|
+
var tokenize = (command, dialect, spans) => {
|
|
20187
20273
|
const posix = dialect === "posix";
|
|
20188
20274
|
const segments = [];
|
|
20189
20275
|
let current = { words: [], redirects: [] };
|
|
20190
20276
|
let word = "";
|
|
20191
20277
|
let inWord = false;
|
|
20278
|
+
let wordStart = -1;
|
|
20279
|
+
let cursor = 0;
|
|
20192
20280
|
let expanding = false;
|
|
20193
20281
|
let afterOperator = false;
|
|
20194
20282
|
let pending = null;
|
|
@@ -20199,9 +20287,13 @@ var tokenize = (command, dialect) => {
|
|
|
20199
20287
|
if (!inWord)
|
|
20200
20288
|
return;
|
|
20201
20289
|
const text = MARKERS.test(word) ? literal2(word) : word;
|
|
20290
|
+
const span = [wordStart, cursor];
|
|
20202
20291
|
if (pending === "redirect") {
|
|
20203
|
-
if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
|
|
20292
|
+
if (!duplicate || !/^(?:\d+-?|-)$/.test(text)) {
|
|
20204
20293
|
current.redirects.push(text);
|
|
20294
|
+
if (spans)
|
|
20295
|
+
(current.redirectSpans ??= []).push(span);
|
|
20296
|
+
}
|
|
20205
20297
|
} else if (pending === "heredoc")
|
|
20206
20298
|
heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
|
|
20207
20299
|
else if (pending === "herestring")
|
|
@@ -20209,17 +20301,20 @@ var tokenize = (command, dialect) => {
|
|
|
20209
20301
|
else if (pending === "input")
|
|
20210
20302
|
(current.inputs ??= []).push(text);
|
|
20211
20303
|
else {
|
|
20212
|
-
const
|
|
20304
|
+
const at0 = current.words.length;
|
|
20213
20305
|
if (/^[^=-][^=]*=/.test(word) && afterEnv(current.words))
|
|
20214
20306
|
word = word.replace(/^[^=]*/, (name) => name.replace(/\W/g, "_"));
|
|
20215
20307
|
current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
|
|
20308
|
+
if (spans)
|
|
20309
|
+
(current.spans ??= []).push(...current.words.slice(at0).map(() => span));
|
|
20216
20310
|
if (expanding || !posix && word.startsWith("@"))
|
|
20217
|
-
(current.expands ??= []).push(...current.words.slice(
|
|
20311
|
+
(current.expands ??= []).push(...current.words.slice(at0).map((_, i) => at0 + i));
|
|
20218
20312
|
}
|
|
20219
20313
|
pending = null;
|
|
20220
20314
|
duplicate = false;
|
|
20221
20315
|
word = "";
|
|
20222
20316
|
inWord = false;
|
|
20317
|
+
wordStart = -1;
|
|
20223
20318
|
expanding = false;
|
|
20224
20319
|
};
|
|
20225
20320
|
const flushSegment = () => {
|
|
@@ -20244,9 +20339,12 @@ var tokenize = (command, dialect) => {
|
|
|
20244
20339
|
};
|
|
20245
20340
|
const plain = posix ? PLAIN_POSIX : PLAIN_POWERSHELL;
|
|
20246
20341
|
for (let index = 0;index < command.length; index++) {
|
|
20342
|
+
cursor = index;
|
|
20247
20343
|
plain.lastIndex = index;
|
|
20248
20344
|
const run = plain.exec(command);
|
|
20249
20345
|
if (run) {
|
|
20346
|
+
if (wordStart < 0)
|
|
20347
|
+
wordStart = index;
|
|
20250
20348
|
word += run[0];
|
|
20251
20349
|
inWord = true;
|
|
20252
20350
|
if (EXPANDING_RUN.test(run[0]))
|
|
@@ -20272,9 +20370,11 @@ var tokenize = (command, dialect) => {
|
|
|
20272
20370
|
word += text;
|
|
20273
20371
|
inWord = true;
|
|
20274
20372
|
index = end;
|
|
20275
|
-
} else if (posix && char === "$" && next === '"')
|
|
20373
|
+
} else if (posix && char === "$" && next === '"') {
|
|
20374
|
+
if (wordStart < 0)
|
|
20375
|
+
wordStart = index;
|
|
20276
20376
|
continue;
|
|
20277
|
-
else if (char === "'" || char === '"') {
|
|
20377
|
+
} else if (char === "'" || char === '"') {
|
|
20278
20378
|
const end = closingQuote(command, index, dialect);
|
|
20279
20379
|
const body = command.slice(index + 1, end < 0 ? undefined : end);
|
|
20280
20380
|
if (posix && char === '"' && /\$\(|`/.test(body))
|
|
@@ -20315,6 +20415,7 @@ var tokenize = (command, dialect) => {
|
|
|
20315
20415
|
index = end;
|
|
20316
20416
|
} else if (posix && char === "(" && (pending === "input" || pending === "redirect")) {
|
|
20317
20417
|
const sign = pending === "input" ? "<" : ">";
|
|
20418
|
+
wordStart = index - 1;
|
|
20318
20419
|
pending = null;
|
|
20319
20420
|
const end = substitutionEnd(command, index);
|
|
20320
20421
|
const inner = command.slice(index + 1, end);
|
|
@@ -20327,8 +20428,10 @@ var tokenize = (command, dialect) => {
|
|
|
20327
20428
|
if (char === "(" && inWord && word.endsWith("$")) {
|
|
20328
20429
|
word = word.slice(0, -1);
|
|
20329
20430
|
inWord = word !== "";
|
|
20330
|
-
if (!inWord)
|
|
20431
|
+
if (!inWord) {
|
|
20331
20432
|
expanding = false;
|
|
20433
|
+
wordStart = -1;
|
|
20434
|
+
}
|
|
20332
20435
|
}
|
|
20333
20436
|
group(char === "(" ? "open" : "close");
|
|
20334
20437
|
} else if (!posix && (char === "{" || char === "}")) {
|
|
@@ -20363,6 +20466,7 @@ var tokenize = (command, dialect) => {
|
|
|
20363
20466
|
if (inWord && /^\d$/.test(word)) {
|
|
20364
20467
|
word = "";
|
|
20365
20468
|
inWord = false;
|
|
20469
|
+
wordStart = -1;
|
|
20366
20470
|
} else
|
|
20367
20471
|
flushWord();
|
|
20368
20472
|
if (command[index + 1] === ">")
|
|
@@ -20394,7 +20498,10 @@ var tokenize = (command, dialect) => {
|
|
|
20394
20498
|
word += char;
|
|
20395
20499
|
inWord = true;
|
|
20396
20500
|
}
|
|
20501
|
+
if (inWord && wordStart < 0)
|
|
20502
|
+
wordStart = cursor;
|
|
20397
20503
|
}
|
|
20504
|
+
cursor = command.length;
|
|
20398
20505
|
flushSegment();
|
|
20399
20506
|
return segments;
|
|
20400
20507
|
};
|
|
@@ -26516,6 +26623,36 @@ var verbAt = (words) => {
|
|
|
26516
26623
|
}
|
|
26517
26624
|
};
|
|
26518
26625
|
var WRAPPERS2 = new Set(["env", "sudo", "nohup", "command", "timeout", "nice", "exec"]);
|
|
26626
|
+
var VALUED = /^-(?:[ugnskCpD]|-user|-group|-signal|-kill-after|-unset|-chdir)$/u;
|
|
26627
|
+
var unwrapped = (words) => {
|
|
26628
|
+
let at = 0;
|
|
26629
|
+
for (;; ) {
|
|
26630
|
+
const word = words[at] ?? "";
|
|
26631
|
+
const name = word.split("/").at(-1) ?? "";
|
|
26632
|
+
if (/^[A-Za-z_]\w*=/u.test(word))
|
|
26633
|
+
at += 1;
|
|
26634
|
+
else if (WRAPPERS2.has(name)) {
|
|
26635
|
+
at += 1;
|
|
26636
|
+
while (words[at]?.startsWith("-"))
|
|
26637
|
+
at += VALUED.test(words[at] ?? "") ? 2 : 1;
|
|
26638
|
+
if (name === "timeout" && words[at] !== undefined)
|
|
26639
|
+
at += 1;
|
|
26640
|
+
} else
|
|
26641
|
+
return words.slice(at);
|
|
26642
|
+
}
|
|
26643
|
+
};
|
|
26644
|
+
var shellScript2 = (all) => {
|
|
26645
|
+
const words = unwrapped(all);
|
|
26646
|
+
const name = words[0]?.split("/").at(-1) ?? "";
|
|
26647
|
+
if (name === "eval")
|
|
26648
|
+
return words.slice(1).join(" ") || null;
|
|
26649
|
+
if (!/^(?:ba|z|da|k)?sh$/u.test(name))
|
|
26650
|
+
return null;
|
|
26651
|
+
const flag = words.findIndex((word, at) => at > 0 && /^-[a-z]*c[a-z]*$/u.test(word));
|
|
26652
|
+
if (flag < 0)
|
|
26653
|
+
return null;
|
|
26654
|
+
return words[words[flag + 1] === "--" ? flag + 2 : flag + 1] ?? null;
|
|
26655
|
+
};
|
|
26519
26656
|
var isAllowedWorkitCall = (words, expands = []) => {
|
|
26520
26657
|
if (words[0] !== "workit")
|
|
26521
26658
|
return false;
|
|
@@ -28139,7 +28276,7 @@ var wrappedScript = (input) => {
|
|
|
28139
28276
|
return null;
|
|
28140
28277
|
if ("script" in tail)
|
|
28141
28278
|
return tail.script;
|
|
28142
|
-
const script =
|
|
28279
|
+
const script = shellScript3(tail.argv);
|
|
28143
28280
|
if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
|
|
28144
28281
|
return script;
|
|
28145
28282
|
return tail.argv.map(quoteWord2).join(" ");
|
|
@@ -28477,13 +28614,13 @@ var scriptArgs = (verb, args) => {
|
|
|
28477
28614
|
}
|
|
28478
28615
|
return { preloads };
|
|
28479
28616
|
};
|
|
28480
|
-
var
|
|
28617
|
+
var unwrapped2 = (words) => {
|
|
28481
28618
|
let at = 0;
|
|
28482
28619
|
for (let takes;(takes = WRAPPERS3[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; )
|
|
28483
28620
|
at = pastOptions(words, at + 1, takes, true);
|
|
28484
28621
|
return at ? words.slice(at) : null;
|
|
28485
28622
|
};
|
|
28486
|
-
var
|
|
28623
|
+
var shellScript3 = (words) => {
|
|
28487
28624
|
if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
|
|
28488
28625
|
return null;
|
|
28489
28626
|
for (let index = 1;index < words.length; index++) {
|
|
@@ -28635,7 +28772,7 @@ var opaqueWrites = (input, scriptOf = (index) => input[index], fed, loads = fals
|
|
|
28635
28772
|
return ["."];
|
|
28636
28773
|
if (/^(?:python[\d.]*|node|bun|deno|ruby|php|tsx|ts-node)$/.test(name))
|
|
28637
28774
|
return inline(INLINE_CODE);
|
|
28638
|
-
return
|
|
28775
|
+
return shellScript3(words) === null ? null : ["."];
|
|
28639
28776
|
};
|
|
28640
28777
|
var CURL_LONG = [
|
|
28641
28778
|
"output",
|
|
@@ -29399,7 +29536,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29399
29536
|
moved(plain);
|
|
29400
29537
|
continue;
|
|
29401
29538
|
}
|
|
29402
|
-
const literal = depth < 4 ? wrappedScript(words) ?? (strict ?
|
|
29539
|
+
const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript3(pastLead(words)) : null) : null;
|
|
29403
29540
|
const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
|
|
29404
29541
|
const inner = held.length === 1 ? held[0] : literal;
|
|
29405
29542
|
const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
|
|
@@ -29414,7 +29551,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29414
29551
|
if (windows !== null && dir !== undefined)
|
|
29415
29552
|
for (const file of segmentTargets(dir, windows, "powershell", depth + 1, strict, vars, cmd))
|
|
29416
29553
|
targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
|
|
29417
|
-
const bare = strict && depth < 4 ?
|
|
29554
|
+
const bare = strict && depth < 4 ? unwrapped2(words) : null;
|
|
29418
29555
|
if (bare?.length && dir !== undefined)
|
|
29419
29556
|
targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
|
|
29420
29557
|
if (strict === "registry" && dir !== undefined && depth < 4) {
|
|
@@ -29451,9 +29588,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29451
29588
|
const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
|
|
29452
29589
|
const others = [];
|
|
29453
29590
|
if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
|
|
29454
|
-
if (named === undefined &&
|
|
29591
|
+
if (named === undefined && shellScript3(run) === null)
|
|
29455
29592
|
shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
|
|
29456
|
-
else if (named !== undefined &&
|
|
29593
|
+
else if (named !== undefined && shellScript3(run) === null)
|
|
29457
29594
|
shells.push(...read(named));
|
|
29458
29595
|
shells.push(...preloads.flatMap(read));
|
|
29459
29596
|
} else if (INTERPRETERS.test(verb)) {
|
|
@@ -29523,7 +29660,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29523
29660
|
targets.push(file === "." ? placeholderIn(resolved, here) : path43.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path43.dirname(resolved), path43.basename(resolved)) : resolved);
|
|
29524
29661
|
const [shell = "", ...shellArgs] = pastLead(words);
|
|
29525
29662
|
const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
29526
|
-
const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") &&
|
|
29663
|
+
const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
|
|
29527
29664
|
if (depth < 4 && verb === "eval")
|
|
29528
29665
|
targets.push(...segmentTargets(runIn, shellArgs.join(" "), dialect, depth + 1, strict, vars));
|
|
29529
29666
|
else if (named !== null && /^<\(|^\/dev\/fd\/[1-9]/.test(named))
|
|
@@ -30559,8 +30696,8 @@ var WRITE_TOOLS = new Set([
|
|
|
30559
30696
|
"writefile"
|
|
30560
30697
|
]);
|
|
30561
30698
|
// packages/workit-core/src/hooks/standing.ts
|
|
30562
|
-
import
|
|
30563
|
-
import
|
|
30699
|
+
import fs31 from "node:fs";
|
|
30700
|
+
import path47 from "node:path";
|
|
30564
30701
|
|
|
30565
30702
|
// packages/workit-core/src/approvals/store.ts
|
|
30566
30703
|
var REQUEST_TTL_MS = 30 * 60000;
|
|
@@ -30570,72 +30707,232 @@ var INLINE_ASK_TTL_MS = 2 * 60000;
|
|
|
30570
30707
|
var namesTicket = (text) => /WORKIT_APPROVAL_(?:TICKET|UNASKED)/u.test(text.replace(/['"\\]/gu, ""));
|
|
30571
30708
|
var TICKET_DENY = "Only the host's prompt adds an approval ticket.";
|
|
30572
30709
|
|
|
30573
|
-
// packages/workit-core/src/
|
|
30574
|
-
var
|
|
30575
|
-
var
|
|
30576
|
-
|
|
30577
|
-
|
|
30578
|
-
|
|
30579
|
-
|
|
30580
|
-
|
|
30710
|
+
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
30711
|
+
var DIR = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
30712
|
+
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
30713
|
+
var UNSAFE = /[\p{Cf}\p{Zl}\p{Zp}]|[^\P{Cc}\n]/u;
|
|
30714
|
+
var newlines = (text) => text.split(`
|
|
30715
|
+
`).length - 1;
|
|
30716
|
+
var writtenWord = (command, segment, index) => {
|
|
30717
|
+
const span = segment.spans?.[index];
|
|
30718
|
+
if (!span)
|
|
30719
|
+
return null;
|
|
30720
|
+
const glued = (other) => other !== undefined && other !== span && (other[1] === span[0] || other[0] === span[1]);
|
|
30721
|
+
if (glued(segment.spans?.[index - 1]) || glued(segment.spans?.[index + 1]))
|
|
30722
|
+
return null;
|
|
30723
|
+
const text = command.slice(span[0], span[1]);
|
|
30724
|
+
const value = segment.words[index] ?? "";
|
|
30725
|
+
return UNSAFE.test(text) || newlines(text) !== newlines(value) ? null : text;
|
|
30726
|
+
};
|
|
30727
|
+
var writtenWords = (command, segment, indexes) => {
|
|
30728
|
+
const texts = [];
|
|
30729
|
+
let last;
|
|
30730
|
+
for (const index of indexes) {
|
|
30731
|
+
const span = segment.spans?.[index];
|
|
30732
|
+
if (span && span === last)
|
|
30733
|
+
continue;
|
|
30734
|
+
last = span;
|
|
30735
|
+
const text = writtenWord(command, segment, index);
|
|
30736
|
+
if (text === null)
|
|
30737
|
+
return null;
|
|
30738
|
+
texts.push(text);
|
|
30739
|
+
}
|
|
30740
|
+
return texts;
|
|
30581
30741
|
};
|
|
30582
|
-
|
|
30583
|
-
|
|
30584
|
-
|
|
30585
|
-
|
|
30586
|
-
|
|
30587
|
-
|
|
30588
|
-
|
|
30589
|
-
|
|
30590
|
-
|
|
30591
|
-
|
|
30592
|
-
|
|
30593
|
-
|
|
30594
|
-
|
|
30595
|
-
|
|
30596
|
-
|
|
30597
|
-
|
|
30598
|
-
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
|
|
30602
|
-
|
|
30603
|
-
|
|
30604
|
-
|
|
30605
|
-
|
|
30606
|
-
|
|
30607
|
-
|
|
30608
|
-
|
|
30609
|
-
|
|
30610
|
-
|
|
30611
|
-
|
|
30612
|
-
|
|
30613
|
-
|
|
30614
|
-
|
|
30615
|
-
|
|
30616
|
-
|
|
30617
|
-
|
|
30618
|
-
|
|
30619
|
-
|
|
30620
|
-
|
|
30621
|
-
|
|
30622
|
-
|
|
30623
|
-
|
|
30624
|
-
|
|
30625
|
-
|
|
30626
|
-
|
|
30627
|
-
|
|
30628
|
-
|
|
30629
|
-
|
|
30630
|
-
|
|
30631
|
-
|
|
30632
|
-
|
|
30633
|
-
|
|
30634
|
-
|
|
30635
|
-
|
|
30636
|
-
|
|
30637
|
-
|
|
30638
|
-
|
|
30742
|
+
var cwdIndependent = (text, colons = false) => {
|
|
30743
|
+
let quoted = false;
|
|
30744
|
+
for (let index = 0;index < text.length; index += 1) {
|
|
30745
|
+
const char = text[index] ?? "";
|
|
30746
|
+
if (char === "\\")
|
|
30747
|
+
index += 1;
|
|
30748
|
+
else if (char === "'" && !quoted) {
|
|
30749
|
+
const end = text.indexOf("'", index + 1);
|
|
30750
|
+
if (end < 0)
|
|
30751
|
+
return false;
|
|
30752
|
+
index = end;
|
|
30753
|
+
} else if (char === '"')
|
|
30754
|
+
quoted = !quoted;
|
|
30755
|
+
else if (char === "$" || char === "`")
|
|
30756
|
+
return false;
|
|
30757
|
+
else if (quoted)
|
|
30758
|
+
continue;
|
|
30759
|
+
else if (/[*?[]/u.test(char) || /[<>]/u.test(char) && text[index + 1] === "(")
|
|
30760
|
+
return false;
|
|
30761
|
+
else if (char === "~") {
|
|
30762
|
+
const start = index === 0 || colons && text[index - 1] === ":";
|
|
30763
|
+
if (!start || !/^(?:\/|:|$)/u.test(text.slice(index + 1, index + 2)))
|
|
30764
|
+
return false;
|
|
30765
|
+
}
|
|
30766
|
+
}
|
|
30767
|
+
return !quoted;
|
|
30768
|
+
};
|
|
30769
|
+
var NOT_A_PATH = /^(?:\d*|true|false|yes|no|on|off|-[\w-]*(?:=\d+)?)$/iu;
|
|
30770
|
+
var cwdFreeAssignment = (text, value) => {
|
|
30771
|
+
const written = text.replace(/^[A-Za-z_]\w*=/u, "");
|
|
30772
|
+
if (!cwdIndependent(written, true))
|
|
30773
|
+
return false;
|
|
30774
|
+
const quotes = /['"\\]/u.test(written);
|
|
30775
|
+
const parts = value.replace(/^[A-Za-z_]\w*=/u, "").split(":");
|
|
30776
|
+
return parts.every((part) => part.startsWith("/") || !quotes && /^~(?:\/|$)/u.test(part) || (part !== "" || parts.length === 1) && NOT_A_PATH.test(part));
|
|
30777
|
+
};
|
|
30778
|
+
var plainQuotedExpansions = (text) => {
|
|
30779
|
+
const bare = text.replaceAll(/\\./gu, "").replaceAll(/\$(?:[A-Za-z_]\w*|\{[A-Za-z_]\w*\})/gu, "");
|
|
30780
|
+
return !bare.includes("$") && !bare.includes("`");
|
|
30781
|
+
};
|
|
30782
|
+
var certainDir = (text, value) => value !== "" && !value.startsWith("-") && (/^(?:"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(text) && (text.startsWith("'") || plainQuotedExpansions(text)) || cwdIndependent(text) && !/[{}]/u.test(text.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"|\\./gu, "")));
|
|
30783
|
+
var namesSet = (segments) => {
|
|
30784
|
+
const names = new Set;
|
|
30785
|
+
for (const { words } of segments) {
|
|
30786
|
+
const at = /^(?:export|declare|typeset|local|readonly)$/u.test(words[0] ?? "") ? 1 : 0;
|
|
30787
|
+
const assigns = words.slice(at).filter((word) => /^[A-Za-z_]\w*=/u.test(word));
|
|
30788
|
+
if (at === 1 || assigns.length === words.length)
|
|
30789
|
+
for (const word of assigns)
|
|
30790
|
+
names.add(word.slice(0, word.indexOf("=")));
|
|
30791
|
+
if (words[0] === "read" || words[0] === "mapfile") {
|
|
30792
|
+
for (const word of words.slice(1))
|
|
30793
|
+
if (/^[A-Za-z_]\w*$/u.test(word))
|
|
30794
|
+
names.add(word);
|
|
30795
|
+
}
|
|
30796
|
+
}
|
|
30797
|
+
return names;
|
|
30798
|
+
};
|
|
30799
|
+
var NO_PATH = /^(?:\d+|-[A-Za-z0-9-]*)$/u;
|
|
30800
|
+
var cwdFreeTail = (texts, check = false) => {
|
|
30801
|
+
const [command = "", ...args] = texts;
|
|
30802
|
+
if (command.includes("/") && !command.startsWith("/"))
|
|
30803
|
+
return false;
|
|
30804
|
+
return check || args.every((text) => NO_PATH.test(text) || /^(?:\/|~(?:\/|$))/u.test(text));
|
|
30805
|
+
};
|
|
30806
|
+
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
30807
|
+
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
30808
|
+
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
30809
|
+
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
30810
|
+
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
30811
|
+
var stdinOnly = (words) => {
|
|
30812
|
+
const [name, ...args] = words;
|
|
30813
|
+
const operands = args.filter((w) => !w.startsWith("-"));
|
|
30814
|
+
if (name === "grep")
|
|
30815
|
+
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
30816
|
+
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
30817
|
+
};
|
|
30818
|
+
var cwdRewrite = (command) => {
|
|
30819
|
+
const match = COMPOUND2.exec(command);
|
|
30820
|
+
const dir = match?.[1];
|
|
30821
|
+
const rest = match?.[2];
|
|
30822
|
+
if (!dir || !rest || dir.startsWith("-"))
|
|
30823
|
+
return null;
|
|
30824
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
30825
|
+
return null;
|
|
30826
|
+
const segments = segmentsOf(rest);
|
|
30827
|
+
const [head, ...filters] = segments;
|
|
30828
|
+
if (!head || head.words[0] !== "workit")
|
|
30829
|
+
return null;
|
|
30830
|
+
if (!segments.every(clean))
|
|
30831
|
+
return null;
|
|
30832
|
+
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
30833
|
+
return null;
|
|
30834
|
+
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
30835
|
+
return null;
|
|
30836
|
+
const at = head.words.indexOf("--cwd");
|
|
30837
|
+
if (at >= 0) {
|
|
30838
|
+
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
30839
|
+
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
30840
|
+
}
|
|
30841
|
+
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
30842
|
+
return null;
|
|
30843
|
+
const args = rest.slice("workit".length).trimStart();
|
|
30844
|
+
const verb = VERB_FIRST.exec(args);
|
|
30845
|
+
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
30846
|
+
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
30847
|
+
const json = verb[1] ? " --json" : "";
|
|
30848
|
+
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
30849
|
+
};
|
|
30850
|
+
var verbFirst = (command) => {
|
|
30851
|
+
const match = GLOBALS_FIRST.exec(command);
|
|
30852
|
+
const [whole, lead, globals, verb] = match ?? [];
|
|
30853
|
+
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
30854
|
+
return null;
|
|
30855
|
+
const segments = segmentsOf(command);
|
|
30856
|
+
if (segments.length !== 1 || !segments.every(clean))
|
|
30857
|
+
return null;
|
|
30858
|
+
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
30859
|
+
};
|
|
30860
|
+
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
30861
|
+
var npxWorkit = (command) => {
|
|
30862
|
+
const match = NPX.exec(command);
|
|
30863
|
+
if (!match)
|
|
30864
|
+
return null;
|
|
30865
|
+
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
30866
|
+
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
30867
|
+
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
30868
|
+
};
|
|
30869
|
+
|
|
30870
|
+
// packages/workit-core/src/approvals/youtrack-ask.ts
|
|
30871
|
+
var TIME = "markdown file minutes text date";
|
|
30872
|
+
var FLAGS = {
|
|
30873
|
+
note: TIME,
|
|
30874
|
+
time: TIME,
|
|
30875
|
+
meeting: TIME,
|
|
30876
|
+
update: `${TIME} attach state command`,
|
|
30877
|
+
create: "project summary description file attach command"
|
|
30878
|
+
};
|
|
30879
|
+
|
|
30880
|
+
// packages/workit-core/src/approvals/inline.ts
|
|
30881
|
+
var DIR2 = "<dir>";
|
|
30882
|
+
var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
|
|
30883
|
+
|
|
30884
|
+
// packages/workit-core/src/hooks/hosts/claude-code.ts
|
|
30885
|
+
var CLAUDE_CODE_DESCRIPTOR = {
|
|
30886
|
+
host: "claude_code",
|
|
30887
|
+
label: "Claude Code",
|
|
30888
|
+
verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
|
|
30889
|
+
docs: ["https://code.claude.com/docs/en/hooks"],
|
|
30890
|
+
transport: "hook-process",
|
|
30891
|
+
events: {
|
|
30892
|
+
"session.start": { support: "native", native: "SessionStart" },
|
|
30893
|
+
"session.end": { support: "native", native: "SessionEnd" },
|
|
30894
|
+
"context.turn": { support: "native", native: "UserPromptSubmit" },
|
|
30895
|
+
"shell.pre": { support: "native", native: "PreToolUse" },
|
|
30896
|
+
"tool.pre": { support: "native", native: "PreToolUse" },
|
|
30897
|
+
"write.pre": { support: "native", native: "PreToolUse" },
|
|
30898
|
+
"shell.post": { support: "native", native: "PostToolUse" },
|
|
30899
|
+
"subagent.start": { support: "native", native: "SubagentStart" },
|
|
30900
|
+
"prompt.submit": { support: "native", native: "UserPromptSubmit" },
|
|
30901
|
+
"subagent.stop": { support: "native", native: "SubagentStop" },
|
|
30902
|
+
"compact.pre": { support: "none", native: null },
|
|
30903
|
+
stop: { support: "native", native: "Stop" }
|
|
30904
|
+
},
|
|
30905
|
+
shellPolicy: {
|
|
30906
|
+
deny: "native",
|
|
30907
|
+
channel: "permissionDecision",
|
|
30908
|
+
failClosed: false,
|
|
30909
|
+
rewrite: "native"
|
|
30910
|
+
},
|
|
30911
|
+
context: {
|
|
30912
|
+
sessionStart: "native",
|
|
30913
|
+
perTurn: "native",
|
|
30914
|
+
afterCompact: "native",
|
|
30915
|
+
task: "session-bound",
|
|
30916
|
+
turnResend: "on-change"
|
|
30917
|
+
},
|
|
30918
|
+
subagents: {
|
|
30919
|
+
identity: "native",
|
|
30920
|
+
parentBinding: "partial",
|
|
30921
|
+
blockStart: "none",
|
|
30922
|
+
worktreeIsolation: "native",
|
|
30923
|
+
maxConcurrency: "undocumented",
|
|
30924
|
+
agentPrefix: "workit:"
|
|
30925
|
+
},
|
|
30926
|
+
provenance: {
|
|
30927
|
+
sessionId: "native",
|
|
30928
|
+
agentIdOnTool: "native",
|
|
30929
|
+
postToolObserve: "native"
|
|
30930
|
+
},
|
|
30931
|
+
interaction: { questions: "undocumented", writeBoundary: "partial" },
|
|
30932
|
+
stopControl: "native",
|
|
30933
|
+
shellAvailable: "native",
|
|
30934
|
+
perEventCost: "low",
|
|
30935
|
+
capabilities: [
|
|
30639
30936
|
{
|
|
30640
30937
|
name: "known_product_writes",
|
|
30641
30938
|
surface: "PreToolUse",
|
|
@@ -31049,8 +31346,477 @@ var PI_DESCRIPTOR = {
|
|
|
31049
31346
|
assurance: "agent_guided",
|
|
31050
31347
|
reason: "independent review runs as a supervised stock-Pi process; evidence evaluation enforces reviewer exclusivity"
|
|
31051
31348
|
}
|
|
31052
|
-
]
|
|
31053
|
-
};
|
|
31349
|
+
]
|
|
31350
|
+
};
|
|
31351
|
+
|
|
31352
|
+
// packages/workit-core/src/hooks/identity-env.ts
|
|
31353
|
+
import fs30 from "node:fs";
|
|
31354
|
+
import path46 from "node:path";
|
|
31355
|
+
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
31356
|
+
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
31357
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
31358
|
+
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
31359
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
31360
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
31361
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
31362
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
31363
|
+
var powershell = (names) => new RegExp([
|
|
31364
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
31365
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
31366
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
31367
|
+
].join("|"), "iu");
|
|
31368
|
+
var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
|
|
31369
|
+
var POWERSHELL = powershell(NAMES);
|
|
31370
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
31371
|
+
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
31372
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
31373
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
31374
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
31375
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
31376
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
31377
|
+
].join("|"), "iu");
|
|
31378
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
31379
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
31380
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
31381
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
31382
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
31383
|
+
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
31384
|
+
var OPAQUE = new Set([
|
|
31385
|
+
"watch",
|
|
31386
|
+
"strace",
|
|
31387
|
+
"chroot",
|
|
31388
|
+
"flock",
|
|
31389
|
+
"ssh",
|
|
31390
|
+
"su",
|
|
31391
|
+
"runuser",
|
|
31392
|
+
"script",
|
|
31393
|
+
"parallel"
|
|
31394
|
+
]);
|
|
31395
|
+
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
31396
|
+
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
31397
|
+
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
31398
|
+
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
31399
|
+
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
31400
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
31401
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
31402
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
31403
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
31404
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
31405
|
+
var linksToWorkit = (word, cwd) => {
|
|
31406
|
+
const places = /[\\/]/u.test(word) ? [path46.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path46.delimiter).map((dir) => path46.join(dir, word));
|
|
31407
|
+
for (const place of places) {
|
|
31408
|
+
try {
|
|
31409
|
+
const real = fs30.realpathSync(place);
|
|
31410
|
+
return isWorkit(real);
|
|
31411
|
+
} catch {}
|
|
31412
|
+
}
|
|
31413
|
+
return false;
|
|
31414
|
+
};
|
|
31415
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
31416
|
+
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
31417
|
+
var note = (scan, seg, word) => {
|
|
31418
|
+
if (scan.identity && named(word)) {
|
|
31419
|
+
if (seg)
|
|
31420
|
+
seg.identity ??= nameOf(word);
|
|
31421
|
+
else
|
|
31422
|
+
scan.hit ??= nameOf(word);
|
|
31423
|
+
}
|
|
31424
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
31425
|
+
return;
|
|
31426
|
+
if (seg)
|
|
31427
|
+
seg.scoped ??= nameOf(word);
|
|
31428
|
+
else
|
|
31429
|
+
scan.shell ??= nameOf(word);
|
|
31430
|
+
};
|
|
31431
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
31432
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
31433
|
+
const risky = (what) => void (scan.risky ??= what);
|
|
31434
|
+
const unset = (name) => note(scan, seg, name);
|
|
31435
|
+
const split = (line, rest, built) => {
|
|
31436
|
+
if (line === undefined || depth >= 4)
|
|
31437
|
+
return risky(UNREADABLE);
|
|
31438
|
+
if (built || /[$`]/u.test(line))
|
|
31439
|
+
risky(UNREADABLE);
|
|
31440
|
+
const tokens = [];
|
|
31441
|
+
const expanded = new Set;
|
|
31442
|
+
try {
|
|
31443
|
+
for (const segment of segmentsOf(line)) {
|
|
31444
|
+
for (const index of segment.expands ?? [])
|
|
31445
|
+
expanded.add(tokens.length + index);
|
|
31446
|
+
tokens.push(...segment.words);
|
|
31447
|
+
}
|
|
31448
|
+
} catch {
|
|
31449
|
+
return risky(UNREADABLE);
|
|
31450
|
+
}
|
|
31451
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
31452
|
+
};
|
|
31453
|
+
let options = true;
|
|
31454
|
+
for (let index = at;index < words.length; index += 1) {
|
|
31455
|
+
const word = words[index] ?? "";
|
|
31456
|
+
if (expands.has(index)) {
|
|
31457
|
+
risky(UNREADABLE);
|
|
31458
|
+
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
31459
|
+
if (built)
|
|
31460
|
+
return split(built[1], index + 1, true);
|
|
31461
|
+
continue;
|
|
31462
|
+
}
|
|
31463
|
+
if (options && word === "--") {
|
|
31464
|
+
options = false;
|
|
31465
|
+
continue;
|
|
31466
|
+
}
|
|
31467
|
+
if (options && word === "-") {
|
|
31468
|
+
risky("env -i");
|
|
31469
|
+
continue;
|
|
31470
|
+
}
|
|
31471
|
+
if (options && word.startsWith("--")) {
|
|
31472
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
31473
|
+
if (name === "--ignore-environment")
|
|
31474
|
+
risky("env -i");
|
|
31475
|
+
else if (name === "--unset")
|
|
31476
|
+
unset(value ?? words[index += 1]);
|
|
31477
|
+
else if (name === "--split-string")
|
|
31478
|
+
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
31479
|
+
else if (ENV_LONG_VALUED.has(name))
|
|
31480
|
+
index += value === undefined ? 1 : 0;
|
|
31481
|
+
else if (!ENV_LONG_FLAGS.test(word))
|
|
31482
|
+
risky(UNREADABLE);
|
|
31483
|
+
continue;
|
|
31484
|
+
}
|
|
31485
|
+
if (options && word.startsWith("-") && word.length > 1) {
|
|
31486
|
+
for (let at2 = 1;at2 < word.length; at2 += 1) {
|
|
31487
|
+
const letter = word[at2] ?? "";
|
|
31488
|
+
if (letter === "i")
|
|
31489
|
+
risky("env -i");
|
|
31490
|
+
else if (ENV_FLAGS.has(letter))
|
|
31491
|
+
continue;
|
|
31492
|
+
else if (ENV_VALUED.has(letter)) {
|
|
31493
|
+
const glued = word.slice(at2 + 1);
|
|
31494
|
+
if (!glued)
|
|
31495
|
+
index += 1;
|
|
31496
|
+
const value = glued || words[index];
|
|
31497
|
+
if (letter === "u")
|
|
31498
|
+
unset(value);
|
|
31499
|
+
if (letter === "S")
|
|
31500
|
+
return split(value, index + 1, expands.has(index));
|
|
31501
|
+
break;
|
|
31502
|
+
} else {
|
|
31503
|
+
risky(UNREADABLE);
|
|
31504
|
+
break;
|
|
31505
|
+
}
|
|
31506
|
+
}
|
|
31507
|
+
continue;
|
|
31508
|
+
}
|
|
31509
|
+
if (ASSIGN.test(word)) {
|
|
31510
|
+
unset(word);
|
|
31511
|
+
continue;
|
|
31512
|
+
}
|
|
31513
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
31514
|
+
}
|
|
31515
|
+
};
|
|
31516
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
31517
|
+
let index = from;
|
|
31518
|
+
while (index < words.length) {
|
|
31519
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
31520
|
+
note(scan, seg, words[index]);
|
|
31521
|
+
index += 1;
|
|
31522
|
+
}
|
|
31523
|
+
const name = base2(words[index]).toLowerCase();
|
|
31524
|
+
if (name === "env")
|
|
31525
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
31526
|
+
if (OPAQUE.has(name))
|
|
31527
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
31528
|
+
if (name === "busybox" || name === "toybox") {
|
|
31529
|
+
index += 1;
|
|
31530
|
+
continue;
|
|
31531
|
+
}
|
|
31532
|
+
const takes = WRAPPERS3[name];
|
|
31533
|
+
if (takes === undefined)
|
|
31534
|
+
break;
|
|
31535
|
+
index = pastOptions(words, index + 1, takes);
|
|
31536
|
+
}
|
|
31537
|
+
const word = words[index];
|
|
31538
|
+
if (word === undefined)
|
|
31539
|
+
return;
|
|
31540
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
31541
|
+
const rest = words.slice(index + 1);
|
|
31542
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
31543
|
+
seg.runs = true;
|
|
31544
|
+
if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
|
|
31545
|
+
opaque(rest, scan, seg, false);
|
|
31546
|
+
const program = base2(word).toLowerCase();
|
|
31547
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
31548
|
+
if (program === "cmd" || shell) {
|
|
31549
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
31550
|
+
if (at >= 0) {
|
|
31551
|
+
const script = rest.slice(at + 1).join(" ");
|
|
31552
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
31553
|
+
if (change)
|
|
31554
|
+
scan.hit ??= change;
|
|
31555
|
+
}
|
|
31556
|
+
}
|
|
31557
|
+
};
|
|
31558
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
31559
|
+
if (!rest.some(isWorkit))
|
|
31560
|
+
return;
|
|
31561
|
+
seg.runs = true;
|
|
31562
|
+
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
31563
|
+
if (rest.some(changes))
|
|
31564
|
+
scan.risky ??= UNREADABLE;
|
|
31565
|
+
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
31566
|
+
for (const word of rest)
|
|
31567
|
+
note(scan, seg, word);
|
|
31568
|
+
};
|
|
31569
|
+
var LOGIN_VALUED = {
|
|
31570
|
+
su: /[sgGwc]/u,
|
|
31571
|
+
runuser: /[sgGwuc]/u,
|
|
31572
|
+
script: /[cEIOBTmot]/u
|
|
31573
|
+
};
|
|
31574
|
+
var loginScript = (words) => {
|
|
31575
|
+
const at = words.findIndex((word) => /^(?:su|runuser|script)$/u.test(base2(word)));
|
|
31576
|
+
if (at < 0)
|
|
31577
|
+
return null;
|
|
31578
|
+
const valued = LOGIN_VALUED[base2(words[at])] ?? /c/u;
|
|
31579
|
+
for (let index = at + 1;index < words.length; index += 1) {
|
|
31580
|
+
const word = words[index] ?? "";
|
|
31581
|
+
if (word === "--command")
|
|
31582
|
+
return words[index + 1] ?? null;
|
|
31583
|
+
if (word.startsWith("--command="))
|
|
31584
|
+
return word.slice("--command=".length);
|
|
31585
|
+
if (!/^-[^-]/u.test(word))
|
|
31586
|
+
continue;
|
|
31587
|
+
const ends = word.slice(1).search(valued) + 1;
|
|
31588
|
+
if (ends > 0 && word[ends] === "c")
|
|
31589
|
+
return word.slice(ends + 1) || (words[index + 1] ?? null);
|
|
31590
|
+
}
|
|
31591
|
+
return null;
|
|
31592
|
+
};
|
|
31593
|
+
var scanCommand = (command, dialect, depth, scan) => {
|
|
31594
|
+
let segments;
|
|
31595
|
+
try {
|
|
31596
|
+
segments = segmentsOf(command, dialect);
|
|
31597
|
+
} catch {
|
|
31598
|
+
return;
|
|
31599
|
+
}
|
|
31600
|
+
for (const { words, expands = [] } of segments) {
|
|
31601
|
+
const expanded = new Set(expands);
|
|
31602
|
+
const seg = newSeg();
|
|
31603
|
+
let at = 0;
|
|
31604
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
31605
|
+
at += 1;
|
|
31606
|
+
for (const word of words.slice(0, at))
|
|
31607
|
+
note(scan, at === words.length ? null : seg, word);
|
|
31608
|
+
let declare = at;
|
|
31609
|
+
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
31610
|
+
declare += 1;
|
|
31611
|
+
if (DECLARES.has(words[declare] ?? "")) {
|
|
31612
|
+
for (let index = declare + 1;index < words.length; index += 1) {
|
|
31613
|
+
note(scan, null, words[index]);
|
|
31614
|
+
if (expanded.has(index))
|
|
31615
|
+
scan.risky ??= UNREADABLE;
|
|
31616
|
+
}
|
|
31617
|
+
continue;
|
|
31618
|
+
}
|
|
31619
|
+
commandAt(words, scan, seg, expanded, at);
|
|
31620
|
+
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
31621
|
+
if (script) {
|
|
31622
|
+
const before = scan.runs;
|
|
31623
|
+
scan.runs = false;
|
|
31624
|
+
scanCommand(script, dialect, depth + 1, scan);
|
|
31625
|
+
seg.runs ||= scan.runs;
|
|
31626
|
+
scan.runs ||= before;
|
|
31627
|
+
}
|
|
31628
|
+
scan.words.push(...seg.words);
|
|
31629
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
31630
|
+
if (seg.identity && reaches())
|
|
31631
|
+
scan.hit ??= seg.identity;
|
|
31632
|
+
if (seg.scoped && reaches())
|
|
31633
|
+
scan.state ??= seg.scoped;
|
|
31634
|
+
scan.runs ||= seg.runs;
|
|
31635
|
+
}
|
|
31636
|
+
};
|
|
31637
|
+
var cmdChange = (script, scan) => (scan.identity ? CMD_IDENTITY.exec(script)?.[1] : null) ?? (RUNS_TEXT.test(script) ? CMD_STATE.exec(script)?.[1] ?? (scan.identity ? CMD_HOST.exec(script)?.[1] : null) ?? null : null);
|
|
31638
|
+
var powershellChange = (command, identity) => {
|
|
31639
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
31640
|
+
if (hit)
|
|
31641
|
+
return hit;
|
|
31642
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
31643
|
+
return null;
|
|
31644
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
31645
|
+
if (state)
|
|
31646
|
+
return state;
|
|
31647
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
31648
|
+
};
|
|
31649
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
31650
|
+
const identity = options.identity ?? true;
|
|
31651
|
+
if (dialect === "powershell")
|
|
31652
|
+
return powershellChange(command, identity);
|
|
31653
|
+
if (!/WORKIT_|XDG_|HOME|USERPROFILE|APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|EnvironmentVariable|\b(?:env|unset|export|declare|typeset|local|readonly)\b/iu.test(command))
|
|
31654
|
+
return null;
|
|
31655
|
+
const scan = {
|
|
31656
|
+
identity,
|
|
31657
|
+
cwd: options.cwd,
|
|
31658
|
+
hit: null,
|
|
31659
|
+
state: null,
|
|
31660
|
+
shell: null,
|
|
31661
|
+
risky: null,
|
|
31662
|
+
runs: false,
|
|
31663
|
+
words: []
|
|
31664
|
+
};
|
|
31665
|
+
scanCommand(command, dialect, 0, scan);
|
|
31666
|
+
if (scan.hit)
|
|
31667
|
+
return scan.hit;
|
|
31668
|
+
if (scan.state)
|
|
31669
|
+
return scan.state;
|
|
31670
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
31671
|
+
return scan.shell;
|
|
31672
|
+
return scan.runs ? scan.risky : null;
|
|
31673
|
+
};
|
|
31674
|
+
|
|
31675
|
+
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
31676
|
+
var EXIT_VERBS = [
|
|
31677
|
+
["ci", "wait"],
|
|
31678
|
+
["check"],
|
|
31679
|
+
["pr", "merge"],
|
|
31680
|
+
["release"],
|
|
31681
|
+
["verify-delivery"]
|
|
31682
|
+
];
|
|
31683
|
+
var base3 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
31684
|
+
var verbPath = (words) => {
|
|
31685
|
+
const path = [];
|
|
31686
|
+
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
31687
|
+
const word = words[at];
|
|
31688
|
+
if (word === "--")
|
|
31689
|
+
break;
|
|
31690
|
+
if (word === "--cwd")
|
|
31691
|
+
at += 1;
|
|
31692
|
+
else if (!word.startsWith("-"))
|
|
31693
|
+
path.push(word);
|
|
31694
|
+
}
|
|
31695
|
+
return path;
|
|
31696
|
+
};
|
|
31697
|
+
var identityAssignment = (name) => identityEnvChange(`${name}=x workit`) !== null;
|
|
31698
|
+
var identityWhy = (names) => names.length ? `
|
|
31699
|
+
Why: the retry leaves out ${names.join(", ")}: the identity guard refuses a workit call that sets ${names.length === 1 ? "it" : "them"}.` : "";
|
|
31700
|
+
var exitCall = (segment, first) => {
|
|
31701
|
+
const { words } = segment;
|
|
31702
|
+
let at = first;
|
|
31703
|
+
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
31704
|
+
at += 1;
|
|
31705
|
+
if (!/^workit(?:-cli)?$/u.test(base3(words[at])))
|
|
31706
|
+
return null;
|
|
31707
|
+
const path = verbPath(words.slice(at + 1));
|
|
31708
|
+
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? { segment, first, at } : null;
|
|
31709
|
+
};
|
|
31710
|
+
var backgrounded = (command, segment) => {
|
|
31711
|
+
const ends = [...segment.spans ?? [], ...segment.redirectSpans ?? []].map(([, end]) => end);
|
|
31712
|
+
return /^[ \t]*&(?![&>])/u.test(command.slice(Math.max(0, ...ends)));
|
|
31713
|
+
};
|
|
31714
|
+
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
31715
|
+
var range = (from, to) => Array.from({ length: to - from }, (_, i) => from + i);
|
|
31716
|
+
var absoluteCwd = (text, value) => cwdIndependent(text) && (/^(?:\/|[A-Za-z]:[\\/])/u.test(value) || /^~(?:\/|$)/u.test(text));
|
|
31717
|
+
var retryOf = (command, found) => {
|
|
31718
|
+
const { segment, first, at, cd, set } = found;
|
|
31719
|
+
const { words } = segment;
|
|
31720
|
+
const dropped = [];
|
|
31721
|
+
const env = range(first, at).filter((index) => {
|
|
31722
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
31723
|
+
if (!identityAssignment(name))
|
|
31724
|
+
return true;
|
|
31725
|
+
dropped.push(name);
|
|
31726
|
+
return false;
|
|
31727
|
+
});
|
|
31728
|
+
const envText = writtenWords(command, segment, env);
|
|
31729
|
+
const callText = writtenWords(command, segment, range(at + 1, words.length));
|
|
31730
|
+
const dir = cd ? writtenWord(command, cd, 1) : "";
|
|
31731
|
+
if (!envText || !callText || cd === undefined || dir === null)
|
|
31732
|
+
return { retry: null, dropped };
|
|
31733
|
+
const reads = [dir, ...envText, ...callText].flatMap((text) => [...text.matchAll(/\$\{?(\w+)/gu)].map((match) => match[1] ?? "")).find((name) => set.has(name));
|
|
31734
|
+
if (reads)
|
|
31735
|
+
return { retry: null, dropped, reads };
|
|
31736
|
+
const call = words.slice(at + 1);
|
|
31737
|
+
const verbAt = call[0]?.startsWith("-") ? 0 : 1;
|
|
31738
|
+
const plain = (body) => [...envText, "workit", ...body].join(" ");
|
|
31739
|
+
if (!cd)
|
|
31740
|
+
return { retry: plain(callText), dropped };
|
|
31741
|
+
const check = verbPath(call)[0] === "check";
|
|
31742
|
+
const cwds = range(at + 1, words.length).filter((index) => words.slice(at + 1, index).every((word) => word !== "--") && (words[index - 1] === "--cwd" || words[index].startsWith("--cwd=")));
|
|
31743
|
+
const moves = certainDir(dir, cd.words[1] ?? "") && env.every((index, n) => cwdFreeAssignment(envText[n] ?? "", words[index])) && callText.every((text) => cwdIndependent(text)) && (!call.includes("--") || callText.includes("--") && cwdFreeTail(callText.slice(callText.indexOf("--") + 1), check)) && cwds.every((index) => {
|
|
31744
|
+
const text = writtenWord(command, segment, index) ?? "";
|
|
31745
|
+
return absoluteCwd(text.replace(/^--cwd=/u, ""), words[index].replace(/^--cwd=/u, ""));
|
|
31746
|
+
});
|
|
31747
|
+
if (!moves)
|
|
31748
|
+
return { retry: `cd ${dir} && ${plain(callText)}`, dropped };
|
|
31749
|
+
if (cwds.length)
|
|
31750
|
+
return { retry: plain(callText), dropped };
|
|
31751
|
+
return {
|
|
31752
|
+
retry: plain([...callText.slice(0, verbAt), "--cwd", dir, ...callText.slice(verbAt)]),
|
|
31753
|
+
dropped
|
|
31754
|
+
};
|
|
31755
|
+
};
|
|
31756
|
+
function exitPipeGate(command, dialect = "posix") {
|
|
31757
|
+
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
31758
|
+
return null;
|
|
31759
|
+
const groups = [];
|
|
31760
|
+
let carry = null;
|
|
31761
|
+
let pipefail = false;
|
|
31762
|
+
let cd = null;
|
|
31763
|
+
const seen = [];
|
|
31764
|
+
const chained = !command.includes("||");
|
|
31765
|
+
for (const segment of segmentsOf(command, dialect, { spans: true })) {
|
|
31766
|
+
if (segment.unanalyzable)
|
|
31767
|
+
return null;
|
|
31768
|
+
let words = segment.words;
|
|
31769
|
+
let closes = segment.group === "close";
|
|
31770
|
+
if (segment.group === "open") {
|
|
31771
|
+
groups.push(null);
|
|
31772
|
+
continue;
|
|
31773
|
+
}
|
|
31774
|
+
if (words[0] === "{") {
|
|
31775
|
+
groups.push(null);
|
|
31776
|
+
words = words.slice(1);
|
|
31777
|
+
} else if (words[0] === "}") {
|
|
31778
|
+
closes = true;
|
|
31779
|
+
words = words.slice(1);
|
|
31780
|
+
}
|
|
31781
|
+
if (closes) {
|
|
31782
|
+
const inner = groups.pop() ?? null;
|
|
31783
|
+
if (segment.group === "close" && cd)
|
|
31784
|
+
cd = undefined;
|
|
31785
|
+
if (inner && groups.length)
|
|
31786
|
+
groups[groups.length - 1] = inner;
|
|
31787
|
+
carry = segment.pipe ? inner ?? carry : null;
|
|
31788
|
+
continue;
|
|
31789
|
+
}
|
|
31790
|
+
if (!words.length && !segment.stdin && !segment.subs)
|
|
31791
|
+
continue;
|
|
31792
|
+
if (setsPipefail(words))
|
|
31793
|
+
pipefail = true;
|
|
31794
|
+
const filter = base3(words[0]);
|
|
31795
|
+
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
31796
|
+
const { retry, dropped, reads } = retryOf(command, carry);
|
|
31797
|
+
const verb = verbPath(carry.segment.words.slice(carry.at + 1)).join(" ");
|
|
31798
|
+
const why = reads ? `Why: an earlier step sets $${reads}, which the call reads: run the same command without the \`| ${filter}\`, that step kept.` : `Why: run the same call without the \`| ${filter}\`, its words as you wrote them.`;
|
|
31799
|
+
return {
|
|
31800
|
+
kind: "deny",
|
|
31801
|
+
reason: `workit exit-pipe: piping \`workit ${verb}\` into ${filter} hides its exit code.
|
|
31802
|
+
${retry ? `Retry as: ${retry}` : why}${identityWhy(dropped)}`,
|
|
31803
|
+
unblock: retry
|
|
31804
|
+
};
|
|
31805
|
+
}
|
|
31806
|
+
const call = exitCall(segment, segment.words.length - words.length);
|
|
31807
|
+
const found = call ? { ...call, cd, set: namesSet(seen) } : null;
|
|
31808
|
+
seen.push(segment);
|
|
31809
|
+
if (found && groups.length)
|
|
31810
|
+
groups[groups.length - 1] = found;
|
|
31811
|
+
carry = segment.pipe ? found ?? carry : null;
|
|
31812
|
+
const clean = chained && words === segment.words && words.length === 2 && !segment.pipe && !backgrounded(command, segment);
|
|
31813
|
+
if (words[0] === "cd")
|
|
31814
|
+
cd = clean && cd === null ? segment : undefined;
|
|
31815
|
+
else if (cd)
|
|
31816
|
+
cd = undefined;
|
|
31817
|
+
}
|
|
31818
|
+
return null;
|
|
31819
|
+
}
|
|
31054
31820
|
|
|
31055
31821
|
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
31056
31822
|
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
@@ -31079,17 +31845,17 @@ var workitRole = (descriptor, agentType) => {
|
|
|
31079
31845
|
|
|
31080
31846
|
// packages/workit-core/src/hooks/standing.ts
|
|
31081
31847
|
var readPlans = (store) => {
|
|
31082
|
-
const dir =
|
|
31848
|
+
const dir = path47.join(store, "fanouts");
|
|
31083
31849
|
let names;
|
|
31084
31850
|
try {
|
|
31085
|
-
names =
|
|
31851
|
+
names = fs31.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
31086
31852
|
} catch {
|
|
31087
31853
|
return [];
|
|
31088
31854
|
}
|
|
31089
31855
|
const plans = [];
|
|
31090
31856
|
for (const name of names) {
|
|
31091
31857
|
try {
|
|
31092
|
-
const raw = JSON.parse(
|
|
31858
|
+
const raw = JSON.parse(fs31.readFileSync(path47.join(dir, name), "utf8"));
|
|
31093
31859
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
31094
31860
|
continue;
|
|
31095
31861
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -31199,73 +31965,6 @@ var standingSinceStart = (input) => {
|
|
|
31199
31965
|
return null;
|
|
31200
31966
|
}
|
|
31201
31967
|
};
|
|
31202
|
-
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
31203
|
-
var DIR2 = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
31204
|
-
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR2})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
31205
|
-
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR2})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
31206
|
-
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
31207
|
-
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
31208
|
-
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
31209
|
-
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
31210
|
-
var stdinOnly = (words) => {
|
|
31211
|
-
const [name, ...args] = words;
|
|
31212
|
-
const operands = args.filter((w) => !w.startsWith("-"));
|
|
31213
|
-
if (name === "grep")
|
|
31214
|
-
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
31215
|
-
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
31216
|
-
};
|
|
31217
|
-
var cwdRewrite = (command) => {
|
|
31218
|
-
const match = COMPOUND2.exec(command);
|
|
31219
|
-
const dir = match?.[1];
|
|
31220
|
-
const rest = match?.[2];
|
|
31221
|
-
if (!dir || !rest || dir.startsWith("-"))
|
|
31222
|
-
return null;
|
|
31223
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
31224
|
-
return null;
|
|
31225
|
-
const segments = segmentsOf(rest);
|
|
31226
|
-
const [head, ...filters] = segments;
|
|
31227
|
-
if (!head || head.words[0] !== "workit")
|
|
31228
|
-
return null;
|
|
31229
|
-
if (!segments.every(clean))
|
|
31230
|
-
return null;
|
|
31231
|
-
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
31232
|
-
return null;
|
|
31233
|
-
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
31234
|
-
return null;
|
|
31235
|
-
const at = head.words.indexOf("--cwd");
|
|
31236
|
-
if (at >= 0) {
|
|
31237
|
-
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
31238
|
-
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
31239
|
-
}
|
|
31240
|
-
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
31241
|
-
return null;
|
|
31242
|
-
const args = rest.slice("workit".length).trimStart();
|
|
31243
|
-
const verb = VERB_FIRST.exec(args);
|
|
31244
|
-
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
31245
|
-
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
31246
|
-
const json = verb[1] ? " --json" : "";
|
|
31247
|
-
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
31248
|
-
};
|
|
31249
|
-
var verbFirst = (command) => {
|
|
31250
|
-
const match = GLOBALS_FIRST.exec(command);
|
|
31251
|
-
const [whole, lead, globals, verb] = match ?? [];
|
|
31252
|
-
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
31253
|
-
return null;
|
|
31254
|
-
const segments = segmentsOf(command);
|
|
31255
|
-
if (segments.length !== 1 || !segments.every(clean))
|
|
31256
|
-
return null;
|
|
31257
|
-
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
31258
|
-
};
|
|
31259
|
-
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR2})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
31260
|
-
var npxWorkit = (command) => {
|
|
31261
|
-
const match = NPX.exec(command);
|
|
31262
|
-
if (!match)
|
|
31263
|
-
return null;
|
|
31264
|
-
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
31265
|
-
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
31266
|
-
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
31267
|
-
};
|
|
31268
|
-
|
|
31269
31968
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
31270
31969
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
31271
31970
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
@@ -31407,9 +32106,9 @@ var SCAN_MS = 30 * 60000;
|
|
|
31407
32106
|
var UNLISTED = new Set(["description", "prompt"]);
|
|
31408
32107
|
|
|
31409
32108
|
// packages/workit-core/src/hooks/server-gate.ts
|
|
31410
|
-
import
|
|
31411
|
-
import
|
|
31412
|
-
var procNoticeFile = (env, session) =>
|
|
32109
|
+
import fs32 from "node:fs";
|
|
32110
|
+
import path48 from "node:path";
|
|
32111
|
+
var procNoticeFile = (env, session) => path48.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
|
|
31413
32112
|
var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
|
|
31414
32113
|
function takeProcNotice(session, env = process.env) {
|
|
31415
32114
|
if (!session)
|
|
@@ -31417,12 +32116,12 @@ function takeProcNotice(session, env = process.env) {
|
|
|
31417
32116
|
const file = procNoticeFile(env, session);
|
|
31418
32117
|
const taken = `${file}.${process.pid}.taken`;
|
|
31419
32118
|
try {
|
|
31420
|
-
|
|
32119
|
+
fs32.renameSync(file, taken);
|
|
31421
32120
|
} catch {
|
|
31422
32121
|
return null;
|
|
31423
32122
|
}
|
|
31424
32123
|
try {
|
|
31425
|
-
const { notices } = JSON.parse(
|
|
32124
|
+
const { notices } = JSON.parse(fs32.readFileSync(taken, "utf8"));
|
|
31426
32125
|
const lines = (Array.isArray(notices) ? notices : []).flatMap((notice) => {
|
|
31427
32126
|
if (!notice || typeof notice !== "object")
|
|
31428
32127
|
return [];
|
|
@@ -31439,29 +32138,29 @@ function takeProcNotice(session, env = process.env) {
|
|
|
31439
32138
|
return null;
|
|
31440
32139
|
} finally {
|
|
31441
32140
|
try {
|
|
31442
|
-
|
|
32141
|
+
fs32.rmSync(taken, { force: true });
|
|
31443
32142
|
} catch {}
|
|
31444
32143
|
}
|
|
31445
32144
|
}
|
|
31446
32145
|
|
|
31447
32146
|
// packages/workit-core/src/hooks/teardown.ts
|
|
31448
32147
|
import { spawn } from "node:child_process";
|
|
31449
|
-
import
|
|
31450
|
-
import
|
|
32148
|
+
import fs33 from "node:fs";
|
|
32149
|
+
import path50 from "node:path";
|
|
31451
32150
|
|
|
31452
32151
|
// packages/workit-core/src/core/cli-locate.ts
|
|
31453
32152
|
import { closeSync as closeSync3, existsSync as existsSync17, openSync as openSync3, readSync } from "node:fs";
|
|
31454
|
-
import
|
|
32153
|
+
import path49 from "node:path";
|
|
31455
32154
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
31456
32155
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
31457
32156
|
var installRoot = (env, platform = process.platform) => {
|
|
31458
32157
|
if (env.WORKIT_INSTALL_ROOT)
|
|
31459
32158
|
return env.WORKIT_INSTALL_ROOT;
|
|
31460
32159
|
const data = dataDir(env, platform);
|
|
31461
|
-
return platform === "win32" ?
|
|
32160
|
+
return platform === "win32" ? path49.join(data, "install") : data;
|
|
31462
32161
|
};
|
|
31463
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
31464
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
32162
|
+
var ownedLauncherPath = (env, platform = process.platform) => path49.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
32163
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path49.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
31465
32164
|
var head = (file) => {
|
|
31466
32165
|
let fd;
|
|
31467
32166
|
try {
|
|
@@ -31488,7 +32187,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
31488
32187
|
source: "owned-launcher",
|
|
31489
32188
|
command: launcher,
|
|
31490
32189
|
args: [],
|
|
31491
|
-
binDir:
|
|
32190
|
+
binDir: path49.dirname(launcher)
|
|
31492
32191
|
};
|
|
31493
32192
|
const current = ownedCurrentEntry(env, platform);
|
|
31494
32193
|
if (exists(current))
|
|
@@ -31517,7 +32216,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
31517
32216
|
if (located.binDir) {
|
|
31518
32217
|
const key = pathKey(env);
|
|
31519
32218
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
31520
|
-
const same = (dir) => platform === "win32" ?
|
|
32219
|
+
const same = (dir) => platform === "win32" ? path49.win32.normalize(dir).toLowerCase() === path49.win32.normalize(located.binDir).toLowerCase() : path49.posix.normalize(dir) === path49.posix.normalize(located.binDir);
|
|
31521
32220
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
31522
32221
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
31523
32222
|
}
|
|
@@ -31541,9 +32240,9 @@ var ENDS = {
|
|
|
31541
32240
|
};
|
|
31542
32241
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
31543
32242
|
var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
31544
|
-
var teardownDir = (env) =>
|
|
31545
|
-
var teardownLog = (env) =>
|
|
31546
|
-
var reapStamp = (env) =>
|
|
32243
|
+
var teardownDir = (env) => path50.join(stateDir(env), "procs");
|
|
32244
|
+
var teardownLog = (env) => path50.join(teardownDir(env), "teardown.log");
|
|
32245
|
+
var reapStamp = (env) => path50.join(teardownDir(env), "reap-at-start.stamp");
|
|
31547
32246
|
function spawnDetached(request) {
|
|
31548
32247
|
try {
|
|
31549
32248
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -31570,13 +32269,13 @@ var teardownDeps = {
|
|
|
31570
32269
|
var openLog = (env, args) => {
|
|
31571
32270
|
try {
|
|
31572
32271
|
const file = teardownLog(env);
|
|
31573
|
-
|
|
32272
|
+
fs33.mkdirSync(path50.dirname(file), { recursive: true });
|
|
31574
32273
|
let size = 0;
|
|
31575
32274
|
try {
|
|
31576
|
-
size =
|
|
32275
|
+
size = fs33.statSync(file).size;
|
|
31577
32276
|
} catch {}
|
|
31578
|
-
const fd =
|
|
31579
|
-
|
|
32277
|
+
const fd = fs33.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
32278
|
+
fs33.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
31580
32279
|
`);
|
|
31581
32280
|
return fd;
|
|
31582
32281
|
} catch {
|
|
@@ -31588,7 +32287,7 @@ function runCli(args, env) {
|
|
|
31588
32287
|
try {
|
|
31589
32288
|
const cli = locateWorkitCli({ env });
|
|
31590
32289
|
const cwd = teardownDir(env);
|
|
31591
|
-
|
|
32290
|
+
fs33.mkdirSync(cwd, { recursive: true });
|
|
31592
32291
|
log = openLog(env, args);
|
|
31593
32292
|
const started = teardownDeps.spawn({
|
|
31594
32293
|
command: cli.command,
|
|
@@ -31598,7 +32297,7 @@ function runCli(args, env) {
|
|
|
31598
32297
|
log
|
|
31599
32298
|
});
|
|
31600
32299
|
if (!started && log !== null)
|
|
31601
|
-
|
|
32300
|
+
fs33.writeSync(log, ` not started
|
|
31602
32301
|
`);
|
|
31603
32302
|
return started;
|
|
31604
32303
|
} catch {
|
|
@@ -31606,7 +32305,7 @@ function runCli(args, env) {
|
|
|
31606
32305
|
} finally {
|
|
31607
32306
|
if (log !== null)
|
|
31608
32307
|
try {
|
|
31609
|
-
|
|
32308
|
+
fs33.closeSync(log);
|
|
31610
32309
|
} catch {}
|
|
31611
32310
|
}
|
|
31612
32311
|
}
|
|
@@ -31625,24 +32324,24 @@ function endSession(end, env = process.env) {
|
|
|
31625
32324
|
var claim2 = (file, now) => {
|
|
31626
32325
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
31627
32326
|
try {
|
|
31628
|
-
|
|
32327
|
+
fs33.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
31629
32328
|
return true;
|
|
31630
32329
|
} catch (error) {
|
|
31631
32330
|
if (error.code !== "EEXIST")
|
|
31632
32331
|
return false;
|
|
31633
32332
|
let held = Number.NaN;
|
|
31634
32333
|
try {
|
|
31635
|
-
held = Number(
|
|
32334
|
+
held = Number(fs33.readFileSync(file, "utf8"));
|
|
31636
32335
|
} catch {}
|
|
31637
32336
|
if (now - held < REAP_INTERVAL_MS)
|
|
31638
32337
|
return false;
|
|
31639
|
-
|
|
32338
|
+
fs33.rmSync(file, { force: true });
|
|
31640
32339
|
}
|
|
31641
32340
|
return false;
|
|
31642
32341
|
};
|
|
31643
32342
|
var fresh = (stamp, now) => {
|
|
31644
32343
|
try {
|
|
31645
|
-
const last = Number(
|
|
32344
|
+
const last = Number(fs33.readFileSync(stamp, "utf8"));
|
|
31646
32345
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
31647
32346
|
} catch {
|
|
31648
32347
|
return false;
|
|
@@ -31655,7 +32354,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
31655
32354
|
try {
|
|
31656
32355
|
if (fresh(stamp, now))
|
|
31657
32356
|
return false;
|
|
31658
|
-
|
|
32357
|
+
fs33.mkdirSync(path50.dirname(stamp), { recursive: true });
|
|
31659
32358
|
if (!claim2(lock, now))
|
|
31660
32359
|
return false;
|
|
31661
32360
|
} catch {
|
|
@@ -31668,12 +32367,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
31668
32367
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
31669
32368
|
if (started) {
|
|
31670
32369
|
const temp = `${stamp}.${process.pid}`;
|
|
31671
|
-
|
|
31672
|
-
|
|
32370
|
+
fs33.writeFileSync(temp, String(now), { mode: 384 });
|
|
32371
|
+
fs33.renameSync(temp, stamp);
|
|
31673
32372
|
}
|
|
31674
32373
|
} catch {} finally {
|
|
31675
32374
|
try {
|
|
31676
|
-
|
|
32375
|
+
fs33.rmSync(lock, { force: true });
|
|
31677
32376
|
} catch {}
|
|
31678
32377
|
}
|
|
31679
32378
|
return started;
|
|
@@ -32252,98 +32951,6 @@ Retry as: ${retry}` : ""}`,
|
|
|
32252
32951
|
};
|
|
32253
32952
|
};
|
|
32254
32953
|
|
|
32255
|
-
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
32256
|
-
var EXIT_VERBS = [
|
|
32257
|
-
["ci", "wait"],
|
|
32258
|
-
["check"],
|
|
32259
|
-
["pr", "merge"],
|
|
32260
|
-
["release"],
|
|
32261
|
-
["verify-delivery"]
|
|
32262
|
-
];
|
|
32263
|
-
var base2 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
32264
|
-
var quote3 = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
32265
|
-
var verbPath = (words) => {
|
|
32266
|
-
const path = [];
|
|
32267
|
-
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
32268
|
-
const word = words[at];
|
|
32269
|
-
if (word === "--")
|
|
32270
|
-
break;
|
|
32271
|
-
if (word === "--cwd")
|
|
32272
|
-
at += 1;
|
|
32273
|
-
else if (!word.startsWith("-"))
|
|
32274
|
-
path.push(word);
|
|
32275
|
-
}
|
|
32276
|
-
return path;
|
|
32277
|
-
};
|
|
32278
|
-
var exitCall = (words) => {
|
|
32279
|
-
let at = 0;
|
|
32280
|
-
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
32281
|
-
at += 1;
|
|
32282
|
-
if (!/^workit(?:-cli)?$/u.test(base2(words[at])))
|
|
32283
|
-
return null;
|
|
32284
|
-
const path = verbPath(words.slice(at + 1));
|
|
32285
|
-
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? words.slice(at) : null;
|
|
32286
|
-
};
|
|
32287
|
-
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
32288
|
-
var retryOf = ({ call, dir }) => {
|
|
32289
|
-
const at = call[1]?.startsWith("-") ? 1 : 2;
|
|
32290
|
-
const words = dir && !call.includes("--cwd") ? [...call.slice(0, at), "--cwd", dir, ...call.slice(at)] : call;
|
|
32291
|
-
return ["workit", ...words.slice(1)].map(quote3).join(" ");
|
|
32292
|
-
};
|
|
32293
|
-
function exitPipeGate(command, dialect = "posix") {
|
|
32294
|
-
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
32295
|
-
return null;
|
|
32296
|
-
const groups = [];
|
|
32297
|
-
let carry = null;
|
|
32298
|
-
let pipefail = false;
|
|
32299
|
-
let dir = null;
|
|
32300
|
-
for (const segment of segmentsOf(command, dialect)) {
|
|
32301
|
-
if (segment.unanalyzable)
|
|
32302
|
-
return null;
|
|
32303
|
-
let words = segment.words;
|
|
32304
|
-
let closes = segment.group === "close";
|
|
32305
|
-
if (segment.group === "open") {
|
|
32306
|
-
groups.push(null);
|
|
32307
|
-
continue;
|
|
32308
|
-
}
|
|
32309
|
-
if (words[0] === "{") {
|
|
32310
|
-
groups.push(null);
|
|
32311
|
-
words = words.slice(1);
|
|
32312
|
-
} else if (words[0] === "}") {
|
|
32313
|
-
closes = true;
|
|
32314
|
-
words = words.slice(1);
|
|
32315
|
-
}
|
|
32316
|
-
if (closes) {
|
|
32317
|
-
const inner = groups.pop() ?? null;
|
|
32318
|
-
if (inner && groups.length)
|
|
32319
|
-
groups[groups.length - 1] = inner;
|
|
32320
|
-
carry = segment.pipe ? inner ?? carry : null;
|
|
32321
|
-
continue;
|
|
32322
|
-
}
|
|
32323
|
-
if (!words.length && !segment.stdin && !segment.subs)
|
|
32324
|
-
continue;
|
|
32325
|
-
if (setsPipefail(words))
|
|
32326
|
-
pipefail = true;
|
|
32327
|
-
const filter = base2(words[0]);
|
|
32328
|
-
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
32329
|
-
const retry = retryOf(carry);
|
|
32330
|
-
return {
|
|
32331
|
-
kind: "deny",
|
|
32332
|
-
reason: `workit exit-pipe: piping \`workit ${verbPath(carry.call.slice(1)).join(" ")}\` into ${filter} hides its exit code.
|
|
32333
|
-
Retry as: ${retry}`,
|
|
32334
|
-
unblock: retry
|
|
32335
|
-
};
|
|
32336
|
-
}
|
|
32337
|
-
const call = exitCall(words);
|
|
32338
|
-
const found = call ? { call, dir } : null;
|
|
32339
|
-
if (found && groups.length)
|
|
32340
|
-
groups[groups.length - 1] = found;
|
|
32341
|
-
carry = segment.pipe ? found ?? carry : null;
|
|
32342
|
-
dir = words.length === 2 && words[0] === "cd" && !segment.expands?.length ? words[1] : null;
|
|
32343
|
-
}
|
|
32344
|
-
return null;
|
|
32345
|
-
}
|
|
32346
|
-
|
|
32347
32954
|
// packages/workit-core/src/hooks/stamp-hint.ts
|
|
32348
32955
|
var STATE_NAME = "(?:WORKIT_(?:STATE_DIR|CONFIG)\\w*|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
32349
32956
|
var STATE_ENV = new RegExp(`${STATE_NAME}\\s*\\+?=|(?:unset|-u|--unset)[\\s=]+${STATE_NAME}|env:|EnvironmentVariable`, "iu");
|
|
@@ -32396,50 +33003,6 @@ var KEYWORDS3 = new Set([
|
|
|
32396
33003
|
]);
|
|
32397
33004
|
var READERS2 = new Set(("cat less more head tail ls dir stat file wc grep egrep fgrep rg ag diff cmp sha256sum md5sum " + "shasum du bat echo printf cp mv rm chmod touch mkdir realpath readlink dirname basename tee " + "oxfmt oxlint prettier eslint tsc gh jq sort uniq cut tr nl od xxd hexdump strings code vim " + "nano sed get-content gc type select-string get-childitem test-path").split(" "));
|
|
32398
33005
|
|
|
32399
|
-
// packages/workit-core/src/hooks/identity-env.ts
|
|
32400
|
-
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
32401
|
-
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
32402
|
-
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
32403
|
-
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
32404
|
-
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
32405
|
-
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
32406
|
-
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
32407
|
-
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
32408
|
-
var powershell = (names) => new RegExp([
|
|
32409
|
-
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
32410
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
32411
|
-
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
32412
|
-
].join("|"), "iu");
|
|
32413
|
-
var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
|
|
32414
|
-
var POWERSHELL = powershell(NAMES);
|
|
32415
|
-
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
32416
|
-
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
32417
|
-
var POWERSHELL_OPAQUE = new RegExp([
|
|
32418
|
-
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
32419
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
32420
|
-
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
32421
|
-
`\\b(?:iex|Invoke-Expression)\\b`
|
|
32422
|
-
].join("|"), "iu");
|
|
32423
|
-
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
32424
|
-
var CMD_IDENTITY = cmdSet(NAMES);
|
|
32425
|
-
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
32426
|
-
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
32427
|
-
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
32428
|
-
var OPAQUE = new Set([
|
|
32429
|
-
"watch",
|
|
32430
|
-
"strace",
|
|
32431
|
-
"chroot",
|
|
32432
|
-
"flock",
|
|
32433
|
-
"ssh",
|
|
32434
|
-
"su",
|
|
32435
|
-
"runuser",
|
|
32436
|
-
"script",
|
|
32437
|
-
"parallel"
|
|
32438
|
-
]);
|
|
32439
|
-
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
32440
|
-
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
32441
|
-
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
32442
|
-
|
|
32443
33006
|
// packages/workit-core/src/hooks/handle.ts
|
|
32444
33007
|
var offered = new Set;
|
|
32445
33008
|
var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
|
|
@@ -32457,11 +33020,11 @@ var PROCESS_START = performance.timeOrigin;
|
|
|
32457
33020
|
// packages/workit-core/src/hooks/run.ts
|
|
32458
33021
|
if (false) {}
|
|
32459
33022
|
// packages/workit-opencode/src/shared/init-apply.ts
|
|
32460
|
-
import
|
|
33023
|
+
import path56 from "node:path";
|
|
32461
33024
|
|
|
32462
33025
|
// packages/workit-core/src/core/gitignore.ts
|
|
32463
33026
|
import { existsSync as existsSync18, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32464
|
-
import
|
|
33027
|
+
import path51 from "node:path";
|
|
32465
33028
|
var GITIGNORE_ENTRIES = [
|
|
32466
33029
|
"# workit: SDD working state (never commit)",
|
|
32467
33030
|
"docs/*/sdd/",
|
|
@@ -32481,7 +33044,7 @@ var GITIGNORE_ENTRIES = [
|
|
|
32481
33044
|
var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
32482
33045
|
if (!confirmed)
|
|
32483
33046
|
return { ok: false, error: "confirmed: true required" };
|
|
32484
|
-
const file =
|
|
33047
|
+
const file = path51.join(workspaceRoot, ".gitignore");
|
|
32485
33048
|
const existing = existsSync18(file) ? readFileSync13(file, "utf8") : "";
|
|
32486
33049
|
const existingLines = new Set(existing.split(`
|
|
32487
33050
|
`).map((l) => l.trim()).filter(Boolean));
|
|
@@ -32509,7 +33072,7 @@ var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
|
32509
33072
|
|
|
32510
33073
|
// packages/workit-core/src/core/hygiene.ts
|
|
32511
33074
|
import { existsSync as existsSync20, readFileSync as readFileSync15, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
32512
|
-
import
|
|
33075
|
+
import path53 from "node:path";
|
|
32513
33076
|
|
|
32514
33077
|
// packages/workit-core/src/git/ops.ts
|
|
32515
33078
|
import { spawnSync as spawnSync25 } from "node:child_process";
|
|
@@ -32522,7 +33085,7 @@ import {
|
|
|
32522
33085
|
rmSync as rmSync3,
|
|
32523
33086
|
writeFileSync as writeFileSync7
|
|
32524
33087
|
} from "node:fs";
|
|
32525
|
-
import
|
|
33088
|
+
import path52 from "node:path";
|
|
32526
33089
|
var COMMIT_TIMEOUT_MS = 10 * 60000;
|
|
32527
33090
|
var git5 = (cwd, args, options = {}) => {
|
|
32528
33091
|
const result = spawnSync25("git", args, {
|
|
@@ -32555,18 +33118,18 @@ function operationInProgress(cwd) {
|
|
|
32555
33118
|
if (!run.ok)
|
|
32556
33119
|
return null;
|
|
32557
33120
|
const found = run.stdout.split(`
|
|
32558
|
-
`).map((line) =>
|
|
33121
|
+
`).map((line) => path52.resolve(cwd, line.trim()));
|
|
32559
33122
|
const conflicted = () => git5(cwd, ["ls-files", "-u"]).stdout.trim() !== "";
|
|
32560
33123
|
for (const [index, [, operation]] of markers.entries()) {
|
|
32561
33124
|
const marker = found[index];
|
|
32562
33125
|
if (!marker || !existsSync19(marker))
|
|
32563
33126
|
continue;
|
|
32564
|
-
if (index === 1 && existsSync19(
|
|
33127
|
+
if (index === 1 && existsSync19(path52.join(marker, "applying")))
|
|
32565
33128
|
return { operation: "am", commitAllowed: false, branch: null };
|
|
32566
|
-
if (index === 0 && existsSync19(
|
|
33129
|
+
if (index === 0 && existsSync19(path52.join(marker, "amend")) && !conflicted()) {
|
|
32567
33130
|
let headName = "";
|
|
32568
33131
|
try {
|
|
32569
|
-
headName = readFileSync14(
|
|
33132
|
+
headName = readFileSync14(path52.join(marker, "head-name"), "utf8").trim();
|
|
32570
33133
|
} catch {}
|
|
32571
33134
|
const branch = headName.startsWith("refs/heads/") ? headName.slice("refs/heads/".length) : null;
|
|
32572
33135
|
return { operation, commitAllowed: branch !== null, branch };
|
|
@@ -32621,23 +33184,23 @@ var BATCH_BYTES = 16 * 1024 * 1024;
|
|
|
32621
33184
|
|
|
32622
33185
|
// packages/workit-core/src/core/hygiene.ts
|
|
32623
33186
|
var repoRoot3 = assetRoot();
|
|
32624
|
-
var templatesDir = () =>
|
|
33187
|
+
var templatesDir = () => path53.join(repoRoot3, "templates", "hygiene");
|
|
32625
33188
|
var packageJson2 = (root) => {
|
|
32626
|
-
if (!existsSync20(
|
|
33189
|
+
if (!existsSync20(path53.join(root, "package.json")))
|
|
32627
33190
|
return null;
|
|
32628
33191
|
try {
|
|
32629
|
-
return JSON.parse(readFileSync15(
|
|
33192
|
+
return JSON.parse(readFileSync15(path53.join(root, "package.json"), "utf8"));
|
|
32630
33193
|
} catch {
|
|
32631
33194
|
return null;
|
|
32632
33195
|
}
|
|
32633
33196
|
};
|
|
32634
33197
|
var isOpenSource = (root) => {
|
|
32635
|
-
if (existsSync20(
|
|
33198
|
+
if (existsSync20(path53.join(root, "LICENSE")))
|
|
32636
33199
|
return true;
|
|
32637
33200
|
const pkg = packageJson2(root);
|
|
32638
33201
|
if (pkg && !pkg.private)
|
|
32639
33202
|
return true;
|
|
32640
|
-
return
|
|
33203
|
+
return path53.basename(root) === "workit";
|
|
32641
33204
|
};
|
|
32642
33205
|
var licenseHolder = (root) => {
|
|
32643
33206
|
const pkg = packageJson2(root);
|
|
@@ -32660,13 +33223,13 @@ var planHygieneFiles = (root, opts = {}) => {
|
|
|
32660
33223
|
files.push("LICENSE", "CONTRIBUTING.md");
|
|
32661
33224
|
const planned = [];
|
|
32662
33225
|
for (const file of files) {
|
|
32663
|
-
if (existsSync20(
|
|
33226
|
+
if (existsSync20(path53.join(root, file)))
|
|
32664
33227
|
continue;
|
|
32665
|
-
const tpl =
|
|
33228
|
+
const tpl = path53.join(templatesDir(), file);
|
|
32666
33229
|
if (!existsSync20(tpl))
|
|
32667
33230
|
continue;
|
|
32668
|
-
const content = readFileSync15(tpl, "utf8").replace(/<PROJECT>/g,
|
|
32669
|
-
planned.push({ path:
|
|
33231
|
+
const content = readFileSync15(tpl, "utf8").replace(/<PROJECT>/g, path53.basename(root)).replace(/<YEAR>/g, String(new Date().getFullYear())).replace(/<HOLDER>\s*/g, licenseHolder(root));
|
|
33232
|
+
planned.push({ path: path53.join(root, file), content });
|
|
32670
33233
|
}
|
|
32671
33234
|
return planned;
|
|
32672
33235
|
};
|
|
@@ -32676,19 +33239,19 @@ var ensureHygieneFiles = (root, opts) => {
|
|
|
32676
33239
|
const created = [];
|
|
32677
33240
|
for (const planned of planHygieneFiles(root, opts)) {
|
|
32678
33241
|
writeFileSync8(planned.path, planned.content, "utf8");
|
|
32679
|
-
created.push(
|
|
33242
|
+
created.push(path53.basename(planned.path));
|
|
32680
33243
|
}
|
|
32681
33244
|
return { ok: true, created };
|
|
32682
33245
|
};
|
|
32683
33246
|
|
|
32684
33247
|
// packages/workit-core/src/core/init.ts
|
|
32685
|
-
import
|
|
32686
|
-
import
|
|
33248
|
+
import fs34 from "node:fs";
|
|
33249
|
+
import path55 from "node:path";
|
|
32687
33250
|
import { spawnSync as spawnSync26 } from "node:child_process";
|
|
32688
33251
|
|
|
32689
33252
|
// packages/workit-core/src/core/workspace-branch-policy.ts
|
|
32690
33253
|
import { mkdirSync as mkdirSync7, readFileSync as readFileSync16, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync9 } from "node:fs";
|
|
32691
|
-
import
|
|
33254
|
+
import path54 from "node:path";
|
|
32692
33255
|
import { isDeepStrictEqual } from "node:util";
|
|
32693
33256
|
var readFileSafe = (p) => {
|
|
32694
33257
|
try {
|
|
@@ -32699,7 +33262,7 @@ var readFileSafe = (p) => {
|
|
|
32699
33262
|
};
|
|
32700
33263
|
function applyWorkspaceBranchPolicy(opts) {
|
|
32701
33264
|
const { workspace_root, env = process.env } = opts;
|
|
32702
|
-
const dir =
|
|
33265
|
+
const dir = path54.join(env.WORKIT_CONFIG ?? configDir2());
|
|
32703
33266
|
const {
|
|
32704
33267
|
status,
|
|
32705
33268
|
path: wsPath,
|
|
@@ -32711,7 +33274,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32711
33274
|
if (status === "malformed" || status === "invalid")
|
|
32712
33275
|
return { ok: false, error: workspacesError ?? `invalid workspaces.json: ${wsPath}` };
|
|
32713
33276
|
const detection = detectBranchPolicy(workspace_root);
|
|
32714
|
-
const name = String(env.WORKIT_BP_NAME ??
|
|
33277
|
+
const name = String(env.WORKIT_BP_NAME ?? path54.basename(workspace_root));
|
|
32715
33278
|
const integration = env.WORKIT_BP_INTEGRATION ?? detection.integration;
|
|
32716
33279
|
const policy = {
|
|
32717
33280
|
preset: detection.preset,
|
|
@@ -32760,7 +33323,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32760
33323
|
ok: false,
|
|
32761
33324
|
error: `workspaces.json changed while applying the branch policy: ${wsPath}`
|
|
32762
33325
|
};
|
|
32763
|
-
mkdirSync7(
|
|
33326
|
+
mkdirSync7(path54.dirname(wsPath), { recursive: true });
|
|
32764
33327
|
const tmp = `${wsPath}.${process.pid}.tmp`;
|
|
32765
33328
|
try {
|
|
32766
33329
|
writeFileSync9(tmp, JSON.stringify({ ...document, workspaces: next }, null, 2) + `
|
|
@@ -32794,7 +33357,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32794
33357
|
// packages/workit-core/src/core/init.ts
|
|
32795
33358
|
var readJson3 = (p) => {
|
|
32796
33359
|
try {
|
|
32797
|
-
const parsed = JSON.parse(
|
|
33360
|
+
const parsed = JSON.parse(fs34.readFileSync(p, "utf8"));
|
|
32798
33361
|
return isConfigObject(parsed) ? parsed : null;
|
|
32799
33362
|
} catch {
|
|
32800
33363
|
return null;
|
|
@@ -32857,11 +33420,11 @@ var vcsJsonContent = () => {
|
|
|
32857
33420
|
};
|
|
32858
33421
|
function initApplyData(action, env = process.env) {
|
|
32859
33422
|
const dir = String(env.WORKIT_CONFIG ?? configDir2());
|
|
32860
|
-
|
|
33423
|
+
fs34.mkdirSync(dir, { recursive: true });
|
|
32861
33424
|
switch (action) {
|
|
32862
33425
|
case "youtrack_json": {
|
|
32863
|
-
const out =
|
|
32864
|
-
|
|
33426
|
+
const out = path55.join(dir, "youtrack.json");
|
|
33427
|
+
fs34.writeFileSync(out, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
32865
33428
|
`, "utf8");
|
|
32866
33429
|
return { action, ok: true, path: out };
|
|
32867
33430
|
}
|
|
@@ -32874,10 +33437,10 @@ function initApplyData(action, env = process.env) {
|
|
|
32874
33437
|
};
|
|
32875
33438
|
}
|
|
32876
33439
|
case "youtrack_scaffold": {
|
|
32877
|
-
const jsonOut =
|
|
32878
|
-
|
|
33440
|
+
const jsonOut = path55.join(dir, "youtrack.json");
|
|
33441
|
+
fs34.writeFileSync(jsonOut, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
32879
33442
|
`, "utf8");
|
|
32880
|
-
const configPath =
|
|
33443
|
+
const configPath = path55.resolve(jsonOut);
|
|
32881
33444
|
const cfg = readJson3(configPath) ?? {};
|
|
32882
33445
|
const base = String(cfg.baseUrl ?? "").replace(/\/+$/, "");
|
|
32883
33446
|
const meeting = String(cfg.meetingIssue ?? "");
|
|
@@ -32913,10 +33476,10 @@ function initApplyData(action, env = process.env) {
|
|
|
32913
33476
|
};
|
|
32914
33477
|
}
|
|
32915
33478
|
case "vcs_scaffold": {
|
|
32916
|
-
const jsonOut =
|
|
32917
|
-
|
|
33479
|
+
const jsonOut = path55.join(dir, "vcs.json");
|
|
33480
|
+
fs34.writeFileSync(jsonOut, JSON.stringify(vcsJsonContent(), null, 2) + `
|
|
32918
33481
|
`, "utf8");
|
|
32919
|
-
const configPath =
|
|
33482
|
+
const configPath = path55.resolve(jsonOut);
|
|
32920
33483
|
const prev = process.env.WORKIT_VCS_CONFIG;
|
|
32921
33484
|
process.env.WORKIT_VCS_CONFIG = configPath;
|
|
32922
33485
|
try {
|
|
@@ -33035,7 +33598,7 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
33035
33598
|
protectedNames: args.branch_policy_protected
|
|
33036
33599
|
}, current);
|
|
33037
33600
|
writeConfig(next);
|
|
33038
|
-
return output(ok({ action: "config", path:
|
|
33601
|
+
return output(ok({ action: "config", path: path56.join(configDir2(), "config.json"), ...next }));
|
|
33039
33602
|
}
|
|
33040
33603
|
const env = Object.fromEntries(Object.entries({
|
|
33041
33604
|
WORKIT_YT_BASE_URL: args.base_url,
|
|
@@ -33052,14 +33615,14 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
33052
33615
|
|
|
33053
33616
|
// packages/workit-opencode/src/shared/session.ts
|
|
33054
33617
|
import { realpathSync as realpathSync12 } from "node:fs";
|
|
33055
|
-
import
|
|
33618
|
+
import path57 from "node:path";
|
|
33056
33619
|
var sameWorkspace = (expected, observed) => {
|
|
33057
33620
|
if (typeof observed !== "string" || !observed)
|
|
33058
33621
|
return false;
|
|
33059
33622
|
try {
|
|
33060
33623
|
return realpathSync12(expected) === realpathSync12(observed);
|
|
33061
33624
|
} catch {
|
|
33062
|
-
return
|
|
33625
|
+
return path57.resolve(expected) === path57.resolve(observed);
|
|
33063
33626
|
}
|
|
33064
33627
|
};
|
|
33065
33628
|
|
|
@@ -33131,7 +33694,7 @@ var workitFamilyOf = (toolName) => {
|
|
|
33131
33694
|
|
|
33132
33695
|
// packages/workit-opencode/src/tools/context.ts
|
|
33133
33696
|
import { realpathSync as realpathSync13 } from "node:fs";
|
|
33134
|
-
import
|
|
33697
|
+
import path58 from "node:path";
|
|
33135
33698
|
var createContextTool = () => ({
|
|
33136
33699
|
description: "Read Git, pull request, YouTrack, issue, changelog, release, or affected-file context.",
|
|
33137
33700
|
execute: async (args, context) => {
|
|
@@ -33141,7 +33704,7 @@ var createContextTool = () => ({
|
|
|
33141
33704
|
let root;
|
|
33142
33705
|
try {
|
|
33143
33706
|
const cwd = parsed.data.cwd;
|
|
33144
|
-
root = realpathSync13(cwd ?
|
|
33707
|
+
root = realpathSync13(cwd ? path58.resolve(context.directory, cwd) : context.directory);
|
|
33145
33708
|
} catch {
|
|
33146
33709
|
return JSON.stringify(failure2("invalid_input", "context target directory cannot be resolved"), null, 2);
|
|
33147
33710
|
}
|
|
@@ -33173,8 +33736,8 @@ var workerCoordinatorFor = (task, worker) => {
|
|
|
33173
33736
|
// packages/workit-core/src/fanout.ts
|
|
33174
33737
|
import { spawnSync as spawnSync29 } from "node:child_process";
|
|
33175
33738
|
import { createHash as createHash21 } from "node:crypto";
|
|
33176
|
-
import
|
|
33177
|
-
import
|
|
33739
|
+
import fs36 from "node:fs";
|
|
33740
|
+
import path60 from "node:path";
|
|
33178
33741
|
|
|
33179
33742
|
// packages/workit-core/src/fanout-landed.ts
|
|
33180
33743
|
import { spawnSync as spawnSync27 } from "node:child_process";
|
|
@@ -33407,8 +33970,8 @@ var NOTICE_TTL_MS = 7 * 86400000;
|
|
|
33407
33970
|
// packages/workit-core/src/stack.ts
|
|
33408
33971
|
import { spawnSync as spawnSync28 } from "node:child_process";
|
|
33409
33972
|
import { createHash as createHash20, randomBytes as randomBytes4 } from "node:crypto";
|
|
33410
|
-
import
|
|
33411
|
-
import
|
|
33973
|
+
import fs35 from "node:fs";
|
|
33974
|
+
import path59 from "node:path";
|
|
33412
33975
|
|
|
33413
33976
|
// packages/workit-core/src/forge/report.ts
|
|
33414
33977
|
var GITLAB_MERGEABLE = new Set(["mergeable"]);
|
|
@@ -33475,7 +34038,7 @@ function rebasingBranch2(dir) {
|
|
|
33475
34038
|
if (!found.ok)
|
|
33476
34039
|
continue;
|
|
33477
34040
|
try {
|
|
33478
|
-
return
|
|
34041
|
+
return fs35.readFileSync(found.stdout.trim(), "utf8").trim();
|
|
33479
34042
|
} catch {}
|
|
33480
34043
|
}
|
|
33481
34044
|
return null;
|
|
@@ -33483,14 +34046,14 @@ function rebasingBranch2(dir) {
|
|
|
33483
34046
|
function rebaseInProgress(dir) {
|
|
33484
34047
|
for (const name of ["rebase-merge", "rebase-apply"]) {
|
|
33485
34048
|
const found = gitRun4(dir, ["rev-parse", "--path-format=absolute", "--git-path", name]);
|
|
33486
|
-
if (found.ok &&
|
|
34049
|
+
if (found.ok && fs35.existsSync(found.stdout.trim()))
|
|
33487
34050
|
return true;
|
|
33488
34051
|
}
|
|
33489
34052
|
return false;
|
|
33490
34053
|
}
|
|
33491
34054
|
var scratchDir = (cwd) => {
|
|
33492
34055
|
const dir = stacksDir(cwd);
|
|
33493
|
-
return dir.ok ?
|
|
34056
|
+
return dir.ok ? path59.join(dir.data, "worktrees") : null;
|
|
33494
34057
|
};
|
|
33495
34058
|
function gitRestack(cwd, input) {
|
|
33496
34059
|
const owner = worktreeOf(cwd, input.branch);
|
|
@@ -33504,8 +34067,8 @@ function gitRestack(cwd, input) {
|
|
|
33504
34067
|
worktree: cwd,
|
|
33505
34068
|
error: "no store root"
|
|
33506
34069
|
};
|
|
33507
|
-
|
|
33508
|
-
dir =
|
|
34070
|
+
fs35.mkdirSync(scratch, { recursive: true });
|
|
34071
|
+
dir = path59.join(scratch, `${input.branch.replace(/[^A-Za-z0-9._-]+/gu, "_").slice(0, 40)}-${randomBytes4(4).toString("hex")}`);
|
|
33509
34072
|
const added = gitRun4(cwd, ["worktree", "add", "-q", dir, input.branch], GIT_TIMEOUTS.worktree);
|
|
33510
34073
|
if (!added.ok)
|
|
33511
34074
|
return {
|
|
@@ -33564,7 +34127,7 @@ function stacksDir(cwd) {
|
|
|
33564
34127
|
const root = storeRoot(cwd);
|
|
33565
34128
|
if (!root.ok)
|
|
33566
34129
|
return stackFail(root.code, root.error, root.unblock);
|
|
33567
|
-
return { ok: true, data:
|
|
34130
|
+
return { ok: true, data: path59.join(root.value.root, "stacks") };
|
|
33568
34131
|
}
|
|
33569
34132
|
var HEARTBEAT_STALE_MS = 2 * 60000;
|
|
33570
34133
|
var SETTLED_BY_RESTACK = new Set(["checks_pending", "behind_base_required"]);
|
|
@@ -33711,7 +34274,7 @@ function fanoutsDir(cwd) {
|
|
|
33711
34274
|
const root = storeRoot(cwd);
|
|
33712
34275
|
if (!root.ok)
|
|
33713
34276
|
return fanoutFail(root.code, root.error, root.unblock);
|
|
33714
|
-
return { ok: true, data:
|
|
34277
|
+
return { ok: true, data: path60.join(root.value.root, "fanouts") };
|
|
33715
34278
|
}
|
|
33716
34279
|
function parseStored(raw) {
|
|
33717
34280
|
if (!isRecord9(raw) || typeof raw.name !== "string" || typeof raw.trunk !== "string")
|
|
@@ -33779,10 +34342,10 @@ function readFanout(cwd, name) {
|
|
|
33779
34342
|
const dir = fanoutsDir(cwd);
|
|
33780
34343
|
if (!dir.ok)
|
|
33781
34344
|
return dir;
|
|
33782
|
-
const file =
|
|
34345
|
+
const file = path60.join(dir.data, stackFileName(name));
|
|
33783
34346
|
let parsed = null;
|
|
33784
34347
|
try {
|
|
33785
|
-
parsed = parseStored(JSON.parse(
|
|
34348
|
+
parsed = parseStored(JSON.parse(fs36.readFileSync(file, "utf8")));
|
|
33786
34349
|
} catch (error) {
|
|
33787
34350
|
if (error.code === "ENOENT")
|
|
33788
34351
|
return { ok: true, data: null };
|
|
@@ -33796,7 +34359,7 @@ function listFanouts(cwd) {
|
|
|
33796
34359
|
return dir;
|
|
33797
34360
|
let names = [];
|
|
33798
34361
|
try {
|
|
33799
|
-
names =
|
|
34362
|
+
names = fs36.readdirSync(dir.data).filter((entry) => entry.endsWith(".json"));
|
|
33800
34363
|
} catch {
|
|
33801
34364
|
return { ok: true, data: [] };
|
|
33802
34365
|
}
|
|
@@ -33804,7 +34367,7 @@ function listFanouts(cwd) {
|
|
|
33804
34367
|
for (const entry of names) {
|
|
33805
34368
|
let parsed = null;
|
|
33806
34369
|
try {
|
|
33807
|
-
parsed = parseStored(JSON.parse(
|
|
34370
|
+
parsed = parseStored(JSON.parse(fs36.readFileSync(path60.join(dir.data, entry), "utf8")));
|
|
33808
34371
|
} catch {
|
|
33809
34372
|
parsed = null;
|
|
33810
34373
|
}
|
|
@@ -34697,7 +35260,7 @@ var childTaskMissing = (store, input) => {
|
|
|
34697
35260
|
var childDenial = (identity) => `OpenCode child session has no validated Workit worker: as ${identity} it may only inspect the task summary (workit_task action "inspect") or record evidence or findings (workit_evidence/workit_finding action "record") on an existing task; for anything else the lead assigns it a worker with workit_worker before launching it`;
|
|
34698
35261
|
|
|
34699
35262
|
// packages/workit-opencode/src/v2/shell.ts
|
|
34700
|
-
import
|
|
35263
|
+
import path61 from "node:path";
|
|
34701
35264
|
|
|
34702
35265
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
34703
35266
|
import { createHash as createHash22 } from "node:crypto";
|
|
@@ -34760,7 +35323,7 @@ var commandOf = (input) => {
|
|
|
34760
35323
|
};
|
|
34761
35324
|
var hookInput = (root, sessionID, id, shell) => ({
|
|
34762
35325
|
host: "opencode",
|
|
34763
|
-
cwd: shell.workdir ?
|
|
35326
|
+
cwd: shell.workdir ? path61.resolve(root, shell.workdir) : root,
|
|
34764
35327
|
session: { id: sessionID, agentId: null, agentType: null, parentId: null },
|
|
34765
35328
|
permissionMode: null,
|
|
34766
35329
|
transcriptPath: null,
|
|
@@ -35284,37 +35847,37 @@ var createStopControl = (root, port) => {
|
|
|
35284
35847
|
|
|
35285
35848
|
// packages/workit-opencode/src/v2/registry.ts
|
|
35286
35849
|
import { existsSync as existsSync22, readFileSync as readFileSync17 } from "node:fs";
|
|
35287
|
-
import
|
|
35850
|
+
import path63 from "node:path";
|
|
35288
35851
|
|
|
35289
35852
|
// packages/workit-opencode/src/shared/assets.ts
|
|
35290
35853
|
import { existsSync as existsSync21, realpathSync as realpathSync14 } from "node:fs";
|
|
35291
|
-
import
|
|
35854
|
+
import path62 from "node:path";
|
|
35292
35855
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
35293
35856
|
var moduleDir = () => {
|
|
35294
35857
|
try {
|
|
35295
|
-
return realpathSync14(
|
|
35858
|
+
return realpathSync14(path62.dirname(fileURLToPath2(import.meta.url)));
|
|
35296
35859
|
} catch {
|
|
35297
|
-
return
|
|
35860
|
+
return path62.dirname(fileURLToPath2(import.meta.url));
|
|
35298
35861
|
}
|
|
35299
35862
|
};
|
|
35300
35863
|
var packageRoot2 = () => {
|
|
35301
35864
|
const dir = moduleDir();
|
|
35302
35865
|
for (const candidate of [
|
|
35303
|
-
|
|
35304
|
-
|
|
35305
|
-
|
|
35866
|
+
path62.resolve(dir, ".."),
|
|
35867
|
+
path62.resolve(dir, "..", ".."),
|
|
35868
|
+
path62.resolve(dir, "..", "..", "..")
|
|
35306
35869
|
]) {
|
|
35307
|
-
if (existsSync21(
|
|
35870
|
+
if (existsSync21(path62.join(candidate, "package.json")))
|
|
35308
35871
|
return candidate;
|
|
35309
35872
|
}
|
|
35310
|
-
return
|
|
35873
|
+
return path62.resolve(dir, "..");
|
|
35311
35874
|
};
|
|
35312
35875
|
var skillsRoot = () => {
|
|
35313
35876
|
const root = packageRoot2();
|
|
35314
|
-
const canonical =
|
|
35315
|
-
if (existsSync21(
|
|
35877
|
+
const canonical = path62.resolve(root, "..", "workit-core", "skills");
|
|
35878
|
+
if (existsSync21(path62.join(root, "src")) && existsSync21(canonical))
|
|
35316
35879
|
return canonical;
|
|
35317
|
-
return
|
|
35880
|
+
return path62.join(root, "assets", "skills");
|
|
35318
35881
|
};
|
|
35319
35882
|
|
|
35320
35883
|
// packages/workit-opencode/src/v2/registry.ts
|
|
@@ -35341,11 +35904,11 @@ var registerSkills = async (ctx) => {
|
|
|
35341
35904
|
if (!existsSync22(skillsDir))
|
|
35342
35905
|
return new Set;
|
|
35343
35906
|
const listed = await ctx.skill.list().catch(() => ({ data: [] }));
|
|
35344
|
-
const own = (skill) => typeof skill.path === "string" &&
|
|
35907
|
+
const own = (skill) => typeof skill.path === "string" && path63.resolve(skill.path).startsWith(skillsDir + path63.sep);
|
|
35345
35908
|
const userSkills = new Set((listed?.data ?? []).filter((skill) => !own(skill)).map((skill) => skill.id));
|
|
35346
35909
|
const packaged = new Map;
|
|
35347
35910
|
for (const id of WORKIT_METHOD_SKILLS) {
|
|
35348
|
-
const file =
|
|
35911
|
+
const file = path63.join(skillsDir, id, "SKILL.md");
|
|
35349
35912
|
if (!userSkills.has(id) && existsSync22(file))
|
|
35350
35913
|
packaged.set(id, file);
|
|
35351
35914
|
}
|
|
@@ -35393,22 +35956,22 @@ var registerCommands = async (ctx, registeredSkills) => {
|
|
|
35393
35956
|
|
|
35394
35957
|
// packages/workit-opencode/src/stale-sources.ts
|
|
35395
35958
|
import { existsSync as existsSync23, readdirSync as readdirSync9 } from "node:fs";
|
|
35396
|
-
import
|
|
35959
|
+
import path64 from "node:path";
|
|
35397
35960
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
35398
35961
|
var typescriptFiles = (directory) => {
|
|
35399
35962
|
if (!existsSync23(directory))
|
|
35400
35963
|
return [];
|
|
35401
35964
|
return readdirSync9(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
35402
|
-
const file =
|
|
35965
|
+
const file = path64.join(directory, entry.name);
|
|
35403
35966
|
return entry.isDirectory() ? typescriptFiles(file) : entry.isFile() && file.endsWith(".ts") ? [file] : [];
|
|
35404
35967
|
});
|
|
35405
35968
|
};
|
|
35406
35969
|
var pluginSourceFiles = [
|
|
35407
35970
|
...new Set([
|
|
35408
35971
|
fileURLToPath3(import.meta.url),
|
|
35409
|
-
...typescriptFiles(
|
|
35410
|
-
|
|
35411
|
-
...typescriptFiles(
|
|
35972
|
+
...typescriptFiles(path64.join(packageRoot2(), "src")),
|
|
35973
|
+
path64.join(packageRoot2(), "..", "workit-core", "src", "core.ts"),
|
|
35974
|
+
...typescriptFiles(path64.join(packageRoot2(), "..", "workit-core", "src", "core"))
|
|
35412
35975
|
])
|
|
35413
35976
|
].filter((file) => existsSync23(file)).toSorted();
|
|
35414
35977
|
|