@swirls/deploy 0.0.0 → 0.3.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
@@ -39,13 +39,74 @@ It returns a `LowerResult`:
39
39
  | ------------------- | ------------------------------------------------------------------------------------------------------- |
40
40
  | `ok` | True when a definition was built. Warnings do not make it false. |
41
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. |
42
+ | `diagnostics` | `{ severity, stage, message, path?, range?, related? }` for every error and warning. |
43
43
  | `sourceFiles` | Each `.swirls` file with its size and SHA-256, sorted by path. |
44
44
  | `sourceFingerprint` | A stable hash of `sourceFiles`. |
45
45
  | `skillFiles` | The files of each skill an agent uses, base64 encoded. |
46
46
  | `ast` | The merged syntax tree, or `null`. `buildDeploymentSourceManifest` takes it to map resources to source. |
47
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.
48
+ A diagnostic's `stage` says which step reported it: `mount` for an input that cannot be used (an unusable path), `parse` and `validate` for one file, `merge` for combining files (a name declared twice, at each declaration with `related` naming the others, or files declaring different `version`s), `lower` for building the definition, and `definition` for the built document failing its schema.
49
+
50
+ `lowerSwirlsSources` is `lowerSwirlsMounts` over one mount, with the outputs in this shape.
51
+
52
+ ## Several directories as one program
53
+
54
+ `lowerSwirlsMounts(mounts, options?)` lowers several directories, called mounts, into one definition. Each mount is `{ id, files, skillsRoot? }`:
55
+
56
+ | Field | Meaning |
57
+ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
+ | `id` | Chosen by the host, unique among the mounts of one call, at least one character. Any string works: it is never used as a path. It names the mount in every output and never appears in the definition. |
59
+ | `files` | `Map` or record of mount-relative posix path to text or bytes (`Uint8Array`). `.swirls` and `.ts.swirls` files and operation scripts must be UTF-8; skill files are kept byte for byte, so they may be binary. |
60
+ | `skillsRoot` | The mount-relative directory holding the mount's skills, `<skillsRoot>/<skill>/SKILL.md`. Defaults to `.agents/skills` (`MOUNT_SKILLS_ROOT`). |
61
+
62
+ ```ts
63
+ import { lowerSwirlsMounts, swirlsHost } from '@swirls/deploy'
64
+
65
+ const result = lowerSwirlsMounts(
66
+ [
67
+ { id: 'intake', files: { 'intake.swirls': intake } },
68
+ { id: 'flows', files: { 'greet.swirls': greet, '.agents/skills/kit/SKILL.md': kit } },
69
+ ],
70
+ { host: swirlsHost },
71
+ )
72
+
73
+ for (const d of result.diagnostics) {
74
+ console.error(`${d.mount ?? ''}:${d.path ?? ''}:${d.range?.start.line ?? 0}: ${d.message}`)
75
+ }
76
+ ```
77
+
78
+ What holds across mounts:
79
+
80
+ - **One namespace.** A block may name a block of another mount by its bare name. A name is unique per kind across every mount (a form and a workflow may share one).
81
+ - **Confinement.** A file may read only files of its own mount: a `@ts "…"` reference or an operation's `@sh "…"` / `@ps "…"` script that resolves outside the mount is a `validate` error at the referencing file, `"<ref>" is outside this directory`.
82
+ - **Every duplicate, at every site.** A name declared more than once gives one `merge` error per declaration, at its mount, path and range, with `related` listing every other declaration.
83
+ - **Version.** Every file that declares `version:` must declare the same value; otherwise each such file gets a `merge` error.
84
+ - **Skills.** A skill is read from the skills root of the mount that declares its `skill` block, which need not be the mount of the agent that uses it. Two mounts may hold the same skill directory name under different `skill` blocks.
85
+ - **Inputs.** An empty or repeated mount id, a file path that is absolute, empty or holds `.`, `..` or a backslash, and a `skillsRoot` outside the mount are `mount` errors. Nothing in the inputs makes the call throw.
86
+
87
+ It returns a `LowerMountsResult`: `ok`, `definition` and `ast` as for `lowerSwirlsSources`; `diagnostics`, each with `mount` when it belongs to one and with mount-relative `path`s; `sourceFiles` (each with `mount`, sorted by mount id then path); `skillFiles` (each bundle with the `mount` it was read from, sorted by block name); `manifest` (version 2, below); `mounts` (each mount's `sources` and `skills` fingerprint, sorted by id) and `fingerprint`.
88
+
89
+ ### Ids by site
90
+
91
+ `options.newId(site, mount)` makes every id. `site` says what the id is for and is unique within one call; `mount` is the mount that declares it. Without it every id is a UUIDv7 drawn in call order. A host that derives ids from the site (a UUIDv8 of a hash of the site and something of its own, say) gets identical ids for identical sources, and the ids of one mount stay the same when another mount changes. Every id must be a UUID. The sites are a stable contract:
92
+
93
+ | What | Site |
94
+ | ----------------------------- | --------------------------------------------- |
95
+ | A named block of kind `k` | `<k>:<name>`, `k` as in the manifest's `kind` |
96
+ | A workflow's node | `workflow:<workflow>/node:<node>` |
97
+ | A workflow's edge | `workflow:<workflow>/edge:<source>-><target>` |
98
+ | A synthetic subgraph workflow | `workflow:<its synthesized name>` |
99
+ | A database's connection | `database:<database>/connection:<connection>` |
100
+
101
+ A site that would repeat within one call (two edges between one pair of nodes, say) gets `#2`, `#3`, … in call order. The mount of a synthetic workflow is its parent's.
102
+
103
+ ### Manifest v2
104
+
105
+ `manifest` places every named block: `{ version: 2, mounts, files, resources, nodes, fingerprint }`, where every file, resource and node carries its `mount`. Resources cover every named kind, including `computer`, `query`, `operation`, `role`, `mock` and `playbook`; a role has no `id`. Policies have no name and are not listed, and neither are the nodes of synthetic subgraph workflows. `deploymentSourceManifestV2Schema` and `parseDeploymentSourceManifestV2` check one. Version 1 (`buildDeploymentSourceManifest`) is unchanged.
106
+
107
+ ### Fingerprints
108
+
109
+ A mount's `sources` is the SHA-256 of its `.swirls` and `.ts.swirls` files (path and SHA-256 of each, sorted by path: the formula of `computeDeploymentSourceFingerprint`). Its `skills` is the same over every file under its skills root, whether or not an agent uses it. `fingerprint` hashes every mount's id, `sources` and `skills`, sorted by id: it does not change with the order mounts are given in, and it does change when a file moves from one mount to another.
49
110
 
50
111
  ## The steps, for a host that reads a directory
51
112