@pleri/olam-cli 0.1.144 → 0.1.145
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/doctor.d.ts +53 -23
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +117 -46
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/logs.d.ts +17 -3
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +38 -35
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/memory/bridge.d.ts +57 -0
- package/dist/commands/memory/bridge.d.ts.map +1 -0
- package/dist/commands/memory/bridge.js +156 -0
- package/dist/commands/memory/bridge.js.map +1 -0
- package/dist/commands/memory/index.d.ts +3 -0
- package/dist/commands/memory/index.d.ts.map +1 -1
- package/dist/commands/memory/index.js +10 -1
- package/dist/commands/memory/index.js.map +1 -1
- package/dist/commands/memory/reclassify.d.ts +56 -0
- package/dist/commands/memory/reclassify.d.ts.map +1 -0
- package/dist/commands/memory/reclassify.js +177 -0
- package/dist/commands/memory/reclassify.js.map +1 -0
- package/dist/commands/memory/stats.d.ts +69 -0
- package/dist/commands/memory/stats.d.ts.map +1 -0
- package/dist/commands/memory/stats.js +164 -0
- package/dist/commands/memory/stats.js.map +1 -0
- package/dist/commands/skills-source.d.ts +12 -0
- package/dist/commands/skills-source.d.ts.map +1 -0
- package/dist/commands/skills-source.js +133 -0
- package/dist/commands/skills-source.js.map +1 -0
- package/dist/commands/skills.d.ts +11 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +163 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/status.d.ts +27 -0
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +102 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/image-digests.json +7 -7
- package/dist/index.js +2027 -529
- package/dist/index.js.map +1 -1
- package/dist/lib/health-probes.d.ts +72 -0
- package/dist/lib/health-probes.d.ts.map +1 -1
- package/dist/lib/health-probes.js +218 -0
- package/dist/lib/health-probes.js.map +1 -1
- package/dist/mcp-server.js +1246 -351
- package/host-cp/src/agent-runtime-trigger.mjs +74 -4
- package/host-cp/src/engine-identity.mjs +32 -0
- package/host-cp/src/server.mjs +188 -3
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* olam memory bridge serve --local — embedded Miniflare bridge.
|
|
3
|
+
*
|
|
4
|
+
* `wrangler dev` is a dev iteration loop, not a production-style host
|
|
5
|
+
* for a long-lived service. This subcommand spawns
|
|
6
|
+
* `packages/memory-service/scripts/local-bridge-server.mjs` as a
|
|
7
|
+
* foreground Node process: operators wire it into launchd / systemd
|
|
8
|
+
* (Type=simple) and get the agent-memory bridge running on their
|
|
9
|
+
* laptop without a Cloudflare account.
|
|
10
|
+
*
|
|
11
|
+
* Flow:
|
|
12
|
+
* 1. Resolve packages/memory-service/ via the shared candidates list
|
|
13
|
+
* (handles workspace / bundled-CLI / cwd-checkout layouts).
|
|
14
|
+
* 2. Locate scripts/local-bridge-server.mjs inside it.
|
|
15
|
+
* 3. Ensure ~/.olam/memory-secret (0600) exists; pass it via
|
|
16
|
+
* AGENTMEMORY_SECRET env so the bridge can authenticate
|
|
17
|
+
* /bridge/stats callers without leaking the secret on argv.
|
|
18
|
+
* 4. Spawn the .mjs in foreground; stdin/stdout/stderr propagate so
|
|
19
|
+
* the service-manager journal captures the bridge's logs.
|
|
20
|
+
* 5. Forward SIGTERM/SIGINT to the child + exit with its code.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors `start.ts`'s service-resolution + secret-handling pattern;
|
|
23
|
+
* differs in that the spawned process stays in foreground (start.ts
|
|
24
|
+
* detaches because the agentmemory engine is a separate long-lived
|
|
25
|
+
* service).
|
|
26
|
+
*
|
|
27
|
+
* Plan reference: architecture conversation in PR #612.
|
|
28
|
+
*/
|
|
29
|
+
import { spawn } from 'node:child_process';
|
|
30
|
+
import { existsSync } from 'node:fs';
|
|
31
|
+
import { join } from 'node:path';
|
|
32
|
+
import { printError, printHeader, printInfo } from '../../output.js';
|
|
33
|
+
import { ensureMemorySecret } from '../../lib/memory-secret.js';
|
|
34
|
+
import { MEMORY_SERVICE_CANDIDATES } from './_paths.js';
|
|
35
|
+
const DEFAULT_PORT = 8788;
|
|
36
|
+
export function resolveMemoryServiceDir() {
|
|
37
|
+
for (const c of MEMORY_SERVICE_CANDIDATES) {
|
|
38
|
+
if (existsSync(c))
|
|
39
|
+
return c;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Could not find packages/memory-service/. Searched: ${MEMORY_SERVICE_CANDIDATES.join(', ')}. ` +
|
|
42
|
+
`If running from a published @pleri/olam-cli tarball, this is a packaging bug — please file an issue.`);
|
|
43
|
+
}
|
|
44
|
+
export function resolveLocalBridgeScript(serviceDir) {
|
|
45
|
+
const path = join(serviceDir, 'scripts', 'local-bridge-server.mjs');
|
|
46
|
+
if (!existsSync(path)) {
|
|
47
|
+
throw new Error(`Could not find local-bridge-server.mjs at ${path}. ` +
|
|
48
|
+
`Verify packages/memory-service ships the scripts/ directory.`);
|
|
49
|
+
}
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
export function validateBridgeOpts(opts) {
|
|
53
|
+
const local = opts.local ?? false;
|
|
54
|
+
if (!local) {
|
|
55
|
+
throw new Error(`'olam memory bridge serve' currently requires --local. ` +
|
|
56
|
+
`Remote-bridge orchestration is reserved for future flags.`);
|
|
57
|
+
}
|
|
58
|
+
const port = opts.port ?? DEFAULT_PORT;
|
|
59
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
60
|
+
throw new Error(`--port must be an integer 0..65535 (got: ${opts.port})`);
|
|
61
|
+
}
|
|
62
|
+
const result = {
|
|
63
|
+
port,
|
|
64
|
+
local,
|
|
65
|
+
};
|
|
66
|
+
if (typeof opts.persistTo === 'string' && opts.persistTo.length > 0) {
|
|
67
|
+
result.persistTo = opts.persistTo;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
export async function runBridgeServe(opts, deps = {}) {
|
|
72
|
+
printHeader('olam memory bridge serve --local');
|
|
73
|
+
const validated = validateBridgeOpts(opts);
|
|
74
|
+
printInfo('port', String(validated.port));
|
|
75
|
+
if (validated.persistTo) {
|
|
76
|
+
printInfo('persist-to', validated.persistTo);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
printInfo('persist-to', '(in-memory — DO state lost on restart)');
|
|
80
|
+
}
|
|
81
|
+
const serviceDir = (deps.resolveServiceDir ?? resolveMemoryServiceDir)();
|
|
82
|
+
const scriptPath = resolveLocalBridgeScript(serviceDir);
|
|
83
|
+
printInfo('entry', scriptPath);
|
|
84
|
+
const secret = (deps.ensureSecret ?? ensureMemorySecret)();
|
|
85
|
+
const args = ['--port', String(validated.port)];
|
|
86
|
+
if (validated.persistTo) {
|
|
87
|
+
args.push('--persist-to', validated.persistTo);
|
|
88
|
+
}
|
|
89
|
+
const env = {
|
|
90
|
+
...process.env,
|
|
91
|
+
AGENTMEMORY_SECRET: secret,
|
|
92
|
+
};
|
|
93
|
+
const spawner = deps.spawnChild ??
|
|
94
|
+
((command, spawnArgs, spawnEnv) => spawn(command, [...spawnArgs], {
|
|
95
|
+
env: spawnEnv,
|
|
96
|
+
stdio: 'inherit',
|
|
97
|
+
}));
|
|
98
|
+
const child = spawner(process.execPath, [scriptPath, ...args], env);
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
let resolved = false;
|
|
101
|
+
const finish = (code) => {
|
|
102
|
+
if (resolved)
|
|
103
|
+
return;
|
|
104
|
+
resolved = true;
|
|
105
|
+
resolve(code);
|
|
106
|
+
};
|
|
107
|
+
const forward = (signal) => () => {
|
|
108
|
+
if (!child.killed) {
|
|
109
|
+
try {
|
|
110
|
+
child.kill(signal);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Best-effort signal forwarding; child may already be exiting.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
process.on('SIGTERM', forward('SIGTERM'));
|
|
118
|
+
process.on('SIGINT', forward('SIGINT'));
|
|
119
|
+
child.on('error', (err) => {
|
|
120
|
+
printError(`failed to spawn local-bridge-server.mjs: ${err.message}`);
|
|
121
|
+
finish(1);
|
|
122
|
+
});
|
|
123
|
+
child.on('exit', (code, signal) => {
|
|
124
|
+
if (signal) {
|
|
125
|
+
// Treat signal-driven exit as success (operator stopped service).
|
|
126
|
+
finish(0);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
finish(code ?? 1);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function registerMemoryBridge(cmd) {
|
|
135
|
+
const bridge = cmd
|
|
136
|
+
.command('bridge')
|
|
137
|
+
.description('Local bridge service (Miniflare-embedded) for the agent-memory engine');
|
|
138
|
+
bridge
|
|
139
|
+
.command('serve')
|
|
140
|
+
.description('Run the agent-memory bridge as a foreground Node process (suitable for systemd/launchd)')
|
|
141
|
+
.option('--local', 'Use the embedded Miniflare runtime (currently required)')
|
|
142
|
+
.option('--port <n>', 'TCP port to bind on', (v) => parseInt(v, 10), DEFAULT_PORT)
|
|
143
|
+
.option('--persist-to <path>', 'DO SQLite persistence directory')
|
|
144
|
+
.action(async (opts) => {
|
|
145
|
+
try {
|
|
146
|
+
const rc = await runBridgeServe(opts);
|
|
147
|
+
if (rc !== 0)
|
|
148
|
+
process.exitCode = rc;
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
printError(err instanceof Error ? err.message : String(err));
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../src/commands/memory/bridge.ts"],"names":[],"mappings":"AA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G,EAAE,CAAC;YACb,UAAU,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* secret — show / rotate the bearer secret at ~/.olam/memory-secret
|
|
10
10
|
* install — register agentmemory with the operator's host claude
|
|
11
11
|
* uninstall — symmetric (idempotent)
|
|
12
|
+
* bridge — Miniflare-embedded local bridge service (alt to wrangler dev)
|
|
13
|
+
* reclassify — bust classifier cache by content_hash OR since_version
|
|
14
|
+
* stats — format /bridge/stats with derived cache-error-rate
|
|
12
15
|
*
|
|
13
16
|
* Plan reference: docs/plans/olam-agent-memory-distributed/phase-a-tasks.md
|
|
14
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/memory/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAazC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkBrD"}
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* secret — show / rotate the bearer secret at ~/.olam/memory-secret
|
|
10
10
|
* install — register agentmemory with the operator's host claude
|
|
11
11
|
* uninstall — symmetric (idempotent)
|
|
12
|
+
* bridge — Miniflare-embedded local bridge service (alt to wrangler dev)
|
|
13
|
+
* reclassify — bust classifier cache by content_hash OR since_version
|
|
14
|
+
* stats — format /bridge/stats with derived cache-error-rate
|
|
12
15
|
*
|
|
13
16
|
* Plan reference: docs/plans/olam-agent-memory-distributed/phase-a-tasks.md
|
|
14
17
|
*/
|
|
@@ -20,10 +23,13 @@ import { registerMemorySecret } from './secret.js';
|
|
|
20
23
|
import { registerMemoryInstall } from './install.js';
|
|
21
24
|
import { registerMemoryUninstall } from './uninstall.js';
|
|
22
25
|
import { registerMemoryMode } from './mode.js';
|
|
26
|
+
import { registerMemoryBridge } from './bridge.js';
|
|
27
|
+
import { registerMemoryReclassify } from './reclassify.js';
|
|
28
|
+
import { registerMemoryStats } from './stats.js';
|
|
23
29
|
export function registerMemory(program) {
|
|
24
30
|
const memory = program
|
|
25
31
|
.command('memory')
|
|
26
|
-
.description('Host-process agent-memory service for the olam fleet (start, stop, status, logs, secret, install, uninstall)');
|
|
32
|
+
.description('Host-process agent-memory service for the olam fleet (start, stop, status, logs, secret, install, uninstall, bridge, reclassify, stats)');
|
|
27
33
|
registerMemoryStart(memory);
|
|
28
34
|
registerMemoryStop(memory);
|
|
29
35
|
registerMemoryStatus(memory);
|
|
@@ -32,5 +38,8 @@ export function registerMemory(program) {
|
|
|
32
38
|
registerMemoryInstall(memory);
|
|
33
39
|
registerMemoryUninstall(memory);
|
|
34
40
|
registerMemoryMode(memory);
|
|
41
|
+
registerMemoryBridge(memory);
|
|
42
|
+
registerMemoryReclassify(memory);
|
|
43
|
+
registerMemoryStats(memory);
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/memory/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,MAAM,MAAM,GAAG,OAAO;SACnB,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CACV,yIAAyI,CAC1I,CAAC;IAEJ,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9B,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAChC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACjC,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* olam memory reclassify — operator wrapper over the bridge
|
|
3
|
+
* `/classify/cache-bust` endpoint (Phase B5). Two modes:
|
|
4
|
+
*
|
|
5
|
+
* $ olam memory reclassify --content-hash=sha256:abc...
|
|
6
|
+
* # bust one cache entry by content hash
|
|
7
|
+
*
|
|
8
|
+
* $ olam memory reclassify --since-version=haiku-v1+prompt-v1
|
|
9
|
+
* # bulk bust by classifier_version (operator-side after a
|
|
10
|
+
* # prompt-template change)
|
|
11
|
+
*
|
|
12
|
+
* $ olam memory reclassify --content-hash=sha256:abc... --dry-run
|
|
13
|
+
* # show what would be busted without calling the bridge
|
|
14
|
+
*
|
|
15
|
+
* Config (env vars):
|
|
16
|
+
* AGENTMEMORY_BRIDGE_URL bridge base URL
|
|
17
|
+
* (default: https://olam-agent-memory.ernestcodes.workers.dev)
|
|
18
|
+
* AGENTMEMORY_BRIDGE_SECRET bearer token
|
|
19
|
+
*
|
|
20
|
+
* Plan reference:
|
|
21
|
+
* docs/plans/agentmemory-classifier-and-regret/phase-b-tasks.md B5
|
|
22
|
+
* (Originally bundled into B5; carved out as B5.1 because the
|
|
23
|
+
* bridge endpoint shipped in PR #612 + the CLI is convenience.)
|
|
24
|
+
*/
|
|
25
|
+
import type { Command } from 'commander';
|
|
26
|
+
export interface ReclassifyOptions {
|
|
27
|
+
contentHash?: string;
|
|
28
|
+
sinceVersion?: string;
|
|
29
|
+
dryRun?: boolean;
|
|
30
|
+
bridgeUrl?: string;
|
|
31
|
+
bearer?: string;
|
|
32
|
+
json?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ReclassifyResult {
|
|
35
|
+
ok: boolean;
|
|
36
|
+
busted: number;
|
|
37
|
+
mode: 'hash' | 'version' | 'dry-run';
|
|
38
|
+
memoryId?: string;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate that the operator supplied EXACTLY one of `--content-hash`
|
|
43
|
+
* or `--since-version`. Returns a clean error string for any malformed
|
|
44
|
+
* input. (Matches the bridge handler's validateCacheBustRequest contract
|
|
45
|
+
* — operator-side errors fail loudly before any HTTP call.)
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateReclassifyOptions(opts: ReclassifyOptions): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* Run the reclassify call. Pure-ish: takes opts + fetch (so tests can
|
|
50
|
+
* stub) + returns a structured result.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runReclassify(opts: ReclassifyOptions, fetchImpl?: typeof fetch): Promise<ReclassifyResult>;
|
|
53
|
+
/** Run + render. Returns the process exit code. */
|
|
54
|
+
export declare function runReclassifyCli(opts: ReclassifyOptions): Promise<number>;
|
|
55
|
+
export declare function registerMemoryReclassify(cmd: Command): void;
|
|
56
|
+
//# sourceMappingURL=reclassify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reclassify.d.ts","sourceRoot":"","sources":["../../../src/commands/memory/reclassify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAchF;AAgBD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,EACvB,SAAS,GAAE,OAAO,KAAa,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CAmE3B;AAED,mDAAmD;AACnD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqC/E;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAgB3D"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* olam memory reclassify — operator wrapper over the bridge
|
|
3
|
+
* `/classify/cache-bust` endpoint (Phase B5). Two modes:
|
|
4
|
+
*
|
|
5
|
+
* $ olam memory reclassify --content-hash=sha256:abc...
|
|
6
|
+
* # bust one cache entry by content hash
|
|
7
|
+
*
|
|
8
|
+
* $ olam memory reclassify --since-version=haiku-v1+prompt-v1
|
|
9
|
+
* # bulk bust by classifier_version (operator-side after a
|
|
10
|
+
* # prompt-template change)
|
|
11
|
+
*
|
|
12
|
+
* $ olam memory reclassify --content-hash=sha256:abc... --dry-run
|
|
13
|
+
* # show what would be busted without calling the bridge
|
|
14
|
+
*
|
|
15
|
+
* Config (env vars):
|
|
16
|
+
* AGENTMEMORY_BRIDGE_URL bridge base URL
|
|
17
|
+
* (default: https://olam-agent-memory.ernestcodes.workers.dev)
|
|
18
|
+
* AGENTMEMORY_BRIDGE_SECRET bearer token
|
|
19
|
+
*
|
|
20
|
+
* Plan reference:
|
|
21
|
+
* docs/plans/agentmemory-classifier-and-regret/phase-b-tasks.md B5
|
|
22
|
+
* (Originally bundled into B5; carved out as B5.1 because the
|
|
23
|
+
* bridge endpoint shipped in PR #612 + the CLI is convenience.)
|
|
24
|
+
*/
|
|
25
|
+
import { printError, printInfo, printHeader, printWarning } from '../../output.js';
|
|
26
|
+
const DEFAULT_BRIDGE_URL = 'https://olam-agent-memory.ernestcodes.workers.dev';
|
|
27
|
+
const RECLASSIFY_TIMEOUT_MS = 10_000;
|
|
28
|
+
/**
|
|
29
|
+
* Validate that the operator supplied EXACTLY one of `--content-hash`
|
|
30
|
+
* or `--since-version`. Returns a clean error string for any malformed
|
|
31
|
+
* input. (Matches the bridge handler's validateCacheBustRequest contract
|
|
32
|
+
* — operator-side errors fail loudly before any HTTP call.)
|
|
33
|
+
*/
|
|
34
|
+
export function validateReclassifyOptions(opts) {
|
|
35
|
+
const hasHash = typeof opts.contentHash === 'string' && opts.contentHash.length > 0;
|
|
36
|
+
const hasVersion = typeof opts.sinceVersion === 'string' && opts.sinceVersion.length > 0;
|
|
37
|
+
if (!hasHash && !hasVersion) {
|
|
38
|
+
return 'must specify one of --content-hash or --since-version';
|
|
39
|
+
}
|
|
40
|
+
if (hasHash && hasVersion) {
|
|
41
|
+
return '--content-hash and --since-version are mutually exclusive';
|
|
42
|
+
}
|
|
43
|
+
if (hasHash && !/^sha256:[0-9a-f]{64}$/.test(opts.contentHash)) {
|
|
44
|
+
return '--content-hash must be sha256:<64hex>';
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function resolveBridgeUrl(opts) {
|
|
49
|
+
return opts.bridgeUrl
|
|
50
|
+
?? process.env['AGENTMEMORY_BRIDGE_URL']
|
|
51
|
+
?? DEFAULT_BRIDGE_URL;
|
|
52
|
+
}
|
|
53
|
+
function resolveBearer(opts) {
|
|
54
|
+
const fromOpt = opts.bearer;
|
|
55
|
+
if (fromOpt && fromOpt.length > 0)
|
|
56
|
+
return fromOpt;
|
|
57
|
+
const fromEnv = process.env['AGENTMEMORY_BRIDGE_SECRET'];
|
|
58
|
+
if (fromEnv && fromEnv.length > 0)
|
|
59
|
+
return fromEnv;
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run the reclassify call. Pure-ish: takes opts + fetch (so tests can
|
|
64
|
+
* stub) + returns a structured result.
|
|
65
|
+
*/
|
|
66
|
+
export async function runReclassify(opts, fetchImpl = fetch) {
|
|
67
|
+
const validationError = validateReclassifyOptions(opts);
|
|
68
|
+
if (validationError) {
|
|
69
|
+
return { ok: false, busted: 0, mode: opts.contentHash ? 'hash' : 'version', error: validationError };
|
|
70
|
+
}
|
|
71
|
+
if (opts.dryRun) {
|
|
72
|
+
return {
|
|
73
|
+
ok: true,
|
|
74
|
+
busted: 0,
|
|
75
|
+
mode: 'dry-run',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const bridgeUrl = resolveBridgeUrl(opts);
|
|
79
|
+
const bearer = resolveBearer(opts);
|
|
80
|
+
if (!bearer) {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
busted: 0,
|
|
84
|
+
mode: opts.contentHash ? 'hash' : 'version',
|
|
85
|
+
error: 'AGENTMEMORY_BRIDGE_SECRET not set (or --bearer not passed)',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const body = opts.contentHash
|
|
89
|
+
? { content_hash: opts.contentHash }
|
|
90
|
+
: { since_version: opts.sinceVersion };
|
|
91
|
+
try {
|
|
92
|
+
const res = await fetchImpl(`${bridgeUrl}/classify/cache-bust`, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: {
|
|
95
|
+
authorization: `Bearer ${bearer}`,
|
|
96
|
+
'content-type': 'application/json',
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify(body),
|
|
99
|
+
signal: AbortSignal.timeout(RECLASSIFY_TIMEOUT_MS),
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const detail = await res.text().catch(() => '');
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
busted: 0,
|
|
106
|
+
mode: opts.contentHash ? 'hash' : 'version',
|
|
107
|
+
error: `bridge returned ${res.status} ${res.statusText}${detail ? `: ${detail.slice(0, 200)}` : ''}`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const payload = (await res.json());
|
|
111
|
+
return {
|
|
112
|
+
ok: true,
|
|
113
|
+
busted: payload.busted,
|
|
114
|
+
mode: payload.mode,
|
|
115
|
+
memoryId: payload.memoryId,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
busted: 0,
|
|
122
|
+
mode: opts.contentHash ? 'hash' : 'version',
|
|
123
|
+
error: err instanceof Error ? err.message : String(err),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Run + render. Returns the process exit code. */
|
|
128
|
+
export async function runReclassifyCli(opts) {
|
|
129
|
+
const result = await runReclassify(opts);
|
|
130
|
+
if (opts.json) {
|
|
131
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
132
|
+
return result.ok ? 0 : 1;
|
|
133
|
+
}
|
|
134
|
+
printHeader('olam memory reclassify');
|
|
135
|
+
if (opts.contentHash) {
|
|
136
|
+
printInfo('content-hash', opts.contentHash);
|
|
137
|
+
}
|
|
138
|
+
if (opts.sinceVersion) {
|
|
139
|
+
printInfo('since-version', opts.sinceVersion);
|
|
140
|
+
}
|
|
141
|
+
printInfo('mode', result.mode);
|
|
142
|
+
if (opts.dryRun) {
|
|
143
|
+
printInfo('dry-run', 'no HTTP call made');
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
if (!result.ok) {
|
|
147
|
+
printError(`reclassify failed: ${result.error ?? '(unknown error)'}`);
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
if (result.busted === 0) {
|
|
151
|
+
printWarning(`no rows busted (hash not in cache OR no rows matched the version)`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
printInfo('busted', `${result.busted}`);
|
|
155
|
+
if (result.memoryId) {
|
|
156
|
+
printInfo('memory-id', result.memoryId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
export function registerMemoryReclassify(cmd) {
|
|
162
|
+
cmd
|
|
163
|
+
.command('reclassify')
|
|
164
|
+
.description('Bust the bridge classifier cache (single entry by content hash OR bulk by classifier_version) so the next batch re-runs the LLM')
|
|
165
|
+
.option('--content-hash <hash>', 'Bust one entry by sha256:<64hex> content hash')
|
|
166
|
+
.option('--since-version <version>', 'Bulk bust by classifier_version (e.g. "haiku-v1+prompt-v1")')
|
|
167
|
+
.option('--dry-run', 'Show what would be busted without calling the bridge', false)
|
|
168
|
+
.option('--bridge-url <url>', 'Override AGENTMEMORY_BRIDGE_URL')
|
|
169
|
+
.option('--bearer <token>', 'Override AGENTMEMORY_BRIDGE_SECRET')
|
|
170
|
+
.option('--json', 'Machine-readable JSON output', false)
|
|
171
|
+
.action(async (opts) => {
|
|
172
|
+
const rc = await runReclassifyCli(opts);
|
|
173
|
+
if (rc !== 0)
|
|
174
|
+
process.exitCode = rc;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=reclassify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reclassify.js","sourceRoot":"","sources":["../../../src/commands/memory/reclassify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnF,MAAM,kBAAkB,GAAG,mDAAmD,CAAC;AAC/E,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAmBrC;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAuB;IAC/D,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;IACpF,MAAM,UAAU,GAAG,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;QAC5B,OAAO,uDAAuD,CAAC;IACjE,CAAC;IACD,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;Q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,EAAE,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,EAAE,KAAK,CAAC;YAAE,OAAO,CAAC,QAAQ,GAAG,EAAE,CAAC;IACtC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* olam memory stats — operator-facing formatter over `/bridge/stats`.
|
|
3
|
+
*
|
|
4
|
+
* $ olam memory stats
|
|
5
|
+
* # human-readable counters + derived cache_error_rate
|
|
6
|
+
*
|
|
7
|
+
* $ olam memory stats --json
|
|
8
|
+
* # raw /bridge/stats response (for jq / monitoring scripts)
|
|
9
|
+
*
|
|
10
|
+
* Config (env vars):
|
|
11
|
+
* AGENTMEMORY_BRIDGE_URL bridge base URL
|
|
12
|
+
* (default: https://olam-agent-memory.ernestcodes.workers.dev)
|
|
13
|
+
* AGENTMEMORY_BRIDGE_SECRET bearer token
|
|
14
|
+
*
|
|
15
|
+
* Derived metric: cache_error_rate =
|
|
16
|
+
* (cache_busted_hash + cache_busted_version) / max(writes_observed, 1)
|
|
17
|
+
*
|
|
18
|
+
* Interpretation: high rates (>5%) mean operators have been forced to
|
|
19
|
+
* reclassify a lot of recent writes — usually a sign that the prompt
|
|
20
|
+
* template / classifier_version is churning. The denominator is
|
|
21
|
+
* classifier_writes_observed (NOT bridge writes_observed).
|
|
22
|
+
*
|
|
23
|
+
* Plan reference:
|
|
24
|
+
* docs/plans/agentmemory-classifier-and-regret/phase-b-tasks.md (B5/B6)
|
|
25
|
+
*/
|
|
26
|
+
import type { Command } from 'commander';
|
|
27
|
+
export interface StatsOptions {
|
|
28
|
+
bridgeUrl?: string;
|
|
29
|
+
bearer?: string;
|
|
30
|
+
json?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The seven counters this command formats. Mirrors the classifier_*
|
|
34
|
+
* subset of {@link BridgeStatsSnapshot} but renamed to drop the
|
|
35
|
+
* `classifier_` prefix — operators see "writes_observed" not
|
|
36
|
+
* "classifier_writes_observed" when scanning output.
|
|
37
|
+
*/
|
|
38
|
+
export interface StatsCounters {
|
|
39
|
+
writes_observed: number;
|
|
40
|
+
writes_deduped_hash: number;
|
|
41
|
+
writes_deduped_semantic: number;
|
|
42
|
+
recalls_observed: number;
|
|
43
|
+
cache_busted_hash: number;
|
|
44
|
+
cache_busted_version: number;
|
|
45
|
+
}
|
|
46
|
+
export interface StatsResult {
|
|
47
|
+
ok: boolean;
|
|
48
|
+
counters?: StatsCounters;
|
|
49
|
+
/** Decimal fraction, 0–1+. Multiply by 100 for display percentage. */
|
|
50
|
+
cacheErrorRate?: number;
|
|
51
|
+
/** Raw /bridge/stats envelope (preserved for --json mode). */
|
|
52
|
+
raw?: unknown;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Pure helper — separated so it's unit-testable without HTTP.
|
|
57
|
+
* Guards divide-by-zero (returns 0 when writes_observed === 0, even
|
|
58
|
+
* if busts are nonzero — Infinity / NaN would be operator-hostile).
|
|
59
|
+
*/
|
|
60
|
+
export declare function computeCacheErrorRate(counters: Pick<StatsCounters, 'writes_observed' | 'cache_busted_hash' | 'cache_busted_version'>): number;
|
|
61
|
+
/**
|
|
62
|
+
* Run the stats call. Pure-ish: takes opts + fetch (so tests can stub) +
|
|
63
|
+
* returns a structured result. Mirrors `runReclassify` for symmetry.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runStats(opts: StatsOptions, fetchImpl?: typeof fetch): Promise<StatsResult>;
|
|
66
|
+
/** Run + render. Returns the process exit code. */
|
|
67
|
+
export declare function runStatsCli(opts: StatsOptions): Promise<number>;
|
|
68
|
+
export declare function registerMemoryStats(cmd: Command): void;
|
|
69
|
+
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/commands/memory/stats.ts"],"names":[],"mappings":"AAAA;;;;;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