@plurnk/plurnk-service 1.16.5 → 1.18.0

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 (661) hide show
  1. package/.env.defaults +140 -246
  2. package/INSTALL.md +84 -138
  3. package/README.md +10 -6
  4. package/SPEC.md +2468 -1694
  5. package/dist/Paths.d.ts +2 -0
  6. package/dist/Paths.d.ts.map +1 -1
  7. package/dist/Paths.js +2 -0
  8. package/dist/Paths.js.map +1 -1
  9. package/dist/build-info.d.ts.map +1 -1
  10. package/dist/build-info.js +7 -1
  11. package/dist/build-info.js.map +1 -1
  12. package/dist/build-info.json +1 -1
  13. package/dist/content/body-preview.d.ts +8 -0
  14. package/dist/content/body-preview.d.ts.map +1 -0
  15. package/dist/content/body-preview.js +39 -0
  16. package/dist/content/body-preview.js.map +1 -0
  17. package/dist/content/byte-view.d.ts +1 -4
  18. package/dist/content/byte-view.d.ts.map +1 -1
  19. package/dist/content/byte-view.js.map +1 -1
  20. package/dist/content/edit-collision.d.ts.map +1 -1
  21. package/dist/content/edit-collision.js +3 -4
  22. package/dist/content/edit-collision.js.map +1 -1
  23. package/dist/content/line-anchors.d.ts +2 -2
  24. package/dist/content/line-anchors.d.ts.map +1 -1
  25. package/dist/content/line-anchors.js +4 -3
  26. package/dist/content/line-anchors.js.map +1 -1
  27. package/dist/content/line-selection.d.ts +9 -0
  28. package/dist/content/line-selection.d.ts.map +1 -0
  29. package/dist/content/line-selection.js +29 -0
  30. package/dist/content/line-selection.js.map +1 -0
  31. package/dist/content/matcher.d.ts +0 -1
  32. package/dist/content/matcher.d.ts.map +1 -1
  33. package/dist/content/matcher.js +2 -3
  34. package/dist/content/matcher.js.map +1 -1
  35. package/dist/content/pattern-edits.d.ts +39 -0
  36. package/dist/content/pattern-edits.d.ts.map +1 -0
  37. package/dist/content/pattern-edits.js +121 -0
  38. package/dist/content/pattern-edits.js.map +1 -0
  39. package/dist/content/read-projector.d.ts +18 -9
  40. package/dist/content/read-projector.d.ts.map +1 -1
  41. package/dist/content/read-projector.js +132 -35
  42. package/dist/content/read-projector.js.map +1 -1
  43. package/dist/content/read-resolve.d.ts +4 -1
  44. package/dist/content/read-resolve.d.ts.map +1 -1
  45. package/dist/content/read-resolve.js +42 -7
  46. package/dist/content/read-resolve.js.map +1 -1
  47. package/dist/core/AdmittedTurnExecutor.d.ts +2 -5
  48. package/dist/core/AdmittedTurnExecutor.d.ts.map +1 -1
  49. package/dist/core/AdmittedTurnExecutor.js +96 -88
  50. package/dist/core/AdmittedTurnExecutor.js.map +1 -1
  51. package/dist/core/BareBatchRunner.d.ts +6 -1
  52. package/dist/core/BareBatchRunner.d.ts.map +1 -1
  53. package/dist/core/BareBatchRunner.js +20 -5
  54. package/dist/core/BareBatchRunner.js.map +1 -1
  55. package/dist/core/BudgetReadout.d.ts +2 -3
  56. package/dist/core/BudgetReadout.d.ts.map +1 -1
  57. package/dist/core/BudgetReadout.js +23 -32
  58. package/dist/core/BudgetReadout.js.map +1 -1
  59. package/dist/core/CapabilityPolicies.d.ts +3 -8
  60. package/dist/core/CapabilityPolicies.d.ts.map +1 -1
  61. package/dist/core/CapabilityPolicies.js +2 -28
  62. package/dist/core/CapabilityPolicies.js.map +1 -1
  63. package/dist/core/CapabilityResolver.d.ts +10 -10
  64. package/dist/core/CapabilityResolver.d.ts.map +1 -1
  65. package/dist/core/CapabilityResolver.js +122 -93
  66. package/dist/core/CapabilityResolver.js.map +1 -1
  67. package/dist/core/ChannelWrite.d.ts +15 -11
  68. package/dist/core/ChannelWrite.d.ts.map +1 -1
  69. package/dist/core/ChannelWrite.js +12 -13
  70. package/dist/core/ChannelWrite.js.map +1 -1
  71. package/dist/core/ChannelWrite.sql +99 -9
  72. package/dist/core/ClientInteractions.d.ts.map +1 -1
  73. package/dist/core/ClientInteractions.js +7 -0
  74. package/dist/core/ClientInteractions.js.map +1 -1
  75. package/dist/core/CoreSchemeServices.d.ts +13 -10
  76. package/dist/core/CoreSchemeServices.d.ts.map +1 -1
  77. package/dist/core/CoreSchemeServices.js +13 -5
  78. package/dist/core/CoreSchemeServices.js.map +1 -1
  79. package/dist/core/DataStatementRunner.d.ts +2 -2
  80. package/dist/core/DataStatementRunner.d.ts.map +1 -1
  81. package/dist/core/DataStatementRunner.js +208 -161
  82. package/dist/core/DataStatementRunner.js.map +1 -1
  83. package/dist/core/Dispatcher.d.ts +24 -26
  84. package/dist/core/Dispatcher.d.ts.map +1 -1
  85. package/dist/core/Dispatcher.js +381 -232
  86. package/dist/core/Dispatcher.js.map +1 -1
  87. package/dist/core/Dispatcher.sql +66 -0
  88. package/dist/core/DurableStatement.d.ts.map +1 -1
  89. package/dist/core/DurableStatement.js +2 -1
  90. package/dist/core/DurableStatement.js.map +1 -1
  91. package/dist/core/EditMutations.d.ts +14 -18
  92. package/dist/core/EditMutations.d.ts.map +1 -1
  93. package/dist/core/EditMutations.js +211 -280
  94. package/dist/core/EditMutations.js.map +1 -1
  95. package/dist/core/EditMutations.sql +15 -0
  96. package/dist/core/EditSequence.d.ts +13 -0
  97. package/dist/core/EditSequence.d.ts.map +1 -0
  98. package/dist/core/EditSequence.js +73 -0
  99. package/dist/core/EditSequence.js.map +1 -0
  100. package/dist/core/Engine.d.ts +17 -23
  101. package/dist/core/Engine.d.ts.map +1 -1
  102. package/dist/core/Engine.js +74 -164
  103. package/dist/core/Engine.js.map +1 -1
  104. package/dist/core/Engine.sql +0 -724
  105. package/dist/core/EntryAddressBinding.d.ts +7 -17
  106. package/dist/core/EntryAddressBinding.d.ts.map +1 -1
  107. package/dist/core/EntryAddressBinding.js +12 -72
  108. package/dist/core/EntryAddressBinding.js.map +1 -1
  109. package/dist/core/ExecutionOutputs.d.ts +9 -0
  110. package/dist/core/ExecutionOutputs.d.ts.map +1 -0
  111. package/dist/core/ExecutionOutputs.js +36 -0
  112. package/dist/core/ExecutionOutputs.js.map +1 -0
  113. package/dist/core/ExecutionOutputs.sql +21 -0
  114. package/dist/core/ExecutorRegistry.d.ts +11 -5
  115. package/dist/core/ExecutorRegistry.d.ts.map +1 -1
  116. package/dist/core/ExecutorRegistry.js +37 -32
  117. package/dist/core/ExecutorRegistry.js.map +1 -1
  118. package/dist/core/HostPaths.d.ts +1 -0
  119. package/dist/core/HostPaths.d.ts.map +1 -1
  120. package/dist/core/HostPaths.js +4 -0
  121. package/dist/core/HostPaths.js.map +1 -1
  122. package/dist/core/InferenceCall.d.ts.map +1 -1
  123. package/dist/core/InferenceCall.js +1 -2
  124. package/dist/core/InferenceCall.js.map +1 -1
  125. package/dist/core/InferenceCall.sql +29 -0
  126. package/dist/core/KillHandler.d.ts +1 -0
  127. package/dist/core/KillHandler.d.ts.map +1 -1
  128. package/dist/core/KillHandler.js +24 -21
  129. package/dist/core/KillHandler.js.map +1 -1
  130. package/dist/core/LogBody.d.ts +8 -1
  131. package/dist/core/LogBody.d.ts.map +1 -1
  132. package/dist/core/LogBody.js +44 -12
  133. package/dist/core/LogBody.js.map +1 -1
  134. package/dist/core/LogEntryProjection.d.ts +1 -0
  135. package/dist/core/LogEntryProjection.d.ts.map +1 -1
  136. package/dist/core/LogEntryProjection.js +12 -10
  137. package/dist/core/LogEntryProjection.js.map +1 -1
  138. package/dist/core/LogVisibility.d.ts +1 -0
  139. package/dist/core/LogVisibility.d.ts.map +1 -1
  140. package/dist/core/LogVisibility.js +3 -0
  141. package/dist/core/LogVisibility.js.map +1 -1
  142. package/dist/core/LogWriter.d.ts +2 -3
  143. package/dist/core/LogWriter.d.ts.map +1 -1
  144. package/dist/core/LogWriter.js +31 -36
  145. package/dist/core/LogWriter.js.map +1 -1
  146. package/dist/core/LogWriter.sql +23 -0
  147. package/dist/core/LoopDriver.d.ts +11 -8
  148. package/dist/core/LoopDriver.d.ts.map +1 -1
  149. package/dist/core/LoopDriver.js +161 -189
  150. package/dist/core/LoopDriver.js.map +1 -1
  151. package/dist/core/LoopDriver.sql +11 -0
  152. package/dist/core/LoopLifecycle.d.ts +32 -2
  153. package/dist/core/LoopLifecycle.d.ts.map +1 -1
  154. package/dist/core/LoopLifecycle.js +88 -4
  155. package/dist/core/LoopLifecycle.js.map +1 -1
  156. package/dist/core/LoopLifecycle.sql +145 -28
  157. package/dist/core/LoopPolicyReader.sql +6 -0
  158. package/dist/core/MembershipMaterialization.d.ts.map +1 -1
  159. package/dist/core/MembershipMaterialization.js +6 -28
  160. package/dist/core/MembershipMaterialization.js.map +1 -1
  161. package/dist/core/ModelCall.d.ts.map +1 -1
  162. package/dist/core/ModelCall.js +2 -6
  163. package/dist/core/ModelCall.js.map +1 -1
  164. package/dist/core/ModelCall.sql +41 -0
  165. package/dist/core/MutationEffects.d.ts +5 -3
  166. package/dist/core/MutationEffects.d.ts.map +1 -1
  167. package/dist/core/MutationEffects.js +10 -28
  168. package/dist/core/MutationEffects.js.map +1 -1
  169. package/dist/core/NativeContent.d.ts +6 -0
  170. package/dist/core/NativeContent.d.ts.map +1 -0
  171. package/dist/core/NativeContent.js +16 -0
  172. package/dist/core/NativeContent.js.map +1 -0
  173. package/dist/core/NativeContent.sql +6 -0
  174. package/dist/core/NoticeChannel.js +1 -1
  175. package/dist/core/NoticeChannel.js.map +1 -1
  176. package/dist/core/OperatorConfig.js +5 -5
  177. package/dist/core/OperatorConfig.js.map +1 -1
  178. package/dist/core/PacketBuilder.d.ts +8 -5
  179. package/dist/core/PacketBuilder.d.ts.map +1 -1
  180. package/dist/core/PacketBuilder.js +117 -81
  181. package/dist/core/PacketBuilder.js.map +1 -1
  182. package/dist/core/PacketBuilder.sql +146 -0
  183. package/dist/core/PatternSelection.d.ts +28 -0
  184. package/dist/core/PatternSelection.d.ts.map +1 -0
  185. package/dist/core/PatternSelection.js +42 -0
  186. package/dist/core/PatternSelection.js.map +1 -0
  187. package/dist/core/ProblemLog.d.ts.map +1 -1
  188. package/dist/core/ProblemLog.js +0 -1
  189. package/dist/core/ProblemLog.js.map +1 -1
  190. package/dist/core/PromptFrames.d.ts +12 -0
  191. package/dist/core/PromptFrames.d.ts.map +1 -0
  192. package/dist/core/PromptFrames.js +28 -0
  193. package/dist/core/PromptFrames.js.map +1 -0
  194. package/dist/core/ProposalLifecycle.d.ts +0 -1
  195. package/dist/core/ProposalLifecycle.d.ts.map +1 -1
  196. package/dist/core/ProposalLifecycle.js +26 -23
  197. package/dist/core/ProposalLifecycle.js.map +1 -1
  198. package/dist/core/ProposalLifecycle.sql +33 -0
  199. package/dist/core/ProviderInstantiate.d.ts +1 -1
  200. package/dist/core/ProviderInstantiate.d.ts.map +1 -1
  201. package/dist/core/ProviderInstantiate.js +7 -14
  202. package/dist/core/ProviderInstantiate.js.map +1 -1
  203. package/dist/core/ReasoningView.d.ts +9 -0
  204. package/dist/core/ReasoningView.d.ts.map +1 -0
  205. package/dist/core/ReasoningView.js +47 -0
  206. package/dist/core/ReasoningView.js.map +1 -0
  207. package/dist/core/ResourceBindings.d.ts +16 -0
  208. package/dist/core/ResourceBindings.d.ts.map +1 -0
  209. package/dist/core/ResourceBindings.js +45 -0
  210. package/dist/core/ResourceBindings.js.map +1 -0
  211. package/dist/core/ResourceMutations.d.ts +5 -8
  212. package/dist/core/ResourceMutations.d.ts.map +1 -1
  213. package/dist/core/ResourceMutations.js +6 -7
  214. package/dist/core/ResourceMutations.js.map +1 -1
  215. package/dist/core/ResourceSelector.d.ts +2 -2
  216. package/dist/core/ResourceSelector.d.ts.map +1 -1
  217. package/dist/core/ResourceSelector.js +122 -62
  218. package/dist/core/ResourceSelector.js.map +1 -1
  219. package/dist/core/ResourceTransfers.d.ts +4 -2
  220. package/dist/core/ResourceTransfers.d.ts.map +1 -1
  221. package/dist/core/ResourceTransfers.js +95 -26
  222. package/dist/core/ResourceTransfers.js.map +1 -1
  223. package/dist/core/RuntimeWorker.d.ts +5 -0
  224. package/dist/core/RuntimeWorker.d.ts.map +1 -0
  225. package/dist/core/RuntimeWorker.js +15 -0
  226. package/dist/core/RuntimeWorker.js.map +1 -0
  227. package/dist/core/RuntimeWorker.sql +11 -0
  228. package/dist/core/SchemeRegistry.d.ts +12 -16
  229. package/dist/core/SchemeRegistry.d.ts.map +1 -1
  230. package/dist/core/SchemeRegistry.js +59 -85
  231. package/dist/core/SchemeRegistry.js.map +1 -1
  232. package/dist/core/StoredPacket.d.ts +6 -1
  233. package/dist/core/StoredPacket.d.ts.map +1 -1
  234. package/dist/core/StoredPacket.js +30 -10
  235. package/dist/core/StoredPacket.js.map +1 -1
  236. package/dist/core/StrikeRail.d.ts +11 -8
  237. package/dist/core/StrikeRail.d.ts.map +1 -1
  238. package/dist/core/StrikeRail.js +63 -114
  239. package/dist/core/StrikeRail.js.map +1 -1
  240. package/dist/core/StrikeRail.sql +12 -0
  241. package/dist/core/TerminalResult.d.ts +1 -1
  242. package/dist/core/TerminalResult.d.ts.map +1 -1
  243. package/dist/core/TerminalResult.js +2 -2
  244. package/dist/core/TerminalResult.js.map +1 -1
  245. package/dist/core/TokenCalibration.d.ts +1 -6
  246. package/dist/core/TokenCalibration.d.ts.map +1 -1
  247. package/dist/core/TokenCalibration.js +13 -9
  248. package/dist/core/TokenCalibration.js.map +1 -1
  249. package/dist/core/TokenCalibration.sql +15 -0
  250. package/dist/core/ToolInputSchema.d.ts +6 -0
  251. package/dist/core/ToolInputSchema.d.ts.map +1 -0
  252. package/dist/core/ToolInputSchema.js +43 -0
  253. package/dist/core/ToolInputSchema.js.map +1 -0
  254. package/dist/core/ToolResources.d.ts.map +1 -1
  255. package/dist/core/ToolResources.js +77 -51
  256. package/dist/core/ToolResources.js.map +1 -1
  257. package/dist/core/Turn.d.ts +5 -2
  258. package/dist/core/Turn.d.ts.map +1 -1
  259. package/dist/core/Turn.js +13 -11
  260. package/dist/core/Turn.js.map +1 -1
  261. package/dist/core/Turn.sql +25 -39
  262. package/dist/core/{SendBroadcastHandler.d.ts → TurnDispositionHandler.d.ts} +24 -18
  263. package/dist/core/TurnDispositionHandler.d.ts.map +1 -0
  264. package/dist/core/TurnDispositionHandler.js +206 -0
  265. package/dist/core/TurnDispositionHandler.js.map +1 -0
  266. package/dist/core/TurnMaterialization.d.ts +2 -3
  267. package/dist/core/TurnMaterialization.d.ts.map +1 -1
  268. package/dist/core/TurnMaterialization.js +47 -24
  269. package/dist/core/TurnMaterialization.js.map +1 -1
  270. package/dist/core/TurnMaterialization.sql +44 -0
  271. package/dist/core/TurnOps.d.ts.map +1 -1
  272. package/dist/core/TurnOps.js +8 -64
  273. package/dist/core/TurnOps.js.map +1 -1
  274. package/dist/core/TurnRunner.d.ts +8 -15
  275. package/dist/core/TurnRunner.d.ts.map +1 -1
  276. package/dist/core/TurnRunner.js +1175 -1317
  277. package/dist/core/TurnRunner.js.map +1 -1
  278. package/dist/core/TurnRunner.sql +74 -0
  279. package/dist/core/TurnSources.sql +39 -0
  280. package/dist/core/WorkerControlAddress.d.ts +1 -0
  281. package/dist/core/WorkerControlAddress.d.ts.map +1 -1
  282. package/dist/core/WorkerControlAddress.js +5 -0
  283. package/dist/core/WorkerControlAddress.js.map +1 -1
  284. package/dist/core/WorkerControlHandler.d.ts +1 -3
  285. package/dist/core/WorkerControlHandler.d.ts.map +1 -1
  286. package/dist/core/WorkerControlHandler.js +64 -48
  287. package/dist/core/WorkerControlHandler.js.map +1 -1
  288. package/dist/core/WorkerName.d.ts +11 -12
  289. package/dist/core/WorkerName.d.ts.map +1 -1
  290. package/dist/core/WorkerName.js +40 -47
  291. package/dist/core/WorkerName.js.map +1 -1
  292. package/dist/core/WorkerName.sql +7 -10
  293. package/dist/core/WorkspaceGate.d.ts +1 -1
  294. package/dist/core/WorkspaceGate.d.ts.map +1 -1
  295. package/dist/core/WorkspaceGate.js +33 -10
  296. package/dist/core/WorkspaceGate.js.map +1 -1
  297. package/dist/core/ambient.sql +236 -0
  298. package/dist/core/attachments.d.ts +2 -1
  299. package/dist/core/attachments.d.ts.map +1 -1
  300. package/dist/core/attachments.js +5 -4
  301. package/dist/core/attachments.js.map +1 -1
  302. package/dist/core/caps/CapsResolve.d.ts +2 -3
  303. package/dist/core/caps/CapsResolve.d.ts.map +1 -1
  304. package/dist/core/caps/CapsResolve.js +5 -5
  305. package/dist/core/caps/CapsResolve.js.map +1 -1
  306. package/dist/core/caps/DbChannelCaps.d.ts +1 -1
  307. package/dist/core/caps/DbChannelCaps.d.ts.map +1 -1
  308. package/dist/core/caps/DbChannelCaps.js +4 -6
  309. package/dist/core/caps/DbChannelCaps.js.map +1 -1
  310. package/dist/core/caps/DbEntryCaps.d.ts +2 -1
  311. package/dist/core/caps/DbEntryCaps.d.ts.map +1 -1
  312. package/dist/core/caps/DbEntryCaps.js +11 -17
  313. package/dist/core/caps/DbEntryCaps.js.map +1 -1
  314. package/dist/core/caps/DbNotifyCaps.d.ts +1 -1
  315. package/dist/core/caps/DbNotifyCaps.d.ts.map +1 -1
  316. package/dist/core/caps/DbNotifyCaps.js +3 -5
  317. package/dist/core/caps/DbNotifyCaps.js.map +1 -1
  318. package/dist/core/caps/DbProjectionCaps.js +1 -1
  319. package/dist/core/caps/DbProjectionCaps.js.map +1 -1
  320. package/dist/core/caps/DbSubscriptionCaps.d.ts +1 -1
  321. package/dist/core/caps/DbSubscriptionCaps.d.ts.map +1 -1
  322. package/dist/core/caps/DbSubscriptionCaps.js +5 -7
  323. package/dist/core/caps/DbSubscriptionCaps.js.map +1 -1
  324. package/dist/core/caps/SchemeCtxImpl.d.ts +0 -2
  325. package/dist/core/caps/SchemeCtxImpl.d.ts.map +1 -1
  326. package/dist/core/caps/SchemeCtxImpl.js +4 -20
  327. package/dist/core/caps/SchemeCtxImpl.js.map +1 -1
  328. package/dist/core/env-catalog.d.ts +28 -0
  329. package/dist/core/env-catalog.d.ts.map +1 -0
  330. package/dist/core/env-catalog.js +99 -0
  331. package/dist/core/env-catalog.js.map +1 -0
  332. package/dist/core/env-defaults.d.ts.map +1 -1
  333. package/dist/core/env-defaults.js +4 -2
  334. package/dist/core/env-defaults.js.map +1 -1
  335. package/dist/core/file-materialization.d.ts +4 -1
  336. package/dist/core/file-materialization.d.ts.map +1 -1
  337. package/dist/core/file-materialization.js +15 -1
  338. package/dist/core/file-materialization.js.map +1 -1
  339. package/dist/core/fork.d.ts +1 -6
  340. package/dist/core/fork.d.ts.map +1 -1
  341. package/dist/core/fork.js +9 -153
  342. package/dist/core/fork.js.map +1 -1
  343. package/dist/core/fork.sql +162 -185
  344. package/dist/core/git-env.d.ts +1 -0
  345. package/dist/core/git-env.d.ts.map +1 -1
  346. package/dist/core/git-env.js +39 -2
  347. package/dist/core/git-env.js.map +1 -1
  348. package/dist/core/git-membership.d.ts.map +1 -1
  349. package/dist/core/git-membership.js +64 -48
  350. package/dist/core/git-membership.js.map +1 -1
  351. package/dist/core/git-state.d.ts.map +1 -1
  352. package/dist/core/git-state.js +26 -20
  353. package/dist/core/git-state.js.map +1 -1
  354. package/dist/core/glob_match.d.ts +4 -0
  355. package/dist/core/glob_match.d.ts.map +1 -0
  356. package/dist/core/glob_match.js +7 -0
  357. package/dist/core/glob_match.js.map +1 -0
  358. package/dist/core/maintenance.sql +6 -0
  359. package/dist/core/mutation-types.d.ts +7 -28
  360. package/dist/core/mutation-types.d.ts.map +1 -1
  361. package/dist/core/operation-target-groups.d.ts.map +1 -1
  362. package/dist/core/operation-target-groups.js +2 -1
  363. package/dist/core/operation-target-groups.js.map +1 -1
  364. package/dist/core/packet-inject.d.ts.map +1 -1
  365. package/dist/core/packet-inject.js +2 -3
  366. package/dist/core/packet-inject.js.map +1 -1
  367. package/dist/core/packet-wire.d.ts +8 -6
  368. package/dist/core/packet-wire.d.ts.map +1 -1
  369. package/dist/core/packet-wire.js +381 -388
  370. package/dist/core/packet-wire.js.map +1 -1
  371. package/dist/core/plurnk-uri.d.ts +1 -1
  372. package/dist/core/plurnk-uri.d.ts.map +1 -1
  373. package/dist/core/plurnk-uri.js +5 -12
  374. package/dist/core/plurnk-uri.js.map +1 -1
  375. package/dist/core/scheme-types.d.ts +3 -3
  376. package/dist/core/scheme-types.d.ts.map +1 -1
  377. package/dist/core/scheme-types.js.map +1 -1
  378. package/dist/core/sha256.d.ts +4 -0
  379. package/dist/core/sha256.d.ts.map +1 -0
  380. package/dist/core/sha256.js +6 -0
  381. package/dist/core/sha256.js.map +1 -0
  382. package/dist/core/teaching.js +1 -1
  383. package/dist/core/teaching.js.map +1 -1
  384. package/dist/core/turn-scheduler.d.ts.map +1 -1
  385. package/dist/core/turn-scheduler.js +5 -18
  386. package/dist/core/turn-scheduler.js.map +1 -1
  387. package/dist/core/turn-signals.d.ts +0 -6
  388. package/dist/core/turn-signals.d.ts.map +1 -1
  389. package/dist/core/turn-signals.js +1 -7
  390. package/dist/core/turn-signals.js.map +1 -1
  391. package/dist/core/worker-ops.sql +15 -22
  392. package/dist/core/workspace-settings.d.ts.map +1 -1
  393. package/dist/core/workspace-settings.js +18 -2
  394. package/dist/core/workspace-settings.js.map +1 -1
  395. package/dist/core/workspace-settings.sql +6 -0
  396. package/dist/digest/Digest.d.ts.map +1 -1
  397. package/dist/digest/Digest.js +30 -91
  398. package/dist/digest/Digest.js.map +1 -1
  399. package/dist/digest/DigestRender.d.ts +1 -0
  400. package/dist/digest/DigestRender.d.ts.map +1 -1
  401. package/dist/digest/DigestRender.js +58 -62
  402. package/dist/digest/DigestRender.js.map +1 -1
  403. package/dist/digest/digest-rows.d.ts +16 -32
  404. package/dist/digest/digest-rows.d.ts.map +1 -1
  405. package/dist/digest/digest.sql +54 -20
  406. package/dist/schemes/Exec.d.ts +6 -12
  407. package/dist/schemes/Exec.d.ts.map +1 -1
  408. package/dist/schemes/Exec.js +318 -215
  409. package/dist/schemes/Exec.js.map +1 -1
  410. package/dist/schemes/ExecOutputScheme.d.ts +8 -6
  411. package/dist/schemes/ExecOutputScheme.d.ts.map +1 -1
  412. package/dist/schemes/ExecOutputScheme.js +33 -61
  413. package/dist/schemes/ExecOutputScheme.js.map +1 -1
  414. package/dist/schemes/ExecScheduler.js +2 -2
  415. package/dist/schemes/ExecScheduler.js.map +1 -1
  416. package/dist/schemes/ExecutionInput.d.ts +12 -0
  417. package/dist/schemes/ExecutionInput.d.ts.map +1 -0
  418. package/dist/schemes/ExecutionInput.js +94 -0
  419. package/dist/schemes/ExecutionInput.js.map +1 -0
  420. package/dist/schemes/File.d.ts +5 -2
  421. package/dist/schemes/File.d.ts.map +1 -1
  422. package/dist/schemes/File.js +62 -91
  423. package/dist/schemes/File.js.map +1 -1
  424. package/dist/schemes/Log.d.ts.map +1 -1
  425. package/dist/schemes/Log.js +84 -79
  426. package/dist/schemes/Log.js.map +1 -1
  427. package/dist/schemes/Log.sql +183 -15
  428. package/dist/schemes/Prompt.d.ts.map +1 -1
  429. package/dist/schemes/Prompt.js +3 -12
  430. package/dist/schemes/Prompt.js.map +1 -1
  431. package/dist/schemes/QuestionTool.d.ts +5 -0
  432. package/dist/schemes/QuestionTool.d.ts.map +1 -1
  433. package/dist/schemes/QuestionTool.js +7 -15
  434. package/dist/schemes/QuestionTool.js.map +1 -1
  435. package/dist/schemes/Skill.d.ts +12 -7
  436. package/dist/schemes/Skill.d.ts.map +1 -1
  437. package/dist/schemes/Skill.js +149 -21
  438. package/dist/schemes/Skill.js.map +1 -1
  439. package/dist/schemes/TurnSource.d.ts +12 -0
  440. package/dist/schemes/TurnSource.d.ts.map +1 -0
  441. package/dist/schemes/TurnSource.js +117 -0
  442. package/dist/schemes/TurnSource.js.map +1 -0
  443. package/dist/schemes/Worker.d.ts +3 -3
  444. package/dist/schemes/Worker.d.ts.map +1 -1
  445. package/dist/schemes/Worker.js +61 -208
  446. package/dist/schemes/Worker.js.map +1 -1
  447. package/dist/schemes/_entry-crud.d.ts +12 -15
  448. package/dist/schemes/_entry-crud.d.ts.map +1 -1
  449. package/dist/schemes/_entry-crud.js +63 -63
  450. package/dist/schemes/_entry-crud.js.map +1 -1
  451. package/dist/schemes/_entry-crud.sql +159 -45
  452. package/dist/schemes/_entry-find.d.ts +1 -3
  453. package/dist/schemes/_entry-find.d.ts.map +1 -1
  454. package/dist/schemes/_entry-find.js +111 -112
  455. package/dist/schemes/_entry-find.js.map +1 -1
  456. package/dist/schemes/_entry-find.sql +22 -14
  457. package/dist/schemes/_entry-fts.d.ts +14 -0
  458. package/dist/schemes/_entry-fts.d.ts.map +1 -0
  459. package/dist/schemes/_entry-fts.js +82 -0
  460. package/dist/schemes/_entry-fts.js.map +1 -0
  461. package/dist/schemes/_entry-fts.sql +31 -0
  462. package/dist/schemes/_entry-graph.d.ts.map +1 -1
  463. package/dist/schemes/_entry-graph.js +6 -14
  464. package/dist/schemes/_entry-graph.js.map +1 -1
  465. package/dist/schemes/_entry-graph.sql +29 -44
  466. package/dist/schemes/_entry-manifest.d.ts +2 -1
  467. package/dist/schemes/_entry-manifest.d.ts.map +1 -1
  468. package/dist/schemes/_entry-manifest.js +20 -26
  469. package/dist/schemes/_entry-manifest.js.map +1 -1
  470. package/dist/schemes/_entry-manifest.sql +26 -0
  471. package/dist/schemes/_entry-ops.d.ts +3 -5
  472. package/dist/schemes/_entry-ops.d.ts.map +1 -1
  473. package/dist/schemes/_entry-ops.js +30 -43
  474. package/dist/schemes/_entry-ops.js.map +1 -1
  475. package/dist/schemes/_entry-ops.sql +5 -6
  476. package/dist/schemes/_entry-readable.d.ts +8 -0
  477. package/dist/schemes/_entry-readable.d.ts.map +1 -0
  478. package/dist/schemes/_entry-readable.js +38 -0
  479. package/dist/schemes/_entry-readable.js.map +1 -0
  480. package/dist/schemes/_entry-send.d.ts +1 -1
  481. package/dist/schemes/_entry-send.d.ts.map +1 -1
  482. package/dist/schemes/_entry-send.js +3 -3
  483. package/dist/schemes/_entry-send.js.map +1 -1
  484. package/dist/schemes/_search-index.d.ts +5 -3
  485. package/dist/schemes/_search-index.d.ts.map +1 -1
  486. package/dist/schemes/_search-index.js +169 -160
  487. package/dist/schemes/_search-index.js.map +1 -1
  488. package/dist/schemes/_search-index.sql +47 -0
  489. package/dist/schemes/exec-abort.js +1 -1
  490. package/dist/schemes/exec-abort.js.map +1 -1
  491. package/dist/schemes/exec-env.d.ts +3 -0
  492. package/dist/schemes/exec-env.d.ts.map +1 -1
  493. package/dist/schemes/exec-env.js +66 -15
  494. package/dist/schemes/exec-env.js.map +1 -1
  495. package/dist/schemes/exec-runtime.d.ts +1 -1
  496. package/dist/schemes/exec-runtime.d.ts.map +1 -1
  497. package/dist/schemes/exec-runtime.js +1 -1
  498. package/dist/schemes/exec-runtime.js.map +1 -1
  499. package/dist/server/ClientReads.d.ts +2 -2
  500. package/dist/server/ClientReads.d.ts.map +1 -1
  501. package/dist/server/ClientReads.js +7 -9
  502. package/dist/server/ClientReads.js.map +1 -1
  503. package/dist/server/Daemon.d.ts +15 -21
  504. package/dist/server/Daemon.d.ts.map +1 -1
  505. package/dist/server/Daemon.js +165 -168
  506. package/dist/server/Daemon.js.map +1 -1
  507. package/dist/server/DaemonModule.d.ts +29 -22
  508. package/dist/server/DaemonModule.d.ts.map +1 -1
  509. package/dist/server/DrainSupervisor.d.ts +8 -21
  510. package/dist/server/DrainSupervisor.d.ts.map +1 -1
  511. package/dist/server/DrainSupervisor.js +278 -306
  512. package/dist/server/DrainSupervisor.js.map +1 -1
  513. package/dist/server/EnvFunctionality.d.ts +43 -0
  514. package/dist/server/EnvFunctionality.d.ts.map +1 -0
  515. package/dist/server/EnvFunctionality.js +194 -0
  516. package/dist/server/EnvFunctionality.js.map +1 -0
  517. package/dist/server/Functionality.d.ts +12 -11
  518. package/dist/server/Functionality.d.ts.map +1 -1
  519. package/dist/server/Functionality.js +279 -142
  520. package/dist/server/Functionality.js.map +1 -1
  521. package/dist/server/FunctionalityManager.d.ts +5 -5
  522. package/dist/server/FunctionalityManager.d.ts.map +1 -1
  523. package/dist/server/FunctionalityManager.js +29 -57
  524. package/dist/server/FunctionalityManager.js.map +1 -1
  525. package/dist/server/MembersFunctionality.d.ts +5 -4
  526. package/dist/server/MembersFunctionality.d.ts.map +1 -1
  527. package/dist/server/MembersFunctionality.js +24 -38
  528. package/dist/server/MembersFunctionality.js.map +1 -1
  529. package/dist/server/PlurnkSkill.d.ts +11 -0
  530. package/dist/server/PlurnkSkill.d.ts.map +1 -0
  531. package/dist/server/PlurnkSkill.js +41 -0
  532. package/dist/server/PlurnkSkill.js.map +1 -0
  533. package/dist/server/Retention.d.ts +25 -0
  534. package/dist/server/Retention.d.ts.map +1 -0
  535. package/dist/server/Retention.js +57 -0
  536. package/dist/server/Retention.js.map +1 -0
  537. package/dist/server/Retention.sql +59 -0
  538. package/dist/server/ServiceModules.d.ts +5 -0
  539. package/dist/server/ServiceModules.d.ts.map +1 -0
  540. package/dist/server/ServiceModules.js +10 -0
  541. package/dist/server/ServiceModules.js.map +1 -0
  542. package/dist/server/SkillsFunctionality.d.ts +14 -19
  543. package/dist/server/SkillsFunctionality.d.ts.map +1 -1
  544. package/dist/server/SkillsFunctionality.js +102 -106
  545. package/dist/server/SkillsFunctionality.js.map +1 -1
  546. package/dist/server/WorkerModelResolver.d.ts +4 -0
  547. package/dist/server/WorkerModelResolver.d.ts.map +1 -1
  548. package/dist/server/WorkerModelResolver.js +72 -39
  549. package/dist/server/WorkerModelResolver.js.map +1 -1
  550. package/dist/server/WorkspaceCapabilities.d.ts +21 -0
  551. package/dist/server/WorkspaceCapabilities.d.ts.map +1 -0
  552. package/dist/server/{WorkerCapabilities.js → WorkspaceCapabilities.js} +40 -40
  553. package/dist/server/WorkspaceCapabilities.js.map +1 -0
  554. package/dist/server/WorkspaceResidency.d.ts +38 -0
  555. package/dist/server/WorkspaceResidency.d.ts.map +1 -0
  556. package/dist/server/WorkspaceResidency.js +226 -0
  557. package/dist/server/WorkspaceResidency.js.map +1 -0
  558. package/dist/server/client-input.d.ts +1 -4
  559. package/dist/server/client-input.d.ts.map +1 -1
  560. package/dist/server/client-input.js +5 -46
  561. package/dist/server/client-input.js.map +1 -1
  562. package/dist/server/dispatch-as-plurnk.d.ts.map +1 -1
  563. package/dist/server/dispatch-as-plurnk.js +4 -22
  564. package/dist/server/dispatch-as-plurnk.js.map +1 -1
  565. package/dist/server/drain.sql +66 -43
  566. package/dist/server/envelope.d.ts +8 -1
  567. package/dist/server/envelope.d.ts.map +1 -1
  568. package/dist/server/envelope.js +9 -19
  569. package/dist/server/envelope.js.map +1 -1
  570. package/dist/server/envelope.sql +49 -13
  571. package/dist/server/lifecycle-recovery.sql +18 -20
  572. package/dist/server/logEntry.d.ts +1 -1
  573. package/dist/server/logEntry.d.ts.map +1 -1
  574. package/dist/server/logEntry.js +4 -1
  575. package/dist/server/logEntry.js.map +1 -1
  576. package/dist/server/logEntry.sql +25 -1
  577. package/dist/server/loopDocs.d.ts +2 -2
  578. package/dist/server/loopDocs.d.ts.map +1 -1
  579. package/dist/server/loopDocs.js +38 -31
  580. package/dist/server/loopDocs.js.map +1 -1
  581. package/dist/server/loopDocs.sql +1 -3
  582. package/dist/server/model-catalog.d.ts.map +1 -1
  583. package/dist/server/model-catalog.js +2 -1
  584. package/dist/server/model-catalog.js.map +1 -1
  585. package/dist/server/model-route.d.ts +1 -1
  586. package/dist/server/model-route.d.ts.map +1 -1
  587. package/dist/server/model-route.js +4 -2
  588. package/dist/server/model-route.js.map +1 -1
  589. package/dist/server/seam-entry-read.sql +3 -4
  590. package/dist/server/seam-loop.sql +2 -9
  591. package/dist/server/workspace-capabilities.sql +64 -0
  592. package/dist/service.d.ts.map +1 -1
  593. package/dist/service.js +21 -18
  594. package/dist/service.js.map +1 -1
  595. package/docs/env.md +55 -0
  596. package/docs/members.md +83 -0
  597. package/docs/skills.md +50 -0
  598. package/migrations/001_workspaces.sql +53 -0
  599. package/migrations/002_workers.sql +198 -0
  600. package/migrations/003_loops.sql +326 -0
  601. package/migrations/004_inference.sql +401 -0
  602. package/migrations/005_entries.sql +215 -0
  603. package/migrations/006_log.sql +581 -0
  604. package/migrations/007_subscriptions.sql +175 -0
  605. package/migrations/008_interactions.sql +29 -0
  606. package/package.json +44 -41
  607. package/digest-sql/channel-dispositions/dispositions.sql +0 -15
  608. package/digest-sql/channel-state/state.sql +0 -6
  609. package/digest-sql/curation/curation.sql +0 -6
  610. package/digest-sql/derivations/derivations.sql +0 -4
  611. package/digest-sql/embeddings/embeddings.sql +0 -4
  612. package/digest-sql/entry-dispositions/dispositions.sql +0 -15
  613. package/digest-sql/entry-state/state.sql +0 -6
  614. package/digest-sql/token-counts/token-counts.sql +0 -2
  615. package/dist/core/EmbeddingCall.d.ts +0 -23
  616. package/dist/core/EmbeddingCall.d.ts.map +0 -1
  617. package/dist/core/EmbeddingCall.js +0 -149
  618. package/dist/core/EmbeddingCall.js.map +0 -1
  619. package/dist/core/OverflowTurn.d.ts +0 -11
  620. package/dist/core/OverflowTurn.d.ts.map +0 -1
  621. package/dist/core/OverflowTurn.js +0 -80
  622. package/dist/core/OverflowTurn.js.map +0 -1
  623. package/dist/core/Owner.d.ts +0 -8
  624. package/dist/core/Owner.d.ts.map +0 -1
  625. package/dist/core/Owner.js +0 -46
  626. package/dist/core/Owner.js.map +0 -1
  627. package/dist/core/SendBroadcastHandler.d.ts.map +0 -1
  628. package/dist/core/SendBroadcastHandler.js +0 -159
  629. package/dist/core/SendBroadcastHandler.js.map +0 -1
  630. package/dist/core/VectorPump.d.ts +0 -28
  631. package/dist/core/VectorPump.d.ts.map +0 -1
  632. package/dist/core/VectorPump.js +0 -130
  633. package/dist/core/VectorPump.js.map +0 -1
  634. package/dist/core/owner.sql +0 -11
  635. package/dist/core/worker-settings.d.ts +0 -10
  636. package/dist/core/worker-settings.d.ts.map +0 -1
  637. package/dist/core/worker-settings.js +0 -53
  638. package/dist/core/worker-settings.js.map +0 -1
  639. package/dist/schemes/_entry-chunk.d.ts +0 -14
  640. package/dist/schemes/_entry-chunk.d.ts.map +0 -1
  641. package/dist/schemes/_entry-chunk.js +0 -165
  642. package/dist/schemes/_entry-chunk.js.map +0 -1
  643. package/dist/schemes/_entry-semantic.d.ts +0 -63
  644. package/dist/schemes/_entry-semantic.d.ts.map +0 -1
  645. package/dist/schemes/_entry-semantic.js +0 -299
  646. package/dist/schemes/_entry-semantic.js.map +0 -1
  647. package/dist/schemes/_entry-semantic.sql +0 -99
  648. package/dist/schemes/cosine.d.ts +0 -4
  649. package/dist/schemes/cosine.d.ts.map +0 -1
  650. package/dist/schemes/cosine.js +0 -9
  651. package/dist/schemes/cosine.js.map +0 -1
  652. package/dist/server/WorkerCapabilities.d.ts +0 -21
  653. package/dist/server/WorkerCapabilities.d.ts.map +0 -1
  654. package/dist/server/WorkerCapabilities.js.map +0 -1
  655. package/dist/server/WorkerResidency.d.ts +0 -40
  656. package/dist/server/WorkerResidency.d.ts.map +0 -1
  657. package/dist/server/WorkerResidency.js +0 -283
  658. package/dist/server/WorkerResidency.js.map +0 -1
  659. package/dist/server/seam-log-read.sql +0 -21
  660. package/dist/server/worker-capabilities.sql +0 -28
  661. package/migrations/001_schema.sql +0 -2207
