@workit-dev/opencode 2.29.1 → 2.29.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/plugin.js +930 -397
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -6993,17 +6993,17 @@ function explainInvalidOperation(family, request) {
6993
6993
  return parsed.success ? null : invalidOperation(family, request, parsed.error);
6994
6994
  }
6995
6995
  // packages/workit-core/src/core/task-store.ts
6996
- import { createHash as createHash12 } from "node:crypto";
6996
+ import { createHash as createHash13 } from "node:crypto";
6997
6997
  import * as fs16 from "node:fs";
6998
- import path19 from "node:path";
6998
+ import path20 from "node:path";
6999
6999
 
7000
7000
  // packages/workit-core/src/host-session.ts
7001
- import { createHash as createHash10, randomBytes, timingSafeEqual } from "node:crypto";
7001
+ import { createHash as createHash11, randomBytes, timingSafeEqual } from "node:crypto";
7002
7002
  import fs9 from "node:fs";
7003
- import path13 from "node:path";
7003
+ import path14 from "node:path";
7004
7004
 
7005
7005
  // packages/workit-core/src/core/branch.ts
7006
- import { createHash as createHash8 } from "node:crypto";
7006
+ import { createHash as createHash9 } from "node:crypto";
7007
7007
 
7008
7008
  // packages/workit-core/src/core/branch-policy.ts
7009
7009
  import { spawnSync } from "node:child_process";
@@ -7379,9 +7379,9 @@ var gitContext = (workspaceRoot, paths = []) => {
7379
7379
 
7380
7380
  // packages/workit-core/src/core/workspaces.ts
7381
7381
  import { spawnSync as spawnSync6 } from "node:child_process";
7382
- import { createHash as createHash6 } from "node:crypto";
7383
- import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
7384
- import path9 from "node:path";
7382
+ import { createHash as createHash7 } from "node:crypto";
7383
+ import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
7384
+ import path10 from "node:path";
7385
7385
 
7386
7386
  // packages/workit-core/src/core/remotes.ts
7387
7387
  import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
@@ -8697,6 +8697,103 @@ var pushTarget = (cwd, remote, replay = {}) => {
8697
8697
  return { remotes };
8698
8698
  };
8699
8699
 
8700
+ // packages/workit-core/src/core/grant-seal.ts
8701
+ import { createHash as createHash6 } from "node:crypto";
8702
+ import { readFileSync as readFileSync4 } from "node:fs";
8703
+ import path9 from "node:path";
8704
+ var SEAL_FILE = "workspaces.json.seal";
8705
+ var SEAL_VERSION = 2;
8706
+ var isSealVersion = (value) => value === 1 || value === 2;
8707
+ var SEAL_COMMAND = "workit workspace seal";
8708
+ var pick3 = (value, keys) => {
8709
+ if (!value || typeof value !== "object" || Array.isArray(value))
8710
+ return;
8711
+ const out = Object.fromEntries(keys.flatMap((key) => {
8712
+ const item = value[key];
8713
+ return item === undefined ? [] : [[key, item]];
8714
+ }));
8715
+ return Object.keys(out).length > 0 ? out : undefined;
8716
+ };
8717
+ var ENTRY_KEYS = [
8718
+ "name",
8719
+ "glob",
8720
+ "remotes",
8721
+ "externalRepos",
8722
+ "additiveRiskPaths",
8723
+ "vcs",
8724
+ "autonomy",
8725
+ "autoApprove",
8726
+ "defaultEndpoint",
8727
+ "verification",
8728
+ "youtrack"
8729
+ ];
8730
+ var RELEASE_KEYS = [
8731
+ "releaseNotes",
8732
+ "releaseTagPrefix",
8733
+ "branchPolicy",
8734
+ "profiles",
8735
+ "defaultProfile",
8736
+ "releaseTracks",
8737
+ "releasePackages"
8738
+ ];
8739
+ var keysOf = (version) => version >= 2 ? [...ENTRY_KEYS, ...RELEASE_KEYS] : ENTRY_KEYS;
8740
+ var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
8741
+ var sealProjection = (entries, version = SEAL_VERSION) => entries.map((entry) => {
8742
+ const keys = keysOf(version);
8743
+ const all = pick3(entry, keys) ?? {};
8744
+ return pick3({
8745
+ ...all,
8746
+ vcs: pick3(all.vcs, IDENTITY_KEYS),
8747
+ youtrack: pick3(all.youtrack, ["writes", "autoHosts"]),
8748
+ ...version >= 2 ? releaseLineMapping(entry, true) : {}
8749
+ }, keys);
8750
+ });
8751
+ var canonical3 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
8752
+ var sealDigest = (projection) => createHash6("sha256").update(canonical3(projection)).digest("hex");
8753
+ var broken = (reason, sealed = null, version) => ({
8754
+ state: "broken",
8755
+ reason,
8756
+ sealed,
8757
+ ...version ? { version } : {}
8758
+ });
8759
+ var PARTIAL_KEYS = ["releaseTracks", "branchPolicy", "profiles", "defaultProfile"];
8760
+ var sealedEntries = (projection, file) => {
8761
+ const partial = projection.map((entry) => pick3(entry, PARTIAL_KEYS));
8762
+ const validated = validateWorkspacesDocument({
8763
+ workspaces: projection.map((entry) => {
8764
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
8765
+ return entry;
8766
+ const rest = { ...entry };
8767
+ for (const key of PARTIAL_KEYS)
8768
+ delete rest[key];
8769
+ return rest;
8770
+ })
8771
+ }, file);
8772
+ if (validated.status !== "valid" || validated.entries.length !== projection.length)
8773
+ return null;
8774
+ return validated.entries.map((entry, at) => partial[at] === undefined ? entry : { ...entry, ...partial[at] });
8775
+ };
8776
+ function checkSeal(dir) {
8777
+ const file = path9.join(dir, SEAL_FILE);
8778
+ let seal;
8779
+ try {
8780
+ seal = JSON.parse(readFileSync4(file, "utf8"));
8781
+ } catch (error) {
8782
+ if (error.code === "ENOENT")
8783
+ return { state: "none" };
8784
+ return broken(`${SEAL_FILE} cannot be read`);
8785
+ }
8786
+ if (!isSealVersion(seal?.version) || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
8787
+ return broken(`${SEAL_FILE} is malformed`);
8788
+ const version = seal.version;
8789
+ const sealed = sealedEntries(seal.projection, file);
8790
+ if (!sealed)
8791
+ return broken(`${SEAL_FILE} is malformed`, null, version);
8792
+ const current = readWorkspacesResult(dir);
8793
+ const ok = current.status === "valid" || current.status === "missing";
8794
+ return ok && sealDigest(sealProjection(current.entries, version)) === seal.sha256 ? { state: "valid", version } : broken("workspaces.json changed since it was sealed", sealed, version);
8795
+ }
8796
+
8700
8797
  // packages/workit-core/src/core/workspaces.ts
8701
8798
  var nonBlank = string2().check(refine((value) => value.trim().length > 0, "must not be blank"));
8702
8799
  var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
@@ -8762,7 +8859,7 @@ var releaseTrackSchema = looseObject({
8762
8859
  });
8763
8860
  }
8764
8861
  }
