@abot-ai/runtime 1.2.0 → 1.3.1

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 (550) hide show
  1. package/README.md +14 -0
  2. package/dist/scripts/init-runtime.js +4 -13
  3. package/dist/scripts/runtime-setup-directories.d.ts +2 -0
  4. package/dist/scripts/runtime-setup-directories.js +38 -0
  5. package/dist/src/bridge/request-steering.d.ts +2 -1
  6. package/dist/src/bridge/request-steering.js +4 -2
  7. package/dist/src/bridge/runtime-replay.js +2 -19
  8. package/dist/src/bridge/start-agent-bridge.js +1 -1
  9. package/dist/src/capabilities/normal-invocation/validator.js +1 -1
  10. package/dist/src/capabilities/tool-definition-validator/event-presentation.js +3 -0
  11. package/dist/src/capabilities/tool-definition-validator/event-result-metadata.d.ts +2 -0
  12. package/dist/src/capabilities/tool-definition-validator/event-result-metadata.js +74 -0
  13. package/dist/src/capabilities/tool-event-metadata.js +3 -0
  14. package/dist/src/capabilities/tool-result-event-projection.d.ts +3 -0
  15. package/dist/src/capabilities/tool-result-event-projection.js +82 -0
  16. package/dist/src/capabilities/tool-types.d.ts +5 -0
  17. package/dist/src/cli/abot.js +2 -11
  18. package/dist/src/runtime/adapters/in-memory-session-store.js +1 -0
  19. package/dist/src/runtime/adapters/long-term-memory/file-lock/acquisition.js +11 -2
  20. package/dist/src/runtime/adapters/long-term-memory/file-lock/contracts.d.ts +2 -0
  21. package/dist/src/runtime/adapters/long-term-memory/file-lock/synchronous-release.d.ts +2 -0
  22. package/dist/src/runtime/adapters/long-term-memory/file-lock/synchronous-release.js +40 -0
  23. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/approval.d.ts +3 -0
  24. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/approval.js +9 -0
  25. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/rejection-event.d.ts +13 -0
  26. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/rejection-event.js +25 -0
  27. package/dist/src/runtime/adapters/registered-tool-normal-invocations/execution/run.js +18 -2
  28. package/dist/src/runtime/adapters/registered-tool-normal-invocations/executor.js +8 -0
  29. package/dist/src/runtime/adapters/registered-tool-normal-invocations/payload/lifecycle.js +7 -3
  30. package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/contracts.d.ts +17 -2
  31. package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/event-metadata.d.ts +9 -0
  32. package/dist/src/runtime/adapters/registered-tool-normal-invocations/shared/event-metadata.js +8 -0
  33. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.js +16 -1
  34. package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-observability.js +2 -2
  35. package/dist/src/runtime/adapters/scheduled-request-outcome.d.ts +11 -0
  36. package/dist/src/runtime/adapters/scheduled-request-outcome.js +41 -0
  37. package/dist/src/runtime/adapters/scheduler-runtime.d.ts +19 -0
  38. package/dist/src/runtime/adapters/scheduler-runtime.js +138 -0
  39. package/dist/src/runtime/capabilities/scheduling/create-operations.d.ts +55 -0
  40. package/dist/src/runtime/capabilities/scheduling/create-operations.js +30 -0
  41. package/dist/src/runtime/capabilities/scheduling/create-time-zone.d.ts +1 -0
  42. package/dist/src/runtime/capabilities/scheduling/create-time-zone.js +11 -0
  43. package/dist/src/runtime/capabilities/scheduling/job-list-page.d.ts +25 -0
  44. package/dist/src/runtime/capabilities/scheduling/job-list-page.js +40 -0
  45. package/dist/src/runtime/capabilities/scheduling/model-validation.d.ts +2 -0
  46. package/dist/src/runtime/capabilities/scheduling/model-validation.js +15 -0
  47. package/dist/src/runtime/capabilities/scheduling/tool-contract.d.ts +2 -0
  48. package/dist/src/runtime/capabilities/scheduling/tool-contract.js +35 -0
  49. package/dist/src/runtime/capabilities/scheduling/tool-input-properties.d.ts +43 -0
  50. package/dist/src/runtime/capabilities/scheduling/tool-input-properties.js +27 -0
  51. package/dist/src/runtime/capabilities/scheduling/tool-module.d.ts +4 -0
  52. package/dist/src/runtime/capabilities/scheduling/tool-module.js +158 -0
  53. package/dist/src/runtime/capabilities/scheduling/update-operations.d.ts +2 -0
  54. package/dist/src/runtime/capabilities/scheduling/update-operations.js +49 -0
  55. package/dist/src/runtime/composition.d.ts +23 -3
  56. package/dist/src/runtime/composition.js +12 -17
  57. package/dist/src/runtime/config/environment-paths.d.ts +10 -0
  58. package/dist/src/runtime/config/environment-paths.js +31 -0
  59. package/dist/src/runtime/config/environment-storage.d.ts +9 -0
  60. package/dist/src/runtime/config/environment-storage.js +65 -0
  61. package/dist/src/runtime/config/fields.js +7 -0
  62. package/dist/src/runtime/config/long-term-memory.js +15 -0
  63. package/dist/src/runtime/config/schema.js +8 -0
  64. package/dist/src/runtime/config.js +9 -5
  65. package/dist/src/runtime/context/scheduled-execution-context.d.ts +10 -0
  66. package/dist/src/runtime/context/scheduled-execution-context.js +52 -0
  67. package/dist/src/runtime/default-adapters.d.ts +3 -32
  68. package/dist/src/runtime/default-adapters.js +3 -270
  69. package/dist/src/runtime/default-environment-adapters.d.ts +19 -0
  70. package/dist/src/runtime/default-environment-adapters.js +144 -0
  71. package/dist/src/runtime/index.d.ts +5 -0
  72. package/dist/src/runtime/index.js +4 -0
  73. package/dist/src/runtime/local-application.d.ts +22 -0
  74. package/dist/src/runtime/local-application.js +81 -0
  75. package/dist/src/runtime/local-host/app-memory-dispatch.d.ts +11 -0
  76. package/dist/src/runtime/local-host/app-memory-dispatch.js +103 -0
  77. package/dist/src/runtime/local-host/app-owner.d.ts +4 -0
  78. package/dist/src/runtime/local-host/app-owner.js +119 -0
  79. package/dist/src/runtime/local-host/app-request-control.d.ts +24 -0
  80. package/dist/src/runtime/local-host/app-request-control.js +135 -0
  81. package/dist/src/runtime/local-host/app-service-dispatch.d.ts +5 -0
  82. package/dist/src/runtime/local-host/app-service-dispatch.js +64 -0
  83. package/dist/src/runtime/local-host/client-identity.d.ts +3 -0
  84. package/dist/src/runtime/local-host/client-identity.js +17 -0
  85. package/dist/src/runtime/local-host/client-memory.d.ts +7 -0
  86. package/dist/src/runtime/local-host/client-memory.js +54 -0
  87. package/dist/src/runtime/local-host/client-requests.d.ts +19 -0
  88. package/dist/src/runtime/local-host/client-requests.js +145 -0
  89. package/dist/src/runtime/local-host/client-services.d.ts +10 -0
  90. package/dist/src/runtime/local-host/client-services.js +14 -0
  91. package/dist/src/runtime/local-host/contracts.d.ts +36 -0
  92. package/dist/src/runtime/local-host/contracts.js +1 -0
  93. package/dist/src/runtime/local-host/endpoint.d.ts +7 -0
  94. package/dist/src/runtime/local-host/endpoint.js +79 -0
  95. package/dist/src/runtime/local-host/owner-activity.d.ts +10 -0
  96. package/dist/src/runtime/local-host/owner-activity.js +30 -0
  97. package/dist/src/runtime/local-host/owner-retirement.d.ts +3 -0
  98. package/dist/src/runtime/local-host/owner-retirement.js +15 -0
  99. package/dist/src/runtime/local-host/owner-server.d.ts +6 -0
  100. package/dist/src/runtime/local-host/owner-server.js +88 -0
  101. package/dist/src/runtime/local-host/private-access.d.ts +2 -0
  102. package/dist/src/runtime/local-host/private-access.js +16 -0
  103. package/dist/src/runtime/local-host/private-directory.d.ts +1 -0
  104. package/dist/src/runtime/local-host/private-directory.js +57 -0
  105. package/dist/src/runtime/local-host/rpc-peer.d.ts +22 -0
  106. package/dist/src/runtime/local-host/rpc-peer.js +168 -0
  107. package/dist/src/runtime/local-host/rpc-protocol.d.ts +21 -0
  108. package/dist/src/runtime/local-host/rpc-protocol.js +46 -0
  109. package/dist/src/runtime/local-host/startup-connection.d.ts +5 -0
  110. package/dist/src/runtime/local-host/startup-connection.js +72 -0
  111. package/dist/src/runtime/local-host/transport.d.ts +3 -0
  112. package/dist/src/runtime/local-host/transport.js +88 -0
  113. package/dist/src/runtime/local-host/windows-private-access.d.ts +1 -0
  114. package/dist/src/runtime/local-host/windows-private-access.js +51 -0
  115. package/dist/src/runtime/long-term-memory/onboarding/configuration.js +6 -0
  116. package/dist/src/runtime/long-term-memory/recall-binding.d.ts +3 -0
  117. package/dist/src/runtime/long-term-memory/recall-binding.js +27 -0
  118. package/dist/src/runtime/long-term-memory/recall-context.d.ts +20 -0
  119. package/dist/src/runtime/long-term-memory/recall-context.js +101 -0
  120. package/dist/src/runtime/long-term-memory/recall-continuation.d.ts +8 -0
  121. package/dist/src/runtime/long-term-memory/recall-continuation.js +36 -0
  122. package/dist/src/runtime/long-term-memory/recall-policy.d.ts +7 -0
  123. package/dist/src/runtime/long-term-memory/recall-policy.js +14 -0
  124. package/dist/src/runtime/long-term-memory/recall-result.d.ts +5 -0
  125. package/dist/src/runtime/long-term-memory/recall-result.js +54 -0
  126. package/dist/src/runtime/long-term-memory/repository-state.d.ts +2 -1
  127. package/dist/src/runtime/long-term-memory/repository-state.js +2 -2
  128. package/dist/src/runtime/model/invoke-raw-step.d.ts +1 -0
  129. package/dist/src/runtime/model/invoke-raw-step.js +1 -0
  130. package/dist/src/runtime/model/invoke-step.js +6 -0
  131. package/dist/src/runtime/model/invoke-structured-step.d.ts +1 -0
  132. package/dist/src/runtime/model/invoke-structured-step.js +1 -0
  133. package/dist/src/runtime/model/model-step-port.d.ts +2 -0
  134. package/dist/src/runtime/model/model-step-steering.d.ts +8 -0
  135. package/dist/src/runtime/model/model-step-steering.js +19 -0
  136. package/dist/src/runtime/orchestration/final-response/authoring-contract.js +1 -1
  137. package/dist/src/runtime/orchestration/final-response/invoke.d.ts +1 -0
  138. package/dist/src/runtime/orchestration/final-response/invoke.js +1 -0
  139. package/dist/src/runtime/orchestration/role-calls/activation-budget.js +1 -0
  140. package/dist/src/runtime/orchestration/role-calls/candidate-validation.js +9 -49
  141. package/dist/src/runtime/orchestration/role-calls/capability-selection-reconsideration.d.ts +9 -0
  142. package/dist/src/runtime/orchestration/role-calls/capability-selection-reconsideration.js +17 -8
  143. package/dist/src/runtime/orchestration/role-calls/capability-selection-supervision-validation.d.ts +2 -0
  144. package/dist/src/runtime/orchestration/role-calls/capability-selection-supervision-validation.js +62 -0
  145. package/dist/src/runtime/orchestration/role-calls/command-decoder.js +4 -0
  146. package/dist/src/runtime/orchestration/role-calls/command-dispatch/memory-recall-transitions.d.ts +4 -0
  147. package/dist/src/runtime/orchestration/role-calls/command-dispatch/memory-recall-transitions.js +89 -0
  148. package/dist/src/runtime/orchestration/role-calls/command-dispatch.js +5 -0
  149. package/dist/src/runtime/orchestration/role-calls/contracts.d.ts +9 -7
  150. package/dist/src/runtime/orchestration/role-calls/contracts.js +2 -2
  151. package/dist/src/runtime/orchestration/role-calls/diagnostics.js +3 -0
  152. package/dist/src/runtime/orchestration/role-calls/index.d.ts +1 -0
  153. package/dist/src/runtime/orchestration/role-calls/index.js +1 -0
  154. package/dist/src/runtime/orchestration/role-calls/memory-recall-contract.d.ts +51 -0
  155. package/dist/src/runtime/orchestration/role-calls/memory-recall-contract.js +4 -0
  156. package/dist/src/runtime/orchestration/role-calls/memory-recall-decoder.d.ts +6 -0
  157. package/dist/src/runtime/orchestration/role-calls/memory-recall-decoder.js +147 -0
  158. package/dist/src/runtime/orchestration/role-calls/memory-recall-diagnostics.d.ts +5 -0
  159. package/dist/src/runtime/orchestration/role-calls/memory-recall-diagnostics.js +27 -0
  160. package/dist/src/runtime/orchestration/role-calls/memory-recall-state-validation.d.ts +3 -0
  161. package/dist/src/runtime/orchestration/role-calls/memory-recall-state-validation.js +121 -0
  162. package/dist/src/runtime/orchestration/role-calls/memory-recall-transactions.d.ts +3 -0
  163. package/dist/src/runtime/orchestration/role-calls/memory-recall-transactions.js +44 -0
  164. package/dist/src/runtime/orchestration/role-calls/reducer.js +1 -0
  165. package/dist/src/runtime/orchestration/role-calls/transaction-effect.d.ts +5 -0
  166. package/dist/src/runtime/orchestration/role-calls/transaction-effect.js +14 -0
  167. package/dist/src/runtime/orchestration/role-calls/transactions.js +3 -24
  168. package/dist/src/runtime/plugins/manifest-validator.js +4 -1
  169. package/dist/src/runtime/ports.d.ts +4 -0
  170. package/dist/src/runtime/request/bound-runtime-handler.d.ts +2 -0
  171. package/dist/src/runtime/request/bound-runtime-handler.js +25 -0
  172. package/dist/src/runtime/request/contracts.d.ts +6 -0
  173. package/dist/src/runtime/request/execution-agent-root-execution.js +12 -0
  174. package/dist/src/runtime/request/execution-facets.js +6 -0
  175. package/dist/src/runtime/request/execution-scope-surfaces.js +10 -0
  176. package/dist/src/runtime/request/execution-scope.d.ts +1 -1
  177. package/dist/src/runtime/request/handler.js +6 -0
  178. package/dist/src/runtime/request/root-contract.d.ts +7 -1
  179. package/dist/src/runtime/request/root-execution-kernel.js +33 -37
  180. package/dist/src/runtime/request/root-memory-recall.d.ts +11 -0
  181. package/dist/src/runtime/request/root-memory-recall.js +71 -0
  182. package/dist/src/runtime/request/root-observation-handoff.d.ts +17 -0
  183. package/dist/src/runtime/request/root-observation-handoff.js +44 -0
  184. package/dist/src/runtime/request/scheduled-execution.d.ts +9 -0
  185. package/dist/src/runtime/request/scheduled-execution.js +32 -0
  186. package/dist/src/runtime/request/session-admission.d.ts +17 -0
  187. package/dist/src/runtime/request/session-admission.js +88 -0
  188. package/dist/src/runtime/request/supervisor-root-execution-diagnostics.d.ts +1 -1
  189. package/dist/src/runtime/request/supervisor-root-execution.js +8 -0
  190. package/dist/src/runtime/runtime-environment.d.ts +31 -0
  191. package/dist/src/runtime/runtime-environment.js +102 -0
  192. package/dist/src/runtime/runtime-host-environment.d.ts +8 -0
  193. package/dist/src/runtime/runtime-host-environment.js +57 -0
  194. package/dist/src/runtime/runtime-host-lifecycle.d.ts +4 -0
  195. package/dist/src/runtime/runtime-host-lifecycle.js +64 -0
  196. package/dist/src/runtime/runtime-host-scheduler-ownership.d.ts +5 -0
  197. package/dist/src/runtime/runtime-host-scheduler-ownership.js +67 -0
  198. package/dist/src/runtime/runtime-host.d.ts +19 -0
  199. package/dist/src/runtime/runtime-host.js +63 -0
  200. package/dist/src/runtime/scheduler/calendar-time.d.ts +10 -0
  201. package/dist/src/runtime/scheduler/calendar-time.js +58 -0
  202. package/dist/src/runtime/scheduler/contracts.d.ts +143 -0
  203. package/dist/src/runtime/scheduler/contracts.js +1 -0
  204. package/dist/src/runtime/scheduler/file-store.d.ts +2 -0
  205. package/dist/src/runtime/scheduler/file-store.js +76 -0
  206. package/dist/src/runtime/scheduler/instant-validation.d.ts +4 -0
  207. package/dist/src/runtime/scheduler/instant-validation.js +69 -0
  208. package/dist/src/runtime/scheduler/interval-range.d.ts +8 -0
  209. package/dist/src/runtime/scheduler/interval-range.js +24 -0
  210. package/dist/src/runtime/scheduler/job-management.d.ts +8 -0
  211. package/dist/src/runtime/scheduler/job-management.js +212 -0
  212. package/dist/src/runtime/scheduler/journal-checkpoint.d.ts +9 -0
  213. package/dist/src/runtime/scheduler/journal-checkpoint.js +45 -0
  214. package/dist/src/runtime/scheduler/journal-durability.d.ts +8 -0
  215. package/dist/src/runtime/scheduler/journal-durability.js +59 -0
  216. package/dist/src/runtime/scheduler/journal-files.d.ts +14 -0
  217. package/dist/src/runtime/scheduler/journal-files.js +59 -0
  218. package/dist/src/runtime/scheduler/journal-head.d.ts +21 -0
  219. package/dist/src/runtime/scheduler/journal-head.js +81 -0
  220. package/dist/src/runtime/scheduler/journal-index-state.d.ts +31 -0
  221. package/dist/src/runtime/scheduler/journal-index-state.js +137 -0
  222. package/dist/src/runtime/scheduler/journal-index.d.ts +22 -0
  223. package/dist/src/runtime/scheduler/journal-index.js +195 -0
  224. package/dist/src/runtime/scheduler/journal-store.d.ts +21 -0
  225. package/dist/src/runtime/scheduler/journal-store.js +184 -0
  226. package/dist/src/runtime/scheduler/journal-transaction.d.ts +14 -0
  227. package/dist/src/runtime/scheduler/journal-transaction.js +104 -0
  228. package/dist/src/runtime/scheduler/next-occurrence.d.ts +3 -0
  229. package/dist/src/runtime/scheduler/next-occurrence.js +39 -0
  230. package/dist/src/runtime/scheduler/run-completion.d.ts +12 -0
  231. package/dist/src/runtime/scheduler/run-completion.js +77 -0
  232. package/dist/src/runtime/scheduler/run-list-query.d.ts +5 -0
  233. package/dist/src/runtime/scheduler/run-list-query.js +38 -0
  234. package/dist/src/runtime/scheduler/run-records.d.ts +6 -0
  235. package/dist/src/runtime/scheduler/run-records.js +41 -0
  236. package/dist/src/runtime/scheduler/schedule-update.d.ts +3 -0
  237. package/dist/src/runtime/scheduler/schedule-update.js +22 -0
  238. package/dist/src/runtime/scheduler/schedule-validation.d.ts +10 -0
  239. package/dist/src/runtime/scheduler/schedule-validation.js +132 -0
  240. package/dist/src/runtime/scheduler/scheduler-engine.d.ts +2 -0
  241. package/dist/src/runtime/scheduler/scheduler-engine.js +174 -0
  242. package/dist/src/runtime/scheduler/scheduler-service.d.ts +10 -0
  243. package/dist/src/runtime/scheduler/scheduler-service.js +115 -0
  244. package/dist/src/runtime/scheduler/service-context.d.ts +21 -0
  245. package/dist/src/runtime/scheduler/service-context.js +26 -0
  246. package/dist/src/runtime/scheduler/session-deletion-state.d.ts +9 -0
  247. package/dist/src/runtime/scheduler/session-deletion-state.js +30 -0
  248. package/dist/src/runtime/scheduler/snapshot-validation.d.ts +4 -0
  249. package/dist/src/runtime/scheduler/snapshot-validation.js +112 -0
  250. package/dist/src/runtime/scheduler/startup-recovery.d.ts +2 -0
  251. package/dist/src/runtime/scheduler/startup-recovery.js +38 -0
  252. package/dist/src/runtime/scheduler/validation-error.d.ts +4 -0
  253. package/dist/src/runtime/scheduler/validation-error.js +8 -0
  254. package/dist/src/runtime/scheduler/working-store.d.ts +3 -0
  255. package/dist/src/runtime/scheduler/working-store.js +8 -0
  256. package/dist/src/runtime/session/request-session.d.ts +1 -0
  257. package/dist/src/runtime/session/request-session.js +14 -1
  258. package/dist/src/runtime/session/session-attachment-deletion.d.ts +8 -0
  259. package/dist/src/runtime/session/session-attachment-deletion.js +87 -0
  260. package/dist/src/runtime/session/session-deletion-boundary.d.ts +10 -0
  261. package/dist/src/runtime/session/session-deletion-boundary.js +39 -0
  262. package/dist/src/runtime/session/session-deletion-cleanup.d.ts +7 -0
  263. package/dist/src/runtime/session/session-deletion-cleanup.js +62 -0
  264. package/dist/src/runtime/session/session-deletion-finalization.d.ts +7 -0
  265. package/dist/src/runtime/session/session-deletion-finalization.js +34 -0
  266. package/dist/src/runtime/session/session-deletion-receipts.d.ts +7 -0
  267. package/dist/src/runtime/session/session-deletion-receipts.js +18 -0
  268. package/dist/src/runtime/session/session-lifecycle-store.d.ts +21 -0
  269. package/dist/src/runtime/session/session-lifecycle-store.js +72 -0
  270. package/dist/src/runtime/session/session-mutation-queue.d.ts +3 -0
  271. package/dist/src/runtime/session/session-mutation-queue.js +15 -0
  272. package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.d.ts +16 -0
  273. package/dist/src/runtime/steps/execution-agent/capability-decision-parsing.js +165 -0
  274. package/dist/src/runtime/steps/execution-agent/contracts.d.ts +3 -1
  275. package/dist/src/runtime/steps/execution-agent/decision-parsing.d.ts +2 -0
  276. package/dist/src/runtime/steps/execution-agent/decision-parsing.js +195 -0
  277. package/dist/src/runtime/steps/execution-agent/decision-validation.d.ts +30 -0
  278. package/dist/src/runtime/steps/execution-agent/decision-validation.js +127 -0
  279. package/dist/src/runtime/steps/execution-agent/format.d.ts +1 -0
  280. package/dist/src/runtime/steps/execution-agent/format.js +12 -0
  281. package/dist/src/runtime/steps/execution-agent/input.d.ts +2 -1
  282. package/dist/src/runtime/steps/execution-agent/input.js +17 -2
  283. package/dist/src/runtime/steps/execution-agent/parser.d.ts +1 -2
  284. package/dist/src/runtime/steps/execution-agent/parser.js +1 -472
  285. package/dist/src/runtime/steps/execution-agent/prompt.d.ts +2 -0
  286. package/dist/src/runtime/steps/execution-agent/prompt.js +2 -0
  287. package/dist/src/runtime/steps/execution-agent/reconsideration-context.js +4 -3
  288. package/dist/src/runtime/steps/execution-agent/response-input.js +5 -4
  289. package/dist/src/runtime/steps/execution-agent/response-run.d.ts +3 -0
  290. package/dist/src/runtime/steps/execution-agent/response-run.js +7 -3
  291. package/dist/src/runtime/steps/execution-agent/run.d.ts +2 -0
  292. package/dist/src/runtime/steps/execution-agent/run.js +2 -0
  293. package/dist/src/runtime/steps/execution-agent/state-context.d.ts +2 -1
  294. package/dist/src/runtime/steps/execution-agent/state-context.js +13 -5
  295. package/dist/src/runtime/steps/memory-recall-decision.d.ts +30 -0
  296. package/dist/src/runtime/steps/memory-recall-decision.js +101 -0
  297. package/dist/src/runtime/steps/memory-recall-prompt.d.ts +1 -0
  298. package/dist/src/runtime/steps/memory-recall-prompt.js +15 -0
  299. package/dist/src/runtime/steps/supervisor-decision/contracts.d.ts +4 -2
  300. package/dist/src/runtime/steps/supervisor-decision/diagnostics.d.ts +2 -0
  301. package/dist/src/runtime/steps/supervisor-decision/diagnostics.js +13 -6
  302. package/dist/src/runtime/steps/supervisor-decision/format.d.ts +2 -0
  303. package/dist/src/runtime/steps/supervisor-decision/format.js +41 -2
  304. package/dist/src/runtime/steps/supervisor-decision/input.d.ts +5 -1
  305. package/dist/src/runtime/steps/supervisor-decision/input.js +25 -5
  306. package/dist/src/runtime/steps/supervisor-decision/memory-recall-continuation.d.ts +10 -0
  307. package/dist/src/runtime/steps/supervisor-decision/memory-recall-continuation.js +32 -0
  308. package/dist/src/runtime/steps/supervisor-decision/parser.d.ts +2 -0
  309. package/dist/src/runtime/steps/supervisor-decision/parser.js +36 -1
  310. package/dist/src/runtime/steps/supervisor-decision/prompt.d.ts +3 -0
  311. package/dist/src/runtime/steps/supervisor-decision/prompt.js +16 -8
  312. package/dist/src/runtime/steps/supervisor-decision/response-recommendation.d.ts +13 -0
  313. package/dist/src/runtime/steps/supervisor-decision/response-recommendation.js +32 -0
  314. package/dist/src/runtime/steps/supervisor-decision/resume.d.ts +2 -0
  315. package/dist/src/runtime/steps/supervisor-decision/resume.js +13 -0
  316. package/dist/src/runtime/steps/supervisor-decision/run.d.ts +3 -0
  317. package/dist/src/runtime/steps/supervisor-decision/run.js +19 -0
  318. package/dist/src/runtime/steps/supervisor-decision/working-directory.js +7 -1
  319. package/dist/src/runtime/steps/supervisor-response/diagnostics.d.ts +1 -0
  320. package/dist/src/runtime/steps/supervisor-response/diagnostics.js +1 -0
  321. package/dist/src/runtime/steps/supervisor-response/input.d.ts +2 -1
  322. package/dist/src/runtime/steps/supervisor-response/input.js +17 -4
  323. package/dist/src/runtime/steps/supervisor-response/memory-authoring.d.ts +1 -0
  324. package/dist/src/runtime/steps/supervisor-response/memory-authoring.js +4 -0
  325. package/dist/src/runtime/steps/supervisor-response/prompt.d.ts +1 -0
  326. package/dist/src/runtime/steps/supervisor-response/prompt.js +8 -2
  327. package/dist/src/runtime/steps/supervisor-response/response-recommendation.d.ts +10 -0
  328. package/dist/src/runtime/steps/supervisor-response/response-recommendation.js +25 -0
  329. package/dist/src/runtime/steps/supervisor-response/run.d.ts +6 -1
  330. package/dist/src/runtime/steps/supervisor-response/run.js +26 -7
  331. package/dist/src/sessions/record/projection.js +1 -0
  332. package/dist/src/sessions/schedule-metadata.d.ts +8 -0
  333. package/dist/src/sessions/schedule-metadata.js +1 -0
  334. package/dist/src/sessions/session-service.d.ts +1 -0
  335. package/dist/src/sessions/session-service.js +1 -0
  336. package/dist/src/sessions/types.d.ts +2 -0
  337. package/dist/src/shared/directory-authority/bootstrap.d.ts +1 -0
  338. package/dist/src/shared/directory-authority/bootstrap.js +118 -0
  339. package/dist/src/shared/directory-authority/command.d.ts +8 -0
  340. package/dist/src/shared/directory-authority/command.js +27 -0
  341. package/dist/src/shared/directory-authority/errors.d.ts +5 -0
  342. package/dist/src/shared/directory-authority/errors.js +10 -0
  343. package/dist/src/shared/directory-authority/index.d.ts +3 -0
  344. package/dist/src/shared/directory-authority/index.js +3 -0
  345. package/dist/src/shared/directory-authority/protocol.d.ts +11 -0
  346. package/dist/src/shared/directory-authority/protocol.js +62 -0
  347. package/dist/src/shared/directory-authority/task.d.ts +7 -0
  348. package/dist/src/shared/directory-authority/task.js +97 -0
  349. package/dist/src/shared/http-server-shutdown.d.ts +4 -0
  350. package/dist/src/shared/http-server-shutdown.js +17 -0
  351. package/dist/src/shared/public-http/aggregate-gate.d.ts +3 -0
  352. package/dist/src/shared/public-http/aggregate-gate.js +87 -0
  353. package/dist/src/shared/public-http/deadline.d.ts +2 -0
  354. package/dist/src/shared/public-http/deadline.js +29 -0
  355. package/dist/src/shared/public-http/errors.d.ts +6 -0
  356. package/dist/src/shared/public-http/errors.js +11 -0
  357. package/dist/src/shared/public-http/limits.d.ts +8 -0
  358. package/dist/src/shared/public-http/limits.js +8 -0
  359. package/dist/src/shared/public-http/network-policy.d.ts +11 -0
  360. package/dist/src/shared/public-http/network-policy.js +178 -0
  361. package/dist/src/shared/public-http/public-http.d.ts +24 -0
  362. package/dist/src/shared/public-http/public-http.js +85 -0
  363. package/dist/src/shared/public-http/request-hop.d.ts +18 -0
  364. package/dist/src/shared/public-http/request-hop.js +140 -0
  365. package/dist/src/web-ui/app/ARCHITECTURE.md +66 -4
  366. package/dist/src/web-ui/app/app-bootstrap.js +53 -0
  367. package/dist/src/web-ui/app/app-dom.js +80 -0
  368. package/dist/src/web-ui/app/app.js +195 -212
  369. package/dist/src/web-ui/app/components/conversation-activity.d.ts +2 -0
  370. package/dist/src/web-ui/app/components/conversation-activity.js +34 -7
  371. package/dist/src/web-ui/app/components/conversation-role-cards.d.ts +1 -0
  372. package/dist/src/web-ui/app/components/conversation-role-cards.js +61 -5
  373. package/dist/src/web-ui/app/components/conversation-schedule.js +71 -0
  374. package/dist/src/web-ui/app/components/conversation-status.js +65 -0
  375. package/dist/src/web-ui/app/components/conversation-tools.d.ts +13 -0
  376. package/dist/src/web-ui/app/components/conversation-tools.js +284 -0
  377. package/dist/src/web-ui/app/components/conversation-view.js +39 -11
  378. package/dist/src/web-ui/app/components/dashboard/activity.js +61 -0
  379. package/dist/src/web-ui/app/components/dashboard/icons.js +23 -0
  380. package/dist/src/web-ui/app/components/dashboard/recent-conversations.js +64 -0
  381. package/dist/src/web-ui/app/components/dashboard/workspace.js +107 -0
  382. package/dist/src/web-ui/app/components/message-link-previews.d.ts +16 -0
  383. package/dist/src/web-ui/app/components/message-link-previews.js +179 -0
  384. package/dist/src/web-ui/app/components/schedules/details.js +101 -0
  385. package/dist/src/web-ui/app/components/schedules/form.d.ts +13 -0
  386. package/dist/src/web-ui/app/components/schedules/form.js +246 -0
  387. package/dist/src/web-ui/app/components/schedules/workspace-state.js +59 -0
  388. package/dist/src/web-ui/app/components/schedules/workspace.js +165 -0
  389. package/dist/src/web-ui/app/components/workspace-shell.js +48 -2
  390. package/dist/src/web-ui/app/configuration-feature.js +72 -0
  391. package/dist/src/web-ui/app/controllers/composer-attachments-controller.d.ts +1 -0
  392. package/dist/src/web-ui/app/controllers/composer-attachments-controller.js +17 -6
  393. package/dist/src/web-ui/app/controllers/composer-submit-controller.d.ts +2 -0
  394. package/dist/src/web-ui/app/controllers/composer-submit-controller.js +15 -1
  395. package/dist/src/web-ui/app/controllers/composer-surface-controller.js +58 -0
  396. package/dist/src/web-ui/app/controllers/composer-workspace-controller.d.ts +53 -0
  397. package/dist/src/web-ui/app/controllers/composer-workspace-controller.js +180 -0
  398. package/dist/src/web-ui/app/controllers/conversation-read-state-controller.d.ts +23 -0
  399. package/dist/src/web-ui/app/controllers/conversation-read-state-controller.js +82 -0
  400. package/dist/src/web-ui/app/controllers/conversation-session-controller.d.ts +8 -0
  401. package/dist/src/web-ui/app/controllers/conversation-session-controller.js +28 -39
  402. package/dist/src/web-ui/app/controllers/dashboard-controller.js +127 -0
  403. package/dist/src/web-ui/app/controllers/home-composer-feature.d.ts +40 -0
  404. package/dist/src/web-ui/app/controllers/home-composer-feature.js +119 -0
  405. package/dist/src/web-ui/app/controllers/home-conversation-activation.js +37 -0
  406. package/dist/src/web-ui/app/controllers/realtime-event-controller.d.ts +1 -0
  407. package/dist/src/web-ui/app/controllers/realtime-event-controller.js +74 -3
  408. package/dist/src/web-ui/app/controllers/runtime-selection-controller.d.ts +2 -1
  409. package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +15 -14
  410. package/dist/src/web-ui/app/controllers/schedule-realtime.js +118 -0
  411. package/dist/src/web-ui/app/controllers/schedules-controller.js +421 -0
  412. package/dist/src/web-ui/app/controllers/session-controller.js +30 -3
  413. package/dist/src/web-ui/app/dashboard-feature.js +44 -0
  414. package/dist/src/web-ui/app/index.html +53 -1
  415. package/dist/src/web-ui/app/lib/composer-submission-scope.d.ts +21 -0
  416. package/dist/src/web-ui/app/lib/composer-submission-scope.js +13 -0
  417. package/dist/src/web-ui/app/lib/context-window-snapshot-order.d.ts +15 -0
  418. package/dist/src/web-ui/app/lib/context-window-snapshot-order.js +31 -0
  419. package/dist/src/web-ui/app/lib/conversation-role-model.d.ts +10 -1
  420. package/dist/src/web-ui/app/lib/conversation-role-model.js +97 -15
  421. package/dist/src/web-ui/app/lib/conversation-status-model.d.ts +12 -0
  422. package/dist/src/web-ui/app/lib/conversation-status-model.js +116 -0
  423. package/dist/src/web-ui/app/lib/dashboard-job-templates.js +41 -0
  424. package/dist/src/web-ui/app/lib/dashboard-presentation.js +126 -0
  425. package/dist/src/web-ui/app/lib/message-markdown.d.ts +5 -0
  426. package/dist/src/web-ui/app/lib/message-markdown.js +99 -0
  427. package/dist/src/web-ui/app/lib/message-url-policy.d.ts +1 -0
  428. package/dist/src/web-ui/app/lib/message-url-policy.js +13 -0
  429. package/dist/src/web-ui/app/lib/schedule-errors.js +29 -0
  430. package/dist/src/web-ui/app/lib/schedule-message.js +30 -0
  431. package/dist/src/web-ui/app/lib/schedule-presentation.js +81 -0
  432. package/dist/src/web-ui/app/lib/session-read-state.d.ts +22 -0
  433. package/dist/src/web-ui/app/lib/session-read-state.js +63 -0
  434. package/dist/src/web-ui/app/lib/text-format.js +2 -143
  435. package/dist/src/web-ui/app/lib/tool-activity-event.d.ts +26 -0
  436. package/dist/src/web-ui/app/lib/tool-activity-event.js +228 -0
  437. package/dist/src/web-ui/app/lib/tool-activity-model.d.ts +41 -0
  438. package/dist/src/web-ui/app/lib/tool-activity-model.js +255 -0
  439. package/dist/src/web-ui/app/lib/tool-timeline.d.ts +3 -0
  440. package/dist/src/web-ui/app/lib/tool-timeline.js +18 -0
  441. package/dist/src/web-ui/app/schedules-feature.js +87 -0
  442. package/dist/src/web-ui/app/services/message-link-preview-client.d.ts +14 -0
  443. package/dist/src/web-ui/app/services/message-link-preview-client.js +96 -0
  444. package/dist/src/web-ui/app/services/runtime-web-client/schedules.js +51 -0
  445. package/dist/src/web-ui/app/services/runtime-web-client.d.ts +37 -0
  446. package/dist/src/web-ui/app/services/runtime-web-client.js +13 -8
  447. package/dist/src/web-ui/app/styles/00-tokens-base.css +11 -11
  448. package/dist/src/web-ui/app/styles/18-dashboard.css +384 -0
  449. package/dist/src/web-ui/app/styles/20-chat-composer.css +1 -130
  450. package/dist/src/web-ui/app/styles/26-message-content.css +295 -0
  451. package/dist/src/web-ui/app/styles/27-conversation-tools.css +266 -0
  452. package/dist/src/web-ui/app/styles/28-conversation-status.css +52 -0
  453. package/dist/src/web-ui/app/styles/38-schedule-workspace.css +263 -0
  454. package/dist/src/web-ui/app/styles/38-schedules.css +352 -0
  455. package/dist/src/web-ui/app/styles/90-responsive.css +14 -0
  456. package/dist/src/web-ui/app/styles/91-schedules-responsive.css +72 -0
  457. package/dist/src/web-ui/app/styles/92-dashboard-responsive.css +88 -0
  458. package/dist/src/web-ui/app/styles.css +8 -0
  459. package/dist/src/web-ui/app/ui-behavior.d.ts +1 -1
  460. package/dist/src/web-ui/app/ui-behavior.js +3 -1
  461. package/dist/src/web-ui/app/vendor/README.md +15 -0
  462. package/dist/src/web-ui/app/vendor/markdown-it.LICENSE +22 -0
  463. package/dist/src/web-ui/app/vendor/markdown-it.js +3003 -0
  464. package/dist/src/web-ui/link-preview/metadata.d.ts +9 -0
  465. package/dist/src/web-ui/link-preview/metadata.js +97 -0
  466. package/dist/src/web-ui/link-preview/preview-cache.d.ts +4 -0
  467. package/dist/src/web-ui/link-preview/preview-cache.js +23 -0
  468. package/dist/src/web-ui/link-preview/raster-response.d.ts +9 -0
  469. package/dist/src/web-ui/link-preview/raster-response.js +49 -0
  470. package/dist/src/web-ui/link-preview/routes.d.ts +3 -0
  471. package/dist/src/web-ui/link-preview/routes.js +97 -0
  472. package/dist/src/web-ui/link-preview/service.d.ts +11 -0
  473. package/dist/src/web-ui/link-preview/service.js +117 -0
  474. package/dist/src/web-ui/local-runtime/api-router.d.ts +4 -1
  475. package/dist/src/web-ui/local-runtime/api-router.js +42 -73
  476. package/dist/src/web-ui/local-runtime/contracts.d.ts +2 -2
  477. package/dist/src/web-ui/local-runtime/environment-registry.d.ts +12 -1
  478. package/dist/src/web-ui/local-runtime/environment-registry.js +38 -3
  479. package/dist/src/web-ui/local-runtime/realtime-controller.js +3 -1
  480. package/dist/src/web-ui/local-runtime/request-execution.d.ts +5 -1
  481. package/dist/src/web-ui/local-runtime/request-execution.js +38 -2
  482. package/dist/src/web-ui/local-runtime/schedule-job-creation.d.ts +7 -0
  483. package/dist/src/web-ui/local-runtime/schedule-job-creation.js +62 -0
  484. package/dist/src/web-ui/local-runtime/schedule-management-routes.d.ts +30 -0
  485. package/dist/src/web-ui/local-runtime/schedule-management-routes.js +134 -0
  486. package/dist/src/web-ui/local-runtime/schedule-run-page.d.ts +5 -0
  487. package/dist/src/web-ui/local-runtime/schedule-run-page.js +23 -0
  488. package/dist/src/web-ui/local-runtime/session-routes.d.ts +17 -0
  489. package/dist/src/web-ui/local-runtime/session-routes.js +74 -0
  490. package/dist/src/web-ui/local-runtime-backend.d.ts +2 -0
  491. package/dist/src/web-ui/local-runtime-backend.js +11 -1
  492. package/dist/src/web-ui/schedule-creation-contract.d.ts +7 -0
  493. package/dist/src/web-ui/schedule-creation-contract.js +1 -0
  494. package/dist/src/web-ui/server-shutdown.d.ts +4 -0
  495. package/dist/src/web-ui/server-shutdown.js +32 -0
  496. package/dist/src/web-ui/server.js +13 -10
  497. package/dist/src/web-ui/session-read-state/availability.d.ts +16 -0
  498. package/dist/src/web-ui/session-read-state/availability.js +20 -0
  499. package/dist/src/web-ui/session-read-state/projection.d.ts +17 -0
  500. package/dist/src/web-ui/session-read-state/projection.js +71 -0
  501. package/dist/src/web-ui/session-read-state/service.d.ts +86 -0
  502. package/dist/src/web-ui/session-read-state/service.js +89 -0
  503. package/dist/src/web-ui/session-read-state/store.d.ts +22 -0
  504. package/dist/src/web-ui/session-read-state/store.js +110 -0
  505. package/docs/configuration.md +41 -1
  506. package/docs/long-term-memory.md +46 -5
  507. package/docs/plugins.md +15 -9
  508. package/docs/runtime-invariant-coverage.md +1 -1
  509. package/docs/runtime-library.md +23 -0
  510. package/docs/runtime-public-contracts.md +32 -1
  511. package/package.json +3 -1
  512. package/plugins/code-outline/plugin.json +15 -0
  513. package/plugins/document-reader/plugin.json +17 -0
  514. package/plugins/exec/plugin.json +3 -3
  515. package/plugins/exec/skills/exec_skill/SKILL.md +1 -1
  516. package/plugins/exec/source/process-manager.ts +1 -20
  517. package/plugins/exec/source/shell-platform.ts +29 -0
  518. package/plugins/exec/src/index.cjs +25 -18
  519. package/plugins/filesystem/plugin.json +17 -2
  520. package/plugins/filesystem/source/atomic-write.ts +9 -0
  521. package/plugins/filesystem/source/bounded-io.ts +5 -99
  522. package/plugins/filesystem/source/directory-authority-write.ts +64 -0
  523. package/plugins/filesystem/source/directory-sample-task.ts +23 -0
  524. package/plugins/filesystem/source/directory-sample.ts +132 -0
  525. package/plugins/filesystem/source/directory-write-task.ts +160 -0
  526. package/plugins/filesystem/source/mutation-parent.ts +11 -0
  527. package/plugins/filesystem/src/index.cjs +693 -118
  528. package/plugins/json-inspector/plugin.json +12 -0
  529. package/plugins/local-search/plugin.json +12 -0
  530. package/plugins/local-search/source/index.ts +2 -0
  531. package/plugins/local-search/source/paths.ts +30 -7
  532. package/plugins/local-search/source/ripgrep-process.ts +69 -0
  533. package/plugins/local-search/source/ripgrep.ts +19 -23
  534. package/plugins/local-search/src/index.cjs +295 -32
  535. package/plugins/memory/plugin.json +26 -1
  536. package/plugins/memory/source/index.ts +10 -6
  537. package/plugins/memory/src/index.cjs +11 -7
  538. package/plugins/project-orientation/plugin.json +14 -0
  539. package/plugins/web/source/aggregate-gate.ts +8 -130
  540. package/plugins/web/source/deadline.ts +14 -50
  541. package/plugins/web/source/errors.ts +17 -11
  542. package/plugins/web/source/limits.ts +3 -6
  543. package/plugins/web/source/network-policy.ts +28 -226
  544. package/plugins/web/source/public-http.ts +17 -142
  545. package/plugins/web/source/request-hop.ts +11 -191
  546. package/plugins/web/src/index.cjs +119 -59
  547. package/runtime.config.schema.json +7 -0
  548. package/src/runtime/README.md +105 -1
  549. package/src/runtime/local-host/README.md +86 -0
  550. package/src/runtime/scheduler/README.md +166 -0
