@plurnk/plurnk-service 1.0.4 → 1.0.6

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 (215) hide show
  1. package/.env.defaults +55 -31
  2. package/INSTALL.md +3 -3
  3. package/README.md +4 -4
  4. package/SPEC.md +205 -193
  5. package/dist/Paths.js +1 -1
  6. package/dist/Paths.js.map +1 -1
  7. package/dist/core/ChannelWrite.d.ts +18 -18
  8. package/dist/core/ChannelWrite.d.ts.map +1 -1
  9. package/dist/core/ChannelWrite.js +17 -17
  10. package/dist/core/ChannelWrite.js.map +1 -1
  11. package/dist/core/ChannelWrite.sql +11 -11
  12. package/dist/core/Dispatcher.d.ts +11 -16
  13. package/dist/core/Dispatcher.d.ts.map +1 -1
  14. package/dist/core/Dispatcher.js +122 -125
  15. package/dist/core/Dispatcher.js.map +1 -1
  16. package/dist/core/Engine.d.ts +20 -23
  17. package/dist/core/Engine.d.ts.map +1 -1
  18. package/dist/core/Engine.js +213 -210
  19. package/dist/core/Engine.js.map +1 -1
  20. package/dist/core/Engine.sql +108 -130
  21. package/dist/core/PacketBuilder.d.ts +10 -11
  22. package/dist/core/PacketBuilder.d.ts.map +1 -1
  23. package/dist/core/PacketBuilder.js +204 -128
  24. package/dist/core/PacketBuilder.js.map +1 -1
  25. package/dist/core/ProposalLifecycle.d.ts +8 -8
  26. package/dist/core/ProposalLifecycle.d.ts.map +1 -1
  27. package/dist/core/ProposalLifecycle.js +10 -10
  28. package/dist/core/ProposalLifecycle.js.map +1 -1
  29. package/dist/core/ProviderInstantiate.d.ts +1 -0
  30. package/dist/core/ProviderInstantiate.d.ts.map +1 -1
  31. package/dist/core/ProviderInstantiate.js +9 -3
  32. package/dist/core/ProviderInstantiate.js.map +1 -1
  33. package/dist/core/SchemeRegistry.d.ts +4 -1
  34. package/dist/core/SchemeRegistry.d.ts.map +1 -1
  35. package/dist/core/SchemeRegistry.js +18 -9
  36. package/dist/core/SchemeRegistry.js.map +1 -1
  37. package/dist/core/TelemetryChannel.d.ts +5 -5
  38. package/dist/core/TelemetryChannel.d.ts.map +1 -1
  39. package/dist/core/TelemetryChannel.js +9 -9
  40. package/dist/core/TelemetryChannel.js.map +1 -1
  41. package/dist/core/caps/CapsResolve.js +2 -2
  42. package/dist/core/caps/CapsResolve.js.map +1 -1
  43. package/dist/core/caps/DbNotifyCaps.js +2 -2
  44. package/dist/core/caps/DbNotifyCaps.js.map +1 -1
  45. package/dist/core/caps/DbSubscriptionCaps.js +7 -7
  46. package/dist/core/caps/DbSubscriptionCaps.js.map +1 -1
  47. package/dist/core/caps/SchemeCtxImpl.d.ts +2 -2
  48. package/dist/core/caps/SchemeCtxImpl.d.ts.map +1 -1
  49. package/dist/core/caps/SchemeCtxImpl.js +4 -4
  50. package/dist/core/caps/SchemeCtxImpl.js.map +1 -1
  51. package/dist/core/content-hash.d.ts +2 -0
  52. package/dist/core/content-hash.d.ts.map +1 -0
  53. package/dist/core/content-hash.js +6 -0
  54. package/dist/core/content-hash.js.map +1 -0
  55. package/dist/core/fork.d.ts +1 -1
  56. package/dist/core/fork.d.ts.map +1 -1
  57. package/dist/core/fork.js +31 -26
  58. package/dist/core/fork.js.map +1 -1
  59. package/dist/core/fork.sql +41 -32
  60. package/dist/core/git-env.d.ts.map +1 -1
  61. package/dist/core/git-env.js +23 -7
  62. package/dist/core/git-env.js.map +1 -1
  63. package/dist/core/git-iso.d.ts +9 -0
  64. package/dist/core/git-iso.d.ts.map +1 -0
  65. package/dist/core/git-iso.js +227 -0
  66. package/dist/core/git-iso.js.map +1 -0
  67. package/dist/core/git-membership.d.ts +2 -2
  68. package/dist/core/git-membership.d.ts.map +1 -1
  69. package/dist/core/git-membership.js +70 -50
  70. package/dist/core/git-membership.js.map +1 -1
  71. package/dist/core/git-state.d.ts +1 -1
  72. package/dist/core/git-state.d.ts.map +1 -1
  73. package/dist/core/git-state.js +21 -11
  74. package/dist/core/git-state.js.map +1 -1
  75. package/dist/core/packet-wire.d.ts.map +1 -1
  76. package/dist/core/packet-wire.js +81 -22
  77. package/dist/core/packet-wire.js.map +1 -1
  78. package/dist/core/plurnk-uri.d.ts +2 -2
  79. package/dist/core/plurnk-uri.d.ts.map +1 -1
  80. package/dist/core/plurnk-uri.js +19 -12
  81. package/dist/core/plurnk-uri.js.map +1 -1
  82. package/dist/core/run-ops.sql +26 -26
  83. package/dist/core/scheme-types.d.ts +6 -11
  84. package/dist/core/scheme-types.d.ts.map +1 -1
  85. package/dist/core/search-gate.js +0 -0
  86. package/dist/core/search-gate.js.map +1 -1
  87. package/dist/core/token-ruler.d.ts +2 -0
  88. package/dist/core/token-ruler.d.ts.map +1 -0
  89. package/dist/core/token-ruler.js +18 -0
  90. package/dist/core/token-ruler.js.map +1 -0
  91. package/dist/core/worker-cap.d.ts +8 -0
  92. package/dist/core/worker-cap.d.ts.map +1 -0
  93. package/dist/core/worker-cap.js +20 -0
  94. package/dist/core/worker-cap.js.map +1 -0
  95. package/dist/core/{session-settings.d.ts → workspace-settings.d.ts} +5 -5
  96. package/dist/core/workspace-settings.d.ts.map +1 -0
  97. package/dist/core/{session-settings.js → workspace-settings.js} +13 -13
  98. package/dist/core/workspace-settings.js.map +1 -0
  99. package/dist/digest/Digest.d.ts +3 -3
  100. package/dist/digest/Digest.d.ts.map +1 -1
  101. package/dist/digest/Digest.js +79 -73
  102. package/dist/digest/Digest.js.map +1 -1
  103. package/dist/digest/digest.sql +18 -18
  104. package/dist/schemes/Exec.d.ts +9 -2
  105. package/dist/schemes/Exec.d.ts.map +1 -1
  106. package/dist/schemes/Exec.js +121 -68
  107. package/dist/schemes/Exec.js.map +1 -1
  108. package/dist/schemes/ExecOutputScheme.js +3 -3
  109. package/dist/schemes/ExecOutputScheme.js.map +1 -1
  110. package/dist/schemes/File.js +23 -23
  111. package/dist/schemes/File.js.map +1 -1
  112. package/dist/schemes/Known.js +5 -5
  113. package/dist/schemes/Known.js.map +1 -1
  114. package/dist/schemes/Log.d.ts.map +1 -1
  115. package/dist/schemes/Log.js +63 -14
  116. package/dist/schemes/Log.js.map +1 -1
  117. package/dist/schemes/Log.sql +49 -8
  118. package/dist/schemes/Plurnk.js +5 -5
  119. package/dist/schemes/Plurnk.js.map +1 -1
  120. package/dist/schemes/Skill.js +5 -5
  121. package/dist/schemes/Skill.js.map +1 -1
  122. package/dist/schemes/Unknown.js +5 -5
  123. package/dist/schemes/Unknown.js.map +1 -1
  124. package/dist/schemes/{Run.d.ts → Worker.d.ts} +2 -2
  125. package/dist/schemes/Worker.d.ts.map +1 -0
  126. package/dist/schemes/{Run.js → Worker.js} +67 -67
  127. package/dist/schemes/Worker.js.map +1 -0
  128. package/dist/schemes/_entry-crud.js +11 -11
  129. package/dist/schemes/_entry-crud.js.map +1 -1
  130. package/dist/schemes/_entry-crud.sql +29 -29
  131. package/dist/schemes/_entry-find.d.ts +2 -1
  132. package/dist/schemes/_entry-find.d.ts.map +1 -1
  133. package/dist/schemes/_entry-find.js +31 -19
  134. package/dist/schemes/_entry-find.js.map +1 -1
  135. package/dist/schemes/_entry-find.sql +9 -9
  136. package/dist/schemes/_entry-graph.d.ts +2 -2
  137. package/dist/schemes/_entry-graph.d.ts.map +1 -1
  138. package/dist/schemes/_entry-graph.js +18 -18
  139. package/dist/schemes/_entry-graph.js.map +1 -1
  140. package/dist/schemes/_entry-graph.sql +8 -8
  141. package/dist/schemes/_entry-manifest.d.ts +1 -1
  142. package/dist/schemes/_entry-manifest.d.ts.map +1 -1
  143. package/dist/schemes/_entry-manifest.js +74 -50
  144. package/dist/schemes/_entry-manifest.js.map +1 -1
  145. package/dist/schemes/_entry-ops.d.ts +4 -4
  146. package/dist/schemes/_entry-ops.d.ts.map +1 -1
  147. package/dist/schemes/_entry-ops.js +25 -25
  148. package/dist/schemes/_entry-ops.js.map +1 -1
  149. package/dist/schemes/_entry-ops.sql +9 -9
  150. package/dist/schemes/_entry-semantic.d.ts +2 -1
  151. package/dist/schemes/_entry-semantic.d.ts.map +1 -1
  152. package/dist/schemes/_entry-semantic.js +23 -4
  153. package/dist/schemes/_entry-semantic.js.map +1 -1
  154. package/dist/schemes/_entry-semantic.sql +18 -4
  155. package/dist/schemes/_entry-send.d.ts +1 -1
  156. package/dist/schemes/_entry-send.d.ts.map +1 -1
  157. package/dist/schemes/_entry-send.js +6 -6
  158. package/dist/schemes/_entry-send.js.map +1 -1
  159. package/dist/schemes/exec-abort.js +1 -1
  160. package/dist/schemes/exec-abort.js.map +1 -1
  161. package/dist/server/Daemon.d.ts +50 -48
  162. package/dist/server/Daemon.d.ts.map +1 -1
  163. package/dist/server/Daemon.js +307 -297
  164. package/dist/server/Daemon.js.map +1 -1
  165. package/dist/server/client-input.js +20 -20
  166. package/dist/server/client-input.js.map +1 -1
  167. package/dist/server/dispatch-as-plurnk.d.ts +1 -1
  168. package/dist/server/dispatch-as-plurnk.d.ts.map +1 -1
  169. package/dist/server/dispatch-as-plurnk.js +7 -7
  170. package/dist/server/dispatch-as-plurnk.js.map +1 -1
  171. package/dist/server/drain.sql +27 -27
  172. package/dist/server/envelope.d.ts +20 -20
  173. package/dist/server/envelope.d.ts.map +1 -1
  174. package/dist/server/envelope.js +86 -86
  175. package/dist/server/envelope.js.map +1 -1
  176. package/dist/server/envelope.sql +39 -39
  177. package/dist/server/logEntry.d.ts +1 -1
  178. package/dist/server/logEntry.d.ts.map +1 -1
  179. package/dist/server/logEntry.js +1 -1
  180. package/dist/server/logEntry.js.map +1 -1
  181. package/dist/server/loop-model.d.ts +3 -0
  182. package/dist/server/loop-model.d.ts.map +1 -0
  183. package/dist/server/loop-model.js +26 -0
  184. package/dist/server/loop-model.js.map +1 -0
  185. package/dist/server/loopDocs.d.ts +1 -1
  186. package/dist/server/loopDocs.d.ts.map +1 -1
  187. package/dist/server/loopDocs.js +6 -6
  188. package/dist/server/loopDocs.js.map +1 -1
  189. package/dist/server/seam-entry-read.sql +2 -2
  190. package/dist/server/seam-log-read.sql +3 -3
  191. package/dist/server/seam-loop.sql +3 -3
  192. package/dist/server/seam-proposal-list.sql +4 -4
  193. package/dist/server/yolo.js +2 -2
  194. package/dist/server/yolo.js.map +1 -1
  195. package/dist/service.d.ts.map +1 -1
  196. package/dist/service.js +21 -6
  197. package/dist/service.js.map +1 -1
  198. package/migrations/0000-00-00.01_schema.sql +84 -85
  199. package/package.json +17 -14
  200. package/dist/core/TokenGauge.d.ts +0 -16
  201. package/dist/core/TokenGauge.d.ts.map +0 -1
  202. package/dist/core/TokenGauge.js +0 -58
  203. package/dist/core/TokenGauge.js.map +0 -1
  204. package/dist/core/run-cap.d.ts +0 -8
  205. package/dist/core/run-cap.d.ts.map +0 -1
  206. package/dist/core/run-cap.js +0 -20
  207. package/dist/core/run-cap.js.map +0 -1
  208. package/dist/core/search-prefetch.d.ts +0 -17
  209. package/dist/core/search-prefetch.d.ts.map +0 -1
  210. package/dist/core/search-prefetch.js +0 -164
  211. package/dist/core/search-prefetch.js.map +0 -1
  212. package/dist/core/session-settings.d.ts.map +0 -1
  213. package/dist/core/session-settings.js.map +0 -1
  214. package/dist/schemes/Run.d.ts.map +0 -1
  215. package/dist/schemes/Run.js.map +0 -1
