@plurnk/plurnk-service 1.17.0 → 1.19.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 (501) hide show
  1. package/.env.defaults +95 -14
  2. package/README.md +5 -3
  3. package/SPEC.md +1756 -1442
  4. package/dist/Paths.js +3 -3
  5. package/dist/build-info.json +1 -1
  6. package/dist/content/body-preview.d.ts +1 -0
  7. package/dist/content/body-preview.d.ts.map +1 -1
  8. package/dist/content/body-preview.js +8 -10
  9. package/dist/content/body-preview.js.map +1 -1
  10. package/dist/content/edit-receipt.d.ts.map +1 -1
  11. package/dist/content/edit-receipt.js +30 -29
  12. package/dist/content/edit-receipt.js.map +1 -1
  13. package/dist/content/line-anchors.d.ts.map +1 -1
  14. package/dist/content/line-anchors.js +17 -5
  15. package/dist/content/line-anchors.js.map +1 -1
  16. package/dist/content/read-projector.d.ts +2 -2
  17. package/dist/content/read-projector.d.ts.map +1 -1
  18. package/dist/content/read-projector.js +81 -39
  19. package/dist/content/read-projector.js.map +1 -1
  20. package/dist/content/read-resolve.d.ts +1 -0
  21. package/dist/content/read-resolve.d.ts.map +1 -1
  22. package/dist/content/read-resolve.js +13 -10
  23. package/dist/content/read-resolve.js.map +1 -1
  24. package/dist/content/scope-format.d.ts +9 -0
  25. package/dist/content/scope-format.d.ts.map +1 -0
  26. package/dist/content/scope-format.js +28 -0
  27. package/dist/content/scope-format.js.map +1 -0
  28. package/dist/core/AdministrativeLoop.d.ts +8 -0
  29. package/dist/core/AdministrativeLoop.d.ts.map +1 -0
  30. package/dist/core/AdministrativeLoop.js +16 -0
  31. package/dist/core/AdministrativeLoop.js.map +1 -0
  32. package/dist/core/AdmittedTurnExecutor.d.ts +2 -2
  33. package/dist/core/AdmittedTurnExecutor.d.ts.map +1 -1
  34. package/dist/core/AdmittedTurnExecutor.js +26 -26
  35. package/dist/core/AdmittedTurnExecutor.js.map +1 -1
  36. package/dist/core/BareBatchRunner.d.ts +1 -2
  37. package/dist/core/BareBatchRunner.d.ts.map +1 -1
  38. package/dist/core/BareBatchRunner.js +7 -12
  39. package/dist/core/BareBatchRunner.js.map +1 -1
  40. package/dist/core/BudgetReadout.d.ts.map +1 -1
  41. package/dist/core/BudgetReadout.js +3 -4
  42. package/dist/core/BudgetReadout.js.map +1 -1
  43. package/dist/core/CapabilityPolicies.d.ts +4 -2
  44. package/dist/core/CapabilityPolicies.d.ts.map +1 -1
  45. package/dist/core/CapabilityPolicies.js +23 -2
  46. package/dist/core/CapabilityPolicies.js.map +1 -1
  47. package/dist/core/CapabilityResolver.d.ts +2 -2
  48. package/dist/core/CapabilityResolver.d.ts.map +1 -1
  49. package/dist/core/CapabilityResolver.js +46 -36
  50. package/dist/core/CapabilityResolver.js.map +1 -1
  51. package/dist/core/ChannelWrite.d.ts +4 -6
  52. package/dist/core/ChannelWrite.d.ts.map +1 -1
  53. package/dist/core/ChannelWrite.js +8 -8
  54. package/dist/core/ChannelWrite.js.map +1 -1
  55. package/dist/core/ChannelWrite.sql +17 -11
  56. package/dist/core/ClientInteractions.d.ts +11 -1
  57. package/dist/core/ClientInteractions.d.ts.map +1 -1
  58. package/dist/core/ClientInteractions.js +26 -2
  59. package/dist/core/ClientInteractions.js.map +1 -1
  60. package/dist/core/CoreSchemeServices.d.ts.map +1 -1
  61. package/dist/core/CoreSchemeServices.js +1 -0
  62. package/dist/core/CoreSchemeServices.js.map +1 -1
  63. package/dist/core/DataStatementRunner.d.ts.map +1 -1
  64. package/dist/core/DataStatementRunner.js +198 -148
  65. package/dist/core/DataStatementRunner.js.map +1 -1
  66. package/dist/core/Dispatcher.d.ts +18 -5
  67. package/dist/core/Dispatcher.d.ts.map +1 -1
  68. package/dist/core/Dispatcher.js +135 -114
  69. package/dist/core/Dispatcher.js.map +1 -1
  70. package/dist/core/Dispatcher.sql +11 -26
  71. package/dist/core/DurableStatement.d.ts +4 -1
  72. package/dist/core/DurableStatement.d.ts.map +1 -1
  73. package/dist/core/DurableStatement.js +4 -4
  74. package/dist/core/DurableStatement.js.map +1 -1
  75. package/dist/core/EditMutations.d.ts.map +1 -1
  76. package/dist/core/EditMutations.js +5 -2
  77. package/dist/core/EditMutations.js.map +1 -1
  78. package/dist/core/Engine.d.ts +11 -9
  79. package/dist/core/Engine.d.ts.map +1 -1
  80. package/dist/core/Engine.js +27 -65
  81. package/dist/core/Engine.js.map +1 -1
  82. package/dist/core/Engine.sql +2 -22
  83. package/dist/core/EnvFlags.d.ts.map +1 -1
  84. package/dist/core/EnvFlags.js +4 -2
  85. package/dist/core/EnvFlags.js.map +1 -1
  86. package/dist/core/ExecutionOutputs.sql +8 -0
  87. package/dist/core/ExecutorRegistry.d.ts +4 -0
  88. package/dist/core/ExecutorRegistry.d.ts.map +1 -1
  89. package/dist/core/ExecutorRegistry.js +3 -1
  90. package/dist/core/ExecutorRegistry.js.map +1 -1
  91. package/dist/core/KillHandler.d.ts.map +1 -1
  92. package/dist/core/KillHandler.js +7 -12
  93. package/dist/core/KillHandler.js.map +1 -1
  94. package/dist/core/Knob.d.ts +9 -0
  95. package/dist/core/Knob.d.ts.map +1 -0
  96. package/dist/core/Knob.js +50 -0
  97. package/dist/core/Knob.js.map +1 -0
  98. package/dist/core/LogBody.d.ts.map +1 -1
  99. package/dist/core/LogBody.js +8 -36
  100. package/dist/core/LogBody.js.map +1 -1
  101. package/dist/core/LogEntryProjection.d.ts.map +1 -1
  102. package/dist/core/LogEntryProjection.js +8 -10
  103. package/dist/core/LogEntryProjection.js.map +1 -1
  104. package/dist/core/LogVisibility.d.ts.map +1 -1
  105. package/dist/core/LogVisibility.js +2 -1
  106. package/dist/core/LogVisibility.js.map +1 -1
  107. package/dist/core/LogWriter.d.ts.map +1 -1
  108. package/dist/core/LogWriter.js +11 -9
  109. package/dist/core/LogWriter.js.map +1 -1
  110. package/dist/core/LoopDriver.d.ts +1 -1
  111. package/dist/core/LoopDriver.d.ts.map +1 -1
  112. package/dist/core/LoopDriver.js +24 -32
  113. package/dist/core/LoopDriver.js.map +1 -1
  114. package/dist/core/LoopLifecycle.d.ts +4 -17
  115. package/dist/core/LoopLifecycle.d.ts.map +1 -1
  116. package/dist/core/LoopLifecycle.js +20 -22
  117. package/dist/core/LoopLifecycle.js.map +1 -1
  118. package/dist/core/LoopLifecycle.sql +36 -49
  119. package/dist/core/LoopOutcome.d.ts +10 -0
  120. package/dist/core/LoopOutcome.d.ts.map +1 -0
  121. package/dist/core/LoopOutcome.js +28 -0
  122. package/dist/core/LoopOutcome.js.map +1 -0
  123. package/dist/core/LoopPolicies.d.ts +7 -0
  124. package/dist/core/LoopPolicies.d.ts.map +1 -0
  125. package/dist/core/LoopPolicies.js +37 -0
  126. package/dist/core/LoopPolicies.js.map +1 -0
  127. package/dist/core/MessageResources.d.ts +15 -0
  128. package/dist/core/MessageResources.d.ts.map +1 -0
  129. package/dist/core/MessageResources.js +46 -0
  130. package/dist/core/MessageResources.js.map +1 -0
  131. package/dist/core/MessageResources.sql +36 -0
  132. package/dist/core/ModelCall.d.ts.map +1 -1
  133. package/dist/core/ModelCall.js +2 -6
  134. package/dist/core/ModelCall.js.map +1 -1
  135. package/dist/core/ModelCall.sql +7 -36
  136. package/dist/core/OperatorConfig.d.ts +2 -1
  137. package/dist/core/OperatorConfig.d.ts.map +1 -1
  138. package/dist/core/OperatorConfig.js +14 -6
  139. package/dist/core/OperatorConfig.js.map +1 -1
  140. package/dist/core/PacketBuilder.d.ts.map +1 -1
  141. package/dist/core/PacketBuilder.js +20 -35
  142. package/dist/core/PacketBuilder.js.map +1 -1
  143. package/dist/core/PacketBuilder.sql +24 -6
  144. package/dist/core/PatternSelection.d.ts +1 -1
  145. package/dist/core/PatternSelection.d.ts.map +1 -1
  146. package/dist/core/ProposalLifecycle.d.ts +3 -1
  147. package/dist/core/ProposalLifecycle.d.ts.map +1 -1
  148. package/dist/core/ProposalLifecycle.js +93 -28
  149. package/dist/core/ProposalLifecycle.js.map +1 -1
  150. package/dist/core/ProviderInstantiate.d.ts +1 -0
  151. package/dist/core/ProviderInstantiate.d.ts.map +1 -1
  152. package/dist/core/ProviderInstantiate.js +12 -7
  153. package/dist/core/ProviderInstantiate.js.map +1 -1
  154. package/dist/core/ReasoningView.d.ts +1 -2
  155. package/dist/core/ReasoningView.d.ts.map +1 -1
  156. package/dist/core/ReasoningView.js +9 -20
  157. package/dist/core/ReasoningView.js.map +1 -1
  158. package/dist/core/ResourceBindings.d.ts.map +1 -1
  159. package/dist/core/ResourceBindings.js +5 -4
  160. package/dist/core/ResourceBindings.js.map +1 -1
  161. package/dist/core/ResourceMutations.d.ts +4 -4
  162. package/dist/core/ResourceMutations.d.ts.map +1 -1
  163. package/dist/core/ResourceMutations.js +2 -3
  164. package/dist/core/ResourceMutations.js.map +1 -1
  165. package/dist/core/ResourceSelector.d.ts +10 -3
  166. package/dist/core/ResourceSelector.d.ts.map +1 -1
  167. package/dist/core/ResourceSelector.js +52 -13
  168. package/dist/core/ResourceSelector.js.map +1 -1
  169. package/dist/core/ResourceTransfers.d.ts.map +1 -1
  170. package/dist/core/ResourceTransfers.js +4 -2
  171. package/dist/core/ResourceTransfers.js.map +1 -1
  172. package/dist/core/RuntimeWorker.d.ts.map +1 -1
  173. package/dist/core/RuntimeWorker.js +6 -1
  174. package/dist/core/RuntimeWorker.js.map +1 -1
  175. package/dist/core/RuntimeWorker.sql +7 -1
  176. package/dist/core/SchemeRegistry.d.ts +2 -0
  177. package/dist/core/SchemeRegistry.d.ts.map +1 -1
  178. package/dist/core/SchemeRegistry.js +12 -6
  179. package/dist/core/SchemeRegistry.js.map +1 -1
  180. package/dist/core/StoredPacket.d.ts +3 -1
  181. package/dist/core/StoredPacket.d.ts.map +1 -1
  182. package/dist/core/StoredPacket.js +7 -3
  183. package/dist/core/StoredPacket.js.map +1 -1
  184. package/dist/core/StrikeRail.d.ts +2 -2
  185. package/dist/core/StrikeRail.d.ts.map +1 -1
  186. package/dist/core/StrikeRail.js +15 -7
  187. package/dist/core/StrikeRail.js.map +1 -1
  188. package/dist/core/TerminalResult.d.ts +2 -2
  189. package/dist/core/TerminalResult.d.ts.map +1 -1
  190. package/dist/core/TerminalResult.js +15 -8
  191. package/dist/core/TerminalResult.js.map +1 -1
  192. package/dist/core/ToolInputSchema.d.ts.map +1 -1
  193. package/dist/core/ToolInputSchema.js +24 -8
  194. package/dist/core/ToolInputSchema.js.map +1 -1
  195. package/dist/core/ToolResources.d.ts +1 -0
  196. package/dist/core/ToolResources.d.ts.map +1 -1
  197. package/dist/core/ToolResources.js +50 -26
  198. package/dist/core/ToolResources.js.map +1 -1
  199. package/dist/core/Turn.d.ts +3 -1
  200. package/dist/core/Turn.d.ts.map +1 -1
  201. package/dist/core/Turn.js +4 -1
  202. package/dist/core/Turn.js.map +1 -1
  203. package/dist/core/Turn.sql +14 -2
  204. package/dist/core/TurnDispositionHandler.d.ts +13 -23
  205. package/dist/core/TurnDispositionHandler.d.ts.map +1 -1
  206. package/dist/core/TurnDispositionHandler.js +30 -180
  207. package/dist/core/TurnDispositionHandler.js.map +1 -1
  208. package/dist/core/TurnMaterialization.d.ts +9 -7
  209. package/dist/core/TurnMaterialization.d.ts.map +1 -1
  210. package/dist/core/TurnMaterialization.js +66 -46
  211. package/dist/core/TurnMaterialization.js.map +1 -1
  212. package/dist/core/TurnMaterialization.sql +23 -6
  213. package/dist/core/TurnOps.d.ts.map +1 -1
  214. package/dist/core/TurnOps.js +2 -2
  215. package/dist/core/TurnOps.js.map +1 -1
  216. package/dist/core/TurnRunner.d.ts +2 -8
  217. package/dist/core/TurnRunner.d.ts.map +1 -1
  218. package/dist/core/TurnRunner.js +1116 -1123
  219. package/dist/core/TurnRunner.js.map +1 -1
  220. package/dist/core/TurnRunner.sql +1 -24
  221. package/dist/core/TurnSources.sql +42 -11
  222. package/dist/core/WorkerControlHandler.d.ts.map +1 -1
  223. package/dist/core/WorkerControlHandler.js +23 -0
  224. package/dist/core/WorkerControlHandler.js.map +1 -1
  225. package/dist/core/WorkerName.d.ts +3 -6
  226. package/dist/core/WorkerName.d.ts.map +1 -1
  227. package/dist/core/WorkerName.js +10 -26
  228. package/dist/core/WorkerName.js.map +1 -1
  229. package/dist/core/WorkspaceGate.js +4 -4
  230. package/dist/core/WorkspaceGate.js.map +1 -1
  231. package/dist/core/ambient.sql +45 -19
  232. package/dist/core/attachments.d.ts +3 -1
  233. package/dist/core/attachments.d.ts.map +1 -1
  234. package/dist/core/attachments.js +4 -0
  235. package/dist/core/attachments.js.map +1 -1
  236. package/dist/core/caps/CoreInteractionCaps.d.ts +1 -1
  237. package/dist/core/caps/CoreInteractionCaps.d.ts.map +1 -1
  238. package/dist/core/caps/CoreInteractionCaps.js +4 -2
  239. package/dist/core/caps/CoreInteractionCaps.js.map +1 -1
  240. package/dist/core/caps/DbChannelCaps.js +6 -6
  241. package/dist/core/caps/DbChannelCaps.js.map +1 -1
  242. package/dist/core/caps/DbEntryCaps.js +1 -1
  243. package/dist/core/caps/DbEntryCaps.js.map +1 -1
  244. package/dist/core/caps/DbMessageCaps.d.ts +10 -0
  245. package/dist/core/caps/DbMessageCaps.d.ts.map +1 -0
  246. package/dist/core/caps/DbMessageCaps.js +39 -0
  247. package/dist/core/caps/DbMessageCaps.js.map +1 -0
  248. package/dist/core/caps/DbProjectionCaps.d.ts +2 -2
  249. package/dist/core/caps/DbProjectionCaps.d.ts.map +1 -1
  250. package/dist/core/caps/DbProjectionCaps.js +10 -4
  251. package/dist/core/caps/DbProjectionCaps.js.map +1 -1
  252. package/dist/core/caps/SchemeCtxImpl.d.ts +3 -1
  253. package/dist/core/caps/SchemeCtxImpl.d.ts.map +1 -1
  254. package/dist/core/caps/SchemeCtxImpl.js +11 -0
  255. package/dist/core/caps/SchemeCtxImpl.js.map +1 -1
  256. package/dist/core/env-catalog.d.ts +28 -0
  257. package/dist/core/env-catalog.d.ts.map +1 -0
  258. package/dist/core/env-catalog.js +99 -0
  259. package/dist/core/env-catalog.js.map +1 -0
  260. package/dist/core/file-materialization.js +1 -1
  261. package/dist/core/file-materialization.js.map +1 -1
  262. package/dist/core/fork.sql +7 -6
  263. package/dist/core/git-state.d.ts +3 -2
  264. package/dist/core/git-state.d.ts.map +1 -1
  265. package/dist/core/git-state.js +38 -21
  266. package/dist/core/git-state.js.map +1 -1
  267. package/dist/core/operation-target-groups.d.ts.map +1 -1
  268. package/dist/core/operation-target-groups.js +2 -1
  269. package/dist/core/operation-target-groups.js.map +1 -1
  270. package/dist/core/packet-inject.js +1 -1
  271. package/dist/core/packet-wire.d.ts +11 -0
  272. package/dist/core/packet-wire.d.ts.map +1 -1
  273. package/dist/core/packet-wire.js +382 -333
  274. package/dist/core/packet-wire.js.map +1 -1
  275. package/dist/core/plurnk-uri.d.ts +4 -5
  276. package/dist/core/plurnk-uri.d.ts.map +1 -1
  277. package/dist/core/plurnk-uri.js +10 -31
  278. package/dist/core/plurnk-uri.js.map +1 -1
  279. package/dist/core/scheme-types.d.ts +3 -1
  280. package/dist/core/scheme-types.d.ts.map +1 -1
  281. package/dist/core/scheme-types.js +1 -1
  282. package/dist/core/scheme-types.js.map +1 -1
  283. package/dist/core/teaching.d.ts.map +1 -1
  284. package/dist/core/teaching.js +2 -1
  285. package/dist/core/teaching.js.map +1 -1
  286. package/dist/core/types.d.ts +1 -2
  287. package/dist/core/types.d.ts.map +1 -1
  288. package/dist/core/types.js +1 -1
  289. package/dist/core/types.js.map +1 -1
  290. package/dist/core/worker-ops.sql +3 -8
  291. package/dist/digest/Digest.d.ts.map +1 -1
  292. package/dist/digest/Digest.js +37 -30
  293. package/dist/digest/Digest.js.map +1 -1
  294. package/dist/digest/DigestRender.d.ts +2 -0
  295. package/dist/digest/DigestRender.d.ts.map +1 -1
  296. package/dist/digest/DigestRender.js +97 -9
  297. package/dist/digest/DigestRender.js.map +1 -1
  298. package/dist/digest/DigestRequiem.d.ts.map +1 -1
  299. package/dist/digest/DigestRequiem.js +13 -15
  300. package/dist/digest/DigestRequiem.js.map +1 -1
  301. package/dist/digest/digest-db.d.ts +3 -0
  302. package/dist/digest/digest-db.d.ts.map +1 -0
  303. package/dist/digest/digest-db.js +68 -0
  304. package/dist/digest/digest-db.js.map +1 -0
  305. package/dist/digest/digest-paths.d.ts +6 -0
  306. package/dist/digest/digest-paths.d.ts.map +1 -0
  307. package/dist/digest/digest-paths.js +23 -0
  308. package/dist/digest/digest-paths.js.map +1 -0
  309. package/dist/digest/digest-rows.d.ts +21 -0
  310. package/dist/digest/digest-rows.d.ts.map +1 -1
  311. package/dist/digest/digest.sql +24 -5
  312. package/dist/index.d.ts +0 -1
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +0 -1
  315. package/dist/index.js.map +1 -1
  316. package/dist/observe/genai.d.ts +2 -2
  317. package/dist/observe/genai.d.ts.map +1 -1
  318. package/dist/observe/genai.js +15 -5
  319. package/dist/observe/genai.js.map +1 -1
  320. package/dist/schemes/EffectPolicy.d.ts +0 -2
  321. package/dist/schemes/EffectPolicy.d.ts.map +1 -1
  322. package/dist/schemes/EffectPolicy.js +25 -36
  323. package/dist/schemes/EffectPolicy.js.map +1 -1
  324. package/dist/schemes/Exec.d.ts +4 -5
  325. package/dist/schemes/Exec.d.ts.map +1 -1
  326. package/dist/schemes/Exec.js +129 -82
  327. package/dist/schemes/Exec.js.map +1 -1
  328. package/dist/schemes/ExecOutputScheme.d.ts +6 -5
  329. package/dist/schemes/ExecOutputScheme.d.ts.map +1 -1
  330. package/dist/schemes/ExecOutputScheme.js +49 -16
  331. package/dist/schemes/ExecOutputScheme.js.map +1 -1
  332. package/dist/schemes/ExecScheduler.js +2 -2
  333. package/dist/schemes/ExecScheduler.js.map +1 -1
  334. package/dist/schemes/File.d.ts.map +1 -1
  335. package/dist/schemes/File.js +30 -21
  336. package/dist/schemes/File.js.map +1 -1
  337. package/dist/schemes/Log.d.ts +4 -4
  338. package/dist/schemes/Log.d.ts.map +1 -1
  339. package/dist/schemes/Log.js +30 -10
  340. package/dist/schemes/Log.js.map +1 -1
  341. package/dist/schemes/QuestionTool.d.ts.map +1 -1
  342. package/dist/schemes/QuestionTool.js +15 -2
  343. package/dist/schemes/QuestionTool.js.map +1 -1
  344. package/dist/schemes/TurnSource.d.ts +3 -2
  345. package/dist/schemes/TurnSource.d.ts.map +1 -1
  346. package/dist/schemes/TurnSource.js +87 -41
  347. package/dist/schemes/TurnSource.js.map +1 -1
  348. package/dist/schemes/Worker.d.ts.map +1 -1
  349. package/dist/schemes/Worker.js +22 -56
  350. package/dist/schemes/Worker.js.map +1 -1
  351. package/dist/schemes/_entry-crud.js +6 -6
  352. package/dist/schemes/_entry-crud.js.map +1 -1
  353. package/dist/schemes/_entry-crud.sql +37 -17
  354. package/dist/schemes/_entry-find.d.ts.map +1 -1
  355. package/dist/schemes/_entry-find.js +6 -5
  356. package/dist/schemes/_entry-find.js.map +1 -1
  357. package/dist/schemes/_entry-fts.d.ts.map +1 -1
  358. package/dist/schemes/_entry-fts.js +6 -3
  359. package/dist/schemes/_entry-fts.js.map +1 -1
  360. package/dist/schemes/_entry-fts.sql +25 -6
  361. package/dist/schemes/_entry-manifest.d.ts +1 -1
  362. package/dist/schemes/_entry-manifest.d.ts.map +1 -1
  363. package/dist/schemes/_entry-manifest.js +10 -17
  364. package/dist/schemes/_entry-manifest.js.map +1 -1
  365. package/dist/schemes/_entry-manifest.sql +1 -1
  366. package/dist/schemes/_entry-ops.js +4 -4
  367. package/dist/schemes/_entry-ops.js.map +1 -1
  368. package/dist/schemes/_entry-ops.sql +2 -2
  369. package/dist/schemes/_entry-readable.d.ts.map +1 -1
  370. package/dist/schemes/_entry-readable.js +5 -4
  371. package/dist/schemes/_entry-readable.js.map +1 -1
  372. package/dist/schemes/_entry-send.js +2 -2
  373. package/dist/schemes/_entry-send.js.map +1 -1
  374. package/dist/schemes/_search-exclusion.d.ts +1 -0
  375. package/dist/schemes/_search-exclusion.d.ts.map +1 -1
  376. package/dist/schemes/_search-exclusion.js +12 -0
  377. package/dist/schemes/_search-exclusion.js.map +1 -1
  378. package/dist/schemes/_search-index.d.ts +5 -1
  379. package/dist/schemes/_search-index.d.ts.map +1 -1
  380. package/dist/schemes/_search-index.js +99 -59
  381. package/dist/schemes/_search-index.js.map +1 -1
  382. package/dist/schemes/_search-index.sql +17 -0
  383. package/dist/schemes/exec-abort.d.ts.map +1 -1
  384. package/dist/schemes/exec-abort.js +5 -4
  385. package/dist/schemes/exec-abort.js.map +1 -1
  386. package/dist/schemes/exec-env.d.ts +3 -0
  387. package/dist/schemes/exec-env.d.ts.map +1 -1
  388. package/dist/schemes/exec-env.js +66 -15
  389. package/dist/schemes/exec-env.js.map +1 -1
  390. package/dist/schemes/exec-lifetime.d.ts +11 -0
  391. package/dist/schemes/exec-lifetime.d.ts.map +1 -0
  392. package/dist/schemes/exec-lifetime.js +29 -0
  393. package/dist/schemes/exec-lifetime.js.map +1 -0
  394. package/dist/schemes/exec-runtime.d.ts +1 -1
  395. package/dist/schemes/exec-runtime.d.ts.map +1 -1
  396. package/dist/schemes/exec-runtime.js +1 -1
  397. package/dist/schemes/exec-runtime.js.map +1 -1
  398. package/dist/server/ClientReads.d.ts.map +1 -1
  399. package/dist/server/ClientReads.js +5 -2
  400. package/dist/server/ClientReads.js.map +1 -1
  401. package/dist/server/Daemon.d.ts +31 -7
  402. package/dist/server/Daemon.d.ts.map +1 -1
  403. package/dist/server/Daemon.js +137 -60
  404. package/dist/server/Daemon.js.map +1 -1
  405. package/dist/server/DaemonModule.d.ts +25 -6
  406. package/dist/server/DaemonModule.d.ts.map +1 -1
  407. package/dist/server/DrainSupervisor.d.ts +13 -11
  408. package/dist/server/DrainSupervisor.d.ts.map +1 -1
  409. package/dist/server/DrainSupervisor.js +87 -98
  410. package/dist/server/DrainSupervisor.js.map +1 -1
  411. package/dist/server/EnvFunctionality.d.ts +52 -0
  412. package/dist/server/EnvFunctionality.d.ts.map +1 -0
  413. package/dist/server/EnvFunctionality.js +199 -0
  414. package/dist/server/EnvFunctionality.js.map +1 -0
  415. package/dist/server/Functionality.d.ts +4 -2
  416. package/dist/server/Functionality.d.ts.map +1 -1
  417. package/dist/server/Functionality.js +250 -106
  418. package/dist/server/Functionality.js.map +1 -1
  419. package/dist/server/FunctionalityManager.d.ts +5 -1
  420. package/dist/server/FunctionalityManager.d.ts.map +1 -1
  421. package/dist/server/FunctionalityManager.js +24 -8
  422. package/dist/server/FunctionalityManager.js.map +1 -1
  423. package/dist/server/HttpListener.d.ts +16 -0
  424. package/dist/server/HttpListener.d.ts.map +1 -0
  425. package/dist/server/HttpListener.js +81 -0
  426. package/dist/server/HttpListener.js.map +1 -0
  427. package/dist/server/MembersFunctionality.d.ts.map +1 -1
  428. package/dist/server/MembersFunctionality.js +12 -17
  429. package/dist/server/MembersFunctionality.js.map +1 -1
  430. package/dist/server/PlurnkSkill.d.ts.map +1 -1
  431. package/dist/server/PlurnkSkill.js +1 -0
  432. package/dist/server/PlurnkSkill.js.map +1 -1
  433. package/dist/server/Retention.d.ts +14 -0
  434. package/dist/server/Retention.d.ts.map +1 -1
  435. package/dist/server/Retention.js +52 -4
  436. package/dist/server/Retention.js.map +1 -1
  437. package/dist/server/Retention.sql +55 -1
  438. package/dist/server/ServiceModules.d.ts.map +1 -1
  439. package/dist/server/ServiceModules.js +2 -0
  440. package/dist/server/ServiceModules.js.map +1 -1
  441. package/dist/server/SkillsFunctionality.d.ts +2 -0
  442. package/dist/server/SkillsFunctionality.d.ts.map +1 -1
  443. package/dist/server/SkillsFunctionality.js +27 -17
  444. package/dist/server/SkillsFunctionality.js.map +1 -1
  445. package/dist/server/WorkspaceCapabilities.d.ts.map +1 -1
  446. package/dist/server/WorkspaceCapabilities.js +1 -0
  447. package/dist/server/WorkspaceCapabilities.js.map +1 -1
  448. package/dist/server/WorkspaceResidency.d.ts +2 -0
  449. package/dist/server/WorkspaceResidency.d.ts.map +1 -1
  450. package/dist/server/WorkspaceResidency.js +27 -0
  451. package/dist/server/WorkspaceResidency.js.map +1 -1
  452. package/dist/server/WorkspaceStorage.d.ts +8 -0
  453. package/dist/server/WorkspaceStorage.d.ts.map +1 -0
  454. package/dist/server/WorkspaceStorage.js +26 -0
  455. package/dist/server/WorkspaceStorage.js.map +1 -0
  456. package/dist/server/client-input.d.ts +4 -3
  457. package/dist/server/client-input.d.ts.map +1 -1
  458. package/dist/server/client-input.js +25 -27
  459. package/dist/server/client-input.js.map +1 -1
  460. package/dist/server/dispatch-as-plurnk.js +2 -2
  461. package/dist/server/dispatch-as-plurnk.js.map +1 -1
  462. package/dist/server/drain.sql +69 -132
  463. package/dist/server/envelope.d.ts +2 -3
  464. package/dist/server/envelope.d.ts.map +1 -1
  465. package/dist/server/envelope.js +7 -21
  466. package/dist/server/envelope.js.map +1 -1
  467. package/dist/server/envelope.sql +10 -6
  468. package/dist/server/exec-poll-backoff.js +3 -3
  469. package/dist/server/exec-poll-backoff.js.map +1 -1
  470. package/dist/server/lifecycle-recovery.sql +12 -38
  471. package/dist/server/logEntry.sql +2 -2
  472. package/dist/server/loopDocs.js +3 -3
  473. package/dist/server/loopDocs.sql +4 -2
  474. package/dist/server/model-catalog.d.ts.map +1 -1
  475. package/dist/server/model-catalog.js +2 -2
  476. package/dist/server/model-catalog.js.map +1 -1
  477. package/dist/server/seam-loop.sql +0 -1
  478. package/dist/server/workspace-capabilities.sql +45 -0
  479. package/dist/server/workspace-storage.sql +8 -0
  480. package/dist/service.d.ts.map +1 -1
  481. package/dist/service.js +37 -11
  482. package/dist/service.js.map +1 -1
  483. package/docs/copy-move.md +31 -0
  484. package/docs/env.md +67 -0
  485. package/docs/members.md +4 -4
  486. package/docs/skills.md +2 -2
  487. package/migrations/002_workers.sql +41 -17
  488. package/migrations/003_loops.sql +82 -28
  489. package/migrations/004_inference.sql +53 -12
  490. package/migrations/005_entries.sql +135 -14
  491. package/migrations/006_log.sql +79 -24
  492. package/migrations/007_subscriptions.sql +10 -15
  493. package/package.json +45 -36
  494. package/dist/core/PromptFrames.d.ts +0 -12
  495. package/dist/core/PromptFrames.d.ts.map +0 -1
  496. package/dist/core/PromptFrames.js +0 -28
  497. package/dist/core/PromptFrames.js.map +0 -1
  498. package/dist/schemes/Prompt.d.ts +0 -8
  499. package/dist/schemes/Prompt.d.ts.map +0 -1
  500. package/dist/schemes/Prompt.js +0 -25
  501. package/dist/schemes/Prompt.js.map +0 -1
