@mono-agent/agent-app 0.3.0 → 0.4.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 (68) hide show
  1. package/README.md +9 -5
  2. package/dist/adapter-send-tools-main.d.ts +3 -0
  3. package/dist/adapter-send-tools-main.d.ts.map +1 -0
  4. package/dist/adapter-send-tools-main.js +20 -0
  5. package/dist/adapter-send-tools-main.js.map +1 -0
  6. package/dist/adapter-send-tools.d.ts +59 -0
  7. package/dist/adapter-send-tools.d.ts.map +1 -0
  8. package/dist/adapter-send-tools.js +254 -0
  9. package/dist/adapter-send-tools.js.map +1 -0
  10. package/dist/app-config.d.ts +40 -17
  11. package/dist/app-config.d.ts.map +1 -1
  12. package/dist/app-config.js +188 -68
  13. package/dist/app-config.js.map +1 -1
  14. package/dist/app.d.ts +41 -20
  15. package/dist/app.d.ts.map +1 -1
  16. package/dist/app.js +250 -91
  17. package/dist/app.js.map +1 -1
  18. package/dist/backfill.d.ts +79 -0
  19. package/dist/backfill.d.ts.map +1 -0
  20. package/dist/backfill.js +246 -0
  21. package/dist/backfill.js.map +1 -0
  22. package/dist/background.d.ts +0 -4
  23. package/dist/background.d.ts.map +1 -1
  24. package/dist/background.js +78 -50
  25. package/dist/background.js.map +1 -1
  26. package/dist/channels.d.ts +7 -0
  27. package/dist/channels.d.ts.map +1 -1
  28. package/dist/channels.js +26 -3
  29. package/dist/channels.js.map +1 -1
  30. package/dist/cli.d.ts +52 -3
  31. package/dist/cli.d.ts.map +1 -1
  32. package/dist/cli.js +315 -111
  33. package/dist/cli.js.map +1 -1
  34. package/dist/doctor.d.ts +8 -0
  35. package/dist/doctor.d.ts.map +1 -1
  36. package/dist/doctor.js +148 -48
  37. package/dist/doctor.js.map +1 -1
  38. package/dist/index.d.ts +6 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +3 -2
  41. package/dist/index.js.map +1 -1
  42. package/dist/launchd.d.ts +0 -2
  43. package/dist/launchd.d.ts.map +1 -1
  44. package/dist/launchd.js +0 -2
  45. package/dist/launchd.js.map +1 -1
  46. package/dist/memory-recall-main.d.ts +3 -0
  47. package/dist/memory-recall-main.d.ts.map +1 -0
  48. package/dist/memory-recall-main.js +30 -0
  49. package/dist/memory-recall-main.js.map +1 -0
  50. package/dist/memory-recall.d.ts +111 -0
  51. package/dist/memory-recall.d.ts.map +1 -0
  52. package/dist/memory-recall.js +275 -0
  53. package/dist/memory-recall.js.map +1 -0
  54. package/dist/sessions.d.ts +21 -0
  55. package/dist/sessions.d.ts.map +1 -0
  56. package/dist/sessions.js +45 -0
  57. package/dist/sessions.js.map +1 -0
  58. package/dist/ui.d.ts +54 -0
  59. package/dist/ui.d.ts.map +1 -0
  60. package/dist/ui.js +153 -0
  61. package/dist/ui.js.map +1 -0
  62. package/package.json +22 -17
  63. package/skills/mono-agent-composer/SKILL.md +6 -5
  64. package/skills/mono-agent-composer/references/config-blueprint.md +37 -18
  65. package/skills/mono-agent-composer/references/discovery-questions.md +38 -23
  66. package/skills/mono-agent-composer/references/feature-coverage.md +12 -9
  67. package/skills/mono-agent-composer/references/package-map.md +5 -5
  68. package/skills/mono-agent-composer/references/validation.md +5 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-recall-main.js","sourceRoot":"","sources":["../src/memory-recall-main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAE9G,KAAK,UAAU,IAAI;IACjB,MAAM,QAAQ,GAAG,2BAA2B,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,GAAS,EAAE;QAC1B,KAAK,KAAK;aACP,KAAK,EAAE;aACP,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,2FAA2F;YAC3F,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvI,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChC,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrH,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,111 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { BujoMemoryStore } from "@mono-agent/memory-bujo";
