loki-mode 11.145.0 → 11.147.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.
Files changed (78) hide show
  1. package/SKILL.md +2 -2
  2. package/VERSION +1 -1
  3. package/autonomy/lib/secret-scan.sh +7 -2
  4. package/autonomy/verify.sh +7 -2
  5. package/dashboard/__init__.py +1 -1
  6. package/docs/CLI-REFERENCE.md +1 -1
  7. package/docs/INSTALLATION.md +1 -1
  8. package/loki-ts/dist/loki.js +1899 -1846
  9. package/mcp/__init__.py +1 -1
  10. package/package.json +2 -2
  11. package/packages/control-plane/dist/ask-tools-server.js +10 -1
  12. package/packages/control-plane/dist/server.js +1072 -423
  13. package/packages/control-plane/src/server/routes/index.ts +2 -1
  14. package/packages/control-plane/src/server/routes/workspace.ts +126 -0
  15. package/packages/control-plane/src/server/runs.ts +8 -0
  16. package/packages/control-plane/ui/dist/assets/index-CWUisTer.css +1 -0
  17. package/packages/control-plane/ui/dist/assets/index-CwNcWbo3.js +151 -0
  18. package/packages/control-plane/ui/dist/index.html +2 -2
  19. package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
  20. package/web-app/dist/assets/{AdminPage-Dtrte_9h.js → AdminPage-BMvwexjQ.js} +1 -1
  21. package/web-app/dist/assets/{Avatar-BqDxz5Iw.js → Avatar-CfkC79c3.js} +1 -1
  22. package/web-app/dist/assets/{Badge-BGX45Lnh.js → Badge-CQqH4Hem.js} +1 -1
  23. package/web-app/dist/assets/{Button-DVr538c3.js → Button-4UdYP24d.js} +1 -1
  24. package/web-app/dist/assets/{CockpitPage-CIODjzWx.js → CockpitPage-C7LEbCrM.js} +1 -1
  25. package/web-app/dist/assets/{ComparePage-DSaexpQe.js → ComparePage-Ve1BS_x2.js} +1 -1
  26. package/web-app/dist/assets/{ErrorBoundary-CnkNmsIK.js → ErrorBoundary-Cl9od_1B.js} +1 -1
  27. package/web-app/dist/assets/{EvidenceReceiptPanel-BOYje705.js → EvidenceReceiptPanel-5eTo3MR7.js} +1 -1
  28. package/web-app/dist/assets/{GitHubIssuesPanel-D-obZbg0.js → GitHubIssuesPanel-ChxzVbJj.js} +1 -1
  29. package/web-app/dist/assets/{GitHubPRsPanel-BDP6UPrV.js → GitHubPRsPanel-DMyctO75.js} +1 -1
  30. package/web-app/dist/assets/{HomePage-CyuUJmkD.js → HomePage-XkiUsK0I.js} +2 -2
  31. package/web-app/dist/assets/{LoginPage-CwzpHE77.js → LoginPage-Do4AESUj.js} +1 -1
  32. package/web-app/dist/assets/{MagicPage-B-2U-xDs.js → MagicPage-tQT4NhvK.js} +1 -1
  33. package/web-app/dist/assets/{MetricsPage-cNfnAqIP.js → MetricsPage-BRpQ5j9b.js} +1 -1
  34. package/web-app/dist/assets/{NotFoundPage-Bnja4u7t.js → NotFoundPage-CClAf7lp.js} +1 -1
  35. package/web-app/dist/assets/{ProjectPage-DxKwokda.js → ProjectPage-Bm_5mzNw.js} +3 -3
  36. package/web-app/dist/assets/{ProjectsPage-D0HElwG2.js → ProjectsPage-BEqNV5uq.js} +1 -1
  37. package/web-app/dist/assets/{SettingsPage-cKZTmoDV.js → SettingsPage-B-3niEp-.js} +1 -1
  38. package/web-app/dist/assets/{ShowcasePage-COCzMSj2.js → ShowcasePage-Bgmf8L36.js} +1 -1
  39. package/web-app/dist/assets/{SystemSettingsPage-DpEdU35g.js → SystemSettingsPage-B2r4ns1l.js} +1 -1
  40. package/web-app/dist/assets/{TeamsPage-CRa-oR3c.js → TeamsPage-CFnggeui.js} +1 -1
  41. package/web-app/dist/assets/{TemplatesPage-CqVQ2RrJ.js → TemplatesPage-A_4uAZY6.js} +1 -1
  42. package/web-app/dist/assets/{TerminalOutput-77EBpy6w.js → TerminalOutput-BoEdnm-M.js} +1 -1
  43. package/web-app/dist/assets/{activity-CwYJMGXJ.js → activity-BOSpWO2W.js} +1 -1
  44. package/web-app/dist/assets/{bell-D7tpnhHd.js → bell-IyUIduRQ.js} +1 -1
  45. package/web-app/dist/assets/{bot-BGEMExhD.js → bot-BM1VS3XN.js} +1 -1
  46. package/web-app/dist/assets/{check-DXYfUB9x.js → check-DaoAoVE6.js} +1 -1
  47. package/web-app/dist/assets/{chevron-left-fmjoQGhm.js → chevron-left-D5iMrc40.js} +1 -1
  48. package/web-app/dist/assets/{circle-alert-Bg5XeK2P.js → circle-alert-DR3HNYeA.js} +1 -1
  49. package/web-app/dist/assets/{clock-CsKyZSPS.js → clock-DOc4LATU.js} +1 -1
  50. package/web-app/dist/assets/{cloud-Bd60jog4.js → cloud-Dks7qs40.js} +1 -1
  51. package/web-app/dist/assets/{code-xml-Ctl0DdWZ.js → code-xml-CMdkWBY9.js} +1 -1
  52. package/web-app/dist/assets/{database-ziASlG1B.js → database-CFaZAV5h.js} +1 -1
  53. package/web-app/dist/assets/{dollar-sign-Bo2f3aLO.js → dollar-sign-3r252MtY.js} +1 -1
  54. package/web-app/dist/assets/{file-code-corner-BZCY8u6u.js → file-code-corner-BdfoBM6Q.js} +1 -1
  55. package/web-app/dist/assets/{file-plus-DZX_AwtZ.js → file-plus-DWgk1WFy.js} +1 -1
  56. package/web-app/dist/assets/{globe-BqP4Lntz.js → globe-CQs1OPNS.js} +1 -1
  57. package/web-app/dist/assets/{hammer-KMjpooTk.js → hammer-BvKxwbdj.js} +1 -1
  58. package/web-app/dist/assets/{index-B_8pnUwl.js → index-DymFh2L1.js} +3 -3
  59. package/web-app/dist/assets/{layers-Bdkz5DFw.js → layers-lcbVWAxC.js} +1 -1
  60. package/web-app/dist/assets/{loader-circle-BV_0L7bg.js → loader-circle-VSOQj5_P.js} +1 -1
  61. package/web-app/dist/assets/{lock-DhK1z1dB.js → lock-c6R6zJnw.js} +1 -1
  62. package/web-app/dist/assets/{package-De8MCdUa.js → package-DELuK13T.js} +1 -1
  63. package/web-app/dist/assets/{plus-BQbDrNgm.js → plus-d2vcE9IO.js} +1 -1
  64. package/web-app/dist/assets/{refresh-cw-BQ2ezlqR.js → refresh-cw-BzJ6JHvZ.js} +1 -1
  65. package/web-app/dist/assets/{rotate-ccw-EuVYh2XK.js → rotate-ccw-CYKipckB.js} +1 -1
  66. package/web-app/dist/assets/{scroll-text-BcrL2UnM.js → scroll-text-DDzufCS2.js} +1 -1
  67. package/web-app/dist/assets/{server-dpdGPXDc.js → server-BPIwN9NB.js} +1 -1
  68. package/web-app/dist/assets/{shield-alert-B2AnkpV_.js → shield-alert-PoaTr3PN.js} +1 -1
  69. package/web-app/dist/assets/{thumbs-up-Zock-j5_.js → thumbs-up-Bb7o5Vke.js} +1 -1
  70. package/web-app/dist/assets/{trash-2-B9zGFCn0.js → trash-2-BT9DxpYE.js} +1 -1
  71. package/web-app/dist/assets/{trending-down-DWQW56VW.js → trending-down-BG2q1nVM.js} +1 -1
  72. package/web-app/dist/assets/{trending-up--6mzkyyP.js → trending-up-DI1UcsKN.js} +1 -1
  73. package/web-app/dist/assets/{upload-CNxdXaU0.js → upload-ZC7osdna.js} +1 -1
  74. package/web-app/dist/assets/{usePolling-CVHCrC_t.js → usePolling-T5CvoNTb.js} +1 -1
  75. package/web-app/dist/assets/{user-CuL3zj1a.js → user-BBesY7Dg.js} +1 -1
  76. package/web-app/dist/index.html +1 -1
  77. package/packages/control-plane/ui/dist/assets/index-DeSVrWgd.css +0 -1
  78. package/packages/control-plane/ui/dist/assets/index-Dy80VLtj.js +0 -190
@@ -12946,171 +12946,6 @@ var init_lean_select = __esm(() => {
12946
12946
  init_relevant_files();
12947
12947
  });
12948
12948
 
