Skip to content

Commit 3f084df

Browse files
RoyLinRoyLin
authored andcommitted
docs: sync native ACL generation contract
1 parent 6a75c7f commit 3f084df

12 files changed

Lines changed: 270 additions & 85 deletions

File tree

apps/docs/content/docs/cn/acl/generation-boundaries.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@ ACL 适合产品配置,是因为它让配置保持可读、结构化,同时
1515
| String escaping | Quotes、backslashes、newline、carriage return、tab 会被 escape。 |
1616
| Lists and objects | Values 会 inline 生成。 |
1717
| Function calls | Calls 会以语法形式保留,例如 `env("PROVIDER_API_KEY")`|
18-
| Labels | 默认输出把 labels 写在 block headers 中。 |
19-
| Label-as-attribute mode | Rust 暴露 `GeneratorConfig.labels_as_attrs`;Node 暴露 `generateHCL`|
18+
| Labels | 输出会把所有 labels 写在 native ACL block headers 中。 |
19+
20+
Native ACL 是唯一 output mode。两个 SDK 都不提供 label-as-attribute
21+
generator mode,并且 Node 会拒绝 generator options,避免静默生成不同
22+
document shape。
23+
24+
## Canonical Bytes And Digests
25+
26+
当配置需要签名、存储或比较时,Rust 使用 `canonical_bytes` /
27+
`canonical_digest`,Node 使用 `canonicalBytes` / `canonicalDigest`
28+
Canonical output 使用 UTF-8、LF line endings、恰好一个 final newline、
29+
sorted portable attribute/object keys,并对 duplicate object keys 使用
30+
last-value-wins。Block、label、list 和 function-argument order 保持有意义。
31+
32+
Finite numbers 使用 ECMAScript shortest-round-trip formatting,negative zero
33+
输出为 `0`。Unicode scalar sequences 不做 normalization。Digest 格式为
34+
`sha256:<64 lowercase hexadecimal characters>`
2035

2136
## Secret Hygiene
2237

2338
存引用,不存秘密:
2439