@@ -3,23 +3,23 @@
3
3
  -- PREP: engine_loop_status
4
4
  SELECT status FROM loops WHERE id = $loop_id;
5
5
 
6
- -- PREP: engine_run_has_live_child
7
- -- A non-terminal CHILD run (run:// spawn/fork set parent_run_id) — a "live thing the run holds",
6
+ -- PREP: engine_worker_has_live_child
7
+ -- A non-terminal CHILD run (worker:// spawn/fork set parent_worker_id) — a "live thing the worker holds",
8
8
  -- like an open stream. A SEND[200] while one exists is a premature-terminate (§send-premature-terminate).
9
9
  -- Live = a child whose LATEST loop is still pending/running/parked (100/102/202) — the SAME definition
10
- -- engine_child_runs_live uses for the Child Runs orientation, so the 409 gate and the section the model
10
+ -- engine_child_workers_live uses for the Child Runs orientation, so the 409 gate and the section the model
11
11
  -- reads NEVER disagree: a refused termination is always backed by a child the model can SEE and KILL
12
12
  -- (§child-orientation). An inherited/historical loop (a fork copies the parent's loops) is not the
13
13
  -- latest, so it never makes a concluded child look forever-live.
14
- SELECT 1 AS live FROM runs r
15
- JOIN loops l ON l.id = (SELECT id FROM loops WHERE run_id = r.id ORDER BY sequence DESC, id DESC LIMIT 1)
16
- WHERE r.parent_run_id = $run_id AND l.status IN (100, 102, 202) LIMIT 1;
14
+ SELECT 1 AS live FROM workers r
15
+ JOIN loops l ON l.id = (SELECT id FROM loops WHERE worker_id = r.id ORDER BY sequence DESC, id DESC LIMIT 1)
16
+ WHERE r.parent_worker_id = $worker_id AND l.status IN (100, 102, 202) LIMIT 1;
17
17
 
18
- -- PREP: engine_count_active_loops_for_run
18
+ -- PREP: engine_count_active_loops_for_worker
19
19
  -- Wake-on-completion uses this to decide whether to open a new loop or
20
20
  -- let the existing one pick up the channel transition at the next turn
21
21
  -- boundary. Status 102 = "in progress" (any non-terminal state).
22
- SELECT COUNT(*) AS n FROM loops WHERE run_id = $run_id AND status = 102;
22
+ SELECT COUNT(*) AS n FROM loops WHERE worker_id = $worker_id AND status = 102;
23
23
 
24
24
  -- PREP: engine_get_loop_flags
25
25
  -- Loads the loop's persisted flags (json). Default '{}'; YOLO listener and
@@ -53,7 +53,7 @@ SELECT open_paths FROM loops WHERE id = $loop_id;
53
53
  SELECT prompt, sequence FROM loops WHERE id = $loop_id;
54
54
 
55
55
  -- PREP: engine_reclaim_queued_loop
56
- -- §run-lifecycle-wake-requeue-not-terminal — atomic 100→102 re-claim by loop id. A wake
56
+ -- §worker-lifecycle-wake-requeue-not-terminal — atomic 100→102 re-claim by loop id. A wake
57
57
  -- re-queued this loop while ITS OWN live drain was between turns; the drain re-claims and
58
58
  -- keeps running (the injected prompt is already the next turn). Conditional so a racing
59
59
  -- claimant can never double-claim.
@@ -62,7 +62,7 @@ UPDATE loops SET status = 102 WHERE id = $loop_id AND status = 100;
62
62
  -- PREP: engine_loop_set_status
63
63
  -- The universal terminal setter. terminal_message carries either the loop's deliverable
64
64
  -- (the SEND body) or the engine's abandonment reason (max_turns / budget_overflow /
65
- -- strike_threshold) — rides the §run-scheme delta.
65
+ -- strike_threshold) — rides the §worker-scheme delta.
66
66
  UPDATE loops SET status = $status, terminal_message = $message WHERE id = $loop_id;
67
67
 
68
68
  -- PREP: engine_loop_mark_terminated_by
@@ -80,75 +80,74 @@ UPDATE loops SET terminated_by = $terminated_by WHERE id = $loop_id;
80
80
  UPDATE loops SET status = 499, terminal_message = $message, terminated_by = 'cancel'
81
81
  WHERE id = $loop_id AND status NOT IN (200, 413, 429, 499, 500, 504, 508);
82
82
 
83
- -- PREP: engine_run_cancel_live_loops
83
+ -- PREP: engine_worker_cancel_live_loops
84
84
  -- #380, the PARKED case — a 202-blocked loop has no drain to observe the abort (the drain
85
- -- tears down on 202), so loop.cancel terminalizes the run's live loops itself. 102/202 only:
85
+ -- tears down on 202), so loop.cancel terminalizes the worker's live loops itself. 102/202 only:
86
86
  -- queued (100) loops stay enqueued per §methods-loop-cancel. RETURNING feeds the
