loki-mode 7.5.2 → 7.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/autonomy/loki +6 -3
- package/autonomy/run.sh +33 -1
- package/bin/loki +2 -1
- package/bin/loki-mode.js +4 -12
- package/dashboard/__init__.py +1 -1
- package/dashboard/server.py +106 -0
- package/docs/INSTALLATION.md +1 -1
- package/loki-ts/dist/loki.js +194 -134
- package/mcp/__init__.py +1 -1
- package/mcp/server.py +159 -0
- package/package.json +1 -1
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.
|
|
6
|
+
# Loki Mode v7.5.3
|
|
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.
|
|
325
|
+
**v7.5.3 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
7.5.
|
|
1
|
+
7.5.3
|
package/autonomy/loki
CHANGED
|
@@ -1346,13 +1346,16 @@ cmd_start() {
|
|
|
1346
1346
|
if [[ "$_auto_confirm" == "true" ]]; then
|
|
1347
1347
|
echo -e "${YELLOW}Warning: No PRD file specified. Auto-confirming (CI mode).${NC}"
|
|
1348
1348
|
else
|
|
1349
|
-
echo -e "${YELLOW}
|
|
1349
|
+
echo -e "${YELLOW}No PRD file specified.${NC}"
|
|
1350
1350
|
echo "Loki Mode will analyze the existing codebase and generate"
|
|
1351
1351
|
echo "a PRD automatically. No requirements document needed."
|
|
1352
1352
|
echo ""
|
|
1353
|
-
|
|
1353
|
+
# v7.5.3 UX: rephrased + default flipped from N to Y. The pre-v7.5.3
|
|
1354
|
+
# "Continue? [y/N]" with default-N caused users to accidentally
|
|
1355
|
+
# cancel by hitting Enter after reading the explanation.
|
|
1356
|
+
echo -e "Generate PRD from codebase and start? [Y/n] \c"
|
|
1354
1357
|
read -r confirm
|
|
1355
|
-
if [[
|
|
1358
|
+
if [[ "$confirm" =~ ^[Nn] ]]; then
|
|
1356
1359
|
echo "Aborted. Usage: loki start <path-to-prd.md>"
|
|
1357
1360
|
exit 0
|
|
1358
1361
|
fi
|
package/autonomy/run.sh
CHANGED
|
@@ -11011,10 +11011,36 @@ if __name__ == "__main__":
|
|
|
11011
11011
|
cr_count=$(track_gate_failure "code_review")
|
|
11012
11012
|
# BUG-QG-007: Always append to gate_failures regardless of escalation tier
|
|
11013
11013
|
# BUG-RUN-009: Write PAUSE to .loki/PAUSE (not .loki/signals/PAUSE)
|
|
11014
|
-
|
|
11014
|
+
# v7.5.3 Phase 1 hook: try the override council BEFORE
|
|
11015
|
+
# locking in the BLOCK / escalation. If counter-evidence
|
|
11016
|
+
# is supplied AND a trusted proofType, this lifts the
|
|
11017
|
+
# BLOCK and clears the code_review gate counter.
|
|
11018
|
+
# No-op when no counter-evidence file exists. Embedded
|
|
11019
|
+
# by default; opt out with LOKI_OVERRIDE_COUNCIL=0.
|
|
11020
|
+
local _phase1_overrode=false
|
|
11021
|
+
if [ "${LOKI_OVERRIDE_COUNCIL:-1}" != "0" ] && command -v bun >/dev/null 2>&1; then
|
|
11022
|
+
local _override_out
|
|
11023
|
+
_override_out=$(bun "${SCRIPT_DIR}/../loki-ts/dist/loki.js" internal phase1-hooks override "$ITERATION_COUNT" 2>/dev/null || true)
|
|
11024
|
+
case "$_override_out" in
|
|
11025
|
+
*"override: LIFTED"*)
|
|
11026
|
+
log_info "Phase 1 override council lifted code_review BLOCK"
|
|
11027
|
+
clear_gate_failure "code_review"
|
|
11028
|
+
cr_count=0
|
|
11029
|
+
_phase1_overrode=true
|
|
11030
|
+
;;
|
|
11031
|
+
esac
|
|
11032
|
+
fi
|
|
11033
|
+
if [ "$_phase1_overrode" = "true" ]; then
|
|
11034
|
+
: # BLOCK lifted; continue without escalation
|
|
11035
|
+
elif [ "$cr_count" -ge "$GATE_PAUSE_LIMIT" ]; then
|
|
11015
11036
|
log_error "Gate escalation: code_review failed $cr_count times (>= $GATE_PAUSE_LIMIT) - forcing PAUSE for human intervention"
|
|
11016
11037
|
echo "PAUSE" > "${TARGET_DIR:-.}/.loki/signals/GATE_ESCALATION"
|
|
11017
11038
|
echo "code_review gate failed $cr_count consecutive times" >> "${TARGET_DIR:-.}/.loki/signals/GATE_ESCALATION"
|
|
11039
|
+
# v7.5.3 Phase 1 hook: structured handoff doc before
|
|
11040
|
+
# bare PAUSE. Embedded; opt out LOKI_HANDOFF_MD=0.
|
|
11041
|
+
if [ "${LOKI_HANDOFF_MD:-1}" != "0" ] && command -v bun >/dev/null 2>&1; then
|
|
11042
|
+
bun "${SCRIPT_DIR}/../loki-ts/dist/loki.js" internal phase1-hooks handoff code_review "$cr_count" "$ITERATION_COUNT" 2>/dev/null || true
|
|
11043
|
+
fi
|
|
11018
11044
|
touch "${TARGET_DIR:-.}/.loki/PAUSE"
|
|
11019
11045
|
gate_failures="${gate_failures}code_review_PAUSED,"
|
|
11020
11046
|
elif [ "$cr_count" -ge "$GATE_ESCALATE_LIMIT" ]; then
|
|
@@ -11028,6 +11054,12 @@ if __name__ == "__main__":
|
|
|
11028
11054
|
gate_failures="${gate_failures}code_review,"
|
|
11029
11055
|
log_warn "Code review BLOCKED ($cr_count consecutive) - Critical/High findings"
|
|
11030
11056
|
fi
|
|
11057
|
+
# v7.5.3 Phase 1 hook: persist structured findings +
|
|
11058
|
+
# auto-write learnings (one shell-out per iteration).
|
|
11059
|
+
# Best-effort; never fails the main loop.
|
|
11060
|
+
if [ "${LOKI_INJECT_FINDINGS:-1}" != "0" ] && command -v bun >/dev/null 2>&1; then
|
|
11061
|
+
bun "${SCRIPT_DIR}/../loki-ts/dist/loki.js" internal phase1-hooks reflect "$ITERATION_COUNT" 2>/dev/null || true
|
|
11062
|
+
fi
|
|
11031
11063
|
fi
|
|
11032
11064
|
fi
|
|
11033
11065
|
# Documentation staleness check (v6.75.0)
|
package/bin/loki
CHANGED
|
@@ -103,8 +103,9 @@ fi
|
|
|
103
103
|
# Two-token routes (provider show/list, memory list/index) match on the first
|
|
104
104
|
# token only; the Bun dispatcher handles subcommand routing internally.
|
|
105
105
|
case "${1:-}" in
|
|
106
|
-
version|--version|-v|status|stats|doctor|provider|memory|rollback)
|
|
106
|
+
version|--version|-v|status|stats|doctor|provider|memory|rollback|internal)
|
|
107
107
|
# v7.5.2: rollback added (wires loki-ts/src/commands/rollback.ts).
|
|
108
|
+
# v7.5.3: internal added for autonomy/run.sh phase1-hooks calls.
|
|
108
109
|
exec bun "$BUN_CLI" "$@"
|
|
109
110
|
;;
|
|
110
111
|
*)
|
package/bin/loki-mode.js
CHANGED
|
@@ -13,18 +13,10 @@
|
|
|
13
13
|
const { spawn } = require('child_process');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
!process.env.LOKI_NO_BANNER &&
|
|
21
|
-
!process.env.NO_COLOR
|
|
22
|
-
) {
|
|
23
|
-
process.stderr.write(
|
|
24
|
-
'[loki-mode] DEPRECATED: this binary is being removed in v8.0.0. ' +
|
|
25
|
-
'Use `loki` instead -- same behaviour, shorter name.\n',
|
|
26
|
-
);
|
|
27
|
-
}
|
|
16
|
+
// v7.5.3: dropped the per-invocation deprecation banner per the
|
|
17
|
+
// "embedded by default, no commands required" UX mandate. Muscle-memory
|
|
18
|
+
// users continue to work with no friction; the wrapper is removed in
|
|
19
|
+
// v8.0.0 along with the rest of the bash sunset.
|
|
28
20
|
|
|
29
21
|
const shim = path.join(__dirname, 'loki');
|
|
30
22
|
const args = process.argv.slice(2);
|
package/dashboard/__init__.py
CHANGED
package/dashboard/server.py
CHANGED
|
@@ -5794,6 +5794,112 @@ async def list_managed_memory_versions(memory_id: str):
|
|
|
5794
5794
|
return {"memory_id": memory_id, "versions": items, "count": len(items)}
|
|
5795
5795
|
|
|
5796
5796
|
|
|
5797
|
+
# ---------------------------------------------------------------------------
|
|
5798
|
+
# Phase 1 artifact endpoints (v7.5.3) -- read-only inspectors.
|
|
5799
|
+
# ---------------------------------------------------------------------------
|
|
5800
|
+
|
|
5801
|
+
|
|
5802
|
+
@app.get("/api/findings/{iteration}")
|
|
5803
|
+
async def get_findings(iteration: int):
|
|
5804
|
+
"""Read structured code-review findings for a given iteration."""
|
|
5805
|
+
base = _get_loki_dir()
|
|
5806
|
+
persisted = base / "state" / f"findings-{iteration}.json"
|
|
5807
|
+
if persisted.exists():
|
|
5808
|
+
data = _safe_json_read(persisted, default=None)
|
|
5809
|
+
if data is not None:
|
|
5810
|
+
return data
|
|
5811
|
+
reviews_dir = base / "quality" / "reviews"
|
|
5812
|
+
if reviews_dir.exists():
|
|
5813
|
+
candidates = sorted(
|
|
5814
|
+
d.name for d in reviews_dir.iterdir()
|
|
5815
|
+
if d.is_dir() and d.name.startswith("review-")
|
|
5816
|
+
and d.name.endswith(f"-{iteration}")
|
|
5817
|
+
)
|
|
5818
|
+
if candidates:
|
|
5819
|
+
review_dir = reviews_dir / candidates[-1]
|
|
5820
|
+
agg = _safe_json_read(review_dir / "aggregate.json", default=None)
|
|
5821
|
+
return {
|
|
5822
|
+
"iteration": iteration,
|
|
5823
|
+
"review_id": agg.get("review_id") if isinstance(agg, dict) else candidates[-1],
|
|
5824
|
+
"findings": [],
|
|
5825
|
+
"note": "findings-<iter>.json not found; review dir present",
|
|
5826
|
+
}
|
|
5827
|
+
raise HTTPException(status_code=404,
|
|
5828
|
+
detail=f"No findings for iteration {iteration}")
|
|
5829
|
+
|
|
5830
|
+
|
|
5831
|
+
@app.get("/api/learnings")
|
|
5832
|
+
async def get_learnings(limit: int = 50):
|
|
5833
|
+
"""Read recent learnings (newest first)."""
|
|
5834
|
+
base = _get_loki_dir()
|
|
5835
|
+
path = base / "state" / "relevant-learnings.json"
|
|
5836
|
+
if not path.exists():
|
|
5837
|
+
return {"version": 1, "learnings": [], "total": 0}
|
|
5838
|
+
data = _safe_json_read(path, default={})
|
|
5839
|
+
if not isinstance(data, dict):
|
|
5840
|
+
return {"version": 1, "learnings": [], "total": 0}
|
|
5841
|
+
learnings = data.get("learnings", [])
|
|
5842
|
+
if not isinstance(learnings, list):
|
|
5843
|
+
learnings = []
|
|
5844
|
+
limit_clamped = max(1, int(limit)) if isinstance(limit, int) else 50
|
|
5845
|
+
sliced = list(reversed(learnings))[:limit_clamped]
|
|
5846
|
+
return {"version": data.get("version", 1), "total": len(learnings),
|
|
5847
|
+
"learnings": sliced}
|
|
5848
|
+
|
|
5849
|
+
|
|
5850
|
+
@app.get("/api/escalations")
|
|
5851
|
+
async def list_escalations():
|
|
5852
|
+
"""List handoff documents under .loki/escalations/."""
|
|
5853
|
+
base = _get_loki_dir()
|
|
5854
|
+
esc_dir = base / "escalations"
|
|
5855
|
+
if not esc_dir.exists():
|
|
5856
|
+
return {"escalations": []}
|
|
5857
|
+
items = []
|
|
5858
|
+
try:
|
|
5859
|
+
for entry in sorted(esc_dir.iterdir(),
|
|
5860
|
+
key=lambda p: p.name, reverse=True):
|
|
5861
|
+
if not entry.name.endswith(".md"):
|
|
5862
|
+
continue
|
|
5863
|
+
try:
|
|
5864
|
+
stat = entry.stat()
|
|
5865
|
+
items.append({
|
|
5866
|
+
"filename": entry.name,
|
|
5867
|
+
"size_bytes": stat.st_size,
|
|
5868
|
+
"modified_at": (
|
|
5869
|
+
__import__("datetime").datetime
|
|
5870
|
+
.fromtimestamp(stat.st_mtime,
|
|
5871
|
+
tz=__import__("datetime").timezone.utc)
|
|
5872
|
+
.isoformat()
|
|
5873
|
+
),
|
|
5874
|
+
})
|
|
5875
|
+
except OSError:
|
|
5876
|
+
continue
|
|
5877
|
+
except OSError:
|
|
5878
|
+
pass
|
|
5879
|
+
return {"escalations": items}
|
|
5880
|
+
|
|
5881
|
+
|
|
5882
|
+
@app.get("/api/escalations/{filename}")
|
|
5883
|
+
async def get_escalation(filename: str):
|
|
5884
|
+
"""Read one handoff document. Path-traversal-safe."""
|
|
5885
|
+
if "/" in filename or "\\" in filename or filename.startswith("."):
|
|
5886
|
+
raise HTTPException(status_code=400, detail="invalid filename")
|
|
5887
|
+
if not filename.endswith(".md"):
|
|
5888
|
+
raise HTTPException(status_code=400,
|
|
5889
|
+
detail="only .md handoffs are served")
|
|
5890
|
+
base = _get_loki_dir()
|
|
5891
|
+
path = base / "escalations" / filename
|
|
5892
|
+
if not path.exists():
|
|
5893
|
+
raise HTTPException(status_code=404,
|
|
5894
|
+
detail=f"handoff not found: {filename}")
|
|
5895
|
+
try:
|
|
5896
|
+
body = _safe_read_text(path)
|
|
5897
|
+
except OSError as exc:
|
|
5898
|
+
raise HTTPException(status_code=500,
|
|
5899
|
+
detail=f"read failed: {exc}") from exc
|
|
5900
|
+
return PlainTextResponse(content=body, media_type="text/markdown")
|
|
5901
|
+
|
|
5902
|
+
|
|
5797
5903
|
# ---------------------------------------------------------------------------
|
|
5798
5904
|
# SPA catch-all: serve index.html for any path not matched by API routes
|
|
5799
5905
|
# or static asset mounts. This lets the dashboard UI handle client-side routing.
|
package/docs/INSTALLATION.md
CHANGED
package/loki-ts/dist/loki.js
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
2
|
+
var Z6=Object.defineProperty;var X6=($)=>$;function z6($,Z){this[$]=X6.bind(null,Z)}var b=($,Z)=>{for(var Q in Z)Z6($,Q,{get:Z[Q],enumerable:!0,configurable:!0,set:z6.bind(Z,Q)})};var E=($,Z)=>()=>($&&(Z=$($=0)),Z);var V1=import.meta.require;var a1={};b(a1,{lokiDir:()=>F,homeLokiDir:()=>L1,findSkillDir:()=>U6,findRepoRootForVersion:()=>P1,REPO_ROOT:()=>g});import{resolve as y,dirname as I1}from"path";import{fileURLToPath as K6}from"url";import{existsSync as a}from"fs";import{homedir as n1}from"os";function q6(){let $=o1;for(let Z=0;Z<6;Z++){if(a(y($,"VERSION"))&&a(y($,"autonomy/run.sh")))return $;let Q=I1($);if(Q===$)break;$=Q}return y(o1,"..","..","..")}function P1($){let Z=$;for(let Q=0;Q<6;Q++){if(a(y(Z,"VERSION"))&&a(y(Z,"autonomy/run.sh")))return Z;let X=I1(Z);if(X===Z)break;Z=X}return y($,"..","..","..")}function F(){return process.env.LOKI_DIR??y(process.cwd(),".loki")}function L1(){return y(n1(),".loki")}function U6(){let $=[g,y(n1(),".claude/skills/loki-mode"),process.cwd()];for(let Z of $)if(a(y(Z,"SKILL.md"))&&a(y(Z,"autonomy/run.sh")))return Z;return null}var o1,g;var f=E(()=>{o1=I1(K6(import.meta.url));g=q6()});var t1={};b(t1,{runOrThrow:()=>J6,run:()=>S,commandVersion:()=>M6,commandExists:()=>v,ShellError:()=>F1});async function S($,Z={}){let Q=Bun.spawn({cmd:[...$],stdout:"pipe",stderr:"pipe",env:Z.env?{...process.env,...Z.env}:process.env,cwd:Z.cwd}),X,z;if(Z.timeoutMs&&Z.timeoutMs>0)X=setTimeout(()=>{try{Q.kill("SIGTERM")}catch{}z=setTimeout(()=>{try{Q.kill("SIGKILL")}catch{}},2000)},Z.timeoutMs);try{let[K,q,V]=await Promise.all([new Response(Q.stdout).text(),new Response(Q.stderr).text(),Q.exited]);return{stdout:K,stderr:q,exitCode:V}}finally{if(X)clearTimeout(X);if(z)clearTimeout(z)}}async function J6($,Z={}){let Q=await S($,Z);if(Q.exitCode!==0)throw new F1(`command failed (${Q.exitCode}): ${$.join(" ")}`,Q.exitCode,Q.stdout,Q.stderr);return Q}async function v($){let Z=B6($),Q=await S(["sh","-c",`command -v ${Z}`],{timeoutMs:5000});if(Q.exitCode===0)return Q.stdout.trim()||null;return null}function B6($){if(!/^[A-Za-z0-9._/-]+$/.test($))throw Error(`refused to shell-escape suspect token: ${$}`);return $}async function M6($,Z="--version"){if(!await v($))return null;let X=await S([$,Z],{timeoutMs:5000});if(X.exitCode!==0)return null;return((X.stdout||X.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var F1;var m=E(()=>{F1=class F1 extends Error{message;exitCode;stdout;stderr;constructor($,Z,Q,X){super($);this.message=$;this.exitCode=Z;this.stdout=Q;this.stderr=X;this.name="ShellError"}}});function u($){return Y6?"":$}var Y6,P,C,w,E5,A,D,L,U;var d=E(()=>{Y6=(process.env.NO_COLOR??"").length>0;P=u("\x1B[0;31m"),C=u("\x1B[0;32m"),w=u("\x1B[1;33m"),E5=u("\x1B[0;34m"),A=u("\x1B[0;36m"),D=u("\x1B[1m"),L=u("\x1B[2m"),U=u("\x1B[0m")});import{existsSync as w6}from"fs";async function s(){if($1!==void 0)return $1;let $="/opt/homebrew/bin/python3.12";if(w6($))return $1=$,$;let Z=await v("python3.12");if(Z)return $1=Z,Z;let Q=await v("python3");return $1=Q,Q}async function o($,Z={}){let Q=await s();if(!Q)return{stdout:"",stderr:"python3 not found",exitCode:127};return S([Q,"-c",$],Z)}var $1;var Q1=E(()=>{m()});var V0={};b(V0,{runStatus:()=>f6});import{existsSync as N,readFileSync as X1,readdirSync as Z0,statSync as X0}from"fs";import{resolve as x,basename as N6}from"path";async function k6(){if(await v("jq"))return!0;return process.stdout.write(`${P}Error: jq is required but not installed.${U}
|
|
3
3
|
`),process.stdout.write(`Install with:
|
|
4
4
|
`),process.stdout.write(` brew install jq (macOS)
|
|
5
5
|
`),process.stdout.write(` apt install jq (Debian/Ubuntu)
|
|
6
6
|
`),process.stdout.write(` yum install jq (RHEL/CentOS)
|
|
7
|
-
`),!1}function
|
|
7
|
+
`),!1}function H1($){if(!Number.isFinite($)||$<=0)return!1;try{return process.kill($,0),!0}catch{return!1}}function W1($){if(!N($))return null;try{let Z=X1($,"utf-8").trim();if(!Z)return null;let Q=Number.parseInt(Z,10);return Number.isFinite(Q)?Q:null}catch{return null}}function C6($){let Z=[],Q=W1(x($,"loki.pid"));if(Q!==null&&H1(Q))Z.push(`global:${Q}`);let X=x($,"sessions");if(N(X)){let z=[];try{z=Z0(X)}catch{z=[]}for(let K of z){let q=x(X,K);try{if(!X0(q).isDirectory())continue}catch{continue}let V=x(q,"loki.pid"),H=W1(V);if(H!==null&&H1(H))Z.push(`${K}:${H}`)}}if(N($)){let z=[];try{z=Z0($)}catch{z=[]}for(let K of z){if(!K.startsWith("run-")||!K.endsWith(".pid"))continue;let q=x($,K);try{if(!X0(q).isFile())continue}catch{continue}let V=N6(K,".pid").slice(4),H=W1(q);if(H!==null&&H1(H)){if(!Z.some((G)=>G.startsWith(`${V}:`)))Z.push(`${V}:${H}`)}}}return Z}async function z0($,Z){let Q=await S(["jq","-r",$,Z]);if(Q.exitCode!==0)return null;return Q.stdout.trim()}function K0($,Z){try{let Q=X1($,"utf-8"),z=JSON.parse(Q)[Z];if(typeof z==="number"){if(Z==="budget_used"){let K=Math.round(z*100)/100;if(Number.isInteger(K))return String(K);return String(K)}return String(z)}if(z===void 0||z===null)return"0";return String(z)}catch{return"0"}}function q0($,Z,Q){try{let X=X1($,"utf-8"),K=JSON.parse(X)[Z];if(typeof K==="number"&&Number.isFinite(K))return K;return Q}catch{return Q}}async function b6(){let $=F();if(!await k6())return 1;if(!N($))return process.stdout.write(`${D}Loki Mode Status${U}
|
|
8
8
|
`),process.stdout.write(`
|
|
9
|
-
`),process.stdout.write(`${
|
|
9
|
+
`),process.stdout.write(`${w}No active session found.${U}
|
|
10
10
|
`),process.stdout.write(`Loki Mode has not been initialized in this directory.
|
|
11
11
|
`),process.stdout.write(`
|
|
12
12
|
`),process.stdout.write(`To start a session:
|
|
13
13
|
`),process.stdout.write(` loki start <prd> - Start with a PRD file
|
|
14
14
|
`),process.stdout.write(` loki start - Start without a PRD
|
|
15
15
|
`),process.stdout.write(`
|
|
16
|
-
`),process.stdout.write(`${
|
|
17
|
-
`),0;process.stdout.write(`${
|
|
16
|
+
`),process.stdout.write(`${L}Current directory: ${process.cwd()}${U}
|
|
17
|
+
`),0;process.stdout.write(`${D}Loki Mode Status${U}
|
|
18
18
|
`),process.stdout.write(`
|
|
19
|
-
`);let Z="",Q=
|
|
20
|
-
`),process.stdout.write(`${
|
|
19
|
+
`);let Z="",Q=x($,"state","provider");if(N(Q))try{Z=X1(Q,"utf-8").trim()}catch{Z=""}let X=Z||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(`${A}Provider:${U} ${X} (${z})
|
|
20
|
+
`),process.stdout.write(`${L} Switch with: loki provider set <claude|codex|gemini|cline|aider>${U}
|
|
21
21
|
`),process.stdout.write(`
|
|
22
|
-
`);let
|
|
23
|
-
`);for(let J of
|
|
24
|
-
`);else process.stdout.write(` ${
|
|
22
|
+
`);let K=C6($);if(K.length>0){process.stdout.write(`${C}Active Sessions: ${K.length}${U}
|
|
23
|
+
`);for(let J of K){let Y=J.indexOf(":"),_=Y>=0?J.slice(0,Y):J,I=Y>=0?J.slice(Y+1):"";if(_==="global")process.stdout.write(` ${A}[global]${U} PID ${I}
|
|
24
|
+
`);else process.stdout.write(` ${A}[#${_}]${U} PID ${I}
|
|
25
25
|
`)}process.stdout.write(`
|
|
26
|
-
`),process.stdout.write(`${
|
|
27
|
-
`),process.stdout.write(`${
|
|
26
|
+
`),process.stdout.write(`${L} Stop specific: loki stop <session-id>${U}
|
|
27
|
+
`),process.stdout.write(`${L} Stop all: loki stop${U}
|
|
28
28
|
`),process.stdout.write(`
|
|
29
|
-
`)}if(
|
|
30
|
-
`),process.stdout.write(`${
|
|
29
|
+
`)}if(N(x($,"PAUSE")))process.stdout.write(`${w}Status: PAUSED${U}
|
|
30
|
+
`),process.stdout.write(`${L} Resume with: loki resume${U}
|
|
31
31
|
`),process.stdout.write(`
|
|
32
|
-
`);else if(
|
|
33
|
-
`),process.stdout.write(`${
|
|
32
|
+
`);else if(N(x($,"STOP")))process.stdout.write(`${P}Status: STOPPED${U}
|
|
33
|
+
`),process.stdout.write(`${L} Clear with: loki resume${U}
|
|
34
34
|
`),process.stdout.write(`
|
|
35
|
-
`);let
|
|
36
|
-
`);try{process.stdout.write(
|
|
37
|
-
`)}let
|
|
38
|
-
`);let J=await
|
|
39
|
-
`)}let
|
|
40
|
-
`)}let
|
|
41
|
-
`);else process.stdout.write(`${
|
|
42
|
-
`)}let
|
|
43
|
-
`)}let
|
|
44
|
-
`)}}return process.stdout.write(`
|
|
45
|
-
`),process.stdout.write(`${
|
|
46
|
-
`),process.stdout.write(`${
|
|
47
|
-
`),0}async function
|
|
48
|
-
|
|
49
|
-
`),
|
|
50
|
-
`),0;
|
|
35
|
+
`);let q=x($,"STATUS.txt");if(N(q)){process.stdout.write(`${A}Session Info:${U}
|
|
36
|
+
`);try{process.stdout.write(X1(q,"utf-8"))}catch{}process.stdout.write(`
|
|
37
|
+
`)}let V=x($,"state","orchestrator.json");if(N(V)){process.stdout.write(`${A}Orchestrator State:${U}
|
|
38
|
+
`);let J=await z0('.currentPhase // "unknown"',V);process.stdout.write(`${J??"unknown"}
|
|
39
|
+
`)}let H=x($,"queue","pending.json");if(N(H)){let J=await z0('if type == "array" then length elif .tasks then .tasks | length else 0 end',H);process.stdout.write(`${A}Pending Tasks:${U} ${J??"0"}
|
|
40
|
+
`)}let W=x($,"metrics","budget.json");if(N(W)){let J=K0(W,"budget_limit"),Y=K0(W,"budget_used");if(J!=="0")process.stdout.write(`${A}Budget:${U} $${Y} / $${J}
|
|
41
|
+
`);else process.stdout.write(`${A}Cost:${U} $${Y} (no limit)
|
|
42
|
+
`)}let G=x($,"state","context-usage.json");if(N(G)){let J=q0(G,"window_size",200000),Y=q0(G,"used_tokens",0),_=0;if(J>0)_=Math.floor(Y*100/J);process.stdout.write(`${A}Context:${U} ${_}% (${Y} / ${J} tokens)
|
|
43
|
+
`)}let B=x($,"dashboard","dashboard.pid");if(N(B)){let J=W1(B);if(J!==null&&H1(J)){let Y=process.env.LOKI_DASHBOARD_PORT||"57374";process.stdout.write(`${A}Dashboard:${U} http://127.0.0.1:${Y}/
|
|
44
|
+
`)}}return await y6($),process.stdout.write(`
|
|
45
|
+
`),process.stdout.write(`${L} Tip: loki context show - detailed token breakdown${U}
|
|
46
|
+
`),process.stdout.write(`${L} Tip: loki code overview - codebase intelligence${U}
|
|
47
|
+
`),0}async function y6($){let Z=x($,"state"),Q=v6(Z),X=x(Z,"relevant-learnings.json"),z=x($,"escalations"),K=Q.length>0,q=N(X),V=N(z);if(!K&&!q&&!V)return;if(process.stdout.write(`
|
|
48
|
+
${A}Phase 1 artifacts:${U}
|
|
49
|
+
`),K){let H=Q[Q.length-1],W=U0(H);if(W&&Array.isArray(W.findings)){let G={Critical:0,High:0,Medium:0,Low:0};for(let J of W.findings){let Y=String(J.severity??"");if(Y in G)G[Y]=(G[Y]??0)+1}let B=Object.entries(G).filter(([,J])=>J>0).map(([J,Y])=>`${Y} ${J.toLowerCase()}`).join(", ");process.stdout.write(` Findings (iter ${W.iteration??"?"}): ${B||"none"} -- ${W.findings.length} total
|
|
50
|
+
`)}}if(q){let H=U0(X);if(H&&Array.isArray(H.learnings)&&H.learnings.length>0){let W=new Map;for(let B of H.learnings){let J=String(B.trigger??"unknown");W.set(J,(W.get(J)??0)+1)}let G=[...W.entries()].sort((B,J)=>J[1]-B[1]).slice(0,3).map(([B,J])=>`${J} ${B}`).join(", ");process.stdout.write(` Learnings: ${H.learnings.length} total (${G})
|
|
51
|
+
`)}}if(V){let H=0,W="";try{let B=(await import("fs")).readdirSync(z).filter((J)=>J.endsWith(".md"));if(H=B.length,B.length>0)B.sort(),W=B[B.length-1]??""}catch{}if(H>0)process.stdout.write(` Escalations: ${H} handoff doc${H===1?"":"s"} (latest: ${W})
|
|
52
|
+
`)}}function v6($){if(!N($))return[];try{return V1("fs").readdirSync($).filter((X)=>/^findings-\d+\.json$/.test(X)).sort((X,z)=>{let K=Number.parseInt(X.replace(/[^0-9]/g,""),10)||0,q=Number.parseInt(z.replace(/[^0-9]/g,""),10)||0;return K-q}).map((X)=>x($,X))}catch{return[]}}function U0($){try{let Z=V1("fs");return JSON.parse(Z.readFileSync($,"utf-8"))}catch{return null}}async function h6(){let $=await s();if(!$)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
53
|
+
`),1;let Z=g,Q=F(),X=process.env.LOKI_DASHBOARD_PORT||"57374",z=process.env.LOKI_PROVIDER||"claude",K=await S([$,"-c",D6,Z,Q,X,z],{timeoutMs:30000});if(K.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
54
|
+
`),1;return process.stdout.write(K.stdout),0}async function f6($){let Z=[...$];while(Z.length>0){let Q=Z[0];if(Q==="--json")return h6();if(Q==="--help"||Q==="-h")return process.stdout.write(`Usage: loki status [--json]
|
|
55
|
+
`),0;return process.stdout.write(`${P}Unknown flag: ${Q}${U}
|
|
51
56
|
`),process.stdout.write(`Usage: loki status [--json]
|
|
52
|
-
`),1}return
|
|
57
|
+
`),1}return b6()}var D6=`
|
|
53
58
|
import json, os, sys, time
|
|
54
59
|
|
|
55
60
|
skill_dir = sys.argv[1]
|
|
@@ -195,9 +200,9 @@ if os.path.isdir(queue_dir):
|
|
|
195
200
|
result['task_counts'] = task_counts
|
|
196
201
|
|
|
197
202
|
print(json.dumps(result, indent=2))
|
|
198
|
-
`;var
|
|
199
|
-
`)}function
|
|
200
|
-
Start a session with: loki start <prd>`}}let z=
|
|
203
|
+
`;var H0=E(()=>{m();Q1();d();f()});var B0={};b(B0,{runStats:()=>l6,computeStats:()=>J0});import{readdirSync as W0,readFileSync as g6,statSync as G0}from"fs";import{join as p}from"path";function t($){try{if(!G0($).isFile())return null;return JSON.parse(g6($,"utf-8"))}catch{return null}}function E1($){try{return G0($).isDirectory()}catch{return!1}}function m6($){if(!E1($))return[];try{let Z=W0($).filter((Q)=>Q.startsWith("iteration-")&&Q.endsWith(".json"));return Z.sort(),Z.map((Q)=>p($,Q))}catch{return[]}}function i($){return Math.trunc($).toLocaleString("en-US")}function x1($){let Z=Math.trunc($);if(Z<60)return`${Z}s`;let Q=Math.trunc(Z/3600),X=Math.trunc(Z%3600/60),z=Z%60;if(Q>0)return`${Q}h ${String(X).padStart(2,"0")}m`;return`${X}m ${String(z).padStart(2,"0")}s`}function c($,Z=0){let Q=Math.pow(10,Z);return Math.round($*Q)/Q}function e($,Z){return $.toFixed(Z)}function R1($,Z){return $.length>=Z?$:$+" ".repeat(Z-$.length)}function u6($){let Z="N/A",Q=0,X=t(p($,"state","orchestrator.json"));if(X&&typeof X==="object"){if(typeof X.currentPhase==="string")Z=X.currentPhase;if(typeof X.currentIteration==="number")Q=X.currentIteration}let z=p($,"metrics","efficiency"),K=m6(z),q=[];for(let T of K){let j=t(T);if(j&&typeof j==="object")q.push(j)}if(q.length>0)Q=Math.max(Q,q.length);let V=q.reduce((T,j)=>T+(j.input_tokens??0),0),H=q.reduce((T,j)=>T+(j.output_tokens??0),0),W=V+H,G=q.reduce((T,j)=>T+(j.cost_usd??0),0),B=q.reduce((T,j)=>T+(j.duration_seconds??0),0),J=0,Y=0,_=t(p($,"metrics","budget.json"));if(_&&typeof _==="object"){if(typeof _.budget_limit==="number")J=_.budget_limit;if(typeof _.budget_used==="number")Y=_.budget_used}let I=0,R=0,O=t(p($,"state","quality-gates.json"));if(O&&typeof O==="object"){if(Array.isArray(O)){for(let T of O)if(R+=1,T===!0)I+=1;else if(T&&typeof T==="object"){let j=T;if(j.passed===!0||j.status==="passed")I+=1}}else for(let T of Object.values(O))if(typeof T==="boolean"){if(R+=1,T)I+=1}else if(T&&typeof T==="object"){R+=1;let j=T;if(j.passed===!0||j.status==="passed")I+=1}}let k={},U1=t(p($,"quality","gate-failure-count.json"));if(U1&&typeof U1==="object"&&!Array.isArray(U1)){let T={};for(let[j,h]of Object.entries(U1))if(typeof h==="number")T[j]=h;k=T}let p1=0,c1=0,l1=0,_1=p($,"quality");if(E1(_1)){let T=[];try{T=W0(_1)}catch{T=[]}for(let j of T){if(!j.endsWith(".json")||j==="gate-failure-count.json")continue;let h=t(p(_1,j));if(!h||typeof h!=="object")continue;if(!(("verdict"in h)||("approved"in h)||("reviewers"in h)))continue;p1+=1;let d1=(h.verdict??"").toString().toLowerCase();if(h.approved===!0||["approved","approve","pass"].includes(d1))c1+=1;else if(["revision","revise","changes_requested","reject"].includes(d1))l1+=1}}return{phase:Z,iterationCount:Q,iterations:q,totalInput:V,totalOutput:H,totalTokens:W,totalCost:G,totalDuration:B,budgetLimit:J,budgetUsed:Y,gatesPassed:I,gatesTotal:R,gateFailures:k,reviewsTotal:p1,reviewsApproved:c1,reviewsRevision:l1}}function p6($,Z){let Q=$.iterationCount,X={session:{iterations:Q,duration_seconds:$.totalDuration,phase:$.phase},tokens:{input:$.totalInput,output:$.totalOutput,total:$.totalTokens,cost_usd:c($.totalCost,2)},quality:{gates_passed:$.gatesPassed,gates_total:$.gatesTotal,reviews_total:$.reviewsTotal,reviews_approved:$.reviewsApproved,reviews_revision:$.reviewsRevision,gate_failures:$.gateFailures},efficiency:{avg_tokens_per_iteration:Q>0?c($.totalTokens/Q,0):0,avg_cost_per_iteration:Q>0?c($.totalCost/Q,2):0,avg_duration_per_iteration:Q>0?c($.totalDuration/Q,1):0},budget:{used:c($.budgetUsed,2),limit:$.budgetLimit,percent:$.budgetLimit>0?c($.budgetUsed/$.budgetLimit*100,1):0}};if(Z)X.iterations=$.iterations.map((q,V)=>({number:V+1,input_tokens:q.input_tokens??0,output_tokens:q.output_tokens??0,cost_usd:c(q.cost_usd??0,2),duration_seconds:q.duration_seconds??0}));let z=JSON.stringify(X,null,2);function K(q,V){if(!V)return;let H=new RegExp(`("${q}": )(-?\\d+)(,?)$`,"m");z=z.replace(H,(W,G,B,J)=>`${G}${B}.0${J}`)}if(K("avg_duration_per_iteration",Q>0&&Number.isInteger(X.efficiency.avg_duration_per_iteration)),K("percent",$.budgetLimit>0&&Number.isInteger(X.budget.percent)),K("cost_usd",Q>0&&Number.isInteger(X.tokens.cost_usd)),Z)z=z.replace(/("cost_usd": )(-?\d+)(,?)$/gm,(q,V,H,W)=>`${V}${H}.0${W}`);return z}function c6($,Z){let Q=[];if(Q.push("Loki Mode Session Statistics"),Q.push("============================"),Q.push(""),Q.push("Session"),Q.push(` Iterations completed: ${$.iterationCount}`),Q.push(` Duration: ${x1($.totalDuration)}`),Q.push(` Current phase: ${$.phase}`),Q.push(""),Q.push("Token Usage"),$.iterations.length>0)Q.push(` Input tokens: ${i($.totalInput)}`),Q.push(` Output tokens: ${i($.totalOutput)}`),Q.push(` Total tokens: ${i($.totalTokens)}`),Q.push(` Estimated cost: $${e($.totalCost,2)}`);else Q.push(" N/A (no iteration metrics found)");if(Q.push(""),Q.push("Quality Gates"),$.gatesTotal>0){let X=Math.round($.gatesPassed/$.gatesTotal*100);Q.push(` Gates passed: ${$.gatesPassed}/${$.gatesTotal} (${X}%)`)}else Q.push(" Gates passed: N/A");if($.reviewsTotal>0){let X=[];if($.reviewsApproved>0)X.push(`${$.reviewsApproved} approved`);if($.reviewsRevision>0)X.push(`${$.reviewsRevision} revision requested`);let z=X.length>0?X.join(", "):"N/A";Q.push(` Code reviews: ${$.reviewsTotal} (${z})`)}if(Object.keys($.gateFailures).length>0){let X=Object.entries($.gateFailures).filter(([,z])=>z>0).map(([z,K])=>`${z} (${K})`);if(X.length>0)Q.push(` Gate failures: ${X.join(", ")}`)}if(Q.push(""),Q.push("Efficiency"),$.iterationCount>0&&$.iterations.length>0){let X=Math.round($.totalTokens/$.iterationCount),z=$.totalCost/$.iterationCount,K=$.totalDuration/$.iterationCount;Q.push(` Avg tokens/iteration: ${i(X)}`),Q.push(` Avg cost/iteration: $${e(z,2)}`),Q.push(` Avg duration/iteration: ${x1(K)}`)}else Q.push(" N/A (no iteration metrics found)");if(Q.push(""),Q.push("Budget"),$.budgetLimit>0){let X=c($.budgetUsed/$.budgetLimit*100,1),z=Number.isInteger(X)?`${X}.0`:`${X}`;Q.push(` Used: $${e($.budgetUsed,2)} / $${e($.budgetLimit,2)} (${z}%)`)}else if($.budgetUsed>0)Q.push(` Used: $${e($.budgetUsed,2)} (no limit set)`);else Q.push(" N/A");if(Z&&$.iterations.length>0)Q.push(""),Q.push("Per-Iteration Breakdown"),$.iterations.forEach((X,z)=>{let K=z+1,q=R1(i(X.input_tokens??0),10),V=R1(i(X.output_tokens??0),10),H=X.cost_usd??0,W=x1(X.duration_seconds??0),G=R1(`${K}`,3);Q.push(` #${G} input: ${q} output: ${V} cost: $${e(H,2)} time: ${W}`)});return Q.join(`
|
|
204
|
+
`)}function J0($){let Z=!1,Q=!1;for(let q of $)if(q==="--json")Z=!0;else if(q==="--efficiency")Q=!0;let X=F();if(!E1(X)){if(Z)return{exitCode:0,stdout:'{"error": "No active session"}'};return{exitCode:0,stdout:`${w}No active session found.${U}
|
|
205
|
+
Start a session with: loki start <prd>`}}let z=u6(X);return{exitCode:0,stdout:Z?p6(z,Q):c6(z,Q)}}async function l6($){let Z=J0($);return console.log(Z.stdout),Z.exitCode}var M0=E(()=>{f();d()});var P0={};b(P0,{runDoctor:()=>Z3,httpReachable:()=>N1,checkTool:()=>O0,checkSkills:()=>j0,checkDisk:()=>D1,buildDoctorJson:()=>I0});import{existsSync as d6,lstatSync as o6,readlinkSync as n6,statfsSync as a6}from"fs";import{homedir as A0}from"os";import{resolve as Y0}from"path";function r6($){let Z=$.match(s6);return Z?Z[1]:null}async function t6($){try{let Z=await S([$,"--version"],{timeoutMs:5000}),Q=(Z.stdout||Z.stderr||"").trim();return r6(Q)}catch{return null}}function T0($,Z){let Q=$.split(".").map((z)=>parseInt(z,10)),X=Z.split(".").map((z)=>parseInt(z,10));while(Q.length<2)Q.push(0);while(X.length<2)X.push(0);for(let z=0;z<2;z++){let K=Q[z]??0,q=X[z]??0;if(Number.isNaN(K)||Number.isNaN(q))return 0;if(K!==q)return K-q}return 0}async function O0($,Z,Q,X=null){let z=await v(Z),K=z!==null,q=K?await t6(Z):null,V="pass";if(!K)V=Q==="required"?"fail":"warn";else if(X&&q){if(T0(q,X)<0)V=Q==="required"?"fail":"warn"}return{name:$,command:Z,found:K,version:q,required:Q,min_version:X,status:V,path:z}}function D1(){let $=null;try{let Q=a6(A0()),X=Number(Q.bavail)*Number(Q.bsize);$=Math.round(X/1073741824*10)/10}catch{$=null}let Z="pass";if($!==null){if($<1)Z="fail";else if($<5)Z="warn"}return{available_gb:$,status:Z}}async function N1($,Z=2000){try{return(await fetch($,{signal:AbortSignal.timeout(Z)})).ok}catch{return!1}}async function S1($,Z=!1){let Q=`import ${$}`,X=Z?30000:5000;if(!Z)return(await o(Q,{timeoutMs:X})).exitCode===0;let z=await s();if(!z)return!1;return(await S([z,"-c",Q],{timeoutMs:X})).exitCode===0}function j0(){let $=A0();return i6.map(({name:Z,dir:Q})=>{let X=Y0($,Q),z=X,K=Y0(X,"SKILL.md");if(d6(K))return{name:Z,path:z,status:"pass",detail:""};try{if(o6(X).isSymbolicLink()){let V="unknown";try{V=n6(X)}catch{}return{name:Z,path:z,status:"fail",detail:`(broken symlink -> ${V})`}}}catch{}return{name:Z,path:z,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function _0(){return Promise.all(e6.map(async($)=>{return{...await O0($.jsonName,$.cmd,$.required,$.min??null),displayName:$.displayName}}))}async function I0(){let Z=(await _0()).map(({displayName:q,...V})=>V),Q=D1(),X=0,z=0,K=0;for(let q of Z)if(q.status==="pass")X++;else if(q.status==="fail")z++;else K++;if(Q.status==="pass")X++;else if(Q.status==="fail")z++;else K++;return{checks:Z,disk:Q,summary:{passed:X,failed:z,warnings:K,ok:z===0}}}function M($){switch($){case"pass":return`${C}PASS${U}`;case"fail":return`${P}FAIL${U}`;case"warn":return`${w}WARN${U}`}}function G1($){let Z=$.version?` (v${$.version})`:"",Q=$.displayName;if(!$.found){let X=$.required==="required"?"not found":$.required==="recommended"?"not found (recommended)":"not found (optional)";return` ${M($.status)} ${Q} - ${X}`}if($.min_version&&$.version&&T0($.version,$.min_version)<0){let X=$.required==="required"?"requires":"recommended";return` ${M($.status)} ${Q}${Z} - ${X} >= ${$.min_version}`}return` ${M($.status)} ${Q}${Z}`}function J1($,Z){if(Z==="pass")$.pass++;else if(Z==="fail")$.fail++;else $.warn++}function $3(){process.stdout.write(`${D}loki doctor${U} - Check system prerequisites
|
|
201
206
|
|
|
202
207
|
`),process.stdout.write(`Usage: loki doctor [--json]
|
|
203
208
|
|
|
@@ -206,89 +211,89 @@ Start a session with: loki start <prd>`}}let z=Z3(X);return{exitCode:0,stdout:Z?
|
|
|
206
211
|
|
|
207
212
|
`),process.stdout.write(`Checks: node, python3, jq, git, curl, bash version,
|
|
208
213
|
`),process.stdout.write(` claude/codex/gemini CLIs, and disk space.
|
|
209
|
-
`)}async function
|
|
214
|
+
`)}async function Q3(){process.stdout.write(`${D}Loki Mode Doctor${U}
|
|
210
215
|
|
|
211
216
|
`),process.stdout.write(`Checking system prerequisites...
|
|
212
217
|
|
|
213
|
-
`);let $={pass:0,fail:0,warn:0},Z=await
|
|
214
|
-
`);for(let
|
|
215
|
-
`),
|
|
216
|
-
`),process.stdout.write(`${
|
|
217
|
-
`);let X=["claude","codex","gemini","cline","aider"],z=!1;for(let
|
|
218
|
-
`),
|
|
219
|
-
`),process.stdout.write(` ${
|
|
218
|
+
`);let $={pass:0,fail:0,warn:0},Z=await _0(),Q=new Map(Z.map((O)=>[O.command,O]));process.stdout.write(`${A}Required:${U}
|
|
219
|
+
`);for(let O of["node","python3","jq","git","curl"]){let k=Q.get(O);process.stdout.write(G1(k)+`
|
|
220
|
+
`),J1($,k.status)}process.stdout.write(`
|
|
221
|
+
`),process.stdout.write(`${A}AI Providers:${U}
|
|
222
|
+
`);let X=["claude","codex","gemini","cline","aider"],z=!1;for(let O of X){let k=Q.get(O);if(process.stdout.write(G1(k)+`
|
|
223
|
+
`),J1($,k.status),k.found)z=!0}if(!z)process.stdout.write(` ${M("fail")} No AI provider CLI installed -- at least one is required
|
|
224
|
+
`),process.stdout.write(` ${w}Install: npm install -g @anthropic-ai/claude-code${U}
|
|
220
225
|
`),$.fail++;process.stdout.write(`
|
|
221
|
-
`),process.stdout.write(`${
|
|
222
|
-
`);let
|
|
223
|
-
`),$.pass++;else if(
|
|
224
|
-
`);if(
|
|
225
|
-
`),$.pass++;else if(
|
|
226
|
-
`);if(
|
|
227
|
-
`),$.pass++;else if(
|
|
226
|
+
`),process.stdout.write(`${A}API Keys:${U}
|
|
227
|
+
`);let K=Q.get("claude").found,q=Q.get("codex").found,V=Q.get("gemini").found,H=process.env;if(H.ANTHROPIC_API_KEY)process.stdout.write(` ${M("pass")} ANTHROPIC_API_KEY is set
|
|
228
|
+
`),$.pass++;else if(K)process.stdout.write(` ${L} -- ${U} ANTHROPIC_API_KEY not set (Claude CLI uses its own login)
|
|
229
|
+
`);if(H.OPENAI_API_KEY)process.stdout.write(` ${M("pass")} OPENAI_API_KEY is set
|
|
230
|
+
`),$.pass++;else if(q)process.stdout.write(` ${L} -- ${U} OPENAI_API_KEY not set (Codex CLI uses its own login)
|
|
231
|
+
`);if(H.GOOGLE_API_KEY||H.GEMINI_API_KEY)process.stdout.write(` ${M("pass")} GOOGLE_API_KEY is set
|
|
232
|
+
`),$.pass++;else if(V)process.stdout.write(` ${L} -- ${U} GOOGLE_API_KEY not set (Gemini CLI uses its own login)
|
|
228
233
|
`);process.stdout.write(`
|
|
229
|
-
`),process.stdout.write(`${
|
|
230
|
-
`);for(let
|
|
231
|
-
`),$.pass++;else if(
|
|
232
|
-
`),process.stdout.write(` ${
|
|
233
|
-
`),$.fail++;else process.stdout.write(` ${
|
|
234
|
+
`),process.stdout.write(`${A}Skills:${U}
|
|
235
|
+
`);for(let O of j0())if(O.status==="pass")process.stdout.write(` ${M("pass")} ${O.name} ${L}${O.path}${U}
|
|
236
|
+
`),$.pass++;else if(O.status==="fail")process.stdout.write(` ${M("fail")} ${O.name} ${L}${O.detail}${U}
|
|
237
|
+
`),process.stdout.write(` ${w}Fix: loki setup-skill${U}
|
|
238
|
+
`),$.fail++;else process.stdout.write(` ${M("warn")} ${O.name} ${L}${O.detail}${U}
|
|
234
239
|
`),$.warn++;if(process.stdout.write(`
|
|
235
|
-
`),process.stdout.write(`${
|
|
236
|
-
`),await
|
|
237
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
238
|
-
`),$.warn++;if(await
|
|
239
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
240
|
-
`),$.warn++;if(await
|
|
241
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
242
|
-
`),$.warn++;if(await
|
|
243
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
244
|
-
`),$.warn++;let
|
|
245
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
246
|
-
`),$.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${
|
|
247
|
-
`),$.pass++;else process.stdout.write(` ${
|
|
240
|
+
`),process.stdout.write(`${A}Integrations:${U}
|
|
241
|
+
`),await S1("mcp"))process.stdout.write(` ${M("pass")} MCP SDK (Python)
|
|
242
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} MCP SDK - not installed (pip3 install mcp)
|
|
243
|
+
`),$.warn++;if(await S1("numpy",!0))process.stdout.write(` ${M("pass")} numpy (vector search)
|
|
244
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} numpy - not installed (pip3 install numpy)
|
|
245
|
+
`),$.warn++;if(await S1("sentence_transformers",!0))process.stdout.write(` ${M("pass")} sentence-transformers (embeddings)
|
|
246
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} sentence-transformers - not installed (loki memory vectors setup)
|
|
247
|
+
`),$.warn++;if(await N1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${M("pass")} ChromaDB server (port 8100)
|
|
248
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} ChromaDB - not running (docker start loki-chroma)
|
|
249
|
+
`),$.warn++;let W=process.env.LOKI_MIROFISH_URL;if(W)if(await N1(`${W}/health`))process.stdout.write(` ${M("pass")} MiroFish server (${W})
|
|
250
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
|
|
251
|
+
`),$.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${M("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
|
|
252
|
+
`),$.pass++;else process.stdout.write(` ${M("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
|
|
248
253
|
`),$.warn++;process.stdout.write(`
|
|
249
|
-
`),process.stdout.write(`${
|
|
250
|
-
`);let
|
|
251
|
-
`),
|
|
252
|
-
`),
|
|
253
|
-
`),$.warn++;else if(J.status==="fail")process.stdout.write(` ${
|
|
254
|
-
`),$.fail++;else if(J.status==="warn")process.stdout.write(` ${
|
|
255
|
-
`),$.warn++;else process.stdout.write(` ${
|
|
254
|
+
`),process.stdout.write(`${A}System:${U}
|
|
255
|
+
`);let G=Q.get("bash");process.stdout.write(G1(G)+`
|
|
256
|
+
`),J1($,G.status);let B=Q.get("bun");if(B)process.stdout.write(G1(B)+`
|
|
257
|
+
`),J1($,B.status);let J=D1(),Y=J.available_gb===null?null:Math.floor(J.available_gb);if(Y===null)process.stdout.write(` ${M("warn")} Disk space: unable to determine
|
|
258
|
+
`),$.warn++;else if(J.status==="fail")process.stdout.write(` ${M("fail")} Disk space: ${Y}GB available (need >= 1GB)
|
|
259
|
+
`),$.fail++;else if(J.status==="warn")process.stdout.write(` ${M("warn")} Disk space: ${Y}GB available (low)
|
|
260
|
+
`),$.warn++;else process.stdout.write(` ${M("pass")} Disk space: ${Y}GB available
|
|
256
261
|
`),$.pass++;process.stdout.write(`
|
|
257
|
-
`),process.stdout.write(`${
|
|
258
|
-
`);let
|
|
259
|
-
`),process.env.LOKI_LEGACY_BASH==="1"||process.env.LOKI_LEGACY_BASH==="true")process.stdout.write(` ${
|
|
260
|
-
`);if(process.env.LOKI_TS_ENTRY)process.stdout.write(` ${
|
|
261
|
-
`);if(process.env.BUN_FROM_SOURCE==="1"||process.env.BUN_FROM_SOURCE==="true")process.stdout.write(` ${
|
|
262
|
-
`);let
|
|
263
|
-
`);else if(
|
|
264
|
-
`);else process.stdout.write(` ${
|
|
265
|
-
`)}else process.stdout.write(` ${
|
|
262
|
+
`),process.stdout.write(`${A}Runtime route:${U}
|
|
263
|
+
`);let _=process.versions.bun!==void 0,I=process.argv[0]??"(unknown)";if(process.stdout.write(` ${M("pass")} Active runtime: ${_?"Bun":"Node"} (${I})
|
|
264
|
+
`),process.env.LOKI_LEGACY_BASH==="1"||process.env.LOKI_LEGACY_BASH==="true")process.stdout.write(` ${M("warn")} LOKI_LEGACY_BASH set: shim routes every command to autonomy/loki (bash)
|
|
265
|
+
`);if(process.env.LOKI_TS_ENTRY)process.stdout.write(` ${M("pass")} LOKI_TS_ENTRY override: ${process.env.LOKI_TS_ENTRY}
|
|
266
|
+
`);if(process.env.BUN_FROM_SOURCE==="1"||process.env.BUN_FROM_SOURCE==="true")process.stdout.write(` ${M("pass")} BUN_FROM_SOURCE set: shim prefers loki-ts/src/ over dist/
|
|
267
|
+
`);let R=await s();if(R!==null){let k=(await S([R,"-c","import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"],{timeoutMs:5000})).stdout.trim();if(k.startsWith("3.12"))process.stdout.write(` ${M("pass")} Python 3.12 (chromadb / sentence-transformers): ${k} at ${R}
|
|
268
|
+
`);else if(k)process.stdout.write(` ${M("warn")} Python 3.12 NOT found -- using ${k} at ${R}; chromadb / sentence-transformers may fail. Install python3.12 (brew install python@3.12 / apt install python3.12).
|
|
269
|
+
`);else process.stdout.write(` ${M("warn")} Python 3 found at ${R} but version probe failed; chromadb may not work.
|
|
270
|
+
`)}else process.stdout.write(` ${M("warn")} Python 3 not on PATH -- memory + MCP integrations disabled.
|
|
266
271
|
`);if(process.stdout.write(`
|
|
267
|
-
`),process.stdout.write(`${
|
|
272
|
+
`),process.stdout.write(`${D}Summary:${U} ${C}${$.pass} passed${U}, ${P}${$.fail} failed${U}, ${w}${$.warn} warnings${U}
|
|
268
273
|
|
|
269
|
-
`),$.fail>0)return process.stdout.write(`${
|
|
274
|
+
`),$.fail>0)return process.stdout.write(`${P}Some required prerequisites are missing.${U}
|
|
270
275
|
`),process.stdout.write(`Install missing dependencies and run 'loki doctor' again.
|
|
271
|
-
`),1;if($.warn>0)return process.stdout.write(`${
|
|
272
|
-
`),0;return process.stdout.write(`${
|
|
273
|
-
`),0}async function
|
|
276
|
+
`),1;if($.warn>0)return process.stdout.write(`${w}All required checks passed with some warnings.${U}
|
|
277
|
+
`),0;return process.stdout.write(`${C}All checks passed. System is ready for Loki Mode.${U}
|
|
278
|
+
`),0}async function Z3($){let Z=!1;for(let Q of $)if(Q==="--json")Z=!0;else if(Q==="--help"||Q==="-h")return $3(),0;else return process.stderr.write(`${P}Unknown option: ${Q}${U}
|
|
274
279
|
`),process.stderr.write(`Usage: loki doctor [--json]
|
|
275
|
-
`),1;if(Z){let Q=await
|
|
276
|
-
`),0}return
|
|
277
|
-
`),0;process.stdout.write(`${
|
|
278
|
-
`);for(let z of X)process.stdout.write(` ${
|
|
279
|
-
`);return 0}case"show":{let X=Q[0];if(!X)return process.stderr.write(`${
|
|
280
|
-
`),2;try{let z=
|
|
281
|
-
`),0}catch(z){return process.stderr.write(`${
|
|
282
|
-
`),1}}case"to":{let X=Q[0];if(!X)return process.stderr.write(`${
|
|
283
|
-
`),2;return
|
|
284
|
-
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${
|
|
285
|
-
`),
|
|
286
|
-
`),process.stderr.write(
|
|
287
|
-
`),1}if(Z.restore.length===0)return process.stdout.write(`${
|
|
288
|
-
`),0;let Q=
|
|
289
|
-
`);return process.stderr.write(`${
|
|
290
|
-
`),1}return process.stdout.write(`${
|
|
291
|
-
`),process.stdout.write("Run `loki start` to resume from the restored state.\n"),0}var
|
|
280
|
+
`),1;if(Z){let Q=await I0();return process.stdout.write(JSON.stringify(Q,null,2)+`
|
|
281
|
+
`),0}return Q3()}var s6,i6,e6;var L0=E(()=>{m();Q1();d();s6=/(\d+\.\d+(?:\.\d+)*)/;i6=[{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"}];e6=[{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"}]});import{existsSync as B1,mkdirSync as X3,copyFileSync as z3,readFileSync as K3,readdirSync as q3,statSync as U3,writeFileSync as W7,renameSync as V3,appendFileSync as G7,rmSync as J7}from"fs";import{join as n,dirname as H3}from"path";function M1($){return n($,"state","checkpoints")}function G3($){let Z=M1($);if(!B1(Z))return[];return q3(Z).filter((Q)=>Q.startsWith("cp-")).filter((Q)=>{try{return U3(n(Z,Q)).isDirectory()}catch{return!1}})}function J3($){return[...$].sort((Z,Q)=>{let X=F0(Z),z=F0(Q);return X-z})}function F0($){let Z=$.split("-");if(Z.length<3)return 0;let Q=Z[Z.length-1],X=Number.parseInt(Q??"0",10);return Number.isFinite(X)?X:0}function C1($){let Z=$??F(),Q=J3(G3(Z)),X=[];for(let z of Q){let K=w0(Z,z);if(K)X.push(K)}return X}function w0($,Z){let Q=n(M1($),Z,"metadata.json");if(!B1(Q))return null;try{return JSON.parse(K3(Q,"utf-8"))}catch{return null}}function b1($,Z){if(!B3.test($))throw new x0($);let Q=Z??F(),X=n(M1(Q),$);if(!B1(X))throw new k1($);let z=w0(Q,$);if(!z)throw new k1($);return z}function R0($,Z){let Q=b1($,Z),X=Z??F(),z=n(M1(X),$),K=[];for(let q of M3){let V=n(z,q);if(!B1(V))continue;K.push({from:V,to:n(X,q)})}return{id:$,metadata:Q,restore:K}}function E0($){let Z=[],Q=0;for(let X of $.restore)try{X3(H3(X.to),{recursive:!0});let z=`${X.to}.tmp.${process.pid}.${++W3}`;z3(X.from,z),V3(z,X.to),Q+=1}catch(z){Z.push(`${X.from} -> ${X.to}: ${z.message}`)}return{restored:Q,errors:Z}}var A7,W3=0,B3,k1,x0,M3;var S0=E(()=>{f();m();A7=Promise.resolve();B3=/^[a-zA-Z0-9_-]+$/;k1=class k1 extends Error{id;constructor($){super(`Checkpoint not found: ${$}`);this.id=$;this.name="CheckpointNotFoundError"}};x0=class x0 extends Error{id;constructor($){super(`Invalid checkpoint ID: must be alphanumeric, hyphens, underscores only (got: ${$})`);this.id=$;this.name="InvalidCheckpointIdError"}};M3=["state/orchestrator.json","queue/pending.json","queue/completed.json","queue/in-progress.json","queue/current-task.json"]});var k0={};b(k0,{runRollback:()=>Y3});async function Y3($){let Z=$[0],Q=$.slice(1);if(Z===void 0||Z==="help"||Z==="--help"||Z==="-h")return process.stdout.write(N0),Z===void 0?1:0;switch(Z){case"list":{let X=[...C1()].reverse();if(X.length===0)return process.stdout.write(`${w}No checkpoints found.${U}
|
|
282
|
+
`),0;process.stdout.write(`${D}Checkpoints${U} (${X.length}, newest first):
|
|
283
|
+
`);for(let z of X)process.stdout.write(` ${A}${z.id}${U} iter=${z.iteration} ${z.git_branch||"(no branch)"}@${(z.git_sha||"").slice(0,7)} ${z.timestamp}
|
|
284
|
+
`);return 0}case"show":{let X=Q[0];if(!X)return process.stderr.write(`${P}Missing checkpoint id.${U} Use \`loki rollback list\`.
|
|
285
|
+
`),2;try{let z=b1(X);return process.stdout.write(`${JSON.stringify(z,null,2)}
|
|
286
|
+
`),0}catch(z){return process.stderr.write(`${P}Failed to read checkpoint:${U} ${z.message}
|
|
287
|
+
`),1}}case"to":{let X=Q[0];if(!X)return process.stderr.write(`${P}Missing checkpoint id.${U} Use \`loki rollback list\`.
|
|
288
|
+
`),2;return D0(X)}case"latest":{let X=C1(),z=X[X.length-1];if(!z)return process.stderr.write(`${P}No checkpoints found to roll back to.${U}
|
|
289
|
+
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${A}${z.id}${U}
|
|
290
|
+
`),D0(z.id)}default:return process.stderr.write(`Unknown subcommand: ${Z}
|
|
291
|
+
`),process.stderr.write(N0),2}}function D0($){let Z;try{Z=R0($)}catch(X){return process.stderr.write(`${P}Cannot plan rollback:${U} ${X.message}
|
|
292
|
+
`),1}if(Z.restore.length===0)return process.stdout.write(`${w}Checkpoint ${$} has no restorable state files; nothing to do.${U}
|
|
293
|
+
`),0;let Q=E0(Z);if(Q.errors.length>0){for(let X of Q.errors)process.stderr.write(`${P}restore error:${U} ${X}
|
|
294
|
+
`);return process.stderr.write(`${P}Partial rollback: ${Q.restored}/${Z.restore.length} files restored.${U}
|
|
295
|
+
`),1}return process.stdout.write(`${C}Rolled back ${Q.restored}/${Z.restore.length} state files from ${$}.${U}
|
|
296
|
+
`),process.stdout.write("Run `loki start` to resume from the restored state.\n"),0}var N0=`Usage: loki rollback <subcommand>
|
|
292
297
|
|
|
293
298
|
Subcommands:
|
|
294
299
|
list List checkpoints (newest first)
|
|
@@ -303,24 +308,78 @@ Restored files (matches autonomy/run.sh:7028 byte-for-byte):
|
|
|
303
308
|
Note: only state files are restored. Source code, git history, and the
|
|
304
309
|
session's autonomy-state.json are unchanged. Re-run \`loki start\` to
|
|
305
310
|
resume from the restored state.
|
|
306
|
-
`;var
|
|
307
|
-
`),
|
|
311
|
+
`;var C0=E(()=>{S0();d()});import{mkdirSync as A3,renameSync as T3,writeFileSync as O3}from"fs";import{dirname as j3}from"path";function z1($,Z){A3(j3($),{recursive:!0});let Q=`${$}.tmp.${process.pid}.${++_3}`;O3(Q,`${JSON.stringify(Z,null,2)}
|
|
312
|
+
`),T3(Q,$)}async function b0($,Z){let Q=Y1.get($)??Promise.resolve(),X=()=>{},z=new Promise((q)=>{X=q}),K=Q.catch(()=>{}).then(()=>z);Y1.set($,K);try{return await Q.catch(()=>{}),await Z()}finally{if(X(),Y1.get($)===K)Y1.delete($)}}var _3=0,Y1;var y1=E(()=>{Y1=new Map});var h1={};b(h1,{renderFindingsForPrompt:()=>w3,loadPreviousFindings:()=>v1,findLatestReviewDir:()=>g0,_parseReviewerOutputForTests:()=>x3});import{existsSync as v0,readFileSync as y0,readdirSync as h0,statSync as I3}from"fs";import{join as A1}from"path";function F3($){let Z=$.toLowerCase();if(Z==="critical")return"Critical";if(Z==="high")return"High";if(Z==="medium")return"Medium";return"Low"}function f0($,Z,Q,X){let z=[],K=$.split(/\r?\n/);for(let q of K){let V=q.trim();if(V.length===0)continue;let H=V.replace(/^[-*]\s*/,""),W=P3.exec(H);if(!W)continue;let G=F3(W[1]),B=W[2].trim(),J=L3.exec(B),Y=J?J[1]:null,_=J?Number.parseInt(J[2],10):null;z.push({reviewId:Q,iteration:X,reviewer:Z,severity:G,description:B,file:Y,line:Number.isFinite(_)?_:null,raw:V})}return z}function g0($,Z){let Q=A1($,"quality","reviews");if(!v0(Q))return null;let X;try{X=h0(Q)}catch{return null}let z=Z===void 0?X.filter((V)=>V.startsWith("review-")):X.filter((V)=>V.endsWith(`-${Z}`)&&V.startsWith("review-"));if(z.length===0)return null;z.sort();let K=z[z.length-1];if(!K)return null;let q=A1(Q,K);try{if(!I3(q).isDirectory())return null}catch{return null}return q}function v1($,Z){let Q=g0($,Z);if(Q===null)return{reviewDir:null,reviewId:null,iteration:null,findings:[]};let X=null,z=null,K=A1(Q,"aggregate.json");if(v0(K))try{let W=y0(K,"utf-8"),G=JSON.parse(W);if(typeof G.review_id==="string")X=G.review_id;if(typeof G.iteration==="number")z=G.iteration}catch{}let q;try{q=h0(Q)}catch{return{reviewDir:Q,reviewId:X,iteration:z,findings:[]}}let V=new Set(["diff.txt","files.txt","anti-sycophancy.txt"]),H=[];for(let W of q){if(!W.endsWith(".txt"))continue;if(V.has(W))continue;if(W.endsWith("-prompt.txt"))continue;let G=W.replace(/\.txt$/,""),B;try{B=y0(A1(Q,W),"utf-8")}catch{continue}H.push(...f0(B,G,X??"",z??-1))}return{reviewDir:Q,reviewId:X,iteration:z,findings:H}}function w3($){if($.length===0)return"";let Z=["Critical","High","Medium","Low"],Q=new Map;for(let z of Z)Q.set(z,[]);for(let z of $){let K=Q.get(z.severity);if(K)K.push(z)}let X=[];X.push("PREVIOUS REVIEWER FINDINGS (must address each, or supply counter-evidence in .loki/state/counter-evidence-<iter>.json):");for(let z of Z){let K=Q.get(z)??[];if(K.length===0)continue;X.push(` [${z}] (${K.length}):`);for(let q of K){let V=q.file?` (${q.file}${q.line!==null?":"+q.line:""})`:"";X.push(` - ${q.description}${V} -- via ${q.reviewer}`)}}return X.join(`
|
|
313
|
+
`)}function x3($,Z,Q="review-test",X=0){return f0($,Z,Q,X)}var P3,L3;var T1=E(()=>{P3=/\[(Critical|High|Medium|Low)\]\s*(.+)/i,L3=/([\w.\-/]+\.[a-zA-Z]+):(\d+)/});import{existsSync as R3}from"fs";import{join as E3}from"path";async function m0($,Z){let Q=E3($,"memory");if(!R3(Q))return{stored:!1,reason:"memory dir not initialized"};let X=Math.max(0,Math.floor(Z.durationSeconds??0)),z={_LOKI_PROJECT_DIR:g,_LOKI_TARGET_DIR:process.cwd(),_LOKI_TASK_ID:Z.taskId,_LOKI_OUTCOME:Z.outcome,_LOKI_PHASE:Z.phase,_LOKI_GOAL:Z.goal,_LOKI_DURATION:String(X),_LOKI_LOKI_DIR:$},q=await o(`
|
|
314
|
+
import os, sys
|
|
315
|
+
project = os.environ.get('_LOKI_PROJECT_DIR', '')
|
|
316
|
+
loki = os.environ.get('_LOKI_LOKI_DIR', '.loki')
|
|
317
|
+
task_id = os.environ.get('_LOKI_TASK_ID', '')
|
|
318
|
+
outcome = os.environ.get('_LOKI_OUTCOME', '')
|
|
319
|
+
phase = os.environ.get('_LOKI_PHASE', '')
|
|
320
|
+
goal = os.environ.get('_LOKI_GOAL', '')
|
|
321
|
+
duration = os.environ.get('_LOKI_DURATION', '0')
|
|
322
|
+
sys.path.insert(0, project)
|
|
323
|
+
try:
|
|
324
|
+
from memory.engine import MemoryEngine
|
|
325
|
+
from memory.schemas import EpisodeTrace
|
|
326
|
+
engine = MemoryEngine(loki + '/memory')
|
|
327
|
+
engine.initialize()
|
|
328
|
+
trace = EpisodeTrace.create(
|
|
329
|
+
task_id=task_id,
|
|
330
|
+
agent='loki-orchestrator',
|
|
331
|
+
phase=phase,
|
|
332
|
+
goal=goal,
|
|
333
|
+
outcome=outcome,
|
|
334
|
+
duration_seconds=int(duration) if duration.isdigit() else 0,
|
|
335
|
+
)
|
|
336
|
+
engine.store_episode(trace)
|
|
337
|
+
print('OK')
|
|
338
|
+
except Exception as e:
|
|
339
|
+
print('ERR:' + str(e))
|
|
340
|
+
`,{env:z,timeoutMs:15000});if(q.exitCode===127)return{stored:!1,reason:"python3 not found"};let V=q.stdout.trim();if(V==="OK")return{stored:!0,reason:"stored"};if(V.startsWith("ERR:"))return{stored:!1,reason:V.replace(/^ERR:/,"")};return{stored:!1,reason:q.stderr.trim()||"unknown"}}var u0=E(()=>{Q1();f()});var d0={};b(d0,{loadLearnings:()=>f1,appendLearning:()=>K1,appendFromGateFailure:()=>v3});import{existsSync as S3,readFileSync as N3}from"fs";import{join as p0}from"path";import{createHash as D3}from"crypto";function c0($){return p0($,k3)}function C3($){if($===null||typeof $!=="object")return!1;let Z=$;return typeof Z.id==="string"&&typeof Z.timestamp==="string"&&typeof Z.iteration==="number"&&typeof Z.trigger==="string"&&typeof Z.rootCause==="string"&&typeof Z.fix==="string"&&typeof Z.preventInFuture==="string"&&typeof Z.evidence==="object"&&Z.evidence!==null}function l0($){if(!S3($))return{version:1,learnings:[]};try{let Z=N3($,"utf-8"),Q=JSON.parse(Z);if(Q.version===1&&Array.isArray(Q.learnings))return{version:1,learnings:Q.learnings.filter(C3)}}catch{}return{version:1,learnings:[]}}function b3($,Z){return D3("sha256").update(`${$}\x00${Z}`).digest("hex").slice(0,16)}async function K1($,Z,Q={}){let X=b3(Z.trigger,Z.rootCause),z=new Date().toISOString(),K={id:X,timestamp:z,...Z},q=c0($);if(await b0(q,()=>{let H=l0(q),W=H.learnings.findIndex((G)=>G.id===X);if(W>=0){let G=H.learnings[W];H.learnings[W]={...G,timestamp:z,iteration:K.iteration}}else H.learnings.push(K);z1(q,H)}),Q.episodeBridge!==null&&(Q.episodeBridge!==void 0||process.env.LOKI_AUTO_LEARNINGS_EPISODE==="1")){let H=Q.episodeBridge??m0,W=Q.bridgeFailureLog??y3;try{let G=await H($,{taskId:`learning-${X}`,outcome:"failure",phase:"VERIFY",goal:`${Z.trigger}: ${Z.rootCause}`});if(G&&!G.stored){if(!new Set(["memory dir not initialized","stub"]).has(G.reason))W(`episode_bridge skipped: ${G.reason}`)}}catch(G){W(`episode_bridge threw: ${G.message}`)}}return K}function y3($){process.stderr.write(`[learnings_writer] ${$}
|
|
341
|
+
`)}async function v3($,Z,Q,X={}){let z=`[${Q.severity}] ${Q.description}`;return K1($,{iteration:Z,trigger:"gate_failure",rootCause:z,fix:"pending: dev agent must address in next iteration or supply counter-evidence",preventInFuture:"if this finding recurs, lower its severity threshold or add a regression test",evidence:{reviewId:Q.reviewId,file:Q.file??void 0,line:Q.line??void 0,severity:Q.severity,reviewer:Q.reviewer}},X)}function f1($){return l0(c0($))}var k3;var O1=E(()=>{y1();u0();k3=p0("state","relevant-learnings.json")});var n0={};b(n0,{runOverrideCouncil:()=>p3,recordOverrideOutcome:()=>c3,loadCounterEvidence:()=>u3,canonicalFindingId:()=>g1,DEFAULT_OVERRIDE_JUDGES:()=>o0});import{existsSync as h3,readFileSync as f3}from"fs";import{join as g3}from"path";function u3($,Z){let Q=g3($,"state",`counter-evidence-${Z}.json`);if(!h3(Q))return null;try{let X=f3(Q,"utf-8"),z=JSON.parse(X);if(typeof z.iteration!=="number")return null;let K=Array.isArray(z.evidence)?z.evidence:[],q=[];for(let V of K){if(typeof V!=="object"||V===null)continue;let H=V;if(typeof H.findingId!=="string")continue;if(typeof H.claim!=="string")continue;if(typeof H.proofType!=="string")continue;let W=H.proofType;if(!m3.has(W))continue;let G=Array.isArray(H.artifacts)?H.artifacts:[];q.push({findingId:H.findingId,claim:H.claim,proofType:W,artifacts:G.filter((B)=>typeof B==="string")})}return{iteration:z.iteration,evidence:q}}catch{return null}}async function p3($,Z,Q,X={}){let z=X.judges??o0,K=new Set,q=new Set,V={},H=new Map;for(let W of Z.evidence)H.set(W.findingId,W);for(let W of $){let G=g1(W),B=H.get(G);if(!B){q.add(G);continue}let J=await Promise.all(z.map((_)=>Q({finding:W,evidence:B,judge:_})));if(V[G]=J,J.filter((_)=>_.verdict==="APPROVE_OVERRIDE").length>=2)K.add(G);else q.add(G)}return{approvedFindingIds:K,rejectedFindingIds:q,votes:V}}function g1($){let Z=$.raw.slice(0,80).replace(/\s+/g," ").trim();return`${$.reviewer}::${Z}`}async function c3($,Z,Q,X,z={}){let K={episodeBridge:z.episodeBridge===void 0?null:z.episodeBridge};for(let q of X){let V=g1(q);if(Q.approvedFindingIds.has(V))await K1($,{iteration:Z,trigger:"override_approved",rootCause:`[${q.severity}] ${q.description}`,fix:"override council approved counter-evidence; finding lifted",preventInFuture:"if this reviewer/file pair recurs, narrow the reviewer's selector OR add a baseline doc",evidence:{findingId:V,reviewId:q.reviewId,file:q.file??void 0,line:q.line??void 0,severity:q.severity,reviewer:q.reviewer}},K);else if(Q.rejectedFindingIds.has(V))await K1($,{iteration:Z,trigger:"override_rejected",rootCause:`[${q.severity}] ${q.description}`,fix:"override council rejected -- dev agent must fix the finding",preventInFuture:"address this finding in the next iteration",evidence:{findingId:V,reviewId:q.reviewId,file:q.file??void 0,line:q.line??void 0,severity:q.severity,reviewer:q.reviewer}},K)}}var m3,o0;var a0=E(()=>{O1();m3=new Set(["file-exists","test-passes","grep-miss","reviewer-misread","duplicate-code-path","out-of-scope"]);o0=["judge-primary","judge-secondary","judge-tertiary"]});var t0={};b(t0,{writeEscalationHandoff:()=>Q5,renderHandoff:()=>s0,readLatestHandoff:()=>Z5});import{existsSync as l3,mkdirSync as d3,readdirSync as o3,readFileSync as n3,renameSync as a3,writeFileSync as s3}from"fs";import{dirname as r3,join as j1}from"path";function t3(){return new Date().toISOString()}function i3($){let Z=$.file?` (${$.file}${$.line!==null?":"+$.line:""})`:"";return` - [${$.severity}] ${$.description}${Z} -- ${$.reviewer}`}function e3($){let Z=$.evidence,Q=Z.file?` ${Z.file}${Z.line!==void 0?":"+Z.line:""}`:"";return` - **${$.trigger}** (iter ${$.iteration})${Q}: ${$.rootCause}`}function s0($,Z,Q){let X=[];if(X.push(`# Loki escalation handoff -- ${t3()}`),X.push(""),X.push(`Gate **${$.gateName}** has failed ${$.consecutiveFailures} consecutive times at iteration ${$.iteration}.`),X.push(""),X.push(`Reason: ${$.detail}`),X.push(""),Z.length>0){X.push(`## Outstanding findings (${Z.length})`),X.push("");for(let z of Z)X.push(i3(z));X.push("")}else X.push("## Outstanding findings"),X.push(""),X.push("(no per-finding records captured -- gate failed without populating reviewer outputs)"),X.push("");if(Q.length>0){X.push(`## Recent learnings (${Math.min(Q.length,10)})`),X.push("");for(let z of Q.slice(-10))X.push(e3(z));X.push("")}return X.push("## What the human must decide"),X.push(""),X.push("- Approve override? Write `.loki/state/counter-evidence-<iter>.json` with one entry per finding to dispute, then `rm .loki/PAUSE` to resume."),X.push("- Disable a gate? Set `LOKI_GATE_<NAME>=false` in env (see skills/quality-gates.md)."),X.push("- Tweak escalation? Set `LOKI_GATE_PAUSE_LIMIT` or `LOKI_GATE_ESCALATE_LIMIT`."),X.push("- Roll back? Switch to `LOKI_LEGACY_BASH=1` and re-run; the bash route does not consult this handoff doc."),X.push(""),X.push("To resume: address the findings (or supply counter-evidence) and `rm .loki/PAUSE`."),X.join(`
|
|
342
|
+
`)}function $5($,Z){d3(r3($),{recursive:!0});let Q=`${$}.tmp.${process.pid}.${++r0}`;s3(Q,Z),a3(Q,$)}function Q5($,Z,Q={}){let X=Q.findings??v1($,Z.iteration).findings,z=Q.learnings??f1($).learnings,K=s0(Z,X,z),q=(Q.now?.()??new Date).toISOString().replace(/[-:.]/g,""),V=j1($,"escalations"),H=++r0,W=j1(V,`handoff-${q}-${process.pid}-${H}-${Z.gateName}.md`);return $5(W,K),{path:W,bytes:K.length}}function Z5($){let Z=j1($,"escalations");if(!l3(Z))return null;let Q;try{Q=o3(Z).filter((K)=>K.endsWith(".md"))}catch{return null}if(Q.length===0)return null;Q.sort();let X=Q[Q.length-1];if(!X)return null;let z=j1(Z,X);try{return{path:z,body:n3(z,"utf-8")}}catch{return null}}var r0=0;var i0=E(()=>{T1();O1()});var e0={};b(e0,{runInternalPhase1Hooks:()=>V5,_resolveForTests:()=>U5,_internalPhase1HooksHelp:()=>J5});import{existsSync as X5,mkdirSync as z5,readdirSync as K5,statSync as q5}from"fs";import{join as q1,resolve as U5}from"path";async function V5($){let[Z,...Q]=$;switch(Z){case void 0:case"help":case"--help":case"-h":return process.stdout.write(m1),Z===void 0?1:0;case"reflect":return H5(Q);case"override":return W5(Q);case"handoff":return G5(Q);default:return process.stderr.write(`Unknown subcommand: ${Z}
|
|
343
|
+
`),process.stderr.write(m1),2}}async function H5($){let Z=u1($[0]);if(Z===null)return process.stderr.write(`reflect: missing or invalid <iter>
|
|
344
|
+
`),2;let Q=F();try{let z=(await Promise.resolve().then(() => (T1(),h1))).loadPreviousFindings(Q,Z);if(z.findings.length===0)return process.stdout.write(`reflect: no findings for iter ${Z} (nothing to do)
|
|
345
|
+
`),0;let K=q1(Q,"state");z5(K,{recursive:!0}),z1(q1(K,`findings-${Z}.json`),{review_id:z.reviewId,iteration:Z,findings:z.findings});let q=await Promise.resolve().then(() => (O1(),d0)),V=0;if(process.env.LOKI_AUTO_LEARNINGS!=="0"){for(let H of z.findings)if(H.severity==="Critical"||H.severity==="High")await q.appendFromGateFailure(Q,Z,H,{episodeBridge:null}),V+=1}return process.stdout.write(`reflect: persisted ${z.findings.length} findings + ${V} learnings (iter ${Z})
|
|
346
|
+
`),0}catch(X){return process.stderr.write(`reflect: ${X.message}
|
|
347
|
+
`),1}}async function W5($){let Z=u1($[0]);if(Z===null)return process.stderr.write(`override: missing or invalid <iter>
|
|
348
|
+
`),2;let Q=F();try{let X=await Promise.resolve().then(() => (a0(),n0)),z=X.loadCounterEvidence(Q,Z);if(z===null||z.evidence.length===0)return process.stdout.write(`override: no counter-evidence for iter ${Z} (skip)
|
|
349
|
+
`),0;let q=(await Promise.resolve().then(() => (T1(),h1))).loadPreviousFindings(Q,Z),V=q.findings.filter((I)=>I.severity==="Critical"||I.severity==="High");if(V.length===0)return process.stdout.write(`override: no blocking findings for iter ${Z} (skip)
|
|
350
|
+
`),0;let H=new Set(["duplicate-code-path","file-exists","test-passes","grep-miss","out-of-scope"]),W=async(I)=>{let R=H.has(I.evidence.proofType);return{judge:I.judge,verdict:R?"APPROVE_OVERRIDE":"REJECT_OVERRIDE",reasoning:R?`[stub] proofType=${I.evidence.proofType} trusted`:`[stub] proofType=${I.evidence.proofType} requires manual review`}},G=await X.runOverrideCouncil(V,z,W);await X.recordOverrideOutcome(Q,Z,G,V);let B=q1(Q,"quality","reviews");if(X5(B))try{let I=K5(B).filter((O)=>O.startsWith("review-")).sort(),R=I[I.length-1];if(R&&q5(q1(B,R)).isDirectory())z1(q1(B,R,`override-${Z}.json`),{review_id:q.reviewId,iteration:Z,approved_finding_ids:Array.from(G.approvedFindingIds),rejected_finding_ids:Array.from(G.rejectedFindingIds),votes:G.votes})}catch{}let J=G.approvedFindingIds.size,Y=G.rejectedFindingIds.size;if(Y===0&&J>0)process.stdout.write(`override: LIFTED -- ${J} approved, ${Y} rejected
|
|
351
|
+
`);else process.stdout.write(`override: BLOCKED -- ${J} approved, ${Y} rejected
|
|
352
|
+
`);return 0}catch(X){return process.stderr.write(`override: ${X.message}
|
|
353
|
+
`),1}}async function G5($){let Z=$[0],Q=Number.parseInt($[1]??"0",10),X=u1($[2]);if(!Z||!Number.isFinite(Q)||X===null)return process.stderr.write(`handoff: usage: handoff <gate> <consecutive-failures> <iter>
|
|
354
|
+
`),2;let z=F();try{let q=(await Promise.resolve().then(() => (i0(),t0))).writeEscalationHandoff(z,{gateName:Z,iteration:X,consecutiveFailures:Q,detail:`${Z} hit PAUSE_LIMIT (${Q} consecutive failures)`});return process.stdout.write(`handoff: wrote ${q.path} (${q.bytes}B)
|
|
355
|
+
`),0}catch(K){return process.stderr.write(`handoff: ${K.message}
|
|
356
|
+
`),1}}function u1($){if($===void 0)return null;let Z=Number.parseInt($,10);return Number.isFinite(Z)&&Z>=0?Z:null}var m1=`loki internal phase1-hooks <subcommand>
|
|
357
|
+
|
|
358
|
+
Subcommands:
|
|
359
|
+
reflect <iter> Persist structured findings + auto-learnings.
|
|
360
|
+
override <iter> Run override council if counter-evidence present.
|
|
361
|
+
handoff <gate> <count> <iter> Write structured handoff doc before PAUSE.
|
|
362
|
+
|
|
363
|
+
This command is invoked by autonomy/run.sh between iterations. Users
|
|
364
|
+
should not run it directly -- run \`loki start\` instead.
|
|
365
|
+
`,J5;var $6=E(()=>{f();y1();J5=m1});f();import{readFileSync as V6}from"fs";import{resolve as H6,dirname as W6}from"path";import{fileURLToPath as G6}from"url";var l=null;function s1(){if(l!==null)return l;let $="7.5.3";if(typeof $==="string"&&$.length>0)return l=$,l;try{let Z=W6(G6(import.meta.url)),Q=P1(Z);l=V6(H6(Q,"VERSION"),"utf-8").trim()}catch{l="unknown"}return l}function r1(){return process.stdout.write(`Loki Mode v${s1()}
|
|
366
|
+
`),0}m();d();f();import{readFileSync as A6,existsSync as T6}from"fs";import{resolve as O6}from"path";var j6=["claude","codex","gemini","cline","aider"];function i1(){let $=O6(F(),"state","provider");if(!T6($))return"";try{return A6($,"utf-8").trim()}catch{return""}}function _6($,Z){return $||Z||process.env.LOKI_PROVIDER||"claude"}function I6($){let Z=i1(),Q=_6($,Z);switch(process.stdout.write(`${D}Current Provider${U}
|
|
308
367
|
`),process.stdout.write(`
|
|
309
|
-
`),process.stdout.write(`${
|
|
310
|
-
`),Q){case"claude":process.stdout.write(`${
|
|
311
|
-
`);break;case"cline":process.stdout.write(`${
|
|
312
|
-
`);break;case"codex":case"gemini":case"aider":process.stdout.write(`${
|
|
313
|
-
`);break;default:break}if(Z)process.stdout.write(`${
|
|
314
|
-
`);else process.stdout.write(`${
|
|
368
|
+
`),process.stdout.write(`${A}Provider:${U} ${Q}
|
|
369
|
+
`),Q){case"claude":process.stdout.write(`${C}Status:${U} Full features (subagents, parallel, MCP)
|
|
370
|
+
`);break;case"cline":process.stdout.write(`${C}Status:${U} Near-full mode (subagents, MCP, 12+ providers)
|
|
371
|
+
`);break;case"codex":case"gemini":case"aider":process.stdout.write(`${w}Status:${U} Degraded mode (sequential only)
|
|
372
|
+
`);break;default:break}if(Z)process.stdout.write(`${L}(saved in .loki/state/provider)${U}
|
|
373
|
+
`);else process.stdout.write(`${L}(default - not explicitly set)${U}
|
|
315
374
|
`);return process.stdout.write(`
|
|
316
|
-
`),process.stdout.write(`Switch provider: ${
|
|
317
|
-
`),process.stdout.write(`Available: ${
|
|
318
|
-
`),0}async function
|
|
375
|
+
`),process.stdout.write(`Switch provider: ${A}loki provider set <name>${U}
|
|
376
|
+
`),process.stdout.write(`Available: ${A}loki provider list${U}
|
|
377
|
+
`),0}async function P6(){let Z=i1()||process.env.LOKI_PROVIDER||"claude";process.stdout.write(`${D}Available Providers${U}
|
|
319
378
|
`),process.stdout.write(`
|
|
320
|
-
`);let Q=await Promise.all(
|
|
379
|
+
`);let Q=await Promise.all(j6.map(async(K)=>[K,await v(K)!==null])),X=new Map;for(let[K,q]of Q)X.set(K,q?`${C}installed${U}`:`${P}not installed${U}`);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[K,q]of z){let V=Z===K?` ${A}(current)${U}`:"";process.stdout.write(` ${q} ${X.get(K)}${V}
|
|
321
380
|
`)}return process.stdout.write(`
|
|
322
|
-
`),process.stdout.write(`Set provider: ${
|
|
323
|
-
`),0}function
|
|
381
|
+
`),process.stdout.write(`Set provider: ${A}loki provider set <name>${U}
|
|
382
|
+
`),0}function L6(){return process.stdout.write(`${D}Loki Mode Provider Management${U}
|
|
324
383
|
`),process.stdout.write(`
|
|
325
384
|
`),process.stdout.write(`Usage: loki provider <command>
|
|
326
385
|
`),process.stdout.write(`
|
|
@@ -338,17 +397,17 @@ resume from the restored state.
|
|
|
338
397
|
`),process.stdout.write(` loki provider list
|
|
339
398
|
`),process.stdout.write(` loki provider info gemini
|
|
340
399
|
`),process.stdout.write(` loki provider models
|
|
341
|
-
`),0}async function
|
|
342
|
-
`))if(X.includes('"description"'))Q++;return Q}catch{return 0}}async function
|
|
400
|
+
`),0}async function e1($){let Z=$[0]??"show",Q=$.slice(1);switch(Z){case"show":case"current":return I6(Q[0]);case"list":return P6();case"set":case"info":case"models":return F6(["provider",Z,...Q]);default:return L6()}}async function F6($){let{run:Z}=await Promise.resolve().then(() => (m(),t1)),{resolve:Q}=await import("path"),{REPO_ROOT:X}=await Promise.resolve().then(() => (f(),a1)),z=Q(X,"autonomy","loki"),K=await Z([z,...$],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(K.stdout),process.stderr.write(K.stderr),K.exitCode}d();f();Q1();m();import{existsSync as $0,readFileSync as x6}from"fs";import{resolve as r}from"path";import{mkdir as R6}from"fs/promises";var Z1=r(L1(),"learnings");function w1($){if(!$0($))return 0;try{let Z=x6($,"utf-8"),Q=0;for(let X of Z.split(`
|
|
401
|
+
`))if(X.includes('"description"'))Q++;return Q}catch{return 0}}async function E6(){await R6(Z1,{recursive:!0});let $=w1(r(Z1,"patterns.jsonl")),Z=w1(r(Z1,"mistakes.jsonl")),Q=w1(r(Z1,"successes.jsonl"));return process.stdout.write(`${D}Cross-Project Learnings${U}
|
|
343
402
|
`),process.stdout.write(`
|
|
344
|
-
`),process.stdout.write(` Patterns: ${
|
|
345
|
-
`),process.stdout.write(` Mistakes: ${
|
|
346
|
-
`),process.stdout.write(` Successes: ${
|
|
403
|
+
`),process.stdout.write(` Patterns: ${C}${$}${U}
|
|
404
|
+
`),process.stdout.write(` Mistakes: ${w}${Z}${U}
|
|
405
|
+
`),process.stdout.write(` Successes: ${A}${Q}${U}
|
|
347
406
|
`),process.stdout.write(`
|
|
348
|
-
`),process.stdout.write(`Location: ${
|
|
407
|
+
`),process.stdout.write(`Location: ${Z1}
|
|
349
408
|
`),process.stdout.write(`
|
|
350
409
|
`),process.stdout.write(`Use 'loki memory show <type>' to view entries
|
|
351
|
-
`),0}async function
|
|
410
|
+
`),0}async function S6($){if($){let X=`
|
|
352
411
|
try:
|
|
353
412
|
from memory.layers import IndexLayer
|
|
354
413
|
layer = IndexLayer('.loki/memory')
|
|
@@ -358,9 +417,9 @@ except ImportError:
|
|
|
358
417
|
print('Error: memory.layers module not found')
|
|
359
418
|
except Exception as e:
|
|
360
419
|
print(f'Error: {e}')
|
|
361
|
-
`.trim(),z=await
|
|
362
|
-
`),0;let Q=await
|
|
363
|
-
`),0;return process.stdout.write(Q.stdout),0}async function
|
|
420
|
+
`.trim(),z=await o(X,{cwd:g});return process.stdout.write(z.stdout),0}let Z=r(F(),"memory","index.json");if(!$0(Z))return process.stdout.write(`No index found
|
|
421
|
+
`),0;let Q=await o(`import json, sys; sys.stdout.write(json.dumps(json.load(open(${JSON.stringify(Z)})), indent=4) + "\\n")`);if(Q.exitCode!==0)return process.stdout.write(`No index found
|
|
422
|
+
`),0;return process.stdout.write(Q.stdout),0}async function Q0($){switch($[0]??"list"){case"list":case"ls":return E6();case"index":return S6($[1]==="rebuild");default:{let Q=r(g,"autonomy","loki"),X=await S([Q,"memory",...$],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(X.stdout),process.stderr.write(X.stderr),X.exitCode}}}var Q6=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
|
|
364
423
|
|
|
365
424
|
Usage: loki <command> [args...]
|
|
366
425
|
|
|
@@ -378,7 +437,8 @@ Phase 2 ported (Bun-native, fast):
|
|
|
378
437
|
|
|
379
438
|
All other commands fall through to the bash CLI (autonomy/loki).
|
|
380
439
|
Set LOKI_LEGACY_BASH=1 to force the bash CLI for every command.
|
|
381
|
-
`;async function
|
|
382
|
-
`),process.stderr.write(
|
|
440
|
+
`;async function B5($){let Z=$[0],Q=$.slice(1);switch(Z){case void 0:case"help":case"--help":case"-h":return process.stdout.write(Q6),0;case"version":case"--version":case"-v":return r1();case"provider":return e1(Q);case"memory":return Q0(Q);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (H0(),V0));return X(Q)}case"stats":{let{runStats:X}=await Promise.resolve().then(() => (M0(),B0));return X(Q)}case"doctor":{let{runDoctor:X}=await Promise.resolve().then(() => (L0(),P0));return X(Q)}case"rollback":{let{runRollback:X}=await Promise.resolve().then(() => (C0(),k0));return X(Q)}case"internal":{let X=Q[0];if(X==="phase1-hooks"){let{runInternalPhase1Hooks:z}=await Promise.resolve().then(() => ($6(),e0));return z(Q.slice(1))}return process.stderr.write(`Unknown internal subcommand: ${X}
|
|
441
|
+
`),2}default:return process.stderr.write(`Unknown command: ${Z}
|
|
442
|
+
`),process.stderr.write(Q6),2}}process.on("SIGINT",()=>process.exit(130));process.on("SIGTERM",()=>process.exit(143));var M5=await B5(Bun.argv.slice(2));process.exit(M5);
|
|
383
443
|
|
|
384
|
-
//# debugId=
|
|
444
|
+
//# debugId=5A91EDB7DF77076264756E2164756E21
|
package/mcp/__init__.py
CHANGED
package/mcp/server.py
CHANGED
|
@@ -2021,6 +2021,165 @@ async def loki_get_doc_coverage() -> str:
|
|
|
2021
2021
|
return json.dumps({"error": str(e)})
|
|
2022
2022
|
|
|
2023
2023
|
|
|
2024
|
+
# ============================================================
|
|
2025
|
+
# Phase 1 artifact tools (v7.5.3) -- expose findings + learnings +
|
|
2026
|
+
# counter-evidence templates produced by the Bun runner under .loki/.
|
|
2027
|
+
# ============================================================
|
|
2028
|
+
|
|
2029
|
+
@mcp.tool()
|
|
2030
|
+
async def loki_findings(iteration: int = -1) -> str:
|
|
2031
|
+
"""Read structured code-review findings for a given iteration.
|
|
2032
|
+
|
|
2033
|
+
Args:
|
|
2034
|
+
iteration: iteration number (default -1 = most recent).
|
|
2035
|
+
Returns: JSON {iteration, review_id, findings: [...]}.
|
|
2036
|
+
"""
|
|
2037
|
+
_emit_tool_event_async('loki_findings', 'start',
|
|
2038
|
+
parameters={'iteration': iteration})
|
|
2039
|
+
try:
|
|
2040
|
+
import re as _re
|
|
2041
|
+
state_dir = safe_path_join('.loki', 'state')
|
|
2042
|
+
if iteration >= 0:
|
|
2043
|
+
persisted = safe_path_join('.loki', 'state', f'findings-{iteration}.json')
|
|
2044
|
+
if os.path.exists(persisted):
|
|
2045
|
+
with safe_open(persisted, 'r') as f:
|
|
2046
|
+
data = json.load(f)
|
|
2047
|
+
_emit_tool_event_async('loki_findings', 'complete', result_status='success')
|
|
2048
|
+
return json.dumps(data)
|
|
2049
|
+
if iteration < 0 and os.path.exists(state_dir):
|
|
2050
|
+
files = [n for n in os.listdir(state_dir) if _re.fullmatch(r'findings-\d+\.json', n)]
|
|
2051
|
+
if files:
|
|
2052
|
+
files.sort(key=lambda n: int(_re.sub(r'\D', '', n) or '0'))
|
|
2053
|
+
with safe_open(safe_path_join('.loki', 'state', files[-1]), 'r') as f:
|
|
2054
|
+
data = json.load(f)
|
|
2055
|
+
_emit_tool_event_async('loki_findings', 'complete', result_status='success')
|
|
2056
|
+
return json.dumps(data)
|
|
2057
|
+
reviews_dir = safe_path_join('.loki', 'quality', 'reviews')
|
|
2058
|
+
if not os.path.exists(reviews_dir):
|
|
2059
|
+
return json.dumps({"iteration": iteration, "review_id": None, "findings": []})
|
|
2060
|
+
candidates = sorted([d for d in os.listdir(reviews_dir)
|
|
2061
|
+
if d.startswith('review-')
|
|
2062
|
+
and os.path.isdir(os.path.join(reviews_dir, d))])
|
|
2063
|
+
if iteration >= 0:
|
|
2064
|
+
candidates = [c for c in candidates if c.endswith(f'-{iteration}')]
|
|
2065
|
+
if not candidates:
|
|
2066
|
+
return json.dumps({"iteration": iteration, "review_id": None, "findings": []})
|
|
2067
|
+
latest = candidates[-1]
|
|
2068
|
+
review_path = safe_path_join('.loki', 'quality', 'reviews', latest)
|
|
2069
|
+
sev_re = _re.compile(r'\[(Critical|High|Medium|Low)\]\s*(.+)', _re.IGNORECASE)
|
|
2070
|
+
file_re = _re.compile(r'([\w./\-]+\.[a-zA-Z]+):(\d+)')
|
|
2071
|
+
findings = []
|
|
2072
|
+
for entry in os.listdir(review_path):
|
|
2073
|
+
if not entry.endswith('.txt'):
|
|
2074
|
+
continue
|
|
2075
|
+
if entry in ('diff.txt', 'files.txt', 'anti-sycophancy.txt'):
|
|
2076
|
+
continue
|
|
2077
|
+
if entry.endswith('-prompt.txt'):
|
|
2078
|
+
continue
|
|
2079
|
+
reviewer = entry[:-4]
|
|
2080
|
+
with safe_open(os.path.join(review_path, entry), 'r') as f:
|
|
2081
|
+
body = f.read()
|
|
2082
|
+
for line in body.splitlines():
|
|
2083
|
+
stripped = line.strip().lstrip('-* ').strip()
|
|
2084
|
+
m = sev_re.match(stripped)
|
|
2085
|
+
if not m:
|
|
2086
|
+
continue
|
|
2087
|
+
sev_raw, desc = m.group(1), m.group(2).strip()
|
|
2088
|
+
sev = sev_raw[:1].upper() + sev_raw[1:].lower()
|
|
2089
|
+
fl = file_re.search(desc)
|
|
2090
|
+
findings.append({
|
|
2091
|
+
"severity": sev, "reviewer": reviewer, "description": desc,
|
|
2092
|
+
"file": fl.group(1) if fl else None,
|
|
2093
|
+
"line": int(fl.group(2)) if fl else None,
|
|
2094
|
+
"raw": stripped,
|
|
2095
|
+
})
|
|
2096
|
+
result = {"iteration": iteration, "review_id": latest, "findings": findings}
|
|
2097
|
+
_emit_tool_event_async('loki_findings', 'complete', result_status='success')
|
|
2098
|
+
return json.dumps(result)
|
|
2099
|
+
except Exception as e:
|
|
2100
|
+
logger.error(f"loki_findings failed: {e}")
|
|
2101
|
+
_emit_tool_event_async('loki_findings', 'complete', result_status='error', error=str(e))
|
|
2102
|
+
return json.dumps({"error": str(e)})
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
@mcp.tool()
|
|
2106
|
+
async def loki_learnings(limit: int = 50) -> str:
|
|
2107
|
+
"""Read recent learnings (newest first) from relevant-learnings.json."""
|
|
2108
|
+
_emit_tool_event_async('loki_learnings', 'start', parameters={'limit': limit})
|
|
2109
|
+
try:
|
|
2110
|
+
path = safe_path_join('.loki', 'state', 'relevant-learnings.json')
|
|
2111
|
+
if not os.path.exists(path):
|
|
2112
|
+
return json.dumps({"version": 1, "learnings": [], "total": 0})
|
|
2113
|
+
with safe_open(path, 'r') as f:
|
|
2114
|
+
data = json.load(f)
|
|
2115
|
+
learnings = data.get('learnings', []) if isinstance(data, dict) else []
|
|
2116
|
+
if not isinstance(learnings, list):
|
|
2117
|
+
learnings = []
|
|
2118
|
+
sliced = list(reversed(learnings))[:max(1, int(limit))]
|
|
2119
|
+
result = {"version": data.get('version', 1) if isinstance(data, dict) else 1,
|
|
2120
|
+
"total": len(learnings), "learnings": sliced}
|
|
2121
|
+
_emit_tool_event_async('loki_learnings', 'complete', result_status='success')
|
|
2122
|
+
return json.dumps(result)
|
|
2123
|
+
except Exception as e:
|
|
2124
|
+
logger.error(f"loki_learnings failed: {e}")
|
|
2125
|
+
_emit_tool_event_async('loki_learnings', 'complete', result_status='error', error=str(e))
|
|
2126
|
+
return json.dumps({"error": str(e)})
|
|
2127
|
+
|
|
2128
|
+
|
|
2129
|
+
@mcp.tool()
|
|
2130
|
+
async def loki_counter_evidence_template(iteration: int) -> str:
|
|
2131
|
+
"""Generate a counter-evidence file template for the given iteration.
|
|
2132
|
+
|
|
2133
|
+
Pre-fills canonical findingId for each Critical/High finding so the
|
|
2134
|
+
user only has to fill in `claim` + `proofType`. Save the template
|
|
2135
|
+
body to .loki/state/counter-evidence-<iteration>.json to dispute
|
|
2136
|
+
findings via the override council.
|
|
2137
|
+
"""
|
|
2138
|
+
_emit_tool_event_async('loki_counter_evidence_template', 'start',
|
|
2139
|
+
parameters={'iteration': iteration})
|
|
2140
|
+
try:
|
|
2141
|
+
findings_data = json.loads(await loki_findings(iteration=iteration))
|
|
2142
|
+
if 'error' in findings_data:
|
|
2143
|
+
return json.dumps(findings_data)
|
|
2144
|
+
findings = findings_data.get('findings', [])
|
|
2145
|
+
if not findings:
|
|
2146
|
+
return json.dumps({"iteration": iteration, "template": None,
|
|
2147
|
+
"message": f"No findings for iteration {iteration}."})
|
|
2148
|
+
evidence = []
|
|
2149
|
+
for f in findings:
|
|
2150
|
+
if f.get('severity') not in ('Critical', 'High'):
|
|
2151
|
+
continue
|
|
2152
|
+
head = (f.get('raw') or '').strip()[:80]
|
|
2153
|
+
evidence.append({
|
|
2154
|
+
"findingId": f"{f.get('reviewer', '')}::{head}",
|
|
2155
|
+
"claim": "(describe why this finding is wrong, in one sentence)",
|
|
2156
|
+
"proofType": "duplicate-code-path",
|
|
2157
|
+
"artifacts": ["(file path or command output backing your claim)"],
|
|
2158
|
+
"_finding_for_reference": {
|
|
2159
|
+
"severity": f.get('severity'),
|
|
2160
|
+
"description": f.get('description'),
|
|
2161
|
+
"file": f.get('file'),
|
|
2162
|
+
"line": f.get('line'),
|
|
2163
|
+
},
|
|
2164
|
+
})
|
|
2165
|
+
result = {
|
|
2166
|
+
"iteration": iteration,
|
|
2167
|
+
"template": {"iteration": iteration, "evidence": evidence},
|
|
2168
|
+
"usage": (f"Save to .loki/state/counter-evidence-{iteration}.json "
|
|
2169
|
+
"after filling in `claim` and `proofType`. proofType MUST "
|
|
2170
|
+
"be one of: file-exists, test-passes, grep-miss, "
|
|
2171
|
+
"reviewer-misread, duplicate-code-path, out-of-scope."),
|
|
2172
|
+
}
|
|
2173
|
+
_emit_tool_event_async('loki_counter_evidence_template', 'complete',
|
|
2174
|
+
result_status='success')
|
|
2175
|
+
return json.dumps(result)
|
|
2176
|
+
except Exception as e:
|
|
2177
|
+
logger.error(f"loki_counter_evidence_template failed: {e}")
|
|
2178
|
+
_emit_tool_event_async('loki_counter_evidence_template', 'complete',
|
|
2179
|
+
result_status='error', error=str(e))
|
|
2180
|
+
return json.dumps({"error": str(e)})
|
|
2181
|
+
|
|
2182
|
+
|
|
2024
2183
|
# ============================================================
|
|
2025
2184
|
# PROMPTS - Pre-built prompt templates
|
|
2026
2185
|
# ============================================================
|