@halonicjs/testing 0.1.0 → 0.1.2

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 (228) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  4. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  5. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  6. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  7. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  8. package/dist/adapters/http-kit/src/index.js +2 -0
  9. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  10. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  11. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  13. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  15. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  16. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  17. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  18. package/dist/adapters/integration-kit/src/host.js +1 -0
  19. package/dist/adapters/integration-kit/src/index.d.ts +5 -2
  20. package/dist/adapters/integration-kit/src/index.js +2 -0
  21. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  22. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  23. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  24. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  25. package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
  26. package/dist/adapters/integration-kit/src/loader.js +36 -21
  27. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  28. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  29. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  30. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  31. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  32. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  33. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  34. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  35. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  36. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  37. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  38. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  39. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  40. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  41. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  42. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  43. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  44. package/dist/core/events/src/blocked-sites.js +89 -0
  45. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  46. package/dist/core/events/src/connector-listing-failed.js +1 -0
  47. package/dist/core/events/src/home-path.d.ts +4 -1
  48. package/dist/core/events/src/home-path.js +14 -3
  49. package/dist/core/events/src/index.d.ts +8 -2
  50. package/dist/core/events/src/index.js +5 -0
  51. package/dist/core/events/src/provider-notes.d.ts +16 -0
  52. package/dist/core/events/src/provider-notes.js +24 -0
  53. package/dist/core/events/src/run-basics.d.ts +131 -10
  54. package/dist/core/events/src/run-event.d.ts +120 -11
  55. package/dist/core/events/src/run-reads.d.ts +25 -0
  56. package/dist/core/events/src/run-reads.js +44 -0
  57. package/dist/core/events/src/run-sends.d.ts +47 -0
  58. package/dist/core/events/src/run-sends.js +68 -0
  59. package/dist/core/events/src/run-summary.d.ts +11 -1
  60. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  61. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  62. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  63. package/dist/core/events/src/sandbox-opened.js +13 -3
  64. package/dist/core/events/src/summarize.js +8 -1
  65. package/dist/core/events/src/timeline-entry.js +1 -0
  66. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  67. package/dist/core/events/src/tool-failure-cause.js +66 -0
  68. package/dist/core/format/src/index.d.ts +9 -6
  69. package/dist/core/format/src/index.js +7 -3
  70. package/dist/core/format/src/integration/index.d.ts +3 -2
  71. package/dist/core/format/src/integration/index.js +2 -1
  72. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  73. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  74. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  75. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  76. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  77. package/dist/core/format/src/kinds/agent/schema.js +5 -2
  78. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  79. package/dist/core/format/src/kinds/connector/kind.js +122 -2
  80. package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
  81. package/dist/core/format/src/kinds/connector/schema.js +71 -2
  82. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  83. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  84. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  85. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  86. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  87. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  88. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  89. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  90. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  91. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  92. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  93. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  94. package/dist/core/format/src/kinds/integration/schema.js +133 -7
  95. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
  96. package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
  97. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  98. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  99. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  100. package/dist/core/format/src/kinds/plugin/checks.js +24 -6
  101. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  102. package/dist/core/format/src/kinds/plugin/schema.js +26 -6
  103. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  104. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  105. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  106. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  107. package/dist/core/format/src/kinds/provider/types.js +22 -0
  108. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  109. package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
  110. package/dist/core/format/src/kinds/routine/schema.js +42 -14
  111. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  112. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  113. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  114. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  115. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  116. package/dist/core/format/src/kinds/workspace/schema.js +6 -5
  117. package/dist/core/format/src/parse-file.js +3 -1
  118. package/dist/core/format/src/shared/fields.d.ts +12 -8
  119. package/dist/core/format/src/shared/fields.js +48 -19
  120. package/dist/core/format/src/shared/guard.d.ts +8 -0
  121. package/dist/core/format/src/shared/guard.js +50 -1
  122. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  123. package/dist/core/format/src/shared/missing-keys.js +110 -0
  124. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  125. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  126. package/dist/core/ports/src/blob-store.d.ts +12 -0
  127. package/dist/core/ports/src/blob-store.js +22 -0
  128. package/dist/core/ports/src/chat.d.ts +8 -0
  129. package/dist/core/ports/src/connector-client.d.ts +48 -4
  130. package/dist/core/ports/src/connector-client.js +17 -0
  131. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  132. package/dist/core/ports/src/connector-start-failure.js +32 -0
  133. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  134. package/dist/core/ports/src/connector-tool-error.js +40 -0
  135. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  136. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  137. package/dist/core/ports/src/definition-store.d.ts +36 -5
  138. package/dist/core/ports/src/definition-store.js +1 -1
  139. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  140. package/dist/core/ports/src/deploy-target.js +2 -0
  141. package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
  142. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  143. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  144. package/dist/core/ports/src/harness.d.ts +79 -15
  145. package/dist/core/ports/src/harness.js +1 -1
  146. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  147. package/dist/core/ports/src/host-settings-store.js +106 -0
  148. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  149. package/dist/core/ports/src/host-too-old.js +27 -0
  150. package/dist/core/ports/src/index.d.ts +32 -13
  151. package/dist/core/ports/src/index.js +28 -8
  152. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  153. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  154. package/dist/core/ports/src/integration.d.ts +71 -7
  155. package/dist/core/ports/src/integration.js +22 -4
  156. package/dist/core/ports/src/llm-provider.d.ts +39 -6
  157. package/dist/core/ports/src/llm-provider.js +46 -3
  158. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  159. package/dist/core/ports/src/pairing-codes.js +336 -0
  160. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  161. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  162. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  163. package/dist/core/ports/src/port-versions.d.ts +13 -6
  164. package/dist/core/ports/src/port-versions.js +14 -0
  165. package/dist/core/ports/src/program-probe.d.ts +25 -2
  166. package/dist/core/ports/src/program-probe.js +1 -1
  167. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  168. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  169. package/dist/core/ports/src/record-store.d.ts +17 -0
  170. package/dist/core/ports/src/record-store.js +70 -0
  171. package/dist/core/ports/src/remote-control.d.ts +159 -0
  172. package/dist/core/ports/src/remote-control.js +26 -0
  173. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  174. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  175. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  176. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  177. package/dist/core/ports/src/run-executor.d.ts +44 -7
  178. package/dist/core/ports/src/run-executor.js +1 -1
  179. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  180. package/dist/core/ports/src/run-target-not-found.js +41 -0
  181. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  182. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  183. package/dist/core/ports/src/sandbox.d.ts +149 -13
  184. package/dist/core/ports/src/sandbox.js +52 -2
  185. package/dist/core/ports/src/secrets.d.ts +105 -1
  186. package/dist/core/ports/src/secrets.js +75 -2
  187. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  188. package/dist/core/ports/src/tool-approval-store.js +59 -0
  189. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  190. package/dist/core/ports/src/tunnel-provider.js +65 -0
  191. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  192. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  193. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  194. package/dist/core/ports/src/vcs-status.js +90 -0
  195. package/dist/core/ports/src/vcs.d.ts +30 -0
  196. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  197. package/dist/core/schema-kit/src/builders.js +5 -0
  198. package/dist/core/std/src/amount.d.ts +13 -0
  199. package/dist/core/std/src/amount.js +22 -0
  200. package/dist/core/std/src/hidden-characters.d.ts +28 -0
  201. package/dist/core/std/src/hidden-characters.js +72 -0
  202. package/dist/core/std/src/index.d.ts +7 -0
  203. package/dist/core/std/src/index.js +7 -0
  204. package/dist/core/std/src/path-overlap.d.ts +22 -0
  205. package/dist/core/std/src/path-overlap.js +57 -0
  206. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  207. package/dist/core/std/src/public-suffixes.generated.js +10428 -0
  208. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  209. package/dist/core/std/src/registrable-domain.js +62 -0
  210. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  211. package/dist/core/std/src/secret-variable-name.js +34 -0
  212. package/dist/core/std/src/site-name.d.ts +35 -0
  213. package/dist/core/std/src/site-name.js +111 -0
  214. package/dist/core/std/src/url-host.d.ts +35 -0
  215. package/dist/core/std/src/url-host.js +170 -0
  216. package/dist/core/std/src/word-diff.d.ts +28 -0
  217. package/dist/core/std/src/word-diff.js +77 -0
  218. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  219. package/dist/core/yaml/src/edit-data.js +62 -3
  220. package/dist/core/yaml/src/edit.d.ts +7 -0
  221. package/dist/core/yaml/src/edit.js +34 -3
  222. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  223. package/dist/core/yaml/src/splice-node.js +10 -0
  224. package/dist/core/yaml/src/splice.js +20 -10
  225. package/dist/testing/integration/src/checks.d.ts +5 -3
  226. package/dist/testing/integration/src/checks.js +31 -3
  227. package/dist/testing/integration/src/load.js +3 -1
  228. package/package.json +9 -2