87
87
  -- loop/terminated broadcast for exactly the loops this cancel killed.
88
88
  UPDATE loops SET status = 499, terminal_message = $message, terminated_by = 'cancel'
89
- WHERE run_id = $run_id AND status IN (102, 202)
89
+ WHERE worker_id = $worker_id AND status IN (102, 202)
90
90
  RETURNING id;
91
91
 
92
- -- PREP: engine_terminate_run_live_loops
92
+ -- PREP: engine_terminate_worker_live_loops
93
93
  -- §op-synchronous — KILL(run) is a DECISIVE op, not a fork/spawn/stream, so it must complete
94
- -- before the turn moves on. Synchronously flip every LIVE loop of the run to 499 (killed) so the
95
- -- same-turn premature-terminate gate (engine_run_has_live_child) sees it dead immediately; the
96
- -- physical scope reap (drain abort, stream teardown) then proceeds async via cancelRun. The
97
- -- loops_stamp_terminated_at trigger stamps terminated_at on the 499 transition (the §run-scheme delta).
94
+ -- before the turn moves on. Synchronously flip every LIVE loop of the worker to 499 (killed) so the
95
+ -- same-turn premature-terminate gate (engine_worker_has_live_child) sees it dead immediately; the
96
+ -- physical scope reap (drain abort, stream teardown) then proceeds async via cancelWorker. The
97
+ -- loops_stamp_terminated_at trigger stamps terminated_at on the 499 transition (the §worker-scheme delta).
98
98
  UPDATE loops SET status = 499, terminal_message = $message
99
- WHERE run_id = $run_id AND status IN (100, 102, 202);
99
+ WHERE worker_id = $worker_id AND status IN (100, 102, 202);
100
100
 
