loki-mode 7.5.0 → 7.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: loki-mode
3
3
  description: Multi-agent autonomous startup system. Triggers on "Loki Mode". Takes PRD to deployed product with minimal human intervention. Requires --dangerously-skip-permissions flag.
4
4
  ---
5
5
 
6
- # Loki Mode v7.5.0
6
+ # Loki Mode v7.5.1
7
7
 
8
8
  **You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
9
9
 
@@ -322,4 +322,4 @@ The following features are documented in skill modules but not yet fully automat
322
322
  | Quality gates 3-reviewer system | Implemented (v5.35.0) | 5 specialist reviewers in `skills/quality-gates.md`; execution in run.sh |
323
323
  | Benchmarks (HumanEval, SWE-bench) | Infrastructure only | Runner scripts and datasets exist in `benchmarks/`; no published results |
324
324
 
325
- **v7.5.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
325
+ **v7.5.1 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
package/VERSION CHANGED
@@ -1 +1 @@
1
- 7.5.0
1
+ 7.5.1
package/autonomy/loki CHANGED
@@ -459,7 +459,6 @@ show_help() {
459
459
  echo " setup-skill Create skill symlinks for all providers"
460
460
  echo " self-update Upgrade loki via current manager (use --to bun|npm|brew to switch)"
461
461
  echo " watchdog [cmd] Process health monitoring (status|help)"
462
- echo " telemetry [cmd] OpenTelemetry management (status|enable|disable)"
463
462
  echo " worktree [cmd] Parallel worktree management (list|merge|clean|status)"
464
463
  echo " agent [cmd] Agent type dispatch (list|info|run|start|review)"
465
464
  echo " remote [PRD] Start remote session (connect from phone/browser, Claude Pro/Max)"
@@ -6750,6 +6749,23 @@ cmd_doctor() {
6750
6749
  fi
6751
6750
  echo ""
6752
6751
 
6752
+ # v7.5.1 fix B23: Runtime route -- mirror loki-ts/src/commands/doctor.ts.
6753
+ # Informational only; does NOT contribute to pass/fail/warn counts so
6754
+ # the bun-parity matrix can normalize it without reconciling summary
6755
+ # totals across routes.
6756
+ echo -e "${CYAN}Runtime route:${NC}"
6757
+ echo -e " ${GREEN}PASS${NC} Active runtime: Bash (autonomy/loki)"
6758
+ if [ "${LOKI_LEGACY_BASH:-}" = "1" ] || [ "${LOKI_LEGACY_BASH:-}" = "true" ]; then
6759
+ echo -e " ${YELLOW}WARN${NC} LOKI_LEGACY_BASH set: shim routes every command to autonomy/loki (bash)"
6760
+ fi
6761
+ if [ -n "${LOKI_TS_ENTRY:-}" ]; then
6762
+ echo -e " ${GREEN}PASS${NC} LOKI_TS_ENTRY override: ${LOKI_TS_ENTRY}"
6763
+ fi
6764
+ if [ "${BUN_FROM_SOURCE:-}" = "1" ] || [ "${BUN_FROM_SOURCE:-}" = "true" ]; then
6765
+ echo -e " ${GREEN}PASS${NC} BUN_FROM_SOURCE set: shim prefers loki-ts/src/ over dist/"
6766
+ fi
6767
+ echo ""
6768
+
6753
6769
  # Summary
6754
6770
  echo -e "${BOLD}Summary:${NC} ${GREEN}$pass_count passed${NC}, ${RED}$fail_count failed${NC}, ${YELLOW}$warn_count warnings${NC}"
6755
6771
  echo ""
package/bin/loki CHANGED
@@ -43,6 +43,15 @@ BASH_CLI="$REPO_ROOT/autonomy/loki"
43
43
  # installs because src/ is excluded by .npmignore. Now we warn once and fall
44
44
  # back to dist if src/cli.ts is missing.
45
45
  if [ -n "${LOKI_TS_ENTRY:-}" ]; then
46
+ # v7.5.1 fix B18: validate that the explicit override actually exists.
47
+ # Pre-v7.5.1 a typo (LOKI_TS_ENTRY=/nonexistent) produced a raw Bun
48
+ # "Module not found" error with no hint about the env var. Now we warn
49
+ # to stderr and fall through to the bash CLI so the user can still
50
+ # invoke commands while they fix the path.
51
+ if [ ! -f "$LOKI_TS_ENTRY" ]; then
52
+ echo "ERROR: LOKI_TS_ENTRY=$LOKI_TS_ENTRY does not exist; falling through to bash CLI. Unset the variable or fix the path." >&2
53
+ exec "$BASH_CLI" "$@"
54
+ fi
46
55
  BUN_CLI="$LOKI_TS_ENTRY"
47
56
  elif [ "${BUN_FROM_SOURCE:-0}" = "1" ] || [ "${BUN_FROM_SOURCE:-}" = "true" ]; then
48
57
  if [ -f "$REPO_ROOT/loki-ts/src/cli.ts" ]; then
@@ -7,7 +7,7 @@ Modules:
7
7
  control: Session control API (start/stop/pause/resume)
8
8
  """
9
9
 
10
- __version__ = "7.5.0"
10
+ __version__ = "7.5.1"
11
11
 
12
12
  # Expose the control app for easy import
13
13
  try:
@@ -2,28 +2,33 @@
2
2
 
3
3
  The flagship product of [Autonomi](https://www.autonomi.dev/). Complete installation instructions for all platforms and use cases.
4
4
 
5
- **Version:** v7.5.0
5
+ **Version:** v7.5.1
6
6
 
7
7
  ---
8
8
 
9
- ## What's New in v6.7.0
9
+ ## What's New in v7.5.0
10
10
 
11
- ### Dual-Mode Architecture (v6.0.0)
12
- - `loki run` command for direct autonomous execution
13
- - Dual-mode: skill mode (inside Claude Code) and standalone mode
14
- - Dynamic model resolution across all providers
15
- - Multi-provider issue fixes and stability improvements
11
+ ### Phase 1 RARV-C closure (Bun route, default-off feature flags)
12
+ - `findings_injector.ts` -- structured per-finding records (severity, file,
13
+ line, reviewer) injected into the next iteration's prompt instead of bare
14
+ comma-separated tokens. Enable with `LOKI_INJECT_FINDINGS=1`.
15
+ - `counter_evidence.ts` -- 3-judge override council. Drop a
16
+ `.loki/state/counter-evidence-<iter>.json` to dispute reviewer findings;
17
+ 2-of-3 approval lifts the BLOCK. Enable with `LOKI_OVERRIDE_COUNCIL=1`
18
+ (requires `LOKI_INJECT_FINDINGS=1`).
19
+ - `learnings_writer.ts` -- automatic structured learnings to
20
+ `.loki/state/relevant-learnings.json` on every code_review failure.
21
+ Enable with `LOKI_AUTO_LEARNINGS=1`.
22
+ - `escalation_handoff.ts` -- structured human-handoff doc to
23
+ `.loki/escalations/handoff-*.md` before PAUSE. Enable with
24
+ `LOKI_HANDOFF_MD=1`.
25
+ - See `skills/quality-gates.md` for full schema and reachability notes.
16
26
 
17
- ### ChromaDB Semantic Code Search (v6.1.0)
18
- - Semantic code search via ChromaDB vector database
19
- - MCP integration with `loki_code_search` and `loki_code_search_stats` tools
20
- - Automatic codebase indexing with `tools/index-codebase.py`
21
-
22
- ### Memory System (v5.15.0+)
23
- - Episodic, semantic, and procedural memory layers
24
- - Progressive disclosure with 3-layer loading
25
- - Token economics tracking for discovery vs read tokens
26
- - Optional vector search with sentence-transformers
27
+ ### Earlier highlights still in scope
28
+ - Bash-to-Bun runtime migration in progress (see `UPGRADING.md`)
29
+ - 5-provider support: Claude (full), Codex, Gemini, Cline, Aider
30
+ - Memory system (episodic / semantic / procedural)
31
+ - ChromaDB semantic code search via MCP
27
32
 
28
33
  ---
29
34
 
@@ -52,14 +57,18 @@ The flagship product of [Autonomi](https://www.autonomi.dev/). Complete installa
52
57
  npm install -g loki-mode
53
58
  ```
54
59
 
55
- Installs the `loki` CLI and automatically sets up the skill for Claude Code, Codex CLI, and Gemini CLI via the postinstall script.
60
+ Installs the `loki` CLI. As of v7.4.12 there is no postinstall step; run
61
+ `loki setup-skill` once after install to create the per-provider skill
62
+ symlinks (Claude Code, Codex CLI, Gemini CLI). The `loki` shim auto-routes
63
+ read-only commands to the Bun runtime when `bun` is on `PATH` and falls
64
+ back to the bash CLI otherwise.
56
65
 
57
- **Prerequisites:** Node.js 18+
66
+ **Prerequisites:** Node.js 18+. Bun 1.3+ optional but recommended for the
67
+ faster routed commands and forward-compat with v8.0.0.
58
68
 
59
69
  **What it does:**
60
- - Installs the `loki` CLI binary to your PATH
61
- - Creates skill symlinks at `~/.claude/skills/loki-mode`, `~/.codex/skills/loki-mode`, and `~/.gemini/skills/loki-mode`
62
- - Each provider auto-discovers skills in its respective directory
70
+ - Installs the `loki` CLI binary to your PATH (`bin/loki` shim)
71
+ - Subsequent `loki setup-skill` creates symlinks at `~/.claude/skills/loki-mode`, `~/.codex/skills/loki-mode`, `~/.gemini/skills/loki-mode`
63
72
 
64
73
  **Opt out of anonymous install telemetry:**
65
74
  ```bash
@@ -222,15 +231,17 @@ The `HUMAN_INPUT.md` file has security controls:
222
231
 
223
232
  ## Multi-Provider Support
224
233
 
225
- Loki Mode v5.0.0 introduces support for multiple AI providers beyond Claude.
234
+ Loki Mode supports five providers across three tiers. Pick by capability + cost.
226
235
 
227
236
  ### Supported Providers
228
237
 
229
- | Provider | Status | Notes |
230
- |----------|--------|-------|
231
- | `claude` | Full Support | Default provider, all features available |
232
- | `codex` | Degraded Mode | Core functionality only, some features unavailable |
233
- | `gemini` | Degraded Mode | Core functionality only, some features unavailable |
238
+ | Provider | Tier | Notes |
239
+ |----------|------|-------|
240
+ | `claude` | Tier 1 (full) | Default. All features incl. Task subagents, MCP, council. |
241
+ | `cline` | Tier 2 | Full feature set; small models (<13B) may fail tool-use. |
242
+ | `codex` | Tier 3 (degraded) | Sequential only, no Task tool; aligned with `@openai/codex` v0.125+. |
243
+ | `gemini` | Tier 3 (degraded) | Sequential only, no Task tool; uses `--approval-mode=yolo`. |
244
+ | `aider` | Tier 3 (degraded) | Sequential only; `ollama_chat/<model>` works for local models. |
234
245
 
235
246
  ### Configuration
236
247
 
@@ -1,12 +1,12 @@
1
1
  // @bun
2
- var Q0=Object.defineProperty;var X0=(z)=>z;function Z0(z,Q){this[z]=X0.bind(null,Q)}var r=(z,Q)=>{for(var $ in Q)Q0(z,$,{get:Q[$],enumerable:!0,configurable:!0,set:Z0.bind(Q,$)})};var g=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var K0=import.meta.require;var P1={};r(P1,{lokiDir:()=>b,homeLokiDir:()=>V1,findSkillDir:()=>B0,findRepoRootForVersion:()=>U1,REPO_ROOT:()=>y});import{resolve as k,dirname as B1}from"path";import{fileURLToPath as H0}from"url";import{existsSync as u}from"fs";import{homedir as L1}from"os";function W0(){let z=x1;for(let Q=0;Q<6;Q++){if(u(k(z,"VERSION"))&&u(k(z,"autonomy/run.sh")))return z;let $=B1(z);if($===z)break;z=$}return k(x1,"..","..","..")}function U1(z){let Q=z;for(let $=0;$<6;$++){if(u(k(Q,"VERSION"))&&u(k(Q,"autonomy/run.sh")))return Q;let X=B1(Q);if(X===Q)break;Q=X}return k(z,"..","..","..")}function b(){return process.env.LOKI_DIR??k(process.cwd(),".loki")}function V1(){return k(L1(),".loki")}function B0(){let z=[y,k(L1(),".claude/skills/loki-mode"),process.cwd()];for(let Q of z)if(u(k(Q,"SKILL.md"))&&u(k(Q,"autonomy/run.sh")))return Q;return null}var x1,y;var h=g(()=>{x1=B1(H0(import.meta.url));y=W0()});var S1={};r(S1,{runOrThrow:()=>J0,run:()=>w,commandVersion:()=>M0,commandExists:()=>R,ShellError:()=>q1});async function w(z,Q={}){let $=Bun.spawn({cmd:[...z],stdout:"pipe",stderr:"pipe",env:Q.env?{...process.env,...Q.env}:process.env,cwd:Q.cwd}),X;if(Q.timeoutMs&&Q.timeoutMs>0)X=setTimeout(()=>$.kill(),Q.timeoutMs);let[Z,H,W]=await Promise.all([new Response($.stdout).text(),new Response($.stderr).text(),$.exited]);if(X)clearTimeout(X);return{stdout:Z,stderr:H,exitCode:W}}async function J0(z,Q={}){let $=await w(z,Q);if($.exitCode!==0)throw new q1(`command failed (${$.exitCode}): ${z.join(" ")}`,$.exitCode,$.stdout,$.stderr);return $}async function R(z){let Q=j0(z),$=await w(["sh","-c",`command -v ${Q}`],{timeoutMs:5000});if($.exitCode===0)return $.stdout.trim()||null;return null}function j0(z){if(!/^[A-Za-z0-9._/-]+$/.test(z))throw Error(`refused to shell-escape suspect token: ${z}`);return z}async function M0(z,Q="--version"){if(!await R(z))return null;let X=await w([z,Q],{timeoutMs:5000});if(X.exitCode!==0)return null;return((X.stdout||X.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var q1;var m=g(()=>{q1=class q1 extends Error{message;exitCode;stdout;stderr;constructor(z,Q,$,X){super(z);this.message=z;this.exitCode=Q;this.stdout=$;this.stderr=X;this.name="ShellError"}}});function N(z){return Y0?"":z}var Y0,S,P,T,A3,G,x,A,K;var p=g(()=>{Y0=(process.env.NO_COLOR??"").length>0;S=N("\x1B[0;31m"),P=N("\x1B[0;32m"),T=N("\x1B[1;33m"),A3=N("\x1B[0;34m"),G=N("\x1B[0;36m"),x=N("\x1B[1m"),A=N("\x1B[2m"),K=N("\x1B[0m")});import{existsSync as P0}from"fs";async function a(){if(t!==void 0)return t;let z="/opt/homebrew/bin/python3.12";if(P0(z))return t=z,z;let Q=await R("python3.12");if(Q)return t=Q,Q;let $=await R("python3");return t=$,$}async function s(z,Q={}){let $=await a();if(!$)return{stdout:"",stderr:"python3 not found",exitCode:127};return w([$,"-c",z],Q)}var t;var Q1=g(()=>{m()});var v1={};r(v1,{runStatus:()=>y0});import{existsSync as L,readFileSync as e,readdirSync as C1,statSync as f1}from"fs";import{resolve as F,basename as E0}from"path";async function N0(){if(await R("jq"))return!0;return process.stdout.write(`${S}Error: jq is required but not installed.${K}
2
+ var Q0=Object.defineProperty;var X0=(z)=>z;function Z0(z,Q){this[z]=X0.bind(null,Q)}var t=(z,Q)=>{for(var $ in Q)Q0(z,$,{get:Q[$],enumerable:!0,configurable:!0,set:Z0.bind(Q,$)})};var h=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var K0=import.meta.require;var P1={};t(P1,{lokiDir:()=>C,homeLokiDir:()=>B1,findSkillDir:()=>U0,findRepoRootForVersion:()=>V1,REPO_ROOT:()=>v});import{resolve as R,dirname as U1}from"path";import{fileURLToPath as H0}from"url";import{existsSync as c}from"fs";import{homedir as L1}from"os";function W0(){let z=x1;for(let Q=0;Q<6;Q++){if(c(R(z,"VERSION"))&&c(R(z,"autonomy/run.sh")))return z;let $=U1(z);if($===z)break;z=$}return R(x1,"..","..","..")}function V1(z){let Q=z;for(let $=0;$<6;$++){if(c(R(Q,"VERSION"))&&c(R(Q,"autonomy/run.sh")))return Q;let X=U1(Q);if(X===Q)break;Q=X}return R(z,"..","..","..")}function C(){return process.env.LOKI_DIR??R(process.cwd(),".loki")}function B1(){return R(L1(),".loki")}function U0(){let z=[v,R(L1(),".claude/skills/loki-mode"),process.cwd()];for(let Q of z)if(c(R(Q,"SKILL.md"))&&c(R(Q,"autonomy/run.sh")))return Q;return null}var x1,v;var m=h(()=>{x1=U1(H0(import.meta.url));v=W0()});var S1={};t(S1,{runOrThrow:()=>J0,run:()=>w,commandVersion:()=>M0,commandExists:()=>S,ShellError:()=>q1});async function w(z,Q={}){let $=Bun.spawn({cmd:[...z],stdout:"pipe",stderr:"pipe",env:Q.env?{...process.env,...Q.env}:process.env,cwd:Q.cwd}),X;if(Q.timeoutMs&&Q.timeoutMs>0)X=setTimeout(()=>$.kill(),Q.timeoutMs);let[Z,H,W]=await Promise.all([new Response($.stdout).text(),new Response($.stderr).text(),$.exited]);if(X)clearTimeout(X);return{stdout:Z,stderr:H,exitCode:W}}async function J0(z,Q={}){let $=await w(z,Q);if($.exitCode!==0)throw new q1(`command failed (${$.exitCode}): ${z.join(" ")}`,$.exitCode,$.stdout,$.stderr);return $}async function S(z){let Q=j0(z),$=await w(["sh","-c",`command -v ${Q}`],{timeoutMs:5000});if($.exitCode===0)return $.stdout.trim()||null;return null}function j0(z){if(!/^[A-Za-z0-9._/-]+$/.test(z))throw Error(`refused to shell-escape suspect token: ${z}`);return z}async function M0(z,Q="--version"){if(!await S(z))return null;let X=await w([z,Q],{timeoutMs:5000});if(X.exitCode!==0)return null;return((X.stdout||X.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var q1;var p=h(()=>{q1=class q1 extends Error{message;exitCode;stdout;stderr;constructor(z,Q,$,X){super(z);this.message=z;this.exitCode=Q;this.stdout=$;this.stderr=X;this.name="ShellError"}}});function f(z){return Y0?"":z}var Y0,D,k,_,A3,G,x,A,K;var l=h(()=>{Y0=(process.env.NO_COLOR??"").length>0;D=f("\x1B[0;31m"),k=f("\x1B[0;32m"),_=f("\x1B[1;33m"),A3=f("\x1B[0;34m"),G=f("\x1B[0;36m"),x=f("\x1B[1m"),A=f("\x1B[2m"),K=f("\x1B[0m")});import{existsSync as P0}from"fs";async function s(){if(a!==void 0)return a;let z="/opt/homebrew/bin/python3.12";if(P0(z))return a=z,z;let Q=await S("python3.12");if(Q)return a=Q,Q;let $=await S("python3");return a=$,$}async function i(z,Q={}){let $=await s();if(!$)return{stdout:"",stderr:"python3 not found",exitCode:127};return w([$,"-c",z],Q)}var a;var Q1=h(()=>{p()});var v1={};t(v1,{runStatus:()=>y0});import{existsSync as L,readFileSync as z1,readdirSync as C1,statSync as f1}from"fs";import{resolve as F,basename as E0}from"path";async function b0(){if(await S("jq"))return!0;return process.stdout.write(`${D}Error: jq is required but not installed.${K}
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 X1(z){if(!Number.isFinite(z)||z<=0)return!1;try{return process.kill(z,0),!0}catch{return!1}}function Z1(z){if(!L(z))return null;try{let Q=e(z,"utf-8").trim();if(!Q)return null;let $=Number.parseInt(Q,10);return Number.isFinite($)?$:null}catch{return null}}function C0(z){let Q=[],$=Z1(F(z,"loki.pid"));if($!==null&&X1($))Q.push(`global:${$}`);let X=F(z,"sessions");if(L(X)){let Z=[];try{Z=C1(X)}catch{Z=[]}for(let H of Z){let W=F(X,H);try{if(!f1(W).isDirectory())continue}catch{continue}let B=F(W,"loki.pid"),j=Z1(B);if(j!==null&&X1(j))Q.push(`${H}:${j}`)}}if(L(z)){let Z=[];try{Z=C1(z)}catch{Z=[]}for(let H of Z){if(!H.startsWith("run-")||!H.endsWith(".pid"))continue;let W=F(z,H);try{if(!f1(W).isFile())continue}catch{continue}let B=E0(H,".pid").slice(4),j=Z1(W);if(j!==null&&X1(j)){if(!Q.some((I)=>I.startsWith(`${B}:`)))Q.push(`${B}:${j}`)}}}return Q}async function g1(z,Q){let $=await w(["jq","-r",z,Q]);if($.exitCode!==0)return null;return $.stdout.trim()}function y1(z,Q){try{let $=e(z,"utf-8"),Z=JSON.parse($)[Q];if(typeof Z==="number"){if(Q==="budget_used"){let H=Math.round(Z*100)/100;if(Number.isInteger(H))return String(H);return String(H)}return String(Z)}if(Z===void 0||Z===null)return"0";return String(Z)}catch{return"0"}}function h1(z,Q,$){try{let X=e(z,"utf-8"),H=JSON.parse(X)[Q];if(typeof H==="number"&&Number.isFinite(H))return H;return $}catch{return $}}async function f0(){let z=b();if(!await N0())return 1;if(!L(z))return process.stdout.write(`${x}Loki Mode Status${K}
7
+ `),!1}function X1(z){if(!Number.isFinite(z)||z<=0)return!1;try{return process.kill(z,0),!0}catch{return!1}}function Z1(z){if(!L(z))return null;try{let Q=z1(z,"utf-8").trim();if(!Q)return null;let $=Number.parseInt(Q,10);return Number.isFinite($)?$:null}catch{return null}}function C0(z){let Q=[],$=Z1(F(z,"loki.pid"));if($!==null&&X1($))Q.push(`global:${$}`);let X=F(z,"sessions");if(L(X)){let Z=[];try{Z=C1(X)}catch{Z=[]}for(let H of Z){let W=F(X,H);try{if(!f1(W).isDirectory())continue}catch{continue}let U=F(W,"loki.pid"),J=Z1(U);if(J!==null&&X1(J))Q.push(`${H}:${J}`)}}if(L(z)){let Z=[];try{Z=C1(z)}catch{Z=[]}for(let H of Z){if(!H.startsWith("run-")||!H.endsWith(".pid"))continue;let W=F(z,H);try{if(!f1(W).isFile())continue}catch{continue}let U=E0(H,".pid").slice(4),J=Z1(W);if(J!==null&&X1(J)){if(!Q.some((T)=>T.startsWith(`${U}:`)))Q.push(`${U}:${J}`)}}}return Q}async function g1(z,Q){let $=await w(["jq","-r",z,Q]);if($.exitCode!==0)return null;return $.stdout.trim()}function y1(z,Q){try{let $=z1(z,"utf-8"),Z=JSON.parse($)[Q];if(typeof Z==="number"){if(Q==="budget_used"){let H=Math.round(Z*100)/100;if(Number.isInteger(H))return String(H);return String(H)}return String(Z)}if(Z===void 0||Z===null)return"0";return String(Z)}catch{return"0"}}function h1(z,Q,$){try{let X=z1(z,"utf-8"),H=JSON.parse(X)[Q];if(typeof H==="number"&&Number.isFinite(H))return H;return $}catch{return $}}async function f0(){let z=C();if(!await b0())return 1;if(!L(z))return process.stdout.write(`${x}Loki Mode Status${K}
8
8
  `),process.stdout.write(`
9
- `),process.stdout.write(`${T}No active session found.${K}
9
+ `),process.stdout.write(`${_}No active session found.${K}
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:
@@ -16,40 +16,40 @@ var Q0=Object.defineProperty;var X0=(z)=>z;function Z0(z,Q){this[z]=X0.bind(null
16
16
  `),process.stdout.write(`${A}Current directory: ${process.cwd()}${K}
17
17
  `),0;process.stdout.write(`${x}Loki Mode Status${K}
18
18
  `),process.stdout.write(`
19
- `);let Q="",$=F(z,"state","provider");if(L($))try{Q=e($,"utf-8").trim()}catch{Q=""}let X=Q||process.env.LOKI_PROVIDER||"claude",Z="full features";switch(X){case"codex":case"gemini":case"aider":Z="degraded mode";break;case"cline":Z="near-full mode";break;default:Z="full features";break}process.stdout.write(`${G}Provider:${K} ${X} (${Z})
19
+ `);let Q="",$=F(z,"state","provider");if(L($))try{Q=z1($,"utf-8").trim()}catch{Q=""}let X=Q||process.env.LOKI_PROVIDER||"claude",Z="full features";switch(X){case"codex":case"gemini":case"aider":Z="degraded mode";break;case"cline":Z="near-full mode";break;default:Z="full features";break}process.stdout.write(`${G}Provider:${K} ${X} (${Z})
20
20
  `),process.stdout.write(`${A} Switch with: loki provider set <claude|codex|gemini|cline|aider>${K}
21
21
  `),process.stdout.write(`
22
- `);let H=C0(z);if(H.length>0){process.stdout.write(`${P}Active Sessions: ${H.length}${K}
23
- `);for(let U of H){let Y=U.indexOf(":"),V=Y>=0?U.slice(0,Y):U,_=Y>=0?U.slice(Y+1):"";if(V==="global")process.stdout.write(` ${G}[global]${K} PID ${_}
24
- `);else process.stdout.write(` ${G}[#${V}]${K} PID ${_}
22
+ `);let H=C0(z);if(H.length>0){process.stdout.write(`${k}Active Sessions: ${H.length}${K}
23
+ `);for(let B of H){let M=B.indexOf(":"),I=M>=0?B.slice(0,M):B,N=M>=0?B.slice(M+1):"";if(I==="global")process.stdout.write(` ${G}[global]${K} PID ${N}
24
+ `);else process.stdout.write(` ${G}[#${I}]${K} PID ${N}
25
25
  `)}process.stdout.write(`
26
26
  `),process.stdout.write(`${A} Stop specific: loki stop <session-id>${K}
27
27
  `),process.stdout.write(`${A} Stop all: loki stop${K}
28
28
  `),process.stdout.write(`
29
- `)}if(L(F(z,"PAUSE")))process.stdout.write(`${T}Status: PAUSED${K}
29
+ `)}if(L(F(z,"PAUSE")))process.stdout.write(`${_}Status: PAUSED${K}
30
30
  `),process.stdout.write(`${A} Resume with: loki resume${K}
31
31
  `),process.stdout.write(`
32
- `);else if(L(F(z,"STOP")))process.stdout.write(`${S}Status: STOPPED${K}
32
+ `);else if(L(F(z,"STOP")))process.stdout.write(`${D}Status: STOPPED${K}
33
33
  `),process.stdout.write(`${A} Clear with: loki resume${K}
34
34
  `),process.stdout.write(`
35
35
  `);let W=F(z,"STATUS.txt");if(L(W)){process.stdout.write(`${G}Session Info:${K}
36
- `);try{process.stdout.write(e(W,"utf-8"))}catch{}process.stdout.write(`
37
- `)}let B=F(z,"state","orchestrator.json");if(L(B)){process.stdout.write(`${G}Orchestrator State:${K}
38
- `);let U=await g1('.currentPhase // "unknown"',B);process.stdout.write(`${U??"unknown"}
39
- `)}let j=F(z,"queue","pending.json");if(L(j)){let U=await g1('if type == "array" then length elif .tasks then .tasks | length else 0 end',j);process.stdout.write(`${G}Pending Tasks:${K} ${U??"0"}
40
- `)}let O=F(z,"metrics","budget.json");if(L(O)){let U=y1(O,"budget_limit"),Y=y1(O,"budget_used");if(U!=="0")process.stdout.write(`${G}Budget:${K} $${Y} / $${U}
41
- `);else process.stdout.write(`${G}Cost:${K} $${Y} (no limit)
42
- `)}let I=F(z,"state","context-usage.json");if(L(I)){let U=h1(I,"window_size",200000),Y=h1(I,"used_tokens",0),V=0;if(U>0)V=Math.floor(Y*100/U);process.stdout.write(`${G}Context:${K} ${V}% (${Y} / ${U} tokens)
43
- `)}let D=F(z,"dashboard","dashboard.pid");if(L(D)){let U=Z1(D);if(U!==null&&X1(U)){let Y=process.env.LOKI_DASHBOARD_PORT||"57374";process.stdout.write(`${G}Dashboard:${K} http://127.0.0.1:${Y}/
36
+ `);try{process.stdout.write(z1(W,"utf-8"))}catch{}process.stdout.write(`
37
+ `)}let U=F(z,"state","orchestrator.json");if(L(U)){process.stdout.write(`${G}Orchestrator State:${K}
38
+ `);let B=await g1('.currentPhase // "unknown"',U);process.stdout.write(`${B??"unknown"}
39
+ `)}let J=F(z,"queue","pending.json");if(L(J)){let B=await g1('if type == "array" then length elif .tasks then .tasks | length else 0 end',J);process.stdout.write(`${G}Pending Tasks:${K} ${B??"0"}
40
+ `)}let O=F(z,"metrics","budget.json");if(L(O)){let B=y1(O,"budget_limit"),M=y1(O,"budget_used");if(B!=="0")process.stdout.write(`${G}Budget:${K} $${M} / $${B}
41
+ `);else process.stdout.write(`${G}Cost:${K} $${M} (no limit)
42
+ `)}let T=F(z,"state","context-usage.json");if(L(T)){let B=h1(T,"window_size",200000),M=h1(T,"used_tokens",0),I=0;if(B>0)I=Math.floor(M*100/B);process.stdout.write(`${G}Context:${K} ${I}% (${M} / ${B} tokens)
43
+ `)}let E=F(z,"dashboard","dashboard.pid");if(L(E)){let B=Z1(E);if(B!==null&&X1(B)){let M=process.env.LOKI_DASHBOARD_PORT||"57374";process.stdout.write(`${G}Dashboard:${K} http://127.0.0.1:${M}/
44
44
  `)}}return process.stdout.write(`
45
45
  `),process.stdout.write(`${A} Tip: loki context show - detailed token breakdown${K}
46
46
  `),process.stdout.write(`${A} Tip: loki code overview - codebase intelligence${K}
47
- `),0}async function g0(){let z=await a();if(!z)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
48
- `),1;let Q=y,$=b(),X=process.env.LOKI_DASHBOARD_PORT||"57374",Z=process.env.LOKI_PROVIDER||"claude",H=await w([z,"-c",b0,Q,$,X,Z],{timeoutMs:30000});if(H.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
47
+ `),0}async function g0(){let z=await s();if(!z)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
48
+ `),1;let Q=v,$=C(),X=process.env.LOKI_DASHBOARD_PORT||"57374",Z=process.env.LOKI_PROVIDER||"claude",H=await w([z,"-c",N0,Q,$,X,Z],{timeoutMs:30000});if(H.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
49
49
  `),1;return process.stdout.write(H.stdout),0}async function y0(z){let Q=[...z];while(Q.length>0){let $=Q[0];if($==="--json")return g0();if($==="--help"||$==="-h")return process.stdout.write(`Usage: loki status [--json]
50
- `),0;return process.stdout.write(`${S}Unknown flag: ${$}${K}
50
+ `),0;return process.stdout.write(`${D}Unknown flag: ${$}${K}
51
51
  `),process.stdout.write(`Usage: loki status [--json]
52
- `),1}return f0()}var b0=`
52
+ `),1}return f0()}var N0=`
53
53
  import json, os, sys, time
54
54
 
55
55
  skill_dir = sys.argv[1]
@@ -195,9 +195,9 @@ if os.path.isdir(queue_dir):
195
195
  result['task_counts'] = task_counts
196
196
 
197
197
  print(json.dumps(result, indent=2))
198
- `;var m1=g(()=>{m();Q1();p();h()});var l1={};r(l1,{runStats:()=>c0,computeStats:()=>c1});import{readdirSync as u1,readFileSync as h0,statSync as p1}from"fs";import{join as C}from"path";function l(z){try{if(!p1(z).isFile())return null;return JSON.parse(h0(z,"utf-8"))}catch{return null}}function M1(z){try{return p1(z).isDirectory()}catch{return!1}}function v0(z){if(!M1(z))return[];try{let Q=u1(z).filter(($)=>$.startsWith("iteration-")&&$.endsWith(".json"));return Q.sort(),Q.map(($)=>C(z,$))}catch{return[]}}function d(z){return Math.trunc(z).toLocaleString("en-US")}function J1(z){let Q=Math.trunc(z);if(Q<60)return`${Q}s`;let $=Math.trunc(Q/3600),X=Math.trunc(Q%3600/60),Z=Q%60;if($>0)return`${$}h ${String(X).padStart(2,"0")}m`;return`${X}m ${String(Z).padStart(2,"0")}s`}function f(z,Q=0){let $=Math.pow(10,Q);return Math.round(z*$)/$}function o(z,Q){return z.toFixed(Q)}function j1(z,Q){return z.length>=Q?z:z+" ".repeat(Q-z.length)}function m0(z){let Q="N/A",$=0,X=l(C(z,"state","orchestrator.json"));if(X&&typeof X==="object"){if(typeof X.currentPhase==="string")Q=X.currentPhase;if(typeof X.currentIteration==="number")$=X.currentIteration}let Z=C(z,"metrics","efficiency"),H=v0(Z),W=[];for(let q of H){let M=l(q);if(M&&typeof M==="object")W.push(M)}if(W.length>0)$=Math.max($,W.length);let B=W.reduce((q,M)=>q+(M.input_tokens??0),0),j=W.reduce((q,M)=>q+(M.output_tokens??0),0),O=B+j,I=W.reduce((q,M)=>q+(M.cost_usd??0),0),D=W.reduce((q,M)=>q+(M.duration_seconds??0),0),U=0,Y=0,V=l(C(z,"metrics","budget.json"));if(V&&typeof V==="object"){if(typeof V.budget_limit==="number")U=V.budget_limit;if(typeof V.budget_used==="number")Y=V.budget_used}let _=0,z1=0,n=l(C(z,"state","quality-gates.json"));if(n&&typeof n==="object"){if(Array.isArray(n)){for(let q of n)if(z1+=1,q===!0)_+=1;else if(q&&typeof q==="object"){let M=q;if(M.passed===!0||M.status==="passed")_+=1}}else for(let q of Object.values(n))if(typeof q==="boolean"){if(z1+=1,q)_+=1}else if(q&&typeof q==="object"){z1+=1;let M=q;if(M.passed===!0||M.status==="passed")_+=1}}let _1={},$1=l(C(z,"quality","gate-failure-count.json"));if($1&&typeof $1==="object"&&!Array.isArray($1)){let q={};for(let[M,E]of Object.entries($1))if(typeof E==="number")q[M]=E;_1=q}let T1=0,I1=0,w1=0,W1=C(z,"quality");if(M1(W1)){let q=[];try{q=u1(W1)}catch{q=[]}for(let M of q){if(!M.endsWith(".json")||M==="gate-failure-count.json")continue;let E=l(C(W1,M));if(!E||typeof E!=="object")continue;if(!(("verdict"in E)||("approved"in E)||("reviewers"in E)))continue;T1+=1;let F1=(E.verdict??"").toString().toLowerCase();if(E.approved===!0||["approved","approve","pass"].includes(F1))I1+=1;else if(["revision","revise","changes_requested","reject"].includes(F1))w1+=1}}return{phase:Q,iterationCount:$,iterations:W,totalInput:B,totalOutput:j,totalTokens:O,totalCost:I,totalDuration:D,budgetLimit:U,budgetUsed:Y,gatesPassed:_,gatesTotal:z1,gateFailures:_1,reviewsTotal:T1,reviewsApproved:I1,reviewsRevision:w1}}function u0(z,Q){let $=z.iterationCount,X={session:{iterations:$,duration_seconds:z.totalDuration,phase:z.phase},tokens:{input:z.totalInput,output:z.totalOutput,total:z.totalTokens,cost_usd:f(z.totalCost,2)},quality:{gates_passed:z.gatesPassed,gates_total:z.gatesTotal,reviews_total:z.reviewsTotal,reviews_approved:z.reviewsApproved,reviews_revision:z.reviewsRevision,gate_failures:z.gateFailures},efficiency:{avg_tokens_per_iteration:$>0?f(z.totalTokens/$,0):0,avg_cost_per_iteration:$>0?f(z.totalCost/$,2):0,avg_duration_per_iteration:$>0?f(z.totalDuration/$,1):0},budget:{used:f(z.budgetUsed,2),limit:z.budgetLimit,percent:z.budgetLimit>0?f(z.budgetUsed/z.budgetLimit*100,1):0}};if(Q)X.iterations=z.iterations.map((W,B)=>({number:B+1,input_tokens:W.input_tokens??0,output_tokens:W.output_tokens??0,cost_usd:f(W.cost_usd??0,2),duration_seconds:W.duration_seconds??0}));let Z=JSON.stringify(X,null,2);function H(W,B){if(!B)return;let j=new RegExp(`("${W}": )(-?\\d+)(,?)$`,"m");Z=Z.replace(j,(O,I,D,U)=>`${I}${D}.0${U}`)}if(H("avg_duration_per_iteration",$>0&&Number.isInteger(X.efficiency.avg_duration_per_iteration)),H("percent",z.budgetLimit>0&&Number.isInteger(X.budget.percent)),H("cost_usd",$>0&&Number.isInteger(X.tokens.cost_usd)),Q)Z=Z.replace(/("cost_usd": )(-?\d+)(,?)$/gm,(W,B,j,O)=>`${B}${j}.0${O}`);return Z}function p0(z,Q){let $=[];if($.push("Loki Mode Session Statistics"),$.push("============================"),$.push(""),$.push("Session"),$.push(` Iterations completed: ${z.iterationCount}`),$.push(` Duration: ${J1(z.totalDuration)}`),$.push(` Current phase: ${z.phase}`),$.push(""),$.push("Token Usage"),z.iterations.length>0)$.push(` Input tokens: ${d(z.totalInput)}`),$.push(` Output tokens: ${d(z.totalOutput)}`),$.push(` Total tokens: ${d(z.totalTokens)}`),$.push(` Estimated cost: $${o(z.totalCost,2)}`);else $.push(" N/A (no iteration metrics found)");if($.push(""),$.push("Quality Gates"),z.gatesTotal>0){let X=Math.round(z.gatesPassed/z.gatesTotal*100);$.push(` Gates passed: ${z.gatesPassed}/${z.gatesTotal} (${X}%)`)}else $.push(" Gates passed: N/A");if(z.reviewsTotal>0){let X=[];if(z.reviewsApproved>0)X.push(`${z.reviewsApproved} approved`);if(z.reviewsRevision>0)X.push(`${z.reviewsRevision} revision requested`);let Z=X.length>0?X.join(", "):"N/A";$.push(` Code reviews: ${z.reviewsTotal} (${Z})`)}if(Object.keys(z.gateFailures).length>0){let X=Object.entries(z.gateFailures).filter(([,Z])=>Z>0).map(([Z,H])=>`${Z} (${H})`);if(X.length>0)$.push(` Gate failures: ${X.join(", ")}`)}if($.push(""),$.push("Efficiency"),z.iterationCount>0&&z.iterations.length>0){let X=Math.round(z.totalTokens/z.iterationCount),Z=z.totalCost/z.iterationCount,H=z.totalDuration/z.iterationCount;$.push(` Avg tokens/iteration: ${d(X)}`),$.push(` Avg cost/iteration: $${o(Z,2)}`),$.push(` Avg duration/iteration: ${J1(H)}`)}else $.push(" N/A (no iteration metrics found)");if($.push(""),$.push("Budget"),z.budgetLimit>0){let X=f(z.budgetUsed/z.budgetLimit*100,1),Z=Number.isInteger(X)?`${X}.0`:`${X}`;$.push(` Used: $${o(z.budgetUsed,2)} / $${o(z.budgetLimit,2)} (${Z}%)`)}else if(z.budgetUsed>0)$.push(` Used: $${o(z.budgetUsed,2)} (no limit set)`);else $.push(" N/A");if(Q&&z.iterations.length>0)$.push(""),$.push("Per-Iteration Breakdown"),z.iterations.forEach((X,Z)=>{let H=Z+1,W=j1(d(X.input_tokens??0),10),B=j1(d(X.output_tokens??0),10),j=X.cost_usd??0,O=J1(X.duration_seconds??0),I=j1(`${H}`,3);$.push(` #${I} input: ${W} output: ${B} cost: $${o(j,2)} time: ${O}`)});return $.join(`
199
- `)}function c1(z){let Q=!1,$=!1;for(let W of z)if(W==="--json")Q=!0;else if(W==="--efficiency")$=!0;let X=b();if(!M1(X)){if(Q)return{exitCode:0,stdout:'{"error": "No active session"}'};return{exitCode:0,stdout:`${T}No active session found.${K}
200
- Start a session with: loki start <prd>`}}let Z=m0(X);return{exitCode:0,stdout:Q?u0(Z,$):p0(Z,$)}}async function c0(z){let Q=c1(z);return console.log(Q.stdout),Q.exitCode}var d1=g(()=>{h();p()});var e1={};r(e1,{runDoctor:()=>$3,httpReachable:()=>A1,checkTool:()=>t1,checkSkills:()=>a1,checkDisk:()=>O1,buildDoctorJson:()=>i1});import{existsSync as l0,lstatSync as d0,readlinkSync as o0,statfsSync as n0}from"fs";import{homedir as n1}from"os";import{resolve as o1}from"path";function t0(z){let Q=z.match(r0);return Q?Q[1]:null}async function a0(z){try{let Q=await w([z,"--version"],{timeoutMs:5000}),$=(Q.stdout||Q.stderr||"").trim();return t0($)}catch{return null}}function r1(z,Q){let $=z.split(".").map((Z)=>parseInt(Z,10)),X=Q.split(".").map((Z)=>parseInt(Z,10));while($.length<2)$.push(0);while(X.length<2)X.push(0);for(let Z=0;Z<2;Z++){let H=$[Z]??0,W=X[Z]??0;if(Number.isNaN(H)||Number.isNaN(W))return 0;if(H!==W)return H-W}return 0}async function t1(z,Q,$,X=null){let Z=await R(Q),H=Z!==null,W=H?await a0(Q):null,B="pass";if(!H)B=$==="required"?"fail":"warn";else if(X&&W){if(r1(W,X)<0)B=$==="required"?"fail":"warn"}return{name:z,command:Q,found:H,version:W,required:$,min_version:X,status:B,path:Z}}function O1(){let z=null;try{let $=n0(n1()),X=Number($.bavail)*Number($.bsize);z=Math.round(X/1073741824*10)/10}catch{z=null}let Q="pass";if(z!==null){if(z<1)Q="fail";else if(z<5)Q="warn"}return{available_gb:z,status:Q}}async function A1(z,Q=2000){try{return(await fetch(z,{signal:AbortSignal.timeout(Q)})).ok}catch{return!1}}async function Y1(z,Q=!1){let $=`import ${z}`,X=Q?30000:5000;if(!Q)return(await s($,{timeoutMs:X})).exitCode===0;let Z=await a();if(!Z)return!1;return(await w([Z,"-c",$],{timeoutMs:X})).exitCode===0}function a1(){let z=n1();return s0.map(({name:Q,dir:$})=>{let X=o1(z,$),Z=X,H=o1(X,"SKILL.md");if(l0(H))return{name:Q,path:Z,status:"pass",detail:""};try{if(d0(X).isSymbolicLink()){let B="unknown";try{B=o0(X)}catch{}return{name:Q,path:Z,status:"fail",detail:`(broken symlink -> ${B})`}}}catch{}return{name:Q,path:Z,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function s1(){return Promise.all(i0.map(async(z)=>{return{...await t1(z.jsonName,z.cmd,z.required,z.min??null),displayName:z.displayName}}))}async function i1(){let Q=(await s1()).map(({displayName:W,...B})=>B),$=O1(),X=0,Z=0,H=0;for(let W of Q)if(W.status==="pass")X++;else if(W.status==="fail")Z++;else H++;if($.status==="pass")X++;else if($.status==="fail")Z++;else H++;return{checks:Q,disk:$,summary:{passed:X,failed:Z,warnings:H,ok:Z===0}}}function J(z){switch(z){case"pass":return`${P}PASS${K}`;case"fail":return`${S}FAIL${K}`;case"warn":return`${T}WARN${K}`}}function K1(z){let Q=z.version?` (v${z.version})`:"",$=z.displayName;if(!z.found){let X=z.required==="required"?"not found":z.required==="recommended"?"not found (recommended)":"not found (optional)";return` ${J(z.status)} ${$} - ${X}`}if(z.min_version&&z.version&&r1(z.version,z.min_version)<0){let X=z.required==="required"?"requires":"recommended";return` ${J(z.status)} ${$}${Q} - ${X} >= ${z.min_version}`}return` ${J(z.status)} ${$}${Q}`}function H1(z,Q){if(Q==="pass")z.pass++;else if(Q==="fail")z.fail++;else z.warn++}function e0(){process.stdout.write(`${x}loki doctor${K} - Check system prerequisites
198
+ `;var m1=h(()=>{p();Q1();l();m()});var l1={};t(l1,{runStats:()=>c0,computeStats:()=>c1});import{readdirSync as u1,readFileSync as h0,statSync as p1}from"fs";import{join as g}from"path";function o(z){try{if(!p1(z).isFile())return null;return JSON.parse(h0(z,"utf-8"))}catch{return null}}function M1(z){try{return p1(z).isDirectory()}catch{return!1}}function v0(z){if(!M1(z))return[];try{let Q=u1(z).filter(($)=>$.startsWith("iteration-")&&$.endsWith(".json"));return Q.sort(),Q.map(($)=>g(z,$))}catch{return[]}}function n(z){return Math.trunc(z).toLocaleString("en-US")}function J1(z){let Q=Math.trunc(z);if(Q<60)return`${Q}s`;let $=Math.trunc(Q/3600),X=Math.trunc(Q%3600/60),Z=Q%60;if($>0)return`${$}h ${String(X).padStart(2,"0")}m`;return`${X}m ${String(Z).padStart(2,"0")}s`}function y(z,Q=0){let $=Math.pow(10,Q);return Math.round(z*$)/$}function r(z,Q){return z.toFixed(Q)}function j1(z,Q){return z.length>=Q?z:z+" ".repeat(Q-z.length)}function m0(z){let Q="N/A",$=0,X=o(g(z,"state","orchestrator.json"));if(X&&typeof X==="object"){if(typeof X.currentPhase==="string")Q=X.currentPhase;if(typeof X.currentIteration==="number")$=X.currentIteration}let Z=g(z,"metrics","efficiency"),H=v0(Z),W=[];for(let q of H){let j=o(q);if(j&&typeof j==="object")W.push(j)}if(W.length>0)$=Math.max($,W.length);let U=W.reduce((q,j)=>q+(j.input_tokens??0),0),J=W.reduce((q,j)=>q+(j.output_tokens??0),0),O=U+J,T=W.reduce((q,j)=>q+(j.cost_usd??0),0),E=W.reduce((q,j)=>q+(j.duration_seconds??0),0),B=0,M=0,I=o(g(z,"metrics","budget.json"));if(I&&typeof I==="object"){if(typeof I.budget_limit==="number")B=I.budget_limit;if(typeof I.budget_used==="number")M=I.budget_used}let N=0,Y=0,P=o(g(z,"state","quality-gates.json"));if(P&&typeof P==="object"){if(Array.isArray(P)){for(let q of P)if(Y+=1,q===!0)N+=1;else if(q&&typeof q==="object"){let j=q;if(j.passed===!0||j.status==="passed")N+=1}}else for(let q of Object.values(P))if(typeof q==="boolean"){if(Y+=1,q)N+=1}else if(q&&typeof q==="object"){Y+=1;let j=q;if(j.passed===!0||j.status==="passed")N+=1}}let _1={},$1=o(g(z,"quality","gate-failure-count.json"));if($1&&typeof $1==="object"&&!Array.isArray($1)){let q={};for(let[j,b]of Object.entries($1))if(typeof b==="number")q[j]=b;_1=q}let T1=0,I1=0,w1=0,W1=g(z,"quality");if(M1(W1)){let q=[];try{q=u1(W1)}catch{q=[]}for(let j of q){if(!j.endsWith(".json")||j==="gate-failure-count.json")continue;let b=o(g(W1,j));if(!b||typeof b!=="object")continue;if(!(("verdict"in b)||("approved"in b)||("reviewers"in b)))continue;T1+=1;let F1=(b.verdict??"").toString().toLowerCase();if(b.approved===!0||["approved","approve","pass"].includes(F1))I1+=1;else if(["revision","revise","changes_requested","reject"].includes(F1))w1+=1}}return{phase:Q,iterationCount:$,iterations:W,totalInput:U,totalOutput:J,totalTokens:O,totalCost:T,totalDuration:E,budgetLimit:B,budgetUsed:M,gatesPassed:N,gatesTotal:Y,gateFailures:_1,reviewsTotal:T1,reviewsApproved:I1,reviewsRevision:w1}}function u0(z,Q){let $=z.iterationCount,X={session:{iterations:$,duration_seconds:z.totalDuration,phase:z.phase},tokens:{input:z.totalInput,output:z.totalOutput,total:z.totalTokens,cost_usd:y(z.totalCost,2)},quality:{gates_passed:z.gatesPassed,gates_total:z.gatesTotal,reviews_total:z.reviewsTotal,reviews_approved:z.reviewsApproved,reviews_revision:z.reviewsRevision,gate_failures:z.gateFailures},efficiency:{avg_tokens_per_iteration:$>0?y(z.totalTokens/$,0):0,avg_cost_per_iteration:$>0?y(z.totalCost/$,2):0,avg_duration_per_iteration:$>0?y(z.totalDuration/$,1):0},budget:{used:y(z.budgetUsed,2),limit:z.budgetLimit,percent:z.budgetLimit>0?y(z.budgetUsed/z.budgetLimit*100,1):0}};if(Q)X.iterations=z.iterations.map((W,U)=>({number:U+1,input_tokens:W.input_tokens??0,output_tokens:W.output_tokens??0,cost_usd:y(W.cost_usd??0,2),duration_seconds:W.duration_seconds??0}));let Z=JSON.stringify(X,null,2);function H(W,U){if(!U)return;let J=new RegExp(`("${W}": )(-?\\d+)(,?)$`,"m");Z=Z.replace(J,(O,T,E,B)=>`${T}${E}.0${B}`)}if(H("avg_duration_per_iteration",$>0&&Number.isInteger(X.efficiency.avg_duration_per_iteration)),H("percent",z.budgetLimit>0&&Number.isInteger(X.budget.percent)),H("cost_usd",$>0&&Number.isInteger(X.tokens.cost_usd)),Q)Z=Z.replace(/("cost_usd": )(-?\d+)(,?)$/gm,(W,U,J,O)=>`${U}${J}.0${O}`);return Z}function p0(z,Q){let $=[];if($.push("Loki Mode Session Statistics"),$.push("============================"),$.push(""),$.push("Session"),$.push(` Iterations completed: ${z.iterationCount}`),$.push(` Duration: ${J1(z.totalDuration)}`),$.push(` Current phase: ${z.phase}`),$.push(""),$.push("Token Usage"),z.iterations.length>0)$.push(` Input tokens: ${n(z.totalInput)}`),$.push(` Output tokens: ${n(z.totalOutput)}`),$.push(` Total tokens: ${n(z.totalTokens)}`),$.push(` Estimated cost: $${r(z.totalCost,2)}`);else $.push(" N/A (no iteration metrics found)");if($.push(""),$.push("Quality Gates"),z.gatesTotal>0){let X=Math.round(z.gatesPassed/z.gatesTotal*100);$.push(` Gates passed: ${z.gatesPassed}/${z.gatesTotal} (${X}%)`)}else $.push(" Gates passed: N/A");if(z.reviewsTotal>0){let X=[];if(z.reviewsApproved>0)X.push(`${z.reviewsApproved} approved`);if(z.reviewsRevision>0)X.push(`${z.reviewsRevision} revision requested`);let Z=X.length>0?X.join(", "):"N/A";$.push(` Code reviews: ${z.reviewsTotal} (${Z})`)}if(Object.keys(z.gateFailures).length>0){let X=Object.entries(z.gateFailures).filter(([,Z])=>Z>0).map(([Z,H])=>`${Z} (${H})`);if(X.length>0)$.push(` Gate failures: ${X.join(", ")}`)}if($.push(""),$.push("Efficiency"),z.iterationCount>0&&z.iterations.length>0){let X=Math.round(z.totalTokens/z.iterationCount),Z=z.totalCost/z.iterationCount,H=z.totalDuration/z.iterationCount;$.push(` Avg tokens/iteration: ${n(X)}`),$.push(` Avg cost/iteration: $${r(Z,2)}`),$.push(` Avg duration/iteration: ${J1(H)}`)}else $.push(" N/A (no iteration metrics found)");if($.push(""),$.push("Budget"),z.budgetLimit>0){let X=y(z.budgetUsed/z.budgetLimit*100,1),Z=Number.isInteger(X)?`${X}.0`:`${X}`;$.push(` Used: $${r(z.budgetUsed,2)} / $${r(z.budgetLimit,2)} (${Z}%)`)}else if(z.budgetUsed>0)$.push(` Used: $${r(z.budgetUsed,2)} (no limit set)`);else $.push(" N/A");if(Q&&z.iterations.length>0)$.push(""),$.push("Per-Iteration Breakdown"),z.iterations.forEach((X,Z)=>{let H=Z+1,W=j1(n(X.input_tokens??0),10),U=j1(n(X.output_tokens??0),10),J=X.cost_usd??0,O=J1(X.duration_seconds??0),T=j1(`${H}`,3);$.push(` #${T} input: ${W} output: ${U} cost: $${r(J,2)} time: ${O}`)});return $.join(`
199
+ `)}function c1(z){let Q=!1,$=!1;for(let W of z)if(W==="--json")Q=!0;else if(W==="--efficiency")$=!0;let X=C();if(!M1(X)){if(Q)return{exitCode:0,stdout:'{"error": "No active session"}'};return{exitCode:0,stdout:`${_}No active session found.${K}
200
+ Start a session with: loki start <prd>`}}let Z=m0(X);return{exitCode:0,stdout:Q?u0(Z,$):p0(Z,$)}}async function c0(z){let Q=c1(z);return console.log(Q.stdout),Q.exitCode}var d1=h(()=>{m();l()});var e1={};t(e1,{runDoctor:()=>$3,httpReachable:()=>A1,checkTool:()=>t1,checkSkills:()=>a1,checkDisk:()=>O1,buildDoctorJson:()=>i1});import{existsSync as l0,lstatSync as d0,readlinkSync as o0,statfsSync as n0}from"fs";import{homedir as n1}from"os";import{resolve as o1}from"path";function t0(z){let Q=z.match(r0);return Q?Q[1]:null}async function a0(z){try{let Q=await w([z,"--version"],{timeoutMs:5000}),$=(Q.stdout||Q.stderr||"").trim();return t0($)}catch{return null}}function r1(z,Q){let $=z.split(".").map((Z)=>parseInt(Z,10)),X=Q.split(".").map((Z)=>parseInt(Z,10));while($.length<2)$.push(0);while(X.length<2)X.push(0);for(let Z=0;Z<2;Z++){let H=$[Z]??0,W=X[Z]??0;if(Number.isNaN(H)||Number.isNaN(W))return 0;if(H!==W)return H-W}return 0}async function t1(z,Q,$,X=null){let Z=await S(Q),H=Z!==null,W=H?await a0(Q):null,U="pass";if(!H)U=$==="required"?"fail":"warn";else if(X&&W){if(r1(W,X)<0)U=$==="required"?"fail":"warn"}return{name:z,command:Q,found:H,version:W,required:$,min_version:X,status:U,path:Z}}function O1(){let z=null;try{let $=n0(n1()),X=Number($.bavail)*Number($.bsize);z=Math.round(X/1073741824*10)/10}catch{z=null}let Q="pass";if(z!==null){if(z<1)Q="fail";else if(z<5)Q="warn"}return{available_gb:z,status:Q}}async function A1(z,Q=2000){try{return(await fetch(z,{signal:AbortSignal.timeout(Q)})).ok}catch{return!1}}async function Y1(z,Q=!1){let $=`import ${z}`,X=Q?30000:5000;if(!Q)return(await i($,{timeoutMs:X})).exitCode===0;let Z=await s();if(!Z)return!1;return(await w([Z,"-c",$],{timeoutMs:X})).exitCode===0}function a1(){let z=n1();return s0.map(({name:Q,dir:$})=>{let X=o1(z,$),Z=X,H=o1(X,"SKILL.md");if(l0(H))return{name:Q,path:Z,status:"pass",detail:""};try{if(d0(X).isSymbolicLink()){let U="unknown";try{U=o0(X)}catch{}return{name:Q,path:Z,status:"fail",detail:`(broken symlink -> ${U})`}}}catch{}return{name:Q,path:Z,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function s1(){return Promise.all(i0.map(async(z)=>{return{...await t1(z.jsonName,z.cmd,z.required,z.min??null),displayName:z.displayName}}))}async function i1(){let Q=(await s1()).map(({displayName:W,...U})=>U),$=O1(),X=0,Z=0,H=0;for(let W of Q)if(W.status==="pass")X++;else if(W.status==="fail")Z++;else H++;if($.status==="pass")X++;else if($.status==="fail")Z++;else H++;return{checks:Q,disk:$,summary:{passed:X,failed:Z,warnings:H,ok:Z===0}}}function V(z){switch(z){case"pass":return`${k}PASS${K}`;case"fail":return`${D}FAIL${K}`;case"warn":return`${_}WARN${K}`}}function K1(z){let Q=z.version?` (v${z.version})`:"",$=z.displayName;if(!z.found){let X=z.required==="required"?"not found":z.required==="recommended"?"not found (recommended)":"not found (optional)";return` ${V(z.status)} ${$} - ${X}`}if(z.min_version&&z.version&&r1(z.version,z.min_version)<0){let X=z.required==="required"?"requires":"recommended";return` ${V(z.status)} ${$}${Q} - ${X} >= ${z.min_version}`}return` ${V(z.status)} ${$}${Q}`}function H1(z,Q){if(Q==="pass")z.pass++;else if(Q==="fail")z.fail++;else z.warn++}function e0(){process.stdout.write(`${x}loki doctor${K} - Check system prerequisites
201
201
 
202
202
  `),process.stdout.write(`Usage: loki doctor [--json]
203
203
 
@@ -210,66 +210,72 @@ Start a session with: loki start <prd>`}}let Z=m0(X);return{exitCode:0,stdout:Q?
210
210
 
211
211
  `),process.stdout.write(`Checking system prerequisites...
212
212
 
213
- `);let z={pass:0,fail:0,warn:0},Q=await s1(),$=new Map(Q.map((V)=>[V.command,V]));process.stdout.write(`${G}Required:${K}
214
- `);for(let V of["node","python3","jq","git","curl"]){let _=$.get(V);process.stdout.write(K1(_)+`
215
- `),H1(z,_.status)}process.stdout.write(`
213
+ `);let z={pass:0,fail:0,warn:0},Q=await s1(),$=new Map(Q.map((Y)=>[Y.command,Y]));process.stdout.write(`${G}Required:${K}
214
+ `);for(let Y of["node","python3","jq","git","curl"]){let P=$.get(Y);process.stdout.write(K1(P)+`
215
+ `),H1(z,P.status)}process.stdout.write(`
216
216
  `),process.stdout.write(`${G}AI Providers:${K}
217
- `);let X=["claude","codex","gemini","cline","aider"],Z=!1;for(let V of X){let _=$.get(V);if(process.stdout.write(K1(_)+`
218
- `),H1(z,_.status),_.found)Z=!0}if(!Z)process.stdout.write(` ${J("fail")} No AI provider CLI installed -- at least one is required
219
- `),process.stdout.write(` ${T}Install: npm install -g @anthropic-ai/claude-code${K}
217
+ `);let X=["claude","codex","gemini","cline","aider"],Z=!1;for(let Y of X){let P=$.get(Y);if(process.stdout.write(K1(P)+`
218
+ `),H1(z,P.status),P.found)Z=!0}if(!Z)process.stdout.write(` ${V("fail")} No AI provider CLI installed -- at least one is required
219
+ `),process.stdout.write(` ${_}Install: npm install -g @anthropic-ai/claude-code${K}
220
220
  `),z.fail++;process.stdout.write(`
221
221
  `),process.stdout.write(`${G}API Keys:${K}
222
- `);let H=$.get("claude").found,W=$.get("codex").found,B=$.get("gemini").found,j=process.env;if(j.ANTHROPIC_API_KEY)process.stdout.write(` ${J("pass")} ANTHROPIC_API_KEY is set
222
+ `);let H=$.get("claude").found,W=$.get("codex").found,U=$.get("gemini").found,J=process.env;if(J.ANTHROPIC_API_KEY)process.stdout.write(` ${V("pass")} ANTHROPIC_API_KEY is set
223
223
  `),z.pass++;else if(H)process.stdout.write(` ${A} -- ${K} ANTHROPIC_API_KEY not set (Claude CLI uses its own login)
224
- `);if(j.OPENAI_API_KEY)process.stdout.write(` ${J("pass")} OPENAI_API_KEY is set
224
+ `);if(J.OPENAI_API_KEY)process.stdout.write(` ${V("pass")} OPENAI_API_KEY is set
225
225
  `),z.pass++;else if(W)process.stdout.write(` ${A} -- ${K} OPENAI_API_KEY not set (Codex CLI uses its own login)
226
- `);if(j.GOOGLE_API_KEY||j.GEMINI_API_KEY)process.stdout.write(` ${J("pass")} GOOGLE_API_KEY is set
227
- `),z.pass++;else if(B)process.stdout.write(` ${A} -- ${K} GOOGLE_API_KEY not set (Gemini CLI uses its own login)
226
+ `);if(J.GOOGLE_API_KEY||J.GEMINI_API_KEY)process.stdout.write(` ${V("pass")} GOOGLE_API_KEY is set
227
+ `),z.pass++;else if(U)process.stdout.write(` ${A} -- ${K} GOOGLE_API_KEY not set (Gemini CLI uses its own login)
228
228
  `);process.stdout.write(`
229
229
  `),process.stdout.write(`${G}Skills:${K}
230
- `);for(let V of a1())if(V.status==="pass")process.stdout.write(` ${J("pass")} ${V.name} ${A}${V.path}${K}
231
- `),z.pass++;else if(V.status==="fail")process.stdout.write(` ${J("fail")} ${V.name} ${A}${V.detail}${K}
232
- `),process.stdout.write(` ${T}Fix: loki setup-skill${K}
233
- `),z.fail++;else process.stdout.write(` ${J("warn")} ${V.name} ${A}${V.detail}${K}
230
+ `);for(let Y of a1())if(Y.status==="pass")process.stdout.write(` ${V("pass")} ${Y.name} ${A}${Y.path}${K}
231
+ `),z.pass++;else if(Y.status==="fail")process.stdout.write(` ${V("fail")} ${Y.name} ${A}${Y.detail}${K}
232
+ `),process.stdout.write(` ${_}Fix: loki setup-skill${K}
233
+ `),z.fail++;else process.stdout.write(` ${V("warn")} ${Y.name} ${A}${Y.detail}${K}
234
234
  `),z.warn++;if(process.stdout.write(`
235
235
  `),process.stdout.write(`${G}Integrations:${K}
236
- `),await Y1("mcp"))process.stdout.write(` ${J("pass")} MCP SDK (Python)
237
- `),z.pass++;else process.stdout.write(` ${J("warn")} MCP SDK - not installed (pip3 install mcp)
238
- `),z.warn++;if(await Y1("numpy",!0))process.stdout.write(` ${J("pass")} numpy (vector search)
239
- `),z.pass++;else process.stdout.write(` ${J("warn")} numpy - not installed (pip3 install numpy)
240
- `),z.warn++;if(await Y1("sentence_transformers",!0))process.stdout.write(` ${J("pass")} sentence-transformers (embeddings)
241
- `),z.pass++;else process.stdout.write(` ${J("warn")} sentence-transformers - not installed (loki memory vectors setup)
242
- `),z.warn++;if(await A1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${J("pass")} ChromaDB server (port 8100)
243
- `),z.pass++;else process.stdout.write(` ${J("warn")} ChromaDB - not running (docker start loki-chroma)
244
- `),z.warn++;let O=process.env.LOKI_MIROFISH_URL;if(O)if(await A1(`${O}/health`))process.stdout.write(` ${J("pass")} MiroFish server (${O})
245
- `),z.pass++;else process.stdout.write(` ${J("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
246
- `),z.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${J("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
247
- `),z.pass++;else process.stdout.write(` ${J("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
236
+ `),await Y1("mcp"))process.stdout.write(` ${V("pass")} MCP SDK (Python)
237
+ `),z.pass++;else process.stdout.write(` ${V("warn")} MCP SDK - not installed (pip3 install mcp)
238
+ `),z.warn++;if(await Y1("numpy",!0))process.stdout.write(` ${V("pass")} numpy (vector search)
239
+ `),z.pass++;else process.stdout.write(` ${V("warn")} numpy - not installed (pip3 install numpy)
240
+ `),z.warn++;if(await Y1("sentence_transformers",!0))process.stdout.write(` ${V("pass")} sentence-transformers (embeddings)
241
+ `),z.pass++;else process.stdout.write(` ${V("warn")} sentence-transformers - not installed (loki memory vectors setup)
242
+ `),z.warn++;if(await A1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${V("pass")} ChromaDB server (port 8100)
243
+ `),z.pass++;else process.stdout.write(` ${V("warn")} ChromaDB - not running (docker start loki-chroma)
244
+ `),z.warn++;let O=process.env.LOKI_MIROFISH_URL;if(O)if(await A1(`${O}/health`))process.stdout.write(` ${V("pass")} MiroFish server (${O})
245
+ `),z.pass++;else process.stdout.write(` ${V("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
246
+ `),z.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${V("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
247
+ `),z.pass++;else process.stdout.write(` ${V("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
248
248
  `),z.warn++;process.stdout.write(`
249
249
  `),process.stdout.write(`${G}System:${K}
250
- `);let I=$.get("bash");process.stdout.write(K1(I)+`
251
- `),H1(z,I.status);let D=$.get("bun");if(D)process.stdout.write(K1(D)+`
252
- `),H1(z,D.status);let U=O1(),Y=U.available_gb===null?null:Math.floor(U.available_gb);if(Y===null)process.stdout.write(` ${J("warn")} Disk space: unable to determine
253
- `),z.warn++;else if(U.status==="fail")process.stdout.write(` ${J("fail")} Disk space: ${Y}GB available (need >= 1GB)
254
- `),z.fail++;else if(U.status==="warn")process.stdout.write(` ${J("warn")} Disk space: ${Y}GB available (low)
255
- `),z.warn++;else process.stdout.write(` ${J("pass")} Disk space: ${Y}GB available
256
- `),z.pass++;if(process.stdout.write(`
257
- `),process.stdout.write(`${x}Summary:${K} ${P}${z.pass} passed${K}, ${S}${z.fail} failed${K}, ${T}${z.warn} warnings${K}
250
+ `);let T=$.get("bash");process.stdout.write(K1(T)+`
251
+ `),H1(z,T.status);let E=$.get("bun");if(E)process.stdout.write(K1(E)+`
252
+ `),H1(z,E.status);let B=O1(),M=B.available_gb===null?null:Math.floor(B.available_gb);if(M===null)process.stdout.write(` ${V("warn")} Disk space: unable to determine
253
+ `),z.warn++;else if(B.status==="fail")process.stdout.write(` ${V("fail")} Disk space: ${M}GB available (need >= 1GB)
254
+ `),z.fail++;else if(B.status==="warn")process.stdout.write(` ${V("warn")} Disk space: ${M}GB available (low)
255
+ `),z.warn++;else process.stdout.write(` ${V("pass")} Disk space: ${M}GB available
256
+ `),z.pass++;process.stdout.write(`
257
+ `),process.stdout.write(`${G}Runtime route:${K}
258
+ `);let I=process.versions.bun!==void 0,N=process.argv[0]??"(unknown)";if(process.stdout.write(` ${V("pass")} Active runtime: ${I?"Bun":"Node"} (${N})
259
+ `),process.env.LOKI_LEGACY_BASH==="1"||process.env.LOKI_LEGACY_BASH==="true")process.stdout.write(` ${V("warn")} LOKI_LEGACY_BASH set: shim routes every command to autonomy/loki (bash)
260
+ `);if(process.env.LOKI_TS_ENTRY)process.stdout.write(` ${V("pass")} LOKI_TS_ENTRY override: ${process.env.LOKI_TS_ENTRY}
261
+ `);if(process.env.BUN_FROM_SOURCE==="1"||process.env.BUN_FROM_SOURCE==="true")process.stdout.write(` ${V("pass")} BUN_FROM_SOURCE set: shim prefers loki-ts/src/ over dist/
262
+ `);if(process.stdout.write(`
263
+ `),process.stdout.write(`${x}Summary:${K} ${k}${z.pass} passed${K}, ${D}${z.fail} failed${K}, ${_}${z.warn} warnings${K}
258
264
 
259
- `),z.fail>0)return process.stdout.write(`${S}Some required prerequisites are missing.${K}
265
+ `),z.fail>0)return process.stdout.write(`${D}Some required prerequisites are missing.${K}
260
266
  `),process.stdout.write(`Install missing dependencies and run 'loki doctor' again.
261
- `),1;if(z.warn>0)return process.stdout.write(`${T}All required checks passed with some warnings.${K}
262
- `),0;return process.stdout.write(`${P}All checks passed. System is ready for Loki Mode.${K}
263
- `),0}async function $3(z){let Q=!1;for(let $ of z)if($==="--json")Q=!0;else if($==="--help"||$==="-h")return e0(),0;else return process.stderr.write(`${S}Unknown option: ${$}${K}
267
+ `),1;if(z.warn>0)return process.stdout.write(`${_}All required checks passed with some warnings.${K}
268
+ `),0;return process.stdout.write(`${k}All checks passed. System is ready for Loki Mode.${K}
269
+ `),0}async function $3(z){let Q=!1;for(let $ of z)if($==="--json")Q=!0;else if($==="--help"||$==="-h")return e0(),0;else return process.stderr.write(`${D}Unknown option: ${$}${K}
264
270
  `),process.stderr.write(`Usage: loki doctor [--json]
265
271
  `),1;if(Q){let $=await i1();return process.stdout.write(JSON.stringify($,null,2)+`
266
- `),0}return z3()}var r0,s0,i0;var z0=g(()=>{m();Q1();p();r0=/(\d+\.\d+(?:\.\d+)*)/;s0=[{name:"Claude Code",dir:".claude/skills/loki-mode"},{name:"Codex CLI",dir:".codex/skills/loki-mode"},{name:"Gemini CLI",dir:".gemini/skills/loki-mode"},{name:"Cline CLI",dir:".cline/skills/loki-mode"},{name:"Aider CLI",dir:".aider/skills/loki-mode"}];i0=[{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:"Gemini CLI",jsonName:"Gemini CLI",cmd:"gemini",required:"optional"},{displayName:"Cline CLI",jsonName:"Cline CLI",cmd:"cline",required:"optional"},{displayName:"Aider CLI",jsonName:"Aider CLI",cmd:"aider",required:"optional"}]});h();import{readFileSync as U0}from"fs";import{resolve as V0,dirname as q0}from"path";import{fileURLToPath as G0}from"url";var v=null;function k1(){if(v!==null)return v;let z="7.5.0";if(typeof z==="string"&&z.length>0)return v=z,v;try{let Q=q0(G0(import.meta.url)),$=U1(Q);v=U0(V0($,"VERSION"),"utf-8").trim()}catch{v="unknown"}return v}function R1(){return process.stdout.write(`Loki Mode v${k1()}
267
- `),0}m();p();h();import{readFileSync as A0,existsSync as O0}from"fs";import{resolve as _0}from"path";var T0=["claude","codex","gemini","cline","aider"];function D1(){let z=_0(b(),"state","provider");if(!O0(z))return"";try{return A0(z,"utf-8").trim()}catch{return""}}function I0(z,Q){return z||Q||process.env.LOKI_PROVIDER||"claude"}function w0(z){let Q=D1(),$=I0(z,Q);switch(process.stdout.write(`${x}Current Provider${K}
272
+ `),0}return z3()}var r0,s0,i0;var z0=h(()=>{p();Q1();l();r0=/(\d+\.\d+(?:\.\d+)*)/;s0=[{name:"Claude Code",dir:".claude/skills/loki-mode"},{name:"Codex CLI",dir:".codex/skills/loki-mode"},{name:"Gemini CLI",dir:".gemini/skills/loki-mode"},{name:"Cline CLI",dir:".cline/skills/loki-mode"},{name:"Aider CLI",dir:".aider/skills/loki-mode"}];i0=[{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:"Gemini CLI",jsonName:"Gemini CLI",cmd:"gemini",required:"optional"},{displayName:"Cline CLI",jsonName:"Cline CLI",cmd:"cline",required:"optional"},{displayName:"Aider CLI",jsonName:"Aider CLI",cmd:"aider",required:"optional"}]});m();import{readFileSync as V0}from"fs";import{resolve as B0,dirname as q0}from"path";import{fileURLToPath as G0}from"url";var u=null;function k1(){if(u!==null)return u;let z="7.5.1";if(typeof z==="string"&&z.length>0)return u=z,u;try{let Q=q0(G0(import.meta.url)),$=V1(Q);u=V0(B0($,"VERSION"),"utf-8").trim()}catch{u="unknown"}return u}function R1(){return process.stdout.write(`Loki Mode v${k1()}
273
+ `),0}p();l();m();import{readFileSync as A0,existsSync as O0}from"fs";import{resolve as _0}from"path";var T0=["claude","codex","gemini","cline","aider"];function D1(){let z=_0(C(),"state","provider");if(!O0(z))return"";try{return A0(z,"utf-8").trim()}catch{return""}}function I0(z,Q){return z||Q||process.env.LOKI_PROVIDER||"claude"}function w0(z){let Q=D1(),$=I0(z,Q);switch(process.stdout.write(`${x}Current Provider${K}
268
274
  `),process.stdout.write(`
269
275
  `),process.stdout.write(`${G}Provider:${K} ${$}
270
- `),$){case"claude":process.stdout.write(`${P}Status:${K} Full features (subagents, parallel, MCP)
271
- `);break;case"cline":process.stdout.write(`${P}Status:${K} Near-full mode (subagents, MCP, 12+ providers)
272
- `);break;case"codex":case"gemini":case"aider":process.stdout.write(`${T}Status:${K} Degraded mode (sequential only)
276
+ `),$){case"claude":process.stdout.write(`${k}Status:${K} Full features (subagents, parallel, MCP)
277
+ `);break;case"cline":process.stdout.write(`${k}Status:${K} Near-full mode (subagents, MCP, 12+ providers)
278
+ `);break;case"codex":case"gemini":case"aider":process.stdout.write(`${_}Status:${K} Degraded mode (sequential only)
273
279
  `);break;default:break}if(Q)process.stdout.write(`${A}(saved in .loki/state/provider)${K}
274
280
  `);else process.stdout.write(`${A}(default - not explicitly set)${K}
275
281
  `);return process.stdout.write(`
@@ -277,7 +283,7 @@ Start a session with: loki start <prd>`}}let Z=m0(X);return{exitCode:0,stdout:Q?
277
283
  `),process.stdout.write(`Available: ${G}loki provider list${K}
278
284
  `),0}async function F0(){let Q=D1()||process.env.LOKI_PROVIDER||"claude";process.stdout.write(`${x}Available Providers${K}
279
285
  `),process.stdout.write(`
280
- `);let $=await Promise.all(T0.map(async(H)=>[H,await R(H)!==null])),X=new Map;for(let[H,W]of $)X.set(H,W?`${P}installed${K}`:`${S}not installed${K}`);let Z=[["claude","claude - Claude Code (Anthropic) "],["codex","codex - Codex CLI (OpenAI) "],["gemini","gemini - Gemini CLI (Google) "],["cline","cline - Cline (multi-provider) "],["aider","aider - Aider (terminal pair prog) "]];for(let[H,W]of Z){let B=Q===H?` ${G}(current)${K}`:"";process.stdout.write(` ${W} ${X.get(H)}${B}
286
+ `);let $=await Promise.all(T0.map(async(H)=>[H,await S(H)!==null])),X=new Map;for(let[H,W]of $)X.set(H,W?`${k}installed${K}`:`${D}not installed${K}`);let Z=[["claude","claude - Claude Code (Anthropic) "],["codex","codex - Codex CLI (OpenAI) "],["gemini","gemini - Gemini CLI (Google) "],["cline","cline - Cline (multi-provider) "],["aider","aider - Aider (terminal pair prog) "]];for(let[H,W]of Z){let U=Q===H?` ${G}(current)${K}`:"";process.stdout.write(` ${W} ${X.get(H)}${U}
281
287
  `)}return process.stdout.write(`
282
288
  `),process.stdout.write(`Set provider: ${G}loki provider set <name>${K}
283
289
  `),0}function x0(){return process.stdout.write(`${x}Loki Mode Provider Management${K}
@@ -298,14 +304,14 @@ Start a session with: loki start <prd>`}}let Z=m0(X);return{exitCode:0,stdout:Q?
298
304
  `),process.stdout.write(` loki provider list
299
305
  `),process.stdout.write(` loki provider info gemini
300
306
  `),process.stdout.write(` loki provider models
301
- `),0}async function E1(z){let Q=z[0]??"show",$=z.slice(1);switch(Q){case"show":case"current":return w0($[0]);case"list":return F0();case"set":case"info":case"models":return L0(["provider",Q,...$]);default:return x0()}}async function L0(z){let{run:Q}=await Promise.resolve().then(() => (m(),S1)),{resolve:$}=await import("path"),{REPO_ROOT:X}=await Promise.resolve().then(() => (h(),P1)),Z=$(X,"autonomy","loki"),H=await Q([Z,...z],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(H.stdout),process.stderr.write(H.stderr),H.exitCode}p();h();Q1();m();import{existsSync as b1,readFileSync as k0}from"fs";import{resolve as c}from"path";import{mkdir as R0}from"fs/promises";var i=c(V1(),"learnings");function G1(z){if(!b1(z))return 0;try{let Q=k0(z,"utf-8"),$=0;for(let X of Q.split(`
302
- `))if(X.includes('"description"'))$++;return $}catch{return 0}}async function S0(){await R0(i,{recursive:!0});let z=G1(c(i,"patterns.jsonl")),Q=G1(c(i,"mistakes.jsonl")),$=G1(c(i,"successes.jsonl"));return process.stdout.write(`${x}Cross-Project Learnings${K}
307
+ `),0}async function E1(z){let Q=z[0]??"show",$=z.slice(1);switch(Q){case"show":case"current":return w0($[0]);case"list":return F0();case"set":case"info":case"models":return L0(["provider",Q,...$]);default:return x0()}}async function L0(z){let{run:Q}=await Promise.resolve().then(() => (p(),S1)),{resolve:$}=await import("path"),{REPO_ROOT:X}=await Promise.resolve().then(() => (m(),P1)),Z=$(X,"autonomy","loki"),H=await Q([Z,...z],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(H.stdout),process.stderr.write(H.stderr),H.exitCode}l();m();Q1();p();import{existsSync as N1,readFileSync as k0}from"fs";import{resolve as d}from"path";import{mkdir as R0}from"fs/promises";var e=d(B1(),"learnings");function G1(z){if(!N1(z))return 0;try{let Q=k0(z,"utf-8"),$=0;for(let X of Q.split(`
308
+ `))if(X.includes('"description"'))$++;return $}catch{return 0}}async function S0(){await R0(e,{recursive:!0});let z=G1(d(e,"patterns.jsonl")),Q=G1(d(e,"mistakes.jsonl")),$=G1(d(e,"successes.jsonl"));return process.stdout.write(`${x}Cross-Project Learnings${K}
303
309
  `),process.stdout.write(`
304
- `),process.stdout.write(` Patterns: ${P}${z}${K}
305
- `),process.stdout.write(` Mistakes: ${T}${Q}${K}
310
+ `),process.stdout.write(` Patterns: ${k}${z}${K}
311
+ `),process.stdout.write(` Mistakes: ${_}${Q}${K}
306
312
  `),process.stdout.write(` Successes: ${G}${$}${K}
307
313
  `),process.stdout.write(`
308
- `),process.stdout.write(`Location: ${i}
314
+ `),process.stdout.write(`Location: ${e}
309
315
  `),process.stdout.write(`
310
316
  `),process.stdout.write(`Use 'loki memory show <type>' to view entries
311
317
  `),0}async function D0(z){if(z){let X=`
@@ -318,9 +324,9 @@ except ImportError:
318
324
  print('Error: memory.layers module not found')
319
325
  except Exception as e:
320
326
  print(f'Error: {e}')
321
- `.trim(),Z=await s(X,{cwd:y});return process.stdout.write(Z.stdout),0}let Q=c(b(),"memory","index.json");if(!b1(Q))return process.stdout.write(`No index found
322
- `),0;let $=await s(`import json, sys; sys.stdout.write(json.dumps(json.load(open(${JSON.stringify(Q)})), indent=4) + "\\n")`);if($.exitCode!==0)return process.stdout.write(`No index found
323
- `),0;return process.stdout.write($.stdout),0}async function N1(z){switch(z[0]??"list"){case"list":case"ls":return S0();case"index":return D0(z[1]==="rebuild");default:{let $=c(y,"autonomy","loki"),X=await w([$,"memory",...z],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(X.stdout),process.stderr.write(X.stderr),X.exitCode}}}var $0=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
327
+ `.trim(),Z=await i(X,{cwd:v});return process.stdout.write(Z.stdout),0}let Q=d(C(),"memory","index.json");if(!N1(Q))return process.stdout.write(`No index found
328
+ `),0;let $=await i(`import json, sys; sys.stdout.write(json.dumps(json.load(open(${JSON.stringify(Q)})), indent=4) + "\\n")`);if($.exitCode!==0)return process.stdout.write(`No index found
329
+ `),0;return process.stdout.write($.stdout),0}async function b1(z){switch(z[0]??"list"){case"list":case"ls":return S0();case"index":return D0(z[1]==="rebuild");default:{let $=d(v,"autonomy","loki"),X=await w([$,"memory",...z],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(X.stdout),process.stderr.write(X.stderr),X.exitCode}}}var $0=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
324
330
 
325
331
  Usage: loki <command> [args...]
326
332
 
@@ -336,7 +342,7 @@ Phase 2 ported (Bun-native, fast):
336
342
 
337
343
  All other commands fall through to the bash CLI (autonomy/loki).
338
344
  Set LOKI_LEGACY_BASH=1 to force the bash CLI for every command.
339
- `;async function Q3(z){let Q=z[0],$=z.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write($0),0;case"version":case"--version":case"-v":return R1();case"provider":return E1($);case"memory":return N1($);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (m1(),v1));return X($)}case"stats":{let{runStats:X}=await Promise.resolve().then(() => (d1(),l1));return X($)}case"doctor":{let{runDoctor:X}=await Promise.resolve().then(() => (z0(),e1));return X($)}default:return process.stderr.write(`Unknown command: ${Q}
345
+ `;async function Q3(z){let Q=z[0],$=z.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write($0),0;case"version":case"--version":case"-v":return R1();case"provider":return E1($);case"memory":return b1($);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (m1(),v1));return X($)}case"stats":{let{runStats:X}=await Promise.resolve().then(() => (d1(),l1));return X($)}case"doctor":{let{runDoctor:X}=await Promise.resolve().then(() => (z0(),e1));return X($)}default:return process.stderr.write(`Unknown command: ${Q}
340
346
  `),process.stderr.write($0),2}}process.on("SIGINT",()=>process.exit(130));process.on("SIGTERM",()=>process.exit(143));var X3=await Q3(Bun.argv.slice(2));process.exit(X3);
341
347
 
342
- //# debugId=1C8D12580BF319DD64756E2164756E21
348
+ //# debugId=CB3CC6615374C70C64756E2164756E21
package/mcp/__init__.py CHANGED
@@ -57,4 +57,4 @@ try:
57
57
  except ImportError:
58
58
  __all__ = ['mcp']
59
59
 
60
- __version__ = '7.5.0'
60
+ __version__ = '7.5.1'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loki-mode",
3
- "version": "7.5.0",
3
+ "version": "7.5.1",
4
4
  "description": "Loki Mode by Autonomi - Multi-agent autonomous startup system for Claude Code, Codex CLI, and Gemini CLI",
5
5
  "keywords": [
6
6
  "agent",
@@ -36,10 +36,10 @@
36
36
  - Missing adapter for replaced component = **High** (BLOCK)
37
37
  - Behavioral baseline mismatch without documentation = **Medium** (BLOCK)
38
38
 
39
- **Disabling (not recommended for healing mode):**
40
- ```bash
41
- LOKI_GATE_BACKWARD_COMPAT=false # Disable gate 10
42
- ```
39
+ **Disabling**: gate 10 only fires when `LOKI_HEAL_MODE=true` or
40
+ `.loki/healing/friction-map.json` exists in the project root (v7.4.20).
41
+ Greenfield projects skip the auditor entirely. To suppress on a healing
42
+ project, set `LOKI_HEAL_MODE=false`.
43
43
 
44
44
  ---
45
45
 
@@ -76,11 +76,71 @@ Gates 8 (Mock Detector) and 9 (Test Mutation Detector) run during the VERIFY pha
76
76
  - Both produce findings at HIGH/MEDIUM/LOW severity levels
77
77
  - HIGH findings = automatic FAIL (same as other blocking gates)
78
78
 
79
- **Disabling (not recommended):**
79
+ **Disabling**: gates 8 and 9 are baked into the test pipeline (the bash
80
+ scripts at `tests/detect-mock-problems.sh` and
81
+ `tests/detect-test-mutations.sh`); they have no env-var toggle today.
82
+ Skip the gate by not running the script in your CI.
83
+
84
+ ---
85
+
86
+ ## v7.5.0 Phase 1 environment flags
87
+
88
+ These four flags activate the override council and structured-findings
89
+ pipeline added in v7.5.0. All default off; behavior is byte-identical
90
+ when unset.
91
+
80
92
  ```bash
81
- LOKI_GATE_MOCK_DETECTOR=false # Disable gate 8
82
- LOKI_GATE_MUTATION_DETECTOR=false # Disable gate 9
83
- ```
93
+ LOKI_INJECT_FINDINGS=1 # inject structured per-finding records into the
94
+ # next iteration's prompt (instead of just the
95
+ # comma-separated gate-failure tokens)
96
+
97
+ LOKI_OVERRIDE_COUNCIL=1 # enable the 3-judge override council on BLOCK
98
+ # when .loki/state/counter-evidence-<iter>.json
99
+ # exists. Requires LOKI_INJECT_FINDINGS=1.
100
+
101
+ LOKI_AUTO_LEARNINGS=1 # auto-write structured learnings to
102
+ # .loki/state/relevant-learnings.json on every
103
+ # code_review gate failure
104
+
105
+ LOKI_HANDOFF_MD=1 # write a structured handoff doc to
106
+ # .loki/escalations/handoff-*.md before PAUSE
107
+ # (in addition to the bare PAUSE signal)
108
+ ```
109
+
110
+ Optional: `LOKI_AUTO_LEARNINGS_EPISODE=1` also writes the learning into
111
+ the Python episodic memory layer via `memory.engine.save_episode`.
112
+
113
+ **Reachability note (v7.5.0/v7.5.1)**: these flags activate inside the
114
+ Bun runtime. Today `loki start <prd>` routes through the bash runner via
115
+ `bin/loki` shim fall-through, so the flags do not yet trigger on a real
116
+ `loki start`. They DO activate in any code path that calls
117
+ `loki-ts/src/runner/runQualityGates` directly (e.g. tests, programmatic
118
+ integration). End-to-end activation lands when Part A Phase 4 wires the
119
+ Bun `start` route. See CHANGELOG v7.5.0 NOT-tested section.
120
+
121
+ ### Counter-evidence file format (`.loki/state/counter-evidence-<iter>.json`)
122
+
123
+ ```json
124
+ {
125
+ "iteration": 7,
126
+ "evidence": [
127
+ {
128
+ "findingId": "eng-qa::- [Critical] dead code path bug at sdk/python/...",
129
+ "claim": "this code path is dead duplicate; live code is at sdk/src/gauge/",
130
+ "proofType": "duplicate-code-path",
131
+ "artifacts": ["sdk/python/ is excluded by pyproject.toml"]
132
+ }
133
+ ]
134
+ }
135
+ ```
136
+
137
+ `findingId` is `canonicalFindingId(finding)` -- `<reviewer>::<first 80 chars
138
+ of the finding's raw text>`. `proofType` MUST be one of:
139
+ `file-exists`, `test-passes`, `grep-miss`, `reviewer-misread`,
140
+ `duplicate-code-path`, `out-of-scope`. Entries with any other proofType
141
+ are silently dropped at load time. The override council uses a stub
142
+ judge in v7.5.x that approves any of those six trusted proofTypes;
143
+ real provider-backed judges land in Phase 2 of Part B.
84
144
 
85
145
  ---
86
146