@@ -3,13 +3,16 @@ import { relative, sep } from "node:path";
3
3
  import { Problems, Validator } from "@plurnk/plurnk-contracts";
4
4
  import { TextCoordinates } from "@plurnk/plurnk-mimetypes";
5
5
  import { renderTarget } from "./plurnk-uri.js";
6
+ import GitState from "./git-state.js";
6
7
  import LogBody from "./LogBody.js";
7
8
  import LogEntryProjection from "./LogEntryProjection.js";
8
9
  import LogVisibility from "./LogVisibility.js";
9
10
  import BodyPreview from "../content/body-preview.js";
11
+ import ScopeFormat from "../content/scope-format.js";
10
12
  import { assertEditReceipt, assertResourceEffects, LineAnchors, } from "../content/index.js";
11
13
  // {§packet-attachment-parts} — the attachment kinds and their readout weights live in one table.
12
- import { imageWeight, pdfWeight } from "./attachments.js";
14
+ import { audioWeight, imageWeight, pdfWeight } from "./attachments.js";
15
+ import { isExecutionOp } from "@plurnk/plurnk-contracts";
13
16
  export { imageWeight, pdfWeight };
14
17
  export default class PacketWire {
15
18
  // {§packet-markdown} Render the sections in `slot` to one ChatMessage.content
@@ -145,6 +148,9 @@ export default class PacketWire {
145
148
  if (lines.length !== ordinals.length) {
146
149
  throw new TypeError("A sparse log-body projection requires one source ordinal per rendered line.");
147
150
  }
151
+ if (sourceLineNumbers !== null && ordinals.some((ordinal) => ordinal < 1 || ordinal > sourceLineNumbers.length)) {
152
+ throw new TypeError("A sparse log-body projection's ordinals must address its source line numbers.");
153
+ }
148
154
  const displayed = ordinals.map((ordinal) => sourceLineNumbers === null ? startLine + ordinal - 1 : sourceLineNumbers[ordinal - 1]);
149
155
  const width = lineAnchors === null
150
156
  ? numericLineNumberWidth > 0
@@ -201,7 +207,7 @@ export default class PacketWire {
201
207
  static #canonicalJson(obj) {
202
208
  const keys = Object.keys(obj).sort();
203
209
  const sorted = {};
204
- for (const key of ["target", "aside"]) {
210
+ for (const key of ["path", "from", "to", "aside"]) {
205
211
  if (Object.hasOwn(obj, key))
206
212
  sorted[key] = obj[key];
207
213
  }
@@ -223,7 +229,7 @@ export default class PacketWire {
223
229
  return {
224
230
  ...head,
225
231
  change: `-${receipt.effect.removed} +${receipt.effect.inserted}`,
226
- range: `${receipt.effect.requested} ${receipt.effect.source}->${receipt.effect.result}`,
232
+ effect: `${receipt.effect.source} -> ${receipt.effect.result}`,
227
233
  // {§edit-receipt-removed-text} — what a deletion took, so it can be put back from the receipt.
228
234
  ...(receipt.effect.removedText === undefined ? {} : { removed: receipt.effect.removedText }),
229
235
  };
@@ -236,7 +242,7 @@ export default class PacketWire {
236
242
  ? {}
237
243
  : {
238
244
  change: `-${receipt.replacement.removed} +${receipt.replacement.inserted}`,
239
- replacement: `${receipt.replacement.requested} ${receipt.replacement.source}->${receipt.replacement.result}`,
245
+ replacement: `${receipt.replacement.source} -> ${receipt.replacement.result}`,
240
246
  }),
241
247
  };
242
248
  }
@@ -252,21 +258,7 @@ export default class PacketWire {
252
258
  }
253
259
  return endsWithLineBreak ? body.replace(/(?:\r\n|\r|\n)$/, "") : body;
254
260
  }
255
- // Render one Log entry → a single bullet line carrying the meta JSON.
256
- // No body, no fence — every meaningful field is in the JSON. Naming
257
- // follows the uniform principle: `path` is identity (this log row's
258
- // own URI), `target` is the URI in the statement's target slot. COPY/MOVE
259
- // retain their source and destination selections separately from ordered
260
- // applied `effects`.
261
- //
262
- // On error, status >= 400 signals the failure; Problem Details live on
263
- // this durable row and the next packet's Errors section points here.
264
- //
265
- // Per-entry render: one meta JSON line plus the row's canonical body.
266
- // LogBody owns tx/rx storage interpretation; packet projection owns only
267
- // visibility, previewing, mimetype rendering, and metadata.
268
- // The log:/// handle the model sees for an entry.
269
- // ({§log-kill-scope}).
261
+ // {§log-address-metadata} — row identity belongs to the H3, not its operand metadata.
270
262
  static #entryPath(coordinate, leaf) {
271
263
  if (coordinate === null)
272
264
  throw new TypeError("A packet log row requires an addressable coordinate.");
@@ -287,30 +279,26 @@ export default class PacketWire {
287
279
  chunk: cut ? PacketWire.#chunk(coordinates, physicalLines, end, text.length) : null,
288
280
  };
289
281
  }
290
- static #formatRegion(region) {
291
- return `<${region.startLine},${region.startColumn},${region.endLine},${region.endColumn}>`;
292
- }
293
282
  static #chunk(coordinates, lines, end, completeEnd) {