101
- -- PREP: session_get_settings
102
- -- #231 — the session's client-chosen open-context bag ({ manifestItems?, mdDocs? }),
101
+ -- PREP: workspace_get_settings
102
+ -- #231 — the workspace's client-chosen open-context bag ({ manifestItems?, mdDocs? }),
103
103
  -- read at turn-0 with precedence over env.
104
- SELECT settings FROM sessions WHERE id = $session_id;
104
+ SELECT settings FROM workspaces WHERE id = $workspace_id;
105
105
 
106
106
  -- PREP: engine_target_diverged_this_turn
107
107
  -- #note10 — did this entry diverge on disk THIS turn? A source=file env-delta for the
108
- -- target, materialized into this run's log at the current turn, means the model's view
108
+ -- target, materialized into this worker's log at the current turn, means the model's view
109
109
  -- predates the ambient change — a YOLO auto-accept of a same-turn EDIT would clobber it.
110
110
  SELECT 1 AS hit
111
111
  FROM log_entries
112
- WHERE run_id = $run_id AND turn_id = $turn_id
112
+ WHERE worker_id = $worker_id AND turn_id = $turn_id
113
113
  AND origin = 'plurnk' AND source = 'file' AND op = 'EDIT'
114
114
  AND scheme IS $scheme AND pathname = $pathname
115
115
  LIMIT 1;
116
116
 
117
- -- PREP: engine_list_session_entry_tags
118
- -- #note13 — every (entry, tag) in the session, for the manifest catalog's tags field.
117
+ -- PREP: engine_list_workspace_entry_tags
118
+ -- #note13 — every (entry, tag) in the workspace, for the manifest catalog's tags field.
119
119
  SELECT et.entry_id, et.tag
120
120
  FROM entry_tags et
121
121
  JOIN entries e ON e.id = et.entry_id
122
- WHERE e.session_id = $session_id
122
+ WHERE e.workspace_id = $workspace_id
123
123
  ORDER BY et.entry_id, et.tag;
124
124
 
125
- -- PREP: engine_list_run_entries
126
- -- §run-scheme — the building run's OWN run-scope entries (catalogRowsFor source for a run-scope
127
- -- FIND/foist). Byte-for-byte engine_list_session_entries but scope='run' + an owner-prefix glob
128
- -- (`/<owner>/*`) so it yields exactly one run's scratch — its perspective, not a sibling's. Additive.
129
- SELECT e.id AS entry_id, e.scheme, e.pathname, ec.name AS channel, ec.content, ec.mimetype, COALESCE(tc.tokens, ec.tokens) AS tokens, e.deep_hash,
125
+ -- PREP: engine_list_worker_entries
126
+ -- §worker-scheme — the building worker's OWN worker-scope entries (catalogRowsFor source for a worker-scope
127
+ -- FIND/foist). Byte-for-byte engine_list_workspace_entries but scope='worker' + an owner-prefix glob
128
+ -- (`/<owner>/*`) so it yields exactly one worker's scratch — its perspective, not a sibling's. Additive.
129
+ SELECT e.id AS entry_id, e.scheme, e.pathname, ec.name AS channel, ec.content, ec.mimetype, ec.tokens AS tokens, e.deep_hash,
130
130
  CAST(unixepoch('now') - unixepoch(s.opened_at) AS INTEGER) AS seconds
131
131
  FROM entries e
132
132
  JOIN entry_channels ec ON ec.entry_id = e.id
133
- LEFT JOIN token_counts tc ON tc.content_hash = ec.content_hash AND tc.tokenizer_id = $tokenizer_id
134
133
  LEFT JOIN subscriptions s ON s.entry_id = e.id AND s.closed_at IS NULL
135
- WHERE e.scope = 'run' AND e.session_id = $session_id AND e.pathname GLOB $owner_prefix
134
+ WHERE e.scope = 'worker' AND e.workspace_id = $workspace_id AND e.pathname GLOB $owner_prefix
136
135
  ORDER BY e.updated_at ASC, e.id ASC, ec.name;
137
136
 
138
- -- PREP: engine_list_run_entry_tags
139
- -- §run-scheme — (entry, tag) for the building run's own run-scope entries (the run-scope catalog's tags field).
137
+ -- PREP: engine_list_worker_entry_tags
138
+ -- §worker-scheme — (entry, tag) for the building worker's own worker-scope entries (the worker-scope catalog's tags field).
140
139
  SELECT et.entry_id, et.tag
141
140
  FROM entry_tags et
142
141
  JOIN entries e ON e.id = et.entry_id
143
- WHERE e.session_id = $session_id AND e.scope = 'run' AND e.pathname GLOB $owner_prefix
142
+ WHERE e.workspace_id = $workspace_id AND e.scope = 'worker' AND e.pathname GLOB $owner_prefix
144
143
  ORDER BY et.entry_id, et.tag;
145
144
 
