@mneme-ai/sdk 2.55.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/benchmark.d.ts +39 -0
- package/dist/benchmark.d.ts.map +1 -0
- package/dist/benchmark.js +115 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/events.d.ts +44 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +107 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/lock.d.ts +63 -0
- package/dist/lock.d.ts.map +1 -0
- package/dist/lock.js +140 -0
- package/dist/lock.js.map +1 -0
- package/dist/nemesis.d.ts +134 -0
- package/dist/nemesis.d.ts.map +1 -0
- package/dist/nemesis.js +137 -0
- package/dist/nemesis.js.map +1 -0
- package/dist/truth.d.ts +39 -0
- package/dist/truth.d.ts.map +1 -0
- package/dist/truth.js +56 -0
- package/dist/truth.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +42 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +39 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +51 -0
- package/dist/verify.js.map +1 -0
- package/package.json +69 -0
package/dist/lock.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mneme-ai/sdk file-lock adapter.
|
|
3
|
+
*
|
|
4
|
+
* Fixes the race condition the user identified:
|
|
5
|
+
* "CLI mneme verify ... + Cursor SDK writing HMAC chain simultaneously
|
|
6
|
+
* → race in writing .mneme/cli-activity.jsonl"
|
|
7
|
+
*
|
|
8
|
+
* Strategy: simple advisory lock via `.lock` sentinel file with PID +
|
|
9
|
+
* stale-detection. No external dependency (no proper-lockfile import) —
|
|
10
|
+
* stays compatible with bundler tree-shake + works in container/serverless.
|
|
11
|
+
*
|
|
12
|
+
* Pure deterministic + defensive; never throws.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync, openSync, closeSync, constants as fsConstants } from "node:fs";
|
|
15
|
+
import { dirname } from "node:path";
|
|
16
|
+
const STALE_MS = 5_000; // a lock older than this is considered stale
|
|
17
|
+
function lockPathFor(target) {
|
|
18
|
+
return target + ".lock";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Try to acquire an advisory lock on a target file. Non-blocking: returns
|
|
22
|
+
* { acquired: false } immediately on failure.
|
|
23
|
+
*
|
|
24
|
+
* Caller MUST call releaseLock when done.
|
|
25
|
+
*/
|
|
26
|
+
export function acquireLock(targetPath) {
|
|
27
|
+
const lockPath = lockPathFor(targetPath);
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
try {
|
|
30
|
+
// Ensure parent dir exists
|
|
31
|
+
const parent = dirname(targetPath);
|
|
32
|
+
if (parent && !existsSync(parent)) {
|
|
33
|
+
try {
|
|
34
|
+
mkdirSync(parent, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
catch { /* */ }
|
|
37
|
+
}
|
|
38
|
+
// Stale check: if lock file exists + old enough → remove
|
|
39
|
+
if (existsSync(lockPath)) {
|
|
40
|
+
try {
|
|
41
|
+
const body = JSON.parse(readFileSync(lockPath, "utf8"));
|
|
42
|
+
if (now - body.at > STALE_MS) {
|
|
43
|
+
try {
|
|
44
|
+
unlinkSync(lockPath);
|
|
45
|
+
}
|
|
46
|
+
catch { /* */ }
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return { acquired: false, lockPath, at: body.at, holderPid: body.pid, reason: "held by another process" };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Corrupted lock file → safe to remove
|
|
54
|
+
try {
|
|
55
|
+
unlinkSync(lockPath);
|
|
56
|
+
}
|
|
57
|
+
catch { /* */ }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Try exclusive create — fails if another process raced us
|
|
61
|
+
let fd;
|
|
62
|
+
try {
|
|
63
|
+
fd = openSync(lockPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { acquired: false, lockPath, at: now, reason: "exclusive create failed (race)" };
|
|
67
|
+
}
|
|
68
|
+
writeFileSync(fd, JSON.stringify({ pid: process.pid, at: now }));
|
|
69
|
+
closeSync(fd);
|
|
70
|
+
return { acquired: true, lockPath, at: now, holderPid: process.pid };
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
return { acquired: false, lockPath, at: now, reason: `lock attempt failed: ${e.message}` };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function releaseLock(lockResult) {
|
|
77
|
+
if (!lockResult.acquired)
|
|
78
|
+
return;
|
|
79
|
+
try {
|
|
80
|
+
if (existsSync(lockResult.lockPath))
|
|
81
|
+
unlinkSync(lockResult.lockPath);
|
|
82
|
+
}
|
|
83
|
+
catch { /* */ }
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Run a critical section under the lock. Releases the lock even when fn
|
|
87
|
+
* throws. Returns { acquired: false } envelope when the lock could not
|
|
88
|
+
* be acquired (caller decides whether to retry).
|
|
89
|
+
*/
|
|
90
|
+
export async function withLock(targetPath, fn, opts = {}) {
|
|
91
|
+
const retries = Math.max(0, opts.retries ?? 5);
|
|
92
|
+
const delayMs = Math.max(1, opts.retryDelayMs ?? 50);
|
|
93
|
+
for (let i = 0; i <= retries; i++) {
|
|
94
|
+
const r = acquireLock(targetPath);
|
|
95
|
+
if (r.acquired) {
|
|
96
|
+
try {
|
|
97
|
+
const data = await Promise.resolve(fn());
|
|
98
|
+
return { ok: true, data };
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
return { ok: false, reason: `critical-section threw: ${e.message}` };
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
releaseLock(r);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (i < retries)
|
|
108
|
+
await new Promise((res) => setTimeout(res, delayMs));
|
|
109
|
+
}
|
|
110
|
+
return { ok: false, reason: `lock acquisition failed after ${retries + 1} attempts` };
|
|
111
|
+
}
|
|
112
|
+
/** Diagnostic: check if a lock currently exists + is fresh. */
|
|
113
|
+
export function isLocked(targetPath) {
|
|
114
|
+
const p = lockPathFor(targetPath);
|
|
115
|
+
if (!existsSync(p))
|
|
116
|
+
return { locked: false };
|
|
117
|
+
try {
|
|
118
|
+
const body = JSON.parse(readFileSync(p, "utf8"));
|
|
119
|
+
const age = Date.now() - body.at;
|
|
120
|
+
if (age > STALE_MS)
|
|
121
|
+
return { locked: false, ageMs: age };
|
|
122
|
+
return { locked: true, holderPid: body.pid, ageMs: age };
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return { locked: false };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Test-only: lockPath getter. */
|
|
129
|
+
export function __lockPathForTest(targetPath) {
|
|
130
|
+
return lockPathFor(targetPath);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Wrap a function so that every call serialises through the lock for
|
|
134
|
+
* a given path. Useful for wrapping ledger writers transparently.
|
|
135
|
+
*/
|
|
136
|
+
export function serializeOnLock(lockTarget, fn) {
|
|
137
|
+
return async (...a) => withLock(lockTarget, () => fn(...a));
|
|
138
|
+
}
|
|
139
|
+
export const STALE_LOCK_MS = STALE_MS;
|
|
140
|
+
//# sourceMappingURL=lock.js.map
|
package/dist/lock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS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method
|
|
5
|
+
* is a direct function call into @mneme-ai/core. No spawn, no JSON
|
|
6
|
+
* parsing, no stderr piping. Type-safe via branded types.
|
|
7
|
+
*/
|
|
8
|
+
import * as core from "@mneme-ai/core";
|
|
9
|
+
import type { Fixture, SdkEnvelope, VendorId } from "./types.js";
|
|
10
|
+
export interface MnemeInstanceOpts {
|
|
11
|
+
/** Directory where Mneme keeps chains (default: <cwd>/.mneme). */
|
|
12
|
+
dataDir?: string;
|
|
13
|
+
/** HMAC key for NEMESIS receipts (overrides env / file). */
|
|
14
|
+
hmacKey?: string;
|
|
15
|
+
/** Strict mode: throw on default-insecure key (mirrors MNEME_NEMESIS_STRICT=1). */
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class NemesisSdk {
|
|
19
|
+
private readonly opts;
|
|
20
|
+
constructor(opts?: MnemeInstanceOpts);
|
|
21
|
+
/** Pure deterministic — extract the 41-feature fingerprint. <30ms. */
|
|
22
|
+
fingerprint(fx: Fixture): {
|
|
23
|
+
ok: true;
|
|
24
|
+
data: core.nemesis.Fingerprint;
|
|
25
|
+
latencyMs: number;
|
|
26
|
+
};
|
|
27
|
+
/** Calibrated Mahalanobis classifier — <50ms. */
|
|
28
|
+
classify(fx: Fixture | Parameters<typeof core.nemesis.classifyAgentCalibrated>[0]): {
|
|
29
|
+
ok: true;
|
|
30
|
+
data: core.nemesis.AgentVerdict;
|
|
31
|
+
latencyMs: number;
|
|
32
|
+
};
|
|
33
|
+
/** EU AI Act Article 50 stamp — <30ms warm path. */
|
|
34
|
+
stamp(input: {
|
|
35
|
+
message: string;
|
|
36
|
+
vendor: VendorId | string;
|
|
37
|
+
confidence?: number;
|
|
38
|
+
contentType?: string;
|
|
39
|
+
}): {
|
|
40
|
+
ok: boolean;
|
|
41
|
+
data: core.nemesis.StampResult;
|
|
42
|
+
latencyMs: number;
|
|
43
|
+
};
|
|
44
|
+
verifyStamp(stampedMessage: string): SdkEnvelope<ReturnType<typeof core.nemesis.verifyStamp>>;
|
|
45
|
+
/** STEALTH SCORE — inverse of classifier confidence. <80ms. */
|
|
46
|
+
stealthScore(fx: Fixture): {
|
|
47
|
+
ok: true;
|
|
48
|
+
data: core.nemesis.StealthVerdict;
|
|
49
|
+
latencyMs: number;
|
|
50
|
+
};
|
|
51
|
+
/** CAPILLARY — 50+ micro-tells. <50ms. */
|
|
52
|
+
capillary(diff: string): {
|
|
53
|
+
ok: true;
|
|
54
|
+
data: core.nemesis.MicroProfile;
|
|
55
|
+
latencyMs: number;
|
|
56
|
+
};
|
|
57
|
+
/** JANUS — locate vendor cluster basin. <50ms. */
|
|
58
|
+
janusObserve(fx: Fixture): {
|
|
59
|
+
ok: true;
|
|
60
|
+
data: core.nemesis.JanusObservation;
|
|
61
|
+
latencyMs: number;
|
|
62
|
+
};
|
|
63
|
+
/** JANUS swap detector — emits swap.detected events. */
|
|
64
|
+
janusSwap(fixtures: Fixture[], swapOpts?: {
|
|
65
|
+
minMargin?: number;
|
|
66
|
+
}): {
|
|
67
|
+
ok: true;
|
|
68
|
+
data: core.nemesis.JanusSessionResult;
|
|
69
|
+
latencyMs: number;
|
|
70
|
+
};
|
|
71
|
+
/** THEMIS alibi verifier. */
|
|
72
|
+
alibi(input: {
|
|
73
|
+
notVendor: VendorId | string;
|
|
74
|
+
fixture: Fixture;
|
|
75
|
+
}): {
|
|
76
|
+
ok: boolean;
|
|
77
|
+
data: core.nemesis.ThemisResult;
|
|
78
|
+
latencyMs: number;
|
|
79
|
+
};
|
|
80
|
+
/** SIBYL commit (session-start identity hash commitment). */
|
|
81
|
+
sibylCommit(input: {
|
|
82
|
+
vendor: VendorId | string;
|
|
83
|
+
model?: string;
|
|
84
|
+
version?: string;
|
|
85
|
+
sessionId?: string;
|
|
86
|
+
}): {
|
|
87
|
+
ok: true;
|
|
88
|
+
data: core.nemesis.CommitResult;
|
|
89
|
+
latencyMs: number;
|
|
90
|
+
};
|
|
91
|
+
/** SIBYL reveal — verifies the (identity, nonce) recreates the commitment. */
|
|
92
|
+
sibylReveal(input: {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
identity: {
|
|
95
|
+
vendor: string;
|
|
96
|
+
model?: string;
|
|
97
|
+
version?: string;
|
|
98
|
+
};
|
|
99
|
+
nonce: string;
|
|
100
|
+
}): {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
data: core.nemesis.RevealResult;
|
|
103
|
+
latencyMs: number;
|
|
104
|
+
};
|
|
105
|
+
/** GAVEL — court-admissible bundle pack. */
|
|
106
|
+
gavelPack(input: Parameters<typeof core.nemesis.buildGavelBundle>[0]): {
|
|
107
|
+
ok: boolean;
|
|
108
|
+
data: {
|
|
109
|
+
ok: boolean;
|
|
110
|
+
bundle?: core.nemesis.GavelBundle;
|
|
111
|
+
reason: string;
|
|
112
|
+
};
|
|
113
|
+
latencyMs: number;
|
|
114
|
+
};
|
|
115
|
+
/** LETHE — GDPR forget. */
|
|
116
|
+
letheForget(input: {
|
|
117
|
+
ledgerRelative: string;
|
|
118
|
+
rowIndex: number;
|
|
119
|
+
jurisdiction?: string;
|
|
120
|
+
dryRun?: boolean;
|
|
121
|
+
}): {
|
|
122
|
+
ok: boolean;
|
|
123
|
+
data: core.nemesis.ForgetResult;
|
|
124
|
+
latencyMs: number;
|
|
125
|
+
};
|
|
126
|
+
/** NIMBUS publish leaderboard card to the local pub-store. */
|
|
127
|
+
nimbusPublish(input: Omit<Parameters<typeof core.nemesis.publishCard>[0], "repoRoot">): {
|
|
128
|
+
ok: boolean;
|
|
129
|
+
data: core.nemesis.PublishResult;
|
|
130
|
+
latencyMs: number;
|
|
131
|
+
};
|
|
132
|
+
private dataDir;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=nemesis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nemesis.d.ts","sourceRoot":"","sources":["../src/nemesis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,IAAI,MAAM,gBAAgB,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is a direct function call into @mneme-ai/core. No spawn, no JSON
|
|
6
|
+
* parsing, no stderr piping. Type-safe via branded types.
|
|
7
|
+
*/
|
|
8
|
+
import * as core from "@mneme-ai/core";
|
|
9
|
+
import { getEventBus } from "./events.js";
|
|
10
|
+
export class NemesisSdk {
|
|
11
|
+
opts;
|
|
12
|
+
constructor(opts = {}) {
|
|
13
|
+
this.opts = opts;
|
|
14
|
+
}
|
|
15
|
+
/** Pure deterministic — extract the 41-feature fingerprint. <30ms. */
|
|
16
|
+
fingerprint(fx) {
|
|
17
|
+
const t0 = performance.now();
|
|
18
|
+
const data = core.nemesis.extractFingerprint(fx);
|
|
19
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
20
|
+
}
|
|
21
|
+
/** Calibrated Mahalanobis classifier — <50ms. */
|
|
22
|
+
classify(fx) {
|
|
23
|
+
const t0 = performance.now();
|
|
24
|
+
const fp = (typeof fx.diff === "string")
|
|
25
|
+
? core.nemesis.extractFingerprint(fx)
|
|
26
|
+
: fx;
|
|
27
|
+
const data = core.nemesis.classifyAgentCalibrated(fp);
|
|
28
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
29
|
+
}
|
|
30
|
+
/** EU AI Act Article 50 stamp — <30ms warm path. */
|
|
31
|
+
stamp(input) {
|
|
32
|
+
const t0 = performance.now();
|
|
33
|
+
const data = core.nemesis.stampArticle50({
|
|
34
|
+
message: input.message,
|
|
35
|
+
vendor: String(input.vendor),
|
|
36
|
+
confidence: input.confidence ?? 0.95,
|
|
37
|
+
contentType: input.contentType,
|
|
38
|
+
});
|
|
39
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
40
|
+
getEventBus().emit({ kind: "stamp.issued", at: Date.now(), data: { vendor: input.vendor, latencyMs } });
|
|
41
|
+
return { ok: data.ok, data, latencyMs };
|
|
42
|
+
}
|
|
43
|
+
verifyStamp(stampedMessage) {
|
|
44
|
+
const t0 = performance.now();
|
|
45
|
+
const data = core.nemesis.verifyStamp(stampedMessage);
|
|
46
|
+
return { ok: data.valid, data, latencyMs: +(performance.now() - t0).toFixed(2), reason: data.reason };
|
|
47
|
+
}
|
|
48
|
+
/** STEALTH SCORE — inverse of classifier confidence. <80ms. */
|
|
49
|
+
stealthScore(fx) {
|
|
50
|
+
const t0 = performance.now();
|
|
51
|
+
const data = core.nemesis.computeStealthScore(fx);
|
|
52
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
53
|
+
}
|
|
54
|
+
/** CAPILLARY — 50+ micro-tells. <50ms. */
|
|
55
|
+
capillary(diff) {
|
|
56
|
+
const t0 = performance.now();
|
|
57
|
+
const data = core.nemesis.extractMicroProfile(diff);
|
|
58
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
59
|
+
}
|
|
60
|
+
/** JANUS — locate vendor cluster basin. <50ms. */
|
|
61
|
+
janusObserve(fx) {
|
|
62
|
+
const t0 = performance.now();
|
|
63
|
+
const data = core.nemesis.observe(fx);
|
|
64
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
65
|
+
}
|
|
66
|
+
/** JANUS swap detector — emits swap.detected events. */
|
|
67
|
+
janusSwap(fixtures, swapOpts = {}) {
|
|
68
|
+
const t0 = performance.now();
|
|
69
|
+
const obs = fixtures.map((fx) => core.nemesis.observe(fx));
|
|
70
|
+
const data = core.nemesis.detectIdentitySwap(obs, swapOpts);
|
|
71
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
72
|
+
if (data.swapDetected) {
|
|
73
|
+
getEventBus().emit({ kind: "swap.detected", at: Date.now(), data: { transitions: data.transitions, latencyMs } });
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, data, latencyMs };
|
|
76
|
+
}
|
|
77
|
+
/** THEMIS alibi verifier. */
|
|
78
|
+
alibi(input) {
|
|
79
|
+
const t0 = performance.now();
|
|
80
|
+
const data = core.nemesis.verifyAlibi({ notVendor: String(input.notVendor), fixture: input.fixture });
|
|
81
|
+
return { ok: data.verdict !== "INCONCLUSIVE", data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
82
|
+
}
|
|
83
|
+
/** SIBYL commit (session-start identity hash commitment). */
|
|
84
|
+
sibylCommit(input) {
|
|
85
|
+
const t0 = performance.now();
|
|
86
|
+
const data = core.nemesis.commitIdentity(this.dataDir(), {
|
|
87
|
+
identity: { vendor: String(input.vendor), model: input.model, version: input.version },
|
|
88
|
+
sessionId: input.sessionId,
|
|
89
|
+
});
|
|
90
|
+
return { ok: true, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
91
|
+
}
|
|
92
|
+
/** SIBYL reveal — verifies the (identity, nonce) recreates the commitment. */
|
|
93
|
+
sibylReveal(input) {
|
|
94
|
+
const t0 = performance.now();
|
|
95
|
+
const data = core.nemesis.revealIdentity(this.dataDir(), input);
|
|
96
|
+
return { ok: data.matches, data, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
97
|
+
}
|
|
98
|
+
/** GAVEL — court-admissible bundle pack. */
|
|
99
|
+
gavelPack(input) {
|
|
100
|
+
const t0 = performance.now();
|
|
101
|
+
const data = core.nemesis.buildGavelBundle(input);
|
|
102
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
103
|
+
if (data.ok)
|
|
104
|
+
getEventBus().emit({ kind: "gavel.packed", at: Date.now(), data: { commitRef: input.commitRef, latencyMs } });
|
|
105
|
+
return { ok: data.ok, data, latencyMs };
|
|
106
|
+
}
|
|
107
|
+
/** LETHE — GDPR forget. */
|
|
108
|
+
letheForget(input) {
|
|
109
|
+
const t0 = performance.now();
|
|
110
|
+
const data = core.nemesis.forgetRow({
|
|
111
|
+
repoRoot: this.dataDir().replace(/[\\/]\.mneme$/, ""),
|
|
112
|
+
ledgerRelative: input.ledgerRelative,
|
|
113
|
+
rowIndex: input.rowIndex,
|
|
114
|
+
jurisdiction: input.jurisdiction,
|
|
115
|
+
dryRun: input.dryRun,
|
|
116
|
+
});
|
|
117
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
118
|
+
if (data.ok && data.receipt)
|
|
119
|
+
getEventBus().emit({ kind: "lethe.forgotten", at: Date.now(), data: { ledger: input.ledgerRelative, latencyMs } });
|
|
120
|
+
return { ok: data.ok, data, latencyMs };
|
|
121
|
+
}
|
|
122
|
+
/** NIMBUS publish leaderboard card to the local pub-store. */
|
|
123
|
+
nimbusPublish(input) {
|
|
124
|
+
const t0 = performance.now();
|
|
125
|
+
const data = core.nemesis.publishCard({ ...input, repoRoot: this.dataDir().replace(/[\\/]\.mneme$/, "") });
|
|
126
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
127
|
+
if (data.ok)
|
|
128
|
+
getEventBus().emit({ kind: "nimbus.published", at: Date.now(), data: { orgTag: input.orgTag, latencyMs } });
|
|
129
|
+
return { ok: data.ok, data, latencyMs };
|
|
130
|
+
}
|
|
131
|
+
dataDir() {
|
|
132
|
+
if (this.opts.dataDir)
|
|
133
|
+
return this.opts.dataDir;
|
|
134
|
+
return `${process.cwd()}/.mneme`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=nemesis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nemesis.js","sourceRoot":"","sources":["../src/nemesis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAW1C,MAAM,OAAO,UAAU;IACQ;IAA7B,YAA6B,OAA0B,EAAE;QAA5B,SAAI,GAAJ,IAAI,CAAwB;IAAG,CAAC;IAE7D,sEAAsE;IACtE,WAAW,CAAC,EAAW;QACrB,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC,C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AAO,GAAG,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC;IACnC,CAAC;CACF"}
|
package/dist/truth.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mneme-ai/sdk/truth — TRUTH GATE in-process surface.
|
|
3
|
+
*
|
|
4
|
+
* The CLI shells out to `mneme truth_gate run` which spawns the MCP
|
|
5
|
+
* server + walks all probes. The SDK calls the probe runner directly
|
|
6
|
+
* — same probes, no subprocess, type-safe results.
|
|
7
|
+
*/
|
|
8
|
+
import { truthGate } from "@mneme-ai/core";
|
|
9
|
+
import type { SdkEnvelope } from "./types.js";
|
|
10
|
+
declare const ALL_PROBES: readonly truthGate.Probe[];
|
|
11
|
+
type ProbeResultLike = Awaited<ReturnType<typeof ALL_PROBES[number]["run"]>>;
|
|
12
|
+
export interface ProbeRunInput {
|
|
13
|
+
probeId: string;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runProbe(input: ProbeRunInput): Promise<SdkEnvelope<ProbeResultLike & {
|
|
17
|
+
probeId: string;
|
|
18
|
+
latencyMs: number;
|
|
19
|
+
}>>;
|
|
20
|
+
export declare function listProbes(): ReadonlyArray<{
|
|
21
|
+
id: string;
|
|
22
|
+
kind: string;
|
|
23
|
+
description: string;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function runAllProbes(opts?: {
|
|
26
|
+
cwd?: string;
|
|
27
|
+
}): Promise<SdkEnvelope<{
|
|
28
|
+
total: number;
|
|
29
|
+
passed: number;
|
|
30
|
+
failed: number;
|
|
31
|
+
results: Array<{
|
|
32
|
+
probeId: string;
|
|
33
|
+
value: unknown;
|
|
34
|
+
evidence: string;
|
|
35
|
+
latencyMs: number;
|
|
36
|
+
}>;
|
|
37
|
+
}>>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=truth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truth.d.ts","sourceRoot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.
|
|
3
|
+
*
|
|
4
|
+
* The CLI shells out to `mneme truth_gate run` which spawns the MCP
|
|
5
|
+
* server + walks all probes. The SDK calls the probe runner directly
|
|
6
|
+
* — same probes, no subprocess, type-safe results.
|
|
7
|
+
*/
|
|
8
|
+
import { truthGate } from "@mneme-ai/core";
|
|
9
|
+
const { ALL_PROBES, probeById } = truthGate;
|
|
10
|
+
export async function runProbe(input) {
|
|
11
|
+
const p = probeById(input.probeId);
|
|
12
|
+
if (!p)
|
|
13
|
+
return { ok: false, reason: `unknown probe: ${input.probeId}` };
|
|
14
|
+
const t0 = performance.now();
|
|
15
|
+
try {
|
|
16
|
+
const r = await p.run({ cwd: input.cwd ?? process.cwd() });
|
|
17
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
18
|
+
return { ok: true, data: { ...r, probeId: input.probeId, latencyMs }, latencyMs };
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return { ok: false, reason: e.message, latencyMs: +(performance.now() - t0).toFixed(2) };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function listProbes() {
|
|
25
|
+
return ALL_PROBES.map((p) => ({ id: p.id, kind: p.kind, description: p.description }));
|
|
26
|
+
}
|
|
27
|
+
export async function runAllProbes(opts = {}) {
|
|
28
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
29
|
+
const t0 = performance.now();
|
|
30
|
+
const results = [];
|
|
31
|
+
let passed = 0, failed = 0;
|
|
32
|
+
for (const p of ALL_PROBES) {
|
|
33
|
+
const start = performance.now();
|
|
34
|
+
try {
|
|
35
|
+
const r = await p.run({ cwd });
|
|
36
|
+
const latency = +(performance.now() - start).toFixed(2);
|
|
37
|
+
const ok = r.value === 1;
|
|
38
|
+
if (ok)
|
|
39
|
+
passed++;
|
|
40
|
+
else
|
|
41
|
+
failed++;
|
|
42
|
+
results.push({ probeId: p.id, value: r.value, evidence: r.evidence, latencyMs: latency });
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
failed++;
|
|
46
|
+
results.push({ probeId: p.id, value: null, evidence: `threw: ${e.message}`, latencyMs: +(performance.now() - start).toFixed(2) });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const latencyMs = +(performance.now() - t0).toFixed(2);
|
|
50
|
+
return {
|
|
51
|
+
ok: failed === 0,
|
|
52
|
+
data: { total: results.length, passed, failed, results },
|
|
53
|
+
latencyMs,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=truth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truth.js","sourceRoot":"","sources":["../src/truth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;AAQ5C,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;IACxE,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAA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,CAAC;;gBAAM,MAAM,EAAE,CAAC;YAChC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5F,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAW,CAAW,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/I,CAAC;IACH,CAAC;IACD,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO;QACL,EAAE,EAAE,MAAM,KAAK,CAAC;QAChB,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;QACxD,SAAS;KACV,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mneme-ai/sdk types — branded types for type-level safety.
|
|
3
|
+
*
|
|
4
|
+
* "Branded" type pattern: a `Brand<T, "tag">` looks like `T` at runtime
|
|
5
|
+
* but the compiler refuses to substitute one tagged value for another.
|
|
6
|
+
* Prevents string-confusion bugs (e.g. passing a vendor slug where a
|
|
7
|
+
* commit ref is expected).
|
|
8
|
+
*
|
|
9
|
+
* Adopted from world-class TS codebases (Effect, fp-ts).
|
|
10
|
+
*/
|
|
11
|
+
declare const __brand: unique symbol;
|
|
12
|
+
export type Brand<T, B> = T & {
|
|
13
|
+
readonly [__brand]: B;
|
|
14
|
+
};
|
|
15
|
+
/** A SHA-256 hex digest. */
|
|
16
|
+
export type HmacHash = Brand<string, "HmacHash">;
|
|
17
|
+
/** A vendor slug from the NEMESIS allowlist. */
|
|
18
|
+
export type VendorId = Brand<string, "VendorId">;
|
|
19
|
+
/** A claim text submitted to the verifier. */
|
|
20
|
+
export type ClaimText = Brand<string, "ClaimText">;
|
|
21
|
+
/** A git commit ref (short or long). */
|
|
22
|
+
export type CommitRef = Brand<string, "CommitRef">;
|
|
23
|
+
/** An ISO-8601 timestamp string. */
|
|
24
|
+
export type IsoTimestamp = Brand<string, "IsoTimestamp">;
|
|
25
|
+
/** A NEMESIS session identifier. */
|
|
26
|
+
export type SessionId = Brand<string, "SessionId">;
|
|
27
|
+
/** A repo-relative path. */
|
|
28
|
+
export type RepoPath = Brand<string, "RepoPath">;
|
|
29
|
+
export declare function asHmacHash(s: string): HmacHash;
|
|
30
|
+
export declare function asVendorId(s: string): VendorId;
|
|
31
|
+
export declare function asClaimText(s: string): ClaimText;
|
|
32
|
+
export declare function asCommitRef(s: string): CommitRef;
|
|
33
|
+
export declare function asIsoTimestamp(s: string | Date): IsoTimestamp;
|
|
34
|
+
export interface Fixture {
|
|
35
|
+
diff: string;
|
|
36
|
+
prDescription: string;
|
|
37
|
+
commitMessages: string[];
|
|
38
|
+
}
|
|
39
|
+
/** Verdict ladder produced by ACGV / verify. */
|
|
40
|
+
export type Verdict = "IMPOSSIBLE_REFUTE" | "AUTO_REFUTE" | "BLACK_HOLE" | "FUSION" | "LIMBO" | "PASSTHROUGH";
|
|
41
|
+
/** Plain envelope every SDK call returns — always includes ok + reason. */
|
|
42
|
+
export interface SdkEnvelope<T> {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
data?: T;
|
|
45
|
+
reason?: string;
|
|
46
|
+
/** Latency in milliseconds (in-process). */
|
|
47
|
+
latencyMs?: number;
|
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AKhD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAM7D;AAID,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,gDAAgD;AAChD,MAAM,MAAM,OAAO,GAAG,mBAAmB,GAAG,aAAa,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAC;AAE9G,2EAA2E;AAC3E,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mneme-ai/sdk types — branded types for type-level safety.
|
|
3
|
+
*
|
|
4
|
+
* "Branded" type pattern: a `Brand<T, "tag">` looks like `T` at runtime
|
|
5
|
+
* but the compiler refuses to substitute one tagged value for another.
|
|
6
|
+
* Prevents string-confusion bugs (e.g. passing a vendor slug where a
|
|
7
|
+
* commit ref is expected).
|
|
8
|
+
*
|
|
9
|
+
* Adopted from world-class TS codebases (Effect, fp-ts).
|
|
10
|
+
*/
|
|
11
|
+
// ── Constructors (validating + casting) ─────────────────────────────
|
|
12
|
+
export function asHmacHash(s) {
|
|
13
|
+
if (typeof s !== "string" || !/^[0-9a-f]{64}$/.test(s)) {
|
|
14
|
+
throw new Error(`asHmacHash: not a SHA-256 hex digest: ${String(s).slice(0, 16)}...`);
|
|
15
|
+
}
|
|
16
|
+
return s;
|
|
17
|
+
}
|
|
18
|
+
export function asVendorId(s) {
|
|
19
|
+
if (typeof s !== "string" || !/^[a-z0-9_-]{1,64}$/.test(s)) {
|
|
20
|
+
throw new Error(`asVendorId: not a valid vendor slug: ${String(s).slice(0, 32)}`);
|
|
21
|
+
}
|
|
22
|
+
return s;
|
|
23
|
+
}
|
|
24
|
+
export function asClaimText(s) {
|
|
25
|
+
if (typeof s !== "string")
|
|
26
|
+
throw new Error("asClaimText: not a string");
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
export function asCommitRef(s) {
|
|
30
|
+
if (typeof s !== "string" || !/^[0-9a-f]{7,64}$/.test(s)) {
|
|
31
|
+
throw new Error(`asCommitRef: not a valid commit hash: ${String(s).slice(0, 32)}`);
|
|
32
|
+
}
|
|
33
|
+
return s;
|
|
34
|
+
}
|
|
35
|
+
export function asIsoTimestamp(s) {
|
|
36
|
+
const v = s instanceof Date ? s.toISOString() : s;
|
|
37
|
+
if (typeof v !== "string" || Number.isNaN(Date.parse(v))) {
|
|
38
|
+
throw new Error(`asIsoTimestamp: not parseable: ${String(v).slice(0, 32)}`);
|
|
39
|
+
}
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoBH,uEAAuE;AAEvE,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,CAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QA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