@markus-global/cli 0.12.4 → 0.12.5-rc.1
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/dist/background-maintenance.d.ts +25 -0
- package/dist/background-maintenance.d.ts.map +1 -1
- package/dist/background-maintenance.js +61 -0
- package/dist/background-maintenance.js.map +1 -1
- package/dist/commands/im-inbound-origin.d.ts +38 -0
- package/dist/commands/im-inbound-origin.d.ts.map +1 -0
- package/dist/commands/im-inbound-origin.js +48 -0
- package/dist/commands/im-inbound-origin.js.map +1 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +211 -46
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +18520 -9886
- package/dist/web-ui/assets/{AsyncState-BTLUPIr1.js → AsyncState-fJJNUOXK.js} +1 -1
- package/dist/web-ui/assets/ChatComponents-S7d2CAAU.js +14 -0
- package/dist/web-ui/assets/{ContentRenderer-BZXRiKE3.js → ContentRenderer-DWqhC0uq.js} +6 -6
- package/dist/web-ui/assets/DeliverableShareModal-B7DwzEnt.js +1 -0
- package/dist/web-ui/assets/{Deliverables-3Y3zjT_1.js → Deliverables-CueBYYpx.js} +2 -2
- package/dist/web-ui/assets/MarkdownMessage-D8BsJzvD.js +4 -0
- package/dist/web-ui/assets/{Search-BI3hk-5j.js → Search-CaYXz3u-.js} +1 -1
- package/dist/web-ui/assets/{SendToChat-D_5zHO-k.js → SendToChat-_9sm7UBY.js} +1 -1
- package/dist/web-ui/assets/Settings-DTL14pY8.js +8 -0
- package/dist/web-ui/assets/{Store-B8ksRjHF.js → Store-DpGqUMS2.js} +1 -1
- package/dist/web-ui/assets/Switch-NYQTn8wl.js +1 -0
- package/dist/web-ui/assets/Team-DB-JytPl.js +93 -0
- package/dist/web-ui/assets/Work-sQq-gy3S.js +142 -0
- package/dist/web-ui/assets/{arc-VmvI7TpW.js → arc-JtkmqkSR.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CTUtPasm.js → architectureDiagram-3BPJPVTR-B8zM5fky.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-xeYAqtZJ.js → blockDiagram-GPEHLZMM-BQgjaOcE.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BiFgoGY5.js → c4Diagram-AAUBKEIU-BnZvYRwj.js} +1 -1
- package/dist/web-ui/assets/channel-Zno2q8Ba.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-DueHBqOn.js → chunk-2J33WTMH-KONx1qvt.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-B8zgDfSV.js → chunk-4BX2VUAB-BqkxAkWs.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-DieD55CP.js → chunk-55IACEB6-DxLiTj85.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-Do4Z9LQ0.js → chunk-727SXJPM-Dhj-9NIs.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-qrYsW5ml.js → chunk-AQP2D5EJ-M1vQ4YYc.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BSz3QT1q.js → chunk-FMBD7UC4-DaXv58SH.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-utDWSydt.js → chunk-ND2GUHAM-Brkz9FCu.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-Cd86CYHV.js → chunk-QZHKN3VN-DIsEGiBf.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-hI59DDUw.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-hI59DDUw.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-Dc6cP9WW.js → cose-bilkent-S5V4N54A-CSjC_YL5.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-4b0Wf_6D.js → dagre-BM42HDAG-BevSxaQN.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-zS_j1Kf4.js → diagram-2AECGRRQ-CT3Hj8jy.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-CPo-_Ime.js → diagram-5GNKFQAL-CAebHy6q.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-CjHOA4_j.js → diagram-KO2AKTUF-BvRWS7BX.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-CalZRF6K.js → diagram-LMA3HP47-gR9HBKc4.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-DnLAhsLX.js → diagram-OG6HWLK6-B5HGsfNo.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-uRVPnxwM.js → docx-preview-pRjmDg6F.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-L0nzlMSn.js → erDiagram-TEJ5UH35-mrPW01aQ.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-Bdc3UwtW.js → flowDiagram-I6XJVG4X-BrZ1G-Tt.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CFRmj_qc.js → ganttDiagram-6RSMTGT7-Dq_5mate.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-B5hZwcoJ.js → gitGraphDiagram-PVQCEYII-Cb3yTWUy.js} +1 -1
- package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
- package/dist/web-ui/assets/index-Bco6UnT7.js +867 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DVT4RgPd.js → infoDiagram-5YYISTIA-CcnNlnvs.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-Bf7pvUY_.js → ishikawaDiagram-YF4QCWOH-BqHTPtO1.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-NVRjJlnd.js → journeyDiagram-JHISSGLW-DKBB9B-C.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Co7BKMut.js → kanban-definition-UN3LZRKU-BVO5tbNl.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-CCf28Hq6.js → mermaid.core-bMoKRCj4.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-DepMhVEb.js → mindmap-definition-RKZ34NQL-Bk0lFKmi.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-Cq9ANaI0.js → pieDiagram-4H26LBE5-BRPnBLeL.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CUY0BWhQ.js → quadrantDiagram-W4KKPZXB-CAqdqT5W.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-D9fU5rCm.js → requirementDiagram-4Y6WPE33-Vv5YNzCu.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CMHhuSQF.js → sankeyDiagram-5OEKKPKP-Ciq1EgmQ.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-Bjx53SID.js → sequenceDiagram-3UESZ5HK-DVRqp161.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DVvatKnO.js → stateDiagram-AJRCARHV-zbjDSKA3.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C54VSYn7.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-9I80LG9m.js → timeline-definition-PNZ67QCA-D0hr0d1U.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-B82Deutq.js → vennDiagram-CIIHVFJN-CtuZLcPo.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BKXtp57W.js → wardley-L42UT6IY-nP2-eCDJ.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DzqTzfYa.js → wardleyDiagram-YWT4CUSO-Dxc7OveP.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-TowyDWYu.js → xychartDiagram-2RQKCTM6-Bm2LvPhZ.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +50 -16
- package/docs/api/guides/websocket.md +43 -0
- package/docs/api/reference.md +657 -0
- package/docs/architecture/a2a-communication.md +303 -0
- package/docs/architecture/agent-runtime.md +145 -28
- package/docs/architecture/architecture.md +30 -11
- package/docs/architecture/cognitive-architecture.md +189 -15
- package/docs/architecture/concurrent-processing.md +190 -31
- package/docs/architecture/context-assembly.md +264 -0
- package/docs/architecture/derived-views.md +463 -0
- package/docs/architecture/desktop-auto-update.md +185 -0
- package/docs/architecture/facts.md +406 -0
- package/docs/architecture/learning-loop.md +11 -0
- package/docs/architecture/limits.md +79 -0
- package/docs/architecture/mailbox-system.md +786 -668
- package/docs/architecture/memory-system.md +1 -1
- package/docs/architecture/messaging-gateway.md +7 -0
- package/docs/architecture/notification-delivery.md +221 -0
- package/docs/architecture/notification-sounds.md +177 -0
- package/docs/architecture/prompt-engineering.md +171 -700
- package/docs/{design/remote-access-contract.md → architecture/remote-access.md} +4 -0
- package/docs/architecture/state-machines.md +288 -5
- package/docs/architecture/tool-loop-harness.md +362 -0
- package/docs/architecture/tool-system.md +40 -16
- package/docs/design/background-callback-in-turn-delivery-2026-11-22.md +95 -0
- package/docs/design/c10-0b-pick-identity-leak-2026-11-22.md +233 -0
- package/docs/design/c10-a-identity-columns-2026-11-22.md +182 -0
- package/docs/design/c10-c-trust-boundary-2026-11-23.md +222 -0
- package/docs/design/c10-external-adapters-plan-2026-11-19.md +448 -0
- package/docs/design/c8-residual-mechanisms-2026-11-15.md +984 -0
- package/docs/design/external-signal-decision-loop-2026-11-25.md +579 -0
- package/docs/guides/development.md +1 -1
- package/docs/{architecture → guides}/mailbox-audit-checklist.md +7 -0
- package/docs/guides/remote-access.md +1 -1
- package/docs/{design/agent-stop-intent-audit.md → records/agent-stop-intent-audit-2026-11-08.md} +4 -0
- package/docs/records/c10-l5-gate-verification-2026-11-26.md +72 -0
- package/docs/records/c10-l5-live-verification-2026-11-25.md +117 -0
- package/docs/records/cut6-c4-verification-2026-11-12.md +268 -0
- package/docs/records/cut6-mailbox-address-envelope-design-2026-11-12.md +871 -0
- package/docs/records/cut7-c7a-red-green-evidence-2026-11-13.md +105 -0
- package/docs/records/cut7-c7a-workunit-implementation-2026-11-13.md +116 -0
- package/docs/records/cut7-c7b-verification-2026-11-14.md +90 -0
- package/docs/records/cut7-live-verification-2026-11-14.md +33 -0
- package/docs/records/cut7-wiring-negative-cache-2026-11-14.md +64 -0
- package/docs/records/cut7-workunit-execution-plan-2026-11-13.md +206 -0
- package/docs/records/cut8-a-entity-keys-design-2026-11-14.md +377 -0
- package/docs/records/cut8-b-turn-delta-injection-2026-11-14.md +362 -0
- package/docs/records/cut8-c-single-clock-2026-11-14.md +119 -0
- package/docs/records/cut8-c-single-clock-design-2026-11-14.md +150 -0
- package/docs/records/cut8-d-2026-11-14.md +231 -0
- package/docs/records/cut8-live-verification-2026-11-14.md +1018 -0
- package/docs/records/cut9-adjacent-identity-paths-2026-11-15.md +200 -0
- package/docs/records/cut9-identity-declaration-2026-11-15.md +163 -0
- package/docs/records/cut9-inbox-dual-run-diff-2026-11-15.md +117 -0
- package/docs/records/cut9-live-verification-2026-11-15.md +222 -0
- package/docs/records/cut9-runtime-probe-2026-11-19.md +520 -0
- package/docs/{design/deliverable-sharing.md → records/deliverable-sharing-2026-08-12.md} +10 -3
- package/docs/records/identity-backlog-disposition-2026-11-22.md +143 -0
- package/docs/records/marketplace-orphan-freeze-2026-11-22.md +239 -0
- package/docs/{architecture/notify-user-context-truth.md → records/notify-user-context-truth-2026-10-28.md} +6 -0
- package/docs/{handoff → records}/remote-access-handoff.md +1 -1
- package/package.json +1 -1
- package/templates/roles/HANDBOOK.md +1 -1
- package/templates/skills/agent-building/SKILL.md +1 -1
- package/dist/web-ui/assets/ChatComponents-DTB3H_n2.js +0 -12
- package/dist/web-ui/assets/DeliverableShareModal-BwZP39nd.js +0 -1
- package/dist/web-ui/assets/MarkdownMessage-DVfFMzM9.js +0 -4
- package/dist/web-ui/assets/Settings-DTUjLhJY.js +0 -8
- package/dist/web-ui/assets/Switch-RmZHA47D.js +0 -1
- package/dist/web-ui/assets/Team-BRgI1zM9.js +0 -85
- package/dist/web-ui/assets/Work-nah0UYFz.js +0 -142
- package/dist/web-ui/assets/channel-s7K3KXLr.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-B2mHhFY8.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-B2mHhFY8.js +0 -1
- package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
- package/dist/web-ui/assets/index-TPf50ZeO.js +0 -867
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-92MmE2MZ.js +0 -1
- package/docs/api/api.md +0 -353
- package/docs/architecture/llm-provider-timeouts.md +0 -60
- package/docs/architecture/state-ownership.md +0 -83
- /package/docs/architecture/{frontend/team-chat.md → team-chat.md} +0 -0
- /package/docs/{analysis → records}/2026-10-29-a2a-cache-hit-rate.md +0 -0
- /package/docs/{fixes → records}/2026-11-12-session-expiry-and-mention-thinking.md +0 -0
- /package/docs/{handoff → records}/approval-tri-state-handoff.md +0 -0
- /package/docs/{design → records}/overview-attention-redesign.md +0 -0
- /package/docs/{remote-access/fast-path-plan.md → records/remote-access-fast-path-plan-2026-10-17.md} +0 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
# Derived views (C9) — thread stage, inbox, observation tables
|
|
2
|
+
|
|
3
|
+
> **Single authority.** 本文件是 C9 派生视图的单一权威,2026-11-15 由 `thread-stage.md`、
|
|
4
|
+
> `inbox-derivation.md` 与 `observability-tables.md` 合并而来(原因:三者都是「从事实派生出来的
|
|
5
|
+
> 视图」,同一类契约分开维护会生出多个派生点、多个读侧)。
|
|
6
|
+
>
|
|
7
|
+
> All three parts answer the same shape of question — **what may be derived from the facts, and
|
|
8
|
+
> who is allowed to derive it** — so they are one document:
|
|
9
|
+
>
|
|
10
|
+
> - **Part I** — thread stage (C9-C): the badge that answers "who is this thread waiting for".
|
|
11
|
+
> - **Part II** — inbox derivation (C9-D): the list that answers "what must a human do now".
|
|
12
|
+
> - **Part III** — observation tables (C9-B): the four append-mostly logs, and the single source
|
|
13
|
+
> of "is this agent running".
|
|
14
|
+
>
|
|
15
|
+
> Section numbers run continuously (1-17) so no two sections of this file share an anchor: both
|
|
16
|
+
> derivation parts legitimately own a section called "One derivation, one reader".
|
|
17
|
+
>
|
|
18
|
+
> The fact layer itself — the row contract and its verification mechanism — is
|
|
19
|
+
> [`facts.md`](./facts.md). Every view here derives from it, never the other way round; a view
|
|
20
|
+
> that wrote back would be a second writer of the fact it summarizes.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Part I — thread stage (C9-C)
|
|
25
|
+
|
|
26
|
+
`ThreadStage` answers exactly one question: **who is this thread waiting for right now.**
|
|
27
|
+
It is not the governance state (`TaskStatus`, which is persisted) and not the runtime
|
|
28
|
+
attention state (`AttentionState`, which is in-memory). Three concepts, three
|
|
29
|
+
vocabularies, no shared literals — the front-end test asserts that mechanically.
|
|
30
|
+
|
|
31
|
+
The facts write path and the independent verifier are C9-A / C9-E (see [`facts.md`](./facts.md));
|
|
32
|
+
the inbox derivation is Part II of this file.
|
|
33
|
+
|
|
34
|
+
### 1. The closed set
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
waiting_human | running | needs_evidence | in_verification | done | blocked_deps | failed
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Declared once in `packages/core/src/facts/derive-stage.ts` (`THREAD_STAGES`) and mirrored
|
|
41
|
+
once for the UI in `packages/web-ui/src/lib/threadStage.ts`. The two lists are compared by
|
|
42
|
+
`scripts/architecture-guard.mjs` (`thread-stage-closed-set`), so a stage added on one side
|
|
43
|
+
and forgotten on the other is a CI failure, not a blank badge in production.
|
|
44
|
+
|
|
45
|
+
`saved` as free text is impossible by construction: the function's return type is the union,
|
|
46
|
+
and every boundary between the server and the UI passes through `isThreadStage()` /
|
|
47
|
+
`asThreadStage()`. A value the reader does not understand renders **nothing** — the UI never
|
|
48
|
+
invents a stage.
|
|
49
|
+
|
|
50
|
+
### 2. One derivation, one reader
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
packages/core/src/facts/derive-stage.ts deriveStage({fsm, facts, approvals}) — pure
|
|
54
|
+
packages/org-manager/src/thread-stage.ts the only place that turns rows into that input
|
|
55
|
+
packages/org-manager/src/routes/tasks.ts GET /api/tasks/:id returns { threadStage, evidence }
|
|
56
|
+
packages/web-ui/src/components/ThreadStage.tsx renders the value, never re-derives it
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Why the UI does not re-derive: the previous generation of this knowledge lived in four
|
|
60
|
+
components that each assembled "what is going on" from whatever they had loaded. Four
|
|
61
|
+
writers, one fact, four answers — and the most consequential one ("is it running?") was
|
|
62
|
+
derived from *whether a message existed*, which is why a stopped agent kept showing as busy
|
|
63
|
+
(C8-E). Re-deriving in the browser would bring that back; the page now renders a value.
|
|
64
|
+
|
|
65
|
+
### 3. Precedence (first match wins)
|
|
66
|
+
|
|
67
|
+
| # | Stage | Structural source |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| 1 | `failed` | FSM row `failed` / `rejected` |
|
|
70
|
+
| 2 | `waiting_human` | a pending approval/question row; FSM `pending` (awaiting approval); FSM `blocked` + `blocked_reason='hold'` |
|
|
71
|
+
| 3 | `done` | FSM `cancelled` / `archived` — closed without claiming success |
|
|
72
|
+
| 4 | `blocked_deps` | an open dependency id (resolved by the caller); or FSM `blocked` when nobody resolved the graph |
|
|
73
|
+
| 5 | `running` | a `work_units` row in `running`; or FSM `in_progress` |
|
|
74
|
+
| 6 | `needs_evidence` | no active `task.completion_evidence` fact |
|
|
75
|
+
| 7 | `in_verification` | evidence exists, no independent `pass` |
|
|
76
|
+
| 8 | `done` | evidence + independent `pass` |
|
|
77
|
+
|
|
78
|
+
Two rules carry the weight:
|
|
79
|
+
|
|
80
|
+
- **No branch reads traffic.** The input has no message/notice/timestamp channel at all, so
|
|
81
|
+
"it must be running because things are happening" cannot be expressed.
|
|
82
|
+
- **Only an independent `pass` produces `done`** for a success terminal. `verification.result
|
|
83
|
+
=== 'fail'` and a self-verification both land in `in_verification` — a disproven claim is an
|
|
84
|
+
unevidenced claim, and the reader must not be told otherwise.
|
|
85
|
+
|
|
86
|
+
Deliberate decisions worth reviewing:
|
|
87
|
+
|
|
88
|
+
- **`running` from the FSM row.** A WorkUnit count of zero proves nothing (a turn boundary is
|
|
89
|
+
not a state change), so absence never demotes. `in_progress` is a structural row, not
|
|
90
|
+
silence, and is a legitimate source under the C9 rule ("every cell traces to a fact or an
|
|
91
|
+
FSM row").
|
|
92
|
+
- **`cancelled` / `archived` → `done`.** They are terminal but never claimed success, so there
|
|
93
|
+
is no claim to verify. Mapping them to `failed` would label a deliberate cancellation as a
|
|
94
|
+
failure. The invariant "`done` ⇒ pass" is therefore stated for the *success* terminals
|
|
95
|
+
(`review`, `completed`) and tested as such.
|
|
96
|
+
- **A human-declared `hold` is `waiting_human`.** `blocked_reason` is already the single
|
|
97
|
+
discriminator for "why is this blocked" (`web-ui/src/lib/blockedReason.ts`); reusing it is
|
|
98
|
+
not a second writer, it is reading the existing one. Rendering a hold as `blocked_deps`
|
|
99
|
+
would tell the reader to wait for an engine that will never move.
|
|
100
|
+
- **An explicit dependency resolution beats the coarse flag.** If the caller resolved the
|
|
101
|
+
graph and found nothing open, a task still flagged `blocked` is an engine anomaly — saying
|
|
102
|
+
"waiting on deps" would point at work that already finished.
|
|
103
|
+
|
|
104
|
+
### 4. Facts that do not participate
|
|
105
|
+
|
|
106
|
+
Superseded rows (`superseded_by` / `superseded_at` present) are ignored: history cannot keep
|
|
107
|
+
a thread `done`. Among current rows the newest `created_at` wins, ties broken by id, so two
|
|
108
|
+
calls on the same set always agree (no clock, no unstable sort).
|
|
109
|
+
|
|
110
|
+
### 5. UI surface (what a human is allowed to see)
|
|
111
|
+
|
|
112
|
+
| Human question | Derived from | Where |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| What do I need to do | `deriveInbox()` (C9-D, §7) | Home |
|
|
115
|
+
| Where is this, who is it waiting for | `deriveStage()` | task/requirement detail badge |
|
|
116
|
+
| Why do we believe it is done | `facts.source_refs` | detail page evidence fold (collapsed by default) |
|
|
117
|
+
|
|
118
|
+
Asserting one fact may change exactly two things on screen: a stage label and an inbox item.
|
|
119
|
+
A "fact card" appearing in the UI means internal state leaked to the user.
|
|
120
|
+
|
|
121
|
+
The evidence fold never prints the fact's raw JSON. It shows `value.summary`, who asserted it,
|
|
122
|
+
the verification result, and clickable pointers: `dlv_…` opens the deliverable, comment ids
|
|
123
|
+
scroll to the activity section in place, anything else stays a labelled reference.
|
|
124
|
+
|
|
125
|
+
### 6. Verification
|
|
126
|
+
|
|
127
|
+
| Claim | Proof |
|
|
128
|
+
|---|---|
|
|
129
|
+
| zero IO / zero clock / zero randomness | `packages/core/test/derive-stage.test.ts` — no repo is mocked anywhere in the file, and two cases run with `Date.now`/`Math.random` replaced by throwing stubs |
|
|
130
|
+
| seven stages, positive and negative | same file, one `describe` per stage plus a totality matrix over 9 statuses × 5 reasons × 4 fact shapes × 2 human states × 2 WorkUnit counts × 2 dependency states |
|
|
131
|
+
| breaking the verification rule turns red | mutate `independentPass` to accept `fail`, the `in_verification` case goes red (verified while developing) |
|
|
132
|
+
| evidence → stage on the real writer | `packages/org-manager/test/thread-stage.test.ts` — real SQLite + `SqliteFactService`: assert → `in_verification`, add pass → `done`, supersede → back, self-verification rejected |
|
|
133
|
+
| the badge text follows the value | `packages/web-ui/src/components/ThreadStage.test.tsx` — DOM level: `needs_evidence → in_verification → done → in_verification` |
|
|
134
|
+
| no second vocabulary | `packages/web-ui/src/lib/threadStage.test.ts` — `crossVocabularyCollisions()` over stage / task-status / process labels in `en` and `zh-CN` |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Part II — inbox derivation (C9-D)
|
|
139
|
+
|
|
140
|
+
`deriveInbox()` answers exactly one question: **what does a human have to do right now, and where
|
|
141
|
+
do they do it.** It is a pure function. It does not persist anything — a stored inbox is a second
|
|
142
|
+
copy of the truth and would immediately drift from the four sources it summarizes.
|
|
143
|
+
|
|
144
|
+
The facts write path and the independent verifier are C9-A / C9-E (see [`facts.md`](./facts.md));
|
|
145
|
+
the stage badge it corroborates rows with is C9-C (Part I of this file).
|
|
146
|
+
|
|
147
|
+
### 7. One derivation, one reader
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
packages/web-ui/src/lib/deriveInbox.ts deriveInbox(snapshot, ports) — pure, zero IO
|
|
151
|
+
packages/web-ui/src/lib/attentionQueue.ts presentation adapter: api rows → snapshot, items → rows
|
|
152
|
+
packages/web-ui/src/pages/Home.tsx renders the adapter's output; assembles nothing
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Why it lives in `web-ui` and not in `packages/shared`** (measured, not assumed): the browser
|
|
156
|
+
bundle cannot import `@markus/shared` — it is absent from `packages/web-ui/package.json`, there is
|
|
157
|
+
no vite alias and no tsconfig `paths`, and twelve existing files record the same constraint
|
|
158
|
+
(`allowedTransitions.ts`, `providers.ts`, `mailboxStatusFilters.ts`, `mailboxTypeMeta.ts`, …). The
|
|
159
|
+
repo's habit in that situation is a hand-written mirror plus a test that keeps the two copies in
|
|
160
|
+
step — acceptable for a three-item constant (`thread-stage`), absolutely not for a derivation:
|
|
161
|
+
two copies of this algorithm *is* the second writer this cut exists to remove. So the single
|
|
162
|
+
implementation sits where its readers are, and when a server/mobile consumer appears it moves
|
|
163
|
+
whole (one file move, or one build alias) — never a split.
|
|
164
|
+
|
|
165
|
+
Before this cut the "what needs me" list was assembled inside `Home.tsx` (`:511-549` of the
|
|
166
|
+
2026-11-15 base commit): four sources — `approvals`, `user_notifications`, the task/requirement
|
|
167
|
+
FSM, and the board — were each turned into rows in the page body, with page-local dedupe. That
|
|
168
|
+
extraction already happened (2026-11-10, `lib/attentionQueue.ts`), so the *inline* copy was gone by
|
|
169
|
+
the time C9-D started; what remained was a **second decider**: `buildAttentionQueue` owned
|
|
170
|
+
membership, dedupe and precedence, and would have to stay in lock-step with any future derivation
|
|
171
|
+
(a server-side board, a mobile client, a CLI). C9-D moves every one of those decisions into
|
|
172
|
+
`deriveInbox()`; the web-ui file keeps only what is genuinely UI (i18n titles, route params of an
|
|
173
|
+
existing single discriminator, `NotificationInfo` objects for "mark read").
|
|
174
|
+
|
|
175
|
+
The `inbox-single-derivation` invariant in `scripts/architecture-guard.mjs` fails CI when a
|
|
176
|
+
membership keyword (`'pending'`, `'review'`, `dedupeKey`, an entity→row map) reappears in the
|
|
177
|
+
adapter, or when the drop rule disappears from the derivation. Both directions have self-test
|
|
178
|
+
fixtures.
|
|
179
|
+
|
|
180
|
+
### 8. Identity: `subjectKind:subjectId:needKind`
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
dedupeKey = `${subjectKind}:${subjectId}:${needKind}`
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- `subjectKind` — the closed set `task | requirement | approval | notification`. `notification`
|
|
187
|
+
means "the message itself is the object": two unrelated messages must never collapse into one
|
|
188
|
+
row, because a row standing for three messages is a row nobody can act on.
|
|
189
|
+
- `needKind` — the closed set, in precedence order:
|
|
190
|
+
|
|
191
|
+
| # | need | what the human must do | `blocking` |
|
|
192
|
+
|---|---|---|---|
|
|
193
|
+
| 1 | `answer` | answer a blocking question (`request_user_input`) | yes |
|
|
194
|
+
| 2 | `approve` | approve / reject a request | yes |
|
|
195
|
+
| 3 | `review` | accept a finished task (reviewer is human) | yes |
|
|
196
|
+
| 4 | `resolve_failure` | re-dispatch or abandon a failed task | no |
|
|
197
|
+
| 5 | `unblock` | a declared `hold` — was parking it still intended? | yes |
|
|
198
|
+
| 6 | `read` | informational (unread message) | no |
|
|
199
|
+
|
|
200
|
+
Three sources pointing at the **same** subject and need produce **one** row, with every
|
|
201
|
+
contributing source kept in `sources[]` — that is the "why is this here" answer, and it is what
|
|
202
|
+
lets one click mark several notifications read.
|
|
203
|
+
|
|
204
|
+
The key is **necessary, not sufficient**. Rows are then folded per `subjectKind:subjectId`
|
|
205
|
+
(`foldBySubject`), keeping the highest-precedence need and recording the rest in `mergedNeeds`.
|
|
206
|
+
Reason: a list is scanned by object, not by verb — "task t1: answer" and "task t1: review" both end
|
|
207
|
+
on the same page with one obvious next action, and showing them twice is the defect the Owner
|
|
208
|
+
reported on 2026-11-10 ("两条内容重复"). The fold is visible, never silent: `mergedNeeds` and
|
|
209
|
+
`sources` name what was absorbed. Different subjects never fold — an over-aggressive dedupe that
|
|
210
|
+
swallows unrelated work is worse than a duplicate.
|
|
211
|
+
|
|
212
|
+
### 9. `action` and `blocking` are mandatory
|
|
213
|
+
|
|
214
|
+
Every row carries `action: { page, params }` — the concrete route that *resolves* the need, not a
|
|
215
|
+
description of it. `ports.resolveNotificationTarget` (the existing `notifyNavigate.notificationTarget`)
|
|
216
|
+
and the approval's `details.{taskId,requirementId}` / `agentId` are the only sources of a
|
|
217
|
+
destination.
|
|
218
|
+
|
|
219
|
+
**A row with no destination is dropped** (`if (!action) continue`). "A red light nobody can act
|
|
220
|
+
on is worse than no light": a system broadcast with no entity, an approval whose agent is gone,
|
|
221
|
+
a `creditExhausted` modal hook — none of these belong in a to-do list, because clicking them
|
|
222
|
+
lands the user on a page where nothing can be done. The drop is counted, not swallowed: the
|
|
223
|
+
derivation returns `dropped[]` (`{ source, ref, reason: 'no_action' }`) so the dual-run diff and
|
|
224
|
+
the audit page can prove what is being withheld.
|
|
225
|
+
|
|
226
|
+
`blocking` is a property of the **need**, not a per-row heuristic (`NEED_BLOCKING`): a question
|
|
227
|
+
blocks the agent's whole turn, an approval blocks the requested action, a human review blocks
|
|
228
|
+
completion, a `hold` blocks the task; a failure or a message blocks no named party. `foldBySubject`
|
|
229
|
+
ORs the flag, so folding can only ever *reveal* blocking, never hide it.
|
|
230
|
+
|
|
231
|
+
### 10. Purity
|
|
232
|
+
|
|
233
|
+
No IO, no `Date.now()`, no `Math.random()`, no `process.env`, no repo, no fetch. Time enters only
|
|
234
|
+
as data (`waitingSince`, `lastSeenAt`); the only clock-dependent output is `isNew`, computed by
|
|
235
|
+
string comparison against a caller-supplied timestamp. Two calls on the same snapshot return
|
|
236
|
+
byte-identical output, whatever the wall clock says — `packages/shared/test/derive-inbox.test.ts`
|
|
237
|
+
runs one case with `Date.now`/`Math.random` replaced by throwing stubs, and no test in the file
|
|
238
|
+
mocks a repo (there is nothing to mock).
|
|
239
|
+
|
|
240
|
+
Sorting is a contract, not an implementation detail: longest wait first, then priority, then need
|
|
241
|
+
precedence, then key. All four are total orders over data, so the list never reshuffles between
|
|
242
|
+
two renders of the same state.
|
|
243
|
+
|
|
244
|
+
### 11. Inputs
|
|
245
|
+
|
|
246
|
+
`InboxSnapshot` = normalized rows of the four sources. Rows are structural (they mirror the API
|
|
247
|
+
shapes) so the caller passes what it already has:
|
|
248
|
+
|
|
249
|
+
| channel | fields read | why |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `approvals` | `status`, `title`, `requestedAt`, `agentName`, `agentId`, `questions`, `details.{taskId,requirementId}` | pending approvals ARE human needs |
|
|
252
|
+
| `notifications` | `read`, `createdAt`, `priority`, `title`, `metadata`, `actionType/actionTarget` (via port) | unread messages, and the *duplicate* of an FSM/approval row. **A notification never raises a need** — its need is always `read`; the state comes from the row that owns it. Mapping `type = 'task_review'` → need `review` invented three blocking reviews for already-`completed` tasks on the first run over live data (`records/cut9-inbox-dual-run-diff-2026-11-15.md` §3.4) |
|
|
253
|
+
| `tasks` | `status`, `reviewerType`, `blockedReason`, `priority`, `statusChangedAt`, `updatedAt`, `createdAt` | review / hold / failed |
|
|
254
|
+
| `requirements` | `status`, `priority`, `createdAt` | requirement approval |
|
|
255
|
+
| `stages` | `subjectKind`, `subjectId`, `stage` | facts-derived stage (C9-C, §3): `failed` → `resolve_failure`, `waiting_human` → `answer`. They corroborate a row rather than invent one, so a stage can never create a row without a destination. |
|
|
256
|
+
|
|
257
|
+
`ports` are **required** named functions, not optional defaults: an omitted `resolveNotificationTarget`
|
|
258
|
+
would silently make every notification undeliverable (and every row disappear), which is the
|
|
259
|
+
"optional injection silently becomes the root" defect recorded in the C9 playbook.
|
|
260
|
+
|
|
261
|
+
### 12. What is deliberately not here
|
|
262
|
+
|
|
263
|
+
- No inbox table, no read-state of its own (`notifications.read` stays the only read flag).
|
|
264
|
+
- No approval FSM changes, no historical notification migration.
|
|
265
|
+
- No runtime `legacy | derive` switch. A switch would keep the old assembly alive in the shipped
|
|
266
|
+
bundle — i.e. two live deciders again, which is the defect this cut removes. The dual run is a
|
|
267
|
+
**build-time** artifact (§13) and rollback is `git revert` of one commit (or `INBOX_DERIVATION`
|
|
268
|
+
is deliberately not a thing).
|
|
269
|
+
|
|
270
|
+
### 13. Verification
|
|
271
|
+
|
|
272
|
+
| Claim | Proof |
|
|
273
|
+
|---|---|
|
|
274
|
+
| three sources, one subject, one need ⇒ one row | `packages/shared/test/derive-inbox.test.ts` (`describe('dedupe')`) |
|
|
275
|
+
| three sources, three subjects ⇒ three rows (no over-dedupe) | same file, negative case that fails if `foldBySubject` keys on anything but the subject |
|
|
276
|
+
| no `action` ⇒ dropped, and the drop is recorded | same file; delete the `if (!action) continue` line and the case turns red (verified while developing) |
|
|
277
|
+
| zero IO / zero clock / zero randomness | same file: no repo is mocked anywhere, and one case throws from `Date.now`/`Math.random` |
|
|
278
|
+
| the adapter no longer decides membership | `scripts/architecture-guard.mjs` → `inbox-single-derivation` (fixtures included) |
|
|
279
|
+
| the rendered list matches the old queue on real data | `scripts/inbox-dual-run.mjs` → `docs/records/cut9-inbox-dual-run-diff-2026-11-15.md` (read-only on `~/.markus/data.db`) |
|
|
280
|
+
| the badge never double-counts | `actionableCount()` keeps excluding `read`; unread stays merged in `lib/attentionCount` |
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Part III — observation tables and the single source of "running" (C9-B)
|
|
285
|
+
|
|
286
|
+
Part III is canonical for two questions that used to be answered by whatever code happened to be
|
|
287
|
+
nearby:
|
|
288
|
+
|
|
289
|
+
1. **What are the four observation tables, and what does each row mean?**
|
|
290
|
+
2. **Who is allowed to answer "is this agent working right now"?**
|
|
291
|
+
|
|
292
|
+
The short answer to (2) is: `work_units` — and nothing else. An observation table
|
|
293
|
+
records *what happened*; it never carries state.
|
|
294
|
+
|
|
295
|
+
### 14. The four observation tables
|
|
296
|
+
|
|
297
|
+
They are append-mostly event logs: they answer "what happened to this agent / this
|
|
298
|
+
task, and when". Before cut 9 they also silently carried a second, weaker answer to
|
|
299
|
+
"is it still running" (an unfinished row), because no code could ask `work_units`.
|
|
300
|
+
That second answer is now removed — see §16. Since C10-0E `agent_activities` is
|
|
301
|
+
**strictly append-only** (a database trigger rejects any rewrite, §15.1); the other
|
|
302
|
+
three remain append-mostly.
|
|
303
|
+
|
|
304
|
+
| Table | One row is | Volume at cut 9 (live DB) | `work_unit_ref` |
|
|
305
|
+
|---|---|---|---|
|
|
306
|
+
| `agent_activities` | one activity (a turn's execution: chat / task / review / heartbeat), written once at start; end/correction data arrives as `activity_end` events in `agent_activity_logs` and is derived on read (§15.1) | ~250k | nullable, indexed |
|
|
307
|
+
| `agent_activity_logs` | one log line *inside* an activity (`status` / `text` / `tool_start` / `tool_end` / `llm_request` / `error`), ordered by `seq` | ~3.8M | nullable, indexed |
|
|
308
|
+
| `execution_stream_logs` | the unified execution stream: the same kind of log line, but keyed by `(source_type, source_id)` so `task` / `activity` / `chat` streams share one read face | ~4.5M | nullable, indexed |
|
|
309
|
+
| `task_logs` | one persisted task log line, grouped by `execution_round` | ~0.5M | nullable, indexed |
|
|
310
|
+
|
|
311
|
+
Notes that are contracts, not trivia:
|
|
312
|
+
|
|
313
|
+
- **`work_unit_ref` is nullable and is not backfilled.** ~9M historical rows keep
|
|
314
|
+
`NULL`. `NULL` means "this row predates the identity chain (cut 7)" — it is a
|
|
315
|
+
legal value, not a defect. Backfilling would manufacture a second history of
|
|
316
|
+
which turn produced which row, and no reader could tell it from the real one.
|
|
317
|
+
- **`work_unit_ref` is derived, never inferred.** It is written from the identity
|
|
318
|
+
the producer already holds (`Agent.currentTurnWorkUnitRef`, sourced from
|
|
319
|
+
`mailbox_items.work_unit_ref`; or `WORK_UNIT_REF.task(taskId, round)` in
|
|
320
|
+
`TaskService`). It is *never* recovered by looking up "the nearest WorkUnit in
|
|
321
|
+
time" — that would be inferring structure from timing.
|
|
322
|
+
- **`agent_activity_logs` inherits the ref from its activity.** A log line cannot
|
|
323
|
+
belong to a different WorkUnit than the activity that emitted it, so the row is
|
|
324
|
+
written with `(SELECT work_unit_ref FROM agent_activities WHERE id = ?)`. One
|
|
325
|
+
writer, no drift, no second derivation.
|
|
326
|
+
- **The migration is additive only** (`ALTER TABLE ... ADD COLUMN` + `CREATE INDEX
|
|
327
|
+
IF NOT EXISTS`), guarded by `PRAGMA table_info` in
|
|
328
|
+
`packages/storage/src/sqlite-storage.ts`. Re-opening an old database adds the
|
|
329
|
+
columns once and never rebuilds the table. Since C10-0E the same idempotent,
|
|
330
|
+
additive category also carries the append-only trigger and the `activity_end`
|
|
331
|
+
partial index (§15.1) — DDL only; no data row is ever touched.
|
|
332
|
+
|
|
333
|
+
### 15. What a row does *not* mean
|
|
334
|
+
|
|
335
|
+
`agent_activities.ended_at IS NULL` does **not** mean "still running". It means
|
|
336
|
+
"no end was recorded for this row". Two independent reasons:
|
|
337
|
+
|
|
338
|
+
1. A process can die between `insertActivity` and the end callback. The row is then
|
|
339
|
+
permanently unfinished, and nothing will ever close it.
|
|
340
|
+
2. `ended_at` is duration data about an event. Process liveness is a different
|
|
341
|
+
question with a different owner.
|
|
342
|
+
|
|
343
|
+
Consequently there is no "close the orphans" sweeper any more. There used to be one
|
|
344
|
+
(`SqliteActivityRepo.closeOrphansAgainstTerminalMailbox()`): it rewrote `ended_at`
|
|
345
|
+
on zombie rows so that "unfinished" would become trustworthy as a liveness signal.
|
|
346
|
+
It was a second writer of a fact that only exists to prop up a wrong reading. It is
|
|
347
|
+
deleted — if a row has no end, the row has no end.
|
|
348
|
+
|
|
349
|
+
Since C10-0E the base `ended_at` column is **never written at all** (§15.1): new
|
|
350
|
+
rows keep it NULL forever, and the derived `endedAt` comes from the latest
|
|
351
|
+
`activity_end` event. The reading above is unchanged — unfinished ≠ running — and
|
|
352
|
+
applies to the derived value just the same.
|
|
353
|
+
|
|
354
|
+
### 15.1 Append-only: a correction is a new row (C10-0E)
|
|
355
|
+
|
|
356
|
+
An `agent_activities` row is written **once** (`insertActivity`) and never
|
|
357
|
+
rewritten. "What happened" had a second writer — the old `updateActivity` path
|
|
358
|
+
could rewrite history, and no reader could tell original from tampered. It is
|
|
359
|
+
deleted. The contract now:
|
|
360
|
+
|
|
361
|
+
- **The end of an activity (and any correction to it) is a new `activity_end`
|
|
362
|
+
event row** in `agent_activity_logs`, written by
|
|
363
|
+
`SqliteActivityRepo.appendActivityEnd`. The payload (`endedAt`, `totalTokens`,
|
|
364
|
+
`totalTools`, `success`, `summary`, `keywords`) lives in the event's `metadata`
|
|
365
|
+
(inline JSON — never blob-projected, because the derivation reads it with
|
|
366
|
+
`json_extract`). `seq` and `work_unit_ref` are derived by subquery, exactly like
|
|
367
|
+
every other log line: one writer per fact, no second derivation.
|
|
368
|
+
- **Readers derive the current view.** `ACTIVITY_CURRENT_SELECT` — one definition
|
|
369
|
+
in `packages/storage/src/sqlite-storage.ts` — LEFT JOINs the latest
|
|
370
|
+
`activity_end` event per activity and COALESCEs each mutable field over the base
|
|
371
|
+
row. Every read face (`queryActivities` / `getActivity` / `getByMailboxItemId(s)`
|
|
372
|
+
/ `searchActivities`) wraps that single derivation. Latest event wins: the same
|
|
373
|
+
last-wins semantics the old UPDATE path had, except history keeps every version.
|
|
374
|
+
- **Legacy rows are untouched.** Rows written before C10-0E carry end data on the
|
|
375
|
+
row itself and have no end event; the COALESCE falls back to the base values, so
|
|
376
|
+
the derivation is the identity for them. No migration touches them (verified:
|
|
377
|
+
dual-run of every read face over a live-DB snapshot, byte-identical output).
|
|
378
|
+
- **Enforcement is structural, two layers.** A `BEFORE UPDATE` trigger
|
|
379
|
+
(`agent_activities_no_update`, created idempotently on open) raises on any
|
|
380
|
+
rewrite; the architecture-guard rule `activities-append-only` forbids UPDATE /
|
|
381
|
+
OR REPLACE / OR IGNORE / ON CONFLICT DO UPDATE paths in `packages/*/src` and
|
|
382
|
+
`scripts/`. Behavior test:
|
|
383
|
+
`packages/storage/test/c10-0e-activities-append-only.test.ts` — delete the
|
|
384
|
+
trigger or the derivation and it goes red.
|
|
385
|
+
|
|
386
|
+
### 16. The single source of "running"
|
|
387
|
+
|
|
388
|
+
**Answer only from `work_units`:**
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
work_units.status = 'running'
|
|
392
|
+
AND claimed_by IS NOT NULL -- somebody actually holds it
|
|
393
|
+
AND lease_until > now -- and the lease has not expired
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
- The read face is `GET /api/agents/:id/work-units?status=running`
|
|
397
|
+
(`packages/org-manager/src/api-server.ts`), which applies the lease filter once,
|
|
398
|
+
server-side.
|
|
399
|
+
- The UI component is `RunningWorkUnits` (`packages/web-ui/src/components/RunningWorkUnits.tsx`).
|
|
400
|
+
It shows internal turns (`requirement_*` / `channel_*` / `session:*`) as well as
|
|
401
|
+
user-visible chat turns — "I am working but the page is empty" was the bug.
|
|
402
|
+
- `work_status()` is the agent-facing read of the same table.
|
|
403
|
+
|
|
404
|
+
Forbidden sources of "running" (each of these was, at some point, in production):
|
|
405
|
+
|
|
406
|
+
| Forbidden source | Why it lies |
|
|
407
|
+
|---|---|
|
|
408
|
+
| `agent_activities.ended_at IS NULL` | unfinished ≠ running (§15) |
|
|
409
|
+
| In-memory `activeStreams` / `activeTaskCount` | resets on restart; empty after a crash |
|
|
410
|
+
| "the last message was recent" | intensity of traffic is not execution state |
|
|
411
|
+
|
|
412
|
+
#### 16.1 How an activity list may still show liveness
|
|
413
|
+
|
|
414
|
+
It may **not** decide liveness itself. An activity row is history. If a list needs a
|
|
415
|
+
live marker, it takes the set of live WorkUnit refs from the `work_units` read face
|
|
416
|
+
and asks the pure function
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
isActivityLive(activity, liveWorkUnitRefs) // packages/web-ui/src/lib/workUnitLiveness.ts
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
which answers `true` only when the row carries a `workUnitRef` that is present in
|
|
423
|
+
that set. A row without a ref (all historical rows) is history, full stop.
|
|
424
|
+
|
|
425
|
+
#### 16.2 Enforcement
|
|
426
|
+
|
|
427
|
+
`node scripts/architecture-guard.mjs` fails the build if either side of this contract
|
|
428
|
+
is reintroduced:
|
|
429
|
+
|
|
430
|
+
- a read path in `packages/web-ui/src` that derives liveness from a missing
|
|
431
|
+
`endedAt` (`!x.endedAt`, `x.endedAt == null`, …);
|
|
432
|
+
- SQL in `packages/*/src` **or `scripts/`** that reads `agent_activities` /
|
|
433
|
+
`agent_activity_logs` state from `ended_at IS NULL`, or re-introduces an
|
|
434
|
+
orphan-closing sweep;
|
|
435
|
+
- `activities-append-only` (C10-0E): any UPDATE / OR REPLACE / OR IGNORE /
|
|
436
|
+
ON CONFLICT DO UPDATE path targeting `agent_activities` (§15.1);
|
|
437
|
+
- `no-orphan-marketplace` (C10-0C): any source read/write path for the frozen
|
|
438
|
+
orphan tables `marketplace_templates` / `marketplace_skills`. The Owner verdict
|
|
439
|
+
(2026-11-19: no migration, no DROP) and the verbatim 3-row archive live in
|
|
440
|
+
`docs/records/marketplace-orphan-freeze-2026-11-22.md` — a frozen snapshot, the
|
|
441
|
+
live DB is the authority.
|
|
442
|
+
|
|
443
|
+
The scan covers the whole repo, not just the UI: the same mistake is just as wrong in
|
|
444
|
+
a service, a CLI command, or an operations script. `scripts/` is not a product source
|
|
445
|
+
root, but the path invariants (`no-activity-liveness`, `activities-append-only`,
|
|
446
|
+
`no-orphan-marketplace`) scan it too, with no allowlist exemption — an invariant
|
|
447
|
+
that can hide outside the scan roots is not an invariant.
|
|
448
|
+
|
|
449
|
+
`scripts/identity-audit.mjs` used to carry a fifth gate for "trigger row terminal but
|
|
450
|
+
`ended_at` still empty". It is **gone** with the sweep that kept it satisfied: a row
|
|
451
|
+
without an end is "we did not record an end", not a violation, and with no time bound
|
|
452
|
+
it could only stay permanently red on the ~3k historical rows. The underlying fact —
|
|
453
|
+
"a turn closed but left work hanging" — is measured on the authoritative object by the
|
|
454
|
+
lease-expired `running` gate.
|
|
455
|
+
|
|
456
|
+
### 17. Scope boundaries
|
|
457
|
+
|
|
458
|
+
- **Not here**: `facts` and its `FactService` writer (the row contract and its verification
|
|
459
|
+
mechanism are [`facts.md`](./facts.md)), `agent_decisions.work_unit_ref`, board / inbox
|
|
460
|
+
persistence (the inbox derivation is Part II of this file, §7-§13). This part covers the four
|
|
461
|
+
observation tables only.
|
|
462
|
+
- **Not here**: the `work_units` schema and lifecycle. See
|
|
463
|
+
[state-machines.md §16](./state-machines.md).
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Desktop auto-update
|
|
2
|
+
|
|
3
|
+
How the Markus desktop app detects, downloads and installs a new version on each
|
|
4
|
+
platform, and what must be true for a release to be installable.
|
|
5
|
+
|
|
6
|
+
This is the authoritative document for the update path. If code and this page
|
|
7
|
+
disagree, the code wins and this page gets a PR in the same change (see
|
|
8
|
+
[docs/README.md](../README.md)).
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. Ownership: one writer per surface
|
|
13
|
+
|
|
14
|
+
| Surface | Who decides "there is an update" | Who installs it |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| Packaged desktop app (dmg / exe / AppImage) | `packages/desktop/src/updater.ts` (single writer of `UpdateState`) | `electron-updater` (`autoUpdater.quitAndInstall`) |
|
|
17
|
+
| MAS build | Apple App Store | App Store |
|
|
18
|
+
| Browser / LAN access to the server | `/health.updateAvailable` (npm registry version of `@markus-global/cli`) | nobody — the banner links to the website |
|
|
19
|
+
|
|
20
|
+
Two rules make that table hold:
|
|
21
|
+
|
|
22
|
+
1. **No second caller of `electron-updater`.** `ipc-handlers.ts` and `menu.ts`
|
|
23
|
+
only call `updater.ts` (`checkForUpdatesNow`, `getUpdateState`,
|
|
24
|
+
`installUpdateNow`). A direct `import('electron-updater')` anywhere else is a
|
|
25
|
+
regression: it bypasses the state machine, the MAS/unpackaged guards, and the
|
|
26
|
+
renderer notification.
|
|
27
|
+
2. **The website-link banner is a fallback, not a parallel truth.**
|
|
28
|
+
`web-ui`'s `UpdateNotice` renders the native lifecycle; the legacy banner in
|
|
29
|
+
`App.tsx` is gated behind `!hasDesktopUpdater()`, so a desktop user never sees
|
|
30
|
+
"download from the website" while a real installer is available.
|
|
31
|
+
|
|
32
|
+
### State machine
|
|
33
|
+
|
|
34
|
+
`packages/desktop/src/update-policy.ts` (pure, unit-tested) defines:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
idle ──checking──▶ checking ──available──▶ downloading ──progress──▶ downloading
|
|
38
|
+
│
|
|
39
|
+
└──downloaded──▶ ready (terminal until installed)
|
|
40
|
+
any ──error──▶ error ──checking──▶ checking ready is NEVER downgraded by error/not-available
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`ready` being terminal is deliberate: a transient network failure after a
|
|
44
|
+
successful download must not hide an update the user could install right now.
|
|
45
|
+
|
|
46
|
+
### Scheduling
|
|
47
|
+
|
|
48
|
+
- First check 10 s after launch, then every 4 h (`BASE_CHECK_INTERVAL_MS`).
|
|
49
|
+
- On consecutive failures the interval doubles, capped at 24 h
|
|
50
|
+
(`nextCheckIntervalMs`). A permanently broken feed must not retry at full rate
|
|
51
|
+
forever.
|
|
52
|
+
- The timer is `unref()`ed — polling never keeps the process alive.
|
|
53
|
+
|
|
54
|
+
### Install policy
|
|
55
|
+
|
|
56
|
+
- `autoDownload = true`, `autoInstallOnAppQuit = true`: download in the
|
|
57
|
+
background, apply on quit.
|
|
58
|
+
- The user can apply immediately via the "Restart to update" button (→
|
|
59
|
+
`installUpdateNow()` → `quitAndInstall(false, true)`).
|
|
60
|
+
- `MARKUS_UPDATE_DEBUG=1` logs every transition and forwards electron-updater's
|
|
61
|
+
own logger to the console. This is the only supported way to diagnose
|
|
62
|
+
"the update never arrives" on a user's machine.
|
|
63
|
+
- Errors are **not** shown to the user as a banner; a background check that fails
|
|
64
|
+
must not nag. They are logged, and the next check clears the state.
|
|
65
|
+
|
|
66
|
+
### Platform support matrix
|
|
67
|
+
|
|
68
|
+
`resolveUpdaterSupport()` in `update-policy.ts` is the single decision point. It
|
|
69
|
+
returns a **reason** when it says no, so the log explains itself:
|
|
70
|
+
|
|
71
|
+
| Platform / mode | Runs? | Why |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| macOS, packaged, non-MAS | yes | Squirrel.Mac + `latest-mac.yml` |
|
|
74
|
+
| Windows, packaged | yes | `NsisUpdater` + `latest.yml` |
|
|
75
|
+
| Linux, packaged, launched from an AppImage | yes | `AppImageUpdater` (needs `$APPIMAGE`) |
|
|
76
|
+
| Linux, packaged, deb/rpm install | **no** (`no-appimage-env`) | nothing writable to replace in place |
|
|
77
|
+
| MAS build | **no** (`mas`) | App Store owns updates |
|
|
78
|
+
| Unpackaged (`electron .`) | **no** (`unpackaged`) | no `app-update.yml` feed → ENOENT |
|
|
79
|
+
|
|
80
|
+
### Release channel: stable vs prerelease
|
|
81
|
+
|
|
82
|
+
`shouldFollowPrereleaseChannel(app.getVersion())` sets `autoUpdater.allowPrerelease`:
|
|
83
|
+
|
|
84
|
+
- version contains `-` (e.g. `0.12.5-rc.0`) → follow prereleases, so an installed
|
|
85
|
+
candidate can see the next candidate (`rc.0` → `rc.1`).
|
|
86
|
+
- stable version → `releases/latest` only. **This is what stops an rc from being
|
|
87
|
+
pushed to every user**, and it is also why a stable install will never offer an
|
|
88
|
+
rc: GitHub's `latest` endpoint excludes prereleases.
|
|
89
|
+
|
|
90
|
+
Consequence worth remembering when testing a candidate: an installed **stable**
|
|
91
|
+
build cannot see an rc. To exercise the update chain on a candidate you must
|
|
92
|
+
install `rc.N` by hand once, then publish `rc.N+1`.
|
|
93
|
+
|
|
94
|
+
## 2. Platform requirements
|
|
95
|
+
|
|
96
|
+
### macOS
|
|
97
|
+
|
|
98
|
+
- **The feed must point at a `.zip`.** `MacUpdater` calls
|
|
99
|
+
`findFile(files, "zip", ["pkg", "dmg"])` and throws
|
|
100
|
+
`ERR_UPDATER_ZIP_FILE_NOT_FOUND` otherwise. `dmg` alone is not installable —
|
|
101
|
+
this was the actual state of the v0.12.4 feed.
|
|
102
|
+
- **Both architectures must be in one `latest-mac.yml`.** `MacUpdater` filters
|
|
103
|
+
entries by arch (`filterFilesForArch`): arm64 Macs prefer arm64 entries, Intel
|
|
104
|
+
Macs exclude them. An arm64-only feed is a dead end for Intel users. Hence
|
|
105
|
+
**one** CI job builds `--mac --arm64 --x64`; two jobs would each write the same
|
|
106
|
+
filename and the last upload would win.
|
|
107
|
+
- **Developer ID signature + notarization.** Squirrel.Mac rejects a bundle whose
|
|
108
|
+
identity does not match the running app; Gatekeeper blocks an un-notarized
|
|
109
|
+
replacement. `electron-builder.yml` sets `hardenedRuntime: true` and
|
|
110
|
+
`notarize: true`; `scripts/verify-mac-artifacts.sh --require-developer-id`
|
|
111
|
+
enforces the result on every release.
|
|
112
|
+
- **The app must live in `/Applications`.** A bundle run from the mounted DMG is
|
|
113
|
+
translocated and cannot be swapped. The updater detects this
|
|
114
|
+
(`app.isInApplicationsFolder()`) and the UI asks the user to move the app
|
|
115
|
+
instead of offering a button that would fail.
|
|
116
|
+
- MAS builds never self-update (`shouldStartUpdater` → `isMas` guard) —
|
|
117
|
+
Guideline 2.4.5.
|
|
118
|
+
|
|
119
|
+
### Windows
|
|
120
|
+
|
|
121
|
+
- `latest.yml` + NSIS installer + `.blockmap` for differential download.
|
|
122
|
+
- `oneClick: false` does **not** disable auto-update: electron-updater invokes the
|
|
123
|
+
assisted installer with `/S` (silent). Per-user install (`perMachine: false`)
|
|
124
|
+
means no UAC prompt.
|
|
125
|
+
- The running `.exe` cannot be replaced, so install happens after process exit.
|
|
126
|
+
- Gate: `node scripts/verify-update-feed.mjs --platform win` — the feed must name
|
|
127
|
+
an `.exe` and that `.exe`'s `.blockmap` must exist (missing blockmap still
|
|
128
|
+
works, but every update becomes a ~100 MB full download instead of a delta).
|
|
129
|
+
|
|
130
|
+
### Linux
|
|
131
|
+
|
|
132
|
+
- AppImage only: `latest-linux.yml` + in-place replacement of the file named by
|
|
133
|
+
`$APPIMAGE`. Started from anywhere else (deb/rpm/tar.gz) the updater reports
|
|
134
|
+
`no-appimage-env` and does nothing — by design, not a silent failure.
|
|
135
|
+
- deb/rpm distribution is the package manager's job; the app must not self-elevate.
|
|
136
|
+
- Gate: `node scripts/verify-update-feed.mjs --platform linux` — the feed must
|
|
137
|
+
name an `.AppImage`.
|
|
138
|
+
|
|
139
|
+
### 3. Release gate
|
|
140
|
+
|
|
141
|
+
`scripts/verify-update-feed.mjs` reads the **build output**, not the config, and
|
|
142
|
+
fails on every failure mode above. It covers all three platforms:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
node scripts/verify-update-feed.mjs --platform mac|win|linux|all
|
|
146
|
+
scripts/verify-mac-artifacts.sh [--require-developer-id|--require-notarized] # mac extras
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Checks: per-platform artifact selectable (zip per arch / exe + blockmap /
|
|
150
|
+
AppImage), version matches the packaged version, sha512 + size matching the files
|
|
151
|
+
on disk; on mac additionally 2 DMGs + 2 ZIPs, per-arch `lipo`, `codesign
|
|
152
|
+
--verify`, and optionally Gatekeeper + stapled-ticket validation.
|
|
153
|
+
|
|
154
|
+
It runs in:
|
|
155
|
+
|
|
156
|
+
- `.github/workflows/build-desktop-test.yml` — every PR (structure only, all
|
|
157
|
+
platforms).
|
|
158
|
+
- `.github/workflows/publish.yml` — every release, with `--require-developer-id
|
|
159
|
+
--require-notarized` on mac when the Apple certificate secret is present.
|
|
160
|
+
|
|
161
|
+
## 4. What a release must contain on macOS
|
|
162
|
+
|
|
163
|
+
Attached to the GitHub release and referenced by `latest-mac.yml`:
|
|
164
|
+
|
|
165
|
+
| Asset | Why |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `Markus-<version>-arm64-mac.zip`, `Markus-<version>-mac.zip` | what Squirrel.Mac installs |
|
|
168
|
+
| `Markus-<version>-arm64.dmg`, `Markus-<version>.dmg` | human download from the website |
|
|
169
|
+
| `latest-mac.yml` | the feed both arches read |
|
|
170
|
+
|
|
171
|
+
Missing zip ⇒ macOS users can never auto-update, and the failure is invisible to
|
|
172
|
+
them. That is why the gate exists.
|
|
173
|
+
|
|
174
|
+
## 5. Verifying a change end to end
|
|
175
|
+
|
|
176
|
+
Ordered from cheapest to most authoritative — do not stop at the first green:
|
|
177
|
+
|
|
178
|
+
1. `pnpm --filter @markus/desktop build:typecheck` + `pnpm test` (state machine).
|
|
179
|
+
2. `pnpm test:web-ui` (`UpdateNotice` behaviour with the real locale files).
|
|
180
|
+
3. Build locally: `pnpm dist --mac --arm64 --x64 --publish never`, then
|
|
181
|
+
`scripts/verify-mac-artifacts.sh`.
|
|
182
|
+
4. Real upgrade: install the previous release, point it at a feed containing the
|
|
183
|
+
new build, confirm the version number actually changes after restart. This is
|
|
184
|
+
the only step that proves the whole chain; steps 1–3 can be green while the
|
|
185
|
+
installer still refuses.
|