@@ -1,11 +1,4 @@
1
- // Packet → wire markdown projection. Single source of truth for how the
2
- // Packet's ordered list of sections renders to ChatMessage.content
3
- // strings the LLM receives. Engine imports this for the wire payload; the
4
- // digest tool imports it to write byte-identical packetNNN.{system,user}.md
5
- // files. No second implementation, no drift.
6
- //
7
- // Format and omission rules are owned by {§packet-markdown}. Section producers
8
- // supply names and typed content; this projection preserves their ordered evidence.
1
+ import { TurnDisposition } from "@plurnk/plurnk-contracts";
9
2
  import { relative, sep } from "node:path";
10
3
  import { Problems, Validator } from "@plurnk/plurnk-contracts";
11
4
  import { TextCoordinates } from "@plurnk/plurnk-mimetypes";
@@ -13,35 +6,16 @@ import { renderTarget } from "./plurnk-uri.js";
13
6
  import LogBody from "./LogBody.js";
14
7
  import LogEntryProjection from "./LogEntryProjection.js";
15
8
  import LogVisibility from "./LogVisibility.js";
9
+ import BodyPreview from "../content/body-preview.js";
16
10
  import { assertEditReceipt, assertResourceEffects, LineAnchors, } from "../content/index.js";
17
- const editReceiptRevisionChars = () => {
18
- const raw = process.env.PLURNK_SERVICE_EDIT_RECEIPT_REVISION_CHARS;
19
- const value = Number(raw);
20
- if (!Number.isSafeInteger(value) || value < 1 || value > 64) {
21
- throw new Error(`PLURNK_SERVICE_EDIT_RECEIPT_REVISION_CHARS must be a safe integer from 1 through 64, got ${JSON.stringify(raw)}`);
22
- }
23
- return value;
24
- };
25
- const previewBounds = () => {
26
- const rawLines = process.env.PLURNK_SERVICE_PREVIEW_LINES;
27
- const rawChars = process.env.PLURNK_SERVICE_PREVIEW_CHARS;
28
- const lines = Number(rawLines);
29
- const chars = Number(rawChars);
30
- if (!Number.isSafeInteger(lines) || lines < 1) {
31
- throw new Error(`PLURNK_SERVICE_PREVIEW_LINES must be a positive safe integer, got ${JSON.stringify(rawLines)}`);
32
- }
33
- if (!Number.isSafeInteger(chars) || chars < 1) {
34
- throw new Error(`PLURNK_SERVICE_PREVIEW_CHARS must be a positive safe integer, got ${JSON.stringify(rawChars)}`);
35
- }
36
- return { lines, chars };
37
- };
38
11
  // {§packet-attachment-parts} — the attachment kinds and their readout weights live in one table.
