@intentius/chant-lexicon-fly 0.16.0 → 0.18.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.
Files changed (65) hide show
  1. package/README.md +2 -2
  2. package/dist/composites/fly-deploy.d.ts +1 -1
  3. package/dist/composites/fly-deploy.d.ts.map +1 -1
  4. package/dist/coverage.d.ts +15 -0
  5. package/dist/coverage.d.ts.map +1 -0
  6. package/dist/emulator-freshness-cli.d.ts +11 -0
  7. package/dist/emulator-freshness-cli.d.ts.map +1 -0
  8. package/dist/emulator-freshness.d.ts +38 -0
  9. package/dist/emulator-freshness.d.ts.map +1 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/mcp/context-tools.d.ts +15 -0
  13. package/dist/mcp/context-tools.d.ts.map +1 -0
  14. package/dist/op/activities/emulator-images.d.ts +20 -0
  15. package/dist/op/activities/emulator-images.d.ts.map +1 -0
  16. package/dist/op/activities/flaps.d.ts +1 -1
  17. package/dist/op/activities/flaps.d.ts.map +1 -1
  18. package/dist/op/activities/index.d.ts +4 -0
  19. package/dist/op/activities/index.d.ts.map +1 -1
  20. package/dist/op/activities/machines-contract.d.ts +36 -0
  21. package/dist/op/activities/machines-contract.d.ts.map +1 -0
  22. package/dist/op/activities/sprites-contract.d.ts +45 -0
  23. package/dist/op/activities/sprites-contract.d.ts.map +1 -0
  24. package/dist/op/activities/sprites-emulator.d.ts +29 -0
  25. package/dist/op/activities/sprites-emulator.d.ts.map +1 -0
  26. package/dist/op/activities/sprites-fake.d.ts +62 -0
  27. package/dist/op/activities/sprites-fake.d.ts.map +1 -0
  28. package/dist/op/activities/sprites.d.ts +195 -0
  29. package/dist/op/activities/sprites.d.ts.map +1 -0
  30. package/dist/plugin.d.ts.map +1 -1
  31. package/dist/reference-catalog.d.ts +21 -0
  32. package/dist/reference-catalog.d.ts.map +1 -0
  33. package/package.json +6 -2
  34. package/src/composites/fly-deploy.ts +1 -1
  35. package/src/coverage.ts +49 -0
  36. package/src/emulator-freshness-cli.ts +49 -0
  37. package/src/emulator-freshness.test.ts +86 -0
  38. package/src/emulator-freshness.ts +87 -0
  39. package/src/index.ts +15 -0
  40. package/src/mcp/context-tools.test.ts +27 -0
  41. package/src/mcp/context-tools.ts +120 -0
  42. package/src/op/activities/emulator-images.ts +21 -0
  43. package/src/op/activities/flaps.test.ts +2 -1
  44. package/src/op/activities/flaps.ts +3 -2
  45. package/src/op/activities/index.ts +53 -0
  46. package/src/op/activities/machines-contract.docker.integration.test.ts +72 -0
  47. package/src/op/activities/machines-contract.test.ts +49 -0
  48. package/src/op/activities/machines-contract.ts +73 -0
  49. package/src/op/activities/sprites-contract.docker.integration.test.ts +74 -0
  50. package/src/op/activities/sprites-contract.test.ts +60 -0
  51. package/src/op/activities/sprites-contract.ts +61 -0
  52. package/src/op/activities/sprites-emulator.ts +46 -0
  53. package/src/op/activities/sprites-fake.ts +314 -0
  54. package/src/op/activities/sprites.docker.integration.test.ts +99 -0
  55. package/src/op/activities/sprites.integration.test.ts +158 -0
  56. package/src/op/activities/sprites.real.test.ts +56 -0
  57. package/src/op/activities/sprites.test.ts +296 -0
  58. package/src/op/activities/sprites.ts +527 -0
  59. package/src/plugin.ts +28 -5
  60. package/src/reference-catalog.test.ts +50 -0
  61. package/src/reference-catalog.ts +39 -0
  62. package/src/skills/chant-fly-patterns.md +2 -2
  63. package/src/skills/chant-fly-sprites.md +104 -0
  64. package/src/skills/chant-fly.md +2 -2
  65. package/src/generated/.gitkeep +0 -0
