loki-mode 5.8.6 → 5.8.8
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/VERSION +1 -1
- package/autonomy/loki +72 -0
- package/autonomy/run.sh +88 -4
- package/package.json +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.8.
|
|
1
|
+
5.8.8
|
package/autonomy/loki
CHANGED
|
@@ -1124,6 +1124,9 @@ main() {
|
|
|
1124
1124
|
provider)
|
|
1125
1125
|
cmd_provider "$@"
|
|
1126
1126
|
;;
|
|
1127
|
+
reset)
|
|
1128
|
+
cmd_reset "$@"
|
|
1129
|
+
;;
|
|
1127
1130
|
version|--version|-v)
|
|
1128
1131
|
cmd_version
|
|
1129
1132
|
;;
|
|
@@ -1138,4 +1141,73 @@ main() {
|
|
|
1138
1141
|
esac
|
|
1139
1142
|
}
|
|
1140
1143
|
|
|
1144
|
+
# Reset session state
|
|
1145
|
+
cmd_reset() {
|
|
1146
|
+
local subcommand="${1:-all}"
|
|
1147
|
+
|
|
1148
|
+
case "$subcommand" in
|
|
1149
|
+
retries|retry)
|
|
1150
|
+
if [ -f "$LOKI_DIR/autonomy-state.json" ]; then
|
|
1151
|
+
# Reset only retry count
|
|
1152
|
+
if command -v python3 &> /dev/null; then
|
|
1153
|
+
python3 -c "
|
|
1154
|
+
import json
|
|
1155
|
+
with open('$LOKI_DIR/autonomy-state.json', 'r') as f:
|
|
1156
|
+
state = json.load(f)
|
|
1157
|
+
state['retryCount'] = 0
|
|
1158
|
+
state['status'] = 'reset'
|
|
1159
|
+
with open('$LOKI_DIR/autonomy-state.json', 'w') as f:
|
|
1160
|
+
json.dump(state, f, indent=4)
|
|
1161
|
+
" 2>/dev/null
|
|
1162
|
+
echo -e "${GREEN}Retry count reset to 0${NC}"
|
|
1163
|
+
else
|
|
1164
|
+
rm -f "$LOKI_DIR/autonomy-state.json"
|
|
1165
|
+
echo -e "${GREEN}Autonomy state cleared${NC}"
|
|
1166
|
+
fi
|
|
1167
|
+
else
|
|
1168
|
+
echo -e "${YELLOW}No autonomy state found${NC}"
|
|
1169
|
+
fi
|
|
1170
|
+
;;
|
|
1171
|
+
failed|failures)
|
|
1172
|
+
if [ -f "$LOKI_DIR/queue/failed.json" ]; then
|
|
1173
|
+
local count
|
|
1174
|
+
count=$(jq 'length' "$LOKI_DIR/queue/failed.json" 2>/dev/null || echo "?")
|
|
1175
|
+
rm -f "$LOKI_DIR/queue/failed.json"
|
|
1176
|
+
echo "[]" > "$LOKI_DIR/queue/failed.json"
|
|
1177
|
+
echo -e "${GREEN}Cleared $count failed tasks${NC}"
|
|
1178
|
+
else
|
|
1179
|
+
echo -e "${YELLOW}No failed tasks found${NC}"
|
|
1180
|
+
fi
|
|
1181
|
+
;;
|
|
1182
|
+
all)
|
|
1183
|
+
# Reset everything
|
|
1184
|
+
rm -f "$LOKI_DIR/autonomy-state.json"
|
|
1185
|
+
echo "[]" > "$LOKI_DIR/queue/failed.json" 2>/dev/null
|
|
1186
|
+
echo -e "${GREEN}Session state reset${NC}"
|
|
1187
|
+
echo " - Autonomy state cleared"
|
|
1188
|
+
echo " - Failed task queue cleared"
|
|
1189
|
+
;;
|
|
1190
|
+
--help|-h|help)
|
|
1191
|
+
echo -e "${BOLD}loki reset${NC} - Reset session state"
|
|
1192
|
+
echo ""
|
|
1193
|
+
echo "Usage: loki reset [target]"
|
|
1194
|
+
echo ""
|
|
1195
|
+
echo "Targets:"
|
|
1196
|
+
echo " all Reset everything (default)"
|
|
1197
|
+
echo " retries Reset only the retry counter"
|
|
1198
|
+
echo " failed Clear failed task queue"
|
|
1199
|
+
echo ""
|
|
1200
|
+
echo "Examples:"
|
|
1201
|
+
echo " loki reset # Reset all state"
|
|
1202
|
+
echo " loki reset retries # Just reset retry count"
|
|
1203
|
+
echo " loki reset failed # Clear failed tasks"
|
|
1204
|
+
;;
|
|
1205
|
+
*)
|
|
1206
|
+
echo -e "${RED}Unknown reset target: $subcommand${NC}"
|
|
1207
|
+
echo "Valid targets: all, retries, failed"
|
|
1208
|
+
exit 1
|
|
1209
|
+
;;
|
|
1210
|
+
esac
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1141
1213
|
main "$@"
|
package/autonomy/run.sh
CHANGED
|
@@ -3494,7 +3494,19 @@ EOF
|
|
|
3494
3494
|
load_state() {
|
|
3495
3495
|
if [ -f ".loki/autonomy-state.json" ]; then
|
|
3496
3496
|
if command -v python3 &> /dev/null; then
|
|
3497
|
+
# Load both retry count and status from previous session
|
|
3498
|
+
local prev_status
|
|
3499
|
+
prev_status=$(python3 -c "import json; print(json.load(open('.loki/autonomy-state.json')).get('status', 'unknown'))" 2>/dev/null || echo "unknown")
|
|
3497
3500
|
RETRY_COUNT=$(python3 -c "import json; print(json.load(open('.loki/autonomy-state.json')).get('retryCount', 0))" 2>/dev/null || echo "0")
|
|
3501
|
+
|
|
3502
|
+
# Reset retry count if previous session ended in a terminal state
|
|
3503
|
+
# This allows new sessions to start fresh after failures
|
|
3504
|
+
case "$prev_status" in
|
|
3505
|
+
failed|max_iterations_reached|max_retries_exceeded)
|
|
3506
|
+
log_info "Previous session ended with status: $prev_status. Resetting retry count."
|
|
3507
|
+
RETRY_COUNT=0
|
|
3508
|
+
;;
|
|
3509
|
+
esac
|
|
3498
3510
|
else
|
|
3499
3511
|
RETRY_COUNT=0
|
|
3500
3512
|
fi
|
|
@@ -3503,6 +3515,71 @@ load_state() {
|
|
|
3503
3515
|
fi
|
|
3504
3516
|
}
|
|
3505
3517
|
|
|
3518
|
+
# Load tasks from queue files for prompt injection
|
|
3519
|
+
# Supports both array format [...] and object format {"tasks": [...]}
|
|
3520
|
+
load_queue_tasks() {
|
|
3521
|
+
local task_injection=""
|
|
3522
|
+
|
|
3523
|
+
# Helper Python script to extract and format tasks
|
|
3524
|
+
# Handles both formats, truncates long actions, normalizes newlines
|
|
3525
|
+
local extract_script='
|
|
3526
|
+
import json
|
|
3527
|
+
import sys
|
|
3528
|
+
|
|
3529
|
+
def extract_tasks(filepath, prefix):
|
|
3530
|
+
try:
|
|
3531
|
+
data = json.load(open(filepath))
|
|
3532
|
+
# Support both formats: [...] and {"tasks": [...]}
|
|
3533
|
+
tasks = data.get("tasks", data) if isinstance(data, dict) else data
|
|
3534
|
+
if not isinstance(tasks, list):
|
|
3535
|
+
return ""
|
|
3536
|
+
|
|
3537
|
+
results = []
|
|
3538
|
+
for i, task in enumerate(tasks[:3]): # Limit to first 3 tasks
|
|
3539
|
+
if not isinstance(task, dict):
|
|
3540
|
+
continue
|
|
3541
|
+
task_id = task.get("id") or "unknown"
|
|
3542
|
+
task_type = task.get("type") or "unknown"
|
|
3543
|
+
payload = task.get("payload", {})
|
|
3544
|
+
|
|
3545
|
+
# Extract action from payload
|
|
3546
|
+
if isinstance(payload, dict):
|
|
3547
|
+
action = payload.get("action") or payload.get("goal") or ""
|
|
3548
|
+
else:
|
|
3549
|
+
action = str(payload) if payload else ""
|
|
3550
|
+
|
|
3551
|
+
# Normalize: remove newlines, truncate to 500 chars
|
|
3552
|
+
action = str(action).replace("\n", " ").replace("\r", "")[:500]
|
|
3553
|
+
if len(str(task.get("payload", {}).get("action", ""))) > 500:
|
|
3554
|
+
action += "..."
|
|
3555
|
+
|
|
3556
|
+
results.append(f"{prefix}[{i+1}] id={task_id} type={task_type}: {action}")
|
|
3557
|
+
|
|
3558
|
+
return " ".join(results)
|
|
3559
|
+
except:
|
|
3560
|
+
return ""
|
|
3561
|
+
|
|
3562
|
+
# Check in-progress first
|
|
3563
|
+
in_progress = extract_tasks(".loki/queue/in-progress.json", "TASK")
|
|
3564
|
+
pending = extract_tasks(".loki/queue/pending.json", "PENDING")
|
|
3565
|
+
|
|
3566
|
+
output = []
|
|
3567
|
+
if in_progress:
|
|
3568
|
+
output.append(f"IN-PROGRESS TASKS (EXECUTE THESE): {in_progress}")
|
|
3569
|
+
if pending:
|
|
3570
|
+
output.append(f"PENDING: {pending}")
|
|
3571
|
+
|
|
3572
|
+
print(" | ".join(output))
|
|
3573
|
+
'
|
|
3574
|
+
|
|
3575
|
+
# First check in-progress tasks (highest priority)
|
|
3576
|
+
if [ -f ".loki/queue/in-progress.json" ] || [ -f ".loki/queue/pending.json" ]; then
|
|
3577
|
+
task_injection=$(python3 -c "$extract_script" 2>/dev/null || echo "")
|
|
3578
|
+
fi
|
|
3579
|
+
|
|
3580
|
+
echo "$task_injection"
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3506
3583
|
#===============================================================================
|
|
3507
3584
|
# Build Resume Prompt
|
|
3508
3585
|
#===============================================================================
|
|
@@ -3576,17 +3653,24 @@ build_prompt() {
|
|
|
3576
3653
|
human_directive="HUMAN_DIRECTIVE (PRIORITY): $LOKI_HUMAN_INPUT Execute this directive BEFORE continuing normal tasks."
|
|
3577
3654
|
fi
|
|
3578
3655
|
|
|
3656
|
+
# Queue task injection (from dashboard or API)
|
|
3657
|
+
local queue_tasks=""
|
|
3658
|
+
queue_tasks=$(load_queue_tasks)
|
|
3659
|
+
if [ -n "$queue_tasks" ]; then
|
|
3660
|
+
queue_tasks="QUEUED_TASKS (PRIORITY): $queue_tasks. Execute these tasks BEFORE finding new improvements."
|
|
3661
|
+
fi
|
|
3662
|
+
|
|
3579
3663
|
if [ $retry -eq 0 ]; then
|
|
3580
3664
|
if [ -n "$prd" ]; then
|
|
3581
|
-
echo "Loki Mode with PRD at $prd. $human_directive $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3665
|
+
echo "Loki Mode with PRD at $prd. $human_directive $queue_tasks $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3582
3666
|
else
|
|
3583
|
-
echo "Loki Mode. $human_directive $analysis_instruction $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3667
|
+
echo "Loki Mode. $human_directive $queue_tasks $analysis_instruction $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3584
3668
|
fi
|
|
3585
3669
|
else
|
|
3586
3670
|
if [ -n "$prd" ]; then
|
|
3587
|
-
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). PRD: $prd. $human_directive $context_injection $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3671
|
+
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). PRD: $prd. $human_directive $queue_tasks $context_injection $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3588
3672
|
else
|
|
3589
|
-
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). $human_directive $context_injection Use .loki/generated-prd.md if exists. $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3673
|
+
echo "Loki Mode - Resume iteration #$iteration (retry #$retry). $human_directive $queue_tasks $context_injection Use .loki/generated-prd.md if exists. $rarv_instruction $memory_instruction $compaction_reminder $completion_instruction $sdlc_instruction $autonomous_suffix"
|
|
3590
3674
|
fi
|
|
3591
3675
|
fi
|
|
3592
3676
|
}
|