@workit-dev/opencode 1.6.0 → 1.6.1

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