loki-mode 7.49.0 → 7.51.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/README.md +2 -2
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/autonomy/prd-analyzer.py +215 -1
- package/autonomy/prd-checklist.sh +315 -0
- package/autonomy/run.sh +350 -3
- package/autonomy/spec-interrogation.sh +224 -4
- package/autonomy/spec.sh +25 -16
- package/autonomy/verify.sh +108 -26
- package/dashboard/__init__.py +1 -1
- package/dashboard/audit.py +202 -21
- package/docs/INSTALLATION.md +2 -2
- package/docs/siem-integration.md +102 -0
- package/loki-ts/dist/loki.js +231 -230
- package/mcp/__init__.py +1 -1
- package/mcp/lsp_proxy.py +203 -0
- package/mcp/tests/test_lsp_proxy.py +169 -0
- package/package.json +1 -1
- package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
- package/references/invariant-checks.md +109 -0
- package/src/audit/crosslink.js +413 -0
- package/src/audit/index.js +32 -0
- package/src/observability/siem-export.js +424 -0
- package/src/policies/cost.js +270 -1
package/loki-ts/dist/loki.js
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var r6=Object.defineProperty;var t6=($)=>$;function i6($,Q){this[$]=t6.bind(null,Q)}var h=($,Q)=>{for(var Z in Q)r6($,Z,{get:Q[Z],enumerable:!0,configurable:!0,set:i6.bind(Q,Z)})};var L=($,Q)=>()=>($&&(Q=$($=0)),Q);var K$=import.meta.require;var D1={};h(D1,{lokiDir:()=>P,homeLokiDir:()=>n$,findRepoRootForVersion:()=>o$,REPO_ROOT:()=>g});import{resolve as n,dirname as d$}from"path";import{fileURLToPath as e6}from"url";import{existsSync as P$}from"fs";import{homedir as $Q}from"os";function QQ(){let $=S1;for(let Q=0;Q<6;Q++){if(P$(n($,"VERSION"))&&P$(n($,"autonomy/run.sh")))return $;let Z=d$($);if(Z===$)break;$=Z}return n(S1,"..","..","..")}function o$($){let Q=$;for(let Z=0;Z<6;Z++){if(P$(n(Q,"VERSION"))&&P$(n(Q,"autonomy/run.sh")))return Q;let z=d$(Q);if(z===Q)break;Q=z}return n($,"..","..","..")}function P(){return process.env.LOKI_DIR??n(process.cwd(),".loki")}function n$(){return n($Q(),".loki")}var S1,g;var b=L(()=>{S1=d$(e6(import.meta.url));g=QQ()});import{readFileSync as ZQ}from"fs";import{resolve as zQ,dirname as XQ}from"path";import{fileURLToPath as KQ}from"url";function j$(){if($$!==null)return $$;let $="7.51.0";if(typeof $==="string"&&$.length>0)return $$=$,$$;try{let Q=XQ(KQ(import.meta.url)),Z=o$(Q);$$=ZQ(zQ(Z,"VERSION"),"utf-8").trim()}catch{$$="unknown"}return $$}var $$=null;var a$=L(()=>{b()});var b1={};h(b1,{runOrThrow:()=>qQ,run:()=>k,commandVersion:()=>WQ,commandExists:()=>f,ShellError:()=>s$});async function k($,Q={}){let Z=Bun.spawn({cmd:[...$],stdout:"pipe",stderr:"pipe",env:Q.env?{...process.env,...Q.env}:process.env,cwd:Q.cwd}),z,X;if(Q.timeoutMs&&Q.timeoutMs>0)z=setTimeout(()=>{try{Z.kill("SIGTERM")}catch{}X=setTimeout(()=>{try{Z.kill("SIGKILL")}catch{}},2000)},Q.timeoutMs);try{let[q,K,W]=await Promise.all([new Response(Z.stdout).text(),new Response(Z.stderr).text(),Z.exited]);return{stdout:q,stderr:K,exitCode:W}}finally{if(z)clearTimeout(z);if(X)clearTimeout(X)}}async function qQ($,Q={}){let Z=await k($,Q);if(Z.exitCode!==0)throw new s$(`command failed (${Z.exitCode}): ${$.join(" ")}`,Z.exitCode,Z.stdout,Z.stderr);return Z}async function f($){let Q=VQ($),Z=await k(["sh","-c",`command -v ${Q}`],{timeoutMs:5000});if(Z.exitCode===0)return Z.stdout.trim()||null;return null}function VQ($){if(!/^[A-Za-z0-9._/-]+$/.test($))throw Error(`refused to shell-escape suspect token: ${$}`);return $}async function WQ($,Q="--version"){if(!await f($))return null;let z=await k([$,Q],{timeoutMs:5000});if(z.exitCode!==0)return null;return((z.stdout||z.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var s$;var d=L(()=>{s$=class s$ extends Error{message;exitCode;stdout;stderr;constructor($,Q,Z,z){super($);this.message=$;this.exitCode=Q;this.stdout=Z;this.stderr=z;this.name="ShellError"}}});function a($){return JQ?"":$}var JQ,T,S,_,wZ,I,R,y,V;var c=L(()=>{JQ=(process.env.NO_COLOR??"").length>0;T=a("\x1B[0;31m"),S=a("\x1B[0;32m"),_=a("\x1B[1;33m"),wZ=a("\x1B[0;34m"),I=a("\x1B[0;36m"),R=a("\x1B[1m"),y=a("\x1B[2m"),V=a("\x1B[0m")});import{existsSync as wQ}from"fs";async function Q$(){if(G$!==void 0)return G$;let $="/opt/homebrew/bin/python3.12";if(wQ($))return G$=$,$;let Q=await f("python3.12");if(Q)return G$=Q,Q;let Z=await f("python3");return G$=Z,Z}async function Z$($,Q={}){let Z=await Q$();if(!Z)return{stdout:"",stderr:"python3 not found",exitCode:127};return k([Z,"-c",$],Q)}var G$;var q$=L(()=>{d()});var e1={};h(e1,{runStatus:()=>uQ});import{existsSync as v,readFileSync as W$,readdirSync as d1,statSync as o1}from"fs";import{resolve as C,basename as DQ}from"path";import{homedir as CQ}from"os";function n1($){let Q=Math.trunc($);if(Q>=1e6)return`${(Math.trunc(Q/1e6*10)/10).toFixed(1)}M`;if(Q>=1000)return`${(Math.trunc(Q/1000*10)/10).toFixed(1)}K`;return String(Q)}function a1($,Q,Z){if(Q===0)return null;let z=Math.trunc($*100/Q),X=Math.trunc($*k$/Q);if(X>k$)X=k$;let q=k$-X,K=S;if(z>=80)K=T;else if(z>=50)K=_;let W="=".repeat(Math.max(0,X))+" ".repeat(Math.max(0,q)),J=n1($),U=n1(Q);return` ${R}${Z}${V} ${K}[${W}]${V} ${z}% (${J} / ${U})`}async function hQ(){if(await f("jq"))return!0;return process.stdout.write(`${T}Error: jq is required but not installed.${V}
|
|
3
3
|
`),process.stdout.write(`Install with:
|
|
4
4
|
`),process.stdout.write(` brew install jq (macOS)
|
|
5
5
|
`),process.stdout.write(` apt install jq (Debian/Ubuntu)
|
|
6
6
|
`),process.stdout.write(` yum install jq (RHEL/CentOS)
|
|
7
|
-
`),!1}function
|
|
7
|
+
`),!1}function R$($){if(!Number.isFinite($)||$<=0)return!1;try{return process.kill($,0),!0}catch{return!1}}function x$($){if(!v($))return null;try{let Q=W$($,"utf-8").trim();if(!Q)return null;let Z=Number.parseInt(Q,10);return Number.isFinite(Z)?Z:null}catch{return null}}function yQ($){let Q=[],Z=x$(C($,"loki.pid"));if(Z!==null&&R$(Z))Q.push(`global:${Z}`);let z=C($,"sessions");if(v(z)){let X=[];try{X=d1(z)}catch{X=[]}for(let q of X){let K=C(z,q);try{if(!o1(K).isDirectory())continue}catch{continue}let W=C(K,"loki.pid"),J=x$(W);if(J!==null&&R$(J))Q.push(`${q}:${J}`)}}if(v($)){let X=[];try{X=d1($)}catch{X=[]}for(let q of X){if(!q.startsWith("run-")||!q.endsWith(".pid"))continue;let K=C($,q);try{if(!o1(K).isFile())continue}catch{continue}let W=DQ(q,".pid").slice(4),J=x$(K);if(J!==null&&R$(J)){if(!Q.some((H)=>H.startsWith(`${W}:`)))Q.push(`${W}:${J}`)}}}return Q}async function s1($,Q){let Z=await k(["jq","-r",$,Q]);if(Z.exitCode!==0)return null;return Z.stdout.trim()}function r1($,Q){try{let Z=W$($,"utf-8"),X=JSON.parse(Z)[Q];if(typeof X==="number"){if(Q==="budget_used"){let q=Math.round(X*100)/100;if(Number.isInteger(q))return String(q);return String(q)}return String(X)}if(X===void 0||X===null)return"0";return String(X)}catch{return"0"}}function t1($,Q,Z){try{let z=W$($,"utf-8"),q=JSON.parse(z)[Q];if(typeof q==="number"&&Number.isFinite(q))return q;return Z}catch{return Z}}async function vQ(){let $=P();if(!await hQ())return 1;if(!v($))return process.stdout.write(`${R}Loki Mode Status${V}
|
|
8
8
|
`),process.stdout.write(`
|
|
9
|
-
`),process.stdout.write(`${
|
|
9
|
+
`),process.stdout.write(`${_}No active session found.${V}
|
|
10
10
|
`),process.stdout.write(`Loki Mode has not been initialized in this directory.
|
|
11
11
|
`),process.stdout.write(`
|
|
12
12
|
`),process.stdout.write(`To start a session:
|
|
13
13
|
`),process.stdout.write(` loki start <prd> - Start with a PRD file
|
|
14
14
|
`),process.stdout.write(` loki start - Start without a PRD
|
|
15
15
|
`),process.stdout.write(`
|
|
16
|
-
`),process.stdout.write(`${y}Current directory: ${process.cwd()}${
|
|
17
|
-
`),0;process.stdout.write(`${R}Loki Mode Status${
|
|
16
|
+
`),process.stdout.write(`${y}Current directory: ${process.cwd()}${V}
|
|
17
|
+
`),0;process.stdout.write(`${R}Loki Mode Status${V}
|
|
18
18
|
`),process.stdout.write(`
|
|
19
|
-
`);let Q="",Z=
|
|
20
|
-
`),process.stdout.write(`${y} Switch with: loki provider set <claude|codex|cline|aider>${
|
|
19
|
+
`);let Q="",Z=C($,"state","provider");if(v(Z))try{Q=W$(Z,"utf-8").trim()}catch{Q=""}let z=Q||process.env.LOKI_PROVIDER||"claude",X="full features";switch(z){case"codex":case"aider":X="degraded mode";break;case"cline":X="near-full mode";break;default:X="full features";break}process.stdout.write(`${I}Provider:${V} ${z} (${X})
|
|
20
|
+
`),process.stdout.write(`${y} Switch with: loki provider set <claude|codex|cline|aider>${V}
|
|
21
21
|
`),process.stdout.write(`
|
|
22
|
-
`);let
|
|
23
|
-
`);for(let
|
|
24
|
-
`);else process.stdout.write(` ${
|
|
22
|
+
`);let q=yQ($);if(q.length>0){process.stdout.write(`${S}Active Sessions: ${q.length}${V}
|
|
23
|
+
`);for(let G of q){let O=G.indexOf(":"),M=O>=0?G.slice(0,O):G,F=O>=0?G.slice(O+1):"";if(M==="global")process.stdout.write(` ${I}[global]${V} PID ${F}
|
|
24
|
+
`);else process.stdout.write(` ${I}[#${M}]${V} PID ${F}
|
|
25
25
|
`)}process.stdout.write(`
|
|
26
|
-
`),process.stdout.write(`${y} Stop specific: loki stop <session-id>${
|
|
27
|
-
`),process.stdout.write(`${y} Stop all: loki stop${
|
|
26
|
+
`),process.stdout.write(`${y} Stop specific: loki stop <session-id>${V}
|
|
27
|
+
`),process.stdout.write(`${y} Stop all: loki stop${V}
|
|
28
28
|
`),process.stdout.write(`
|
|
29
|
-
`)}if(v(
|
|
30
|
-
`),process.stdout.write(`${y} Resume with: loki resume${
|
|
29
|
+
`)}if(v(C($,"PAUSE")))process.stdout.write(`${_}Status: PAUSED${V}
|
|
30
|
+
`),process.stdout.write(`${y} Resume with: loki resume${V}
|
|
31
31
|
`),process.stdout.write(`
|
|
32
|
-
`);else if(v(
|
|
33
|
-
`),process.stdout.write(`${y} Clear with: loki resume${
|
|
32
|
+
`);else if(v(C($,"STOP")))process.stdout.write(`${T}Status: STOPPED${V}
|
|
33
|
+
`),process.stdout.write(`${y} Clear with: loki resume${V}
|
|
34
34
|
`),process.stdout.write(`
|
|
35
|
-
`);let K=
|
|
36
|
-
`);try{process.stdout.write(
|
|
37
|
-
`)}let
|
|
38
|
-
`);let
|
|
39
|
-
`)}let
|
|
40
|
-
`)}let
|
|
41
|
-
`);
|
|
42
|
-
`)}
|
|
43
|
-
`)}let
|
|
44
|
-
`)}
|
|
45
|
-
`),process.stdout.write(
|
|
46
|
-
`),process.stdout.write(`${y} Tip: loki analyze
|
|
47
|
-
`),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`)
|
|
51
|
-
`)}}if(
|
|
52
|
-
`)}}
|
|
53
|
-
`)
|
|
54
|
-
`),1;
|
|
55
|
-
`),
|
|
35
|
+
`);let K=C($,"STATUS.txt");if(v(K)){process.stdout.write(`${I}Session Info:${V}
|
|
36
|
+
`);try{process.stdout.write(W$(K,"utf-8"))}catch{}process.stdout.write(`
|
|
37
|
+
`)}let W=C($,"state","orchestrator.json");if(v(W)){process.stdout.write(`${I}Orchestrator State:${V}
|
|
38
|
+
`);let G=await s1('.currentPhase // "unknown"',W);process.stdout.write(`${G??"unknown"}
|
|
39
|
+
`)}let J=C($,"queue","pending.json");if(v(J)){let G=await s1('if type == "array" then length elif .tasks then .tasks | length else 0 end',J);process.stdout.write(`${I}Pending Tasks:${V} ${G??"0"}
|
|
40
|
+
`)}let U=C($,"metrics","budget.json");if(v(U)){let G=r1(U,"budget_limit"),O=r1(U,"budget_used");if(G!=="0"){process.stdout.write(`${I}Budget:${V} $${O} / $${G}
|
|
41
|
+
`);let M=Math.trunc((Number.parseFloat(O)||0)*100),F=Number.parseFloat(G),x=Number.isFinite(F)&&F!==0?Math.trunc(F*100):100,D=a1(M,x,"Budget");if(D!==null)process.stdout.write(`${D}
|
|
42
|
+
`)}else process.stdout.write(`${I}Cost:${V} $${O} (no limit)
|
|
43
|
+
`)}let H=C($,"state","context-usage.json");if(v(H)){let G=t1(H,"window_size",200000),O=t1(H,"used_tokens",0),M=a1(O,G,"Context");if(M!==null)process.stdout.write(`${M}
|
|
44
|
+
`)}let B=[C($,"dashboard","dashboard.pid"),C(CQ(),".loki","dashboard","dashboard.pid")].find((G)=>v(G))??"";if(B&&v(B)){let G=x$(B);if(G!==null&&R$(G)){let O=C(B,".."),M=(w,E)=>{let u=C(O,w);try{return v(u)?W$(u,"utf-8").trim()||E:E}catch{return E}},F=M("scheme","http"),x=M("host","127.0.0.1"),D=M("port",process.env.LOKI_DASHBOARD_PORT||"57374");if(x==="0.0.0.0")x="127.0.0.1";process.stdout.write(`${I}Dashboard:${V} ${F}://${x}:${D}/
|
|
45
|
+
`)}}return await mQ($),process.stdout.write(`
|
|
46
|
+
`),process.stdout.write(`${y} Tip: loki analyze context show - detailed token breakdown${V}
|
|
47
|
+
`),process.stdout.write(`${y} Tip: loki analyze code overview - codebase intelligence${V}
|
|
48
|
+
`),0}async function mQ($){let Q=C($,"state"),Z=gQ(Q),z=C(Q,"relevant-learnings.json"),X=C($,"escalations"),q=Z.length>0,K=v(z),W=v(X);if(!q&&!K&&!W)return;if(process.stdout.write(`
|
|
49
|
+
${I}Phase 1 artifacts:${V}
|
|
50
|
+
`),q){let J=Z[Z.length-1],U=i1(J);if(U&&Array.isArray(U.findings)){let H={Critical:0,High:0,Medium:0,Low:0};for(let B of U.findings){let G=String(B.severity??"");if(G in H)H[G]=(H[G]??0)+1}let Y=Object.entries(H).filter(([,B])=>B>0).map(([B,G])=>`${G} ${B.toLowerCase()}`).join(", ");process.stdout.write(` Findings (iter ${U.iteration??"?"}): ${Y||"none"} -- ${U.findings.length} total
|
|
51
|
+
`)}}if(K){let J=i1(z);if(J&&Array.isArray(J.learnings)&&J.learnings.length>0){let U=new Map;for(let Y of J.learnings){let B=String(Y.trigger??"unknown");U.set(B,(U.get(B)??0)+1)}let H=[...U.entries()].sort((Y,B)=>B[1]-Y[1]).slice(0,3).map(([Y,B])=>`${B} ${Y}`).join(", ");process.stdout.write(` Learnings: ${J.learnings.length} total (${H})
|
|
52
|
+
`)}}if(W){let J=0,U="";try{let Y=(await import("fs")).readdirSync(X).filter((B)=>B.endsWith(".md"));if(J=Y.length,Y.length>0)Y.sort(),U=Y[Y.length-1]??""}catch{}if(J>0)process.stdout.write(` Escalations: ${J} handoff doc${J===1?"":"s"} (latest: ${U})
|
|
53
|
+
`)}}function gQ($){if(!v($))return[];try{return K$("fs").readdirSync($).filter((z)=>/^findings-\d+\.json$/.test(z)).sort((z,X)=>{let q=Number.parseInt(z.replace(/[^0-9]/g,""),10)||0,K=Number.parseInt(X.replace(/[^0-9]/g,""),10)||0;return q-K}).map((z)=>C($,z))}catch{return[]}}function i1($){try{let Q=K$("fs");return JSON.parse(Q.readFileSync($,"utf-8"))}catch{return null}}async function fQ(){let $=await Q$();if(!$)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
54
|
+
`),1;let Q=g,Z=P(),z=process.env.LOKI_DASHBOARD_PORT||"57374",X=process.env.LOKI_PROVIDER||"claude",q=await k([$,"-c",bQ,Q,Z,z,X],{timeoutMs:30000});if(q.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
55
|
+
`),1;return process.stdout.write(q.stdout),0}async function uQ($){let Q=[...$];while(Q.length>0){let Z=Q[0];if(Z==="--json")return fQ();if(Z==="--help"||Z==="-h")return process.stdout.write(`Usage: loki status [--json]
|
|
56
|
+
`),0;return process.stdout.write(`${T}Unknown flag: ${Z}${V}
|
|
56
57
|
`),process.stdout.write(`Usage: loki status [--json]
|
|
57
|
-
`),1}return
|
|
58
|
+
`),1}return vQ()}var k$=30,bQ=`
|
|
58
59
|
import json, os, sys, time
|
|
59
60
|
|
|
60
61
|
skill_dir = sys.argv[1]
|
|
@@ -328,11 +329,11 @@ if os.path.isfile(gate_count_file):
|
|
|
328
329
|
result['phase1'] = phase1
|
|
329
330
|
|
|
330
331
|
print(json.dumps(result, indent=2))
|
|
331
|
-
`;var
|
|
332
|
-
`)}var
|
|
333
|
-
`)}function
|
|
334
|
-
Start a session with: loki start <prd>`}}let X=
|
|
335
|
-
`);if(
|
|
332
|
+
`;var $0=L(()=>{d();q$();c();b()});var Z0={};h(Z0,{emitDeprecatedAlias:()=>i$,deprecatedAliasShouldSuppress:()=>Q0});function Q0($){let Q=$[0];if(Q!==void 0&&pQ.has(Q))return!0;for(let Z of $)if(cQ.has(Z))return!0;return!1}function i$($,Q,Z){if(Q0(Z))return;process.stderr.write(`note: 'loki ${$}' is now 'loki ${Q}'. The old form still works.
|
|
333
|
+
`)}var cQ,pQ;var e$=L(()=>{cQ=new Set(["--json","-q","--quiet"]),pQ=new Set(["json","csv","timeline"])});var q0={};h(q0,{runStats:()=>sQ,computeStats:()=>K0});import{readdirSync as z0,readFileSync as lQ,statSync as X0}from"fs";import{join as s}from"path";function J$($){try{if(!X0($).isFile())return null;return JSON.parse(lQ($,"utf-8"))}catch{return null}}function Z1($){try{return X0($).isDirectory()}catch{return!1}}function dQ($){if(!Z1($))return[];try{let Q=z0($).filter((Z)=>Z.startsWith("iteration-")&&Z.endsWith(".json"));return Q.sort(),Q.map((Z)=>s($,Z))}catch{return[]}}function U$($){return Math.trunc($).toLocaleString("en-US")}function $1($){let Q=Math.trunc($);if(Q<60)return`${Q}s`;let Z=Math.trunc(Q/3600),z=Math.trunc(Q%3600/60),X=Q%60;if(Z>0)return`${Z}h ${String(z).padStart(2,"0")}m`;return`${z}m ${String(X).padStart(2,"0")}s`}function r($,Q=0){let Z=Math.pow(10,Q);return Math.round($*Z)/Z}function H$($,Q){return $.toFixed(Q)}function Q1($,Q){return $.length>=Q?$:$+" ".repeat(Q-$.length)}function oQ($){let Q="N/A",Z=0,z=J$(s($,"state","orchestrator.json"));if(z&&typeof z==="object"){if(typeof z.currentPhase==="string")Q=z.currentPhase;if(typeof z.currentIteration==="number")Z=z.currentIteration}let X=s($,"metrics","efficiency"),q=dQ(X),K=[];for(let j of q){let N=J$(j);if(N&&typeof N==="object")K.push(N)}if(K.length>0)Z=Math.max(Z,K.length);let W=K.reduce((j,N)=>j+(N.input_tokens??0),0),J=K.reduce((j,N)=>j+(N.output_tokens??0),0),U=W+J,H=K.reduce((j,N)=>j+(N.cost_usd??0),0),Y=K.reduce((j,N)=>j+(N.duration_seconds??0),0),B=0,G=0,O=J$(s($,"metrics","budget.json"));if(O&&typeof O==="object"){if(typeof O.budget_limit==="number")B=O.budget_limit;if(typeof O.budget_used==="number")G=O.budget_used}let M=0,F=0,x=J$(s($,"state","quality-gates.json"));if(x&&typeof x==="object"){if(Array.isArray(x)){for(let j of x)if(F+=1,j===!0)M+=1;else if(j&&typeof j==="object"){let N=j;if(N.passed===!0||N.status==="passed")M+=1}}else for(let j of Object.values(x))if(typeof j==="boolean"){if(F+=1,j)M+=1}else if(j&&typeof j==="object"){F+=1;let N=j;if(N.passed===!0||N.status==="passed")M+=1}}let D={},w=J$(s($,"quality","gate-failure-count.json"));if(w&&typeof w==="object"&&!Array.isArray(w)){let j={};for(let[N,l]of Object.entries(w))if(typeof l==="number")j[N]=l;D=j}let E=0,u=0,E1=0,l$=s($,"quality");if(Z1(l$)){let j=[];try{j=z0(l$)}catch{j=[]}for(let N of j){if(!N.endsWith(".json")||N==="gate-failure-count.json")continue;let l=J$(s(l$,N));if(!l||typeof l!=="object")continue;if(!(("verdict"in l)||("approved"in l)||("reviewers"in l)))continue;E+=1;let N1=(l.verdict??"").toString().toLowerCase();if(l.approved===!0||["approved","approve","pass"].includes(N1))u+=1;else if(["revision","revise","changes_requested","reject"].includes(N1))E1+=1}}return{phase:Q,iterationCount:Z,iterations:K,totalInput:W,totalOutput:J,totalTokens:U,totalCost:H,totalDuration:Y,budgetLimit:B,budgetUsed:G,gatesPassed:M,gatesTotal:F,gateFailures:D,reviewsTotal:E,reviewsApproved:u,reviewsRevision:E1}}function nQ($,Q){let Z=$.iterationCount,z={session:{iterations:Z,duration_seconds:$.totalDuration,phase:$.phase},tokens:{input:$.totalInput,output:$.totalOutput,total:$.totalTokens,cost_usd:r($.totalCost,2)},quality:{gates_passed:$.gatesPassed,gates_total:$.gatesTotal,reviews_total:$.reviewsTotal,reviews_approved:$.reviewsApproved,reviews_revision:$.reviewsRevision,gate_failures:$.gateFailures},efficiency:{avg_tokens_per_iteration:Z>0?r($.totalTokens/Z,0):0,avg_cost_per_iteration:Z>0?r($.totalCost/Z,2):0,avg_duration_per_iteration:Z>0?r($.totalDuration/Z,1):0},budget:{used:r($.budgetUsed,2),limit:$.budgetLimit,percent:$.budgetLimit>0?r($.budgetUsed/$.budgetLimit*100,1):0}};if(Q)z.iterations=$.iterations.map((K,W)=>({number:W+1,input_tokens:K.input_tokens??0,output_tokens:K.output_tokens??0,cost_usd:r(K.cost_usd??0,2),duration_seconds:K.duration_seconds??0}));let X=JSON.stringify(z,null,2);function q(K,W){if(!W)return;let J=new RegExp(`("${K}": )(-?\\d+)(,?)$`,"m");X=X.replace(J,(U,H,Y,B)=>`${H}${Y}.0${B}`)}if(q("avg_duration_per_iteration",Z>0&&Number.isInteger(z.efficiency.avg_duration_per_iteration)),q("percent",$.budgetLimit>0&&Number.isInteger(z.budget.percent)),q("cost_usd",Z>0&&Number.isInteger(z.tokens.cost_usd)),Q)X=X.replace(/("cost_usd": )(-?\d+)(,?)$/gm,(K,W,J,U)=>`${W}${J}.0${U}`);return X}function aQ($,Q){let Z=[];if(Z.push("Loki Mode Session Statistics"),Z.push("============================"),Z.push(""),Z.push("Session"),Z.push(` Iterations completed: ${$.iterationCount}`),Z.push(` Duration: ${$1($.totalDuration)}`),Z.push(` Current phase: ${$.phase}`),Z.push(""),Z.push("Token Usage"),$.iterations.length>0)Z.push(` Input tokens: ${U$($.totalInput)}`),Z.push(` Output tokens: ${U$($.totalOutput)}`),Z.push(` Total tokens: ${U$($.totalTokens)}`),Z.push(` Estimated cost: $${H$($.totalCost,2)}`);else Z.push(" N/A (no iteration metrics found)");if(Z.push(""),Z.push("Quality Gates"),$.gatesTotal>0){let z=Math.round($.gatesPassed/$.gatesTotal*100);Z.push(` Gates passed: ${$.gatesPassed}/${$.gatesTotal} (${z}%)`)}else Z.push(" Gates passed: N/A");if($.reviewsTotal>0){let z=[];if($.reviewsApproved>0)z.push(`${$.reviewsApproved} approved`);if($.reviewsRevision>0)z.push(`${$.reviewsRevision} revision requested`);let X=z.length>0?z.join(", "):"N/A";Z.push(` Code reviews: ${$.reviewsTotal} (${X})`)}if(Object.keys($.gateFailures).length>0){let z=Object.entries($.gateFailures).filter(([,X])=>X>0).map(([X,q])=>`${X} (${q})`);if(z.length>0)Z.push(` Gate failures: ${z.join(", ")}`)}if(Z.push(""),Z.push("Efficiency"),$.iterationCount>0&&$.iterations.length>0){let z=Math.round($.totalTokens/$.iterationCount),X=$.totalCost/$.iterationCount,q=$.totalDuration/$.iterationCount;Z.push(` Avg tokens/iteration: ${U$(z)}`),Z.push(` Avg cost/iteration: $${H$(X,2)}`),Z.push(` Avg duration/iteration: ${$1(q)}`)}else Z.push(" N/A (no iteration metrics found)");if(Z.push(""),Z.push("Budget"),$.budgetLimit>0){let z=r($.budgetUsed/$.budgetLimit*100,1),X=Number.isInteger(z)?`${z}.0`:`${z}`;Z.push(` Used: $${H$($.budgetUsed,2)} / $${H$($.budgetLimit,2)} (${X}%)`)}else if($.budgetUsed>0)Z.push(` Used: $${H$($.budgetUsed,2)} (no limit set)`);else Z.push(" N/A");if(Q&&$.iterations.length>0)Z.push(""),Z.push("Per-Iteration Breakdown"),$.iterations.forEach((z,X)=>{let q=X+1,K=Q1(U$(z.input_tokens??0),10),W=Q1(U$(z.output_tokens??0),10),J=z.cost_usd??0,U=$1(z.duration_seconds??0),H=Q1(`${q}`,3);Z.push(` #${H} input: ${K} output: ${W} cost: $${H$(J,2)} time: ${U}`)});return Z.join(`
|
|
334
|
+
`)}function K0($){let Q=!1,Z=!1;for(let K of $)if(K==="--json")Q=!0;else if(K==="--efficiency")Z=!0;let z=P();if(!Z1(z)){if(Q)return{exitCode:0,stdout:'{"error": "No active session"}'};return{exitCode:0,stdout:`${_}No active session found.${V}
|
|
335
|
+
Start a session with: loki start <prd>`}}let X=oQ(z);return{exitCode:0,stdout:Q?nQ(X,Z):aQ(X,Z)}}async function sQ($){let{emitDeprecatedAlias:Q}=await Promise.resolve().then(() => (e$(),Z0));Q("stats","report session",$);let Z=K0($);return console.log(Z.stdout),Z.exitCode}var V0=L(()=>{b();c()});var T0={};h(T0,{runDoctor:()=>J3,pythonImportOk:()=>q1,httpReachable:()=>X1,checkTool:()=>B0,checkSkills:()=>G0,checkDisk:()=>K1,buildDoctorJson:()=>M0,_setPythonImportOkForTest:()=>Z3});import{existsSync as W0,lstatSync as rQ,readlinkSync as tQ,statfsSync as iQ}from"fs";import{spawnSync as eQ}from"child_process";import{homedir as J0}from"os";import{resolve as z1}from"path";function Q3($){let Q=$.match($3);return Q?Q[1]:null}async function U0($){try{let Q=await k([$,"--version"],{timeoutMs:5000}),Z=(Q.stdout||Q.stderr||"").trim();return Q3(Z)}catch{return null}}function H0($,Q){let Z=$.split(".").map((X)=>parseInt(X,10)),z=Q.split(".").map((X)=>parseInt(X,10));while(Z.length<2)Z.push(0);while(z.length<2)z.push(0);for(let X=0;X<2;X++){let q=Z[X]??0,K=z[X]??0;if(Number.isNaN(q)||Number.isNaN(K))return 0;if(q!==K)return q-K}return 0}async function B0($,Q,Z,z=null){let X=await f(Q),q=X!==null,K=q?await U0(Q):null,W="pass";if(!q)W=Z==="required"?"fail":"warn";else if(z&&K){if(H0(K,z)<0)W=Z==="required"?"fail":"warn"}return{name:$,command:Q,found:q,version:K,required:Z,min_version:z,status:W,path:X}}function K1(){let $=null;try{let Z=iQ(J0()),z=Number(Z.bavail)*Number(Z.bsize);$=Math.round(z/1073741824*10)/10}catch{$=null}let Q="pass";if($!==null){if($<1)Q="fail";else if($<5)Q="warn"}return{available_gb:$,status:Q}}async function X1($,Q=2000){try{return(await fetch($,{signal:AbortSignal.timeout(Q)})).ok}catch{return!1}}async function q1($,Q=!1){let Z=`import ${$}`,z=Q?30000:5000;if(!Q)return(await Z$(Z,{timeoutMs:z})).exitCode===0;let X=await Q$();if(!X)return!1;return(await k([X,"-c",Z],{timeoutMs:z})).exitCode===0}function Z3($){S$.fn=$??q1}function G0(){let $=J0();return z3.map(({name:Q,dir:Z})=>{let z=z1($,Z),X=z,q=z1(z,"SKILL.md");if(W0(q))return{name:Q,path:X,status:"pass",detail:""};try{if(rQ(z).isSymbolicLink()){let W="unknown";try{W=tQ(z)}catch{}return{name:Q,path:X,status:"fail",detail:`(broken symlink -> ${W})`}}}catch{}return{name:Q,path:X,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function Y0(){return Promise.all(X3.map(async($)=>{return{...await B0($.jsonName,$.cmd,$.required,$.min??null),displayName:$.displayName}}))}async function K3(){let Q=await f("sentrux")!==null,Z=Q?await U0("sentrux"):null;return{found:Q,version:Z,status:Q?"pass":"warn",required:"optional"}}async function q3(){let{openSync:$,statSync:Q,readSync:Z,closeSync:z,existsSync:X}=await import("fs"),{join:q}=await import("path"),K=65536,W=process.env.LOKI_DIR??".loki",J=q(W,"memory",".errors.log"),U=[],H=!1;try{if(X(J)){H=!0;let Y=Q(J).size,B=Math.max(0,Y-65536),G=Y-B,O=Buffer.alloc(G),M=$(J,"r");try{Z(M,O,0,G,B)}finally{z(M)}let x=O.toString("utf-8").split(`
|
|
336
|
+
`);if(B>0&&x.length>0)x=x.slice(1);x=x.map((D)=>D.trim()).filter((D)=>D.length>0),U=x.slice(-5)}}catch{U=[]}return{errors_log_path:H?J:null,recent_errors:U,recent_error_count:U.length,status:U.length===0?"pass":"warn"}}async function M0(){let Q=(await Y0()).map(({displayName:J,...U})=>U),Z=K1(),z=await K3(),X=await q3(),q=0,K=0,W=0;for(let J of Q)if(J.status==="pass")q++;else if(J.status==="fail")K++;else W++;if(Z.status==="pass")q++;else if(Z.status==="fail")K++;else W++;return{loki_mode_version:j$(),checks:Q,disk:Z,sentrux:z,memory:X,summary:{passed:q,failed:K,warnings:W,ok:K===0}}}function A($){switch($){case"pass":return`${S}PASS${V}`;case"fail":return`${T}FAIL${V}`;case"warn":return`${_}WARN${V}`}}function E$($){let Q=$.version?` (v${$.version})`:"",Z=$.displayName;if(!$.found){let z=$.required==="required"?"not found":$.required==="recommended"?"not found (recommended)":"not found (optional)";return` ${A($.status)} ${Z} - ${z}`}if($.min_version&&$.version&&H0($.version,$.min_version)<0){let z=$.required==="required"?"requires":"recommended";return` ${A($.status)} ${Z}${Q} - ${z} >= ${$.min_version}`}return` ${A($.status)} ${Z}${Q}`}function N$($,Q){if(Q==="pass")$.pass++;else if(Q==="fail")$.fail++;else $.warn++}function V3(){process.stdout.write(`${R}loki doctor${V} - Check system prerequisites
|
|
336
337
|
|
|
337
338
|
`),process.stdout.write(`Usage: loki doctor [--json]
|
|
338
339
|
|
|
@@ -341,84 +342,84 @@ Start a session with: loki start <prd>`}}let X=pQ(z);return{exitCode:0,stdout:Q?
|
|
|
341
342
|
|
|
342
343
|
`),process.stdout.write(`Checks: node, python3, jq, git, curl, bash version,
|
|
343
344
|
`),process.stdout.write(` claude/codex CLIs, and disk space.
|
|
344
|
-
`)}async function
|
|
345
|
+
`)}async function W3(){process.stdout.write(`${R}Loki Mode Doctor${V}
|
|
345
346
|
|
|
346
347
|
`),process.stdout.write(`Checking system prerequisites...
|
|
347
348
|
|
|
348
|
-
`);let $={pass:0,fail:0,warn:0},Q=await
|
|
349
|
-
`);for(let
|
|
350
|
-
`),
|
|
351
|
-
`),process.stdout.write(`${
|
|
352
|
-
`);let z=["claude","codex","cline","aider"],X=!1;for(let
|
|
353
|
-
`),
|
|
354
|
-
`),process.stdout.write(` ${
|
|
355
|
-
`),$.fail++,process.stdout.isTTY){let
|
|
356
|
-
`),process.stdout.write(`${
|
|
357
|
-
`);let
|
|
358
|
-
`),$.pass++;else if(
|
|
359
|
-
`);if(
|
|
360
|
-
`),$.pass++;else if(K)process.stdout.write(` ${y} -- ${
|
|
361
|
-
`);if(
|
|
362
|
-
`),$.pass++,!
|
|
363
|
-
`),$.warn++;else process.stdout.write(` ${A("pass")} LOKI_MODEL_OVERRIDE: ${
|
|
349
|
+
`);let $={pass:0,fail:0,warn:0},Q=await Y0(),Z=new Map(Q.map((w)=>[w.command,w]));process.stdout.write(`${I}Required:${V}
|
|
350
|
+
`);for(let w of["node","python3","jq","git","curl"]){let E=Z.get(w);process.stdout.write(E$(E)+`
|
|
351
|
+
`),N$($,E.status)}process.stdout.write(`
|
|
352
|
+
`),process.stdout.write(`${I}AI Providers:${V}
|
|
353
|
+
`);let z=["claude","codex","cline","aider"],X=!1;for(let w of z){let E=Z.get(w);if(process.stdout.write(E$(E)+`
|
|
354
|
+
`),N$($,E.status),E.found)X=!0}if(!X){if(process.stdout.write(` ${A("fail")} No AI provider CLI installed -- at least one is required
|
|
355
|
+
`),process.stdout.write(` ${_}Install: npm install -g @anthropic-ai/claude-code${V}
|
|
356
|
+
`),$.fail++,process.stdout.isTTY){let w=z1(g,"autonomy/provider-offer.sh");if(W0(w))eQ("bash",[w,"report"],{stdio:"inherit"})}}process.stdout.write(`
|
|
357
|
+
`),process.stdout.write(`${I}API Keys:${V}
|
|
358
|
+
`);let q=Z.get("claude")?.found??!1,K=Z.get("codex")?.found??!1,W=process.env;if(W.ANTHROPIC_API_KEY)process.stdout.write(` ${A("pass")} ANTHROPIC_API_KEY is set
|
|
359
|
+
`),$.pass++;else if(q)process.stdout.write(` ${y} -- ${V} ANTHROPIC_API_KEY not set (Claude CLI uses its own login)
|
|
360
|
+
`);if(W.OPENAI_API_KEY)process.stdout.write(` ${A("pass")} OPENAI_API_KEY is set
|
|
361
|
+
`),$.pass++;else if(K)process.stdout.write(` ${y} -- ${V} OPENAI_API_KEY not set (Codex CLI uses its own login)
|
|
362
|
+
`);if(W.ANTHROPIC_BASE_URL){let w=W.ANTHROPIC_BASE_URL;if(process.stdout.write(` ${A("pass")} ANTHROPIC_BASE_URL: ${w}
|
|
363
|
+
`),$.pass++,!W.LOKI_MODEL_OVERRIDE)process.stdout.write(` ${A("warn")} LOKI_MODEL_OVERRIDE not set -- opus/sonnet/haiku aliases may not resolve on alt-provider
|
|
364
|
+
`),$.warn++;else process.stdout.write(` ${A("pass")} LOKI_MODEL_OVERRIDE: ${W.LOKI_MODEL_OVERRIDE}
|
|
364
365
|
`),$.pass++}process.stdout.write(`
|
|
365
|
-
`),process.stdout.write(`${
|
|
366
|
-
`);for(let
|
|
367
|
-
`),$.pass++;else if(
|
|
368
|
-
`),process.stdout.write(` ${
|
|
369
|
-
`),$.fail++;else process.stdout.write(` ${A("warn")} ${
|
|
366
|
+
`),process.stdout.write(`${I}Skills:${V}
|
|
367
|
+
`);for(let w of G0())if(w.status==="pass")process.stdout.write(` ${A("pass")} ${w.name} ${y}${w.path}${V}
|
|
368
|
+
`),$.pass++;else if(w.status==="fail")process.stdout.write(` ${A("fail")} ${w.name} ${y}${w.detail}${V}
|
|
369
|
+
`),process.stdout.write(` ${_}Fix: loki setup-skill${V}
|
|
370
|
+
`),$.fail++;else process.stdout.write(` ${A("warn")} ${w.name} ${y}${w.detail}${V}
|
|
370
371
|
`),$.warn++;process.stdout.write(`
|
|
371
|
-
`),process.stdout.write(`${
|
|
372
|
-
`);let[
|
|
372
|
+
`),process.stdout.write(`${I}Integrations:${V}
|
|
373
|
+
`);let[J,U,H]=await Promise.all([S$.fn("mcp"),S$.fn("numpy",!0),S$.fn("sentence_transformers",!0)]);if(J)process.stdout.write(` ${A("pass")} MCP SDK (Python)
|
|
373
374
|
`),$.pass++;else process.stdout.write(` ${A("warn")} MCP SDK - not installed (pip3 install mcp)
|
|
374
|
-
`),$.warn++;if(
|
|
375
|
+
`),$.warn++;if(U)process.stdout.write(` ${A("pass")} numpy (vector search)
|
|
375
376
|
`),$.pass++;else process.stdout.write(` ${A("warn")} numpy - not installed (pip3 install numpy)
|
|
376
|
-
`),$.warn++;if(
|
|
377
|
+
`),$.warn++;if(H)process.stdout.write(` ${A("pass")} sentence-transformers (embeddings)
|
|
377
378
|
`),$.pass++;else process.stdout.write(` ${A("warn")} sentence-transformers - not installed (loki memory vectors setup)
|
|
378
|
-
`),$.warn++;if(await
|
|
379
|
+
`),$.warn++;if(await X1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${A("pass")} ChromaDB server (port 8100)
|
|
379
380
|
`),$.pass++;else process.stdout.write(` ${A("warn")} ChromaDB - not running (docker start loki-chroma)
|
|
380
|
-
`),$.warn++;{let
|
|
381
|
+
`),$.warn++;{let w=["pyright-langserver","pylsp","typescript-language-server","gopls","rust-analyzer","jdtls"],E=[];for(let u of w)if(await f(u))E.push(u);if(E.length>0)process.stdout.write(` ${A("pass")} LSP servers detected (${E.length}): ${E.join(", ")}
|
|
381
382
|
`),$.pass++;else process.stdout.write(` ${A("warn")} LSP servers - none on PATH (install for symbol grounding: npm i -g pyright typescript-language-server; brew install gopls)
|
|
382
|
-
`),$.warn++}let Y=process.env.LOKI_MIROFISH_URL;if(Y)if(await
|
|
383
|
+
`),$.warn++}let Y=process.env.LOKI_MIROFISH_URL;if(Y)if(await X1(`${Y}/health`))process.stdout.write(` ${A("pass")} MiroFish server (${Y})
|
|
383
384
|
`),$.pass++;else process.stdout.write(` ${A("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
|
|
384
385
|
`),$.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${A("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
|
|
385
386
|
`),$.pass++;else process.stdout.write(` ${A("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
|
|
386
|
-
`),$.warn++;if(await f("sentrux")){let
|
|
387
|
+
`),$.warn++;if(await f("sentrux")){let w="unknown";try{let u=(await k(["sentrux","--version"],{timeoutMs:2000})).stdout.split(/\s+/).filter(Boolean).pop();if(u)w=u.replace(/^v/,"")}catch{}process.stdout.write(` ${A("pass")} sentrux ${w} (architectural drift gate: loki sentrux help)
|
|
387
388
|
`),$.pass++}else process.stdout.write(` ${A("warn")} sentrux - not installed (optional, brew install sentrux/tap/sentrux)
|
|
388
389
|
`),$.warn++;process.stdout.write(`
|
|
389
|
-
`),process.stdout.write(`${
|
|
390
|
-
`);let
|
|
391
|
-
`),
|
|
392
|
-
`),
|
|
390
|
+
`),process.stdout.write(`${I}System:${V}
|
|
391
|
+
`);let B=Z.get("bash");process.stdout.write(E$(B)+`
|
|
392
|
+
`),N$($,B.status);let G=Z.get("bun");if(G)process.stdout.write(E$(G)+`
|
|
393
|
+
`),N$($,G.status);let O=K1(),M=O.available_gb===null?null:Math.floor(O.available_gb);if(M===null)process.stdout.write(` ${A("warn")} Disk space: unable to determine
|
|
393
394
|
`),$.warn++;else if(O.status==="fail")process.stdout.write(` ${A("fail")} Disk space: ${M}GB available (need >= 1GB)
|
|
394
395
|
`),$.fail++;else if(O.status==="warn")process.stdout.write(` ${A("warn")} Disk space: ${M}GB available (low)
|
|
395
396
|
`),$.warn++;else process.stdout.write(` ${A("pass")} Disk space: ${M}GB available
|
|
396
397
|
`),$.pass++;process.stdout.write(`
|
|
397
|
-
`),process.stdout.write(`${
|
|
398
|
-
`);let
|
|
398
|
+
`),process.stdout.write(`${I}Runtime route:${V}
|
|
399
|
+
`);let F=process.versions.bun!==void 0,x=process.argv[0]??"(unknown)";if(process.stdout.write(` ${A("pass")} Active runtime: ${F?"Bun":"Node"} (${x})
|
|
399
400
|
`),process.env.LOKI_LEGACY_BASH==="1"||process.env.LOKI_LEGACY_BASH==="true")process.stdout.write(` ${A("warn")} LOKI_LEGACY_BASH set: shim routes every command to autonomy/loki (bash)
|
|
400
401
|
`);if(process.env.LOKI_TS_ENTRY)process.stdout.write(` ${A("pass")} LOKI_TS_ENTRY override: ${process.env.LOKI_TS_ENTRY}
|
|
401
402
|
`);if(process.env.BUN_FROM_SOURCE==="1"||process.env.BUN_FROM_SOURCE==="true")process.stdout.write(` ${A("pass")} BUN_FROM_SOURCE set: shim prefers loki-ts/src/ over dist/
|
|
402
|
-
`);let
|
|
403
|
-
`);else if(
|
|
404
|
-
`);else process.stdout.write(` ${A("warn")} Python 3 found at ${
|
|
403
|
+
`);let D=await Q$();if(D!==null){let E=(await k([D,"-c","import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"],{timeoutMs:5000})).stdout.trim();if(E.startsWith("3.12"))process.stdout.write(` ${A("pass")} Python 3.12 (chromadb / sentence-transformers): ${E} at ${D}
|
|
404
|
+
`);else if(E)process.stdout.write(` ${A("warn")} Python 3.12 NOT found -- using ${E} at ${D}; chromadb / sentence-transformers may fail. Install python3.12 (brew install python@3.12 / apt install python3.12).
|
|
405
|
+
`);else process.stdout.write(` ${A("warn")} Python 3 found at ${D} but version probe failed; chromadb may not work.
|
|
405
406
|
`)}else process.stdout.write(` ${A("warn")} Python 3 not on PATH -- memory + MCP integrations disabled.
|
|
406
407
|
`);if(process.stdout.write(`
|
|
407
|
-
`),process.stdout.write(`${R}Summary:${
|
|
408
|
+
`),process.stdout.write(`${R}Summary:${V} ${S}${$.pass} passed${V}, ${T}${$.fail} failed${V}, ${_}${$.warn} warnings${V}
|
|
408
409
|
|
|
409
|
-
`),$.fail>0)return process.stdout.write(`${T}Some required prerequisites are missing.${
|
|
410
|
+
`),$.fail>0)return process.stdout.write(`${T}Some required prerequisites are missing.${V}
|
|
410
411
|
`),process.stdout.write(`Install missing dependencies and run 'loki doctor' again.
|
|
411
|
-
`),1;if($.warn>0)return process.stdout.write(`${
|
|
412
|
-
`),0;return process.stdout.write(`${S}All checks passed. System is ready for Loki Mode.${
|
|
413
|
-
`),0}async function
|
|
412
|
+
`),1;if($.warn>0)return process.stdout.write(`${_}All required checks passed with some warnings.${V}
|
|
413
|
+
`),0;return process.stdout.write(`${S}All checks passed. System is ready for Loki Mode.${V}
|
|
414
|
+
`),0}async function J3($){let Q=!1;for(let Z of $)if(Z==="--json")Q=!0;else if(Z==="--help"||Z==="-h")return V3(),0;else return process.stderr.write(`${T}Unknown option: ${Z}${V}
|
|
414
415
|
`),process.stderr.write(`Usage: loki doctor [--json]
|
|
415
|
-
`),1;if(Q){let Z=await
|
|
416
|
-
`),0}return
|
|
417
|
-
`)}var
|
|
416
|
+
`),1;if(Q){let Z=await M0();return process.stdout.write(JSON.stringify(Z,null,2)+`
|
|
417
|
+
`),0}return W3()}var $3,S$,z3,X3;var O0=L(()=>{b();d();q$();c();a$();$3=/(\d+\.\d+(?:\.\d+)*)/;S$={fn:q1};z3=[{name:"Claude Code",dir:".claude/skills/loki-mode"},{name:"Codex CLI",dir:".codex/skills/loki-mode"},{name:"Cline CLI",dir:".cline/skills/loki-mode"},{name:"Aider CLI",dir:".aider/skills/loki-mode"}];X3=[{displayName:"Node.js (>= 18)",jsonName:"Node.js",cmd:"node",required:"required",min:"18.0"},{displayName:"Python 3 (>= 3.8)",jsonName:"Python 3",cmd:"python3",required:"required",min:"3.8"},{displayName:"jq",jsonName:"jq",cmd:"jq",required:"required"},{displayName:"git",jsonName:"git",cmd:"git",required:"required"},{displayName:"curl",jsonName:"curl",cmd:"curl",required:"required"},{displayName:"bash (>= 4.0)",jsonName:"bash",cmd:"bash",required:"recommended",min:"4.0"},{displayName:"Bun (>= 1.3)",jsonName:"Bun",cmd:"bun",required:"recommended",min:"1.3"},{displayName:"Claude CLI",jsonName:"Claude CLI",cmd:"claude",required:"optional"},{displayName:"Codex CLI",jsonName:"Codex CLI",cmd:"codex",required:"optional"},{displayName:"Cline CLI",jsonName:"Cline CLI",cmd:"cline",required:"optional"},{displayName:"Aider CLI",jsonName:"Aider CLI",cmd:"aider",required:"optional"}]});import{existsSync as _0,mkdirSync as B9,readdirSync as U3,readFileSync as I0,renameSync as G9,writeFileSync as Y9}from"fs";import{dirname as H3,join as B3,resolve as G3}from"path";import{fileURLToPath as Y3}from"url";function M3(){try{let $=H3(Y3(import.meta.url)),Q=G3($,"..","..","data","model-pricing.json");if(!_0(Q))return M$;let z=JSON.parse(I0(Q,"utf8")).pricing;if(!z||typeof z!=="object")return M$;let X={};for(let[q,K]of Object.entries(z))if(K!==null&&typeof K==="object"&&typeof K.input==="number"&&typeof K.output==="number")X[q]={input:K.input,output:K.output};for(let q of Object.keys(M$))if(!(q in X))return M$;return X}catch{return M$}}function T3($){return Math.round(($+Number.EPSILON)*1e4)/1e4}function O3($){let Q=($??w0).toLowerCase();return A0[Q]??A0[w0]}function L0($){let Q=0;for(let Z of $){if(typeof Z.cost_usd==="number"&&Number.isFinite(Z.cost_usd)){Q+=Z.cost_usd;continue}let z=O3(Z.model),X=typeof Z.input_tokens==="number"?Z.input_tokens:0,q=typeof Z.output_tokens==="number"?Z.output_tokens:0;Q+=X/1e6*z.input+q/1e6*z.output}return T3(Q)}function P0($){if(!_0($))return[];let Q=[],Z;try{Z=U3($)}catch{return[]}for(let z of Z){if(!z.endsWith(".json"))continue;let X=B3($,z);try{let q=I0(X,"utf8"),K=JSON.parse(q);if(K&&typeof K==="object")Q.push(K)}catch{}}return Q}var M$,A0,w0="sonnet";var j0=L(()=>{b();M$={fable:{input:10,output:50},opus:{input:5,output:25},sonnet:{input:3,output:15},haiku:{input:1,output:5},"gpt-5.3-codex":{input:1.5,output:12}};A0=Object.freeze(M3())});import{existsSync as D$,readdirSync as A3,readFileSync as w3,statSync as _3}from"fs";import{join as C$}from"path";function I3($){let Q=[],Z=C$($,"votes");if(!D$(Z))return Q;let z;try{z=A3(Z)}catch{return Q}for(let X of z){if(!X.startsWith("round-")||!X.endsWith(".json"))continue;try{let q=C$(Z,X);if(!_3(q).isFile())continue;let K=JSON.parse(w3(q,"utf8"));Q.push({iteration:typeof K.iteration==="number"?K.iteration:void 0,verdict:typeof K.verdict==="string"?K.verdict:void 0,complete_votes:typeof K.complete_votes==="number"?K.complete_votes:void 0,total_members:typeof K.total_members==="number"?K.total_members:void 0,threshold:typeof K.threshold==="number"?K.threshold:void 0})}catch{}}return Q}function L3(){return{iteration_count:0,total_cost_usd:0,avg_cost_per_iteration:null,total_input_tokens:0,total_output_tokens:0,total_duration_ms:0,avg_duration_ms_per_iteration:null,model_breakdown:{},phase_breakdown:{},status_breakdown:{}}}function P3(){return{council_rounds:0,unanimous_rate:null,approval_rate:null,iteration_success_rate:null}}function j3($){let Q=L3();if($.length===0)return Q;Q.iteration_count=$.length,Q.total_cost_usd=Math.round(L0($)*1e4)/1e4;for(let Z of $){if(typeof Z.input_tokens==="number")Q.total_input_tokens+=Z.input_tokens;if(typeof Z.output_tokens==="number")Q.total_output_tokens+=Z.output_tokens;let z=Z;if(typeof z.duration_ms==="number")Q.total_duration_ms+=z.duration_ms;if(typeof Z.model==="string")Q.model_breakdown[Z.model]=(Q.model_breakdown[Z.model]??0)+1;if(typeof z.phase==="string")Q.phase_breakdown[z.phase]=(Q.phase_breakdown[z.phase]??0)+1;if(typeof z.status==="string")Q.status_breakdown[z.status]=(Q.status_breakdown[z.status]??0)+1}return Q.avg_cost_per_iteration=Math.round(Q.total_cost_usd/Q.iteration_count*1e4)/1e4,Q.avg_duration_ms_per_iteration=Math.round(Q.total_duration_ms/Q.iteration_count),Q}function F3($,Q,Z){let z=P3();if(z.council_rounds=$.length,$.length>0){let X=0,q=0;for(let K of $){if(typeof K.complete_votes==="number"&&typeof K.total_members==="number"&&K.total_members>0&&K.complete_votes===K.total_members)X+=1;if(K.verdict==="COMPLETE")q+=1}z.unanimous_rate=Math.round(X/$.length*1e4)/1e4,z.approval_rate=Math.round(q/$.length*1e4)/1e4}if(Z>0)z.iteration_success_rate=Math.round(Q/Z*1e4)/1e4;return z}function F0($){let Q=[],Z=C$($,"metrics","efficiency"),z=C$($,"council"),X=D$(Z)?P0(Z):[];if(!D$(Z))Q.push("no .loki/metrics/efficiency/ dir (efficiency KPIs zeroed)");else if(X.length===0)Q.push(".loki/metrics/efficiency/ exists but no iteration files found");let q=I3(z);if(!D$(z))Q.push("no .loki/council/ dir (accuracy KPIs zeroed)");else if(q.length===0)Q.push(".loki/council/ exists but no round-N.json files found");let K=j3(X),W=K.status_breakdown.success??0,J=F3(q,W,K.iteration_count);return{schema_version:1,generated_at:new Date().toISOString(),loki_dir:$,efficiency:K,accuracy:J,notes:Q}}function k0($){return JSON.stringify($,null,2)}function R0($){let Q=[];Q.push(`Loki Mode KPIs (snapshot at ${$.generated_at})`),Q.push(`Source: ${$.loki_dir}`),Q.push(""),Q.push("Efficiency"),Q.push(` Iterations: ${$.efficiency.iteration_count}`),Q.push(` Total cost USD: ${$.efficiency.total_cost_usd}`),Q.push(` Avg cost per iter: ${$.efficiency.avg_cost_per_iteration??"n/a"}`),Q.push(` Total input tokens: ${$.efficiency.total_input_tokens}`),Q.push(` Total output tokens: ${$.efficiency.total_output_tokens}`),Q.push(` Total duration (ms): ${$.efficiency.total_duration_ms}`),Q.push(` Avg duration / iter: ${$.efficiency.avg_duration_ms_per_iteration??"n/a"}`);let Z=Object.entries($.efficiency.model_breakdown).sort((q,K)=>q[0].localeCompare(K[0]));if(Z.length>0)Q.push(` Model breakdown: ${Z.map(([q,K])=>`${q}=${K}`).join(", ")}`);let z=Object.entries($.efficiency.phase_breakdown).sort((q,K)=>q[0].localeCompare(K[0]));if(z.length>0)Q.push(` Phase breakdown: ${z.map(([q,K])=>`${q}=${K}`).join(", ")}`);let X=Object.entries($.efficiency.status_breakdown).sort((q,K)=>q[0].localeCompare(K[0]));if(X.length>0)Q.push(` Status breakdown: ${X.map(([q,K])=>`${q}=${K}`).join(", ")}`);if(Q.push(""),Q.push("Accuracy"),Q.push(` Council rounds: ${$.accuracy.council_rounds}`),Q.push(` Unanimous rate: ${$.accuracy.unanimous_rate??"n/a"}`),Q.push(` Approval rate: ${$.accuracy.approval_rate??"n/a"}`),Q.push(` Iter success rate: ${$.accuracy.iteration_success_rate??"n/a"}`),$.notes.length>0){Q.push(""),Q.push("Notes");for(let q of $.notes)Q.push(` - ${q}`)}return Q.push(""),Q.push("See also: loki trust (trust trajectory across runs)"),Q.join(`
|
|
418
|
+
`)}var x0=L(()=>{j0()});var V1={};h(V1,{runKpis:()=>R3});function R3($,Q={}){if(Q.aliasOf)i$(Q.aliasOf,"report kpis",$);let Z=!1;for(let X of $){if(X==="--help"||X==="-h"||X==="help")return process.stdout.write(k3),0;if(X==="--json"){Z=!0;continue}if(X==="-q"||X==="--quiet")continue;return process.stderr.write(`loki kpis: unknown arg: ${X}
|
|
418
419
|
Run 'loki kpis --help' for usage.
|
|
419
|
-
`),1}let z=
|
|
420
|
-
`:
|
|
421
|
-
`),0}var
|
|
420
|
+
`),1}let z=F0(P());return process.stdout.write(Z?k0(z)+`
|
|
421
|
+
`:R0(z)+`
|
|
422
|
+
`),0}var k3=`loki report kpis -- accuracy + efficiency KPI snapshot (v7.5.28 MVP)
|
|
422
423
|
|
|
423
424
|
Usage:
|
|
424
425
|
loki report kpis Pretty-print KPI snapshot
|
|
@@ -439,13 +440,13 @@ iteration success rate.
|
|
|
439
440
|
This is the Phase K MVP -- read-only derivation. Per-iteration
|
|
440
441
|
emission, dashboard panel, and the loki-bench harness are deferred
|
|
441
442
|
follow-ups (see project_v7_5_18_arc_status.md).
|
|
442
|
-
`;var
|
|
443
|
-
`)}Q.push("Is the agent earning autonomy on this repo?");for(let X of
|
|
444
|
-
`)}var
|
|
443
|
+
`;var W1=L(()=>{x0();b();e$()});var E0={};h(E0,{delegateToBash:()=>N3});import{resolve as x3}from"path";async function N3($){let Q=x3(g,"autonomy","loki"),Z=Bun.spawn({cmd:[Q,...$],stdin:"inherit",stdout:"inherit",stderr:"inherit",env:{...process.env,LOKI_LEGACY_BASH:"1"}}),z=setTimeout(()=>{try{Z.kill("SIGKILL")}catch{}},E3);try{return await Z.exited}finally{clearTimeout(z)}}var E3=3600000;var N0=L(()=>{b()});import{existsSync as S3,mkdirSync as D3,readdirSync as C3,readFileSync as b3,statSync as h3,writeFileSync as y3}from"fs";import{join as T$}from"path";function J1($){return $&&typeof $==="object"?$:{}}function z$($){return Math.round($*1e4)/1e4}function u3($){let Q=String($??"").trim().toUpperCase();if(!Q)return null;for(let Z of D0)if(Q.startsWith(Z))return!0;return!1}function c3($){let Q=u3($.final_verdict);if(Q!==null)return Q?1:0;let Z=$.reviewers;if(Array.isArray(Z)&&Z.length>0){let z=0,X=0;for(let q of Z){if(!q||typeof q!=="object")continue;X+=1;let K=String(q.vote??"").trim().toUpperCase();if(D0.some((W)=>K.startsWith(W)))z+=1}if(X>0)return z===X?1:0}return null}function p3($){let Q=Number($.total),Z=Number($.passed);if(!Number.isFinite(Q)||!Number.isFinite(Z))return null;if(Q<=0)return null;return Math.max(0,Math.min(1,Z/Q))}function l3($){let Q;if($&&typeof $==="object")Q=$.count;else Q=$;let Z=Number(Q);if(!Number.isFinite(Z)||Z<0)return null;return Z}function d3($){let Q=J1($.council);for(let Z of[Q.interventions,$.interventions]){let z=Number(Z);if(Number.isFinite(z)&&z>=0)return z}return null}function o3($){let Q=T$($,"proofs"),Z=[];if(!S3(Q))return Z;let z;try{z=C3(Q).sort()}catch{return Z}for(let X of z){let q=T$(Q,X);try{if(!h3(q).isDirectory())continue}catch{continue}let K=null;try{K=JSON.parse(b3(T$(q,"proof.json"),"utf8"))}catch{continue}if(!K||typeof K!=="object")continue;Z.push({run_id:String(K.run_id??X),generated_at:typeof K.generated_at==="string"?K.generated_at:null,council_pass_rate:c3(J1(K.council)),gate_pass_rate:p3(J1(K.quality_gates)),iterations:l3(K.iterations),interventions:d3(K)})}return Z.sort((X,q)=>{let K=X.generated_at===null?1:0,W=q.generated_at===null?1:0;if(K!==W)return K-W;return(X.generated_at??"").localeCompare(q.generated_at??"")}),Z}function S0($){return $.reduce((Q,Z)=>Q+Z,0)/$.length}function n3($,Q){let Z=m3[$],z=g3[$],X=f3[$],q=Q.filter((M)=>M!==null),K=q.length;if(K===0)return{axis:$,label:X,available:!1,higher_is_better:Z,note:"no runs recorded this metric"};if(K<2)return{axis:$,label:X,available:!0,higher_is_better:Z,data_points:K,latest:z$(q[K-1]),direction:"flat",improving:null,delta:0,earlier_mean:z$(q[0]),later_mean:z$(q[K-1]),insufficient:!0,note:"not enough history yet (need 2+ runs with this metric)"};let W=Math.floor(K/2),J=q.slice(0,W),U=q.slice(K-W),H=S0(J),Y=S0(U),B=Y-H,G;if(Math.abs(B)<=z)G="flat";else if(B>0)G="up";else G="down";let O;if(G==="flat")O=null;else O=G==="up"===Z;return{axis:$,label:X,available:!0,higher_is_better:Z,data_points:K,latest:z$(q[K-1]),direction:G,improving:O,delta:z$(B),earlier_mean:z$(H),later_mean:z$(Y),insufficient:!1}}function C0($){let Q=o3($),Z=Q.map((J)=>({run_id:J.run_id,generated_at:J.generated_at,council_pass_rate:J.council_pass_rate,gate_pass_rate:J.gate_pass_rate,iterations:J.iterations,interventions:J.interventions})),z={};for(let J of b$)z[J]=n3(J,Q.map((U)=>U[J]));let X=Q.length<2,q=b$.filter((J)=>z[J].available&&z[J].improving===!0),K=b$.filter((J)=>z[J].available&&z[J].improving===!1),W=[];if(X)W.push(`not enough history yet: ${Q.length} run(s) recorded, need 2+ to show a trend`);if(!z.interventions.available)W.push("intervention trend unavailable: no per-run intervention count in proof.json yet (axis lights up automatically once recorded)");return{schema_version:v3,generated_at:new Date().toISOString(),loki_dir:$,runs_count:Q.length,insufficient:X,axes:z,improving_count:q.length,regressing_count:K.length,improving_axes:q,regressing_axes:K,series:Z,notes:W}}function b0($){return JSON.stringify($,null,2)}function h0($,Q){let Z=T$($,"metrics"),z=T$(Z,"trust-trajectory.json");try{return D3(Z,{recursive:!0}),y3(z,JSON.stringify(Q,null,2)),z}catch{return null}}function a3($){if($==="up")return"up";if($==="down")return"down";return"flat"}function s3($){let Q=$.label??$.axis;if(!$.available)return` ${(Q+":").padEnd(26)} no data`;let Z;if($.insufficient)Z="(need 2+ runs)";else if($.improving===!0)Z="improving";else if($.improving===!1)Z="regressing";else Z="stable";let z=$.higher_is_better?"higher better":"lower better",X=$.latest??"n/a";return` ${(Q+":").padEnd(26)} ${a3($.direction).padEnd(5)} latest=${String(X).padEnd(7)} ${Z.padEnd(11)} [${z}]`}function y0($){let Q=[];if(Q.push(`Loki Mode Trust Trajectory (snapshot at ${$.generated_at})`),Q.push(`Source: ${$.loki_dir}`),Q.push(`Runs analyzed: ${$.runs_count}`),Q.push(""),$.insufficient){if(Q.push("Not enough history yet."),Q.push("Trust trajectory needs 2+ recorded runs to show a direction."),Q.push("Each `loki start` run writes a proof-of-run; come back after the next run."),$.notes.length>0){Q.push(""),Q.push("Notes");for(let X of $.notes)Q.push(` - ${X}`)}return Q.join(`
|
|
444
|
+
`)}Q.push("Is the agent earning autonomy on this repo?");for(let X of b$)if($.axes[X])Q.push(s3($.axes[X]));Q.push("");let{improving_count:Z,regressing_count:z}=$;if(Z&&!z)Q.push(`Overall: trending more trustworthy (${Z} axis improving).`);else if(z&&!Z)Q.push(`Overall: trust regressing (${z} axis regressing). Review recent runs.`);else if(Z||z)Q.push(`Overall: mixed (${Z} improving / ${z} regressing).`);else Q.push("Overall: stable.");if($.notes.length>0){Q.push(""),Q.push("Notes");for(let X of $.notes)Q.push(` - ${X}`)}return Q.join(`
|
|
445
|
+
`)}var v3=1,b$,m3,g3,f3,D0;var v0=L(()=>{b$=["council_pass_rate","gate_pass_rate","iterations","interventions"],m3={council_pass_rate:!0,gate_pass_rate:!0,iterations:!1,interventions:!1},g3={council_pass_rate:0.01,gate_pass_rate:0.01,iterations:0.25,interventions:0.25},f3={council_pass_rate:"Council pass rate",gate_pass_rate:"Gate pass rate",iterations:"Iterations to completion",interventions:"Human interventions"},D0=["APPROVE","APPROVED","COMPLETE","PASS","PASSED"]});var m0={};h(m0,{runTrust:()=>t3});function t3($){let Q=!1;for(let X of $){if(X==="--help"||X==="-h"||X==="help")return process.stdout.write(r3),0;if(X==="--json"){Q=!0;continue}return process.stderr.write(`loki trust: unknown arg: ${X}
|
|
445
446
|
Run 'loki trust --help' for usage.
|
|
446
|
-
`),1}let Z=P(),z=
|
|
447
|
-
`:
|
|
448
|
-
`),0}var
|
|
447
|
+
`),1}let Z=P(),z=C0(Z);return h0(Z,z),process.stdout.write(Q?b0(z)+`
|
|
448
|
+
`:y0(z)+`
|
|
449
|
+
`),0}var r3=`loki trust -- visible trust trajectory (R4)
|
|
449
450
|
|
|
450
451
|
Usage:
|
|
451
452
|
loki trust Pretty-print the per-project trust trajectory
|
|
@@ -461,30 +462,30 @@ Shows whether the agent is earning autonomy on THIS repo over time:
|
|
|
461
462
|
Derived read-only from proof-of-run history in .loki/proofs/. With fewer
|
|
462
463
|
than 2 recorded runs it reports "not enough history yet" rather than a
|
|
463
464
|
fabricated trend. Complements 'loki kpis' (single-run snapshot).
|
|
464
|
-
`;var
|
|
465
|
-
`),
|
|
466
|
-
`),Q}catch(Z){if(Q!==null){try{
|
|
467
|
-
`)}),
|
|
465
|
+
`;var g0=L(()=>{v0();b()});import{closeSync as U1,fstatSync as i3,lstatSync as e3,mkdirSync as f0,openSync as u0,readSync as $8,renameSync as Q8,rmSync as c0,statSync as Z8,unlinkSync as p0,writeFileSync as z8,writeSync as X8}from"fs";import{dirname as l0}from"path";function O$($,Q){f0(l0($),{recursive:!0});let Z=`${$}.tmp.${process.pid}.${++K8}`;z8(Z,`${JSON.stringify(Q,null,2)}
|
|
466
|
+
`),Q8(Z,$)}async function d0($,Q){let Z=h$.get($)??Promise.resolve(),z=()=>{},X=new Promise((K)=>{z=K}),q=Z.catch(()=>{}).then(()=>X);h$.set($,q);try{return await Z.catch(()=>{}),await Q()}finally{if(z(),h$.get($)===q)h$.delete($)}}function V8($){return`${$}.lock`}function W8($){if(!Number.isFinite($)||$<=0)return!1;try{return process.kill($,0),!0}catch(Q){return Q?.code==="EPERM"}}function J8($){let Q=null;try{return f0(l0($),{recursive:!0}),Q=u0($,"wx"),X8(Q,`${process.pid}
|
|
467
|
+
`),Q}catch(Z){if(Q!==null){try{U1(Q)}catch{}try{p0($)}catch{}}if(Z?.code==="EEXIST")return null;throw Z}}function U8($,Q){let Z;try{Z=e3($)}catch{return!0}if(Z.isSymbolicLink())try{return p0($),!0}catch{return!1}let z;try{z=u0($,"r")}catch{return!0}try{let X=i3(z);if(Date.now()-X.mtimeMs<Q)return!1;let K=NaN;try{let W=Buffer.alloc(64),J=$8(z,W,0,64,0);K=Number.parseInt(W.subarray(0,J).toString("utf-8").trim(),10)}catch{}if(Number.isFinite(K)&&W8(K))return!1;try{if(Z8($).mtimeMs>X.mtimeMs)return!1}catch{return!0}try{c0($,{force:!0})}catch{}return!0}finally{try{U1(z)}catch{}}}function H1($,Q,Z={}){let z=Z.timeoutMs??1e4,X=Z.pollMs??25,q=Z.staleMs??30000,K=V8($),W=Date.now()+z,J=null,U=0,H=new Int32Array(new SharedArrayBuffer(4));while(J===null){if(J=J8(K),J!==null)break;if(Date.now()>W)throw Error(`withFileLockSync: timed out after ${z}ms acquiring ${K}`);if(U8(K,q))continue;let Y=Math.min(X*2**Math.min(U,4),q8);U+=1,Atomics.wait(H,0,0,Y)}try{return Q()}finally{try{U1(J)}catch{}try{c0(K,{force:!0})}catch{}}}var K8=0,h$,q8=50;var y$=L(()=>{h$=new Map});import{existsSync as X$,mkdirSync as B$,copyFileSync as s0,readFileSync as Y1,readdirSync as H8,statSync as B8,writeFileSync as G8,renameSync as r0,appendFileSync as t0,rmSync as Y8}from"fs";import{join as m,dirname as v$}from"path";function T8($){let Q=n0.then($,$);return n0=Q.catch((Z)=>{console.warn("[checkpoint] serialized op rejected:",Z);return}),Q}function o($){return m($,"state","checkpoints")}function i0($){return m(o($),"index.jsonl")}async function O8($){let Q=await k(["git","rev-parse","HEAD"],{cwd:$,timeoutMs:5000});if(Q.exitCode!==0)return"no-git";return Q.stdout.trim()||"no-git"}async function A8($){let Q=await k(["git","branch","--show-current"],{cwd:$,timeoutMs:5000});if(Q.exitCode!==0)return"unknown";return Q.stdout.trim()||"unknown"}async function w8($){let Q=await k(["git","diff","--quiet"],{cwd:$,timeoutMs:5000}),Z=await k(["git","diff","--cached","--quiet"],{cwd:$,timeoutMs:5000}),z=Q.exitCode===1,X=Z.exitCode===1;return z||X}function _8($){let Q=m($,"state","orchestrator.json");if(!X$(Q))return"unknown";try{let z=JSON.parse(Y1(Q,"utf-8")).currentPhase;return typeof z==="string"&&z.length>0?z:"unknown"}catch{return"unknown"}}function L8($,Q){for(let Z of I8){let z=m($,Z);if(!X$(z))continue;let X=m(Q,Z);B$(v$(X),{recursive:!0});try{s0(z,X)}catch{}}}function $6($,Q){B$(v$($),{recursive:!0});let Z=`${$}.tmp.${process.pid}.${++e0}`;G8(Z,Q),r0(Z,$)}function P8($){return JSON.stringify($,null,2)}function Q6($){return`{${[`"id": ${JSON.stringify($.id)}`,`"ts": ${JSON.stringify($.ts)}`,`"iter": ${JSON.stringify($.iter)}`,`"task": ${JSON.stringify($.task)}`,`"sha": ${JSON.stringify($.sha)}`].join(", ")}}`}async function j8($){return T8(()=>F8($))}async function F8($){let Q=$.lokiDirOverride??P(),Z=process.cwd(),z=o(Q);if(B$(z,{recursive:!0}),!$.forceCreate){if(!await w8(Z))return{created:!1,reason:"no uncommitted changes"}}let X=await O8(Z),q=await A8(Z),K=$.iteration??Number.parseInt(process.env.ITERATION_COUNT??"0",10),W=$.epochOverride??Math.floor(Date.now()/1000),J=`cp-${K}-${W}`,U=m(z,J);B$(U,{recursive:!0}),L8(Q,U);let H=new Date().toISOString().replace(/\.\d{3}Z$/,"Z"),Y=($.taskDescription??"task completed").slice(0,M8),B=$.provider??process.env.PROVIDER_NAME??"claude",G={id:J,timestamp:H,iteration:K,task_id:$.taskId??"unknown",task_description:Y,git_sha:X,git_branch:q,provider:B,phase:_8(Q)};$6(m(U,"metadata.json"),P8(G));let O={id:G.id,ts:G.timestamp,iter:G.iteration,task:G.task_description,sha:G.git_sha},M=i0(Q);return H1(M,()=>{t0(M,`${Q6(O)}
|
|
468
|
+
`)}),k8(Q),{created:!0,id:J,metadata:G,dir:U}}function M1($){let Q=o($);if(!X$(Q))return[];return H8(Q).filter((Z)=>Z.startsWith("cp-")).filter((Z)=>{try{return B8(m(Q,Z)).isDirectory()}catch{return!1}})}function T1($){return[...$].sort((Q,Z)=>{let z=a0(Q),X=a0(Z);return z-X})}function a0($){let Q=$.split("-");if(Q.length<3)return 0;let Z=Q[Q.length-1],z=Number.parseInt(Z??"0",10);return Number.isFinite(z)?z:0}function k8($){let Q=M1($);if(Q.length<=o0)return;let Z=T1(Q),z=Z.slice(0,Z.length-o0);for(let X of z)try{Y8(m(o($),X),{recursive:!0,force:!0})}catch{}R8($)}function R8($){let Q=T1(M1($)),Z=[];for(let q of Q){let K=m(o($),q,"metadata.json"),W=m(o($),q);if(!X$(K)){B1($,W,"missing_field","metadata.json");continue}try{let J=JSON.parse(Y1(K,"utf-8")),U=z6(J,K);if(!U.ok){B1($,W,U.reason,U.field);continue}let H=U.value;Z.push(Q6({id:H.id,ts:H.timestamp,iter:H.iteration,task:H.task_description??"",sha:H.git_sha}))}catch{B1($,W,"invalid_type","metadata.json")}}let z=i0($),X=Z.length>0?`${Z.join(`
|
|
468
469
|
`)}
|
|
469
|
-
`:""
|
|
470
|
-
`)})}catch{}}function
|
|
471
|
-
`),0;process.stdout.write(`${R}Checkpoints${
|
|
472
|
-
`);for(let X of z)process.stdout.write(` ${
|
|
473
|
-
`);return 0}case"show":{let z=Z[0];if(!z)return process.stderr.write(`${T}Missing checkpoint id.${
|
|
474
|
-
`),2;try{let X=
|
|
475
|
-
`),0}catch(X){return process.stderr.write(`${T}Failed to read checkpoint:${
|
|
476
|
-
`),1}}case"to":{let z=Z[0];if(!z)return process.stderr.write(`${T}Missing checkpoint id.${
|
|
477
|
-
`),2;return await
|
|
478
|
-
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${
|
|
479
|
-
`),await
|
|
480
|
-
`),process.stderr.write(
|
|
481
|
-
`),1}if(Z.restore.length===0)return process.stdout.write(`${
|
|
482
|
-
`),0;let z;try{z=await
|
|
483
|
-
`),1}if(z.errors.length>0){for(let X of z.errors)process.stderr.write(`${T}restore error:${
|
|
484
|
-
`);return process.stderr.write(`${T}Partial rollback: ${z.restored}/${Z.restore.length} files restored.${
|
|
485
|
-
`),1}if(process.stdout.write(`${S}Rolled back ${z.restored}/${Z.restore.length} state files from ${$}.${
|
|
486
|
-
`),z.preRollbackSnapshotId)process.stdout.write(`Saved your prior state as ${
|
|
487
|
-
`);return process.stdout.write("Run `loki start` to resume from the restored state.\n"),0}var
|
|
470
|
+
`:"";$6(z,X)}function B1($,Q,Z,z){let X=m($,"events.jsonl"),q={timestamp:new Date().toISOString(),type:"checkpoint.metadata.dropped",checkpoint_dir:Q,reason:Z,field:z};try{B$(v$(X),{recursive:!0}),H1(X,()=>{t0(X,`${JSON.stringify(q)}
|
|
471
|
+
`)})}catch{}}function O1($){let Q=$??P(),Z=T1(M1(Q)),z=[];for(let X of Z){let q=Z6(Q,X);if(q)z.push(q)}return z}function Z6($,Q){let Z=m(o($),Q,"metadata.json");if(!X$(Z))return null;try{let z=JSON.parse(Y1(Z,"utf-8"));return x8(z,Z)}catch{return null}}function x8($,Q){let Z=z6($,Q);return Z.ok?Z.value:null}function z6($,Q){if($===null||typeof $!=="object")return console.warn(`[checkpoint] invalid metadata at ${Q}: not an object`),{ok:!1,reason:"invalid_type",field:"<root>"};let Z=$,z=["id","timestamp","task_id","task_description","git_sha","git_branch","provider","phase"];for(let X of z){if(!(X in Z))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${X}" missing`),{ok:!1,reason:"missing_field",field:X};if(typeof Z[X]!=="string")return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${X}" not a string`),{ok:!1,reason:"invalid_type",field:X}}if(!Object.prototype.hasOwnProperty.call(Z,"iteration"))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "iteration" missing`),{ok:!1,reason:"missing_field",field:"iteration"};if(typeof Z.iteration!=="number"||!Number.isFinite(Z.iteration))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "iteration" not a finite number`),{ok:!1,reason:"invalid_type",field:"iteration"};for(let X of N8){let q=Z[X];if(E8.test(q))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${X}" contains control characters`),{ok:!1,reason:"control_chars",field:X}}return{ok:!0,value:{id:Z.id,timestamp:Z.timestamp,iteration:Z.iteration,task_id:Z.task_id,task_description:Z.task_description,git_sha:Z.git_sha,git_branch:Z.git_branch,provider:Z.provider,phase:Z.phase}}}function A1($,Q){if(!S8.test($))throw new X6($);let Z=Q??P(),z=m(o(Z),$);if(!X$(z))throw new G1($);let X=Z6(Z,$);if(!X)throw new G1($);return X}function K6($,Q){let Z=A1($,Q),z=Q??P(),X=m(o(z),$),q=[];for(let K of D8){let W=m(X,K);if(!X$(W))continue;q.push({from:W,to:m(z,K)})}return{id:$,metadata:Z,restore:q}}function C8($){let Q=[],Z=0;for(let z of $.restore)try{B$(v$(z.to),{recursive:!0});let X=`${z.to}.tmp.${process.pid}.${++e0}`;s0(z.from,X),r0(X,z.to),Z+=1}catch(X){Q.push(`${z.from} -> ${z.to}: ${X.message}`)}return{restored:Z,errors:Q}}async function q6($,Q,Z=!1){let z=null;try{let q=await j8({taskDescription:`pre-rollback snapshot (before restoring ${$.id})`,taskId:"rollback",forceCreate:!0,lokiDirOverride:Q});if(q.created)z=q.id}catch(q){let K=q instanceof Error?q.message:String(q);if(!Z)throw Error("pre-rollback snapshot failed ("+K+"); aborting rollback to preserve current state. Re-run with force to roll back anyway without a safety snapshot.");console.warn("[checkpoint] pre-rollback snapshot failed; proceeding due to force:",K)}let X=C8($);return{preRollbackSnapshotId:z,restored:X.restored,errors:X.errors}}var o0=50,M8=200,n0,I8,e0=0,E8,N8,S8,G1,X6,D8;var V6=L(()=>{b();d();y$();n0=Promise.resolve();I8=["state/orchestrator.json","autonomy-state.json","queue/pending.json","queue/completed.json","queue/in-progress.json","queue/current-task.json","CONTINUITY.md"];E8=/[\x00-\x08\x0a-\x1f\x7f-\x9f]/,N8=["id","task_id","git_sha","git_branch","provider","phase"];S8=/^[a-zA-Z0-9_-]+$/;G1=class G1 extends Error{id;constructor($){super(`Checkpoint not found: ${$}`);this.id=$;this.name="CheckpointNotFoundError"}};X6=class X6 extends Error{id;constructor($){super(`Invalid checkpoint ID: must be alphanumeric, hyphens, underscores only (got: ${$})`);this.id=$;this.name="InvalidCheckpointIdError"}};D8=["state/orchestrator.json","queue/pending.json","queue/completed.json","queue/in-progress.json","queue/current-task.json","CONTINUITY.md"]});var U6={};h(U6,{runRollback:()=>b8});async function b8($){let Q=$[0],Z=$.slice(1);if(Q===void 0||Q==="help"||Q==="--help"||Q==="-h")return process.stdout.write(W6),Q===void 0?1:0;switch(Q){case"list":{let z=[...O1()].reverse();if(z.length===0)return process.stdout.write(`${_}No checkpoints found.${V}
|
|
472
|
+
`),0;process.stdout.write(`${R}Checkpoints${V} (${z.length}, newest first):
|
|
473
|
+
`);for(let X of z)process.stdout.write(` ${I}${X.id}${V} iter=${X.iteration} ${X.git_branch||"(no branch)"}@${(X.git_sha||"").slice(0,7)} ${X.timestamp}
|
|
474
|
+
`);return 0}case"show":{let z=Z[0];if(!z)return process.stderr.write(`${T}Missing checkpoint id.${V} Use \`loki rollback list\`.
|
|
475
|
+
`),2;try{let X=A1(z);return process.stdout.write(`${JSON.stringify(X,null,2)}
|
|
476
|
+
`),0}catch(X){return process.stderr.write(`${T}Failed to read checkpoint:${V} ${X.message}
|
|
477
|
+
`),1}}case"to":{let z=Z[0];if(!z)return process.stderr.write(`${T}Missing checkpoint id.${V} Use \`loki rollback list\`.
|
|
478
|
+
`),2;return await J6(z,Z.includes("--force"))}case"latest":{let z=O1(),X=z[z.length-1];if(!X)return process.stderr.write(`${T}No checkpoints found to roll back to.${V}
|
|
479
|
+
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${I}${X.id}${V}
|
|
480
|
+
`),await J6(X.id,Z.includes("--force"))}default:return process.stderr.write(`Unknown subcommand: ${Q}
|
|
481
|
+
`),process.stderr.write(W6),2}}async function J6($,Q=!1){let Z;try{Z=K6($)}catch(X){return process.stderr.write(`${T}Cannot plan rollback:${V} ${X.message}
|
|
482
|
+
`),1}if(Z.restore.length===0)return process.stdout.write(`${_}Checkpoint ${$} has no restorable state files; nothing to do.${V}
|
|
483
|
+
`),0;let z;try{z=await q6(Z,void 0,Q)}catch(X){return process.stderr.write(`${T}Rollback aborted:${V} ${X.message}
|
|
484
|
+
`),1}if(z.errors.length>0){for(let X of z.errors)process.stderr.write(`${T}restore error:${V} ${X}
|
|
485
|
+
`);return process.stderr.write(`${T}Partial rollback: ${z.restored}/${Z.restore.length} files restored.${V}
|
|
486
|
+
`),1}if(process.stdout.write(`${S}Rolled back ${z.restored}/${Z.restore.length} state files from ${$}.${V}
|
|
487
|
+
`),z.preRollbackSnapshotId)process.stdout.write(`Saved your prior state as ${I}${z.preRollbackSnapshotId}${V}; undo this rollback with \`loki rollback to ${z.preRollbackSnapshotId}\`.
|
|
488
|
+
`);return process.stdout.write("Run `loki start` to resume from the restored state.\n"),0}var W6=`Usage: loki rollback <subcommand>
|
|
488
489
|
|
|
489
490
|
Subcommands:
|
|
490
491
|
list List checkpoints (newest first)
|
|
@@ -505,72 +506,72 @@ to the checkpoint's snapshot (if one was anchored at checkpoint time):
|
|
|
505
506
|
git stash apply refs/loki/cp/<id>
|
|
506
507
|
|
|
507
508
|
Re-run \`loki start\` to resume from the restored state.
|
|
508
|
-
`;var
|
|
509
|
-
`),0;let Q=[];try{Q=
|
|
510
|
-
`),0;process.stdout.write(`${
|
|
509
|
+
`;var H6=L(()=>{V6();c()});function h8(){return process.env.LOKI_TIER||"oss"}function B6($){let Q=h8();if(Q==="oss")return{allowed:!0,notes:[]};if(!process.env.LOKI_LICENSE_KEY)return{allowed:!1,notes:[`${_}LOKI_TIER='${Q}' requested but no LOKI_LICENSE_KEY set.${V}`,`Hosted/enterprise license verification is not available yet (capability: ${$}).`,"OSS users: leave LOKI_TIER unset (or 'oss') -- everything stays free."]};return{allowed:!0,notes:[`${_}LOKI_LICENSE_KEY set but the verification backend is not available yet (R9 seam).${V}`]}}var G6=L(()=>{c()});var M6={};h(M6,{runProof:()=>r8});import{existsSync as A$,readdirSync as y8,readFileSync as Y6,mkdtempSync as v8,copyFileSync as m8,rmSync as g8}from"fs";import{join as i}from"path";import{tmpdir as f8}from"os";import{createInterface as u8}from"readline";import{readFile as c8}from"fs/promises";function e($){return $&&typeof $==="object"?$:{}}function p($){return $===void 0||$===null?"-":String($)}function w$(){return i(P(),"proofs")}function w1($){let Q=i(w$(),$,"proof.json");if(!A$(Q))return null;try{return JSON.parse(Y6(Q,"utf8"))}catch{return{}}}function t($,Q){return $.length>=Q?$:$+" ".repeat(Q-$.length)}function l8(){let $=w$();if(!A$($))return process.stdout.write(`${_}No proofs found.${V} Run 'loki start' to generate one.
|
|
510
|
+
`),0;let Q=[];try{Q=y8($,{withFileTypes:!0}).filter((z)=>z.isDirectory()).map((z)=>z.name).sort()}catch{Q=[]}let Z=[];for(let z of Q){let X=i($,z,"proof.json");if(!A$(X))continue;let q={};try{q=JSON.parse(Y6(X,"utf8"))}catch{q={}}let K=p(q.run_id),W=p(q.generated_at),J=p(e(q.council).final_verdict),U=p(e(q.cost).usd),H=p(e(q.files_changed).count);Z.push(`${t(K,26)} ${t(W,20)} ${t(J,10)} ${t(U,9)} ${H}`)}if(Z.length===0)return process.stdout.write(`${_}No proofs found.${V} Run 'loki start' to generate one.
|
|
511
|
+
`),0;process.stdout.write(`${t("RUN_ID",26)} ${t("GENERATED_AT",20)} ${t("VERDICT",10)} ${t("COST_USD",9)} FILES
|
|
511
512
|
`);for(let z of Z)process.stdout.write(`${z}
|
|
512
|
-
`);return 0}function
|
|
513
|
-
`),2;let Q=
|
|
513
|
+
`);return 0}function d8($){if(!$)return process.stderr.write(`${T}Missing proof id.${V} Use 'loki proof list'.
|
|
514
|
+
`),2;let Q=w1($);if(Q===null)return process.stderr.write(`${T}Proof not found: ${$}${V}
|
|
514
515
|
`),process.stderr.write(`Use 'loki proof list' to see available proofs.
|
|
515
516
|
`),1;return process.stdout.write(`${JSON.stringify(Q,null,2)}
|
|
516
|
-
`),0}async function
|
|
517
|
-
`),2;let Q=i(w$(),$,"index.html");if(!A$(Q))return process.stderr.write(`${T}Proof page not found: ${$}/index.html${
|
|
517
|
+
`),0}async function o8($){if(!$)return process.stderr.write(`${T}Missing proof id.${V} Use 'loki proof list'.
|
|
518
|
+
`),2;let Q=i(w$(),$,"index.html");if(!A$(Q))return process.stderr.write(`${T}Proof page not found: ${$}/index.html${V}
|
|
518
519
|
`),process.stderr.write(`Use 'loki proof list' to see available proofs.
|
|
519
|
-
`),1;process.stdout.write(`${S}Opening proof: ${Q}${
|
|
520
|
-
`);for(let Z of["open","xdg-open","start"])try{if((await
|
|
520
|
+
`),1;process.stdout.write(`${S}Opening proof: ${Q}${V}
|
|
521
|
+
`);for(let Z of["open","xdg-open","start"])try{if((await k([Z,Q],{timeoutMs:5000})).exitCode===0)return 0}catch{}return process.stdout.write(`
|
|
521
522
|
Could not detect browser opener.
|
|
522
523
|
`),process.stdout.write(`Please open in browser: ${Q}
|
|
523
|
-
`),0}function
|
|
524
|
-
`);let X=process.env.LOKI_HOSTED_ENDPOINT||"";if(!X)return process.stderr.write(`${
|
|
524
|
+
`),0}function n8($){return new Promise((Q)=>{let Z=u8({input:process.stdin,output:process.stdout});Z.question($,(z)=>{Z.close();let X=z.trim().toLowerCase();Q(X==="y"||X==="yes")})})}async function a8($,Q,Z){let z=B6("hosted_publish");for(let B of z.notes)process.stderr.write(`${B}
|
|
525
|
+
`);let X=process.env.LOKI_HOSTED_ENDPOINT||"";if(!X)return process.stderr.write(`${_}Hosted publishing backend not available.${V}
|
|
525
526
|
`),process.stderr.write(`There is no official Loki hosted service yet (R9 ships the seam, not a live backend).
|
|
526
527
|
`),process.stderr.write(`To publish to your own hosted endpoint, set LOKI_HOSTED_ENDPOINT to its URL.
|
|
527
528
|
`),process.stderr.write(`Or publish to a GitHub Gist instead: loki proof share ${$}
|
|
528
|
-
`),1;let
|
|
529
|
+
`),1;let q=w1($);if(q){if(e(q.redaction).applied!==!0)return process.stderr.write(`${T}Refusing to publish: proof redaction was not confirmed applied.${V}
|
|
529
530
|
`),process.stderr.write(`Regenerate the proof (LOKI_PROOF=1) so the redactor runs, then retry.
|
|
530
|
-
`),1}process.stdout.write(`${R}Publishing proof '${$}' to hosted endpoint${
|
|
531
|
+
`),1}process.stdout.write(`${R}Publishing proof '${$}' to hosted endpoint${V}
|
|
531
532
|
`),process.stdout.write(` endpoint: ${X}
|
|
532
533
|
`),process.stdout.write(` payload: ${Q} (already redacted by the generator)
|
|
533
534
|
|
|
534
|
-
`);let K;try{K=await
|
|
535
|
-
`),1}let
|
|
535
|
+
`);let K;try{K=await c8(Q)}catch{return process.stderr.write(`${T}Could not read proof page: ${Q}${V}
|
|
536
|
+
`),1}let W={"Content-Type":"text/html","X-Loki-Proof-Id":$},J=process.env.LOKI_LICENSE_KEY||"";if(J)W.Authorization=`Bearer ${J}`;let U;try{U=await fetch(X,{method:"POST",headers:W,body:new Uint8Array(K)})}catch(B){return process.stderr.write(`${T}Failed to reach hosted endpoint: ${String(B.message||B)}${V}
|
|
536
537
|
`),process.stderr.write(`Check LOKI_HOSTED_ENDPOINT or publish to a gist: loki proof share ${$}
|
|
537
|
-
`),1}let
|
|
538
|
-
`),
|
|
539
|
-
`),process.stderr.write(`${
|
|
538
|
+
`),1}let H=await U.text();if(!U.ok){if(process.stderr.write(`${T}Hosted endpoint returned HTTP ${U.status}.${V}
|
|
539
|
+
`),H)process.stderr.write(`Response:
|
|
540
|
+
`),process.stderr.write(`${H.slice(0,500)}
|
|
540
541
|
`);return process.stderr.write(`Nothing was published. Or publish to a gist: loki proof share ${$}
|
|
541
|
-
`),1}let Y="";try{let
|
|
542
|
-
`);else process.stdout.write(`${S}Published to ${X} (HTTP ${
|
|
542
|
+
`),1}let Y="";try{let B=JSON.parse(H);if(B&&typeof B==="object"){let G=B.url??B.public_url;if(typeof G==="string")Y=G}}catch{}if(Y)process.stdout.write(`${S}Published: ${Y}${V}
|
|
543
|
+
`);else process.stdout.write(`${S}Published to ${X} (HTTP ${U.status}).${V}
|
|
543
544
|
`),process.stdout.write(`The endpoint did not return a 'url' field; check your endpoint's response.
|
|
544
|
-
`);return 0}async function
|
|
545
|
-
`),1;else Q=M;if(!Q)return process.stderr.write(`${T}Missing proof id.${
|
|
546
|
-
`),2;let
|
|
545
|
+
`);return 0}async function s8($){let Q="",Z=!1,z="--public",X=!1;for(let M of $)if(M==="--yes"||M==="-y")Z=!0;else if(M==="--private")z="";else if(M==="--public")z="--public";else if(M==="--hosted")X=!0;else if(M.startsWith("-"))return process.stderr.write(`${T}Unknown option: ${M}${V}
|
|
546
|
+
`),1;else Q=M;if(!Q)return process.stderr.write(`${T}Missing proof id.${V} Use 'loki proof list'.
|
|
547
|
+
`),2;let q=i(w$(),Q,"index.html");if(!A$(q))return process.stderr.write(`${T}Proof page not found: ${Q}/index.html${V}
|
|
547
548
|
`),process.stderr.write(`Use 'loki proof list' to see available proofs.
|
|
548
|
-
`),1;if(X)return
|
|
549
|
+
`),1;if(X)return a8(Q,q,i(w$(),Q,"proof.json"));if((await k(["gh","--version"],{timeoutMs:5000})).exitCode!==0)return process.stderr.write(`${T}gh CLI not found${V}
|
|
549
550
|
`),process.stderr.write(`Install the GitHub CLI to publish a proof:
|
|
550
551
|
`),process.stderr.write(` brew install gh # macOS
|
|
551
552
|
`),process.stderr.write(` sudo apt install gh # Ubuntu/Debian
|
|
552
553
|
`),process.stderr.write(` https://cli.github.com # Other platforms
|
|
553
|
-
`),1;if((await
|
|
554
|
+
`),1;if((await k(["gh","auth","status"],{timeoutMs:1e4})).exitCode!==0)return process.stderr.write(`${T}GitHub CLI not authenticated${V}
|
|
554
555
|
`),process.stderr.write(`Run 'gh auth login' to authenticate, then try again.
|
|
555
|
-
`),1;let
|
|
556
|
+
`),1;let J=z===""?"secret":"public";process.stdout.write(`${R}Publishing proof '${Q}' as a ${J} GitHub Gist${V}
|
|
556
557
|
|
|
557
558
|
`),process.stdout.write(`What will be shared:
|
|
558
|
-
`),process.stdout.write(` - ${
|
|
559
|
-
`);let
|
|
560
|
-
`),process.stdout.write(` - files_changed: ${
|
|
561
|
-
`),process.stdout.write(` - council verdict: ${
|
|
562
|
-
`),process.stdout.write(` - redaction: applied=${p(
|
|
559
|
+
`),process.stdout.write(` - ${q}
|
|
560
|
+
`);let U=w1(Q);if(U){let M=p(e(U.cost).usd),F=p(e(U.files_changed).count),x=p(e(U.council).final_verdict),D=e(U.redaction);process.stdout.write(` - cost.usd: ${M}
|
|
561
|
+
`),process.stdout.write(` - files_changed: ${F}
|
|
562
|
+
`),process.stdout.write(` - council verdict: ${x}
|
|
563
|
+
`),process.stdout.write(` - redaction: applied=${p(D.applied)} rules_version=${p(D.rules_version)} redactions_count=${p(D.redactions_count)}
|
|
563
564
|
`)}if(process.stdout.write(`
|
|
564
|
-
${
|
|
565
|
+
${_}Secrets, API keys, tokens, env values, and absolute paths have already been stripped by the generator.${V}
|
|
565
566
|
|
|
566
|
-
`),!Z){if(!await
|
|
567
|
-
`),0}let
|
|
568
|
-
`);let
|
|
567
|
+
`),!Z){if(!await n8(`Publish this proof to a ${J} gist? [y/N] `))return process.stdout.write(`Aborted. Nothing was published.
|
|
568
|
+
`),0}let H=v8(i(f8(),"loki-proof-")),Y=i(H,"index.html");m8(q,Y),process.stdout.write(`Uploading proof page...
|
|
569
|
+
`);let B=`Loki Mode proof-of-run ${Q}`,G=["gh","gist","create",Y,"--desc",B];if(z!=="")G.push(z);let O=await k(G,{timeoutMs:60000});try{g8(H,{recursive:!0,force:!0})}catch{}if(O.exitCode!==0)return process.stderr.write(`${T}Failed to create gist${V}
|
|
569
570
|
`),process.stderr.write(`${O.stdout}${O.stderr}
|
|
570
|
-
`),1;return process.stdout.write(`${S}Shared: ${O.stdout.trim()}${
|
|
571
|
-
`),0}async function
|
|
571
|
+
`),1;return process.stdout.write(`${S}Shared: ${O.stdout.trim()}${V}
|
|
572
|
+
`),0}async function r8($){let Q=$[0],Z=$.slice(1);if(Q===void 0||Q==="help"||Q==="--help"||Q==="-h")return process.stdout.write(p8),Q===void 0?1:0;switch(Q){case"list":return l8();case"show":return d8(Z[0]);case"open":return o8(Z[0]);case"share":return s8(Z);default:return process.stderr.write(`${T}Unknown subcommand: ${Q}${V}
|
|
572
573
|
`),process.stderr.write(`Run 'loki proof --help' for usage.
|
|
573
|
-
`),1}}var
|
|
574
|
+
`),1}}var p8;var T6=L(()=>{b();d();c();G6();p8=`${R}loki proof${V} - inspect and share proof-of-run artifacts
|
|
574
575
|
|
|
575
576
|
Usage: loki proof <subcommand> [args]
|
|
576
577
|
|
|
@@ -586,31 +587,31 @@ Options for 'share':
|
|
|
586
587
|
--hosted Publish to LOKI_HOSTED_ENDPOINT (open-core seam; no official backend yet)
|
|
587
588
|
|
|
588
589
|
Proofs are generated automatically at run completion (LOKI_PROOF=0 to opt out).
|
|
589
|
-
`});var
|
|
590
|
-
`),0;process.stdout.write(`${
|
|
591
|
-
`);for(let Q of $){let Z=
|
|
590
|
+
`});var L6={};h(L6,{runCrash:()=>K7});import{existsSync as A6,readdirSync as t8,readFileSync as i8}from"fs";import{join as w6}from"path";function _$($){return $===void 0||$===null?"-":String($)}function m$($,Q){return $.length>=Q?$:$+" ".repeat(Q-$.length)}function _6(){return w6(P(),"crash")}function _1(){let $=_6();if(!A6($))return[];try{return t8($,{withFileTypes:!0}).filter((Q)=>Q.isFile()&&Q.name.endsWith(".json")).map((Q)=>Q.name.slice(0,-5)).sort()}catch{return[]}}function $7($){if($.length===0)return!1;if($.includes("/")||$.includes("\\"))return!1;if($.includes(".."))return!1;return!0}function g$($){if(!$7($))return null;let Q=w6(_6(),`${$}.json`);if(!A6(Q))return null;try{return JSON.parse(i8(Q,"utf8"))}catch{return{}}}function Q7(){let $=_1();if($.length===0)return process.stdout.write(`${_}No crash reports found.${V} Nothing has been captured in .loki/crash/.
|
|
591
|
+
`),0;process.stdout.write(`${m$("ID",40)} ${m$("CAPTURED_AT",22)} ERROR_CLASS
|
|
592
|
+
`);for(let Q of $){let Z=g$(Q)??{},z=_$(Z.fingerprint),X=_$(Z.captured_at),q=_$(Z.error_class),K=z!=="-"?z:Q;process.stdout.write(`${m$(K,40)} ${m$(X,22)} ${q}
|
|
592
593
|
`)}return process.stdout.write(`
|
|
593
594
|
${$.length} report(s). Run 'loki crash show <id>' to inspect, 'loki crash submit' to get a prefilled GitHub issue URL.
|
|
594
|
-
`),0}function
|
|
595
|
-
`),2;let Q=
|
|
595
|
+
`),0}function I6($){let Q=g$($);if(Q!==null)return{id:$,report:Q};for(let Z of _1()){let z=g$(Z);if(z&&String(z.fingerprint??"")===$)return{id:Z,report:z}}return null}function Z7($){if(!$)return process.stderr.write(`${T}Missing crash id.${V} Use 'loki crash' to list reports.
|
|
596
|
+
`),2;let Q=I6($);if(Q===null)return process.stderr.write(`${T}Crash report not found: ${$}${V}
|
|
596
597
|
`),process.stderr.write(`Use 'loki crash' to see available reports.
|
|
597
598
|
`),1;return process.stdout.write(`${JSON.stringify(Q.report,null,2)}
|
|
598
|
-
`),0}function
|
|
599
|
-
`),
|
|
599
|
+
`),0}function z7($){let Q=_$($.error_class),Z=_$($.fingerprint),z=Z!=="-"?Z.slice(0,12):"unknown",X=`crash: ${Q} (${z})`,K=["Anonymous crash report captured by Loki Mode (scrubbed, whitelist-only).","","Scrubbed payload:","```json",JSON.stringify($,null,2),"```","","Nothing was sent automatically. This issue is submitted manually by me."].join(`
|
|
600
|
+
`),W=new URLSearchParams({title:X,body:K});return`${e8}?${W.toString()}`}function X7($){let Q;if($){if(Q=I6($),Q===null)return process.stderr.write(`${T}Crash report not found: ${$}${V}
|
|
600
601
|
`),process.stderr.write(`Use 'loki crash' to see available reports.
|
|
601
|
-
`),1}else{let Z=
|
|
602
|
-
`),0;let z=Z[Z.length-1],X=
|
|
602
|
+
`),1}else{let Z=_1();if(Z.length===0)return process.stdout.write(`${_}No crash reports found.${V} Nothing to submit.
|
|
603
|
+
`),0;let z=Z[Z.length-1],X=g$(z)??{};Q={id:z,report:X}}return process.stdout.write(`${R}Scrubbed payload (this is the ENTIRE report):${V}
|
|
603
604
|
`),process.stdout.write(`${JSON.stringify(Q.report,null,2)}
|
|
604
605
|
|
|
605
|
-
`),process.stdout.write(`${
|
|
606
|
+
`),process.stdout.write(`${_}Nothing is sent automatically in this version.${V} Loki Mode never transmits crash data on its own.
|
|
606
607
|
`),process.stdout.write(`To submit manually, open this prefilled GitHub issue and review it first:
|
|
607
608
|
|
|
608
|
-
`),process.stdout.write(` ${
|
|
609
|
+
`),process.stdout.write(` ${I}${z7(Q.report)}${V}
|
|
609
610
|
|
|
610
|
-
`),process.stdout.write(`${S}The payload above is exactly what the URL contains.${
|
|
611
|
+
`),process.stdout.write(`${S}The payload above is exactly what the URL contains.${V}
|
|
611
612
|
`),process.stdout.write(`See docs/PRIVACY.md for what is and is not collected.
|
|
612
|
-
`),0}async function
|
|
613
|
-
`),process.stdout.write(
|
|
613
|
+
`),0}async function K7($){let Q=$[0];switch(Q){case void 0:case"list":return Q7();case"--help":case"-h":case"help":return process.stdout.write(O6),0;case"show":return Z7($[1]);case"submit":return X7($[1]);default:return process.stderr.write(`${T}Unknown crash subcommand: ${Q}${V}
|
|
614
|
+
`),process.stdout.write(O6),2}}var e8="https://github.com/asklokesh/loki-mode/issues/new",O6;var P6=L(()=>{b();c();O6=`${R}loki crash${V} - inspect and manually submit local crash reports
|
|
614
615
|
|
|
615
616
|
Usage: loki crash [subcommand] [args]
|
|
616
617
|
|
|
@@ -622,15 +623,15 @@ Subcommands:
|
|
|
622
623
|
|
|
623
624
|
Crash reports are anonymous, scrubbed, and stored locally only. Nothing is
|
|
624
625
|
sent automatically in this version. See docs/PRIVACY.md.
|
|
625
|
-
`});var
|
|
626
|
+
`});var R6={};h(R6,{runWiki:()=>U7});import{existsSync as I1,readFileSync as j6}from"fs";import{join as L1,resolve as q7}from"path";function W7(){return L1(process.cwd(),".loki","wiki")}function J7($){let Q="";for(let X of $){if(X==="--help"||X==="-h")return process.stdout.write(`Usage: loki wiki show [section]
|
|
626
627
|
Sections: architecture, modules, data-flow
|
|
627
|
-
`),0;if(X.startsWith("-"))return process.stderr.write(`${T}Unknown option: ${X}${
|
|
628
|
-
`),1;Q=X}let Z=
|
|
629
|
-
`),1;if(Q){if(!
|
|
630
|
-
`),1;let X=
|
|
631
|
-
`),1;return process.stdout.write(
|
|
632
|
-
`),1;return process.stdout.write(
|
|
633
|
-
`),process.stdout.write(
|
|
628
|
+
`),0;if(X.startsWith("-"))return process.stderr.write(`${T}Unknown option: ${X}${V}
|
|
629
|
+
`),1;Q=X}let Z=W7();if(!I1(Z))return process.stderr.write(`${_}No wiki found. Run 'loki wiki generate' first.${V}
|
|
630
|
+
`),1;if(Q){if(!V7.has(Q))return process.stderr.write(`${T}No such section: ${Q} (try: architecture, modules, data-flow)${V}
|
|
631
|
+
`),1;let X=L1(Z,`${Q}.md`);if(!I1(X))return process.stderr.write(`${T}Section not generated: ${Q}${V}
|
|
632
|
+
`),1;return process.stdout.write(j6(X,"utf8")),0}let z=L1(Z,"index.md");if(!I1(z))return process.stderr.write(`${T}Wiki index not found. Run 'loki wiki generate'.${V}
|
|
633
|
+
`),1;return process.stdout.write(j6(z,"utf8")),0}async function k6($,Q){let Z=q7(g,"autonomy","loki"),z=3600000,X=Bun.spawn({cmd:[Z,"wiki",$,...Q],stdin:"inherit",stdout:"inherit",stderr:"inherit",env:{...process.env,LOKI_LEGACY_BASH:"1"}}),q=setTimeout(()=>{try{X.kill("SIGKILL")}catch{}},3600000);try{return await X.exited}finally{clearTimeout(q)}}async function U7($){let Q=$[0],Z=$.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(F6),0;case"show":return J7(Z);case"generate":return k6("generate",Z);case"ask":return k6("ask",Z);default:return process.stderr.write(`${T}Unknown wiki command: ${Q}${V}
|
|
634
|
+
`),process.stdout.write(F6),1}}var F6,V7;var x6=L(()=>{b();c();F6=`${R}loki wiki${V} - Auto-generated, cited codebase wiki + Q&A
|
|
634
635
|
|
|
635
636
|
Usage: loki wiki <command> [options]
|
|
636
637
|
|
|
@@ -646,8 +647,8 @@ Examples:
|
|
|
646
647
|
loki wiki generate
|
|
647
648
|
loki wiki show architecture
|
|
648
649
|
loki wiki ask "how does the cli dispatch commands"
|
|
649
|
-
`,
|
|
650
|
-
`)}function
|
|
650
|
+
`,V7=new Set(["architecture","modules","data-flow"])});var j1={};h(j1,{renderFindingsForPrompt:()=>M7,loadPreviousFindings:()=>P1,findLatestReviewDir:()=>C6,_parseReviewerOutputForTests:()=>T7});import{existsSync as N6,readFileSync as E6,readdirSync as S6,statSync as H7}from"fs";import{join as f$}from"path";function Y7($){let Q=$.toLowerCase();if(Q==="critical")return"Critical";if(Q==="high")return"High";if(Q==="medium")return"Medium";return"Low"}function D6($,Q,Z,z){let X=[],q=$.split(/\r?\n/);for(let K of q){let W=K.trim();if(W.length===0)continue;let J=W.replace(/^[-*]\s*/,""),U=B7.exec(J);if(!U||!U[1]||!U[2])continue;let H=Y7(U[1]),Y=U[2].trim(),B=G7.exec(Y),G=B&&B[1]?B[1]:null,O=B&&B[2]?Number.parseInt(B[2],10):null;X.push({reviewId:Z,iteration:z,reviewer:Q,severity:H,description:Y,file:G,line:Number.isFinite(O)?O:null,raw:W})}return X}function C6($,Q){let Z=f$($,"quality","reviews");if(!N6(Z))return null;let z;try{z=S6(Z)}catch{return null}let X=Q===void 0?z.filter((W)=>W.startsWith("review-")):z.filter((W)=>W.endsWith(`-${Q}`)&&W.startsWith("review-"));if(X.length===0)return null;X.sort();let q=X[X.length-1];if(!q)return null;let K=f$(Z,q);try{if(!H7(K).isDirectory())return null}catch{return null}return K}function P1($,Q){let Z=C6($,Q);if(Z===null)return{reviewDir:null,reviewId:null,iteration:null,findings:[]};let z=null,X=null,q=f$(Z,"aggregate.json");if(N6(q))try{let U=E6(q,"utf-8"),H=JSON.parse(U);if(typeof H.review_id==="string")z=H.review_id;if(typeof H.iteration==="number")X=H.iteration}catch{}let K;try{K=S6(Z)}catch{return{reviewDir:Z,reviewId:z,iteration:X,findings:[]}}let W=new Set(["diff.txt","files.txt","anti-sycophancy.txt"]),J=[];for(let U of K){if(!U.endsWith(".txt"))continue;if(W.has(U))continue;if(U.endsWith("-prompt.txt"))continue;let H=U.replace(/\.txt$/,""),Y;try{Y=E6(f$(Z,U),"utf-8")}catch{continue}J.push(...D6(Y,H,z??"",X??-1))}return{reviewDir:Z,reviewId:z,iteration:X,findings:J}}function M7($){if($.length===0)return"";let Q=["Critical","High","Medium","Low"],Z=new Map;for(let X of Q)Z.set(X,[]);for(let X of $){let q=Z.get(X.severity);if(q)q.push(X)}let z=[];z.push("PREVIOUS REVIEWER FINDINGS (must address each, or supply counter-evidence in .loki/state/counter-evidence-<iter>.json):");for(let X of Q){let q=Z.get(X)??[];if(q.length===0)continue;z.push(` [${X}] (${q.length}):`);for(let K of q){let W=K.file?` (${K.file}${K.line!==null?":"+K.line:""})`:"";z.push(` - ${K.description}${W} -- via ${K.reviewer}`)}}return z.join(`
|
|
651
|
+
`)}function T7($,Q,Z="review-test",z=0){return D6($,Q,Z,z)}var B7,G7;var u$=L(()=>{B7=/\[(Critical|High|Medium|Low)\]\s*(.+)/i,G7=/([\w.\-/]+\.[a-zA-Z]+):(\d+)/});import{existsSync as O7}from"fs";import{join as A7}from"path";async function b6($,Q){let Z=A7($,"memory");if(!O7(Z))return{stored:!1,reason:"memory dir not initialized"};let z=Math.max(0,Math.floor(Q.durationSeconds??0)),X={_LOKI_PROJECT_DIR:g,_LOKI_TARGET_DIR:process.cwd(),_LOKI_TASK_ID:Q.taskId,_LOKI_OUTCOME:Q.outcome,_LOKI_PHASE:Q.phase,_LOKI_GOAL:Q.goal,_LOKI_DURATION:String(z),_LOKI_LOKI_DIR:$},K=await Z$(`
|
|
651
652
|
import os, sys
|
|
652
653
|
project = os.environ.get('_LOKI_PROJECT_DIR', '')
|
|
653
654
|
loki = os.environ.get('_LOKI_LOKI_DIR', '.loki')
|
|
@@ -674,23 +675,23 @@ try:
|
|
|
674
675
|
print('OK')
|
|
675
676
|
except Exception as e:
|
|
676
677
|
print('ERR:' + str(e))
|
|
677
|
-
`,{env:X,timeoutMs:15000});if(K.exitCode===127)return{stored:!1,reason:"python3 not found"};let
|
|
678
|
-
`)}async function
|
|
679
|
-
`)}function
|
|
680
|
-
`),process.stderr.write(
|
|
681
|
-
`),2;let Z=P();try{let X=(await Promise.resolve().then(() => (
|
|
682
|
-
`),0;let
|
|
678
|
+
`,{env:X,timeoutMs:15000});if(K.exitCode===127)return{stored:!1,reason:"python3 not found"};let W=K.stdout.trim();if(W==="OK")return{stored:!0,reason:"stored"};if(W.startsWith("ERR:"))return{stored:!1,reason:W.replace(/^ERR:/,"")};return{stored:!1,reason:K.stderr.trim()||"unknown"}}var h6=L(()=>{q$();b()});var g6={};h(g6,{loadLearnings:()=>F1,appendLearning:()=>I$,appendFromGateFailure:()=>k7});import{existsSync as w7,readFileSync as _7}from"fs";import{join as y6}from"path";import{createHash as I7}from"crypto";function v6($){return y6($,L7)}function P7($){if($===null||typeof $!=="object")return!1;let Q=$;return typeof Q.id==="string"&&typeof Q.timestamp==="string"&&typeof Q.iteration==="number"&&typeof Q.trigger==="string"&&typeof Q.rootCause==="string"&&typeof Q.fix==="string"&&typeof Q.preventInFuture==="string"&&typeof Q.evidence==="object"&&Q.evidence!==null}function m6($){if(!w7($))return{version:1,learnings:[]};try{let Q=_7($,"utf-8"),Z=JSON.parse(Q);if(Z.version===1&&Array.isArray(Z.learnings))return{version:1,learnings:Z.learnings.filter(P7)}}catch{}return{version:1,learnings:[]}}function j7($,Q){return I7("sha256").update(`${$}\x00${Q}`).digest("hex").slice(0,16)}async function I$($,Q,Z={}){let z=j7(Q.trigger,Q.rootCause),X=new Date().toISOString(),q={id:z,timestamp:X,...Q},K=v6($);if(await d0(K,()=>{let J=m6(K),U=J.learnings.findIndex((H)=>H.id===z);if(U>=0){let H=J.learnings[U];J.learnings[U]={...H,timestamp:X,iteration:q.iteration}}else J.learnings.push(q);O$(K,J)}),Z.episodeBridge!==null&&(Z.episodeBridge!==void 0||process.env.LOKI_AUTO_LEARNINGS_EPISODE==="1")){let J=Z.episodeBridge??b6,U=Z.bridgeFailureLog??F7;try{let H=await J($,{taskId:`learning-${z}`,outcome:"failure",phase:"VERIFY",goal:`${Q.trigger}: ${Q.rootCause}`});if(H&&!H.stored){if(!new Set(["memory dir not initialized","stub"]).has(H.reason))U(`episode_bridge skipped: ${H.reason}`)}}catch(H){U(`episode_bridge threw: ${H.message}`)}}return q}function F7($){process.stderr.write(`[learnings_writer] ${$}
|
|
679
|
+
`)}async function k7($,Q,Z,z={}){let X=`[${Z.severity}] ${Z.description}`;return I$($,{iteration:Q,trigger:"gate_failure",rootCause:X,fix:"pending: dev agent must address in next iteration or supply counter-evidence",preventInFuture:"if this finding recurs, lower its severity threshold or add a regression test",evidence:{reviewId:Z.reviewId,file:Z.file??void 0,line:Z.line??void 0,severity:Z.severity,reviewer:Z.reviewer}},z)}function F1($){return m6(v6($))}var L7;var c$=L(()=>{y$();h6();L7=y6("state","relevant-learnings.json")});var u6={};h(u6,{runOverrideCouncil:()=>D7,recordOverrideOutcome:()=>C7,loadCounterEvidence:()=>S7,canonicalFindingId:()=>k1,DEFAULT_OVERRIDE_JUDGES:()=>f6});import{existsSync as R7,readFileSync as x7}from"fs";import{join as E7}from"path";function S7($,Q){let Z=E7($,"state",`counter-evidence-${Q}.json`);if(!R7(Z))return null;try{let z=x7(Z,"utf-8"),X=JSON.parse(z);if(typeof X.iteration!=="number")return null;let q=Array.isArray(X.evidence)?X.evidence:[],K=[];for(let W of q){if(typeof W!=="object"||W===null)continue;let J=W;if(typeof J.findingId!=="string")continue;if(typeof J.claim!=="string")continue;let U=J.proofType;if(typeof U!=="string"||!N7.has(U))continue;let H=U,Y=Array.isArray(J.artifacts)?J.artifacts:[];K.push({findingId:J.findingId,claim:J.claim,proofType:H,artifacts:Y.filter((B)=>typeof B==="string")})}return{iteration:X.iteration,evidence:K}}catch{return null}}async function D7($,Q,Z,z={}){let X=z.judges??f6,q=new Set,K=new Set,W={},J=new Map;for(let U of Q.evidence)J.set(U.findingId,U);for(let U of $){let H=k1(U),Y=J.get(H);if(!Y){K.add(H);continue}let B=await Promise.all(X.map((O)=>Z({finding:U,evidence:Y,judge:O})));if(W[H]=B,B.filter((O)=>O.verdict==="APPROVE_OVERRIDE").length>=2)q.add(H);else K.add(H)}return{approvedFindingIds:q,rejectedFindingIds:K,votes:W}}function k1($){let Q=$.raw.slice(0,80).replace(/\s+/g," ").trim();return`${$.reviewer}::${Q}`}async function C7($,Q,Z,z,X={}){let q={episodeBridge:X.episodeBridge===void 0?null:X.episodeBridge};for(let K of z){let W=k1(K);if(Z.approvedFindingIds.has(W))await I$($,{iteration:Q,trigger:"override_approved",rootCause:`[${K.severity}] ${K.description}`,fix:"override council approved counter-evidence; finding lifted",preventInFuture:"if this reviewer/file pair recurs, narrow the reviewer's selector OR add a baseline doc",evidence:{findingId:W,reviewId:K.reviewId,file:K.file??void 0,line:K.line??void 0,severity:K.severity,reviewer:K.reviewer}},q);else if(Z.rejectedFindingIds.has(W))await I$($,{iteration:Q,trigger:"override_rejected",rootCause:`[${K.severity}] ${K.description}`,fix:"override council rejected -- dev agent must fix the finding",preventInFuture:"address this finding in the next iteration",evidence:{findingId:W,reviewId:K.reviewId,file:K.file??void 0,line:K.line??void 0,severity:K.severity,reviewer:K.reviewer}},q)}}var N7,f6;var c6=L(()=>{c$();N7=new Set(["file-exists","test-passes","grep-miss","reviewer-misread","duplicate-code-path","out-of-scope"]);f6=["judge-primary","judge-secondary","judge-tertiary"]});var d6={};h(d6,{writeEscalationHandoff:()=>d7,renderHandoff:()=>p6,readLatestHandoff:()=>o7});import{existsSync as b7,mkdirSync as h7,readdirSync as y7,readFileSync as v7,renameSync as m7,writeFileSync as g7}from"fs";import{dirname as f7,join as p$}from"path";function u7(){return new Date().toISOString()}function c7($){let Q=$.file?` (${$.file}${$.line!==null?":"+$.line:""})`:"";return` - [${$.severity}] ${$.description}${Q} -- ${$.reviewer}`}function p7($){let Q=$.evidence,Z=Q.file?` ${Q.file}${Q.line!==void 0?":"+Q.line:""}`:"";return` - **${$.trigger}** (iter ${$.iteration})${Z}: ${$.rootCause}`}function p6($,Q,Z){let z=[];if(z.push(`# Loki escalation handoff -- ${u7()}`),z.push(""),z.push(`Gate **${$.gateName}** has failed ${$.consecutiveFailures} consecutive times at iteration ${$.iteration}.`),z.push(""),z.push(`Reason: ${$.detail}`),z.push(""),Q.length>0){z.push(`## Outstanding findings (${Q.length})`),z.push("");for(let X of Q)z.push(c7(X));z.push("")}else z.push("## Outstanding findings"),z.push(""),z.push("(no per-finding records captured -- gate failed without populating reviewer outputs)"),z.push("");if(Z.length>0){z.push(`## Recent learnings (${Math.min(Z.length,10)})`),z.push("");for(let X of Z.slice(-10))z.push(p7(X));z.push("")}return z.push("## What the human must decide"),z.push(""),z.push("- Approve override? Write `.loki/state/counter-evidence-<iter>.json` with one entry per finding to dispute, then `rm .loki/PAUSE` to resume."),z.push("- Disable a gate? Set `LOKI_GATE_<NAME>=false` in env (see skills/quality-gates.md)."),z.push("- Tweak escalation? Set `LOKI_GATE_PAUSE_LIMIT` or `LOKI_GATE_ESCALATE_LIMIT`."),z.push("- Roll back? Switch to `LOKI_LEGACY_BASH=1` and re-run; the bash route does not consult this handoff doc."),z.push(""),z.push("To resume: address the findings (or supply counter-evidence) and `rm .loki/PAUSE`."),z.join(`
|
|
680
|
+
`)}function l7($,Q){h7(f7($),{recursive:!0});let Z=`${$}.tmp.${process.pid}.${++l6}`;g7(Z,Q),m7(Z,$)}function d7($,Q,Z={}){let z=Z.findings??P1($,Q.iteration).findings,X=Z.learnings??F1($).learnings,q=p6(Q,z,X),K=(Z.now?.()??new Date).toISOString().replace(/[-:.]/g,""),W=p$($,"escalations"),J=++l6,U=p$(W,`handoff-${K}-${process.pid}-${J}-${Q.gateName}.md`);return l7(U,q),{path:U,bytes:q.length}}function o7($){let Q=p$($,"escalations");if(!b7(Q))return null;let Z;try{Z=y7(Q).filter((q)=>q.endsWith(".md"))}catch{return null}if(Z.length===0)return null;Z.sort();let z=Z[Z.length-1];if(!z)return null;let X=p$(Q,z);try{return{path:X,body:v7(X,"utf-8")}}catch{return null}}var l6=0;var o6=L(()=>{u$();c$()});var n6={};h(n6,{runInternalPhase1Hooks:()=>i7,_resolveForTests:()=>t7,_internalPhase1HooksHelp:()=>ZZ});import{existsSync as n7,mkdirSync as a7,readdirSync as s7,statSync as r7}from"fs";import{join as L$,resolve as t7}from"path";async function i7($){let[Q,...Z]=$;switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(R1),Q===void 0?1:0;case"reflect":return e7(Z);case"override":return $Z(Z);case"handoff":return QZ(Z);default:return process.stderr.write(`Unknown subcommand: ${Q}
|
|
681
|
+
`),process.stderr.write(R1),2}}async function e7($){let Q=x1($[0]);if(Q===null)return process.stderr.write(`reflect: missing or invalid <iter>
|
|
682
|
+
`),2;let Z=P();try{let X=(await Promise.resolve().then(() => (u$(),j1))).loadPreviousFindings(Z,Q);if(X.findings.length===0)return process.stdout.write(`reflect: no findings for iter ${Q} (nothing to do)
|
|
683
|
+
`),0;let q=L$(Z,"state");a7(q,{recursive:!0}),O$(L$(q,`findings-${Q}.json`),{review_id:X.reviewId,iteration:Q,findings:X.findings});let K=await Promise.resolve().then(() => (c$(),g6)),W=0;if(process.env.LOKI_AUTO_LEARNINGS!=="0"){for(let J of X.findings)if(J.severity==="Critical"||J.severity==="High")await K.appendFromGateFailure(Z,Q,J,{episodeBridge:null}),W+=1}return process.stdout.write(`reflect: persisted ${X.findings.length} findings + ${W} learnings (iter ${Q})
|
|
683
684
|
`),0}catch(z){return process.stderr.write(`reflect: ${z.message}
|
|
684
|
-
`),1}}async function
|
|
685
|
-
`),2;let Z=P();try{let z=await Promise.resolve().then(() => (
|
|
686
|
-
`),0;let K=(await Promise.resolve().then(() => (
|
|
687
|
-
`),0;let
|
|
688
|
-
`);else process.stdout.write(`override: BLOCKED -- ${
|
|
685
|
+
`),1}}async function $Z($){let Q=x1($[0]);if(Q===null)return process.stderr.write(`override: missing or invalid <iter>
|
|
686
|
+
`),2;let Z=P();try{let z=await Promise.resolve().then(() => (c6(),u6)),X=z.loadCounterEvidence(Z,Q);if(X===null||X.evidence.length===0)return process.stdout.write(`override: no counter-evidence for iter ${Q} (skip)
|
|
687
|
+
`),0;let K=(await Promise.resolve().then(() => (u$(),j1))).loadPreviousFindings(Z,Q),W=K.findings.filter((M)=>M.severity==="Critical"||M.severity==="High");if(W.length===0)return process.stdout.write(`override: no blocking findings for iter ${Q} (skip)
|
|
688
|
+
`),0;let J=new Set(["duplicate-code-path","file-exists","test-passes","grep-miss","out-of-scope"]),U=async(M)=>{let F=J.has(M.evidence.proofType);return{judge:M.judge,verdict:F?"APPROVE_OVERRIDE":"REJECT_OVERRIDE",reasoning:F?`[stub] proofType=${M.evidence.proofType} trusted`:`[stub] proofType=${M.evidence.proofType} requires manual review`}},H=await z.runOverrideCouncil(W,X,U);await z.recordOverrideOutcome(Z,Q,H,W);let Y=L$(Z,"quality","reviews");if(n7(Y))try{let M=s7(Y).filter((x)=>x.startsWith("review-")).sort(),F=M[M.length-1];if(F&&r7(L$(Y,F)).isDirectory())O$(L$(Y,F,`override-${Q}.json`),{review_id:K.reviewId,iteration:Q,approved_finding_ids:Array.from(H.approvedFindingIds),rejected_finding_ids:Array.from(H.rejectedFindingIds),votes:H.votes})}catch{}let B=H.approvedFindingIds.size,G=H.rejectedFindingIds.size;if(G===0&&B>0)process.stdout.write(`override: LIFTED -- ${B} approved, ${G} rejected
|
|
689
|
+
`);else process.stdout.write(`override: BLOCKED -- ${B} approved, ${G} rejected
|
|
689
690
|
`);return 0}catch(z){return process.stderr.write(`override: ${z.message}
|
|
690
|
-
`),1}}async function
|
|
691
|
-
`),2;let X=P();try{let K=(await Promise.resolve().then(() => (
|
|
692
|
-
`),0}catch(
|
|
693
|
-
`),1}}function
|
|
691
|
+
`),1}}async function QZ($){let Q=$[0],Z=Number.parseInt($[1]??"0",10),z=x1($[2]);if(!Q||!Number.isFinite(Z)||z===null)return process.stderr.write(`handoff: usage: handoff <gate> <consecutive-failures> <iter>
|
|
692
|
+
`),2;let X=P();try{let K=(await Promise.resolve().then(() => (o6(),d6))).writeEscalationHandoff(X,{gateName:Q,iteration:z,consecutiveFailures:Z,detail:`${Q} hit PAUSE_LIMIT (${Z} consecutive failures)`});return process.stdout.write(`handoff: wrote ${K.path} (${K.bytes}B)
|
|
693
|
+
`),0}catch(q){return process.stderr.write(`handoff: ${q.message}
|
|
694
|
+
`),1}}function x1($){if($===void 0)return null;let Q=Number.parseInt($,10);return Number.isFinite(Q)&&Q>=0?Q:null}var R1=`loki internal phase1-hooks <subcommand>
|
|
694
695
|
|
|
695
696
|
Subcommands:
|
|
696
697
|
reflect <iter> Persist structured findings + auto-learnings.
|
|
@@ -699,24 +700,24 @@ Subcommands:
|
|
|
699
700
|
|
|
700
701
|
This command is invoked by autonomy/run.sh between iterations. Users
|
|
701
702
|
should not run it directly -- run \`loki start\` instead.
|
|
702
|
-
`,
|
|
703
|
-
`),0}d();c();
|
|
703
|
+
`,ZZ;var a6=L(()=>{b();y$();ZZ=R1});a$();function C1(){return process.stdout.write(`Loki Mode v${j$()}
|
|
704
|
+
`),0}d();c();b();import{readFileSync as UQ,existsSync as HQ}from"fs";import{resolve as BQ}from"path";var GQ=["claude","codex","cline","aider"];function h1(){let $=BQ(P(),"state","provider");if(!HQ($))return"";try{return UQ($,"utf-8").trim()}catch{return""}}function YQ($,Q){return $||Q||process.env.LOKI_PROVIDER||"claude"}function MQ($){let Q=h1(),Z=YQ($,Q);switch(process.stdout.write(`${R}Current Provider${V}
|
|
704
705
|
`),process.stdout.write(`
|
|
705
|
-
`),process.stdout.write(`${
|
|
706
|
-
`),Z){case"claude":process.stdout.write(`${S}Status:${
|
|
707
|
-
`);break;case"cline":process.stdout.write(`${S}Status:${
|
|
708
|
-
`);break;case"codex":case"aider":process.stdout.write(`${
|
|
709
|
-
`);break;default:break}if(Q)process.stdout.write(`${y}(saved in .loki/state/provider)${
|
|
710
|
-
`);else process.stdout.write(`${y}(default - not explicitly set)${
|
|
706
|
+
`),process.stdout.write(`${I}Provider:${V} ${Z}
|
|
707
|
+
`),Z){case"claude":process.stdout.write(`${S}Status:${V} Full features (subagents, parallel, MCP)
|
|
708
|
+
`);break;case"cline":process.stdout.write(`${S}Status:${V} Near-full mode (subagents, MCP, 12+ providers)
|
|
709
|
+
`);break;case"codex":case"aider":process.stdout.write(`${_}Status:${V} Degraded mode (sequential only)
|
|
710
|
+
`);break;default:break}if(Q)process.stdout.write(`${y}(saved in .loki/state/provider)${V}
|
|
711
|
+
`);else process.stdout.write(`${y}(default - not explicitly set)${V}
|
|
711
712
|
`);return process.stdout.write(`
|
|
712
|
-
`),process.stdout.write(`Switch provider: ${
|
|
713
|
-
`),process.stdout.write(`Available: ${
|
|
714
|
-
`),0}async function
|
|
713
|
+
`),process.stdout.write(`Switch provider: ${I}loki provider set <name>${V}
|
|
714
|
+
`),process.stdout.write(`Available: ${I}loki provider list${V}
|
|
715
|
+
`),0}async function TQ(){let Q=h1()||process.env.LOKI_PROVIDER||"claude";process.stdout.write(`${R}Available Providers${V}
|
|
715
716
|
`),process.stdout.write(`
|
|
716
|
-
`);let Z=await Promise.all(
|
|
717
|
+
`);let Z=await Promise.all(GQ.map(async(q)=>[q,await f(q)!==null])),z=new Map;for(let[q,K]of Z)z.set(q,K?`${S}installed${V}`:`${T}not installed${V}`);let X=[["claude","claude - Claude Code (Anthropic) "],["codex","codex - Codex CLI (OpenAI) "],["cline","cline - Cline (multi-provider) "],["aider","aider - Aider (terminal pair prog) "]];for(let[q,K]of X){let W=Q===q?` ${I}(current)${V}`:"";process.stdout.write(` ${K} ${z.get(q)}${W}
|
|
717
718
|
`)}return process.stdout.write(`
|
|
718
|
-
`),process.stdout.write(`Set provider: ${
|
|
719
|
-
`),0}function
|
|
719
|
+
`),process.stdout.write(`Set provider: ${I}loki provider set <name>${V}
|
|
720
|
+
`),0}function OQ(){return process.stdout.write(`${R}Loki Mode Provider Management${V}
|
|
720
721
|
`),process.stdout.write(`
|
|
721
722
|
`),process.stdout.write(`Usage: loki provider <command>
|
|
722
723
|
`),process.stdout.write(`
|
|
@@ -734,17 +735,17 @@ should not run it directly -- run \`loki start\` instead.
|
|
|
734
735
|
`),process.stdout.write(` loki provider list
|
|
735
736
|
`),process.stdout.write(` loki provider info codex
|
|
736
737
|
`),process.stdout.write(` loki provider models
|
|
737
|
-
`),0}async function
|
|
738
|
-
`))if(z.includes('"description"'))Z++;return Z}catch{return 0}}async function
|
|
738
|
+
`),0}async function y1($){let Q=$[0]??"show",Z=$.slice(1);switch(Q){case"show":case"current":return MQ(Z[0]);case"list":return TQ();case"set":case"info":case"models":return AQ(["provider",Q,...Z]);default:return OQ()}}async function AQ($){let{run:Q}=await Promise.resolve().then(() => (d(),b1)),{resolve:Z}=await import("path"),{REPO_ROOT:z}=await Promise.resolve().then(() => (b(),D1)),X=Z(z,"autonomy","loki"),q=await Q([X,...$],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(q.stdout),process.stderr.write(q.stderr),q.exitCode}c();b();q$();import{existsSync as v1,readFileSync as _Q}from"fs";import{resolve as V$}from"path";import{mkdir as IQ}from"fs/promises";var Y$=V$(n$(),"learnings");function r$($){if(!v1($))return 0;try{let Q=_Q($,"utf-8"),Z=0;for(let z of Q.split(`
|
|
739
|
+
`))if(z.includes('"description"'))Z++;return Z}catch{return 0}}async function LQ(){await IQ(Y$,{recursive:!0});let $=r$(V$(Y$,"patterns.jsonl")),Q=r$(V$(Y$,"mistakes.jsonl")),Z=r$(V$(Y$,"successes.jsonl"));return process.stdout.write(`${R}Cross-Project Learnings${V}
|
|
739
740
|
`),process.stdout.write(`
|
|
740
|
-
`),process.stdout.write(` Patterns: ${S}${$}${
|
|
741
|
-
`),process.stdout.write(` Mistakes: ${
|
|
742
|
-
`),process.stdout.write(` Successes: ${
|
|
741
|
+
`),process.stdout.write(` Patterns: ${S}${$}${V}
|
|
742
|
+
`),process.stdout.write(` Mistakes: ${_}${Q}${V}
|
|
743
|
+
`),process.stdout.write(` Successes: ${I}${Z}${V}
|
|
743
744
|
`),process.stdout.write(`
|
|
744
745
|
`),process.stdout.write(`Location: ${Y$}
|
|
745
746
|
`),process.stdout.write(`
|
|
746
747
|
`),process.stdout.write(`Use 'loki memory show <type>' to view entries
|
|
747
|
-
`),0}async function
|
|
748
|
+
`),0}async function PQ($){if($){let z=`
|
|
748
749
|
try:
|
|
749
750
|
from memory.layers import IndexLayer
|
|
750
751
|
layer = IndexLayer('.loki/memory')
|
|
@@ -754,12 +755,12 @@ except ImportError:
|
|
|
754
755
|
print('Error: memory.layers module not found')
|
|
755
756
|
except Exception as e:
|
|
756
757
|
print(f'Error: {e}')
|
|
757
|
-
`.trim(),X=await Z$(z,{cwd:g});return process.stdout.write(X.stdout),0}let Q=
|
|
758
|
+
`.trim(),X=await Z$(z,{cwd:g});return process.stdout.write(X.stdout),0}let Q=V$(P(),"memory","index.json");if(!v1(Q))return process.stdout.write(`No index found
|
|
758
759
|
`),0;let Z=await Z$(`import json, sys; sys.stdout.write(json.dumps(json.load(open(${JSON.stringify(Q)})), indent=4) + "\\n")`);if(Z.exitCode!==0)return process.stdout.write(`No index found
|
|
759
|
-
`),0;return process.stdout.write(Z.stdout),0}async function
|
|
760
|
-
`)){let K=
|
|
761
|
-
`)}catch{}process.exit(1)}),process.on("unhandledRejection",($)=>{if(!
|
|
762
|
-
`)}catch{}process.exit(1)})}var
|
|
760
|
+
`),0;return process.stdout.write(Z.stdout),0}async function m1($){switch($[0]??"list"){case"list":case"ls":return LQ();case"index":return PQ($[1]==="rebuild");default:{let Z=V$(g,"autonomy","loki"),z=3600000,X=Bun.spawn({cmd:[Z,"memory",...$],stdin:"inherit",stdout:"inherit",stderr:"inherit",env:{...process.env,LOKI_LEGACY_BASH:"1"}}),q=setTimeout(()=>{try{X.kill("SIGKILL")}catch{}},3600000);try{return await X.exited}finally{clearTimeout(q)}}}}b();q$();d();import{resolve as jQ,join as FQ}from"path";import{existsSync as t$,readFileSync as kQ}from"fs";import{homedir as RQ}from"os";import{spawnSync as c1}from"child_process";var p1=3000;function xQ(){let $=(process.env.LOKI_TELEMETRY??"").toLowerCase();if($==="off")return!1;if(process.env.LOKI_TELEMETRY_DISABLED==="true")return!1;if(process.env.DO_NOT_TRACK==="1")return!1;let Q=!1,Z=!1;try{let z=FQ(RQ(),".loki","config");if(t$(z)){let X=kQ(z,"utf8");for(let q of X.split(`
|
|
761
|
+
`)){let K=q.replace(/\r$/,"");if(K==="TELEMETRY_DISABLED=true")Q=!0;if(K==="TELEMETRY_ENABLED=true")Z=!0}}}catch{}if(Q)return!1;if($==="on"||Z)return!0;return!1}var F$=!1;function EQ(){return jQ(g,"autonomy","lib","crash_capture.py")}function NQ($,Q){let Z=[$,"--error-class",Q.errorClass,"--message",Q.message];if(Q.stack!==void 0)Z.push("--stack",Q.stack);if(Q.rarvPhase!==void 0)Z.push("--rarv-phase",Q.rarvPhase);if(Q.exitCode!==void 0)Z.push("--exit-code",String(Q.exitCode));if(Q.frictionKind!==void 0)Z.push("--friction-kind",Q.frictionKind);return Z.push("--target-dir",Q.targetDir??process.cwd()),Z}function SQ(){if(t$("/opt/homebrew/bin/python3.12"))return"/opt/homebrew/bin/python3.12";for(let Q of["python3.12","python3"])try{let Z=c1("sh",["-c",`command -v ${Q}`],{timeout:p1,encoding:"utf8"});if(Z.status===0){let z=(Z.stdout||"").trim();if(z)return z}}catch{}return null}function g1($){try{if(!xQ())return;let Q=EQ();if(!t$(Q))return;let Z=SQ();if(!Z)return;let z=NQ(Q,$);c1(Z,z,{timeout:p1,stdio:"ignore"})}catch{}}function f1($,Q){if($ instanceof Error){let z={errorClass:$.name&&$.name.length>0?$.name:Q,message:$.message};if($.stack)z.stack=$.stack;return z}return{errorClass:Q,message:String($)}}var u1=!1;function l1(){if(u1)return;u1=!0,process.on("uncaughtException",($)=>{if(!F$){F$=!0;let Q=f1($,"UncaughtException");g1({errorClass:Q.errorClass,message:Q.message,...Q.stack!==void 0?{stack:Q.stack}:{},exitCode:1})}try{process.stderr.write(`${$&&$.stack||String($)}
|
|
762
|
+
`)}catch{}process.exit(1)}),process.on("unhandledRejection",($)=>{if(!F$){F$=!0;let Q=f1($,"UnhandledRejection");g1({errorClass:Q.errorClass,message:Q.message,...Q.stack!==void 0?{stack:Q.stack}:{},exitCode:1})}try{let Q=$ instanceof Error?$.stack||$.message:String($);process.stderr.write(`Unhandled promise rejection: ${Q}
|
|
763
|
+
`)}catch{}process.exit(1)})}var s6=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
|
|
763
764
|
|
|
764
765
|
Usage: loki <command> [args...]
|
|
765
766
|
|
|
@@ -781,12 +782,12 @@ Phase 2 ported (Bun-native, fast):
|
|
|
781
782
|
|
|
782
783
|
All other commands fall through to the bash CLI (autonomy/loki).
|
|
783
784
|
Set LOKI_LEGACY_BASH=1 to force the bash CLI for every command.
|
|
784
|
-
`;function
|
|
785
|
-
`)}async function
|
|
786
|
-
`);return process.stdout.write(`${
|
|
787
|
-
`),0}if(z==="phase1-hooks"){let{runInternalPhase1Hooks:
|
|
785
|
+
`;function zZ(){let $=process.env.LOKI_LEGACY_BASH;if($===void 0)return;let Q=$.trim().toLowerCase();if(Q!=="1"&&Q!=="true"&&Q!=="yes"&&Q!=="on")return;if(process.env.LOKI_SUPPRESS_BUN_DIRECT_WARN==="1")return;process.stderr.write(`warning: LOKI_LEGACY_BASH is set, but you are running the Bun runtime directly (src/cli.ts). The env var only takes effect via the bin/loki shim, which dispatches between Bun and bash. Behavior is unchanged; this message is informational.
|
|
786
|
+
`)}async function XZ($){zZ();let Q=$[0],Z=$.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(s6),0;case"version":case"--version":case"-v":return C1();case"provider":return y1(Z);case"memory":return m1(Z);case"status":{let{runStatus:z}=await Promise.resolve().then(() => ($0(),e1));return z(Z)}case"stats":{let{runStats:z}=await Promise.resolve().then(() => (V0(),q0));return z(Z)}case"doctor":{let{runDoctor:z}=await Promise.resolve().then(() => (O0(),T0));return z(Z)}case"kpis":{let{runKpis:z}=await Promise.resolve().then(() => (W1(),V1));return z(Z,{aliasOf:"kpis"})}case"report":{if(Z.find((q)=>!q.startsWith("-"))==="kpis"){let{runKpis:q}=await Promise.resolve().then(() => (W1(),V1)),K=!1,W=Z.filter((J)=>{if(!K&&J==="kpis")return K=!0,!1;return!0});return q(W)}let{delegateToBash:X}=await Promise.resolve().then(() => (N0(),E0));return X(["report",...Z])}case"trust":{let{runTrust:z}=await Promise.resolve().then(() => (g0(),m0));return z(Z)}case"rollback":{let{runRollback:z}=await Promise.resolve().then(() => (H6(),U6));return z(Z)}case"proof":{let{runProof:z}=await Promise.resolve().then(() => (T6(),M6));return z(Z)}case"crash":{let{runCrash:z}=await Promise.resolve().then(() => (P6(),L6));return z(Z)}case"wiki":{let{runWiki:z}=await Promise.resolve().then(() => (x6(),R6));return z(Z)}case"internal":{let z=Z[0];if(!z||z==="--help"||z==="-h"||z==="help"){let q=["loki internal -- runtime hooks driven by autonomy/run.sh","","Subcommands:"," phase1-hooks Persist structured findings, run override council,"," append learnings, and write the escalation handoff"," doc once per iteration. Driven by run.sh; not"," intended for direct invocation.","","Phase 1 (RARV-C closure) env vars:"," LOKI_INJECT_FINDINGS=1 Persist structured reviewer findings to"," .loki/state/findings-<iter>.json so the"," next iteration can address them."," LOKI_OVERRIDE_COUNCIL=1 Allow a 3-LLM override panel to lift a"," BLOCK when counter-evidence is presented."," See LOKI_OVERRIDE_JUDGES (csv),"," LOKI_OVERRIDE_PANEL_SIZE,"," LOKI_OVERRIDE_REAL_JUDGE."," LOKI_AUTO_LEARNINGS=1 Append failure rootcauses to"," .loki/state/relevant-learnings.json via"," the episodic memory bridge."," LOKI_HANDOFF_MD=1 Write a structured human handoff doc to"," .loki/escalations/<ts>.md before PAUSE.","","All four are default-on as of v7.5.3. Set to 0 to disable.","Reference: CHANGELOG.md (search 'Phase 1') and skills/healing.md.","","These commands are wired into the autonomous loop and may change","without notice. Do not script against them.",""].join(`
|
|
787
|
+
`);return process.stdout.write(`${q}
|
|
788
|
+
`),0}if(z==="phase1-hooks"){let{runInternalPhase1Hooks:q}=await Promise.resolve().then(() => (a6(),n6));return q(Z.slice(1))}return process.stderr.write(`Unknown internal subcommand: ${z}
|
|
788
789
|
`),process.stderr.write(`Run 'loki internal --help' for the supported list.
|
|
789
790
|
`),2}default:return process.stderr.write(`Unknown command: ${Q}
|
|
790
|
-
`),process.stderr.write(
|
|
791
|
+
`),process.stderr.write(s6),2}}l1();process.on("SIGINT",()=>process.exit(130));process.on("SIGTERM",()=>process.exit(143));var KZ=await XZ(Bun.argv.slice(2));process.exit(KZ);
|
|
791
792
|
|
|
792
|
-
//# debugId=
|
|
793
|
+
//# debugId=8015709BAB9E625464756E2164756E21
|