loki-mode 9.73.0 → 9.75.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.
Files changed (79) hide show
  1. package/SKILL.md +2 -2
  2. package/VERSION +1 -1
  3. package/autonomy/council-v2.sh +60 -13
  4. package/autonomy/lib/done-recognition.sh +73 -21
  5. package/autonomy/lib/proof-generator.py +7 -0
  6. package/autonomy/loki +18 -7
  7. package/autonomy/run.sh +14 -1
  8. package/dashboard/__init__.py +1 -1
  9. package/dashboard/server.py +22 -13
  10. package/dashboard/static/index.html +5 -5
  11. package/docs/INSTALLATION.md +1 -1
  12. package/docs/R3-COST-OBSERVABILITY-DESIGN.md +7 -1
  13. package/docs/exit-codes.md +21 -0
  14. package/docs/v10/ARCHITECT-CUTS.md +386 -317
  15. package/docs/v10/BOARD.md +64 -24
  16. package/docs/v10/GUARDS.md +13 -7
  17. package/loki-ts/dist/loki.js +251 -250
  18. package/mcp/__init__.py +1 -1
  19. package/package.json +1 -1
  20. package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
  21. package/web-app/dist/assets/{AdminPage-B11jqriL.js → AdminPage-CMGkmNnt.js} +1 -1
  22. package/web-app/dist/assets/{Avatar-vmIEiL2U.js → Avatar-9mn8sJ-2.js} +1 -1
  23. package/web-app/dist/assets/{Badge-DxtrDGcl.js → Badge-mSFLvvRX.js} +1 -1
  24. package/web-app/dist/assets/{Button-BiPlRkkg.js → Button-B1v4CSkD.js} +1 -1
  25. package/web-app/dist/assets/CockpitPage-BW0hYuzC.js +47 -0
  26. package/web-app/dist/assets/{ComparePage-B4ddvt9J.js → ComparePage-C1BXuolM.js} +1 -1
  27. package/web-app/dist/assets/{ErrorBoundary-BIJy59N_.js → ErrorBoundary-C2sJyBhb.js} +1 -1
  28. package/web-app/dist/assets/{EvidenceReceiptPanel-C4-Phh1f.js → EvidenceReceiptPanel-a1irlBPD.js} +1 -1
  29. package/web-app/dist/assets/GitHubIssuesPanel-zM-WRxYB.js +7 -0
  30. package/web-app/dist/assets/{GitHubPRsPanel-B_VHTB-t.js → GitHubPRsPanel-DvRa5Rxq.js} +1 -1
  31. package/web-app/dist/assets/{HomePage-cxONjTSm.js → HomePage-CNwRexp5.js} +2 -2
  32. package/web-app/dist/assets/{LoginPage-D49p6aVy.js → LoginPage-HKogNiEX.js} +1 -1
  33. package/web-app/dist/assets/{MagicPage-C5GUEIuM.js → MagicPage-u1mvdkUd.js} +1 -1
  34. package/web-app/dist/assets/{MetricsPage-I-OXi9kG.js → MetricsPage-CThdMJb5.js} +1 -1
  35. package/web-app/dist/assets/{NotFoundPage-Do19cbOP.js → NotFoundPage-B1v3lELS.js} +1 -1
  36. package/web-app/dist/assets/{ProjectPage-TRyzTIFH.js → ProjectPage-hDvSsdLF.js} +63 -63
  37. package/web-app/dist/assets/{ProjectsPage-BLSDhtVb.js → ProjectsPage-CRAegSM6.js} +1 -1
  38. package/web-app/dist/assets/{SettingsPage-BvixtAw7.js → SettingsPage-Dt90bFxo.js} +1 -1
  39. package/web-app/dist/assets/{ShowcasePage-By96BMJz.js → ShowcasePage-C5a9l8u_.js} +1 -1
  40. package/web-app/dist/assets/{SystemSettingsPage-AvVujpIo.js → SystemSettingsPage-DtqsDXbx.js} +1 -1
  41. package/web-app/dist/assets/{TeamsPage-BiT3N4px.js → TeamsPage-CooeoWxR.js} +1 -1
  42. package/web-app/dist/assets/{TemplatesPage-Y_m-dzfd.js → TemplatesPage-CJhTxWrw.js} +1 -1
  43. package/web-app/dist/assets/{TerminalOutput-oPTCcEGy.js → TerminalOutput-DvjfbDxb.js} +1 -1
  44. package/web-app/dist/assets/{activity-DCa9Pi7k.js → activity-DK6KBQKA.js} +1 -1
  45. package/web-app/dist/assets/{bell-Br7Xsjam.js → bell-Cd8tQpN6.js} +1 -1
  46. package/web-app/dist/assets/{bot-BsQKlSP5.js → bot-Y30w8rML.js} +1 -1
  47. package/web-app/dist/assets/{check-Cb49hCzQ.js → check-B5eUl1j9.js} +1 -1
  48. package/web-app/dist/assets/{chevron-left-Cs63FOmY.js → chevron-left-qyvpFqze.js} +1 -1
  49. package/web-app/dist/assets/{circle-alert-C8A636Wl.js → circle-alert-DXtjVPDB.js} +1 -1
  50. package/web-app/dist/assets/{clock-DhlnHjQI.js → clock-dqQis2Q6.js} +1 -1
  51. package/web-app/dist/assets/{cloud-uOYQxGRY.js → cloud-CzTURYO9.js} +1 -1
  52. package/web-app/dist/assets/{code-xml-9O9XlVo9.js → code-xml-DLbw1HTk.js} +1 -1
  53. package/web-app/dist/assets/{database-D9Oek2JS.js → database-BIj38v85.js} +1 -1
  54. package/web-app/dist/assets/{dollar-sign-CHetUBPR.js → dollar-sign-9bVcHIkD.js} +1 -1
  55. package/web-app/dist/assets/{file-code-corner-oTJV_ce4.js → file-code-corner-D57x6xD1.js} +1 -1
  56. package/web-app/dist/assets/{file-plus-vuloOqQB.js → file-plus-BXOrz3T5.js} +1 -1
  57. package/web-app/dist/assets/{globe-DMVdf8bk.js → globe-Cnq8h4Gt.js} +1 -1
  58. package/web-app/dist/assets/{hammer-15WRQJ1o.js → hammer-iiLGlF28.js} +1 -1
  59. package/web-app/dist/assets/{index-SRKz3Imw.js → index-uGGZ1Ij3.js} +2 -2
  60. package/web-app/dist/assets/{layers-C-QQQP9K.js → layers-gcGxxNEN.js} +1 -1
  61. package/web-app/dist/assets/{loader-circle-DqoJevCK.js → loader-circle-B4Ad11xq.js} +1 -1
  62. package/web-app/dist/assets/{lock-B68yfqau.js → lock-DvQNG5RI.js} +1 -1
  63. package/web-app/dist/assets/{package-DAxTtm-S.js → package-BtQBNbq2.js} +1 -1
  64. package/web-app/dist/assets/{plus-BSbdI5QI.js → plus-DKLiMXBZ.js} +1 -1
  65. package/web-app/dist/assets/{refresh-cw-DlvFuI3J.js → refresh-cw-B4Gu8e2m.js} +1 -1
  66. package/web-app/dist/assets/{rotate-ccw-BF03pKE0.js → rotate-ccw-DATSPLYS.js} +1 -1
  67. package/web-app/dist/assets/{scroll-text-QFZ1JdTD.js → scroll-text-GA8EtlY4.js} +1 -1
  68. package/web-app/dist/assets/{server-tyIvmSke.js → server-DT_3kM4V.js} +1 -1
  69. package/web-app/dist/assets/{shield-alert-DHeqbtBK.js → shield-alert-BEaqZEhO.js} +1 -1
  70. package/web-app/dist/assets/{thumbs-up-CRag1Tn5.js → thumbs-up-DVvA-Fas.js} +1 -1
  71. package/web-app/dist/assets/{trash-2-B0n4x-Ds.js → trash-2-BCyT5A9N.js} +1 -1
  72. package/web-app/dist/assets/{trending-down-DC4Aqzso.js → trending-down-BLcNt39o.js} +1 -1
  73. package/web-app/dist/assets/{trending-up-DFG157ke.js → trending-up-BqfBp13A.js} +1 -1
  74. package/web-app/dist/assets/{upload-BdWQ4cWx.js → upload-BxH0rjQU.js} +1 -1
  75. package/web-app/dist/assets/{usePolling-DMgD-dJ5.js → usePolling-CokbBZIQ.js} +1 -1
  76. package/web-app/dist/assets/{user-DXaZeAe4.js → user-C_u9mNZM.js} +1 -1
  77. package/web-app/dist/index.html +1 -1
  78. package/web-app/dist/assets/CockpitPage-DXKAc0jc.js +0 -47
  79. package/web-app/dist/assets/GitHubIssuesPanel-CVIG0uwi.js +0 -7
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: loki-mode
3
3
  description: Autonomous spec-driven build system with a built-in trust layer. It does not call work done until it is verified (RARV-C closure loop, 8 quality gates, completion council, verified-completion evidence gate). Triggers on "Loki Mode". Takes a spec (PRD, GitHub issue, OpenAPI doc, etc.) to deployed product with minimal human intervention. Provider-agnostic. Requires --dangerously-skip-permissions flag.
