@everfir/az8-cli 0.2.0 → 0.3.0-preview.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everfir/az8-cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-preview.2",
4
4
  "description": "Semantic Project Canvas client for AZ8 Studio agents.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -16,10 +16,10 @@
16
16
  "main": "./dist/main.js",
17
17
  "publishConfig": {
18
18
  "access": "public",
19
- "tag": "latest"
19
+ "tag": "preview"
20
20
  },
21
21
  "scripts": {
22
- "build": "pnpm build:dependencies && rm -rf dist && esbuild src/main.ts --bundle --platform=node --format=esm --target=node20 --banner:js='import { createRequire } from \"node:module\"; const require = createRequire(import.meta.url);' --outfile=dist/main.js",
22
+ "build": "pnpm build:dependencies && rm -rf dist && esbuild src/main.ts --bundle --platform=node --format=esm --target=node22.12 --banner:js='import { createRequire } from \"node:module\"; const require = createRequire(import.meta.url);' --outfile=dist/main.js",
23
23
  "build:dependencies": "pnpm --filter @everfir/az8-cli^... build",
24
24
  "dev": "tsx src/main.ts",
25
25
  "start": "node dist/main.js",
@@ -48,9 +48,11 @@
48
48
  "yjs": "^13.6.30"
49
49
  },
50
50
  "engines": {
51
- "node": ">=20"
51
+ "node": ">=22.12.0"
52
52
  },
53
53
  "dependencies": {
54
- "file-type": "^21.3.4"
54
+ "commander": "^15.0.0",
55
+ "file-type": "^21.3.4",
56
+ "zod": "^4.4.3"
55
57
  }
56
58
  }
@@ -11,8 +11,9 @@ capabilities instead of guessing operation names or input shapes.
11
11
 
12
12
  ## Contract
13
13
 
14
- - Use only public `az8 projects` and `az8 canvas` commands. Never mutate backend records, Yjs,
15
- Collaborative Document fields, Core Node payloads, or Project Content bindings directly.
14
+ - Use only public `az8 projects`, `az8 session`, and `az8 canvas` commands. Never mutate backend
15
+ records, Yjs, Collaborative Document fields, Core Node payloads, or Project Content bindings
16
+ directly.
16
17
  - Explicitly select `test` or `production`. Never infer authorization to write production data.
17
18
  - Read the relevant Canvas facts before planning a write. Submit one semantic Operation at a time.
18
19
  - Treat every accepted write as a blocker: wait for its terminal Receipt before issuing any later
@@ -33,7 +34,13 @@ capabilities instead of guessing operation names or input shapes.
33
34
  has its own connection, lifecycle, projection, History, Receipt Log, and Awareness identity.
34
35
  - **View Node** is a Canvas placement: note, group, or resource target with position, size, parent,
35
36
  stacking, Draft, and presentation state.
36
- - **Core Node** is immutable or server-owned creative content such as an image, video, or audio.
37
+ - **Note** is a sticky Canvas annotation. Its content uses `createNote` and `editNoteContent`; its
38
+ optional accent uses `setNoteColor` with only `blue`, `orange`, `red`, `gold`, `purple`, or
39
+ `green`. A Note is not a Text Resource.
40
+ - **Text Resource** is creative text content. Use `createTextNode` and `editTextContent` for manual
41
+ text, or `createGenerationTarget` with `contentType: "text"` for generated text. Do not represent
42
+ requested Text content by creating a Note.
43
+ - **Core Node** is immutable or server-owned creative content such as text, image, video, or audio.
37
44
  Resource View Nodes resolve Core Nodes through Project Content. Do not manufacture Core Nodes or
38
45
  bindings.
39
46
  - **Project Content** is the authority that associates a View Node target with its effective Core
@@ -99,12 +106,22 @@ capabilities instead of guessing operation names or input shapes.
99
106
 
100
107
  Retain the returned Project ID. Confirm the authenticated role before assuming write access.
101
108
 
102
- 4. Discover the effective surface for that Project:
109
+ 4. Choose the Canvas carrier before discovery. If the task may perform any Canvas write, open one
110
+ daemon-backed Agent Collaboration Session now and retain it through the authoring task:
103
111
 
