agentlane 0.0.0 → 0.4.0-rc.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 (146) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +27 -0
  3. package/README.md +167 -2
  4. package/dist/agents/claude-plugin.js +79 -0
  5. package/dist/agents/cli.js +258 -0
  6. package/dist/agents/detect.js +88 -0
  7. package/dist/agents/init.js +251 -0
  8. package/dist/agents/launcher.js +32 -0
  9. package/dist/agents/package.js +119 -0
  10. package/dist/agents/skills.js +59 -0
  11. package/dist/agents/toml.js +325 -0
  12. package/dist/agents/wiring-check.js +117 -0
  13. package/dist/agents/wiring.js +374 -0
  14. package/dist/bench/host.js +104 -0
  15. package/dist/bench/live.js +511 -0
  16. package/dist/bench/mcp-client.js +91 -0
  17. package/dist/bench/model.js +15 -0
  18. package/dist/bench/report.js +162 -0
  19. package/dist/bench/run.js +121 -0
  20. package/dist/bench/schedule.js +140 -0
  21. package/dist/bench/stats.js +59 -0
  22. package/dist/bench-cli.js +167 -0
  23. package/dist/browser/aria.js +184 -0
  24. package/dist/browser/control.js +203 -0
  25. package/dist/browser/env.js +118 -0
  26. package/dist/browser/evidence.js +44 -0
  27. package/dist/browser/install.js +361 -0
  28. package/dist/browser/kinds.js +10 -0
  29. package/dist/browser/lane-browser.js +224 -0
  30. package/dist/browser/libraries.js +56 -0
  31. package/dist/browser/paths.js +29 -0
  32. package/dist/browser/release.js +121 -0
  33. package/dist/browser/screen.js +19 -0
  34. package/dist/browser/signin.js +154 -0
  35. package/dist/browser/stop.js +163 -0
  36. package/dist/browser/tools.js +25 -0
  37. package/dist/cache/build.js +154 -0
  38. package/dist/cache/config.js +186 -0
  39. package/dist/cache/index.js +4 -0
  40. package/dist/cache/key.js +196 -0
  41. package/dist/cache/store.js +303 -0
  42. package/dist/cli.js +178 -0
  43. package/dist/clock.js +4 -0
  44. package/dist/devices/adb.js +160 -0
  45. package/dist/devices/android.js +214 -0
  46. package/dist/devices/backend.js +7 -0
  47. package/dist/devices/bundler.js +46 -0
  48. package/dist/devices/common.js +51 -0
  49. package/dist/devices/controls.js +65 -0
  50. package/dist/devices/dial.js +56 -0
  51. package/dist/devices/emulator.js +396 -0
  52. package/dist/devices/hygiene.js +202 -0
  53. package/dist/devices/index.js +5 -0
  54. package/dist/devices/launch.js +76 -0
  55. package/dist/devices/simctl.js +119 -0
  56. package/dist/devices/tools.js +1 -0
  57. package/dist/devices/variant.js +99 -0
  58. package/dist/devices/xcrun.js +265 -0
  59. package/dist/driver/absence.js +54 -0
  60. package/dist/driver/caller.js +51 -0
  61. package/dist/driver/client.js +312 -0
  62. package/dist/driver/diff.js +180 -0
  63. package/dist/driver/elements.js +70 -0
  64. package/dist/driver/engine-main.js +13 -0
  65. package/dist/driver/engine.js +499 -0
  66. package/dist/driver/errors.js +11 -0
  67. package/dist/driver/exec.js +66 -0
  68. package/dist/driver/failure.js +156 -0
  69. package/dist/driver/flow.js +94 -0
  70. package/dist/driver/idle.js +100 -0
  71. package/dist/driver/images.js +68 -0
  72. package/dist/driver/install.js +272 -0
  73. package/dist/driver/lock.js +101 -0
  74. package/dist/driver/look.js +223 -0
  75. package/dist/driver/maestro-child.js +194 -0
  76. package/dist/driver/maestro-runs.js +46 -0
  77. package/dist/driver/paths.js +105 -0
  78. package/dist/driver/pixels.js +144 -0
  79. package/dist/driver/plan.js +108 -0
  80. package/dist/driver/release.js +7 -0
  81. package/dist/driver/runner.js +42 -0
  82. package/dist/driver/selector.js +91 -0
  83. package/dist/driver/session.js +474 -0
  84. package/dist/driver/suggest.js +86 -0
  85. package/dist/driver/supervisor.js +251 -0
  86. package/dist/driver/tree.js +426 -0
  87. package/dist/driver-cli.js +865 -0
  88. package/dist/evidence/device.js +177 -0
  89. package/dist/evidence/evidence.js +304 -0
  90. package/dist/evidence/files.js +92 -0
  91. package/dist/hooks/env.js +81 -0
  92. package/dist/hooks/run.js +101 -0
  93. package/dist/mcp/server.js +69 -0
  94. package/dist/mcp/tools.js +246 -0
  95. package/dist/name.js +22 -0
  96. package/dist/plugin/aims.js +465 -0
  97. package/dist/plugin/conventions.js +73 -0
  98. package/dist/plugin/guard.js +163 -0
  99. package/dist/plugin/hook-cli.js +216 -0
  100. package/dist/plugin/session-name.js +28 -0
  101. package/dist/plugin/shell.js +254 -0
  102. package/dist/processes.js +77 -0
  103. package/dist/project/config.js +316 -0
  104. package/dist/project/schema.js +335 -0
  105. package/dist/project/validate.js +224 -0
  106. package/dist/registry/config.js +142 -0
  107. package/dist/registry/format.js +22 -0
  108. package/dist/registry/owner.js +265 -0
  109. package/dist/registry/paths.js +50 -0
  110. package/dist/registry/ports.js +26 -0
  111. package/dist/registry/prune.js +160 -0
  112. package/dist/registry/refusal.js +53 -0
  113. package/dist/registry/registry.js +1027 -0
  114. package/dist/registry/resources.js +117 -0
  115. package/dist/registry/rows.js +115 -0
  116. package/dist/registry/status.js +85 -0
  117. package/dist/registry/store.js +274 -0
  118. package/dist/registry/types.js +1 -0
  119. package/dist/registry-cli.js +544 -0
  120. package/dist/services/services.js +268 -0
  121. package/dist/services/system.js +189 -0
  122. package/dist/up/deps.js +1 -0
  123. package/dist/up/doctor.js +424 -0
  124. package/dist/up/exec.js +133 -0
  125. package/dist/up/lane-files.js +75 -0
  126. package/dist/up/lane-services.js +38 -0
  127. package/dist/up/maestro-env.js +172 -0
  128. package/dist/up/preflight.js +232 -0
  129. package/dist/up/release.js +148 -0
  130. package/dist/up/resources.js +178 -0
  131. package/dist/up/restart.js +87 -0
  132. package/dist/up/setup.js +28 -0
  133. package/dist/up/up.js +610 -0
  134. package/dist/up-cli.js +258 -0
  135. package/dist/usage.js +16 -0
  136. package/package.json +58 -3
  137. package/schema/agentlane.schema.json +675 -0
  138. package/skills/create-verification-skill/LICENSE +21 -0
  139. package/skills/create-verification-skill/SKILL.md +88 -0
  140. package/skills/dev-loop/LICENSE +21 -0
  141. package/skills/dev-loop/SKILL.md +61 -0
  142. package/skills/device/SKILL.md +8 -0
  143. package/skills/drive/SKILL.md +64 -0
  144. package/skills/maintain-verification-skill/LICENSE +21 -0
  145. package/skills/maintain-verification-skill/SKILL.md +42 -0
  146. package/skills/setup/SKILL.md +80 -0
