@workit-dev/opencode 2.0.2 → 2.1.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 +70 -20
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -19436,6 +19436,7 @@ var tokenize = (command, dialect) => {
19436
19436
  let expanding = false;
19437
19437
  let afterOperator = false;
19438
19438
  let pending = null;
19439
+ let duplicate = false;
19439
19440
  const heredocs = [];
19440
19441
  const escape = posix ? "\\" : "`";
19441
19442
  const flushWord = () => {
@@ -19443,7 +19444,7 @@ var tokenize = (command, dialect) => {
19443
19444
  return;
19444
19445
  const text = MARKERS.test(word) ? literal2(word) : word;
19445
19446
  if (pending === "redirect") {
19446
- if (!text.startsWith("&"))
19447
+ if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
19447
19448
  current.redirects.push(text);
19448
19449
  } else if (pending === "heredoc")
19449
19450
  heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
@@ -19458,6 +19459,7 @@ var tokenize = (command, dialect) => {
19458
19459
  (current.expands ??= []).push(...current.words.slice(at).map((_, i) => at + i));
19459
19460
  }
19460
19461
  pending = null;
19462
+ duplicate = false;
19461
19463
  word = "";
19462
19464
  inWord = false;
19463
19465
  expanding = false;
@@ -19606,11 +19608,9 @@ var tokenize = (command, dialect) => {
19606
19608
  flushWord();
19607
19609
  if (command[index + 1] === ">")
19608
19610
  index++;
19609
- if (command[index + 1] === "&") {
19611
+ duplicate = command[index + 1] === "&";
19612
+ if (duplicate)
19610
19613
  index++;
19611
- word = "&";
19612
- inWord = true;
19613
- }
19614
19614
  pending = "redirect";
19615
19615
  } else if (char === "<" && posix) {
19616
19616
  flushWord();
@@ -25780,7 +25780,14 @@ function heavyGate(cwd, command, options) {
25780
25780
  }
25781
25781
  }
25782
25782
  // packages/workit-core/src/hooks/write-gate.ts
25783
- import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync12, realpathSync as realpathSync9, statSync as statSync5 } from "node:fs";
25783
+ import {
25784
+ existsSync as existsSync13,
25785
+ readdirSync as readdirSync5,
25786
+ readFileSync as readFileSync12,
25787
+ readlinkSync as readlinkSync2,
25788
+ realpathSync as realpathSync9,
25789
+ statSync as statSync5
25790
+ } from "node:fs";
25784
25791
  import os9 from "node:os";
25785
25792
  import path41 from "node:path";
25786
25793
 
@@ -25988,21 +25995,44 @@ var claimLiveSession = (target, owner, deps = {}) => {
25988
25995
  // packages/workit-core/src/hooks/write-gate.ts
25989
25996
  var NONE3 = { kind: "none" };
25990
25997
  var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
25991
- var canonical4 = (file) => {
25998
+ var linkTarget = (file) => {
25999
+ try {
26000
+ const to = readlinkSync2(file);
26001
+ let from = path41.dirname(file);
26002
+ try {
26003
+ from = realpathSync9.native(from);
26004
+ } catch {}
26005
+ return path41.resolve(from, to);
26006
+ } catch {
26007
+ return null;
26008
+ }
26009
+ };
26010
+ var realPath = (file, dangling = true) => {
26011
+ let dir = path41.resolve(file);
25992
26012
  let rest = "";
25993
- for (let dir = path41.resolve(file);; dir = path41.dirname(dir)) {
26013
+ for (let hops = 0;; ) {
25994
26014
  try {
25995
26015
  return path41.join(realpathSync9.native(dir), rest);
25996
26016
  } catch {
25997
- if (path41.dirname(dir) === dir)
26017
+ const link = dangling ? linkTarget(dir) : null;
26018
+ if (link !== null) {
26019
+ if (++hops > 40)
26020
+ return null;
26021
+ dir = path41.join(link, rest);
26022
+ rest = "";
26023
+ } else if (path41.dirname(dir) === dir)
25998
26024
  return path41.resolve(file);
25999
- rest = rest ? path41.join(path41.basename(dir), rest) : path41.basename(dir);
26025
+ else {
26026
+ rest = rest ? path41.join(path41.basename(dir), rest) : path41.basename(dir);
26027
+ dir = path41.dirname(dir);
26028
+ }
26000
26029
  }
26001
26030
  }
26002
26031
  };
26032
+ var canonical4 = (file, dangling = true) => realPath(file, dangling) ?? path41.resolve(file);
26003
26033
  var exempt = (cwd, root, file, plans) => {
26004
26034
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
26005
- const relative = path41.relative(fold(canonical4(root)), fold(canonical4(path41.resolve(cwd, file))));
26035
+ const relative = path41.relative(fold(canonical4(root, false)), fold(canonical4(path41.resolve(cwd, file), false)));
26006
26036
  if (relative.startsWith("..") || path41.isAbsolute(relative))
26007
26037
  return true;
26008
26038
  const posix = relative.split(path41.sep).join("/");
@@ -26040,6 +26070,7 @@ var editsOf = (input) => {
26040
26070
  case "rm":
26041
26071
  case "rmdir":
26042
26072
  case "tee":
26073
+ case "sponge":
26043
26074
  case "mv":
26044
26075
  case "truncate":
26045
26076
  return operands(args);
@@ -26126,7 +26157,7 @@ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test
26126
26157
  var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
26127
26158
  var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move|copy(?:2|file|tree|File)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
26128
26159
  var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
26129
- var readsRoot = (text, at) => {
26160
+ var rootUse = (text, at) => {
26130
26161
  let call;
26131
26162
  for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
26132
26163
  const char = text[index - 1];
@@ -26138,10 +26169,10 @@ var readsRoot = (text, at) => {
26138
26169
  break;
26139
26170
  }
26140
26171
  if (call !== undefined && READ_CALLS.test(call))
26141
- return true;
26172
+ return "reads";
26142
26173
  if (call !== undefined && !PATH_CALLS.test(call))
26143
- return false;
26144
- return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
26174
+ return "takes";
26175
+ return [...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name)) ? "builds" : "reads";
26145
26176
  };
26146
26177
  var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
26147
26178
  var SCRIPT_OPTIONS = [
@@ -26155,12 +26186,15 @@ var SCRIPT_OPTIONS = [
26155
26186
  var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
26156
26187
  var scriptArgs = (verb, args) => {
26157
26188
  const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
26189
+ const shell = SCRIPT_OPTIONS[0][0].test(verb);
26158
26190
  const preloads = [];
26159
26191
  for (let at = 0;at < args.length; at++) {
26160
26192
  const [option, value] = args[at].split(/=(.*)/s);
26161
26193
  if (value !== undefined && PRELOAD.test(option))
26162
26194
  preloads.push(value);
26163
- else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
26195
+ else if (/^-[mce]$|^--(?:eval|print)$|^-$/.test(option))
26196
+ break;
26197
+ else if (shell && /^-[a-zA-Z]*s[a-zA-Z]*$/.test(option))
26164
26198
  break;
26165
26199
  else if (takes.test(option)) {
26166
26200
  if (PRELOAD.test(option))
@@ -26526,6 +26560,7 @@ var DRY_N = new Set(["add", "clean", "rm", "mv"]);
26526
26560
  var MUTATING_WORKIT_GIT = new Set(["commit", "branch", "stage", "unstage"]);
26527
26561
  var DIR_TARGET = ".workit-live-target";
26528
26562
  var OPAQUE_TARGET = ".workit-runs-";
26563
+ var UNRESOLVED_TARGET = ".workit-unresolved-target";
26529
26564
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
26530
26565
  var inert = (args, sub) => args.some((arg) => arg === "--help" || arg === "-h" || arg === "--dry-run" || DRY_N.has(sub) && /^-[a-zA-Z]*n[a-zA-Z]*$/.test(arg) && !arg.startsWith("--"));
26531
26566
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -26991,9 +27026,11 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26991
27026
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
26992
27027
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
26993
27028
  ];
26994
- for (const { file, index } of found)
26995
- if (!isRoot(file) || !readsRoot(text, index))
26996
- targets.push(file);
27029
+ for (const { file, index } of found) {
27030
+ const use = isRoot(file) ? rootUse(text, index) : "takes";
27031
+ if (use !== "reads")
27032
+ targets.push(use === "builds" ? path41.join(file, UNRESOLVED_TARGET) : file);
27033
+ }
26997
27034
  }
26998
27035
  if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
26999
27036
  for (const file of operands(args))
@@ -27199,6 +27236,8 @@ var registryTarget = (cwd, targets) => {
27199
27236
  const inodes = {};
27200
27237
  for (const target of targets) {
27201
27238
  const file = homeExpanded(target);
27239
+ if (realPath(path41.resolve(cwd, file)) === null)
27240
+ return { file: target, registry: "link" };
27202
27241
  const glob = globbed(cwd, file, state, configs)[0];
27203
27242
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
27204
27243
  if (viaGlob)
@@ -27225,7 +27264,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
27225
27264
  };
27226
27265
  var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
27227
27266
  const parts = partsUnder(dir, cwd, target, platform, real);
27228
- return parts?.length === 1 && ["", ...CONFIG_FILES, DIR_TARGET].includes(parts[0]);
27267
+ return parts?.length === 1 && ["", ...CONFIG_FILES, DIR_TARGET, UNRESOLVED_TARGET].includes(parts[0]);
27229
27268
  };
27230
27269
  var unquotedWindowsRegistry = (command, platform = process.platform) => {
27231
27270
  if (platform !== "win32" || !command.includes("\\"))
@@ -27250,6 +27289,11 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
27250
27289
  return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
27251
27290
  };
27252
27291
  var REGISTRY_DENY = {
27292
+ link: {
27293
+ label: "registry guard",
27294
+ what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
27295
+ unblock: "Write to the file's real path."
27296
+ },
27253
27297
  issued: {
27254
27298
  label: "issued-registry guard",
27255
27299
  what: "Workit's issued-session state",
@@ -27268,6 +27312,12 @@ var REGISTRY_DENY = {
27268
27312
  };
27269
27313
  var registryDeny = ({ file, registry }) => {
27270
27314
  const { label, what, unblock } = REGISTRY_DENY[registry];
27315
+ if (path41.basename(file) === UNRESOLVED_TARGET)
27316
+ return {
27317
+ kind: "deny",
27318
+ reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
27319
+ unblock
27320
+ };
27271
27321
  const named = path41.basename(file).startsWith(".workit-") ? path41.dirname(file) : file;
27272
27322
  return {
27273
27323
  kind: "deny",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "2.0.2",
3
+ "version": "2.1.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": "^2.0.2"
44
+ "@workit-dev/core": "^2.1.1"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"