104
112
  ```bash
105
- az8 canvas query <project-id> capabilities.summary
106
- az8 canvas query <project-id> capabilities.detail
107
- az8 canvas query <project-id> canvas.summary
113
+ az8 session open <project-id> --environment test
114
+ az8 session query capabilities.summary
115
+ az8 session query capabilities.detail
116
+ az8 session query canvas.summary
117
+ ```
118
+
119
+ For an isolated read-only task, use the process-independent query instead and do not open a
120
+ Session merely to retain unused state:
121
+
122
+ ```bash
123
+ az8 canvas query <project-id> capabilities.summary --environment test
124
+ az8 canvas query <project-id> canvas.summary --environment test
108
125
  ```
109
126
 
110
127
  `capabilities.summary` is the short menu. `capabilities.detail` is authoritative for exact JSON
@@ -114,59 +131,82 @@ capabilities instead of guessing operation names or input shapes.
114
131
  5. Use `canvas.detail` only when exact node geometry, Draft, status, or bindings are needed:
115
132
 
116
133
  ```bash
117
- az8 canvas query <project-id> canvas.detail --view-node-id <view-node-id>
134
+ az8 session query canvas.detail --view-node-id <view-node-id>
118
135
  ```
119
136
 
120
- 6. If the task may perform any Canvas write, open one persistent stdio client before the first
121
- Canvas read or write and retain it through the authoring session. Use one-shot only under the
122
- explicit exceptions below. Finish by inspecting the affected View Nodes or Workflow Run rather
123
- than trusting visual assumptions.
137
+ For the isolated read-only carrier, use `az8 canvas query <project-id> canvas.detail` with the
138
+ same selector. Opening a Session selects it for the current canonical working directory, so
139
+ later Session commands do not repeat its ID. Finish by inspecting affected View Nodes or
140
+ Workflow Runs, then close any opened Session rather than trusting visual assumptions.
124
141
 
125
142
  ## Interaction modes
126
143
 
127
- Default to persistent stdio for Canvas authoring. A one-write plan still uses persistent stdio. This
128
- is the normal mode whenever a task may create, edit, move, organize, remove, undo, generate, import,
129
- or upload Canvas content. Open the client once, use it for capability discovery and subsequent reads
130
- and Operations, observe concurrent changes, and shut it down only after the Canvas task is complete:
144
+ Default to a daemon-backed Agent Collaboration Session for Canvas authoring. A one-write plan still
145
+ uses a Session. This is the normal mode whenever a task may create, edit, move, organize, remove,
146
+ undo, generate, import, or upload Canvas content. One private local daemon retains the authenticated
147
+ connection, Awareness, History, Receipts, Interests, and Watch Journal across ordinary short CLI
148
+ calls:
131
149
 
132
150
  ```bash
133
- az8 canvas open <project-id> --write --format ndjson
151
+ az8 session open <project-id> --environment test
152
+ az8 session current
153
+ az8 session status
134
154
  ```
135
155
 
136
156
  Use `--client-name <suffix>` only when a more specific CLI presence label helps collaborators. The
137
157
  CLI owns the surrounding parentheses, rejects parentheses in the supplied suffix, and always keeps
138
158
  the authenticated user display name first.
139
159
 
