@halonicjs/testing 0.1.1 → 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 (122) hide show
  1. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  2. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  3. package/dist/adapters/http-kit/src/index.d.ts +2 -0
  4. package/dist/adapters/http-kit/src/index.js +2 -0
  5. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  6. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  7. package/dist/adapters/integration-kit/src/index.d.ts +2 -1
  8. package/dist/adapters/integration-kit/src/index.js +1 -0
  9. package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
  10. package/dist/adapters/integration-kit/src/loader.js +3 -20
  11. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  12. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  13. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  14. package/dist/core/events/src/connector-listing-failed.js +1 -0
  15. package/dist/core/events/src/home-path.d.ts +4 -1
  16. package/dist/core/events/src/home-path.js +14 -3
  17. package/dist/core/events/src/index.d.ts +4 -2
  18. package/dist/core/events/src/index.js +2 -0
  19. package/dist/core/events/src/provider-notes.d.ts +16 -0
  20. package/dist/core/events/src/provider-notes.js +24 -0
  21. package/dist/core/events/src/run-basics.d.ts +103 -5
  22. package/dist/core/events/src/run-event.d.ts +72 -7
  23. package/dist/core/events/src/run-summary.d.ts +11 -1
  24. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  25. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  26. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  27. package/dist/core/events/src/sandbox-opened.js +13 -3
  28. package/dist/core/events/src/summarize.js +3 -0
  29. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  30. package/dist/core/events/src/tool-failure-cause.js +66 -0
  31. package/dist/core/format/src/index.d.ts +3 -2
  32. package/dist/core/format/src/index.js +3 -1
  33. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  34. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  35. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  36. package/dist/core/format/src/kinds/agent/schema.js +3 -0
  37. package/dist/core/format/src/kinds/connector/kind.js +24 -3
  38. package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
  39. package/dist/core/format/src/kinds/connector/schema.js +18 -0
  40. package/dist/core/format/src/kinds/integration/schema.js +1 -1
  41. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
  42. package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
  43. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  44. package/dist/core/format/src/kinds/plugin/checks.js +17 -5
  45. package/dist/core/format/src/kinds/plugin/schema.js +24 -4
  46. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  47. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  48. package/dist/core/format/src/kinds/provider/types.js +22 -0
  49. package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
  50. package/dist/core/format/src/kinds/routine/schema.js +21 -15
  51. package/dist/core/format/src/kinds/workspace/schema.js +5 -4
  52. package/dist/core/format/src/parse-file.js +3 -1
  53. package/dist/core/format/src/shared/fields.d.ts +9 -2
  54. package/dist/core/format/src/shared/fields.js +15 -6
  55. package/dist/core/format/src/shared/guard.d.ts +8 -0
  56. package/dist/core/format/src/shared/guard.js +50 -1
  57. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  58. package/dist/core/format/src/shared/missing-keys.js +110 -0
  59. package/dist/core/ports/src/chat.d.ts +8 -0
  60. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  61. package/dist/core/ports/src/connector-start-failure.js +32 -0
  62. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  63. package/dist/core/ports/src/connector-tool-error.js +40 -0
  64. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  65. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  66. package/dist/core/ports/src/definition-store.d.ts +13 -3
  67. package/dist/core/ports/src/definition-store.js +1 -1
  68. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  69. package/dist/core/ports/src/deploy-target.js +2 -0
  70. package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
  71. package/dist/core/ports/src/harness.d.ts +33 -2
  72. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  73. package/dist/core/ports/src/host-too-old.js +27 -0
  74. package/dist/core/ports/src/index.d.ts +16 -5
  75. package/dist/core/ports/src/index.js +15 -3
  76. package/dist/core/ports/src/llm-provider.d.ts +37 -6
  77. package/dist/core/ports/src/llm-provider.js +43 -3
  78. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  79. package/dist/core/ports/src/pairing-codes.js +336 -0
  80. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  81. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  82. package/dist/core/ports/src/port-versions.d.ts +6 -2
  83. package/dist/core/ports/src/port-versions.js +8 -0
  84. package/dist/core/ports/src/remote-control.d.ts +159 -0
  85. package/dist/core/ports/src/remote-control.js +26 -0
  86. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  87. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  88. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  89. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  90. package/dist/core/ports/src/run-executor.d.ts +39 -3
  91. package/dist/core/ports/src/run-executor.js +1 -1
  92. package/dist/core/ports/src/sandbox.d.ts +19 -0
  93. package/dist/core/ports/src/sandbox.js +14 -0
  94. package/dist/core/ports/src/secrets.d.ts +32 -1
  95. package/dist/core/ports/src/secrets.js +19 -2
  96. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  97. package/dist/core/ports/src/tunnel-provider.js +65 -0
  98. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  99. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  100. package/dist/core/ports/src/vcs.d.ts +30 -0
  101. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  102. package/dist/core/schema-kit/src/builders.js +5 -0
  103. package/dist/core/std/src/hidden-characters.d.ts +9 -0
  104. package/dist/core/std/src/hidden-characters.js +18 -0
  105. package/dist/core/std/src/index.d.ts +3 -1
  106. package/dist/core/std/src/index.js +3 -1
  107. package/dist/core/std/src/path-overlap.d.ts +22 -0
  108. package/dist/core/std/src/path-overlap.js +57 -0
  109. package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
  110. package/dist/core/std/src/public-suffixes.generated.js +0 -1
  111. package/dist/core/std/src/word-diff.d.ts +28 -0
  112. package/dist/core/std/src/word-diff.js +77 -0
  113. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  114. package/dist/core/yaml/src/edit-data.js +62 -3
  115. package/dist/core/yaml/src/edit.d.ts +7 -0
  116. package/dist/core/yaml/src/edit.js +34 -3
  117. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  118. package/dist/core/yaml/src/splice-node.js +10 -0
  119. package/dist/core/yaml/src/splice.js +20 -10
  120. package/dist/testing/integration/src/checks.d.ts +5 -3
  121. package/dist/testing/integration/src/checks.js +31 -3
  122. package/package.json +9 -2
