@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,125 @@
1
+ /**
2
+ * @system service-boot
3
+ * @status handwritten
4
+ * @edit edit directly
5
+ *
6
+ * Lane RESOLUTION for task-sync: given a session or a pane, which work_items
7
+ * task IS this lane, and what is it called.
8
+ *
9
+ * Split out of task-sync-router.ts, which had reached 998 of its 1000-line
10
+ * budget — two lines from frozen. That is not tidiness: the budget is a commit
11
+ * gate, so at 998 lines ANY change to task-sync was blocked for every lane, and
12
+ * the four-line fix that needed to land could not. The router header records
13
+ * being split once before for exactly this reason; it grew back.
14
+ *
15
+ * The seam matches the one that split the projection. Everything here answers
16
+ * "which lane, called what" from an identity, and none of it touches the ORPC
17
+ * surface or decides what a task list should become — which is why these move
18
+ * together rather than one at a time: resolveLaneTask alone has seven callers.
19
+ *
20
+ * CAPABILITY HARVEST (capability-harvest-on-split): APP-LOCAL, not a capability
21
+ * candidate. Checked against the 14 platform singletons and the package
22
+ * catalogue; the doctrine test fails plainly, because every export is bound to
23
+ * the work_items schema and to task-sync own kind_data.lane convention, so no
24
+ * unrelated app could install this unmodified.
25
+ */
26
+
27
+ import type { Prisma, WorkItem } from "./task-sync-router.ts";
28
+
29
+ export async function resolveLaneWorkName(prisma: Prisma, pane: string): Promise<string | null> {
30
+ try {
31
+ const runs = (
32
+ prisma as unknown as {
33
+ fleet_agent_runs?: {
34
+ findFirst: (a: unknown) => Promise<{ slot_name?: string | null } | null>;
35
+ };
36
+ }
37
+ ).fleet_agent_runs;
38
+ if (!runs?.findFirst) return null;
39
+ // Most recent run for the pane, REGARDLESS of state. A lane's work name does
40
+ // not vanish when its run closes, and filtering `state != closed` here is
41
+ // exactly why task rows were titled "Lane": a task-list write (ensureLaneTask)
42
+ // that fires after the run closed resolved no name and fell back to the
43
+ // generic sentinel — spawn debris an orchestrator cannot attribute
44
+ // (measured 2026-08-01: 207 "Lane" rows). Newest-first so a reused pane
45
+ // resolves its CURRENT lane, not a prior one.
46
+ const run = await runs.findFirst({
47
+ where: { pane },
48
+ orderBy: { created_at: "desc" },
49
+ select: { slot_name: true },
50
+ });
51
+ const name = run?.slot_name?.trim();
52
+ return name ? name : null;
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+
58
+ export async function resolveLaneTask(prisma: Prisma, session: string): Promise<WorkItem | null> {
59
+ const active = await prisma.work_items.findFirst({
60
+ where: {
61
+ kind: "task",
62
+ status: "active",
63
+ kind_data: { path: ["lane", "session"], equals: session },
64
+ },
65
+ // Deterministic by oldest. An unordered findFirst returns whichever row
66
+ // Postgres happens to hand back, so with two parents for one lane (the
67
+ // bindLane race, below) one turn wrote the lane's todos under parent A
68
+ // and the next read parent B and found nothing — the lane's task list
69
+ // appeared to empty itself, and the watchdog accused lanes that were
70
+ // holding a populated list. Migration 109 makes the duplicate
71
+ // unwritable; this makes the read stable regardless.
72
+ orderBy: { created_at: "asc" },
73
+ });
74
+ if (active) return active;
75
+
76
+ // FALL BACK TO AN ARCHIVED PARENT FOR THE SAME SESSION.
77
+ //
78
+ // Closing a run archives the lane's parent (close-run.ts) specifically to
79
+ // drop it from the active match set above. That is correct when the LANE is
80
+ // gone, and wrong whenever the run record closes while the lane keeps
81
+ // running — which happens on a tmux-server restart (runs are reaped, panes
82
+ // are restored) and whenever an orchestrator closes a run on a stale read.
83
+ // The lane then has a full task list that this function cannot see, so
84
+ // callers mint a FRESH parent, the old list is orphaned, and the compliance
85
+ // watchdog reports "working with NO task list" at a lane holding 85 tasks.
86
+ // That is the "KNOWN ADJACENT DEFECT" recorded on the lane-working-has-task-list
87
+ // guard row, observed live 2026-07-31.
88
+ //
89
+ // Safe because a session id is minted per lane spawn and never reused, so an
90
+ // archived parent under this session belongs to THIS lane. Newest-first.
91
+ return prisma.work_items.findFirst({
92
+ where: {
93
+ kind: "task",
94
+ status: "archived",
95
+ kind_data: { path: ["lane", "session"], equals: session },
96
+ },
97
+ orderBy: { created_at: "desc" },
98
+ });
99
+ }
100
+
101
+ /**
102
+ * Resolve a lane's task by its AUTHORITATIVE work_item id — the id the spawn
103
+ * minted (createBriefTask) and exported into the pane as SCALA_LANE_WORK_ITEM.
104
+ *
105
+ * WHY this exists alongside the session resolution: readAssignedBrief used to
106
+ * resolve ONLY by kind_data.lane.session, which is written by the lane's OWN
107
+ * bindLane hook at boot. That bind is a fire-and-forget POST racing the brief
108
+ * read, so a fleet lane whose bind had not yet commit read "no task" and the
109
+ * self-brief hook silently exited 0 — absent-input-reads-as-success at the
110
+ * dispatch boundary (a lane booted, was told its brief was loaded, had none,
111
+ * ran nothing, and was archived having done nothing — measured 2026-08-02).
112
+ *
113
+ * The work_item id is known to the spawn before the lane even starts
114
+ * (mintBriefTask returns it; the spawn REFUSES if minting fails for a capture
115
+ * CLI), so resolving by it CANNOT race: the row exists because the spawn
116
+ * created it. The session bind stays for task-list writes (upsertFromTaskList)
117
+ * — it is no longer load-bearing for brief delivery. Any status is matched
118
+ * (active OR archived) because the brief is the brief regardless of the run's
119
+ * state — closing a run archives the task, not the brief.
120
+ */
121
+ export async function resolveTaskById(prisma: Prisma, workItemId: string): Promise<WorkItem | null> {
122
+ return prisma.work_items.findFirst({
123
+ where: { id: workItemId, kind: "task" },
124
+ });
125
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @system service-boot
3
+ * @status handwritten
4
+ * @edit edit directly
5
+ *
6
+ * The task-sync PROJECTION: how a CLI's task list maps onto `work_items` rows,
7
+ * and what reconciling one against the other should do.
8
+ *
9
+ * Split out of `task-sync-router.ts`, which had grown past the 1000-line budget
10
+ * and so could not be committed by anyone touching it. The seam is real rather
11
+ * than arbitrary: everything here is PURE and decides WHAT should change, while
12
+ * the router owns the ORPC surface and performs the writes. That is exactly why
13
+ * this half is directly testable with no database.
14
+ *
15
+ * CAPABILITY HARVEST (capability-harvest-on-split): APP-LOCAL, not a capability
16
+ * candidate. Checked against the 14 platform singletons and the package catalog
17
+ * — nothing generic to fold into, and the doctrine test fails: no unrelated app
18
+ * could install this unmodified, because every export is bound to the
19
+ * `work_items` schema and task-sync's own contract (STATUS_TO_WORK_ITEM encodes
20
+ * the work_items status enum, subtaskKey is this projection's key convention,
21
+ * planReconcile diffs against work_items subtask rows).
22
+ *
23
+ * The near-miss is worth naming so the next reader does not re-derive it: the
24
+ * SHAPE — diff a desired list against existing rows into create/update/delete —
25
+ * is generic, and `document-signing` is precedent for lifting a pure domain half
26
+ * out of service-boot into a package. It stays here because it has exactly one
27
+ * consumer; extracting it now would be speculative packaging, which
28
+ * platform-capabilities treats as drift. Revisit if a SECOND surface needs
29
+ * list-against-rows reconciliation — then the generic diff core (not the
30
+ * work_items-specific mapping) is what earns a package.
31
+ */
32
+ import type { TaskListItem, WorkItem } from "./task-sync-router.ts";
33
+ /** CLI task-list status → work_items.status. The canonical forward direction. */
34
+ export declare const STATUS_TO_WORK_ITEM: Record<"completed" | "in_progress" | "pending", string>;
35
+ export declare function normalizeStatus(s: string | null): TaskListItem["status"];
36
+ /**
37
+ * Decide the status to WRITE for an existing row, given what the CLI list says.
38
+ *
39
+ * The CLI task list has no `blocked` state, so a blocked row round-trips as
40
+ * `pending` (via `normalizeStatus`, which collapses unknown/internal statuses)
41
+ * and then maps back to `todo` — silently destroying the block. That is not a
42
+ * cosmetic drift: the stop gate reads these rows, so un-blocking one re-blocks
43
+ * the LANE from stopping, and the lane's only apparent fix is to touch the list
44
+ * again, which destroys it again.
45
+ *
46
+ * A `todo` arriving from the CLI therefore carries NO information: it is what
47
+ * the projection emits for every status it cannot represent, not an assertion
48
+ * that the work became un-blocked. `in-progress` and `done` are different —
49
+ * those are real transitions the CLI CAN express, so they win normally.
50
+ *
51
+ * Measured 2026-07-30: a lane set a row to `blocked` with a named blocker, the
52
+ * next TaskUpdate reset it to `todo`, and the stop gate reported the lane
53
+ * unfinished again — three turns of ping-pong before the cause was found.
54
+ */
55
+ export declare function resolveProjectedStatus(currentStatus: string | null | undefined, incomingStatus: string): string;
56
+ export declare function subtaskKey(item: {
57
+ mark?: string;
58
+ content: string;
59
+ title: string;
60
+ }): string;
61
+ /**
62
+ * Pure decision for a TaskUpdate/TaskDelete: which existing subtask does this
63
+ * event address, and what should happen when none does. Extracted for the same
64
+ * reason planReconcile was — the handler should only EXECUTE, so the matching
65
+ * rule is unit-testable.
66
+ *
67
+ * Three resolutions:
68
+ * - `update` — matched by mark, or (mark absent/unstamped) by exact title.
69
+ * - `heal` — nothing matched but the event carries a subject, so the row can
70
+ * be reconstructed. Covers a TaskCreate that silently produced no
71
+ * subtask, which previously orphaned the task forever.
72
+ * - `discard` — nothing matched and there is no subject to rebuild a title from.
73
+ *
74
+ * Measured 2026-07-28: marks "1" and "3" were stamped for one lane while mark
75
+ * "2" was never written at all, and every later update for it was dropped as
76
+ * `no-matching-subtask` — 26 of 30 tasksync discards in six hours, across seven
77
+ * distinct lane sessions, were that one reason.
78
+ */
79
+ export declare function resolveTaskUpdateTarget(existing: Array<{
80
+ id: string;
81
+ title: string;
82
+ kind_data?: Record<string, unknown> | null;
83
+ }>, evt: {
84
+ taskId: string;
85
+ subject?: string;
86
+ }): {
87
+ op: "update";
88
+ id: string;
89
+ } | {
90
+ op: "heal";
91
+ title: string;
92
+ } | {
93
+ op: "discard";
94
+ };
95
+ /**
96
+ * Pure reconciliation plan: given the lane's EXISTING subtasks and its INCOMING
97
+ * (current) task list, compute the create/update/delete ops that make the
98
+ * subtask set match the list — WITHOUT touching prisma. Extracted so the
99
+ * matching/status/positioning logic is unit-testable (the handler only executes
100
+ * the plan). Matching is by stable mark when the CLI provides one, else by
101
+ * content. Position follows incoming index, so a reorder is an update.
102
+ */
103
+ export interface ReconcilePlan {
104
+ toCreate: Array<{
105
+ content: string;
106
+ status: string;
107
+ completed: boolean;
108
+ position: string;
109
+ kind_data: Record<string, unknown>;
110
+ }>;
111
+ toUpdate: Array<{
112
+ id: string;
113
+ content: string;
114
+ status: string;
115
+ completed: boolean;
116
+ position: string;
117
+ kind_data: Record<string, unknown>;
118
+ }>;
119
+ toDelete: string[];
120
+ }
121
+ export declare function planReconcile(existing: WorkItem[], incoming: TaskListItem[], source?: string): ReconcilePlan;
@@ -12,7 +12,6 @@
12
12
  import { describe, expect, it } from "bun:test";
13
13
  import {
14
14
  STATUS_TO_WORK_ITEM,
15
- deriveEvidenceProgress,
16
15
  normalizeStatus,
17
16
  planReconcile,
18
17
  resolveProjectedStatus,
@@ -30,31 +29,6 @@ describe("STATUS_TO_WORK_ITEM", () => {
30
29
  });
31
30
  });
32
31
 
33
- describe("evidence-derived task progress", () => {
34
- it("counts only required subtasks with independent Orchestrator acceptance", () => {
35
- const out = deriveEvidenceProgress(
36
- [
37
- { id: "a", status: "done" },
38
- { id: "b", status: "done" },
39
- { id: "c", status: "todo", kind_data: { pm_progress: { required: false } } },
40
- ],
41
- [
42
- { work_item_id: "a", sender_role: "orchestrator", system_key: "acceptance:a" },
43
- { work_item_id: "b", sender_role: "worker", system_key: "acceptance:b" },
44
- ],
45
- );
46
- expect(out).toEqual({ total: 2, accepted: 1, percentage: 50 });
47
- });
48
-
49
- it("does not treat prose, context, or done alone as evidence", () => {
50
- expect(
51
- deriveEvidenceProgress([{ id: "a", status: "done" }], [
52
- { work_item_id: "a", sender_role: "orchestrator", system_key: "progress:100" },
53
- ]),
54
- ).toEqual({ total: 1, accepted: 0, percentage: 0 });
55
- });
56
- });
57
-
58
32
  describe("status translation is a single non-drifting source", () => {
59
33
  // The forward map (CLI → work_items) is canonical; the reverse is DERIVED from
60
34
  // it (+ a closed synonym set). This locks the structural fix: the two
@@ -74,57 +74,6 @@ export function normalizeStatus(s: string | null): TaskListItem["status"] {
74
74
  return (s && WORK_ITEM_TO_STATUS[s]) || "pending";
75
75
  }
76
76
 
77
- export interface ProgressSubtask {
78
- id: string;
79
- status: string | null;
80
- kind_data?: Record<string, unknown> | null;
81
- }
82
-
83
- export interface ProgressAcceptanceEvidence {
84
- work_item_id: string | null;
85
- sender_role: string | null;
86
- system_key: string | null;
87
- }
88
-
89
- export interface EvidenceProgress {
90
- total: number;
91
- accepted: number;
92
- percentage: number;
93
- }
94
-
95
- /**
96
- * Derive progress from the canonical checklist and independent acceptance
97
- * comments. A done status without an Orchestrator acceptance comment is not
98
- * evidence of completion; prose percentages and context gauges never enter
99
- * this calculation. Subtasks are required by default, with an explicit
100
- * `kind_data.pm_progress.required: false` opt-out for non-gating notes.
101
- */
102
- export function deriveEvidenceProgress(
103
- subtasks: ProgressSubtask[],
104
- evidence: ProgressAcceptanceEvidence[],
105
- ): EvidenceProgress {
106
- const required = subtasks.filter(
107
- (s) => (s.kind_data?.pm_progress as { required?: boolean } | undefined)?.required !== false,
108
- );
109
- const accepted = new Set(
110
- evidence
111
- .filter(
112
- (e) =>
113
- e.sender_role === "orchestrator" &&
114
- typeof e.system_key === "string" &&
115
- e.system_key.startsWith("acceptance:") &&
116
- e.work_item_id,
117
- )
118
- .map((e) => e.work_item_id as string),
119
- );
120
- const acceptedCount = required.filter((s) => s.status === "done" && accepted.has(s.id)).length;
121
- return {
122
- total: required.length,
123
- accepted: acceptedCount,
124
- percentage: required.length === 0 ? 0 : Math.round((acceptedCount / required.length) * 100),
125
- };
126
- }
127
-
128
77
  /**
129
78
  * Decide the status to WRITE for an existing row, given what the CLI list says.
130
79
  *
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @system service-boot
3
+ * @status handwritten
4
+ * @edit edit directly
5
+ *
6
+ * Lane RENAME back-write for task-sync: a tab rename EMITS to update the bound
7
+ * work_items task's title in the DB, by CLI session id. This is the DB half of
8
+ * `tab-rename-emits-back-to-task-title`: the operator's tab bar is how they see
9
+ * what is being worked on (`lane-labels-and-task-lists`), so the tmux window
10
+ * name and the task title must never diverge silently. Renaming a tab from
11
+ * `scala-tools session rename` (or the lane renaming itself through the same
12
+ * surface) updates the task title so the project board agrees with the tab bar.
13
+ *
14
+ * THE EMISSION, not a poll (`actions-are-rows-then-emissions`): a caller renames
15
+ * the window (a row/state change) and that change emits the title update — the
16
+ * task-sync owner reacts by updating the row. State lives in the row, never in a
17
+ * return value a caller may never receive.
18
+ *
19
+ * Bound by CLI SESSION ID, never pane id (`lane-identity-is-cli-session-id`): a
20
+ * pane OUTLIVES the session inside it, so matching on a pane would let a dead
21
+ * session's task answer for a live lane. The session is the stable identity a
22
+ * rename resolves to (the daemon resolves the pane's tab → its stored session id
23
+ * and passes that here), so the rename lands on the lane that owns the tab.
24
+ *
25
+ * Split out of task-sync-router.ts for the same reason task-sync-brief/lane/
26
+ * assign exist: the router sits at its 1000-line commit gate, so every cohesive
27
+ * task-sync unit that can live in a sibling does. This owns the rename handler +
28
+ * its pure outcome decision.
29
+ *
30
+ * CAPABILITY HARVEST (capability-harvest-on-split): APP-LOCAL, not a capability
31
+ * candidate. Bound to the work_items schema and to task-sync's own
32
+ * kind_data.lane.session convention; no unrelated app could install this
33
+ * unmodified.
34
+ */
35
+ import * as v from "valibot";
36
+ import { type Context } from "./auth-router.ts";
37
+ /**
38
+ * renameLaneTask ORPC input. `lane_session` is the lane's CLI-native session id
39
+ * (kind_data.lane.session) — the stable identity a pane rename resolves to.
40
+ * `title` is the new task title (the renamed tab's label). Both required:
41
+ * oRPC rejects a call missing either at the signature
42
+ * (`prevention-over-detection`), so a malformed rename is a 400, never a silent
43
+ * no-op that leaves the title stale.
44
+ */
45
+ export declare const renameLaneTaskInput: v.ObjectSchema<{
46
+ readonly lane_session: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "lane_session is required">]>;
47
+ readonly title: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "title is required">]>;
48
+ }, undefined>;
49
+ /**
50
+ * The rename outcome from a resolved lane task — pure so the "no task bound ⇒
51
+ * not updated, never an error" decision is unit-testable with no DB. A rename
52
+ * whose lane has no task is best-effort (returns updated:false): every spawn
53
+ * now mints a task, so this is the rare case (a tab whose task was archived and
54
+ * pruned), not a path the operator hits. Failing loudly here would refuse a
55
+ * rename of the WINDOW for a DB miss, which couples two surfaces that must not
56
+ * be — the tmux rename already succeeded before this is called.
57
+ */
58
+ export declare function renameOutcome(task: {
59
+ id: string;
60
+ } | null): {
61
+ task_id: string | null;
62
+ updated: boolean;
63
+ };
64
+ /**
65
+ * renameLaneTask ORPC handler. The session-picker daemon calls this from
66
+ * `/rpc/rename` after it renames the tmux window: it resolves the pane's tab to
67
+ * its session id and posts it here. Same transport as bindLane/readTaskList:
68
+ * page-gate-exempt (fn.taskSync), localhost super-admin. Resolves the lane's
69
+ * task BY SESSION (never pane) and updates its title. Idempotent: renaming to
70
+ * the same title writes the same row.
71
+ *
72
+ * An archived parent is matched too (resolveLaneTask falls back to the archived
73
+ * lane task for the session), so a rename of a tab whose run closed still lands
74
+ * on its task — the title is the title regardless of run state.
75
+ */
76
+ export declare const renameLaneTaskHandler: import("@orpc/server").DecoratedProcedure<import("@orpc/server").MergedInitialContext<Context & Record<never, never>, Context, Context>, import("@orpc/server").MergedCurrentContext<Context, {
77
+ headers: Headers;
78
+ resolveUser?: (headers: Headers, prisma: any) => Promise<import("./auth-router.ts").User | null>;
79
+ prisma: any;
80
+ user: import("./auth-router.ts").User;
81
+ orgId: string | null | undefined;
82
+ }>, v.ObjectSchema<{
83
+ readonly lane_session: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "lane_session is required">]>;
84
+ readonly title: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "title is required">]>;
85
+ }, undefined>, import("@orpc/contract").Schema<{
86
+ task_id: string | null;
87
+ updated: boolean;
88
+ }, {
89
+ task_id: string | null;
90
+ updated: boolean;
91
+ }>, Record<never, never>, Record<never, never>>;