@workit-dev/codex 2.29.1 → 2.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13304,14 +13304,14 @@ function explainInvalidOperation(family, request) {
13304
13304
  return parsed.success ? null : invalidOperation(family, request, parsed.error);
13305
13305
  }
13306
13306
  // packages/workit-core/src/core/task-store.ts
13307
- import { createHash as createHash9 } from "node:crypto";
13307
+ import { createHash as createHash10 } from "node:crypto";
13308
13308
  import * as fs14 from "node:fs";
13309
- import path17 from "node:path";
13309
+ import path18 from "node:path";
13310
13310
 
13311
13311
  // packages/workit-core/src/host-session.ts
13312
- import { createHash as createHash7, randomBytes, timingSafeEqual } from "node:crypto";
13312
+ import { createHash as createHash8, randomBytes, timingSafeEqual } from "node:crypto";
13313
13313
  import fs7 from "node:fs";
13314
- import path11 from "node:path";
13314
+ import path12 from "node:path";
13315
13315
 
13316
13316
  // packages/workit-core/src/core/branch-policy.ts
13317
13317
  import { spawnSync } from "node:child_process";
@@ -13646,9 +13646,9 @@ var gitContext = (workspaceRoot, paths = []) => {
13646
13646
 
13647
13647
  // packages/workit-core/src/core/workspaces.ts
13648
13648
  import { spawnSync as spawnSync6 } from "node:child_process";
13649
- import { createHash as createHash4 } from "node:crypto";
13650
- import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
13651
- import path7 from "node:path";
13649
+ import { createHash as createHash5 } from "node:crypto";
13650
+ import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
13651
+ import path8 from "node:path";
13652
13652
 
13653
13653
  // packages/workit-core/src/core/remotes.ts
13654
13654
  import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
@@ -14829,6 +14829,103 @@ var pushTarget = (cwd, remote, replay = {}) => {
14829
14829
  return { remotes };
14830
14830
  };
14831
14831
 
14832
+ // packages/workit-core/src/core/grant-seal.ts
14833
+ import { createHash as createHash4 } from "node:crypto";
14834
+ import { readFileSync as readFileSync4 } from "node:fs";
14835
+ import path7 from "node:path";
14836
+ var SEAL_FILE = "workspaces.json.seal";
14837
+ var SEAL_VERSION = 2;
14838
+ var isSealVersion = (value) => value === 1 || value === 2;
14839
+ var SEAL_COMMAND = "workit workspace seal";
14840
+ var pick3 = (value, keys) => {
14841
+ if (!value || typeof value !== "object" || Array.isArray(value))
14842
+ return;
14843
+ const out = Object.fromEntries(keys.flatMap((key) => {
14844
+ const item = value[key];
14845
+ return item === undefined ? [] : [[key, item]];
14846
+ }));
14847
+ return Object.keys(out).length > 0 ? out : undefined;
14848
+ };
14849
+ var ENTRY_KEYS = [
14850
+ "name",
14851
+ "glob",
14852
+ "remotes",
14853
+ "externalRepos",
14854
+ "additiveRiskPaths",
14855
+ "vcs",
14856
+ "autonomy",
14857
+ "autoApprove",
14858
+ "defaultEndpoint",
14859
+ "verification",
14860
+ "youtrack"
14861
+ ];
14862
+ var RELEASE_KEYS = [
14863
+ "releaseNotes",
14864
+ "releaseTagPrefix",
14865
+ "branchPolicy",
14866
+ "profiles",
14867
+ "defaultProfile",
14868
+ "releaseTracks",
14869
+ "releasePackages"
14870
+ ];
14871
+ var keysOf = (version) => version >= 2 ? [...ENTRY_KEYS, ...RELEASE_KEYS] : ENTRY_KEYS;
14872
+ var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
14873
+ var sealProjection = (entries, version = SEAL_VERSION) => entries.map((entry) => {
14874
+ const keys = keysOf(version);
14875
+ const all = pick3(entry, keys) ?? {};
14876
+ return pick3({
14877
+ ...all,
14878
+ vcs: pick3(all.vcs, IDENTITY_KEYS),
14879
+ youtrack: pick3(all.youtrack, ["writes", "autoHosts"]),
14880
+ ...version >= 2 ? releaseLineMapping(entry, true) : {}
14881
+ }, keys);
14882
+ });
14883
+ 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);
14884
+ var sealDigest = (projection) => createHash4("sha256").update(canonical3(projection)).digest("hex");
14885
+ var broken = (reason, sealed = null, version) => ({
14886
+ state: "broken",
14887
+ reason,
14888
+ sealed,
14889
+ ...version ? { version } : {}
14890
+ });
14891
+ var PARTIAL_KEYS = ["releaseTracks", "branchPolicy", "profiles", "defaultProfile"];
14892
+ var sealedEntries = (projection, file) => {
14893
+ const partial = projection.map((entry) => pick3(entry, PARTIAL_KEYS));
14894
+ const validated = validateWorkspacesDocument({
14895
+ workspaces: projection.map((entry) => {
14896
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
14897
+ return entry;
14898
+ const rest = { ...entry };
14899
+ for (const key of PARTIAL_KEYS)
14900
+ delete rest[key];
14901
+ return rest;
14902
+ })
14903
+ }, file);
14904
+ if (validated.status !== "valid" || validated.entries.length !== projection.length)
14905
+ return null;
14906
+ return validated.entries.map((entry, at) => partial[at] === undefined ? entry : { ...entry, ...partial[at] });
14907
+ };
14908
+ function checkSeal(dir) {
14909
+ const file = path7.join(dir, SEAL_FILE);
14910
+ let seal;
14911
+ try {
14912
+ seal = JSON.parse(readFileSync4(file, "utf8"));
14913
+ } catch (error) {
14914
+ if (error.code === "ENOENT")
14915
+ return { state: "none" };
14916
+ return broken(`${SEAL_FILE} cannot be read`);
14917
+ }
14918
+ if (!isSealVersion(seal?.version) || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
14919
+ return broken(`${SEAL_FILE} is malformed`);
14920
+ const version = seal.version;
14921
+ const sealed = sealedEntries(seal.projection, file);
14922
+ if (!sealed)
14923
+ return broken(`${SEAL_FILE} is malformed`, null, version);
14924
+ const current = readWorkspacesResult(dir);
14925
+ const ok = current.status === "valid" || current.status === "missing";
14926
+ return ok && sealDigest(sealProjection(current.entries, version)) === seal.sha256 ? { state: "valid", version } : broken("workspaces.json changed since it was sealed", sealed, version);
14927
+ }
14928
+
14832
14929
  // packages/workit-core/src/core/workspaces.ts
14833
14930
  var nonBlank = string2().check(refine((value) => value.trim().length > 0, "must not be blank"));
14834
14931
  var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
@@ -14894,7 +14991,7 @@ var releaseTrackSchema = looseObject({
14894
14991
  });
14895
14992
  }
14896
14993
  }