@@ -1,4 +1,4 @@
1
- import { passesNameRule } from "../../../../ports/src/index.js";
1
+ import { isHalonicSecretName, isPluginSecretName, passesNameRule } from "../../../../ports/src/index.js";
2
2
  import { isSecretVariableName } from "../../../../std/src/index.js";
3
3
  import { checkKeysIn } from "../../shared/key-in-value.js";
4
4
  import { checkSecretName, looksLikeKey } from "../../shared/secret-name.js";
@@ -39,9 +39,30 @@ function secretNames(connector) {
39
39
  }
40
40
  return names;
41
41
  }
42
- /** The secrets are named in the file, so a bad name or a pasted key is caught here, not at run time. */
42
+ /*
43
+ * The words are the team's, next to `secret-name.ts`: a small wording on a
44
+ * check the board already approved (HAL-11237).
45
+ */
46
+ const reservedNameMessage = "This secret name belongs to Halonic or to a plugin, so a connector can't use it. Store the value under a name of your own, such as my-service-key.";
47
+ /**
48
+ * The secrets are named in the file, so a bad name or a pasted key is caught
49
+ * here, not at run time. A name that belongs to Halonic (`token-key`,
50
+ * `serve-password`) or to a plugin is refused too: the file is the
51
+ * workspace's, and what it names reaches a program or a server.
52
+ */
43
53
  function checkSecretNames(connector) {
44
- return secretNames(connector).flatMap(([name, path]) => checkSecretName(name, path) ?? []);
54
+ return secretNames(connector).flatMap(([name, path]) => {
55
+ const problem = checkSecretName(name, path);
56
+ if (problem !== undefined) {
57
+ return [problem];
58
+ }
59
+ if (isHalonicSecretName(name) || isPluginSecretName(name)) {
60
+ return [
61
+ { severity: "error", code: "secret-name-reserved", path, message: reservedNameMessage },
62
+ ];
63
+ }
64
+ return [];
65
+ });
45
66
  }
46
67
  /**
47
68
  * A Google connector's `client` and `secret` name no secret. The account's
@@ -72,3 +72,17 @@ export declare function needsApproval(tools: Pick<Connector["tools"], "approve">
72
72
  * marksRead({ approve: [] }, "search_issues"); // false
73
73
  */
74
74
  export declare function marksRead(tools: Pick<Connector["tools"], "approve" | "read">, tool: string): boolean;
