@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.
- package/README.md +161 -114
- 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
|
|
6
|
-
Rust [`cant-core`](../../crates/cant-core) crate
|
|
7
|
-
so TypeScript
|
|
8
|
-
and
|
|
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
|
|
12
|
-
workflows (sessions, parallel arms, conditionals, approval gates,
|
|
13
|
-
|
|
14
|
-
|
|
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,
|
|
23
|
-
a WebAssembly (WASI) fallback for the rest
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
initCantParser,
|
|
43
|
-
parseCANTMessage,
|
|
43
|
+
parseDocument,
|
|
44
|
+
validateDocument,
|
|
44
45
|
} from '@cleocode/cant';
|
|
45
|
-
```
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const parsed = await parseDocument('agent.cant');
|
|
48
|
+
// { file, success, document, errors }
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
+
const names = await listSections('team.cant', 'pipeline'); // 'agent' | 'pipeline' | 'workflow'
|
|
57
|
+
// { file, filter, count, names }
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
###
|
|
98
|
+
### Messages: `parseCANTMessage`
|
|
86
99
|
|
|
87
|
-
Parses an inline CANT message
|
|
88
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
│ (
|
|
163
|
+
│ (cleo CLI, core, adapters, caamp) │
|
|
118
164
|
└────────────────┬────────────────────┘
|
|
119
165
|
│
|
|
120
166
|
▼
|
|
121
167
|
┌─────────────────────────────────────┐
|
|
122
168
|
│ @cleocode/cant (this package) │
|
|
123
|
-
│ src/document.ts —
|
|
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
|
|
138
|
-
│ AST
|
|
139
|
-
│ pipeline executor
|
|
183
|
+
│ crates/cant-core + cant-runtime │
|
|
184
|
+
│ AST, parser, validator; │
|
|
185
|
+
│ deterministic pipeline executor │
|
|
140
186
|
└─────────────────────────────────────┘
|
|
141
187
|
```
|
|
142
188
|
|
|
143
|
-
The Rust core
|
|
144
|
-
|
|
189
|
+
The Rust core owns the AST shape and the validation rules; the TypeScript
|
|
190
|
+
surface is a thin wrapper.
|
|
145
191
|
|
|
146
|
-
##
|
|
192
|
+
## Execution
|
|
147
193
|
|
|
148
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
168
|
-
|
|
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
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
`
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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`).
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
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
|
|
216
|
-
| `crates/cant-router` |
|
|
217
|
-
| `crates/cant-lsp` | Shelved from default build (
|
|
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)
|
|
222
|
-
- [`crates/cant-napi`](../../crates/cant-napi)
|
|
223
|
-
- [
|
|
224
|
-
- [
|
|
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.
|
|
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.
|
|
20
|
-
"@cleocode/
|
|
21
|
-
"@cleocode/
|
|
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",
|