@teamscala/service-boot 0.23.329 → 0.23.331

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 (157) hide show
  1. package/package.json +538 -522
  2. package/src/agreement-gate.d.ts +19 -0
  3. package/src/asset-cache-key.d.ts +11 -0
  4. package/src/asset-optimize.d.ts +17 -0
  5. package/src/asset-proxy.d.ts +11 -0
  6. package/src/asset-social-card.d.ts +17 -0
  7. package/src/attach-agreement-magic.d.ts +20 -0
  8. package/src/attach-portal-members.d.ts +23 -0
  9. package/src/attach-proposal-accept.d.ts +26 -0
  10. package/src/attach-proposal-magic.d.ts +18 -0
  11. package/src/attach-transfers-upload.d.ts +27 -0
  12. package/src/auth-gate.d.ts +28 -0
  13. package/src/auth-gate.ts +6 -68
  14. package/src/bind-page-handler.d.ts +18 -0
  15. package/src/build-client-assets/input-hashing.d.ts +25 -0
  16. package/src/build-client-assets/source-candidates.d.ts +27 -0
  17. package/src/build-client-assets.d.ts +50 -0
  18. package/src/build-client-assets.test.ts +1 -1
  19. package/src/build-client-assets.ts +1 -1
  20. package/src/compose-page-title.d.ts +41 -0
  21. package/src/content-gate/access.d.ts +15 -0
  22. package/src/content-gate/config-types.d.ts +99 -0
  23. package/src/content-gate/gate.d.ts +13 -0
  24. package/src/content-gate/parse-cookie.d.ts +9 -0
  25. package/src/content-gate/token.d.ts +48 -0
  26. package/src/content-page-floor.d.ts +39 -0
  27. package/src/discover-blocks.d.ts +28 -0
  28. package/src/discover-blocks.ts +1 -1
  29. package/src/expand-roster.d.ts +34 -0
  30. package/src/fn-routers/agreement-completion-email.d.ts +14 -0
  31. package/src/fn-routers/agreement-send-router.d.ts +82 -0
  32. package/src/fn-routers/ai-health-router.d.ts +35 -0
  33. package/src/fn-routers/auth-router.d.ts +47 -0
  34. package/src/fn-routers/cache-admin-router.d.ts +57 -0
  35. package/src/fn-routers/chat-session-router.d.ts +219 -0
  36. package/src/fn-routers/email-defaults.d.ts +1 -0
  37. package/src/fn-routers/email-link-ttl.d.ts +1 -0
  38. package/src/fn-routers/index.d.ts +18 -0
  39. package/src/fn-routers/index.ts +0 -2
  40. package/src/fn-routers/panel-data-router.d.ts +19 -0
  41. package/src/fn-routers/persist-chat-messages.d.ts +36 -0
  42. package/src/fn-routers/plans-router.d.ts +25 -0
  43. package/src/fn-routers/proposal-send-router.d.ts +58 -0
  44. package/src/fn-routers/public-agreement-router.d.ts +289 -0
  45. package/src/fn-routers/public-assessment-router.d.ts +68 -0
  46. package/src/fn-routers/public-gpt-session-router.d.ts +143 -0
  47. package/src/fn-routers/sign-in-flow-router.d.ts +107 -0
  48. package/src/fn-routers/task-sync-assign.d.ts +305 -0
  49. package/src/fn-routers/task-sync-assign.test.ts +1 -2
  50. package/src/fn-routers/task-sync-assign.ts +4 -4
  51. package/src/fn-routers/task-sync-bind.test.ts +18 -18
  52. package/src/fn-routers/task-sync-brief.d.ts +96 -0
  53. package/src/fn-routers/task-sync-brief.test.ts +17 -20
  54. package/src/fn-routers/task-sync-brief.ts +14 -15
  55. package/src/fn-routers/task-sync-close.d.ts +41 -0
  56. package/src/fn-routers/task-sync-dispatch.d.ts +61 -0
  57. package/src/fn-routers/task-sync-dispatch.test.ts +33 -51
  58. package/src/fn-routers/task-sync-dispatch.ts +124 -0
  59. package/src/fn-routers/task-sync-lane.d.ts +49 -0
  60. package/src/fn-routers/task-sync-lane.ts +125 -0
  61. package/src/fn-routers/task-sync-projection.d.ts +121 -0
  62. package/src/fn-routers/task-sync-projection.test.ts +0 -26
  63. package/src/fn-routers/task-sync-projection.ts +0 -51
  64. package/src/fn-routers/task-sync-rename.d.ts +91 -0
  65. package/src/fn-routers/task-sync-router.d.ts +444 -0
  66. package/src/fn-routers/task-sync-router.test.ts +2 -14
  67. package/src/fn-routers/task-sync-router.ts +1111 -0
  68. package/src/fn-routers/tasks-router.d.ts +25 -0
  69. package/src/fn-routers/user-preferences-router.d.ts +77 -0
  70. package/src/fn-routers/work-items-router.d.ts +102 -0
  71. package/src/gate-ttls.d.ts +6 -0
  72. package/src/gpt-gate.d.ts +25 -0
  73. package/src/handlers/bun-stable-watch.d.ts +1 -0
  74. package/src/handlers/pane-outbox-drain.d.ts +1 -0
  75. package/src/handlers/projects-digest.d.ts +26 -0
  76. package/src/handlers/prune-stale-data.d.ts +30 -0
  77. package/src/handlers/registry-stale-inactive-sweep.d.ts +1 -0
  78. package/src/handlers/scala-tools-currency-watch.d.ts +1 -0
  79. package/src/handlers/singleton-tools-currency-watch.d.ts +1 -0
  80. package/src/handlers/sweep-event-log.d.ts +1 -0
  81. package/src/handlers/sweep-host-cache.d.ts +1 -0
  82. package/src/handlers/sweep-host-cache.ts +26 -143
  83. package/src/handlers/upstream-issue-sync.d.ts +1 -0
  84. package/src/handlers/whatsapp-liveness-logic.d.ts +34 -0
  85. package/src/handlers/whatsapp-liveness.d.ts +4 -0
  86. package/src/hono-error-handler.d.ts +25 -0
  87. package/src/install-harness.d.ts +45 -0
  88. package/src/install-logging.d.ts +34 -0
  89. package/src/load-service-install-row.d.ts +24 -0
  90. package/src/load-service-prisma-client.d.ts +18 -0
  91. package/src/mount-orpc-router.d.ts +15 -0
  92. package/src/mount-orpc-router.ts +1 -1
  93. package/src/mount-server-packages.d.ts +29 -0
  94. package/src/mount.d.ts +9 -0
  95. package/src/mutable-app-ref.d.ts +44 -0
  96. package/src/page-route-shell-types.d.ts +12 -0
  97. package/src/page-server-orpc/audit-revert-router.d.ts +37 -0
  98. package/src/page-server-orpc/hub-mcp-client.d.ts +12 -0
  99. package/src/page-server-orpc/portal-diagnostics-router.d.ts +49 -0
  100. package/src/page-server-orpc/puck-pages-router.d.ts +58 -0
  101. package/src/page-server-orpc/server-client.d.ts +16 -0
  102. package/src/page-server-orpc/templates-router.d.ts +34 -0
  103. package/src/page-server-orpc/user-preferences-router.d.ts +79 -0
  104. package/src/pg-boss-handler-registry.d.ts +27 -0
  105. package/src/pg-boss-mount.d.ts +42 -0
  106. package/src/proposal-authorized-emails.d.ts +28 -0
  107. package/src/proposal-chat-inject.d.ts +17 -0
  108. package/src/proposal-gate.d.ts +18 -0
  109. package/src/read-html-template.d.ts +38 -0
  110. package/src/read-viewport-from-request.d.ts +18 -0
  111. package/src/readiness-gate.d.ts +16 -0
  112. package/src/register-api-routes.d.ts +18 -0
  113. package/src/register-crash-handlers.d.ts +15 -0
  114. package/src/register-page-routes.d.ts +27 -0
  115. package/src/register-page-routes.ts +3 -0
  116. package/src/register-page-server-client.d.ts +11 -0
  117. package/src/register-registry-page-route/ai-chat-prefetch.d.ts +13 -0
  118. package/src/register-registry-page-route/graph-cache.d.ts +30 -0
  119. package/src/register-registry-page-route/meta-title.d.ts +2 -0
  120. package/src/register-registry-page-route/proposal-approval-email-token.d.ts +14 -0
  121. package/src/register-registry-page-route/proposal-brand-stamping.d.ts +28 -0
  122. package/src/register-registry-page-route/resolve-page-data.d.ts +1 -0
  123. package/src/register-registry-page-route.d.ts +27 -0
  124. package/src/register-static-assets.d.ts +13 -0
  125. package/src/register-ws-routes.d.ts +28 -0
  126. package/src/resolve-app-base-url.d.ts +13 -0
  127. package/src/resolve-brand-favicon.d.ts +28 -0
  128. package/src/resolve-brand-favicon.ts +1 -1
  129. package/src/resolve-from-loader-config.d.ts +32 -0
  130. package/src/resolve-service-context.d.ts +17 -0
  131. package/src/resolve-service-port.d.ts +75 -0
  132. package/src/resolve-theme-mode.d.ts +42 -0
  133. package/src/resolvers/fetch-org-brand.d.ts +2 -0
  134. package/src/resolvers/portal-route-paths.d.ts +39 -0
  135. package/src/resolvers/website-by-host-map.d.ts +12 -0
  136. package/src/resource-chat-inject.d.ts +46 -0
  137. package/src/resource-not-found.d.ts +60 -0
  138. package/src/run-boot-hook-list.d.ts +19 -0
  139. package/src/run-boot-hooks.d.ts +31 -0
  140. package/src/scala-tools-currency-watchdog.d.ts +10 -0
  141. package/src/security-headers.d.ts +12 -0
  142. package/src/serve/serve.d.ts +46 -0
  143. package/src/serve/stamp-transport-identity.d.ts +32 -0
  144. package/src/serve/stamp-transport-identity.ts +2 -14
  145. package/src/server-error-page.d.ts +29 -0
  146. package/src/start-scheduled-jobs.d.ts +18 -0
  147. package/src/two-phase-boot.d.ts +136 -0
  148. package/src/two-phase-boot.ts +17 -85
  149. package/src/two-phase-health-gate.test.ts +2 -13
  150. package/src/types.d.ts +46 -0
  151. package/src/ui-service.d.ts +46 -0
  152. package/src/ws-boot-self-test.d.ts +19 -0
  153. package/src/auth-gate.test.ts +0 -70
  154. package/src/fn-routers/task-sync-lane.test.ts +0 -36
  155. package/src/handlers/sweep-host-cache.test.ts +0 -133
  156. package/src/serve/stamp-transport-identity.test.ts +0 -24
  157. package/src/two-phase-health-gate-client-only.test.ts +0 -77
