@workit-dev/opencode 1.8.2 → 1.9.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 +311 -1
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -28483,11 +28483,318 @@ var SCAN_MS = 30 * 60000;
28483
28483
  // packages/workit-core/src/hooks/agent-model.ts
28484
28484
  var UNLISTED = new Set(["description", "prompt"]);
28485
28485
 
28486
+ // packages/workit-core/src/hooks/ytrack-word.ts
28487
+ var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
28488
+ var namesYtrack = (text) => {
28489
+ const bare = text.replace(/['"\\]/g, "");
28490
+ return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
28491
+ };
28492
+
28493
+ // packages/workit-core/src/hooks/ytrack-guard.ts
28494
+ var name2 = (word = "") => (word.split(/[\\/]/).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd)$|@.*$/g, "");
28495
+ var quote2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
28496
+ var minutesOf = (text = "") => {
28497
+ if (/^\d+$/.test(text.trim()))
28498
+ return Number(text) > 0 ? Number(text) : null;
28499
+ let total = 0;
28500
+ const rest = text.replace(/(\d+(?:\.\d+)?)\s*(h|hours?|m|mins?|minutes?)(?![a-z])/gi, (_, n, unit) => {
28501
+ total += Number(n) * (/^h/i.test(unit) ? 60 : 1);
28502
+ return "";
28503
+ });
28504
+ return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
28505
+ };
28506
+ var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
28507
+ var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
28508
+ var standsAlone = (args, at) => {
28509
+ const before = args[at - 1] ?? "";
28510
+ const end = args.indexOf("--");
28511
+ return (end < 0 || at < end) && (!before.startsWith("-") || before.includes("=") || BARE.has(before));
28512
+ };
28513
+ var flagged = (args, flag) => args.some((arg, at) => flag.test(arg) && standsAlone(args, at));
28514
+ var asksHelp2 = (args) => flagged(args, /^(?:--help|-h)$/);
28515
+ var GROUPS = {
28516
+ issue: "issue",
28517
+ "work-item": "work-item",
28518
+ workitem: "work-item",
28519
+ api: "api"
28520
+ };
28521
+ var ASKS = /^(?:post|put|patch|delete)$/i;
28522
+ var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
28523
+ var QUIET = /^--(?:debug|no-color|json|jq)$/;
28524
+ var CARRIES = {
28525
+ note: { "--body": "body", "-b": "body", "--body-file": "file" },
28526
+ time: { "--duration": "duration", "--text": "text", "--date": "date" },
28527
+ create: {
28528
+ "--project": "project",
28529
+ "-p": "project",
28530
+ "--summary": "summary",
28531
+ "-s": "summary",
28532
+ "--description": "description",
28533
+ "--description-file": "file"
28534
+ }
28535
+ };
28536
+ var gap = (part) => ({ workit: null, gap: part });
28537
+ var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
28538
+ var mapWrite = (verb, args) => {
28539
+ const values = {};
28540
+ const operands = [];
28541
+ for (let at = 0;at < args.length; at++) {
28542
+ const arg = args[at];
28543
+ if (!arg.startsWith("-") || arg === "-") {
28544
+ operands.push(arg);
28545
+ continue;
28546
+ }
28547
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
28548
+ const flag = eq > 0 ? arg.slice(0, eq) : arg;
28549
+ const value = eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
28550
+ if (QUIET.test(flag))
28551
+ continue;
28552
+ const key = CARRIES[verb][flag];
28553
+ if (!key || value === undefined || key in values)
28554
+ return gap(`\`${flag}\``);
28555
+ if (/[$`]|^~/.test(value))
28556
+ return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
28557
+ values[key] = value;
28558
+ }
28559
+ const [issue, ...more] = operands.slice(2);
28560
+ const v = values;
28561
+ if (verb === "create") {
28562
+ if (issue !== undefined)
28563
+ return gap(`the operand \`${issue}\``);
28564
+ if (v.project === undefined || v.summary === undefined)
28565
+ return gap("a missing --project or --summary");
28566
+ if (v.description !== undefined && v.file !== undefined)
28567
+ return gap("both --description and --description-file");
28568
+ if (v.file === "-")
28569
+ return gap("text read from standard input");
28570
+ return {
28571
+ workit: [
28572
+ "workit youtrack create",
28573
+ pair("--project", v.project),
28574
+ pair("--summary", v.summary),
28575
+ v.description === undefined ? "" : pair("--description", v.description),
28576
+ v.file === undefined ? "" : pair("--file", v.file)
28577
+ ].filter(Boolean).join(" ")
28578
+ };
28579
+ }
28580
+ if (issue === undefined || more.length || !/^[A-Z]+-\d+$/.test(issue))
28581
+ return gap("the issue, which must be one id like ABC-123");
28582
+ if (verb === "note") {
28583
+ if (v.body === undefined === (v.file === undefined))
28584
+ return gap("a comment that needs exactly one of --body or --body-file");
28585
+ if (v.file === "-")
28586
+ return gap("text read from standard input");
28587
+ if (v.body !== undefined && !v.body.trim())
28588
+ return gap("an empty --body");
28589
+ return {
28590
+ workit: `workit youtrack note ${issue} ${v.body === undefined ? pair("--file", v.file) : pair("--markdown", v.body)}`
28591
+ };
28592
+ }
28593
+ const minutes = minutesOf(v.duration);
28594
+ if (minutes === null)
28595
+ return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
28596
+ if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
28597
+ return gap(`\`--date ${v.date}\``);
28598
+ return {
28599
+ workit: [
28600
+ `workit youtrack time ${issue} --minutes ${minutes}`,
28601
+ v.text === undefined ? "" : pair("--text", v.text),
28602
+ v.date === undefined ? "" : pair("--date", v.date)
28603
+ ].filter(Boolean).join(" ")
28604
+ };
28605
+ };
28606
+ var UNCOVERED = { workit: null, gap: "" };
28607
+ var classify2 = (args) => {
28608
+ if (asksHelp2(args))
28609
+ return null;
28610
+ const lenient = args.filter((arg, at) => !arg.startsWith("-") && !VALUE.has(args[at - 1] ?? ""));
28611
+ const strict = args.filter((arg, at) => !arg.startsWith("-") && standsAlone(args, at));
28612
+ return judge(args, lenient) ?? judge(args, strict);
28613
+ };
28614
+ var judge = (args, words) => {
28615
+ const group = GROUPS[words[0] ?? ""];
28616
+ const verb = words[1] ?? "";
28617
+ if (group === "api") {
28618
+ const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
28619
+ if (methods.some((method) => ASKS.test(method.value)))
28620
+ return UNCOVERED;
28621
+ if (methods.some((method) => method.alone))
28622
+ return null;
28623
+ return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
28624
+ }
28625
+ if (group === "work-item" && /^(?:add|create)$/.test(verb))
28626
+ return mapWrite("time", args);
28627
+ if (group === "work-item")
28628
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
28629
+ if (group !== "issue")
28630
+ return null;
28631
+ if (verb === "comment")
28632
+ return mapWrite("note", args);
28633
+ if (verb === "create")
28634
+ return mapWrite("create", args);
28635
+ if (verb === "command")
28636
+ return flagged(args, /^--dry-run$/) ? null : UNCOVERED;
28637
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
28638
+ };
28639
+ var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
28640
+ var MAX_DEPTH2 = 4;
28641
+ var READ = new Map;
28642
+ var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
28643
+ var ungrant = (write) => write.workit ? { command: write.command, ...NOT_PLAIN } : write;
28644
+ var ytrackArgs = (line, found, depth, names, plain) => {
28645
+ const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
28646
+ const tail = workitCheckTail(line);
28647
+ if (tail) {
28648
+ inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
28649
+ return true;
28650
+ }
28651
+ const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
28652
+ const script = flag > 0 ? line[flag + 1] : name2(line[0]) === "eval" ? line.slice(1).join(" ") : undefined;
28653
+ if (script !== undefined) {
28654
+ inner(script);
28655
+ return true;
28656
+ }
28657
+ let at = 0;
28658
+ let called = false;
28659
+ const runner = name2(line[0]);
28660
+ if (/^(?:npx|bunx|pnpx)$/.test(runner) || /^(?:p?npm|yarn)$/.test(runner) && /^(?:dlx|exec|x)$/.test(line[1] ?? "")) {
28661
+ at = runner.endsWith("x") ? 1 : 2;
28662
+ for (;line[at]?.startsWith("-"); at++) {
28663
+ if (/^(?:-c|--call)$/.test(line[at])) {
28664
+ inner(line[at + 1] ?? "");
28665
+ called = true;
28666
+ }
28667
+ if (/^(?:-[pc]|--package|--call)$/.test(line[at]))
28668
+ at++;
28669
+ }
28670
+ }
28671
+ const resolved = /^(?:\$\(|`)\s*(?:which|command\s+-v|type\s+-[pP])\s+ytrack\s*[)`]$/.test(line[at] ?? "");
28672
+ const alias = names.get(line[at] ?? "");
28673
+ if (name2(line[at]) !== "ytrack" && !resolved && !alias)
28674
+ return called;
28675
+ const argv = [...alias ?? [], ...line.slice(at + 1)];
28676
+ const write = classify2(argv);
28677
+ if (write) {
28678
+ const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
28679
+ found.push(plain ? one : ungrant(one));
28680
+ }
28681
+ return true;
28682
+ };
28683
+ var aliases = (command) => {
28684
+ const found = new Map;
28685
+ for (const [, alias, a, b, c] of command.matchAll(/\balias\s+([\w.-]+)=(?:'([^']*)'|"([^"]*)"|([^\s;&|)]+))/g)) {
28686
+ const value = a ?? b ?? c ?? "";
28687
+ if (/^(?:\S*\/)?ytrack(?:\s|$)/.test(value))
28688
+ found.set(alias, value.split(/\s+/).slice(1));
28689
+ }
28690
+ for (const [, a, b, body] of command.matchAll(/(?:\bfunction\s+([\w.-]+)(?:\s*\(\s*\))?|\b([\w.-]+)\s*\(\s*\))\s*\{([^}]*)\}/g))
28691
+ if (/(?:^|[\s;&|])(?:\S*\/)?ytrack\s/.test(body ?? ""))
28692
+ found.set(a ?? b ?? "", []);
28693
+ return found;
28694
+ };
28695
+ var PASS = /^(?:command|exec|nohup|setsid|time|nice|ionice|stdbuf|chronic|unbuffer|timeout)$/;
28696
+ var COMPOUND3 = /^(?:for|select|while|until|repeat|do|done|function|case|foreach|coproc)$/;
28697
+ var passed = (words) => {
28698
+ let at = 0;
28699
+ for (;at < words.length; at++) {
28700
+ const word = words[at];
28701
+ if (/^[A-Za-z_]\w*=/.test(word))
28702
+ return [];
28703
+ if (!PASS.test(word))
28704
+ break;
28705
+ if (/^(?:exec|command)$/.test(word) && words[at + 1]?.startsWith("-"))
28706
+ return [];
28707
+ while (/^(?:-|\d)/.test(words[at + 1] ?? ""))
28708
+ at++;
28709
+ }
28710
+ return words.slice(at);
28711
+ };
28712
+ var plainLines = (command, dialect) => {
28713
+ let first = null;
28714
+ const later = [];
28715
+ for (const segment of segmentsOf(command, dialect)) {
28716
+ if (segment.group || segment.unanalyzable || segment.subs?.length)
28717
+ return null;
28718
+ if (COMPOUND3.test(segment.words[0] ?? ""))
28719
+ return null;
28720
+ if (segment.words.some((word) => /^YTRACK_\w*=/.test(word)))
28721
+ return null;
28722
+ const names = namesYtrack([...segment.words, ...segment.stdin ?? []].join(" "));
28723
+ if (first === null) {
28724
+ if (!names || segment.expands?.length)
28725
+ return null;
28726
+ first = passed(segment.words);
28727
+ } else if (names)
28728
+ later.push(segment.words);
28729
+ }
28730
+ return first ? { first, later } : null;
28731
+ };
28732
+ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
28733
+ if (!namesYtrack(command))
28734
+ return [];
28735
+ if (depth > MAX_DEPTH2)
28736
+ throw new Error("ytrack nested too deep");
28737
+ const key = `${plain}\x00${dialect}\x00${command}`;
28738
+ const known = READ.get(key);
28739
+ if (known)
28740
+ return known;
28741
+ let found = [];
28742
+ const lines = plain ? plainLines(command, dialect) : null;
28743
+ const none = new Map;
28744
+ if (!lines || !ytrackArgs(lines.first, found, depth, none, true) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
28745
+ found = [];
28746
+ for (const line of commandLines(command, dialect))
28747
+ ytrackArgs(line, found, depth, aliases(command), false);
28748
+ }
28749
+ READ.set(key, found);
28750
+ if (READ.size > 64)
28751
+ READ.delete(READ.keys().next().value);
28752
+ return found;
28753
+ };
28754
+ var writesMode = (cwd) => resolveRuntimeWorkspaceVcs(cwd)?.youtrack?.writes;
28755
+ var ytrackGate = (cwd, command, dialect, ask) => {
28756
+ let writes;
28757
+ try {
28758
+ const merged = new Map;
28759
+ for (const write of ytrackWrites(command, dialect)) {
28760
+ const seen = merged.get(write.command);
28761
+ merged.set(write.command, !seen || !write.workit ? write : !seen.workit ? seen : ungrant(write));
28762
+ }
28763
+ writes = [...merged.values()];
28764
+ } catch {
28765
+ if (writesMode(cwd) === "auto")
28766
+ return null;
28767
+ return {
28768
+ kind: "deny",
28769
+ reason: `Workit could not analyse this command, which names ytrack: run each ytrack call as its own plain command so a YouTrack write can ask the user first (#780).`,
28770
+ unblock: null
28771
+ };
28772
+ }
28773
+ if (!writes.length || writesMode(cwd) === "auto")
28774
+ return null;
28775
+ const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
28776
+ 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"})`);
28777
+ if (!calls.length && ask)
28778
+ return {
28779
+ kind: "ask",
28780
+ reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
28781
+ };
28782
+ const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
28783
+ const run = calls.length ? ` Run ${calls.join(", then ")} instead: it asks the user first. When it answers approval_needed, run exactly the \`workit approve <id>\` it names, now, with nothing around it (no 2>&1, pipe or echo), so the host asks the user; then rerun the workit call once.` : "";
28784
+ const user = bare.length ? ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
28785
+ const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
28786
+ return {
28787
+ kind: "deny",
28788
+ reason: `${why}${run}${user}${rerun}`,
28789
+ unblock: writes[0]?.workit ?? null
28790
+ };
28791
+ };
28792
+
28486
28793
  // packages/workit-core/src/hooks/handle.ts
28487
28794
  var offered = new Set;
28488
28795
  var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
28489
28796
  // packages/workit-core/src/hooks/deadline.ts
28490
- var QUIET = new Set([
28797
+ var QUIET2 = new Set([
28491
28798
  "stop",
28492
28799
  "subagent.stop",
28493
28800
  "shell.post",
@@ -30630,6 +30937,9 @@ var evaluateShellPermission = (root, event, workdirs = new Map) => {
30630
30937
  const decision = shellPolicy(cwd, resource, "posix");
30631
30938
  if (decision.kind === "deny")
30632
30939
  return deny(decision.reason);
30940
+ const ytrack = ytrackGate(cwd, resource, "posix", false);
30941
+ if (ytrack?.kind === "deny")
30942
+ return deny(ytrack.reason);
30633
30943
  const raw = rawGitPre({
30634
30944
  host: "opencode",
30635
30945
  cwd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "1.8.2",
3
+ "version": "1.9.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": "^1.8.2"
44
+ "@workit-dev/core": "^1.9.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"