@mneme-ai/core 2.65.0 → 2.67.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.
Files changed (82) hide show
  1. package/dist/agent_manifest.d.ts.map +1 -1
  2. package/dist/agent_manifest.js +5 -0
  3. package/dist/agent_manifest.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +9 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/protoplasm/auto_wrap.d.ts +33 -0
  9. package/dist/protoplasm/auto_wrap.d.ts.map +1 -0
  10. package/dist/protoplasm/auto_wrap.js +72 -0
  11. package/dist/protoplasm/auto_wrap.js.map +1 -0
  12. package/dist/protoplasm/crawl_planner.d.ts +14 -0
  13. package/dist/protoplasm/crawl_planner.d.ts.map +1 -0
  14. package/dist/protoplasm/crawl_planner.js +50 -0
  15. package/dist/protoplasm/crawl_planner.js.map +1 -0
  16. package/dist/protoplasm/findings_ledger.d.ts +19 -0
  17. package/dist/protoplasm/findings_ledger.d.ts.map +1 -0
  18. package/dist/protoplasm/findings_ledger.js +81 -0
  19. package/dist/protoplasm/findings_ledger.js.map +1 -0
  20. package/dist/protoplasm/ghost_cell.d.ts +30 -0
  21. package/dist/protoplasm/ghost_cell.d.ts.map +1 -0
  22. package/dist/protoplasm/ghost_cell.js +95 -0
  23. package/dist/protoplasm/ghost_cell.js.map +1 -0
  24. package/dist/protoplasm/immortal.test.d.ts +12 -0
  25. package/dist/protoplasm/immortal.test.d.ts.map +1 -0
  26. package/dist/protoplasm/immortal.test.js +118 -0
  27. package/dist/protoplasm/immortal.test.js.map +1 -0
  28. package/dist/protoplasm/index.d.ts +42 -0
  29. package/dist/protoplasm/index.d.ts.map +1 -0
  30. package/dist/protoplasm/index.js +42 -0
  31. package/dist/protoplasm/index.js.map +1 -0
  32. package/dist/protoplasm/orchestrator.d.ts +29 -0
  33. package/dist/protoplasm/orchestrator.d.ts.map +1 -0
  34. package/dist/protoplasm/orchestrator.js +60 -0
  35. package/dist/protoplasm/orchestrator.js.map +1 -0
  36. package/dist/protoplasm/parasite.d.ts +42 -0
  37. package/dist/protoplasm/parasite.d.ts.map +1 -0
  38. package/dist/protoplasm/parasite.js +69 -0
  39. package/dist/protoplasm/parasite.js.map +1 -0
  40. package/dist/protoplasm/phoenix_hook.d.ts +49 -0
  41. package/dist/protoplasm/phoenix_hook.d.ts.map +1 -0
  42. package/dist/protoplasm/phoenix_hook.js +64 -0
  43. package/dist/protoplasm/phoenix_hook.js.map +1 -0
  44. package/dist/protoplasm/protoplasm.test.d.ts +13 -0
  45. package/dist/protoplasm/protoplasm.test.d.ts.map +1 -0
  46. package/dist/protoplasm/protoplasm.test.js +142 -0
  47. package/dist/protoplasm/protoplasm.test.js.map +1 -0
  48. package/dist/protoplasm/quantum_probe.d.ts +21 -0
  49. package/dist/protoplasm/quantum_probe.d.ts.map +1 -0
  50. package/dist/protoplasm/quantum_probe.js +118 -0
  51. package/dist/protoplasm/quantum_probe.js.map +1 -0
  52. package/dist/protoplasm/seamless_boot.d.ts +28 -0
  53. package/dist/protoplasm/seamless_boot.d.ts.map +1 -0
  54. package/dist/protoplasm/seamless_boot.js +106 -0
  55. package/dist/protoplasm/seamless_boot.js.map +1 -0
  56. package/dist/protoplasm/super_quan_probe.d.ts +24 -0
  57. package/dist/protoplasm/super_quan_probe.d.ts.map +1 -0
  58. package/dist/protoplasm/super_quan_probe.js +132 -0
  59. package/dist/protoplasm/super_quan_probe.js.map +1 -0
  60. package/dist/protoplasm/types.d.ts +84 -0
  61. package/dist/protoplasm/types.d.ts.map +1 -0
  62. package/dist/protoplasm/types.js +9 -0
  63. package/dist/protoplasm/types.js.map +1 -0
  64. package/dist/protoplasm/wal.d.ts +46 -0
  65. package/dist/protoplasm/wal.d.ts.map +1 -0
  66. package/dist/protoplasm/wal.js +145 -0
  67. package/dist/protoplasm/wal.js.map +1 -0
  68. package/dist/protoplasm/wisdom_space.d.ts +30 -0
  69. package/dist/protoplasm/wisdom_space.d.ts.map +1 -0
  70. package/dist/protoplasm/wisdom_space.js +77 -0
  71. package/dist/protoplasm/wisdom_space.js.map +1 -0
  72. package/dist/reflog/index.d.ts +165 -0
  73. package/dist/reflog/index.d.ts.map +1 -0
  74. package/dist/reflog/index.js +406 -0
  75. package/dist/reflog/index.js.map +1 -0
  76. package/dist/truth_gate/claims.d.ts.map +1 -1
  77. package/dist/truth_gate/claims.js +37 -0
  78. package/dist/truth_gate/claims.js.map +1 -1
  79. package/dist/truth_gate/probes.d.ts.map +1 -1
  80. package/dist/truth_gate/probes.js +103 -0
  81. package/dist/truth_gate/probes.js.map +1 -1
  82. package/package.json +1 -1