146
- -- PREP: engine_run_scratch_count
147
- -- §run-scheme — distinct run-scope entry count owned by the building run, to decide whether the
148
- -- turn-0 catalog foists a FIND(run:///**) (a run with no scratch foists nothing).
145
+ -- PREP: engine_worker_scratch_count
146
+ -- §worker-scheme — distinct worker-scope entry count owned by the building run, to decide whether the
147
+ -- turn-0 catalog foists a FIND(worker:///**) (a worker with no scratch foists nothing).
149
148
  SELECT COUNT(DISTINCT e.id) AS entries
150
149
  FROM entries e
151
- WHERE e.scope = 'run' AND e.session_id = $session_id AND e.pathname GLOB $owner_prefix;
150
+ WHERE e.scope = 'worker' AND e.workspace_id = $workspace_id AND e.pathname GLOB $owner_prefix;
152
151
 
153
152
  -- PREP: engine_next_turn_sequence
154
153
  SELECT COALESCE(MAX(sequence), 0) + 1 AS next FROM turns WHERE loop_id = $loop_id;
@@ -164,7 +163,7 @@ SELECT COALESCE(SUM(usage_prompt), 0) AS prompt,
164
163
  (SELECT usage_prompt FROM turns WHERE loop_id = $loop_id ORDER BY sequence DESC LIMIT 1) AS context,
165
164
  -- #274 — the LAST turn's model window (denominator), so numerator + denominator come from
166
165
  -- the same loop/model; NULL when the provider reports no window.
167
- (SELECT usage_context_size FROM turns WHERE loop_id = $loop_id ORDER BY sequence DESC LIMIT 1) AS context_size,
166
+ (SELECT usage_prompt_budget FROM turns WHERE loop_id = $loop_id ORDER BY sequence DESC LIMIT 1) AS context_size,
168
167
  -- #252 — the opaque provider meta blob from the LATEST turn (e.g. balancePico, a
169
168
  -- point-in-time snapshot; latest wins). Service-unenforced passthrough to the client.
170
169
  (SELECT meta FROM turns WHERE loop_id = $loop_id ORDER BY sequence DESC LIMIT 1) AS meta
@@ -201,27 +200,26 @@ UPDATE turns SET
201
200
  usage_reasoning = $usage_reasoning,
202
201
  usage_cached = $usage_cached,
203
202
  usage_cost_pico = $usage_cost_pico,
204
- usage_context_size = $usage_context_size,
203
+ usage_prompt_budget = $usage_prompt_budget,
205
204
  finish_reason = $finish_reason,
206
205
  model = $model,
207
206
  meta = $meta
208
207
  WHERE id = $id;
209
208
 
210
- -- PREP: engine_list_session_entries
211
- -- Every entry of a session — all schemes, all channels — the source behind the entry
209
+ -- PREP: engine_list_workspace_entries
210
+ -- Every entry of a workspace — all schemes, all channels — the source behind the entry
212
211
  -- catalog (catalogRowsFor / FIND) and the per-turn derivation pump (maintainDerivations).
213
- -- Session-scoped (persists across runs); FOLD doesn't drop from the catalog.
212
+ -- Workspace-scoped (persists across runs); FOLD doesn't drop from the catalog.
214
213
  -- `seconds` is the live age of an active stream: now − the open subscription's
215
214
  -- opened_at (closed_at IS NULL). NULL for static entries. unixepoch parses the
216
215
  -- stored '...%fZ' timestamp directly; re-evaluated every render like tokens.
217
- SELECT e.id AS entry_id, e.scheme, e.pathname, ec.name AS channel, ec.content, ec.mimetype, COALESCE(tc.tokens, ec.tokens) AS tokens, e.deep_hash,
216
+ SELECT e.id AS entry_id, e.scheme, e.pathname, ec.name AS channel, ec.content, ec.mimetype, ec.tokens AS tokens, e.deep_hash,
218
217
  CAST(unixepoch('now') - unixepoch(s.opened_at) AS INTEGER) AS seconds
219
218
  FROM entries e
220
219
  JOIN entry_channels ec ON ec.entry_id = e.id
221
- LEFT JOIN token_counts tc ON tc.content_hash = ec.content_hash AND tc.tokenizer_id = $tokenizer_id
222
220
  LEFT JOIN subscriptions s ON s.entry_id = e.id AND s.closed_at IS NULL
223
- -- entries are session-scoped, shared across runs — §machine-processes-one-filesystem
224
- WHERE e.scope = 'session' AND e.session_id = $session_id
221
+ -- entries are workspace-scoped, shared across runs — §machine-processes-one-filesystem
222
+ WHERE e.scope = 'workspace' AND e.workspace_id = $workspace_id
225
223
  -- User Note 5 — mtime-ascending: dormant entries hold the stable prompt-cache prefix; churn clusters at the tail.
226
224
  ORDER BY e.updated_at ASC, e.id ASC, ec.name;
227
225
 
@@ -233,51 +231,51 @@ SELECT e.scheme AS scheme,
233
231
  COUNT(DISTINCT e.id) AS entries
234
232
  FROM entries e
235
233
  JOIN entry_channels ec ON ec.entry_id = e.id
236
- WHERE e.scope = 'session' AND e.session_id = $session_id
234
+ WHERE e.scope = 'workspace' AND e.workspace_id = $workspace_id
237
235
  GROUP BY e.scheme
238
236
  ORDER BY e.scheme;
239
237
 
240
- -- PREP: engine_run_prior_turn_time
241
- -- §env-delta — timestamp of this run's most recent turn BEFORE the current one
242
- -- (the "since I last looked" boundary). NULL on the run's first turn → no deltas.
238
+ -- PREP: engine_worker_prior_turn_time
239
+ -- §env-delta — timestamp of this worker's most recent turn BEFORE the current one
240
+ -- (the "since I last looked" boundary). NULL on the worker's first turn → no deltas.
243
241
  SELECT MAX(t.timestamp) AS since
244
242
  FROM turns t JOIN loops l ON l.id = t.loop_id
245
- WHERE l.run_id = $run_id AND t.id != $turn_id;
243
+ WHERE l.worker_id = $worker_id AND t.id != $turn_id;
246
244
 
247
245
  -- PREP: engine_pull_env_deltas
248
- -- §env-delta — other actors' resolved EDITs on shared entries since this run last
249
- -- looked. Real edits (origin model/client) AND the plurnk run's fs-sync fictions
250
- -- (origin=plurnk on the reserved 'plurnk' run); excludes this run's own rows and
251
- -- other runs' already-materialized deltas (origin=plurnk on a real run). plurnk:///
246
+ -- §env-delta — other actors' resolved EDITs on shared entries since this worker last
247
+ -- looked. Real edits (origin model/client) AND the plurnk worker's fs-sync fictions
248
+ -- (origin=plurnk on the reserved 'plurnk' run); excludes this worker's own rows and
249
+ -- other workers' already-materialized deltas (origin=plurnk on a real run). plurnk:///
252
250
  -- entries (manifest/prompt/doc) never surface. This is the environment door (§actor-boundary-two-doors); the voice door is inject.
253
- SELECT le.run_id, le.scheme, le.pathname, le.rx, le.source
251
+ SELECT le.worker_id, le.scheme, le.pathname, le.rx, le.source
254
252
  FROM log_entries le
255
- JOIN runs r ON r.id = le.run_id
256
- WHERE r.session_id = $session_id
253
+ JOIN workers r ON r.id = le.worker_id
254
+ WHERE r.workspace_id = $workspace_id
257
255
  AND le.op = 'EDIT'
258
256
  AND le.state = 'resolved'
259
257
  AND le.status_rx IN (200, 201)
260
258
  AND (le.scheme IS NULL OR le.scheme != 'plurnk')
261
- AND le.run_id != $run_id
259
+ AND le.worker_id != $worker_id
262
260
  AND le.at > $since
263
261
  AND (le.origin != 'plurnk'
264
- OR le.run_id = (SELECT id FROM runs WHERE session_id = $session_id AND name = 'plurnk'))
262
+ OR le.worker_id = (SELECT id FROM workers WHERE workspace_id = $workspace_id AND name = 'plurnk'))
265
263
  ORDER BY le.at;
266
264
 
267
265
  -- PREP: engine_insert_env_delta
268
266
  -- §env-delta — materialize a pulled cross-actor edit as a FOLDED delta (expanded=0)
269
- -- in this run's log. origin=plurnk; source carries the cause (sibling run id or
267
+ -- in this worker's log. origin=plurnk; source carries the cause (sibling worker id or
270
268
  -- 'file'); rx reuses the originating row's result span (§edit-result-render).
