@cleocode/cant 2026.11.11 → 2026.11.12

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 (2) hide show
  1. package/README.md +161 -114
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -2,16 +2,18 @@
2
2
 
3
3
  > Part of [CLEO](https://github.com/kryptobaseddev/cleo#readme). Start with the root README; run `cleo <command> --help` for any command.
4
4
 
5
- CANT protocol parser, validator, and runtime for the CLEO ecosystem. Wraps the
6
- Rust [`cant-core`](../../crates/cant-core) crate via [napi-rs](https://napi.rs)
7
- so TypeScript consumers get the full Rust validator (42 static-analysis rules)
8
- and pipeline executor without spawning a separate process.
5
+ CANT parser, validator, pipeline runner and agent-bundle compiler for CLEO.
6
+ Wraps the Rust [`cant-core`](../../crates/cant-core) crate through
7
+ [napi-rs](https://napi.rs) (`crates/cant-napi`), so TypeScript callers get the
8
+ Rust parser and validator, and deterministic pipeline execution, without
9
+ spawning a separate process.
9
10
 
10
11
  CANT is a constrained agent specification language: agents, protocol
11
- constraints, typed tokens, deterministic pipelines, and orchestration
12
- workflows (sessions, parallel arms, conditionals, approval gates, repeat
13
- loops, try/catch). The format is whitespace-significant Markdown with
14
- typed frontmatter.
12
+ constraints, typed tokens, deterministic pipelines and orchestration
13
+ workflows (sessions, parallel arms, conditionals, approval gates, loops,
14
+ try/catch). Files are indentation-based with typed frontmatter. **Only
15
+ pipelines execute**: workflow constructs parse and validate, but no workflow
16
+ engine ships (see [Execution](#execution)).
15
17
 
16
18
  ## Install
17
19
 
@@ -19,73 +21,91 @@ typed frontmatter.
19
21
  pnpm add @cleocode/cant
20
22
  ```
21
23
 
22
- The package bundles pre-built napi binaries for every supported platform, with
23
- a WebAssembly (WASI) fallback for the rest — see
24
+ The package bundles pre-built napi binaries for every supported platform,
25
+ with a WebAssembly (WASI) fallback for the rest. See
24
26
  [Native binaries and the WebAssembly fallback](#native-binaries-and-the-webassembly-fallback).
25
27
 
26
- **`cant-core` is the single source of truth (SSoT) for all CANT parsing.**
27
- There is no JS-regex fallback parser in the routine code path. If the native
28
- addon is absent, `parseCANTMessage` throws a typed error unless the
29
- `CLEO_CANT_ALLOW_JS_FALLBACK=1` env-var is explicitly set (degraded mode,
30
- not for production use).
28
+ **`cant-core` is the single source of truth for CANT parsing.** There is no
29
+ JS-regex parser in the routine path: when the addon cannot load,
30
+ `parseCANTMessage` throws unless `CLEO_CANT_ALLOW_JS_FALLBACK=1` is set
31
+ (degraded mode that warns on every call; not for production).
31
32
 
32
- ## Public API
33
+ ## TypeScript API
34
+
35
+ All exports come from the package root (`src/index.ts`).
36
+
37
+ ### Documents: parse, validate, list, execute
33
38
 
34
39
  ```ts
35
40
  import {
36
- parseDocument,
37
- validateDocument,
38
41
  executePipeline,
39
42
  listSections,
40
- migrateMarkdown,
41
- serializeCantDocument,
42
- initCantParser,
43
- parseCANTMessage,
43
+ parseDocument,
44
+ validateDocument,
44
45
  } from '@cleocode/cant';
45
- ```
46
46
 
47
- ### `parseDocument(filePath: string): Promise<CantDocument>`
47
+ const parsed = await parseDocument('agent.cant');
48
+ // { file, success, document, errors }
48
49
 
49
- Parses a `.cant` file into a structured AST. The AST mirrors the Rust
50
- canonical types from [`crates/cant-core/src/dsl/ast.rs`](../../crates/cant-core/src/dsl/ast.rs).
51
-
52
- ### `validateDocument(filePath: string): Promise<CantValidationResult>`
50
+ const report = await validateDocument('agent.cant');
51
+ // { file, valid, total, errorCount, warningCount, diagnostics }
52
+ for (const d of report.diagnostics) {
53
+ console.log(`${d.severity} ${d.ruleId}: ${d.message} (${d.line}:${d.col})`);
54
+ }
53
55
 
54
- Runs the 42-rule static-analysis validator. Returns a structured result with
55
- per-diagnostic line/column coordinates and severity levels:
56
+ const names = await listSections('team.cant', 'pipeline'); // 'agent' | 'pipeline' | 'workflow'
57
+ // { file, filter, count, names }
56
58
 
57
- ```ts
58
- interface CantValidationResult {
59
- valid: boolean;
60
- errorCount: number;
61
- warningCount: number;
62
- diagnostics: NativeDiagnostic[];
63
- }
59
+ const run = await executePipeline('build.cant', 'checks');
60
+ // { file, pipeline, success, durationMs, steps, error }
64
61
  ```
65
62
 
66
- Used by `cleo cant validate` (and by the deprecated `caamp pi cant validate`
67
- and `caamp pi cant install`, which retire with the Pi harness under ADR-098) to
68
- reject invalid `.cant` files before they hit the runtime.
63
+ These four functions read the file, normalize CRLF to LF, and call the native
64
+ binding (`src/document.ts`). `parseDocument` returns the cant-core AST as
65
+ `document` (typed `unknown`; the Rust types are in
66
+ [`crates/cant-core/src/dsl/ast.rs`](../../crates/cant-core/src/dsl/ast.rs)).
67
+ Each diagnostic carries `ruleId`, `message`, `severity` (`error`, `warning`,
68
+ `info` or `hint`), `line` and `col`. Each pipeline step reports `name`,
69
+ `exitCode`, `stdoutLen`, `stderrLen`, `durationMs` and `skipped`.
69
70
 
70
- ### `executePipeline(filePath: string, pipelineName: string): Promise<JsPipelineResult>`
71
+ The CLI wraps them: `cleo cant parse <file>`, `cleo cant validate <file>`,
72
+ `cleo cant list <file>` and `cleo cant execute <file> --pipeline <name>`.
71
73
 
72
- Runs a deterministic pipeline by name from a `.cant` file. Pipelines are
73
- the executable subset of CANT — declarative steps with explicit inputs,
74
- outputs, and exit codes. Workflow constructs (sessions, parallel arms,
75
- conditionals, etc.) are not executed by this package; the only interpreter is
76
- the [`cant-bridge.ts`](../cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts)
77
- Pi extension, which retires with the Pi/CleoOS harness (ADR-098).
74
+ ### Bundles: `compileBundle`
78
75
 
79
- ### `migrateMarkdown(input: string): MigrateResult`
76
+ ```ts
77
+ import { compileBundle } from '@cleocode/cant';
78
+
79
+ const bundle = await compileBundle([
80
+ '/project/.cleo/cant/agents/backend-dev.cant',
81
+ '/project/.cleo/cant/agents/frontend-dev.cant',
82
+ ]);
83
+
84
+ bundle.valid; // true only if every file parsed and has no error diagnostics
85
+ bundle.agents; // TypedAgentEntry[]: name, sourcePath, properties, typed (CantAgentV3 | null)
86
+ bundle.teams; // TeamEntry[]
87
+ bundle.tools; // ToolEntry[]
88
+ bundle.diagnostics; // BundleDiagnostic[] from parse errors and validation
89
+ bundle.renderSystemPrompt(); // the bundle as a system-prompt addendum
90
+ ```
80
91
 
81
- Converts legacy markdown agent definitions to canonical `.cant` format.
82
- Used by `cleo cant migrate` to bring pre-CANT skill libraries into the
83
- new format without losing semantics.
92
+ `compileBundle` parses and validates every file. A file that fails to parse
93
+ stays in the bundle with its diagnostics but contributes no entities.
94
+ `toCantAgentV3` projects one agent entry to the typed `CantAgentV3` shape. The
95
+ provider spawn adapters (`packages/adapters/src/cant-context.ts`) use
96
+ `compileBundle` to put project `.cant` agents into spawn prompts.
84
97
 
85
- ### `parseCANTMessage(text: string): ParsedCANTMessage`
98
+ ### Messages: `parseCANTMessage`
86
99
 
87
- Parses an inline CANT message embedded in agent transcripts (used by the
88
- brain memory bridge for cross-provider transcript hooks).
100
+ Parses an inline CANT message (a directive line plus body):
101
+
102
+ ```ts
103
+ import { parseCANTMessage } from '@cleocode/cant';
104
+
105
+ parseCANTMessage('/done @all T1234 #shipped');
106
+ // { directive: 'done', directive_type: 'actionable', addresses: ['all'],
107
+ // task_refs: ['T1234'], tags: ['shipped'], ... }
108
+ ```
89
109
 
90
110
  ```ts
91
111
  interface ParsedCANTMessage {
@@ -97,66 +117,93 @@ interface ParsedCANTMessage {
97
117
  header_raw: string; // first line
98
118
  body: string; // everything after the header
99
119
  }
100
-
101
- parseCANTMessage('/done @all T1234 #shipped');
102
- // { directive: 'done', directive_type: 'actionable', addresses: ['all'],
103
- // task_refs: ['T1234'], tags: ['shipped'], ... }
104
120
  ```
105
121
 
106
- Parsing goes through the cant-core addon (native or WebAssembly, see below).
107
- When neither backend loads, the call throws; set
108
- `CLEO_CANT_ALLOW_JS_FALLBACK=1` to use the degraded regex parser instead, which
109
- warns on every use. `initCantParser()` is a no-op kept for compatibility: the
110
- addon loads synchronously.
122
+ `initCantParser()` is a no-op kept for compatibility: the addon loads
123
+ synchronously.
124
+
125
+ ### Migration
126
+
127
+ `migrateMarkdown(content, inputFile, options)` converts a markdown
128
+ instruction file to `.cant` and returns a `MigrationResult`; `showDiff` and
129
+ `showSummary` render it, and `serializeCantDocument` writes the intermediate
130
+ form back to `.cant` text. `cleo cant migrate` uses them.
131
+
132
+ ### Other exports
133
+
134
+ - **Agent composition and hierarchy**: `composeSpawnPayload`, `escalateTier`,
135
+ `estimateTokens`, `TIER_CAPS`; `filterToolsForRole`, `validateSpawnRequest`,
136
+ `stripSpawnToolsForWorker` and the `*_FORBIDDEN_*` tool lists.
137
+ - **Mental models**: `createEmptyModel`, `harvestObservations`,
138
+ `consolidate`, `renderMentalModel`, and `brainContextProvider`.
139
+ - **Low-level binding**: `cantParseDocumentNative`, `cantValidateDocumentNative`,
140
+ `cantExecutePipelineNative`, `cantParseNative`, `cantClassifyDirectiveNative`,
141
+ `cantExtractAgentProfilesNative`, `extractAgentProfilesTyped`,
142
+ `extractAgentSkills`, `validateAgentCantPath`, `loadSeedAgentIdentities`,
143
+ plus `isNativeAvailable`, `cantAddonBackend` and `cantAddonBuildInfo`.
144
+
145
+ ## Validation rules
146
+
147
+ `cant-core`'s validator (`crates/cant-core/src/validate/`) numbers 42 rules:
148
+ S01–S13 (scope, imports, permissions), P01–P07 (pipeline purity), T01–T07
149
+ (types), H01–H04 (hooks) and W01–W11 (workflow limits), plus hierarchy rules.
150
+ `cleo cant validate` describes this as "the 42-rule validation suite", but
151
+ today (T14603):
152
+
153
+ - 41 of the 42 are defined; S04 has no implementation.
154
+ - `validate()` never calls the S03 (circular import) or S12 (permission
155
+ escalation) checks.
156
+ - S11 (import depth) always sees an empty import chain, so it never fires.
111
157
 
112
158
  ## Architecture
113
159
 
114
160
  ```
115
161
  ┌─────────────────────────────────────┐
116
162
  │ TypeScript consumers │
117
- │ (caamp, cleo, cant-bridge.ts) │
163
+ │ (cleo CLI, core, adapters, caamp) │
118
164
  └────────────────┬────────────────────┘
119
165
  │
120
166
  ▼
121
167
  ┌─────────────────────────────────────┐
122
168
  │ @cleocode/cant (this package) │
123
- │ src/document.ts — TS API surface │
169
+ │ src/document.ts — document API │
170
+ │ src/bundle.ts — compileBundle │
124
171
  │ src/parse.ts — message parser │
125
172
  │ src/migrate/ — markdown→cant │
173
+ │ src/native-loader.ts — binding │
126
174
  └────────────────┬────────────────────┘
127
- │ napi-rs binding
175
+ │ napi-rs binding (native or WASI)
128
176
  ▼
129
177
  ┌─────────────────────────────────────┐
130
178
  │ crates/cant-napi │
131
- │ parse_document, validate_document │
132
- │ execute_pipeline │
133
179
  └────────────────┬────────────────────┘
134
180
  │
135
181
  ▼
136
182
  ┌─────────────────────────────────────┐
137
- │ crates/cant-core (Rust) │
138
- │ AST types, parser, validator, │
139
- │ pipeline executor (deterministic) │
183
+ │ crates/cant-core + cant-runtime │
184
+ │ AST, parser, validator; │
185
+ │ deterministic pipeline executor │
140
186
  └─────────────────────────────────────┘
141
187
  ```
142
188
 
143
- The Rust core is the canonical source of truth for AST shape and
144
- validation rules. The TypeScript surface is a thin async wrapper.
189
+ The Rust core owns the AST shape and the validation rules; the TypeScript
190
+ surface is a thin wrapper.
145
191
 
146
- ## CANT execution paths
192
+ ## Execution
147
193
 
148
- There are two execution paths. Path A retires with the Pi/CleoOS harness (ADR-098, which supersedes ADR-035); Path B is the one CLEO keeps:
194
+ CLEO runs exactly one kind of `.cant` construct: deterministic pipelines,
195
+ through `executePipeline()` / `cleo cant execute <file> --pipeline <name>`.
196
+ Pipelines are declarative steps with explicit commands, inputs and exit codes,
197
+ run as subprocesses by `cant-runtime` with no LLM involvement.
149
198
 
150
- | Path | Engine | Use case |
151
- |---|---|---|
152
- | **Path A — Pi-interactive (deprecated, ADR-098)** | `cant-bridge.ts` Pi extension | User opens a Pi session and runs `/cant:load <file>` then `/cant:run <file> <workflow>` for interactive workflow execution. The Pi extension reuses this package for parsing and validation, then interprets workflow constructs (Session, Parallel, Conditional, ApprovalGate, Repeat, ForLoop, LoopUntil, TryCatch) in TypeScript using Pi's native subagent spawning. |
153
- | **Path B — Deterministic pipelines** | `executePipeline()` (this package) | Pure-data pipelines with explicit inputs and outputs. Runs synchronously inside the napi binding without LLM involvement. Used for build steps, migration scripts, validation gates. |
154
-
155
- There is no third execution engine: the legacy `@cleocode/core/cant`
156
- WorkflowExecutor was deleted in v2026.4.7 per [ADR-035 §D5](../../docs/adr/adr-035-pi-v2-v3-harness.md).
157
- ADR-098 supersedes ADR-035: once Path A retires, CLEO runs only deterministic
158
- pipelines (`cleo cant execute <file> --pipeline <name>`); CLEO Goal (ADR-097)
159
- is the autonomous driver.
199
+ No workflow engine ships. The TypeScript `WorkflowExecutor` was deleted
200
+ ([ADR-035 §D5](../../docs/adr/adr-035-pi-v2-v3-harness.md)), and ADR-098
201
+ (`cleo docs fetch adr-098-retire-the-pi-cleoos-harness`) makes CLEO a
202
+ harness-agnostic core. CLEO Goal
203
+ ([ADR-097](../../docs/adr/ADR-097-goal-protocol-ocg-runtime.md)) is CLEO's one
204
+ autonomous driver and does not execute `.cant` workflows. Sections 7.2–7.5 of
205
+ the [CANT DSL spec](../../docs/spec/cant-dsl.md) describe workflow semantics
206
+ with no shipped implementation.
160
207
 
161
208
  ## Testing
162
209
 
@@ -164,34 +211,35 @@ is the autonomous driver.
164
211
  pnpm --filter @cleocode/cant test
165
212
  ```
166
213
 
167
- Tests use real `.cant` fixtures from `crates/cant-core/fixtures/` and
168
- seed agents from `packages/agents/seed-agents/`.
214
+ Tests read fixtures from `crates/cant-core/tests/fixtures/`,
215
+ `packages/cant/tests/fixtures/` and the cleocode repository's
216
+ `.cleo/cant/agents/`.
169
217
 
170
218
  ## Native binaries and the WebAssembly fallback
171
219
 
172
- The published package bundles the cant-napi addon for every supported
173
- platform in `napi/` (T12382): native binaries for linux x64/arm64 (glibc and
174
- musl), darwin x64/arm64 and win32 x64/arm64, plus
175
- `cant.wasm32-wasi.wasm`, the same crate built for `wasm32-wasip1-threads`.
220
+ The published package bundles the cant-napi addon in `napi/` (T12382): native
221
+ binaries for linux x64/arm64 (glibc and musl), darwin x64/arm64 and win32
222
+ x64/arm64, plus `cant.wasm32-wasi.wasm`, the same crate built for
223
+ `wasm32-wasip1-threads`.
176
224
 
177
225
  **glibc floor on ARM64 Linux:** `linux-arm64-gnu` is built on GitHub's native
178
226
  `ubuntu-24.04-arm` runner, so it requires glibc ≥ 2.39 (Ubuntu 24.04+ /
179
- Debian 13+). Older ARM64 Linux loads the WebAssembly build instead (the
180
- fallback below), and the native worktree helper in `@cleocode/worktree` is
181
- unavailable there. musl (Alpine) ARM64 is unaffected.
182
- The napi-rs generated loader (`napi/index.cjs`) uses the native binary for
183
- the host and falls back to the WebAssembly build automatically when none
184
- matches. `NAPI_RS_FORCE_WASI=error` forces the WebAssembly build (tests use
185
- it to prove the fallback). `cantAddonBackend()` reports which one loaded.
227
+ Debian 13+). Older ARM64 Linux loads the WebAssembly build instead, and the
228
+ native worktree helper in `@cleocode/worktree` is unavailable there. musl
229
+ (Alpine) ARM64 is unaffected.
230
+
231
+ The napi-rs generated loader (`napi/index.cjs`) uses the native binary for the
232
+ host and falls back to the WebAssembly build when none matches.
233
+ `NAPI_RS_FORCE_WASI=error` forces the WebAssembly build (tests use it to prove
234
+ the fallback). `cantAddonBackend()` reports `'native'`, `'wasi'` or `null`.
186
235
 
187
236
  Parsing, validation and profile extraction are identical on both backends
188
- (`tests/native-wasi-parity.test.ts`). One function differs:
189
- `cantExecutePipelineNative` needs the native backend, because pipelines spawn
190
- subprocesses through cant-runtime's multi-thread tokio runtime, which WASI
191
- cannot provide. Under WASI it resolves to `success: false` with an `error`
192
- saying so; it does not throw. Node prints a one-time
193
- `ExperimentalWarning: WASI is an experimental feature` to stderr when the
194
- WebAssembly build loads.
237
+ (`tests/native-wasi-parity.test.ts`). Pipeline execution is native-only,
238
+ because pipelines spawn subprocesses through cant-runtime's multi-thread tokio
239
+ runtime, which WASI cannot provide: under WASI `cantExecutePipelineNative`
240
+ resolves to `success: false` with an `error` saying so, and does not throw.
241
+ Node prints a one-time `ExperimentalWarning: WASI is an experimental feature`
242
+ to stderr when the WebAssembly build loads.
195
243
 
196
244
  To build locally (Rust toolchain required; nothing in `napi/` is committed):
197
245
 
@@ -210,19 +258,18 @@ stamped with the released commit.
210
258
 
211
259
  | Crate | Status | Purpose |
212
260
  |-------|--------|---------|
213
- | `crates/cant-core` | Active — SSoT | Parser, validator, 42 static-analysis rules, pipeline executor |
261
+ | `crates/cant-core` | Active (SSoT) | Parser, validator, AST types |
214
262
  | `crates/cant-napi` | Active | napi-rs cdylib binding wrapping cant-core + cant-runtime |
215
- | `crates/cant-runtime` | Active | Deterministic pipeline execution engine (Path B) |
216
- | `crates/cant-router` | DELETED (T11807) | Model-tier classifier — removed in the state-machine collapse (T11764); model selection owned by the E9 chokepoint |
217
- | `crates/cant-lsp` | Shelved from default build (E8 T11434) | Language Server Protocol for `.cant` files — kept in workspace, build with `cargo build -p cant-lsp` |
263
+ | `crates/cant-runtime` | Active | Deterministic pipeline execution engine |
264
+ | `crates/cant-router` | Deleted (T11807) | Model-tier classifier, removed in the state-machine collapse (T11764); model selection is owned by the LLM chokepoint |
265
+ | `crates/cant-lsp` | Shelved from the default build (T11434) | Language server for `.cant` files; still a workspace member, build with `cargo build -p cant-lsp` |
218
266
 
219
267
  ## Related
220
268
 
221
- - [`crates/cant-core`](../../crates/cant-core) — Rust SSoT (parser, validator, pipeline executor)
222
- - [`crates/cant-napi`](../../crates/cant-napi) — napi-rs bindings (cdylib)
223
- - [`packages/cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts`](../cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts) — Pi-interactive runtime (Path A, deprecated)
224
- - [`docs/adr/adr-035-pi-v2-v3-harness.md`](../../docs/adr/adr-035-pi-v2-v3-harness.md) — the original CANT execution model (superseded by ADR-098)
225
- - [CANT DSL spec §7](../../docs/spec/cant-dsl.md) — what `cant-runtime` implements
269
+ - [`crates/cant-core`](../../crates/cant-core): Rust SSoT (parser, validator)
270
+ - [`crates/cant-napi`](../../crates/cant-napi): napi-rs bindings (cdylib)
271
+ - [CANT DSL spec](../../docs/spec/cant-dsl.md): the language; §7.1 is what `cant-runtime` implements
272
+ - [ADR-035](../../docs/adr/adr-035-pi-v2-v3-harness.md): the original CANT execution model (superseded by ADR-098)
226
273
 
227
274
  ## License
228
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/cant",
3
- "version": "2026.11.11",
3
+ "version": "2026.11.12",
4
4
  "description": "CANT DSL — cant-core (SSoT) parser, validator, and pipeline executor via napi-rs; agent identity, message parsing, and migration utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,9 +16,9 @@
16
16
  "@emnapi/core": "1.11.3",
17
17
  "@emnapi/runtime": "1.11.3",
18
18
  "@napi-rs/wasm-runtime": "1.2.4",
19
- "@cleocode/contracts": "2026.11.11",
20
- "@cleocode/lafs": "2026.11.11",
21
- "@cleocode/core": "2026.11.11"
19
+ "@cleocode/contracts": "2026.11.12",
20
+ "@cleocode/core": "2026.11.12",
21
+ "@cleocode/lafs": "2026.11.12"
22
22
  },
23
23
  "devDependencies": {
24
24
  "typescript": "^6.0.2",