@@ -0,0 +1,444 @@
1
+ /**
2
+ * @system service-boot
3
+ * @status handwritten
4
+ * @edit edit directly
5
+ * @indivisible-unit
6
+ *
7
+ * CLI-AGNOSTIC task-sync CORE — the bridge between a lane's native task list
8
+ * (Claude Code TodoWrite, OpenCode todowrite, future CLIs) and the `work_items`
9
+ * table, which is the single source of truth for "what work does this lane
10
+ * have." Detailed contract + the per-CLI adapter split: apps/agent-fleet.md
11
+ * (task-sync section).
12
+ *
13
+ * Design (operator requirement): work_items is the source; each CLI's task list
14
+ * is a WRITE-THROUGH PROJECTION, never a peer. One source + write-through
15
+ * projection cannot diverge by construction — no two-way sync, no conflict
16
+ * resolution. The lane↔task binding is SYMMETRIC: a lane is a lane whether the
17
+ * pane is an orchestrator or a supervised agent (both have tasks).
18
+ *
19
+ * Mapping: an operator request = a kind='task' work_item; the lane's todo items
20
+ * = kind='subtask' rows under it via parent_id. The task carries the lane
21
+ * identity in kind_data.lane = { pane, session, cli_kind, role } so any surface
22
+ * (fleet UI, another lane) can resolve "who owns this work" and push changes
23
+ * back. Binding is by pane identity (the stable $TMUX_PANE), not by fleet run —
24
+ * so it works before/without the fleet_agent_runs.work_item_id join (that column
25
+ * is a UI convenience for the unified lane+task+subtask view, not a dependency).
26
+ *
27
+ * These procedures are the ONLY CLI-agnostic surface an adapter calls:
28
+ * bindLane — bind (create-or-confirm) a lane's task. SessionStart.
29
+ * closeLane — reconcile a session-owned lane before its runtime releases it.
30
+ * upsertFromTaskList — write a lane's current task list through to subtasks (AGENT→DB leg, OpenCode whole-list).
31
+ * upsertFromTaskHook — apply a per-item Claude Code PostToolUse:TaskCreate/Update/Delete (AGENT→DB leg, Claude per-item).
32
+ * readTaskList — read a lane's current subtasks as a normalized list (DB→AGENT backstop).
33
+ * applyExternalChange — record an out-of-band subtask change + notify the owning lane (DB→AGENT realtime leg).
34
+ * A CLI with no native task surface (Codex today — upstream_issue openai-codex-2966)
35
+ * has NO adapter: it degrades to work_items-only. The work is still tracked and
36
+ * visible in the projects UI; the lane simply has no live projection. That is a
37
+ * legitimate end state, not a gap to paper over with a fake adapter.
38
+ */
39
+ import { type Context } from "./auth-router.ts";
40
+ import * as v from "valibot";
41
+ /** A lane's native task-list item, normalized. Every CLI adapter maps to this. */
42
+ export interface TaskListItem {
43
+ content: string;
44
+ status: "pending" | "in_progress" | "completed";
45
+ /** CLI-native stable id when the CLI provides one (TodoWrite has none; opencode todo row id). */
46
+ mark?: string;
47
+ }
48
+ /**
49
+ * Input contract for upsertFromTaskList. oRPC does NOT parse the JSON body into
50
+ * `input` for a schema-less procedure (see the bindLane comment in this file) —
51
+ * so without an explicit `.input()` schema, `input.lane_session` is ALWAYS
52
+ * undefined and the procedure throws "requires lane_session" unconditionally.
53
+ * Measured 2026-07-29: every pi/opencode whole-list `task_list` publish 400'd
54
+ * for exactly this reason (the per-item upsertFromTaskHook path worked because
55
+ * it unwraps `raw.json ?? raw`). Declaring the schema is the documented remedy
56
+ * and the pattern every other `authed.input(...)` procedure in service-boot
57
+ * already follows. The pi adapter (scala-hooks.ts syncTaskList) already sends
58
+ * `{ lane_session, task_list, source }` — it was always valid; the server never
59
+ * read it.
60
+ */
61
+ export declare const upsertFromTaskListInput: v.ObjectSchema<{
62
+ readonly lane_session: v.StringSchema<undefined>;
63
+ readonly task_list: v.ArraySchema<v.ObjectSchema<{
64
+ readonly content: v.StringSchema<undefined>;
65
+ readonly status: v.PicklistSchema<["pending", "in_progress", "completed"], undefined>;
66
+ readonly mark: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
67
+ }, undefined>, undefined>;
68
+ readonly source: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
69
+ }, undefined>;
70
+ /** Who a lane IS — symmetric across orchestrator/agent roles and across CLIs. */
71
+ export interface LaneIdentity {
72
+ /** "tmux:%42" — authoritative pane identity ($TMUX_PANE). */
73
+ pane: string;
74
+ session?: string;
75
+ /** pane-inventory inferCliKind: claude-code | opencode | codex | unknown. */
76
+ cli_kind?: string;
77
+ /** agent | orchestrator — both have tasks; the model does not assume a supervised agent. */
78
+ role?: string;
79
+ /**
80
+ * Optional. work_items.organisation_id is NOT NULL; when the caller omits it
81
+ * (auto-bind at SessionStart — an adopted or channel-dispatched lane has no
82
+ * client org), bindLane defaults to the platform org via resolveBindOrg.
83
+ */
84
+ organisation_id?: string;
85
+ }
86
+ export interface WorkItem {
87
+ id: string;
88
+ kind: string;
89
+ parent_id: string | null;
90
+ organisation_id: string;
91
+ title: string;
92
+ status: string | null;
93
+ position: string | null;
94
+ completed: boolean | null;
95
+ kind_data: Record<string, unknown>;
96
+ }
97
+ export type Prisma = {
98
+ work_items: {
99
+ findFirst: (a: unknown) => Promise<WorkItem | null>;
100
+ findMany: (a: unknown) => Promise<WorkItem[]>;
101
+ create: (a: unknown) => Promise<WorkItem>;
102
+ update: (a: unknown) => Promise<WorkItem>;
103
+ deleteMany: (a: unknown) => Promise<{
104
+ count: number;
105
+ }>;
106
+ };
107
+ comments?: {
108
+ findFirst: (a: unknown) => Promise<CommentRow | null>;
109
+ };
110
+ };
111
+ /** A `comments` row — only the fields readAssignedBrief touches. */
112
+ export interface CommentRow {
113
+ content: string;
114
+ created_at: Date;
115
+ }
116
+ /**
117
+ * A dispatched run already points at its fleet_tasks row. Task-sync may fill
118
+ * the convenience join for an adopted lane, but must never replace that
119
+ * dispatch identity with the lane's work_items projection id.
120
+ */
121
+ export declare function untrackedRunForPane(pane: string): {
122
+ pane: string;
123
+ state: {
124
+ not: string;
125
+ };
126
+ tracked_task_id: null;
127
+ };
128
+ /**
129
+ * Resolve the org a lane's task is created under. Explicit when the lane knows
130
+ * its org (a dispatched fleet lane carries one); defaults to the platform org
131
+ * otherwise — an adopted or channel-dispatched pane has no client org, and the
132
+ * platform org is the home for fleet/internal lane tasks (where the operator's
133
+ * PM view reads), so auto-bind at SessionStart seeds the task there.
134
+ */
135
+ export declare function resolveBindOrg(explicit?: string): string;
136
+ /**
137
+ * Record a task-sync hook DISCARD to event_log so it is observable + queryable,
138
+ * not silently swallowed by the hook command's `>/dev/null 2>&1 || true`. The
139
+ * endpoint records it server-side regardless of what the hook does with stdout.
140
+ * Fire-and-forget per event-log-is-the-only-durable-event-log. The headline
141
+ * discard is "no-task-bound" (lane has no bound parent task — exactly the gap
142
+ * that SessionStart auto-bind closes; once binding is automatic this becomes a
143
+ * rare safety signal rather than the default outcome).
144
+ */
145
+ export declare function recordTaskSyncDiscard(reason: string, pane: string | null, extra?: Record<string, unknown>): void;
146
+ /**
147
+ * Record a discard AND return the soft {applied:false} body in one step — every
148
+ * no-op path in upsertFromTaskHook goes through here so none can silently drop
149
+ * an event. The returned shape matches the prior `{applied:false, reason,...}`.
150
+ */
151
+ export declare function discardApplied(reason: string, pane: string | null, extra?: Record<string, unknown>): {
152
+ applied: false;
153
+ reason: string;
154
+ } & Record<string, unknown>;
155
+ /**
156
+ * Trim a task subject at the first tool-call marker.
157
+ *
158
+ * A subject arriving as `Cut judge false positives</subject>\n<parameter
159
+ * name="description">Live gate blocks ~half...` is not a title with odd
160
+ * punctuation — it is the raw tool call, and it renders on the dashboard as a
161
+ * wall of XML where the operator expects a task name (observed live 2026-07-25,
162
+ * 3 rows). The malformation happens upstream in the CLI's hook payload, which
163
+ * this service does not control, so the defence belongs at the WRITE boundary:
164
+ * `work_items` is the single source of truth for every surface, and once a
165
+ * corrupted title lands there every reader shows it.
166
+ *
167
+ * Truncating rather than rejecting is deliberate: the text BEFORE the marker is
168
+ * the real subject and is worth keeping. Dropping the row instead would lose a
169
+ * task the lane genuinely created.
170
+ */
171
+ export declare function sanitizeTaskSubject(raw: string): string;
172
+ export declare function classifyTaskHookEvent(evt: {
173
+ hook_event_name?: unknown;
174
+ task_subject?: unknown;
175
+ }): "completed" | "created" | "tool";
176
+ export declare const taskSyncRouter: {
177
+ /**
178
+ * Bind (create-or-confirm) the task a lane owns. Called from a SessionStart
179
+ * adapter so the lane has a durable task row before its first todo write.
180
+ * Idempotent: re-binding updates the identity (role/cli_kind can change) but
181
+ * never orphans existing subtasks. After binding, links the lane's
182
+ * fleet_agent_runs row (matched by pane) to the task via tracked_task_id —
183
+ * the join the operator's lane-labels monitor + the unified fleet view read.
184
+ */
185
+ bindLane: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
186
+ headers: Headers;
187
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
188
+ prisma: any;
189
+ user: import("./auth-router.ts").User;
190
+ orgId: string | null | undefined;
191
+ }>, v.OptionalSchema<v.ObjectSchema<{
192
+ readonly lane: v.OptionalSchema<v.ObjectSchema<{
193
+ readonly pane: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
194
+ readonly session: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
195
+ readonly cli_kind: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
196
+ readonly role: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
197
+ readonly organisation_id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
198
+ }, undefined>, undefined>;
199
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
200
+ readonly parent_id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
201
+ }, undefined>, undefined>, import("@orpc/contract").Schema<{
202
+ task_id: string;
203
+ created: boolean;
204
+ }, {
205
+ task_id: string;
206
+ created: boolean;
207
+ }>, Record<never, never>, Record<never, never>>;
208
+ /**
209
+ * AGENT→DB leg. Write a lane's CURRENT task list through to subtasks. The
210
+ * list is authoritative for this lane (it's what the CLI just rendered), so
211
+ * this is a full reconcile: create/update/delete to match. Matching is by
212
+ * stable mark when the CLI provides one, else by content. Does NOT dispatch
213
+ * a change notification — the lane that authored the list already has it.
214
+ */
215
+ upsertFromTaskList: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
216
+ headers: Headers;
217
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
218
+ prisma: any;
219
+ user: import("./auth-router.ts").User;
220
+ orgId: string | null | undefined;
221
+ }>, v.ObjectSchema<{
222
+ readonly lane_session: v.StringSchema<undefined>;
223
+ readonly task_list: v.ArraySchema<v.ObjectSchema<{
224
+ readonly content: v.StringSchema<undefined>;
225
+ readonly status: v.PicklistSchema<["pending", "in_progress", "completed"], undefined>;
226
+ readonly mark: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
227
+ }, undefined>, undefined>;
228
+ readonly source: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
229
+ }, undefined>, import("@orpc/contract").Schema<{
230
+ task_id: string;
231
+ created: number;
232
+ updated: number;
233
+ deleted: number;
234
+ total: number;
235
+ }, {
236
+ task_id: string;
237
+ created: number;
238
+ updated: number;
239
+ deleted: number;
240
+ total: number;
241
+ }>, Record<never, never>, Record<never, never>>;
242
+ /**
243
+ * Claude Code PostToolUse:TaskCreate/TaskUpdate hook entry. Claude Code's
244
+ * todo tool is the per-item Task* family (TaskCreate/TaskUpdate) — TodoWrite
245
+ * was REMOVED in recent Claude Code; the hook matcher keys on
246
+ * TaskCreate/TaskUpdate, never TodoWrite. The hook command posts the RAW hook
247
+ * event (stdin) + an x-lane-pane header (tmux:$TMUX_PANE). Fired as a
248
+ * PostToolUse:TaskCreate/Update hook (NOT a "TaskCreated" event — that is
249
+ * not a real Claude Code hook event + never fired); this procedure
250
+ * applies the per-item change (TaskCreate → new subtask keyed by the harness
251
+ * task id; TaskUpdate → status/title flip on the matching subtask). Server-
252
+ * side extraction keeps the hook command a trivial jq|curl. Accepts the event
253
+ * raw (input.tool_name) OR oRPC-enveloped (input.json.tool_name). Session-
254
+ * less: fn.taskSync is page-gate-exempt; localhost pane shell authenticates
255
+ * as super-admin via resolveUser. Soft-returns on any no-op (never throws).
256
+ */
257
+ upsertFromTaskHook: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
258
+ headers: Headers;
259
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
260
+ prisma: any;
261
+ user: import("./auth-router.ts").User;
262
+ orgId: string | null | undefined;
263
+ }>, import("@orpc/contract").Schema<unknown, unknown>, import("@orpc/contract").Schema<{
264
+ applied: boolean;
265
+ op: string;
266
+ taskId: string;
267
+ } | ({
268
+ applied: false;
269
+ reason: string;
270
+ } & Record<string, unknown>), {
271
+ applied: boolean;
272
+ op: string;
273
+ taskId: string;
274
+ } | ({
275
+ applied: false;
276
+ reason: string;
277
+ } & Record<string, unknown>)>, Record<never, never>, Record<never, never>>;
278
+ /**
279
+ * DB→AGENT backstop read. Returns the lane's current subtasks in the
280
+ * normalized shape every CLI adapter maps to its native list. Called by the
281
+ * SessionStart/UserPromptSubmit adapters so a pane never opens or continues
282
+ * on stale tasks, and by a lane after it receives a "your tasks changed"
283
+ * channel notification.
284
+ */
285
+ readTaskList: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
286
+ headers: Headers;
287
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
288
+ prisma: any;
289
+ user: import("./auth-router.ts").User;
290
+ orgId: string | null | undefined;
291
+ }>, import("@orpc/contract").Schema<unknown, unknown>, import("@orpc/contract").Schema<{
292
+ task_id: null;
293
+ task_title: null;
294
+ subtasks: never[];
295
+ } | {
296
+ task_id: string;
297
+ task_title: string;
298
+ subtasks: TaskListItem[];
299
+ }, {
300
+ task_id: null;
301
+ task_title: null;
302
+ subtasks: never[];
303
+ } | {
304
+ task_id: string;
305
+ task_title: string;
306
+ subtasks: TaskListItem[];
307
+ }>, Record<never, never>, Record<never, never>>;
308
+ /**
309
+ * DB→AGENT self-brief leg. A spawned lane PULLS its own brief — nothing is
310
+ * pasted, typed, passed as an argument or sent over a channel
311
+ * (`action-emission-architecture.md` "The lane PULLS its brief"). The lane's
312
+ * CLI extension reads its own session id on load, calls this procedure, and
313
+ * reads the brief from the task's LATEST comment. The comment — not the
314
+ * description, not a stale comment — is the brief for THIS run: every spawn
315
+ * writes a NEW comment, so "what was this lane told" always has exactly one
316
+ * answer (`assignment-as-dispatch`). Handler lives in task-sync-brief.ts
317
+ * (router is at its line budget); mounted here so fn.taskSync surfaces it.
318
+ */
319
+ readAssignedBrief: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
320
+ headers: Headers;
321
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
322
+ prisma: any;
323
+ user: import("./auth-router.ts").User;
324
+ orgId: string | null | undefined;
325
+ }>, import("@orpc/contract").Schema<unknown, unknown>, import("@orpc/contract").Schema<{
326
+ work_item_id: string | null;
327
+ brief: string | null;
328
+ comment_created_at: string | null;
329
+ status: import("./task-sync-brief.ts").BriefReadStatus;
330
+ }, {
331
+ work_item_id: string | null;
332
+ brief: string | null;
333
+ comment_created_at: string | null;
334
+ status: import("./task-sync-brief.ts").BriefReadStatus;
335
+ }>, Record<never, never>, Record<never, never>>;
336
+ /** SPAWNER→DB brief mint: `spawn_agent_tab` turns an initialPrompt into the task row (brief = first comment) the lane self-briefs from; returns the work_item_id that rides the spawn payload. Handler in task-sync-assign.ts. */
337
+ createBriefTask: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
338
+ headers: Headers;
339
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
340
+ prisma: any;
341
+ user: import("./auth-router.ts").User;
342
+ orgId: string | null | undefined;
343
+ }>, import("@orpc/contract").Schema<unknown, unknown>, import("@orpc/contract").Schema<{
344
+ work_item_id: string;
345
+ }, {
346
+ work_item_id: string;
347
+ }>, Record<never, never>, Record<never, never>>;
348
+ /** RUNTIME→DB lifecycle close: mark lane.live=false and reconcile task status before the ACP owner releases the session. */
349
+ closeLane: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
350
+ headers: Headers;
351
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
352
+ prisma: any;
353
+ user: import("./auth-router.ts").User;
354
+ orgId: string | null | undefined;
355
+ }>, v.ObjectSchema<{
356
+ readonly lane_session: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "lane_session is required">]>;
357
+ readonly disposition: v.PicklistSchema<["completed", "needs_retry", "failed", "orchestrator_closed", "orphaned"], undefined>;
358
+ }, undefined>, import("@orpc/contract").Schema<{
359
+ task_id: string;
360
+ task_status: "archived" | "done";
361
+ reconciled: boolean;
362
+ }, {
363
+ task_id: string;
364
+ task_status: "archived" | "done";
365
+ reconciled: boolean;
366
+ }>, Record<never, never>, Record<never, never>>;
367
+ /**
368
+ * TAB→DB rename back-write: the session-picker `/rpc/rename` calls this after
369
+ * renaming a tmux window to update the bound task's title BY SESSION (never
370
+ * pane), so the tab bar and the project board never diverge
371
+ * (`tab-rename-emits-back-to-task-title`). Handler in task-sync-rename.ts.
372
+ */
373
+ renameLaneTask: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
374
+ headers: Headers;
375
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
376
+ prisma: any;
377
+ user: import("./auth-router.ts").User;
378
+ orgId: string | null | undefined;
379
+ }>, v.ObjectSchema<{
380
+ readonly lane_session: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "lane_session is required">]>;
381
+ readonly title: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "title is required">]>;
382
+ }, undefined>, import("@orpc/contract").Schema<{
383
+ task_id: string | null;
384
+ updated: boolean;
385
+ }, {
386
+ task_id: string | null;
387
+ updated: boolean;
388
+ }>, Record<never, never>, Record<never, never>>;
389
+ /**
390
+ * DB→AGENT realtime leg (explicit dispatch path). Record an out-of-band
391
+ * change to a subtask's status (operator toggles it in the projects UI,
392
+ * another lane edits a shared task) and notify the OWNING lane's pane that
393
+ * its projection is stale. The pane's adapter re-reads (readTaskList) and
394
+ * updates its native list. Symmetric counterpart to upsertFromTaskList:
395
+ * there the lane is the originator (no self-echo); here the lane is the
396
+ * recipient.
397
+ *
398
+ * COMPLETION STEP (not MVP): this procedure is the explicit trigger. For
399
+ * FULL coverage — every work_items subtask write, including the projects
400
+ * UI's generated CRUD — a Postgres trigger + LISTEN subscriber on
401
+ * scala-channel fires the same publish, so an operator edit reaches the
402
+ * lane with no explicit call. Tracked in apps/agent-fleet.md task-sync.
403
+ */
404
+ applyExternalChange: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
405
+ headers: Headers;
406
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
407
+ prisma: any;
408
+ user: import("./auth-router.ts").User;
409
+ orgId: string | null | undefined;
410
+ }>, import("@orpc/contract").Schema<unknown, unknown>, import("@orpc/contract").Schema<{
411
+ task_id: string;
412
+ lane_pane: string | null;
413
+ notified: boolean;
414
+ }, {
415
+ task_id: string;
416
+ lane_pane: string | null;
417
+ notified: boolean;
418
+ }>, Record<never, never>, Record<never, never>>;
419
+ };
420
+ /**
421
+ * The Claude Code per-item task lifecycle applied to a lane's work_items
422
+ * subtasks — the AGENT→DB leg for the Task* tool family (TaskCreate /
423
+ * TaskUpdate / TaskDelete) and the dedicated TaskCreated / TaskCompleted events.
424
+ *
425
+ * Extracted verbatim from the upsertFromTaskHook ORPC handler so the FULL
426
+ * lifecycle — created, in_progress, completed, deleted — is unit-testable with a
427
+ * mock prisma (same testability split as claim-orchestrator-session, and the
428
+ * router-handlers-only-execute half of planReconcile). The ORPC handler is now a
429
+ * thin `authed` wrapper that delegates here; this function takes the exact
430
+ * `(input, context)` the handler would have bound, so behaviour is unchanged.
431
+ *
432
+ * `task-projection-converges`: every state a task reaches must write through, or
433
+ * the projection is an append-only log and the operator cannot see what a lane is
434
+ * doing. The matcher covering TaskCreate|TaskUpdate|TaskDelete is what makes all
435
+ * four states reach this handler; this body is what applies them.
436
+ */
437
+ export declare function upsertFromTaskHookHandler(input: unknown, context: Context): Promise<{
438
+ applied: boolean;
439
+ op: string;
440
+ taskId: string;
441
+ } | ({
442
+ applied: false;
443
+ reason: string;
444
+ } & Record<string, unknown>)>;
@@ -337,20 +337,8 @@ describe("a blocked row survives a CLI list that cannot express it", () => {
337
337
  it("planReconcile leaves a blocked subtask blocked when the list says pending", () => {
338
338
  // The end-to-end shape: this is what re-blocked the lane three times.
339
339
  const plan = planReconcile(
340
- [
341
- {
342
- id: "row-1",
343
- kind: "subtask",
344
- parent_id: "task-1",
345
- organisation_id: "org-1",
346
- title: "Deploy the fix",
347
- status: "blocked",
348
- position: "0",
349
- completed: false,
350
- kind_data: { task_sync: { mark: "1" } },
351
- },
352
- ],
353
- [{ content: "Deploy the fix", status: "pending" }],
340
+ [{ mark: "1", content: "Deploy the fix", status: "pending" }],
341
+ [{ id: "row-1", title: "Deploy the fix", status: "blocked", completed: false, position: "0", kind_data: { task_sync: { mark: "1" } } }] as never,
354
342
  "claude-code",
355
343
  );
356
344
  const update = plan.toUpdate.find((u) => u.id === "row-1");