@workit-dev/opencode 1.6.0 → 1.7.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 +114 -2
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -10061,7 +10061,8 @@ var workspaceConfigSchema = object({
10061
10061
  ]))).passthrough().optional().describe("Autonomy grants (D15): only ever set here, by the user, with `workit grant set`."),
10062
10062
  youtrack: object({
10063
10063
  baseUrl: nonBlank.optional().describe("This workspace's YouTrack URL."),
10064
- link_issues: boolean2().optional().describe("Legacy alias of `issues: { provider: youtrack, link: true }`.")
10064
+ link_issues: boolean2().optional().describe("Legacy alias of `issues: { provider: youtrack, link: true }`."),
10065
+ 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.")
10065
10066
  }).passthrough().optional().describe("YouTrack settings for this workspace."),
10066
10067
  issues: object({
10067
10068
  provider: _enum(["github", "gitlab", "youtrack"]).optional().describe("The issue tracker PRs link to."),
@@ -20715,7 +20716,10 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
20715
20716
  continue;
20716
20717
  const action = rawAction(invocation);
20717
20718
  const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
20718
- repo: { dir: path27.resolve(cwd, invocation.dir ?? "."), branch: null },
20719
+ repo: {
20720
+ dir: path27.resolve(cwd, invocation.dir ?? "."),
20721
+ branch: null
20722
+ },
20719
20723
  workit: false
20720
20724
  } : null);
20721
20725
  if (action && at)
@@ -20762,6 +20766,109 @@ var pkillSelfMatch = (command, dialect) => {
20762
20766
  }
20763
20767
  return null;
20764
20768
  };
20769
+ var policyDeclared = () => {
20770
+ try {
20771
+ return !!readConfigTyped().config?.branchPolicy?.protected?.length;
20772
+ } catch {
20773
+ return false;
20774
+ }
20775
+ };
20776
+ var word = (text) => /^[\w./@%+:,=-]+$/u.test(text) ? text : shellQuote(text);
20777
+ var HEREDOC = /^cat <<(['"])(\w+)\1\n([\s\S]*)\n\2\n?$/u;
20778
+ var messageOf = (segment, index) => {
20779
+ const text = segment.words[index];
20780
+ if (text === undefined)
20781
+ return null;
20782
+ if (!segment.expands?.includes(index))
20783
+ return text;
20784
+ const sub = segment.subs?.find((each) => text === `$(${each})`);
20785
+ const match = sub === undefined ? null : HEREDOC.exec(sub);
20786
+ if (!match || match[3].split(`
20787
+ `).includes(match[2]))
20788
+ return null;
20789
+ return match[3].replace(/\n+$/u, "");
20790
+ };
20791
+ var cdCommitCall = (input, command, target, repo) => {
20792
+ const { top, git, dir: store } = repo.location;
20793
+ if (!top || !git || git.gitDir === path27.dirname(store) || repoAt(input.cwd)?.location.top === top)
20794
+ return null;
20795
+ const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
20796
+ if (/[;|&<>`$()\n\\]/u.test(bare))
20797
+ return null;
20798
+ const [cd, ...rest] = segmentsOf(command);
20799
+ const commit = rest.at(-1);
20800
+ if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
20801
+ return null;
20802
+ if (path27.resolve(input.cwd, cd.words[1]) !== target)
20803
+ return null;
20804
+ if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
20805
+ return null;
20806
+ const adds = rest.slice(0, -1);
20807
+ if (!adds.length || commit.words[0] !== "git" || commit.words[1] !== "commit")
20808
+ return null;
20809
+ const paths = [];
20810
+ let all = false;
20811
+ for (const add of adds) {
20812
+ const [tool, verb, ...args] = add.words;
20813
+ if (tool !== "git" || verb !== "add" || add.expands?.length || add.subs?.length)
20814
+ return null;
20815
+ const named = args.filter((arg) => !["-A", "--all", "--"].includes(arg));
20816
+ if (named.some((arg) => arg.startsWith("-") || /[*?[\]]/u.test(arg)))
20817
+ return null;
20818
+ if (!named.length && !args.some((arg) => arg === "-A" || arg === "--all"))
20819
+ return null;
20820
+ if (named.length)
20821
+ paths.push(...named);
20822
+ else
20823
+ all = true;
20824
+ }
20825
+ const messages = [];
20826
+ let allowEmpty = false;
20827
+ for (let index = 2;index < commit.words.length; index++) {
20828
+ const arg = commit.words[index];
20829
+ let message = null;
20830
+ if (arg === "--allow-empty") {
20831
+ allowEmpty = true;
20832
+ continue;
20833
+ }
20834
+ if (arg === "-m" || arg === "--message")
20835
+ message = messageOf(commit, ++index);
20836
+ else if (!commit.expands?.includes(index) && /^(?:-m|--message=)./u.test(arg))
20837
+ message = arg.replace(/^(?:-m|--message=)/u, "");
20838
+ if (!message || message.startsWith("-"))
20839
+ return null;
20840
+ messages.push(message);
20841
+ }
20842
+ if (!messages.length)
20843
+ return null;
20844
+ if (!all) {
20845
+ const staged = spawnSync15("git", ["diff", "--cached", "--quiet"], {
20846
+ cwd: target,
20847
+ timeout: 5000
20848
+ });
20849
+ if (staged.status !== 0)
20850
+ return null;
20851
+ }
20852
+ return [
20853
+ `workit git --cwd ${word(target)} commit`,
20854
+ ...messages.map((message) => `-m ${shellQuote(message)}`),
20855
+ ...allowEmpty ? ["--allow-empty"] : [],
20856
+ all ? "--all" : `-- ${[...new Set(paths)].map(word).join(" ")}`
20857
+ ].join(" ");
20858
+ };
20859
+ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit }) => {
20860
+ if (action.kind !== "commit" || !(workit || policyDeclared()))
20861
+ return null;
20862
+ const switches = workitInvocations(command, dialect).length > 0 || rawInvocations(command, dialect).some((raw) => ["switch", "checkout", "worktree"].includes(raw.args[0] ?? ""));
20863
+ let guarded = false;
20864
+ try {
20865
+ guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
20866
+ } catch {}
20867
+ if (guarded && !switches)
20868
+ 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>")}.`;
20869
+ const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path27.resolve(input.cwd, invocation.dir), repo);
20870
+ return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
20871
+ };
20765
20872
  function rawGitPre(input, command, options = {}) {
20766
20873
  try {
20767
20874
  const dialect = dialectOf(input);
@@ -20777,6 +20884,11 @@ function rawGitPre(input, command, options = {}) {
20777
20884
  if (refused)
20778
20885
  return deny(refused);
20779
20886
  }
20887
+ for (const found of located) {
20888
+ const refused = commitRefusal(input, command, dialect, found);
20889
+ if (refused)
20890
+ return deny(refused);
20891
+ }
20780
20892
  for (const { action, repo, invocation, workit } of located) {
20781
20893
  if (!workit)
20782
20894
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "1.6.0",
3
+ "version": "1.7.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.6.0"
44
+ "@workit-dev/core": "^1.7.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"