@rubytech/create-maxy-code 0.1.478 → 0.1.479

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/docs/superpowers/plans/2026-07-20-task-1789-reseat-channel-row-fork.md +1244 -0
  3. package/payload/platform/docs/superpowers/plans/2026-07-20-task-1818-loop-gate-app-routes.md +462 -0
  4. package/payload/platform/docs/superpowers/plans/2026-07-20-task-1819-top-level-label-allowlist.md +321 -0
  5. package/payload/platform/docs/superpowers/plans/2026-07-20-task-1831-data-portal-class-derived-allowlist.md +2177 -0
  6. package/payload/platform/docs/superpowers/specs/2026-07-20-task-1789-reseat-channel-row-fork-design.md +201 -0
  7. package/payload/platform/docs/superpowers/specs/2026-07-20-task-1818-loop-gate-app-routes-design.md +217 -0
  8. package/payload/platform/docs/superpowers/specs/2026-07-20-task-1819-top-level-label-allowlist-design.md +80 -0
  9. package/payload/platform/docs/superpowers/specs/2026-07-20-task-1831-data-portal-class-derived-allowlist-design.md +163 -0
  10. package/payload/platform/lib/graph-style/dist/index.d.ts.map +1 -1
  11. package/payload/platform/lib/graph-style/dist/index.js +22 -0
  12. package/payload/platform/lib/graph-style/dist/index.js.map +1 -1
  13. package/payload/platform/lib/graph-style/src/__tests__/parity.test.ts +6 -0
  14. package/payload/platform/lib/graph-style/src/index.ts +20 -0
  15. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +13 -1
  16. package/payload/platform/plugins/cloudflare/PLUGIN.md +26 -1
  17. package/payload/platform/plugins/cloudflare/bin/d1-http.mjs +80 -0
  18. package/payload/platform/plugins/cloudflare/bin/portal-enrol.mjs +17 -2
  19. package/payload/platform/plugins/cloudflare/bin/portal-index-push.mjs +357 -0
  20. package/payload/platform/plugins/cloudflare/bin/schema-exposed-dirs.mjs +103 -0
  21. package/payload/platform/plugins/cloudflare/mcp/__tests__/authorize.test.ts +2 -2
  22. package/payload/platform/plugins/cloudflare/mcp/__tests__/d1-http.test.ts +96 -0
  23. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-directory-listing.test.ts +120 -0
  24. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-enrol.test.ts +59 -4
  25. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-index-push.test.ts +176 -0
  26. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-index-state-contract.test.ts +75 -0
  27. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-indexed-download.test.ts +131 -0
  28. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-sign.test.ts +68 -0
  29. package/payload/platform/plugins/cloudflare/mcp/__tests__/schema-exposed-dirs.test.ts +88 -0
  30. package/payload/platform/plugins/cloudflare/mcp/__tests__/template-config.test.ts +39 -0
  31. package/payload/platform/plugins/cloudflare/skills/data-portal/SKILL.md +68 -1
  32. package/payload/platform/plugins/cloudflare/skills/data-portal/schema.sql +30 -1
  33. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/portal-sign.mjs +87 -0
  34. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/session.ts +8 -4
  35. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/types.ts +10 -0
  36. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/download.ts +107 -1
  37. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/files.ts +82 -2
  38. package/payload/platform/plugins/cloudflare/skills/data-portal/template/index.html +9 -0
  39. package/payload/platform/plugins/cloudflare/skills/data-portal/template/portal.css +56 -0
  40. package/payload/platform/plugins/cloudflare/skills/data-portal/template/portal.js +98 -2
  41. package/payload/platform/plugins/cloudflare/skills/data-portal/template/wrangler.toml +12 -0
  42. package/payload/platform/plugins/docs/references/cloudflare.md +12 -0
  43. package/payload/platform/plugins/scheduling/mcp/dist/__tests__/portal-index-audit.test.d.ts +2 -0
  44. package/payload/platform/plugins/scheduling/mcp/dist/__tests__/portal-index-audit.test.d.ts.map +1 -0
  45. package/payload/platform/plugins/scheduling/mcp/dist/__tests__/portal-index-audit.test.js +66 -0
  46. package/payload/platform/plugins/scheduling/mcp/dist/__tests__/portal-index-audit.test.js.map +1 -0
  47. package/payload/platform/plugins/scheduling/mcp/dist/lib/portal-index-audit.d.ts +41 -0
  48. package/payload/platform/plugins/scheduling/mcp/dist/lib/portal-index-audit.d.ts.map +1 -0
  49. package/payload/platform/plugins/scheduling/mcp/dist/lib/portal-index-audit.js +75 -0
  50. package/payload/platform/plugins/scheduling/mcp/dist/lib/portal-index-audit.js.map +1 -0
  51. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js +122 -0
  52. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js.map +1 -1
  53. package/payload/server/public/activity.html +8 -6
  54. package/payload/server/public/assets/{AdminLoginScreens-DR5eLF-a.js → AdminLoginScreens-DkxQZnvB.js} +1 -1
  55. package/payload/server/public/assets/AdminShell-Cv_nIFGe.js +2 -0
  56. package/payload/server/public/assets/Checkbox-CsTWK8mm.js +1 -0
  57. package/payload/server/public/assets/activity-BbnTiVBT.js +1 -0
  58. package/payload/server/public/assets/{admin-D2KLZnQW.js → admin-BZY3i_Ff.js} +1 -1
  59. package/payload/server/public/assets/{browser-CDWqEiCD.js → browser-BbIiSFKr.js} +1 -1
  60. package/payload/server/public/assets/{calendar-BG7fOpbB.js → calendar-BvxeTHvQ.js} +1 -1
  61. package/payload/server/public/assets/chat-DUKxufRk.js +1 -0
  62. package/payload/server/public/assets/chevron-left-BtfJD6LL.js +1 -0
  63. package/payload/server/public/assets/data-hl1wa-Ax.js +1 -0
  64. package/payload/server/public/assets/{graph-DRloNic4.js → graph-CDSGRoeb.js} +1 -1
  65. package/payload/server/public/assets/graph-labels-C5qLwnWA.js +1 -0
  66. package/payload/server/public/assets/{maximize-2-CzDaBugs.js → maximize-2-CAzH8dED.js} +1 -1
  67. package/payload/server/public/assets/{operator-BZeeyait.js → operator-BK7r8DAB.js} +1 -1
  68. package/payload/server/public/assets/{page-ef-6rRPL.js → page-B5YngOrK.js} +1 -1
  69. package/payload/server/public/assets/{page-B0obcg3b.js → page-BsCS0Dmc.js} +1 -1
  70. package/payload/server/public/assets/{public-9D3MMOkC.js → public-C1Pz-IBs.js} +1 -1
  71. package/payload/server/public/assets/{rotate-ccw-DXEKUhXP.js → rotate-ccw-UDln4Tou.js} +1 -1
  72. package/payload/server/public/assets/{tasks-BB0L7e5a.js → tasks-B-cLsn3p.js} +1 -1
  73. package/payload/server/public/assets/{time-entry-format-CsYAjplS.js → time-entry-format-DPOBIE18.js} +1 -1
  74. package/payload/server/public/assets/{triangle-alert-0lSBIUg-.js → triangle-alert-Dz-CZKo5.js} +1 -1
  75. package/payload/server/public/assets/{useCopyFeedback-jTBQ2h0V.js → useCopyFeedback-wtUHGohk.js} +1 -1
  76. package/payload/server/public/assets/{useSelectionMode-BooArySZ.js → useSelectionMode-sph7AQT5.js} +1 -1
  77. package/payload/server/public/assets/useSubAccountSwitcher-BRIluIKf.css +1 -0
  78. package/payload/server/public/assets/{useVoiceRecorder-PUT8q_sm.js → useVoiceRecorder-DN4jYQ0A.js} +1 -1
  79. package/payload/server/public/brand-defaults.css +1 -0
  80. package/payload/server/public/browser.html +5 -5
  81. package/payload/server/public/calendar.html +6 -6
  82. package/payload/server/public/chat.html +12 -12
  83. package/payload/server/public/data.html +11 -11
  84. package/payload/server/public/graph.html +11 -11
  85. package/payload/server/public/index.html +14 -14
  86. package/payload/server/public/operator.html +14 -14
  87. package/payload/server/public/privacy.html +1 -0
  88. package/payload/server/public/public.html +12 -12
  89. package/payload/server/public/tasks.html +6 -5
  90. package/payload/server/public/vnc-popout.html +1 -0
  91. package/payload/server/server.js +741 -366
  92. package/payload/server/public/assets/AdminShell-D9zaUxPd.js +0 -2
  93. package/payload/server/public/assets/Checkbox-DcbbAIe5.js +0 -1
  94. package/payload/server/public/assets/activity-C9P5NjEZ.js +0 -1
  95. package/payload/server/public/assets/chat-RyH-WYQC.js +0 -1
  96. package/payload/server/public/assets/chevron-left-DmXCr6nB.js +0 -1
  97. package/payload/server/public/assets/data-BaY_LkLR.js +0 -1
  98. package/payload/server/public/assets/graph-labels-DD-GqS4v.js +0 -1
  99. package/payload/server/public/assets/useSubAccountSwitcher-D9knHOKq.css +0 -1
  100. /package/payload/server/public/assets/{useSubAccountSwitcher-BZnzc5C3.js → useSubAccountSwitcher-v8LyBzZN.js} +0 -0