4
4
  ---
5
5
 
6
- # Loki Mode v9.73.0
6
+ # Loki Mode v9.75.0
7
7
 
8
8
  **You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
9
9
 
@@ -470,4 +470,4 @@ See `CHANGELOG.md` entries [7.5.7], [7.5.8], [7.5.13] for the per-fix list and r
470
470
 
471
471
  ---
472
472
 
473
- **v9.73.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~410 lines core**
473
+ **v9.75.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~410 lines core**
package/VERSION CHANGED
@@ -1 +1 @@
1
- 9.73.0
1
+ 9.75.0
@@ -20,15 +20,43 @@
20
20
  # - swarm/calibration.py (reviewer calibration)
21
21
  #
22
22
  # Inline Python (D7): the council runs with the cwd inside the agent's repo, so
23
- # every python3 here runs -E and drops '' and '.' from sys.path before any other
24
- # import (the swarm dir is inserted after that); a committed json.py or
25
- # sitecustomize.py cannot read the votes. Pinned by
26
- # tests/test-council-no-fabricated-verdict.sh (D7 section).
23
+ # every python here drops '' and '.' from sys.path before any other import (the
24
+ # swarm dir is inserted after that); a committed json.py or sitecustomize.py
25
+ # cannot read the votes. Pinned by tests/test-council-no-fabricated-verdict.sh
26
+ # (D7 section). S-201: -E alone still loads user site-packages, whose .pth
27
+ # "import" lines run before that scrub and can forge json.load, so every site
28
+ # runs the _loki_snapshot_py_tool interpreter -I -S. Pinned by
29
+ # tests/test-council-v2-no-user-site-pth.sh.
27
30
  #