294
283
  const finalCompleteLine = lines.findIndex((line) => line.separator.length > 0 && line.end === end);
295
284
  if (finalCompleteLine !== -1) {
296
- const selected = `<1,${finalCompleteLine + 1}>`;
297
- const complete = `<1,${lines.length}>`;
298
- if (selected === complete) {
285
+ const selected = ScopeFormat.lines(1, finalCompleteLine + 1);
286
+ if (finalCompleteLine + 1 === lines.length) {
299
287
  throw new Error("a bounded body chunk must differ from its complete line extent");
300
288
  }
301
- return `showing ${selected} of ${complete}`;
289
+ return `${selected} of ${ScopeFormat.count("line", lines.length)}`;
302
290
  }
303
291
  const selectedRegion = coordinates.regionFromOffsets(0, end);
304
292
  const completeRegion = coordinates.regionFromOffsets(0, completeEnd);
305
293
  if (selectedRegion === null || completeRegion === null) {
306
294
  throw new Error("a character-bound body chunk must resolve to exact text coordinates");
307
295
  }
308
- const selected = PacketWire.#formatRegion(selectedRegion);
309
- const complete = PacketWire.#formatRegion(completeRegion);
296
+ const selected = ScopeFormat.region(selectedRegion);
297
+ const complete = ScopeFormat.region(completeRegion);
310
298
  if (selected === complete) {
311
299
  throw new Error("a bounded body chunk must differ from its complete text extent");
312
300
  }
313
- return `showing ${selected} of ${complete}`;
301
+ return `${selected} of ${complete}`;
314
302
  }
