mneme-ai 2.142.0 → 2.143.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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `mneme drift` (v2.143.0) — Mission-Drift Detection (Context Forensics). Run an
3
+ * EWMA statistical-process-control chart over an agent's action stream to catch
4
+ * it slowly straying from its declared mission.
5
+ *
6
+ * mneme telos --mission "refactor auth" --scope "src/auth/**" --actions log.jsonl
7
+ * cat actions.jsonl | mneme telos --mission "..." --actions -
8
+ *
9
+ * actions.jsonl: one JSON per line — {"turn":N,"summary":"...","files":["..."],"riskClass":"write"}
10
+ * Exit 2 on DIVERGENT. HONEST: measures movement from the agent's own baseline,
11
+ * not a prediction; abstains UNKNOWN on thin data.
12
+ */
13
+ import type { Command } from "commander";
14
+ export declare function registerDriftCommands(program: Command): void;
15
+ //# sourceMappingURL=drift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/commands/drift.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyBzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA8B5D"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * `mneme drift` (v2.143.0) — Mission-Drift Detection (Context Forensics). Run an
3
+ * EWMA statistical-process-control chart over an agent's action stream to catch
4
+ * it slowly straying from its declared mission.
5
+ *
6
+ * mneme telos --mission "refactor auth" --scope "src/auth/**" --actions log.jsonl
7
+ * cat actions.jsonl | mneme telos --mission "..." --actions -
8
+ *
9
+ * actions.jsonl: one JSON per line — {"turn":N,"summary":"...","files":["..."],"riskClass":"write"}
10
+ * Exit 2 on DIVERGENT. HONEST: measures movement from the agent's own baseline,
11
+ * not a prediction; abstains UNKNOWN on thin data.
12
+ */
13
+ import { existsSync, readFileSync } from "node:fs";
14
+ import { drift, notary } from "@mneme-ai/core";
15
+ function out(s) { process.stdout.write(s + "\n"); }
16
+ function splitList(v) { return typeof v === "string" && v.trim() ? v.split(",").map((s) => s.trim()).filter(Boolean) : []; }
17
+ function readActions(file) {
18
+ try {
19
+ const raw = file === "-" ? readFileSync(0, "utf8") : (file && existsSync(file) ? readFileSync(file, "utf8") : "");
20
+ const acts = [];
21
+ raw.split("\n").forEach((line, i) => {
22
+ if (!line.trim())
23
+ return;
24
+ try {
25
+ const j = JSON.parse(line);
26
+ acts.push({ turn: Number(j.turn) || i + 1, summary: String(j.summary ?? ""), files: Array.isArray(j.files) ? j.files.map(String) : undefined, riskClass: j.riskClass });
27
+ }
28
+ catch { /* skip */ }
29
+ });
30
+ return acts;
31
+ }
32
+ catch {
33
+ return [];
34
+ }
35
+ }
36
+ function sparkline(series, ucl) {
37
+ const blocks = "▁▂▃▄▅▆▇█";
38
+ const max = Math.max(ucl, ...series, 0.001);
39
+ return series.map((v) => { const idx = Math.min(blocks.length - 1, Math.floor((v / max) * (blocks.length - 1))); return v > ucl ? "❗" : blocks[idx]; }).join("");
40
+ }
41
+ export function registerDriftCommands(program) {
42
+ program
43
+ .command("telos")
44
+ .alias("mission-drift")
45
+ .description("🧭 TELOS (Mission Drift) — catch an agent slowly straying from its declared mission/telos across turns. Runs an EWMA statistical-process-control chart over a deterministic off-mission signal (off-scope files · off-topic vs the mission keywords · risk-class), with a control limit from the agent's OWN early baseline → band STABLE / DRIFTING / DIVERGENT / UNKNOWN. Reads an actions JSONL. Exit 2 on DIVERGENT. HONEST: measures movement from baseline, NOT a prediction; abstains UNKNOWN on thin data. (The trend layer — distinct from `mneme overshoot`'s one-shot plan compare.)")
46
+ .requiredOption("--mission <goal>", "the declared mission/goal")
47
+ .option("--scope <globs>", "comma-separated allowed path globs (e.g. \"src/auth/**\")")
48
+ .option("--keywords <list>", "comma-separated mission vocabulary (else derived from the goal)")
49
+ .requiredOption("--actions <file>", "JSONL of agent actions ({turn,summary,files,riskClass}); '-' = stdin")
50
+ .option("--lambda <n>", "EWMA smoothing 0..1 (default 0.3)", (v) => parseFloat(v))
51
+ .option("--json", "JSON output (signed)")
52
+ .action((opts) => {
53
+ const cwd = process.cwd();
54
+ const mission = { goal: opts.mission, scopeGlobs: splitList(opts.scope), keywords: splitList(opts.keywords) };
55
+ const actions = readActions(opts.actions);
56
+ const r = drift.analyzeDrift(mission, actions, opts.lambda !== undefined ? { lambda: opts.lambda } : undefined);
57
+ let receipt = null;
58
+ try {
59
+ receipt = notary.issueReceipt(cwd, { kind: "claim-verdict", subject: `drift:${r.band}`, payload: { band: r.band, driftScore: r.driftScore, ucl: r.ucl, firstBreachTurn: r.firstBreachTurn }, includePayload: true });
60
+ }
61
+ catch { /* */ }
62
+ if (opts.json) {
63
+ out(JSON.stringify({ ...r, signed: receipt }, null, 2));
64
+ process.exitCode = r.band === "DIVERGENT" ? 2 : 0;
65
+ return;
66
+ }
67
+ const icon = r.band === "DIVERGENT" ? "🛑" : r.band === "DRIFTING" ? "🟡" : r.band === "STABLE" ? "🟢" : "❔";
68
+ out(`${icon} MISSION DRIFT — ${r.band}`);
69
+ if (r.band === "UNKNOWN") {
70
+ out(` ${r.reasons[0] ?? "not enough data"}`);
71
+ out(` ${r.note}`);
72
+ process.exitCode = 0;
73
+ return;
74
+ }
75
+ out(` EWMA ${r.driftScore} vs baseline ${r.baseline.mean} · UCL ${r.ucl} · breaches ${r.breachCount}${r.firstBreachTurn !== null ? ` (first @ turn ${r.firstBreachTurn})` : ""}`);
76
+ out(` chart: ${sparkline(r.series, r.ucl)}`);
77
+ for (const reason of r.reasons)
78
+ out(` • ${reason}`);
79
+ if (r.offMissionRecent.length) {
80
+ out(" off-mission actions:");
81
+ for (const a of r.offMissionRecent)
82
+ out(` t${a.turn} (${a.score}) ${a.summary}`);
83
+ }
84
+ out(` ${receipt ? "✓ signed · " : ""}${r.note}`);
85
+ process.exitCode = r.band === "DIVERGENT" ? 2 : 0;
86
+ });
87
+ }
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G,eAAe,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpL,GAAG,CAAC,aAAa,SAAS,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/C,KAAK,MAAM,MAAM,IAAI,CAAC,CAAC,OAAO;YAAE,GAAG,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;YAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;YAAC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,gBAAgB;gBAAE,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAAC,CAAC;QACxJ,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoKA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA4hNvD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqKA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6hNvD"}
package/dist/index.js CHANGED
@@ -96,6 +96,7 @@ import { registerAxiaCommands } from "./commands/axia.js";
96
96
  import { registerPceCommands } from "./commands/pce.js";
97
97
  import { registerHauntCommands } from "./commands/haunt.js";
98
98
  import { registerCrucibleCommands } from "./commands/crucible.js";
99
+ import { registerDriftCommands } from "./commands/drift.js";
99
100
  import { attachRegretOracle } from "./commands/regret.js";
100
101
  import { registerTrustCommands } from "./commands/trust.js";
101
102
  import { registerNuclearCommands } from "./commands/nuclear-cli.js";
@@ -4745,6 +4746,7 @@ export async function run(argv) {
4745
4746
  registerPceCommands(program);
4746
4747
  registerHauntCommands(program);
4747
4748
  registerCrucibleCommands(program);
4749
+ registerDriftCommands(program);
4748
4750
  // ─── Trust calibrator (v1.31.0) -- per-subsystem precision/recall/band
4749
4751
  registerTrustCommands(program);
4750
4752
  // ─── Wisdom reactor (v1.33.0) -- five nuclear-physics formulas as Mneme metrics