28
31
  #===============================================================================
29
32
 
30
33
  COUNCIL_V2_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
31
34
 
35
+ # Guarded copy for callers that source this file on its own (tests). In
36
+ # production completion-council.sh (or run.sh) has already defined it. run.sh
37
+ # is the source of truth: keep this copy byte-identical to it.
38
+ declare -F _loki_snapshot_py_tool >/dev/null 2>&1 || \
39
+ _loki_snapshot_py_tool() {
40
+ local c
41
+ for c in /usr/bin/python3 /bin/python3; do
42
+ [ -x "$c" ] && [ ! -d "$c" ] && "$c" -I -S -c '' >/dev/null 2>&1 && { printf '%s\n' "$c"; return 0; }
43
+ done
44
+ local dir
45
+ local IFS=:
46
+ for dir in $PATH; do
47
+ case "$dir" in
48
+ /*) ;;
49
+ *) continue ;;
50
+ esac
51
+ if [ -x "$dir/python3" ] && [ ! -d "$dir/python3" ] \
52
+ && "$dir/python3" -I -S -c '' >/dev/null 2>&1; then
53
+ printf '%s\n' "$dir/python3"
54
+ return 0
55
+ fi
56
+ done
57
+ return 1
58
+ }
59
+
32
60
  #===============================================================================
33
61
  # council_v2_vote() -- Main entry point for v2 voting
34
62
  #
@@ -48,6 +76,9 @@ council_v2_vote() {
48
76
  local iteration="${4:-0}"
49
77
 
50
78
  local council_size="${COUNCIL_SIZE:-3}"
79
+ # S-201: none resolvable -> every read below takes its fail-safe fallback.
80
+ local _c2_py
81
+ _c2_py="$(_loki_snapshot_py_tool)" || _c2_py=""
51
82
 
52
83
  log_header "COMPLETION COUNCIL v2 - Iteration $iteration"
53
84
  log_info "Convening ${council_size}-member blind review council..."
@@ -103,7 +134,7 @@ council_v2_vote() {
103
134
  votes_json="$votes_json$vote_content"
104
135
 
105
136
  local verdict
106
- verdict=$(echo "$vote_content" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json; print(json.load(sys.stdin).get('verdict','').upper())" 2>/dev/null || echo "UNKNOWN")
137
+ verdict=$(echo "$vote_content" | "$_c2_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json; print(json.load(sys.stdin).get('verdict','').upper())" 2>/dev/null || echo "UNKNOWN")
107
138
  # TRUST: a reviewer that could not be REACHED did not vote REJECT.
108
139
  #
109
140
  # Every provider arm below used to substitute a literal
@@ -141,14 +172,21 @@ council_v2_vote() {
141
172
 
142
173
  # Step 4: Sycophancy detection
143
174
  local sycophancy_score
144
- sycophancy_score=$(python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
175
+ sycophancy_score=$("$_c2_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
145
176
  import sys
146
177
  sys.path.insert(0, '${COUNCIL_V2_DIR}/../swarm')
147
178
  from sycophancy import detect_sycophancy
148
179
  import json
149
180
  votes = json.loads(sys.argv[1])
150
181
  print('{:.3f}'.format(detect_sycophancy(votes)))
151
- " "$votes_json" 2>/dev/null || echo "0.000")
182
+ " "$votes_json" 2>/dev/null) || sycophancy_score=""
183
+ # S-201: a crashed or missing detector did not measure 0.000. Record the
184
+ # score as unmeasured (null keeps summary.json valid JSON) so Step 5
185
+ # challenges instead of reading "independent".
186
+ case "$sycophancy_score" in
187
+ [0-9]*.[0-9][0-9][0-9]) ;;
188
+ *) sycophancy_score="null" ;;
189
+ esac
152
190
 
153
191
  log_info "Sycophancy score: $sycophancy_score"
154
192
 
@@ -156,10 +194,17 @@ print('{:.3f}'.format(detect_sycophancy(votes)))
156
194
  if [ "$approve_count" -eq "$council_size" ]; then
157
195
  local threshold="${LOKI_COUNCIL_SYCOPHANCY_THRESHOLD:-0.6}"
158
196
  local should_challenge
159
- should_challenge=$(python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; print('yes' if float('$sycophancy_score') >= float('$threshold') else 'no')" 2>/dev/null || echo "no")
197
+ # S-201: an unmeasured score, or a compare that cannot run, challenges.
198
+ # Only a measured score below the threshold skips the devil's advocate.
199
+ if [ "$sycophancy_score" = "null" ]; then
200
+ should_challenge="yes"
201
+ else
202
+ should_challenge=$("$_c2_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; print('no' if float(sys.argv[1]) < float(sys.argv[2]) else 'yes')" "$sycophancy_score" "$threshold" 2>/dev/null) || should_challenge="yes"
203
+ [ "$should_challenge" = "no" ] || should_challenge="yes"
204
+ fi
160
205
 
161
206
  if [ "$should_challenge" = "yes" ]; then
162
- log_warn "Sycophancy score $sycophancy_score >= $threshold -- adding devil's advocate"
207
+ log_warn "Sycophancy score $sycophancy_score (threshold $threshold, null = unmeasured) -- adding devil's advocate"
163
208
  # Run devil's advocate with fresh evidence (no visibility of other votes)
164
209
  local da_dir
165
210
  da_dir=$(mktemp -d)
@@ -173,7 +218,7 @@ print('{:.3f}'.format(detect_sycophancy(votes)))
173
218
  # Same trust rule as the main tally: an unparseable devil's
174
219
  # advocate did not vote REJECT. Defaulting to REJECT here would
175
220
  # silently overturn a unanimous APPROVE on a transient failure.
176
- da_verdict=$(cat "$da_vote" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json; print(json.load(sys.stdin).get('verdict','').upper())" 2>/dev/null || echo "INCONCLUSIVE")
221
+ da_verdict=$(cat "$da_vote" | "$_c2_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json; print(json.load(sys.stdin).get('verdict','').upper())" 2>/dev/null || echo "INCONCLUSIVE")
177
222
  if [ "$da_verdict" = "INCONCLUSIVE" ]; then
178
223
  log_warn "Devil's advocate produced no verdict -- unanimous approval left UNCHANGED (not overturned)"
179
224
  elif [ "$da_verdict" = "REJECT" ]; then
@@ -207,7 +252,7 @@ print('{:.3f}'.format(detect_sycophancy(votes)))
207
252
  final_decision="reject"
208
253
  fi
209
254
 
210
- python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
255
+ "$_c2_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
211
256
  import sys
212
257
  sys.path.insert(0, '${COUNCIL_V2_DIR}/../swarm')
213
258
  from calibration import CalibrationTracker
@@ -271,6 +316,8 @@ council_v2_run_reviewer() {
271
316
  local role="$1"
272
317
  local review_dir="$2"
273
318
  local output_file="$3"
319
+ local _c2_py
320
+ _c2_py="$(_loki_snapshot_py_tool)" || _c2_py=""
274
321
 
275
322
  # Build review prompt based on role
276
323
  local prompt
@@ -394,7 +441,7 @@ Respond ONLY with a valid JSON object. No markdown fencing."
394
441
  --json-schema "$_c2_schema_content" --output-format json 2>/dev/null)" || _c2_json=""
395
442
  if [ -n "$_c2_json" ]; then
396
443
  # Pull the schema-validated object out of the envelope.
397
- result="$(printf '%s' "$_c2_json" | python3 -E -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]; import json
444
+ result="$(printf '%s' "$_c2_json" | "$_c2_py" -I -S -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]; import json
398
445
  try:
399
446
  e=json.load(sys.stdin)
400
447
  p=e.get("structured_output")
@@ -496,7 +543,7 @@ except Exception:
496
543
  # or neither, stays INCONCLUSIVE -- never guessed.
497
544
  if [ -z "$extracted" ] && [ -n "${result:-}" ]; then
498
545
  local _recovered
499
- _recovered="$(printf '%s' "$result" | _LOKI_RAW="$result" python3 -E -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]
546
+ _recovered="$(printf '%s' "$result" | _LOKI_RAW="$result" "$_c2_py" -I -S -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]
500
547
  import os, re, sys, json
501
548
  raw = os.environ.get("_LOKI_RAW", "")
502
549
  # Standalone words only: "APPROVE" not "approved-by", and not inside a URL.
@@ -38,9 +38,42 @@
38
38
  # No emojis. No em dashes. bash 3.2 safe. Honors `set -uo pipefail`.
39
39
  #
40
40
  # Inline Python (D7): the gate runs with the cwd inside the agent's repo, so
41
- # every python3 here runs -E and drops '' and '.' from sys.path before any other
42
- # import; a committed json.py or sitecustomize.py cannot turn the verdict done.
43
- # Pinned by tests/test-reuse-done-recognition.sh case (d7).
41
+ # every python3 here drops '' and '.' from sys.path before any other import; a
42
+ # committed json.py or sitecustomize.py cannot turn the verdict done. Pinned by
43
+ # tests/test-reuse-done-recognition.sh case (d7).
44
+ #
45
+ # S-200 (BACKLOG 54): -E alone still loads the user site-packages, whose .pth
46
+ # "import" lines run before that scrub and can forge json.load (a forged verdict
47
+ # read fast-stopped an incomplete project as done). Every call site resolves
48
+ # its interpreter through _loki_snapshot_py_tool and runs it -I -S; when none
49
+ # resolves, nothing reads as done or met (the gate builds, the writers write
50
+ # nothing). See that function's comment in run.sh for the rationale and accepted
51
+ # gaps. run.sh sources this file AFTER it defines _loki_snapshot_py_tool, so in
52
+ # production run.sh's definition is kept; the copy below only serves callers
53
+ # that source this file on its own (tests). run.sh is the source of truth: keep
54
+ # this copy byte-identical to it. Pinned by
55
+ # tests/test-done-recognition-no-user-site-pth.sh.
56
+ declare -F _loki_snapshot_py_tool >/dev/null 2>&1 || \
57
+ _loki_snapshot_py_tool() {
58
+ local c
59
+ for c in /usr/bin/python3 /bin/python3; do
60
+ [ -x "$c" ] && [ ! -d "$c" ] && "$c" -I -S -c '' >/dev/null 2>&1 && { printf '%s\n' "$c"; return 0; }
61
+ done
62
+ local dir
63
+ local IFS=:
64
+ for dir in $PATH; do
65
+ case "$dir" in
66
+ /*) ;;
67
+ *) continue ;;
68
+ esac
69
+ if [ -x "$dir/python3" ] && [ ! -d "$dir/python3" ] \
70
+ && "$dir/python3" -I -S -c '' >/dev/null 2>&1; then
71
+ printf '%s\n' "$dir/python3"
72
+ return 0
73
+ fi
74
+ done
75
+ return 1
76
+ }
44
77
 
45
78
  # Bound the single model call so a huge PRD or test log cannot run away.
46
79
  : "${LOKI_DONE_RECOG_TIMEOUT:=180}" # seconds for the single model call
@@ -133,8 +166,9 @@ _loki_done_recog_invoke() {
133
166
  claude --dangerously-skip-permissions -p "$prompt" \
134
167
  --json-schema "$_dr_schema_content" --output-format json 2>/dev/null) || _dr_json=""
135
168
  fi
136
- if [ -n "$_dr_json" ]; then
137
- _dr_obj=$(printf '%s' "$_dr_json" | python3 -E -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]; import json
169
+ local _dr_py
170
+ if [ -n "$_dr_json" ] && _dr_py="$(_loki_snapshot_py_tool)"; then
171
+ _dr_obj=$(printf '%s' "$_dr_json" | "$_dr_py" -I -S -c 'import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]; import json
138
172
  try:
139
173
  e=json.load(sys.stdin)
140
174
  p=e.get("structured_output")
@@ -206,7 +240,9 @@ _loki_done_recog_prd_sha() {
206
240
  sha256sum "$prd_file" 2>/dev/null | awk '{print $1}'
207
241
  else
208
242
  # Last-resort: a python hash, still deterministic over the same bytes.
209
- LOKI_DR_PRD="$prd_file" python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
243
+ local _dr_py
244
+ _dr_py="$(_loki_snapshot_py_tool)" || { printf ''; return 0; }
245
+ LOKI_DR_PRD="$prd_file" "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
210
246
  import hashlib, os
211
247
  p = os.environ.get('LOKI_DR_PRD','')
212
248
  try:
@@ -278,6 +314,13 @@ reuse_done_recognition_gate() {
278
314
  fi
279
315
  local _test_results="$loki_dir/quality/test-results.json"
280
316
 
317
+ # --- Resolve the -I -S interpreter (S-200); none -> inconclusive -> build.
318
+ local _dr_py
319
+ if ! _dr_py="$(_loki_snapshot_py_tool)"; then
320
+ log_info "Done-recognition: no isolated python3 interpreter resolved; proceeding to build."
321
+ return 1
322
+ fi
323
+
281
324
  # --- Build the model prompt payload (python: bounded, defensive) ---------
282
325
  local prompt
283
326
  prompt=$(LOKI_DR_PRD="$prd_path" \
@@ -287,7 +330,7 @@ reuse_done_recognition_gate() {
287
330
  LOKI_DR_CHECKLIST="$loki_dir/checklist/checklist.json" \
288
331
  LOKI_DR_MAX_PRD="${LOKI_DONE_RECOG_MAX_PRD_CHARS}" \
289
332
  LOKI_DR_MAX_TEST="${LOKI_DONE_RECOG_MAX_TEST_CHARS}" \
290
- python3 -E << 'DR_PROMPT_EOF'
333
+ "$_dr_py" -I -S << 'DR_PROMPT_EOF'
291
334
  import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]
292
335
  import json, os, sys
293
336
 
@@ -389,7 +432,7 @@ DR_PROMPT_EOF
389
432
  LOKI_DR_TESTS="$_test_results" \
390
433
  LOKI_DR_ACTION="$action" \
391
434
  LOKI_DR_PRD="$prd_path" \
392
- python3 -E << 'DR_PARSE_EOF'
435
+ "$_dr_py" -I -S << 'DR_PARSE_EOF'
393
436
  import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]
394
437
  import json, os, re, sys
395
438
 
@@ -700,11 +743,11 @@ DR_PARSE_EOF
700
743
  fi
701
744
 
702
745
  local verdict
703
- verdict=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('verdict',''))" 2>/dev/null)
746
+ verdict=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('verdict',''))" 2>/dev/null)
704
747
 
705
748
  case "$verdict" in
706
749
  done)
707
- _loki_done_recog_finish "$prd_path" "$parsed"
750
+ _loki_done_recog_finish "$prd_path" "$parsed" || return 1
708
751
  return 0
709
752
  ;;
710
753
  incomplete)
@@ -713,7 +756,7 @@ DR_PARSE_EOF
713
756
  ;;
714
757
  *)
715
758
  local _reason
716
- _reason=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('reason','') or 'unverifiable')" 2>/dev/null)
759
+ _reason=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('reason','') or 'unverifiable')" 2>/dev/null)
717
760
  log_info "Done-recognition: could not confirm the existing code already satisfies the reused spec (${_reason}). Proceeding to build to be safe."
718
761
  return 1
719
762
  ;;
@@ -729,6 +772,10 @@ _loki_done_recog_finish() {
729
772
  local parsed="$2"
730
773
  local loki_dir="${TARGET_DIR:-.}/.loki"
731
774
 
775
+ # S-200: no -I -S interpreter -> write no done record (the gate then builds).
776
+ local _dr_py
777
+ _dr_py="$(_loki_snapshot_py_tool)" || return 1
778
+
732
779
  # The gate runs EARLY in run_autonomous, before the run normally mints these
733
780
  # run-scoped ids/baselines (run.sh sets them just after this call site). The
734
781
  # council-parity finalizers below (and what they transitively call) expect
@@ -749,10 +796,10 @@ _loki_done_recog_finish() {
749
796
  mkdir -p "$loki_dir/state" 2>/dev/null || true
750
797
 
751
798
  local summary met total axis
752
- summary=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('summary','') or 'Project already satisfies its spec.')" 2>/dev/null)
753
- met=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('met_count',0))" 2>/dev/null)
754
- total=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('total_count',0))" 2>/dev/null)
755
- axis=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('tests_axis','unknown'))" 2>/dev/null)
799
+ summary=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('summary','') or 'Project already satisfies its spec.')" 2>/dev/null)
800
+ met=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('met_count',0))" 2>/dev/null)
801
+ total=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('total_count',0))" 2>/dev/null)
802
+ axis=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('tests_axis','unknown'))" 2>/dev/null)
756
803
  [ -n "$met" ] || met=0
757
804
  [ -n "$total" ] || total=0
758
805
  [ -n "$axis" ] || axis="unknown"
@@ -792,7 +839,7 @@ _loki_done_recog_finish() {
792
839
  echo ""
793
840
  echo "## Per-requirement evidence"
794
841
  echo ""
795
- printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
842
+ printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
796
843
  import json, sys
797
844
  try:
798
845
  d = json.load(sys.stdin)
@@ -811,7 +858,7 @@ for t in d.get('satisfied', []):
811
858
  LOKI_DR_MET="$met" \
812
859
  LOKI_DR_TOTAL="$total" \
813
860
  LOKI_DR_TS="$ts" \
814
- python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
861
+ "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
815
862
  import json, os, tempfile
816
863
  out = os.environ['LOKI_DR_OUT']
817
864
  def i(v):
@@ -861,6 +908,7 @@ except Exception:
861
908
  log_info "Verified ${met}/${total} requirements met by code inspection (no passing test run was available to confirm). ${summary}"
862
909
  fi
863
910
  log_info "To rebuild from scratch run 'loki start --fresh-prd'; to extend it, edit the spec or pass a new/changed PRD."
911
+ return 0
864
912
  }
865
913
 
866
914
  # incomplete path: write the satisfied-requirements manifest so
@@ -871,6 +919,10 @@ _loki_done_recog_write_manifest() {
871
919
  local parsed="$2"
872
920
  local loki_dir="${TARGET_DIR:-.}/.loki"
873
921
 
922
+ # S-200: no -I -S interpreter -> record nothing as met (full build).
923
+ local _dr_py
924
+ _dr_py="$(_loki_snapshot_py_tool)" || return 1
925
+
874
926
  mkdir -p "$loki_dir/state" 2>/dev/null || true
875
927
 
876
928
  local prd_sha
@@ -882,7 +934,7 @@ _loki_done_recog_write_manifest() {
882
934
  LOKI_DR_PARSED="$parsed" \
883
935
  LOKI_DR_SHA="$prd_sha" \
884
936
  LOKI_DR_TS="$ts" \
885
- python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
937
+ "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]
886
938
  import json, os, sys, tempfile
887
939
  out = os.environ['LOKI_DR_OUT']
888
940
  try:
@@ -923,7 +975,7 @@ except Exception:
923
975
  if [ -f "$loki_dir/queue/pending.json" ]; then
924
976
  # Drop prior PRD-sourced tasks so the incremental pass is the source of
925
977
  # truth; non-PRD tasks (if any) are preserved.
926
- LOKI_DR_PENDING="$loki_dir/queue/pending.json" python3 -E - <<'RESET_EOF' 2>/dev/null || true
978
+ LOKI_DR_PENDING="$loki_dir/queue/pending.json" "$_dr_py" -I -S - <<'RESET_EOF' 2>/dev/null || true
927
979
  import sys; sys.path[:] = [p for p in sys.path if p not in ("", ".")]
928
980
  import json, os, tempfile
929
981
  p = os.environ.get("LOKI_DR_PENDING", ".loki/queue/pending.json")
@@ -948,8 +1000,8 @@ RESET_EOF
948
1000
  fi
949
1001
 
950
1002
  local met total
951
- met=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('met_count',0))" 2>/dev/null)
952
- total=$(printf '%s' "$parsed" | python3 -E -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('total_count',0))" 2>/dev/null)
1003
+ met=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('met_count',0))" 2>/dev/null)
1004
+ total=$(printf '%s' "$parsed" | "$_dr_py" -I -S -c "import sys; sys.path[:] = [p for p in sys.path if p not in ('', '.')]; import json;print(json.load(sys.stdin).get('total_count',0))" 2>/dev/null)
953
1005
  local unmet=$(( ${total:-0} - ${met:-0} ))
954
1006
  log_info "Done-recognition: ${met:-0} of ${total:-0} requirements already satisfied; building only the ${unmet} unmet. Pass --fresh-prd to rebuild from scratch."
955
1007
  }
@@ -911,6 +911,7 @@ def _collect_tests(loki_dir):
911
911
  "status": "not_run",
912
912
  "duration_sec": None,
913
913
  }
914
+ empty = dict(out)
914
915
  if not isinstance(raw, dict):
915
916
  return out
916
917
  out["runner"] = str(raw.get("runner") or "")
@@ -944,6 +945,12 @@ def _collect_tests(loki_dir):
944
945
  out["status"] = "inconclusive"
945
946
  else:
946
947
  out["status"] = "not_run"
948
+ # BACKLOG 98: a test-results.json left by an earlier iteration is not this
949
+ # run's evidence, so it cannot lift the headline (the gates' rule). An
950
+ # earlier red is never discarded: a stale failure still reads failed.
951
+ if out["status"] != "failed" and not _test_results_fresh(
952
+ os.path.join(loki_dir, "quality")):
953
+ return empty
947
954
  return out
948
955
 
949
956
 
package/autonomy/loki CHANGED
@@ -28444,16 +28444,23 @@ if budget_limit is not None:
28444
28444
 
28445
28445
  # Prefer the recorded cumulative spend; fall back to the current run only when
28446
28446
  # the state file carries no figure. Never silently substitute 0.0 for "unknown".
28447
- if isinstance(budget_used_recorded, (int, float)):
28447
+ # A recorded ZERO is not a reading: run.sh check_budget_limit writes
28448
+ # "budget_used": 0 for a run it never measured. Same rule as the dashboard
28449
+ # (server.py budget readers): only a positive recorded figure counts, and a
28450
+ # measured zero comes from current_cost, which collect_efficiency leaves None
28451
+ # unless a record passes record_is_measured.
28452
+ if isinstance(budget_used_recorded, (int, float)) and budget_used_recorded > 0:
28448
28453
  budget_used = budget_used_recorded
28449
28454
  elif isinstance(current_cost, (int, float)):
28450
28455
  budget_used = current_cost
28451
28456
  else:
28452
- budget_used = 0.0
28457
+ budget_used = None
28453
28458
  status = "none"
28454
28459
  percent_used = None
28455
28460
  remaining = None
28456
- if budget_limit is not None and budget_limit > 0:
28461
+ if budget_limit is not None and budget_limit > 0 and budget_used is None:
28462
+ status = "unknown"
28463
+ elif budget_limit is not None and budget_limit > 0:
28457
28464
  percent_used = round(budget_used / budget_limit * 100, 2)
28458
28465
  remaining = max(0.0, budget_limit - budget_used)
28459
28466
  if budget_used >= budget_limit:
@@ -28487,7 +28494,7 @@ if show_json:
28487
28494
  "by_model": {k: round(v, 6) for k, v in by_model.items()},
28488
28495
  "budget": {
28489
28496
  "limit": budget_limit,
28490
- "used": round(budget_used, 6),
28497
+ "used": round(budget_used, 6) if budget_used is not None else None,
28491
28498
  "remaining": round(remaining, 6) if remaining is not None else None,
28492
28499
  "percent_used": percent_used,
28493
28500
  "status": status,
@@ -28538,13 +28545,17 @@ if budget_limit is None:
28538
28545
  print(DIM + " When set, Loki warns at 80% and hard-stops at 100%." + NC)
28539
28546
  else:
28540
28547
  col = GREEN
28541
- if status == "warn":
28548
+ if status in ("warn", "unknown"):
28542
28549
  col = YELLOW
28543
28550
  elif status == "exceeded":
28544
28551
  col = RED
28545
28552
  print(" Cap: " + _fmt_usd(budget_limit))
28546
- print(" Used: " + _fmt_usd(budget_used) + " (" + col + str(percent_used) + "%" + NC + ")")
28547
- print(" Remaining: " + _fmt_usd(remaining))
28553
+ if budget_used is None:
28554
+ print(" Used: not recorded (no measured iteration cost)")
28555
+ print(" Remaining: not recorded")
28556
+ else:
28557
+ print(" Used: " + _fmt_usd(budget_used) + " (" + col + str(percent_used) + "%" + NC + ")")
28558
+ print(" Remaining: " + _fmt_usd(remaining))
28548
28559
  print(" Status: " + col + BOLD + status.upper() + NC)
28549
28560
  if status == "warn":
28550
28561
  print(YELLOW + " Warning: at or above 80% of cap. Run continues; hard-stop at 100%." + NC)
package/autonomy/run.sh CHANGED
@@ -13875,7 +13875,20 @@ sys.stdout.write(t.strip())
13875
13875
  echo "$LOKI_MONOREPO_TEST_CMD" | grep -qE '[;|`$]|&&|\|\||>>|<<'; then
13876
13876
  log_error "LOKI_MONOREPO_TEST_CMD rejected (only [A-Za-z0-9_./= -] allowed): $LOKI_MONOREPO_TEST_CMD"
13877
13877
  test_runner="monorepo-custom-rejected"
13878
- details="monorepo-custom: rejected by whitelist (gate skipped, inconclusive)"
13878
+ # BACKLOG 62: nothing ran, so record the no-runner shape
13879
+ # (see the runner=="none" return below) instead of falling
13880
+ # through with test_passed=true, which wrote pass:true and
13881
+ # touched unit-tests.pass. The runner label stays distinct:
13882
+ # the council reads a non-boolean pass on a named runner as
13883
+ # NO_PASS (inconclusive pass-through). The command itself is
13884
+ # not echoed into the JSON (it failed the whitelist).
13885
+ rm -f "$quality_dir/unit-tests.pass" 2>/dev/null || true
13886
+ cat > "$quality_dir/test-results.json" << TREOF
13887
+ {"timestamp":"$(date -u +%Y-%m-%dT%H:%M:%SZ)","runner":"monorepo-custom-rejected","pass":"inconclusive","summary":"LOKI_MONOREPO_TEST_CMD rejected by whitelist (not run)","command":null,"exit_code":null,"status":"not_run","passed_count":null,"failed_count":null,"verification_gap":"test_command_rejected"}
13888
+ TREOF
13889
+ printf '%s\n' "${ITERATION_COUNT:-0}" > "$quality_dir/.test-results.iter" 2>/dev/null || true
13890
+ _LOKI_TEST_SUITE_STATUS=not_run
13891
+ return 0
13879
13892
  else
13880
13893
  test_runner="monorepo-custom"
13881
13894
  local output
@@ -7,7 +7,7 @@ Modules:
7
7
  control: Session control API (start/stop/pause/resume)
8
8
  """
9
9
 
10
- __version__ = "9.73.0"
10
+ __version__ = "9.75.0"
11
11
 
12
12
  # Expose the control app for easy import
13
13
  try:
@@ -7852,6 +7852,8 @@ def _compute_cost_snapshot() -> dict:
7852
7852
  budget_remaining = None
7853
7853
  # Did ANY record carry an observed value? Not "was a file present".
7854
7854
  cost_recorded = False
7855
+ # Tokens were measured (tracker fallback) but no USD figure was recorded.
7856
+ cost_unknown = False
7855
7857
 
7856
7858
  # Read efficiency files (one JSON file per iteration/task).
7857
7859
  # Use the iteration-*.json pattern so this reader sees the same
@@ -7929,25 +7931,32 @@ def _compute_cost_snapshot() -> dict:
7929
7931
  total_input = totals.get("total_input", 0)
7930
7932
  total_output = totals.get("total_output", 0)
7931
7933
  if total_input > 0 or total_output > 0:
7932
- # Real observed tokens from the context tracker: this IS a
7933
- # measurement, even if the recorded USD total happens to
7934
- # be 0.
7934
+ # Real observed tokens from the context tracker: the TOKENS
7935
+ # are a measurement. The USD figure is only a measurement
7936
+ # when the tracker recorded a number; a missing one is
7937
+ # unknown (null), while a recorded 0.0 stays 0.0.
7935
7938
  cost_recorded = True
7936
- estimated_cost = totals.get("total_cost_usd", 0.0)
7939
+ usd = totals.get("total_cost_usd")
7940
+ if isinstance(usd, (int, float)) and not isinstance(usd, bool):
7941
+ estimated_cost = usd
7942
+ else:
7943
+ cost_unknown = True
7944
+ # No provider recorded -> the model is unknown, not sonnet.
7945
+ model = str(ctx.get("provider") or "unknown").lower()
7937
7946
  # Rebuild by_model and by_phase from per_iteration data
7938
7947
  for it in ctx.get("per_iteration", []):
7939
7948
  inp = it.get("input_tokens", 0)
7940
7949
  out = it.get("output_tokens", 0)
7941
- cost = it.get("cost_usd", 0)
7942
- model = ctx.get("provider", "sonnet").lower()
7950
+ cost = it.get("cost_usd")
7951
+ cost_is_num = isinstance(cost, (int, float)) and not isinstance(cost, bool)
7943
7952
  if model not in by_model:
7944
- by_model[model] = {"input_tokens": 0, "output_tokens": 0, "cost_usd": 0.0}
7953
+ by_model[model] = {"input_tokens": 0, "output_tokens": 0, "cost_usd": 0.0,
7954
+ "measured": False, "tokens_measured": True}
7945
7955
  by_model[model]["input_tokens"] += inp
7946
7956
  by_model[model]["output_tokens"] += out
7947
- by_model[model]["cost_usd"] += cost
7948
- # Observed tokens from the tracker (cost_recorded above).
7949
- by_model[model]["measured"] = True
7950
- by_model[model]["tokens_measured"] = True
7957
+ if cost_is_num:
7958
+ by_model[model]["cost_usd"] += cost
7959
+ by_model[model]["measured"] = True
7951
7960
  except (json.JSONDecodeError, KeyError, TypeError, AttributeError):
7952
7961
  pass
7953
7962
 
@@ -7964,7 +7973,7 @@ def _compute_cost_snapshot() -> dict:
7964
7973
  # Spend against the cap only when something was measured: with
7965
7974
  # nothing recorded, "used" is unknown, not $0.00, and "remaining"
7966
7975
  # is unknown, not the whole cap.
7967
- if budget_limit is not None and cost_recorded:
7976
+ if budget_limit is not None and cost_recorded and not cost_unknown:
7968
7977
  budget_used = estimated_cost
7969
7978
  budget_remaining = max(0.0, budget_limit - budget_used)
7970
7979
  except (json.JSONDecodeError, KeyError):
@@ -7988,7 +7997,7 @@ def _compute_cost_snapshot() -> dict:
7988
7997
  total_input + total_output + total_cache_read + total_cache_creation
7989
7998
  ) if cost_recorded else None,
7990
7999
  "cache_hit_ratio": round(total_cache_read / _read_in, 4) if _read_in > 0 else None,
7991
- "estimated_cost_usd": round(estimated_cost, 6) if cost_recorded else None,
8000
+ "estimated_cost_usd": round(estimated_cost, 6) if cost_recorded and not cost_unknown else None,
7992
8001
  "cost_recorded": cost_recorded,
7993
8002
  "by_phase": {k: {
7994
8003
  "input_tokens": v["input_tokens"] if v.get("tokens_measured") else None,