14897
- if (track.versionSource?.kind === "package-json" && (path7.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
14994
+ if (track.versionSource?.kind === "package-json" && (path8.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
14898
14995
  context.addIssue({
14899
14996
  code: "custom",
14900
14997
  path: ["versionSource", "path"],
@@ -14993,7 +15090,7 @@ var workspacesFileSchema = looseObject({
14993
15090
  names.add(workspace.name);
14994
15091
  }
14995
15092
  }));
14996
- var workspacesRevision = (contents) => createHash4("sha256").update(contents ?? "<missing>").digest("hex");
15093
+ var workspacesRevision = (contents) => createHash5("sha256").update(contents ?? "<missing>").digest("hex");
14997
15094
  var validateWorkspacesDocument = (parsed, file) => {
14998
15095
  if (!isConfigObject(parsed)) {
14999
15096
  return {
@@ -15039,10 +15136,10 @@ var validateWorkspacesDocument = (parsed, file) => {
15039
15136
  };
15040
15137
  };
15041
15138
  var readWorkspacesResult = (dir = configDir2()) => {
15042
- const file = path7.join(dir, "workspaces.json");
15139
+ const file = path8.join(dir, "workspaces.json");
15043
15140
  let raw;
15044
15141
  try {
15045
- raw = readFileSync4(file, "utf8");
15142
+ raw = readFileSync5(file, "utf8");
15046
15143
  } catch (error) {
15047
15144
  if (error.code === "ENOENT")
15048
15145
  return {
@@ -15143,9 +15240,9 @@ var probeCheckout = (cwd) => {
15143
15240
  const cached = probes.get(cwd);
15144
15241
  if (cached !== undefined)
15145
15242
  return cached;
15146
- let dir = path7.resolve(cwd);
15147
- while (!existsSync4(path7.join(dir, ".git"))) {
15148
- if (["HEAD", "objects", "refs"].every((name) => existsSync4(path7.join(dir, name)))) {
15243
+ let dir = path8.resolve(cwd);
15244
+ while (!existsSync4(path8.join(dir, ".git"))) {
15245
+ if (["HEAD", "objects", "refs"].every((name) => existsSync4(path8.join(dir, name)))) {
15149
15246
  const real = realpathOf(dir);
15150
15247
  const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
15151
15248
  if (owner === null)
@@ -15154,7 +15251,7 @@ var probeCheckout = (cwd) => {
15154
15251
  probes.set(cwd, probe);
15155
15252
  return probe;
15156
15253
  }
15157
- const up = path7.dirname(dir);
15254
+ const up = path8.dirname(dir);
15158
15255
  if (up === dir)
15159
15256
  return null;
15160
15257
  dir = up;
@@ -15183,9 +15280,9 @@ var probeCheckout = (cwd) => {
15183
15280
  if (!gitDir || !common)
15184
15281
  return failed;
15185
15282
  let main = null;
15186
- if (path7.resolve(gitDir) === path7.resolve(common)) {
15283
+ if (path8.resolve(gitDir) === path8.resolve(common)) {
15187
15284
  const real = realpathOf(common);
15188
- if (!ownGitDir(path7.join(dir, ".git"), real)) {
15285
+ if (!ownGitDir(path8.join(dir, ".git"), real)) {
15189
15286
  const owner = gitDirOwner(real);
15190
15287
  if (owner === null)
15191
15288
  return Error(`${cwd} uses the repository at ${real}, owned by no checkout workit can name`);
@@ -15204,7 +15301,7 @@ var probeCheckout = (cwd) => {
15204
15301
  const list = git(["worktree", "list", "--porcelain"]);
15205
15302
  if (list === null)
15206
15303
  return failed;
15207
- main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path7.basename(common) === ".git" ? path7.dirname(common) : common);
15304
+ main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path8.basename(common) === ".git" ? path8.dirname(common) : common);
15208
15305
  }
15209
15306
  const probe = { main, superproject: superproject || null };
15210
15307
  probes.set(cwd, probe);
@@ -15221,7 +15318,7 @@ var INTERNALS = ["refs", "objects", "config", "packed-refs", "commondir"];
15221
15318
  var ownInternals = (real) => {
15222
15319
  let lender = null;
15223
15320
  for (const name of INTERNALS) {
15224
- const at = path7.join(real, name);
15321
+ const at = path8.join(real, name);
15225
15322
  try {
15226
15323
  lstatSync3(at);
15227
15324
  } catch {
@@ -15233,10 +15330,10 @@ var ownInternals = (real) => {
15233
15330
  } catch {
15234
15331
  return false;
15235
15332
  }
15236
- const rel = path7.relative(real, resolved);
15237
- if (rel && !rel.startsWith("..") && !path7.isAbsolute(rel))
15333
+ const rel = path8.relative(real, resolved);
15334
+ if (rel && !rel.startsWith("..") && !path8.isAbsolute(rel))
15238
15335
  continue;
15239
- const owner = path7.basename(resolved) === name ? gitDirOwner(path7.dirname(resolved)) : null;
15336
+ const owner = path8.basename(resolved) === name ? gitDirOwner(path8.dirname(resolved)) : null;
15240
15337
  if (owner === null || lender !== null && lender !== owner)
15241
15338
  return false;
15242
15339
  lender = owner;
@@ -15250,7 +15347,7 @@ var gitDirOwner = (real) => {
15250
15347
  return null;
15251
15348
  const rest = parts.slice(at + 1);
15252
15349
  const module = rest[0] === "modules" || rest[0] === "worktrees" && rest[2] === "modules";
15253
- return rest.length === 0 || module ? parts.slice(0, at).join(path7.sep) || path7.sep : null;
15350
+ return rest.length === 0 || module ? parts.slice(0, at).join(path8.sep) || path8.sep : null;
15254
15351
  };
15255
15352
  var mainCheckoutOf = (cwd) => {
15256
15353
  const probe = probeCheckout(cwd);
@@ -15374,11 +15471,11 @@ var resolveRuntimeWorkspaceVcs = (cwd) => resolveRuntimeWorkspaceCandidate(cwd,
15374
15471
  var runtimeWorkspaceIndexSchema = looseObject({
15375
15472
  workspaces: optional(array(looseObject({ name: nonBlank, glob: nonBlank })))
15376
15473
  });
15377
- var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
15378
- const file = path7.join(dir, "workspaces.json");
15474
+ var matchRuntimeWorkspace = (cwd, dir = configDir2(), workspaceName = namedWorkspace()) => {
15475
+ const file = path8.join(dir, "workspaces.json");
15379
15476
  let raw;
15380
15477
  try {
15381
- raw = readFileSync4(file, "utf8");
15478
+ raw = readFileSync5(file, "utf8");
15382
15479
  } catch (error) {
15383
15480
  if (error.code === "ENOENT")
15384
15481
  return null;
@@ -15401,12 +15498,16 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
15401
15498
  if (!glob.ok)
15402
15499
  throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
15403
15500
  }
15404
- const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
15405
- const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
15501
+ const matched = matchAmong(cwd, entries ?? [], workspaceName);
15502
+ return matched ? { file, ...matched } : null;
15503
+ };
15504
+ var namedWorkspace = () => process.env.WORKIT_WORKSPACE_NAME?.trim() || null;
15505
+ var matchAmong = (cwd, entries, workspaceName = namedWorkspace()) => {
15506
+ const selected = resolveWorkspaceFromEntries(cwd, entries, workspaceName ?? undefined, true);
15406
15507
  if (!selected)
15407
15508
  return null;
15408
- const matches = matchingEntries(cwd, entries ?? []);
15409
- return { file, selected, matches: matches.length ? matches : [selected] };
15509
+ const matches = matchingEntries(cwd, entries);
15510
+ return { selected, matches: matches.length ? matches : [selected] };
15410
15511
  };
15411
15512
  var resolveRuntimeReleaseTracks = (cwd) => {
15412
15513
  const matched = matchRuntimeWorkspace(cwd);
@@ -15415,6 +15516,47 @@ var resolveRuntimeReleaseTracks = (cwd) => {
15415
15516
  releaseTracks: matched.selected.releaseTracks
15416
15517
  } : null;
15417
15518
  };
15519
+ var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
15520
+ var pickSet = (value, keys) => isPlainRecord(value) ? Object.fromEntries(keys.filter((key) => value[key] !== undefined).map((key) => [key, value[key]])) : {};
15521
+ var mapRecord = (value, map) => Object.fromEntries(Object.entries(value).map(([name, item]) => [name, map(item)]));
15522
+ var TRACK_LINE_KEYS = [
15523
+ "tagNamespace",
15524
+ "productionBranch",
15525
+ "integrationBranch",
15526
+ "baseBranch",
15527
+ "mergeBackBranches",
15528
+ "pullRequestTarget",
15529
+ "naming",
15530
+ "strategy"
15531
+ ];
15532
+ var releaseLineMapping = (entry, notes = false) => {
15533
+ if (!isPlainRecord(entry))
15534
+ return;
15535
+ const out = {};
15536
+ if (notes && entry.releaseNotes !== undefined)
15537
+ out.releaseNotes = entry.releaseNotes;
15538
+ if (entry.releaseTagPrefix !== undefined)
15539
+ out.releaseTagPrefix = entry.releaseTagPrefix;
15540
+ if (entry.defaultProfile !== undefined)
15541
+ out.defaultProfile = entry.defaultProfile;
15542
+ const policy = pickSet(entry.branchPolicy, ["releaseTagPrefix"]);
15543
+ if (Object.keys(policy).length)
15544
+ out.branchPolicy = policy;
15545
+ const profiles = Object.fromEntries(Object.entries(isPlainRecord(entry.profiles) ? entry.profiles : {}).flatMap(([name, profile]) => {
15546
+ const prefix = pickSet(isPlainRecord(profile) ? profile.branchPolicy : undefined, [
15547
+ "releaseTagPrefix"
15548
+ ]);
15549
+ return Object.keys(prefix).length ? [[name, { branchPolicy: prefix }]] : [];
15550
+ }));
15551
+ if (Object.keys(profiles).length)
15552
+ out.profiles = profiles;
15553
+ const trackKeys = notes ? [...TRACK_LINE_KEYS, "releaseNotes"] : TRACK_LINE_KEYS;
15554
+ if (entry.releaseTracks !== undefined)
15555
+ out.releaseTracks = isPlainRecord(entry.releaseTracks) ? mapRecord(entry.releaseTracks, (track) => pickSet(track, trackKeys)) : entry.releaseTracks;
15556
+ if (entry.releasePackages !== undefined)
15557
+ out.releasePackages = isPlainRecord(entry.releasePackages) ? mapRecord(entry.releasePackages, (pkg) => pickSet(pkg, ["tagNamespace"])) : entry.releasePackages;
15558
+ return Object.keys(out).length ? out : undefined;
15559
+ };
15418
15560
  var modelSources = (cwd, dir) => {
15419
15561
  const out = [];
15420
15562
  try {
@@ -15431,7 +15573,7 @@ var modelSources = (cwd, dir) => {
15431
15573
  }
15432
15574
  } catch {}
15433
15575
  try {
15434
- const document = JSON.parse(readFileSync4(path7.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
15576
+ const document = JSON.parse(readFileSync5(path8.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
15435
15577
  if (document && typeof document === "object" && !Array.isArray(document))
15436
15578
  out.push({
15437
15579
  name: "global",
@@ -15496,11 +15638,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
15496
15638
 
15497
15639
  // packages/workit-core/src/core/vcs-config.ts
15498
15640
  import fs4 from "node:fs";
15499
- import path8 from "node:path";
15641
+ import path9 from "node:path";
15500
15642
  import { spawnSync as spawnSync8 } from "node:child_process";
15501
15643
 
15502
15644
  // packages/workit-core/src/core/release-tracks.ts
15503
- import { createHash as createHash5 } from "node:crypto";
15645
+ import { createHash as createHash6 } from "node:crypto";
15504
15646
  import { spawnSync as spawnSync7 } from "node:child_process";
15505
15647
  var KNOWN_FIELDS = new Set([
15506
15648
  "strategy",
@@ -15870,7 +16012,7 @@ function resolveTrackFor(cwd, options) {
15870
16012
  ]) ?? "",
15871
16013
  git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
15872
16014
  ] : [];
15873
- key = createHash5("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
16015
+ key = createHash6("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
15874
16016
  const hit = memo2.get(key);
15875
16017
  if (hit)
15876
16018
  return hit;
@@ -15885,7 +16027,7 @@ function resolveTrackFor(cwd, options) {
15885
16027
  }
15886
16028
 
15887
16029
  // packages/workit-core/src/core/vcs-config.ts
15888
- var workspacesPath = () => path8.join(configDir2(), "workspaces.json");
16030
+ var workspacesPath = () => path9.join(configDir2(), "workspaces.json");
15889
16031
  var vcsCwd = (cwd) => cwd ?? process.env.WORKIT_WORKSPACE_ROOT ?? process.cwd();
15890
16032
  var remoteProvider = (cwd) => {
15891
16033
  const url = originUrl(cwd) ?? "";
@@ -16097,7 +16239,7 @@ function vcsConfig(mode, cwd, options = {}) {
16097
16239
  const prov = cfg[provider] ?? {};
16098
16240
  const out = {
16099
16241
  ok: true,
16100
- configPath: path8.resolve(cfgPath),
16242
+ configPath: path9.resolve(cfgPath),
16101
16243
  provider,
16102
16244
  defaultTargetBranch: workspaceDefault,
16103
16245
  pr: cfg.pr ?? {},
@@ -16265,7 +16407,7 @@ var redactSecrets = (value) => applyPatterns(value);
16265
16407
  // packages/workit-core/src/store/folder-store.ts
16266
16408
  import fs5 from "node:fs";
16267
16409
  import os5 from "node:os";
16268
- import path9 from "node:path";
16410
+ import path10 from "node:path";
16269
16411
  var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
16270
16412
  var MOVED_POINTER = "MOVED-TO-STATE.txt";
16271
16413
  var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
@@ -16274,7 +16416,7 @@ var MARKER = "workspace.json";
16274
16416
  var v2Workspace = (workit) => {
16275
16417
  let bytes;
16276
16418
  try {
16277
- bytes = fs5.readFileSync(path9.join(workit, MARKER), "utf8");
16419
+ bytes = fs5.readFileSync(path10.join(workit, MARKER), "utf8");
16278
16420
  } catch {
16279
16421
  return null;
16280
16422
  }
@@ -16323,7 +16465,7 @@ var strayEntries = (workit) => {
16323
16465
  } catch {
16324
16466
  return [];
16325
16467
  }
16326
- return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path9.join(workit, name))) && !(name === "tasks" && onlyStubs(path9.join(workit, name))));
16468
+ return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path10.join(workit, name))) && !(name === "tasks" && onlyStubs(path10.join(workit, name))));
16327
16469
  };
16328
16470
  var folderStoreIo = {
16329
16471
  rename: (from, to) => fs5.renameSync(from, to),
@@ -16331,13 +16473,13 @@ var folderStoreIo = {
16331
16473
  judgedStale: () => {}
16332
16474
  };
16333
16475
  var tempSeq = 0;
16334
- var tempBeside = (file) => path9.join(path9.dirname(file), `.${path9.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
16476
+ var tempBeside = (file) => path10.join(path10.dirname(file), `.${path10.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
16335
16477
  var copyInto = (from, to) => {
16336
16478
  const stat = fs5.lstatSync(from);
16337
16479
  if (stat.isDirectory()) {
16338
16480
  fs5.mkdirSync(to, { recursive: true });
16339
16481
  for (const name of fs5.readdirSync(from))
16340
- copyInto(path9.join(from, name), path9.join(to, name));
16482
+ copyInto(path10.join(from, name), path10.join(to, name));
16341
16483
  return;
16342
16484
  }
16343
16485
  if (exists(to))
@@ -16388,7 +16530,7 @@ var merge2 = (from, to, rel, moved) => {
16388
16530
  }
16389
16531
  if (!isDir(from) || !isDir(to))
16390
16532
  return [rel];
16391
- const kept = fs5.readdirSync(from).flatMap((name) => merge2(path9.join(from, name), path9.join(to, name), `${rel}/${name}`, moved));
16533
+ const kept = fs5.readdirSync(from).flatMap((name) => merge2(path10.join(from, name), path10.join(to, name), `${rel}/${name}`, moved));
16392
16534
  try {
16393
16535
  if (fs5.readdirSync(from).length === 0)
16394
16536
  fs5.rmdirSync(from);
@@ -16467,38 +16609,38 @@ var takeMoveLock = (target) => {
16467
16609
  pause(25);
16468
16610
  }
16469
16611
  };
16470
- var canonical3 = (dir) => {
16612
+ var canonical4 = (dir) => {
16471
16613
  try {
16472
16614
  return fs5.realpathSync.native(dir);
16473
16615
  } catch {
16474
- return path9.resolve(dir);
16616
+ return path10.resolve(dir);
16475
16617
  }
16476
16618
  };
16477
16619
  var below = (parent, child) => {
16478
- const rel = path9.relative(parent, child);
16479
- return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
16620
+ const rel = path10.relative(parent, child);
16621
+ return rel !== "" && !rel.startsWith("..") && !path10.isAbsolute(rel);
16480
16622
  };
16481
- var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical3(tempDir), canonical3(dir));
16623
+ var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical4(tempDir), canonical4(dir));
16482
16624
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
16483
16625
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
16484
16626
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
16485
16627
  return null;
16486
- const real = canonical3(folder);
16487
- const tmp = canonical3(tempDir);
16628
+ const real = canonical4(folder);
16629
+ const tmp = canonical4(tempDir);
16488
16630
  if (insideTempDir(folder, tempDir))
16489
16631
  return null;
16490
- return `workit test run (WORKIT_TEST_RUN): refusing to move ${path9.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
16632
+ return `workit test run (WORKIT_TEST_RUN): refusing to move ${path10.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)`;
16491
16633
  };
16492
16634
  function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
16493
16635
  `)) {
16494
- const workit = path9.join(folder, ".workit");
16636
+ const workit = path10.join(folder, ".workit");
16495
16637
  const names = strayEntries(workit);
16496
16638
  const refusal = testRunFolderRefusal(folder, names.length > 0);
16497
16639
  if (refusal) {
16498
16640
  const run = process.env.WORKIT_TEST_RUN ?? "";
16499
- if (path9.isAbsolute(run))
16641
+ if (path10.isAbsolute(run))
16500
16642
  try {
16501
- fs5.appendFileSync(path9.join(run, TEST_RUN_REFUSALS), `${refusal}
16643
+ fs5.appendFileSync(path10.join(run, TEST_RUN_REFUSALS), `${refusal}
16502
16644
  `);
16503
16645
  } catch {}
16504
16646
  throw new Error(refusal);
@@ -16506,7 +16648,7 @@ function migrateFolderStore(folder, target, note = (line) => process.stderr.writ
16506
16648
  if (names.length === 0 || v2Workspace(workit) === true)
16507
16649
  return null;
16508
16650
  try {
16509
- fs5.mkdirSync(path9.dirname(target), { recursive: true });
16651
+ fs5.mkdirSync(path10.dirname(target), { recursive: true });
16510
16652
  } catch {
16511
16653
  return null;
16512
16654
  }
@@ -16530,7 +16672,7 @@ function moveLocked(workit, target, note) {
16530
16672
  }
16531
16673
  const result = { from: workit, to: target, moved: [], kept: [] };
16532
16674
  for (const name of names) {
16533
- result.kept.push(...merge2(path9.join(workit, name), path9.join(target, name), name, result.moved));
16675
+ result.kept.push(...merge2(path10.join(workit, name), path10.join(target, name), name, result.moved));
16534
16676
  }
16535
16677
  const left = (() => {
16536
16678
  try {
@@ -16539,13 +16681,13 @@ function moveLocked(workit, target, note) {
16539
16681
  return [];
16540
16682
  }
16541
16683
  })();
16542
- const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path9.join(workit, name)));
16684
+ const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path10.join(workit, name)));
16543
16685
  if (!v2Left && result.kept.length === 0) {
16544
- fs5.rmSync(path9.join(workit, MARKER), { force: true });
16545
- if (generatedIgnore(path9.join(workit, ".gitignore")))
16546
- fs5.rmSync(path9.join(workit, ".gitignore"), { force: true });
16686
+ fs5.rmSync(path10.join(workit, MARKER), { force: true });
16687
+ if (generatedIgnore(path10.join(workit, ".gitignore")))
16688
+ fs5.rmSync(path10.join(workit, ".gitignore"), { force: true });
16547
16689
  }
16548
- const pointer = path9.join(workit, MOVED_POINTER);
16690
+ const pointer = path10.join(workit, MOVED_POINTER);
16549
16691
  let wrote = false;
16550
16692
  if (result.kept.length > 0) {
16551
16693
  const text = `Workit keeps this folder's state in ${target}.
@@ -16572,9 +16714,9 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
16572
16714
 
16573
16715
  // packages/workit-core/src/store/paths.ts
16574
16716
  import { spawnSync as spawnSync9 } from "node:child_process";
16575
- import { createHash as createHash6 } from "node:crypto";
16717
+ import { createHash as createHash7 } from "node:crypto";
16576
16718
  import fs6 from "node:fs";
16577
- import path10 from "node:path";
16719
+ import path11 from "node:path";
16578
16720
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
16579
16721
  var gitRun = (cwd, args) => {
16580
16722
  const run = spawnSync9("git", args, {
@@ -16599,7 +16741,7 @@ var gitRun = (cwd, args) => {
16599
16741
  missing: error?.code === "ENOENT"
16600
16742
  };
16601
16743
  };
16602
- var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
16744
+ var shortHash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 12);
16603
16745
  var real = (file) => {
16604
16746
  try {
16605
16747
  return fs6.realpathSync.native(file);
@@ -16616,14 +16758,14 @@ var DISCOVERY_ENV = [
16616
16758
  ];
16617
16759
  var isGitDir = (dir) => {
16618
16760
  try {
16619
- return fs6.statSync(path10.join(dir, "HEAD")).isFile() && fs6.statSync(path10.join(dir, "objects")).isDirectory() && fs6.statSync(path10.join(dir, "refs")).isDirectory();
16761
+ return fs6.statSync(path11.join(dir, "HEAD")).isFile() && fs6.statSync(path11.join(dir, "objects")).isDirectory() && fs6.statSync(path11.join(dir, "refs")).isDirectory();
16620
16762
  } catch {
16621
16763
  return false;
16622
16764
  }
16623
16765
  };
16624
16766
  var reftableRefs = (common) => {
16625
16767
  try {
16626
- return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path10.join(common, "config"), "utf8"));
16768
+ return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path11.join(common, "config"), "utf8"));
16627
16769
  } catch {
16628
16770
  return false;
16629
16771
  }
@@ -16643,7 +16785,7 @@ function fastGit(root) {
16643
16785
  if (device !== null && stat.dev !== device)
16644
16786
  return { kind: "none" };
16645
16787
  device = stat.dev;
16646
- const dotGit = path10.join(dir, ".git");
16788
+ const dotGit = path11.join(dir, ".git");
16647
16789
  let entry = null;
16648
16790
  try {
16649
16791
  entry = fs6.statSync(dotGit);
@@ -16664,19 +16806,19 @@ function fastGit(root) {
16664
16806
  const match = /^gitdir: (.+)$/mu.exec(text);
16665
16807
  if (!match)
16666
16808
  return null;
16667
- gitDir = path10.resolve(dir, match[1].trim());
16809
+ gitDir = path11.resolve(dir, match[1].trim());
16668
16810
  } else
16669
16811
  return null;
16670
- if (!fs6.existsSync(path10.join(gitDir, "HEAD")))
16812
+ if (!fs6.existsSync(path11.join(gitDir, "HEAD")))
16671
16813
  return null;
16672
16814
  } else if (isGitDir(dir))
16673
16815
  gitDir = dir;
16674
16816
  if (gitDir) {
16675
16817
  let common = gitDir;
16676
16818
  try {
16677
- common = path10.resolve(gitDir, fs6.readFileSync(path10.join(gitDir, "commondir"), "utf8").trim());
16819
+ common = path11.resolve(gitDir, fs6.readFileSync(path11.join(gitDir, "commondir"), "utf8").trim());
16678
16820
  } catch {}
16679
- if (!fs6.existsSync(path10.join(common, "objects")))
16821
+ if (!fs6.existsSync(path11.join(common, "objects")))
16680
16822
  return null;
16681
16823
  return {
16682
16824
  kind: "repo",
@@ -16686,7 +16828,7 @@ function fastGit(root) {
16686
16828
  reftable: reftableRefs(common)
16687
16829
  };
16688
16830
  }
16689
- const parent = path10.dirname(dir);
16831
+ const parent = path11.dirname(dir);
16690
16832
  if (parent === dir)
16691
16833
  return { kind: "none" };
16692
16834
  dir = parent;
@@ -16698,7 +16840,7 @@ var outsideGit = (root) => {
16698
16840
  return { dir, shared: false, top: null };
16699
16841
  };
16700
16842
  function resolveStore(root) {
16701
- root = path10.resolve(root);
16843
+ root = path11.resolve(root);
16702
16844
  let stat = null;
16703
16845
  try {
16704
16846
  stat = fs6.statSync(root);
@@ -16706,13 +16848,13 @@ function resolveStore(root) {
16706
16848
  if (!stat)
16707
16849
  return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
16708
16850
  if (!stat.isDirectory())
16709
- return { dir: path10.join(root, ".workit"), shared: false, top: null };
16851
+ return { dir: path11.join(root, ".workit"), shared: false, top: null };
16710
16852
  const fast = fastGit(root);
16711
16853
  if (fast?.kind === "none")
16712
16854
  return outsideGit(root);
16713
16855
  if (fast?.kind === "repo")
16714
16856
  return {
16715
- dir: path10.join(fast.common, "workit"),
16857
+ dir: path11.join(fast.common, "workit"),
16716
16858
  shared: true,
16717
16859
  top: fast.top,
16718
16860
  git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
@@ -16722,7 +16864,7 @@ function resolveStore(root) {
16722
16864
  if (run.ok && common) {
16723
16865
  const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
16724
16866
  return {
16725
- dir: path10.join(real(path10.resolve(root, common)), "workit"),
16867
+ dir: path11.join(real(path11.resolve(root, common)), "workit"),
16726
16868
  shared: true,
16727
16869
  top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
16728
16870
  };
@@ -16735,7 +16877,7 @@ function resolveStore(root) {
16735
16877
  var rebasingBranch = (gitDir) => {
16736
16878
  for (const state of ["rebase-merge", "rebase-apply"]) {
16737
16879
  try {
16738
- const ref = fs6.readFileSync(path10.join(gitDir, state, "head-name"), "utf8").trim();
16880
+ const ref = fs6.readFileSync(path11.join(gitDir, state, "head-name"), "utf8").trim();
16739
16881
  const match = /^refs\/heads\/(.+)$/u.exec(ref);
16740
16882
  if (match)
16741
16883
  return match[1];
@@ -16750,7 +16892,7 @@ function resolveTaskKey(root, location) {
16750
16892
  if (location.git && !location.git.reftable) {
16751
16893
  let head = "";
16752
16894
  try {
16753
- head = fs6.readFileSync(path10.join(location.git.gitDir, "HEAD"), "utf8").trim();
16895
+ head = fs6.readFileSync(path11.join(location.git.gitDir, "HEAD"), "utf8").trim();
16754
16896
  } catch {}
16755
16897
  const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
16756
16898
  if (ref && ref[1] !== ".invalid")
@@ -16781,7 +16923,7 @@ function resolveTaskKey(root, location) {
16781
16923
  return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
16782
16924
  }
16783
16925
  function checkoutRootOf(root, location) {
16784
- const resolved = path10.resolve(root);
16926
+ const resolved = path11.resolve(root);
16785
16927
  let canonical = resolved;
16786
16928
  try {
16787
16929
  canonical = fs6.realpathSync(resolved);
@@ -16812,13 +16954,13 @@ function branchRenames(location) {
16812
16954
  }
16813
16955
  for (const entry of entries)
16814
16956
  if (entry.isDirectory())
16815
- walk(path10.join(dir, entry.name));
16957
+ walk(path11.join(dir, entry.name));
16816
16958
  else
16817
- files.push(path10.join(dir, entry.name));
16959
+ files.push(path11.join(dir, entry.name));
16818
16960
  };
16819
- walk(path10.join(path10.dirname(location.dir), "logs", "refs", "heads"));
16961
+ walk(path11.join(path11.dirname(location.dir), "logs", "refs", "heads"));
16820
16962
  if (location.git)
16821
- files.push(path10.join(location.git.gitDir, "logs", "HEAD"));
16963
+ files.push(path11.join(location.git.gitDir, "logs", "HEAD"));
16822
16964
  const seen = new Set;
16823
16965
  const renames = [];
16824
16966
  for (const file of files) {
@@ -16884,13 +17026,13 @@ function hostSessionFromEnv(env) {
16884
17026
  }
16885
17027
  return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
16886
17028
  }
16887
- var hash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 32);
17029
+ var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
16888
17030
  var PIN_FILE = "issued-registry";
16889
17031
  var pinFiles = new Map;
16890
17032
  var pinFile = (cwd) => {
16891
17033
  if (cwd === undefined)
16892
17034
  return null;
16893
- const key = path11.resolve(cwd);
17035
+ const key = path12.resolve(cwd);
16894
17036
  const known = pinFiles.get(key);
16895
17037
  if (known !== undefined)
16896
17038
  return known;
@@ -16898,7 +17040,7 @@ var pinFile = (cwd) => {
16898
17040
  const location = resolveStore(key);
16899
17041
  if (location instanceof Error)
16900
17042
  return null;
16901
- const file = location.shared ? path11.join(location.dir, "ledger", PIN_FILE) : null;
17043
+ const file = location.shared ? path12.join(location.dir, "ledger", PIN_FILE) : null;
16902
17044
  pinFiles.set(key, file);
16903
17045
  return file;
16904
17046
  } catch {
@@ -16911,14 +17053,14 @@ var pinnedStateDir = (cwd) => {
16911
17053
  return null;
16912
17054
  try {
16913
17055
  const pinned = fs7.readFileSync(file, "utf8").trim();
16914
- return path11.isAbsolute(pinned) ? pinned : null;
17056
+ return path12.isAbsolute(pinned) ? pinned : null;
16915
17057
  } catch {
16916
17058
  return null;
16917
17059
  }
16918
17060
  };
16919
17061
  var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
16920
- var userIssuedRoot = (cwd) => path11.join(registryDir(cwd), "issued");
16921
- var userTokenRoot = (cwd) => path11.join(registryDir(cwd), "issued-tokens");
17062
+ var userIssuedRoot = (cwd) => path12.join(registryDir(cwd), "issued");
17063
+ var userTokenRoot = (cwd) => path12.join(registryDir(cwd), "issued-tokens");
16922
17064
  function migrateRepoIssued(cwd) {
16923
17065
  if (cwd === undefined)
16924
17066
  return;
@@ -16927,7 +17069,7 @@ function migrateRepoIssued(cwd) {
16927
17069
  const location = resolveStore(cwd);
16928
17070
  if (location instanceof Error)
16929
17071
  return;
16930
- old = path11.join(location.dir, "hooks", "issued");
17072
+ old = path12.join(location.dir, "hooks", "issued");
16931
17073
  if (!fs7.existsSync(old))
16932
17074
  return;
16933
17075
  } catch {
@@ -16935,19 +17077,19 @@ function migrateRepoIssued(cwd) {
16935
17077
  }
16936
17078
  for (const lead of safeList(old)) {
16937
17079
  try {
16938
- const from = path11.join(old, lead);
17080
+ const from = path12.join(old, lead);
16939
17081
  if (!fs7.statSync(from).isDirectory())
16940
17082
  continue;
16941
- const to = path11.join(userIssuedRoot(cwd), lead);
17083
+ const to = path12.join(userIssuedRoot(cwd), lead);
16942
17084
  fs7.mkdirSync(to, { recursive: true, mode: 448 });
16943
17085
  for (const id of fs7.readdirSync(from)) {
16944
17086
  try {
16945
- fs7.copyFileSync(path11.join(from, id), path11.join(to, id), fs7.constants.COPYFILE_EXCL);
17087
+ fs7.copyFileSync(path12.join(from, id), path12.join(to, id), fs7.constants.COPYFILE_EXCL);
16946
17088
  } catch (error) {
16947
17089
  if (error.code !== "EEXIST")
16948
17090
  throw error;
16949
17091
  }
16950
- fs7.rmSync(path11.join(from, id), { force: true });
17092
+ fs7.rmSync(path12.join(from, id), { force: true });
16951
17093
  }
16952
17094
  removeIfEmpty(from);
16953
17095
  } catch {}
@@ -16972,7 +17114,7 @@ var issuedRecord = (cwd, claimed) => {
16972
17114
  return null;
16973
17115
  migrateRepoIssued(cwd);
16974
17116
  try {
16975
- return fs7.readFileSync(path11.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
17117
+ return fs7.readFileSync(path12.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
16976
17118
  } catch {
16977
17119
  return null;
16978
17120
  }
@@ -16982,9 +17124,9 @@ var issuedToken = (cwd, claimed) => {
16982
17124
  const cut = claimed.lastIndexOf(":");
16983
17125
  if (cut <= 0)
16984
17126
  return { stored: null, leadBound: false };
16985
- const dir = path11.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
17127
+ const dir = path12.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
16986
17128
  try {
16987
- const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
17129
+ const text = fs7.readFileSync(path12.join(dir, hash(claimed)), "utf8");
16988
17130
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
16989
17131
  } catch {
16990
17132
  return { stored: null, leadBound: safeList(dir).length > 0 };
@@ -17004,7 +17146,7 @@ var OWN_CHILD_SHELL = new Set(["opencode", "pi"]);
17004
17146
  // packages/workit-core/src/store/event-log.ts
17005
17147
  import { randomUUID as randomUUID2 } from "node:crypto";
17006
17148
  import fs8 from "node:fs";
17007
- import path12 from "node:path";
17149
+ import path13 from "node:path";
17008
17150
  var EVENT_VERSION = 1;
17009
17151
 
17010
17152
  class LogDamage extends Error {
@@ -17115,7 +17257,7 @@ function appendEvent(file, event, validEnd) {
17115
17257
  fs8.closeSync(fd);
17116
17258
  }
17117
17259
  if (created)
17118
- fsyncDirectory(path12.dirname(file));
17260
+ fsyncDirectory(path13.dirname(file));
17119
17261
  return validEnd;
17120
17262
  }
17121
17263
  function replaceFile(file, bytes, durable) {
@@ -17131,7 +17273,7 @@ function replaceFile(file, bytes, durable) {
17131
17273
  }
17132
17274
  renameWithRetry(temporary, file);
17133
17275
  if (durable)
17134
- fsyncDirectory(path12.dirname(file));
17276
+ fsyncDirectory(path13.dirname(file));
17135
17277
  } catch (error) {
17136
17278
  try {
17137
17279
  fs8.unlinkSync(temporary);
@@ -17288,7 +17430,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
17288
17430
  });
17289
17431
 
17290
17432
  // packages/workit-core/src/store/reduce.ts
17291
- import { createHash as createHash8 } from "node:crypto";
17433
+ import { createHash as createHash9 } from "node:crypto";
17292
17434
  var OPENING_TYPES = new Set([
17293
17435
  "task.opened",
17294
17436
  "task.imported",
@@ -17317,7 +17459,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
17317
17459
  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");
17318
17460
  var BLOB_REF = "$blob";
17319
17461
  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;
17320
- var blobDigest = (value) => createHash8("sha256").update(JSON.stringify(value)).digest("hex");
17462
+ var blobDigest = (value) => createHash9("sha256").update(JSON.stringify(value)).digest("hex");
17321
17463
  var toBlob = (value, blobs) => {
17322
17464
  if (!isObject4(value))
17323
17465
  return value;
@@ -17432,7 +17574,7 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
17432
17574
  // packages/workit-core/src/core/task-read.ts
17433
17575
  import { randomUUID as randomUUID3 } from "node:crypto";
17434
17576
  import * as fs13 from "node:fs";
17435
- import path16 from "node:path";
17577
+ import path17 from "node:path";
17436
17578
 
17437
17579
  // node_modules/@openclaw/fs-safe/dist/errors.js
17438
17580
  var OPERATIONAL_CODES = new Set([
@@ -17483,7 +17625,7 @@ function sameFileIdentity(left, right, platform = process.platform) {
17483
17625
  // node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
17484
17626
  import { randomBytes as randomBytes2 } from "node:crypto";
17485
17627
  import fsSync from "node:fs";
17486
- import path13 from "node:path";
17628
+ import path14 from "node:path";
17487
17629
 
17488
17630
  // node_modules/@openclaw/fs-safe/dist/bounded-read.js
17489
17631
  import fs9 from "node:fs";
@@ -17573,13 +17715,13 @@ ${ownershipToken}
17573
17715
  return { raw, ownershipToken };
17574
17716
  }
17575
17717
  function relativeSidecarLockPath(lockRoot, lockPath) {
17576
- const resolved = path13.resolve(lockPath);
17577
- const lexicalRelative = path13.relative(lockRoot.rootDir, resolved);
17578
- const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path13.sep}`) && !path13.isAbsolute(lexicalRelative) ? lexicalRelative : path13.relative(lockRoot.rootReal, resolved);
17579
- if (!relative || relative === ".." || relative.startsWith(`..${path13.sep}`) || path13.isAbsolute(relative)) {
17718
+ const resolved = path14.resolve(lockPath);
17719
+ const lexicalRelative = path14.relative(lockRoot.rootDir, resolved);
17720
+ const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path14.sep}`) && !path14.isAbsolute(lexicalRelative) ? lexicalRelative : path14.relative(lockRoot.rootReal, resolved);
17721
+ if (!relative || relative === ".." || relative.startsWith(`..${path14.sep}`) || path14.isAbsolute(relative)) {
17580
17722
  throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
17581
17723
  }
17582
- return relative.split(path13.sep).join(path13.posix.sep);
17724
+ return relative.split(path14.sep).join(path14.posix.sep);
17583
17725
  }
17584
17726
  function parseSidecarLockPayload(raw, parser) {
17585
17727
  if (parser) {
@@ -17726,7 +17868,7 @@ function getFsSafeLockConfig() {
17726
17868
 
17727
17869
  // node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
17728
17870
  import fs11 from "node:fs";
17729
- import path14 from "node:path";
17871
+ import path15 from "node:path";
17730
17872
 
17731
17873
  // node_modules/@openclaw/fs-safe/dist/timing.js
17732
17874
  function sleepSync(ms) {
@@ -17817,26 +17959,26 @@ function canonicalLockParentSync(parent) {
17817
17959
  return process.platform === "win32" ? fs11.realpathSync.native(parent) : fs11.realpathSync(parent);
17818
17960
  }
17819
17961
  function normalizeTargetPath(targetPath) {
17820
- const resolved = path14.resolve(targetPath);
17821
- fs11.mkdirSync(path14.dirname(resolved), { recursive: true });
17962
+ const resolved = path15.resolve(targetPath);
17963
+ fs11.mkdirSync(path15.dirname(resolved), { recursive: true });
17822
17964
  try {
17823
- return path14.join(canonicalLockParentSync(path14.dirname(resolved)), path14.basename(resolved));
17965
+ return path15.join(canonicalLockParentSync(path15.dirname(resolved)), path15.basename(resolved));
17824
17966
  } catch {
17825
17967
  return resolved;
17826
17968
  }
17827
17969
  }
17828
17970
  function boundedLockPath(lockPath, lockRoot) {
17829
- const resolved = path14.resolve(lockPath);
17971
+ const resolved = path15.resolve(lockPath);
17830
17972
  if (!lockRoot)
17831
17973
  return resolved;
17832
17974
  relativeSidecarLockPath(lockRoot, resolved);
17833
- const parent = path14.dirname(resolved);
17975
+ const parent = path15.dirname(resolved);
17834
17976
  const parentReal = canonicalLockParentSync(parent);
17835
- const parentRelative = path14.relative(lockRoot.rootReal, parentReal);
17836
- if (parentRelative === ".." || parentRelative.startsWith(`..${path14.sep}`) || path14.isAbsolute(parentRelative)) {
17977
+ const parentRelative = path15.relative(lockRoot.rootReal, parentReal);
17978
+ if (parentRelative === ".." || parentRelative.startsWith(`..${path15.sep}`) || path15.isAbsolute(parentRelative)) {
17837
17979
  throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
17838
17980
  }
17839
- return path14.join(parentReal, path14.basename(resolved));
17981
+ return path15.join(parentReal, path15.basename(resolved));
17840
17982
  }
17841
17983
  function defaultShouldReclaim(snapshot, staleMs, nowMs) {
17842
17984
  const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
@@ -18037,20 +18179,20 @@ function acquireFileLockSync(targetPath, options) {
18037
18179
  }
18038
18180
  // packages/workit-core/src/core/package-root.ts
18039
18181
  import { existsSync as existsSync5 } from "node:fs";
18040
- import path15 from "node:path";
18182
+ import path16 from "node:path";
18041
18183
  import { fileURLToPath } from "node:url";
18042
18184
  var packageRoot = () => {
18043
- let dir = path15.dirname(fileURLToPath(import.meta.url));
18185
+ let dir = path16.dirname(fileURLToPath(import.meta.url));
18044
18186
  while (true) {
18045
- const parent = path15.dirname(dir);
18046
- if (existsSync5(path15.join(dir, "package.json")) || parent === dir)
18187
+ const parent = path16.dirname(dir);
18188
+ if (existsSync5(path16.join(dir, "package.json")) || parent === dir)
18047
18189
  return dir;
18048
18190
  dir = parent;
18049
18191
  }
18050
18192
  };
18051
18193
  var assetRoot = () => {
18052
18194
  const root = packageRoot();
18053
- const assets = path15.join(root, "assets");
18195
+ const assets = path16.join(root, "assets");
18054
18196
  return existsSync5(assets) ? assets : root;
18055
18197
  };
18056
18198
 
@@ -18258,7 +18400,7 @@ var cachedRuntimeVersion = null;
18258
18400
  var runtimeVersion = () => {
18259
18401
  if (cachedRuntimeVersion === null) {
18260
18402
  try {
18261
- const pkg = JSON.parse(fs13.readFileSync(path16.join(packageRoot(), "package.json"), "utf8"));
18403
+ const pkg = JSON.parse(fs13.readFileSync(path17.join(packageRoot(), "package.json"), "utf8"));
18262
18404
  cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
18263
18405
  } catch {
18264
18406
  cachedRuntimeVersion = "0.0.0";
@@ -18287,7 +18429,7 @@ var readText2 = (file) => {
18287
18429
  };
18288
18430
  var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
18289
18431
  var branchStart = (location, branch, aliases) => {
18290
- const first = readText2(path16.join(path16.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
18432
+ const first = readText2(path17.join(path17.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
18291
18433
  `, 1)[0];
18292
18434
  const created = REFLOG_LINE.exec(first);
18293
18435
  const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
@@ -18297,7 +18439,7 @@ var branchStart = (location, branch, aliases) => {
18297
18439
  return start;
18298
18440
  if (!location.git)
18299
18441
  return null;
18300
- for (const line of readText2(path16.join(location.git.gitDir, "logs", "HEAD")).split(`
18442
+ for (const line of readText2(path17.join(location.git.gitDir, "logs", "HEAD")).split(`
18301
18443
  `)) {
18302
18444
  const entry = REFLOG_LINE.exec(line);
18303
18445
  const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
@@ -18307,14 +18449,14 @@ var branchStart = (location, branch, aliases) => {
18307
18449
  }
18308
18450
  return null;
18309
18451
  };
18310
- var refExists2 = (common, ref) => fs13.existsSync(path16.join(common, ref)) || readText2(path16.join(common, "packed-refs")).includes(` ${ref}
18452
+ var refExists2 = (common, ref) => fs13.existsSync(path17.join(common, ref)) || readText2(path17.join(common, "packed-refs")).includes(` ${ref}
18311
18453
  `);
18312
18454
  var origins = new Map;
18313
18455
  var sameDirectoryIdentity = (left, right) => {
18314
- if (!path16.isAbsolute(left) || !path16.isAbsolute(right))
18456
+ if (!path17.isAbsolute(left) || !path17.isAbsolute(right))
18315
18457
  return false;
18316
- const normalizedLeft = path16.resolve(left);
18317
- const normalizedRight = path16.resolve(right);
18458
+ const normalizedLeft = path17.resolve(left);
18459
+ const normalizedRight = path17.resolve(right);
18318
18460
  try {
18319
18461
  const a = fs13.statSync(normalizedLeft, { bigint: true });
18320
18462
  const b = fs13.statSync(normalizedRight, { bigint: true });
@@ -18348,14 +18490,14 @@ class TaskReader {
18348
18490
  located;
18349
18491
  migrationChecked = false;
18350
18492
  constructor(root, options = {}) {
18351
- const resolved = path16.resolve(root);
18493
+ const resolved = path17.resolve(root);
18352
18494
  this.origin = fs13.existsSync(resolved) ? fs13.realpathSync(resolved) : resolved;
18353
18495
  this.located = resolveStore(this.origin);
18354
18496
  this.root = checkoutRootOf(this.origin, this.located);
18355
18497
  this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
18356
18498
  }
18357
18499
  location() {
18358
- if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path16.join(this.root, ".git"))) {
18500
+ if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path17.join(this.root, ".git"))) {
18359
18501
  this.located = undefined;
18360
18502
  this.migrationChecked = false;
18361
18503
  }
@@ -18513,14 +18655,14 @@ class TaskReader {
18513
18655
  const branch = key.ok ? key.data.branch : null;
18514
18656
  if (!branch || !location.ok)
18515
18657
  return success(null, null, null);
18516
- const common = path16.dirname(location.data.dir);
18517
- const heads = path16.join(common, "logs", "refs", "heads");
18518
- const headLog = location.data.git ? path16.join(location.data.git.gitDir, "logs", "HEAD") : "";
18658
+ const common = path17.dirname(location.data.dir);
18659
+ const heads = path17.join(common, "logs", "refs", "heads");
18660
+ const headLog = location.data.git ? path17.join(location.data.git.gitDir, "logs", "HEAD") : "";
18519
18661
  const signatures = [
18520
- path16.join(heads, branch),
18662
+ path17.join(heads, branch),
18521
18663
  headLog,
18522
18664
  heads,
18523
- path16.join(common, "packed-refs")
18665
+ path17.join(common, "packed-refs")
18524
18666
  ].map((file) => fileSignature(file) ?? "-");
18525
18667
  const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
18526
18668
  let resolved = origins.get(slot);
@@ -18532,7 +18674,7 @@ class TaskReader {
18532
18674
  aliases.push(rename.from);
18533
18675
  const start = branchStart(location.data, branch, aliases);
18534
18676
  const slash = start?.indexOf("/") ?? -1;
18535
- const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path16.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
18677
+ const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path17.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
18536
18678
  const name = start && (remote ? start.slice(slash + 1) : start);
18537
18679
  resolved = {
18538
18680
  signature: signatures.join("|"),
@@ -18552,27 +18694,27 @@ class TaskReader {
18552
18694
  }
18553
18695
  paths() {
18554
18696
  const location = this.location();
18555
- const dir = location.ok ? location.data.dir : path16.join(this.root, ".workit");
18556
- const checkout = path16.join(dir, "checkouts", checkoutSlug(this.root));
18697
+ const dir = location.ok ? location.data.dir : path17.join(this.root, ".workit");
18698
+ const checkout = path17.join(dir, "checkouts", checkoutSlug(this.root));
18557
18699
  return {
18558
18700
  dir,
18559
18701
  shared: location.ok ? location.data.shared : false,
18560
- marker: path16.join(dir, "store.json"),
18702
+ marker: path17.join(dir, "store.json"),
18561
18703
  checkout,
18562
- workspace: path16.join(checkout, "workspace.json"),
18563
- checkoutLock: path16.join(checkout, "metadata.lock"),
18564
- tasks: path16.join(dir, "tasks"),
18565
- index: path16.join(dir, "task-index.json"),
18566
- blobs: path16.join(dir, "blobs", "candidates"),
18567
- legacy: path16.join(dir, "legacy", checkoutSlug(this.root), "v2"),
18568
- v2: path16.join(this.root, ".workit")
18704
+ workspace: path17.join(checkout, "workspace.json"),
18705
+ checkoutLock: path17.join(checkout, "metadata.lock"),
18706
+ tasks: path17.join(dir, "tasks"),
18707
+ index: path17.join(dir, "task-index.json"),
18708
+ blobs: path17.join(dir, "blobs", "candidates"),
18709
+ legacy: path17.join(dir, "legacy", checkoutSlug(this.root), "v2"),
18710
+ v2: path17.join(this.root, ".workit")
18569
18711
  };
18570
18712
  }
18571
18713
  eventsPath(taskId) {
18572
- return path16.join(this.paths().tasks, taskId, "events.jsonl");
18714
+ return path17.join(this.paths().tasks, taskId, "events.jsonl");
18573
18715
  }
18574
18716
  snapshotPath(taskId) {
18575
- return path16.join(this.paths().tasks, taskId, "snapshot.json");
18717
+ return path17.join(this.paths().tasks, taskId, "snapshot.json");
18576
18718
  }
18577
18719
  ready(write = false) {
18578
18720
  const location = this.location();
@@ -18607,7 +18749,7 @@ class TaskReader {
18607
18749
  return {
18608
18750
  read: (digest) => {
18609
18751
  try {
18610
- return JSON.parse(fs13.readFileSync(path16.join(dir, `${digest}.json`), "utf8"));
18752
+ return JSON.parse(fs13.readFileSync(path17.join(dir, `${digest}.json`), "utf8"));
18611
18753
  } catch (error) {
18612
18754
  throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
18613
18755
  }
@@ -18773,11 +18915,11 @@ class TaskReader {
18773
18915
  return failure2("recovery_required", `${label} record does not satisfy its schema`);
18774
18916
  }
18775
18917
  v2Dirs() {
18776
- return [...new Set([this.root, this.origin])].map((dir) => path16.join(dir, ".workit"));
18918
+ return [...new Set([this.root, this.origin])].map((dir) => path17.join(dir, ".workit"));
18777
18919
  }
18778
18920
  pendingMigrations() {
18779
18921
  return this.v2Dirs().filter((dir) => {
18780
- const raw = this.readV2Workspace(path16.join(dir, "workspace.json"));
18922
+ const raw = this.readV2Workspace(path17.join(dir, "workspace.json"));
18781
18923
  return raw !== null && raw !== TOMBSTONE;
18782
18924
  });
18783
18925
  }
@@ -18793,7 +18935,7 @@ class TaskReader {
18793
18935
  }
18794
18936
  adoptStoreFrom(local) {
18795
18937
  const dirs = this.paths();
18796
- const marker = path16.join(local, "store.json");
18938
+ const marker = path17.join(local, "store.json");
18797
18939
  if (!fs13.existsSync(marker))
18798
18940
  return success(null, null, null);
18799
18941
  return this.withLock(dirs.checkoutLock, () => {
@@ -18803,7 +18945,7 @@ class TaskReader {
18803
18945
  try {
18804
18946
  const merge = (from, to) => {
18805
18947
  if (!fs13.existsSync(to)) {
18806
- fs13.mkdirSync(path16.dirname(to), { recursive: true });
18948
+ fs13.mkdirSync(path17.dirname(to), { recursive: true });
18807
18949
  try {
18808
18950
  fs13.renameSync(from, to);
18809
18951
  } catch {
@@ -18814,24 +18956,24 @@ class TaskReader {
18814
18956
  }
18815
18957
  if (fs13.lstatSync(from).isDirectory() && fs13.lstatSync(to).isDirectory())
18816
18958
  for (const name of fs13.readdirSync(from))
18817
- merge(path16.join(from, name), path16.join(to, name));
18959
+ merge(path17.join(from, name), path17.join(to, name));
18818
18960
  };
18819
18961
  for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
18820
- const from = path16.join(local, sub);
18962
+ const from = path17.join(local, sub);
18821
18963
  if (!fs13.existsSync(from))
18822
18964
  continue;
18823
18965
  if (sub === "tasks") {
18824
18966
  for (const name of fs13.readdirSync(from))
18825
- if (validId(name) && !fs13.existsSync(path16.join(dirs.dir, sub, name)))
18967
+ if (validId(name) && !fs13.existsSync(path17.join(dirs.dir, sub, name)))
18826
18968
  tasks += 1;
18827
18969
  }
18828
- merge(from, path16.join(dirs.dir, sub));
18970
+ merge(from, path17.join(dirs.dir, sub));
18829
18971
  }
18830
- const ledger = path16.join(local, "ledger");
18831
- if (fs13.existsSync(ledger) && !fs13.existsSync(path16.join(dirs.dir, "ledger")))
18832
- merge(ledger, path16.join(dirs.dir, "ledger"));
18833
- fs13.rmSync(path16.join(local, "task-index.json"), { force: true });
18834
- fs13.renameSync(marker, path16.join(local, "store.moved.json"));
18972
+ const ledger = path17.join(local, "ledger");
18973
+ if (fs13.existsSync(ledger) && !fs13.existsSync(path17.join(dirs.dir, "ledger")))
18974
+ merge(ledger, path17.join(dirs.dir, "ledger"));
18975
+ fs13.rmSync(path17.join(local, "task-index.json"), { force: true });
18976
+ fs13.renameSync(marker, path17.join(local, "store.moved.json"));
18835
18977
  } catch (error) {
18836
18978
  return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
18837
18979
  path: local
@@ -18869,7 +19011,7 @@ class TaskReader {
18869
19011
  schemaVersion: SCHEMA_VERSION,
18870
19012
  id: workspaceId ?? newId(),
18871
19013
  revision: newRevision(),
18872
- root: path16.dirname(v2),
19014
+ root: path17.dirname(v2),
18873
19015
  runtime: { createdWith: version, updatedWith: version },
18874
19016
  writer: null,
18875
19017
  store: {
@@ -18881,11 +19023,11 @@ class TaskReader {
18881
19023
  critical: ["store"]
18882
19024
  };
18883
19025
  fs13.mkdirSync(v2, { recursive: true });
18884
- const ignore = path16.join(v2, ".gitignore");
19026
+ const ignore = path17.join(v2, ".gitignore");
18885
19027
  if (!fs13.existsSync(ignore))
18886
19028
  fs13.writeFileSync(ignore, `*
18887
19029
  `);
18888
- replaceFile(path16.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
19030
+ replaceFile(path17.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
18889
19031
  `, true);
18890
19032
  }
18891
19033
  initializeStorage() {
@@ -18944,7 +19086,7 @@ class TaskReader {
18944
19086
  withLock(lockPath, operation) {
18945
19087
  try {
18946
19088
  this.initializeStorage();
18947
- fs13.mkdirSync(path16.dirname(lockPath), { recursive: true });
19089
+ fs13.mkdirSync(path17.dirname(lockPath), { recursive: true });
18948
19090
  } catch (error) {
18949
19091
  return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
18950
19092
  path: this.paths().dir
@@ -19007,7 +19149,7 @@ class TaskReader {
19007
19149
  if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
19008
19150
  return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
19009
19151
  path: lockPath,
19010
- guidance: `Check permissions and the read-only attribute on ${path16.dirname(lockPath)}.`
19152
+ guidance: `Check permissions and the read-only attribute on ${path17.dirname(lockPath)}.`
19011
19153
  });
19012
19154
  if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
19013
19155
  let lock = null;
@@ -19062,7 +19204,7 @@ var moveInto = (from, to) => {
19062
19204
  target = `${to}.dir`;
19063
19205
  fs14.mkdirSync(target, { recursive: true });
19064
19206
  for (const name of fs14.readdirSync(from))
19065
- moveInto(path17.join(from, name), path17.join(target, name));
19207
+ moveInto(path18.join(from, name), path18.join(target, name));
19066
19208
  fs14.rmdirSync(from);
19067
19209
  return;
19068
19210
  }
@@ -19073,13 +19215,13 @@ var moveInto = (from, to) => {
19073
19215
  fs14.rmSync(from);
19074
19216
  return;
19075
19217
  }
19076
- target = `${to}.${createHash9("sha256").update(bytes).digest("hex").slice(0, 12)}`;
19218
+ target = `${to}.${createHash10("sha256").update(bytes).digest("hex").slice(0, 12)}`;
19077
19219
  if (fs14.existsSync(target)) {
19078
19220
  fs14.rmSync(from);
19079
19221
  return;
19080
19222
  }
19081
19223
  }
19082
- fs14.mkdirSync(path17.dirname(target), { recursive: true });
19224
+ fs14.mkdirSync(path18.dirname(target), { recursive: true });
19083
19225
  try {
19084
19226
  fs14.renameSync(from, target);
19085
19227
  } catch {
@@ -19147,7 +19289,7 @@ class TaskStore extends TaskReader {
19147
19289
  const moved = this.bindLocked(again.data.id, key, input.now);
19148
19290
  return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
19149
19291
  }
19150
- const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path17.basename(this.root) || this.root;
19292
+ const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path18.basename(this.root) || this.root;
19151
19293
  const intent = {
19152
19294
  objective: input.objective?.trim() || `Work on ${label}`,
19153
19295
  scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
@@ -19395,13 +19537,13 @@ class TaskStore extends TaskReader {
19395
19537
  if (!ready.ok)
19396
19538
  return ready;
19397
19539
  const dirs = this.paths();
19398
- const recovery = [path17.join(this.root, ".workit", "recovery"), path17.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
19540
+ const recovery = [path18.join(this.root, ".workit", "recovery"), path18.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
19399
19541
  if (recovery) {
19400
19542
  let files = 0;
19401
19543
  let bytes = 0;
19402
19544
  try {
19403
19545
  for (const name of fs14.readdirSync(recovery)) {
19404
- const stat = fs14.lstatSync(path17.join(recovery, name));
19546
+ const stat = fs14.lstatSync(path18.join(recovery, name));
19405
19547
  if (!stat.isFile())
19406
19548
  continue;
19407
19549
  files += 1;
@@ -19454,7 +19596,7 @@ class TaskStore extends TaskReader {
19454
19596
  if (fs14.existsSync(dirs.blobs))
19455
19597
  for (const name of fs14.readdirSync(dirs.blobs)) {
19456
19598
  const digest = name.replace(/\.json$/, "");
19457
- const file = path17.join(dirs.blobs, name);
19599
+ const file = path18.join(dirs.blobs, name);
19458
19600
  let stat;
19459
19601
  try {
19460
19602
  stat = fs14.lstatSync(file);
@@ -19472,7 +19614,7 @@ class TaskStore extends TaskReader {
19472
19614
  }
19473
19615
  return success(null, null, null);
19474
19616
  };
19475
- const swept = dryRun ? sweep() : this.withLock(path17.join(dirs.dir, "gc.lock"), sweep);
19617
+ const swept = dryRun ? sweep() : this.withLock(path18.join(dirs.dir, "gc.lock"), sweep);
19476
19618
  if (!swept.ok)
19477
19619
  return swept;
19478
19620
  const temporaryDirs = [
@@ -19480,7 +19622,7 @@ class TaskStore extends TaskReader {
19480
19622
  dirs.tasks,
19481
19623
  dirs.blobs,
19482
19624
  dirs.checkout,
19483
- ...names.map((name) => path17.join(dirs.tasks, name))
19625
+ ...names.map((name) => path18.join(dirs.tasks, name))
19484
19626
  ];
19485
19627
  for (const directory of temporaryDirs) {
19486
19628
  if (!fs14.existsSync(directory))
@@ -19488,7 +19630,7 @@ class TaskStore extends TaskReader {
19488
19630
  for (const name of fs14.readdirSync(directory)) {
19489
19631
  if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
19490
19632
  continue;
19491
- const file = path17.join(directory, name);
19633
+ const file = path18.join(directory, name);
19492
19634
  try {
19493
19635
  const stat = fs14.lstatSync(file);
19494
19636
  if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
@@ -19504,7 +19646,7 @@ class TaskStore extends TaskReader {
19504
19646
  return success(null, null, report);
19505
19647
  }
19506
19648
  taskLockPath(taskId) {
19507
- return path17.join(this.paths().tasks, taskId, "lock");
19649
+ return path18.join(this.paths().tasks, taskId, "lock");
19508
19650
  }
19509
19651
  settleMigrations(write) {
19510
19652
  const moved = this.adoptLocalStore();
@@ -19533,7 +19675,7 @@ class TaskStore extends TaskReader {
19533
19675
  return {
19534
19676
  read: (digest) => reader.read(digest),
19535
19677
  write: (digest, value) => {
19536
- const file = path17.join(dir, `${digest}.json`);
19678
+ const file = path18.join(dir, `${digest}.json`);
19537
19679
  if (fs14.existsSync(file)) {
19538
19680
  const stamp = new Date;
19539
19681
  try {
@@ -19635,7 +19777,7 @@ class TaskStore extends TaskReader {
19635
19777
  }
19636
19778
  }
19637
19779
  openTask(record, type, key, legacy = null) {
19638
- const dir = path17.join(this.paths().tasks, record.id);
19780
+ const dir = path18.join(this.paths().tasks, record.id);
19639
19781
  fs14.mkdirSync(dir, { recursive: true });
19640
19782
  const blobs = this.blobStore();
19641
19783
  const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
@@ -19715,8 +19857,8 @@ class TaskStore extends TaskReader {
19715
19857
  }
19716
19858
  }
19717
19859
  withKeyLock(key, operation) {
19718
- const digest = createHash9("sha256").update(key).digest("hex").slice(0, 32);
19719
- return this.withLock(path17.join(this.paths().dir, "keys", `${digest}.lock`), operation);
19860
+ const digest = createHash10("sha256").update(key).digest("hex").slice(0, 32);
19861
+ return this.withLock(path18.join(this.paths().dir, "keys", `${digest}.lock`), operation);
19720
19862
  }
19721
19863
  bindLocked(taskId, key, timestamp) {
19722
19864
  const current = this.readWorkspace();
@@ -19857,7 +19999,7 @@ class TaskStore extends TaskReader {
19857
19999
  writeWorkspace(record) {
19858
20000
  const file = this.paths().workspace;
19859
20001
  try {
19860
- fs14.mkdirSync(path17.dirname(file), { recursive: true });
20002
+ fs14.mkdirSync(path18.dirname(file), { recursive: true });
19861
20003
  replaceFile(file, `${canonicalJson(record)}
19862
20004
  `, true);
19863
20005
  return success(null, null, null);
@@ -19883,13 +20025,13 @@ class TaskStore extends TaskReader {
19883
20025
  }
19884
20026
  migrateV2(v2) {
19885
20027
  const dirs = this.paths();
19886
- const v2Workspace = path17.join(v2, "workspace.json");
19887
- const v2Tasks = path17.join(v2, "tasks");
19888
- const legacy = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
20028
+ const v2Workspace = path18.join(v2, "workspace.json");
20029
+ const v2Tasks = path18.join(v2, "tasks");
20030
+ const legacy = path18.join(dirs.dir, "legacy", checkoutSlug(path18.dirname(v2)), "v2");
19889
20031
  const raw = this.readV2Workspace(v2Workspace);
19890
20032
  if (raw === null || raw === TOMBSTONE)
19891
20033
  return success(null, null, null);
19892
- return this.withLock(dirs.checkoutLock, () => this.withLock(path17.join(v2, "metadata.lock"), () => {
20034
+ return this.withLock(dirs.checkoutLock, () => this.withLock(path18.join(v2, "metadata.lock"), () => {
19893
20035
  const workspace = this.readV2Workspace(v2Workspace);
19894
20036
  if (workspace === null || workspace === TOMBSTONE)
19895
20037
  return success(null, null, null);
@@ -19898,7 +20040,7 @@ class TaskStore extends TaskReader {
19898
20040
  return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
19899
20041
  let files = [];
19900
20042
  try {
19901
- files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path17.join(v2Tasks, name)));
20043
+ files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path18.join(v2Tasks, name)));
19902
20044
  } catch {}
19903
20045
  const current = this.readWorkspace();
19904
20046
  if (!current.ok)
@@ -19916,21 +20058,21 @@ class TaskStore extends TaskReader {
19916
20058
  let skipped = 0;
19917
20059
  const done = new Map;
19918
20060
  try {
19919
- fs14.mkdirSync(path17.join(legacy, "tasks"), { recursive: true });
20061
+ fs14.mkdirSync(path18.join(legacy, "tasks"), { recursive: true });
19920
20062
  for (const name of ["workspace.json", "index.json"])
19921
- if (fs14.existsSync(path17.join(v2, name)))
19922
- fs14.copyFileSync(path17.join(v2, name), path17.join(legacy, name));
20063
+ if (fs14.existsSync(path18.join(v2, name)))
20064
+ fs14.copyFileSync(path18.join(v2, name), path18.join(legacy, name));
19923
20065
  for (const name of files) {
19924
20066
  const id = name.slice(0, -5);
19925
- const file = path17.join(v2Tasks, name);
20067
+ const file = path18.join(v2Tasks, name);
19926
20068
  const bytes = fs14.readFileSync(file, "utf8");
19927
20069
  const digest = sha256(bytes);
19928
- fs14.writeFileSync(path17.join(legacy, "tasks", name), bytes);
20070
+ fs14.writeFileSync(path18.join(legacy, "tasks", name), bytes);
19929
20071
  const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
19930
20072
  if (!parsed.ok || parsed.data.id !== id)
19931
20073
  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 });
19932
20074
  const record = { ...parsed.data, workspaceId: target.id };
19933
- const origin = { path: path17.join(legacy, "tasks", name), digest };
20075
+ const origin = { path: path18.join(legacy, "tasks", name), digest };
19934
20076
  if (!fs14.existsSync(this.eventsPath(id))) {
19935
20077
  this.openTask(record, "migrated.from_v2", null, origin);
19936
20078
  migrated += 1;
@@ -19966,7 +20108,7 @@ class TaskStore extends TaskReader {
19966
20108
  try {
19967
20109
  let complete = true;
19968
20110
  for (const [name, digest] of done) {
19969
- const file = path17.join(v2Tasks, name);
20111
+ const file = path18.join(v2Tasks, name);
19970
20112
  if (sha256(fs14.readFileSync(file, "utf8")) !== digest) {
19971
20113
  complete = false;
19972
20114
  continue;
@@ -19980,7 +20122,7 @@ class TaskStore extends TaskReader {
19980
20122
  return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
19981
20123
  path: v2
19982
20124
  });
19983
- fs14.rmSync(path17.join(v2, "index.json"), { force: true });
20125
+ fs14.rmSync(path18.join(v2, "index.json"), { force: true });
19984
20126
  if (dirs.shared)
19985
20127
  fs14.rmSync(v2Workspace, { force: true });
19986
20128
  else
@@ -20005,8 +20147,8 @@ class TaskStore extends TaskReader {
20005
20147
  const dirs = this.paths();
20006
20148
  if (!dirs.shared)
20007
20149
  return success(null, null, null);
20008
- const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path17.join(v2, name)));
20009
- const ignore = path17.join(v2, ".gitignore");
20150
+ const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path18.join(v2, name)));
20151
+ const ignore = path18.join(v2, ".gitignore");
20010
20152
  const onlyGeneratedIgnore = () => {
20011
20153
  try {
20012
20154
  return fs14.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs14.readFileSync(ignore, "utf8"));
@@ -20016,12 +20158,12 @@ class TaskStore extends TaskReader {
20016
20158
  };
20017
20159
  if (present().length === 0 && !onlyGeneratedIgnore())
20018
20160
  return success(null, null, null);
20019
- const backup = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
20161
+ const backup = path18.join(dirs.dir, "legacy", checkoutSlug(path18.dirname(v2)), "v2");
20020
20162
  return this.withLock(dirs.checkoutLock, () => {
20021
20163
  let moved = 0;
20022
20164
  try {
20023
20165
  for (const name of present()) {
20024
- const entry = path17.join(v2, name);
20166
+ const entry = path18.join(v2, name);
20025
20167
  const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
20026
20168
  const empty = fs14.lstatSync(entry).isDirectory() && fs14.readdirSync(entry).length === 0;
20027
20169
  if (marker || empty) {
@@ -20030,18 +20172,18 @@ class TaskStore extends TaskReader {
20030
20172
  }
20031
20173
  if (name === "tasks" && fs14.lstatSync(entry).isDirectory()) {
20032
20174
  for (const task of fs14.readdirSync(entry)) {
20033
- const file = path17.join(entry, task);
20175
+ const file = path18.join(entry, task);
20034
20176
  if (fs14.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
20035
20177
  fs14.rmSync(file);
20036
20178
  else {
20037
- moveInto(file, path17.join(backup, "tasks", task));
20179
+ moveInto(file, path18.join(backup, "tasks", task));
20038
20180
  moved += 1;
20039
20181
  }
20040
20182
  }
20041
20183
  fs14.rmdirSync(entry);
20042
20184
  continue;
20043
20185
  }
20044
- moveInto(entry, path17.join(backup, name));
20186
+ moveInto(entry, path18.join(backup, name));
20045
20187
  moved += 1;
20046
20188
  }
20047
20189
  if (onlyGeneratedIgnore())
@@ -20082,22 +20224,22 @@ var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
20082
20224
  var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
20083
20225
 
20084
20226
  // packages/workit-core/src/core/task-evaluation.ts
20085
- import { createHash as createHash11 } from "node:crypto";
20227
+ import { createHash as createHash12 } from "node:crypto";
20086
20228
  import * as fs18 from "node:fs";
20087
20229
  import { spawnSync as spawnSync15 } from "node:child_process";
20088
- import path23 from "node:path";
20230
+ import path24 from "node:path";
20089
20231
 
20090
20232
  // packages/workit-core/src/check-config.ts
20091
20233
  import { spawnSync as spawnSync11 } from "node:child_process";
20092
20234
  import fs15 from "node:fs";
20093
- import path18 from "node:path";
20235
+ import path19 from "node:path";
20094
20236
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
20095
20237
  var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
20096
20238
  var CHECKS_FILE = ".workit/checks.json";
20097
20239
  var LEGACY_CHECKS_FILE = "workit.checks.json";
20098
20240
  function checksConfigFile(root) {
20099
- const current = path18.join(root, CHECKS_FILE);
20100
- const legacy = path18.join(root, LEGACY_CHECKS_FILE);
20241
+ const current = path19.join(root, CHECKS_FILE);
20242
+ const legacy = path19.join(root, LEGACY_CHECKS_FILE);
20101
20243
  return !fs15.existsSync(current) && fs15.existsSync(legacy) ? legacy : current;
20102
20244
  }
20103
20245
  var GENERATED_GITIGNORES2 = new Set([`*
@@ -20156,10 +20298,10 @@ var git3 = (cwd, args) => {
20156
20298
  return value || null;
20157
20299
  };
20158
20300
  function checkRoot(cwd) {
20159
- return path18.resolve(gitDirs(cwd)?.top ?? cwd);
20301
+ return path19.resolve(gitDirs(cwd)?.top ?? cwd);
20160
20302
  }
20161
20303
  var packageManager = (root) => {
20162
- const has = (file) => fs15.existsSync(path18.join(root, file));
20304
+ const has = (file) => fs15.existsSync(path19.join(root, file));
20163
20305
  if (has("bun.lock") || has("bun.lockb"))
20164
20306
  return "bun";
20165
20307
  if (has("pnpm-lock.yaml"))
@@ -20179,7 +20321,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
20179
20321
  function detectedChecks(root) {
20180
20322
  const read = (file) => {
20181
20323
  try {
20182
- return fs15.readFileSync(path18.join(root, file), "utf8");
20324
+ return fs15.readFileSync(path19.join(root, file), "utf8");
20183
20325
  } catch {
20184
20326
  return null;
20185
20327
  }
@@ -20254,10 +20396,10 @@ function configFileFor(root) {
20254
20396
  if (fs15.existsSync(own))
20255
20397
  return own;
20256
20398
  const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
20257
- if (!common || path18.basename(common) !== ".git")
20399
+ if (!common || path19.basename(common) !== ".git")
20258
20400
  return own;
20259
- const main = path18.dirname(common);
20260
- if (path18.resolve(main) === path18.resolve(root))
20401
+ const main = path19.dirname(common);
20402
+ if (path19.resolve(main) === path19.resolve(root))
20261
20403
  return own;
20262
20404
  const shared = checksConfigFile(main);
20263
20405
  return fs15.existsSync(shared) ? shared : own;
@@ -20265,7 +20407,7 @@ function configFileFor(root) {
20265
20407
  function loadCheckConfig(cwd) {
20266
20408
  const root = checkRoot(cwd);
20267
20409
  const file = configFileFor(root);
20268
- const legacy = path18.basename(file) === LEGACY_CHECKS_FILE;
20410
+ const legacy = path19.basename(file) === LEGACY_CHECKS_FILE;
20269
20411
  const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
20270
20412
  const note = legacy ? {
20271
20413
  note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
@@ -20396,10 +20538,10 @@ function workitAvailable(env = process.env) {
20396
20538
  return workitOnPath;
20397
20539
  const windows = process.platform === "win32";
20398
20540
  const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
20399
- const dirs = (env.PATH ?? env.Path ?? "").split(path18.delimiter).filter(Boolean);
20541
+ const dirs = (env.PATH ?? env.Path ?? "").split(path19.delimiter).filter(Boolean);
20400
20542
  workitOnPath = dirs.some((dir) => exts.some((ext) => {
20401
20543
  try {
20402
- return fs15.statSync(path18.join(dir, `workit${ext}`)).isFile();
20544
+ return fs15.statSync(path19.join(dir, `workit${ext}`)).isFile();
20403
20545
  } catch {
20404
20546
  return false;
20405
20547
  }
@@ -20460,13 +20602,13 @@ var PYTHON_RUNNERS = new Set(["uv", "poetry", "pipenv", "pdm", "hatch", "rye"]);
20460
20602
 
20461
20603
  // packages/workit-core/src/core/policy/derive.ts
20462
20604
  import { existsSync as existsSync9 } from "node:fs";
20463
- import path22 from "node:path";
20605
+ import path23 from "node:path";
20464
20606
 
20465
20607
  // packages/workit-core/src/ledger.ts
20466
20608
  import { spawnSync as spawnSync14 } from "node:child_process";
20467
- import { createHash as createHash10, randomBytes as randomBytes3 } from "node:crypto";
20609
+ import { createHash as createHash11, randomBytes as randomBytes3 } from "node:crypto";
20468
20610
  import fs17 from "node:fs";
20469
- import path21 from "node:path";
20611
+ import path22 from "node:path";
20470
20612
 
20471
20613
  // packages/workit-core/src/core/policy/bookkeeping.ts
20472
20614
  import { spawnSync as spawnSync12 } from "node:child_process";
@@ -20546,8 +20688,8 @@ function bookkeepingPaths(cwd, input) {
20546
20688
  }
20547
20689
 
20548
20690
  // packages/workit-core/src/core/policy/lane.ts
20549
- import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
20550
- import path19 from "node:path";
20691
+ import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
20692
+ import path20 from "node:path";
20551
20693
 
20552
20694
  // packages/workit-core/src/git/default-base.ts
20553
20695
  import { spawnSync as spawnSync13 } from "node:child_process";
@@ -21938,7 +22080,7 @@ function computeLane(input) {
21938
22080
  }
21939
22081
  function untrackedStat(cwd, file) {
21940
22082
  try {
21941
- const bytes = readFileSync7(path19.join(cwd, file));
22083
+ const bytes = readFileSync8(path20.join(cwd, file));
21942
22084
  if (bytes.includes(0))
21943
22085
  return { path: file, added: 0, deleted: 0, binary: true };
21944
22086
  const text = bytes.toString("utf8");
@@ -21970,7 +22112,7 @@ function cosmeticFiles(cwd, fork, head) {
21970
22112
  let after = blobs.get(entry.newBlob);
21971
22113
  if (!after && head === null && ABSENT.test(entry.newBlob))
21972
22114
  try {
21973
- after = readFileSync7(path19.join(cwd, entry.path));
22115
+ after = readFileSync8(path20.join(cwd, entry.path));
21974
22116
  } catch {
21975
22117
  after = undefined;
21976
22118
  }
@@ -22126,25 +22268,25 @@ function verdictDrift(cwd, input) {
22126
22268
 
22127
22269
  // packages/workit-core/src/hooks/standing-signal.ts
22128
22270
  import fs16 from "node:fs";
22129
- import path20 from "node:path";
22271
+ import path21 from "node:path";
22130
22272
  var gitStoreDir = (cwd) => {
22131
22273
  try {
22132
- for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
22133
- const dotGit = path20.join(dir, ".git");
22274
+ for (let dir = path21.resolve(cwd);; dir = path21.dirname(dir)) {
22275
+ const dotGit = path21.join(dir, ".git");
22134
22276
  if (fs16.existsSync(dotGit)) {
22135
22277
  let gitDir = dotGit;
22136
22278
  if (fs16.statSync(dotGit).isFile()) {
22137
22279
  const target = /^gitdir:\s*(.+)$/mu.exec(fs16.readFileSync(dotGit, "utf8"))?.[1]?.trim();
22138
22280
  if (!target)
22139
22281
  return null;
22140
- gitDir = path20.resolve(dir, target);
22141
- const common = path20.join(gitDir, "commondir");
22282
+ gitDir = path21.resolve(dir, target);
22283
+ const common = path21.join(gitDir, "commondir");
22142
22284
  if (fs16.existsSync(common))
22143
- gitDir = path20.resolve(gitDir, fs16.readFileSync(common, "utf8").trim());
22285
+ gitDir = path21.resolve(gitDir, fs16.readFileSync(common, "utf8").trim());
22144
22286
  }
22145
- return path20.join(gitDir, "workit");
22287
+ return path21.join(gitDir, "workit");
22146
22288
  }
22147
- if (path20.dirname(dir) === dir)
22289
+ if (path21.dirname(dir) === dir)
22148
22290
  return null;
22149
22291
  }
22150
22292
  } catch {
@@ -22217,7 +22359,7 @@ var binaryRangeDiff = (cwd, base, head) => {
22217
22359
  return diff.ok && diff.stdout ? diff.stdout : null;
22218
22360
  };
22219
22361
  var hashOfDiff = (diff) => {
22220
- const hash = createHash10("sha256");
22362
+ const hash = createHash11("sha256");
22221
22363
  for (const line of diff.split(`
22222
22364
  `)) {
22223
22365
  if (line.startsWith("index "))
@@ -22250,14 +22392,14 @@ function cleanRebase(cwd, range) {
22250
22392
  return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
22251
22393
  }
22252
22394
  function storeRoot(cwd) {
22253
- const location = resolveStore(path21.resolve(cwd));
22395
+ const location = resolveStore(path22.resolve(cwd));
22254
22396
  if (location instanceof Error)
22255
22397
  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");
22256
22398
  return { ok: true, value: { root: location.dir, shared: location.shared } };
22257
22399
  }
22258
22400
  function ledgerPath(cwd) {
22259
22401
  const root = storeRoot(cwd);
22260
- return root.ok ? { ok: true, value: path21.join(root.value.root, "ledger", "ledger.jsonl") } : root;
22402
+ return root.ok ? { ok: true, value: path22.join(root.value.root, "ledger", "ledger.jsonl") } : root;
22261
22403
  }
22262
22404
  var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
22263
22405
  var NETWORK_FS_TYPES = new Set([
@@ -22287,13 +22429,13 @@ var LOCK_STALE_MS2 = 30000;
22287
22429
  var LOCK_OWNER = "owner";
22288
22430
  var lockToken = (lock) => {
22289
22431
  try {
22290
- return fs17.readFileSync(path21.join(lock, LOCK_OWNER), "utf8");
22432
+ return fs17.readFileSync(path22.join(lock, LOCK_OWNER), "utf8");
22291
22433
  } catch {
22292
22434
  return null;
22293
22435
  }
22294
22436
  };
22295
22437
  var lockAgeMs = (lock) => {
22296
- for (const target of [path21.join(lock, LOCK_OWNER), lock]) {
22438
+ for (const target of [path22.join(lock, LOCK_OWNER), lock]) {
22297
22439
  try {
22298
22440
  return Date.now() - fs17.statSync(target).mtimeMs;
22299
22441
  } catch {}
@@ -22310,7 +22452,7 @@ var ledgerLock = {
22310
22452
  throw error;
22311
22453
  }
22312
22454
  const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
22313
- fs17.writeFileSync(path21.join(lock, LOCK_OWNER), token);
22455
+ fs17.writeFileSync(path22.join(lock, LOCK_OWNER), token);
22314
22456
  return token;
22315
22457
  },
22316
22458
  release(lock, token) {
@@ -22373,7 +22515,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2))
22373
22515
  ledgerLock.release(lock, token);
22374
22516
  }
22375
22517
  }
22376
- var sha2562 = (text) => createHash10("sha256").update(text).digest("hex");
22518
+ var sha2562 = (text) => createHash11("sha256").update(text).digest("hex");
22377
22519
  var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
22378
22520
  ${body}`);
22379
22521
  var TAIL_BYTES = 64 * 1024;
@@ -22435,8 +22577,8 @@ ${line.value}`);
22435
22577
  }
22436
22578
  };
22437
22579
  try {
22438
- fs17.mkdirSync(path21.dirname(file), { recursive: true });
22439
- if (options.heldLock || !options.forceLock && !onNetworkFs(path21.dirname(file)))
22580
+ fs17.mkdirSync(path22.dirname(file), { recursive: true });
22581
+ if (options.heldLock || !options.forceLock && !onNetworkFs(path22.dirname(file)))
22440
22582
  return write();
22441
22583
  const locked = withLedgerLock(file, write);
22442
22584
  return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
@@ -22453,7 +22595,7 @@ var sealed = (row, id, at, previous) => {
22453
22595
  ` };
22454
22596
  };
22455
22597
  function appendRaw(cwd, row, options) {
22456
- const file = options.store ? { ok: true, value: path21.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
22598
+ const file = options.store ? { ok: true, value: path22.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
22457
22599
  if (!file.ok)
22458
22600
  return file;
22459
22601
  const id = newId2();
@@ -23113,7 +23255,7 @@ function remoteIdentity(cwd, hop = 0) {
23113
23255
  return null;
23114
23256
  if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
23115
23257
  const local = raw.replace(/^file:\/\//u, "");
23116
- const resolved = path21.isAbsolute(local) ? local : path21.resolve(cwd, local);
23258
+ const resolved = path22.isAbsolute(local) ? local : path22.resolve(cwd, local);
23117
23259
  if (fs17.existsSync(resolved))
23118
23260
  return remoteIdentity(resolved, 1);
23119
23261
  }
@@ -23134,8 +23276,8 @@ function verdictMirrorPath(cwd) {
23134
23276
  }
23135
23277
  if (!identity)
23136
23278
  return null;
23137
- const key = createHash10("sha256").update(identity).digest("hex").slice(0, 32);
23138
- return path21.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
23279
+ const key = createHash11("sha256").update(identity).digest("hex").slice(0, 32);
23280
+ return path22.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
23139
23281
  }
23140
23282
  var importedStamp = new Map;
23141
23283
  function importMirroredVerdicts(cwd, branch) {
@@ -23158,7 +23300,7 @@ function importMirroredVerdicts(cwd, branch) {
23158
23300
  const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
23159
23301
  const added = new Set;
23160
23302
  try {
23161
- fs17.mkdirSync(path21.dirname(local.value), { recursive: true });
23303
+ fs17.mkdirSync(path22.dirname(local.value), { recursive: true });
23162
23304
  } catch {
23163
23305
  return [];
23164
23306
  }
@@ -23362,7 +23504,7 @@ var productDecision = (task, ledger) => {
23362
23504
  };
23363
23505
  };
23364
23506
  var planRecorded = (task, root) => {
23365
- const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path22.resolve(root, ref.path)));
23507
+ const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path23.resolve(root, ref.path)));
23366
23508
  if (cited)
23367
23509
  return {
23368
23510
  met: true,
@@ -23428,15 +23570,15 @@ function derivedRuleStatus(task, requirement, root, ledger) {
23428
23570
  }
23429
23571
 
23430
23572
  // packages/workit-core/src/core/task-evaluation.ts
23431
- var digestBytes = (value) => createHash11("sha256").update(value).digest("hex");
23432
- var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path23.sep}`);
23433
- var relative = (root, candidate) => path23.relative(root, candidate).split(path23.sep).join("/") || ".";
23573
+ var digestBytes = (value) => createHash12("sha256").update(value).digest("hex");
23574
+ var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path24.sep}`);
23575
+ var relative = (root, candidate) => path24.relative(root, candidate).split(path24.sep).join("/") || ".";
23434
23576
  var canonicalPath = (value) => {
23435
23577
  if (typeof value !== "string" || !value)
23436
23578
  return null;
23437
23579
  if (value.includes("\\") || value.split("/").includes(".."))
23438
23580
  return null;
23439
- const normalized = path23.posix.normalize(value);
23581
+ const normalized = path24.posix.normalize(value);
23440
23582
  if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
23441
23583
  return null;
23442
23584
  return normalized === "." ? "." : normalized.replace(/\/$/, "");
@@ -23484,14 +23626,14 @@ var gitPaths = (root) => {
23484
23626
  git: !/not a git repository/i.test(stderr)
23485
23627
  };
23486
23628
  }
23487
- const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")) : [];
23629
+ const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path24.sep).join("/")) : [];
23488
23630
  const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
23489
23631
  if (stagedDeleted.status !== 0) {
23490
23632
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
23491
23633
  if (!/not a git repository/i.test(stderr))
23492
23634
  return { paths, uncertain: true, git: true };
23493
23635
  } else if (stagedDeleted.stdout) {
23494
- paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")));
23636
+ paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path24.sep).join("/")));
23495
23637
  }
23496
23638
  return { paths: [...new Set(paths)], uncertain: false, git: true };
23497
23639
  };
@@ -23506,7 +23648,7 @@ var walk = (root, directory, output) => {
23506
23648
  for (const name of names) {
23507
23649
  if (name === ".git" || name === ".workit")
23508
23650
  continue;
23509
- const target = path23.join(directory, name);
23651
+ const target = path24.join(directory, name);
23510
23652
  let stat;
23511
23653
  try {
23512
23654
  stat = fs18.lstatSync(target);
@@ -23524,12 +23666,12 @@ var walk = (root, directory, output) => {
23524
23666
  var scopeRoots = (root, scope) => {
23525
23667
  const roots = [];
23526
23668
  for (const item of scope.paths.length ? scope.paths : ["."]) {
23527
- const target = path23.resolve(root, item);
23669
+ const target = path24.resolve(root, item);
23528
23670
  if (!inside(root, target))
23529
23671
  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` }] });
23530
23672
  let ancestor = target;
23531
23673
  while (!fs18.existsSync(ancestor) && ancestor !== root)
23532
- ancestor = path23.dirname(ancestor);
23674
+ ancestor = path24.dirname(ancestor);
23533
23675
  try {
23534
23676
  if (!inside(root, fs18.realpathSync(ancestor)))
23535
23677
  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` }] });
@@ -23581,7 +23723,7 @@ function captureCandidate(root, scope, environment = []) {
23581
23723
  for (const item of [...names].toSorted()) {
23582
23724
  if (!scopeMatches(item, normalizedScope))
23583
23725
  continue;
23584
- const target = path23.join(checkout, item);
23726
+ const target = path24.join(checkout, item);
23585
23727
  try {
23586
23728
  const stat = fs18.lstatSync(target);
23587
23729
  if (stat.isSymbolicLink()) {
@@ -23765,23 +23907,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
23765
23907
  continue;
23766
23908
  if (!reference.digest)
23767
23909
  return failure2("invalid_input", "document references require a byte digest");
23768
- const target = path23.resolve(root, reference.path);
23769
- if (target !== root && !target.startsWith(`${root}${path23.sep}`))
23910
+ const target = path24.resolve(root, reference.path);
23911
+ if (target !== root && !target.startsWith(`${root}${path24.sep}`))
23770
23912
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
23771
23913
  fields: [
23772
23914
  { path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
23773
23915
  ]
23774
23916
  });
23775
23917
  try {
23776
- const below = path23.relative(root, target);
23918
+ const below = path24.relative(root, target);
23777
23919
  let current = root;
23778
- for (const segment of below.split(path23.sep)) {
23920
+ for (const segment of below.split(path24.sep)) {
23779
23921
  if (!segment)
23780
23922
  continue;
23781
- current = path23.join(current, segment);
23923
+ current = path24.join(current, segment);
23782
23924
  const stat = fs18.lstatSync(current);
23783
23925
  const real = fs18.realpathSync(current);
23784
- if (real !== root && !real.startsWith(`${root}${path23.sep}`))
23926
+ if (real !== root && !real.startsWith(`${root}${path24.sep}`))
23785
23927
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
23786
23928
  fields: [
23787
23929
  {
@@ -24146,8 +24288,8 @@ function briefInspectResult(request, result) {
24146
24288
  }
24147
24289
 
24148
24290
  // packages/workit-core/src/core/model-fallback.ts
24149
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync9, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
24150
- import path24 from "node:path";
24291
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
24292
+ import path25 from "node:path";
24151
24293
  var LIMITS_FILE = "model-limits.json";
24152
24294
  var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
24153
24295
  var KEEP_MS = 9 * 86400000;
@@ -24170,10 +24312,10 @@ var providerOf = (model, host) => {
24170
24312
  return null;
24171
24313
  };
24172
24314
  var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
24173
- var storePath = (stateDir) => path24.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
24315
+ var storePath = (stateDir) => path25.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
24174
24316
  var readStore = (stateDir) => {
24175
24317
  try {
24176
- const parsed = JSON.parse(readFileSync9(storePath(stateDir), "utf8"));
24318
+ const parsed = JSON.parse(readFileSync10(storePath(stateDir), "utf8"));
24177
24319
  const store = empty();
24178
24320
  for (const key of ["exhausted", "seen", "redispatched"])
24179
24321
  if (parsed[key] && typeof parsed[key] === "object")
@@ -24593,20 +24735,20 @@ import path28 from "node:path";
24593
24735
  // packages/workit-core/src/core/eval-world.ts
24594
24736
  import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
24595
24737
  import os6 from "node:os";
24596
- import path25 from "node:path";
24738
+ import path26 from "node:path";
24597
24739
  var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
24598
24740
  var EVAL_WORLD_MARKER = ".workit-eval-world";
24599
24741
  var inside2 = (dir, file) => {
24600
- const rel = path25.relative(dir, file);
24601
- return !rel.startsWith("..") && !path25.isAbsolute(rel);
24742
+ const rel = path26.relative(dir, file);
24743
+ return !rel.startsWith("..") && !path26.isAbsolute(rel);
24602
24744
  };
24603
24745
  var evalWorld = (cwd) => {
24604
24746
  const raw = process.env[EVAL_WORLD_ENV];
24605
- if (!raw || !path25.isAbsolute(raw))
24747
+ if (!raw || !path26.isAbsolute(raw))
24606
24748
  return null;
24607
24749
  try {
24608
24750
  const world = realpathSync7(raw);
24609
- return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path25.join(world, EVAL_WORLD_MARKER)) ? world : null;
24751
+ return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path26.join(world, EVAL_WORLD_MARKER)) ? world : null;
24610
24752
  } catch {
24611
24753
  return null;
24612
24754
  }
@@ -24614,77 +24756,12 @@ var evalWorld = (cwd) => {
24614
24756
  var evalWorldEntry = (cwd) => {
24615
24757
  const world = evalWorld(cwd);
24616
24758
  try {
24617
- return world ? loadWorkspacesFrom(path25.join(world, "config"))[0] ?? null : null;
24759
+ return world ? loadWorkspacesFrom(path26.join(world, "config"))[0] ?? null : null;
24618
24760
  } catch {
24619
24761
  return null;
24620
24762
  }
24621
24763
  };
24622
24764
 
24623
- // packages/workit-core/src/core/grant-seal.ts
24624
- import { createHash as createHash12 } from "node:crypto";
24625
- import { readFileSync as readFileSync10 } from "node:fs";
24626
- import path26 from "node:path";
24627
- var SEAL_FILE = "workspaces.json.seal";
24628
- var SEAL_VERSION = 1;
24629
- var SEAL_COMMAND = "workit workspace seal";
24630
- var pick3 = (value, keys) => {
24631
- if (!value || typeof value !== "object" || Array.isArray(value))
24632
- return;
24633
- const out = Object.fromEntries(keys.flatMap((key) => {
24634
- const item = value[key];
24635
- return item === undefined ? [] : [[key, item]];
24636
- }));
24637
- return Object.keys(out).length > 0 ? out : undefined;
24638
- };
24639
- var ENTRY_KEYS = [
24640
- "name",
24641
- "glob",
24642
- "remotes",
24643
- "externalRepos",
24644
- "additiveRiskPaths",
24645
- "vcs",
24646
- "autonomy",
24647
- "autoApprove",
24648
- "defaultEndpoint",
24649
- "verification",
24650
- "youtrack"
24651
- ];
24652
- var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
24653
- var sealProjection = (entries) => entries.map((entry) => {
24654
- const all = pick3(entry, ENTRY_KEYS) ?? {};
24655
- return pick3({
24656
- ...all,
24657
- vcs: pick3(all.vcs, IDENTITY_KEYS),
24658
- youtrack: pick3(all.youtrack, ["writes", "autoHosts"])
24659
- }, ENTRY_KEYS);
24660
- });
24661
- 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);
24662
- var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
24663
- var broken = (reason, sealed = null) => ({
24664
- state: "broken",
24665
- reason,
24666
- sealed
24667
- });
24668
- function checkSeal(dir) {
24669
- const file = path26.join(dir, SEAL_FILE);
24670
- let seal;
24671
- try {
24672
- seal = JSON.parse(readFileSync10(file, "utf8"));
24673
- } catch (error) {
24674
- if (error.code === "ENOENT")
24675
- return { state: "none" };
24676
- return broken(`${SEAL_FILE} cannot be read`);
24677
- }
24678
- if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
24679
- return broken(`${SEAL_FILE} is malformed`);
24680
- const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
24681
- if (sealed.status !== "valid")
24682
- return broken(`${SEAL_FILE} is malformed`);
24683
- const current = readWorkspacesResult(dir);
24684
- const ok = current.status === "valid" || current.status === "missing";
24685
- return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
24686
- }
24687
-
24688
24765
  // packages/workit-core/src/core/youtrack-ytrack.ts
24689
24766
  import { spawnSync as spawnSync16 } from "node:child_process";
24690
24767
 
@@ -24805,7 +24882,7 @@ var sealOf = () => {
24805
24882
  var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
24806
24883
  var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
24807
24884
  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}`;
24808
- 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;
24885
+ 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;
24809
24886
  var shownGrantsDir = () => {
24810
24887
  const world = evalWorld(process.cwd());
24811
24888
  return world ? path28.join(world, "config") : accountDir();
@@ -25128,7 +25205,14 @@ var SCOPE_FIELDS = new Set([
25128
25205
  "autoApprove",
25129
25206
  "defaultEndpoint",
25130
25207
  "verification",
25131
- "youtrack"
25208
+ "youtrack",
25209
+ "releaseNotes",
25210
+ "releaseTagPrefix",
25211
+ "branchPolicy",
25212
+ "profiles",
25213
+ "defaultProfile",
25214
+ "releaseTracks",
25215
+ "releasePackages"
25132
25216
  ]);
25133
25217
 
25134
25218
  // packages/workit-core/src/core/release-packages.ts