315
303
  static #sparseChunk(completeContent, visibleContent, visibleOrdinals, projectedContent) {
316
304
  const end = projectedContent.length;
@@ -329,8 +317,8 @@ export default class PacketWire {
329
317
  previous[1] = ordinal;
330
318
  }
331
319
  }
332
- const selected = runs.map(([start, finish]) => `<${start},${finish}>`).join(",");
333
- return `showing ${selected} of <1,${TextCoordinates.logicalLines(completeContent).length}>`;
320
+ const selected = runs.map(([start, finish]) => ScopeFormat.lines(start, finish)).join(",");
321
+ return `${selected} of ${ScopeFormat.count("line", TextCoordinates.logicalLines(completeContent).length)}`;
334
322
  }
335
323
  const local = coordinates.regionFromOffsets(0, end);
336
324
  const complete = new TextCoordinates(completeContent)
@@ -343,11 +331,11 @@ export default class PacketWire {
343
331
  if (startLine === undefined || endLine === undefined) {
344
332
  throw new Error("a sparse character-bound chunk must map to canonical body lines");
345
333
  }
346
- return `showing ${PacketWire.#formatRegion({
334
+ return `${ScopeFormat.region({
347
335
  ...local,
348
336
  startLine,
349
337
  endLine,
350
- })} of ${PacketWire.#formatRegion(complete)}`;
338
+ })} of ${ScopeFormat.region(complete)}`;
351
339
  }
352
340
  static #promptProjection(body, budget, weighContent, render = (content) => PacketWire.#renderContentBody(content, body.startLine, null)) {
353
341
  const weightAt = (end) => weighContent(render(body.content.slice(0, end)));
@@ -421,10 +409,24 @@ export default class PacketWire {
421
409
  readableContent: select(readableOrdinals),
422
410
  readableOrdinals,
423
411
  folded: clipped,
412
+ trimmed: LogVisibility.clipped(trimmed, totalLines),
424
413
  totalLines,
425
414
  fullyFolded: LogVisibility.fullyFolded(clipped, totalLines),
426
415
  };
427
416
  }
417
+ // {§message-arrival} — an inbound SEND row: harness-published, the sender's statement as its
418
+ // sent side. {§message-causal-source}: a `source` names the actor; absence is the owner.
419
+ static isArrival(e) {
420
+ if (e.op !== "SEND" || e.origin !== "_plurnk")
421
+ return false;
422
+ const attrs = typeof e.attrs === "string" ? JSON.parse(e.attrs) : e.attrs;
423
+ return attrs !== null && typeof attrs === "object" && attrs.kind === "message";
424
+ }
425
+ // {§message-projection} — a peer worker's message takes the ordinary bounds; every other
426
+ // arrival, the loop's own assignment included, shares the allowance.
427
+ static isExteriorArrival(e) {
428
+ return PacketWire.isArrival(e) && !(typeof e.source === "string" && e.source.startsWith("worker://"));
429
+ }
428
430
  static #promptProjectionWeights(entries, bodies, visibility, weighContent, budget) {
429
431
  if (budget === undefined)
430
432
  return new Map();
@@ -432,7 +434,9 @@ export default class PacketWire {
432
434
  throw new RangeError(`promptProjectionWeight must be a non-negative safe integer, got ${JSON.stringify(budget)}`);
433
435
  }
434
436
  const costs = entries.flatMap((entry, index) => {
435
- if (entry.op !== "prompt" || bodies[index].content.length === 0)
437
+ // {§message-projection} — an arrival from outside the workspace shares the allowance;
438
+ // a peer worker's message takes the ordinary bounds.
439
+ if (!PacketWire.isExteriorArrival(entry) || bodies[index].content.length === 0)
436
440
  return [];
437
441
  const body = bodies[index];
438
442
  const visible = visibility[index];
@@ -481,316 +485,351 @@ export default class PacketWire {
481
485
  }));
482
486
  const promptProjectionWeights = PacketWire.#promptProjectionWeights(entries, visibleBodies, visibility, weighContent, options.promptProjectionWeight);
483
487
  return entries.map((e, index) => {
484
- const meta = {};
485
- const coordinate = typeof e.coordinate === "string" ? e.coordinate : null;
486
- const op = typeof e.op === "string" && e.op.length > 0 ? e.op : null;
487
- const renderedLeaf = LogEntryProjection.leaf(e);
488
- const path = PacketWire.#entryPath(coordinate, renderedLeaf);
489
- // Absence = "model" — the worker's own authorship is the default,
490
- // exactly as `source` absence means the owning worker (#338).
491
- if (typeof e.origin === "string" && e.origin !== "model")
492
- meta.origin = e.origin;
493
- // {§env-delta-attribution}: render the causal worker address or
494
- // subsystem token when present; absence means the owning worker.
495
- if (typeof e.source === "string" && e.source.length > 0)
496
- meta.source = e.source;
497
- if (e.source === "file" && e.attrs !== null && typeof e.attrs === "object" && "git" in e.attrs) {
498
- const git = e.attrs.git;
499
- if (typeof git !== "string" || git.length !== 2) {
500
- throw new TypeError("A source=file log row carries malformed Git XY metadata.");
501
- }
502
- meta.git = git;
503
- }
504
- // SEND, TASK, destructive KILL, and non-200 statuses stay explicit.
505
- // Successful log-KILL rows never reach this projection
506
- // ({§log-kill-meta-operation}).
507
- if (typeof e.status === "number" && (op === "SEND" || op === "KILL" || typeof op === "string" && TurnDisposition.isOp(op) || e.status !== 200))
508
- meta.status = e.status;
509
- const tx = (typeof e.tx === "string" ? PacketWire.#safeParse(e.tx) : e.tx);
510
- if (typeof tx?.aside === "string")
511
- meta.aside = tx.aside;
512
- const target = PacketWire.#renderActionTarget(e.target);
513
- // {§exec-stream}: a terminal stream observation's address is the stream it observed,
514
- // rendered under `stream` like the invocation's own link — never a `target`, which
515
- // the model would otherwise author into an EXEC slot (#425 F4).
516
- const terminalStream = op === "READ"
517
- && e.attrs !== null
518
- && typeof e.attrs === "object"
519
- && e.attrs.terminal === true;
520
- if (op === "COPY" || op === "MOVE") {
521
- const source = PacketWire.#renderSelection(tx?.source?.target, tx?.source?.lineMarker);
522
- const destination = PacketWire.#renderSelection(tx?.destination?.target, tx?.destination?.lineMarker);
523
- if (source !== null)
524
- meta.source = source;
525
- if (destination !== null)
526
- meta.destination = destination;
527
- if (typeof e.status === "number"
528
- && e.status < 400
529
- && (source === null || destination === null)) {
530
- throw new Error(`A successful ${op} log row must retain both operand selections.`);
531
- }
532
- }
533
- else if (target !== null) {
534
- meta[terminalStream ? "stream" : "target"] = target;
535
- }
536
- // {§worker-auto-name} The created identity is an outcome, not an authored target.
537
- if ((op === "WORK" || op === "FORK") && e.attrs !== null && typeof e.attrs === "object"
538
- && typeof e.attrs.worker === "string") {
539
- meta.worker = e.attrs.worker;
540
- }
541
- // EXEC's output is a separate stream entry ({§exec-stream}); its address rides in a
542
- // `stream` link, distinct from the runtime-owned invocation target.
543
- // {§exec-target-routing} {§fs-namespace} — the receipt names the working directory only
544
- // when it is not the project root, and then in the model's own project-relative form;
545
- // the root is the default and a host-absolute path never reaches the packet.
546
- if (op === "EXEC" && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.cwd === "string") {
547
- const cwd = PacketWire.#projectRelativeCwd(e.attrs.cwd, options.projectRoot ?? null);
548
- if (cwd !== null)
549
- meta.cwd = cwd;
550
- }
551
- if (op === "EXEC" && e.attrs !== null && typeof e.attrs === "object" && typeof e.attrs.stream === "string") {
552
- meta.stream = e.attrs.stream;
553
- }
488
+ const identity = PacketWire.#rowIdentity(e, options);
554
489
  // Parse rx once — reused for the matcher/items enrichment and the body.
555
490
  const rx = (typeof e.rx === "string" ? PacketWire.#safeParse(e.rx) : e.rx);
556
- // {§exec-stream}: a terminal stream observation is self-sufficient
557
- // even when its selected channel is empty. Preserve exact producer
558
- // facts; do not manufacture a prose completion summary.
559
- if (terminalStream) {
560
- meta.terminal = true;
561
- if (rx !== null && typeof rx === "object" && Object.hasOwn(rx, "exitCode")) {
562
- if (typeof rx.exitCode !== "number" || !Number.isSafeInteger(rx.exitCode)) {
563
- throw new TypeError("A terminal stream result carries a malformed exitCode.");
564
- }
565
- meta.exitCode = rx.exitCode;
566
- }
491
+ const facts = PacketWire.#rowResultFacts(identity, e, rx, bodies[index]);
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). An arrival is an inbound
508
+ // SEND row the harness published ({§message-causal-source}): its origin says nothing, so
509
+ // the row carries only the causal `source` when another actor supplied one (#706).
510
+ if (typeof e.origin === "string" && e.origin !== "model" && !PacketWire.isArrival(e))
511
+ meta.origin = e.origin;
512
+ // {§env-delta-attribution}: render the causal worker address or
513
+ // subsystem token when present; absence means the owning worker.
514
+ // {§message-short-identity} an arrival whose source is the transport's own name for it adds
515
+ // nothing to its address; a peer's or an agent's source still shows.
516
+ const arrivalAttrs = typeof e.attrs === "string" ? PacketWire.#safeParse(e.attrs) : e.attrs;
517
+ const selfAddressed = arrivalAttrs !== null && typeof arrivalAttrs === "object" && arrivalAttrs.selfAddressed === true;
518
+ if (typeof e.source === "string" && e.source.length > 0 && !selfAddressed)
519
+ meta.source = e.source;
520
+ if (e.source === "file" && e.attrs !== null && typeof e.attrs === "object" && "git" in e.attrs) {
521
+ const git = e.attrs.git;
522
+ if (typeof git !== "string" || git.length !== 2) {
523
+ throw new TypeError("A source=file log row carries malformed Git XY metadata.");
567
524
  }
568
- // {§problem-projection} — the exact durable Problem remains the
569
- // failure authority; the packet carries only facts not already
570
- // owned by its enclosing row. Errors remains only an index.
571
- if (typeof e.status === "number" && e.status >= 400 && rx !== null && typeof rx === "object") {
572
- const problem = rx.problem;
573
- Validator.assertProblemDetails(problem);
574
- meta.problem = Problems.project(problem, {
575
- status: e.status,
576
- row: meta,
577
- });
525
+ meta.git = git;
526
+ }
527
+ // SEND, lifecycle verbs, destructive KILL, and non-200 statuses stay explicit.
528
+ // Successful log-KILL rows never reach this projection
529
+ // ({§log-kill-meta-operation}).
530
+ if (typeof e.status === "number" && (op === "SEND" || op === "KILL" || typeof op === "string" && TurnDisposition.isOp(op) || e.status !== 200))
531
+ meta.status = e.status;
532
+ const tx = (typeof e.tx === "string" ? PacketWire.#safeParse(e.tx) : e.tx);
533
+ if (typeof tx?.aside === "string")
534
+ meta.aside = tx.aside;
535
+ const target = PacketWire.#renderActionTarget(e.target);
536
+ // {§log-address-metadata}: operands are independent of record identity and attribution.
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.from = source;
542
+ if (destination !== null)
543
+ meta.to = 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.`);
578
548
  }
