loki-mode 11.162.0 → 11.164.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.
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/autonomy/route.sh +17 -3
- package/bin/loki +3 -0
- package/dashboard/__init__.py +1 -1
- package/docs/CLI-REFERENCE.md +1 -1
- package/docs/INSTALLATION.md +1 -1
- package/docs/dev/architecture-reference.md +1 -0
- package/docs/environment-variables.md +43 -0
- package/loki-ts/dist/loki.js +1987 -1969
- package/mcp/__init__.py +1 -1
- package/package.json +2 -2
- package/packages/control-plane/dist/server.js +539 -261
- package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
- package/providers/model_catalog.json +12 -3
- package/web-app/dist/assets/{AdminPage-BizDHgWk.js → AdminPage-D_rYWYp0.js} +1 -1
- package/web-app/dist/assets/{Avatar-EPfQ4V79.js → Avatar-CcoGw0m5.js} +1 -1
- package/web-app/dist/assets/{Badge-BOcJREUY.js → Badge-Cw15TPei.js} +1 -1
- package/web-app/dist/assets/{Button-BL7oJ3SX.js → Button-DsX-nsCj.js} +1 -1
- package/web-app/dist/assets/{CockpitPage-CCjh7fQ3.js → CockpitPage-Br_dvjZI.js} +1 -1
- package/web-app/dist/assets/{ComparePage-D5v3QbiF.js → ComparePage-BDmDCMGY.js} +1 -1
- package/web-app/dist/assets/{ErrorBoundary-BPaT8HE3.js → ErrorBoundary-D9O24jrn.js} +1 -1
- package/web-app/dist/assets/{EvidenceReceiptPanel-DPjXfVE0.js → EvidenceReceiptPanel-Cp9ifZPt.js} +1 -1
- package/web-app/dist/assets/{GitHubIssuesPanel-TbALzECx.js → GitHubIssuesPanel-DqyEidYk.js} +1 -1
- package/web-app/dist/assets/{GitHubPRsPanel-C-L_BSIr.js → GitHubPRsPanel-CNYW59H-.js} +1 -1
- package/web-app/dist/assets/{HomePage-1mYJaASp.js → HomePage-DE1QosE6.js} +2 -2
- package/web-app/dist/assets/{LoginPage-B6idMnV-.js → LoginPage-B-c5spXO.js} +1 -1
- package/web-app/dist/assets/{MagicPage-DeNkeYa6.js → MagicPage-BWraqL5H.js} +1 -1
- package/web-app/dist/assets/{MetricsPage-Dgz1xd96.js → MetricsPage-CGOQizXV.js} +1 -1
- package/web-app/dist/assets/{NotFoundPage-BcpJkVEt.js → NotFoundPage-D0KVYl1V.js} +1 -1
- package/web-app/dist/assets/{ProjectPage-BghMVwZJ.js → ProjectPage-DgTGj__j.js} +3 -3
- package/web-app/dist/assets/{ProjectsPage-CYi1AWYT.js → ProjectsPage-C6Vsdip6.js} +1 -1
- package/web-app/dist/assets/{SettingsPage-CY2F-s-3.js → SettingsPage-1L9p6s_b.js} +1 -1
- package/web-app/dist/assets/{ShowcasePage-CnGVGvsv.js → ShowcasePage-Byg9F2e8.js} +1 -1
- package/web-app/dist/assets/{SystemSettingsPage-ZJA4D4Cr.js → SystemSettingsPage-UdZUrd9u.js} +1 -1
- package/web-app/dist/assets/{TeamsPage-D-ubF63c.js → TeamsPage-DWaCqosf.js} +1 -1
- package/web-app/dist/assets/{TemplatesPage-DU5ExG6U.js → TemplatesPage-Cgcp72UN.js} +1 -1
- package/web-app/dist/assets/{TerminalOutput-CxWrY53G.js → TerminalOutput-BVz50D0F.js} +1 -1
- package/web-app/dist/assets/{activity-B0hVt7sG.js → activity-BvipvF1O.js} +1 -1
- package/web-app/dist/assets/{bell-D70EABSP.js → bell-iAUxEaVR.js} +1 -1
- package/web-app/dist/assets/{bot-D0lhJgAo.js → bot-Dy0AAR1b.js} +1 -1
- package/web-app/dist/assets/{check-CvK2c4aF.js → check-viE3SIPw.js} +1 -1
- package/web-app/dist/assets/{chevron-left-5nepkZ1R.js → chevron-left-q56m4xfs.js} +1 -1
- package/web-app/dist/assets/{circle-alert-COWxxc9Q.js → circle-alert-BmY-0cE0.js} +1 -1
- package/web-app/dist/assets/{clock-DVruSW-w.js → clock-DENqKIQP.js} +1 -1
- package/web-app/dist/assets/{cloud-BLxWirmZ.js → cloud-CPMAUAuw.js} +1 -1
- package/web-app/dist/assets/{code-xml-DTR0iFkj.js → code-xml-BLw-S-36.js} +1 -1
- package/web-app/dist/assets/{database-BDk9p0n4.js → database-D4FF5k3m.js} +1 -1
- package/web-app/dist/assets/{dollar-sign-BZNzvnXk.js → dollar-sign-Bo6LODIL.js} +1 -1
- package/web-app/dist/assets/{file-code-corner-BnUFhCvL.js → file-code-corner-B_M8HXRk.js} +1 -1
- package/web-app/dist/assets/{file-plus-COXu7-j_.js → file-plus-CSjmuGXO.js} +1 -1
- package/web-app/dist/assets/{globe-lyZQ67pp.js → globe-1K3sFJ4u.js} +1 -1
- package/web-app/dist/assets/{hammer-DCl4Kayz.js → hammer-BiI_v50O.js} +1 -1
- package/web-app/dist/assets/{index-DPOae9m_.js → index-CLlpTadS.js} +3 -3
- package/web-app/dist/assets/{layers-jBOzzVOq.js → layers-DGA0_XFY.js} +1 -1
- package/web-app/dist/assets/{loader-circle-BFjr0bf_.js → loader-circle-uj-0CBdZ.js} +1 -1
- package/web-app/dist/assets/{lock-CY4mlLs5.js → lock-DX6XtHZP.js} +1 -1
- package/web-app/dist/assets/{package-eZT5xC4c.js → package-D1gxDw7b.js} +1 -1
- package/web-app/dist/assets/{plus-DuykLjQt.js → plus-DhtFD1zI.js} +1 -1
- package/web-app/dist/assets/{refresh-cw-G7q9T3RR.js → refresh-cw-BZZP6kVe.js} +1 -1
- package/web-app/dist/assets/{rotate-ccw-Bokg6RqC.js → rotate-ccw-XPbY4h1d.js} +1 -1
- package/web-app/dist/assets/{scroll-text-DOds11-k.js → scroll-text-Blqe4ma2.js} +1 -1
- package/web-app/dist/assets/{server-C8algKl_.js → server-DXP9qbWJ.js} +1 -1
- package/web-app/dist/assets/{shield-alert-BiKSiXeT.js → shield-alert-DEJ9_mWG.js} +1 -1
- package/web-app/dist/assets/{thumbs-up-DbgJ8_nk.js → thumbs-up-BnIztVmP.js} +1 -1
- package/web-app/dist/assets/{trash-2-CzORwdJm.js → trash-2-BgpBexui.js} +1 -1
- package/web-app/dist/assets/{trending-down-jQ86erDF.js → trending-down-BkCqHMgr.js} +1 -1
- package/web-app/dist/assets/{trending-up-C9JVhiBK.js → trending-up-C6Zp-6bn.js} +1 -1
- package/web-app/dist/assets/{upload-OV-MfCE6.js → upload-BS1Q6UYU.js} +1 -1
- package/web-app/dist/assets/{usePolling-C2jjhfd7.js → usePolling-Bv70waur.js} +1 -1
- package/web-app/dist/assets/{user-CNnDlDog.js → user-D36GKbph.js} +1 -1
- package/web-app/dist/index.html +1 -1
|
@@ -15511,15 +15511,329 @@ var init_receipt_surface = __esm(() => {
|
|
|
15511
15511
|
PR_NUMBER_RE = /\/pull\/(\d+)$/;
|
|
15512
15512
|
});
|
|
15513
15513
|
|
|
15514
|
+
// ../../loki-ts/src/util/claude_model.ts
|
|
15515
|
+
var exports_claude_model = {};
|
|
15516
|
+
__export(exports_claude_model, {
|
|
15517
|
+
stageRole: () => stageRole,
|
|
15518
|
+
specificPin: () => specificPin,
|
|
15519
|
+
roleValueError: () => roleValueError,
|
|
15520
|
+
roleValue: () => roleValue,
|
|
15521
|
+
roleStartLine: () => roleStartLine,
|
|
15522
|
+
roleSettings: () => roleSettings,
|
|
15523
|
+
roleNamesModel: () => roleNamesModel,
|
|
15524
|
+
roleModelsUsed: () => roleModelsUsed,
|
|
15525
|
+
roleModelsReceiptBlock: () => roleModelsReceiptBlock,
|
|
15526
|
+
roleModel: () => roleModel,
|
|
15527
|
+
roleConflictError: () => roleConflictError,
|
|
15528
|
+
resolveClaudeModel: () => resolveClaudeModel,
|
|
15529
|
+
providerOf: () => providerOf,
|
|
15530
|
+
noteRoleSkip: () => noteRoleSkip,
|
|
15531
|
+
noteRoleModel: () => noteRoleModel,
|
|
15532
|
+
isUnresolvedClaudeAlias: () => isUnresolvedClaudeAlias,
|
|
15533
|
+
isClaudeModel: () => isClaudeModel,
|
|
15534
|
+
haikuRun: () => haikuRun,
|
|
15535
|
+
fableRawApiNote: () => fableRawApiNote,
|
|
15536
|
+
explicitSetupModel: () => explicitSetupModel,
|
|
15537
|
+
claudeTierRank: () => claudeTierRank,
|
|
15538
|
+
claudeThinkingSubstitute: () => claudeThinkingSubstitute,
|
|
15539
|
+
claudeThinkingMaxEffort: () => claudeThinkingMaxEffort,
|
|
15540
|
+
claudeThinkingHasAdaptive: () => claudeThinkingHasAdaptive,
|
|
15541
|
+
claudeThinkingAccepted: () => claudeThinkingAccepted,
|
|
15542
|
+
claudeEffortLevels: () => claudeEffortLevels,
|
|
15543
|
+
chooseSessionModel: () => chooseSessionModel,
|
|
15544
|
+
catalogClaudeIds: () => catalogClaudeIds,
|
|
15545
|
+
canonicalSessionPin: () => canonicalSessionPin,
|
|
15546
|
+
__resetRoleModelsForTests: () => __resetRoleModelsForTests,
|
|
15547
|
+
VALID_TIERS: () => VALID_TIERS,
|
|
15548
|
+
ROLE_FLAG_ENV: () => ROLE_FLAG_ENV,
|
|
15549
|
+
ROLES: () => ROLES,
|
|
15550
|
+
PROVIDER_DEFAULT_MODEL: () => PROVIDER_DEFAULT_MODEL,
|
|
15551
|
+
GENERIC_TIERS: () => GENERIC_TIERS,
|
|
15552
|
+
EXPLICIT_MODEL_ENV: () => EXPLICIT_MODEL_ENV,
|
|
15553
|
+
DEFAULT_SESSION_MODEL: () => DEFAULT_SESSION_MODEL
|
|
15554
|
+
});
|
|
15555
|
+
import { readFileSync as readFileSync26 } from "fs";
|
|
15556
|
+
import { resolve as resolve11 } from "path";
|
|
15557
|
+
function resolveClaudeModel(want) {
|
|
15558
|
+
try {
|
|
15559
|
+
const path = process.env["LOKI_MODEL_CATALOG"] || resolve11(REPO_ROOT, "providers/model_catalog.json");
|
|
15560
|
+
return JSON.parse(readFileSync26(path, "utf8")).providers?.claude?.cli_aliases?.[want] ?? want;
|
|
15561
|
+
} catch {
|
|
15562
|
+
return want;
|
|
15563
|
+
}
|
|
15564
|
+
}
|
|
15565
|
+
function isUnresolvedClaudeAlias(model) {
|
|
15566
|
+
return FAMILY_ALIASES.has(model);
|
|
15567
|
+
}
|
|
15568
|
+
function claudeTierRank(model) {
|
|
15569
|
+
try {
|
|
15570
|
+
const path = process.env["LOKI_MODEL_CATALOG"] || resolve11(REPO_ROOT, "providers/model_catalog.json");
|
|
15571
|
+
const models = JSON.parse(readFileSync26(path, "utf8")).providers?.claude?.models;
|
|
15572
|
+
if (!Array.isArray(models))
|
|
15573
|
+
return null;
|
|
15574
|
+
const order2 = [];
|
|
15575
|
+
for (const m of models)
|
|
15576
|
+
if (m.tier !== "legacy" && !order2.includes(m.tier))
|
|
15577
|
+
order2.push(m.tier);
|
|
15578
|
+
const id = resolveClaudeModel(model);
|
|
15579
|
+
const hit = models.find((m) => m.id === id || m.alias === model);
|
|
15580
|
+
const rank = hit ? order2.indexOf(hit.tier) : -1;
|
|
15581
|
+
return rank >= 0 ? rank : null;
|
|
15582
|
+
} catch {
|
|
15583
|
+
return null;
|
|
15584
|
+
}
|
|
15585
|
+
}
|
|
15586
|
+
function claudeEffortLevels(model) {
|
|
15587
|
+
try {
|
|
15588
|
+
const path = process.env["LOKI_MODEL_CATALOG"] || resolve11(REPO_ROOT, "providers/model_catalog.json");
|
|
15589
|
+
const models = JSON.parse(readFileSync26(path, "utf8")).providers?.claude?.models;
|
|
15590
|
+
if (!Array.isArray(models))
|
|
15591
|
+
return null;
|
|
15592
|
+
const id = resolveClaudeModel(model);
|
|
15593
|
+
const levels = models.find((m) => m.id === id || m.alias === model)?.effort?.levels;
|
|
15594
|
+
return Array.isArray(levels) ? levels : null;
|
|
15595
|
+
} catch {
|
|
15596
|
+
return null;
|
|
15597
|
+
}
|
|
15598
|
+
}
|
|
15599
|
+
function claudeThinkingSpec(model) {
|
|
15600
|
+
try {
|
|
15601
|
+
const path = process.env["LOKI_MODEL_CATALOG"] || resolve11(REPO_ROOT, "providers/model_catalog.json");
|
|
15602
|
+
const models = JSON.parse(readFileSync26(path, "utf8")).providers?.claude?.models;
|
|
15603
|
+
if (!Array.isArray(models))
|
|
15604
|
+
return null;
|
|
15605
|
+
const id = resolveClaudeModel(model);
|
|
15606
|
+
return models.find((m) => m.id === id || m.alias === model)?.thinking ?? null;
|
|
15607
|
+
} catch {
|
|
15608
|
+
return null;
|
|
15609
|
+
}
|
|
15610
|
+
}
|
|
15611
|
+
function claudeThinkingMaxEffort(model, type) {
|
|
15612
|
+
const max = claudeThinkingSpec(model)?.max_effort?.[type];
|
|
15613
|
+
return typeof max === "string" ? max : null;
|
|
15614
|
+
}
|
|
15615
|
+
function claudeThinkingSubstitute(model, type) {
|
|
15616
|
+
const sub = claudeThinkingSpec(model)?.substitute?.[type];
|
|
15617
|
+
return typeof sub === "string" ? sub : null;
|
|
15618
|
+
}
|
|
15619
|
+
function claudeThinkingAccepted(model, type) {
|
|
15620
|
+
const spec = claudeThinkingSpec(model);
|
|
15621
|
+
if (!spec || !Array.isArray(spec.types))
|
|
15622
|
+
return true;
|
|
15623
|
+
return spec.types.includes(type) || typeof spec.substitute?.[type] === "string";
|
|
15624
|
+
}
|
|
15625
|
+
function claudeThinkingHasAdaptive(model) {
|
|
15626
|
+
const types = claudeThinkingSpec(model)?.types;
|
|
15627
|
+
return Array.isArray(types) && types.includes("adaptive");
|
|
15628
|
+
}
|
|
15629
|
+
function canonicalSessionPin(raw2) {
|
|
15630
|
+
const v = (raw2 ?? "").trim().toLowerCase();
|
|
15631
|
+
if (!v)
|
|
15632
|
+
return;
|
|
15633
|
+
const pin = GENERIC_TIERS[v] ?? v;
|
|
15634
|
+
if (!VALID_TIERS.has(pin)) {
|
|
15635
|
+
throw new Error(`unknown LOKI_SESSION_MODEL '${(raw2 ?? "").trim()}' (small|medium|high, planning|development|fast, or opus|sonnet|haiku|fable)`);
|
|
15636
|
+
}
|
|
15637
|
+
return pin;
|
|
15638
|
+
}
|
|
15639
|
+
function explicitSetupModel(tier, e = process.env) {
|
|
15640
|
+
if (e["LOKI_LEGACY_TIER_SWITCHING"] === "true")
|
|
15641
|
+
return;
|
|
15642
|
+
const sess = (e["LOKI_SESSION_MODEL"] ?? "").trim().toLowerCase();
|
|
15643
|
+
if (tier === "planning" && (sess === "high" || sess === "planning"))
|
|
15644
|
+
return e["LOKI_CLAUDE_MODEL_PLANNING"] || e["LOKI_MODEL_PLANNING"] ? undefined : "opus";
|
|
15645
|
+
if (tier !== "fast" || sess !== "small" && sess !== "fast" || e["LOKI_CLAUDE_MODEL_FAST"] || e["LOKI_MODEL_FAST"])
|
|
15646
|
+
return;
|
|
15647
|
+
return e["LOKI_ALLOW_HAIKU"] === undefined || e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : undefined;
|
|
15648
|
+
}
|
|
15649
|
+
function chooseSessionModel(e = process.env) {
|
|
15650
|
+
const carried = canonicalSessionPin(e["LOKI_SESSION_MODEL"]);
|
|
15651
|
+
if (e["LOKI_SESSION_MODEL_SOURCE"] === "default" && carried && EXPLICIT_MODEL_ENV.every((k) => k === "LOKI_SESSION_MODEL" || (e[k] ?? "").trim() === ""))
|
|
15652
|
+
return { source: "default", pin: carried, why: "Loki default, carried from the parent run" };
|
|
15653
|
+
const named = EXPLICIT_MODEL_ENV.find((k) => (e[k] ?? "").trim() !== "");
|
|
15654
|
+
if (named)
|
|
15655
|
+
return { source: "explicit", pin: null, why: named === "LOKI_SESSION_MODEL" ? "--session-model or LOKI_SESSION_MODEL" : named };
|
|
15656
|
+
const router = (e["LOKI_ROUTER"] ?? "").trim().toLowerCase();
|
|
15657
|
+
if (["1", "true", "on", "auto"].includes(router))
|
|
15658
|
+
return { source: "explicit", pin: null, why: `LOKI_ROUTER=${router}` };
|
|
15659
|
+
const raw2 = (e["LOKI_DEFAULT_SESSION_MODEL"] ?? "").trim().toLowerCase();
|
|
15660
|
+
if (raw2 === "provider")
|
|
15661
|
+
return { source: "provider", pin: null, why: "LOKI_DEFAULT_SESSION_MODEL=provider (the Claude CLI's own default)" };
|
|
15662
|
+
const pin = canonicalSessionPin(raw2 || DEFAULT_SESSION_MODEL);
|
|
15663
|
+
return { source: "default", pin, why: raw2 ? `LOKI_DEFAULT_SESSION_MODEL=${raw2}` : "Loki default, set another with --session-model or LOKI_DEFAULT_SESSION_MODEL=provider" };
|
|
15664
|
+
}
|
|
15665
|
+
function haikuRun(e = process.env) {
|
|
15666
|
+
const H = /haiku/i, val = (k) => (e[k] ?? "").trim();
|
|
15667
|
+
const dev = roleModel("dev", e);
|
|
15668
|
+
if (dev !== undefined)
|
|
15669
|
+
return H.test(dev);
|
|
15670
|
+
if (val("LOKI_PROVIDER").toLowerCase() === "opencode")
|
|
15671
|
+
return H.test(val("LOKI_OPENCODE_MODEL"));
|
|
15672
|
+
for (const k of ["LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_MODEL_DEVELOPMENT"])
|
|
15673
|
+
if (val(k))
|
|
15674
|
+
return H.test(val(k));
|
|
15675
|
+
let pin;
|
|
15676
|
+
try {
|
|
15677
|
+
pin = canonicalSessionPin(e["LOKI_SESSION_MODEL"]) ?? chooseSessionModel(e).pin ?? undefined;
|
|
15678
|
+
} catch {
|
|
15679
|
+
return false;
|
|
15680
|
+
}
|
|
15681
|
+
if (pin === "haiku")
|
|
15682
|
+
return true;
|
|
15683
|
+
if (pin === "fast")
|
|
15684
|
+
return H.test(explicitSetupModel("fast", e) ?? (val("LOKI_CLAUDE_MODEL_FAST") || val("LOKI_MODEL_FAST") || (e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : "sonnet")));
|
|
15685
|
+
if (pin)
|
|
15686
|
+
return false;
|
|
15687
|
+
return routerPreset(e) && H.test(presetExecutor(e).model);
|
|
15688
|
+
}
|
|
15689
|
+
function roleSettings(e = process.env) {
|
|
15690
|
+
const out2 = {};
|
|
15691
|
+
const check = (role, v, from) => {
|
|
15692
|
+
if (!ROLES.includes(role))
|
|
15693
|
+
throw new Error(`unknown role '${role}' in ${from} (${ROLES.join("|")})`);
|
|
15694
|
+
if (!ROLE_VALUE.test(v))
|
|
15695
|
+
throw new Error(`bad model '${v}' for role ${role} in ${from} (haiku|sonnet|opus|fable or a model id)`);
|
|
15696
|
+
out2[role] = v;
|
|
15697
|
+
};
|
|
15698
|
+
const line2 = (e["LOKI_MODELS"] ?? "").trim();
|
|
15699
|
+
if (line2)
|
|
15700
|
+
for (const part of line2.split(",").map((p) => p.trim()).filter(Boolean)) {
|
|
15701
|
+
const i = part.indexOf("=");
|
|
15702
|
+
if (i <= 0)
|
|
15703
|
+
throw new Error(`bad LOKI_MODELS entry '${part}' (role=model, comma separated)`);
|
|
15704
|
+
check(part.slice(0, i).trim().toLowerCase(), part.slice(i + 1).trim(), "LOKI_MODELS");
|
|
15705
|
+
}
|
|
15706
|
+
for (const r of ROLES) {
|
|
15707
|
+
const v = (e[`LOKI_ROLE_${r.toUpperCase()}`] ?? "").trim();
|
|
15708
|
+
if (v)
|
|
15709
|
+
check(r, v, `LOKI_ROLE_${r.toUpperCase()}`);
|
|
15710
|
+
}
|
|
15711
|
+
return out2;
|
|
15712
|
+
}
|
|
15713
|
+
function catalogClaudeIds() {
|
|
15714
|
+
try {
|
|
15715
|
+
const path = process.env["LOKI_MODEL_CATALOG"] || resolve11(REPO_ROOT, "providers/model_catalog.json");
|
|
15716
|
+
const ms = JSON.parse(readFileSync26(path, "utf8")).providers?.claude?.models;
|
|
15717
|
+
return Array.isArray(ms) ? ms.map((m) => m?.id).filter((x) => typeof x === "string") : [];
|
|
15718
|
+
} catch {
|
|
15719
|
+
return [];
|
|
15720
|
+
}
|
|
15721
|
+
}
|
|
15722
|
+
function roleValueError(e = process.env, provider = providerOf(e)) {
|
|
15723
|
+
if (provider === "opencode")
|
|
15724
|
+
return null;
|
|
15725
|
+
const ids = catalogClaudeIds(), known = new Set(["haiku", "sonnet", "opus", "fable", ...ids]);
|
|
15726
|
+
for (const [role, v] of Object.entries(roleSettings(e))) {
|
|
15727
|
+
if (known.has(v))
|
|
15728
|
+
continue;
|
|
15729
|
+
if (ROUTE_ID.test(v))
|
|
15730
|
+
return `role ${role}: '${v}' is a route; set a route for the whole run with --model, per-role routes are not supported`;
|
|
15731
|
+
const near = [...known].sort((a, b) => editDistance(v.toLowerCase(), a) - editDistance(v.toLowerCase(), b))[0];
|
|
15732
|
+
return `role ${role}: unknown model '${v}' on the claude provider; use haiku, sonnet, opus or fable, or a model id from the catalog${near ? ` (nearest: ${near})` : ""}`;
|
|
15733
|
+
}
|
|
15734
|
+
return null;
|
|
15735
|
+
}
|
|
15736
|
+
function roleConflictError(e = process.env, provider = providerOf(e)) {
|
|
15737
|
+
const route = (e["LOKI_MODEL_ROUTE"] ?? "").trim(), set = Object.entries(roleSettings(e));
|
|
15738
|
+
if (route && provider !== "opencode" && set.length)
|
|
15739
|
+
return `role ${set[0][0]} names ${set[0][1]}, but LOKI_MODEL_ROUTE=${route} serves every call of the run; unset the role or the route`;
|
|
15740
|
+
const cap = (e["LOKI_MAX_TIER"] ?? "").trim().toLowerCase(), order2 = ["haiku", "sonnet", "opus", "fable"];
|
|
15741
|
+
const fam = (m) => {
|
|
15742
|
+
const f = /haiku|sonnet|opus|fable/i.exec(resolveClaudeModel(m))?.[0]?.toLowerCase();
|
|
15743
|
+
return f ? order2.indexOf(f) : -1;
|
|
15744
|
+
};
|
|
15745
|
+
const capRank = order2.indexOf(cap);
|
|
15746
|
+
if (capRank < 0)
|
|
15747
|
+
return null;
|
|
15748
|
+
const s = Object.fromEntries(set);
|
|
15749
|
+
for (const r of ROLES) {
|
|
15750
|
+
const v = s[r];
|
|
15751
|
+
if (v && fam(v) > capRank)
|
|
15752
|
+
return `role ${r} names ${v}, above LOKI_MAX_TIER=${cap}; lower the role or raise the ceiling`;
|
|
15753
|
+
}
|
|
15754
|
+
return null;
|
|
15755
|
+
}
|
|
15756
|
+
function roleValue(role, e = process.env, provider = providerOf(e)) {
|
|
15757
|
+
const v = safeSettings(e)[role];
|
|
15758
|
+
return v && !underRoute(e, provider) ? v : undefined;
|
|
15759
|
+
}
|
|
15760
|
+
function roleModel(role, e = process.env, provider = providerOf(e)) {
|
|
15761
|
+
const v = roleValue(role, e, provider);
|
|
15762
|
+
return v === undefined ? undefined : provider === "opencode" ? v : resolveClaudeModel(v);
|
|
15763
|
+
}
|
|
15764
|
+
function roleNamesModel(model, e = process.env) {
|
|
15765
|
+
return Object.values(safeSettings(e)).some((v) => v === model || resolveClaudeModel(v) === model);
|
|
15766
|
+
}
|
|
15767
|
+
function roleStartLine(e = process.env, provider = providerOf(e)) {
|
|
15768
|
+
const s = safeSettings(e);
|
|
15769
|
+
if (!Object.keys(s).length)
|
|
15770
|
+
return "";
|
|
15771
|
+
return `models: ${ROLES.map((r) => `${r} ${s[r] ? s[r] : r === "escalate" ? s.dev ? "none" : "auto" : "auto"}`).join(", ")}${provider === "opencode" ? " (passed to opencode as given; opencode checks the ids)" : ""}`;
|
|
15772
|
+
}
|
|
15773
|
+
function noteRoleModel(role, model) {
|
|
15774
|
+
if (!model)
|
|
15775
|
+
return;
|
|
15776
|
+
const l = roleUsed.get(role) ?? [];
|
|
15777
|
+
if (!l.includes(model))
|
|
15778
|
+
l.push(model);
|
|
15779
|
+
roleUsed.set(role, l);
|
|
15780
|
+
}
|
|
15781
|
+
function noteRoleSkip(call, reason) {
|
|
15782
|
+
if (!roleSkips.some((x) => x.call === call && x.reason === reason))
|
|
15783
|
+
roleSkips.push({ call, reason });
|
|
15784
|
+
}
|
|
15785
|
+
function fableRawApiNote(e = process.env) {
|
|
15786
|
+
if (!(e["ANTHROPIC_API_KEY"] ?? "").trim())
|
|
15787
|
+
return "";
|
|
15788
|
+
const named = [...Object.values(safeSettings(e)), e["LOKI_SESSION_MODEL"] ?? "", e["LOKI_MODEL_OVERRIDE"] ?? ""].some((v) => /fable/i.test(v));
|
|
15789
|
+
return named ? "fable on the raw API is not verified; a refused call is reported, never swapped for another model" : "";
|
|
15790
|
+
}
|
|
15791
|
+
var PROVIDER_DEFAULT_MODEL = "claude (provider default)", FAMILY_ALIASES, VALID_TIERS, GENERIC_TIERS, DEFAULT_SESSION_MODEL = "sonnet", EXPLICIT_MODEL_ENV, ROLES, ROLE_FLAG_ENV, ROLE_VALUE, ROUTE_ID, editDistance = (a, b) => {
|
|
15792
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
15793
|
+
for (let i = 1;i <= a.length; i++) {
|
|
15794
|
+
const cur = [i];
|
|
15795
|
+
for (let j = 1;j <= b.length; j++)
|
|
15796
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
15797
|
+
prev = cur;
|
|
15798
|
+
}
|
|
15799
|
+
return prev[b.length];
|
|
15800
|
+
}, safeSettings = (e) => {
|
|
15801
|
+
try {
|
|
15802
|
+
return roleSettings(e);
|
|
15803
|
+
} catch {
|
|
15804
|
+
return {};
|
|
15805
|
+
}
|
|
15806
|
+
}, underRoute = (e, provider) => provider !== "opencode" && (e["LOKI_MODEL_ROUTE"] ?? "").trim() !== "", providerOf = (e) => (e["LOKI_E10_RUN_PROVIDER"] || e["LOKI_E10_PROVIDER"] || e["LOKI_PROVIDER"] || "claude").trim().toLowerCase(), isClaudeModel = (m) => /^(claude-|haiku$|sonnet$|opus$|fable$)/i.test(m) || /(haiku|sonnet|opus|fable)/i.test(m) && !m.includes("/"), stageRole = (stage) => stage === "plan" ? "plan" : stage === "wall" || stage === "prove" ? "test" : stage === "intake" ? "helper" : "dev", roleUsed, roleModelsUsed = () => Object.fromEntries([...roleUsed].filter(([, l]) => l.length)), roleSkips, __resetRoleModelsForTests = () => {
|
|
15807
|
+
roleUsed.clear();
|
|
15808
|
+
roleSkips.length = 0;
|
|
15809
|
+
}, specificPin = (role, varName, e = process.env) => (e[varName] ?? "").trim() !== "" && roleModel(role, e) !== undefined ? { pinSource: "specific" } : {}, roleModelsReceiptBlock = (e = process.env) => ({ ...Object.keys(safeSettings(e)).length ? { models_by_role: roleModelsUsed() } : {}, ...roleSkips.length ? { tool_calls_skipped: roleSkips.map((x) => ({ ...x })) } : {}, ...fableRawApiNote(e) ? { fable_raw_api: fableRawApiNote(e) } : {} });
|
|
15810
|
+
var init_claude_model = __esm(() => {
|
|
15811
|
+
init_paths();
|
|
15812
|
+
FAMILY_ALIASES = new Set(["haiku", "sonnet", "opus", "fable"]);
|
|
15813
|
+
VALID_TIERS = new Set(["planning", "development", "fast", "opus", "sonnet", "haiku", "fable"]);
|
|
15814
|
+
GENERIC_TIERS = {
|
|
15815
|
+
small: "fast",
|
|
15816
|
+
medium: "development",
|
|
15817
|
+
high: "planning"
|
|
15818
|
+
};
|
|
15819
|
+
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"];
|
|
15820
|
+
ROLES = ["plan", "dev", "test", "review", "advisor", "helper", "escalate"];
|
|
15821
|
+
ROLE_FLAG_ENV = new Map([...ROLES.map((r) => [`--${r}-model`, `LOKI_ROLE_${r.toUpperCase()}`]), ["--models", "LOKI_MODELS"]]);
|
|
15822
|
+
ROLE_VALUE = /^[A-Za-z0-9][\w.:@/[\]-]*$/;
|
|
15823
|
+
ROUTE_ID = /^(openrouter|ollama|lmstudio|llamacpp|vllm|custom)\//;
|
|
15824
|
+
roleUsed = new Map;
|
|
15825
|
+
roleSkips = [];
|
|
15826
|
+
});
|
|
15827
|
+
|
|
15514
15828
|
// ../../loki-ts/src/council/role_agents.ts
|
|
15515
|
-
import { existsSync as existsSync18, readdirSync as readdirSync15, readFileSync as
|
|
15829
|
+
import { existsSync as existsSync18, readdirSync as readdirSync15, readFileSync as readFileSync27 } from "fs";
|
|
15516
15830
|
import { homedir as homedir9 } from "os";
|
|
15517
15831
|
import { join as join34 } from "path";
|
|
15518
15832
|
function agentDirs(repoDir, env = process.env) {
|
|
15519
15833
|
return [env["LOKI_AGENTS_PROJECT_DIR"] || join34(repoDir, ".loki", "agents"), env["LOKI_AGENTS_USER_DIR"] || join34(env["XDG_CONFIG_HOME"] || join34(homedir9(), ".config"), "loki", "agents")];
|
|
15520
15834
|
}
|
|
15521
15835
|
function parseAgent(file, stem) {
|
|
15522
|
-
const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(
|
|
15836
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(readFileSync27(file, "utf8"));
|
|
15523
15837
|
if (!m)
|
|
15524
15838
|
return null;
|
|
15525
15839
|
const body = m[2].trim();
|
|
@@ -15527,7 +15841,7 @@ function parseAgent(file, stem) {
|
|
|
15527
15841
|
return null;
|
|
15528
15842
|
const kv = (k) => new RegExp(`^${k}:[ \\t]*["']?([^"'\\r\\n#]*?)["']?[ \\t]*$`, "m").exec(m[1])?.[1]?.trim() ?? "";
|
|
15529
15843
|
const role = (kv("role") || stem).toLowerCase();
|
|
15530
|
-
if (!
|
|
15844
|
+
if (!ROLES2.includes(role))
|
|
15531
15845
|
return null;
|
|
15532
15846
|
return { name: kv("name") || stem, role, provider: (kv("provider") || "claude").toLowerCase(), model: kv("model"), prompt: body.slice(0, 4000) };
|
|
15533
15847
|
}
|
|
@@ -15567,7 +15881,7 @@ function explicitReview(repoDir, env) {
|
|
|
15567
15881
|
if (!existsSync18(p))
|
|
15568
15882
|
continue;
|
|
15569
15883
|
try {
|
|
15570
|
-
const m = /^review:[ \t]*["']?([A-Za-z]+)["']?[ \t]*(?:#.*)?$/m.exec(
|
|
15884
|
+
const m = /^review:[ \t]*["']?([A-Za-z]+)["']?[ \t]*(?:#.*)?$/m.exec(readFileSync27(p, "utf8"));
|
|
15571
15885
|
const v = asProvider(m?.[1]);
|
|
15572
15886
|
if (v)
|
|
15573
15887
|
return v;
|
|
@@ -15581,12 +15895,12 @@ function reviewProvider(repoDir, env = process.env, _builder) {
|
|
|
15581
15895
|
const x = explicitReview(repoDir, env);
|
|
15582
15896
|
return x && x !== "off" ? x : null;
|
|
15583
15897
|
}
|
|
15584
|
-
var
|
|
15898
|
+
var ROLES2, asProvider = (v) => {
|
|
15585
15899
|
const s = v?.trim().toLowerCase();
|
|
15586
15900
|
return s === "claude" ? s : null;
|
|
15587
15901
|
}, isOff = (v) => /^(off|none|false|0)$/i.test(v?.trim() ?? ""), xvendorDefault = (env = process.env) => /^(1|true|yes|on)$/i.test(env["LOKI_XVENDOR_DEFAULT"]?.trim() ?? ""), reviewCli = (p, env = process.env) => env[`LOKI_${p.toUpperCase()}_CLI`]?.trim() || p;
|
|
15588
15902
|
var init_role_agents = __esm(() => {
|
|
15589
|
-
|
|
15903
|
+
ROLES2 = ["council", "reviewer"];
|
|
15590
15904
|
});
|
|
15591
15905
|
|
|
15592
15906
|
// ../../loki-ts/src/util/cost_profile.ts
|
|
@@ -15602,7 +15916,7 @@ var init_cost_profile = () => {};
|
|
|
15602
15916
|
var escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15603
15917
|
|
|
15604
15918
|
// ../../loki-ts/src/util/yaml_key.ts
|
|
15605
|
-
import { existsSync as existsSync19, readFileSync as
|
|
15919
|
+
import { existsSync as existsSync19, readFileSync as readFileSync28 } from "fs";
|
|
15606
15920
|
import { join as join35 } from "path";
|
|
15607
15921
|
function lokiYamlTexts(repoDir, opts = {}) {
|
|
15608
15922
|
const out2 = [];
|
|
@@ -15611,7 +15925,7 @@ function lokiYamlTexts(repoDir, opts = {}) {
|
|
|
15611
15925
|
if (!existsSync19(p))
|
|
15612
15926
|
continue;
|
|
15613
15927
|
try {
|
|
15614
|
-
out2.push(
|
|
15928
|
+
out2.push(readFileSync28(p, "utf8"));
|
|
15615
15929
|
} catch {}
|
|
15616
15930
|
}
|
|
15617
15931
|
return out2;
|
|
@@ -15684,7 +15998,7 @@ var clean = (v) => v.replace(/(^|[ \t]+)#.*$/, "").trim().replace(/^(["'])(.*)\1
|
|
|
15684
15998
|
var init_yaml_key = () => {};
|
|
15685
15999
|
|
|
15686
16000
|
// ../../loki-ts/src/util/stack_tools.ts
|
|
15687
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync13, readFileSync as
|
|
16001
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync13, readFileSync as readFileSync29, readdirSync as readdirSync16, writeFileSync as writeFileSync14 } from "fs";
|
|
15688
16002
|
import { tmpdir as tmpdir7 } from "os";
|
|
15689
16003
|
import { join as join36 } from "path";
|
|
15690
16004
|
function stackRunner(files) {
|
|
@@ -15722,7 +16036,7 @@ function dotnetTestProject(repoDir) {
|
|
|
15722
16036
|
for (const e of es)
|
|
15723
16037
|
if (!e.dir && e.name.endsWith(".csproj")) {
|
|
15724
16038
|
try {
|
|
15725
|
-
if (/Microsoft\.NET\.Test\.Sdk/.test(
|
|
16039
|
+
if (/Microsoft\.NET\.Test\.Sdk/.test(readFileSync29(join36(dir, e.name), "utf8")))
|
|
15726
16040
|
return join36(dir, e.name).slice(repoDir.length + 1);
|
|
15727
16041
|
} catch {}
|
|
15728
16042
|
}
|
|
@@ -15760,7 +16074,7 @@ function repoTestCommand(repoDir) {
|
|
|
15760
16074
|
function gradleInitScript() {
|
|
15761
16075
|
const dir = join36(tmpdir7(), "loki-gradle-init"), p = join36(dir, "test-logging.init.gradle");
|
|
15762
16076
|
try {
|
|
15763
|
-
if (
|
|
16077
|
+
if (readFileSync29(p, "utf8") !== GRADLE_INIT)
|
|
15764
16078
|
throw new Error("stale");
|
|
15765
16079
|
} catch {
|
|
15766
16080
|
try {
|
|
@@ -15775,7 +16089,7 @@ function neededServices(repoDir) {
|
|
|
15775
16089
|
const walk = (dir, depth) => {
|
|
15776
16090
|
for (const e of readdirSync16(dir, { withFileTypes: true })) {
|
|
15777
16091
|
if (e.isFile() && NEED_FILES.test(e.name))
|
|
15778
|
-
texts.push(
|
|
16092
|
+
texts.push(readFileSync29(join36(dir, e.name), "utf8").slice(0, 200000));
|
|
15779
16093
|
else if (e.isDirectory() && depth < 2 && !e.name.startsWith(".") && e.name !== "node_modules" && e.name !== "vendor")
|
|
15780
16094
|
walk(join36(dir, e.name), depth + 1);
|
|
15781
16095
|
}
|
|
@@ -15854,7 +16168,7 @@ function envCard(ctx, env = process.env) {
|
|
|
15854
16168
|
}
|
|
15855
16169
|
function readEnvCardFile(runDir) {
|
|
15856
16170
|
try {
|
|
15857
|
-
const c = JSON.parse(
|
|
16171
|
+
const c = JSON.parse(readFileSync29(join36(runDir, "env-card.json"), "utf8"));
|
|
15858
16172
|
return c && Array.isArray(c.needed) && Array.isArray(c.found) ? { ...c, path_appended: Array.isArray(c.path_appended) ? c.path_appended : [] } : null;
|
|
15859
16173
|
} catch {
|
|
15860
16174
|
return null;
|
|
@@ -15894,7 +16208,7 @@ var init_stack_tools = __esm(() => {
|
|
|
15894
16208
|
});
|
|
15895
16209
|
|
|
15896
16210
|
// ../../loki-ts/src/util/dotnet_test.ts
|
|
15897
|
-
import { existsSync as existsSync21, readFileSync as
|
|
16211
|
+
import { existsSync as existsSync21, readFileSync as readFileSync30 } from "fs";
|
|
15898
16212
|
import { basename as basename9, join as join37 } from "path";
|
|
15899
16213
|
function dotnetSummary(text3) {
|
|
15900
16214
|
const ls2 = text3.split(`
|
|
@@ -15953,7 +16267,7 @@ function dotnetSummary(text3) {
|
|
|
15953
16267
|
function dotnetClasses(file) {
|
|
15954
16268
|
let text3 = "";
|
|
15955
16269
|
try {
|
|
15956
|
-
text3 =
|
|
16270
|
+
text3 = readFileSync30(file, "utf8");
|
|
15957
16271
|
} catch {}
|
|
15958
16272
|
const found = [...new Set([...text3.matchAll(/\bclass\s+([A-Za-z_]\w*)/g)].map((m) => m[1]))];
|
|
15959
16273
|
return found.length ? found : [basename9(file, ".cs")];
|
|
@@ -15990,24 +16304,24 @@ var init_wall_knobs = __esm(() => {
|
|
|
15990
16304
|
|
|
15991
16305
|
// ../../loki-ts/src/util/producer_fingerprint.ts
|
|
15992
16306
|
import { createHash as createHash7 } from "crypto";
|
|
15993
|
-
import { readdirSync as readdirSync17, readFileSync as
|
|
15994
|
-
import { relative as relative2, resolve as
|
|
16307
|
+
import { readdirSync as readdirSync17, readFileSync as readFileSync31 } from "fs";
|
|
16308
|
+
import { relative as relative2, resolve as resolve12 } from "path";
|
|
15995
16309
|
function sourceFingerprint(root) {
|
|
15996
16310
|
const h = createHash7("sha256");
|
|
15997
16311
|
const walk = (dir) => {
|
|
15998
16312
|
for (const e of readdirSync17(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
15999
|
-
const p =
|
|
16313
|
+
const p = resolve12(dir, e.name);
|
|
16000
16314
|
if (e.isDirectory()) {
|
|
16001
16315
|
if (e.name !== "node_modules")
|
|
16002
16316
|
walk(p);
|
|
16003
16317
|
} else if (e.isFile() && e.name.endsWith(".ts"))
|
|
16004
|
-
h.update(`${relative2(root, p)}\x00`).update(
|
|
16318
|
+
h.update(`${relative2(root, p)}\x00`).update(readFileSync31(p)).update("\x00");
|
|
16005
16319
|
}
|
|
16006
16320
|
};
|
|
16007
16321
|
walk(root);
|
|
16008
16322
|
return h.digest("hex");
|
|
16009
16323
|
}
|
|
16010
|
-
function computeProducerFingerprint(root =
|
|
16324
|
+
function computeProducerFingerprint(root = resolve12(import.meta.dir, ".."), injected = globalThis.__LOKI_PRODUCER_FP__) {
|
|
16011
16325
|
if (typeof injected === "string" && /^[0-9a-f]{64}$/.test(injected))
|
|
16012
16326
|
return injected;
|
|
16013
16327
|
try {
|
|
@@ -16024,23 +16338,23 @@ var init_producer_fingerprint = () => {};
|
|
|
16024
16338
|
|
|
16025
16339
|
// ../../loki-ts/src/engine10/cache.ts
|
|
16026
16340
|
import { createHash as createHash8 } from "crypto";
|
|
16027
|
-
import { chmodSync as chmodSync5, existsSync as existsSync22, mkdirSync as mkdirSync14, readdirSync as readdirSync18, readFileSync as
|
|
16028
|
-
import { basename as basename10, resolve as
|
|
16341
|
+
import { chmodSync as chmodSync5, existsSync as existsSync22, mkdirSync as mkdirSync14, readdirSync as readdirSync18, readFileSync as readFileSync32, renameSync as renameSync6, statSync as statSync15, unlinkSync as unlinkSync4, writeFileSync as writeFileSync15 } from "fs";
|
|
16342
|
+
import { basename as basename10, resolve as resolve13 } from "path";
|
|
16029
16343
|
function repoKey(originUrl, repoDir) {
|
|
16030
|
-
const basis = originUrl && originUrl.trim() !== "" ? originUrl :
|
|
16344
|
+
const basis = originUrl && originUrl.trim() !== "" ? originUrl : resolve13(repoDir);
|
|
16031
16345
|
return createHash8("sha256").update(basis).digest("hex");
|
|
16032
16346
|
}
|
|
16033
16347
|
function defaultCacheRoot() {
|
|
16034
|
-
return
|
|
16348
|
+
return resolve13(homeLokiDir(), "cache", "v10");
|
|
16035
16349
|
}
|
|
16036
16350
|
function repoCacheDir(key, cacheRoot = defaultCacheRoot()) {
|
|
16037
|
-
return
|
|
16351
|
+
return resolve13(cacheRoot, key);
|
|
16038
16352
|
}
|
|
16039
16353
|
function readJson3(path, isValid = (_v) => true) {
|
|
16040
16354
|
if (!existsSync22(path))
|
|
16041
16355
|
return null;
|
|
16042
16356
|
try {
|
|
16043
|
-
const parsed = JSON.parse(
|
|
16357
|
+
const parsed = JSON.parse(readFileSync32(path, "utf8"));
|
|
16044
16358
|
return isValid(parsed) ? parsed : null;
|
|
16045
16359
|
} catch {
|
|
16046
16360
|
return null;
|
|
@@ -16070,7 +16384,7 @@ function writeJson(path, dir, data) {
|
|
|
16070
16384
|
function pruneCache(dir, prefix, keepPath, keep = prefix === "slice-" ? 500 : 5) {
|
|
16071
16385
|
const mt = (f) => {
|
|
16072
16386
|
try {
|
|
16073
|
-
return statSync15(
|
|
16387
|
+
return statSync15(resolve13(dir, f)).mtimeMs;
|
|
16074
16388
|
} catch {
|
|
16075
16389
|
return 0;
|
|
16076
16390
|
}
|
|
@@ -16078,7 +16392,7 @@ function pruneCache(dir, prefix, keepPath, keep = prefix === "slice-" ? 500 : 5)
|
|
|
16078
16392
|
try {
|
|
16079
16393
|
readdirSync18(dir).filter((f) => f.startsWith(prefix) && f.endsWith(".json") && f !== basename10(keepPath)).sort((x, y) => mt(y) - mt(x) || (x < y ? 1 : -1)).slice(keep - 1).forEach((f) => {
|
|
16080
16394
|
try {
|
|
16081
|
-
unlinkSync4(
|
|
16395
|
+
unlinkSync4(resolve13(dir, f));
|
|
16082
16396
|
} catch {}
|
|
16083
16397
|
});
|
|
16084
16398
|
} catch {}
|
|
@@ -16101,10 +16415,10 @@ var tmpSeq = 0, LEGACY_PREFIX, writeAndPrune = (path, dir, prefix, data) => {
|
|
|
16101
16415
|
const old = LEGACY_PREFIX[prefix];
|
|
16102
16416
|
if (old)
|
|
16103
16417
|
pruneCache(dir, old, path, 1);
|
|
16104
|
-
}, cacheFileName = (kind, tree, fp = producerFingerprint()) => `${kind}-${fp.slice(0, 16)}-${tree}.json`, readRepoMapCache = (dir, tree, fp = producerFingerprint()) => readJson3(
|
|
16418
|
+
}, cacheFileName = (kind, tree, fp = producerFingerprint()) => `${kind}-${fp.slice(0, 16)}-${tree}.json`, readRepoMapCache = (dir, tree, fp = producerFingerprint()) => readJson3(resolve13(dir, cacheFileName("repomap", tree, fp)), isRepoMap), writeRepoMapCache = (dir, tree, map, fp = producerFingerprint()) => writeAndPrune(resolve13(dir, cacheFileName("repomap", tree, fp)), dir, "repomap-", map), readTestMapCache = (dir, tree, fp = producerFingerprint()) => readJson3(resolve13(dir, cacheFileName("testmap", tree, fp)), isTestMap), writeTestMapCache = (dir, tree, map, fp = producerFingerprint()) => writeAndPrune(resolve13(dir, cacheFileName("testmap", tree, fp)), dir, "testmap-", map), cacheStats, cachedRepoMap = (dir, tree, build, fp = producerFingerprint()) => viaCache(readRepoMapCache(dir, tree, fp), build, (m) => writeRepoMapCache(dir, tree, m, fp)), sliceKey = (card, baseSha) => createHash8("sha256").update(`${card.length}:${card}\x00${baseSha}`).digest("hex"), isJournalEntry = (v) => {
|
|
16105
16419
|
const e = v;
|
|
16106
16420
|
return typeof e === "object" && e !== null && typeof e.gid === "string" && typeof e.id === "string" && typeof e.head === "string" && Number.isInteger(e.n);
|
|
16107
|
-
}, readSliceJournal = (dir, key) => readJson3(
|
|
16421
|
+
}, readSliceJournal = (dir, key) => readJson3(resolve13(dir, `slice-${key}.json`), isJournalEntry), writeSliceJournal = (dir, key, entry) => writeAndPrune(resolve13(dir, `slice-${key}.json`), dir, "slice-", entry);
|
|
16108
16422
|
var init_cache2 = __esm(() => {
|
|
16109
16423
|
init_paths();
|
|
16110
16424
|
init_producer_fingerprint();
|
|
@@ -16113,13 +16427,13 @@ var init_cache2 = __esm(() => {
|
|
|
16113
16427
|
});
|
|
16114
16428
|
|
|
16115
16429
|
// ../../loki-ts/src/util/lock_ecosystems.ts
|
|
16116
|
-
import { existsSync as existsSync23, readdirSync as readdirSync19, readFileSync as
|
|
16430
|
+
import { existsSync as existsSync23, readdirSync as readdirSync19, readFileSync as readFileSync33 } from "fs";
|
|
16117
16431
|
import { basename as basename11, dirname as dirname11, join as join38 } from "path";
|
|
16118
16432
|
function isYarnBerry(dir) {
|
|
16119
16433
|
if (existsSync23(join38(dir, ".yarnrc.yml")))
|
|
16120
16434
|
return true;
|
|
16121
16435
|
try {
|
|
16122
|
-
return /^yarn@([2-9]|\d{2,})/.test(String(JSON.parse(
|
|
16436
|
+
return /^yarn@([2-9]|\d{2,})/.test(String(JSON.parse(readFileSync33(join38(dir, "package.json"), "utf8")).packageManager ?? ""));
|
|
16123
16437
|
} catch {
|
|
16124
16438
|
return false;
|
|
16125
16439
|
}
|
|
@@ -16160,7 +16474,7 @@ function declaredPythonDeps(repoDir, manifests) {
|
|
|
16160
16474
|
for (const f of manifests) {
|
|
16161
16475
|
let t;
|
|
16162
16476
|
try {
|
|
16163
|
-
t =
|
|
16477
|
+
t = readFileSync33(join38(repoDir, f), "utf8");
|
|
16164
16478
|
} catch {
|
|
16165
16479
|
continue;
|
|
16166
16480
|
}
|
|
@@ -16369,7 +16683,7 @@ function addedManifestOk(f, c, wall, esc, notes) {
|
|
|
16369
16683
|
return false;
|
|
16370
16684
|
const text4 = c.head ? g(["show", `${c.head}:${f}`]) : (() => {
|
|
16371
16685
|
try {
|
|
16372
|
-
return
|
|
16686
|
+
return readFileSync33(join38(c.repoDir, f), "utf8");
|
|
16373
16687
|
} catch {
|
|
16374
16688
|
return null;
|
|
16375
16689
|
}
|
|
@@ -16436,7 +16750,7 @@ function addedManifestOk(f, c, wall, esc, notes) {
|
|
|
16436
16750
|
}
|
|
16437
16751
|
var has = (rest, ...f) => rest.some((x) => f.includes(x)), withFlag = (rest, flag) => rest.includes(flag) ? rest : [...rest, flag], text3 = (dir, file) => {
|
|
16438
16752
|
try {
|
|
16439
|
-
return
|
|
16753
|
+
return readFileSync33(join38(dir, file), "utf8");
|
|
16440
16754
|
} catch {
|
|
16441
16755
|
return null;
|
|
16442
16756
|
}
|
|
@@ -16853,11 +17167,11 @@ var init_linguist = __esm(() => {
|
|
|
16853
17167
|
});
|
|
16854
17168
|
|
|
16855
17169
|
// ../../loki-ts/src/util/runner_boot.ts
|
|
16856
|
-
import { readFileSync as
|
|
17170
|
+
import { readFileSync as readFileSync34 } from "fs";
|
|
16857
17171
|
import { join as join40 } from "path";
|
|
16858
17172
|
var HITS_TOKEN = "__LOKI_HITS__", pytestBoot = (cmd) => {
|
|
16859
17173
|
const f = (n3, to) => `cat >"$B/${to}" <<'LOKI_VPR_PY'
|
|
16860
|
-
${
|
|
17174
|
+
${readFileSync34(join40(REPO_ROOT, "scripts/vpr-pytest-boot", n3), "utf8")}LOKI_VPR_PY`;
|
|
16861
17175
|
return [
|
|
16862
17176
|
`: ${HITS_TOKEN}`,
|
|
16863
17177
|
'B=$(mktemp -d "${TMPDIR:-/tmp}/loki-vpr.XXXXXX") || exit 125',
|
|
@@ -17023,7 +17337,7 @@ var init_test_file_text = __esm(() => {
|
|
|
17023
17337
|
});
|
|
17024
17338
|
|
|
17025
17339
|
// ../../loki-ts/src/util/context_pack.ts
|
|
17026
|
-
import { closeSync as closeSync8, openSync as openSync8, readdirSync as readdirSync20, readFileSync as
|
|
17340
|
+
import { closeSync as closeSync8, openSync as openSync8, readdirSync as readdirSync20, readFileSync as readFileSync35, readSync as readSync7, statSync as statSync16 } from "fs";
|
|
17027
17341
|
import { join as join41 } from "path";
|
|
17028
17342
|
function langOf(path) {
|
|
17029
17343
|
if (/\.[cm]?[jt]sx?$/.test(path))
|
|
@@ -17363,7 +17677,7 @@ function contextPack(repoDir, task, files, symbolIndex = [], budgetTokens = PACK
|
|
|
17363
17677
|
return false;
|
|
17364
17678
|
let src;
|
|
17365
17679
|
try {
|
|
17366
|
-
src =
|
|
17680
|
+
src = readFileSync35(join41(repoDir, p), "utf8");
|
|
17367
17681
|
} catch {
|
|
17368
17682
|
return false;
|
|
17369
17683
|
}
|
|
@@ -17556,7 +17870,7 @@ function contextCoverage(implement, nameStatus, repoDir) {
|
|
|
17556
17870
|
const iter = Array.isArray(implement?.["iteration_ids"]) ? implement["iteration_ids"][0] : undefined;
|
|
17557
17871
|
if (typeof iter === "string" && /^[\w.-]+$/.test(iter)) {
|
|
17558
17872
|
try {
|
|
17559
|
-
const r = JSON.parse(
|
|
17873
|
+
const r = JSON.parse(readFileSync35(join41(repoDir, ".loki", "metrics", `result-cost-${iter}.json`), "utf8"));
|
|
17560
17874
|
if (typeof r["reads_before_first_edit"] === "number")
|
|
17561
17875
|
reads = r["reads_before_first_edit"];
|
|
17562
17876
|
} catch {}
|
|
@@ -18077,171 +18391,6 @@ var init_decompose = __esm(() => {
|
|
|
18077
18391
|
MS_KEY_RE = /^milestones:\s*$/i;
|
|
18078
18392
|
});
|
|
18079
18393
|
|
|
18080
|
-
// ../../loki-ts/src/util/claude_model.ts
|
|
18081
|
-
var exports_claude_model = {};
|
|
18082
|
-
__export(exports_claude_model, {
|
|
18083
|
-
resolveClaudeModel: () => resolveClaudeModel,
|
|
18084
|
-
isUnresolvedClaudeAlias: () => isUnresolvedClaudeAlias,
|
|
18085
|
-
haikuRun: () => haikuRun,
|
|
18086
|
-
explicitSetupModel: () => explicitSetupModel,
|
|
18087
|
-
claudeTierRank: () => claudeTierRank,
|
|
18088
|
-
claudeThinkingSubstitute: () => claudeThinkingSubstitute,
|
|
18089
|
-
claudeThinkingMaxEffort: () => claudeThinkingMaxEffort,
|
|
18090
|
-
claudeThinkingHasAdaptive: () => claudeThinkingHasAdaptive,
|
|
18091
|
-
claudeThinkingAccepted: () => claudeThinkingAccepted,
|
|
18092
|
-
claudeEffortLevels: () => claudeEffortLevels,
|
|
18093
|
-
chooseSessionModel: () => chooseSessionModel,
|
|
18094
|
-
canonicalSessionPin: () => canonicalSessionPin,
|
|
18095
|
-
VALID_TIERS: () => VALID_TIERS,
|
|
18096
|
-
PROVIDER_DEFAULT_MODEL: () => PROVIDER_DEFAULT_MODEL,
|
|
18097
|
-
GENERIC_TIERS: () => GENERIC_TIERS,
|
|
18098
|
-
EXPLICIT_MODEL_ENV: () => EXPLICIT_MODEL_ENV,
|
|
18099
|
-
DEFAULT_SESSION_MODEL: () => DEFAULT_SESSION_MODEL
|
|
18100
|
-
});
|
|
18101
|
-
import { readFileSync as readFileSync35 } from "fs";
|
|
18102
|
-
import { resolve as resolve13 } from "path";
|
|
18103
|
-
function resolveClaudeModel(want) {
|
|
18104
|
-
try {
|
|
18105
|
-
const path = process.env["LOKI_MODEL_CATALOG"] || resolve13(REPO_ROOT, "providers/model_catalog.json");
|
|
18106
|
-
return JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.cli_aliases?.[want] ?? want;
|
|
18107
|
-
} catch {
|
|
18108
|
-
return want;
|
|
18109
|
-
}
|
|
18110
|
-
}
|
|
18111
|
-
function isUnresolvedClaudeAlias(model) {
|
|
18112
|
-
return FAMILY_ALIASES.has(model);
|
|
18113
|
-
}
|
|
18114
|
-
function claudeTierRank(model) {
|
|
18115
|
-
try {
|
|
18116
|
-
const path = process.env["LOKI_MODEL_CATALOG"] || resolve13(REPO_ROOT, "providers/model_catalog.json");
|
|
18117
|
-
const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
|
|
18118
|
-
if (!Array.isArray(models))
|
|
18119
|
-
return null;
|
|
18120
|
-
const order2 = [];
|
|
18121
|
-
for (const m of models)
|
|
18122
|
-
if (m.tier !== "legacy" && !order2.includes(m.tier))
|
|
18123
|
-
order2.push(m.tier);
|
|
18124
|
-
const id = resolveClaudeModel(model);
|
|
18125
|
-
const hit = models.find((m) => m.id === id || m.alias === model);
|
|
18126
|
-
const rank = hit ? order2.indexOf(hit.tier) : -1;
|
|
18127
|
-
return rank >= 0 ? rank : null;
|
|
18128
|
-
} catch {
|
|
18129
|
-
return null;
|
|
18130
|
-
}
|
|
18131
|
-
}
|
|
18132
|
-
function claudeEffortLevels(model) {
|
|
18133
|
-
try {
|
|
18134
|
-
const path = process.env["LOKI_MODEL_CATALOG"] || resolve13(REPO_ROOT, "providers/model_catalog.json");
|
|
18135
|
-
const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
|
|
18136
|
-
if (!Array.isArray(models))
|
|
18137
|
-
return null;
|
|
18138
|
-
const id = resolveClaudeModel(model);
|
|
18139
|
-
const levels = models.find((m) => m.id === id || m.alias === model)?.effort?.levels;
|
|
18140
|
-
return Array.isArray(levels) ? levels : null;
|
|
18141
|
-
} catch {
|
|
18142
|
-
return null;
|
|
18143
|
-
}
|
|
18144
|
-
}
|
|
18145
|
-
function claudeThinkingSpec(model) {
|
|
18146
|
-
try {
|
|
18147
|
-
const path = process.env["LOKI_MODEL_CATALOG"] || resolve13(REPO_ROOT, "providers/model_catalog.json");
|
|
18148
|
-
const models = JSON.parse(readFileSync35(path, "utf8")).providers?.claude?.models;
|
|
18149
|
-
if (!Array.isArray(models))
|
|
18150
|
-
return null;
|
|
18151
|
-
const id = resolveClaudeModel(model);
|
|
18152
|
-
return models.find((m) => m.id === id || m.alias === model)?.thinking ?? null;
|
|
18153
|
-
} catch {
|
|
18154
|
-
return null;
|
|
18155
|
-
}
|
|
18156
|
-
}
|
|
18157
|
-
function claudeThinkingMaxEffort(model, type) {
|
|
18158
|
-
const max = claudeThinkingSpec(model)?.max_effort?.[type];
|
|
18159
|
-
return typeof max === "string" ? max : null;
|
|
18160
|
-
}
|
|
18161
|
-
function claudeThinkingSubstitute(model, type) {
|
|
18162
|
-
const sub = claudeThinkingSpec(model)?.substitute?.[type];
|
|
18163
|
-
return typeof sub === "string" ? sub : null;
|
|
18164
|
-
}
|
|
18165
|
-
function claudeThinkingAccepted(model, type) {
|
|
18166
|
-
const spec = claudeThinkingSpec(model);
|
|
18167
|
-
if (!spec || !Array.isArray(spec.types))
|
|
18168
|
-
return true;
|
|
18169
|
-
return spec.types.includes(type) || typeof spec.substitute?.[type] === "string";
|
|
18170
|
-
}
|
|
18171
|
-
function claudeThinkingHasAdaptive(model) {
|
|
18172
|
-
const types = claudeThinkingSpec(model)?.types;
|
|
18173
|
-
return Array.isArray(types) && types.includes("adaptive");
|
|
18174
|
-
}
|
|
18175
|
-
function canonicalSessionPin(raw2) {
|
|
18176
|
-
const v = (raw2 ?? "").trim().toLowerCase();
|
|
18177
|
-
if (!v)
|
|
18178
|
-
return;
|
|
18179
|
-
const pin = GENERIC_TIERS[v] ?? v;
|
|
18180
|
-
if (!VALID_TIERS.has(pin)) {
|
|
18181
|
-
throw new Error(`unknown LOKI_SESSION_MODEL '${(raw2 ?? "").trim()}' (small|medium|high, planning|development|fast, or opus|sonnet|haiku|fable)`);
|
|
18182
|
-
}
|
|
18183
|
-
return pin;
|
|
18184
|
-
}
|
|
18185
|
-
function explicitSetupModel(tier, e = process.env) {
|
|
18186
|
-
if (e["LOKI_LEGACY_TIER_SWITCHING"] === "true")
|
|
18187
|
-
return;
|
|
18188
|
-
const sess = (e["LOKI_SESSION_MODEL"] ?? "").trim().toLowerCase();
|
|
18189
|
-
if (tier === "planning" && (sess === "high" || sess === "planning"))
|
|
18190
|
-
return e["LOKI_CLAUDE_MODEL_PLANNING"] || e["LOKI_MODEL_PLANNING"] ? undefined : "opus";
|
|
18191
|
-
if (tier !== "fast" || sess !== "small" && sess !== "fast" || e["LOKI_CLAUDE_MODEL_FAST"] || e["LOKI_MODEL_FAST"])
|
|
18192
|
-
return;
|
|
18193
|
-
return e["LOKI_ALLOW_HAIKU"] === undefined || e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : undefined;
|
|
18194
|
-
}
|
|
18195
|
-
function chooseSessionModel(e = process.env) {
|
|
18196
|
-
const carried = canonicalSessionPin(e["LOKI_SESSION_MODEL"]);
|
|
18197
|
-
if (e["LOKI_SESSION_MODEL_SOURCE"] === "default" && carried && EXPLICIT_MODEL_ENV.every((k) => k === "LOKI_SESSION_MODEL" || (e[k] ?? "").trim() === ""))
|
|
18198
|
-
return { source: "default", pin: carried, why: "Loki default, carried from the parent run" };
|
|
18199
|
-
const named = EXPLICIT_MODEL_ENV.find((k) => (e[k] ?? "").trim() !== "");
|
|
18200
|
-
if (named)
|
|
18201
|
-
return { source: "explicit", pin: null, why: named === "LOKI_SESSION_MODEL" ? "--session-model or LOKI_SESSION_MODEL" : named };
|
|
18202
|
-
const router = (e["LOKI_ROUTER"] ?? "").trim().toLowerCase();
|
|
18203
|
-
if (["1", "true", "on", "auto"].includes(router))
|
|
18204
|
-
return { source: "explicit", pin: null, why: `LOKI_ROUTER=${router}` };
|
|
18205
|
-
const raw2 = (e["LOKI_DEFAULT_SESSION_MODEL"] ?? "").trim().toLowerCase();
|
|
18206
|
-
if (raw2 === "provider")
|
|
18207
|
-
return { source: "provider", pin: null, why: "LOKI_DEFAULT_SESSION_MODEL=provider (the Claude CLI's own default)" };
|
|
18208
|
-
const pin = canonicalSessionPin(raw2 || DEFAULT_SESSION_MODEL);
|
|
18209
|
-
return { source: "default", pin, why: raw2 ? `LOKI_DEFAULT_SESSION_MODEL=${raw2}` : "Loki default, set another with --session-model or LOKI_DEFAULT_SESSION_MODEL=provider" };
|
|
18210
|
-
}
|
|
18211
|
-
function haikuRun(e = process.env) {
|
|
18212
|
-
const H = /haiku/i, val = (k) => (e[k] ?? "").trim();
|
|
18213
|
-
if (val("LOKI_PROVIDER").toLowerCase() === "opencode")
|
|
18214
|
-
return H.test(val("LOKI_OPENCODE_MODEL"));
|
|
18215
|
-
for (const k of ["LOKI_MODEL_OVERRIDE", "LOKI_MODEL_ROUTE", "LOKI_CLAUDE_MODEL_DEVELOPMENT", "LOKI_MODEL_DEVELOPMENT"])
|
|
18216
|
-
if (val(k))
|
|
18217
|
-
return H.test(val(k));
|
|
18218
|
-
let pin;
|
|
18219
|
-
try {
|
|
18220
|
-
pin = canonicalSessionPin(e["LOKI_SESSION_MODEL"]) ?? chooseSessionModel(e).pin ?? undefined;
|
|
18221
|
-
} catch {
|
|
18222
|
-
return false;
|
|
18223
|
-
}
|
|
18224
|
-
if (pin === "haiku")
|
|
18225
|
-
return true;
|
|
18226
|
-
if (pin === "fast")
|
|
18227
|
-
return H.test(explicitSetupModel("fast", e) ?? (val("LOKI_CLAUDE_MODEL_FAST") || val("LOKI_MODEL_FAST") || (e["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : "sonnet")));
|
|
18228
|
-
if (pin)
|
|
18229
|
-
return false;
|
|
18230
|
-
return routerPreset(e) && H.test(presetExecutor(e).model);
|
|
18231
|
-
}
|
|
18232
|
-
var PROVIDER_DEFAULT_MODEL = "claude (provider default)", FAMILY_ALIASES, VALID_TIERS, GENERIC_TIERS, DEFAULT_SESSION_MODEL = "sonnet", EXPLICIT_MODEL_ENV;
|
|
18233
|
-
var init_claude_model = __esm(() => {
|
|
18234
|
-
init_paths();
|
|
18235
|
-
FAMILY_ALIASES = new Set(["haiku", "sonnet", "opus", "fable"]);
|
|
18236
|
-
VALID_TIERS = new Set(["planning", "development", "fast", "opus", "sonnet", "haiku", "fable"]);
|
|
18237
|
-
GENERIC_TIERS = {
|
|
18238
|
-
small: "fast",
|
|
18239
|
-
medium: "development",
|
|
18240
|
-
high: "planning"
|
|
18241
|
-
};
|
|
18242
|
-
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"];
|
|
18243
|
-
});
|
|
18244
|
-
|
|
18245
18394
|
// ../../loki-ts/src/runner/router/decision.ts
|
|
18246
18395
|
var exports_decision = {};
|
|
18247
18396
|
__export(exports_decision, {
|
|
@@ -19805,13 +19954,14 @@ function routedFix(runModel, out2, o) {
|
|
|
19805
19954
|
return { pin: climbed?.to ?? (cur !== runModel ? cur : undefined), climbed };
|
|
19806
19955
|
}
|
|
19807
19956
|
function stallClimb(runModel, out2, reason) {
|
|
19808
|
-
if (!routerActive() || out2["fix"]?.["stall_escalated"])
|
|
19957
|
+
if (!routerActive() || out2["fix"]?.["stall_escalated"] || roleModel("dev") !== undefined)
|
|
19809
19958
|
return null;
|
|
19810
19959
|
const groups = out2["verify"]?.["failures_grouped"] ?? [];
|
|
19811
19960
|
return routedFix(runModel, out2, { repeated: false, stall: true, groups, reason }).climbed;
|
|
19812
19961
|
}
|
|
19813
19962
|
var isHaiku = (m) => resolveModelAlias(m).toLowerCase().includes("haiku"), runFloor = (runModel) => runModel === PROVIDER_DEFAULT_MODEL ? resolveModelAlias("sonnet") : runModel, routerPinsAllowed = (env = process.env) => envOverride(env) === null, routerActive = (env = process.env) => routerEnabled(env) && routerPinsAllowed(env), leanEnabled = (env = process.env) => ["1", "on", "true"].includes((env["LOKI_LEAN"] ?? "").trim().toLowerCase()), leanStart = (runModel, size, env) => leanEnabled(env) && routerPinsAllowed(env) && (size === "small" || size === "normal") && modelRank(runFloor(runModel)) > modelRank("sonnet") ? resolveModelAlias("sonnet") : null, floorNoAdvisor = (model, advisor) => model && advisor?.available === false && isHaiku(model) ? resolveModelAlias("sonnet") : model;
|
|
19814
19963
|
var init_unit_model = __esm(() => {
|
|
19964
|
+
init_claude_model();
|
|
19815
19965
|
init_sizing();
|
|
19816
19966
|
init_session3();
|
|
19817
19967
|
init_decision();
|
|
@@ -20587,7 +20737,7 @@ var init_update_check = __esm(() => {
|
|
|
20587
20737
|
import { existsSync as existsSync32, mkdirSync as mkdirSync19, readFileSync as readFileSync47, writeFileSync as writeFileSync20 } from "fs";
|
|
20588
20738
|
import { join as join52 } from "path";
|
|
20589
20739
|
function advisorPair(env, executorModel) {
|
|
20590
|
-
return { executor: executorModel || envOverride(env) || "opus", advisor:
|
|
20740
|
+
return { executor: executorModel || envOverride(env) || "opus", advisor: routerAdvisorModel(env) };
|
|
20591
20741
|
}
|
|
20592
20742
|
function isAnthropicHost(raw2) {
|
|
20593
20743
|
let host;
|
|
@@ -20650,7 +20800,7 @@ function recordAdvisorError(runDir, message) {
|
|
|
20650
20800
|
`, { flag: "wx" });
|
|
20651
20801
|
} catch {}
|
|
20652
20802
|
}
|
|
20653
|
-
var ADVISOR_MIN_CLAUDE_CODE = "2.1.293", ADVISOR_ERROR_MARKER = "advisor-error.txt", ADVISOR_ERROR_LIMIT = 3, ROUTER_ADVISOR_MODEL = "opus", CLOUD_FLAGS;
|
|
20803
|
+
var ADVISOR_MIN_CLAUDE_CODE = "2.1.293", ADVISOR_ERROR_MARKER = "advisor-error.txt", ADVISOR_ERROR_LIMIT = 3, ROUTER_ADVISOR_MODEL = "opus", routerAdvisorModel = (env = process.env) => roleValue("advisor", env, "claude") ?? ROUTER_ADVISOR_MODEL, CLOUD_FLAGS;
|
|
20654
20804
|
var init_advisor_probe = __esm(() => {
|
|
20655
20805
|
init_claude_model();
|
|
20656
20806
|
init_update_check();
|
|
@@ -22244,6 +22394,7 @@ __export(exports_repo_profile, {
|
|
|
22244
22394
|
repoReadiness: () => repoReadiness,
|
|
22245
22395
|
renderProfile: () => renderProfile,
|
|
22246
22396
|
redactEvidence: () => redactEvidence,
|
|
22397
|
+
redUnattributableOnBase: () => redUnattributableOnBase,
|
|
22247
22398
|
readinessNotice: () => readinessNotice,
|
|
22248
22399
|
readinessLines: () => readinessLines,
|
|
22249
22400
|
readProfile: () => readProfile,
|
|
@@ -22272,6 +22423,7 @@ __export(exports_repo_profile, {
|
|
|
22272
22423
|
baselineSuites: () => baselineSuites,
|
|
22273
22424
|
baselineSuiteOnDemand: () => baselineSuiteOnDemand,
|
|
22274
22425
|
baselineCmdS: () => baselineCmdS,
|
|
22426
|
+
baseUnattributedOn: () => baseUnattributedOn,
|
|
22275
22427
|
baseRedByIdOn: () => baseRedByIdOn,
|
|
22276
22428
|
baseRedById: () => baseRedById,
|
|
22277
22429
|
baseOnDemandOn: () => baseOnDemandOn,
|
|
@@ -23043,6 +23195,19 @@ function sameUnattributableRed(repoDir, baseSha, full) {
|
|
|
23043
23195
|
return !!b && b.ran && !b.attributable && !b.timed_out && b.reason !== "baseline budget used up" && b.failing_ids.length === 0 && !!b.failing_shape && b.failing_shape === c.shape && b.exit_code === c.exit;
|
|
23044
23196
|
}).map((c) => c.name);
|
|
23045
23197
|
}
|
|
23198
|
+
function redUnattributableOnBase(repoDir, baseSha, full) {
|
|
23199
|
+
if (!baseUnattributedOn())
|
|
23200
|
+
return [];
|
|
23201
|
+
const p = loadProfile(repoDir);
|
|
23202
|
+
if (!p || p.revision !== baseSha)
|
|
23203
|
+
return [];
|
|
23204
|
+
return full.filter((c) => {
|
|
23205
|
+
if (c.result !== "fail" || (c.ids ?? []).length > 0 || typeof c.exit !== "number")
|
|
23206
|
+
return false;
|
|
23207
|
+
const b = baseFor(repoDir, p, c.cmd, true);
|
|
23208
|
+
return !!b && b.ran && !b.attributable && !b.timed_out && b.reason !== "baseline budget used up" && b.failing_ids.length === 0 && typeof b.exit_code === "number" && b.exit_code !== 0 && b.exit_code === c.exit;
|
|
23209
|
+
}).map((c) => c.name);
|
|
23210
|
+
}
|
|
23046
23211
|
function attributeFullSuite(repoDir, baseSha, full, blocked, changed, symbols = [], shownIds = new Set) {
|
|
23047
23212
|
const same = sameUnattributableRed(repoDir, baseSha, full);
|
|
23048
23213
|
const res = attributeFullSuiteById(repoDir, baseSha, same.length ? full.filter((c) => !same.includes(c.name)) : full, blocked, changed, symbols, shownIds);
|
|
@@ -23405,7 +23570,7 @@ ${e}`).slice(-8 * 1024 * 1024), missing: code === 127 };
|
|
|
23405
23570
|
} catch {
|
|
23406
23571
|
return "";
|
|
23407
23572
|
}
|
|
23408
|
-
}, SAME_RED_NOTE = "excused as red on base in the identical kind (same command, same exit code, the same unparseable output shape; no failing id could be compared)", baseRedByIdOn = (env = process.env) => /^(1|on|true|yes)$/i.test((env["LOKI_E10_BASE_RED_BY_ID"] ?? "").trim()), baseRedSuiteOff = (env = process.env) => /^(0|off|false|no)$/i.test((env["LOKI_E10_BASE_RED_BY_ID"] ?? "").trim()), touchedBaseRedOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_TOUCHED_BASE_RED"] ?? "").trim()), collateralBaselineOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_COLLATERAL_BASELINE"] ?? "").trim()), TOUCHED_RED = "edited test file red on base by every failing id with the same errors; the cases the change added or edited pass (excused, not blocking)", STATIC_DIAG, STATIC_NOISE, STATIC_SUMMARY, readinessLines = (r) => [` Readiness: ${r.score}/100 (${r.grade})`, ...r.findings.length ? [" Fix:", ...r.findings.map((f) => ` - ${f.fix}`)] : []];
|
|
23573
|
+
}, baseUnattributedOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_BASE_UNATTRIBUTED"] ?? "").trim()), SAME_RED_NOTE = "excused as red on base in the identical kind (same command, same exit code, the same unparseable output shape; no failing id could be compared)", baseRedByIdOn = (env = process.env) => /^(1|on|true|yes)$/i.test((env["LOKI_E10_BASE_RED_BY_ID"] ?? "").trim()), baseRedSuiteOff = (env = process.env) => /^(0|off|false|no)$/i.test((env["LOKI_E10_BASE_RED_BY_ID"] ?? "").trim()), touchedBaseRedOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_TOUCHED_BASE_RED"] ?? "").trim()), collateralBaselineOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_COLLATERAL_BASELINE"] ?? "").trim()), TOUCHED_RED = "edited test file red on base by every failing id with the same errors; the cases the change added or edited pass (excused, not blocking)", STATIC_DIAG, STATIC_NOISE, STATIC_SUMMARY, readinessLines = (r) => [` Readiness: ${r.score}/100 (${r.grade})`, ...r.findings.length ? [" Fix:", ...r.findings.map((f) => ` - ${f.fix}`)] : []];
|
|
23409
23574
|
var init_repo_profile = __esm(() => {
|
|
23410
23575
|
init_types2();
|
|
23411
23576
|
init_shell();
|
|
@@ -27124,7 +27289,9 @@ function commentMentionsOption(c, comments = []) {
|
|
|
27124
27289
|
}
|
|
27125
27290
|
async function defaultVoteCall(system, prompt) {
|
|
27126
27291
|
const { toolLessCall } = await Promise.resolve().then(() => (init_sdk_invoker(), exports_sdk_invoker)), { modelRouteModel: modelRouteModel2 } = await Promise.resolve().then(() => (init_model_routes(), exports_model_routes));
|
|
27127
|
-
const
|
|
27292
|
+
const vm = process.env["LOKI_E10_PRECEDENT_MODEL"] || roleModel("helper") || modelRouteModel2() || "claude-haiku-5-5";
|
|
27293
|
+
noteRoleModel("helper", vm);
|
|
27294
|
+
const dir = process.env["LOKI_DIR"], r = await toolLessCall({ model: vm, system, prompt, maxTokens: 1024, thinking: "off", timeoutMs: 30000, ...dir ? { ledger: { lokiDir: dir, phase: "precedent-vote" } } : {} });
|
|
27128
27295
|
return r.outcome.kind === "ok" ? r.outcome.value : null;
|
|
27129
27296
|
}
|
|
27130
27297
|
async function voteOpenChoices(task, ctx = {}, call = defaultVoteCall) {
|
|
@@ -27284,6 +27451,7 @@ var AMBIGUITY_RULES, ambiguityThreshold = () => {
|
|
|
27284
27451
|
${c.transplant.test}` : ` Advisory, the sibling tests also check for the target (${c.transplant.why}): ${c.transplant.statements.map((x) => trunc(x, 120)).join(" | ")}` : ""}`;
|
|
27285
27452
|
}, emitChoiceLines = (cs) => cs.filter((c) => c.basis !== "none" || c.precedent || c.any).map(choiceLine), rankedRemedyEnabled = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_RANKED_REMEDY"] ?? "").trim()), REMEDY_HEAD, rankedRemedyBlock = (remedy) => typeof remedy === "string" && remedy ? [`The issue ranks its remedies, and its first choice is: "${remedy}". Treat it as the first named site of the coverage check: implement it, and add any other remedy only on top of it, never in its place.`] : [];
|
|
27286
27453
|
var init_spec_ambiguity = __esm(() => {
|
|
27454
|
+
init_claude_model();
|
|
27287
27455
|
init_context_pack();
|
|
27288
27456
|
init_safe_git();
|
|
27289
27457
|
init_fetch_issue();
|
|
@@ -29020,6 +29188,7 @@ function toolLessGenerator(repoDir) {
|
|
|
29020
29188
|
return async (brief, o) => {
|
|
29021
29189
|
if (o.signal.aborted)
|
|
29022
29190
|
return null;
|
|
29191
|
+
noteRoleModel("test", resolveClaudeModel(o.model));
|
|
29023
29192
|
const r = await toolLessCall({ model: resolveClaudeModel(o.model), prompt: brief, maxTokens: o.maxTokens ?? 4096, thinking: "low", timeoutMs: 120000, ledger: { lokiDir: join75(repoDir, ".loki"), phase: EXEC_SPEC_LEDGER_PHASE } });
|
|
29024
29193
|
if (o.meter)
|
|
29025
29194
|
o.meter.usd = r.usd;
|
|
@@ -29408,7 +29577,7 @@ var execSpecEnabled = (env = process.env) => keptUnderLean(env.LOKI_E10_EXEC_SPE
|
|
|
29408
29577
|
}, capSites = (uncovered, task) => {
|
|
29409
29578
|
const d = defectSites(task);
|
|
29410
29579
|
return uncovered.filter((x) => d.has(x));
|
|
29411
|
-
}, generatorOverride = null, execSpecModel = (env = process.env) => env.LOKI_E10_EXEC_SPEC_MODEL || "haiku", EXEC_SPEC_LEDGER_PHASE = "exec_spec", defaultGenerator = (sessions, repoDir, env = process.env) => env.LOKI_E10_INVOKER === "cli" ? sessionGenerator(sessions) : toolLessGenerator(repoDir), EXEC_SPEC_REPLY = "spec_reply.md", RELATION_FILE_GO = "loki_wall_relation_test.go", RELATION_WRAP_PREFIX = "loki: ", OBSERVABLE_ARG, WRAP_TERM, WRAP_ASK, WRAP_NEGATED, WRAP_TEXT, statesWrapRelation = (task) => task.replace(/```[\s\S]*?```/g, `
|
|
29580
|
+
}, generatorOverride = null, execSpecModel = (env = process.env) => env.LOKI_E10_EXEC_SPEC_MODEL || roleModel("test", env) || "haiku", EXEC_SPEC_LEDGER_PHASE = "exec_spec", defaultGenerator = (sessions, repoDir, env = process.env) => env.LOKI_E10_INVOKER === "cli" ? sessionGenerator(sessions) : toolLessGenerator(repoDir), EXEC_SPEC_REPLY = "spec_reply.md", RELATION_FILE_GO = "loki_wall_relation_test.go", RELATION_WRAP_PREFIX = "loki: ", OBSERVABLE_ARG, WRAP_TERM, WRAP_ASK, WRAP_NEGATED, WRAP_TEXT, statesWrapRelation = (task) => task.replace(/```[\s\S]*?```/g, `
|
|
29412
29581
|
|
|
29413
29582
|
`).split(/(?<=[.!?])\s+(?=[A-Z`])|\n\s*\n|\n(?=\s*(?:[-*]|\d+[.)])\s)/).some((u) => WRAP_TERM.test(u) && WRAP_ASK.test(u) && !WRAP_NEGATED.test(u) && !WRAP_TEXT.test(u)), relCall = (spec, x) => spec.returns ? `func() string { return fmt.Sprint(${spec.fn}(${x})) }` : `func() string { ${spec.fn}(${x}); return "" }`, relHeader = (pkg) => `package ${pkg}
|
|
29414
29583
|
|
|
@@ -34165,12 +34334,12 @@ async function runExtraAttempts(ctx, signal, deps, score, call) {
|
|
|
34165
34334
|
outputs: () => ctx.outputs(),
|
|
34166
34335
|
keep: (p) => userUntracked.has(p) || deps.wallPaths.includes(p) || owned(p),
|
|
34167
34336
|
runSession: (i, cwd, sig2) => {
|
|
34168
|
-
const o = { stage: "implement", brief: variantBrief(deps.brief, i), tier: "development", iterationId: ids[i - 1], limitS: deps.limitS, signal: sig2, cwd, ...attemptModel(i, deps.model) ? { model: attemptModel(i, deps.model) } : {} };
|
|
34337
|
+
const o = { stage: "implement", brief: variantBrief(deps.brief, i), tier: "development", iterationId: ids[i - 1], limitS: deps.limitS, signal: sig2, cwd, ...attemptModel(i, deps.model) ? { model: attemptModel(i, deps.model) } : {}, ...attemptListPinned() ? { pinSource: "specific" } : {} };
|
|
34169
34338
|
return ctx.sessions.run(o);
|
|
34170
34339
|
},
|
|
34171
34340
|
score
|
|
34172
34341
|
});
|
|
34173
|
-
const reviewCall = call ?? (attemptsReviewOn() ? consultCallFor(attemptsReviewModel(), process.env.LOKI_DIR ?? join85(ctx.repoDir, ".loki"), process.env, 180000, { maxTokens: 1500, thinking: "off" }) : undefined);
|
|
34342
|
+
const reviewCall = call ?? (attemptsReviewOn() ? consultCallFor(attemptsReviewModel(), process.env.LOKI_DIR ?? join85(ctx.repoDir, ".loki"), process.env, 180000, { maxTokens: 1500, thinking: "off", role: "review" }) : undefined);
|
|
34174
34343
|
const review = reviewCall ? (tied) => reviewTie(reviewCall, reviewContext(ctx.repoDir, ctx.baseSha, String(ctx.outputs().intake?.task ?? ""), tied.map((t) => t.diff)), tied) : undefined;
|
|
34175
34344
|
try {
|
|
34176
34345
|
const r = await runAttempts({ ...ops, ...review ? { review } : {} }, deps.k, signal);
|
|
@@ -34193,8 +34362,8 @@ ${v}`;
|
|
|
34193
34362
|
}, AttemptsRestoreError, diffLines = (d) => d.split(`
|
|
34194
34363
|
`).filter((l) => /^[+-][^+-]/.test(l)).length, ERRORED, INCUMBENT, untracked2 = (root) => safeGit(root, ["ls-files", "-z", "--others", "--exclude-standard", "--", ".", ...ATTEMPT_EXCLUDES.map((e) => `:(exclude)${e}`)]).split("\x00").filter((p) => p.length > 0), ATTEMPTS_TMP_PREFIX = "loki-attempts-", attemptsReviewModel = (env = process.env) => {
|
|
34195
34364
|
const m = (env.LOKI_E10_SELECT_REVIEW_MODEL || env.LOKI_E10_ATTEMPTS_REVIEW_MODEL || "").trim();
|
|
34196
|
-
return m ? resolveClaudeModel(m) : "claude-sonnet-5-5";
|
|
34197
|
-
}, attemptsReviewOn = (env = process.env) => env.LOKI_E10_ATTEMPTS_REVIEW !== "0", CONVENTION_FILES, STYLE_FILES2, CAP, clip4 = (s, n3) => s.length > n3 ? `${s.slice(0, n3)}
|
|
34365
|
+
return m ? resolveClaudeModel(m) : roleModel("review", env) ?? "claude-sonnet-5-5";
|
|
34366
|
+
}, attemptListPinned = (env = process.env) => (env.LOKI_E10_ATTEMPT_MODELS ?? "").trim() !== "" && roleModel("dev", env) !== undefined, attemptsReviewOn = (env = process.env) => env.LOKI_E10_ATTEMPTS_REVIEW !== "0", CONVENTION_FILES, STYLE_FILES2, CAP, clip4 = (s, n3) => s.length > n3 ? `${s.slice(0, n3)}
|
|
34198
34367
|
[... truncated at ${n3} characters]` : s, NEW_FILE_MAX = 64000, touchedPaths = (diff) => [...new Set([...diff.matchAll(/^diff --git a\/(.+?) b\//gm)].map((m) => m[1]))], REVIEW_SYSTEM;
|
|
34199
34368
|
var init_attempts = __esm(() => {
|
|
34200
34369
|
init_credential_env();
|
|
@@ -35402,8 +35571,10 @@ async function runTournament(c, llm, io, o) {
|
|
|
35402
35571
|
function toolLessLlm(model = tournamentModel(), env = process.env) {
|
|
35403
35572
|
return async (system, user, tag) => {
|
|
35404
35573
|
const lokiDir2 = env.LOKI_DIR, maxTokens = tag === "judge" ? 2048 : 8192;
|
|
35405
|
-
const
|
|
35406
|
-
|
|
35574
|
+
const use = env.LOKI_E10_TOURNAMENT_MODEL ? model : roleModel(tag === "judge" ? "review" : "dev", env) ?? model;
|
|
35575
|
+
noteRoleModel(tag === "judge" ? "review" : "dev", use);
|
|
35576
|
+
const r = await toolLessCall({ model: use, system, prompt: user, maxTokens, thinking: "off", timeoutMs: 180000, ...lokiDir2 ? { ledger: { lokiDir: lokiDir2, phase: `tournament-${tag}` } } : {} });
|
|
35577
|
+
return { text: r.outcome.kind === "ok" ? r.outcome.value : "", usage: { costUsd: r.usd ?? 0 }, outcome: r.outcome.kind === "unsupported" ? `unsupported: ${r.outcome.reason}` : r.outcome.kind };
|
|
35407
35578
|
};
|
|
35408
35579
|
}
|
|
35409
35580
|
function writeTournamentInput(runDir, o) {
|
|
@@ -35708,6 +35879,7 @@ var tournamentEnabled = (env = process.env) => env.LOKI_E10_TOURNAMENT !== "0",
|
|
|
35708
35879
|
}
|
|
35709
35880
|
}, FILE_CAP = 24000, TOTAL_CAP = 60000, skipped = (reason, extra = {}) => ({ status: "skipped", reason, ...extra }), TOURNAMENT_UNDO_FILE = "tournament-undo.json";
|
|
35710
35881
|
var init_tournament = __esm(() => {
|
|
35882
|
+
init_claude_model();
|
|
35711
35883
|
init_check_result();
|
|
35712
35884
|
init_sdk_invoker();
|
|
35713
35885
|
init_safe_git();
|
|
@@ -39190,7 +39362,7 @@ async function issueLineCheck(ctx, asks, head, checks2, reply, facts = []) {
|
|
|
39190
39362
|
return { model, outcome: "no_diff", usd: null, calls: 0, input_chars: 0, diff_cut: [], diff_truncated: false, not_reviewed: "the diff could not be read" };
|
|
39191
39363
|
const cd = lineCheckDiff(d.stdout), prompt = lineCheckPrompt(asks, cd.text, (n3?.stdout ?? "").split(`
|
|
39192
39364
|
`).filter(Boolean), checks2, reply, facts);
|
|
39193
|
-
const call = lineCheckOverride ?? consultCallFor(model, join101(ctx.repoDir, ".loki"), process.env, 120000, { maxTokens: 8000, thinking: "off" });
|
|
39365
|
+
const call = lineCheckOverride ?? consultCallFor(model, join101(ctx.repoDir, ".loki"), process.env, 120000, { maxTokens: 8000, thinking: "off", role: "review" });
|
|
39194
39366
|
let usd = null, calls = 0, outcome = "failed", parsed = null;
|
|
39195
39367
|
for (let i = 0;i < 2 && !parsed; i++) {
|
|
39196
39368
|
let r;
|
|
@@ -39232,7 +39404,8 @@ async function crossReview(ctx, verdict, head, signal, early = false) {
|
|
|
39232
39404
|
}
|
|
39233
39405
|
}
|
|
39234
39406
|
}
|
|
39235
|
-
const
|
|
39407
|
+
const reviewRole = p === "claude" ? roleModel("review", process.env, "claude") : undefined;
|
|
39408
|
+
const pin = (reviewRole && isClaudeModel(reviewRole) ? reviewRole : undefined) ?? (medium && p === "claude" ? fastTierModel(process.env) : dflt && p === "claude" && ctx.model && ctx.model !== PROVIDER_DEFAULT_MODEL ? capToSessionPin(ctx.model) : undefined);
|
|
39236
39409
|
const tag = (r) => {
|
|
39237
39410
|
const modelRan = r.level !== "not_run", level = hy.length && (r.level === "pass" || r.level === "not_run") ? "flag" : r.level;
|
|
39238
39411
|
return { ...r, level, notes: hyNote ? [...r.notes, hyNote] : r.notes, ...hy.length ? { hygiene: hy } : {}, reviewed_by: modelRan ? "model" : hyOk ? "deterministic" : "none", ...modelRan && p === "claude" && (agent?.model || pin) ? { reviewer_model: agent?.model || pin } : {}, ...dflt ? { same_vendor_default: true } : {} };
|
|
@@ -39262,6 +39435,8 @@ Review ONLY the diff below. Do not modify files.` : "You are an independent code
|
|
|
39262
39435
|
try {
|
|
39263
39436
|
if (p === "claude")
|
|
39264
39437
|
await ensureClaudeHelpCache();
|
|
39438
|
+
if (p === "claude")
|
|
39439
|
+
noteRoleModel("review", agent?.model || pin || ctx.model);
|
|
39265
39440
|
const r = await withChildLedger(run, join101(ctx.repoDir, ".loki"), "xreview")(reviewArgv(p, prompt, process.env, p === "claude" ? agent?.model || pin : undefined), { cwd: ctx.repoDir, timeoutMs: boxFor(ctx) * 1000, group: true, signal });
|
|
39266
39441
|
const costId = `${ctx.runId}-xreview-${p}${early ? "-early" : ""}`;
|
|
39267
39442
|
writeReviewerCost(join101(ctx.repoDir, ".loki"), costId, { reviewer: `xreview-${p}`, provider: p, model: p === "claude" ? agent?.model || pin : undefined, stdout: r.stdout, stderr: r.stderr });
|
|
@@ -39275,7 +39450,7 @@ Review ONLY the diff below. Do not modify files.` : "You are an independent code
|
|
|
39275
39450
|
var modelReviewRan = (xr) => !!xr && xr.level !== "not_run" && xr.reviewed_by !== "deterministic" && xr.reviewed_by !== "none", COMPILED_PATHS, hygieneFindings = (paths, ignored = new Set) => paths.filter((f) => !f.startsWith(".loki/") && (COMPILED_PATHS.some((re) => re.test(f)) || ignored.has(f))), RANK3, MAX_NOTES = 5, reviewRanWording = (xr) => modelReviewRan(xr) ? xr.reviewer_model ? `reviewer (${xr.reviewer_model})` : "reviewer" : xr?.reviewed_by === "deterministic" ? "deterministic check" : "none", REVIEW_TOOLS_NOTE = "Your tools are Read, Grep, Glob and a read-only shell (cat, ls, grep, rg, find, head, tail, wc). No git commands are available; the diff is in this prompt. You cannot edit files or run project code or tests, so trace behaviour by reading the code. If a tool fails or you could not inspect something, say so plainly in your reasons.", clean4 = (s) => capWhole(s.replace(/[\x00-\x1f\x7f`]+/g, " "), 600), UNMET_REASON_RE, isUnmetNote = (note2) => /^cross-review \w+ \([^)]*\):\s*\**UNMET\b/.test(note2), reviewDefaultOn = (tier, env = process.env) => tier === "high" || tier === "medium" && env["LOKI_REVIEW_DEFAULT"] === "1", reviewBoxS = (env = process.env) => {
|
|
39276
39451
|
const n3 = Number(env["LOKI_E10_REVIEW_BOX_S"]);
|
|
39277
39452
|
return n3 > 0 ? n3 : defaultBudgetsOn(env) ? 300 : Infinity;
|
|
39278
|
-
}, MIN_REVIEW_S = 30, roomS = (ctx) => backstopS(ctx.capS ?? Infinity) - (ctx.startedAtMs === undefined ? 0 : (ctx.clock?.now() ?? Date.now()) - ctx.startedAtMs) / 1000 - 55, boxFor = (ctx) => Math.min(reviewBoxS(), roomS(ctx)), reviewExtraLimitS = (ctx) => pickReviewer(ctx, configuredReviewer(ctx.repoDir)).p && roomS(ctx) >= MIN_REVIEW_S ? boxFor(ctx) + 30 : 0, LINE_CHECK_HEAD = "Loki acceptance line check.", LINE_CHECK_SYSTEM = "You check a code change against an issue's acceptance lines. You have no tools: read only what is below. Answer for every numbered line, one line each, nothing else.", LINE_CHECK_DIFF_MAX = 240000, CUT_FIRST, lineCheckOverride = null, lineCheckModel = (ctxModel, env = process.env) => (env["LOKI_E10_ISSUE_ACCEPTANCE_MODEL"] ?? "").trim() || (ctxModel && /^claude-/.test(ctxModel) ? ctxModel : ctxModel && /^(opus|sonnet|haiku)$/.test(ctxModel) ? `claude-${ctxModel}-5-5` : "claude-sonnet-5-5"), reviewAcceptance = (ctx) => {
|
|
39453
|
+
}, MIN_REVIEW_S = 30, roomS = (ctx) => backstopS(ctx.capS ?? Infinity) - (ctx.startedAtMs === undefined ? 0 : (ctx.clock?.now() ?? Date.now()) - ctx.startedAtMs) / 1000 - 55, boxFor = (ctx) => Math.min(reviewBoxS(), roomS(ctx)), reviewExtraLimitS = (ctx) => pickReviewer(ctx, configuredReviewer(ctx.repoDir)).p && roomS(ctx) >= MIN_REVIEW_S ? boxFor(ctx) + 30 : 0, LINE_CHECK_HEAD = "Loki acceptance line check.", LINE_CHECK_SYSTEM = "You check a code change against an issue's acceptance lines. You have no tools: read only what is below. Answer for every numbered line, one line each, nothing else.", LINE_CHECK_DIFF_MAX = 240000, CUT_FIRST, lineCheckOverride = null, lineCheckModel = (ctxModel, env = process.env) => (env["LOKI_E10_ISSUE_ACCEPTANCE_MODEL"] ?? "").trim() || roleModel("review", env) || (ctxModel && /^claude-/.test(ctxModel) ? ctxModel : ctxModel && /^(opus|sonnet|haiku)$/.test(ctxModel) ? `claude-${ctxModel}-5-5` : "claude-sonnet-5-5"), reviewAcceptance = (ctx) => {
|
|
39279
39454
|
const o = ctx.outputs?.() ?? {}, il = issueAcceptanceCapOn() ? issueAcceptanceOf(o.intake) : [];
|
|
39280
39455
|
return il.length ? il : acceptanceLines(o.plan);
|
|
39281
39456
|
}, reviewChecksBlock = (ctx) => {
|
|
@@ -39699,12 +39874,14 @@ function patchCallFor(model, lokiDir2, timeoutMs = 180000, env = process.env) {
|
|
|
39699
39874
|
}
|
|
39700
39875
|
};
|
|
39701
39876
|
return async ({ system, messages }) => {
|
|
39877
|
+
noteRoleModel("dev", model);
|
|
39702
39878
|
const r = await toolLessCall({ model, system, prompt: flattenMessages(messages), maxTokens: PATCH_MAX_TOKENS, thinking: "off", timeoutMs, ledger: { lokiDir: lokiDir2, phase: "implement-patch" } });
|
|
39703
39879
|
return { text: r.outcome.kind === "ok" ? r.outcome.value : null, usd: r.usd };
|
|
39704
39880
|
};
|
|
39705
39881
|
}
|
|
39706
39882
|
var patchEnabled = (env = process.env) => ["1", "on", "true", "yes"].includes((env.LOKI_E10_PATCH ?? "").trim().toLowerCase()), PATCH_SYSTEM = "You are Loki, an autonomous coding agent. You have no tools. Follow the task prompt exactly.", PATCH_RULES, CONVENTION_HEAD_LINES = 30, CONVENTION_MAX_FILES = 3, CONVENTION_MAX_CHARS = 6000, TEST_NAME4, LOCKFILES, DIGEST_MAX_CHARS = 1500, appliedTests = (applied) => applied.filter((f) => isTestFile(f)), PATCH_MAX_TOKENS = 8000;
|
|
39707
39883
|
var init_patch_protocol = __esm(() => {
|
|
39884
|
+
init_claude_model();
|
|
39708
39885
|
init_lock_ecosystems();
|
|
39709
39886
|
init_commit_filter();
|
|
39710
39887
|
init_runner_config();
|
|
@@ -39909,6 +40086,7 @@ var init_implement = __esm(() => {
|
|
|
39909
40086
|
init_context();
|
|
39910
40087
|
init_test_guard();
|
|
39911
40088
|
init_model_downgrades();
|
|
40089
|
+
init_claude_model();
|
|
39912
40090
|
init_sizing();
|
|
39913
40091
|
init_attempts();
|
|
39914
40092
|
init_plan();
|
|
@@ -39959,16 +40137,17 @@ var init_implement = __esm(() => {
|
|
|
39959
40137
|
const plan = prior.plan?.plan ?? null;
|
|
39960
40138
|
const impacted = impactedTests(ctx);
|
|
39961
40139
|
const readOnly = prior.wall?.readOnlyFiles ?? [];
|
|
39962
|
-
const
|
|
39963
|
-
const
|
|
40140
|
+
const devPin = roleModel("dev"), planPin = roleModel("plan");
|
|
40141
|
+
const routed = routerActive() && !devPin;
|
|
40142
|
+
const downgrade = routed || devPin ? null : cascadeDowngrade(ctx.model);
|
|
39964
40143
|
const cascade = downgrade !== null;
|
|
39965
40144
|
if (downgrade)
|
|
39966
40145
|
process.stderr.write(`${downgrade.note}
|
|
39967
40146
|
`);
|
|
39968
40147
|
const lessons = lessonsForBrief(ctx.repoDir, ctx.runId, task, [...prior.plan?.relevant_files ?? [], ...impacted], ctx.runDir);
|
|
39969
|
-
const bc = briefCtx(ctx, routed ? undefined : downgrade?.to ?? ctx.model), repoMap = bc.text + lessons + learningsBlock(ctx.repoDir) + orgKnowledgeBlock(ctx.repoDir, task, ctx.runDir);
|
|
40148
|
+
const bc = briefCtx(ctx, routed ? undefined : devPin ?? downgrade?.to ?? ctx.model), repoMap = bc.text + lessons + learningsBlock(ctx.repoDir) + orgKnowledgeBlock(ctx.repoDir, task, ctx.runDir);
|
|
39970
40149
|
const spec = specFor(ctx);
|
|
39971
|
-
const chain = routed || !plan ? null : planChain(ctx, downgrade?.to ?? ctx.model, fastTierModel(process.env));
|
|
40150
|
+
const chain = routed || !plan ? null : devPin || planPin ? planChain(ctx, resolveClaudeModel(devPin ?? ctx.model), resolveClaudeModel(planPin ?? fastTierModel(process.env))) : planChain(ctx, downgrade?.to ?? ctx.model, fastTierModel(process.env));
|
|
39972
40151
|
const own = routed ? null : interruptedSession(ctx, `${ctx.runId}-impl`);
|
|
39973
40152
|
const ownId = own && "id" in own ? own.id : undefined;
|
|
39974
40153
|
const resumeId = ownId ?? (chain && "id" in chain ? chain.id : undefined);
|
|
@@ -40020,7 +40199,7 @@ var init_implement = __esm(() => {
|
|
|
40020
40199
|
mkdirSync47(ctx.runDir, { recursive: true });
|
|
40021
40200
|
writeFileSync50(join103(ctx.runDir, ATTEMPT_BRIEF_FILE), fullBrief, "utf8");
|
|
40022
40201
|
} catch {}
|
|
40023
|
-
const firstAttemptModel = attemptsK(ctx.model) > 0 ? attemptModels()[0] : undefined;
|
|
40202
|
+
const attemptsNamed = (process.env.LOKI_E10_ATTEMPT_MODELS ?? "").trim() !== "", firstAttemptModel = attemptsK(devPin ?? ctx.model) > 0 && (!devPin || attemptsNamed) ? attemptModels()[0] : undefined;
|
|
40024
40203
|
const first = {
|
|
40025
40204
|
stage: "implement",
|
|
40026
40205
|
brief: ownId ? INTERRUPTED_BRIEF : fullBrief,
|
|
@@ -40031,7 +40210,7 @@ var init_implement = __esm(() => {
|
|
|
40031
40210
|
limitS: implementStage.limitS,
|
|
40032
40211
|
signal,
|
|
40033
40212
|
cwd: ctx.repoDir,
|
|
40034
|
-
...downgrade ? { model: downgrade.to } : firstAttemptModel ? { model: firstAttemptModel } : {},
|
|
40213
|
+
...downgrade ? { model: downgrade.to } : firstAttemptModel ? { model: firstAttemptModel, ...devPin ? { pinSource: "specific" } : {} } : {},
|
|
40035
40214
|
...suiteCmdsOpt(ctx.repoDir, prior.intake?.testmap),
|
|
40036
40215
|
...resumeId ? { resumeSessionId: resumeId } : {},
|
|
40037
40216
|
...planStopChecks(ctx.repoDir, prior, new Set(impacted), implementStage.limitS, ctx.baseSha)
|
|
@@ -40043,8 +40222,10 @@ var init_implement = __esm(() => {
|
|
|
40043
40222
|
const size = sizeTask(task, loadRepoMap(prior.intake?.repomap_ref), prior.intake?.testmap ?? null).size;
|
|
40044
40223
|
const rt = routed ? routeStart(ctx, first, prior.plan, size) : null;
|
|
40045
40224
|
let patch, patchS = 0, patchNote = "";
|
|
40046
|
-
const patchModel = downgrade?.to ?? ctx.model ?? resolveModel(ctx.provider);
|
|
40225
|
+
const patchModel = devPin ?? downgrade?.to ?? ctx.model ?? resolveModel(ctx.provider);
|
|
40047
40226
|
const patchOn = patchEnabled() && !plan && !routed && !resumeId && ctx.provider === "claude" && /^[\w.:@/-]+$/.test(patchModel);
|
|
40227
|
+
if (patchEnabled() && ctx.provider !== "claude")
|
|
40228
|
+
noteRoleSkip("implement-patch", `LOKI_E10_PATCH: the patch protocol runs on the claude provider only (this run: ${ctx.provider})`);
|
|
40048
40229
|
if (patchOn && !signal.aborted) {
|
|
40049
40230
|
const started = Date.now();
|
|
40050
40231
|
try {
|
|
@@ -40422,7 +40603,7 @@ ${r.session.summary}` };
|
|
|
40422
40603
|
cascade,
|
|
40423
40604
|
...downgrade ? { model_downgrade: downgrade.note } : {},
|
|
40424
40605
|
iteration_ids: earlyReviewCost ? [...ids, earlyReviewCost] : ids,
|
|
40425
|
-
model: rt ? rt.current : downgrade?.to ?? firstAttemptModel ?? ctx.model,
|
|
40606
|
+
model: rt ? rt.current : downgrade?.to ?? firstAttemptModel ?? devPin ?? ctx.model,
|
|
40426
40607
|
...rt ? { route_model: rt.current, route_escalations: rt.escalations } : {},
|
|
40427
40608
|
session_id: readSessionId(ctx.repoDir, iterationId),
|
|
40428
40609
|
duration_s: session3.durationS,
|
|
@@ -46522,6 +46703,7 @@ async function runVerify(ctx, signal, bt) {
|
|
|
46522
46703
|
}
|
|
46523
46704
|
}
|
|
46524
46705
|
const notExcused = [];
|
|
46706
|
+
const baseUnattributed = [];
|
|
46525
46707
|
const fullNotProven = new Set;
|
|
46526
46708
|
const fullErr = new Map;
|
|
46527
46709
|
const ranDeeper = [];
|
|
@@ -46557,6 +46739,11 @@ async function runVerify(ctx, signal, bt) {
|
|
|
46557
46739
|
attr.introducedChecks.push(...fa.introducedChecks);
|
|
46558
46740
|
attr.line = [attr.line, fa.line].filter(Boolean).join("; ") || null;
|
|
46559
46741
|
notExcused.push(...whyFullSuiteNotExcused(ctx.repoDir, ctx.baseSha, full, changed, fa.preExistingChecks, blockedIds, shown));
|
|
46742
|
+
{
|
|
46743
|
+
const namesChange = lineNamesChange(changed);
|
|
46744
|
+
baseUnattributed.push(...redUnattributableOnBase(ctx.repoDir, ctx.baseSha, full).filter((n3) => !fa.preExistingChecks.includes(n3) && !(full.find((c) => c.name === n3)?.excerpt ?? "").split(`
|
|
46745
|
+
`).some(namesChange)));
|
|
46746
|
+
}
|
|
46560
46747
|
if (full.some((c) => c.result === "pass" || c.result === "fail")) {
|
|
46561
46748
|
ranDeeper.push("full test command", "full suite");
|
|
46562
46749
|
risk = markExecuted(risk, ranDeeper);
|
|
@@ -46619,7 +46806,7 @@ async function runVerify(ctx, signal, bt) {
|
|
|
46619
46806
|
await settleNrd(ctx);
|
|
46620
46807
|
if (touchedExcused.length)
|
|
46621
46808
|
attr.line = [attr.line, ...touchedExcused.map((n3) => `${TOUCHED_RED}: ${n3}`)].filter(Boolean).join("; ") || null;
|
|
46622
|
-
return { status: "completed", data: { checks: pub, flaky, verify_scope: complete ? "complete" : "quick", ...ntf ? { no_test_fallback: true } : {}, ...uncaused.length ? { uncaused_reds: uncaused } : {}, ...lintUntouchedNames.length ? { lint_untouched: lintUntouchedNames } : {}, ...ownLintNames.length ? { own_lint: ownLintNames } : {}, independent_fail: independentFail, ...independentReds.length ? { independent_reds: independentReds } : {}, fix_gate: fixGateOf({ independent_fail: independentFail, independent_reds: independentReds }, `${String(ctx.outputs().implement?.model ?? "")} ${ctx.model}`, failuresGrouped.length > 0), file_hashes: hashes, blocking_checks: blockingNames, ...wallFailTail ? { wall_failure_tail: wallFailTail } : {}, ...wallPassed === undefined ? {} : { wall_passed: wallPassed }, failures_grouped: [...failuresGrouped, ...nrdGroupsFor(ctx.outputs().implement, fixRounds)], holdout_failed: holdoutFailed, changed_files: changed, ...depNames.size ? { dependent_checks: [...depNames] } : {}, not_proven: notProven2, ...fullNotProven.size || depsNotes.na.length ? { not_applicable: [...[...fullNotProven].filter(naNote).map(naText), ...depsNotes.na] } : {}, pre_red: preRed.ids, pre_red_checks: preRed.names, ...notExcused.length ? { not_excused: notExcused } : {}, ...preRed.knownRed.length ? { known_red_checks: preRed.knownRed } : {}, ...preRed.sameError.length ? { known_red_same_error: preRed.sameError } : {}, ...baseRed.length ? { base_red_checks: baseRed } : {}, skipped_on_base: preRed.zero, ...collateralSame.length && fixRounds === 0 ? { collateral_same_error: collateralSame } : {}, ...attr.line ? { baseline_line: attr.line, introduced_checks: attr.introducedChecks } : {}, test_counts: testCounts, uncovered_changed: uncoveredChanged, target_checks: checks2.filter((c) => c.result === "pass" && targetNames.has(c.name)).map((c) => isHold(c) ? "holdout" : c.name), risk } };
|
|
46809
|
+
return { status: "completed", data: { checks: pub, flaky, verify_scope: complete ? "complete" : "quick", ...ntf ? { no_test_fallback: true } : {}, ...uncaused.length ? { uncaused_reds: uncaused } : {}, ...lintUntouchedNames.length ? { lint_untouched: lintUntouchedNames } : {}, ...ownLintNames.length ? { own_lint: ownLintNames } : {}, independent_fail: independentFail, ...independentReds.length ? { independent_reds: independentReds } : {}, fix_gate: fixGateOf({ independent_fail: independentFail, independent_reds: independentReds }, `${String(ctx.outputs().implement?.model ?? "")} ${ctx.model}`, failuresGrouped.length > 0), file_hashes: hashes, blocking_checks: blockingNames, ...wallFailTail ? { wall_failure_tail: wallFailTail } : {}, ...wallPassed === undefined ? {} : { wall_passed: wallPassed }, failures_grouped: [...failuresGrouped, ...nrdGroupsFor(ctx.outputs().implement, fixRounds)], holdout_failed: holdoutFailed, changed_files: changed, ...depNames.size ? { dependent_checks: [...depNames] } : {}, not_proven: notProven2, ...fullNotProven.size || depsNotes.na.length ? { not_applicable: [...[...fullNotProven].filter(naNote).map(naText), ...depsNotes.na] } : {}, pre_red: preRed.ids, pre_red_checks: preRed.names, ...notExcused.length ? { not_excused: notExcused } : {}, ...baseUnattributed.length ? { base_unattributed: baseUnattributed } : {}, ...preRed.knownRed.length ? { known_red_checks: preRed.knownRed } : {}, ...preRed.sameError.length ? { known_red_same_error: preRed.sameError } : {}, ...baseRed.length ? { base_red_checks: baseRed } : {}, skipped_on_base: preRed.zero, ...collateralSame.length && fixRounds === 0 ? { collateral_same_error: collateralSame } : {}, ...attr.line ? { baseline_line: attr.line, introduced_checks: attr.introducedChecks } : {}, test_counts: testCounts, uncovered_changed: uncoveredChanged, target_checks: checks2.filter((c) => c.result === "pass" && targetNames.has(c.name)).map((c) => isHold(c) ? "holdout" : c.name), risk } };
|
|
46623
46810
|
}
|
|
46624
46811
|
}
|
|
46625
46812
|
var timeoutCarryOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI_E10_TIMEOUT_CARRY"] ?? "").trim()), TIMEOUT_CARRY_NOTE = "carried from an earlier verify of this run, not rerun (untouched file)", KILL_AFTER_MS = 5000, NO_ID_BASE_REASON = "the test command does not run in this checkout: it fails the same way with the change removed", rootless = (out2, roots2) => {
|
|
@@ -46935,6 +47122,7 @@ async function wallAuthor(ctx, signal, retry) {
|
|
|
46935
47122
|
${retry.note}` : ""),
|
|
46936
47123
|
tier: "development",
|
|
46937
47124
|
model,
|
|
47125
|
+
...specificPin("test", "LOKI_E10_WALL_TIER"),
|
|
46938
47126
|
iterationId,
|
|
46939
47127
|
limitS: wallLimitS(sz.size),
|
|
46940
47128
|
maxOutputTokens: wallOutputCap(),
|
|
@@ -46958,7 +47146,7 @@ ${retry.note}` : ""),
|
|
|
46958
47146
|
});
|
|
46959
47147
|
const bad1 = oor();
|
|
46960
47148
|
if (bad1.length > 0 && !wallCasesRunner(runners) && !signal.aborted && !ctx.overCap?.())
|
|
46961
|
-
await ctx.sessions.run({ stage: "wall", brief: withStagePrefix(outOfRepoReask("Rewrite these Wall files in place, keeping the same names and acceptance coverage.", bad1)), tier: "development", model, iterationId: `${iterationId}-oor`, limitS: wallLimitS(sz.size), maxOutputTokens: wallOutputCap(), signal, cwd });
|
|
47149
|
+
await ctx.sessions.run({ stage: "wall", brief: withStagePrefix(outOfRepoReask("Rewrite these Wall files in place, keeping the same names and acceptance coverage.", bad1)), tier: "development", model, ...specificPin("test", "LOKI_E10_WALL_TIER"), iterationId: `${iterationId}-oor`, limitS: wallLimitS(sz.size), maxOutputTokens: wallOutputCap(), signal, cwd });
|
|
46962
47150
|
const oorBad = new Map(oor().map((b) => [b.name, b.why])), all = readdirSync40(cwd).filter((f) => f.startsWith(WALL_PREFIX)), held = stashHoldout({ runId: ctx.runId, repoDir: ctx.repoDir, srcDir: cwd, targetDir, names: all.filter((n3) => !oorBad.has(n3) && !reject(n3, readFileSync105(join115(cwd, n3), "utf8"))), runnerOf: (n3) => guessRunner(n3, runners) }), generated = all.filter((n3) => !held?.names.has(n3));
|
|
46963
47151
|
const sealedDir = sealStageDir(ctx.runId, ctx.repoDir);
|
|
46964
47152
|
rmSync36(sealedDir, { recursive: true, force: true });
|
|
@@ -47127,6 +47315,7 @@ var WALL_PREFIX = "loki_wall_", BASE_RUN_TIMEOUT_MS = 60000, WALL_MAP_MAX_LINES
|
|
|
47127
47315
|
return { ...u.untagged.length ? { untagged: u.untagged } : {}, ...u.untagged_files.length ? { untagged_files: u.untagged_files } : {} };
|
|
47128
47316
|
}, WALL_SESSION_MAX_S = 300, WALL_BASE_FILES = 4, WALL_RUNG_S, WALL_STAGE_LIMIT_S, distrustGreenBase = (d) => ({ ...d, already_satisfied: false, already_satisfied_distrusted: true, base_run: { ...d.base_run ?? {}, not_run: 1, unproven: true } }), WALL_REAUTHOR_EXHAUSTED = "Wall re-authored once and still no Wall test ran on the base tree", wallStage, stage7;
|
|
47129
47317
|
var init_wall = __esm(() => {
|
|
47318
|
+
init_claude_model();
|
|
47130
47319
|
init_wall_knobs();
|
|
47131
47320
|
init_repo_profile();
|
|
47132
47321
|
init_self_review();
|
|
@@ -48499,7 +48688,8 @@ function secretPushRefusal(verify4, runId) {
|
|
|
48499
48688
|
}
|
|
48500
48689
|
function unattributedRed(o, c) {
|
|
48501
48690
|
const cut = o.verify?.stopped_at === "limit" || o.verify?.stopped_at === "cap", head = c.name.split(":")[0];
|
|
48502
|
-
|
|
48691
|
+
const baseRed = head === "full suite" && strs2(o.verify?.base_unattributed).includes(c.name);
|
|
48692
|
+
return (cut || baseRed) && c.provenance === "exogenous" && c.name.includes(":") && !/^(lint|typecheck|holdout|select-tests|build|patch|turn)$/.test(head);
|
|
48503
48693
|
}
|
|
48504
48694
|
function verdictOf2(o, checks2, emptyDiff, verifyNotProven, wallGreenOnBase, proof, targetProof = false, uncovered = [], leanGap = [], copyGap = [], clauseGap = []) {
|
|
48505
48695
|
const exit = o.implement?.exit;
|
|
@@ -48962,6 +49152,7 @@ async function evaluateSeal(ctx, signal) {
|
|
|
48962
49152
|
return c ? { fired: true, from: str3(c.from) ?? null, to: str3(c.to) ?? null } : { fired: false };
|
|
48963
49153
|
})() } : {},
|
|
48964
49154
|
...!externalRun(o) && /^(explicit|default|provider)$/.test(process.env.LOKI_SESSION_MODEL_SOURCE ?? "") ? { model_source: process.env.LOKI_SESSION_MODEL_SOURCE } : {},
|
|
49155
|
+
...!externalRun(o) ? roleModelsReceiptBlock() : {},
|
|
48965
49156
|
...externalRun(o) ? { implement: { exit: "external", patch_sha256: str3(o.implement?.patch_sha256) ?? "" } } : {},
|
|
48966
49157
|
resumed: o.intake?.resumed === true,
|
|
48967
49158
|
events_sha256: sha2562(existsSync83(eventsPath) ? readFileSync110(eventsPath) : ""),
|
|
@@ -49054,6 +49245,7 @@ var SYSTEM_INTERP = "tests ran on the system interpreter", SYSTEM_INTERP_SUFFIX
|
|
|
49054
49245
|
var init_seal = __esm(() => {
|
|
49055
49246
|
init_resolve();
|
|
49056
49247
|
init_role_agents();
|
|
49248
|
+
init_claude_model();
|
|
49057
49249
|
init_config_fence();
|
|
49058
49250
|
init_redact();
|
|
49059
49251
|
init_intent_card();
|
|
@@ -58070,11 +58262,20 @@ async function main3(args) {
|
|
|
58070
58262
|
sealPatch = resolve35(v);
|
|
58071
58263
|
noPr = true;
|
|
58072
58264
|
i++;
|
|
58265
|
+
} else if (!eoo && ROLE_FLAG_ENV.has(a.includes("=") ? a.slice(0, a.indexOf("=")) : a)) {
|
|
58266
|
+
const name = a.includes("=") ? a.slice(0, a.indexOf("=")) : a, v = a.includes("=") ? a.slice(a.indexOf("=") + 1) : args[++i];
|
|
58267
|
+
if (v === undefined || v === "" || !a.includes("=") && v.startsWith("-")) {
|
|
58268
|
+
process.stderr.write(`engine10: ${name} needs a value
|
|
58269
|
+
`);
|
|
58270
|
+
noteRefusal("unsupported_flag");
|
|
58271
|
+
return 2;
|
|
58272
|
+
}
|
|
58273
|
+
process.env[ROLE_FLAG_ENV.get(name)] = v;
|
|
58073
58274
|
} else if (a === "--" && !eoo)
|
|
58074
58275
|
eoo = true;
|
|
58075
58276
|
else if (!eoo && /^--?[A-Za-z][\w-]*(=\S*)?$/.test(a)) {
|
|
58076
58277
|
process.stderr.write(`engine10: unknown flag ${a}
|
|
58077
|
-
usage: loki "<task>" [--no-pr] [--deep] [--verified] [--json] [--verbose] [--quiet] [--max-cost N] [--max-time DUR] [--verify-max-time DUR] [--provider P] [--spec F] [--seal-existing PATCH] [--resume] [--fresh] [--base-current] [-- <task>]
|
|
58278
|
+
usage: loki "<task>" [--no-pr] [--deep] [--verified] [--json] [--verbose] [--quiet] [--max-cost N] [--max-time DUR] [--verify-max-time DUR] [--provider P] [--spec F] [--seal-existing PATCH] [--resume] [--fresh] [--base-current] [--plan-model M --dev-model M --test-model M --review-model M --advisor-model M --helper-model M --escalate-model M | --models plan=M,...] [-- <task>]
|
|
58078
58279
|
`);
|
|
58079
58280
|
noteRefusal("unsupported_flag");
|
|
58080
58281
|
return 2;
|
|
@@ -58220,6 +58421,20 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
|
|
|
58220
58421
|
process.env.LOKI_SESSION_MODEL_SOURCE = ch.source;
|
|
58221
58422
|
modelWhy = ch.why;
|
|
58222
58423
|
}
|
|
58424
|
+
let roleLine = "";
|
|
58425
|
+
try {
|
|
58426
|
+
const cm = await Promise.resolve().then(() => (init_claude_model(), exports_claude_model));
|
|
58427
|
+
cm.roleSettings(process.env);
|
|
58428
|
+
const ce = cm.roleValueError(process.env, provider) ?? cm.roleConflictError(process.env, provider);
|
|
58429
|
+
if (ce)
|
|
58430
|
+
throw new Error(ce);
|
|
58431
|
+
roleLine = [cm.roleStartLine(process.env, provider), provider === "claude" ? cm.fableRawApiNote(process.env) : ""].filter(Boolean).join(`
|
|
58432
|
+
`);
|
|
58433
|
+
} catch (err) {
|
|
58434
|
+
process.stderr.write(`engine10: ${err instanceof Error ? err.message : String(err)}
|
|
58435
|
+
`);
|
|
58436
|
+
return 2;
|
|
58437
|
+
}
|
|
58223
58438
|
const runId2 = `e10-${new Date().toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z")}-${Math.random().toString(16).slice(2, 6)}`;
|
|
58224
58439
|
const runDir = join135(repoDir, ".loki", "runs", runId2);
|
|
58225
58440
|
const cap = resolveCap(maxCost, repoDir);
|
|
@@ -58229,6 +58444,7 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
|
|
|
58229
58444
|
return 2;
|
|
58230
58445
|
}
|
|
58231
58446
|
const trackerRef = parseTrackerRef(task), isIssue = ISSUE_RE.test(task) || trackerRef !== null, model = resolveModel(provider), env = { ...process.env, ...!quiet && !verbose && !json2 ? { LOKI_E10_READINESS_FOLD: "1" } : {} };
|
|
58447
|
+
env.LOKI_E10_RUN_PROVIDER = provider;
|
|
58232
58448
|
if (quiet || verbose || json2)
|
|
58233
58449
|
delete env.LOKI_E10_READINESS_FOLD;
|
|
58234
58450
|
if (trackerRef && !process.env.LOKI_WRITEBACK_ISSUE) {
|
|
@@ -58359,6 +58575,7 @@ usage: loki "<goal>" (or: loki start <prd.md | owner/repo#N>)
|
|
|
58359
58575
|
const headLines = [
|
|
58360
58576
|
`${START_LINE}, ${prPlan?.header ?? baseLine(repoDir)}`,
|
|
58361
58577
|
modelWhy ? `model ${model} (${modelWhy})` : "",
|
|
58578
|
+
roleLine,
|
|
58362
58579
|
[cap.usd > 0 ? capNote(cap.usd, cap.source) : "", costEst ? startText(JSON.parse(costEst), cap.usd) : "", verifiedOn(env) ? verifiedHeader(env) : ""].filter(Boolean).join("; "),
|
|
58363
58580
|
routeStart2 ? [routeStart2, downLine].filter(Boolean).join("; ") : "",
|
|
58364
58581
|
verbose ? [cap.usd > 0 ? "" : capNote(cap.usd, cap.source), routeStart2 ? "" : downLine].filter(Boolean).join("; ") : ""
|
|
@@ -58601,6 +58818,7 @@ var init_supervisor = __esm(() => {
|
|
|
58601
58818
|
init_run_cap();
|
|
58602
58819
|
init_safe_git();
|
|
58603
58820
|
init_term_width();
|
|
58821
|
+
init_claude_model();
|
|
58604
58822
|
init_run_summary();
|
|
58605
58823
|
init_commit_filter();
|
|
58606
58824
|
init_seal();
|
|
@@ -58960,6 +59178,7 @@ async function checkAlreadyDone(ctx, signal, task, repoMap, testMap) {
|
|
|
58960
59178
|
brief: buildConfirmBrief(task, hits),
|
|
58961
59179
|
tier: "fast",
|
|
58962
59180
|
model: capToRunTier(wallPinModel(), ctx.model, ["LOKI_E10_WALL_TIER", "LOKI_MODEL_OVERRIDE"]),
|
|
59181
|
+
...specificPin("helper", "LOKI_E10_WALL_TIER"),
|
|
58963
59182
|
iterationId: `${ctx.runId}-already-done`,
|
|
58964
59183
|
limitS: 30,
|
|
58965
59184
|
signal,
|
|
@@ -58973,6 +59192,7 @@ async function checkAlreadyDone(ctx, signal, task, repoMap, testMap) {
|
|
|
58973
59192
|
return { satisfied: true, evidence: [marker2, ...evidenceLines(hits)], paths: hits.map((h) => h.path) };
|
|
58974
59193
|
}
|
|
58975
59194
|
var init_already_done = __esm(() => {
|
|
59195
|
+
init_claude_model();
|
|
58976
59196
|
init_sizing();
|
|
58977
59197
|
init_already_done_evidence();
|
|
58978
59198
|
});
|
|
@@ -59560,6 +59780,7 @@ var exports_fix = {};
|
|
|
59560
59780
|
__export(exports_fix, {
|
|
59561
59781
|
stage: () => stage10,
|
|
59562
59782
|
fixStage: () => fixStage,
|
|
59783
|
+
fixRoundModel: () => fixRoundModel,
|
|
59563
59784
|
buildFixBrief: () => buildFixBrief
|
|
59564
59785
|
});
|
|
59565
59786
|
import { relative as relative33, resolve as resolve38 } from "path";
|
|
@@ -59585,11 +59806,18 @@ Your previous diagnosis: ${escalation.priorDiagnosis ?? "(none was recorded)"}`]
|
|
|
59585
59806
|
|
|
59586
59807
|
`));
|
|
59587
59808
|
}
|
|
59809
|
+
function fixRoundModel(runModel, repeated, routed, testFailures, env = process.env) {
|
|
59810
|
+
const devPin = roleModel("dev", env), escPin = repeated ? roleModel("escalate", env) : undefined, rolePin = escPin ?? devPin;
|
|
59811
|
+
const downgrade = routed || rolePin ? null : cascadeDowngrade(runModel, env);
|
|
59812
|
+
const pinnedModel = rolePin ? rolePin : repeated ? escalationModel(runModel) : downgrade && testFailures === 0 ? downgrade.to : undefined;
|
|
59813
|
+
return { ...devPin ? { devPin } : {}, ...escPin ? { escPin } : {}, ...rolePin ? { rolePin } : {}, downgrade, ...pinnedModel ? { pinnedModel } : {} };
|
|
59814
|
+
}
|
|
59588
59815
|
var fixStage, stage10;
|
|
59589
59816
|
var init_fix = __esm(() => {
|
|
59590
59817
|
init_lean_prefix();
|
|
59591
59818
|
init_context();
|
|
59592
59819
|
init_unit_model();
|
|
59820
|
+
init_claude_model();
|
|
59593
59821
|
init_sizing();
|
|
59594
59822
|
init_types2();
|
|
59595
59823
|
init_failures();
|
|
@@ -59622,10 +59850,9 @@ var init_fix = __esm(() => {
|
|
|
59622
59850
|
const testFailures = groups.filter(isTestFailure);
|
|
59623
59851
|
const signatures = groups.filter((g2) => !g2.carried).map((g2) => g2.signature).sort().join("|");
|
|
59624
59852
|
const repeated = testFailures.length > 0 && prior.fix?.signatures === signatures;
|
|
59625
|
-
const
|
|
59853
|
+
const { devPin, escPin, rolePin, downgrade, pinnedModel } = fixRoundModel(ctx.model, repeated, routed, testFailures.length);
|
|
59626
59854
|
const reason = testFailures.map((g2) => g2.signature).join(", ");
|
|
59627
|
-
const
|
|
59628
|
-
const { pin: routedPin, climbed } = routed ? routedFix(ctx.model, prior, { repeated, stall: prior.fix?.stall_pending === true, groups, reason }) : { pin: undefined, climbed: null };
|
|
59855
|
+
const { pin: routedPin, climbed } = routed && !rolePin ? routedFix(ctx.model, prior, { repeated, stall: prior.fix?.stall_pending === true, groups, reason }) : { pin: undefined, climbed: null };
|
|
59629
59856
|
const actualModel = routedPin ?? pinnedModel ?? ctx.model;
|
|
59630
59857
|
if (downgrade && pinnedModel === downgrade.to)
|
|
59631
59858
|
process.stderr.write(`${downgrade.note}
|
|
@@ -59635,7 +59862,7 @@ var init_fix = __esm(() => {
|
|
|
59635
59862
|
const prevDiag = prior.fix?.diagnosis ?? null;
|
|
59636
59863
|
const chain = { sessionId: prior.fix?.session_id ?? prior.implement?.session_id ?? null, model: prior.fix?.model ?? prior.implement?.model ?? ctx.model };
|
|
59637
59864
|
const effort = hooks.effort?.fix(round2, testFailures.length > 0, { model: actualModel, envOnly: environmentShaped(groups.filter((g2) => !g2.carried)) });
|
|
59638
|
-
const sessionBase = { stage: "fix", tier: "development", limitS: fixStage.limitS, signal, cwd: ctx.repoDir, ...suiteCmdsOpt(ctx.repoDir, prior.intake?.testmap), ...effort ? { effort } : {}, ...pinnedModel ? { model: pinnedModel } : {}, ...routedPin ? { model: routedPin } : {} };
|
|
59865
|
+
const sessionBase = { stage: "fix", tier: "development", limitS: fixStage.limitS, signal, cwd: ctx.repoDir, ...suiteCmdsOpt(ctx.repoDir, prior.intake?.testmap), ...effort ? { effort } : {}, ...pinnedModel ? { model: pinnedModel } : {}, ...routedPin ? { model: routedPin } : {}, ...escPin ? { role: "escalate" } : {} };
|
|
59639
59866
|
const hints = siteHints(ctx);
|
|
59640
59867
|
const priorConflict = typeof prior.fix?.spec_conflict_reason === "string" && prior.fix?.exit === "spec_conflict" && neverStopActive() ? prior.fix.spec_conflict_reason : null;
|
|
59641
59868
|
const advice = round2 >= 2 && !signal.aborted ? await runConsult({ runDir: ctx.runDir, repoDir: ctx.repoDir, stage: `fix${round2}`, trigger: priorConflict ? "stop" : "red-verify", task, evidence: [...priorConflict ? [`The previous fix round stopped with LOKI_SPEC_CONFLICT: ${priorConflict}`] : [], ...groups.slice(0, 8).map((g2) => `(${g2.count}x) ${g2.signature}
|
|
@@ -59663,11 +59890,9 @@ ${g2.sample}`)].join(`
|
|
|
59663
59890
|
round: round2,
|
|
59664
59891
|
groups: groups.map((g2) => ({ signature: g2.signature, count: g2.count, sample: g2.sample })),
|
|
59665
59892
|
model: actualModel,
|
|
59666
|
-
escalated: repeated || climbed !== null,
|
|
59667
|
-
fix_resume: r.mode,
|
|
59668
|
-
cache_read_tokens: r.cacheRead,
|
|
59893
|
+
escalated: repeated && (!devPin || !!escPin) || climbed !== null,
|
|
59669
59894
|
...downgrade && pinnedModel === downgrade.to ? { model_downgrade: downgrade.note } : {},
|
|
59670
|
-
...repeated ? { escalation_reason: reason, escalation_model: actualModel } : {}
|
|
59895
|
+
...repeated && (!devPin || escPin) ? { escalation_reason: reason, escalation_model: actualModel } : {}
|
|
59671
59896
|
});
|
|
59672
59897
|
const capStop = capStopOf(r.session.summary), capNote2 = capStop ? `fix round ${round2} stopped by the harness (${capStop}): the failures it was fed are NOT PROVEN fixed` : null;
|
|
59673
59898
|
return {
|
|
@@ -106827,7 +107052,7 @@ function selectClaudeInvokerKind(env) {
|
|
|
106827
107052
|
}
|
|
106828
107053
|
function claudeTierToModel(tier) {
|
|
106829
107054
|
if (tier === "fable")
|
|
106830
|
-
return "
|
|
107055
|
+
return "fable";
|
|
106831
107056
|
const allowHaiku = process.env["LOKI_ALLOW_HAIKU"] === "true";
|
|
106832
107057
|
const pinned = (name, fallback) => applyAliasPin(process.env[`LOKI_CLAUDE_MODEL_${name}`] || process.env[`LOKI_MODEL_${name}`] || fallback, process.env);
|
|
106833
107058
|
switch (tier) {
|
|
@@ -106898,6 +107123,9 @@ function useProviderDefaultModel(call) {
|
|
|
106898
107123
|
return !(e10[`LOKI_CLAUDE_MODEL_${name}`] || e10[`LOKI_MODEL_${name}`] || e10["LOKI_MODEL_OVERRIDE"] || e10["LOKI_MAX_TIER"] || e10["LOKI_TIER_ROUTING"]);
|
|
106899
107124
|
}
|
|
106900
107125
|
function claudeModelFor(call) {
|
|
107126
|
+
const roleModel2 = (process.env["LOKI_E10_ROLE_MODEL"] ?? "").trim();
|
|
107127
|
+
if (roleModel2)
|
|
107128
|
+
return roleModel2;
|
|
106901
107129
|
const routedModel = modelRouteModel(process.env);
|
|
106902
107130
|
if (routedModel)
|
|
106903
107131
|
return routedModel;
|
|
@@ -106921,6 +107149,7 @@ function applyMaxTierCeiling(tier, model) {
|
|
|
106921
107149
|
}
|
|
106922
107150
|
return model;
|
|
106923
107151
|
case "opus":
|
|
107152
|
+
return /fable/i.test(model) ? "opus" : model;
|
|
106924
107153
|
default:
|
|
106925
107154
|
return model;
|
|
106926
107155
|
}
|
|
@@ -107007,13 +107236,13 @@ function planRouterSession(args) {
|
|
|
107007
107236
|
return null;
|
|
107008
107237
|
const probe = probeAdvisor(env, "claude", args.claudeCodeVersion, args.runDir, advisorPair(env, args.model));
|
|
107009
107238
|
if (!routed)
|
|
107010
|
-
return probe.available ? { model: args.model, settings: { advisorModel:
|
|
107239
|
+
return probe.available ? { model: args.model, settings: { advisorModel: routerAdvisorModel(env) } } : null;
|
|
107011
107240
|
if (probe.available) {
|
|
107012
107241
|
return {
|
|
107013
107242
|
model: args.model,
|
|
107014
107243
|
.../sonnet/i.test(args.model) ? { effort: ROUTER_SONNET_ADVISOR_EFFORT } : {},
|
|
107015
107244
|
settings: {
|
|
107016
|
-
advisorModel:
|
|
107245
|
+
advisorModel: routerAdvisorModel(env),
|
|
107017
107246
|
...compactWindowSettings(args.model, true)
|
|
107018
107247
|
}
|
|
107019
107248
|
};
|
|
@@ -107058,7 +107287,7 @@ function claudeProvider() {
|
|
|
107058
107287
|
runDir: process.env["LOKI_DIR"] ?? resolve44(call.cwd, ".loki"),
|
|
107059
107288
|
claudeCodeVersion: await installedClaudeCodeVersion(cli)
|
|
107060
107289
|
}) : null;
|
|
107061
|
-
const model = routed ? routed.model : baseModel;
|
|
107290
|
+
const model = routed && !process.env["LOKI_E10_ROLE_MODEL"] ? routed.model : baseModel;
|
|
107062
107291
|
const window2 = compactWindowSettings(model);
|
|
107063
107292
|
const memory = taskMemorySettings(model);
|
|
107064
107293
|
const sessionSettings = routed?.settings || window2 || memory ? { ...window2, ...routed?.settings, ...memory } : undefined;
|
|
@@ -107170,7 +107399,8 @@ function buildSdkLoopOptions(args) {
|
|
|
107170
107399
|
claudeCodeVersion: args.claudeCodeVersion ?? bundledClaudeCodeVersion2()
|
|
107171
107400
|
}) : null;
|
|
107172
107401
|
if (router) {
|
|
107173
|
-
|
|
107402
|
+
if (!process.env["LOKI_E10_ROLE_MODEL"])
|
|
107403
|
+
out3.model = router.model;
|
|
107174
107404
|
if (router.settings)
|
|
107175
107405
|
out3.settings = router.settings;
|
|
107176
107406
|
}
|
|
@@ -107381,7 +107611,7 @@ function sessionPinModel(e10 = process.env) {
|
|
|
107381
107611
|
if (!pin)
|
|
107382
107612
|
return;
|
|
107383
107613
|
if (pin === "fable")
|
|
107384
|
-
return "
|
|
107614
|
+
return "fable";
|
|
107385
107615
|
if (pin === "planning" || pin === "development" || pin === "fast")
|
|
107386
107616
|
return explicitSetupModel(pin, e10) ?? claudeTierToModel(pin);
|
|
107387
107617
|
return pin;
|
|
@@ -107417,7 +107647,9 @@ var exports_session = {};
|
|
|
107417
107647
|
__export(exports_session, {
|
|
107418
107648
|
writerDenyList: () => writerDenyList,
|
|
107419
107649
|
workRunOf: () => workRunOf,
|
|
107650
|
+
withRoleModel: () => withRoleModel,
|
|
107420
107651
|
untrackedList: () => untrackedList,
|
|
107652
|
+
startedModelOf: () => startedModelOf,
|
|
107421
107653
|
sessionPinModel: () => sessionPinModel,
|
|
107422
107654
|
sessionEffortFor: () => sessionEffortFor,
|
|
107423
107655
|
sessionChildMain: () => sessionChildMain,
|
|
@@ -107466,6 +107698,21 @@ function resolveModel(provider) {
|
|
|
107466
107698
|
return `${provider} (model not recorded)`;
|
|
107467
107699
|
return e10.LOKI_CLAUDE_MODEL_DEVELOPMENT || e10.LOKI_MODEL_DEVELOPMENT || PROVIDER_DEFAULT_MODEL;
|
|
107468
107700
|
}
|
|
107701
|
+
function withRoleModel(opts, provider) {
|
|
107702
|
+
const role = opts.role ?? stageRole(opts.stage), m = opts.pinSource === "specific" ? undefined : roleModel(role, process.env, provider);
|
|
107703
|
+
const out3 = m === undefined ? opts : { ...opts, model: m, roleModel: m };
|
|
107704
|
+
return out3;
|
|
107705
|
+
}
|
|
107706
|
+
function startedModelOf(opts, provider, e10 = process.env) {
|
|
107707
|
+
if (opts.model)
|
|
107708
|
+
return opts.model;
|
|
107709
|
+
if (provider !== "claude")
|
|
107710
|
+
return resolveModel(provider);
|
|
107711
|
+
const forced = e10["LOKI_MODEL_OVERRIDE"] || sessionPinModel(e10), T = String(opts.tier).toUpperCase();
|
|
107712
|
+
if (forced)
|
|
107713
|
+
return forced;
|
|
107714
|
+
return e10[`LOKI_CLAUDE_MODEL_${T}`] || e10[`LOKI_MODEL_${T}`] || (opts.tier === "fast" ? e10["LOKI_ALLOW_HAIKU"] === "true" ? "haiku" : "sonnet" : resolveModel(provider));
|
|
107715
|
+
}
|
|
107469
107716
|
function sessionEffortFor(opts) {
|
|
107470
107717
|
const resolved = hooks.effort?.resolve(opts.stage, opts.effort) ?? opts.effort;
|
|
107471
107718
|
const prior = opts.resumeSessionId ? sessionEffort.get(opts.resumeSessionId) : undefined;
|
|
@@ -107570,13 +107817,18 @@ function childEnv2(opts, cfg) {
|
|
|
107570
107817
|
env["LOKI_ADVISOR_SCOPE"] = "off";
|
|
107571
107818
|
else
|
|
107572
107819
|
delete env["LOKI_ADVISOR_SCOPE"];
|
|
107573
|
-
|
|
107820
|
+
delete env["LOKI_E10_ROLE_MODEL"];
|
|
107821
|
+
if (opts.roleModel && cfg.provider === "opencode")
|
|
107822
|
+
env["LOKI_OPENCODE_MODEL"] = opts.roleModel;
|
|
107823
|
+
else if (opts.roleModel)
|
|
107824
|
+
env["LOKI_E10_ROLE_MODEL"] = opts.roleModel;
|
|
107825
|
+
const pin = opts.roleModel ?? routerSessionPin(env, cfg.provider, cfg.advisor, opts);
|
|
107574
107826
|
if (pin && pin !== PROVIDER_DEFAULT_MODEL) {
|
|
107575
107827
|
const t = String(opts.tier).toUpperCase();
|
|
107576
107828
|
env[`LOKI_CLAUDE_MODEL_${t}`] = pin;
|
|
107577
107829
|
env[`LOKI_MODEL_${t}`] = pin;
|
|
107578
107830
|
}
|
|
107579
|
-
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;
|
|
107831
|
+
const caps = cfg.provider === "claude" && env["LOKI_E10_FULL_SESSION"] !== "1" ? hooks.effort?.caps?.(opts.stage, opts.roleModel || process.env["LOKI_MODEL_OVERRIDE"] || sessionPinModel(process.env) || (pin && pin !== PROVIDER_DEFAULT_MODEL ? pin : "") || opts.model || cfg.model || resolveModel(cfg.provider)) : undefined;
|
|
107580
107832
|
if (caps)
|
|
107581
107833
|
env["LOKI_E10_STOP_RULES"] = JSON.stringify(caps);
|
|
107582
107834
|
else
|
|
@@ -107668,10 +107920,13 @@ function createSessionRunner(cfg) {
|
|
|
107668
107920
|
let allowOnce = [];
|
|
107669
107921
|
return {
|
|
107670
107922
|
run(opts) {
|
|
107671
|
-
|
|
107672
|
-
|
|
107673
|
-
|
|
107674
|
-
|
|
107923
|
+
opts = withRoleModel(opts, cfg.provider);
|
|
107924
|
+
if (opts.roleModel === undefined) {
|
|
107925
|
+
if (cfg.provider === "opencode" && opts.model)
|
|
107926
|
+
opts = { ...opts, model: undefined };
|
|
107927
|
+
else if (cfg.provider === "claude" && opts.model)
|
|
107928
|
+
opts = { ...opts, model: capToSessionPin(opts.model) };
|
|
107929
|
+
}
|
|
107675
107930
|
const start = Date.now();
|
|
107676
107931
|
if (opts.signal.aborted || sessionsCancelled())
|
|
107677
107932
|
return Promise.resolve({ exit: null, markers: { done: false, alreadyDone: null, specConflict: null }, durationS: 0, killed: true, stderrTail: "" });
|
|
@@ -107725,7 +107980,9 @@ function createSessionRunner(cfg) {
|
|
|
107725
107980
|
killCause = cause;
|
|
107726
107981
|
killGroupWithGrace(pgid);
|
|
107727
107982
|
};
|
|
107728
|
-
|
|
107983
|
+
const startedRole = opts.role ?? stageRole(opts.stage);
|
|
107984
|
+
noteRoleModel(startedRole, startedModelOf(opts, cfg.provider));
|
|
107985
|
+
cfg.emit?.("session.started", opts.stage, { session_id: sessionId, provider: cfg.provider, model: opts.model ?? cfg.model ?? null, pgid: pgid ?? null, ...opts.roleModel ? { role: startedRole } : {} });
|
|
107729
107986
|
const onAbort = () => kill("aborted");
|
|
107730
107987
|
const limitTimer = armTimer(() => kill("limit"), opts.limitS * 1000);
|
|
107731
107988
|
const capUsd = parseCapUsd(process.env["LOKI_E10_MAX_COST_USD"]), effDir = cfg.lokiRoot ? join162(cfg.lokiRoot, "metrics", "efficiency") : null, effBase = effDir !== null && capUsd !== null ? calculateCostFromRecords(readEfficiencyDir(effDir)) : 0;
|
|
@@ -108002,8 +108259,8 @@ var namedExactOn = (env = process.env) => !/^(0|off|false|no)$/i.test((env["LOKI
|
|
|
108002
108259
|
}
|
|
108003
108260
|
noteOnce("LOKI_E10_WALL_LIMIT_S", raw2, `is not a positive number; using ${dflt}`);
|
|
108004
108261
|
return dflt;
|
|
108005
|
-
}, cascadeEnabled = (env = process.env) => knob(env.LOKI_E10_CASCADE, ["1", "on", "true"]), resolveModelAlias, wallPinModel = (env = process.env) => resolveModelAlias(env.LOKI_E10_WALL_TIER || "sonnet"), wallModel = (env = process.env) => !env.LOKI_E10_WALL_TIER && routerPreset(env) && envOverride(env) === null ? resolveModelAlias(presetExecutor(env).model) : wallPinModel(env), wallFirstModel = (size, env = process.env) => {
|
|
108006
|
-
if (knob(env.LOKI_E10_WALL_FIRST, ["0", "off", "false"]) || env.LOKI_E10_WALL_TIER || env.LOKI_MODEL_OVERRIDE || wallConcurrent(env))
|
|
108262
|
+
}, cascadeEnabled = (env = process.env) => knob(env.LOKI_E10_CASCADE, ["1", "on", "true"]), resolveModelAlias, wallPinModel = (env = process.env) => resolveModelAlias(env.LOKI_E10_WALL_TIER || "sonnet"), wallModel = (env = process.env) => !env.LOKI_E10_WALL_TIER && roleModel("test", env) !== undefined ? roleModel("test", env) : !env.LOKI_E10_WALL_TIER && routerPreset(env) && envOverride(env) === null ? resolveModelAlias(presetExecutor(env).model) : wallPinModel(env), wallFirstModel = (size, env = process.env) => {
|
|
108263
|
+
if (knob(env.LOKI_E10_WALL_FIRST, ["0", "off", "false"]) || env.LOKI_E10_WALL_TIER || env.LOKI_MODEL_OVERRIDE || wallConcurrent(env) || roleModel("test", env) !== undefined)
|
|
108007
108264
|
return wallModel(env);
|
|
108008
108265
|
return size === "small" || size === "normal" ? resolveModelAlias("haiku") : wallModel(env);
|
|
108009
108266
|
}, cascadeImplementModel;
|
|
@@ -134414,13 +134671,18 @@ function __setSdkClientForTests(stub) {
|
|
|
134414
134671
|
_client = stub;
|
|
134415
134672
|
}
|
|
134416
134673
|
function describeJudgeOutcome(o) {
|
|
134417
|
-
return o.kind === "refused" && o.category ? `refused:${o.category}` : o.kind;
|
|
134674
|
+
return o.kind === "refused" && o.category ? `refused:${o.category}` : o.kind === "unsupported" ? `unsupported: ${o.reason}` : o.kind;
|
|
134418
134675
|
}
|
|
134419
134676
|
function judgeOutcomeNote(o) {
|
|
134420
134677
|
return `sdk judge outcome: ${describeJudgeOutcome(o)}`;
|
|
134421
134678
|
}
|
|
134422
134679
|
function fallbackEligible(model) {
|
|
134423
|
-
return /^claude-(
|
|
134680
|
+
return /^claude-(opus|sonnet)-5(-\d+)?$/i.test(model);
|
|
134681
|
+
}
|
|
134682
|
+
function fableFailure(model, what) {
|
|
134683
|
+
if (/fable/i.test(model))
|
|
134684
|
+
process.stderr.write(`loki: ${model} on the raw API: ${redactSecrets(what).replace(/\s+/g, " ").slice(0, 400)} (not retried on another model)
|
|
134685
|
+
`);
|
|
134424
134686
|
}
|
|
134425
134687
|
function fallbackCovers(model, category) {
|
|
134426
134688
|
if (category === null)
|
|
@@ -134502,9 +134764,12 @@ async function runJudge(params, schema) {
|
|
|
134502
134764
|
return { kind: "context_exceeded" };
|
|
134503
134765
|
}
|
|
134504
134766
|
noteJudgeFailure(ledger2, model, "transport", max, pt2);
|
|
134767
|
+
fableFailure(model, err instanceof Error ? err.message : String(err));
|
|
134505
134768
|
return { kind: "transport" };
|
|
134506
134769
|
}
|
|
134507
134770
|
const outcome = classifyStop(msg2);
|
|
134771
|
+
if (outcome.kind === "refused")
|
|
134772
|
+
fableFailure(model, `refused${outcome.category ? ` (${outcome.category})` : ""}`);
|
|
134508
134773
|
const billed = typeof msg2.model === "string" && msg2.model ? msg2.model : model;
|
|
134509
134774
|
noteJudgeUsage(ledger2, billed, msg2, describeJudgeOutcome(outcome), max, pt2);
|
|
134510
134775
|
if (outcome.kind === "truncated" && !retriedTruncation && Math.min(max * 2, TRUNCATION_RETRY_CAP) > max) {
|
|
@@ -134680,6 +134945,11 @@ async function toolLessCall(p) {
|
|
|
134680
134945
|
const lokiDir2 = p.ledger?.lokiDir ?? process.env["LOKI_DIR"];
|
|
134681
134946
|
const ledger2 = lokiDir2 ? { lokiDir: lokiDir2, phase: p.ledger?.phase ?? "toolless" } : undefined;
|
|
134682
134947
|
const remaining = toolLessRemainingUsd(process.env, lokiDir2);
|
|
134948
|
+
if (providerOf(process.env) === "opencode" && !isClaudeModel(p.model) && roleNamesModel(p.model)) {
|
|
134949
|
+
const reason = `${p.model} is not a Claude model and this call runs on the Anthropic API only (opencode run)`;
|
|
134950
|
+
noteRoleSkip(p.ledger?.phase ?? "toolless", reason);
|
|
134951
|
+
return { outcome: { kind: "unsupported", reason }, route: "api", usd: null, thinkingTokens: null };
|
|
134952
|
+
}
|
|
134683
134953
|
await loadSdk();
|
|
134684
134954
|
if (remaining !== null && remaining <= 0)
|
|
134685
134955
|
return { outcome: { kind: "budget" }, route: client() ? "api" : "agent-sdk", usd: null, thinkingTokens: null };
|
|
@@ -134693,6 +134963,8 @@ async function toolLessCall(p) {
|
|
|
134693
134963
|
}
|
|
134694
134964
|
var _sdk = null, CACHE_BREAKPOINT = "[CACHE_BREAKPOINT]", EFFORT_MAX_TOKENS, STREAM_ABOVE_TOKENS = 21333, judgeMaxTokens = (effort, maxTokens) => maxTokens ?? (effort ? EFFORT_MAX_TOKENS[effort] : 4096), calib, counterOverride = null, COUNT_TIMEOUT_MS = 3000, countTimeoutMs, _client = null, FALLBACK_BETA = "server-side-fallback-2026-07-01", TRUNCATION_RETRY_CAP, DEFAULT_BASE_URL = "https://api.anthropic.com", queryOverride = null, TOOLLESS_MAX_ATTEMPTS = 3, backoffOverride = null, backoffMs2 = (attempt) => backoffOverride ? backoffOverride(attempt) : Math.round(1000 * 3 ** (attempt - 1) * (0.75 + Math.random() * 0.5));
|
|
134695
134965
|
var init_sdk_invoker = __esm(() => {
|
|
134966
|
+
init_claude_model();
|
|
134967
|
+
init_redact();
|
|
134696
134968
|
init_model_routes();
|
|
134697
134969
|
init_finding_schema();
|
|
134698
134970
|
init_price_table();
|
|
@@ -134741,6 +135013,7 @@ function readConsults(runDir) {
|
|
|
134741
135013
|
function consultCallFor(model, lokiDir2, env2 = process.env, timeoutMs = 180000, opts = {}) {
|
|
134742
135014
|
if (env2.LOKI_E10_INVOKER === "cli")
|
|
134743
135015
|
return async (system, prompt, phase) => {
|
|
135016
|
+
noteRoleModel(opts.role ?? "advisor", model);
|
|
134744
135017
|
try {
|
|
134745
135018
|
const r = await withChildLedger(run, lokiDir2, phase, model)([env2.LOKI_CLAUDE_CLI || "claude", "-p", prompt, "--output-format", "json", "--tools", "", "--model", model, "--system-prompt", system, "--strict-mcp-config", "--setting-sources", "project"], { timeoutMs, group: true });
|
|
134746
135019
|
const j10 = JSON.parse(r.stdout);
|
|
@@ -134751,8 +135024,9 @@ function consultCallFor(model, lokiDir2, env2 = process.env, timeoutMs = 180000,
|
|
|
134751
135024
|
}
|
|
134752
135025
|
};
|
|
134753
135026
|
return async (system, prompt, phase) => {
|
|
135027
|
+
noteRoleModel(opts.role ?? "advisor", model);
|
|
134754
135028
|
const r = await toolLessCall({ model, system, prompt, maxTokens: opts.maxTokens ?? MAX_TOKENS, thinking: opts.thinking ?? "low", timeoutMs, ledger: { lokiDir: lokiDir2, phase }, noCache: true });
|
|
134755
|
-
return { text: r.outcome.kind === "ok" ? r.outcome.value : null, usd: r.usd, outcome: r.outcome.kind };
|
|
135029
|
+
return { text: r.outcome.kind === "ok" ? r.outcome.value : null, usd: r.usd, outcome: r.outcome.kind === "unsupported" ? `unsupported: ${r.outcome.reason}` : r.outcome.kind };
|
|
134756
135030
|
};
|
|
134757
135031
|
}
|
|
134758
135032
|
function __setConsultCallForTests(c) {
|
|
@@ -134796,7 +135070,7 @@ function neverStopNotes(implement) {
|
|
|
134796
135070
|
function consultNotes(runDir) {
|
|
134797
135071
|
return readConsults(runDir).map((c) => `Opus consult (${c.trigger}, ${c.stage}, ${c.model}): ${c.outcome}${typeof c.usd === "number" ? `, $${c.usd.toFixed(4)}` : ", cost not measured"}${c.advice ? `; advice: ${one4(c.advice)}` : ""}`);
|
|
134798
135072
|
}
|
|
134799
|
-
var CONSULT_FILE = "opus-consult.json", CONSULT_MODEL_DEFAULT = "claude-opus-5-5", MAX_TOKENS = 1200, CAP2, consultEnabled = (env2 = process.env) => keptUnderLean(env2.LOKI_E10_OPUS_CONSULT, env2), neverStopActive = (env2 = process.env) => consultEnabled(env2) && env2.LOKI_E10_INTAKE_ASK !== "1", consultModel = (env2 = process.env) => env2.LOKI_E10_CONSULT_MODEL || CONSULT_MODEL_DEFAULT, consultMax = (env2) => {
|
|
135073
|
+
var CONSULT_FILE = "opus-consult.json", CONSULT_MODEL_DEFAULT = "claude-opus-5-5", MAX_TOKENS = 1200, CAP2, consultEnabled = (env2 = process.env) => keptUnderLean(env2.LOKI_E10_OPUS_CONSULT, env2), neverStopActive = (env2 = process.env) => consultEnabled(env2) && env2.LOKI_E10_INTAKE_ASK !== "1", consultModel = (env2 = process.env) => env2.LOKI_E10_CONSULT_MODEL || roleModel("advisor", env2) || CONSULT_MODEL_DEFAULT, consultMax = (env2) => {
|
|
134800
135074
|
const n10 = Number(env2.LOKI_E10_CONSULT_MAX);
|
|
134801
135075
|
return Number.isInteger(n10) && n10 >= 0 ? n10 : 1;
|
|
134802
135076
|
}, consultAvailable = (runDir, env2 = process.env) => consultEnabled(env2) && readConsults(runDir).length < consultMax(env2), callOverride = null, CONSULT_SYSTEM, clip10 = (s, n10) => s.length > n10 ? `${s.slice(0, n10)}
|
|
@@ -134810,6 +135084,7 @@ ${advice}`] : [], neverStopBrief = (reason, advice) => [
|
|
|
134810
135084
|
|
|
134811
135085
|
`), assumptionOf = (text5) => /^\W*ASSUMPTION:\s*(.+)$/m.exec(text5 ?? "")?.[1]?.trim().slice(0, 300) ?? null, one4 = (s) => s.replace(/[\x00-\x1f\x7f]+/g, " ").trim().slice(0, 300);
|
|
134812
135086
|
var init_opus_consult = __esm(() => {
|
|
135087
|
+
init_claude_model();
|
|
134813
135088
|
init_cost_profile();
|
|
134814
135089
|
init_sdk_invoker();
|
|
134815
135090
|
init_child_ledger();
|
|
@@ -135185,7 +135460,7 @@ async function refereeSession(ctx, first, id2, task, files, ask, keep = []) {
|
|
|
135185
135460
|
writeFileSync91(join171(cwd, "task.md"), task, "utf8");
|
|
135186
135461
|
for (const [n10, c] of Object.entries(files))
|
|
135187
135462
|
writeFileSync91(join171(cwd, n10), c, "utf8");
|
|
135188
|
-
const s = await ctx.sessions.run({ stage: "wall", tier: "development", model: refereeModel(ctx), iterationId: id2, limitS: 120, signal: first.signal, cwd, brief: [...taskBlock(task), ask, FINISH_LINE].join(`
|
|
135463
|
+
const s = await ctx.sessions.run({ stage: "wall", tier: "development", model: refereeModel(ctx), role: "review", ...specificPin("review", "LOKI_E10_WALL_TIER"), iterationId: id2, limitS: 120, signal: first.signal, cwd, brief: [...taskBlock(task), ask, FINISH_LINE].join(`
|
|
135189
135464
|
|
|
135190
135465
|
`) });
|
|
135191
135466
|
const ok2 = !s.killed && s.exit === 0, out3 = {};
|
|
@@ -135313,6 +135588,8 @@ async function legacyReauthor(ctx, first, firstSession, f, a, reason, task) {
|
|
|
135313
135588
|
stage: "wall",
|
|
135314
135589
|
tier: "development",
|
|
135315
135590
|
model: refereeModel(ctx),
|
|
135591
|
+
role: "review",
|
|
135592
|
+
...specificPin("review", "LOKI_E10_WALL_TIER"),
|
|
135316
135593
|
iterationId: id2,
|
|
135317
135594
|
limitS: 120,
|
|
135318
135595
|
signal: first.signal,
|
|
@@ -135464,7 +135741,7 @@ async function deliverOverWallConflict(o, repoDir, reverify, emit2, opts = {}) {
|
|
|
135464
135741
|
return files;
|
|
135465
135742
|
}
|
|
135466
135743
|
async function resumeForRemedy(ctx, first, firstSession, remedy, diff, env2 = process.env) {
|
|
135467
|
-
const call = remedyCallOverride ?? ((s10, p) => consultCallFor(env2.LOKI_E10_RANKED_REMEDY_MODEL || "claude-haiku-5-5", join171(ctx.repoDir, ".loki"), env2, 60000, { maxTokens: REMEDY_MAX_TOKENS, thinking: "off" })(s10, p, "ranked-remedy-check"));
|
|
135744
|
+
const call = remedyCallOverride ?? ((s10, p) => consultCallFor(env2.LOKI_E10_RANKED_REMEDY_MODEL || roleModel("helper", env2) || "claude-haiku-5-5", join171(ctx.repoDir, ".loki"), env2, 60000, { maxTokens: REMEDY_MAX_TOKENS, thinking: "off", role: "helper" })(s10, p, "ranked-remedy-check"));
|
|
135468
135745
|
let r;
|
|
135469
135746
|
try {
|
|
135470
135747
|
r = await call(REMEDY_CHECK_SYSTEM, remedyCheckPrompt(remedy, diff));
|
|
@@ -135581,6 +135858,7 @@ ${diff.length > REMEDY_DIFF_CAP ? `${diff.slice(0, REMEDY_DIFF_CAP)}
|
|
|
135581
135858
|
}, remedyResumeBrief = (remedy) => `The issue's first-choice remedy is not in your change: "${remedy}". Implement that remedy now, keep any other fix only on top of it, run the targeted tests, then finish. ` + FINISH_LINE, remedyCallOverride = null;
|
|
135582
135859
|
var init_conflict_resume = __esm(() => {
|
|
135583
135860
|
init_types2();
|
|
135861
|
+
init_claude_model();
|
|
135584
135862
|
init_role_agents();
|
|
135585
135863
|
init_opus_consult();
|
|
135586
135864
|
init_session_resume();
|