@mono-agent/agent-app 0.2.2 → 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.
- package/README.md +9 -5
- package/dist/adapter-send-tools-main.d.ts +3 -0
- package/dist/adapter-send-tools-main.d.ts.map +1 -0
- package/dist/adapter-send-tools-main.js +20 -0
- package/dist/adapter-send-tools-main.js.map +1 -0
- package/dist/adapter-send-tools.d.ts +59 -0
- package/dist/adapter-send-tools.d.ts.map +1 -0
- package/dist/adapter-send-tools.js +254 -0
- package/dist/adapter-send-tools.js.map +1 -0
- package/dist/app-config.d.ts +40 -17
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +188 -68
- package/dist/app-config.js.map +1 -1
- package/dist/app.d.ts +41 -20
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +349 -87
- package/dist/app.js.map +1 -1
- package/dist/backfill.d.ts +79 -0
- package/dist/backfill.d.ts.map +1 -0
- package/dist/backfill.js +246 -0
- package/dist/backfill.js.map +1 -0
- package/dist/background.d.ts +0 -4
- package/dist/background.d.ts.map +1 -1
- package/dist/background.js +78 -50
- package/dist/background.js.map +1 -1
- package/dist/channels.d.ts +7 -0
- package/dist/channels.d.ts.map +1 -1
- package/dist/channels.js +26 -3
- package/dist/channels.js.map +1 -1
- package/dist/cli.d.ts +53 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +317 -113
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +8 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +236 -30
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -1
- package/dist/init.js.map +1 -1
- package/dist/launchd.d.ts +0 -2
- package/dist/launchd.d.ts.map +1 -1
- package/dist/launchd.js +0 -2
- package/dist/launchd.js.map +1 -1
- package/dist/memory-recall-main.d.ts +3 -0
- package/dist/memory-recall-main.d.ts.map +1 -0
- package/dist/memory-recall-main.js +30 -0
- package/dist/memory-recall-main.js.map +1 -0
- package/dist/memory-recall.d.ts +111 -0
- package/dist/memory-recall.d.ts.map +1 -0
- package/dist/memory-recall.js +275 -0
- package/dist/memory-recall.js.map +1 -0
- package/dist/memory-rituals.d.ts +51 -0
- package/dist/memory-rituals.d.ts.map +1 -0
- package/dist/memory-rituals.js +228 -0
- package/dist/memory-rituals.js.map +1 -0
- package/dist/sessions.d.ts +21 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +45 -0
- package/dist/sessions.js.map +1 -0
- package/dist/ui.d.ts +54 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +153 -0
- package/dist/ui.js.map +1 -0
- package/package.json +22 -17
- package/skills/mono-agent-composer/SKILL.md +7 -6
- package/skills/mono-agent-composer/references/config-blueprint.md +53 -22
- package/skills/mono-agent-composer/references/discovery-questions.md +121 -10
- package/skills/mono-agent-composer/references/feature-coverage.md +15 -12
- package/skills/mono-agent-composer/references/package-map.md +9 -11
- package/skills/mono-agent-composer/references/validation.md +5 -4
package/dist/launchd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launchd.js","sourceRoot":"","sources":["../src/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,OAAO,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"launchd.js","sourceRoot":"","sources":["../src/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,K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M,CAAC,KAAK,UAAU,SAAS,CAAC,MAAuB,EAAE,SAAiB,EAAE,GAAW;IACrF,OAAO,MAAM,MAAM,CAAC,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAuB,EAAE,KAAa,EAAE,GAAW;IACxF,OAAO,MAAM,MAAM,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAAuB,EAAE,KAAa,EAAE,GAAW;IAC/E,OAAO,MAAM,MAAM,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-recall-main.d.ts","sourceRoot":"","sources":["../src/memory-recall-main.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { createMemoryRecallServer, createRecallStore, memoryRecallSettingsFromEnv } from "./memory-recall.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const settings = memoryRecallSettingsFromEnv(process.env);
|
|
6
|
+
const store = createRecallStore(settings);
|
|
7
|
+
const server = createMemoryRecallServer(store);
|
|
8
|
+
// Registering these listeners overrides Node's default terminate-on-signal, so we must exit
|
|
9
|
+
// explicitly. store.close() drains/closes the db before the process leaves.
|
|
10
|
+
const shutdown = () => {
|
|
11
|
+
void store
|
|
12
|
+
.close()
|
|
13
|
+
.catch((error) => {
|
|
14
|
+
// Don't let a failed close become an unhandled rejection; log to stderr (stdout is the MCP
|
|
15
|
+
// transport) and still exit so the signal isn't swallowed.
|
|
16
|
+
process.stderr.write(`mono-agent-memory-recall: shutdown close failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
17
|
+
})
|
|
18
|
+
.finally(() => {
|
|
19
|
+
process.exit(0);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
process.on("SIGINT", shutdown);
|
|
23
|
+
process.on("SIGTERM", shutdown);
|
|
24
|
+
await server.connect(new StdioServerTransport());
|
|
25
|
+
}
|
|
26
|
+
main().catch((error) => {
|
|
27
|
+
process.stderr.write(`mono-agent-memory-recall: fatal: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
28
|
+
process.exitCode = 1;
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=memory-recall-main.js.map
|
|
@@ -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,CAAC;AAEpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,eAAO,MAAM,6BAA6B,sBAAsB,CAAC;AAEjE,+GAA+G;AAC/G,MAAM,WAAW,oCAAoC;IACnD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,iGAAiG;AACjG,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,oFAAoF;IACpF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kGAAkG;IAClG,QAAQ,CAAC,SA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AC,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,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cron
|
|
5
|
+
* cadences (defaults: `0 3 * * *` / `0 4 1 * *`). Uses a hand-rolled minimal
|
|
6
|
+
* cron next-run calculator (5-field `m h dom mon dow`); avoids adding
|
|
7
|
+
* `cron-parser` as a direct dep of this package.
|
|
8
|
+
*
|
|
9
|
+
* Design guarantees:
|
|
10
|
+
* - Only schedules for `store.tier() === "bujo"` (needs the LLM tier).
|
|
11
|
+
* - Rituals default-enabled; set `enabled: false` to opt out.
|
|
12
|
+
* - Skip-overlap: never starts a run while the previous is in flight.
|
|
13
|
+
* - Never-throws: errors are caught and logged via `logger.warn`; the
|
|
14
|
+
* scheduler reschedules after every run (success or failure).
|
|
15
|
+
* - Injectable `now` / `setTimer` / `clearTimer` for deterministic testing.
|
|
16
|
+
*/
|
|
17
|
+
export interface MemoryRitualSchedule {
|
|
18
|
+
readonly enabled?: boolean;
|
|
19
|
+
readonly cron?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface StartMemoryRitualsInput {
|
|
22
|
+
readonly store: {
|
|
23
|
+
tier(): string;
|
|
24
|
+
reflect(): Promise<unknown>;
|
|
25
|
+
migrate(): Promise<unknown>;
|
|
26
|
+
};
|
|
27
|
+
/** From config.memory.reflection */
|
|
28
|
+
readonly reflection?: MemoryRitualSchedule;
|
|
29
|
+
/** From config.memory.migration */
|
|
30
|
+
readonly migration?: MemoryRitualSchedule;
|
|
31
|
+
readonly logger?: {
|
|
32
|
+
info(m: string): void;
|
|
33
|
+
warn(m: string): void;
|
|
34
|
+
};
|
|
35
|
+
/** Injectable clock for tests. Defaults to `() => new Date()`. */
|
|
36
|
+
readonly now?: () => Date;
|
|
37
|
+
/**
|
|
38
|
+
* Injectable timer factory for tests.
|
|
39
|
+
* Defaults to a `setTimeout` wrapper returning the timeout handle.
|
|
40
|
+
*/
|
|
41
|
+
readonly setTimer?: (cb: () => void, ms: number) => {
|
|
42
|
+
unref?: () => void;
|
|
43
|
+
};
|
|
44
|
+
/** Injectable timer canceller. Defaults to `clearTimeout`. */
|
|
45
|
+
readonly clearTimer?: (handle: unknown) => void;
|
|
46
|
+
}
|
|
47
|
+
export interface RunningRituals {
|
|
48
|
+
stop(): void;
|
|
49
|
+
}
|
|
50
|
+
export declare function startMemoryRituals(input: StartMemoryRitualsInput): RunningRituals;
|
|
51
|
+
//# sourceMappingURL=memory-rituals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-rituals.d.ts","sourceRoot":"","sources":["../src/memory-rituals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE;QACd,IAAI,IAAI,MAAM,CAAC;QACf,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;KAC7B,CAAC;IACF,oCAAoC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC3C,mCAAmC;IACnC,QAAQ,CAAC,SAAS,CAAC,EAAE,oBAAoB,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;IACF,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK;QAAE,KAAK,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;IAC3E,8DAA8D;IAC9D,QAAQ,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