39
12
  import { imageWeight, pdfWeight } from "./attachments.js";
13
+ import { isExecutionOp } from "@plurnk/plurnk-contracts";
40
14
  export { imageWeight, pdfWeight };
41
15
  export default class PacketWire {
42
16
  // {§packet-markdown} Render the sections in `slot` to one ChatMessage.content
43
17
  // string. Sections render in list order; empties are omitted (no empty headers on the wire);
44
- // each is `## {header}\n\n{content}` (or bare content when header is null),
18
+ // JSON follows its H2 directly; other content has one blank line (null header is bare),
45
19
  // trailing newlines stripped, joined with a blank line.
46
20
  static renderSlot(sections, slot) {
47
21
  return sections
@@ -50,15 +24,15 @@ export default class PacketWire {
50
24
  .filter((p) => p.length > 0)
51
25
  .join("\n\n");
52
26
  }
53
- // One section → its markdown block (`## {header}\n{content}`, or bare
54
- // content when header is null/empty), trailing newlines stripped. Empty
27
+ // One section → its markdown block, trailing newlines stripped. Empty
55
28
  // content renders to "" so renderSlot drops it. This is the unit the
56
29
  // per-section `weight` is measured over.
57
30
  static renderSection(s) {
58
31
  if (typeof s.content !== "string" || s.content.length === 0)
59
32
  return "";
60
33
  const header = typeof s.header === "string" && s.header.length > 0 ? s.header : null;
61
- return (header ? `## ${header}\n${s.content}` : s.content).replace(/\n+$/, "");
34
+ const separator = s.content.startsWith("{") || s.content.startsWith("[") ? "\n" : "\n\n";
35
+ return (header ? `## ${header}${separator}${s.content}` : s.content).replace(/\n+$/, "");
62
36
  }
63
37
  // Durable operation failures render as `{status, path}` JSON pointers to the log rows that
64
38
  // own their exact RFC 9457 results.
@@ -88,23 +62,27 @@ export default class PacketWire {
88
62
  return `* ${kind}${message.length > 0 ? `: ${message}` : ""}${position}`;
89
63
  }).join("\n");
90
64
  }