140
- 1. Continuously drain stdout; it is an ordered NDJSON protocol stream and may apply backpressure.
141
- 2. Read `hello`, select protocol `1.0`, then send `initialize` for the same Project ID.
142
- 3. Wait for `ready` before any query or Operation.
143
- 4. Keep exactly one reader for stdout. Parse each frame by `type`, `requestId`, and `streamSeq`.
144
- 5. Use `compact` observations by default. Query `awareness.detail` when cursor context is needed;
145
- cursor coordinates are intentionally not streamed.
146
- 6. On an observation gap, query summary/detail and rebuild the local view.
147
- 7. Send `shutdown` and wait for ordered completion. EOF or a signal is emergency cleanup, not a
148
- cancellation or rollback mechanism.
149
-
150
- Protocol truth is written to stdout. stderr contains diagnostics only. Unknown optional fields are
151
- additive; ignore them. Do not treat a process exit code as the result of the last persistent request.
152
-
153
- Treat the persistent process lifetime and each request lifetime separately:
154
-
155
- - Keep the process running between requests. Decide request completion only from the matching
156
- `requestId` and its `requestCompleted` or `requestFailed` frame; never wait for process exit.
157
- - Treat `requestAccepted` as admission only. For a write, wait for its terminal Receipt before
158
- issuing the next query or Operation.
159
- - Continuously drain and parse stdout, but do not repeatedly poll an idle process merely to make it
160
- produce output. No new frame is a normal healthy state when no lifecycle, request, Canvas, or
161
- Workflow fact changed.
162
- - Do not interpret a shell/agent-host read window ending with no output (for example, a 30-second
163
- terminal yield) as CLI latency, request timeout, or connection failure. Check request terminal
164
- frames and lifecycle/health facts instead.
165
- - Keep one connected client for related work. Reopening one-shot clients repeatedly pays connection,
166
- synchronization, and hydration cost each time and loses local History, Receipts, and presence.
167
- - Remember that the current persistent protocol processes requests serially. A long
168
- `waitWorkflowRun` occupies the request lane until the Run becomes terminal or its observation
169
- window ends; submit it only when no other request needs that lane.
160
+ Session resolution is explicit and discoverable. A command-level `--session <id>` wins, then
161
+ `AZ8_SESSION_ID`, then the current Session for the local context. Use `AZ8_CONTEXT` to separate
162
+ parallel Agents intentionally sharing one working directory. `session list`, `current`, `status`,
163
+ and `use` must be used whenever the binding is uncertain; never guess a Session or Project.
164
+
165
+ Configure named semantic Interests once, then use the singular blocking Watch instead of polling:
166
+
167
+ ```bash
168
+ az8 session interests patch --input-json '{"upsert":[{"key":"canvas-ambient","patch":{"kind":"canvas"}},{"key":"workflow-terminal","patch":{"kind":"workflow"}}]}'
169
+ az8 session watch --timeout-ms 30000
170
+ ```
171
+
172
+ - Canvas Interests exclude the Session's own changes unless `includeOwn: true` is explicit.
173
+ - Workflow Interests are terminal-only unless progress status is explicitly requested.
174
+ - `idle` ends one observation window normally. It does not indicate a failed connection or Run.
175
+ - `resync-required` means bounded continuity was lost. Query authoritative summary/detail, then run
176
+ `az8 session resynchronize`; never pretend the missing interval was observed.
177
+ - Exactly one consumer may wait on a Session. The daemon does not wake or restart an Agent that has
178
+ exited; it only completes an active `session watch` call.
179
+ - Watch acknowledgement is internal. If stdout delivery is interrupted before confirmation, the
180
+ same result may repeat. Treat repeat delivery as at-least-once readiness, not a new business fact.
181
+ - Queries wait behind an executing write. Watch collection remains independent of the write lane.
182
+
183
+ For a bounded human–Agent latency check, report readiness first, start
184
+ `az8 session watch --timeout-ms 60000`, and ask the human to make one recognizable Web Canvas change
185
+ only after the wait is active. Acknowledge the returned semantic change immediately, then wait again
186
+ for the next trial. `result.timing.waitedMs` measures the blocking window and each change's
187
+ `quietForMs` measures local observation-to-delivery delay; neither includes speech recognition or
188
+ Agent-host scheduling. Do not infer an end-to-end latency number from either field alone.
189
+
190
+ Execute reads and writes through the selected Session:
191
+
192
+ ```bash
193
+ az8 session query canvas.detail --view-node-id <view-node-id>
194
+ az8 session operation createNote --request-id <unique-id> \
195
+ --input-json '{"name":"Plan","content":"...","position":{"x":80,"y":80}}'
196
+ az8 session query receipt.detail --receipt-request-id <unique-id>
197
+ ```
198
+
199
+ Every Session Operation returns one terminal Receipt. Keep writes sequential and stop after the
200
+ first failed or indeterminate Receipt. Close the Session explicitly when collaboration is complete:
201
+
202
+ ```bash
203
+ az8 session close
204
+ ```
205
+
206
+ `az8 canvas open <project-id> --write --format ndjson` remains the lower-level persistent stdio
207
+ surface for a host that deliberately owns and continuously drains one child process. It has the
208
+ same semantic capabilities, but ordinary Agents should prefer `az8 session` and should not manually
209
+ implement its daemon behavior.
170
210
 
