@workit-dev/codex 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.
@@ -71,12 +71,12 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
71
71
  };
72
72
  });
73
73
  // packages/workit-core/src/hooks/context.ts
74
- import { createHash as createHash11 } from "node:crypto";
74
+ import { createHash as createHash12 } from "node:crypto";
75
75
  import fs15 from "node:fs";
76
- import path20 from "node:path";
76
+ import path21 from "node:path";
77
77
 
78
78
  // packages/workit-core/src/core/branch.ts
79
- import { createHash as createHash4 } from "node:crypto";
79
+ import { createHash as createHash5 } from "node:crypto";
80
80
 
81
81
  // packages/workit-core/src/core/branch-policy.ts
82
82
  import { spawnSync } from "node:child_process";
@@ -295,9 +295,9 @@ var releaseTagPrefixOf = (workspaceRoot, policyPrefix) => {
295
295
 
296
296
  // packages/workit-core/src/core/workspaces.ts
297
297
  import { spawnSync as spawnSync5 } from "node:child_process";
298
- import { createHash as createHash2 } from "node:crypto";
299
- import { existsSync as existsSync3, lstatSync as lstatSync2, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
300
- import path5 from "node:path";
298
+ import { createHash as createHash3 } from "node:crypto";
299
+ import { existsSync as existsSync3, lstatSync as lstatSync2, readFileSync as readFileSync5, realpathSync as realpathSync3 } from "node:fs";
300
+ import path6 from "node:path";
301
301
 
302
302
  // node_modules/zod/v4/core/util.js
303
303
  function getEnumValues(entries) {
@@ -4041,6 +4041,103 @@ var pushTarget = (cwd, remote, replay = {}) => {
4041
4041
  return { remotes };
4042
4042
  };
4043
4043
 
4044
+ // packages/workit-core/src/core/grant-seal.ts
4045
+ import { createHash as createHash2 } from "node:crypto";
4046
+ import { readFileSync as readFileSync4 } from "node:fs";
4047
+ import path5 from "node:path";
4048
+ var SEAL_FILE = "workspaces.json.seal";
4049
+ var SEAL_VERSION = 2;
4050
+ var isSealVersion = (value) => value === 1 || value === 2;
4051
+ var SEAL_COMMAND = "workit workspace seal";
4052
+ var pick3 = (value, keys) => {
4053
+ if (!value || typeof value !== "object" || Array.isArray(value))
4054
+ return;
4055
+ const out = Object.fromEntries(keys.flatMap((key) => {
4056
+ const item = value[key];
4057
+ return item === undefined ? [] : [[key, item]];
4058
+ }));
4059
+ return Object.keys(out).length > 0 ? out : undefined;
4060
+ };
4061
+ var ENTRY_KEYS = [
4062
+ "name",
4063
+ "glob",
4064
+ "remotes",
4065
+ "externalRepos",
4066
+ "additiveRiskPaths",
4067
+ "vcs",
4068
+ "autonomy",
4069
+ "autoApprove",
4070
+ "defaultEndpoint",
4071
+ "verification",
4072
+ "youtrack"
4073
+ ];
4074
+ var RELEASE_KEYS = [
4075
+ "releaseNotes",
4076
+ "releaseTagPrefix",
4077
+ "branchPolicy",
4078
+ "profiles",
4079
+ "defaultProfile",
4080
+ "releaseTracks",
4081
+ "releasePackages"
4082
+ ];
4083
+ var keysOf = (version) => version >= 2 ? [...ENTRY_KEYS, ...RELEASE_KEYS] : ENTRY_KEYS;
4084
+ var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
4085
+ var sealProjection = (entries, version = SEAL_VERSION) => entries.map((entry) => {
4086
+ const keys = keysOf(version);
4087
+ const all = pick3(entry, keys) ?? {};
4088
+ return pick3({
4089
+ ...all,
4090
+ vcs: pick3(all.vcs, IDENTITY_KEYS),
4091
+ youtrack: pick3(all.youtrack, ["writes", "autoHosts"]),
4092
+ ...version >= 2 ? releaseLineMapping(entry, true) : {}
4093
+ }, keys);
4094
+ });
4095
+ var canonical2 = (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);
4096
+ var sealDigest = (projection) => createHash2("sha256").update(canonical2(projection)).digest("hex");
4097
+ var broken = (reason, sealed = null, version) => ({
4098
+ state: "broken",
4099
+ reason,
4100
+ sealed,
4101
+ ...version ? { version } : {}
4102
+ });
4103
+ var PARTIAL_KEYS = ["releaseTracks", "branchPolicy", "profiles", "defaultProfile"];
4104
+ var sealedEntries = (projection, file) => {
4105
+ const partial = projection.map((entry) => pick3(entry, PARTIAL_KEYS));
4106
+ const validated = validateWorkspacesDocument({
4107
+ workspaces: projection.map((entry) => {
4108
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
4109
+ return entry;
4110
+ const rest = { ...entry };
4111
+ for (const key of PARTIAL_KEYS)
4112
+ delete rest[key];
4113
+ return rest;
4114
+ })
4115
+ }, file);
4116
+ if (validated.status !== "valid" || validated.entries.length !== projection.length)
4117
+ return null;
4118
+ return validated.entries.map((entry, at) => partial[at] === undefined ? entry : { ...entry, ...partial[at] });
4119
+ };
4120
+ function checkSeal(dir) {
4121
+ const file = path5.join(dir, SEAL_FILE);
4122
+ let seal;
4123
+ try {
4124
+ seal = JSON.parse(readFileSync4(file, "utf8"));
4125
+ } catch (error) {
4126
+ if (error.code === "ENOENT")
4127
+ return { state: "none" };
4128
+ return broken(`${SEAL_FILE} cannot be read`);
4129
+ }
4130
+ if (!isSealVersion(seal?.version) || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
4131
+ return broken(`${SEAL_FILE} is malformed`);
4132
+ const version = seal.version;
4133
+ const sealed = sealedEntries(seal.projection, file);
4134
+ if (!sealed)
4135
+ return broken(`${SEAL_FILE} is malformed`, null, version);
4136
+ const current = readWorkspacesResult(dir);
4137
+ const ok = current.status === "valid" || current.status === "missing";
4138
+ return ok && sealDigest(sealProjection(current.entries, version)) === seal.sha256 ? { state: "valid", version } : broken("workspaces.json changed since it was sealed", sealed, version);
4139
+ }
4140
+
4044
4141
  // packages/workit-core/src/core/workspaces.ts
4045
4142
  var nonBlank = string2().check(refine((value) => value.trim().length > 0, "must not be blank"));
4046
4143
  var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
@@ -4106,7 +4203,7 @@ var releaseTrackSchema = looseObject({
4106
4203
  });
4107
4204
  }
4108
4205
  }
4109
- if (track.versionSource?.kind === "package-json" && (path5.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
4206
+ if (track.versionSource?.kind === "package-json" && (path6.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
4110
4207
  context.addIssue({
4111
4208
  code: "custom",
4112
4209
  path: ["versionSource", "path"],
@@ -4205,7 +4302,7 @@ var workspacesFileSchema = looseObject({
4205
4302
  names.add(workspace.name);
4206
4303
  }
4207
4304
  }));
4208
- var workspacesRevision = (contents) => createHash2("sha256").update(contents ?? "<missing>").digest("hex");
4305
+ var workspacesRevision = (contents) => createHash3("sha256").update(contents ?? "<missing>").digest("hex");
4209
4306
  var validateWorkspacesDocument = (parsed, file) => {
4210
4307
  if (!isConfigObject(parsed)) {
4211
4308
  return {
@@ -4251,10 +4348,10 @@ var validateWorkspacesDocument = (parsed, file) => {
4251
4348
  };
4252
4349
  };
4253
4350
  var readWorkspacesResult = (dir = configDir()) => {
4254
- const file = path5.join(dir, "workspaces.json");
4351
+ const file = path6.join(dir, "workspaces.json");
4255
4352
  let raw;
4256
4353
  try {
4257
- raw = readFileSync4(file, "utf8");
4354
+ raw = readFileSync5(file, "utf8");
4258
4355
  } catch (error) {
4259
4356
  if (error.code === "ENOENT")
4260
4357
  return {
@@ -4355,9 +4452,9 @@ var probeCheckout = (cwd) => {
4355
4452
  const cached = probes.get(cwd);
4356
4453
  if (cached !== undefined)
4357
4454
  return cached;
4358
- let dir = path5.resolve(cwd);
4359
- while (!existsSync3(path5.join(dir, ".git"))) {
4360
- if (["HEAD", "objects", "refs"].every((name) => existsSync3(path5.join(dir, name)))) {
4455
+ let dir = path6.resolve(cwd);
4456
+ while (!existsSync3(path6.join(dir, ".git"))) {
4457
+ if (["HEAD", "objects", "refs"].every((name) => existsSync3(path6.join(dir, name)))) {
4361
4458
  const real = realpathOf(dir);
4362
4459
  const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
4363
4460
  if (owner === null)
@@ -4366,7 +4463,7 @@ var probeCheckout = (cwd) => {
4366
4463
  probes.set(cwd, probe);
4367
4464
  return probe;
4368
4465
  }
4369
- const up = path5.dirname(dir);
4466
+ const up = path6.dirname(dir);
4370
4467
  if (up === dir)
4371
4468
  return null;
4372
4469
  dir = up;
@@ -4395,9 +4492,9 @@ var probeCheckout = (cwd) => {
4395
4492
  if (!gitDir || !common)
4396
4493
  return failed;
4397
4494
  let main = null;
4398
- if (path5.resolve(gitDir) === path5.resolve(common)) {
4495
+ if (path6.resolve(gitDir) === path6.resolve(common)) {
4399
4496
  const real = realpathOf(common);
4400
- if (!ownGitDir(path5.join(dir, ".git"), real)) {
4497
+ if (!ownGitDir(path6.join(dir, ".git"), real)) {
4401
4498
  const owner = gitDirOwner(real);
4402
4499
  if (owner === null)
4403
4500
  return Error(`${cwd} uses the repository at ${real}, owned by no checkout workit can name`);
@@ -4416,7 +4513,7 @@ var probeCheckout = (cwd) => {
4416
4513
  const list = git(["worktree", "list", "--porcelain"]);
4417
4514
  if (list === null)
4418
4515
  return failed;
4419
- main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path5.basename(common) === ".git" ? path5.dirname(common) : common);
4516
+ main = /^worktree (.+)$/mu.exec(list)?.[1]?.trim() || (path6.basename(common) === ".git" ? path6.dirname(common) : common);
4420
4517
  }
4421
4518
  const probe = { main, superproject: superproject || null };
4422
4519
  probes.set(cwd, probe);
@@ -4433,7 +4530,7 @@ var INTERNALS = ["refs", "objects", "config", "packed-refs", "commondir"];
4433
4530
  var ownInternals = (real) => {
4434
4531
  let lender = null;
4435
4532
  for (const name of INTERNALS) {
4436
- const at = path5.join(real, name);
4533
+ const at = path6.join(real, name);
4437
4534
  try {
4438
4535
  lstatSync2(at);
4439
4536
  } catch {
@@ -4445,10 +4542,10 @@ var ownInternals = (real) => {
4445
4542
  } catch {
4446
4543
  return false;
4447
4544
  }
4448
- const rel = path5.relative(real, resolved);
4449
- if (rel && !rel.startsWith("..") && !path5.isAbsolute(rel))
4545
+ const rel = path6.relative(real, resolved);
4546
+ if (rel && !rel.startsWith("..") && !path6.isAbsolute(rel))
4450
4547
  continue;
4451
- const owner = path5.basename(resolved) === name ? gitDirOwner(path5.dirname(resolved)) : null;
4548
+ const owner = path6.basename(resolved) === name ? gitDirOwner(path6.dirname(resolved)) : null;
4452
4549
  if (owner === null || lender !== null && lender !== owner)
4453
4550
  return false;
4454
4551
  lender = owner;
@@ -4462,7 +4559,7 @@ var gitDirOwner = (real) => {
4462
4559
  return null;
4463
4560
  const rest = parts.slice(at + 1);
4464
4561
  const module = rest[0] === "modules" || rest[0] === "worktrees" && rest[2] === "modules";
4465
- return rest.length === 0 || module ? parts.slice(0, at).join(path5.sep) || path5.sep : null;
4562
+ return rest.length === 0 || module ? parts.slice(0, at).join(path6.sep) || path6.sep : null;
4466
4563
  };
4467
4564
  var mainCheckoutOf = (cwd) => {
4468
4565
  const probe = probeCheckout(cwd);
@@ -4586,11 +4683,11 @@ var resolveRuntimeWorkspaceVcs = (cwd) => resolveRuntimeWorkspaceCandidate(cwd,
4586
4683
  var runtimeWorkspaceIndexSchema = looseObject({
4587
4684
  workspaces: optional(array(looseObject({ name: nonBlank, glob: nonBlank })))
4588
4685
  });
4589
- var matchRuntimeWorkspace = (cwd, dir = configDir()) => {
4590
- const file = path5.join(dir, "workspaces.json");
4686
+ var matchRuntimeWorkspace = (cwd, dir = configDir(), workspaceName = namedWorkspace()) => {
4687
+ const file = path6.join(dir, "workspaces.json");
4591
4688
  let raw;
4592
4689
  try {
4593
- raw = readFileSync4(file, "utf8");
4690
+ raw = readFileSync5(file, "utf8");
4594
4691
  } catch (error) {
4595
4692
  if (error.code === "ENOENT")
4596
4693
  return null;
@@ -4613,13 +4710,21 @@ var matchRuntimeWorkspace = (cwd, dir = configDir()) => {
4613
4710
  if (!glob.ok)
4614
4711
  throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
4615
4712
  }
4616
- const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
4617
- const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
4713
+ const matched = matchAmong(cwd, entries ?? [], workspaceName);
4714
+ return matched ? { file, ...matched } : null;
4715
+ };
4716
+ var namedWorkspace = () => process.env.WORKIT_WORKSPACE_NAME?.trim() || null;
4717
+ var matchAmong = (cwd, entries, workspaceName = namedWorkspace()) => {
4718
+ const selected = resolveWorkspaceFromEntries(cwd, entries, workspaceName ?? undefined, true);
4618
4719
  if (!selected)
4619
4720
  return null;
4620
- const matches = matchingEntries(cwd, entries ?? []);
4621
- return { file, selected, matches: matches.length ? matches : [selected] };
4721
+ const matches = matchingEntries(cwd, entries);
4722
+ return { selected, matches: matches.length ? matches : [selected] };
4622
4723
  };
4724
+ var chainOf = (matched) => matched ? [
4725
+ matched.selected,
4726
+ ...matched.matches.filter((entry) => entry !== matched.selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob))
4727
+ ] : [];
4623
4728
  var resolveRuntimeReleaseTracks = (cwd) => {
4624
4729
  const matched = matchRuntimeWorkspace(cwd);
4625
4730
  return matched ? {
@@ -4636,11 +4741,9 @@ var inheritedSetting = (cwd, dir, has) => {
4636
4741
  }
4637
4742
  if (!matched)
4638
4743
  return null;
4639
- const { selected, matches } = matched;
4640
- const enclosing = matches.filter((entry) => entry !== selected).toSorted((a, b) => globSpecificity(b.glob) - globSpecificity(a.glob));
4641
4744
  return {
4642
- workspace: selected.name,
4643
- source: [selected, ...enclosing].find(has) ?? null
4745
+ workspace: matched.selected.name,
4746
+ source: chainOf(matched).find(has) ?? null
4644
4747
  };
4645
4748
  };
4646
4749
  var resolveRuntimeReleasePackages = (cwd, dir) => {
@@ -4670,6 +4773,47 @@ var changelogPathOf = (value) => {
4670
4773
  return null;
4671
4774
  return parts.includes("..") ? null : parts.join("/");
4672
4775
  };
4776
+ var isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4777
+ var pickSet = (value, keys) => isPlainRecord(value) ? Object.fromEntries(keys.filter((key) => value[key] !== undefined).map((key) => [key, value[key]])) : {};
4778
+ var mapRecord = (value, map) => Object.fromEntries(Object.entries(value).map(([name, item]) => [name, map(item)]));
4779
+ var TRACK_LINE_KEYS = [
4780
+ "tagNamespace",
4781
+ "productionBranch",
4782
+ "integrationBranch",
4783
+ "baseBranch",
4784
+ "mergeBackBranches",
4785
+ "pullRequestTarget",
4786
+ "naming",
4787
+ "strategy"
4788
+ ];
4789
+ var releaseLineMapping = (entry, notes = false) => {
4790
+ if (!isPlainRecord(entry))
4791
+ return;
4792
+ const out = {};
4793
+ if (notes && entry.releaseNotes !== undefined)
4794
+ out.releaseNotes = entry.releaseNotes;
4795
+ if (entry.releaseTagPrefix !== undefined)
4796
+ out.releaseTagPrefix = entry.releaseTagPrefix;
4797
+ if (entry.defaultProfile !== undefined)
4798
+ out.defaultProfile = entry.defaultProfile;
4799
+ const policy = pickSet(entry.branchPolicy, ["releaseTagPrefix"]);
4800
+ if (Object.keys(policy).length)
4801
+ out.branchPolicy = policy;
4802
+ const profiles = Object.fromEntries(Object.entries(isPlainRecord(entry.profiles) ? entry.profiles : {}).flatMap(([name, profile]) => {
4803
+ const prefix = pickSet(isPlainRecord(profile) ? profile.branchPolicy : undefined, [
4804
+ "releaseTagPrefix"
4805
+ ]);
4806
+ return Object.keys(prefix).length ? [[name, { branchPolicy: prefix }]] : [];
4807
+ }));
4808
+ if (Object.keys(profiles).length)
4809
+ out.profiles = profiles;
4810
+ const trackKeys = notes ? [...TRACK_LINE_KEYS, "releaseNotes"] : TRACK_LINE_KEYS;
4811
+ if (entry.releaseTracks !== undefined)
4812
+ out.releaseTracks = isPlainRecord(entry.releaseTracks) ? mapRecord(entry.releaseTracks, (track) => pickSet(track, trackKeys)) : entry.releaseTracks;
4813
+ if (entry.releasePackages !== undefined)
4814
+ out.releasePackages = isPlainRecord(entry.releasePackages) ? mapRecord(entry.releasePackages, (pkg) => pickSet(pkg, ["tagNamespace"])) : entry.releasePackages;
4815
+ return Object.keys(out).length ? out : undefined;
4816
+ };
4673
4817
  var modelSources = (cwd, dir) => {
4674
4818
  const out = [];
4675
4819
  try {
@@ -4686,7 +4830,7 @@ var modelSources = (cwd, dir) => {
4686
4830
  }
4687
4831
  } catch {}
4688
4832
  try {
4689
- const document = JSON.parse(readFileSync4(path5.join(dir ?? configDir(), "workspaces.json"), "utf8"));
4833
+ const document = JSON.parse(readFileSync5(path6.join(dir ?? configDir(), "workspaces.json"), "utf8"));
4690
4834
  if (document && typeof document === "object" && !Array.isArray(document))
4691
4835
  out.push({
4692
4836
  name: "global",
@@ -4751,10 +4895,10 @@ function workspaceDefaultTarget(cwd, globalDefault) {
4751
4895
 
4752
4896
  // packages/workit-core/src/core/vcs-config.ts
4753
4897
  import fs3 from "node:fs";
4754
- import path6 from "node:path";
4898
+ import path7 from "node:path";
4755
4899
 
4756
4900
  // packages/workit-core/src/core/release-tracks.ts
4757
- import { createHash as createHash3 } from "node:crypto";
4901
+ import { createHash as createHash4 } from "node:crypto";
4758
4902
  import { spawnSync as spawnSync6 } from "node:child_process";
4759
4903
  class ReleaseTrackError extends Error {
4760
4904
  }
@@ -5137,7 +5281,7 @@ function resolveTrackFor(cwd, options) {
5137
5281
  ]) ?? "",
5138
5282
  git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
5139
5283
  ] : [];
5140
- key = createHash3("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
5284
+ key = createHash4("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
5141
5285
  const hit = memo2.get(key);
5142
5286
  if (hit)
5143
5287
  return hit;
@@ -5152,7 +5296,7 @@ function resolveTrackFor(cwd, options) {
5152
5296
  }
5153
5297
 
5154
5298
  // packages/workit-core/src/core/vcs-config.ts
5155
- var workspacesPath = () => path6.join(configDir(), "workspaces.json");
5299
+ var workspacesPath = () => path7.join(configDir(), "workspaces.json");
5156
5300
  var vcsCwd = (cwd) => cwd ?? process.env.WORKIT_WORKSPACE_ROOT ?? process.cwd();
5157
5301
  var remoteProvider = (cwd) => {
5158
5302
  const url = originUrl(cwd) ?? "";
@@ -5291,7 +5435,7 @@ function vcsConfig(mode, cwd, options = {}) {
5291
5435
  const prov = cfg[provider] ?? {};
5292
5436
  const out = {
5293
5437
  ok: true,
5294
- configPath: path6.resolve(cfgPath),
5438
+ configPath: path7.resolve(cfgPath),
5295
5439
  provider,
5296
5440
  defaultTargetBranch: workspaceDefault,
5297
5441
  pr: cfg.pr ?? {},
@@ -5444,7 +5588,7 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
5444
5588
  const source = resolved.provenance.branchPolicy;
5445
5589
  const allowed = branchPolicy.allowed.map((pattern) => `${pattern.source}/${pattern.flags}`).toSorted();
5446
5590
  const protectedRefs = [...branchPolicy.protected].map((name) => name.toLowerCase()).toSorted();
5447
- const fingerprint = createHash4("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
5591
+ const fingerprint = createHash5("sha256").update(JSON.stringify({ allowed, protectedRefs, source })).digest("hex");
5448
5592
  return {
5449
5593
  branchPolicy,
5450
5594
  namePolicy: { allowed: branchPolicy.allowed, protected: branchPolicy.protected },
@@ -5535,9 +5679,9 @@ var isProtectedTarget = (root, name) => {
5535
5679
  };
5536
5680
 
5537
5681
  // packages/workit-core/src/core/model-fallback.ts
5538
- import { createHash as createHash5 } from "node:crypto";
5539
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
5540
- import path7 from "node:path";
5682
+ import { createHash as createHash6 } from "node:crypto";
5683
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync6, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
5684
+ import path8 from "node:path";
5541
5685
 
5542
5686
  // packages/workit-core/src/core/logger.ts
5543
5687
  import os3 from "node:os";
@@ -5605,10 +5749,10 @@ var providerOf = (model, host) => {
5605
5749
  return null;
5606
5750
  };
5607
5751
  var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
5608
- var storePath = (stateDir) => path7.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
5752
+ var storePath = (stateDir) => path8.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
5609
5753
  var readStore = (stateDir) => {
5610
5754
  try {
5611
- const parsed = JSON.parse(readFileSync5(storePath(stateDir), "utf8"));
5755
+ const parsed = JSON.parse(readFileSync6(storePath(stateDir), "utf8"));
5612
5756
  const store = empty();
5613
5757
  for (const key of ["exhausted", "seen", "redispatched"])
5614
5758
  if (parsed[key] && typeof parsed[key] === "object")
@@ -5629,7 +5773,7 @@ var writeStore = (store, now, stateDir) => {
5629
5773
  delete store.exhausted[id];
5630
5774
  try {
5631
5775
  const file = storePath(stateDir);
5632
- mkdirSync2(path7.dirname(file), { recursive: true });
5776
+ mkdirSync2(path8.dirname(file), { recursive: true });
5633
5777
  const temp = `${file}.${process.pid}.tmp`;
5634
5778
  writeFileSync2(temp, `${JSON.stringify(store, null, 2)}
5635
5779
  `);
@@ -5665,7 +5809,7 @@ var firstSighting = (id, now = new Date, stateDir) => {
5665
5809
  writeStore(store, now, stateDir);
5666
5810
  return true;
5667
5811
  };
5668
- var promptKey = (prompt) => createHash5("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
5812
+ var promptKey = (prompt) => createHash6("sha256").update(prompt.trim()).digest("hex").slice(0, 16);
5669
5813
  var claimRedispatch = (key, now = new Date, stateDir) => {
5670
5814
  const store = readStore(stateDir);
5671
5815
  if (store.redispatched[key])
@@ -6083,14 +6227,14 @@ ${table}` : bootstrap;
6083
6227
 
6084
6228
  // packages/workit-core/src/store/paths.ts
6085
6229
  import { spawnSync as spawnSync7 } from "node:child_process";
6086
- import { createHash as createHash6 } from "node:crypto";
6230
+ import { createHash as createHash7 } from "node:crypto";
6087
6231
  import fs5 from "node:fs";
6088
- import path9 from "node:path";
6232
+ import path10 from "node:path";
6089
6233
 
6090
6234
  // packages/workit-core/src/store/folder-store.ts
6091
6235
  import fs4 from "node:fs";
6092
6236
  import os4 from "node:os";
6093
- import path8 from "node:path";
6237
+ import path9 from "node:path";
6094
6238
  var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
6095
6239
  var MOVED_POINTER = "MOVED-TO-STATE.txt";
6096
6240
  var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
@@ -6099,7 +6243,7 @@ var MARKER = "workspace.json";
6099
6243
  var v2Workspace = (workit) => {
6100
6244
  let bytes;
6101
6245
  try {
6102
- bytes = fs4.readFileSync(path8.join(workit, MARKER), "utf8");
6246
+ bytes = fs4.readFileSync(path9.join(workit, MARKER), "utf8");
6103
6247
  } catch {
6104
6248
  return null;
6105
6249
  }
@@ -6148,7 +6292,7 @@ var strayEntries = (workit) => {
6148
6292
  } catch {
6149
6293
  return [];
6150
6294
  }
6151
- return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path8.join(workit, name))) && !(name === "tasks" && onlyStubs(path8.join(workit, name))));
6295
+ return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path9.join(workit, name))) && !(name === "tasks" && onlyStubs(path9.join(workit, name))));
6152
6296
  };
6153
6297
  var folderStoreIo = {
6154
6298
  rename: (from, to) => fs4.renameSync(from, to),
@@ -6156,13 +6300,13 @@ var folderStoreIo = {
6156
6300
  judgedStale: () => {}
6157
6301
  };
6158
6302
  var tempSeq = 0;
6159
- var tempBeside = (file) => path8.join(path8.dirname(file), `.${path8.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
6303
+ var tempBeside = (file) => path9.join(path9.dirname(file), `.${path9.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
6160
6304
  var copyInto = (from, to) => {
6161
6305
  const stat = fs4.lstatSync(from);
6162
6306
  if (stat.isDirectory()) {
6163
6307
  fs4.mkdirSync(to, { recursive: true });
6164
6308
  for (const name of fs4.readdirSync(from))
6165
- copyInto(path8.join(from, name), path8.join(to, name));
6309
+ copyInto(path9.join(from, name), path9.join(to, name));
6166
6310
  return;
6167
6311
  }
6168
6312
  if (exists(to))
@@ -6213,7 +6357,7 @@ var merge2 = (from, to, rel, moved) => {
6213
6357
  }
6214
6358
  if (!isDir(from) || !isDir(to))
6215
6359
  return [rel];
6216
- const kept = fs4.readdirSync(from).flatMap((name) => merge2(path8.join(from, name), path8.join(to, name), `${rel}/${name}`, moved));
6360
+ const kept = fs4.readdirSync(from).flatMap((name) => merge2(path9.join(from, name), path9.join(to, name), `${rel}/${name}`, moved));
6217
6361
  try {
6218
6362
  if (fs4.readdirSync(from).length === 0)
6219
6363
  fs4.rmdirSync(from);
@@ -6292,38 +6436,38 @@ var takeMoveLock = (target) => {
6292
6436
  pause(25);
6293
6437
  }
6294
6438
  };
6295
- var canonical2 = (dir) => {
6439
+ var canonical3 = (dir) => {
6296
6440
  try {
6297
6441
  return fs4.realpathSync.native(dir);
6298
6442
  } catch {
6299
- return path8.resolve(dir);
6443
+ return path9.resolve(dir);
6300
6444
  }
6301
6445
  };
6302
6446
  var below = (parent, child) => {
6303
- const rel = path8.relative(parent, child);
6304
- return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
6447
+ const rel = path9.relative(parent, child);
6448
+ return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
6305
6449
  };
6306
- var insideTempDir = (dir, tempDir = os4.tmpdir()) => below(canonical2(tempDir), canonical2(dir));
6450
+ var insideTempDir = (dir, tempDir = os4.tmpdir()) => below(canonical3(tempDir), canonical3(dir));
6307
6451
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
6308
6452
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
6309
6453
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
6310
6454
  return null;
6311
- const real = canonical2(folder);
6312
- const tmp = canonical2(tempDir);
6455
+ const real = canonical3(folder);
6456
+ const tmp = canonical3(tempDir);
6313
6457
  if (insideTempDir(folder, tempDir))
6314
6458
  return null;
6315
- return `workit test run (WORKIT_TEST_RUN): refusing to move ${path8.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)`;
6459
+ return `workit test run (WORKIT_TEST_RUN): refusing to move ${path9.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
6316
6460
  };
6317
6461
  function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
6318
6462
  `)) {
6319
- const workit = path8.join(folder, ".workit");
6463
+ const workit = path9.join(folder, ".workit");
6320
6464
  const names = strayEntries(workit);
6321
6465
  const refusal = testRunFolderRefusal(folder, names.length > 0);
6322
6466
  if (refusal) {
6323
6467
  const run = process.env.WORKIT_TEST_RUN ?? "";
6324
- if (path8.isAbsolute(run))
6468
+ if (path9.isAbsolute(run))
6325
6469
  try {
6326
- fs4.appendFileSync(path8.join(run, TEST_RUN_REFUSALS), `${refusal}
6470
+ fs4.appendFileSync(path9.join(run, TEST_RUN_REFUSALS), `${refusal}
6327
6471
  `);
6328
6472
  } catch {}
6329
6473
  throw new Error(refusal);
@@ -6331,7 +6475,7 @@ function migrateFolderStore(folder, target, note = (line) => process.stderr.writ
6331
6475
  if (names.length === 0 || v2Workspace(workit) === true)
6332
6476
  return null;
6333
6477
  try {
6334
- fs4.mkdirSync(path8.dirname(target), { recursive: true });
6478
+ fs4.mkdirSync(path9.dirname(target), { recursive: true });
6335
6479
  } catch {
6336
6480
  return null;
6337
6481
  }
@@ -6355,7 +6499,7 @@ function moveLocked(workit, target, note) {
6355
6499
  }
6356
6500
  const result = { from: workit, to: target, moved: [], kept: [] };
6357
6501
  for (const name of names) {
6358
- result.kept.push(...merge2(path8.join(workit, name), path8.join(target, name), name, result.moved));
6502
+ result.kept.push(...merge2(path9.join(workit, name), path9.join(target, name), name, result.moved));
6359
6503
  }
6360
6504
  const left = (() => {
6361
6505
  try {
@@ -6364,13 +6508,13 @@ function moveLocked(workit, target, note) {
6364
6508
  return [];
6365
6509
  }
6366
6510
  })();
6367
- const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path8.join(workit, name)));
6511
+ const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path9.join(workit, name)));
6368
6512
  if (!v2Left && result.kept.length === 0) {
6369
- fs4.rmSync(path8.join(workit, MARKER), { force: true });
6370
- if (generatedIgnore(path8.join(workit, ".gitignore")))
6371
- fs4.rmSync(path8.join(workit, ".gitignore"), { force: true });
6513
+ fs4.rmSync(path9.join(workit, MARKER), { force: true });
6514
+ if (generatedIgnore(path9.join(workit, ".gitignore")))
6515
+ fs4.rmSync(path9.join(workit, ".gitignore"), { force: true });
6372
6516
  }
6373
- const pointer = path8.join(workit, MOVED_POINTER);
6517
+ const pointer = path9.join(workit, MOVED_POINTER);
6374
6518
  let wrote = false;
6375
6519
  if (result.kept.length > 0) {
6376
6520
  const text = `Workit keeps this folder's state in ${target}.
@@ -6420,7 +6564,7 @@ var gitRun = (cwd, args) => {
6420
6564
  missing: error?.code === "ENOENT"
6421
6565
  };
6422
6566
  };
6423
- var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
6567
+ var shortHash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 12);
6424
6568
  var real = (file) => {
6425
6569
  try {
6426
6570
  return fs5.realpathSync.native(file);
@@ -6437,14 +6581,14 @@ var DISCOVERY_ENV = [
6437
6581
  ];
6438
6582
  var isGitDir = (dir) => {
6439
6583
  try {
6440
- return fs5.statSync(path9.join(dir, "HEAD")).isFile() && fs5.statSync(path9.join(dir, "objects")).isDirectory() && fs5.statSync(path9.join(dir, "refs")).isDirectory();
6584
+ return fs5.statSync(path10.join(dir, "HEAD")).isFile() && fs5.statSync(path10.join(dir, "objects")).isDirectory() && fs5.statSync(path10.join(dir, "refs")).isDirectory();
6441
6585
  } catch {
6442
6586
  return false;
6443
6587
  }
6444
6588
  };
6445
6589
  var reftableRefs = (common) => {
6446
6590
  try {
6447
- return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs5.readFileSync(path9.join(common, "config"), "utf8"));
6591
+ return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs5.readFileSync(path10.join(common, "config"), "utf8"));
6448
6592
  } catch {
6449
6593
  return false;
6450
6594
  }
@@ -6464,7 +6608,7 @@ function fastGit(root) {
6464
6608
  if (device !== null && stat.dev !== device)
6465
6609
  return { kind: "none" };
6466
6610
  device = stat.dev;
6467
- const dotGit = path9.join(dir, ".git");
6611
+ const dotGit = path10.join(dir, ".git");
6468
6612
  let entry = null;
6469
6613
  try {
6470
6614
  entry = fs5.statSync(dotGit);
@@ -6485,19 +6629,19 @@ function fastGit(root) {
6485
6629
  const match = /^gitdir: (.+)$/mu.exec(text);
6486
6630
  if (!match)
6487
6631
  return null;
6488
- gitDir = path9.resolve(dir, match[1].trim());
6632
+ gitDir = path10.resolve(dir, match[1].trim());
6489
6633
  } else
6490
6634
  return null;
6491
- if (!fs5.existsSync(path9.join(gitDir, "HEAD")))
6635
+ if (!fs5.existsSync(path10.join(gitDir, "HEAD")))
6492
6636
  return null;
6493
6637
  } else if (isGitDir(dir))
6494
6638
  gitDir = dir;
6495
6639
  if (gitDir) {
6496
6640
  let common = gitDir;
6497
6641
  try {
6498
- common = path9.resolve(gitDir, fs5.readFileSync(path9.join(gitDir, "commondir"), "utf8").trim());
6642
+ common = path10.resolve(gitDir, fs5.readFileSync(path10.join(gitDir, "commondir"), "utf8").trim());
6499
6643
  } catch {}
6500
- if (!fs5.existsSync(path9.join(common, "objects")))
6644
+ if (!fs5.existsSync(path10.join(common, "objects")))
6501
6645
  return null;
6502
6646
  return {
6503
6647
  kind: "repo",
@@ -6507,7 +6651,7 @@ function fastGit(root) {
6507
6651
  reftable: reftableRefs(common)
6508
6652
  };
6509
6653
  }
6510
- const parent = path9.dirname(dir);
6654
+ const parent = path10.dirname(dir);
6511
6655
  if (parent === dir)
6512
6656
  return { kind: "none" };
6513
6657
  dir = parent;
@@ -6519,7 +6663,7 @@ var outsideGit = (root) => {
6519
6663
  return { dir, shared: false, top: null };
6520
6664
  };
6521
6665
  function resolveStore(root) {
6522
- root = path9.resolve(root);
6666
+ root = path10.resolve(root);
6523
6667
  let stat = null;
6524
6668
  try {
6525
6669
  stat = fs5.statSync(root);
@@ -6527,13 +6671,13 @@ function resolveStore(root) {
6527
6671
  if (!stat)
6528
6672
  return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
6529
6673
  if (!stat.isDirectory())
6530
- return { dir: path9.join(root, ".workit"), shared: false, top: null };
6674
+ return { dir: path10.join(root, ".workit"), shared: false, top: null };
6531
6675
  const fast = fastGit(root);
6532
6676
  if (fast?.kind === "none")
6533
6677
  return outsideGit(root);
6534
6678
  if (fast?.kind === "repo")
6535
6679
  return {
6536
- dir: path9.join(fast.common, "workit"),
6680
+ dir: path10.join(fast.common, "workit"),
6537
6681
  shared: true,
6538
6682
  top: fast.top,
6539
6683
  git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
@@ -6543,7 +6687,7 @@ function resolveStore(root) {
6543
6687
  if (run.ok && common) {
6544
6688
  const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
6545
6689
  return {
6546
- dir: path9.join(real(path9.resolve(root, common)), "workit"),
6690
+ dir: path10.join(real(path10.resolve(root, common)), "workit"),
6547
6691
  shared: true,
6548
6692
  top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
6549
6693
  };
@@ -6556,7 +6700,7 @@ function resolveStore(root) {
6556
6700
  var rebasingBranch = (gitDir) => {
6557
6701
  for (const state of ["rebase-merge", "rebase-apply"]) {
6558
6702
  try {
6559
- const ref = fs5.readFileSync(path9.join(gitDir, state, "head-name"), "utf8").trim();
6703
+ const ref = fs5.readFileSync(path10.join(gitDir, state, "head-name"), "utf8").trim();
6560
6704
  const match = /^refs\/heads\/(.+)$/u.exec(ref);
6561
6705
  if (match)
6562
6706
  return match[1];
@@ -6571,7 +6715,7 @@ function resolveTaskKey(root, location) {
6571
6715
  if (location.git && !location.git.reftable) {
6572
6716
  let head = "";
6573
6717
  try {
6574
- head = fs5.readFileSync(path9.join(location.git.gitDir, "HEAD"), "utf8").trim();
6718
+ head = fs5.readFileSync(path10.join(location.git.gitDir, "HEAD"), "utf8").trim();
6575
6719
  } catch {}
6576
6720
  const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
6577
6721
  if (ref && ref[1] !== ".invalid")
@@ -6602,7 +6746,7 @@ function resolveTaskKey(root, location) {
6602
6746
  return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
6603
6747
  }
6604
6748
  function checkoutRootOf(root, location) {
6605
- const resolved = path9.resolve(root);
6749
+ const resolved = path10.resolve(root);
6606
6750
  let canonical = resolved;
6607
6751
  try {
6608
6752
  canonical = fs5.realpathSync(resolved);
@@ -6633,13 +6777,13 @@ function branchRenames(location) {
6633
6777
  }
6634
6778
  for (const entry of entries)
6635
6779
  if (entry.isDirectory())
6636
- walk(path9.join(dir, entry.name));
6780
+ walk(path10.join(dir, entry.name));
6637
6781
  else
6638
- files.push(path9.join(dir, entry.name));
6782
+ files.push(path10.join(dir, entry.name));
6639
6783
  };
6640
- walk(path9.join(path9.dirname(location.dir), "logs", "refs", "heads"));
6784
+ walk(path10.join(path10.dirname(location.dir), "logs", "refs", "heads"));
6641
6785
  if (location.git)
6642
- files.push(path9.join(location.git.gitDir, "logs", "HEAD"));
6786
+ files.push(path10.join(location.git.gitDir, "logs", "HEAD"));
6643
6787
  const seen = new Set;
6644
6788
  const renames = [];
6645
6789
  for (const file of files) {
@@ -6673,7 +6817,7 @@ function followRenames(key, boundAt, renames) {
6673
6817
  var checkoutSlug = (root) => folderSlug2(root);
6674
6818
 
6675
6819
  // packages/workit-core/src/core/task-contract.ts
6676
- import { createHash as createHash7, randomUUID } from "node:crypto";
6820
+ import { createHash as createHash8, randomUUID } from "node:crypto";
6677
6821
 
6678
6822
  // packages/workit-core/src/core/scope-glob.ts
6679
6823
  var GLOB = /[*?[\]{}]/u;
@@ -7235,7 +7379,7 @@ function resolveIdRef(kind, ref, ids) {
7235
7379
  return failure2("not_found", `${kind} not found`);
7236
7380
  return failure2("invalid_input", `${kind} prefix ${ref} is ambiguous; candidates: ${matches.join(", ")}`);
7237
7381
  }
7238
- function canonical3(value, seen) {
7382
+ function canonical4(value, seen) {
7239
7383
  if (value === null || typeof value === "boolean" || typeof value === "string") {
7240
7384
  if (typeof value === "string" && invalidUnicode(value))
7241
7385
  throw new TypeError("invalid Unicode");
@@ -7257,7 +7401,7 @@ function canonical3(value, seen) {
7257
7401
  if (!(index in value))
7258
7402
  throw new TypeError("sparse array");
7259
7403
  }
7260
- result = value.map((item) => canonical3(item, seen));
7404
+ result = value.map((item) => canonical4(item, seen));
7261
7405
  } else {
7262
7406
  if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
7263
7407
  throw new TypeError("value is not a JSON object");
@@ -7265,18 +7409,18 @@ function canonical3(value, seen) {
7265
7409
  throw new TypeError("symbol key is not JSON");
7266
7410
  if (Object.keys(value).some((key) => invalidUnicode(key)))
7267
7411
  throw new TypeError("invalid Unicode");
7268
- result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical3(value[key], seen)]));
7412
+ result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical4(value[key], seen)]));
7269
7413
  }
7270
7414
  seen.delete(value);
7271
7415
  return result;
7272
7416
  }
7273
7417
  function canonicalJson(value) {
7274
- return JSON.stringify(canonical3(value, new Set));
7418
+ return JSON.stringify(canonical4(value, new Set));
7275
7419
  }
7276
7420
  function sha256(value) {
7277
7421
  if (typeof value === "string" && invalidUnicode(value))
7278
7422
  throw new TypeError("invalid Unicode");
7279
- return createHash7("sha256").update(typeof value === "string" ? value : canonicalJson(value), "utf8").digest("hex");
7423
+ return createHash8("sha256").update(typeof value === "string" ? value : canonicalJson(value), "utf8").digest("hex");
7280
7424
  }
7281
7425
  function newId() {
7282
7426
  return randomUUID().toLowerCase();
@@ -7311,15 +7455,15 @@ function candidateDigest(input) {
7311
7455
  }
7312
7456
 
7313
7457
  // packages/workit-core/src/core/task-evaluation.ts
7314
- import { createHash as createHash10 } from "node:crypto";
7458
+ import { createHash as createHash11 } from "node:crypto";
7315
7459
  import * as fs14 from "node:fs";
7316
7460
  import { spawnSync as spawnSync12 } from "node:child_process";
7317
- import path19 from "node:path";
7461
+ import path20 from "node:path";
7318
7462
 
7319
7463
  // packages/workit-core/src/core/task-read.ts
7320
7464
  import { randomUUID as randomUUID3 } from "node:crypto";
7321
7465
  import * as fs11 from "node:fs";
7322
- import path14 from "node:path";
7466
+ import path15 from "node:path";
7323
7467
 
7324
7468
  // node_modules/@openclaw/fs-safe/dist/errors.js
7325
7469
  var OPERATIONAL_CODES = new Set([
@@ -7370,7 +7514,7 @@ function sameFileIdentity(left, right, platform = process.platform) {
7370
7514
  // node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
7371
7515
  import { randomBytes } from "node:crypto";
7372
7516
  import fsSync from "node:fs";
7373
- import path10 from "node:path";
7517
+ import path11 from "node:path";
7374
7518
 
7375
7519
  // node_modules/@openclaw/fs-safe/dist/bounded-read.js
7376
7520
  import fs6 from "node:fs";
@@ -7460,13 +7604,13 @@ ${ownershipToken}
7460
7604
  return { raw, ownershipToken };
7461
7605
  }
7462
7606
  function relativeSidecarLockPath(lockRoot, lockPath) {
7463
- const resolved = path10.resolve(lockPath);
7464
- const lexicalRelative = path10.relative(lockRoot.rootDir, resolved);
7465
- const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path10.sep}`) && !path10.isAbsolute(lexicalRelative) ? lexicalRelative : path10.relative(lockRoot.rootReal, resolved);
7466
- if (!relative || relative === ".." || relative.startsWith(`..${path10.sep}`) || path10.isAbsolute(relative)) {
7607
+ const resolved = path11.resolve(lockPath);
7608
+ const lexicalRelative = path11.relative(lockRoot.rootDir, resolved);
7609
+ const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path11.sep}`) && !path11.isAbsolute(lexicalRelative) ? lexicalRelative : path11.relative(lockRoot.rootReal, resolved);
7610
+ if (!relative || relative === ".." || relative.startsWith(`..${path11.sep}`) || path11.isAbsolute(relative)) {
7467
7611
  throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
7468
7612
  }
7469
- return relative.split(path10.sep).join(path10.posix.sep);
7613
+ return relative.split(path11.sep).join(path11.posix.sep);
7470
7614
  }
7471
7615
  function parseSidecarLockPayload(raw, parser) {
7472
7616
  if (parser) {
@@ -7613,7 +7757,7 @@ function getFsSafeLockConfig() {
7613
7757
 
7614
7758
  // node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
7615
7759
  import fs8 from "node:fs";
7616
- import path11 from "node:path";
7760
+ import path12 from "node:path";
7617
7761
 
7618
7762
  // node_modules/@openclaw/fs-safe/dist/timing.js
7619
7763
  function sleepSync(ms) {
@@ -7704,26 +7848,26 @@ function canonicalLockParentSync(parent) {
7704
7848
  return process.platform === "win32" ? fs8.realpathSync.native(parent) : fs8.realpathSync(parent);
7705
7849
  }
7706
7850
  function normalizeTargetPath(targetPath) {
7707
- const resolved = path11.resolve(targetPath);
7708
- fs8.mkdirSync(path11.dirname(resolved), { recursive: true });
7851
+ const resolved = path12.resolve(targetPath);
7852
+ fs8.mkdirSync(path12.dirname(resolved), { recursive: true });
7709
7853
  try {
7710
- return path11.join(canonicalLockParentSync(path11.dirname(resolved)), path11.basename(resolved));
7854
+ return path12.join(canonicalLockParentSync(path12.dirname(resolved)), path12.basename(resolved));
7711
7855
  } catch {
7712
7856
  return resolved;
7713
7857
  }
7714
7858
  }
7715
7859
  function boundedLockPath(lockPath, lockRoot) {
7716
- const resolved = path11.resolve(lockPath);
7860
+ const resolved = path12.resolve(lockPath);
7717
7861
  if (!lockRoot)
7718
7862
  return resolved;
7719
7863
  relativeSidecarLockPath(lockRoot, resolved);
7720
- const parent = path11.dirname(resolved);
7864
+ const parent = path12.dirname(resolved);
7721
7865
  const parentReal = canonicalLockParentSync(parent);
7722
- const parentRelative = path11.relative(lockRoot.rootReal, parentReal);
7723
- if (parentRelative === ".." || parentRelative.startsWith(`..${path11.sep}`) || path11.isAbsolute(parentRelative)) {
7866
+ const parentRelative = path12.relative(lockRoot.rootReal, parentReal);
7867
+ if (parentRelative === ".." || parentRelative.startsWith(`..${path12.sep}`) || path12.isAbsolute(parentRelative)) {
7724
7868
  throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
7725
7869
  }
7726
- return path11.join(parentReal, path11.basename(resolved));
7870
+ return path12.join(parentReal, path12.basename(resolved));
7727
7871
  }
7728
7872
  function defaultShouldReclaim(snapshot, staleMs, nowMs) {
7729
7873
  const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
@@ -7924,13 +8068,13 @@ function acquireFileLockSync(targetPath, options) {
7924
8068
  }
7925
8069
  // packages/workit-core/src/core/package-root.ts
7926
8070
  import { existsSync as existsSync4 } from "node:fs";
7927
- import path12 from "node:path";
8071
+ import path13 from "node:path";
7928
8072
  import { fileURLToPath } from "node:url";
7929
8073
  var packageRoot = () => {
7930
- let dir = path12.dirname(fileURLToPath(import.meta.url));
8074
+ let dir = path13.dirname(fileURLToPath(import.meta.url));
7931
8075
  while (true) {
7932
- const parent = path12.dirname(dir);
7933
- if (existsSync4(path12.join(dir, "package.json")) || parent === dir)
8076
+ const parent = path13.dirname(dir);
8077
+ if (existsSync4(path13.join(dir, "package.json")) || parent === dir)
7934
8078
  return dir;
7935
8079
  dir = parent;
7936
8080
  }
@@ -8088,7 +8232,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
8088
8232
  // packages/workit-core/src/store/event-log.ts
8089
8233
  import { randomUUID as randomUUID2 } from "node:crypto";
8090
8234
  import fs10 from "node:fs";
8091
- import path13 from "node:path";
8235
+ import path14 from "node:path";
8092
8236
  var EVENT_VERSION = 1;
8093
8237
 
8094
8238
  class LogDamage extends Error {
@@ -8189,7 +8333,7 @@ function replaceFile(file, bytes, durable) {
8189
8333
  }
8190
8334
  renameWithRetry(temporary, file);
8191
8335
  if (durable)
8192
- fsyncDirectory(path13.dirname(file));
8336
+ fsyncDirectory(path14.dirname(file));
8193
8337
  } catch (error) {
8194
8338
  try {
8195
8339
  fs10.unlinkSync(temporary);
@@ -8426,7 +8570,7 @@ var cachedRuntimeVersion = null;
8426
8570
  var runtimeVersion = () => {
8427
8571
  if (cachedRuntimeVersion === null) {
8428
8572
  try {
8429
- const pkg = JSON.parse(fs11.readFileSync(path14.join(packageRoot(), "package.json"), "utf8"));
8573
+ const pkg = JSON.parse(fs11.readFileSync(path15.join(packageRoot(), "package.json"), "utf8"));
8430
8574
  cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
8431
8575
  } catch {
8432
8576
  cachedRuntimeVersion = "0.0.0";
@@ -8455,7 +8599,7 @@ var readText2 = (file) => {
8455
8599
  };
8456
8600
  var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
8457
8601
  var branchStart = (location, branch, aliases) => {
8458
- const first = readText2(path14.join(path14.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
8602
+ const first = readText2(path15.join(path15.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
8459
8603
  `, 1)[0];
8460
8604
  const created = REFLOG_LINE.exec(first);
8461
8605
  const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
@@ -8465,7 +8609,7 @@ var branchStart = (location, branch, aliases) => {
8465
8609
  return start;
8466
8610
  if (!location.git)
8467
8611
  return null;
8468
- for (const line of readText2(path14.join(location.git.gitDir, "logs", "HEAD")).split(`
8612
+ for (const line of readText2(path15.join(location.git.gitDir, "logs", "HEAD")).split(`
8469
8613
  `)) {
8470
8614
  const entry = REFLOG_LINE.exec(line);
8471
8615
  const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
@@ -8475,14 +8619,14 @@ var branchStart = (location, branch, aliases) => {
8475
8619
  }
8476
8620
  return null;
8477
8621
  };
8478
- var refExists2 = (common, ref) => fs11.existsSync(path14.join(common, ref)) || readText2(path14.join(common, "packed-refs")).includes(` ${ref}
8622
+ var refExists2 = (common, ref) => fs11.existsSync(path15.join(common, ref)) || readText2(path15.join(common, "packed-refs")).includes(` ${ref}
8479
8623
  `);
8480
8624
  var origins = new Map;
8481
8625
  var sameDirectoryIdentity = (left, right) => {
8482
- if (!path14.isAbsolute(left) || !path14.isAbsolute(right))
8626
+ if (!path15.isAbsolute(left) || !path15.isAbsolute(right))
8483
8627
  return false;
8484
- const normalizedLeft = path14.resolve(left);
8485
- const normalizedRight = path14.resolve(right);
8628
+ const normalizedLeft = path15.resolve(left);
8629
+ const normalizedRight = path15.resolve(right);
8486
8630
  try {
8487
8631
  const a = fs11.statSync(normalizedLeft, { bigint: true });
8488
8632
  const b = fs11.statSync(normalizedRight, { bigint: true });
@@ -8516,14 +8660,14 @@ class TaskReader {
8516
8660
  located;
8517
8661
  migrationChecked = false;
8518
8662
  constructor(root, options = {}) {
8519
- const resolved = path14.resolve(root);
8663
+ const resolved = path15.resolve(root);
8520
8664
  this.origin = fs11.existsSync(resolved) ? fs11.realpathSync(resolved) : resolved;
8521
8665
  this.located = resolveStore(this.origin);
8522
8666
  this.root = checkoutRootOf(this.origin, this.located);
8523
8667
  this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
8524
8668
  }
8525
8669
  location() {
8526
- if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs11.existsSync(path14.join(this.root, ".git"))) {
8670
+ if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs11.existsSync(path15.join(this.root, ".git"))) {
8527
8671
  this.located = undefined;
8528
8672
  this.migrationChecked = false;
8529
8673
  }
@@ -8681,14 +8825,14 @@ class TaskReader {
8681
8825
  const branch = key.ok ? key.data.branch : null;
8682
8826
  if (!branch || !location.ok)
8683
8827
  return success(null, null, null);
8684
- const common = path14.dirname(location.data.dir);
8685
- const heads = path14.join(common, "logs", "refs", "heads");
8686
- const headLog = location.data.git ? path14.join(location.data.git.gitDir, "logs", "HEAD") : "";
8828
+ const common = path15.dirname(location.data.dir);
8829
+ const heads = path15.join(common, "logs", "refs", "heads");
8830
+ const headLog = location.data.git ? path15.join(location.data.git.gitDir, "logs", "HEAD") : "";
8687
8831
  const signatures = [
8688
- path14.join(heads, branch),
8832
+ path15.join(heads, branch),
8689
8833
  headLog,
8690
8834
  heads,
8691
- path14.join(common, "packed-refs")
8835
+ path15.join(common, "packed-refs")
8692
8836
  ].map((file) => fileSignature(file) ?? "-");
8693
8837
  const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
8694
8838
  let resolved = origins.get(slot);
@@ -8700,7 +8844,7 @@ class TaskReader {
8700
8844
  aliases.push(rename.from);
8701
8845
  const start = branchStart(location.data, branch, aliases);
8702
8846
  const slash = start?.indexOf("/") ?? -1;
8703
- const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path14.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
8847
+ const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path15.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
8704
8848
  const name = start && (remote ? start.slice(slash + 1) : start);
8705
8849
  resolved = {
8706
8850
  signature: signatures.join("|"),
@@ -8720,27 +8864,27 @@ class TaskReader {
8720
8864
  }
8721
8865
  paths() {
8722
8866
  const location = this.location();
8723
- const dir = location.ok ? location.data.dir : path14.join(this.root, ".workit");
8724
- const checkout = path14.join(dir, "checkouts", checkoutSlug(this.root));
8867
+ const dir = location.ok ? location.data.dir : path15.join(this.root, ".workit");
8868
+ const checkout = path15.join(dir, "checkouts", checkoutSlug(this.root));
8725
8869
  return {
8726
8870
  dir,
8727
8871
  shared: location.ok ? location.data.shared : false,
8728
- marker: path14.join(dir, "store.json"),
8872
+ marker: path15.join(dir, "store.json"),
8729
8873
  checkout,
8730
- workspace: path14.join(checkout, "workspace.json"),
8731
- checkoutLock: path14.join(checkout, "metadata.lock"),
8732
- tasks: path14.join(dir, "tasks"),
8733
- index: path14.join(dir, "task-index.json"),
8734
- blobs: path14.join(dir, "blobs", "candidates"),
8735
- legacy: path14.join(dir, "legacy", checkoutSlug(this.root), "v2"),
8736
- v2: path14.join(this.root, ".workit")
8874
+ workspace: path15.join(checkout, "workspace.json"),
8875
+ checkoutLock: path15.join(checkout, "metadata.lock"),
8876
+ tasks: path15.join(dir, "tasks"),
8877
+ index: path15.join(dir, "task-index.json"),
8878
+ blobs: path15.join(dir, "blobs", "candidates"),
8879
+ legacy: path15.join(dir, "legacy", checkoutSlug(this.root), "v2"),
8880
+ v2: path15.join(this.root, ".workit")
8737
8881
  };
8738
8882
  }
8739
8883
  eventsPath(taskId) {
8740
- return path14.join(this.paths().tasks, taskId, "events.jsonl");
8884
+ return path15.join(this.paths().tasks, taskId, "events.jsonl");
8741
8885
  }
8742
8886
  snapshotPath(taskId) {
8743
- return path14.join(this.paths().tasks, taskId, "snapshot.json");
8887
+ return path15.join(this.paths().tasks, taskId, "snapshot.json");
8744
8888
  }
8745
8889
  ready(write = false) {
8746
8890
  const location = this.location();
@@ -8775,7 +8919,7 @@ class TaskReader {
8775
8919
  return {
8776
8920
  read: (digest) => {
8777
8921
  try {
8778
- return JSON.parse(fs11.readFileSync(path14.join(dir, `${digest}.json`), "utf8"));
8922
+ return JSON.parse(fs11.readFileSync(path15.join(dir, `${digest}.json`), "utf8"));
8779
8923
  } catch (error) {
8780
8924
  throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
8781
8925
  }
@@ -8941,11 +9085,11 @@ class TaskReader {
8941
9085
  return failure2("recovery_required", `${label} record does not satisfy its schema`);
8942
9086
  }
8943
9087
  v2Dirs() {
8944
- return [...new Set([this.root, this.origin])].map((dir) => path14.join(dir, ".workit"));
9088
+ return [...new Set([this.root, this.origin])].map((dir) => path15.join(dir, ".workit"));
8945
9089
  }
8946
9090
  pendingMigrations() {
8947
9091
  return this.v2Dirs().filter((dir) => {
8948
- const raw = this.readV2Workspace(path14.join(dir, "workspace.json"));
9092
+ const raw = this.readV2Workspace(path15.join(dir, "workspace.json"));
8949
9093
  return raw !== null && raw !== TOMBSTONE;
8950
9094
  });
8951
9095
  }
@@ -8961,7 +9105,7 @@ class TaskReader {
8961
9105
  }
8962
9106
  adoptStoreFrom(local) {
8963
9107
  const dirs = this.paths();
8964
- const marker = path14.join(local, "store.json");
9108
+ const marker = path15.join(local, "store.json");
8965
9109
  if (!fs11.existsSync(marker))
8966
9110
  return success(null, null, null);
8967
9111
  return this.withLock(dirs.checkoutLock, () => {
@@ -8971,7 +9115,7 @@ class TaskReader {
8971
9115
  try {
8972
9116
  const merge = (from, to) => {
8973
9117
  if (!fs11.existsSync(to)) {
8974
- fs11.mkdirSync(path14.dirname(to), { recursive: true });
9118
+ fs11.mkdirSync(path15.dirname(to), { recursive: true });
8975
9119
  try {
8976
9120
  fs11.renameSync(from, to);
8977
9121
  } catch {
@@ -8982,24 +9126,24 @@ class TaskReader {
8982
9126
  }
8983
9127
  if (fs11.lstatSync(from).isDirectory() && fs11.lstatSync(to).isDirectory())
8984
9128
  for (const name of fs11.readdirSync(from))
8985
- merge(path14.join(from, name), path14.join(to, name));
9129
+ merge(path15.join(from, name), path15.join(to, name));
8986
9130
  };
8987
9131
  for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
8988
- const from = path14.join(local, sub);
9132
+ const from = path15.join(local, sub);
8989
9133
  if (!fs11.existsSync(from))
8990
9134
  continue;
8991
9135
  if (sub === "tasks") {
8992
9136
  for (const name of fs11.readdirSync(from))
8993
- if (validId(name) && !fs11.existsSync(path14.join(dirs.dir, sub, name)))
9137
+ if (validId(name) && !fs11.existsSync(path15.join(dirs.dir, sub, name)))
8994
9138
  tasks += 1;
8995
9139
  }
8996
- merge(from, path14.join(dirs.dir, sub));
9140
+ merge(from, path15.join(dirs.dir, sub));
8997
9141
  }
8998
- const ledger = path14.join(local, "ledger");
8999
- if (fs11.existsSync(ledger) && !fs11.existsSync(path14.join(dirs.dir, "ledger")))
9000
- merge(ledger, path14.join(dirs.dir, "ledger"));
9001
- fs11.rmSync(path14.join(local, "task-index.json"), { force: true });
9002
- fs11.renameSync(marker, path14.join(local, "store.moved.json"));
9142
+ const ledger = path15.join(local, "ledger");
9143
+ if (fs11.existsSync(ledger) && !fs11.existsSync(path15.join(dirs.dir, "ledger")))
9144
+ merge(ledger, path15.join(dirs.dir, "ledger"));
9145
+ fs11.rmSync(path15.join(local, "task-index.json"), { force: true });
9146
+ fs11.renameSync(marker, path15.join(local, "store.moved.json"));
9003
9147
  } catch (error) {
9004
9148
  return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
9005
9149
  path: local
@@ -9037,7 +9181,7 @@ class TaskReader {
9037
9181
  schemaVersion: SCHEMA_VERSION,
9038
9182
  id: workspaceId ?? newId(),
9039
9183
  revision: newRevision(),
9040
- root: path14.dirname(v2),
9184
+ root: path15.dirname(v2),
9041
9185
  runtime: { createdWith: version, updatedWith: version },
9042
9186
  writer: null,
9043
9187
  store: {
@@ -9049,11 +9193,11 @@ class TaskReader {
9049
9193
  critical: ["store"]
9050
9194
  };
9051
9195
  fs11.mkdirSync(v2, { recursive: true });
9052
- const ignore = path14.join(v2, ".gitignore");
9196
+ const ignore = path15.join(v2, ".gitignore");
9053
9197
  if (!fs11.existsSync(ignore))
9054
9198
  fs11.writeFileSync(ignore, `*
9055
9199
  `);
9056
- replaceFile(path14.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
9200
+ replaceFile(path15.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
9057
9201
  `, true);
9058
9202
  }
9059
9203
  initializeStorage() {
@@ -9112,7 +9256,7 @@ class TaskReader {
9112
9256
  withLock(lockPath, operation) {
9113
9257
  try {
9114
9258
  this.initializeStorage();
9115
- fs11.mkdirSync(path14.dirname(lockPath), { recursive: true });
9259
+ fs11.mkdirSync(path15.dirname(lockPath), { recursive: true });
9116
9260
  } catch (error) {
9117
9261
  return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
9118
9262
  path: this.paths().dir
@@ -9175,7 +9319,7 @@ class TaskReader {
9175
9319
  if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
9176
9320
  return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
9177
9321
  path: lockPath,
9178
- guidance: `Check permissions and the read-only attribute on ${path14.dirname(lockPath)}.`
9322
+ guidance: `Check permissions and the read-only attribute on ${path15.dirname(lockPath)}.`
9179
9323
  });
9180
9324
  if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
9181
9325
  let lock = null;
@@ -9195,13 +9339,13 @@ class TaskReader {
9195
9339
 
9196
9340
  // packages/workit-core/src/core/policy/derive.ts
9197
9341
  import { existsSync as existsSync7 } from "node:fs";
9198
- import path18 from "node:path";
9342
+ import path19 from "node:path";
9199
9343
 
9200
9344
  // packages/workit-core/src/ledger.ts
9201
9345
  import { spawnSync as spawnSync11 } from "node:child_process";
9202
- import { createHash as createHash9, randomBytes as randomBytes3 } from "node:crypto";
9346
+ import { createHash as createHash10, randomBytes as randomBytes3 } from "node:crypto";
9203
9347
  import fs13 from "node:fs";
9204
- import path17 from "node:path";
9348
+ import path18 from "node:path";
9205
9349
 
9206
9350
  // packages/workit-core/src/core/policy/bookkeeping.ts
9207
9351
  import { spawnSync as spawnSync9 } from "node:child_process";
@@ -9281,8 +9425,8 @@ function bookkeepingPaths(cwd, input) {
9281
9425
  }
9282
9426
 
9283
9427
  // packages/workit-core/src/core/policy/lane.ts
9284
- import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
9285
- import path15 from "node:path";
9428
+ import { existsSync as existsSync6, readFileSync as readFileSync8 } from "node:fs";
9429
+ import path16 from "node:path";
9286
9430
 
9287
9431
  // packages/workit-core/src/git/default-base.ts
9288
9432
  import { spawnSync as spawnSync10 } from "node:child_process";
@@ -10673,7 +10817,7 @@ function computeLane(input) {
10673
10817
  }
10674
10818
  function untrackedStat(cwd, file) {
10675
10819
  try {
10676
- const bytes = readFileSync7(path15.join(cwd, file));
10820
+ const bytes = readFileSync8(path16.join(cwd, file));
10677
10821
  if (bytes.includes(0))
10678
10822
  return { path: file, added: 0, deleted: 0, binary: true };
10679
10823
  const text = bytes.toString("utf8");
@@ -10705,7 +10849,7 @@ function cosmeticFiles(cwd, fork, head) {
10705
10849
  let after = blobs.get(entry.newBlob);
10706
10850
  if (!after && head === null && ABSENT.test(entry.newBlob))
10707
10851
  try {
10708
- after = readFileSync7(path15.join(cwd, entry.path));
10852
+ after = readFileSync8(path16.join(cwd, entry.path));
10709
10853
  } catch {
10710
10854
  after = undefined;
10711
10855
  }
@@ -10860,9 +11004,9 @@ function verdictDrift(cwd, input) {
10860
11004
  }
10861
11005
 
10862
11006
  // packages/workit-core/src/host-session.ts
10863
- import { createHash as createHash8, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
11007
+ import { createHash as createHash9, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
10864
11008
  import fs12 from "node:fs";
10865
- import path16 from "node:path";
11009
+ import path17 from "node:path";
10866
11010
  var STAMPING_HOSTS = new Set([
10867
11011
  "claude_code",
10868
11012
  "codex_cli",
@@ -10870,13 +11014,13 @@ var STAMPING_HOSTS = new Set([
10870
11014
  ]);
10871
11015
  var ISSUED_PER_LEAD = 64;
10872
11016
  var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
10873
- var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
11017
+ var hash = (value) => createHash9("sha256").update(value).digest("hex").slice(0, 32);
10874
11018
  var PIN_FILE = "issued-registry";
10875
11019
  var pinFiles = new Map;
10876
11020
  var pinFile = (cwd) => {
10877
11021
  if (cwd === undefined)
10878
11022
  return null;
10879
- const key = path16.resolve(cwd);
11023
+ const key = path17.resolve(cwd);
10880
11024
  const known = pinFiles.get(key);
10881
11025
  if (known !== undefined)
10882
11026
  return known;
@@ -10884,7 +11028,7 @@ var pinFile = (cwd) => {
10884
11028
  const location = resolveStore(key);
10885
11029
  if (location instanceof Error)
10886
11030
  return null;
10887
- const file = location.shared ? path16.join(location.dir, "ledger", PIN_FILE) : null;
11031
+ const file = location.shared ? path17.join(location.dir, "ledger", PIN_FILE) : null;
10888
11032
  pinFiles.set(key, file);
10889
11033
  return file;
10890
11034
  } catch {
@@ -10897,32 +11041,32 @@ var pinnedStateDir = (cwd) => {
10897
11041
  return null;
10898
11042
  try {
10899
11043
  const pinned = fs12.readFileSync(file, "utf8").trim();
10900
- return path16.isAbsolute(pinned) ? pinned : null;
11044
+ return path17.isAbsolute(pinned) ? pinned : null;
10901
11045
  } catch {
10902
11046
  return null;
10903
11047
  }
10904
11048
  };
10905
11049
  var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
10906
- var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path16.dirname(path16.dirname(path16.dirname(file))));
11050
+ var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path17.dirname(path17.dirname(path17.dirname(file))));
10907
11051
  function pinIssuedRegistry(cwd) {
10908
11052
  const file = pinFile(cwd);
10909
11053
  if (file === null)
10910
11054
  return;
10911
- const state = path16.resolve(resolveStateDir());
11055
+ const state = path17.resolve(resolveStateDir());
10912
11056
  if (pinnedStateDir(cwd) === state)
10913
11057
  return;
10914
11058
  if (testRunSkipsPin(file))
10915
11059
  return;
10916
11060
  try {
10917
- fs12.mkdirSync(path16.dirname(file), { recursive: true });
11061
+ fs12.mkdirSync(path17.dirname(file), { recursive: true });
10918
11062
  const temp = `${file}.${process.pid}.tmp`;
10919
11063
  fs12.writeFileSync(temp, `${state}
10920
11064
  `, { mode: 420 });
10921
11065
  fs12.renameSync(temp, file);
10922
11066
  } catch {}
10923
11067
  }
10924
- var userIssuedRoot = (cwd) => path16.join(registryDir(cwd), "issued");
10925
- var userTokenRoot = (cwd) => path16.join(registryDir(cwd), "issued-tokens");
11068
+ var userIssuedRoot = (cwd) => path17.join(registryDir(cwd), "issued");
11069
+ var userTokenRoot = (cwd) => path17.join(registryDir(cwd), "issued-tokens");
10926
11070
  function migrateRepoIssued(cwd) {
10927
11071
  if (cwd === undefined)
10928
11072
  return;
@@ -10931,7 +11075,7 @@ function migrateRepoIssued(cwd) {
10931
11075
  const location = resolveStore(cwd);
10932
11076
  if (location instanceof Error)
10933
11077
  return;
10934
- old = path16.join(location.dir, "hooks", "issued");
11078
+ old = path17.join(location.dir, "hooks", "issued");
10935
11079
  if (!fs12.existsSync(old))
10936
11080
  return;
10937
11081
  } catch {
@@ -10939,19 +11083,19 @@ function migrateRepoIssued(cwd) {
10939
11083
  }
10940
11084
  for (const lead of safeList(old)) {
10941
11085
  try {
10942
- const from = path16.join(old, lead);
11086
+ const from = path17.join(old, lead);
10943
11087
  if (!fs12.statSync(from).isDirectory())
10944
11088
  continue;
10945
- const to = path16.join(userIssuedRoot(cwd), lead);
11089
+ const to = path17.join(userIssuedRoot(cwd), lead);
10946
11090
  fs12.mkdirSync(to, { recursive: true, mode: 448 });
10947
11091
  for (const id of fs12.readdirSync(from)) {
10948
11092
  try {
10949
- fs12.copyFileSync(path16.join(from, id), path16.join(to, id), fs12.constants.COPYFILE_EXCL);
11093
+ fs12.copyFileSync(path17.join(from, id), path17.join(to, id), fs12.constants.COPYFILE_EXCL);
10950
11094
  } catch (error) {
10951
11095
  if (error.code !== "EEXIST")
10952
11096
  throw error;
10953
11097
  }
10954
- fs12.rmSync(path16.join(from, id), { force: true });
11098
+ fs12.rmSync(path17.join(from, id), { force: true });
10955
11099
  }
10956
11100
  removeIfEmpty(from);
10957
11101
  } catch {}
@@ -10970,7 +11114,7 @@ var removeIfEmpty = (dir) => {
10970
11114
  fs12.rmdirSync(dir);
10971
11115
  } catch {}
10972
11116
  };
10973
- var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
11117
+ var tokenHash = (token) => createHash9("sha256").update(token).digest("hex");
10974
11118
  function recordIssuedSession(cwd, lead, issued) {
10975
11119
  const token = randomBytes2(18).toString("hex");
10976
11120
  try {
@@ -10978,13 +11122,13 @@ function recordIssuedSession(cwd, lead, issued) {
10978
11122
  migrateRepoIssued(cwd);
10979
11123
  const own = hash(issued);
10980
11124
  const state = resolveStateDir();
10981
- const tokens = path16.join(state, "issued-tokens", hash(lead));
11125
+ const tokens = path17.join(state, "issued-tokens", hash(lead));
10982
11126
  fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
10983
- fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
11127
+ fs12.writeFileSync(path17.join(tokens, own), `${tokenHash(token)}
10984
11128
  `, { mode: 384, flag: "wx" });
10985
- const dir = path16.join(state, "issued", hash(lead));
11129
+ const dir = path17.join(state, "issued", hash(lead));
10986
11130
  fs12.mkdirSync(dir, { recursive: true, mode: 448 });
10987
- fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
11131
+ fs12.writeFileSync(path17.join(dir, own), `${ISSUED_SESSIONS_MARKER}
10988
11132
  `, { mode: 384 });
10989
11133
  pruneIssued(dir, own, tokens);
10990
11134
  return token;
@@ -11014,10 +11158,10 @@ function pruneIssued(dir, own, tokens) {
11014
11158
  const entries = fs12.readdirSync(dir);
11015
11159
  if (entries.length <= ISSUED_PER_LEAD)
11016
11160
  return;
11017
- const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs12.statSync(path16.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
11161
+ const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs12.statSync(path17.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
11018
11162
  for (const { name } of byAge.slice(0, entries.length - ISSUED_PER_LEAD)) {
11019
- fs12.rmSync(path16.join(dir, name), { force: true });
11020
- fs12.rmSync(path16.join(tokens, name), { force: true });
11163
+ fs12.rmSync(path17.join(dir, name), { force: true });
11164
+ fs12.rmSync(path17.join(tokens, name), { force: true });
11021
11165
  }
11022
11166
  } catch {}
11023
11167
  }
@@ -11027,7 +11171,7 @@ var issuedRecord = (cwd, claimed) => {
11027
11171
  return null;
11028
11172
  migrateRepoIssued(cwd);
11029
11173
  try {
11030
- return fs12.readFileSync(path16.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
11174
+ return fs12.readFileSync(path17.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
11031
11175
  } catch {
11032
11176
  return null;
11033
11177
  }
@@ -11037,9 +11181,9 @@ var issuedToken = (cwd, claimed) => {
11037
11181
  const cut = claimed.lastIndexOf(":");
11038
11182
  if (cut <= 0)
11039
11183
  return { stored: null, leadBound: false };
11040
- const dir = path16.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
11184
+ const dir = path17.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
11041
11185
  try {
11042
- const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
11186
+ const text = fs12.readFileSync(path17.join(dir, hash(claimed)), "utf8");
11043
11187
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
11044
11188
  } catch {
11045
11189
  return { stored: null, leadBound: safeList(dir).length > 0 };
@@ -11133,7 +11277,7 @@ var binaryRangeDiff = (cwd, base, head) => {
11133
11277
  return diff.ok && diff.stdout ? diff.stdout : null;
11134
11278
  };
11135
11279
  var hashOfDiff = (diff) => {
11136
- const hash = createHash9("sha256");
11280
+ const hash = createHash10("sha256");
11137
11281
  for (const line of diff.split(`
11138
11282
  `)) {
11139
11283
  if (line.startsWith("index "))
@@ -11166,14 +11310,14 @@ function cleanRebase(cwd, range) {
11166
11310
  return Boolean(tree) && tree === git3(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
11167
11311
  }
11168
11312
  function storeRoot(cwd) {
11169
- const location = resolveStore(path17.resolve(cwd));
11313
+ const location = resolveStore(path18.resolve(cwd));
11170
11314
  if (location instanceof Error)
11171
11315
  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");
11172
11316
  return { ok: true, value: { root: location.dir, shared: location.shared } };
11173
11317
  }
11174
11318
  function ledgerPath(cwd) {
11175
11319
  const root = storeRoot(cwd);
11176
- return root.ok ? { ok: true, value: path17.join(root.value.root, "ledger", "ledger.jsonl") } : root;
11320
+ return root.ok ? { ok: true, value: path18.join(root.value.root, "ledger", "ledger.jsonl") } : root;
11177
11321
  }
11178
11322
  var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
11179
11323
  var NETWORK_FS_TYPES = new Set([
@@ -11203,13 +11347,13 @@ var LOCK_STALE_MS2 = 30000;
11203
11347
  var LOCK_OWNER = "owner";
11204
11348
  var lockToken = (lock) => {
11205
11349
  try {
11206
- return fs13.readFileSync(path17.join(lock, LOCK_OWNER), "utf8");
11350
+ return fs13.readFileSync(path18.join(lock, LOCK_OWNER), "utf8");
11207
11351
  } catch {
11208
11352
  return null;
11209
11353
  }
11210
11354
  };
11211
11355
  var lockAgeMs = (lock) => {
11212
- for (const target of [path17.join(lock, LOCK_OWNER), lock]) {
11356
+ for (const target of [path18.join(lock, LOCK_OWNER), lock]) {
11213
11357
  try {
11214
11358
  return Date.now() - fs13.statSync(target).mtimeMs;
11215
11359
  } catch {}
@@ -11226,7 +11370,7 @@ var ledgerLock = {
11226
11370
  throw error;
11227
11371
  }
11228
11372
  const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
11229
- fs13.writeFileSync(path17.join(lock, LOCK_OWNER), token);
11373
+ fs13.writeFileSync(path18.join(lock, LOCK_OWNER), token);
11230
11374
  return token;
11231
11375
  },
11232
11376
  release(lock, token) {
@@ -11289,7 +11433,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2))
11289
11433
  ledgerLock.release(lock, token);
11290
11434
  }
11291
11435
  }
11292
- var sha2562 = (text) => createHash9("sha256").update(text).digest("hex");
11436
+ var sha2562 = (text) => createHash10("sha256").update(text).digest("hex");
11293
11437
  var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
11294
11438
  ${body}`);
11295
11439
  var TAIL_BYTES = 64 * 1024;
@@ -11351,8 +11495,8 @@ ${line.value}`);
11351
11495
  }
11352
11496
  };
11353
11497
  try {
11354
- fs13.mkdirSync(path17.dirname(file), { recursive: true });
11355
- if (options.heldLock || !options.forceLock && !onNetworkFs(path17.dirname(file)))
11498
+ fs13.mkdirSync(path18.dirname(file), { recursive: true });
11499
+ if (options.heldLock || !options.forceLock && !onNetworkFs(path18.dirname(file)))
11356
11500
  return write();
11357
11501
  const locked = withLedgerLock(file, write);
11358
11502
  return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
@@ -11369,7 +11513,7 @@ var sealed = (row, id, at, previous) => {
11369
11513
  ` };
11370
11514
  };
11371
11515
  function appendRaw(cwd, row, options) {
11372
- const file = options.store ? { ok: true, value: path17.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
11516
+ const file = options.store ? { ok: true, value: path18.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
11373
11517
  if (!file.ok)
11374
11518
  return file;
11375
11519
  const id = newId2();
@@ -12025,7 +12169,7 @@ function remoteIdentity(cwd, hop = 0) {
12025
12169
  return null;
12026
12170
  if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
12027
12171
  const local = raw.replace(/^file:\/\//u, "");
12028
- const resolved = path17.isAbsolute(local) ? local : path17.resolve(cwd, local);
12172
+ const resolved = path18.isAbsolute(local) ? local : path18.resolve(cwd, local);
12029
12173
  if (fs13.existsSync(resolved))
12030
12174
  return remoteIdentity(resolved, 1);
12031
12175
  }
@@ -12046,8 +12190,8 @@ function verdictMirrorPath(cwd) {
12046
12190
  }
12047
12191
  if (!identity)
12048
12192
  return null;
12049
- const key = createHash9("sha256").update(identity).digest("hex").slice(0, 32);
12050
- return path17.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
12193
+ const key = createHash10("sha256").update(identity).digest("hex").slice(0, 32);
12194
+ return path18.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
12051
12195
  }
12052
12196
  var importedStamp = new Map;
12053
12197
  function importMirroredVerdicts(cwd, branch) {
@@ -12070,7 +12214,7 @@ function importMirroredVerdicts(cwd, branch) {
12070
12214
  const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
12071
12215
  const added = new Set;
12072
12216
  try {
12073
- fs13.mkdirSync(path17.dirname(local.value), { recursive: true });
12217
+ fs13.mkdirSync(path18.dirname(local.value), { recursive: true });
12074
12218
  } catch {
12075
12219
  return [];
12076
12220
  }
@@ -12186,7 +12330,7 @@ var productDecision = (task, ledger) => {
12186
12330
  };
12187
12331
  };
12188
12332
  var planRecorded = (task, root) => {
12189
- const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(path18.resolve(root, ref.path)));
12333
+ const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(path19.resolve(root, ref.path)));
12190
12334
  if (cited)
12191
12335
  return {
12192
12336
  met: true,
@@ -12263,15 +12407,15 @@ function writeBlockers(task, root) {
12263
12407
  }
12264
12408
 
12265
12409
  // packages/workit-core/src/core/task-evaluation.ts
12266
- var digestBytes = (value) => createHash10("sha256").update(value).digest("hex");
12267
- var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path19.sep}`);
12268
- var relative = (root, candidate) => path19.relative(root, candidate).split(path19.sep).join("/") || ".";
12410
+ var digestBytes = (value) => createHash11("sha256").update(value).digest("hex");
12411
+ var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path20.sep}`);
12412
+ var relative = (root, candidate) => path20.relative(root, candidate).split(path20.sep).join("/") || ".";
12269
12413
  var canonicalPath = (value) => {
12270
12414
  if (typeof value !== "string" || !value)
12271
12415
  return null;
12272
12416
  if (value.includes("\\") || value.split("/").includes(".."))
12273
12417
  return null;
12274
- const normalized = path19.posix.normalize(value);
12418
+ const normalized = path20.posix.normalize(value);
12275
12419
  if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
12276
12420
  return null;
12277
12421
  return normalized === "." ? "." : normalized.replace(/\/$/, "");
@@ -12319,14 +12463,14 @@ var gitPaths = (root) => {
12319
12463
  git: !/not a git repository/i.test(stderr)
12320
12464
  };
12321
12465
  }
12322
- const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")) : [];
12466
+ const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path20.sep).join("/")) : [];
12323
12467
  const stagedDeleted = spawnSync12("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
12324
12468
  if (stagedDeleted.status !== 0) {
12325
12469
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
12326
12470
  if (!/not a git repository/i.test(stderr))
12327
12471
  return { paths, uncertain: true, git: true };
12328
12472
  } else if (stagedDeleted.stdout) {
12329
- paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")));
12473
+ paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path20.sep).join("/")));
12330
12474
  }
12331
12475
  return { paths: [...new Set(paths)], uncertain: false, git: true };
12332
12476
  };
@@ -12341,7 +12485,7 @@ var walk = (root, directory, output) => {
12341
12485
  for (const name of names) {
12342
12486
  if (name === ".git" || name === ".workit")
12343
12487
  continue;
12344
- const target = path19.join(directory, name);
12488
+ const target = path20.join(directory, name);
12345
12489
  let stat;
12346
12490
  try {
12347
12491
  stat = fs14.lstatSync(target);
@@ -12359,12 +12503,12 @@ var walk = (root, directory, output) => {
12359
12503
  var scopeRoots = (root, scope) => {
12360
12504
  const roots = [];
12361
12505
  for (const item of scope.paths.length ? scope.paths : ["."]) {
12362
- const target = path19.resolve(root, item);
12506
+ const target = path20.resolve(root, item);
12363
12507
  if (!inside(root, target))
12364
12508
  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` }] });
12365
12509
  let ancestor = target;
12366
12510
  while (!fs14.existsSync(ancestor) && ancestor !== root)
12367
- ancestor = path19.dirname(ancestor);
12511
+ ancestor = path20.dirname(ancestor);
12368
12512
  try {
12369
12513
  if (!inside(root, fs14.realpathSync(ancestor)))
12370
12514
  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` }] });
@@ -12416,7 +12560,7 @@ function captureCandidate(root, scope, environment = []) {
12416
12560
  for (const item of [...names].toSorted()) {
12417
12561
  if (!scopeMatches(item, normalizedScope))
12418
12562
  continue;
12419
- const target = path19.join(checkout, item);
12563
+ const target = path20.join(checkout, item);
12420
12564
  try {
12421
12565
  const stat = fs14.lstatSync(target);
12422
12566
  if (stat.isSymbolicLink()) {
@@ -12585,23 +12729,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
12585
12729
  continue;
12586
12730
  if (!reference.digest)
12587
12731
  return failure2("invalid_input", "document references require a byte digest");
12588
- const target = path19.resolve(root, reference.path);
12589
- if (target !== root && !target.startsWith(`${root}${path19.sep}`))
12732
+ const target = path20.resolve(root, reference.path);
12733
+ if (target !== root && !target.startsWith(`${root}${path20.sep}`))
12590
12734
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
12591
12735
  fields: [
12592
12736
  { path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
12593
12737
  ]
12594
12738
  });
12595
12739
  try {
12596
- const below = path19.relative(root, target);
12740
+ const below = path20.relative(root, target);
12597
12741
  let current = root;
12598
- for (const segment of below.split(path19.sep)) {
12742
+ for (const segment of below.split(path20.sep)) {
12599
12743
  if (!segment)
12600
12744
  continue;
12601
- current = path19.join(current, segment);
12745
+ current = path20.join(current, segment);
12602
12746
  const stat = fs14.lstatSync(current);
12603
12747
  const real = fs14.realpathSync(current);
12604
- if (real !== root && !real.startsWith(`${root}${path19.sep}`))
12748
+ if (real !== root && !real.startsWith(`${root}${path20.sep}`))
12605
12749
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
12606
12750
  fields: [
12607
12751
  {
@@ -13099,7 +13243,7 @@ function entryCompactContext(store, entry, session, context) {
13099
13243
  current: () => recentSignal(store.root)
13100
13244
  };
13101
13245
  const observed = task?.data.evidence.some(isObservedCheck) ?? false;
13102
- const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path20.resolve(store.root, ref.path)] : []));
13246
+ const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path21.resolve(store.root, ref.path)] : []));
13103
13247
  const observedFiles = filesKey(files);
13104
13248
  const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
13105
13249
  if (!compact.ok || !compact.data)
@@ -13158,17 +13302,17 @@ ${options.addendum}` : ""}
13158
13302
  </workit-contract>`;
13159
13303
  };
13160
13304
  var checkoutAt = (cwd) => {
13161
- for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
13162
- const dotGit = path20.join(dir, ".git");
13305
+ for (let dir = path21.resolve(cwd);; dir = path21.dirname(dir)) {
13306
+ const dotGit = path21.join(dir, ".git");
13163
13307
  if (fs15.existsSync(dotGit)) {
13164
- const admin = fs15.statSync(dotGit).isFile() ? path20.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs15.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
13165
- const head = fs15.readFileSync(path20.join(admin, "HEAD"), "utf8").trim();
13308
+ const admin = fs15.statSync(dotGit).isFile() ? path21.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs15.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
13309
+ const head = fs15.readFileSync(path21.join(admin, "HEAD"), "utf8").trim();
13166
13310
  return {
13167
13311
  root: dir,
13168
13312
  branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
13169
13313
  };
13170
13314
  }
13171
- if (path20.dirname(dir) === dir)
13315
+ if (path21.dirname(dir) === dir)
13172
13316
  return null;
13173
13317
  }
13174
13318
  };
@@ -13179,7 +13323,7 @@ var whereLine = (cwd) => {
13179
13323
  return null;
13180
13324
  const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
13181
13325
  const kinds = allowed.some((pattern) => pattern.source === "^.*$") ? "any" : allowedKinds(allowed).join(", ") || "see `workit help git`";
13182
- const place = checkout.root === path20.resolve(cwd) ? "" : ` in ${checkout.root}`;
13326
+ const place = checkout.root === path21.resolve(cwd) ? "" : ` in ${checkout.root}`;
13183
13327
  return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
13184
13328
  } catch {
13185
13329
  return null;
@@ -13197,7 +13341,7 @@ var turnContextText = (input, descriptor) => {
13197
13341
  }
13198
13342
  };
13199
13343
  var TURN_TTL_MS = 7 * 24 * 60 * 60 * 1000;
13200
- var digestOf = (text) => createHash11("sha256").update(text).digest("hex");
13344
+ var digestOf = (text) => createHash12("sha256").update(text).digest("hex");
13201
13345
  var turnMarker = (input) => {
13202
13346
  if (!input.session.id)
13203
13347
  return null;
@@ -13206,14 +13350,14 @@ var turnMarker = (input) => {
13206
13350
  if (location instanceof Error)
13207
13351
  return null;
13208
13352
  const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
13209
- return path20.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
13353
+ return path21.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
13210
13354
  } catch {
13211
13355
  return null;
13212
13356
  }
13213
13357
  };
13214
13358
  var writeTurnDigest = (file, digest) => {
13215
13359
  try {
13216
- fs15.mkdirSync(path20.dirname(file), { recursive: true });
13360
+ fs15.mkdirSync(path21.dirname(file), { recursive: true });
13217
13361
  fs15.writeFileSync(file, `${JSON.stringify({ digest })}
13218
13362
  `);
13219
13363
  } catch {}
@@ -13228,7 +13372,7 @@ var pruneTurnDigests = (dir, now) => {
13228
13372
  for (const name of fs15.readdirSync(dir)) {
13229
13373
  if (!name.startsWith("turn-"))
13230
13374
  continue;
13231
- const file = path20.join(dir, name);
13375
+ const file = path21.join(dir, name);
13232
13376
  try {
13233
13377
  if (now - fs15.statSync(file).mtimeMs > TURN_TTL_MS)
13234
13378
  fs15.rmSync(file, { force: true });
@@ -13258,7 +13402,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
13258
13402
  const file = turnMarker(input);
13259
13403
  if (!file)
13260
13404
  return;
13261
- pruneTurnDigests(path20.dirname(file), Date.now());
13405
+ pruneTurnDigests(path21.dirname(file), Date.now());
13262
13406
  if (text)
13263
13407
  writeTurnDigest(file, digestOf(text));
13264
13408
  else
@@ -13283,20 +13427,20 @@ import path23 from "node:path";
13283
13427
  // packages/workit-core/src/core/eval-world.ts
13284
13428
  import { existsSync as existsSync9, realpathSync as realpathSync7 } from "node:fs";
13285
13429
  import os5 from "node:os";
13286
- import path21 from "node:path";
13430
+ import path22 from "node:path";
13287
13431
  var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
13288
13432
  var EVAL_WORLD_MARKER = ".workit-eval-world";
13289
13433
  var inside2 = (dir, file) => {
13290
- const rel = path21.relative(dir, file);
13291
- return !rel.startsWith("..") && !path21.isAbsolute(rel);
13434
+ const rel = path22.relative(dir, file);
13435
+ return !rel.startsWith("..") && !path22.isAbsolute(rel);
13292
13436
  };
13293
13437
  var evalWorld = (cwd) => {
13294
13438
  const raw = process.env[EVAL_WORLD_ENV];
13295
- if (!raw || !path21.isAbsolute(raw))
13439
+ if (!raw || !path22.isAbsolute(raw))
13296
13440
  return null;
13297
13441
  try {
13298
13442
  const world = realpathSync7(raw);
13299
- return inside2(realpathSync7(os5.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync9(path21.join(world, EVAL_WORLD_MARKER)) ? world : null;
13443
+ return inside2(realpathSync7(os5.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync9(path22.join(world, EVAL_WORLD_MARKER)) ? world : null;
13300
13444
  } catch {
13301
13445
  return null;
13302
13446
  }
@@ -13304,77 +13448,12 @@ var evalWorld = (cwd) => {
13304
13448
  var evalWorldEntry = (cwd) => {
13305
13449
  const world = evalWorld(cwd);
13306
13450
  try {
13307
- return world ? loadWorkspacesFrom(path21.join(world, "config"))[0] ?? null : null;
13451
+ return world ? loadWorkspacesFrom(path22.join(world, "config"))[0] ?? null : null;
13308
13452
  } catch {
13309
13453
  return null;
13310
13454
  }
13311
13455
  };
13312
13456
 
13313
- // packages/workit-core/src/core/grant-seal.ts
13314
- import { createHash as createHash12 } from "node:crypto";
13315
- import { readFileSync as readFileSync9 } from "node:fs";
13316
- import path22 from "node:path";
13317
- var SEAL_FILE = "workspaces.json.seal";
13318
- var SEAL_VERSION = 1;
13319
- var SEAL_COMMAND = "workit workspace seal";
13320
- var pick3 = (value, keys) => {
13321
- if (!value || typeof value !== "object" || Array.isArray(value))
13322
- return;
13323
- const out = Object.fromEntries(keys.flatMap((key) => {
13324
- const item = value[key];
13325
- return item === undefined ? [] : [[key, item]];
13326
- }));
13327
- return Object.keys(out).length > 0 ? out : undefined;
13328
- };
13329
- var ENTRY_KEYS = [
13330
- "name",
13331
- "glob",
13332
- "remotes",
13333
- "externalRepos",
13334
- "additiveRiskPaths",
13335
- "vcs",
13336
- "autonomy",
13337
- "autoApprove",
13338
- "defaultEndpoint",
13339
- "verification",
13340
- "youtrack"
13341
- ];
13342
- var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
13343
- var sealProjection = (entries) => entries.map((entry) => {
13344
- const all = pick3(entry, ENTRY_KEYS) ?? {};
13345
- return pick3({
13346
- ...all,
13347
- vcs: pick3(all.vcs, IDENTITY_KEYS),
13348
- youtrack: pick3(all.youtrack, ["writes", "autoHosts"])
13349
- }, ENTRY_KEYS);
13350
- });
13351
- 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);
13352
- var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
13353
- var broken = (reason, sealed = null) => ({
13354
- state: "broken",
13355
- reason,
13356
- sealed
13357
- });
13358
- function checkSeal(dir) {
13359
- const file = path22.join(dir, SEAL_FILE);
13360
- let seal;
13361
- try {
13362
- seal = JSON.parse(readFileSync9(file, "utf8"));
13363
- } catch (error) {
13364
- if (error.code === "ENOENT")
13365
- return { state: "none" };
13366
- return broken(`${SEAL_FILE} cannot be read`);
13367
- }
13368
- if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
13369
- return broken(`${SEAL_FILE} is malformed`);
13370
- const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
13371
- if (sealed.status !== "valid")
13372
- return broken(`${SEAL_FILE} is malformed`);
13373
- const current = readWorkspacesResult(dir);
13374
- const ok = current.status === "valid" || current.status === "missing";
13375
- return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
13376
- }
13377
-
13378
13457
  // packages/workit-core/src/forge/redact.ts
13379
13458
  var NAME = "[A-Za-z0-9_.-]";
13380
13459
  var KEY = String.raw`(?<!${NAME})(?=${NAME}*?(?:token|secret|password|passwd|pwd|api[_-]?key|access[_-]?key|account[_-]?key|private[_-]?key|client[_-]?secret|credentials?|authorization|cookie|signature))${NAME}+`;
@@ -13455,7 +13534,7 @@ var sealOf = () => {
13455
13534
  var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
13456
13535
  var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
13457
13536
  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}`;
13458
- 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;
13537
+ 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;
13459
13538
  var ASK = { mode: "ask" };
13460
13539
  var youtrackOf = (entry) => entry?.youtrack;
13461
13540
  var autoHostsOf = (entry) => {
@@ -13871,7 +13950,14 @@ var SCOPE_FIELDS = new Set([
13871
13950
  "autoApprove",
13872
13951
  "defaultEndpoint",
13873
13952
  "verification",
13874
- "youtrack"
13953
+ "youtrack",
13954
+ "releaseNotes",
13955
+ "releaseTagPrefix",
13956
+ "branchPolicy",
13957
+ "profiles",
13958
+ "defaultProfile",
13959
+ "releaseTracks",
13960
+ "releasePackages"
13875
13961
  ]);
13876
13962
 
13877
13963
  // packages/workit-core/src/core/release-packages.ts
@@ -15050,7 +15136,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
15050
15136
  for (const invocation of inside)
15051
15137
  found.push({ ...invocation, dir: rebase(dir, invocation.dir) });
15052
15138
  };
15053
- const visit = (input, stdin, hops) => {
15139
+ const visit = (input, stdin, hops, expands = "all") => {
15054
15140
  const line = /^\$[\w:]+$/.test(input[0] ?? "") && input[1] === "=" ? input.slice(2) : input;
15055
15141
  const split = splitString(line);
15056
15142
  if (split !== null)
@@ -15112,15 +15198,18 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
15112
15198
  nested(cmdScript(words), "powershell");
15113
15199
  else if (name === "xargs" || name === "find")
15114
15200
  runs(name === "xargs" ? xargsCommands(words, stdin) : findCommands(words));
15115
- else if (name === "gh" || name === "glab")
15201
+ else if (name === "gh" || name === "glab") {
15202
+ const shift = input.length - words.length + 1;
15203
+ const expanded = expands === "all" ? expands : expands.filter((at) => at >= shift).map((at) => at - shift);
15116
15204
  found.push({
15117
15205
  tool: name,
15118
15206
  dir,
15119
15207
  args: words.slice(1),
15120
15208
  ...Object.keys({ ...exported, ...env }).length ? { env: { ...exported, ...env } } : {},
15121
- ...stdin === undefined ? {} : { stdin }
15209
+ ...stdin === undefined ? {} : { stdin },
15210
+ ...expanded.length ? { expanded } : {}
15122
15211
  });
15123
- else if (name === "git") {
15212
+ } else if (name === "git") {
15124
15213
  const invocation = gitInvocation(words.slice(1), dir, { ...exported, ...env }, stdin, sessionConfig);
15125
15214
  found.push(invocation);
15126
15215
  sessionConfig.push(...configSetBy(invocation.args));
@@ -15153,7 +15242,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
15153
15242
  }
15154
15243
  const stdin = stdinOf(segment, segments[index - 1]);
15155
15244
  for (const line of substitute(segment.words, vars))
15156
- visit(line, stdin, 0);
15245
+ visit(line, stdin, 0, segment.expands ?? []);
15157
15246
  }
15158
15247
  return found;
15159
15248
  }
@@ -15448,55 +15537,232 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
15448
15537
  var API_SHORT_VALUES = "XHfFqtp";
15449
15538
  var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
15450
15539
  var API_MERGE = {
15451
- gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?(?:[?#]|$)/i,
15452
- glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?(?:[?#]|$)/i
15540
+ gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?$/i,
15541
+ glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?$/i
15453
15542
  };
15454
15543
  var GRAPHQL_MERGE = /\b(?:mergePullRequest|enablePullRequestAutoMerge|mergeBranch|mergeRequestAccept)\b/;
15455
- var apiAction = (tool, args, stdin) => {
15456
- const request = { method: null, body: false };
15544
+ var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
15545
+ var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
15546
+ var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
15547
+ var GRAPHQL_REF = [
15548
+ [called("createRef|updateRefs?|deleteRef"), "ref"],
15549
+ [
15550
+ called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
15551
+ "branch"
15552
+ ],
15553
+ [called("tagCreate|tagDelete"), "tag"]
15554
+ ];
15555
+ var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
15556
+ var API_REF = {
15557
+ gh: [
15558
+ [ghPath(String.raw`git\/refs?`), "ref"],
15559
+ [ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
15560
+ ],
15561
+ glab: [
15562
+ [/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
15563
+ [/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
15564
+ [/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
15565
+ ]
15566
+ };
15567
+ var API_SETTING = {
15568
+ gh: [
15569
+ ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
15570
+ ghPath("rulesets"),
15571
+ ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
15572
+ /(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
15573
+ ],
15574
+ glab: [
15575
+ /(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
15576
+ /(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
15577
+ ]
15578
+ };
15579
+ var API_REPOSITORY = {
15580
+ gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
15581
+ glab: /(?:^|\/)projects\/[^/]+\/?$/i
15582
+ };
15583
+ var PLAIN_REF = /^refs\/(?:heads|tags)\/(?!.*\.\.)[^\s$`\\%]+$/;
15584
+ var BY_ID = called("updateRefs?|deleteRef");
15585
+ var createdRefs = (query) => {
15586
+ if (/[\\$]|"""/.test(query))
15587
+ return null;
15588
+ const tokens = query.match(/#[^\n\r]*|"[^"\n\r]*"|[_A-Za-z]\w*|[^\s,\uFEFF]/g) ?? [];
15589
+ const named = [];
15590
+ for (let at = 0;at < tokens.length; at++) {
15591
+ if (tokens[at] !== "createRef")
15592
+ continue;
15593
+ const args = tokens.slice(at + 1).filter((token) => !token.startsWith("#"));
15594
+ if (args[0] !== "(")
15595
+ continue;
15596
+ let depth = 0;
15597
+ const names = [];
15598
+ for (let index = 0;index < args.length; index++) {
15599
+ const token = args[index];
15600
+ if (token === "(" || token === "{" || token === "[")
15601
+ depth++;
15602
+ else if (token === ")" || token === "}" || token === "]") {
15603
+ if (--depth === 0)
15604
+ break;
15605
+ } else if (token === "name" && args[index + 1] === ":")
15606
+ names.push(args[index + 2] ?? "");
15607
+ }
15608
+ if (depth !== 0 || names.length !== 1 || !names[0].startsWith('"'))
15609
+ return null;
15610
+ named.push(names[0].slice(1, -1));
15611
+ }
15612
+ return named;
15613
+ };
15614
+ var provablyRead = (query) => /^[\s,\uFEFF]*(?:\{|query[\s,\uFEFF]*[({])/.test(query) && !/\b(?:mutation|subscription)\b/.test(query);
15615
+ var refWrite = (forge, shapes, named, certain) => {
15616
+ const sure = certain && named.length > 0 && named.every((ref) => PLAIN_REF.test(ref));
15617
+ const tags = !sure || named.some((ref) => ref.startsWith("refs/tags/"));
15618
+ const heads = !sure || named.some((ref) => ref.startsWith("refs/heads/"));
15619
+ const ref = shapes.has("ref");
15620
+ return {
15621
+ kind: "ref-write",
15622
+ forge,
15623
+ tag: shapes.has("tag") || ref && tags,
15624
+ branch: shapes.has("branch") || ref && heads,
15625
+ ...ref && sure ? { ref: named[0] } : {}
15626
+ };
15627
+ };
15628
+ var restRef = (route, fields, readable) => {
15629
+ const inPath = /\/git\/refs?\/(.+)$/i.exec(route)?.[1];
15630
+ if (inPath)
15631
+ return { named: [`refs/${inPath}`], certain: true };
15632
+ const refs = fields.filter((field) => field.startsWith("ref=")).map((field) => field.slice(4));
15633
+ const mentions = fields.filter((field) => /refs\//.test(field)).length;
15634
+ return { named: refs, certain: readable && refs.length === 1 && mentions === 1 };
15635
+ };
15636
+ var routeOf = (endpoint) => endpoint.replace(/(?<!:)\/{2,}/g, "/").replace(/[?#][\s\S]*$/, "").replace(/%([\da-f]{2})/gi, (escape, hex) => {
15637
+ const char = String.fromCodePoint(Number.parseInt(hex, 16));
15638
+ return /[\w.~-]/.test(char) ? char : escape;
15639
+ });
15640
+ var apiAction = (tool, args, stdin, expanded = []) => {
15641
+ const request = { method: null, body: false, input: false, unread: false };
15457
15642
  let endpoint = null;
15643
+ let endpointAt = -1;
15458
15644
  const values = [];
15459
- const take = (name, value) => {
15645
+ const fields = [];
15646
+ const queries = [];
15647
+ const field = (value, expands) => {
15648
+ fields.push(value);
15649
+ values.push(value);
15650
+ if (!value.startsWith("query="))
15651
+ return;
15652
+ const text = value.slice(6);
15653
+ const read = expanded !== "all" && (!(expands && /[$`]/.test(text)) || provablyRead(text));
15654
+ queries.push({ text, read });
15655
+ };
15656
+ const fromStdin = (name, value, text) => {
15657
+ if (name !== "--input") {
15658
+ if (text.includes("\\"))
15659
+ request.unread = true;
15660
+ return field(`${value.slice(0, value.indexOf("=") + 1)}${text}`, true);
15661
+ }
15662
+ values.push(text);
15663
+ let body;
15664
+ try {
15665
+ body = JSON.parse(text);
15666
+ } catch {
15667
+ request.unread = true;
15668
+ return;
15669
+ }
15670
+ const strings = (each) => typeof each === "string" ? [each] : each && typeof each === "object" ? Object.entries(each).flatMap(([key, inner]) => [key, ...strings(inner)]) : [];
15671
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
15672
+ values.push(...strings(body));
15673
+ return;
15674
+ }
15675
+ for (const [key, inner] of Object.entries(body)) {
15676
+ if (typeof inner === "string")
15677
+ field(`${key}=${inner}`, true);
15678
+ else
15679
+ values.push(key, ...strings(inner));
15680
+ }
15681
+ };
15682
+ const take = (name, value, at) => {
15683
+ const expands = expanded === "all" || expanded.includes(at);
15460
15684
  if (name === "-X" || name === "--method")
15461
15685
  request.method = value.toUpperCase();
15462
15686
  if (API_FIELDS.has(name) || name === "--input")
15463
15687
  request.body = true;
15464
- values.push(value);
15465
- const fromStdin = name === "--input" ? value === "-" : /^(?:[^=]*=)?@-$/.test(value);
15466
- if (fromStdin && stdin !== undefined)
15467
- values.push(stdin);
15688
+ if (name === "--input")
15689
+ request.input = true;
15690
+ const piped = name === "--input" ? value === "-" : /^(?:-F|--field)$/.test(name) && /^[^=]*=@-$/.test(value);
15691
+ if (piped && stdin !== undefined) {
15692
+ values.push(value);
15693
+ return fromStdin(name, value, stdin);
15694
+ }
15695
+ if (API_FIELDS.has(name))
15696
+ field(value, expands);
15697
+ else
15698
+ values.push(value);
15699
+ const file = name === "--input" || /^(?:-F|--field)$/.test(name) && /^[^=]*=@/.test(value);
15700
+ if (file)
15701
+ request.unread = true;
15468
15702
  };
15469
15703
  for (let index = 1;index < args.length; index++) {
15470
15704
  const arg = args[index];
15471
15705
  if (arg === "--") {
15472
- endpoint ??= args[index + 1] ?? null;
15706
+ if (endpoint === null)
15707
+ [endpoint, endpointAt] = [args[index + 1] ?? null, index + 1];
15473
15708
  break;
15474
15709
  }
15475
15710
  if (arg.startsWith("--")) {
15476
15711
  const eq = arg.indexOf("=");
15477
15712
  const name = eq > 0 ? arg.slice(0, eq) : arg;
15478
15713
  if (API_VALUES.has(name))
15479
- take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "");
15714
+ take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "", index);
15480
15715
  } else if (arg.startsWith("-") && arg.length > 1) {
15481
15716
  for (let at = 1;at < arg.length; at++) {
15482
15717
  if (!API_SHORT_VALUES.includes(arg[at]))
15483
15718
  continue;
15484
- take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "");
15719
+ take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "", index);
15485
15720
  break;
15486
15721
  }
15487
- } else
15488
- endpoint ??= arg;
15722
+ } else if (endpoint === null)
15723
+ [endpoint, endpointAt] = [arg, index];
15489
15724
  }
15490
15725
  if (!endpoint)
15491
15726
  return null;
15492
- endpoint = endpoint.replace(/(?<!:)\/{2,}/g, "/");
15727
+ const atEndpoint = expanded === "all" || expanded.includes(endpointAt);
15728
+ for (const pair of /[?]([^#]*)/.exec(endpoint)?.[1].split("&") ?? []) {
15729
+ let decoded = pair;
15730
+ try {
15731
+ decoded = decodeURIComponent(pair.replaceAll("+", " "));
15732
+ } catch {
15733
+ request.unread = true;
15734
+ }
15735
+ field(decoded, atEndpoint);
15736
+ if (/refs\//i.test(decoded))
15737
+ request.input = true;
15738
+ }
15739
+ const route = routeOf(endpoint);
15493
15740
  const merge = { kind: "merge", forge: tool, via: "api" };
15494
- if (/(?:^|\/)graphql\/?$/i.test(endpoint))
15495
- return values.some((value) => GRAPHQL_MERGE.test(value)) ? merge : null;
15741
+ const setting = {
15742
+ kind: "ref-write",
15743
+ forge: tool,
15744
+ tag: false,
15745
+ branch: true,
15746
+ setting: true
15747
+ };
15748
+ if (/(?:^|\/)graphql\/?$/i.test(route)) {
15749
+ if (request.unread || queries.some((query) => !query.read))
15750
+ return { kind: "ref-write", forge: tool, tag: true, branch: true, unread: true };
15751
+ if (values.some((value) => GRAPHQL_MERGE.test(value)))
15752
+ return merge;
15753
+ if (values.some((value) => GRAPHQL_SETTING.test(value)))
15754
+ return setting;
15755
+ const shapes = new Set(GRAPHQL_REF.filter(([pattern]) => values.some((value) => pattern.test(value))).map(([, shape]) => shape));
15756
+ if (!shapes.size)
15757
+ return null;
15758
+ const created = queries.map((query) => createdRefs(query.text));
15759
+ const certain = !values.some((value) => BY_ID.test(value)) && created.every((named) => named !== null);
15760
+ return refWrite(tool, shapes, created.flatMap((named) => named ?? []), certain);
15761
+ }
15496
15762
  const verb = request.method ?? (request.body ? "POST" : "GET");
15497
15763
  if (verb === "GET" || verb === "HEAD")
15498
15764
  return null;
15499
- const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)\//i.exec(endpoint)?.[1] : /(?:^|\/)projects\/([^/]+)\//i.exec(endpoint)?.[1];
15765
+ const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)(?:\/|$)/i.exec(route)?.[1] ?? (/(?:^|\/)repositories\/[^/]+(?:\/|$)/i.test(route) ? "?" : undefined) : /(?:^|\/)projects\/([^/]+)(?:\/|$)/i.exec(route)?.[1];
15500
15766
  let repo;
15501
15767
  try {
15502
15768
  repo = named === undefined ? undefined : decodeURIComponent(named) || "?";
@@ -15504,9 +15770,17 @@ var apiAction = (tool, args, stdin) => {
15504
15770
  repo = "?";
15505
15771
  }
15506
15772
  const at = repo === undefined ? {} : { repo };
15507
- if (API_MERGE[tool].test(endpoint))
15773
+ if (API_MERGE[tool].test(route))
15508
15774
  return { ...merge, ...at };
15509
- const grant = /\/releases(?:\/|$|\?)/i.test(endpoint) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?(?:\?|$)/i : /\/merge_requests(?:\/\d+)?\/?(?:\?|$)/i).test(endpoint) ? "pr" : null;
15775
+ const defaultBranch = API_REPOSITORY[tool].test(route) && (request.unread || values.some((value) => /default_branch/.test(value)));
15776
+ if (defaultBranch || API_SETTING[tool].some((pattern) => pattern.test(route)))
15777
+ return { ...setting, ...at };
15778
+ const shape = API_REF[tool].find(([pattern]) => pattern.test(route))?.[1];
15779
+ if (shape) {
15780
+ const { named: refs, certain } = restRef(route, fields, !request.unread && !request.input);
15781
+ return { ...refWrite(tool, new Set([shape]), refs, certain), ...at };
15782
+ }
15783
+ const grant = /\/releases(?:\/|$)/i.test(route) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?$/i : /\/merge_requests(?:\/\d+)?\/?$/i).test(route) ? "pr" : null;
15510
15784
  return grant ? { kind: "forge", forge: tool, grant, ...at } : null;
15511
15785
  };
15512
15786
  var subtreePush = (args) => {
@@ -15524,7 +15798,7 @@ var subtreePush = (args) => {
15524
15798
  function rawAction(invocation) {
15525
15799
  const args = invocation.args;
15526
15800
  if (invocation.tool !== "git" && args[0] === "api")
15527
- return apiAction(invocation.tool, args, invocation.stdin);
15801
+ return apiAction(invocation.tool, args, invocation.stdin, invocation.expanded);
15528
15802
  if (asksHelp(invocation))
15529
15803
  return null;
15530
15804
  const [first] = args;
@@ -15800,6 +16074,223 @@ var refusal = (action, branch, dir) => {
15800
16074
  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")}.`;
15801
16075
  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")}.`;
15802
16076
  };
16077
+ var PLAIN_EXPANSION = /^(?:[^$`]|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})*$/u;
16078
+ var shellWord = (text, expands = false) => {
16079
+ if (/^[\w@%+=:,./-]+$/u.test(text))
16080
+ return text;
16081
+ if (expands && text.includes("$") && PLAIN_EXPANSION.test(text))
16082
+ return `"${text.replaceAll(/["\\]/gu, "\\$&")}"`;
16083
+ return `'${text.replaceAll("'", "'\\''")}'`;
16084
+ };
16085
+ var expandingWords = (command, dialect, found = new Set, depth = 0) => {
16086
+ for (const segment of segmentsOf(command, dialect))
16087
+ segment.words.forEach((text, index) => {
16088
+ if (segment.expands?.includes(index))
16089
+ found.add(text);
16090
+ else if (depth < MAX_DEPTH && /\s/u.test(text))
16091
+ expandingWords(text, "posix", found, depth + 1);
16092
+ });
16093
+ return found;
16094
+ };
16095
+ var wordsOf = (command, dialect = "posix") => {
16096
+ const expands = expandsIn(command, dialect);
16097
+ return (text) => shellWord(text, expands(text));
16098
+ };
16099
+ var expandsIn = (command, dialect = "posix") => {
16100
+ let expanding;
16101
+ return (text) => (expanding ??= expandingWords(command, dialect)).has(text);
16102
+ };
16103
+ var oneCall = (command, dialect) => {
16104
+ const steps = /^(?:\s*cd\s+[^\s;&|<>()$`'"\\]+\s*&&)*([\s\S]*)$/u.exec(command);
16105
+ return !!steps && !!simpleCommand(steps[1], dialect);
16106
+ };
16107
+ var flagWord = (flag, value, asWritten) => value.startsWith("-") ? [`${flag}=${asWritten(value)}`] : [flag, asWritten(value)];
16108
+ var PR_FLAGS = {
16109
+ "gh ready": { verb: "ready", booleans: { "--undo": ["--undo"] }, values: {} },
16110
+ "gh merge": {
16111
+ verb: "merge",
16112
+ booleans: {
16113
+ "--squash": ["--squash"],
16114
+ "-s": ["--squash"],
16115
+ "--merge": ["--merge"],
16116
+ "-m": ["--merge"],
16117
+ "--rebase": ["--rebase"],
16118
+ "-r": ["--rebase"],
16119
+ "--delete-branch": ["--delete-branch"],
16120
+ "-d": ["--delete-branch"]
16121
+ },
16122
+ values: {
16123
+ "--subject": { flag: "--subject" },
16124
+ "-t": { flag: "--subject" },
16125
+ "--body": { flag: "--body" },
16126
+ "-b": { flag: "--body" },
16127
+ "--body-file": { flag: "--body-file" },
16128
+ "-F": { flag: "--body-file" }
16129
+ }
16130
+ },
16131
+ "gh edit": {
16132
+ verb: "edit",
16133
+ booleans: {},
16134
+ values: {
16135
+ "--title": { flag: "--title" },
16136
+ "-t": { flag: "--title" },
16137
+ "--body-file": { flag: "--body-file" },
16138
+ "-F": { flag: "--body-file" },
16139
+ "--add-label": { flag: "--add-label", split: true },
16140
+ "--remove-label": { flag: "--remove-label", split: true },
16141
+ "--add-reviewer": { flag: "--add-reviewer", split: true },
16142
+ "--base": { flag: "--base" },
16143
+ "-B": { flag: "--base" }
16144
+ }
16145
+ },
16146
+ "glab merge": {
16147
+ verb: "merge",
16148
+ booleans: {
16149
+ "--squash": ["--squash"],
16150
+ "-s": ["--squash"],
16151
+ "--rebase": ["--rebase"],
16152
+ "-r": ["--rebase"],
16153
+ "--remove-source-branch": ["--delete-branch"],
16154
+ "-d": ["--delete-branch"],
16155
+ "--yes": [],
16156
+ "-y": []
16157
+ },
16158
+ values: {}
16159
+ },
16160
+ "glab update": {
16161
+ verb: "edit",
16162
+ booleans: { "--ready": [], "-r": [], "--draft": ["--undo"], "--yes": [], "-y": [] },
16163
+ values: {
16164
+ "--title": { flag: "--title" },
16165
+ "-t": { flag: "--title" },
16166
+ "--label": { flag: "--add-label", split: true },
16167
+ "-l": { flag: "--add-label", split: true },
16168
+ "--unlabel": { flag: "--remove-label", split: true },
16169
+ "-u": { flag: "--remove-label", split: true },
16170
+ "--target-branch": { flag: "--base" }
16171
+ }
16172
+ }
16173
+ };
16174
+ var prRetry = (cwd, repo, invocation, cache, asWritten) => {
16175
+ const forge = invocation.tool;
16176
+ if (forge === "git")
16177
+ return null;
16178
+ const values = VALUE_OPTIONS[forge];
16179
+ const args = invocation.args;
16180
+ let verb;
16181
+ let at = 1;
16182
+ for (;at < args.length; at++) {
16183
+ if (!args[at].startsWith("-")) {
16184
+ verb = args[at];
16185
+ break;
16186
+ }
16187
+ if (values.has(args[at]))
16188
+ at++;
16189
+ }
16190
+ const table = PR_FLAGS[`${forge} ${verb}`];
16191
+ if (!table)
16192
+ return null;
16193
+ const words = [];
16194
+ const repos = [];
16195
+ let selector;
16196
+ let ready = false;
16197
+ const rest = [...args.slice(1, at), ...args.slice(at + 1)];
16198
+ for (let index = 0;index < rest.length; index++) {
16199
+ const arg = rest[index];
16200
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
16201
+ const name = eq > 0 ? arg.slice(0, eq) : arg;
16202
+ const value = () => eq > 0 ? arg.slice(eq + 1) : rest[++index];
16203
+ if (name === "-R" || name === "--repo") {
16204
+ const named = value();
16205
+ if (named === undefined)
16206
+ return null;
16207
+ repos.push(named);
16208
+ } else if (/^-R./.test(arg))
16209
+ repos.push(arg.slice(2).replace(/^=/, ""));
16210
+ else if (eq < 0 && Object.hasOwn(table.booleans, arg)) {
16211
+ if (forge === "glab" && (arg === "--ready" || arg === "-r" || arg === "--draft")) {
16212
+ if (ready && words.includes("--undo") !== (arg === "--draft"))
16213
+ return null;
16214
+ ready = true;
16215
+ }
16216
+ words.push(...table.booleans[arg]);
16217
+ } else if (Object.hasOwn(table.values, name)) {
16218
+ const given = value();
16219
+ if (given === undefined)
16220
+ return null;
16221
+ const { flag, split } = table.values[name];
16222
+ if (split && given.includes(",") && /[$`]/.test(given))
16223
+ return null;
16224
+ for (const item of split ? given.split(",").filter(Boolean) : [given])
16225
+ words.push(...flagWord(flag, item, asWritten));
16226
+ } else if (arg.startsWith("-") || selector !== undefined)
16227
+ return null;
16228
+ else
16229
+ selector = arg;
16230
+ }
16231
+ const workitVerb = ready ? "ready" : table.verb;
16232
+ if (ready && words.some((word) => word !== "--undo"))
16233
+ return null;
16234
+ const pr = [];
16235
+ if (selector !== undefined) {
16236
+ const url = /^(https?:\/\/[^/]+\/.+?)\/(?:-\/)?(?:pull|merge_requests)\/(\d+)(?:[/?#].*)?$/.exec(selector);
16237
+ const number = url?.[2] ?? /^[#!]?(\d+)$/.exec(selector)?.[1];
16238
+ if (url)
16239
+ repos.push(url[1]);
16240
+ if (number)
16241
+ pr.push("--pr", number);
16242
+ else if (/\$[A-Za-z_{]/.test(selector))
16243
+ pr.push("--pr", asWritten(selector));
16244
+ else if (selector !== repo.branch)
16245
+ return null;
16246
+ }
16247
+ const env = invocation.env ?? {};
16248
+ if (forge === "gh" && (env.GH_REPO ?? process.env.GH_REPO))
16249
+ repos.push(env.GH_REPO ?? process.env.GH_REPO ?? "");
16250
+ if (repos.length) {
16251
+ const config = gitConfig(repo.dir, invocation, cache);
16252
+ const { GH_REPO: _named, ...own } = env;
16253
+ const key = (named, from) => {
16254
+ const found = forgeRepo(forge === "gh", named, from, config, repo.branch, repo.dir);
16255
+ return found instanceof Error ? null : found.remotes[0]?.key.toLowerCase() ?? null;
16256
+ };
16257
+ const checkout = key("", own);
16258
+ if (!checkout || repos.some((named) => /[$`]/.test(named) || key(named, own) !== checkout))
16259
+ return null;
16260
+ }
16261
+ const dir = path25.resolve(cwd, invocation.dir ?? ".");
16262
+ const call = [
16263
+ `workit pr ${workitVerb}`,
16264
+ ...dir === path25.resolve(cwd) ? [] : ["--cwd", shellWord(dir)],
16265
+ ...pr,
16266
+ ...words
16267
+ ].join(" ");
16268
+ return { raw: `${forge} ${forge === "gh" ? "pr" : "mr"} ${verb}`, call };
16269
+ };
16270
+ var prWriteRefusal = (writes, retry) => {
16271
+ const raws = [...new Set(writes.map((write) => quote(write.raw)))].join(", ");
16272
+ const calls = writes.map((write) => quote(write.call)).join(", ");
16273
+ const why = `workit: raw ${raws} changes the PR past workit's checks (the pr grant, and that the PR is this session's own).`;
16274
+ if (retry && writes.length === 1)
16275
+ return `${why} Run ${calls} instead.
16276
+ Retry as: ${writes[0].call}`;
16277
+ 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.`;
16278
+ };
16279
+ var refWriteRefusal = (action) => {
16280
+ if (action.unread)
16281
+ 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.`;
16282
+ if (action.setting)
16283
+ 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.`;
16284
+ const steers = [
16285
+ ...action.branch ? [
16286
+ `push a branch with ${quote("workit git push")} (it refuses protected branches and verifies the remote tip)`
16287
+ ] : [],
16288
+ ...action.tag ? [
16289
+ `tag a release with ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit git push --release <tag>")}, under the ${quote("release")} grant`
16290
+ ] : []
16291
+ ];
16292
+ 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("; ")}.`;
16293
+ };
15803
16294
  var refFacts = (repo, remote) => {
15804
16295
  const facts = {
15805
16296
  heads: new Set,
@@ -15948,6 +16439,7 @@ var nudgeFor = (action, host, session) => {
15948
16439
  case "pr-read":
15949
16440
  case "forge":
15950
16441
  case "merge":
16442
+ case "ref-write":
15951
16443
  return null;
15952
16444
  }
15953
16445
  };
@@ -15965,8 +16457,10 @@ var pushRefusal = (action, repo, config) => {
15965
16457
  return offPolicy;
15966
16458
  for (const target of targets) {
15967
16459
  const guarded = guardedTarget(repo.dir, target ?? repo.branch ?? "");
15968
- if (guarded)
15969
- return refusal(action, guarded, repo.dir);
16460
+ if (!guarded)
16461
+ continue;
16462
+ 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).` : "";
16463
+ return refusal(action, guarded, repo.dir) + first;
15970
16464
  }
15971
16465
  return tagRefusal(pushed, facts, repo.dir) ?? (action.deletes ? null : offPolicyPush(pushed, repo, facts, remote));
15972
16466
  };
@@ -16148,6 +16642,8 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
16148
16642
  try {
16149
16643
  guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
16150
16644
  } catch {}
16645
+ if (guarded && !switches && noRefs(repo))
16646
+ 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).`;
16151
16647
  if (guarded && !switches)
16152
16648
  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>")}.`;
16153
16649
  const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path25.resolve(input.cwd, invocation.dir), repo);
@@ -16157,6 +16653,8 @@ function rawGitPre(input, command, options = {}) {
16157
16653
  try {
16158
16654
  const dialect = dialectOf(input);
16159
16655
  const nudges = new Map;
16656
+ const prWrites = [];
16657
+ const asWritten = wordsOf(command, dialect);
16160
16658
  let store = null;
16161
16659
  const cache = new Map;
16162
16660
  const blind = rawInvocations(command, dialect).find((raw) => raw.redirect && rawAction(raw)?.kind === "push");
@@ -16177,8 +16675,19 @@ function rawGitPre(input, command, options = {}) {
16177
16675
  if (!workit)
16178
16676
  continue;
16179
16677
  store ??= repo.location.dir;
16180
- if (action.kind === "merge")
16181
- return deny(refusal(action, null));
16678
+ if (action.kind === "merge") {
16679
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
16680
+ const named = !retry ? "" : oneCall(command, dialect) ? `
16681
+ 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.`;
16682
+ return deny(`${refusal(action, null)}${named}`);
16683
+ }
16684
+ if (action.kind === "ref-write")
16685
+ return deny(refWriteRefusal(action));
16686
+ if (action.kind === "forge" && action.grant === "pr") {
16687
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
16688
+ if (retry)
16689
+ prWrites.push(retry);
16690
+ }
16182
16691
  if (action.kind === "push") {
16183
16692
  const refused = pushRefusal(action, repo, gitConfig(repo.dir, invocation, cache));
16184
16693
  if (refused)
@@ -16188,6 +16697,8 @@ function rawGitPre(input, command, options = {}) {
16188
16697
  if (nudge && !nudges.has(nudgeKind(action)))
16189
16698
  nudges.set(nudgeKind(action), nudge);
16190
16699
  }
16700
+ if (prWrites.length)
16701
+ return deny(prWriteRefusal(prWrites, oneCall(command, dialect)));
16191
16702
  const pkill = options.nudge === false ? null : pkillSelfMatch(command, dialect);
16192
16703
  const pkillNote = pkill ? { kind: "context", text: pkill } : NONE2;
16193
16704
  if (options.nudge === false || !store || nudges.size === 0)
@@ -16271,6 +16782,8 @@ var grantRefusal = (action, repo, invocation, cache) => {
16271
16782
  kinds.push("pr");
16272
16783
  else if (action.kind === "forge")
16273
16784
  kinds.push(action.grant);
16785
+ else if (action.kind === "ref-write")
16786
+ kinds.push(...action.branch ? ["push"] : [], ...action.tag ? ["release"] : [], ...action.unread ? ["merge"] : []);
16274
16787
  for (const kind of kinds) {
16275
16788
  const denied = rawGrantDenial(repo.dir, kind, target);
16276
16789
  if (denied)
@@ -16278,6 +16791,21 @@ var grantRefusal = (action, repo, invocation, cache) => {
16278
16791
  }
16279
16792
  return null;
16280
16793
  };
16794
+ var noRefs = (repo) => {
16795
+ const common = path25.dirname(repo.location.dir);
16796
+ const holds = (dir) => {
16797
+ try {
16798
+ return fs17.readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isFile() || entry.isDirectory() && holds(path25.join(dir, entry.name)));
16799
+ } catch {
16800
+ return false;
16801
+ }
16802
+ };
16803
+ try {
16804
+ if (/ refs\//.test(fs17.readFileSync(path25.join(common, "packed-refs"), "utf8")))
16805
+ return false;
16806
+ } catch {}
16807
+ return fs17.existsSync(path25.join(common, "refs")) && !holds(path25.join(common, "refs"));
16808
+ };
16281
16809
  var localTag = (repo, name) => {
16282
16810
  const common = path25.dirname(repo.location.dir);
16283
16811
  try {
@@ -17488,8 +18016,7 @@ var linesOf = (command, dialect) => {
17488
18016
  return null;
17489
18017
  }
17490
18018
  };
17491
- var quoteWord = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
17492
- var leaseCommand = (words) => `workit check --heavy -- ${words.map(quoteWord).join(" ")}`;
18019
+ var leaseCommand = (words, word) => `workit check --heavy -- ${words.map(word).join(" ")}`;
17493
18020
  function heavyPlan(command, options) {
17494
18021
  const dialect = options.dialect ?? "posix";
17495
18022
  if (dialect !== "posix" || !gitTop(options.cwd))
@@ -17522,7 +18049,8 @@ function heavyPlan(command, options) {
17522
18049
  }));
17523
18050
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single.reason } : { kind: "none" };
17524
18051
  }
17525
- const parts = heavy.map((match) => leaseCommand(match.line));
18052
+ const word = wordsOf(command, dialect);
18053
+ const parts = heavy.map((match) => leaseCommand(match.line, word));
17526
18054
  return {
17527
18055
  kind: "split",
17528
18056
  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" : ""}.`,
@@ -17544,7 +18072,7 @@ function serverPlan(command, options) {
17544
18072
  const rewrite = leaseRewrite(command)?.replace("workit check --heavy --", "workit run --bg --");
17545
18073
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single, server: true } : { kind: "none" };
17546
18074
  }
17547
- const start = `workit run --bg -- ${found.line.map(quoteWord).join(" ")}`;
18075
+ const start = `workit run --bg -- ${found.line.map(wordsOf(command, dialect)).join(" ")}`;
17548
18076
  return {
17549
18077
  kind: "split",
17550
18078
  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.`,
@@ -18292,7 +18820,7 @@ var wrappedScript = (input) => {
18292
18820
  const script = shellScript3(tail.argv);
18293
18821
  if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
18294
18822
  return script;
18295
- return tail.argv.map(quoteWord2).join(" ");
18823
+ return tail.argv.map(quoteWord).join(" ");
18296
18824
  };
18297
18825
  var editsOf = (input) => {
18298
18826
  const words = pastLead(input);
@@ -19170,7 +19698,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
19170
19698
  return lost;
19171
19699
  return target === undefined ? os9.homedir() : path31.resolve(dir, target);
19172
19700
  };
19173
- var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
19701
+ var quoteWord = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
19174
19702
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
19175
19703
  const value = vars.get(bare ?? braced ?? "");
19176
19704
  return value === undefined ? whole : value;
@@ -19568,7 +20096,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19568
20096
  targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
19569
20097
  const bare = strict && depth < 4 ? unwrapped2(words) : null;
19570
20098
  if (bare?.length && dir !== undefined)
19571
- targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
20099
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord).join(" "), "posix", depth + 1, strict, vars));
19572
20100
  if (strict === "registry" && dir !== undefined && depth < 4) {
19573
20101
  const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
19574
20102
  const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
@@ -19703,7 +20231,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19703
20231
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
19704
20232
  targets.push(...atAll(file));
19705
20233
  if (dir !== undefined)
19706
- for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
20234
+ for (const invocation of workitInvocations(body.map(quoteWord).join(" "), "posix")) {
19707
20235
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
19708
20236
  if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
19709
20237
  targets.push(...runsIn.map((runs) => placeholderIn(runs, DIR_TARGET)));
@@ -19712,7 +20240,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19712
20240
  return targets;
19713
20241
  };
19714
20242
  var workitRunDir = (dir, words, resolve) => {
19715
- for (const invocation of workitInvocations(words.map(quoteWord2).join(" "), "posix")) {
20243
+ for (const invocation of workitInvocations(words.map(quoteWord).join(" "), "posix")) {
19716
20244
  const { at, args } = workitCwd(dir, invocation, resolve);
19717
20245
  if (args[0] === "check" || args[0] === "lock" && args[1] === "run")
19718
20246
  return at;
@@ -22301,7 +22829,7 @@ var workitCallDir = (command, dialect) => {
22301
22829
  const call = plainWorkitCall(command, dialect);
22302
22830
  return call?.cwd && path36.isAbsolute(call.cwd) ? call.cwd : null;
22303
22831
  };
22304
- var shellWord = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
22832
+ var shellWord2 = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
22305
22833
  var cwdAt = (words, index) => words[index] === "--cwd" && words[index + 1] !== undefined ? 2 : words[index]?.startsWith("--cwd=") ? 1 : 0;
22306
22834
  var plainRetry = (dir, command) => {
22307
22835
  const call = plainWorkitCall(command, "posix");
@@ -22350,7 +22878,7 @@ var plainRetry = (dir, command) => {
22350
22878
  if (parts.includes(null))
22351
22879
  return null;
22352
22880
  const [envText, globalText, verbText, restText] = parts;
22353
- const cwd = ["--cwd", shellWord(dir)];
22881
+ const cwd = ["--cwd", shellWord2(dir)];
22354
22882
  const body = [...globalText, ...verbText, ...cwd, ...restText];
22355
22883
  return { retry: [...envText, "workit", ...body].join(" "), dropped };
22356
22884
  };
@@ -24112,11 +24640,12 @@ var hinted = (write) => write.hint ? {
24112
24640
  plain: false,
24113
24641
  workit: write.hint
24114
24642
  } : write;
24115
- var ytrackArgs = (line, found, depth, names, plain) => {
24643
+ var ytrackArgs = (line, found, depth, names, plain, expands = () => false) => {
24116
24644
  const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
24117
24645
  const tail = workitCheckTail(line);
24118
24646
  if (tail) {
24119
- inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
24647
+ const live = (text) => expands(text) && /[$`]/.test(text) ? `"${text.replaceAll(/["\\]/g, "\\$&")}"` : quote2(text);
24648
+ inner("script" in tail ? tail.script : tail.argv.map(live).join(" "));
24120
24649
  return true;
24121
24650
  }
24122
24651
  const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
@@ -24146,8 +24675,9 @@ var ytrackArgs = (line, found, depth, names, plain) => {
24146
24675
  const argv = [...alias ?? [], ...line.slice(at + 1)];
24147
24676
  const write = classify(argv);
24148
24677
  if (write) {
24678
+ const word = (text) => plain ? quote2(text) : shellWord(text, expands(text));
24149
24679
  const one = {
24150
- command: ["ytrack", ...argv].map(quote2).join(" "),
24680
+ command: ["ytrack", ...argv].map(word).join(" "),
24151
24681
  ...write,
24152
24682
  ...hostsOf(argv),
24153
24683
  plain
@@ -24250,14 +24780,15 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
24250
24780
  let found = [];
24251
24781
  const lines = plain ? plainLines(command, dialect) : null;
24252
24782
  const none = new Map;
24783
+ const expands = expandsIn(command, dialect);
24253
24784
  const plainFirst = lines ? ytrackArgs(lines.first, found, depth, none, true) : false;
24254
24785
  const joined = lines && plainFirst ? chained(found, lines.chain, depth) : null;
24255
24786
  if (joined)
24256
24787
  found = joined;
24257
- if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
24788
+ 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))) {
24258
24789
  found = [];
24259
24790
  for (const line of commandLines(command, dialect))
24260
- ytrackArgs(line, found, depth, aliases(command), false);
24791
+ ytrackArgs(line, found, depth, aliases(command), false, expands);
24261
24792
  found = found.map(hinted);
24262
24793
  }
24263
24794
  READ.set(key, found);
@@ -24267,7 +24798,7 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
24267
24798
  };
24268
24799
  var RELOCATES = /(?<![$\w])YTRACK_CONFIG_DIR\b/;
24269
24800
  var reachesOnly = (allowed, write) => write.plain && !!write.hosts?.length && write.hosts.every((host) => youTrackHostAllowed(allowed, host));
24270
- var scopedGate = (allowed, command, writes) => {
24801
+ var scopedGate = (allowed, command, dialect, writes) => {
24271
24802
  const scope = `youtrack.autoHosts (${allowed.join(", ")})`;
24272
24803
  if (RELOCATES.test(command))
24273
24804
  return {
@@ -24282,8 +24813,10 @@ var scopedGate = (allowed, command, writes) => {
24282
24813
  if (!unnamed.length)
24283
24814
  return null;
24284
24815
  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";
24285
- const bare = unnamed.find((write) => write.bare)?.bare;
24286
- const retry = bare ? ["ytrack", "--host", first, ...bare].map(quote2).join(" ") : null;
24816
+ const hostless = unnamed.find((each) => each.bare);
24817
+ const expands = expandsIn(command, dialect);
24818
+ const word = (text) => hostless?.plain ? quote2(text) : shellWord(text, expands(text));
24819
+ const retry = hostless?.bare ? ["ytrack", "--host", first, ...hostless.bare].map(word).join(" ") : null;
24287
24820
  return {
24288
24821
  kind: "deny",
24289
24822
  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 ? `
@@ -24319,7 +24852,7 @@ var ytrackGate = (cwd, command, dialect, ask) => {
24319
24852
  const hosts = policy.hosts;
24320
24853
  if (hosts === null)
24321
24854
  return null;
24322
- const scoped = scopedGate(hosts, command, writes);
24855
+ const scoped = scopedGate(hosts, command, dialect, writes);
24323
24856
  if (scoped)
24324
24857
  return scoped;
24325
24858
  writes = writes.filter((write) => !reachesOnly(hosts, write));