loki-mode 7.5.13 → 7.5.14
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/lib/sentrux-gate.sh +145 -0
- package/autonomy/loki +133 -0
- package/dashboard/__init__.py +1 -1
- package/docs/INSTALLATION.md +1 -1
- package/loki-ts/dist/loki.js +132 -130
- package/mcp/__init__.py +1 -1
- 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 a spec (PRD, GitHub issue, OpenAPI doc, etc.) 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.14
|
|
7
7
|
|
|
8
8
|
**You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
|
|
9
9
|
|
|
@@ -381,4 +381,4 @@ See `CHANGELOG.md` entries [7.5.7], [7.5.8], [7.5.13] for the per-fix list and r
|
|
|
381
381
|
|
|
382
382
|
---
|
|
383
383
|
|
|
384
|
-
**v7.5.
|
|
384
|
+
**v7.5.14 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
7.5.
|
|
1
|
+
7.5.14
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Loki Mode -- sentrux architectural-drift helper (v7.5.14).
|
|
3
|
+
#
|
|
4
|
+
# Why this exists:
|
|
5
|
+
# Loki's existing 11 quality gates and 3-reviewer council catch correctness
|
|
6
|
+
# and behavioral regressions, but no current gate emits a deterministic,
|
|
7
|
+
# per-iteration architecture-drift signal. sentrux (https://github.com/sentrux/sentrux)
|
|
8
|
+
# is a Rust CLI that scores codebase structure (modularity, acyclicity,
|
|
9
|
+
# depth, equality, redundancy) into a single 0-1 number, with a
|
|
10
|
+
# `gate --save` baseline plus `gate` compare workflow that catches when
|
|
11
|
+
# an iteration silently degrades architecture.
|
|
12
|
+
#
|
|
13
|
+
# Why opt-in only:
|
|
14
|
+
# sentrux is an external Rust binary (v0.5.x as of this release) that users
|
|
15
|
+
# install themselves via brew or curl. We do NOT bundle it, do NOT auto-install,
|
|
16
|
+
# and do NOT touch the iteration hot path by default. Every entry point in
|
|
17
|
+
# this file no-ops gracefully when sentrux is not on PATH.
|
|
18
|
+
#
|
|
19
|
+
# Verified facts (v7.5.14, 2026-05-03):
|
|
20
|
+
# - sentrux v0.5.7 binary works on darwin-arm64.
|
|
21
|
+
# - `sentrux gate --save <path>` writes <path>/.sentrux/baseline.json with
|
|
22
|
+
# real JSON: {timestamp, quality_signal (0..1), coupling_score, cycle_count,
|
|
23
|
+
# god_file_count, hotspot_count, complex_fn_count, max_depth,
|
|
24
|
+
# total_import_edges, cross_module_edges}.
|
|
25
|
+
# - `sentrux gate <path>` prints a "Quality: <before> -> <after>"
|
|
26
|
+
# line and either "DEGRADED" or "No degradation detected".
|
|
27
|
+
# - Defect: `sentrux gate` exits 0 even when output reports DEGRADED. This
|
|
28
|
+
# helper parses stdout and the JSON file rather than relying on exit code.
|
|
29
|
+
#
|
|
30
|
+
# Public API:
|
|
31
|
+
# sentrux_available -> 0 if binary on PATH, 1 otherwise
|
|
32
|
+
# sentrux_version -> prints "X.Y.Z" or empty on fail
|
|
33
|
+
# sentrux_baseline_save <path> -> writes <path>/.sentrux/baseline.json
|
|
34
|
+
# sentrux_baseline_quality <path> -> prints quality_signal*10000 as int
|
|
35
|
+
# (or empty on missing/malformed)
|
|
36
|
+
# sentrux_gate_diff <path> -> prints "<before>|<after>|<verdict>"
|
|
37
|
+
# where verdict is OK|DEGRADED|UNKNOWN
|
|
38
|
+
#
|
|
39
|
+
# All functions are pure helpers: no global state mutations, no side effects
|
|
40
|
+
# beyond what sentrux itself writes inside <path>/.sentrux/.
|
|
41
|
+
|
|
42
|
+
# Guard against double-source.
|
|
43
|
+
if [ "${__LOKI_SENTRUX_GATE_SH_LOADED:-0}" = "1" ]; then
|
|
44
|
+
return 0 2>/dev/null || true
|
|
45
|
+
fi
|
|
46
|
+
__LOKI_SENTRUX_GATE_SH_LOADED=1
|
|
47
|
+
|
|
48
|
+
sentrux_available() {
|
|
49
|
+
command -v sentrux >/dev/null 2>&1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
sentrux_version() {
|
|
53
|
+
if ! sentrux_available; then
|
|
54
|
+
return 1
|
|
55
|
+
fi
|
|
56
|
+
sentrux --version 2>/dev/null | head -1 | awk '{print $NF}' | tr -d 'v'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Run sentrux gate --save against <path>. Returns 0 on success, 1 on failure
|
|
60
|
+
# or if sentrux is unavailable. stderr from sentrux is preserved for debugging
|
|
61
|
+
# but stdout is suppressed.
|
|
62
|
+
sentrux_baseline_save() {
|
|
63
|
+
local path="${1:-.}"
|
|
64
|
+
if ! sentrux_available; then
|
|
65
|
+
return 1
|
|
66
|
+
fi
|
|
67
|
+
if [ ! -d "$path" ]; then
|
|
68
|
+
return 1
|
|
69
|
+
fi
|
|
70
|
+
sentrux gate --save "$path" >/dev/null 2>&1
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Read quality_signal from <path>/.sentrux/baseline.json and print it as an
|
|
74
|
+
# integer in the 0-10000 range (matching sentrux's stdout convention). Prints
|
|
75
|
+
# empty string and returns 1 on missing file, malformed JSON, or missing field.
|
|
76
|
+
sentrux_baseline_quality() {
|
|
77
|
+
local path="${1:-.}"
|
|
78
|
+
local baseline="$path/.sentrux/baseline.json"
|
|
79
|
+
if [ ! -f "$baseline" ]; then
|
|
80
|
+
return 1
|
|
81
|
+
fi
|
|
82
|
+
# Use python3 for JSON parsing -- jq is not always installed and python3
|
|
83
|
+
# is already a hard requirement in cmd_doctor. Pin float math to int via
|
|
84
|
+
# round() so callers get a stable, comparable integer.
|
|
85
|
+
local q
|
|
86
|
+
q=$(python3 -c "
|
|
87
|
+
import json, sys
|
|
88
|
+
try:
|
|
89
|
+
with open(sys.argv[1]) as f:
|
|
90
|
+
d = json.load(f)
|
|
91
|
+
v = d.get('quality_signal')
|
|
92
|
+
if v is None:
|
|
93
|
+
sys.exit(1)
|
|
94
|
+
print(int(round(float(v) * 10000)))
|
|
95
|
+
except Exception:
|
|
96
|
+
sys.exit(1)
|
|
97
|
+
" "$baseline" 2>/dev/null)
|
|
98
|
+
if [ -z "$q" ]; then
|
|
99
|
+
return 1
|
|
100
|
+
fi
|
|
101
|
+
printf '%s' "$q"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# Run sentrux gate against <path> and print "<before>|<after>|<verdict>".
|
|
105
|
+
# verdict is OK | DEGRADED | UNKNOWN. Returns 0 if a valid verdict was parsed,
|
|
106
|
+
# 1 only when sentrux is unavailable, the path is missing, or no Quality line
|
|
107
|
+
# could be parsed from output. before/after are integers (0-10000) or empty.
|
|
108
|
+
#
|
|
109
|
+
# Important: sentrux gate's exit code is inconsistent in v0.5.7 -- it has been
|
|
110
|
+
# observed to exit 0 on DEGRADED in some shapes and 1 in others. This helper
|
|
111
|
+
# captures stdout regardless of exit code and relies on text parsing as the
|
|
112
|
+
# source of truth.
|
|
113
|
+
sentrux_gate_diff() {
|
|
114
|
+
local path="${1:-.}"
|
|
115
|
+
if ! sentrux_available; then
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
118
|
+
if [ ! -d "$path" ]; then
|
|
119
|
+
return 1
|
|
120
|
+
fi
|
|
121
|
+
local out
|
|
122
|
+
# Deliberately do NOT gate on sentrux's exit code -- capture output either
|
|
123
|
+
# way. The `|| true` on the substitution keeps a nonzero gate exit from
|
|
124
|
+
# tripping callers running under `set -e`.
|
|
125
|
+
out=$(sentrux gate "$path" 2>/dev/null || true)
|
|
126
|
+
if [ -z "$out" ]; then
|
|
127
|
+
printf '%s' "||UNKNOWN"
|
|
128
|
+
return 1
|
|
129
|
+
fi
|
|
130
|
+
local quality_line before after verdict
|
|
131
|
+
# Match "Quality: 4333 -> 4321" or with arrow variants.
|
|
132
|
+
quality_line=$(printf '%s\n' "$out" | grep -E '^Quality:' | head -1 || true)
|
|
133
|
+
if [ -n "$quality_line" ]; then
|
|
134
|
+
before=$(printf '%s' "$quality_line" | grep -oE '[0-9]+' | sed -n '1p')
|
|
135
|
+
after=$(printf '%s' "$quality_line" | grep -oE '[0-9]+' | sed -n '2p')
|
|
136
|
+
fi
|
|
137
|
+
if printf '%s' "$out" | grep -q 'DEGRADED'; then
|
|
138
|
+
verdict="DEGRADED"
|
|
139
|
+
elif printf '%s' "$out" | grep -q 'No degradation detected'; then
|
|
140
|
+
verdict="OK"
|
|
141
|
+
else
|
|
142
|
+
verdict="UNKNOWN"
|
|
143
|
+
fi
|
|
144
|
+
printf '%s|%s|%s' "${before:-}" "${after:-}" "$verdict"
|
|
145
|
+
}
|
package/autonomy/loki
CHANGED
|
@@ -6795,6 +6795,16 @@ cmd_doctor() {
|
|
|
6795
6795
|
echo -e " ${YELLOW}WARN${NC} OTEL - not configured (set LOKI_OTEL_ENDPOINT)"
|
|
6796
6796
|
warn_count=$((warn_count + 1))
|
|
6797
6797
|
fi
|
|
6798
|
+
# sentrux check (v7.5.14, optional architectural-drift gate)
|
|
6799
|
+
if command -v sentrux &>/dev/null; then
|
|
6800
|
+
local _sentrux_ver
|
|
6801
|
+
_sentrux_ver=$(sentrux --version 2>/dev/null | head -1 | awk '{print $NF}')
|
|
6802
|
+
echo -e " ${GREEN}PASS${NC} sentrux ${_sentrux_ver:-unknown} (architectural drift gate: loki sentrux help)"
|
|
6803
|
+
pass_count=$((pass_count + 1))
|
|
6804
|
+
else
|
|
6805
|
+
echo -e " ${YELLOW}WARN${NC} sentrux - not installed (optional, brew install sentrux/tap/sentrux)"
|
|
6806
|
+
warn_count=$((warn_count + 1))
|
|
6807
|
+
fi
|
|
6798
6808
|
echo ""
|
|
6799
6809
|
|
|
6800
6810
|
echo -e "${CYAN}System:${NC}"
|
|
@@ -6977,6 +6987,126 @@ print(json.dumps(result, indent=2))
|
|
|
6977
6987
|
"
|
|
6978
6988
|
}
|
|
6979
6989
|
|
|
6990
|
+
# Architectural-drift gate (v7.5.14, opt-in).
|
|
6991
|
+
#
|
|
6992
|
+
# Wraps the external sentrux Rust binary -- https://github.com/sentrux/sentrux --
|
|
6993
|
+
# to give users a deterministic per-iteration architecture-drift signal that
|
|
6994
|
+
# complements the existing 11 quality gates and 3-reviewer council. This is a
|
|
6995
|
+
# manual subcommand only in v7.5.14; iteration-loop integration is deferred
|
|
6996
|
+
# pending a real-PRD smoke test (tracked in CHANGELOG).
|
|
6997
|
+
#
|
|
6998
|
+
# Subcommands:
|
|
6999
|
+
# loki sentrux baseline [<path>] -- save .sentrux/baseline.json
|
|
7000
|
+
# loki sentrux gate [<path>] -- compare current vs baseline
|
|
7001
|
+
# loki sentrux status [<path>] -- print current baseline + verdict
|
|
7002
|
+
#
|
|
7003
|
+
# Default path is the current working directory.
|
|
7004
|
+
cmd_sentrux() {
|
|
7005
|
+
# shellcheck source=autonomy/lib/sentrux-gate.sh
|
|
7006
|
+
if ! source "$_LOKI_SCRIPT_DIR/lib/sentrux-gate.sh" 2>/dev/null \
|
|
7007
|
+
&& ! source "$(dirname "$0")/lib/sentrux-gate.sh" 2>/dev/null; then
|
|
7008
|
+
echo -e "${RED}sentrux helper missing -- expected at autonomy/lib/sentrux-gate.sh${NC}" >&2
|
|
7009
|
+
return 1
|
|
7010
|
+
fi
|
|
7011
|
+
|
|
7012
|
+
local sub="${1:-help}"
|
|
7013
|
+
if [ "$#" -gt 0 ]; then shift; fi
|
|
7014
|
+
local target="${1:-.}"
|
|
7015
|
+
|
|
7016
|
+
case "$sub" in
|
|
7017
|
+
baseline)
|
|
7018
|
+
if ! sentrux_available; then
|
|
7019
|
+
echo -e "${YELLOW}sentrux not installed.${NC} Install via:" >&2
|
|
7020
|
+
echo " brew install sentrux/tap/sentrux" >&2
|
|
7021
|
+
echo " or download from https://github.com/sentrux/sentrux/releases" >&2
|
|
7022
|
+
return 2
|
|
7023
|
+
fi
|
|
7024
|
+
if sentrux_baseline_save "$target"; then
|
|
7025
|
+
local q
|
|
7026
|
+
q=$(sentrux_baseline_quality "$target" || echo "?")
|
|
7027
|
+
echo -e "${GREEN}Baseline saved.${NC} Quality: $q (path: $target)"
|
|
7028
|
+
return 0
|
|
7029
|
+
fi
|
|
7030
|
+
echo -e "${RED}Failed to save baseline.${NC}" >&2
|
|
7031
|
+
return 1
|
|
7032
|
+
;;
|
|
7033
|
+
gate)
|
|
7034
|
+
if ! sentrux_available; then
|
|
7035
|
+
echo -e "${YELLOW}sentrux not installed.${NC} Run 'loki sentrux baseline' for setup hints." >&2
|
|
7036
|
+
return 2
|
|
7037
|
+
fi
|
|
7038
|
+
local diff verdict before after
|
|
7039
|
+
diff=$(sentrux_gate_diff "$target")
|
|
7040
|
+
verdict=$(printf '%s' "$diff" | awk -F'|' '{print $3}')
|
|
7041
|
+
before=$(printf '%s' "$diff" | awk -F'|' '{print $1}')
|
|
7042
|
+
after=$(printf '%s' "$diff" | awk -F'|' '{print $2}')
|
|
7043
|
+
case "$verdict" in
|
|
7044
|
+
OK)
|
|
7045
|
+
echo -e "${GREEN}OK${NC} Quality: $before -> $after (no degradation)"
|
|
7046
|
+
return 0
|
|
7047
|
+
;;
|
|
7048
|
+
DEGRADED)
|
|
7049
|
+
echo -e "${RED}DEGRADED${NC} Quality: $before -> $after"
|
|
7050
|
+
echo " Architecture regressed since the saved baseline."
|
|
7051
|
+
echo " Inspect with: sentrux scan $target"
|
|
7052
|
+
return 1
|
|
7053
|
+
;;
|
|
7054
|
+
*)
|
|
7055
|
+
echo -e "${YELLOW}UNKNOWN${NC} Could not parse sentrux output."
|
|
7056
|
+
echo " Try: sentrux gate --save $target (to refresh baseline)"
|
|
7057
|
+
return 2
|
|
7058
|
+
;;
|
|
7059
|
+
esac
|
|
7060
|
+
;;
|
|
7061
|
+
status)
|
|
7062
|
+
if ! sentrux_available; then
|
|
7063
|
+
echo "sentrux: not installed (optional)"
|
|
7064
|
+
echo "install: brew install sentrux/tap/sentrux"
|
|
7065
|
+
return 0
|
|
7066
|
+
fi
|
|
7067
|
+
local v
|
|
7068
|
+
v=$(sentrux_version || echo "unknown")
|
|
7069
|
+
echo "sentrux: v$v"
|
|
7070
|
+
local q
|
|
7071
|
+
if q=$(sentrux_baseline_quality "$target"); then
|
|
7072
|
+
echo "baseline ($target): quality=$q"
|
|
7073
|
+
else
|
|
7074
|
+
echo "baseline ($target): not saved (run: loki sentrux baseline $target)"
|
|
7075
|
+
fi
|
|
7076
|
+
return 0
|
|
7077
|
+
;;
|
|
7078
|
+
help|--help|-h|"")
|
|
7079
|
+
echo -e "${BOLD}loki sentrux${NC} - Architectural drift gate (opt-in, requires sentrux binary)"
|
|
7080
|
+
echo ""
|
|
7081
|
+
echo "Usage:"
|
|
7082
|
+
echo " loki sentrux baseline [<path>] Save current architecture as baseline"
|
|
7083
|
+
echo " loki sentrux gate [<path>] Compare current vs baseline (exit 1 on DEGRADED)"
|
|
7084
|
+
echo " loki sentrux status [<path>] Show binary version + saved baseline quality"
|
|
7085
|
+
echo ""
|
|
7086
|
+
echo "Default path is the current directory."
|
|
7087
|
+
echo ""
|
|
7088
|
+
echo "About:"
|
|
7089
|
+
echo " Wraps the sentrux CLI (https://github.com/sentrux/sentrux), a Rust tool that"
|
|
7090
|
+
echo " scores codebase structure into a single 0-10000 quality signal. Useful as a"
|
|
7091
|
+
echo " supplement to Loki's existing 11 quality gates when you want an objective"
|
|
7092
|
+
echo " per-iteration architectural-drift number."
|
|
7093
|
+
echo ""
|
|
7094
|
+
echo " Iteration-loop auto-gating is planned for a future release; for now this"
|
|
7095
|
+
echo " subcommand is the manual integration surface."
|
|
7096
|
+
echo ""
|
|
7097
|
+
echo "Install sentrux:"
|
|
7098
|
+
echo " brew install sentrux/tap/sentrux"
|
|
7099
|
+
echo " curl -fsSL https://raw.githubusercontent.com/sentrux/sentrux/main/install.sh | sh"
|
|
7100
|
+
return 0
|
|
7101
|
+
;;
|
|
7102
|
+
*)
|
|
7103
|
+
echo -e "${RED}Unknown subcommand: $sub${NC}" >&2
|
|
7104
|
+
echo "Run 'loki sentrux help' for usage." >&2
|
|
7105
|
+
return 1
|
|
7106
|
+
;;
|
|
7107
|
+
esac
|
|
7108
|
+
}
|
|
7109
|
+
|
|
6980
7110
|
# Show version
|
|
6981
7111
|
cmd_version() {
|
|
6982
7112
|
echo "Loki Mode v$(get_version)"
|
|
@@ -11974,6 +12104,9 @@ main() {
|
|
|
11974
12104
|
doctor)
|
|
11975
12105
|
cmd_doctor "$@"
|
|
11976
12106
|
;;
|
|
12107
|
+
sentrux)
|
|
12108
|
+
cmd_sentrux "$@"
|
|
12109
|
+
;;
|
|
11977
12110
|
setup-skill)
|
|
11978
12111
|
cmd_setup_skill "$@"
|
|
11979
12112
|
;;
|
package/dashboard/__init__.py
CHANGED
package/docs/INSTALLATION.md
CHANGED
package/loki-ts/dist/loki.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var Q6=Object.defineProperty;var X6=($)=>$;function Z6($,Q){this[$]=X6.bind(null,Q)}var
|
|
2
|
+
var Q6=Object.defineProperty;var X6=($)=>$;function Z6($,Q){this[$]=X6.bind(null,Q)}var y=($,Q)=>{for(var z in Q)Q6($,z,{get:Q[z],enumerable:!0,configurable:!0,set:Z6.bind(Q,z)})};var S=($,Q)=>()=>($&&(Q=$($=0)),Q);var V1=import.meta.require;var a1={};y(a1,{lokiDir:()=>P,homeLokiDir:()=>w1,findRepoRootForVersion:()=>E1,REPO_ROOT:()=>u});import{resolve as f,dirname as F1}from"path";import{fileURLToPath as K6}from"url";import{existsSync as G1}from"fs";import{homedir as W6}from"os";function U6(){let $=n1;for(let Q=0;Q<6;Q++){if(G1(f($,"VERSION"))&&G1(f($,"autonomy/run.sh")))return $;let z=F1($);if(z===$)break;$=z}return f(n1,"..","..","..")}function E1($){let Q=$;for(let z=0;z<6;z++){if(G1(f(Q,"VERSION"))&&G1(f(Q,"autonomy/run.sh")))return Q;let X=F1(Q);if(X===Q)break;Q=X}return f($,"..","..","..")}function P(){return process.env.LOKI_DIR??f(process.cwd(),".loki")}function w1(){return f(W6(),".loki")}var n1,u;var m=S(()=>{n1=F1(K6(import.meta.url));u=U6()});var t1={};y(t1,{runOrThrow:()=>J6,run:()=>E,commandVersion:()=>Y6,commandExists:()=>b,ShellError:()=>S1});async function E($,Q={}){let z=Bun.spawn({cmd:[...$],stdout:"pipe",stderr:"pipe",env:Q.env?{...process.env,...Q.env}:process.env,cwd:Q.cwd}),X,Z;if(Q.timeoutMs&&Q.timeoutMs>0)X=setTimeout(()=>{try{z.kill("SIGTERM")}catch{}Z=setTimeout(()=>{try{z.kill("SIGKILL")}catch{}},2000)},Q.timeoutMs);try{let[K,W,q]=await Promise.all([new Response(z.stdout).text(),new Response(z.stderr).text(),z.exited]);return{stdout:K,stderr:W,exitCode:q}}finally{if(X)clearTimeout(X);if(Z)clearTimeout(Z)}}async function J6($,Q={}){let z=await E($,Q);if(z.exitCode!==0)throw new S1(`command failed (${z.exitCode}): ${$.join(" ")}`,z.exitCode,z.stdout,z.stderr);return z}async function b($){let Q=B6($),z=await E(["sh","-c",`command -v ${Q}`],{timeoutMs:5000});if(z.exitCode===0)return z.stdout.trim()||null;return null}function B6($){if(!/^[A-Za-z0-9._/-]+$/.test($))throw Error(`refused to shell-escape suspect token: ${$}`);return $}async function Y6($,Q="--version"){if(!await b($))return null;let X=await E([$,Q],{timeoutMs:5000});if(X.exitCode!==0)return null;return((X.stdout||X.stderr).split(/\r?\n/)[0]?.trim()??"")||null}var S1;var p=S(()=>{S1=class S1 extends Error{message;exitCode;stdout;stderr;constructor($,Q,z,X){super($);this.message=$;this.exitCode=Q;this.stdout=z;this.stderr=X;this.name="ShellError"}}});function c($){return M6?"":$}var M6,L,k,R,b5,A,C,x,U;var n=S(()=>{M6=(process.env.NO_COLOR??"").length>0;L=c("\x1B[0;31m"),k=c("\x1B[0;32m"),R=c("\x1B[1;33m"),b5=c("\x1B[0;34m"),A=c("\x1B[0;36m"),C=c("\x1B[1m"),x=c("\x1B[2m"),U=c("\x1B[0m")});import{existsSync as R6}from"fs";async function s(){if(Q1!==void 0)return Q1;let $="/opt/homebrew/bin/python3.12";if(R6($))return Q1=$,$;let Q=await b("python3.12");if(Q)return Q1=Q,Q;let z=await b("python3");return Q1=z,z}async function a($,Q={}){let z=await s();if(!z)return{stdout:"",stderr:"python3 not found",exitCode:127};return E([z,"-c",$],Q)}var Q1;var X1=S(()=>{p()});var q0={};y(q0,{runStatus:()=>m6});import{existsSync as N,readFileSync as K1,readdirSync as Q0,statSync as X0}from"fs";import{resolve as F,basename as N6}from"path";async function C6(){if(await b("jq"))return!0;return process.stdout.write(`${L}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 J1($){if(!Number.isFinite($)||$<=0)return!1;try{return process.kill($,0),!0}catch{return!1}}function B1($){if(!N($))return null;try{let Q=K1($,"utf-8").trim();if(!Q)return null;let z=Number.parseInt(Q,10);return Number.isFinite(z)?z:null}catch{return null}}function k6($){let Q=[],z=B1(F($,"loki.pid"));if(z!==null&&J1(z))Q.push(`global:${z}`);let X=F($,"sessions");if(N(X)){let Z=[];try{Z=Q0(X)}catch{Z=[]}for(let K of Z){let W=F(X,K);try{if(!X0(W).isDirectory())continue}catch{continue}let q=F(W,"loki.pid"),H=B1(q);if(H!==null&&J1(H))Q.push(`${K}:${H}`)}}if(N($)){let Z=[];try{Z=Q0($)}catch{Z=[]}for(let K of Z){if(!K.startsWith("run-")||!K.endsWith(".pid"))continue;let W=F($,K);try{if(!X0(W).isFile())continue}catch{continue}let q=N6(K,".pid").slice(4),H=B1(W);if(H!==null&&J1(H)){if(!Q.some((J)=>J.startsWith(`${q}:`)))Q.push(`${q}:${H}`)}}}return Q}async function Z0($,Q){let z=await E(["jq","-r",$,Q]);if(z.exitCode!==0)return null;return z.stdout.trim()}function K0($,Q){try{let z=K1($,"utf-8"),Z=JSON.parse(z)[Q];if(typeof Z==="number"){if(Q==="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 W0($,Q,z){try{let X=K1($,"utf-8"),K=JSON.parse(X)[Q];if(typeof K==="number"&&Number.isFinite(K))return K;return z}catch{return z}}async function b6(){let $=P();if(!await C6())return 1;if(!N($))return process.stdout.write(`${C}Loki Mode Status${U}
|
|
8
8
|
`),process.stdout.write(`
|
|
9
|
-
`),process.stdout.write(`${R}No active session found.${
|
|
9
|
+
`),process.stdout.write(`${R}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(`${x}Current directory: ${process.cwd()}${U}
|
|
17
|
+
`),0;process.stdout.write(`${C}Loki Mode Status${U}
|
|
18
18
|
`),process.stdout.write(`
|
|
19
|
-
`);let Q="",z=
|
|
20
|
-
`),process.stdout.write(`${
|
|
19
|
+
`);let Q="",z=F($,"state","provider");if(N(z))try{Q=K1(z,"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(`${A}Provider:${U} ${X} (${Z})
|
|
20
|
+
`),process.stdout.write(`${x} Switch with: loki provider set <claude|codex|gemini|cline|aider>${U}
|
|
21
21
|
`),process.stdout.write(`
|
|
22
|
-
`);let K=k6($);if(K.length>0){process.stdout.write(`${k}Active Sessions: ${K.length}${
|
|
23
|
-
`);for(let G of K){let M=G.indexOf(":"),O=M>=0?G.slice(0,M):G,j=M>=0?G.slice(M+1):"";if(O==="global")process.stdout.write(` ${A}[global]${
|
|
24
|
-
`);else process.stdout.write(` ${A}[#${O}]${
|
|
22
|
+
`);let K=k6($);if(K.length>0){process.stdout.write(`${k}Active Sessions: ${K.length}${U}
|
|
23
|
+
`);for(let G of K){let M=G.indexOf(":"),O=M>=0?G.slice(0,M):G,j=M>=0?G.slice(M+1):"";if(O==="global")process.stdout.write(` ${A}[global]${U} PID ${j}
|
|
24
|
+
`);else process.stdout.write(` ${A}[#${O}]${U} PID ${j}
|
|
25
25
|
`)}process.stdout.write(`
|
|
26
|
-
`),process.stdout.write(`${
|
|
27
|
-
`),process.stdout.write(`${
|
|
26
|
+
`),process.stdout.write(`${x} Stop specific: loki stop <session-id>${U}
|
|
27
|
+
`),process.stdout.write(`${x} Stop all: loki stop${U}
|
|
28
28
|
`),process.stdout.write(`
|
|
29
|
-
`)}if(N(
|
|
30
|
-
`),process.stdout.write(`${
|
|
29
|
+
`)}if(N(F($,"PAUSE")))process.stdout.write(`${R}Status: PAUSED${U}
|
|
30
|
+
`),process.stdout.write(`${x} Resume with: loki resume${U}
|
|
31
31
|
`),process.stdout.write(`
|
|
32
|
-
`);else if(N(
|
|
33
|
-
`),process.stdout.write(`${
|
|
32
|
+
`);else if(N(F($,"STOP")))process.stdout.write(`${L}Status: STOPPED${U}
|
|
33
|
+
`),process.stdout.write(`${x} Clear with: loki resume${U}
|
|
34
34
|
`),process.stdout.write(`
|
|
35
|
-
`);let
|
|
36
|
-
`);try{process.stdout.write(
|
|
37
|
-
`)}let
|
|
38
|
-
`);let G=await Z0('.currentPhase // "unknown"',
|
|
39
|
-
`)}let
|
|
40
|
-
`)}let
|
|
41
|
-
`);else process.stdout.write(`${A}Cost:${
|
|
42
|
-
`)}let J=
|
|
43
|
-
`)}let B=
|
|
35
|
+
`);let W=F($,"STATUS.txt");if(N(W)){process.stdout.write(`${A}Session Info:${U}
|
|
36
|
+
`);try{process.stdout.write(K1(W,"utf-8"))}catch{}process.stdout.write(`
|
|
37
|
+
`)}let q=F($,"state","orchestrator.json");if(N(q)){process.stdout.write(`${A}Orchestrator State:${U}
|
|
38
|
+
`);let G=await Z0('.currentPhase // "unknown"',q);process.stdout.write(`${G??"unknown"}
|
|
39
|
+
`)}let H=F($,"queue","pending.json");if(N(H)){let G=await Z0('if type == "array" then length elif .tasks then .tasks | length else 0 end',H);process.stdout.write(`${A}Pending Tasks:${U} ${G??"0"}
|
|
40
|
+
`)}let V=F($,"metrics","budget.json");if(N(V)){let G=K0(V,"budget_limit"),M=K0(V,"budget_used");if(G!=="0")process.stdout.write(`${A}Budget:${U} $${M} / $${G}
|
|
41
|
+
`);else process.stdout.write(`${A}Cost:${U} $${M} (no limit)
|
|
42
|
+
`)}let J=F($,"state","context-usage.json");if(N(J)){let G=W0(J,"window_size",200000),M=W0(J,"used_tokens",0),O=0;if(G>0)O=Math.floor(M*100/G);process.stdout.write(`${A}Context:${U} ${O}% (${M} / ${G} tokens)
|
|
43
|
+
`)}let B=F($,"dashboard","dashboard.pid");if(N(B)){let G=B1(B);if(G!==null&&J1(G)){let M=process.env.LOKI_DASHBOARD_PORT||"57374";process.stdout.write(`${A}Dashboard:${U} http://127.0.0.1:${M}/
|
|
44
44
|
`)}}return await y6($),process.stdout.write(`
|
|
45
|
-
`),process.stdout.write(`${
|
|
46
|
-
`),process.stdout.write(`${
|
|
47
|
-
`),0}async function y6($){let Q=
|
|
48
|
-
${A}Phase 1 artifacts:${
|
|
49
|
-
`),K){let
|
|
50
|
-
`)}}if(
|
|
51
|
-
`)}}if(
|
|
52
|
-
`)}}function h6($){if(!N($))return[];try{return
|
|
53
|
-
`),1;let Q=u,z=P(),X=process.env.LOKI_DASHBOARD_PORT||"57374",Z=process.env.LOKI_PROVIDER||"claude",K=await
|
|
45
|
+
`),process.stdout.write(`${x} Tip: loki context show - detailed token breakdown${U}
|
|
46
|
+
`),process.stdout.write(`${x} Tip: loki code overview - codebase intelligence${U}
|
|
47
|
+
`),0}async function y6($){let Q=F($,"state"),z=h6(Q),X=F(Q,"relevant-learnings.json"),Z=F($,"escalations"),K=z.length>0,W=N(X),q=N(Z);if(!K&&!W&&!q)return;if(process.stdout.write(`
|
|
48
|
+
${A}Phase 1 artifacts:${U}
|
|
49
|
+
`),K){let H=z[z.length-1],V=U0(H);if(V&&Array.isArray(V.findings)){let J={Critical:0,High:0,Medium:0,Low:0};for(let G of V.findings){let M=String(G.severity??"");if(M in J)J[M]=(J[M]??0)+1}let B=Object.entries(J).filter(([,G])=>G>0).map(([G,M])=>`${M} ${G.toLowerCase()}`).join(", ");process.stdout.write(` Findings (iter ${V.iteration??"?"}): ${B||"none"} -- ${V.findings.length} total
|
|
50
|
+
`)}}if(W){let H=U0(X);if(H&&Array.isArray(H.learnings)&&H.learnings.length>0){let V=new Map;for(let B of H.learnings){let G=String(B.trigger??"unknown");V.set(G,(V.get(G)??0)+1)}let J=[...V.entries()].sort((B,G)=>G[1]-B[1]).slice(0,3).map(([B,G])=>`${G} ${B}`).join(", ");process.stdout.write(` Learnings: ${H.learnings.length} total (${J})
|
|
51
|
+
`)}}if(q){let H=0,V="";try{let B=(await import("fs")).readdirSync(Z).filter((G)=>G.endsWith(".md"));if(H=B.length,B.length>0)B.sort(),V=B[B.length-1]??""}catch{}if(H>0)process.stdout.write(` Escalations: ${H} handoff doc${H===1?"":"s"} (latest: ${V})
|
|
52
|
+
`)}}function h6($){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,W=Number.parseInt(Z.replace(/[^0-9]/g,""),10)||0;return K-W}).map((X)=>F($,X))}catch{return[]}}function U0($){try{let Q=V1("fs");return JSON.parse(Q.readFileSync($,"utf-8"))}catch{return null}}async function v6(){let $=await s();if(!$)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
53
|
+
`),1;let Q=u,z=P(),X=process.env.LOKI_DASHBOARD_PORT||"57374",Z=process.env.LOKI_PROVIDER||"claude",K=await E([$,"-c",D6,Q,z,X,Z],{timeoutMs:30000});if(K.exitCode!==0)return process.stderr.write(`{"error": "Failed to generate JSON status. Ensure python3 is available."}
|
|
54
54
|
`),1;return process.stdout.write(K.stdout),0}async function m6($){let Q=[...$];while(Q.length>0){let z=Q[0];if(z==="--json")return v6();if(z==="--help"||z==="-h")return process.stdout.write(`Usage: loki status [--json]
|
|
55
|
-
`),0;return process.stdout.write(`${
|
|
55
|
+
`),0;return process.stdout.write(`${L}Unknown flag: ${z}${U}
|
|
56
56
|
`),process.stdout.write(`Usage: loki status [--json]
|
|
57
57
|
`),1}return b6()}var D6=`
|
|
58
58
|
import json, os, sys, time
|
|
@@ -261,9 +261,9 @@ if os.path.isfile(gate_count_file):
|
|
|
261
261
|
result['phase1'] = phase1
|
|
262
262
|
|
|
263
263
|
print(json.dumps(result, indent=2))
|
|
264
|
-
`;var
|
|
265
|
-
`)}function J0($){let Q=!1,z=!1;for(let
|
|
266
|
-
Start a session with: loki start <prd>`}}let Z=u6(X);return{exitCode:0,stdout:Q?p6(Z,z):c6(Z,z)}}async function l6($){let Q=J0($);return console.log(Q.stdout),Q.exitCode}var Y0=
|
|
264
|
+
`;var H0=S(()=>{p();X1();n();m()});var B0={};y(B0,{runStats:()=>l6,computeStats:()=>J0});import{readdirSync as V0,readFileSync as g6,statSync as G0}from"fs";import{join as l}from"path";function i($){try{if(!G0($).isFile())return null;return JSON.parse(g6($,"utf-8"))}catch{return null}}function k1($){try{return G0($).isDirectory()}catch{return!1}}function f6($){if(!k1($))return[];try{let Q=V0($).filter((z)=>z.startsWith("iteration-")&&z.endsWith(".json"));return Q.sort(),Q.map((z)=>l($,z))}catch{return[]}}function e($){return Math.trunc($).toLocaleString("en-US")}function D1($){let Q=Math.trunc($);if(Q<60)return`${Q}s`;let z=Math.trunc(Q/3600),X=Math.trunc(Q%3600/60),Z=Q%60;if(z>0)return`${z}h ${String(X).padStart(2,"0")}m`;return`${X}m ${String(Z).padStart(2,"0")}s`}function d($,Q=0){let z=Math.pow(10,Q);return Math.round($*z)/z}function $1($,Q){return $.toFixed(Q)}function C1($,Q){return $.length>=Q?$:$+" ".repeat(Q-$.length)}function u6($){let Q="N/A",z=0,X=i(l($,"state","orchestrator.json"));if(X&&typeof X==="object"){if(typeof X.currentPhase==="string")Q=X.currentPhase;if(typeof X.currentIteration==="number")z=X.currentIteration}let Z=l($,"metrics","efficiency"),K=f6(Z),W=[];for(let T of K){let _=i(T);if(_&&typeof _==="object")W.push(_)}if(W.length>0)z=Math.max(z,W.length);let q=W.reduce((T,_)=>T+(_.input_tokens??0),0),H=W.reduce((T,_)=>T+(_.output_tokens??0),0),V=q+H,J=W.reduce((T,_)=>T+(_.cost_usd??0),0),B=W.reduce((T,_)=>T+(_.duration_seconds??0),0),G=0,M=0,O=i(l($,"metrics","budget.json"));if(O&&typeof O==="object"){if(typeof O.budget_limit==="number")G=O.budget_limit;if(typeof O.budget_used==="number")M=O.budget_used}let j=0,w=0,g=i(l($,"state","quality-gates.json"));if(g&&typeof g==="object"){if(Array.isArray(g)){for(let T of g)if(w+=1,T===!0)j+=1;else if(T&&typeof T==="object"){let _=T;if(_.passed===!0||_.status==="passed")j+=1}}else for(let T of Object.values(g))if(typeof T==="boolean"){if(w+=1,T)j+=1}else if(T&&typeof T==="object"){w+=1;let _=T;if(_.passed===!0||_.status==="passed")j+=1}}let H1={},h=i(l($,"quality","gate-failure-count.json"));if(h&&typeof h==="object"&&!Array.isArray(h)){let T={};for(let[_,v]of Object.entries(h))if(typeof v==="number")T[_]=v;H1=T}let I=0,D=0,z1=0,R1=l($,"quality");if(k1(R1)){let T=[];try{T=V0(R1)}catch{T=[]}for(let _ of T){if(!_.endsWith(".json")||_==="gate-failure-count.json")continue;let v=i(l(R1,_));if(!v||typeof v!=="object")continue;if(!(("verdict"in v)||("approved"in v)||("reviewers"in v)))continue;I+=1;let o1=(v.verdict??"").toString().toLowerCase();if(v.approved===!0||["approved","approve","pass"].includes(o1))D+=1;else if(["revision","revise","changes_requested","reject"].includes(o1))z1+=1}}return{phase:Q,iterationCount:z,iterations:W,totalInput:q,totalOutput:H,totalTokens:V,totalCost:J,totalDuration:B,budgetLimit:G,budgetUsed:M,gatesPassed:j,gatesTotal:w,gateFailures:H1,reviewsTotal:I,reviewsApproved:D,reviewsRevision:z1}}function p6($,Q){let z=$.iterationCount,X={session:{iterations:z,duration_seconds:$.totalDuration,phase:$.phase},tokens:{input:$.totalInput,output:$.totalOutput,total:$.totalTokens,cost_usd:d($.totalCost,2)},quality:{gates_passed:$.gatesPassed,gates_total:$.gatesTotal,reviews_total:$.reviewsTotal,reviews_approved:$.reviewsApproved,reviews_revision:$.reviewsRevision,gate_failures:$.gateFailures},efficiency:{avg_tokens_per_iteration:z>0?d($.totalTokens/z,0):0,avg_cost_per_iteration:z>0?d($.totalCost/z,2):0,avg_duration_per_iteration:z>0?d($.totalDuration/z,1):0},budget:{used:d($.budgetUsed,2),limit:$.budgetLimit,percent:$.budgetLimit>0?d($.budgetUsed/$.budgetLimit*100,1):0}};if(Q)X.iterations=$.iterations.map((W,q)=>({number:q+1,input_tokens:W.input_tokens??0,output_tokens:W.output_tokens??0,cost_usd:d(W.cost_usd??0,2),duration_seconds:W.duration_seconds??0}));let Z=JSON.stringify(X,null,2);function K(W,q){if(!q)return;let H=new RegExp(`("${W}": )(-?\\d+)(,?)$`,"m");Z=Z.replace(H,(V,J,B,G)=>`${J}${B}.0${G}`)}if(K("avg_duration_per_iteration",z>0&&Number.isInteger(X.efficiency.avg_duration_per_iteration)),K("percent",$.budgetLimit>0&&Number.isInteger(X.budget.percent)),K("cost_usd",z>0&&Number.isInteger(X.tokens.cost_usd)),Q)Z=Z.replace(/("cost_usd": )(-?\d+)(,?)$/gm,(W,q,H,V)=>`${q}${H}.0${V}`);return Z}function c6($,Q){let z=[];if(z.push("Loki Mode Session Statistics"),z.push("============================"),z.push(""),z.push("Session"),z.push(` Iterations completed: ${$.iterationCount}`),z.push(` Duration: ${D1($.totalDuration)}`),z.push(` Current phase: ${$.phase}`),z.push(""),z.push("Token Usage"),$.iterations.length>0)z.push(` Input tokens: ${e($.totalInput)}`),z.push(` Output tokens: ${e($.totalOutput)}`),z.push(` Total tokens: ${e($.totalTokens)}`),z.push(` Estimated cost: $${$1($.totalCost,2)}`);else z.push(" N/A (no iteration metrics found)");if(z.push(""),z.push("Quality Gates"),$.gatesTotal>0){let X=Math.round($.gatesPassed/$.gatesTotal*100);z.push(` Gates passed: ${$.gatesPassed}/${$.gatesTotal} (${X}%)`)}else z.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";z.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)z.push(` Gate failures: ${X.join(", ")}`)}if(z.push(""),z.push("Efficiency"),$.iterationCount>0&&$.iterations.length>0){let X=Math.round($.totalTokens/$.iterationCount),Z=$.totalCost/$.iterationCount,K=$.totalDuration/$.iterationCount;z.push(` Avg tokens/iteration: ${e(X)}`),z.push(` Avg cost/iteration: $${$1(Z,2)}`),z.push(` Avg duration/iteration: ${D1(K)}`)}else z.push(" N/A (no iteration metrics found)");if(z.push(""),z.push("Budget"),$.budgetLimit>0){let X=d($.budgetUsed/$.budgetLimit*100,1),Z=Number.isInteger(X)?`${X}.0`:`${X}`;z.push(` Used: $${$1($.budgetUsed,2)} / $${$1($.budgetLimit,2)} (${Z}%)`)}else if($.budgetUsed>0)z.push(` Used: $${$1($.budgetUsed,2)} (no limit set)`);else z.push(" N/A");if(Q&&$.iterations.length>0)z.push(""),z.push("Per-Iteration Breakdown"),$.iterations.forEach((X,Z)=>{let K=Z+1,W=C1(e(X.input_tokens??0),10),q=C1(e(X.output_tokens??0),10),H=X.cost_usd??0,V=D1(X.duration_seconds??0),J=C1(`${K}`,3);z.push(` #${J} input: ${W} output: ${q} cost: $${$1(H,2)} time: ${V}`)});return z.join(`
|
|
265
|
+
`)}function J0($){let Q=!1,z=!1;for(let W of $)if(W==="--json")Q=!0;else if(W==="--efficiency")z=!0;let X=P();if(!k1(X)){if(Q)return{exitCode:0,stdout:'{"error": "No active session"}'};return{exitCode:0,stdout:`${R}No active session found.${U}
|
|
266
|
+
Start a session with: loki start <prd>`}}let Z=u6(X);return{exitCode:0,stdout:Q?p6(Z,z):c6(Z,z)}}async function l6($){let Q=J0($);return console.log(Q.stdout),Q.exitCode}var Y0=S(()=>{m();n()});var L0={};y(L0,{runDoctor:()=>X3,pythonImportOk:()=>h1,httpReachable:()=>b1,checkTool:()=>O0,checkSkills:()=>j0,checkDisk:()=>y1,buildDoctorJson:()=>I0,_setPythonImportOkForTest:()=>i6});import{existsSync as d6,lstatSync as o6,readlinkSync as n6,statfsSync as a6}from"fs";import{homedir as A0}from"os";import{resolve as M0}from"path";function s6($){let Q=$.match(r6);return Q?Q[1]:null}async function t6($){try{let Q=await E([$,"--version"],{timeoutMs:5000}),z=(Q.stdout||Q.stderr||"").trim();return s6(z)}catch{return null}}function T0($,Q){let z=$.split(".").map((Z)=>parseInt(Z,10)),X=Q.split(".").map((Z)=>parseInt(Z,10));while(z.length<2)z.push(0);while(X.length<2)X.push(0);for(let Z=0;Z<2;Z++){let K=z[Z]??0,W=X[Z]??0;if(Number.isNaN(K)||Number.isNaN(W))return 0;if(K!==W)return K-W}return 0}async function O0($,Q,z,X=null){let Z=await b(Q),K=Z!==null,W=K?await t6(Q):null,q="pass";if(!K)q=z==="required"?"fail":"warn";else if(X&&W){if(T0(W,X)<0)q=z==="required"?"fail":"warn"}return{name:$,command:Q,found:K,version:W,required:z,min_version:X,status:q,path:Z}}function y1(){let $=null;try{let z=a6(A0()),X=Number(z.bavail)*Number(z.bsize);$=Math.round(X/1073741824*10)/10}catch{$=null}let Q="pass";if($!==null){if($<1)Q="fail";else if($<5)Q="warn"}return{available_gb:$,status:Q}}async function b1($,Q=2000){try{return(await fetch($,{signal:AbortSignal.timeout(Q)})).ok}catch{return!1}}async function h1($,Q=!1){let z=`import ${$}`,X=Q?30000:5000;if(!Q)return(await a(z,{timeoutMs:X})).exitCode===0;let Z=await s();if(!Z)return!1;return(await E([Z,"-c",z],{timeoutMs:X})).exitCode===0}function i6($){A1.fn=$??h1}function j0(){let $=A0();return e6.map(({name:Q,dir:z})=>{let X=M0($,z),Z=X,K=M0(X,"SKILL.md");if(d6(K))return{name:Q,path:Z,status:"pass",detail:""};try{if(o6(X).isSymbolicLink()){let q="unknown";try{q=n6(X)}catch{}return{name:Q,path:Z,status:"fail",detail:`(broken symlink -> ${q})`}}}catch{}return{name:Q,path:Z,status:"warn",detail:"(not found - run 'loki setup-skill')"}})}async function _0(){return Promise.all($3.map(async($)=>{return{...await O0($.jsonName,$.cmd,$.required,$.min??null),displayName:$.displayName}}))}async function I0(){let Q=(await _0()).map(({displayName:W,...q})=>q),z=y1(),X=0,Z=0,K=0;for(let W of Q)if(W.status==="pass")X++;else if(W.status==="fail")Z++;else K++;if(z.status==="pass")X++;else if(z.status==="fail")Z++;else K++;return{checks:Q,disk:z,summary:{passed:X,failed:Z,warnings:K,ok:Z===0}}}function Y($){switch($){case"pass":return`${k}PASS${U}`;case"fail":return`${L}FAIL${U}`;case"warn":return`${R}WARN${U}`}}function Y1($){let Q=$.version?` (v${$.version})`:"",z=$.displayName;if(!$.found){let X=$.required==="required"?"not found":$.required==="recommended"?"not found (recommended)":"not found (optional)";return` ${Y($.status)} ${z} - ${X}`}if($.min_version&&$.version&&T0($.version,$.min_version)<0){let X=$.required==="required"?"requires":"recommended";return` ${Y($.status)} ${z}${Q} - ${X} >= ${$.min_version}`}return` ${Y($.status)} ${z}${Q}`}function M1($,Q){if(Q==="pass")$.pass++;else if(Q==="fail")$.fail++;else $.warn++}function z3(){process.stdout.write(`${C}loki doctor${U} - Check system prerequisites
|
|
267
267
|
|
|
268
268
|
`),process.stdout.write(`Usage: loki doctor [--json]
|
|
269
269
|
|
|
@@ -272,89 +272,91 @@ Start a session with: loki start <prd>`}}let Z=u6(X);return{exitCode:0,stdout:Q?
|
|
|
272
272
|
|
|
273
273
|
`),process.stdout.write(`Checks: node, python3, jq, git, curl, bash version,
|
|
274
274
|
`),process.stdout.write(` claude/codex/gemini CLIs, and disk space.
|
|
275
|
-
`)}async function Q3(){process.stdout.write(`${
|
|
275
|
+
`)}async function Q3(){process.stdout.write(`${C}Loki Mode Doctor${U}
|
|
276
276
|
|
|
277
277
|
`),process.stdout.write(`Checking system prerequisites...
|
|
278
278
|
|
|
279
|
-
`);let $={pass:0,fail:0,warn:0},Q=await _0(),z=new Map(Q.map((I)=>[I.command,I]));process.stdout.write(`${A}Required:${
|
|
280
|
-
`);for(let I of["node","python3","jq","git","curl"]){let
|
|
281
|
-
`),
|
|
282
|
-
`),process.stdout.write(`${A}AI Providers:${
|
|
283
|
-
`);let X=["claude","codex","gemini","cline","aider"],Z=!1;for(let I of X){let
|
|
284
|
-
`),
|
|
285
|
-
`),process.stdout.write(` ${R}Install: npm install -g @anthropic-ai/claude-code${
|
|
279
|
+
`);let $={pass:0,fail:0,warn:0},Q=await _0(),z=new Map(Q.map((I)=>[I.command,I]));process.stdout.write(`${A}Required:${U}
|
|
280
|
+
`);for(let I of["node","python3","jq","git","curl"]){let D=z.get(I);process.stdout.write(Y1(D)+`
|
|
281
|
+
`),M1($,D.status)}process.stdout.write(`
|
|
282
|
+
`),process.stdout.write(`${A}AI Providers:${U}
|
|
283
|
+
`);let X=["claude","codex","gemini","cline","aider"],Z=!1;for(let I of X){let D=z.get(I);if(process.stdout.write(Y1(D)+`
|
|
284
|
+
`),M1($,D.status),D.found)Z=!0}if(!Z)process.stdout.write(` ${Y("fail")} No AI provider CLI installed -- at least one is required
|
|
285
|
+
`),process.stdout.write(` ${R}Install: npm install -g @anthropic-ai/claude-code${U}
|
|
286
286
|
`),$.fail++;process.stdout.write(`
|
|
287
|
-
`),process.stdout.write(`${A}API Keys:${
|
|
288
|
-
`);let K=z.get("claude")?.found??!1,
|
|
289
|
-
`),$.pass++;else if(K)process.stdout.write(` ${
|
|
290
|
-
`);if(
|
|
291
|
-
`),$.pass++;else if(
|
|
292
|
-
`);if(
|
|
293
|
-
`),$.pass++;else if(
|
|
287
|
+
`),process.stdout.write(`${A}API Keys:${U}
|
|
288
|
+
`);let K=z.get("claude")?.found??!1,W=z.get("codex")?.found??!1,q=z.get("gemini")?.found??!1,H=process.env;if(H.ANTHROPIC_API_KEY)process.stdout.write(` ${Y("pass")} ANTHROPIC_API_KEY is set
|
|
289
|
+
`),$.pass++;else if(K)process.stdout.write(` ${x} -- ${U} ANTHROPIC_API_KEY not set (Claude CLI uses its own login)
|
|
290
|
+
`);if(H.OPENAI_API_KEY)process.stdout.write(` ${Y("pass")} OPENAI_API_KEY is set
|
|
291
|
+
`),$.pass++;else if(W)process.stdout.write(` ${x} -- ${U} OPENAI_API_KEY not set (Codex CLI uses its own login)
|
|
292
|
+
`);if(H.GOOGLE_API_KEY||H.GEMINI_API_KEY)process.stdout.write(` ${Y("pass")} GOOGLE_API_KEY is set
|
|
293
|
+
`),$.pass++;else if(q)process.stdout.write(` ${x} -- ${U} GOOGLE_API_KEY not set (Gemini CLI uses its own login)
|
|
294
294
|
`);process.stdout.write(`
|
|
295
|
-
`),process.stdout.write(`${A}Skills:${
|
|
296
|
-
`);for(let I of j0())if(I.status==="pass")process.stdout.write(` ${Y("pass")} ${I.name} ${
|
|
297
|
-
`),$.pass++;else if(I.status==="fail")process.stdout.write(` ${Y("fail")} ${I.name} ${
|
|
298
|
-
`),process.stdout.write(` ${R}Fix: loki setup-skill${
|
|
299
|
-
`),$.fail++;else process.stdout.write(` ${Y("warn")} ${I.name} ${
|
|
295
|
+
`),process.stdout.write(`${A}Skills:${U}
|
|
296
|
+
`);for(let I of j0())if(I.status==="pass")process.stdout.write(` ${Y("pass")} ${I.name} ${x}${I.path}${U}
|
|
297
|
+
`),$.pass++;else if(I.status==="fail")process.stdout.write(` ${Y("fail")} ${I.name} ${x}${I.detail}${U}
|
|
298
|
+
`),process.stdout.write(` ${R}Fix: loki setup-skill${U}
|
|
299
|
+
`),$.fail++;else process.stdout.write(` ${Y("warn")} ${I.name} ${x}${I.detail}${U}
|
|
300
300
|
`),$.warn++;process.stdout.write(`
|
|
301
|
-
`),process.stdout.write(`${A}Integrations:${
|
|
302
|
-
`);let[
|
|
301
|
+
`),process.stdout.write(`${A}Integrations:${U}
|
|
302
|
+
`);let[V,J,B]=await Promise.all([A1.fn("mcp"),A1.fn("numpy",!0),A1.fn("sentence_transformers",!0)]);if(V)process.stdout.write(` ${Y("pass")} MCP SDK (Python)
|
|
303
303
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} MCP SDK - not installed (pip3 install mcp)
|
|
304
304
|
`),$.warn++;if(J)process.stdout.write(` ${Y("pass")} numpy (vector search)
|
|
305
305
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} numpy - not installed (pip3 install numpy)
|
|
306
306
|
`),$.warn++;if(B)process.stdout.write(` ${Y("pass")} sentence-transformers (embeddings)
|
|
307
307
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} sentence-transformers - not installed (loki memory vectors setup)
|
|
308
|
-
`),$.warn++;if(await
|
|
308
|
+
`),$.warn++;if(await b1("http://localhost:8100/api/v2/heartbeat"))process.stdout.write(` ${Y("pass")} ChromaDB server (port 8100)
|
|
309
309
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} ChromaDB - not running (docker start loki-chroma)
|
|
310
|
-
`),$.warn++;let G=process.env.LOKI_MIROFISH_URL;if(G)if(await
|
|
310
|
+
`),$.warn++;let G=process.env.LOKI_MIROFISH_URL;if(G)if(await b1(`${G}/health`))process.stdout.write(` ${Y("pass")} MiroFish server (${G})
|
|
311
311
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} MiroFish - not running (loki start --mirofish-docker <image>)
|
|
312
312
|
`),$.warn++;if(process.env.LOKI_OTEL_ENDPOINT)process.stdout.write(` ${Y("pass")} OTEL endpoint: ${process.env.LOKI_OTEL_ENDPOINT}
|
|
313
313
|
`),$.pass++;else process.stdout.write(` ${Y("warn")} OTEL - not configured (set LOKI_OTEL_ENDPOINT)
|
|
314
|
+
`),$.warn++;if(await b("sentrux")){let I="unknown";try{let z1=(await E(["sentrux","--version"],{timeoutMs:2000})).stdout.split(/\s+/).filter(Boolean).pop();if(z1)I=z1.replace(/^v/,"")}catch{}process.stdout.write(` ${Y("pass")} sentrux ${I} (architectural drift gate: loki sentrux help)
|
|
315
|
+
`),$.pass++}else process.stdout.write(` ${Y("warn")} sentrux - not installed (optional, brew install sentrux/tap/sentrux)
|
|
314
316
|
`),$.warn++;process.stdout.write(`
|
|
315
|
-
`),process.stdout.write(`${A}System:${
|
|
316
|
-
`);let M=z.get("bash");process.stdout.write(
|
|
317
|
-
`),
|
|
318
|
-
`),
|
|
319
|
-
`),$.warn++;else if(j.status==="fail")process.stdout.write(` ${Y("fail")} Disk space: ${
|
|
320
|
-
`),$.fail++;else if(j.status==="warn")process.stdout.write(` ${Y("warn")} Disk space: ${
|
|
321
|
-
`),$.warn++;else process.stdout.write(` ${Y("pass")} Disk space: ${
|
|
317
|
+
`),process.stdout.write(`${A}System:${U}
|
|
318
|
+
`);let M=z.get("bash");process.stdout.write(Y1(M)+`
|
|
319
|
+
`),M1($,M.status);let O=z.get("bun");if(O)process.stdout.write(Y1(O)+`
|
|
320
|
+
`),M1($,O.status);let j=y1(),w=j.available_gb===null?null:Math.floor(j.available_gb);if(w===null)process.stdout.write(` ${Y("warn")} Disk space: unable to determine
|
|
321
|
+
`),$.warn++;else if(j.status==="fail")process.stdout.write(` ${Y("fail")} Disk space: ${w}GB available (need >= 1GB)
|
|
322
|
+
`),$.fail++;else if(j.status==="warn")process.stdout.write(` ${Y("warn")} Disk space: ${w}GB available (low)
|
|
323
|
+
`),$.warn++;else process.stdout.write(` ${Y("pass")} Disk space: ${w}GB available
|
|
322
324
|
`),$.pass++;process.stdout.write(`
|
|
323
|
-
`),process.stdout.write(`${A}Runtime route:${
|
|
324
|
-
`);let g=process.versions.bun!==void 0,
|
|
325
|
+
`),process.stdout.write(`${A}Runtime route:${U}
|
|
326
|
+
`);let g=process.versions.bun!==void 0,H1=process.argv[0]??"(unknown)";if(process.stdout.write(` ${Y("pass")} Active runtime: ${g?"Bun":"Node"} (${H1})
|
|
325
327
|
`),process.env.LOKI_LEGACY_BASH==="1"||process.env.LOKI_LEGACY_BASH==="true")process.stdout.write(` ${Y("warn")} LOKI_LEGACY_BASH set: shim routes every command to autonomy/loki (bash)
|
|
326
328
|
`);if(process.env.LOKI_TS_ENTRY)process.stdout.write(` ${Y("pass")} LOKI_TS_ENTRY override: ${process.env.LOKI_TS_ENTRY}
|
|
327
329
|
`);if(process.env.BUN_FROM_SOURCE==="1"||process.env.BUN_FROM_SOURCE==="true")process.stdout.write(` ${Y("pass")} BUN_FROM_SOURCE set: shim prefers loki-ts/src/ over dist/
|
|
328
|
-
`);let h=await s();if(h!==null){let
|
|
329
|
-
`);else if(
|
|
330
|
+
`);let h=await s();if(h!==null){let D=(await E([h,"-c","import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"],{timeoutMs:5000})).stdout.trim();if(D.startsWith("3.12"))process.stdout.write(` ${Y("pass")} Python 3.12 (chromadb / sentence-transformers): ${D} at ${h}
|
|
331
|
+
`);else if(D)process.stdout.write(` ${Y("warn")} Python 3.12 NOT found -- using ${D} at ${h}; chromadb / sentence-transformers may fail. Install python3.12 (brew install python@3.12 / apt install python3.12).
|
|
330
332
|
`);else process.stdout.write(` ${Y("warn")} Python 3 found at ${h} but version probe failed; chromadb may not work.
|
|
331
333
|
`)}else process.stdout.write(` ${Y("warn")} Python 3 not on PATH -- memory + MCP integrations disabled.
|
|
332
334
|
`);if(process.stdout.write(`
|
|
333
|
-
`),process.stdout.write(`${
|
|
335
|
+
`),process.stdout.write(`${C}Summary:${U} ${k}${$.pass} passed${U}, ${L}${$.fail} failed${U}, ${R}${$.warn} warnings${U}
|
|
334
336
|
|
|
335
|
-
`),$.fail>0)return process.stdout.write(`${
|
|
337
|
+
`),$.fail>0)return process.stdout.write(`${L}Some required prerequisites are missing.${U}
|
|
336
338
|
`),process.stdout.write(`Install missing dependencies and run 'loki doctor' again.
|
|
337
|
-
`),1;if($.warn>0)return process.stdout.write(`${R}All required checks passed with some warnings.${
|
|
338
|
-
`),0;return process.stdout.write(`${k}All checks passed. System is ready for Loki Mode.${
|
|
339
|
-
`),0}async function X3($){let Q=!1;for(let z of $)if(z==="--json")Q=!0;else if(z==="--help"||z==="-h")return z3(),0;else return process.stderr.write(`${
|
|
339
|
+
`),1;if($.warn>0)return process.stdout.write(`${R}All required checks passed with some warnings.${U}
|
|
340
|
+
`),0;return process.stdout.write(`${k}All checks passed. System is ready for Loki Mode.${U}
|
|
341
|
+
`),0}async function X3($){let Q=!1;for(let z of $)if(z==="--json")Q=!0;else if(z==="--help"||z==="-h")return z3(),0;else return process.stderr.write(`${L}Unknown option: ${z}${U}
|
|
340
342
|
`),process.stderr.write(`Usage: loki doctor [--json]
|
|
341
343
|
`),1;if(Q){let z=await I0();return process.stdout.write(JSON.stringify(z,null,2)+`
|
|
342
|
-
`),0}return Q3()}var r6,
|
|
343
|
-
`),K3(z,$)}async function P0($,Q){let z=
|
|
344
|
-
`),0;process.stdout.write(`${
|
|
345
|
-
`);for(let Z of X)process.stdout.write(` ${A}${Z.id}${
|
|
346
|
-
`);return 0}case"show":{let X=z[0];if(!X)return process.stderr.write(`${
|
|
347
|
-
`),2;try{let Z=
|
|
348
|
-
`),0}catch(Z){return process.stderr.write(`${
|
|
349
|
-
`),1}}case"to":{let X=z[0];if(!X)return process.stderr.write(`${
|
|
350
|
-
`),2;return C0(X)}case"latest":{let X=
|
|
351
|
-
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${A}${Z.id}${
|
|
344
|
+
`),0}return Q3()}var r6,A1,e6,$3;var x0=S(()=>{p();X1();n();r6=/(\d+\.\d+(?:\.\d+)*)/;A1={fn:h1};e6=[{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"}];$3=[{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{closeSync as A7,fstatSync as T7,lstatSync as O7,mkdirSync as Z3,openSync as j7,readSync as _7,renameSync as K3,rmSync as I7,statSync as L7,unlinkSync as x7,writeFileSync as W3,writeSync as P7}from"fs";import{dirname as U3}from"path";function W1($,Q){Z3(U3($),{recursive:!0});let z=`${$}.tmp.${process.pid}.${++q3}`;W3(z,`${JSON.stringify(Q,null,2)}
|
|
345
|
+
`),K3(z,$)}async function P0($,Q){let z=T1.get($)??Promise.resolve(),X=()=>{},Z=new Promise((W)=>{X=W}),K=z.catch(()=>{}).then(()=>Z);T1.set($,K);try{return await z.catch(()=>{}),await Q()}finally{if(X(),T1.get($)===K)T1.delete($)}}var q3=0,T1;var O1=S(()=>{T1=new Map});import{existsSync as j1,mkdirSync as H3,copyFileSync as V3,readFileSync as G3,readdirSync as J3,statSync as B3,writeFileSync as S7,renameSync as Y3,appendFileSync as N7,rmSync as D7}from"fs";import{join as r,dirname as M3}from"path";function _1($){return r($,"state","checkpoints")}function T3($){let Q=_1($);if(!j1(Q))return[];return J3(Q).filter((z)=>z.startsWith("cp-")).filter((z)=>{try{return B3(r(Q,z)).isDirectory()}catch{return!1}})}function O3($){return[...$].sort((Q,z)=>{let X=R0(Q),Z=R0(z);return X-Z})}function R0($){let Q=$.split("-");if(Q.length<3)return 0;let z=Q[Q.length-1],X=Number.parseInt(z??"0",10);return Number.isFinite(X)?X:0}function m1($){let Q=$??P(),z=O3(T3(Q)),X=[];for(let Z of z){let K=F0(Q,Z);if(K)X.push(K)}return X}function F0($,Q){let z=r(_1($),Q,"metadata.json");if(!j1(z))return null;try{let X=JSON.parse(G3(z,"utf-8"));return j3(X,z)}catch{return null}}function j3($,Q){let z=L3($,Q);return z.ok?z.value:null}function L3($,Q){if($===null||typeof $!=="object")return console.warn(`[checkpoint] invalid metadata at ${Q}: not an object`),{ok:!1,reason:"invalid_type",field:"<root>"};let z=$,X=["id","timestamp","task_id","task_description","git_sha","git_branch","provider","phase"];for(let Z of X){if(!(Z in z))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${Z}" missing`),{ok:!1,reason:"missing_field",field:Z};if(typeof z[Z]!=="string")return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${Z}" not a string`),{ok:!1,reason:"invalid_type",field:Z}}if(!Object.prototype.hasOwnProperty.call(z,"iteration"))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "iteration" missing`),{ok:!1,reason:"missing_field",field:"iteration"};if(typeof z.iteration!=="number"||!Number.isFinite(z.iteration))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "iteration" not a finite number`),{ok:!1,reason:"invalid_type",field:"iteration"};for(let Z of I3){let K=z[Z];if(_3.test(K))return console.warn(`[checkpoint] invalid metadata at ${Q}: field "${Z}" contains control characters`),{ok:!1,reason:"control_chars",field:Z}}return{ok:!0,value:{id:z.id,timestamp:z.timestamp,iteration:z.iteration,task_id:z.task_id,task_description:z.task_description,git_sha:z.git_sha,git_branch:z.git_branch,provider:z.provider,phase:z.phase}}}function g1($,Q){if(!x3.test($))throw new E0($);let z=Q??P(),X=r(_1(z),$);if(!j1(X))throw new v1($);let Z=F0(z,$);if(!Z)throw new v1($);return Z}function w0($,Q){let z=g1($,Q),X=Q??P(),Z=r(_1(X),$),K=[];for(let W of P3){let q=r(Z,W);if(!j1(q))continue;K.push({from:q,to:r(X,W)})}return{id:$,metadata:z,restore:K}}function S0($){let Q=[],z=0;for(let X of $.restore)try{H3(M3(X.to),{recursive:!0});let Z=`${X.to}.tmp.${process.pid}.${++A3}`;V3(X.from,Z),Y3(Z,X.to),z+=1}catch(Z){Q.push(`${X.from} -> ${X.to}: ${Z.message}`)}return{restored:z,errors:Q}}var h7,A3=0,_3,I3,x3,v1,E0,P3;var N0=S(()=>{m();p();O1();h7=Promise.resolve();_3=/[\x00-\x08\x0a-\x1f\x7f-\x9f]/,I3=["id","task_id","git_sha","git_branch","provider","phase"];x3=/^[a-zA-Z0-9_-]+$/;v1=class v1 extends Error{id;constructor($){super(`Checkpoint not found: ${$}`);this.id=$;this.name="CheckpointNotFoundError"}};E0=class E0 extends Error{id;constructor($){super(`Invalid checkpoint ID: must be alphanumeric, hyphens, underscores only (got: ${$})`);this.id=$;this.name="InvalidCheckpointIdError"}};P3=["state/orchestrator.json","queue/pending.json","queue/completed.json","queue/in-progress.json","queue/current-task.json"]});var k0={};y(k0,{runRollback:()=>R3});async function R3($){let Q=$[0],z=$.slice(1);if(Q===void 0||Q==="help"||Q==="--help"||Q==="-h")return process.stdout.write(D0),Q===void 0?1:0;switch(Q){case"list":{let X=[...m1()].reverse();if(X.length===0)return process.stdout.write(`${R}No checkpoints found.${U}
|
|
346
|
+
`),0;process.stdout.write(`${C}Checkpoints${U} (${X.length}, newest first):
|
|
347
|
+
`);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}
|
|
348
|
+
`);return 0}case"show":{let X=z[0];if(!X)return process.stderr.write(`${L}Missing checkpoint id.${U} Use \`loki rollback list\`.
|
|
349
|
+
`),2;try{let Z=g1(X);return process.stdout.write(`${JSON.stringify(Z,null,2)}
|
|
350
|
+
`),0}catch(Z){return process.stderr.write(`${L}Failed to read checkpoint:${U} ${Z.message}
|
|
351
|
+
`),1}}case"to":{let X=z[0];if(!X)return process.stderr.write(`${L}Missing checkpoint id.${U} Use \`loki rollback list\`.
|
|
352
|
+
`),2;return C0(X)}case"latest":{let X=m1(),Z=X[X.length-1];if(!Z)return process.stderr.write(`${L}No checkpoints found to roll back to.${U}
|
|
353
|
+
`),1;return process.stdout.write(`Rolling back to latest checkpoint: ${A}${Z.id}${U}
|
|
352
354
|
`),C0(Z.id)}default:return process.stderr.write(`Unknown subcommand: ${Q}
|
|
353
|
-
`),process.stderr.write(D0),2}}function C0($){let Q;try{Q=w0($)}catch(X){return process.stderr.write(`${
|
|
354
|
-
`),1}if(Q.restore.length===0)return process.stdout.write(`${R}Checkpoint ${$} has no restorable state files; nothing to do.${
|
|
355
|
-
`),0;let z=S0(Q);if(z.errors.length>0){for(let X of z.errors)process.stderr.write(`${
|
|
356
|
-
`);return process.stderr.write(`${
|
|
357
|
-
`),1}return process.stdout.write(`${k}Rolled back ${z.restored}/${Q.restore.length} state files from ${$}.${
|
|
355
|
+
`),process.stderr.write(D0),2}}function C0($){let Q;try{Q=w0($)}catch(X){return process.stderr.write(`${L}Cannot plan rollback:${U} ${X.message}
|
|
356
|
+
`),1}if(Q.restore.length===0)return process.stdout.write(`${R}Checkpoint ${$} has no restorable state files; nothing to do.${U}
|
|
357
|
+
`),0;let z=S0(Q);if(z.errors.length>0){for(let X of z.errors)process.stderr.write(`${L}restore error:${U} ${X}
|
|
358
|
+
`);return process.stderr.write(`${L}Partial rollback: ${z.restored}/${Q.restore.length} files restored.${U}
|
|
359
|
+
`),1}return process.stdout.write(`${k}Rolled back ${z.restored}/${Q.restore.length} state files from ${$}.${U}
|
|
358
360
|
`),process.stdout.write("Run `loki start` to resume from the restored state.\n"),0}var D0=`Usage: loki rollback <subcommand>
|
|
359
361
|
|
|
360
362
|
Subcommands:
|
|
@@ -370,8 +372,8 @@ Restored files (matches autonomy/run.sh:7028 byte-for-byte):
|
|
|
370
372
|
Note: only state files are restored. Source code, git history, and the
|
|
371
373
|
session's autonomy-state.json are unchanged. Re-run \`loki start\` to
|
|
372
374
|
resume from the restored state.
|
|
373
|
-
`;var b0=
|
|
374
|
-
`)}function D3($,Q,z="review-test",X=0){return m0($,Q,z,X)}var
|
|
375
|
+
`;var b0=S(()=>{N0();n()});var u1={};y(u1,{renderFindingsForPrompt:()=>N3,loadPreviousFindings:()=>f1,findLatestReviewDir:()=>g0,_parseReviewerOutputForTests:()=>D3});import{existsSync as h0,readFileSync as y0,readdirSync as v0,statSync as F3}from"fs";import{join as I1}from"path";function S3($){let Q=$.toLowerCase();if(Q==="critical")return"Critical";if(Q==="high")return"High";if(Q==="medium")return"Medium";return"Low"}function m0($,Q,z,X){let Z=[],K=$.split(/\r?\n/);for(let W of K){let q=W.trim();if(q.length===0)continue;let H=q.replace(/^[-*]\s*/,""),V=E3.exec(H);if(!V||!V[1]||!V[2])continue;let J=S3(V[1]),B=V[2].trim(),G=w3.exec(B),M=G&&G[1]?G[1]:null,O=G&&G[2]?Number.parseInt(G[2],10):null;Z.push({reviewId:z,iteration:X,reviewer:Q,severity:J,description:B,file:M,line:Number.isFinite(O)?O:null,raw:q})}return Z}function g0($,Q){let z=I1($,"quality","reviews");if(!h0(z))return null;let X;try{X=v0(z)}catch{return null}let Z=Q===void 0?X.filter((q)=>q.startsWith("review-")):X.filter((q)=>q.endsWith(`-${Q}`)&&q.startsWith("review-"));if(Z.length===0)return null;Z.sort();let K=Z[Z.length-1];if(!K)return null;let W=I1(z,K);try{if(!F3(W).isDirectory())return null}catch{return null}return W}function f1($,Q){let z=g0($,Q);if(z===null)return{reviewDir:null,reviewId:null,iteration:null,findings:[]};let X=null,Z=null,K=I1(z,"aggregate.json");if(h0(K))try{let V=y0(K,"utf-8"),J=JSON.parse(V);if(typeof J.review_id==="string")X=J.review_id;if(typeof J.iteration==="number")Z=J.iteration}catch{}let W;try{W=v0(z)}catch{return{reviewDir:z,reviewId:X,iteration:Z,findings:[]}}let q=new Set(["diff.txt","files.txt","anti-sycophancy.txt"]),H=[];for(let V of W){if(!V.endsWith(".txt"))continue;if(q.has(V))continue;if(V.endsWith("-prompt.txt"))continue;let J=V.replace(/\.txt$/,""),B;try{B=y0(I1(z,V),"utf-8")}catch{continue}H.push(...m0(B,J,X??"",Z??-1))}return{reviewDir:z,reviewId:X,iteration:Z,findings:H}}function N3($){if($.length===0)return"";let Q=["Critical","High","Medium","Low"],z=new Map;for(let Z of Q)z.set(Z,[]);for(let Z of $){let K=z.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 Q){let K=z.get(Z)??[];if(K.length===0)continue;X.push(` [${Z}] (${K.length}):`);for(let W of K){let q=W.file?` (${W.file}${W.line!==null?":"+W.line:""})`:"";X.push(` - ${W.description}${q} -- via ${W.reviewer}`)}}return X.join(`
|
|
376
|
+
`)}function D3($,Q,z="review-test",X=0){return m0($,Q,z,X)}var E3,w3;var L1=S(()=>{E3=/\[(Critical|High|Medium|Low)\]\s*(.+)/i,w3=/([\w.\-/]+\.[a-zA-Z]+):(\d+)/});import{existsSync as C3}from"fs";import{join as k3}from"path";async function f0($,Q){let z=k3($,"memory");if(!C3(z))return{stored:!1,reason:"memory dir not initialized"};let X=Math.max(0,Math.floor(Q.durationSeconds??0)),Z={_LOKI_PROJECT_DIR:u,_LOKI_TARGET_DIR:process.cwd(),_LOKI_TASK_ID:Q.taskId,_LOKI_OUTCOME:Q.outcome,_LOKI_PHASE:Q.phase,_LOKI_GOAL:Q.goal,_LOKI_DURATION:String(X),_LOKI_LOKI_DIR:$},W=await a(`
|
|
375
377
|
import os, sys
|
|
376
378
|
project = os.environ.get('_LOKI_PROJECT_DIR', '')
|
|
377
379
|
loki = os.environ.get('_LOKI_LOKI_DIR', '.loki')
|
|
@@ -398,23 +400,23 @@ try:
|
|
|
398
400
|
print('OK')
|
|
399
401
|
except Exception as e:
|
|
400
402
|
print('ERR:' + str(e))
|
|
401
|
-
`,{env:Z,timeoutMs:15000});if(
|
|
402
|
-
`)}async function u3($,Q,z,X={}){let Z=`[${z.severity}] ${z.description}`;return
|
|
403
|
-
`)}function K5($,Q){s3(z5($),{recursive:!0});let z=`${$}.tmp.${process.pid}.${++s0}`;$5(z,Q),e3(z,$)}function
|
|
404
|
-
`),process.stderr.write(
|
|
405
|
-
`),2;let z=P();try{let Z=(await Promise.resolve().then(() => (
|
|
406
|
-
`),0;let K=
|
|
403
|
+
`,{env:Z,timeoutMs:15000});if(W.exitCode===127)return{stored:!1,reason:"python3 not found"};let q=W.stdout.trim();if(q==="OK")return{stored:!0,reason:"stored"};if(q.startsWith("ERR:"))return{stored:!1,reason:q.replace(/^ERR:/,"")};return{stored:!1,reason:W.stderr.trim()||"unknown"}}var u0=S(()=>{X1();m()});var d0={};y(d0,{loadLearnings:()=>p1,appendLearning:()=>U1,appendFromGateFailure:()=>u3});import{existsSync as b3,readFileSync as y3}from"fs";import{join as p0}from"path";import{createHash as h3}from"crypto";function c0($){return p0($,v3)}function m3($){if($===null||typeof $!=="object")return!1;let Q=$;return typeof Q.id==="string"&&typeof Q.timestamp==="string"&&typeof Q.iteration==="number"&&typeof Q.trigger==="string"&&typeof Q.rootCause==="string"&&typeof Q.fix==="string"&&typeof Q.preventInFuture==="string"&&typeof Q.evidence==="object"&&Q.evidence!==null}function l0($){if(!b3($))return{version:1,learnings:[]};try{let Q=y3($,"utf-8"),z=JSON.parse(Q);if(z.version===1&&Array.isArray(z.learnings))return{version:1,learnings:z.learnings.filter(m3)}}catch{}return{version:1,learnings:[]}}function g3($,Q){return h3("sha256").update(`${$}\x00${Q}`).digest("hex").slice(0,16)}async function U1($,Q,z={}){let X=g3(Q.trigger,Q.rootCause),Z=new Date().toISOString(),K={id:X,timestamp:Z,...Q},W=c0($);if(await P0(W,()=>{let H=l0(W),V=H.learnings.findIndex((J)=>J.id===X);if(V>=0){let J=H.learnings[V];H.learnings[V]={...J,timestamp:Z,iteration:K.iteration}}else H.learnings.push(K);W1(W,H)}),z.episodeBridge!==null&&(z.episodeBridge!==void 0||process.env.LOKI_AUTO_LEARNINGS_EPISODE==="1")){let H=z.episodeBridge??f0,V=z.bridgeFailureLog??f3;try{let J=await H($,{taskId:`learning-${X}`,outcome:"failure",phase:"VERIFY",goal:`${Q.trigger}: ${Q.rootCause}`});if(J&&!J.stored){if(!new Set(["memory dir not initialized","stub"]).has(J.reason))V(`episode_bridge skipped: ${J.reason}`)}}catch(J){V(`episode_bridge threw: ${J.message}`)}}return K}function f3($){process.stderr.write(`[learnings_writer] ${$}
|
|
404
|
+
`)}async function u3($,Q,z,X={}){let Z=`[${z.severity}] ${z.description}`;return U1($,{iteration:Q,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:z.reviewId,file:z.file??void 0,line:z.line??void 0,severity:z.severity,reviewer:z.reviewer}},X)}function p1($){return l0(c0($))}var v3;var x1=S(()=>{O1();u0();v3=p0("state","relevant-learnings.json")});var n0={};y(n0,{runOverrideCouncil:()=>n3,recordOverrideOutcome:()=>a3,loadCounterEvidence:()=>o3,canonicalFindingId:()=>c1,DEFAULT_OVERRIDE_JUDGES:()=>o0});import{existsSync as p3,readFileSync as c3}from"fs";import{join as l3}from"path";function o3($,Q){let z=l3($,"state",`counter-evidence-${Q}.json`);if(!p3(z))return null;try{let X=c3(z,"utf-8"),Z=JSON.parse(X);if(typeof Z.iteration!=="number")return null;let K=Array.isArray(Z.evidence)?Z.evidence:[],W=[];for(let q of K){if(typeof q!=="object"||q===null)continue;let H=q;if(typeof H.findingId!=="string")continue;if(typeof H.claim!=="string")continue;let V=H.proofType;if(typeof V!=="string"||!d3.has(V))continue;let J=V,B=Array.isArray(H.artifacts)?H.artifacts:[];W.push({findingId:H.findingId,claim:H.claim,proofType:J,artifacts:B.filter((G)=>typeof G==="string")})}return{iteration:Z.iteration,evidence:W}}catch{return null}}async function n3($,Q,z,X={}){let Z=X.judges??o0,K=new Set,W=new Set,q={},H=new Map;for(let V of Q.evidence)H.set(V.findingId,V);for(let V of $){let J=c1(V),B=H.get(J);if(!B){W.add(J);continue}let G=await Promise.all(Z.map((O)=>z({finding:V,evidence:B,judge:O})));if(q[J]=G,G.filter((O)=>O.verdict==="APPROVE_OVERRIDE").length>=2)K.add(J);else W.add(J)}return{approvedFindingIds:K,rejectedFindingIds:W,votes:q}}function c1($){let Q=$.raw.slice(0,80).replace(/\s+/g," ").trim();return`${$.reviewer}::${Q}`}async function a3($,Q,z,X,Z={}){let K={episodeBridge:Z.episodeBridge===void 0?null:Z.episodeBridge};for(let W of X){let q=c1(W);if(z.approvedFindingIds.has(q))await U1($,{iteration:Q,trigger:"override_approved",rootCause:`[${W.severity}] ${W.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:q,reviewId:W.reviewId,file:W.file??void 0,line:W.line??void 0,severity:W.severity,reviewer:W.reviewer}},K);else if(z.rejectedFindingIds.has(q))await U1($,{iteration:Q,trigger:"override_rejected",rootCause:`[${W.severity}] ${W.description}`,fix:"override council rejected -- dev agent must fix the finding",preventInFuture:"address this finding in the next iteration",evidence:{findingId:q,reviewId:W.reviewId,file:W.file??void 0,line:W.line??void 0,severity:W.severity,reviewer:W.reviewer}},K)}}var d3,o0;var a0=S(()=>{x1();d3=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={};y(t0,{writeEscalationHandoff:()=>W5,renderHandoff:()=>r0,readLatestHandoff:()=>U5});import{existsSync as r3,mkdirSync as s3,readdirSync as t3,readFileSync as i3,renameSync as e3,writeFileSync as $5}from"fs";import{dirname as z5,join as P1}from"path";function Q5(){return new Date().toISOString()}function X5($){let Q=$.file?` (${$.file}${$.line!==null?":"+$.line:""})`:"";return` - [${$.severity}] ${$.description}${Q} -- ${$.reviewer}`}function Z5($){let Q=$.evidence,z=Q.file?` ${Q.file}${Q.line!==void 0?":"+Q.line:""}`:"";return` - **${$.trigger}** (iter ${$.iteration})${z}: ${$.rootCause}`}function r0($,Q,z){let X=[];if(X.push(`# Loki escalation handoff -- ${Q5()}`),X.push(""),X.push(`Gate **${$.gateName}** has failed ${$.consecutiveFailures} consecutive times at iteration ${$.iteration}.`),X.push(""),X.push(`Reason: ${$.detail}`),X.push(""),Q.length>0){X.push(`## Outstanding findings (${Q.length})`),X.push("");for(let Z of Q)X.push(X5(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(z.length>0){X.push(`## Recent learnings (${Math.min(z.length,10)})`),X.push("");for(let Z of z.slice(-10))X.push(Z5(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(`
|
|
405
|
+
`)}function K5($,Q){s3(z5($),{recursive:!0});let z=`${$}.tmp.${process.pid}.${++s0}`;$5(z,Q),e3(z,$)}function W5($,Q,z={}){let X=z.findings??f1($,Q.iteration).findings,Z=z.learnings??p1($).learnings,K=r0(Q,X,Z),W=(z.now?.()??new Date).toISOString().replace(/[-:.]/g,""),q=P1($,"escalations"),H=++s0,V=P1(q,`handoff-${W}-${process.pid}-${H}-${Q.gateName}.md`);return K5(V,K),{path:V,bytes:K.length}}function U5($){let Q=P1($,"escalations");if(!r3(Q))return null;let z;try{z=t3(Q).filter((K)=>K.endsWith(".md"))}catch{return null}if(z.length===0)return null;z.sort();let X=z[z.length-1];if(!X)return null;let Z=P1(Q,X);try{return{path:Z,body:i3(Z,"utf-8")}}catch{return null}}var s0=0;var i0=S(()=>{L1();x1()});var e0={};y(e0,{runInternalPhase1Hooks:()=>B5,_resolveForTests:()=>J5,_internalPhase1HooksHelp:()=>T5});import{existsSync as q5,mkdirSync as H5,readdirSync as V5,statSync as G5}from"fs";import{join as q1,resolve as J5}from"path";async function B5($){let[Q,...z]=$;switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(l1),Q===void 0?1:0;case"reflect":return Y5(z);case"override":return M5(z);case"handoff":return A5(z);default:return process.stderr.write(`Unknown subcommand: ${Q}
|
|
406
|
+
`),process.stderr.write(l1),2}}async function Y5($){let Q=d1($[0]);if(Q===null)return process.stderr.write(`reflect: missing or invalid <iter>
|
|
407
|
+
`),2;let z=P();try{let Z=(await Promise.resolve().then(() => (L1(),u1))).loadPreviousFindings(z,Q);if(Z.findings.length===0)return process.stdout.write(`reflect: no findings for iter ${Q} (nothing to do)
|
|
408
|
+
`),0;let K=q1(z,"state");H5(K,{recursive:!0}),W1(q1(K,`findings-${Q}.json`),{review_id:Z.reviewId,iteration:Q,findings:Z.findings});let W=await Promise.resolve().then(() => (x1(),d0)),q=0;if(process.env.LOKI_AUTO_LEARNINGS!=="0"){for(let H of Z.findings)if(H.severity==="Critical"||H.severity==="High")await W.appendFromGateFailure(z,Q,H,{episodeBridge:null}),q+=1}return process.stdout.write(`reflect: persisted ${Z.findings.length} findings + ${q} learnings (iter ${Q})
|
|
407
409
|
`),0}catch(X){return process.stderr.write(`reflect: ${X.message}
|
|
408
|
-
`),1}}async function M5($){let Q=
|
|
410
|
+
`),1}}async function M5($){let Q=d1($[0]);if(Q===null)return process.stderr.write(`override: missing or invalid <iter>
|
|
409
411
|
`),2;let z=P();try{let X=await Promise.resolve().then(() => (a0(),n0)),Z=X.loadCounterEvidence(z,Q);if(Z===null||Z.evidence.length===0)return process.stdout.write(`override: no counter-evidence for iter ${Q} (skip)
|
|
410
|
-
`),0;let
|
|
411
|
-
`),0;let
|
|
412
|
+
`),0;let W=(await Promise.resolve().then(() => (L1(),u1))).loadPreviousFindings(z,Q),q=W.findings.filter((j)=>j.severity==="Critical"||j.severity==="High");if(q.length===0)return process.stdout.write(`override: no blocking findings for iter ${Q} (skip)
|
|
413
|
+
`),0;let H=new Set(["duplicate-code-path","file-exists","test-passes","grep-miss","out-of-scope"]),V=async(j)=>{let w=H.has(j.evidence.proofType);return{judge:j.judge,verdict:w?"APPROVE_OVERRIDE":"REJECT_OVERRIDE",reasoning:w?`[stub] proofType=${j.evidence.proofType} trusted`:`[stub] proofType=${j.evidence.proofType} requires manual review`}},J=await X.runOverrideCouncil(q,Z,V);await X.recordOverrideOutcome(z,Q,J,q);let B=q1(z,"quality","reviews");if(q5(B))try{let j=V5(B).filter((g)=>g.startsWith("review-")).sort(),w=j[j.length-1];if(w&&G5(q1(B,w)).isDirectory())W1(q1(B,w,`override-${Q}.json`),{review_id:W.reviewId,iteration:Q,approved_finding_ids:Array.from(J.approvedFindingIds),rejected_finding_ids:Array.from(J.rejectedFindingIds),votes:J.votes})}catch{}let G=J.approvedFindingIds.size,M=J.rejectedFindingIds.size;if(M===0&&G>0)process.stdout.write(`override: LIFTED -- ${G} approved, ${M} rejected
|
|
412
414
|
`);else process.stdout.write(`override: BLOCKED -- ${G} approved, ${M} rejected
|
|
413
415
|
`);return 0}catch(X){return process.stderr.write(`override: ${X.message}
|
|
414
|
-
`),1}}async function A5($){let Q=$[0],z=Number.parseInt($[1]??"0",10),X=
|
|
415
|
-
`),2;let Z=P();try{let
|
|
416
|
+
`),1}}async function A5($){let Q=$[0],z=Number.parseInt($[1]??"0",10),X=d1($[2]);if(!Q||!Number.isFinite(z)||X===null)return process.stderr.write(`handoff: usage: handoff <gate> <consecutive-failures> <iter>
|
|
417
|
+
`),2;let Z=P();try{let W=(await Promise.resolve().then(() => (i0(),t0))).writeEscalationHandoff(Z,{gateName:Q,iteration:X,consecutiveFailures:z,detail:`${Q} hit PAUSE_LIMIT (${z} consecutive failures)`});return process.stdout.write(`handoff: wrote ${W.path} (${W.bytes}B)
|
|
416
418
|
`),0}catch(K){return process.stderr.write(`handoff: ${K.message}
|
|
417
|
-
`),1}}function
|
|
419
|
+
`),1}}function d1($){if($===void 0)return null;let Q=Number.parseInt($,10);return Number.isFinite(Q)&&Q>=0?Q:null}var l1=`loki internal phase1-hooks <subcommand>
|
|
418
420
|
|
|
419
421
|
Subcommands:
|
|
420
422
|
reflect <iter> Persist structured findings + auto-learnings.
|
|
@@ -423,24 +425,24 @@ Subcommands:
|
|
|
423
425
|
|
|
424
426
|
This command is invoked by autonomy/run.sh between iterations. Users
|
|
425
427
|
should not run it directly -- run \`loki start\` instead.
|
|
426
|
-
`,T5;var $6=
|
|
427
|
-
`),0}p();n();m();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(P(),"state","provider");if(!T6($))return"";try{return A6($,"utf-8").trim()}catch{return""}}function _6($,Q){return $||Q||process.env.LOKI_PROVIDER||"claude"}function I6($){let Q=i1(),z=_6($,Q);switch(process.stdout.write(`${
|
|
428
|
+
`,T5;var $6=S(()=>{m();O1();T5=l1});m();import{readFileSync as q6}from"fs";import{resolve as H6,dirname as V6}from"path";import{fileURLToPath as G6}from"url";var o=null;function r1(){if(o!==null)return o;let $="7.5.14";if(typeof $==="string"&&$.length>0)return o=$,o;try{let Q=V6(G6(import.meta.url)),z=E1(Q);o=q6(H6(z,"VERSION"),"utf-8").trim()}catch{o="unknown"}return o}function s1(){return process.stdout.write(`Loki Mode v${r1()}
|
|
429
|
+
`),0}p();n();m();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(P(),"state","provider");if(!T6($))return"";try{return A6($,"utf-8").trim()}catch{return""}}function _6($,Q){return $||Q||process.env.LOKI_PROVIDER||"claude"}function I6($){let Q=i1(),z=_6($,Q);switch(process.stdout.write(`${C}Current Provider${U}
|
|
428
430
|
`),process.stdout.write(`
|
|
429
|
-
`),process.stdout.write(`${A}Provider:${
|
|
430
|
-
`),z){case"claude":process.stdout.write(`${k}Status:${
|
|
431
|
-
`);break;case"cline":process.stdout.write(`${k}Status:${
|
|
432
|
-
`);break;case"codex":case"gemini":case"aider":process.stdout.write(`${R}Status:${
|
|
433
|
-
`);break;default:break}if(Q)process.stdout.write(`${
|
|
434
|
-
`);else process.stdout.write(`${
|
|
431
|
+
`),process.stdout.write(`${A}Provider:${U} ${z}
|
|
432
|
+
`),z){case"claude":process.stdout.write(`${k}Status:${U} Full features (subagents, parallel, MCP)
|
|
433
|
+
`);break;case"cline":process.stdout.write(`${k}Status:${U} Near-full mode (subagents, MCP, 12+ providers)
|
|
434
|
+
`);break;case"codex":case"gemini":case"aider":process.stdout.write(`${R}Status:${U} Degraded mode (sequential only)
|
|
435
|
+
`);break;default:break}if(Q)process.stdout.write(`${x}(saved in .loki/state/provider)${U}
|
|
436
|
+
`);else process.stdout.write(`${x}(default - not explicitly set)${U}
|
|
435
437
|
`);return process.stdout.write(`
|
|
436
|
-
`),process.stdout.write(`Switch provider: ${A}loki provider set <name>${
|
|
437
|
-
`),process.stdout.write(`Available: ${A}loki provider list${
|
|
438
|
-
`),0}async function
|
|
438
|
+
`),process.stdout.write(`Switch provider: ${A}loki provider set <name>${U}
|
|
439
|
+
`),process.stdout.write(`Available: ${A}loki provider list${U}
|
|
440
|
+
`),0}async function L6(){let Q=i1()||process.env.LOKI_PROVIDER||"claude";process.stdout.write(`${C}Available Providers${U}
|
|
439
441
|
`),process.stdout.write(`
|
|
440
|
-
`);let z=await Promise.all(j6.map(async(K)=>[K,await
|
|
442
|
+
`);let z=await Promise.all(j6.map(async(K)=>[K,await b(K)!==null])),X=new Map;for(let[K,W]of z)X.set(K,W?`${k}installed${U}`:`${L}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,W]of Z){let q=Q===K?` ${A}(current)${U}`:"";process.stdout.write(` ${W} ${X.get(K)}${q}
|
|
441
443
|
`)}return process.stdout.write(`
|
|
442
|
-
`),process.stdout.write(`Set provider: ${A}loki provider set <name>${
|
|
443
|
-
`),0}function
|
|
444
|
+
`),process.stdout.write(`Set provider: ${A}loki provider set <name>${U}
|
|
445
|
+
`),0}function x6(){return process.stdout.write(`${C}Loki Mode Provider Management${U}
|
|
444
446
|
`),process.stdout.write(`
|
|
445
447
|
`),process.stdout.write(`Usage: loki provider <command>
|
|
446
448
|
`),process.stdout.write(`
|
|
@@ -458,14 +460,14 @@ should not run it directly -- run \`loki start\` instead.
|
|
|
458
460
|
`),process.stdout.write(` loki provider list
|
|
459
461
|
`),process.stdout.write(` loki provider info gemini
|
|
460
462
|
`),process.stdout.write(` loki provider models
|
|
461
|
-
`),0}async function e1($){let Q=$[0]??"show",z=$.slice(1);switch(Q){case"show":case"current":return I6(z[0]);case"list":return
|
|
462
|
-
`))if(X.includes('"description"'))z++;return z}catch{return 0}}async function w6(){await
|
|
463
|
+
`),0}async function e1($){let Q=$[0]??"show",z=$.slice(1);switch(Q){case"show":case"current":return I6(z[0]);case"list":return L6();case"set":case"info":case"models":return P6(["provider",Q,...z]);default:return x6()}}async function P6($){let{run:Q}=await Promise.resolve().then(() => (p(),t1)),{resolve:z}=await import("path"),{REPO_ROOT:X}=await Promise.resolve().then(() => (m(),a1)),Z=z(X,"autonomy","loki"),K=await Q([Z,...$],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(K.stdout),process.stderr.write(K.stderr),K.exitCode}n();m();X1();p();import{existsSync as $0,readFileSync as F6}from"fs";import{resolve as t}from"path";import{mkdir as E6}from"fs/promises";var Z1=t(w1(),"learnings");function N1($){if(!$0($))return 0;try{let Q=F6($,"utf-8"),z=0;for(let X of Q.split(`
|
|
464
|
+
`))if(X.includes('"description"'))z++;return z}catch{return 0}}async function w6(){await E6(Z1,{recursive:!0});let $=N1(t(Z1,"patterns.jsonl")),Q=N1(t(Z1,"mistakes.jsonl")),z=N1(t(Z1,"successes.jsonl"));return process.stdout.write(`${C}Cross-Project Learnings${U}
|
|
463
465
|
`),process.stdout.write(`
|
|
464
|
-
`),process.stdout.write(` Patterns: ${k}${$}${
|
|
465
|
-
`),process.stdout.write(` Mistakes: ${R}${Q}${
|
|
466
|
-
`),process.stdout.write(` Successes: ${A}${z}${
|
|
466
|
+
`),process.stdout.write(` Patterns: ${k}${$}${U}
|
|
467
|
+
`),process.stdout.write(` Mistakes: ${R}${Q}${U}
|
|
468
|
+
`),process.stdout.write(` Successes: ${A}${z}${U}
|
|
467
469
|
`),process.stdout.write(`
|
|
468
|
-
`),process.stdout.write(`Location: ${
|
|
470
|
+
`),process.stdout.write(`Location: ${Z1}
|
|
469
471
|
`),process.stdout.write(`
|
|
470
472
|
`),process.stdout.write(`Use 'loki memory show <type>' to view entries
|
|
471
473
|
`),0}async function S6($){if($){let X=`
|
|
@@ -480,7 +482,7 @@ except Exception as e:
|
|
|
480
482
|
print(f'Error: {e}')
|
|
481
483
|
`.trim(),Z=await a(X,{cwd:u});return process.stdout.write(Z.stdout),0}let Q=t(P(),"memory","index.json");if(!$0(Q))return process.stdout.write(`No index found
|
|
482
484
|
`),0;let z=await a(`import json, sys; sys.stdout.write(json.dumps(json.load(open(${JSON.stringify(Q)})), indent=4) + "\\n")`);if(z.exitCode!==0)return process.stdout.write(`No index found
|
|
483
|
-
`),0;return process.stdout.write(z.stdout),0}async function z0($){switch($[0]??"list"){case"list":case"ls":return w6();case"index":return S6($[1]==="rebuild");default:{let z=t(u,"autonomy","loki"),X=await
|
|
485
|
+
`),0;return process.stdout.write(z.stdout),0}async function z0($){switch($[0]??"list"){case"list":case"ls":return w6();case"index":return S6($[1]==="rebuild");default:{let z=t(u,"autonomy","loki"),X=await E([z,"memory",...$],{env:{LOKI_LEGACY_BASH:"1"},timeoutMs:3600000});return process.stdout.write(X.stdout),process.stderr.write(X.stderr),X.exitCode}}}var z6=`Loki Mode (TypeScript port, Phase 2 of bash->Bun migration)
|
|
484
486
|
|
|
485
487
|
Usage: loki <command> [args...]
|
|
486
488
|
|
|
@@ -499,11 +501,11 @@ Phase 2 ported (Bun-native, fast):
|
|
|
499
501
|
All other commands fall through to the bash CLI (autonomy/loki).
|
|
500
502
|
Set LOKI_LEGACY_BASH=1 to force the bash CLI for every command.
|
|
501
503
|
`;function O5(){let $=process.env.LOKI_LEGACY_BASH;if($===void 0)return;let Q=$.trim().toLowerCase();if(Q!=="1"&&Q!=="true"&&Q!=="yes"&&Q!=="on")return;if(process.env.LOKI_SUPPRESS_BUN_DIRECT_WARN==="1")return;process.stderr.write(`warning: LOKI_LEGACY_BASH is set, but you are running the Bun runtime directly (src/cli.ts). The env var only takes effect via the bin/loki shim, which dispatches between Bun and bash. Behavior is unchanged; this message is informational.
|
|
502
|
-
`)}async function j5($){O5();let Q=$[0],z=$.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(z6),0;case"version":case"--version":case"-v":return s1();case"provider":return e1(z);case"memory":return z0(z);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (
|
|
504
|
+
`)}async function j5($){O5();let Q=$[0],z=$.slice(1);switch(Q){case void 0:case"help":case"--help":case"-h":return process.stdout.write(z6),0;case"version":case"--version":case"-v":return s1();case"provider":return e1(z);case"memory":return z0(z);case"status":{let{runStatus:X}=await Promise.resolve().then(() => (H0(),q0));return X(z)}case"stats":{let{runStats:X}=await Promise.resolve().then(() => (Y0(),B0));return X(z)}case"doctor":{let{runDoctor:X}=await Promise.resolve().then(() => (x0(),L0));return X(z)}case"rollback":{let{runRollback:X}=await Promise.resolve().then(() => (b0(),k0));return X(z)}case"internal":{let X=z[0];if(!X||X==="--help"||X==="-h"||X==="help"){let K=["loki internal -- runtime hooks driven by autonomy/run.sh","","Subcommands:"," phase1-hooks Persist structured findings, run override council,"," append learnings, and write the escalation handoff"," doc once per iteration. Driven by run.sh; not"," intended for direct invocation.","","Phase 1 (RARV-C closure) env vars:"," LOKI_INJECT_FINDINGS=1 Persist structured reviewer findings to"," .loki/state/findings-<iter>.json so the"," next iteration can address them."," LOKI_OVERRIDE_COUNCIL=1 Allow a 3-LLM override panel to lift a"," BLOCK when counter-evidence is presented."," See LOKI_OVERRIDE_JUDGES (csv),"," LOKI_OVERRIDE_PANEL_SIZE,"," LOKI_OVERRIDE_REAL_JUDGE."," LOKI_AUTO_LEARNINGS=1 Append failure rootcauses to"," .loki/state/relevant-learnings.json via"," the episodic memory bridge."," LOKI_HANDOFF_MD=1 Write a structured human handoff doc to"," .loki/escalations/<ts>.md before PAUSE.","","All four are default-on as of v7.5.3. Set to 0 to disable.","Reference: CHANGELOG.md (search 'Phase 1') and skills/healing.md.","","These commands are wired into the autonomous loop and may change","without notice. Do not script against them.",""].join(`
|
|
503
505
|
`);return process.stdout.write(`${K}
|
|
504
506
|
`),0}if(X==="phase1-hooks"){let{runInternalPhase1Hooks:K}=await Promise.resolve().then(() => ($6(),e0));return K(z.slice(1))}return process.stderr.write(`Unknown internal subcommand: ${X}
|
|
505
507
|
`),process.stderr.write(`Run 'loki internal --help' for the supported list.
|
|
506
508
|
`),2}default:return process.stderr.write(`Unknown command: ${Q}
|
|
507
509
|
`),process.stderr.write(z6),2}}process.on("SIGINT",()=>process.exit(130));process.on("SIGTERM",()=>process.exit(143));var _5=await j5(Bun.argv.slice(2));process.exit(_5);
|
|
508
510
|
|
|
509
|
-
//# debugId=
|
|
511
|
+
//# debugId=78BC492C990A1E0764756E2164756E21
|
package/mcp/__init__.py
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loki-mode",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.14",
|
|
4
4
|
"description": "Loki Mode by Autonomi. Multi-agent autonomous SDLC framework. Spec to deployed app: PRD, GitHub issue, OpenAPI/JSON/YAML, or one-line brief. 5 AI providers (Claude Code, OpenAI Codex, Google Gemini, Cline, Aider). 11 quality gates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|