operon-agents-core 0.1.0-alpha.20 → 0.1.0-alpha.21

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.
@@ -32,6 +32,30 @@ const READS_ALL_ARGS = new Set([
32
32
  "cat", "head", "tail", "less", "more", "wc", "file", "stat", "nl", "od", "xxd", "strings",
33
33
  "base64", "md5sum", "sha1sum", "sha256sum", "shasum", "cmp", "diff", "sort", "readlink",
34
34
  ]);
35
+ /**
36
+ * Options of the read commands above that take a value as the next word (`head -n 100`), so
37
+ * the value is not mistaken for a file. A value glued to its option (`-n100`) is one word and
38
+ * already dropped as an option.
39
+ */
40
+ const OPTION_VALUES = {
41
+ head: new Set(["-n", "-c", "--lines", "--bytes"]),
42
+ tail: new Set(["-n", "-c", "--lines", "--bytes", "-s", "--sleep-interval", "--pid"]),
43
+ sort: new Set(["-k", "-t", "-S", "-T", "--key", "--field-separator", "--buffer-size", "--temporary-directory"]),
44
+ nl: new Set(["-b", "-d", "-f", "-h", "-i", "-l", "-n", "-s", "-v", "-w"]),
45
+ od: new Set(["-A", "-j", "-N", "-t", "-w"]),
46
+ xxd: new Set(["-c", "-g", "-l", "-o", "-s"]),
47
+ strings: new Set(["-n", "-t", "-e"]),
48
+ base64: new Set(["-w", "--wrap"]),
49
+ diff: new Set(["-U", "-C", "-L", "--label", "-I", "--ignore-matching-lines"]),
50
+ cmp: new Set(["-i", "-n", "--ignore-initial", "--bytes"]),
51
+ shasum: new Set(["-a", "--algorithm"]),
52
+ };
53
+ /**
54
+ * Character and stream devices a command reads or writes without touching a file: `2>/dev/null`
55
+ * is how a command discards its errors, not a write outside the workspace. Reporting them would
56
+ * prompt for exactly the most common harmless redirect.
57
+ */
58
+ const STREAM_DEVICE = /^\/dev\/(?:null|zero|u?random|stdin|stdout|stderr|tty|fd\/\d+)$/;
35
59
  /**
36
60
  * Split one simple command into words, tracking whether each is a knowable literal.
37
61
  *
@@ -180,17 +204,24 @@ function scriptCommandFiles(name, rawArgs) {
180
204
  const nonEmpty = operandWords.filter((word) => word.text.length > 0);
181
205
  return { inPlace, files: scriptIsAnOption ? nonEmpty : nonEmpty.slice(1) };
182
206
  }
183
- /** Drop option flags, and stop treating anything as an option after a bare `--`. */
184
- function operands(words) {
207
+ /**
208
+ * Drop option flags — and the value of an option in `withValue` — and stop treating anything as
209
+ * an option after a bare `--`.
210
+ */
211
+ function operands(words, withValue) {
185
212
  const result = [];
186
213
  let optionsEnded = false;
187
- for (const word of words) {
214
+ for (let i = 0; i < words.length; i++) {
215
+ const word = words[i];
188
216
  if (!optionsEnded && word.text === "--") {
189
217
  optionsEnded = true;
190
218
  continue;
191
219
  }
192
- if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1)
220
+ if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1) {
221
+ if (withValue?.has(word.text))
222
+ i++;
193
223
  continue;
224
+ }
194
225
  result.push(word);
195
226
  }
196
227
  return result;
@@ -219,8 +250,8 @@ export function extractBashPaths(command) {
219
250
  if (verb === undefined || !verb.literal)
220
251
  continue;
221
252
  const rawArgs = words.slice(1);
222
- const args = operands(rawArgs);
223
253
  const name = verb.text.replace(/^.*\//, ""); // /bin/rm → rm
254
+ const args = operands(rawArgs, OPTION_VALUES[name]);
224
255
  if (SCRIPT_COMMANDS.has(name)) {
225
256
  const { inPlace, files } = scriptCommandFiles(name, rawArgs);
226
257
  pushLiteral(files, inPlace ? "write" : "read", out);
@@ -242,6 +273,6 @@ export function extractBashPaths(command) {
242
273
  pushLiteral(args, "read", out);
243
274
  }
244
275
  }
245
- return out;
276
+ return out.filter((access) => !STREAM_DEVICE.test(access.path));
246
277
  }
247
278
  //# sourceMappingURL=bash-paths.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "operon-agents-core",
3
- "version": "0.1.0-alpha.20",
3
+ "version": "0.1.0-alpha.21",
4
4
  "description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
5
5
  "type": "module",
6
6
  "engines": {