@greppleai/grip 0.0.1 → 0.1.3

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 (197) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +13 -7
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js +4 -2
  5. package/dist/bun/cli.js.map +1 -1
  6. package/dist/bun/embedded-assets.d.ts +3 -0
  7. package/dist/bun/embedded-assets.d.ts.map +1 -0
  8. package/dist/bun/embedded-assets.js +52 -0
  9. package/dist/bun/embedded-assets.js.map +1 -0
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js +1 -0
  12. package/dist/cli/args.js.map +1 -1
  13. package/dist/config.d.ts.map +1 -1
  14. package/dist/config.js +3 -3
  15. package/dist/config.js.map +1 -1
  16. package/dist/core/agent-session.d.ts.map +1 -1
  17. package/dist/core/agent-session.js +17 -2
  18. package/dist/core/agent-session.js.map +1 -1
  19. package/dist/core/remote-workspace-protocol/contract.d.ts +13 -4
  20. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -1
  21. package/dist/core/remote-workspace-protocol/contract.js +17 -1
  22. package/dist/core/remote-workspace-protocol/contract.js.map +1 -1
  23. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts +16 -0
  24. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -0
  25. package/dist/core/remote-workspace-protocol/guest-shared-client.js +54 -0
  26. package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -0
  27. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts +23 -0
  28. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -0
  29. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +112 -0
  30. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -0
  31. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts +30 -0
  32. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -0
  33. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +243 -0
  34. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -0
  35. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts +3 -0
  36. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -0
  37. package/dist/core/remote-workspace-protocol/lima-owner-directory.js +31 -0
  38. package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -0
  39. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts +9 -0
  40. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -0
  41. package/dist/core/remote-workspace-protocol/lima-owner-lock.js +89 -0
  42. package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -0
  43. package/dist/core/remote-workspace-protocol/session.d.ts +2 -0
  44. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -1
  45. package/dist/core/remote-workspace-protocol/session.js +3 -0
  46. package/dist/core/remote-workspace-protocol/session.js.map +1 -1
  47. package/dist/core/remote-workspace-protocol/shared-transport.d.ts +71 -0
  48. package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -0
  49. package/dist/core/remote-workspace-protocol/shared-transport.js +68 -0
  50. package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -0
  51. package/dist/core/sandbox/command.d.ts +2 -4
  52. package/dist/core/sandbox/command.d.ts.map +1 -1
  53. package/dist/core/sandbox/command.js +24 -46
  54. package/dist/core/sandbox/command.js.map +1 -1
  55. package/dist/core/sandbox/config.d.ts +91 -0
  56. package/dist/core/sandbox/config.d.ts.map +1 -0
  57. package/dist/core/sandbox/config.js +88 -0
  58. package/dist/core/sandbox/config.js.map +1 -0
  59. package/dist/core/sandbox/lima-guest-binary.d.ts +11 -0
  60. package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -0
  61. package/dist/core/sandbox/lima-guest-binary.js +140 -0
  62. package/dist/core/sandbox/lima-guest-binary.js.map +1 -0
  63. package/dist/core/sandbox/lima.d.ts +22 -3
  64. package/dist/core/sandbox/lima.d.ts.map +1 -1
  65. package/dist/core/sandbox/lima.js +434 -42
  66. package/dist/core/sandbox/lima.js.map +1 -1
  67. package/dist/core/sandbox/shared-lima-roots.d.ts +11 -0
  68. package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -0
  69. package/dist/core/sandbox/shared-lima-roots.js +25 -0
  70. package/dist/core/sandbox/shared-lima-roots.js.map +1 -0
  71. package/dist/core/sandbox/update-shared-guest-binary.d.ts +8 -0
  72. package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -0
  73. package/dist/core/sandbox/update-shared-guest-binary.js +100 -0
  74. package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -0
  75. package/dist/core/settings-manager.d.ts +1 -5
  76. package/dist/core/settings-manager.d.ts.map +1 -1
  77. package/dist/core/settings-manager.js.map +1 -1
  78. package/dist/core/tools/bash.d.ts.map +1 -1
  79. package/dist/core/tools/bash.js +25 -14
  80. package/dist/core/tools/bash.js.map +1 -1
  81. package/dist/core/tools/file-mutation-queue.d.ts +2 -0
  82. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  83. package/dist/core/tools/file-mutation-queue.js +9 -0
  84. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  85. package/dist/core/tools/operations.d.ts +13 -2
  86. package/dist/core/tools/operations.d.ts.map +1 -1
  87. package/dist/core/tools/operations.js +132 -36
  88. package/dist/core/tools/operations.js.map +1 -1
  89. package/dist/daemon/activity-budget.d.ts +10 -0
  90. package/dist/daemon/activity-budget.d.ts.map +1 -0
  91. package/dist/daemon/activity-budget.js +34 -0
  92. package/dist/daemon/activity-budget.js.map +1 -0
  93. package/dist/daemon/config.d.ts +2 -0
  94. package/dist/daemon/config.d.ts.map +1 -1
  95. package/dist/daemon/config.js +15 -0
  96. package/dist/daemon/config.js.map +1 -1
  97. package/dist/daemon/outbound-budget.d.ts +10 -0
  98. package/dist/daemon/outbound-budget.d.ts.map +1 -0
  99. package/dist/daemon/outbound-budget.js +30 -0
  100. package/dist/daemon/outbound-budget.js.map +1 -0
  101. package/dist/daemon/security.d.ts.map +1 -1
  102. package/dist/daemon/security.js +3 -1
  103. package/dist/daemon/security.js.map +1 -1
  104. package/dist/daemon/server.d.ts.map +1 -1
  105. package/dist/daemon/server.js +104 -24
  106. package/dist/daemon/server.js.map +1 -1
  107. package/dist/daemon/shared-connection.d.ts +33 -0
  108. package/dist/daemon/shared-connection.d.ts.map +1 -0
  109. package/dist/daemon/shared-connection.js +271 -0
  110. package/dist/daemon/shared-connection.js.map +1 -0
  111. package/dist/daemon/shared-revision.d.ts +5 -0
  112. package/dist/daemon/shared-revision.d.ts.map +1 -0
  113. package/dist/daemon/shared-revision.js +61 -0
  114. package/dist/daemon/shared-revision.js.map +1 -0
  115. package/dist/daemon/shared-roots.d.ts +9 -0
  116. package/dist/daemon/shared-roots.d.ts.map +1 -0
  117. package/dist/daemon/shared-roots.js +33 -0
  118. package/dist/daemon/shared-roots.js.map +1 -0
  119. package/dist/daemon/workspace-runtime.d.ts +1 -1
  120. package/dist/daemon/workspace-runtime.d.ts.map +1 -1
  121. package/dist/daemon/workspace-runtime.js +42 -10
  122. package/dist/daemon/workspace-runtime.js.map +1 -1
  123. package/dist/main.d.ts.map +1 -1
  124. package/dist/main.js +5 -3
  125. package/dist/main.js.map +1 -1
  126. package/dist/modes/interactive/components/assistant-message.d.ts +1 -0
  127. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  128. package/dist/modes/interactive/components/assistant-message.js +13 -3
  129. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  130. package/dist/modes/interactive/components/branch-summary-message.d.ts +4 -3
  131. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  132. package/dist/modes/interactive/components/branch-summary-message.js +5 -4
  133. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  134. package/dist/modes/interactive/components/compaction-summary-message.d.ts +4 -3
  135. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  136. package/dist/modes/interactive/components/compaction-summary-message.js +5 -4
  137. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  138. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  139. package/dist/modes/interactive/components/custom-message.js +4 -3
  140. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  141. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -1
  142. package/dist/modes/interactive/components/hook-execution.js +3 -2
  143. package/dist/modes/interactive/components/hook-execution.js.map +1 -1
  144. package/dist/modes/interactive/components/message-card.d.ts +9 -0
  145. package/dist/modes/interactive/components/message-card.d.ts.map +1 -0
  146. package/dist/modes/interactive/components/message-card.js +24 -0
  147. package/dist/modes/interactive/components/message-card.js.map +1 -0
  148. package/dist/modes/interactive/components/skill-invocation-message.d.ts +4 -3
  149. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  150. package/dist/modes/interactive/components/skill-invocation-message.js +5 -4
  151. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  152. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  153. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  154. package/dist/modes/interactive/components/tool-execution.js +27 -21
  155. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  156. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  157. package/dist/modes/interactive/components/user-message.js +3 -2
  158. package/dist/modes/interactive/components/user-message.js.map +1 -1
  159. package/dist/modes/interactive/interactive-mode.d.ts +0 -3
  160. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  161. package/dist/modes/interactive/interactive-mode.js +55 -44
  162. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  163. package/dist/modes/interactive/theme/theme.d.ts +3 -0
  164. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  165. package/dist/modes/interactive/theme/theme.js +10 -0
  166. package/dist/modes/interactive/theme/theme.js.map +1 -1
  167. package/dist/utils/clipboard-native.d.ts.map +1 -1
  168. package/dist/utils/clipboard-native.js +1 -1
  169. package/dist/utils/clipboard-native.js.map +1 -1
  170. package/dist/utils/image-resize.d.ts.map +1 -1
  171. package/dist/utils/image-resize.js +5 -0
  172. package/dist/utils/image-resize.js.map +1 -1
  173. package/dist/utils/photon.d.ts.map +1 -1
  174. package/dist/utils/photon.js +1 -0
  175. package/dist/utils/photon.js.map +1 -1
  176. package/docs/daemon.md +6 -4
  177. package/docs/docs.json +1 -1
  178. package/docs/index.md +8 -12
  179. package/docs/packages.md +3 -3
  180. package/docs/quickstart.md +11 -19
  181. package/docs/sandbox.md +40 -117
  182. package/docs/settings.md +12 -11
  183. package/docs/termux.md +1 -18
  184. package/docs/usage.md +2 -2
  185. package/examples/README.md +0 -2
  186. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  187. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  188. package/examples/extensions/sandbox/package.json +1 -1
  189. package/examples/extensions/with-deps/package.json +1 -1
  190. package/npm-shrinkwrap.json +12 -12
  191. package/package.json +5 -6
  192. package/dist/core/sandbox/docker.d.ts +0 -169
  193. package/dist/core/sandbox/docker.d.ts.map +0 -1
  194. package/dist/core/sandbox/docker.js +0 -633
  195. package/dist/core/sandbox/docker.js.map +0 -1
  196. package/examples/sandbox-docker/Dockerfile +0 -274
  197. package/examples/sandbox-docker/README.md +0 -88