171
211
  Use one-shot only for:
172
212
 
@@ -174,12 +214,12 @@ Use one-shot only for:
174
214
  - a standalone media download;
175
215
  - an explicitly standalone upload/import whose caller does not want an ongoing authoring session;
176
216
  - an explicit user request for one-shot behavior; or
177
- - a host that genuinely cannot retain a child process and write later NDJSON to its stdin.
217
+ - a platform that cannot run the local Session daemon or persistent stdio carrier.
178
218
 
179
219
  Do not choose one-shot merely because the current plan has one write or because it requires fewer
180
- tool calls. Codex and other hosts with retained process sessions can use persistent stdio. If a host
181
- limitation forces fallback, disclose that the client will not preserve local History, Receipt Log,
182
- Awareness, observations, or request replay across invocations.
220
+ tool calls. Codex and ordinary shell hosts can use daemon-backed Sessions without retaining stdin.
221
+ If a host limitation forces fallback, disclose that the client will not preserve local History,
222
+ Receipt Log, Awareness, observations, or request replay across invocations.
183
223
 
184
224
  For a permitted one-shot call, supply Operation input through exactly one of `--input-stdin`,
185
225
  `--input-file`, or `--input-json`, give every write a meaningful unique `--request-id`, and retain its
@@ -190,15 +230,24 @@ one-shot processes.
190
230
 
191
231
  1. Query `canvas.summary`; query selected details only as needed.
192
232
  2. Query `capabilities.detail` and validate the planned Operation input against its schema.
193
- 3. Pick explicit absolute Canvas coordinates. Public move positions remain absolute even for group
233
+ 3. When artifact type and placement are already clear, make the first meaningful Canvas state
234
+ visible before doing lengthy prompt refinement or generation planning:
235
+ - create the empty generation target first, then plan and edit its Draft;
236
+ - create an empty manual Text Resource with `text: ""`, then fill it with
237
+ `editTextContent`;
238
+ - create a Note with its useful content directly rather than creating an empty sticky.
239
+ Do not create a placeholder while its type or placement is still ambiguous. Watch and the
240
+ Session daemon never create placeholders automatically.
241
+ 4. Pick explicit absolute Canvas coordinates. Public move positions remain absolute even for group
194
242
  children.
195
- 4. Submit one Operation with a new request ID and wait for its terminal Receipt.
196
- 5. Confirm the Receipt outcome and affected IDs, then query the changed View Node when subsequent
243
+ 5. Submit one Operation with a new request ID and wait for its terminal Receipt.
244
+ 6. Confirm the Receipt outcome and affected IDs, then query the changed View Node when subsequent
197
245
  work depends on its exact state.
198
- 6. Only then plan the next interaction.
246
+ 7. Only then plan the next interaction.
199
247
 
200
- Common capabilities include notes, move/resize/rename, duplicate/remove, groups and stacking, Core
201
- Node placement, and media targets. The runtime catalog is authoritative. Group nodes cannot nest;
248
+ Common capabilities include notes, manual Text Resources, move/resize/rename, duplicate/remove,
249
+ groups and stacking, Core Node placement, and generation targets. The runtime catalog is
250
+ authoritative. Group nodes cannot nest;
202
251
  stacking applies only among siblings. Unsupported World, Decoration, Asset, alignment, and automatic
203
252
  layout behavior must not be simulated through lower-level writes.
204
253
 
@@ -210,13 +259,30 @@ entries. Never use compensating low-level mutations to imitate undo.
210
259
 
211
260
  Generation is an explicit sequence, never one transaction:
212
261
 
213
- 1. Create a target with `createMediaTarget` and retain its View Node ID.
262
+ 1. Create a target with `createGenerationTarget` and retain its View Node ID. It accepts `audio`,
263
+ `image`, `text`, or `video`; `createMediaTarget` remains a compatibility capability for non-text
264
+ targets when advertised.
214
265
  2. Call the read-only `planGeneration` Operation with the target, prompt, and any references. Use
