@noppu-labs/opencode-permission-reviewer 3.5.0 → 3.6.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.6.0] - 2026-11-19
11
+
12
+ ### Changed
13
+
14
+ - Answers to agent ask dialogs reach the reviewer with a full UTC timestamp
15
+ (`[2026-09-01T12:01:03Z]`) instead of the time of day only, so answers given on different days of
16
+ a long session no longer look alike.
17
+
18
+ ### Fixed
19
+
20
+ - The V1 entrypoint refuses to load on a host that reports an OpenCode V2 version, and logs why
21
+ even without `debug`. Its reviewer isolation is a single-file plugin, which V2 does not load, so
22
+ every review used to fail closed with no visible cause. The message points at the V2 `"plugins"`
23
+ key.
24
+
25
+ ### Security
26
+
27
+ - Tools that usually only read are no longer labeled read-only when the command writes a file or
28
+ runs a program. Before, a policy rule on workspace writes or code execution did not match these
29
+ forms, and the reviewer was told the command only read.
30
+ - `sort` reads `-o` inside a short-option cluster (`sort -uo FILE`, `-nruoFILE`) and as an
31
+ abbreviated long option (`--out=FILE`). `--compress-program` counts as code execution.
32
+ - `uniq` and `xxd` report their second operand as a write.
33
+ - `tree` reports `-o FILE`, including after an attached level (`-L2 -o FILE`), and `-R`, which
34
+ writes a listing into each directory it visits.
35
+ - `yq` reports `-i` inside a flag cluster (`-iP`) or with a value (`--inplace=true`), and
36
+ `-s`/`--split-exp`, which writes a file per result. With `--security-allow-write-any-path`,
37
+ the write can land outside the workspace.
38
+
10
39
  ## [3.5.0] - 2026-11-19
11
40
 
12
41
  ### Changed
package/dist/explain.js CHANGED
@@ -5850,13 +5850,275 @@ function assessmentFrom(parsed, facts) {
5850
5850
  analysisWarnings: warnings
5851
5851
  };
5852
5852
  }