91
- // The Child Streams / Active Child Workers sections ({§child-orientation}) — the OPPOSITE of advice: terse
92
- // `{status, path}` JSON pointers (same shape as the errors section) to the live things the worker holds,
93
- // so the model SEES its active streams + unconcluded workers each turn and reasons for itself (READ /
94
- // KILL via the path). Orienting state, never an instruction. "" when none → section omitted.
95
- static renderChildPointers(rows) {
65
+ // The Delegation section ({§child-orientation}) — the OPPOSITE of advice: terse `{status, path}`
66
+ // JSON pointers (same shape as the errors section) to the live things the worker holds, under the
67
+ // word the teaching uses for handing work out: its unconcluded workers and its open streams. The
68
+ // model SEES them each turn and reasons for itself (READ / SEND / KILL via the path). Orienting
69
+ // state, never an instruction; both lists render every turn, `[]` when empty ({§packet-empty-sections}).
70
+ static renderDelegation(workers, streams) {
71
+ return `{"workers":${PacketWire.#pointers(workers)},\n"streams":${PacketWire.#pointers(streams)}}`;
72
+ }
73
+ static #pointers(rows) {
96
74
  const items = Array.isArray(rows) ? rows : [];
97
75
  const pointers = items.map((r) => JSON.stringify({
98
76
  status: r.status,
99
77
  path: r.path,
100
78
  ...(typeof r.detail === "string" && r.detail.length > 0 ? { detail: r.detail } : {}),
101
79
  }));
102
- return pointers.length === 0 ? "" : `[${pointers.join(",\n")}]`;
80
+ return pointers.length === 0 ? "[]" : `[${pointers.join(",\n")}]`;
103
81
  }