@@ -0,0 +1,84 @@
1
+ /**
2
+ * 🦠 PROTOPLASM — types
3
+ *
4
+ * Live atom embedded in every function. Reports super_quan findings to
5
+ * orchestrator. Orchestrator decides: HEALTHY → crawl-and-learn,
6
+ * BROKEN → wisdom-space root-cause + heal.
7
+ */
8
+ export type ProbeOutcome = "healthy" | "warn" | "broken";
9
+ /** A single recorded invocation snapshot. */
10
+ export interface InvocationSnapshot {
11
+ fnId: string;
12
+ ts: string;
13
+ durationMs: number;
14
+ args: {
15
+ count: number;
16
+ shape: string;
17
+ };
18
+ output: {
19
+ kind: "ok" | "throw";
20
+ shape?: string;
21
+ errorClass?: string;
22
+ };
23
+ }
24
+ /** Statistical baseline for a single function (rolling). */
25
+ export interface FunctionBaseline {
26
+ fnId: string;
27
+ samples: number;
28
+ durationMean: number;
29
+ durationStdev: number;
30
+ errorRate: number;
31
+ argShapeEntropy: number;
32
+ outputShapeEntropy: number;
33
+ lastUpdate: string;
34
+ }
35
+ /** Result of a single super_quan probe run. */
36
+ export interface SuperQuanFinding {
37
+ fnId: string;
38
+ at: string;
39
+ outcome: ProbeOutcome;
40
+ zScores: Record<string, number>;
41
+ quantumSignals: QuantumSignals;
42
+ rootCauseHints: string[];
43
+ evidence: string;
44
+ hmac: string;
45
+ prev: string;
46
+ }
47
+ /** Quantum-inspired signals (analogues, not literal QM). */
48
+ export interface QuantumSignals {
49
+ /** Shannon entropy of output distribution. Low = collapse to single state. High = decoherence. */
50
+ outputEntropy: number;
51
+ /** Chaos-input divergence — how much the function's output varies given structured perturbation. */
52
+ chaosDivergence: number;
53
+ /** Cross-function correlation — does this function's broken state coincide w/ neighbors? */
54
+ neighborCorrelation: number;
55
+ /** Superposition collapse score — proportion of calls that produce typed output vs throw. */
56
+ collapseStability: number;
57
+ }
58
+ export interface WisdomRootCause {
59
+ fnId: string;
60
+ hypothesis: string;
61
+ upstreamSuspects: string[];
62
+ confidence: number;
63
+ proposedHeal: HealAction[];
64
+ }
65
+ export interface HealAction {
66
+ kind: "retry-with-backoff" | "fallback-to-cached" | "request-supernova-restart" | "raise-truth-gate-block" | "noop";
67
+ rationale: string;
68
+ }
69
+ export interface CrawlPlan {
70
+ trigger: "healthy-burst" | "scheduled" | "manual";
71
+ fnId: string;
72
+ searchTopics: string[];
73
+ budgetMs: number;
74
+ estimatedROI: number;
75
+ }
76
+ export interface ProtoplasmConfig {
77
+ baselineSamplesMin: number;
78
+ zScoreWarn: number;
79
+ zScoreBroken: number;
80
+ ledgerDir: string;
81
+ hmacKey: string;
82
+ crawlOnHealthyEvery: number;
83
+ }
84
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/protoplasm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEzD,6CAA6C;AAC7C,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,MAAM,EAAE;QA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IAAI,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,2BAA2B,GAAG,wBAAwB,GAAG,MAAM,CAAC;IACpH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,eAAe,GAAG,WAAW,GAAG,QAAQ,CAAC;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 🦠 PROTOPLASM — types
3
+ *
4
+ * Live atom embedded in every function. Reports super_quan findings to
5
+ * orchestrator. Orchestrator decides: HEALTHY → crawl-and-learn,
6
+ * BROKEN → wisdom-space root-cause + heal.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/protoplasm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 🩸 PROTOPLASM — WAL (Write-Ahead Log)
3
+ *
4
+ * Survives uncatchable kills (SIGKILL, SIGSEGV, OS reboot).
5
+ *
6
+ * Strategy: every baseline mutation persists to disk BEFORE RAM update.
7
+ * Process death = baseline survives. Next start reads WAL → reconstructs.
8
+ *
9
+ * WAL format: append-only JSONL at .mneme/protoplasm/wal.jsonl
10
+ * Each row = { ts, fnId, op, payload, prevHmac, hmac }
11
+ *
12
+ * Compaction: when WAL exceeds 5MB, snapshot baselines to baselines.json
13
+ * + truncate WAL to entries since snapshot.
14
+ */
15
+ import type { FunctionBaseline } from "./types.js";
16
+ export type WalOp = "baseline_set" | "buffer_evict" | "config_set";
17
+ export interface WalRow {
18
+ ts: string;
19
+ fnId: string;
20
+ op: WalOp;
21
+ payload: unknown;
22
+ prevHmac: string;
23
+ hmac: string;
24
+ }
25
+ export declare class Wal {
26
+ private path;
27
+ private secret;
28
+ private lastHmac;
29
+ private compactionThresholdBytes;
30
+ constructor(walDir: string, secret: string);
31
+ private computeLastHmac;
32
+ /** Append op to WAL. Synchronous + flush — survives unexpected death. */
33
+ append(op: WalOp, fnId: string, payload: unknown): WalRow;
34
+ /** Replay WAL → reconstruct baseline map. Idempotent. */
35
+ replay(): Map<string, FunctionBaseline>;
36
+ /** Verify chain integrity (chain HMAC continuity). */
37
+ verify(): {
38
+ ok: boolean;
39
+ rows: number;
40
+ brokenAt?: number;
41
+ };
42
+ /** Compact WAL → snapshot if file exceeds threshold. */
43
+ private maybeCompact;
44
+ path_for_test(): string;
45
+ }
46
+ //# sourceMappingURL=wal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wal.d.ts","sourceRoot":"","sources":["../../src/protoplasm/wal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,KAAK,GAAG,cAAc,GAAG,cAAc,GAAG,YAAY,CAAC;AAEnE,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,KAAK,CAAC;IACV,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAmBD,qBAAa,GAAG;IACd,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,wBAAwB,CAAmB;gBAEvC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO1C,OAAO,CAAC,eAAe;IAWvB,yEAAyE;IACzE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;IAUzD,yDAAyD;IACzD,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAsBvC,sDAAsD;IACtD,MAAM,IAAI;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAiB1D,wDAAwD;IACxD,OAAO,CAAC,YAAY;IAiBpB,aAAa,IAAI,MAAM;CACxB"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * 🩸 PROTOPLASM — WAL (Write-Ahead Log)
3
+ *
4
+ * Survives uncatchable kills (SIGKILL, SIGSEGV, OS reboot).
5
+ *
6
+ * Strategy: every baseline mutation persists to disk BEFORE RAM update.
7
+ * Process death = baseline survives. Next start reads WAL → reconstructs.
8
+ *
9
+ * WAL format: append-only JSONL at .mneme/protoplasm/wal.jsonl
10
+ * Each row = { ts, fnId, op, payload, prevHmac, hmac }
11
+ *
12
+ * Compaction: when WAL exceeds 5MB, snapshot baselines to baselines.json
13
+ * + truncate WAL to entries since snapshot.
14
+ */
15
+ import { existsSync, statSync, readFileSync, appendFileSync, writeFileSync, mkdirSync, renameSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import { createHmac } from "node:crypto";
18
+ /** Recursive canonical JSON: sort all keys at every depth, drop undefined. */
19
+ function canonical(v) {
20
+ if (v === null || typeof v !== "object")
21
+ return v;
22
+ if (Array.isArray(v))
23
+ return v.map(canonical);
24
+ const out = {};
25
+ for (const k of Object.keys(v).sort()) {
26
+ const val = v[k];
27
+ if (val !== undefined)
28
+ out[k] = canonical(val);
29
+ }
30
+ return out;
31
+ }
32
+ function hmacRow(prev, body, secret) {
33
+ const canon = JSON.stringify(canonical(body));
34
+ return createHmac("sha256", secret).update(prev + "::" + canon).digest("hex").slice(0, 16);
35
+ }
36
+ export class Wal {
37
+ path;
38
+ secret;
39
+ lastHmac = "0".repeat(16);
40
+ compactionThresholdBytes = 5 * 1024 * 1024; // 5MB
41
+ constructor(walDir, secret) {
42
+ mkdirSync(walDir, { recursive: true });
43
+ this.path = join(walDir, "wal.jsonl");
44
+ this.secret = secret;
45
+ this.lastHmac = this.computeLastHmac();
46
+ }
47
+ computeLastHmac() {
48
+ if (!existsSync(this.path))
49
+ return "0".repeat(16);
50
+ try {
51
+ const content = readFileSync(this.path, "utf8").trim();
52
+ if (!content)
53
+ return "0".repeat(16);
54
+ const lines = content.split("\n");
55
+ const last = JSON.parse(lines[lines.length - 1]);
56
+ return last.hmac;
57
+ }
58
+ catch {
59
+ return "0".repeat(16);
60
+ }
61
+ }
62
+ /** Append op to WAL. Synchronous + flush — survives unexpected death. */
63
+ append(op, fnId, payload) {
64
+ const body = { ts: new Date().toISOString(), fnId, op, payload, prevHmac: this.lastHmac };
65
+ const hmac = hmacRow(this.lastHmac, body, this.secret);
66
+ const row = { ...body, hmac };
67
+ appendFileSync(this.path, JSON.stringify(row) + "\n", { encoding: "utf8", flush: true });
68
+ this.lastHmac = hmac;
69
+ this.maybeCompact();
70
+ return row;
71
+ }
72
+ /** Replay WAL → reconstruct baseline map. Idempotent. */
73
+ replay() {
74
+ const baselines = new Map();
75
+ const snapshotPath = this.path.replace("wal.jsonl", "baselines.json");
76
+ // Load snapshot first (compaction product)
77
+ if (existsSync(snapshotPath)) {
78
+ try {
79
+ const snap = JSON.parse(readFileSync(snapshotPath, "utf8"));
80
+ for (const [k, v] of Object.entries(snap))
81
+ baselines.set(k, v);
82
+ }
83
+ catch { /* ignore corrupt snapshot — fall back to full WAL */ }
84
+ }
85
+ if (!existsSync(this.path))
86
+ return baselines;
87
+ const content = readFileSync(this.path, "utf8").trim();
88
+ if (!content)
89
+ return baselines;
90
+ for (const line of content.split("\n")) {
91
+ try {
92
+ const row = JSON.parse(line);
93
+ if (row.op === "baseline_set")
94
+ baselines.set(row.fnId, row.payload);
95
+ }
96
+ catch { /* skip malformed */ }
97
+ }
98
+ return baselines;
99
+ }
100
+ /** Verify chain integrity (chain HMAC continuity). */
101
+ verify() {
102
+ if (!existsSync(this.path))
103
+ return { ok: true, rows: 0 };
104
+ const lines = readFileSync(this.path, "utf8").trim().split("\n").filter(Boolean);
105
+ let prev = "0".repeat(16);
106
+ for (let i = 0; i < lines.length; i++) {
107
+ try {
108
+ const row = JSON.parse(lines[i]);
109
+ if (row.prevHmac !== prev)
110
+ return { ok: false, rows: lines.length, brokenAt: i };
111
+ const { hmac, ...body } = row;
112
+ const recomputed = hmacRow(prev, body, this.secret);
113
+ if (recomputed !== hmac)
114
+ return { ok: false, rows: lines.length, brokenAt: i };
115
+ prev = hmac;
116
+ }
117
+ catch {
118
+ return { ok: false, rows: lines.length, brokenAt: i };
119
+ }
120
+ }
121
+ return { ok: true, rows: lines.length };
122
+ }
123
+ /** Compact WAL → snapshot if file exceeds threshold. */
124
+ maybeCompact() {
125
+ try {
126
+ const sz = statSync(this.path).size;
127
+ if (sz < this.compactionThresholdBytes)
128
+ return;
129
+ const baselines = this.replay();
130
+ const snapshotPath = this.path.replace("wal.jsonl", "baselines.json");
131
+ const obj = {};
132
+ for (const [k, v] of baselines)
133
+ obj[k] = v;
134
+ writeFileSync(snapshotPath, JSON.stringify(obj), "utf8");
135
+ // Truncate WAL atomically: write empty + reset chain
136
+ const tmpPath = this.path + ".tmp";
137
+ writeFileSync(tmpPath, "", "utf8");
138
+ renameSync(tmpPath, this.path);
139
+ this.lastHmac = "0".repeat(16);
140
+ }
141
+ catch { /* compaction is best-effort */ }
142
+ }
143
+ path_for_test() { return this.path; }
144
+ }
145
+ //# sourceMappingURL=wal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wal.js","sourceRoot":"","sources":["../../src/protoplasm/w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MAAM,CAAC,CAAC;YACnC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC,CAAC,+BAA+B,CAAC,CAAC;IAC7C,CAAC;IAED,aAAa,KAAa,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;CAC9C"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 🦠 PROTOPLASM — wisdom_space
3
+ *
4
+ * When orchestrator marks a finding BROKEN → wisdom_space diagnoses root cause.
5
+ *
6
+ * Strategy:
7
+ * 1. Collect last N findings across ALL functions in same time window
8
+ * 2. Score upstream suspects by co-occurrence (broke around same time)
9
+ * 3. Detect "neighbor-broken-first" patterns (this fn broke 30s AFTER fnX broke)
10
+ * 4. Emit hypothesis + proposed heal actions
11
+ *
12
+ * The "wisdom" is the cross-function correlation — single-function metrics
13
+ * can't see "I broke because dep X broke 30 seconds ago".
14
+ */
15
+ import type { SuperQuanFinding, WisdomRootCause } from "./types.js";
16
+ interface DiagnoseInput {
17
+ brokenFinding: SuperQuanFinding;
18
+ recentLedger: SuperQuanFinding[];
19
+ windowMs?: number;
20
+ }
21
+ export declare function diagnose(input: DiagnoseInput): WisdomRootCause;
22
+ /** Quick summary of recent ledger health. */
23
+ export declare function ledgerHealth(recent: SuperQuanFinding[]): {
24
+ broken: number;
25
+ warn: number;
26
+ healthy: number;
27
+ brokenRate: number;
28
+ };
29
+ export {};
30
+ //# sourceMappingURL=wisdom_space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wisdom_space.d.ts","sourceRoot":"","sources":["../../src/protoplasm/wisdom_space.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAc,MAAM,YAAY,CAAC;AAEhF,UAAU,aAAa;IACrB,aAAa,EAAE,gBAAgB,CAAC;IAChC,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,CA0D9D;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAM9H"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * 🦠 PROTOPLASM — wisdom_space
3
+ *
4
+ * When orchestrator marks a finding BROKEN → wisdom_space diagnoses root cause.
5
+ *
6
+ * Strategy:
7
+ * 1. Collect last N findings across ALL functions in same time window
8
+ * 2. Score upstream suspects by co-occurrence (broke around same time)
9
+ * 3. Detect "neighbor-broken-first" patterns (this fn broke 30s AFTER fnX broke)
10
+ * 4. Emit hypothesis + proposed heal actions
11
+ *
12
+ * The "wisdom" is the cross-function correlation — single-function metrics
13
+ * can't see "I broke because dep X broke 30 seconds ago".
14
+ */
15
+ export function diagnose(input) {
16
+ const window = input.windowMs ?? 60_000;
17
+ const brokenAt = new Date(input.brokenFinding.at).getTime();
18
+ const inWindow = input.recentLedger.filter((f) => Math.abs(new Date(f.at).getTime() - brokenAt) <= window);
19
+ // Upstream suspects: other fns that turned broken WITHIN the window AND earlier
20
+ const earlierBroken = inWindow.filter((f) => f.fnId !== input.brokenFinding.fnId
21
+ && f.outcome === "broken"
22
+ && new Date(f.at).getTime() < brokenAt);
23
+ // Score by recency (earlier → higher suspect score)
24
+ const suspects = earlierBroken
25
+ .map((f) => ({ fnId: f.fnId, age: brokenAt - new Date(f.at).getTime(), reason: f.evidence }))
26
+ .sort((a, b) => b.age - a.age); // older = upstream
27
+ const upstreamSuspects = suspects.slice(0, 5).map((s) => s.fnId);
28
+ let hypothesis;
29
+ let confidence = 0.4;
30
+ const heals = [];
31
+ if (upstreamSuspects.length >= 2) {
32
+ hypothesis = `cascade failure from upstream: ${upstreamSuspects.join(" → ")}`;
33
+ confidence = 0.85;
34
+ heals.push({ kind: "request-supernova-restart", rationale: "multiple upstream functions broken — restart cycle to clear shared state" });
35
+ heals.push({ kind: "raise-truth-gate-block", rationale: "cascade detected — block any new release tag until heal verified" });
36
+ }
37
+ else if (upstreamSuspects.length === 1) {
38
+ hypothesis = `proximate cause: ${upstreamSuspects[0]} broke earlier in window`;
39
+ confidence = 0.7;
40
+ heals.push({ kind: "retry-with-backoff", rationale: "single upstream suspect — retry after upstream stabilizes" });
41
+ }
42
+ else {
43
+ // No upstream suspects → check quantum signals
44
+ const qs = input.brokenFinding.quantumSignals;
45
+ if (qs.collapseStability < 0.5) {
46
+ hypothesis = "intrinsic instability — function throws on >50% of calls";
47
+ confidence = 0.6;
48
+ heals.push({ kind: "fallback-to-cached", rationale: "high throw rate — serve cached last-good response" });
49
+ }
50
+ else if (qs.chaosDivergence > 3) {
51
+ hypothesis = "duration variance spiking — likely external dep slowdown (network/disk/db)";
52
+ confidence = 0.55;
53
+ heals.push({ kind: "retry-with-backoff", rationale: "transient slowdown — backoff + retry" });
54
+ }
55
+ else {
56
+ hypothesis = "unknown — z-score breach but no clear pattern";
57
+ confidence = 0.3;
58
+ heals.push({ kind: "noop", rationale: "insufficient signal — record + observe one more cycle before acting" });
59
+ }
60
+ }
61
+ return {
62
+ fnId: input.brokenFinding.fnId,
63
+ hypothesis,
64
+ upstreamSuspects,
65
+ confidence,
66
+ proposedHeal: heals,
67
+ };
68
+ }
69
+ /** Quick summary of recent ledger health. */
70
+ export function ledgerHealth(recent) {
71
+ const broken = recent.filter((f) => f.outcome === "broken").length;
72
+ const warn = recent.filter((f) => f.outcome === "warn").length;
73
+ const healthy = recent.filter((f) => f.outcome === "healthy").length;
74
+ const total = recent.length || 1;
75
+ return { broken, warn, healthy, brokenRate: broken / total };
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"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * v2.66.0 — REFLOG: cross-session time-machine for AI-driven repos.
3
+ *
4
+ * Closes the Mneme MCP septet: bodyguard + diplomat + conscience +
5
+ * memory + consensus + coordination + **time machine**. With v2.66
6
+ * shipped, the full 7-primitive agent infrastructure stack is LIVE.
7
+ *
8
+ * Killer use case: "rewind 2 hours, keep tests" → bad commits revert,
9
+ * tests intact. Pre-MIRROR: `git reset --hard` is all-or-nothing —
10
+ * loses the good with the bad. REFLOG keeps:
11
+ * - HMAC-signed checkpoints (HEAD ref + per-file SHA + AI pheromone
12
+ * tag = which agent was active when each file was last touched)
13
+ * - Selective rewind via path-predicate filter (include/exclude
14
+ * globs) and/or AI pheromone filter (only rewind cursor's edits)
15
+ * - Dry-run preview by default — shows what WOULD revert / keep
16
+ * - Cryptographic audit trail of every checkpoint + rewind
17
+ *
18
+ * REFLOG is SAFE by construction: rewind() never touches the working
19
+ * tree. It returns a PROPOSAL (a list of files + their target SHAs).
20
+ * The caller applies it via a separate operation OR pastes the
21
+ * proposal into git/IDE for manual review.
22
+ *
23
+ * 7 wild innovations:
24
+ *
25
+ * 1. PER-FILE SHA CHECKPOINT — snapshot the SHA of every tracked
26
+ * file at checkpoint time. Lets rewind operate at file
27
+ * granularity, not just commit granularity.
28
+ *
29
+ * 2. AI PHEROMONE TAGGING — each checkpoint records `recentAgent`
30
+ * (Claude / Cursor / Continue / Aider) inferred from env vars
31
+ * (CLAUDECODE / CURSOR_AGENT / etc). Rewind can filter by
32
+ * pheromone: "rewind only Cursor's edits in the last 2h".
33
+ *
34
+ * 3. PATH-PREDICATE FILTER — minimatch-style include/exclude globs.
35
+ * "Rewind everything EXCEPT tests/**" keeps tests intact while
36
+ * reverting production code.
37
+ *
38
+ * 4. TIME-WINDOW REWIND — `--since 2h` or `--checkpoint <id>`.
39
+ * REFLOG computes the right target checkpoint then diffs.
40
+ *
41
+ * 5. DRY-RUN PROPOSAL — every rewind returns a structured
42
+ * `RewindProposal` (toRevert + toKeep). The agent reviews
43
+ * before applying. No accidental data loss.
44
+ *
45
+ * 6. HMAC-CHAINED REFLOG LEDGER — every checkpoint + rewind
46
+ * proposal + apply event chained. Tamper-evident.
47
+ *
48
+ * 7. COMPOSES WITH SWARM BUS — when a rewind ships, REFLOG can
49
+ * auto-broadcast to a swarm channel so other agents know
50
+ * the working tree changed. Wire pending v2.67+.
51
+ *
52
+ * Pure ESM. Defensive — never throws.
53
+ */
54
+ export interface FileSha {
55
+ /** Relative path from repo root, forward slashes. */
56
+ path: string;
57
+ /** SHA-256 hex of file content. "" if file absent. */
58
+ sha: string;
59
+ /** mtime ms. */
60
+ mtimeMs: number;
61
+ }
62
+ export interface Checkpoint {
63
+ id: string;
64
+ at: string;
65
+ /** Best-effort git HEAD ref at checkpoint time (empty if not a git repo). */
66
+ gitHead: string;
67
+ /** Pheromone tag: which AI agent was active. */
68
+ pheromone: string;
69
+ /** Per-file SHA snapshot. */
70
+ files: FileSha[];
71
+ /** Optional reason / label (e.g. "before refactor"). */
72
+ label?: string;
73
+ hmac: string;
74
+ }
75
+ export interface CheckpointInput {
76
+ /** Working directory. */
77
+ cwd?: string;
78
+ /** Optional label. */
79
+ label?: string;
80
+ /** Path globs to include (default ["**\/*"]). */
81
+ include?: string[];
82
+ /** Path globs to exclude. */
83
+ exclude?: string[];
84
+ /** Max files to track (default 5000). */
85
+ maxFiles?: number;
86
+ }
87
+ export interface RewindInput {
88
+ /** Working directory. */
89
+ cwd?: string;
90
+ /** Time window: "2h" / "30m" / "1d". Mutually exclusive with checkpointId. */
91
+ since?: string;
92
+ /** Specific checkpoint to rewind to. */
93
+ checkpointId?: string;
94
+ /** Include path globs (default = everything). */
95
+ include?: string[];
96
+ /** Exclude path globs (default = empty). */
97
+ exclude?: string[];
98
+ /** Only rewind files last touched by THIS pheromone. */
99
+ pheromone?: string;
100
+ }
101
+ export interface RewindEntry {
102
+ /** Relative path. */
103
+ path: string;
104
+ /** Current SHA. */
105
+ currentSha: string;
106
+ /** Target SHA (what to restore to). */
107
+ targetSha: string;
108
+ /** mtime at the target checkpoint. */
109
+ targetMtimeMs: number;
110
+ /** Pheromone tag at target checkpoint. */
111
+ targetPheromone: string;
112
+ }
113
+ export interface RewindProposal {
114
+ ok: boolean;
115
+ /** Target checkpoint. */
116
+ targetCheckpoint: {
117
+ id: string;
118
+ at: string;
119
+ label?: string;
120
+ };
121
+ /** Files that would be reverted. */
122
+ toRevert: RewindEntry[];
123
+ /** Files that would be kept (filtered out OR not in target checkpoint). */
124
+ toKeep: Array<{
125
+ path: string;
126
+ reason: string;
127
+ }>;
128
+ /** Plain-English summary. */
129
+ summary: string;
130
+ hmac: string;
131
+ }
132
+ export declare function detectPheromone(): string;
133
+ export declare function createCheckpoint(input?: CheckpointInput): {
134
+ ok: boolean;
135
+ checkpoint: Checkpoint;
136
+ hint: string;
137
+ };
138
+ export declare function listCheckpoints(cwd: string): Array<{
139
+ id: string;
140
+ at: string;
141
+ label?: string;
142
+ fileCount: number;
143
+ pheromone: string;
144
+ }>;
145
+ export declare function readCheckpoint(cwd: string, id: string): Checkpoint | null;
146
+ export declare function verifyCheckpoint(c: Checkpoint): boolean;
147
+ export declare function rewindPreview(input: RewindInput): RewindProposal;
148
+ export declare function verifyRewindProposal(r: RewindProposal): boolean;
149
+ interface LedgerEntry {
150
+ kind: "checkpoint" | "rewind_preview" | "rewind_apply";
151
+ at: string;
152
+ id: string;
153
+ detail: string;
154
+ prevHmac: string;
155
+ hmac: string;
156
+ }
157
+ export declare function readLedger(cwd: string): LedgerEntry[];
158
+ export declare function verifyLedgerChain(cwd: string): {
159
+ ok: boolean;
160
+ rows: number;
161
+ brokenAt?: number;
162
+ };
163
+ export declare function renderRewindBanner(r: RewindProposal): string;
164
+ export {};
165
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reflog/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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