@@ -8,7 +8,7 @@ export declare const REMOTE_WORKSPACE_CAPABILITIES: readonly ["catalog_refresh",
8
8
  export type RemoteWorkspaceCapability = (typeof REMOTE_WORKSPACE_CAPABILITIES)[number];
9
9
  export declare const REMOTE_WORKSPACE_METHODS: readonly ["catalog.get", "tool.invoke", "workspace.access", "workspace.read", "workspace.write", "workspace.mkdir", "workspace.stat", "workspace.readdir", "workspace.glob", "workspace.grep", "workspace.detect_image_mime", "workspace.exec", "lsp.status", "resource.read", "artifact.read", "transfer.upload", "transfer.download"];
10
10
  export type RemoteWorkspaceMethod = (typeof REMOTE_WORKSPACE_METHODS)[number];
11
- export declare const REMOTE_WORKSPACE_ERROR_CODES: readonly ["invalid_request", "method_not_supported", "incompatible_version", "capability_mismatch", "schema_mismatch", "stale_generation", "not_available", "limit_exceeded", "deadline_exceeded", "cancelled", "generation_retired", "connection_draining", "result_too_large", "internal_error"];
11
+ export declare const REMOTE_WORKSPACE_ERROR_CODES: readonly ["invalid_request", "method_not_supported", "incompatible_version", "capability_mismatch", "schema_mismatch", "stale_generation", "not_available", "limit_exceeded", "deadline_exceeded", "cancelled", "conflict", "generation_retired", "connection_draining", "result_too_large", "internal_error"];
12
12
  export type RemoteWorkspaceErrorCode = (typeof REMOTE_WORKSPACE_ERROR_CODES)[number];
13
13
  export type RemoteWorkspaceExecutionState = "not_started" | "completed" | "indeterminate";
14
14
  export type RemoteWorkspacePathFlavor = "posix" | "windows";
@@ -215,7 +215,7 @@ export declare const RemoteWorkspaceResultSchema: Type.TObject<{
215
215
  }>;
216
216
  export type RemoteWorkspaceResult = Static<typeof RemoteWorkspaceResultSchema>;
217
217
  export declare const RemoteWorkspaceProtocolErrorSchema: Type.TObject<{
218
- code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
218
+ code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"conflict">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
219
219
  message: Type.TString;
220
220
  executionState: Type.TUnion<[Type.TLiteral<"not_started">, Type.TLiteral<"completed">, Type.TLiteral<"indeterminate">]>;
221
221
  retryable: Type.TBoolean;
@@ -226,7 +226,7 @@ export declare const RemoteWorkspaceErrorMessageSchema: Type.TObject<{
226
226
  type: Type.TLiteral<"error">;
227
227
  id: Type.TString;
228
228
  error: Type.TObject<{
229
- code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
229
+ code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"conflict">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
230
230
  message: Type.TString;
231
231
  executionState: Type.TUnion<[Type.TLiteral<"not_started">, Type.TLiteral<"completed">, Type.TLiteral<"indeterminate">]>;
232
232
  retryable: Type.TBoolean;
@@ -364,7 +364,7 @@ export declare const RemoteWorkspaceServerMessageSchema: Type.TUnion<[Type.TObje
364
364
  type: Type.TLiteral<"error">;
365
365
  id: Type.TString;
366
366
  error: Type.TObject<{
367
- code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
367
+ code: Type.TUnion<[Type.TLiteral<"invalid_request">, Type.TLiteral<"method_not_supported">, Type.TLiteral<"incompatible_version">, Type.TLiteral<"capability_mismatch">, Type.TLiteral<"schema_mismatch">, Type.TLiteral<"stale_generation">, Type.TLiteral<"not_available">, Type.TLiteral<"limit_exceeded">, Type.TLiteral<"deadline_exceeded">, Type.TLiteral<"cancelled">, Type.TLiteral<"conflict">, Type.TLiteral<"generation_retired">, Type.TLiteral<"connection_draining">, Type.TLiteral<"result_too_large">, Type.TLiteral<"internal_error">]>;
368
368
  message: Type.TString;
369
369
  executionState: Type.TUnion<[Type.TLiteral<"not_started">, Type.TLiteral<"completed">, Type.TLiteral<"indeterminate">]>;
370
370
  retryable: Type.TBoolean;
@@ -392,6 +392,15 @@ export declare const RemoteWorkspaceServerMessageSchema: Type.TUnion<[Type.TObje
392
392
  }>]>;
393
393
  export type RemoteWorkspaceClientMessage = Static<typeof RemoteWorkspaceClientMessageSchema>;
394
394
  export type RemoteWorkspaceServerMessage = Static<typeof RemoteWorkspaceServerMessageSchema>;
395
+ /** Shared v2 mutations require an observed digest/absence, or an explicitly unsafe write. */
396
+ declare const ExpectedRevisionSchema: Type.TUnion<[Type.TObject<{
397
+ sha256: Type.TString;
398
+ }>, Type.TObject<{
399
+ absent: Type.TLiteral<true>;
400
+ }>, Type.TObject<{
401
+ unsafeOverwrite: Type.TLiteral<true>;
402
+ }>]>;
403
+ export type ExpectedWorkspaceRevision = Static<typeof ExpectedRevisionSchema>;
395
404
  declare const LspStatusResultSchema: Type.TObject<{
396
405
  enabled: Type.TBoolean;
397
406
  servers: Type.TArray<Type.TObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/core/remote-workspace-protocol/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,kCAAkC;;;;EAAoD,CAAC;AAEpG,eAAO,MAAM,6BAA6B,kHAOhC,CAAC;AAEX,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvF,eAAO,MAAM,wBAAwB,yUAkB3B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E,eAAO,MAAM,4BAA4B,oSAe/B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AACrF,MAAM,MAAM,6BAA6B,GAAG,aAAa,GAAG,WAAW,GAAG,eAAe,CAAC;AAC1F,MAAM,MAAM,yBAAyB,GAAG,OAAO,GAAG,SAAS,CAAC;AAC5D,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvF,MAAM,WAAW,+BAA+B;IAC/C,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,6BAA8B,SAAQ,+BAA+B;IACrF,YAAY,EAAE,MAA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,MAAM,EAAE,6BAA6B,CAAC;CACtC;AAED,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAEjG,qBAAa,+BAAgC,SAAQ,KAAK;IACzD,QAAQ,CAAC,IAAI,EAAE,mCAAmC,CAAC;IAEnD,YAAY,IAAI,EAAE,mCAAmC,EAAE,OAAO,EAAE,MAAM,EAIrE;CACD;AA+BD,wBAAgB,iCAAiC,CAChD,SAAS,EAAE,wBAAwB,EACnC,OAAO,EAAE,iCAAiC,GACxC,gCAAgC,CA8ElC;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,qBAAqB,GAAG,4BAA4B,CAaxG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { type Static, Type } from \"typebox\";\nimport { Compile, type Validator } from \"typebox/compile\";\n\nexport const REMOTE_WORKSPACE_PROTOCOL_VERSIONS = [{ major: 1, minMinor: 0, maxMinor: 0 }] as const;\n\nexport const REMOTE_WORKSPACE_CAPABILITIES = [\n\t\"catalog_refresh\",\n\t\"tool_updates\",\n\t\"primitive_operations\",\n\t\"lsp_status\",\n\t\"file_transfer\",\n\t\"artifacts\",\n] as const;\n\nexport type RemoteWorkspaceCapability = (typeof REMOTE_WORKSPACE_CAPABILITIES)[number];\n\nexport const REMOTE_WORKSPACE_METHODS = [\n\t\"catalog.get\",\n\t\"tool.invoke\",\n\t\"workspace.access\",\n\t\"workspace.read\",\n\t\"workspace.write\",\n\t\"workspace.mkdir\",\n\t\"workspace.stat\",\n\t\"workspace.readdir\",\n\t\"workspace.glob\",\n\t\"workspace.grep\",\n\t\"workspace.detect_image_mime\",\n\t\"workspace.exec\",\n\t\"lsp.status\",\n\t\"resource.read\",\n\t\"artifact.read\",\n\t\"transfer.upload\",\n\t\"transfer.download\",\n] as const;\n\nexport type RemoteWorkspaceMethod = (typeof REMOTE_WORKSPACE_METHODS)[number];\n\nexport const REMOTE_WORKSPACE_ERROR_CODES = [\n\t\"invalid_request\",\n\t\"method_not_supported\",\n\t\"incompatible_version\",\n\t\"capability_mismatch\",\n\t\"schema_mismatch\",\n\t\"stale_generation\",\n\t\"not_available\",\n\t\"limit_exceeded\",\n\t\"deadline_exceeded\",\n\t\"cancelled\",\n\t\"generation_retired\",\n\t\"connection_draining\",\n\t\"result_too_large\",\n\t\"internal_error\",\n] as const;\n\nexport type RemoteWorkspaceErrorCode = (typeof REMOTE_WORKSPACE_ERROR_CODES)[number];\nexport type RemoteWorkspaceExecutionState = \"not_started\" | \"completed\" | \"indeterminate\";\nexport type RemoteWorkspacePathFlavor = \"posix\" | \"windows\";\nexport type RemoteWorkspaceOperationKind = \"read\" | \"mutation\" | \"process\" | \"service\";\n\nexport interface RemoteWorkspaceStructuralLimits {\n\tmaxMessageBytes: number;\n\tmaxStringBytes: number;\n\tmaxDepth: number;\n\tmaxObjectKeys: number;\n\tmaxArrayLength: number;\n\tmaxNodes: number;\n}\n\nexport interface RemoteWorkspaceProtocolLimits extends RemoteWorkspaceStructuralLimits {\n\tmaxRequestMs: number;\n\tmaxTransferChunkBytes: number;\n\tmaxPendingTransferBytes: number;\n\tmaxPendingInboundBytes: number;\n\tmaxPendingInboundMessages: number;\n\tmaxPendingOutboundBytes: number;\n\tmaxPendingOutboundMessages: number;\n\tmaxTransferBytes: number;\n\tmaxTransferChunks: number;\n\tmaxActiveRequests: number;\n\tmaxActiveTransfers: number;\n\tmaxCancellationMs: number;\n\tmaxTransportSendMs: number;\n}\n\nexport const DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS: RemoteWorkspaceProtocolLimits = {\n\tmaxMessageBytes: 2 * 1024 * 1024,\n\tmaxStringBytes: 1536 * 1024,\n\tmaxDepth: 32,\n\tmaxObjectKeys: 4096,\n\tmaxArrayLength: 4096,\n\tmaxNodes: 16_384,\n\tmaxRequestMs: 10 * 60 * 1000,\n\tmaxTransferChunkBytes: 64 * 1024,\n\tmaxPendingTransferBytes: 256 * 1024,\n\tmaxPendingInboundBytes: 4 * 1024 * 1024,\n\tmaxPendingInboundMessages: 64,\n\tmaxPendingOutboundBytes: 4 * 1024 * 1024,\n\tmaxPendingOutboundMessages: 128,\n\tmaxTransferBytes: 100 * 1024 * 1024,\n\tmaxTransferChunks: 16_384,\n\tmaxActiveRequests: 64,\n\tmaxActiveTransfers: 8,\n\tmaxCancellationMs: 100,\n\tmaxTransportSendMs: 10_000,\n};\n\nconst closedObject = { additionalProperties: false } as const;\nconst safeIntegerOptions = { minimum: 0, maximum: Number.MAX_SAFE_INTEGER } as const;\nconst RequestIdSchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z0-9._:-]+$\" });\nconst HashSchema = Type.String({ pattern: \"^[0-9a-f]{64}$\" });\nconst CapabilitySchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[a-z][a-z0-9_.-]*$\" });\nconst RemoteWorkspaceMethodSchema = Type.Union([\n\tType.Literal(\"catalog.get\"),\n\tType.Literal(\"tool.invoke\"),\n\tType.Literal(\"workspace.access\"),\n\tType.Literal(\"workspace.read\"),\n\tType.Literal(\"workspace.write\"),\n\tType.Literal(\"workspace.mkdir\"),\n\tType.Literal(\"workspace.stat\"),\n\tType.Literal(\"workspace.readdir\"),\n\tType.Literal(\"workspace.glob\"),\n\tType.Literal(\"workspace.grep\"),\n\tType.Literal(\"workspace.detect_image_mime\"),\n\tType.Literal(\"workspace.exec\"),\n\tType.Literal(\"lsp.status\"),\n\tType.Literal(\"resource.read\"),\n\tType.Literal(\"artifact.read\"),\n\tType.Literal(\"transfer.upload\"),\n\tType.Literal(\"transfer.download\"),\n]);\n\nexport const RemoteWorkspaceVersionRangeSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t\tmaxMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersionRange = Static<typeof RemoteWorkspaceVersionRangeSchema>;\n\nexport const RemoteWorkspaceVersionSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersion = Static<typeof RemoteWorkspaceVersionSchema>;\n\nexport const RemoteWorkspaceLimitsSchema = Type.Object(\n\t{\n\t\tmaxMessageBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxStringBytes: Type.Integer({ minimum: 1, maximum: 64 * 1024 * 1024 }),\n\t\tmaxDepth: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxObjectKeys: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxArrayLength: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxNodes: Type.Integer({ minimum: 1, maximum: 2_000_000 }),\n\t\tmaxRequestMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tmaxTransferChunkBytes: Type.Integer({ minimum: 1024, maximum: 1024 * 1024 }),\n\t\tmaxPendingTransferBytes: Type.Integer({ minimum: 1024, maximum: 16 * 1024 * 1024 }),\n\t\tmaxPendingInboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingInboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxPendingOutboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingOutboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxTransferBytes: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tmaxTransferChunks: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxActiveRequests: Type.Integer({ minimum: 1, maximum: 10_000_000 }),\n\t\tmaxActiveTransfers: Type.Integer({ minimum: 1, maximum: 10_000 }),\n\t\tmaxCancellationMs: Type.Integer({ minimum: 1, maximum: 60_000 }),\n\t\tmaxTransportSendMs: Type.Integer({ minimum: 1, maximum: 5 * 60_000 }),\n\t},\n\tclosedObject,\n);\n\nexport const RemoteWorkspaceIdentitySchema = Type.Object(\n\t{\n\t\tid: Type.String({ minLength: 16, maxLength: 128, pattern: \"^[A-Za-z0-9_-]+$\" }),\n\t\troot: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tpathFlavor: Type.Union([Type.Literal(\"posix\"), Type.Literal(\"windows\")]),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceIdentity = Static<typeof RemoteWorkspaceIdentitySchema>;\n\nexport const RemoteWorkspaceToolCatalogEntrySchema = Type.Object(\n\t{\n\t\tname: Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z][A-Za-z0-9_.-]*$\" }),\n\t\texecutionMode: Type.Union([\n\t\t\tType.Literal(\"read\"),\n\t\t\tType.Literal(\"mutation\"),\n\t\t\tType.Literal(\"process\"),\n\t\t\tType.Literal(\"service\"),\n\t\t]),\n\t\tparameterSchema: Type.Record(Type.String({ maxLength: 256 }), Type.Unknown()),\n\t\tschemaHash: HashSchema,\n\t\tfeatureFlags: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceToolCatalogEntry = Static<typeof RemoteWorkspaceToolCatalogEntrySchema>;\n\nexport const RemoteWorkspaceCatalogSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\ttools: Type.Array(RemoteWorkspaceToolCatalogEntrySchema, { maxItems: 1024 }),\n\t\toperations: Type.Array(RemoteWorkspaceMethodSchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalog = Static<typeof RemoteWorkspaceCatalogSchema>;\n\nexport const RemoteWorkspaceHandshakeSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake\"),\n\t\tid: RequestIdSchema,\n\t\tversions: Type.Array(RemoteWorkspaceVersionRangeSchema, { minItems: 1, maxItems: 16 }),\n\t\trequiredCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\toptionalCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\treceiveLimits: RemoteWorkspaceLimitsSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshake = Static<typeof RemoteWorkspaceHandshakeSchema>;\n\nexport const RemoteWorkspaceHandshakeAckSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake_ack\"),\n\t\tid: RequestIdSchema,\n\t\tversion: RemoteWorkspaceVersionSchema,\n\t\tcapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t\tlimits: RemoteWorkspaceLimitsSchema,\n\t\tcatalog: RemoteWorkspaceCatalogSchema,\n\t\tcatalogHash: HashSchema,\n\t\tbackendMetadata: Type.Object(\n\t\t\t{\n\t\t\t\tkind: Type.Literal(\"remote-workspace\"),\n\t\t\t\tlabel: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshakeAck = Static<typeof RemoteWorkspaceHandshakeAckSchema>;\n\nexport const RemoteWorkspaceRequestSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"request\"),\n\t\tid: RequestIdSchema,\n\t\tmethod: Type.String({ minLength: 1, maxLength: 128 }),\n\t\ttimeoutMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tparams: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceRequest = Static<typeof RemoteWorkspaceRequestSchema>;\n\nexport const RemoteWorkspaceCancelSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"cancel\"),\n\t\tid: RequestIdSchema,\n\t\treason: Type.Optional(Type.String({ maxLength: 256 })),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCancel = Static<typeof RemoteWorkspaceCancelSchema>;\n\nexport const RemoteWorkspaceTransferChunkSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_chunk\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tdataBase64: Type.String({ minLength: 4 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferChunk = Static<typeof RemoteWorkspaceTransferChunkSchema>;\n\nexport const RemoteWorkspaceTransferFinishSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_finish\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferFinish = Static<typeof RemoteWorkspaceTransferFinishSchema>;\n\nexport const RemoteWorkspaceResultSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"result\"),\n\t\tid: RequestIdSchema,\n\t\tresult: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceResult = Static<typeof RemoteWorkspaceResultSchema>;\n\nexport const RemoteWorkspaceProtocolErrorSchema = Type.Object(\n\t{\n\t\tcode: Type.Union([\n\t\t\tType.Literal(\"invalid_request\"),\n\t\t\tType.Literal(\"method_not_supported\"),\n\t\t\tType.Literal(\"incompatible_version\"),\n\t\t\tType.Literal(\"capability_mismatch\"),\n\t\t\tType.Literal(\"schema_mismatch\"),\n\t\t\tType.Literal(\"stale_generation\"),\n\t\t\tType.Literal(\"not_available\"),\n\t\t\tType.Literal(\"limit_exceeded\"),\n\t\t\tType.Literal(\"deadline_exceeded\"),\n\t\t\tType.Literal(\"cancelled\"),\n\t\t\tType.Literal(\"generation_retired\"),\n\t\t\tType.Literal(\"connection_draining\"),\n\t\t\tType.Literal(\"result_too_large\"),\n\t\t\tType.Literal(\"internal_error\"),\n\t\t]),\n\t\tmessage: Type.String({ minLength: 1, maxLength: 4096 }),\n\t\texecutionState: Type.Union([\n\t\t\tType.Literal(\"not_started\"),\n\t\t\tType.Literal(\"completed\"),\n\t\t\tType.Literal(\"indeterminate\"),\n\t\t]),\n\t\tretryable: Type.Boolean(),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceProtocolError = Static<typeof RemoteWorkspaceProtocolErrorSchema>;\n\nexport const RemoteWorkspaceErrorMessageSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"error\"),\n\t\tid: RequestIdSchema,\n\t\terror: RemoteWorkspaceProtocolErrorSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceErrorMessage = Static<typeof RemoteWorkspaceErrorMessageSchema>;\n\nexport const RemoteWorkspaceUpdateSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"update\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tupdate: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceUpdate = Static<typeof RemoteWorkspaceUpdateSchema>;\n\nexport const RemoteWorkspaceTransferStartSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_start\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferStart = Static<typeof RemoteWorkspaceTransferStartSchema>;\n\nexport const RemoteWorkspaceCatalogChangedSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"catalog_changed\"),\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalogChanged = Static<typeof RemoteWorkspaceCatalogChangedSchema>;\n\nexport const RemoteWorkspaceClientMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeSchema,\n\tRemoteWorkspaceRequestSchema,\n\tRemoteWorkspaceCancelSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceTransferFinishSchema,\n]);\n\nexport const RemoteWorkspaceServerMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeAckSchema,\n\tRemoteWorkspaceResultSchema,\n\tRemoteWorkspaceErrorMessageSchema,\n\tRemoteWorkspaceUpdateSchema,\n\tRemoteWorkspaceTransferStartSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceCatalogChangedSchema,\n]);\n\nexport type RemoteWorkspaceClientMessage = Static<typeof RemoteWorkspaceClientMessageSchema>;\nexport type RemoteWorkspaceServerMessage = Static<typeof RemoteWorkspaceServerMessageSchema>;\n\nconst EmptyParamsSchema = Type.Object({}, closedObject);\nconst PathParamsSchema = Type.Object({ path: Type.String({ minLength: 1, maxLength: 32_768 }) }, closedObject);\nconst CatalogGetParamsSchema = EmptyParamsSchema;\nconst SessionEnvironmentSchema = Type.Object(\n\t{\n\t\tGRIP_SESSION_ID: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_SESSION_FILE: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_PROVIDER: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_MODEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_REASONING_LEVEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t},\n\tclosedObject,\n);\nconst ToolInvokeParamsSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t\ttoolName: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tschemaHash: HashSchema,\n\t\targumentsPrepared: Type.Literal(true),\n\t\targuments: Type.Unknown(),\n\t\texecutionOptions: Type.Object(\n\t\t\t{\n\t\t\t\timageAutoResize: Type.Optional(Type.Boolean()),\n\t\t\t\tshellCommandPrefix: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\t\t\tsessionEnvironment: Type.Optional(SessionEnvironmentSchema),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\nconst AccessParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tmode: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"exists\"), Type.Literal(\"read\"), Type.Literal(\"write\"), Type.Literal(\"readwrite\")]),\n\t\t),\n\t},\n\tclosedObject,\n);\nconst WriteParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcontentBase64: Type.String(),\n\t},\n\tclosedObject,\n);\nconst MkdirParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\trecursive: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst GlobParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tignore: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 4096 }),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst GrepParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ maxLength: 1024 * 1024 }),\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tglob: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tignoreCase: Type.Optional(Type.Boolean()),\n\t\tliteral: Type.Optional(Type.Boolean()),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst ExecParamsSchema = Type.Object(\n\t{\n\t\tcommand: Type.String({ minLength: 1 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\nconst TransferUploadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t\toverwrite: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst TransferDownloadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\n\nconst ToolContentSchema = Type.Union([\n\tType.Object({ type: Type.Literal(\"text\"), text: Type.String() }, closedObject),\n\tType.Object(\n\t\t{\n\t\t\ttype: Type.Literal(\"image\"),\n\t\t\tdata: Type.String(),\n\t\t\tmimeType: Type.String({ minLength: 1, maxLength: 256 }),\n\t\t},\n\t\tclosedObject,\n\t),\n]);\nconst ToolResultSchema = Type.Object(\n\t{\n\t\tcontent: Type.Array(ToolContentSchema),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t\tterminate: Type.Optional(Type.Boolean()),\n\t},\n\tclosedObject,\n);\nconst EmptyResultSchema = EmptyParamsSchema;\nconst LspStatusServerSchema = Type.Object(\n\t{\n\t\tserverId: Type.String({ minLength: 1, maxLength: 256 }),\n\t\tlanguageIds: Type.Array(Type.String({ maxLength: 256 }), { maxItems: 256 }),\n\t\ttransport: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tinstanceKey: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\tworkspaceRoot: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tendpoint: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\trootUri: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\townership: Type.Union([Type.Literal(\"managed\"), Type.Literal(\"attached\")]),\n\t\tshutdownMode: Type.Union([Type.Literal(\"protocol\"), Type.Literal(\"disconnect\")]),\n\t\tstate: Type.Union([\n\t\t\tType.Literal(\"idle\"),\n\t\t\tType.Literal(\"connecting\"),\n\t\t\tType.Literal(\"initializing\"),\n\t\t\tType.Literal(\"running\"),\n\t\t\tType.Literal(\"closed\"),\n\t\t\tType.Literal(\"failed\"),\n\t\t\tType.Literal(\"disposed\"),\n\t\t]),\n\t\treconnectEligible: Type.Boolean(),\n\t\trunning: Type.Boolean(),\n\t\tstarting: Type.Boolean(),\n\t\tdiagnosticsCount: Type.Integer(safeIntegerOptions),\n\t\tlastError: Type.Optional(Type.String()),\n\t\tlastRequestError: Type.Optional(Type.String()),\n\t\tstderr: Type.Optional(Type.String()),\n\t\tsynchronizationError: Type.Optional(Type.String()),\n\t},\n\tclosedObject,\n);\nconst LspStatusResultSchema = Type.Object(\n\t{ enabled: Type.Boolean(), servers: Type.Array(LspStatusServerSchema, { maxItems: 1024 }) },\n\tclosedObject,\n);\nexport type RemoteLspStatus = Static<typeof LspStatusResultSchema>;\nconst ReadResultSchema = Type.Object(\n\t{\n\t\tcontentBase64: Type.String(),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst StatResultSchema = Type.Object(\n\t{\n\t\tkind: Type.Union([Type.Literal(\"file\"), Type.Literal(\"directory\"), Type.Literal(\"other\")]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ReaddirResultSchema = Type.Object(\n\t{\n\t\tentries: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GlobResultSchema = Type.Object(\n\t{\n\t\tmatches: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GrepResultSchema = Type.Object(\n\t{\n\t\tisDirectory: Type.Boolean(),\n\t\tmatches: Type.Array(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tfilePath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\t\t\t\tlineNumber: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\t\t\t\tlineText: Type.Optional(Type.String()),\n\t\t\t\t},\n\t\t\t\tclosedObject,\n\t\t\t),\n\t\t\t{ maxItems: 1_000_000 },\n\t\t),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst MimeResultSchema = Type.Object(\n\t{\n\t\tmimeType: Type.Union([\n\t\t\tType.Literal(\"image/jpeg\"),\n\t\t\tType.Literal(\"image/png\"),\n\t\t\tType.Literal(\"image/gif\"),\n\t\t\tType.Literal(\"image/webp\"),\n\t\t\tType.Null(),\n\t\t]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ExecResultSchema = Type.Object(\n\t{ exitCode: Type.Union([Type.Integer({ minimum: 0, maximum: 255 }), Type.Null()]) },\n\tclosedObject,\n);\nconst TransferResultSchema = Type.Object(\n\t{\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nconst parameterValidators = {\n\t\"catalog.get\": Compile(CatalogGetParamsSchema),\n\t\"tool.invoke\": Compile(ToolInvokeParamsSchema),\n\t\"workspace.access\": Compile(AccessParamsSchema),\n\t\"workspace.read\": Compile(PathParamsSchema),\n\t\"workspace.write\": Compile(WriteParamsSchema),\n\t\"workspace.mkdir\": Compile(MkdirParamsSchema),\n\t\"workspace.stat\": Compile(PathParamsSchema),\n\t\"workspace.readdir\": Compile(PathParamsSchema),\n\t\"workspace.glob\": Compile(GlobParamsSchema),\n\t\"workspace.grep\": Compile(GrepParamsSchema),\n\t\"workspace.detect_image_mime\": Compile(PathParamsSchema),\n\t\"workspace.exec\": Compile(ExecParamsSchema),\n\t\"lsp.status\": Compile(EmptyParamsSchema),\n\t\"resource.read\": Compile(PathParamsSchema),\n\t\"artifact.read\": Compile(PathParamsSchema),\n\t\"transfer.upload\": Compile(TransferUploadParamsSchema),\n\t\"transfer.download\": Compile(TransferDownloadParamsSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile>>;\n\nconst resultValidators = {\n\t\"catalog.get\": Compile(RemoteWorkspaceCatalogSchema),\n\t\"tool.invoke\": Compile(ToolResultSchema),\n\t\"workspace.access\": Compile(EmptyResultSchema),\n\t\"workspace.read\": Compile(ReadResultSchema),\n\t\"workspace.write\": Compile(EmptyResultSchema),\n\t\"workspace.mkdir\": Compile(EmptyResultSchema),\n\t\"workspace.stat\": Compile(StatResultSchema),\n\t\"workspace.readdir\": Compile(ReaddirResultSchema),\n\t\"workspace.glob\": Compile(GlobResultSchema),\n\t\"workspace.grep\": Compile(GrepResultSchema),\n\t\"workspace.detect_image_mime\": Compile(MimeResultSchema),\n\t\"workspace.exec\": Compile(ExecResultSchema),\n\t\"lsp.status\": Compile(LspStatusResultSchema),\n\t\"resource.read\": Compile(ReadResultSchema),\n\t\"artifact.read\": Compile(TransferResultSchema),\n\t\"transfer.upload\": Compile(TransferResultSchema),\n\t\"transfer.download\": Compile(TransferResultSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile> | undefined>;\n\nconst clientMessageValidator = Compile(RemoteWorkspaceClientMessageSchema);\nconst serverMessageValidator = Compile(RemoteWorkspaceServerMessageSchema);\nconst handshakeAckValidator = Compile(RemoteWorkspaceHandshakeAckSchema);\nconst limitsValidator = Compile(RemoteWorkspaceLimitsSchema);\n\nexport class RemoteWorkspaceValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceValidationError\";\n\t}\n}\n\nfunction validationMessage(validator: Validator, value: unknown): string {\n\tconst error = validator.Errors(value)[0];\n\tif (!error) return \"value does not match the protocol schema\";\n\treturn `${error.instancePath || \"/\"}: ${error.message}`;\n}\n\nfunction parseWithValidator<T>(validator: Validator, value: unknown, label: string): T {\n\tif (!validator.Check(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(`Invalid ${label}: ${validationMessage(validator, value)}`);\n\t}\n\treturn value as T;\n}\n\nexport function validateRemoteWorkspaceProtocolLimits(value: unknown): RemoteWorkspaceProtocolLimits {\n\tconst limits = parseWithValidator<RemoteWorkspaceProtocolLimits>(limitsValidator, value, \"protocol limits\");\n\tif (limits.maxMessageBytes > limits.maxPendingInboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingInboundBytes\");\n\t}\n\tif (limits.maxMessageBytes > limits.maxPendingOutboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingOutboundBytes\");\n\t}\n\tif (limits.maxTransferChunkBytes > limits.maxPendingTransferBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must not exceed maxPendingTransferBytes\");\n\t}\n\tif (Math.ceil((limits.maxTransferChunkBytes * 4) / 3) + 512 > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must fit in one base64 protocol message\");\n\t}\n\treturn limits;\n}\n\ninterface RemoteWorkspacePendingValue {\n\tvalue: unknown;\n\tdepth: number;\n}\n\ninterface RemoteWorkspaceStructureState {\n\tpending: RemoteWorkspacePendingValue[];\n\tnodes: number;\n\tobjectKeys: number;\n\tlimits: RemoteWorkspaceStructuralLimits;\n}\n\nfunction validateRemoteWorkspaceNodeBudget(depth: number, state: RemoteWorkspaceStructureState): void {\n\tstate.nodes++;\n\tif (state.nodes > state.limits.maxNodes)\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds node limit\");\n\tif (depth > state.limits.maxDepth) throw new RemoteWorkspaceValidationError(\"Protocol value exceeds depth limit\");\n}\n\nfunction validateRemoteWorkspaceScalar(value: unknown, limits: RemoteWorkspaceStructuralLimits): boolean {\n\tif (value === null || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Protocol numbers must be finite\");\n\t\treturn true;\n\t}\n\tif (typeof value !== \"string\") return false;\n\tif (Buffer.byteLength(value, \"utf8\") > limits.maxStringBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol string exceeds byte limit\");\n\t}\n\treturn true;\n}\n\nfunction enqueueRemoteWorkspaceArray(value: unknown[], depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value.length > state.limits.maxArrayLength) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol array exceeds item limit\");\n\t}\n\tfor (let index = value.length - 1; index >= 0; index--) {\n\t\tstate.pending.push({ value: value[index], depth: depth + 1 });\n\t}\n}\n\nfunction enqueueRemoteWorkspaceObject(value: unknown, depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value === null || typeof value !== \"object\")\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol values must be JSON-compatible\");\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol objects must be plain JSON objects\");\n\t}\n\tconst entries = Object.entries(value);\n\tif (entries.length > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object exceeds key limit\");\n\t}\n\tstate.objectKeys += entries.length;\n\tif (state.objectKeys > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds total key limit\");\n\t}\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (!entry) continue;\n\t\tif (Buffer.byteLength(entry[0], \"utf8\") > state.limits.maxStringBytes) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object key exceeds byte limit\");\n\t\t}\n\t\tstate.pending.push({ value: entry[1], depth: depth + 1 });\n\t}\n}\n\nexport function assertRemoteWorkspaceJsonStructure(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): void {\n\tconst state: RemoteWorkspaceStructureState = {\n\t\tpending: [{ value, depth: 1 }],\n\t\tnodes: 0,\n\t\tobjectKeys: 0,\n\t\tlimits,\n\t};\n\twhile (state.pending.length > 0) {\n\t\tconst current = state.pending.pop();\n\t\tif (!current) break;\n\t\tvalidateRemoteWorkspaceNodeBudget(current.depth, state);\n\t\tif (validateRemoteWorkspaceScalar(current.value, limits)) continue;\n\t\tif (Array.isArray(current.value)) {\n\t\t\tenqueueRemoteWorkspaceArray(current.value, current.depth, state);\n\t\t\tcontinue;\n\t\t}\n\t\tenqueueRemoteWorkspaceObject(current.value, current.depth, state);\n\t}\n}\n\nexport function decodeRemoteWorkspaceMessage(\n\tpayload: string | Uint8Array,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tconst bytes = typeof payload === \"string\" ? Buffer.from(payload, \"utf8\") : payload;\n\tif (bytes.byteLength > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol message exceeds byte limit\");\n\t}\n\tconst text = typeof payload === \"string\" ? payload : new TextDecoder(\"utf-8\", { fatal: true }).decode(payload);\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(text) as unknown;\n\t} catch (error) {\n\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t`Protocol message is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn value;\n}\n\nexport function parseRemoteWorkspaceClientMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceClientMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceClientMessage>(clientMessageValidator, value, \"client message\");\n}\n\nexport function parseRemoteWorkspaceServerMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceServerMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceServerMessage>(serverMessageValidator, value, \"server message\");\n}\n\nexport function isRemoteWorkspaceMethod(method: string): method is RemoteWorkspaceMethod {\n\treturn (REMOTE_WORKSPACE_METHODS as readonly string[]).includes(method);\n}\n\nexport function parseRemoteWorkspaceRequestParams(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst parsed = parseWithValidator(parameterValidators[method], value, `${method} params`);\n\tif (method === \"workspace.write\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceResult(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst validator = resultValidators[method];\n\tconst parsed = validator ? parseWithValidator(validator, value, `${method} result`) : value;\n\tif (method === \"workspace.read\" || method === \"resource.read\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceToolResult(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator(Compile(ToolResultSchema), value, \"tool result\");\n}\n\nexport function decodeCanonicalBase64(value: string, maxBytes: number): Buffer {\n\tif (value.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\tconst decoded = Buffer.from(value, \"base64\");\n\tif (decoded.byteLength > maxBytes) throw new RemoteWorkspaceValidationError(\"Transfer chunk exceeds byte limit\");\n\tif (decoded.toString(\"base64\") !== value) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\treturn decoded;\n}\n\nfunction canonicalJson(value: unknown): string {\n\tif (value === null) return \"null\";\n\tif (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Cannot hash a non-finite number\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (typeof value === \"string\") return JSON.stringify(value);\n\tif (Array.isArray(value)) return `[${value.map((entry) => canonicalJson(entry)).join(\",\")}]`;\n\tif (typeof value !== \"object\" || value === undefined) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Cannot hash a non-JSON value\");\n\t}\n\tconst entries = Object.entries(value).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));\n\treturn `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(\",\")}}`;\n}\n\nexport function hashRemoteWorkspaceJson(value: unknown): string {\n\tassertRemoteWorkspaceJsonStructure(value);\n\treturn createHash(\"sha256\").update(canonicalJson(value)).digest(\"hex\");\n}\n\nexport function hashRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): string {\n\treturn hashRemoteWorkspaceJson(catalog);\n}\n\nfunction assertUnique(values: readonly string[], label: string): void {\n\tif (new Set(values).size !== values.length) throw new RemoteWorkspaceValidationError(`${label} contains duplicates`);\n}\n\nexport function validateRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): void {\n\tparseWithValidator(Compile(RemoteWorkspaceCatalogSchema), catalog, \"tool catalog\");\n\tassertUnique(catalog.operations, \"Catalog operations\");\n\tassertUnique(\n\t\tcatalog.tools.map((tool) => tool.name),\n\t\t\"Catalog tool names\",\n\t);\n\tfor (const tool of catalog.tools) {\n\t\tassertUnique(tool.featureFlags, `Feature flags for ${tool.name}`);\n\t\tif (hashRemoteWorkspaceJson(tool.parameterSchema) !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Schema hash mismatch for tool ${tool.name}`);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceLocalToolSchemas(\n\tcatalog: RemoteWorkspaceCatalog,\n\tlocalToolSchemas: ReadonlyMap<string, string>,\n): void {\n\tfor (const tool of catalog.tools) {\n\t\tconst localHash = localToolSchemas.get(tool.name);\n\t\tif (localHash !== undefined && localHash !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t\t`Remote schema does not match the local canonical schema for ${tool.name}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceHandshakeAck(\n\tack: unknown,\n\toffer: RemoteWorkspaceHandshake,\n\tlocalToolSchemas: ReadonlyMap<string, string> = new Map(),\n): RemoteWorkspaceHandshakeAck {\n\tconst parsed = parseWithValidator<RemoteWorkspaceHandshakeAck>(handshakeAckValidator, ack, \"handshake response\");\n\tvalidateRemoteWorkspaceProtocolLimits(offer.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(parsed.limits);\n\tconst selected = offer.versions.some(\n\t\t(range) =>\n\t\t\trange.major === parsed.version.major &&\n\t\t\trange.minMinor <= parsed.version.minor &&\n\t\t\trange.maxMinor >= parsed.version.minor,\n\t);\n\tif (!selected)\n\t\tthrow new RemoteWorkspaceValidationError(\"Server selected a protocol version outside the offered range\");\n\tconst offeredCapabilities = new Set([...offer.requiredCapabilities, ...offer.optionalCapabilities]);\n\tfor (const capability of parsed.capabilities) {\n\t\tif (!offeredCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server selected an unoffered capability: ${capability}`);\n\t\t}\n\t}\n\tconst selectedCapabilities = new Set(parsed.capabilities);\n\tfor (const capability of offer.requiredCapabilities) {\n\t\tif (!selectedCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server omitted required capability: ${capability}`);\n\t\t}\n\t}\n\tassertUnique(parsed.capabilities, \"Negotiated capabilities\");\n\tvalidateRemoteWorkspaceCatalog(parsed.catalog);\n\tif (hashRemoteWorkspaceCatalog(parsed.catalog) !== parsed.catalogHash) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Catalog hash does not match the negotiated catalog\");\n\t}\n\tvalidateRemoteWorkspaceLocalToolSchemas(parsed.catalog, localToolSchemas);\n\tfor (const key of Object.keys(offer.receiveLimits) as (keyof RemoteWorkspaceProtocolLimits)[]) {\n\t\tif (parsed.limits[key] > offer.receiveLimits[key]) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server increased negotiated limit: ${key}`);\n\t\t}\n\t}\n\treturn parsed;\n}\n\nexport interface RemoteWorkspaceNegotiationOptions {\n\tserverVersions: readonly RemoteWorkspaceVersionRange[];\n\tserverCapabilities: readonly string[];\n\trequiredClientCapabilities?: readonly string[];\n\tserverLimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport interface RemoteWorkspaceNegotiationResult {\n\tversion: RemoteWorkspaceVersion;\n\tcapabilities: string[];\n\tlimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport type RemoteWorkspaceNegotiationErrorCode = \"incompatible_version\" | \"capability_mismatch\";\n\nexport class RemoteWorkspaceNegotiationError extends Error {\n\treadonly code: RemoteWorkspaceNegotiationErrorCode;\n\n\tconstructor(code: RemoteWorkspaceNegotiationErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceNegotiationError\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction validateVersionRanges(ranges: readonly RemoteWorkspaceVersionRange[], label: string): void {\n\tfor (const range of ranges) {\n\t\tif (range.minMinor > range.maxMinor) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\"incompatible_version\", `${label} has an inverted minor range`);\n\t\t}\n\t}\n}\n\nfunction findCompatibleRemoteWorkspaceVersions(\n\tclientVersions: readonly RemoteWorkspaceVersionRange[],\n\tserverVersions: readonly RemoteWorkspaceVersionRange[],\n): RemoteWorkspaceVersion[] {\n\tconst serverVersionsByMajor = new Map<number, RemoteWorkspaceVersionRange[]>();\n\tfor (const server of serverVersions) {\n\t\tconst ranges = serverVersionsByMajor.get(server.major) ?? [];\n\t\tranges.push(server);\n\t\tserverVersionsByMajor.set(server.major, ranges);\n\t}\n\tconst candidates: RemoteWorkspaceVersion[] = [];\n\tfor (const client of clientVersions) {\n\t\tfor (const server of serverVersionsByMajor.get(client.major) ?? []) {\n\t\t\tconst minMinor = Math.max(client.minMinor, server.minMinor);\n\t\t\tconst maxMinor = Math.min(client.maxMinor, server.maxMinor);\n\t\t\tif (minMinor <= maxMinor) candidates.push({ major: client.major, minor: maxMinor });\n\t\t}\n\t}\n\treturn candidates;\n}\n\nexport function negotiateRemoteWorkspaceHandshake(\n\thandshake: RemoteWorkspaceHandshake,\n\toptions: RemoteWorkspaceNegotiationOptions,\n): RemoteWorkspaceNegotiationResult {\n\tvalidateRemoteWorkspaceProtocolLimits(handshake.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(options.serverLimits);\n\tvalidateVersionRanges(handshake.versions, \"Client version offer\");\n\tvalidateVersionRanges(options.serverVersions, \"Server version offer\");\n\tassertUnique(handshake.requiredCapabilities, \"Required capabilities\");\n\tassertUnique(handshake.optionalCapabilities, \"Optional capabilities\");\n\tconst optionalCapabilities = new Set(handshake.optionalCapabilities);\n\tconst duplicateOffer = handshake.requiredCapabilities.find((capability) => optionalCapabilities.has(capability));\n\tif (duplicateOffer) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"capability_mismatch\",\n\t\t\t`Capability is both required and optional: ${duplicateOffer}`,\n\t\t);\n\t}\n\tconst candidates = findCompatibleRemoteWorkspaceVersions(handshake.versions, options.serverVersions);\n\tcandidates.sort((left, right) => right.major - left.major || right.minor - left.minor);\n\tconst version = candidates[0];\n\tif (!version) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"incompatible_version\",\n\t\t\t\"No compatible remote workspace protocol version\",\n\t\t);\n\t}\n\tconst serverCapabilities = new Set(options.serverCapabilities);\n\tfor (const capability of handshake.requiredCapabilities) {\n\t\tif (!serverCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Server does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst clientCapabilities = new Set([...handshake.requiredCapabilities, ...handshake.optionalCapabilities]);\n\tfor (const capability of options.requiredClientCapabilities ?? []) {\n\t\tif (!clientCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Client does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst capabilities = Array.from(clientCapabilities)\n\t\t.filter((capability) => serverCapabilities.has(capability))\n\t\t.sort();\n\tconst clientLimits = handshake.receiveLimits;\n\tconst serverLimits = options.serverLimits;\n\treturn {\n\t\tversion,\n\t\tcapabilities,\n\t\tlimits: {\n\t\t\tmaxMessageBytes: Math.min(clientLimits.maxMessageBytes, serverLimits.maxMessageBytes),\n\t\t\tmaxStringBytes: Math.min(clientLimits.maxStringBytes, serverLimits.maxStringBytes),\n\t\t\tmaxDepth: Math.min(clientLimits.maxDepth, serverLimits.maxDepth),\n\t\t\tmaxObjectKeys: Math.min(clientLimits.maxObjectKeys, serverLimits.maxObjectKeys),\n\t\t\tmaxArrayLength: Math.min(clientLimits.maxArrayLength, serverLimits.maxArrayLength),\n\t\t\tmaxNodes: Math.min(clientLimits.maxNodes, serverLimits.maxNodes),\n\t\t\tmaxRequestMs: Math.min(clientLimits.maxRequestMs, serverLimits.maxRequestMs),\n\t\t\tmaxTransferChunkBytes: Math.min(clientLimits.maxTransferChunkBytes, serverLimits.maxTransferChunkBytes),\n\t\t\tmaxPendingTransferBytes: Math.min(clientLimits.maxPendingTransferBytes, serverLimits.maxPendingTransferBytes),\n\t\t\tmaxPendingInboundBytes: Math.min(clientLimits.maxPendingInboundBytes, serverLimits.maxPendingInboundBytes),\n\t\t\tmaxPendingInboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingInboundMessages,\n\t\t\t\tserverLimits.maxPendingInboundMessages,\n\t\t\t),\n\t\t\tmaxPendingOutboundBytes: Math.min(clientLimits.maxPendingOutboundBytes, serverLimits.maxPendingOutboundBytes),\n\t\t\tmaxPendingOutboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingOutboundMessages,\n\t\t\t\tserverLimits.maxPendingOutboundMessages,\n\t\t\t),\n\t\t\tmaxTransferBytes: Math.min(clientLimits.maxTransferBytes, serverLimits.maxTransferBytes),\n\t\t\tmaxTransferChunks: Math.min(clientLimits.maxTransferChunks, serverLimits.maxTransferChunks),\n\t\t\tmaxActiveRequests: Math.min(clientLimits.maxActiveRequests, serverLimits.maxActiveRequests),\n\t\t\tmaxActiveTransfers: Math.min(clientLimits.maxActiveTransfers, serverLimits.maxActiveTransfers),\n\t\t\tmaxCancellationMs: Math.min(clientLimits.maxCancellationMs, serverLimits.maxCancellationMs),\n\t\t\tmaxTransportSendMs: Math.min(clientLimits.maxTransportSendMs, serverLimits.maxTransportSendMs),\n\t\t},\n\t};\n}\n\nexport function getRemoteWorkspaceMethodKind(method: RemoteWorkspaceMethod): RemoteWorkspaceOperationKind {\n\tswitch (method) {\n\t\tcase \"workspace.write\":\n\t\tcase \"workspace.mkdir\":\n\t\tcase \"transfer.upload\":\n\t\t\treturn \"mutation\";\n\t\tcase \"workspace.exec\":\n\t\t\treturn \"process\";\n\t\tcase \"tool.invoke\":\n\t\t\treturn \"service\";\n\t\tdefault:\n\t\t\treturn \"read\";\n\t}\n}\n"]}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/core/remote-workspace-protocol/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,kCAAkC;;;;EAAoD,CAAC;AAEpG,eAAO,MAAM,6BAA6B,kHAOhC,CAAC;AAEX,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvF,eAAO,MAAM,wBAAwB,yUAkB3B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E,eAAO,MAAM,4BAA4B,gTAgB/B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC;AACrF,MAAM,MAAM,6BAA6B,GAAG,aAAa,GAAG,WAAW,GAAG,eAAe,CAAC;AAC1F,MAAM,MAAM,yBAAyB,GAAG,OAAO,GAAG,SAAS,CAAC;AAC5D,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvF,MAAM,WAAW,+BAA+B;IAC/C,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,6BAA8B,SAAQ,+BAA+B;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IAChC,sB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,CAAC;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,6BAA6B,CAAC;CACtC;AAED,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAEjG,qBAAa,+BAAgC,SAAQ,KAAK;IACzD,QAAQ,CAAC,IAAI,EAAE,mCAAmC,CAAC;IAEnD,YAAY,IAAI,EAAE,mCAAmC,EAAE,OAAO,EAAE,MAAM,EAIrE;CACD;AA+BD,wBAAgB,iCAAiC,CAChD,SAAS,EAAE,wBAAwB,EACnC,OAAO,EAAE,iCAAiC,GACxC,gCAAgC,CA8ElC;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,qBAAqB,GAAG,4BAA4B,CAaxG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { type Static, Type } from \"typebox\";\nimport { Compile, type Validator } from \"typebox/compile\";\n\nexport const REMOTE_WORKSPACE_PROTOCOL_VERSIONS = [{ major: 1, minMinor: 0, maxMinor: 0 }] as const;\n\nexport const REMOTE_WORKSPACE_CAPABILITIES = [\n\t\"catalog_refresh\",\n\t\"tool_updates\",\n\t\"primitive_operations\",\n\t\"lsp_status\",\n\t\"file_transfer\",\n\t\"artifacts\",\n] as const;\n\nexport type RemoteWorkspaceCapability = (typeof REMOTE_WORKSPACE_CAPABILITIES)[number];\n\nexport const REMOTE_WORKSPACE_METHODS = [\n\t\"catalog.get\",\n\t\"tool.invoke\",\n\t\"workspace.access\",\n\t\"workspace.read\",\n\t\"workspace.write\",\n\t\"workspace.mkdir\",\n\t\"workspace.stat\",\n\t\"workspace.readdir\",\n\t\"workspace.glob\",\n\t\"workspace.grep\",\n\t\"workspace.detect_image_mime\",\n\t\"workspace.exec\",\n\t\"lsp.status\",\n\t\"resource.read\",\n\t\"artifact.read\",\n\t\"transfer.upload\",\n\t\"transfer.download\",\n] as const;\n\nexport type RemoteWorkspaceMethod = (typeof REMOTE_WORKSPACE_METHODS)[number];\n\nexport const REMOTE_WORKSPACE_ERROR_CODES = [\n\t\"invalid_request\",\n\t\"method_not_supported\",\n\t\"incompatible_version\",\n\t\"capability_mismatch\",\n\t\"schema_mismatch\",\n\t\"stale_generation\",\n\t\"not_available\",\n\t\"limit_exceeded\",\n\t\"deadline_exceeded\",\n\t\"cancelled\",\n\t\"conflict\",\n\t\"generation_retired\",\n\t\"connection_draining\",\n\t\"result_too_large\",\n\t\"internal_error\",\n] as const;\n\nexport type RemoteWorkspaceErrorCode = (typeof REMOTE_WORKSPACE_ERROR_CODES)[number];\nexport type RemoteWorkspaceExecutionState = \"not_started\" | \"completed\" | \"indeterminate\";\nexport type RemoteWorkspacePathFlavor = \"posix\" | \"windows\";\nexport type RemoteWorkspaceOperationKind = \"read\" | \"mutation\" | \"process\" | \"service\";\n\nexport interface RemoteWorkspaceStructuralLimits {\n\tmaxMessageBytes: number;\n\tmaxStringBytes: number;\n\tmaxDepth: number;\n\tmaxObjectKeys: number;\n\tmaxArrayLength: number;\n\tmaxNodes: number;\n}\n\nexport interface RemoteWorkspaceProtocolLimits extends RemoteWorkspaceStructuralLimits {\n\tmaxRequestMs: number;\n\tmaxTransferChunkBytes: number;\n\tmaxPendingTransferBytes: number;\n\tmaxPendingInboundBytes: number;\n\tmaxPendingInboundMessages: number;\n\tmaxPendingOutboundBytes: number;\n\tmaxPendingOutboundMessages: number;\n\tmaxTransferBytes: number;\n\tmaxTransferChunks: number;\n\tmaxActiveRequests: number;\n\tmaxActiveTransfers: number;\n\tmaxCancellationMs: number;\n\tmaxTransportSendMs: number;\n}\n\nexport const DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS: RemoteWorkspaceProtocolLimits = {\n\tmaxMessageBytes: 2 * 1024 * 1024,\n\tmaxStringBytes: 1536 * 1024,\n\tmaxDepth: 32,\n\tmaxObjectKeys: 4096,\n\tmaxArrayLength: 4096,\n\tmaxNodes: 16_384,\n\tmaxRequestMs: 10 * 60 * 1000,\n\tmaxTransferChunkBytes: 64 * 1024,\n\tmaxPendingTransferBytes: 256 * 1024,\n\tmaxPendingInboundBytes: 4 * 1024 * 1024,\n\tmaxPendingInboundMessages: 64,\n\tmaxPendingOutboundBytes: 4 * 1024 * 1024,\n\tmaxPendingOutboundMessages: 128,\n\tmaxTransferBytes: 100 * 1024 * 1024,\n\tmaxTransferChunks: 16_384,\n\tmaxActiveRequests: 64,\n\tmaxActiveTransfers: 8,\n\tmaxCancellationMs: 100,\n\tmaxTransportSendMs: 10_000,\n};\n\nconst closedObject = { additionalProperties: false } as const;\nconst safeIntegerOptions = { minimum: 0, maximum: Number.MAX_SAFE_INTEGER } as const;\nconst RequestIdSchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z0-9._:-]+$\" });\nconst HashSchema = Type.String({ pattern: \"^[0-9a-f]{64}$\" });\nconst CapabilitySchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[a-z][a-z0-9_.-]*$\" });\nconst RemoteWorkspaceMethodSchema = Type.Union([\n\tType.Literal(\"catalog.get\"),\n\tType.Literal(\"tool.invoke\"),\n\tType.Literal(\"workspace.access\"),\n\tType.Literal(\"workspace.read\"),\n\tType.Literal(\"workspace.write\"),\n\tType.Literal(\"workspace.mkdir\"),\n\tType.Literal(\"workspace.stat\"),\n\tType.Literal(\"workspace.readdir\"),\n\tType.Literal(\"workspace.glob\"),\n\tType.Literal(\"workspace.grep\"),\n\tType.Literal(\"workspace.detect_image_mime\"),\n\tType.Literal(\"workspace.exec\"),\n\tType.Literal(\"lsp.status\"),\n\tType.Literal(\"resource.read\"),\n\tType.Literal(\"artifact.read\"),\n\tType.Literal(\"transfer.upload\"),\n\tType.Literal(\"transfer.download\"),\n]);\n\nexport const RemoteWorkspaceVersionRangeSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t\tmaxMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersionRange = Static<typeof RemoteWorkspaceVersionRangeSchema>;\n\nexport const RemoteWorkspaceVersionSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersion = Static<typeof RemoteWorkspaceVersionSchema>;\n\nexport const RemoteWorkspaceLimitsSchema = Type.Object(\n\t{\n\t\tmaxMessageBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxStringBytes: Type.Integer({ minimum: 1, maximum: 64 * 1024 * 1024 }),\n\t\tmaxDepth: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxObjectKeys: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxArrayLength: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxNodes: Type.Integer({ minimum: 1, maximum: 2_000_000 }),\n\t\tmaxRequestMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tmaxTransferChunkBytes: Type.Integer({ minimum: 1024, maximum: 1024 * 1024 }),\n\t\tmaxPendingTransferBytes: Type.Integer({ minimum: 1024, maximum: 16 * 1024 * 1024 }),\n\t\tmaxPendingInboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingInboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxPendingOutboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingOutboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxTransferBytes: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tmaxTransferChunks: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxActiveRequests: Type.Integer({ minimum: 1, maximum: 10_000_000 }),\n\t\tmaxActiveTransfers: Type.Integer({ minimum: 1, maximum: 10_000 }),\n\t\tmaxCancellationMs: Type.Integer({ minimum: 1, maximum: 60_000 }),\n\t\tmaxTransportSendMs: Type.Integer({ minimum: 1, maximum: 5 * 60_000 }),\n\t},\n\tclosedObject,\n);\n\nexport const RemoteWorkspaceIdentitySchema = Type.Object(\n\t{\n\t\tid: Type.String({ minLength: 16, maxLength: 128, pattern: \"^[A-Za-z0-9_-]+$\" }),\n\t\troot: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tpathFlavor: Type.Union([Type.Literal(\"posix\"), Type.Literal(\"windows\")]),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceIdentity = Static<typeof RemoteWorkspaceIdentitySchema>;\n\nexport const RemoteWorkspaceToolCatalogEntrySchema = Type.Object(\n\t{\n\t\tname: Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z][A-Za-z0-9_.-]*$\" }),\n\t\texecutionMode: Type.Union([\n\t\t\tType.Literal(\"read\"),\n\t\t\tType.Literal(\"mutation\"),\n\t\t\tType.Literal(\"process\"),\n\t\t\tType.Literal(\"service\"),\n\t\t]),\n\t\tparameterSchema: Type.Record(Type.String({ maxLength: 256 }), Type.Unknown()),\n\t\tschemaHash: HashSchema,\n\t\tfeatureFlags: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceToolCatalogEntry = Static<typeof RemoteWorkspaceToolCatalogEntrySchema>;\n\nexport const RemoteWorkspaceCatalogSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\ttools: Type.Array(RemoteWorkspaceToolCatalogEntrySchema, { maxItems: 1024 }),\n\t\toperations: Type.Array(RemoteWorkspaceMethodSchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalog = Static<typeof RemoteWorkspaceCatalogSchema>;\n\nexport const RemoteWorkspaceHandshakeSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake\"),\n\t\tid: RequestIdSchema,\n\t\tversions: Type.Array(RemoteWorkspaceVersionRangeSchema, { minItems: 1, maxItems: 16 }),\n\t\trequiredCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\toptionalCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\treceiveLimits: RemoteWorkspaceLimitsSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshake = Static<typeof RemoteWorkspaceHandshakeSchema>;\n\nexport const RemoteWorkspaceHandshakeAckSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake_ack\"),\n\t\tid: RequestIdSchema,\n\t\tversion: RemoteWorkspaceVersionSchema,\n\t\tcapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t\tlimits: RemoteWorkspaceLimitsSchema,\n\t\tcatalog: RemoteWorkspaceCatalogSchema,\n\t\tcatalogHash: HashSchema,\n\t\tbackendMetadata: Type.Object(\n\t\t\t{\n\t\t\t\tkind: Type.Literal(\"remote-workspace\"),\n\t\t\t\tlabel: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshakeAck = Static<typeof RemoteWorkspaceHandshakeAckSchema>;\n\nexport const RemoteWorkspaceRequestSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"request\"),\n\t\tid: RequestIdSchema,\n\t\tmethod: Type.String({ minLength: 1, maxLength: 128 }),\n\t\ttimeoutMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tparams: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceRequest = Static<typeof RemoteWorkspaceRequestSchema>;\n\nexport const RemoteWorkspaceCancelSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"cancel\"),\n\t\tid: RequestIdSchema,\n\t\treason: Type.Optional(Type.String({ maxLength: 256 })),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCancel = Static<typeof RemoteWorkspaceCancelSchema>;\n\nexport const RemoteWorkspaceTransferChunkSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_chunk\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tdataBase64: Type.String({ minLength: 4 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferChunk = Static<typeof RemoteWorkspaceTransferChunkSchema>;\n\nexport const RemoteWorkspaceTransferFinishSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_finish\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferFinish = Static<typeof RemoteWorkspaceTransferFinishSchema>;\n\nexport const RemoteWorkspaceResultSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"result\"),\n\t\tid: RequestIdSchema,\n\t\tresult: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceResult = Static<typeof RemoteWorkspaceResultSchema>;\n\nexport const RemoteWorkspaceProtocolErrorSchema = Type.Object(\n\t{\n\t\tcode: Type.Union([\n\t\t\tType.Literal(\"invalid_request\"),\n\t\t\tType.Literal(\"method_not_supported\"),\n\t\t\tType.Literal(\"incompatible_version\"),\n\t\t\tType.Literal(\"capability_mismatch\"),\n\t\t\tType.Literal(\"schema_mismatch\"),\n\t\t\tType.Literal(\"stale_generation\"),\n\t\t\tType.Literal(\"not_available\"),\n\t\t\tType.Literal(\"limit_exceeded\"),\n\t\t\tType.Literal(\"deadline_exceeded\"),\n\t\t\tType.Literal(\"cancelled\"),\n\t\t\tType.Literal(\"conflict\"),\n\t\t\tType.Literal(\"generation_retired\"),\n\t\t\tType.Literal(\"connection_draining\"),\n\t\t\tType.Literal(\"result_too_large\"),\n\t\t\tType.Literal(\"internal_error\"),\n\t\t]),\n\t\tmessage: Type.String({ minLength: 1, maxLength: 4096 }),\n\t\texecutionState: Type.Union([\n\t\t\tType.Literal(\"not_started\"),\n\t\t\tType.Literal(\"completed\"),\n\t\t\tType.Literal(\"indeterminate\"),\n\t\t]),\n\t\tretryable: Type.Boolean(),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceProtocolError = Static<typeof RemoteWorkspaceProtocolErrorSchema>;\n\nexport const RemoteWorkspaceErrorMessageSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"error\"),\n\t\tid: RequestIdSchema,\n\t\terror: RemoteWorkspaceProtocolErrorSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceErrorMessage = Static<typeof RemoteWorkspaceErrorMessageSchema>;\n\nexport const RemoteWorkspaceUpdateSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"update\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tupdate: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceUpdate = Static<typeof RemoteWorkspaceUpdateSchema>;\n\nexport const RemoteWorkspaceTransferStartSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_start\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferStart = Static<typeof RemoteWorkspaceTransferStartSchema>;\n\nexport const RemoteWorkspaceCatalogChangedSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"catalog_changed\"),\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalogChanged = Static<typeof RemoteWorkspaceCatalogChangedSchema>;\n\nexport const RemoteWorkspaceClientMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeSchema,\n\tRemoteWorkspaceRequestSchema,\n\tRemoteWorkspaceCancelSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceTransferFinishSchema,\n]);\n\nexport const RemoteWorkspaceServerMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeAckSchema,\n\tRemoteWorkspaceResultSchema,\n\tRemoteWorkspaceErrorMessageSchema,\n\tRemoteWorkspaceUpdateSchema,\n\tRemoteWorkspaceTransferStartSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceCatalogChangedSchema,\n]);\n\nexport type RemoteWorkspaceClientMessage = Static<typeof RemoteWorkspaceClientMessageSchema>;\nexport type RemoteWorkspaceServerMessage = Static<typeof RemoteWorkspaceServerMessageSchema>;\n\nconst EmptyParamsSchema = Type.Object({}, closedObject);\nconst PathParamsSchema = Type.Object({ path: Type.String({ minLength: 1, maxLength: 32_768 }) }, closedObject);\nconst CatalogGetParamsSchema = EmptyParamsSchema;\nconst SessionEnvironmentSchema = Type.Object(\n\t{\n\t\tGRIP_SESSION_ID: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_SESSION_FILE: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_PROVIDER: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_MODEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_REASONING_LEVEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t},\n\tclosedObject,\n);\n/** Shared v2 mutations require an observed digest/absence, or an explicitly unsafe write. */\nconst ExpectedRevisionSchema = Type.Union([\n\tType.Object({ sha256: HashSchema }, closedObject),\n\tType.Object({ absent: Type.Literal(true) }, closedObject),\n\tType.Object({ unsafeOverwrite: Type.Literal(true) }, closedObject),\n]);\nexport type ExpectedWorkspaceRevision = Static<typeof ExpectedRevisionSchema>;\nconst ToolInvokeParamsSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t\ttoolName: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tschemaHash: HashSchema,\n\t\targumentsPrepared: Type.Literal(true),\n\t\targuments: Type.Unknown(),\n\t\texpectedRevision: Type.Optional(ExpectedRevisionSchema),\n\t\texecutionOptions: Type.Object(\n\t\t\t{\n\t\t\t\timageAutoResize: Type.Optional(Type.Boolean()),\n\t\t\t\tshellCommandPrefix: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\t\t\tsessionEnvironment: Type.Optional(SessionEnvironmentSchema),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\nconst AccessParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tmode: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"exists\"), Type.Literal(\"read\"), Type.Literal(\"write\"), Type.Literal(\"readwrite\")]),\n\t\t),\n\t},\n\tclosedObject,\n);\nconst WriteParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcontentBase64: Type.String(),\n\t\texpectedRevision: Type.Optional(ExpectedRevisionSchema),\n\t},\n\tclosedObject,\n);\nconst MkdirParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\trecursive: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst GlobParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tignore: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 4096 }),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst GrepParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ maxLength: 1024 * 1024 }),\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tglob: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tignoreCase: Type.Optional(Type.Boolean()),\n\t\tliteral: Type.Optional(Type.Boolean()),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst ExecParamsSchema = Type.Object(\n\t{\n\t\tcommand: Type.String({ minLength: 1 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\nconst TransferUploadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t\toverwrite: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst TransferDownloadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\n\nconst ToolContentSchema = Type.Union([\n\tType.Object({ type: Type.Literal(\"text\"), text: Type.String() }, closedObject),\n\tType.Object(\n\t\t{\n\t\t\ttype: Type.Literal(\"image\"),\n\t\t\tdata: Type.String(),\n\t\t\tmimeType: Type.String({ minLength: 1, maxLength: 256 }),\n\t\t},\n\t\tclosedObject,\n\t),\n]);\nconst ToolResultSchema = Type.Object(\n\t{\n\t\tcontent: Type.Array(ToolContentSchema),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t\tterminate: Type.Optional(Type.Boolean()),\n\t},\n\tclosedObject,\n);\nconst EmptyResultSchema = EmptyParamsSchema;\nconst LspStatusServerSchema = Type.Object(\n\t{\n\t\tserverId: Type.String({ minLength: 1, maxLength: 256 }),\n\t\tlanguageIds: Type.Array(Type.String({ maxLength: 256 }), { maxItems: 256 }),\n\t\ttransport: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tinstanceKey: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\tworkspaceRoot: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tendpoint: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\trootUri: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\townership: Type.Union([Type.Literal(\"managed\"), Type.Literal(\"attached\")]),\n\t\tshutdownMode: Type.Union([Type.Literal(\"protocol\"), Type.Literal(\"disconnect\")]),\n\t\tstate: Type.Union([\n\t\t\tType.Literal(\"idle\"),\n\t\t\tType.Literal(\"connecting\"),\n\t\t\tType.Literal(\"initializing\"),\n\t\t\tType.Literal(\"running\"),\n\t\t\tType.Literal(\"closed\"),\n\t\t\tType.Literal(\"failed\"),\n\t\t\tType.Literal(\"disposed\"),\n\t\t]),\n\t\treconnectEligible: Type.Boolean(),\n\t\trunning: Type.Boolean(),\n\t\tstarting: Type.Boolean(),\n\t\tdiagnosticsCount: Type.Integer(safeIntegerOptions),\n\t\tlastError: Type.Optional(Type.String()),\n\t\tlastRequestError: Type.Optional(Type.String()),\n\t\tstderr: Type.Optional(Type.String()),\n\t\tsynchronizationError: Type.Optional(Type.String()),\n\t},\n\tclosedObject,\n);\nconst LspStatusResultSchema = Type.Object(\n\t{ enabled: Type.Boolean(), servers: Type.Array(LspStatusServerSchema, { maxItems: 1024 }) },\n\tclosedObject,\n);\nexport type RemoteLspStatus = Static<typeof LspStatusResultSchema>;\nconst ReadResultSchema = Type.Object(\n\t{\n\t\tcontentBase64: Type.String(),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t\trevision: Type.Optional(HashSchema),\n\t},\n\tclosedObject,\n);\nconst StatResultSchema = Type.Object(\n\t{\n\t\tkind: Type.Union([\n\t\t\tType.Literal(\"file\"),\n\t\t\tType.Literal(\"directory\"),\n\t\t\tType.Literal(\"other\"),\n\t\t\tType.Literal(\"absent\"),\n\t\t]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ReaddirResultSchema = Type.Object(\n\t{\n\t\tentries: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GlobResultSchema = Type.Object(\n\t{\n\t\tmatches: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GrepResultSchema = Type.Object(\n\t{\n\t\tisDirectory: Type.Boolean(),\n\t\tmatches: Type.Array(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tfilePath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\t\t\t\tlineNumber: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\t\t\t\tlineText: Type.Optional(Type.String()),\n\t\t\t\t},\n\t\t\t\tclosedObject,\n\t\t\t),\n\t\t\t{ maxItems: 1_000_000 },\n\t\t),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst MimeResultSchema = Type.Object(\n\t{\n\t\tmimeType: Type.Union([\n\t\t\tType.Literal(\"image/jpeg\"),\n\t\t\tType.Literal(\"image/png\"),\n\t\t\tType.Literal(\"image/gif\"),\n\t\t\tType.Literal(\"image/webp\"),\n\t\t\tType.Null(),\n\t\t]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ExecResultSchema = Type.Object(\n\t{ exitCode: Type.Union([Type.Integer({ minimum: 0, maximum: 255 }), Type.Null()]) },\n\tclosedObject,\n);\nconst TransferResultSchema = Type.Object(\n\t{\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nconst parameterValidators = {\n\t\"catalog.get\": Compile(CatalogGetParamsSchema),\n\t\"tool.invoke\": Compile(ToolInvokeParamsSchema),\n\t\"workspace.access\": Compile(AccessParamsSchema),\n\t\"workspace.read\": Compile(PathParamsSchema),\n\t\"workspace.write\": Compile(WriteParamsSchema),\n\t\"workspace.mkdir\": Compile(MkdirParamsSchema),\n\t\"workspace.stat\": Compile(PathParamsSchema),\n\t\"workspace.readdir\": Compile(PathParamsSchema),\n\t\"workspace.glob\": Compile(GlobParamsSchema),\n\t\"workspace.grep\": Compile(GrepParamsSchema),\n\t\"workspace.detect_image_mime\": Compile(PathParamsSchema),\n\t\"workspace.exec\": Compile(ExecParamsSchema),\n\t\"lsp.status\": Compile(EmptyParamsSchema),\n\t\"resource.read\": Compile(PathParamsSchema),\n\t\"artifact.read\": Compile(PathParamsSchema),\n\t\"transfer.upload\": Compile(TransferUploadParamsSchema),\n\t\"transfer.download\": Compile(TransferDownloadParamsSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile>>;\n\nconst resultValidators = {\n\t\"catalog.get\": Compile(RemoteWorkspaceCatalogSchema),\n\t\"tool.invoke\": Compile(ToolResultSchema),\n\t\"workspace.access\": Compile(EmptyResultSchema),\n\t\"workspace.read\": Compile(ReadResultSchema),\n\t\"workspace.write\": Compile(EmptyResultSchema),\n\t\"workspace.mkdir\": Compile(EmptyResultSchema),\n\t\"workspace.stat\": Compile(StatResultSchema),\n\t\"workspace.readdir\": Compile(ReaddirResultSchema),\n\t\"workspace.glob\": Compile(GlobResultSchema),\n\t\"workspace.grep\": Compile(GrepResultSchema),\n\t\"workspace.detect_image_mime\": Compile(MimeResultSchema),\n\t\"workspace.exec\": Compile(ExecResultSchema),\n\t\"lsp.status\": Compile(LspStatusResultSchema),\n\t\"resource.read\": Compile(ReadResultSchema),\n\t\"artifact.read\": Compile(TransferResultSchema),\n\t\"transfer.upload\": Compile(TransferResultSchema),\n\t\"transfer.download\": Compile(TransferResultSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile> | undefined>;\n\nconst clientMessageValidator = Compile(RemoteWorkspaceClientMessageSchema);\nconst serverMessageValidator = Compile(RemoteWorkspaceServerMessageSchema);\nconst handshakeAckValidator = Compile(RemoteWorkspaceHandshakeAckSchema);\nconst limitsValidator = Compile(RemoteWorkspaceLimitsSchema);\n\nexport class RemoteWorkspaceValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceValidationError\";\n\t}\n}\n\nfunction validationMessage(validator: Validator, value: unknown): string {\n\tconst error = validator.Errors(value)[0];\n\tif (!error) return \"value does not match the protocol schema\";\n\treturn `${error.instancePath || \"/\"}: ${error.message}`;\n}\n\nfunction parseWithValidator<T>(validator: Validator, value: unknown, label: string): T {\n\tif (!validator.Check(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(`Invalid ${label}: ${validationMessage(validator, value)}`);\n\t}\n\treturn value as T;\n}\n\nexport function validateRemoteWorkspaceProtocolLimits(value: unknown): RemoteWorkspaceProtocolLimits {\n\tconst limits = parseWithValidator<RemoteWorkspaceProtocolLimits>(limitsValidator, value, \"protocol limits\");\n\tif (limits.maxMessageBytes > limits.maxPendingInboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingInboundBytes\");\n\t}\n\tif (limits.maxMessageBytes > limits.maxPendingOutboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingOutboundBytes\");\n\t}\n\tif (limits.maxTransferChunkBytes > limits.maxPendingTransferBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must not exceed maxPendingTransferBytes\");\n\t}\n\tif (Math.ceil((limits.maxTransferChunkBytes * 4) / 3) + 512 > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must fit in one base64 protocol message\");\n\t}\n\treturn limits;\n}\n\ninterface RemoteWorkspacePendingValue {\n\tvalue: unknown;\n\tdepth: number;\n}\n\ninterface RemoteWorkspaceStructureState {\n\tpending: RemoteWorkspacePendingValue[];\n\tnodes: number;\n\tobjectKeys: number;\n\tlimits: RemoteWorkspaceStructuralLimits;\n}\n\nfunction validateRemoteWorkspaceNodeBudget(depth: number, state: RemoteWorkspaceStructureState): void {\n\tstate.nodes++;\n\tif (state.nodes > state.limits.maxNodes)\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds node limit\");\n\tif (depth > state.limits.maxDepth) throw new RemoteWorkspaceValidationError(\"Protocol value exceeds depth limit\");\n}\n\nfunction validateRemoteWorkspaceScalar(value: unknown, limits: RemoteWorkspaceStructuralLimits): boolean {\n\tif (value === null || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Protocol numbers must be finite\");\n\t\treturn true;\n\t}\n\tif (typeof value !== \"string\") return false;\n\tif (Buffer.byteLength(value, \"utf8\") > limits.maxStringBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol string exceeds byte limit\");\n\t}\n\treturn true;\n}\n\nfunction enqueueRemoteWorkspaceArray(value: unknown[], depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value.length > state.limits.maxArrayLength) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol array exceeds item limit\");\n\t}\n\tfor (let index = value.length - 1; index >= 0; index--) {\n\t\tstate.pending.push({ value: value[index], depth: depth + 1 });\n\t}\n}\n\nfunction enqueueRemoteWorkspaceObject(value: unknown, depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value === null || typeof value !== \"object\")\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol values must be JSON-compatible\");\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol objects must be plain JSON objects\");\n\t}\n\tconst entries = Object.entries(value);\n\tif (entries.length > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object exceeds key limit\");\n\t}\n\tstate.objectKeys += entries.length;\n\tif (state.objectKeys > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds total key limit\");\n\t}\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (!entry) continue;\n\t\tif (Buffer.byteLength(entry[0], \"utf8\") > state.limits.maxStringBytes) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object key exceeds byte limit\");\n\t\t}\n\t\tstate.pending.push({ value: entry[1], depth: depth + 1 });\n\t}\n}\n\nexport function assertRemoteWorkspaceJsonStructure(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): void {\n\tconst state: RemoteWorkspaceStructureState = {\n\t\tpending: [{ value, depth: 1 }],\n\t\tnodes: 0,\n\t\tobjectKeys: 0,\n\t\tlimits,\n\t};\n\twhile (state.pending.length > 0) {\n\t\tconst current = state.pending.pop();\n\t\tif (!current) break;\n\t\tvalidateRemoteWorkspaceNodeBudget(current.depth, state);\n\t\tif (validateRemoteWorkspaceScalar(current.value, limits)) continue;\n\t\tif (Array.isArray(current.value)) {\n\t\t\tenqueueRemoteWorkspaceArray(current.value, current.depth, state);\n\t\t\tcontinue;\n\t\t}\n\t\tenqueueRemoteWorkspaceObject(current.value, current.depth, state);\n\t}\n}\n\nexport function decodeRemoteWorkspaceMessage(\n\tpayload: string | Uint8Array,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tconst bytes = typeof payload === \"string\" ? Buffer.from(payload, \"utf8\") : payload;\n\tif (bytes.byteLength > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol message exceeds byte limit\");\n\t}\n\tconst text = typeof payload === \"string\" ? payload : new TextDecoder(\"utf-8\", { fatal: true }).decode(payload);\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(text) as unknown;\n\t} catch (error) {\n\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t`Protocol message is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn value;\n}\n\nexport function parseRemoteWorkspaceClientMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceClientMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceClientMessage>(clientMessageValidator, value, \"client message\");\n}\n\nexport function parseRemoteWorkspaceServerMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceServerMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceServerMessage>(serverMessageValidator, value, \"server message\");\n}\n\nexport function isRemoteWorkspaceMethod(method: string): method is RemoteWorkspaceMethod {\n\treturn (REMOTE_WORKSPACE_METHODS as readonly string[]).includes(method);\n}\n\nexport function parseRemoteWorkspaceRequestParams(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst parsed = parseWithValidator(parameterValidators[method], value, `${method} params`);\n\tif (method === \"workspace.write\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceResult(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst validator = resultValidators[method];\n\tconst parsed = validator ? parseWithValidator(validator, value, `${method} result`) : value;\n\tif (method === \"workspace.read\" || method === \"resource.read\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceToolResult(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator(Compile(ToolResultSchema), value, \"tool result\");\n}\n\nexport function decodeCanonicalBase64(value: string, maxBytes: number): Buffer {\n\tif (value.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\tconst decoded = Buffer.from(value, \"base64\");\n\tif (decoded.byteLength > maxBytes) throw new RemoteWorkspaceValidationError(\"Transfer chunk exceeds byte limit\");\n\tif (decoded.toString(\"base64\") !== value) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\treturn decoded;\n}\n\nfunction canonicalJson(value: unknown): string {\n\tif (value === null) return \"null\";\n\tif (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Cannot hash a non-finite number\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (typeof value === \"string\") return JSON.stringify(value);\n\tif (Array.isArray(value)) return `[${value.map((entry) => canonicalJson(entry)).join(\",\")}]`;\n\tif (typeof value !== \"object\" || value === undefined) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Cannot hash a non-JSON value\");\n\t}\n\tconst entries = Object.entries(value).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));\n\treturn `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(\",\")}}`;\n}\n\nexport function hashRemoteWorkspaceJson(value: unknown): string {\n\tassertRemoteWorkspaceJsonStructure(value);\n\treturn createHash(\"sha256\").update(canonicalJson(value)).digest(\"hex\");\n}\n\nexport function hashRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): string {\n\treturn hashRemoteWorkspaceJson(catalog);\n}\n\nfunction assertUnique(values: readonly string[], label: string): void {\n\tif (new Set(values).size !== values.length) throw new RemoteWorkspaceValidationError(`${label} contains duplicates`);\n}\n\nexport function validateRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): void {\n\tparseWithValidator(Compile(RemoteWorkspaceCatalogSchema), catalog, \"tool catalog\");\n\tassertUnique(catalog.operations, \"Catalog operations\");\n\tassertUnique(\n\t\tcatalog.tools.map((tool) => tool.name),\n\t\t\"Catalog tool names\",\n\t);\n\tfor (const tool of catalog.tools) {\n\t\tassertUnique(tool.featureFlags, `Feature flags for ${tool.name}`);\n\t\tif (hashRemoteWorkspaceJson(tool.parameterSchema) !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Schema hash mismatch for tool ${tool.name}`);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceLocalToolSchemas(\n\tcatalog: RemoteWorkspaceCatalog,\n\tlocalToolSchemas: ReadonlyMap<string, string>,\n): void {\n\tfor (const tool of catalog.tools) {\n\t\tconst localHash = localToolSchemas.get(tool.name);\n\t\tif (localHash !== undefined && localHash !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t\t`Remote schema does not match the local canonical schema for ${tool.name}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceHandshakeAck(\n\tack: unknown,\n\toffer: RemoteWorkspaceHandshake,\n\tlocalToolSchemas: ReadonlyMap<string, string> = new Map(),\n): RemoteWorkspaceHandshakeAck {\n\tconst parsed = parseWithValidator<RemoteWorkspaceHandshakeAck>(handshakeAckValidator, ack, \"handshake response\");\n\tvalidateRemoteWorkspaceProtocolLimits(offer.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(parsed.limits);\n\tconst selected = offer.versions.some(\n\t\t(range) =>\n\t\t\trange.major === parsed.version.major &&\n\t\t\trange.minMinor <= parsed.version.minor &&\n\t\t\trange.maxMinor >= parsed.version.minor,\n\t);\n\tif (!selected)\n\t\tthrow new RemoteWorkspaceValidationError(\"Server selected a protocol version outside the offered range\");\n\tconst offeredCapabilities = new Set([...offer.requiredCapabilities, ...offer.optionalCapabilities]);\n\tfor (const capability of parsed.capabilities) {\n\t\tif (!offeredCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server selected an unoffered capability: ${capability}`);\n\t\t}\n\t}\n\tconst selectedCapabilities = new Set(parsed.capabilities);\n\tfor (const capability of offer.requiredCapabilities) {\n\t\tif (!selectedCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server omitted required capability: ${capability}`);\n\t\t}\n\t}\n\tassertUnique(parsed.capabilities, \"Negotiated capabilities\");\n\tvalidateRemoteWorkspaceCatalog(parsed.catalog);\n\tif (hashRemoteWorkspaceCatalog(parsed.catalog) !== parsed.catalogHash) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Catalog hash does not match the negotiated catalog\");\n\t}\n\tvalidateRemoteWorkspaceLocalToolSchemas(parsed.catalog, localToolSchemas);\n\tfor (const key of Object.keys(offer.receiveLimits) as (keyof RemoteWorkspaceProtocolLimits)[]) {\n\t\tif (parsed.limits[key] > offer.receiveLimits[key]) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server increased negotiated limit: ${key}`);\n\t\t}\n\t}\n\treturn parsed;\n}\n\nexport interface RemoteWorkspaceNegotiationOptions {\n\tserverVersions: readonly RemoteWorkspaceVersionRange[];\n\tserverCapabilities: readonly string[];\n\trequiredClientCapabilities?: readonly string[];\n\tserverLimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport interface RemoteWorkspaceNegotiationResult {\n\tversion: RemoteWorkspaceVersion;\n\tcapabilities: string[];\n\tlimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport type RemoteWorkspaceNegotiationErrorCode = \"incompatible_version\" | \"capability_mismatch\";\n\nexport class RemoteWorkspaceNegotiationError extends Error {\n\treadonly code: RemoteWorkspaceNegotiationErrorCode;\n\n\tconstructor(code: RemoteWorkspaceNegotiationErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceNegotiationError\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction validateVersionRanges(ranges: readonly RemoteWorkspaceVersionRange[], label: string): void {\n\tfor (const range of ranges) {\n\t\tif (range.minMinor > range.maxMinor) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\"incompatible_version\", `${label} has an inverted minor range`);\n\t\t}\n\t}\n}\n\nfunction findCompatibleRemoteWorkspaceVersions(\n\tclientVersions: readonly RemoteWorkspaceVersionRange[],\n\tserverVersions: readonly RemoteWorkspaceVersionRange[],\n): RemoteWorkspaceVersion[] {\n\tconst serverVersionsByMajor = new Map<number, RemoteWorkspaceVersionRange[]>();\n\tfor (const server of serverVersions) {\n\t\tconst ranges = serverVersionsByMajor.get(server.major) ?? [];\n\t\tranges.push(server);\n\t\tserverVersionsByMajor.set(server.major, ranges);\n\t}\n\tconst candidates: RemoteWorkspaceVersion[] = [];\n\tfor (const client of clientVersions) {\n\t\tfor (const server of serverVersionsByMajor.get(client.major) ?? []) {\n\t\t\tconst minMinor = Math.max(client.minMinor, server.minMinor);\n\t\t\tconst maxMinor = Math.min(client.maxMinor, server.maxMinor);\n\t\t\tif (minMinor <= maxMinor) candidates.push({ major: client.major, minor: maxMinor });\n\t\t}\n\t}\n\treturn candidates;\n}\n\nexport function negotiateRemoteWorkspaceHandshake(\n\thandshake: RemoteWorkspaceHandshake,\n\toptions: RemoteWorkspaceNegotiationOptions,\n): RemoteWorkspaceNegotiationResult {\n\tvalidateRemoteWorkspaceProtocolLimits(handshake.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(options.serverLimits);\n\tvalidateVersionRanges(handshake.versions, \"Client version offer\");\n\tvalidateVersionRanges(options.serverVersions, \"Server version offer\");\n\tassertUnique(handshake.requiredCapabilities, \"Required capabilities\");\n\tassertUnique(handshake.optionalCapabilities, \"Optional capabilities\");\n\tconst optionalCapabilities = new Set(handshake.optionalCapabilities);\n\tconst duplicateOffer = handshake.requiredCapabilities.find((capability) => optionalCapabilities.has(capability));\n\tif (duplicateOffer) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"capability_mismatch\",\n\t\t\t`Capability is both required and optional: ${duplicateOffer}`,\n\t\t);\n\t}\n\tconst candidates = findCompatibleRemoteWorkspaceVersions(handshake.versions, options.serverVersions);\n\tcandidates.sort((left, right) => right.major - left.major || right.minor - left.minor);\n\tconst version = candidates[0];\n\tif (!version) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"incompatible_version\",\n\t\t\t\"No compatible remote workspace protocol version\",\n\t\t);\n\t}\n\tconst serverCapabilities = new Set(options.serverCapabilities);\n\tfor (const capability of handshake.requiredCapabilities) {\n\t\tif (!serverCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Server does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst clientCapabilities = new Set([...handshake.requiredCapabilities, ...handshake.optionalCapabilities]);\n\tfor (const capability of options.requiredClientCapabilities ?? []) {\n\t\tif (!clientCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Client does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst capabilities = Array.from(clientCapabilities)\n\t\t.filter((capability) => serverCapabilities.has(capability))\n\t\t.sort();\n\tconst clientLimits = handshake.receiveLimits;\n\tconst serverLimits = options.serverLimits;\n\treturn {\n\t\tversion,\n\t\tcapabilities,\n\t\tlimits: {\n\t\t\tmaxMessageBytes: Math.min(clientLimits.maxMessageBytes, serverLimits.maxMessageBytes),\n\t\t\tmaxStringBytes: Math.min(clientLimits.maxStringBytes, serverLimits.maxStringBytes),\n\t\t\tmaxDepth: Math.min(clientLimits.maxDepth, serverLimits.maxDepth),\n\t\t\tmaxObjectKeys: Math.min(clientLimits.maxObjectKeys, serverLimits.maxObjectKeys),\n\t\t\tmaxArrayLength: Math.min(clientLimits.maxArrayLength, serverLimits.maxArrayLength),\n\t\t\tmaxNodes: Math.min(clientLimits.maxNodes, serverLimits.maxNodes),\n\t\t\tmaxRequestMs: Math.min(clientLimits.maxRequestMs, serverLimits.maxRequestMs),\n\t\t\tmaxTransferChunkBytes: Math.min(clientLimits.maxTransferChunkBytes, serverLimits.maxTransferChunkBytes),\n\t\t\tmaxPendingTransferBytes: Math.min(clientLimits.maxPendingTransferBytes, serverLimits.maxPendingTransferBytes),\n\t\t\tmaxPendingInboundBytes: Math.min(clientLimits.maxPendingInboundBytes, serverLimits.maxPendingInboundBytes),\n\t\t\tmaxPendingInboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingInboundMessages,\n\t\t\t\tserverLimits.maxPendingInboundMessages,\n\t\t\t),\n\t\t\tmaxPendingOutboundBytes: Math.min(clientLimits.maxPendingOutboundBytes, serverLimits.maxPendingOutboundBytes),\n\t\t\tmaxPendingOutboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingOutboundMessages,\n\t\t\t\tserverLimits.maxPendingOutboundMessages,\n\t\t\t),\n\t\t\tmaxTransferBytes: Math.min(clientLimits.maxTransferBytes, serverLimits.maxTransferBytes),\n\t\t\tmaxTransferChunks: Math.min(clientLimits.maxTransferChunks, serverLimits.maxTransferChunks),\n\t\t\tmaxActiveRequests: Math.min(clientLimits.maxActiveRequests, serverLimits.maxActiveRequests),\n\t\t\tmaxActiveTransfers: Math.min(clientLimits.maxActiveTransfers, serverLimits.maxActiveTransfers),\n\t\t\tmaxCancellationMs: Math.min(clientLimits.maxCancellationMs, serverLimits.maxCancellationMs),\n\t\t\tmaxTransportSendMs: Math.min(clientLimits.maxTransportSendMs, serverLimits.maxTransportSendMs),\n\t\t},\n\t};\n}\n\nexport function getRemoteWorkspaceMethodKind(method: RemoteWorkspaceMethod): RemoteWorkspaceOperationKind {\n\tswitch (method) {\n\t\tcase \"workspace.write\":\n\t\tcase \"workspace.mkdir\":\n\t\tcase \"transfer.upload\":\n\t\t\treturn \"mutation\";\n\t\tcase \"workspace.exec\":\n\t\t\treturn \"process\";\n\t\tcase \"tool.invoke\":\n\t\t\treturn \"service\";\n\t\tdefault:\n\t\t\treturn \"read\";\n\t}\n}\n"]}
@@ -40,6 +40,7 @@ export const REMOTE_WORKSPACE_ERROR_CODES = [
40
40
  "limit_exceeded",
41
41
  "deadline_exceeded",
42
42
  "cancelled",
43
+ "conflict",
43
44
  "generation_retired",
44
45
  "connection_draining",
45
46
  "result_too_large",
@@ -205,6 +206,7 @@ export const RemoteWorkspaceProtocolErrorSchema = Type.Object({
205
206
  Type.Literal("limit_exceeded"),
206
207
  Type.Literal("deadline_exceeded"),
207
208
  Type.Literal("cancelled"),
209
+ Type.Literal("conflict"),
208
210
  Type.Literal("generation_retired"),
209
211
  Type.Literal("connection_draining"),
210
212
  Type.Literal("result_too_large"),
@@ -267,6 +269,12 @@ const SessionEnvironmentSchema = Type.Object({
267
269
  GRIP_MODEL: Type.Optional(Type.String({ maxLength: 32_768 })),
268
270
  GRIP_REASONING_LEVEL: Type.Optional(Type.String({ maxLength: 32_768 })),
269
271
  }, closedObject);
272
+ /** Shared v2 mutations require an observed digest/absence, or an explicitly unsafe write. */
273
+ const ExpectedRevisionSchema = Type.Union([
274
+ Type.Object({ sha256: HashSchema }, closedObject),
275
+ Type.Object({ absent: Type.Literal(true) }, closedObject),
276
+ Type.Object({ unsafeOverwrite: Type.Literal(true) }, closedObject),
277
+ ]);
270
278
  const ToolInvokeParamsSchema = Type.Object({
271
279
  generation: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),
272
280
  catalogHash: HashSchema,
@@ -274,6 +282,7 @@ const ToolInvokeParamsSchema = Type.Object({
274
282
  schemaHash: HashSchema,
275
283
  argumentsPrepared: Type.Literal(true),
276
284
  arguments: Type.Unknown(),
285
+ expectedRevision: Type.Optional(ExpectedRevisionSchema),
277
286
  executionOptions: Type.Object({
278
287
  imageAutoResize: Type.Optional(Type.Boolean()),
279
288
  shellCommandPrefix: Type.Optional(Type.String({ maxLength: 32_768 })),
@@ -287,6 +296,7 @@ const AccessParamsSchema = Type.Object({
287
296
  const WriteParamsSchema = Type.Object({
288
297
  path: Type.String({ minLength: 1, maxLength: 32_768 }),
289
298
  contentBase64: Type.String(),
299
+ expectedRevision: Type.Optional(ExpectedRevisionSchema),
290
300
  }, closedObject);
291
301
  const MkdirParamsSchema = Type.Object({
292
302
  path: Type.String({ minLength: 1, maxLength: 32_768 }),
@@ -365,9 +375,15 @@ const LspStatusResultSchema = Type.Object({ enabled: Type.Boolean(), servers: Ty
365
375
  const ReadResultSchema = Type.Object({
366
376
  contentBase64: Type.String(),
367
377
  workspace: RemoteWorkspaceIdentitySchema,
378
+ revision: Type.Optional(HashSchema),
368
379
  }, closedObject);
369
380
  const StatResultSchema = Type.Object({
370
- kind: Type.Union([Type.Literal("file"), Type.Literal("directory"), Type.Literal("other")]),
381
+ kind: Type.Union([
382
+ Type.Literal("file"),
383
+ Type.Literal("directory"),
384
+ Type.Literal("other"),
385
+ Type.Literal("absent"),
386
+ ]),
371
387
  workspace: RemoteWorkspaceIdentitySchema,
372
388
  }, closedObject);
373
389
  const ReaddirResultSchema = Type.Object({