ctxpipe 0.1.0-alpha.0 → 0.2.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/LICENSE +21 -0
- package/README.md +74 -0
- package/bin/ctxpipe.js +6 -42
- package/dist/auth.d.ts +52 -0
- package/dist/auth.js +416 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +56 -0
- package/dist/commands.js +264 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +19 -0
- package/dist/constants.js.map +1 -0
- package/dist/fs-operations.d.ts +16 -0
- package/dist/fs-operations.js +62 -0
- package/dist/fs-operations.js.map +1 -0
- package/dist/mcp/json.d.ts +3 -0
- package/dist/mcp/json.js +15 -0
- package/dist/mcp/json.js.map +1 -0
- package/dist/mcp/mcp-operations.d.ts +103 -0
- package/dist/mcp/mcp-operations.js +464 -0
- package/dist/mcp/mcp-operations.js.map +1 -0
- package/dist/mcp/paths.d.ts +7 -0
- package/dist/mcp/paths.js +17 -0
- package/dist/mcp/paths.js.map +1 -0
- package/dist/memory/agentmemory-client.d.ts +24 -0
- package/dist/memory/agentmemory-client.js +47 -0
- package/dist/memory/agentmemory-client.js.map +1 -0
- package/dist/memory/hydration.d.ts +141 -0
- package/dist/memory/hydration.js +390 -0
- package/dist/memory/hydration.js.map +1 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/markdown.d.ts +29 -0
- package/dist/memory/markdown.js +193 -0
- package/dist/memory/markdown.js.map +1 -0
- package/dist/memory/mcp-server.d.ts +48 -0
- package/dist/memory/mcp-server.js +322 -0
- package/dist/memory/mcp-server.js.map +1 -0
- package/dist/memory/paths.d.ts +12 -0
- package/dist/memory/paths.js +71 -0
- package/dist/memory/paths.js.map +1 -0
- package/dist/memory/policy.d.ts +16 -0
- package/dist/memory/policy.js +81 -0
- package/dist/memory/policy.js.map +1 -0
- package/dist/memory/run-hook.d.ts +13 -0
- package/dist/memory/run-hook.js +44 -0
- package/dist/memory/run-hook.js.map +1 -0
- package/dist/memory/run-init.d.ts +11 -0
- package/dist/memory/run-init.js +92 -0
- package/dist/memory/run-init.js.map +1 -0
- package/dist/memory/run-mcp.d.ts +3 -0
- package/dist/memory/run-mcp.js +7 -0
- package/dist/memory/run-mcp.js.map +1 -0
- package/dist/memory/run-meta.d.ts +11 -0
- package/dist/memory/run-meta.js +124 -0
- package/dist/memory/run-meta.js.map +1 -0
- package/dist/memory/supervisor.d.ts +49 -0
- package/dist/memory/supervisor.js +217 -0
- package/dist/memory/supervisor.js.map +1 -0
- package/dist/program.d.ts +1 -0
- package/dist/program.js +209 -0
- package/dist/program.js.map +1 -0
- package/dist/prompts.d.ts +42 -0
- package/dist/prompts.js +336 -0
- package/dist/prompts.js.map +1 -0
- package/dist/system.d.ts +3 -0
- package/dist/system.js +27 -0
- package/dist/system.js.map +1 -0
- package/dist/ui.d.ts +20 -0
- package/dist/ui.js +115 -0
- package/dist/ui.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +26 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { resolve, join, isAbsolute } from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
export const DEFAULT_MEMORY_ROOT = ".ai/memory";
|
|
7
|
+
/** Override for tests so we don't write into the real user home. */
|
|
8
|
+
export function memoryStateRoot() {
|
|
9
|
+
const override = process.env.CTXPIPE_MEMORY_STATE_ROOT;
|
|
10
|
+
if (override && override.length > 0) {
|
|
11
|
+
return override;
|
|
12
|
+
}
|
|
13
|
+
return join(homedir(), ".config", "ctxpipe", "memory");
|
|
14
|
+
}
|
|
15
|
+
export function detectRepoFingerprint(cwd) {
|
|
16
|
+
const top = gitTopLevel(cwd) ?? cwd;
|
|
17
|
+
const worktree = gitCommonDir(cwd) ?? top;
|
|
18
|
+
const hash = createHash("sha256")
|
|
19
|
+
.update(top)
|
|
20
|
+
.update("\0")
|
|
21
|
+
.update(worktree)
|
|
22
|
+
.digest("hex")
|
|
23
|
+
.slice(0, 16);
|
|
24
|
+
return `repo_${hash}`;
|
|
25
|
+
}
|
|
26
|
+
function gitTopLevel(cwd) {
|
|
27
|
+
const result = spawnSync("git", ["rev-parse", "--show-toplevel"], {
|
|
28
|
+
cwd,
|
|
29
|
+
encoding: "utf8",
|
|
30
|
+
});
|
|
31
|
+
if (result.status === 0 && result.stdout) {
|
|
32
|
+
return result.stdout.trim();
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function gitCommonDir(cwd) {
|
|
37
|
+
const result = spawnSync("git", ["rev-parse", "--git-common-dir"], {
|
|
38
|
+
cwd,
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
});
|
|
41
|
+
if (result.status === 0 && result.stdout) {
|
|
42
|
+
const value = result.stdout.trim();
|
|
43
|
+
return isAbsolute(value) ? value : resolve(cwd, value);
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
export function ensureRepoStateDir(fingerprint) {
|
|
48
|
+
const dir = join(memoryStateRoot(), "repos", fingerprint);
|
|
49
|
+
if (!existsSync(dir))
|
|
50
|
+
mkdirSync(dir, { recursive: true });
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
export function repoStateDir(fingerprint) {
|
|
54
|
+
return join(memoryStateRoot(), "repos", fingerprint);
|
|
55
|
+
}
|
|
56
|
+
export function runtimeStateFile(fingerprint) {
|
|
57
|
+
return join(repoStateDir(fingerprint), "runtime.json");
|
|
58
|
+
}
|
|
59
|
+
export function hydrationManifestFile(fingerprint) {
|
|
60
|
+
return join(repoStateDir(fingerprint), "hydration-manifest.json");
|
|
61
|
+
}
|
|
62
|
+
export function hydrationLockFile(fingerprint) {
|
|
63
|
+
return join(repoStateDir(fingerprint), "hydration.lock");
|
|
64
|
+
}
|
|
65
|
+
export function agentMemoryHomeDir(fingerprint) {
|
|
66
|
+
return join(repoStateDir(fingerprint), "agentmemory-home");
|
|
67
|
+
}
|
|
68
|
+
export function resolveMemoryRoot(cwd) {
|
|
69
|
+
return resolve(cwd, DEFAULT_MEMORY_ROOT);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/memory/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAA;AAE/C,oEAAoE;AACpE,MAAM,UAAU,eAAe;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAA;IACtD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;AACxD,CAAC;AAID,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAA;I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AAC,eAAe,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;IACzD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,WAA4B;IACvD,OAAO,IAAI,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;AACtD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,WAA4B;IAC3D,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,WAA4B;IAChE,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,yBAAyB,CAAC,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAA4B;IAC5D,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAC1D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,WAA4B;IAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC,CAAA;AAC5D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,OAAO,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hybrid MCP policy proxy.
|
|
3
|
+
*
|
|
4
|
+
* The table below is the source of truth for which AgentMemory tools the
|
|
5
|
+
* agent sees and what ctxpipe does with each call. New AgentMemory tools
|
|
6
|
+
* default to `hide` until we add an explicit policy entry so we never leak
|
|
7
|
+
* upstream surface area without a deliberate decision.
|
|
8
|
+
*/
|
|
9
|
+
export type PolicyAction = "write-markdown-then-hydrate" | "hydrate-then-query-or-markdown-fallback" | "gate-hosted-model" | "ctxpipe-native" | "hide";
|
|
10
|
+
export declare const POLICY: Record<string, PolicyAction>;
|
|
11
|
+
export type ToolSpec = {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
export declare function toolSpec(name: string): ToolSpec;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const POLICY = {
|
|
2
|
+
memory_save: "write-markdown-then-hydrate",
|
|
3
|
+
memory_recall: "hydrate-then-query-or-markdown-fallback",
|
|
4
|
+
memory_smart_search: "hydrate-then-query-or-markdown-fallback",
|
|
5
|
+
memory_status: "ctxpipe-native",
|
|
6
|
+
memory_summarize_session: "gate-hosted-model",
|
|
7
|
+
memory_consolidate: "gate-hosted-model",
|
|
8
|
+
memory_export: "hide",
|
|
9
|
+
memory_governance_delete: "hide",
|
|
10
|
+
};
|
|
11
|
+
const DESCRIPTIONS = {
|
|
12
|
+
memory_save: {
|
|
13
|
+
name: "memory_save",
|
|
14
|
+
description: "Save a durable memory record into the canonical .ai/memory Markdown tree, then hydrate AgentMemory.",
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: "object",
|
|
17
|
+
required: ["id", "body"],
|
|
18
|
+
properties: {
|
|
19
|
+
id: { type: "string", description: "Stable identifier (slug). Must be unique across the repo." },
|
|
20
|
+
type: { type: "string", description: "Record category: architecture | decision | pattern | lesson | session | fact | note" },
|
|
21
|
+
title: { type: "string", description: "Human-readable title; defaults to the id." },
|
|
22
|
+
body: { type: "string", description: "Markdown body. Must be safe to commit." },
|
|
23
|
+
concepts: { type: "array", items: { type: "string" } },
|
|
24
|
+
files: { type: "array", items: { type: "string" } },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
memory_recall: {
|
|
29
|
+
name: "memory_recall",
|
|
30
|
+
description: "Recall ctxpipe memories matching the query. Uses hydrated AgentMemory when available, falls back to direct Markdown search.",
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: "object",
|
|
33
|
+
required: ["query"],
|
|
34
|
+
properties: {
|
|
35
|
+
query: { type: "string" },
|
|
36
|
+
limit: { type: "integer", minimum: 1, maximum: 50 },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
memory_smart_search: {
|
|
41
|
+
name: "memory_smart_search",
|
|
42
|
+
description: "Smart search over ctxpipe memories. Like memory_recall but allows AgentMemory to use richer ranking when available.",
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: "object",
|
|
45
|
+
required: ["query"],
|
|
46
|
+
properties: {
|
|
47
|
+
query: { type: "string" },
|
|
48
|
+
limit: { type: "integer", minimum: 1, maximum: 50 },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
memory_status: {
|
|
53
|
+
name: "memory_status",
|
|
54
|
+
description: "Report current memory mode (signed-in / signed-out), runtime URL if any, and hosted model availability.",
|
|
55
|
+
inputSchema: { type: "object", properties: {} },
|
|
56
|
+
},
|
|
57
|
+
memory_summarize_session: {
|
|
58
|
+
name: "memory_summarize_session",
|
|
59
|
+
description: "Summarize the current session into a durable lesson. Requires ctxpipe hosted model access.",
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
sessionId: { type: "string" },
|
|
64
|
+
prompt: { type: "string" },
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
memory_consolidate: {
|
|
69
|
+
name: "memory_consolidate",
|
|
70
|
+
description: "Consolidate recent memories. Requires ctxpipe hosted model access.",
|
|
71
|
+
inputSchema: { type: "object", properties: {} },
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
export function toolSpec(name) {
|
|
75
|
+
return (DESCRIPTIONS[name] ?? {
|
|
76
|
+
name,
|
|
77
|
+
description: `ctxpipe memory tool ${name}`,
|
|
78
|
+
inputSchema: { type: "object", properties: {} },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/memory/policy.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,MAAM,GAAiC;IAClD,WAAW,EAAE,6BAA6B;IAC1C,aAAa,EAAE,yCAAyC;IACxD,mBAAmB,EAAE,yCAAyC;IAC9D,aAAa,EAAE,gBAAgB;IAC/B,wBAAwB,EAAE,mBAAmB;IAC7C,kBAAkB,EAAE,mBAAmB;IACvC,aAAa,EAAE,MAAM;IACrB,wBAAwB,EAAE,MAAM;CACjC,CAAA;AAQD,MAAM,YAAY,GAA6B;IAC7C,WAAW,EAAE;QACX,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,qGAAqG;QACvG,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;YACxB,UAAU,EAAE;gBACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2DAA2D,EAAE;gBAChG,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qFAAqF,EAAE;gBAC5H,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2CAA2C,EAAE;gBACnF,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,wCAAwC,EAAE;gBAC/E,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACtD,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;aACpD;SACF;KACF;IACD,aAAa,EAAE;QACb,IAAI,EAAE,eAAe;QACrB,WAAW,EACT,6HA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AI;QACpB,IAAI;QACJ,WAAW,EAAE,uBAAuB,IAAI,EAAE;QAC1C,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;KAChD,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle hook entrypoint. Invoked by agent-native hook configs (Claude Code,
|
|
3
|
+
* etc.) — must exit fast and never block the agent.
|
|
4
|
+
*
|
|
5
|
+
* For v1 we drop a JSON marker into the per-repo state dir so other parts of
|
|
6
|
+
* the system can observe that a session started/ended. Heavier work (summaries,
|
|
7
|
+
* consolidation, graph extraction) is deferred to the supervisor and runs when
|
|
8
|
+
* hosted model access is available.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runMemoryHook(opts: {
|
|
11
|
+
name: string;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resolveCtxpipeBaseUrl } from "../auth.js";
|
|
4
|
+
import { ensureRepoStateDir, runtimeStateFile } from "./paths.js";
|
|
5
|
+
import { detectRepoFingerprint } from "./paths.js";
|
|
6
|
+
/**
|
|
7
|
+
* Lifecycle hook entrypoint. Invoked by agent-native hook configs (Claude Code,
|
|
8
|
+
* etc.) — must exit fast and never block the agent.
|
|
9
|
+
*
|
|
10
|
+
* For v1 we drop a JSON marker into the per-repo state dir so other parts of
|
|
11
|
+
* the system can observe that a session started/ended. Heavier work (summaries,
|
|
12
|
+
* consolidation, graph extraction) is deferred to the supervisor and runs when
|
|
13
|
+
* hosted model access is available.
|
|
14
|
+
*/
|
|
15
|
+
export async function runMemoryHook(opts) {
|
|
16
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
17
|
+
const fingerprint = detectRepoFingerprint(process.cwd());
|
|
18
|
+
const stateDir = ensureRepoStateDir(fingerprint);
|
|
19
|
+
const event = {
|
|
20
|
+
name: opts.name,
|
|
21
|
+
baseUrl,
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
at: new Date().toISOString(),
|
|
24
|
+
};
|
|
25
|
+
const eventsFile = join(stateDir, "hook-events.jsonl");
|
|
26
|
+
try {
|
|
27
|
+
writeFileSync(eventsFile, `${JSON.stringify(event)}\n`, { flag: "a" });
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// hooks must never throw — they would break the agent session
|
|
31
|
+
}
|
|
32
|
+
// Touch the runtime file modification time so the supervisor can pick up the
|
|
33
|
+
// event on the next memory tool call without us having to run a long-lived
|
|
34
|
+
// worker here.
|
|
35
|
+
const runtimeFile = runtimeStateFile(fingerprint);
|
|
36
|
+
try {
|
|
37
|
+
writeFileSync(runtimeFile, "", { flag: "a" });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// best effort
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(JSON.stringify({ status: "ok", event: opts.name }));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=run-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-hook.js","sourceRoot":"","sources":["../../src/memory/run-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAGnC;IACC,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,OA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
+
claudeHooks?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function runMemoryInit(opts: MemoryInitRunOpts): Promise<void>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CLIENT_LABELS } from "../constants.js";
|
|
2
|
+
import { confirmAndApply, isInteractive } from "../commands.js";
|
|
3
|
+
import { buildClaudeHooksOperation, buildMemoryArtifactOperations, buildMemoryConfigOperation, buildMemoryMcpOperations, createOperationContext, validateClients, validateScope, } from "../mcp/mcp-operations.js";
|
|
4
|
+
import { promptMemoryInitWizard } from "../prompts.js";
|
|
5
|
+
import { commandExists } from "../system.js";
|
|
6
|
+
export async function runMemoryInit(opts) {
|
|
7
|
+
const interactive = isInteractive(opts);
|
|
8
|
+
const answers = {
|
|
9
|
+
org: opts.org ?? null,
|
|
10
|
+
baseUrl: opts.baseUrl,
|
|
11
|
+
agents: [...opts.agents],
|
|
12
|
+
scope: opts.scope ?? null,
|
|
13
|
+
dryRun: opts.dryRun,
|
|
14
|
+
};
|
|
15
|
+
if (interactive) {
|
|
16
|
+
const wizard = await promptMemoryInitWizard({
|
|
17
|
+
org: answers.org,
|
|
18
|
+
baseUrl: answers.baseUrl,
|
|
19
|
+
agents: answers.agents,
|
|
20
|
+
scope: answers.scope,
|
|
21
|
+
});
|
|
22
|
+
if (wizard.org !== undefined)
|
|
23
|
+
answers.org = wizard.org;
|
|
24
|
+
if (wizard.scope)
|
|
25
|
+
answers.scope = wizard.scope;
|
|
26
|
+
if (wizard.agents)
|
|
27
|
+
answers.agents = wizard.agents;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (answers.agents.length === 0) {
|
|
31
|
+
throw new Error("Missing --agents for non-interactive memory init");
|
|
32
|
+
}
|
|
33
|
+
if (!answers.scope)
|
|
34
|
+
answers.scope = "repo";
|
|
35
|
+
}
|
|
36
|
+
const scope = answers.scope;
|
|
37
|
+
const agents = answers.agents;
|
|
38
|
+
if (!scope)
|
|
39
|
+
throw new Error("Missing --scope");
|
|
40
|
+
validateScope(scope);
|
|
41
|
+
validateClients(agents);
|
|
42
|
+
const context = createOperationContext({ commandExists });
|
|
43
|
+
const configOp = buildMemoryConfigOperation({
|
|
44
|
+
org: answers.org,
|
|
45
|
+
baseUrl: answers.baseUrl,
|
|
46
|
+
context,
|
|
47
|
+
});
|
|
48
|
+
const mcpOps = buildMemoryMcpOperations({
|
|
49
|
+
clients: agents,
|
|
50
|
+
baseUrl: answers.baseUrl,
|
|
51
|
+
org: answers.org,
|
|
52
|
+
scope,
|
|
53
|
+
context,
|
|
54
|
+
});
|
|
55
|
+
const memoryOps = buildMemoryArtifactOperations({ context });
|
|
56
|
+
const claudeHookOps = opts.claudeHooks && agents.includes("claude")
|
|
57
|
+
? [buildClaudeHooksOperation({ context })]
|
|
58
|
+
: [];
|
|
59
|
+
const operations = [configOp, ...mcpOps, ...memoryOps, ...claudeHookOps];
|
|
60
|
+
const orgLine = answers.org
|
|
61
|
+
? `Organization ${answers.org}`
|
|
62
|
+
: "Organization none (local-only memory)";
|
|
63
|
+
const modeLine = answers.org
|
|
64
|
+
? "Hosted summaries available after sign-in"
|
|
65
|
+
: "Local-only — no ctxpipe account required";
|
|
66
|
+
await confirmAndApply({
|
|
67
|
+
operations,
|
|
68
|
+
json: opts.json,
|
|
69
|
+
nonInteractive: opts.nonInteractive,
|
|
70
|
+
interactive,
|
|
71
|
+
dryRun: answers.dryRun,
|
|
72
|
+
introShown: interactive,
|
|
73
|
+
setupSummary: [
|
|
74
|
+
orgLine,
|
|
75
|
+
scopeLabel(scope),
|
|
76
|
+
`Agents ${agents.map((a) => CLIENT_LABELS[a]).join(", ")}`,
|
|
77
|
+
modeLine,
|
|
78
|
+
],
|
|
79
|
+
successMessage: "Local memory is configured",
|
|
80
|
+
outroMessage: "Memory setup complete. Restart your agent MCP servers to pick up ctxpipe-memory.",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function scopeLabel(scope) {
|
|
84
|
+
if (scope === "repo")
|
|
85
|
+
return "Scope This repo";
|
|
86
|
+
if (scope === "user")
|
|
87
|
+
return "Scope Globally";
|
|
88
|
+
if (scope === "both")
|
|
89
|
+
return "Scope This repo and globally";
|
|
90
|
+
return `Scope ${scope}`;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=run-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-init.js","sourceRoot":"","sources":["../../src/memory/run-init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EACf,aAAa,GACd,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAa5C,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAuB;IACzD,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,OAAO,GAMT;QACF,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAa;QACpC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAA;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC;YAC1C,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC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@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { resolveCtxpipeBaseUrl } from "../auth.js";
|
|
2
|
+
import { startMcpServer } from "./mcp-server.js";
|
|
3
|
+
export async function runMemoryMcp(opts) {
|
|
4
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
5
|
+
await startMcpServer({ baseUrl });
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=run-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-mcp.js","sourceRoot":"","sources":["../../src/memory/run-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAyB;IAC1D,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IAClE,MAAM,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function runMemoryStatus(opts: {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
json: boolean;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function runMemoryDoctor(opts: {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
json: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function runMemoryStop(opts: {
|
|
10
|
+
json: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { log, note } from "@clack/prompts";
|
|
3
|
+
import { readStoredAuth, resolveCtxpipeBaseUrl } from "../auth.js";
|
|
4
|
+
import { detectRepoFingerprint, runtimeStateFile } from "./paths.js";
|
|
5
|
+
import { resolveMemoryRoot } from "./paths.js";
|
|
6
|
+
import { computeManifestStats } from "./hydration.js";
|
|
7
|
+
export async function runMemoryStatus(opts) {
|
|
8
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
9
|
+
const state = await collectStatus(baseUrl);
|
|
10
|
+
if (opts.json) {
|
|
11
|
+
process.stdout.write(`${JSON.stringify(state, null, 2)}\n`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
note(formatStatusText(state), "ctx| memory status");
|
|
15
|
+
}
|
|
16
|
+
export async function runMemoryDoctor(opts) {
|
|
17
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
18
|
+
const status = await collectStatus(baseUrl);
|
|
19
|
+
const checks = await collectDoctorChecks(status);
|
|
20
|
+
if (opts.json) {
|
|
21
|
+
process.stdout.write(`${JSON.stringify({ ...status, checks }, null, 2)}\n`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
note([formatStatusText(status), "", "Checks:", ...checks.map(formatCheck)].join("\n"), "ctx| memory doctor");
|
|
25
|
+
}
|
|
26
|
+
export async function runMemoryStop(opts) {
|
|
27
|
+
const fingerprint = detectRepoFingerprint(process.cwd());
|
|
28
|
+
const file = runtimeStateFile(fingerprint);
|
|
29
|
+
if (!existsSync(file)) {
|
|
30
|
+
if (opts.json) {
|
|
31
|
+
process.stdout.write(`${JSON.stringify({ status: "noop" }, null, 2)}\n`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
log.info("No managed AgentMemory runtime is recorded for this repo.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const runtime = JSON.parse(readFileSync(file, "utf8"));
|
|
38
|
+
try {
|
|
39
|
+
process.kill(runtime.pid, "SIGTERM");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// already gone
|
|
43
|
+
}
|
|
44
|
+
if (opts.json) {
|
|
45
|
+
process.stdout.write(`${JSON.stringify({ status: "stopped", pid: runtime.pid }, null, 2)}\n`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
log.success(`Stopped AgentMemory runtime (pid ${runtime.pid}).`);
|
|
49
|
+
}
|
|
50
|
+
async function collectStatus(baseUrl) {
|
|
51
|
+
const cwd = process.cwd();
|
|
52
|
+
const fingerprint = detectRepoFingerprint(cwd);
|
|
53
|
+
const runtimeFile = runtimeStateFile(fingerprint);
|
|
54
|
+
let runtime = null;
|
|
55
|
+
if (existsSync(runtimeFile)) {
|
|
56
|
+
try {
|
|
57
|
+
runtime = JSON.parse(readFileSync(runtimeFile, "utf8"));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
runtime = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const memoryRoot = resolveMemoryRoot(cwd);
|
|
64
|
+
const auth = await readStoredAuth(baseUrl);
|
|
65
|
+
const signedIn = Boolean(auth?.accessToken);
|
|
66
|
+
const manifest = computeManifestStats(fingerprint);
|
|
67
|
+
return {
|
|
68
|
+
baseUrl,
|
|
69
|
+
cwd,
|
|
70
|
+
repoFingerprint: fingerprint,
|
|
71
|
+
memoryRoot,
|
|
72
|
+
memoryRootExists: existsSync(memoryRoot),
|
|
73
|
+
runtime,
|
|
74
|
+
signedIn,
|
|
75
|
+
hostedModel: signedIn ? "available" : "signed-out",
|
|
76
|
+
manifest,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function collectDoctorChecks(status) {
|
|
80
|
+
const checks = [];
|
|
81
|
+
checks.push({
|
|
82
|
+
name: "memory-root",
|
|
83
|
+
status: status.memoryRootExists ? "ok" : "warn",
|
|
84
|
+
detail: status.memoryRootExists
|
|
85
|
+
? `${status.memoryRoot} present`
|
|
86
|
+
: `${status.memoryRoot} missing — run \`npx ctxpipe memory init\``,
|
|
87
|
+
});
|
|
88
|
+
checks.push({
|
|
89
|
+
name: "auth",
|
|
90
|
+
status: status.signedIn ? "ok" : "warn",
|
|
91
|
+
detail: status.signedIn
|
|
92
|
+
? "ctx| setup auth available; hosted model proxy enabled"
|
|
93
|
+
: "no ctx| setup auth — local memory still works in no-LLM mode (`npx ctxpipe auth login`)",
|
|
94
|
+
});
|
|
95
|
+
checks.push({
|
|
96
|
+
name: "runtime",
|
|
97
|
+
status: status.runtime ? "ok" : "warn",
|
|
98
|
+
detail: status.runtime
|
|
99
|
+
? `AgentMemory ${status.runtime.agentmemoryVersion} pid ${status.runtime.pid} at ${status.runtime.url}`
|
|
100
|
+
: "no managed AgentMemory runtime is currently recorded (lazy-spawn happens on first MCP call)",
|
|
101
|
+
});
|
|
102
|
+
checks.push({
|
|
103
|
+
name: "hydration-manifest",
|
|
104
|
+
status: status.manifest.exists ? "ok" : "warn",
|
|
105
|
+
detail: status.manifest.exists
|
|
106
|
+
? `${status.manifest.fileCount} tracked files, ${status.manifest.memoryCount} memories`
|
|
107
|
+
: "no manifest yet (will be created on first hydration)",
|
|
108
|
+
});
|
|
109
|
+
return checks;
|
|
110
|
+
}
|
|
111
|
+
function formatStatusText(state) {
|
|
112
|
+
return [
|
|
113
|
+
`mode: ${state.signedIn ? "signed-in" : "local-only"}`,
|
|
114
|
+
`memory root: ${state.memoryRoot} ${state.memoryRootExists ? "" : "(missing)"}`.trim(),
|
|
115
|
+
`runtime: ${state.runtime ? `${state.runtime.url} (pid ${state.runtime.pid})` : "not started"}`,
|
|
116
|
+
`hosted model: ${state.hostedModel}`,
|
|
117
|
+
`manifest: ${state.manifest.exists ? `${state.manifest.fileCount} files, ${state.manifest.memoryCount} memories` : "not yet built"}`,
|
|
118
|
+
].join("\n");
|
|
119
|
+
}
|
|
120
|
+
function formatCheck(check) {
|
|
121
|
+
const badge = check.status === "ok" ? "✓" : check.status === "warn" ? "!" : "✗";
|
|
122
|
+
return ` ${badge} ${check.name}: ${check.detail}`;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=run-meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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
+
rest: number;
|
|
5
|
+
streams: number;
|
|
6
|
+
viewer: number;
|
|
7
|
+
engineWs: number;
|
|
8
|
+
};
|
|
9
|
+
export type RuntimeState = {
|
|
10
|
+
provider: "agentmemory";
|
|
11
|
+
agentmemoryVersion: string;
|
|
12
|
+
url: string;
|
|
13
|
+
viewerUrl: string;
|
|
14
|
+
pid: number;
|
|
15
|
+
startedAt: string;
|
|
16
|
+
mode: "local-only" | "signed-in";
|
|
17
|
+
hostedModel: "available" | "signed-out";
|
|
18
|
+
ports: AgentMemoryPorts;
|
|
19
|
+
/** AgentMemory REST bearer; env + in-process only (omitted from runtime.json). */
|
|
20
|
+
secret?: string;
|
|
21
|
+
};
|
|
22
|
+
export type SupervisorOptions = {
|
|
23
|
+
fingerprint: RepoFingerprint;
|
|
24
|
+
/** Override for tests. Defaults to `npx -y @agentmemory/agentmemory@<pin>`. */
|
|
25
|
+
command?: {
|
|
26
|
+
command: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
};
|
|
29
|
+
/** Optional callback that returns the OAuth bearer to forward as OPENAI_API_KEY. */
|
|
30
|
+
getAccessToken?: () => Promise<string | null>;
|
|
31
|
+
/** Override for tests so we can keep tests fully offline. */
|
|
32
|
+
liveZUrl?: (ports: AgentMemoryPorts) => string;
|
|
33
|
+
/** OpenAI base URL to forward chat/embeddings through; usually the backend proxy. */
|
|
34
|
+
openaiBaseUrl?: string;
|
|
35
|
+
chatModel?: string;
|
|
36
|
+
embeddingModel?: string;
|
|
37
|
+
/** Max ms to wait for /agentmemory/livez. Default 30_000. */
|
|
38
|
+
readinessTimeoutMs?: number;
|
|
39
|
+
};
|
|
40
|
+
export type Supervisor = {
|
|
41
|
+
/** Returns existing state if alive, otherwise spawns the runtime and waits for livez. */
|
|
42
|
+
ensureRunning(): Promise<RuntimeState>;
|
|
43
|
+
/** Stop the runtime if we started it; returns true if we killed something. */
|
|
44
|
+
stop(): Promise<boolean>;
|
|
45
|
+
/** Return the current state or null if nothing is running. */
|
|
46
|
+
current(): RuntimeState | null;
|
|
47
|
+
};
|
|
48
|
+
export declare function createSupervisor(opts: SupervisorOptions): Supervisor;
|
|
49
|
+
export declare function allocatePorts(): Promise<AgentMemoryPorts>;
|