104
82
  // The git section content: the working-tree summary. "" when absent.
105
83
  static renderGit(git) {
106
84
  const status = git === null || git === undefined ? "" : PacketWire.#renderGitState(git);
107
- return status;
85
+ return status.length === 0 ? "" : `> [!NOTE]\n${status.split("\n").map((line) => `> ${line}`).join("\n")}`;
108
86
  }
109
87
  // The log section's content: the model's curated rows as Markdown-framed records ({§log-wire-format}).
110
88
  // Data only — no prose leads the records (the log carries rules for no one). Empty log → ""
@@ -117,12 +95,16 @@ export default class PacketWire {
117
95
  static renderLogWithAccounting(entries, weighContent, options = {}) {
118
96
  const log = Array.isArray(entries) ? entries : [];
119
97
  if (log.length === 0)
120
- return { content: "", reclaimableBodies: [], attachments: [] };
98
+ return { content: "", records: [], curationTargets: [], attachments: [], unadmittedOutput: [], newOverflow: false };
121
99
  const rows = PacketWire.#renderLogEntries(log, weighContent, options);
100
+ const records = rows.map(({ content }) => content);
122
101
  return {
123
- content: rows.map(({ content }) => content).join("\n\n"),
124
- reclaimableBodies: rows.flatMap(({ reclaimableBody }) => reclaimableBody === null ? [] : [reclaimableBody]),
102
+ content: records.join("\n\n"),
103
+ records,
104
+ curationTargets: rows.flatMap(({ curationTarget }) => curationTarget === null ? [] : [curationTarget]),
125
105
  attachments: rows.flatMap(({ attachment }) => attachment === null ? [] : [attachment]),
106
+ unadmittedOutput: rows.flatMap(({ unadmittedOutput }) => unadmittedOutput === null ? [] : [unadmittedOutput]),
107
+ newOverflow: rows.some(({ newOverflow }) => newOverflow),
126
108
  };
127
109
  }
128
110
  // Read one section's content by name off a packet (Engine's or re-parsed).
@@ -144,7 +126,7 @@ export default class PacketWire {
144
126
  }
145
127
  // Number a non-READ body line as `<N>:<line>` — `N:` followed by NO separator whitespace
146
128
  // ({§render-rule-line-navigable-prefix}): the leading digit prevents column-zero fence collisions and gives
147
- // the model line refs for free (`### READ0 (...) <42-46>`), while the absence of any separator means a
129
+ // the model line refs for free (`READ (...) <42-46>`), while the absence of any separator means a
148
130
  // reproduced line has nothing between `N:` and the content to copy — the hard-tab separator used
149
131
  // to leak into edit bodies and corrupt indentation. The content's OWN leading whitespace is
150
132
  // content, preserved verbatim. `N` is left-padded to the body's line-range width so every body
@@ -159,12 +141,15 @@ export default class PacketWire {
159
141
  const prefix = () => `${String(line++).padStart(width, " ")}:`;
160
142
  return `${prefix()}${body.replace(/(\r\n|\r(?!\n)|\n)(?=[\s\S])/g, (separator) => `${separator}${prefix()}`)}`;
161
143
  }
162
- static #numberSelectedLines(body, ordinals, startLine, lineAnchors, lineNumberWidth, numericLineNumberWidth) {
144
+ static #numberSelectedLines(body, ordinals, startLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, sourceLineNumbers) {
163
145
  const lines = TextCoordinates.logicalLines(body);
164
146
  if (lines.length !== ordinals.length) {
165
147
  throw new TypeError("A sparse log-body projection requires one source ordinal per rendered line.");
166
148
  }
167
- const displayed = ordinals.map((ordinal) => startLine + ordinal - 1);
149
+ if (sourceLineNumbers !== null && ordinals.some((ordinal) => ordinal < 1 || ordinal > sourceLineNumbers.length)) {
150
+ throw new TypeError("A sparse log-body projection's ordinals must address its source line numbers.");
151
+ }
152
+ const displayed = ordinals.map((ordinal) => sourceLineNumbers === null ? startLine + ordinal - 1 : sourceLineNumbers[ordinal - 1]);
168
153
  const width = lineAnchors === null
169
154
  ? numericLineNumberWidth > 0
170
155
  ? numericLineNumberWidth
@@ -192,14 +177,14 @@ export default class PacketWire {
192
177
  // Exact READ content receives source-width-aligned `@hash N:`; other textual bodies receive `N:`.
193
178
  // Matchers consume canonical content before this presentation projection.
194
179
  // Empty content produces no body.
195
- static #renderContentBody(content, startLine = 1, lineAnchors = null, lineNumberWidth = null, numericLineNumberWidth = 0, lineOrdinals = null) {
180
+ static #renderContentBody(content, startLine = 1, lineAnchors = null, lineNumberWidth = null, numericLineNumberWidth = 0, lineOrdinals = null, sourceLineNumbers = null) {
196
181
  if (content.length === 0)
197
182
  return "";
198
183
  // `startLine === null` means the producer already supplied numbered
199
184
  // content; re-numbering would duplicate its coordinates.
200
185
  const rendered = startLine !== null
201
186
  ? lineOrdinals !== null
202
- ? PacketWire.#numberSelectedLines(content, lineOrdinals, startLine, lineAnchors, lineNumberWidth, numericLineNumberWidth)
187
+ ? PacketWire.#numberSelectedLines(content, lineOrdinals, startLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, sourceLineNumbers)
203
188
  : lineAnchors === null
204
189
  ? PacketWire.#numberLines(content, startLine, numericLineNumberWidth)
205
190
  : LineAnchors.render(content, startLine, lineAnchors, lineNumberWidth ?? 0)
@@ -216,19 +201,23 @@ export default class PacketWire {
216
201
  return null;
217
202
  }
218
203
  }
219
- // Stable JSON metadata: keys are sorted so the same facts produce the same
220
- // line across turns — prefix-cache friendly. The preceding H3 owns identity.
204
+ // {§log-wire-format} Orientation precedes telemetry on every receipt.
221
205
  static #canonicalJson(obj) {
222
206
  const keys = Object.keys(obj).sort();
223
207
  const sorted = {};
208
+ for (const key of ["target", "aside"]) {
209
+ if (Object.hasOwn(obj, key))
210
+ sorted[key] = obj[key];
211
+ }
224
212
  for (const k of keys)
225
213
  sorted[k] = obj[k];
226
214
  return JSON.stringify(sorted);
227
215
  }
228
216
  static #receiptMeta(value) {
229
217
  const receipt = assertEditReceipt(value);
218
+ // The durable receipt keeps the full revision for forensics; the model gets no token it
219
+ // cannot use (operator, 2026-09-13: "ditch rev").
230
220
  const head = {
231
- rev: receipt.revision.slice(0, editReceiptRevisionChars()),
232
221
  extent: `${receipt.unit} ${receipt.before}->${receipt.after}`,
233
222
  ...(receipt.parseIssues === undefined
234
223
  ? {}
@@ -287,41 +276,14 @@ export default class PacketWire {
287
276
  throw new TypeError("A packet log row requires an addressable coordinate.");
288
277
  return `log:///${coordinate}/${leaf}`;
289
278
  }
290
- static #offsetAfterCharacters(text, count) {
291
- let offset = 0;
292
- let consumed = 0;
293
- while (offset < text.length && consumed < count) {
294
- if (text.startsWith("\r\n", offset)) {
295
- offset += 2;
296
- }
297
- else {
298
- const codePoint = text.codePointAt(offset);
299
- if (codePoint === undefined)
300
- break;
301
- offset += String.fromCodePoint(codePoint).length;
302
- }
303
- consumed++;
304
- }
305
- return offset;
306
- }
307
279
  // One preview function for every bounded model-facing projection. Lines
308
280
  // protect ordinary documents and Unicode characters protect a single-line
309
281
  // bomb. Once a physical line is complete, a character cut retreats to that
310
282
  // line boundary rather than exposing a partial coordinate prefix.
311
283
  static #preview(text) {
312
- const { lines: maxLines, chars: maxChars } = previewBounds();
313
284
  const coordinates = new TextCoordinates(text);
314
285
  const physicalLines = coordinates.logicalLines();
315
- const lineEnd = physicalLines.length > maxLines
316
- ? physicalLines[maxLines - 1].end
317
- : text.length;
318
- const characterEnd = PacketWire.#offsetAfterCharacters(text, maxChars);
319
- let end = Math.min(lineEnd, characterEnd);
320
- if (characterEnd < text.length && characterEnd <= lineEnd) {
321
- const completeLine = physicalLines.findLast((line) => line.separator.length > 0 && line.end <= characterEnd);
322
- if (completeLine !== undefined)
323
- end = completeLine.end;
324
- }
286
+ const { end } = BodyPreview.select(text);
325
287
  const cut = end < text.length;
326
288
  return {
327
289
  text: text.slice(0, end),
@@ -446,17 +408,22 @@ export default class PacketWire {
446
408
  };
447
409
  }
448
410
  static #visibleBody(entry, body) {
449
- const folded = LogVisibility.parse(entry.folded ?? LogVisibility.OPEN);
411
+ const trimmed = LogVisibility.parse(entry.folded ?? LogVisibility.OPEN);
412
+ const folded = LogVisibility.combine(LogVisibility.parse(entry.initial_folded ?? LogVisibility.OPEN), trimmed);
450
413
  const lines = TextCoordinates.logicalLines(body.content);
451
414
  const totalLines = lines.length;
452
415
  const clipped = LogVisibility.clipped(folded, totalLines);
453
416
  const ordinals = LogVisibility.visibleLineOrdinals(clipped, totalLines);
417
+ const readableOrdinals = LogVisibility.visibleLineOrdinals(trimmed, totalLines);
418
+ const select = (selected) => selected.map((ordinal) => {
419
+ const line = lines[ordinal - 1];
420
+ return body.content.slice(line.start, line.end);
421
+ }).join("");
454
422
  return {
455
- content: ordinals.map((ordinal) => {
456
- const line = lines[ordinal - 1];
457
- return body.content.slice(line.start, line.end);
458
- }).join(""),
423
+ content: select(ordinals),
459
424
  ordinals,
425
+ readableContent: select(readableOrdinals),
426
+ readableOrdinals,
460
427
  folded: clipped,
461
428
  totalLines,
462
429
  fullyFolded: LogVisibility.fullyFolded(clipped, totalLines),
@@ -518,315 +485,343 @@ export default class PacketWire {
518
485
  }));
519
486
  const promptProjectionWeights = PacketWire.#promptProjectionWeights(entries, visibleBodies, visibility, weighContent, options.promptProjectionWeight);
