@swirls/deploy 0.0.0-stage → 0.0.0

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.
package/README.md CHANGED
@@ -1,3 +1,90 @@
1
- # Temporary Holding Version
1
+ # @swirls/deploy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lowers `.swirls` source files into a deployment definition: the JSON document a runtime stores and runs, described by `@swirls/definition`.
4
+
5
+ ```ts
6
+ import { lowerSwirlsSources, swirlsHost } from '@swirls/deploy'
7
+
8
+ const result = lowerSwirlsSources(
9
+ {
10
+ 'intake.swirls': source,
11
+ 'flows/normalize.swirls': other,
12
+ 'flows/lower-case.ts.swirls': code,
13
+ },
14
+ { host: swirlsHost },
15
+ )
16
+
17
+ if (!result.ok) {
18
+ for (const d of result.diagnostics) {
19
+ console.error(`${d.path ?? ''}:${d.range?.start.line ?? 0}: ${d.message}`)
20
+ }
21
+ } else {
22
+ store(result.definition, result.sourceFiles, result.skillFiles)
23
+ }
24
+ ```
25
+
26
+ `lowerSwirlsSources` reads nothing from disk or from the environment. The files passed in are the whole project, keyed by posix path relative to the project root. A problem in the sources comes back as a diagnostic and is not thrown, so every problem in every file is reported at once.
27
+
28
+ ## `lowerSwirlsSources(files, options?)`
29
+
30
+ | Argument | Type | Meaning |
31
+ | --------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
32
+ | `files` | `Map<string, string>` or `Record<string, string>` | Path to text. Include `.swirls` files, the `.ts.swirls` files they reference, and `.agents/skills/<name>/` files of skills in use. |
33
+ | `options.host` | `LanguageHost` | The runtime's provider catalog, `@openui` checker and harness catalog. Without it those checks are skipped. |
34
+ | `options.newId` | `() => string` | Makes the id of every resource and node. Defaults to a UUIDv7. Pass a counter for reproducible output. |
35
+
36
+ It returns a `LowerResult`:
37
+
38
+ | Field | Meaning |
39
+ | ------------------- | ------------------------------------------------------------------------------------------------------- |
40
+ | `ok` | True when a definition was built. Warnings do not make it false. |
41
+ | `definition` | The definition as a JSON document, or `null`. It has passed `parseDeploymentDefinition`. |
42
+ | `diagnostics` | `{ severity, stage, message, path?, range? }` for every error and warning. |
43
+ | `sourceFiles` | Each `.swirls` file with its size and SHA-256, sorted by path. |
44
+ | `sourceFingerprint` | A stable hash of `sourceFiles`. |
45
+ | `skillFiles` | The files of each skill an agent uses, base64 encoded. |
46
+ | `ast` | The merged syntax tree, or `null`. `buildDeploymentSourceManifest` takes it to map resources to source. |
47
+
48
+ A diagnostic's `stage` says which step reported it: `parse` and `validate` for one file, `merge` for combining files (a name declared twice), `lower` for building the definition, and `definition` for the built document failing its schema.
49
+
50
+ ## The steps, for a host that reads a directory
51
+
52
+ `lowerSwirlsSources` is these steps over an in-memory file system. They are exported for a caller that wants to read a real directory or stop between them. The first two throw on a problem in the sources.
53
+
54
+ ```ts
55
+ import fs from 'node:fs'
56
+ import {
57
+ buildDeploymentDefinitionPayload,
58
+ collectDeploymentSkillFiles,
59
+ collectDeploymentSourceFiles,
60
+ collectReferencedSkillBlocksFromAst,
61
+ computeDeploymentSourceFingerprint,
62
+ createNodeDeployBundleFs,
63
+ mergeProjectSwirlsFiles,
64
+ } from '@swirls/deploy'
65
+
66
+ const files = createNodeDeployBundleFs(fs)
67
+ const merged = mergeProjectSwirlsFiles(files, dir, { host })
68
+ const { definition, parseError } = buildDeploymentDefinitionPayload(merged, { newId })
69
+ const sourceFiles = collectDeploymentSourceFiles(files, dir)
70
+ const skillFiles = collectDeploymentSkillFiles(
71
+ files,
72
+ dir,
73
+ collectReferencedSkillBlocksFromAst(merged),
74
+ )
75
+ const name = computeDeploymentSourceFingerprint(sourceFiles).slice(0, 12)
76
+ ```
77
+
78
+ Also exported: `createMemoryRepoFs` (a file system over a path-to-text map), `computeDeploymentDefinitionFingerprint` (a hash of a definition that ignores ids and ordering), `computeDefinitionHash`, `buildDeploymentSourceManifest`, `compileComputerRecipe`, `compileOperationBlock`, `resolveSkillTree` and `classifySkillBundle`.
79
+
80
+ ## What is not here
81
+
82
+ Storing a deployment is the runtime's job. This package does not upload skill files or sources anywhere, and it does not build computer images: `compileComputerRecipe` only works out the recipe and its hash.
83
+
84
+ ## Tests
85
+
86
+ `bun test` runs the unit tests and a golden test that lowers every recipe in the repository's [`cookbook`](../../cookbook) and compares the result with the output recorded under `src/__golden__/cookbook`.
87
+
88
+ ## Build
89
+
90
+ `bun run build` writes `dist/index.js` and `dist/index.d.ts`. `@swirls/language` and `@swirls/definition` are compiled in, so the package depends only on `zod`, `ajv` and `pathe`. It imports `node:crypto` and `node:fs`, so it runs on Node 20 or later, Bun, and Workers with Node compatibility turned on.