mneme-ai 2.108.0 → 2.110.0
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/dist/commands/absorb.d.ts +11 -0
- package/dist/commands/absorb.d.ts.map +1 -0
- package/dist/commands/absorb.js +105 -0
- package/dist/commands/absorb.js.map +1 -0
- package/dist/commands/loopguard.d.ts +13 -0
- package/dist/commands/loopguard.d.ts.map +1 -0
- package/dist/commands/loopguard.js +128 -0
- package/dist/commands/loopguard.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +73 -73
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme absorb` (v2.109.0) — pipe a command's output in; Mneme deterministically
|
|
3
|
+
* extracts {intent, error-class, excerpt} and files it as a SIGNED Cortex fact
|
|
4
|
+
* (recall by any agent). If it's an error and you pass --fix, it also teaches
|
|
5
|
+
* the Shell Autopilot — closing the loop: absorb (learn) → autopilot (suggest).
|
|
6
|
+
*
|
|
7
|
+
* mycmd 2>&1 | mneme absorb --cmd "mycmd" --code $?
|
|
8
|
+
*/
|
|
9
|
+
import type { Command } from "commander";
|
|
10
|
+
export declare function registerAbsorbCommands(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=absorb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"absorb.d.ts","sourceRoot":"","sources":["../../src/commands/absorb.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+BzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyC7D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme absorb` (v2.109.0) — pipe a command's output in; Mneme deterministically
|
|
3
|
+
* extracts {intent, error-class, excerpt} and files it as a SIGNED Cortex fact
|
|
4
|
+
* (recall by any agent). If it's an error and you pass --fix, it also teaches
|
|
5
|
+
* the Shell Autopilot — closing the loop: absorb (learn) → autopilot (suggest).
|
|
6
|
+
*
|
|
7
|
+
* mycmd 2>&1 | mneme absorb --cmd "mycmd" --code $?
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync } from "node:fs";
|
|
10
|
+
import { join, dirname } from "node:path";
|
|
11
|
+
function writeJson(p) { process.stdout.write(JSON.stringify(p, null, 2) + "\n"); }
|
|
12
|
+
function writeText(l) { process.stdout.write(l + "\n"); }
|
|
13
|
+
async function core() {
|
|
14
|
+
try {
|
|
15
|
+
const c = (await import("@mneme-ai/core"));
|
|
16
|
+
if (c.logpipe && c.cortex)
|
|
17
|
+
return c;
|
|
18
|
+
}
|
|
19
|
+
catch { /* */ }
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function cortexPath(cwd) { return join(cwd, ".mneme", "cortex", "store.json"); }
|
|
23
|
+
function readStdin() {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
if (process.stdin.isTTY)
|
|
26
|
+
return resolve("");
|
|
27
|
+
let data = "";
|
|
28
|
+
let done = false;
|
|
29
|
+
const finish = () => { if (!done) {
|
|
30
|
+
done = true;
|
|
31
|
+
resolve(data);
|
|
32
|
+
} };
|
|
33
|
+
process.stdin.setEncoding("utf8");
|
|
34
|
+
process.stdin.on("data", (c) => { data += c; if (data.length > 2_000_000)
|
|
35
|
+
finish(); });
|
|
36
|
+
process.stdin.on("end", finish);
|
|
37
|
+
process.stdin.on("error", finish);
|
|
38
|
+
setTimeout(finish, 4000); // never hang
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function registerAbsorbCommands(program) {
|
|
42
|
+
program
|
|
43
|
+
.command("absorb")
|
|
44
|
+
.description("📥 LOGPIPE — pipe a command's output in; Mneme extracts {intent, error, fix} deterministically and files it as a SIGNED, recallable Cortex fact (cross-agent). With --fix it also teaches the Shell Autopilot (absorb→autopilot loop). Usage: `mycmd 2>&1 | mneme absorb --cmd \"mycmd\" --code $?`")
|
|
45
|
+
.option("--cmd <c>", "the command that produced the output", "")
|
|
46
|
+
.option("--code <n>", "exit code (else inferred from output)", (v) => parseInt(v, 10))
|
|
47
|
+
.option("--fix <f>", "the command that FIXED this error (teaches the autopilot)")
|
|
48
|
+
.option("--text <t>", "output text inline (else read from stdin)")
|
|
49
|
+
.option("--agent <a>", "agent id", "absorb")
|
|
50
|
+
.option("--json", "JSON output.")
|
|
51
|
+
.action(async (opts) => {
|
|
52
|
+
const m = await core();
|
|
53
|
+
if (!m) {
|
|
54
|
+
writeText("✗ core unavailable");
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const cwd = process.cwd();
|
|
59
|
+
const output = typeof opts.text === "string" ? opts.text : await readStdin();
|
|
60
|
+
const entry = m.logpipe.extractLogEntry(opts.cmd ?? "", output, typeof opts.code === "number" ? opts.code : NaN);
|
|
61
|
+
const f = m.logpipe.formatForCortex(entry);
|
|
62
|
+
// store as a signed cortex fact
|
|
63
|
+
let store = { v: 1, entries: [] };
|
|
64
|
+
try {
|
|
65
|
+
if (existsSync(cortexPath(cwd)))
|
|
66
|
+
store = JSON.parse(readFileSync(cortexPath(cwd), "utf8"));
|
|
67
|
+
}
|
|
68
|
+
catch { /* */ }
|
|
69
|
+
const out = m.cortex.contribute(cwd, store, { agent: opts.agent ?? "absorb", key: f.key, value: f.value, kind: f.kind }, Date.now());
|
|
70
|
+
store = out.store;
|
|
71
|
+
// close the loop: an error + a known fix → teach the autopilot
|
|
72
|
+
let taught = false;
|
|
73
|
+
if (entry.hadError && opts.fix) {
|
|
74
|
+
const rk = m.shellAutopilot.recoveryKey(entry.signature);
|
|
75
|
+
const o2 = m.cortex.contribute(cwd, store, { agent: opts.agent ?? "absorb", key: rk, value: opts.fix, kind: "fact" }, Date.now(), { update: true });
|
|
76
|
+
store = o2.store;
|
|
77
|
+
taught = true;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const dir = join(cwd, ".mneme", "cortex");
|
|
81
|
+
if (!existsSync(dir))
|
|
82
|
+
mkdirSync(dir, { recursive: true });
|
|
83
|
+
writeFileSync(cortexPath(cwd), JSON.stringify(store, null, 2));
|
|
84
|
+
}
|
|
85
|
+
catch { /* */ }
|
|
86
|
+
// feed the LOOPGUARD ledger (objective thrash detection + `mneme resume`)
|
|
87
|
+
try {
|
|
88
|
+
const ev = m.loopguard.toEvent(entry, Date.now());
|
|
89
|
+
const lp = join(cwd, m.loopguard.LOOPGUARD_LEDGER);
|
|
90
|
+
if (!existsSync(dirname(lp)))
|
|
91
|
+
mkdirSync(dirname(lp), { recursive: true });
|
|
92
|
+
appendFileSync(lp, JSON.stringify(ev) + "\n");
|
|
93
|
+
}
|
|
94
|
+
catch { /* */ }
|
|
95
|
+
if (opts.json) {
|
|
96
|
+
writeJson({ entry, cortex: out.result.verdict, taughtAutopilot: taught });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
writeText(`📥 ${entry.intent}`);
|
|
100
|
+
if (entry.hadError)
|
|
101
|
+
writeText(` error[${entry.errorClass}]: ${entry.excerpt}`);
|
|
102
|
+
writeText(` → cortex (${out.result.verdict})${taught ? " · taught the autopilot a recovery" : ""}`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=absorb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"absorb.js","sourceRoot":"","sources":["../../src/commands/absorb.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,SAAS,SAAS,CAAC,CAAU,IAAU,OAAO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KAAK,CAAC,CAAC;QACjB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QACrG,SAAS,CAAC,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAChC,IAAI,KAAK,CAAC,QAAQ;YAAE,SAAS,CAAC,YAAY,KAAK,CAAC,UAAU,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACjF,SAAS,CAAC,gBAAgB,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme loopguard` + `mneme resume` (v2.110.0) — the honest core of Terminal
|
|
3
|
+
* Cognitive Telemetry. Reads the LOOPGUARD event ledger (fed by `mneme absorb`)
|
|
4
|
+
* and answers two deterministic questions:
|
|
5
|
+
* - loopguard: are we THRASHING on the same failure right now? (objective)
|
|
6
|
+
* - resume: where did this session leave off? (deterministic reconstruction)
|
|
7
|
+
*
|
|
8
|
+
* No mind-reading, no LLM — a sequence of events → a verdict. The known fix is
|
|
9
|
+
* recalled from the COGNITIVE CORTEX (learned shell recoveries).
|
|
10
|
+
*/
|
|
11
|
+
import type { Command } from "commander";
|
|
12
|
+
export declare function registerLoopguardCommands(program: Command): void;
|
|
13
|
+
//# sourceMappingURL=loopguard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopguard.d.ts","sourceRoot":"","sources":["../../src/commands/loopguard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmCzC,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4ChE"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme loopguard` + `mneme resume` (v2.110.0) — the honest core of Terminal
|
|
3
|
+
* Cognitive Telemetry. Reads the LOOPGUARD event ledger (fed by `mneme absorb`)
|
|
4
|
+
* and answers two deterministic questions:
|
|
5
|
+
* - loopguard: are we THRASHING on the same failure right now? (objective)
|
|
6
|
+
* - resume: where did this session leave off? (deterministic reconstruction)
|
|
7
|
+
*
|
|
8
|
+
* No mind-reading, no LLM — a sequence of events → a verdict. The known fix is
|
|
9
|
+
* recalled from the COGNITIVE CORTEX (learned shell recoveries).
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
function writeJson(p) { process.stdout.write(JSON.stringify(p, null, 2) + "\n"); }
|
|
14
|
+
function writeText(l) { process.stdout.write(l + "\n"); }
|
|
15
|
+
async function core() {
|
|
16
|
+
try {
|
|
17
|
+
const c = (await import("@mneme-ai/core"));
|
|
18
|
+
if (c.loopguard)
|
|
19
|
+
return c;
|
|
20
|
+
}
|
|
21
|
+
catch { /* */ }
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function loadEvents(m, cwd) {
|
|
25
|
+
try {
|
|
26
|
+
const p = join(cwd, m.loopguard.LOOPGUARD_LEDGER);
|
|
27
|
+
if (!existsSync(p))
|
|
28
|
+
return [];
|
|
29
|
+
return m.loopguard.parseLedger(readFileSync(p, "utf8"));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function loadStore(cwd) {
|
|
36
|
+
try {
|
|
37
|
+
const p = join(cwd, ".mneme", "cortex", "store.json");
|
|
38
|
+
if (existsSync(p))
|
|
39
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
40
|
+
}
|
|
41
|
+
catch { /* */ }
|
|
42
|
+
return { v: 1, entries: [] };
|
|
43
|
+
}
|
|
44
|
+
/** recall a learned recovery for a failure signature from the cortex. */
|
|
45
|
+
function makeRecall(m, cwd) {
|
|
46
|
+
const view = (() => { try {
|
|
47
|
+
return m.cortex.activeView(loadStore(cwd));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return new Map();
|
|
51
|
+
} })();
|
|
52
|
+
return (sig) => { try {
|
|
53
|
+
const e = view.get(m.shellAutopilot.recoveryKey(sig));
|
|
54
|
+
return e && typeof e.value === "string" && e.value.length > 0 ? e.value : null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
} };
|
|
59
|
+
}
|
|
60
|
+
export function registerLoopguardCommands(program) {
|
|
61
|
+
program
|
|
62
|
+
.command("loopguard")
|
|
63
|
+
.description("🔁 LOOPGUARD — are you (or an agent) THRASHING? Detects when the SAME failure repeats ≥N times with no success in between (objective, not mind-reading) and surfaces what's already known. Reads the ledger fed by `mneme absorb`.")
|
|
64
|
+
.option("--threshold <n>", "repeats before it's a thrash", (v) => parseInt(v, 10), 3)
|
|
65
|
+
.option("--window <min>", "trailing window in minutes", (v) => parseInt(v, 10), 15)
|
|
66
|
+
.option("--json", "JSON output.")
|
|
67
|
+
.action(async (opts) => {
|
|
68
|
+
const m = await core();
|
|
69
|
+
if (!m) {
|
|
70
|
+
writeText("✗ core unavailable");
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const cwd = process.cwd();
|
|
75
|
+
const events = loadEvents(m, cwd);
|
|
76
|
+
const v = m.loopguard.detectStuck(events, { threshold: opts.threshold, windowMs: (opts.window ?? 15) * 60_000 });
|
|
77
|
+
if (opts.json) {
|
|
78
|
+
writeJson(v);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!v.stuck) {
|
|
82
|
+
writeText(`✓ no thrash detected (${events.length} events) — ${v.reason}`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const recall = makeRecall(m, cwd);
|
|
86
|
+
const fix = recall(v.signature);
|
|
87
|
+
writeText(`🔁 THRASH: \`${v.command}\` failed ${v.repeats}× (signature ${v.signature})`);
|
|
88
|
+
writeText(` ${v.reason}`);
|
|
89
|
+
if (fix)
|
|
90
|
+
writeText(` 💡 known recovery (recalled): ${fix}`);
|
|
91
|
+
else
|
|
92
|
+
writeText(` (no learned recovery yet — teach one: mneme absorb --cmd "${v.command}" --code 1 --fix "<the fix>")`);
|
|
93
|
+
});
|
|
94
|
+
program
|
|
95
|
+
.command("resume")
|
|
96
|
+
.description("⏸▶ RESUME — pull your focus back in 3 seconds. Deterministically reconstructs where this session left off from the `mneme absorb` ledger: last command, last UNRESOLVED error, repeated failures, and the known next move.")
|
|
97
|
+
.option("--json", "JSON output.")
|
|
98
|
+
.action(async (opts) => {
|
|
99
|
+
const m = await core();
|
|
100
|
+
if (!m) {
|
|
101
|
+
writeText("✗ core unavailable");
|
|
102
|
+
process.exitCode = 1;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const cwd = process.cwd();
|
|
106
|
+
const events = loadEvents(m, cwd);
|
|
107
|
+
const recall = makeRecall(m, cwd);
|
|
108
|
+
const r = m.loopguard.summarizeSession(events, recall);
|
|
109
|
+
if (opts.json) {
|
|
110
|
+
writeJson(r);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
writeText(`▶ ${r.headline}`);
|
|
114
|
+
if (r.lastError && !r.resolved) {
|
|
115
|
+
writeText(` ✗ open error: ${r.lastError}`);
|
|
116
|
+
if (r.suggestion)
|
|
117
|
+
writeText(` 💡 known fix: ${r.suggestion}`);
|
|
118
|
+
}
|
|
119
|
+
if (r.stuck.stuck)
|
|
120
|
+
writeText(` 🔁 you are thrashing on this (${r.stuck.repeats}×) — stop and try the known fix above`);
|
|
121
|
+
if (r.repeatedFailures.length > 0) {
|
|
122
|
+
writeText(` repeated failures:`);
|
|
123
|
+
for (const f of r.repeatedFailures.slice(0, 5))
|
|
124
|
+
writeText(` ${f.count}× ${f.base} (${f.signature})`);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=loopguard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopguard.js","sourceRoot":"","sources":["../../src/commands/loopguard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,SAAS,SAAS,CAAC,CAAU,IAAU,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACjG,SAAS,SAAS,CAAC,CAAS,IAAU,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAYvE,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QAAC,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAsB,CAAC;QAAC,IAAI,CAAC,CAAC,SAAS;YAAE,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IACnH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAAC,CAAS,EAAE,GAAW;IACxC,IAAI,CAAC;QAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,CAAC;QAAC,OAAO,CAAC,CAAC,SAAS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AAC,CAAC,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QACxC,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,oBAAoB,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;YAC7C,IAAI,CAAC,CAAC,UAAU;gBAAE,SAAS,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK;YAAE,SAAS,CAAC,oCAAoC,CAAC,CAAC,KAAK,CAAC,OAAO,uCAAuC,CAAC,CAAC;QACzH,IAAI,CAAC,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,SAAS,CAAC,uBAAuB,CAAC,CAAC;YACnC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+IA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAy+MvD"}
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,8 @@ import { registerCortexCommands } from "./commands/cortex.js";
|
|
|
74
74
|
import { registerShellCommands } from "./commands/shell.js";
|
|
75
75
|
import { registerDigCommands } from "./commands/dig.js";
|
|
76
76
|
import { registerEntropyCommands } from "./commands/entropy.js";
|
|
77
|
+
import { registerAbsorbCommands } from "./commands/absorb.js";
|
|
78
|
+
import { registerLoopguardCommands } from "./commands/loopguard.js";
|
|
77
79
|
import { registerTrustCommands } from "./commands/trust.js";
|
|
78
80
|
import { registerNuclearCommands } from "./commands/nuclear-cli.js";
|
|
79
81
|
import { registerOvernightCommand } from "./commands/overnight.js";
|
|
@@ -4693,6 +4695,8 @@ export async function run(argv) {
|
|
|
4693
4695
|
registerShellCommands(program);
|
|
4694
4696
|
registerDigCommands(program);
|
|
4695
4697
|
registerEntropyCommands(program);
|
|
4698
|
+
registerAbsorbCommands(program);
|
|
4699
|
+
registerLoopguardCommands(program);
|
|
4696
4700
|
// ─── Trust calibrator (v1.31.0) -- per-subsystem precision/recall/band
|
|
4697
4701
|
registerTrustCommands(program);
|
|
4698
4702
|
// ─── Wisdom reactor (v1.33.0) -- five nuclear-physics formulas as Mneme metrics
|