@oooooooooo/ch0de 0.0.0-stage → 1.9.56
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/API-TESTING.md +76 -0
- package/DEBTAUR-INTEGRATION.md +71 -0
- package/EDITING.md +80 -0
- package/EXPERT-PANEL.md +16 -0
- package/INTEGRATIONS.md +75 -0
- package/LICENSE +21 -0
- package/MODELS-DEV-LICENSE +21 -0
- package/PROVIDER-CONNECTIONS.md +48 -0
- package/PROVIDERS.md +17 -0
- package/README.md +523 -2
- package/RELIABILITY.md +95 -0
- package/UX-1.3.md +83 -0
- package/UX-1.4.1.md +13 -0
- package/UX-1.4.md +48 -0
- package/UX-1.5.md +13 -0
- package/UX-1.6.md +7 -0
- package/UX-1.7.3.md +13 -0
- package/UX-1.7.4.md +13 -0
- package/UX-1.7.md +19 -0
- package/acceptance-check.js +27 -0
- package/agent-budget.js +4 -0
- package/api-testing.js +140 -0
- package/automatic-re.js +19 -0
- package/benchmarks/public-baselines.json +29 -0
- package/benchmarks/render-1.4.0.json +8 -0
- package/benchmarks/targets.js +11 -0
- package/browser-check.js +1062 -0
- package/build-progress.js +10 -0
- package/build-quality.js +49 -0
- package/chode.js +7937 -0
- package/debtaur-engine.js +305 -0
- package/debtaur-orchestration.js +456 -0
- package/debtaur-worker.cjs +76 -0
- package/doctor.js +24 -0
- package/edit-transactions.js +79 -0
- package/elapsed.js +28 -0
- package/evidence-ledger.js +26 -0
- package/expert-panel.cjs +42 -0
- package/helios-ledger.js +405 -0
- package/install.cjs +25 -0
- package/integrations.js +30 -0
- package/json-output.js +8 -0
- package/local-memory.js +613 -0
- package/local-models.js +52 -0
- package/mcp-client.js +50 -0
- package/memory.js +511 -0
- package/model-catalog.js +46 -0
- package/native-tools.js +27 -0
- package/nosignups.js +325 -0
- package/observation-progress.js +33 -0
- package/orchestrator.js +299 -0
- package/package.json +160 -6
- package/plan-z6.js +490 -0
- package/project-memory.js +27 -0
- package/provider-capacity.js +13 -0
- package/provider-catalog.js +246 -0
- package/provider-connect.js +66 -0
- package/provider-credentials.js +5 -0
- package/provider-directory.js +8 -0
- package/provider-directory.json +32300 -0
- package/provider-errors.js +11 -0
- package/provider-picker.js +188 -0
- package/provider-policy.js +4 -0
- package/provider-race.js +25 -0
- package/provider-request.js +45 -0
- package/provider-store.js +13 -0
- package/rea-environment.js +5 -0
- package/read-window.js +21 -0
- package/recovery-context.js +3 -0
- package/reliability-memory.js +38 -0
- package/reliability-services.js +34 -0
- package/reliability-store.js +16 -0
- package/request-deadline.js +4 -0
- package/serve-frontend.html +172 -0
- package/settings-reset.js +11 -0
- package/skill-catalog.js +16 -0
- package/task-group.js +22 -0
- package/terminal-graphics.js +39 -0
- package/terminal-logo.js +76 -0
- package/terminal-ui.js +79 -0
- package/tool-call-validation.js +26 -0
- package/tool-health.js +22 -0
- package/tool-history.js +5 -0
- package/toolbox.js +156 -0
- package/tui-provider-picker.js +134 -0
- package/tui-worker.js +32 -0
- package/web-context.js +232 -0
- package/wolfram-math.js +6 -0
- package/worker-transport.js +11 -0
- package/workspace-commands.js +45 -0
- package/workspace-log.js +56 -0
- package/workspace-store.js +7 -0
- package/workspace-tui.js +113 -0
- package/workspace-view.js +109 -0
- package/worktrees.js +18 -0
- package/z6-integration.js +227 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Private Debtaur runtime bridge. No engine source/binary is redistributed here.
|
|
3
|
+
const fs = require("fs"),
|
|
4
|
+
path = require("path"),
|
|
5
|
+
os = require("os"),
|
|
6
|
+
crypto = require("crypto"),
|
|
7
|
+
{ Worker } = require("worker_threads");
|
|
8
|
+
const PINNED = Object.freeze({
|
|
9
|
+
"judge_wasm.js":
|
|
10
|
+
"4be9fa032c2780d545e6e499c2062089b8b904b0b7d1b4bf7fc8aeb22f3eab0c",
|
|
11
|
+
"judge_wasm.wasm":
|
|
12
|
+
"e58ee25dc0c2dad6a1c61c20dae398aab0086f2e7675fe90765d18099cc110ac",
|
|
13
|
+
});
|
|
14
|
+
const hash = (value) => crypto.createHash("sha256").update(value).digest("hex");
|
|
15
|
+
function directory(options = {}) {
|
|
16
|
+
return (
|
|
17
|
+
options.runtimeDir ||
|
|
18
|
+
process.env.CHODE_DEBTAUR_RUNTIME ||
|
|
19
|
+
path.join(
|
|
20
|
+
process.env.CHODE_PROVIDER_HOME || os.homedir(),
|
|
21
|
+
".chode",
|
|
22
|
+
"runtimes",
|
|
23
|
+
"debtaur",
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function runtime(options = {}) {
|
|
28
|
+
const dir = path.resolve(directory(options)),
|
|
29
|
+
files = {};
|
|
30
|
+
for (const [name, expected] of Object.entries(PINNED)) {
|
|
31
|
+
const full = path.join(dir, name),
|
|
32
|
+
st = fs.lstatSync(full);
|
|
33
|
+
if (
|
|
34
|
+
!st.isFile() ||
|
|
35
|
+
st.isSymbolicLink() ||
|
|
36
|
+
st.nlink > 1 ||
|
|
37
|
+
st.size > 1024 * 1024
|
|
38
|
+
)
|
|
39
|
+
throw Error("Unsafe Debtaur runtime file");
|
|
40
|
+
const bytes = fs.readFileSync(full);
|
|
41
|
+
if (hash(bytes) !== expected)
|
|
42
|
+
throw Error("Debtaur runtime integrity mismatch: " + name);
|
|
43
|
+
files[name] = bytes;
|
|
44
|
+
}
|
|
45
|
+
return { directory: dir, files, id: hash(JSON.stringify(PINNED)) };
|
|
46
|
+
}
|
|
47
|
+
function status(options = {}) {
|
|
48
|
+
try {
|
|
49
|
+
const r = runtime(options);
|
|
50
|
+
return {
|
|
51
|
+
enabled: process.env.CHODE_DEBTAUR !== "off",
|
|
52
|
+
available: true,
|
|
53
|
+
backend: "debtaur-wasm",
|
|
54
|
+
runtimeHash: r.id,
|
|
55
|
+
directory: r.directory,
|
|
56
|
+
privateRuntime: true,
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
enabled: process.env.CHODE_DEBTAUR !== "off",
|
|
61
|
+
available: false,
|
|
62
|
+
backend: "unavailable",
|
|
63
|
+
reason:
|
|
64
|
+
error.code === "ENOENT"
|
|
65
|
+
? "Standalone Debtaur runtime is not installed"
|
|
66
|
+
: error.message,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function encode(operations) {
|
|
71
|
+
if (
|
|
72
|
+
!Array.isArray(operations) ||
|
|
73
|
+
!operations.length ||
|
|
74
|
+
operations.length > 48
|
|
75
|
+
)
|
|
76
|
+
throw Error("Debtaur batch must contain1–48 operations");
|
|
77
|
+
const wire =
|
|
78
|
+
operations
|
|
79
|
+
.map((row) => {
|
|
80
|
+
if (
|
|
81
|
+
!row ||
|
|
82
|
+
!["stated", "dreamt", "!", "-"].includes(row.op) ||
|
|
83
|
+
typeof row.clause !== "string" ||
|
|
84
|
+
!row.clause.trim() ||
|
|
85
|
+
Buffer.byteLength(row.clause) > 180 ||
|
|
86
|
+
/[\x00-\x1f\x7f]/.test(row.clause)
|
|
87
|
+
)
|
|
88
|
+
throw Error("Invalid Debtaur protocol operation");
|
|
89
|
+
return row.op + "\t" + row.clause;
|
|
90
|
+
})
|
|
91
|
+
.join("\n") + "\n";
|
|
92
|
+
if (Buffer.byteLength(wire) > 24000)
|
|
93
|
+
throw Error("Debtaur protocol batch too large");
|
|
94
|
+
return wire;
|
|
95
|
+
}
|
|
96
|
+
function decode(raw, operations) {
|
|
97
|
+
if (typeof raw !== "string" || Buffer.byteLength(raw) >= 524287)
|
|
98
|
+
throw Error("Invalid Debtaur response");
|
|
99
|
+
const rows = JSON.parse(raw);
|
|
100
|
+
if (!Array.isArray(rows) || rows.length !== operations.length)
|
|
101
|
+
throw Error("Debtaur protocol row count mismatch");
|
|
102
|
+
for (let i = 0; i < rows.length; i++) {
|
|
103
|
+
const row = rows[i],
|
|
104
|
+
op = operations[i].op,
|
|
105
|
+
expected = op === "!" ? "gate" : op === "-" ? "retract" : op;
|
|
106
|
+
if (!row || row.op !== expected)
|
|
107
|
+
throw Error("Debtaur protocol operation mismatch");
|
|
108
|
+
if (op === "!") {
|
|
109
|
+
if (
|
|
110
|
+
row.input !== operations[i].clause ||
|
|
111
|
+
!["allow", "deny", "refuted", "contradiction"].includes(row.verdict) ||
|
|
112
|
+
typeof row.allow !== "boolean" ||
|
|
113
|
+
row.allow !== (row.verdict === "allow") ||
|
|
114
|
+
typeof row.why !== "string" ||
|
|
115
|
+
!row.why.trim() ||
|
|
116
|
+
!["stated", "derived", "taught", "dreamt"].includes(row.provenance) ||
|
|
117
|
+
!row.evidence ||
|
|
118
|
+
!["asserted", "rules", "derived"].every(
|
|
119
|
+
(k) =>
|
|
120
|
+
Array.isArray(row.evidence[k]) &&
|
|
121
|
+
row.evidence[k].every((x) => typeof x === "string"),
|
|
122
|
+
) ||
|
|
123
|
+
(row.allow && row.provenance === "dreamt")
|
|
124
|
+
)
|
|
125
|
+
throw Error("Invalid Debtaur gate verdict");
|
|
126
|
+
} else if (op === "-") {
|
|
127
|
+
if (
|
|
128
|
+
typeof row.found !== "boolean" ||
|
|
129
|
+
!Number.isSafeInteger(row.died) ||
|
|
130
|
+
row.died < 0
|
|
131
|
+
)
|
|
132
|
+
throw Error("Invalid Debtaur retraction");
|
|
133
|
+
} else if (row.ok !== true) throw Error("Debtaur assertion refused");
|
|
134
|
+
}
|
|
135
|
+
return rows;
|
|
136
|
+
}
|
|
137
|
+
function create(options = {}) {
|
|
138
|
+
let worker = null,
|
|
139
|
+
next = 0,
|
|
140
|
+
closed = false,
|
|
141
|
+
failure = null;
|
|
142
|
+
const pending = new Map();
|
|
143
|
+
const info = status(options);
|
|
144
|
+
function fail(error) {
|
|
145
|
+
failure = String(error.message || error).slice(0, 180);
|
|
146
|
+
for (const p of pending.values()) {
|
|
147
|
+
clearTimeout(p.timer);
|
|
148
|
+
p.detach?.();
|
|
149
|
+
p.resolve({ status: "unavailable", reason: failure });
|
|
150
|
+
}
|
|
151
|
+
pending.clear();
|
|
152
|
+
if (worker) {
|
|
153
|
+
worker.terminate().catch(() => {});
|
|
154
|
+
worker = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function start() {
|
|
158
|
+
if (worker) return;
|
|
159
|
+
if (!info.available) throw Error(info.reason);
|
|
160
|
+
worker = new Worker(path.join(__dirname, "debtaur-worker.cjs"), {
|
|
161
|
+
workerData: { directory: directory(options), pinned: PINNED },
|
|
162
|
+
resourceLimits: { maxOldGenerationSizeMb: 96 },
|
|
163
|
+
});
|
|
164
|
+
worker.on("error", fail);
|
|
165
|
+
worker.on("exit", (code) => {
|
|
166
|
+
if (pending.size) fail(Error("Debtaur worker stopped (" + code + ")"));
|
|
167
|
+
});
|
|
168
|
+
worker.on("message", (message) => {
|
|
169
|
+
const p = pending.get(message.id);
|
|
170
|
+
if (!p) return;
|
|
171
|
+
clearTimeout(p.timer);
|
|
172
|
+
p.detach?.();
|
|
173
|
+
pending.delete(message.id);
|
|
174
|
+
if (!pending.size) worker?.unref();
|
|
175
|
+
try {
|
|
176
|
+
if (message.error) throw Error(message.error);
|
|
177
|
+
const rows = decode(message.raw, p.operations);
|
|
178
|
+
p.resolve({
|
|
179
|
+
status: "judged",
|
|
180
|
+
backend: "debtaur-wasm",
|
|
181
|
+
runtimeHash: info.runtimeHash,
|
|
182
|
+
inputHash: hash(p.wire),
|
|
183
|
+
outputHash: hash(message.raw),
|
|
184
|
+
rows,
|
|
185
|
+
});
|
|
186
|
+
} catch (error) {
|
|
187
|
+
p.resolve({
|
|
188
|
+
status: "unavailable",
|
|
189
|
+
reason: String(error.message).slice(0, 180),
|
|
190
|
+
});
|
|
191
|
+
fail(error);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async function run(operations, signal = options.signal) {
|
|
196
|
+
const wire = encode(operations);
|
|
197
|
+
if (signal?.aborted)
|
|
198
|
+
return { status: "unavailable", reason: "Debtaur request cancelled" };
|
|
199
|
+
if (closed || failure || !info.available)
|
|
200
|
+
return {
|
|
201
|
+
status: "unavailable",
|
|
202
|
+
reason: failure || info.reason || "Debtaur bridge closed",
|
|
203
|
+
};
|
|
204
|
+
if (pending.size >= 4)
|
|
205
|
+
return {
|
|
206
|
+
status: "unavailable",
|
|
207
|
+
reason: "Debtaur concurrency limit reached",
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
start();
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return { status: "unavailable", reason: error.message };
|
|
213
|
+
}
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
const id = ++next,
|
|
216
|
+
timeout = Math.max(10, Math.min(10000, options.timeoutMs || 5000)),
|
|
217
|
+
timer = setTimeout(
|
|
218
|
+
() => fail(Error("Debtaur deadline exceeded")),
|
|
219
|
+
timeout,
|
|
220
|
+
);
|
|
221
|
+
const cancel = () => fail(Error("Debtaur request cancelled"));
|
|
222
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
223
|
+
pending.set(id, {
|
|
224
|
+
resolve,
|
|
225
|
+
timer,
|
|
226
|
+
operations,
|
|
227
|
+
wire,
|
|
228
|
+
detach: () => signal?.removeEventListener("abort", cancel),
|
|
229
|
+
});
|
|
230
|
+
worker.ref();
|
|
231
|
+
worker.postMessage({ id, wire });
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function close() {
|
|
235
|
+
closed = true;
|
|
236
|
+
fail(Error("Debtaur bridge closed"));
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
run,
|
|
240
|
+
close,
|
|
241
|
+
status: () => ({
|
|
242
|
+
...info,
|
|
243
|
+
available: info.available && !failure && !closed,
|
|
244
|
+
reason: failure || info.reason,
|
|
245
|
+
}),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function install(source, options = {}) {
|
|
249
|
+
// Explicit local setup only: no private repository download or network request.
|
|
250
|
+
const candidate = runtime({ runtimeDir: source }),
|
|
251
|
+
target = path.resolve(directory(options));
|
|
252
|
+
if (path.resolve(source) === target) return status(options);
|
|
253
|
+
let at = path.parse(target).root;
|
|
254
|
+
for (const part of target.slice(at.length).split(path.sep).filter(Boolean)) {
|
|
255
|
+
at = path.join(at, part);
|
|
256
|
+
try {
|
|
257
|
+
const st = fs.lstatSync(at);
|
|
258
|
+
if (!st.isDirectory() || st.isSymbolicLink())
|
|
259
|
+
throw Error("Unsafe Debtaur installation directory");
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (error.code !== "ENOENT") throw error;
|
|
262
|
+
fs.mkdirSync(at, { mode: 0o700 });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Preserve any different/partial installation for explicit diagnosis.
|
|
266
|
+
for (const [name, bytes] of Object.entries(candidate.files)) {
|
|
267
|
+
const file = path.join(target, name);
|
|
268
|
+
if (fs.existsSync(file)) {
|
|
269
|
+
const st = fs.lstatSync(file);
|
|
270
|
+
if (
|
|
271
|
+
st.isSymbolicLink() ||
|
|
272
|
+
st.nlink > 1 ||
|
|
273
|
+
hash(fs.readFileSync(file)) !== PINNED[name]
|
|
274
|
+
)
|
|
275
|
+
throw Error("Existing Debtaur runtime differs; preserved for review");
|
|
276
|
+
} else fs.writeFileSync(file, bytes, { flag: "wx", mode: 0o600 });
|
|
277
|
+
}
|
|
278
|
+
return status(options);
|
|
279
|
+
}
|
|
280
|
+
module.exports = {
|
|
281
|
+
create,
|
|
282
|
+
status,
|
|
283
|
+
install,
|
|
284
|
+
encode,
|
|
285
|
+
decode,
|
|
286
|
+
runtime,
|
|
287
|
+
hash,
|
|
288
|
+
PINNED,
|
|
289
|
+
};
|
|
290
|
+
if (require.main === module) {
|
|
291
|
+
try {
|
|
292
|
+
const [verb, source] = process.argv.slice(2);
|
|
293
|
+
if (verb === "setup" && source)
|
|
294
|
+
console.log(JSON.stringify(install(source), null, 2));
|
|
295
|
+
else if (!verb || verb === "status")
|
|
296
|
+
console.log(JSON.stringify(status(), null, 2));
|
|
297
|
+
else
|
|
298
|
+
throw Error(
|
|
299
|
+
"Use node debtaur-engine.js status | setup <local-wasm-directory>",
|
|
300
|
+
);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
console.error(error.message);
|
|
303
|
+
process.exitCode = 1;
|
|
304
|
+
}
|
|
305
|
+
}
|