loki-mode 6.81.1 → 6.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/autonomy/run.sh +249 -44
- package/dashboard/__init__.py +1 -1
- package/docs/INSTALLATION.md +1 -1
- package/mcp/__init__.py +1 -1
- package/mcp/server.py +105 -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 v6.
|
|
6
|
+
# Loki Mode v6.82.0
|
|
7
7
|
|
|
8
8
|
**You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
|
|
9
9
|
|
|
@@ -269,4 +269,4 @@ The following features are documented in skill modules but not yet fully automat
|
|
|
269
269
|
| Quality gates 3-reviewer system | Implemented (v5.35.0) | 5 specialist reviewers in `skills/quality-gates.md`; execution in run.sh |
|
|
270
270
|
| Benchmarks (HumanEval, SWE-bench) | Infrastructure only | Runner scripts and datasets exist in `benchmarks/`; no published results |
|
|
271
271
|
|
|
272
|
-
**v6.
|
|
272
|
+
**v6.82.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
6.
|
|
1
|
+
6.82.0
|
package/autonomy/run.sh
CHANGED
|
@@ -3763,9 +3763,12 @@ track_iteration_complete() {
|
|
|
3763
3763
|
[ -z "$phase" ] && phase=$(python3 -c "import json; print(json.load(open('.loki/state/orchestrator.json')).get('currentPhase', 'unknown'))" 2>/dev/null || echo "unknown")
|
|
3764
3764
|
|
|
3765
3765
|
# Read token data from context tracker output (v5.42.0)
|
|
3766
|
+
# v6.82.0: also capture cache_read_tokens / cache_creation_tokens for
|
|
3767
|
+
# prompt-cache hit-rate analysis (S1.1 prompt restructure).
|
|
3766
3768
|
local iter_input=0 iter_output=0 iter_cost=0
|
|
3769
|
+
local iter_cache_read=0 iter_cache_creation=0
|
|
3767
3770
|
if [ -f ".loki/context/tracking.json" ]; then
|
|
3768
|
-
read iter_input iter_output iter_cost < <(python3 -c "
|
|
3771
|
+
read iter_input iter_output iter_cost iter_cache_read iter_cache_creation < <(python3 -c "
|
|
3769
3772
|
import json
|
|
3770
3773
|
try:
|
|
3771
3774
|
t = json.load(open('.loki/context/tracking.json'))
|
|
@@ -3773,11 +3776,17 @@ try:
|
|
|
3773
3776
|
match = [i for i in iters if i.get('iteration') == $iteration]
|
|
3774
3777
|
if match:
|
|
3775
3778
|
m = match[-1]
|
|
3776
|
-
print(
|
|
3779
|
+
print(
|
|
3780
|
+
m.get('input_tokens', 0),
|
|
3781
|
+
m.get('output_tokens', 0),
|
|
3782
|
+
m.get('cost_usd', 0),
|
|
3783
|
+
m.get('cache_read_tokens', 0),
|
|
3784
|
+
m.get('cache_creation_tokens', 0),
|
|
3785
|
+
)
|
|
3777
3786
|
else:
|
|
3778
|
-
print(0, 0, 0)
|
|
3779
|
-
except: print(0, 0, 0)
|
|
3780
|
-
" 2>/dev/null || echo "0 0 0")
|
|
3787
|
+
print(0, 0, 0, 0, 0)
|
|
3788
|
+
except: print(0, 0, 0, 0, 0)
|
|
3789
|
+
" 2>/dev/null || echo "0 0 0 0 0")
|
|
3781
3790
|
fi
|
|
3782
3791
|
|
|
3783
3792
|
cat > ".loki/metrics/efficiency/iteration-${iteration}.json" << EFF_EOF
|
|
@@ -3790,6 +3799,8 @@ except: print(0, 0, 0)
|
|
|
3790
3799
|
"status": "$status_str",
|
|
3791
3800
|
"input_tokens": ${iter_input:-0},
|
|
3792
3801
|
"output_tokens": ${iter_output:-0},
|
|
3802
|
+
"cache_read_tokens": ${iter_cache_read:-0},
|
|
3803
|
+
"cache_creation_tokens": ${iter_cache_creation:-0},
|
|
3793
3804
|
"cost_usd": ${iter_cost:-0},
|
|
3794
3805
|
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
3795
3806
|
}
|
|
@@ -7596,18 +7607,87 @@ except Exception:
|
|
|
7596
7607
|
return 0
|
|
7597
7608
|
}
|
|
7598
7609
|
|
|
7599
|
-
# Check if
|
|
7610
|
+
# Check if the loki_complete_task MCP tool was invoked in this iteration.
|
|
7611
|
+
# The tool writes a payload to .loki/signals/TASK_COMPLETION_CLAIMED with the
|
|
7612
|
+
# structured completion claim. When the signal exists, we read it, log the
|
|
7613
|
+
# structured event, and consume (remove) the file. Returns 0 on detection.
|
|
7614
|
+
#
|
|
7615
|
+
# Output on stdout: the JSON payload (for callers that want to log it).
|
|
7616
|
+
check_task_completion_signal() {
|
|
7617
|
+
local signal_file=".loki/signals/TASK_COMPLETION_CLAIMED"
|
|
7618
|
+
if [ ! -f "$signal_file" ]; then
|
|
7619
|
+
return 1
|
|
7620
|
+
fi
|
|
7621
|
+
|
|
7622
|
+
local payload
|
|
7623
|
+
payload=$(cat "$signal_file" 2>/dev/null || echo "")
|
|
7624
|
+
if [ -z "$payload" ]; then
|
|
7625
|
+
# Empty signal -- treat as noise and clean up
|
|
7626
|
+
rm -f "$signal_file" 2>/dev/null
|
|
7627
|
+
return 1
|
|
7628
|
+
fi
|
|
7629
|
+
|
|
7630
|
+
# Emit a structured event for observability (best-effort).
|
|
7631
|
+
local statement evidence confidence
|
|
7632
|
+
statement=$(python3 -c "
|
|
7633
|
+
import json, sys
|
|
7634
|
+
try:
|
|
7635
|
+
d = json.loads(sys.stdin.read())
|
|
7636
|
+
print(d.get('statement',''))
|
|
7637
|
+
except Exception:
|
|
7638
|
+
pass
|
|
7639
|
+
" <<< "$payload" 2>/dev/null || echo "")
|
|
7640
|
+
evidence=$(python3 -c "
|
|
7641
|
+
import json, sys
|
|
7642
|
+
try:
|
|
7643
|
+
d = json.loads(sys.stdin.read())
|
|
7644
|
+
print(d.get('evidence',''))
|
|
7645
|
+
except Exception:
|
|
7646
|
+
pass
|
|
7647
|
+
" <<< "$payload" 2>/dev/null || echo "")
|
|
7648
|
+
confidence=$(python3 -c "
|
|
7649
|
+
import json, sys
|
|
7650
|
+
try:
|
|
7651
|
+
d = json.loads(sys.stdin.read())
|
|
7652
|
+
print(d.get('confidence','medium'))
|
|
7653
|
+
except Exception:
|
|
7654
|
+
print('medium')
|
|
7655
|
+
" <<< "$payload" 2>/dev/null || echo "medium")
|
|
7656
|
+
|
|
7657
|
+
emit_event_json "task_completion_claim" \
|
|
7658
|
+
"statement=${statement:0:500}" \
|
|
7659
|
+
"confidence=${confidence}" \
|
|
7660
|
+
"evidence_length=${#evidence}"
|
|
7661
|
+
|
|
7662
|
+
# Return the payload on stdout
|
|
7663
|
+
printf '%s\n' "$payload"
|
|
7664
|
+
|
|
7665
|
+
# Consume the signal (next iteration would otherwise re-trigger)
|
|
7666
|
+
rm -f "$signal_file" 2>/dev/null
|
|
7667
|
+
return 0
|
|
7668
|
+
}
|
|
7669
|
+
|
|
7670
|
+
# Check if completion promise is fulfilled in log output.
|
|
7671
|
+
#
|
|
7672
|
+
# As of v6.82.0, the default path is the MCP tool `loki_complete_task`
|
|
7673
|
+
# (detected via check_task_completion_signal above). The legacy grep-based
|
|
7674
|
+
# detection is retained behind LOKI_LEGACY_COMPLETION_MATCH=true for rollback.
|
|
7600
7675
|
check_completion_promise() {
|
|
7601
7676
|
local log_file="$1"
|
|
7602
7677
|
|
|
7603
|
-
#
|
|
7604
|
-
if
|
|
7678
|
+
# New default: structured signal from the loki_complete_task MCP tool.
|
|
7679
|
+
if check_task_completion_signal >/dev/null 2>&1; then
|
|
7605
7680
|
return 0
|
|
7606
7681
|
fi
|
|
7607
7682
|
|
|
7608
|
-
#
|
|
7609
|
-
if [
|
|
7610
|
-
|
|
7683
|
+
# Legacy grep fallback (opt-in via env flag for rollback).
|
|
7684
|
+
if [ "${LOKI_LEGACY_COMPLETION_MATCH:-false}" = "true" ]; then
|
|
7685
|
+
if grep -q "COMPLETION PROMISE FULFILLED" "$log_file" 2>/dev/null; then
|
|
7686
|
+
return 0
|
|
7687
|
+
fi
|
|
7688
|
+
if [ -n "$COMPLETION_PROMISE" ] && grep -qF "$COMPLETION_PROMISE" "$log_file" 2>/dev/null; then
|
|
7689
|
+
return 0
|
|
7690
|
+
fi
|
|
7611
7691
|
fi
|
|
7612
7692
|
|
|
7613
7693
|
return 1
|
|
@@ -8360,12 +8440,16 @@ build_prompt() {
|
|
|
8360
8440
|
# Ralph Wiggum Mode - Reason-Act-Reflect-VERIFY cycle with self-verification loop (Boris Cherny pattern)
|
|
8361
8441
|
local rarv_instruction="RALPH WIGGUM MODE ACTIVE. Use Reason-Act-Reflect-VERIFY cycle: 1) REASON - READ .loki/CONTINUITY.md including 'Mistakes & Learnings' section to avoid past errors. CHECK .loki/state/relevant-learnings.json for cross-project learnings from previous projects (mistakes to avoid, patterns to apply). Check .loki/state/ and .loki/queue/, identify next task. CHECK .loki/state/resources.json for system resource warnings - if CPU or memory is high, reduce parallel agent spawning or pause non-critical tasks. Limit to MAX_PARALLEL_AGENTS=${MAX_PARALLEL_AGENTS}. If queue empty, find new improvements. 2) ACT - Execute task, write code, commit changes atomically (git checkpoint). 3) REFLECT - Update .loki/CONTINUITY.md with progress, update state, identify NEXT improvement. Save valuable learnings for future projects. 4) VERIFY - Run automated tests (unit, integration, E2E), check compilation/build, verify against spec. IF VERIFICATION FAILS: a) Capture error details (stack trace, logs), b) Analyze root cause, c) UPDATE 'Mistakes & Learnings' in CONTINUITY.md with what failed, why, and how to prevent, d) Rollback to last good git checkpoint if needed, e) Apply learning and RETRY from REASON. If verification passes, mark task complete and continue. This self-verification loop achieves 2-3x quality improvement. CRITICAL: There is NEVER a 'finished' state - always find the next improvement, optimization, test, or feature."
|
|
8362
8442
|
|
|
8363
|
-
# Completion
|
|
8443
|
+
# Completion instruction (S0.2 -- structured tool call).
|
|
8444
|
+
# When PRD requirements are implemented, tests pass, and the checklist is
|
|
8445
|
+
# at or near 100%, the agent MUST invoke the `loki_complete_task` MCP tool
|
|
8446
|
+
# (defined in mcp/server.py) with completion_statement + evidence fields,
|
|
8447
|
+
# instead of emitting a prose completion string.
|
|
8364
8448
|
local completion_instruction=""
|
|
8365
8449
|
if [ -n "$COMPLETION_PROMISE" ]; then
|
|
8366
|
-
completion_instruction="COMPLETION_PROMISE: [$COMPLETION_PROMISE].
|
|
8450
|
+
completion_instruction="COMPLETION_PROMISE: [$COMPLETION_PROMISE]. When all PRD requirements are implemented, tests pass, and the PRD checklist is at or near 100%, invoke the loki_complete_task MCP tool with your completion_statement and evidence (cite tests that passed, checklist items verified, files created/modified). Do NOT emit a completion string in prose -- use the tool call."
|
|
8367
8451
|
else
|
|
8368
|
-
completion_instruction="NO COMPLETION PROMISE SET. Continue finding improvements. The Completion Council will evaluate your progress periodically. Iteration $iteration of max $MAX_ITERATIONS."
|
|
8452
|
+
completion_instruction="NO COMPLETION PROMISE SET. Continue finding improvements. The Completion Council will evaluate your progress periodically. Iteration $iteration of max $MAX_ITERATIONS. If you do decide the task is complete, invoke the loki_complete_task MCP tool with a structured statement and evidence rather than emitting prose."
|
|
8369
8453
|
fi
|
|
8370
8454
|
|
|
8371
8455
|
# Core autonomous instructions - NO questions, NO waiting, NEVER say done
|
|
@@ -8373,7 +8457,7 @@ build_prompt() {
|
|
|
8373
8457
|
if [ "$AUTONOMY_MODE" = "perpetual" ] || [ "$PERPETUAL_MODE" = "true" ]; then
|
|
8374
8458
|
autonomous_suffix="CRITICAL AUTONOMY RULES: 1) NEVER ask questions - just decide. 2) NEVER wait for confirmation - just act. 3) NEVER say 'done' or 'complete' - there's always more to improve. 4) NEVER stop voluntarily - if out of tasks, create new ones (add tests, optimize, refactor, add features). 5) Work continues PERPETUALLY. Even if PRD is implemented, find bugs, add tests, improve UX, optimize performance."
|
|
8375
8459
|
else
|
|
8376
|
-
autonomous_suffix="CRITICAL AUTONOMY RULES: 1) NEVER ask questions - just decide. 2) NEVER wait for confirmation - just act. 3) When all PRD requirements are implemented and tests pass,
|
|
8460
|
+
autonomous_suffix="CRITICAL AUTONOMY RULES: 1) NEVER ask questions - just decide. 2) NEVER wait for confirmation - just act. 3) When all PRD requirements are implemented and tests pass, invoke the loki_complete_task MCP tool (completion_statement='$COMPLETION_PROMISE' plus evidence + confidence). Do not emit completion prose. 4) If out of tasks but PRD is not fully implemented, continue working on remaining requirements. 5) Focus on completing PRD scope, not endless improvements."
|
|
8377
8461
|
fi
|
|
8378
8462
|
|
|
8379
8463
|
# Skill files are always copied to .loki/skills/ for all providers
|
|
@@ -8655,42 +8739,154 @@ except Exception:
|
|
|
8655
8739
|
fi
|
|
8656
8740
|
fi
|
|
8657
8741
|
|
|
8658
|
-
#
|
|
8659
|
-
#
|
|
8742
|
+
# S1.1 -- Static-first prompt assembly with cache-breakpoint marker.
|
|
8743
|
+
#
|
|
8744
|
+
# The prior shape (v<=6.81.x) concatenated ~13 dynamic blobs BEFORE the
|
|
8745
|
+
# 4-5 static instruction blobs, which destroyed Claude's prefix cache on
|
|
8746
|
+
# every iteration. The new layout places the stable instruction set first
|
|
8747
|
+
# (prd_anchor + RARV/SDLC/autonomy/memory instructions), emits a literal
|
|
8748
|
+
# [CACHE_BREAKPOINT] marker, then appends the volatile per-iteration
|
|
8749
|
+
# context inside a <dynamic_context> tag.
|
|
8750
|
+
#
|
|
8751
|
+
# The [CACHE_BREAKPOINT] marker is a documentation anchor today. When the
|
|
8752
|
+
# Claude CLI migration exposes cache_control, the orchestrator can split
|
|
8753
|
+
# the prompt at this marker and set cache_control on the prefix half.
|
|
8754
|
+
#
|
|
8755
|
+
# Rollback: set LOKI_LEGACY_PROMPT_ORDERING=true to restore the previous
|
|
8756
|
+
# dynamic-first concatenation order.
|
|
8757
|
+
|
|
8758
|
+
if [ "${LOKI_LEGACY_PROMPT_ORDERING:-false}" = "true" ]; then
|
|
8759
|
+
# Legacy dynamic-first ordering (pre-v6.82.0). Retained for rollback.
|
|
8760
|
+
if [ "${PROVIDER_DEGRADED:-false}" = "true" ]; then
|
|
8761
|
+
local _legacy_prd_content=""
|
|
8762
|
+
if [ -n "$prd" ] && [ -f "$prd" ]; then
|
|
8763
|
+
_legacy_prd_content=$(head -c 4000 "$prd")
|
|
8764
|
+
fi
|
|
8765
|
+
if [ $retry -eq 0 ]; then
|
|
8766
|
+
if [ -n "$prd" ]; then
|
|
8767
|
+
echo "You are a coding assistant. Read and implement the requirements from the PRD below. Write working code, run tests if possible, and commit changes. ${human_directive:+Priority: $human_directive} ${queue_tasks:+Tasks: $queue_tasks} PRD contents: $_legacy_prd_content"
|
|
8768
|
+
else
|
|
8769
|
+
echo "You are a coding assistant. Analyze this codebase and suggest improvements. Write working code and commit changes. ${human_directive:+Priority: $human_directive} ${queue_tasks:+Tasks: $queue_tasks}"
|
|
8770
|
+
fi
|
|
8771
|
+
else
|
|
8772
|
+
if [ -n "$prd" ]; then
|
|
8773
|
+
echo "You are a coding assistant. Continue working on iteration $iteration. Review what exists, implement remaining PRD requirements, fix any issues, add tests. ${human_directive:+Priority: $human_directive} ${queue_tasks:+Tasks: $queue_tasks} PRD contents: $_legacy_prd_content"
|
|
8774
|
+
else
|
|
8775
|
+
echo "You are a coding assistant. Continue working on iteration $iteration. Review what exists, improve code, fix bugs, add tests. ${human_directive:+Priority: $human_directive} ${queue_tasks:+Tasks: $queue_tasks}"
|
|
8776
|
+
fi
|
|
8777
|
+
fi
|
|
8778
|
+
else
|
|
8779
|
+
if [ $retry -eq 0 ]; then
|
|
8780
|
+
if [ -n "$prd" ]; then
|
|
8781
|
+
echo "Loki Mode with PRD at $prd. $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8782
|
+
else
|
|
8783
|
+
echo "Loki Mode. $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section $analysis_instruction $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8784
|
+
fi
|
|
8785
|
+
else
|
|
8786
|
+
if [ -n "$prd" ]; then
|
|
8787
|
+
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). PRD: $prd. $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8788
|
+
else
|
|
8789
|
+
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section Use .loki/generated-prd.md if exists. $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8790
|
+
fi
|
|
8791
|
+
fi
|
|
8792
|
+
fi
|
|
8793
|
+
return 0
|
|
8794
|
+
fi
|
|
8795
|
+
|
|
8796
|
+
# --- New static-first layout (v6.82.0+) ---
|
|
8797
|
+
#
|
|
8798
|
+
# assemble_prompt_static outputs the cache-stable prefix:
|
|
8799
|
+
# <loki_system>
|
|
8800
|
+
# {prd_anchor}
|
|
8801
|
+
# {rarv_instruction + sdlc_instruction + autonomous_suffix + memory_instruction}
|
|
8802
|
+
# </loki_system>
|
|
8803
|
+
# [CACHE_BREAKPOINT]
|
|
8804
|
+
#
|
|
8805
|
+
# assemble_prompt_dynamic outputs the volatile tail wrapped in
|
|
8806
|
+
# <dynamic_context iteration=".." retry=".."> ... </dynamic_context>.
|
|
8807
|
+
#
|
|
8808
|
+
# Keeping these as inline local helpers (nested functions via eval are
|
|
8809
|
+
# awkward in bash) -- we emit them as two contiguous printf blocks so the
|
|
8810
|
+
# logic is self-documenting and byte-reproducible.
|
|
8811
|
+
|
|
8660
8812
|
if [ "${PROVIDER_DEGRADED:-false}" = "true" ]; then
|
|
8813
|
+
# Degraded providers: simpler wording, but still static-first.
|
|
8661
8814
|
local prd_content=""
|
|
8662
8815
|
if [ -n "$prd" ] && [ -f "$prd" ]; then
|
|
8663
8816
|
prd_content=$(head -c 4000 "$prd")
|
|
8664
8817
|
fi
|
|
8665
8818
|
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8819
|
+
local degraded_prd_anchor="Loki Mode"
|
|
8820
|
+
[ -n "$prd" ] && degraded_prd_anchor="Loki Mode with PRD"
|
|
8821
|
+
|
|
8822
|
+
# STATIC PREFIX (cache-stable across iterations)
|
|
8823
|
+
printf '<loki_system>\n'
|
|
8824
|
+
printf '%s\n' "$degraded_prd_anchor"
|
|
8825
|
+
if [ -n "$prd" ]; then
|
|
8826
|
+
printf 'You are a coding assistant. Read and implement the requirements from the PRD. Write working code, run tests if possible, and commit changes.\n'
|
|
8672
8827
|
else
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8828
|
+
printf 'You are a coding assistant. Analyze this codebase and suggest improvements. Write working code and commit changes.\n'
|
|
8829
|
+
fi
|
|
8830
|
+
printf '</loki_system>\n'
|
|
8831
|
+
printf '[CACHE_BREAKPOINT]\n'
|
|
8832
|
+
|
|
8833
|
+
# DYNAMIC TAIL (changes every iteration)
|
|
8834
|
+
printf '<dynamic_context iteration="%s" retry="%s">\n' "$iteration" "$retry"
|
|
8835
|
+
[ -n "$human_directive" ] && printf 'Priority: %s\n' "$human_directive"
|
|
8836
|
+
[ -n "$queue_tasks" ] && printf 'Tasks: %s\n' "$queue_tasks"
|
|
8837
|
+
if [ -n "$prd" ]; then
|
|
8838
|
+
printf 'PRD contents: %s\n' "$prd_content"
|
|
8678
8839
|
fi
|
|
8840
|
+
printf '</dynamic_context>\n'
|
|
8841
|
+
return 0
|
|
8842
|
+
fi
|
|
8843
|
+
|
|
8844
|
+
# Full-featured providers (Claude, etc.)
|
|
8845
|
+
local prd_anchor
|
|
8846
|
+
if [ -n "$prd" ]; then
|
|
8847
|
+
prd_anchor="Loki Mode with PRD at $prd"
|
|
8679
8848
|
else
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8849
|
+
prd_anchor="Loki Mode"
|
|
8850
|
+
fi
|
|
8851
|
+
|
|
8852
|
+
# STATIC PREFIX (cache-stable across iterations).
|
|
8853
|
+
# Order is deterministic so the prefix is byte-identical for iter N and N+1.
|
|
8854
|
+
printf '<loki_system>\n'
|
|
8855
|
+
printf '%s\n' "$prd_anchor"
|
|
8856
|
+
printf '%s\n' "$rarv_instruction"
|
|
8857
|
+
printf '%s\n' "$sdlc_instruction"
|
|
8858
|
+
printf '%s\n' "$autonomous_suffix"
|
|
8859
|
+
printf '%s\n' "$memory_instruction"
|
|
8860
|
+
# For codebase-analysis mode (no PRD), analysis_instruction is part of the
|
|
8861
|
+
# static prefix so it remains cache-stable.
|
|
8862
|
+
if [ -z "$prd" ]; then
|
|
8863
|
+
printf '%s\n' "$analysis_instruction"
|
|
8864
|
+
fi
|
|
8865
|
+
printf '</loki_system>\n'
|
|
8866
|
+
printf '[CACHE_BREAKPOINT]\n'
|
|
8867
|
+
|
|
8868
|
+
# DYNAMIC TAIL -- all per-iteration context goes here.
|
|
8869
|
+
printf '<dynamic_context iteration="%s" retry="%s">\n' "$iteration" "$retry"
|
|
8870
|
+
if [ $retry -gt 0 ]; then
|
|
8871
|
+
if [ -n "$prd" ]; then
|
|
8872
|
+
printf 'Resume iteration #%s (retry #%s). PRD: %s\n' "$iteration" "$retry" "$prd"
|
|
8686
8873
|
else
|
|
8687
|
-
|
|
8688
|
-
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). PRD: $prd. $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8689
|
-
else
|
|
8690
|
-
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). $human_directive $gate_failure_context $queue_tasks $bmad_context $openspec_context $mirofish_context $magic_context $checklist_status $app_runner_info $playwright_info $memory_context_section Use .loki/generated-prd.md if exists. $rarv_instruction $memory_instruction $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
8691
|
-
fi
|
|
8874
|
+
printf 'Resume iteration #%s (retry #%s). Use .loki/generated-prd.md if exists.\n' "$iteration" "$retry"
|
|
8692
8875
|
fi
|
|
8693
8876
|
fi
|
|
8877
|
+
[ -n "$human_directive" ] && printf '%s\n' "$human_directive"
|
|
8878
|
+
[ -n "$gate_failure_context" ] && printf '%s\n' "$gate_failure_context"
|
|
8879
|
+
[ -n "$queue_tasks" ] && printf '%s\n' "$queue_tasks"
|
|
8880
|
+
[ -n "$bmad_context" ] && printf '%s\n' "$bmad_context"
|
|
8881
|
+
[ -n "$openspec_context" ] && printf '%s\n' "$openspec_context"
|
|
8882
|
+
[ -n "$mirofish_context" ] && printf '%s\n' "$mirofish_context"
|
|
8883
|
+
[ -n "$magic_context" ] && printf '%s\n' "$magic_context"
|
|
8884
|
+
[ -n "$checklist_status" ] && printf '%s\n' "$checklist_status"
|
|
8885
|
+
[ -n "$app_runner_info" ] && printf '%s\n' "$app_runner_info"
|
|
8886
|
+
[ -n "$playwright_info" ] && printf '%s\n' "$playwright_info"
|
|
8887
|
+
[ -n "$memory_context_section" ] && printf '%s\n' "$memory_context_section"
|
|
8888
|
+
printf '%s\n' "$completion_instruction"
|
|
8889
|
+
printf '</dynamic_context>\n'
|
|
8694
8890
|
}
|
|
8695
8891
|
|
|
8696
8892
|
#===============================================================================
|
|
@@ -10317,12 +10513,21 @@ if __name__ == "__main__":
|
|
|
10317
10513
|
return 0
|
|
10318
10514
|
fi
|
|
10319
10515
|
|
|
10320
|
-
#
|
|
10321
|
-
#
|
|
10322
|
-
|
|
10516
|
+
# Stop if either:
|
|
10517
|
+
# (a) the agent invoked the loki_complete_task MCP tool
|
|
10518
|
+
# (detected via .loki/signals/TASK_COMPLETION_CLAIMED), OR
|
|
10519
|
+
# (b) LOKI_LEGACY_COMPLETION_MATCH=true AND the completion
|
|
10520
|
+
# promise text appears in the iteration output.
|
|
10521
|
+
# The check_completion_promise() helper encapsulates both.
|
|
10522
|
+
# BUG-RUN-001: Use per-iteration output, not stale daily log.
|
|
10523
|
+
if check_completion_promise "$iter_output"; then
|
|
10323
10524
|
echo ""
|
|
10324
|
-
|
|
10325
|
-
|
|
10525
|
+
if [ -n "$COMPLETION_PROMISE" ]; then
|
|
10526
|
+
log_header "COMPLETION PROMISE FULFILLED: $COMPLETION_PROMISE"
|
|
10527
|
+
else
|
|
10528
|
+
log_header "TASK COMPLETION CLAIMED (via loki_complete_task)"
|
|
10529
|
+
fi
|
|
10530
|
+
log_info "Explicit completion signal detected."
|
|
10326
10531
|
# Run memory consolidation on successful completion
|
|
10327
10532
|
log_info "Running memory consolidation..."
|
|
10328
10533
|
run_memory_consolidation
|
package/dashboard/__init__.py
CHANGED
package/docs/INSTALLATION.md
CHANGED
package/mcp/__init__.py
CHANGED
package/mcp/server.py
CHANGED
|
@@ -1005,6 +1005,111 @@ async def loki_consolidate_memory(since_hours: int = 24) -> str:
|
|
|
1005
1005
|
return json.dumps({"error": str(e)})
|
|
1006
1006
|
|
|
1007
1007
|
|
|
1008
|
+
@mcp.tool()
|
|
1009
|
+
async def loki_complete_task(
|
|
1010
|
+
completion_statement: str,
|
|
1011
|
+
evidence: str,
|
|
1012
|
+
confidence: str = "medium",
|
|
1013
|
+
) -> str:
|
|
1014
|
+
"""
|
|
1015
|
+
Declare that the current PRD / task is complete.
|
|
1016
|
+
|
|
1017
|
+
Replaces the legacy 'COMPLETION PROMISE FULFILLED: ...' prose string with a
|
|
1018
|
+
structured tool call. The orchestrator (run.sh) detects this via a signal
|
|
1019
|
+
file and stops the iteration loop gracefully.
|
|
1020
|
+
|
|
1021
|
+
Args:
|
|
1022
|
+
completion_statement: A short statement of what is complete (for example,
|
|
1023
|
+
"PRD requirements implemented, all tests passing, checklist 100%").
|
|
1024
|
+
evidence: Concrete evidence supporting the claim -- tests that passed,
|
|
1025
|
+
checklist items verified, files created/modified, metrics hit.
|
|
1026
|
+
confidence: One of 'high', 'medium', 'low' (default 'medium').
|
|
1027
|
+
'low' signals the orchestrator should still run the completion council.
|
|
1028
|
+
|
|
1029
|
+
Returns:
|
|
1030
|
+
JSON: {"recorded": true, "path": ".loki/events.jsonl"} on success,
|
|
1031
|
+
{"error": "..."} otherwise.
|
|
1032
|
+
"""
|
|
1033
|
+
_emit_tool_event_async(
|
|
1034
|
+
'loki_complete_task', 'start',
|
|
1035
|
+
parameters={
|
|
1036
|
+
'confidence': confidence,
|
|
1037
|
+
'statement_len': len(completion_statement or ''),
|
|
1038
|
+
'evidence_len': len(evidence or ''),
|
|
1039
|
+
},
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
# Validate inputs
|
|
1043
|
+
if not completion_statement or not completion_statement.strip():
|
|
1044
|
+
_emit_tool_event_async(
|
|
1045
|
+
'loki_complete_task', 'complete',
|
|
1046
|
+
result_status='error', error='completion_statement required')
|
|
1047
|
+
return json.dumps({"error": "completion_statement is required"})
|
|
1048
|
+
if not evidence or not evidence.strip():
|
|
1049
|
+
_emit_tool_event_async(
|
|
1050
|
+
'loki_complete_task', 'complete',
|
|
1051
|
+
result_status='error', error='evidence required')
|
|
1052
|
+
return json.dumps({"error": "evidence is required"})
|
|
1053
|
+
|
|
1054
|
+
confidence_norm = (confidence or 'medium').strip().lower()
|
|
1055
|
+
if confidence_norm not in ('high', 'medium', 'low'):
|
|
1056
|
+
confidence_norm = 'medium'
|
|
1057
|
+
|
|
1058
|
+
timestamp = datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z')
|
|
1059
|
+
|
|
1060
|
+
payload = {
|
|
1061
|
+
'type': 'task_completion_claim',
|
|
1062
|
+
'statement': completion_statement.strip(),
|
|
1063
|
+
'evidence': evidence.strip(),
|
|
1064
|
+
'confidence': confidence_norm,
|
|
1065
|
+
'timestamp': timestamp,
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
# Wrap event record with timestamp and type at the outer level so it matches
|
|
1069
|
+
# the shape of other events in .loki/events.jsonl.
|
|
1070
|
+
event_record = {
|
|
1071
|
+
'timestamp': timestamp,
|
|
1072
|
+
'type': 'task_completion_claim',
|
|
1073
|
+
'data': payload,
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
try:
|
|
1077
|
+
# Ensure .loki/ and .loki/signals/ exist under the project root
|
|
1078
|
+
loki_dir = safe_path_join('.loki')
|
|
1079
|
+
os.makedirs(loki_dir, exist_ok=True)
|
|
1080
|
+
signals_dir = safe_path_join('.loki', 'signals')
|
|
1081
|
+
os.makedirs(signals_dir, exist_ok=True)
|
|
1082
|
+
|
|
1083
|
+
events_path = safe_path_join('.loki', 'events.jsonl')
|
|
1084
|
+
with safe_open(events_path, 'a') as f:
|
|
1085
|
+
f.write(json.dumps(event_record) + '\n')
|
|
1086
|
+
|
|
1087
|
+
signal_path = safe_path_join('.loki', 'signals', 'TASK_COMPLETION_CLAIMED')
|
|
1088
|
+
with safe_open(signal_path, 'w') as f:
|
|
1089
|
+
f.write(json.dumps(payload, indent=2))
|
|
1090
|
+
|
|
1091
|
+
_emit_tool_event_async(
|
|
1092
|
+
'loki_complete_task', 'complete', result_status='success')
|
|
1093
|
+
return json.dumps({
|
|
1094
|
+
"recorded": True,
|
|
1095
|
+
"path": ".loki/events.jsonl",
|
|
1096
|
+
"signal": ".loki/signals/TASK_COMPLETION_CLAIMED",
|
|
1097
|
+
"confidence": confidence_norm,
|
|
1098
|
+
})
|
|
1099
|
+
except PathTraversalError as e:
|
|
1100
|
+
logger.error(f"Path traversal attempt blocked in loki_complete_task: {e}")
|
|
1101
|
+
_emit_tool_event_async(
|
|
1102
|
+
'loki_complete_task', 'complete',
|
|
1103
|
+
result_status='error', error='Access denied')
|
|
1104
|
+
return json.dumps({"error": "Access denied"})
|
|
1105
|
+
except Exception as e:
|
|
1106
|
+
logger.error(f"loki_complete_task failed: {e}")
|
|
1107
|
+
_emit_tool_event_async(
|
|
1108
|
+
'loki_complete_task', 'complete',
|
|
1109
|
+
result_status='error', error=str(e))
|
|
1110
|
+
return json.dumps({"error": str(e)})
|
|
1111
|
+
|
|
1112
|
+
|
|
1008
1113
|
# ============================================================
|
|
1009
1114
|
# RESOURCES - Data that can be read
|
|
1010
1115
|
# ============================================================
|