3
+ import type { MonoAgentConfig } from "@mono-agent/config";
4
+ /**
5
+ * Read-only memory recall, wired from the SINGLE `config.memory` block.
6
+ *
7
+ * When `config.memory.recallTool.enabled` is true, the app exposes a `memory_recall` MCP tool
8
+ * (server name {@link MEMORY_RECALL_MCP_SERVER_NAME}) to the agent. Recall needs only embeddings +
9
+ * FTS — no chat LLM — so the recall server is built with embeddings alone. When embeddings are
10
+ * absent (lite tier, or an explicit opt-in on a no-embeddings store) recall still serves FTS-only
11
+ * (lexical) results. Capture stays in-app (unchanged); this module never touches it.
12
+ *
13
+ * Embeddings parity with the in-app store (`createConfiguredMemory`): the recall child applies the
14
+ * SAME resilience wrapping — a per-call timeout plus a circuit breaker — so a slow/failing backend
15
+ * cannot stall or repeatedly block recall in the child process either.
16
+ *
17
+ * Secret handling: the raw embeddings api key is NOT copied into the recall child's env. When the
18
+ * key was sourced from a named environment variable (`apiKeyEnv`) we forward only the NAME and the
19
+ * child re-reads the value from its inherited process env at runtime. An inline literal key (no
20
+ * `apiKeyEnv`) still has to transit the child env as a value — that residual is documented on
21
+ * {@link memoryRecallMcpEnv}.
22
+ *
23
+ * A stdio MCP server is injected purely as an `mcpServers` entry via the per-request runtime
24
+ * options. MCP tools are not gated by `tools.allowedTools`, so no allowlist entry is required.
25
+ */
26
+ export declare const MEMORY_RECALL_MCP_SERVER_NAME = "mono-agent-memory";
27
+ /** Circuit-breaker tuning carried into the recall child. Mirrors `config.memory.embeddings.circuitBreaker`. */
28
+ export interface MemoryRecallEmbeddingsCircuitBreaker {
29
+ readonly failureThreshold?: number;
30
+ readonly cooldownMs?: number;
31
+ }
32
+ /** Embeddings the recall server needs. Mirrors the resolved `config.memory.embeddings` slice. */
33
+ export interface MemoryRecallEmbeddings {
34
+ readonly provider: "ollama" | "openai";
35
+ readonly model: string;
36
+ readonly endpoint?: string;
37
+ /** Resolved key value. Only used as a last resort (inline apiKey, no apiKeyEnv). */
38
+ readonly apiKey?: string;
39
+ /** Name of the env var the key was read from; forwarded instead of the raw value when present. */
40
+ readonly apiKeyEnv?: string;
41
+ readonly dim?: number;
42
+ /** Per-call embeddings timeout in ms; mirrors the host default when unset (see createRecallStore). */
43
+ readonly timeoutMs?: number;
44
+ /** Circuit-breaker overrides; unset fields fall back to the breaker defaults. */
45
+ readonly circuitBreaker?: MemoryRecallEmbeddingsCircuitBreaker;
46
+ }
47
+ export interface MemoryRecallSettings {
48
+ /** Memory root directory (config.memory.path). */
49
+ readonly root: string;
50
+ /** Embeddings for semantic recall. Omitted for an FTS-only (lite) recall store. */
51
+ readonly embeddings?: MemoryRecallEmbeddings;
52
+ }
53
+ export interface MemoryRecallRuntimeExtension {
54
+ readonly runtimeOptions: {
55
+ readonly mcpServers: Record<string, unknown>;
56
+ };
57
+ readonly cleanup: () => Promise<void>;
58
+ }
59
+ /**
60
+ * Bound embeddings calls in the recall child so a slow/cold backend cannot stall a turn for the
61
+ * provider default. Mirrors the in-app `createConfiguredMemory` host default (agent-host).
62
+ */
63
+ export declare const DEFAULT_RECALL_EMBEDDINGS_TIMEOUT_MS = 10000;
64
+ /**
65
+ * Resolve recall settings from the single in-app memory block. Returns `undefined` (recall off) only
66
+ * when memory is unconfigured or the recall tool is disabled. When the operator explicitly enables
67
+ * recall on a no-embeddings store (lite tier), settings are returned WITHOUT embeddings so the child
68
+ * serves FTS-only recall — the config layer deliberately supports this forced-on opt-in.
69
+ */
70
+ export declare function resolveMemoryRecallSettings(config: MonoAgentConfig): MemoryRecallSettings | undefined;
71
+ /**
72
+ * Re-read recall settings from the recall server's own environment (the stdio child process).
73
+ *
74
+ * Only `MONO_AGENT_MEMORY_PATH` is required. When the embeddings provider/model are both absent the
75
+ * child runs FTS-only (no embedding provider). When present, the embeddings slice — including the
76
+ * resilience knobs (timeout + circuit breaker) — is rehydrated. The api key is resolved from the
77
+ * inherited env var named by `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY_ENV` when set, falling back to a
78
+ * literal `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY` (the inline-key case).
79
+ */
80
+ export declare function memoryRecallSettingsFromEnv(env: Record<string, string | undefined>): MemoryRecallSettings;
81
+ /**
82
+ * Env passed to the recall stdio child. Reuses the MONO_AGENT_MEMORY_* names the old memory-mcp used.
83
+ *
84
+ * With no embeddings the child runs FTS-only and only the memory path is emitted. The embeddings
85
+ * resilience knobs (timeout + circuit breaker) are forwarded so the child wraps its provider exactly
86
+ * like the in-app store. SECRET HANDLING (F13): when `apiKeyEnv` is present the env-var NAME is
87
+ * forwarded (NOT the value) and the child re-reads it from its inherited process env; the raw
88
+ * `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY` value is emitted ONLY for the inline-key residual (an inline
89
+ * `apiKey` with no `apiKeyEnv`), where there is no name to forward.
90
+ */
91
+ export declare function memoryRecallMcpEnv(settings: MemoryRecallSettings): Record<string, string>;
92
+ export declare function memoryRecallMcpServerSpec(settings: MemoryRecallSettings, cwd: string): Record<string, unknown>;
93
+ /**
94
+ * Build the per-request runtime extension that injects the recall server. The cleanup is a no-op:
95
+ * the stdio child owns its store lifecycle and drains on signal (see memory-recall-main).
96
+ */
97
+ export declare function createMemoryRecallRuntimeExtension(settings: MemoryRecallSettings, cwd: string): () => Promise<MemoryRecallRuntimeExtension>;
98
+ /**
99
+ * Build a RECALL-ONLY store: embeddings + FTS, no chat LLM (recall needs none, so capture/reflect
100
+ * stay disabled here). With no embeddings (lite tier / explicit FTS-only opt-in) the store is built
101
+ * without an embedding provider and serves FTS-only recall.
102
+ *
103
+ * The embedding provider is wrapped with the SAME resilience as the in-app store
104
+ * (`createConfiguredMemory`): a bounded per-call timeout (default
105
+ * {@link DEFAULT_RECALL_EMBEDDINGS_TIMEOUT_MS}) keeps a slow backend from stalling recall, and a
106
+ * circuit breaker fast-fails after repeated failures so a sustained outage stops blocking it.
107
+ */
108
+ export declare function createRecallStore(settings: MemoryRecallSettings): BujoMemoryStore;
109
+ /** Register the single read-only `memory_recall` tool against a store. */
110
+ export declare function createMemoryRecallServer(store: BujoMemoryStore): McpServer;
111
+ //# sourceMappingURL=memory-recall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-recall.d.ts","sourceRoot":"","sources":["../src/memory-recall.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CA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AAED;;;GAGG;AACH,eAAO,MAAM,oCAAoC,QAAS,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,eAAe,GAAG,oBAAoB,GAAG,SAAS,CA6BrG;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,oBAAoB,CAuDzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuBzF;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQ9G;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,EAAE,MAAM,GACV,MAAM,OAAO,CAAC,4BAA4B,CAAC,CAS7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,eAAe,CAwBjF;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,CA0B1E"}
@@ -0,0 +1,275 @@
1
+ import process from "node:process";
2
+ import { fileURLToPath } from "node:url";
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { createBujoMemoryStore } from "@mono-agent/memory-bujo";
5
+ import { createCircuitBreakerEmbeddingProvider, createEmbeddingProvider } from "@mono-agent/memory-search";
6
+ import * as z from "zod/v4";
7
+ /**
8
+ * Read-only memory recall, wired from the SINGLE `config.memory` block.
9
+ *
10
+ * When `config.memory.recallTool.enabled` is true, the app exposes a `memory_recall` MCP tool
11
+ * (server name {@link MEMORY_RECALL_MCP_SERVER_NAME}) to the agent. Recall needs only embeddings +
12
+ * FTS — no chat LLM — so the recall server is built with embeddings alone. When embeddings are
13
+ * absent (lite tier, or an explicit opt-in on a no-embeddings store) recall still serves FTS-only
14
+ * (lexical) results. Capture stays in-app (unchanged); this module never touches it.
15
+ *
16
+ * Embeddings parity with the in-app store (`createConfiguredMemory`): the recall child applies the
17
+ * SAME resilience wrapping — a per-call timeout plus a circuit breaker — so a slow/failing backend
18
+ * cannot stall or repeatedly block recall in the child process either.
19
+ *
20
+ * Secret handling: the raw embeddings api key is NOT copied into the recall child's env. When the
21
+ * key was sourced from a named environment variable (`apiKeyEnv`) we forward only the NAME and the
22
+ * child re-reads the value from its inherited process env at runtime. An inline literal key (no
23
+ * `apiKeyEnv`) still has to transit the child env as a value — that residual is documented on
24
+ * {@link memoryRecallMcpEnv}.
25
+ *
26
+ * A stdio MCP server is injected purely as an `mcpServers` entry via the per-request runtime
27
+ * options. MCP tools are not gated by `tools.allowedTools`, so no allowlist entry is required.
28
+ */
29
+ export const MEMORY_RECALL_MCP_SERVER_NAME = "mono-agent-memory";
30
+ /**
31
+ * Bound embeddings calls in the recall child so a slow/cold backend cannot stall a turn for the
32
+ * provider default. Mirrors the in-app `createConfiguredMemory` host default (agent-host).
33
+ */
34
+ export const DEFAULT_RECALL_EMBEDDINGS_TIMEOUT_MS = 10_000;
35
+ /**
36
+ * Resolve recall settings from the single in-app memory block. Returns `undefined` (recall off) only
37
+ * when memory is unconfigured or the recall tool is disabled. When the operator explicitly enables
38
+ * recall on a no-embeddings store (lite tier), settings are returned WITHOUT embeddings so the child
39
+ * serves FTS-only recall — the config layer deliberately supports this forced-on opt-in.
40
+ */
41
+ export function resolveMemoryRecallSettings(config) {
42
+ const memory = config.memory;
43
+ if (memory === undefined) {
44
+ return undefined;
45
+ }
46
+ if (memory.recallTool?.enabled !== true) {
47
+ return undefined;
48
+ }
49
+ const embeddings = memory.embeddings;
50
+ if (embeddings === undefined) {
51
+ // Explicit opt-in without embeddings → FTS-only recall (no embedding provider built).
52
+ return { root: memory.path };
53
+ }
54
+ return {
55
+ root: memory.path,
56
+ embeddings: {
57
+ provider: embeddings.provider,
58
+ model: embeddings.model,
59
+ ...(embeddings.endpoint === undefined ? {} : { endpoint: embeddings.endpoint }),
60
+ // Prefer forwarding the env-var NAME over the resolved secret value (F13): when apiKeyEnv is
61
+ // present the child re-reads the key from its inherited env, so the raw key never lands in the
62
+ // child's spec env. The literal apiKey is kept only as a fallback for the inline-key case.
63
+ ...(embeddings.apiKeyEnv === undefined ? {} : { apiKeyEnv: embeddings.apiKeyEnv }),
64
+ ...(embeddings.apiKey === undefined ? {} : { apiKey: embeddings.apiKey }),
65
+ ...(embeddings.dim === undefined ? {} : { dim: embeddings.dim }),
66
+ ...(embeddings.timeoutMs === undefined ? {} : { timeoutMs: embeddings.timeoutMs }),
67
+ ...(embeddings.circuitBreaker === undefined ? {} : { circuitBreaker: embeddings.circuitBreaker }),
68
+ },
69
+ };
70
+ }
71
+ /**
72
+ * Re-read recall settings from the recall server's own environment (the stdio child process).
73
+ *
74
+ * Only `MONO_AGENT_MEMORY_PATH` is required. When the embeddings provider/model are both absent the
75
+ * child runs FTS-only (no embedding provider). When present, the embeddings slice — including the
76
+ * resilience knobs (timeout + circuit breaker) — is rehydrated. The api key is resolved from the
77
+ * inherited env var named by `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY_ENV` when set, falling back to a
78
+ * literal `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY` (the inline-key case).
79
+ */
80
+ export function memoryRecallSettingsFromEnv(env) {
81
+ const root = optionalString(env.MONO_AGENT_MEMORY_PATH);
82
+ if (root === undefined) {
83
+ throw new Error("memory-recall: missing required environment (MONO_AGENT_MEMORY_PATH).");
84
+ }
85
+ const provider = optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_PROVIDER);
86
+ const model = optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_MODEL);
87
+ if (provider === undefined && model === undefined) {
88
+ // No embeddings configured → FTS-only recall store.
89
+ return { root };
90
+ }
91
+ if (provider === undefined || model === undefined) {
92
+ throw new Error("memory-recall: incomplete embeddings environment (MONO_AGENT_MEMORY_EMBEDDINGS_PROVIDER and MONO_AGENT_MEMORY_EMBEDDINGS_MODEL must be set together).");
93
+ }
94
+ if (provider !== "ollama" && provider !== "openai") {
95
+ throw new Error(`memory-recall: unsupported MONO_AGENT_MEMORY_EMBEDDINGS_PROVIDER "${provider}" (expected "ollama" or "openai").`);
96
+ }
97
+ const endpoint = optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_ENDPOINT);
98
+ const apiKeyEnv = optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY_ENV);
99
+ // Resolve the key from the named inherited var first (F13); fall back to a literal value.
100
+ const apiKey = (apiKeyEnv === undefined ? undefined : optionalString(env[apiKeyEnv])) ??
101
+ optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY);
102
+ const dim = parseDim(optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_DIM));
103
+ const timeoutMs = parsePositiveInt(optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_TIMEOUT_MS), "MONO_AGENT_MEMORY_EMBEDDINGS_TIMEOUT_MS");
104
+ const failureThreshold = parsePositiveInt(optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_FAILURE_THRESHOLD), "MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_FAILURE_THRESHOLD");
105
+ const cooldownMs = parsePositiveInt(optionalString(env.MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_COOLDOWN_MS), "MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_COOLDOWN_MS");
106
+ const circuitBreaker = failureThreshold === undefined && cooldownMs === undefined
107
+ ? undefined
108
+ : {
109
+ ...(failureThreshold === undefined ? {} : { failureThreshold }),
110
+ ...(cooldownMs === undefined ? {} : { cooldownMs }),
111
+ };
112
+ return {
113
+ root,
114
+ embeddings: {
115
+ provider,
116
+ model,
117
+ ...(endpoint === undefined ? {} : { endpoint }),
118
+ ...(apiKeyEnv === undefined ? {} : { apiKeyEnv }),
119
+ ...(apiKey === undefined ? {} : { apiKey }),
120
+ ...(dim === undefined ? {} : { dim }),
121
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
122
+ ...(circuitBreaker === undefined ? {} : { circuitBreaker }),
123
+ },
124
+ };
125
+ }
126
+ /**
127
+ * Env passed to the recall stdio child. Reuses the MONO_AGENT_MEMORY_* names the old memory-mcp used.
128
+ *
129
+ * With no embeddings the child runs FTS-only and only the memory path is emitted. The embeddings
130
+ * resilience knobs (timeout + circuit breaker) are forwarded so the child wraps its provider exactly
131
+ * like the in-app store. SECRET HANDLING (F13): when `apiKeyEnv` is present the env-var NAME is
132
+ * forwarded (NOT the value) and the child re-reads it from its inherited process env; the raw
133
+ * `MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY` value is emitted ONLY for the inline-key residual (an inline
134
+ * `apiKey` with no `apiKeyEnv`), where there is no name to forward.
135
+ */
136
+ export function memoryRecallMcpEnv(settings) {
137
+ const { embeddings } = settings;
138
+ if (embeddings === undefined) {
139
+ return { MONO_AGENT_MEMORY_PATH: settings.root };
140
+ }
141
+ // Forward the secret only as a last resort: prefer the env-var name passthrough.
142
+ const forwardLiteralApiKey = embeddings.apiKeyEnv === undefined && embeddings.apiKey !== undefined;
143
+ return {
144
+ MONO_AGENT_MEMORY_PATH: settings.root,
145
+ MONO_AGENT_MEMORY_EMBEDDINGS_PROVIDER: embeddings.provider,
146
+ MONO_AGENT_MEMORY_EMBEDDINGS_MODEL: embeddings.model,
147
+ ...(embeddings.endpoint === undefined ? {} : { MONO_AGENT_MEMORY_EMBEDDINGS_ENDPOINT: embeddings.endpoint }),
148
+ ...(embeddings.apiKeyEnv === undefined ? {} : { MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY_ENV: embeddings.apiKeyEnv }),
149
+ ...(forwardLiteralApiKey ? { MONO_AGENT_MEMORY_EMBEDDINGS_API_KEY: embeddings.apiKey } : {}),
150
+ ...(embeddings.dim === undefined ? {} : { MONO_AGENT_MEMORY_EMBEDDINGS_DIM: String(embeddings.dim) }),
151
+ ...(embeddings.timeoutMs === undefined ? {} : { MONO_AGENT_MEMORY_EMBEDDINGS_TIMEOUT_MS: String(embeddings.timeoutMs) }),
152
+ ...(embeddings.circuitBreaker?.failureThreshold === undefined
153
+ ? {}
154
+ : { MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_FAILURE_THRESHOLD: String(embeddings.circuitBreaker.failureThreshold) }),
155
+ ...(embeddings.circuitBreaker?.cooldownMs === undefined
156
+ ? {}
157
+ : { MONO_AGENT_MEMORY_EMBEDDINGS_CIRCUIT_BREAKER_COOLDOWN_MS: String(embeddings.circuitBreaker.cooldownMs) }),
158
+ };
159
+ }
160
+ export function memoryRecallMcpServerSpec(settings, cwd) {
161
+ return {
162
+ type: "stdio",
163
+ command: process.execPath,
164
+ args: [fileURLToPath(new URL("./memory-recall-main.js", import.meta.url))],
165
+ cwd,
166
+ env: memoryRecallMcpEnv(settings),
167
+ };
168
+ }
169
+ /**
170
+ * Build the per-request runtime extension that injects the recall server. The cleanup is a no-op:
171
+ * the stdio child owns its store lifecycle and drains on signal (see memory-recall-main).
172
+ */
173
+ export function createMemoryRecallRuntimeExtension(settings, cwd) {
174
+ return async () => ({
175
+ runtimeOptions: {
176
+ mcpServers: {
177
+ [MEMORY_RECALL_MCP_SERVER_NAME]: memoryRecallMcpServerSpec(settings, cwd),
178
+ },
179
+ },
180
+ cleanup: async () => { },
181
+ });
182
+ }
183
+ /**
184
+ * Build a RECALL-ONLY store: embeddings + FTS, no chat LLM (recall needs none, so capture/reflect
185
+ * stay disabled here). With no embeddings (lite tier / explicit FTS-only opt-in) the store is built
186
+ * without an embedding provider and serves FTS-only recall.
187
+ *
188
+ * The embedding provider is wrapped with the SAME resilience as the in-app store
189
+ * (`createConfiguredMemory`): a bounded per-call timeout (default
190
+ * {@link DEFAULT_RECALL_EMBEDDINGS_TIMEOUT_MS}) keeps a slow backend from stalling recall, and a
191
+ * circuit breaker fast-fails after repeated failures so a sustained outage stops blocking it.
192
+ */
193
+ export function createRecallStore(settings) {
194
+ const { embeddings } = settings;
195
+ if (embeddings === undefined) {
196
+ // FTS-only recall: no embedding provider, no dim (mirrors the lite-tier store shape).
197
+ return createBujoMemoryStore({ root: settings.root });
198
+ }
199
+ const providerConfig = {
200
+ provider: embeddings.provider,
201
+ model: embeddings.model,
202
+ ...(embeddings.endpoint === undefined ? {} : { endpoint: embeddings.endpoint }),
203
+ ...(embeddings.apiKey === undefined ? {} : { apiKey: embeddings.apiKey }),
204
+ timeoutMs: embeddings.timeoutMs ?? DEFAULT_RECALL_EMBEDDINGS_TIMEOUT_MS,
205
+ };
206
+ const breakerOptions = {
207
+ ...(embeddings.circuitBreaker?.failureThreshold === undefined
208
+ ? {}
209
+ : { failureThreshold: embeddings.circuitBreaker.failureThreshold }),
210
+ ...(embeddings.circuitBreaker?.cooldownMs === undefined ? {} : { cooldownMs: embeddings.circuitBreaker.cooldownMs }),
211
+ };
212
+ return createBujoMemoryStore({
213
+ root: settings.root,
214
+ embeddings: createCircuitBreakerEmbeddingProvider(createEmbeddingProvider(providerConfig), breakerOptions),
215
+ dim: embeddings.dim ?? 768,
216
+ });
217
+ }
218
+ /** Register the single read-only `memory_recall` tool against a store. */
219
+ export function createMemoryRecallServer(store) {
220
+ const server = new McpServer({ name: "agent-memory", version: "0.3.0" });
221
+ server.registerTool("memory_recall", {
222
+ title: "Recall from memory",
223
+ description: "Read-only hybrid (keyword + semantic) search over long-term memory. Use to recall facts, decisions, and context.",
224
+ inputSchema: {
225
+ query: z.string().min(1).describe("Natural-language description of what to recall."),
226
+ limit: z.number().int().min(1).max(50).optional().describe("Max results (default 8)."),
227
+ },
228
+ }, async (args) => {
229
+ const topK = clampLimit(args.limit, 8);
230
+ const hits = await store.recall(args.query, { topK });
231
+ if (hits.length === 0) {
232
+ return { content: [{ type: "text", text: `No memories matched "${args.query}".` }], structuredContent: { hits: [] } };
233
+ }
234
+ const text = hits.map((hit) => `${hit.score.toFixed(3)} ${hit.record.text}`).join("\n");
235
+ return {
236
+ content: [{ type: "text", text }],
237
+ structuredContent: { hits: hits.map((hit) => ({ id: hit.record.id, score: hit.score, text: hit.record.text })) },
238
+ };
239
+ });
240
+ return server;
241
+ }
242
+ function clampLimit(limit, fallback) {
243
+ if (limit === undefined || !Number.isFinite(limit)) {
244
+ return fallback;
245
+ }
246
+ return Math.min(50, Math.max(1, Math.trunc(limit)));
247
+ }
248
+ function optionalString(value) {
249
+ if (value === undefined) {
250
+ return undefined;
251
+ }
252
+ const trimmed = value.trim();
253
+ return trimmed.length === 0 ? undefined : trimmed;
254
+ }
255
+ function parseDim(raw) {
256
+ if (raw === undefined) {
257
+ return undefined;
258
+ }
259
+ const parsed = Number(raw);
260
+ if (!Number.isInteger(parsed) || parsed <= 0) {
261
+ throw new Error(`memory-recall: invalid MONO_AGENT_MEMORY_EMBEDDINGS_DIM "${raw}" (expected a positive integer).`);
262
+ }
263
+ return parsed;
264
+ }
265
+ function parsePositiveInt(raw, name) {
266
+ if (raw === undefined) {
267
+ return undefined;
268
+ }
269
+ const parsed = Number(raw);
270
+ if (!Number.isInteger(parsed) || parsed <= 0) {
271
+ throw new Error(`memory-recall: invalid ${name} "${raw}" (expected a positive integer).`);
272
+ }
273
+ return parsed;
274
+ }
275
+ //# sourceMappingURL=memory-recall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-recall.js","sourceRoot":"","sources":["../src/memory-recall.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,qCAAqC,EAA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KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC;AAED,SAAS,QAAQ,CAAC,GAAuB;IACvC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,4DAA4D,GAAG,kCAAkC,CAAC,CAAC;IACrH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAuB,EAAE,IAAY;IAC7D,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,KAAK,GAAG,kCAAkC,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { MonoAgentAppConfigInput } from "./app-config.js";
2
+ export interface PurgeSessionsResult {
3
+ /** The resolved sessions root, or undefined when sessions are in-memory only. */
4
+ readonly root?: string;
5
+ /** True when an on-disk sessions store existed and was removed. */
6
+ readonly removed: boolean;
7
+ /** Count of removed `*.jsonl` session files (best-effort; 0 when none/unknown). */
8
+ readonly files: number;
9
+ }
10
+ /**
11
+ * Remove the durable pi-session store so the next start begins with fresh sessions
12
+ * instead of resuming persisted transcripts. A no-op (`removed: false`) when no
13
+ * on-disk store is configured (in-memory sessions) or the directory does not exist.
14
+ *
15
+ * The runtime recreates the directory on the next session, and the agent's durable
16
+ * memory lives elsewhere (`memory.path`), so this drops only resumable conversation
17
+ * transcripts — not the knowledge base. Stop the worker before calling this so it is
18
+ * not writing sessions while they are deleted.
19
+ */
20
+ export declare function purgeSessions(input: MonoAgentAppConfigInput): Promise<PurgeSessionsResult>;
21
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAgBhG"}
@@ -0,0 +1,45 @@
1
+ import { readdir, rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { resolveAppSessionsRoot } from "./app-config.js";
4
+ /**
5
+ * Remove the durable pi-session store so the next start begins with fresh sessions
6
+ * instead of resuming persisted transcripts. A no-op (`removed: false`) when no
7
+ * on-disk store is configured (in-memory sessions) or the directory does not exist.
8
+ *
9
+ * The runtime recreates the directory on the next session, and the agent's durable
10
+ * memory lives elsewhere (`memory.path`), so this drops only resumable conversation
11
+ * transcripts — not the knowledge base. Stop the worker before calling this so it is
12
+ * not writing sessions while they are deleted.
13
+ */
14
+ export async function purgeSessions(input) {
15
+ const root = await resolveAppSessionsRoot(input);
16
+ if (root === undefined) {
17
+ return { removed: false, files: 0 };
18
+ }
19
+ let files = 0;
20
+ try {
21
+ files = await countSessionFiles(root);
22
+ }
23
+ catch {
24
+ // The store may not exist yet; treat it as nothing to remove.
25
+ return { root, removed: false, files: 0 };
26
+ }
27
+ await rm(root, { recursive: true, force: true });
28
+ return { root, removed: true, files };
29
+ }
30
+ /** Recursively count `*.jsonl` session files under a sessions root. */
31
+ async function countSessionFiles(dir) {
32
+ const entries = await readdir(dir, { withFileTypes: true });
33
+ let total = 0;
34
+ for (const entry of entries) {
35
+ const full = join(dir, entry.name);
36
+ if (entry.isDirectory()) {
37
+ total += await countSessionFiles(full);
38
+ }
39
+ else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
40
+ total += 1;
41
+ }
42
+ }
43
+ return total;
44
+ }
45
+ //# sourceMappingURL=sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAYzD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAA8B;IAChE,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,8DAA8D;QAC9D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC;AAED,uEAAuE;AACvE,KAAK,UAAU,iBAAiB,CAAC,GAAW;IAC1C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,KAAK,IAAI,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;aAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3D,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/ui.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { ValidationStatus } from "./doctor.js";
2
+ /**
3
+ * Decide whether ANSI color should be emitted. `NO_COLOR` (any value) always
4
+ * wins per the no-color.org convention; `FORCE_COLOR` forces the decision when
5
+ * set to a recognized truthy/falsy value; otherwise color follows the TTY-ness
6
+ * of the stream. Pure and env-injected so it is trivially testable.
7
+ */
8
+ export declare function computeColorEnabled(env: Record<string, string | undefined>, isTty: boolean | undefined): boolean;
9
+ export declare function isColorEnabled(): boolean;
10
+ /** Color/weight helpers. Each is the identity function when color is disabled. */
11
+ export declare const style: {
12
+ readonly bold: (text: string) => string;
13
+ readonly dim: (text: string) => string;
14
+ readonly red: (text: string) => string;
15
+ readonly green: (text: string) => string;
16
+ readonly yellow: (text: string) => string;
17
+ readonly cyan: (text: string) => string;
18
+ readonly gray: (text: string) => string;
19
+ };
20
+ /**
21
+ * Render a status badge as a fixed-width prefix (badge + trailing space). With
22
+ * color on it is a green/yellow/dim/red glyph; with color off it falls back to
23
+ * an equal-width ASCII tag so columns still line up in plain output.
24
+ */
25
+ export declare function badge(status: ValidationStatus): string;
26
+ /**
27
+ * Render aligned `label value` rows: labels are padded to the widest label so
28
+ * values line up, replacing the hand-tuned `padEnd` blocks. `indent` prefixes
29
+ * every row with that many spaces (used to nest rows under a section rule).
30
+ * Returns one string with a trailing newline per row (empty when there are no
31
+ * rows).
32
+ */
33
+ export declare function keyValue(rows: ReadonlyArray<readonly [label: string, value: string]>, indent?: number): string;
34
+ /**
35
+ * A horizontal section divider, optionally labeled — `── instance ────────`.
36
+ * Width tracks the terminal (read at call time so resizes are honored), capped
37
+ * for readability and falling back to a fixed width when stdout is not a TTY.
38
+ * Rendered dim/gray (identity when color is off); the label appears verbatim so
39
+ * it stays greppable. Always ends with a newline.
40
+ */
41
+ export declare function rule(label?: string): string;
42
+ /** Badge for a channel status *kind* string (running/waiting…/disabled/error). */
43
+ export declare function channelBadge(kind: string): string;
44
+ /** Badge for a trace-source health word (running/stale/stopped/…). */
45
+ export declare function healthBadge(health: string): string;
46
+ /** A bold/cyan section heading with a trailing newline. */
47
+ export declare function heading(text: string): string;
48
+ /** The CLI title block: bold title plus an optional dim subtitle. */
49
+ export declare function banner(title: string, subtitle?: string): string;
50
+ /** A red error line (✗ prefix) with a trailing newline — write to stderr. */
51
+ export declare function errorLine(message: string): string;
52
+ /** A dim hint line (→ prefix) with a trailing newline. */
53
+ export declare function hint(message: string): string;
54
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
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