8765
- if (track.versionSource?.kind === "package-json" && (path9.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
8862
+ if (track.versionSource?.kind === "package-json" && (path10.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
8766
8863
  context.addIssue({
8767
8864
  code: "custom",
8768
8865
  path: ["versionSource", "path"],
@@ -8861,8 +8958,8 @@ var workspacesFileSchema = looseObject({
8861
8958
  names.add(workspace.name);
8862
8959
  }
8863
8960
  }));
8864
- var workspacesPath = () => path9.join(configDir2(), "workspaces.json");
8865
- var workspacesRevision = (contents) => createHash6("sha256").update(contents ?? "<missing>").digest("hex");
8961
+ var workspacesPath = () => path10.join(configDir2(), "workspaces.json");
8962
+ var workspacesRevision = (contents) => createHash7("sha256").update(contents ?? "<missing>").digest("hex");
8866
8963
  var validateWorkspacesDocument = (parsed, file) => {
8867
8964
  if (!isConfigObject(parsed)) {
8868
8965
  return {
@@ -8908,10 +9005,10 @@ var validateWorkspacesDocument = (parsed, file) => {
8908
9005
  };
8909
9006
  };
8910
9007
  var readWorkspacesResult = (dir = configDir2()) => {
8911
- const file = path9.join(dir, "workspaces.json");
9008
+ const file = path10.join(dir, "workspaces.json");
8912
9009
  let raw;
8913
9010
  try {
8914
- raw = readFileSync4(file, "utf8");
9011
+ raw = readFileSync5(file, "utf8");
8915
9012
  } catch (error) {
8916
9013
  if (error.code === "ENOENT")
8917
9014
  return {
@@ -9012,9 +9109,9 @@ var probeCheckout = (cwd) => {
9012
9109
  const cached = probes.get(cwd);
9013
9110
  if (cached !== undefined)
9014
9111
  return cached;
9015
- let dir = path9.resolve(cwd);
9016
- while (!existsSync4(path9.join(dir, ".git"))) {
9017
- if (["HEAD", "objects", "refs"].every((name) => existsSync4(path9.join(dir, name)))) {
9112
+ let dir = path10.resolve(cwd);
9113
+ while (!existsSync4(path10.join(dir, ".git"))) {
9114
+ if (["HEAD", "objects", "refs"].every((name) => existsSync4(path10.join(dir, name)))) {
9018
9115
  const real = realpathOf(dir);
9019
9116
  const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
9020
9117
  if (owner === null)
@@ -9023,7 +9120,7 @@ var probeCheckout = (cwd) => {
9023
9120
  probes.set(cwd, probe);
9024
9121
  return probe;
9025
9122
  }
9026
- const up = path9.dirname(dir);
9123
+ const up = path10.dirname(dir);
9027
9124
  if (up === dir)
9028
9125
  return null;
9029
9126
  dir = up;
@@ -9052,9 +9149,9 @@ var probeCheckout = (cwd) => {
9052
9149
  if (!gitDir || !common)
9053
9150
  return failed;
9054
9151
  let main = null;
9055
- if (path9.resolve(gitDir) === path9.resolve(common)) {
9152
+ if (path10.resolve(gitDir) === path10.resolve(common)) {
9056
9153
  const real = realpathOf(common);
9057
- if (!ownGitDir(path9.join(dir, ".git"), real)) {
9154
+ if (!ownGitDir(path10.join(dir, ".git"), real)) {
9058
9155
  const owner = gitDirOwner(real);
9059
9156
  if (owner === null)
9060
9157
  return Error(`${cwd} uses the repository at ${real}, owned by no checkout workit can name`);
@@ -9073,7 +9170,7 @@ var probeCheckout = (cwd) => {
9073
9170
  const list = git(["worktree", "list", "--porcelain"]);
9074
9171
  if (list === null)
9075
9172
  return failed;
9076
- main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path9.basename(common) === ".git" ? path9.dirname(common) : common);
9173
+ main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path10.basename(common) === ".git" ? path10.dirname(common) : common);
9077
9174
  }
9078
9175
  const probe = { main, superproject: superproject || null };
9079
9176
  probes.set(cwd, probe);
@@ -9090,7 +9187,7 @@ var INTERNALS = ["refs", "objects", "config", "packed-refs", "commondir"];
9090
9187
  var ownInternals = (real) => {
9091
9188
  let lender = null;
9092
9189
  for (const name of INTERNALS) {
9093
- const at = path9.join(real, name);
9190
+ const at = path10.join(real, name);
9094
9191
  try {
9095
9192
  lstatSync3(at);
9096
9193
  } catch {
@@ -9102,10 +9199,10 @@ var ownInternals = (real) => {
9102
9199
  } catch {
9103
9200
  return false;
9104
9201
  }
9105
- const rel = path9.relative(real, resolved);
9106
- if (rel && !rel.startsWith("..") && !path9.isAbsolute(rel))
9202
+ const rel = path10.relative(real, resolved);
9203
+ if (rel && !rel.startsWith("..") && !path10.isAbsolute(rel))
9107
9204
  continue;
9108
- const owner = path9.basename(resolved) === name ? gitDirOwner(path9.dirname(resolved)) : null;
9205
+ const owner = path10.basename(resolved) === name ? gitDirOwner(path10.dirname(resolved)) : null;
9109
9206
  if (owner === null || lender !== null && lender !== owner)
9110
9207
  return false;
9111
9208
  lender = owner;
@@ -9119,7 +9216,7 @@ var gitDirOwner = (real) => {
9119
9216
  return null;
9120
9217
  const rest = parts.slice(at + 1);
9121
9218
  const module = rest[0] === "modules" || rest[0] === "worktrees" && rest[2] === "modules";
9122
- return rest.length === 0 || module ? parts.slice(0, at).join(path9.sep) || path9.sep : null;
9219
+ return rest.length === 0 || module ? parts.slice(0, at).join(path10.sep) || path10.sep : null;
9123
9220
  };
9124
9221
  var mainCheckoutOf = (cwd) => {
9125
9222
  const probe = probeCheckout(cwd);
@@ -9243,11 +9340,11 @@ var resolveRuntimeWorkspaceVcs = (cwd) => resolveRuntimeWorkspaceCandidate(cwd,
9243
9340
  var runtimeWorkspaceIndexSchema = looseObject({
9244
9341
  workspaces: optional(array(looseObject({ name: nonBlank, glob: nonBlank })))
9245
9342
  });
9246
- var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
9247
- const file = path9.join(dir, "workspaces.json");
9343
+ var matchRuntimeWorkspace = (cwd, dir = configDir2(), workspaceName = namedWorkspace()) => {
9344
+ const file = path10.join(dir, "workspaces.json");
9248
9345
  let raw;
9249
9346
  try {
9250
- raw = readFileSync4(file, "utf8");
9347
+ raw = readFileSync5(file, "utf8");
9251
9348
  } catch (error) {
9252
9349
  if (error.code === "ENOENT")
9253
9350
  return null;
@@ -9270,13 +9367,21 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
9270
9367
  if (!glob.ok)
9271
9368
  throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
9272
9369
  }
9273
- const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
9274
- const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
9370
+ const matched = matchAmong(cwd, entries ?? [], workspaceName);
9371
+ return matched ? { file, ...matched } : null;
9372
+ };
9373
+ var namedWorkspace = () => process.env.WORKIT_WORKSPACE_NAME?.trim() || null;
9374
+ var matchAmong = (cwd, entries, workspaceName = namedWorkspace()) => {
9375
+ const selected = resolveWorkspaceFromEntries(cwd, entries, workspaceName ?? undefined, true);
9275
9376
  if (!selected)
9276
9377
  return null;
9277
- const matches = matchingEntries(cwd, entries ?? []);
9278
- return { file, selected, matches: matches.length ? matches : [selected] };
9378
+ const matches = matchingEntries(cwd, entries);
9379
+ return { selected, matches: matches.length ? matches : [selected] };
9279
9380
  };
9381
+ var chainOf = (matched) => matched ? [
9382
+ matched.selected,
9383
+ ...matched.matches.filter((entry) => entry !== matched.selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob))
9384
+ ] : [];
9280
9385
  var resolveRuntimeReleaseTracks = (cwd) => {
9281
9386
  const matched = matchRuntimeWorkspace(cwd);
9282
9387
  return matched ? {
@@ -9293,11 +9398,9 @@ var inheritedSetting = (cwd, dir, has) => {
9293
9398
  }
9294
9399
  if (!matched)
9295
9400
  return null;
9296
- const { selected, matches } = matched;
9297
- const enclosing = matches.filter((entry) => entry !== selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob));
9298
9401
  return {
9299
- workspace: selected.name,
9300
- source: [selected, ...enclosing].find(has) ?? null
9402
+ workspace: matched.selected.name,
9403
+ source: chainOf(matched).find(has) ?? null
9301
9404
  };
9302
9405
  };
9303
9406
  var resolveRuntimeReleasePackages = (cwd, dir) => {
@@ -9319,6 +9422,47 @@ var changelogPathOf = (value) => {
9319
9422
  return null;
9320
9423
  return parts.includes("..") ? null : parts.join("/");
9321
9424
  };
9425
+ var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9426
+ var pickSet = (value, keys) => isPlainRecord(value) ? Object.fromEntries(keys.filter((key) => value[key] !== undefined).map((key) => [key, value[key]])) : {};
9427
+ var mapRecord = (value, map) => Object.fromEntries(Object.entries(value).map(([name, item]) => [name, map(item)]));
9428
+ var TRACK_LINE_KEYS = [
9429
+ "tagNamespace",
9430
+ "productionBranch",
9431
+ "integrationBranch",
9432
+ "baseBranch",
9433
+ "mergeBackBranches",
9434
+ "pullRequestTarget",
9435
+ "naming",
9436
+ "strategy"
9437
+ ];
9438
+ var releaseLineMapping = (entry, notes = false) => {
9439
+ if (!isPlainRecord(entry))
9440
+ return;
9441
+ const out = {};
9442
+ if (notes && entry.releaseNotes !== undefined)
9443
+ out.releaseNotes = entry.releaseNotes;
9444
+ if (entry.releaseTagPrefix !== undefined)
9445
+ out.releaseTagPrefix = entry.releaseTagPrefix;
9446
+ if (entry.defaultProfile !== undefined)
9447
+ out.defaultProfile = entry.defaultProfile;
9448
+ const policy = pickSet(entry.branchPolicy, ["releaseTagPrefix"]);
9449
+ if (Object.keys(policy).length)
9450
+ out.branchPolicy = policy;
9451
+ const profiles = Object.fromEntries(Object.entries(isPlainRecord(entry.profiles) ? entry.profiles : {}).flatMap(([name, profile]) => {
9452
+ const prefix = pickSet(isPlainRecord(profile) ? profile.branchPolicy : undefined, [
9453
+ "releaseTagPrefix"
9454
+ ]);
9455
+ return Object.keys(prefix).length ? [[name, { branchPolicy: prefix }]] : [];
9456
+ }));
9457
+ if (Object.keys(profiles).length)
9458
+ out.profiles = profiles;
9459
+ const trackKeys = notes ? [...TRACK_LINE_KEYS, "releaseNotes"] : TRACK_LINE_KEYS;
9460
+ if (entry.releaseTracks !== undefined)
9461
+ out.releaseTracks = isPlainRecord(entry.releaseTracks) ? mapRecord(entry.releaseTracks, (track) => pickSet(track, trackKeys)) : entry.releaseTracks;
9462
+ if (entry.releasePackages !== undefined)
9463
+ out.releasePackages = isPlainRecord(entry.releasePackages) ? mapRecord(entry.releasePackages, (pkg) => pickSet(pkg, ["tagNamespace"])) : entry.releasePackages;
9464
+ return Object.keys(out).length ? out : undefined;
9465
+ };
9322
9466
  var modelSources = (cwd, dir) => {
9323
9467
  const out = [];
9324
9468
  try {
@@ -9335,7 +9479,7 @@ var modelSources = (cwd, dir) => {
9335
9479
  }
9336
9480
  } catch {}
9337
9481
  try {
9338
- const document = JSON.parse(readFileSync4(path9.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
9482
+ const document = JSON.parse(readFileSync5(path10.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
9339
9483
  if (document && typeof document === "object" && !Array.isArray(document))
9340
9484
  out.push({
9341
9485
  name: "global",
@@ -9400,11 +9544,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
9400
9544
 
9401
9545
  // packages/workit-core/src/core/vcs-config.ts
9402
9546
  import fs6 from "node:fs";
9403
- import path10 from "node:path";
9547
+ import path11 from "node:path";
9404
9548
  import { spawnSync as spawnSync8 } from "node:child_process";
9405
9549
 
9406
9550
  // packages/workit-core/src/core/release-tracks.ts
9407
- import { createHash as createHash7 } from "node:crypto";
9551
+ import { createHash as createHash8 } from "node:crypto";
9408
9552
  import { spawnSync as spawnSync7 } from "node:child_process";
9409
9553
  class ReleaseTrackError extends Error {
9410
9554
  }
@@ -9787,7 +9931,7 @@ function resolveTrackFor(cwd, options) {
9787
9931
  ]) ?? "",
9788
9932
  git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
9789
9933
  ] : [];
9790
- key = createHash7("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
9934
+ key = createHash8("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
9791
9935
  const hit = memo2.get(key);
9792
9936
  if (hit)
9793
9937
  return hit;
@@ -9802,7 +9946,7 @@ function resolveTrackFor(cwd, options) {
9802
9946
  }
9803
9947
 
9804
9948
  // packages/workit-core/src/core/vcs-config.ts
9805
- var workspacesPath2 = () => path10.join(configDir2(), "workspaces.json");
9949
+ var workspacesPath2 = () => path11.join(configDir2(), "workspaces.json");
9806
9950
  var vcsCwd = (cwd) => cwd ?? process.env.WORKIT_WORKSPACE_ROOT ?? process.cwd();
9807
9951
  var remoteProvider = (cwd) => {
9808
9952
  const url = originUrl(cwd) ?? "";
@@ -10014,7 +10158,7 @@ function vcsConfig(mode, cwd, options = {}) {
10014
10158
  const prov = cfg[provider] ?? {};
10015
10159
  const out = {
10016
10160
  ok: true,
10017
- configPath: path10.resolve(cfgPath),
10161
+ configPath: path11.resolve(cfgPath),
10018
10162
  provider,
10019
10163
  defaultTargetBranch: workspaceDefault,
10020
10164
  pr: cfg.pr ?? {},
@@ -10245,7 +10389,7 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
10245
10389
  const source = resolved.provenance.branchPolicy;
10246
10390
  const allowed = branchPolicy.allowed.map((pattern) => `${pattern.source}/${pattern.flags}`).toSorted();
10247
10391
  const protectedRefs = [...branchPolicy.protected].map((name) => name.toLowerCase()).toSorted();
10248
- const fingerprint = createHash8("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
10392
+ const fingerprint = createHash9("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
10249
10393
  return {
10250
10394
  branchPolicy,
10251
10395
  namePolicy: { allowed: branchPolicy.allowed, protected: branchPolicy.protected },
@@ -10358,7 +10502,7 @@ var homePattern = new RegExp(`${escapeRegExp2(os4.homedir())}(?=[/\\\\]|$)|\\$HO
10358
10502
  // packages/workit-core/src/store/folder-store.ts
10359
10503
  import fs7 from "node:fs";
10360
10504
  import os5 from "node:os";
10361
- import path11 from "node:path";
10505
+ import path12 from "node:path";
10362
10506
  var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
10363
10507
  var MOVED_POINTER = "MOVED-TO-STATE.txt";
10364
10508
  var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
@@ -10367,7 +10511,7 @@ var MARKER = "workspace.json";
10367
10511
  var v2Workspace = (workit) => {
10368
10512
  let bytes;
10369
10513
  try {
10370
- bytes = fs7.readFileSync(path11.join(workit, MARKER), "utf8");
10514
+ bytes = fs7.readFileSync(path12.join(workit, MARKER), "utf8");
10371
10515
  } catch {
10372
10516
  return null;
10373
10517
  }
@@ -10416,7 +10560,7 @@ var strayEntries = (workit) => {
10416
10560
  } catch {
10417
10561
  return [];
10418
10562
  }
10419
- return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path11.join(workit, name))) && !(name === "tasks" && onlyStubs(path11.join(workit, name))));
10563
+ return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path12.join(workit, name))) && !(name === "tasks" && onlyStubs(path12.join(workit, name))));
10420
10564
  };
10421
10565
  var folderStoreIo = {
10422
10566
  rename: (from, to) => fs7.renameSync(from, to),
@@ -10424,13 +10568,13 @@ var folderStoreIo = {
10424
10568
  judgedStale: () => {}
10425
10569
  };
10426
10570
  var tempSeq = 0;
10427
- var tempBeside = (file) => path11.join(path11.dirname(file), `.${path11.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
10571
+ var tempBeside = (file) => path12.join(path12.dirname(file), `.${path12.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
10428
10572
  var copyInto = (from, to) => {
10429
10573
  const stat = fs7.lstatSync(from);
10430
10574
  if (stat.isDirectory()) {
10431
10575
  fs7.mkdirSync(to, { recursive: true });
10432
10576
  for (const name of fs7.readdirSync(from))
10433
- copyInto(path11.join(from, name), path11.join(to, name));
10577
+ copyInto(path12.join(from, name), path12.join(to, name));
10434
10578
  return;
10435
10579
  }
10436
10580
  if (exists(to))
@@ -10481,7 +10625,7 @@ var merge2 = (from, to, rel, moved) => {
10481
10625
  }
10482
10626
  if (!isDir(from) || !isDir(to))
10483
10627
  return [rel];
10484
- const kept = fs7.readdirSync(from).flatMap((name) => merge2(path11.join(from, name), path11.join(to, name), `${rel}/${name}`, moved));
10628
+ const kept = fs7.readdirSync(from).flatMap((name) => merge2(path12.join(from, name), path12.join(to, name), `${rel}/${name}`, moved));
10485
10629
  try {
10486
10630
  if (fs7.readdirSync(from).length === 0)
10487
10631
  fs7.rmdirSync(from);
@@ -10560,38 +10704,38 @@ var takeMoveLock = (target) => {
10560
10704
  pause(25);
10561
10705
  }
10562
10706
  };
10563
- var canonical3 = (dir) => {
10707
+ var canonical4 = (dir) => {
10564
10708
  try {
10565
10709
  return fs7.realpathSync.native(dir);
10566
10710
  } catch {
10567
- return path11.resolve(dir);
10711
+ return path12.resolve(dir);
10568
10712
  }
10569
10713
  };
10570
10714
  var below = (parent, child) => {
10571
- const rel = path11.relative(parent, child);
10572
- return rel !== "" && !rel.startsWith("..") && !path11.isAbsolute(rel);
10715
+ const rel = path12.relative(parent, child);
10716
+ return rel !== "" && !rel.startsWith("..") && !path12.isAbsolute(rel);
10573
10717
  };
10574
- var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical3(tempDir), canonical3(dir));
10718
+ var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical4(tempDir), canonical4(dir));
10575
10719
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
10576
10720
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
10577
10721
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
10578
10722
  return null;
10579
- const real = canonical3(folder);
10580
- const tmp = canonical3(tempDir);
10723
+ const real = canonical4(folder);
10724
+ const tmp = canonical4(tempDir);
10581
10725
  if (insideTempDir(folder, tempDir))
10582
10726
  return null;
10583
- return `workit test run (WORKIT_TEST_RUN): refusing to move ${path11.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
10727
+ return `workit test run (WORKIT_TEST_RUN): refusing to move ${path12.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
10584
10728
  };
10585
10729
  function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
10586
10730
  `)) {
10587
- const workit = path11.join(folder, ".workit");
10731
+ const workit = path12.join(folder, ".workit");
10588
10732
  const names = strayEntries(workit);
10589
10733
  const refusal = testRunFolderRefusal(folder, names.length > 0);
10590
10734
  if (refusal) {
10591
10735
  const run = process.env.WORKIT_TEST_RUN ?? "";
10592
- if (path11.isAbsolute(run))
10736
+ if (path12.isAbsolute(run))
10593
10737
  try {
10594
- fs7.appendFileSync(path11.join(run, TEST_RUN_REFUSALS), `${refusal}
10738
+ fs7.appendFileSync(path12.join(run, TEST_RUN_REFUSALS), `${refusal}
10595
10739
  `);
10596
10740
  } catch {}
10597
10741
  throw new Error(refusal);
@@ -10599,7 +10743,7 @@ function migrateFolderStore(folder, target, note = (line) => process.stderr.writ
10599
10743
  if (names.length === 0 || v2Workspace(workit) === true)
10600
10744
  return null;
10601
10745
  try {
10602
- fs7.mkdirSync(path11.dirname(target), { recursive: true });
10746
+ fs7.mkdirSync(path12.dirname(target), { recursive: true });
10603
10747
  } catch {
10604
10748
  return null;
10605
10749
  }
@@ -10623,7 +10767,7 @@ function moveLocked(workit, target, note) {
10623
10767
  }
10624
10768
  const result = { from: workit, to: target, moved: [], kept: [] };
10625
10769
  for (const name of names) {
10626
- result.kept.push(...merge2(path11.join(workit, name), path11.join(target, name), name, result.moved));
10770
+ result.kept.push(...merge2(path12.join(workit, name), path12.join(target, name), name, result.moved));
10627
10771
  }
10628
10772
  const left = (() => {
10629
10773
  try {
@@ -10632,13 +10776,13 @@ function moveLocked(workit, target, note) {
10632
10776
  return [];
10633
10777
  }
10634
10778
  })();
10635
- const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path11.join(workit, name)));
10779
+ const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path12.join(workit, name)));
10636
10780
  if (!v2Left && result.kept.length === 0) {
10637
- fs7.rmSync(path11.join(workit, MARKER), { force: true });
10638
- if (generatedIgnore(path11.join(workit, ".gitignore")))
10639
- fs7.rmSync(path11.join(workit, ".gitignore"), { force: true });
10781
+ fs7.rmSync(path12.join(workit, MARKER), { force: true });
10782
+ if (generatedIgnore(path12.join(workit, ".gitignore")))
10783
+ fs7.rmSync(path12.join(workit, ".gitignore"), { force: true });
10640
10784
  }
10641
- const pointer = path11.join(workit, MOVED_POINTER);
10785
+ const pointer = path12.join(workit, MOVED_POINTER);
10642
10786
  let wrote = false;
10643
10787
  if (result.kept.length > 0) {
10644
10788
  const text = `Workit keeps this folder's state in ${target}.
@@ -10665,9 +10809,9 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
10665
10809
 
10666
10810
  // packages/workit-core/src/store/paths.ts
10667
10811
  import { spawnSync as spawnSync9 } from "node:child_process";
10668
- import { createHash as createHash9 } from "node:crypto";
10812
+ import { createHash as createHash10 } from "node:crypto";
10669
10813
  import fs8 from "node:fs";
10670
- import path12 from "node:path";
10814
+ import path13 from "node:path";
10671
10815
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
10672
10816
  var gitRun = (cwd, args) => {
10673
10817
  const run = spawnSync9("git", args, {
@@ -10692,7 +10836,7 @@ var gitRun = (cwd, args) => {
10692
10836
  missing: error?.code === "ENOENT"
10693
10837
  };
10694
10838
  };
10695
- var shortHash = (value) => createHash9("sha256").update(value).digest("hex").slice(0, 12);
10839
+ var shortHash = (value) => createHash10("sha256").update(value).digest("hex").slice(0, 12);
10696
10840
  var real = (file) => {
10697
10841
  try {
10698
10842
  return fs8.realpathSync.native(file);
@@ -10709,14 +10853,14 @@ var DISCOVERY_ENV = [
10709
10853
  ];
10710
10854
  var isGitDir = (dir) => {
10711
10855
  try {
10712
- return fs8.statSync(path12.join(dir, "HEAD")).isFile() && fs8.statSync(path12.join(dir, "objects")).isDirectory() && fs8.statSync(path12.join(dir, "refs")).isDirectory();
10856
+ return fs8.statSync(path13.join(dir, "HEAD")).isFile() && fs8.statSync(path13.join(dir, "objects")).isDirectory() && fs8.statSync(path13.join(dir, "refs")).isDirectory();
10713
10857
  } catch {
10714
10858
  return false;
10715
10859
  }
10716
10860
  };
10717
10861
  var reftableRefs = (common) => {
10718
10862
  try {
10719
- return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs8.readFileSync(path12.join(common, "config"), "utf8"));
10863
+ return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs8.readFileSync(path13.join(common, "config"), "utf8"));
10720
10864
  } catch {
10721
10865
  return false;
10722
10866
  }
@@ -10736,7 +10880,7 @@ function fastGit(root) {
10736
10880
  if (device !== null && stat.dev !== device)
10737
10881
  return { kind: "none" };
10738
10882
  device = stat.dev;
10739
- const dotGit = path12.join(dir, ".git");
10883
+ const dotGit = path13.join(dir, ".git");
10740
10884
  let entry = null;
10741
10885
  try {
10742
10886
  entry = fs8.statSync(dotGit);
@@ -10757,19 +10901,19 @@ function fastGit(root) {
10757
10901
  const match = /^gitdir: (.+)$/mu.exec(text);
10758
10902
  if (!match)
10759
10903
  return null;
10760
- gitDir = path12.resolve(dir, match[1].trim());
10904
+ gitDir = path13.resolve(dir, match[1].trim());
10761
10905
  } else
10762
10906
  return null;
10763
- if (!fs8.existsSync(path12.join(gitDir, "HEAD")))
10907
+ if (!fs8.existsSync(path13.join(gitDir, "HEAD")))
10764
10908
  return null;
10765
10909
  } else if (isGitDir(dir))
10766
10910
  gitDir = dir;
10767
10911
  if (gitDir) {
10768
10912
  let common = gitDir;
10769
10913
  try {
10770
- common = path12.resolve(gitDir, fs8.readFileSync(path12.join(gitDir, "commondir"), "utf8").trim());
10914
+ common = path13.resolve(gitDir, fs8.readFileSync(path13.join(gitDir, "commondir"), "utf8").trim());
10771
10915
  } catch {}
10772
- if (!fs8.existsSync(path12.join(common, "objects")))
10916
+ if (!fs8.existsSync(path13.join(common, "objects")))
10773
10917
  return null;
10774
10918
  return {
10775
10919
  kind: "repo",
@@ -10779,7 +10923,7 @@ function fastGit(root) {
10779
10923
  reftable: reftableRefs(common)
10780
10924
  };
10781
10925
  }
10782
- const parent = path12.dirname(dir);
10926
+ const parent = path13.dirname(dir);
10783
10927
  if (parent === dir)
10784
10928
  return { kind: "none" };
10785
10929
  dir = parent;
@@ -10791,7 +10935,7 @@ var outsideGit = (root) => {
10791
10935
  return { dir, shared: false, top: null };
10792
10936
  };
10793
10937
  function resolveStore(root) {
10794
- root = path12.resolve(root);
10938
+ root = path13.resolve(root);
10795
10939
  let stat = null;
10796
10940
  try {
10797
10941
  stat = fs8.statSync(root);
@@ -10799,13 +10943,13 @@ function resolveStore(root) {
10799
10943
  if (!stat)
10800
10944
  return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
10801
10945
  if (!stat.isDirectory())
10802
- return { dir: path12.join(root, ".workit"), shared: false, top: null };
10946
+ return { dir: path13.join(root, ".workit"), shared: false, top: null };
10803
10947
  const fast = fastGit(root);
10804
10948
  if (fast?.kind === "none")
10805
10949
  return outsideGit(root);
10806
10950
  if (fast?.kind === "repo")
10807
10951
  return {
10808
- dir: path12.join(fast.common, "workit"),
10952
+ dir: path13.join(fast.common, "workit"),
10809
10953
  shared: true,
10810
10954
  top: fast.top,
10811
10955
  git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
@@ -10815,7 +10959,7 @@ function resolveStore(root) {
10815
10959
  if (run.ok && common) {
10816
10960
  const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
10817
10961
  return {
10818
- dir: path12.join(real(path12.resolve(root, common)), "workit"),
10962
+ dir: path13.join(real(path13.resolve(root, common)), "workit"),
10819
10963
  shared: true,
10820
10964
  top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
10821
10965
  };
@@ -10828,7 +10972,7 @@ function resolveStore(root) {
10828
10972
  var rebasingBranch = (gitDir) => {
10829
10973
  for (const state of ["rebase-merge", "rebase-apply"]) {
10830
10974
  try {
10831
- const ref = fs8.readFileSync(path12.join(gitDir, state, "head-name"), "utf8").trim();
10975
+ const ref = fs8.readFileSync(path13.join(gitDir, state, "head-name"), "utf8").trim();
10832
10976
  const match = /^refs\/heads\/(.+)$/u.exec(ref);
10833
10977
  if (match)
10834
10978
  return match[1];
@@ -10843,7 +10987,7 @@ function resolveTaskKey(root, location) {
10843
10987
  if (location.git && !location.git.reftable) {
10844
10988
  let head = "";
10845
10989
  try {
10846
- head = fs8.readFileSync(path12.join(location.git.gitDir, "HEAD"), "utf8").trim();
10990
+ head = fs8.readFileSync(path13.join(location.git.gitDir, "HEAD"), "utf8").trim();
10847
10991
  } catch {}
10848
10992
  const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
10849
10993
  if (ref && ref[1] !== ".invalid")
@@ -10874,7 +11018,7 @@ function resolveTaskKey(root, location) {
10874
11018
  return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
10875
11019
  }
10876
11020
  function checkoutRootOf(root, location) {
10877
- const resolved = path12.resolve(root);
11021
+ const resolved = path13.resolve(root);
10878
11022
  let canonical = resolved;
10879
11023
  try {
10880
11024
  canonical = fs8.realpathSync(resolved);
@@ -10905,13 +11049,13 @@ function branchRenames(location) {
10905
11049
  }
10906
11050
  for (const entry of entries)
10907
11051
  if (entry.isDirectory())
10908
- walk(path12.join(dir, entry.name));
11052
+ walk(path13.join(dir, entry.name));
10909
11053
  else
10910
- files.push(path12.join(dir, entry.name));
11054
+ files.push(path13.join(dir, entry.name));
10911
11055
  };
10912
- walk(path12.join(path12.dirname(location.dir), "logs", "refs", "heads"));
11056
+ walk(path13.join(path13.dirname(location.dir), "logs", "refs", "heads"));
10913
11057
  if (location.git)
10914
- files.push(path12.join(location.git.gitDir, "logs", "HEAD"));
11058
+ files.push(path13.join(location.git.gitDir, "logs", "HEAD"));
10915
11059
  const seen = new Set;
10916
11060
  const renames = [];
10917
11061
  for (const file of files) {
@@ -10977,13 +11121,13 @@ function hostSessionFromEnv(env) {
10977
11121
  }
10978
11122
  return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
10979
11123
  }
10980
- var hash2 = (value) => createHash10("sha256").update(value).digest("hex").slice(0, 32);
11124
+ var hash2 = (value) => createHash11("sha256").update(value).digest("hex").slice(0, 32);
10981
11125
  var PIN_FILE = "issued-registry";
10982
11126
  var pinFiles = new Map;
10983
11127
  var pinFile = (cwd) => {
10984
11128
  if (cwd === undefined)
10985
11129
  return null;
10986
- const key = path13.resolve(cwd);
11130
+ const key = path14.resolve(cwd);
10987
11131
  const known = pinFiles.get(key);
10988
11132
  if (known !== undefined)
10989
11133
  return known;
@@ -10991,7 +11135,7 @@ var pinFile = (cwd) => {
10991
11135
  const location = resolveStore(key);
10992
11136
  if (location instanceof Error)
10993
11137
  return null;
10994
- const file = location.shared ? path13.join(location.dir, "ledger", PIN_FILE) : null;
11138
+ const file = location.shared ? path14.join(location.dir, "ledger", PIN_FILE) : null;
10995
11139
  pinFiles.set(key, file);
10996
11140
  return file;
10997
11141
  } catch {
@@ -11004,14 +11148,14 @@ var pinnedStateDir = (cwd) => {
11004
11148
  return null;
11005
11149
  try {
11006
11150
  const pinned = fs9.readFileSync(file, "utf8").trim();
11007
- return path13.isAbsolute(pinned) ? pinned : null;
11151
+ return path14.isAbsolute(pinned) ? pinned : null;
11008
11152
  } catch {
11009
11153
  return null;
11010
11154
  }
11011
11155
  };
11012
11156
  var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
11013
- var userIssuedRoot = (cwd) => path13.join(registryDir(cwd), "issued");
11014
- var userTokenRoot = (cwd) => path13.join(registryDir(cwd), "issued-tokens");
11157
+ var userIssuedRoot = (cwd) => path14.join(registryDir(cwd), "issued");
11158
+ var userTokenRoot = (cwd) => path14.join(registryDir(cwd), "issued-tokens");
11015
11159
  function migrateRepoIssued(cwd) {
11016
11160
  if (cwd === undefined)
11017
11161
  return;
@@ -11020,7 +11164,7 @@ function migrateRepoIssued(cwd) {
11020
11164
  const location = resolveStore(cwd);
11021
11165
  if (location instanceof Error)
11022
11166
  return;
11023
- old = path13.join(location.dir, "hooks", "issued");
11167
+ old = path14.join(location.dir, "hooks", "issued");
11024
11168
  if (!fs9.existsSync(old))
11025
11169
  return;
11026
11170
  } catch {
@@ -11028,19 +11172,19 @@ function migrateRepoIssued(cwd) {
11028
11172
  }
11029
11173
  for (const lead of safeList(old)) {
11030
11174
  try {
11031
- const from = path13.join(old, lead);
11175
+ const from = path14.join(old, lead);
11032
11176
  if (!fs9.statSync(from).isDirectory())
11033
11177
  continue;
11034
- const to = path13.join(userIssuedRoot(cwd), lead);
11178
+ const to = path14.join(userIssuedRoot(cwd), lead);
11035
11179
  fs9.mkdirSync(to, { recursive: true, mode: 448 });
11036
11180
  for (const id of fs9.readdirSync(from)) {
11037
11181
  try {
11038
- fs9.copyFileSync(path13.join(from, id), path13.join(to, id), fs9.constants.COPYFILE_EXCL);
11182
+ fs9.copyFileSync(path14.join(from, id), path14.join(to, id), fs9.constants.COPYFILE_EXCL);
11039
11183
  } catch (error) {
11040
11184
  if (error.code !== "EEXIST")
11041
11185
  throw error;
11042
11186
  }
11043
- fs9.rmSync(path13.join(from, id), { force: true });
11187
+ fs9.rmSync(path14.join(from, id), { force: true });
11044
11188
  }
11045
11189
  removeIfEmpty(from);
11046
11190
  } catch {}
@@ -11082,7 +11226,7 @@ var issuedRecord = (cwd, claimed) => {
11082
11226
  return null;
11083
11227
  migrateRepoIssued(cwd);
11084
11228
  try {
11085
- return fs9.readFileSync(path13.join(userIssuedRoot(cwd), hash2(claimed.slice(0, cut)), hash2(claimed)), "utf8");
11229
+ return fs9.readFileSync(path14.join(userIssuedRoot(cwd), hash2(claimed.slice(0, cut)), hash2(claimed)), "utf8");
11086
11230
  } catch {
11087
11231
  return null;
11088
11232
  }
@@ -11092,9 +11236,9 @@ var issuedToken = (cwd, claimed) => {
11092
11236
  const cut = claimed.lastIndexOf(":");
11093
11237
  if (cut <= 0)
11094
11238
  return { stored: null, leadBound: false };
11095
- const dir = path13.join(userTokenRoot(cwd), hash2(claimed.slice(0, cut)));
11239
+ const dir = path14.join(userTokenRoot(cwd), hash2(claimed.slice(0, cut)));
11096
11240
  try {
11097
- const text = fs9.readFileSync(path13.join(dir, hash2(claimed)), "utf8");
11241
+ const text = fs9.readFileSync(path14.join(dir, hash2(claimed)), "utf8");
11098
11242
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
11099
11243
  } catch {
11100
11244
  return { stored: null, leadBound: safeList(dir).length > 0 };
@@ -11120,7 +11264,7 @@ function childSessionId(lead, child) {
11120
11264
  // packages/workit-core/src/store/event-log.ts
11121
11265
  import { randomUUID as randomUUID2 } from "node:crypto";
11122
11266
  import fs10 from "node:fs";
11123
- import path14 from "node:path";
11267
+ import path15 from "node:path";
11124
11268
  var EVENT_VERSION = 1;
11125
11269
 
11126
11270
  class LogDamage extends Error {
@@ -11231,7 +11375,7 @@ function appendEvent(file, event, validEnd) {
11231
11375
  fs10.closeSync(fd);
11232
11376
  }
11233
11377
  if (created)
11234
- fsyncDirectory(path14.dirname(file));
11378
+ fsyncDirectory(path15.dirname(file));
11235
11379
  return validEnd;
11236
11380
  }
11237
11381
  function replaceFile(file, bytes, durable) {
@@ -11247,7 +11391,7 @@ function replaceFile(file, bytes, durable) {
11247
11391
  }
11248
11392
  renameWithRetry(temporary, file);
11249
11393
  if (durable)
11250
- fsyncDirectory(path14.dirname(file));
11394
+ fsyncDirectory(path15.dirname(file));
11251
11395
  } catch (error) {
11252
11396
  try {
11253
11397
  fs10.unlinkSync(temporary);
@@ -11404,7 +11548,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
11404
11548
  });
11405
11549
 
11406
11550
  // packages/workit-core/src/store/reduce.ts
11407
- import { createHash as createHash11 } from "node:crypto";
11551
+ import { createHash as createHash12 } from "node:crypto";
11408
11552
  var OPENING_TYPES = new Set([
11409
11553
  "task.opened",
11410
11554
  "task.imported",
@@ -11433,7 +11577,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
11433
11577
  var isKey = (value) => isObject4(value) && typeof value.key === "string" && (value.kind === "branch" || value.kind === "detached" || value.kind === "dir") && (value.branch === null || typeof value.branch === "string");
11434
11578
  var BLOB_REF = "$blob";
11435
11579
  var blobRef = (value) => isObject4(value) && Object.keys(value).length === 1 && typeof value[BLOB_REF] === "string" && /^[0-9a-f]{64}$/.test(value[BLOB_REF]) ? value[BLOB_REF] : null;
11436
- var blobDigest = (value) => createHash11("sha256").update(JSON.stringify(value)).digest("hex");
11580
+ var blobDigest = (value) => createHash12("sha256").update(JSON.stringify(value)).digest("hex");
11437
11581
  var toBlob = (value, blobs) => {
11438
11582
  if (!isObject4(value))
11439
11583
  return value;
@@ -11548,7 +11692,7 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
11548
11692
  // packages/workit-core/src/core/task-read.ts
11549
11693
  import { randomUUID as randomUUID3 } from "node:crypto";
11550
11694
  import * as fs15 from "node:fs";
11551
- import path18 from "node:path";
11695
+ import path19 from "node:path";
11552
11696
 
11553
11697
  // node_modules/@openclaw/fs-safe/dist/errors.js
11554
11698
  var OPERATIONAL_CODES = new Set([
@@ -11599,7 +11743,7 @@ function sameFileIdentity(left, right, platform = process.platform) {
11599
11743
  // node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
11600
11744
  import { randomBytes as randomBytes2 } from "node:crypto";
11601
11745
  import fsSync from "node:fs";
11602
- import path15 from "node:path";
11746
+ import path16 from "node:path";
11603
11747
 
11604
11748
  // node_modules/@openclaw/fs-safe/dist/bounded-read.js
11605
11749
  import fs11 from "node:fs";
@@ -11689,13 +11833,13 @@ ${ownershipToken}
11689
11833
  return { raw, ownershipToken };
11690
11834
  }
11691
11835
  function relativeSidecarLockPath(lockRoot, lockPath) {
11692
- const resolved = path15.resolve(lockPath);
11693
- const lexicalRelative = path15.relative(lockRoot.rootDir, resolved);
11694
- const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path15.sep}`) && !path15.isAbsolute(lexicalRelative) ? lexicalRelative : path15.relative(lockRoot.rootReal, resolved);
11695
- if (!relative || relative === ".." || relative.startsWith(`..${path15.sep}`) || path15.isAbsolute(relative)) {
11836
+ const resolved = path16.resolve(lockPath);
11837
+ const lexicalRelative = path16.relative(lockRoot.rootDir, resolved);
11838
+ const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path16.sep}`) && !path16.isAbsolute(lexicalRelative) ? lexicalRelative : path16.relative(lockRoot.rootReal, resolved);
11839
+ if (!relative || relative === ".." || relative.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative)) {
11696
11840
  throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
11697
11841
  }
11698
- return relative.split(path15.sep).join(path15.posix.sep);
11842
+ return relative.split(path16.sep).join(path16.posix.sep);
11699
11843
  }
11700
11844
  function parseSidecarLockPayload(raw, parser) {
11701
11845
  if (parser) {
@@ -11842,7 +11986,7 @@ function getFsSafeLockConfig() {
11842
11986
 
11843
11987
  // node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
11844
11988
  import fs13 from "node:fs";
11845
- import path16 from "node:path";
11989
+ import path17 from "node:path";
11846
11990
 
11847
11991
  // node_modules/@openclaw/fs-safe/dist/timing.js
11848
11992
  function sleepSync(ms) {
@@ -11933,26 +12077,26 @@ function canonicalLockParentSync(parent) {
11933
12077
  return process.platform === "win32" ? fs13.realpathSync.native(parent) : fs13.realpathSync(parent);
11934
12078
  }
11935
12079
  function normalizeTargetPath(targetPath) {
11936
- const resolved = path16.resolve(targetPath);
11937
- fs13.mkdirSync(path16.dirname(resolved), { recursive: true });
12080
+ const resolved = path17.resolve(targetPath);
12081
+ fs13.mkdirSync(path17.dirname(resolved), { recursive: true });
11938
12082
  try {
11939
- return path16.join(canonicalLockParentSync(path16.dirname(resolved)), path16.basename(resolved));
12083
+ return path17.join(canonicalLockParentSync(path17.dirname(resolved)), path17.basename(resolved));
11940
12084
  } catch {
11941
12085
  return resolved;
11942
12086
  }
11943
12087
  }
11944
12088
  function boundedLockPath(lockPath, lockRoot) {
11945
- const resolved = path16.resolve(lockPath);
12089
+ const resolved = path17.resolve(lockPath);
11946
12090
  if (!lockRoot)
11947
12091
  return resolved;
11948
12092
  relativeSidecarLockPath(lockRoot, resolved);
11949
- const parent = path16.dirname(resolved);
12093
+ const parent = path17.dirname(resolved);
11950
12094
  const parentReal = canonicalLockParentSync(parent);
11951
- const parentRelative = path16.relative(lockRoot.rootReal, parentReal);
11952
- if (parentRelative === ".." || parentRelative.startsWith(`..${path16.sep}`) || path16.isAbsolute(parentRelative)) {
12095
+ const parentRelative = path17.relative(lockRoot.rootReal, parentReal);
12096
+ if (parentRelative === ".." || parentRelative.startsWith(`..${path17.sep}`) || path17.isAbsolute(parentRelative)) {
11953
12097
  throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
11954
12098
  }
11955
- return path16.join(parentReal, path16.basename(resolved));
12099
+ return path17.join(parentReal, path17.basename(resolved));
11956
12100
  }
11957
12101
  function defaultShouldReclaim(snapshot, staleMs, nowMs) {
11958
12102
  const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
@@ -12153,20 +12297,20 @@ function acquireFileLockSync(targetPath, options) {
12153
12297
  }
12154
12298
  // packages/workit-core/src/core/package-root.ts
12155
12299
  import { existsSync as existsSync5 } from "node:fs";
12156
- import path17 from "node:path";
12300
+ import path18 from "node:path";
12157
12301
  import { fileURLToPath } from "node:url";
12158
12302
  var packageRoot = () => {
12159
- let dir = path17.dirname(fileURLToPath(import.meta.url));
12303
+ let dir = path18.dirname(fileURLToPath(import.meta.url));
12160
12304
  while (true) {
12161
- const parent = path17.dirname(dir);
12162
- if (existsSync5(path17.join(dir, "package.json")) || parent === dir)
12305
+ const parent = path18.dirname(dir);
12306
+ if (existsSync5(path18.join(dir, "package.json")) || parent === dir)
12163
12307
  return dir;
12164
12308
  dir = parent;
12165
12309
  }
12166
12310
  };
12167
12311
  var assetRoot = () => {
12168
12312
  const root = packageRoot();
12169
- const assets = path17.join(root, "assets");
12313
+ const assets = path18.join(root, "assets");
12170
12314
  return existsSync5(assets) ? assets : root;
12171
12315
  };
12172
12316
 
@@ -12374,7 +12518,7 @@ var cachedRuntimeVersion = null;
12374
12518
  var runtimeVersion = () => {
12375
12519
  if (cachedRuntimeVersion === null) {
12376
12520
  try {
12377
- const pkg = JSON.parse(fs15.readFileSync(path18.join(packageRoot(), "package.json"), "utf8"));
12521
+ const pkg = JSON.parse(fs15.readFileSync(path19.join(packageRoot(), "package.json"), "utf8"));
12378
12522
  cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
12379
12523
  } catch {
12380
12524
  cachedRuntimeVersion = "0.0.0";
@@ -12403,7 +12547,7 @@ var readText2 = (file) => {
12403
12547
  };
12404
12548
  var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
12405
12549
  var branchStart = (location, branch, aliases) => {
12406
- const first = readText2(path18.join(path18.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
12550
+ const first = readText2(path19.join(path19.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
12407
12551
  `, 1)[0];
12408
12552
  const created = REFLOG_LINE.exec(first);
12409
12553
  const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
@@ -12413,7 +12557,7 @@ var branchStart = (location, branch, aliases) => {
12413
12557
  return start;
12414
12558
  if (!location.git)
12415
12559
  return null;
12416
- for (const line of readText2(path18.join(location.git.gitDir, "logs", "HEAD")).split(`
12560
+ for (const line of readText2(path19.join(location.git.gitDir, "logs", "HEAD")).split(`
12417
12561
  `)) {
12418
12562
  const entry = REFLOG_LINE.exec(line);
12419
12563
  const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
@@ -12423,14 +12567,14 @@ var branchStart = (location, branch, aliases) => {
12423
12567
  }
12424
12568
  return null;
12425
12569
  };
12426
- var refExists2 = (common, ref) => fs15.existsSync(path18.join(common, ref)) || readText2(path18.join(common, "packed-refs")).includes(` ${ref}
12570
+ var refExists2 = (common, ref) => fs15.existsSync(path19.join(common, ref)) || readText2(path19.join(common, "packed-refs")).includes(` ${ref}
12427
12571
  `);
12428
12572
  var origins = new Map;
12429
12573
  var sameDirectoryIdentity = (left, right) => {
12430
- if (!path18.isAbsolute(left) || !path18.isAbsolute(right))
12574
+ if (!path19.isAbsolute(left) || !path19.isAbsolute(right))
12431
12575
  return false;
12432
- const normalizedLeft = path18.resolve(left);
12433
- const normalizedRight = path18.resolve(right);
12576
+ const normalizedLeft = path19.resolve(left);
12577
+ const normalizedRight = path19.resolve(right);
12434
12578
  try {
12435
12579
  const a = fs15.statSync(normalizedLeft, { bigint: true });
12436
12580
  const b = fs15.statSync(normalizedRight, { bigint: true });
@@ -12464,14 +12608,14 @@ class TaskReader {
12464
12608
  located;
12465
12609
  migrationChecked = false;
12466
12610
  constructor(root, options = {}) {
12467
- const resolved = path18.resolve(root);
12611
+ const resolved = path19.resolve(root);
12468
12612
  this.origin = fs15.existsSync(resolved) ? fs15.realpathSync(resolved) : resolved;
12469
12613
  this.located = resolveStore(this.origin);
12470
12614
  this.root = checkoutRootOf(this.origin, this.located);
12471
12615
  this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
12472
12616
  }
12473
12617
  location() {
12474
- if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs15.existsSync(path18.join(this.root, ".git"))) {
12618
+ if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs15.existsSync(path19.join(this.root, ".git"))) {
12475
12619
  this.located = undefined;
12476
12620
  this.migrationChecked = false;
12477
12621
  }
@@ -12629,14 +12773,14 @@ class TaskReader {
12629
12773
  const branch = key.ok ? key.data.branch : null;
12630
12774
  if (!branch || !location.ok)
12631
12775
  return success(null, null, null);
12632
- const common = path18.dirname(location.data.dir);
12633
- const heads = path18.join(common, "logs", "refs", "heads");
12634
- const headLog = location.data.git ? path18.join(location.data.git.gitDir, "logs", "HEAD") : "";
12776
+ const common = path19.dirname(location.data.dir);
12777
+ const heads = path19.join(common, "logs", "refs", "heads");
12778
+ const headLog = location.data.git ? path19.join(location.data.git.gitDir, "logs", "HEAD") : "";
12635
12779
  const signatures = [
12636
- path18.join(heads, branch),
12780
+ path19.join(heads, branch),
12637
12781
  headLog,
12638
12782
  heads,
12639
- path18.join(common, "packed-refs")
12783
+ path19.join(common, "packed-refs")
12640
12784
  ].map((file) => fileSignature(file) ?? "-");
12641
12785
  const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
12642
12786
  let resolved = origins.get(slot);
@@ -12648,7 +12792,7 @@ class TaskReader {
12648
12792
  aliases.push(rename.from);
12649
12793
  const start = branchStart(location.data, branch, aliases);
12650
12794
  const slash = start?.indexOf("/") ?? -1;
12651
- const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path18.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
12795
+ const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path19.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
12652
12796
  const name = start && (remote ? start.slice(slash + 1) : start);
12653
12797
  resolved = {
12654
12798
  signature: signatures.join("|"),
@@ -12668,27 +12812,27 @@ class TaskReader {
12668
12812
  }
12669
12813
  paths() {
12670
12814
  const location = this.location();
12671
- const dir = location.ok ? location.data.dir : path18.join(this.root, ".workit");
12672
- const checkout = path18.join(dir, "checkouts", checkoutSlug(this.root));
12815
+ const dir = location.ok ? location.data.dir : path19.join(this.root, ".workit");
12816
+ const checkout = path19.join(dir, "checkouts", checkoutSlug(this.root));
12673
12817
  return {
12674
12818
  dir,
12675
12819
  shared: location.ok ? location.data.shared : false,
12676
- marker: path18.join(dir, "store.json"),
12820
+ marker: path19.join(dir, "store.json"),
12677
12821
  checkout,
12678
- workspace: path18.join(checkout, "workspace.json"),
12679
- checkoutLock: path18.join(checkout, "metadata.lock"),
12680
- tasks: path18.join(dir, "tasks"),
12681
- index: path18.join(dir, "task-index.json"),
12682
- blobs: path18.join(dir, "blobs", "candidates"),
12683
- legacy: path18.join(dir, "legacy", checkoutSlug(this.root), "v2"),
12684
- v2: path18.join(this.root, ".workit")
12822
+ workspace: path19.join(checkout, "workspace.json"),
12823
+ checkoutLock: path19.join(checkout, "metadata.lock"),
12824
+ tasks: path19.join(dir, "tasks"),
12825
+ index: path19.join(dir, "task-index.json"),
12826
+ blobs: path19.join(dir, "blobs", "candidates"),
12827
+ legacy: path19.join(dir, "legacy", checkoutSlug(this.root), "v2"),
12828
+ v2: path19.join(this.root, ".workit")
12685
12829
  };
12686
12830
  }
12687
12831
  eventsPath(taskId) {
12688
- return path18.join(this.paths().tasks, taskId, "events.jsonl");
12832
+ return path19.join(this.paths().tasks, taskId, "events.jsonl");
12689
12833
  }
12690
12834
  snapshotPath(taskId) {
12691
- return path18.join(this.paths().tasks, taskId, "snapshot.json");
12835
+ return path19.join(this.paths().tasks, taskId, "snapshot.json");
12692
12836
  }
12693
12837
  ready(write = false) {
12694
12838
  const location = this.location();
@@ -12723,7 +12867,7 @@ class TaskReader {
12723
12867
  return {
12724
12868
  read: (digest) => {
12725
12869
  try {
12726
- return JSON.parse(fs15.readFileSync(path18.join(dir, `${digest}.json`), "utf8"));
12870
+ return JSON.parse(fs15.readFileSync(path19.join(dir, `${digest}.json`), "utf8"));
12727
12871
  } catch (error) {
12728
12872
  throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
12729
12873
  }
@@ -12889,11 +13033,11 @@ class TaskReader {
12889
13033
  return failure2("recovery_required", `${label} record does not satisfy its schema`);
12890
13034
  }
12891
13035
  v2Dirs() {
12892
- return [...new Set([this.root, this.origin])].map((dir) => path18.join(dir, ".workit"));
13036
+ return [...new Set([this.root, this.origin])].map((dir) => path19.join(dir, ".workit"));
12893
13037
  }
12894
13038
  pendingMigrations() {
12895
13039
  return this.v2Dirs().filter((dir) => {
12896
- const raw = this.readV2Workspace(path18.join(dir, "workspace.json"));
13040
+ const raw = this.readV2Workspace(path19.join(dir, "workspace.json"));
12897
13041
  return raw !== null && raw !== TOMBSTONE;
12898
13042
  });
12899
13043
  }
@@ -12909,7 +13053,7 @@ class TaskReader {
12909
13053
  }
12910
13054
  adoptStoreFrom(local) {
12911
13055
  const dirs = this.paths();
12912
- const marker = path18.join(local, "store.json");
13056
+ const marker = path19.join(local, "store.json");
12913
13057
  if (!fs15.existsSync(marker))
12914
13058
  return success(null, null, null);
12915
13059
  return this.withLock(dirs.checkoutLock, () => {
@@ -12919,7 +13063,7 @@ class TaskReader {
12919
13063
  try {
12920
13064
  const merge = (from, to) => {
12921
13065
  if (!fs15.existsSync(to)) {
12922
- fs15.mkdirSync(path18.dirname(to), { recursive: true });
13066
+ fs15.mkdirSync(path19.dirname(to), { recursive: true });
12923
13067
  try {
12924
13068
  fs15.renameSync(from, to);
12925
13069
  } catch {
@@ -12930,24 +13074,24 @@ class TaskReader {
12930
13074
  }
12931
13075
  if (fs15.lstatSync(from).isDirectory() && fs15.lstatSync(to).isDirectory())
12932
13076
  for (const name of fs15.readdirSync(from))
12933
- merge(path18.join(from, name), path18.join(to, name));
13077
+ merge(path19.join(from, name), path19.join(to, name));
12934
13078
  };
12935
13079
  for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
12936
- const from = path18.join(local, sub);
13080
+ const from = path19.join(local, sub);
12937
13081
  if (!fs15.existsSync(from))
12938
13082
  continue;
12939
13083
  if (sub === "tasks") {
12940
13084
  for (const name of fs15.readdirSync(from))
12941
- if (validId(name) && !fs15.existsSync(path18.join(dirs.dir, sub, name)))
13085
+ if (validId(name) && !fs15.existsSync(path19.join(dirs.dir, sub, name)))
12942
13086
  tasks += 1;
12943
13087
  }
12944
- merge(from, path18.join(dirs.dir, sub));
13088
+ merge(from, path19.join(dirs.dir, sub));
12945
13089
  }
12946
- const ledger = path18.join(local, "ledger");
12947
- if (fs15.existsSync(ledger) && !fs15.existsSync(path18.join(dirs.dir, "ledger")))
12948
- merge(ledger, path18.join(dirs.dir, "ledger"));
12949
- fs15.rmSync(path18.join(local, "task-index.json"), { force: true });
12950
- fs15.renameSync(marker, path18.join(local, "store.moved.json"));
13090
+ const ledger = path19.join(local, "ledger");
13091
+ if (fs15.existsSync(ledger) && !fs15.existsSync(path19.join(dirs.dir, "ledger")))
13092
+ merge(ledger, path19.join(dirs.dir, "ledger"));
13093
+ fs15.rmSync(path19.join(local, "task-index.json"), { force: true });
13094
+ fs15.renameSync(marker, path19.join(local, "store.moved.json"));
12951
13095
  } catch (error) {
12952
13096
  return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
12953
13097
  path: local
@@ -12985,7 +13129,7 @@ class TaskReader {
12985
13129
  schemaVersion: SCHEMA_VERSION,
12986
13130
  id: workspaceId ?? newId(),
12987
13131
  revision: newRevision(),
12988
- root: path18.dirname(v2),
13132
+ root: path19.dirname(v2),
12989
13133
  runtime: { createdWith: version, updatedWith: version },
12990
13134
  writer: null,
12991
13135
  store: {
@@ -12997,11 +13141,11 @@ class TaskReader {
12997
13141
  critical: ["store"]
12998
13142
  };
12999
13143
  fs15.mkdirSync(v2, { recursive: true });
13000
- const ignore = path18.join(v2, ".gitignore");
13144
+ const ignore = path19.join(v2, ".gitignore");
13001
13145
  if (!fs15.existsSync(ignore))
13002
13146
  fs15.writeFileSync(ignore, `*
13003
13147
  `);
13004
- replaceFile(path18.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
13148
+ replaceFile(path19.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
13005
13149
  `, true);
13006
13150
  }
13007
13151
  initializeStorage() {
@@ -13060,7 +13204,7 @@ class TaskReader {
13060
13204
  withLock(lockPath, operation) {
13061
13205
  try {
13062
13206
  this.initializeStorage();
13063
- fs15.mkdirSync(path18.dirname(lockPath), { recursive: true });
13207
+ fs15.mkdirSync(path19.dirname(lockPath), { recursive: true });
13064
13208
  } catch (error) {
13065
13209
  return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
13066
13210
  path: this.paths().dir
@@ -13123,7 +13267,7 @@ class TaskReader {
13123
13267
  if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
13124
13268
  return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
13125
13269
  path: lockPath,
13126
- guidance: `Check permissions and the read-only attribute on ${path18.dirname(lockPath)}.`
13270
+ guidance: `Check permissions and the read-only attribute on ${path19.dirname(lockPath)}.`
13127
13271
  });
13128
13272
  if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
13129
13273
  let lock = null;
@@ -13178,7 +13322,7 @@ var moveInto = (from, to) => {
13178
13322
  target = `${to}.dir`;
13179
13323
  fs16.mkdirSync(target, { recursive: true });
13180
13324
  for (const name of fs16.readdirSync(from))
13181
- moveInto(path19.join(from, name), path19.join(target, name));
13325
+ moveInto(path20.join(from, name), path20.join(target, name));
13182
13326
  fs16.rmdirSync(from);
13183
13327
  return;
13184
13328
  }
@@ -13189,13 +13333,13 @@ var moveInto = (from, to) => {
13189
13333
  fs16.rmSync(from);
13190
13334
  return;
13191
13335
  }
13192
- target = `${to}.${createHash12("sha256").update(bytes).digest("hex").slice(0, 12)}`;
13336
+ target = `${to}.${createHash13("sha256").update(bytes).digest("hex").slice(0, 12)}`;
13193
13337
  if (fs16.existsSync(target)) {
13194
13338
  fs16.rmSync(from);
13195
13339
  return;
13196
13340
  }
13197
13341
  }
13198
- fs16.mkdirSync(path19.dirname(target), { recursive: true });
13342
+ fs16.mkdirSync(path20.dirname(target), { recursive: true });
13199
13343
  try {
13200
13344
  fs16.renameSync(from, target);
13201
13345
  } catch {
@@ -13263,7 +13407,7 @@ class TaskStore extends TaskReader {
13263
13407
  const moved = this.bindLocked(again.data.id, key, input.now);
13264
13408
  return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
13265
13409
  }
13266
- const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path19.basename(this.root) || this.root;
13410
+ const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path20.basename(this.root) || this.root;
13267
13411
  const intent = {
13268
13412
  objective: input.objective?.trim() || `Work on ${label}`,
13269
13413
  scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
@@ -13511,13 +13655,13 @@ class TaskStore extends TaskReader {
13511
13655
  if (!ready.ok)
13512
13656
  return ready;
13513
13657
  const dirs = this.paths();
13514
- const recovery = [path19.join(this.root, ".workit", "recovery"), path19.join(dirs.legacy, "recovery")].find((dir) => fs16.existsSync(dir)) ?? null;
13658
+ const recovery = [path20.join(this.root, ".workit", "recovery"), path20.join(dirs.legacy, "recovery")].find((dir) => fs16.existsSync(dir)) ?? null;
13515
13659
  if (recovery) {
13516
13660
  let files = 0;
13517
13661
  let bytes = 0;
13518
13662
  try {
13519
13663
  for (const name of fs16.readdirSync(recovery)) {
13520
- const stat = fs16.lstatSync(path19.join(recovery, name));
13664
+ const stat = fs16.lstatSync(path20.join(recovery, name));
13521
13665
  if (!stat.isFile())
13522
13666
  continue;
13523
13667
  files += 1;
@@ -13570,7 +13714,7 @@ class TaskStore extends TaskReader {
13570
13714
  if (fs16.existsSync(dirs.blobs))
13571
13715
  for (const name of fs16.readdirSync(dirs.blobs)) {
13572
13716
  const digest = name.replace(/\.json$/, "");
13573
- const file = path19.join(dirs.blobs, name);
13717
+ const file = path20.join(dirs.blobs, name);
13574
13718
  let stat;
13575
13719
  try {
13576
13720
  stat = fs16.lstatSync(file);
@@ -13588,7 +13732,7 @@ class TaskStore extends TaskReader {
13588
13732
  }
13589
13733
  return success(null, null, null);
13590
13734
  };
13591
- const swept = dryRun ? sweep() : this.withLock(path19.join(dirs.dir, "gc.lock"), sweep);
13735
+ const swept = dryRun ? sweep() : this.withLock(path20.join(dirs.dir, "gc.lock"), sweep);
13592
13736
  if (!swept.ok)
13593
13737
  return swept;
13594
13738
  const temporaryDirs = [
@@ -13596,7 +13740,7 @@ class TaskStore extends TaskReader {
13596
13740
  dirs.tasks,
13597
13741
  dirs.blobs,
13598
13742
  dirs.checkout,
13599
- ...names.map((name) => path19.join(dirs.tasks, name))
13743
+ ...names.map((name) => path20.join(dirs.tasks, name))
13600
13744
  ];
13601
13745
  for (const directory of temporaryDirs) {
13602
13746
  if (!fs16.existsSync(directory))
@@ -13604,7 +13748,7 @@ class TaskStore extends TaskReader {
13604
13748
  for (const name of fs16.readdirSync(directory)) {
13605
13749
  if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
13606
13750
  continue;
13607
- const file = path19.join(directory, name);
13751
+ const file = path20.join(directory, name);
13608
13752
  try {
13609
13753
  const stat = fs16.lstatSync(file);
13610
13754
  if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
@@ -13620,7 +13764,7 @@ class TaskStore extends TaskReader {
13620
13764
  return success(null, null, report);
13621
13765
  }
13622
13766
  taskLockPath(taskId) {
13623
- return path19.join(this.paths().tasks, taskId, "lock");
13767
+ return path20.join(this.paths().tasks, taskId, "lock");
13624
13768
  }
13625
13769
  settleMigrations(write) {
13626
13770
  const moved = this.adoptLocalStore();
@@ -13649,7 +13793,7 @@ class TaskStore extends TaskReader {
13649
13793
  return {
13650
13794
  read: (digest) => reader.read(digest),
13651
13795
  write: (digest, value) => {
13652
- const file = path19.join(dir, `${digest}.json`);
13796
+ const file = path20.join(dir, `${digest}.json`);
13653
13797
  if (fs16.existsSync(file)) {
13654
13798
  const stamp = new Date;
13655
13799
  try {
@@ -13751,7 +13895,7 @@ class TaskStore extends TaskReader {
13751
13895
  }
13752
13896
  }
13753
13897
  openTask(record, type, key, legacy = null) {
13754
- const dir = path19.join(this.paths().tasks, record.id);
13898
+ const dir = path20.join(this.paths().tasks, record.id);
13755
13899
  fs16.mkdirSync(dir, { recursive: true });
13756
13900
  const blobs = this.blobStore();
13757
13901
  const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
@@ -13831,8 +13975,8 @@ class TaskStore extends TaskReader {
13831
13975
  }
13832
13976
  }
13833
13977
  withKeyLock(key, operation) {
13834
- const digest = createHash12("sha256").update(key).digest("hex").slice(0, 32);
13835
- return this.withLock(path19.join(this.paths().dir, "keys", `${digest}.lock`), operation);
13978
+ const digest = createHash13("sha256").update(key).digest("hex").slice(0, 32);
13979
+ return this.withLock(path20.join(this.paths().dir, "keys", `${digest}.lock`), operation);
13836
13980
  }
13837
13981
  bindLocked(taskId, key, timestamp) {
13838
13982
  const current = this.readWorkspace();
@@ -13973,7 +14117,7 @@ class TaskStore extends TaskReader {
13973
14117
  writeWorkspace(record) {
13974
14118
  const file = this.paths().workspace;
13975
14119
  try {
13976
- fs16.mkdirSync(path19.dirname(file), { recursive: true });
14120
+ fs16.mkdirSync(path20.dirname(file), { recursive: true });
13977
14121
  replaceFile(file, `${canonicalJson(record)}
13978
14122
  `, true);
13979
14123
  return success(null, null, null);
@@ -13999,13 +14143,13 @@ class TaskStore extends TaskReader {
13999
14143
  }
14000
14144
  migrateV2(v2) {
14001
14145
  const dirs = this.paths();
14002
- const v2Workspace = path19.join(v2, "workspace.json");
14003
- const v2Tasks = path19.join(v2, "tasks");
14004
- const legacy = path19.join(dirs.dir, "legacy", checkoutSlug(path19.dirname(v2)), "v2");
14146
+ const v2Workspace = path20.join(v2, "workspace.json");
14147
+ const v2Tasks = path20.join(v2, "tasks");
14148
+ const legacy = path20.join(dirs.dir, "legacy", checkoutSlug(path20.dirname(v2)), "v2");
14005
14149
  const raw = this.readV2Workspace(v2Workspace);
14006
14150
  if (raw === null || raw === TOMBSTONE)
14007
14151
  return success(null, null, null);
14008
- return this.withLock(dirs.checkoutLock, () => this.withLock(path19.join(v2, "metadata.lock"), () => {
14152
+ return this.withLock(dirs.checkoutLock, () => this.withLock(path20.join(v2, "metadata.lock"), () => {
14009
14153
  const workspace = this.readV2Workspace(v2Workspace);
14010
14154
  if (workspace === null || workspace === TOMBSTONE)
14011
14155
  return success(null, null, null);
@@ -14014,7 +14158,7 @@ class TaskStore extends TaskReader {
14014
14158
  return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
14015
14159
  let files = [];
14016
14160
  try {
14017
- files = fs16.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path19.join(v2Tasks, name)));
14161
+ files = fs16.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path20.join(v2Tasks, name)));
14018
14162
  } catch {}
14019
14163
  const current = this.readWorkspace();
14020
14164
  if (!current.ok)
@@ -14032,21 +14176,21 @@ class TaskStore extends TaskReader {
14032
14176
  let skipped = 0;
14033
14177
  const done = new Map;
14034
14178
  try {
14035
- fs16.mkdirSync(path19.join(legacy, "tasks"), { recursive: true });
14179
+ fs16.mkdirSync(path20.join(legacy, "tasks"), { recursive: true });
14036
14180
  for (const name of ["workspace.json", "index.json"])
14037
- if (fs16.existsSync(path19.join(v2, name)))
14038
- fs16.copyFileSync(path19.join(v2, name), path19.join(legacy, name));
14181
+ if (fs16.existsSync(path20.join(v2, name)))
14182
+ fs16.copyFileSync(path20.join(v2, name), path20.join(legacy, name));
14039
14183
  for (const name of files) {
14040
14184
  const id = name.slice(0, -5);
14041
- const file = path19.join(v2Tasks, name);
14185
+ const file = path20.join(v2Tasks, name);
14042
14186
  const bytes = fs16.readFileSync(file, "utf8");
14043
14187
  const digest = sha256(bytes);
14044
- fs16.writeFileSync(path19.join(legacy, "tasks", name), bytes);
14188
+ fs16.writeFileSync(path20.join(legacy, "tasks", name), bytes);
14045
14189
  const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
14046
14190
  if (!parsed.ok || parsed.data.id !== id)
14047
14191
  return failure2("recovery_required", `cannot migrate 2.x task ${id}: ${parsed.ok ? "file name and record ID differ" : parsed.error}; move ${file} aside to continue`, { path: file });
14048
14192
  const record = { ...parsed.data, workspaceId: target.id };
14049
- const origin = { path: path19.join(legacy, "tasks", name), digest };
14193
+ const origin = { path: path20.join(legacy, "tasks", name), digest };
14050
14194
  if (!fs16.existsSync(this.eventsPath(id))) {
14051
14195
  this.openTask(record, "migrated.from_v2", null, origin);
14052
14196
  migrated += 1;
@@ -14082,7 +14226,7 @@ class TaskStore extends TaskReader {
14082
14226
  try {
14083
14227
  let complete = true;
14084
14228
  for (const [name, digest] of done) {
14085
- const file = path19.join(v2Tasks, name);
14229
+ const file = path20.join(v2Tasks, name);
14086
14230
  if (sha256(fs16.readFileSync(file, "utf8")) !== digest) {
14087
14231
  complete = false;
14088
14232
  continue;
@@ -14096,7 +14240,7 @@ class TaskStore extends TaskReader {
14096
14240
  return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
14097
14241
  path: v2
14098
14242
  });
14099
- fs16.rmSync(path19.join(v2, "index.json"), { force: true });
14243
+ fs16.rmSync(path20.join(v2, "index.json"), { force: true });
14100
14244
  if (dirs.shared)
14101
14245
  fs16.rmSync(v2Workspace, { force: true });
14102
14246
  else
@@ -14121,8 +14265,8 @@ class TaskStore extends TaskReader {
14121
14265
  const dirs = this.paths();
14122
14266
  if (!dirs.shared)
14123
14267
  return success(null, null, null);
14124
- const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs16.existsSync(path19.join(v2, name)));
14125
- const ignore = path19.join(v2, ".gitignore");
14268
+ const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs16.existsSync(path20.join(v2, name)));
14269
+ const ignore = path20.join(v2, ".gitignore");
14126
14270
  const onlyGeneratedIgnore = () => {
14127
14271
  try {
14128
14272
  return fs16.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs16.readFileSync(ignore, "utf8"));
@@ -14132,12 +14276,12 @@ class TaskStore extends TaskReader {
14132
14276
  };
14133
14277
  if (present().length === 0 && !onlyGeneratedIgnore())
14134
14278
  return success(null, null, null);
14135
- const backup = path19.join(dirs.dir, "legacy", checkoutSlug(path19.dirname(v2)), "v2");
14279
+ const backup = path20.join(dirs.dir, "legacy", checkoutSlug(path20.dirname(v2)), "v2");
14136
14280
  return this.withLock(dirs.checkoutLock, () => {
14137
14281
  let moved = 0;
14138
14282
  try {
14139
14283
  for (const name of present()) {
14140
- const entry = path19.join(v2, name);
14284
+ const entry = path20.join(v2, name);
14141
14285
  const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
14142
14286
  const empty = fs16.lstatSync(entry).isDirectory() && fs16.readdirSync(entry).length === 0;
14143
14287
  if (marker || empty) {
@@ -14146,18 +14290,18 @@ class TaskStore extends TaskReader {
14146
14290
  }
14147
14291
  if (name === "tasks" && fs16.lstatSync(entry).isDirectory()) {
14148
14292
  for (const task of fs16.readdirSync(entry)) {
14149
- const file = path19.join(entry, task);
14293
+ const file = path20.join(entry, task);
14150
14294
  if (fs16.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
14151
14295
  fs16.rmSync(file);
14152
14296
  else {
14153
- moveInto(file, path19.join(backup, "tasks", task));
14297
+ moveInto(file, path20.join(backup, "tasks", task));
14154
14298
  moved += 1;
14155
14299
  }
14156
14300
  }
14157
14301
  fs16.rmdirSync(entry);
14158
14302
  continue;
14159
14303
  }
14160
- moveInto(entry, path19.join(backup, name));
14304
+ moveInto(entry, path20.join(backup, name));
14161
14305
  moved += 1;
14162
14306
  }
14163
14307
  if (onlyGeneratedIgnore())
@@ -14199,22 +14343,22 @@ var workerBlocksTransition = (transition, state) => transition === "pause" ? fal
14199
14343
  var holdsLiveState = (state, dirty) => state === "running" || dirty === true;
14200
14344
 
14201
14345
  // packages/workit-core/src/core/task-evaluation.ts
14202
- import { createHash as createHash14 } from "node:crypto";
14346
+ import { createHash as createHash15 } from "node:crypto";
14203
14347
  import * as fs19 from "node:fs";
14204
14348
  import { spawnSync as spawnSync15 } from "node:child_process";
14205
- import path24 from "node:path";
14349
+ import path25 from "node:path";
14206
14350
 
14207
14351
  // packages/workit-core/src/check-config.ts
14208
14352
  import { spawnSync as spawnSync11 } from "node:child_process";
14209
14353
  import fs17 from "node:fs";
14210
- import path20 from "node:path";
14354
+ import path21 from "node:path";
14211
14355
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
14212
14356
  var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
14213
14357
  var CHECKS_FILE = ".workit/checks.json";
14214
14358
  var LEGACY_CHECKS_FILE = "workit.checks.json";
14215
14359
  function checksConfigFile(root) {
14216
- const current = path20.join(root, CHECKS_FILE);
14217
- const legacy = path20.join(root, LEGACY_CHECKS_FILE);
14360
+ const current = path21.join(root, CHECKS_FILE);
14361
+ const legacy = path21.join(root, LEGACY_CHECKS_FILE);
14218
14362
  return !fs17.existsSync(current) && fs17.existsSync(legacy) ? legacy : current;
14219
14363
  }
14220
14364
  var GENERATED_GITIGNORES2 = new Set([`*
@@ -14283,10 +14427,10 @@ var git3 = (cwd, args) => {
14283
14427
  return value || null;
14284
14428
  };
14285
14429
  function checkRoot(cwd) {
14286
- return path20.resolve(gitDirs(cwd)?.top ?? cwd);
14430
+ return path21.resolve(gitDirs(cwd)?.top ?? cwd);
14287
14431
  }
14288
14432
  var packageManager = (root) => {
14289
- const has = (file) => fs17.existsSync(path20.join(root, file));
14433
+ const has = (file) => fs17.existsSync(path21.join(root, file));
14290
14434
  if (has("bun.lock") || has("bun.lockb"))
14291
14435
  return "bun";
14292
14436
  if (has("pnpm-lock.yaml"))
@@ -14306,7 +14450,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
14306
14450
  function detectedChecks(root) {
14307
14451
  const read = (file) => {
14308
14452
  try {
14309
- return fs17.readFileSync(path20.join(root, file), "utf8");
14453
+ return fs17.readFileSync(path21.join(root, file), "utf8");
14310
14454
  } catch {
14311
14455
  return null;
14312
14456
  }
@@ -14381,10 +14525,10 @@ function configFileFor(root) {
14381
14525
  if (fs17.existsSync(own))
14382
14526
  return own;
14383
14527
  const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
14384
- if (!common || path20.basename(common) !== ".git")
14528
+ if (!common || path21.basename(common) !== ".git")
14385
14529
  return own;
14386
- const main = path20.dirname(common);
14387
- if (path20.resolve(main) === path20.resolve(root))
14530
+ const main = path21.dirname(common);
14531
+ if (path21.resolve(main) === path21.resolve(root))
14388
14532
  return own;
14389
14533
  const shared = checksConfigFile(main);
14390
14534
  return fs17.existsSync(shared) ? shared : own;
@@ -14392,7 +14536,7 @@ function configFileFor(root) {
14392
14536
  function loadCheckConfig(cwd) {
14393
14537
  const root = checkRoot(cwd);
14394
14538
  const file = configFileFor(root);
14395
- const legacy = path20.basename(file) === LEGACY_CHECKS_FILE;
14539
+ const legacy = path21.basename(file) === LEGACY_CHECKS_FILE;
14396
14540
  const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
14397
14541
  const note = legacy ? {
14398
14542
  note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
@@ -14523,10 +14667,10 @@ function workitAvailable(env = process.env) {
14523
14667
  return workitOnPath;
14524
14668
  const windows = process.platform === "win32";
14525
14669
  const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
14526
- const dirs = (env.PATH ?? env.Path ?? "").split(path20.delimiter).filter(Boolean);
14670
+ const dirs = (env.PATH ?? env.Path ?? "").split(path21.delimiter).filter(Boolean);
14527
14671
  workitOnPath = dirs.some((dir) => exts.some((ext) => {
14528
14672
  try {
14529
- return fs17.statSync(path20.join(dir, `workit${ext}`)).isFile();
14673
+ return fs17.statSync(path21.join(dir, `workit${ext}`)).isFile();
14530
14674
  } catch {
14531
14675
  return false;
14532
14676
  }
@@ -14596,14 +14740,14 @@ var firstPositional = (words, from) => {
14596
14740
  return index;
14597
14741
  };
14598
14742
  function fileTarget(word, cwd) {
14599
- if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(path20.sep))
14743
+ if (/[*?[\]{}]/u.test(word) || word.endsWith("/") || word.endsWith(path21.sep))
14600
14744
  return false;
14601
- if (!/\.[A-Za-z0-9]+$/u.test(path20.basename(word)))
14745
+ if (!/\.[A-Za-z0-9]+$/u.test(path21.basename(word)))
14602
14746
  return false;
14603
14747
  if (!cwd)
14604
14748
  return true;
14605
14749
  try {
14606
- return !fs17.statSync(path20.resolve(cwd, word)).isDirectory();
14750
+ return !fs17.statSync(path21.resolve(cwd, word)).isDirectory();
14607
14751
  } catch {
14608
14752
  return true;
14609
14753
  }
@@ -14671,13 +14815,13 @@ function lightCommand(argv, cwd) {
14671
14815
 
14672
14816
  // packages/workit-core/src/core/policy/derive.ts
14673
14817
  import { existsSync as existsSync9 } from "node:fs";
14674
- import path23 from "node:path";
14818
+ import path24 from "node:path";
14675
14819
 
14676
14820
  // packages/workit-core/src/ledger.ts
14677
14821
  import { spawnSync as spawnSync14 } from "node:child_process";
14678
- import { createHash as createHash13, randomBytes as randomBytes3 } from "node:crypto";
14822
+ import { createHash as createHash14, randomBytes as randomBytes3 } from "node:crypto";
14679
14823
  import fs18 from "node:fs";
14680
- import path22 from "node:path";
14824
+ import path23 from "node:path";
14681
14825
 
14682
14826
  // packages/workit-core/src/core/policy/bookkeeping.ts
14683
14827
  import { spawnSync as spawnSync12 } from "node:child_process";
@@ -14757,8 +14901,8 @@ function bookkeepingPaths(cwd, input) {
14757
14901
  }
14758
14902
 
14759
14903
  // packages/workit-core/src/core/policy/lane.ts
14760
- import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
14761
- import path21 from "node:path";
14904
+ import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
14905
+ import path22 from "node:path";
14762
14906
 
14763
14907
  // packages/workit-core/src/git/default-base.ts
14764
14908
  import { spawnSync as spawnSync13 } from "node:child_process";
@@ -16149,7 +16293,7 @@ function computeLane(input) {
16149
16293
  }
16150
16294
  function untrackedStat(cwd, file) {
16151
16295
  try {
16152
- const bytes = readFileSync7(path21.join(cwd, file));
16296
+ const bytes = readFileSync8(path22.join(cwd, file));
16153
16297
  if (bytes.includes(0))
16154
16298
  return { path: file, added: 0, deleted: 0, binary: true };
16155
16299
  const text = bytes.toString("utf8");
@@ -16181,7 +16325,7 @@ function cosmeticFiles(cwd, fork, head) {
16181
16325
  let after = blobs.get(entry.newBlob);
16182
16326
  if (!after && head === null && ABSENT.test(entry.newBlob))
16183
16327
  try {
16184
- after = readFileSync7(path21.join(cwd, entry.path));
16328
+ after = readFileSync8(path22.join(cwd, entry.path));
16185
16329
  } catch {
16186
16330
  after = undefined;
16187
16331
  }
@@ -16412,7 +16556,7 @@ var binaryRangeDiff = (cwd, base, head) => {
16412
16556
  return diff.ok && diff.stdout ? diff.stdout : null;
16413
16557
  };
16414
16558
  var hashOfDiff = (diff) => {
16415
- const hash = createHash13("sha256");
16559
+ const hash = createHash14("sha256");
16416
16560
  for (const line of diff.split(`
16417
16561
  `)) {
16418
16562
  if (line.startsWith("index "))
@@ -16445,14 +16589,14 @@ function cleanRebase(cwd, range) {
16445
16589
  return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
16446
16590
  }
16447
16591
  function storeRoot(cwd) {
16448
- const location = resolveStore(path22.resolve(cwd));
16592
+ const location = resolveStore(path23.resolve(cwd));
16449
16593
  if (location instanceof Error)
16450
16594
  return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), / does not exist /u.test(location.message) ? "run workit from a directory that exists" : "fix the repository (git status should work here) or run from a non-git directory");
16451
16595
  return { ok: true, value: { root: location.dir, shared: location.shared } };
16452
16596
  }
16453
16597
  function ledgerPath(cwd) {
16454
16598
  const root = storeRoot(cwd);
16455
- return root.ok ? { ok: true, value: path22.join(root.value.root, "ledger", "ledger.jsonl") } : root;
16599
+ return root.ok ? { ok: true, value: path23.join(root.value.root, "ledger", "ledger.jsonl") } : root;
16456
16600
  }
16457
16601
  var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
16458
16602
  var NETWORK_FS_TYPES = new Set([
@@ -16482,13 +16626,13 @@ var LOCK_STALE_MS2 = 30000;
16482
16626
  var LOCK_OWNER = "owner";
16483
16627
  var lockToken = (lock) => {
16484
16628
  try {
16485
- return fs18.readFileSync(path22.join(lock, LOCK_OWNER), "utf8");
16629
+ return fs18.readFileSync(path23.join(lock, LOCK_OWNER), "utf8");
16486
16630
  } catch {
16487
16631
  return null;
16488
16632
  }
16489
16633
  };
16490
16634
  var lockAgeMs = (lock) => {
16491
- for (const target of [path22.join(lock, LOCK_OWNER), lock]) {
16635
+ for (const target of [path23.join(lock, LOCK_OWNER), lock]) {
16492
16636
  try {
16493
16637
  return Date.now() - fs18.statSync(target).mtimeMs;
16494
16638
  } catch {}
@@ -16505,7 +16649,7 @@ var ledgerLock = {
16505
16649
  throw error;
16506
16650
  }
16507
16651
  const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
16508
- fs18.writeFileSync(path22.join(lock, LOCK_OWNER), token);
16652
+ fs18.writeFileSync(path23.join(lock, LOCK_OWNER), token);
16509
16653
  return token;
16510
16654
  },
16511
16655
  release(lock, token) {
@@ -16568,7 +16712,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2))
16568
16712
  ledgerLock.release(lock, token);
16569
16713
  }
16570
16714
  }
16571
- var sha2562 = (text) => createHash13("sha256").update(text).digest("hex");
16715
+ var sha2562 = (text) => createHash14("sha256").update(text).digest("hex");
16572
16716
  var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
16573
16717
  ${body}`);
16574
16718
  var TAIL_BYTES = 64 * 1024;
@@ -16630,8 +16774,8 @@ ${line.value}`);
16630
16774
  }
16631
16775
  };
16632
16776
  try {
16633
- fs18.mkdirSync(path22.dirname(file), { recursive: true });
16634
- if (options.heldLock || !options.forceLock && !onNetworkFs(path22.dirname(file)))
16777
+ fs18.mkdirSync(path23.dirname(file), { recursive: true });
16778
+ if (options.heldLock || !options.forceLock && !onNetworkFs(path23.dirname(file)))
16635
16779
  return write();
16636
16780
  const locked = withLedgerLock(file, write);
16637
16781
  return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
@@ -16648,7 +16792,7 @@ var sealed = (row, id, at, previous) => {
16648
16792
  ` };
16649
16793
  };
16650
16794
  function appendRaw(cwd, row, options) {
16651
- const file = options.store ? { ok: true, value: path22.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
16795
+ const file = options.store ? { ok: true, value: path23.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
16652
16796
  if (!file.ok)
16653
16797
  return file;
16654
16798
  const id = newId2();
@@ -17311,7 +17455,7 @@ function remoteIdentity(cwd, hop = 0) {
17311
17455
  return null;
17312
17456
  if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
17313
17457
  const local = raw.replace(/^file:\/\//u, "");
17314
- const resolved = path22.isAbsolute(local) ? local : path22.resolve(cwd, local);
17458
+ const resolved = path23.isAbsolute(local) ? local : path23.resolve(cwd, local);
17315
17459
  if (fs18.existsSync(resolved))
17316
17460
  return remoteIdentity(resolved, 1);
17317
17461
  }
@@ -17332,8 +17476,8 @@ function verdictMirrorPath(cwd) {
17332
17476
  }
17333
17477
  if (!identity)
17334
17478
  return null;
17335
- const key = createHash13("sha256").update(identity).digest("hex").slice(0, 32);
17336
- return path22.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
17479
+ const key = createHash14("sha256").update(identity).digest("hex").slice(0, 32);
17480
+ return path23.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
17337
17481
  }
17338
17482
  var importedStamp = new Map;
17339
17483
  function importMirroredVerdicts(cwd, branch) {
@@ -17356,7 +17500,7 @@ function importMirroredVerdicts(cwd, branch) {
17356
17500
  const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
17357
17501
  const added = new Set;
17358
17502
  try {
17359
- fs18.mkdirSync(path22.dirname(local.value), { recursive: true });
17503
+ fs18.mkdirSync(path23.dirname(local.value), { recursive: true });
17360
17504
  } catch {
17361
17505
  return [];
17362
17506
  }
@@ -17582,7 +17726,7 @@ var productDecision = (task, ledger) => {
17582
17726
  };
17583
17727
  };
17584
17728
  var planRecorded = (task, root) => {
17585
- const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path23.resolve(root, ref.path)));
17729
+ const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path24.resolve(root, ref.path)));
17586
17730
  if (cited)
17587
17731
  return {
17588
17732
  met: true,
@@ -17659,15 +17803,15 @@ function writeBlockers(task, root) {
17659
17803
  }
17660
17804
 
17661
17805
  // packages/workit-core/src/core/task-evaluation.ts
17662
- var digestBytes = (value) => createHash14("sha256").update(value).digest("hex");
17663
- var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path24.sep}`);
17664
- var relative = (root, candidate) => path24.relative(root, candidate).split(path24.sep).join("/") || ".";
17806
+ var digestBytes = (value) => createHash15("sha256").update(value).digest("hex");
17807
+ var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path25.sep}`);
17808
+ var relative = (root, candidate) => path25.relative(root, candidate).split(path25.sep).join("/") || ".";
17665
17809
  var canonicalPath = (value) => {
17666
17810
  if (typeof value !== "string" || !value)
17667
17811
  return null;
17668
17812
  if (value.includes("\\") || value.split("/").includes(".."))
17669
17813
  return null;
17670
- const normalized = path24.posix.normalize(value);
17814
+ const normalized = path25.posix.normalize(value);
17671
17815
  if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
17672
17816
  return null;
17673
17817
  return normalized === "." ? "." : normalized.replace(/\/$/, "");
@@ -17715,14 +17859,14 @@ var gitPaths = (root) => {
17715
17859
  git: !/not a git repository/i.test(stderr)
17716
17860
  };
17717
17861
  }
17718
- const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path24.sep).join("/")) : [];
17862
+ const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")) : [];
17719
17863
  const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
17720
17864
  if (stagedDeleted.status !== 0) {
17721
17865
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
17722
17866
  if (!/not a git repository/i.test(stderr))
17723
17867
  return { paths, uncertain: true, git: true };
17724
17868
  } else if (stagedDeleted.stdout) {
17725
- paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path24.sep).join("/")));
17869
+ paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path25.sep).join("/")));
17726
17870
  }
17727
17871
  return { paths: [...new Set(paths)], uncertain: false, git: true };
17728
17872
  };
@@ -17737,7 +17881,7 @@ var walk = (root, directory, output) => {
17737
17881
  for (const name of names) {
17738
17882
  if (name === ".git" || name === ".workit")
17739
17883
  continue;
17740
- const target = path24.join(directory, name);
17884
+ const target = path25.join(directory, name);
17741
17885
  let stat;
17742
17886
  try {
17743
17887
  stat = fs19.lstatSync(target);
@@ -17755,12 +17899,12 @@ var walk = (root, directory, output) => {
17755
17899
  var scopeRoots = (root, scope) => {
17756
17900
  const roots = [];
17757
17901
  for (const item of scope.paths.length ? scope.paths : ["."]) {
17758
- const target = path24.resolve(root, item);
17902
+ const target = path25.resolve(root, item);
17759
17903
  if (!inside(root, target))
17760
17904
  return failure2("invalid_input", `candidate scope escapes checkout: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} is outside the checkout` }] });
17761
17905
  let ancestor = target;
17762
17906
  while (!fs19.existsSync(ancestor) && ancestor !== root)
17763
- ancestor = path24.dirname(ancestor);
17907
+ ancestor = path25.dirname(ancestor);
17764
17908
  try {
17765
17909
  if (!inside(root, fs19.realpathSync(ancestor)))
17766
17910
  return failure2("invalid_input", `candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] });
@@ -17812,7 +17956,7 @@ function captureCandidate(root, scope, environment = []) {
17812
17956
  for (const item of [...names].toSorted()) {
17813
17957
  if (!scopeMatches(item, normalizedScope))
17814
17958
  continue;
17815
- const target = path24.join(checkout, item);
17959
+ const target = path25.join(checkout, item);
17816
17960
  try {
17817
17961
  const stat = fs19.lstatSync(target);
17818
17962
  if (stat.isSymbolicLink()) {
@@ -17996,23 +18140,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
17996
18140
  continue;
17997
18141
  if (!reference.digest)
17998
18142
  return failure2("invalid_input", "document references require a byte digest");
17999
- const target = path24.resolve(root, reference.path);
18000
- if (target !== root && !target.startsWith(`${root}${path24.sep}`))
18143
+ const target = path25.resolve(root, reference.path);
18144
+ if (target !== root && !target.startsWith(`${root}${path25.sep}`))
18001
18145
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
18002
18146
  fields: [
18003
18147
  { path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
18004
18148
  ]
18005
18149
  });
18006
18150
  try {
18007
- const below = path24.relative(root, target);
18151
+ const below = path25.relative(root, target);
18008
18152
  let current = root;
18009
- for (const segment of below.split(path24.sep)) {
18153
+ for (const segment of below.split(path25.sep)) {
18010
18154
  if (!segment)
18011
18155
  continue;
18012
- current = path24.join(current, segment);
18156
+ current = path25.join(current, segment);
18013
18157
  const stat = fs19.lstatSync(current);
18014
18158
  const real = fs19.realpathSync(current);
18015
- if (real !== root && !real.startsWith(`${root}${path24.sep}`))
18159
+ if (real !== root && !real.startsWith(`${root}${path25.sep}`))
18016
18160
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
18017
18161
  fields: [
18018
18162
  {
@@ -18373,9 +18517,9 @@ function boundTaskSummary(summary) {
18373
18517
  }
18374
18518
 
18375
18519
  // packages/workit-core/src/core/model-fallback.ts
18376
- import { createHash as createHash15 } from "node:crypto";
18377
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync9, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
18378
- import path25 from "node:path";
18520
+ import { createHash as createHash16 } from "node:crypto";
18521
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
18522
+ import path26 from "node:path";
18379
18523
  var LIMITS_FILE = "model-limits.json";
18380
18524
  var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
18381
18525
  var KEEP_MS = 9 * 86400000;
@@ -18398,10 +18542,10 @@ var providerOf = (model, host) => {
18398
18542
  return null;
18399
18543
  };
18400
18544
  var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
18401
- var storePath = (stateDir) => path25.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
18545
+ var storePath = (stateDir) => path26.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
18402
18546
  var readStore = (stateDir) => {
18403
18547
  try {
18404
- const parsed = JSON.parse(readFileSync9(storePath(stateDir), "utf8"));
18548
+ const parsed = JSON.parse(readFileSync10(storePath(stateDir), "utf8"));
18405
18549
  const store = empty();
18406
18550
  for (const key of ["exhausted", "seen", "redispatched"])
18407
18551
  if (parsed[key] && typeof parsed[key] === "object")
@@ -18422,7 +18566,7 @@ var writeStore = (store, now, stateDir) => {
18422
18566
  delete store.exhausted[id];
18423
18567
  try {
18424
18568
  const file = storePath(stateDir);
18425
- mkdirSync5(path25.dirname(file), { recursive: true });
18569
+ mkdirSync5(path26.dirname(file), { recursive: true });
18426
18570
  const temp = `${file}.${process.pid}.tmp`;
18427
18571
  writeFileSync5(temp, `${JSON.stringify(store, null, 2)}
18428
18572
  `);
@@ -18450,7 +18594,7 @@ var exhaustionFor = (model, host, now = new Date, stateDir) => {
18450
18594
  const keys = new Set([provider, ...family ? [`${provider}/${family}`] : []]);
18451
18595
  return exhaustedProviders(now, stateDir).find((entry) => keys.has(entry.provider)) ?? null;
18452
18596
  };
18453
- var promptKey = (prompt) => createHash15("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
18597
+ var promptKey = (prompt) => createHash16("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
18454
18598
  var claimRedispatch = (key, now = new Date, stateDir) => {
18455
18599
  const store = readStore(stateDir);
18456
18600
  if (store.redispatched[key])
@@ -19044,20 +19188,20 @@ import path29 from "node:path";
19044
19188
  // packages/workit-core/src/core/eval-world.ts
19045
19189
  import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
19046
19190
  import os6 from "node:os";
19047
- import path26 from "node:path";
19191
+ import path27 from "node:path";
19048
19192
  var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
19049
19193
  var EVAL_WORLD_MARKER = ".workit-eval-world";
19050
19194
  var inside2 = (dir, file) => {
19051
- const rel = path26.relative(dir, file);
19052
- return !rel.startsWith("..") && !path26.isAbsolute(rel);
19195
+ const rel = path27.relative(dir, file);
19196
+ return !rel.startsWith("..") && !path27.isAbsolute(rel);
19053
19197
  };
19054
19198
  var evalWorld = (cwd) => {
19055
19199
  const raw = process.env[EVAL_WORLD_ENV];
19056
- if (!raw || !path26.isAbsolute(raw))
19200
+ if (!raw || !path27.isAbsolute(raw))
19057
19201
  return null;
19058
19202
  try {
19059
19203
  const world = realpathSync7(raw);
19060
- return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path26.join(world, EVAL_WORLD_MARKER)) ? world : null;
19204
+ return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path27.join(world, EVAL_WORLD_MARKER)) ? world : null;
19061
19205
  } catch {
19062
19206
  return null;
19063
19207
  }
@@ -19065,77 +19209,12 @@ var evalWorld = (cwd) => {
19065
19209
  var evalWorldEntry = (cwd) => {
19066
19210
  const world = evalWorld(cwd);
19067
19211
  try {
19068
- return world ? loadWorkspacesFrom(path26.join(world, "config"))[0] ?? null : null;
19212
+ return world ? loadWorkspacesFrom(path27.join(world, "config"))[0] ?? null : null;
19069
19213
  } catch {
19070
19214
  return null;
19071
19215
  }
19072
19216
  };
19073
19217
 
19074
- // packages/workit-core/src/core/grant-seal.ts
19075
- import { createHash as createHash16 } from "node:crypto";
19076
- import { readFileSync as readFileSync10 } from "node:fs";
19077
- import path27 from "node:path";
19078
- var SEAL_FILE = "workspaces.json.seal";
19079
- var SEAL_VERSION = 1;
19080
- var SEAL_COMMAND = "workit workspace seal";
19081
- var pick3 = (value, keys) => {
19082
- if (!value || typeof value !== "object" || Array.isArray(value))
19083
- return;
19084
- const out = Object.fromEntries(keys.flatMap((key) => {
19085
- const item = value[key];
19086
- return item === undefined ? [] : [[key, item]];
19087
- }));
19088
- return Object.keys(out).length > 0 ? out : undefined;
19089
- };
19090
- var ENTRY_KEYS = [
19091
- "name",
19092
- "glob",
19093
- "remotes",
19094
- "externalRepos",
19095
- "additiveRiskPaths",
19096
- "vcs",
19097
- "autonomy",
19098
- "autoApprove",
19099
- "defaultEndpoint",
19100
- "verification",
19101
- "youtrack"
19102
- ];
19103
- var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
19104
- var sealProjection = (entries) => entries.map((entry) => {
19105
- const all = pick3(entry, ENTRY_KEYS) ?? {};
19106
- return pick3({
19107
- ...all,
19108
- vcs: pick3(all.vcs, IDENTITY_KEYS),
19109
- youtrack: pick3(all.youtrack, ["writes", "autoHosts"])
19110
- }, ENTRY_KEYS);
19111
- });
19112
- var canonical4 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
19113
- var sealDigest = (projection) => createHash16("sha256").update(canonical4(projection)).digest("hex");
19114
- var broken = (reason, sealed = null) => ({
19115
- state: "broken",
19116
- reason,
19117
- sealed
19118
- });
19119
- function checkSeal(dir) {
19120
- const file = path27.join(dir, SEAL_FILE);
19121
- let seal;
19122
- try {
19123
- seal = JSON.parse(readFileSync10(file, "utf8"));
19124
- } catch (error) {
19125
- if (error.code === "ENOENT")
19126
- return { state: "none" };
19127
- return broken(`${SEAL_FILE} cannot be read`);
19128
- }
19129
- if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
19130
- return broken(`${SEAL_FILE} is malformed`);
19131
- const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
19132
- if (sealed.status !== "valid")
19133
- return broken(`${SEAL_FILE} is malformed`);
19134
- const current = readWorkspacesResult(dir);
19135
- const ok = current.status === "valid" || current.status === "missing";
19136
- return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
19137
- }
19138
-
19139
19218
  // packages/workit-core/src/core/youtrack-ytrack.ts
19140
19219
  import { spawnSync as spawnSync16 } from "node:child_process";
19141
19220
 
@@ -19348,7 +19427,7 @@ var sealOf = () => {
19348
19427
  var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
19349
19428
  var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
19350
19429
  var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never run), so grants, endpoint, verification and youtrack.writes stay at or below the D4 defaults; ${NO_SEAL_UNBLOCK}`;
19351
- var sealNote = (seal = sealOf()) => seal.state === "broken" ? `workspaces.json does not match its seal (${seal.reason}), so grants, endpoint, verification and youtrack.writes are the stricter of their current and last sealed values; ${SEAL_UNBLOCK}` : null;
19430
+ var sealNote = (seal = sealOf()) => seal.state === "broken" ? `workspaces.json does not match its seal (${seal.reason}), so grants, endpoint, verification and youtrack.writes are the stricter of their current and last sealed values, and a sealed releaseNotes review stays; ${SEAL_UNBLOCK}` : null;
19352
19431
  var ASK = { mode: "ask" };
19353
19432
  var youtrackOf = (entry) => entry?.youtrack;
19354
19433
  var autoHostsOf = (entry) => {
@@ -19764,7 +19843,14 @@ var SCOPE_FIELDS = new Set([
19764
19843
  "autoApprove",
19765
19844
  "defaultEndpoint",
19766
19845
  "verification",
19767
- "youtrack"
19846
+ "youtrack",
19847
+ "releaseNotes",
19848
+ "releaseTagPrefix",
19849
+ "branchPolicy",
19850
+ "profiles",
19851
+ "defaultProfile",
19852
+ "releaseTracks",
19853
+ "releasePackages"
19768
19854
  ]);
19769
19855
 
19770
19856
  // packages/workit-core/src/core/release-packages.ts
@@ -20921,7 +21007,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
20921
21007
  for (const invocation of inside)
20922
21008
  found.push({ ...invocation, dir: rebase(dir, invocation.dir) });
20923
21009
  };
20924
- const visit = (input, stdin, hops) => {
21010
+ const visit = (input, stdin, hops, expands = "all") => {
20925
21011
  const line = /^\$[\w:]+$/.test(input[0] ?? "") && input[1] === "=" ? input.slice(2) : input;
20926
21012
  const split = splitString(line);
20927
21013
  if (split !== null)
@@ -20983,15 +21069,18 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
20983
21069
  nested(cmdScript(words), "powershell");
20984
21070
  else if (name === "xargs" || name === "find")
20985
21071
  runs(name === "xargs" ? xargsCommands(words, stdin) : findCommands(words));
20986
- else if (name === "gh" || name === "glab")
21072
+ else if (name === "gh" || name === "glab") {
21073
+ const shift = input.length - words.length + 1;
21074
+ const expanded = expands === "all" ? expands : expands.filter((at) => at >= shift).map((at) => at - shift);
20987
21075
  found.push({
20988
21076
  tool: name,
20989
21077
  dir,
20990
21078
  args: words.slice(1),
20991
21079
  ...Object.keys({ ...exported, ...env }).length ? { env: { ...exported, ...env } } : {},
20992
- ...stdin === undefined ? {} : { stdin }
21080
+ ...stdin === undefined ? {} : { stdin },
21081
+ ...expanded.length ? { expanded } : {}
20993
21082
  });
20994
- else if (name === "git") {
21083
+ } else if (name === "git") {
20995
21084
  const invocation = gitInvocation(words.slice(1), dir, { ...exported, ...env }, stdin, sessionConfig);
20996
21085
  found.push(invocation);
20997
21086
  sessionConfig.push(...configSetBy(invocation.args));
@@ -21024,7 +21113,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
21024
21113
  }
21025
21114
  const stdin = stdinOf(segment, segments[index - 1]);
21026
21115
  for (const line of substitute(segment.words, vars))
21027
- visit(line, stdin, 0);
21116
+ visit(line, stdin, 0, segment.expands ?? []);
21028
21117
  }
21029
21118
  return found;
21030
21119
  }
@@ -21319,55 +21408,232 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
21319
21408
  var API_SHORT_VALUES = "XHfFqtp";
21320
21409
  var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
21321
21410
  var API_MERGE = {
21322
- gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?(?:[?#]|$)/i,
21323
- glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?(?:[?#]|$)/i
21411
+ gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?$/i,
21412
+ glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?$/i
21324
21413
  };
21325
21414
  var GRAPHQL_MERGE = /\b(?:mergePullRequest|enablePullRequestAutoMerge|mergeBranch|mergeRequestAccept)\b/;
21326
- var apiAction = (tool, args, stdin) => {
21327
- const request = { method: null, body: false };
21415
+ var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
21416
+ var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
21417
+ var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
21418
+ var GRAPHQL_REF = [
21419
+ [called("createRef|updateRefs?|deleteRef"), "ref"],
21420
+ [
21421
+ called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
21422
+ "branch"
21423
+ ],
21424
+ [called("tagCreate|tagDelete"), "tag"]
21425
+ ];
21426
+ var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
21427
+ var API_REF = {
21428
+ gh: [
21429
+ [ghPath(String.raw`git\/refs?`), "ref"],
21430
+ [ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
21431
+ ],
21432
+ glab: [
21433
+ [/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
21434
+ [/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
21435
+ [/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
21436
+ ]
21437
+ };
21438
+ var API_SETTING = {
21439
+ gh: [
21440
+ ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
21441
+ ghPath("rulesets"),
21442
+ ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
21443
+ /(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
21444
+ ],
21445
+ glab: [
21446
+ /(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
21447
+ /(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
21448
+ ]
21449
+ };
21450
+ var API_REPOSITORY = {
21451
+ gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
21452
+ glab: /(?:^|\/)projects\/[^/]+\/?$/i
21453
+ };
21454
+ var PLAIN_REF = /^refs\/(?:heads|tags)\/(?!.*\.\.)[^\s$`\\%]+$/;
21455
+ var BY_ID = called("updateRefs?|deleteRef");
21456
+ var createdRefs = (query) => {
21457
+ if (/[\\$]|"""/.test(query))
21458
+ return null;
21459
+ const tokens = query.match(/#[^\n\r]*|"[^"\n\r]*"|[_A-Za-z]\w*|[^\s,\uFEFF]/g) ?? [];
21460
+ const named = [];
21461
+ for (let at = 0;at < tokens.length; at++) {
21462
+ if (tokens[at] !== "createRef")
21463
+ continue;
21464
+ const args = tokens.slice(at + 1).filter((token) => !token.startsWith("#"));
21465
+ if (args[0] !== "(")
21466
+ continue;
21467
+ let depth = 0;
21468
+ const names = [];
21469
+ for (let index = 0;index < args.length; index++) {
21470
+ const token = args[index];
21471
+ if (token === "(" || token === "{" || token === "[")
21472
+ depth++;
21473
+ else if (token === ")" || token === "}" || token === "]") {
21474
+ if (--depth === 0)
21475
+ break;
21476
+ } else if (token === "name" && args[index + 1] === ":")
21477
+ names.push(args[index + 2] ?? "");
21478
+ }
21479
+ if (depth !== 0 || names.length !== 1 || !names[0].startsWith('"'))
21480
+ return null;
21481
+ named.push(names[0].slice(1, -1));
21482
+ }
21483
+ return named;
21484
+ };
21485
+ var provablyRead = (query) => /^[\s,\uFEFF]*(?:\{|query[\s,\uFEFF]*[({])/.test(query) && !/\b(?:mutation|subscription)\b/.test(query);
21486
+ var refWrite = (forge, shapes, named, certain) => {
21487
+ const sure = certain && named.length > 0 && named.every((ref) => PLAIN_REF.test(ref));
21488
+ const tags = !sure || named.some((ref) => ref.startsWith("refs/tags/"));
21489
+ const heads = !sure || named.some((ref) => ref.startsWith("refs/heads/"));
21490
+ const ref = shapes.has("ref");
21491
+ return {
21492
+ kind: "ref-write",
21493
+ forge,
21494
+ tag: shapes.has("tag") || ref && tags,
21495
+ branch: shapes.has("branch") || ref && heads,
21496
+ ...ref && sure ? { ref: named[0] } : {}
21497
+ };
21498
+ };
21499
+ var restRef = (route, fields, readable) => {
21500
+ const inPath = /\/git\/refs?\/(.+)$/i.exec(route)?.[1];
21501
+ if (inPath)
21502
+ return { named: [`refs/${inPath}`], certain: true };
21503
+ const refs = fields.filter((field) => field.startsWith("ref=")).map((field) => field.slice(4));
21504
+ const mentions = fields.filter((field) => /refs\//.test(field)).length;
21505
+ return { named: refs, certain: readable && refs.length === 1 && mentions === 1 };
21506
+ };
21507
+ var routeOf = (endpoint) => endpoint.replace(/(?<!:)\/{2,}/g, "/").replace(/[?#][\s\S]*$/, "").replace(/%([\da-f]{2})/gi, (escape, hex) => {
21508
+ const char = String.fromCodePoint(Number.parseInt(hex, 16));
21509
+ return /[\w.~-]/.test(char) ? char : escape;
21510
+ });
21511
+ var apiAction = (tool, args, stdin, expanded = []) => {
21512
+ const request = { method: null, body: false, input: false, unread: false };
21328
21513
  let endpoint = null;
21514
+ let endpointAt = -1;
21329
21515
  const values = [];
21330
- const take = (name, value) => {
21516
+ const fields = [];
21517
+ const queries = [];
21518
+ const field = (value, expands) => {
21519
+ fields.push(value);
21520
+ values.push(value);
21521
+ if (!value.startsWith("query="))
21522
+ return;
21523
+ const text = value.slice(6);
21524
+ const read = expanded !== "all" && (!(expands && /[$`]/.test(text)) || provablyRead(text));
21525
+ queries.push({ text, read });
21526
+ };
21527
+ const fromStdin = (name, value, text) => {
21528
+ if (name !== "--input") {
21529
+ if (text.includes("\\"))
21530
+ request.unread = true;
21531
+ return field(`${value.slice(0, value.indexOf("=") + 1)}${text}`, true);
21532
+ }
21533
+ values.push(text);
21534
+ let body;
21535
+ try {
21536
+ body = JSON.parse(text);
21537
+ } catch {
21538
+ request.unread = true;
21539
+ return;
21540
+ }
21541
+ const strings = (each) => typeof each === "string" ? [each] : each && typeof each === "object" ? Object.entries(each).flatMap(([key, inner]) => [key, ...strings(inner)]) : [];
21542
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
21543
+ values.push(...strings(body));
21544
+ return;
21545
+ }
21546
+ for (const [key, inner] of Object.entries(body)) {
21547
+ if (typeof inner === "string")
21548
+ field(`${key}=${inner}`, true);
21549
+ else
21550
+ values.push(key, ...strings(inner));
21551
+ }
21552
+ };
21553
+ const take = (name, value, at) => {
21554
+ const expands = expanded === "all" || expanded.includes(at);
21331
21555
  if (name === "-X" || name === "--method")
21332
21556
  request.method = value.toUpperCase();
21333
21557
  if (API_FIELDS.has(name) || name === "--input")
21334
21558
  request.body = true;
21335
- values.push(value);
21336
- const fromStdin = name === "--input" ? value === "-" : /^(?:[^=]*=)?@-$/.test(value);
21337
- if (fromStdin && stdin !== undefined)
21338
- values.push(stdin);
21559
+ if (name === "--input")
21560
+ request.input = true;
21561
+ const piped = name === "--input" ? value === "-" : /^(?:-F|--field)$/.test(name) && /^[^=]*=@-$/.test(value);
21562
+ if (piped && stdin !== undefined) {
21563
+ values.push(value);
21564
+ return fromStdin(name, value, stdin);
21565
+ }
21566
+ if (API_FIELDS.has(name))
21567
+ field(value, expands);
21568
+ else
21569
+ values.push(value);
21570
+ const file = name === "--input" || /^(?:-F|--field)$/.test(name) && /^[^=]*=@/.test(value);
21571
+ if (file)
21572
+ request.unread = true;
21339
21573
  };
21340
21574
  for (let index = 1;index < args.length; index++) {
21341
21575
  const arg = args[index];
21342
21576
  if (arg === "--") {
21343
- endpoint ??= args[index + 1] ?? null;
21577
+ if (endpoint === null)
21578
+ [endpoint, endpointAt] = [args[index + 1] ?? null, index + 1];
21344
21579
  break;
21345
21580
  }
21346
21581
  if (arg.startsWith("--")) {
21347
21582
  const eq = arg.indexOf("=");
21348
21583
  const name = eq > 0 ? arg.slice(0, eq) : arg;
21349
21584
  if (API_VALUES.has(name))
21350
- take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "");
21585
+ take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "", index);
21351
21586
  } else if (arg.startsWith("-") && arg.length > 1) {
21352
21587
  for (let at = 1;at < arg.length; at++) {
21353
21588
  if (!API_SHORT_VALUES.includes(arg[at]))
21354
21589
  continue;
21355
- take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "");
21590
+ take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "", index);
21356
21591
  break;
21357
21592
  }
21358
- } else
21359
- endpoint ??= arg;
21593
+ } else if (endpoint === null)
21594
+ [endpoint, endpointAt] = [arg, index];
21360
21595
  }
21361
21596
  if (!endpoint)
21362
21597
  return null;
21363
- endpoint = endpoint.replace(/(?<!:)\/{2,}/g, "/");
21598
+ const atEndpoint = expanded === "all" || expanded.includes(endpointAt);
21599
+ for (const pair of /[?]([^#]*)/.exec(endpoint)?.[1].split("&") ?? []) {
21600
+ let decoded = pair;
21601
+ try {
21602
+ decoded = decodeURIComponent(pair.replaceAll("+", " "));
21603
+ } catch {
21604
+ request.unread = true;
21605
+ }
21606
+ field(decoded, atEndpoint);
21607
+ if (/refs\//i.test(decoded))
21608
+ request.input = true;
21609
+ }
21610
+ const route = routeOf(endpoint);
21364
21611
  const merge = { kind: "merge", forge: tool, via: "api" };
21365
- if (/(?:^|\/)graphql\/?$/i.test(endpoint))
21366
- return values.some((value) => GRAPHQL_MERGE.test(value)) ? merge : null;
21612
+ const setting = {
21613
+ kind: "ref-write",
21614
+ forge: tool,
21615
+ tag: false,
21616
+ branch: true,
21617
+ setting: true
21618
+ };
21619
+ if (/(?:^|\/)graphql\/?$/i.test(route)) {
21620
+ if (request.unread || queries.some((query) => !query.read))
21621
+ return { kind: "ref-write", forge: tool, tag: true, branch: true, unread: true };
21622
+ if (values.some((value) => GRAPHQL_MERGE.test(value)))
21623
+ return merge;
21624
+ if (values.some((value) => GRAPHQL_SETTING.test(value)))
21625
+ return setting;
21626
+ const shapes = new Set(GRAPHQL_REF.filter(([pattern]) => values.some((value) => pattern.test(value))).map(([, shape]) => shape));
21627
+ if (!shapes.size)
21628
+ return null;
21629
+ const created = queries.map((query) => createdRefs(query.text));
21630
+ const certain = !values.some((value) => BY_ID.test(value)) && created.every((named) => named !== null);
21631
+ return refWrite(tool, shapes, created.flatMap((named) => named ?? []), certain);
21632
+ }
21367
21633
  const verb = request.method ?? (request.body ? "POST" : "GET");
21368
21634
  if (verb === "GET" || verb === "HEAD")
21369
21635
  return null;
21370
- const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)\//i.exec(endpoint)?.[1] : /(?:^|\/)projects\/([^/]+)\//i.exec(endpoint)?.[1];
21636
+ const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)(?:\/|$)/i.exec(route)?.[1] ?? (/(?:^|\/)repositories\/[^/]+(?:\/|$)/i.test(route) ? "?" : undefined) : /(?:^|\/)projects\/([^/]+)(?:\/|$)/i.exec(route)?.[1];
21371
21637
  let repo;
21372
21638
  try {
21373
21639
  repo = named === undefined ? undefined : decodeURIComponent(named) || "?";
@@ -21375,9 +21641,17 @@ var apiAction = (tool, args, stdin) => {
21375
21641
  repo = "?";
21376
21642
  }
21377
21643
  const at = repo === undefined ? {} : { repo };
21378
- if (API_MERGE[tool].test(endpoint))
21644
+ if (API_MERGE[tool].test(route))
21379
21645
  return { ...merge, ...at };
21380
- const grant = /\/releases(?:\/|$|\?)/i.test(endpoint) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?(?:\?|$)/i : /\/merge_requests(?:\/\d+)?\/?(?:\?|$)/i).test(endpoint) ? "pr" : null;
21646
+ const defaultBranch = API_REPOSITORY[tool].test(route) && (request.unread || values.some((value) => /default_branch/.test(value)));
21647
+ if (defaultBranch || API_SETTING[tool].some((pattern) => pattern.test(route)))
21648
+ return { ...setting, ...at };
21649
+ const shape = API_REF[tool].find(([pattern]) => pattern.test(route))?.[1];
21650
+ if (shape) {
21651
+ const { named: refs, certain } = restRef(route, fields, !request.unread && !request.input);
21652
+ return { ...refWrite(tool, new Set([shape]), refs, certain), ...at };
21653
+ }
21654
+ const grant = /\/releases(?:\/|$)/i.test(route) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?$/i : /\/merge_requests(?:\/\d+)?\/?$/i).test(route) ? "pr" : null;
21381
21655
  return grant ? { kind: "forge", forge: tool, grant, ...at } : null;
21382
21656
  };
21383
21657
  var subtreePush = (args) => {
@@ -21395,7 +21669,7 @@ var subtreePush = (args) => {
21395
21669
  function rawAction(invocation) {
21396
21670
  const args = invocation.args;
21397
21671
  if (invocation.tool !== "git" && args[0] === "api")
21398
- return apiAction(invocation.tool, args, invocation.stdin);
21672
+ return apiAction(invocation.tool, args, invocation.stdin, invocation.expanded);
21399
21673
  if (asksHelp(invocation))
21400
21674
  return null;
21401
21675
  const [first] = args;
@@ -21671,6 +21945,223 @@ var refusal = (action, branch, dir) => {
21671
21945
  return `workit: raw ${quote("git push")} onto ${branch}, a protected release branch, bypasses workit's protected-branch check. To finish a release or hotfix, push it with ${quote(`workit git push --release ${branch} [--release ${releaseTagPrefixOf(dir)}<version>]`)}: it pushes ${branch} (fast-forward only) and the release tag, verifies the remote and records it, under the ${quote("release")} grant (if refused, ask the user to run ${quote("workit grant set <workspace> release=true")}). Feature work goes through ${quote("workit git push")} and ${quote("workit pr merge")}.`;
21672
21946
  return `workit: raw ${quote("git push")}${action.kind === "push" && action.blindForce ? " --force" : ""} onto ${branch}, a protected branch or the default target, bypasses workit's protected-branch check. Push your feature branch with ${quote("workit git push")} (${quote("workit git push --force-with-lease")} to rewrite it) and land it with ${quote("workit pr merge")}.`;
21673
21947
  };
21948
+ var PLAIN_EXPANSION = /^(?:[^$`]|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})*$/u;
21949
+ var shellWord = (text, expands = false) => {
21950
+ if (/^[\w@%+=:,./-]+$/u.test(text))
21951
+ return text;
21952
+ if (expands && text.includes("$") && PLAIN_EXPANSION.test(text))
21953
+ return `"${text.replaceAll(/["\\]/gu, "\\$&")}"`;
21954
+ return `'${text.replaceAll("'", "'\\''")}'`;
21955
+ };
21956
+ var expandingWords = (command, dialect, found = new Set, depth = 0) => {
21957
+ for (const segment of segmentsOf(command, dialect))
21958
+ segment.words.forEach((text, index) => {
21959
+ if (segment.expands?.includes(index))
21960
+ found.add(text);
21961
+ else if (depth < MAX_DEPTH && /\s/u.test(text))
21962
+ expandingWords(text, "posix", found, depth + 1);
21963
+ });
21964
+ return found;
21965
+ };
21966
+ var wordsOf = (command, dialect = "posix") => {
21967
+ const expands = expandsIn(command, dialect);
21968
+ return (text) => shellWord(text, expands(text));
21969
+ };
21970
+ var expandsIn = (command, dialect = "posix") => {
21971
+ let expanding;
21972
+ return (text) => (expanding ??= expandingWords(command, dialect)).has(text);
21973
+ };
21974
+ var oneCall = (command, dialect) => {
21975
+ const steps = /^(?:\s*cd\s+[^\s;&|<>()$`'"\\]+\s*&&)*([\s\S]*)$/u.exec(command);
21976
+ return !!steps && !!simpleCommand(steps[1], dialect);
21977
+ };
21978
+ var flagWord = (flag, value, asWritten) => value.startsWith("-") ? [`${flag}=${asWritten(value)}`] : [flag, asWritten(value)];
21979
+ var PR_FLAGS = {
21980
+ "gh ready": { verb: "ready", booleans: { "--undo": ["--undo"] }, values: {} },
21981
+ "gh merge": {
21982
+ verb: "merge",
21983
+ booleans: {
21984
+ "--squash": ["--squash"],
21985
+ "-s": ["--squash"],
21986
+ "--merge": ["--merge"],
21987
+ "-m": ["--merge"],
21988
+ "--rebase": ["--rebase"],
21989
+ "-r": ["--rebase"],
21990
+ "--delete-branch": ["--delete-branch"],
21991
+ "-d": ["--delete-branch"]
21992
+ },
21993
+ values: {
21994
+ "--subject": { flag: "--subject" },
21995
+ "-t": { flag: "--subject" },
21996
+ "--body": { flag: "--body" },
21997
+ "-b": { flag: "--body" },
21998
+ "--body-file": { flag: "--body-file" },
21999
+ "-F": { flag: "--body-file" }
22000
+ }
22001
+ },
22002
+ "gh edit": {
22003
+ verb: "edit",
22004
+ booleans: {},
22005
+ values: {
22006
+ "--title": { flag: "--title" },
22007
+ "-t": { flag: "--title" },
22008
+ "--body-file": { flag: "--body-file" },
22009
+ "-F": { flag: "--body-file" },
22010
+ "--add-label": { flag: "--add-label", split: true },
22011
+ "--remove-label": { flag: "--remove-label", split: true },
22012
+ "--add-reviewer": { flag: "--add-reviewer", split: true },
22013
+ "--base": { flag: "--base" },
22014
+ "-B": { flag: "--base" }
22015
+ }
22016
+ },
22017
+ "glab merge": {
22018
+ verb: "merge",
22019
+ booleans: {
22020
+ "--squash": ["--squash"],
22021
+ "-s": ["--squash"],
22022
+ "--rebase": ["--rebase"],
22023
+ "-r": ["--rebase"],
22024
+ "--remove-source-branch": ["--delete-branch"],
22025
+ "-d": ["--delete-branch"],
22026
+ "--yes": [],
22027
+ "-y": []
22028
+ },
22029
+ values: {}
22030
+ },
22031
+ "glab update": {
22032
+ verb: "edit",
22033
+ booleans: { "--ready": [], "-r": [], "--draft": ["--undo"], "--yes": [], "-y": [] },
22034
+ values: {
22035
+ "--title": { flag: "--title" },
22036
+ "-t": { flag: "--title" },
22037
+ "--label": { flag: "--add-label", split: true },
22038
+ "-l": { flag: "--add-label", split: true },
22039
+ "--unlabel": { flag: "--remove-label", split: true },
22040
+ "-u": { flag: "--remove-label", split: true },
22041
+ "--target-branch": { flag: "--base" }
22042
+ }
22043
+ }
22044
+ };
22045
+ var prRetry = (cwd, repo, invocation, cache, asWritten) => {
22046
+ const forge = invocation.tool;
22047
+ if (forge === "git")
22048
+ return null;
22049
+ const values = VALUE_OPTIONS[forge];
22050
+ const args = invocation.args;
22051
+ let verb;
22052
+ let at = 1;
22053
+ for (;at < args.length; at++) {
22054
+ if (!args[at].startsWith("-")) {
22055
+ verb = args[at];
22056
+ break;
22057
+ }
22058
+ if (values.has(args[at]))
22059
+ at++;
22060
+ }
22061
+ const table = PR_FLAGS[`${forge} ${verb}`];
22062
+ if (!table)
22063
+ return null;
22064
+ const words = [];
22065
+ const repos = [];
22066
+ let selector;
22067
+ let ready = false;
22068
+ const rest = [...args.slice(1, at), ...args.slice(at + 1)];
22069
+ for (let index = 0;index < rest.length; index++) {
22070
+ const arg = rest[index];
22071
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
22072
+ const name = eq > 0 ? arg.slice(0, eq) : arg;
22073
+ const value = () => eq > 0 ? arg.slice(eq + 1) : rest[++index];
22074
+ if (name === "-R" || name === "--repo") {
22075
+ const named = value();
22076
+ if (named === undefined)
22077
+ return null;
22078
+ repos.push(named);
22079
+ } else if (/^-R./.test(arg))
22080
+ repos.push(arg.slice(2).replace(/^=/, ""));
22081
+ else if (eq < 0 && Object.hasOwn(table.booleans, arg)) {
22082
+ if (forge === "glab" && (arg === "--ready" || arg === "-r" || arg === "--draft")) {
22083
+ if (ready && words.includes("--undo") !== (arg === "--draft"))
22084
+ return null;
22085
+ ready = true;
22086
+ }
22087
+ words.push(...table.booleans[arg]);
22088
+ } else if (Object.hasOwn(table.values, name)) {
22089
+ const given = value();
22090
+ if (given === undefined)
22091
+ return null;
22092
+ const { flag, split } = table.values[name];
22093
+ if (split && given.includes(",") && /[$`]/.test(given))
22094
+ return null;
22095
+ for (const item of split ? given.split(",").filter(Boolean) : [given])
22096
+ words.push(...flagWord(flag, item, asWritten));
22097
+ } else if (arg.startsWith("-") || selector !== undefined)
22098
+ return null;
22099
+ else
22100
+ selector = arg;
22101
+ }
22102
+ const workitVerb = ready ? "ready" : table.verb;
22103
+ if (ready && words.some((word) => word !== "--undo"))
22104
+ return null;
22105
+ const pr = [];
22106
+ if (selector !== undefined) {
22107
+ const url = /^(https?:\/\/[^/]+\/.+?)\/(?:-\/)?(?:pull|merge_requests)\/(\d+)(?:[/?#].*)?$/.exec(selector);
22108
+ const number = url?.[2] ?? /^[#!]?(\d+)$/.exec(selector)?.[1];
22109
+ if (url)
22110
+ repos.push(url[1]);
22111
+ if (number)
22112
+ pr.push("--pr", number);
22113
+ else if (/\$[A-Za-z_{]/.test(selector))
22114
+ pr.push("--pr", asWritten(selector));
22115
+ else if (selector !== repo.branch)
22116
+ return null;
22117
+ }
22118
+ const env = invocation.env ?? {};
22119
+ if (forge === "gh" && (env.GH_REPO ?? process.env.GH_REPO))
22120
+ repos.push(env.GH_REPO ?? process.env.GH_REPO ?? "");
22121
+ if (repos.length) {
22122
+ const config = gitConfig(repo.dir, invocation, cache);
22123
+ const { GH_REPO: _named, ...own } = env;
22124
+ const key = (named, from) => {
22125
+ const found = forgeRepo(forge === "gh", named, from, config, repo.branch, repo.dir);
22126
+ return found instanceof Error ? null : found.remotes[0]?.key.toLowerCase() ?? null;
22127
+ };
22128
+ const checkout = key("", own);
22129
+ if (!checkout || repos.some((named) => /[$`]/.test(named) || key(named, own) !== checkout))
22130
+ return null;
22131
+ }
22132
+ const dir = path31.resolve(cwd, invocation.dir ?? ".");
22133
+ const call = [
22134
+ `workit pr ${workitVerb}`,
22135
+ ...dir === path31.resolve(cwd) ? [] : ["--cwd", shellWord(dir)],
22136
+ ...pr,
22137
+ ...words
22138
+ ].join(" ");
22139
+ return { raw: `${forge} ${forge === "gh" ? "pr" : "mr"} ${verb}`, call };
22140
+ };
22141
+ var prWriteRefusal = (writes, retry) => {
22142
+ const raws = [...new Set(writes.map((write) => quote(write.raw)))].join(", ");
22143
+ const calls = writes.map((write) => quote(write.call)).join(", ");
22144
+ const why = `workit: raw ${raws} changes the PR past workit's checks (the pr grant, and that the PR is this session's own).`;
22145
+ if (retry && writes.length === 1)
22146
+ return `${why} Run ${calls} instead.
22147
+ Retry as: ${writes[0].call}`;
22148
+ return `${why} Run ${writes.length > 1 ? `each as its own call: ${calls}` : `${calls} as its own call`}, in place of the raw ${writes.length > 1 ? "ones" : "one"}; the rest of this command is yours to run apart.`;
22149
+ };
22150
+ var refWriteRefusal = (action) => {
22151
+ if (action.unread)
22152
+ return `workit: raw ${quote(`${action.forge} api graphql`)} sends a document the hook cannot read (a file, stdin it does not see, or a shell expansion), so it may merge, write a ref or change branch protection past workit's checks. Write the document inline in single quotes, run the change through ${quote("workit git push")}, ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit pr merge")}, or ask the user to run it.`;
22153
+ if (action.setting)
22154
+ return `workit: raw ${quote(`${action.forge} api`)} changes branch protection, a ruleset or the default branch on the forge directly: that guards what ${quote("workit git push")} and ${quote("workit pr merge")} may do, and no agent call changes it. Ask the user to change it in the forge's settings.`;
22155
+ const steers = [
22156
+ ...action.branch ? [
22157
+ `push a branch with ${quote("workit git push")} (it refuses protected branches and verifies the remote tip)`
22158
+ ] : [],
22159
+ ...action.tag ? [
22160
+ `tag a release with ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit git push --release <tag>")}, under the ${quote("release")} grant`
22161
+ ] : []
22162
+ ];
22163
+ return `workit: raw ${quote(`${action.forge} api`)} writes ${action.ref ?? (action.tag && !action.branch ? "a tag" : action.branch && !action.tag ? "a branch" : "a ref")} on the forge directly, past workit's protected-branch check${action.tag ? " and the release grant" : ""}. Instead, ${steers.join("; ")}.`;
22164
+ };
21674
22165
  var refFacts = (repo, remote) => {
21675
22166
  const facts = {
21676
22167
  heads: new Set,
@@ -21819,6 +22310,7 @@ var nudgeFor = (action, host, session) => {
21819
22310
  case "pr-read":
21820
22311
  case "forge":
21821
22312
  case "merge":
22313
+ case "ref-write":
21822
22314
  return null;
21823
22315
  }
21824
22316
  };
@@ -21836,8 +22328,10 @@ var pushRefusal = (action, repo, config) => {
21836
22328
  return offPolicy;
21837
22329
  for (const target of targets) {
21838
22330
  const guarded = guardedTarget(repo.dir, target ?? repo.branch ?? "");
21839
- if (guarded)
21840
- return refusal(action, guarded, repo.dir);
22331
+ if (!guarded)
22332
+ continue;
22333
+ const first = !action.blindForce && !action.deletes && !facts.remoteHeads.has(guarded) ? ` ${remote} has no ${guarded} as last fetched: if it is a new, empty remote, ${quote("workit git push")} from ${guarded} makes that first push (it checks the remote first).` : "";
22334
+ return refusal(action, guarded, repo.dir) + first;
21841
22335
  }
21842
22336
  return tagRefusal(pushed, facts, repo.dir) ?? (action.deletes ? null : offPolicyPush(pushed, repo, facts, remote));
21843
22337
  };
@@ -22019,6 +22513,8 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
22019
22513
  try {
22020
22514
  guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
22021
22515
  } catch {}
22516
+ if (guarded && !switches && noRefs(repo))
22517
+ return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. This repository has no commit yet, so its root commit may go there: run ${quote("workit git commit -m '<msg>' [--all | -- <paths>]")} (it adds the Workit-Session trailer; later work goes on a branch).`;
22022
22518
  if (guarded && !switches)
22023
22519
  return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. Branch first: ${quote("workit git branch --kind feature --slug <slug>")} (uncommitted changes come along), then ${quote("workit git commit -m '<msg>' -- <paths>")}.`;
22024
22520
  const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path31.resolve(input.cwd, invocation.dir), repo);
@@ -22028,6 +22524,8 @@ function rawGitPre(input, command, options = {}) {
22028
22524
  try {
22029
22525
  const dialect = dialectOf(input);
22030
22526
  const nudges = new Map;
22527
+ const prWrites = [];
22528
+ const asWritten = wordsOf(command, dialect);
22031
22529
  let store = null;
22032
22530
  const cache = new Map;
22033
22531
  const blind = rawInvocations(command, dialect).find((raw) => raw.redirect && rawAction(raw)?.kind === "push");
@@ -22048,8 +22546,19 @@ function rawGitPre(input, command, options = {}) {
22048
22546
  if (!workit)
22049
22547
  continue;
22050
22548
  store ??= repo.location.dir;
22051
- if (action.kind === "merge")
22052
- return deny(refusal(action, null));
22549
+ if (action.kind === "merge") {
22550
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
22551
+ const named = !retry ? "" : oneCall(command, dialect) ? `
22552
+ Retry as: ${retry.call}` : ` Run ${quote(retry.call)} as its own call, in place of the raw one; the rest of this command is yours to run apart.`;
22553
+ return deny(`${refusal(action, null)}${named}`);
22554
+ }
22555
+ if (action.kind === "ref-write")
22556
+ return deny(refWriteRefusal(action));
22557
+ if (action.kind === "forge" && action.grant === "pr") {
22558
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
22559
+ if (retry)
22560
+ prWrites.push(retry);
22561
+ }
22053
22562
  if (action.kind === "push") {
22054
22563
  const refused = pushRefusal(action, repo, gitConfig(repo.dir, invocation, cache));
22055
22564
  if (refused)
@@ -22059,6 +22568,8 @@ function rawGitPre(input, command, options = {}) {
22059
22568
  if (nudge && !nudges.has(nudgeKind(action)))
22060
22569
  nudges.set(nudgeKind(action), nudge);
22061
22570
  }
22571
+ if (prWrites.length)
22572
+ return deny(prWriteRefusal(prWrites, oneCall(command, dialect)));
22062
22573
  const pkill = options.nudge === false ? null : pkillSelfMatch(command, dialect);
22063
22574
  const pkillNote = pkill ? { kind: "context", text: pkill } : NONE2;
22064
22575
  if (options.nudge === false || !store || nudges.size === 0)
@@ -22142,6 +22653,8 @@ var grantRefusal = (action, repo, invocation, cache) => {
22142
22653
  kinds.push("pr");
22143
22654
  else if (action.kind === "forge")
22144
22655
  kinds.push(action.grant);
22656
+ else if (action.kind === "ref-write")
22657
+ kinds.push(...action.branch ? ["push"] : [], ...action.tag ? ["release"] : [], ...action.unread ? ["merge"] : []);
22145
22658
  for (const kind of kinds) {
22146
22659
  const denied = rawGrantDenial(repo.dir, kind, target);
22147
22660
  if (denied)
@@ -22149,6 +22662,21 @@ var grantRefusal = (action, repo, invocation, cache) => {
22149
22662
  }
22150
22663
  return null;
22151
22664
  };
22665
+ var noRefs = (repo) => {
22666
+ const common = path31.dirname(repo.location.dir);
22667
+ const holds = (dir) => {
22668
+ try {
22669
+ return fs22.readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isFile() || entry.isDirectory() && holds(path31.join(dir, entry.name)));
22670
+ } catch {
22671
+ return false;
22672
+ }
22673
+ };
22674
+ try {
22675
+ if (/ refs\//.test(fs22.readFileSync(path31.join(common, "packed-refs"), "utf8")))
22676
+ return false;
22677
+ } catch {}
22678
+ return fs22.existsSync(path31.join(common, "refs")) && !holds(path31.join(common, "refs"));
22679
+ };
22152
22680
  var localTag = (repo, name) => {
22153
22681
  const common = path31.dirname(repo.location.dir);
22154
22682
  try {
@@ -27359,8 +27887,7 @@ var linesOf = (command, dialect) => {
27359
27887
  return null;
27360
27888
  }
27361
27889
  };
27362
- var quoteWord = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
27363
- var leaseCommand = (words) => `workit check --heavy -- ${words.map(quoteWord).join(" ")}`;
27890
+ var leaseCommand = (words, word) => `workit check --heavy -- ${words.map(word).join(" ")}`;
27364
27891
  function heavyPlan(command, options) {
27365
27892
  const dialect = options.dialect ?? "posix";
27366
27893
  if (dialect !== "posix" || !gitTop(options.cwd))
@@ -27393,7 +27920,8 @@ function heavyPlan(command, options) {
27393
27920
  }));
27394
27921
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single.reason } : { kind: "none" };
27395
27922
  }
27396
- const parts = heavy.map((match) => leaseCommand(match.line));
27923
+ const word = wordsOf(command, dialect);
27924
+ const parts = heavy.map((match) => leaseCommand(match.line, word));
27397
27925
  return {
27398
27926
  kind: "split",
27399
27927
  reason: `heavy_command: \`${command.trim()}\` chains heavy work (${heavy.map((match) => match.reason).join("; ")}) with other commands, and a chain cannot run under the machine-wide heavy-check lease. Run the heavy part alone, now: \`${parts[0]}\`; then run the other parts as their own commands${parts.length > 1 ? ", each heavy one the same way" : ""}.`,
@@ -27415,7 +27943,7 @@ function serverPlan(command, options) {
27415
27943
  const rewrite = leaseRewrite(command)?.replace("workit check --heavy --", "workit run --bg --");
27416
27944
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single, server: true } : { kind: "none" };
27417
27945
  }
27418
- const start = `workit run --bg -- ${found.line.map(quoteWord).join(" ")}`;
27946
+ const start = `workit run --bg -- ${found.line.map(wordsOf(command, dialect)).join(" ")}`;
27419
27947
  return {
27420
27948
  kind: "split",
27421
27949
  reason: `dev_server: \`${command.trim()}\` chains a dev server (${found.reason}) with other commands. Start it alone, now: \`${start}\`; then run the other parts as their own commands.`,
@@ -27450,7 +27978,7 @@ function leaseRewrite(command) {
27450
27978
  import fs27 from "node:fs";
27451
27979
  import path40 from "node:path";
27452
27980
  var HEAVY_WORDS = new Set(("npm npx pnpm pnpx yarn bun bunx deno corepack make gmake docker podman nerdctl " + "python python3 py uv poetry pdm pipenv hatch rye bundle rake nx " + "jest vitest mocha ava tap karma jasmine nyc c8 tsc vue-tsc svelte-check eslint stylelint " + "tslint webpack webpack-cli rollup parcel tsup vite next nuxt nuxi astro ng react-scripts " + "playwright cypress wdio testcafe turbo lerna sonar-scanner sonarless sonarless-mcp go " + "golangci-lint gotestsum staticcheck cargo mvn mvnw gradle gradlew ant sbt bazel bazelisk " + "buck2 dotnet msbuild pytest py.test tox nox mypy pyright pylint coverage maturin pip pip3 " + "rspec rails phpunit pest phpstan psalm composer mix swift xcodebuild flutter dart pod cmake " + "ninja meson ctest scons docker-compose buildah earthly").split(" "));
27453
- var wordsOf = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
27981
+ var wordsOf2 = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
27454
27982
  var stateDir3 = (env) => stateDir(env);
27455
27983
  var readJson2 = (file) => {
27456
27984
  try {
@@ -27476,7 +28004,7 @@ var patternWords = (cwd, env) => {
27476
28004
  for (const pattern of patterns) {
27477
28005
  if (typeof pattern !== "string")
27478
28006
  continue;
27479
- const first = wordsOf(pattern)[0];
28007
+ const first = wordsOf2(pattern)[0];
27480
28008
  if (!first || first.includes("*"))
27481
28009
  return null;
27482
28010
  words.add(first);
@@ -27485,7 +28013,7 @@ var patternWords = (cwd, env) => {
27485
28013
  };
27486
28014
  function maybeHeavy(command, cwd, env = process.env) {
27487
28015
  try {
27488
- const words = wordsOf(command);
28016
+ const words = wordsOf2(command);
27489
28017
  if (words.some((word) => HEAVY_WORDS.has(word) || /^python[\d.]*$/u.test(word)))
27490
28018
  return true;
27491
28019
  const extra = patternWords(cwd, env);
@@ -28193,7 +28721,7 @@ var wrappedScript = (input) => {
28193
28721
  const script = shellScript3(tail.argv);
28194
28722
  if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
28195
28723
  return script;
28196
- return tail.argv.map(quoteWord2).join(" ");
28724
+ return tail.argv.map(quoteWord).join(" ");
28197
28725
  };
28198
28726
  var editsOf = (input) => {
28199
28727
  const words = pastLead(input);
@@ -29069,7 +29597,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
29069
29597
  return lost;
29070
29598
  return target === undefined ? os10.homedir() : path43.resolve(dir, target);
29071
29599
  };
29072
- var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
29600
+ var quoteWord = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
29073
29601
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
29074
29602
  const value = vars.get(bare ?? braced ?? "");
29075
29603
  return value === undefined ? whole : value;
@@ -29467,7 +29995,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29467
29995
  targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
29468
29996
  const bare = strict && depth < 4 ? unwrapped2(words) : null;
29469
29997
  if (bare?.length && dir !== undefined)
29470
- targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
29998
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord).join(" "), "posix", depth + 1, strict, vars));
29471
29999
  if (strict === "registry" && dir !== undefined && depth < 4) {
29472
30000
  const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
29473
30001
  const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
@@ -29602,7 +30130,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29602
30130
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
29603
30131
  targets.push(...atAll(file));
29604
30132
  if (dir !== undefined)
29605
- for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
30133
+ for (const invocation of workitInvocations(body.map(quoteWord).join(" "), "posix")) {
29606
30134
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
29607
30135
  if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
29608
30136
  targets.push(...runsIn.map((runs) => placeholderIn(runs, DIR_TARGET)));
@@ -29611,7 +30139,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29611
30139
  return targets;
29612
30140
  };
29613
30141
  var workitRunDir = (dir, words, resolve) => {
29614
- for (const invocation of workitInvocations(words.map(quoteWord2).join(" "), "posix")) {
30142
+ for (const invocation of workitInvocations(words.map(quoteWord).join(" "), "posix")) {
29615
30143
  const { at, args } = workitCwd(dir, invocation, resolve);
29616
30144
  if (args[0] === "check" || args[0] === "lock" && args[1] === "run")
29617
30145
  return at;
@@ -32631,11 +33159,12 @@ var hinted = (write) => write.hint ? {
32631
33159
  plain: false,
32632
33160
  workit: write.hint
32633
33161
  } : write;
32634
- var ytrackArgs = (line, found, depth, names, plain) => {
33162
+ var ytrackArgs = (line, found, depth, names, plain, expands = () => false) => {
32635
33163
  const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
32636
33164
  const tail = workitCheckTail(line);
32637
33165
  if (tail) {
32638
- inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
33166
+ const live = (text) => expands(text) && /[$`]/.test(text) ? `"${text.replaceAll(/["\\]/g, "\\$&")}"` : quote2(text);
33167
+ inner("script" in tail ? tail.script : tail.argv.map(live).join(" "));
32639
33168
  return true;
32640
33169
  }
32641
33170
  const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
@@ -32665,8 +33194,9 @@ var ytrackArgs = (line, found, depth, names, plain) => {
32665
33194
  const argv = [...alias ?? [], ...line.slice(at + 1)];
32666
33195
  const write = classify2(argv);
32667
33196
  if (write) {
33197
+ const word = (text) => plain ? quote2(text) : shellWord(text, expands(text));
32668
33198
  const one = {
32669
- command: ["ytrack", ...argv].map(quote2).join(" "),
33199
+ command: ["ytrack", ...argv].map(word).join(" "),
32670
33200
  ...write,
32671
33201
  ...hostsOf(argv),
32672
33202
  plain
@@ -32769,14 +33299,15 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
32769
33299
  let found = [];
32770
33300
  const lines = plain ? plainLines(command, dialect) : null;
32771
33301
  const none = new Map;
33302
+ const expands = expandsIn(command, dialect);
32772
33303
  const plainFirst = lines ? ytrackArgs(lines.first, found, depth, none, true) : false;
32773
33304
  const joined = lines && plainFirst ? chained(found, lines.chain, depth) : null;
32774
33305
  if (joined)
32775
33306
  found = joined;
32776
- if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
33307
+ if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false, expands)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false, expands))) {
32777
33308
  found = [];
32778
33309
  for (const line of commandLines(command, dialect))
32779
- ytrackArgs(line, found, depth, aliases(command), false);
33310
+ ytrackArgs(line, found, depth, aliases(command), false, expands);
32780
33311
  found = found.map(hinted);
32781
33312
  }
32782
33313
  READ.set(key, found);
@@ -32786,7 +33317,7 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
32786
33317
  };
32787
33318
  var RELOCATES = /(?<![$\w])YTRACK_CONFIG_DIR\b/;
32788
33319
  var reachesOnly = (allowed, write) => write.plain && !!write.hosts?.length && write.hosts.every((host) => youTrackHostAllowed(allowed, host));
32789
- var scopedGate = (allowed, command, writes) => {
33320
+ var scopedGate = (allowed, command, dialect, writes) => {
32790
33321
  const scope = `youtrack.autoHosts (${allowed.join(", ")})`;
32791
33322
  if (RELOCATES.test(command))
32792
33323
  return {
@@ -32801,8 +33332,10 @@ var scopedGate = (allowed, command, writes) => {
32801
33332
  if (!unnamed.length)
32802
33333
  return null;
32803
33334
  const why = (write) => write.hosts === null ? "its --host is no literal host" : !write.hosts.length ? "it names no --host" : "it is not a plain command of its own";
32804
- const bare = unnamed.find((write) => write.bare)?.bare;
32805
- const retry = bare ? ["ytrack", "--host", first, ...bare].map(quote2).join(" ") : null;
33335
+ const hostless = unnamed.find((each) => each.bare);
33336
+ const expands = expandsIn(command, dialect);
33337
+ const word = (text) => hostless?.plain ? quote2(text) : shellWord(text, expands(text));
33338
+ const retry = hostless?.bare ? ["ytrack", "--host", first, ...hostless.bare].map(word).join(" ") : null;
32806
33339
  return {
32807
33340
  kind: "deny",
32808
33341
  reason: `${scope} posts to YouTrack unasked only from a plain ytrack call that names an allowed host with --host: ${unnamed.map((write) => `\`${write.command}\` (${why(write)})`).join(", ")}. Name the host, as its own plain call.${retry ? `
@@ -32838,7 +33371,7 @@ var ytrackGate = (cwd, command, dialect, ask) => {
32838
33371
  const hosts = policy.hosts;
32839
33372
  if (hosts === null)
32840
33373
  return null;
32841
- const scoped = scopedGate(hosts, command, writes);
33374
+ const scoped = scopedGate(hosts, command, dialect, writes);
32842
33375
  if (scoped)
32843
33376
  return scoped;
32844
33377
  writes = writes.filter((write) => !reachesOnly(hosts, write));