@@ -15,9 +15,9 @@ Beyond the App and Machine covered in `chant-fly`, the lexicon models `Volume`,
15
15
  The FLY011 build check enforces the link statically: every machine mount must reference a `Volume` declared in the stack, checked across files. A mount that points at an undeclared volume fails `chant build` before anything reaches the API.
16
16
 
17
17
  ```ts
18
- import { App, Machine, MachineConfig, MachineGuest, Volume } from "@intentius/chant-lexicon-fly";
18
+ import { App, Machine, MachineConfig, MachineGuest, Volume, Fly } from "@intentius/chant-lexicon-fly";
19
19
 
20
- export const app = new App({ name: "my-app" });
20
+ export const app = new App({ name: "my-app", org_slug: Fly.OrgSlug });
21
21
 
22
22
  export const data = new Volume({ name: "data", region: "iad", size_gb: 10 });
23
23
 
@@ -0,0 +1,104 @@
1
+ ---
2
+ skill: chant-temporal-sprites
3
+ description: Run an agent task in a Sprite as a chant Op — create, exec, checkpoint, restore, and destroy, with checkpoint-as-compensation
4
+ user-invocable: true
5
+ ---
6
+
7
+ # Run an Agent Task in a Sprite
8
+
9
+ [Sprites](https://sprites.dev) are stateful, checkpointable sandboxes. Unlike a resource lexicon, a Sprite has no desired state to reconcile: it is a runtime-orchestration primitive, the same category as `k3dUp` or `httpCheck`. So the sprite lifecycle lives in chant's Op and activity layer, not in a declarative resource type.
10
+
11
+ This is the direct-API, Op-driven way to drive a Sprite: a structured, replayable activity sequence that a chant Op can checkpoint and roll back. It sits alongside the Sprites SDKs and CLI rather than replacing them, and it is not an MCP wrapper.
12
+
13
+ ## The five activities
14
+
15
+ Each activity is a direct REST call over an injectable HTTP client, imported from `@intentius/chant-lexicon-fly` (Sprites are a Fly product, so they live in the fly lexicon alongside Machines):
16
+
17
+ | Activity | What it does |
18
+ |----------|--------------|
19
+ | `spriteCreate` | Create a sandbox. The caller-chosen `name` becomes the sprite `id` that every later activity keys on |
20
+ | `spriteExec` | Run a command inside the sprite. A non-zero exit throws, so the phase fails and any `onFailure` compensation runs |
21
+ | `spriteCheckpoint` | Snapshot the sprite under a caller-chosen `label` |
22
+ | `spriteRestore` | Rewind the sprite to a labeled checkpoint |
23
+ | `spriteDestroy` | Destroy the sprite (idempotent; an already-gone sprite is a no-op) |
24
+
25
+ The sprite `id` and the checkpoint `label` are static strings the Op author writes, so nothing has to be threaded from a prior phase's output.
26
+
27
+ ## The happy path
28
+
29
+ Compose the activities into an Op as phases:
30
+
31
+ ```ts
32
+ import { Op, phase } from "@intentius/chant-lexicon-temporal";
33
+ import { spriteCreate, spriteCheckpoint, spriteExec, spriteDestroy }
34
+ from "@intentius/chant-lexicon-fly";
35
+
36
+ export default Op({
37
+ name: "agent-task",
38
+ overview: "Create a sprite, checkpoint, run the task, verify, destroy",
39
+ taskQueue: "sprites",
40
+ phases: [
41
+ phase("Create", [spriteCreate({ name: "task-1", image: "sprites/base:latest" })]),
42
+ phase("Checkpoint", [spriteCheckpoint({ id: "task-1", label: "pre-run" })]),
43
+ phase("Run", [spriteExec({ id: "task-1", cmd: "echo hello > /work/output" })]),
44
+ phase("Verify", [spriteExec({ id: "task-1", cmd: "cat /work/output" })]),
45
+ phase("Destroy", [spriteDestroy({ id: "task-1" })]),
46
+ ],
47
+ });
48
+ ```
49
+
50
+ There is no `build` phase and no serialized plan: the activities run in sequence. Run it with `chant run agent-task`.
51
+
52
+ ## Checkpoint-as-compensation
53
+
54
+ The reason Sprites map onto chant Ops so well is rollback. A VM checkpoint is a fast transactional boundary. An Op checkpoints before a risky phase and, on failure, restores the labeled checkpoint instead of running an inverse action. The environment itself is the transaction, so there is nothing to unwind by hand.
55
+
56
+ Put the `spriteRestore` in the Op's `onFailure`, referencing the same label the `Checkpoint` phase wrote:
57
+
58
+ ```ts
59
+ import { Op, phase } from "@intentius/chant-lexicon-temporal";
60
+ import { spriteCreate, spriteCheckpoint, spriteExec, spriteDestroy, spriteRestore }
61
+ from "@intentius/chant-lexicon-fly";
62
+
63
+ export default Op({
64
+ name: "guarded-task",
65
+ overview: "Checkpoint, run a risky step, restore on failure",
66
+ taskQueue: "sprites",
67
+ phases: [
68
+ phase("Create", [spriteCreate({ name: "task-1" })]),
69
+ phase("Checkpoint", [spriteCheckpoint({ id: "task-1", label: "pre-run" })]),
70
+ phase("Run", [spriteExec({ id: "task-1", cmd: "./risky.sh" })]),
71
+ phase("Destroy", [spriteDestroy({ id: "task-1" })]),
72
+ ],
73
+ onFailure: [
74
+ phase("Restore", [spriteRestore({ id: "task-1", checkpoint: "pre-run" })]),
75
+ ],
76
+ });
77
+ ```
78
+
79
+ When the `Run` phase's command exits non-zero, `spriteExec` throws, the phase fails, and the Op-level `onFailure` `Restore` rewinds the sprite to its `pre-run` checkpoint.
80
+
81
+ ## Targeting the emulator or real Sprites
82
+
83
+ The activities resolve their endpoint in this order: an explicit `endpoint` arg, then `SPRITES_BASE_URL`, then the real Sprites base. The same Op targets an emulator or real Sprites with no code change. The default `fetch` client adds `Authorization: Bearer ${SPRITES_API_TOKEN}` when a token is set; the emulator ignores it.
84
+
85
+ ```bash
86
+ # Point at a self-hosted or in-process emulator.
87
+ export SPRITES_BASE_URL=http://127.0.0.1:9000
88
+ chant run agent-task
89
+ ```
90
+
91
+ ```bash
92
+ # Real Sprites: drop the override and set a token.
93
+ unset SPRITES_BASE_URL
94
+ export SPRITES_API_TOKEN=...
95
+ chant run agent-task
96
+ ```
97
+
98
+ The offline, Docker-free emulator that CI runs against is `createSpritesFake()` in this lexicon (`src/op/activities/sprites-fake.ts`); the activities and their tests live alongside it in `sprites.ts`. The local-emulator flow is the one to develop against.
99
+
100
+ The real Sprites REST surface is provisional (S6, tracked in #766): the endpoint constants may still move to match the official API. The activity input and output contracts (the `Args` and `Result` shapes shown above) are the stable interface the Ops and the emulator are written against, so build your Ops on those.
101
+
102
+ ## Where it fits
103
+
104
+ The runnable starter is [`examples/sprites-agent-task`](../../examples/sprites-agent-task), which ships both Ops above. Run `chant run agent-task` for the happy path and `chant run guarded-task` to watch the checkpoint-as-compensation rollback. `guarded-task` exits non-zero on purpose: the `Run` phase fails, the `onFailure` `Restore` runs, and the sprite is back at `pre-run`.
@@ -40,9 +40,9 @@ That Op runs the phases boot, build, apply, verify, and teardown against a local
40
40
  Import resource types from `@intentius/chant-lexicon-fly`. They are generated from Fly's Machines API OpenAPI spec, so `MachineConfig` is typed all the way down through guest, services, mounts, and checks.
41
41
 
42
42
  ```ts
43
- import { App, Machine, MachineConfig, MachineGuest } from "@intentius/chant-lexicon-fly";
43
+ import { App, Machine, MachineConfig, MachineGuest, Fly } from "@intentius/chant-lexicon-fly";
44
44
 
45
- export const app = new App({ name: "my-app" });
45
+ export const app = new App({ name: "my-app", org_slug: Fly.OrgSlug });
46
46
 
47
47
  export const web = new Machine({
48
48
  name: "web",
File without changes