579
- // The success-side sibling (#342): a sub-problem receipt may carry one
580
- // terse `detail` (e.g. the EDIT 304) so situational teaching is paid
581
- // only when the situation occurs, never in the hot path.
582
- if (!Object.hasOwn(meta, "problem") && rx !== null && typeof rx === "object"
583
- && typeof rx.detail === "string"
584
- && rx.detail.length > 0) {
585
- meta.detail = rx.detail;
549
+ }
550
+ else if (target !== null) {
551
+ meta.path = 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 };
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, fullBody) {
577
+ const { meta, op, tx } = identity;
578
+ if (op === "SEND" && rx !== null && typeof rx === "object" && Array.isArray(rx.attachments) && rx.attachments.length > 0) {
579
+ meta.attachments = rx.attachments.map(({ name, mediaType, target }) => ({ name, mediaType, path: target }));
580
+ }
581
+ // {§operation-resource-receipt}: preserve the returned address, not a second authored target.
582
+ if (rx !== null && typeof rx === "object" && typeof rx.resource === "string"
583
+ && rx.resource.length > 0 && rx.resource !== meta.path && rx.resource !== meta.stream) {
584
+ meta.resource = rx.resource;
585
+ }
586
+ // {§exec-stream}: explicit and automatic READs preserve the same
587
+ // durable liveness facts, including an empty active channel.
588
+ if (op === "READ" && rx !== null && typeof rx === "object" && Object.hasOwn(rx, "terminal")) {
589
+ if (typeof rx.terminal !== "boolean") {
590
+ throw new TypeError("A stream READ result carries a malformed terminal flag.");
586
591
  }
587
- // {§retrieval-packet-metadata}: one extent/coordinate owner plus
588
- // only FIND aggregates that add information beyond that extent.
589
- let findItems = null;
590
- // {§matcher-option} — a pattern rides the heading; the row shows it as `matcher`.
591
- const patterned = tx !== null && tx !== undefined && typeof tx === "object" && tx.matcher !== null && typeof tx.matcher === "object" && typeof tx.matcher.raw === "string";
592
- if (patterned) {
593
- meta.matcher = tx.matcher.raw;
594
- if (op !== "FIND" && rx !== null && typeof rx === "object" && typeof rx.matched === "number")
595
- meta.matched = rx.matched;
592
+ meta.terminal = rx.terminal;
593
+ if (Object.hasOwn(rx, "exitCode")) {
594
+ if (typeof rx.exitCode !== "number" || !Number.isSafeInteger(rx.exitCode)) {
595
+ throw new TypeError("A stream READ result carries a malformed exitCode.");
596
+ }
597
+ meta.exitCode = rx.exitCode;
596
598
  }
597
- // {§channel-selection-visibility} — a READ names the resource's other channels with their
598
- // tokens, so the row itself shows the choice a FIND listing would.
599
- if (op === "READ" && rx !== null && typeof rx === "object" && rx.channels !== null && typeof rx.channels === "object") {
600
- meta.channels = rx.channels;
599
+ }
600
+ // {§problem-projection} — the exact durable Problem remains the
601
+ // failure authority; the packet carries only facts not already
602
+ // owned by its enclosing row. Errors remains only an index.
603
+ if (typeof e.status === "number" && e.status >= 400 && rx !== null && typeof rx === "object") {
604
+ const problem = rx.problem;
605
+ Validator.assertProblemDetails(problem);
606
+ meta.problem = Problems.project(problem, {
607
+ status: e.status,
608
+ row: { ...meta, target: identity.target },
609
+ });
610
+ }
611
+ // The success-side sibling (#342): a sub-problem receipt may carry one
612
+ // terse `detail` (e.g. the EDIT 304) so situational teaching is paid
613
+ // only when the situation occurs, never in the hot path.
614
+ if (!Object.hasOwn(meta, "problem") && rx !== null && typeof rx === "object"
615
+ && typeof rx.detail === "string"
616
+ && rx.detail.length > 0) {
617
+ meta.detail = rx.detail;
618
+ }
619
+ // {§retrieval-packet-metadata}: one extent/coordinate owner plus
620
+ // only FIND aggregates that add information beyond that extent.
621
+ let findItems = null;
622
+ let range = null;
623
+ const patterned = tx !== null && tx !== undefined && typeof tx === "object" && tx.matcher !== null && typeof tx.matcher === "object" && typeof tx.matcher.raw === "string";
624
+ if (patterned) {
625
+ meta.matcher = tx.matcher.raw;
626
+ if (op !== "FIND" && rx !== null && typeof rx === "object" && typeof rx.matched === "number")
627
+ meta.matched = rx.matched;
628
+ }
629
+ // {§channel-selection-visibility} — a READ names the resource's other channels with their
630
+ // tokens, so the row itself shows the choice a FIND listing would.
631
+ if (op === "READ" && rx !== null && typeof rx === "object" && rx.channels !== null && typeof rx.channels === "object") {
632
+ meta.channels = rx.channels;
633
+ }
634
+ // {§send-response-receipt} — a reply's row names the prompts it answered.
635
+ if (op === "SEND" && rx !== null && typeof rx === "object" && Array.isArray(rx.answers)) {
636
+ meta.answers = rx.answers;
637
+ }
638
+ if (op === "READ" || op === "FIND") {
639
+ if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.content === "string") {
640
+ const parsed = PacketWire.#safeParse(rx.content);
641
+ if (Array.isArray(parsed))
642
+ findItems = parsed.length;
601
643
  }
602
- // {§send-response-receipt} — a reply's row names the prompts it answered.
603
- if (op === "SEND" && rx !== null && typeof rx === "object" && Array.isArray(rx.recipients)) {
604
- meta.recipients = rx.recipients;
644
+ range = rx !== null && typeof rx === "object" && rx.range !== undefined
645
+ ? Validator.assertRangeExtent(rx.range)
646
+ : null;
647
+ const problemOwnsRange = typeof e.status === "number"
648
+ && e.status >= 400
649
+ && meta.problem !== null
650
+ && typeof meta.problem === "object"
651
+ && Object.hasOwn(meta.problem, "range");
652
+ if (problemOwnsRange) {
653
+ Validator.assertRangeExtent(meta.problem.range);
605
654
  }
606
- if (op === "READ" || op === "FIND") {
607
- if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.content === "string") {
608
- const parsed = PacketWire.#safeParse(rx.content);
609
- if (Array.isArray(parsed))
610
- findItems = parsed.length;
611
- }
612
- const range = rx !== null && typeof rx === "object" && rx.range !== undefined
613
- ? rx.range
614
- : undefined;
615
- const problemOwnsRange = typeof e.status === "number"
616
- && e.status >= 400
617
- && meta.problem !== null
618
- && typeof meta.problem === "object"
619
- && Object.hasOwn(meta.problem, "range");
620
- if (problemOwnsRange) {
621
- Validator.assertRangeExtent(meta.problem.range);
622
- }
623
- if (range !== undefined && !problemOwnsRange) {
624
- meta.range = Validator.assertRangeExtent(range);
625
- }
626
- else if (op === "READ" && rx !== null && typeof rx === "object" && rx.region !== undefined) {
627
- meta.region = Validator.assertTextRegion(rx.region);
628
- }
629
- // These are underlying selected-content weights, distinct from
630
- // the emitted body's generic `tokens` measurement.
631
- if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.itemsWeightTotal === "number" && rx.itemsWeightTotal > 0) {
632
- meta.itemsTokenTotal = rx.itemsWeightTotal;
633
- }
634
- if (op === "FIND"
635
- && rx !== null
636
- && typeof rx === "object"
637
- && typeof rx.returnedItemsWeightTotal === "number"
638
- && rx.returnedItemsWeightTotal > 0
639
- && rx.returnedItemsWeightTotal !== rx.itemsWeightTotal) {
640
- meta.returnedItemsTokenTotal = rx.returnedItemsWeightTotal;
641
- }
642
- if (op === "FIND"
643
- && patterned
644
- && range !== null
645
- && typeof range === "object"
646
- && range.unit === "resource"
647
- && rx !== null
648
- && typeof rx === "object"
649
- && typeof rx.matchLocationCount === "number"
650
- && rx.matchLocationCount > 0) {
651
- meta.matchLocationCount = rx.matchLocationCount;
652
- }
655
+ if (range !== null && !problemOwnsRange) {
656
+ const sparse = fullBody.lineOrdinals !== undefined
657
+ && range.returned !== undefined
658
+ && fullBody.lineOrdinals.length !== range.returned[1] - range.returned[0] + 1;
659
+ meta.range = typeof e.status === "number" && e.status >= 400
660
+ ? range
661
+ : ScopeFormat.range(range, sparse);
662
+ }
663
+ else if (range === null && !problemOwnsRange && op === "READ" && rx !== null && typeof rx === "object" && rx.region !== undefined) {
664
+ meta.range = ScopeFormat.region(Validator.assertTextRegion(rx.region));
653
665
  }
654
- // {§edit-result-receipt-projection} {§edit-result-copy-move-effects}
655
- // EDIT/scoped entry KILL own one receipt; COPY/MOVE own resource effects whose
656
- // optional receipts describe scoped textual materializations.
657
- let structuredMutationReceipt = false;
658
- if ((op === "EDIT" || op === "KILL") && rx !== null && typeof rx === "object" && Object.hasOwn(rx, "receipt")) {
659
- Object.assign(meta, PacketWire.#receiptMeta(rx.receipt));
660
- structuredMutationReceipt = true;
666
+ // These are underlying selected-content weights, distinct from
667
+ // the emitted body's generic `tokens` measurement.
668
+ if (op === "FIND" && rx !== null && typeof rx === "object" && typeof rx.itemsWeightTotal === "number" && rx.itemsWeightTotal > 0) {
669
+ meta.itemsTokenTotal = rx.itemsWeightTotal;
661
670
  }
662
- if ((op === "COPY" || op === "MOVE")
671
+ if (op === "FIND"
663
672
  && rx !== null
664
673
  && typeof rx === "object"
665
- && Object.hasOwn(rx, "effects")) {
666
- const effects = assertResourceEffects(rx.effects);
667
- meta.effects = effects.map((effect) => ({
668
- target: effect.target,
669
- action: effect.action,
670
- ...(effect.receipt === undefined
671
- ? {}
672
- : PacketWire.#receiptMeta(effect.receipt)),
673
- }));
674
- structuredMutationReceipt = effects.some((effect) => effect.receipt !== undefined);
675
- }
676
- // The canonical full body is shared with log READ, log FIND,
677
- // and search derivation. READ/FIND own selection bounds, TASK and
678
- // admitted programs remain complete, and prompt rows share their packet
679
- // allowance. Structured mutation receipts own their join bound;
680
- // every remaining body uses the ordinary fixed preview.
681
- const fullBody = bodies[index];
682
- const bodyVisibility = visibility[index];
683
- const projectedBody = {
684
- ...fullBody,
685
- content: bodyVisibility.fullyFolded ? bodyVisibility.readableContent : bodyVisibility.content,
686
- };
687
- const emptyFind = op === "FIND" && e.status === 200 && findItems === 0;
688
- const previewExempt = op === "READ"
689
- || op === "FIND"
690
- || op === "TASK"
691
- || (op === null && renderedLeaf === "ops")
692
- || structuredMutationReceipt;
693
- const lineAnchors = op === "READ" ? e.lineAnchors ?? null : null;
694
- const lineNumberWidth = op === "READ" ? e.lineNumberWidth ?? null : null;
695
- if (lineAnchors !== null) {
696
- LineAnchors.assertProjection(fullBody.content, lineAnchors);
674
+ && typeof rx.returnedItemsWeightTotal === "number"
675
+ && rx.returnedItemsWeightTotal > 0
676
+ && rx.returnedItemsWeightTotal !== rx.itemsWeightTotal) {
677
+ meta.returnedItemsTokenTotal = rx.returnedItemsWeightTotal;
697
678
  }
698
- const findRange = op === "FIND" && meta.range !== null && typeof meta.range === "object"
699
- ? meta.range
700
- : null;
701
- const bodyStartLine = findRange?.returned?.[0] ?? fullBody.startLine;
702
- const numericLineNumberWidth = findRange === null
703
- ? bodyStartLine === null || bodyVisibility.totalLines === 0
704
- ? 0
705
- : String(fullBody.lineOrdinals?.at(-1) ?? bodyStartLine + bodyVisibility.totalLines - 1).length
706
- : String(findRange.total).length;
707
- const sourceOrdinals = bodyVisibility.fullyFolded
708
- ? bodyVisibility.readableOrdinals
709
- : bodyVisibility.ordinals;
710
- const promptProjectionWeight = promptProjectionWeights.get(index);
711
- const projection = promptProjectionWeight !== undefined
712
- ? PacketWire.#promptProjection(projectedBody, promptProjectionWeight, weighContent, (content) => PacketWire.#renderContentBody(content, bodyStartLine, null, null, numericLineNumberWidth, bodyStartLine === null
713
- ? null
714
- : sourceOrdinals.slice(0, TextCoordinates.logicalLines(content).length)))
715
- : previewExempt
716
- ? { text: projectedBody.content, cut: false, chunk: null }
717
- : PacketWire.#preview(projectedBody.content);
718
- const projectedLineCount = TextCoordinates.logicalLines(projection.text).length;
719
- const projectedOrdinals = sourceOrdinals.slice(0, projectedLineCount);
720
- const body = emptyFind || projection.text.length === 0
721
- ? ""
722
- : PacketWire.#renderContentBody(projection.text, bodyStartLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, bodyStartLine === null ? null : projectedOrdinals, fullBody.lineOrdinals ?? null);
723
- // lines beside tokens on a non-retrieval row with a navigable body — the count of
724
- // `N:`-numbered lines (fences and unnumbered prose don't count), so the model can plan
725
- // a <start,end> slice before paying for a READ. READ/FIND own typed extents instead.
726
- if (fullBody.content.length > 0 && op !== "READ" && op !== "FIND") {
727
- meta.lines = bodyVisibility.totalLines;
728
- }
729
- if (bodyVisibility.folded.length > 0 && !bodyVisibility.fullyFolded) {
730
- meta.folded = LogVisibility.format(bodyVisibility.folded);
731
- }
732
- const display = bodyVisibility.readableContent.length === 0
733
- ? "none"
734
- : bodyVisibility.fullyFolded || e.output_withheld === true
735
- ? "folded"
736
- : body.length === 0
737
- ? "none"
738
- : "open";
739
- const projectedChunk = projection.chunk !== null
740
- && bodyVisibility.folded.length > 0
741
- && !bodyVisibility.fullyFolded
742
- ? PacketWire.#sparseChunk(fullBody.content, projectedBody.content, sourceOrdinals, projection.text)
743
- : projection.chunk;
744
- if (display === "open" && projectedChunk !== null)
745
- meta.chunk = projectedChunk;
746
- const nativeCandidate = op === "READ" && typeof e.status === "number" && e.status >= 200 && e.status < 300
747
- ? PacketWire.#attachmentOf(e.rx, e.target, coordinate, target) : null;
748
- const native = nativeCandidate !== null && (options.acceptedAttachmentKinds?.has(nativeCandidate.kind) ?? true)
749
- ? nativeCandidate : null;
750
- const outputWithheld = e.output_withheld === true
751
- && ((!bodyVisibility.fullyFolded && body.length > 0) || native !== null);
752
- if (outputWithheld) {
753
- const omitted = body.length > 0
754
- ? `${projectedLineCount} output lines${native === null ? "" : " and native content"}`
755
- : "native content";
756
- meta.overflow = `${omitted} not shown; logTokensTotal exceeds logTokensMax`;
679
+ if (op === "FIND"
680
+ && patterned
681
+ && range?.unit === "resource"
682
+ && rx !== null
683
+ && typeof rx === "object"
684
+ && typeof rx.matchLocationCount === "number"
685
+ && rx.matchLocationCount > 0) {
686
+ meta.matchLocationCount = rx.matchLocationCount;
757
687
  }
758
- const renderRow = () => {
759
- const metadata = PacketWire.#canonicalJson(meta);
760
- return display === "open"
761
- ? `### ${path}\n${metadata}\n${body}`
762
- : `### ${path}\n${metadata}`;
763
- };
764
- // The accounting field participates in the row it measures. Iterate
765
- // until its decimal width and therefore the rendered row's curation
766
- // weight are stable. {§packet-token-accounting}
767
- // {§packet-attachment-parts}: retained native content shares the row's curation lifetime.
768
- const attachment = e.output_withheld !== true
769
- && !(bodyVisibility.totalLines > 0 && bodyVisibility.fullyFolded)
770
- ? native
771
- : null;
772
- if (attachment !== null)
773
- meta.tokensAttachment = attachment.weight;
774
- meta.logTokens = 0;
775
- for (let pass = 0; pass < 8; pass += 1) {
776
- const logTokens = weighContent(renderRow()) + (attachment?.weight ?? 0);
777
- if (meta.logTokens === logTokens) {
778
- return {
779
- content: renderRow(),
780
- curationTarget: { path, logTokens },
781
- attachment,
782
- unadmittedOutput: (display === "open" || attachment !== null)
783
- && fullBody.provenance === "returned"
784
- && e.output_admission_turn_id == null
785
- && typeof e.id === "number"
786
- ? e.id : null,
787
- newOverflow: outputWithheld && e.newOverflow === true,
788
- };
789
- }
790
- meta.logTokens = logTokens;
688
+ }
689
+ // {§edit-result-receipt-projection} {§edit-result-copy-move-effects}
690
+ // EDIT/scoped entry KILL own one receipt; COPY/MOVE own resource effects whose
691
+ // optional receipts describe scoped textual materializations.
692
+ let structuredMutationReceipt = false;
693
+ if ((op === "EDIT" || op === "KILL") && rx !== null && typeof rx === "object" && Object.hasOwn(rx, "receipt")) {
694
+ Object.assign(meta, PacketWire.#receiptMeta(rx.receipt));
695
+ structuredMutationReceipt = true;
696
+ }
697
+ if ((op === "COPY" || op === "MOVE")
698
+ && rx !== null
699
+ && typeof rx === "object"
700
+ && Object.hasOwn(rx, "effects")) {
701
+ const effects = assertResourceEffects(rx.effects);
702
+ meta.effects = effects.map((effect) => ({
703
+ path: effect.target,
704
+ action: effect.action,
705
+ ...(effect.receipt === undefined
706
+ ? {}
707
+ : PacketWire.#receiptMeta(effect.receipt)),
708
+ }));
709
+ structuredMutationReceipt = effects.some((effect) => effect.receipt !== undefined);
710
+ }
711
+ return { findItems, range, structuredMutationReceipt };
712
+ }
713
+ // The body the row shows: the canonical full body is shared with log READ, log FIND, and
714
+ // search derivation. READ/FIND own selection bounds, NOTE, lifecycle bodies and admitted programs remain
715
+ // complete, and exterior arrivals share their packet allowance. Structured mutation receipts own
716
+ // their join bound; every remaining body uses the ordinary fixed preview.
717
+ static #rowBody(identity, e, fullBody, bodyVisibility, facts, promptProjectionWeight, weighContent) {
718
+ const { meta, op, renderedLeaf } = identity;
719
+ const projectedBody = {
720
+ ...fullBody,
721
+ content: bodyVisibility.fullyFolded ? bodyVisibility.readableContent : bodyVisibility.content,
722
+ };
723
+ const emptyFind = op === "FIND" && e.status === 200 && facts.findItems === 0;
724
+ const previewExempt = op === "READ"
725
+ || op === "FIND"
726
+ || op === "NOTE" || typeof op === "string" && TurnDisposition.isOp(op)
727
+ || (op === null && renderedLeaf === "ops")
728
+ || facts.structuredMutationReceipt;
729
+ const lineAnchors = op === "READ" ? e.lineAnchors ?? null : null;
730
+ const lineNumberWidth = op === "READ" ? e.lineNumberWidth ?? null : null;
731
+ if (lineAnchors !== null) {
732
+ LineAnchors.assertProjection(fullBody.content, lineAnchors);
733
+ }
734
+ const findRange = op === "FIND" ? facts.range : null;
735
+ const bodyStartLine = findRange?.returned?.[0] ?? fullBody.startLine;
736
+ const numericLineNumberWidth = findRange === null
737
+ ? bodyStartLine === null || bodyVisibility.totalLines === 0
738
+ ? 0
739
+ : String(fullBody.lineOrdinals?.at(-1) ?? bodyStartLine + bodyVisibility.totalLines - 1).length
740
+ : String(findRange.total).length;
741
+ const sourceOrdinals = bodyVisibility.fullyFolded
742
+ ? bodyVisibility.readableOrdinals
743
+ : bodyVisibility.ordinals;
744
+ const projection = promptProjectionWeight !== undefined
745
+ ? PacketWire.#promptProjection(projectedBody, promptProjectionWeight, weighContent, (content) => PacketWire.#renderContentBody(content, bodyStartLine, null, null, numericLineNumberWidth, bodyStartLine === null
746
+ ? null
747
+ : sourceOrdinals.slice(0, TextCoordinates.logicalLines(content).length)))
748
+ : previewExempt
749
+ ? { text: projectedBody.content, cut: false, chunk: null }
750
+ : PacketWire.#preview(projectedBody.content);
751
+ const projectedLineCount = TextCoordinates.logicalLines(projection.text).length;
752
+ const projectedOrdinals = sourceOrdinals.slice(0, projectedLineCount);
753
+ const body = emptyFind || projection.text.length === 0
754
+ ? ""
755
+ : PacketWire.#renderContentBody(projection.text, bodyStartLine, lineAnchors, lineNumberWidth, numericLineNumberWidth, bodyStartLine === null ? null : projectedOrdinals, fullBody.lineOrdinals ?? null);
756
+ // lines beside tokens on a non-retrieval row with a navigable body — the count of
757
+ // `N:`-numbered lines (fences and unnumbered prose don't count), so the model can plan
758
+ // a <start,end> slice before paying for a READ. READ/FIND own typed extents instead.
759
+ if (fullBody.content.length > 0 && op !== "READ" && op !== "FIND") {
760
+ meta.lines = bodyVisibility.totalLines;
761
+ }
762
+ if (bodyVisibility.trimmed.length > 0 && !bodyVisibility.fullyFolded) {
763
+ meta.trimmed = LogVisibility.format(bodyVisibility.trimmed);
764
+ }
765
+ const display = bodyVisibility.readableContent.length === 0
766
+ ? "none"
767
+ : bodyVisibility.fullyFolded || e.output_withheld === true
768
+ ? "folded"
769
+ : body.length === 0
770
+ ? "none"
771
+ : "open";
772
+ const projectedChunk = projection.chunk !== null
773
+ && bodyVisibility.folded.length > 0
774
+ && !bodyVisibility.fullyFolded
775
+ ? PacketWire.#sparseChunk(fullBody.content, projectedBody.content, sourceOrdinals, projection.text)
776
+ : projection.chunk;
777
+ if (display === "open" && projectedChunk !== null) {
778
+ meta.preview = projectedChunk;
779
+ delete meta.lines;
780
+ }
781
+ return { body, projectedLineCount, display };
782
+ }
783
+ // The row's native attachment, its withholding receipt, and the accounting field that
784
+ // participates in the row it measures: iterate until its decimal width and therefore the
785
+ // rendered row's curation weight are stable. {§packet-token-accounting}
786
+ static #rowAccounting(identity, e, fullBody, bodyVisibility, projected, weighContent, options) {
787
+ const { meta, op, coordinate, path, target } = identity;
788
+ const { body, projectedLineCount, display } = projected;
789
+ const nativeCandidate = op === "READ" && typeof e.status === "number" && e.status >= 200 && e.status < 300
790
+ ? PacketWire.#attachmentOf(e.rx, e.target, coordinate, target) : null;
791
+ const native = nativeCandidate !== null && (options.acceptedAttachmentKinds?.has(nativeCandidate.kind) ?? true)
792
+ ? nativeCandidate : null;
793
+ const outputWithheld = e.output_withheld === true
794
+ && ((!bodyVisibility.fullyFolded && body.length > 0) || native !== null);
795
+ if (outputWithheld) {
796
+ const omitted = body.length > 0
797
+ ? `${projectedLineCount} output lines${native === null ? "" : " and native content"}`
798
+ : "native content";
799
+ meta.overflow = `${omitted} not shown; the log exceeded logTokensMax when this row was withheld`;
800
+ }
801
+ const renderRow = () => {
802
+ const metadata = PacketWire.#canonicalJson(meta);
803
+ return display === "open"
804
+ ? `### ${path}\n${metadata}\n${body}`
805
+ : `### ${path}\n${metadata}`;
806
+ };
807
+ // {§packet-attachment-parts}: retained native content shares the row's curation lifetime.
808
+ const attachment = e.output_withheld !== true
809
+ && !(bodyVisibility.totalLines > 0 && bodyVisibility.fullyFolded)
810
+ ? native
811
+ : null;
812
+ if (attachment !== null)
813
+ meta.tokensAttachment = attachment.weight;
814
+ meta.logTokens = 0;
815
+ for (let pass = 0; pass < 8; pass += 1) {
816
+ const logTokens = weighContent(renderRow()) + (attachment?.weight ?? 0);
817
+ if (meta.logTokens === logTokens) {
818
+ return {
819
+ content: renderRow(),
820
+ curationTarget: { path, logTokens },
821
+ attachment,
822
+ unadmittedOutput: (display === "open" || attachment !== null)
823
+ && fullBody.provenance === "returned"
824
+ && e.output_admission_turn_id == null
825
+ && typeof e.id === "number"
826
+ ? e.id : null,
827
+ newOverflow: outputWithheld && e.newOverflow === true,
828
+ };
791
829
  }
792
- throw new Error("packet log row accounting did not converge");
793
- });
830
+ meta.logTokens = logTokens;
831
+ }
832
+ throw new Error("packet log row accounting did not converge");
794
833
  }
795
834
  static #attachmentOf(rx, target, coordinate, path) {
796
835
  const view = rx;
@@ -818,6 +857,15 @@ export default class PacketWire {
818
857
  weight: pdfWeight(pages, document.bytes),
819
858
  };
820
859
  }