@@ -10,6 +10,20 @@ export declare const connectorClientVersion = 1;
10
10
  * sending a mail. Approvals use it.
11
11
  */
12
12
  export type ToolRisk = "read" | "write" | "send";
13
+ /**
14
+ * Whether a text passes the name rule of `ports.untrusted-tool-listings`:
15
+ * 1 to 64 ASCII letters, digits, `_` or `-`. The model sends tool names
16
+ * back in calls, so they can't be fenced, and the rule keeps them too short
17
+ * and plain to carry much. A connector file's `tools.read` names pass the
18
+ * same rule, so a look-alike letter or an invisible character can't hide
19
+ * in one; widen both together or neither.
20
+ *
21
+ * @example
22
+ * passesNameRule("search_issues"); // true
23
+ * passesNameRule("search_\u0456ssues"); // false: a Cyrillic "і" in "issues"
24
+ * passesNameRule("notes.lookup"); // false
25
+ */
26
+ export declare function passesNameRule(text: unknown): text is string;
13
27
  /** A tool a connector offers. */
14
28
  export interface ConnectorTool {
15
29
  /** The tool's name, unique within its connector. */
@@ -49,13 +63,20 @@ export interface ConnectorCallOptions {
49
63
  export interface ConnectorClient {
50
64
  /** The connector's id in the workspace. */
51
65
  readonly id: string;
66
+ /**
67
+ * Whether the connector runs on this computer, as `connectorIsLocal` in
68
+ * `@halonicjs/format` says. In a local-only workspace the engine uses only
69
+ * the connectors that set it to `true`.
70
+ */
71
+ readonly local?: boolean;
52
72
  /**
53
73
  * The tools the connector offers now. Connects on the first call.
54
74
  *
55
75
  * For an `http` or `stdio` connector, a server the workspace chose wrote
56
76
  * these tools. The host rebuilds their parameters from an allow-list,
57
77
  * fences off their descriptions and results as untrusted text, treats
58
- * their `risk` as `write` unless the workspace sets a lower one, and
78
+ * their `risk` as `write`, or `send` when they say so, unless the
79
+ * workspace sets a lower one for a `write` tool, and
59
80
  * refuses tools that are too large or whose names it can't check
60
81
  * (requirement `ports.untrusted-tool-listings`).
61
82
  * Don't fence them here, and don't mark them trusted.
@@ -122,7 +143,19 @@ export type ConnectorTransport = {
122
143
  command: string;
123
144
  args: string[];
124
145
  env: Record<string, string>;
146
+ /**
147
+ * Variables the program takes from the app's own environment by name,
148
+ * on top of the base every program gets (`app.connector-base-env`).
149
+ * Never a secret's name: the format refuses one (`format.connector-inherit-env`).
150
+ */
151
+ inheritEnv?: string[];
125
152
  cwd?: string;
153
+ /**
154
+ * The only sites the program may reach when it starts in a sandbox,
155
+ * lowercase and in Punycode (`format.connector-sites`). Absent means
156
+ * none. A program that starts without a sandbox isn't held to them.
157
+ */
158
+ sites?: string[];
126
159
  /**
127
160
  * The version to start, for package-runner connectors. The app fills it
128
161
  * from the trust record, **never from workspace YAML**, so a workspace
@@ -154,9 +187,10 @@ export type ConnectorTransport = {
154
187
  * `CURL_CA_BUNDLE`; or a preload, `LD_PRELOAD`, `LD_LIBRARY_PATH`,
155
188
  * `DYLD_INSERT_LIBRARIES` or `DYLD_LIBRARY_PATH`. It drops the
156
189
  * package-manager and language variables it inherits from its own
157
- * process and sets the registry from `registryUrl` itself. It keeps an
158
- * inherited proxy, certificate or preload: those are the person's own
159
- * machine settings, such as a company proxy, not the workspace's.
190
+ * process and sets the registry from `registryUrl` itself. Of what it
191
+ * inherits it keeps only the base (`app.connector-base-env`), which
192
+ * holds a proxy, certificate or library folder: those are the person's
193
+ * own machine settings, such as a company proxy, not the workspace's.
160
194
  *
161
195
  * And it refuses to start when an argument is a runner option that
162
196
  * fetches from somewhere else: `--registry`, an npm scope's
@@ -175,6 +209,16 @@ export type ConnectorTransport = {
175
209
  kind: "google";
176
210
  account: string;
177
211
  client: string;
212
+ }
213
+ /** A local integration in the I5 runner: a folder under `integrations/`. */
214
+ | {
215
+ kind: "integration";
216
+ folder: string;
217
+ }
218
+ /** A plugin's backend in the I5 runner. */
219
+ | {
220
+ kind: "plugin";
221
+ id: string;
178
222
  };
179
223
  /** A connector as the workspace configures it. */
180
224
  export interface ConnectorConfig {
@@ -1,2 +1,19 @@
1
1
  /** Version of the {@link ConnectorClient} and {@link ConnectorFactory} ports. A breaking change bumps it and comes with an ADR. */
2
2
  export const connectorClientVersion = 1;
3
+ const toolNamePattern = /^[A-Za-z0-9_-]{1,64}$/;
4
+ /**
5
+ * Whether a text passes the name rule of `ports.untrusted-tool-listings`:
6
+ * 1 to 64 ASCII letters, digits, `_` or `-`. The model sends tool names
7
+ * back in calls, so they can't be fenced, and the rule keeps them too short
8
+ * and plain to carry much. A connector file's `tools.read` names pass the
9
+ * same rule, so a look-alike letter or an invisible character can't hide
10
+ * in one; widen both together or neither.
11
+ *
12
+ * @example
13
+ * passesNameRule("search_issues"); // true
14
+ * passesNameRule("search_\u0456ssues"); // false: a Cyrillic "і" in "issues"
15
+ * passesNameRule("notes.lookup"); // false
16
+ */
17
+ export function passesNameRule(text) {
18
+ return typeof text === "string" && toolNamePattern.test(text);
19
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Why a connector couldn't start, when it's one the engine can name
3
+ * (requirement `ports.connector-start-failure`): its program isn't on this
4
+ * computer, or a secret it needs isn't set. `program` and `secret` are names
5
+ * as the connector's file writes them, never a secret's value.
6
+ */
7
+ export type ConnectorStartFailure = {
8
+ readonly reason: "program-missing";
9
+ readonly program: string;
10
+ } | {
11
+ readonly reason: "secret-not-set";
12
+ readonly secret: string;
13
+ };
14
+ /**
15
+ * Why `value`, thrown while a connector started, says it couldn't start, or
16
+ * `undefined` for any other error. A connector adapter says it with two
17
+ * errors (as `@halonicjs/adapter-mcp` does):
18
+ *
19
+ * - an `Error` named `ProgramNotFoundError` with the program's name in `program`;
20
+ * - an `Error` named `SecretNotSetError` with the secret's name in `secretName`.
21
+ *
22
+ * It reads them by name and field, not `instanceof`, so the engine needs no
23
+ * adapter, and an adapter with its own copy of this package works too. It
24
+ * keeps only the name, never the error's message, which can hold paths or
25
+ * a program's output.
26
+ *
27
+ * @example
28
+ * connectorStartFailureOf(new SecretNotSetError("notes", "NOTES_TOKEN"));
29
+ * // => { reason: "secret-not-set", secret: "NOTES_TOKEN" }
30
+ */
31
+ export declare function connectorStartFailureOf(value: unknown): ConnectorStartFailure | undefined;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Why `value`, thrown while a connector started, says it couldn't start, or
3
+ * `undefined` for any other error. A connector adapter says it with two
4
+ * errors (as `@halonicjs/adapter-mcp` does):
5
+ *
6
+ * - an `Error` named `ProgramNotFoundError` with the program's name in `program`;
7
+ * - an `Error` named `SecretNotSetError` with the secret's name in `secretName`.
8
+ *
9
+ * It reads them by name and field, not `instanceof`, so the engine needs no
10
+ * adapter, and an adapter with its own copy of this package works too. It
11
+ * keeps only the name, never the error's message, which can hold paths or
12
+ * a program's output.
13
+ *
14
+ * @example
15
+ * connectorStartFailureOf(new SecretNotSetError("notes", "NOTES_TOKEN"));
16
+ * // => { reason: "secret-not-set", secret: "NOTES_TOKEN" }
17
+ */
18
+ export function connectorStartFailureOf(value) {
19
+ if (!(value instanceof Error))
20
+ return undefined;
21
+ const { program, secretName } = value;
22
+ if (value.name === "ProgramNotFoundError" && isName(program)) {
23
+ return { reason: "program-missing", program };
24
+ }
25
+ if (value.name === "SecretNotSetError" && isName(secretName)) {
26
+ return { reason: "secret-not-set", secret: secretName };
27
+ }
28
+ return undefined;
29
+ }
30
+ function isName(value) {
31
+ return typeof value === "string" && value !== "";
32
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A connector's tool that answered, but with an error of its own (MCP's
3
+ * `isError`), such as a file tool that found no file. The server did answer,
4
+ * so the call didn't break off: the engine logs it as a failed call, with the
5
+ * tool's own text, and the agent goes on (requirement
6
+ * `ports.connector-tool-error`). A call that got no answer at all, because
7
+ * the program died, the connection dropped or it ran out of time, throws any
8
+ * other error instead.
9
+ *
10
+ * The message is Halonic's; the tool's own text, which the server wrote, is
11
+ * kept apart in `toolText`, so a reader can fence it as untrusted.
12
+ *
13
+ * Check for it with {@link isConnectorToolError}, not `instanceof`: an
14
+ * adapter may be built against its own copy of this package.
15
+ *
16
+ * @example
17
+ * if (result.isError) throw new ConnectorToolError("handbook-files", "read_text_file", "ENOENT: …");
18
+ */
19
+ export declare class ConnectorToolError extends Error {
20
+ readonly name = "ConnectorToolError";
21
+ /** What the tool said about its failure: the server's text. */
22
+ readonly toolText: string;
23
+ constructor(connectorId: string, toolName: string, toolText: string);
24
+ }
25
+ /**
26
+ * Whether `value` is a {@link ConnectorToolError}: an `Error` named
27
+ * "ConnectorToolError" with a `toolText` string. It works across copies of
28
+ * this package, where `instanceof` doesn't.
29
+ *
30
+ * @example
31
+ * const outcome = isConnectorToolError(error) ? "error" : "unknown";
32
+ */
33
+ export declare function isConnectorToolError(value: unknown): value is ConnectorToolError;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A connector's tool that answered, but with an error of its own (MCP's
3
+ * `isError`), such as a file tool that found no file. The server did answer,
4
+ * so the call didn't break off: the engine logs it as a failed call, with the
5
+ * tool's own text, and the agent goes on (requirement
6
+ * `ports.connector-tool-error`). A call that got no answer at all, because
7
+ * the program died, the connection dropped or it ran out of time, throws any
8
+ * other error instead.
9
+ *
10
+ * The message is Halonic's; the tool's own text, which the server wrote, is
11
+ * kept apart in `toolText`, so a reader can fence it as untrusted.
12
+ *
13
+ * Check for it with {@link isConnectorToolError}, not `instanceof`: an
14
+ * adapter may be built against its own copy of this package.
15
+ *
16
+ * @example
17
+ * if (result.isError) throw new ConnectorToolError("handbook-files", "read_text_file", "ENOENT: …");
18
+ */
19
+ export class ConnectorToolError extends Error {
20
+ name = "ConnectorToolError";
21
+ /** What the tool said about its failure: the server's text. */
22
+ toolText;
23
+ constructor(connectorId, toolName, toolText) {
24
+ super(`Connector "${connectorId}" says its tool "${toolName}" failed.`);
25
+ this.toolText = toolText;
26
+ }
27
+ }
28
+ /**
29
+ * Whether `value` is a {@link ConnectorToolError}: an `Error` named
30
+ * "ConnectorToolError" with a `toolText` string. It works across copies of
31
+ * this package, where `instanceof` doesn't.
32
+ *
33
+ * @example
34
+ * const outcome = isConnectorToolError(error) ? "error" : "unknown";
35
+ */
36
+ export function isConnectorToolError(value) {
37
+ if (!(value instanceof Error) || value.name !== "ConnectorToolError")
38
+ return false;
39
+ return typeof value.toolText === "string";
40
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Folders a caller asks a `DefinitionSource` to leave out of `list()`
3
+ * and `version()` (requirement `ports.definition-store-left-out`): the
4
+ * working folders agents write in and `node_modules`, which can hold tens of
5
+ * thousands of files and no definitions. Loading the workspace asks for it;
6
+ * a caller that copies or compares the workspace doesn't.
7
+ *
8
+ * It is about scale, not privacy: a left-out file still reads, writes and
9
+ * removes as any other. Names compare as {@link segmentAsOpened} gives them,
10
+ * as a file system that ignores case would open them.
11
+ */
12
+ export interface LeaveOut {
13
+ /** Folder paths from the store root, such as `repo` or `files/agents/coder`. Everything under one is left out. */
14
+ readonly folders?: readonly string[];
15
+ /** Folder names left out at any depth, such as `node_modules`. One segment each. */
16
+ readonly names?: readonly string[];
17
+ }
18
+ /** Options for `DefinitionSource.list`. */
19
+ export interface ListOptions {
20
+ /** What to leave out of the listing. Leave it out to list every file, as without options. */
21
+ readonly leaveOut?: LeaveOut;
22
+ }
23
+ /** Options for `DefinitionSource.version`. */
24
+ export interface VersionOptions {
25
+ /** Version only what `list()` gives with the same `leaveOut`. */
26
+ readonly leaveOut?: LeaveOut;
27
+ }
28
+ /**
29
+ * Refuses a {@link LeaveOut} with an unsafe folder path, or a name that isn't
30
+ * a single safe segment, so `a/../b` can't leave out more than it says. Every
31
+ * store calls it before it lists.
32
+ *
33
+ * @throws RangeError naming the folder or name and what is wrong with it
34
+ */
35
+ export declare function checkLeaveOut(leaveOut: LeaveOut | undefined): void;
36
+ /**
37
+ * Whether a safe workspace path is left out: it is one of the folders, or
38
+ * inside one, or one of its segments is one of the names. A store that walks
39
+ * folders can ask it for a folder's own path and not step into it.
40
+ *
41
+ * @example
42
+ * isLeftOut("repo/src/a.ts", { folders: ["repo"] }); // true
43
+ * isLeftOut("repository.md", { folders: ["repo"] }); // false
44
+ * isLeftOut("tools/Node_Modules/x/index.js", { names: ["node_modules"] }); // true
45
+ */
46
+ export declare function isLeftOut(path: string, leaveOut: LeaveOut | undefined): boolean;
@@ -0,0 +1,47 @@
1
+ import { checkWorkspacePath, segmentAsOpened } from "./definition-store.js";
2
+ /**
3
+ * Refuses a {@link LeaveOut} with an unsafe folder path, or a name that isn't
4
+ * a single safe segment, so `a/../b` can't leave out more than it says. Every
5
+ * store calls it before it lists.
6
+ *
7
+ * @throws RangeError naming the folder or name and what is wrong with it
8
+ */
9
+ export function checkLeaveOut(leaveOut) {
10
+ for (const folder of leaveOut?.folders ?? []) {
11
+ checkWorkspacePath(folder);
12
+ }
13
+ for (const name of leaveOut?.names ?? []) {
14
+ checkWorkspacePath(name);
15
+ if (name.includes("/")) {
16
+ throw new RangeError(`Unsafe folder name ${JSON.stringify(name)}: no "/".`);
17
+ }
18
+ }
19
+ }
20
+ /**
21
+ * Whether a safe workspace path is left out: it is one of the folders, or
22
+ * inside one, or one of its segments is one of the names. A store that walks
23
+ * folders can ask it for a folder's own path and not step into it.
24
+ *
25
+ * @example
26
+ * isLeftOut("repo/src/a.ts", { folders: ["repo"] }); // true
27
+ * isLeftOut("repository.md", { folders: ["repo"] }); // false
28
+ * isLeftOut("tools/Node_Modules/x/index.js", { names: ["node_modules"] }); // true
29
+ */
30
+ export function isLeftOut(path, leaveOut) {
31
+ if (leaveOut === undefined) {
32
+ return false;
33
+ }
34
+ const segments = path.split("/").map(segmentAsOpened);
35
+ const names = new Set((leaveOut.names ?? []).map(segmentAsOpened));
36
+ if (segments.some((segment) => names.has(segment))) {
37
+ return true;
38
+ }
39
+ return (leaveOut.folders ?? []).some((folder) => startsWithFolder(segments, folder));
40
+ }
41
+ function startsWithFolder(segments, folder) {
42
+ const folderSegments = folder.split("/").map(segmentAsOpened);
43
+ if (folderSegments.length > segments.length) {
44
+ return false;
45
+ }
46
+ return folderSegments.every((segment, index) => segments[index] === segment);
47
+ }
@@ -1,5 +1,6 @@
1
+ import type { ListOptions, VersionOptions } from "./definition-store-left-out.js";
1
2
  /** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
2
- export declare const definitionStoreVersion = 2;
3
+ export declare const definitionStoreVersion = 3;
3
4
  /**
4
5
  * Read access to the workspace files (agents, workflows, hubs …), wherever
5
6
  * they live: a folder, git, memory or a deployed snapshot. Paths are
@@ -45,15 +46,24 @@ export interface DefinitionSource {
45
46
  * gives `[]`. A folder under the root that the account may not read
46
47
  * throws an `UnreadableWorkspaceFolderError` naming it, rather than being
47
48
  * left out.
49
+ *
50
+ * With `options.leaveOut`, it also leaves out the folders and folder
51
+ * names it gives (see `LeaveOut`), and a store that walks folders doesn't
52
+ * step into them. It refuses an unsafe folder or name with a `RangeError`.
48
53
  */
49
- list(dir?: string): Promise<string[]>;
54
+ list(dir?: string, options?: ListOptions): Promise<string[]>;
50
55
  /** The file's text, or `null` when there is no such file. */
51
56
  read(path: string): Promise<string | null>;
52
57
  /**
53
58
  * Identifier of the current version of the definitions (git commit, content
54
59
  * hash). Runs record it so they can be explained and replayed later.
60
+ *
61
+ * With `options.leaveOut`, it covers only what `list()` gives with the
62
+ * same options, so a change to a left-out file alone doesn't change it. A
63
+ * store whose version names a whole snapshot (a commit) keeps naming it:
64
+ * any change makes a new snapshot.
55
65
  */
56
- version(): Promise<string>;
66
+ version(options?: VersionOptions): Promise<string>;
57
67
  }
58
68
  /**
59
69
  * What a caller expects a file to hold before it writes: the digest of the
@@ -87,6 +97,22 @@ export type WriteResult = {
87
97
  readonly status: "changed-on-disk";
88
98
  readonly current: string | null;
89
99
  };
100
+ /** Options for {@link DefinitionStore.remove}. */
101
+ export interface RemoveOptions {
102
+ /** Remove only if the file still holds this. Leave it out to remove the file whatever it holds. */
103
+ readonly expected?: ExpectedContent;
104
+ }
105
+ /**
106
+ * What {@link DefinitionStore.remove} did. `changed-on-disk` means the file
107
+ * no longer held what the caller expected, so nothing was removed; `current`
108
+ * is its text now, or `null` when it is gone.
109
+ */
110
+ export type RemoveResult = {
111
+ readonly status: "removed";
112
+ } | {
113
+ readonly status: "changed-on-disk";
114
+ readonly current: string | null;
115
+ };
90
116
  /**
91
117
  * One workspace file that changed outside Halonic. `removed` means it is gone
92
118
  * at the end of the batch; a file removed and created again, as many editors
@@ -120,8 +146,13 @@ export interface DefinitionStore extends DefinitionSource {
120
146
  * read and, if not, writes nothing and returns `changed-on-disk`.
121
147
  */
122
148
  write(path: string, content: string, options?: WriteOptions): Promise<WriteResult>;
123
- /** Deletes a file. Deleting a file that isn't there is not an error. */
124
- remove(path: string): Promise<void>;
149
+ /**
150
+ * Deletes a file. Deleting a file that isn't there is not an error. With
151
+ * `expected`, it first checks the file still holds what the caller last
152
+ * read and, if not, removes nothing and returns `changed-on-disk`, so an
153
+ * edit made since is not deleted.
154
+ */
155
+ remove(path: string, options?: RemoveOptions): Promise<RemoveResult>;
125
156
  /**
126
157
  * Reports the files that change from outside Halonic (save model 6):
127
158
  * another editor, a sync tool, `git pull`. A change is one whose text
@@ -1,5 +1,5 @@
1
1
  /** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
2
- export const definitionStoreVersion = 2;
2
+ export const definitionStoreVersion = 3;
3
3
  /**
4
4
  * What a {@link DefinitionSource}'s `list()` throws when the account may not
5
5
  * read a folder under the store's root (requirement