@@ -253,13 +253,13 @@ var writeFileAdapter = Object.freeze({
253
253
  });
254
254
 
255
255
  // plugins/filesystem/source/dev-view.ts
256
- var import_promises2 = require("node:fs/promises");
256
+ var import_promises3 = require("node:fs/promises");
257
257
 
258
258
  // plugins/filesystem/source/bounded-io.ts
259
259
  var import_node_crypto = require("node:crypto");
260
- var import_node_fs = require("node:fs");
261
- var import_promises = require("node:fs/promises");
262
- var import_node_path = require("node:path");
260
+ var import_node_fs2 = require("node:fs");
261
+ var import_promises2 = require("node:fs/promises");
262
+ var import_node_path3 = require("node:path");
263
263
  var import_node_string_decoder = require("node:string_decoder");
264
264
  var import_node_util = require("node:util");
265
265
 
@@ -302,12 +302,462 @@ function rethrowFilesystemError(error, operation, logicalPath) {
302
302
  );
303
303
  }
304
304
 
305
+ // plugins/filesystem/source/directory-sample.ts
306
+ var import_node_fs = require("node:fs");
307
+ var import_promises = require("node:fs/promises");
308
+ var import_node_path2 = require("node:path");
309
+
310
+ // src/shared/directory-authority/bootstrap.ts
311
+ function directoryAuthorityBootstrap(mode, messageLimit, task) {
312
+ const fs = require("node:fs");
313
+ function fail2(code, message) {
314
+ throw Object.assign(new Error(message), { code });
315
+ }
316
+ function verifyDirectoryAuthority() {
317
+ const expected = fs.fstatSync(3, { bigint: true });
318
+ const actual = fs.statSync(".", { bigint: true });
319
+ const matchesHeldDirectory = expected.isDirectory() && actual.isDirectory() && expected.dev === actual.dev && expected.ino === actual.ino;
320
+ if (matchesHeldDirectory) return;
321
+ fail2(
322
+ "directory_authority_changed",
323
+ "The directory changed before the operation could establish its authority."
324
+ );
325
+ }
326
+ function readRequest() {
327
+ const fd = mode === "task" ? 0 : 4;
328
+ const chunk = Buffer.alloc(64 * 1024);
329
+ const chunks = [];
330
+ let total = 0;
331
+ for (; ; ) {
332
+ const length = fs.readSync(fd, chunk, 0, chunk.length, null);
333
+ if (length === 0) break;
334
+ total += length;
335
+ if (total > messageLimit) {
336
+ fail2(
337
+ "directory_authority_request_too_large",
338
+ "The directory operation input exceeds the bridge byte limit."
339
+ );
340
+ }
341
+ chunks.push(Buffer.from(chunk.subarray(0, length)));
342
+ }
343
+ return JSON.parse(Buffer.concat(chunks).toString("utf8"));
344
+ }
345
+ function reportFailure(error) {
346
+ const detail = error;
347
+ const code = typeof detail?.code === "string" ? detail.code.slice(0, 256) : "directory_authority_failed";
348
+ const message = typeof detail?.message === "string" ? detail.message.slice(0, 4096) : "The directory operation failed.";
349
+ let encoded;
350
+ try {
351
+ encoded = JSON.stringify({
352
+ ok: false,
353
+ error: { code, message, data: detail?.data }
354
+ });
355
+ if (Buffer.byteLength(encoded) > messageLimit) throw new Error();
356
+ } catch {
357
+ encoded = JSON.stringify({ ok: false, error: { code, message } });
358
+ }
359
+ writeResponse(mode === "task" ? 1 : 2, encoded);
360
+ process.exitCode = mode === "task" ? 0 : 125;
361
+ }
362
+ function writeResponse(fd, encoded) {
363
+ const bytes = Buffer.from(encoded);
364
+ let offset = 0;
365
+ while (offset < bytes.length) {
366
+ offset += fs.writeSync(fd, bytes, offset, bytes.length - offset);
367
+ }
368
+ }
369
+ async function runTask(input) {
370
+ if (!task)
371
+ fail2("directory_authority_failed", "The directory task is missing.");
372
+ const result = await task(input);
373
+ const encoded = JSON.stringify({ ok: true, result });
374
+ if (Buffer.byteLength(encoded) > messageLimit) {
375
+ fail2(
376
+ "directory_authority_result_too_large",
377
+ "The directory operation result exceeds the bridge byte limit."
378
+ );
379
+ }
380
+ writeResponse(1, encoded);
381
+ }
382
+ function runCommand(input) {
383
+ const { spawn: spawn2 } = require("node:child_process");
384
+ const command = input;
385
+ const child = spawn2(command.command, command.args, {
386
+ stdio: ["ignore", "inherit", "inherit"],
387
+ env: process.env
388
+ });
389
+ child.once("error", reportFailure);
390
+ child.once("exit", (code, signal) => {
391
+ if (signal) {
392
+ process.kill(process.pid, signal);
393
+ return;
394
+ }
395
+ if (typeof code === "number") process.exitCode = code;
396
+ });
397
+ }
398
+ try {
399
+ verifyDirectoryAuthority();
400
+ const input = readRequest();
401
+ if (mode === "command") {
402
+ runCommand(input);
403
+ return;
404
+ }
405
+ void runTask(input).catch(reportFailure);
406
+ } catch (error) {
407
+ reportFailure(error);
408
+ }
409
+ }
410
+ function directoryAuthorityScript(mode, messageLimit, task) {
411
+ const taskSource = task ? `(${task.toString()})` : "undefined";
412
+ const preserveFunctionName = "const __name=(target,value)=>Object.defineProperty(target,'name',{value,configurable:true});";
413
+ return `${preserveFunctionName}(${directoryAuthorityBootstrap.toString()})(${JSON.stringify(mode)},${messageLimit},${taskSource});`;
414
+ }
415
+
416
+ // src/shared/directory-authority/protocol.ts
417
+ var import_node_path = require("node:path");
418
+
419
+ // src/shared/directory-authority/errors.ts
420
+ var DirectoryAuthorityError = class extends Error {
421
+ constructor(code, message, data) {
422
+ super(message);
423
+ this.code = code;
424
+ this.data = data;
425
+ this.name = "DirectoryAuthorityError";
426
+ }
427
+ code;
428
+ data;
429
+ };
430
+
431
+ // src/shared/directory-authority/protocol.ts
432
+ var AUTHORITY_MESSAGE_LIMIT = 8 * 1024 * 1024;
433
+ var AUTHORITY_STDERR_LIMIT = 16 * 1024;
434
+ var AUTHORITY_TASK_TIMEOUT_MS = 3e4;
435
+ function assertDirectoryAuthorityLocation(location) {
436
+ if (!(0, import_node_path.isAbsolute)(location.directoryPath)) {
437
+ throw new DirectoryAuthorityError(
438
+ "directory_authority_invalid_path",
439
+ "The directory authority requires an absolute starting path."
440
+ );
441
+ }
442
+ const hasOpenDescriptorNumber = Number.isInteger(location.directoryFd) && location.directoryFd >= 0;
443
+ if (hasOpenDescriptorNumber) return;
444
+ throw new DirectoryAuthorityError(
445
+ "directory_authority_invalid_fd",
446
+ "The directory authority requires an open directory descriptor."
447
+ );
448
+ }
449
+ function authorityEnvironment(environment = process.env) {
450
+ const sanitized = { ...environment };
451
+ delete sanitized.NODE_OPTIONS;
452
+ delete sanitized.NODE_PATH;
453
+ return sanitized;
454
+ }
455
+ function encodeAuthorityRequest(input) {
456
+ let encoded;
457
+ try {
458
+ encoded = JSON.stringify(input);
459
+ } catch {
460
+ throw new DirectoryAuthorityError(
461
+ "directory_authority_invalid_request",
462
+ "The directory operation input must be JSON serializable."
463
+ );
464
+ }
465
+ if (encoded === void 0) {
466
+ throw new DirectoryAuthorityError(
467
+ "directory_authority_invalid_request",
468
+ "The directory operation input must be JSON serializable."
469
+ );
470
+ }
471
+ if (Buffer.byteLength(encoded) <= AUTHORITY_MESSAGE_LIMIT) return encoded;
472
+ throw new DirectoryAuthorityError(
473
+ "directory_authority_request_too_large",
474
+ "The directory operation input exceeds the bridge byte limit."
475
+ );
476
+ }
477
+ function isAuthorityMessageObject(value) {
478
+ return typeof value === "object" && value !== null && !Array.isArray(value);
479
+ }
480
+ function decodeAuthorityResult(output) {
481
+ let message;
482
+ try {
483
+ message = JSON.parse(output);
484
+ } catch {
485
+ throw new DirectoryAuthorityError(
486
+ "directory_authority_protocol_error",
487
+ "The directory operation returned an invalid response."
488
+ );
489
+ }
490
+ if (!isAuthorityMessageObject(message)) {
491
+ throw new DirectoryAuthorityError(
492
+ "directory_authority_protocol_error",
493
+ "The directory operation returned an invalid response."
494
+ );
495
+ }
496
+ if (message.ok === true) return message.result;
497
+ const hasAuthorityError = message.ok === false && isAuthorityMessageObject(message.error);
498
+ if (!hasAuthorityError) {
499
+ throw new DirectoryAuthorityError(
500
+ "directory_authority_protocol_error",
501
+ "The directory operation returned an invalid response."
502
+ );
503
+ }
504
+ const {
505
+ code,
506
+ message: explanation,
507
+ data
508
+ } = message.error;
509
+ const hasErrorDescription = typeof code === "string" && typeof explanation === "string";
510
+ if (!hasErrorDescription) {
511
+ throw new DirectoryAuthorityError(
512
+ "directory_authority_protocol_error",
513
+ "The directory operation returned an invalid error response."
514
+ );
515
+ }
516
+ throw new DirectoryAuthorityError(
517
+ code,
518
+ explanation,
519
+ isAuthorityMessageObject(data) ? data : void 0
520
+ );
521
+ }
522
+
523
+ // src/shared/directory-authority/task.ts
524
+ var import_node_child_process = require("node:child_process");
525
+ async function runDirectoryAuthorityTask(input) {
526
+ assertDirectoryAuthorityLocation(input);
527
+ const request = encodeAuthorityRequest(input.input);
528
+ const timeoutMs = input.timeoutMs ?? AUTHORITY_TASK_TIMEOUT_MS;
529
+ const hasPositiveDeadline = Number.isFinite(timeoutMs) && timeoutMs > 0;
530
+ if (!hasPositiveDeadline) {
531
+ throw new DirectoryAuthorityError(
532
+ "directory_authority_invalid_timeout",
533
+ "The directory operation deadline must be a positive finite duration."
534
+ );
535
+ }
536
+ if (input.signal?.aborted) {
537
+ throw new DirectoryAuthorityError(
538
+ "directory_authority_aborted",
539
+ "The directory operation was cancelled before it started."
540
+ );
541
+ }
542
+ const child = (0, import_node_child_process.spawn)(
543
+ process.execPath,
544
+ [
545
+ "--input-type=commonjs",
546
+ "-e",
547
+ directoryAuthorityScript("task", AUTHORITY_MESSAGE_LIMIT, input.task)
548
+ ],
549
+ {
550
+ cwd: input.directoryPath,
551
+ env: authorityEnvironment(),
552
+ detached: true,
553
+ windowsHide: true,
554
+ stdio: ["pipe", "pipe", "pipe", input.directoryFd]
555
+ }
556
+ );
557
+ return new Promise((resolve, reject) => {
558
+ const chunks = [];
559
+ const stderrChunks = [];
560
+ let bytes = 0;
561
+ let stderrBytes = 0;
562
+ let failure;
563
+ const stop = (error) => {
564
+ if (failure) return;
565
+ failure = error;
566
+ if (typeof child.pid === "number") {
567
+ try {
568
+ process.kill(-child.pid, "SIGKILL");
569
+ return;
570
+ } catch {
571
+ }
572
+ }
573
+ child.kill("SIGKILL");
574
+ };
575
+ const onAbort = () => stop(
576
+ new DirectoryAuthorityError(
577
+ "directory_authority_aborted",
578
+ "The directory operation was cancelled."
579
+ )
580
+ );
581
+ const timer = setTimeout(
582
+ () => stop(
583
+ new DirectoryAuthorityError(
584
+ "directory_authority_timeout",
585
+ "The directory operation exceeded its deadline."
586
+ )
587
+ ),
588
+ timeoutMs
589
+ );
590
+ timer.unref();
591
+ input.signal?.addEventListener("abort", onAbort, { once: true });
592
+ if (input.signal?.aborted) onAbort();
593
+ child.stdout.on("data", (chunk) => {
594
+ bytes += chunk.length;
595
+ if (bytes > AUTHORITY_MESSAGE_LIMIT) {
596
+ stop(
597
+ new DirectoryAuthorityError(
598
+ "directory_authority_result_too_large",
599
+ "The directory operation result exceeds the bridge byte limit."
600
+ )
601
+ );
602
+ return;
603
+ }
604
+ chunks.push(chunk);
605
+ });
606
+ child.stderr.on("data", (chunk) => {
607
+ const remaining = Math.max(AUTHORITY_STDERR_LIMIT - stderrBytes, 0);
608
+ if (remaining === 0) return;
609
+ stderrChunks.push(chunk.subarray(0, remaining));
610
+ stderrBytes += Math.min(chunk.length, remaining);
611
+ });
612
+ child.stdin.on("error", () => void 0);
613
+ child.once("error", (error) => {
614
+ failure ??= new DirectoryAuthorityError(
615
+ "directory_authority_unavailable",
616
+ `The directory operation could not start: ${error.message}`
617
+ );
618
+ });
619
+ child.once("close", (code, signal) => {
620
+ clearTimeout(timer);
621
+ input.signal?.removeEventListener("abort", onAbort);
622
+ if (failure) {
623
+ reject(failure);
624
+ return;
625
+ }
626
+ if (code !== 0) {
627
+ reject(
628
+ new DirectoryAuthorityError(
629
+ "directory_authority_failed",
630
+ "The directory operation process did not complete successfully.",
631
+ {
632
+ exitCode: code,
633
+ signal,
634
+ stderr: Buffer.concat(stderrChunks).toString("utf8")
635
+ }
636
+ )
637
+ );
638
+ return;
639
+ }
640
+ try {
641
+ resolve(
642
+ decodeAuthorityResult(Buffer.concat(chunks).toString("utf8"))
643
+ );
644
+ } catch (error) {
645
+ reject(error);
646
+ }
647
+ });
648
+ child.stdin.end(request);
649
+ });
650
+ }
651
+
652
+ // plugins/filesystem/source/directory-sample-task.ts
653
+ async function sampleDirectoryTask(input) {
654
+ const { opendir: opendir2 } = require("node:fs/promises");
655
+ const entries = [];
656
+ const directory = await opendir2(".");
657
+ for await (const entry of directory) {
658
+ if (entries.length >= input.maxEntries) {
659
+ entries.sort((left, right) => left.localeCompare(right));
660
+ return { entries, truncated: true };
661
+ }
662
+ entries.push(`${entry.name}${entry.isDirectory() ? "/" : ""}`);
663
+ }
664
+ entries.sort((left, right) => left.localeCompare(right));
665
+ return { entries, truncated: false };
666
+ }
667
+
668
+ // plugins/filesystem/source/directory-sample.ts
669
+ var DIRECTORY_ENTRY_LIMIT = 160;
670
+ async function readDirectorySample(target) {
671
+ const entries = [];
672
+ let handle;
673
+ try {
674
+ if (typeof import_node_fs.constants.O_DIRECTORY !== "number" || typeof import_node_fs.constants.O_NOFOLLOW !== "number") {
675
+ fail(
676
+ "filesystem_safe_io_unsupported",
677
+ "This platform does not provide the no-follow directory operation required for a safe read."
678
+ );
679
+ }
680
+ handle = await (0, import_promises.open)(
681
+ target.absolutePath,
682
+ import_node_fs.constants.O_RDONLY | import_node_fs.constants.O_DIRECTORY | import_node_fs.constants.O_NOFOLLOW
683
+ );
684
+ const before = await handle.stat({ bigint: true });
685
+ if (!before.isDirectory()) {
686
+ fail("not_a_directory", `Expected a directory: ${target.logicalPath}`);
687
+ }
688
+ const [canonicalRoot, canonicalTarget] = await Promise.all([
689
+ (0, import_promises.realpath)(target.rootPath),
690
+ (0, import_promises.realpath)(target.absolutePath)
691
+ ]);
692
+ const rootRelative = (0, import_node_path2.relative)(canonicalRoot, canonicalTarget);
693
+ if (rootRelative === ".." || rootRelative.startsWith(`..${import_node_path2.sep}`) || rootRelative.startsWith(import_node_path2.sep)) {
694
+ fail(
695
+ "filesystem_path_changed",
696
+ `Directory changed outside its configured root: ${target.logicalPath}`
697
+ );
698
+ }
699
+ const pathIdentity = await (0, import_promises.stat)(canonicalTarget, { bigint: true });
700
+ if (!pathIdentity.isDirectory() || pathIdentity.dev !== before.dev || pathIdentity.ino !== before.ino) {
701
+ fail(
702
+ "filesystem_path_changed",
703
+ `Directory changed while it was being opened: ${target.logicalPath}`
704
+ );
705
+ }
706
+ if (requiresIsolatedDirectorySample()) {
707
+ const sample = await runDirectoryAuthorityTask({
708
+ directoryPath: target.absolutePath,
709
+ directoryFd: handle.fd,
710
+ input: { maxEntries: DIRECTORY_ENTRY_LIMIT },
711
+ task: sampleDirectoryTask
712
+ });
713
+ await assertDirectoryStable(handle, before, target.logicalPath);
714
+ return sample;
715
+ }
716
+ const directory = await (0, import_promises.opendir)(`/proc/self/fd/${handle.fd}`);
717
+ for await (const entry of directory) {
718
+ if (entries.length >= DIRECTORY_ENTRY_LIMIT) {
719
+ await assertDirectoryStable(handle, before, target.logicalPath);
720
+ entries.sort((left, right) => left.localeCompare(right));
721
+ return Object.freeze({
722
+ entries: Object.freeze(entries),
723
+ truncated: true
724
+ });
725
+ }
726
+ entries.push(`${entry.name}${entry.isDirectory() ? "/" : ""}`);
727
+ }
728
+ await assertDirectoryStable(handle, before, target.logicalPath);
729
+ entries.sort((left, right) => left.localeCompare(right));
730
+ return Object.freeze({ entries: Object.freeze(entries), truncated: false });
731
+ } catch (error) {
732
+ if (error instanceof DirectoryAuthorityError && error.code.startsWith("directory_authority_")) {
733
+ fail(
734
+ "filesystem_path_changed",
735
+ `Directory authority was lost: ${target.logicalPath}`
736
+ );
737
+ }
738
+ return rethrowFilesystemError(error, "inspect", target.logicalPath);
739
+ } finally {
740
+ await handle?.close().catch(() => void 0);
741
+ }
742
+ }
743
+ async function assertDirectoryStable(handle, before, logicalPath) {
744
+ const after = await handle.stat({ bigint: true });
745
+ if (!after.isDirectory() || after.dev !== before.dev || after.ino !== before.ino || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
746
+ fail(
747
+ "filesystem_read_changed",
748
+ `Directory changed while it was being read: ${logicalPath}`
749
+ );
750
+ }
751
+ }
752
+ function requiresIsolatedDirectorySample() {
753
+ return process.platform === "darwin";
754
+ }
755
+
305
756
  // plugins/filesystem/source/bounded-io.ts
