@akira-tl/forgerelay 0.8.8 → 0.8.9

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 (246) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +10 -18
  3. package/capabilities/host-integration/GUIDE.md +2 -2
  4. package/dist/activity/{audit-store.js → history/audit-store.js} +129 -21
  5. package/dist/activity/history/bash-output-store.js +250 -0
  6. package/dist/activity/{host-turn-store.js → history/host-turn-store.js} +4 -1
  7. package/dist/activity/{query-service.js → history/query-service.js} +13 -7
  8. package/dist/activity/{lifecycle.js → runtime/lifecycle.js} +1 -1
  9. package/dist/activity/{mcp-query-tools.js → runtime/mcp-query-tools.js} +3 -3
  10. package/dist/activity/storage/history.js +12 -0
  11. package/dist/activity/storage/paths.js +56 -0
  12. package/dist/activity/storage/segmented-log.js +149 -0
  13. package/dist/cli/setup-support.js +116 -0
  14. package/dist/cli.js +18 -126
  15. package/dist/lsp/code-intelligence.js +1 -1
  16. package/dist/lsp/test-support/server-fixture.js +9 -9
  17. package/dist/mcp/filesystem/filesystem-tools.js +245 -0
  18. package/dist/mcp/hooks/command-runner.js +79 -0
  19. package/dist/{hook-cli.js → mcp/hooks/hook-cli.js} +1 -1
  20. package/dist/{hooks.js → mcp/hooks/hooks.js} +3 -80
  21. package/dist/{oauth-provider.js → mcp/oauth/oauth-provider.js} +1 -1
  22. package/dist/{oauth-store.js → mcp/oauth/oauth-store.js} +5 -4
  23. package/dist/{operations → mcp/operations}/native-bulk-mutations.js +2 -2
  24. package/dist/mcp/panel/app.js +143 -0
  25. package/dist/{mcp-app-template.js → mcp/panel/mcp-app-template.js} +2 -38
  26. package/dist/mcp/process/runtime.js +257 -0
  27. package/dist/mcp/process/tools.js +346 -0
  28. package/dist/mcp/server/core/activity-support.js +70 -0
  29. package/dist/{capabilities.js → mcp/server/core/capabilities.js} +5 -3
  30. package/dist/{capability-registry.js → mcp/server/core/capability-registry.js} +2 -2
  31. package/dist/mcp/server/core/capability-support.js +90 -0
  32. package/dist/mcp/server/core/schemas.js +216 -0
  33. package/dist/mcp/server/core/tool-support.js +207 -0
  34. package/dist/mcp/server/core/version.js +9 -0
  35. package/dist/mcp/server/operations/runtime/filesystem-tools.js +400 -0
  36. package/dist/mcp/server/operations/runtime/operation-runtime.js +523 -0
  37. package/dist/mcp/server/transport/http-server.js +301 -0
  38. package/dist/mcp/server/transport/http-support.js +43 -0
  39. package/dist/mcp/server/workspace/runtime/workspace-open-presentation.js +222 -0
  40. package/dist/mcp/server/workspace/runtime/workspace-open-schema.js +187 -0
  41. package/dist/mcp/server/workspace/runtime/workspace-open.js +552 -0
  42. package/dist/mcp/server/workspace/runtime/workspace-tools.js +601 -0
  43. package/dist/{config.js → runtime/config/config.js} +3 -3
  44. package/dist/{user-config.js → runtime/config/user-config.js} +14 -54
  45. package/dist/{db → runtime/state/db}/client.js +1 -1
  46. package/dist/{db → runtime/state/db}/migrations.js +34 -3
  47. package/dist/runtime/state/lock/file-lock.js +130 -0
  48. package/dist/runtime/testing/server-fixture.js +190 -0
  49. package/dist/server.js +116 -4202
  50. package/dist/subagents/providers/adapters/claude.js +86 -52
  51. package/dist/subagents/providers/adapters/codex.js +103 -39
  52. package/dist/subagents/providers/adapters/opencode.js +114 -84
  53. package/dist/subagents/providers/adapters/pi.js +59 -8
  54. package/dist/subagents/providers/availability.js +15 -30
  55. package/dist/subagents/providers/runtime/external-command.js +56 -0
  56. package/dist/subagents/sessions/capability.js +1 -1
  57. package/dist/subagents/sessions/execution.js +1 -1
  58. package/dist/subagents/sessions/mcp/activity-audit-test-support.js +30 -0
  59. package/dist/subagents/sessions/store.js +1 -1
  60. package/dist/ui/.vite/manifest.json +342 -410
  61. package/dist/ui/activity-panel-app.html +2 -4
  62. package/dist/ui/assets/activity-panel-app-7Xe0alhm.css +1 -0
  63. package/dist/ui/assets/activity-panel-app-Sl1Jro8v.js +115 -0
  64. package/dist/ui/assets/angular-html-B_yn91wW.js +1 -0
  65. package/dist/ui/assets/{angular-ts-Bxh4-O1-.js → angular-ts-DSgtloKz.js} +1 -1
  66. package/dist/ui/assets/{apl-BmYHKQ6m.js → apl-NatWtF8X.js} +1 -1
  67. package/dist/ui/assets/{astro-C51vqDKq.js → astro-BYFEVBuN.js} +1 -1
  68. package/dist/ui/assets/{blade-CdhVsmwq.js → blade-DoO7yvMR.js} +1 -1
  69. package/dist/ui/assets/c-Rl2hMCcg.js +1 -0
  70. package/dist/ui/assets/{cobol-Cf6azoN_.js → cobol-ByC5mWiB.js} +1 -1
  71. package/dist/ui/assets/{coffee-vVdGzlmt.js → coffee-Dez77Qov.js} +1 -1
  72. package/dist/ui/assets/cpp-DtaAQT9h.js +1 -0
  73. package/dist/ui/assets/{crystal-5UZy6KIX.js → crystal-Bgmbf8ec.js} +1 -1
  74. package/dist/ui/assets/css-C1tjBtVN.js +1 -0
  75. package/dist/ui/assets/{edge-CESgo4ia.js → edge-DeH6u8Wg.js} +1 -1
  76. package/dist/ui/assets/{elixir-9FKfw4cJ.js → elixir-_H3KnmWT.js} +1 -1
  77. package/dist/ui/assets/{elm-Dv7A0aLa.js → elm-CsCe3U28.js} +1 -1
  78. package/dist/ui/assets/{erb-DHFmDvM0.js → erb-CbM-L2g8.js} +1 -1
  79. package/dist/ui/assets/{git-rebase-utbU6CzV.js → git-rebase-D0s5pDh9.js} +1 -1
  80. package/dist/ui/assets/{glimmer-js-t2kiCkyB.js → glimmer-js-BfOToq_A.js} +1 -1
  81. package/dist/ui/assets/{glimmer-ts-F0Jv5okV.js → glimmer-ts-CCUOkL2K.js} +1 -1
  82. package/dist/ui/assets/glsl-DH4ec9dE.js +1 -0
  83. package/dist/ui/assets/graphql-DilAMBoI.js +1 -0
  84. package/dist/ui/assets/{hack-8yjdbaSA.js → hack-BDkNDZlF.js} +1 -1
  85. package/dist/ui/assets/haml-D_QBp6K7.js +1 -0
  86. package/dist/ui/assets/{handlebars-BBFEg4Lo.js → handlebars-DePUrTpC.js} +1 -1
  87. package/dist/ui/assets/heavy-payload-DOwZpO6n.js +290 -0
  88. package/dist/ui/assets/html-By4dNnM4.js +1 -0
  89. package/dist/ui/assets/{html-derivative-DJAQcZyc.js → html-derivative-DDw9Ef4Q.js} +1 -1
  90. package/dist/ui/assets/{http-Dg5LSYRK.js → http-B0QxWc9M.js} +1 -1
  91. package/dist/ui/assets/{hurl-Y5uYzMZR.js → hurl-vMQ4lda1.js} +1 -1
  92. package/dist/ui/assets/java-DYRe2lWG.js +1 -0
  93. package/dist/ui/assets/javascript-CxyGqwcL.js +1 -0
  94. package/dist/ui/assets/{jinja-Bt30h8Ik.js → jinja-JUwV-fZt.js} +1 -1
  95. package/dist/ui/assets/{jison-D5uZ1Nyo.js → jison-7ZqCEvS8.js} +1 -1
  96. package/dist/ui/assets/json-dbltgiiA.js +1 -0
  97. package/dist/ui/assets/jsx-oDopT7YQ.js +1 -0
  98. package/dist/ui/assets/{julia-76hRaaGz.js → julia-CkKiNSav.js} +1 -1
  99. package/dist/ui/assets/{just-CDE7W0vW.js → just-DuqCAKJ3.js} +1 -1
  100. package/dist/ui/assets/{latex-CVO2Byab.js → latex-sudcRDSn.js} +1 -1
  101. package/dist/ui/assets/{liquid-CA-AS3EX.js → liquid-Di-08Js7.js} +1 -1
  102. package/dist/ui/assets/lua-YlqdMoV0.js +1 -0
  103. package/dist/ui/assets/{marko-_BWrPfny.js → marko-CJRNyJDb.js} +1 -1
  104. package/dist/ui/assets/{mdc-PyJv85eS.js → mdc-t12CzZHs.js} +1 -1
  105. package/dist/ui/assets/{nginx-DAWVw8yu.js → nginx-57-b4XwT.js} +1 -1
  106. package/dist/ui/assets/{nim-CKE1dzpU.js → nim-BzrswYQa.js} +1 -1
  107. package/dist/ui/assets/{perl-BBhWva19.js → perl-D9JR_iIh.js} +1 -1
  108. package/dist/ui/assets/{php-ChIeaAoF.js → php-Py2gFHil.js} +1 -1
  109. package/dist/ui/assets/{pug-CMgI5afi.js → pug-PzLLy0h1.js} +1 -1
  110. package/dist/ui/assets/{qml-CjxTkcFH.js → qml-By8fwgV4.js} +1 -1
  111. package/dist/ui/assets/r-CcezTbLq.js +1 -0
  112. package/dist/ui/assets/{razor-i4DbHr8p.js → razor-dG-vdhL_.js} +1 -1
  113. package/dist/ui/assets/regexp-BlsQ-N_8.js +1 -0
  114. package/dist/ui/assets/{rst-oy_97Kl4.js → rst-C2awDCat.js} +1 -1
  115. package/dist/ui/assets/{ruby-C5zYZIyl.js → ruby-zA2W_49d.js} +1 -1
  116. package/dist/ui/assets/{sas-BnMEh2S3.js → sas-D49bhyaN.js} +1 -1
  117. package/dist/ui/assets/scss-BQb-cp01.js +1 -0
  118. package/dist/ui/assets/shellscript-Dga4H_Ni.js +1 -0
  119. package/dist/ui/assets/{shellsession-BpE5o7_3.js → shellsession-n3-5CqcF.js} +1 -1
  120. package/dist/ui/assets/{soy-COesmhTY.js → soy-XYBOf_BA.js} +1 -1
  121. package/dist/ui/assets/sql-ET4u5Cpl.js +1 -0
  122. package/dist/ui/assets/{stata-CGQEuSZq.js → stata-CLHcJHO_.js} +1 -1
  123. package/dist/ui/assets/{surrealql-Bz4JbU-9.js → surrealql-BdjQ60T4.js} +1 -1
  124. package/dist/ui/assets/{svelte-1jM2ejXj.js → svelte-B2RPtKJe.js} +1 -1
  125. package/dist/ui/assets/{templ-C-VwELcp.js → templ-CrByPW_W.js} +1 -1
  126. package/dist/ui/assets/{tex-t1rUiQCm.js → tex-DZBkg363.js} +1 -1
  127. package/dist/ui/assets/{ts-tags-Bewoa6pS.js → ts-tags-DJR3Gphb.js} +1 -1
  128. package/dist/ui/assets/tsx-CajzROyy.js +1 -0
  129. package/dist/ui/assets/{twig-DVg-vELl.js → twig-BZjk5Zda.js} +1 -1
  130. package/dist/ui/assets/typescript-B-EWToLj.js +1 -0
  131. package/dist/ui/assets/{vue-wPQ7UlMy.js → vue-D_rHCCr8.js} +1 -1
  132. package/dist/ui/assets/{vue-html-BHtJ8geX.js → vue-html-CC4WlvVt.js} +1 -1
  133. package/dist/ui/assets/{vue-vine-CNSGAWwc.js → vue-vine-BgNMVgpk.js} +1 -1
  134. package/dist/ui/assets/xml-BI86-WbH.js +1 -0
  135. package/dist/ui/assets/{xsl-3_vJ27aE.js → xsl-DXeLZV4J.js} +1 -1
  136. package/dist/ui/assets/yaml-60_PFlWa.js +1 -0
  137. package/dist/workspaces/bootstrap.js +72 -0
  138. package/dist/workspaces/context.js +302 -0
  139. package/dist/workspaces/conversation-test-support.js +86 -0
  140. package/dist/{git-worktrees.js → workspaces/git/git-worktrees.js} +1 -1
  141. package/dist/workspaces/inventory.js +131 -0
  142. package/dist/workspaces/paths.js +55 -0
  143. package/dist/{remote-auth.js → workspaces/relay/auth/remote-auth.js} +2 -2
  144. package/dist/workspaces/relay/result-support.js +111 -0
  145. package/dist/workspaces/relay/tests/test-support.js +203 -0
  146. package/dist/{remote-mcp-connection-pool.js → workspaces/relay/transport/remote-mcp-connection-pool.js} +1 -1
  147. package/dist/workspaces/relay/types.js +1 -0
  148. package/dist/{remote-workspace-relay.js → workspaces/relay/workspace-relay.js} +23 -172
  149. package/dist/workspaces/resources/skills.js +285 -0
  150. package/dist/{review-checkpoints.js → workspaces/review/review-checkpoints.js} +2 -2
  151. package/dist/workspaces/sessions.js +457 -0
  152. package/dist/{workspace-store.js → workspaces/state/workspace-store.js} +2 -2
  153. package/dist/workspaces.js +68 -995
  154. package/docs/chatgpt-coding-workflow.md +3 -11
  155. package/docs/configuration.md +12 -25
  156. package/docs/gotchas.md +0 -30
  157. package/docs/roadmap.md +6 -10
  158. package/docs/security.md +1 -5
  159. package/docs/setup.md +0 -11
  160. package/package.json +6 -8
  161. package/scripts/ci/architecture.mjs +109 -0
  162. package/scripts/ci/verify.mjs +5 -0
  163. package/scripts/debug/accept/bootstrap.mjs +326 -0
  164. package/scripts/debug/accept/harness.mjs +76 -0
  165. package/scripts/debug/accept/support.mjs +432 -0
  166. package/scripts/debug/accept.mjs +43 -806
  167. package/scripts/debug/relay-accept/support.mjs +135 -0
  168. package/scripts/debug/relay-accept.mjs +26 -115
  169. package/scripts/debug/traffic/support.mjs +167 -0
  170. package/scripts/debug/traffic/traffic-audit.mjs +4 -161
  171. package/scripts/{lsp-interop-support.test.mjs → lsp/interop-support.test.mjs} +1 -1
  172. package/scripts/{lsp-interop.mjs → lsp/interop.mjs} +3 -3
  173. package/scripts/wiki/sync.mjs +21 -10
  174. package/dist/activity/bash-output-store.js +0 -127
  175. package/dist/pi-tools.js +0 -110
  176. package/dist/skills.js +0 -127
  177. package/dist/ui/assets/activity-panel-app-7AckaxIR.js +0 -2
  178. package/dist/ui/assets/angular-html-BkgDQl-G.js +0 -1
  179. package/dist/ui/assets/c-IBzBpxAO.js +0 -1
  180. package/dist/ui/assets/chunk-EyZ2wyi3.js +0 -1
  181. package/dist/ui/assets/cpp-CVHeO-Jk.js +0 -1
  182. package/dist/ui/assets/css-DEfus9J5.js +0 -1
  183. package/dist/ui/assets/glsl-_ooCjaeB.js +0 -1
  184. package/dist/ui/assets/graphql-B9LqP-cY.js +0 -1
  185. package/dist/ui/assets/haml-BU5EoZBn.js +0 -1
  186. package/dist/ui/assets/heavy-payload-Bol1_mcs.js +0 -4
  187. package/dist/ui/assets/html-D-C6YZk4.js +0 -1
  188. package/dist/ui/assets/java-ppHvycj5.js +0 -1
  189. package/dist/ui/assets/javascript-DDTjKLlQ.js +0 -1
  190. package/dist/ui/assets/json-Cw91r8h1.js +0 -1
  191. package/dist/ui/assets/jsx-04X2FT_1.js +0 -1
  192. package/dist/ui/assets/lua-CiyBp52Y.js +0 -1
  193. package/dist/ui/assets/r-DfFga4si.js +0 -1
  194. package/dist/ui/assets/regexp-iC9_nbSI.js +0 -1
  195. package/dist/ui/assets/review-payload-BqJp0c5e.js +0 -1
  196. package/dist/ui/assets/scrollbar-CvE-I-jG.js +0 -287
  197. package/dist/ui/assets/scss-BfZXsAWQ.js +0 -1
  198. package/dist/ui/assets/shellscript-BC2srNaB.js +0 -1
  199. package/dist/ui/assets/sql-Ccv_yeUm.js +0 -1
  200. package/dist/ui/assets/tsx-CTXzrBkN.js +0 -1
  201. package/dist/ui/assets/typescript--ElHoFkw.js +0 -1
  202. package/dist/ui/assets/workspace-app-BLW7p6IZ.js +0 -114
  203. package/dist/ui/assets/workspace-app-BjNqR0en.js +0 -1
  204. package/dist/ui/assets/workspace-app-CmaYU4DW.js +0 -3
  205. package/dist/ui/assets/workspace-app-D2bJ5fjt.css +0 -1
  206. package/dist/ui/assets/workspace-lifecycle-app-BVbI2Ilf.js +0 -1
  207. package/dist/ui/assets/xml-JnmX6vyS.js +0 -1
  208. package/dist/ui/assets/yaml-OAcZkP-w.js +0 -1
  209. package/dist/ui/workspace-app.html +0 -18
  210. package/dist/ui/workspace-lifecycle-app.html +0 -18
  211. package/docs/agent-profile-schema.md +0 -114
  212. package/docs/artifact-exchange.md +0 -65
  213. package/docs/versioning.md +0 -205
  214. /package/capabilities/{managed-worktrees → workspace/managed-worktrees}/GUIDE.md +0 -0
  215. /package/capabilities/{workspace-tasks → workspace/workspace-tasks}/GUIDE.md +0 -0
  216. /package/dist/activity/{process-output-audit.js → runtime/process-output-audit.js} +0 -0
  217. /package/dist/{artifact-error.js → mcp/artifacts/artifact-error.js} +0 -0
  218. /package/dist/{artifact-tools.js → mcp/artifacts/artifact-tools.js} +0 -0
  219. /package/dist/{incoming-artifacts.js → mcp/artifacts/incoming-artifacts.js} +0 -0
  220. /package/dist/{advertised-files.js → mcp/filesystem/advertised-files.js} +0 -0
  221. /package/dist/{apply-patch.js → mcp/filesystem/apply-patch.js} +0 -0
  222. /package/dist/{file-mutations.js → mcp/filesystem/file-mutations.js} +0 -0
  223. /package/dist/{roots.js → mcp/filesystem/roots.js} +0 -0
  224. /package/dist/{oauth → mcp/oauth}/public-url.js +0 -0
  225. /package/dist/{oauth → mcp/oauth}/router.js +0 -0
  226. /package/dist/{operations → mcp/operations}/batch/executor.js +0 -0
  227. /package/dist/{operations → mcp/operations}/batch/scheduler.js +0 -0
  228. /package/dist/{operations → mcp/operations}/batch/types.js +0 -0
  229. /package/dist/{operations → mcp/operations}/bulk-mutation.js +0 -0
  230. /package/dist/{operations → mcp/operations}/bulk-read.js +0 -0
  231. /package/dist/{operations → mcp/operations}/core-operation-executor.js +0 -0
  232. /package/dist/{process-platform.js → mcp/process/process-platform.js} +0 -0
  233. /package/dist/{process-sessions.js → mcp/process/process-sessions.js} +0 -0
  234. /package/dist/{request-meta.js → mcp/request-meta.js} +0 -0
  235. /package/dist/{mcp-sessions.js → mcp/server/transport/mcp-sessions.js} +0 -0
  236. /package/dist/{server-shutdown.js → mcp/server/transport/server-shutdown.js} +0 -0
  237. /package/dist/{logger.js → runtime/logging/logger.js} +0 -0
  238. /package/dist/{db → runtime/state/db}/schema.js +0 -0
  239. /package/dist/{composite-activity.js → workspaces/composite/composite-activity.js} +0 -0
  240. /package/dist/{composite-workspaces.js → workspaces/composite/composite-workspaces.js} +0 -0
  241. /package/dist/{git.js → workspaces/git/git.js} +0 -0
  242. /package/dist/{workspace-presentation.js → workspaces/presentation/workspace-presentation.js} +0 -0
  243. /package/dist/{remote-transport.js → workspaces/relay/transport/remote-transport.js} +0 -0
  244. /package/dist/{workspace-task-reminders.js → workspaces/tasks/workspace-task-reminders.js} +0 -0
  245. /package/dist/{workspace-tasks.js → workspaces/tasks/workspace-tasks.js} +0 -0
  246. /package/scripts/{lsp-interop-support.mjs → lsp/interop-support.mjs} +0 -0