860
+ const audio = view?.audio;
861
+ if (audio !== undefined && typeof audio.mimetype === "string" && Number.isSafeInteger(audio.bytes)) {
862
+ const duration = typeof audio.duration === "number" && Number.isFinite(audio.duration) && audio.duration >= 0 ? audio.duration : null;
863
+ return {
864
+ contentHash, coordinate, path, scheme, pathname, mimetype: audio.mimetype, kind: "audio",
865
+ ...(duration === null ? {} : { duration }),
866
+ weight: audioWeight(duration, audio.bytes),
867
+ };
868
+ }
821
869
  return null;
822
870
  }
823
871
  // {§packet-attachment-parts} — the wire form with native parts: user text first, then each accepted
@@ -871,10 +919,10 @@ export default class PacketWire {
871
919
  }
872
920
  // {§packet-git-status}: the count line, then one bounded line per non-empty class. Untracked paths are
873
921
  // named because they are NOT members ({§membership-baseline}) — a human `git add`s or picks them.
874
- static #GIT_PATHS_PER_CLASS = 8;
875
922
  static #renderGitState(git) {
876
923
  const sync = git.ahead > 0 || git.behind > 0 ? ` (↑${git.ahead} ↓${git.behind})` : "";
877
- const head = `branch \`${git.branch}\`${sync} — ${git.staged} staged, ${git.unstaged} unstaged, ${git.untracked} untracked`;
924
+ const position = git.branch === null ? "detached HEAD" : `branch \`${git.branch}\`${git.unborn ? " (no commits)" : ""}`;
925
+ const head = `${position}${sync} — ${git.staged} staged, ${git.unstaged} unstaged, ${git.untracked} untracked`;
878
926
  const files = git.files ?? [];
879
927
  const path = (p) => `\`${p}\``;
880
928
  const untracked = files.filter((f) => f.status === "??");
@@ -888,8 +936,9 @@ export default class PacketWire {
888
936
  const lines = classes
889
937
  .filter(([, items]) => items.length > 0)
890
938
  .map(([label, items]) => {
891
- const shown = items.slice(0, PacketWire.#GIT_PATHS_PER_CLASS).join(" · ");
892
- const more = items.length > PacketWire.#GIT_PATHS_PER_CLASS ? ` (+${items.length - PacketWire.#GIT_PATHS_PER_CLASS} more)` : "";
939
+ const paths = GitState.renderedPaths();
940
+ const shown = items.slice(0, paths).join(" · ");
941
+ const more = items.length > paths ? ` (+${items.length - paths} more)` : "";
893
942
  return `${label}: ${shown}${more}`;
894
943
  });
895
944
  return [head, ...lines].join("\n");