@@ -0,0 +1,201 @@
1
+ # Task 1789 — Re-seating a channel row forks it to webchat and destroys the channel seat
2
+
3
+ Design, 2026-07-20.
4
+
5
+ ## The defect
6
+
7
+ `session-reseat.ts` builds every fork payload with a hardcoded webchat shape. Re-seating a
8
+ WhatsApp or Telegram row therefore spawns a **webchat** session whose `senderId` is
9
+ `session:<newId>`. The per-sender channel server for the real sender is replaced, its SSE stream
10
+ aborts, and `whatsapp/gateway/routes.ts:56` fires `op=channel-detached`. The fork renders with a
11
+ webchat glyph.
12
+
13
+ The fork is also unreachable from the channel. A sender's session id is
14
+ `adminSessionIdFor(accountId, senderId)` — `sha256` shaped into a v4 UUID, a pure function. Every
15
+ future inbound recomputes the original id, never the fork's.
16
+
17
+ Observed 2026-07-18 on `sitedesk-code`, account `5e99bba5`, sender `447504472444`, session
18
+ `c6ed890f`. Brand-uniform code path.
19
+
20
+ ## Three corrections to the task brief
21
+
22
+ The brief was written against a reading of the code that does not hold. All three were confirmed
23
+ by reading the tree and were agreed with the operator before this design was written.
24
+
25
+ **The seam named in Fix #2 is log-only.** `wa-gateway.ts:312`'s `adminSessionIdFor` call feeds the
26
+ `op=inbound … sessionId=` line and nothing else. The id the spawn actually runs under comes from
27
+ the pure builder `whatsapp/gateway/spawn-request.ts:34`, called once at `server/index.ts:418`.
28
+ Telegram mirrors it exactly (`spawn-request.ts:31`, `server/index.ts:700`). Consulting the
29
+ override at the gateway line alone would make the log truthful and route nothing.
30
+
31
+ **The fork has no channel binding until the next inbound.** The manager wires the WhatsApp reply
32
+ tool only when a `waChannel` descriptor (senderId, gatewayUrl, serverPath) is present. The re-seat
33
+ route holds none of those, and the manager's store fallback is keyed on the new session id, which
34
+ is empty for a fresh fork. So the fork spawns correctly labelled but without
35
+ `mcp__whatsapp-channel__reply` until an inbound arrives and `ensureChannelSession` binds it. This
36
+ is accepted, not fixed — the existing re-attach path already covers it. It is made observable
37
+ rather than left silent, because the manager's own `op=channel-binding-lost` invariant is gated on
38
+ the store and cannot fire here.
39
+
40
+ **The audit sweep cannot answer the standing check as specified.** `runDuplicateSenderAudit`
41
+ walks session sidecars on disk. It has no event history, so "a sender whose last event is a
42
+ `channel-detached`" is not derivable from it. The gateway must record detach times for the sweep
43
+ to query.
44
+
45
+ ## Scope
46
+
47
+ In scope: WhatsApp and Telegram admin channel rows.
48
+
49
+ Out of scope, deliberately:
50
+
51
+ - **Public channel rows.** Public sessions key their id on `personId` as well as `senderId`, so
52
+ the `<channel>:<senderId>` override key is ambiguous for them. Public re-seat is not evidenced
53
+ as broken. Public rows re-seat exactly as they do today.
54
+ - **Telegram in the standing audit.** `runDuplicateSenderAudit` is WhatsApp-only today. The
55
+ unseated check extends it in place; making the whole sweep multi-channel is separate work.
56
+ - Everything already listed under the task's own "Out of scope": the fork's displayed model
57
+ (Task 1790), the cross-lever clobber (Task 940), re-attaching the live sender, and
58
+ `op=duplicate-sender-sessions` for `447850009518`.
59
+
60
+ ## Design
61
+
62
+ ### Unit 1 — `platform/ui/server/channel-session-override.ts` (new)
63
+
64
+ Modelled on `canonical-webchat-override.ts`. One JSON file, `channel-session-override.json`, in
65
+ the account directory.
66
+
67
+ ```json
68
+ { "bySender": { "whatsapp:447504472444": "fc397054-…" } }
69
+ ```
70
+
71
+ - `channelOverridePath(accountDir)` — the file path.
72
+ - `readChannelOverrideId(accountDir, channel, senderId): string | null` — the fork id for that
73
+ sender, or null when unset, malformed, or not a v4-shaped UUID. Never throws; a corrupt file
74
+ reads as null so a bad write can never wedge inbound routing.
75
+ - `writeChannelOverrideId(accountDir, channel, senderId, sessionId): void` — merges into
76
+ `bySender`, preserving other senders' entries. Atomic tmp+rename so a concurrent read never
77
+ sees a half-written file.
78
+
79
+ There is no legacy-shape migration. Unlike the canonical override this file has no predecessor.
80
+
81
+ ### Unit 2 — the fork inherits the source row's channel
82
+
83
+ `session-reseat.ts` reads the source session's `.meta.json` through the existing exported
84
+ `readSidecarMeta`, and passes the result to `resolveReseatPlan` as a new optional `source`
85
+ argument. `resolveReseatPlan` stays pure and unit-testable without the gate.
86
+
87
+ The channel shape applies when **all three** hold: sidecar `role` is `admin`, sidecar `channel` is
88
+ `whatsapp` or `telegram`, and sidecar `senderId` is a non-empty string. Then the payload carries:
89
+
90
+ - `channel` — the sidecar's channel
91
+ - `senderId` — the sidecar's senderId
92
+ - `role: 'admin'`
93
+ - `targetAccountId` — the sidecar's `accountId`, when present
94
+ - **no** `webchatChannel` descriptor
95
+
96
+ `personId` is never carried: the admin-only scope means it is always null on these rows.
97
+
98
+ When any of the three conditions fails, the payload is byte-for-byte what it is today.
99
+
100
+ `targetAccountId` is an addition beyond the task text and was approved explicitly. Without it the
101
+ manager defaults the fork to the boot account, so a channel row belonging to a client sub-account
102
+ would fork into the house account — wrong account scope for every Neo4j write the fork makes.
103
+ Pre-983 sidecars carry no `accountId`; those omit the field and keep today's behaviour.
104
+
105
+ ### Unit 3 — resolution consults the override
106
+
107
+ `buildWaSpawnRequest` and `buildTelegramSpawnRequest` each gain an optional `overrideSessionId`
108
+ input. When set it is used as `sessionId`; otherwise `adminSessionIdFor` as today. The builders
109
+ keep no filesystem access and stay pure.
110
+
111
+ `server/index.ts` reads the override at both spawn call sites (`:418` WhatsApp, `:700` Telegram),
112
+ resolving the effective account's directory by id through `listValidAccounts()`. Using the
113
+ **effective** account id on the read side matches the write side, which keys on the source
114
+ sidecar's `accountId` — so an account-manager-routed sub-account sender resolves its own override
115
+ and never the house's.
116
+
117
+ The two gateway `op=inbound` log lines consult the same override, so the logged `sessionId` names
118
+ the session the message actually reaches. The gateways do not read the file themselves: each takes
119
+ an optional `resolveSessionOverride?: (accountId, senderId) => string | null` dependency, injected
120
+ by `server/index.ts` at construction. The gateways keep no filesystem knowledge and stay testable
121
+ with a stub, and an absent dependency degrades to the deterministic id.
122
+
123
+ ### Chained re-seats
124
+
125
+ Mirroring Task 876's canonical pointer: the route writes the override when the source is either
126
+ the deterministic per-sender id **or** the current override value. Re-seating a fork moves the
127
+ pointer forward instead of stranding it.
128
+
129
+ ### Why not a mutable binding
130
+
131
+ Rejected, per the task. `adminSessionIdFor`'s determinism is what lets an inbound resume the right
132
+ JSONL after a bridge or manager restart, and every existing channel session's id derives from it.
133
+
134
+ ### Relationship to Task 1746
135
+
136
+ `spawn-request.ts` currently comments that "the deterministic per-sender id is the ONLY id a
137
+ sender's session ever has", written when Task 1746 removed Task 1526's per-firing seat. That seat
138
+ was **salted per scheduled firing**: it minted a new session on every dispatch, which then
139
+ attached under the sender's own hub key and swallowed their real messages, splitting one
140
+ conversation across two sessions.
141
+
142
+ This override is a **stable forward pointer**: one session, repointed once by an operator action,
143
+ resolving identically for every subsequent inbound. It cannot split a conversation because it
144
+ never yields a second id for a sender. Both comments are rewritten to say the deterministic id is
145
+ the default rather than the only id, and to record this distinction so the next reader does not
146
+ re-remove the override.
147
+
148
+ ### Unit 4 — observability
149
+
150
+ - `op=request` gains the source's resolved channel and senderId, so the lifeline says what kind of
151
+ row was re-seated.
152
+ - `op=channel-forward senderId=… from=… to=…` at the override write, mirroring the existing
153
+ `op=canonical-forward`.
154
+ - `op=channel-fork-unbound senderId=… session=…` at a channel fork, naming the window in which the
155
+ fork has no reply tool. The brief did not ask for this; it exists because the manager's own
156
+ binding-lost invariant provably cannot fire on this path.
157
+ - **Standing check.** The WhatsApp gateway records a detach timestamp per sender when
158
+ `op=channel-detached` fires, and clears it on attach. `runDuplicateSenderAudit` queries that map
159
+ and emits `op=sender-unseated senderId=… since=…` for any sender still detached longer than one
160
+ sweep interval (15 min). This reconciles expected state — every known sender has a seat or a
161
+ reason not to — against actual, without reproducing the failure. A detached sender with no live
162
+ channel server is otherwise invisible to action logging, because nothing happens.
163
+
164
+ ### Comments to correct
165
+
166
+ `session-reseat.ts`'s header (asserts the fork is always webchat-bound),
167
+ `SessionReseatControl.tsx:10-13` (asserts the opposite), and both `spawn-request.ts` Task 1746
168
+ comments. All four must describe the delivered behaviour.
169
+
170
+ ## Testing
171
+
172
+ - `session-reseat.test.ts` — a `whatsapp` admin sidecar source produces a payload carrying
173
+ `channel:'whatsapp'`, the source `senderId`, and no `webchatChannel` key; a `telegram` admin
174
+ sidecar does the same for its channel; a `webchat` sidecar produces today's payload
175
+ byte-for-byte; a `whatsapp` sidecar with `role:'public'` produces today's payload; a sidecar with
176
+ no `accountId` omits `targetAccountId`.
177
+ - Override round-trip — write then read returns the fork id for that sender and null for an
178
+ unwritten sender; a second sender's write preserves the first; a malformed file reads null
179
+ rather than throwing.
180
+ - Spawn builders — with an `overrideSessionId` the request carries it; without one it carries
181
+ `adminSessionIdFor`. Both channels.
182
+ - Unseated audit — a sender detached longer than one interval is reported; one detached within the
183
+ interval is not; one that re-attached is not.
184
+ - Regression proof on-device — re-seat a WhatsApp row, confirm no `channel-detached` without a
185
+ following `channel-attached`, then send an inbound and confirm `op=inbound … sessionId=<fork>`.
186
+
187
+ ## Files
188
+
189
+ | File | Change |
190
+ |---|---|
191
+ | `platform/ui/server/channel-session-override.ts` | new |
192
+ | `platform/ui/server/routes/admin/session-reseat.ts` | sidecar read, channel payload, override write, lifeline fields |
193
+ | `platform/ui/app/lib/whatsapp/gateway/spawn-request.ts` | optional `overrideSessionId` |
194
+ | `platform/ui/app/lib/telegram/gateway/spawn-request.ts` | optional `overrideSessionId` |
195
+ | `platform/ui/server/index.ts` | override read at both spawn sites; unseated audit |
196
+ | `platform/ui/app/lib/whatsapp/gateway/wa-gateway.ts` | detach-time map; override in `op=inbound` |
197
+ | `platform/ui/app/lib/telegram/gateway/telegram-gateway.ts` | override in `op=inbound` |
198
+ | `platform/ui/app/lib/whatsapp/gateway/duplicate-sender-audit.ts` | `op=sender-unseated` |
199
+ | `platform/ui/app/components/SessionReseatControl.tsx` | comment correction |
200
+ | `.docs/admin-webchat-native-channel.md` | document the override and the unbound window |
201
+ | `.tasks/LANES.md` | archive sync |
@@ -0,0 +1,217 @@
1
+ # Task 1818 — Widen the loop gate to cover `app/**` outside `app/lib/`
2
+
3
+ **Date:** 2026-07-20
4
+ **Lane:** Platform / admin UI · activity view · scheduled work visibility
5
+ **Depends on:** 1810 (landed), 1814 (landed — the widened gate and its marker convention)
6
+
7
+ ## Summary
8
+
9
+ `scripts/check-loops-registered.mjs` walks `server/**` and `app/lib/**`. The rest of
10
+ `app/**` is unscanned, so a standing server loop armed there would not be caught and
11
+ would be invisible on `/activity`, which is the omission mode 1810 and 1814 exist to
12
+ close.
13
+
14
+ This task widens the scan to the whole of `app/**` and marks the fifteen browser timers
15
+ already there `loop-exempt:client`.
16
+
17
+ ## Premise corrections
18
+
19
+ The task file's approach section rests on three factual claims about the tree. All three
20
+ are wrong, and the first one voids one of its two candidate approaches outright. They are
21
+ recorded here because the task's stated reasoning cannot be followed as written.
22
+
23
+ ### 1. There is no Next.js
24
+
25
+ The task describes the unscanned area as "Next.js route and component code" and names
26
+ `app/api/*/route.ts` as the shape of the loop that would escape.
27
+
28
+ `platform/ui` has no `next` dependency and no `next.config`. It is a Vite SPA with ten
29
+ HTML entries (`vite.config.ts`) plus a Hono server bundled by tsup from exactly two
30
+ entries, `server/index.ts` and `server/edge.ts` (`tsup.config.ts`). There is no `app/api/`
31
+ directory and no route file under `app/` at all. Server routes live in `server/routes/`,
32
+ which the gate already scans.
33
+
34
+ The task's second candidate — "treat `app/api/**` and any other server-executing subtree
35
+ as in scope while leaving component directories out" — therefore describes a layout that
36
+ cannot exist in this package. It is void rather than merely less attractive. The task
37
+ states that establishing "whichever the Next.js routing layout actually makes stable" is
38
+ the first work of this task; the answer is that there is no such layout, and the decision
39
+ collapses to the remaining candidate.
40
+
41
+ ### 2. `'use client'` is unusable, but not for the stated reason
42
+
43
+ The task rules out the `'use client'` directive as a discriminator on the grounds that
44
+ "the 1814 census confirmed `app/lib/use-now-tick.ts` is a React hook carrying no such
45
+ directive".
46
+
47
+ `app/lib/use-now-tick.ts` carries `'use client'` on line 14, and carried it at 1814's own
48
+ commit (`git show main:…` returns the directive).
49
+
50
+ The conclusion survives on different evidence. Of the eleven files under `app/` outside
51
+ `app/lib/` that arm a browser timer, three carry no directive: `app/chat/page.tsx`,
52
+ `app/chat/transcript-render.tsx`, and `app/graph/settle-lock.ts`. A discriminator that
53
+ misses three of eleven cannot gate a build.
54
+
55
+ ### 3. Fifteen sites, not sixteen
56
+
57
+ The task and its LANES row both count sixteen browser timers in the unscanned area.
58
+
59
+ Applying the gate's own `ARM` regex (`/\bsetInterval\s*\(/`) to `app/**` outside
60
+ `app/lib/`, skipping `__tests__`, yields **fifteen** sites across eleven files. The
61
+ difference is that eight further occurrences are `ReturnType<typeof setInterval>` type
62
+ positions, which have no `(` after the identifier and do not match. The sixteenth timer is
63
+ `app/lib/use-now-tick.ts`, which lives inside a scanned root and already carries its
64
+ marker.
65
+
66
+ ## What the census found
67
+
68
+ Two findings beyond the count, both bearing on the design.
69
+
70
+ **No hidden standing loop.** Every one of the fifteen sites is genuinely a browser timer.
71
+ The two least obvious were checked directly: `app/graph/settle-lock.ts` samples
72
+ `network.getPositions()` to freeze vis-network canvas physics and is imported only by
73
+ `app/graph/page.tsx`; `app/chat/transcript-render.tsx` is a React render module ticking
74
+ `setNow(Date.now())`. This is the opposite of 1814, whose widening surfaced
75
+ `visitor-event.ts`, a standing loop that had been invisible the whole time. Here the
76
+ widening surfaces nothing: every new site resolves to a marker, and no `registerLoop` call
77
+ is added, so the registry's 26 production loops are unchanged.
78
+
79
+ **Server-reachable code outside `app/lib/` already exists.** A census of every
80
+ `from '…/app/…'` import in `server/` returns `app/lib/…` in every case but one:
81
+ `server/routes/whatsapp-reader.ts:43` imports `SUPPORTED_MIME_SET`, `MAX_FILE_BYTES` and
82
+ `MAX_ATTACHMENTS` from `app/admin-types.ts`. Those are runtime values, not types, so this
83
+ is genuinely server-executing code living outside the scanned tree today. It arms no
84
+ timer, so nothing is currently hidden, but the boundary "server code stops at `app/lib/`"
85
+ is already false and the design must not depend on it. No dynamic `import()` or
86
+ `require()` in `server/` reaches `app/`, and no file under `app/` outside `app/lib/`
87
+ imports a `node:` builtin.
88
+
89
+ ## Approach
90
+
91
+ Scan the whole of `app/**`. Mark the fifteen browser timers `loop-exempt:client`.
92
+
93
+ Two alternatives were considered and rejected.
94
+
95
+ **Reachability from the two server entry points.** The gate could resolve the import graph
96
+ from `server/index.ts` and `server/edge.ts` and scan exactly what it reaches. This is the
97
+ most precise statement of the real semantic. It is rejected because it puts a module
98
+ resolver inside a gate whose own header records that hand-rolled parsing is what killed
99
+ its first version: that version stripped `//` comments, ate the closing backtick of every
100
+ template literal containing a URL, and reported `ok` on a real violation. The gate's
101
+ governing principle is to match raw lines and parse nothing.
102
+
103
+ **Close 1818 as void.** Since there is no route-file surface under `app/` in a Vite SPA, a
104
+ server loop arguably has nowhere there to hide. This is rejected because it rests on
105
+ "everything under `app/` is client today", which is the assumption the task exists to stop
106
+ relying on, and which `app/admin-types.ts` already partially falsifies.
107
+
108
+ ## Design
109
+
110
+ ### The scan root
111
+
112
+ `SCAN_ROOTS` becomes `['server', 'app']`, replacing `['server', 'app/lib']`.
113
+
114
+ `app/lib` is subsumed rather than listed alongside `app`. Listing both would walk `app/lib`
115
+ twice and double its contribution to `files=` and `sites=`, corrupting the exact counter
116
+ the task names as its evidence that the widening took effect.
117
+
118
+ ### The fifteen markers
119
+
120
+ Each site gets `// loop-exempt:client <reason>` on its own line, with the reason specific
121
+ to that timer rather than a repeated phrase. `client` is already in the closed category set
122
+ established by 1814 (`per-connection`, `demand-singleton`, `client`, `registry-primitive`),
123
+ so no convention changes. The task puts the marker convention and category set explicitly
124
+ out of scope.
125
+
126
+ The sites:
127
+
128
+ | File | Line | What it ticks |
129
+ |---|---|---|
130
+ | `app/AdminShell.tsx` | 228 | 60s poll |
131
+ | `app/Sidebar.tsx` | 512, 534, 1609 | channel conversations, sessions, system stats |
132
+ | `app/activity/page.tsx` | 428 | 15s activity reload |
133
+ | `app/chat/page.tsx` | 700, 721 | pointer poll, 60s read |
134
+ | `app/chat/transcript-render.tsx` | 80 | 1s relative-time clock |
135
+ | `app/graph/page.tsx` | 1456 | layout poll |
136
+ | `app/graph/settle-lock.ts` | 137 | vis-network motion sampler |
137
+ | `app/hooks/useViewMode.ts` | 110 | view-mode poll |
138
+ | `app/hooks/useVoiceRecorder.ts` | 142 | recording elapsed timer |
139
+ | `app/useAdminAuth.ts` | 219 | auth refresh |
140
+ | `app/useElapsedTimer.ts` | 29, 35 | session tick, elapsed tick |
141
+
142
+ ### The header
143
+
144
+ The gate's SCOPE block currently reads "Covers `server/**` and `app/lib/**` … NOT covered:
145
+ the rest of `app/**`, which is Next.js route and component code running in the visitor's
146
+ browser". Every clause of that becomes false or was already false.
147
+
148
+ It is rewritten to state the real boundary (`server/**` and `app/**`, excluding
149
+ `__tests__`), that the server bundles from two entries so `server/**` is where server code
150
+ starts, and that `app/admin-types.ts` is already server-reachable from outside `app/lib/`
151
+ — which is why the whole of `app/` is scanned rather than a subtree of it. A gate whose
152
+ header overclaims is the defect class this file exists to prevent, so the header moves in
153
+ the same change as the behaviour.
154
+
155
+ ### Tests
156
+
157
+ The behaviour belongs in the project's own committed suite at
158
+ `scripts/__tests__/check-loops-registered.test.ts`, so these are committed rather than
159
+ ephemeral.
160
+
161
+ One existing test **encodes the hole this task closes**. `ignores files outside the two
162
+ scan roots` (line 87) proves its point with `app/chat/page.tsx`, asserting exit 0 and
163
+ `sites=0`. That file moves in-scope, so the test must be rewritten against a path that is
164
+ genuinely outside both roots, not merely extended around.
165
+
166
+ New cases:
167
+
168
+ - An unmarked module-scope `setInterval` in a component file under `app/` outside
169
+ `app/lib/` fails with exit 1 and the message naming the file.
170
+ - A marked `client` site in that same area passes and is counted under `client=`.
171
+
172
+ The real-tree floor assertions rise so a walk that silently stops reading shows as
173
+ collapsed counts rather than a healthy `ok`.
174
+
175
+ ### Mutation check
176
+
177
+ Required by the task on 1814's terms. A real unmarked `setInterval` is inserted into an
178
+ actual file under `app/` outside `app/lib/`, the gate is observed exiting 1 and naming
179
+ that file, and the line is removed. A negative test that passes because the signal is dead
180
+ is the failure this whole line of work exists to remove, and a synthetic fixture under
181
+ `--root` cannot prove the real scan root moved.
182
+
183
+ ## Observability
184
+
185
+ `files=` rises from **284** to **393**: 109 non-test source files under `app/` outside
186
+ `app/lib/`. The predicted figure is asserted rather than "the number went up", so a partial
187
+ walk fails instead of passing.
188
+
189
+ `sites=` rises from 10 to 25, `marked=` from 9 to 24, and `client=` from 1 to 16. No
190
+ `registerLoop` call is added, because the census found no standing loop in the newly
191
+ covered area. That pairing — coverage widens, registered loop count holds at 26 — is the
192
+ finding, not an absence of one.
193
+
194
+ ## Scope boundaries
195
+
196
+ **In scope:** the scan boundary for `app/**` outside `app/lib/`, the marking that decision
197
+ implies, the gate's SCOPE header, and the test surface above.
198
+
199
+ **Out of scope:** the marker convention and category set, settled in 1814; the two scan
200
+ roots already covered; the gate's raw-line matching, whose two known holes are documented
201
+ in its header and are accepted rather than open.
202
+
203
+ **Answered, not deferred: `app/admin-types.ts` stays where it is.** Being server-reachable
204
+ from outside `app/lib/` reads at first like a filing error worth correcting. It is not.
205
+ That file exists precisely so it cannot import `app/lib/attachments.ts` — its own comment
206
+ records the reason ("cannot import a Node.js module into a client component"), and
207
+ `attachments.ts` opens with `node:crypto`, `node:fs/promises` and `node:fs`. `app/lib/` is
208
+ the Node-touching tree: 56 of its 191 non-test source files import a `node:` builtin.
209
+ Moving the deliberately client-safe mirror into that directory would file it beside the
210
+ module it exists to avoid. Separately, the move would buy this task's outcome nothing,
211
+ because the widened scan covers the file wherever it lives. So there is no structural
212
+ question left open here and no follow-up task to file.
213
+
214
+ **A real adjacent risk, named and not fixed here.** `ACCEPT_MIME` / `SUPPORTED_MIME_SET` in
215
+ `app/admin-types.ts` mirror `app/lib/attachments.ts` by hand, with nothing keeping the two
216
+ in sync. That is a mime-allowlist consistency problem with no bearing on loop coverage, and
217
+ it is not touched by this task.
@@ -0,0 +1,80 @@
1
+ # Task 1819 — top-level label allowlist drift
2
+
3
+ Design, 2026-07-20.
4
+
5
+ ## Problem
6
+
7
+ Two tests fail on `main`:
8
+
9
+ - `server/lib/top-level-labels.test.ts` — deep-equals the derived allowlist against the real references dir
10
+ - `server/routes/__tests__/graph-default-topLevel.test.ts` — resolves the top-level label set for the default view
11
+
12
+ Both compare the hardcoded client mirror `FILTER_TOP_LEVEL_LABELS` against the set derived from `plugins/memory/references/`.
13
+
14
+ ## Evidence
15
+
16
+ Measured set diff, both directions:
17
+
18
+ | Direction | Labels |
19
+ |---|---|
20
+ | In `FILTER_TOP_LEVEL_LABELS`, not in derived | `InboundInvoice` |
21
+ | In derived, not in `FILTER_TOP_LEVEL_LABELS` | none |
22
+
23
+ Client mirror 48 entries, derived 47. Contributing files: `schema-construction.md`, `schema-estate-agent.md`. Table-derived 14, static 33.
24
+
25
+ ## Cause
26
+
27
+ Commit `7b225f814` (2026-07-18, "promote ledger labels to base") moved the `InboundInvoice` row out of the `## Top-level node types` table in `schema-construction.md` and into the `## Node Types` table in `schema-base.md`.
28
+
29
+ `getTopLevelLabelAllowlist` parses only `## Top-level node types` sections. It deliberately never parses `schema-base.md`, because that table mixes child types (`InvoiceLine`, `InvoicePayment`, `PostalAddress`) in with top-level ones. So the promotion deleted `InboundInvoice` from the derived set.
30
+
31
+ `STATIC_TOP_LEVEL_LABELS` exists precisely for base-schema labels with no top-level section to derive from. `InboundInvoice` was never added to it — `git log -S` confirms the string has never appeared in `top-level-labels.ts`.
32
+
33
+ The other three promoted labels (`InvoiceLine`, `InvoicePayment`, `Credit`) are documented children in `graph-labels.ts` and correctly stay off both sets.
34
+
35
+ Nothing regenerates either side. The rot mechanism is that a schema-doc edit in the memory plugin's references directory silently changes the UI's derived chip set, guarded only by a test that was not run before the promotion landed.
36
+
37
+ ## Fix
38
+
39
+ `InboundInvoice` is genuinely top-level and the client mirror is correct. The derivation is missing an entry.
40
+
41
+ 1. Add `InboundInvoice` to `STATIC_TOP_LEVEL_LABELS`.
42
+ 2. Extend the `STATIC_TOP_LEVEL_LABELS` doc comment to cover the reverse migration. It documents only the forward direction today (a vertical gains a top-level section, so its labels leave static). It is silent on the direction that caused this: a label promoted into `schema-base.md` must enter static, because base is never parsed.
43
+
44
+ Editing either assertion is explicitly not the fix.
45
+
46
+ ## CashEntry
47
+
48
+ The same commit added `CashEntry`, absent from both sets, so it fails no test but has no `/graph` chip. Operator decision on this sprint: add it as a top-level label.
49
+
50
+ Justification that it is top-level: the promoting commit describes it as money "not attached to any invoice" with "no parent label". Child labels are reached by drilling down from a parent neighbourhood. `CashEntry` has no parent, so without a chip it is unreachable on `/graph` except by search.
51
+
52
+ Five surfaces:
53
+
54
+ | Surface | Change | Gate |
55
+ |---|---|---|
56
+ | `GRAPH_LABEL_COLOURS` | unique hex | hex uniqueness is test-enforced |
57
+ | `LABEL_ICONS` | Lucide glyph | coverage test fails if a colour label has no glyph |
58
+ | `FILTER_TOP_LEVEL_LABELS` | add | client chip mirror |
59
+ | `STATIC_TOP_LEVEL_LABELS` | add | server derived set |
60
+ | `pickShortLabel` | `CashEntry` branch | properties are `entryId`/`direction`/`amount`/`date`/`description`; none match the generic caption keys, so nodes would render captionless |
61
+
62
+ ### Placement
63
+
64
+ Append `CashEntry` at the end of `GRAPH_LABEL_COLOURS`, not beside the ledger family.
65
+
66
+ `SHAPE_BY_LABEL` assigns each label a shape by its index position in `ALL_GRAPH_LABELS`, which is the colour table's key order. A mid-table insert shifts every subsequent index and changes the node shape of roughly 40 labels across the whole graph. No test catches that. Appending costs source-file grouping and buys zero collateral churn.
67
+
68
+ ### Build
69
+
70
+ `platform/lib/graph-style/dist` is a symlink to the parent checkout in this worktree. Replace it with a local build before editing, so the parent checkout's build output is never written to.
71
+
72
+ ## Scope boundaries
73
+
74
+ **In scope:** the cause of the disagreement, the correct value of the label set, both failing tests, and the five `CashEntry` surfaces.
75
+
76
+ **Out of scope:** the `/graph` view's rendering; the loop registry and its gate (1810, 1814, 1818); other pre-existing red on `main`; retiring the client mirror in favour of the derived set (already noted as a follow-up in `graph-labels.ts`).
77
+
78
+ ## Testing
79
+
80
+ The two named tests, passing because the sets agree. Plus the graph-style icon-coverage and hex-uniqueness tests, and the client `graph-labels.test.ts` suite, since the colour table changed.
@@ -0,0 +1,163 @@
1
+ # Task 1831 — data portal class-derived allowlist (design)
2
+
3
+ Date: 2026-07-20. Task: [`.tasks/1831-data-portal-exposes-only-uploads-not-the-sub-accounts-folder-tree.md`](../../../../.tasks/1831-data-portal-exposes-only-uploads-not-the-sub-accounts-folder-tree.md).
4
+
5
+ ## Problem
6
+
7
+ The portal only shows what the client uploaded. `processFiles`
8
+ (`skills/data-portal/template/functions/api/files.ts:11-24`) reads
9
+ `manifest WHERE ownerId = ?`, and `manifest` holds one row per `/api/upload`
10
+ object. There is no device-to-portal path at all, so an account can receive
11
+ documents from a client but cannot hand any back.
12
+
13
+ A fixed folder list cannot solve it. On SiteDesk account
14
+ `098a18a3-1741-447f-9778-65470645d57d` the deliverables sit in both `output/`
15
+ and `quotes/`, and `quotes/` is projected per account from the brand's vertical
16
+ ontology (`platform/scripts/lib/account-schema-owned-dirs.py:288-296`), not
17
+ shipped in the template. A different vertical projects different buckets.
18
+
19
+ Provenance cannot be recovered either. `upsertFileArtifact`
20
+ (`platform/ui/app/lib/file-index.ts:294-307`) stores no writer, and the watcher
21
+ runs agent writes and operator uploads through one path
22
+ (`platform/ui/app/lib/file-watcher.ts:30-34`).
23
+
24
+ ## Approach
25
+
26
+ Key on each folder's declared class, not its name.
27
+
28
+ Exposed = the dirs named in the account's `<!-- ontology-buckets -->` region,
29
+ plus `output`, intersected with the ```` ```allowed-top-level ```` block. All
30
+ three are read from `accounts/<accountId>/SCHEMA.md`, which is generated per
31
+ account. A new vertical projects new buckets and they appear with no code change.
32
+
33
+ ## Data flow
34
+
35
+ ```
36
+ DEVICE (each heartbeat) D1 PORTAL
37
+ read SCHEMA.md
38
+ resolve exposed dirs
39
+ walk those dirs only ── metadata ──▶ directory ──── read ───▶ folder tree
40
+
41
+ click a file ───────────────┘
42
+
43
+ HEAD (alive?) ◀───────────┤
44
+
45
+ signed link, 5 min ──────┘
46
+
47
+ verify signature ◀──────────────┘
48
+ re-resolve exposed dirs
49
+ serve bytes
50
+ ```
51
+
52
+ Bytes never enter D1 or R2. Listing therefore survives the device being offline;
53
+ download does not, and says so plainly.
54
+
55
+ ## Components
56
+
57
+ | File | Responsibility |
58
+ |---|---|
59
+ | `plugins/cloudflare/bin/schema-exposed-dirs.mjs` | `SCHEMA.md` text in, exposed dir names out. Pure, no I/O. |
60
+ | `plugins/cloudflare/bin/portal-index-push.mjs` | walk exposed dirs, full-replace the account's `directory` rows |
61
+ | `.../template/functions/api/_lib/portal-sign.mjs` | mint + verify the signed link, portal side (sits beside `passcode.mjs`, same precedent) |
62
+ | `plugins/cloudflare/skills/data-portal/schema.sql` | `directory` table, `people.accountId` column |
63
+ | `.../template/functions/api/files.ts` | folder entries beside today's uploads |
64
+ | `.../template/functions/api/download.ts` | uploads to R2 unchanged; indexed files get a signed link |
65
+ | `.../template/portal.js`, `index.html` | breadcrumb folder navigation |
66
+ | `platform/ui/server/routes/portal-fetch.ts` | verify signature, re-resolve exposure, serve |
67
+
68
+ ## Parsing contract
69
+
70
+ Pinned against the generator, because two details are easy to get wrong and both
71
+ fail silently:
72
+
73
+ - The ontology region lists `` - `<dir>/` - one folder per <Label> record. `` with
74
+ an **ASCII hyphen**; the plugin-owned region uses an **em dash**
75
+ (`account-schema-owned-dirs.py:294` vs `:281`). Parsing on the em dash matches
76
+ nothing and reads as "this account has no buckets".
77
+ - An absent ontology region is normal, not corrupt: `merge()` strips both regions
78
+ before regenerating, and a brand with no declared vertical never gets one. It
79
+ yields `output` alone.
80
+ - A dir claimed by a plugin is described only in the plugin-owned region
81
+ (`:287`), so it will not parse as a domain bucket and drops out of the exposed
82
+ set. Instrumented, not fixed, here.
83
+
84
+ ## Authentication
85
+
86
+ One secret per account, generated at portal assembly, written to the account's
87
+ secrets file and set as the Pages secret `PORTAL_FETCH_SECRET`. The install
88
+ origin is set alongside it as `PORTAL_INSTALL_ORIGIN`.
89
+
90
+ The portal signs `accountId`, `relPath` and an expiry with HMAC-SHA256 via Web
91
+ Crypto and puts the signature in the link. The install verifies it. The secret
92
+ itself never travels, and each grant covers one file for five minutes.
93
+
94
+ The install re-resolves the exposed dir list from `SCHEMA.md` on every request
95
+ rather than trusting the path it was handed. A valid signature over
96
+ `documents/private.pdf` is still refused. That check is the security boundary;
97
+ the signature only proves the request came from the portal.
98
+
99
+ **The two ends do not share a module.** No production code in `platform/ui`
100
+ imports from `platform/plugins` today — only one test does
101
+ (`server/lib/calendar-ics.test.ts:12`) — and this sprint will not invent that
102
+ coupling for fifteen lines of HMAC. The portal mints with
103
+ `_lib/portal-sign.mjs`; `portal-fetch.ts` carries its own verify. Both call Web
104
+ Crypto, which Node 22 and Workers both provide, so the algorithm is identical by
105
+ construction. A parity test mints with the portal module and verifies with the
106
+ install's function, which catches drift at the only place it could occur.
107
+
108
+ ## Error handling
109
+
110
+ | Condition | Response |
111
+ |---|---|
112
+ | device unreachable (HEAD fails) | 503 `device-offline` |
113
+ | signature absent, altered, or expired | 401 |
114
+ | path outside the exposed dirs | 404, regardless of signature |
115
+ | path outside the account partition | 404 |
116
+ | `SCHEMA.md` missing or unparseable | expose nothing |
117
+
118
+ The last one deliberately inverts `fs-schema-guard.sh:76-78`, which fails open so
119
+ an unseeded legacy account is not write-blocked. A read surface facing a client
120
+ must fail closed. The code carries that reason inline.
121
+
122
+ ## Testing
123
+
124
+ Unit only. No portal is deployed anywhere and no account exists on this Mac, so
125
+ nothing can be driven end to end.
126
+
127
+ - **Resolver.** SiteDesk-shaped text yields `output,quotes`. No ontology region
128
+ yields `output`. A dir absent from the allowed block is dropped. A region
129
+ written with an em dash yields zero buckets, which asserts the hyphen contract
130
+ rather than assuming it. Missing file yields nothing.
131
+ - **Walker.** Fixture tree carrying `output/`, `quotes/`, `documents/`,
132
+ `uploads/`, `.claude/` produces rows for the first two only, at any depth.
133
+ Delete leaves no stale row; rename produces one row at the new path; a
134
+ repeated run is identical.
135
+ - **Listing.** Account A never sees account B's rows. Prefix filtering
136
+ synthesises directories from paths. A `people` row with no `accountId` returns
137
+ an empty list, not an error.
138
+ - **Signing.** Round trip verifies. Expired fails. Tampered path fails. Tampered
139
+ account fails. Parity: a token minted by the portal module verifies with the
140
+ install's own function, so the two implementations cannot drift unnoticed.
141
+ - **Fetch route.** Well-signed request for a non-exposed path is refused. Path
142
+ traversal is refused. Exposed path serves with the right content type.
143
+ - **Regression.** The existing 139 tests across 10 files stay green.
144
+ `typecheck:templates` stays at exit 0.
145
+
146
+ ## Out of scope
147
+
148
+ The upload ingestion sweep; client write-back, delete or rename; mirroring bytes
149
+ into R2; recording write provenance (the SiteDesk quote engine writes through its
150
+ own tool, not `Write`/`Edit`, so `quotes/` would never register); fixing the
151
+ plugin-owned name collision; search; the `/data` admin browser.
152
+
153
+ ## Dependencies
154
+
155
+ `people.accountId` is new, so existing enrolments are re-run — the upsert on
156
+ `ownerId` makes that a re-run, not a migration. Each portal-serving account needs
157
+ a seeded `SCHEMA.md` or it exposes nothing. Downloads need the install reachable
158
+ at its tunnel hostname; listing does not.
159
+
160
+ The heartbeat spawn this copies
161
+ (`plugins/scheduling/mcp/src/scripts/check-due-events.ts:797`) has never been
162
+ observed running on a Pi, which is Task 1828. `portal-index-push.mjs` is
163
+ therefore runnable standalone, so it stays operable while 1828 is open.