@@ -0,0 +1,523 @@
1
+ import { CapabilityError } from "../../core/capability-registry.js";
2
+ import { deletePath, renamePath } from "../../../filesystem/file-mutations.js";
3
+ import { editFileTool, readFileTool, writeFileTool } from "../../../filesystem/filesystem-tools.js";
4
+ import { runToolWithHooks } from "../../../hooks/hooks.js";
5
+ import { toolNames } from "../../../server-instructions.js";
6
+ import { BatchExecutor } from "../../../operations/batch/executor.js";
7
+ import { NativeBulkMutationExecutor } from "../../../operations/native-bulk-mutations.js";
8
+ import { createCoreOperationExecutor, } from "../../../operations/core-operation-executor.js";
9
+ import { formatAgentsPath } from "../../../../workspaces.js";
10
+ import { markReturnedOutput, processActivityOutcome, processToolResponse, } from "../../../process/runtime.js";
11
+ import { capabilityActivityAuditRequest, capabilityActivityAuditResult } from "../../../../subagents/sessions/mcp/audit.js";
12
+ import { activityRelationFor, activityRequestFor, runActivityTool, runActivityToolWithHooks, standardActivityOutcome, } from "../../core/activity-support.js";
13
+ import { capabilityContextFor, workspaceHookInvocation } from "../../core/capability-support.js";
14
+ import { assertWorkspaceInstructionsLoadedBeforeSideEffect, contentLineCount, contentText, countDiffStats, formatDiscoveredWorkspaceInstructions, logFailedToolResponse, logToolCall, newFilePatch, textBlock, textSummary, toolResultContent, toolResultIsError, toolResultText, workspaceLogContext, } from "../../core/tool-support.js";
15
+ export function createOperationRuntime(options) {
16
+ const { config, workspaces, activityLifecycle, hooks, processSessions, bashOutputStore, capabilityRegistry, hostScopeIdFor } = options;
17
+ const coreOperations = createCoreOperationExecutor({
18
+ read: async (input, context) => {
19
+ const { workspaceId, ...readInput } = input;
20
+ const workspace = workspaces.getWorkspace(workspaceId);
21
+ return runActivityToolWithHooks(activityLifecycle, hooks, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), activityRequestFor(input, context), {
22
+ signal: context.signal,
23
+ tool: toolNames.read,
24
+ invocation: workspaceHookInvocation(workspace),
25
+ payload: { path: readInput.path, offset: readInput.offset, limit: readInput.limit },
26
+ isFailure: toolResultIsError,
27
+ operation: async () => {
28
+ const startedAt = performance.now();
29
+ const readPath = workspaces.resolveReadPath(workspace, readInput.path);
30
+ const discoveredInstructions = (await workspaces.discoverPathInstructions(workspace, readPath.absolutePath)).filter((file) => file.path !== readPath.absolutePath);
31
+ const response = await readFileTool({ ...readInput, path: readPath.absolutePath }, {
32
+ cwd: workspace.root,
33
+ root: workspace.root,
34
+ readRoots: readPath.readRoots,
35
+ });
36
+ if (response.isError) {
37
+ logFailedToolResponse(config, {
38
+ tool: toolNames.read,
39
+ ...workspaceLogContext(workspace, context.sessionId),
40
+ path: readInput.path,
41
+ }, response.content, startedAt);
42
+ return response;
43
+ }
44
+ workspaces.markReadPathLoaded(workspace, readPath);
45
+ const discoveredInstructionContent = discoveredInstructions.length > 0
46
+ ? textBlock(formatDiscoveredWorkspaceInstructions(discoveredInstructions, workspace.root))
47
+ : undefined;
48
+ const content = discoveredInstructionContent
49
+ ? [discoveredInstructionContent, ...response.content]
50
+ : response.content;
51
+ const summary = {
52
+ ...textSummary(response.content),
53
+ offset: readInput.offset ?? 1,
54
+ limited: readInput.limit !== undefined,
55
+ };
56
+ logToolCall(config, {
57
+ tool: toolNames.read,
58
+ ...workspaceLogContext(workspace, context.sessionId),
59
+ path: readInput.path,
60
+ success: true,
61
+ durationMs: Math.round(performance.now() - startedAt),
62
+ });
63
+ return {
64
+ ...response,
65
+ content,
66
+ _meta: {
67
+ tool: toolNames.read,
68
+ card: {
69
+ workspaceId,
70
+ path: readInput.path,
71
+ summary,
72
+ payload: { content: response.content },
73
+ },
74
+ },
75
+ structuredContent: {
76
+ result: contentText(content),
77
+ ...(discoveredInstructions.length > 0
78
+ ? {
79
+ agentsFiles: discoveredInstructions.map((file) => ({
80
+ path: formatAgentsPath(file.path, workspace.root),
81
+ content: file.content,
82
+ })),
83
+ }
84
+ : {}),
85
+ },
86
+ };
87
+ },
88
+ }, activityRelationFor(context));
89
+ },
90
+ write: async (input, context) => {
91
+ const { workspaceId, ...writeInput } = input;
92
+ const workspace = workspaces.getWorkspace(workspaceId);
93
+ return runActivityToolWithHooks(activityLifecycle, hooks, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), activityRequestFor(input, context), {
94
+ signal: context.signal,
95
+ tool: toolNames.write,
96
+ invocation: workspaceHookInvocation(workspace),
97
+ payload: { path: writeInput.path },
98
+ isFailure: toolResultIsError,
99
+ changedPaths: (result) => toolResultIsError(result) ? [] : [writeInput.path],
100
+ operation: async () => {
101
+ const startedAt = performance.now();
102
+ await assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, [writeInput.path]);
103
+ const response = await writeFileTool(writeInput, {
104
+ cwd: workspace.root,
105
+ root: workspace.root,
106
+ fileRoots: workspaces.fileToolRoots(workspace),
107
+ });
108
+ if (response.isError) {
109
+ logFailedToolResponse(config, {
110
+ tool: toolNames.write,
111
+ ...workspaceLogContext(workspace, context.sessionId),
112
+ path: writeInput.path,
113
+ }, response.content, startedAt);
114
+ return response;
115
+ }
116
+ const patch = newFilePatch(writeInput.path, writeInput.content);
117
+ const stats = countDiffStats(patch);
118
+ const summary = {
119
+ ...stats,
120
+ lines: contentLineCount(writeInput.content),
121
+ characters: writeInput.content.length,
122
+ };
123
+ logToolCall(config, {
124
+ tool: toolNames.write,
125
+ ...workspaceLogContext(workspace, context.sessionId),
126
+ path: writeInput.path,
127
+ success: true,
128
+ durationMs: Math.round(performance.now() - startedAt),
129
+ });
130
+ return {
131
+ ...response,
132
+ _meta: {
133
+ tool: toolNames.write,
134
+ card: {
135
+ workspaceId,
136
+ path: writeInput.path,
137
+ summary,
138
+ payload: {
139
+ content: response.content,
140
+ patch,
141
+ },
142
+ },
143
+ },
144
+ structuredContent: {
145
+ result: contentText(response.content),
146
+ },
147
+ };
148
+ },
149
+ }, activityRelationFor(context));
150
+ },
151
+ edit: async (input, context) => {
152
+ const { workspaceId, ...editInput } = input;
153
+ const workspace = workspaces.getWorkspace(workspaceId);
154
+ return runActivityToolWithHooks(activityLifecycle, hooks, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), activityRequestFor(input, context), {
155
+ signal: context.signal,
156
+ tool: toolNames.edit,
157
+ invocation: workspaceHookInvocation(workspace),
158
+ payload: { path: editInput.path, editCount: editInput.edits.length },
159
+ isFailure: toolResultIsError,
160
+ changedPaths: (result) => toolResultIsError(result) ? [] : [editInput.path],
161
+ operation: async () => {
162
+ const startedAt = performance.now();
163
+ await assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, [editInput.path]);
164
+ const response = await editFileTool(editInput, {
165
+ cwd: workspace.root,
166
+ root: workspace.root,
167
+ fileRoots: workspaces.fileToolRoots(workspace),
168
+ });
169
+ if (response.isError) {
170
+ logFailedToolResponse(config, {
171
+ tool: toolNames.edit,
172
+ ...workspaceLogContext(workspace, context.sessionId),
173
+ path: editInput.path,
174
+ }, response.content, startedAt);
175
+ return response;
176
+ }
177
+ const stats = countDiffStats(response.details?.patch ?? response.details?.diff);
178
+ const summary = {
179
+ ...stats,
180
+ editCount: editInput.edits.length,
181
+ };
182
+ const editResultText = `Edited ${editInput.path} (+${stats.additions} -${stats.removals}).`;
183
+ const editContent = [textBlock(editResultText)];
184
+ logToolCall(config, {
185
+ tool: toolNames.edit,
186
+ ...workspaceLogContext(workspace, context.sessionId),
187
+ path: editInput.path,
188
+ success: true,
189
+ durationMs: Math.round(performance.now() - startedAt),
190
+ });
191
+ return {
192
+ content: editContent,
193
+ _meta: {
194
+ tool: toolNames.edit,
195
+ card: {
196
+ workspaceId,
197
+ path: editInput.path,
198
+ summary,
199
+ payload: {
200
+ diff: response.details?.diff,
201
+ patch: response.details?.patch,
202
+ },
203
+ },
204
+ },
205
+ structuredContent: {
206
+ status: "applied",
207
+ result: contentText(editContent),
208
+ },
209
+ };
210
+ },
211
+ }, activityRelationFor(context));
212
+ },
213
+ rename: async (input, context) => {
214
+ const { workspaceId, path, newPath } = input;
215
+ const workspace = workspaces.getWorkspace(workspaceId);
216
+ return runActivityToolWithHooks(activityLifecycle, hooks, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), activityRequestFor(input, context), {
217
+ signal: context.signal,
218
+ tool: toolNames.rename,
219
+ invocation: workspaceHookInvocation(workspace),
220
+ payload: { path, newPath, paths: [path, newPath] },
221
+ changedPaths: () => [path, newPath],
222
+ operation: async () => {
223
+ const startedAt = performance.now();
224
+ try {
225
+ await assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, [path, newPath]);
226
+ await renamePath({ path, newPath }, {
227
+ cwd: workspace.root,
228
+ allowedRoots: workspaces.fileToolRoots(workspace),
229
+ });
230
+ const result = `Renamed ${path} to ${newPath}.`;
231
+ const content = [textBlock(result)];
232
+ logToolCall(config, {
233
+ tool: toolNames.rename,
234
+ ...workspaceLogContext(workspace, context.sessionId),
235
+ path: `${path} -> ${newPath}`,
236
+ success: true,
237
+ durationMs: Math.round(performance.now() - startedAt),
238
+ });
239
+ return {
240
+ content,
241
+ _meta: {
242
+ tool: toolNames.rename,
243
+ card: {
244
+ workspaceId,
245
+ path: newPath,
246
+ summary: { previousPath: path },
247
+ payload: { content },
248
+ },
249
+ },
250
+ structuredContent: {
251
+ result,
252
+ status: "renamed",
253
+ path,
254
+ newPath,
255
+ },
256
+ };
257
+ }
258
+ catch (error) {
259
+ logToolCall(config, {
260
+ tool: toolNames.rename,
261
+ ...workspaceLogContext(workspace, context.sessionId),
262
+ path: `${path} -> ${newPath}`,
263
+ success: false,
264
+ durationMs: Math.round(performance.now() - startedAt),
265
+ error: error instanceof Error ? error.message : String(error),
266
+ });
267
+ throw error;
268
+ }
269
+ },
270
+ }, activityRelationFor(context));
271
+ },
272
+ delete: async (input, context) => {
273
+ const { workspaceId, path, recursive } = input;
274
+ const workspace = workspaces.getWorkspace(workspaceId);
275
+ return runActivityToolWithHooks(activityLifecycle, hooks, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), activityRequestFor(input, context), {
276
+ signal: context.signal,
277
+ tool: toolNames.delete,
278
+ invocation: workspaceHookInvocation(workspace),
279
+ payload: { path, recursive: recursive ?? false },
280
+ changedPaths: () => [path],
281
+ operation: async () => {
282
+ const startedAt = performance.now();
283
+ try {
284
+ await assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, [path]);
285
+ const deleted = await deletePath({ path, recursive }, {
286
+ cwd: workspace.root,
287
+ allowedRoots: workspaces.fileToolRoots(workspace),
288
+ });
289
+ const result = `Deleted ${path}${deleted.recursive ? " recursively" : ""}.`;
290
+ const content = [textBlock(result)];
291
+ logToolCall(config, {
292
+ tool: toolNames.delete,
293
+ ...workspaceLogContext(workspace, context.sessionId),
294
+ path,
295
+ success: true,
296
+ durationMs: Math.round(performance.now() - startedAt),
297
+ });
298
+ return {
299
+ content,
300
+ _meta: {
301
+ tool: toolNames.delete,
302
+ card: {
303
+ workspaceId,
304
+ path,
305
+ summary: { recursive: deleted.recursive },
306
+ payload: { content },
307
+ },
308
+ },
309
+ structuredContent: {
310
+ result,
311
+ status: "deleted",
312
+ path,
313
+ recursive: deleted.recursive,
314
+ },
315
+ };
316
+ }
317
+ catch (error) {
318
+ logToolCall(config, {
319
+ tool: toolNames.delete,
320
+ ...workspaceLogContext(workspace, context.sessionId),
321
+ path,
322
+ success: false,
323
+ durationMs: Math.round(performance.now() - startedAt),
324
+ error: error instanceof Error ? error.message : String(error),
325
+ });
326
+ throw error;
327
+ }
328
+ },
329
+ }, activityRelationFor(context));
330
+ },
331
+ shellRun: async (input, context) => {
332
+ const { workspaceId, command, surface, tty, columns, rows, workingDirectory, yieldTimeMs, timeoutMs, maxOutputTokens, } = input;
333
+ const workspace = workspaces.getWorkspace(workspaceId);
334
+ const activityRequest = surface === "exec_command"
335
+ ? {
336
+ workspaceId,
337
+ cmd: command,
338
+ tty,
339
+ columns,
340
+ rows,
341
+ workingDirectory,
342
+ yieldTimeMs,
343
+ timeoutMs,
344
+ maxOutputTokens,
345
+ }
346
+ : {
347
+ workspaceId,
348
+ action: "run",
349
+ command,
350
+ tty,
351
+ columns,
352
+ rows,
353
+ workingDirectory,
354
+ yieldTimeMs,
355
+ timeoutMs,
356
+ maxOutputTokens,
357
+ };
358
+ let undeliveredProcessId;
359
+ const activityResult = await runActivityTool(activityLifecycle, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), surface, activityRequestFor(activityRequest, context), async (activityContext) => {
360
+ try {
361
+ const result = await runToolWithHooks(hooks, {
362
+ signal: context.signal,
363
+ tool: surface,
364
+ invocation: workspaceHookInvocation(workspace),
365
+ payload: surface === "exec_command"
366
+ ? { command, workingDirectory: workingDirectory ?? "." }
367
+ : { action: "run", command, workingDirectory: workingDirectory ?? "." },
368
+ ...(surface === "bash" ? { isFailure: toolResultIsError } : {}),
369
+ operation: async () => {
370
+ const startedAt = performance.now();
371
+ const cwd = workspaces.resolveWorkingDirectory(workspace, workingDirectory);
372
+ await assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, [cwd]);
373
+ const snapshot = await processSessions.start({
374
+ workspaceId,
375
+ command,
376
+ cwd,
377
+ workspaceRoot: workspace.root,
378
+ tty,
379
+ columns,
380
+ rows,
381
+ yieldTimeMs,
382
+ timeoutMs,
383
+ maxOutputTokens,
384
+ ...(surface === "exec_command" ? { codexCi: true } : {}),
385
+ signal: context.signal,
386
+ audit: activityContext,
387
+ });
388
+ undeliveredProcessId = snapshot.running ? snapshot.processId : undefined;
389
+ logToolCall(config, {
390
+ tool: surface,
391
+ ...workspaceLogContext(workspace, context.sessionId),
392
+ workingDirectory: workingDirectory ?? ".",
393
+ command,
394
+ commandLength: command.length,
395
+ exitCode: snapshot.exitCode,
396
+ running: snapshot.running,
397
+ processId: snapshot.processId,
398
+ success: surface === "exec_command"
399
+ ? snapshot.running || snapshot.exitCode === 0
400
+ : snapshot.running || (snapshot.exitCode === 0 && !snapshot.signal),
401
+ durationMs: Math.round(performance.now() - startedAt),
402
+ });
403
+ const response = processToolResponse(surface, workspaceId, snapshot, {
404
+ ...(surface === "bash" ? { action: "run" } : {}),
405
+ command,
406
+ workingDirectory: workingDirectory ?? ".",
407
+ running: snapshot.running,
408
+ exitCode: snapshot.exitCode,
409
+ wallTimeMs: snapshot.wallTimeMs,
410
+ });
411
+ return surface === "bash" && !snapshot.running && (snapshot.signal || snapshot.exitCode !== 0)
412
+ ? { ...response, isError: true }
413
+ : response;
414
+ },
415
+ });
416
+ context.signal?.throwIfAborted();
417
+ return result;
418
+ }
419
+ catch (error) {
420
+ if (undeliveredProcessId !== undefined) {
421
+ processSessions.discardUndelivered(workspaceId, undeliveredProcessId);
422
+ }
423
+ throw error;
424
+ }
425
+ }, processActivityOutcome, activityRelationFor(context));
426
+ markReturnedOutput(bashOutputStore, activityResult);
427
+ return activityResult;
428
+ },
429
+ capabilityRun: async (input, context) => {
430
+ const { workspaceId, name, arguments: capabilityArguments, file } = input;
431
+ const workspace = workspaces.getWorkspace(workspaceId);
432
+ let changedPaths = [];
433
+ return runActivityTool(activityLifecycle, workspace, hostScopeIdFor(context.requestMeta, context.sessionId), toolNames.capability, activityRequestFor(capabilityActivityAuditRequest(input), context), (activityContext) => runToolWithHooks(hooks, {
434
+ signal: context.signal,
435
+ tool: toolNames.capability,
436
+ invocation: workspaceHookInvocation(workspace),
437
+ payload: { name, action: "run" },
438
+ isFailure: toolResultIsError,
439
+ changedPaths: () => changedPaths,
440
+ operation: async () => {
441
+ const startedAt = performance.now();
442
+ try {
443
+ const execution = await capabilityRegistry.run(name, capabilityArguments ?? {}, capabilityContextFor(workspace), {
444
+ nativeFile: file,
445
+ signal: context.signal,
446
+ requestMeta: context.requestMeta,
447
+ sessionId: context.sessionId,
448
+ batch: context.batch,
449
+ activityId: activityContext.activityId,
450
+ });
451
+ changedPaths = execution.changedPaths ?? [];
452
+ const result = {
453
+ content: [textBlock(`Capability ${name} completed.\n${JSON.stringify(execution.value, null, 2)}`)],
454
+ ...(execution.card
455
+ ? {
456
+ _meta: {
457
+ tool: toolNames.capability,
458
+ card: {
459
+ workspaceId,
460
+ capabilityName: name,
461
+ summary: execution.card.summary ?? {},
462
+ files: execution.card.files,
463
+ payload: execution.card.payload ?? {},
464
+ },
465
+ },
466
+ }
467
+ : {}),
468
+ structuredContent: { name, action: "run", result: execution.value },
469
+ };
470
+ logToolCall(config, {
471
+ tool: toolNames.capability,
472
+ ...workspaceLogContext(workspace, context.sessionId),
473
+ capability: name,
474
+ action: "run",
475
+ success: true,
476
+ durationMs: Math.round(performance.now() - startedAt),
477
+ });
478
+ return result;
479
+ }
480
+ catch (error) {
481
+ const capabilityError = error instanceof CapabilityError
482
+ ? error
483
+ : new CapabilityError("execution_failed", error instanceof Error ? error.message : String(error));
484
+ const result = {
485
+ content: [textBlock(`${capabilityError.code}: ${capabilityError.message}`)],
486
+ structuredContent: {
487
+ name,
488
+ action: "run",
489
+ error: { code: capabilityError.code, message: capabilityError.message },
490
+ },
491
+ isError: true,
492
+ };
493
+ logFailedToolResponse(config, {
494
+ tool: toolNames.capability,
495
+ ...workspaceLogContext(workspace, context.sessionId),
496
+ capability: name,
497
+ action: "run",
498
+ }, result.content, startedAt);
499
+ return result;
500
+ }
501
+ },
502
+ }), standardActivityOutcome, activityRelationFor(context), (result) => capabilityActivityAuditResult(name, result));
503
+ },
504
+ });
505
+ const batchExecutor = new BatchExecutor({
506
+ lifecycle: activityLifecycle,
507
+ workspaces,
508
+ coreOperations,
509
+ resultIsError: toolResultIsError,
510
+ capabilityBatchPolicy: (name) => capabilityRegistry.batchPolicy(name),
511
+ shellSurface: "bash",
512
+ });
513
+ const nativeBulkMutations = new NativeBulkMutationExecutor({
514
+ lifecycle: activityLifecycle,
515
+ workspaces,
516
+ coreOperations,
517
+ preflightInstructions: (workspace, paths) => assertWorkspaceInstructionsLoadedBeforeSideEffect(workspaces, workspace, paths),
518
+ resultIsError: toolResultIsError,
519
+ resultText: toolResultText,
520
+ resultContent: toolResultContent,
521
+ });
522
+ return { coreOperations, batchExecutor, nativeBulkMutations };
523
+ }