215
266
  `detail: "detail"` when configuration fields or dynamic enum options are needed.
267
+ Every reference must be `{ "viewNodeId": "..." }`. If the desired Core Node is not currently
268
+ on the Canvas, first call `placeCoreNode`, wait for its successful Receipt, and use the returned
269
+ View Node ID. Never pass a Core Node ID as a generation reference or silently choose among
270
+ multiple placements of the same Core Node. A manual Text Resource is also a valid reference:
271
+ pass its View Node ID instead of copying its text into `prompt`. Planning reads its current text,
272
+ the Draft retains the View Node binding for Web lineage and connection rendering, and
273
+ `startGeneration` materializes the Text Core Node only after estimation succeeds. The stable
274
+ operation names `addVisualReference` and `removeVisualReference` cover these planned Text
275
+ bindings as well as image/video bindings; execute the names returned by the plan rather than
276
+ interpreting them literally.
216
277
  3. If the plan reports blocking issues, resolve them and plan again. Do not execute a non-ready
217
278
  plan.
218
279
  4. Execute `plan.operations` exactly in order, one Operation at a time. Each step revalidates
219
280
  current facts. Stop after the first non-success.
281
+ When a reference must also appear at a meaningful Prompt position, use
282
+ `insertPromptReference` with the target View Node, visible reference View Node, and
283
+ `placement: "start"` or `"end"`. The CLI creates and validates the binding and At token
284
+ atomically. Do not write `{{@...}}`, choose an input slot/index, or allocate a binding ID
285
+ yourself. `addVisualReference` remains the connection-only operation.
220
286
  5. `startGeneration` succeeds when the Workflow Run is accepted and immediate Canvas effects are
221
287
  acknowledged. This completes the start interaction; it does not mean generation finished.
222
288
  6. Retain the Workflow Run ID. After the successful start Receipt, continue any work that does not
@@ -230,6 +296,19 @@ Generation is an explicit sequence, never one transaction:
230
296
  8. On terminal success, query the target detail and resolve its current output Core Node through
231
297
  Project Content before downloading or placing it elsewhere.
232
298
 
299
+ If `startGeneration` returns an indeterminate Receipt after the Workflow was accepted, retain
300
+ `receipt.result.workflowRunId` and `receipt.result.viewNodeId`, reconnect the Session, and invoke
301
+ `reconcileGenerationStart` with those two identities. Never call `startGeneration` again for that
302
+ intent. `running-insufficient` means the Run is still authoritative but does not yet expose enough
303
+ target evidence: wait and reconcile later. `repaired` means the CLI restored the missing Canvas
304
+ launch facts through the semantic Command path. `conflict` or `insufficient` requires inspection;
305
+ neither authorizes a retry.
306
+
307
+ A Workflow Interest performs an authoritative status catch-up for Run IDs already known to the
308
+ Session; explicit `filter.runIds` narrows or restores that set when needed. This closes
309
+ missed-live-event races and delivers each unchanged terminal fact once. Keep explicit Run ID filters
310
+ current across handoffs; the daemon does not scan unrelated Workflow Runs.
311
+
233
312
  Workflow Definitions change over time. Query `workflowDefinitions.summary`, then
234
313
  `workflowDefinition.detail` only when planning detail is insufficient. Never guess a Definition,
235
314
  configuration option, modality, cost, or media compatibility from its display name.
@@ -338,8 +417,8 @@ Before reporting a task complete, verify all applicable facts:
338
417
  - Generation start and generation completion were reported as separate interactions; the target's
339
418
  effective Core Node was resolved after completion.
340
419
  - Media transfers were verified by identities and checksums without exposing URLs or credentials.
341
- - Persistent stdio was shut down in order, or any abnormal termination and uncertain active write
342
- was disclosed.
420
+ - The daemon-backed Session was closed explicitly (or persistent stdio was shut down in order), and
421
+ any abnormal termination or uncertain active write was disclosed.
343
422
  - Deferred scopes were not approximated by bypassing the public semantic surface.
344
423
 
345
424
  When any item cannot be proven, report the uncertainty and the next safe read or reconciliation