5853
+ // src/modules/analysis/capability/getopt-long-option.ts
5854
+ /** A getopt_long option word: `--name` or `--name=value`, where `name` may be
5855
+ * any unambiguous prefix of the full option name. `minimum` is the length of
5856
+ * the shortest such prefix, `--` included, so a shorter prefix that another
5857
+ * option of the same tool shares never matches. */
5858
+ function longOption$1(value, name, minimum) {
5859
+ if (!value.startsWith("--")) return void 0;
5860
+ const equals = value.indexOf("=");
5861
+ const word = equals === -1 ? value : value.slice(0, equals);
5862
+ if (word.length < minimum || !name.startsWith(word)) return void 0;
5863
+ return equals === -1 ? {} : { inline: value.slice(equals + 1) };
5864
+ }
5865
+ // src/modules/analysis/capability/output-operand-mutations.ts
5866
+ /** uniq's long options with a required value, with the length of each one's
5867
+ * shortest unambiguous prefix. */
5868
+ const UNIQ_VALUED_LONG = [
5869
+ ["--skip-fields", 8],
5870
+ ["--skip-chars", 8],
5871
+ ["--check-chars", 4]
5872
+ ];
5873
+ const UNIQ_OPTIONS = {
5874
+ takesNextWord(value) {
5875
+ if (value.startsWith("--")) return !value.includes("=") && UNIQ_VALUED_LONG.some(([name, minimum]) => longOption$1(value, name, minimum) !== void 0);
5876
+ const at = value.slice(1).search(/[fsw]/);
5877
+ return at !== -1 && at + 2 === value.length;
5878
+ },
5879
+ permute: true
5880
+ };
5881
+ /** xxd's options that take a value, by letter, with the tails of their long
5882
+ * spellings (`-c`, `-cols`). Such a word takes the next word as its value;
5883
+ * any other text after the letter is the value itself (`-c8`). */
5884
+ const XXD_VALUED = /* @__PURE__ */ new Map([
5885
+ ["c", ["ols"]],
5886
+ ["g", ["roup"]],
5887
+ ["o", ["ffset"]],
5888
+ ["s", ["kip", "eek"]],
5889
+ ["l", ["en"]],
5890
+ ["n", ["ame"]],
5891
+ ["R", []]
5892
+ ]);
5893
+ const XXD_OPTIONS = {
5894
+ takesNextWord(value) {
5895
+ const word = value.startsWith("--") && value.length > 2 ? value.slice(1) : value;
5896
+ const rest = word.slice(2);
5897
+ if (word.charAt(1) === "c" && rest.startsWith("apitalize")) return false;
5898
+ const tails = XXD_VALUED.get(word.charAt(1));
5899
+ if (tails === void 0) return false;
5900
+ return rest === "" || tails.some((tail) => rest.startsWith(tail));
5901
+ },
5902
+ permute: false
5903
+ };
5904
+ /** `TOOL [OPTION]... [INPUT [OUTPUT]]` (uniq, xxd): a second operand is a file
5905
+ * the command writes ("-" is standard output). */
5906
+ function outputOperandMutation(cmd, tool) {
5907
+ const output = operandsOf(cmd, tool)[1];
5908
+ return output !== void 0 && output !== "-" ? { writeTargets: [output] } : void 0;
5909
+ }
5910
+ function operandsOf(cmd, tool) {
5911
+ const operands = [];
5912
+ let options = true;
5913
+ for (let index = 1; index < cmd.length; index += 1) {
5914
+ const value = elementAt(cmd, index, "cmd").value;
5915
+ if (options && value === "--") options = false;
5916
+ else if (options && value.startsWith("-") && value !== "-") {
5917
+ if (tool.takesNextWord(value)) index += 1;
5918
+ } else {
5919
+ operands.push(value);
5920
+ options &&= tool.permute;
5921
+ }
5922
+ }
5923
+ return operands;
5924
+ }
5925
+ // src/modules/analysis/capability/sort-mutation.ts
5926
+ /** GNU sort short options that take a value. The value is the rest of the
5927
+ * cluster, or the next word when the letter ends it. */
5928
+ const SORT_VALUED_LETTERS = "kotST";
5929
+ /** GNU sort: `-o FILE` writes FILE and `--compress-program=PROG` runs PROG.
5930
+ * Short options cluster getopt-style (`-uo FILE`, `-nruoFILE`), and long
5931
+ * options may be abbreviated (`--out=FILE`). */
5932
+ function sortMutation(cmd) {
5933
+ const result = { writeTargets: [] };
5934
+ let index = 1;
5935
+ while (index < cmd.length) {
5936
+ const value = elementAt(cmd, index, "cmd").value;
5937
+ if (value === "--") break;
5938
+ index += value.startsWith("--") ? sortLongOption(cmd, index, result) : sortShortOptions(cmd, index, result);
5939
+ }
5940
+ return result.writeTargets.length > 0 || result.executesCode === true ? result : void 0;
5941
+ }
5942
+ /** Record a long option's effect; returns the words it spans. */
5943
+ function sortLongOption(cmd, index, result) {
5944
+ const value = elementAt(cmd, index, "cmd").value;
5945
+ const output = longOption$1(value, "--output", 3);
5946
+ if (output !== void 0) {
5947
+ const target = output.inline ?? cmd[index + 1]?.value;
5948
+ if (target !== void 0) result.writeTargets.push(target);
5949
+ return output.inline === void 0 ? 2 : 1;
5950
+ }
5951
+ if (longOption$1(value, "--compress-program", 4) !== void 0) result.executesCode = true;
5952
+ return 1;
5953
+ }
5954
+ /** Record a short-option cluster's output file; returns the words it spans. */
5955
+ function sortShortOptions(cmd, index, result) {
5956
+ const value = elementAt(cmd, index, "cmd").value;
5957
+ if (!value.startsWith("-") || value === "-") return 1;
5958
+ for (let at = 1; at < value.length; at += 1) {
5959
+ const letter = value.charAt(at);
5960
+ if (!SORT_VALUED_LETTERS.includes(letter)) continue;
5961
+ const attached = value.slice(at + 1);
5962
+ const argument = attached === "" ? cmd[index + 1]?.value : attached;
5963
+ if (letter === "o" && argument !== void 0) result.writeTargets.push(argument);
5964
+ return attached === "" ? 2 : 1;
5965
+ }
5966
+ return 1;
5967
+ }
5968
+ // src/modules/analysis/capability/tree-mutation.ts
5969
+ /** tree's short options whose value is the next unused word. `-L` also takes
5970
+ * its value as digits attached inside the cluster (`-L2`). */
5971
+ const TREE_VALUED_LETTERS = /* @__PURE__ */ new Set([
5972
+ "L",
5973
+ "P",
5974
+ "I",
5975
+ "H",
5976
+ "T",
5977
+ "o"
5978
+ ]);
5979
+ /** tree's long options with a value, which is inline (`--sort=name`) or the
5980
+ * next word. tree matches each by prefix. */
5981
+ const TREE_VALUED_LONG = [
5982
+ "--authority",
5983
+ "--charset",
5984
+ "--compress",
5985
+ "--filelimit",
5986
+ "--gitfile",
5987
+ "--hintro",
5988
+ "--houtro",
5989
+ "--infofile",
5990
+ "--scheme",
5991
+ "--sort",
5992
+ "--timefmt"
5993
+ ];
5994
+ /** tree: `-o FILE` writes FILE, and `-R` writes an `00Tree.html` listing into
5995
+ * each directory it visits. Options may follow the roots. */
5996
+ function treeMutation(cmd) {
5997
+ const scan = {
5998
+ roots: [],
5999
+ outputs: [],
6000
+ recursive: false
6001
+ };
6002
+ let index = 1;
6003
+ while (index < cmd.length) {
6004
+ if (elementAt(cmd, index, "cmd").value === "--") {
6005
+ scan.roots.push(...cmd.slice(index + 1).map((token) => token.value));
6006
+ break;
6007
+ }
6008
+ index += treeWord(cmd, index, scan);
6009
+ }
6010
+ const writeTargets = [...scan.outputs];
6011
+ if (scan.recursive) writeTargets.push(...scan.roots.length > 0 ? scan.roots : ["."]);
6012
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
6013
+ }
6014
+ /** Scan the word at `index`; returns the words it spans. */
6015
+ function treeWord(cmd, index, scan) {
6016
+ const value = elementAt(cmd, index, "cmd").value;
6017
+ if (value.startsWith("--")) return TREE_VALUED_LONG.some((name) => value.startsWith(name) && value.charAt(name.length) !== "=") ? 2 : 1;
6018
+ if (!value.startsWith("-") || value === "-") {
6019
+ scan.roots.push(value);
6020
+ return 1;
6021
+ }
6022
+ return 1 + treeShortOptions(cmd, index, scan);
6023
+ }
6024
+ /** Scan a short-option cluster. Each letter that takes a value consumes the
6025
+ * next unused word, in order (`-Lo 2 out.txt`). Returns how many it used. */
6026
+ function treeShortOptions(cmd, index, scan) {
6027
+ const value = elementAt(cmd, index, "cmd").value;
6028
+ let consumed = 0;
6029
+ let at = 1;
6030
+ while (at < value.length) {
6031
+ const letter = value.charAt(at);
6032
+ const digits = letter === "L" ? attachedDigits(value, at + 1) : 0;
6033
+ if (letter === "R") scan.recursive = true;
6034
+ else if (digits === 0 && TREE_VALUED_LETTERS.has(letter)) {
6035
+ consumed += 1;
6036
+ recordTreeValue(letter, cmd[index + consumed]?.value, scan);
6037
+ }
6038
+ at += 1 + digits;
6039
+ }
6040
+ return consumed;
6041
+ }
6042
+ /** How many digits start `value` at `from`. */
6043
+ function attachedDigits(value, from) {
6044
+ return value.slice(from).match(/^\d*/)?.[0].length ?? 0;
6045
+ }
6046
+ function recordTreeValue(letter, argument, scan) {
6047
+ if (letter === "o" && argument !== void 0) scan.outputs.push(argument);
6048
+ }
6049
+ // src/modules/analysis/capability/yq-mutation.ts
6050
+ /** yq's short flags that take a value. The value is the rest of the cluster,
6051
+ * so a later letter is not a flag (`-oi` is output format "i"). */
6052
+ const YQ_VALUED_LETTERS = "poIsf";
6053
+ /** The values a Go boolean flag parses as false. */
6054
+ const FALSE_VALUES = /* @__PURE__ */ new Set([
6055
+ "0",
6056
+ "f",
6057
+ "F",
6058
+ "false",
6059
+ "FALSE",
6060
+ "False"
6061
+ ]);
6062
+ /** yq: `-i` rewrites its file operands, and `-s` writes a file per result.
6063
+ * For an in-place edit every non-option word, the expression included, is
6064
+ * recorded as a write target. */
6065
+ function yqMutation(cmd) {
6066
+ const writes = yqWrites(cmd);
6067
+ const writeTargets = [];
6068
+ if (writes.inPlace) writeTargets.push(...cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-")));
6069
+ if (writes.split) writeTargets.push(writes.anyPath ? "/" : ".");
6070
+ if (writes.inPlace && writeTargets.length === 0) writeTargets.push(".");
6071
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
6072
+ }
6073
+ /** Scan yq's flags (pflag syntax: no abbreviations, booleans may carry
6074
+ * `=value`, short booleans cluster). */
6075
+ function yqWrites(cmd) {
6076
+ const writes = {
6077
+ inPlace: false,
6078
+ split: false,
6079
+ anyPath: false
6080
+ };
6081
+ for (const token of cmd.slice(1)) {
6082
+ const value = token.value;
6083
+ if (value === "--") break;
6084
+ if (value.startsWith("--")) yqLongFlag(value, writes);
6085
+ else if (value.startsWith("-")) yqShortFlags(value, writes);
6086
+ }
6087
+ return writes;
6088
+ }
6089
+ function yqLongFlag(value, writes) {
6090
+ const equals = value.indexOf("=");
6091
+ const name = equals === -1 ? value : value.slice(0, equals);
6092
+ const enabled = equals === -1 || !FALSE_VALUES.has(value.slice(equals + 1));
6093
+ if (name === "--inplace") writes.inPlace ||= enabled;
6094
+ else if (name === "--split-exp" || name === "--split-exp-file") writes.split = true;
6095
+ else if (name === "--security-allow-write-any-path") writes.anyPath ||= enabled;
6096
+ }
6097
+ function yqShortFlags(value, writes) {
6098
+ for (let at = 1; at < value.length; at += 1) {
6099
+ const letter = value.charAt(at);
6100
+ if (letter === "i") {
6101
+ if (yqInPlaceFlag(value, at, writes)) return;
6102
+ } else if (YQ_VALUED_LETTERS.includes(letter)) {
6103
+ writes.split ||= letter === "s";
6104
+ return;
6105
+ }
6106
+ }
6107
+ }
6108
+ /** Record the `-i` at `at`. pflag reads `-i=false` as the flag with a value,
6109
+ * which ends the cluster; returns whether it did. */
6110
+ function yqInPlaceFlag(value, at, writes) {
6111
+ const inline = value.charAt(at + 1) === "=" ? value.slice(at + 2) : void 0;
6112
+ writes.inPlace ||= inline === void 0 || !FALSE_VALUES.has(inline);
6113
+ return inline !== void 0;
6114
+ }
5853
6115
  // src/modules/analysis/capability/read-only-tool-mutations.ts
5854
- /** Placeholder target when a mutating form names no operand: conservatively
5855
- * treated as a workspace write (the current directory). */
5856
- const directoryFallback = ".";
5857
6116
  function readOnlyToolMutation(cmd, base) {
5858
6117
  if (base === "find") return findMutation(cmd);
5859
6118
  if (base === "sort") return sortMutation(cmd);
6119
+ if (base === "uniq") return outputOperandMutation(cmd, UNIQ_OPTIONS);
6120
+ if (base === "xxd") return outputOperandMutation(cmd, XXD_OPTIONS);
6121
+ if (base === "tree") return treeMutation(cmd);
5860
6122
  if (base === "yq") return yqMutation(cmd);
5861
6123
  }
5862
6124
  function findMutation(cmd) {
@@ -5916,22 +6178,6 @@ function pushOptionValue(cmd, index, targets) {
5916
6178
  const target = cmd[index + 1]?.value;
5917
6179
  if (target !== void 0 && !target.startsWith("-")) targets.push(target);
5918
6180
  }
5919
- function sortMutation(cmd) {
5920
- const result = { writeTargets: [] };
5921
- for (let index = 1; index < cmd.length; index += 1) {
5922
- const value = elementAt(cmd, index, "cmd").value;
5923
- if (value === "-o" || value === "--output") pushOptionValue(cmd, index, result.writeTargets);
5924
- else if (value.startsWith("--output=")) result.writeTargets.push(value.slice(9));
5925
- else if (value.startsWith("-o") && value.length > 2) result.writeTargets.push(value.slice(2));
5926
- }
5927
- return result.writeTargets.length > 0 ? result : void 0;
5928
- }
5929
- /** In-place edit: every non-option operand, the expression included, is recorded as a write target. */
5930
- function yqMutation(cmd) {
5931
- if (!cmd.some((token) => token.value === "-i" || token.value === "--inplace")) return void 0;
5932
- const targets = cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-"));
5933
- return targets.length > 0 ? { writeTargets: targets } : { writeTargets: [directoryFallback] };
5934
- }
5935
6181
  // src/modules/analysis/capability/executable-recognition.ts
5936
6182
  /** Effect families that keep a read-only or no-effect executable from
5937
6183
  * counting as read-only. */
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { parse as parse$1, satisfies } from "semver";
1
2
  import { createHash, randomBytes, randomUUID } from "node:crypto";
2
3
  import { basename as basename$1, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
3
4
  import { lstat, mkdir, mkdtemp, open as open$2, readlink, realpath, rm, stat, writeFile } from "node:fs/promises";
@@ -6,7 +7,6 @@ import { promisify } from "node:util";
6
7
  import { closeSync, constants, fchmodSync, fstatSync, openSync, readSync, realpathSync, rmSync, writeSync } from "node:fs";
7
8
  import { homedir, tmpdir } from "node:os";
8
9
  import { TypeSafeClient } from "@typesafe-ai/sdk";
9
- import { satisfies } from "semver";
10
10
  import { z } from "zod";
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { Buffer as Buffer$1 } from "node:buffer";
@@ -76,6 +76,37 @@ function extractPermissionRequest(event) {
76
76
  ...tool === void 0 ? {} : { tool }
77
77
  };
78
78
  }
79
+ // src/adapters/opencode/host-guard.ts
80
+ /**
81
+ * OpenCode V2 host versions accepted at setup. A host outside this range
82
+ * fails setup loudly instead of running against an unknown contract.
83
+ */
84
+ const SUPPORTED_V2_RANGE = ">=2.0.22 <3";
85
+ /**
86
+ * Guard the legacy adapter against incompatible client shapes.
87
+ *
88
+ * A client exposing only permission.reply does not satisfy the legacy
89
+ * transport contract. Product V2 uses its own setup entrypoint and adapter.
90
+ */
91
+ function assertV1Host(client) {
92
+ const record = client ?? {};
93
+ const permission = record.permission ?? {};
94
+ const raw = record._client ?? {};
95
+ if (typeof permission.reply === "function" && typeof raw.post !== "function") throw new Error("The V1 adapter requires the authenticated legacy transport. Use the setup entrypoint for OpenCode V2; refusing this incompatible client.");
96
+ }
97
+ /**
98
+ * Why the V1 entrypoint must refuse a host that reports a V2 version, or
99
+ * undefined when the version is V1 or unknown.
100
+ *
101
+ * The V1 reviewer isolates its sessions with a single-file local plugin, and
102
+ * V2 skips plugin paths that name a file. Every review would then fail closed
103
+ * with no visible cause, so the plugin fails at load and says how to fix it.
104
+ */
105
+ function v1HostVersionRefusal(version) {
106
+ const parsed = version === void 0 ? null : parse$1(version);
107
+ if (parsed === null || parsed.major < 2) return;
108
+ return `OpenCode ${parsed.version} loaded the V1 entrypoint of opencode-permission-reviewer, whose reviewer isolation V2 does not load. Register the plugin under the V2 "plugins" key (see "Configure" in the README) so the host uses its setup entrypoint.`;
109
+ }
79
110
  // src/utils/with-timeout.ts
80
111
  function withTimeout(promise, timeoutMs) {
81
112
  let timer;
@@ -108,7 +139,7 @@ function invariant(condition, message) {
108
139
  if (!condition) throw new Error(message);
109
140
  }
110
141
  // package.json
111
- var version = "3.5.0";
142
+ var version = "3.6.0";
112
143
  // src/utils/redact.ts
113
144
  const REDACT = (type) => `[REDACTED:${type}]`;
114
145
  const OPENCODE_SESSION_KEY = /^(?:session[_-]?id|session|sid)$/i;
@@ -5421,12 +5452,12 @@ function scanWord(words, index, scan) {
5421
5452
  scan.operand = index + 1 < words.length;
5422
5453
  return;
5423
5454
  }
5424
- if (word.startsWith("--")) return longOption(word, scan);
5455
+ if (word.startsWith("--")) return longOption$1(word, scan);
5425
5456
  if (word.length > 1 && (word.startsWith("-") || word.startsWith("+"))) return optionCluster(words, index, scan);
5426
5457
  scan.operand = true;
5427
5458
  }
5428
5459
  /** The words a long option takes after itself. */
5429
- function longOption(word, scan) {
5460
+ function longOption$1(word, scan) {
5430
5461
  if (SHELL_NO_RUN_LONG_OPTIONS.has(word)) scan.noRun = true;
5431
5462
  return SHELL_LONG_VALUE_OPTIONS.has(word) ? 1 : 0;
5432
5463
  }
@@ -10198,13 +10229,275 @@ function assessmentFrom(parsed, facts) {
10198
10229
  analysisWarnings: warnings
10199
10230
  };
10200
10231
  }
10232
+ // src/modules/analysis/capability/getopt-long-option.ts
10233
+ /** A getopt_long option word: `--name` or `--name=value`, where `name` may be
10234
+ * any unambiguous prefix of the full option name. `minimum` is the length of
10235
+ * the shortest such prefix, `--` included, so a shorter prefix that another
10236
+ * option of the same tool shares never matches. */
10237
+ function longOption(value, name, minimum) {
10238
+ if (!value.startsWith("--")) return void 0;
10239
+ const equals = value.indexOf("=");
10240
+ const word = equals === -1 ? value : value.slice(0, equals);
10241
+ if (word.length < minimum || !name.startsWith(word)) return void 0;
10242
+ return equals === -1 ? {} : { inline: value.slice(equals + 1) };
10243
+ }
10244
+ // src/modules/analysis/capability/output-operand-mutations.ts
10245
+ /** uniq's long options with a required value, with the length of each one's
10246
+ * shortest unambiguous prefix. */
10247
+ const UNIQ_VALUED_LONG = [
10248
+ ["--skip-fields", 8],
10249
+ ["--skip-chars", 8],
10250
+ ["--check-chars", 4]
10251
+ ];
10252
+ const UNIQ_OPTIONS = {
10253
+ takesNextWord(value) {
10254
+ if (value.startsWith("--")) return !value.includes("=") && UNIQ_VALUED_LONG.some(([name, minimum]) => longOption(value, name, minimum) !== void 0);
10255
+ const at = value.slice(1).search(/[fsw]/);
10256
+ return at !== -1 && at + 2 === value.length;
10257
+ },
10258
+ permute: true
10259
+ };
10260
+ /** xxd's options that take a value, by letter, with the tails of their long
10261
+ * spellings (`-c`, `-cols`). Such a word takes the next word as its value;
10262
+ * any other text after the letter is the value itself (`-c8`). */
10263
+ const XXD_VALUED = /* @__PURE__ */ new Map([
10264
+ ["c", ["ols"]],
10265
+ ["g", ["roup"]],
10266
+ ["o", ["ffset"]],
10267
+ ["s", ["kip", "eek"]],
10268
+ ["l", ["en"]],
10269
+ ["n", ["ame"]],
10270
+ ["R", []]
10271
+ ]);
10272
+ const XXD_OPTIONS = {
10273
+ takesNextWord(value) {
10274
+ const word = value.startsWith("--") && value.length > 2 ? value.slice(1) : value;
10275
+ const rest = word.slice(2);
10276
+ if (word.charAt(1) === "c" && rest.startsWith("apitalize")) return false;
10277
+ const tails = XXD_VALUED.get(word.charAt(1));
10278
+ if (tails === void 0) return false;
10279
+ return rest === "" || tails.some((tail) => rest.startsWith(tail));
10280
+ },
10281
+ permute: false
10282
+ };
10283
+ /** `TOOL [OPTION]... [INPUT [OUTPUT]]` (uniq, xxd): a second operand is a file
10284
+ * the command writes ("-" is standard output). */
10285
+ function outputOperandMutation(cmd, tool) {
10286
+ const output = operandsOf(cmd, tool)[1];
10287
+ return output !== void 0 && output !== "-" ? { writeTargets: [output] } : void 0;
10288
+ }
10289
+ function operandsOf(cmd, tool) {
10290
+ const operands = [];
10291
+ let options = true;
10292
+ for (let index = 1; index < cmd.length; index += 1) {
10293
+ const value = elementAt(cmd, index, "cmd").value;
10294
+ if (options && value === "--") options = false;
10295
+ else if (options && value.startsWith("-") && value !== "-") {
10296
+ if (tool.takesNextWord(value)) index += 1;
10297
+ } else {
10298
+ operands.push(value);
10299
+ options &&= tool.permute;
10300
+ }
10301
+ }
10302
+ return operands;
10303
+ }
10304
+ // src/modules/analysis/capability/sort-mutation.ts
10305
+ /** GNU sort short options that take a value. The value is the rest of the
10306
+ * cluster, or the next word when the letter ends it. */
10307
+ const SORT_VALUED_LETTERS = "kotST";
10308
+ /** GNU sort: `-o FILE` writes FILE and `--compress-program=PROG` runs PROG.
10309
+ * Short options cluster getopt-style (`-uo FILE`, `-nruoFILE`), and long
10310
+ * options may be abbreviated (`--out=FILE`). */
10311
+ function sortMutation(cmd) {
10312
+ const result = { writeTargets: [] };
10313
+ let index = 1;
10314
+ while (index < cmd.length) {
10315
+ const value = elementAt(cmd, index, "cmd").value;
10316
+ if (value === "--") break;
10317
+ index += value.startsWith("--") ? sortLongOption(cmd, index, result) : sortShortOptions(cmd, index, result);
10318
+ }
10319
+ return result.writeTargets.length > 0 || result.executesCode === true ? result : void 0;
10320
+ }
10321
+ /** Record a long option's effect; returns the words it spans. */
10322
+ function sortLongOption(cmd, index, result) {
10323
+ const value = elementAt(cmd, index, "cmd").value;
10324
+ const output = longOption(value, "--output", 3);
10325
+ if (output !== void 0) {
10326
+ const target = output.inline ?? cmd[index + 1]?.value;
10327
+ if (target !== void 0) result.writeTargets.push(target);
10328
+ return output.inline === void 0 ? 2 : 1;
10329
+ }
10330
+ if (longOption(value, "--compress-program", 4) !== void 0) result.executesCode = true;
10331
+ return 1;
10332
+ }
10333
+ /** Record a short-option cluster's output file; returns the words it spans. */
10334
+ function sortShortOptions(cmd, index, result) {
10335
+ const value = elementAt(cmd, index, "cmd").value;
10336
+ if (!value.startsWith("-") || value === "-") return 1;
10337
+ for (let at = 1; at < value.length; at += 1) {
10338
+ const letter = value.charAt(at);
10339
+ if (!SORT_VALUED_LETTERS.includes(letter)) continue;
10340
+ const attached = value.slice(at + 1);
10341
+ const argument = attached === "" ? cmd[index + 1]?.value : attached;
10342
+ if (letter === "o" && argument !== void 0) result.writeTargets.push(argument);
10343
+ return attached === "" ? 2 : 1;
10344
+ }
10345
+ return 1;
10346
+ }
10347
+ // src/modules/analysis/capability/tree-mutation.ts
10348
+ /** tree's short options whose value is the next unused word. `-L` also takes
10349
+ * its value as digits attached inside the cluster (`-L2`). */
10350
+ const TREE_VALUED_LETTERS = /* @__PURE__ */ new Set([
10351
+ "L",
10352
+ "P",
10353
+ "I",
10354
+ "H",
10355
+ "T",
10356
+ "o"
10357
+ ]);
10358
+ /** tree's long options with a value, which is inline (`--sort=name`) or the
10359
+ * next word. tree matches each by prefix. */
10360
+ const TREE_VALUED_LONG = [
10361
+ "--authority",
10362
+ "--charset",
10363
+ "--compress",
10364
+ "--filelimit",
10365
+ "--gitfile",
10366
+ "--hintro",
10367
+ "--houtro",
10368
+ "--infofile",
10369
+ "--scheme",
10370
+ "--sort",
10371
+ "--timefmt"
10372
+ ];
10373
+ /** tree: `-o FILE` writes FILE, and `-R` writes an `00Tree.html` listing into
10374
+ * each directory it visits. Options may follow the roots. */
10375
+ function treeMutation(cmd) {
10376
+ const scan = {
10377
+ roots: [],
10378
+ outputs: [],
10379
+ recursive: false
10380
+ };
10381
+ let index = 1;
10382
+ while (index < cmd.length) {
10383
+ if (elementAt(cmd, index, "cmd").value === "--") {
10384
+ scan.roots.push(...cmd.slice(index + 1).map((token) => token.value));
10385
+ break;
10386
+ }
10387
+ index += treeWord(cmd, index, scan);
10388
+ }
10389
+ const writeTargets = [...scan.outputs];
10390
+ if (scan.recursive) writeTargets.push(...scan.roots.length > 0 ? scan.roots : ["."]);
10391
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
10392
+ }
10393
+ /** Scan the word at `index`; returns the words it spans. */
10394
+ function treeWord(cmd, index, scan) {
10395
+ const value = elementAt(cmd, index, "cmd").value;
10396
+ if (value.startsWith("--")) return TREE_VALUED_LONG.some((name) => value.startsWith(name) && value.charAt(name.length) !== "=") ? 2 : 1;
10397
+ if (!value.startsWith("-") || value === "-") {
10398
+ scan.roots.push(value);
10399
+ return 1;
10400
+ }
10401
+ return 1 + treeShortOptions(cmd, index, scan);
10402
+ }
10403
+ /** Scan a short-option cluster. Each letter that takes a value consumes the
10404
+ * next unused word, in order (`-Lo 2 out.txt`). Returns how many it used. */
10405
+ function treeShortOptions(cmd, index, scan) {
10406
+ const value = elementAt(cmd, index, "cmd").value;
10407
+ let consumed = 0;
10408
+ let at = 1;
10409
+ while (at < value.length) {
10410
+ const letter = value.charAt(at);
10411
+ const digits = letter === "L" ? attachedDigits(value, at + 1) : 0;
10412
+ if (letter === "R") scan.recursive = true;
10413
+ else if (digits === 0 && TREE_VALUED_LETTERS.has(letter)) {
10414
+ consumed += 1;
10415
+ recordTreeValue(letter, cmd[index + consumed]?.value, scan);
10416
+ }
10417
+ at += 1 + digits;
10418
+ }
10419
+ return consumed;
10420
+ }
10421
+ /** How many digits start `value` at `from`. */
10422
+ function attachedDigits(value, from) {
10423
+ return value.slice(from).match(/^\d*/)?.[0].length ?? 0;
10424
+ }
10425
+ function recordTreeValue(letter, argument, scan) {
10426
+ if (letter === "o" && argument !== void 0) scan.outputs.push(argument);
10427
+ }
10428
+ // src/modules/analysis/capability/yq-mutation.ts
10429
+ /** yq's short flags that take a value. The value is the rest of the cluster,
10430
+ * so a later letter is not a flag (`-oi` is output format "i"). */
10431
+ const YQ_VALUED_LETTERS = "poIsf";
10432
+ /** The values a Go boolean flag parses as false. */
10433
+ const FALSE_VALUES = /* @__PURE__ */ new Set([
10434
+ "0",
10435
+ "f",
10436
+ "F",
10437
+ "false",
10438
+ "FALSE",
10439
+ "False"
10440
+ ]);
10441
+ /** yq: `-i` rewrites its file operands, and `-s` writes a file per result.
10442
+ * For an in-place edit every non-option word, the expression included, is
10443
+ * recorded as a write target. */
10444
+ function yqMutation(cmd) {
10445
+ const writes = yqWrites(cmd);
10446
+ const writeTargets = [];
10447
+ if (writes.inPlace) writeTargets.push(...cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-")));
10448
+ if (writes.split) writeTargets.push(writes.anyPath ? "/" : ".");
10449
+ if (writes.inPlace && writeTargets.length === 0) writeTargets.push(".");
10450
+ return writeTargets.length > 0 ? { writeTargets } : void 0;
10451
+ }
10452
+ /** Scan yq's flags (pflag syntax: no abbreviations, booleans may carry
10453
+ * `=value`, short booleans cluster). */
10454
+ function yqWrites(cmd) {
10455
+ const writes = {
10456
+ inPlace: false,
10457
+ split: false,
10458
+ anyPath: false
10459
+ };
10460
+ for (const token of cmd.slice(1)) {
10461
+ const value = token.value;
10462
+ if (value === "--") break;
10463
+ if (value.startsWith("--")) yqLongFlag(value, writes);
10464
+ else if (value.startsWith("-")) yqShortFlags(value, writes);
10465
+ }
10466
+ return writes;
10467
+ }
10468
+ function yqLongFlag(value, writes) {
10469
+ const equals = value.indexOf("=");
10470
+ const name = equals === -1 ? value : value.slice(0, equals);
10471
+ const enabled = equals === -1 || !FALSE_VALUES.has(value.slice(equals + 1));
10472
+ if (name === "--inplace") writes.inPlace ||= enabled;
10473
+ else if (name === "--split-exp" || name === "--split-exp-file") writes.split = true;
10474
+ else if (name === "--security-allow-write-any-path") writes.anyPath ||= enabled;
10475
+ }
10476
+ function yqShortFlags(value, writes) {
10477
+ for (let at = 1; at < value.length; at += 1) {
10478
+ const letter = value.charAt(at);
10479
+ if (letter === "i") {
10480
+ if (yqInPlaceFlag(value, at, writes)) return;
10481
+ } else if (YQ_VALUED_LETTERS.includes(letter)) {
10482
+ writes.split ||= letter === "s";
10483
+ return;
10484
+ }
10485
+ }
10486
+ }
10487
+ /** Record the `-i` at `at`. pflag reads `-i=false` as the flag with a value,
10488
+ * which ends the cluster; returns whether it did. */
10489
+ function yqInPlaceFlag(value, at, writes) {
10490
+ const inline = value.charAt(at + 1) === "=" ? value.slice(at + 2) : void 0;
10491
+ writes.inPlace ||= inline === void 0 || !FALSE_VALUES.has(inline);
10492
+ return inline !== void 0;
10493
+ }
10201
10494
  // src/modules/analysis/capability/read-only-tool-mutations.ts
10202
- /** Placeholder target when a mutating form names no operand: conservatively
10203
- * treated as a workspace write (the current directory). */
10204
- const directoryFallback = ".";
10205
10495
  function readOnlyToolMutation(cmd, base) {
10206
10496
  if (base === "find") return findMutation(cmd);
10207
10497
  if (base === "sort") return sortMutation(cmd);
10498
+ if (base === "uniq") return outputOperandMutation(cmd, UNIQ_OPTIONS);
10499
+ if (base === "xxd") return outputOperandMutation(cmd, XXD_OPTIONS);
10500
+ if (base === "tree") return treeMutation(cmd);
10208
10501
  if (base === "yq") return yqMutation(cmd);
10209
10502
  }
10210
10503
  function findMutation(cmd) {
@@ -10264,22 +10557,6 @@ function pushOptionValue(cmd, index, targets) {
10264
10557
  const target = cmd[index + 1]?.value;
10265
10558
  if (target !== void 0 && !target.startsWith("-")) targets.push(target);
10266
10559
  }
10267
- function sortMutation(cmd) {
10268
- const result = { writeTargets: [] };
10269
- for (let index = 1; index < cmd.length; index += 1) {
10270
- const value = elementAt(cmd, index, "cmd").value;
10271
- if (value === "-o" || value === "--output") pushOptionValue(cmd, index, result.writeTargets);
10272
- else if (value.startsWith("--output=")) result.writeTargets.push(value.slice(9));
10273
- else if (value.startsWith("-o") && value.length > 2) result.writeTargets.push(value.slice(2));
10274
- }
10275
- return result.writeTargets.length > 0 ? result : void 0;
10276
- }
10277
- /** In-place edit: every non-option operand, the expression included, is recorded as a write target. */
10278
- function yqMutation(cmd) {
10279
- if (!cmd.some((token) => token.value === "-i" || token.value === "--inplace")) return void 0;
10280
- const targets = cmd.slice(1).map((token) => token.value).filter((value) => !value.startsWith("-"));
10281
- return targets.length > 0 ? { writeTargets: targets } : { writeTargets: [directoryFallback] };
10282
- }
10283
10560
  // src/modules/analysis/capability/executable-recognition.ts
10284
10561
  /** Effect families that keep a read-only or no-effect executable from
10285
10562
  * counting as read-only. */
@@ -11762,15 +12039,16 @@ function renderActionPurpose(purpose, max, intentReference = false) {
11762
12039
  ...purpose.text === void 0 ? {} : { text: intentReference && purpose.source === "intent-derived" ? "<see literal intent sections>" : purpose.text }
11763
12040
  }, max)}`;
11764
12041
  }
11765
- /** Compact rendering of ask decisions, one line each (UTC time, question,
11766
- * answer). `undefined` when there is nothing to show so the whole section is
11767
- * omitted rather than padded with a placeholder. */
12042
+ /** Compact rendering of ask decisions, one line each (full UTC timestamp,
12043
+ * question, answer). The date keeps answers apart in sessions that span
12044
+ * several days. `undefined` when there is nothing to show so the whole
12045
+ * section is omitted rather than padded with a placeholder. */
11768
12046
  function renderAskDecisions(decisions) {
11769
12047
  if (decisions === void 0 || decisions.length === 0) return;
11770
12048
  const lines = [];
11771
12049
  for (const decision of decisions) {
11772
- const time = new Date(decision.at).toISOString().slice(11, 19);
11773
- lines.push(`[${time}Z] Q: ${decision.question} A: ${decision.answer}`);
12050
+ const time = new Date(decision.at).toISOString().replace(/\.\d{3}Z$/, "Z");
12051
+ lines.push(`[${time}] Q: ${decision.question} A: ${decision.answer}`);
11774
12052
  }
11775
12053
  const maxChars = 1500;
11776
12054
  while (lines.length > 1 && lines.join("\n").length > maxChars) lines.shift();
@@ -16355,24 +16633,6 @@ function probeCapabilities(client) {
16355
16633
  tuiPublish: typeof tui.publish === "function"
16356
16634
  };
16357
16635
  }
16358
- // src/adapters/opencode/host-guard.ts
16359
- /**
16360
- * OpenCode V2 host versions accepted at setup. A host outside this range
16361
- * fails setup loudly instead of running against an unknown contract.
16362
- */
16363
- const SUPPORTED_V2_RANGE = ">=2.0.22 <3";
16364
- /**
16365
- * Guard the legacy adapter against incompatible client shapes.
16366
- *
16367
- * A client exposing only permission.reply does not satisfy the legacy
16368
- * transport contract. Product V2 uses its own setup entrypoint and adapter.
16369
- */
16370
- function assertV1Host(client) {
16371
- const record = client ?? {};
16372
- const permission = record.permission ?? {};
16373
- const raw = record._client ?? {};
16374
- if (typeof permission.reply === "function" && typeof raw.post !== "function") throw new Error("The V1 adapter requires the authenticated legacy transport. Use the setup entrypoint for OpenCode V2; refusing this incompatible client.");
16375
- }
16376
16636
  // src/adapters/opencode/reply-transport.ts
16377
16637
  /**
16378
16638
  * Resolve how a permission reply is sent. The priority is: a public SDK reply
@@ -18938,6 +19198,11 @@ const server = async (input, options) => {
18938
19198
  const writeAudit = createAuditWriter(config, config.debug ? logger : debugLogger);
18939
19199
  const probe = probeHostVersion(input.client);
18940
19200
  const hostVersion = probe === void 0 ? void 0 : await probe;
19201
+ const refusal = v1HostVersionRefusal(hostVersion);
19202
+ if (refusal !== void 0) {
19203
+ debugLogger(refusal);
19204
+ throw new Error(refusal);
19205
+ }
18941
19206
  const ctx = {
18942
19207
  ...hostVersion ? { hostVersion } : {},
18943
19208
  ...createV1Adapter({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noppu-labs/opencode-permission-reviewer",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Let OpenCode run unattended, securely: a System One or LLM reviewer answers permission prompts and asks you only when it should.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",