25-
```hcl
40+
```text
2641
providers "provider" {
2742
api_key = env("PROVIDER_API_KEY")
2843
base_url = env("PROVIDER_BASE_URL")

apps/docs/content/docs/cn/acl/index.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: A3S ACL
3-
description: A3S 组件使用的类 HCL Agent Configuration Language。
3+
description: A3S 组件使用的类型化 Agent Configuration Language。
44
---
55

66
# A3S ACL
@@ -9,35 +9,36 @@ description: A3S 组件使用的类 HCL Agent Configuration Language。
99
Rust crate 与 Node.js/TypeScript SDK,可以把 ACL 文本解析成 AST,也可以从结构化
1010
值生成 ACL 文本。
1111

12-
当前 Rust crate 是 `a3s-acl` `0.2.1`,当前 Node package 是 `@a3s-lab/acl`
13-
`0.2.1`。crate repository metadata 指向
12+
仓库中 Rust crate 是 `a3s-acl` `0.2.2`Node package 是 `@a3s-lab/acl`
13+
`0.2.2`。crate repository metadata 指向
1414
[`A3S-Lab/ACL`](https://github.com/A3S-Lab/ACL)
1515

1616
## 能力地图
1717

1818
| 领域 | 当前能力 |
1919
| --- | --- |
20-
| 语法 | 类 HCL attributes、带 label 的 blocks、nested blocks、lists、objects、strings、numbers、booleans、null、function calls、comments,以及 `=` / `:` assignments。 |
21-
| Lexer/parser | Source spans、line/column parse errors、comment skipping、string escapes、negative numbers 和 scientific notation。 |
20+
| 语法 | ACL attributes、带 label 的 blocks、nested blocks、lists、objects、strings、numbers、booleans、null、function calls、comments,以及 `=` / `:` assignments。 |
21+
| Lexer/parser | Bounded parsing、stable diagnostic codes、UTF-8 byte spans、comment skipping、string escapes、negative numbers 和 scientific notation。 |
2222
| 函数 | 支持把 `env(...)``concat(...)` 和自定义函数名表示为 first-class call values。 |
2323
| AST | `Document``Block`、typed values、builders、value constructors 和 `Value` accessors。 |
24-
| 生成 | 支持 parse/generate 双向流程、sorted attributes、string escaping、map generation 和 label-as-attribute output mode。 |
24+
| 生成 | Native ACL output、block-header labels、sorted attributes 和 objects、type-stable strings,以及 map generation。 |
25+
| 完整性 | Rust/Node byte-identical canonical UTF-8 和带 algorithm prefix 的 SHA-256 digests。 |
2526
| SDK | Rust crate `a3s-acl`;Node package `@a3s-lab/acl`,带 TypeScript definitions。 |
2627

2728
## 从这里开始
2829

2930
- [Syntax](/cn/docs/acl/syntax) 说明 blocks、attributes、values、calls、
3031
comments 和 parser boundaries。
31-
- [Rust API](/cn/docs/acl/rust-api) 覆盖 `parse``generate`、builders、
32-
`GeneratorConfig` 和 AST value helpers。
32+
- [Rust API](/cn/docs/acl/rust-api) 覆盖 bounded parsing、diagnostics、canonical
33+
digests、generation、builders 和 AST value helpers。
3334
- [Node SDK](/cn/docs/acl/node-sdk) 覆盖 JavaScript/TypeScript parser、
34-
generator、builders 和 `generateHCL`
35-
- [Generation And Boundaries](/cn/docs/acl/generation-boundaries) 说明 output
36-
modes、secret handling,以及 ACL 自身不会评估什么
35+
native ACL generator、canonical APIs 和 builders
36+
- [Generation And Boundaries](/cn/docs/acl/generation-boundaries) 说明 stable
37+
output、canonical bytes、secret handling 和 host-component ownership
3738

3839
## 示例
3940

40-
```hcl
41+
```text
4142
default_model = "provider/model-id"
4243
4344
providers "provider" {

apps/docs/content/docs/cn/acl/node-sdk.mdx

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Node SDK
3-
description: "@a3s-lab/acl 的 JavaScript/TypeScript parsing、generation、builders、lexer/parser classesHCL output"
3+
description: "@a3s-lab/acl 的 JavaScript/TypeScript bounded parsing、native ACL generation、canonical digestsbuilders"
44
---
55

66
# Node SDK
@@ -11,7 +11,7 @@ description: "@a3s-lab/acl 的 JavaScript/TypeScript parsing、generation、buil
1111
npm install @a3s-lab/acl
1212
```
1313

14-
当前仓库中的 package version 是 `0.2.1`
14+
仓库中的 package version 是 `0.2.2`
1515

1616
## Parse And Generate
1717

@@ -43,26 +43,53 @@ const generated = generate(new DocumentBuilder().block(provider).build());
4343

4444
| API | 作用 |
4545
| --- | --- |
46-
| `parse(input)` | 把 ACL text 解析成 `Document`|
47-
| `generate(doc)` | 生成 ACL-style text。 |
48-
| `generateHCL(doc)` | 生成 label-as-attribute HCL-shaped text。 |
46+
| `parse(input, limits?)` | 使用默认或显式 resource limits,把 ACL text 解析成 `Document`|
47+
| `DEFAULT_PARSE_LIMITS` | Document bytes、nesting、collection items 和 token bytes 的 shared immutable defaults。 |
48+
| `ParseError``DIAGNOSTIC_CODES` | Stable codes、complete spans、UTF-8 byte offsets 和 redacted messages。 |
49+
| `generate(doc)` | 生成 labels 位于 block headers 的 native ACL text。 |
50+
| `canonicalBytes(doc)``canonicalDigest(doc)` | 生成 stable cross-SDK bytes 和带 algorithm prefix 的 SHA-256 digest。 |
51+
| `CanonicalError` | 对 non-finite numbers、non-scalar strings 和 non-portable identifiers 返回不回显值的错误。 |
4952
| `string``number``boolean``bool``nullValue``list``call` | Value constructors。 |
5053
| `BlockBuilder``DocumentBuilder` | Structured document builders。 |
5154
| `Lexer``Parser` | Advanced tokenization/parsing classes。 |
5255

5356
Package 在 `src/index.d.ts` 中提供 TypeScript definitions。
5457

55-
## HCL Output Mode
58+
## Bounded Admission
5659

57-
Node generator 有 `generateHCL` helper。它会把 labels 写成 generated block 内部的 attributes。
58-
`models` blocks,label attribute 名为 `id`;其它 blocks 使用 `name`
60+
在 API boundary 传入显式 limits:
5961

6062
```typescript
61-
import {generateHCL} from '@a3s-lab/acl';
62-
63-
const hcl = generateHCL(doc);
63+
import {ParseError, parse} from '@a3s-lab/acl';
64+
65+
const source = 'limits { max_tasks = 10 }';
66+
67+
try {
68+
const document = parse(source, {
69+
maxDocumentBytes: 64 * 1024,
70+
maxNestingDepth: 32,
71+
maxCollectionItems: 1_000,
72+
maxTokenBytes: 16 * 1024,
73+
});
74+
} catch (error) {
75+
if (error instanceof ParseError) {
76+
console.error(error.code, error.span);
77+
}
78+
}
6479
```
6580

81+
Document 和 token sizes 使用 UTF-8 bytes。Diagnostic messages 只标识 token
82+
kinds,不包含 source token values 或 snippets。
83+
84+
## Native And Canonical Output
85+
86+
`generate` 只有一个 native ACL output contract。Labels 保留在 block headers;
87+
alternate generator modes 和 generator options 均不支持。
88+
89+
签名、durable identity 和 cross-SDK comparisons 应使用 `canonicalBytes`
90+
`canonicalDigest`。Canonical bytes 会保留 ordered ACL constructs,同时对
91+
semantically unordered attribute 和 object keys 排序。
92+
6693
## 边界
6794

6895
SDK 是 parser/generator 和 AST builder。它不会加载环境变量、拉取远程配置、验证 provider

apps/docs/content/docs/cn/acl/rust-api.mdx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Rust API
3-
description: a3s-acl 的 Rust parser、generator、AST、builders、value helpers 和 generator configuration
3+
description: a3s-acl 的 Rust bounded parsing、diagnostics、canonical digests、native ACL generation、AST 和 builders
44
---
55

66
# Rust API
@@ -9,7 +9,7 @@ description: a3s-acl 的 Rust parser、generator、AST、builders、value helper
99

1010
```toml
1111
[dependencies]
12-
a3s-acl = "0.2.1"
12+
a3s-acl = "0.2.2"
1313
```
1414

1515
## Parse And Generate
@@ -34,10 +34,35 @@ Public crate exports:
3434
| API | 作用 |
3535
| --- | --- |
3636
| `parse` / `parse_acl` | 把 ACL text 解析成 `Document`|
37+
| `parse_with_limits``ParseLimits` | 使用显式 document、nesting、collection 和 token limits 解析 untrusted input。 |
38+
| `DiagnosticCode``ParseError` | 返回 stable codes、UTF-8 byte spans 和 redacted messages。 |
3739
| `generate` / `generate_acl` |`Document` 生成 ACL text。 |
3840
| `generate_from_map` |`HashMap<String, Value>` 生成 ACL text。 |
41+
| `canonical_bytes``canonical_digest` | 生成 stable cross-SDK bytes 和带 algorithm prefix 的 SHA-256 digest。 |
42+
| `CanonicalError` | 拒绝 unsupported programmatic values 且不回显值。 |
3943
| `Lexer` / `Parser` | 高级 tokenization 和 parsing entry points。 |
40-
| `ParseError` | 带 message、line、column 的错误。 |
44+
45+
## Bounded Admission
46+
47+
```rust
48+
use a3s_acl::{parse_with_limits, ParseLimits};
49+
50+
let input = "limits { max_tasks = 10 }";
51+
let document = parse_with_limits(
52+
input,
53+
ParseLimits {
54+
max_document_bytes: 64 * 1024,
55+
max_nesting_depth: 32,
56+
max_collection_items: 1_000,
57+
max_token_bytes: 16 * 1024,
58+
},
59+
)?;
60+
```
61+
62+
Document 和 token sizes 使用 UTF-8 bytes。`ParseError` 提供 stable
63+
`DiagnosticCode`、带 UTF-8 byte offsets 的 complete source span,以及
64+
compatibility `line` / `column` fields。Messages 只标识 token kinds,不包含
65+
source token values 或 snippets。
4166

4267
## AST
4368

@@ -65,20 +90,34 @@ let doc = DocumentBuilder::new().block(provider).build();
6590

6691
Builder helpers 包括 `string``number``integer``boolean``null``list``call`
6792

68-
## GeneratorConfig
93+
## Native Generation
6994

7095
```rust
7196
use a3s_acl::{Generator, GeneratorConfig};
7297

7398
let generator = Generator::with_config(GeneratorConfig {
74-
indent: " ",
99+
indent: " ",
75100
comments: false,
76-
labels_as_attrs: true,
77101
});
102+
let text = generator.generate(&doc);
103+
```
104+
105+
Generation 只有一个 native ACL contract:block labels 保留在 block headers。
106+
不存在 label-as-attribute compatibility mode。
107+
108+
## Canonical Bytes And Digests
109+
110+
```rust
111+
use a3s_acl::{canonical_bytes, canonical_digest};
112+
113+
let bytes = canonical_bytes(&doc)?;
114+
let digest = canonical_digest(&doc)?;
115+
assert!(digest.starts_with("sha256:"));
78116
```
79117

80-
`labels_as_attrs` 会把 block labels 写成 block 内部 attributes,而不是写在 block header 中。
81-
当 integration 更偏向 attribute-oriented HCL shape 时可以使用。
118+
签名、durable identity 和 cross-SDK comparisons 应使用 canonical APIs。
119+
Canonical bytes 会保留 ordered ACL constructs,同时对 semantically
120+
unordered attribute 和 object keys 排序。
82121

83122
## Notes
84123

apps/docs/content/docs/cn/acl/syntax.mdx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ description: A3S ACL 的 blocks、labels、attributes、values、calls、comment
55

66
# ACL Syntax
77

8-
ACL 刻意接近 HCL:document 会被解析成一组 named blocks。Top-level bare attributes 会表示成
9-
single-attribute blocks,因此编辑工具可以使用统一 AST 形态。
8+
ACL 使用紧凑的 attribute-and-block syntax。Document 会被解析成一组 named
9+
blocks。Top-level bare attributes 会表示成 single-attribute blocks,因此编辑
10+
工具可以使用统一 AST 形态。
1011

1112
## Blocks And Attributes
1213

13-
```hcl
14+
```text
1415
default_model = "provider/model-id"
1516
1617
providers "provider" {
@@ -51,10 +52,21 @@ Lexer 里有 `+=` token,但 parser 当前接受的是 `=` 和 `:` attributes
5152
Double-quoted strings 支持 newline、carriage return、tab、backslash、escaped quote 等常见 escapes。
5253
Single-quoted strings 也会被 tokenized。
5354

54-
## Parse Errors
55+
## Resource Limits And Parse Errors
5556

56-
`ParseError` 包含 message、line 和 column。Lexer 为 tokens 跟踪 spans,方便 editor integrations
57-
定位失败位置。
57+
两个 SDK 的 high-level parser 使用相同 defaults:
58+
59+
| Limit | Default |
60+
| --- | ---: |
61+
| UTF-8 document size | 1 MiB |
62+
| Structural nesting depth | 64 |
63+
| Items in one document or collection | 10,000 |
64+
| UTF-8 source token size | 256 KiB |
65+
66+
`ParseError` 提供 stable machine-readable code、complete source span 和
67+
compatibility line/column fields。Span offsets 使用 UTF-8 bytes,因此即使
68+
error 前有 Unicode,Rust 和 Node 也会定位到相同位置。Messages 只标识 token
69+
kinds,不回显 token values 或 source snippets。
5870

5971
## Evaluation Boundary
6072

apps/docs/content/docs/en/acl/generation-boundaries.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,29 @@ and structured while leaving sensitive value resolution to the host component.
1616
| String escaping | Quotes, backslashes, newline, carriage return, and tab are escaped. |
1717
| Lists and objects | Values are generated inline. |
1818
| Function calls | Calls are preserved as syntax, for example `env("PROVIDER_API_KEY")`. |
19-
| Labels | Default output writes labels in block headers. |
20-
| Label-as-attribute mode | Rust exposes `GeneratorConfig.labels_as_attrs`; Node exposes `generateHCL`. |
19+
| Labels | Output writes every label in its native ACL block header. |
20+
21+
Native ACL is the only output mode. Neither SDK provides a label-as-attribute
22+
generator mode, and Node rejects generator options instead of silently
23+
producing a different document shape.
24+
25+
## Canonical Bytes And Digests
26+
27+
Use `canonical_bytes` / `canonical_digest` in Rust and `canonicalBytes` /
28+
`canonicalDigest` in Node when configuration is signed, stored, or compared.
29+
Canonical output uses UTF-8, LF line endings, exactly one final newline, sorted
30+
portable attribute and object keys, and last-value-wins duplicate object keys.
31+
Block, label, list, and function-argument order remains significant.
32+
33+
Finite numbers use ECMAScript shortest-round-trip formatting, including `0` for
34+
negative zero. Unicode scalar sequences are preserved without normalization.
35+
The digest format is `sha256:<64 lowercase hexadecimal characters>`.
2136

2237
## Secret Hygiene
2338

2439
Store references, not secrets:
2540

26-
```hcl
41+
```text
2742
providers "provider" {
2843
api_key = env("PROVIDER_API_KEY")
2944
base_url = env("PROVIDER_BASE_URL")

apps/docs/content/docs/en/acl/index.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: A3S ACL
3-
description: HCL-like Agent Configuration Language used across A3S components.
3+
description: Typed Agent Configuration Language used across A3S components.
44
---
55

66
# A3S ACL
@@ -9,35 +9,36 @@ description: HCL-like Agent Configuration Language used across A3S components.
99
configuration. It provides a Rust crate and a Node.js/TypeScript SDK for parsing
1010
ACL text into an AST and generating ACL text back from structured values.
1111

12-
The current Rust crate is `a3s-acl` `0.2.1`, and the current Node package is
13-
`@a3s-lab/acl` `0.2.1`. The crate repository metadata points to
12+
The checked-in Rust crate is `a3s-acl` `0.2.2`, and the checked-in Node package
13+
is `@a3s-lab/acl` `0.2.2`. The crate repository metadata points to
1414
[`A3S-Lab/ACL`](https://github.com/A3S-Lab/ACL).
1515

1616
## Capability Map
1717

1818
| Area | Current capability |
1919
| --- | --- |
20-
| Syntax | HCL-like attributes, labeled blocks, nested blocks, lists, objects, strings, numbers, booleans, null, function calls, comments, and `=` / `:` assignments. |
21-
| Lexer/parser | Source spans, line/column parse errors, comment skipping, string escapes, negative numbers, and scientific notation. |
20+
| Syntax | ACL attributes, labeled blocks, nested blocks, lists, objects, strings, numbers, booleans, null, function calls, comments, and `=` / `:` assignments. |
21+
| Lexer/parser | Bounded parsing, stable diagnostic codes, UTF-8 byte spans, comment skipping, string escapes, negative numbers, and scientific notation. |
2222
| Functions | First-class call values such as `env(...)`, `concat(...)`, and custom function names. |
2323
| AST | `Document`, `Block`, typed values, builders, value constructors, and `Value` accessors. |
24-
| Generation | Bidirectional parse/generate flow, sorted attributes, string escaping, map generation, and label-as-attribute output mode. |
24+
| Generation | Native ACL output, block-header labels, sorted attributes and objects, type-stable strings, and map generation. |
25+
| Integrity | Byte-identical Rust/Node canonical UTF-8 and algorithm-prefixed SHA-256 digests. |
2526
| SDKs | Rust crate `a3s-acl`; Node package `@a3s-lab/acl` with TypeScript definitions. |
2627

2728
## Start Here
2829

2930
- [Syntax](/docs/acl/syntax) documents blocks, attributes, values, calls,
3031
comments, and parser boundaries.
31-
- [Rust API](/docs/acl/rust-api) covers `parse`, `generate`, builders,
32-
`GeneratorConfig`, and AST value helpers.
32+
- [Rust API](/docs/acl/rust-api) covers bounded parsing, diagnostics, canonical
33+
digests, generation, builders, and AST value helpers.
3334
- [Node SDK](/docs/acl/node-sdk) covers the JavaScript/TypeScript parser,
34-
generator, builders, and `generateHCL`.
35-
- [Generation And Boundaries](/docs/acl/generation-boundaries) explains output
36-
modes, secret handling, and what ACL does not evaluate by itself.
35+
native ACL generator, canonical APIs, and builders.
36+
- [Generation And Boundaries](/docs/acl/generation-boundaries) explains stable
37+
output, canonical bytes, secret handling, and host-component ownership.
3738

3839
## Example
3940

40-
```hcl
41+
```text
4142
default_model = "provider/model-id"
4243
4344
providers "provider" {

0 commit comments

Comments
 (0)