75
+ /**
76
+ * Whether every call to `tool` waits for a person: the rule the engine
77
+ * counts a listed tool's risk by, so `halonic tools review` and Studio say
78
+ * what a run then does. A tool runs without asking only when the workspace
79
+ * marks it as only reading ({@link marksRead}) and its listing doesn't say
80
+ * `send`: a server can raise its tool's risk, and the `read` list can't lower
81
+ * `send`. `listedRisk` is the risk its listing gives, absent when it gives none.
82
+ *
83
+ * @example
84
+ * asksBeforeEachUse({ approve: [] }, "lookup"); // true
85
+ * asksBeforeEachUse({ approve: [], read: ["lookup"] }, "lookup"); // false
86
+ * asksBeforeEachUse({ approve: [], read: ["mail"] }, "mail", "send"); // true
87
+ */
88
+ export declare function asksBeforeEachUse(tools: Pick<Connector["tools"], "approve" | "read">, tool: string, listedRisk?: "read" | "write" | "send"): boolean;
@@ -141,3 +141,21 @@ export function needsApproval(tools, tool) {
141
141
  export function marksRead(tools, tool) {
142
142
  return (tools.read?.includes(tool) ?? false) && !needsApproval(tools, tool);
143
143
  }
144
+ /**
145
+ * Whether every call to `tool` waits for a person: the rule the engine
146
+ * counts a listed tool's risk by, so `halonic tools review` and Studio say
147
+ * what a run then does. A tool runs without asking only when the workspace
148
+ * marks it as only reading ({@link marksRead}) and its listing doesn't say
149
+ * `send`: a server can raise its tool's risk, and the `read` list can't lower
150
+ * `send`. `listedRisk` is the risk its listing gives, absent when it gives none.
151
+ *
152
+ * @example
153
+ * asksBeforeEachUse({ approve: [] }, "lookup"); // true
154
+ * asksBeforeEachUse({ approve: [], read: ["lookup"] }, "lookup"); // false
155
+ * asksBeforeEachUse({ approve: [], read: ["mail"] }, "mail", "send"); // true
156
+ */
157
+ export function asksBeforeEachUse(tools, tool,
158
+ // Written out rather than ports' `ToolRisk`: the connector entry imports only schema-kit and std.
159
+ listedRisk) {
160
+ return listedRisk === "send" || !marksRead(tools, tool);
161
+ }
@@ -9,7 +9,7 @@ import { s } from "../../../../schema-kit/src/index.js";
9
9
  export const INTEGRATION_NAME_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
10
10
  const name = s
11
11
  .string()
12
- .regex(INTEGRATION_NAME_PATTERN, "use lower-case words joined by '-', such as 'weather-key'");
12
+ .regex(INTEGRATION_NAME_PATTERN, "use lower-case words joined by '-', such as 'weather' or 'weather-key'");
13
13
  /**
14
14
  * A host name in lower case, with at least one dot and a top-level name of
15
15
  * letters, and an optional `:port`. No scheme, no path, no wildcards and no
@@ -4,7 +4,8 @@ import { type IntegrationSheet } from "./schema.js";
4
4
  * The rules over a sheet's `signIns` and their client secrets: the sheet
5
5
  * says `kit: 2`; the access token goes only to hosts the sheet declares; a
6
6
  * `{ fromSetting }` URL reads a public host the sheet declares; Halonic's own
7
- * authorize parameters stay Halonic's; and a client secret has no hosts of
7
+ * authorize parameters stay Halonic's; a `revokeUrl` is on the host of the
8
+ * sign-in's `tokenUrl` or `authorizeUrl`; and a client secret has no hosts of
8
9
  * its own and belongs to exactly one sign-in.
9
10
  *
10
11
  * @example
@@ -1,5 +1,5 @@
1
1
  import { hostKey } from "./host-key.js";
2
- import { isPlacedSecret } from "./schema.js";
2
+ import { isPlacedSecret, } from "./schema.js";
3
3
  import { fixedSignInUrl, queryParameterNames, RESERVED_AUTHORIZE_PARAMETERS, } from "./sign-in-urls.js";
4
4
  /** The first `kit` that has `signIns`. */
5
5
  const SIGN_IN_KIT = 2;
@@ -14,7 +14,8 @@ const URL_FIELDS = [
14
14
  * The rules over a sheet's `signIns` and their client secrets: the sheet
15
15
  * says `kit: 2`; the access token goes only to hosts the sheet declares; a
16
16
  * `{ fromSetting }` URL reads a public host the sheet declares; Halonic's own
17
- * authorize parameters stay Halonic's; and a client secret has no hosts of
17
+ * authorize parameters stay Halonic's; a `revokeUrl` is on the host of the
18
+ * sign-in's `tokenUrl` or `authorizeUrl`; and a client secret has no hosts of
18
19
  * its own and belongs to exactly one sign-in.
19
20
  *
20
21
  * @example
@@ -24,7 +25,7 @@ export function checkSignIns(sheet) {
24
25
  const entries = Object.entries(sheet.signIns);
25
26
  const problems = [...kitProblems(sheet, entries.length)];
26
27
  for (const [name, signIn] of entries) {
27
- problems.push(...accessHostProblems(sheet, name, signIn), ...urlProblems(sheet, name, signIn));
28
+ problems.push(...accessHostProblems(sheet, name, signIn), ...urlProblems(sheet, name, signIn), ...revokeHostProblems(sheet, name, signIn));
28
29
  }
29
30
  problems.push(...clientSecretProblems(sheet));
30
31
  return problems;
@@ -73,6 +74,35 @@ function urlProblems(sheet, name, signIn) {
73
74
  }
74
75
  return problems;
75
76
  }
77
+ /**
78
+ * A `revokeUrl` is on the host of the sign-in's `tokenUrl` or `authorizeUrl`.
79
+ * Sign-out sends it the refresh token, and the client secret too, so a third
80
+ * host would get them without the person having seen it in the trust check.
81
+ */
82
+ function revokeHostProblems(sheet, name, signIn) {
83
+ if (signIn.revokeUrl === undefined) {
84
+ return [];
85
+ }
86
+ const revokeHost = endpointHost(signIn.revokeUrl);
87
+ if ([signIn.tokenUrl, signIn.authorizeUrl].some((url) => endpointHost(url) === revokeHost)) {
88
+ return [];
89
+ }
90
+ return [
91
+ problemAt(sheet, "sign-in-revoke-host", ["signIns", name, "revokeUrl"], `the revokeUrl of "${name}" must be on the host of its tokenUrl or authorizeUrl`),
92
+ ];
93
+ }
94
+ /**
95
+ * Where a sign-in URL goes, as one text to compare: its host in lower case
96
+ * and without the default port, or the setting it reads.
97
+ */
98
+ function endpointHost(url) {
99
+ const fixed = fixedSignInUrl(url);
100
+ if (fixed === undefined) {
101
+ return typeof url === "string" ? url : `fromSetting ${url.fromSetting}`;
102
+ }
103
+ const host = fixed.host.toLowerCase();
104
+ return host.endsWith(":443") ? host.slice(0, -4) : host;
105
+ }
76
106
  /**
77
107
  * A client secret is declared without `hosts` and `as`, named by exactly one
78
108
  * sign-in, and every such secret is named by one.
@@ -4,8 +4,9 @@ import { type Plugin } from "./schema.js";
4
4
  * The rules over several fields of a plugin: it has a backend or local
5
5
  * tools, its id and secret names aren't too long, its backend passes the
6
6
  * integration sheet's checks and starts no program, no id is used twice, no tool or secret name is in two parts, a
7
- * local tool's environment names its own secrets and the plugin's settings,
8
- * and its `ui` names what the plugin declares.
7
+ * local tool's environment names its own secrets and the plugin's settings
8
+ * and sets none of the variables Halonic sets itself, and its `ui` names
9
+ * what the plugin declares.
9
10
  *
10
11
  * @example
11
12
  * checkPlugin(plugin); // [] for the weather plugin in the ADR
@@ -7,8 +7,9 @@ import { uiProblems } from "./ui-checks.js";
7
7
  * The rules over several fields of a plugin: it has a backend or local
8
8
  * tools, its id and secret names aren't too long, its backend passes the
9
9
  * integration sheet's checks and starts no program, no id is used twice, no tool or secret name is in two parts, a
10
- * local tool's environment names its own secrets and the plugin's settings,
11
- * and its `ui` names what the plugin declares.
10
+ * local tool's environment names its own secrets and the plugin's settings
11
+ * and sets none of the variables Halonic sets itself, and its `ui` names
12
+ * what the plugin declares.
12
13
  *
13
14
  * @example
14
15
  * checkPlugin(plugin); // [] for the weather plugin in the ADR
@@ -87,15 +88,26 @@ function localToolProblems(plugin) {
87
88
  return problems;
88
89
  }
89
90
  /**
90
- * An `env` value names one of this local tool's own secrets, never another
91
- * part's, so a secret reaches only the program it was declared for. A
92
- * setting it names exists and isn't a `secret` field: secrets go by `secret`.
91
+ * The variables Halonic sets itself for every local tool: its `PATH`, and
92
+ * its home and temp folders inside the session.
93
+ */
94
+ const halonicVariables = new Set(["HOME", "PATH", "TMPDIR", "TEMP", "TMP"]);
95
+ /**
96
+ * An `env` variable isn't one Halonic sets itself. Its value names one of
97
+ * this local tool's own secrets, never another part's, so a secret reaches
98
+ * only the program it was declared for. A setting it names exists and isn't
99
+ * a `secret` field: secrets go by `secret`.
93
100
  */
94
101
  function envProblems(plugin, localTool, index) {
95
102
  const settings = plugin.ui?.settings ?? {};
96
103
  const problems = [];
97
104
  for (const [variable, value] of Object.entries(localTool.env)) {
98
105
  const path = ["localTools", index, "env", variable];
106
+ if (halonicVariables.has(variable)) {
107
+ const message = `${variable} is set by Halonic for every local tool; use another name`;
108
+ problems.push(problem(plugin, "env-reserved", path, message));
109
+ continue;
110
+ }
99
111
  if ("secret" in value) {
100
112
  if (!Object.hasOwn(localTool.secrets, value.secret)) {
101
113
  const message = `${variable} takes the secret ${value.secret}, which local tool "${localTool.id}" doesn't declare in its secrets`;
@@ -18,8 +18,23 @@ export const ARGUMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*$/;
18
18
  const argumentName = s
19
19
  .string()
20
20
  .regex(ARGUMENT_NAME_PATTERN, "use the tool argument's name, such as 'city' or 'folderId'");
21
+ /**
22
+ * A control character, or a mark that turns the direction of the text around it.
23
+ * In text a person reads, either can make one name look like another, in the
24
+ * Plugins list and in the trust dialog. A line break is the one exception, and
25
+ * only in longer text.
26
+ */
27
+ const HIDDEN_MARK = /[\p{Cc}\p{Bidi_Control}]/u;
28
+ const HIDDEN_MARK_BUT_LINE_BREAK = /(?!\n)[\p{Cc}\p{Bidi_Control}]/u;
29
+ const NO_HIDDEN_MARKS = "don't use control characters or text-direction marks";
30
+ /** Whether a description or help text has no hidden mark. It may break lines. */
31
+ const withoutHiddenMarks = (text) => !HIDDEN_MARK_BUT_LINE_BREAK.test(text);
21
32
  /** Text a person reads: a title or a label. Studio shows it as untrusted text. */
22
- const label = s.string().min(1).max(80);
33
+ const label = s
34
+ .string()
35
+ .min(1)
36
+ .max(80)
37
+ .refine((text) => !HIDDEN_MARK.test(text), NO_HIDDEN_MARKS);
23
38
  /**
24
39
  * Why a local tool's `network` entry can't be used, or `null` when it can.
25
40
  * The list is the sandbox's allow-list for code Halonic doesn't trust, so it
@@ -179,7 +194,7 @@ const LocalTool = s
179
194
  /** What every field says, whatever its type. */
180
195
  const fieldBase = {
181
196
  label,
182
- help: s.string().min(1).max(500).optional(),
197
+ help: s.string().min(1).max(500).refine(withoutHiddenMarks, NO_HIDDEN_MARKS).optional(),
183
198
  required: s.boolean().default(false),
184
199
  };
185
200
  /** The field types a setting and a command's form share. */
@@ -192,7 +207,12 @@ const inputFields = [
192
207
  .object({
193
208
  ...fieldBase,
194
209
  type: s.literal("choice"),
195
- choices: s.array(s.string().min(1)).min(1),
210
+ choices: s
211
+ .array(s
212
+ .string()
213
+ .min(1)
214
+ .refine((text) => !HIDDEN_MARK.test(text), NO_HIDDEN_MARKS))
215
+ .min(1),
196
216
  default: s.string().optional(),
197
217
  })
198
218
  .strict(),
@@ -253,7 +273,7 @@ export const Plugin = s
253
273
  sdk: IntegrationSheet.shape.kit,
254
274
  name: label,
255
275
  /** Empty for an `integration.yaml` read as a plugin, which has no description. */
256
- description: s.string().max(500).default(""),
276
+ description: s.string().max(500).refine(withoutHiddenMarks, NO_HIDDEN_MARKS).default(""),
257
277
  backend: Backend.optional(),
258
278
  localTools: s.array(LocalTool).min(1).optional(),
259
279
  ui: Ui.optional(),
@@ -1,6 +1,7 @@
1
1
  import { checkKeysIn } from "../../shared/key-in-value.js";
2
2
  import { checkSecretName } from "../../shared/secret-name.js";
3
3
  import { Provider } from "./schema.js";
4
+ import { isProviderType, providerTypesInWords } from "./types.js";
4
5
  /** `providers/<id>.yaml` at the workspace root. */
5
6
  export const providerKind = {
6
7
  name: "provider",
@@ -13,12 +14,50 @@ export const providerKind = {
13
14
  };
14
15
  /**
15
16
  * The secret is named in the file, so a bad name or a pasted key is caught
16
- * here, not at run time. A key pasted into `options` is caught too.
17
+ * here, not at run time. A key pasted into `options` is caught too, and so
18
+ * is a type Halonic can't call, or a `baseUrl` it can't reach, which would
19
+ * only fail once a run reached the model (HAL-14260).
17
20
  */
18
21
  function checkProvider(provider) {
19
22
  const problem = provider.secret === undefined ? undefined : checkSecretName(provider.secret, ["secret"]);
20
23
  return [
24
+ ...checkType(provider),
25
+ ...checkBaseUrl(provider),
21
26
  ...(problem === undefined ? [] : [problem]),
22
27
  ...checkKeysIn(provider.options, ["options"], "provider-option"),
23
28
  ];
24
29
  }
30
+ /**
31
+ * `provider-type` on the `type:` line, worded like the run's fix:
32
+ * "Halonic can't call provider type antropic: set type in
33
+ * providers/mock.yaml to one of anthropic, … or mock".
34
+ */
35
+ function checkType(provider) {
36
+ if (isProviderType(provider.type))
37
+ return [];
38
+ return [
39
+ {
40
+ severity: "error",
41
+ code: "provider-type",
42
+ path: ["type"],
43
+ message: `Halonic can't call provider type ${provider.type}: set type in providers/${provider.id}.yaml to one of ${providerTypesInWords}`,
44
+ },
45
+ ];
46
+ }
47
+ /**
48
+ * `provider-base-url` on the `baseUrl:` line when it doesn't start with
49
+ * http:// or https://. `localhost:11434` passes as a URL, but its scheme is
50
+ * "localhost:", so the run would try to reach an empty address.
51
+ */
52
+ function checkBaseUrl(provider) {
53
+ if (provider.baseUrl === undefined || /^https?:\/\//iu.test(provider.baseUrl))
54
+ return [];
55
+ return [
56
+ {
57
+ severity: "error",
58
+ code: "provider-base-url",
59
+ path: ["baseUrl"],
60
+ message: "baseUrl needs http:// or https://, such as http://localhost:11434",
61
+ },
62
+ ];
63
+ }
@@ -0,0 +1,19 @@
1
+ /** The types that speak OpenAI's chat completions API. */
2
+ export declare const openAiCompatibleTypes: readonly ["openai", "openai-compatible", "ollama", "lmstudio"];
3
+ /** Every type Halonic can call, in the order a fix lists them. */
4
+ export declare const providerTypes: readonly ["anthropic", "openai", "openai-compatible", "ollama", "lmstudio", "mock"];
5
+ /** One of {@link providerTypes}. */
6
+ export type ProviderType = (typeof providerTypes)[number];
7
+ /**
8
+ * The types as a fix lists them: "anthropic, openai, openai-compatible,
9
+ * ollama, lmstudio or mock".
10
+ */
11
+ export declare const providerTypesInWords: string;
12
+ /**
13
+ * Whether Halonic can call a provider of this type.
14
+ *
15
+ * @example
16
+ * isProviderType("anthropic"); // true
17
+ * isProviderType("antropic"); // false
18
+ */
19
+ export declare function isProviderType(type: string): type is ProviderType;
@@ -0,0 +1,22 @@
1
+ // The provider types a workspace's provider file can name. The run builds a
2
+ // provider for each of them, and `halonic validate` refuses any other, so
3
+ // both read this one list and can't drift apart (HAL-14260).
4
+ /** The types that speak OpenAI's chat completions API. */
5
+ export const openAiCompatibleTypes = ["openai", "openai-compatible", "ollama", "lmstudio"];
6
+ /** Every type Halonic can call, in the order a fix lists them. */
7
+ export const providerTypes = ["anthropic", ...openAiCompatibleTypes, "mock"];
8
+ /**
9
+ * The types as a fix lists them: "anthropic, openai, openai-compatible,
10
+ * ollama, lmstudio or mock".
11
+ */
12
+ export const providerTypesInWords = `${providerTypes.slice(0, -1).join(", ")} or ${providerTypes.at(-1)}`;
13
+ /**
14
+ * Whether Halonic can call a provider of this type.
15
+ *
16
+ * @example
17
+ * isProviderType("anthropic"); // true
18
+ * isProviderType("antropic"); // false
19
+ */
20
+ export function isProviderType(type) {
21
+ return providerTypes.includes(type);
22
+ }
@@ -1,11 +1,16 @@
1
1
  import { type Infer } from "../../../../schema-kit/src/index.js";
2
2
  import { Guard } from "../../shared/guard.js";
3
- /** When a routine starts. */
3
+ /**
4
+ * When a routine starts. A trigger that matches none of the kinds, such as
5
+ * two at once or `manual: false`, gets one message that names them all
6
+ * (HAL-14299), instead of Zod's "Invalid input". A mistake inside one kind,
7
+ * such as `every: 15`, still gets that kind's own message.
8
+ */
4
9
  export declare const RoutineTrigger: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
5
10
  schedule: import("zod").ZodString;
6
11
  timezone: import("zod").ZodOptional<import("zod").ZodString>;
7
12
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
8
- every: import("zod").ZodString;
13
+ every: import("zod").ZodPreprocess<import("zod").ZodString, unknown>;
9
14
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
10
15
  manual: import("zod").ZodLiteral<true>;
11
16
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
@@ -17,7 +22,7 @@ export declare const RoutineTrigger: import("zod").ZodUnion<readonly [import("zo
17
22
  mail: import("zod").ZodObject<{
18
23
  connector: import("zod").ZodString;
19
24
  query: import("zod").ZodDefault<import("zod").ZodString>;
20
- every: import("zod").ZodDefault<import("zod").ZodString>;
25
+ every: import("zod").ZodPreprocess<import("zod").ZodDefault<import("zod").ZodString>, unknown>;
21
26
  }, import("zod/v4/core").$strict>;
22
27
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
23
28
  webhook: import("zod").ZodObject<{
@@ -46,7 +51,7 @@ export declare const Routine: import("zod").ZodObject<{
46
51
  schedule: import("zod").ZodString;
47
52
  timezone: import("zod").ZodOptional<import("zod").ZodString>;
48
53
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
49
- every: import("zod").ZodString;
54
+ every: import("zod").ZodPreprocess<import("zod").ZodString, unknown>;
50
55
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
51
56
  manual: import("zod").ZodLiteral<true>;
52
57
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
@@ -58,7 +63,7 @@ export declare const Routine: import("zod").ZodObject<{
58
63
  mail: import("zod").ZodObject<{
59
64
  connector: import("zod").ZodString;
60
65
  query: import("zod").ZodDefault<import("zod").ZodString>;
61
- every: import("zod").ZodDefault<import("zod").ZodString>;
66
+ every: import("zod").ZodPreprocess<import("zod").ZodDefault<import("zod").ZodString>, unknown>;
62
67
  }, import("zod/v4/core").$strict>;
63
68
  }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
64
69
  webhook: import("zod").ZodObject<{
@@ -2,6 +2,13 @@ import { s } from "../../../../schema-kit/src/index.js";
2
2
  import { DURATION_PATTERN, id, version } from "../../shared/fields.js";
3
3
  import { Guard } from "../../shared/guard.js";
4
4
  import { WEBHOOK_HEADER_PATTERN } from "./webhook-headers.js";
5
+ /**
6
+ * Reads a number as text, for an interval such as "15m". YAML reads
7
+ * `every: 15` as a number; as the text "15" it gets the interval's message
8
+ * for a count without a unit, instead of failing the whole trigger
9
+ * (HAL-12607). No number passes: the pattern needs a unit.
10
+ */
11
+ const numberAsText = (value) => (typeof value === "number" ? String(value) : value);
5
12
  /** On a schedule: five-field cron or a shortcut such as @daily, in a time zone. */
6
13
  const ScheduleTrigger = s
7
14
  .object({
@@ -13,9 +20,9 @@ const ScheduleTrigger = s
13
20
  /** At a fixed interval. */
14
21
  const EveryTrigger = s
15
22
  .object({
16
- every: s
23
+ every: s.preprocess(numberAsText, s
17
24
  .string()
18
- .regex(DURATION_PATTERN, 'use a number and a unit, e.g. "15m", "1h", "1d" (runs are placed from midnight UTC)'),
25
+ .regex(DURATION_PATTERN, 'use a number and a unit, e.g. "15m", "1h", "1d" (runs are placed from midnight UTC)')),
19
26
  })
20
27
  .strict();
21
28
  /** Only when someone starts it. */
@@ -40,10 +47,7 @@ const MailTrigger = s
40
47
  * any number of more than one digit, such as "15m"
41
48
  * (format.routine-mail-interval).
42
49
  */
43
- every: s
44
- .string()
45
- .regex(DURATION_PATTERN, 'use a number and a unit, e.g. "2m"')
46
- .default("2m"),
50
+ every: s.preprocess(numberAsText, s.string().regex(DURATION_PATTERN, 'use a number and a unit, e.g. "2m"').default("2m")),
47
51
  })
48
52
  .strict(),
49
53
  })
@@ -68,15 +72,17 @@ const WebhookTrigger = s
68
72
  .strict(),
69
73
  })
70
74
  .strict();
71
- /** When a routine starts. */
72
- export const RoutineTrigger = s.union([
73
- ScheduleTrigger,
74
- EveryTrigger,
75
- ManualTrigger,
76
- SignalTrigger,
77
- MailTrigger,
78
- WebhookTrigger,
79
- ]);
75
+ /**
76
+ * When a routine starts. A trigger that matches none of the kinds, such as
77
+ * two at once or `manual: false`, gets one message that names them all
78
+ * (HAL-14299), instead of Zod's "Invalid input". A mistake inside one kind,
79
+ * such as `every: 15`, still gets that kind's own message.
80
+ */
81
+ export const RoutineTrigger = s.union([ScheduleTrigger, EveryTrigger, ManualTrigger, SignalTrigger, MailTrigger, WebhookTrigger], {
82
+ error: (issue) => issue.code === "invalid_union"
83
+ ? "trigger needs exactly one of: schedule, every, manual: true, signal, mail or webhook."
84
+ : undefined,
85
+ });
80
86
  /** What a routine runs: a workflow with input, or one agent with a prompt. */
81
87
  export const RoutineTarget = s.union([
82
88
  s
@@ -33,10 +33,11 @@ export const WorkspaceSettings = s
33
33
  .strict()
34
34
  .default({ localOnly: false }),
35
35
  /**
36
- * Spending limits in `currency`, counted from model prices. Not enforced
37
- * in 0.1: nothing reads `perRun` or `monthly` yet. `currency` names the
38
- * currency the prices in `models.yaml` are written in; Halonic doesn't
39
- * convert between currencies.
36
+ * Spending limits in `currency`, counted from model prices. The engine
37
+ * stops a run (`run.failed` with the reason `budget`) before a model call
38
+ * once the run has spent `perRun` or the month has spent `monthly`
39
+ * (`engine.budget-stops`). `currency` names the currency the prices in
40
+ * `models.yaml` are written in; Halonic doesn't convert between currencies.
40
41
  */
41
42
  budget: s
42
43
  .object({
@@ -2,6 +2,7 @@ import { parse } from "../../schema-kit/src/index.js";
2
2
  import { err, ok } from "../../std/src/index.js";
3
3
  import { fileKinds } from "./registry.js";
4
4
  import { isMap } from "./shared/legacy-keys.js";
5
+ import { wordIssues } from "./shared/missing-keys.js";
5
6
  import { readSource } from "./source.js";
6
7
  /**
7
8
  * Reads and checks one workspace file of a known kind.
@@ -28,7 +29,8 @@ export function parseFile(kind, text, options = {}) {
28
29
  const prepared = prepare(fileKind, source.data, options.id);
29
30
  const parsed = parse(fileKind.schema, prepared.data);
30
31
  if (!parsed.ok) {
31
- const problems = parsed.error.map((issue) => schemaProblem(issue, source));
32
+ const issues = wordIssues(parsed.error, prepared.data);
33
+ const problems = issues.map((issue) => schemaProblem(issue, source));
32
34
  return err(prepared.idFromPlace ? problems.map((problem) => namePlaceId(problem, options.id)) : problems);
33
35
  }
34
36
  const found = fileKind.check?.(parsed.value) ?? [];
@@ -15,9 +15,16 @@ export declare const agentId: import("zod").ZodString;
15
15
  * their names.
16
16
  */
17
17
  export declare const collectionId: import("zod").ZodString;
18
- /** The `version` key: `1`, and `1` when the file leaves it out. */
18
+ /**
19
+ * The `version` key: `1`, and `1` when the file leaves it out. The message
20
+ * names the one allowed value instead of Zod's "Invalid input: expected 1".
21
+ */
19
22
  export declare const version: import("zod").ZodDefault<import("zod").ZodLiteral<1>>;
20
- /** A whole number and a unit: minutes, hours or days ("30m", "4h", "2d"). */
23
+ /**
24
+ * A whole number of up to five digits and a unit: minutes, hours or days
25
+ * ("30m", "4h", "2d"). The most is 99999 days, about 273 years: longer would
26
+ * leave the range of a date, so no timer could be set for it.
27
+ */
21
28
  export declare const DURATION_PATTERN: RegExp;
22
29
  /** Tuning passed to a model (temperature, maxTokens, …). */
23
30
  export declare const ModelParams: import("zod").ZodObject<{
@@ -7,7 +7,7 @@ export const SCHEMA_VERSION = 1;
7
7
  export const id = s
8
8
  .string()
9
9
  .min(1)
10
- .regex(/^[a-z0-9][a-z0-9-_]*$/, "use lowercase letters, digits, '-' or '_'");
10
+ .regex(/^[a-z0-9][a-z0-9-_]*$/, "use lowercase letters, digits, '-' or '_', starting with a letter or digit");
11
11
  /**
12
12
  * The most characters an id that names a folder may have. A deployment's runs
13
13
  * live in `deployments/<id>/runs` and an agent's harness settings in
@@ -55,11 +55,20 @@ export const agentId = folderId("agent");
55
55
  */
56
56
  export const collectionId = s
57
57
  .string()
58
- .regex(/^[a-z0-9][a-z0-9-]*$/, "use lowercase letters, digits or '-'");
59
- /** The `version` key: `1`, and `1` when the file leaves it out. */
60
- export const version = s.literal(SCHEMA_VERSION).default(SCHEMA_VERSION);
61
- /** A whole number and a unit: minutes, hours or days ("30m", "4h", "2d"). */
62
- export const DURATION_PATTERN = /^[1-9]\d*(m|h|d)$/;
58
+ .regex(/^[a-z0-9][a-z0-9-]*$/, "use lowercase letters, digits or '-', starting with a letter or digit");
59
+ /**
60
+ * The `version` key: `1`, and `1` when the file leaves it out. The message
61
+ * names the one allowed value instead of Zod's "Invalid input: expected 1".
62
+ */
63
+ export const version = s
64
+ .literal(SCHEMA_VERSION, { error: `version must be ${SCHEMA_VERSION}` })
65
+ .default(SCHEMA_VERSION);
66
+ /**
67
+ * A whole number of up to five digits and a unit: minutes, hours or days
68
+ * ("30m", "4h", "2d"). The most is 99999 days, about 273 years: longer would
69
+ * leave the range of a date, so no timer could be set for it.
70
+ */
71
+ export const DURATION_PATTERN = /^[1-9]\d{0,4}(m|h|d)$/;
63
72
  /** Tuning passed to a model (temperature, maxTokens, …). */
64
73
  export const ModelParams = s
65
74
  .object({
@@ -28,5 +28,13 @@ export type Guard = {
28
28
  } | {
29
29
  any: Guard[];
30
30
  };
31
+ /**
32
+ * Says what is wrong with a value that is no condition, instead of Zod's
33
+ * "Invalid input": an unknown kind and the allowed ones, or what a known
34
+ * kind takes.
35
+ */
36
+ export declare function guardProblem(input: unknown): string;
31
37
  /** The schema of a `Guard`. It refers to itself for `not`, `all` and `any`. */
32
38
  export declare const Guard: Schema<Guard>;
39
+ /** Whether a value is a condition the engine accepts, so callers can check before they write one. */
40
+ export declare function isGuard(value: unknown): value is Guard;