loki-mode 7.104.1 → 7.104.3

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.
@@ -0,0 +1,355 @@
1
+ # Dashboard Task-List Accuracy Fix Plan
2
+
3
+ Branch: fix/tasklist-accuracy
4
+ Worktree: /Users/lokesh/git/loki-tasklist-wt
5
+ Type: PATCH release (bug fix, no new features)
6
+ Status: Plan only. No implementation in this document.
7
+
8
+ ## 1. Summary
9
+
10
+ On a live run (~/git/anonima, loki start reusing a generated PRD) the dashboard
11
+ board at :57375/#section=overview shows:
12
+
13
+ - DONE column: 30 bare "Iteration N" cards with empty body (click -> empty modal).
14
+ - PENDING column: 12 rich PRD stories (prd-001..prd-012) that never move.
15
+ - IN-PROGRESS: iteration-13, which correctly borrows the active PRD story
16
+ title/description (intentional).
17
+
18
+ This plan verifies the mechanism against source, recommends an honesty-first
19
+ board model, lists the exact per-file change set with line references, gives a
20
+ test plan, and notes the patch-release steps.
21
+
22
+ ## 2. Verified root cause (against source + real data)
23
+
24
+ Reproduced by replaying the /api/tasks merge logic over the real
25
+ ~/git/anonima/.loki files. Rendered output shape:
26
+
27
+ - TOTAL 43 tasks: done=30, pending=12, in_progress=1.
28
+ - EMPTY-description done cards: 30 of 30.
29
+ - Duplicate ids in the output: iteration-1 x5, iteration-2 x3,
30
+ iteration-3..12 x2 each, iteration-13 x2 (appears in BOTH in_progress and
31
+ done). This is a distinct, second defect (see 2C).
32
+
33
+ There are four concrete defects.
34
+
35
+ ### 2A. Thin completed markers (primary defect -> empty done cards)
36
+
37
+ `track_iteration_start` (autonomy/run.sh:5370-5569) writes a RICH in-progress
38
+ record: it reads pending[0] for context (5395-5416) and emits a task with
39
+ id `iteration-N`, type `iteration`, a real title/description, acceptance_criteria,
40
+ notes, and a `logs` array (5462-5488, with fallbacks at 5499-5532 and
41
+ 5545-5568). `append_iteration_log` (5013-5072) appends further per-phase log
42
+ entries to that same in-progress record.
43
+
44
+ `track_iteration_complete` (autonomy/run.sh:6276-6455) writes the COMPLETED
45
+ marker with a hardcoded THIN body (6400-6411):
46
+
47
+ {
48
+ "id": "iteration-N",
49
+ "type": "iteration",
50
+ "title": "Iteration N",
51
+ "status": "completed"|"failed",
52
+ "completedAt": "...",
53
+ "exitCode": N,
54
+ "provider": "..."
55
+ }
56
+
57
+ No title-from-context, no description, no logs. It appends this to
58
+ completed.json/failed.json (6414-6429), then DELETES the rich in-progress
59
+ record (6431-6443). So the rich in-progress card becomes an empty done card,
60
+ and the logs that lived only in the in-progress record are discarded.
61
+
62
+ Confirmed data: ~/git/anonima/.loki/queue/completed.json items are all
63
+ `{"id":"iteration-N","title":"Iteration N","description":""...}`.
64
+
65
+ Key consequence for the fix: the body (logs/phase) exists ONLY in the
66
+ in-progress record at completion time. The API cannot recover it after run.sh
67
+ deletes it. run.sh MUST lift it before removal. This is why run.sh is the
68
+ required fix site for the card body, not the API.
69
+
70
+ ### 2B. PRD stories never reconcile pending -> done
71
+
72
+ PRD tasks are populated once into pending.json by the PRD parser
73
+ (autonomy/run.sh:15167-15213, ids `prd-001`..). Nothing ever pops or moves a
74
+ prd task out of pending: grep of every pending.json write site
75
+ (2625-2720 dedup, 2918-2938 GitHub sync read-only, 14663 openspec purge,
76
+ 14679 populate) shows no path that transitions a prd story to completed. The
77
+ RARV loop only READS pending[0] for iteration context (5403-5413); it never
78
+ mutates prd status. So the 12 stories sit in pending forever regardless of how
79
+ many iterations run.
80
+
81
+ Honesty check (decisive): ~/git/anonima/.loki/checklist/checklist.json has 19
82
+ items, ALL status `pending`; verification-results.json summary is
83
+ verified=0/failing=0/pending=19. Nothing in this run is verified-complete.
84
+ Auto-moving any prd story to done would be fake-green.
85
+
86
+ ### 2C. No intra-source dedup in /api/tasks (duplicate cards, broken keys)
87
+
88
+ dashboard/server.py /api/tasks (1772-1914) merges two sources:
89
+ 1. dashboard-state.json `.tasks` groups (1783-1825) mapped
90
+ pending->pending, inProgress->in_progress, completed->done, failed->done.
91
+ 2. queue/*.json files (1827-1881).
92
+
93
+ The queue merge skips ids already present (1854 `any(t["id"] == tid ...)`), but
94
+ there is NO dedup WITHIN the dashboard-state groups themselves, and no
95
+ cross-column dedup. The real dashboard-state completed group already contains
96
+ iteration-1 x5 and iteration-13 (which is ALSO in the inProgress group). Result:
97
+ the same id renders as multiple cards, and iteration-13 appears in both the
98
+ in-progress and done columns simultaneously. In the React board these become
99
+ duplicate `key={task.id}` / dnd-kit sortable ids (TaskCard.tsx:24), which is a
100
+ correctness bug (duplicate keys, unstable drag).
101
+
102
+ Root of the id collision: iteration ids are `iteration-N` and N resets/repeats
103
+ across sub-runs, and completed.json is capped with `data[-50:]` (run.sh:6426)
104
+ which retains stale duplicate-id entries rather than replacing by id.
105
+
106
+ ### 2D. iteration-13 leaks into completed while still in-progress
107
+
108
+ The completed group contains iteration-13 even though it is the active
109
+ in-progress card. Combined with 2C this is what puts one id in two columns.
110
+ The dedup fix (3C) resolves the display; the run.sh completed-writer dedup (3B)
111
+ resolves the source accumulation.
112
+
113
+ ## 3. Recommended board model (honesty-first)
114
+
115
+ Recommendation: Option A now; defer Option B as a scoped follow-up. Do NOT ship
116
+ Option B (or C) in this patch.
117
+
118
+ Rationale (honesty + accuracy):
119
+
120
+ - Iterations that ran are real events. Making their done cards honest and
121
+ informative is truthful and low-risk.
122
+ - LITERAL Option A is a trap and must be avoided: `track_iteration_start`
123
+ borrows pending[0] for the title, and because prd stories never leave pending
124
+ (2B), pending[0] is ALWAYS prd-001. Carrying that borrowed PRD title forward
125
+ onto every done card would render 13+ done cards all titled
126
+ "server.js (single backend module)", implying server.js was built and
127
+ completed 13 times, when the checklist says it was never verified. That is the
128
+ same fake-green we reject for Option B, spread across the done column. So the
129
+ corrected Option A carries forward the REAL, iteration-scoped parts (logs,
130
+ phase, exit code, duration) and keeps an iteration-scoped title
131
+ ("Iteration N complete - <phase>, exit 0"), NOT the borrowed PRD story title.
132
+ - Option B (reconcile prd pending -> done) requires a trustworthy per-story
133
+ completion signal. The only per-item truth signal is the checklist, keyed by
134
+ `be-001`/`api-001` item ids with NO stored `prd-NNN` link
135
+ (verified in checklist.json/verification-results.json). Mapping checklist ->
136
+ prd would require fuzzy title matching, which introduces inaccuracy
137
+ (mismatch -> fake-green or fake-red). Shipping a fuzzy reconciler in a patch
138
+ contradicts the high-accuracy mandate. On this run the correct verified signal
139
+ would move ZERO stories anyway (verified=0), so B delivers no value now and
140
+ carries real regression risk. Defer to a follow-up that either (a) stamps a
141
+ `prd-NNN` source id onto checklist items at generation time so the join is
142
+ exact, or (b) surfaces the checklist as its own honest progress panel instead
143
+ of mutating prd story status.
144
+
145
+ Net board after this patch: DONE shows honest iteration cards (informative
146
+ title + real logs, no empty modals); PENDING keeps the 12 prd stories
147
+ (truthful - none are verified-done); IN-PROGRESS shows the single active
148
+ iteration; no duplicate cards; no card in two columns.
149
+
150
+ ## 4. Exact change set (per file, with line refs)
151
+
152
+ All engine (run.sh) edits are additive/corrective to the task-record shape only.
153
+ No trust-gate, verdict, or completion-council logic is touched.
154
+
155
+ ### 4A. autonomy/run.sh - track_iteration_complete (6390-6444)
156
+
157
+ Change the completed-marker construction so it lifts the honest body from the
158
+ in-progress record BEFORE that record is removed.
159
+
160
+ - Before building task_json (currently 6400-6411), read the matching
161
+ `iteration-N` entry from in-progress.json (the file already read at 6432-6443
162
+ for removal). Capture its `logs`, `title`, `description`, `acceptance_criteria`,
163
+ `notes`, `startedAt`, `user_story`, `source`, `project` if present.
164
+ - Build the completed entry with:
165
+ - `title`: iteration-scoped and honest, e.g.
166
+ "Iteration N complete - <phase>" (exit 0) or
167
+ "Iteration N failed (exit <code>)" - derived from `$phase` (already computed
168
+ at 6355-6356) and `$exit_code`. Do NOT reuse the borrowed PRD story title
169
+ (see 3 rationale). If a truthful iteration description is wanted, synthesize
170
+ "Iteration N: <phase>, exit <code>, <duration>ms" from values already in
171
+ scope (`$phase`, `$exit_code`, `$duration_ms` at 6285).
172
+ - `logs`: the lifted logs array from the in-progress record (preserves the
173
+ real per-phase entries so the modal is populated).
174
+ - keep `type`, `status`, `completedAt`, `exitCode`, `provider` as today; add
175
+ `startedAt` (from in-progress) so the card can show duration.
176
+ - Do this with the same python-embedded approach already used at 6417-6429;
177
+ read in-progress inside that python block so it is atomic with the append.
178
+ - Dedup by id on write (see 4B) instead of blind append.
179
+
180
+ Keep the existing lock/atomic-write and the last-resort fallback shape so a
181
+ python-unavailable environment still writes a valid (if minimal) card.
182
+
183
+ ### 4B. autonomy/run.sh - completed.json/failed.json dedup on write (6417-6429)
184
+
185
+ Replace the blind `data.append(...)` + `data[-50:]` (6424-6426) with a
186
+ replace-by-id upsert: drop any existing entry with the same `id`, append the
187
+ new one, then cap at 50. This stops the cross-sub-run iteration-N accumulation
188
+ (iteration-1 x5) at the source. Failed.json (same writer, target chosen at
189
+ 6414-6415) gets the same upsert.
190
+
191
+ Note: also prevents an id being simultaneously in completed and failed (real
192
+ data has iteration-1 in both). Upsert-by-id in the chosen target plus removal
193
+ from the other target (add a small removal of `id` from the non-target file)
194
+ makes completed/failed mutually exclusive per id.
195
+
196
+ ### 4C. dashboard/server.py - /api/tasks global dedup (1780-1914)
197
+
198
+ Add a single global dedup pass keyed by id with column priority so one id yields
199
+ exactly one card, and it lands in the most-active column:
200
+
201
+ - Priority order: in_progress > review > pending > done. (in_progress beats done
202
+ so iteration-13-in-both resolves to the in-progress card; pending beats done
203
+ is irrelevant here but keeps a story that is both queued and archived in the
204
+ live column.)
205
+ - Implementation: keep a dict keyed by id while appending; when a duplicate id
206
+ arrives, keep the entry whose status has higher priority, and if equal
207
+ priority prefer the one with a non-empty description/logs (richer wins). Apply
208
+ this across BOTH the dashboard-state pass (1796-1823) and the queue pass
209
+ (1850-1879), replacing the current one-directional skip at 1854.
210
+ - Return `list(dict.values())` (or rebuild all_tasks from the dict) at 1906
211
+ before the project_id/status filters, preserving current ordering by
212
+ first-seen where possible.
213
+
214
+ Backward compatibility: the response is still a JSON array of the same
215
+ task-entry shape (same keys as today at 1808-1822 and 1856-1878). No field is
216
+ removed or renamed. Consumers see fewer/deduped items and populated
217
+ description/logs on done cards. This is strictly a correctness improvement to an
218
+ existing shape - compatible.
219
+
220
+ ### 4D. dashboard/frontend - defense-in-depth (optional, low risk)
221
+
222
+ The React TaskCard already guards empty description (TaskCard.tsx:129-133) and
223
+ renders title from `task.title` (124-126); the empty cards are a DATA problem
224
+ fixed by 4A/4C, so no functional SPA change is required. Optional hardening:
225
+
226
+ - TaskModal.tsx: when a task has neither description nor logs nor
227
+ acceptance_criteria, render an explicit honest placeholder
228
+ ("No details recorded for this iteration.") instead of an empty modal body.
229
+ This is a safety net for any legacy/thin records still on disk from before the
230
+ patch.
231
+ - No change to api.ts transformTask (api.ts:41-56) or types.ts is needed; the
232
+ status enum already covers done/in_progress/pending.
233
+
234
+ Prefer to include 4D TaskModal placeholder (small, defensive) but keep it out of
235
+ scope if the patch must be minimal - 4A/4C alone fix the reported bug.
236
+
237
+ ## 5. Dedup correctness argument
238
+
239
+ - Source (run.sh): 4B upsert-by-id makes completed.json / failed.json contain at
240
+ most one entry per iteration id, and mutual exclusion across the two files.
241
+ - API (server.py): 4C global id-dedup with column priority guarantees each id
242
+ appears in exactly one column. iteration-13 (currently in inProgress state
243
+ group AND completed queue) collapses to the in_progress card because
244
+ in_progress outranks done. The 5x iteration-1 collapses to one done card.
245
+ - Result on the anonima fixture: 43 -> ~26 unique cards (12 pending + 1
246
+ in_progress + ~13 unique iteration done cards), zero duplicate ids, zero
247
+ cross-column duplication, zero empty-body done cards.
248
+
249
+ ## 6. Test plan
250
+
251
+ ### 6A. pytest for /api/tasks (primary)
252
+
253
+ Add a test module under the dashboard test suite (co-locate with existing
254
+ server/API tests; confirm the exact dir during implementation, e.g.
255
+ dashboard/tests/ or tests/). Build a fixture .loki dir mirroring anonima:
256
+
257
+ - dashboard-state.json .tasks with: pending = 12 prd-NNN rich stories;
258
+ inProgress = [iteration-13 rich, borrowed prd title]; completed = duplicate
259
+ iteration-1..13 thin markers INCLUDING iteration-13 (to reproduce cross-column
260
+ leak); failed = [iteration-14 thin, iteration-1 thin].
261
+ - queue/completed.json + queue/pending.json mirroring the same.
262
+
263
+ Assertions:
264
+ 1. No done-column card has an empty title AND empty description AND empty logs
265
+ (no empty modal payloads). After the fix, done iteration cards carry logs.
266
+ 2. Every returned id is unique (len(ids) == len(set(ids))).
267
+ 3. iteration-13 appears exactly once, with status in_progress (column-priority
268
+ rule).
269
+ 4. All 12 prd-NNN remain in pending (no fake-green: none promoted to done).
270
+ 5. Counts: done has one card per unique completed/failed iteration id; no
271
+ duplicates.
272
+ 6. Backward-compat: response is a list; each entry still has id/title/
273
+ description/status/priority/type keys.
274
+
275
+ Add a focused unit-style test for the dedup helper (column-priority + richer-
276
+ wins) if it is factored into a function.
277
+
278
+ ### 6B. run.sh completed-writer test (shell/behavioral)
279
+
280
+ If the shell test harness supports it (see scripts/local-ci.sh 14/14 dual-route
281
+ suite), add a case that: seeds an in-progress.json with a rich iteration-N record
282
+ (title/desc/logs), calls track_iteration_complete N 0, then asserts the resulting
283
+ completed.json entry (a) has a non-empty logs array carried from in-progress,
284
+ (b) has an honest iteration-scoped title (not "Iteration N" empty-body, not the
285
+ borrowed PRD story title), and (c) contains no duplicate id after two calls with
286
+ the same N (upsert). Keep it provider-agnostic and offline.
287
+
288
+ ### 6C. Playwright screenshot of the board
289
+
290
+ Capture :57375/#section=overview against the fixture-backed dashboard (or the
291
+ anonima state) after the fix: assert the DONE column cards show titles + preview
292
+ text (not bare "Iteration N"), clicking a done card opens a populated modal, and
293
+ no card ID is visually duplicated across columns. Store under
294
+ artifacts/<release>-screens/ per CLAUDE.md:227.
295
+
296
+ ## 7. Disjoint build lanes
297
+
298
+ Two independent lanes (can be done in parallel, no shared edit region):
299
+
300
+ - Lane 1 (engine): autonomy/run.sh 6390-6444 (completed writer + upsert). Owner
301
+ must respect: additive/corrective to record shape only; no trust/verdict/
302
+ council logic; no version bump/commit; no emoji/em-dash.
303
+ - Lane 2 (dashboard): dashboard/server.py /api/tasks 1780-1914 (global dedup) +
304
+ optional dashboard/frontend TaskModal.tsx placeholder.
305
+
306
+ Lane 3 (tests, after 1+2): pytest fixture (6A), optional shell test (6B),
307
+ Playwright shot (6C).
308
+
309
+ Sequencing: Lane 1 and Lane 2 are independent and each independently improves
310
+ the board; the API dedup (Lane 2) also protects against any not-yet-fixed thin
311
+ records, so it can ship even if Lane 1 slips. Tests depend on both.
312
+
313
+ ## 8. Patch release steps (per CLAUDE.md)
314
+
315
+ - Version: current 7.104.1 (VERSION, package.json, CLAUDE.md:306, SKILL.md
316
+ header+footer, plugins/loki-mode/.claude-plugin/plugin.json, wiki/Home.md,
317
+ wiki/_Sidebar.md, docs/INSTALLATION.md - grep "7.104.1" for the full set).
318
+ Bump PATCH -> 7.104.2 in ALL of these (CLAUDE.md:301 mandates header AND footer
319
+ for SKILL.md).
320
+ - CHANGELOG.md: add a new "## [7.104.2] - <date>" section above 7.104.1 with a
321
+ fix entry describing honest iteration done cards + /api/tasks dedup + no
322
+ fake-green prd promotion. (Currently "## [Unreleased]" is "(none)".)
323
+ - Pre-push gate (MANDATORY, CLAUDE.md:318-330): run
324
+ `bash scripts/local-ci.sh` on this Mac; do not push if it says DO NOT PUSH.
325
+ - Commit protocol (CLAUDE.md:290-296): show git diff --stat, stage files
326
+ individually by name (never git add -A), STOP and wait for user approval
327
+ before commit. This plan does not commit.
328
+ - Post-release distribution validation (CLAUDE.md:332-334): npm pack + Docker
329
+ pull smoke of the shipped version.
330
+
331
+ ## 9. Open questions
332
+
333
+ 1. Done-card title wording: "Iteration N complete - <phase>" vs
334
+ "Iteration N: <phase>, exit 0, <duration>ms". Pick the clearest; both avoid
335
+ the borrowed PRD title. Founder preference?
336
+ 2. Should failed iterations render in the done column (current mapping
337
+ failed->done) or a distinct failed column? Out of scope for this patch;
338
+ current behavior preserved. Note for follow-up.
339
+ 3. Follow-up (Option B) design: stamp `prd-NNN` source id onto checklist items
340
+ at generation so checklist->story is an exact join, versus surfacing the
341
+ checklist as a separate honest progress panel. Decide before building B.
342
+ 4. Exact dashboard test directory + whether a shell harness case for
343
+ track_iteration_complete is supported by scripts/local-ci.sh - confirm at
344
+ implementation time.
345
+ 5. Should the API dedup also collapse the stale duplicate ids already persisted
346
+ in old on-disk state (one-time migration), or is display-time dedup
347
+ sufficient? Recommend display-time only (no destructive migration in a patch).
348
+
349
+ ## 10. Critical files for implementation
350
+
351
+ - /Users/lokesh/git/loki-tasklist-wt/autonomy/run.sh (track_iteration_complete 6276-6455; track_iteration_start 5370-5569; append_iteration_log 5013-5072; write_dashboard_state 5078-5118)
352
+ - /Users/lokesh/git/loki-tasklist-wt/dashboard/server.py (/api/tasks 1772-1914)
353
+ - /Users/lokesh/git/loki-tasklist-wt/dashboard/frontend/src/components/TaskModal.tsx (optional empty-body placeholder)
354
+ - /Users/lokesh/git/loki-tasklist-wt/CHANGELOG.md (patch entry)
355
+ - /Users/lokesh/git/loki-tasklist-wt/VERSION and package.json (patch bump; plus SKILL.md/CLAUDE.md/plugin.json version strings)