replicas-engine 0.1.933 → 0.1.934

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.
@@ -2062,6 +2062,313 @@ function normalizeBackgroundTaskStatus(status) {
2062
2062
  // ../shared/src/display-message/constants.ts
2063
2063
  var USER_MESSAGE_MATCH_GRACE_PERIOD_MS = 3e4;
2064
2064
 
2065
+ // ../shared/src/shell-commands.ts
2066
+ var SHELL_OPAQUE = "\0";
2067
+ var MAX_DEPTH = 8;
2068
+ var OPERATOR = /&&|\|\||;;|\|&|<<<|<<-|<<|&>>|&>|>>|>&|>\||<&|<>|[;&|()<>]/y;
2069
+ var NAME = /[A-Za-z_]\w*/y;
2070
+ var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh"]);
2071
+ var PREFIX_WORDS = /* @__PURE__ */ new Set(["!", "{", "}", "if", "then", "else", "elif", "fi", "do", "done", "while", "until", "time", "exec", "command", "builtin", "nohup"]);
2072
+ var WRAPPER_VALUE_OPTIONS = {
2073
+ env: /^(?:-[uCS]|--(?:unset|chdir|split-string))$/,
2074
+ sudo: /^(?:-[ugCpUrhDRT]|--(?:user|group|close-from|prompt|other-user|role|type|host|chdir|command-timeout))$/,
2075
+ nice: /^(?:-n|--adjustment)$/,
2076
+ timeout: /^(?:-[sk]|--(?:signal|kill-after))$/
2077
+ };
2078
+ var ANSI_C_ESCAPES = { n: "\n", t: " ", r: "\r", a: "\x07", b: "\b", e: "\x1B", E: "\x1B", f: "\f", v: "\v" };
2079
+ function parseShellScript(script, cwd) {
2080
+ const scope = { src: script, vars: /* @__PURE__ */ new Map(), dir: cwd, commands: [], depth: 0 };
2081
+ parseUntil(scope, 0, false);
2082
+ return scope.commands;
2083
+ }
2084
+ function resolveShellPath(dir, path) {
2085
+ if (path.includes(SHELL_OPAQUE) || path.startsWith("~")) return null;
2086
+ if (!path.startsWith("/") && dir === null) return null;
2087
+ const parts = [];
2088
+ for (const part of (path.startsWith("/") ? path : `${dir}/${path}`).split("/")) {
2089
+ if (part === "..") parts.pop();
2090
+ else if (part && part !== ".") parts.push(part);
2091
+ }
2092
+ return `/${parts.join("/")}`;
2093
+ }
2094
+ function stripCommandPrefixes(words) {
2095
+ const assignments = [];
2096
+ let k = 0;
2097
+ while (k < words.length) {
2098
+ const word = words[k];
2099
+ if (/^[A-Za-z_]\w*=/.test(word)) assignments.push(word);
2100
+ else if (WRAPPER_VALUE_OPTIONS[word]) {
2101
+ while (words[k + 1]?.startsWith("-")) k += WRAPPER_VALUE_OPTIONS[word].test(words[k + 1]) ? 2 : 1;
2102
+ if (word === "timeout") k++;
2103
+ } else if (!PREFIX_WORDS.has(word)) break;
2104
+ k++;
2105
+ }
2106
+ return { argv: words.slice(k), assignments };
2107
+ }
2108
+ function indexOrEnd(src, search, from) {
2109
+ const index = src.indexOf(search, from);
2110
+ return index < 0 ? src.length : index;
2111
+ }
2112
+ function decodeAnsiC(text2) {
2113
+ return text2.replace(/\\(x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|[0-7]{1,3}|[\s\S])/g, (_match, escape) => {
2114
+ if (escape[0] === "x" || escape[0] === "u") return String.fromCharCode(parseInt(escape.slice(1), 16));
2115
+ if (/^[0-7]/.test(escape)) return String.fromCharCode(parseInt(escape, 8));
2116
+ return ANSI_C_ESCAPES[escape] ?? escape;
2117
+ });
2118
+ }
2119
+ function staticOutput(argv, stdin) {
2120
+ const [name, ...args] = argv;
2121
+ if (name === "cat") return args.length === 0 || args.length === 1 && args[0] === "-" ? stdin : void 0;
2122
+ if (name === "echo") {
2123
+ let newline = true;
2124
+ let escapes = false;
2125
+ while (/^-[neE]+$/.test(args[0] ?? "")) {
2126
+ const flags = args.shift() ?? "";
2127
+ if (flags.includes("n")) newline = false;
2128
+ if (flags.includes("e")) escapes = true;
2129
+ }
2130
+ const text2 = args.join(" ");
2131
+ return (escapes ? decodeAnsiC(text2) : text2) + (newline ? "\n" : "");
2132
+ }
2133
+ if (name === "printf" && args.length > 0) {
2134
+ const format = decodeAnsiC(args[0]);
2135
+ if (/%(?![s%])/.test(format)) return void 0;
2136
+ const values = args.slice(1);
2137
+ let output = "";
2138
+ let next = 0;
2139
+ do {
2140
+ output += format.replace(/%([s%])/g, (_match, directive) => directive === "%" ? "%" : values[next++] ?? "");
2141
+ } while (format.includes("%s") && next < values.length);
2142
+ return output;
2143
+ }
2144
+ return void 0;
2145
+ }
2146
+ function commandStdin(raw) {
2147
+ const heredoc = raw.heredocs.at(-1);
2148
+ if (heredoc) return heredoc.body;
2149
+ const input = raw.redirects.findLast(({ op }) => op === "<<<" || op === "<" || op === "0<");
2150
+ if (input) return input.op === "<<<" ? `${input.target}
2151
+ ` : SHELL_OPAQUE;
2152
+ if (raw.pipeFrom) return staticOutput(stripCommandPrefixes(raw.pipeFrom.words).argv, commandStdin(raw.pipeFrom)) ?? SHELL_OPAQUE;
2153
+ return void 0;
2154
+ }
2155
+ function assign(scope, assignments) {
2156
+ for (const assignment of assignments) {
2157
+ const separator = assignment.indexOf("=");
2158
+ scope.vars.set(assignment.slice(0, separator), assignment.slice(separator + 1));
2159
+ }
2160
+ }
2161
+ function emit(scope, raw) {
2162
+ const { argv, assignments } = stripCommandPrefixes(raw.words);
2163
+ if (argv.length === 0) {
2164
+ assign(scope, assignments);
2165
+ return;
2166
+ }
2167
+ const stdin = commandStdin(raw);
2168
+ const output = staticOutput(argv, stdin) ?? SHELL_OPAQUE;
2169
+ const stdinFile = raw.redirects.findLast(({ op }) => op === "<" || op === "0<");
2170
+ const name = argv[0].split("/").pop() ?? "";
2171
+ const flag = SHELLS.has(name) ? argv.findIndex((arg, index) => index > 0 && /^-[A-Za-z]*c[A-Za-z]*$/.test(arg)) : -1;
2172
+ const script = flag > 0 ? argv[flag + 1] : SHELLS.has(name) && argv.length === 1 && stdin !== SHELL_OPAQUE ? stdin : name === "eval" ? argv.slice(1).join(" ") : void 0;
2173
+ const truncated = script !== void 0 && scope.depth >= MAX_DEPTH;
2174
+ scope.commands.push({
2175
+ argv,
2176
+ dir: scope.dir,
2177
+ stdin,
2178
+ afterAnd: raw.afterAnd,
2179
+ stdinFile: stdinFile ? resolveShellPath(scope.dir, stdinFile.target) : null,
2180
+ writes: raw.redirects.flatMap(({ op, target }) => /^(?:1?>|1?>\||1?>>|&>|&>>|>&)$/.test(op) && !/^(?:\d+|-)$/.test(target) ? [{ path: resolveShellPath(scope.dir, target), content: output, append: op.endsWith(">>") }] : []),
2181
+ wrapper: script !== void 0,
2182
+ truncated
2183
+ });
2184
+ if (name === "cd" || name === "pushd" || name === "popd") {
2185
+ scope.dir = name !== "popd" && argv[1] && argv[1] !== "-" ? resolveShellPath(scope.dir, argv[1]) : null;
2186
+ } else if (["export", "declare", "local", "readonly"].includes(name)) {
2187
+ assign(scope, argv.slice(1).filter((arg) => /^[A-Za-z_]\w*=/.test(arg)));
2188
+ }
2189
+ if (script && !truncated) parseUntil({ src: script, vars: name === "eval" ? scope.vars : /* @__PURE__ */ new Map(), dir: scope.dir, commands: scope.commands, depth: scope.depth + 1 }, 0, false);
2190
+ }
2191
+ function readHeredocBodies(scope, heredocs, start) {
2192
+ const { src } = scope;
2193
+ let position = start;
2194
+ for (const heredoc of heredocs) {
2195
+ const lines = [];
2196
+ while (position < src.length) {
2197
+ const end = indexOrEnd(src, "\n", position);
2198
+ const line = heredoc.strip ? src.slice(position, end).replace(/^\t+/, "") : src.slice(position, end);
2199
+ position = end + 1;
2200
+ if (line === heredoc.delimiter) break;
2201
+ lines.push(line);
2202
+ }
2203
+ heredoc.body = lines.length > 0 ? `${lines.join("\n")}
2204
+ ` : "";
2205
+ if (heredoc.expand) heredoc.body = readDoubleQuoted({ ...scope, src: heredoc.body }, 0, null).value;
2206
+ }
2207
+ return Math.min(position, src.length);
2208
+ }
2209
+ function readDoubleQuoted(scope, start, terminator) {
2210
+ const { src } = scope;
2211
+ let value = "";
2212
+ let i = start;
2213
+ while (i < src.length && src[i] !== terminator) {
2214
+ const c = src[i];
2215
+ if (c === "\\" && i + 1 < src.length) {
2216
+ const next = src[i + 1];
2217
+ if (next === "\n") i += 2;
2218
+ else if ("$`\\".includes(next) || next === terminator) {
2219
+ value += next;
2220
+ i += 2;
2221
+ } else {
2222
+ value += c;
2223
+ i++;
2224
+ }
2225
+ } else if (c === "$" || c === "`") {
2226
+ const expansion = readExpansion(scope, i, true);
2227
+ value += expansion.value;
2228
+ i = expansion.end;
2229
+ } else {
2230
+ value += c;
2231
+ i++;
2232
+ }
2233
+ }
2234
+ return { value, end: i };
2235
+ }
2236
+ function substitute(scope, src, start, closeParen) {
2237
+ const child = { src, vars: new Map(scope.vars), dir: scope.dir, commands: [], depth: scope.depth + 1 };
2238
+ const end = parseUntil(child, start, closeParen);
2239
+ scope.commands.push(...child.commands);
2240
+ const [only] = child.commands;
2241
+ const output = child.commands.length === 1 ? staticOutput(only.argv, only.stdin) : void 0;
2242
+ return { value: output?.replace(/\n+$/, "") ?? SHELL_OPAQUE, end };
2243
+ }
2244
+ function readExpansion(scope, i, inDouble) {
2245
+ const { src } = scope;
2246
+ if (src[i] === "`") {
2247
+ let inner = "";
2248
+ let j = i + 1;
2249
+ while (j < src.length && src[j] !== "`") {
2250
+ if (src[j] === "\\" && "$`\\".includes(src[j + 1] ?? "")) {
2251
+ inner += src[j + 1];
2252
+ j += 2;
2253
+ } else inner += src[j++];
2254
+ }
2255
+ return { value: substitute(scope, inner, 0, false).value, end: j + 1 };
2256
+ }
2257
+ const next = src[i + 1];
2258
+ if (next === "(") return substitute(scope, src, i + 2, true);
2259
+ if (next === "{") {
2260
+ const end = indexOrEnd(src, "}", i + 2);
2261
+ return { value: scope.vars.get(src.slice(i + 2, end)) ?? SHELL_OPAQUE, end: end + 1 };
2262
+ }
2263
+ if (next === "'" && !inDouble) {
2264
+ let j = i + 2;
2265
+ while (j < src.length && src[j] !== "'") j += src[j] === "\\" ? 2 : 1;
2266
+ return { value: decodeAnsiC(src.slice(i + 2, j)), end: j + 1, quoted: true };
2267
+ }
2268
+ if (next === '"' && !inDouble) {
2269
+ const { value, end } = readDoubleQuoted(scope, i + 2, '"');
2270
+ return { value, end: end + 1, quoted: true };
2271
+ }
2272
+ NAME.lastIndex = i + 1;
2273
+ const name = NAME.exec(src)?.[0];
2274
+ if (name) return { value: scope.vars.get(name) ?? SHELL_OPAQUE, end: i + 1 + name.length };
2275
+ if (next && /[0-9@*#?$!-]/.test(next)) return { value: SHELL_OPAQUE, end: i + 2 };
2276
+ return { value: "$", end: i + 1 };
2277
+ }
2278
+ function parseUntil(scope, start, closeParen) {
2279
+ const { src } = scope;
2280
+ let i = start;
2281
+ let line = [];
2282
+ let current = { words: [], redirects: [], heredocs: [], afterAnd: false };
2283
+ let pendingHeredocs = [];
2284
+ let word = null;
2285
+ let quoted = false;
2286
+ let redirect = null;
2287
+ let parens = 0;
2288
+ const append = (text2, isQuoted = false) => {
2289
+ word = (word ?? "") + text2;
2290
+ quoted ||= isQuoted;
2291
+ };
2292
+ const endWord = () => {
2293
+ if (word === null) return;
2294
+ if (redirect === "<<" || redirect === "<<-") {
2295
+ const heredoc = { strip: redirect === "<<-", delimiter: word, expand: !quoted, body: "" };
2296
+ current.heredocs.push(heredoc);
2297
+ pendingHeredocs.push(heredoc);
2298
+ } else if (redirect) {
2299
+ current.redirects.push({ op: redirect, target: word });
2300
+ } else {
2301
+ current.words.push(word);
2302
+ }
2303
+ word = null;
2304
+ quoted = false;
2305
+ redirect = null;
2306
+ };
2307
+ const endCommand = (op) => {
2308
+ endWord();
2309
+ const done = current;
2310
+ current = { words: [], redirects: [], heredocs: [], pipeFrom: op === "|" || op === "|&" ? done : void 0, afterAnd: op === "&&" };
2311
+ if (done.words.length > 0 || done.redirects.length > 0 || done.heredocs.length > 0) line.push(done);
2312
+ };
2313
+ const flush = () => {
2314
+ endCommand();
2315
+ for (const raw of line) emit(scope, raw);
2316
+ line = [];
2317
+ };
2318
+ while (i < src.length) {
2319
+ const c = src[i];
2320
+ if (c === "\\") {
2321
+ if (src[i + 1] !== "\n") append(src[i + 1] ?? "", true);
2322
+ i += 2;
2323
+ } else if (c === "'") {
2324
+ const end = indexOrEnd(src, "'", i + 1);
2325
+ append(src.slice(i + 1, end), true);
2326
+ i = end + 1;
2327
+ } else if (c === '"') {
2328
+ const { value, end } = readDoubleQuoted(scope, i + 1, '"');
2329
+ append(value, true);
2330
+ i = end + 1;
2331
+ } else if (c === "$" || c === "`") {
2332
+ const expansion = readExpansion(scope, i, false);
2333
+ append(expansion.value, expansion.quoted);
2334
+ i = expansion.end;
2335
+ } else if (c === "#" && word === null) {
2336
+ i = indexOrEnd(src, "\n", i);
2337
+ } else if (c === "\n") {
2338
+ endWord();
2339
+ i = readHeredocBodies(scope, pendingHeredocs, i + 1);
2340
+ pendingHeredocs = [];
2341
+ flush();
2342
+ } else if (c === " " || c === " " || c === "\r") {
2343
+ endWord();
2344
+ i++;
2345
+ } else if (c === ")" && parens === 0 && closeParen) {
2346
+ flush();
2347
+ return i + 1;
2348
+ } else {
2349
+ OPERATOR.lastIndex = i;
2350
+ const op = OPERATOR.exec(src)?.[0];
2351
+ if (!op) {
2352
+ append(c);
2353
+ i++;
2354
+ continue;
2355
+ }
2356
+ const fd = /[<>]/.test(op) && !quoted && /^\d+$/.test(word ?? "") ? word : null;
2357
+ if (fd !== null) word = null;
2358
+ endWord();
2359
+ i += op.length;
2360
+ if (/[<>]/.test(op)) redirect = `${fd ?? ""}${op}`;
2361
+ else {
2362
+ if (op === "(") parens++;
2363
+ if (op === ")") parens = Math.max(0, parens - 1);
2364
+ endCommand(op);
2365
+ }
2366
+ }
2367
+ }
2368
+ flush();
2369
+ return i;
2370
+ }
2371
+
2065
2372
  // ../shared/src/display-message/parsers/utils.ts
2066
2373
  var INTERRUPTED_MESSAGE_REGEX = /^\[Request interrupted by user.*\]$/;
2067
2374
  function userMessageImages(value) {
@@ -2207,61 +2514,11 @@ ${operation.diff}` : ""}`).join("\n\n");
2207
2514
  if (message.type === "interruption") return { kind: "error", title: "Agent stopped", summary: "", content: "" };
2208
2515
  return { kind: "error", title: "Agent error", summary: "", content: message.message };
2209
2516
  }
2210
- function unquoteShellArg(value) {
2211
- const trimmed = value.trim();
2212
- if (trimmed.length < 2) return trimmed;
2213
- if (trimmed[0] === "'" && trimmed[trimmed.length - 1] === "'") {
2214
- return trimmed.slice(1, -1).replace(/'\\''/g, "'");
2215
- }
2216
- if (trimmed[0] === '"' && trimmed[trimmed.length - 1] === '"') {
2217
- return trimmed.slice(1, -1).replace(/\\(["\\$`])/g, "$1");
2218
- }
2219
- return trimmed;
2220
- }
2221
- function shellPayload(command) {
2222
- const match = command.trim().match(/^(?:\S*\/)?(?:ba|z|c|fi)?sh\s+-(?:[a-zA-Z]*c[a-zA-Z]*|c)\s+([\s\S]+)$/);
2223
- return match ? unquoteShellArg(match[1]) : command.trim();
2224
- }
2225
- function splitShellWords(command) {
2226
- const words = [];
2227
- let word = "";
2228
- let quote = null;
2229
- let escaped = false;
2230
- for (const char of command) {
2231
- if (escaped) {
2232
- word += char;
2233
- escaped = false;
2234
- continue;
2235
- }
2236
- if (char === "\\" && quote !== "'") {
2237
- escaped = true;
2238
- continue;
2239
- }
2240
- if (quote) {
2241
- if (char === quote) quote = null;
2242
- else word += char;
2243
- continue;
2244
- }
2245
- if (char === '"' || char === "'") {
2246
- quote = char;
2247
- continue;
2248
- }
2249
- if (/\s/.test(char)) {
2250
- if (word) {
2251
- words.push(word);
2252
- word = "";
2253
- }
2254
- continue;
2255
- }
2256
- word += char;
2257
- }
2258
- if (word) words.push(word);
2259
- return words;
2260
- }
2261
2517
  function commandWords(command) {
2262
- const payload = shellPayload(command);
2263
- if (!payload || /[;|<>]|&&/.test(payload)) return null;
2264
- return splitShellWords(payload);
2518
+ const commands = parseShellScript(command, null).filter(({ wrapper }) => !wrapper);
2519
+ if (commands.length !== 1) return null;
2520
+ const [{ argv, stdin, stdinFile, writes }] = commands;
2521
+ return stdin === void 0 && !stdinFile && writes.length === 0 ? argv.map((word) => word.replaceAll(SHELL_OPAQUE, "\u2026")) : null;
2265
2522
  }
2266
2523
  function skillNamesFromCommand(command) {
2267
2524
  const words = commandWords(command);
@@ -7066,6 +7323,120 @@ var CLAUDE_AUTH_ENV_KEYS_BY_METHOD = {
7066
7323
  };
7067
7324
 
7068
7325
  // ../shared/src/routes/command-protection.ts
7326
+ import { z as z10 } from "zod";
7327
+
7328
+ // ../shared/src/git-invocations.ts
7329
+ var COMMIT_VALUE_OPTIONS = /* @__PURE__ */ new Set(["message", "file", "trailer", "reuse-message", "reedit-message", "fixup", "squash", "template", "author", "date", "cleanup", "pathspec-from-file"]);
7330
+ function findGitInvocations(commands) {
7331
+ return commands.flatMap((command) => {
7332
+ const { argv } = command;
7333
+ if (argv[0].split("/").pop() !== "git") return [];
7334
+ let dir = command.dir;
7335
+ let index = 1;
7336
+ for (; argv[index]?.startsWith("-"); index++) {
7337
+ if (argv[index] === "-C" && argv[index + 1]) dir = resolveShellPath(dir, argv[index + 1]);
7338
+ if (/^--(?:git-dir|work-tree)\b/.test(argv[index])) dir = null;
7339
+ if (["-C", "-c", "--git-dir", "--work-tree", "--namespace"].includes(argv[index])) index++;
7340
+ }
7341
+ return argv[index] ? [{ dir, subcommand: argv[index], args: argv.slice(index + 1), command }] : [];
7342
+ });
7343
+ }
7344
+ function parseCommitArgs(args) {
7345
+ const messages = [];
7346
+ const trailers = [];
7347
+ let file;
7348
+ let reuse = false;
7349
+ let amend = false;
7350
+ for (let index = 0; index < args.length && args[index] !== "--"; index++) {
7351
+ const arg = args[index];
7352
+ const long = /^--([\w-]+)(?:=([\s\S]*))?$/.exec(arg);
7353
+ if (long) {
7354
+ const [, name, inline] = long;
7355
+ if (name === "amend") amend = true;
7356
+ if (!COMMIT_VALUE_OPTIONS.has(name)) continue;
7357
+ const value = inline ?? args[++index] ?? "";
7358
+ if (name === "message") messages.push(value);
7359
+ else if (name === "file") file = value;
7360
+ else if (name === "trailer") trailers.push(value);
7361
+ else if (["reuse-message", "reedit-message", "fixup", "squash"].includes(name)) reuse = true;
7362
+ continue;
7363
+ }
7364
+ if (!/^-[^-]/.test(arg)) continue;
7365
+ for (let position = 1; position < arg.length && !"Su".includes(arg[position]); position++) {
7366
+ const flag = arg[position];
7367
+ if (!"mFCct".includes(flag)) continue;
7368
+ const value = arg.slice(position + 1) || (args[++index] ?? "");
7369
+ if (flag === "m") messages.push(value);
7370
+ else if (flag === "F") file = value;
7371
+ else if (flag !== "t") reuse = true;
7372
+ break;
7373
+ }
7374
+ }
7375
+ return { messages, trailers, file, reuse, amend };
7376
+ }
7377
+ function parsePushArgs(args) {
7378
+ const positionals = [];
7379
+ const options = [];
7380
+ let all = false;
7381
+ let tags = false;
7382
+ let repo = false;
7383
+ for (let index = 0; index < args.length; index++) {
7384
+ const arg = args[index];
7385
+ const long = /^--([\w-]+)(?:=([\s\S]*))?$/.exec(arg);
7386
+ if (arg === "--") {
7387
+ positionals.push(...args.slice(index + 1));
7388
+ break;
7389
+ } else if (long) {
7390
+ const [, name, inline] = long;
7391
+ all ||= ["all", "mirror", "branches"].includes(name);
7392
+ tags ||= name === "tags";
7393
+ repo ||= name === "repo";
7394
+ if (["repo", "push-option", "receive-pack", "exec"].includes(name)) {
7395
+ const value = inline ?? args[++index] ?? "";
7396
+ if (name === "push-option") options.push(value);
7397
+ }
7398
+ } else if (/^-[^-]/.test(arg)) {
7399
+ const option = arg.indexOf("o");
7400
+ if (option > 0) options.push(arg.slice(option + 1) || (args[++index] ?? ""));
7401
+ } else {
7402
+ positionals.push(arg);
7403
+ }
7404
+ }
7405
+ return { refspecs: repo ? positionals : positionals.slice(1), options, all, tags };
7406
+ }
7407
+ function findCheckoutTarget(args) {
7408
+ if (args.includes("--")) return void 0;
7409
+ const create = args.findIndex((arg) => /^(?:-[bBcC]|--orphan)$/.test(arg));
7410
+ if (create >= 0) return { branch: args[create + 1] ?? null, certain: true };
7411
+ if (args.some((arg) => arg === "-" || arg === "--detach" || arg === "-d")) return { branch: null, certain: true };
7412
+ const positional = args.find((arg) => !arg.startsWith("-"));
7413
+ return positional === void 0 ? void 0 : { branch: positional, certain: false };
7414
+ }
7415
+
7416
+ // ../shared/src/routes/command-protection.ts
7417
+ var commandProtectionRepoStateSchema = z10.object({
7418
+ branch: z10.string().nullable(),
7419
+ defaultBranch: z10.string().nullable(),
7420
+ pushBranch: z10.string().nullable(),
7421
+ pushConfig: z10.string().nullable(),
7422
+ headMessage: z10.string().nullable(),
7423
+ mergeInProgress: z10.boolean().optional()
7424
+ });
7425
+ var commandProtectionEvaluateRequestSchema = z10.object({
7426
+ provider: z10.enum(["claude", "codex", "cursor", "opencode", "pi"]),
7427
+ source: z10.enum(["claude_pre_tool_use", "codex_approval_request", "cursor_pre_tool_use", "opencode_pre_tool_use", "pi_tool_call"]),
7428
+ toolName: z10.string(),
7429
+ toolInput: z10.unknown(),
7430
+ command: z10.string().nullish(),
7431
+ cwd: z10.string().nullish(),
7432
+ toolUseId: z10.string().nullish(),
7433
+ // Read by the engine before the command runs, keyed by absolute path, so the
7434
+ // policy can see branches and commit messages the command text only references.
7435
+ gitContext: z10.object({
7436
+ repos: z10.record(z10.string(), commandProtectionRepoStateSchema),
7437
+ messageFiles: z10.record(z10.string(), z10.string())
7438
+ }).optional()
7439
+ });
7069
7440
  var COMMAND_PROTECTION_COMMAND_KEYS = ["command", "cmd", "script", "query", "endpoint", "path", "url", "mutation"];
7070
7441
  function stringifyCommandProtectionInput(value) {
7071
7442
  if (typeof value === "string") return value;
@@ -7096,41 +7467,152 @@ function extractCommandProtectionCommandText(request, options = {}) {
7096
7467
  if (typeof input === "string") return input;
7097
7468
  return options.stringifyFallback ? stringifyCommandProtectionInput(input) : null;
7098
7469
  }
7099
- function findPrMergeSignals(request) {
7100
- const command = normalizeCommandProtectionText(extractCommandProtectionCommandText(request, { stringifyFallback: true }) ?? "");
7101
- const input = normalizeCommandProtectionText(stringifyCommandProtectionInput(request.toolInput));
7102
- const combined = `${request.toolName.toLowerCase()} ${command} ${input}`;
7103
- const checks = [
7104
- ["gh-pr-merge", /\bgh\s+pr\s+merge\b/],
7105
- ["gh-api-pulls-merge", /\bgh\s+api\b[\s\S]*\/pulls\/(?:\d+|[^/\s]+)\/merge\b/],
7106
- ["github-rest-pulls-merge", /api\.github\.com\/repos\/[^/\s]+\/[^/\s]+\/pulls\/(?:\d+|[^/\s]+)\/merge\b/],
7107
- ["gitlab-rest-mr-merge", /\/projects\/[^/\s]+\/merge_requests\/(?:\d+|[^/\s]+)\/merge\b/],
7108
- ["gitlab-rest-mr-merge-query", /\/projects\/[^/\s]+\/merge_requests\/(?:\d+|[^/\s]+)\b[\s\S]*\bmerge_when_pipeline_succeeds\b/],
7109
- ["github-rest-ref-update", /\b(?:gh\s+api|curl|wget|python3?)\b[\s\S]*(?:\/repos\/|repos\/)[^/\s]+\/[^/\s]+\/git\/refs\/heads\/(?:main|master|trunk|develop)\b[\s\S]*\b(?:patch|put|sha|oid|force)\b/],
7110
- ["github-graphql-merge-pr", /\bmergepullrequest\b/],
7111
- ["github-graphql-enable-auto-merge", /\benablepullrequestautomerge\b/],
7112
- ["github-graphql-update-ref", /\bupdateref\b/],
7113
- ["git-merge-default-branch", /\bgit\s+(?:checkout|switch)\s+(?:main|master|trunk|develop)\b[\s\S]*\bgit\s+merge\b/],
7114
- ["git-merge-standalone", /\bgit\s+merge\s+(?:origin\/)?(main|master|trunk|develop)\b/],
7115
- ["git-push-main", /\bgit\s+push\b[\s\S]*\b(origin\s+)?(main|master|trunk|develop)\b/],
7116
- ["git-push-refspec-default-branch", /\bgit\s+push\b[\s\S]*\S+:(?:refs\/heads\/)?(main|master|trunk|develop)\b/],
7117
- ["git-cherry-pick-default-branch", /\bgit\s+(?:checkout|switch)\s+(?:main|master|trunk|develop)\b[\s\S]*\bgit\s+cherry-pick\b[\s\S]*\bgit\s+push\b/],
7118
- ["git-push-all", /\bgit\s+push\s+(-[^\s]+\s+)*(--all|--mirror)\b/],
7119
- ["git-push-bare", /\bgit\s+push\s*(?:["{}\[\]]|$)/],
7120
- ["hub-merge", /\bhub\s+merge\b/],
7121
- ["obfuscated-gh-pr-merge", /printf\s+['"]\\x67\\x68['"][\s\S]*\bpr\b[\s\S]*printf\s+['"]m\\x65rge['"]/],
7122
- ["mcp-merge-tool", /\bmcp__[^\s"]*merge[^\s"]*\b/],
7123
- ["tool-merge-name", /\b(pr|pull[_-]?request|mr|merge[_-]?request).{0,40}\bmerge\b|\bmerge.{0,40}(pr|pull[_-]?request|mr|merge[_-]?request)\b/],
7124
- ["merge-word", /(?:^|[^a-z0-9])merge(?:$|[^a-z0-9])/]
7125
- ];
7126
- return checks.flatMap(([name, pattern]) => pattern.test(combined) ? [name] : []);
7127
- }
7128
- function findGitCommitCommands(command) {
7129
- return [...command.matchAll(/\bgit(?:\s+-[^\s;&|]+(?:\s+(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\s;&|]+))?)*\s+commit\b(?:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\\\r?\n|[^;&|\r\n])*)/g)].map((match) => match[0]);
7470
+ var PROTECTED_BRANCH = /^(?:main|master|trunk|develop)$/;
7471
+ var AUTO_MERGE_PUSH_OPTION = /merge_when_pipeline_succeeds|auto_merge/i;
7472
+ var CONFIGURED_AUTO_MERGE_PUSH_OPTION = /^push\.pushoption[ =].*(?:merge_when_pipeline_succeeds|auto_merge)/im;
7473
+ var MERGE_SIGNAL_CHECKS = [
7474
+ ["gh-pr-merge", /\bgh\s+pr\s+merge\b/],
7475
+ ["glab-mr-merge", /\bglab\s+mr\s+merge\b/],
7476
+ ["gh-api-pulls-merge", /\bgh\s+api\b[\s\S]*\/pulls\/(?:\d+|[^/\s]+)\/merge\b/],
7477
+ ["github-rest-pulls-merge", /api\.github\.com\/repos\/[^/\s]+\/[^/\s]+\/pulls\/(?:\d+|[^/\s]+)\/merge\b/],
7478
+ ["gitlab-rest-mr-merge", /\/projects\/[^/\s]+\/merge_requests\/(?:\d+|[^/\s]+)\/merge\b/],
7479
+ ["gitlab-rest-mr-merge-query", /\/projects\/[^/\s]+\/merge_requests\/(?:\d+|[^/\s]+)\b[\s\S]*\bmerge_when_pipeline_succeeds\b/],
7480
+ ["github-rest-ref-update", /\b(?:gh\s+api|curl|wget|python3?)\b[\s\S]*(?:\/repos\/|repos\/)[^/\s]+\/[^/\s]+\/git\/refs\/heads\/(?:main|master|trunk|develop)\b[\s\S]*\b(?:patch|put|sha|oid|force)\b/],
7481
+ ["github-graphql-merge-pr", /\bmergepullrequest\b/],
7482
+ ["github-graphql-enable-auto-merge", /\benablepullrequestautomerge\b/],
7483
+ ["github-graphql-update-ref", /\bupdateref\b/],
7484
+ ["hub-merge", /\bhub\s+merge\b/],
7485
+ ["obfuscated-gh-pr-merge", /printf\s+['"]?\\x67\\x68['"]?[\s\S]*\bpr\b[\s\S]*printf\s+['"]?m\\x65rge['"]?/],
7486
+ ["mcp-merge-tool", /\bmcp__[^\s"]*merge[^\s"]*\b/]
7487
+ ];
7488
+ var BROAD_MERGE_SIGNAL_CHECKS = [
7489
+ ["git-push-default-branch-text", /\bgit\s+push\b[^;&|\n]*?\s(?:\S+:)?(?:refs\/heads\/)?(?:main|master|trunk|develop)\b/],
7490
+ ["tool-merge-name", /\b(pr|pull[_-]?request|mr|merge[_-]?request).{0,40}\bmerge\b|\bmerge.{0,40}(pr|pull[_-]?request|mr|merge[_-]?request)\b/],
7491
+ ["merge-word", /(?:^|[^a-z0-9])merge(?:$|[^a-z0-9])/]
7492
+ ];
7493
+ function shellScript(input) {
7494
+ if (typeof input === "string") return input;
7495
+ if (!isRecord(input)) return null;
7496
+ for (const key of ["command", "cmd", "script"]) {
7497
+ const value = input[key];
7498
+ if (typeof value === "string") return value;
7499
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) return value.map(shellQuotePosix).join(" ");
7500
+ }
7501
+ return isRecord(input.args) ? shellScript(input.args) : null;
7502
+ }
7503
+ function workingDirectory({ toolInput, cwd }) {
7504
+ const input = isRecord(toolInput) ? toolInput : {};
7505
+ const dir = [input.workdir, input.cwd].find((value) => typeof value === "string" && value.trim() !== "");
7506
+ return dir ? resolveShellPath(cwd || null, dir) : cwd || null;
7507
+ }
7508
+ function parseCommandProtectionRequest(request) {
7509
+ const script = shellScript(request.toolInput);
7510
+ const dir = workingDirectory(request);
7511
+ const commands = script === null ? [] : parseShellScript(script, dir);
7512
+ return { request, script, workingDirectory: dir, commands, invocations: findGitInvocations(commands), truncated: commands.some(({ truncated }) => truncated) };
7513
+ }
7514
+ var isProtectedBranch = (branch, repo) => branch === repo?.defaultBranch || PROTECTED_BRANCH.test(branch);
7515
+ function trackCheckedOutBranches(commands, invocations, context) {
7516
+ const switches = /* @__PURE__ */ new Map();
7517
+ return invocations.map(({ dir, subcommand, args, command }) => {
7518
+ const repo = dir === null ? void 0 : context?.repos[dir];
7519
+ const index = commands.indexOf(command);
7520
+ const last = switches.get(dir);
7521
+ const mayStayOnBefore = last !== void 0 && !commands.slice(last.index + 1, index + 1).every(({ afterAnd }) => afterAnd);
7522
+ const branch = last === void 0 ? repo?.branch ?? null : mayStayOnBefore && (last.before === null || isProtectedBranch(last.before, repo)) ? null : last.branch;
7523
+ const target = subcommand === "checkout" || subcommand === "switch" ? findCheckoutTarget(args) : void 0;
7524
+ if (target) {
7525
+ const trusted = target.certain || isProtectedBranch(target.branch ?? "", repo) || branch !== null && !isProtectedBranch(branch, repo);
7526
+ switches.set(dir, { branch: trusted ? target.branch : null, before: branch, index });
7527
+ }
7528
+ return { branch, switched: last !== void 0 };
7529
+ });
7130
7530
  }
7131
- function findGitCommitSignals(request) {
7132
- const command = extractCommandProtectionCommandText(request, { stringifyFallback: true }) ?? "";
7133
- return findGitCommitCommands(command).length > 0 ? ["git-commit"] : [];
7531
+ function refspecDestination(refspec, current) {
7532
+ const spec = refspec.replace(/^\+/, "");
7533
+ const destination = spec.slice(spec.indexOf(":") + 1);
7534
+ if (destination === "" || destination.includes("*")) return "*";
7535
+ if (destination.includes(SHELL_OPAQUE)) return null;
7536
+ if (destination === "HEAD" || destination === "@") return current;
7537
+ return destination.startsWith("refs/tags/") ? void 0 : destination.replace(/^refs\/heads\//, "");
7538
+ }
7539
+ function findPushSignals({ commands, invocations, truncated }, context) {
7540
+ const branches = trackCheckedOutBranches(commands, invocations, context);
7541
+ const signals = invocations.flatMap(({ dir, subcommand, args, command }, index) => {
7542
+ if (subcommand === "config") {
7543
+ return args.some((arg) => /^push\.pushoption$/i.test(arg)) && args.some((arg) => AUTO_MERGE_PUSH_OPTION.test(arg)) ? ["git-push-auto-merge"] : [];
7544
+ }
7545
+ if (subcommand !== "push") return [];
7546
+ const repo = dir === null ? void 0 : context?.repos[dir];
7547
+ const { branch, switched } = branches[index];
7548
+ const { refspecs, options, all, tags } = parsePushArgs(args);
7549
+ const pushSignals = [];
7550
+ if (all) pushSignals.push("git-push-all");
7551
+ if (options.some((option) => AUTO_MERGE_PUSH_OPTION.test(option)) || CONFIGURED_AUTO_MERGE_PUSH_OPTION.test([repo?.pushConfig ?? "", ...command.argv].join("\n"))) {
7552
+ pushSignals.push("git-push-auto-merge");
7553
+ }
7554
+ const bareDestination = /^remote\..+\.push |^push\.default matching$/m.test(repo?.pushConfig ?? "") ? null : switched ? branch : repo?.pushBranch ?? branch;
7555
+ const destinations = refspecs.length > 0 ? refspecs.map((refspec) => refspecDestination(refspec, branch)) : all || tags ? [] : [bareDestination];
7556
+ for (const destination of destinations) {
7557
+ if (destination === "*") pushSignals.push("git-push-all");
7558
+ else if (destination === null) pushSignals.push("git-push-unknown-destination");
7559
+ else if (destination !== void 0 && isProtectedBranch(destination, repo)) pushSignals.push("git-push-default-branch");
7560
+ }
7561
+ return pushSignals;
7562
+ });
7563
+ return truncated ? [...signals, "git-push-unknown-destination"] : signals;
7564
+ }
7565
+ function isPrMergeCommand(argv) {
7566
+ const name = argv[0].split("/").pop();
7567
+ if (name !== "gh" && name !== "glab") return false;
7568
+ const args = argv.slice(1);
7569
+ if (args.includes("--help") || args.includes("-h")) return false;
7570
+ const words = args.filter((arg, index) => !arg.startsWith("-") && !/^(?:-R|--repo)$/.test(args[index - 1] ?? ""));
7571
+ if (words[0] === (name === "gh" ? "pr" : "mr") && words[1] === "merge") return true;
7572
+ const method = /(?:^|\s)(?:-X\s*|--method[\s=])(\w+)/i.exec(args.join(" "))?.[1];
7573
+ return words[0] === "api" && method?.toUpperCase() === "PUT" && words.some((word) => /\/(?:pulls|merge_requests)\/[^/]+\/merge$/.test(word));
7574
+ }
7575
+ var matchingChecks = (checks, text2) => checks.flatMap(([name, pattern]) => pattern.test(text2) ? [name] : []);
7576
+ function executedText(commands, keepWord = () => true) {
7577
+ return commands.filter(({ argv, wrapper, truncated }) => (!wrapper || truncated) && argv[0].split("/").pop() !== "git").map(({ argv, stdin }) => normalizeCommandProtectionText([...argv.filter(keepWord), stdin ?? ""].join(" ").replaceAll(SHELL_OPAQUE, " "))).join("\n");
7578
+ }
7579
+ function findShellMergeSignals(parsed, context) {
7580
+ const actions = parsed.commands.filter(({ argv }) => !["cd", "pushd"].includes(argv[0].split("/").pop() ?? ""));
7581
+ return [.../* @__PURE__ */ new Set([
7582
+ ...matchingChecks(MERGE_SIGNAL_CHECKS, executedText(parsed.commands)),
7583
+ ...matchingChecks(BROAD_MERGE_SIGNAL_CHECKS, executedText(actions, (word) => !word.includes("/"))),
7584
+ ...parsed.commands.some(({ argv }) => isPrMergeCommand(argv)) ? ["pr-merge-command"] : [],
7585
+ ...findPushSignals(parsed, context)
7586
+ ])];
7587
+ }
7588
+ function findToolMergeSignals({ toolName, toolInput }) {
7589
+ if (/^(?:read|write|edit|multi_?edit|patch|apply_?patch|glob|grep|ls|list|notebook_?edit)$/i.test(toolName)) return [];
7590
+ const checks = [...MERGE_SIGNAL_CHECKS, ...BROAD_MERGE_SIGNAL_CHECKS];
7591
+ return [.../* @__PURE__ */ new Set([...matchingChecks(checks, toolName.toLowerCase()), ...matchingChecks(checks, normalizeCommandProtectionText(stringifyCommandProtectionInput(toolInput)))])].sort((a, b) => checks.findIndex(([name]) => name === a) - checks.findIndex(([name]) => name === b));
7592
+ }
7593
+ var DEFINITE_MERGE_REASONS = {
7594
+ "git-push-default-branch": "The command pushes to the default branch.",
7595
+ "git-push-auto-merge": "The command enables auto-merge through a git push option.",
7596
+ "pr-merge-command": "The command merges a pull request or merge request."
7597
+ };
7598
+ function findPrMergeSignals(parsed, context) {
7599
+ const signals = parsed.script === null ? findToolMergeSignals(parsed.request) : findShellMergeSignals(parsed, context);
7600
+ return { signals, definiteReasons: signals.flatMap((signal) => DEFINITE_MERGE_REASONS[signal] ?? []) };
7601
+ }
7602
+ function findGitCommitSignals({ invocations, truncated }) {
7603
+ return truncated || invocations.some(({ subcommand }) => subcommand === "commit") ? ["git-commit"] : [];
7604
+ }
7605
+ function findCommandProtectionGitLookups({ invocations }) {
7606
+ const writes = invocations.filter(({ subcommand }) => subcommand === "commit" || subcommand === "push");
7607
+ const messageFiles = writes.flatMap(({ subcommand, args, dir, command }) => {
7608
+ const { file } = subcommand === "commit" ? parseCommitArgs(args) : { file: void 0 };
7609
+ const path = file === "-" ? command.stdinFile : file === void 0 ? null : resolveShellPath(dir, file);
7610
+ return path ? [path] : [];
7611
+ });
7612
+ return {
7613
+ repoDirs: [...new Set(writes.flatMap(({ dir }) => dir === null ? [] : [dir]))],
7614
+ messageFiles: [...new Set(messageFiles)]
7615
+ };
7134
7616
  }
7135
7617
  function shouldRefreshPullRequests(toolName, toolInput) {
7136
7618
  const name = toolName.toLowerCase();
@@ -7149,38 +7631,38 @@ function shouldRefreshPullRequests(toolName, toolInput) {
7149
7631
  }
7150
7632
 
7151
7633
  // ../shared/src/routes/linear.ts
7152
- import { z as z10 } from "zod";
7153
- var linearSessionMetadataSchema = z10.object({
7154
- via_mothership: z10.boolean().optional(),
7155
- issue_id: z10.string(),
7156
- issue_identifier: z10.string(),
7157
- issue_title: z10.string(),
7158
- issue_description: z10.string(),
7159
- issue_url: z10.string(),
7160
- comment_id: z10.string(),
7161
- comment_body: z10.string(),
7162
- triggered_by_id: z10.string().optional(),
7163
- triggered_by_name: z10.string().optional(),
7164
- triggered_by_email: z10.string().optional(),
7165
- linear_workspace_id: z10.string().optional(),
7166
- creator_id: z10.string().optional(),
7167
- creator_name: z10.string().optional(),
7168
- creator_email: z10.string().optional(),
7169
- assignee_id: z10.string().optional(),
7170
- assignee_name: z10.string().optional(),
7171
- assignee_email: z10.string().optional(),
7172
- issue_state: z10.string().optional(),
7173
- parent_issue: z10.object({
7174
- id: z10.string(),
7175
- identifier: z10.string(),
7176
- title: z10.string(),
7177
- description: z10.string().nullable()
7634
+ import { z as z11 } from "zod";
7635
+ var linearSessionMetadataSchema = z11.object({
7636
+ via_mothership: z11.boolean().optional(),
7637
+ issue_id: z11.string(),
7638
+ issue_identifier: z11.string(),
7639
+ issue_title: z11.string(),
7640
+ issue_description: z11.string(),
7641
+ issue_url: z11.string(),
7642
+ comment_id: z11.string(),
7643
+ comment_body: z11.string(),
7644
+ triggered_by_id: z11.string().optional(),
7645
+ triggered_by_name: z11.string().optional(),
7646
+ triggered_by_email: z11.string().optional(),
7647
+ linear_workspace_id: z11.string().optional(),
7648
+ creator_id: z11.string().optional(),
7649
+ creator_name: z11.string().optional(),
7650
+ creator_email: z11.string().optional(),
7651
+ assignee_id: z11.string().optional(),
7652
+ assignee_name: z11.string().optional(),
7653
+ assignee_email: z11.string().optional(),
7654
+ issue_state: z11.string().optional(),
7655
+ parent_issue: z11.object({
7656
+ id: z11.string(),
7657
+ identifier: z11.string(),
7658
+ title: z11.string(),
7659
+ description: z11.string().nullable()
7178
7660
  }).optional(),
7179
- workspace: z10.object({
7180
- id: z10.string(),
7181
- coding_agent: z10.custom((value) => typeof value === "string" && isValidAgentProvider(value)),
7182
- task_description: z10.string(),
7183
- created_at: z10.string()
7661
+ workspace: z11.object({
7662
+ id: z11.string(),
7663
+ coding_agent: z11.custom((value) => typeof value === "string" && isValidAgentProvider(value)),
7664
+ task_description: z11.string(),
7665
+ created_at: z11.string()
7184
7666
  }).optional()
7185
7667
  });
7186
7668
 
@@ -7515,46 +7997,46 @@ var DEFAULT_WORKSPACE_FILTERS = {
7515
7997
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
7516
7998
 
7517
7999
  // ../shared/src/routes/workspace-events.ts
7518
- import { z as z11 } from "zod";
7519
- var workspaceChangedEventSchema = z11.discriminatedUnion("type", [
7520
- z11.object({
7521
- type: z11.literal("workspace.changed"),
7522
- workspaceId: z11.string(),
7523
- completion: z11.object({
7524
- workspaceName: z11.string(),
7525
- completedAt: z11.string(),
7526
- processing: z11.boolean().optional()
8000
+ import { z as z12 } from "zod";
8001
+ var workspaceChangedEventSchema = z12.discriminatedUnion("type", [
8002
+ z12.object({
8003
+ type: z12.literal("workspace.changed"),
8004
+ workspaceId: z12.string(),
8005
+ completion: z12.object({
8006
+ workspaceName: z12.string(),
8007
+ completedAt: z12.string(),
8008
+ processing: z12.boolean().optional()
7527
8009
  }).optional(),
7528
- ts: z11.string()
8010
+ ts: z12.string()
7529
8011
  }),
7530
- z11.object({
7531
- type: z11.literal("workspace.chat.changed"),
7532
- workspaceId: z11.string(),
7533
- chatId: z11.string(),
7534
- ts: z11.string()
8012
+ z12.object({
8013
+ type: z12.literal("workspace.chat.changed"),
8014
+ workspaceId: z12.string(),
8015
+ chatId: z12.string(),
8016
+ ts: z12.string()
7535
8017
  }),
7536
- z11.object({ type: z11.literal("presence.changed"), ts: z11.string() }),
7537
- z11.object({
7538
- type: z11.literal("mobile-testing.changed"),
7539
- workspaceId: z11.string(),
7540
- ts: z11.string()
8018
+ z12.object({ type: z12.literal("presence.changed"), ts: z12.string() }),
8019
+ z12.object({
8020
+ type: z12.literal("mobile-testing.changed"),
8021
+ workspaceId: z12.string(),
8022
+ ts: z12.string()
7541
8023
  })
7542
8024
  ]);
7543
8025
 
7544
8026
  // ../shared/src/routes/presence.ts
7545
- import { z as z12 } from "zod";
7546
- var presenceStatusSchema = z12.enum(["online", "typing"]);
7547
- var presenceLocationSchema = z12.object({
7548
- environmentId: z12.string().optional(),
7549
- workspaceId: z12.string().optional()
8027
+ import { z as z13 } from "zod";
8028
+ var presenceStatusSchema = z13.enum(["online", "typing"]);
8029
+ var presenceLocationSchema = z13.object({
8030
+ environmentId: z13.string().optional(),
8031
+ workspaceId: z13.string().optional()
7550
8032
  });
7551
- var presenceEntrySchema = z12.object({
7552
- userId: z12.string(),
8033
+ var presenceEntrySchema = z13.object({
8034
+ userId: z13.string(),
7553
8035
  status: presenceStatusSchema,
7554
8036
  location: presenceLocationSchema,
7555
- ts: z12.string()
8037
+ ts: z13.string()
7556
8038
  });
7557
- var updatePresenceRequestSchema = z12.object({
8039
+ var updatePresenceRequestSchema = z13.object({
7558
8040
  status: presenceStatusSchema,
7559
8041
  location: presenceLocationSchema.optional()
7560
8042
  });
@@ -7898,7 +8380,7 @@ function isSkillRegistryManifest(value) {
7898
8380
  }
7899
8381
 
7900
8382
  // ../shared/src/routes/environment-setups.ts
7901
- import { z as z13 } from "zod";
8383
+ import { z as z14 } from "zod";
7902
8384
  var ENVIRONMENT_SETUP_STEPS = [
7903
8385
  { key: "understand", label: "Understand the codebase" },
7904
8386
  { key: "install", label: "Install dependencies and run the app" },
@@ -7932,27 +8414,27 @@ var ENVIRONMENT_SETUP_LIMITS = {
7932
8414
  };
7933
8415
  var ENVIRONMENT_SETUP_VARIABLE_WAIT = { defaultMs: 5 * 6e4, maxMs: 15 * 6e4, pollMs: 5e3 };
7934
8416
  var VARIABLE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
7935
- var text = (max) => max === void 0 ? z13.string().trim() : z13.string().trim().max(max);
8417
+ var text = (max) => max === void 0 ? z14.string().trim() : z14.string().trim().max(max);
7936
8418
  var requiredText = (max) => text(max).min(1, "must not be empty");
7937
8419
  var optionalText = (max) => text(max).nullish().transform((value) => value || null);
7938
8420
  var clearableText = (max) => text(max).nullish().transform((value) => value === void 0 ? void 0 : value || null);
7939
- var list = (item, max) => max === void 0 ? z13.array(item) : z13.array(item).max(max);
8421
+ var list = (item, max) => max === void 0 ? z14.array(item) : z14.array(item).max(max);
7940
8422
  var ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES = ["cron", "github", "gitlab"];
7941
8423
  function isEnvironmentSetupAuthoredTriggerType(type) {
7942
8424
  return ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES.some((authored) => authored === type);
7943
8425
  }
7944
- var repositoryTriggerConfigSchema = z13.object({
7945
- event: z13.string(),
7946
- repository_ids: z13.array(z13.string().regex(UUID_RE, "must be a repository id")).optional(),
7947
- group_pr_events: z13.boolean().optional(),
7948
- excluded_actors: z13.array(z13.string()).optional()
8426
+ var repositoryTriggerConfigSchema = z14.object({
8427
+ event: z14.string(),
8428
+ repository_ids: z14.array(z14.string().regex(UUID_RE, "must be a repository id")).optional(),
8429
+ group_pr_events: z14.boolean().optional(),
8430
+ excluded_actors: z14.array(z14.string()).optional()
7949
8431
  });
7950
- var proposalTriggerSchema = z13.discriminatedUnion("type", [
7951
- z13.object({ type: z13.literal("cron"), config: z13.object({ schedule: z13.string(), timezone: z13.string().optional() }) }),
7952
- z13.object({ type: z13.literal("github"), config: repositoryTriggerConfigSchema }),
7953
- z13.object({ type: z13.literal("gitlab"), config: repositoryTriggerConfigSchema })
8432
+ var proposalTriggerSchema = z14.discriminatedUnion("type", [
8433
+ z14.object({ type: z14.literal("cron"), config: z14.object({ schedule: z14.string(), timezone: z14.string().optional() }) }),
8434
+ z14.object({ type: z14.literal("github"), config: repositoryTriggerConfigSchema }),
8435
+ z14.object({ type: z14.literal("gitlab"), config: repositoryTriggerConfigSchema })
7954
8436
  ]);
7955
- var existingTriggerSchema = z13.custom(
8437
+ var existingTriggerSchema = z14.custom(
7956
8438
  (value) => isRecord(value) && typeof value.type === "string" && isRecord(value.config),
7957
8439
  "must be an automation trigger"
7958
8440
  );
@@ -7960,17 +8442,17 @@ var carriedTriggerSchema = existingTriggerSchema.refine(
7960
8442
  (trigger) => !isEnvironmentSetupAuthoredTriggerType(trigger.type)
7961
8443
  );
7962
8444
  function automationSchema(limits) {
7963
- const authored = z13.object({
8445
+ const authored = z14.object({
7964
8446
  name: text(limits.nameChars),
7965
8447
  description: text(limits.descriptionChars),
7966
8448
  prompt: text(limits.automationPromptChars),
7967
8449
  triggers: list(proposalTriggerSchema, limits.automationTriggers)
7968
8450
  });
7969
- const updated = authored.extend({ triggers: list(z13.union([proposalTriggerSchema, carriedTriggerSchema]), limits.automationTriggers) });
7970
- return z13.object({
8451
+ const updated = authored.extend({ triggers: list(z14.union([proposalTriggerSchema, carriedTriggerSchema]), limits.automationTriggers) });
8452
+ return z14.object({
7971
8453
  key: requiredText(limits.automationKeyChars),
7972
- action: z13.enum(ENVIRONMENT_SETUP_AUTOMATION_ACTIONS).default("create"),
7973
- automation_id: z13.string().regex(UUID_RE, "must be an automation id").nullable().default(null),
8454
+ action: z14.enum(ENVIRONMENT_SETUP_AUTOMATION_ACTIONS).default("create"),
8455
+ automation_id: z14.string().regex(UUID_RE, "must be an automation id").nullable().default(null),
7974
8456
  name: text().default(""),
7975
8457
  description: optionalText().transform((value) => value ?? ""),
7976
8458
  prompt: text().default(""),
@@ -7993,7 +8475,7 @@ function automationSchema(limits) {
7993
8475
  const content = (automation.action === "update" ? updated : authored).safeParse(automation);
7994
8476
  if (content.success) return { ...automation, ...content.data };
7995
8477
  for (const issue of content.error.issues) ctx.addIssue({ ...issue, code: "custom" });
7996
- return z13.NEVER;
8478
+ return z14.NEVER;
7997
8479
  });
7998
8480
  }
7999
8481
  function automationListSchema(limits) {
@@ -8011,7 +8493,7 @@ function automationListSchema(limits) {
8011
8493
  });
8012
8494
  }
8013
8495
  function environmentSchema(limits) {
8014
- return z13.object({
8496
+ return z14.object({
8015
8497
  name: optionalText(limits.nameChars).transform((value) => value ?? void 0),
8016
8498
  description: clearableText(limits.descriptionChars),
8017
8499
  system_prompt: clearableText(limits.systemPromptChars),
@@ -8020,26 +8502,26 @@ function environmentSchema(limits) {
8020
8502
  });
8021
8503
  }
8022
8504
  function variableSchema(limits, requiredDefault) {
8023
- return z13.object({
8024
- key: z13.string().regex(VARIABLE_KEY_RE, "must be a valid environment variable name").max(limits.variableKeyChars ?? Number.POSITIVE_INFINITY),
8505
+ return z14.object({
8506
+ key: z14.string().regex(VARIABLE_KEY_RE, "must be a valid environment variable name").max(limits.variableKeyChars ?? Number.POSITIVE_INFINITY),
8025
8507
  description: optionalText(limits.variableDescriptionChars).transform((value) => value ?? ""),
8026
- required: z13.boolean().default(requiredDefault)
8508
+ required: z14.boolean().default(requiredDefault)
8027
8509
  });
8028
8510
  }
8029
8511
  function proposalSchema(limits) {
8030
- return z13.object({
8512
+ return z14.object({
8031
8513
  summary: requiredText(limits.summaryChars),
8032
8514
  stack: list(text(), limits.stackItems).default([]).transform((items) => items.filter(Boolean)),
8033
8515
  environment: environmentSchema(limits),
8034
8516
  variables: list(variableSchema(limits, false), limits.variables).default([]),
8035
8517
  automations: automationListSchema(limits),
8036
- verification: list(z13.object({
8518
+ verification: list(z14.object({
8037
8519
  label: requiredText(limits.nameChars),
8038
- status: z13.enum(ENVIRONMENT_SETUP_VERIFICATION_STATUSES),
8520
+ status: z14.enum(ENVIRONMENT_SETUP_VERIFICATION_STATUSES),
8039
8521
  detail: optionalText(limits.verificationDetailChars).transform((value) => value ?? void 0)
8040
8522
  }), limits.verificationItems).default([]),
8041
- media: list(z13.object({
8042
- media_id: z13.string().regex(UUID_RE, "must be a media id"),
8523
+ media: list(z14.object({
8524
+ media_id: z14.string().regex(UUID_RE, "must be a media id"),
8043
8525
  title: requiredText(limits.nameChars)
8044
8526
  }), limits.mediaItems).default([])
8045
8527
  });
@@ -8047,35 +8529,35 @@ function proposalSchema(limits) {
8047
8529
  var environmentSetupProposalSchema = proposalSchema({});
8048
8530
  var environmentSetupProposalSubmissionSchema = proposalSchema(ENVIRONMENT_SETUP_LIMITS);
8049
8531
  var environmentSetupVariableRequestSchema = variableSchema({}, false).extend({
8050
- status: z13.enum(["pending", "provided", "skipped"]),
8051
- requested_at: z13.string(),
8052
- resolved_at: z13.string().nullable().default(null)
8532
+ status: z14.enum(["pending", "provided", "skipped"]),
8533
+ requested_at: z14.string(),
8534
+ resolved_at: z14.string().nullable().default(null)
8053
8535
  });
8054
- var environmentSetupRunStateSchema = z13.object({
8055
- status: z13.enum(ENVIRONMENT_SETUP_RUN_STATUSES),
8056
- steps: z13.partialRecord(z13.enum(ENVIRONMENT_SETUP_STEPS.map((step) => step.key)), z13.enum(ENVIRONMENT_SETUP_STEP_STATUSES)).default({}),
8536
+ var environmentSetupRunStateSchema = z14.object({
8537
+ status: z14.enum(ENVIRONMENT_SETUP_RUN_STATUSES),
8538
+ steps: z14.partialRecord(z14.enum(ENVIRONMENT_SETUP_STEPS.map((step) => step.key)), z14.enum(ENVIRONMENT_SETUP_STEP_STATUSES)).default({}),
8057
8539
  proposal: environmentSetupProposalSchema.nullable().default(null),
8058
- applied: z13.object({
8059
- applied_at: z13.string(),
8060
- automation_ids: z13.array(z13.string())
8540
+ applied: z14.object({
8541
+ applied_at: z14.string(),
8542
+ automation_ids: z14.array(z14.string())
8061
8543
  }).nullable().default(null),
8062
- variable_requests: z13.array(environmentSetupVariableRequestSchema).default([])
8544
+ variable_requests: z14.array(environmentSetupVariableRequestSchema).default([])
8063
8545
  });
8064
- var applyEnvironmentSetupRequestSchema = z13.object({
8546
+ var applyEnvironmentSetupRequestSchema = z14.object({
8065
8547
  environment: environmentSchema(ENVIRONMENT_SETUP_LIMITS).extend({ name: requiredText(ENVIRONMENT_SETUP_LIMITS.nameChars) }),
8066
- variables: list(z13.object({ key: z13.string().regex(VARIABLE_KEY_RE), value: z13.string() }), ENVIRONMENT_SETUP_LIMITS.variables).default([]).refine((variables) => new Set(variables.map((variable) => variable.key)).size === variables.length, "must have unique keys").transform((variables) => variables.filter((variable) => variable.value.length > 0)),
8548
+ variables: list(z14.object({ key: z14.string().regex(VARIABLE_KEY_RE), value: z14.string() }), ENVIRONMENT_SETUP_LIMITS.variables).default([]).refine((variables) => new Set(variables.map((variable) => variable.key)).size === variables.length, "must have unique keys").transform((variables) => variables.filter((variable) => variable.value.length > 0)),
8067
8549
  automations: automationListSchema(ENVIRONMENT_SETUP_LIMITS)
8068
8550
  });
8069
- var requestEnvironmentSetupVariablesSchema = z13.object({
8551
+ var requestEnvironmentSetupVariablesSchema = z14.object({
8070
8552
  variables: list(variableSchema(ENVIRONMENT_SETUP_LIMITS, true), ENVIRONMENT_SETUP_LIMITS.variables).min(1, "must not be empty")
8071
8553
  }).superRefine(({ variables }, ctx) => {
8072
8554
  if (new Set(variables.map((variable) => variable.key)).size !== variables.length) {
8073
8555
  ctx.addIssue({ code: "custom", path: ["variables"], message: "must have unique keys" });
8074
8556
  }
8075
8557
  });
8076
- var respondEnvironmentSetupVariablesSchema = z13.object({
8077
- values: z13.record(z13.string().regex(VARIABLE_KEY_RE), z13.string()).default({}),
8078
- skipped: z13.array(z13.string().regex(VARIABLE_KEY_RE)).default([])
8558
+ var respondEnvironmentSetupVariablesSchema = z14.object({
8559
+ values: z14.record(z14.string().regex(VARIABLE_KEY_RE), z14.string()).default({}),
8560
+ skipped: z14.array(z14.string().regex(VARIABLE_KEY_RE)).default([])
8079
8561
  });
8080
8562
 
8081
8563
  export {
@@ -8298,8 +8780,10 @@ export {
8298
8780
  claudeAuthEnvFromResponse,
8299
8781
  CLAUDE_AUTH_ENV_KEYS_BY_METHOD,
8300
8782
  extractCommandProtectionCommandText,
8783
+ parseCommandProtectionRequest,
8301
8784
  findPrMergeSignals,
8302
8785
  findGitCommitSignals,
8786
+ findCommandProtectionGitLookups,
8303
8787
  shouldRefreshPullRequests,
8304
8788
  MAX_REPO_FILE_CONTENT_BYTES,
8305
8789
  searchRepoFileIndex,