@cleocode/cant 2026.4.6 → 2026.4.9
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 +156 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @cleocode/cant
|
|
2
|
+
|
|
3
|
+
CANT protocol parser, validator, and runtime for the CLEO ecosystem. Wraps the
|
|
4
|
+
Rust [`cant-core`](../../crates/cant-core) crate via [napi-rs](https://napi.rs)
|
|
5
|
+
so TypeScript consumers get the full Rust validator (42 static-analysis rules)
|
|
6
|
+
and pipeline executor without spawning a separate process.
|
|
7
|
+
|
|
8
|
+
CANT is a constrained agent specification language: agents, protocol
|
|
9
|
+
constraints, typed tokens, deterministic pipelines, and orchestration
|
|
10
|
+
workflows (sessions, parallel arms, conditionals, approval gates, repeat
|
|
11
|
+
loops, try/catch). The format is whitespace-significant Markdown with
|
|
12
|
+
typed frontmatter.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @cleocode/cant
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The package ships pre-built napi binaries via `optionalDependencies` for
|
|
21
|
+
`x86_64-unknown-linux-gnu`. On other platforms `@cleocode/cant` falls back to
|
|
22
|
+
graceful errors at runtime — the TypeScript surface still loads but
|
|
23
|
+
parser/validator/executor calls require a native binding present.
|
|
24
|
+
|
|
25
|
+
## Public API
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
parseDocument,
|
|
30
|
+
validateDocument,
|
|
31
|
+
executePipeline,
|
|
32
|
+
listSections,
|
|
33
|
+
migrateMarkdown,
|
|
34
|
+
serializeCantDocument,
|
|
35
|
+
initCantParser,
|
|
36
|
+
parseCANTMessage,
|
|
37
|
+
} from '@cleocode/cant';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `parseDocument(filePath: string): Promise<CantDocument>`
|
|
41
|
+
|
|
42
|
+
Parses a `.cant` file into a structured AST. The AST mirrors the Rust
|
|
43
|
+
canonical types from [`crates/cant-core/src/dsl/ast.rs`](../../crates/cant-core/src/dsl/ast.rs).
|
|
44
|
+
|
|
45
|
+
### `validateDocument(filePath: string): Promise<CantValidationResult>`
|
|
46
|
+
|
|
47
|
+
Runs the 42-rule static-analysis validator. Returns a structured result with
|
|
48
|
+
per-diagnostic line/column coordinates and severity levels:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
interface CantValidationResult {
|
|
52
|
+
valid: boolean;
|
|
53
|
+
errorCount: number;
|
|
54
|
+
warningCount: number;
|
|
55
|
+
diagnostics: NativeDiagnostic[];
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Used by `caamp pi cant validate` and `caamp pi cant install` to reject
|
|
60
|
+
invalid `.cant` files before they hit the runtime.
|
|
61
|
+
|
|
62
|
+
### `executePipeline(filePath: string, pipelineName: string): Promise<JsPipelineResult>`
|
|
63
|
+
|
|
64
|
+
Runs a deterministic pipeline by name from a `.cant` file. Pipelines are
|
|
65
|
+
the executable subset of CANT — declarative steps with explicit inputs,
|
|
66
|
+
outputs, and exit codes. Workflow constructs (sessions, parallel arms,
|
|
67
|
+
conditionals, etc.) are interpreted by the [`cant-bridge.ts`](../cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts)
|
|
68
|
+
Pi extension, not by this package.
|
|
69
|
+
|
|
70
|
+
### `migrateMarkdown(input: string): MigrateResult`
|
|
71
|
+
|
|
72
|
+
Converts legacy markdown agent definitions to canonical `.cant` format.
|
|
73
|
+
Used by `cleo cant migrate` to bring pre-CANT skill libraries into the
|
|
74
|
+
new format without losing semantics.
|
|
75
|
+
|
|
76
|
+
### `parseCANTMessage(text: string): ParsedCANTMessage`
|
|
77
|
+
|
|
78
|
+
Parses an inline CANT message embedded in agent transcripts (used by the
|
|
79
|
+
brain memory bridge for cross-provider transcript hooks).
|
|
80
|
+
|
|
81
|
+
## Architecture
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
┌─────────────────────────────────────┐
|
|
85
|
+
│ TypeScript consumers │
|
|
86
|
+
│ (caamp, cleo, cant-bridge.ts) │
|
|
87
|
+
└────────────────┬────────────────────┘
|
|
88
|
+
│
|
|
89
|
+
▼
|
|
90
|
+
┌─────────────────────────────────────┐
|
|
91
|
+
│ @cleocode/cant (this package) │
|
|
92
|
+
│ src/document.ts — TS API surface │
|
|
93
|
+
│ src/parse.ts — message parser │
|
|
94
|
+
│ src/migrate/ — markdown→cant │
|
|
95
|
+
└────────────────┬────────────────────┘
|
|
96
|
+
│ napi-rs binding
|
|
97
|
+
▼
|
|
98
|
+
┌─────────────────────────────────────┐
|
|
99
|
+
│ crates/cant-napi │
|
|
100
|
+
│ parse_document, validate_document │
|
|
101
|
+
│ execute_pipeline │
|
|
102
|
+
└────────────────┬────────────────────┘
|
|
103
|
+
│
|
|
104
|
+
▼
|
|
105
|
+
┌─────────────────────────────────────┐
|
|
106
|
+
│ crates/cant-core (Rust) │
|
|
107
|
+
│ AST types, parser, validator, │
|
|
108
|
+
│ pipeline executor (deterministic) │
|
|
109
|
+
└─────────────────────────────────────┘
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The Rust core is the canonical source of truth for AST shape and
|
|
113
|
+
validation rules. The TypeScript surface is a thin async wrapper.
|
|
114
|
+
|
|
115
|
+
## CANT execution paths
|
|
116
|
+
|
|
117
|
+
There are two execution paths in the CleoOS runtime:
|
|
118
|
+
|
|
119
|
+
| Path | Engine | Use case |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| **Path A — Pi-interactive** | `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. |
|
|
122
|
+
| **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. |
|
|
123
|
+
|
|
124
|
+
There is no third execution engine — the legacy `@cleocode/core/cant`
|
|
125
|
+
WorkflowExecutor was deleted in v2026.4.7 per [ADR-035 §D5](../../.cleo/adrs/ADR-035-pi-v2-v3-harness.md)
|
|
126
|
+
"single engine, cant-bridge.ts as canonical".
|
|
127
|
+
|
|
128
|
+
## Testing
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pnpm --filter @cleocode/cant test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Tests use real `.cant` fixtures from `crates/cant-core/fixtures/` and
|
|
135
|
+
seed agents from `packages/agents/seed-agents/`.
|
|
136
|
+
|
|
137
|
+
## Rebuilding the napi binary
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pnpm --filter @cleocode/cant build:napi
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Requires a Rust toolchain. Produces `napi/cant.linux-x64-gnu.node`.
|
|
144
|
+
Other platform triples are added via the workspace release pipeline,
|
|
145
|
+
not locally.
|
|
146
|
+
|
|
147
|
+
## Related
|
|
148
|
+
|
|
149
|
+
- [`crates/cant-core`](../../crates/cant-core) — Rust source of truth (parser, validator, executor)
|
|
150
|
+
- [`crates/cant-napi`](../../crates/cant-napi) — napi-rs bindings (cdylib)
|
|
151
|
+
- [`packages/cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts`](../cleo/templates/cleoos-hub/pi-extensions/cant-bridge.ts) — Pi-interactive runtime (Path A)
|
|
152
|
+
- [`.cleo/adrs/ADR-035-pi-v2-v3-harness.md`](../../.cleo/adrs/ADR-035-pi-v2-v3-harness.md) — architecture decisions for the CANT execution model
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/cant",
|
|
3
|
-
"version": "2026.4.
|
|
3
|
+
"version": "2026.4.9",
|
|
4
4
|
"description": "CANT protocol parser and runtime for CLEO — wraps cant-core via napi-rs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"napi/"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@cleocode/contracts": "2026.4.
|
|
13
|
-
"@cleocode/lafs": "2026.4.
|
|
12
|
+
"@cleocode/contracts": "2026.4.9",
|
|
13
|
+
"@cleocode/lafs": "2026.4.9"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"typescript": "^5.0.0",
|