@workit-dev/opencode 1.14.1 → 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/plugin.js +56 -6
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -11128,11 +11128,13 @@ function fastGit(root) {
11128
11128
  }
11129
11129
  function resolveStore(root) {
11130
11130
  root = path11.resolve(root);
11131
- let directory = false;
11131
+ let stat = null;
11132
11132
  try {
11133
- directory = fs7.statSync(root).isDirectory();
11133
+ stat = fs7.statSync(root);
11134
11134
  } catch {}
11135
- if (!directory)
11135
+ if (!stat)
11136
+ return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
11137
+ if (!stat.isDirectory())
11136
11138
  return { dir: path11.join(root, ".workit"), shared: false, top: null };
11137
11139
  const fast = fastGit(root);
11138
11140
  if (fast?.kind === "none")
@@ -15990,7 +15992,7 @@ function cleanRebase(cwd, range) {
15990
15992
  function storeRoot(cwd) {
15991
15993
  const location = resolveStore(path21.resolve(cwd));
15992
15994
  if (location instanceof Error)
15993
- return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), "fix the repository (git status should work here) or run from a non-git directory");
15995
+ return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), / does not exist /u.test(location.message) ? "run workit from a directory that exists" : "fix the repository (git status should work here) or run from a non-git directory");
15994
15996
  return { ok: true, value: { root: location.dir, shared: location.shared } };
15995
15997
  }
15996
15998
  function ledgerPath(cwd) {
@@ -16191,7 +16193,7 @@ var sealed = (row, id, at, previous) => {
16191
16193
  ` };
16192
16194
  };
16193
16195
  function appendRaw(cwd, row, options) {
16194
- const file = ledgerPath(cwd);
16196
+ const file = options.store ? { ok: true, value: path21.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
16195
16197
  if (!file.ok)
16196
16198
  return file;
16197
16199
  const id = newId2();
@@ -24869,8 +24871,18 @@ var WORKIT_USER_ONLY = [
24869
24871
  ["grant", "set"],
24870
24872
  ["grant", "raise"],
24871
24873
  ["ledger", "void"],
24872
- ["approve"]
24874
+ ["approve"],
24875
+ ["setup"],
24876
+ ["uninstall"],
24877
+ ["install"],
24878
+ ["workspace", "seal"]
24873
24879
  ];
24880
+ var USER_ONLY_WORD = new RegExp(`\\b(?:${[...new Set(WORKIT_USER_ONLY.map((words) => words[0]))].join("|")})\\b`);
24881
+ var mayRunUserOnly = (text) => {
24882
+ const joined = text.replace(/\\\r?\n/g, "");
24883
+ const bare = joined.replace(/['"\\]/g, "");
24884
+ return [bare, bare.replace(/`/g, "")].some((all) => /\bworkit\b/.test(all) && (USER_ONLY_WORD.test(all) || /\$['"]/.test(joined)));
24885
+ };
24874
24886
  var ALLOWED = new Set(WORKIT_ALLOWED_VERBS);
24875
24887
  var hasWordsInOrder = (words, needle) => {
24876
24888
  let at = 0;
@@ -24880,6 +24892,7 @@ var hasWordsInOrder = (words, needle) => {
24880
24892
  return false;
24881
24893
  };
24882
24894
  var isBypass = (word) => WORKIT_BYPASS_FLAGS.some((flag) => word === flag || word.startsWith(`${flag}=`));
24895
+ var isWorkitWord = (word) => /^(?:.*[\\/])?workit(?:-cli)?$/u.test(word);
24883
24896
  var isAllowedWorkitCall = (words, expands = []) => {
24884
24897
  if (words[0] !== "workit")
24885
24898
  return false;
@@ -24909,6 +24922,37 @@ var isAllowedWorkitCall = (words, expands = []) => {
24909
24922
  return false;
24910
24923
  return !words.slice(0, limit).some(isBypass) && !expands.some((index) => index < limit);
24911
24924
  };
24925
+ var userOnlyWorkitCall = (command, dialect = "posix") => {
24926
+ if (!mayRunUserOnly(command))
24927
+ return null;
24928
+ for (const segment of segmentsOf(command, dialect)) {
24929
+ if (segment.unanalyzable)
24930
+ continue;
24931
+ const start = segment.words.findIndex(isWorkitWord);
24932
+ if (start < 0)
24933
+ continue;
24934
+ const words = segment.words.slice(start + 1);
24935
+ const end = words.indexOf("--");
24936
+ const args = end < 0 ? words : words.slice(0, end);
24937
+ let at = 0;
24938
+ for (;; ) {
24939
+ const word = args[at];
24940
+ if (word === "--json")
24941
+ at += 1;
24942
+ else if (word === "--cwd" || word === "--session")
24943
+ at += 2;
24944
+ else if (word?.startsWith("--cwd="))
24945
+ at += 1;
24946
+ else
24947
+ break;
24948
+ }
24949
+ const call = args.slice(at);
24950
+ const found = WORKIT_USER_ONLY.find((needle) => call[0] === needle[0] && hasWordsInOrder(call, needle));
24951
+ if (found)
24952
+ return [...found];
24953
+ }
24954
+ return null;
24955
+ };
24912
24956
  var isAllowedWorkitCommand = (command) => {
24913
24957
  const segments = segmentsOf(command);
24914
24958
  return segments.length > 0 && segments.every((s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length && isAllowedWorkitCall(s.words, s.expands));
@@ -31269,6 +31313,12 @@ var evaluateShellPermission = (root, event, workdirs = new Map) => {
31269
31313
  return deny(plan.reason);
31270
31314
  }
31271
31315
  }
31316
+ const userOnly = resources.map((resource) => userOnlyWorkitCall(resource, "posix")).find(Boolean);
31317
+ if (userOnly) {
31318
+ event.effect = "ask";
31319
+ event.message = `Only the user runs \`workit ${userOnly.join(" ")}\`: the user decides this call.`;
31320
+ return;
31321
+ }
31272
31322
  if (event.effect === "ask" && resources.length > 0 && resources.length === event.resources.length && resources.every(isAllowedWorkitCommand))
31273
31323
  event.effect = "allow";
31274
31324
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "1.14.1",
3
+ "version": "1.14.3",
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.14.1"
44
+ "@workit-dev/core": "^1.14.3"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"