@brainervirus/workit-codex 8.12.0 → 8.12.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.
|
@@ -26,7 +26,7 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
|
|
|
26
26
|
// packages/workit-core/src/hooks/context.ts
|
|
27
27
|
import { createHash as createHash11 } from "node:crypto";
|
|
28
28
|
import fs14 from "node:fs";
|
|
29
|
-
import
|
|
29
|
+
import path18 from "node:path";
|
|
30
30
|
|
|
31
31
|
// packages/workit-core/src/core/methods.ts
|
|
32
32
|
var METHODS = {
|
|
@@ -8793,7 +8793,7 @@ function requirementId(input) {
|
|
|
8793
8793
|
import { createHash as createHash10 } from "node:crypto";
|
|
8794
8794
|
import * as fs13 from "node:fs";
|
|
8795
8795
|
import { spawnSync as spawnSync10 } from "node:child_process";
|
|
8796
|
-
import
|
|
8796
|
+
import path16 from "node:path";
|
|
8797
8797
|
|
|
8798
8798
|
// packages/workit-core/src/check-config.ts
|
|
8799
8799
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
@@ -9184,7 +9184,7 @@ function pushRemoteName(cwd, branch) {
|
|
|
9184
9184
|
// packages/workit-core/src/core/task-store.ts
|
|
9185
9185
|
import { createHash as createHash6, randomUUID as randomUUID3 } from "node:crypto";
|
|
9186
9186
|
import * as fs10 from "node:fs";
|
|
9187
|
-
import
|
|
9187
|
+
import path10 from "node:path";
|
|
9188
9188
|
|
|
9189
9189
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
9190
9190
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -9790,7 +9790,68 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
9790
9790
|
// packages/workit-core/src/host-session.ts
|
|
9791
9791
|
import { createHash as createHash4 } from "node:crypto";
|
|
9792
9792
|
import fs7 from "node:fs";
|
|
9793
|
+
import path7 from "node:path";
|
|
9794
|
+
|
|
9795
|
+
// packages/workit-core/src/core/logger.ts
|
|
9796
|
+
import os2 from "node:os";
|
|
9793
9797
|
import path6 from "node:path";
|
|
9798
|
+
var SENSITIVE_WORDS = new Set([
|
|
9799
|
+
"token",
|
|
9800
|
+
"secret",
|
|
9801
|
+
"password",
|
|
9802
|
+
"passwd",
|
|
9803
|
+
"authorization",
|
|
9804
|
+
"credential",
|
|
9805
|
+
"credentials",
|
|
9806
|
+
"cookie",
|
|
9807
|
+
"api",
|
|
9808
|
+
"apikey",
|
|
9809
|
+
"apitoken",
|
|
9810
|
+
"accesstoken",
|
|
9811
|
+
"clientsecret",
|
|
9812
|
+
"refreshtoken",
|
|
9813
|
+
"key",
|
|
9814
|
+
"bearer",
|
|
9815
|
+
"prompt",
|
|
9816
|
+
"message",
|
|
9817
|
+
"messages",
|
|
9818
|
+
"content",
|
|
9819
|
+
"body",
|
|
9820
|
+
"args",
|
|
9821
|
+
"argument",
|
|
9822
|
+
"result",
|
|
9823
|
+
"results",
|
|
9824
|
+
"output",
|
|
9825
|
+
"issue",
|
|
9826
|
+
"description",
|
|
9827
|
+
"summary",
|
|
9828
|
+
"payload",
|
|
9829
|
+
"script",
|
|
9830
|
+
"command",
|
|
9831
|
+
"text",
|
|
9832
|
+
"query"
|
|
9833
|
+
]);
|
|
9834
|
+
var STACK_WORDS = new Set(["stack", "stacktrace", "trace"]);
|
|
9835
|
+
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9836
|
+
var resolveStateDir = () => {
|
|
9837
|
+
const override = process.env.WORKFLOW_TOOLKIT_STATE;
|
|
9838
|
+
if (override)
|
|
9839
|
+
return override;
|
|
9840
|
+
const home = os2.homedir();
|
|
9841
|
+
if (process.env.XDG_STATE_HOME)
|
|
9842
|
+
return path6.join(process.env.XDG_STATE_HOME, "workit");
|
|
9843
|
+
switch (os2.platform()) {
|
|
9844
|
+
case "darwin":
|
|
9845
|
+
return path6.join(home, "Library", "Application Support", "workit");
|
|
9846
|
+
case "win32":
|
|
9847
|
+
return path6.join(process.env.LOCALAPPDATA ?? path6.join(home, "AppData", "Local"), "workit");
|
|
9848
|
+
default:
|
|
9849
|
+
return path6.join(process.env.HOME ?? home, ".local", "state", "workit");
|
|
9850
|
+
}
|
|
9851
|
+
};
|
|
9852
|
+
var homePattern = new RegExp(`${escapeRegExp(os2.homedir())}(?=[/\\\\]|$)|\\$HOME(?=[/\\\\]|$)`, "g");
|
|
9853
|
+
|
|
9854
|
+
// packages/workit-core/src/host-session.ts
|
|
9794
9855
|
var HOST_SESSION_VARS = [
|
|
9795
9856
|
["OPENCODE_SESSION_ID", () => "opencode"],
|
|
9796
9857
|
["PI_SESSION_ID", () => "pi"],
|
|
@@ -9819,43 +9880,77 @@ function hostSessionFromEnv(env) {
|
|
|
9819
9880
|
return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
|
|
9820
9881
|
}
|
|
9821
9882
|
var ISSUED_PER_LEAD = 64;
|
|
9822
|
-
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/
|
|
9883
|
+
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/2";
|
|
9823
9884
|
var hash = (value) => createHash4("sha256").update(value).digest("hex").slice(0, 32);
|
|
9824
|
-
var
|
|
9825
|
-
|
|
9826
|
-
|
|
9885
|
+
var userIssuedRoot = () => path7.join(resolveStateDir(), "issued");
|
|
9886
|
+
function migrateRepoIssued(cwd) {
|
|
9887
|
+
if (cwd === undefined)
|
|
9888
|
+
return;
|
|
9889
|
+
let old;
|
|
9890
|
+
try {
|
|
9891
|
+
const location = resolveStore(cwd);
|
|
9892
|
+
if (location instanceof Error)
|
|
9893
|
+
return;
|
|
9894
|
+
old = path7.join(location.dir, "hooks", "issued");
|
|
9895
|
+
if (!fs7.existsSync(old))
|
|
9896
|
+
return;
|
|
9897
|
+
} catch {
|
|
9898
|
+
return;
|
|
9899
|
+
}
|
|
9900
|
+
for (const lead of safeList(old)) {
|
|
9901
|
+
try {
|
|
9902
|
+
const from = path7.join(old, lead);
|
|
9903
|
+
if (!fs7.statSync(from).isDirectory())
|
|
9904
|
+
continue;
|
|
9905
|
+
const to = path7.join(userIssuedRoot(), lead);
|
|
9906
|
+
fs7.mkdirSync(to, { recursive: true, mode: 448 });
|
|
9907
|
+
for (const id of fs7.readdirSync(from)) {
|
|
9908
|
+
fs7.copyFileSync(path7.join(from, id), path7.join(to, id));
|
|
9909
|
+
fs7.rmSync(path7.join(from, id), { force: true });
|
|
9910
|
+
}
|
|
9911
|
+
removeIfEmpty(from);
|
|
9912
|
+
} catch {}
|
|
9913
|
+
}
|
|
9914
|
+
removeIfEmpty(old);
|
|
9915
|
+
}
|
|
9916
|
+
var safeList = (dir) => {
|
|
9917
|
+
try {
|
|
9918
|
+
return fs7.readdirSync(dir);
|
|
9919
|
+
} catch {
|
|
9920
|
+
return [];
|
|
9921
|
+
}
|
|
9827
9922
|
};
|
|
9828
|
-
var
|
|
9829
|
-
|
|
9830
|
-
|
|
9923
|
+
var removeIfEmpty = (dir) => {
|
|
9924
|
+
try {
|
|
9925
|
+
fs7.rmdirSync(dir);
|
|
9926
|
+
} catch {}
|
|
9831
9927
|
};
|
|
9832
9928
|
function recordIssuedSession(cwd, lead, issued) {
|
|
9833
9929
|
try {
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
fs7.mkdirSync(dir, { recursive: true });
|
|
9930
|
+
migrateRepoIssued(cwd);
|
|
9931
|
+
const dir = path7.join(userIssuedRoot(), hash(lead));
|
|
9932
|
+
fs7.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
9838
9933
|
const own = hash(issued);
|
|
9839
|
-
fs7.writeFileSync(
|
|
9934
|
+
fs7.writeFileSync(path7.join(dir, own), ISSUED_SESSIONS_MARKER);
|
|
9840
9935
|
const entries = fs7.readdirSync(dir);
|
|
9841
9936
|
if (entries.length <= ISSUED_PER_LEAD)
|
|
9842
9937
|
return;
|
|
9843
|
-
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs7.statSync(
|
|
9938
|
+
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs7.statSync(path7.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
|
|
9844
9939
|
for (const { name } of byAge.slice(0, entries.length - ISSUED_PER_LEAD))
|
|
9845
|
-
fs7.rmSync(
|
|
9940
|
+
fs7.rmSync(path7.join(dir, name), { force: true });
|
|
9846
9941
|
} catch {}
|
|
9847
9942
|
}
|
|
9848
9943
|
var OWN_CHILD_SHELL = new Set(["opencode", "pi"]);
|
|
9849
9944
|
|
|
9850
9945
|
// packages/workit-core/src/core/package-root.ts
|
|
9851
9946
|
import { existsSync } from "node:fs";
|
|
9852
|
-
import
|
|
9947
|
+
import path8 from "node:path";
|
|
9853
9948
|
import { fileURLToPath } from "node:url";
|
|
9854
9949
|
var packageRoot = () => {
|
|
9855
|
-
let dir =
|
|
9950
|
+
let dir = path8.dirname(fileURLToPath(import.meta.url));
|
|
9856
9951
|
while (true) {
|
|
9857
|
-
const parent =
|
|
9858
|
-
if (existsSync(
|
|
9952
|
+
const parent = path8.dirname(dir);
|
|
9953
|
+
if (existsSync(path8.join(dir, "package.json")) || parent === dir)
|
|
9859
9954
|
return dir;
|
|
9860
9955
|
dir = parent;
|
|
9861
9956
|
}
|
|
@@ -10004,7 +10099,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
|
|
|
10004
10099
|
// packages/workit-core/src/store/event-log.ts
|
|
10005
10100
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
10006
10101
|
import fs9 from "node:fs";
|
|
10007
|
-
import
|
|
10102
|
+
import path9 from "node:path";
|
|
10008
10103
|
var EVENT_VERSION = 1;
|
|
10009
10104
|
|
|
10010
10105
|
class LogDamage extends Error {
|
|
@@ -10115,7 +10210,7 @@ function appendEvent(file, event, validEnd) {
|
|
|
10115
10210
|
fs9.closeSync(fd);
|
|
10116
10211
|
}
|
|
10117
10212
|
if (created)
|
|
10118
|
-
fsyncDirectory(
|
|
10213
|
+
fsyncDirectory(path9.dirname(file));
|
|
10119
10214
|
return validEnd;
|
|
10120
10215
|
}
|
|
10121
10216
|
function replaceFile(file, bytes, durable) {
|
|
@@ -10131,7 +10226,7 @@ function replaceFile(file, bytes, durable) {
|
|
|
10131
10226
|
}
|
|
10132
10227
|
renameWithRetry(temporary, file);
|
|
10133
10228
|
if (durable)
|
|
10134
|
-
fsyncDirectory(
|
|
10229
|
+
fsyncDirectory(path9.dirname(file));
|
|
10135
10230
|
} catch (error) {
|
|
10136
10231
|
try {
|
|
10137
10232
|
fs9.unlinkSync(temporary);
|
|
@@ -10474,7 +10569,7 @@ var cachedRuntimeVersion = null;
|
|
|
10474
10569
|
var runtimeVersion = () => {
|
|
10475
10570
|
if (cachedRuntimeVersion === null) {
|
|
10476
10571
|
try {
|
|
10477
|
-
const pkg = JSON.parse(fs10.readFileSync(
|
|
10572
|
+
const pkg = JSON.parse(fs10.readFileSync(path10.join(packageRoot(), "package.json"), "utf8"));
|
|
10478
10573
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
10479
10574
|
} catch {
|
|
10480
10575
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -10507,7 +10602,7 @@ var readText = (file) => {
|
|
|
10507
10602
|
};
|
|
10508
10603
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
10509
10604
|
var branchStart = (location, branch, aliases) => {
|
|
10510
|
-
const first = readText(
|
|
10605
|
+
const first = readText(path10.join(path10.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
10511
10606
|
`, 1)[0];
|
|
10512
10607
|
const created = REFLOG_LINE.exec(first);
|
|
10513
10608
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -10517,7 +10612,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
10517
10612
|
return start;
|
|
10518
10613
|
if (!location.git)
|
|
10519
10614
|
return null;
|
|
10520
|
-
for (const line of readText(
|
|
10615
|
+
for (const line of readText(path10.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
10521
10616
|
`)) {
|
|
10522
10617
|
const entry = REFLOG_LINE.exec(line);
|
|
10523
10618
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -10527,14 +10622,14 @@ var branchStart = (location, branch, aliases) => {
|
|
|
10527
10622
|
}
|
|
10528
10623
|
return null;
|
|
10529
10624
|
};
|
|
10530
|
-
var refExists = (common, ref) => fs10.existsSync(
|
|
10625
|
+
var refExists = (common, ref) => fs10.existsSync(path10.join(common, ref)) || readText(path10.join(common, "packed-refs")).includes(` ${ref}
|
|
10531
10626
|
`);
|
|
10532
10627
|
var origins = new Map;
|
|
10533
10628
|
var sameDirectoryIdentity = (left, right) => {
|
|
10534
|
-
if (!
|
|
10629
|
+
if (!path10.isAbsolute(left) || !path10.isAbsolute(right))
|
|
10535
10630
|
return false;
|
|
10536
|
-
const normalizedLeft =
|
|
10537
|
-
const normalizedRight =
|
|
10631
|
+
const normalizedLeft = path10.resolve(left);
|
|
10632
|
+
const normalizedRight = path10.resolve(right);
|
|
10538
10633
|
try {
|
|
10539
10634
|
const a = fs10.statSync(normalizedLeft, { bigint: true });
|
|
10540
10635
|
const b = fs10.statSync(normalizedRight, { bigint: true });
|
|
@@ -10580,7 +10675,7 @@ class TaskStore {
|
|
|
10580
10675
|
migrationChecked = false;
|
|
10581
10676
|
compactDue = new Set;
|
|
10582
10677
|
constructor(root, options = {}) {
|
|
10583
|
-
const resolved =
|
|
10678
|
+
const resolved = path10.resolve(root);
|
|
10584
10679
|
this.origin = fs10.existsSync(resolved) ? fs10.realpathSync(resolved) : resolved;
|
|
10585
10680
|
this.located = resolveStore(this.origin);
|
|
10586
10681
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
@@ -10589,7 +10684,7 @@ class TaskStore {
|
|
|
10589
10684
|
this.migrateOnRead = options.migrateOnRead;
|
|
10590
10685
|
}
|
|
10591
10686
|
location() {
|
|
10592
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs10.existsSync(
|
|
10687
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs10.existsSync(path10.join(this.root, ".git"))) {
|
|
10593
10688
|
this.located = undefined;
|
|
10594
10689
|
this.migrationChecked = false;
|
|
10595
10690
|
}
|
|
@@ -10745,7 +10840,7 @@ class TaskStore {
|
|
|
10745
10840
|
const moved = this.bindLocked(again.data.id, key, input.now);
|
|
10746
10841
|
return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
|
|
10747
10842
|
}
|
|
10748
|
-
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" :
|
|
10843
|
+
const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path10.basename(this.root) || this.root;
|
|
10749
10844
|
const intent = {
|
|
10750
10845
|
objective: input.objective?.trim() || `Work on ${label}`,
|
|
10751
10846
|
scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
|
|
@@ -10805,14 +10900,14 @@ class TaskStore {
|
|
|
10805
10900
|
const branch = key.ok ? key.data.branch : null;
|
|
10806
10901
|
if (!branch || !location.ok)
|
|
10807
10902
|
return success(null, null, null);
|
|
10808
|
-
const common =
|
|
10809
|
-
const heads =
|
|
10810
|
-
const headLog = location.data.git ?
|
|
10903
|
+
const common = path10.dirname(location.data.dir);
|
|
10904
|
+
const heads = path10.join(common, "logs", "refs", "heads");
|
|
10905
|
+
const headLog = location.data.git ? path10.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
10811
10906
|
const signatures = [
|
|
10812
|
-
|
|
10907
|
+
path10.join(heads, branch),
|
|
10813
10908
|
headLog,
|
|
10814
10909
|
heads,
|
|
10815
|
-
|
|
10910
|
+
path10.join(common, "packed-refs")
|
|
10816
10911
|
].map((file) => fileSignature(file) ?? "-");
|
|
10817
10912
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
10818
10913
|
let resolved = origins.get(slot);
|
|
@@ -10824,7 +10919,7 @@ class TaskStore {
|
|
|
10824
10919
|
aliases.push(rename.from);
|
|
10825
10920
|
const start = branchStart(location.data, branch, aliases);
|
|
10826
10921
|
const slash = start?.indexOf("/") ?? -1;
|
|
10827
|
-
const remote = slash > 0 && !refExists(common, `refs/heads/${start}`) && (refExists(common, `refs/remotes/${start}`) || readText(
|
|
10922
|
+
const remote = slash > 0 && !refExists(common, `refs/heads/${start}`) && (refExists(common, `refs/remotes/${start}`) || readText(path10.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
|
|
10828
10923
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
10829
10924
|
resolved = {
|
|
10830
10925
|
signature: signatures.join("|"),
|
|
@@ -11062,13 +11157,13 @@ class TaskStore {
|
|
|
11062
11157
|
if (!ready.ok)
|
|
11063
11158
|
return ready;
|
|
11064
11159
|
const dirs = this.paths();
|
|
11065
|
-
const recovery =
|
|
11160
|
+
const recovery = path10.join(this.root, ".workit", "recovery");
|
|
11066
11161
|
if (fs10.existsSync(recovery)) {
|
|
11067
11162
|
let files = 0;
|
|
11068
11163
|
let bytes = 0;
|
|
11069
11164
|
try {
|
|
11070
11165
|
for (const name of fs10.readdirSync(recovery)) {
|
|
11071
|
-
const stat = fs10.lstatSync(
|
|
11166
|
+
const stat = fs10.lstatSync(path10.join(recovery, name));
|
|
11072
11167
|
if (!stat.isFile())
|
|
11073
11168
|
continue;
|
|
11074
11169
|
files += 1;
|
|
@@ -11121,7 +11216,7 @@ class TaskStore {
|
|
|
11121
11216
|
if (fs10.existsSync(dirs.blobs))
|
|
11122
11217
|
for (const name of fs10.readdirSync(dirs.blobs)) {
|
|
11123
11218
|
const digest = name.replace(/\.json$/, "");
|
|
11124
|
-
const file =
|
|
11219
|
+
const file = path10.join(dirs.blobs, name);
|
|
11125
11220
|
let stat;
|
|
11126
11221
|
try {
|
|
11127
11222
|
stat = fs10.lstatSync(file);
|
|
@@ -11139,7 +11234,7 @@ class TaskStore {
|
|
|
11139
11234
|
}
|
|
11140
11235
|
return success(null, null, null);
|
|
11141
11236
|
};
|
|
11142
|
-
const swept = dryRun ? sweep() : this.withLock(
|
|
11237
|
+
const swept = dryRun ? sweep() : this.withLock(path10.join(dirs.dir, "gc.lock"), sweep);
|
|
11143
11238
|
if (!swept.ok)
|
|
11144
11239
|
return swept;
|
|
11145
11240
|
const temporaryDirs = [
|
|
@@ -11147,7 +11242,7 @@ class TaskStore {
|
|
|
11147
11242
|
dirs.tasks,
|
|
11148
11243
|
dirs.blobs,
|
|
11149
11244
|
dirs.checkout,
|
|
11150
|
-
...names.map((name) =>
|
|
11245
|
+
...names.map((name) => path10.join(dirs.tasks, name))
|
|
11151
11246
|
];
|
|
11152
11247
|
for (const directory of temporaryDirs) {
|
|
11153
11248
|
if (!fs10.existsSync(directory))
|
|
@@ -11155,7 +11250,7 @@ class TaskStore {
|
|
|
11155
11250
|
for (const name of fs10.readdirSync(directory)) {
|
|
11156
11251
|
if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
|
|
11157
11252
|
continue;
|
|
11158
|
-
const file =
|
|
11253
|
+
const file = path10.join(directory, name);
|
|
11159
11254
|
try {
|
|
11160
11255
|
const stat = fs10.lstatSync(file);
|
|
11161
11256
|
if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
|
|
@@ -11172,30 +11267,30 @@ class TaskStore {
|
|
|
11172
11267
|
}
|
|
11173
11268
|
paths() {
|
|
11174
11269
|
const location = this.location();
|
|
11175
|
-
const dir = location.ok ? location.data.dir :
|
|
11176
|
-
const checkout =
|
|
11270
|
+
const dir = location.ok ? location.data.dir : path10.join(this.root, ".workit");
|
|
11271
|
+
const checkout = path10.join(dir, "checkouts", checkoutSlug(this.root));
|
|
11177
11272
|
return {
|
|
11178
11273
|
dir,
|
|
11179
11274
|
shared: location.ok ? location.data.shared : false,
|
|
11180
|
-
marker:
|
|
11275
|
+
marker: path10.join(dir, "store.json"),
|
|
11181
11276
|
checkout,
|
|
11182
|
-
workspace:
|
|
11183
|
-
checkoutLock:
|
|
11184
|
-
tasks:
|
|
11185
|
-
index:
|
|
11186
|
-
blobs:
|
|
11187
|
-
legacy:
|
|
11188
|
-
v2:
|
|
11277
|
+
workspace: path10.join(checkout, "workspace.json"),
|
|
11278
|
+
checkoutLock: path10.join(checkout, "metadata.lock"),
|
|
11279
|
+
tasks: path10.join(dir, "tasks"),
|
|
11280
|
+
index: path10.join(dir, "task-index.json"),
|
|
11281
|
+
blobs: path10.join(dir, "blobs", "candidates"),
|
|
11282
|
+
legacy: path10.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
11283
|
+
v2: path10.join(this.root, ".workit")
|
|
11189
11284
|
};
|
|
11190
11285
|
}
|
|
11191
11286
|
eventsPath(taskId) {
|
|
11192
|
-
return
|
|
11287
|
+
return path10.join(this.paths().tasks, taskId, "events.jsonl");
|
|
11193
11288
|
}
|
|
11194
11289
|
snapshotPath(taskId) {
|
|
11195
|
-
return
|
|
11290
|
+
return path10.join(this.paths().tasks, taskId, "snapshot.json");
|
|
11196
11291
|
}
|
|
11197
11292
|
taskLockPath(taskId) {
|
|
11198
|
-
return
|
|
11293
|
+
return path10.join(this.paths().tasks, taskId, "lock");
|
|
11199
11294
|
}
|
|
11200
11295
|
ready(write = false) {
|
|
11201
11296
|
const location = this.location();
|
|
@@ -11234,13 +11329,13 @@ class TaskStore {
|
|
|
11234
11329
|
return {
|
|
11235
11330
|
read: (digest) => {
|
|
11236
11331
|
try {
|
|
11237
|
-
return JSON.parse(fs10.readFileSync(
|
|
11332
|
+
return JSON.parse(fs10.readFileSync(path10.join(dir, `${digest}.json`), "utf8"));
|
|
11238
11333
|
} catch (error) {
|
|
11239
11334
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
11240
11335
|
}
|
|
11241
11336
|
},
|
|
11242
11337
|
write: (digest, value) => {
|
|
11243
|
-
const file =
|
|
11338
|
+
const file = path10.join(dir, `${digest}.json`);
|
|
11244
11339
|
if (fs10.existsSync(file)) {
|
|
11245
11340
|
const stamp = new Date;
|
|
11246
11341
|
try {
|
|
@@ -11432,7 +11527,7 @@ class TaskStore {
|
|
|
11432
11527
|
}
|
|
11433
11528
|
}
|
|
11434
11529
|
openTask(record, type, key, legacy = null) {
|
|
11435
|
-
const dir =
|
|
11530
|
+
const dir = path10.join(this.paths().tasks, record.id);
|
|
11436
11531
|
fs10.mkdirSync(dir, { recursive: true });
|
|
11437
11532
|
const blobs = this.blobStore();
|
|
11438
11533
|
const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
|
|
@@ -11525,7 +11620,7 @@ class TaskStore {
|
|
|
11525
11620
|
}
|
|
11526
11621
|
withKeyLock(key, operation) {
|
|
11527
11622
|
const digest = createHash6("sha256").update(key).digest("hex").slice(0, 32);
|
|
11528
|
-
return this.withLock(
|
|
11623
|
+
return this.withLock(path10.join(this.paths().dir, "keys", `${digest}.lock`), operation);
|
|
11529
11624
|
}
|
|
11530
11625
|
bindLocked(taskId, key, timestamp) {
|
|
11531
11626
|
const current = this.readWorkspace();
|
|
@@ -11666,7 +11761,7 @@ class TaskStore {
|
|
|
11666
11761
|
writeWorkspace(record) {
|
|
11667
11762
|
const file = this.paths().workspace;
|
|
11668
11763
|
try {
|
|
11669
|
-
fs10.mkdirSync(
|
|
11764
|
+
fs10.mkdirSync(path10.dirname(file), { recursive: true });
|
|
11670
11765
|
replaceFile(file, `${canonicalJson(record)}
|
|
11671
11766
|
`, true);
|
|
11672
11767
|
return success(null, null, null);
|
|
@@ -11744,23 +11839,23 @@ class TaskStore {
|
|
|
11744
11839
|
return failure2("revision_conflict", "workspace revision does not match; omit expectedWorkspaceRevision to use the current record", { expectedWorkspaceRevision: expected, actualWorkspaceRevision: actual });
|
|
11745
11840
|
}
|
|
11746
11841
|
v2Dirs() {
|
|
11747
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
11842
|
+
return [...new Set([this.root, this.origin])].map((dir) => path10.join(dir, ".workit"));
|
|
11748
11843
|
}
|
|
11749
11844
|
pendingMigrations() {
|
|
11750
11845
|
return this.v2Dirs().filter((dir) => {
|
|
11751
|
-
const raw = this.readV2Workspace(
|
|
11846
|
+
const raw = this.readV2Workspace(path10.join(dir, "workspace.json"));
|
|
11752
11847
|
return raw !== null && raw !== TOMBSTONE;
|
|
11753
11848
|
});
|
|
11754
11849
|
}
|
|
11755
11850
|
migrateV2(v2) {
|
|
11756
11851
|
const dirs = this.paths();
|
|
11757
|
-
const v2Workspace =
|
|
11758
|
-
const v2Tasks =
|
|
11759
|
-
const legacy =
|
|
11852
|
+
const v2Workspace = path10.join(v2, "workspace.json");
|
|
11853
|
+
const v2Tasks = path10.join(v2, "tasks");
|
|
11854
|
+
const legacy = path10.join(dirs.dir, "legacy", checkoutSlug(path10.dirname(v2)), "v2");
|
|
11760
11855
|
const raw = this.readV2Workspace(v2Workspace);
|
|
11761
11856
|
if (raw === null || raw === TOMBSTONE)
|
|
11762
11857
|
return success(null, null, null);
|
|
11763
|
-
return this.withLock(dirs.checkoutLock, () => this.withLock(
|
|
11858
|
+
return this.withLock(dirs.checkoutLock, () => this.withLock(path10.join(v2, "metadata.lock"), () => {
|
|
11764
11859
|
const workspace = this.readV2Workspace(v2Workspace);
|
|
11765
11860
|
if (workspace === null || workspace === TOMBSTONE)
|
|
11766
11861
|
return success(null, null, null);
|
|
@@ -11769,7 +11864,7 @@ class TaskStore {
|
|
|
11769
11864
|
return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
|
|
11770
11865
|
let files = [];
|
|
11771
11866
|
try {
|
|
11772
|
-
files = fs10.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(
|
|
11867
|
+
files = fs10.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path10.join(v2Tasks, name)));
|
|
11773
11868
|
} catch {}
|
|
11774
11869
|
const current = this.readWorkspace();
|
|
11775
11870
|
if (!current.ok)
|
|
@@ -11787,21 +11882,21 @@ class TaskStore {
|
|
|
11787
11882
|
let skipped = 0;
|
|
11788
11883
|
const done = new Map;
|
|
11789
11884
|
try {
|
|
11790
|
-
fs10.mkdirSync(
|
|
11885
|
+
fs10.mkdirSync(path10.join(legacy, "tasks"), { recursive: true });
|
|
11791
11886
|
for (const name of ["workspace.json", "index.json"])
|
|
11792
|
-
if (fs10.existsSync(
|
|
11793
|
-
fs10.copyFileSync(
|
|
11887
|
+
if (fs10.existsSync(path10.join(v2, name)))
|
|
11888
|
+
fs10.copyFileSync(path10.join(v2, name), path10.join(legacy, name));
|
|
11794
11889
|
for (const name of files) {
|
|
11795
11890
|
const id = name.slice(0, -5);
|
|
11796
|
-
const file =
|
|
11891
|
+
const file = path10.join(v2Tasks, name);
|
|
11797
11892
|
const bytes = fs10.readFileSync(file, "utf8");
|
|
11798
11893
|
const digest = sha256(bytes);
|
|
11799
|
-
fs10.writeFileSync(
|
|
11894
|
+
fs10.writeFileSync(path10.join(legacy, "tasks", name), bytes);
|
|
11800
11895
|
const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
|
|
11801
11896
|
if (!parsed.ok || parsed.data.id !== id)
|
|
11802
11897
|
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 });
|
|
11803
11898
|
const record = { ...parsed.data, workspaceId: target.id };
|
|
11804
|
-
const origin = { path:
|
|
11899
|
+
const origin = { path: path10.join(legacy, "tasks", name), digest };
|
|
11805
11900
|
if (!fs10.existsSync(this.eventsPath(id))) {
|
|
11806
11901
|
this.openTask(record, "migrated.from_v2", null, origin);
|
|
11807
11902
|
migrated += 1;
|
|
@@ -11837,7 +11932,7 @@ class TaskStore {
|
|
|
11837
11932
|
try {
|
|
11838
11933
|
let complete = true;
|
|
11839
11934
|
for (const [name, digest] of done) {
|
|
11840
|
-
const file =
|
|
11935
|
+
const file = path10.join(v2Tasks, name);
|
|
11841
11936
|
if (sha256(fs10.readFileSync(file, "utf8")) !== digest) {
|
|
11842
11937
|
complete = false;
|
|
11843
11938
|
continue;
|
|
@@ -11848,7 +11943,7 @@ class TaskStore {
|
|
|
11848
11943
|
return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
|
|
11849
11944
|
path: v2
|
|
11850
11945
|
});
|
|
11851
|
-
fs10.rmSync(
|
|
11946
|
+
fs10.rmSync(path10.join(v2, "index.json"), { force: true });
|
|
11852
11947
|
this.writeTombstone(v2, target.id);
|
|
11853
11948
|
} catch (error) {
|
|
11854
11949
|
return failure2("storage_error", `cannot finish the 2.x migration: ${String(error)}`, {
|
|
@@ -11868,7 +11963,7 @@ class TaskStore {
|
|
|
11868
11963
|
}
|
|
11869
11964
|
adoptLocalStore() {
|
|
11870
11965
|
const dirs = this.paths();
|
|
11871
|
-
const marker =
|
|
11966
|
+
const marker = path10.join(dirs.v2, "store.json");
|
|
11872
11967
|
if (!dirs.shared || !fs10.existsSync(marker))
|
|
11873
11968
|
return success(null, null, null);
|
|
11874
11969
|
return this.withLock(dirs.checkoutLock, () => {
|
|
@@ -11878,7 +11973,7 @@ class TaskStore {
|
|
|
11878
11973
|
try {
|
|
11879
11974
|
const merge = (from, to) => {
|
|
11880
11975
|
if (!fs10.existsSync(to)) {
|
|
11881
|
-
fs10.mkdirSync(
|
|
11976
|
+
fs10.mkdirSync(path10.dirname(to), { recursive: true });
|
|
11882
11977
|
try {
|
|
11883
11978
|
fs10.renameSync(from, to);
|
|
11884
11979
|
} catch {
|
|
@@ -11889,24 +11984,24 @@ class TaskStore {
|
|
|
11889
11984
|
}
|
|
11890
11985
|
if (fs10.lstatSync(from).isDirectory() && fs10.lstatSync(to).isDirectory())
|
|
11891
11986
|
for (const name of fs10.readdirSync(from))
|
|
11892
|
-
merge(
|
|
11987
|
+
merge(path10.join(from, name), path10.join(to, name));
|
|
11893
11988
|
};
|
|
11894
11989
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
11895
|
-
const from =
|
|
11990
|
+
const from = path10.join(dirs.v2, sub);
|
|
11896
11991
|
if (!fs10.existsSync(from))
|
|
11897
11992
|
continue;
|
|
11898
11993
|
if (sub === "tasks") {
|
|
11899
11994
|
for (const name of fs10.readdirSync(from))
|
|
11900
|
-
if (validId(name) && !fs10.existsSync(
|
|
11995
|
+
if (validId(name) && !fs10.existsSync(path10.join(dirs.dir, sub, name)))
|
|
11901
11996
|
tasks += 1;
|
|
11902
11997
|
}
|
|
11903
|
-
merge(from,
|
|
11998
|
+
merge(from, path10.join(dirs.dir, sub));
|
|
11904
11999
|
}
|
|
11905
|
-
const ledger =
|
|
11906
|
-
if (fs10.existsSync(ledger) && !fs10.existsSync(
|
|
11907
|
-
merge(ledger,
|
|
11908
|
-
fs10.rmSync(
|
|
11909
|
-
fs10.renameSync(marker,
|
|
12000
|
+
const ledger = path10.join(dirs.v2, "ledger");
|
|
12001
|
+
if (fs10.existsSync(ledger) && !fs10.existsSync(path10.join(dirs.dir, "ledger")))
|
|
12002
|
+
merge(ledger, path10.join(dirs.dir, "ledger"));
|
|
12003
|
+
fs10.rmSync(path10.join(dirs.v2, "task-index.json"), { force: true });
|
|
12004
|
+
fs10.renameSync(marker, path10.join(dirs.v2, "store.moved.json"));
|
|
11910
12005
|
} catch (error) {
|
|
11911
12006
|
return failure2("storage_error", `cannot move ${dirs.v2} into ${dirs.dir}: ${String(error)}`, {
|
|
11912
12007
|
path: dirs.v2
|
|
@@ -11944,7 +12039,7 @@ class TaskStore {
|
|
|
11944
12039
|
schemaVersion: SCHEMA_VERSION,
|
|
11945
12040
|
id: workspaceId ?? newId(),
|
|
11946
12041
|
revision: newRevision(),
|
|
11947
|
-
root:
|
|
12042
|
+
root: path10.dirname(v2),
|
|
11948
12043
|
runtime: { createdWith: version, updatedWith: version },
|
|
11949
12044
|
writer: null,
|
|
11950
12045
|
store: {
|
|
@@ -11956,11 +12051,11 @@ class TaskStore {
|
|
|
11956
12051
|
critical: ["store"]
|
|
11957
12052
|
};
|
|
11958
12053
|
fs10.mkdirSync(v2, { recursive: true });
|
|
11959
|
-
const ignore =
|
|
12054
|
+
const ignore = path10.join(v2, ".gitignore");
|
|
11960
12055
|
if (!fs10.existsSync(ignore))
|
|
11961
12056
|
fs10.writeFileSync(ignore, `*
|
|
11962
12057
|
`);
|
|
11963
|
-
replaceFile(
|
|
12058
|
+
replaceFile(path10.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
11964
12059
|
`, true);
|
|
11965
12060
|
}
|
|
11966
12061
|
stubFor(taskId) {
|
|
@@ -11984,8 +12079,8 @@ class TaskStore {
|
|
|
11984
12079
|
}
|
|
11985
12080
|
writeTombstoneIfMissing() {
|
|
11986
12081
|
try {
|
|
11987
|
-
const v2 =
|
|
11988
|
-
if (fs10.existsSync(
|
|
12082
|
+
const v2 = path10.join(this.root, ".workit");
|
|
12083
|
+
if (fs10.existsSync(path10.join(v2, "workspace.json")))
|
|
11989
12084
|
return;
|
|
11990
12085
|
let id = null;
|
|
11991
12086
|
try {
|
|
@@ -12002,7 +12097,7 @@ class TaskStore {
|
|
|
12002
12097
|
replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
|
|
12003
12098
|
`, false);
|
|
12004
12099
|
if (!dirs.shared) {
|
|
12005
|
-
const ignore =
|
|
12100
|
+
const ignore = path10.join(dirs.dir, ".gitignore");
|
|
12006
12101
|
let current = null;
|
|
12007
12102
|
try {
|
|
12008
12103
|
current = fs10.readFileSync(ignore, "utf8");
|
|
@@ -12062,7 +12157,7 @@ class TaskStore {
|
|
|
12062
12157
|
withLock(lockPath, operation) {
|
|
12063
12158
|
try {
|
|
12064
12159
|
this.initializeStorage();
|
|
12065
|
-
fs10.mkdirSync(
|
|
12160
|
+
fs10.mkdirSync(path10.dirname(lockPath), { recursive: true });
|
|
12066
12161
|
} catch (error) {
|
|
12067
12162
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
12068
12163
|
path: this.paths().dir
|
|
@@ -12125,7 +12220,7 @@ class TaskStore {
|
|
|
12125
12220
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
12126
12221
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
12127
12222
|
path: lockPath,
|
|
12128
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
12223
|
+
guidance: `Check permissions and the read-only attribute on ${path10.dirname(lockPath)}.`
|
|
12129
12224
|
});
|
|
12130
12225
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
12131
12226
|
let lock = null;
|
|
@@ -12145,17 +12240,17 @@ class TaskStore {
|
|
|
12145
12240
|
|
|
12146
12241
|
// packages/workit-core/src/core/policy/derive.ts
|
|
12147
12242
|
import { existsSync as existsSync4 } from "node:fs";
|
|
12148
|
-
import
|
|
12243
|
+
import path15 from "node:path";
|
|
12149
12244
|
|
|
12150
12245
|
// packages/workit-core/src/ledger.ts
|
|
12151
12246
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
12152
12247
|
import { createHash as createHash9, randomBytes as randomBytes2 } from "node:crypto";
|
|
12153
12248
|
import fs12 from "node:fs";
|
|
12154
|
-
import
|
|
12249
|
+
import path14 from "node:path";
|
|
12155
12250
|
|
|
12156
12251
|
// packages/workit-core/src/core/vcs-config.ts
|
|
12157
12252
|
import fs11 from "node:fs";
|
|
12158
|
-
import
|
|
12253
|
+
import path13 from "node:path";
|
|
12159
12254
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
12160
12255
|
|
|
12161
12256
|
// packages/workit-core/src/core/config.ts
|
|
@@ -12168,8 +12263,8 @@ import {
|
|
|
12168
12263
|
readdirSync as readdirSync2,
|
|
12169
12264
|
writeFileSync as writeFileSync2
|
|
12170
12265
|
} from "node:fs";
|
|
12171
|
-
import
|
|
12172
|
-
import
|
|
12266
|
+
import os3 from "node:os";
|
|
12267
|
+
import path11 from "node:path";
|
|
12173
12268
|
|
|
12174
12269
|
// packages/workit-core/src/core/boundary.ts
|
|
12175
12270
|
var EVENT = {
|
|
@@ -12213,7 +12308,7 @@ var mergePreset = (preset, input = {}, current = {
|
|
|
12213
12308
|
protected: preset === "custom" ? input.protectedNames ?? current.branchPolicy.protected : [...defs.protected]
|
|
12214
12309
|
};
|
|
12215
12310
|
};
|
|
12216
|
-
var resolveConfigDir = () => process.env.WORKFLOW_TOOLKIT_CONFIG ?? process.env.WORKFLOW_TOOLKIT_CONFIG_DIR ??
|
|
12311
|
+
var resolveConfigDir = () => process.env.WORKFLOW_TOOLKIT_CONFIG ?? process.env.WORKFLOW_TOOLKIT_CONFIG_DIR ?? path11.join(process.env.XDG_CONFIG_HOME || path11.join(os3.homedir(), ".config"), "workit");
|
|
12217
12312
|
var migratedDir = null;
|
|
12218
12313
|
var migrationFailed = false;
|
|
12219
12314
|
var ensureConfigDir = (dir = resolveConfigDir()) => {
|
|
@@ -12223,7 +12318,7 @@ var ensureConfigDir = (dir = resolveConfigDir()) => {
|
|
|
12223
12318
|
migratedDir = dir;
|
|
12224
12319
|
return dir;
|
|
12225
12320
|
}
|
|
12226
|
-
const legacy =
|
|
12321
|
+
const legacy = path11.join(process.env.XDG_CONFIG_HOME || path11.join(os3.homedir(), ".config"), "workflow-toolkit");
|
|
12227
12322
|
if (!existsSync3(legacy)) {
|
|
12228
12323
|
migratedDir = dir;
|
|
12229
12324
|
return dir;
|
|
@@ -12236,8 +12331,8 @@ var ensureConfigDir = (dir = resolveConfigDir()) => {
|
|
|
12236
12331
|
mkdirSync2(dir, { recursive: true });
|
|
12237
12332
|
diagnosticLogger?.info(EVENT.migration, { from: legacy, to: dir });
|
|
12238
12333
|
for (const entry of readdirSync2(legacy, { withFileTypes: true })) {
|
|
12239
|
-
const src =
|
|
12240
|
-
const dest =
|
|
12334
|
+
const src = path11.join(legacy, entry.name);
|
|
12335
|
+
const dest = path11.join(dir, entry.name);
|
|
12241
12336
|
if (existsSync3(dest))
|
|
12242
12337
|
continue;
|
|
12243
12338
|
try {
|
|
@@ -12309,7 +12404,7 @@ var parseConfigResult = (raw, file) => {
|
|
|
12309
12404
|
return { status: "valid", path: file, config };
|
|
12310
12405
|
};
|
|
12311
12406
|
var readConfigTyped = (dir) => {
|
|
12312
|
-
const file =
|
|
12407
|
+
const file = path11.join(dir ?? configDir(), "config.json");
|
|
12313
12408
|
return parseConfigResult(readSafe(file), file);
|
|
12314
12409
|
};
|
|
12315
12410
|
var readConfig = () => {
|
|
@@ -12318,7 +12413,7 @@ var readConfig = () => {
|
|
|
12318
12413
|
throw new Error(result.error);
|
|
12319
12414
|
return result.config ?? DEFAULTS;
|
|
12320
12415
|
};
|
|
12321
|
-
var vcsConfigPath = () => process.env.WORKFLOW_VCS_CONFIG ??
|
|
12416
|
+
var vcsConfigPath = () => process.env.WORKFLOW_VCS_CONFIG ?? path11.join(configDir(), "vcs.json");
|
|
12322
12417
|
var branchGlobPattern = (glob) => new RegExp(`^${glob.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`, "i");
|
|
12323
12418
|
var resolveBranchPolicy = (config, workspace, repoPreset) => {
|
|
12324
12419
|
const wp = workspace?.branchPolicy ?? {};
|
|
@@ -12362,7 +12457,7 @@ var resolveCommitPolicy = (config, workspace) => {
|
|
|
12362
12457
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
12363
12458
|
import { createHash as createHash7 } from "node:crypto";
|
|
12364
12459
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
12365
|
-
import
|
|
12460
|
+
import path12 from "node:path";
|
|
12366
12461
|
|
|
12367
12462
|
// packages/workit-core/src/core/branch-policy.ts
|
|
12368
12463
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
@@ -12488,7 +12583,7 @@ var releaseTrackSchema = object({
|
|
|
12488
12583
|
context.addIssue({ code: "custom", path: [field], message: "entries must be unique" });
|
|
12489
12584
|
}
|
|
12490
12585
|
}
|
|
12491
|
-
if (track.versionSource?.kind === "package-json" && (
|
|
12586
|
+
if (track.versionSource?.kind === "package-json" && (path12.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
|
|
12492
12587
|
context.addIssue({
|
|
12493
12588
|
code: "custom",
|
|
12494
12589
|
path: ["versionSource", "path"],
|
|
@@ -12587,7 +12682,7 @@ var validateWorkspacesDocument = (parsed, file) => {
|
|
|
12587
12682
|
};
|
|
12588
12683
|
};
|
|
12589
12684
|
var readWorkspacesResult = (dir = configDir()) => {
|
|
12590
|
-
const file =
|
|
12685
|
+
const file = path12.join(dir, "workspaces.json");
|
|
12591
12686
|
let raw;
|
|
12592
12687
|
try {
|
|
12593
12688
|
raw = readFileSync3(file, "utf8");
|
|
@@ -12698,9 +12793,9 @@ var mainCheckoutOf = (cwd) => {
|
|
|
12698
12793
|
let main = null;
|
|
12699
12794
|
const dirs = git(["rev-parse", "--path-format=absolute", "--git-dir", "--git-common-dir"]);
|
|
12700
12795
|
const [gitDir, common] = (dirs ?? "").trim().split(/\r?\n/u);
|
|
12701
|
-
if (gitDir && common &&
|
|
12796
|
+
if (gitDir && common && path12.resolve(gitDir) !== path12.resolve(common)) {
|
|
12702
12797
|
const listed = /^worktree (.+)$/mu.exec(git(["worktree", "list", "--porcelain"]) ?? "")?.[1];
|
|
12703
|
-
main = listed?.trim() || (
|
|
12798
|
+
main = listed?.trim() || (path12.basename(common) === ".git" ? path12.dirname(common) : common);
|
|
12704
12799
|
}
|
|
12705
12800
|
mainCheckouts.set(cwd, main);
|
|
12706
12801
|
return main;
|
|
@@ -12791,7 +12886,7 @@ var runtimeWorkspaceIndexSchema = object({
|
|
|
12791
12886
|
workspaces: array(object({ name: nonBlank, glob: nonBlank }).passthrough()).optional()
|
|
12792
12887
|
}).passthrough();
|
|
12793
12888
|
var matchRuntimeWorkspace = (cwd, dir = configDir()) => {
|
|
12794
|
-
const file =
|
|
12889
|
+
const file = path12.join(dir, "workspaces.json");
|
|
12795
12890
|
let raw;
|
|
12796
12891
|
try {
|
|
12797
12892
|
raw = readFileSync3(file, "utf8");
|
|
@@ -13180,7 +13275,7 @@ var git3 = (cwd, args) => {
|
|
|
13180
13275
|
return run.status === 0 ? (run.stdout ?? "").trim() : null;
|
|
13181
13276
|
};
|
|
13182
13277
|
var recordedBaseKey = (branch) => `branch.${branch}.workitBase`;
|
|
13183
|
-
var
|
|
13278
|
+
var escapeRegExp2 = (text) => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
13184
13279
|
var reflog = (cwd, ref) => (git3(cwd, ["log", "-g", "--date=unix", "--format=%H%x09%gd%x09%gs", ref, "--"]) ?? "").split(`
|
|
13185
13280
|
`).map((line) => {
|
|
13186
13281
|
const [sha = "", selector = "", ...subject] = line.split("\t");
|
|
@@ -13212,7 +13307,7 @@ function gitTrackProbe(cwd) {
|
|
|
13212
13307
|
const created = own.at(-1);
|
|
13213
13308
|
if (!created || created.subject !== "branch: Created from HEAD")
|
|
13214
13309
|
return null;
|
|
13215
|
-
const pattern = new RegExp(`^checkout: moving from (\\S+) to ${
|
|
13310
|
+
const pattern = new RegExp(`^checkout: moving from (\\S+) to ${escapeRegExp2(branch)}$`, "u");
|
|
13216
13311
|
const entry = reflog(cwd, "HEAD").findLast((item) => item.time >= created.time && item.sha === created.sha && pattern.test(item.subject));
|
|
13217
13312
|
return entry ? pattern.exec(entry.subject)?.[1] ?? null : null;
|
|
13218
13313
|
},
|
|
@@ -13282,7 +13377,7 @@ function resolveTrackFor(cwd, options) {
|
|
|
13282
13377
|
}
|
|
13283
13378
|
|
|
13284
13379
|
// packages/workit-core/src/core/vcs-config.ts
|
|
13285
|
-
var workspacesPath = () =>
|
|
13380
|
+
var workspacesPath = () => path13.join(configDir(), "workspaces.json");
|
|
13286
13381
|
var vcsCwd = (cwd) => cwd ?? process.env.WORKFLOW_WORKSPACE_ROOT ?? process.cwd();
|
|
13287
13382
|
var remoteProvider = (cwd) => {
|
|
13288
13383
|
const r = spawnSync8("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf8" });
|
|
@@ -13384,7 +13479,7 @@ function vcsConfig(mode, cwd, options = {}) {
|
|
|
13384
13479
|
const prov = cfg[provider] ?? {};
|
|
13385
13480
|
const out = {
|
|
13386
13481
|
ok: true,
|
|
13387
|
-
configPath:
|
|
13482
|
+
configPath: path13.resolve(cfgPath),
|
|
13388
13483
|
provider,
|
|
13389
13484
|
defaultTargetBranch: workspaceDefault,
|
|
13390
13485
|
pr: cfg.pr ?? {},
|
|
@@ -13522,14 +13617,14 @@ function diffHash(cwd, base, head) {
|
|
|
13522
13617
|
return `sha256:${hash.digest("hex")}`;
|
|
13523
13618
|
}
|
|
13524
13619
|
function storeRoot(cwd) {
|
|
13525
|
-
const location = resolveStore(
|
|
13620
|
+
const location = resolveStore(path14.resolve(cwd));
|
|
13526
13621
|
if (location instanceof Error)
|
|
13527
13622
|
return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), "fix the repository (git status should work here) or run from a non-git directory");
|
|
13528
13623
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
13529
13624
|
}
|
|
13530
13625
|
function ledgerPath(cwd) {
|
|
13531
13626
|
const root = storeRoot(cwd);
|
|
13532
|
-
return root.ok ? { ok: true, value:
|
|
13627
|
+
return root.ok ? { ok: true, value: path14.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
13533
13628
|
}
|
|
13534
13629
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes2(6).toString("hex")}`;
|
|
13535
13630
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -13559,13 +13654,13 @@ var LOCK_STALE_MS = 30000;
|
|
|
13559
13654
|
var LOCK_OWNER = "owner";
|
|
13560
13655
|
var lockToken = (lock) => {
|
|
13561
13656
|
try {
|
|
13562
|
-
return fs12.readFileSync(
|
|
13657
|
+
return fs12.readFileSync(path14.join(lock, LOCK_OWNER), "utf8");
|
|
13563
13658
|
} catch {
|
|
13564
13659
|
return null;
|
|
13565
13660
|
}
|
|
13566
13661
|
};
|
|
13567
13662
|
var lockAgeMs = (lock) => {
|
|
13568
|
-
for (const target of [
|
|
13663
|
+
for (const target of [path14.join(lock, LOCK_OWNER), lock]) {
|
|
13569
13664
|
try {
|
|
13570
13665
|
return Date.now() - fs12.statSync(target).mtimeMs;
|
|
13571
13666
|
} catch {}
|
|
@@ -13582,7 +13677,7 @@ var ledgerLock = {
|
|
|
13582
13677
|
throw error;
|
|
13583
13678
|
}
|
|
13584
13679
|
const token = `${process.pid}-${randomBytes2(8).toString("hex")}`;
|
|
13585
|
-
fs12.writeFileSync(
|
|
13680
|
+
fs12.writeFileSync(path14.join(lock, LOCK_OWNER), token);
|
|
13586
13681
|
return token;
|
|
13587
13682
|
},
|
|
13588
13683
|
release(lock, token) {
|
|
@@ -13707,8 +13802,8 @@ function appendLine(file, build, options) {
|
|
|
13707
13802
|
}
|
|
13708
13803
|
};
|
|
13709
13804
|
try {
|
|
13710
|
-
fs12.mkdirSync(
|
|
13711
|
-
if (!options.forceLock && !onNetworkFs(
|
|
13805
|
+
fs12.mkdirSync(path14.dirname(file), { recursive: true });
|
|
13806
|
+
if (!options.forceLock && !onNetworkFs(path14.dirname(file)))
|
|
13712
13807
|
return write();
|
|
13713
13808
|
const locked = withLedgerLock(file, write);
|
|
13714
13809
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -14271,7 +14366,7 @@ var productDecision = (task, ledger) => {
|
|
|
14271
14366
|
};
|
|
14272
14367
|
};
|
|
14273
14368
|
var planRecorded = (task, root) => {
|
|
14274
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync4(
|
|
14369
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync4(path15.resolve(root, ref.path)));
|
|
14275
14370
|
if (cited)
|
|
14276
14371
|
return {
|
|
14277
14372
|
met: true,
|
|
@@ -14331,14 +14426,14 @@ function writeBlockers(task, root) {
|
|
|
14331
14426
|
|
|
14332
14427
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
14333
14428
|
var digestBytes = (value) => createHash10("sha256").update(value).digest("hex");
|
|
14334
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
14335
|
-
var relative = (root, candidate) =>
|
|
14429
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path16.sep}`);
|
|
14430
|
+
var relative = (root, candidate) => path16.relative(root, candidate).split(path16.sep).join("/") || ".";
|
|
14336
14431
|
var canonicalPath = (value) => {
|
|
14337
14432
|
if (typeof value !== "string" || !value)
|
|
14338
14433
|
return null;
|
|
14339
14434
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
14340
14435
|
return null;
|
|
14341
|
-
const normalized =
|
|
14436
|
+
const normalized = path16.posix.normalize(value);
|
|
14342
14437
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
14343
14438
|
return null;
|
|
14344
14439
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -14386,14 +14481,14 @@ var gitPaths = (root) => {
|
|
|
14386
14481
|
git: !/not a git repository/i.test(stderr)
|
|
14387
14482
|
};
|
|
14388
14483
|
}
|
|
14389
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
14484
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path16.sep).join("/")) : [];
|
|
14390
14485
|
const stagedDeleted = spawnSync10("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
14391
14486
|
if (stagedDeleted.status !== 0) {
|
|
14392
14487
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
14393
14488
|
if (!/not a git repository/i.test(stderr))
|
|
14394
14489
|
return { paths, uncertain: true, git: true };
|
|
14395
14490
|
} else if (stagedDeleted.stdout) {
|
|
14396
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
14491
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path16.sep).join("/")));
|
|
14397
14492
|
}
|
|
14398
14493
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
14399
14494
|
};
|
|
@@ -14408,7 +14503,7 @@ var walk = (root, directory, output) => {
|
|
|
14408
14503
|
for (const name of names) {
|
|
14409
14504
|
if (name === ".git" || name === ".workit")
|
|
14410
14505
|
continue;
|
|
14411
|
-
const target =
|
|
14506
|
+
const target = path16.join(directory, name);
|
|
14412
14507
|
let stat;
|
|
14413
14508
|
try {
|
|
14414
14509
|
stat = fs13.lstatSync(target);
|
|
@@ -14426,12 +14521,12 @@ var walk = (root, directory, output) => {
|
|
|
14426
14521
|
var scopeRoots = (root, scope) => {
|
|
14427
14522
|
const roots = [];
|
|
14428
14523
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
14429
|
-
const target =
|
|
14524
|
+
const target = path16.resolve(root, item);
|
|
14430
14525
|
if (!inside(root, target))
|
|
14431
14526
|
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` }] });
|
|
14432
14527
|
let ancestor = target;
|
|
14433
14528
|
while (!fs13.existsSync(ancestor) && ancestor !== root)
|
|
14434
|
-
ancestor =
|
|
14529
|
+
ancestor = path16.dirname(ancestor);
|
|
14435
14530
|
try {
|
|
14436
14531
|
if (!inside(root, fs13.realpathSync(ancestor)))
|
|
14437
14532
|
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` }] });
|
|
@@ -14483,7 +14578,7 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
14483
14578
|
for (const item of [...names].toSorted()) {
|
|
14484
14579
|
if (!scopeMatches(item, normalizedScope))
|
|
14485
14580
|
continue;
|
|
14486
|
-
const target =
|
|
14581
|
+
const target = path16.join(checkout, item);
|
|
14487
14582
|
try {
|
|
14488
14583
|
const stat = fs13.lstatSync(target);
|
|
14489
14584
|
if (stat.isSymbolicLink()) {
|
|
@@ -14667,23 +14762,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
14667
14762
|
continue;
|
|
14668
14763
|
if (!reference.digest)
|
|
14669
14764
|
return failure2("invalid_input", "document references require a byte digest");
|
|
14670
|
-
const target =
|
|
14671
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
14765
|
+
const target = path16.resolve(root, reference.path);
|
|
14766
|
+
if (target !== root && !target.startsWith(`${root}${path16.sep}`))
|
|
14672
14767
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
14673
14768
|
fields: [
|
|
14674
14769
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
14675
14770
|
]
|
|
14676
14771
|
});
|
|
14677
14772
|
try {
|
|
14678
|
-
const below =
|
|
14773
|
+
const below = path16.relative(root, target);
|
|
14679
14774
|
let current = root;
|
|
14680
|
-
for (const segment of below.split(
|
|
14775
|
+
for (const segment of below.split(path16.sep)) {
|
|
14681
14776
|
if (!segment)
|
|
14682
14777
|
continue;
|
|
14683
|
-
current =
|
|
14778
|
+
current = path16.join(current, segment);
|
|
14684
14779
|
const stat = fs13.lstatSync(current);
|
|
14685
14780
|
const real = fs13.realpathSync(current);
|
|
14686
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
14781
|
+
if (real !== root && !real.startsWith(`${root}${path16.sep}`))
|
|
14687
14782
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
14688
14783
|
fields: [
|
|
14689
14784
|
{
|
|
@@ -15555,20 +15650,20 @@ var judgeInputSummary = (raw) => {
|
|
|
15555
15650
|
};
|
|
15556
15651
|
|
|
15557
15652
|
// packages/workit-core/src/autonomy.ts
|
|
15558
|
-
import
|
|
15559
|
-
import
|
|
15653
|
+
import os4 from "node:os";
|
|
15654
|
+
import path17 from "node:path";
|
|
15560
15655
|
var accountHome = () => {
|
|
15561
15656
|
try {
|
|
15562
|
-
return
|
|
15657
|
+
return os4.userInfo().homedir;
|
|
15563
15658
|
} catch {
|
|
15564
|
-
return
|
|
15659
|
+
return os4.homedir();
|
|
15565
15660
|
}
|
|
15566
15661
|
};
|
|
15567
15662
|
var grantsHome = { resolve: accountHome };
|
|
15568
|
-
var grantsDir = () =>
|
|
15663
|
+
var grantsDir = () => path17.join(grantsHome.resolve(), ".config", "workit");
|
|
15569
15664
|
var grantsOverride = () => {
|
|
15570
|
-
const configured =
|
|
15571
|
-
return configured ===
|
|
15665
|
+
const configured = path17.resolve(resolveConfigDir());
|
|
15666
|
+
return configured === path17.resolve(grantsDir()) ? null : `the config directory is redirected to ${configured} (WORKFLOW_TOOLKIT_CONFIG, WORKFLOW_TOOLKIT_CONFIG_DIR or XDG_CONFIG_HOME); grants are read only from ${path17.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply`;
|
|
15572
15667
|
};
|
|
15573
15668
|
var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
|
|
15574
15669
|
var DEFAULT_GRANTS = Object.freeze({
|
|
@@ -17550,7 +17645,7 @@ function entryCompactContext(store, entry, session, context) {
|
|
|
17550
17645
|
return null;
|
|
17551
17646
|
const freshness = { mode: "signal", current: () => recentSignal(store.root) };
|
|
17552
17647
|
const observed = task?.data.evidence.some(isObservedCheck) ?? false;
|
|
17553
|
-
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [
|
|
17648
|
+
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path18.resolve(store.root, ref.path)] : []));
|
|
17554
17649
|
const observedFiles = filesKey(files);
|
|
17555
17650
|
const compact = new WorkitCore(store, context).compactContext(entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
|
|
17556
17651
|
if (!compact.ok || !compact.data)
|
|
@@ -17628,14 +17723,14 @@ var turnMarker = (input) => {
|
|
|
17628
17723
|
if (location instanceof Error)
|
|
17629
17724
|
return null;
|
|
17630
17725
|
const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
|
|
17631
|
-
return
|
|
17726
|
+
return path18.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
|
|
17632
17727
|
} catch {
|
|
17633
17728
|
return null;
|
|
17634
17729
|
}
|
|
17635
17730
|
};
|
|
17636
17731
|
var writeTurnDigest = (file, digest) => {
|
|
17637
17732
|
try {
|
|
17638
|
-
fs14.mkdirSync(
|
|
17733
|
+
fs14.mkdirSync(path18.dirname(file), { recursive: true });
|
|
17639
17734
|
fs14.writeFileSync(file, `${JSON.stringify({ digest })}
|
|
17640
17735
|
`);
|
|
17641
17736
|
} catch {}
|
|
@@ -17650,7 +17745,7 @@ var pruneTurnDigests = (dir, now) => {
|
|
|
17650
17745
|
for (const name of fs14.readdirSync(dir)) {
|
|
17651
17746
|
if (!name.startsWith("turn-"))
|
|
17652
17747
|
continue;
|
|
17653
|
-
const file =
|
|
17748
|
+
const file = path18.join(dir, name);
|
|
17654
17749
|
try {
|
|
17655
17750
|
if (now - fs14.statSync(file).mtimeMs > TURN_TTL_MS)
|
|
17656
17751
|
fs14.rmSync(file, { force: true });
|
|
@@ -17680,7 +17775,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
|
|
|
17680
17775
|
const file = turnMarker(input);
|
|
17681
17776
|
if (!file)
|
|
17682
17777
|
return;
|
|
17683
|
-
pruneTurnDigests(
|
|
17778
|
+
pruneTurnDigests(path18.dirname(file), Date.now());
|
|
17684
17779
|
if (text)
|
|
17685
17780
|
writeTurnDigest(file, digestOf(text));
|
|
17686
17781
|
else
|
|
@@ -17689,14 +17784,14 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
|
|
|
17689
17784
|
// packages/workit-core/src/core/route-intent.ts
|
|
17690
17785
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
17691
17786
|
import { existsSync as existsSync6 } from "node:fs";
|
|
17692
|
-
import
|
|
17787
|
+
import path21 from "node:path";
|
|
17693
17788
|
|
|
17694
17789
|
// packages/workit-core/src/hooks/raw-git.ts
|
|
17695
17790
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
17696
17791
|
import { createHash as createHash14 } from "node:crypto";
|
|
17697
17792
|
import fs16 from "node:fs";
|
|
17698
|
-
import
|
|
17699
|
-
import
|
|
17793
|
+
import os5 from "node:os";
|
|
17794
|
+
import path20 from "node:path";
|
|
17700
17795
|
|
|
17701
17796
|
// packages/workit-core/src/core/branch.ts
|
|
17702
17797
|
import { createHash as createHash12 } from "node:crypto";
|
|
@@ -17909,7 +18004,7 @@ var globOf = (pattern) => pattern.source.replace(/^\^|\$$/gu, "").replaceAll(".*
|
|
|
17909
18004
|
// packages/workit-core/src/hooks/session-marker.ts
|
|
17910
18005
|
import { createHash as createHash13 } from "node:crypto";
|
|
17911
18006
|
import fs15 from "node:fs";
|
|
17912
|
-
import
|
|
18007
|
+
import path19 from "node:path";
|
|
17913
18008
|
var sessionMarkerFile = (input, session, store) => {
|
|
17914
18009
|
let dir = store;
|
|
17915
18010
|
if (dir === undefined) {
|
|
@@ -17919,7 +18014,7 @@ var sessionMarkerFile = (input, session, store) => {
|
|
|
17919
18014
|
dir = location.dir;
|
|
17920
18015
|
}
|
|
17921
18016
|
const name = createHash13("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
|
|
17922
|
-
return
|
|
18017
|
+
return path19.join(dir, "hooks", `skills-${name}.json`);
|
|
17923
18018
|
};
|
|
17924
18019
|
var list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
17925
18020
|
var readSessionMarker = (file) => {
|
|
@@ -17932,7 +18027,7 @@ var readSessionMarker = (file) => {
|
|
|
17932
18027
|
};
|
|
17933
18028
|
var writeSessionMarker = (file, marker) => {
|
|
17934
18029
|
try {
|
|
17935
|
-
fs15.mkdirSync(
|
|
18030
|
+
fs15.mkdirSync(path19.dirname(file), { recursive: true });
|
|
17936
18031
|
fs15.writeFileSync(file, JSON.stringify(marker));
|
|
17937
18032
|
} catch {}
|
|
17938
18033
|
};
|
|
@@ -18077,12 +18172,12 @@ var GIT_VALUE_OPTIONS = new Set([
|
|
|
18077
18172
|
"--config-env",
|
|
18078
18173
|
"--super-prefix"
|
|
18079
18174
|
]);
|
|
18080
|
-
var isAbsolute = (value) =>
|
|
18175
|
+
var isAbsolute = (value) => path20.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
|
|
18081
18176
|
var joinDir = (base, next) => {
|
|
18082
18177
|
if (base === undefined || /[$`*?]/.test(next) || next === "-")
|
|
18083
18178
|
return;
|
|
18084
|
-
const expanded = next === "~" || next.startsWith("~/") ?
|
|
18085
|
-
return base === null || isAbsolute(expanded) ? expanded :
|
|
18179
|
+
const expanded = next === "~" || next.startsWith("~/") ? path20.join(os5.homedir(), next.slice(1)) : next;
|
|
18180
|
+
return base === null || isAbsolute(expanded) ? expanded : path20.join(base, expanded);
|
|
18086
18181
|
};
|
|
18087
18182
|
var cdTarget = (words) => {
|
|
18088
18183
|
const args = words.slice(1);
|
|
@@ -18133,7 +18228,7 @@ function rawInvocations(command, dialect = "posix", depth = 0) {
|
|
|
18133
18228
|
const name = commandName(words[0]);
|
|
18134
18229
|
if (CD.has(name)) {
|
|
18135
18230
|
const target = cdTarget(words);
|
|
18136
|
-
dir = target === null ?
|
|
18231
|
+
dir = target === null ? os5.homedir() : joinDir(dir, target);
|
|
18137
18232
|
continue;
|
|
18138
18233
|
}
|
|
18139
18234
|
if (PUSHD.has(name)) {
|
|
@@ -18391,17 +18486,17 @@ var headSha2 = (repo) => {
|
|
|
18391
18486
|
if (!git || git.reftable)
|
|
18392
18487
|
return null;
|
|
18393
18488
|
try {
|
|
18394
|
-
const head = fs16.readFileSync(
|
|
18489
|
+
const head = fs16.readFileSync(path20.join(git.gitDir, "HEAD"), "utf8").trim();
|
|
18395
18490
|
if (/^[0-9a-f]{40,64}$/.test(head))
|
|
18396
18491
|
return head;
|
|
18397
18492
|
const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
|
|
18398
18493
|
if (!ref)
|
|
18399
18494
|
return null;
|
|
18400
|
-
const common =
|
|
18495
|
+
const common = path20.dirname(repo.location.dir);
|
|
18401
18496
|
try {
|
|
18402
|
-
return fs16.readFileSync(
|
|
18497
|
+
return fs16.readFileSync(path20.join(common, ref), "utf8").trim() || null;
|
|
18403
18498
|
} catch {}
|
|
18404
|
-
const packed = fs16.readFileSync(
|
|
18499
|
+
const packed = fs16.readFileSync(path20.join(common, "packed-refs"), "utf8");
|
|
18405
18500
|
return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
|
|
18406
18501
|
} catch {
|
|
18407
18502
|
return null;
|
|
@@ -18490,7 +18585,7 @@ var actionsIn = (cwd, command, dialect) => {
|
|
|
18490
18585
|
const action = rawAction(invocation);
|
|
18491
18586
|
if (!action)
|
|
18492
18587
|
continue;
|
|
18493
|
-
const dir =
|
|
18588
|
+
const dir = path20.resolve(cwd, invocation.dir ?? ".");
|
|
18494
18589
|
if (!repos.has(dir)) {
|
|
18495
18590
|
const repo = repoAt(dir);
|
|
18496
18591
|
repos.set(dir, repo && isWorkitWorkspace(repo) ? repo : null);
|
|
@@ -18570,7 +18665,7 @@ function rawGitPre(input, command, options = {}) {
|
|
|
18570
18665
|
var deny = (reason) => ({ kind: "deny", reason, unblock: null });
|
|
18571
18666
|
var NEXT_COMMAND = "next";
|
|
18572
18667
|
var MARKER_TTL_SECONDS = 3600;
|
|
18573
|
-
var markerFile = (repo, session, key) =>
|
|
18668
|
+
var markerFile = (repo, session, key) => path20.join(repo.location.dir, "hooks", `commit-${createHash14("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
|
|
18574
18669
|
var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash14("sha256").update(command).digest("hex")}`;
|
|
18575
18670
|
function noteRawCommit(input, command, key) {
|
|
18576
18671
|
try {
|
|
@@ -18581,7 +18676,7 @@ function noteRawCommit(input, command, key) {
|
|
|
18581
18676
|
if (action.kind !== "commit")
|
|
18582
18677
|
continue;
|
|
18583
18678
|
const file = markerFile(repo, input.session.id, key);
|
|
18584
|
-
fs16.mkdirSync(
|
|
18679
|
+
fs16.mkdirSync(path20.dirname(file), { recursive: true });
|
|
18585
18680
|
fs16.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
|
|
18586
18681
|
`);
|
|
18587
18682
|
}
|
|
@@ -18754,7 +18849,7 @@ var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
|
|
|
18754
18849
|
for (const target of shellBranchTargets(command, dialect)) {
|
|
18755
18850
|
if (target.dir === undefined)
|
|
18756
18851
|
continue;
|
|
18757
|
-
const dir = target.dir === null ? root :
|
|
18852
|
+
const dir = target.dir === null ? root : path21.resolve(root, target.dir);
|
|
18758
18853
|
if (target.dir !== null && (!existsSync6(dir) || !inWorkitWorkspace(dir)))
|
|
18759
18854
|
continue;
|
|
18760
18855
|
if (localBranchExists(dir, target.branch))
|
|
@@ -18774,27 +18869,27 @@ var shellPolicy = (cwd, command, dialect = "posix") => {
|
|
|
18774
18869
|
};
|
|
18775
18870
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
18776
18871
|
import { realpathSync as realpathSync5 } from "node:fs";
|
|
18777
|
-
import
|
|
18872
|
+
import path22 from "node:path";
|
|
18778
18873
|
var NONE3 = { kind: "none" };
|
|
18779
18874
|
var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
|
|
18780
18875
|
var canonical2 = (file) => {
|
|
18781
18876
|
let rest = "";
|
|
18782
|
-
for (let dir =
|
|
18877
|
+
for (let dir = path22.resolve(file);; dir = path22.dirname(dir)) {
|
|
18783
18878
|
try {
|
|
18784
|
-
return
|
|
18879
|
+
return path22.join(realpathSync5(dir), rest);
|
|
18785
18880
|
} catch {
|
|
18786
|
-
if (
|
|
18787
|
-
return
|
|
18788
|
-
rest = rest ?
|
|
18881
|
+
if (path22.dirname(dir) === dir)
|
|
18882
|
+
return path22.resolve(file);
|
|
18883
|
+
rest = rest ? path22.join(path22.basename(dir), rest) : path22.basename(dir);
|
|
18789
18884
|
}
|
|
18790
18885
|
}
|
|
18791
18886
|
};
|
|
18792
18887
|
var exempt = (cwd, root, file, plans) => {
|
|
18793
18888
|
const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
|
|
18794
|
-
const relative =
|
|
18795
|
-
if (relative.startsWith("..") ||
|
|
18889
|
+
const relative = path22.relative(fold(canonical2(root)), fold(canonical2(path22.resolve(cwd, file))));
|
|
18890
|
+
if (relative.startsWith("..") || path22.isAbsolute(relative))
|
|
18796
18891
|
return true;
|
|
18797
|
-
const posix = relative.split(
|
|
18892
|
+
const posix = relative.split(path22.sep).join("/");
|
|
18798
18893
|
const segments = posix.split("/");
|
|
18799
18894
|
return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
|
|
18800
18895
|
};
|
|
@@ -18892,7 +18987,7 @@ var shellWrites = (command) => {
|
|
|
18892
18987
|
return { writes: true, targets: unknown ? null : targets };
|
|
18893
18988
|
};
|
|
18894
18989
|
var cache2 = new Map;
|
|
18895
|
-
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(
|
|
18990
|
+
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path22.resolve(root, file)) ?? "-").join("\x00");
|
|
18896
18991
|
var gateFor = (cwd) => {
|
|
18897
18992
|
const store = new TaskStore(cwd);
|
|
18898
18993
|
const listed = store.listTaskIndex();
|
|
@@ -19333,12 +19428,12 @@ ${line}` };
|
|
|
19333
19428
|
};
|
|
19334
19429
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
19335
19430
|
import { existsSync as existsSync7, realpathSync as realpathSync6, statSync as statSync2 } from "node:fs";
|
|
19336
|
-
import
|
|
19431
|
+
import path23 from "node:path";
|
|
19337
19432
|
var isRecord4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
19338
19433
|
var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
19339
19434
|
var optionalText = (value) => typeof value === "string" ? value : null;
|
|
19340
19435
|
var existingDirectory = (value) => {
|
|
19341
|
-
if (!nonEmpty2(value) || !
|
|
19436
|
+
if (!nonEmpty2(value) || !path23.isAbsolute(value) || !existsSync7(value))
|
|
19342
19437
|
return null;
|
|
19343
19438
|
try {
|
|
19344
19439
|
return statSync2(value).isDirectory() ? realpathSync6(value) : null;
|
|
@@ -20077,7 +20172,7 @@ var codexAdapter = {
|
|
|
20077
20172
|
|
|
20078
20173
|
// packages/workit-core/src/hooks/hosts/cursor.ts
|
|
20079
20174
|
import fs17 from "node:fs";
|
|
20080
|
-
import
|
|
20175
|
+
import path24 from "node:path";
|
|
20081
20176
|
var undocumented = { support: "undocumented", native: null };
|
|
20082
20177
|
var none = { support: "none", native: null };
|
|
20083
20178
|
var CURSOR_DESCRIPTOR = {
|
|
@@ -20274,7 +20369,7 @@ var protocolEvent2 = (input) => {
|
|
|
20274
20369
|
};
|
|
20275
20370
|
var TRANSCRIPT_TAIL_BYTES = 256 * 1024;
|
|
20276
20371
|
var lastAssistantText = (file) => {
|
|
20277
|
-
if (!file || !
|
|
20372
|
+
if (!file || !path24.isAbsolute(file))
|
|
20278
20373
|
return null;
|
|
20279
20374
|
try {
|
|
20280
20375
|
const size = fs17.statSync(file).size;
|
|
@@ -20311,7 +20406,7 @@ var lastAssistantText = (file) => {
|
|
|
20311
20406
|
return null;
|
|
20312
20407
|
}
|
|
20313
20408
|
};
|
|
20314
|
-
var within = (root, dir) => dir === root || dir.startsWith(root.endsWith(
|
|
20409
|
+
var within = (root, dir) => dir === root || dir.startsWith(root.endsWith(path24.sep) ? root : `${root}${path24.sep}`);
|
|
20315
20410
|
var hookCwd = (input) => {
|
|
20316
20411
|
const cwd = existingDirectory(input.cwd);
|
|
20317
20412
|
if (cwd && input.hook_event_name === "beforeShellExecution")
|