520
487
  return entries.map((e, index) => {
521
- const meta = {};
522
- const coordinate = typeof e.coordinate === "string" ? e.coordinate : null;
523
- const op = typeof e.op === "string" && e.op.length > 0 ? e.op : null;
524
- const renderedLeaf = LogEntryProjection.leaf(e);
525
- const path = PacketWire.#entryPath(coordinate, renderedLeaf);
526
- // Absence = "model" — the worker's own authorship is the default,
527
- // exactly as `source` absence means the owning worker (#338).
528
- if (typeof e.origin === "string" && e.origin !== "model")
529
- meta.origin = e.origin;
530
- // {§env-delta-attribution}: render the causal worker address or
531
- // subsystem token when present; absence means the owning worker.
532
- if (typeof e.source === "string" && e.source.length > 0)
533
- meta.source = e.source;
534
- if (e.source === "file" && e.attrs !== null && typeof e.attrs === "object" && "git" in e.attrs) {
535
- const git = e.attrs.git;
536
- if (typeof git !== "string" || git.length !== 2) {
537
- throw new TypeError("A source=file log row carries malformed Git XY metadata.");
538
- }
539
- meta.git = git;
540
- }
541
- // Absence = 200 on an ordinary row — the clients' quiet grammar
542
- // (plurnk#21) applied to the packet. SEND keeps its disposition,
543
- // KILL keeps decisive destructive completion, a dissolving log-KILL
544
- // receipt exists only to show its status ({§curation-receipt-dissolves}),
545
- // and every non-200 stays explicit (#338).
546
- if (typeof e.status === "number" && (op === "SEND" || op === "KILL" || e.status !== 200))
547
- meta.status = e.status;
548
- const tx = (typeof e.tx === "string" ? PacketWire.#safeParse(e.tx) : e.tx);
549
- if (typeof tx?.annotation === "string")
550
- meta.annotation = tx.annotation;
551
- const target = PacketWire.#renderActionTarget(e.target);
552
- // {§exec-stream}: a terminal stream observation's address is the stream it observed,
553
- // rendered under `stream` like the invocation's own link — never a `target`, which
554
- // the model would otherwise author into an EXEC slot (#425 F4).
555
- const terminalStream = op === "READ"
556
- && e.attrs !== null
557
- && typeof e.attrs === "object"
558
- && e.attrs.terminal === true;
559
- if (op === "COPY" || op === "MOVE") {
560
- const source = PacketWire.#renderSelection(tx?.source?.target, tx?.source?.lineMarker);
561
- const destination = PacketWire.#renderSelection(tx?.destination?.target, tx?.destination?.lineMarker);
562
- if (source !== null)
563
- meta.source = source;
564
- if (destination !== null)
565
- meta.destination = destination;
566
- if (typeof e.status === "number"
567
- && e.status < 400
568
- && (source === null || destination === null)) {
569
- throw new Error(`A successful ${op} log row must retain both operand selections.`);
570
- }
571
- }
572
- else if (target !== null) {
573
- meta[terminalStream ? "stream" : "target"] = target;
574
- }
575
- // EXEC's output is a separate stream entry ({§exec-stream}); its address rides in a
576
- // `stream` link, distinct from the runtime-owned invocation target.
577
- // {§exec-target-routing} {§fs-namespace} — the receipt names the working directory only
578
- // when it is not the project root, and then in the model's own project-relative form;
579
- // the root is the default and a host-absolute path never reaches the packet.
580
- if (op === "EXEC" && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.cwd === "string") {
581
- const cwd = PacketWire.#projectRelativeCwd(e.attrs.cwd, options.projectRoot ?? null);
582
- if (cwd !== null)
583
- meta.cwd = cwd;
584
- }
585
- if (op === "EXEC" && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.stream === "string") {
586
- meta.stream = e.attrs.stream;
587
- }
488
+ const identity = PacketWire.#rowIdentity(e, options);
588
489
  // Parse rx once — reused for the matcher/items enrichment and the body.
589
490
  const rx = (typeof e.rx === "string" ? PacketWire.#safeParse(e.rx) : e.rx);
590
- // {§exec-stream}: a terminal stream observation is self-sufficient
591
- // even when its selected channel is empty. Preserve exact producer
592
- // facts; do not manufacture a prose completion summary.
593
- if (terminalStream) {
594
- meta.terminal = true;
595
- if (rx !== null && typeof rx === "object" && Object.hasOwn(rx, "exitCode")) {
596
- if (typeof rx.exitCode !== "number" || !Number.isSafeInteger(rx.exitCode)) {
597
- throw new TypeError("A terminal stream result carries a malformed exitCode.");
598
- }
599
- meta.exitCode = rx.exitCode;
491
+ const facts = PacketWire.#rowResultFacts(identity, e, rx);
492
+ const projected = PacketWire.#rowBody(identity, e, bodies[index], visibility[index], facts, promptProjectionWeights.get(index), weighContent);
493
+ return PacketWire.#rowAccounting(identity, e, bodies[index], visibility[index], projected, weighContent, options);
494
+ });
495
+ }
496
+ // The row's identity and authored facts: who wrote it, what it addressed, and the statuses
497
+ // that stay explicit. `meta` is the metadata line under construction; each later stage adds
498
+ // to it, and {§log-wire-format}'s canonical JSON sorts the keys, so the order of stages never
499
+ // reaches the wire.
500
+ static #rowIdentity(e, options) {
501
+ const meta = {};
502
+ const coordinate = typeof e.coordinate === "string" ? e.coordinate : null;
503
+ const op = typeof e.op === "string" && e.op.length > 0 ? e.op : null;
504
+ const renderedLeaf = LogEntryProjection.leaf(e);
505
+ const path = PacketWire.#entryPath(coordinate, renderedLeaf);
506
+ // Absence = "model" — the worker's own authorship is the default,
507
+ // exactly as `source` absence means the owning worker (#338).
508
+ if (typeof e.origin === "string" && e.origin !== "model")
509
+ meta.origin = e.origin;
510
+ // {§env-delta-attribution}: render the causal worker address or
511
+ // subsystem token when present; absence means the owning worker.
512
+ if (typeof e.source === "string" && e.source.length > 0)
513
+ meta.source = e.source;
514
+ if (e.source === "file" && e.attrs !== null && typeof e.attrs === "object" && "git" in e.attrs) {
515
+ const git = e.attrs.git;
516
+ if (typeof git !== "string" || git.length !== 2) {
517
+ throw new TypeError("A source=file log row carries malformed Git XY metadata.");
518
+ }
519
+ meta.git = git;
520
+ }
521
+ // SEND, TASK, destructive KILL, and non-200 statuses stay explicit.
522
+ // Successful log-KILL rows never reach this projection
523
+ // ({§log-kill-meta-operation}).
524
+ if (typeof e.status === "number" && (op === "SEND" || op === "KILL" || typeof op === "string" && TurnDisposition.isOp(op) || e.status !== 200))
525
+ meta.status = e.status;
526
+ const tx = (typeof e.tx === "string" ? PacketWire.#safeParse(e.tx) : e.tx);
527
+ if (typeof tx?.aside === "string")
528
+ meta.aside = tx.aside;
529
+ const target = PacketWire.#renderActionTarget(e.target);
530
+ // {§exec-stream}: a terminal stream observation's address is the stream it observed,
531
+ // rendered under `stream` like the invocation's own link — never a `target`, which
532
+ // the model would otherwise author into an execution slot (#425 F4).
533
+ const terminalStream = op === "READ"
534
+ && e.attrs !== null
535
+ && typeof e.attrs === "object"
536
+ && e.attrs.terminal === true;
537
+ if (op === "COPY" || op === "MOVE") {
538
+ const source = PacketWire.#renderSelection(tx?.source?.target, tx?.source?.lineMarker);
539
+ const destination = PacketWire.#renderSelection(tx?.destination?.target, tx?.destination?.lineMarker);
540
+ if (source !== null)
541
+ meta.source = source;
542
+ if (destination !== null)
543
+ meta.destination = destination;
544
+ if (typeof e.status === "number"
545
+ && e.status < 400
546
+ && (source === null || destination === null)) {
547
+ throw new Error(`A successful ${op} log row must retain both operand selections.`);
548
+ }
549
+ }
550
+ else if (target !== null) {
551
+ meta[terminalStream ? "stream" : "target"] = target;
552
+ }
553
+ // {§worker-auto-name} The created identity is an outcome, not an authored target.
554
+ if ((op === "WORK" || op === "FORK") && e.attrs !== null && typeof e.attrs === "object"
555
+ && typeof e.attrs.worker === "string") {
556
+ meta.worker = e.attrs.worker;
557
+ }
558
+ // An execution's output is a separate stream entry ({§exec-stream}); its address rides in a
559
+ // `stream` link, distinct from the runtime-owned invocation target.
560
+ // {§exec-target-routing} {§fs-namespace} — the receipt names the working directory only
561
+ // when it is not the project root, and then in the model's own project-relative form;
562
+ // the root is the default and a host-absolute path never reaches the packet.
563
+ if (isExecutionOp(op) && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.cwd === "string") {
564
+ const cwd = PacketWire.#projectRelativeCwd(e.attrs.cwd, options.projectRoot ?? null);
565
+ if (cwd !== null)
566
+ meta.cwd = cwd;
567
+ }
568
+ if (isExecutionOp(op) && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.stream === "string") {
569
+ meta.stream = e.attrs.stream;
570
+ }
571
+ return { meta, op, tx, coordinate, path, renderedLeaf, target, terminalStream };
572
+ }
573
+ // The row's result facts from its rx: the terminal stream's exit, the Problem or detail, the
574
+ // matcher, the retrieval extents, and the structured mutation receipts. Returns what the body
575
+ // projection needs to know about the result.
576
+ static #rowResultFacts(identity, e, rx) {
577
+ const { meta, op, tx, terminalStream } = identity;
578
+ // {§exec-stream}: a terminal stream observation is self-sufficient
579
+ // even when its selected channel is empty. Preserve exact producer
580
+ // facts; do not manufacture a prose completion summary.
581
+ if (terminalStream) {
582
+ meta.terminal = true;
583
+ if (rx !== null && typeof rx === "object" && Object.hasOwn(rx, "exitCode")) {
584
+ if (typeof rx.exitCode !== "number" || !Number.isSafeInteger(rx.exitCode)) {
585
+ throw new TypeError("A terminal stream result carries a malformed exitCode.");
600
586
  }
587
+ meta.exitCode = rx.exitCode;
588
+ }
589
+ }
590
+ // {§problem-projection} — the exact durable Problem remains the
591
+ // failure authority; the packet carries only facts not already
592
+ // owned by its enclosing row. Errors remains only an index.
593
+ if (typeof e.status === "number" && e.status >= 400 && rx !== null && typeof rx === "object") {
594
+ const problem = rx.problem;
595
+ Validator.assertProblemDetails(problem);
596
+ meta.problem = Problems.project(problem, {
597
+ status: e.status,
598
+ row: meta,
599
+ });
600
+ }
601
+ // The success-side sibling (#342): a sub-problem receipt may carry one
602
+ // terse `detail` (e.g. the EDIT 304) so situational teaching is paid
603
+ // only when the situation occurs, never in the hot path.
604
+ if (!Object.hasOwn(meta, "problem") && rx !== null && typeof rx === "object"
605
+ && typeof rx.detail === "string"
606
+ && rx.detail.length > 0) {
607
+ meta.detail = rx.detail;
608
+ }
609
+ // {§retrieval-packet-metadata}: one extent/coordinate owner plus
610
+ // only FIND aggregates that add information beyond that extent.
611
+ let findItems = null;
612
+ const patterned = tx !== null && tx !== undefined && typeof tx === "object" && tx.matcher !== null && typeof tx.matcher === "object" && typeof tx.matcher.raw === "string";
613
+ if (patterned) {
614
+ meta.matcher = tx.matcher.raw;
615
+ if (op !== "FIND" && rx !== null && typeof rx === "object" && typeof rx.matched === "number")
616
+ meta.matched = rx.matched;
617
+ }
618
+ // {§channel-selection-visibility} — a READ names the resource's other channels with their
619
+ // tokens, so the row itself shows the choice a FIND listing would.
620
+ if (op === "READ" && rx !== null && typeof rx === "object" && rx.channels !== null && typeof rx.channels === "object") {
621
+ meta.channels = rx.channels;
622
+ }
623
+ // {§send-response-receipt} — a reply's row names the prompts it answered.
624
+ if (op === "SEND" && rx !== null && typeof rx === "object" && Array.isArray(rx.recipients)) {
625
+ meta.recipients = rx.recipients;
626
+ }
627
+ if (op === "READ" || op === "FIND") {
628
+ if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.content === "string") {
629
+ const parsed = PacketWire.#safeParse(rx.content);
630
+ if (Array.isArray(parsed))
631
+ findItems = parsed.length;
601
632
  }
602
- // {§problem-projection} — the exact durable Problem remains the
603
- // failure authority; the packet carries only facts not already
604
- // owned by its enclosing row. Errors remains only an index.
605
- if (typeof e.status === "number" && e.status >= 400 && rx !== null && typeof rx === "object") {
606
- const problem = rx.problem;
607
- Validator.assertProblemDetails(problem);
608
- meta.problem = Problems.project(problem, {
609
- status: e.status,
610
- row: meta,
611
- });
633
+ const range = rx !== null && typeof rx === "object" && rx.range !== undefined
634
+ ? rx.range
635
+ : undefined;
636
+ const problemOwnsRange = typeof e.status === "number"
637
+ && e.status >= 400
638
+ && meta.problem !== null
639
+ && typeof meta.problem === "object"
640
+ && Object.hasOwn(meta.problem, "range");
641
+ if (problemOwnsRange) {
642
+ Validator.assertRangeExtent(meta.problem.range);
612
643
  }
613
- // The success-side sibling (#342): a sub-problem receipt may carry one
614
- // terse `detail` (e.g. the EDIT 304) so situational teaching is paid
615
- // only when the situation occurs, never in the hot path.
616
- if (!Object.hasOwn(meta, "problem") && rx !== null && typeof rx === "object"
617
- && typeof rx.detail === "string"
618
- && rx.detail.length > 0) {
619
- meta.detail = rx.detail;
644
+ if (range !== undefined && !problemOwnsRange) {
645
+ meta.range = Validator.assertRangeExtent(range);
620
646
  }
621
- // {§retrieval-packet-metadata}: one extent/coordinate owner plus
622
- // only FIND aggregates that add information beyond that extent.
623
- let findItems = null;
624
- if (op === "READ" || op === "FIND") {
625
- const findMatcher = op === "FIND"
626
- && tx !== null
627
- && tx !== undefined
628
- && typeof tx === "object"
629
- && tx.body !== null
630
- && typeof tx.body === "object";
631
- if (findMatcher) {
632
- const body = tx?.body;
633
- if (body !== null && typeof body === "object" && typeof body.raw === "string") {
634
- meta.matcher = body.raw;
635
- }
636
- }
637
- if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.content === "string") {
638
- const parsed = PacketWire.#safeParse(rx.content);
639
- if (Array.isArray(parsed))
640
- findItems = parsed.length;
641
- }
642
- const range = rx !== null && typeof rx === "object" && rx.range !== undefined
643
- ? rx.range
644
- : undefined;
645
- const problemOwnsRange = typeof e.status === "number"
646
- && e.status >= 400
647
- && meta.problem !== null
648
- && typeof meta.problem === "object"
649
- && Object.hasOwn(meta.problem, "range");
650
- if (problemOwnsRange) {
651
- Validator.assertRangeExtent(meta.problem.range);
652
- }
653
- if (range !== undefined && !problemOwnsRange) {
654
- meta.range = Validator.assertRangeExtent(range);
655
- }
656
- else if (op === "READ" && rx !== null && typeof rx === "object" && rx.region !== undefined) {
657
- meta.region = Validator.assertTextRegion(rx.region);
658
- }
659
- // These are underlying selected-content weights, distinct from
660
- // the emitted body's generic `tokens` measurement.
661
- if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.itemsWeightTotal === "number" && rx.itemsWeightTotal > 0) {
662
- meta.itemsTokenTotal = rx.itemsWeightTotal;
663
- }
664
- if (op === "FIND"
665
- && rx !== null
666
- && typeof rx === "object"
667
- && typeof rx.returnedItemsWeightTotal === "number"
668
- && rx.returnedItemsWeightTotal > 0
669
- && rx.returnedItemsWeightTotal !== rx.itemsWeightTotal) {
670
- meta.returnedItemsTokenTotal = rx.returnedItemsWeightTotal;
671
- }
672
- if (findMatcher
673
- && range !== null
674
- && typeof range === "object"
675
- && range.unit === "resource"
676
- && rx !== null
677
- && typeof rx === "object"
678
- && typeof rx.matchLocationCount === "number"
679
- && rx.matchLocationCount > 0) {
680
- meta.matchLocationCount = rx.matchLocationCount;
681
- }
647
+ else if (op === "READ" && rx !== null && typeof rx === "object" && rx.region !== undefined) {
648
+ meta.region = Validator.assertTextRegion(rx.region);
682
649
  }
683
- // {§edit-result-receipt-projection} {§edit-result-copy-move-effects}
684
- // Mutations expose compact, validated outcome metadata. EDIT owns
685
- // one receipt; COPY/MOVE own ordered resource effects whose
686
- // optional receipts describe scoped textual materializations.
687
- let structuredMutationReceipt = false;
688
- if (op === "EDIT" && rx !== null && typeof rx === "object" && Object.hasOwn(rx, "receipt")) {
689
- Object.assign(meta, PacketWire.#receiptMeta(rx.receipt));
690
- structuredMutationReceipt = true;
650
+ // These are underlying selected-content weights, distinct from
651
+ // the emitted body's generic `tokens` measurement.
652
+ if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.itemsWeightTotal === "number" && rx.itemsWeightTotal > 0) {
653
+ meta.itemsTokenTotal = rx.itemsWeightTotal;
691
654
  }
692
- if ((op === "COPY" || op === "MOVE")
655
+ if (op === "FIND"
693
656
  && rx !== null
694
657
  && typeof rx === "object"
695
- && Object.hasOwn(rx, "effects")) {
696
- const effects = assertResourceEffects(rx.effects);
697
- meta.effects = effects.map((effect) => ({
698
- target: effect.target,
699
- action: effect.action,
700
- ...(effect.receipt === undefined
701
- ? {}
702
- : PacketWire.#receiptMeta(effect.receipt)),
703
- }));
704
- structuredMutationReceipt = effects.some((effect) => effect.receipt !== undefined);
705
- }
706
- // The canonical full body is shared with log READ, log FIND,
707
- // and search derivation. READ/FIND own selection bounds, PLAN is
708
- // persistent working memory, and prompt rows share their packet
709
- // allowance. Structured mutation receipts own their join bound;
710
- // every remaining body uses the ordinary fixed preview.
711
- const fullBody = bodies[index];
712
- const bodyVisibility = visibility[index];
713
- const projectedBody = bodyVisibility.fullyFolded
714
- ? fullBody
715
- : { ...fullBody, content: bodyVisibility.content };
716
- const emptyFind = op === "FIND" && e.status === 200 && findItems === 0;
717
- const previewExempt = op === "READ"
718
- || op === "FIND"
719
- || op === "PLAN"
720
- || structuredMutationReceipt;
721
- const lineAnchors = op === "READ" ? e.lineAnchors ?? null : null;
722
- const lineNumberWidth = op === "READ" ? e.lineNumberWidth ?? null : null;
723
- if (lineAnchors !== null) {
724
- LineAnchors.assertProjection(fullBody.content, lineAnchors);
725
- }
726
- const findRange = op === "FIND" && meta.range !== null && typeof meta.range === "object"
727
- ? meta.range
728
- : null;
729
- const bodyStartLine = findRange?.returned?.[0] ?? fullBody.startLine;
730
- const numericLineNumberWidth = findRange === null
731
- ? bodyStartLine === null || bodyVisibility.totalLines === 0
732
- ? 0
733
- : String(bodyStartLine + bodyVisibility.totalLines - 1).length
734
- : String(findRange.total).length;
735
- const allOrdinals = Array.from({ length: bodyVisibility.totalLines }, (_, ordinal) => ordinal + 1);
736
- const sourceOrdinals = bodyVisibility.fullyFolded
737
- ? allOrdinals
738
- : bodyVisibility.ordinals;
739
- const promptProjectionWeight = promptProjectionWeights.get(index);
740
- const projection = promptProjectionWeight !== undefined
741
- ? PacketWire.#promptProjection(projectedBody, promptProjectionWeight, weighContent, (content) => PacketWire.#renderContentBody(content, bodyStartLine, null, null, numericLineNumberWidth, bodyStartLine === null
742
- ? null
743
- : sourceOrdinals.slice(0, TextCoordinates.logicalLines(content).length)))
744
- : previewExempt
745
- ? { text: projectedBody.content, cut: false, chunk: null }
746
- : PacketWire.#preview(projectedBody.content);
747
- const projectedLineCount = TextCoordinates.logicalLines(projection.text).length;
748
- const projectedOrdinals = sourceOrdinals.slice(0, projectedLineCount);
749
- const body = emptyFind || projection.text.length === 0
750
- ? ""
751
- : PacketWire.#renderContentBody(projection.text, bodyStartLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, bodyStartLine === null ? null : projectedOrdinals);
752
- // {§packet-token-accounting} — tokensBody reports the projected body's weight even
753
- // when that body is withheld. Active accounting happens only after every field and
754
- // the final row framing are known below.
755
- const renderedBodyWeight = body.length > 0 ? weighContent(body) : 0;
756
- // Never tokensBody:0 — a zero-weight visible body is field absence, and
757
- // tokensBody presence is what marks the folded state (#338).
758
- if (fullBody.content.length > 0 && renderedBodyWeight > 0)
759
- meta.tokensBody = renderedBodyWeight;
760
- // lines beside tokens on a non-retrieval row with a navigable body — the count of
761
- // `N:`-numbered lines (fences and unnumbered prose don't count), so the model can plan
762
- // a <start,end> slice before paying for a READ. READ/FIND own typed extents instead.
763
- if (fullBody.content.length > 0 && op !== "READ" && op !== "FIND") {
764
- meta.lines = bodyVisibility.totalLines;
658
+ && typeof rx.returnedItemsWeightTotal === "number"
659
+ && rx.returnedItemsWeightTotal > 0
660
+ && rx.returnedItemsWeightTotal !== rx.itemsWeightTotal) {
661
+ meta.returnedItemsTokenTotal = rx.returnedItemsWeightTotal;
765
662
  }
766
- if (bodyVisibility.folded.length > 0 && !bodyVisibility.fullyFolded) {
767
- meta.folded = LogVisibility.format(bodyVisibility.folded);
663
+ if (op === "FIND"
664
+ && patterned
665
+ && range !== null
666
+ && typeof range === "object"
667
+ && range.unit === "resource"
668
+ && rx !== null
669
+ && typeof rx === "object"
670
+ && typeof rx.matchLocationCount === "number"
671
+ && rx.matchLocationCount > 0) {
672
+ meta.matchLocationCount = rx.matchLocationCount;
768
673
  }
769
- // {§log-wire-format} — the three body states stay self-describing:
770
- // coordinate lines ⇒ visible, `tokensBody` without lines ⇒ suppressed,
771
- // neither ⇒ no canonical body.
772
- const display = fullBody.content.length === 0
773
- ? "none"
774
- : bodyVisibility.fullyFolded
775
- ? "folded"
776
- : body.length === 0
777
- ? "none"
778
- : "open";
779
- const projectedChunk = projection.chunk !== null
780
- && bodyVisibility.folded.length > 0
781
- && !bodyVisibility.fullyFolded
782
- ? PacketWire.#sparseChunk(fullBody.content, projectedBody.content, sourceOrdinals, projection.text)
783
- : projection.chunk;
784
- if (display === "open" && projectedChunk !== null)
785
- meta.chunk = projectedChunk;
786
- const renderRow = () => {
787
- const metadata = PacketWire.#canonicalJson(meta);
788
- return display === "open"
789
- ? `### ${path}\n${metadata}\n${body}`
790
- : `### ${path}\n${metadata}`;
791
- };
792
- // The accounting field participates in the row it measures. Iterate
793
- // until its decimal width and therefore the rendered row's curation
794
- // weight are stable. The metadata share is derivable (tokensActive −
795
- // tokensBody when open; tokensActive otherwise) and feeds no
796
- // curation decision, so it is not serialized (#338).
797
- // {§packet-attachment-parts} — only an undelivered READ supported by this request's
798
- // route contributes native content and its weight.
799
- const candidate = display === "open"
800
- && op === "READ"
801
- && (e.native_delivered_at === null || e.native_delivered_at === undefined)
802
- ? PacketWire.#attachmentOf(e.rx, e.target, coordinate, target)
803
- : null;
804
- const attachment = candidate !== null
805
- && (options.acceptedAttachmentKinds?.has(candidate.kind) ?? true)
806
- ? candidate
807
- : null;
808
- if (attachment !== null)
809
- meta.tokensAttachment = attachment.weight;
810
- meta.tokensActive = 0;
811
- for (let pass = 0; pass < 8; pass += 1) {
812
- const tokensActive = weighContent(renderRow()) + (attachment?.weight ?? 0);
813
- if (meta.tokensActive === tokensActive) {
814
- const tokensBody = typeof meta.tokensBody === "number" ? meta.tokensBody : 0;
815
- return {
816
- content: renderRow(),
817
- reclaimableBody: display === "open" && tokensBody > 0
818
- ? { path, tokensBody, tokensActive }
819
- : null,
820
- attachment,
821
- };
822
- }
823
- meta.tokensActive = tokensActive;
674
+ }
675
+ // {§edit-result-receipt-projection} {§edit-result-copy-move-effects}
676
+ // EDIT/scoped entry KILL own one receipt; COPY/MOVE own resource effects whose
677
+ // optional receipts describe scoped textual materializations.
678
+ let structuredMutationReceipt = false;
679
+ if ((op === "EDIT" || op === "KILL") && rx !== null && typeof rx === "object" && Object.hasOwn(rx, "receipt")) {
680
+ Object.assign(meta, PacketWire.#receiptMeta(rx.receipt));
681
+ structuredMutationReceipt = true;
682
+ }
683
+ if ((op === "COPY" || op === "MOVE")
684
+ && rx !== null
685
+ && typeof rx === "object"
686
+ && Object.hasOwn(rx, "effects")) {
687
+ const effects = assertResourceEffects(rx.effects);
688
+ meta.effects = effects.map((effect) => ({
689
+ target: effect.target,
690
+ action: effect.action,
691
+ ...(effect.receipt === undefined
692
+ ? {}
693
+ : PacketWire.#receiptMeta(effect.receipt)),
694
+ }));
695
+ structuredMutationReceipt = effects.some((effect) => effect.receipt !== undefined);
696
+ }
697
+ return { findItems, structuredMutationReceipt };
698
+ }
699
+ // The body the row shows: the canonical full body is shared with log READ, log FIND, and
700
+ // search derivation. READ/FIND own selection bounds, TASK and admitted programs remain
701
+ // complete, and prompt rows share their packet allowance. Structured mutation receipts own
702
+ // their join bound; every remaining body uses the ordinary fixed preview.
703
+ static #rowBody(identity, e, fullBody, bodyVisibility, facts, promptProjectionWeight, weighContent) {
704
+ const { meta, op, renderedLeaf } = identity;
705
+ const projectedBody = {
706
+ ...fullBody,
707
+ content: bodyVisibility.fullyFolded ? bodyVisibility.readableContent : bodyVisibility.content,
708
+ };
709
+ const emptyFind = op === "FIND" && e.status === 200 && facts.findItems === 0;
710
+ const previewExempt = op === "READ"
711
+ || op === "FIND"
712
+ || op === "TASK"
713
+ || (op === null && renderedLeaf === "ops")
714
+ || facts.structuredMutationReceipt;
715
+ const lineAnchors = op === "READ" ? e.lineAnchors ?? null : null;
716
+ const lineNumberWidth = op === "READ" ? e.lineNumberWidth ?? null : null;
717
+ if (lineAnchors !== null) {
718
+ LineAnchors.assertProjection(fullBody.content, lineAnchors);
719
+ }
720
+ const findRange = op === "FIND" && meta.range !== null && typeof meta.range === "object"
721
+ ? meta.range
722
+ : null;
723
+ const bodyStartLine = findRange?.returned?.[0] ?? fullBody.startLine;
724
+ const numericLineNumberWidth = findRange === null
725
+ ? bodyStartLine === null || bodyVisibility.totalLines === 0
726
+ ? 0
727
+ : String(fullBody.lineOrdinals?.at(-1) ?? bodyStartLine + bodyVisibility.totalLines - 1).length
728
+ : String(findRange.total).length;
729
+ const sourceOrdinals = bodyVisibility.fullyFolded
730
+ ? bodyVisibility.readableOrdinals
731
+ : bodyVisibility.ordinals;
732
+ const projection = promptProjectionWeight !== undefined
733
+ ? PacketWire.#promptProjection(projectedBody, promptProjectionWeight, weighContent, (content) => PacketWire.#renderContentBody(content, bodyStartLine, null, null, numericLineNumberWidth, bodyStartLine === null
734
+ ? null
735
+ : sourceOrdinals.slice(0, TextCoordinates.logicalLines(content).length)))
736
+ : previewExempt
737
+ ? { text: projectedBody.content, cut: false, chunk: null }
738
+ : PacketWire.#preview(projectedBody.content);
739
+ const projectedLineCount = TextCoordinates.logicalLines(projection.text).length;
740
+ const projectedOrdinals = sourceOrdinals.slice(0, projectedLineCount);
741
+ const body = emptyFind || projection.text.length === 0
742
+ ? ""
743
+ : PacketWire.#renderContentBody(projection.text, bodyStartLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, bodyStartLine === null ? null : projectedOrdinals, fullBody.lineOrdinals ?? null);
744
+ // lines beside tokens on a non-retrieval row with a navigable body — the count of
745
+ // `N:`-numbered lines (fences and unnumbered prose don't count), so the model can plan
746
+ // a <start,end> slice before paying for a READ. READ/FIND own typed extents instead.
747
+ if (fullBody.content.length > 0 && op !== "READ" && op !== "FIND") {
748
+ meta.lines = bodyVisibility.totalLines;
749
+ }
750
+ if (bodyVisibility.folded.length > 0 && !bodyVisibility.fullyFolded) {
751
+ meta.folded = LogVisibility.format(bodyVisibility.folded);
752
+ }
753
+ const display = bodyVisibility.readableContent.length === 0
754
+ ? "none"
755
+ : bodyVisibility.fullyFolded || e.output_withheld === true
756
+ ? "folded"
757
+ : body.length === 0
758
+ ? "none"
759
+ : "open";
760
+ const projectedChunk = projection.chunk !== null
761
+ && bodyVisibility.folded.length > 0
762
+ && !bodyVisibility.fullyFolded
763
+ ? PacketWire.#sparseChunk(fullBody.content, projectedBody.content, sourceOrdinals, projection.text)
764
+ : projection.chunk;
765
+ if (display === "open" && projectedChunk !== null)
766
+ meta.chunk = projectedChunk;
767
+ return { body, projectedLineCount, display };
768
+ }
769
+ // The row's native attachment, its withholding receipt, and the accounting field that
770
+ // participates in the row it measures: iterate until its decimal width and therefore the
771
+ // rendered row's curation weight are stable. {§packet-token-accounting}
772
+ static #rowAccounting(identity, e, fullBody, bodyVisibility, projected, weighContent, options) {
773
+ const { meta, op, coordinate, path, target } = identity;
774
+ const { body, projectedLineCount, display } = projected;
775
+ const nativeCandidate = op === "READ" && typeof e.status === "number" && e.status >= 200 && e.status < 300
776
+ ? PacketWire.#attachmentOf(e.rx, e.target, coordinate, target) : null;
777
+ const native = nativeCandidate !== null && (options.acceptedAttachmentKinds?.has(nativeCandidate.kind) ?? true)
778
+ ? nativeCandidate : null;
779
+ const outputWithheld = e.output_withheld === true
780
+ && ((!bodyVisibility.fullyFolded && body.length > 0) || native !== null);
781
+ if (outputWithheld) {
782
+ const omitted = body.length > 0
783
+ ? `${projectedLineCount} output lines${native === null ? "" : " and native content"}`
784
+ : "native content";
785
+ meta.overflow = `${omitted} not shown; the log exceeded logTokensMax when this row was withheld`;
786
+ }
787
+ const renderRow = () => {
788
+ const metadata = PacketWire.#canonicalJson(meta);
789
+ return display === "open"
790
+ ? `### ${path}\n${metadata}\n${body}`
791
+ : `### ${path}\n${metadata}`;
792
+ };
793
+ // {§packet-attachment-parts}: retained native content shares the row's curation lifetime.
794
+ const attachment = e.output_withheld !== true
795
+ && !(bodyVisibility.totalLines > 0 && bodyVisibility.fullyFolded)
796
+ ? native
797
+ : null;
798
+ if (attachment !== null)
799
+ meta.tokensAttachment = attachment.weight;
800
+ meta.logTokens = 0;
801
+ for (let pass = 0; pass < 8; pass += 1) {
802
+ const logTokens = weighContent(renderRow()) + (attachment?.weight ?? 0);
803
+ if (meta.logTokens === logTokens) {
804
+ return {
805
+ content: renderRow(),
806
+ curationTarget: { path, logTokens },
807
+ attachment,
808
+ unadmittedOutput: (display === "open" || attachment !== null)
809
+ && fullBody.provenance === "returned"
810
+ && e.output_admission_turn_id == null
811
+ && typeof e.id === "number"
812
+ ? e.id : null,
813
+ newOverflow: outputWithheld && e.newOverflow === true,
814
+ };
824
815
  }
825
- throw new Error("packet log row accounting did not converge");
826
- });
816
+ meta.logTokens = logTokens;
817
+ }
818
+ throw new Error("packet log row accounting did not converge");
827
819
  }
828
820
  static #attachmentOf(rx, target, coordinate, path) {
829
821
  const view = rx;
822
+ const contentHash = rx?.nativeContentHash;
823
+ if (typeof contentHash !== "string")
824
+ return null;
830
825
  const pathname = typeof target?.pathname === "string" && target.pathname.length > 0
831
826
  ? target.pathname
832
827
  : typeof target?.raw === "string" ? target.raw : null;
@@ -837,17 +832,21 @@ export default class PacketWire {
837
832
  if (image !== undefined && typeof image.mimetype === "string" && Number.isSafeInteger(image.width) && Number.isSafeInteger(image.height)) {
838
833
  const width = image.width;
839
834
  const height = image.height;
840
- return { coordinate, path, scheme, pathname, mimetype: image.mimetype, kind: "image", width, height, weight: imageWeight(width, height) };
835
+ return { contentHash, coordinate, path, scheme, pathname, mimetype: image.mimetype, kind: "image", width, height, weight: imageWeight(width, height) };
841
836
  }
842
837
  const document = view?.document;
843
- if (document !== undefined && typeof document.mimetype === "string" && Number.isSafeInteger(document.pages)) {
844
- const pages = document.pages;
845
- return { coordinate, path, scheme, pathname, mimetype: document.mimetype, kind: "pdf", pages, weight: pdfWeight(pages) };
838
+ if (document !== undefined && typeof document.mimetype === "string" && Number.isSafeInteger(document.bytes)) {
839
+ const pages = Number.isSafeInteger(document.pages) ? document.pages : null;
840
+ return {
841
+ contentHash, coordinate, path, scheme, pathname, mimetype: document.mimetype, kind: "pdf",
842
+ ...(pages === null ? {} : { pages }),
843
+ weight: pdfWeight(pages, document.bytes),
844
+ };
846
845
  }
847
846
  return null;
848
847
  }
849
848
  // {§packet-attachment-parts} — the wire form with native parts: user text first, then each accepted
850
- // file immediately followed by its reactive ejection sentence.
849
+ // retained native part in observation order.
851
850
  static async wireMessages(packet, bytesOf, accepts = () => true) {
852
851
  const [system, user] = PacketWire.packetToWireMessages(packet);
853
852
  const parts = [{ type: "text", text: user.content }];
@@ -855,13 +854,7 @@ export default class PacketWire {
855
854
  if (!accepts(attachment.kind))
856
855
  continue;
857
856
  const bytes = await bytesOf(attachment);
858
- if (bytes === null)
859
- continue;
860
857
  parts.push({ type: "file", data: bytes, mediaType: attachment.mimetype });
861
- parts.push({
862
- type: "text",
863
- text: `${attachment.path} has been ejected from context. It must be READ again to retain it in context.`,
864
- });
865
858
  }
866
859
  return parts.length === 1 ? [system, user] : [system, { role: "user", content: parts }];
867
860
  }