@@ -0,0 +1,335 @@
1
+ import { BROWSER_DRIVERS, DEFAULT_BROWSER_DRIVER } from "../browser/kinds.js";
2
+ import { buildCacheSchema } from "../cache/config.js";
3
+ import { CONFIG_FILE, ENV_PREFIX, envName, TOOL } from "../name.js";
4
+ export const SERVICE_NAME_PATTERN = '^[a-z][a-z0-9-]*$';
5
+ export const BUILT_IN_SERVICE_TYPES = ['metro', 'api', 'web'];
6
+ export const LAUNCH_MODES = ['dev-client', 'bundler-pin', 'hook'];
7
+ export const HOOK_NAMES = ['setup', 'build', 'launch', 'signin', 'teardown'];
8
+ export const PRECONDITION_STAGES = ['claim', 'build'];
9
+ export const PLATFORMS = ['ios', 'android'];
10
+ export const WEB_PLATFORM = 'web';
11
+ export const PROJECT_PLATFORMS = [...PLATFORMS, WEB_PLATFORM];
12
+ export const EXPORT_NAME_PATTERN = '^[A-Za-z_][A-Za-z0-9_]*$';
13
+ export const EXPORTS_FILE_ENV = envName('EXPORTS');
14
+ export const STORAGE_STATE_ENV = envName('STORAGE_STATE');
15
+ export const DEFAULT_WEB_PATH = '/';
16
+ export const DEFAULT_TEARDOWN_SECONDS = 120;
17
+ export const DEFAULT_VARIANT = 'Debug';
18
+ export const DEFAULT_READY_HOST = '127.0.0.1';
19
+ export const DEFAULT_READY_SECONDS = 60;
20
+ export const DEFAULT_DIAL_VALUE = 'http://localhost:{port}';
21
+ const port = { type: 'integer', minimum: 1024, maximum: 65535 };
22
+ const bundleId = {
23
+ type: 'string',
24
+ pattern: '^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)+$',
25
+ description: 'The bundle id or package name.',
26
+ };
27
+ const output = {
28
+ type: 'string',
29
+ minLength: 1,
30
+ description: 'The app the build hook produces (an .app or .apk), relative to this file. The toolkit installs it. Leave it out when the build hook installs the app itself; the installed app is then read back for the cache.',
31
+ };
32
+ const device = {
33
+ type: 'object',
34
+ additionalProperties: false,
35
+ properties: {
36
+ type: {
37
+ type: 'string',
38
+ minLength: 1,
39
+ description: 'A simulator device type, or an Android device profile such as pixel_8. Default: the newest iPhone the runtime supports, or pixel_8.',
40
+ },
41
+ runtime: {
42
+ type: 'string',
43
+ minLength: 1,
44
+ description: 'A simulator runtime, or an Android system image (a package id or an API level). Default: the newest installed iOS runtime, or the newest Google APIs image.',
45
+ },
46
+ strict: {
47
+ type: 'boolean',
48
+ default: false,
49
+ description: 'Take only a device of exactly this type and runtime. Without it, when the shared pool is full, a lane takes a free device of another type rather than deleting one to make this type.',
50
+ },
51
+ },
52
+ };
53
+ const platformApp = (platform) => ({
54
+ type: 'object',
55
+ additionalProperties: false,
56
+ description: `What differs on ${platform}: these replace app.bundleId, app.output and app.device when \`up\` runs for ${platform}.`,
57
+ properties: { bundleId, output, device },
58
+ });
59
+ const host = {
60
+ type: 'string',
61
+ minLength: 1,
62
+ default: DEFAULT_READY_HOST,
63
+ description: 'The host the readiness check connects to.',
64
+ };
65
+ const hook = (when) => ({ type: 'string', minLength: 1, description: `A shell command run with \`sh -c\` ${when}.` });
66
+ export const projectSchema = {
67
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
68
+ title: CONFIG_FILE,
69
+ description: `How ${TOOL} runs this project: its mobile app, its web app, or both; the long-running services they need; what each lane gets of its own; and the hooks that set it up, build, launch and sign in. Commands run in the directory holding this file, with ${ENV_PREFIX}_* variables for the lane (device, ports, worktree), the values of the lane's resources, and LANG and LC_ALL set to a UTF-8 locale: en_US.UTF-8 on macOS, C.UTF-8 on Linux.`,
70
+ type: 'object',
71
+ additionalProperties: false,
72
+ properties: {
73
+ $schema: { type: 'string', description: 'The path or URL of this schema, for editors.' },
74
+ app: { $ref: '#/$defs/app' },
75
+ web: { $ref: '#/$defs/web' },
76
+ services: {
77
+ type: 'object',
78
+ description: `The long-running servers the app needs, by name. Each gets a claimed port in ${ENV_PREFIX}_<NAME>_PORT (the name upper-cased, dashes as underscores).`,
79
+ propertyNames: { pattern: SERVICE_NAME_PATTERN },
80
+ additionalProperties: { $ref: '#/$defs/service' },
81
+ },
82
+ resources: {
83
+ type: 'object',
84
+ description: `What each lane gets of its own besides ports, such as a database, by name. \`up\` runs each create once per lane, in this order, after the setup hook and the build preconditions (also under --no-setup). The values a create exports then reach the lane's services, the hooks after setup, and \`${TOOL} exec\`, as ${ENV_PREFIX}_<NAME>_PORT does; a command never takes an exported variable from the caller's environment. When the lane ends (release, the session-end release, or a reap of a lane whose owner died or was taken over), each teardown runs, last created first.`,
85
+ propertyNames: { pattern: SERVICE_NAME_PATTERN },
86
+ additionalProperties: { $ref: '#/$defs/resource' },
87
+ },
88
+ hooks: { $ref: '#/$defs/hooks' },
89
+ preconditions: {
90
+ type: 'array',
91
+ description: 'Checks `up` runs before any slow step. A failing check refuses with its fix.',
92
+ items: { $ref: '#/$defs/precondition' },
93
+ },
94
+ hygiene: { $ref: '#/$defs/hygiene' },
95
+ buildCache: buildCacheSchema,
96
+ driver: { $ref: '#/$defs/driver' },
97
+ },
98
+ $defs: {
99
+ app: {
100
+ type: 'object',
101
+ additionalProperties: false,
102
+ description: 'The mobile app: what `up` builds, installs and launches on the claimed simulator or emulator.',
103
+ required: ['platform', 'bundleId', 'launch'],
104
+ properties: {
105
+ platform: {
106
+ enum: PLATFORMS,
107
+ description: 'The platform `up` claims a device for, unless `up --platform` names another.',
108
+ },
109
+ bundleId,
110
+ scheme: {
111
+ type: 'string',
112
+ pattern: '^[A-Za-z][A-Za-z0-9+.-]*$',
113
+ description: 'A URL scheme the app handles. It is approved on the simulator before it boots, so opening a link never stops at "Open in ...?".',
114
+ },
115
+ launch: {
116
+ enum: LAUNCH_MODES,
117
+ description: "How the app is launched. dev-client: an Expo dev client opened on the bundler with --initialUrl. bundler-pin: a React Native app whose bundler location is written to its defaults and read back, then launched. hook: the project's launch hook.",
118
+ },
119
+ bundler: {
120
+ type: 'string',
121
+ pattern: SERVICE_NAME_PATTERN,
122
+ description: 'The service the app loads its JavaScript from. Default: the only service of type metro.',
123
+ },
124
+ variant: {
125
+ type: 'string',
126
+ minLength: 1,
127
+ default: DEFAULT_VARIANT,
128
+ description: `The build variant, given to hooks as ${ENV_PREFIX}_VARIANT and used by the build cache.`,
129
+ },
130
+ output,
131
+ device,
132
+ ios: platformApp('iOS'),
133
+ android: platformApp('Android'),
134
+ },
135
+ },
136
+ web: {
137
+ type: 'object',
138
+ additionalProperties: false,
139
+ description: `The web app: the service that serves it and the page to open. \`up --platform web\` (the default when there is no app) claims ports and no device, starts the services, and ends on doctor with the app's URL, also given to commands as ${ENV_PREFIX}_WEB_URL.`,
140
+ properties: {
141
+ service: {
142
+ type: 'string',
143
+ pattern: SERVICE_NAME_PATTERN,
144
+ description: 'The service that serves the web app. Default: the only service of type web.',
145
+ },
146
+ path: {
147
+ type: 'string',
148
+ pattern: '^/',
149
+ default: DEFAULT_WEB_PATH,
150
+ description: "The page to open, on the service's port.",
151
+ },
152
+ browser: { $ref: '#/$defs/browser' },
153
+ },
154
+ },
155
+ browser: {
156
+ type: 'object',
157
+ additionalProperties: false,
158
+ description: `The lane's own browser, which \`up\` opens on the web app. Each lane gets its own profile folder, debugging port and driver session, released with the lane. The toolkit installs the driver and its browser at pinned versions in its own data folder (\`${TOOL} browser install\`). Drive it with the driver's own CLI under \`${TOOL} exec\`, which sets the driver's session, the web app's URL and the lane's saved login. The signin hook writes that saved login, in Playwright's storage-state format, to the file named by $${STORAGE_STATE_ENV}, and the browser starts with it.`,
159
+ properties: {
160
+ driver: {
161
+ enum: BROWSER_DRIVERS,
162
+ default: DEFAULT_BROWSER_DRIVER,
163
+ description: "playwright: Playwright's own CLI, playwright-cli, and Playwright tests run with `exec -- npx playwright test`. agent-browser: Vercel's agent-browser CLI, headless. Both drive the toolkit's pinned Chrome for Testing.",
164
+ },
165
+ headed: {
166
+ type: 'boolean',
167
+ default: false,
168
+ description: 'Show the browser window, so a person can watch it. Default: headless. Playwright only: agent-browser runs headless, on the headless shell of Chrome for Testing.',
169
+ },
170
+ },
171
+ },
172
+ resource: {
173
+ type: 'object',
174
+ additionalProperties: false,
175
+ required: ['create', 'teardown'],
176
+ properties: {
177
+ create: {
178
+ type: 'string',
179
+ minLength: 1,
180
+ description: `A shell command that makes the resource for this lane. It writes each value it exports as a NAME=value line (quotes around the value are removed) to the file named by $${EXPORTS_FILE_ENV}. Its output goes to its log, and a failing create stops \`up\` with it. It runs again at the next \`up\` when it failed or never finished, so it must cope with what a partial run left.`,
181
+ },
182
+ exports: {
183
+ type: 'array',
184
+ items: { type: 'string', pattern: EXPORT_NAME_PATTERN },
185
+ uniqueItems: true,
186
+ description: `The variables create writes, such as DATABASE_URL. Create must write each of them and no other. Names starting with ${ENV_PREFIX}_, and LANG and LC_ALL, are the toolkit's.`,
187
+ },
188
+ teardown: {
189
+ type: 'string',
190
+ minLength: 1,
191
+ description: `A shell command that removes the resource when the lane ends. What it runs is recorded when create starts: this command, its folder and its variables (the lane's, plus the values create exported), so it runs even after this file changes and after the session that made the lane died. When the folder is gone (the worktree was deleted), it runs in the lane's log folder. A failed teardown is kept and tried again at the next release or reap, so it must cope with a resource that is already gone.`,
192
+ },
193
+ cwd: { type: 'string', minLength: 1, description: 'The directory create and teardown run in, relative to this file.' },
194
+ teardownTimeoutSeconds: {
195
+ type: 'number',
196
+ exclusiveMinimum: 0,
197
+ default: DEFAULT_TEARDOWN_SECONDS,
198
+ description: 'How long teardown may run before it is stopped and counted as failed.',
199
+ },
200
+ },
201
+ },
202
+ service: {
203
+ type: 'object',
204
+ additionalProperties: false,
205
+ required: ['type', 'start', 'ready'],
206
+ properties: {
207
+ type: {
208
+ type: 'string',
209
+ pattern: SERVICE_NAME_PATTERN,
210
+ description: `The port block the service's port comes from: ${BUILT_IN_SERVICE_TYPES.join(', ')}, or a name of your own with \`ports\`.`,
211
+ },
212
+ ports: {
213
+ type: 'array',
214
+ prefixItems: [port, port],
215
+ items: false,
216
+ minItems: 2,
217
+ description: "[first, last]: the port block for a type of your own. The Mac's own blocks (metro, api, web, and any in its registry config) take precedence.",
218
+ },
219
+ start: {
220
+ type: 'string',
221
+ minLength: 1,
222
+ description: `The command that runs the server in the foreground on $${ENV_PREFIX}_<NAME>_PORT. It is started in its own process group and logged to a file per lane.`,
223
+ },
224
+ cwd: { type: 'string', minLength: 1, description: 'The directory to start it in, relative to this file.' },
225
+ platforms: {
226
+ type: 'array',
227
+ items: { enum: PROJECT_PLATFORMS },
228
+ minItems: 1,
229
+ uniqueItems: true,
230
+ description: 'The platforms that need it, such as ["ios", "android"] for a bundler the web app does not use. `up`, `doctor` and `restart` for another platform leave it out. Leave it out to run it for every platform.',
231
+ },
232
+ ready: { oneOf: [{ $ref: '#/$defs/httpReady' }, { $ref: '#/$defs/tcpReady' }] },
233
+ timeoutSeconds: {
234
+ type: 'number',
235
+ exclusiveMinimum: 0,
236
+ default: DEFAULT_READY_SECONDS,
237
+ description: 'How long to wait for the readiness check.',
238
+ },
239
+ dial: {
240
+ type: 'object',
241
+ additionalProperties: false,
242
+ required: ['argument'],
243
+ description: "The app dials this service: launch it with this argument, so it talks to this lane's server.",
244
+ properties: {
245
+ argument: { type: 'string', pattern: '^-[A-Za-z0-9_.-]+$', description: 'The launch argument, such as -apiBaseUrl.' },
246
+ value: {
247
+ type: 'string',
248
+ pattern: '\\{port\\}',
249
+ default: DEFAULT_DIAL_VALUE,
250
+ description: "The argument's value; {port} is the service's port.",
251
+ },
252
+ },
253
+ },
254
+ },
255
+ },
256
+ httpReady: {
257
+ type: 'object',
258
+ additionalProperties: false,
259
+ required: ['kind', 'path'],
260
+ properties: {
261
+ kind: { const: 'http' },
262
+ path: { type: 'string', pattern: '^/', description: 'The path to GET.' },
263
+ status: { type: 'integer', minimum: 100, maximum: 599, default: 200, description: 'The status that means ready.' },
264
+ body: { type: 'string', minLength: 1, description: 'Text the response body must contain.' },
265
+ host,
266
+ },
267
+ },
268
+ tcpReady: {
269
+ type: 'object',
270
+ additionalProperties: false,
271
+ required: ['kind'],
272
+ properties: { kind: { const: 'tcp' }, host },
273
+ },
274
+ hooks: {
275
+ type: 'object',
276
+ additionalProperties: false,
277
+ properties: {
278
+ setup: hook('first, to install dependencies'),
279
+ build: hook('to build the app for the claimed device'),
280
+ launch: hook(`to launch the app when app.launch is "hook"; ${ENV_PREFIX}_LAUNCH_ARGS holds the dial arguments`),
281
+ signin: hook(`after launch, to sign in; for the web app it writes the lane's saved login, in Playwright's storage-state format, to $${STORAGE_STATE_ENV}`),
282
+ teardown: hook(`by \`${TOOL} release\`, after the services stop and before the resources' teardowns`),
283
+ },
284
+ },
285
+ precondition: {
286
+ type: 'object',
287
+ additionalProperties: false,
288
+ required: ['name', 'run', 'fix'],
289
+ properties: {
290
+ name: { type: 'string', minLength: 1, description: 'What is checked, as a short phrase.' },
291
+ run: { type: 'string', minLength: 1, description: 'A shell command that exits 0 when the precondition holds.' },
292
+ fix: { type: 'string', minLength: 1, description: 'What to do when it fails.' },
293
+ before: {
294
+ enum: PRECONDITION_STAGES,
295
+ default: 'claim',
296
+ description: 'claim: checked before anything is claimed. build: checked after the setup hook, before the build.',
297
+ },
298
+ platforms: {
299
+ type: 'array',
300
+ items: { enum: PROJECT_PLATFORMS },
301
+ minItems: 1,
302
+ uniqueItems: true,
303
+ description: 'The platforms it applies to. Leave it out to check it for every platform.',
304
+ },
305
+ },
306
+ },
307
+ hygiene: {
308
+ type: 'object',
309
+ additionalProperties: false,
310
+ properties: {
311
+ location: {
312
+ type: 'object',
313
+ additionalProperties: false,
314
+ required: ['latitude', 'longitude'],
315
+ properties: {
316
+ latitude: { type: 'number', minimum: -90, maximum: 90 },
317
+ longitude: { type: 'number', minimum: -180, maximum: 180 },
318
+ },
319
+ },
320
+ appearance: { enum: ['light', 'dark'] },
321
+ },
322
+ },
323
+ driver: {
324
+ type: 'object',
325
+ additionalProperties: false,
326
+ description: 'The project drives its app with the toolkit (Maestro flows); `up` and `doctor` then check for Java 17.',
327
+ properties: {
328
+ flows: { type: 'string', minLength: 1, description: 'The folder of committed flows, relative to this file.' },
329
+ },
330
+ },
331
+ },
332
+ };
333
+ export function schemaText() {
334
+ return `${JSON.stringify(projectSchema, null, 2)}\n`;
335
+ }
@@ -0,0 +1,224 @@
1
+ const ANNOTATIONS = new Set([
2
+ '$schema',
3
+ '$id',
4
+ '$comment',
5
+ '$defs',
6
+ 'title',
7
+ 'description',
8
+ 'markdownDescription',
9
+ 'default',
10
+ 'examples',
11
+ 'deprecated',
12
+ ]);
13
+ const KEYWORDS = new Set([
14
+ '$ref',
15
+ 'type',
16
+ 'enum',
17
+ 'const',
18
+ 'properties',
19
+ 'required',
20
+ 'additionalProperties',
21
+ 'propertyNames',
22
+ 'items',
23
+ 'prefixItems',
24
+ 'minItems',
25
+ 'maxItems',
26
+ 'uniqueItems',
27
+ 'minLength',
28
+ 'pattern',
29
+ 'minimum',
30
+ 'maximum',
31
+ 'exclusiveMinimum',
32
+ 'oneOf',
33
+ ]);
34
+ function isRecord(value) {
35
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
36
+ }
37
+ function pointer(segment) {
38
+ return `/${String(segment).replaceAll('~', '~0').replaceAll('/', '~1')}`;
39
+ }
40
+ function typeOf(value) {
41
+ if (value === null)
42
+ return 'null';
43
+ if (Array.isArray(value))
44
+ return 'array';
45
+ if (typeof value === 'number')
46
+ return Number.isInteger(value) ? 'integer' : 'number';
47
+ return typeof value;
48
+ }
49
+ function hasType(value, type) {
50
+ const actual = typeOf(value);
51
+ return actual === type || (type === 'number' && actual === 'integer');
52
+ }
53
+ function show(value) {
54
+ return JSON.stringify(value);
55
+ }
56
+ function article(type) {
57
+ return /^[aeiou]/.test(type) ? `an ${type}` : `a ${type}`;
58
+ }
59
+ function equal(a, b) {
60
+ return JSON.stringify(a) === JSON.stringify(b);
61
+ }
62
+ function sub(schema, key) {
63
+ const value = schema[key];
64
+ if (typeof value === 'boolean' || isRecord(value))
65
+ return value;
66
+ throw new Error(`schema keyword ${key} is not a schema`);
67
+ }
68
+ function list(schema, key) {
69
+ const value = schema[key];
70
+ if (!Array.isArray(value))
71
+ throw new Error(`schema keyword ${key} is not a list`);
72
+ return value;
73
+ }
74
+ function num(schema, key) {
75
+ const value = schema[key];
76
+ if (typeof value !== 'number')
77
+ throw new Error(`schema keyword ${key} is not a number`);
78
+ return value;
79
+ }
80
+ export class SchemaValidator {
81
+ root;
82
+ constructor(root) {
83
+ this.root = root;
84
+ }
85
+ validate(value) {
86
+ return this.check(value, this.root, '', '#');
87
+ }
88
+ resolve(ref) {
89
+ const match = /^#\/\$defs\/([A-Za-z0-9_-]+)$/.exec(ref);
90
+ const defs = this.root.$defs;
91
+ const target = match?.[1] !== undefined && isRecord(defs) ? defs[match[1]] : undefined;
92
+ if (typeof target === 'boolean' || isRecord(target))
93
+ return target;
94
+ throw new Error(`schema $ref ${ref} does not resolve to a schema under #/$defs`);
95
+ }
96
+ check(value, schema, path, at) {
97
+ if (schema === true)
98
+ return [];
99
+ if (schema === false)
100
+ return [{ path, schemaPath: at, message: 'is not allowed here' }];
101
+ for (const key of Object.keys(schema)) {
102
+ if (!KEYWORDS.has(key) && !ANNOTATIONS.has(key))
103
+ throw new Error(`schema keyword '${key}' at ${at} is not supported`);
104
+ }
105
+ const problems = [];
106
+ const fail = (keyword, message, where = path) => {
107
+ problems.push({ path: where, schemaPath: `${at}/${keyword}`, message });
108
+ };
109
+ if (typeof schema.$ref === 'string') {
110
+ problems.push(...this.check(value, this.resolve(schema.$ref), path, schema.$ref));
111
+ }
112
+ if (schema.type !== undefined) {
113
+ const types = (Array.isArray(schema.type) ? schema.type : [schema.type]);
114
+ if (!types.some(type => hasType(value, type))) {
115
+ fail('type', `must be ${types.map(article).join(' or ')}, not ${article(typeOf(value))}`);
116
+ return problems;
117
+ }
118
+ }
119
+ if (schema.const !== undefined && !equal(value, schema.const))
120
+ fail('const', `must be ${show(schema.const)}`);
121
+ if (schema.enum !== undefined && !list(schema, 'enum').some(option => equal(option, value))) {
122
+ fail('enum', `must be one of ${list(schema, 'enum').map(show).join(', ')}, not ${show(value)}`);
123
+ }
124
+ if (schema.oneOf !== undefined)
125
+ problems.push(...this.oneOf(value, list(schema, 'oneOf'), path, `${at}/oneOf`));
126
+ if (isRecord(value))
127
+ problems.push(...this.object(value, schema, path, at));
128
+ if (Array.isArray(value))
129
+ problems.push(...this.array(value, schema, path, at));
130
+ if (typeof value === 'string') {
131
+ if (schema.minLength !== undefined && value.length < num(schema, 'minLength')) {
132
+ fail('minLength', value.length === 0 ? 'must not be empty' : `must be at least ${String(num(schema, 'minLength'))} characters`);
133
+ }
134
+ if (typeof schema.pattern === 'string' && !new RegExp(schema.pattern, 'u').test(value)) {
135
+ fail('pattern', `${show(value)} must match ${schema.pattern}`);
136
+ }
137
+ }
138
+ if (typeof value === 'number') {
139
+ if (schema.minimum !== undefined && value < num(schema, 'minimum'))
140
+ fail('minimum', `must be at least ${String(num(schema, 'minimum'))}`);
141
+ if (schema.maximum !== undefined && value > num(schema, 'maximum'))
142
+ fail('maximum', `must be at most ${String(num(schema, 'maximum'))}`);
143
+ if (schema.exclusiveMinimum !== undefined && value <= num(schema, 'exclusiveMinimum'))
144
+ fail('exclusiveMinimum', `must be more than ${String(num(schema, 'exclusiveMinimum'))}`);
145
+ }
146
+ return problems;
147
+ }
148
+ object(value, schema, path, at) {
149
+ const problems = [];
150
+ const properties = isRecord(schema.properties) ? schema.properties : {};
151
+ if (schema.required !== undefined) {
152
+ for (const name of list(schema, 'required')) {
153
+ if (!(name in value))
154
+ problems.push({ path: path + pointer(name), schemaPath: `${at}/required`, message: 'is required' });
155
+ }
156
+ }
157
+ for (const [name, child] of Object.entries(value)) {
158
+ const where = path + pointer(name);
159
+ if (schema.propertyNames !== undefined) {
160
+ problems.push(...this.check(name, sub(schema, 'propertyNames'), where, `${at}/propertyNames`));
161
+ }
162
+ const declared = properties[name];
163
+ if (typeof declared === 'boolean' || isRecord(declared)) {
164
+ problems.push(...this.check(child, declared, where, `${at}/properties${pointer(name)}`));
165
+ }
166
+ else if (schema.additionalProperties === false) {
167
+ const known = Object.keys(properties);
168
+ problems.push({
169
+ path: where,
170
+ schemaPath: `${at}/additionalProperties`,
171
+ message: `is not a known field${known.length > 0 ? ` (known: ${known.join(', ')})` : ''}`,
172
+ });
173
+ }
174
+ else if (schema.additionalProperties !== undefined) {
175
+ problems.push(...this.check(child, sub(schema, 'additionalProperties'), where, `${at}/additionalProperties`));
176
+ }
177
+ }
178
+ return problems;
179
+ }
180
+ array(value, schema, path, at) {
181
+ const problems = [];
182
+ if (schema.minItems !== undefined && value.length < num(schema, 'minItems')) {
183
+ problems.push({
184
+ path,
185
+ schemaPath: `${at}/minItems`,
186
+ message: `must have at least ${String(num(schema, 'minItems'))} item(s)`,
187
+ });
188
+ }
189
+ if (schema.maxItems !== undefined && value.length > num(schema, 'maxItems')) {
190
+ problems.push({
191
+ path,
192
+ schemaPath: `${at}/maxItems`,
193
+ message: `must have at most ${String(num(schema, 'maxItems'))} item(s)`,
194
+ });
195
+ }
196
+ if (schema.uniqueItems === true && new Set(value.map(item => JSON.stringify(item))).size !== value.length) {
197
+ problems.push({ path, schemaPath: `${at}/uniqueItems`, message: 'must not list an item twice' });
198
+ }
199
+ const prefix = schema.prefixItems === undefined ? [] : list(schema, 'prefixItems');
200
+ value.forEach((item, i) => {
201
+ const where = path + pointer(i);
202
+ const positional = prefix[i];
203
+ if (positional !== undefined)
204
+ problems.push(...this.check(item, positional, where, `${at}/prefixItems/${String(i)}`));
205
+ else if (schema.items !== undefined)
206
+ problems.push(...this.check(item, sub(schema, 'items'), where, `${at}/items`));
207
+ });
208
+ return problems;
209
+ }
210
+ oneOf(value, branches, path, at) {
211
+ const results = branches.map((branch, i) => this.check(value, branch, path, `${at}/${String(i)}`));
212
+ const passing = results.filter(r => r.length === 0).length;
213
+ if (passing === 1)
214
+ return [];
215
+ if (passing > 1)
216
+ return [{ path, schemaPath: at, message: 'matches more than one of the allowed shapes' }];
217
+ const isChild = (p) => p.path.startsWith(`${path}/`) && !p.path.slice(path.length + 1).includes('/');
218
+ const discriminated = results.filter(r => !r.some(p => p.schemaPath.endsWith('/const') && isChild(p)));
219
+ const [only] = discriminated;
220
+ if (discriminated.length === 1 && only)
221
+ return only;
222
+ return [{ path, schemaPath: at, message: `must match one of the ${String(branches.length)} allowed shapes` }];
223
+ }
224
+ }