n2-clotho 2.0.0 โ 2.0.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/README.md +21 -1
- package/n2_compiler.d.ts +25 -0
- package/n2_compiler.js +211 -0
- package/n2_compiler_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# ๐งต Clotho โ The Thread of Fate for AI Agents
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/n2-clotho)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
|
|
3
6
|
> **Markdown rules are dead. Long live `.n2`.**
|
|
4
7
|
|
|
5
8
|
Clotho is a compiled instruction language for AI agents. It replaces fragile markdown-based rules (GEMINI.md, .cursorrules, CLAUDE.md) with **enforceable, type-checked, deterministic** specifications that agents cannot ignore.
|
|
@@ -74,8 +77,24 @@ Clotho introduces `.n2` โ a compiled instruction language with:
|
|
|
74
77
|
|
|
75
78
|
### Installation
|
|
76
79
|
|
|
80
|
+
> ๐ก **The easiest way to get started?** Just ask your AI to write a `.n2` file for you.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# npm (WASM โ use in Node.js)
|
|
84
|
+
npm install n2-clotho
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
// Usage in Node.js
|
|
89
|
+
const { parse_n2_wasm, validate_n2_wasm, query_n2_wasm } = require('n2-clotho');
|
|
90
|
+
|
|
91
|
+
const ast = parse_n2_wasm(n2Source); // Parse โ AST JSON
|
|
92
|
+
const result = validate_n2_wasm(n2Source); // Validate โ errors/warnings
|
|
93
|
+
const table = query_n2_wasm(n2Source, 'SELECT * FROM rules'); // SQL query
|
|
94
|
+
```
|
|
95
|
+
|
|
77
96
|
```bash
|
|
78
|
-
# From source (Rust required)
|
|
97
|
+
# From source (Rust required โ full CLI)
|
|
79
98
|
git clone https://github.com/choihyunsus/n2-clotho.git
|
|
80
99
|
cd n2-clotho/compiler
|
|
81
100
|
cargo build --release
|
|
@@ -431,6 +450,7 @@ Apache-2.0 โ Free to use, modify, and distribute.
|
|
|
431
450
|
|
|
432
451
|
## ๐ Links
|
|
433
452
|
|
|
453
|
+
- [**npm: n2-clotho**](https://www.npmjs.com/package/n2-clotho) โ WASM bindings for Node.js
|
|
434
454
|
- [N2 Soul](https://github.com/choihyunsus/soul) โ Agent memory & runtime
|
|
435
455
|
- [N2 Arachne](https://github.com/choihyunsus/n2-arachne) โ Code context assembly
|
|
436
456
|
- [N2 QLN](https://github.com/choihyunsus/n2-qln) โ Tool orchestration & routing
|
package/n2_compiler.d.ts
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extract blacklist patterns from .n2 source โ returns JSON array
|
|
6
|
+
*/
|
|
7
|
+
export function extract_blacklist_wasm(source: string): string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get compiler version info
|
|
11
|
+
*/
|
|
12
|
+
export function n2c_version(): string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse .n2 source and return AST as JSON string
|
|
16
|
+
*/
|
|
17
|
+
export function parse_n2_wasm(source: string): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Query .n2 source with SQL โ returns formatted table string
|
|
21
|
+
*/
|
|
22
|
+
export function query_n2_wasm(source: string, sql: string): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Validate .n2 source โ returns JSON with errors/warnings
|
|
26
|
+
*/
|
|
27
|
+
export function validate_n2_wasm(source: string): string;
|
package/n2_compiler.js
CHANGED
|
@@ -1,8 +1,142 @@
|
|
|
1
1
|
/* @ts-self-types="./n2_compiler.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Extract blacklist patterns from .n2 source โ returns JSON array
|
|
5
|
+
* @param {string} source
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
function extract_blacklist_wasm(source) {
|
|
9
|
+
let deferred3_0;
|
|
10
|
+
let deferred3_1;
|
|
11
|
+
try {
|
|
12
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
13
|
+
const len0 = WASM_VECTOR_LEN;
|
|
14
|
+
const ret = wasm.extract_blacklist_wasm(ptr0, len0);
|
|
15
|
+
var ptr2 = ret[0];
|
|
16
|
+
var len2 = ret[1];
|
|
17
|
+
if (ret[3]) {
|
|
18
|
+
ptr2 = 0; len2 = 0;
|
|
19
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
20
|
+
}
|
|
21
|
+
deferred3_0 = ptr2;
|
|
22
|
+
deferred3_1 = len2;
|
|
23
|
+
return getStringFromWasm0(ptr2, len2);
|
|
24
|
+
} finally {
|
|
25
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.extract_blacklist_wasm = extract_blacklist_wasm;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get compiler version info
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
function n2c_version() {
|
|
35
|
+
let deferred1_0;
|
|
36
|
+
let deferred1_1;
|
|
37
|
+
try {
|
|
38
|
+
const ret = wasm.n2c_version();
|
|
39
|
+
deferred1_0 = ret[0];
|
|
40
|
+
deferred1_1 = ret[1];
|
|
41
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
42
|
+
} finally {
|
|
43
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.n2c_version = n2c_version;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse .n2 source and return AST as JSON string
|
|
50
|
+
* @param {string} source
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
function parse_n2_wasm(source) {
|
|
54
|
+
let deferred3_0;
|
|
55
|
+
let deferred3_1;
|
|
56
|
+
try {
|
|
57
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
58
|
+
const len0 = WASM_VECTOR_LEN;
|
|
59
|
+
const ret = wasm.parse_n2_wasm(ptr0, len0);
|
|
60
|
+
var ptr2 = ret[0];
|
|
61
|
+
var len2 = ret[1];
|
|
62
|
+
if (ret[3]) {
|
|
63
|
+
ptr2 = 0; len2 = 0;
|
|
64
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
65
|
+
}
|
|
66
|
+
deferred3_0 = ptr2;
|
|
67
|
+
deferred3_1 = len2;
|
|
68
|
+
return getStringFromWasm0(ptr2, len2);
|
|
69
|
+
} finally {
|
|
70
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.parse_n2_wasm = parse_n2_wasm;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Query .n2 source with SQL โ returns formatted table string
|
|
77
|
+
* @param {string} source
|
|
78
|
+
* @param {string} sql
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
function query_n2_wasm(source, sql) {
|
|
82
|
+
let deferred4_0;
|
|
83
|
+
let deferred4_1;
|
|
84
|
+
try {
|
|
85
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
86
|
+
const len0 = WASM_VECTOR_LEN;
|
|
87
|
+
const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
88
|
+
const len1 = WASM_VECTOR_LEN;
|
|
89
|
+
const ret = wasm.query_n2_wasm(ptr0, len0, ptr1, len1);
|
|
90
|
+
var ptr3 = ret[0];
|
|
91
|
+
var len3 = ret[1];
|
|
92
|
+
if (ret[3]) {
|
|
93
|
+
ptr3 = 0; len3 = 0;
|
|
94
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
95
|
+
}
|
|
96
|
+
deferred4_0 = ptr3;
|
|
97
|
+
deferred4_1 = len3;
|
|
98
|
+
return getStringFromWasm0(ptr3, len3);
|
|
99
|
+
} finally {
|
|
100
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.query_n2_wasm = query_n2_wasm;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Validate .n2 source โ returns JSON with errors/warnings
|
|
107
|
+
* @param {string} source
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
function validate_n2_wasm(source) {
|
|
111
|
+
let deferred3_0;
|
|
112
|
+
let deferred3_1;
|
|
113
|
+
try {
|
|
114
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
115
|
+
const len0 = WASM_VECTOR_LEN;
|
|
116
|
+
const ret = wasm.validate_n2_wasm(ptr0, len0);
|
|
117
|
+
var ptr2 = ret[0];
|
|
118
|
+
var len2 = ret[1];
|
|
119
|
+
if (ret[3]) {
|
|
120
|
+
ptr2 = 0; len2 = 0;
|
|
121
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
122
|
+
}
|
|
123
|
+
deferred3_0 = ptr2;
|
|
124
|
+
deferred3_1 = len2;
|
|
125
|
+
return getStringFromWasm0(ptr2, len2);
|
|
126
|
+
} finally {
|
|
127
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.validate_n2_wasm = validate_n2_wasm;
|
|
131
|
+
|
|
3
132
|
function __wbg_get_imports() {
|
|
4
133
|
const import0 = {
|
|
5
134
|
__proto__: null,
|
|
135
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
136
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
137
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
138
|
+
return ret;
|
|
139
|
+
},
|
|
6
140
|
__wbindgen_init_externref_table: function() {
|
|
7
141
|
const table = wasm.__wbindgen_externrefs;
|
|
8
142
|
const offset = table.grow(4);
|
|
@@ -19,6 +153,83 @@ function __wbg_get_imports() {
|
|
|
19
153
|
};
|
|
20
154
|
}
|
|
21
155
|
|
|
156
|
+
function getStringFromWasm0(ptr, len) {
|
|
157
|
+
ptr = ptr >>> 0;
|
|
158
|
+
return decodeText(ptr, len);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let cachedUint8ArrayMemory0 = null;
|
|
162
|
+
function getUint8ArrayMemory0() {
|
|
163
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
164
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
165
|
+
}
|
|
166
|
+
return cachedUint8ArrayMemory0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
170
|
+
if (realloc === undefined) {
|
|
171
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
172
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
173
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
174
|
+
WASM_VECTOR_LEN = buf.length;
|
|
175
|
+
return ptr;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let len = arg.length;
|
|
179
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
180
|
+
|
|
181
|
+
const mem = getUint8ArrayMemory0();
|
|
182
|
+
|
|
183
|
+
let offset = 0;
|
|
184
|
+
|
|
185
|
+
for (; offset < len; offset++) {
|
|
186
|
+
const code = arg.charCodeAt(offset);
|
|
187
|
+
if (code > 0x7F) break;
|
|
188
|
+
mem[ptr + offset] = code;
|
|
189
|
+
}
|
|
190
|
+
if (offset !== len) {
|
|
191
|
+
if (offset !== 0) {
|
|
192
|
+
arg = arg.slice(offset);
|
|
193
|
+
}
|
|
194
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
195
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
196
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
197
|
+
|
|
198
|
+
offset += ret.written;
|
|
199
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
WASM_VECTOR_LEN = offset;
|
|
203
|
+
return ptr;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function takeFromExternrefTable0(idx) {
|
|
207
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
208
|
+
wasm.__externref_table_dealloc(idx);
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
213
|
+
cachedTextDecoder.decode();
|
|
214
|
+
function decodeText(ptr, len) {
|
|
215
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const cachedTextEncoder = new TextEncoder();
|
|
219
|
+
|
|
220
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
221
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
222
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
223
|
+
view.set(buf);
|
|
224
|
+
return {
|
|
225
|
+
read: arg.length,
|
|
226
|
+
written: buf.length
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let WASM_VECTOR_LEN = 0;
|
|
232
|
+
|
|
22
233
|
const wasmPath = `${__dirname}/n2_compiler_bg.wasm`;
|
|
23
234
|
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
24
235
|
const wasmModule = new WebAssembly.Module(wasmBytes);
|
package/n2_compiler_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n2-clotho",
|
|
3
3
|
"description": "๐งต Compiled instruction language for AI agents. Replace GEMINI.md, .cursorrules, CLAUDE.md with enforceable .n2 rules.",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|