gm-codex 2.0.1074 → 2.0.1076
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/.codex-plugin/plugin.json +1 -1
- package/bin/plugkit.wasm +0 -0
- package/bin/plugkit.wasm.sha256 +1 -0
- package/gm.json +1 -1
- package/lib/browser-spool-handler.js +130 -0
- package/lib/browser.js +131 -0
- package/lib/codeinsight.js +109 -0
- package/lib/daemon-bootstrap.js +435 -0
- package/lib/git.js +331 -0
- package/lib/learning.js +169 -0
- package/lib/skill-bootstrap.js +406 -0
- package/lib/spool-dispatch.js +100 -0
- package/lib/spool.js +201 -0
- package/lib/wasm-host.js +241 -0
- package/package.json +6 -2
- package/plugin.json +1 -1
package/lib/wasm-host.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { execSync, spawnSync } = require('child_process');
|
|
4
|
+
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
|
|
5
|
+
|
|
6
|
+
class WasmHost {
|
|
7
|
+
constructor(wasmPath) {
|
|
8
|
+
this.wasmPath = wasmPath;
|
|
9
|
+
this.instance = null;
|
|
10
|
+
this.memory = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async init() {
|
|
14
|
+
try {
|
|
15
|
+
const wasmBuffer = fs.readFileSync(this.wasmPath);
|
|
16
|
+
const wasmModule = new WebAssembly.Module(wasmBuffer);
|
|
17
|
+
|
|
18
|
+
const importObject = {
|
|
19
|
+
host: {
|
|
20
|
+
host_fs_read: this.hostFsRead.bind(this),
|
|
21
|
+
host_fs_write: this.hostFsWrite.bind(this),
|
|
22
|
+
host_fs_readdir: this.hostFsReaddir.bind(this),
|
|
23
|
+
host_fs_stat: this.hostFsStat.bind(this),
|
|
24
|
+
host_kv_get: this.hostKvGet.bind(this),
|
|
25
|
+
host_kv_put: this.hostKvPut.bind(this),
|
|
26
|
+
host_kv_query: this.hostKvQuery.bind(this),
|
|
27
|
+
host_fetch: this.hostFetch.bind(this),
|
|
28
|
+
host_vec_search: this.hostVecSearch.bind(this),
|
|
29
|
+
host_vec_embed: this.hostVecEmbed.bind(this),
|
|
30
|
+
host_browser_spawn: this.hostBrowserSpawn.bind(this),
|
|
31
|
+
host_browser_eval: this.hostBrowserEval.bind(this),
|
|
32
|
+
host_browser_close: this.hostBrowserClose.bind(this),
|
|
33
|
+
host_exec_js: this.hostExecJs.bind(this),
|
|
34
|
+
host_log: this.hostLog.bind(this),
|
|
35
|
+
host_now_ms: this.hostNowMs.bind(this),
|
|
36
|
+
host_env_get: this.hostEnvGet.bind(this),
|
|
37
|
+
},
|
|
38
|
+
env: {
|
|
39
|
+
memory: new WebAssembly.Memory({ initial: 256, maximum: 512 }),
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.instance = new WebAssembly.Instance(wasmModule, importObject);
|
|
44
|
+
this.memory = importObject.env.memory;
|
|
45
|
+
return { ok: true };
|
|
46
|
+
} catch (err) {
|
|
47
|
+
return { ok: false, error: err.message };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
readString(offset, len) {
|
|
52
|
+
const buf = new Uint8Array(this.memory.buffer, offset, len);
|
|
53
|
+
return new TextDecoder().decode(buf);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
writeString(str) {
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
const encoded = encoder.encode(str);
|
|
59
|
+
const len = encoded.length;
|
|
60
|
+
const offset = this.instance.exports.plugkit_alloc(len);
|
|
61
|
+
const buf = new Uint8Array(this.memory.buffer, offset, len);
|
|
62
|
+
buf.set(encoded);
|
|
63
|
+
return [offset, len];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
hostFsRead(pathPtr, pathLen) {
|
|
67
|
+
try {
|
|
68
|
+
const pathStr = this.readString(pathPtr, pathLen);
|
|
69
|
+
const content = fs.readFileSync(pathStr, 'utf8');
|
|
70
|
+
const [offset, len] = this.writeString(content);
|
|
71
|
+
return offset;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
hostFsWrite(pathPtr, pathLen, dataPtr, dataLen) {
|
|
78
|
+
try {
|
|
79
|
+
const pathStr = this.readString(pathPtr, pathLen);
|
|
80
|
+
const data = this.readString(dataPtr, dataLen);
|
|
81
|
+
fs.writeFileSync(pathStr, data, 'utf8');
|
|
82
|
+
return 1;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
hostFsReaddir(pathPtr, pathLen) {
|
|
89
|
+
try {
|
|
90
|
+
const pathStr = this.readString(pathPtr, pathLen);
|
|
91
|
+
const entries = fs.readdirSync(pathStr);
|
|
92
|
+
const result = JSON.stringify(entries);
|
|
93
|
+
const [offset] = this.writeString(result);
|
|
94
|
+
return offset;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
hostFsStat(pathPtr, pathLen) {
|
|
101
|
+
try {
|
|
102
|
+
const pathStr = this.readString(pathPtr, pathLen);
|
|
103
|
+
const stat = fs.statSync(pathStr);
|
|
104
|
+
const result = JSON.stringify({
|
|
105
|
+
isFile: stat.isFile(),
|
|
106
|
+
isDirectory: stat.isDirectory(),
|
|
107
|
+
size: stat.size,
|
|
108
|
+
mtime: stat.mtime.getTime(),
|
|
109
|
+
});
|
|
110
|
+
const [offset] = this.writeString(result);
|
|
111
|
+
return offset;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
hostKvGet(keyPtr, keyLen) {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
hostKvPut(keyPtr, keyLen, valPtr, valLen) {
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
hostKvQuery(queryPtr, queryLen) {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
hostFetch(urlPtr, urlLen, optsPtr, optsLen) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
hostVecSearch(queryPtr, queryLen) {
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
hostVecEmbed(textPtr, textLen) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
hostBrowserSpawn(urlPtr, urlLen) {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
hostBrowserEval(sessionPtr, sessionLen, jsPtr, jsLen) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
hostBrowserClose(sessionPtr, sessionLen) {
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
hostExecJs(codePtr, codeLen) {
|
|
154
|
+
try {
|
|
155
|
+
const code = this.readString(codePtr, codeLen);
|
|
156
|
+
const result = eval(`(${code})`);
|
|
157
|
+
const [offset] = this.writeString(JSON.stringify(result));
|
|
158
|
+
return offset;
|
|
159
|
+
} catch (err) {
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
hostLog(msgPtr, msgLen) {
|
|
165
|
+
const msg = this.readString(msgPtr, msgLen);
|
|
166
|
+
console.log(msg);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
hostNowMs() {
|
|
171
|
+
return Date.now();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
hostEnvGet(keyPtr, keyLen) {
|
|
175
|
+
const key = this.readString(keyPtr, keyLen);
|
|
176
|
+
const val = process.env[key] || '';
|
|
177
|
+
const [offset] = this.writeString(val);
|
|
178
|
+
return offset;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async dispatch(verb, body) {
|
|
182
|
+
if (!this.instance) {
|
|
183
|
+
const initResult = await this.init();
|
|
184
|
+
if (!initResult.ok) return initResult;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
|
189
|
+
const [verbOffset, verbLen] = this.writeString(verb);
|
|
190
|
+
const [bodyOffset, bodyLen] = this.writeString(bodyStr);
|
|
191
|
+
|
|
192
|
+
const resultPtr = this.instance.exports.dispatch_verb(verbOffset, verbLen, bodyOffset, bodyLen);
|
|
193
|
+
if (resultPtr === 0) {
|
|
194
|
+
return { ok: false, error: 'dispatch_verb returned null' };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const resultStr = this.readString(resultPtr, 1024);
|
|
198
|
+
try {
|
|
199
|
+
return JSON.parse(resultStr);
|
|
200
|
+
} catch {
|
|
201
|
+
return { ok: true, output: resultStr };
|
|
202
|
+
}
|
|
203
|
+
} catch (err) {
|
|
204
|
+
return { ok: false, error: err.message };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async hook(name, body) {
|
|
209
|
+
if (!this.instance) {
|
|
210
|
+
const initResult = await this.init();
|
|
211
|
+
if (!initResult.ok) return initResult;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
|
216
|
+
const [nameOffset, nameLen] = this.writeString(name);
|
|
217
|
+
const [bodyOffset, bodyLen] = this.writeString(bodyStr);
|
|
218
|
+
|
|
219
|
+
const hookFn = this.instance.exports[`hook_${name}`];
|
|
220
|
+
if (!hookFn) {
|
|
221
|
+
return { ok: false, error: `hook_${name} not found` };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const resultPtr = hookFn(bodyOffset, bodyLen);
|
|
225
|
+
if (resultPtr === 0) {
|
|
226
|
+
return { ok: false, error: `hook_${name} returned null` };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const resultStr = this.readString(resultPtr, 1024);
|
|
230
|
+
try {
|
|
231
|
+
return JSON.parse(resultStr);
|
|
232
|
+
} catch {
|
|
233
|
+
return { ok: true, output: resultStr };
|
|
234
|
+
}
|
|
235
|
+
} catch (err) {
|
|
236
|
+
return { ok: false, error: err.message };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
module.exports = WasmHost;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-codex",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1076",
|
|
4
4
|
"description": "Spool-dispatch orchestration engine with unified state machine, skills, and automated git enforcement",
|
|
5
5
|
"author": "AnEntrypoint",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"hooks/",
|
|
29
29
|
"agents/",
|
|
30
30
|
"bin/",
|
|
31
|
+
"lib/",
|
|
31
32
|
"scripts/",
|
|
32
33
|
"skills/",
|
|
33
34
|
"assets/",
|
|
@@ -52,5 +53,8 @@
|
|
|
52
53
|
"mcp",
|
|
53
54
|
"automation",
|
|
54
55
|
"gm"
|
|
55
|
-
]
|
|
56
|
+
],
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"gm-plugkit": "*"
|
|
59
|
+
}
|
|
56
60
|
}
|