loop-task 2.1.2 → 2.1.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.
@@ -4,7 +4,19 @@ import { formatDuration } from "../duration.js";
4
4
  import { t } from "../i18n/index.js";
5
5
  import { MAX_CONTEXT_STDOUT_BYTES } from "../config/constants.js";
6
6
  function quoteArg(arg) {
7
- return /[\s"]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
7
+ if (arg.length === 0)
8
+ return '""';
9
+ // If the arg already starts with a single quote (from interpolate's
10
+ // shellEscape), it's already safely shell-quoted — pass through as-is.
11
+ if (arg.startsWith("'") && arg.endsWith("'"))
12
+ return arg;
13
+ // Safe characters: no quoting needed
14
+ if (/^[A-Za-z0-9_\-=:./,@]+$/.test(arg))
15
+ return arg;
16
+ // Otherwise: double-quote and escape inner double-quotes.
17
+ // Replace newlines with spaces (shell command line is single-line).
18
+ const cleaned = arg.replace(/[\n\r]/g, " ");
19
+ return `"${cleaned.replace(/"/g, '\\"')}"`;
8
20
  }
9
21
  function formatCommandLine(command, commandArgs) {
10
22
  return [command, ...commandArgs.map((a) => quoteArg(a.replace(/[\n\r]/g, " ")))].join(" ").trim();
@@ -1,3 +1,20 @@
1
+ function shellEscape(value) {
2
+ if (value.length === 0)
3
+ return '""';
4
+ // If the value is purely safe characters, pass it through unmodified
5
+ if (/^[A-Za-z0-9_\-=:./,@]+$/.test(value))
6
+ return value;
7
+ // Escape characters that are dangerous inside double quotes, then wrap
8
+ // the whole value in single quotes — the strongest shell quoting.
9
+ // Single quotes preserve everything literally (newlines, backticks,
10
+ // $, ", \, parens) except single quotes themselves.
11
+ return "'" + value.replace(/'/g, "'\\''") + "'";
12
+ }
1
13
  export function interpolate(input, context) {
2
- return input.replace(/{{(\w+)}}/g, (_, key) => String(context[key] ?? ""));
14
+ return input.replace(/{{(\w+)}}/g, (_, key) => {
15
+ const raw = context[key];
16
+ if (raw === undefined || raw === null)
17
+ return "";
18
+ return shellEscape(String(raw));
19
+ });
3
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loop-task",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Loop engineering toolkit. Run any command on a cadence, in the background, managed from a terminal board. Schedule tests, builds, syncs, or agent prompts.",
5
5
  "type": "module",
6
6
  "bin": {