271
269
  INSERT INTO log_entries (
272
- run_id, loop_id, turn_id, sequence, origin, source,
270
+ worker_id, loop_id, turn_id, sequence, origin, source,
273
271
  op, scheme, pathname, tx, mimetype_tx, rx, mimetype_rx, status_rx, expanded
274
272
  ) VALUES (
275
- $run_id, $loop_id, $turn_id, $sequence, 'plurnk', $source,
273
+ $worker_id, $loop_id, $turn_id, $sequence, 'plurnk', $source,
276
274
  'EDIT', $scheme, $pathname, '', 'text/plain', $rx, 'application/json', 200, 0
277
275
  );
278
276
 
279
- -- PREP: engine_run_stream_channels
280
- -- §exec-stream — every stream channel the run owns (an EXEC's stdout/stderr live on the
277
+ -- PREP: engine_worker_stream_channels
278
+ -- §exec-stream — every stream channel the worker owns (an EXEC's stdout/stderr live on the
281
279
  -- runtime-tag entry), with content + state + coordinate, so the per-turn injector can emit the
282
280
  -- channel's unshown byte-delta. Stays listed until its last delta is shown (cursor == content len).
283
281
  SELECT s.id AS subscription_id, e.scheme AS runtime, e.pathname AS coord,
@@ -285,15 +283,15 @@ SELECT s.id AS subscription_id, e.scheme AS runtime, e.pathname AS coord,
285
283
  FROM subscriptions s
286
284
  JOIN entries e ON e.id = s.entry_id
287
285
  JOIN entry_channels ec ON ec.entry_id = s.entry_id
288
- WHERE s.run_id = $run_id
286
+ WHERE s.worker_id = $worker_id
289
287
  ORDER BY s.id, ec.name;
290
288
 
291
289
  -- PREP: engine_stream_cursor
292
- -- §exec-stream — bytes of this channel already shown to the run: the streamEnd recorded on its
290
+ -- §exec-stream — bytes of this channel already shown to the worker: the streamEnd recorded on its
293
291
  -- latest foisted delta (the caller defaults to 0 when none exists yet).
294
292
  SELECT attrs
295
293
  FROM log_entries
296
- WHERE run_id = $run_id AND origin = 'plurnk' AND op = 'READ'
294
+ WHERE worker_id = $worker_id AND origin = 'plurnk' AND op = 'READ'
297
295
  AND scheme = $scheme AND pathname = $pathname AND fragment = $fragment
298
296
  ORDER BY id DESC LIMIT 1;
299
297
 
@@ -303,63 +301,63 @@ ORDER BY id DESC LIMIT 1;
303
301
  -- the channel; attrs.streamEnd is the next turn's cursor; expanded=1 when the channel has CLOSED
304
302
  -- (the terminal delta auto-OPENs), 0 while it streams (ongoing deltas fold). §exec-stream
305
303
  INSERT INTO log_entries (
306
- run_id, loop_id, turn_id, sequence, origin, source,
304
+ worker_id, loop_id, turn_id, sequence, origin, source,
307
305
  op, scheme, pathname, fragment, tx, mimetype_tx, rx, mimetype_rx, status_rx, attrs, expanded
308
306
  ) VALUES (
309
- $run_id, $loop_id, $turn_id, $sequence, 'plurnk', NULL,
307
+ $worker_id, $loop_id, $turn_id, $sequence, 'plurnk', NULL,
310
308
  'READ', $scheme, $pathname, $fragment, '', 'text/plain', $rx, 'application/json', 200, $attrs, $expanded
311
309
  );
312
310
 
313
311
  -- PREP: engine_pull_loop_terminations
314
- -- §run-scheme — sibling runs' loops that reached a terminal status since this run last
312
+ -- §worker-scheme — sibling runs' loops that reached a terminal status since this worker last
315
313
  -- looked (the loop-termination ambient delta). Carries terminal_message — the SEND[200]
316
314
  -- deliverable or the abandonment reason — plus terminated_by so a collapse/cancel renders
317
- -- its marker (#379). Excludes this run's own loops.
318
- SELECT l.run_id, r.name AS run_name, l.status, l.prompt, l.terminal_message, l.terminated_by
315
+ -- its marker (#379). Excludes this worker's own loops.
316
+ SELECT l.worker_id, r.name AS worker_name, l.status, l.prompt, l.terminal_message, l.terminated_by
319
317
  FROM loops l
320
- JOIN runs r ON r.id = l.run_id
321
- WHERE r.session_id = $session_id
318
+ JOIN workers r ON r.id = l.worker_id
319
+ WHERE r.workspace_id = $workspace_id
322
320
  AND l.terminated_at IS NOT NULL
323
321
  AND l.terminated_at > $since
324
- AND l.run_id != $run_id
322
+ AND l.worker_id != $worker_id
325
323
  ORDER BY l.terminated_at;
326
324
 
327
325
  -- PREP: engine_insert_loop_termination_delta
328
- -- §run-scheme — materialize a sibling's loop-termination as a delta: a SEND from
329
- -- run:///<name> carrying the terminal status + message (the deliverable). origin=plurnk,
326
+ -- §worker-scheme — materialize a sibling's loop-termination as a delta: a SEND from
327
+ -- worker:///<name> carrying the terminal status + message (the deliverable). origin=plurnk,
330
328
  -- source=the terminated run — uniform with the env-delta. Born OPEN for a 2xx deliverable
331
329
  -- (a child's success must reach the parent open + awakening), folded otherwise.
332
330
  INSERT INTO log_entries (
333
- run_id, loop_id, turn_id, sequence, origin, source,
331
+ worker_id, loop_id, turn_id, sequence, origin, source,
334
332
  op, scheme, pathname, tx, mimetype_tx, rx, mimetype_rx, status_rx, expanded
335
333
  ) VALUES (
336
- $run_id, $loop_id, $turn_id, $sequence, 'plurnk', $source,
337
- 'SEND', 'run', $pathname, '', 'text/plain', $rx, 'text/markdown', $status,
334
+ $worker_id, $loop_id, $turn_id, $sequence, 'plurnk', $source,
335
+ 'SEND', 'worker', $pathname, '', 'text/plain', $rx, 'text/markdown', $status,
338
336
  CASE WHEN $status >= 200 AND $status < 300 THEN 1 ELSE 0 END
339
337
  );
340
338
 
341
339
  -- PREP: engine_entry_tags
342
340
  SELECT tag FROM entry_tags WHERE entry_id = $entry_id ORDER BY tag;
343
341
 
344
- -- PREP: engine_child_runs_live
345
- -- The run's LIVE child runs — latest loop non-terminal (100 pending / 102 processing / 202 parked).
346
- -- Powers the Child Runs orienting section (§child-orientation): terse `* <status> run://<name>`
342
+ -- PREP: engine_child_workers_live
343
+ -- The worker's LIVE child workers — latest loop non-terminal (100 pending / 102 processing / 202 parked).
344
+ -- Powers the Child Runs orienting section (§child-orientation): terse `* <status> worker://<name>`
347
345
  -- pointers so the model SEES what it holds live and reasons for itself (READ/KILL), never told to.
348
346
  -- Empty → section omitted.
349
347
  SELECT r.name, l.status
350
- FROM runs r
351
- JOIN loops l ON l.id = (SELECT id FROM loops WHERE run_id = r.id ORDER BY sequence DESC, id DESC LIMIT 1)
352
- WHERE r.parent_run_id = $run_id AND l.status IN (100, 102, 202)
348
+ FROM workers r
349
+ JOIN loops l ON l.id = (SELECT id FROM loops WHERE worker_id = r.id ORDER BY sequence DESC, id DESC LIMIT 1)
350
+ WHERE r.parent_worker_id = $worker_id AND l.status IN (100, 102, 202)
353
351
  ORDER BY r.name;
354
352
 
355
353
  -- PREP: engine_child_streams_open
356
- -- The run's OPEN streams (subscriptions not yet closed) — their addressable coord. Powers the Child
354
+ -- The worker's OPEN streams (subscriptions not yet closed) — their addressable coord. Powers the Child
357
355
  -- Streams orienting section (§child-orientation): terse `* active <runtime>:///<coord>` pointers the
358
356
  -- model OPENs/READs/KILLs. Empty → section omitted.
359
357
  SELECT s.scheme, e.pathname
360
358
  FROM subscriptions s
361
359
  JOIN entries e ON e.id = s.entry_id
362
- WHERE s.run_id = $run_id AND s.closed_at IS NULL
360
+ WHERE s.worker_id = $worker_id AND s.closed_at IS NULL
363
361
  ORDER BY e.pathname;
364
362
 
365
363
  -- PREP: engine_render_telemetry_errors
@@ -390,11 +388,14 @@ ORDER BY t.sequence, le.sequence;
390
388
  -- landing when there is no room: one set-op folds the still-open rows of the newest turn
391
389
  -- boundary — the immediately-prior turn's emissions and the current turn's pre-model rows
392
390
  -- (foists, wake surfaces). Turn 1 is the same rule (no prior turn; its foists are the newest).
393
- -- Folded, never deleted; op='error' rows are EXEMPT (§grinder-errors-exempt), and so is the
391
+ -- Folded, never deleted; THREE exemptions (§grinder-errors-exempt): op='error' rows, the
394
392
  -- user PROMPT (#382 — the task frame the engine foisted is not the model's curatable memory;
395
- -- the engine never reclaims the definition of the task it set).
393
+ -- the engine never reclaims the definition of the task it set), and PLAN rows (#465, owner
394
+ -- ruling — the checklist is the model's orientation surface at exactly the moment the grinder
395
+ -- fires; plans are concise by rule, so exempting them reclaims almost nothing and preserves
396
+ -- the reasoning thread a recovery turn steers by).
396
397
  UPDATE log_entries SET expanded = 0
397
- WHERE loop_id = $loop_id AND expanded = 1 AND op != 'error'
398
+ WHERE loop_id = $loop_id AND expanded = 1 AND op NOT IN ('error', 'PLAN')
398
399
  AND NOT (COALESCE(scheme, '') = 'plurnk' AND COALESCE(pathname, '') LIKE '/prompt/%') -- NULL-safe: a model row's scheme is NULL
399
400
  AND (turn_id = $turn_id
400
401
  OR turn_id = (SELECT MAX(id) FROM turns WHERE loop_id = $loop_id AND id < $turn_id));
@@ -408,7 +409,7 @@ UPDATE log_entries SET expanded = 0 WHERE id = $id;
408
409
  -- PREP: engine_render_log
409
410
  -- Render-time log assembly (SPEC §packet packet.system.log).
410
411
  -- Yields log_entries for the whole RUN — the conversation's working
411
- -- memory carries across loops within a session's run, not just the
412
+ -- memory carries across loops within a workspace's run, not just the
412
413
  -- current loop. Coordinate is log:///<loop_seq>/<turn_seq>/<sequence>/<op>.
413
414
  -- Status 202 entries in state='proposed' are model-invisible until resolved.
414
415
  -- `expanded = 0` rows are FOLDED — listed but collapsed to their coordinate
@@ -417,7 +418,7 @@ SELECT
417
418
  l.sequence AS loop_seq,
418
419
  t.sequence AS turn_seq,
419
420
  le.sequence,
420
- -- le.origin is attribution, never a render filter; the run's actor — §actor-boundary-origin-not-filter §machine-processes-run-origin
421
+ -- le.origin is attribution, never a render filter; the worker's actor — §actor-boundary-origin-not-filter §machine-processes-worker-origin
421
422
  le.origin,
422
423
  le.op, le.suffix, le.signal,
423
424
  le.scheme, le.username, le.password,
@@ -429,13 +430,13 @@ SELECT
429
430
  FROM log_entries le
430
431
  JOIN turns t ON t.id = le.turn_id
431
432
  JOIN loops l ON l.id = le.loop_id
432
- -- WHERE renders exactly one run's log — §actor-boundary-isolation §machine-processes-run-is-its-log
433
+ -- WHERE renders exactly one worker's log — §actor-boundary-isolation §machine-processes-worker-is-its-log
433
434
  -- the AND NOT clauses keep proposed (202) rows hidden until resolved (§proposal-proposed-hidden),
434
435
  -- and SUCCESSFUL OPEN/FOLD render-directive rows out of the packet (#382 — recorded in the DB for
435
436
  -- forensics, suppressed from materialization so a curation receipt rents zero packet space; the
436
437
  -- successful fold that hid the task frame in run43 left NO trace, the database dig. A FAILED
437
438
  -- OPEN/FOLD still renders — errors are signals, §telemetry-uniform-error-channel).
438
- WHERE le.run_id = $run_id
439
+ WHERE le.worker_id = $worker_id
439
440
  AND NOT (le.status_rx = 202 AND le.state = 'proposed')
440
441
  AND NOT (le.op IN ('OPEN', 'FOLD') AND le.status_rx < 400)
441
442
  ORDER BY l.sequence, t.sequence, le.sequence;
@@ -446,14 +447,14 @@ ORDER BY l.sequence, t.sequence, le.sequence;
446
447
  -- triggers the proposal lifecycle (engine pauses dispatch; client resolves
447
448
  -- via loop/resolve RPC; entry transitions through engine_resolve_log_entry).
448
449
  INSERT INTO log_entries (
449
- run_id, loop_id, turn_id, sequence, origin, source,
450
+ worker_id, loop_id, turn_id, sequence, origin, source,
450
451
  op, suffix, signal,
451
452
  scheme, username, password, hostname, port,
452
453
  pathname, params, fragment, lineMarker,
453
454
  tx, mimetype_tx, rx, mimetype_rx, status_rx, tokens,
454
455
  state, outcome, attrs
455
456
  ) VALUES (
456
- $run_id, $loop_id, $turn_id, $sequence, $origin, $source,
457
+ $worker_id, $loop_id, $turn_id, $sequence, $origin, $source,
457
458
  $op, $suffix, $signal,
458
459
  $scheme, $username, $password, $hostname, $port,
459
460
  $pathname, $params, $fragment, $lineMarker,
@@ -499,23 +500,6 @@ WHERE turn_id = $turn_id AND origin = 'model' AND status_rx >= 400 AND op != 'er
499
500
  -- truth the return value carries: the loop never went terminal, so the turn didn't either.
500
501
  UPDATE turns SET status = $status WHERE id = $id;
501
502
 
502
- -- PREP: token_count_get
503
- -- #312 — the keyed token-derivation lookup: one content blob, one tokenizer identity, one count.
504
- SELECT tokens FROM token_counts WHERE content_hash = $content_hash AND tokenizer_id = $tokenizer_id;
505
-
506
- -- PREP: token_count_upsert
507
- INSERT INTO token_counts (content_hash, tokenizer_id, tokens) VALUES ($content_hash, $tokenizer_id, $tokens)
508
- ON CONFLICT (content_hash, tokenizer_id) DO UPDATE SET tokens = excluded.tokens;
509
-
510
- -- PREP: token_stale_channels
511
- -- #312 — the pump's recount worklist: body channels whose (content_hash, active tokenizer) pair
512
- -- has no derivation row yet. A model swap to a NEW tokenizer identity makes every row miss (the
513
- -- bulk recount); a swap between vocab-sharing models misses nothing.
514
- SELECT ec.entry_id, ec.content, ec.content_hash
515
- FROM entry_channels ec
516
- JOIN entries e ON e.id = ec.entry_id
517
- WHERE e.session_id = $session_id AND ec.name = 'body' AND ec.content_hash IS NOT NULL
518
- AND NOT EXISTS (SELECT 1 FROM token_counts tc WHERE tc.content_hash = ec.content_hash AND tc.tokenizer_id = $tokenizer_id);
519
503
 
520
504
 
521
505
  -- PREP: engine_loop_sequence
@@ -524,21 +508,15 @@ WHERE e.session_id = $session_id AND ec.name = 'body' AND ec.content_hash IS NOT
524
508
  -- model's first loop read as prompt/2/1 (the docs loop holds id 1). Owner: minor but annoying.
525
509
  SELECT sequence FROM loops WHERE id = $loop_id;
526
510
 
527
- -- PREP: engine_run_has_undelivered_child_term
528
- -- A child run whose loop TERMINATED after the current turn's timestamp — its deliverable
529
- -- (the §run-scheme collect delta) is queued for the NEXT packet build and has not been seen.
511
+ -- PREP: engine_worker_has_undelivered_child_term
512
+ -- A child worker whose loop TERMINATED after the current turn's timestamp — its deliverable
513
+ -- (the §worker-scheme collect delta) is queued for the NEXT packet build and has not been seen.
530
514
  -- The 1ms-wide fan-out race: workers concluding DURING the parent's generation are not "live"
531
515
  -- (the wait's J leg misses them) but their results are pending — concluding or ∅-collapsing
532
516
  -- over them silently discards deliverables the model spawned. {§send-undelivered-child-term}
533
517
  SELECT 1 AS pending FROM loops l
534
- JOIN runs r ON r.id = l.run_id
535
- WHERE r.parent_run_id = $run_id
518
+ JOIN workers r ON r.id = l.worker_id
519
+ WHERE r.parent_worker_id = $worker_id
536
520
  AND l.terminated_at IS NOT NULL
537
521
  AND l.terminated_at > (SELECT timestamp FROM turns WHERE id = $turn_id)
538
522
  LIMIT 1;
539
-
540
- -- PREP: search_stamp_entry_attributes
541
- -- §search-prefetch — chooser context (title/snippet/publishedDate) stamped onto a survivor
542
- -- entry's attributes at materialization; json_patch merges, never clobbers other keys.
543
- UPDATE entries SET attributes = json_patch(attributes, $patch)
544
- WHERE session_id = $session_id AND scheme = $scheme AND pathname = $pathname AND scope = 'session';
@@ -28,39 +28,38 @@ export default class PacketBuilder {
28
28
  telemetry: TelemetryChannel;
29
29
  executors: () => ExecutorRegistry | undefined;
30
30
  });
31
- decodeBudget(provider: Provider): number;
32
- promptBudgetFor(provider: Provider): number;
33
- ceilingFor(provider: Provider, tokenRatio?: number): number;
34
- buildRequestPacket({ initialMessages, requirements, sessionId, runId, loopId, currentTurnSeq, provider, gitStatus, tokenRatio, telemetryErrors: presetTelemetry, }: {
35
- tokenRatio?: number;
31
+ maxTokensFor(provider: Provider): number;
32
+ promptBudgetFor(provider: Provider): number | null;
33
+ ceilingFor(provider: Provider): number | null;
34
+ buildRequestPacket({ initialMessages, requirements, workspaceId, workerId, loopId, currentTurnSeq, provider, gitStatus, telemetryErrors: presetTelemetry, }: {
36
35
  initialMessages: ChatMessage[];
37
36
  requirements: string;
38
37
  gitStatus: GitStatus | null;
39
- sessionId: number;
40
- runId: number;
38
+ workspaceId: number;
39
+ workerId: number;
41
40
  loopId: number;
42
41
  currentTurnSeq: number;
43
42
  provider: Provider;
44
43
  telemetryErrors?: object[];
45
44
  }): Promise<RequestPacket>;
46
- docEntries(sessionId: number): Promise<Array<{
45
+ docEntries(workspaceId: number): Promise<Array<{
47
46
  name: string;
48
47
  content: string;
49
48
  }>>;
50
- enforceBudget({ packet, provider, runId, loopId, turnId, mintSequence, tokenRatio, rebuild }: {
49
+ enforceBudget({ packet, provider, workerId, loopId, turnId, mintSequence, rebuild }: {
51
50
  packet: RequestPacket;
52
51
  provider: Provider;
53
- runId: number;
52
+ workerId: number;
54
53
  loopId: number;
55
54
  turnId: number;
56
55
  mintSequence: number;
57
- tokenRatio?: number;
58
56
  rebuild: () => Promise<RequestPacket>;
59
57
  }): Promise<{
60
58
  packet: RequestPacket;
61
59
  fit: boolean;
62
60
  struck: boolean;
63
61
  }>;
62
+ exactPacketTokens(packet: RequestPacket, provider: Provider): number;
64
63
  completePacket(requestPacket: RequestPacket, assistant: PacketAssistant, assistantRaw: unknown, provider: Provider): object;
65
64
  buildTelemetryErrors(loopId: number, currentTurnSeq: number): Promise<object[]>;
66
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PacketBuilder.d.ts","sourceRoot":"","sources":["../../src/core/PacketBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,EAAE,EAAc,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAchD,OAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAoBzD,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,QAAQ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