loki-mode 7.86.0 → 7.88.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/lib/own-render.py +547 -0
- package/autonomy/lib/proof-generator.py +64 -0
- package/autonomy/lib/secure-scan.py +652 -0
- package/autonomy/loki +168 -0
- package/autonomy/run.sh +187 -0
- package/dashboard/__init__.py +1 -1
- package/docs/INSTALLATION.md +2 -2
- package/loki-ts/dist/loki.js +2 -2
- package/mcp/__init__.py +1 -1
- package/package.json +1 -1
- package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
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 v7.
|
|
6
|
+
# Loki Mode v7.88.0
|
|
7
7
|
|
|
8
8
|
**You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
|
|
9
9
|
|
|
@@ -408,4 +408,4 @@ See `CHANGELOG.md` entries [7.5.7], [7.5.8], [7.5.13] for the per-fix list and r
|
|
|
408
408
|
|
|
409
409
|
---
|
|
410
410
|
|
|
411
|
-
**v7.
|
|
411
|
+
**v7.88.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
7.
|
|
1
|
+
7.88.0
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Finish-and-own renderer for Loki Mode (Loop 5, v7.88.0).
|
|
3
|
+
|
|
4
|
+
A PURE render layer over EXISTING honest data. It reads the artifacts the
|
|
5
|
+
runner already wrote (the Evidence Receipt proof.json, completion.json,
|
|
6
|
+
USAGE.md, the app-runner state, the assumptions ledger) and restates them in
|
|
7
|
+
plain English for a NON-technical founder.
|
|
8
|
+
|
|
9
|
+
Design rules (LOOP5-FINISH-AND-OWN-PLAN.md):
|
|
10
|
+
- NEVER recompute or fabricate. Every line maps to a real artifact value.
|
|
11
|
+
- The "Is it working?" verdict is taken VERBATIM from honesty.headline.
|
|
12
|
+
Green ("ready") is gated on headline == "VERIFIED" AND tests passed AND
|
|
13
|
+
the build ran. This honesty gate is the core of the lib.
|
|
14
|
+
- Tolerant of missing artifacts: each one absent is marked honestly rather
|
|
15
|
+
than guessed at.
|
|
16
|
+
- No LLM call here (keep it pure / deterministic / testable). The "What you
|
|
17
|
+
have now" paragraph is a deterministic template over the recorded brief +
|
|
18
|
+
diff stat. No invented features.
|
|
19
|
+
- Exit 0 always: this is a report, never a gate.
|
|
20
|
+
|
|
21
|
+
CLI:
|
|
22
|
+
python3 autonomy/lib/own-render.py [--loki-dir .loki] [--md|--json]
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
# tolerant readers
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
def _read_json(path, default=None):
|
|
36
|
+
try:
|
|
37
|
+
with open(path, "r") as f:
|
|
38
|
+
return json.load(f)
|
|
39
|
+
except Exception:
|
|
40
|
+
return default
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _read_text(path, default=""):
|
|
44
|
+
try:
|
|
45
|
+
with open(path, "r", errors="replace") as f:
|
|
46
|
+
return f.read()
|
|
47
|
+
except Exception:
|
|
48
|
+
return default
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _latest_proof(loki_dir):
|
|
52
|
+
"""Return (run_id, proof_dict) for the most recent proof, or (None, None).
|
|
53
|
+
|
|
54
|
+
Proof run dirs are named with a timestamp prefix (YYYYmmddTHHMMSSZ-...),
|
|
55
|
+
so a lexicographic sort puts the newest last. We pick the newest dir that
|
|
56
|
+
actually contains a readable proof.json.
|
|
57
|
+
"""
|
|
58
|
+
proofs_dir = os.path.join(loki_dir, "proofs")
|
|
59
|
+
try:
|
|
60
|
+
entries = sorted(os.listdir(proofs_dir))
|
|
61
|
+
except Exception:
|
|
62
|
+
return None, None
|
|
63
|
+
for run_id in reversed(entries):
|
|
64
|
+
proof = _read_json(os.path.join(proofs_dir, run_id, "proof.json"))
|
|
65
|
+
if isinstance(proof, dict):
|
|
66
|
+
return run_id, proof
|
|
67
|
+
return None, None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _live_url(loki_dir):
|
|
71
|
+
"""Return the live app URL only when the app runner reports it running."""
|
|
72
|
+
state = _read_json(os.path.join(loki_dir, "app-runner", "state.json"))
|
|
73
|
+
if isinstance(state, dict) and state.get("status") == "running":
|
|
74
|
+
url = str(state.get("url") or "").strip()
|
|
75
|
+
if url:
|
|
76
|
+
return url
|
|
77
|
+
return ""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _usage_section(usage_text, header):
|
|
81
|
+
"""Pull the body of a '## <header>' section from USAGE.md, verbatim.
|
|
82
|
+
|
|
83
|
+
Returns the lines under the matching heading up to the next '## ' heading,
|
|
84
|
+
trimmed of blank edges. Empty string when the section is absent.
|
|
85
|
+
"""
|
|
86
|
+
if not usage_text:
|
|
87
|
+
return ""
|
|
88
|
+
lines = usage_text.splitlines()
|
|
89
|
+
out = []
|
|
90
|
+
capturing = False
|
|
91
|
+
want = header.strip().lower()
|
|
92
|
+
for line in lines:
|
|
93
|
+
stripped = line.strip()
|
|
94
|
+
if stripped.startswith("## "):
|
|
95
|
+
if capturing:
|
|
96
|
+
break
|
|
97
|
+
name = stripped[3:].strip().lower()
|
|
98
|
+
# Match on a prefix so "## Verify (it works)" matches "Verify".
|
|
99
|
+
capturing = name == want or name.startswith(want + " ") \
|
|
100
|
+
or name.startswith(want + " (")
|
|
101
|
+
continue
|
|
102
|
+
if capturing:
|
|
103
|
+
out.append(line)
|
|
104
|
+
# Trim leading/trailing blank lines.
|
|
105
|
+
while out and not out[0].strip():
|
|
106
|
+
out.pop(0)
|
|
107
|
+
while out and not out[-1].strip():
|
|
108
|
+
out.pop()
|
|
109
|
+
return "\n".join(out)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# ---------------------------------------------------------------------------
|
|
113
|
+
# honesty gate (the core)
|
|
114
|
+
# ---------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
def _is_ready(proof):
|
|
117
|
+
"""Deterministic green gate. True ONLY when:
|
|
118
|
+
- honesty.headline == "VERIFIED", AND
|
|
119
|
+
- facts.tests.status in (passed, verified), AND
|
|
120
|
+
- the build actually ran (facts.build.ran true / status not 'not_run').
|
|
121
|
+
|
|
122
|
+
Any one missing -> not ready. This is the line that must never overclaim.
|
|
123
|
+
"""
|
|
124
|
+
if not isinstance(proof, dict):
|
|
125
|
+
return False
|
|
126
|
+
honesty = proof.get("honesty") or {}
|
|
127
|
+
if str(honesty.get("headline") or "").strip().upper() != "VERIFIED":
|
|
128
|
+
return False
|
|
129
|
+
facts = proof.get("facts") or {}
|
|
130
|
+
tests = facts.get("tests") or {}
|
|
131
|
+
if str(tests.get("status") or "").strip().lower() not in ("passed", "verified"):
|
|
132
|
+
return False
|
|
133
|
+
build = facts.get("build") or {}
|
|
134
|
+
build_ran = bool(build.get("ran")) or \
|
|
135
|
+
str(build.get("status") or "").strip().lower() not in ("not_run", "", "none")
|
|
136
|
+
return build_ran
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# ---------------------------------------------------------------------------
|
|
140
|
+
# section builders (markdown). Each returns a list of lines.
|
|
141
|
+
# ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
def _section_what_you_have(proof):
|
|
144
|
+
"""1. 'What you have now' - product-terms restatement of the brief + diff.
|
|
145
|
+
|
|
146
|
+
Deterministic template only: the recorded brief verbatim plus a one-line
|
|
147
|
+
files-changed summary. No invented features, no LLM call.
|
|
148
|
+
"""
|
|
149
|
+
lines = ["## What you have now", ""]
|
|
150
|
+
spec = (proof or {}).get("spec") or {}
|
|
151
|
+
brief = str(spec.get("brief") or "").strip()
|
|
152
|
+
if brief:
|
|
153
|
+
# Restate the brief as the description of what was built. Quote it so the
|
|
154
|
+
# reader sees it is their own words, not a Loki claim.
|
|
155
|
+
first = brief.splitlines()[0].strip()
|
|
156
|
+
lines.append("You asked Loki to build this:")
|
|
157
|
+
lines.append("")
|
|
158
|
+
lines.append("> " + first)
|
|
159
|
+
else:
|
|
160
|
+
lines.append("Loki worked directly on an existing codebase here (no written "
|
|
161
|
+
"spec was recorded for this run).")
|
|
162
|
+
lines.append("")
|
|
163
|
+
|
|
164
|
+
facts = (proof or {}).get("facts") or {}
|
|
165
|
+
git = facts.get("git") or {}
|
|
166
|
+
diff = git.get("diff") or (proof or {}).get("files_changed") or {}
|
|
167
|
+
count = diff.get("count") or 0
|
|
168
|
+
ins = diff.get("insertions") or 0
|
|
169
|
+
dele = diff.get("deletions") or 0
|
|
170
|
+
if count:
|
|
171
|
+
lines.append("It changed %d file%s (%d lines added, %d removed)."
|
|
172
|
+
% (count, "" if count == 1 else "s", ins, dele))
|
|
173
|
+
else:
|
|
174
|
+
lines.append("No file changes were recorded for this run.")
|
|
175
|
+
return lines
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _build_age_note(run_id):
|
|
179
|
+
"""An honest 'this verdict describes the build at <when>' line + a pointer to
|
|
180
|
+
re-verify against current code. A non-technical owner must not read an old
|
|
181
|
+
receipt as a statement about code they edited since the build."""
|
|
182
|
+
lines = []
|
|
183
|
+
when = _run_id_when(run_id)
|
|
184
|
+
if when:
|
|
185
|
+
lines.append("This describes the build Loki finished on %s. If you (or a "
|
|
186
|
+
"developer) changed the code after that, this verdict is about "
|
|
187
|
+
"the older version, not your current files." % when)
|
|
188
|
+
else:
|
|
189
|
+
lines.append("This describes the last build Loki finished. If the code "
|
|
190
|
+
"changed since then, this verdict is about the older version.")
|
|
191
|
+
if run_id:
|
|
192
|
+
lines.append("To confirm it still matches your current code, run: "
|
|
193
|
+
"`loki proof verify %s`" % run_id)
|
|
194
|
+
return lines
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _run_id_when(run_id):
|
|
198
|
+
"""Format a human date from a proof run_id (YYYYmmddTHHMMSSZ-...). Returns ''
|
|
199
|
+
if the id is not in that shape (no fabrication -- only restate what is there)."""
|
|
200
|
+
if not run_id:
|
|
201
|
+
return ""
|
|
202
|
+
stamp = str(run_id).split("-", 1)[0]
|
|
203
|
+
# Expect YYYYmmddTHHMMSSZ
|
|
204
|
+
if len(stamp) >= 16 and stamp[8:9] == "T" and stamp[15:16] == "Z":
|
|
205
|
+
y, mo, d = stamp[0:4], stamp[4:6], stamp[6:8]
|
|
206
|
+
hh, mm = stamp[9:11], stamp[11:13]
|
|
207
|
+
if y.isdigit() and mo.isdigit() and d.isdigit():
|
|
208
|
+
return "%s-%s-%s at %s:%s UTC" % (y, mo, d, hh, mm)
|
|
209
|
+
return ""
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _section_is_it_working(proof, run_id=None):
|
|
213
|
+
"""2. 'Is it working?' - VERBATIM honesty.headline gating.
|
|
214
|
+
|
|
215
|
+
Green only when _is_ready(). Otherwise plainly states what was not verified
|
|
216
|
+
and lists honesty.degraded[]. NEVER prints a ready/ship line unless ready.
|
|
217
|
+
Always dates the verdict + points to re-verify, so a stale receipt is never
|
|
218
|
+
read as current truth.
|
|
219
|
+
"""
|
|
220
|
+
lines = ["## Is it working?", ""]
|
|
221
|
+
honesty = (proof or {}).get("honesty") or {}
|
|
222
|
+
headline = str(honesty.get("headline") or "").strip()
|
|
223
|
+
degraded = honesty.get("degraded") or []
|
|
224
|
+
|
|
225
|
+
if _is_ready(proof):
|
|
226
|
+
lines.append("Yes. Loki verified this build: the tests passed and the "
|
|
227
|
+
"build ran cleanly.")
|
|
228
|
+
lines.append("")
|
|
229
|
+
lines.append("Verdict (Loki's honest receipt): %s" % (headline or "VERIFIED"))
|
|
230
|
+
lines.append("")
|
|
231
|
+
lines.extend(_build_age_note(run_id))
|
|
232
|
+
return lines
|
|
233
|
+
|
|
234
|
+
# Not ready. State the verdict plainly and list every gap.
|
|
235
|
+
if headline:
|
|
236
|
+
lines.append("Not fully verified. Loki's honest verdict for this run is: "
|
|
237
|
+
"%s" % headline)
|
|
238
|
+
else:
|
|
239
|
+
lines.append("Not verified. Loki did not record a verdict for this run.")
|
|
240
|
+
lines.append("")
|
|
241
|
+
lines.append("This means Loki is NOT telling you it is ready to ship. Here is "
|
|
242
|
+
"what was not verified:")
|
|
243
|
+
lines.append("")
|
|
244
|
+
if isinstance(degraded, list) and degraded:
|
|
245
|
+
for d in degraded:
|
|
246
|
+
if isinstance(d, dict):
|
|
247
|
+
item = str(d.get("item") or "").strip() or "(unnamed check)"
|
|
248
|
+
status = str(d.get("status") or "").strip()
|
|
249
|
+
reason = str(d.get("reason") or "").strip()
|
|
250
|
+
bits = [b for b in (status, reason) if b]
|
|
251
|
+
tail = (" - " + "; ".join(bits)) if bits else ""
|
|
252
|
+
lines.append("- %s%s" % (item, tail))
|
|
253
|
+
else:
|
|
254
|
+
lines.append("- %s" % str(d))
|
|
255
|
+
else:
|
|
256
|
+
lines.append("- (no specific gaps were itemized, but the verdict above is "
|
|
257
|
+
"not a clean pass)")
|
|
258
|
+
lines.append("")
|
|
259
|
+
lines.extend(_build_age_note(run_id))
|
|
260
|
+
return lines
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _section_run_on_computer(proof, usage_text, live_url):
|
|
264
|
+
"""3. 'How to run it on your computer' - quote Start/Verify from USAGE.md."""
|
|
265
|
+
lines = ["## How to run it on your computer", ""]
|
|
266
|
+
if live_url:
|
|
267
|
+
lines.append("It is running right now on this machine at: %s" % live_url)
|
|
268
|
+
lines.append("")
|
|
269
|
+
start = _usage_section(usage_text, "Start")
|
|
270
|
+
verify = _usage_section(usage_text, "Verify")
|
|
271
|
+
install = _usage_section(usage_text, "Install")
|
|
272
|
+
if install:
|
|
273
|
+
lines.append("First, install it:")
|
|
274
|
+
lines.append("")
|
|
275
|
+
lines.append("```")
|
|
276
|
+
lines.append(install)
|
|
277
|
+
lines.append("```")
|
|
278
|
+
lines.append("")
|
|
279
|
+
if start:
|
|
280
|
+
lines.append("To start it:")
|
|
281
|
+
lines.append("")
|
|
282
|
+
lines.append("```")
|
|
283
|
+
lines.append(start)
|
|
284
|
+
lines.append("```")
|
|
285
|
+
lines.append("")
|
|
286
|
+
if verify:
|
|
287
|
+
lines.append("To check it works:")
|
|
288
|
+
lines.append("")
|
|
289
|
+
lines.append("```")
|
|
290
|
+
lines.append(verify)
|
|
291
|
+
lines.append("```")
|
|
292
|
+
if not (start or verify or install):
|
|
293
|
+
lines.append("No run instructions (USAGE.md) were found for this build. "
|
|
294
|
+
"Once you run a build to completion, Loki writes a USAGE.md at "
|
|
295
|
+
"the project root with the exact commands.")
|
|
296
|
+
return lines
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _section_put_online(proof):
|
|
300
|
+
"""4. 'How to put it online' - mention loki deploy / preview; URL if present."""
|
|
301
|
+
lines = ["## How to put it online", ""]
|
|
302
|
+
deployment = (proof or {}).get("deployment") or {}
|
|
303
|
+
deployed_url = str(deployment.get("deployed_url") or "").strip()
|
|
304
|
+
if deployed_url:
|
|
305
|
+
lines.append("This build was deployed. It is live at: %s" % deployed_url)
|
|
306
|
+
lines.append("")
|
|
307
|
+
else:
|
|
308
|
+
lines.append("This build has not been put online yet.")
|
|
309
|
+
lines.append("")
|
|
310
|
+
lines.append("When you are ready, you have two options:")
|
|
311
|
+
lines.append("")
|
|
312
|
+
lines.append("- `loki deploy` - deploy it using your own cloud account.")
|
|
313
|
+
lines.append("- `loki preview --public` - share a temporary public link to the "
|
|
314
|
+
"version running on your computer.")
|
|
315
|
+
return lines
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _section_developer_needs(proof):
|
|
319
|
+
"""5. 'What a developer needs to know' - group changed files by top dir."""
|
|
320
|
+
lines = ["## What a developer needs to know", ""]
|
|
321
|
+
facts = (proof or {}).get("facts") or {}
|
|
322
|
+
git = facts.get("git") or {}
|
|
323
|
+
diff = git.get("diff") or (proof or {}).get("files_changed") or {}
|
|
324
|
+
files = diff.get("files") or []
|
|
325
|
+
if isinstance(files, list) and files:
|
|
326
|
+
groups = {}
|
|
327
|
+
for f in files:
|
|
328
|
+
if not isinstance(f, dict):
|
|
329
|
+
continue
|
|
330
|
+
path = str(f.get("path") or "").strip()
|
|
331
|
+
if not path:
|
|
332
|
+
continue
|
|
333
|
+
top = path.split("/")[0] if "/" in path else "(project root)"
|
|
334
|
+
groups.setdefault(top, 0)
|
|
335
|
+
groups[top] += 1
|
|
336
|
+
if groups:
|
|
337
|
+
lines.append("The changes touch these areas of the codebase:")
|
|
338
|
+
lines.append("")
|
|
339
|
+
for top in sorted(groups):
|
|
340
|
+
n = groups[top]
|
|
341
|
+
lines.append("- %s (%d file%s)" % (top, n, "" if n == 1 else "s"))
|
|
342
|
+
lines.append("")
|
|
343
|
+
else:
|
|
344
|
+
lines.append("No changed-file list was recorded for this run.")
|
|
345
|
+
lines.append("")
|
|
346
|
+
lines.append("A developer should read USAGE.md (run/verify commands) and the "
|
|
347
|
+
"developer handoff notes in .loki/memory/handoffs/.")
|
|
348
|
+
return lines
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def _section_verified(proof, run_id):
|
|
352
|
+
"""6. 'What is verified' - the proof commands."""
|
|
353
|
+
lines = ["## What is verified", ""]
|
|
354
|
+
if run_id:
|
|
355
|
+
lines.append("Loki keeps a tamper-evident receipt of exactly what it did. "
|
|
356
|
+
"Anyone can inspect or re-check it:")
|
|
357
|
+
lines.append("")
|
|
358
|
+
lines.append("- `loki proof show %s` - read the full receipt." % run_id)
|
|
359
|
+
lines.append("- `loki proof verify %s` - confirm the receipt has not been "
|
|
360
|
+
"altered." % run_id)
|
|
361
|
+
else:
|
|
362
|
+
lines.append("No receipt was found for this project yet. Loki writes one "
|
|
363
|
+
"when a build completes.")
|
|
364
|
+
return lines
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _section_still_to_do(proof, completion):
|
|
368
|
+
"""7. 'What you still need to do or decide'."""
|
|
369
|
+
lines = ["## What you still need to do or decide", ""]
|
|
370
|
+
items = []
|
|
371
|
+
|
|
372
|
+
# Assumptions Loki had to make where the spec was ambiguous.
|
|
373
|
+
total = 0
|
|
374
|
+
high = 0
|
|
375
|
+
if isinstance(completion, dict):
|
|
376
|
+
try:
|
|
377
|
+
total = int(completion.get("assumptions_total") or 0)
|
|
378
|
+
except Exception:
|
|
379
|
+
total = 0
|
|
380
|
+
try:
|
|
381
|
+
high = int(completion.get("assumptions_high") or 0)
|
|
382
|
+
except Exception:
|
|
383
|
+
high = 0
|
|
384
|
+
if total > 0:
|
|
385
|
+
msg = ("Review %d assumption%s Loki had to make where your spec was "
|
|
386
|
+
"ambiguous" % (total, "" if total == 1 else "s"))
|
|
387
|
+
if high > 0:
|
|
388
|
+
msg += (" (%d of them high-impact)" % high)
|
|
389
|
+
msg += ". See .loki/assumptions/ledger.md."
|
|
390
|
+
items.append(msg)
|
|
391
|
+
|
|
392
|
+
# Anything not verified (degraded items) is also a to-do.
|
|
393
|
+
honesty = (proof or {}).get("honesty") or {}
|
|
394
|
+
degraded = honesty.get("degraded") or []
|
|
395
|
+
if isinstance(degraded, list) and degraded:
|
|
396
|
+
for d in degraded:
|
|
397
|
+
if isinstance(d, dict):
|
|
398
|
+
item = str(d.get("item") or "").strip()
|
|
399
|
+
reason = str(d.get("reason") or "").strip()
|
|
400
|
+
if item:
|
|
401
|
+
items.append("Address: %s%s"
|
|
402
|
+
% (item, (" (" + reason + ")") if reason else ""))
|
|
403
|
+
|
|
404
|
+
# PR state.
|
|
405
|
+
pr_url = ""
|
|
406
|
+
if isinstance(completion, dict):
|
|
407
|
+
pr_url = str(completion.get("pr_url") or "").strip()
|
|
408
|
+
if pr_url:
|
|
409
|
+
items.append("A pull request was opened: %s" % pr_url)
|
|
410
|
+
else:
|
|
411
|
+
items.append("No pull request was opened. Open one when you are ready to "
|
|
412
|
+
"merge the changes.")
|
|
413
|
+
|
|
414
|
+
# Deployment state.
|
|
415
|
+
deployment = (proof or {}).get("deployment") or {}
|
|
416
|
+
if not str(deployment.get("deployed_url") or "").strip():
|
|
417
|
+
items.append("It is not deployed yet. Use `loki deploy` when you are ready.")
|
|
418
|
+
|
|
419
|
+
for it in items:
|
|
420
|
+
lines.append("- %s" % it)
|
|
421
|
+
if not items:
|
|
422
|
+
lines.append("- Nothing outstanding was recorded. Read the sections above "
|
|
423
|
+
"to decide your next step.")
|
|
424
|
+
return lines
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
# ---------------------------------------------------------------------------
|
|
428
|
+
# top-level render
|
|
429
|
+
# ---------------------------------------------------------------------------
|
|
430
|
+
|
|
431
|
+
def _empty_doc_md(loki_dir):
|
|
432
|
+
return "\n".join([
|
|
433
|
+
"# What Loki built for you",
|
|
434
|
+
"",
|
|
435
|
+
"No completed build was found here yet.",
|
|
436
|
+
"",
|
|
437
|
+
"Run `loki start <spec>` to build something (a one-line idea, a PRD "
|
|
438
|
+
"file, or a GitHub issue all work). When it finishes, come back and run "
|
|
439
|
+
"`loki own` to read this plain-English summary of what you have.",
|
|
440
|
+
"",
|
|
441
|
+
])
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def _empty_doc_json(loki_dir):
|
|
445
|
+
return {
|
|
446
|
+
"ok": True,
|
|
447
|
+
"found": False,
|
|
448
|
+
"loki_dir": loki_dir,
|
|
449
|
+
"message": "No completed build found here yet -- run loki start <spec>",
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def render_markdown(loki_dir):
|
|
454
|
+
run_id, proof = _latest_proof(loki_dir)
|
|
455
|
+
if proof is None:
|
|
456
|
+
return _empty_doc_md(loki_dir)
|
|
457
|
+
|
|
458
|
+
completion = _read_json(os.path.join(loki_dir, "state", "completion.json"))
|
|
459
|
+
# USAGE.md lives at the project root (parent of .loki).
|
|
460
|
+
project_root = os.path.dirname(os.path.abspath(loki_dir)) or "."
|
|
461
|
+
usage_text = _read_text(os.path.join(project_root, "USAGE.md"))
|
|
462
|
+
live_url = _live_url(loki_dir)
|
|
463
|
+
|
|
464
|
+
blocks = [["# What Loki built for you", ""]]
|
|
465
|
+
blocks.append(_section_what_you_have(proof))
|
|
466
|
+
blocks.append(_section_is_it_working(proof, run_id))
|
|
467
|
+
blocks.append(_section_run_on_computer(proof, usage_text, live_url))
|
|
468
|
+
blocks.append(_section_put_online(proof))
|
|
469
|
+
blocks.append(_section_developer_needs(proof))
|
|
470
|
+
blocks.append(_section_verified(proof, run_id))
|
|
471
|
+
blocks.append(_section_still_to_do(proof, completion))
|
|
472
|
+
|
|
473
|
+
parts = []
|
|
474
|
+
for b in blocks:
|
|
475
|
+
parts.append("\n".join(b))
|
|
476
|
+
return "\n\n".join(parts) + "\n"
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def render_json(loki_dir):
|
|
480
|
+
run_id, proof = _latest_proof(loki_dir)
|
|
481
|
+
if proof is None:
|
|
482
|
+
return _empty_doc_json(loki_dir)
|
|
483
|
+
|
|
484
|
+
completion = _read_json(os.path.join(loki_dir, "state", "completion.json")) or {}
|
|
485
|
+
project_root = os.path.dirname(os.path.abspath(loki_dir)) or "."
|
|
486
|
+
usage_text = _read_text(os.path.join(project_root, "USAGE.md"))
|
|
487
|
+
live_url = _live_url(loki_dir)
|
|
488
|
+
|
|
489
|
+
honesty = proof.get("honesty") or {}
|
|
490
|
+
deployment = proof.get("deployment") or {}
|
|
491
|
+
facts = proof.get("facts") or {}
|
|
492
|
+
git = facts.get("git") or {}
|
|
493
|
+
diff = git.get("diff") or proof.get("files_changed") or {}
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
"ok": True,
|
|
497
|
+
"found": True,
|
|
498
|
+
"run_id": run_id,
|
|
499
|
+
"ready": _is_ready(proof),
|
|
500
|
+
"headline": str(honesty.get("headline") or ""),
|
|
501
|
+
"degraded": honesty.get("degraded") or [],
|
|
502
|
+
"spec_brief": str((proof.get("spec") or {}).get("brief") or ""),
|
|
503
|
+
"files_changed": {
|
|
504
|
+
"count": diff.get("count") or 0,
|
|
505
|
+
"insertions": diff.get("insertions") or 0,
|
|
506
|
+
"deletions": diff.get("deletions") or 0,
|
|
507
|
+
},
|
|
508
|
+
"live_url": live_url,
|
|
509
|
+
"deployed_url": str(deployment.get("deployed_url") or ""),
|
|
510
|
+
"start_command": _usage_section(usage_text, "Start"),
|
|
511
|
+
"verify_command": _usage_section(usage_text, "Verify"),
|
|
512
|
+
"pr_url": str(completion.get("pr_url") or ""),
|
|
513
|
+
"assumptions_total": completion.get("assumptions_total") or 0,
|
|
514
|
+
"assumptions_high": completion.get("assumptions_high") or 0,
|
|
515
|
+
"proof_show_cmd": ("loki proof show %s" % run_id) if run_id else "",
|
|
516
|
+
"proof_verify_cmd": ("loki proof verify %s" % run_id) if run_id else "",
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def main(argv=None):
|
|
521
|
+
parser = argparse.ArgumentParser(
|
|
522
|
+
description="Loki Mode finish-and-own renderer (plain-English ownership doc)"
|
|
523
|
+
)
|
|
524
|
+
parser.add_argument("--loki-dir", default=".loki")
|
|
525
|
+
fmt = parser.add_mutually_exclusive_group()
|
|
526
|
+
fmt.add_argument("--md", action="store_const", const="md", dest="fmt")
|
|
527
|
+
fmt.add_argument("--json", action="store_const", const="json", dest="fmt")
|
|
528
|
+
parser.set_defaults(fmt="md")
|
|
529
|
+
args = parser.parse_args(argv)
|
|
530
|
+
|
|
531
|
+
loki_dir = os.path.abspath(args.loki_dir)
|
|
532
|
+
try:
|
|
533
|
+
if args.fmt == "json":
|
|
534
|
+
print(json.dumps(render_json(loki_dir), indent=2))
|
|
535
|
+
else:
|
|
536
|
+
print(render_markdown(loki_dir))
|
|
537
|
+
except Exception as exc:
|
|
538
|
+
# This is a report, never a gate: emit an honest line and exit 0.
|
|
539
|
+
if args.fmt == "json":
|
|
540
|
+
print(json.dumps({"ok": False, "found": False, "error": str(exc)}))
|
|
541
|
+
else:
|
|
542
|
+
sys.stderr.write("warn: own-render failed: %s\n" % exc)
|
|
543
|
+
return 0
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
if __name__ == "__main__":
|
|
547
|
+
sys.exit(main())
|
|
@@ -253,6 +253,52 @@ def _collect_build(loki_dir):
|
|
|
253
253
|
return out
|
|
254
254
|
|
|
255
255
|
|
|
256
|
+
def _collect_security(loki_dir):
|
|
257
|
+
"""Read .loki/quality/security-findings.json (the secure-by-default gate).
|
|
258
|
+
|
|
259
|
+
Deterministic FACT (pattern scan, not an LLM opinion). Tolerates an absent
|
|
260
|
+
file -> status not_run. Counts only ACTIVE (un-waived) findings; HIGH active
|
|
261
|
+
findings are the gap signal. Shape:
|
|
262
|
+
{ran, total, active, waived, high_active, status, findings:[{rule,severity}]}.
|
|
263
|
+
status: not_run (no scan) | clean (ran, no active findings) | findings
|
|
264
|
+
(ran, active findings present).
|
|
265
|
+
"""
|
|
266
|
+
out = {
|
|
267
|
+
"ran": False, "total": 0, "active": 0, "waived": 0,
|
|
268
|
+
"high_active": 0, "status": "not_run", "findings": [],
|
|
269
|
+
}
|
|
270
|
+
raw = _read_json(
|
|
271
|
+
os.path.join(loki_dir, "quality", "security-findings.json"), default=None
|
|
272
|
+
)
|
|
273
|
+
if not isinstance(raw, dict):
|
|
274
|
+
return out
|
|
275
|
+
out["ran"] = True
|
|
276
|
+
findings = raw.get("findings") if isinstance(raw.get("findings"), list) else []
|
|
277
|
+
total = active = waived = high_active = 0
|
|
278
|
+
slim = []
|
|
279
|
+
for f in findings:
|
|
280
|
+
if not isinstance(f, dict):
|
|
281
|
+
continue
|
|
282
|
+
total += 1
|
|
283
|
+
is_waived = bool(f.get("waived"))
|
|
284
|
+
sev = str(f.get("severity") or "").upper()
|
|
285
|
+
if is_waived:
|
|
286
|
+
waived += 1
|
|
287
|
+
else:
|
|
288
|
+
active += 1
|
|
289
|
+
if sev == "HIGH":
|
|
290
|
+
high_active += 1
|
|
291
|
+
slim.append({"rule": str(f.get("rule") or ""), "severity": sev,
|
|
292
|
+
"waived": is_waived})
|
|
293
|
+
out["total"] = total
|
|
294
|
+
out["active"] = active
|
|
295
|
+
out["waived"] = waived
|
|
296
|
+
out["high_active"] = high_active
|
|
297
|
+
out["findings"] = slim
|
|
298
|
+
out["status"] = "findings" if active > 0 else "clean"
|
|
299
|
+
return out
|
|
300
|
+
|
|
301
|
+
|
|
256
302
|
def _norm_tests_status(raw):
|
|
257
303
|
"""Map a recorded test status to {verified,failed,inconclusive,not_run}.
|
|
258
304
|
|
|
@@ -578,6 +624,7 @@ def _build_proof(args, loki_dir, target_dir, repo_root):
|
|
|
578
624
|
|
|
579
625
|
build = _collect_build(loki_dir)
|
|
580
626
|
tests = _collect_tests(loki_dir)
|
|
627
|
+
security = _collect_security(loki_dir)
|
|
581
628
|
evidence_gate = _collect_evidence_gate(loki_dir)
|
|
582
629
|
|
|
583
630
|
deployed_url = os.environ.get("LOKI_DEPLOYED_URL") or None
|
|
@@ -611,6 +658,7 @@ def _build_proof(args, loki_dir, target_dir, repo_root):
|
|
|
611
658
|
{"name": g.get("name", ""), "status": g.get("status", "not_run")}
|
|
612
659
|
for g in (quality_gates.get("gates") or [])
|
|
613
660
|
],
|
|
661
|
+
"security": security,
|
|
614
662
|
"cost": cost,
|
|
615
663
|
"meta": {
|
|
616
664
|
"run_id": run_id,
|
|
@@ -711,6 +759,15 @@ def _compute_degraded(facts):
|
|
|
711
759
|
out.append({"item": "quality_gate:%s" % g.get("name", ""),
|
|
712
760
|
"status": g.get("status"),
|
|
713
761
|
"reason": "gate %s" % g.get("status")})
|
|
762
|
+
# Secure-by-default gate: an ACTIVE (un-waived) HIGH security finding is a gap
|
|
763
|
+
# in the proof of done -- the receipt must surface it, never green-wash an app
|
|
764
|
+
# that ships a known-bad pattern. Waived findings are NOT a gap (the user
|
|
765
|
+
# accepted them with intent, recorded in the receipt).
|
|
766
|
+
sec = facts.get("security") or {}
|
|
767
|
+
if sec.get("ran") and (sec.get("high_active") or 0) > 0:
|
|
768
|
+
out.append({"item": "security", "status": "findings",
|
|
769
|
+
"reason": "%s un-waived HIGH security finding(s)"
|
|
770
|
+
% sec.get("high_active")})
|
|
714
771
|
git = facts.get("git") or {}
|
|
715
772
|
if not (git.get("diff") or {}).get("count"):
|
|
716
773
|
out.append({"item": "git.diff", "status": "not_run",
|
|
@@ -736,11 +793,18 @@ def _compute_headline(facts, degraded):
|
|
|
736
793
|
# negative signal than a not-run one: amber means "we did not check
|
|
737
794
|
# everything", red means "something we checked did not pass". Conflating them
|
|
738
795
|
# would let a failed test render amber, which understates the failure.
|
|
796
|
+
# An ACTIVE (un-waived) HIGH security finding is a hard failure too: shipping a
|
|
797
|
+
# known-bad pattern (a committed private key, a world-open datastore) is not a
|
|
798
|
+
# "gap", it is a verified-NO. Waived findings do not count (accepted with
|
|
799
|
+
# intent). This keeps the receipt honest about security, not just tests.
|
|
800
|
+
sec = facts.get("security") or {}
|
|
801
|
+
sec_high = bool(sec.get("ran") and (sec.get("high_active") or 0) > 0)
|
|
739
802
|
any_failed = (
|
|
740
803
|
tests.get("status") == "failed"
|
|
741
804
|
or build.get("status") == "failed"
|
|
742
805
|
or any(g.get("status") == "failed"
|
|
743
806
|
for g in (facts.get("quality_gates") or []))
|
|
807
|
+
or sec_high
|
|
744
808
|
)
|
|
745
809
|
if any_failed:
|
|
746
810
|
return "NOT VERIFIED"
|