@workit-dev/opencode 2.20.6 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/plugin.js +366 -248
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -9511,7 +9511,8 @@ var workspaceConfigSchema = object({
9511
9511
  youtrack: object({
9512
9512
  baseUrl: nonBlank.optional().describe("This workspace's YouTrack URL."),
9513
9513
  link_issues: boolean2().optional().describe("Legacy alias of `issues: { provider: youtrack, link: true }`."),
9514
- writes: _enum(["ask", "auto"]).optional().describe("ask (default): each workit youtrack write waits for the user's yes. auto: posts without asking, behind WORKIT_YT_WRITE=1.")
9514
+ writes: _enum(["ask", "auto"]).optional().describe("ask (default): each workit youtrack write waits for the user's yes. auto: posts without asking, behind WORKIT_YT_WRITE=1."),
9515
+ autoHosts: array(nonBlank).optional().describe("With writes auto: the only YouTrack hosts (`acme.youtrack.cloud`) a write may reach without asking. A raw ytrack write must name one with --host; a write elsewhere asks. Only the user widens it, in their own terminal (`workit workspace seal`).")
9515
9516
  }).passthrough().optional().describe("YouTrack settings for this workspace."),
9516
9517
  issues: object({
9517
9518
  provider: _enum(["github", "gitlab", "youtrack"]).optional().describe("The issue tracker PRs link to."),
@@ -19372,20 +19373,20 @@ var exportDigest = (bundle) => sha256({
19372
19373
  task: bundle.task
19373
19374
  });
19374
19375
  // packages/workit-core/src/core/route-intent.ts
19375
- import { spawnSync as spawnSync17 } from "node:child_process";
19376
+ import { spawnSync as spawnSync18 } from "node:child_process";
19376
19377
  import { existsSync as existsSync12 } from "node:fs";
19377
- import path30 from "node:path";
19378
+ import path31 from "node:path";
19378
19379
 
19379
19380
  // packages/workit-core/src/hooks/raw-git.ts
19380
- import { spawnSync as spawnSync16 } from "node:child_process";
19381
+ import { spawnSync as spawnSync17 } from "node:child_process";
19381
19382
  import { createHash as createHash17 } from "node:crypto";
19382
- import fs20 from "node:fs";
19383
+ import fs21 from "node:fs";
19383
19384
  import os6 from "node:os";
19384
- import path29 from "node:path";
19385
+ import path30 from "node:path";
19385
19386
 
19386
19387
  // packages/workit-core/src/autonomy.ts
19387
19388
  import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync11, openSync as openSync2 } from "node:fs";
19388
- import path27 from "node:path";
19389
+ import path28 from "node:path";
19389
19390
 
19390
19391
  // packages/workit-core/src/core/eval-world.ts
19391
19392
  import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
@@ -19450,7 +19451,7 @@ var sealProjection = (entries) => entries.map((entry) => {
19450
19451
  return pick2({
19451
19452
  ...all,
19452
19453
  vcs: pick2(all.vcs, IDENTITY_KEYS),
19453
- youtrack: pick2(all.youtrack, ["writes"])
19454
+ youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
19454
19455
  }, ENTRY_KEYS);
19455
19456
  });
19456
19457
  var canonical3 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
@@ -19480,6 +19481,168 @@ function checkSeal(dir) {
19480
19481
  return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
19481
19482
  }
19482
19483
 
19484
+ // packages/workit-core/src/core/youtrack-ytrack.ts
19485
+ import { spawnSync as spawnSync16 } from "node:child_process";
19486
+
19487
+ // packages/workit-core/src/forge/exec.ts
19488
+ import fs19 from "node:fs";
19489
+ import path27 from "node:path";
19490
+
19491
+ // packages/workit-core/src/forge/redact.ts
19492
+ var KEY = String.raw`[A-Za-z0-9_.-]*?(?:token|secret|password|passwd|pwd|api[_-]?key|access[_-]?key|account[_-]?key|private[_-]?key|client[_-]?secret|credentials?|authorization|cookie|signature)[A-Za-z0-9_.-]*`;
19493
+ var ASSIGNMENT = new RegExp(String.raw`(?<![A-Za-z0-9])(["']?${KEY}["']?\s*[:=]\s*["']?)((?:bearer|basic|token|digest)\s+)?([^\s"',;&]+)`, "giu");
19494
+ var QUOTED_ASSIGNMENT = new RegExp(String.raw`(?<![A-Za-z0-9])(["']?${KEY}["']?\s*[:=]\s*)(["'])([^"'\n]*[^\s"'][^"'\n]*)\2`, "giu");
19495
+ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007`, "gu");
19496
+
19497
+ // packages/workit-core/src/forge/types.ts
19498
+ var success2 = (data) => ({ ok: true, data });
19499
+ var failure3 = (code, error, unblock) => ({ ok: false, code, error, ...unblock ? { unblock } : {} });
19500
+
19501
+ // packages/workit-core/src/forge/exec.ts
19502
+ var MAX_BUFFER2 = 64 * 1024 * 1024;
19503
+ function findExecutable(bin, env) {
19504
+ const dirs = (env.PATH ?? env.Path ?? "").split(path27.delimiter).filter(Boolean);
19505
+ const exts = process.platform === "win32" ? [".exe"] : [""];
19506
+ for (const dir of dirs)
19507
+ for (const ext of exts) {
19508
+ const candidate = path27.join(dir, `${bin}${ext}`);
19509
+ try {
19510
+ const stat = fs19.statSync(candidate);
19511
+ if (stat.isFile())
19512
+ return candidate;
19513
+ } catch {}
19514
+ }
19515
+ return null;
19516
+ }
19517
+
19518
+ // packages/workit-core/src/core/youtrack-ytrack.ts
19519
+ var TIMEOUT_MS = 60000;
19520
+ var YTRACK_EXIT = { ok: 0, failed: 1, cancelled: 2, auth: 4 };
19521
+ var findYtrack = (env) => env.WORKIT_NO_YTRACK === "1" ? null : findExecutable("ytrack", env);
19522
+ var YTRACK_QUIET_ENV = {
19523
+ YTRACK_NO_UPDATE_NOTIFIER: "1",
19524
+ YTRACK_NO_AUTO_UPGRADE: "1"
19525
+ };
19526
+ function ytrackRunner(env, host, timeoutMs = TIMEOUT_MS) {
19527
+ return (args, input) => {
19528
+ const exe = findYtrack(env);
19529
+ if (!exe)
19530
+ return { status: null, stdout: "", stderr: "", missing: true };
19531
+ const result = spawnSync16(exe, args, {
19532
+ encoding: "utf8",
19533
+ env: {
19534
+ ...env,
19535
+ NO_COLOR: "1",
19536
+ ...YTRACK_QUIET_ENV,
19537
+ ...host ? { YTRACK_HOST: host } : {}
19538
+ },
19539
+ timeout: timeoutMs,
19540
+ killSignal: "SIGKILL",
19541
+ windowsHide: true,
19542
+ ...input === undefined ? { stdio: ["ignore", "pipe", "pipe"] } : { input, stdio: ["pipe", "pipe", "pipe"] }
19543
+ });
19544
+ const error = result.error;
19545
+ if (error?.code === "ENOENT")
19546
+ return { status: null, stdout: "", stderr: "", missing: true };
19547
+ return {
19548
+ status: result.status,
19549
+ stdout: result.stdout ?? "",
19550
+ stderr: result.stderr || (error ? error.message : "")
19551
+ };
19552
+ };
19553
+ }
19554
+ var ytrackDetail = (out) => out.stderr.trim().split(`
19555
+ `).slice(-3).join(" ").slice(0, 300);
19556
+ var STATUS_FIELDS = "host,active,login,state,tokenSource,error";
19557
+ function ytrackStatus(run) {
19558
+ const version = run(["version"]);
19559
+ if (version.missing)
19560
+ return { installed: false };
19561
+ const match = /ytrack version (\S+)/u.exec(version.stdout);
19562
+ const status = run(["auth", "status", "--json", STATUS_FIELDS]);
19563
+ const base = { installed: true, version: match ? match[1] : null };
19564
+ if (status.status === YTRACK_EXIT.auth)
19565
+ return { ...base, auth: "logged_out", hosts: [], error: ytrackDetail(status) || null };
19566
+ let rows;
19567
+ try {
19568
+ rows = JSON.parse(status.stdout);
19569
+ } catch {
19570
+ return { ...base, auth: "error", hosts: [], error: ytrackDetail(status) || "no JSON" };
19571
+ }
19572
+ const hosts = (Array.isArray(rows) ? rows : [rows]).filter((row) => typeof row === "object" && row !== null).map((row) => ({
19573
+ host: String(row.host ?? ""),
19574
+ active: row.active === true,
19575
+ login: typeof row.login === "string" && row.login ? row.login : null,
19576
+ state: String(row.state ?? "error"),
19577
+ tokenSource: typeof row.tokenSource === "string" && row.tokenSource ? row.tokenSource : null,
19578
+ error: typeof row.error === "string" && row.error ? row.error : null
19579
+ }));
19580
+ const active = hosts.find((row) => row.active) ?? hosts[0];
19581
+ return { ...base, auth: rowAuth(active), hosts, error: null };
19582
+ }
19583
+ var rowAuth = (row) => !row ? "logged_out" : row.state === "ok" ? "ok" : row.state === "rejected" ? "rejected" : row.state === "no_token" ? "logged_out" : "error";
19584
+ var ytrackHostName = (urlOrHost) => urlOrHost.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//iu, "").split("/")[0].toLowerCase();
19585
+ var youTrackHostKey = (input) => {
19586
+ const text = input.trim();
19587
+ if (!text || /\s/u.test(text))
19588
+ return null;
19589
+ let url;
19590
+ try {
19591
+ url = new URL(text.includes("://") ? text : `https://${text}`);
19592
+ } catch {
19593
+ return null;
19594
+ }
19595
+ if (!/^https?:$/u.test(url.protocol) || !url.hostname || url.username || url.password)
19596
+ return null;
19597
+ const service = url.pathname.replace(/\/+$/u, "").replace(/\/api$/u, "").replace(/\/+$/u, "");
19598
+ return `${url.host.toLowerCase()}${service}`;
19599
+ };
19600
+ var youTrackHostAllowed = (allowed, host) => {
19601
+ const key = host ? youTrackHostKey(host) : null;
19602
+ return key !== null && allowed.some((entry) => youTrackHostKey(entry) === key);
19603
+ };
19604
+ function ytrackHostAuth(status, host) {
19605
+ if (!host) {
19606
+ const active = status.hosts.find((row) => row.active) ?? status.hosts[0];
19607
+ return {
19608
+ auth: status.auth,
19609
+ login: active?.login ?? null,
19610
+ error: active?.error ?? status.error
19611
+ };
19612
+ }
19613
+ const name = ytrackHostName(host);
19614
+ const row = status.hosts.find((candidate) => ytrackHostName(candidate.host) === name);
19615
+ return {
19616
+ auth: status.auth === "error" && !row ? "error" : rowAuth(row),
19617
+ login: row?.login ?? null,
19618
+ error: row?.error ?? status.error
19619
+ };
19620
+ }
19621
+ var YTRACK_INSTALL = "install ytrack (https://github.com/BrainerVirus/youtrack-cli: install.sh, or install.ps1 on Windows)";
19622
+ var ytrackLogin = (host) => `ytrack auth login${host ? ` --host ${ytrackHostName(host)}` : ""}`;
19623
+ var ytrackMissingUnblock = (host) => `${YTRACK_INSTALL}, then ${ytrackLogin(host)}`;
19624
+ var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only through ytrack";
19625
+ function ytrackReadiness(run, host) {
19626
+ const status = ytrackStatus(run);
19627
+ if (!status.installed)
19628
+ return {
19629
+ ok: false,
19630
+ reason: "missing",
19631
+ error: YTRACK_MISSING,
19632
+ unblock: ytrackMissingUnblock(host)
19633
+ };
19634
+ const auth = ytrackHostAuth(status, host);
19635
+ const where = host ? ytrackHostName(host) : "the active host";
19636
+ if (auth.auth === "ok")
19637
+ return { ok: true, version: status.version, login: auth.login };
19638
+ return {
19639
+ ok: false,
19640
+ reason: auth.auth,
19641
+ error: auth.auth === "logged_out" ? `ytrack is not logged in to ${where}` : auth.auth === "rejected" ? `${where} rejected ytrack's stored token` : `could not read ytrack's login for ${where}${auth.error ? ` (${auth.error})` : ""}`,
19642
+ unblock: ytrackLogin(host)
19643
+ };
19644
+ }
19645
+
19483
19646
  // packages/workit-core/src/autonomy.ts
19484
19647
  var accountHomeDir = () => {
19485
19648
  const home = grantsHome.resolve();
@@ -19487,7 +19650,7 @@ var accountHomeDir = () => {
19487
19650
  };
19488
19651
  var deniedFile = (dir) => {
19489
19652
  for (const name of ["workspaces.json", SEAL_FILE]) {
19490
- const file = path27.join(dir, name);
19653
+ const file = path28.join(dir, name);
19491
19654
  try {
19492
19655
  closeSync2(openSync2(file, "r"));
19493
19656
  } catch (error) {
@@ -19509,7 +19672,7 @@ var accountUnread = () => {
19509
19672
  if (dir === null)
19510
19673
  return NO_ACCOUNT;
19511
19674
  const file = deniedFile(dir);
19512
- return file === null ? null : `the account's ${path27.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
19675
+ return file === null ? null : `the account's ${path28.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
19513
19676
  };
19514
19677
  var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
19515
19678
  var fileSource = (dir = accountDir()) => ({
@@ -19528,26 +19691,40 @@ var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own
19528
19691
  var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
19529
19692
  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}`;
19530
19693
  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;
19531
- var youTrackWritesMode = (cwd) => {
19694
+ var ASK = { mode: "ask" };
19695
+ var youtrackOf = (entry) => entry?.youtrack;
19696
+ var autoHostsOf = (entry) => {
19697
+ const hosts = youtrackOf(entry)?.autoHosts;
19698
+ return Array.isArray(hosts) ? hosts.filter((host) => typeof host === "string") : null;
19699
+ };
19700
+ var youTrackWritesPolicy = (cwd) => {
19532
19701
  try {
19533
19702
  const dir = accountDir();
19534
19703
  if (dir === null || redirected(dir) || evalWorld(cwd))
19535
- return "ask";
19704
+ return ASK;
19536
19705
  if (checkSeal(dir).state !== "valid")
19537
- return "ask";
19538
- const auto = (entry) => entry?.youtrack?.writes === "auto";
19706
+ return ASK;
19707
+ const auto = (entry) => youtrackOf(entry)?.writes === "auto";
19539
19708
  const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
19540
- if (!auto(resolveWorkspaceFrom(cwd, dir, name)))
19541
- return "ask";
19542
- return !name || auto(resolveWorkspaceFrom(cwd, dir)) ? "auto" : "ask";
19709
+ const named = resolveWorkspaceFrom(cwd, dir, name);
19710
+ const folder = name ? resolveWorkspaceFrom(cwd, dir) : named;
19711
+ if (!auto(named) || !auto(folder))
19712
+ return ASK;
19713
+ const [a, b] = [autoHostsOf(named), autoHostsOf(folder)];
19714
+ const base = youtrackOf(named)?.baseUrl;
19715
+ return {
19716
+ mode: "auto",
19717
+ hosts: a === null ? b : b === null ? a : a.filter((host) => youTrackHostAllowed(b, host)),
19718
+ baseUrl: typeof base === "string" && base.trim() ? base.trim() : null
19719
+ };
19543
19720
  } catch {
19544
- return "ask";
19721
+ return ASK;
19545
19722
  }
19546
19723
  };
19547
- var redirected = (dir) => path27.resolve(resolveConfigDir()) !== path27.resolve(dir);
19724
+ var redirected = (dir) => path28.resolve(resolveConfigDir()) !== path28.resolve(dir);
19548
19725
  var shownGrantsDir = () => {
19549
19726
  const world = evalWorld(process.cwd());
19550
- return world ? path27.join(world, "config") : accountDir();
19727
+ return world ? path28.join(world, "config") : accountDir();
19551
19728
  };
19552
19729
  var benchWorld = (cwd) => {
19553
19730
  const entry = evalWorldEntry(cwd);
@@ -19571,10 +19748,10 @@ var grantsOverride = () => {
19571
19748
  const shown = shownGrantsDir();
19572
19749
  if (shown === null)
19573
19750
  return accountUnread() ?? NO_ACCOUNT;
19574
- const configured = path27.resolve(resolveConfigDir());
19575
- return configured === path27.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path27.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
19751
+ const configured = path28.resolve(resolveConfigDir());
19752
+ return configured === path28.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path28.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
19576
19753
  };
19577
- var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${path27.join(grantsDir(), "workspaces.json")}`;
19754
+ var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${path28.join(grantsDir(), "workspaces.json")}`;
19578
19755
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
19579
19756
  var DEFAULT_GRANTS = Object.freeze({
19580
19757
  push: true,
@@ -19982,8 +20159,8 @@ var packageTagShapes = (packages) => packages.map((entry) => `${entry.tagNamespa
19982
20159
 
19983
20160
  // packages/workit-core/src/hooks/session-marker.ts
19984
20161
  import { createHash as createHash16 } from "node:crypto";
19985
- import fs19 from "node:fs";
19986
- import path28 from "node:path";
20162
+ import fs20 from "node:fs";
20163
+ import path29 from "node:path";
19987
20164
  var sessionMarkerFile = (input, session, store) => {
19988
20165
  let dir = store;
19989
20166
  if (dir === undefined) {
@@ -19993,7 +20170,7 @@ var sessionMarkerFile = (input, session, store) => {
19993
20170
  dir = location.dir;
19994
20171
  }
19995
20172
  const name = createHash16("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
19996
- return path28.join(dir, "hooks", `skills-${name}.json`);
20173
+ return path29.join(dir, "hooks", `skills-${name}.json`);
19997
20174
  };
19998
20175
  var list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
19999
20176
  var EMPTY = {
@@ -20006,7 +20183,7 @@ var EMPTY = {
20006
20183
  };
20007
20184
  var readRaw = (file) => {
20008
20185
  try {
20009
- return fs19.readFileSync(file, "utf8");
20186
+ return fs20.readFileSync(file, "utf8");
20010
20187
  } catch {
20011
20188
  return "";
20012
20189
  }
@@ -20028,13 +20205,13 @@ var parseMarker = (text) => {
20028
20205
  };
20029
20206
  var readSessionMarker = (file) => parseMarker(readRaw(file));
20030
20207
  var writeAtomic = (file, marker) => {
20031
- fs19.mkdirSync(path28.dirname(file), { recursive: true });
20208
+ fs20.mkdirSync(path29.dirname(file), { recursive: true });
20032
20209
  const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
20033
20210
  try {
20034
- fs19.writeFileSync(temp, JSON.stringify(marker));
20035
- fs19.renameSync(temp, file);
20211
+ fs20.writeFileSync(temp, JSON.stringify(marker));
20212
+ fs20.renameSync(temp, file);
20036
20213
  } catch (error) {
20037
- fs19.rmSync(temp, { force: true });
20214
+ fs20.rmSync(temp, { force: true });
20038
20215
  throw error;
20039
20216
  }
20040
20217
  };
@@ -20591,17 +20768,17 @@ var GIT_VALUE_OPTIONS = new Set([
20591
20768
  ]);
20592
20769
  var GIT_CONFIG_OPTIONS = new Set(["-c", "--config-env", "--git-dir"]);
20593
20770
  var GIT_CONFIG_ENV = /^(?:GIT_(?:CONFIG\w*|DIR|COMMON_DIR|WORK_TREE|SSH|SSH_COMMAND|PROXY_COMMAND|EXEC_PATH)|GH_HOST|GH_REPO|GITLAB_HOST|GL_HOST)$/;
20594
- var ASSIGNMENT = /^([A-Za-z_]\w*)=([\s\S]*)$/;
20771
+ var ASSIGNMENT2 = /^([A-Za-z_]\w*)=([\s\S]*)$/;
20595
20772
  var MAX_DEPTH = 4;
20596
20773
  var MAX_EXPANSIONS = 16;
20597
- var isAbsolute = (value) => path29.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
20774
+ var isAbsolute = (value) => path30.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
20598
20775
  var HERE = /^(?:\$PWD|\$\{PWD\}|\$\(\s*pwd\s*\)|`pwd`|\$\(\s*git\s+rev-parse\s+--show-toplevel\s*\))(?=$|[\\/])/;
20599
20776
  var joinDir = (base, raw) => {
20600
20777
  const next = raw.replace(HERE, ".");
20601
20778
  if (base === undefined || /[$`*?]/.test(next) || next === "-")
20602
20779
  return;
20603
- const expanded = next === "~" || next.startsWith("~/") ? path29.join(os6.homedir(), next.slice(1)) : next;
20604
- return base === null || isAbsolute(expanded) ? expanded : path29.join(base, expanded);
20780
+ const expanded = next === "~" || next.startsWith("~/") ? path30.join(os6.homedir(), next.slice(1)) : next;
20781
+ return base === null || isAbsolute(expanded) ? expanded : path30.join(base, expanded);
20605
20782
  };
20606
20783
  var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
20607
20784
  var cdTarget = (words) => {
@@ -20618,7 +20795,7 @@ var stripPrefixes = (input) => {
20618
20795
  const first = words[0];
20619
20796
  if (first === undefined)
20620
20797
  return { words, env };
20621
- const assignment = ASSIGNMENT.exec(first);
20798
+ const assignment = ASSIGNMENT2.exec(first);
20622
20799
  if (assignment) {
20623
20800
  if (GIT_CONFIG_ENV.test(assignment[1]))
20624
20801
  env[assignment[1]] = assignment[2];
@@ -20677,10 +20854,10 @@ var assignments = (words, vars) => {
20677
20854
  while (rest[0]?.startsWith("-"))
20678
20855
  rest = rest.slice(1);
20679
20856
  }
20680
- if (rest.length === 0 || !rest.every((word) => ASSIGNMENT.test(word)))
20857
+ if (rest.length === 0 || !rest.every((word) => ASSIGNMENT2.test(word)))
20681
20858
  return null;
20682
20859
  return rest.map((word) => {
20683
- const [, name, value] = ASSIGNMENT.exec(word);
20860
+ const [, name, value] = ASSIGNMENT2.exec(word);
20684
20861
  return [name, expandWord(value, vars)];
20685
20862
  });
20686
20863
  };
@@ -20868,7 +21045,7 @@ var splitString = (line) => {
20868
21045
  return line.slice(index).join(" ").slice(15);
20869
21046
  if (/^-S./.test(word))
20870
21047
  return [word.slice(2), ...line.slice(index + 1)].join(" ");
20871
- if (!word.startsWith("-") && !ASSIGNMENT.test(word))
21048
+ if (!word.startsWith("-") && !ASSIGNMENT2.test(word))
20872
21049
  return null;
20873
21050
  }
20874
21051
  return null;
@@ -21502,7 +21679,7 @@ var repoAt = (dir) => {
21502
21679
  return { location, dir, branch: resolveTaskKey(dir, location).branch };
21503
21680
  };
21504
21681
  var isWorkitWorkspace = (repo) => {
21505
- if (fs20.existsSync(repo.location.dir))
21682
+ if (fs21.existsSync(repo.location.dir))
21506
21683
  return true;
21507
21684
  try {
21508
21685
  return resolveRuntimeWorkspaceVcs(repo.location.top ?? repo.dir) !== null;
@@ -21523,17 +21700,17 @@ var headSha2 = (repo) => {
21523
21700
  if (!git || git.reftable)
21524
21701
  return null;
21525
21702
  try {
21526
- const head = fs20.readFileSync(path29.join(git.gitDir, "HEAD"), "utf8").trim();
21703
+ const head = fs21.readFileSync(path30.join(git.gitDir, "HEAD"), "utf8").trim();
21527
21704
  if (/^[0-9a-f]{40,64}$/.test(head))
21528
21705
  return head;
21529
21706
  const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
21530
21707
  if (!ref)
21531
21708
  return null;
21532
- const common = path29.dirname(repo.location.dir);
21709
+ const common = path30.dirname(repo.location.dir);
21533
21710
  try {
21534
- return fs20.readFileSync(path29.join(common, ref), "utf8").trim() || null;
21711
+ return fs21.readFileSync(path30.join(common, ref), "utf8").trim() || null;
21535
21712
  } catch {}
21536
- const packed = fs20.readFileSync(path29.join(common, "packed-refs"), "utf8");
21713
+ const packed = fs21.readFileSync(path30.join(common, "packed-refs"), "utf8");
21537
21714
  return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
21538
21715
  } catch {
21539
21716
  return null;
@@ -21545,7 +21722,7 @@ var gitConfig = (dir, invocation, cache) => {
21545
21722
  if (cached)
21546
21723
  return cached;
21547
21724
  const config = new Map;
21548
- const listed = spawnSync16("git", [...invocation.config ?? [], "config", "-z", "--list"], {
21725
+ const listed = spawnSync17("git", [...invocation.config ?? [], "config", "-z", "--list"], {
21549
21726
  cwd: dir,
21550
21727
  encoding: "utf8",
21551
21728
  timeout: 3000,
@@ -21626,8 +21803,8 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
21626
21803
  const sub = invocation.args[0];
21627
21804
  if (invocation.tool !== "git" || invocation.dir === undefined || !sub || sub.startsWith("-") || GIT_COMMANDS.has(sub) || depth >= MAX_DEPTH)
21628
21805
  return [invocation];
21629
- const dir = path29.resolve(root, invocation.dir ?? ".");
21630
- if (!fs20.existsSync(dir))
21806
+ const dir = path30.resolve(root, invocation.dir ?? ".");
21807
+ if (!fs21.existsSync(dir))
21631
21808
  return [invocation];
21632
21809
  const config = gitConfig(dir, invocation, cache);
21633
21810
  const alias = configValue(config, `alias.${sub.toLowerCase()}`);
@@ -21649,11 +21826,11 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
21649
21826
  var normalizedUrl = (url, dir) => {
21650
21827
  const trimmed = url.trim();
21651
21828
  if (/^file:\/\//i.test(trimmed))
21652
- return path29.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
21829
+ return path30.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
21653
21830
  const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(trimmed);
21654
21831
  const scp = !scheme && /^(?:[^@/\\]+@)?[^/\\:]{2,}:/.test(trimmed);
21655
21832
  if (!scheme && !scp)
21656
- return path29.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
21833
+ return path30.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
21657
21834
  const value = scheme ? trimmed.slice(scheme[0].length).replace(/^[^@/]*@/, "").replace(/^([^/:]+):\d+(?=\/)/, "$1") : trimmed.replace(/^[^@/]*@/, "").replace(":", "/");
21658
21835
  return value.toLowerCase().replace(/\/{2,}/g, "/").replace(/^www\./, "").replace(/\/+$/, "").replace(/\.git$/, "");
21659
21836
  };
@@ -21718,7 +21895,7 @@ var refFacts = (repo, remote) => {
21718
21895
  tags: new Set,
21719
21896
  remoteHeads: new Set
21720
21897
  };
21721
- const listed = spawnSync16("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/tags", `refs/remotes/${remote}`], { cwd: repo.dir, encoding: "utf8", timeout: 5000 });
21898
+ const listed = spawnSync17("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/tags", `refs/remotes/${remote}`], { cwd: repo.dir, encoding: "utf8", timeout: 5000 });
21722
21899
  const remotePrefix = `refs/remotes/${remote}/`;
21723
21900
  for (const ref of (listed.stdout ?? "").split(`
21724
21901
  `)) {
@@ -21735,7 +21912,7 @@ var globBranches = (repo, glob) => {
21735
21912
  const source = glob.source.startsWith("refs/") ? glob.source : `refs/heads/${glob.source}`;
21736
21913
  const [sourcePrefix, sourceSuffix = ""] = source.split("*");
21737
21914
  const [destinationPrefix, destinationSuffix = ""] = glob.destination.split("*");
21738
- const listed = spawnSync16("git", [
21915
+ const listed = spawnSync17("git", [
21739
21916
  "for-each-ref",
21740
21917
  "--format=%(refname)",
21741
21918
  sourcePrefix.slice(0, sourcePrefix.lastIndexOf("/") + 1)
@@ -21817,7 +21994,7 @@ var tagRefusal = (action, facts, dir) => {
21817
21994
  return `workit: raw ${quote(`git push${action.allTags ? " --tags" : ""}`)} of ${tags.length ? `tag ${tags.join(", ")}` : "tags"} bypasses the release grant. Push a release tag with ${quote(`workit git push --release ${named}`)} (${shapes.join(", ")} tags whose commit the production branch already has; a tag never moves), under the ${quote("release")} grant (if refused, ask the user to run ${quote("workit grant set <workspace> release=true")}).${create}`;
21818
21995
  };
21819
21996
  var remoteHeads = (repo, remote) => {
21820
- const listed = spawnSync16("git", ["ls-remote", "--heads", remote], {
21997
+ const listed = spawnSync17("git", ["ls-remote", "--heads", remote], {
21821
21998
  cwd: repo.dir,
21822
21999
  encoding: "utf8",
21823
22000
  timeout: 3000,
@@ -21886,7 +22063,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
21886
22063
  const out = [];
21887
22064
  const repos = new Map;
21888
22065
  const repoFor = (relative) => {
21889
- const dir = path29.resolve(cwd, relative ?? ".");
22066
+ const dir = path30.resolve(cwd, relative ?? ".");
21890
22067
  if (!repos.has(dir)) {
21891
22068
  const repo = repoAt(dir);
21892
22069
  const workit = repo !== null && isWorkitWorkspace(repo);
@@ -21907,7 +22084,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
21907
22084
  const action = rawAction(invocation);
21908
22085
  const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
21909
22086
  repo: {
21910
- dir: path29.resolve(cwd, invocation.dir ?? "."),
22087
+ dir: path30.resolve(cwd, invocation.dir ?? "."),
21911
22088
  branch: null
21912
22089
  },
21913
22090
  workit: false
@@ -21980,13 +22157,13 @@ var messageOf = (segment, index) => {
21980
22157
  };
21981
22158
  var sameGitDir = (a, b, platform = process.platform) => {
21982
22159
  if (platform !== "win32")
21983
- return path29.posix.resolve(a) === path29.posix.resolve(b);
21984
- const fold = (value) => path29.win32.resolve(value).toLowerCase();
22160
+ return path30.posix.resolve(a) === path30.posix.resolve(b);
22161
+ const fold = (value) => path30.win32.resolve(value).toLowerCase();
21985
22162
  return fold(a) === fold(b);
21986
22163
  };
21987
22164
  var cdCommitCall = (input, command, target, repo) => {
21988
22165
  const { top, git, dir: store } = repo.location;
21989
- if (!top || !git || sameGitDir(git.gitDir, path29.dirname(store)) || repoAt(input.cwd)?.location.top === top)
22166
+ if (!top || !git || sameGitDir(git.gitDir, path30.dirname(store)) || repoAt(input.cwd)?.location.top === top)
21990
22167
  return null;
21991
22168
  const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
21992
22169
  if (/[;|&<>`$()\n\\]/u.test(bare))
@@ -21995,7 +22172,7 @@ var cdCommitCall = (input, command, target, repo) => {
21995
22172
  const commit = rest.at(-1);
21996
22173
  if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
21997
22174
  return null;
21998
- if (path29.resolve(input.cwd, cd.words[1]) !== target)
22175
+ if (path30.resolve(input.cwd, cd.words[1]) !== target)
21999
22176
  return null;
22000
22177
  if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
22001
22178
  return null;
@@ -22038,7 +22215,7 @@ var cdCommitCall = (input, command, target, repo) => {
22038
22215
  if (!messages.length)
22039
22216
  return null;
22040
22217
  if (!all) {
22041
- const staged = spawnSync16("git", ["diff", "--cached", "--quiet"], {
22218
+ const staged = spawnSync17("git", ["diff", "--cached", "--quiet"], {
22042
22219
  cwd: target,
22043
22220
  timeout: 5000
22044
22221
  });
@@ -22062,7 +22239,7 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
22062
22239
  } catch {}
22063
22240
  if (guarded && !switches)
22064
22241
  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>")}.`;
22065
- const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path29.resolve(input.cwd, invocation.dir), repo);
22242
+ const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path30.resolve(input.cwd, invocation.dir), repo);
22066
22243
  return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
22067
22244
  };
22068
22245
  function rawGitPre(input, command, options = {}) {
@@ -22160,9 +22337,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
22160
22337
  return null;
22161
22338
  };
22162
22339
  var localTag = (repo, name) => {
22163
- const common = path29.dirname(repo.location.dir);
22340
+ const common = path30.dirname(repo.location.dir);
22164
22341
  try {
22165
- return fs20.existsSync(path29.join(common, "refs/tags", name)) || fs20.readFileSync(path29.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
22342
+ return fs21.existsSync(path30.join(common, "refs/tags", name)) || fs21.readFileSync(path30.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
22166
22343
  `);
22167
22344
  } catch {
22168
22345
  return false;
@@ -22181,7 +22358,7 @@ var analysisDenial = (error) => ({
22181
22358
  unblock: SPLIT_IT
22182
22359
  });
22183
22360
  var MARKER_TTL_SECONDS = 3600;
22184
- var markerFile = (repo, session, key) => path29.join(repo.location.dir, "hooks", `commit-${createHash17("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
22361
+ var markerFile = (repo, session, key) => path30.join(repo.location.dir, "hooks", `commit-${createHash17("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
22185
22362
  var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash17("sha256").update(command).digest("hex")}`;
22186
22363
  function noteRawCommit(input, command, key) {
22187
22364
  try {
@@ -22192,14 +22369,14 @@ function noteRawCommit(input, command, key) {
22192
22369
  if (action.kind !== "commit")
22193
22370
  continue;
22194
22371
  const file = markerFile(repo, input.session.id, key);
22195
- fs20.mkdirSync(path29.dirname(file), { recursive: true });
22196
- fs20.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
22372
+ fs21.mkdirSync(path30.dirname(file), { recursive: true });
22373
+ fs21.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
22197
22374
  `);
22198
22375
  }
22199
22376
  } catch {}
22200
22377
  }
22201
22378
  var headCommit = (dir) => {
22202
- const run = spawnSync16("git", [
22379
+ const run = spawnSync17("git", [
22203
22380
  "log",
22204
22381
  "-1",
22205
22382
  "--format=%H%x1f%ct%x1f%s%x1f%(trailers:key=Workit-Session,valueonly,separator=%x2c)"
@@ -22226,11 +22403,11 @@ var headCommit = (dir) => {
22226
22403
  var settle2 = (input, repo, file) => {
22227
22404
  let marker;
22228
22405
  try {
22229
- marker = JSON.parse(fs20.readFileSync(file, "utf8"));
22406
+ marker = JSON.parse(fs21.readFileSync(file, "utf8"));
22230
22407
  } catch {
22231
22408
  return;
22232
22409
  }
22233
- fs20.rmSync(file, { force: true });
22410
+ fs21.rmSync(file, { force: true });
22234
22411
  const session = input.session.id;
22235
22412
  const now = Date.now() / 1000;
22236
22413
  if (typeof marker.at !== "number" || now - marker.at > MARKER_TTL_SECONDS)
@@ -22411,7 +22588,7 @@ var targetsOf = (invocations) => invocations.flatMap((invocation) => invocation.
22411
22588
  branch,
22412
22589
  dir: invocation.dir
22413
22590
  })) : []);
22414
- var localBranchExists = (dir, branch) => spawnSync17("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
22591
+ var localBranchExists = (dir, branch) => spawnSync18("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
22415
22592
  cwd: dir,
22416
22593
  stdio: "ignore",
22417
22594
  timeout: 5000
@@ -22421,7 +22598,7 @@ var judgedDir = (root, dir) => {
22421
22598
  return null;
22422
22599
  if (dir === null)
22423
22600
  return root;
22424
- const resolved = path30.resolve(root, dir);
22601
+ const resolved = path31.resolve(root, dir);
22425
22602
  return existsSync12(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
22426
22603
  };
22427
22604
  var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
@@ -24417,9 +24594,9 @@ class WorkitCore {
24417
24594
  }
24418
24595
  }
24419
24596
  // packages/workit-core/src/core/repo-context.ts
24420
- import { spawnSync as spawnSync18 } from "node:child_process";
24597
+ import { spawnSync as spawnSync19 } from "node:child_process";
24421
24598
  import { existsSync as existsSync13, readFileSync as readFileSync11, readdirSync as readdirSync4 } from "node:fs";
24422
- import path31 from "node:path";
24599
+ import path32 from "node:path";
24423
24600
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
24424
24601
  try {
24425
24602
  gitRevisionParts(value);
@@ -24446,7 +24623,7 @@ var invalidRange = (cwd) => ({
24446
24623
  cwd
24447
24624
  });
24448
24625
  var runGit = (cwd, args) => {
24449
- const result = spawnSync18("git", args, { cwd, encoding: "utf8" });
24626
+ const result = spawnSync19("git", args, { cwd, encoding: "utf8" });
24450
24627
  return {
24451
24628
  stdout: (result.stdout ?? "").trimEnd(),
24452
24629
  stderr: (result.stderr ?? "").trimEnd(),
@@ -24563,13 +24740,13 @@ var findPrTemplate = (cwd) => {
24563
24740
  for (const rel of PR_TEMPLATE_FILES) {
24564
24741
  const parts = rel.split("/");
24565
24742
  const base = parts[parts.length - 1];
24566
- const dir = parts.length > 1 ? path31.join(cwd, ...parts.slice(0, -1)) : cwd;
24743
+ const dir = parts.length > 1 ? path32.join(cwd, ...parts.slice(0, -1)) : cwd;
24567
24744
  const actual = probeCaseInsensitive(dir, base);
24568
24745
  if (actual)
24569
24746
  return [...parts.slice(0, -1), actual].join("/");
24570
24747
  }
24571
24748
  for (const rel of PR_TEMPLATE_DIRS) {
24572
- const only = singleMarkdown(path31.join(cwd, ...rel.split("/")));
24749
+ const only = singleMarkdown(path32.join(cwd, ...rel.split("/")));
24573
24750
  if (only)
24574
24751
  return `${rel}/${only}`;
24575
24752
  }
@@ -24599,7 +24776,7 @@ var diffStatForRange = (cwd, range) => {
24599
24776
  return runGit(cwd, ["diff", "--stat", "--"]).stdout;
24600
24777
  };
24601
24778
  var packageScripts = (cwd, keys) => {
24602
- const pkgPath = path31.join(cwd, "package.json");
24779
+ const pkgPath = path32.join(cwd, "package.json");
24603
24780
  if (!existsSync13(pkgPath))
24604
24781
  return [];
24605
24782
  try {
@@ -24625,9 +24802,9 @@ var documentationFiles = (cwd) => {
24625
24802
  if (entry.isDirectory()) {
24626
24803
  if (excluded.has(entry.name))
24627
24804
  continue;
24628
- walk(path31.join(dir, entry.name), depth + 1);
24805
+ walk(path32.join(dir, entry.name), depth + 1);
24629
24806
  } else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
24630
- matches.push("./" + path31.relative(cwd, path31.join(dir, entry.name)).replaceAll("\\", "/"));
24807
+ matches.push("./" + path32.relative(cwd, path32.join(dir, entry.name)).replaceAll("\\", "/"));
24631
24808
  }
24632
24809
  }
24633
24810
  };
@@ -24643,7 +24820,7 @@ var readTrimmed2 = (file, maxLines) => {
24643
24820
  `);
24644
24821
  };
24645
24822
  function prReadyContext(root, range) {
24646
- const cwd = path31.resolve(repoRoot(root));
24823
+ const cwd = path32.resolve(repoRoot(root));
24647
24824
  if (range !== undefined && !isResolvableContextRange(cwd, range))
24648
24825
  return invalidRange(cwd);
24649
24826
  let stdout = "";
@@ -24701,7 +24878,7 @@ ${status.stderr}` : "");
24701
24878
  stdout += `template_path: ${template}
24702
24879
 
24703
24880
  `;
24704
- stdout += readTrimmed2(path31.join(cwd, template), 220);
24881
+ stdout += readTrimmed2(path32.join(cwd, template), 220);
24705
24882
  } else {
24706
24883
  stdout += `template_path: none
24707
24884
 
@@ -24711,7 +24888,7 @@ ${status.stderr}` : "");
24711
24888
  stdout += `
24712
24889
  `;
24713
24890
  stdout += printSection("Recent Validation Signals");
24714
- if (existsSync13(path31.join(cwd, "package.json"))) {
24891
+ if (existsSync13(path32.join(cwd, "package.json"))) {
24715
24892
  stdout += `package.json detected. Common scripts:
24716
24893
  `;
24717
24894
  const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
@@ -24720,7 +24897,7 @@ ${status.stderr}` : "");
24720
24897
  `) + `
24721
24898
  `;
24722
24899
  }
24723
- if (existsSync13(path31.join(cwd, "Cargo.toml")) || existsSync13(path31.join(cwd, "src-tauri/Cargo.toml"))) {
24900
+ if (existsSync13(path32.join(cwd, "Cargo.toml")) || existsSync13(path32.join(cwd, "src-tauri/Cargo.toml"))) {
24724
24901
  stdout += `Rust project detected.
24725
24902
  `;
24726
24903
  }
@@ -24753,7 +24930,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
24753
24930
  - Apply with the host-native editor, preserving the repository changelog conventions.
24754
24931
  - If Unreleased already has duplicate category headings, normalize_only first.`;
24755
24932
  function changelogContext(root, range) {
24756
- const cwd = path31.resolve(repoRoot(root));
24933
+ const cwd = path32.resolve(repoRoot(root));
24757
24934
  if (range !== undefined && !isResolvableContextRange(cwd, range))
24758
24935
  return invalidRange(cwd);
24759
24936
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -24771,7 +24948,7 @@ function changelogContext(root, range) {
24771
24948
  stdout += CHANGELOG_RULES + `
24772
24949
  `;
24773
24950
  stdout += printSection("Existing CHANGELOG.md");
24774
- const changelogPath = path31.join(cwd, "CHANGELOG.md");
24951
+ const changelogPath = path32.join(cwd, "CHANGELOG.md");
24775
24952
  if (existsSync13(changelogPath)) {
24776
24953
  stdout += readTrimmed2(changelogPath, 260) + `
24777
24954
  `;
@@ -24791,7 +24968,7 @@ function changelogContext(root, range) {
24791
24968
  return { stdout, stderr: "", exitCode: 0, cwd };
24792
24969
  }
24793
24970
  function docsRefreshContext(root, range) {
24794
- const cwd = path31.resolve(repoRoot(root));
24971
+ const cwd = path32.resolve(repoRoot(root));
24795
24972
  if (range !== undefined && !isResolvableContextRange(cwd, range))
24796
24973
  return invalidRange(cwd);
24797
24974
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -24813,7 +24990,7 @@ function docsRefreshContext(root, range) {
24813
24990
  `) + `
24814
24991
  `;
24815
24992
  stdout += printSection("README Preview");
24816
- const readme = path31.join(cwd, "README.md");
24993
+ const readme = path32.join(cwd, "README.md");
24817
24994
  if (existsSync13(readme)) {
24818
24995
  stdout += readTrimmed2(readme, 220) + `
24819
24996
  `;
@@ -24822,7 +24999,7 @@ function docsRefreshContext(root, range) {
24822
24999
  `;
24823
25000
  }
24824
25001
  stdout += printSection("Package Scripts");
24825
- const pkgPath = path31.join(cwd, "package.json");
25002
+ const pkgPath = path32.join(cwd, "package.json");
24826
25003
  if (existsSync13(pkgPath)) {
24827
25004
  try {
24828
25005
  const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
@@ -24836,7 +25013,7 @@ function docsRefreshContext(root, range) {
24836
25013
  return { stdout, stderr: "", exitCode: 0, cwd };
24837
25014
  }
24838
25015
  function releaseNotesContext(root, rangeOrTag) {
24839
- const cwd = path31.resolve(repoRoot(root));
25016
+ const cwd = path32.resolve(repoRoot(root));
24840
25017
  if (!rangeOrTag) {
24841
25018
  return {
24842
25019
  stdout: "",
@@ -24879,7 +25056,7 @@ function releaseNotesContext(root, rangeOrTag) {
24879
25056
  `;
24880
25057
  stdout += printSection("Existing Release Files");
24881
25058
  for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
24882
- if (existsSync13(path31.join(cwd, rel)))
25059
+ if (existsSync13(path32.join(cwd, rel)))
24883
25060
  stdout += rel + `
24884
25061
  `;
24885
25062
  }
@@ -24907,12 +25084,12 @@ function releaseNotesContext(root, rangeOrTag) {
24907
25084
  }
24908
25085
 
24909
25086
  // packages/workit-core/src/core/tracker-issues.ts
24910
- import { spawnSync as spawnSync20 } from "node:child_process";
25087
+ import { spawnSync as spawnSync21 } from "node:child_process";
24911
25088
 
24912
25089
  // packages/workit-core/src/core/pr-create.ts
24913
- import fs21 from "node:fs";
24914
- import path32 from "node:path";
24915
- import { spawnSync as spawnSync19 } from "node:child_process";
25090
+ import fs22 from "node:fs";
25091
+ import path33 from "node:path";
25092
+ import { spawnSync as spawnSync20 } from "node:child_process";
24916
25093
  import { pathToFileURL } from "node:url";
24917
25094
  // packages/workit-core/src/forge/pr-body.ts
24918
25095
  function parseGhIssue(value) {
@@ -24932,13 +25109,13 @@ var LOCAL = bounded(20000);
24932
25109
  var NETWORK = bounded(60000);
24933
25110
  function whichOnPath(tool) {
24934
25111
  const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
24935
- for (const dir of (process.env.PATH ?? "").split(path32.delimiter)) {
25112
+ for (const dir of (process.env.PATH ?? "").split(path33.delimiter)) {
24936
25113
  if (!dir)
24937
25114
  continue;
24938
25115
  for (const name of names) {
24939
- const candidate = path32.join(dir, name);
25116
+ const candidate = path33.join(dir, name);
24940
25117
  try {
24941
- fs21.accessSync(candidate, fs21.constants.X_OK);
25118
+ fs22.accessSync(candidate, fs22.constants.X_OK);
24942
25119
  return candidate;
24943
25120
  } catch {}
24944
25121
  }
@@ -24947,7 +25124,7 @@ function whichOnPath(tool) {
24947
25124
  }
24948
25125
  var hostingCliAvailable = (provider) => whichOnPath(provider === "gitlab" ? "glab" : "gh") !== null;
24949
25126
  var pushRemote = (cwd) => {
24950
- const result = spawnSync19("git", ["remote", "get-url", "--push", "--all", "origin"], {
25127
+ const result = spawnSync20("git", ["remote", "get-url", "--push", "--all", "origin"], {
24951
25128
  cwd,
24952
25129
  ...LOCAL
24953
25130
  });
@@ -24958,7 +25135,7 @@ var pushRemote = (cwd) => {
24958
25135
  };
24959
25136
  var safePushUrl = (remote) => {
24960
25137
  const raw = remote.trim();
24961
- if (path32.isAbsolute(raw))
25138
+ if (path33.isAbsolute(raw))
24962
25139
  return pathToFileURL(raw).href;
24963
25140
  if (!raw.includes("://")) {
24964
25141
  const scp = /^(?:([^@\s]+)@)?([^:]+):(.+)$/u.exec(raw);
@@ -24983,7 +25160,7 @@ var pushTargetIsStable = (cwd, remote) => {
24983
25160
  const target = safePushUrl(remote);
24984
25161
  if (!target)
24985
25162
  return false;
24986
- const result = spawnSync19("git", ["config", "--get-regexp", "^url\\..*\\.(insteadof|pushinsteadof)$"], { cwd, ...LOCAL });
25163
+ const result = spawnSync20("git", ["config", "--get-regexp", "^url\\..*\\.(insteadof|pushinsteadof)$"], { cwd, ...LOCAL });
24987
25164
  if (result.status !== 0 && result.status !== 1)
24988
25165
  return false;
24989
25166
  const prefixes = (result.stdout ?? "").split(/\r?\n/u).map((line) => line.trim().slice(line.trim().indexOf(" ") + 1)).filter(Boolean);
@@ -25011,7 +25188,7 @@ var defaultCli = (bin, available) => {
25011
25188
  if (!available)
25012
25189
  return null;
25013
25190
  return (args, root) => {
25014
- const out = spawnSync20(bin, args, {
25191
+ const out = spawnSync21(bin, args, {
25015
25192
  cwd: root,
25016
25193
  encoding: "utf8",
25017
25194
  env: { ...process.env, PATH: process.env.PATH ?? "" }
@@ -25100,149 +25277,6 @@ var PLUGIN_ROOT = packageRoot();
25100
25277
  var ASSET_ROOT = assetRoot();
25101
25278
  var resolveWorkspaceRoot = (explicit) => explicit || process.cwd();
25102
25279
 
25103
- // packages/workit-core/src/core/youtrack-ytrack.ts
25104
- import { spawnSync as spawnSync21 } from "node:child_process";
25105
-
25106
- // packages/workit-core/src/forge/exec.ts
25107
- import fs22 from "node:fs";
25108
- import path33 from "node:path";
25109
-
25110
- // packages/workit-core/src/forge/redact.ts
25111
- var KEY = String.raw`[A-Za-z0-9_.-]*?(?:token|secret|password|passwd|pwd|api[_-]?key|access[_-]?key|account[_-]?key|private[_-]?key|client[_-]?secret|credentials?|authorization|cookie|signature)[A-Za-z0-9_.-]*`;
25112
- var ASSIGNMENT2 = new RegExp(String.raw`(?<![A-Za-z0-9])(["']?${KEY}["']?\s*[:=]\s*["']?)((?:bearer|basic|token|digest)\s+)?([^\s"',;&]+)`, "giu");
25113
- var QUOTED_ASSIGNMENT = new RegExp(String.raw`(?<![A-Za-z0-9])(["']?${KEY}["']?\s*[:=]\s*)(["'])([^"'\n]*[^\s"'][^"'\n]*)\2`, "giu");
25114
- var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007`, "gu");
25115
-
25116
- // packages/workit-core/src/forge/types.ts
25117
- var success2 = (data) => ({ ok: true, data });
25118
- var failure3 = (code, error, unblock) => ({ ok: false, code, error, ...unblock ? { unblock } : {} });
25119
-
25120
- // packages/workit-core/src/forge/exec.ts
25121
- var MAX_BUFFER2 = 64 * 1024 * 1024;
25122
- function findExecutable(bin, env) {
25123
- const dirs = (env.PATH ?? env.Path ?? "").split(path33.delimiter).filter(Boolean);
25124
- const exts = process.platform === "win32" ? [".exe"] : [""];
25125
- for (const dir of dirs)
25126
- for (const ext of exts) {
25127
- const candidate = path33.join(dir, `${bin}${ext}`);
25128
- try {
25129
- const stat = fs22.statSync(candidate);
25130
- if (stat.isFile())
25131
- return candidate;
25132
- } catch {}
25133
- }
25134
- return null;
25135
- }
25136
-
25137
- // packages/workit-core/src/core/youtrack-ytrack.ts
25138
- var TIMEOUT_MS = 60000;
25139
- var YTRACK_EXIT = { ok: 0, failed: 1, cancelled: 2, auth: 4 };
25140
- var findYtrack = (env) => env.WORKIT_NO_YTRACK === "1" ? null : findExecutable("ytrack", env);
25141
- var YTRACK_QUIET_ENV = {
25142
- YTRACK_NO_UPDATE_NOTIFIER: "1",
25143
- YTRACK_NO_AUTO_UPGRADE: "1"
25144
- };
25145
- function ytrackRunner(env, host, timeoutMs = TIMEOUT_MS) {
25146
- return (args, input) => {
25147
- const exe = findYtrack(env);
25148
- if (!exe)
25149
- return { status: null, stdout: "", stderr: "", missing: true };
25150
- const result = spawnSync21(exe, args, {
25151
- encoding: "utf8",
25152
- env: {
25153
- ...env,
25154
- NO_COLOR: "1",
25155
- ...YTRACK_QUIET_ENV,
25156
- ...host ? { YTRACK_HOST: host } : {}
25157
- },
25158
- timeout: timeoutMs,
25159
- killSignal: "SIGKILL",
25160
- windowsHide: true,
25161
- ...input === undefined ? { stdio: ["ignore", "pipe", "pipe"] } : { input, stdio: ["pipe", "pipe", "pipe"] }
25162
- });
25163
- const error = result.error;
25164
- if (error?.code === "ENOENT")
25165
- return { status: null, stdout: "", stderr: "", missing: true };
25166
- return {
25167
- status: result.status,
25168
- stdout: result.stdout ?? "",
25169
- stderr: result.stderr || (error ? error.message : "")
25170
- };
25171
- };
25172
- }
25173
- var ytrackDetail = (out) => out.stderr.trim().split(`
25174
- `).slice(-3).join(" ").slice(0, 300);
25175
- var STATUS_FIELDS = "host,active,login,state,tokenSource,error";
25176
- function ytrackStatus(run) {
25177
- const version = run(["version"]);
25178
- if (version.missing)
25179
- return { installed: false };
25180
- const match = /ytrack version (\S+)/u.exec(version.stdout);
25181
- const status = run(["auth", "status", "--json", STATUS_FIELDS]);
25182
- const base = { installed: true, version: match ? match[1] : null };
25183
- if (status.status === YTRACK_EXIT.auth)
25184
- return { ...base, auth: "logged_out", hosts: [], error: ytrackDetail(status) || null };
25185
- let rows;
25186
- try {
25187
- rows = JSON.parse(status.stdout);
25188
- } catch {
25189
- return { ...base, auth: "error", hosts: [], error: ytrackDetail(status) || "no JSON" };
25190
- }
25191
- const hosts = (Array.isArray(rows) ? rows : [rows]).filter((row) => typeof row === "object" && row !== null).map((row) => ({
25192
- host: String(row.host ?? ""),
25193
- active: row.active === true,
25194
- login: typeof row.login === "string" && row.login ? row.login : null,
25195
- state: String(row.state ?? "error"),
25196
- tokenSource: typeof row.tokenSource === "string" && row.tokenSource ? row.tokenSource : null,
25197
- error: typeof row.error === "string" && row.error ? row.error : null
25198
- }));
25199
- const active = hosts.find((row) => row.active) ?? hosts[0];
25200
- return { ...base, auth: rowAuth(active), hosts, error: null };
25201
- }
25202
- var rowAuth = (row) => !row ? "logged_out" : row.state === "ok" ? "ok" : row.state === "rejected" ? "rejected" : row.state === "no_token" ? "logged_out" : "error";
25203
- var ytrackHostName = (urlOrHost) => urlOrHost.trim().replace(/^[a-z][a-z0-9+.-]*:\/\//iu, "").split("/")[0].toLowerCase();
25204
- function ytrackHostAuth(status, host) {
25205
- if (!host) {
25206
- const active = status.hosts.find((row) => row.active) ?? status.hosts[0];
25207
- return {
25208
- auth: status.auth,
25209
- login: active?.login ?? null,
25210
- error: active?.error ?? status.error
25211
- };
25212
- }
25213
- const name = ytrackHostName(host);
25214
- const row = status.hosts.find((candidate) => ytrackHostName(candidate.host) === name);
25215
- return {
25216
- auth: status.auth === "error" && !row ? "error" : rowAuth(row),
25217
- login: row?.login ?? null,
25218
- error: row?.error ?? status.error
25219
- };
25220
- }
25221
- var YTRACK_INSTALL = "install ytrack (https://github.com/BrainerVirus/youtrack-cli: install.sh, or install.ps1 on Windows)";
25222
- var ytrackLogin = (host) => `ytrack auth login${host ? ` --host ${ytrackHostName(host)}` : ""}`;
25223
- var ytrackMissingUnblock = (host) => `${YTRACK_INSTALL}, then ${ytrackLogin(host)}`;
25224
- var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only through ytrack";
25225
- function ytrackReadiness(run, host) {
25226
- const status = ytrackStatus(run);
25227
- if (!status.installed)
25228
- return {
25229
- ok: false,
25230
- reason: "missing",
25231
- error: YTRACK_MISSING,
25232
- unblock: ytrackMissingUnblock(host)
25233
- };
25234
- const auth = ytrackHostAuth(status, host);
25235
- const where = host ? ytrackHostName(host) : "the active host";
25236
- if (auth.auth === "ok")
25237
- return { ok: true, version: status.version, login: auth.login };
25238
- return {
25239
- ok: false,
25240
- reason: auth.auth,
25241
- error: auth.auth === "logged_out" ? `ytrack is not logged in to ${where}` : auth.auth === "rejected" ? `${where} rejected ytrack's stored token` : `could not read ytrack's login for ${where}${auth.error ? ` (${auth.error})` : ""}`,
25242
- unblock: ytrackLogin(host)
25243
- };
25244
- }
25245
-
25246
25280
  // packages/workit-core/src/core/youtrack.ts
25247
25281
  var ISSUE_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
25248
25282
  var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path34.join(resolveConfigDir(), "youtrack.json");
@@ -30444,6 +30478,29 @@ var judge = (args, words) => {
30444
30478
  return mapIssueWrite("attach", args);
30445
30479
  return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
30446
30480
  };
30481
+ var hostsOf = (args) => {
30482
+ const end = args.indexOf("--");
30483
+ const hosts = [];
30484
+ const bare = [];
30485
+ let literal = true;
30486
+ let named = false;
30487
+ for (let at = 0;at < args.length; at++) {
30488
+ const arg = args[at];
30489
+ if (end >= 0 && at >= end || !/^--host(?:=|$)/.test(arg)) {
30490
+ bare.push(arg);
30491
+ continue;
30492
+ }
30493
+ named ||= standsAlone(args, at);
30494
+ const value = arg === "--host" ? args[++at] : arg.slice("--host=".length);
30495
+ if (value === undefined || !value.trim() || EXPANDS.test(value))
30496
+ literal = false;
30497
+ else
30498
+ hosts.push(value);
30499
+ }
30500
+ if (!literal)
30501
+ return { hosts: null, bare };
30502
+ return named ? { hosts, bare } : { hosts: [], bare: [...args] };
30503
+ };
30447
30504
  var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
30448
30505
  var MAX_DEPTH2 = 4;
30449
30506
  var READ = new Map;
@@ -30451,10 +30508,19 @@ var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wra
30451
30508
  var timeOnly = (effect) => effect?.minutes !== undefined && Object.keys(effect).every((key) => /^(?:issue|minutes|text|date)$/u.test(key));
30452
30509
  var ungrant = (write) => write.workit ? {
30453
30510
  command: write.command,
30511
+ hosts: write.hosts,
30512
+ bare: write.bare,
30513
+ plain: write.plain,
30454
30514
  ...NOT_PLAIN,
30455
30515
  ...timeOnly(write.effect) ? { hint: write.workit } : {}
30456
30516
  } : write;
30457
- var hinted = (write) => write.hint ? { command: write.command, workit: write.hint } : write;
30517
+ var hinted = (write) => write.hint ? {
30518
+ command: write.command,
30519
+ hosts: write.hosts,
30520
+ bare: write.bare,
30521
+ plain: false,
30522
+ workit: write.hint
30523
+ } : write;
30458
30524
  var ytrackArgs = (line, found, depth, names, plain) => {
30459
30525
  const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
30460
30526
  const tail = workitCheckTail(line);
@@ -30489,7 +30555,12 @@ var ytrackArgs = (line, found, depth, names, plain) => {
30489
30555
  const argv = [...alias ?? [], ...line.slice(at + 1)];
30490
30556
  const write = classify2(argv);
30491
30557
  if (write) {
30492
- const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
30558
+ const one = {
30559
+ command: ["ytrack", ...argv].map(quote2).join(" "),
30560
+ ...write,
30561
+ ...hostsOf(argv),
30562
+ plain
30563
+ };
30493
30564
  found.push(plain ? one : ungrant(one));
30494
30565
  }
30495
30566
  return true;
@@ -30566,7 +30637,15 @@ var chained = (first, chain, depth) => {
30566
30637
  const effect = combine(effects);
30567
30638
  if (!effect)
30568
30639
  return null;
30569
- return [{ command: found.map((write) => write.command).join(" && "), ...mapped(effect) }];
30640
+ const hosts = found.map((write) => write.hosts);
30641
+ return [
30642
+ {
30643
+ command: found.map((write) => write.command).join(" && "),
30644
+ ...mapped(effect),
30645
+ hosts: hosts.includes(null) ? null : hosts.some((list) => !list?.length) ? [] : hosts.flatMap((list) => list ?? []),
30646
+ plain: true
30647
+ }
30648
+ ];
30570
30649
  };
30571
30650
  var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
30572
30651
  if (!namesYtrack(command))
@@ -30595,6 +30674,32 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
30595
30674
  READ.delete(READ.keys().next().value);
30596
30675
  return found;
30597
30676
  };
30677
+ var RELOCATES = /(?<![$\w])YTRACK_CONFIG_DIR\b/;
30678
+ var reachesOnly = (allowed, write) => write.plain && !!write.hosts?.length && write.hosts.every((host) => youTrackHostAllowed(allowed, host));
30679
+ var scopedGate = (allowed, command, writes) => {
30680
+ const scope = `youtrack.autoHosts (${allowed.join(", ")})`;
30681
+ if (RELOCATES.test(command))
30682
+ return {
30683
+ kind: "deny",
30684
+ reason: `This command sets YTRACK_CONFIG_DIR, where ytrack reads its hosts, so a --host may reach another instance: ${scope} lets a YouTrack write through only with ytrack's own config. Run the ytrack call without it.`,
30685
+ unblock: null
30686
+ };
30687
+ const first = allowed.map(youTrackHostKey).find(Boolean);
30688
+ if (!first)
30689
+ return null;
30690
+ const unnamed = writes.filter((write) => !reachesOnly(allowed, write) && (!write.hosts?.length || write.hosts.every((host) => youTrackHostAllowed(allowed, host))));
30691
+ if (!unnamed.length)
30692
+ return null;
30693
+ 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";
30694
+ const bare = unnamed.find((write) => write.bare)?.bare;
30695
+ const retry = bare ? ["ytrack", "--host", first, ...bare].map(quote2).join(" ") : null;
30696
+ return {
30697
+ kind: "deny",
30698
+ 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 ? `
30699
+ Retry as: ${retry}` : ""}`,
30700
+ unblock: retry
30701
+ };
30702
+ };
30598
30703
  var ytrackGate = (cwd, command, dialect, ask) => {
30599
30704
  if (namesTicket(command))
30600
30705
  return { kind: "deny", reason: TICKET_DENY, unblock: null };
@@ -30607,7 +30712,8 @@ var ytrackGate = (cwd, command, dialect, ask) => {
30607
30712
  }
30608
30713
  writes = [...merged.values()];
30609
30714
  } catch {
30610
- if (youTrackWritesMode(cwd) === "auto")
30715
+ const policy = youTrackWritesPolicy(cwd);
30716
+ if (policy.mode === "auto" && policy.hosts === null)
30611
30717
  return null;
30612
30718
  return {
30613
30719
  kind: "deny",
@@ -30615,7 +30721,19 @@ var ytrackGate = (cwd, command, dialect, ask) => {
30615
30721
  unblock: null
30616
30722
  };
30617
30723
  }
30618
- if (!writes.length || youTrackWritesMode(cwd) === "auto")
30724
+ if (!writes.length && !RELOCATES.test(command))
30725
+ return null;
30726
+ const policy = youTrackWritesPolicy(cwd);
30727
+ if (policy.mode === "auto") {
30728
+ const hosts = policy.hosts;
30729
+ if (hosts === null)
30730
+ return null;
30731
+ const scoped = scopedGate(hosts, command, writes);
30732
+ if (scoped)
30733
+ return scoped;
30734
+ writes = writes.filter((write) => !reachesOnly(hosts, write));
30735
+ }
30736
+ if (!writes.length)
30619
30737
  return null;
30620
30738
  const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
30621
30739
  const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "2.20.6",
3
+ "version": "2.21.0",
4
4
  "private": false,
5
5
  "description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@opencode/plugin": "2.0.18",
44
- "@workit-dev/core": "^2.20.6"
44
+ "@workit-dev/core": "^2.21.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"