auto-mode 2.0.1 → 2.0.2

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.
@@ -17740,7 +17740,7 @@ function classifyEdit(action, scope) {
17740
17740
  kind: "jev",
17741
17741
  reason: "target in a checkout outside the scope"
17742
17742
  };
17743
- const exclusion = [action.target, action.requested].some((each) => scope.protectedDirs.some((dir) => isWithin(each, dir))) ? "auto-mode configuration or state" : findExclusion(path) ?? findExclusion(toWorktreePath(action.requested, scope.worktrees));
17743
+ const exclusion = [action.target, action.requested].some((each) => scope.protectedDirs.some((directory) => isWithin(each, directory))) ? "auto-mode configuration or state" : findExclusion(path) ?? findExclusion(toWorktreePath(action.requested, scope.worktrees));
17744
17744
  if (exclusion !== null) return {
17745
17745
  kind: "jev",
17746
17746
  reason: `target is ${exclusion}`
@@ -17809,10 +17809,10 @@ function toWorktreePath(path, worktrees) {
17809
17809
  return worktree === null ? path : relative(worktree, path).split(sep).join("/");
17810
17810
  }
17811
17811
  function findWorktree(target, worktrees) {
17812
- return worktrees.filter((worktree) => isWithin(target, worktree)).toSorted((a, b) => b.length - a.length)[0] ?? null;
17812
+ return worktrees.filter((worktree) => isWithin(target, worktree)).toSorted((left, right) => right.length - left.length)[0] ?? null;
17813
17813
  }
17814
- function isWithin(path, dir) {
17815
- const offset = relative(dir, path);
17814
+ function isWithin(path, directory) {
17815
+ const offset = relative(directory, path);
17816
17816
  return offset !== "" && !offset.startsWith("..") && !offset.startsWith(sep);
17817
17817
  }
17818
17818
  const EXCLUDED_PATHS = [
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { C as pickJudgeLane, E as updateJSONFile, S as CLI_LIMITS, T as resolveXDGDir, _ as findCheckout, a as resolveSessionScopePath, b as loadConfig, c as splitGitCommand, d as loadCheckoutFacts, f as writeActionDiagnostic, g as isUnresolvedWord, h as resolveShellPath, i as classifyAction, l as loadPolicy, m as collectShellCommands, n as readRuntime, o as loadSessionScope, p as toRepositorySlug, s as EMPTY_SESSION_SCOPE, t as parseActionRequest, u as resolveShippedPolicyDir, v as findGitEntry, w as M, x as runCapped, y as DEFAULT_SCOPE_SOURCES } from "./parse-action-request-neI2tNwd.js";
3
- import { a as literal, d as string, i as discriminatedUnion, r as boolean, s as number, u as strictObject } from "./schemas-Dc2424NY.js";
2
+ import { C as pickJudgeLane, E as updateJSONFile, S as CLI_LIMITS, T as resolveXDGDir, _ as findCheckout, a as resolveSessionScopePath, b as loadConfig, c as splitGitCommand, d as loadCheckoutFacts, f as writeActionDiagnostic, g as isUnresolvedWord, h as resolveShellPath, i as classifyAction, l as loadPolicy, m as collectShellCommands, n as readRuntime, o as loadSessionScope, p as toRepositorySlug, s as EMPTY_SESSION_SCOPE, t as parseActionRequest, u as resolveShippedPolicyDir, v as findGitEntry, w as M, x as runCapped, y as DEFAULT_SCOPE_SOURCES } from "./parse-action-request-CPpuEqFq.js";
3
+ import { a as literal, d as string, i as discriminatedUnion, r as boolean, s as number, u as strictObject } from "./schemas-B_w83Dze.js";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import { chmod, mkdir, open, readFile, realpath, stat } from "node:fs/promises";
6
6
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
@@ -2567,7 +2567,7 @@ function lazy(loader, definition) {
2567
2567
  //#endregion
2568
2568
  //#region src/capture/resolve-capture-dir.ts
2569
2569
  function resolveCaptureDir(capture, host) {
2570
- return capture.dir ?? join(resolveXDGDir(host, "state"), "captures");
2570
+ return capture.directory ?? join(resolveXDGDir(host, "state"), "captures");
2571
2571
  }
2572
2572
  //#endregion
2573
2573
  //#region src/capture/find-enclosing-work-tree.ts
@@ -2587,22 +2587,22 @@ async function resolveExistingPrefix(path) {
2587
2587
  }
2588
2588
  //#endregion
2589
2589
  //#region src/capture/try-write-request-capture.ts
2590
- async function tryWriteRequestCapture(dir, record) {
2591
- if (!isAbsolute(dir)) return {
2590
+ async function tryWriteRequestCapture(directory, record) {
2591
+ if (!isAbsolute(directory)) return {
2592
2592
  kind: "refused",
2593
- reason: `the capture dir ${dir} is not an absolute path`
2593
+ reason: `the capture dir ${directory} is not an absolute path`
2594
2594
  };
2595
2595
  try {
2596
- const before = await findEnclosingWorkTree(dir);
2596
+ const before = await findEnclosingWorkTree(directory);
2597
2597
  if (before !== null) return {
2598
2598
  kind: "refused",
2599
2599
  reason: `the capture dir is inside the git work tree ${before}`
2600
2600
  };
2601
- await mkdir(dir, {
2601
+ await mkdir(directory, {
2602
2602
  recursive: true,
2603
2603
  mode: 448
2604
2604
  });
2605
- const real = await realpath(dir);
2605
+ const real = await realpath(directory);
2606
2606
  const after = await findEnclosingWorkTree(real);
2607
2607
  if (after !== null) return {
2608
2608
  kind: "refused",
@@ -2758,10 +2758,10 @@ function sendLine(socket, line, signal) {
2758
2758
  //#region src/judge/resolve-judge-socket-path.ts
2759
2759
  function resolveJudgeSocketPath(host, sessionID, entry) {
2760
2760
  const runtime = host.env["XDG_RUNTIME_DIR"];
2761
- const dir = runtime === void 0 || runtime === "" ? join(resolveXDGDir(host, "state"), "judge") : join(runtime, "auto-mode");
2761
+ const directory = runtime === void 0 || runtime === "" ? join(resolveXDGDir(host, "state"), "judge") : join(runtime, "auto-mode");
2762
2762
  const build = statSync(entry, { throwIfNoEntry: false });
2763
2763
  const name = createHash("sha256").update(`${sessionID}\0${entry}\0${String(build?.mtimeMs ?? 0)}`).digest("hex").slice(0, 24);
2764
- return join(dir, `judge-${name}.sock`);
2764
+ return join(directory, `judge-${name}.sock`);
2765
2765
  }
2766
2766
  //#endregion
2767
2767
  //#region src/scope/read-pull-request.ts
@@ -3220,7 +3220,7 @@ async function runJudgeServer(io, socketPath) {
3220
3220
  io.stderr.write(`auto-mode: judge-server needs a socket path\n\n${USAGE}`);
3221
3221
  return 2;
3222
3222
  }
3223
- await (await (await import("./start-judge-server-CCSZbTwM.js")).startJudgeServer({
3223
+ await (await (await import("./start-judge-server-D-zcMyFZ.js")).startJudgeServer({
3224
3224
  socketPath,
3225
3225
  env: io.runtime.host.env,
3226
3226
  idleMs: JUDGE_IDLE_MS
package/dist/index.d.ts CHANGED
@@ -76,7 +76,7 @@ interface HostEnvironment {
76
76
  interface Runtime {
77
77
  readonly host: Readonly<HostEnvironment>;
78
78
  readonly now: () => number;
79
- readonly timeout: (ms: number) => AbortSignal;
79
+ readonly timeout: (timeoutMs: number) => AbortSignal;
80
80
  readonly fetch: (url: string, init: Readonly<RequestInit>) => Promise<Response>;
81
81
  readonly findCheckout: CheckoutFinder;
82
82
  }
@@ -117,7 +117,7 @@ type ScopeSourceKind = (typeof SCOPE_SOURCE_KINDS)[number];
117
117
  declare const SCOPE_SOURCE_KINDS: readonly ['cwd', 'session', 'globs', 'atc'];
118
118
  interface CaptureConfig {
119
119
  readonly enabled: boolean;
120
- readonly dir?: string | undefined;
120
+ readonly directory?: string | undefined;
121
121
  }
122
122
  interface Config {
123
123
  readonly provider: ProviderConfig;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b as loadConfig$1, i as classifyAction$1, n as readRuntime, r as readHostEnvironment, t as parseActionRequest } from "./parse-action-request-neI2tNwd.js";
1
+ import { b as loadConfig$1, i as classifyAction$1, n as readRuntime, r as readHostEnvironment, t as parseActionRequest } from "./parse-action-request-CPpuEqFq.js";
2
2
  //#region src/index.ts
3
3
  function classifyAction(request, config, options = {}) {
4
4
  return classifyAction$1(request, config, {
@@ -1,4 +1,4 @@
1
- import { a as literal, c as object, d as string, f as union, l as record, m as prettifyError, n as array, o as looseObject, p as unknown, r as boolean, s as number, t as _enum, u as strictObject } from "./schemas-Dc2424NY.js";
1
+ import { a as literal, c as object, d as string, f as union, l as record, m as prettifyError, n as array, o as looseObject, p as unknown, r as boolean, s as number, t as _enum, u as strictObject } from "./schemas-B_w83Dze.js";
2
2
  import { t as getEditFields } from "./get-edit-fields-BtAvHIsq.js";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { appendFile, link, lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
@@ -33,7 +33,7 @@ function buildRetryKey(request) {
33
33
  }
34
34
  function sortKeys(value) {
35
35
  if (Array.isArray(value)) return value.map((item) => sortKeys(item));
36
- if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).toSorted(([a], [b]) => a < b ? -1 : 1).map(([key, item]) => [key, sortKeys(item)]));
36
+ if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).toSorted(([leftKey], [rightKey]) => leftKey < rightKey ? -1 : 1).map(([key, item]) => [key, sortKeys(item)]));
37
37
  return value;
38
38
  }
39
39
  //#endregion
@@ -135,7 +135,7 @@ function resolveDenialStatePath(request, stateDir) {
135
135
  //#region src/state/update-json-file.ts
136
136
  const SYSTEM_CLOCK = {
137
137
  now: Date.now,
138
- wait: (ms) => setTimeout(ms)
138
+ wait: (delayMs) => setTimeout(delayMs)
139
139
  };
140
140
  async function updateJSONFile(path, load, update, clock = SYSTEM_CLOCK) {
141
141
  await mkdir(dirname(path), {
@@ -262,9 +262,9 @@ const BASE_DIRS = {
262
262
  }
263
263
  };
264
264
  function resolveXDGDir(host, kind) {
265
- const dir = BASE_DIRS[kind];
266
- const base = host.env[dir.variable];
267
- const root = base === void 0 || base === "" ? join(host.home, ...dir.fallback) : base;
265
+ const directory = BASE_DIRS[kind];
266
+ const base = host.env[directory.variable];
267
+ const root = base === void 0 || base === "" ? join(host.home, ...directory.fallback) : base;
268
268
  return join(root, "auto-mode");
269
269
  }
270
270
  //#endregion
@@ -663,8 +663,8 @@ function runCapped(file, args, options) {
663
663
  }
664
664
  //#endregion
665
665
  //#region src/config/to-timer-delay.ts
666
- function toTimerDelay(ms) {
667
- return Math.max(1, Math.ceil(ms));
666
+ function toTimerDelay(timeoutMs) {
667
+ return Math.max(1, Math.ceil(timeoutMs));
668
668
  }
669
669
  //#endregion
670
670
  //#region src/config/read-api-key-from-command.ts
@@ -805,7 +805,7 @@ function buildConfig(json, path, home) {
805
805
  },
806
806
  ...file.capture === void 0 ? {} : { capture: {
807
807
  enabled: file.capture.enabled ?? false,
808
- dir: expandHomePath(file.capture.dir, home)
808
+ directory: expandHomePath(file.capture.dir, home)
809
809
  } },
810
810
  warnings
811
811
  };
@@ -1001,11 +1001,11 @@ async function tryClassifyEdit(request, scope, host, reader = {}) {
1001
1001
  const [target, worktrees, protectedDirs] = await Promise.all([
1002
1002
  files.resolveEditTarget(requested),
1003
1003
  Promise.all(scope.worktrees.map((worktree) => files.resolveEditTarget(worktree))),
1004
- Promise.all(ownDirs.map((dir) => files.resolveEditTarget(dir)))
1004
+ Promise.all(ownDirs.map((directory) => files.resolveEditTarget(directory)))
1005
1005
  ]);
1006
1006
  if (target === null || GIT_OVERRIDES.some((name) => host.env[name] !== void 0)) return null;
1007
1007
  const [checkout, current] = await Promise.all([files.findCheckout(dirname(target), host.env), request.toolName === "Edit" ? files.readFile(target).catch(() => null) : null]);
1008
- return (await import("./classify-edit-DXP7XLGH.js")).classifyEdit({
1008
+ return (await import("./classify-edit-C-CQMndB.js")).classifyEdit({
1009
1009
  toolName: request.toolName,
1010
1010
  toolInput: request.toolInput,
1011
1011
  requested,
@@ -1014,7 +1014,7 @@ async function tryClassifyEdit(request, scope, host, reader = {}) {
1014
1014
  current
1015
1015
  }, {
1016
1016
  worktrees: worktrees.filter((worktree) => worktree !== null),
1017
- protectedDirs: [...ownDirs, ...protectedDirs.filter((dir) => dir !== null)]
1017
+ protectedDirs: [...ownDirs, ...protectedDirs.filter((directory) => directory !== null)]
1018
1018
  });
1019
1019
  } catch {
1020
1020
  return null;
@@ -1028,8 +1028,8 @@ const DEFAULT_DIRS = {
1028
1028
  };
1029
1029
  function resolveClaudeConfigPath(host, file) {
1030
1030
  const configDir = host.env["CLAUDE_CONFIG_DIR"];
1031
- const dir = configDir === void 0 || configDir === "" ? join(host.home, ...DEFAULT_DIRS[file]) : configDir;
1032
- return join(dir, file);
1031
+ const directory = configDir === void 0 || configDir === "" ? join(host.home, ...DEFAULT_DIRS[file]) : configDir;
1032
+ return join(directory, file);
1033
1033
  }
1034
1034
  //#endregion
1035
1035
  //#region src/config/load-claude-settings.ts
@@ -1110,24 +1110,24 @@ function resolveShellPath(directory, path, home) {
1110
1110
  }
1111
1111
  //#endregion
1112
1112
  //#region src/shell/parse-ansi-escape.ts
1113
- const ANSI_ESCAPES = {
1114
- a: "\x07",
1115
- b: "\b",
1116
- e: "\x1B",
1117
- E: "\x1B",
1118
- f: "\f",
1119
- n: "\n",
1120
- r: "\r",
1121
- t: " ",
1122
- v: "\v",
1123
- "\\": "\\",
1124
- "'": "'",
1125
- "\"": "\"",
1126
- "?": "?"
1127
- };
1113
+ const ANSI_ESCAPES = /* @__PURE__ */ new Map([
1114
+ ["a", "\x07"],
1115
+ ["b", "\b"],
1116
+ ["e", "\x1B"],
1117
+ ["E", "\x1B"],
1118
+ ["f", "\f"],
1119
+ ["n", "\n"],
1120
+ ["r", "\r"],
1121
+ ["t", " "],
1122
+ ["v", "\v"],
1123
+ ["\\", "\\"],
1124
+ ["'", "'"],
1125
+ ["\"", "\""],
1126
+ ["?", "?"]
1127
+ ]);
1128
1128
  function parseANSIEscape(raw, index) {
1129
1129
  const next = raw.charAt(index + 1);
1130
- const named = ANSI_ESCAPES[next];
1130
+ const named = ANSI_ESCAPES.get(next);
1131
1131
  const hex = /^x(?<digits>[0-9A-Fa-f]{1,2})/u.exec(raw.slice(index + 1));
1132
1132
  const octal = /^[0-7]{1,3}/u.exec(raw.slice(index + 1));
1133
1133
  if (named !== void 0) return {
@@ -3156,6 +3156,11 @@ async function loadCheckoutRemotes(commonDir) {
3156
3156
  }
3157
3157
  return remotes;
3158
3158
  }
3159
+ const CONFIG_ESCAPES = /* @__PURE__ */ new Map([
3160
+ ["n", "\n"],
3161
+ ["t", " "],
3162
+ ["b", ""]
3163
+ ]);
3159
3164
  function parseConfigValue(raw) {
3160
3165
  let value = "";
3161
3166
  let isQuoted = false;
@@ -3163,11 +3168,7 @@ function parseConfigValue(raw) {
3163
3168
  const char = raw[index] ?? "";
3164
3169
  if (char === "\\") {
3165
3170
  const next = raw[index + 1] ?? "";
3166
- value += {
3167
- n: "\n",
3168
- t: " ",
3169
- b: ""
3170
- }[next] ?? next;
3171
+ value += CONFIG_ESCAPES.get(next) ?? next;
3171
3172
  index += 1;
3172
3173
  } else if (char === "\"") isQuoted = !isQuoted;
3173
3174
  else if (!isQuoted && (char === "#" || char === ";")) break;
@@ -3230,12 +3231,12 @@ function createDeadlineSignal(limitMs, options) {
3230
3231
  //#endregion
3231
3232
  //#region src/policy/resolve-shipped-policy-dir.ts
3232
3233
  function resolveShippedPolicyDir(startDir = import.meta.dirname, stopDir = parse(startDir).root) {
3233
- let dir = startDir;
3234
+ let directory = startDir;
3234
3235
  for (;;) {
3235
- if (existsSync(join(dir, "policy", "decision.md"))) return join(dir, "policy");
3236
- const parent = dirname(dir);
3237
- if (parent === dir || dir === stopDir) throw new Error("auto-mode cannot find its shipped policy/ directory");
3238
- dir = parent;
3236
+ if (existsSync(join(directory, "policy", "decision.md"))) return join(directory, "policy");
3237
+ const parent = dirname(directory);
3238
+ if (parent === directory || directory === stopDir) throw new Error("auto-mode cannot find its shipped policy/ directory");
3239
+ directory = parent;
3239
3240
  }
3240
3241
  }
3241
3242
  //#endregion
@@ -3635,7 +3636,7 @@ function sendJudgeMessage(provider, request, transport, signal) {
3635
3636
  }
3636
3637
  async function sendToAgentSDK(provider, request, transport, signal) {
3637
3638
  if (transport.session !== void 0) return transport.session.review(provider.model, request, signal);
3638
- const session = (await import("./start-judge-session-B_DFN8Ji.js")).startJudgeSession(transport.env);
3639
+ const session = (await import("./start-judge-session-DOkwKT_N.js")).startJudgeSession(transport.env);
3639
3640
  try {
3640
3641
  return await session.review(provider.model, request, signal);
3641
3642
  } finally {
@@ -4056,7 +4057,7 @@ function collectBlockingRules(request, result, blockThreshold) {
4056
4057
  rule,
4057
4058
  answer
4058
4059
  };
4059
- }).filter((entry) => entry.answer.probabilities.block >= blockThreshold).toSorted((a, b) => b.answer.probabilities.block - a.answer.probabilities.block || TIER_ORDER[a.rule.tier] - TIER_ORDER[b.rule.tier]);
4060
+ }).filter((entry) => entry.answer.probabilities.block >= blockThreshold).toSorted((left, right) => right.answer.probabilities.block - left.answer.probabilities.block || TIER_ORDER[left.rule.tier] - TIER_ORDER[right.rule.tier]);
4060
4061
  }
4061
4062
  const TIER_ORDER = {
4062
4063
  hard: 0,
@@ -4257,7 +4258,7 @@ async function sendDecision(provider, apiKey, request, options) {
4257
4258
  const value = parsed.answers[id];
4258
4259
  if (value === void 0) throw new DecisionRequestError("invalid-response", requestBytes, "Decision API omitted a requested answer");
4259
4260
  const distribution = Object.values(value.probabilities);
4260
- if (Math.abs(distribution.reduce((sum, p) => sum + p, 0) - 1) > .010000001 || (value.probabilities[value.choice] ?? 0) < Math.max(...distribution)) throw new DecisionRequestError("invalid-response", requestBytes, "Decision API returned invalid probabilities");
4261
+ if (Math.abs(distribution.reduce((sum, probability) => sum + probability, 0) - 1) > .010000001 || (value.probabilities[value.choice] ?? 0) < Math.max(...distribution)) throw new DecisionRequestError("invalid-response", requestBytes, "Decision API returned invalid probabilities");
4261
4262
  }
4262
4263
  return {
4263
4264
  model: parsed.model,
@@ -4714,7 +4715,7 @@ function classifyRemove(args, cwd) {
4714
4715
  const resolved = isAbsolute(stripped) ? normalize(stripped) : normalize(`${cwd}/${stripped}`);
4715
4716
  const within = relative(cwd, resolved);
4716
4717
  if (within === "" || within.startsWith("..") || isAbsolute(within)) return null;
4717
- const last = within.split(/[\\/]/u).filter((s) => s !== "").at(-1);
4718
+ const last = within.split(/[\\/]/u).filter((segment) => segment !== "").at(-1);
4718
4719
  if (last === void 0 || !REGENERABLE_DIRS.has(last)) return null;
4719
4720
  }
4720
4721
  return "Regenerable output";
@@ -5314,7 +5315,7 @@ function readRuntime() {
5314
5315
  return {
5315
5316
  host: readHostEnvironment(),
5316
5317
  now: Date.now,
5317
- timeout: (ms) => AbortSignal.timeout(ms),
5318
+ timeout: (timeoutMs) => AbortSignal.timeout(timeoutMs),
5318
5319
  fetch: (url, init) => fetch(url, init),
5319
5320
  findCheckout: (start, env) => findCheckout(start, env)
5320
5321
  };