306
757
  var MAX_MUTATION_BYTES = 1048576;
307
758
  var READ_HEAD_BYTES = 24576;
308
759
  var READ_TAIL_BYTES = 12288;
309
760
  var DEV_SCAN_BYTES = 1048576;
310
- var DIRECTORY_ENTRY_LIMIT = 160;
311
761
  async function readExactBytes(reader, buffer, position, logicalPath) {
312
762
  let offset = 0;
313
763
  while (offset < buffer.length) {
@@ -349,15 +799,15 @@ function decodeMutationText(buffer, logicalPath) {
349
799
  async function openRegularFile(target) {
350
800
  let handle;
351
801
  try {
352
- if (typeof import_node_fs.constants.O_NOFOLLOW !== "number") {
802
+ if (typeof import_node_fs2.constants.O_NOFOLLOW !== "number") {
353
803
  fail(
354
804
  "filesystem_safe_io_unsupported",
355
805
  "This platform does not provide the no-follow operation required for a safe read."
356
806
  );
357
807
  }
358
- handle = await (0, import_promises.open)(
808
+ handle = await (0, import_promises2.open)(
359
809
  target.absolutePath,
360
- import_node_fs.constants.O_RDONLY | import_node_fs.constants.O_NOFOLLOW
810
+ import_node_fs2.constants.O_RDONLY | import_node_fs2.constants.O_NOFOLLOW
361
811
  );
362
812
  const info = await handle.stat({ bigint: true });
363
813
  if (!info.isFile()) {
@@ -365,17 +815,17 @@ async function openRegularFile(target) {
365
815
  }
366
816
  const metadata = metadataFromStat(info, target.logicalPath);
367
817
  const [canonicalRoot, canonicalTarget] = await Promise.all([
368
- (0, import_promises.realpath)(target.rootPath),
369
- (0, import_promises.realpath)(target.absolutePath)
818
+ (0, import_promises2.realpath)(target.rootPath),
819
+ (0, import_promises2.realpath)(target.absolutePath)
370
820
  ]);
371
- const rootRelative = (0, import_node_path.relative)(canonicalRoot, canonicalTarget);
372
- if (rootRelative === ".." || rootRelative.startsWith(`..${import_node_path.sep}`) || rootRelative.startsWith(import_node_path.sep)) {
821
+ const rootRelative = (0, import_node_path3.relative)(canonicalRoot, canonicalTarget);
822
+ if (rootRelative === ".." || rootRelative.startsWith(`..${import_node_path3.sep}`) || rootRelative.startsWith(import_node_path3.sep)) {
373
823
  fail(
374
824
  "filesystem_path_changed",
375
825
  `File changed outside its configured root: ${target.logicalPath}`
376
826
  );
377
827
  }
378
- const pathIdentity = await (0, import_promises.stat)(canonicalTarget, { bigint: true });
828
+ const pathIdentity = await (0, import_promises2.stat)(canonicalTarget, { bigint: true });
379
829
  if (!pathIdentity.isFile() || pathIdentity.dev !== info.dev || pathIdentity.ino !== info.ino) {
380
830
  fail(
381
831
  "filesystem_path_changed",
@@ -546,72 +996,6 @@ function assertMutationContentSize(content) {
546
996
  }
547
997
  return byteCount;
548
998
  }
549
- async function readDirectorySample(target) {
550
- const entries = [];
551
- let handle;
552
- try {
553
- if (typeof import_node_fs.constants.O_DIRECTORY !== "number" || typeof import_node_fs.constants.O_NOFOLLOW !== "number") {
554
- fail(
555
- "filesystem_safe_io_unsupported",
556
- "This platform does not provide the no-follow directory operation required for a safe read."
557
- );
558
- }
559
- handle = await (0, import_promises.open)(
560
- target.absolutePath,
561
- import_node_fs.constants.O_RDONLY | import_node_fs.constants.O_DIRECTORY | import_node_fs.constants.O_NOFOLLOW
562
- );
563
- const before = await handle.stat({ bigint: true });
564
- if (!before.isDirectory()) {
565
- fail("not_a_directory", `Expected a directory: ${target.logicalPath}`);
566
- }
567
- const [canonicalRoot, canonicalTarget] = await Promise.all([
568
- (0, import_promises.realpath)(target.rootPath),
569
- (0, import_promises.realpath)(target.absolutePath)
570
- ]);
571
- const rootRelative = (0, import_node_path.relative)(canonicalRoot, canonicalTarget);
572
- if (rootRelative === ".." || rootRelative.startsWith(`..${import_node_path.sep}`) || rootRelative.startsWith(import_node_path.sep)) {
573
- fail(
574
- "filesystem_path_changed",
575
- `Directory changed outside its configured root: ${target.logicalPath}`
576
- );
577
- }
578
- const pathIdentity = await (0, import_promises.stat)(canonicalTarget, { bigint: true });
579
- if (!pathIdentity.isDirectory() || pathIdentity.dev !== before.dev || pathIdentity.ino !== before.ino) {
580
- fail(
581
- "filesystem_path_changed",
582
- `Directory changed while it was being opened: ${target.logicalPath}`
583
- );
584
- }
585
- const directory = await (0, import_promises.opendir)(`/proc/self/fd/${handle.fd}`);
586
- for await (const entry of directory) {
587
- if (entries.length >= DIRECTORY_ENTRY_LIMIT) {
588
- await assertDirectoryStable(handle, before, target.logicalPath);
589
- entries.sort((left, right) => left.localeCompare(right));
590
- return Object.freeze({
591
- entries: Object.freeze(entries),
592
- truncated: true
593
- });
594
- }
595
- entries.push(`${entry.name}${entry.isDirectory() ? "/" : ""}`);
596
- }
597
- await assertDirectoryStable(handle, before, target.logicalPath);
598
- entries.sort((left, right) => left.localeCompare(right));
599
- return Object.freeze({ entries: Object.freeze(entries), truncated: false });
600
- } catch (error) {
601
- return rethrowFilesystemError(error, "inspect", target.logicalPath);
602
- } finally {
603
- await handle?.close().catch(() => void 0);
604
- }
605
- }
606
- async function assertDirectoryStable(handle, before, logicalPath) {
607
- const after = await handle.stat({ bigint: true });
608
- if (!after.isDirectory() || after.dev !== before.dev || after.ino !== before.ino || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
609
- fail(
610
- "filesystem_read_changed",
611
- `Directory changed while it was being read: ${logicalPath}`
612
- );
613
- }
614
- }
615
999
  function rejectBinary(buffer, logicalPath) {
616
1000
  if (buffer.includes(0)) {
617
1001
  fail(
@@ -725,7 +1109,7 @@ function createDevViewHandler(paths) {
725
1109
  const target = paths.resolve(pathRange.path, context);
726
1110
  let info;
727
1111
  try {
728
- info = await (0, import_promises2.stat)(target.absolutePath);
1112
+ info = await (0, import_promises3.stat)(target.absolutePath);
729
1113
  } catch (error) {
730
1114
  rethrowFilesystemError(error, "inspect", target.logicalPath);
731
1115
  }
@@ -924,22 +1308,22 @@ async function viewFile(input) {
924
1308
 
925
1309
  // plugins/filesystem/source/atomic-write.ts
926
1310
  var import_node_crypto2 = require("node:crypto");
927
- var import_promises4 = require("node:fs/promises");
928
- var import_node_path3 = require("node:path");
1311
+ var import_promises5 = require("node:fs/promises");
1312
+ var import_node_path5 = require("node:path");
929
1313
 
930
1314
  // plugins/filesystem/source/mutation-parent.ts
931
- var import_node_fs2 = require("node:fs");
932
- var import_promises3 = require("node:fs/promises");
933
- var import_node_path2 = require("node:path");
1315
+ var import_node_fs3 = require("node:fs");
1316
+ var import_promises4 = require("node:fs/promises");
1317
+ var import_node_path4 = require("node:path");
934
1318
  function isWithinRoot(target, root) {
935
- const rel = (0, import_node_path2.relative)(root, target);
936
- return rel === "" || rel !== ".." && !rel.startsWith(`..${import_node_path2.sep}`);
1319
+ const rel = (0, import_node_path4.relative)(root, target);
1320
+ return rel === "" || rel !== ".." && !rel.startsWith(`..${import_node_path4.sep}`);
937
1321
  }
938
1322
  function sameIdentity(left, right) {
939
1323
  return left.dev === right.dev && left.ino === right.ino;
940
1324
  }
941
1325
  async function openDirectory(path, rootPath, logicalPath, allowMissing = false) {
942
- if (typeof import_node_fs2.constants.O_DIRECTORY !== "number" || typeof import_node_fs2.constants.O_NOFOLLOW !== "number") {
1326
+ if (typeof import_node_fs3.constants.O_DIRECTORY !== "number" || typeof import_node_fs3.constants.O_NOFOLLOW !== "number") {
943
1327
  fail(
944
1328
  "filesystem_safe_io_unsupported",
945
1329
  "This platform does not provide the no-follow directory operations required for a safe write."
@@ -947,17 +1331,17 @@ async function openDirectory(path, rootPath, logicalPath, allowMissing = false)
947
1331
  }
948
1332
  let handle;
949
1333
  try {
950
- handle = await (0, import_promises3.open)(
1334
+ handle = await (0, import_promises4.open)(
951
1335
  path,
952
- import_node_fs2.constants.O_RDONLY | import_node_fs2.constants.O_DIRECTORY | import_node_fs2.constants.O_NOFOLLOW
1336
+ import_node_fs3.constants.O_RDONLY | import_node_fs3.constants.O_DIRECTORY | import_node_fs3.constants.O_NOFOLLOW
953
1337
  );
954
1338
  const opened = await handle.stat({ bigint: true });
955
1339
  if (!opened.isDirectory()) {
956
1340
  fail("not_a_directory", `Expected a directory: ${logicalPath}`);
957
1341
  }
958
1342
  const [canonicalRoot, canonicalDirectory] = await Promise.all([
959
- (0, import_promises3.realpath)(rootPath),
960
- (0, import_promises3.realpath)(path)
1343
+ (0, import_promises4.realpath)(rootPath),
1344
+ (0, import_promises4.realpath)(path)
961
1345
  ]);
962
1346
  if (!isWithinRoot(canonicalDirectory, canonicalRoot)) {
963
1347
  fail(
@@ -965,15 +1349,16 @@ async function openDirectory(path, rootPath, logicalPath, allowMissing = false)
965
1349
  `Directory changed outside its configured root: ${logicalPath}`
966
1350
  );
967
1351
  }
968
- const pathIdentity = await (0, import_promises3.stat)(canonicalDirectory, { bigint: true });
1352
+ const pathIdentity = await (0, import_promises4.stat)(canonicalDirectory, { bigint: true });
969
1353
  if (!pathIdentity.isDirectory() || !sameIdentity(opened, pathIdentity)) {
970
1354
  fail(
971
1355
  "filesystem_path_changed",
972
1356
  `Directory changed while it was being opened: ${logicalPath}`
973
1357
  );
974
1358
  }
1359
+ if (usesIsolatedDirectoryAuthority()) return handle;
975
1360
  const procPath = `/proc/self/fd/${handle.fd}`;
976
- const procIdentity = await (0, import_promises3.stat)(procPath, { bigint: true });
1361
+ const procIdentity = await (0, import_promises4.stat)(procPath, { bigint: true });
977
1362
  if (!procIdentity.isDirectory() || !sameIdentity(opened, procIdentity)) {
978
1363
  fail(
979
1364
  "filesystem_safe_io_unsupported",
@@ -1000,7 +1385,7 @@ async function openChildDirectory(parent, name, logicalPath) {
1000
1385
  if (!isNodeErrorCode(error, "ENOENT")) throw error;
1001
1386
  }
1002
1387
  try {
1003
- await (0, import_promises3.mkdir)(anchoredPath);
1388
+ await (0, import_promises4.mkdir)(anchoredPath);
1004
1389
  } catch (error) {
1005
1390
  if (!isNodeErrorCode(error, "EEXIST")) {
1006
1391
  rethrowFilesystemError(error, "write", logicalPath);
@@ -1047,10 +1432,197 @@ async function openMutationParent(target) {
1047
1432
  throw error;
1048
1433
  }
1049
1434
  }
1435
+ function usesIsolatedDirectoryAuthority() {
1436
+ return process.platform === "darwin";
1437
+ }
1438
+ function openMutationRoot(target) {
1439
+ return openDirectory(target.rootPath, target.rootPath, target.logicalPath);
1440
+ }
1441
+
1442
+ // plugins/filesystem/source/directory-write-task.ts
1443
+ async function commitDirectoryWrite(input) {
1444
+ const fs = require("node:fs/promises");
1445
+ const { constants: constants4 } = require("node:fs");
1446
+ const { createHash: createHash3, randomUUID: randomUUID2 } = require("node:crypto");
1447
+ const expected = input.expectedVersion;
1448
+ function failWrite(code) {
1449
+ throw Object.assign(new Error(code), { code });
1450
+ }
1451
+ function hasNodeCode(error, code) {
1452
+ return error instanceof Error && "code" in error && error.code === code;
1453
+ }
1454
+ function isSingleComponent(value) {
1455
+ if (!value || value === "." || value === "..") return false;
1456
+ if (value.includes("/") || value.includes("\\")) return false;
1457
+ return !value.includes("\0");
1458
+ }
1459
+ const segments = input.relativePath.split("/");
1460
+ if (!segments.every(isSingleComponent)) failWrite("filesystem_path_changed");
1461
+ const targetName = segments.pop();
1462
+ if (Buffer.byteLength(input.content, "utf8") > 1048576) {
1463
+ failWrite("filesystem_file_too_large");
1464
+ }
1465
+ async function enterChildDirectory(name) {
1466
+ let handle;
1467
+ const flags = constants4.O_RDONLY | constants4.O_DIRECTORY | constants4.O_NOFOLLOW;
1468
+ try {
1469
+ handle = await fs.open(name, flags);
1470
+ } catch (error) {
1471
+ if (!hasNodeCode(error, "ENOENT")) throw error;
1472
+ try {
1473
+ await fs.mkdir(name);
1474
+ } catch (creationError) {
1475
+ if (!hasNodeCode(creationError, "EEXIST")) throw creationError;
1476
+ }
1477
+ handle = await fs.open(name, flags);
1478
+ }
1479
+ try {
1480
+ const held = await handle.stat({ bigint: true });
1481
+ if (!held.isDirectory()) failWrite("filesystem_path_changed");
1482
+ process.chdir(name);
1483
+ const entered = await fs.stat(".", { bigint: true });
1484
+ if (held.dev !== entered.dev || held.ino !== entered.ino) {
1485
+ failWrite("filesystem_path_changed");
1486
+ }
1487
+ } finally {
1488
+ await handle.close();
1489
+ }
1490
+ }
1491
+ for (const segment of segments) await enterChildDirectory(segment);
1492
+ function hasExpectedMetadata(info) {
1493
+ if (expected.kind !== "file" || !info.isFile()) return false;
1494
+ if (String(info.dev) !== expected.device) return false;
1495
+ if (String(info.ino) !== expected.inode) return false;
1496
+ if (Number(info.size) !== expected.size) return false;
1497
+ if ((Number(info.mode) & 4095) !== expected.mode) return false;
1498
+ if (String(info.mtimeNs) !== expected.modifiedNs) return false;
1499
+ return String(info.ctimeNs) === expected.changedNs;
1500
+ }
1501
+ async function assertExpectedTarget() {
1502
+ let target;
1503
+ try {
1504
+ target = await fs.open(
1505
+ targetName,
1506
+ constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK
1507
+ );
1508
+ } catch (error) {
1509
+ if (hasNodeCode(error, "ENOENT") && expected.kind === "absent") return;
1510
+ failWrite("filesystem_target_changed");
1511
+ }
1512
+ try {
1513
+ const before = await target.stat({ bigint: true });
1514
+ if (!hasExpectedMetadata(before)) failWrite("filesystem_target_changed");
1515
+ if (expected.kind !== "file") failWrite("filesystem_target_changed");
1516
+ const bytes = Buffer.alloc(expected.size);
1517
+ let offset = 0;
1518
+ while (offset < bytes.length) {
1519
+ const { bytesRead } = await target.read(
1520
+ bytes,
1521
+ offset,
1522
+ bytes.length - offset,
1523
+ offset
1524
+ );
1525
+ if (bytesRead <= 0) failWrite("filesystem_target_changed");
1526
+ offset += bytesRead;
1527
+ }
1528
+ const after = await target.stat({ bigint: true });
1529
+ if (!hasExpectedMetadata(after)) failWrite("filesystem_target_changed");
1530
+ const digest2 = createHash3("sha256").update(bytes).digest("hex");
1531
+ if (digest2 !== expected.digest) failWrite("filesystem_target_changed");
1532
+ } finally {
1533
+ await target.close();
1534
+ }
1535
+ }
1536
+ const parent = await fs.open(
1537
+ ".",
1538
+ constants4.O_RDONLY | constants4.O_DIRECTORY | constants4.O_NOFOLLOW
1539
+ );
1540
+ const temporaryName = `.abot-${targetName}-${randomUUID2()}.tmp`;
1541
+ let temporaryCreated = false;
1542
+ try {
1543
+ const temporary = await fs.open(temporaryName, "wx");
1544
+ temporaryCreated = true;
1545
+ try {
1546
+ await temporary.writeFile(input.content, "utf8");
1547
+ if (expected.kind === "file") await temporary.chmod(expected.mode);
1548
+ await temporary.sync();
1549
+ } finally {
1550
+ await temporary.close();
1551
+ }
1552
+ await assertExpectedTarget();
1553
+ if (expected.kind === "file") {
1554
+ await fs.rename(temporaryName, targetName);
1555
+ temporaryCreated = false;
1556
+ } else {
1557
+ try {
1558
+ await fs.link(temporaryName, targetName);
1559
+ } catch (error) {
1560
+ if (hasNodeCode(error, "EEXIST"))
1561
+ failWrite("filesystem_target_changed");
1562
+ throw error;
1563
+ }
1564
+ const removed = await fs.rm(temporaryName, { force: true }).then(() => true).catch(() => false);
1565
+ temporaryCreated = !removed;
1566
+ }
1567
+ await parent.sync().catch(() => void 0);
1568
+ } finally {
1569
+ if (temporaryCreated)
1570
+ await fs.rm(temporaryName, { force: true }).catch(() => void 0);
1571
+ await parent.close().catch(() => void 0);
1572
+ }
1573
+ }
1574
+
1575
+ // plugins/filesystem/source/directory-authority-write.ts
1576
+ async function writeWithDirectoryAuthority(input) {
1577
+ const root = await openMutationRoot(input.target);
1578
+ const expected = input.expectedVersion;
1579
+ const expectedVersion = expected.kind === "absent" ? { kind: "absent" } : {
1580
+ ...expected,
1581
+ device: String(expected.device),
1582
+ inode: String(expected.inode),
1583
+ modifiedNs: String(expected.modifiedNs),
1584
+ changedNs: String(expected.changedNs)
1585
+ };
1586
+ try {
1587
+ await runDirectoryAuthorityTask({
1588
+ directoryPath: input.target.rootPath,
1589
+ directoryFd: root.fd,
1590
+ input: {
1591
+ relativePath: input.target.relativePath,
1592
+ content: input.content,
1593
+ expectedVersion
1594
+ },
1595
+ task: commitDirectoryWrite
1596
+ });
1597
+ } catch (error) {
1598
+ if (error instanceof DirectoryAuthorityError) {
1599
+ if (error.code.startsWith("filesystem_")) {
1600
+ fail(
1601
+ error.code,
1602
+ `Safe write failed: ${input.target.logicalPath}`,
1603
+ error.data
1604
+ );
1605
+ }
1606
+ if (error.code.startsWith("directory_authority_")) {
1607
+ fail(
1608
+ "filesystem_path_changed",
1609
+ `Directory authority was lost: ${input.target.logicalPath}`
1610
+ );
1611
+ }
1612
+ }
1613
+ rethrowFilesystemError(error, "write", input.target.logicalPath);
1614
+ } finally {
1615
+ await root.close().catch(() => void 0);
1616
+ }
1617
+ }
1050
1618
 
1051
1619
  // plugins/filesystem/source/atomic-write.ts
1052
1620
  async function atomicWriteText(input) {
1053
1621
  assertMutationContentSize(input.content);
1622
+ if (requiresIsolatedDirectoryAuthority()) {
1623
+ await writeWithDirectoryAuthority(input);
1624
+ return;
1625
+ }
1054
1626
  const parent = await openMutationParent(input.target);
1055
1627
  const targetPath = `${parent.procPath}/${parent.targetName}`;
1056
1628
  const anchoredTarget = Object.freeze({
@@ -1059,12 +1631,12 @@ async function atomicWriteText(input) {
1059
1631
  absolutePath: targetPath,
1060
1632
  relativePath: parent.targetName
1061
1633
  });
1062
- const temporaryName = `.abot-${import_node_path3.posix.basename(parent.targetName)}-${(0, import_node_crypto2.randomUUID)()}.tmp`;
1634
+ const temporaryName = `.abot-${import_node_path5.posix.basename(parent.targetName)}-${(0, import_node_crypto2.randomUUID)()}.tmp`;
1063
1635
  const temporaryPath = `${parent.procPath}/${temporaryName}`;
1064
1636
  const existingMode = input.expectedVersion.kind === "file" ? input.expectedVersion.mode : void 0;
1065
1637
  let temporaryCreated = false;
1066
1638
  try {
1067
- const temporaryHandle = await (0, import_promises4.open)(temporaryPath, "wx");
1639
+ const temporaryHandle = await (0, import_promises5.open)(temporaryPath, "wx");
1068
1640
  temporaryCreated = true;
1069
1641
  try {
1070
1642
  await temporaryHandle.writeFile(input.content, "utf8");
@@ -1086,7 +1658,7 @@ async function atomicWriteText(input) {
1086
1658
  if (input.expectedVersion.kind === "file") {
1087
1659
  temporaryCreated = false;
1088
1660
  } else {
1089
- const removed = await (0, import_promises4.rm)(temporaryPath, { force: true }).then(() => true).catch(() => false);
1661
+ const removed = await (0, import_promises5.rm)(temporaryPath, { force: true }).then(() => true).catch(() => false);
1090
1662
  temporaryCreated = !removed;
1091
1663
  }
1092
1664
  await syncDirectoryBestEffort(parent.handle);
@@ -1094,7 +1666,7 @@ async function atomicWriteText(input) {
1094
1666
  rethrowFilesystemError(error, "write", input.target.logicalPath);
1095
1667
  } finally {
1096
1668
  if (temporaryCreated) {
1097
- await (0, import_promises4.rm)(temporaryPath, { force: true }).catch(() => void 0);
1669
+ await (0, import_promises5.rm)(temporaryPath, { force: true }).catch(() => void 0);
1098
1670
  }
1099
1671
  await parent.handle.close().catch(() => void 0);
1100
1672
  }
@@ -1103,11 +1675,11 @@ async function installPreparedFile(input) {
1103
1675
  const temporaryPath = `${input.parentProcPath}/${input.temporaryName}`;
1104
1676
  const targetPath = `${input.parentProcPath}/${input.targetName}`;
1105
1677
  if (input.expectedKind === "file") {
1106
- await (0, import_promises4.rename)(temporaryPath, targetPath);
1678
+ await (0, import_promises5.rename)(temporaryPath, targetPath);
1107
1679
  return;
1108
1680
  }
1109
1681
  try {
1110
- await (0, import_promises4.link)(temporaryPath, targetPath);
1682
+ await (0, import_promises5.link)(temporaryPath, targetPath);
1111
1683
  } catch (error) {
1112
1684
  if (isNodeErrorCode(error, "EEXIST")) {
1113
1685
  fail(
@@ -1124,10 +1696,13 @@ async function syncDirectoryBestEffort(handle) {
1124
1696
  } catch {
1125
1697
  }
1126
1698
  }
1699
+ function requiresIsolatedDirectoryAuthority() {
1700
+ return process.platform === "darwin";
1701
+ }
1127
1702
 
1128
1703
  // plugins/filesystem/source/draft/grounding.ts
1129
1704
  var import_node_crypto3 = require("node:crypto");
1130
- var import_node_path4 = require("node:path");
1705
+ var import_node_path6 = require("node:path");
1131
1706
  var GROUNDING_MAX_CHARS = 32768;
1132
1707
  var SNAPSHOT_MAX_CHARS = 3e4;
1133
1708
  var SNAPSHOT_SEGMENT_CHARS = Math.floor(SNAPSHOT_MAX_CHARS / 2);
@@ -1136,7 +1711,7 @@ function buildMutationGrounding(input) {
1136
1711
  const byteCount = Buffer.byteLength(input.content, "utf8");
1137
1712
  const lineCount = input.content.length ? input.content.split(/\r?\n/u).length : 0;
1138
1713
  const sha256 = (0, import_node_crypto3.createHash)("sha256").update(input.content).digest("hex");
1139
- const extension = (0, import_node_path4.extname)(input.logicalPath).toLowerCase() || "none";
1714
+ const extension = (0, import_node_path6.extname)(input.logicalPath).toLowerCase() || "none";
1140
1715
  const snapshot = projectSnapshot(input.content, input.previousContent);
1141
1716
  const summary = bound(
1142
1717
  [
@@ -1380,7 +1955,7 @@ function scopeError(message) {
1380
1955
  // plugins/filesystem/source/draft/validators.ts
1381
1956
  var import_parser = require("@babel/parser");
1382
1957
  var import_postcss = require("postcss");
1383
- var import_node_path5 = require("node:path");
1958
+ var import_node_path7 = require("node:path");
1384
1959
  var SCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([
1385
1960
  ".js",
1386
1961
  ".jsx",
@@ -1420,7 +1995,7 @@ function lineColumnAt(content, offset) {
1420
1995
  });
1421
1996
  }
1422
1997
  function scriptOptions(targetPath) {
1423
- const extension = (0, import_node_path5.extname)(targetPath).toLowerCase();
1998
+ const extension = (0, import_node_path7.extname)(targetPath).toLowerCase();
1424
1999
  const plugins = [];
1425
2000
  if ([".js", ".jsx", ".mjs", ".cjs", ".tsx"].includes(extension)) {
1426
2001
  plugins.push("jsx");
@@ -1483,7 +2058,7 @@ function foreignScriptWrapper(content, targetPath, originalError) {
1483
2058
  return parseScript(projected.join("\n"), targetPath) === void 0;
1484
2059
  };
1485
2060
  if (opening && closing && first < last && parsesWithout(first, last)) {
1486
- const extension = (0, import_node_path5.extname)(targetPath).toLowerCase();
2061
+ const extension = (0, import_node_path7.extname)(targetPath).toLowerCase();
1487
2062
  if (!originalError && [".jsx", ".tsx"].includes(extension))
1488
2063
  return void 0;
1489
2064
  return wrapperDiagnostic(lines[first], first, "opening", 2);
@@ -1501,14 +2076,14 @@ var validators = Object.freeze([
1501
2076
  id: "json",
1502
2077
  label: "strict JSON",
1503
2078
  authoritativeStructure: true,
1504
- matchesTarget: (targetPath) => (0, import_node_path5.extname)(targetPath).toLowerCase() === ".json",
2079
+ matchesTarget: (targetPath) => (0, import_node_path7.extname)(targetPath).toLowerCase() === ".json",
1505
2080
  validate: (content) => validateJson(content)
1506
2081
  }),
1507
2082
  Object.freeze({
1508
2083
  id: "css",
1509
2084
  label: "CSS",
1510
2085
  authoritativeStructure: true,
1511
- matchesTarget: (targetPath) => (0, import_node_path5.extname)(targetPath).toLowerCase() === ".css",
2086
+ matchesTarget: (targetPath) => (0, import_node_path7.extname)(targetPath).toLowerCase() === ".css",
1512
2087
  validate(content, targetPath) {
1513
2088
  try {
1514
2089
  (0, import_postcss.parse)(content, { from: targetPath });
@@ -1528,7 +2103,7 @@ var validators = Object.freeze([
1528
2103
  id: "script",
1529
2104
  label: "JavaScript/TypeScript",
1530
2105
  authoritativeStructure: true,
1531
- matchesTarget: (targetPath) => SCRIPT_EXTENSIONS.has((0, import_node_path5.extname)(targetPath).toLowerCase()),
2106
+ matchesTarget: (targetPath) => SCRIPT_EXTENSIONS.has((0, import_node_path7.extname)(targetPath).toLowerCase()),
1532
2107
  validate(content, targetPath) {
1533
2108
  const error = parseScript(content, targetPath);
1534
2109
  return foreignScriptWrapper(content, targetPath, error) ?? (error ? scriptDiagnostic(error) : void 0);
@@ -1877,17 +2452,17 @@ function delimiterRegressions(previous, updated) {
1877
2452
  ["square", "[", "]"],
1878
2453
  ["paren", "(", ")"]
1879
2454
  ];
1880
- return delimiters.flatMap(([name, open4, close]) => {
1881
- if (!previous.includes(open4) || !previous.includes(close)) return [];
1882
- const before = balance(previous, open4, close);
1883
- const after = balance(updated, open4, close);
2455
+ return delimiters.flatMap(([name, open5, close]) => {
2456
+ if (!previous.includes(open5) || !previous.includes(close)) return [];
2457
+ const before = balance(previous, open5, close);
2458
+ const after = balance(updated, open5, close);
1884
2459
  return before === 0 && after !== 0 ? [`${name} delimiter balance changed from 0 to ${after}`] : [];
1885
2460
  });
1886
2461
  }
1887
- function balance(content, open4, close) {
2462
+ function balance(content, open5, close) {
1888
2463
  let count = 0;
1889
2464
  for (const character of content) {
1890
- if (character === open4) count += 1;
2465
+ if (character === open5) count += 1;
1891
2466
  else if (character === close) count -= 1;
1892
2467
  }
1893
2468
  return count;
@@ -1933,7 +2508,7 @@ function getProcessFilesystemMutationCoordinator() {
1933
2508
  }
1934
2509
 
1935
2510
  // plugins/filesystem/source/path-service.ts
1936
- var import_node_path6 = require("node:path");
2511
+ var import_node_path8 = require("node:path");
1937
2512
  var FILESYSTEM_LOCATIONS = Object.freeze([
1938
2513
  "agent_work",
1939
2514
  "workspace"
@@ -1951,7 +2526,7 @@ function logicalParent(logicalPath) {
1951
2526
  if (logicalPath === "." || logicalPath === "workspace") {
1952
2527
  return logicalPath;
1953
2528
  }
1954
- return import_node_path6.posix.dirname(logicalPath);
2529
+ return import_node_path8.posix.dirname(logicalPath);
1955
2530
  }
1956
2531
  function createFilesystemPathService(fallbackResolver) {
1957
2532
  return Object.freeze({
@@ -1966,7 +2541,7 @@ function createFilesystemPathService(fallbackResolver) {
1966
2541
  },
1967
2542
  sibling(target, name, context) {
1968
2543
  const parent = logicalParent(target.logicalPath);
1969
- const logicalPath = parent === "." ? name : import_node_path6.posix.join(parent, name);
2544
+ const logicalPath = parent === "." ? name : import_node_path8.posix.join(parent, name);
1970
2545
  return resolveWith(resolverFor(fallbackResolver, context), logicalPath);
1971
2546
  }
1972
2547
  });