loki-mode 7.2.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md 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.2.0
6
+ # Loki Mode v7.3.0
7
7
 
8
8
  **You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
9
9
 
@@ -320,4 +320,4 @@ The following features are documented in skill modules but not yet fully automat
320
320
  | Quality gates 3-reviewer system | Implemented (v5.35.0) | 5 specialist reviewers in `skills/quality-gates.md`; execution in run.sh |
321
321
  | Benchmarks (HumanEval, SWE-bench) | Infrastructure only | Runner scripts and datasets exist in `benchmarks/`; no published results |
322
322
 
323
- **v7.2.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
323
+ **v7.3.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
package/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.0
1
+ 7.3.0
package/bin/loki ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ #===============================================================================
3
+ # Loki Mode shim
4
+ #
5
+ # Routes commands ported in Phase 2 (bash->Bun migration) to the Bun CLI;
6
+ # everything else falls through to autonomy/loki (bash).
7
+ #
8
+ # Set LOKI_LEGACY_BASH=1 to force bash for every command (rollback flag).
9
+ # See docs/architecture/ADR-001-runtime-migration.md and
10
+ # /Users/lokesh/.claude/plans/polished-waddling-stardust.md.
11
+ #===============================================================================
12
+ set -euo pipefail
13
+
14
+ # Resolve script directory (handles symlinks like the bash CLI does).
15
+ _resolve_path() {
16
+ local script="$1"
17
+ if command -v realpath &>/dev/null; then
18
+ realpath "$script" 2>/dev/null || echo "$script"
19
+ else
20
+ while [ -L "$script" ]; do
21
+ local dir
22
+ dir=$(dirname "$script")
23
+ script=$(readlink "$script")
24
+ [[ "$script" != /* ]] && script="$dir/$script"
25
+ done
26
+ echo "$script"
27
+ fi
28
+ }
29
+
30
+ SCRIPT_PATH=$(_resolve_path "$0")
31
+ SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
32
+ REPO_ROOT=$(cd "$SCRIPT_DIR/.." 2>/dev/null && pwd)
33
+ BASH_CLI="$REPO_ROOT/autonomy/loki"
34
+
35
+ # Resolve which Bun entry to use:
36
+ # 1. LOKI_TS_ENTRY=... -- explicit override (custom builds, tests)
37
+ # 2. BUN_FROM_SOURCE=1 -- force src/cli.ts (used by bench --compare-dist
38
+ # and during Phase 3 development before dist ships)
39
+ # 3. dist/loki.js exists -- production path (npm/Docker/Homebrew artifact)
40
+ # 4. fall back to src -- in-repo development before first build
41
+ if [ -n "${LOKI_TS_ENTRY:-}" ]; then
42
+ BUN_CLI="$LOKI_TS_ENTRY"
43
+ elif [ "${BUN_FROM_SOURCE:-0}" = "1" ] || [ "${BUN_FROM_SOURCE:-}" = "true" ]; then
44
+ BUN_CLI="$REPO_ROOT/loki-ts/src/cli.ts"
45
+ elif [ -f "$REPO_ROOT/loki-ts/dist/loki.js" ]; then
46
+ BUN_CLI="$REPO_ROOT/loki-ts/dist/loki.js"
47
+ else
48
+ BUN_CLI="$REPO_ROOT/loki-ts/src/cli.ts"
49
+ fi
50
+
51
+ # Force-fall-through to bash when the rollback flag is set.
52
+ if [ "${LOKI_LEGACY_BASH:-0}" = "1" ] || [ "${LOKI_LEGACY_BASH:-}" = "true" ]; then
53
+ exec "$BASH_CLI" "$@"
54
+ fi
55
+
56
+ # Bun must be installed for the new path; if it isn't, fall through to bash
57
+ # silently rather than fail. This keeps users on systems without Bun working.
58
+ if ! command -v bun &>/dev/null; then
59
+ exec "$BASH_CLI" "$@"
60
+ fi
61
+
62
+ # Commands ported in Phase 2 -- route to Bun. Everything else goes to bash.
63
+ # Two-token routes (provider show/list, memory list/index) match on the first
64
+ # token only; the Bun dispatcher handles subcommand routing internally.
65
+ case "${1:-}" in
66
+ version|--version|-v|status|stats|doctor|provider|memory)
67
+ exec bun "$BUN_CLI" "$@"
68
+ ;;
69
+ *)
70
+ exec "$BASH_CLI" "$@"
71
+ ;;
72
+ esac
@@ -7,7 +7,7 @@ Modules:
7
7
  control: Session control API (start/stop/pause/resume)
8
8
  """
9
9
 
10
- __version__ = "7.2.0"
10
+ __version__ = "7.3.0"
11
11
 
12
12
  # Expose the control app for easy import
13
13
  try:
@@ -2,7 +2,7 @@
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.2.0
5
+ **Version:** v7.3.0
6
6
 
7
7
  ---
8
8
 
@@ -0,0 +1,229 @@
1
+ # ADR-001: Migrate Loki orchestrator off bash
2
+
3
+ **Status:** Proposed (feature/bun-migration branch)
4
+ **Date:** 2026-04-25
5
+ **Decision driver:** `autonomy/run.sh` is 11,327 lines of bash and `autonomy/loki` is 22,304 lines. Both are fragile, hard to refactor, untyped, and the upstream RARV-C audit (v6.81 plan) flagged them as the single biggest architectural debt.
6
+
7
+ ## Context: facts the user asked me to verify
8
+
9
+ ### 1. Did Anthropic acquire Bun?
10
+
11
+ **YES, verified.** Anthropic acquired Bun (Oven, Inc.) in December 2025. Bun remains MIT-licensed and open-source. Anthropic is positioning Bun as the runtime infrastructure for Claude Code, the Claude Agent SDK, and future AI coding products.
12
+
13
+ Sources:
14
+ - [Bun Blog: Bun is joining Anthropic](https://bun.com/blog/bun-joins-anthropic)
15
+ - [Anthropic: Anthropic acquires Bun as Claude Code reaches $1B milestone](https://www.anthropic.com/news/anthropic-acquires-bun-as-claude-code-reaches-usd1b-milestone)
16
+
17
+ ### 2. Is Bun faster than bash for our workload?
18
+
19
+ **Two-layer answer with REAL benchmarks.**
20
+
21
+ #### Layer 1: trivial hello-world cold start (hyperfine, 100 runs)
22
+
23
+ | Runtime | Cold start mean | vs bash |
24
+ |---|---|---|
25
+ | **Go binary** (compiled) | **1.8 ms** | **2.5x faster** |
26
+ | **bash hello-world** | **4.5 ms** | baseline |
27
+ | **Bun binary** (`bun build --compile`) | 6.9 ms | 1.5x slower |
28
+ | **Bun script** (`bun foo.ts`) | 7.6 ms | 1.7x slower |
29
+ | **Python3 script** | 20.3 ms | 4.5x slower |
30
+ | **Node.js script** | 45.2 ms | 10x slower |
31
+
32
+ For a trivial 1-line script, bash beats Bun by ~3 ms.
33
+
34
+ #### Layer 2: real Loki workload (50 runs, side-by-side, scripts/bench.ts)
35
+
36
+ | Runtime | `loki version` mean | vs bash |
37
+ |---|---|---|
38
+ | **bash autonomy/loki version** | **106.71 ms** (min 96.54, max 125.35) | baseline |
39
+ | **bun loki-ts/src/cli.ts version** | **12.36 ms** (min 11.63, max 13.52) | **8.63x FASTER** |
40
+
41
+ **This is the finding that flips the analysis.** When the bash script is 22,304 lines (the actual `autonomy/loki`), bash re-parses the entire AST every invocation. That parse cost dwarfs Bun's runtime startup cost by ~10x. **Bun is 8.6x faster than actual Loki bash.**
42
+
43
+ The user's premise ("Bun is faster than bash, no speed compromise") is correct for actual Loki workloads, even though it's false for hello-world.
44
+
45
+ **Why the gap:** bash has no bytecode cache. Every `loki version` invocation re-parses 22k lines of shell. Bun parses TypeScript once at install (or even at compile time with `--compile`), then executes machine code. The asymmetry grows with script size:
46
+
47
+ | Script size | Bash startup | Bun startup |
48
+ |---|---|---|
49
+ | 1 line | 4.5 ms | 7.6 ms (1.7x slower) |
50
+ | 22,304 lines (real `autonomy/loki`) | 106.71 ms | 12.36 ms (**8.63x FASTER**) |
51
+
52
+ So: **for hello-world bash wins; for our actual codebase Bun wins decisively, by an order of magnitude.**
53
+
54
+ ### 3. What about the npm distribution requirement?
55
+
56
+ User constraint: "people use npm, I want to keep it the same way."
57
+
58
+ | Runtime | npm distribution path | Complexity |
59
+ |---|---|---|
60
+ | **Bash** (today) | `package.json` `bin` field points to shell script | Trivial; current state |
61
+ | **Bun runtime** | `npm install -g loki-mode` ships TS, requires Bun installed via `npm install -g bun` (peer) OR Bun standalone in postinstall | Medium; peer dependency convention |
62
+ | **Bun compiled binary** | `bun build --compile` → 60 MB binary per platform; npm postinstall downloads correct binary (esbuild model) | Medium; per-platform binaries |
63
+ | **Go binary** | Same model as Bun compiled — npm postinstall downloads platform binary (esbuild, biome, vite-rust, swc all use this) | Medium; mature pattern |
64
+ | **Python** | npm postinstall would shell out to `pip install` or bundle Python — fragile, two package managers | High; do not recommend |
65
+ | **Node.js** | Native — no postinstall needed | Trivial; but Node is 10x slower than bash on cold start |
66
+
67
+ All three viable options (Bun runtime, Bun compiled, Go binary) keep the `npm install -g loki-mode` UX. Users see no change.
68
+
69
+ ## Three options, honestly compared
70
+
71
+ ### Option A: Go
72
+
73
+ **Pro:**
74
+ - **Only language that strictly beats bash.** 2.5x faster cold-start (1.8 ms vs 4.5 ms). User's "no speed compromise" requirement is met without caveats.
75
+ - Single static binary, ~2.4 MB (vs 60 MB Bun binary).
76
+ - Mature CLI ecosystem (Docker, kubectl, Terraform, Helm all use Go).
77
+ - Strict typing prevents whole class of bash quoting bugs.
78
+ - Cross-compile to all platforms from any platform.
79
+
80
+ **Con:**
81
+ - Loki team has zero Go in the codebase today.
82
+ - Anthropic does NOT own Go; less strategic alignment.
83
+ - Rewriting 33,000+ lines of bash to idiomatic Go is a 3-6 month effort.
84
+ - Goroutines/channels are different mental model than bash + Python orchestration.
85
+
86
+ **Distribution via npm:** Same pattern as esbuild — npm postinstall downloads the right platform binary. Mature, ~5 MB compressed per arch.
87
+
88
+ ### Option B: Bun runtime + TypeScript
89
+
90
+ **Pro:**
91
+ - **Anthropic owns Bun.** Strategic alignment with the company that owns the model we depend on.
92
+ - Native shell built in (`Bun.$\`echo hello\``) — minimal friction porting bash idioms.
93
+ - Bun's `npm install` is 20-40x faster than npm — every CI run faster.
94
+ - TypeScript: types catch bugs bash can't.
95
+ - Anthropic-funded development means Bun improvements specifically target AI agent workloads.
96
+ - 98% Node.js compatibility — npm packages work directly.
97
+
98
+ **Con:**
99
+ - **1.7x SLOWER than bash on trivial cold-start** (7.6 ms vs 4.5 ms). The user explicitly said "no speed compromise". This is a genuine compromise, even if 3 ms is humanly invisible.
100
+ - Bun runtime must be installed separately OR shipped via postinstall (60 MB if compiled).
101
+ - Less mature than Node (Bun 1.3 in 2026; some npm packages still hit edge cases).
102
+
103
+ **Distribution via npm:** Either (a) declare Bun as a peer dep and prompt user `npm install -g bun`; (b) ship `--compile` binary via postinstall.
104
+
105
+ ### Option C: Hybrid (recommended)
106
+
107
+ **Pro:**
108
+ - Keep tiny scripts in bash (where it wins by 3 ms): `loki version`, `loki status`, anything <100 LOC.
109
+ - Migrate the 11k-line orchestrator (`run.sh`) and 22k-line CLI (`autonomy/loki`) to Bun TypeScript — where compiled+typed wins.
110
+ - Keep `memory/`, `providers/`, `mcp/` in Python — they're already mature, no reason to rewrite.
111
+ - Anthropic alignment via Bun for the parts that matter.
112
+ - No speed regression for trivial commands; large gains for orchestrator.
113
+
114
+ **Con:**
115
+ - Three runtimes in the codebase (bash + Bun + Python) — operational complexity.
116
+ - Cross-runtime debugging harder than monorepo.
117
+
118
+ **Distribution:** Bun shipped via npm postinstall as compiled binary; bash remains as-is; Python unchanged.
119
+
120
+ ## Recommendation
121
+
122
+ **Option B (Bun runtime + TypeScript) — full migration, not hybrid.**
123
+
124
+ Reasons:
125
+
126
+ 1. **The Layer 2 benchmark inverts the speed argument.** Bun is 8.6x FASTER than actual Loki bash because `autonomy/loki` is 22,304 lines that re-parse every invocation. The user's "no speed compromise" rule is met decisively, with margin.
127
+ 2. **Anthropic strategic alignment.** Anthropic owns Bun. Loki uses Claude. Aligning runtime and model owner reduces dependency-versioning friction over time.
128
+ 3. **TypeScript pays the maintainability dividend** that 33k lines of bash will never deliver. Type checking catches whole classes of bugs (the kind we hit in v6.81-v7.2 cycles).
129
+ 4. **Hybrid is now harder to justify.** When bash loses by 8.6x on the actual workload, keeping it for 3 ms theoretical wins on hello-world is bad engineering.
130
+ 5. **Go would still be 2-4x faster than Bun** in absolute cold-start, but: zero existing Go in the codebase, no Anthropic alignment, larger rewrite cost, no JS ecosystem reuse. Unless Loki specifically targets the sub-millisecond CLI category (which it doesn't — every command runs in a multi-second/minute autonomous loop), the absolute speed delta doesn't justify the strategic cost.
131
+
132
+ **If user explicitly wants the absolute fastest:** Go (Option A) is 2.5x faster than Bun. But for orchestrator-heavy work where most time is spent waiting on Claude API calls, the difference is invisible.
133
+
134
+ ## Migration plan (Option C)
135
+
136
+ ### Phase 1: Scaffold (this branch, no behavior change)
137
+ - Create `loki-ts/` directory parallel to `autonomy/`
138
+ - `package.json` with Bun as engine, TypeScript config
139
+ - Port ONE simple command: `loki ts-version` (proves the toolchain)
140
+ - Add Bun to CI matrix (alongside existing Node/Python)
141
+ - **No user-visible change.** All existing commands route to bash.
142
+
143
+ ### Phase 2: Sub-commands
144
+ - Migrate read-only commands: `loki provider show`, `loki status`, `loki stats`, `loki memory list`
145
+ - Each migrated command goes through `loki-ts/` with bash as fallback flag
146
+ - Performance benchmark each: must be ≤ 2x bash cold start
147
+
148
+ ### Phase 3: Build/release tooling
149
+ - Replace npm publish with `bun publish` in CI
150
+ - Replace dashboard-ui esbuild with `bun build` (already 4-5x faster)
151
+ - Replace pytest where possible with `bun test` for non-Python tests
152
+ - Measure: full CI wall time, npm install time
153
+
154
+ ### Phase 4: build_prompt + RARV-C migration
155
+ - Port `build_prompt` (the 360-line bash function) to TypeScript
156
+ - Port `run_autonomous` outer loop
157
+ - Keep all Python subprocess invocations untouched (they're already fine)
158
+ - Side-by-side validation: same prompt output character-by-character
159
+ - Fallback flag: `LOKI_LEGACY_BASH=true` reverts
160
+
161
+ ### Phase 5: completion-council + code-review
162
+ - Port `council_should_stop` and `run_code_review` to TypeScript
163
+ - Same validation discipline
164
+
165
+ ### Phase 6: Sunset bash (only after 30 days clean in production)
166
+ - Remove `LOKI_LEGACY_BASH` flag
167
+ - Delete `autonomy/run.sh` and `autonomy/loki` (keep in git history)
168
+ - Bash → Bun migration complete
169
+
170
+ ## What we can do better for releases (Anthropic owns Bun → leverage)
171
+
172
+ | Today | Tomorrow | Win |
173
+ |---|---|---|
174
+ | `npm publish` (45-60 sec) | `bun publish` | ~5x faster CI publish |
175
+ | `npm install -g loki-mode` for users | Same UX, `bun install` under the hood when available | 20-40x faster install (verified) |
176
+ | Tests via `npm test` (Node 20-25 sec) | `bun test` for non-Python | ~10x faster test runs |
177
+ | Dashboard build with esbuild (122 ms) | `bun build` | 2-4x faster |
178
+ | Per-iteration cold start in run.sh: bash 4.5ms × N | Compiled Bun start once, run 100s | Net negative if iteration count low; net positive for sessions >5 iterations |
179
+ | Python `mcp/server.py` | Stays Python (already good) | No change |
180
+
181
+ ## Risks I'm not hiding
182
+
183
+ 1. **Migration drift:** TS port may behave subtly differently from bash. Mitigation: side-by-side test harness comparing outputs.
184
+ 2. **Bun beta-feature churn:** Even though Bun 1.3 is stable, Anthropic may push it in directions that break us. Mitigation: pin Bun version in `package.json` engines.
185
+ 3. **60 MB binary** if we ship `--compile`. Half a Loki Docker image. Mitigation: ship runtime peer dep instead of compiled binary in v8.
186
+ 4. **Three-runtime codebase** is real cognitive overhead for new contributors. Mitigation: clear `CONTRIBUTING.md` table of "what runtime owns what."
187
+ 5. **Bun's npm shipping pattern** is less proven than Go's. Mitigation: keep npm registry as primary distribution; add Homebrew (already exists) as a Bun-bundled alternative.
188
+
189
+ ## Concrete next steps if approved
190
+
191
+ 1. Scaffold `loki-ts/` with `package.json`, `tsconfig.json`, `src/cli.ts` (this PR)
192
+ 2. Port `cmd_version` to `loki-ts/src/commands/version.ts` (proof of concept)
193
+ 3. Add `bun-test.yml` GitHub workflow alongside existing `test.yml`
194
+ 4. Set acceptance criteria: every Phase 2+ command must benchmark within 2x of bash cold-start AND be type-checked via `bun typecheck`
195
+ 5. Ship Phase 1 as v8.0.0-alpha.1 (pre-release, opt-in) — does not affect default users
196
+
197
+ ---
198
+
199
+ ## Appendix: real benchmark data captured on this machine
200
+
201
+ Hyperfine 100 runs, 5 warmup, hello-world equivalent:
202
+
203
+ ```
204
+ bash /tmp/loki-bench-bash.sh 4.5 ± 0.4 ms baseline
205
+ bun-compiled-binary 6.9 ± 0.4 ms 1.53x slower
206
+ bun /tmp/loki-bench-bun.ts 7.6 ± 0.4 ms 1.69x slower
207
+ node /tmp/loki-bench-node.js 45.2 ± 1.0 ms 10.04x slower
208
+ python3 /tmp/loki-bench-py.py 20.3 ± 0.5 ms 4.51x slower
209
+ go-compiled-binary 1.8 ± 0.3 ms 2.5x FASTER
210
+ ```
211
+
212
+ Local versions:
213
+ - bash 5.x (macOS shipped /bin/bash 3.2 + brew bash)
214
+ - Bun 1.3.13
215
+ - Node v25.9.0
216
+ - Python 3.x
217
+ - Go 1.26.1
218
+
219
+ These are real numbers from this exact Mac, not from a vendor blog. Run hyperfine yourself to reproduce.
220
+
221
+ **Layer 2** (real Loki workload, 50 runs via `loki-ts/scripts/bench.ts`):
222
+ ```
223
+ bash autonomy/loki version 106.71 ms (min 96.54, max 125.35)
224
+ bun loki-ts/src/cli.ts version 12.36 ms (min 11.63, max 13.52)
225
+
226
+ bun is 8.63x FASTER than bash on the actual Loki entry point
227
+ ```
228
+
229
+ The 22,304-line `autonomy/loki` re-parses every invocation. Bun parses TS once, executes machine code thereafter. The asymmetry is the core argument for migration.
@@ -0,0 +1,341 @@
1
+ // @bun
2
+ var $0=Object.defineProperty;var Q0=(z)=>z;function X0(z,Q){this[z]=Q0.bind(null,Q)}var l=(z,Q)=>{for(var $ in Q)$0(z,$,{get:Q[$],enumerable:!0,configurable:!0,set:X0.bind(Q,$)})};var f=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var Z0=import.meta.require;var L1={};l(L1,{runOrThrow:()=>B0,run:()=>O,commandVersion:()=>J0,commandExists:()=>R,ShellError:()=>K1});async function O(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,V]=await Promise.all([new Response($.stdout).text(),new Response($.stderr).text(),$.exited]);if(X)clearTimeout(X);return{stdout:Z,stderr:H,exitCode:V}}async function B0(z,Q={}){let $=await O(z,Q);if($.exitCode!==0)throw new K1(`command failed (${$.exitCode}): ${z.join(" ")}`,$.exitCode,$.stdout,$.stderr);return $}async function R(z){let Q=q0(z),$=await O(["sh","-c",`command -v ${Q}`]);if($.exitCode===0)return $.stdout.trim()||null;return null}function q0(z){if(!/^[A-Za-z0-9._/-]+$/.test(z))throw Error(`refused to shell-escape suspect token: ${z}`);return z}async function J0(z,Q="--version"){if(!await R(z))return null;let X=await O([z,Q],{timeoutMs:5000});if(X.exitCode!==0)return null;return((X.stdout||X.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var K1;var g=f(()=>{K1=class K1 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"}}});var k="\x1B[0;31m",x="\x1B[0;32m",T="\x1B[1;33m",J="\x1B[0;36m",F="\x1B[1m",Y="\x1B[2m",K="\x1B[0m";var h=()=>{};var k1={};l(k1,{lokiDir:()=>E,homeLokiDir:()=>H1,findSkillDir:()=>j0,REPO_ROOT:()=>y});import{resolve as b,dirname as P1}from"path";import{fileURLToPath as G0}from"url";import{existsSync as z1}from"fs";import{homedir as R1}from"os";function M0(){let z=x1;for(let Q=0;Q<6;Q++){if(z1(b(z,"VERSION"))&&z1(b(z,"autonomy/run.sh")))return z;let $=P1(z);if($===z)break;z=$}return b(x1,"..","..","..")}function E(){return process.env.LOKI_DIR??b(process.cwd(),".loki")}function H1(){return b(R1(),".loki")}function j0(){let z=[y,b(R1(),".claude/skills/loki-mode"),process.cwd()];for(let Q of z)if(z1(b(Q,"SKILL.md"))&&z1(b(Q,"autonomy/run.sh")))return Q;return null}var x1,y;var m=f(()=>{x1=P1(G0(import.meta.url));y=M0()});import{existsSync as x0}from"fs";async function n(){if(o!==void 0)return o;let z="/opt/homebrew/bin/python3.12";if(x0(z))return o=z,z;let Q=await R("python3.12");if(Q)return o=Q,Q;let $=await R("python3");return o=$,$}async function r(z,Q={}){let $=await n();if(!$)return{stdout:"",stderr:"python3 not found",exitCode:127};return O([$,"-c",z],Q)}var o;var $1=f(()=>{g()});var h1={};l(h1,{runStatus:()=>g0});import{existsSync as L,readFileSync as i,readdirSync as N1,statSync as C1}from"fs";import{resolve as w,basename as E0}from"path";async function b0(){if(await R("jq"))return!0;return process.stdout.write(`${k}Error: jq is required but not installed.${K}
3
+ `),process.stdout.write(`Install with:
4
+ `),process.stdout.write(` brew install jq (macOS)
5
+ `),process.stdout.write(` apt install jq (Debian/Ubuntu)
6
+ `),process.stdout.write(` yum install jq (RHEL/CentOS)
7
+ `),!1}function Q1(z){if(!Number.isFinite(z)||z<=0)return!1;try{return process.kill(z,0),!0}catch{return!1}}function X1(z){if(!L(z))return null;try{let Q=i(z,"utf-8").trim();if(!Q)return null;let $=Number.parseInt(Q,10);return Number.isFinite($)?$:null}catch{return null}}function N0(z){let Q=[],$=X1(w(z,"loki.pid"));if($!==null&&Q1($))Q.push(`global:${$}`);let X=w(z,"sessions");if(L(X)){let Z=[];try{Z=N1(X)}catch{Z=[]}for(let H of Z){let V=w(X,H);try{if(!C1(V).isDirectory())continue}catch{continue}let W=w(V,"loki.pid"),M=X1(W);if(M!==null&&Q1(M))Q.push(`${H}:${M}`)}}if(L(z)){let Z=[];try{Z=N1(z)}catch{Z=[]}for(let H of Z){if(!H.startsWith("run-")||!H.endsWith(".pid"))continue;let V=w(z,H);try{if(!C1(V).isFile())continue}catch{continue}let W=E0(H,".pid").slice(4),M=X1(V);if(M!==null&&Q1(M)){if(!Q.some((I)=>I.startsWith(`${W}:`)))Q.push(`${W}:${M}`)}}}return Q}async function f1(z,Q){let $=await O(["jq","-r",z,Q]);if($.exitCode!==0)return null;return $.stdout.trim()}function g1(z,Q){try{let $=i(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 y1(z,Q,$){try{let X=i(z,"utf-8"),H=JSON.parse(X)[Q];if(typeof H==="number"&&Number.isFinite(H))return H;return $}catch{return $}}async function C0(){let z=E();if(!await b0())return 1;if(!L(z))return process.stdout.write(`${F}Loki Mode Status${K}
8
+ `),process.stdout.write(`
9
+ `),process.stdout.write(`${T}No active session found.${K}
10
+ `),process.stdout.write(`Loki Mode has not been initialized in this directory.
11
+ `),process.stdout.write(`
12
+ `),process.stdout.write(`To start a session:
13
+ `),process.stdout.write(` loki start <prd> - Start with a PRD file
14
+ `),process.stdout.write(` loki start - Start without a PRD
15
+ `),process.stdout.write(`
16
+ `),process.stdout.write(`${Y}Current directory: ${process.cwd()}${K}
17
+ `),0;process.stdout.write(`${F}Loki Mode Status${K}
18
+ `),process.stdout.write(`
19
+ `);let Q="",$=w(z,"state","provider");if(L($))try{Q=i($,"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(`${J}Provider:${K} ${X} (${Z})
20
+ `),process.stdout.write(`${Y} Switch with: loki provider set <claude|codex|gemini|cline|aider>${K}
21
+ `),process.stdout.write(`
22
+ `);let H=N0(z);if(H.length>0){process.stdout.write(`${x}Active Sessions: ${H.length}${K}
23
+ `);for(let B of H){let U=B.indexOf(":"),_=U>=0?B.slice(0,U):B,D=U>=0?B.slice(U+1):"";if(_==="global")process.stdout.write(` ${J}[global]${K} PID ${D}
24
+ `);else process.stdout.write(` ${J}[#${_}]${K} PID ${D}
25
+ `)}process.stdout.write(`
26
+ `),process.stdout.write(`${Y} Stop specific: loki stop <session-id>${K}
27
+ `),process.stdout.write(`${Y} Stop all: loki stop${K}
28
+ `),process.stdout.write(`
29
+ `)}if(L(w(z,"PAUSE")))process.stdout.write(`${T}Status: PAUSED${K}
30
+ `),process.stdout.write(`${Y} Resume with: loki resume${K}
31
+ `),process.stdout.write(`
32
+ `);else if(L(w(z,"STOP")))process.stdout.write(`${k}Status: STOPPED${K}
33
+ `),process.stdout.write(`${Y} Clear with: loki resume${K}
34
+ `),process.stdout.write(`
35
+ `);let V=w(z,"STATUS.txt");if(L(V)){process.stdout.write(`${J}Session Info:${K}
36
+ `);try{process.stdout.write(i(V,"utf-8"))}catch{}process.stdout.write(`
37
+ `)}let W=w(z,"state","orchestrator.json");if(L(W)){process.stdout.write(`${J}Orchestrator State:${K}
38
+ `);let B=await f1('.currentPhase // "unknown"',W);process.stdout.write(`${B??"unknown"}
39
+ `)}let M=w(z,"queue","pending.json");if(L(M)){let B=await f1('if type == "array" then length elif .tasks then .tasks | length else 0 end',M);process.stdout.write(`${J}Pending Tasks:${K} ${B??"0"}
40
+ `)}let A=w(z,"metrics","budget.json");if(L(A)){let B=g1(A,"budget_limit"),U=g1(A,"budget_used");if(B!=="0")process.stdout.write(`${J}Budget:${K} $${U} / $${B}
41
+ `);else process.stdout.write(`${J}Cost:${K} $${U} (no limit)
42
+ `)}let I=w(z,"state","context-usage.json");if(L(I)){let B=y1(I,"window_size",200000),U=y1(I,"used_tokens",0),_=0;if(B>0)_=Math.floor(U*100/B);process.stdout.write(`${J}Context:${K} ${_}% (${U} / ${B} tokens)
43
+ `)}let P=w(z,"dashboard","dashboard.pid");if(L(P)){let B=X1(P);if(B!==null&&Q1(B)){let U=process.env.LOKI_DASHBOARD_PORT||"57374";process.stdout.write(`${J}Dashboard:${K} http://127.0.0.1:${U}/
44
+ `)}}return process.stdout.write(`
45
+ `),process.stdout.write(`${Y} Tip: loki context show - detailed token breakdown${K}
46
+ `),process.stdout.write(`${Y} Tip: loki code overview - codebase intelligence${K}
47
+ `),0}async function f0(){let z=await n();if(!z)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
48
+ `),1;let Q=y,$=E(),X=process.env.LOKI_DASHBOARD_PORT||"57374",Z=process.env.LOKI_PROVIDER||"claude",H=await O([z,"-c",D0,Q,$,X,Z]);if(H.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
49
+ `),1;return process.stdout.write(H.stdout),0}async function g0(z){let Q=[...z];while(Q.length>0){let $=Q[0];if($==="--json")return f0();if($==="--help"||$==="-h")return process.stdout.write(`Usage: loki status [--json]
50
+ `),0;return process.stdout.write(`${k}Unknown flag: ${$}${K}
51
+ `),process.stdout.write(`Usage: loki status [--json]
52
+ `),1}return C0()}var D0=`
53
+ import json, os, sys, time
54
+
55
+ skill_dir = sys.argv[1]
56
+ loki_dir = sys.argv[2]
57
+ dashboard_port = sys.argv[3]
58
+ env_provider = sys.argv[4]
59
+ result = {}
60
+
61
+ # Version
62
+ version_file = os.path.join(skill_dir, 'VERSION')
63
+ if os.path.isfile(version_file):
64
+ with open(version_file) as f:
65
+ result['version'] = f.read().strip()
66
+ else:
67
+ result['version'] = 'unknown'
68
+
69
+ # Check if session exists
70
+ if not os.path.isdir(loki_dir):
71
+ result['status'] = 'inactive'
72
+ result['phase'] = None
73
+ result['iteration'] = 0
74
+ result['provider'] = env_provider
75
+ result['dashboard_url'] = None
76
+ result['pid'] = None
77
+ result['elapsed_time'] = 0
78
+ result['task_counts'] = {'total': 0, 'completed': 0, 'failed': 0, 'pending': 0}
79
+ print(json.dumps(result, indent=2))
80
+ sys.exit(0)
81
+
82
+ # Status from signals and session.json
83
+ if os.path.isfile(os.path.join(loki_dir, 'PAUSE')):
84
+ result['status'] = 'paused'
85
+ elif os.path.isfile(os.path.join(loki_dir, 'STOP')):
86
+ result['status'] = 'stopped'
87
+ else:
88
+ session_file = os.path.join(loki_dir, 'session.json')
89
+ if os.path.isfile(session_file):
90
+ try:
91
+ with open(session_file) as f:
92
+ session = json.load(f)
93
+ result['status'] = session.get('status', 'unknown')
94
+ except Exception:
95
+ result['status'] = 'unknown'
96
+ else:
97
+ result['status'] = 'unknown'
98
+
99
+ # Phase and iteration from dashboard-state.json
100
+ ds_file = os.path.join(loki_dir, 'dashboard-state.json')
101
+ if os.path.isfile(ds_file):
102
+ try:
103
+ with open(ds_file) as f:
104
+ ds = json.load(f)
105
+ result['phase'] = ds.get('phase', ds.get('currentPhase'))
106
+ result['iteration'] = ds.get('iteration', ds.get('currentIteration', 0))
107
+ except Exception:
108
+ result['phase'] = None
109
+ result['iteration'] = 0
110
+ else:
111
+ orch_file = os.path.join(loki_dir, 'state', 'orchestrator.json')
112
+ if os.path.isfile(orch_file):
113
+ try:
114
+ with open(orch_file) as f:
115
+ orch = json.load(f)
116
+ result['phase'] = orch.get('currentPhase')
117
+ result['iteration'] = orch.get('currentIteration', 0)
118
+ except Exception:
119
+ result['phase'] = None
120
+ result['iteration'] = 0
121
+ else:
122
+ result['phase'] = None
123
+ result['iteration'] = 0
124
+
125
+ # Provider
126
+ provider_file = os.path.join(loki_dir, 'state', 'provider')
127
+ if os.path.isfile(provider_file):
128
+ with open(provider_file) as f:
129
+ result['provider'] = f.read().strip()
130
+ else:
131
+ result['provider'] = env_provider
132
+
133
+ # PID
134
+ pid_file = os.path.join(loki_dir, 'loki.pid')
135
+ if os.path.isfile(pid_file):
136
+ try:
137
+ with open(pid_file) as f:
138
+ result['pid'] = int(f.read().strip())
139
+ except (ValueError, Exception):
140
+ result['pid'] = None
141
+ else:
142
+ result['pid'] = None
143
+
144
+ # Elapsed time from session.json
145
+ session_file = os.path.join(loki_dir, 'session.json')
146
+ if os.path.isfile(session_file):
147
+ try:
148
+ with open(session_file) as f:
149
+ session = json.load(f)
150
+ start_time = session.get('start_time', session.get('startTime'))
151
+ if start_time:
152
+ if isinstance(start_time, (int, float)):
153
+ result['elapsed_time'] = int(time.time() - start_time)
154
+ else:
155
+ from datetime import datetime
156
+ dt = datetime.fromisoformat(start_time.replace('Z', '+00:00'))
157
+ result['elapsed_time'] = int(time.time() - dt.timestamp())
158
+ else:
159
+ result['elapsed_time'] = 0
160
+ except Exception:
161
+ result['elapsed_time'] = 0
162
+ else:
163
+ result['elapsed_time'] = 0
164
+
165
+ # Dashboard URL
166
+ dashboard_pid_file = os.path.join(loki_dir, 'dashboard', 'dashboard.pid')
167
+ dashboard_url = None
168
+ if os.path.isfile(dashboard_pid_file):
169
+ try:
170
+ with open(dashboard_pid_file) as f:
171
+ dpid = int(f.read().strip())
172
+ os.kill(dpid, 0)
173
+ dashboard_url = 'http://127.0.0.1:' + dashboard_port + '/'
174
+ except (ProcessLookupError, PermissionError, ValueError, Exception):
175
+ pass
176
+ result['dashboard_url'] = dashboard_url
177
+
178
+ # Task counts from queue files
179
+ task_counts = {'total': 0, 'completed': 0, 'failed': 0, 'pending': 0}
180
+ queue_dir = os.path.join(loki_dir, 'queue')
181
+ if os.path.isdir(queue_dir):
182
+ for name, key in [('pending.json', 'pending'), ('completed.json', 'completed'), ('failed.json', 'failed')]:
183
+ fpath = os.path.join(queue_dir, name)
184
+ if os.path.isfile(fpath):
185
+ try:
186
+ with open(fpath) as f:
187
+ data = json.load(f)
188
+ if isinstance(data, list):
189
+ task_counts[key] = len(data)
190
+ elif isinstance(data, dict) and 'tasks' in data:
191
+ task_counts[key] = len(data['tasks'])
192
+ except Exception:
193
+ pass
194
+ task_counts['total'] = task_counts['pending'] + task_counts['completed'] + task_counts['failed']
195
+ result['task_counts'] = task_counts
196
+
197
+ print(json.dumps(result, indent=2))
198
+ `;var m1=f(()=>{g();$1();h();m()});var c1={};l(c1,{runStats:()=>p0,computeStats:()=>p1});import{readdirSync as v1,readFileSync as y0,statSync as u1}from"fs";import{join as N}from"path";function u(z){try{if(!u1(z).isFile())return null;return JSON.parse(y0(z,"utf-8"))}catch{return null}}function B1(z){try{return u1(z).isDirectory()}catch{return!1}}function h0(z){if(!B1(z))return[];try{let Q=v1(z).filter(($)=>$.startsWith("iteration-")&&$.endsWith(".json"));return Q.sort(),Q.map(($)=>N(z,$))}catch{return[]}}function p(z){return Math.trunc(z).toLocaleString("en-US")}function W1(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 C(z,Q=0){let $=Math.pow(10,Q);return Math.round(z*$)/$}function c(z,Q){return z.toFixed(Q)}function U1(z,Q){return z.length>=Q?z:z+" ".repeat(Q-z.length)}function m0(z){let Q="N/A",$=0,X=u(N(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=N(z,"metrics","efficiency"),H=h0(Z),V=[];for(let q of H){let j=u(q);if(j&&typeof j==="object")V.push(j)}if(V.length>0)$=Math.max($,V.length);let W=V.reduce((q,j)=>q+(j.input_tokens??0),0),M=V.reduce((q,j)=>q+(j.output_tokens??0),0),A=W+M,I=V.reduce((q,j)=>q+(j.cost_usd??0),0),P=V.reduce((q,j)=>q+(j.duration_seconds??0),0),B=0,U=0,_=u(N(z,"metrics","budget.json"));if(_&&typeof _==="object"){if(typeof _.budget_limit==="number")B=_.budget_limit;if(typeof _.budget_used==="number")U=_.budget_used}let D=0,a=0,d=u(N(z,"state","quality-gates.json"));if(d&&typeof d==="object"){if(Array.isArray(d)){for(let q of d)if(a+=1,q===!0)D+=1;else if(q&&typeof q==="object"){let j=q;if(j.passed===!0||j.status==="passed")D+=1}}else for(let q of Object.values(d))if(typeof q==="boolean"){if(a+=1,q)D+=1}else if(q&&typeof q==="object"){a+=1;let j=q;if(j.passed===!0||j.status==="passed")D+=1}}let _1={},s=u(N(z,"quality","gate-failure-count.json"));if(s&&typeof s==="object"&&!Array.isArray(s)){let q={};for(let[j,S]of Object.entries(s))if(typeof S==="number")q[j]=S;_1=q}let Y1=0,A1=0,T1=0,Z1=N(z,"quality");if(B1(Z1)){let q=[];try{q=v1(Z1)}catch{q=[]}for(let j of q){if(!j.endsWith(".json")||j==="gate-failure-count.json")continue;let S=u(N(Z1,j));if(!S||typeof S!=="object")continue;if(!(("verdict"in S)||("approved"in S)||("reviewers"in S)))continue;Y1+=1;let I1=(S.verdict??"").toString().toLowerCase();if(S.approved===!0||["approved","approve","pass"].includes(I1))A1+=1;else if(["revision","revise","changes_requested","reject"].includes(I1))T1+=1}}return{phase:Q,iterationCount:$,iterations:V,totalInput:W,totalOutput:M,totalTokens:A,totalCost:I,totalDuration:P,budgetLimit:B,budgetUsed:U,gatesPassed:D,gatesTotal:a,gateFailures:_1,reviewsTotal:Y1,reviewsApproved:A1,reviewsRevision:T1}}function v0(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:C(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?C(z.totalTokens/$,0):0,avg_cost_per_iteration:$>0?C(z.totalCost/$,2):0,avg_duration_per_iteration:$>0?C(z.totalDuration/$,1):0},budget:{used:C(z.budgetUsed,2),limit:z.budgetLimit,percent:z.budgetLimit>0?C(z.budgetUsed/z.budgetLimit*100,1):0}};if(Q)X.iterations=z.iterations.map((V,W)=>({number:W+1,input_tokens:V.input_tokens??0,output_tokens:V.output_tokens??0,cost_usd:C(V.cost_usd??0,2),duration_seconds:V.duration_seconds??0}));let Z=JSON.stringify(X,null,2);function H(V,W){if(!W)return;let M=new RegExp(`("${V}": )(-?\\d+)(,?)$`,"m");Z=Z.replace(M,(A,I,P,B)=>`${I}${P}.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,(V,W,M,A)=>`${W}${M}.0${A}`);return Z}function u0(z,Q){let $=[];if($.push("Loki Mode Session Statistics"),$.push("============================"),$.push(""),$.push("Session"),$.push(` Iterations completed: ${z.iterationCount}`),$.push(` Duration: ${W1(z.totalDuration)}`),$.push(` Current phase: ${z.phase}`),$.push(""),$.push("Token Usage"),z.iterations.length>0)$.push(` Input tokens: ${p(z.totalInput)}`),$.push(` Output tokens: ${p(z.totalOutput)}`),$.push(` Total tokens: ${p(z.totalTokens)}`),$.push(` Estimated cost: $${c(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: ${p(X)}`),$.push(` Avg cost/iteration: $${c(Z,2)}`),$.push(` Avg duration/iteration: ${W1(H)}`)}else $.push(" N/A (no iteration metrics found)");if($.push(""),$.push("Budget"),z.budgetLimit>0){let X=C(z.budgetUsed/z.budgetLimit*100,1),Z=Number.isInteger(X)?`${X}.0`:`${X}`;$.push(` Used: $${c(z.budgetUsed,2)} / $${c(z.budgetLimit,2)} (${Z}%)`)}else if(z.budgetUsed>0)$.push(` Used: $${c(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,V=U1(p(X.input_tokens??0),10),W=U1(p(X.output_tokens??0),10),M=X.cost_usd??0,A=W1(X.duration_seconds??0),I=U1(`${H}`,3);$.push(` #${I} input: ${V} output: ${W} cost: $${c(M,2)} time: ${A}`)});return $.join(`
199
+ `)}function p1(z){let Q=!1,$=!1;for(let V of z)if(V==="--json")Q=!0;else if(V==="--efficiency")$=!0;let X=E();if(!B1(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?v0(Z,$):u0(Z,$)}}async function p0(z){let Q=p1(z);return console.log(Q.stdout),Q.exitCode}var d1=f(()=>{m();h()});var s1={};l(s1,{runDoctor:()=>z6,httpReachable:()=>M1,checkTool:()=>r1,checkSkills:()=>t1,checkDisk:()=>j1,buildDoctorJson:()=>a1});import{existsSync as c0,lstatSync as d0,readlinkSync as l0,statfsSync as o0}from"fs";import{homedir as o1}from"os";import{resolve as l1}from"path";function r0(z){let Q=z.match(n0);return Q?Q[1]:null}async function t0(z){try{let Q=await O([z,"--version"],{timeoutMs:5000}),$=(Q.stdout||Q.stderr||"").trim();return r0($)}catch{return null}}function n1(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,V=X[Z]??0;if(Number.isNaN(H)||Number.isNaN(V))return 0;if(H!==V)return H-V}return 0}async function r1(z,Q,$,X=null){let Z=await R(Q),H=Z!==null,V=H?await t0(Q):null,W="pass";if(!H)W=$==="required"?"fail":"warn";else if(X&&V){if(n1(V,X)<0)W=$==="required"?"fail":"warn"}return{name:z,command:Q,found:H,version:V,required:$,min_version:X,status:W,path:Z}}function j1(){let z=null;try{let $=o0(o1()),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 M1(z,Q=2000){try{return(await fetch(z,{signal:AbortSignal.timeout(Q)})).ok}catch{return!1}}async function q1(z,Q=!1){let $=`import ${z}`;if(!Q)return(await r($,{timeoutMs:5000})).exitCode===0;let X=await n();if(!X)return!1;return(await O([X,"-c",$],{timeoutMs:5000})).exitCode===0}function t1(){let z=o1();return i0.map(({name:Q,dir:$})=>{let X=l1(z,$),Z=X,H=l1(X,"SKILL.md");if(c0(H))return{name:Q,path:Z,status:"pass",detail:""};try{if(d0(X).isSymbolicLink()){let W="unknown";try{W=l0(X)}catch{}return{name:Q,path:Z,status:"fail",detail:`(broken symlink -> ${W})`}}}catch{}return{name:Q,path:Z,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function i1(){return Promise.all(a0.map(async(z)=>{return{...await r1(z.jsonName,z.cmd,z.required,z.min??null),displayName:z.displayName}}))}async function a1(){let Q=(await i1()).map(({displayName:V,...W})=>W),$=j1(),X=0,Z=0,H=0;for(let V of Q)if(V.status==="pass")X++;else if(V.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 G(z){switch(z){case"pass":return`${x}PASS${K}`;case"fail":return`${k}FAIL${K}`;case"warn":return`${T}WARN${K}`}}function J1(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` ${G(z.status)} ${$} - ${X}`}if(z.min_version&&z.version&&n1(z.version,z.min_version)<0){let X=z.required==="required"?"requires":"recommended";return` ${G(z.status)} ${$}${Q} - ${X} >= ${z.min_version}`}return` ${G(z.status)} ${$}${Q}`}function G1(z,Q){if(Q==="pass")z.pass++;else if(Q==="fail")z.fail++;else z.warn++}function s0(){process.stdout.write(`${F}loki doctor${K} - Check system prerequisites
201
+
202
+ `),process.stdout.write(`Usage: loki doctor [--json]
203
+
204
+ `),process.stdout.write(`Options:
205
+ `),process.stdout.write(` --json Output machine-readable JSON
206
+
207
+ `),process.stdout.write(`Checks: node, python3, jq, git, curl, bash version,
208
+ `),process.stdout.write(` claude/codex/gemini CLIs, and disk space.
209
+ `)}async function e0(){process.stdout.write(`${F}Loki Mode Doctor${K}
210
+
211
+ `),process.stdout.write(`Checking system prerequisites...
212
+
213
+ `);let z={pass:0,fail:0,warn:0},Q=await i1(),$=new Map(Q.map((U)=>[U.command,U]));process.stdout.write(`${J}Required:${K}
214
+ `);for(let U of["node","python3","jq","git","curl"]){let _=$.get(U);process.stdout.write(J1(_)+`
215
+ `),G1(z,_.status)}process.stdout.write(`
216
+ `),process.stdout.write(`${J}AI Providers:${K}
217
+ `);let X=["claude","codex","gemini","cline","aider"],Z=!1;for(let U of X){let _=$.get(U);if(process.stdout.write(J1(_)+`
218
+ `),G1(z,_.status),_.found)Z=!0}if(!Z)process.stdout.write(` ${G("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}
220
+ `),z.fail++;process.stdout.write(`
221
+ `),process.stdout.write(`${J}API Keys:${K}
222
+ `);let H=$.get("claude").found,V=$.get("codex").found,W=$.get("gemini").found,M=process.env;if(M.ANTHROPIC_API_KEY)process.stdout.write(` ${G("pass")} ANTHROPIC_API_KEY is set
223
+ `),z.pass++;else if(H)process.stdout.write(` ${Y} -- ${K} ANTHROPIC_API_KEY not set (Claude CLI uses its own login)
224
+ `);if(M.OPENAI_API_KEY)process.stdout.write(` ${G("pass")} OPENAI_API_KEY is set
225
+ `),z.pass++;else if(V)process.stdout.write(` ${Y} -- ${K} OPENAI_API_KEY not set (Codex CLI uses its own login)
226
+ `);if(M.GOOGLE_API_KEY||M.GEMINI_API_KEY)process.stdout.write(` ${G("pass")} GOOGLE_API_KEY is set
227
+ `),z.pass++;else if(W)process.stdout.write(` ${Y} -- ${K} GOOGLE_API_KEY not set (Gemini CLI uses its own login)
228
+ `);process.stdout.write(`
229
+ `),process.stdout.write(`${J}Skills:${K}
230
+ `);for(let U of t1())if(U.status==="pass")process.stdout.write(` ${G("pass")} ${U.name} ${Y}${U.path}${K}
231
+ `),z.pass++;else if(U.status==="fail")process.stdout.write(` ${G("fail")} ${U.name} ${Y}${U.detail}${K}
232
+ `),process.stdout.write(` ${T}Fix: loki setup-skill${K}
233
+ `),z.fail++;else process.stdout.write(` ${G("warn")} ${U.name} ${Y}${U.detail}${K}
234
+ `),z.warn++;if(process.stdout.write(`
235
+ `),process.stdout.write(`${J}Integrations:${K}
236
+ `),await q1("mcp"))process.stdout.write(` ${G("pass")} MCP SDK (Python)
237
+ `),z.pass++;else process.stdout.write(` ${G("warn")} MCP SDK - not installed (pip3 install mcp)
238
+ `),z.warn++;if(await q1("numpy",!0))process.stdout.write(` ${G("pass")} numpy (vector search)
239
+ `),z.pass++;else process.stdout.write(` ${G("warn")} numpy - not installed (pip3 install numpy)
240
+ `),z.warn++;if(await q1("sentence_transformers",!0))process.stdout.write(` ${G("pass")} sentence-transformers (embeddings)
241
+ `),z.pass++;else process.stdout.write(` ${G("warn")} sentence-transformers - not installed (loki memory vectors setup)
242
+ `),z.warn++;if(await M1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${G("pass")} ChromaDB server (port 8100)
243
+ `),z.pass++;else process.stdout.write(` ${G("warn")} ChromaDB - not running (docker start loki-chroma)
244
+ `),z.warn++;let A=process.env.LOKI_MIROFISH_URL;if(A)if(await M1(`${A}/health`))process.stdout.write(` ${G("pass")} MiroFish server (${A})
245
+ `),z.pass++;else process.stdout.write(` ${G("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
246
+ `),z.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${G("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
247
+ `),z.pass++;else process.stdout.write(` ${G("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
248
+ `),z.warn++;process.stdout.write(`
249
+ `),process.stdout.write(`${J}System:${K}
250
+ `);let I=$.get("bash");process.stdout.write(J1(I)+`
251
+ `),G1(z,I.status);let P=j1(),B=P.available_gb===null?null:Math.floor(P.available_gb);if(B===null)process.stdout.write(` ${G("warn")} Disk space: unable to determine
252
+ `),z.warn++;else if(P.status==="fail")process.stdout.write(` ${G("fail")} Disk space: ${B}GB available (need >= 1GB)
253
+ `),z.fail++;else if(P.status==="warn")process.stdout.write(` ${G("warn")} Disk space: ${B}GB available (low)
254
+ `),z.warn++;else process.stdout.write(` ${G("pass")} Disk space: ${B}GB available
255
+ `),z.pass++;if(process.stdout.write(`
256
+ `),process.stdout.write(`${F}Summary:${K} ${x}${z.pass} passed${K}, ${k}${z.fail} failed${K}, ${T}${z.warn} warnings${K}
257
+
258
+ `),z.fail>0)return process.stdout.write(`${k}Some required prerequisites are missing.${K}
259
+ `),process.stdout.write(`Install missing dependencies and run 'loki doctor' again.
260
+ `),1;if(z.warn>0)return process.stdout.write(`${T}All required checks passed with some warnings.${K}
261
+ `),0;return process.stdout.write(`${x}All checks passed. System is ready for Loki Mode.${K}
262
+ `),0}async function z6(z){let Q=!1;for(let $ of z)if($==="--json")Q=!0;else if($==="--help"||$==="-h")return s0(),0;else return process.stderr.write(`${k}Unknown option: ${$}${K}
263
+ `),process.stderr.write(`Usage: loki doctor [--json]
264
+ `),1;if(Q){let $=await a1();return process.stdout.write(JSON.stringify($,null,2)+`
265
+ `),0}return e0()}var n0,i0,a0;var e1=f(()=>{g();$1();h();n0=/(\d+\.\d+(?:\.\d+)*)/;i0=[{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"}];a0=[{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:"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"}]});import{readFileSync as K0}from"fs";import{resolve as O1,dirname as H0}from"path";import{fileURLToPath as V0}from"url";var W0=H0(V0(import.meta.url)),U0=O1(W0,"..",".."),e=null;function w1(){if(e===null)try{e=K0(O1(U0,"VERSION"),"utf-8").trim()}catch{e="unknown"}return e}function F1(){return process.stdout.write(`Loki Mode v${w1()}
266
+ `),0}g();h();m();import{readFileSync as _0,existsSync as Y0}from"fs";import{resolve as A0}from"path";var T0=["claude","codex","gemini","cline","aider"];function S1(){let z=A0(E(),"state","provider");if(!Y0(z))return"";try{return _0(z,"utf-8").trim()}catch{return""}}function I0(z,Q){return z||Q||process.env.LOKI_PROVIDER||"claude"}function O0(z){let Q=S1(),$=I0(z,Q);switch(process.stdout.write(`${F}Current Provider${K}
267
+ `),process.stdout.write(`
268
+ `),process.stdout.write(`${J}Provider:${K} ${$}
269
+ `),$){case"claude":process.stdout.write(`${x}Status:${K} Full features (subagents, parallel, MCP)
270
+ `);break;case"cline":process.stdout.write(`${x}Status:${K} Near-full mode (subagents, MCP, 12+ providers)
271
+ `);break;case"codex":case"gemini":case"aider":process.stdout.write(`${T}Status:${K} Degraded mode (sequential only)
272
+ `);break;default:break}if(Q)process.stdout.write(`${Y}(saved in .loki/state/provider)${K}
273
+ `);else process.stdout.write(`${Y}(default - not explicitly set)${K}
274
+ `);return process.stdout.write(`
275
+ `),process.stdout.write(`Switch provider: ${J}loki provider set <name>${K}
276
+ `),process.stdout.write(`Available: ${J}loki provider list${K}
277
+ `),0}async function w0(){let Q=S1()||process.env.LOKI_PROVIDER||"claude";process.stdout.write(`${F}Available Providers${K}
278
+ `),process.stdout.write(`
279
+ `);let $=await Promise.all(T0.map(async(H)=>[H,await R(H)!==null])),X=new Map;for(let[H,V]of $)X.set(H,V?`${x}installed${K}`:`${k}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,V]of Z){let W=Q===H?` ${J}(current)${K}`:"";process.stdout.write(` ${V} ${X.get(H)}${W}
280
+ `)}return process.stdout.write(`
281
+ `),process.stdout.write(`Set provider: ${J}loki provider set <name>${K}
282
+ `),0}function F0(){return process.stdout.write(`${F}Loki Mode Provider Management${K}
283
+ `),process.stdout.write(`
284
+ `),process.stdout.write(`Usage: loki provider <command>
285
+ `),process.stdout.write(`
286
+ `),process.stdout.write(`Commands:
287
+ `),process.stdout.write(` show Show current provider (default)
288
+ `),process.stdout.write(` set Set provider for this project
289
+ `),process.stdout.write(` list List available providers
290
+ `),process.stdout.write(` info Show provider details
291
+ `),process.stdout.write(` models Show resolved model configuration for all providers
292
+ `),process.stdout.write(`
293
+ `),process.stdout.write(`Examples:
294
+ `),process.stdout.write(` loki provider show
295
+ `),process.stdout.write(` loki provider set claude
296
+ `),process.stdout.write(` loki provider set codex
297
+ `),process.stdout.write(` loki provider list
298
+ `),process.stdout.write(` loki provider info gemini
299
+ `),process.stdout.write(` loki provider models
300
+ `),0}async function E1(z){let Q=z[0]??"show",$=z.slice(1);switch(Q){case"show":case"current":return O0($[0]);case"list":return w0();case"set":case"info":case"models":return L0(["provider",Q,...$]);default:return F0()}}async function L0(z){let{run:Q}=await Promise.resolve().then(() => (g(),L1)),{resolve:$}=await import("path"),{REPO_ROOT:X}=await Promise.resolve().then(() => (m(),k1)),Z=$(X,"autonomy","loki"),H=await Q([Z,...z],{env:{LOKI_LEGACY_BASH:"1"}});return process.stdout.write(H.stdout),process.stderr.write(H.stderr),H.exitCode}h();m();$1();g();import{existsSync as D1,readFileSync as P0}from"fs";import{resolve as v}from"path";import{mkdir as R0}from"fs/promises";var t=v(H1(),"learnings");function V1(z){if(!D1(z))return 0;try{let Q=P0(z,"utf-8"),$=0;for(let X of Q.split(`
301
+ `))if(X.includes('"description"'))$++;return $}catch{return 0}}async function k0(){await R0(t,{recursive:!0});let z=V1(v(t,"patterns.jsonl")),Q=V1(v(t,"mistakes.jsonl")),$=V1(v(t,"successes.jsonl"));return process.stdout.write(`${F}Cross-Project Learnings${K}
302
+ `),process.stdout.write(`
303
+ `),process.stdout.write(` Patterns: ${x}${z}${K}
304
+ `),process.stdout.write(` Mistakes: ${T}${Q}${K}
305
+ `),process.stdout.write(` Successes: ${J}${$}${K}
306
+ `),process.stdout.write(`
307
+ `),process.stdout.write(`Location: ${t}
308
+ `),process.stdout.write(`
309
+ `),process.stdout.write(`Use 'loki memory show <type>' to view entries
310
+ `),0}async function S0(z){if(z){let X=`
311
+ try:
312
+ from memory.layers import IndexLayer
313
+ layer = IndexLayer('.loki/memory')
314
+ layer.update([])
315
+ print('Index rebuilt')
316
+ except ImportError:
317
+ print('Error: memory.layers module not found')
318
+ except Exception as e:
319
+ print(f'Error: {e}')
320
+ `.trim(),Z=await r(X,{cwd:y});return process.stdout.write(Z.stdout),0}let Q=v(E(),"memory","index.json");if(!D1(Q))return process.stdout.write(`No index found
321
+ `),0;let $=await r(`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
322
+ `),0;return process.stdout.write($.stdout),0}async function b1(z){switch(z[0]??"list"){case"list":case"ls":return k0();case"index":return S0(z[1]==="rebuild");default:{let $=v(y,"autonomy","loki"),X=await O([$,"memory",...z],{env:{LOKI_LEGACY_BASH:"1"}});return process.stdout.write(X.stdout),process.stderr.write(X.stderr),X.exitCode}}}var z0=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
323
+
324
+ Usage: loki <command> [args...]
325
+
326
+ Phase 2 ported (Bun-native, fast):
327
+ version Print Loki Mode version
328
+ status [--json] Show current orchestrator status
329
+ stats [--json] [--efficiency] Session statistics
330
+ provider show [name] Show current provider
331
+ provider list List available providers and install status
332
+ memory list Cross-project learnings counts
333
+ memory index [rebuild] Show or rebuild memory index
334
+ doctor [--json] System prerequisites health check
335
+
336
+ All other commands fall through to the bash CLI (autonomy/loki).
337
+ Set LOKI_LEGACY_BASH=1 to force the bash CLI for every command.
338
+ `;async function $6(z){let Q=z[0],$=z.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(z0),0;case"version":case"--version":case"-v":return F1();case"provider":return E1($);case"memory":return b1($);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (m1(),h1));return X($)}case"stats":{let{runStats:X}=await Promise.resolve().then(() => (d1(),c1));return X($)}case"doctor":{let{runDoctor:X}=await Promise.resolve().then(() => (e1(),s1));return X($)}default:return process.stderr.write(`Unknown command: ${Q}
339
+ `),process.stderr.write(z0),2}}process.on("SIGINT",()=>process.exit(130));process.on("SIGTERM",()=>process.exit(143));var Q6=await $6(Bun.argv.slice(2));process.exit(Q6);
340
+
341
+ //# debugId=1CBFE5CD7E7E8D9B64756E2164756E21
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@loki-mode/orchestrator",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Loki Mode TypeScript orchestrator (Bun runtime). Parallel implementation alongside autonomy/run.sh during Phase 1 of the bash->Bun migration. See docs/architecture/ADR-001-runtime-migration.md.",
5
+ "private": true,
6
+ "type": "module",
7
+ "engines": {
8
+ "bun": ">=1.3.0"
9
+ },
10
+ "scripts": {
11
+ "version": "bun src/cli.ts version",
12
+ "typecheck": "bun run --bun tsc --noEmit",
13
+ "test": "bun test",
14
+ "bench": "bun run scripts/bench.ts",
15
+ "build": "bun run scripts/build.ts",
16
+ "build:binary": "bun build --compile src/cli.ts --outfile=dist/loki-ts"
17
+ },
18
+ "devDependencies": {
19
+ "@types/bun": "latest",
20
+ "typescript": "^5.6.0"
21
+ }
22
+ }
package/mcp/__init__.py CHANGED
@@ -57,4 +57,4 @@ try:
57
57
  except ImportError:
58
58
  __all__ = ['mcp']
59
59
 
60
- __version__ = '7.2.0'
60
+ __version__ = '7.3.0'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loki-mode",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
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",
@@ -59,7 +59,7 @@
59
59
  "license": "BUSL-1.1",
60
60
  "author": "Lokesh",
61
61
  "bin": {
62
- "loki": "autonomy/loki",
62
+ "loki": "bin/loki",
63
63
  "loki-mode": "bin/loki-mode.js"
64
64
  },
65
65
  "files": [
@@ -72,6 +72,9 @@
72
72
  "references/",
73
73
  "docs/**/*.md",
74
74
  "bin/",
75
+ "bin/loki",
76
+ "loki-ts/dist/",
77
+ "loki-ts/package.json",
75
78
  "api/",
76
79
  "events/",
77
80
  "memory/",
@@ -100,7 +103,7 @@
100
103
  ],
101
104
  "scripts": {
102
105
  "postinstall": "node bin/postinstall.js",
103
- "prepack": "find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null; find . -name '*.pyc' -delete 2>/dev/null; true",
106
+ "prepack": "find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null; find . -name '*.pyc' -delete 2>/dev/null; if command -v bun >/dev/null 2>&1; then (cd loki-ts && bun install --production && bun run build) || echo 'WARN: loki-ts build failed, using existing dist if present'; else echo 'WARN: bun not on PATH, skipping loki-ts build (using committed dist if present)'; fi; true",
104
107
  "prepublishOnly": "cd dashboard-ui && npm ci && npm run build:all",
105
108
  "test": "bash -n autonomy/run.sh && bash -n autonomy/loki && bash -n autonomy/completion-council.sh && bash -n autonomy/app-runner.sh && bash -n autonomy/prd-checklist.sh && bash -n autonomy/playwright-verify.sh && node --test tests/protocols/*.test.js && node --test tests/protocols/a2a/*.test.js && node --test tests/observability/*.test.js && node --test tests/policies/*.test.js && node --test tests/audit/*.test.js && node --test tests/integrations/*.test.js && node --test tests/integrations/jira/*.test.js && node --test tests/integrations/github/*.test.js && node --test tests/integrations/slack/*.test.js && bash tests/managed_memory/test_flag_matrix.sh && bash tests/managed_memory/test_sdk_isolation.sh && bash tests/managed_memory/test_kill_switch.sh && python3 -m unittest tests.managed_memory.test_shadow_write_mock tests.managed_memory.test_retrieve_mock && echo 'All checks passed'",
106
109
  "test:visual": "node --experimental-vm-modules node_modules/jest/bin/jest.js dashboard-ui/tests/visual-regression.test.js",