12949
- // ../../loki-ts/src/util/claude_model.ts
12950
- var exports_claude_model = {};
12951
- __export(exports_claude_model, {
12952
- resolveClaudeModel: () => resolveClaudeModel,
12953
- isUnresolvedClaudeAlias: () => isUnresolvedClaudeAlias,
12954
- haikuRun: () => haikuRun,
12955
- explicitSetupModel: () => explicitSetupModel,
12956
- claudeTierRank: () => claudeTierRank,
12957
- claudeThinkingSubstitute: () => claudeThinkingSubstitute,
12958
- claudeThinkingMaxEffort: () => claudeThinkingMaxEffort,
12959
- claudeThinkingHasAdaptive: () => claudeThinkingHasAdaptive,
12960
- claudeThinkingAccepted: () => claudeThinkingAccepted,
12961
- claudeEffortLevels: () => claudeEffortLevels,
12962
- chooseSessionModel: () => chooseSessionModel,
12963
- canonicalSessionPin: () => canonicalSessionPin,
12964
- VALID_TIERS: () => VALID_TIERS,
12965
- PROVIDER_DEFAULT_MODEL: () => PROVIDER_DEFAULT_MODEL,
12966
- GENERIC_TIERS: () => GENERIC_TIERS,
12967
- EXPLICIT_MODEL_ENV: () => EXPLICIT_MODEL_ENV,
12968
- DEFAULT_SESSION_MODEL: () => DEFAULT_SESSION_MODEL
12969
- });
12970
- import { readFileSync as readFileSync35 } from "fs";
12971
- import { resolve as resolve12 } from "path";
12972
- function resolveClaudeModel(want) {
12973
- try {
12974
- const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
12975
- return JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.cli_aliases?.[want] ?? want;
12976
- } catch {
12977
- return want;
12978
- }
12979
- }
12980
- function isUnresolvedClaudeAlias(model) {
12981
- return FAMILY_ALIASES.has(model);
12982
- }
12983
- function claudeTierRank(model) {
12984
- try {
12985
- const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
12986
- const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
12987
- if (!Array.isArray(models))
12988
- return null;
12989
- const order2 = [];
12990
- for (const m of models)
12991
- if (m.tier !== "legacy" && !order2.includes(m.tier))
12992
- order2.push(m.tier);
12993
- const id = resolveClaudeModel(model);
12994
- const hit = models.find((m) => m.id === id || m.alias === model);
12995
- const rank = hit ? order2.indexOf(hit.tier) : -1;
12996
- return rank >= 0 ? rank : null;
12997
- } catch {
12998
- return null;
12999
- }
13000
- }
13001
- function claudeEffortLevels(model) {
13002
- try {
13003
- const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13004
- const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
13005
- if (!Array.isArray(models))
13006
- return null;
13007
- const id = resolveClaudeModel(model);
13008
- const levels = models.find((m) => m.id === id || m.alias === model)?.effort?.levels;
13009
- return Array.isArray(levels) ? levels : null;
13010
- } catch {
13011
- return null;
13012
- }
13013
- }
13014
- function claudeThinkingSpec(model) {
13015
- try {
13016
- const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13017
- const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
13018
- if (!Array.isArray(models))
13019
- return null;
13020
- const id = resolveClaudeModel(model);
13021
- return models.find((m) => m.id === id || m.alias === model)?.thinking ?? null;
13022
- } catch {
13023
- return null;
13024
- }
13025
- }
13026
- function claudeThinkingMaxEffort(model, type) {
13027
- const max = claudeThinkingSpec(model)?.max_effort?.[type];
13028
- return typeof max === "string" ? max : null;
13029
- }
13030
- function claudeThinkingSubstitute(model, type) {
13031
- const sub = claudeThinkingSpec(model)?.substitute?.[type];
13032
- return typeof sub === "string" ? sub : null;
13033
- }
13034
- function claudeThinkingAccepted(model, type) {
13035
- const spec = claudeThinkingSpec(model);
13036
- if (!spec || !Array.isArray(spec.types))
13037
- return true;
13038
- return spec.types.includes(type) || typeof spec.substitute?.[type] === "string";
13039
- }
13040
- function claudeThinkingHasAdaptive(model) {
13041
- const types = claudeThinkingSpec(model)?.types;
13042
- return Array.isArray(types) && types.includes("adaptive");
13043
- }
13044
- function canonicalSessionPin(raw2) {
13045
- const v = (raw2 ?? "").trim().toLowerCase();
13046
- if (!v)
13047
- return;
13048
- const pin = GENERIC_TIERS[v] ?? v;
13049
- if (!VALID_TIERS.has(pin)) {
13050
- throw new Error(`unknown LOKI_SESSION_MODEL '${(raw2 ?? "").trim()}' (small|medium|high, planning|development|fast, or opus|sonnet|haiku|fable)`);
13051
- }
13052
- return pin;
13053
- }
13054
- function explicitSetupModel(tier, e = process.env) {
13055
- if (e["LOKI_LEGACY_TIER_SWITCHING"] === "true")
13056
- return;
13057
- const sess = (e["LOKI_SESSION_MODEL"] ?? "").trim().toLowerCase();
13058
- if (tier === "planning" && (sess === "high" || sess === "planning"))
13059
- return e["LOKI_CLAUDE_MODEL_PLANNING"] || e["LOKI_MODEL_PLANNING"] ? undefined : "opus";
13060
- if (tier !== "fast" || sess !== "small" && sess !== "fast" || e["LOKI_CLAUDE_MODEL_FAST"] || e["LOKI_MODEL_FAST"])
13061
- return;
13062
- return e["LOKI_ALLOW_HAIKU"] === undefined || e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : undefined;
13063
- }
13064
- function chooseSessionModel(e = process.env) {
13065
- const carried = canonicalSessionPin(e["LOKI_SESSION_MODEL"]);
13066
- if (e["LOKI_SESSION_MODEL_SOURCE"] === "default" && carried && EXPLICIT_MODEL_ENV.every((k) => k === "LOKI_SESSION_MODEL" || (e[k] ?? "").trim() === ""))
13067
- return { source: "default", pin: carried, why: "Loki default, carried from the parent run" };
13068
- const named = EXPLICIT_MODEL_ENV.find((k) => (e[k] ?? "").trim() !== "");
13069
- if (named)
13070
- return { source: "explicit", pin: null, why: named === "LOKI_SESSION_MODEL" ? "--session-model or LOKI_SESSION_MODEL" : named };
13071
- const router = (e["LOKI_ROUTER"] ?? "").trim().toLowerCase();
13072
- if (["1", "true", "on", "auto"].includes(router))
13073
- return { source: "explicit", pin: null, why: `LOKI_ROUTER=${router}` };
13074
- const raw2 = (e["LOKI_DEFAULT_SESSION_MODEL"] ?? "").trim().toLowerCase();
13075
- if (raw2 === "provider")
13076
- return { source: "provider", pin: null, why: "LOKI_DEFAULT_SESSION_MODEL=provider (the Claude CLI's own default)" };
13077
- const pin = canonicalSessionPin(raw2 || DEFAULT_SESSION_MODEL);
13078
- return { source: "default", pin, why: raw2 ? `LOKI_DEFAULT_SESSION_MODEL=${raw2}` : "Loki default, set another with --session-model or LOKI_DEFAULT_SESSION_MODEL=provider" };
13079
- }
13080
- function haikuRun(e = process.env) {
13081
- const H = /haiku/i, val = (k) => (e[k] ?? "").trim();
13082
- if (val("LOKI_PROVIDER").toLowerCase() === "opencode")
13083
- return H.test(val("LOKI_OPENCODE_MODEL"));
13084
- for (const k of ["LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_MODEL_DEVELOPMENT"])
13085
- if (val(k))
13086
- return H.test(val(k));
13087
- let pin;
13088
- try {
13089
- pin = canonicalSessionPin(e["LOKI_SESSION_MODEL"]) ?? chooseSessionModel(e).pin ?? undefined;
13090
- } catch {
13091
- return false;
13092
- }
13093
- if (pin === "haiku")
13094
- return true;
13095
- if (pin === "fast")
13096
- return H.test(explicitSetupModel("fast", e) ?? (val("LOKI_CLAUDE_MODEL_FAST") || val("LOKI_MODEL_FAST") || (e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : "sonnet")));
13097
- if (pin)
13098
- return false;
13099
- return routerPreset(e) && H.test(presetExecutor(e).model);
13100
- }
13101
- var PROVIDER_DEFAULT_MODEL = "claude (provider default)", FAMILY_ALIASES, VALID_TIERS, GENERIC_TIERS, DEFAULT_SESSION_MODEL = "sonnet", EXPLICIT_MODEL_ENV;
13102
- var init_claude_model = __esm(() => {
13103
- init_paths();
13104
- FAMILY_ALIASES = new Set(["haiku", "sonnet", "opus", "fable"]);
13105
- VALID_TIERS = new Set(["planning", "development", "fast", "opus", "sonnet", "haiku", "fable"]);
13106
- GENERIC_TIERS = {
13107
- small: "fast",
13108
- medium: "development",
13109
- high: "planning"
13110
- };
13111
- EXPLICIT_MODEL_ENV = ["LOKI_SESSION_MODEL", "LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_MODEL_DEVELOPMENT", "LOKI_MODEL_PLANNING", "LOKI_MODEL_FAST", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_CLAUDE_MODEL_PLANNING", "LOKI_CLAUDE_MODEL_FAST"];
13112
- });
13113
-
13114
12949
  // ../../loki-ts/src/features/decompose.ts
13115
12950
  function isSharedFile(path) {
13116
12951
  const base = path.slice(path.lastIndexOf("/") + 1);
@@ -13300,10 +13135,9 @@ var SHARED_BASENAME, LIST_RE, HEAD_RE, SOLUTION_WORD, ACCEPT_WORD, CONTEXT_WORD,
13300
13135
  return true;
13301
13136
  if (/^(0|off|false|no)$/i.test(v))
13302
13137
  return false;
13303
- return !haikuRun(env);
13138
+ return true;
13304
13139
  }, MS_HEAD_RE, MS_KEY_RE, uniqSorted = (a) => [...new Set(a)].sort();
13305
13140
  var init_decompose = __esm(() => {
13306
- init_claude_model();
13307
13141
  SHARED_BASENAME = /^(package\.json|package-lock\.json|bun\.lockb?|yarn\.lock|pnpm-lock\.yaml|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|poetry\.lock|Pipfile\.lock|requirements\.txt|pyproject\.toml|CHANGELOG(\.md)?|index\.(ts|tsx|js|jsx|mjs)|__init__\.py|mod\.rs)$/i;
13308
13142
  LIST_RE = /^\s*(?:\d+[.)]|[-*+])\s+(?:\[[ xX]\]\s+)?(\S.*)$/;
13309
13143
  HEAD_RE = /^\s{0,3}#{1,6}\s+(\S.*?)\s*#*\s*$/;
@@ -13318,6 +13152,171 @@ var init_decompose = __esm(() => {
13318
13152
  MS_KEY_RE = /^milestones:\s*$/i;
13319
13153
  });
13320
13154
 
13155
+ // ../../loki-ts/src/util/claude_model.ts
13156
+ var exports_claude_model = {};
13157
+ __export(exports_claude_model, {
13158
+ resolveClaudeModel: () => resolveClaudeModel,
13159
+ isUnresolvedClaudeAlias: () => isUnresolvedClaudeAlias,
13160
+ haikuRun: () => haikuRun,
13161
+ explicitSetupModel: () => explicitSetupModel,
13162
+ claudeTierRank: () => claudeTierRank,
13163
+ claudeThinkingSubstitute: () => claudeThinkingSubstitute,
13164
+ claudeThinkingMaxEffort: () => claudeThinkingMaxEffort,
13165
+ claudeThinkingHasAdaptive: () => claudeThinkingHasAdaptive,
13166
+ claudeThinkingAccepted: () => claudeThinkingAccepted,
13167
+ claudeEffortLevels: () => claudeEffortLevels,
13168
+ chooseSessionModel: () => chooseSessionModel,
13169
+ canonicalSessionPin: () => canonicalSessionPin,
13170
+ VALID_TIERS: () => VALID_TIERS,
13171
+ PROVIDER_DEFAULT_MODEL: () => PROVIDER_DEFAULT_MODEL,
13172
+ GENERIC_TIERS: () => GENERIC_TIERS,
13173
+ EXPLICIT_MODEL_ENV: () => EXPLICIT_MODEL_ENV,
13174
+ DEFAULT_SESSION_MODEL: () => DEFAULT_SESSION_MODEL
13175
+ });
13176
+ import { readFileSync as readFileSync35 } from "fs";
13177
+ import { resolve as resolve12 } from "path";
13178
+ function resolveClaudeModel(want) {
13179
+ try {
13180
+ const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13181
+ return JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.cli_aliases?.[want] ?? want;
13182
+ } catch {
13183
+ return want;
13184
+ }
13185
+ }
13186
+ function isUnresolvedClaudeAlias(model) {
13187
+ return FAMILY_ALIASES.has(model);
13188
+ }
13189
+ function claudeTierRank(model) {
13190
+ try {
13191
+ const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13192
+ const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
13193
+ if (!Array.isArray(models))
13194
+ return null;
13195
+ const order2 = [];
13196
+ for (const m of models)
13197
+ if (m.tier !== "legacy" && !order2.includes(m.tier))
13198
+ order2.push(m.tier);
13199
+ const id = resolveClaudeModel(model);
13200
+ const hit = models.find((m) => m.id === id || m.alias === model);
13201
+ const rank = hit ? order2.indexOf(hit.tier) : -1;
13202
+ return rank >= 0 ? rank : null;
13203
+ } catch {
13204
+ return null;
13205
+ }
13206
+ }
13207
+ function claudeEffortLevels(model) {
13208
+ try {
13209
+ const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13210
+ const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
13211
+ if (!Array.isArray(models))
13212
+ return null;
13213
+ const id = resolveClaudeModel(model);
13214
+ const levels = models.find((m) => m.id === id || m.alias === model)?.effort?.levels;
13215
+ return Array.isArray(levels) ? levels : null;
13216
+ } catch {
13217
+ return null;
13218
+ }
13219
+ }
13220
+ function claudeThinkingSpec(model) {
13221
+ try {
13222
+ const path = process.env["LOKI_MODEL_CATALOG"] || resolve12(REPO_ROOT, "providers/model_catalog.json");
13223
+ const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
13224
+ if (!Array.isArray(models))
13225
+ return null;
13226
+ const id = resolveClaudeModel(model);
13227
+ return models.find((m) => m.id === id || m.alias === model)?.thinking ?? null;
13228
+ } catch {
13229
+ return null;
13230
+ }
13231
+ }
13232
+ function claudeThinkingMaxEffort(model, type) {
13233
+ const max = claudeThinkingSpec(model)?.max_effort?.[type];
13234
+ return typeof max === "string" ? max : null;
13235
+ }
13236
+ function claudeThinkingSubstitute(model, type) {
13237
+ const sub = claudeThinkingSpec(model)?.substitute?.[type];
13238
+ return typeof sub === "string" ? sub : null;
13239
+ }
13240
+ function claudeThinkingAccepted(model, type) {
13241
+ const spec = claudeThinkingSpec(model);
13242
+ if (!spec || !Array.isArray(spec.types))
13243
+ return true;
13244
+ return spec.types.includes(type) || typeof spec.substitute?.[type] === "string";
13245
+ }
13246
+ function claudeThinkingHasAdaptive(model) {
13247
+ const types = claudeThinkingSpec(model)?.types;
13248
+ return Array.isArray(types) && types.includes("adaptive");
13249
+ }
13250
+ function canonicalSessionPin(raw2) {
13251
+ const v = (raw2 ?? "").trim().toLowerCase();
13252
+ if (!v)
13253
+ return;
13254
+ const pin = GENERIC_TIERS[v] ?? v;
13255
+ if (!VALID_TIERS.has(pin)) {
13256
+ throw new Error(`unknown LOKI_SESSION_MODEL '${(raw2 ?? "").trim()}' (small|medium|high, planning|development|fast, or opus|sonnet|haiku|fable)`);
13257
+ }
13258
+ return pin;
13259
+ }
13260
+ function explicitSetupModel(tier, e = process.env) {
13261
+ if (e["LOKI_LEGACY_TIER_SWITCHING"] === "true")
13262
+ return;
13263
+ const sess = (e["LOKI_SESSION_MODEL"] ?? "").trim().toLowerCase();
13264
+ if (tier === "planning" && (sess === "high" || sess === "planning"))
13265
+ return e["LOKI_CLAUDE_MODEL_PLANNING"] || e["LOKI_MODEL_PLANNING"] ? undefined : "opus";
13266
+ if (tier !== "fast" || sess !== "small" && sess !== "fast" || e["LOKI_CLAUDE_MODEL_FAST"] || e["LOKI_MODEL_FAST"])
13267
+ return;
13268
+ return e["LOKI_ALLOW_HAIKU"] === undefined || e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : undefined;
13269
+ }
13270
+ function chooseSessionModel(e = process.env) {
13271
+ const carried = canonicalSessionPin(e["LOKI_SESSION_MODEL"]);
13272
+ if (e["LOKI_SESSION_MODEL_SOURCE"] === "default" && carried && EXPLICIT_MODEL_ENV.every((k) => k === "LOKI_SESSION_MODEL" || (e[k] ?? "").trim() === ""))
13273
+ return { source: "default", pin: carried, why: "Loki default, carried from the parent run" };
13274
+ const named = EXPLICIT_MODEL_ENV.find((k) => (e[k] ?? "").trim() !== "");
13275
+ if (named)
13276
+ return { source: "explicit", pin: null, why: named === "LOKI_SESSION_MODEL" ? "--session-model or LOKI_SESSION_MODEL" : named };
13277
+ const router = (e["LOKI_ROUTER"] ?? "").trim().toLowerCase();
13278
+ if (["1", "true", "on", "auto"].includes(router))
13279
+ return { source: "explicit", pin: null, why: `LOKI_ROUTER=${router}` };
13280
+ const raw2 = (e["LOKI_DEFAULT_SESSION_MODEL"] ?? "").trim().toLowerCase();
13281
+ if (raw2 === "provider")
13282
+ return { source: "provider", pin: null, why: "LOKI_DEFAULT_SESSION_MODEL=provider (the Claude CLI's own default)" };
13283
+ const pin = canonicalSessionPin(raw2 || DEFAULT_SESSION_MODEL);
13284
+ return { source: "default", pin, why: raw2 ? `LOKI_DEFAULT_SESSION_MODEL=${raw2}` : "Loki default, set another with --session-model or LOKI_DEFAULT_SESSION_MODEL=provider" };
13285
+ }
13286
+ function haikuRun(e = process.env) {
13287
+ const H = /haiku/i, val = (k) => (e[k] ?? "").trim();
13288
+ if (val("LOKI_PROVIDER").toLowerCase() === "opencode")
13289
+ return H.test(val("LOKI_OPENCODE_MODEL"));
13290
+ for (const k of ["LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_MODEL_DEVELOPMENT"])
13291
+ if (val(k))
13292
+ return H.test(val(k));
13293
+ let pin;
13294
+ try {
13295
+ pin = canonicalSessionPin(e["LOKI_SESSION_MODEL"]) ?? chooseSessionModel(e).pin ?? undefined;
13296
+ } catch {
13297
+ return false;
13298
+ }
13299
+ if (pin === "haiku")
13300
+ return true;
13301
+ if (pin === "fast")
13302
+ return H.test(explicitSetupModel("fast", e) ?? (val("LOKI_CLAUDE_MODEL_FAST") || val("LOKI_MODEL_FAST") || (e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : "sonnet")));
13303
+ if (pin)
13304
+ return false;
13305
+ return routerPreset(e) && H.test(presetExecutor(e).model);
13306
+ }
13307
+ var PROVIDER_DEFAULT_MODEL = "claude (provider default)", FAMILY_ALIASES, VALID_TIERS, GENERIC_TIERS, DEFAULT_SESSION_MODEL = "sonnet", EXPLICIT_MODEL_ENV;
13308
+ var init_claude_model = __esm(() => {
13309
+ init_paths();
13310
+ FAMILY_ALIASES = new Set(["haiku", "sonnet", "opus", "fable"]);
13311
+ VALID_TIERS = new Set(["planning", "development", "fast", "opus", "sonnet", "haiku", "fable"]);
13312
+ GENERIC_TIERS = {
13313
+ small: "fast",
13314
+ medium: "development",
13315
+ high: "planning"
13316
+ };
13317
+ EXPLICIT_MODEL_ENV = ["LOKI_SESSION_MODEL", "LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_MODEL_DEVELOPMENT", "LOKI_MODEL_PLANNING", "LOKI_MODEL_FAST", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_CLAUDE_MODEL_PLANNING", "LOKI_CLAUDE_MODEL_FAST"];
13318
+ });
13319
+
13321
13320
  // ../../loki-ts/src/runner/router/decision.ts
13322
13321
  var exports_decision = {};
13323
13322
  __export(exports_decision, {
@@ -17710,7 +17709,7 @@ function redOnBaseProfile(p, ids, errors2) {
17710
17709
  for (const [k, v] of Object.entries(b.failing_errors ?? {}))
17711
17710
  if (!baseErr.has(k))
17712
17711
  baseErr.set(k, v);
17713
- return ids.length > 0 && ids.every((i) => baseIds.has(i) || [...baseIds].some((b) => b.endsWith(` > ${i}`))) && sameErrors(errors2, baseErr, [...ids]);
17712
+ return ids.length > 0 && ids.every((i) => baseIds.has(i) || [...baseIds].some((b) => b.endsWith(` > ${i}`))) && (baseRedByIdOn() || sameErrors(errors2, baseErr, [...ids]));
17714
17713
  }
17715
17714
  function collateralOnBaseline(repoDir, baseSha, test, c, changed, stem) {
17716
17715
  if (!collateralBaselineOn() || changed.includes(test))
@@ -32812,7 +32811,7 @@ ${cmds.join(`
32812
32811
  return { text: text3, files: [...new Set([...files, ...pack.files])], pack: record, packText: pack.text };
32813
32812
  }
32814
32813
  var planHintsOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_PLAN_HINTS"] ?? "").trim()), PLAN_HINT_LEAD = "A plan from an earlier session (a hint, not the scope: the task decides what to change; cover every case the task states even where the plan leaves it out, and edit any file the fix needs):", PINNED_RULE = '- Exception: when the task names an existing test file or asks to change tests, change only what it asks. An existing assertion that pins the OLD behavior the issue explicitly asks to change is not a spec conflict: change its expected value to the behavior the issue states, change nothing else in that test, and before the last line of your reply write one line per such change: `UPDATED TEST <path>:<line>: <old expectation> -> <new expectation>; issue: "<the issue sentence that asks for the new behavior>"`. Never delete a test, add skip, xfail or only, widen a tolerance, or touch a test unrelated to the behavior the issue names; any other existing test that contradicts the task is a spec conflict: cite it.', DOC_RULE_V139 = "- Write no documentation unless the task explicitly asks for it, except the release-note fragment a repository convention listed below requires. Never write documentation, changelog or README text that announces a behavior the code does not have, even to make a test pass: if the task needs code that is not in this repository, finish with LOKI_SPEC_CONFLICT.", DOC_RULE_UPDATE = "- Write no new documentation pages unless the task asks for them, except the release-note fragment a repository convention listed below requires. Do update existing docs that list what you changed: when you add or change an option, flag, method, rule or name that a README or doc page in the repository already lists, add or fix its entry there, written like the entries around it. Never write documentation, changelog or README text that announces a behavior the code does not have, even to make a test pass: if the task needs code that is not in this repository, finish with LOKI_SPEC_CONFLICT.", DOC_RULE, FIXED_RULES, FIXED_RULES_DOC_V139, docUpdateRuleOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_DOC_UPDATE_RULE"] ?? "").trim()), LEGACY_FIXED_RULES, ISSUE_RULE_LINE = "- You may start this repository's own services and throwaway dependencies to exercise your change. Bind anything you start to 127.0.0.1 or a unix socket, never to all interfaces. Create data directories, sockets and scratch files under $TMPDIR. Leave what you started running; Loki stops it after the session. Never stop or signal a process you did not start. Use only a database, cache or server you started yourself under $TMPDIR; never connect to one named in the repository's env files or in your environment, and never apply migrations to it.", SERVER_RULES = `- Never leave a long-lived server running.
32815
- - Never kill processes.`, PROVE_BY_RUNNING_BLOCK = "Before you finish, prove the change works by running it, not by reading it. Exercise each thing the task asks for the way its user or caller reaches it: start the service or program this repository provides (if it needs a database or another dependency, start a throwaway one in a temporary directory), and call every new or changed entry point exactly as its real caller does; for a web or API client, use the exact paths the client code sends. Never use a fixed port number: pick a port you have just checked is free, or a unix socket inside your temporary directory, and call only the processes you started; before the first call, confirm the process answering on that port is the one whose process id you recorded. Prove a fresh install, not only an existing one: start from an empty database or data directory, set it up with the repository's own migrations or setup command, and create the first account, tenant or other record through the product's own code path after your change. Fix whatever fails and run it again. You may say something cannot be run only after you have tried: list each command you tried to find or start it and what it printed. A missing program on PATH is not enough; look where this machine installs it. Before the finish line, list each requested item with the command you ran to prove it and what it returned, then one line starting `Fresh install:` with the commands that built the empty environment and created the first record, and what they returned. Loki checks the label against this list, so an item with no command and result counts as not proved.", PROOF_SCRIPT_LINE = "Put your proof in one script at exactly $LOKI_SCRATCH/loki-proof.sh (the same directory as $TMPDIR; never inside the repository, so it is not part of the change, and never delete it: Loki copies it from there when you finish) and run it yourself until it passes. The acceptance lines the label is checked against are numbered in $LOKI_SCRATCH/acceptance.txt: read it first. The script takes one argument, an empty directory, and must do everything inside it from nothing: create the database or data directory there, apply the repository's own migrations or setup, start what it needs on ports it has just checked are free (bound to 127.0.0.1), and create the first account, tenant or record through the product's own code. Then it proves each numbered line with the functions in $LOKI_SCRATCH/loki-check.sh, which it must source by that exact path (when Loki runs your script the variable points at Loki's own copy): `loki_http <line number> \"<what is proved>\" <expected status> <curl arguments>` for a request, sent the way the real caller sends it (for a page, every path its client code calls, same method and parameters; set LOKI_BODY_MATCH to a pattern the response must contain), and `loki_cmd <line number> \"<what is proved>\" <command>` for anything else (a test run, a query plan, a file that must exist). Only lines these functions print count: a line with no passing check is not met, and one failing check makes it not met, so give every line, including the fresh-install line if listed, at least one real check. It must stop what it started and exit 0 only when every required line is proved. Use paths relative to the repository root for the repository's own files. Loki runs this same script again by itself after you finish, in a new empty directory, and the label is a count of the checks that pass in that run, not of what you write about it.", TAKE_THE_TIME_LINE = "This is an issue to deliver in full, not a quick fix: take the time the work needs and finish every item the issue asks for. Starting this repository's own services and their dependencies to prove the change is expected here, not discouraged.", DELIVER_EACH_LINE = "This issue lists several things to deliver. Deliver each one. If a required one is left undone, finish with LOKI_UNFINISHED and say which. An item the issue marks optional may be skipped: say so and finish with LOKI_DONE.", proveByRunningBlock = (provider, source, env = process.env, cardLine = null) => issueRunBrief(provider, source, env) ? [PROVE_BY_RUNNING_BLOCK, PROOF_SCRIPT_LINE, TAKE_THE_TIME_LINE, DELIVER_EACH_LINE, ...cardLine ? [cardLine] : []].join(`
32814
+ - Never kill processes.`, PROVE_BY_RUNNING_BLOCK = "Before you finish, prove the change works by running it, not by reading it. Exercise each thing the task asks for the way its user or caller reaches it: start the service or program this repository provides (if it needs a database or another dependency, start a throwaway one in a temporary directory), and call every new or changed entry point exactly as its real caller does; for a web or API client, use the exact paths the client code sends. Never use a fixed port number: pick a port you have just checked is free, or a unix socket inside your temporary directory, and call only the processes you started; before the first call, confirm the process answering on that port is the one whose process id you recorded. Prove a fresh install, not only an existing one: start from an empty database or data directory, set it up with the repository's own migrations or setup command, and create the first account, tenant or other record through the product's own code path after your change. Fix whatever fails and run it again. You may say something cannot be run only after you have tried: list each command you tried to find or start it and what it printed. A missing program on PATH is not enough; look where this machine installs it. Before the finish line, list each requested item with the command you ran to prove it and what it returned, then one line starting `Fresh install:` with the commands that built the empty environment and created the first record, and what they returned. Loki checks the label against this list, so an item with no command and result counts as not proved.", PROOF_SCRIPT_LINE = "Put your proof in one script at exactly $LOKI_SCRATCH/loki-proof.sh (the same directory as $TMPDIR; never inside the repository, so it is not part of the change, and never delete it: Loki copies it from there when you finish) and run it yourself until it passes. The acceptance lines the label is checked against are numbered in $LOKI_SCRATCH/acceptance.txt: read it first. The script takes one argument, an empty directory, and must do everything inside it from nothing: create the database or data directory there, apply the repository's own migrations or setup, start what it needs on ports it has just checked are free (bound to 127.0.0.1), and create the first account, tenant or record through the product's own code. Then it proves each numbered line with the functions in $LOKI_SCRATCH/loki-check.sh, which it must source by that exact path (when Loki runs your script the variable points at Loki's own copy): `loki_http <line number> \"<what is proved>\" <expected status> <curl arguments>` for a request, sent the way the real caller sends it (for a page, every path its client code calls, same method and parameters; set LOKI_BODY_MATCH to a pattern the response must contain), and `loki_cmd <line number> \"<what is proved>\" <command>` for anything else (a test run, a query plan, a file that must exist). Only lines these functions print count: a line with no passing check is not met, and one failing check makes it not met, so give every line, including the fresh-install line if listed, at least one real check. It must stop what it started and exit 0 only when every required line is proved. Use paths relative to the repository root for the repository's own files. Loki runs this same script again by itself after you finish, in a new empty directory, and the label is a count of the checks that pass in that run, not of what you write about it. The same file gives you throwaway services: loki_pg_start <dir> and loki_redis_start <dir> start a new empty PostgreSQL or Redis on a free port and export its connection settings, loki_free_port prints a free port, loki_services_stop stops them. Use these for the proof and for your own runs; never use, and never expect, a database or cache that is already running on this machine.", TAKE_THE_TIME_LINE = "This is an issue to deliver in full, not a quick fix: take the time the work needs and finish every item the issue asks for. Starting this repository's own services and their dependencies to prove the change is expected here, not discouraged. Your reply ends this session and nothing runs after it: never end your turn while a subagent or a background command is still working. Wait for it, read its result, and only then reply.", DELIVER_EACH_LINE = "This issue lists several things to deliver. Deliver each one. If a required one is left undone, finish with LOKI_UNFINISHED and say which. An item the issue marks optional may be skipped: say so and finish with LOKI_DONE.", proveByRunningBlock = (provider, source, env = process.env, cardLine = null) => issueRunBrief(provider, source, env) ? [PROVE_BY_RUNNING_BLOCK, PROOF_SCRIPT_LINE, TAKE_THE_TIME_LINE, DELIVER_EACH_LINE, ...cardLine ? [cardLine] : []].join(`
32816
32815
 
32817
32816
  `) : "", pinnedTestUpdateEnabled = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_PINNED_TEST_UPDATE"] ?? "").trim()), fixedRules = (env = process.env, issue = false) => {
32818
32817
  const r = pinnedTestUpdateEnabled(env) ? docUpdateRuleOn(env) ? FIXED_RULES : FIXED_RULES_DOC_V139 : LEGACY_FIXED_RULES;
@@ -33123,7 +33122,7 @@ ${PRESET_PLAN_INSTRUCTION}` : ""),
33123
33122
 
33124
33123
  // ../../loki-ts/src/engine10/proof_rerun.ts
33125
33124
  import { randomBytes as randomBytes7 } from "crypto";
33126
- import { copyFileSync as copyFileSync5, existsSync as existsSync63, readFileSync as readFileSync88, rmSync as rmSync29, statSync as statSync30, writeFileSync as writeFileSync49 } from "fs";
33125
+ import { copyFileSync as copyFileSync5, existsSync as existsSync63, mkdirSync as mkdirSync45, readFileSync as readFileSync88, realpathSync as realpathSync33, rmSync as rmSync29, statSync as statSync30, writeFileSync as writeFileSync49 } from "fs";
33127
33126
  import { join as join97 } from "path";
33128
33127
  function labelAsks(provider, intake, plan, repoDir, env = process.env) {
33129
33128
  if (!issueAcceptanceCapOn(env))
@@ -33159,6 +33158,32 @@ async function worktreeTree(repoDir) {
33159
33158
  } catch {}
33160
33159
  }
33161
33160
  }
33161
+ async function unusedNewFiles(repoDir, baseSha, tree) {
33162
+ if (!baseSha || !tree)
33163
+ return [];
33164
+ try {
33165
+ const a = await run(["git", "-C", repoDir, "diff", "--name-only", "--diff-filter=A", baseSha, tree, "--", ".", ":(exclude).loki"], { timeoutMs: 30000 });
33166
+ if (a.exitCode !== 0)
33167
+ return [];
33168
+ const added = a.stdout.split(`
33169
+ `).filter((f) => UNUSED_EXT.test(f) && !UNUSED_TEST.test(f) && !UNUSED_ENTRY.test(f) && !UNUSED_DIR.test(f) && !/\.d\.ts$|\.config\.[a-z]+$/.test(f)).slice(0, 60), out2 = [];
33170
+ for (const f of added) {
33171
+ const stem2 = f.slice(f.lastIndexOf("/") + 1).replace(/\.[^.]+$/, "");
33172
+ if (stem2.length < 4)
33173
+ continue;
33174
+ const g = await run(["git", "-C", repoDir, "grep", "-l", "-F", "-w", "-e", stem2, tree, "--", "."], { timeoutMs: 30000 });
33175
+ if (g.exitCode > 1)
33176
+ continue;
33177
+ const users = g.stdout.split(`
33178
+ `).map((l) => l.slice(l.indexOf(":") + 1)).filter((u) => u && u !== f && !UNUSED_TEST.test(u));
33179
+ if (users.length === 0)
33180
+ out2.push(f);
33181
+ }
33182
+ return out2;
33183
+ } catch {
33184
+ return [];
33185
+ }
33186
+ }
33162
33187
  function unmetBrief(unmet) {
33163
33188
  return [
33164
33189
  `Loki checked your change against the acceptance lines, using its own run of your proof script. ${unmet.length} line${unmet.length === 1 ? " is" : "s are"} not met yet:`,
@@ -33205,22 +33230,50 @@ function keepProofScript(scratchDir, runDir) {
33205
33230
  const st = statSync30(src);
33206
33231
  if (!st.isFile() || st.size === 0 || st.size > MAX_SCRIPT_BYTES)
33207
33232
  return false;
33208
- copyFileSync5(src, join97(runDir, PROOF_SCRIPT));
33233
+ const real3 = (() => {
33234
+ try {
33235
+ return realpathSync33(scratchDir);
33236
+ } catch {
33237
+ return scratchDir;
33238
+ }
33239
+ })(), names = [...new Set([real3, scratchDir, real3.replace(/^\/private\//, "/")])].filter((d) => d.length > 5).sort((a, b) => b.length - a.length);
33240
+ let text3 = readFileSync88(src, "utf8");
33241
+ for (const d of names)
33242
+ text3 = text3.split(d).join("${LOKI_SCRATCH}");
33243
+ writeFileSync49(join97(runDir, PROOF_SCRIPT), text3, { mode: 448 });
33209
33244
  return true;
33210
33245
  } catch {
33211
33246
  return false;
33212
33247
  }
33213
33248
  }
33249
+ function proofScriptRefusal(text3) {
33250
+ const code = text3.split(`
33251
+ `).filter((l) => !/^\s*#/.test(l)).join(`
33252
+ `);
33253
+ const writes = code.split(`
33254
+ `).filter((l) => /(^|[\s;&|(])(echo|printf|print|tee|cat)\b/.test(l) && !/(^|[\s;&|(])(grep|egrep|awk|sed|rg)\b[^|]*LOKI-PROOF/.test(l));
33255
+ if (writes.some((l) => /LOKI_PROOF_TOKEN/.test(l)))
33256
+ return "the proof script writes output using LOKI_PROOF_TOKEN; results count only when loki_http or loki_cmd print them";
33257
+ if (writes.some((l) => /LOKI-PROOF/.test(l)))
33258
+ return "the proof script prints a LOKI-PROOF result line itself; results count only when loki_http or loki_cmd print them";
33259
+ if (/(^|[\s;&|({])(function\s+)?(loki_http|loki_cmd|_lp)\s*\(\s*\)/.test(code))
33260
+ return "the proof script redefines loki_http, loki_cmd or _lp; source loki-check.sh and use its functions unchanged";
33261
+ return null;
33262
+ }
33214
33263
  async function rerunProof(repoDir, runDir, signal, env = process.env) {
33215
33264
  const script = join97(runDir, PROOF_SCRIPT);
33216
33265
  if (!proofRerunOn(env) || !existsSync63(script))
33217
33266
  return null;
33218
- let scriptChars = 0;
33267
+ let scriptChars = 0, refusal = null;
33219
33268
  try {
33220
- scriptChars = readFileSync88(script, "utf8").length;
33269
+ const t = readFileSync88(script, "utf8");
33270
+ scriptChars = t.length;
33271
+ refusal = proofScriptRefusal(t);
33221
33272
  } catch {
33222
33273
  return null;
33223
33274
  }
33275
+ if (refusal)
33276
+ return { refused: refusal, exit: null, seconds: 0, proved: 0, failed: 0, tail: `Loki did not run this proof script: ${refusal}.`, script_chars: scriptChars, stopped: 0, left: 0, lines: {} };
33224
33277
  let scratch;
33225
33278
  try {
33226
33279
  scratch = createSessionScratch();
@@ -33233,10 +33286,13 @@ async function rerunProof(repoDir, runDir, signal, env = process.env) {
33233
33286
  blank[k] = "";
33234
33287
  const token = randomBytes7(8).toString("hex");
33235
33288
  writeProofKit(scratch.dir, null);
33289
+ writeProofKit(runDir, null);
33236
33290
  const t0 = Date.now();
33237
33291
  let exit = null, out2 = "";
33238
33292
  try {
33239
- const r = await run(["bash", script, scratch.dir], { cwd: repoDir, timeoutMs: proofRerunS(env) * 1000, group: true, signal, env: { ...blank, ...scratchSessionEnv(scratch), LOKI_PROOF_TOKEN: token } });
33293
+ const emptyDir = join97(scratch.dir, "run");
33294
+ mkdirSync45(emptyDir, { mode: 448 });
33295
+ const r = await run(["bash", script, emptyDir], { cwd: repoDir, timeoutMs: proofRerunS(env) * 1000, group: true, signal, env: { ...blank, ...scratchSessionEnv(scratch), LOKI_PROOF_TOKEN: token } });
33240
33296
  exit = r.exitCode;
33241
33297
  out2 = `${r.stdout}
33242
33298
  ${r.stderr}`;
@@ -33269,10 +33325,10 @@ function ruleStatus(asks2, r) {
33269
33325
  const e = r?.lines[String(i + 1)], opt = optionalAsk(line2) ? { optional: true } : {};
33270
33326
  if (e && e.proved > 0 && e.failed === 0)
33271
33327
  return { line: line2, status: "met", evidence: `Loki's own run: ${e.proved} passing check${e.proved === 1 ? "" : "s"}; first: ${e.first_proved ?? ""}`.slice(0, 300), ...opt };
33272
- return { line: line2, status: "unmet", reason: (!r ? "there is no proof script for Loki to run" : r.exit === null ? "Loki's own run of the proof did not finish" : e && e.failed > 0 ? `a check failed in Loki's own run: ${e.first_failed ?? ""}` : "Loki's own run has no passing check for this line").slice(0, 300), ...opt };
33328
+ return { line: line2, status: "unmet", reason: (!r ? "there is no proof script for Loki to run" : r.refused ? `Loki did not run the proof script: ${r.refused}` : r.exit === null ? "Loki's own run of the proof did not finish" : e && e.failed > 0 ? `a check failed in Loki's own run: ${e.first_failed ?? ""}` : "Loki's own run has no passing check for this line").slice(0, 300), ...opt };
33273
33329
  });
33274
33330
  }
33275
- var PROOF_SCRIPT = "loki-proof.sh", PROOF_HELPER = "loki-check.sh", ACCEPTANCE_FILE = "acceptance.txt", PROOF_HELPER_SH = `# Loki proof helpers. Source this file; never edit it. Only lines printed by these functions count toward the label.
33331
+ var UNUSED_EXT, UNUSED_TEST, UNUSED_ENTRY, UNUSED_DIR, unusedNewFileNote = (f) => `new file nothing uses: ${f} is not imported or named by any other file (disclosed, does not cap: on merged history this check also flags files loaded by convention, 7 in about a thousand commits of two repositories)`, PROOF_SCRIPT = "loki-proof.sh", PROOF_HELPER = "loki-check.sh", ACCEPTANCE_FILE = "acceptance.txt", PROOF_HELPER_SH = `# Loki proof helpers. Source this file; never edit it. Only lines printed by these functions count toward the label.
33276
33332
  _lp() { printf 'LOKI-PROOF %s %s %s: %s\\n' "\${LOKI_PROOF_TOKEN:-session}" "$1" "$2" "$3"; }
33277
33333
  # loki_http <line number> "<what is proved>" <expected status> <curl arguments...>
33278
33334
  # Sends the request with curl. Passes when the status equals the expected one (and, when LOKI_BODY_MATCH is set, the body matches that grep -E pattern).
@@ -33296,6 +33352,49 @@ loki_cmd() {
33296
33352
  snip="$(printf '%s' "$out" | tail -n 3 | tr '\\n' ' ' | cut -c1-300)"
33297
33353
  if [ "$rc" = 0 ]; then _lp PROVED "$n" "$what | exit 0 | $snip"; else _lp FAILED "$n" "$what | exit $rc | $snip"; return 1; fi
33298
33354
  }
33355
+
33356
+ # ---- Throwaway services. Use these; never use or expect a database or cache already running on this machine. ----
33357
+ # loki_free_port: prints a TCP port that is free on 127.0.0.1 right now.
33358
+ loki_free_port() {
33359
+ python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1]);s.close()' 2>/dev/null || perl -MIO::Socket::INET -e '$s=IO::Socket::INET->new(Listen=>1,LocalAddr=>"127.0.0.1",LocalPort=>0) or exit 1; print $s->sockport(),"
33360
+ "'
33361
+ }
33362
+ # _loki_bin <name>: prints the path of a program from PATH or the usual install locations.
33363
+ _loki_bin() {
33364
+ local n="$1" d p
33365
+ p="$(command -v "$n" 2>/dev/null)" && [ -n "$p" ] && { printf '%s
33366
+ ' "$p"; return 0; }
33367
+ for d in /opt/homebrew/opt/postgresql@*/bin /opt/homebrew/opt/postgresql/bin /usr/local/opt/postgresql@*/bin /usr/local/opt/postgresql/bin /usr/lib/postgresql/*/bin /usr/pgsql-*/bin /opt/homebrew/bin /usr/local/bin /usr/bin; do
33368
+ [ -x "$d/$n" ] && { printf '%s
33369
+ ' "$d/$n"; return 0; }
33370
+ done
33371
+ return 1
33372
+ }
33373
+ # loki_pg_start <empty dir>: starts a new, empty PostgreSQL under <dir>/pg on a free 127.0.0.1 port (superuser "postgres", no password).
33374
+ # Exports PGHOST PGPORT PGUSER PGDATABASE and DATABASE_URL, and LOKI_PG_BIN (the directory holding psql, createdb). Non-zero with the reason on failure.
33375
+ loki_pg_start() {
33376
+ local dir="$1" initdb pgctl
33377
+ initdb="$(_loki_bin initdb)" && pgctl="$(_loki_bin pg_ctl)" || { echo "loki_pg_start: PostgreSQL programs (initdb, pg_ctl) are not installed on this machine" >&2; return 1; }
33378
+ export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
33379
+ LOKI_PG_DATA="$dir/pg"; LOKI_PG_CTL="$pgctl"; LOKI_PG_BIN="$(dirname "$pgctl")"; PGPORT="$(loki_free_port)" || return 1
33380
+ "$initdb" -D "$LOKI_PG_DATA" -U postgres -A trust -E UTF8 >"$dir/pg-init.log" 2>&1 || { echo "loki_pg_start: initdb failed, see $dir/pg-init.log" >&2; return 1; }
33381
+ "$pgctl" -D "$LOKI_PG_DATA" -l "$dir/pg.log" -w -t 60 -o "-p $PGPORT -c listen_addresses=127.0.0.1 -c unix_socket_directories=''" start >/dev/null 2>&1 || { echo "loki_pg_start: the server did not start, see $dir/pg.log" >&2; return 1; }
33382
+ export LOKI_PG_DATA LOKI_PG_CTL LOKI_PG_BIN PGPORT PGHOST=127.0.0.1 PGUSER=postgres PGDATABASE=postgres DATABASE_URL="postgres://postgres@127.0.0.1:$PGPORT/postgres"
33383
+ }
33384
+ # loki_redis_start <empty dir>: starts a new, empty Redis on a free 127.0.0.1 port. Exports REDIS_HOST REDIS_PORT REDIS_URL.
33385
+ loki_redis_start() {
33386
+ local dir="$1" rs
33387
+ rs="$(_loki_bin redis-server)" || { echo "loki_redis_start: redis-server is not installed on this machine" >&2; return 1; }
33388
+ REDIS_PORT="$(loki_free_port)" || return 1
33389
+ mkdir -p "$dir/redis" && "$rs" --port "$REDIS_PORT" --bind 127.0.0.1 --dir "$dir/redis" --save "" --appendonly no --daemonize yes --pidfile "$dir/redis/redis.pid" --logfile "$dir/redis/redis.log" >/dev/null 2>&1 || { echo "loki_redis_start: redis-server did not start" >&2; return 1; }
33390
+ export REDIS_PORT REDIS_HOST=127.0.0.1 REDIS_URL="redis://127.0.0.1:$REDIS_PORT"; LOKI_REDIS_PID="$dir/redis/redis.pid"
33391
+ }
33392
+ # loki_services_stop: stops what loki_pg_start and loki_redis_start started. Call it from your EXIT trap.
33393
+ loki_services_stop() {
33394
+ [ -n "\${LOKI_PG_DATA:-}" ] && [ -n "\${LOKI_PG_CTL:-}" ] && "$LOKI_PG_CTL" -D "$LOKI_PG_DATA" -m fast stop >/dev/null 2>&1
33395
+ [ -n "\${LOKI_REDIS_PID:-}" ] && [ -f "$LOKI_REDIS_PID" ] && kill "$(cat "$LOKI_REDIS_PID")" 2>/dev/null
33396
+ return 0
33397
+ }
33299
33398
  `, MAX_SCRIPT_BYTES = 200000, TAIL_CHARS = 8000, proofRerunS = (env = process.env) => {
33300
33399
  const n3 = Number(env["LOKI_E10_PROOF_RERUN_S"]);
33301
33400
  return n3 > 0 ? n3 : 600;
@@ -33310,6 +33409,10 @@ var init_proof_rerun = __esm(() => {
33310
33409
  init_intent_card();
33311
33410
  init_stack_tools();
33312
33411
  init_types2();
33412
+ UNUSED_EXT = /\.(tsx?|jsx?|mjs|cjs|vue|svelte|py)$/;
33413
+ UNUSED_TEST = /(^|\/)(__tests__|tests?|spec|e2e|__mocks__|fixtures?|stories)\/|\.(test|spec|stories)\.[a-z]+$|(^|\/)(test_[^/]*|[^/]*_test)\.py$/;
33414
+ UNUSED_ENTRY = /(^|\/)(page|layout|route|index|main|app|server|middleware|loading|error|not-found|template|default|global-error|instrumentation|conftest|setup|manage|__init__|__main__|cli|worker)\.[a-z]+$/;
33415
+ UNUSED_DIR = /(^|\/)(migrations?|scripts?|bin|tools|seeds?|config|\.github|docs?|pages|api|routes|commands|plugins|hooks\.server)\//;
33313
33416
  });
33314
33417
 
33315
33418
  // ../../loki-ts/src/engine10/stages/xreview.ts
@@ -33580,7 +33683,7 @@ var init_implement_route = __esm(() => {
33580
33683
  });
33581
33684
 
33582
33685
  // ../../loki-ts/src/features/patch_protocol.ts
33583
- import { existsSync as existsSync64, lstatSync as lstatSync26, mkdirSync as mkdirSync45, readFileSync as readFileSync89, realpathSync as realpathSync33, rmSync as rmSync30, writeFileSync as writeFileSync50 } from "fs";
33686
+ import { existsSync as existsSync64, lstatSync as lstatSync26, mkdirSync as mkdirSync46, readFileSync as readFileSync89, realpathSync as realpathSync34, rmSync as rmSync30, writeFileSync as writeFileSync50 } from "fs";
33584
33687
  import { basename as basename31, dirname as dirname41, join as join99, normalize as normalize5, relative as relative20, sep as sep20 } from "path";
33585
33688
  function buildPatchBrief(task, code, conventions, checkCmds) {
33586
33689
  return [
@@ -33645,7 +33748,7 @@ function refusal(rules, rel, before, after) {
33645
33748
  }
33646
33749
  function contained(repoDir, rel) {
33647
33750
  try {
33648
- const root = realpathSync33(repoDir);
33751
+ const root = realpathSync34(repoDir);
33649
33752
  let p = join99(root, rel);
33650
33753
  for (;; ) {
33651
33754
  let exists2 = false;
@@ -33654,7 +33757,7 @@ function contained(repoDir, rel) {
33654
33757
  exists2 = true;
33655
33758
  } catch {}
33656
33759
  if (exists2) {
33657
- const r = realpathSync33(p);
33760
+ const r = realpathSync34(p);
33658
33761
  return r === p && (r === root || r.startsWith(root + sep20));
33659
33762
  }
33660
33763
  const up = dirname41(p);
@@ -33719,7 +33822,7 @@ ${lines2.slice(Math.max(0, near - 3), near + 6).join(`
33719
33822
  try {
33720
33823
  for (const [rel, body] of staged) {
33721
33824
  const abs = join99(rules.repoDir, rel);
33722
- mkdirSync45(dirname41(abs), { recursive: true });
33825
+ mkdirSync46(dirname41(abs), { recursive: true });
33723
33826
  writeFileSync50(abs, body, "utf8");
33724
33827
  written.push(rel);
33725
33828
  }
@@ -33994,7 +34097,7 @@ __export(exports_implement, {
33994
34097
  FOLD_PLAN_INSTRUCTION: () => FOLD_PLAN_INSTRUCTION,
33995
34098
  ATTEMPT_BRIEF_FILE: () => ATTEMPT_BRIEF_FILE
33996
34099
  });
33997
- import { existsSync as existsSync65, mkdirSync as mkdirSync46, readFileSync as readFileSync90, rmSync as rmSync31, writeFileSync as writeFileSync51 } from "fs";
34100
+ import { existsSync as existsSync65, mkdirSync as mkdirSync47, readFileSync as readFileSync90, rmSync as rmSync31, writeFileSync as writeFileSync51 } from "fs";
33998
34101
  import { join as join100, relative as relative21 } from "path";
33999
34102
  function impactedTests(ctx) {
34000
34103
  const o = ctx.outputs();
@@ -34237,7 +34340,7 @@ var init_implement = __esm(() => {
34237
34340
 
34238
34341
  `) || null, prior.intake?.assumptions, rankedRemedyEnabled() ? prior.intake?.ranked_remedy : undefined, issue);
34239
34342
  try {
34240
- mkdirSync46(ctx.runDir, { recursive: true });
34343
+ mkdirSync47(ctx.runDir, { recursive: true });
34241
34344
  writeFileSync51(join100(ctx.runDir, ATTEMPT_BRIEF_FILE), fullBrief, "utf8");
34242
34345
  } catch {}
34243
34346
  const firstAttemptModel = attemptsK(ctx.model) > 0 ? attemptModels()[0] : undefined;
@@ -34278,7 +34381,7 @@ var init_implement = __esm(() => {
34278
34381
  record: (n3, prompt, reply) => {
34279
34382
  if (reply && n3 === 1)
34280
34383
  patchNote = reply.split(/^FILE:/m)[0].trim();
34281
- mkdirSync46(ctx.runDir, { recursive: true });
34384
+ mkdirSync47(ctx.runDir, { recursive: true });
34282
34385
  writeFileSync51(join100(ctx.runDir, `implement-patch-${n3}.txt`), `${prompt}
34283
34386
 
34284
34387
  === REPLY ===
@@ -34440,16 +34543,22 @@ ${r.session.summary}` };
34440
34543
  }
34441
34544
  const lineRounds = [];
34442
34545
  const proofRounds = [];
34443
- for (let round2 = 0;round2 < proofLoopMax() && scratch && proofRerunOn() && existsSync65(join100(scratch.dir, PROOF_SCRIPT)) && !signal.aborted && !session.killed && session.exit === 0 && !session.markers.specConflict && !session.markers.alreadyDone; round2++) {
34546
+ let proofFails = 0, lineTurns = 0;
34547
+ const LINE_TURNS_MAX = 2;
34548
+ for (let round2 = 0;proofFails < proofLoopMax() && scratch && proofRerunOn() && existsSync65(join100(scratch.dir, PROOF_SCRIPT)) && !signal.aborted && !session.killed && session.exit === 0 && !session.markers.specConflict && !session.markers.alreadyDone; round2++) {
34444
34549
  if (!keepProofScript(scratch.dir, ctx.runDir))
34445
34550
  break;
34446
34551
  const pr = await rerunProof(ctx.repoDir, ctx.runDir, signal);
34447
34552
  if (!pr)
34448
34553
  break;
34449
34554
  proofRounds.push({ exit: pr.exit, failed: pr.failed, seconds: pr.seconds });
34555
+ {
34556
+ const la0 = labelAsks(ctx.provider, prior.intake, prior.plan, ctx.repoDir);
34557
+ ctx.emit("proof.rerun", "implement", { round: round2 + 1, exit: pr.exit, proved: pr.proved, failed: pr.failed, seconds: pr.seconds, source: la0.source, statuses: ruleStatus(la0.asks, pr).map((s, i) => ({ line: s.line, status: s.status, checks: pr.lines[String(i + 1)]?.proved ?? 0, ...s.reason ? { reason: s.reason } : {} })) });
34558
+ }
34450
34559
  if (pr.exit === 0 && pr.failed === 0) {
34451
34560
  const la = labelAsks(ctx.provider, prior.intake, prior.plan, ctx.repoDir);
34452
- if (!la.asks.length || round2 + 1 >= proofLoopMax())
34561
+ if (!la.asks.length || lineTurns >= LINE_TURNS_MAX)
34453
34562
  break;
34454
34563
  const tree = await worktreeTree(ctx.repoDir);
34455
34564
  if (!tree)
@@ -34462,7 +34571,11 @@ ${r.session.summary}` };
34462
34571
  return [{ line: `${i + 1}. ${line2}`, reason: byRule[i].reason ?? "" }];
34463
34572
  return lc.marks && !lc.marks.met.includes(i + 1) ? [{ line: `${i + 1}. ${line2}`, reason: `it has a passing check, but a reviewer found a gap: ${lc.reasons?.[String(i + 1)] ?? "not stated"}` }] : [];
34464
34573
  });
34574
+ const lineUnmet = unmet.length;
34575
+ for (const f of await unusedNewFiles(ctx.repoDir, ctx.baseSha, tree))
34576
+ unmet.push({ line: `(not an acceptance line) ${f}`, reason: "no other file in the repository imports or names this new file, so a user cannot reach what it does. Mount it where it belongs (a page, a route, a registry, a menu) and prove that path, or remove it" });
34465
34577
  lineRounds.push({ met: lc.marks?.met.length ?? 0, unmet: unmet.length, usd: lc.usd });
34578
+ ctx.emit("acceptance.round", "implement", { round: round2 + 1, met: la.asks.length - lineUnmet, unmet: lineUnmet, ...unmet.length > lineUnmet ? { unused_new_files: unmet.length - lineUnmet } : {} });
34466
34579
  if (!unmet.length)
34467
34580
  break;
34468
34581
  const r2 = await resumeForProofScript(ctx, { ...unchained(), iterationId: ids[ids.length - 1] }, session, unmetBrief(unmet));
@@ -34470,6 +34583,7 @@ ${r.session.summary}` };
34470
34583
  ids.push(r2.iterationId);
34471
34584
  else
34472
34585
  break;
34586
+ lineTurns++;
34473
34587
  if (r2.session.summary)
34474
34588
  session = { ...session, summary: `${session.summary ?? ""}
34475
34589
 
@@ -34486,6 +34600,7 @@ Find out why it fails when it starts from nothing. A script that passed for you
34486
34600
  ids.push(r.iterationId);
34487
34601
  else
34488
34602
  break;
34603
+ proofFails++;
34489
34604
  if (r.session.summary)
34490
34605
  session = { ...session, summary: `${session.summary ?? ""}
34491
34606
 
@@ -34609,7 +34724,7 @@ ${session.summary.slice(-4000)}` : session.summary.slice(-16000) } : {},
34609
34724
  if (exit !== "error")
34610
34725
  return { status: "completed", data };
34611
34726
  const stderrTail = session.stderrTail ?? "";
34612
- mkdirSync46(ctx.runDir, { recursive: true });
34727
+ mkdirSync47(ctx.runDir, { recursive: true });
34613
34728
  const stderrPath = join100(ctx.runDir, `${iterationId}.stderr.log`);
34614
34729
  writeFileSync51(stderrPath, stderrTail, "utf8");
34615
34730
  data.stderr_path = stderrPath;
@@ -34685,7 +34800,7 @@ var init_run_control = __esm(() => {
34685
34800
  });
34686
34801
 
34687
34802
  // ../../loki-ts/src/providers/provider_guard.ts
34688
- import { copyFileSync as copyFileSync6, existsSync as existsSync67, lstatSync as lstatSync27, mkdirSync as mkdirSync47, readFileSync as readFileSync92, readdirSync as readdirSync36, readlinkSync as readlinkSync4, realpathSync as realpathSync34, rmSync as rmSync32 } from "fs";
34803
+ import { copyFileSync as copyFileSync6, existsSync as existsSync67, lstatSync as lstatSync27, mkdirSync as mkdirSync48, readFileSync as readFileSync92, readdirSync as readdirSync36, readlinkSync as readlinkSync4, realpathSync as realpathSync35, rmSync as rmSync32 } from "fs";
34689
34804
  import { dirname as dirname42, isAbsolute as isAbsolute16, join as join102, relative as relative22, resolve as resolve24 } from "path";
34690
34805
  function providerSandboxFlags(provider) {
34691
34806
  return [];
@@ -34696,7 +34811,7 @@ function beginGuard(cwd, backupRoot) {
34696
34811
  return null;
34697
34812
  const gd = gitDir(cwd);
34698
34813
  const backupDir = join102(backupRoot, "guard-backup");
34699
- mkdirSync47(backupDir, { recursive: true });
34814
+ mkdirSync48(backupDir, { recursive: true });
34700
34815
  if (existsSync67(join102(gd, "config")))
34701
34816
  copyFileSync6(join102(gd, "config"), join102(backupDir, "config"));
34702
34817
  const tracked = git6(cwd, ["ls-files"]).split(`
@@ -34710,7 +34825,7 @@ function escapesProject(root, linkPath) {
34710
34825
  try {
34711
34826
  const target = readlinkSync4(linkPath);
34712
34827
  const abs = isAbsolute16(target) ? target : resolve24(dirname42(linkPath), target);
34713
- const rel = relative22(realpathSync34(root), existsSync67(abs) ? realpathSync34(abs) : abs);
34828
+ const rel = relative22(realpathSync35(root), existsSync67(abs) ? realpathSync35(abs) : abs);
34714
34829
  return rel.startsWith("..") || isAbsolute16(rel);
34715
34830
  } catch {
34716
34831
  return false;
@@ -34859,7 +34974,7 @@ var init_provider_guard = __esm(() => {
34859
34974
  });
34860
34975
 
34861
34976
  // ../../loki-ts/src/e10ext/budget_cap.ts
34862
- import { appendFileSync as appendFileSync10, existsSync as existsSync68, mkdirSync as mkdirSync48, readdirSync as readdirSync37, readFileSync as readFileSync93, writeFileSync as writeFileSync53 } from "fs";
34977
+ import { appendFileSync as appendFileSync10, existsSync as existsSync68, mkdirSync as mkdirSync49, readdirSync as readdirSync37, readFileSync as readFileSync93, writeFileSync as writeFileSync53 } from "fs";
34863
34978
  import { join as join103, resolve as resolve25 } from "path";
34864
34979
  function hasApiKey(env) {
34865
34980
  return ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "OPENROUTER_API_KEY", "LOKI_MODEL_API_KEY"].some((k) => (env[k] ?? "") !== "");
@@ -34903,7 +35018,7 @@ function groupEnv(env, capUsd, repoDir) {
34903
35018
  if (repoDir && !out2.LOKI_BUDGET_LEDGER) {
34904
35019
  try {
34905
35020
  const d = join103(resolve25(repoDir), ".loki", "runs");
34906
- mkdirSync48(d, { recursive: true });
35021
+ mkdirSync49(d, { recursive: true });
34907
35022
  out2.LOKI_BUDGET_LEDGER = join103(d, `group-${process.pid}-${Date.now()}.ledger`);
34908
35023
  } catch (e) {
34909
35024
  out2.LOKI_BUDGET_LEDGER = join103(resolve25(repoDir), ".loki", "runs", "unusable", "group.ledger");
@@ -35031,7 +35146,7 @@ function childBudgetLimit(remaining) {
35031
35146
  function writeBudgetStop(repoDir, runId, rec2) {
35032
35147
  try {
35033
35148
  const d = join103(repoDir, ".loki", "runs", runId);
35034
- mkdirSync48(d, { recursive: true });
35149
+ mkdirSync49(d, { recursive: true });
35035
35150
  writeFileSync53(join103(d, "budget.json"), JSON.stringify({ ...rec2, outcome: "budget_stopped" }) + `
35036
35151
  `);
35037
35152
  } catch {}
@@ -35100,7 +35215,7 @@ __export(exports_machine, {
35100
35215
  FLOW: () => FLOW,
35101
35216
  BASE_RED_CONFLICT: () => BASE_RED_CONFLICT
35102
35217
  });
35103
- import { existsSync as existsSync69, mkdirSync as mkdirSync49, mkdtempSync as mkdtempSync15, rmSync as rmSync33, writeFileSync as writeFileSync54 } from "fs";
35218
+ import { existsSync as existsSync69, mkdirSync as mkdirSync50, mkdtempSync as mkdtempSync15, rmSync as rmSync33, writeFileSync as writeFileSync54 } from "fs";
35104
35219
  import { tmpdir as tmpdir19 } from "os";
35105
35220
  import { isAbsolute as isAbsolute17, join as join104, relative as relative23 } from "path";
35106
35221
  async function optional(path) {
@@ -35481,7 +35596,7 @@ ${wallTail}` : brief0;
35481
35596
  else
35482
35597
  try {
35483
35598
  const w = a;
35484
- mkdirSync49(join104(base, relative23(ctx.repoDir, w.targetDir)), { recursive: true });
35599
+ mkdirSync50(join104(base, relative23(ctx.repoDir, w.targetDir)), { recursive: true });
35485
35600
  for (const [n3, c] of w.contents)
35486
35601
  writeFileSync54(join104(base, relative23(ctx.repoDir, w.targetDir), n3), c, "utf8");
35487
35602
  r = j.split.install(sctx, a, base);
@@ -35844,7 +35959,7 @@ __export(exports_prove, {
35844
35959
  LIST_S: () => LIST_S,
35845
35960
  ALSO_ON_BASE: () => ALSO_ON_BASE
35846
35961
  });
35847
- import { existsSync as existsSync70, mkdirSync as mkdirSync50, mkdtempSync as mkdtempSync16, readdirSync as readdirSync38, readFileSync as readFileSync94, readlinkSync as readlinkSync5, realpathSync as realpathSync35, rmSync as rmSync34, writeFileSync as writeFileSync55 } from "fs";
35962
+ import { existsSync as existsSync70, mkdirSync as mkdirSync51, mkdtempSync as mkdtempSync16, readdirSync as readdirSync38, readFileSync as readFileSync94, readlinkSync as readlinkSync5, realpathSync as realpathSync36, rmSync as rmSync34, writeFileSync as writeFileSync55 } from "fs";
35848
35963
  import { tmpdir as tmpdir20 } from "os";
35849
35964
  import { join as join105, relative as relative24 } from "path";
35850
35965
  function proverBrief(issue, asks2, dir, card, scriptS) {
@@ -36009,7 +36124,7 @@ function cancelProve() {
36009
36124
  }
36010
36125
  async function runPass(root, dir, out2, ids, signal, o = {}) {
36011
36126
  rmSync34(out2, { recursive: true, force: true });
36012
- mkdirSync50(out2, { recursive: true });
36127
+ mkdirSync51(out2, { recursive: true });
36013
36128
  for (const f of ["endpoints", "pids"])
36014
36129
  rmSync34(join105(dir, f), { force: true });
36015
36130
  const scratch = createSessionScratch(join105(dir, "..")), tmp = scratch.dir, since = Date.now(), scriptS = o.scriptS ?? scriptLimitS(), passS = o.passS ?? 480, teardownS = o.teardownS ?? TEARDOWN_S;
@@ -36173,7 +36288,7 @@ var off2 = (v) => /^(0|off|false|no)$/i.test((v ?? "").trim()), num6 = (v, d) =>
36173
36288
  return m ? Number(m[1]) : null;
36174
36289
  }, real3 = (p) => {
36175
36290
  try {
36176
- return realpathSync35(p);
36291
+ return realpathSync36(p);
36177
36292
  } catch {
36178
36293
  return p;
36179
36294
  }
@@ -36276,7 +36391,7 @@ var init_prove = __esm(() => {
36276
36391
  ctx.emit("prove.started", "prove", { dir: dirRel, budget_s: budgetS, reused: fixed !== null });
36277
36392
  if (!fixed) {
36278
36393
  rmSync34(dir, { recursive: true, force: true });
36279
- mkdirSync50(dir, { recursive: true });
36394
+ mkdirSync51(dir, { recursive: true });
36280
36395
  let accepted = null, rejected = [];
36281
36396
  for (let attempt = 1;attempt <= 2 && !signal.aborted && accepted === null; attempt++) {
36282
36397
  const out2 = join105(dir, `asks-list-${attempt}.json`), cwd = mkdtempSync16(join105(tmpdir20(), "loki-prove-list-")), id = `${ctx.runId}-prove-ls${attempt}`;
@@ -36576,7 +36691,7 @@ var init_reviewer_body = __esm(() => {
36576
36691
  // ../../loki-ts/src/features/visual_evidence.ts
36577
36692
  import { spawn as spawn9 } from "child_process";
36578
36693
  import { createHash as createHash23, randomBytes as randomBytes8 } from "crypto";
36579
- import { existsSync as existsSync71, lstatSync as lstatSync28, mkdirSync as mkdirSync51, readdirSync as readdirSync39, readFileSync as readFileSync96, writeFileSync as writeFileSync56 } from "fs";
36694
+ import { existsSync as existsSync71, lstatSync as lstatSync28, mkdirSync as mkdirSync52, readdirSync as readdirSync39, readFileSync as readFileSync96, writeFileSync as writeFileSync56 } from "fs";
36580
36695
  import { createServer } from "net";
36581
36696
  import { dirname as dirname45, isAbsolute as isAbsolute18, join as join106, normalize as normalize6, relative as relative25, sep as sep21 } from "path";
36582
36697
  function routeFor(file) {
@@ -36670,7 +36785,7 @@ async function recordE2eMedia(repoDir, runDir, relDir, base, routes, ms, signal)
36670
36785
  return { rels: [], skipped: "playwright e2e video and trace skipped: @playwright/test is not installed in the repo" };
36671
36786
  try {
36672
36787
  const dir = join106(runDir, relDir, "e2e");
36673
- mkdirSync51(dir, { recursive: true });
36788
+ mkdirSync52(dir, { recursive: true });
36674
36789
  writeFileSync56(join106(dir, "walk.spec.cjs"), e2eSpecSource(pkg, base, routes));
36675
36790
  writeFileSync56(join106(dir, "playwright.config.cjs"), `module.exports = { testDir: ".", testMatch: "walk.spec.cjs", outputDir: "./out", reporter: "null", use: { video: "on", trace: "on" } };
36676
36791
  `);
@@ -36810,10 +36925,10 @@ async function captureVisualEvidence(repoDir, runDir, changed, opts = {}) {
36810
36925
  const evRoot = join106(runDir, "evidence");
36811
36926
  if (isSymlink(evRoot))
36812
36927
  return skip2("evidence dir is a symlink");
36813
- mkdirSync51(evRoot, { recursive: true });
36928
+ mkdirSync52(evRoot, { recursive: true });
36814
36929
  if (pages.length > 0) {
36815
36930
  const rel0 = join106("evidence", randomBytes8(6).toString("hex"));
36816
- mkdirSync51(join106(runDir, rel0));
36931
+ mkdirSync52(join106(runDir, rel0));
36817
36932
  const rels = [];
36818
36933
  for (const route of [...new Set(pages.map(routeFor))].slice(0, opts.maxRoutes ?? MAX_ROUTES)) {
36819
36934
  if (aborted() || left() <= 0)
@@ -36846,7 +36961,7 @@ async function captureVisualEvidence(repoDir, runDir, changed, opts = {}) {
36846
36961
  if (aborted())
36847
36962
  return skip2("aborted");
36848
36963
  const hdir = join106(evRoot, randomBytes8(6).toString("hex"));
36849
- mkdirSync51(hdir);
36964
+ mkdirSync52(hdir);
36850
36965
  writeFileSync56(join106(hdir, "http.json"), JSON.stringify(rows, null, 2) + `
36851
36966
  `);
36852
36967
  return { screens: [], http: true, skipped: null };
@@ -36934,7 +37049,7 @@ var init_visual_evidence = __esm(() => {
36934
37049
  });
36935
37050
 
36936
37051
  // ../../loki-ts/src/integrations/before_after.ts
36937
- import { existsSync as existsSync72, mkdirSync as mkdirSync52, symlinkSync as symlinkSync4 } from "fs";
37052
+ import { existsSync as existsSync72, mkdirSync as mkdirSync53, symlinkSync as symlinkSync4 } from "fs";
36938
37053
  import { join as join107 } from "path";
36939
37054
  function hasDevCommand(repoDir) {
36940
37055
  try {
@@ -36964,14 +37079,14 @@ async function captureBeforeAfter(repoDir, runDir, changed, baseRef, o = {}) {
36964
37079
  let added = false;
36965
37080
  const cap = (tree, side) => {
36966
37081
  const sub = join107(base, side);
36967
- mkdirSync52(sub, { recursive: true });
37082
+ mkdirSync53(sub, { recursive: true });
36968
37083
  return deps.capture(tree, sub, changed, { env, budgetMs: bootMs, signal: o.signal, onServer: (p) => {
36969
37084
  pgids.push(p);
36970
37085
  } });
36971
37086
  };
36972
37087
  const rel = (side, s) => s.filter((x) => /\.png$/.test(x.path)).map((x) => ({ path: join107("before_after", side, x.path), sha256: x.sha256 }));
36973
37088
  try {
36974
- mkdirSync52(base, { recursive: true });
37089
+ mkdirSync53(base, { recursive: true });
36975
37090
  try {
36976
37091
  deps.worktreeAdd(repoDir, wt, baseRef);
36977
37092
  added = true;
@@ -37218,7 +37333,7 @@ var init_receipt_dsse = __esm(() => {
37218
37333
 
37219
37334
  // ../../loki-ts/src/util/receipt_bundle.ts
37220
37335
  import { createPublicKey as createPublicKey4 } from "crypto";
37221
- import { cpSync as cpSync4, copyFileSync as copyFileSync7, existsSync as existsSync73, mkdirSync as mkdirSync53, readdirSync as readdirSync40, readFileSync as readFileSync98, renameSync as renameSync21, rmSync as rmSync35, writeFileSync as writeFileSync57 } from "fs";
37336
+ import { cpSync as cpSync4, copyFileSync as copyFileSync7, existsSync as existsSync73, mkdirSync as mkdirSync54, readdirSync as readdirSync40, readFileSync as readFileSync98, renameSync as renameSync21, rmSync as rmSync35, writeFileSync as writeFileSync57 } from "fs";
37222
37337
  import { homedir as homedir11 } from "os";
37223
37338
  import { basename as basename32, dirname as dirname46, join as join108, normalize as normalize7 } from "path";
37224
37339
  function publicJwk(pub) {
@@ -37351,13 +37466,13 @@ exit 0
37351
37466
 
37352
37467
  // ../../loki-ts/src/util/outbox.ts
37353
37468
  import { createHash as createHash24 } from "crypto";
37354
- import { existsSync as existsSync74, mkdirSync as mkdirSync54, readFileSync as readFileSync99, renameSync as renameSync22 } from "fs";
37469
+ import { existsSync as existsSync74, mkdirSync as mkdirSync55, readFileSync as readFileSync99, renameSync as renameSync22 } from "fs";
37355
37470
  import { join as join109 } from "path";
37356
37471
  function idempotencyKey(kind, runId, discriminator) {
37357
37472
  return createHash24("sha256").update(`${kind}\x00${runId}\x00${discriminator}`).digest("hex").slice(0, 32);
37358
37473
  }
37359
37474
  function runOnce2(a) {
37360
- mkdirSync54(a.dir, { recursive: true });
37475
+ mkdirSync55(a.dir, { recursive: true });
37361
37476
  const file = join109(a.dir, `outbox-${a.key}.json`);
37362
37477
  let rec2 = null;
37363
37478
  if (existsSync74(file)) {
@@ -37502,7 +37617,7 @@ __export(exports_pr, {
37502
37617
  DEFAULT_PUSH_GITLAB_SH: () => DEFAULT_PUSH_GITLAB_SH
37503
37618
  });
37504
37619
  import { spawnSync as spawnSync12 } from "child_process";
37505
- import { mkdirSync as mkdirSync55, readFileSync as readFileSync100, writeFileSync as writeFileSync58 } from "fs";
37620
+ import { mkdirSync as mkdirSync56, readFileSync as readFileSync100, writeFileSync as writeFileSync58 } from "fs";
37506
37621
  import { join as join110 } from "path";
37507
37622
  function resolvePrAuthor(repoDir, environ = process.env) {
37508
37623
  let v = (environ.LOKI_PR_AUTHOR ?? "").trim() || null;
@@ -37720,7 +37835,7 @@ async function runPr(ctx, signal, opts = {}) {
37720
37835
  const base = stackBase(process.env);
37721
37836
  if (base === null)
37722
37837
  return { status: "failed", data: {}, reason: "LOKI_PR_BASE is not a valid branch name: refusing to push" };
37723
- mkdirSync55(ctx.runDir, { recursive: true });
37838
+ mkdirSync56(ctx.runDir, { recursive: true });
37724
37839
  const link = issueLink(ctx.runDir, verdict);
37725
37840
  const bodyFile = join110(ctx.runDir, "pr-body.md");
37726
37841
  const beforeAfter = await beforeAfterBlock(ctx.repoDir, ctx.runDir, (ctx.outputs().verify?.["changed_files"] ?? []).map(String), ctx.baseSha, { signal });
@@ -37883,7 +37998,7 @@ __export(exports_pr_lessons, {
37883
37998
  EXAMPLE_CAP: () => EXAMPLE_CAP,
37884
37999
  DEMOTE_AFTER: () => DEMOTE_AFTER
37885
38000
  });
37886
- import { appendFileSync as appendFileSync11, existsSync as existsSync75, mkdirSync as mkdirSync56, mkdtempSync as mkdtempSync17, readFileSync as readFileSync101, rmSync as rmSync36, writeFileSync as writeFileSync59 } from "fs";
38001
+ import { appendFileSync as appendFileSync11, existsSync as existsSync75, mkdirSync as mkdirSync57, mkdtempSync as mkdtempSync17, readFileSync as readFileSync101, rmSync as rmSync36, writeFileSync as writeFileSync59 } from "fs";
37887
38002
  import { homedir as homedir12, tmpdir as tmpdir21 } from "os";
37888
38003
  import { dirname as dirname47, join as join111 } from "path";
37889
38004
  import { createHash as createHash25 } from "crypto";
@@ -37901,7 +38016,7 @@ function loadLessons(repoDir) {
37901
38016
  }
37902
38017
  function save2(repoDir, lessons) {
37903
38018
  const p = lessonsPath(repoDir);
37904
- mkdirSync56(dirname47(p), { recursive: true });
38019
+ mkdirSync57(dirname47(p), { recursive: true });
37905
38020
  atomicWriteJson(p, { version: 2, lessons });
37906
38021
  }
37907
38022
  function loadPromoted() {
@@ -37913,7 +38028,7 @@ function loadPromoted() {
37913
38028
  }
37914
38029
  }
37915
38030
  function savePromoted(lessons) {
37916
- mkdirSync56(dirname47(promotedPath()), { recursive: true });
38031
+ mkdirSync57(dirname47(promotedPath()), { recursive: true });
37917
38032
  atomicWriteJson(promotedPath(), { version: 2, lessons });
37918
38033
  }
37919
38034
  function promoteLesson(repoDir, id) {
@@ -38247,7 +38362,7 @@ async function replayKnownVerdict(repoDir, task, o) {
38247
38362
  return null;
38248
38363
  const code = r.verdict === "SPEC_CONFLICT" ? 4 : 0;
38249
38364
  const dir = join111(repoDir, ".loki", "memory");
38250
- mkdirSync56(dir, { recursive: true });
38365
+ mkdirSync57(dir, { recursive: true });
38251
38366
  appendFileSync11(join111(dir, "replays.jsonl"), JSON.stringify({ v: 1, seq: 0, ts: new Date().toISOString(), run: r.runId, type: "run.replayed", stage: null, data: { prior_run_id: r.runId, receipt_sha256: r.receiptSha256, verdict: r.verdict, prior_runs: r.runs, ...key } }) + `
38252
38367
  `);
38253
38368
  if (o.json) {
@@ -39010,7 +39125,7 @@ __export(exports_contract, {
39010
39125
  MAX_CONTRACT_BYTES: () => MAX_CONTRACT_BYTES,
39011
39126
  CONSTRAINT_KINDS: () => CONSTRAINT_KINDS
39012
39127
  });
39013
- import { existsSync as existsSync76, lstatSync as lstatSync29, mkdirSync as mkdirSync57, readFileSync as readFileSync102, rmSync as rmSync37, writeFileSync as writeFileSync60 } from "fs";
39128
+ import { existsSync as existsSync76, lstatSync as lstatSync29, mkdirSync as mkdirSync58, readFileSync as readFileSync102, rmSync as rmSync37, writeFileSync as writeFileSync60 } from "fs";
39014
39129
  import { spawnSync as spawnSync14 } from "child_process";
39015
39130
  import { dirname as dirname48, join as join112 } from "path";
39016
39131
  import { createHash as createHash26 } from "crypto";
@@ -39087,7 +39202,7 @@ function freezeGroupContract(repoDir, groupId, units, contract) {
39087
39202
  return { ok: false, reason: `NOT PROVEN: group contract has ${a.orphans.length} criterion owned by no unit: ${a.orphans.map((o) => `${sanitizeCriterion(o.id)} ${sanitizeCriterion(o.text)}`).join("; ")}`, orphans: a.orphans };
39088
39203
  const gc = { group: groupId, units: a.units, orphans: [] };
39089
39204
  const path = groupContractPath(repoDir, groupId);
39090
- mkdirSync57(dirname48(path), { recursive: true });
39205
+ mkdirSync58(dirname48(path), { recursive: true });
39091
39206
  atomicWriteJson(path, gc);
39092
39207
  return { ok: true, path, contract: gc };
39093
39208
  }
@@ -39234,7 +39349,7 @@ function main(args) {
39234
39349
  }
39235
39350
  const contract = parseContract(readFileSync102(file, "utf8"), file);
39236
39351
  const out2 = contractPath(repoRoot(process.cwd()));
39237
- mkdirSync57(dirname48(out2), { recursive: true });
39352
+ mkdirSync58(dirname48(out2), { recursive: true });
39238
39353
  writeFileSync60(out2, JSON.stringify(contract, null, 2) + `
39239
39354
  `);
39240
39355
  process.stdout.write(renderContract(contract));
@@ -39450,7 +39565,7 @@ var init_contract = __esm(() => {
39450
39565
 
39451
39566
  // ../../loki-ts/src/features/speed/seal_group.ts
39452
39567
  import { createHash as createHash27 } from "crypto";
39453
- import { existsSync as existsSync77, mkdirSync as mkdirSync58, readdirSync as readdirSync41, readFileSync as readFileSync103, renameSync as renameSync23, statSync as statSync32, writeFileSync as writeFileSync61 } from "fs";
39568
+ import { existsSync as existsSync77, mkdirSync as mkdirSync59, readdirSync as readdirSync41, readFileSync as readFileSync103, renameSync as renameSync23, statSync as statSync32, writeFileSync as writeFileSync61 } from "fs";
39454
39569
  import { dirname as dirname49, join as join113 } from "path";
39455
39570
  function sealGroup(runDir, rh) {
39456
39571
  const manifestPath = join113(runDir, "group", "manifest.json");
@@ -39581,7 +39696,7 @@ function composeGroupReceipt(groupDir, rh, o) {
39581
39696
  const hash = rh(body), sig = signReceipt(gid, hash);
39582
39697
  const receipt = { ...body, receipt_sha256: hash, verification: { jwt: sig.jwt, kid: sig.kid } };
39583
39698
  const path = join113(groupDir, "receipt.json"), tmp = `${path}.${process.pid}.tmp`;
39584
- mkdirSync58(groupDir, { recursive: true });
39699
+ mkdirSync59(groupDir, { recursive: true });
39585
39700
  writeFileSync61(tmp, JSON.stringify(receipt, null, 2) + `
39586
39701
  `);
39587
39702
  renameSync23(tmp, path);
@@ -39900,7 +40015,7 @@ __export(exports_seal, {
39900
40015
  });
39901
40016
  import { createHash as createHash28 } from "crypto";
39902
40017
  import { execFileSync as execFileSync10 } from "child_process";
39903
- import { existsSync as existsSync79, readdirSync as readdirSync42, mkdirSync as mkdirSync59, readFileSync as readFileSync105, rmSync as rmSync38 } from "fs";
40018
+ import { existsSync as existsSync79, readdirSync as readdirSync42, mkdirSync as mkdirSync60, readFileSync as readFileSync105, rmSync as rmSync38 } from "fs";
39904
40019
  import { basename as basename34, isAbsolute as isAbsolute19, join as join115, relative as relative26 } from "path";
39905
40020
  function missingLintChecks(vraw, env = process.env) {
39906
40021
  if (/^(0|off|false|no)$/i.test((env["LOKI_E10_LINT_MISSING_DISCLOSE"] ?? "").trim()))
@@ -40399,7 +40514,9 @@ var init_seal = __esm(() => {
40399
40514
  const issueSt = byRule ? byRule.map((r, i) => ({ ...r, ...advisory && advisory[i].status === "unmet" && r.status === "met" ? { note: `reviewer note: ${advisory[i].reason ?? ""}`.slice(0, 300) } : {} })) : advisory, issueNotes = !issueSt || verdict3a !== "VERIFIED" ? [] : !byRule && lineCheck?.not_reviewed ? [`acceptance not reviewed: ${lineCheck.not_reviewed}`] : notAddressedNotes(issueSt);
40400
40515
  const allLinesMet = !!issueSt && (byRule ? true : !!lineCheck && !lineCheck.not_reviewed) && notAddressedNotes(issueSt).length === 0, unfinished = unfinishedNotes(o.implement);
40401
40516
  const proofNotes = proofRun && proofRun.exit !== 0 ? [`Loki's own re-run of the session's proof script did not pass (exit ${proofRun.exit === null ? "none" : proofRun.exit}, ${proofRun.failed} FAILED line(s))`] : [];
40402
- const openNotes = [...issueNotes, ...proofNotes, ...neverStopNotes(o.implement), ...allLinesMet ? [] : unfinished, ...proveNotes(ctx.provider, o, process.env, ctx.runDir), ...allLinesMet && proofRun?.exit === 0 ? [] : (xr?.notes ?? []).filter(isUnmetNote), ...openDecisionNotes(o), ...namedOpen.filter((s) => s.why === null).map(namedUnchangedNote)], verdict3 = openNotes.length > 0 && verdict3a === "VERIFIED" ? "PARTIAL" : verdict3a;
40517
+ const twoReaders = (xr?.notes ?? []).filter(isUnmetNote).filter((n3) => issueAsks.some((line2, i) => advisory?.[i]?.status === "unmet" && n3.toLowerCase().includes(line2.toLowerCase().slice(0, 60)))).map((n3) => `${n3} (the acceptance check also reads this line as not delivered: two readers agree, so the count does not carry it)`);
40518
+ const unusedNotes = issueAsks.length ? (await unusedNewFiles(ctx.repoDir, ctx.baseSha, head)).map(unusedNewFileNote) : [];
40519
+ const openNotes = [...issueNotes, ...proofNotes, ...neverStopNotes(o.implement), ...allLinesMet ? [] : unfinished, ...proveNotes(ctx.provider, o, process.env, ctx.runDir), ...allLinesMet && proofRun?.exit === 0 ? twoReaders : (xr?.notes ?? []).filter(isUnmetNote), ...openDecisionNotes(o), ...namedOpen.filter((s) => s.why === null).map(namedUnchangedNote)], verdict3 = openNotes.length > 0 && verdict3a === "VERIFIED" ? "PARTIAL" : verdict3a;
40403
40520
  const deepG = deepGaps(o.verify?.risk, vraw, Array.isArray(o.deep?.checks) ? o.deep.checks : [], modelReviewRan(xr)), notProven2 = new Set([...sealOnlyPass() ? [TIME_RAN_OUT_NOTE] : [], ...deepG.notProven, ...supply.notProven, ...grp.notProven, ...xr?.notes ?? [], ...reviewReceipt(ctx.provider, xr).notProven, ...openNotes]);
40404
40521
  const wp = verdict3 === "VERIFIED" && commitWallEnabled() ? wpAll : { files: [], notes: wpAll.notes }, wallKept = verdict3 === "VERIFIED" && !commitWallEnabled() ? wpAll.files : [];
40405
40522
  const wallPub0 = wp.files.length > 0 ? await publishWall(g(ctx), ctx.runId, ctx.repoDir, wp.files, wallDone) : false;
@@ -40418,6 +40535,8 @@ var init_seal = __esm(() => {
40418
40535
  if (sites.length)
40419
40536
  notProven2.add(`completed by rule, no model (LOKI_E10_SYSEDIT; a failing check now passes): ${sites.join(", ")}`);
40420
40537
  }
40538
+ for (const n3 of unusedNotes)
40539
+ notProven2.add(n3);
40421
40540
  if (allLinesMet)
40422
40541
  for (const n3 of unfinished)
40423
40542
  notProven2.add(`${n3} (outside the issue's acceptance lines, every one of which is met; disclosed, does not cap)`);
@@ -40677,7 +40796,7 @@ var init_seal = __esm(() => {
40677
40796
  hash = receiptSha256(body);
40678
40797
  }
40679
40798
  const receipt = { ...body, receipt_sha256: hash, verification: { jwt: sig.jwt, kid: sig.kid } };
40680
- mkdirSync59(ctx.runDir, { recursive: true });
40799
+ mkdirSync60(ctx.runDir, { recursive: true });
40681
40800
  const path = join115(ctx.runDir, "receipt.json");
40682
40801
  atomicWriteText(path, JSON.stringify(receipt, null, 2) + `
40683
40802
  `);
@@ -40690,7 +40809,7 @@ var init_seal = __esm(() => {
40690
40809
  `);
40691
40810
  }
40692
40811
  const signed = sig.jwt !== null;
40693
- const data = { ...wallPub ? { wall_published: { files: wp.files.map((f) => f.rel), cmds: [...new Set(wp.files.map((f) => f.cmd))] } } : {}, ...wallKept.length ? { wall_kept: { files: wallKept.map((f) => f.rel), sha256: wallKept.map((f) => createHash28("sha256").update(f.bytes).digest("hex")), cmds: [...new Set(wallKept.map((f) => f.cmd))], sealed_dir: sealedWallDir(ctx.runDir) } } : {}, receipt_path: path, receipt_sha256: hash, signed, kid: sig.kid, verdict, not_proven: receipt.not_proven, ...receipt.context ? { context: receipt.context } : {}, ...mp ? { mutation_line: mp.line } : {}, ...routeBlock ? { route_line: routePrLine(routeBlock) } : {} };
40812
+ const data = { ...wallPub ? { wall_published: { files: wp.files.map((f) => f.rel), cmds: [...new Set(wp.files.map((f) => f.cmd))] } } : {}, ...wallKept.length ? { wall_kept: { files: wallKept.map((f) => f.rel), sha256: wallKept.map((f) => createHash28("sha256").update(f.bytes).digest("hex")), cmds: [...new Set(wallKept.map((f) => f.cmd))], sealed_dir: sealedWallDir(ctx.runDir) } } : {}, receipt_path: path, receipt_sha256: hash, signed, kid: sig.kid, verdict, not_proven: receipt.not_proven, ...issueSt ? { issue_acceptance: issueSt.map((s, i) => ({ line: s.line, status: s.status, checks: proofRun?.lines[String(i + 1)]?.proved ?? 0, ..."reason" in s && s.reason ? { reason: s.reason } : {} })), issue_acceptance_source: listed.length ? "issue" : "plan" } : {}, ...receipt.context ? { context: receipt.context } : {}, ...mp ? { mutation_line: mp.line } : {}, ...routeBlock ? { route_line: routePrLine(routeBlock) } : {} };
40694
40813
  try {
40695
40814
  recordRunVerdict(ctx.repoDir, ctx.runId, verdict);
40696
40815
  } catch {}
@@ -40708,7 +40827,7 @@ var init_seal = __esm(() => {
40708
40827
 
40709
40828
  // ../../loki-ts/src/util/seal_drift.ts
40710
40829
  import { createHash as createHash29, createPublicKey as createPublicKey5, sign as sign3, verify as verify4 } from "crypto";
40711
- import { existsSync as existsSync80, lstatSync as lstatSync30, readFileSync as readFileSync106, realpathSync as realpathSync37 } from "fs";
40830
+ import { existsSync as existsSync80, lstatSync as lstatSync30, readFileSync as readFileSync106, realpathSync as realpathSync38 } from "fs";
40712
40831
  import { basename as basename35, dirname as dirname51, join as join116, relative as relative27 } from "path";
40713
40832
  function tornTail(raw2) {
40714
40833
  if (raw2 === "" || raw2.endsWith(`
@@ -40837,7 +40956,7 @@ function onlyWallPublish(repo, r, sealedHead, head) {
40837
40956
  try {
40838
40957
  const real4 = (x) => {
40839
40958
  try {
40840
- return realpathSync37(x);
40959
+ return realpathSync38(x);
40841
40960
  } catch {
40842
40961
  return x;
40843
40962
  }
@@ -40879,7 +40998,7 @@ function claimsWallPublish(repo, r, sealedHead, head) {
40879
40998
  function sealDrift(given, r, env = process.env) {
40880
40999
  let receiptPath = given;
40881
41000
  try {
40882
- receiptPath = join116(realpathSync37(dirname51(given)), basename35(given));
41001
+ receiptPath = join116(realpathSync38(dirname51(given)), basename35(given));
40883
41002
  } catch {}
40884
41003
  const fab = fabricatedPass(receiptPath, r);
40885
41004
  if (fab)
@@ -41737,6 +41856,288 @@ var init_liveline = __esm(() => {
41737
41856
  LIVE_LABELS = { intake: "reading the task", plan: "planning", wall: "writing acceptance checks", implement: "implementing", verify: "verifying", fix: "fixing failures", commit: "committing", seal: "sealing the receipt", pr: "opening the PR", deep: "deep review" };
41738
41857
  });
41739
41858
 
41859
+ // ../../loki-ts/src/e10ext/console.ts
41860
+ class LiveConsole {
41861
+ o;
41862
+ t0;
41863
+ drawn = 0;
41864
+ closed = false;
41865
+ details = false;
41866
+ rawOn = false;
41867
+ title = "Loki";
41868
+ model = "";
41869
+ url = null;
41870
+ spent = null;
41871
+ stage = new Map;
41872
+ lines = [];
41873
+ lineSource = "the issue's own lines";
41874
+ seen = [];
41875
+ recent = [];
41876
+ diff = "";
41877
+ proof = "";
41878
+ tests = { pass: 0, fail: 0 };
41879
+ outcome = "";
41880
+ out;
41881
+ unhook = [];
41882
+ midLine = false;
41883
+ constructor(o) {
41884
+ this.o = o;
41885
+ this.t0 = (o.now ?? Date.now)();
41886
+ this.out = o.write ?? ((x) => {
41887
+ process.stdout.write(x);
41888
+ });
41889
+ if (!o.write && o.hookStd !== false)
41890
+ this.hook();
41891
+ this.keys();
41892
+ }
41893
+ hook() {
41894
+ const raw2 = process.stdout.write.bind(process.stdout);
41895
+ this.out = (x) => {
41896
+ raw2(x);
41897
+ };
41898
+ for (const st of [process.stdout, process.stderr]) {
41899
+ const orig = st.write.bind(st);
41900
+ this.unhook.push(() => {
41901
+ st.write = orig;
41902
+ });
41903
+ st.write = (chunk, ...rest) => {
41904
+ if (this.closed)
41905
+ return orig(chunk, ...rest);
41906
+ if (this.drawn > 0) {
41907
+ raw2(`\x1B[${this.drawn}A\r\x1B[J`);
41908
+ this.drawn = 0;
41909
+ }
41910
+ const r = orig(chunk, ...rest), text4 = typeof chunk === "string" ? chunk : chunk instanceof Uint8Array ? Buffer.from(chunk).toString("utf8") : "";
41911
+ if (text4)
41912
+ this.midLine = !text4.endsWith(`
41913
+ `);
41914
+ if (!this.redrawQueued) {
41915
+ this.redrawQueued = true;
41916
+ setImmediate(() => {
41917
+ this.redrawQueued = false;
41918
+ if (!this.closed)
41919
+ this.render();
41920
+ });
41921
+ }
41922
+ return r;
41923
+ };
41924
+ }
41925
+ }
41926
+ redrawQueued = false;
41927
+ now() {
41928
+ return (this.o.now ?? Date.now)();
41929
+ }
41930
+ get color() {
41931
+ return !(this.o.env ?? process.env)["NO_COLOR"];
41932
+ }
41933
+ c(code, s) {
41934
+ return this.color ? `\x1B[${code}m${s}\x1B[0m` : s;
41935
+ }
41936
+ safe(s, w) {
41937
+ const t = redactSecrets(String(s).replace(/[\t\r\n]+/g, " ").replace(UNSAFE_TERMINAL_CHARS_RE, " "));
41938
+ return t.length > w ? `${t.slice(0, Math.max(0, w - 3))}...` : t;
41939
+ }
41940
+ note(s) {
41941
+ this.recent.push(s);
41942
+ if (this.recent.length > 40)
41943
+ this.recent.shift();
41944
+ }
41945
+ setUrl(u) {
41946
+ if (u) {
41947
+ this.url = u;
41948
+ this.render();
41949
+ }
41950
+ }
41951
+ keys() {
41952
+ const stdin = this.o.stdin === undefined ? process.stdin : this.o.stdin;
41953
+ if (!stdin || !stdin.isTTY || typeof stdin.setRawMode !== "function")
41954
+ return;
41955
+ try {
41956
+ stdin.setRawMode(true);
41957
+ stdin.resume();
41958
+ this.rawOn = true;
41959
+ const restore = () => {
41960
+ if (this.rawOn) {
41961
+ try {
41962
+ stdin.setRawMode(false);
41963
+ stdin.pause();
41964
+ } catch {}
41965
+ this.rawOn = false;
41966
+ }
41967
+ };
41968
+ process.once("exit", restore);
41969
+ this.restore = restore;
41970
+ stdin.on("data", (b) => {
41971
+ const k = b.toString("utf8");
41972
+ if (k === "d" || k === "D") {
41973
+ this.details = !this.details;
41974
+ this.render();
41975
+ } else if (k === "\x03" || k === "q" || k === "Q") {
41976
+ restore();
41977
+ (this.o.onCancel ?? (() => {
41978
+ process.kill(process.pid, "SIGINT");
41979
+ }))();
41980
+ }
41981
+ });
41982
+ } catch {
41983
+ this.rawOn = false;
41984
+ }
41985
+ }
41986
+ restore = () => {};
41987
+ onEvent(e) {
41988
+ if (this.closed)
41989
+ return;
41990
+ const d = e.data ?? {};
41991
+ if (e.type === "run.started" || e.type === "run.resumed") {
41992
+ const ref = d["issue_ref"] ?? d["task_title"];
41993
+ if (typeof ref === "string" && ref)
41994
+ this.title = ref;
41995
+ if (typeof d["model"] === "string")
41996
+ this.model = String(d["model"]);
41997
+ }
41998
+ const cp = d["control_plane_url"];
41999
+ if (typeof cp === "string" && cp)
42000
+ this.url = cp;
42001
+ this.seen.push(e);
42002
+ if (e.type === "cost") {
42003
+ try {
42004
+ this.spent = (this.o.spend ?? ((ev) => spendSoFar(ev, this.o.repoDir ? `${this.o.repoDir}/.loki` : undefined)))(this.seen).replace(/^\((.*)\)$/, "$1");
42005
+ } catch {}
42006
+ }
42007
+ if (e.stage && e.type === "stage.started") {
42008
+ this.stage.set(e.stage, { state: "running", at: this.now() });
42009
+ this.note(`${e.stage} started`);
42010
+ } else if (e.stage && /^stage\.(completed|failed|skipped)$/.test(e.type)) {
42011
+ const st = e.type === "stage.completed" ? "done" : e.type === "stage.failed" ? "failed" : "skipped", prev = this.stage.get(e.stage);
42012
+ this.stage.set(e.stage, { state: st, at: prev?.at ?? this.now(), s: typeof d["duration_s"] === "number" ? d["duration_s"] : prev ? (this.now() - prev.at) / 1000 : undefined });
42013
+ this.note(`${e.stage} ${st}${typeof d["reason"] === "string" ? `: ${d["reason"]}` : ""}`);
42014
+ if (e.stage === "intake" && Array.isArray(d["issue_acceptance"]) && d["issue_acceptance"].length)
42015
+ this.lines = d["issue_acceptance"].map((t) => ({ text: String(t), state: "waiting", checks: 0 }));
42016
+ if (e.stage === "seal" && Array.isArray(d["issue_acceptance"]))
42017
+ this.setLines(d["issue_acceptance"], d["issue_acceptance_source"]);
42018
+ if (e.stage === "seal" && typeof d["verdict"] === "string")
42019
+ this.outcome = String(d["verdict"]);
42020
+ }
42021
+ if (e.type === "heartbeat" && d["diff"] && typeof d["diff"] === "object") {
42022
+ const x = d["diff"];
42023
+ this.diff = `${Number(x["files"] ?? 0)} files changed, +${Number(x["insertions"] ?? 0)} -${Number(x["deletions"] ?? 0)}`;
42024
+ }
42025
+ if (e.type === "test.result") {
42026
+ if (d["result"] === "pass")
42027
+ this.tests.pass++;
42028
+ else if (d["result"] === "fail")
42029
+ this.tests.fail++;
42030
+ }
42031
+ if (e.type === "proof.rerun") {
42032
+ this.proof = `Loki ran the proof itself, round ${Number(d["round"] ?? 1)}: ${d["exit"] === 0 ? "passed" : "did not pass"}, ${Number(d["proved"] ?? 0)} passing and ${Number(d["failed"] ?? 0)} failing checks in ${Number(d["seconds"] ?? 0)}s`;
42033
+ this.note(this.proof);
42034
+ if (Array.isArray(d["statuses"]))
42035
+ this.setLines(d["statuses"], d["source"]);
42036
+ }
42037
+ if (e.type === "acceptance.round")
42038
+ this.note(`acceptance check, round ${Number(d["round"] ?? 1)}: ${Number(d["met"] ?? 0)} met, ${Number(d["unmet"] ?? 0)} handed back to the session`);
42039
+ this.render();
42040
+ }
42041
+ setLines(rows, source) {
42042
+ if (!rows.length)
42043
+ return;
42044
+ this.lines = rows.map((r, i) => ({ text: String(r["line"] ?? this.lines[i]?.text ?? `line ${i + 1}`), state: r["status"] === "met" ? "met" : r["status"] === "unmet" ? "unmet" : "waiting", checks: Number(r["checks"] ?? 0), ...typeof r["reason"] === "string" ? { why: r["reason"] } : {} }));
42045
+ if (source === "plan")
42046
+ this.lineSource = "written by Loki from the issue";
42047
+ }
42048
+ frame(final = false) {
42049
+ const w = Math.max(50, terminalWidth({ columns: this.o.columns }) - 1), out2 = [];
42050
+ const right = [this.model, formatDuration((this.now() - this.t0) / 1000), this.spent ?? ""].filter(Boolean).join(" ");
42051
+ const left = this.safe(`LOKI ${this.title}`, Math.max(10, w - right.length - 2));
42052
+ out2.push(`${this.c("1", left)}${" ".repeat(Math.max(1, w - left.length - right.length))}${this.c("2", right)}`);
42053
+ out2.push(this.c("2", "-".repeat(w)));
42054
+ const tag = (s) => s === "done" ? this.c("32", "done") : s === "running" ? this.c("33", "now ") : s === "failed" ? this.c("31", "FAIL") : s === "skipped" ? this.c("2", "skip") : this.c("2", " ");
42055
+ const cells = STAGES.filter(([k]) => k !== "fix" || this.stage.has("fix")).map(([k, label3]) => {
42056
+ const st = this.stage.get(k);
42057
+ const s = st?.state ?? "waiting";
42058
+ const t = s === "running" && st ? ` ${formatDuration((this.now() - st.at) / 1000)}` : s === "done" && st?.s !== undefined ? ` ${formatDuration(st.s)}` : "";
42059
+ return { plain: `[${s === "done" ? "done" : s === "running" ? "now " : s === "failed" ? "FAIL" : s === "skipped" ? "skip" : " "}] ${label3}${t}`, shown: `[${tag(s)}] ${label3}${this.c("2", t)}` };
42060
+ });
42061
+ let row = "", rowPlain = "";
42062
+ for (const c of cells) {
42063
+ if (rowPlain.length + c.plain.length + 3 > w && rowPlain) {
42064
+ out2.push(row);
42065
+ row = "";
42066
+ rowPlain = "";
42067
+ }
42068
+ row += (rowPlain ? " " : "") + c.shown;
42069
+ rowPlain += (rowPlain ? " " : "") + c.plain;
42070
+ }
42071
+ if (rowPlain)
42072
+ out2.push(row);
42073
+ out2.push("");
42074
+ if (this.lines.length) {
42075
+ const met = this.lines.filter((l) => l.state === "met").length;
42076
+ out2.push(`${this.c("1", "Acceptance")} ${this.c("2", `(${this.lineSource})`)} ${met} of ${this.lines.length} met`);
42077
+ this.lines.forEach((l, i) => {
42078
+ const mark = l.state === "met" ? this.c("32", "[ ok ]") : l.state === "unmet" ? this.c("31", "[ no ]") : this.c("2", "[ .. ]");
42079
+ const tail2 = l.state === "met" && l.checks ? ` ${l.checks} check${l.checks === 1 ? "" : "s"}` : "";
42080
+ out2.push(` ${mark} ${String(i + 1).padStart(2)} ${this.safe(l.text, w - 16 - tail2.length)}${this.c("2", tail2)}`);
42081
+ if (l.state === "unmet" && l.why && (final || this.details))
42082
+ out2.push(this.c("2", ` ${this.safe(l.why, w - 14)}`));
42083
+ });
42084
+ out2.push("");
42085
+ }
42086
+ const cur = [...this.stage.entries()].reverse().find(([, v]) => v.state === "running")?.[0];
42087
+ if (!final && cur)
42088
+ out2.push(`${this.c("1", "Now:")} ${this.safe(`${NOW[cur] ?? cur}${cur === "implement" && this.diff ? ` (${this.diff})` : ""}${cur === "verify" && this.tests.pass + this.tests.fail ? ` (${this.tests.pass} passed, ${this.tests.fail} failed so far)` : ""}`, w - 6)}`);
42089
+ if (this.proof)
42090
+ out2.push(this.safe(this.proof, w));
42091
+ if (this.details && !final) {
42092
+ out2.push(this.c("2", "Recent:"));
42093
+ for (const r of this.recent.slice(-8))
42094
+ out2.push(this.c("2", ` ${this.safe(r, w - 2)}`));
42095
+ }
42096
+ if (!final)
42097
+ out2.push(this.c("2", this.safe(`d details q or Ctrl-C stop (loki start resumes it)${this.url ? ` ${this.url}` : ""}`, w)));
42098
+ return out2;
42099
+ }
42100
+ tick() {
42101
+ if (!this.closed)
42102
+ this.render();
42103
+ }
42104
+ render(final = false) {
42105
+ const f = this.frame(final), up = this.drawn > 0 ? `\x1B[${this.drawn}A` : "";
42106
+ let s = `\x1B[?25l${this.drawn === 0 && this.midLine ? `
42107
+ ` : ""}${up}`;
42108
+ this.midLine = false;
42109
+ for (const l of f)
42110
+ s += `\r\x1B[2K${l}
42111
+ `;
42112
+ for (let i = f.length;i < this.drawn; i++)
42113
+ s += `\r\x1B[2K
42114
+ `;
42115
+ if (this.drawn > f.length)
42116
+ s += `\x1B[${this.drawn - f.length}A`;
42117
+ this.out(s);
42118
+ this.drawn = f.length;
42119
+ }
42120
+ clear() {
42121
+ if (this.closed)
42122
+ return;
42123
+ this.render(true);
42124
+ this.closed = true;
42125
+ this.out("\x1B[?25h");
42126
+ for (const u of this.unhook)
42127
+ u();
42128
+ this.unhook = [];
42129
+ this.restore();
42130
+ }
42131
+ }
42132
+ var STAGES, NOW, consoleOn = (env = process.env, tty = !!process.stdout.isTTY) => tty && !/^(0|off|false|no)$/i.test((env["LOKI_CONSOLE"] ?? "").trim()) && env["TERM"] !== "dumb";
42133
+ var init_console = __esm(() => {
42134
+ init_output();
42135
+ init_term_width();
42136
+ init_redact();
42137
+ STAGES = [["intake", "read"], ["plan", "plan"], ["implement", "build"], ["verify", "verify"], ["fix", "fix"], ["commit", "commit"], ["seal", "label"], ["pr", "pull request"]];
42138
+ NOW = { intake: "reading the task", plan: "planning the change", implement: "the session is building and running the product", verify: "running the repository's tests", fix: "fixing what the tests found", commit: "committing", seal: "checking every line and writing the receipt", pr: "opening the pull request" };
42139
+ });
42140
+
41740
42141
  // ../../loki-ts/src/cli/registry.ts
41741
42142
  var exports_registry = {};
41742
42143
  __export(exports_registry, {
@@ -42706,7 +43107,7 @@ __export(exports_doctor_fix, {
42706
43107
  runDoctorFix: () => runDoctorFix,
42707
43108
  applyDoctorFixes: () => applyDoctorFixes
42708
43109
  });
42709
- import { copyFileSync as copyFileSync8, existsSync as existsSync82, mkdirSync as mkdirSync60, readFileSync as readFileSync109, readSync as readSync13, writeFileSync as writeFileSync64 } from "fs";
43110
+ import { copyFileSync as copyFileSync8, existsSync as existsSync82, mkdirSync as mkdirSync61, readFileSync as readFileSync109, readSync as readSync13, writeFileSync as writeFileSync64 } from "fs";
42710
43111
  import { homedir as homedir13 } from "os";
42711
43112
  import { join as join119 } from "path";
42712
43113
  import { spawnSync as spawnSync15 } from "child_process";
@@ -42753,7 +43154,7 @@ function applyDoctorFixes(cwd = process.cwd(), home = homedir13(), deps = {}) {
42753
43154
  for (const dir of [join119(home, ".loki"), join119(home, ".config", "loki-mode"), join119(cwd, ".loki")]) {
42754
43155
  if (!existsSync82(dir)) {
42755
43156
  try {
42756
- mkdirSync60(dir, { recursive: true });
43157
+ mkdirSync61(dir, { recursive: true });
42757
43158
  applied.push(`created ${dir}`);
42758
43159
  } catch (e) {
42759
43160
  manual.push(`mkdir -p ${dir} (${e.message})`);
@@ -42765,7 +43166,7 @@ function applyDoctorFixes(cwd = process.cwd(), home = homedir13(), deps = {}) {
42765
43166
  const cfgFile = join119(cfgDir, "settings.json");
42766
43167
  if (!existsSync82(cfgFile)) {
42767
43168
  try {
42768
- mkdirSync60(cfgDir, { recursive: true });
43169
+ mkdirSync61(cfgDir, { recursive: true });
42769
43170
  writeFileSync64(cfgFile, JSON.stringify({ provider: seedProvider }, null, 2) + `
42770
43171
  `);
42771
43172
  applied.push(`wrote default config ${cfgFile} (provider=${seedProvider})`);
@@ -42931,7 +43332,7 @@ __export(exports_doctor, {
42931
43332
  CLAUDE_LOGIN_TTL_MS: () => CLAUDE_LOGIN_TTL_MS,
42932
43333
  AUTH_PROVIDERS: () => AUTH_PROVIDERS
42933
43334
  });
42934
- import { appendFileSync as appendFileSync12, writeFileSync as writeFileSync65, mkdirSync as mkdirSync61, accessSync as accessSync3, constants as fsConstants3, existsSync as existsSync83, lstatSync as lstatSync31, readdirSync as readdirSync44, readFileSync as readFileSync110, readlinkSync as readlinkSync6, realpathSync as realpathSync38, statSync as statSync36, statfsSync } from "fs";
43335
+ import { appendFileSync as appendFileSync12, writeFileSync as writeFileSync65, mkdirSync as mkdirSync62, accessSync as accessSync3, constants as fsConstants3, existsSync as existsSync83, lstatSync as lstatSync31, readdirSync as readdirSync44, readFileSync as readFileSync110, readlinkSync as readlinkSync6, realpathSync as realpathSync39, statSync as statSync36, statfsSync } from "fs";
42935
43336
  import { spawnSync as spawnSync16 } from "child_process";
42936
43337
  import { homedir as homedir14, tmpdir as tmpdir22 } from "os";
42937
43338
  import { basename as basename36, join as join120, resolve as resolve28 } from "path";
@@ -43733,7 +44134,7 @@ function claudeLoginProbeCached(cli, env = process.env, now2 = Date.now()) {
43733
44134
  li = claudeAuthStatusLoggedIn(cli, env);
43734
44135
  if (li === "yes") {
43735
44136
  try {
43736
- mkdirSync61(join120(file, ".."), { recursive: true });
44137
+ mkdirSync62(join120(file, ".."), { recursive: true });
43737
44138
  writeFileSync65(file, JSON.stringify({ cli, at: now2 }));
43738
44139
  } catch {}
43739
44140
  }
@@ -43751,7 +44152,7 @@ async function ghAuthProbeCached(env, probe, now2 = Date.now()) {
43751
44152
  const ok = await probe();
43752
44153
  if (ok) {
43753
44154
  try {
43754
- mkdirSync61(join120(file, ".."), { recursive: true });
44155
+ mkdirSync62(join120(file, ".."), { recursive: true });
43755
44156
  writeFileSync65(file, JSON.stringify({ gh, at: now2 }));
43756
44157
  } catch {}
43757
44158
  }
@@ -44403,7 +44804,7 @@ async function runText(deps = {}) {
44403
44804
  {
44404
44805
  const resolveReal = (p) => {
44405
44806
  try {
44406
- return realpathSync38(p);
44807
+ return realpathSync39(p);
44407
44808
  } catch {
44408
44809
  return p;
44409
44810
  }
@@ -44634,7 +45035,7 @@ async function runDoctor2(argv, deps = {}) {
44634
45035
  }
44635
45036
  try {
44636
45037
  const dir = join120(process.cwd(), ".loki", "state");
44637
- mkdirSync61(dir, { recursive: true });
45038
+ mkdirSync62(dir, { recursive: true });
44638
45039
  const checks = rep.paths.flatMap((x) => x.items).map((i) => ({ id: i.id, level: i.level, status: i.status }));
44639
45040
  appendFileSync12(join120(dir, "readiness.jsonl"), JSON.stringify({ ts: new Date().toISOString(), checks, pass: ready, score: withReadiness?.readiness?.score ?? null, roundTrip: rt }) + `
44640
45041
  `);
@@ -44812,7 +45213,7 @@ __export(exports_preflight, {
44812
45213
  PreflightError: () => PreflightError,
44813
45214
  CLI_ENV_VAR: () => CLI_ENV_VAR
44814
45215
  });
44815
- import { accessSync as accessSync4, constants as fsc2, mkdirSync as mkdirSync62, statfsSync as statfsSync2, writeFileSync as writeFileSync66 } from "fs";
45216
+ import { accessSync as accessSync4, constants as fsc2, mkdirSync as mkdirSync63, statfsSync as statfsSync2, writeFileSync as writeFileSync66 } from "fs";
44816
45217
  import { join as join122 } from "path";
44817
45218
  async function sh3(argv, opts) {
44818
45219
  try {
@@ -44903,7 +45304,7 @@ async function checkPreflight(o) {
44903
45304
  }
44904
45305
  if (o.runDir && hits.every(([b]) => b === "not_logged_in")) {
44905
45306
  try {
44906
- mkdirSync62(o.runDir, { recursive: true });
45307
+ mkdirSync63(o.runDir, { recursive: true });
44907
45308
  writeFileSync66(join122(o.runDir, "preflight.json"), JSON.stringify({ provider: o.provider, auth_path, probe }) + `
44908
45309
  `);
44909
45310
  } catch {}
@@ -45067,7 +45468,7 @@ var init_one_line_goal = __esm(() => {
45067
45468
  });
45068
45469
 
45069
45470
  // ../../loki-ts/src/util/group_integrate.ts
45070
- import { existsSync as existsSync84, mkdirSync as mkdirSync63, readFileSync as readFileSync111, rmSync as rmSync39, writeFileSync as writeFileSync67 } from "fs";
45471
+ import { existsSync as existsSync84, mkdirSync as mkdirSync64, readFileSync as readFileSync111, rmSync as rmSync39, writeFileSync as writeFileSync67 } from "fs";
45071
45472
  import { basename as basename37, dirname as dirname53, join as join123, normalize as normalize8 } from "path";
45072
45473
  function integrationOrder(dag) {
45073
45474
  const ids = dag.units.map((u) => u.id), indeg = new Map(ids.map((i) => [i, 0]));
@@ -45108,7 +45509,7 @@ async function rerunWalls(runner, repoDir, merged, walls) {
45108
45509
  if (bad = wallPathProblem(repoDir, rel) ?? (r2 ? undefined : `no runner for ${f.rel}`))
45109
45510
  break;
45110
45511
  written.push({ abs, prev: existsSync84(abs) ? readFileSync111(abs) : null });
45111
- mkdirSync63(dirname53(abs), { recursive: true });
45512
+ mkdirSync64(dirname53(abs), { recursive: true });
45112
45513
  writeFileSync67(abs, f.bytes);
45113
45514
  tests.push({ runner: r2, path: rel });
45114
45515
  }
@@ -45566,7 +45967,7 @@ __export(exports_run_group, {
45566
45967
  groupCostLine: () => groupCostLine,
45567
45968
  NOT_PROVEN: () => NOT_PROVEN
45568
45969
  });
45569
- import { cpSync as cpSync5, existsSync as existsSync85, mkdirSync as mkdirSync64, readdirSync as readdirSync46, readFileSync as readFileSync112, rmSync as rmSync40, statSync as statSync38 } from "fs";
45970
+ import { cpSync as cpSync5, existsSync as existsSync85, mkdirSync as mkdirSync65, readdirSync as readdirSync46, readFileSync as readFileSync112, rmSync as rmSync40, statSync as statSync38 } from "fs";
45570
45971
  import { createHash as createHash30 } from "crypto";
45571
45972
  import { spawn as spawn11 } from "child_process";
45572
45973
  import { join as join124, resolve as resolve29 } from "path";
@@ -45619,7 +46020,7 @@ function writeGroupCostRecord(repoDir, name, costs, provider) {
45619
46020
  }
45620
46021
  if (recs.length === 0)
45621
46022
  return;
45622
- mkdirSync64(dir, { recursive: true });
46023
+ mkdirSync65(dir, { recursive: true });
45623
46024
  recs.forEach((r, k) => atomicWriteJson(join124(dir, `iteration-group-${name}-${String(k).padStart(3, "0")}.json`), r));
45624
46025
  } catch {}
45625
46026
  }
@@ -45838,7 +46239,7 @@ async function runGroupCore(launcher, dag, ctx) {
45838
46239
  for (const cu of Array.isArray(gc?.["units"]) ? gc["units"] : [])
45839
46240
  accOf.set(cu.id, cu.criteria.map((c) => c.text));
45840
46241
  const specDir = join124(groupDir, "unit_specs");
45841
- mkdirSync64(specDir, { recursive: true });
46242
+ mkdirSync65(specDir, { recursive: true });
45842
46243
  for (const u of units) {
45843
46244
  const spec = join124(specDir, `${u.id}.json`);
45844
46245
  const isFix = !!u.fixKind;
@@ -46076,7 +46477,7 @@ __export(exports_route, {
46076
46477
  MAX_SPEC_BYTES: () => MAX_SPEC_BYTES2,
46077
46478
  MAX_SEQ_TASK_BYTES: () => MAX_SEQ_TASK_BYTES
46078
46479
  });
46079
- import { closeSync as closeSync17, constants as constants4, fstatSync as fstatSync9, openSync as openSync17, readFileSync as readFileSync113, realpathSync as realpathSync39 } from "fs";
46480
+ import { closeSync as closeSync17, constants as constants4, fstatSync as fstatSync9, openSync as openSync17, readFileSync as readFileSync113, realpathSync as realpathSync40 } from "fs";
46080
46481
  import { isAbsolute as isAbsolute20, relative as relative28, resolve as resolve30 } from "path";
46081
46482
  function providerSlots(env, provider) {
46082
46483
  provider = (provider || env.LOKI_PROVIDER || "claude").toLowerCase();
@@ -46088,11 +46489,11 @@ function readSpec(task, repoDir, cwd) {
46088
46489
  const p = isAbsolute20(task) ? task : resolve30(cwd, task);
46089
46490
  let real4;
46090
46491
  try {
46091
- real4 = realpathSync39(p);
46492
+ real4 = realpathSync40(p);
46092
46493
  } catch {
46093
46494
  return { kind: "missing", path: p };
46094
46495
  }
46095
- const rel = relative28(realpathSync39(repoDir), real4);
46496
+ const rel = relative28(realpathSync40(repoDir), real4);
46096
46497
  if (rel === ".." || rel.startsWith("../") || isAbsolute20(rel))
46097
46498
  return { kind: "reject", reason: `spec path escapes the repo: ${task}` };
46098
46499
  let fd = -1;
@@ -46227,7 +46628,7 @@ var init_route = __esm(() => {
46227
46628
  });
46228
46629
 
46229
46630
  // ../../loki-ts/src/contrib/forecast.ts
46230
- import { appendFileSync as appendFileSync13, existsSync as existsSync86, mkdirSync as mkdirSync65, readFileSync as readFileSync114 } from "fs";
46631
+ import { appendFileSync as appendFileSync13, existsSync as existsSync86, mkdirSync as mkdirSync66, readFileSync as readFileSync114 } from "fs";
46231
46632
  import { join as join125 } from "path";
46232
46633
  function readWindowDeltas(lokiDir2) {
46233
46634
  const p = historyPath2(lokiDir2);
@@ -46258,7 +46659,7 @@ function recordWindowDelta(lokiDir2, before, after) {
46258
46659
  if (session < 0 || week < 0 || session === 0 && week === 0)
46259
46660
  return false;
46260
46661
  try {
46261
- mkdirSync65(lokiDir2, { recursive: true });
46662
+ mkdirSync66(lokiDir2, { recursive: true });
46262
46663
  appendFileSync13(historyPath2(lokiDir2), JSON.stringify({ session, week }) + `
46263
46664
  `);
46264
46665
  return true;
@@ -46305,7 +46706,7 @@ var init_forecast = __esm(() => {
46305
46706
  });
46306
46707
 
46307
46708
  // ../../loki-ts/src/commands/queue.ts
46308
- import { existsSync as existsSync87, mkdirSync as mkdirSync66, readFileSync as readFileSync115, readdirSync as readdirSync47, renameSync as renameSync24, statSync as statSync39, writeFileSync as writeFileSync68 } from "fs";
46709
+ import { existsSync as existsSync87, mkdirSync as mkdirSync67, readFileSync as readFileSync115, readdirSync as readdirSync47, renameSync as renameSync24, statSync as statSync39, writeFileSync as writeFileSync68 } from "fs";
46309
46710
  import { join as join126, resolve as resolve31 } from "path";
46310
46711
  function normalizeRef(raw2) {
46311
46712
  const m = URL_RE.exec(raw2);
@@ -46343,7 +46744,7 @@ function quarantineCorruptQueue(lokiDir2, now2, warn) {
46343
46744
  } catch {}
46344
46745
  }
46345
46746
  function writeQueue(lokiDir2, items2) {
46346
- mkdirSync66(lokiDir2, { recursive: true });
46747
+ mkdirSync67(lokiDir2, { recursive: true });
46347
46748
  const p = queuePath(lokiDir2);
46348
46749
  atomicWriteText(p, JSON.stringify({ version: 1, items: items2 }, null, 2) + `
46349
46750
  `);
@@ -46531,7 +46932,7 @@ ${QUEUE_USAGE}`);
46531
46932
  const finished = d.now();
46532
46933
  const text4 = renderDigest(started, finished, rows, skipped2, stopReason2);
46533
46934
  try {
46534
- mkdirSync66(d.lokiDir, { recursive: true });
46935
+ mkdirSync67(d.lokiDir, { recursive: true });
46535
46936
  const stamp2 = finished.toISOString().replace(/[:.]/g, "-");
46536
46937
  writeFileSync68(join126(d.lokiDir, `queue-digest-${stamp2}.txt`), text4);
46537
46938
  writeFileSync68(join126(d.lokiDir, "queue-digest-latest.txt"), text4);
@@ -46605,7 +47006,7 @@ function makeDefaultRunner(lokiDir2) {
46605
47006
  const output = so + se;
46606
47007
  try {
46607
47008
  const logDir = join126(lokiDir2, "queue-logs");
46608
- mkdirSync66(logDir, { recursive: true });
47009
+ mkdirSync67(logDir, { recursive: true });
46609
47010
  writeFileSync68(join126(logDir, `${(opts.logName ?? ref).replace(/[^A-Za-z0-9_.-]/g, "_").slice(0, 120)}.log`), output);
46610
47011
  } catch {}
46611
47012
  const proof = newestRecord(runLoki, since);
@@ -46839,12 +47240,12 @@ function decomposeReply(outPath, logPath, summary) {
46839
47240
  }
46840
47241
  function makeSessionDecompose(repoDir, lokiDir2, provider, onCost) {
46841
47242
  return async (slug, issue, triageReason, note) => {
46842
- const { mkdirSync: mkdirSync67, writeFileSync: writeFileSync69 } = await import("fs");
47243
+ const { mkdirSync: mkdirSync68, writeFileSync: writeFileSync69 } = await import("fs");
46843
47244
  const { join: join127 } = await import("path");
46844
47245
  const { createSessionRunner: createSessionRunner2 } = await Promise.resolve().then(() => (init_session(), exports_session));
46845
47246
  const { envOverride: envOverride2 } = await Promise.resolve().then(() => (init_decision(), exports_decision));
46846
47247
  const dir = join127(lokiDir2, "issues-run", "decompose");
46847
- mkdirSync67(dir, { recursive: true });
47248
+ mkdirSync68(dir, { recursive: true });
46848
47249
  const stamp2 = Date.now(), outPath = join127(dir, `issue-${issue.number}-${stamp2}.json`), iterationId = `issues-decompose-${issue.number}-${stamp2}`;
46849
47250
  let usd = null;
46850
47251
  const runner = createSessionRunner2({ provider, lokiRoot: lokiDir2, emit: (type, _stage, data) => {
@@ -46936,7 +47337,7 @@ var init_issues_epic = __esm(() => {
46936
47337
  });
46937
47338
 
46938
47339
  // ../../loki-ts/src/commands/issues_combine.ts
46939
- import { cpSync as cpSync6, existsSync as existsSync89, mkdirSync as mkdirSync67, mkdtempSync as mkdtempSync18, readFileSync as readFileSync117, rmSync as rmSync41, symlinkSync as symlinkSync5, writeFileSync as writeFileSync69 } from "fs";
47340
+ import { cpSync as cpSync6, existsSync as existsSync89, mkdirSync as mkdirSync68, mkdtempSync as mkdtempSync18, readFileSync as readFileSync117, rmSync as rmSync41, symlinkSync as symlinkSync5, writeFileSync as writeFileSync69 } from "fs";
46940
47341
  import { tmpdir as tmpdir23 } from "os";
46941
47342
  import { dirname as dirname54, join as join127 } from "path";
46942
47343
  function oneMaxFiles(env = process.env) {
@@ -47065,7 +47466,7 @@ function resetTo(wt, sha5) {
47065
47466
  }
47066
47467
  async function combineSlices(o) {
47067
47468
  const { io } = o, n3 = o.issue.number, branch = combinedBranch(n3), dir = join127(o.runDir, "combined");
47068
- mkdirSync67(dir, { recursive: true });
47469
+ mkdirSync68(dir, { recursive: true });
47069
47470
  const res = { branch, pr: null, verdict: "PARTIAL", commits: [], fallback: [], notProven: [], receiptPath: null, resolveUsd: [] };
47070
47471
  const byId = new Map(o.slices.map((s) => [s.id, s]));
47071
47472
  const filesOf = (s) => lines2(out2(o.repoDir, ["-c", "core.quotePath=false", "diff", "--no-renames", "--name-only", parentTipOf(s), s.branch, "--", ".", ":(exclude).loki"]));
@@ -47200,7 +47601,7 @@ async function combineSlices(o) {
47200
47601
  const s = byId.get(id);
47201
47602
  if (!s.receiptDir)
47202
47603
  throw new Error(`slice ${id} kept no receipt`);
47203
- mkdirSync67(join127(unitsDir2, id), { recursive: true });
47604
+ mkdirSync68(join127(unitsDir2, id), { recursive: true });
47204
47605
  for (const f of ["receipt.json", "events.jsonl"])
47205
47606
  if (existsSync89(join127(s.receiptDir, f)))
47206
47607
  cpSync6(join127(s.receiptDir, f), join127(unitsDir2, id, f));
@@ -47307,7 +47708,7 @@ async function publishFallback2(o, dropped2, res) {
47307
47708
  const base2 = s.parent && pushedBranch.has(s.parent) ? pushedBranch.get(s.parent) : null;
47308
47709
  const rec2 = readReceipt2(s.receiptDir), dir = join127(o.runDir, "combined"), bodyFile = join127(dir, `pr-body-${s.id}.md`);
47309
47710
  const files = lines2(out2(o.repoDir, ["-c", "core.quotePath=false", "diff", "--no-renames", "--name-only", s.parent && o.slices.some((x) => x.id === s.parent) ? o.slices.find((x) => x.id === s.parent).branch : o.baseSha, s.branch, "--", ".", ":(exclude).loki"]));
47310
- mkdirSync67(dir, { recursive: true });
47711
+ mkdirSync68(dir, { recursive: true });
47311
47712
  writeFileSync69(bodyFile, [`Slice ${s.id} of ${o.slug}#${o.issue.number}, opened as its own pull request because ${one2(why)}.${s.parent && !base2 ? ` This branch also holds slice ${s.parent}${res.pr ? `, which is in ${res.pr}` : ""}; merge that first.` : ""}`, "", sliceSection(s, { files, notProven: receiptNotProven(rec2), receiptSha: typeof rec2?.["receipt_sha256"] === "string" ? rec2["receipt_sha256"] : null }), o.io.link("PARTIAL").trim()].join(`
47312
47713
  `) + `
47313
47714
  `);
@@ -47398,7 +47799,7 @@ __export(exports_issues_run, {
47398
47799
  REAPER_SH: () => REAPER_SH
47399
47800
  });
47400
47801
  import { spawnSync as spawnSync19 } from "child_process";
47401
- import { cpSync as cpSync7, existsSync as existsSync90, mkdirSync as mkdirSync68, mkdtempSync as mkdtempSync19, readdirSync as readdirSync48, readFileSync as readFileSync118, rmdirSync as rmdirSync2, rmSync as rmSync42, writeFileSync as writeFileSync70 } from "fs";
47802
+ import { cpSync as cpSync7, existsSync as existsSync90, mkdirSync as mkdirSync69, mkdtempSync as mkdtempSync19, readdirSync as readdirSync48, readFileSync as readFileSync118, rmdirSync as rmdirSync2, rmSync as rmSync42, writeFileSync as writeFileSync70 } from "fs";
47402
47803
  import { tmpdir as tmpdir24 } from "os";
47403
47804
  import { join as join128, resolve as resolve32 } from "path";
47404
47805
  import { createInterface as createInterface3 } from "readline";
@@ -47681,7 +48082,7 @@ ${USAGE}`);
47681
48082
  }
47682
48083
  const stamp2 = started.toISOString().replace(/[:.]/g, "-");
47683
48084
  const runDir = join128(d.lokiDir, "issues-run", stamp2);
47684
- mkdirSync68(runDir, { recursive: true });
48085
+ mkdirSync69(runDir, { recursive: true });
47685
48086
  const byRef = new Map(actionable.map((i) => [`${slug}#${i.number}`, i]));
47686
48087
  const sink = () => {};
47687
48088
  if (actionable.length > 0) {
@@ -48012,7 +48413,7 @@ function makeWorktrees(repoDir) {
48012
48413
  return {
48013
48414
  create: (name, base2) => {
48014
48415
  root ??= mkdtempSync19(join128(tmpdir24(), "loki-issues-"));
48015
- mkdirSync68(root, { recursive: true });
48416
+ mkdirSync69(root, { recursive: true });
48016
48417
  const p = join128(root, name);
48017
48418
  safeGit(repoDir, ["worktree", "add", "-B", `loki/${name}`, p, base2]);
48018
48419
  return p;
@@ -48153,7 +48554,7 @@ __export(exports_supervisor, {
48153
48554
  });
48154
48555
  import { spawnSync as spawnSync20 } from "child_process";
48155
48556
  import { createHash as createHash31, createPublicKey as createPublicKey6, sign as sign4 } from "crypto";
48156
- import { existsSync as existsSync91, mkdirSync as mkdirSync69, readFileSync as readFileSync119, writeFileSync as writeFileSync71 } from "fs";
48557
+ import { existsSync as existsSync91, mkdirSync as mkdirSync70, readFileSync as readFileSync119, writeFileSync as writeFileSync71 } from "fs";
48157
48558
  import { dirname as dirname55, join as join129, relative as relative29, resolve as resolve33 } from "path";
48158
48559
  async function slackEvent(...a) {
48159
48560
  try {
@@ -48781,7 +49182,7 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
48781
49182
  task = g2.task;
48782
49183
  }
48783
49184
  if (spec) {
48784
- mkdirSync69(runDir, { recursive: true });
49185
+ mkdirSync70(runDir, { recursive: true });
48785
49186
  writeFileSync71(join129(runDir, "spec.snapshot.md"), spec.raw);
48786
49187
  for (const e of [env, process.env]) {
48787
49188
  e.LOKI_E10_SPEC_PATH = relative29(repoDir, spec.path);
@@ -48804,7 +49205,7 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
48804
49205
  if (!isIssue)
48805
49206
  env.LOKI_E10_TASK_TEXT = task;
48806
49207
  else if (isIssue) {
48807
- mkdirSync69(runDir, { recursive: true });
49208
+ mkdirSync70(runDir, { recursive: true });
48808
49209
  try {
48809
49210
  if (trackerRef)
48810
49211
  await fetchTrackerIssueToFile(trackerRef, join129(runDir, "issue.json"));
@@ -48895,9 +49296,11 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
48895
49296
  }
48896
49297
  }, 100);
48897
49298
  let liveStop = () => {};
48898
- const liveLine = !verbose && !json2 ? new LiveLine({ tty: !!process.stdout.isTTY, write: (x) => {
49299
+ const liveLine = verbose || json2 ? null : consoleOn() ? new LiveConsole({ write: (x) => {
49300
+ process.stdout.write(x);
49301
+ }, repoDir }) : new LiveLine({ tty: !!process.stdout.isTTY, write: (x) => {
48899
49302
  process.stdout.write(x);
48900
- }, columns: terminalWidth(), graceS: 3, repoDir }) : null;
49303
+ }, columns: terminalWidth(), graceS: 3, repoDir });
48901
49304
  if (liveLine) {
48902
49305
  if (process.env.LOKI_CONTROL_PLANE_URL)
48903
49306
  liveLine.setUrl(process.env.LOKI_CONTROL_PLANE_URL);
@@ -48983,7 +49386,7 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
48983
49386
  },
48984
49387
  comment: noPr ? undefined : async ({ issueRef, reason, prUrl }) => {
48985
49388
  const { DEFAULT_PUSH_SH: DEFAULT_PUSH_SH2 } = await Promise.resolve().then(() => (init_pr(), exports_pr));
48986
- mkdirSync69(runDir, { recursive: true });
49389
+ mkdirSync70(runDir, { recursive: true });
48987
49390
  const bodyFile = join129(runDir, "backstop-comment.md");
48988
49391
  writeFileSync71(bodyFile, `<!-- loki-backstop -->
48989
49392
  Loki 10 run ${runId2} ${prUrl ? `opened draft PR ${prUrl}` : "ended without a PR"}.
@@ -49099,6 +49502,7 @@ var init_supervisor = __esm(() => {
49099
49502
  init_tracker_intake();
49100
49503
  init_output();
49101
49504
  init_liveline();
49505
+ init_console();
49102
49506
  init_worker_proc();
49103
49507
  init_intent_card();
49104
49508
  init_preflight();
@@ -49465,7 +49869,7 @@ __export(exports_warm, {
49465
49869
  WarmEngine: () => WarmEngine
49466
49870
  });
49467
49871
  import { createHash as createHash32 } from "crypto";
49468
- import { existsSync as existsSync93, mkdirSync as mkdirSync70, readFileSync as readFileSync122, statSync as statSync40, unlinkSync as unlinkSync11 } from "fs";
49872
+ import { existsSync as existsSync93, mkdirSync as mkdirSync71, readFileSync as readFileSync122, statSync as statSync40, unlinkSync as unlinkSync11 } from "fs";
49469
49873
  import { createServer as createServer2 } from "net";
49470
49874
  import { dirname as dirname56, resolve as resolve34 } from "path";
49471
49875
  function speedEnabled() {
@@ -49548,7 +49952,7 @@ function startWarmIfEnabled() {
49548
49952
  }
49549
49953
  }
49550
49954
  function startWarmServer(path = warmSocketPath(), engine = new WarmEngine) {
49551
- mkdirSync70(dirname56(path), { recursive: true });
49955
+ mkdirSync71(dirname56(path), { recursive: true });
49552
49956
  try {
49553
49957
  unlinkSync11(path);
49554
49958
  } catch {}
@@ -49605,7 +50009,7 @@ var init_warm = __esm(() => {
49605
50009
 
49606
50010
  // ../../loki-ts/src/features/speed/already_done_async.ts
49607
50011
  import { execFile as execFile2 } from "child_process";
49608
- import { mkdirSync as mkdirSync71, mkdtempSync as mkdtempSync20, rmSync as rmSync43 } from "fs";
50012
+ import { mkdirSync as mkdirSync72, mkdtempSync as mkdtempSync20, rmSync as rmSync43 } from "fs";
49609
50013
  import { tmpdir as tmpdir25 } from "os";
49610
50014
  import { join as join132 } from "path";
49611
50015
  function hitsUnchangedFromBase(repoDir, baseSha, paths) {
@@ -49651,7 +50055,7 @@ function pinBaseTree(ctx, signal) {
49651
50055
  }
49652
50056
  trackRoot(root);
49653
50057
  try {
49654
- mkdirSync71(join132(root, "tree"));
50058
+ mkdirSync72(join132(root, "tree"));
49655
50059
  } catch {
49656
50060
  dropRoot(root);
49657
50061
  return Promise.resolve(null);
@@ -49746,7 +50150,7 @@ __export(exports_intake, {
49746
50150
  runIntake: () => runIntake,
49747
50151
  alreadyDoneCheckOn: () => alreadyDoneCheckOn
49748
50152
  });
49749
- import { appendFileSync as appendFileSync14, existsSync as existsSync94, mkdirSync as mkdirSync72, readFileSync as readFileSync123, writeFileSync as writeFileSync72 } from "fs";
50153
+ import { appendFileSync as appendFileSync14, existsSync as existsSync94, mkdirSync as mkdirSync73, readFileSync as readFileSync123, writeFileSync as writeFileSync72 } from "fs";
49750
50154
  import { dirname as dirname57, join as join133, resolve as resolve35 } from "path";
49751
50155
  function issueRefOf(raw2) {
49752
50156
  return typeof raw2.repo === "string" && raw2.repo && typeof raw2.number === "number" ? `${raw2.repo}#${raw2.number}` : null;
@@ -49775,7 +50179,7 @@ function excludeLokiDir(repoDir) {
49775
50179
  if (existing.split(`
49776
50180
  `).some((l) => l.trim() === ".loki/"))
49777
50181
  return;
49778
- mkdirSync72(dirname57(path), { recursive: true });
50182
+ mkdirSync73(dirname57(path), { recursive: true });
49779
50183
  const sep22 = existing.length > 0 && !existing.endsWith(`
49780
50184
  `) ? `
49781
50185
  ` : "";
@@ -49887,7 +50291,7 @@ async function runIntakeBody(ctx, signal, opts, held) {
49887
50291
  const ambiguity = gate.data;
49888
50292
  if (gate.stop)
49889
50293
  return { status: "failed", data: { ...common, task_sha256: taskSha256, source, base_sha: baseSha, tree, branch: ctx.branch, ...gate.stop.failData }, reason: gate.stop.reason };
49890
- mkdirSync72(ctx.runDir, { recursive: true });
50294
+ mkdirSync73(ctx.runDir, { recursive: true });
49891
50295
  const repomapRef = join133(ctx.runDir, "repomap.json");
49892
50296
  const cacheDir = repoCacheDir(repoKey(null, ctx.repoDir));
49893
50297
  const tm = { setup: { ms: Date.now() - t0, at: 0 } }, lap = () => {
@@ -50160,7 +50564,7 @@ ${g2.sample}`)].join(`
50160
50564
 
50161
50565
  // ../../loki-ts/src/util/app_probe.ts
50162
50566
  import { spawnSync as spawnSync21 } from "child_process";
50163
- import { existsSync as existsSync95, mkdirSync as mkdirSync73, readFileSync as readFileSync124, renameSync as renameSync25, writeFileSync as writeFileSync73 } from "fs";
50567
+ import { existsSync as existsSync95, mkdirSync as mkdirSync74, readFileSync as readFileSync124, renameSync as renameSync25, writeFileSync as writeFileSync73 } from "fs";
50164
50568
  import { join as join134 } from "path";
50165
50569
  function readJson8(p) {
50166
50570
  try {
@@ -50238,7 +50642,7 @@ async function functionalVerify(opts, url, dir, lokiDir2, timeoutMs) {
50238
50642
  if (!out3 || r.status !== 0)
50239
50643
  return res("not_run", "functional harness produced no result");
50240
50644
  const q = join134(lokiDir2, "quality");
50241
- mkdirSync73(q, { recursive: true });
50645
+ mkdirSync74(q, { recursive: true });
50242
50646
  const tmp = join134(q, `functional-results.json.tmp.${process.pid}`);
50243
50647
  writeFileSync73(tmp, JSON.stringify(out3, null, 2));
50244
50648
  renameSync25(tmp, join134(q, "functional-results.json"));
@@ -50286,7 +50690,7 @@ __export(exports_deep, {
50286
50690
  addedLineNumbers: () => addedLineNumbers,
50287
50691
  DEFAULT_SECRET_SCAN_SH: () => DEFAULT_SECRET_SCAN_SH
50288
50692
  });
50289
- import { copyFileSync as copyFileSync9, existsSync as existsSync96, mkdirSync as mkdirSync74, mkdtempSync as mkdtempSync21, readFileSync as readFileSync125, rmSync as rmSync44, writeFileSync as writeFileSync74 } from "fs";
50693
+ import { copyFileSync as copyFileSync9, existsSync as existsSync96, mkdirSync as mkdirSync75, mkdtempSync as mkdtempSync21, readFileSync as readFileSync125, rmSync as rmSync44, writeFileSync as writeFileSync74 } from "fs";
50290
50694
  import { tmpdir as tmpdir26 } from "os";
50291
50695
  import { dirname as dirname58, join as join135 } from "path";
50292
50696
  async function runFullSuite(ctx, signal, opts, checks, notProven2) {
@@ -50392,7 +50796,7 @@ async function secretLines(scriptPath, root, rel, cap = 5) {
50392
50796
  await walk(mid, hi);
50393
50797
  };
50394
50798
  try {
50395
- mkdirSync74(dirname58(probe), { recursive: true });
50799
+ mkdirSync75(dirname58(probe), { recursive: true });
50396
50800
  await walk(0, lines3.length);
50397
50801
  return found;
50398
50802
  } catch {
@@ -50469,7 +50873,7 @@ async function runSecretScan(ctx, changed, opts, checks, notProven2) {
50469
50873
  headLines.set(f, addedLineNumbers(d.stdout));
50470
50874
  } else
50471
50875
  fresh.push(f);
50472
- mkdirSync74(dirname58(join135(root, f)), { recursive: true });
50876
+ mkdirSync75(dirname58(join135(root, f)), { recursive: true });
50473
50877
  if (added === null)
50474
50878
  copyFileSync9(join135(ctx.repoDir, f), join135(root, f));
50475
50879
  else
@@ -50553,7 +50957,7 @@ async function runDeep(ctx, signal, opts = {}) {
50553
50957
  const addendumSha256 = sha2562(canonicalJson(addendumBody));
50554
50958
  const sig = signReceipt(`${ctx.runId}-deep`, addendumSha256);
50555
50959
  const addendum = { ...addendumBody, addendum_sha256: addendumSha256, verification: { jwt: sig.jwt, kid: sig.kid } };
50556
- mkdirSync74(ctx.runDir, { recursive: true });
50960
+ mkdirSync75(ctx.runDir, { recursive: true });
50557
50961
  writeFileSync74(join135(ctx.runDir, "receipt-addendum-1.json"), JSON.stringify(addendum, null, 2) + `
50558
50962
  `);
50559
50963
  if (opts.post === false) {
@@ -51689,7 +52093,7 @@ var init_codemod = __esm(() => {
51689
52093
 
51690
52094
  // ../../loki-ts/src/engine10/modernize/oracle/seal.ts
51691
52095
  import { createHash as createHash33 } from "crypto";
51692
- import { existsSync as existsSync98, mkdirSync as mkdirSync75, readFileSync as readFileSync128, writeFileSync as writeFileSync75 } from "fs";
52096
+ import { existsSync as existsSync98, mkdirSync as mkdirSync76, readFileSync as readFileSync128, writeFileSync as writeFileSync75 } from "fs";
51693
52097
  import { join as join140 } from "path";
51694
52098
  function normalizersSha(n3) {
51695
52099
  return sha2564(JSON.stringify({
@@ -51769,7 +52173,7 @@ function sealOracle(repoDir, mid, unit, log, normalizers = DEFAULT_NORMALIZERS)
51769
52173
  const coverageRaw = readFileSync128(coveragePath, "utf8");
51770
52174
  const normalizersHash = normalizersSha(normalizers);
51771
52175
  const sealed = buildSealedOracle(unit, casesRaw, coverageRaw, normalizersHash);
51772
- mkdirSync75(dir, { recursive: true });
52176
+ mkdirSync76(dir, { recursive: true });
51773
52177
  writeFileSync75(sealedPath, JSON.stringify(sealed, null, 2));
51774
52178
  log.append(sealed.verdict === "PROVEN_ORACLE" ? "oracle.captured" : "oracle.flagged", {
51775
52179
  unit,
@@ -51834,7 +52238,7 @@ var init_seal2 = __esm(() => {
51834
52238
 
51835
52239
  // ../../loki-ts/src/engine10/modernize/oracle/search.ts
51836
52240
  import { spawnSync as spawnSync23 } from "child_process";
51837
- import { copyFileSync as copyFileSync10, existsSync as existsSync99, linkSync as linkSync4, mkdirSync as mkdirSync76, mkdtempSync as mkdtempSync22, readFileSync as readFileSync129, renameSync as renameSync26, rmSync as rmSync45, rmdirSync as rmdirSync3, writeFileSync as writeFileSync76 } from "fs";
52241
+ import { copyFileSync as copyFileSync10, existsSync as existsSync99, linkSync as linkSync4, mkdirSync as mkdirSync77, mkdtempSync as mkdtempSync22, readFileSync as readFileSync129, renameSync as renameSync26, rmSync as rmSync45, rmdirSync as rmdirSync3, writeFileSync as writeFileSync76 } from "fs";
51838
52242
  import { tmpdir as tmpdir27 } from "os";
51839
52243
  import { basename as basename40, dirname as dirname60, join as join141 } from "path";
51840
52244
  function search(unitSource, seedCases, propose, runCapture, opts = {}) {
@@ -52011,7 +52415,7 @@ function captureUnitOracle(a) {
52011
52415
  rec2.not_proven = [...rec2.not_proven ?? [], `nondeterministic field ${f}`];
52012
52416
  }
52013
52417
  });
52014
- mkdirSync76(dir, { recursive: true });
52418
+ mkdirSync77(dir, { recursive: true });
52015
52419
  writeFileSync76(tmpCases, recs.map((x) => JSON.stringify(x)).join(`
52016
52420
  `) + `
52017
52421
  `);
@@ -52804,7 +53208,7 @@ var init_resume = __esm(() => {
52804
53208
  });
52805
53209
 
52806
53210
  // ../../loki-ts/src/engine10/modernize/report.ts
52807
- import { mkdirSync as mkdirSync77, readFileSync as readFileSync132, writeFileSync as writeFileSync77 } from "fs";
53211
+ import { mkdirSync as mkdirSync78, readFileSync as readFileSync132, writeFileSync as writeFileSync77 } from "fs";
52808
53212
  import { dirname as dirname61 } from "path";
52809
53213
  function buildReport(o) {
52810
53214
  const units = o.units.map((x) => ({ unit: x.unit, verdict: x.verdict, not_proven: [...x.not_proven], rate: x.rate, branchPct: x.branchPct, receiptPath: x.receiptPath, receiptSha256: x.receiptSha256 }));
@@ -52848,7 +53252,7 @@ function renderReportMd(r) {
52848
53252
  function writeReport(o) {
52849
53253
  const sealed = sealReport(buildReport(o), o.sign);
52850
53254
  const jp = reportJsonPath(o.repoDir, o.mid);
52851
- mkdirSync77(dirname61(jp), { recursive: true });
53255
+ mkdirSync78(dirname61(jp), { recursive: true });
52852
53256
  writeFileSync77(jp, JSON.stringify(sealed, null, 2) + `
52853
53257
  `, "utf8");
52854
53258
  writeFileSync77(reportMdPath(o.repoDir, o.mid), renderReportMd(sealed), "utf8");
@@ -52864,7 +53268,7 @@ var init_report = __esm(() => {
52864
53268
  });
52865
53269
 
52866
53270
  // ../../loki-ts/src/engine10/modernize/ship.ts
52867
- import { mkdirSync as mkdirSync78, writeFileSync as writeFileSync78 } from "fs";
53271
+ import { mkdirSync as mkdirSync79, writeFileSync as writeFileSync78 } from "fs";
52868
53272
  import { join as join144 } from "path";
52869
53273
  function waveIsDraft(verdict, units) {
52870
53274
  return verdict === null || verdict.verified !== true || units.length === 0 || units.some((x) => x.verdict !== "PROVEN");
@@ -52887,7 +53291,7 @@ function shipWave(o) {
52887
53291
  if (draft)
52888
53292
  return fail2("wave not verified: branch stays local, not pushed");
52889
53293
  const dir = join144(o.repoDir, ".loki", "modernize", o.mid);
52890
- mkdirSync78(dir, { recursive: true });
53294
+ mkdirSync79(dir, { recursive: true });
52891
53295
  const bodyFile = join144(dir, `wave-${o.wave}-pr-body.md`);
52892
53296
  writeFileSync78(bodyFile, renderWaveBody(o.wave, o.verdict, o.units), "utf8");
52893
53297
  const r = (o.push ?? runPushPr)({ repoDir: o.repoDir, branch: o.branch, title: `Loki modernize: wave ${o.wave}`, bodyFile, draft, pinnedOrigin });
@@ -52908,7 +53312,7 @@ var init_ship2 = __esm(() => {
52908
53312
  });
52909
53313
 
52910
53314
  // ../../loki-ts/src/engine10/modernize/presealed_wall.ts
52911
- import { existsSync as existsSync101, mkdirSync as mkdirSync79, readFileSync as readFileSync133, writeFileSync as writeFileSync79 } from "fs";
53315
+ import { existsSync as existsSync101, mkdirSync as mkdirSync80, readFileSync as readFileSync133, writeFileSync as writeFileSync79 } from "fs";
52912
53316
  import { join as join145 } from "path";
52913
53317
  function isRealFailCount(n3) {
52914
53318
  return typeof n3 === "number" && Number.isInteger(n3) && n3 >= 1;
@@ -52973,7 +53377,7 @@ function sealPreSealedWall(repoDir, mid, unit, target, runConformance, log, base
52973
53377
  reason: `conformance did not run (D42 (3)): exit ${String(outcome.exitCode)}${outcome.timedOut ? ", timeout" : ""}; seal refused, NOT PROVEN`
52974
53378
  };
52975
53379
  }
52976
- mkdirSync79(dir, { recursive: true });
53380
+ mkdirSync80(dir, { recursive: true });
52977
53381
  const sealedPath = preSealedPath(repoDir, mid, unit);
52978
53382
  if (existsSync101(sealedPath)) {
52979
53383
  throw new Error(`presealed wall: ${unit} already has a sealed presealed_wall.json; re-seal refused (seal is write-once)`);
@@ -53050,7 +53454,7 @@ var init_presealed_wall = __esm(() => {
53050
53454
  // ../../loki-ts/src/engine10/modernize/unit.ts
53051
53455
  import { spawnSync as spawnSync24 } from "child_process";
53052
53456
  import { createHash as createHash34 } from "crypto";
53053
- import { lstatSync as lstatSync32, readFileSync as readFileSync134, readdirSync as readdirSync50, readlinkSync as readlinkSync7, realpathSync as realpathSync40, rmSync as rmSync46 } from "fs";
53457
+ import { lstatSync as lstatSync32, readFileSync as readFileSync134, readdirSync as readdirSync50, readlinkSync as readlinkSync7, realpathSync as realpathSync41, rmSync as rmSync46 } from "fs";
53054
53458
  import { tmpdir as tmpdir28 } from "os";
53055
53459
  import { join as join146, sep as sep22 } from "path";
53056
53460
  function isSealedName(rel) {
@@ -53079,13 +53483,13 @@ function purgePycache(dir) {
53079
53483
  function outsideTargetDigest(dir, full) {
53080
53484
  let real4;
53081
53485
  try {
53082
- real4 = realpathSync40(full);
53486
+ real4 = realpathSync41(full);
53083
53487
  } catch {
53084
53488
  return "dangling";
53085
53489
  }
53086
53490
  let root;
53087
53491
  try {
53088
- root = realpathSync40(dir);
53492
+ root = realpathSync41(dir);
53089
53493
  } catch {
53090
53494
  return "noroot";
53091
53495
  }
@@ -53477,7 +53881,7 @@ var init_wave = __esm(() => {
53477
53881
 
53478
53882
  // ../../loki-ts/src/util/modernize_unit.ts
53479
53883
  import { spawnSync as spawnSync26 } from "child_process";
53480
- import { existsSync as existsSync102, lstatSync as lstatSync33, mkdtempSync as mkdtempSync23, readFileSync as readFileSync136, realpathSync as realpathSync41, rmSync as rmSync47, statSync as statSync42, writeFileSync as writeFileSync80 } from "fs";
53884
+ import { existsSync as existsSync102, lstatSync as lstatSync33, mkdtempSync as mkdtempSync23, readFileSync as readFileSync136, realpathSync as realpathSync42, rmSync as rmSync47, statSync as statSync42, writeFileSync as writeFileSync80 } from "fs";
53481
53885
  import { tmpdir as tmpdir29 } from "os";
53482
53886
  import { join as join148, sep as sep23 } from "path";
53483
53887
  function parseUnitArgs(args) {
@@ -53558,8 +53962,8 @@ function defaultUnitFile(unitId, newTreeDir) {
53558
53962
  if (!isSafeUnitId(unitId))
53559
53963
  return null;
53560
53964
  try {
53561
- const root = realpathSync41(newTreeDir);
53562
- const real4 = realpathSync41(join148(root, unitId));
53965
+ const root = realpathSync42(newTreeDir);
53966
+ const real4 = realpathSync42(join148(root, unitId));
53563
53967
  return real4.startsWith(root + sep23) ? real4 : null;
53564
53968
  } catch {
53565
53969
  return null;
@@ -54721,7 +55125,7 @@ __export(exports_base_guard, {
54721
55125
  });
54722
55126
  import { execFileSync as execFileSync12 } from "child_process";
54723
55127
  import { createHash as createHash37 } from "crypto";
54724
- import { existsSync as existsSync107, mkdirSync as mkdirSync80, mkdtempSync as mkdtempSync25, readdirSync as readdirSync52, readFileSync as readFileSync140, readlinkSync as readlinkSync8, realpathSync as realpathSync42, rmSync as rmSync49, statSync as statSync45, symlinkSync as symlinkSync6, utimesSync, writeFileSync as writeFileSync82 } from "fs";
55128
+ import { existsSync as existsSync107, mkdirSync as mkdirSync81, mkdtempSync as mkdtempSync25, readdirSync as readdirSync52, readFileSync as readFileSync140, readlinkSync as readlinkSync8, realpathSync as realpathSync43, rmSync as rmSync49, statSync as statSync45, symlinkSync as symlinkSync6, utimesSync, writeFileSync as writeFileSync82 } from "fs";
54725
55129
  import { tmpdir as tmpdir31 } from "os";
54726
55130
  import { basename as basename42, dirname as dirname63, join as join152, relative as relative31, resolve as resolve38, sep as sep24 } from "path";
54727
55131
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -54823,7 +55227,7 @@ function insideAny(p, roots) {
54823
55227
  if (under3(resolve38(p)))
54824
55228
  return true;
54825
55229
  try {
54826
- return under3(realpathSync42(p));
55230
+ return under3(realpathSync43(p));
54827
55231
  } catch {
54828
55232
  return false;
54829
55233
  }
@@ -54838,7 +55242,7 @@ function namedPaths2(file, text4) {
54838
55242
  function depsSeeHead(pkgDir, repoDir) {
54839
55243
  let roots;
54840
55244
  try {
54841
- roots = [...new Set([resolve38(repoDir), realpathSync42(repoDir)])];
55245
+ roots = [...new Set([resolve38(repoDir), realpathSync43(repoDir)])];
54842
55246
  } catch {
54843
55247
  return true;
54844
55248
  }
@@ -54852,7 +55256,7 @@ function depsSeeHead(pkgDir, repoDir) {
54852
55256
  const t = resolve38(dir, readlinkSync8(p));
54853
55257
  let rt = t;
54854
55258
  try {
54855
- rt = realpathSync42(t);
55259
+ rt = realpathSync43(t);
54856
55260
  } catch {}
54857
55261
  if (insideAny(t, roots) && !own.some((r) => rt === r || rt.startsWith(r + sep24)))
54858
55262
  return true;
@@ -54871,7 +55275,7 @@ function depsSeeHead(pkgDir, repoDir) {
54871
55275
  return ["node_modules", ".venv"].some((d) => {
54872
55276
  try {
54873
55277
  const top = join152(pkgDir, d);
54874
- return walk(top, [...new Set([resolve38(top), realpathSync42(top)])]);
55278
+ return walk(top, [...new Set([resolve38(top), realpathSync43(top)])]);
54875
55279
  } catch (e) {
54876
55280
  if (e.code === "ENOENT")
54877
55281
  return false;
@@ -55048,7 +55452,7 @@ function splitDeclaredAdvisories(notes, c) {
55048
55452
  const named2 = (f) => new RegExp(`${f.includes("/") ? `(?<![\\w./-])${escapeRegex(f)}(?![\\w-])|` : ""}[/"'\`]${escapeRegex(basename42(f))}(?=["'\`\\s);]|$)`).test(wall());
55049
55453
  const linkOk = (f) => {
55050
55454
  try {
55051
- const root = realpathSync42(c.repoDir), t = realpathSync42(join152(c.repoDir, f)), rel = relative31(root, t);
55455
+ const root = realpathSync43(c.repoDir), t = realpathSync43(join152(c.repoDir, f)), rel = relative31(root, t);
55052
55456
  return !rel.startsWith("..") && !rel.split(sep24).includes(".git") && statSync45(t).isFile() && changed.has(rel.split(sep24).join("/")) && !isTestFile(rel) && !c.wallPaths.includes(rel);
55053
55457
  } catch {
55054
55458
  return false;
@@ -55081,7 +55485,7 @@ function removeRunWorktrees(repoDir, baseSha) {
55081
55485
  return;
55082
55486
  const roots = [tmpdir31()];
55083
55487
  try {
55084
- roots.push(realpathSync42(tmpdir31()));
55488
+ roots.push(realpathSync43(tmpdir31()));
55085
55489
  } catch {}
55086
55490
  for (const t of checkedOut(repoDir).trees.slice(1)) {
55087
55491
  const named2 = RUN_TMP_WORKTREE_RE.test(basename42(t.path)) || RUN_TMP_WORKTREE_RE.test(basename42(dirname63(t.path)));
@@ -55099,7 +55503,7 @@ function settleBranch(repoDir, branch, dir, stem2, pushed, extra = {}) {
55099
55503
  `, deleted: false };
55100
55504
  let bundle = null;
55101
55505
  try {
55102
- mkdirSync80(dir, { recursive: true });
55506
+ mkdirSync81(dir, { recursive: true });
55103
55507
  if (unique > 0) {
55104
55508
  const file = join152(dir, `${stem2}.bundle`);
55105
55509
  if (git14(repoDir, ["bundle", "create", file, `refs/heads/${branch}`, ...NOT_ELSEWHERE], 120000) === null || git14(repoDir, ["bundle", "verify", file], 120000) === null)
@@ -55174,7 +55578,7 @@ function finishRunBranch(repoDir, runId2, end, env = process.env) {
55174
55578
  const branch = `loki/${runId2}`, runDir = join152(repoDir, ".loki", "runs", runId2), tip = tipOf(repoDir, `refs/heads/${branch}`);
55175
55579
  try {
55176
55580
  if (end.deferred && tip) {
55177
- mkdirSync80(runDir, { recursive: true });
55581
+ mkdirSync81(runDir, { recursive: true });
55178
55582
  writeFileSync82(join152(runDir, "branch.json"), JSON.stringify({ branch, head_sha: tip, pushed: end.pushed, bundle: null, orig_branch: end.orig, deferred: true }, null, 2) + `
55179
55583
  `);
55180
55584
  return `engine10: the checkout stays on ${branch} while the background deep verify runs, then returns to ${end.orig ?? "the starting branch"}
@@ -55341,9 +55745,9 @@ __export(exports_verify, {
55341
55745
  COLLATERAL_RED: () => COLLATERAL_RED,
55342
55746
  BCE_REASON: () => BCE_REASON
55343
55747
  });
55344
- import { existsSync as existsSync108, mkdtempSync as mkdtempSync26, readFileSync as readFileSync141, realpathSync as realpathSync43, rmSync as rmSync50 } from "fs";
55748
+ import { existsSync as existsSync108, mkdtempSync as mkdtempSync26, readFileSync as readFileSync141, realpathSync as realpathSync44, rmSync as rmSync50, statSync as statSync46 } from "fs";
55345
55749
  import { tmpdir as tmpdir32 } from "os";
55346
- import { basename as basename43, isAbsolute as isAbsolute21, join as join153, relative as relative32, resolve as resolve39 } from "path";
55750
+ import { basename as basename43, dirname as dirname64, isAbsolute as isAbsolute21, join as join153, relative as relative32, resolve as resolve39 } from "path";
55347
55751
  function carriedTimeouts(prev, tests, changed, keep, env = process.env) {
55348
55752
  if (!timeoutCarryOn(env))
55349
55753
  return [];
@@ -55584,7 +55988,7 @@ async function vitestBatch(cwd, rels, signal, opts = {}) {
55584
55988
  return null;
55585
55989
  const real4 = (p) => {
55586
55990
  try {
55587
- return realpathSync43(p);
55991
+ return realpathSync44(p);
55588
55992
  } catch {
55589
55993
  return p;
55590
55994
  }
@@ -55963,6 +56367,39 @@ function tscLocalKeys(out3, pkgRel, keep, changed) {
55963
56367
  return null;
55964
56368
  return found.every((m) => TSC_LOCAL.has(m[2]) && !keep.has(join153(pkgRel === "." ? "" : pkgRel, m[1].trim()))) ? found.map((m) => `${m[1].trim()}|${m[2]}`) : null;
55965
56369
  }
56370
+ function tscOnlyIgnored(repoDir, cwd, out3) {
56371
+ if (!out3 || out3.length >= 60000)
56372
+ return false;
56373
+ const lines3 = out3.split(`
56374
+ `).filter((l) => /error TS\d+/.test(l));
56375
+ if (lines3.length === 0)
56376
+ return false;
56377
+ try {
56378
+ return lines3.every((l) => {
56379
+ const m = /^(\S.*?)(?:\(\d+,\d+\)|:\d+:\d+)\s*(?::|-)\s*error TS2307: Cannot find module '([^']+)'/.exec(l.trim());
56380
+ if (!m)
56381
+ return false;
56382
+ const file = join153(cwd, m[1].trim()), mod = m[2];
56383
+ if (!mod.startsWith("."))
56384
+ return false;
56385
+ try {
56386
+ safeGit(repoDir, ["check-ignore", "-q", "--", file]);
56387
+ } catch {
56388
+ return false;
56389
+ }
56390
+ const target = join153(dirname64(file), mod).replace(/\.(js|mjs|cjs|jsx)$/, "");
56391
+ return ![target, ...[".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".d.ts"].map((e) => target + e), ...["index.ts", "index.tsx", "index.js"].map((e) => join153(target, e))].some((t) => {
56392
+ try {
56393
+ return statSync46(t).isFile();
56394
+ } catch {
56395
+ return false;
56396
+ }
56397
+ });
56398
+ });
56399
+ } catch {
56400
+ return false;
56401
+ }
56402
+ }
55966
56403
  function tscUntouchedShape(out3, pkgRel, touched, symbols) {
55967
56404
  if (out3.length >= 60000 || [...touched].some((f) => LINT_CONFIG.test(f)))
55968
56405
  return false;
@@ -56043,7 +56480,9 @@ async function runLintChecks(ctx, changed, signal, checks, opts = {}) {
56043
56480
  const sfx = g2.root === "." ? "" : `:${g2.root}`, co = g2.root === "." ? opts : { ...opts, cwd: g2.cwd };
56044
56481
  if (existsSync108(join153(g2.cwd, "tsconfig.json"))) {
56045
56482
  const c = await runCheck(ctx, `lint:tsc${sfx}`, "npx", ["--no-install", "tsc", "--noEmit", "-p", "."], signal, checks, { ...co, kind: "static" });
56046
- if (c.result === "fail" && keep && tscLocalKeys(tscOut.get(c) ?? "", g2.root, keep, [...keep]) && tscUntouchedLocal(tscOut.get(c) ?? "", g2.root, keep, [...keep], await tscOnBase(ctx, g2.cwd, signal, co)))
56483
+ if (c.result === "fail" && tscOnlyIgnored(ctx.repoDir, g2.cwd, tscOut.get(c) ?? ""))
56484
+ pre.push(c.name);
56485
+ else if (c.result === "fail" && keep && tscLocalKeys(tscOut.get(c) ?? "", g2.root, keep, [...keep]) && tscUntouchedLocal(tscOut.get(c) ?? "", g2.root, keep, [...keep], await tscOnBase(ctx, g2.cwd, signal, co)))
56047
56486
  pre.push(c.name);
56048
56487
  else if (c.result === "fail" && keep && untouched && lintUntouchedOn()) {
56049
56488
  const syms = diffSymbols(ctx, [...keep]), o = tscOut.get(c) ?? "";
@@ -56396,8 +56835,9 @@ var init_verify = __esm(() => {
56396
56835
  return [...testFileWeakened(ctx.repoDir, ctx.baseSha, null, t.path, "M", intake?.task ?? "") ? [`weakened test: ${t.path}`] : [], ...assertDeltaNotes(ctx.repoDir, ctx.baseSha, null, t.path, intake?.task ?? "", k?.b, k?.h) ?? []];
56397
56836
  });
56398
56837
  const weakened = [...modifiedRel, ...cfgChanged.map((f) => `test configuration changed: ${f}`), ...preRed.weak.map((n3) => `skipped or fewer tests than base: ${n3}`), ...collateralRed.map((n3) => `${COLLATERAL_RED}: ${n3}`), ...preRed.quiet.filter((n3) => preRed.names.includes(n3)).map((n3) => `${QUIET_RED}: ${n3}`)];
56838
+ const fullChecks = checks.filter((c) => c.name.startsWith("full suite")), fullSuiteRan = fullChecks.length > 0 && fullChecks.every((c) => c.result === "pass" || c.result === "fail");
56399
56839
  const depsNotes = unusedInstallNotes(intake?.deps_not_proven ?? [], api, changed, checks.map((c) => c.name), ctx.repoDir);
56400
- const notProven2 = [...complete ? [] : [QUICK_ONLY_NOTE], ...preRed.envCrash.map((e) => `${e.name}: ${BCE_REASON} (${e.sig})`), ...weakened, ...hiddenEdits(ctx.repoDir), ...ignoreRuleChanges(ctx.repoDir, intake?.ignore_snapshot, ctx.baseSha), ...dependentNotes(dep), ...depsNotes.cap, ...pub.filter((c) => c.name === "holdout" && c.result !== "pass").map((c) => c.result === "not_run" ? "holdout not executed" : "holdout check failed"), ...[...fullNotProven].filter((n3) => !naNote(n3)), ...pub.filter((c) => c.owner === "harness" && c.name !== "holdout").map((c) => `${c.reason} (${c.name}; harness-owned, no fix rounds)`), ...new Set(checks.filter((c) => c.interpreter === "system" && c.result !== "not_run").map((c) => c.name.startsWith("lint:") ? "lint ran on the system ruff" : "tests ran on the system interpreter"))];
56840
+ const notProven2 = [...complete ? [] : [QUICK_ONLY_NOTE], ...preRed.envCrash.map((e) => `${e.name}: ${BCE_REASON} (${e.sig})`), ...weakened, ...hiddenEdits(ctx.repoDir), ...ignoreRuleChanges(ctx.repoDir, intake?.ignore_snapshot, ctx.baseSha), ...dependentNotes(dep).filter((n3) => !(fullSuiteRan && n3.startsWith("reverse-dependent tests dropped"))), ...depsNotes.cap, ...pub.filter((c) => c.name === "holdout" && c.result !== "pass").map((c) => c.result === "not_run" ? "holdout not executed" : "holdout check failed"), ...[...fullNotProven].filter((n3) => !naNote(n3)), ...pub.filter((c) => c.owner === "harness" && c.name !== "holdout").map((c) => `${c.reason} (${c.name}; harness-owned, no fix rounds)`), ...new Set(checks.filter((c) => c.interpreter === "system" && c.result !== "not_run").map((c) => c.name.startsWith("lint:") ? "lint ran on the system ruff" : "tests ran on the system interpreter"))];
56401
56841
  const wallDropped = [...wallPaths].filter((p) => !wallTests.some((t) => t.path === p));
56402
56842
  notProven2.push(...wallDropped.map((p) => `Wall test not executed: ${p}: ${NO_RUNNER_REASON}`));
56403
56843
  const wallNames = new Set(wallTests.map(testCheckName)), wallRun = checks.filter((c) => wallNames.has(c.name) || isHold(c)), wallFailTail = writeWallFailureTail(ctx.runDir, checks.filter((c) => wallNames.has(c.name) && c.result === "fail" && !isHold(c) && !preRed.names.includes(c.name)).map((c) => ({ name: c.name, out: failTails.get(c) ?? "" }))), wallPassed = wallRun.some((c) => c.result === "fail") ? false : wallRun.length > 0 && wallDropped.length === 0 && wallRun.every((c) => c.result === "pass") ? true : undefined;
@@ -56411,7 +56851,7 @@ var init_verify = __esm(() => {
56411
56851
  });
56412
56852
 
56413
56853
  // ../../loki-ts/src/runner/stop_checks.ts
56414
- import { appendFileSync as appendFileSync15, existsSync as existsSync109, mkdirSync as mkdirSync81, readFileSync as readFileSync142, statSync as statSync46 } from "fs";
56854
+ import { appendFileSync as appendFileSync15, existsSync as existsSync109, mkdirSync as mkdirSync82, readFileSync as readFileSync142, statSync as statSync47 } from "fs";
56415
56855
  import { basename as basename44, isAbsolute as isAbsolute22, join as join154, relative as relative33 } from "path";
56416
56856
  function redOnBase(repoDir) {
56417
56857
  try {
@@ -56465,9 +56905,9 @@ function recordStopBlock(repoDir, name, err, env = process.env) {
56465
56905
  return;
56466
56906
  try {
56467
56907
  const p = stopBlocksPath(repoDir);
56468
- if (existsSync109(p) && statSync46(p).size >= STOP_BLOCKS_MAX_BYTES)
56908
+ if (existsSync109(p) && statSync47(p).size >= STOP_BLOCKS_MAX_BYTES)
56469
56909
  return;
56470
- mkdirSync81(join154(repoDir, ".loki", "state"), { recursive: true });
56910
+ mkdirSync82(join154(repoDir, ".loki", "state"), { recursive: true });
56471
56911
  appendFileSync15(p, JSON.stringify({ at: new Date().toISOString(), run_id: runId2.slice(0, 128), name: redactSecrets(name).slice(0, 200), first_error: redactSecrets(err).slice(0, 300) }) + `
56472
56912
  `);
56473
56913
  } catch {}
@@ -56517,8 +56957,8 @@ var init_stop_checks = __esm(() => {
56517
56957
  });
56518
56958
 
56519
56959
  // ../../loki-ts/src/runner/provider_opencode.ts
56520
- import { mkdirSync as mkdirSync82 } from "fs";
56521
- import { dirname as dirname64 } from "path";
56960
+ import { mkdirSync as mkdirSync83 } from "fs";
56961
+ import { dirname as dirname65 } from "path";
56522
56962
  function buildOpencodeArgv(prompt, env = process.env) {
56523
56963
  const cliOverride = env["LOKI_OPENCODE_CLI"];
56524
56964
  const cli = cliOverride && cliOverride.length > 0 ? cliOverride : "opencode";
@@ -56539,7 +56979,7 @@ function opencodeProvider() {
56539
56979
  return {
56540
56980
  async invoke(call) {
56541
56981
  const r = await run(buildOpencodeArgv(call.prompt), { cwd: call.cwd });
56542
- mkdirSync82(dirname64(call.iterationOutputPath), { recursive: true });
56982
+ mkdirSync83(dirname65(call.iterationOutputPath), { recursive: true });
56543
56983
  await Bun.write(call.iterationOutputPath, r.stderr.length > 0 ? `${r.stderr}
56544
56984
  ${r.stdout}` : r.stdout);
56545
56985
  return { exitCode: r.exitCode, capturedOutputPath: call.iterationOutputPath };
@@ -97725,8 +98165,8 @@ __export(exports_providers, {
97725
98165
  SDK_BUNDLED_CLAUDE_CODE: () => SDK_BUNDLED_CLAUDE_CODE,
97726
98166
  PROVIDER_COMMIT_HYGIENE: () => PROVIDER_COMMIT_HYGIENE
97727
98167
  });
97728
- import { mkdirSync as mkdirSync84, existsSync as existsSync111, readFileSync as readFileSync144, realpathSync as realpathSync45, appendFileSync as appendFileSync17 } from "fs";
97729
- import { delimiter as delimiter5, dirname as dirname66, isAbsolute as isAbsolute24, relative as relative34, resolve as resolve41, sep as sep26 } from "path";
98168
+ import { mkdirSync as mkdirSync85, existsSync as existsSync111, readFileSync as readFileSync144, realpathSync as realpathSync46, appendFileSync as appendFileSync17 } from "fs";
98169
+ import { delimiter as delimiter5, dirname as dirname67, isAbsolute as isAbsolute24, relative as relative34, resolve as resolve41, sep as sep26 } from "path";
97730
98170
  function mergeDisallowedTools(policy, stageCsv) {
97731
98171
  return [...new Set([...policy ?? [], ...stageCsv.split(",").filter(Boolean)])];
97732
98172
  }
@@ -97869,14 +98309,14 @@ function applyMaxTierCeiling(tier, model) {
97869
98309
  }
97870
98310
  }
97871
98311
  function ensureParentDir(path) {
97872
- const parent = dirname66(path);
98312
+ const parent = dirname67(path);
97873
98313
  if (!parent || parent === "." || parent === "/")
97874
98314
  return;
97875
- mkdirSync84(parent, { recursive: true });
98315
+ mkdirSync85(parent, { recursive: true });
97876
98316
  }
97877
98317
  function physicalPath(path) {
97878
98318
  try {
97879
- return realpathSync45(path);
98319
+ return realpathSync46(path);
97880
98320
  } catch {
97881
98321
  return resolve41(path);
97882
98322
  }
@@ -97968,7 +98408,8 @@ function implementWriteFence(cwd) {
97968
98408
  const stage11 = process.env["LOKI_E10_STAGE"], deny = [...cwd && stage11 ? stateDenyRules(cwd, harnessOutputs(cwd, process.env)) : [], ...cwd && fenceEnabled(stage11) ? fencedDenyRules(cwd, process.env) : []];
97969
98409
  if (stage11 !== "implement" && deny.length === 0)
97970
98410
  return;
97971
- return { permissions: { ...stage11 === "implement" ? { blockWritesOutsideWorkingDirectories: true } : {}, ...deny.length > 0 ? { deny } : {} } };
98411
+ const scratch = process.env["LOKI_SCRATCH"];
98412
+ return { permissions: { ...stage11 === "implement" ? { blockWritesOutsideWorkingDirectories: true, ...scratch ? { additionalDirectories: [scratch] } : {} } : {}, ...deny.length > 0 ? { deny } : {} } };
97972
98413
  }
97973
98414
  async function writeCaptured(path, stdout, stderr) {
97974
98415
  ensureParentDir(path);
@@ -98024,6 +98465,7 @@ function claudeProvider() {
98024
98465
  ...modelArgv,
98025
98466
  ...autoFlags,
98026
98467
  ...sessionArgv,
98468
+ ...process.env["LOKI_SCRATCH"] && claudeFlagSupported("--add-dir") ? ["--add-dir", process.env["LOKI_SCRATCH"]] : [],
98027
98469
  ...hostGuard2 || sessionSettings || fence3 ? ["--settings", cliSettingsJson(hostGuard2, sessionSettings, fence3)] : [],
98028
98470
  "-p",
98029
98471
  call.prompt
@@ -98064,7 +98506,7 @@ function providerCallTimeoutMs(env) {
98064
98506
  function emitSdkDegradationEvent(cwd, payload) {
98065
98507
  try {
98066
98508
  const lokiRoot = process.env["LOKI_DIR"] ?? resolve41(cwd, ".loki");
98067
- mkdirSync84(lokiRoot, { recursive: true });
98509
+ mkdirSync85(lokiRoot, { recursive: true });
98068
98510
  const record = {
98069
98511
  type: "capability_degraded",
98070
98512
  source: "sdk_loop",
@@ -98337,8 +98779,8 @@ __export(exports_session, {
98337
98779
  CONNECTION_ENV: () => CONNECTION_ENV
98338
98780
  });
98339
98781
  import { spawn as spawn12 } from "child_process";
98340
- import { copyFileSync as copyFileSync11, existsSync as existsSync112, mkdirSync as mkdirSync85, readFileSync as readFileSync145, writeFileSync as writeFileSync84, writeSync as writeSync4 } from "fs";
98341
- import { dirname as dirname67, join as join157, resolve as resolve42 } from "path";
98782
+ import { copyFileSync as copyFileSync11, existsSync as existsSync112, mkdirSync as mkdirSync86, readFileSync as readFileSync145, writeFileSync as writeFileSync84, writeSync as writeSync4 } from "fs";
98783
+ import { dirname as dirname68, join as join157, resolve as resolve42 } from "path";
98342
98784
  import { tmpdir as tmpdir33 } from "os";
98343
98785
  import { randomUUID as randomUUID2 } from "crypto";
98344
98786
  function capStopOf(summary) {
@@ -98467,7 +98909,7 @@ function childEnv2(opts, cfg) {
98467
98909
  env[`LOKI_CLAUDE_MODEL_${t}`] = pin;
98468
98910
  env[`LOKI_MODEL_${t}`] = pin;
98469
98911
  }
98470
- const caps = cfg.provider === "claude" ? hooks.effort?.caps?.(opts.stage, process.env["LOKI_MODEL_OVERRIDE"] || sessionPinModel(process.env) || (pin && pin !== PROVIDER_DEFAULT_MODEL ? pin : "") || opts.model || cfg.model || resolveModel(cfg.provider)) : undefined;
98912
+ const caps = cfg.provider === "claude" && env["LOKI_E10_FULL_SESSION"] !== "1" ? hooks.effort?.caps?.(opts.stage, process.env["LOKI_MODEL_OVERRIDE"] || sessionPinModel(process.env) || (pin && pin !== PROVIDER_DEFAULT_MODEL ? pin : "") || opts.model || cfg.model || resolveModel(cfg.provider)) : undefined;
98471
98913
  if (caps)
98472
98914
  env["LOKI_E10_STOP_RULES"] = JSON.stringify(caps);
98473
98915
  else
@@ -98495,17 +98937,17 @@ function recordCost(cfg, opts, status, durationS, outText = "") {
98495
98937
  const ownRoot = join157(opts.cwd ?? process.cwd(), ".loki");
98496
98938
  const own = resultCostPath(ownRoot, opts.iterationId), dest = resultCostPath(cfg.lokiRoot, opts.iterationId);
98497
98939
  if (own !== dest && existsSync112(own)) {
98498
- mkdirSync85(dirname67(dest), { recursive: true });
98940
+ mkdirSync86(dirname68(dest), { recursive: true });
98499
98941
  copyFileSync11(own, dest);
98500
98942
  }
98501
98943
  const ownPartial = partialUsagePath(ownRoot, opts.iterationId), destPartial = partialUsagePath(cfg.lokiRoot, opts.iterationId);
98502
98944
  if (ownPartial !== destPartial && existsSync112(ownPartial)) {
98503
- mkdirSync85(dirname67(destPartial), { recursive: true });
98945
+ mkdirSync86(dirname68(destPartial), { recursive: true });
98504
98946
  copyFileSync11(ownPartial, destPartial);
98505
98947
  }
98506
98948
  const model = opts.model ?? cfg.model ?? resolveModel(cfg.provider);
98507
98949
  if (process.env["LOKI_E10_INVOKER"] === "cli" && cfg.provider === "claude" && status !== "killed" && !existsSync112(dest)) {
98508
- mkdirSync85(dirname67(dest), { recursive: true });
98950
+ mkdirSync86(dirname68(dest), { recursive: true });
98509
98951
  writeFileSync84(dest, JSON.stringify({ total_cost_usd: 0, input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_creation_tokens: 0, model, source: UNMETERED }));
98510
98952
  }
98511
98953
  const pcost = existsSync112(dest) ? null : writeProviderCost(dest, cfg.provider, model, opts.brief, outText);
@@ -98915,21 +99357,21 @@ var init_model_downgrades = __esm(() => {
98915
99357
  });
98916
99358
 
98917
99359
  // ../../loki-ts/src/util/run_shape.ts
98918
- import { existsSync as existsSync114, mkdirSync as mkdirSync86, writeFileSync as writeFileSync85 } from "fs";
99360
+ import { existsSync as existsSync114, mkdirSync as mkdirSync87, writeFileSync as writeFileSync85 } from "fs";
98919
99361
  import { join as join159 } from "path";
98920
99362
  function recordRunShape(runDir, model) {
98921
99363
  try {
98922
99364
  const p = join159(runDir, "project-model.answer.json");
98923
99365
  if (existsSync114(p))
98924
99366
  return;
98925
- mkdirSync86(runDir, { recursive: true });
99367
+ mkdirSync87(runDir, { recursive: true });
98926
99368
  writeFileSync85(p, JSON.stringify(model));
98927
99369
  } catch {}
98928
99370
  }
98929
99371
  var init_run_shape = () => {};
98930
99372
 
98931
99373
  // ../../loki-ts/src/project_model/discover.ts
98932
- import { existsSync as existsSync115, mkdirSync as mkdirSync87, readFileSync as readFileSync147, rmSync as rmSync52, writeFileSync as writeFileSync86 } from "fs";
99374
+ import { existsSync as existsSync115, mkdirSync as mkdirSync88, readFileSync as readFileSync147, rmSync as rmSync52, writeFileSync as writeFileSync86 } from "fs";
98933
99375
  import { join as join160 } from "path";
98934
99376
  function projectModelEnabled(env = process.env) {
98935
99377
  return env["LOKI_E10_PROJECT_MODEL"] !== "0";
@@ -98985,7 +99427,7 @@ function saveShared(repoDir, model) {
98985
99427
  function save3(repoDir, model) {
98986
99428
  if (isGitTracked(repoDir, PROJECT_FILE))
98987
99429
  return;
98988
- mkdirSync87(join160(repoDir, ".loki"), { recursive: true });
99430
+ mkdirSync88(join160(repoDir, ".loki"), { recursive: true });
98989
99431
  writeFileSync86(join160(repoDir, PROJECT_FILE), `${JSON.stringify(model, null, 2)}
98990
99432
  `);
98991
99433
  }
@@ -99078,7 +99520,7 @@ async function discoverProjectModel(ctx, signal, opts = {}) {
99078
99520
  }
99079
99521
  const deadline = Date.now() + (opts.budgetS ?? Infinity) * 1000;
99080
99522
  const g10 = gather(ctx.repoDir);
99081
- mkdirSync87(ctx.runDir, { recursive: true });
99523
+ mkdirSync88(ctx.runDir, { recursive: true });
99082
99524
  const answerPath = join160(ctx.runDir, "project-model.answer.json");
99083
99525
  let errors2 = null;
99084
99526
  let lastModel;
@@ -99297,9 +99739,9 @@ var init_python_build_check = __esm(() => {
99297
99739
  // ../../loki-ts/src/util/check_result.ts
99298
99740
  import { spawn as spawn13, spawnSync as spawnSync27 } from "child_process";
99299
99741
  import { createHash as createHash38 } from "crypto";
99300
- import { copyFileSync as copyFileSync12, existsSync as existsSync116, lstatSync as lstatSync35, mkdirSync as mkdirSync88, readlinkSync as readlinkSync10, mkdtempSync as mkdtempSync27, readdirSync as readdirSync54, readFileSync as readFileSync148, realpathSync as realpathSync46, renameSync as renameSync28, rmSync as rmSync53, statSync as statSync48, writeFileSync as writeFileSync87 } from "fs";
99742
+ import { copyFileSync as copyFileSync12, existsSync as existsSync116, lstatSync as lstatSync35, mkdirSync as mkdirSync89, readlinkSync as readlinkSync10, mkdtempSync as mkdtempSync27, readdirSync as readdirSync54, readFileSync as readFileSync148, realpathSync as realpathSync47, renameSync as renameSync28, rmSync as rmSync53, statSync as statSync49, writeFileSync as writeFileSync87 } from "fs";
99301
99743
  import { homedir as homedir15, tmpdir as tmpdir34 } from "os";
99302
- import { basename as basename46, dirname as dirname68, isAbsolute as isAbsolute25, join as join162, normalize as normalize9, relative as relative35, resolve as resolve43, sep as sep27 } from "path";
99744
+ import { basename as basename46, dirname as dirname69, isAbsolute as isAbsolute25, join as join162, normalize as normalize9, relative as relative35, resolve as resolve43, sep as sep27 } from "path";
99303
99745
  function plainTestEnv(base2 = process.env) {
99304
99746
  const e10 = {};
99305
99747
  for (const [k10, v10] of Object.entries(tokenFreeEnv(base2)))
@@ -99461,7 +99903,7 @@ function plannedGoDir(repoDir, texts) {
99461
99903
  for (const t of texts)
99462
99904
  for (const sentence of t.split(/(?<=[.!?])\s+|\n+/))
99463
99905
  for (const m of sentence.matchAll(GO_SRC)) {
99464
- const stem2 = goRel(m[1]), rel = dirname68(`${stem2}.go`), base2 = stem2.split("/").pop();
99906
+ const stem2 = goRel(m[1]), rel = dirname69(`${stem2}.go`), base2 = stem2.split("/").pop();
99465
99907
  if (stem2.endsWith("_test") || base2.startsWith("_") || base2.startsWith(".") || rel !== "." && goIgnoredPath(rel))
99466
99908
  continue;
99467
99909
  const dir = join162(repoDir, rel === "." ? "" : rel);
@@ -99713,7 +100155,7 @@ function cargoRunnerConfigured(cwd, env, toks2) {
99713
100155
  return true;
99714
100156
  }
99715
100157
  const dirs = [env["CARGO_HOME"] ?? join162(env["HOME"] ?? homedir15(), ".cargo"), join162(homedir15(), ".cargo")];
99716
- for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname68(d))
100158
+ for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname69(d))
99717
100159
  dirs.push(join162(d, ".cargo"));
99718
100160
  return dirs.some((dir) => ["config", "config.toml"].some((f) => existsSync116(join162(dir, f)) && doubtful(join162(dir, f))));
99719
100161
  }
@@ -99732,7 +100174,7 @@ function cargoToolchainRedirected(cwd, env) {
99732
100174
  return true;
99733
100175
  }
99734
100176
  };
99735
- for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname68(d))
100177
+ for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname69(d))
99736
100178
  if (["rust-toolchain", "rust-toolchain.toml"].some((f) => lstatOk(join162(d, f)) && doubtful(join162(d, f))))
99737
100179
  return true;
99738
100180
  return false;
@@ -99801,7 +100243,7 @@ function compilerSettingIn(raw2) {
99801
100243
  }
99802
100244
  function cargoRepoRoot(cwd) {
99803
100245
  let top = null;
99804
- for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname68(d)) {
100246
+ for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname69(d)) {
99805
100247
  if (existsSync116(join162(d, ".git")))
99806
100248
  return d;
99807
100249
  if (existsSync116(join162(d, "Cargo.toml")))
@@ -99856,7 +100298,7 @@ function cargoProfileRustflagsManifest(root, cwd, toks2) {
99856
100298
  }
99857
100299
  };
99858
100300
  const seen = new Set, files = [];
99859
- for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname68(d)) {
100301
+ for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname69(d)) {
99860
100302
  files.push(join162(d, "Cargo.toml"));
99861
100303
  if (d === root)
99862
100304
  break;
@@ -99914,10 +100356,10 @@ function cargoRepoCompilerRedirected(cwd, env, toks2) {
99914
100356
  }
99915
100357
  const home = new Set([resolve43(env["CARGO_HOME"] || join162(env["HOME"] || homedir15(), ".cargo")), resolve43(homedir15(), ".cargo")]);
99916
100358
  const aboveRoot = (dir) => {
99917
- const r = relative35(dirname68(dir), root);
100359
+ const r = relative35(dirname69(dir), root);
99918
100360
  return r !== "" && !r.startsWith("..") && !isAbsolute25(r);
99919
100361
  };
99920
- for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname68(d)) {
100362
+ for (let d = resolve43(cwd), prev = "";d !== prev; prev = d, d = dirname69(d)) {
99921
100363
  const dir = join162(d, ".cargo");
99922
100364
  if (home.has(dir) && aboveRoot(dir))
99923
100365
  continue;
@@ -100743,7 +101185,7 @@ function wallPathProblem(repoDir, relPath) {
100743
101185
  if (isAbsolute25(rel) || rel.split(sep27).includes(".."))
100744
101186
  return `Wall path outside the repo: ${relPath}`;
100745
101187
  let cur = repoDir;
100746
- for (const part of dirname68(rel) === "." ? [] : dirname68(rel).split(sep27)) {
101188
+ for (const part of dirname69(rel) === "." ? [] : dirname69(rel).split(sep27)) {
100747
101189
  cur = join162(cur, part);
100748
101190
  try {
100749
101191
  const st2 = lstatSync35(cur);
@@ -100827,9 +101269,9 @@ function sparseExcluded(repoDir, tmp, paths) {
100827
101269
  return new Set;
100828
101270
  const rel = safeGit(repoDir, ["rev-parse", "--git-path", "info/sparse-checkout"]).trim(), pf2 = isAbsolute25(rel) ? rel : join162(repoDir, rel);
100829
101271
  const scratch = join162(tmp, "sparse");
100830
- mkdirSync88(scratch);
101272
+ mkdirSync89(scratch);
100831
101273
  safeGit(scratch, ["init", "-q"]);
100832
- mkdirSync88(join162(scratch, ".git", "info"), { recursive: true });
101274
+ mkdirSync89(join162(scratch, ".git", "info"), { recursive: true });
100833
101275
  copyFileSync12(pf2, join162(scratch, ".git", "info", "exclude"));
100834
101276
  const r = safeGitSpawn(scratch, ["-c", "core.ignorecase=false", "-c", "core.excludesFile=/dev/null", "check-ignore", "--no-index", "-z", "--stdin"], { input: Buffer.from(paths.map((p) => `${p}\x00`).join("")) });
100835
101277
  if (r.error || r.status !== 0 && r.status !== 1)
@@ -100845,7 +101287,7 @@ function hiddenEdits(repoDir) {
100845
101287
  try {
100846
101288
  const idxRel = safeGit(repoDir, ["rev-parse", "--git-path", "index"]).trim(), idx = isAbsolute25(idxRel) ? idxRel : join162(repoDir, idxRel);
100847
101289
  const flags = new Map;
100848
- for (const l of safeGit(repoDir, ["-c", "core.quotePath=false", "ls-files", "-v", "-z"], { maxBuffer: Math.max(64 << 20, statSync48(idx).size * 32) }).split("\x00")) {
101290
+ for (const l of safeGit(repoDir, ["-c", "core.quotePath=false", "ls-files", "-v", "-z"], { maxBuffer: Math.max(64 << 20, statSync49(idx).size * 32) }).split("\x00")) {
100849
101291
  const m = /^([a-zS]) ([\s\S]+)$/.exec(l);
100850
101292
  if (m)
100851
101293
  flags.set(m[2], m[1]);
@@ -100890,10 +101332,10 @@ function execFiles(repoDir) {
100890
101332
  } catch {
100891
101333
  return null;
100892
101334
  }
100893
- const roots = new Set([".venv", "venv", ...all.filter((f) => basename46(f) === "pyvenv.cfg").map((f) => dirname68(f))]);
101335
+ const roots = new Set([".venv", "venv", ...all.filter((f) => basename46(f) === "pyvenv.cfg").map((f) => dirname69(f))]);
100894
101336
  const inVenvBin = (f) => {
100895
- for (let d = dirname68(f);d !== "." && d !== "/"; d = dirname68(d))
100896
- if ((basename46(d) === "bin" || basename46(d) === "Scripts") && roots.has(dirname68(d)))
101337
+ for (let d = dirname69(f);d !== "." && d !== "/"; d = dirname69(d))
101338
+ if ((basename46(d) === "bin" || basename46(d) === "Scripts") && roots.has(dirname69(d)))
100897
101339
  return true;
100898
101340
  return false;
100899
101341
  };
@@ -100962,7 +101404,7 @@ function pureToolCache(repoDir, dir) {
100962
101404
  return false;
100963
101405
  continue;
100964
101406
  }
100965
- if (!e10.isFile() || CACHE_CODE_EXT.test(e10.name) || (EXEC_NAMES.has(e10.name) || /^(conftest|sitecustomize|usercustomize)\./.test(e10.name)) && e10.name !== ".gitignore" || /^python/i.test(e10.name) || (statSync48(join162(repoDir, r)).mode & 73) !== 0)
101407
+ if (!e10.isFile() || CACHE_CODE_EXT.test(e10.name) || (EXEC_NAMES.has(e10.name) || /^(conftest|sitecustomize|usercustomize)\./.test(e10.name)) && e10.name !== ".gitignore" || /^python/i.test(e10.name) || (statSync49(join162(repoDir, r)).mode & 73) !== 0)
100966
101408
  return false;
100967
101409
  }
100968
101410
  return true;
@@ -100995,7 +101437,7 @@ function ignoreRuleChanges(repoDir, snap, baseSha) {
100995
101437
  for (const [f, h10] of Object.entries(cur)) {
100996
101438
  if (prior[f] === h10)
100997
101439
  continue;
100998
- if (basename46(f) === ".gitignore" && pureToolCache(repoDir, dirname68(f)))
101440
+ if (basename46(f) === ".gitignore" && pureToolCache(repoDir, dirname69(f)))
100999
101441
  continue;
101000
101442
  if (basename46(f) === ".gitignore")
101001
101443
  gi2.add(f);
@@ -101010,7 +101452,7 @@ function ignoreRuleChanges(repoDir, snap, baseSha) {
101010
101452
  return [];
101011
101453
  const made = listIgnoredFiles(repoDir).filter((f) => {
101012
101454
  try {
101013
- const st2 = statSync48(join162(repoDir, f));
101455
+ const st2 = statSync49(join162(repoDir, f));
101014
101456
  return Math.max(st2.birthtimeMs, st2.mtimeMs) >= s.at;
101015
101457
  } catch {
101016
101458
  return false;
@@ -101094,7 +101536,7 @@ function diffFiles(repoDir, baseSha, skip2) {
101094
101536
  function recordRisk(repoDir, a) {
101095
101537
  try {
101096
101538
  const dir = join162(repoDir, ".loki", "state"), p = join162(dir, "risk-tier.json");
101097
- mkdirSync88(dir, { recursive: true });
101539
+ mkdirSync89(dir, { recursive: true });
101098
101540
  writeFileSync87(`${p}.tmp`, JSON.stringify(a, null, 2) + `
101099
101541
  `);
101100
101542
  renameSync28(`${p}.tmp`, p);
@@ -101151,7 +101593,7 @@ function pytestCollectionIsRed(output, repoDir) {
101151
101593
  return moduleToBeCreated(output, repoDir);
101152
101594
  const real4 = (p) => {
101153
101595
  try {
101154
- return realpathSync46(isAbsolute25(p) ? p : join162(repoDir, p));
101596
+ return realpathSync47(isAbsolute25(p) ? p : join162(repoDir, p));
101155
101597
  } catch {
101156
101598
  return null;
101157
101599
  }
@@ -101346,11 +101788,11 @@ function missingRelativeImportIsRed(f, raw2, repoDir) {
101346
101788
  return hits.every(({ spec, importer }) => {
101347
101789
  if (!/^\.\.?(?:\/|$)/.test(spec) || !(abs === importer || abs.endsWith("/" + importer.replace(/^\.\//, "")) || importer.endsWith("/" + f.path) || importer === f.path))
101348
101790
  return false;
101349
- const target = resolve43(dirname68(abs), spec.replace(/[?#].*$/, ""));
101791
+ const target = resolve43(dirname69(abs), spec.replace(/[?#].*$/, ""));
101350
101792
  const stem2 = target.replace(/\.(?:jsx?|mjs|cjs)$/, "");
101351
- if (existsSync116(target) && statSync48(target).isDirectory())
101793
+ if (existsSync116(target) && statSync49(target).isDirectory())
101352
101794
  return false;
101353
- return ![target, stem2].some((t) => ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".json"].some((x10) => existsSync116(t + x10) && statSync48(t + x10).isFile())) && !["ts", "tsx", "js", "jsx", "mjs", "cjs"].some((x10) => existsSync116(join162(target, `index.${x10}`)));
101795
+ return ![target, stem2].some((t) => ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".json"].some((x10) => existsSync116(t + x10) && statSync49(t + x10).isFile())) && !["ts", "tsx", "js", "jsx", "mjs", "cjs"].some((x10) => existsSync116(join162(target, `index.${x10}`)));
101354
101796
  });
101355
101797
  }
101356
101798
  function classify(f, status, output, repoDir, interpreter) {
@@ -101686,7 +102128,7 @@ function toolFallbacks(repoDir, tool, env = process.env) {
101686
102128
  function resolveTool(repoDir, bin, fallback, lastResort = fallback) {
101687
102129
  const inRepo2 = (p) => {
101688
102130
  try {
101689
- const r = relative35(realpathSync46(repoDir), realpathSync46(p));
102131
+ const r = relative35(realpathSync47(repoDir), realpathSync47(p));
101690
102132
  return r !== "" && !r.startsWith("..") && !isAbsolute25(r);
101691
102133
  } catch {
101692
102134
  return false;
@@ -101732,7 +102174,7 @@ function runnerCmd(t, repoDir) {
101732
102174
  return ["npm", ["test", "--silent"]];
101733
102175
  case "go": {
101734
102176
  const names = goTestNames(join162(repoDir, t.path));
101735
- return ["go", ["test", "-json", ...names.length ? ["-run", `^(${names.join("|")})$`] : [], `./${dirname68(t.path)}`]];
102177
+ return ["go", ["test", "-json", ...names.length ? ["-run", `^(${names.join("|")})$`] : [], `./${dirname69(t.path)}`]];
101736
102178
  }
101737
102179
  case "maven": {
101738
102180
  const j10 = javaTestClass(t.path);
@@ -101769,7 +102211,7 @@ function fullSuiteCmd(runner, repoDir) {
101769
102211
  }
101770
102212
  function ownVitestSite(repoDir, path) {
101771
102213
  const cfg = /^vite(st)?\.config\.(?:[cm]?[jt]s|mts)$/;
101772
- for (let d = dirname68(path);d !== "." && d !== "" && d !== "/" && !d.startsWith(".."); d = dirname68(d)) {
102214
+ for (let d = dirname69(path);d !== "." && d !== "" && d !== "/" && !d.startsWith(".."); d = dirname69(d)) {
101773
102215
  try {
101774
102216
  const abs = join162(repoDir, d);
101775
102217
  if (!existsSync116(join162(abs, "package.json")))
@@ -101804,11 +102246,11 @@ function commandFor(t, repoDir, api) {
101804
102246
  return { cwd: mod === base2 ? base2 : mod, cmd: cmd2, args, argv: [cmd2, ...args], ...interpreter ? { interpreter } : {}, pkgRoot: mod === base2 ? site?.root ?? "." : relative35(repoDir, mod) || "." };
101805
102247
  }
101806
102248
  function goModDir(base2, rel) {
101807
- let d = dirname68(join162(base2, rel));
102249
+ let d = dirname69(join162(base2, rel));
101808
102250
  while (d !== base2 && relative35(base2, d) !== "" && !relative35(base2, d).startsWith("..")) {
101809
102251
  if (existsSync116(join162(d, "go.mod")))
101810
102252
  return d;
101811
- d = dirname68(d);
102253
+ d = dirname69(d);
101812
102254
  }
101813
102255
  return base2;
101814
102256
  }
@@ -101943,11 +102385,11 @@ async function publishWall(git15, runId2, repoDir, files, done) {
101943
102385
  for (const f of files) {
101944
102386
  const abs = join162(repoDir, f.rel);
101945
102387
  try {
101946
- if (!realpathSync46(dirname68(abs)).startsWith(realpathSync46(repoDir)))
102388
+ if (!realpathSync47(dirname69(abs)).startsWith(realpathSync47(repoDir)))
101947
102389
  return false;
101948
102390
  } catch {}
101949
102391
  rmSync53(abs, { force: true });
101950
- mkdirSync88(dirname68(abs), { recursive: true });
102392
+ mkdirSync89(dirname69(abs), { recursive: true });
101951
102393
  writeFileSync87(abs, f.bytes);
101952
102394
  }
101953
102395
  if ((await git15(["--literal-pathspecs", "add", "--", ...rels])).code !== 0 || (await git15(["--literal-pathspecs", "commit", "-q", "-m", "test: loki acceptance checks (Wall)", "-m", `Loki-Wall-Publish: ${runId2}
@@ -102211,8 +102653,8 @@ var init_check_result = __esm(() => {
102211
102653
  });
102212
102654
 
102213
102655
  // ../../loki-ts/src/council/finding_schema.ts
102214
- import { existsSync as existsSync117, readdirSync as readdirSync55, readFileSync as readFileSync149, statSync as statSync49 } from "fs";
102215
- import { resolve as resolvePath3, dirname as dirname69, relative as relative36, isAbsolute as isAbsolute26, join as join163, sep as sep28 } from "path";
102656
+ import { existsSync as existsSync117, readdirSync as readdirSync55, readFileSync as readFileSync149, statSync as statSync50 } from "fs";
102657
+ import { resolve as resolvePath3, dirname as dirname70, relative as relative36, isAbsolute as isAbsolute26, join as join163, sep as sep28 } from "path";
102216
102658
  import { fileURLToPath as fileURLToPath6 } from "url";
102217
102659
  function resolveSchemaDataDir(moduleDir = _moduleDir, candidates2 = SCHEMA_DATA_DIR_CANDIDATES) {
102218
102660
  for (const rel of candidates2) {
@@ -102289,7 +102731,7 @@ function isRecord(v10) {
102289
102731
  var _moduleDir, SCHEMA_DATA_DIR_CANDIDATES, _dataDir, _schemaPath, FINDING_SCHEMA, SchemaLiteralError, _static = null, VOTE_ENUM, SEVERITY_ENUM, BLOCKING_SEVERITY, ANCHOR_EXEMPT_ROLES, MAX_CITATION_FILE_BYTES, SKIP_DIRS5, treeFiles;
102290
102732
  var init_finding_schema = __esm(() => {
102291
102733
  init_check_result();
102292
- _moduleDir = dirname69(fileURLToPath6(import.meta.url));
102734
+ _moduleDir = dirname70(fileURLToPath6(import.meta.url));
102293
102735
  SCHEMA_DATA_DIR_CANDIDATES = [["..", "..", "data"], ["..", "data"], ["..", "..", "..", "loki-ts", "data"]];
102294
102736
  _dataDir = resolveSchemaDataDir();
102295
102737
  _schemaPath = resolvePath3(_dataDir, "finding-schema.json");
@@ -109149,10 +109591,10 @@ async function setupSkills(ctx) {
109149
109591
  for (const skill of session.agent.skills) {
109150
109592
  try {
109151
109593
  const version2 = await client.beta.skills.versions.retrieve(skill.version, { skill_id: skill.skill_id });
109152
- let dirname70 = path2.basename(version2.name.trim());
109153
- if (dirname70 === "" || dirname70 === "." || dirname70 === "..")
109154
- dirname70 = skill.skill_id;
109155
- const dest = path2.resolve(skillsRoot, dirname70);
109594
+ let dirname71 = path2.basename(version2.name.trim());
109595
+ if (dirname71 === "" || dirname71 === "." || dirname71 === "..")
109596
+ dirname71 = skill.skill_id;
109597
+ const dest = path2.resolve(skillsRoot, dirname71);
109156
109598
  if (dest !== skillsRoot && !dest.startsWith(skillsRoot + path2.sep)) {
109157
109599
  log2.warn("skill name escapes the skills dir; skipping", {
109158
109600
  component: "agent-tool-context",
@@ -125392,7 +125834,7 @@ __export(exports_opus_consult, {
125392
125834
  CONSULT_MODEL_DEFAULT: () => CONSULT_MODEL_DEFAULT,
125393
125835
  CONSULT_FILE: () => CONSULT_FILE
125394
125836
  });
125395
- import { mkdirSync as mkdirSync89, readFileSync as readFileSync151, writeFileSync as writeFileSync88 } from "fs";
125837
+ import { mkdirSync as mkdirSync90, readFileSync as readFileSync151, writeFileSync as writeFileSync88 } from "fs";
125396
125838
  import { join as join165 } from "path";
125397
125839
  function readConsults(runDir) {
125398
125840
  try {
@@ -125440,7 +125882,7 @@ async function runConsult(o, env2 = process.env) {
125440
125882
  const prior = readConsults(o.runDir), slot = { trigger: o.trigger, stage: o.stage, model, outcome: "started", usd: null, advice: null };
125441
125883
  const save4 = (xs2) => {
125442
125884
  try {
125443
- mkdirSync89(o.runDir, { recursive: true });
125885
+ mkdirSync90(o.runDir, { recursive: true });
125444
125886
  writeFileSync88(join165(o.runDir, CONSULT_FILE), JSON.stringify(xs2), "utf8");
125445
125887
  } catch {}
125446
125888
  };
@@ -125485,9 +125927,9 @@ var init_opus_consult = __esm(() => {
125485
125927
  // ../../loki-ts/src/util/conflict_resume.ts
125486
125928
  import { createHash as createHash39 } from "crypto";
125487
125929
  import { execFileSync as execFileSync14 } from "child_process";
125488
- import { chmodSync as chmodSync9, existsSync as existsSync118, mkdirSync as mkdirSync90, mkdtempSync as mkdtempSync28, readdirSync as readdirSync56, readFileSync as readFileSync152, rmSync as rmSync54, statSync as statSync50, symlinkSync as symlinkSync7, writeFileSync as writeFileSync89 } from "fs";
125930
+ import { chmodSync as chmodSync9, existsSync as existsSync118, mkdirSync as mkdirSync91, mkdtempSync as mkdtempSync28, readdirSync as readdirSync56, readFileSync as readFileSync152, rmSync as rmSync54, statSync as statSync51, symlinkSync as symlinkSync7, writeFileSync as writeFileSync89 } from "fs";
125489
125931
  import { tmpdir as tmpdir36 } from "os";
125490
- import { basename as basename47, dirname as dirname71, isAbsolute as isAbsolute28, join as join166, relative as relative37 } from "path";
125932
+ import { basename as basename47, dirname as dirname72, isAbsolute as isAbsolute28, join as join166, relative as relative37 } from "path";
125491
125933
  function answerMark(events2, assumeNext = false) {
125492
125934
  if (assumeNext)
125493
125935
  return events2.length;
@@ -125603,6 +126045,7 @@ function citesTestFile(text4) {
125603
126045
  async function resumeToFinish(ctx, first, session, o) {
125604
126046
  const env2 = o.env ?? process.env, ids = [], max = continueMax(env2), usdLine = continueMaxUsd(env2);
125605
126047
  const missing = () => readPlanScope(ctx.runDir).filter((f) => !existsSync118(join166(ctx.repoDir, f)));
126048
+ let unchanged = 0;
125606
126049
  let cur = session, outstanding = outstandingOf(session.summary), base2 = first, ended = max === 0 ? "continue off" : "count cap", spent = null;
125607
126050
  for (let n10 = 1;n10 <= max; n10++) {
125608
126051
  if (o.signal.aborted) {
@@ -125639,9 +126082,12 @@ async function resumeToFinish(ctx, first, session, o) {
125639
126082
  break;
125640
126083
  }
125641
126084
  if (before === after) {
125642
- ended = "tree unchanged";
125643
- break;
125644
- }
126085
+ if (++unchanged >= 2) {
126086
+ ended = "tree unchanged";
126087
+ break;
126088
+ }
126089
+ } else
126090
+ unchanged = 0;
125645
126091
  }
125646
126092
  return { session: cur, iterationIds: ids, record: { continues: ids.length, ended, outstanding: outstanding || null, spent_usd: spent ?? o.spentUsd() } };
125647
126093
  }
@@ -125898,7 +126344,7 @@ async function adjudicateWallConflict(ctx, first, firstSession, wall, deps = {})
125898
126344
  declined("no copy of the base tree could be made, so red-on-base was not run");
125899
126345
  return null;
125900
126346
  }
125901
- mkdirSync90(dirname71(join166(base2, a.file)), { recursive: true });
126347
+ mkdirSync91(dirname72(join166(base2, a.file)), { recursive: true });
125902
126348
  writeFileSync89(join166(base2, a.file), next, "utf8");
125903
126349
  const onBase = runCheck2(base2, ref);
125904
126350
  if (onBase !== "fail") {
@@ -125908,7 +126354,7 @@ async function adjudicateWallConflict(ctx, first, firstSession, wall, deps = {})
125908
126354
  }
125909
126355
  f.content = next;
125910
126356
  const sealedCopy = join166(sealedWallDir(ctx.runDir), name);
125911
- if (existsSync118(dirname71(sealedCopy)))
126357
+ if (existsSync118(dirname72(sealedCopy)))
125912
126358
  writeFileSync89(sealedCopy, next, "utf8");
125913
126359
  sf2.sha256 = createHash39("sha256").update(next).digest("hex");
125914
126360
  const sealedNow = existsSync118(sealedCopy) ? readFileSync152(sealedCopy, "utf8") : null;
@@ -125980,7 +126426,7 @@ async function legacyReauthor(ctx, first, firstSession, f, a, reason, task) {
125980
126426
  const sf2 = o.wall?.files?.find((x10) => x10.path === f.path), sha6 = createHash39("sha256").update(next).digest("hex");
125981
126427
  if (sf2)
125982
126428
  sf2.sha256 = sha6;
125983
- mkdirSync90(sealedWallDir(ctx.runDir), { recursive: true });
126429
+ mkdirSync91(sealedWallDir(ctx.runDir), { recursive: true });
125984
126430
  writeFileSync89(sealedWallCopy(ctx.runDir, f.path), next, "utf8");
125985
126431
  const arb = { check: a.file, test: "(whole file)", old_assertion: "(not validated)", new_assertion: "(not validated)", spec_quote: oneLine6(reason), spec_quote_2: "", sha256: sha6, kind: "legacy" };
125986
126432
  if (o.wall)
@@ -126048,7 +126494,7 @@ async function deliverOverWallConflict(o, repoDir, reverify, emit2, opts = {}) {
126048
126494
  }
126049
126495
  }, modeOf = (p) => {
126050
126496
  try {
126051
- return statSync50(p).mode & 4095;
126497
+ return statSync51(p).mode & 4095;
126052
126498
  } catch {
126053
126499
  return null;
126054
126500
  }
@@ -126135,7 +126581,7 @@ async function resumeForPrecedence(ctx, first, firstSession, env2 = process.env)
126135
126581
  return none;
126136
126582
  const sameDir = (p) => {
126137
126583
  try {
126138
- const d = dirname71(p);
126584
+ const d = dirname72(p);
126139
126585
  return readdirSync56(join166(ctx.repoDir, d)).slice(0, 60).map((f) => d === "." ? f : `${d}/${f}`);
126140
126586
  } catch {
126141
126587
  return [];
@@ -126315,7 +126761,7 @@ __export(exports_run_outputs, {
126315
126761
  });
126316
126762
  import { execFile as execFile3, spawnSync as spawnSync28 } from "child_process";
126317
126763
  import { createHash as createHash40 } from "crypto";
126318
- import { existsSync as existsSync119, lstatSync as lstatSync36, mkdirSync as mkdirSync91, readdirSync as readdirSync57, readFileSync as readFileSync153, statSync as statSync51, writeFileSync as writeFileSync90 } from "fs";
126764
+ import { existsSync as existsSync119, lstatSync as lstatSync36, mkdirSync as mkdirSync92, readdirSync as readdirSync57, readFileSync as readFileSync153, statSync as statSync52, writeFileSync as writeFileSync90 } from "fs";
126319
126765
  import { basename as basename48, join as join167, resolve as resolve45 } from "path";
126320
126766
  function intentRevisionsBlock(revs) {
126321
126767
  const r = (revs ?? []).filter((r10) => r10.unapplied !== true).map(({ rev, source, actor, sha: sha6 }) => ({ rev, source, actor, sha: sha6 }));
@@ -126497,7 +126943,7 @@ function findInterrupted(repoDir, runId2, includeCancelled = false, why) {
126497
126943
  } catch {
126498
126944
  return null;
126499
126945
  }
126500
- const rows = ids.filter((id2) => /^e10-[A-Za-z0-9-]+$/.test(id2) && existsSync119(join167(repoDir, eventsRelPath(id2)))).map((id2) => ({ id: id2, m: statSync51(join167(repoDir, eventsRelPath(id2))).mtimeMs })).sort((a, b) => b.m - a.m);
126946
+ const rows = ids.filter((id2) => /^e10-[A-Za-z0-9-]+$/.test(id2) && existsSync119(join167(repoDir, eventsRelPath(id2)))).map((id2) => ({ id: id2, m: statSync52(join167(repoDir, eventsRelPath(id2))).mtimeMs })).sort((a, b) => b.m - a.m);
126501
126947
  const top = rows[0];
126502
126948
  if (!top)
126503
126949
  return null;
@@ -127147,7 +127593,7 @@ function issueStatusProjector(o) {
127147
127593
  const body = issueStatusBody(events2, { runId: o.runId, steerRevs: revs, controlUrl: controlRunLink(o.env.LOKI_CONTROL_PLANE_URL || o.env.LOKI_CONTROL_URL, o.repoDir, o.runId), ...x10 }), bodyFile = join167(o.runDir, "status-comment.md"), argv = argvOf(bodyFile);
127148
127594
  if (body === last)
127149
127595
  return { argv, ok: true };
127150
- mkdirSync91(o.runDir, { recursive: true });
127596
+ mkdirSync92(o.runDir, { recursive: true });
127151
127597
  writeFileSync90(bodyFile, body);
127152
127598
  const [ok2, skipped3] = await new Promise((res) => {
127153
127599
  execFile3("bash", [o.pushSh, ...argv], { env: env2 }, (err, out3) => res([!err, /^skipped: /m.test(String(out3))]));
@@ -127282,7 +127728,7 @@ async function sealRefusal(o) {
127282
127728
  const [{ SupervisorLog: SupervisorLog2 }, seal, signer, { atomicWriteText: atomicWriteText2 }, { githubRepoFromUrl: githubRepoFromUrl2 }] = await Promise.all([Promise.resolve().then(() => (init_supervisor(), exports_supervisor)), Promise.resolve().then(() => (init_seal(), exports_seal)), Promise.resolve().then(() => (init_receipt_signer(), exports_receipt_signer)), Promise.resolve().then(() => (init_atomic(), exports_atomic)), Promise.resolve().then(() => (init_engine_origin(), exports_engine_origin))]);
127283
127729
  const runId2 = `e10-${new Date().toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z")}-${Math.random().toString(16).slice(2, 6)}`;
127284
127730
  const runDir = join167(o.repoDir, ".loki", "runs", runId2), provider = o.provider ?? "claude", repo = githubRepoFromUrl2(readOriginUrl(o.repoDir));
127285
- mkdirSync91(runDir, { recursive: true });
127731
+ mkdirSync92(runDir, { recursive: true });
127286
127732
  const log2 = new SupervisorLog2(join167(o.repoDir, eventsRelPath(runId2)), runId2);
127287
127733
  log2.append("run.started", null, { task_source: "text", provider, refused: true, origin_repo: repo });
127288
127734
  const git15 = (a) => {
@@ -127396,7 +127842,7 @@ var init_run_outputs = __esm(() => {
127396
127842
 
127397
127843
  // ../../loki-ts/src/util/composite_seal.ts
127398
127844
  import { existsSync as existsSync120, readFileSync as readFileSync154 } from "fs";
127399
- import { basename as basename49, dirname as dirname72, join as join168 } from "path";
127845
+ import { basename as basename49, dirname as dirname73, join as join168 } from "path";
127400
127846
  function logProblem(runDir, integ) {
127401
127847
  if (typeof integ["log_sha256"] !== "string")
127402
127848
  return null;
@@ -127467,7 +127913,7 @@ function composeComposite(runDir, rh, toolchain = collectToolchain()) {
127467
127913
  throw new Error("workspace has no repos");
127468
127914
  return {
127469
127915
  schema: COMPOSITE_SCHEMA,
127470
- workspace: basename49(dirname72(runDir)),
127916
+ workspace: basename49(dirname73(runDir)),
127471
127917
  run_id: basename49(runDir),
127472
127918
  integration_sha256: sha3(ibytes),
127473
127919
  integration: { status: String(integ["status"]), exit_code: typeof integ["exit_code"] === "number" ? integ["exit_code"] : null, log_sha256: typeof integ["log_sha256"] === "string" ? integ["log_sha256"] : null, heads },
@@ -127477,7 +127923,7 @@ function composeComposite(runDir, rh, toolchain = collectToolchain()) {
127477
127923
  };
127478
127924
  }
127479
127925
  async function verifyComposite(receiptPath, receipt, rh, verifyOne, deps = {}) {
127480
- const runDir = dirname72(receiptPath);
127926
+ const runDir = dirname73(receiptPath);
127481
127927
  const signed = isObj10(receipt["verification"]) && typeof receipt["verification"]["jwt"] === "string";
127482
127928
  const bad = (reason) => ({ problem: { verdict: "TAMPERED", reason: `composite: ${reason}` }, verdict: "FAILED" });
127483
127929
  const deep = (what) => ({ problem: { verdict: "UNCHECKED", reason: `composite: ${what} cannot be hashed (nested too deeply)` }, verdict: "FAILED" });
@@ -127595,8 +128041,8 @@ __export(exports_verify_cmd, {
127595
128041
  checkEventLog: () => checkEventLog,
127596
128042
  checkAttestation: () => checkAttestation
127597
128043
  });
127598
- import { existsSync as existsSync121, readFileSync as readFileSync155, renameSync as renameSync29, statSync as statSync52, writeFileSync as writeFileSync91 } from "fs";
127599
- import { basename as basename50, dirname as dirname73, join as join169 } from "path";
128044
+ import { existsSync as existsSync121, readFileSync as readFileSync155, renameSync as renameSync29, statSync as statSync53, writeFileSync as writeFileSync91 } from "fs";
128045
+ import { basename as basename50, dirname as dirname74, join as join169 } from "path";
127600
128046
  import { createHash as createHash41, verify as verify5 } from "crypto";
127601
128047
  function checkAttestation(jwt, expectedHash, given) {
127602
128048
  const bad = (reason) => ({ status: "tampered", reason });
@@ -127621,11 +128067,11 @@ function checkAttestation(jwt, expectedHash, given) {
127621
128067
  }
127622
128068
  function wallTamperProblem(receiptPath, receipt) {
127623
128069
  const wall = receipt["wall"], files = Array.isArray(wall?.files) ? wall.files : [];
127624
- const wallDir = sealedWallDir(dirname73(receiptPath)), haveWallDir = existsSync121(wallDir);
128070
+ const wallDir = sealedWallDir(dirname74(receiptPath)), haveWallDir = existsSync121(wallDir);
127625
128071
  for (const f of files) {
127626
128072
  if (typeof f?.path !== "string" || typeof f.sha256 !== "string")
127627
128073
  continue;
127628
- const copy = sealedWallCopy(dirname73(receiptPath), f.path);
128074
+ const copy = sealedWallCopy(dirname74(receiptPath), f.path);
127629
128075
  let cur;
127630
128076
  try {
127631
128077
  cur = createHash41("sha256").update(readFileSync155(copy)).digest("hex");
@@ -127655,7 +128101,7 @@ function checkEventLog(receiptPath, receipt) {
127655
128101
  const claims = st2 !== null && typeof st2 === "object" && Object.keys(st2).length > 0;
127656
128102
  return claims ? "the receipt records stages but binds the empty-log hash, so no events.jsonl can back it (missing, empty or non-empty); the receipt is forged or was sealed without a log. Re-run the task to produce a fresh receipt" : null;
127657
128103
  }
127658
- const path4 = join169(dirname73(receiptPath), "events.jsonl");
128104
+ const path4 = join169(dirname74(receiptPath), "events.jsonl");
127659
128105
  if (!existsSync121(path4))
127660
128106
  return "events.jsonl is missing";
127661
128107
  const raw2 = readFileSync155(path4, "utf8"), events2 = readEvents(path4), all = raw2.split(`
@@ -127688,7 +128134,7 @@ function resumeCheckpointOk(events2, done, i) {
127688
128134
  return m > done && isAnsweredResume(events2[m]);
127689
128135
  }
127690
128136
  function checkLogSeal(receiptPath, hash, kid, given) {
127691
- const path4 = join169(dirname73(receiptPath), "events.jsonl"), events2 = readEvents(path4), done = events2.findLastIndex((e10) => e10.type === "run.completed");
128137
+ const path4 = join169(dirname74(receiptPath), "events.jsonl"), events2 = readEvents(path4), done = events2.findLastIndex((e10) => e10.type === "run.completed");
127692
128138
  const rs2 = events2.findIndex((e10) => e10.type === "receipt.sealed" && e10.data["receipt_sha256"] === hash);
127693
128139
  if (rs2 < 0)
127694
128140
  return { verdict: "TAMPERED", reason: "events.jsonl has no receipt.sealed event for this receipt" };
@@ -127913,7 +128359,7 @@ ${/^(unknown option|expected at most one)/.test(pk.error) ? `Usage: loki verify
127913
128359
  if (!runId2)
127914
128360
  return process.stderr.write(`loki verify: no runs found
127915
128361
  `), 66;
127916
- const isFile2 = existsSync121(runId2) && statSync52(runId2).isFile();
128362
+ const isFile2 = existsSync121(runId2) && statSync53(runId2).isFile();
127917
128363
  const isPath = isFile2 || /[\\/]/.test(runId2) || runId2.endsWith(".json");
127918
128364
  const receiptPath = isPath ? runId2 : join169(runsRoot2, runId2, "receipt.json");
127919
128365
  const byRunId = !isPath;
@@ -128059,8 +128505,8 @@ var init_verify_cmd = __esm(() => {
128059
128505
  });
128060
128506
 
128061
128507
  // src/server/app.ts
128062
- import { existsSync as existsSync123, readFileSync as readFileSync158, statSync as statSync53 } from "fs";
128063
- import { join as join172, resolve as resolve46, sep as sep30 } from "path";
128508
+ import { existsSync as existsSync124, readFileSync as readFileSync159, statSync as statSync55 } from "fs";
128509
+ import { join as join173, resolve as resolve47, sep as sep31 } from "path";
128064
128510
 
128065
128511
  // node_modules/hono/dist/request/constants.js
128066
128512
  var GET_MATCH_RESULT = Symbol();
@@ -134545,6 +134991,12 @@ function runDetail(db, sourceId, runId) {
134545
134991
  const done = f.run.completed?.data;
134546
134992
  const sealed = evs.find((e) => e.type === "receipt.sealed")?.data;
134547
134993
  const stop = stopReason(evs, r.verdict);
134994
+ const sealAcc = evs.findLast((e) => e.type === "stage.completed" && e.stage === "seal")?.data;
134995
+ const proofEv = evs.findLast((e) => e.type === "proof.rerun")?.data;
134996
+ const intakeAcc = evs.find((e) => e.type === "stage.completed" && e.stage === "intake")?.data;
134997
+ const accRows = Array.isArray(sealAcc?.issue_acceptance) ? sealAcc.issue_acceptance : Array.isArray(proofEv?.statuses) ? proofEv.statuses : Array.isArray(intakeAcc?.issue_acceptance) ? intakeAcc.issue_acceptance.map((l) => ({ line: String(l), status: "waiting" })) : [];
134998
+ const acceptance = accRows.map((x) => ({ line: String(x.line ?? ""), status: x.status === "met" ? "met" : x.status === "unmet" ? "unmet" : "waiting", checks: typeof x.checks === "number" ? x.checks : 0, reason: typeof x.reason === "string" ? x.reason : null }));
134999
+ const proof = proofEv ? { round: Number(proofEv.round ?? 1), exit: typeof proofEv.exit === "number" ? proofEv.exit : null, proved: Number(proofEv.proved ?? 0), failed: Number(proofEv.failed ?? 0), seconds: Number(proofEv.seconds ?? 0) } : null;
134548
135000
  return {
134549
135001
  ...withLive(db, r),
134550
135002
  blocked_question: blockedQuestion(evs, r.verdict),
@@ -134553,7 +135005,10 @@ function runDetail(db, sourceId, runId) {
134553
135005
  stages,
134554
135006
  stages_completed: f.completed,
134555
135007
  receipt: sealed ? { sha256: str(sealed.receipt_sha256), signed: sealed.signed === true, verdict: str(sealed.verdict), path: str(sealed.path) } : null,
134556
- not_proven: Array.isArray(done?.not_proven) ? done.not_proven : []
135008
+ not_proven: Array.isArray(done?.not_proven) ? done.not_proven : [],
135009
+ acceptance,
135010
+ acceptance_source: (sealAcc?.issue_acceptance_source ?? proofEv?.source) === "plan" ? "plan" : "issue",
135011
+ proof
134557
135012
  };
134558
135013
  }
134559
135014
 
@@ -138511,7 +138966,7 @@ function mount20(ctx) {
138511
138966
  }
138512
138967
 
138513
138968
  // src/server/routes/verify.ts
138514
- import { readFileSync as readFileSync156, realpathSync as realpathSync47 } from "fs";
138969
+ import { readFileSync as readFileSync156, realpathSync as realpathSync48 } from "fs";
138515
138970
  import { createPublicKey as createPublicKey9 } from "crypto";
138516
138971
  import { join as join170, sep as sep29 } from "path";
138517
138972
  init_verify_cmd();
@@ -138540,11 +138995,11 @@ function mount21(ctx) {
138540
138995
  return done(404, "receipt not available", "not_found");
138541
138996
  let runDir, file;
138542
138997
  try {
138543
- const root = realpathSync47(join170(repo.p, ".loki", "runs"));
138544
- runDir = realpathSync47(join170(root, run2));
138998
+ const root = realpathSync48(join170(repo.p, ".loki", "runs"));
138999
+ runDir = realpathSync48(join170(root, run2));
138545
139000
  if (runDir !== join170(root, run2))
138546
139001
  return done(404, "receipt not found", "not_found");
138547
- file = realpathSync47(join170(runDir, "receipt.json"));
139002
+ file = realpathSync48(join170(runDir, "receipt.json"));
138548
139003
  } catch {
138549
139004
  return done(404, "receipt not found", "not_found");
138550
139005
  }
@@ -138597,8 +139052,202 @@ function mount21(ctx) {
138597
139052
  });
138598
139053
  }
138599
139054
 
139055
+ // src/server/routes/workspace.ts
139056
+ import { existsSync as existsSync122, mkdirSync as mkdirSync93, readFileSync as readFileSync157, readdirSync as readdirSync58, renameSync as renameSync30, statSync as statSync54, writeFileSync as writeFileSync92 } from "fs";
139057
+ import { homedir as homedir17, userInfo } from "os";
139058
+ import { dirname as dirname75, join as join171, resolve as resolve46, sep as sep30 } from "path";
139059
+ var ID7 = /^[a-z0-9][a-z0-9-]{0,39}$/;
139060
+ var MAX_BYTES3 = 200000;
139061
+ var workspaceFile = (env2 = process.env) => env2["LOKI_WORKSPACE_FILE"] || join171(homedir17(), ".loki", "control", "workspace.json");
139062
+ var accountName = () => {
139063
+ try {
139064
+ return userInfo().username || "me";
139065
+ } catch {
139066
+ return "me";
139067
+ }
139068
+ };
139069
+ var text4 = (v10, max) => typeof v10 === "string" && v10.trim() !== "" && v10.length <= max ? v10.trim() : null;
139070
+ function parseWorkspace(raw2) {
139071
+ const o = raw2;
139072
+ const name = text4(o?.account?.name, 80);
139073
+ if (!name)
139074
+ return { ok: false, error: "account.name must be 1 to 80 characters" };
139075
+ if (!Array.isArray(o?.orgs) || o.orgs.length === 0 || o.orgs.length > 50)
139076
+ return { ok: false, error: "orgs must hold 1 to 50 entries" };
139077
+ const orgs = [], orgIds = new Set;
139078
+ for (const x10 of o.orgs) {
139079
+ const id2 = text4(x10?.id, 40), nm2 = text4(x10?.name, 80);
139080
+ if (!id2 || !ID7.test(id2) || orgIds.has(id2) || !nm2)
139081
+ return { ok: false, error: "each org needs a unique lowercase id and a name" };
139082
+ orgIds.add(id2);
139083
+ if (!Array.isArray(x10.projects) || x10.projects.length > 200)
139084
+ return { ok: false, error: `org ${id2}: projects must be a list of at most 200` };
139085
+ const projects = [], pIds = new Set;
139086
+ for (const p of x10.projects) {
139087
+ const pid = text4(p?.id, 40), pn2 = text4(p?.name, 80);
139088
+ if (!pid || !ID7.test(pid) || pIds.has(pid) || !pn2)
139089
+ return { ok: false, error: `org ${id2}: each project needs a unique lowercase id and a name` };
139090
+ pIds.add(pid);
139091
+ const repos = Array.isArray(p.repos) ? [...new Set(p.repos.filter((r) => typeof r === "string" && r.length > 0 && r.length <= 200))].slice(0, 500) : [];
139092
+ projects.push({ id: pid, name: pn2, repos });
139093
+ }
139094
+ orgs.push({ id: id2, name: nm2, projects });
139095
+ }
139096
+ return { ok: true, ws: { account: { name }, orgs } };
139097
+ }
139098
+ function loadWorkspace(known, file = workspaceFile()) {
139099
+ try {
139100
+ if (existsSync122(file)) {
139101
+ const p = parseWorkspace(JSON.parse(readFileSync157(file, "utf8")));
139102
+ if (p.ok)
139103
+ return p.ws;
139104
+ }
139105
+ } catch {}
139106
+ return { account: { name: accountName() }, orgs: [{ id: "personal", name: "Personal", projects: [{ id: "default", name: "My project", repos: [...known] }] }] };
139107
+ }
139108
+ function saveWorkspace(ws2, file = workspaceFile()) {
139109
+ mkdirSync93(dirname75(file), { recursive: true, mode: 448 });
139110
+ const tmp = `${file}.${process.pid}.tmp`;
139111
+ writeFileSync92(tmp, JSON.stringify(ws2, null, 2) + `
139112
+ `, { mode: 384 });
139113
+ renameSync30(tmp, file);
139114
+ }
139115
+ function reposWithRuns(db2) {
139116
+ const names = db2.selectDistinct({ r: runs.originRepo }).from(runs).all().map((x10) => x10.r ? x10.r.split("/").pop() ?? "" : "").filter(Boolean);
139117
+ return [...new Set(names)].sort();
139118
+ }
139119
+ var knownRepos = (db2) => [...new Set([...repoNames(db2), ...reposWithRuns(db2)])].sort();
139120
+ var unassigned = (ws2, withRuns) => {
139121
+ const held = new Set(ws2.orgs.flatMap((o) => o.projects.flatMap((p) => p.repos)));
139122
+ return withRuns.filter((r) => !held.has(r));
139123
+ };
139124
+ function repoDirsOf(db2, name) {
139125
+ const rows = db2.select({ name: localRepos.name, realpath: localRepos.realpath }).from(localRepos).all().filter((r) => r.name === name);
139126
+ return [...new Set(rows.map((r) => r.realpath))].filter((d) => {
139127
+ try {
139128
+ return statSync54(d).isDirectory();
139129
+ } catch {
139130
+ return false;
139131
+ }
139132
+ });
139133
+ }
139134
+ var repoDirOf = (db2, name) => repoDirsOf(db2, name)[0] ?? null;
139135
+ var INSTRUCTION_FILES = ["CLAUDE.md", "CLAUDE.local.md", ".claude/CLAUDE.md", "AGENTS.md"];
139136
+ var NOTE_DIRS = [".loki/memory", ".loki/learnings", ".claude/rules"];
139137
+ var readCapped3 = (p) => {
139138
+ try {
139139
+ const st2 = statSync54(p);
139140
+ if (!st2.isFile())
139141
+ return null;
139142
+ const b = readFileSync157(p);
139143
+ return { text: b.subarray(0, MAX_BYTES3).toString("utf8"), bytes: st2.size, truncated: st2.size > MAX_BYTES3 };
139144
+ } catch {
139145
+ return null;
139146
+ }
139147
+ };
139148
+ function repoKnowledge(dir) {
139149
+ const instructions = INSTRUCTION_FILES.flatMap((f) => {
139150
+ const r = readCapped3(join171(dir, f));
139151
+ return r ? [{ path: f, ...r }] : [];
139152
+ });
139153
+ const notes = [];
139154
+ for (const d of NOTE_DIRS) {
139155
+ let names = [];
139156
+ try {
139157
+ names = readdirSync58(join171(dir, d)).filter((n10) => /\.(md|json|jsonl|txt)$/i.test(n10)).sort().slice(0, 40);
139158
+ } catch {
139159
+ continue;
139160
+ }
139161
+ for (const n10 of names) {
139162
+ const r = readCapped3(join171(dir, d, n10));
139163
+ if (r)
139164
+ notes.push({ path: `${d}/${n10}`, bytes: r.bytes, preview: r.text.slice(0, 600) });
139165
+ }
139166
+ }
139167
+ return { instructions, notes };
139168
+ }
139169
+ function writeInstructions(dir, content) {
139170
+ const root = resolve46(dir), target = join171(root, "CLAUDE.md");
139171
+ if (!target.startsWith(root + sep30))
139172
+ throw new Error("path outside the repository");
139173
+ const tmp = `${target}.${process.pid}.tmp`;
139174
+ writeFileSync92(tmp, content);
139175
+ renameSync30(tmp, target);
139176
+ }
139177
+ function mount22(ctx) {
139178
+ const { app, act, db: db2, local } = ctx, deny = { error: "loopback only without a token" };
139179
+ const body = async (c) => {
139180
+ if (!local(c))
139181
+ return { ok: false, res: c.json({ error: "loopback JSON requests only" }, 403) };
139182
+ if (!originOk(c.req.header("origin")))
139183
+ return { ok: false, res: c.json({ error: "origin not allowed" }, 403) };
139184
+ const t = await c.req.text();
139185
+ if (t.length > MAX_BYTES3 + 2000)
139186
+ return { ok: false, res: c.json({ error: "body too large" }, 413) };
139187
+ try {
139188
+ return { ok: true, json: JSON.parse(t) };
139189
+ } catch {
139190
+ return { ok: false, res: c.json({ error: "invalid JSON" }, 400) };
139191
+ }
139192
+ };
139193
+ app.get("/v1/workspace", (c) => {
139194
+ if (!probeAllowed(ctx, c))
139195
+ return c.json(deny, 403);
139196
+ const active = reposWithRuns(db2), ws2 = loadWorkspace(active);
139197
+ return c.json({ ...ws2, repos: knownRepos(db2), unassigned: unassigned(ws2, active) });
139198
+ });
139199
+ act.put("/v1/workspace", async (c) => {
139200
+ const b = await body(c);
139201
+ if (!b.ok)
139202
+ return b.res;
139203
+ const p = parseWorkspace(b.json);
139204
+ if (!p.ok) {
139205
+ audit3(db2, { kind: "workspace.save", result: "refused", detail: p.error });
139206
+ return c.json({ error: p.error }, 400);
139207
+ }
139208
+ try {
139209
+ saveWorkspace(p.ws);
139210
+ } catch (e10) {
139211
+ return c.json({ error: `could not save: ${e10.message}` }, 500);
139212
+ }
139213
+ audit3(db2, { kind: "workspace.save", result: "saved", detail: `${p.ws.orgs.length} org(s), ${p.ws.orgs.reduce((a, o) => a + o.projects.length, 0)} project(s)` });
139214
+ return c.json({ ...p.ws, repos: knownRepos(db2), unassigned: unassigned(p.ws, reposWithRuns(db2)) });
139215
+ });
139216
+ app.get("/v1/repo/knowledge", (c) => {
139217
+ if (!probeAllowed(ctx, c))
139218
+ return c.json(deny, 403);
139219
+ const name = c.req.query("repo") ?? "", dir = name ? repoDirOf(db2, name) : null;
139220
+ if (!dir)
139221
+ return c.json({ error: "not a repository Loki has seen on this machine" }, 404);
139222
+ return c.json({ repo: name, ...repoKnowledge(dir) });
139223
+ });
139224
+ act.put("/v1/repo/instructions", async (c) => {
139225
+ const b = await body(c);
139226
+ if (!b.ok)
139227
+ return b.res;
139228
+ const name = text4(b.json?.repo, 200), content = b.json?.content;
139229
+ if (!name || typeof content !== "string" || content.length > MAX_BYTES3)
139230
+ return c.json({ error: `repo and content (at most ${MAX_BYTES3} characters) are required` }, 400);
139231
+ const dirs = repoDirsOf(db2, name), dir = dirs[0];
139232
+ if (!dir)
139233
+ return c.json({ error: "not a repository Loki has seen on this machine" }, 404);
139234
+ if (dirs.length > 1) {
139235
+ audit3(db2, { kind: "repo.instructions", target: name, result: "refused", detail: `${dirs.length} checkouts share this name` });
139236
+ return c.json({ error: `${dirs.length} checkouts on this machine are named ${name}; edit CLAUDE.md in the one you mean` }, 409);
139237
+ }
139238
+ try {
139239
+ writeInstructions(dir, content);
139240
+ } catch (e10) {
139241
+ audit3(db2, { kind: "repo.instructions", target: name, result: "error", detail: e10.message });
139242
+ return c.json({ error: `could not write CLAUDE.md: ${e10.message}` }, 500);
139243
+ }
139244
+ audit3(db2, { kind: "repo.instructions", target: name, result: "saved", detail: `${content.length} characters` });
139245
+ return c.json({ repo: name, ...repoKnowledge(dir) });
139246
+ });
139247
+ }
139248
+
138600
139249
  // src/server/routes/index.ts
138601
- var routeModules = [mount2, mount4, mount3, mount8, mount10, mount, mount11, mount6, mount12, mount13, mount15, mount7, mount14, mount16, mount9, mount20, mount21, mount17, mount19, mount5, mount18];
139250
+ var routeModules = [mount2, mount4, mount3, mount8, mount10, mount, mount11, mount6, mount12, mount13, mount15, mount7, mount14, mount16, mount9, mount20, mount21, mount17, mount19, mount5, mount18, mount22];
138602
139251
  function registerRoutes(ctx) {
138603
139252
  mountRepos(ctx.act, ctx.db, ctx.peerIsLoopback, ctx.repoDir, ctx.ghImpl);
138604
139253
  for (const m of routeModules)
@@ -138625,8 +139274,8 @@ function ttlCache(ttlMs = PROBE_CACHE_MS, now2 = Date.now) {
138625
139274
  }
138626
139275
 
138627
139276
  // src/server/legacy/shim.ts
138628
- import { existsSync as existsSync122, readFileSync as readFileSync157 } from "fs";
138629
- import { join as join171 } from "path";
139277
+ import { existsSync as existsSync123, readFileSync as readFileSync158 } from "fs";
139278
+ import { join as join172 } from "path";
138630
139279
 
138631
139280
  // src/server/legacy/routes.ts
138632
139281
  var LEGACY_ROUTES = [
@@ -139004,10 +139653,10 @@ var logged = new Set;
139004
139653
  var toHono = (p) => p.replace(/\{([A-Za-z_]+):path\}/g, ":$1{.+}").replace(/\{([A-Za-z_]+)\}/g, ":$1");
139005
139654
  var NOT_SUPPORTED = "not yet supported by the Control Plane";
139006
139655
  var repoVersion = () => {
139007
- for (const f of [join171(import.meta.dir, "../../../../../VERSION")]) {
139656
+ for (const f of [join172(import.meta.dir, "../../../../../VERSION")]) {
139008
139657
  try {
139009
- if (existsSync122(f))
139010
- return readFileSync157(f, "utf8").trim();
139658
+ if (existsSync123(f))
139659
+ return readFileSync158(f, "utf8").trim();
139011
139660
  } catch {}
139012
139661
  }
139013
139662
  return "unknown";
@@ -139189,7 +139838,7 @@ function legacyShim(opts) {
139189
139838
 
139190
139839
  // src/server/app.ts
139191
139840
  var MAX_BODY2 = 1e6;
139192
- var defaultUiDir = () => [join172(import.meta.dir, "../../ui/dist"), join172(import.meta.dir, "../ui/dist")].find((d) => existsSync123(join172(d, "index.html")));
139841
+ var defaultUiDir = () => [join173(import.meta.dir, "../../ui/dist"), join173(import.meta.dir, "../ui/dist")].find((d) => existsSync124(join173(d, "index.html")));
139193
139842
  function createApp(opts) {
139194
139843
  const uiDir = opts.uiDir ?? defaultUiDir();
139195
139844
  const { db: db2, sqlite } = openDb(opts.dbPath);
@@ -139218,10 +139867,10 @@ function createApp(opts) {
139218
139867
  await next();
139219
139868
  });
139220
139869
  const readInstalled = () => {
139221
- for (const f of [process.env.LOKI_VERSION_FILE, join172(import.meta.dir, "../../../../VERSION")]) {
139870
+ for (const f of [process.env.LOKI_VERSION_FILE, join173(import.meta.dir, "../../../../VERSION")]) {
139222
139871
  try {
139223
139872
  if (f)
139224
- return readFileSync158(f, "utf8").trim() || "unknown";
139873
+ return readFileSync159(f, "utf8").trim() || "unknown";
139225
139874
  } catch {}
139226
139875
  }
139227
139876
  return "unknown";
@@ -139237,12 +139886,12 @@ function createApp(opts) {
139237
139886
  return ready ? c.json({ ready: true }) : c.json({ ready: false }, 503);
139238
139887
  });
139239
139888
  app.post("/v1/ingest", async (c) => {
139240
- const text4 = await c.req.text();
139241
- if (text4.length > MAX_BODY2)
139889
+ const text5 = await c.req.text();
139890
+ if (text5.length > MAX_BODY2)
139242
139891
  return c.json({ error: "body over 1 MB" }, 413);
139243
139892
  let body;
139244
139893
  try {
139245
- body = JSON.parse(text4);
139894
+ body = JSON.parse(text5);
139246
139895
  } catch {
139247
139896
  return c.json({ error: "invalid JSON" }, 400);
139248
139897
  }
@@ -139262,12 +139911,12 @@ function createApp(opts) {
139262
139911
  const source = c.req.param("source"), run2 = c.req.param("run");
139263
139912
  if (!(c.req.header("content-type") ?? "").toLowerCase().startsWith("application/json"))
139264
139913
  return c.json({ error: "content-type must be application/json" }, 400);
139265
- const text4 = await c.req.text();
139266
- if (text4.length > 20000)
139914
+ const text5 = await c.req.text();
139915
+ if (text5.length > 20000)
139267
139916
  return c.json({ error: "body too large" }, 413);
139268
139917
  let body;
139269
139918
  try {
139270
- body = JSON.parse(text4);
139919
+ body = JSON.parse(text5);
139271
139920
  } catch {
139272
139921
  return c.json({ error: "invalid JSON" }, 400);
139273
139922
  }
@@ -139330,13 +139979,13 @@ function createApp(opts) {
139330
139979
  }
139331
139980
  if (!uiDir || p.startsWith("/v1/"))
139332
139981
  return c.json({ error: "not found" }, 404);
139333
- const root = resolve46(uiDir);
139334
- const f = resolve46(root, `.${p}`);
139335
- if (f.startsWith(root + sep30) && existsSync123(f) && statSync53(f).isFile())
139982
+ const root = resolve47(uiDir);
139983
+ const f = resolve47(root, `.${p}`);
139984
+ if (f.startsWith(root + sep31) && existsSync124(f) && statSync55(f).isFile())
139336
139985
  return new Response(Bun.file(f));
139337
139986
  if (/\.[a-z0-9]+$/i.test(p))
139338
139987
  return c.json({ error: "not found" }, 404);
139339
- return new Response(Bun.file(join172(root, "index.html")));
139988
+ return new Response(Bun.file(join173(root, "index.html")));
139340
139989
  });
139341
139990
  return { app, db: db2, close: () => {
139342
139991
  clearInterval(reconciler);