@ai-agent-forge/plugin-memory 0.88.1 → 0.88.4
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 +10 -4
- package/agent-forge.json +1 -1
- package/bin/agent-forge-memory-inference.js +8 -0
- package/dist/capability.d.ts +42 -59
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +263 -2055
- package/dist/capability.js.map +1 -1
- package/dist/entry.d.ts +11 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +38 -2
- package/dist/entry.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inference-bin.d.ts +21 -0
- package/dist/inference-bin.d.ts.map +1 -0
- package/dist/inference-bin.js +85 -0
- package/dist/inference-bin.js.map +1 -0
- package/dist/memory/command-face.d.ts +86 -0
- package/dist/memory/command-face.d.ts.map +1 -0
- package/dist/memory/command-face.js +377 -0
- package/dist/memory/command-face.js.map +1 -0
- package/dist/memory/embedding-provider.d.ts.map +1 -1
- package/dist/memory/embedding-provider.js +14 -2
- package/dist/memory/embedding-provider.js.map +1 -1
- package/dist/memory/embedding-reranker.d.ts.map +1 -1
- package/dist/memory/embedding-reranker.js +14 -2
- package/dist/memory/embedding-reranker.js.map +1 -1
- package/dist/memory/enabling.d.ts +104 -0
- package/dist/memory/enabling.d.ts.map +1 -0
- package/dist/memory/enabling.js +321 -0
- package/dist/memory/enabling.js.map +1 -0
- package/dist/memory/hooks.d.ts +110 -0
- package/dist/memory/hooks.d.ts.map +1 -0
- package/dist/memory/hooks.js +478 -0
- package/dist/memory/hooks.js.map +1 -0
- package/dist/memory/inference-channel.d.ts +33 -0
- package/dist/memory/inference-channel.d.ts.map +1 -0
- package/dist/memory/inference-channel.js +101 -0
- package/dist/memory/inference-channel.js.map +1 -0
- package/dist/memory/inference-client.d.ts +25 -0
- package/dist/memory/inference-client.d.ts.map +1 -0
- package/dist/memory/inference-client.js +216 -0
- package/dist/memory/inference-client.js.map +1 -0
- package/dist/memory/inference-protocol.d.ts +95 -0
- package/dist/memory/inference-protocol.d.ts.map +1 -0
- package/dist/memory/inference-protocol.js +27 -0
- package/dist/memory/inference-protocol.js.map +1 -0
- package/dist/memory/inference-server.d.ts +70 -0
- package/dist/memory/inference-server.d.ts.map +1 -0
- package/dist/memory/inference-server.js +395 -0
- package/dist/memory/inference-server.js.map +1 -0
- package/dist/memory/inference-service-main.d.ts +31 -0
- package/dist/memory/inference-service-main.d.ts.map +1 -0
- package/dist/memory/inference-service-main.js +89 -0
- package/dist/memory/inference-service-main.js.map +1 -0
- package/dist/memory/ledger.d.ts +15 -0
- package/dist/memory/ledger.d.ts.map +1 -1
- package/dist/memory/ledger.js +35 -2
- package/dist/memory/ledger.js.map +1 -1
- package/dist/memory/model-cache-hygiene.d.ts +10 -0
- package/dist/memory/model-cache-hygiene.d.ts.map +1 -1
- package/dist/memory/model-cache-hygiene.js +15 -0
- package/dist/memory/model-cache-hygiene.js.map +1 -1
- package/dist/memory/preference-promotion.d.ts +0 -14
- package/dist/memory/preference-promotion.d.ts.map +1 -1
- package/dist/memory/preference-promotion.js +17 -0
- package/dist/memory/preference-promotion.js.map +1 -1
- package/dist/memory/recall-pipeline.d.ts +85 -0
- package/dist/memory/recall-pipeline.d.ts.map +1 -0
- package/dist/memory/recall-pipeline.js +678 -0
- package/dist/memory/recall-pipeline.js.map +1 -0
- package/dist/memory/retention-sweep.d.ts +59 -0
- package/dist/memory/retention-sweep.d.ts.map +1 -0
- package/dist/memory/retention-sweep.js +103 -0
- package/dist/memory/retention-sweep.js.map +1 -0
- package/dist/memory/store.d.ts +17 -2
- package/dist/memory/store.d.ts.map +1 -1
- package/dist/memory/store.js +18 -2
- package/dist/memory/store.js.map +1 -1
- package/dist/memory/vector-channel.d.ts +120 -0
- package/dist/memory/vector-channel.d.ts.map +1 -0
- package/dist/memory/vector-channel.js +495 -0
- package/dist/memory/vector-channel.js.map +1 -0
- package/dist/memory/vector-projection.d.ts +87 -0
- package/dist/memory/vector-projection.d.ts.map +1 -0
- package/dist/memory/vector-projection.js +215 -0
- package/dist/memory/vector-projection.js.map +1 -0
- package/dist/memory/write-face.d.ts +128 -0
- package/dist/memory/write-face.d.ts.map +1 -0
- package/dist/memory/write-face.js +504 -0
- package/dist/memory/write-face.js.map +1 -0
- package/dist/testing/memory-testkit.d.ts +2 -0
- package/dist/testing/memory-testkit.d.ts.map +1 -1
- package/dist/testing/memory-testkit.js +1 -0
- package/dist/testing/memory-testkit.js.map +1 -1
- package/package.json +7 -3
- package/plugin.json +1 -1
package/dist/entry.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { CapabilityAPI } from "@agent-forge/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* 记忆共享推理服务进程的档位解析 (Slice B1): bin 入口没有宿主插件配置面,
|
|
4
|
+
* 解析链 = env `AGENT_FORGE_MEMORY_MODE` (resolver 内建) → agent-dir 配置文件
|
|
5
|
+
* 的 `memorySettingsMode` → 默认 light — 与会话装配同一 resolver, 同一配置
|
|
6
|
+
* 键。off (显式关闭/非法 fail-closed) 时服务不启动 (结构化 error)。
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveMemoryServiceMode(agentDir: string, env: NodeJS.ProcessEnv): {
|
|
9
|
+
readonly mode: "light" | "full";
|
|
10
|
+
} | {
|
|
11
|
+
readonly error: string;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.
|
|
4
15
|
*
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,yBAAyB,CAAC;AAqD9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,GAAG,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA2E3F","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { CapabilityAPI, PluginConfig, PluginConfigValue } from \"@agent-forge/plugin-sdk\";\nimport { createMemoryCapability, resolveMemoryMode } from \"./capability.ts\";\n\n/**\n * Agent-dir config file channel (D-075 S4 fourth batch): the same path the\n * host's pre-split `builtinCapabilityConfigPath(agentDir, \"builtin.memory\")`\n * resolved for the embedded capability. Hosts that declare `api.host.agentDir`\n * have this file read here and merged over the manifest config — the exact\n * merge-over-defaults semantics the embedded `withCapabilityConfig` channel\n * had. A missing file is the normal unconfigured state; an unreadable file,\n * invalid JSON, or a non-object payload fails the plugin load explicitly\n * (D-028: this plugin only, never the session). A host without `agentDir`\n * loads the plugin with the manifest config alone.\n */\nconst CAPABILITY_CONFIG_RELATIVE_PATH = join(\"capabilities\", \"builtin.memory.json\");\n\n/** Reads the agent-dir config channel; `undefined` means \"no file\" (normal unconfigured state). */\nfunction readAgentDirConfig(configPath: string | undefined): PluginConfig | undefined {\n\tif (configPath === undefined) return undefined;\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(configPath, \"utf8\");\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow new Error(`Failed to read ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (error) {\n\t\tthrow new Error(`${configPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${configPath} must contain a JSON object`);\n\t}\n\treturn parsed as PluginConfig;\n}\n\n/**\n * The string-valued config key or `undefined`. A present-but-non-string value\n * (only possible through the raw JSON channels) is reported by the caller —\n * never silently coerced.\n */\nfunction stringConfigValue(\n\tconfig: PluginConfig,\n\tkey: string,\n): { readonly value?: string; readonly invalid?: PluginConfigValue } {\n\tconst raw = config[key];\n\tif (raw === undefined) return {};\n\tif (typeof raw === \"string\") return { value: raw };\n\treturn { invalid: raw };\n}\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * Service mapping (D-075 S4 fourth batch): the host facts the embedded\n * capability received as constructor context are assembled here from\n * `api.host` and the merged config —\n * - `api.host.agentDir` roots the durable ledger (`<agentDir>/memory/`) and\n * opens the agent-dir config channel;\n * - `api.host.memoryStorage` → the A1/A2 storage injection face\n * (`MemoryStorageComponentsV1`: store/ledger factories plus optional\n * vector components); absent = the plugin's built-in local implementation;\n * - mode resolution reuses the migrated `resolveMemoryMode` with the same\n * precedence the host assembler had: explicit config `memoryMode` (host\n * configOverride injects it, wiring lands with the host cutover batch) →\n * env `AGENT_FORGE_MEMORY_MODE` (read here via the resolver's process.env\n * default) → config `memorySettingsMode` (the persistent settings face) →\n * legacy alias → off.\n *\n * A resolved mode of \"off\", or a host without `agentDir`, registers NOTHING\n * (zero tools, zero commands, zero events) with one debug log line — the same\n * tool-face-absent semantics the embedded capability had for mode=off; the\n * factory never throws for a disabled configuration.\n *\n * `vectorComponents` (the test-only seam) deliberately does NOT ride the\n * entry: it stays on the library face (`createCapabilityWithVectorComponents`)\n * for embedders and tests, per the deterministic-mock gate.\n *\n * The factory returns its registrations as an array; the wrapper disposes them\n * in reverse order on plugin teardown — the same disposal semantics as the\n * host's embedded `syncRegistrationFactory`.\n */\nexport default function createMemoryPluginEntry(api: CapabilityAPI): { dispose: () => void } {\n\tconst agentDir = api.host.agentDir;\n\tif (agentDir === undefined) {\n\t\t// No agent dir = no durable memory location; the tool face stays absent\n\t\t// instead of failing the plugin (the host opted out of disk state).\n\t\tapi.logger?.debug(\"memory plugin idle: host declares no agentDir\");\n\t\treturn { dispose: () => {} };\n\t}\n\tconst configPath = join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH);\n\tconst fileConfig = readAgentDirConfig(configPath);\n\tconst effectiveConfig: PluginConfig = fileConfig === undefined ? api.config : { ...api.config, ...fileConfig };\n\n\tconst mode = stringConfigValue(effectiveConfig, \"memoryMode\");\n\tif (mode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memoryMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\tconst settingsMode = stringConfigValue(effectiveConfig, \"memorySettingsMode\");\n\tif (settingsMode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memorySettingsMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\t// resolveMemoryMode's env parameter defaults to process.env; passing the\n\t// default explicitly keeps the entry's \"env read here\" contract visible.\n\tconst resolution = resolveMemoryMode(mode.value, process.env, settingsMode.value);\n\tif (resolution.invalidEnvValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid AGENT_FORGE_MEMORY_MODE value \"${resolution.invalidEnvValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.invalidSettingsValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid memory.mode setting \"${resolution.invalidSettingsValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.mode === \"off\") {\n\t\tapi.logger?.debug(\"memory plugin idle (mode=off)\");\n\t\treturn { dispose: () => {} };\n\t}\n\n\tconst memoryStorage = api.host.memoryStorage;\n\t// 宿主重依赖路径注入 (安装店可见性): 装载器把 hostDependencyPaths 并进\n\t// manifest config (specifier → 宿主 node_modules 入口绝对路径)。onnxruntime\n\t// 供 native 预检; lancedb/transformers 供运行时按绝对路径原生 import (安装店\n\t// 副本的裸 import 无法解析)。非字符串值忽略 (fail-closed 由消费侧兜底)。\n\tconst dependencyPaths = effectiveConfig.hostDependencyPaths;\n\tconst dependencyPathMap: Record<string, PluginConfigValue> | undefined =\n\t\tArray.isArray(dependencyPaths) || typeof dependencyPaths !== \"object\" || dependencyPaths === null\n\t\t\t? undefined\n\t\t\t: (dependencyPaths as Record<string, PluginConfigValue>);\n\tconst stringDependencyPath = (key: string): string | undefined => {\n\t\tconst value = dependencyPathMap?.[key];\n\t\treturn typeof value === \"string\" ? value : undefined;\n\t};\n\tconst hostOnnxRuntimeEntryPath = stringDependencyPath(\"onnxruntimeNode\");\n\tconst hostLancedbEntryPath = stringDependencyPath(\"lancedb\");\n\tconst hostTransformersEntryPath = stringDependencyPath(\"transformers\");\n\tconst registrations = createMemoryCapability(api, {\n\t\tagentDir,\n\t\t...(hostOnnxRuntimeEntryPath === undefined ? {} : { hostOnnxRuntimeEntryPath }),\n\t\t...(hostLancedbEntryPath === undefined ? {} : { hostLancedbEntryPath }),\n\t\t...(hostTransformersEntryPath === undefined ? {} : { hostTransformersEntryPath }),\n\t\tmemory: {\n\t\t\tmode: resolution.mode,\n\t\t\t...(settingsMode.value === undefined ? {} : { settingsMode: settingsMode.value }),\n\t\t},\n\t\t...(memoryStorage === undefined ? {} : { storage: memoryStorage }),\n\t});\n\treturn {\n\t\tdispose: () => {\n\t\t\tfor (const registration of [...registrations].reverse()) {\n\t\t\t\t// Registration disposal in the capability runtime is synchronous;\n\t\t\t\t// void consumes the declared Promise possibility of the contract.\n\t\t\t\tvoid registration.dispose();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,yBAAyB,CAAC;AA0D9F;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACvC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,UAAU,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAalE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,GAAG,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA8F3F","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { CapabilityAPI, PluginConfig, PluginConfigValue } from \"@agent-forge/plugin-sdk\";\nimport {\n\tcreateMemoryCapability,\n\tMEMORY_CONSENT_DECLINED_VALUE,\n\tmemoryModeSourceIsDefault,\n\tresolveMemoryMode,\n} from \"./capability.ts\";\n\n/**\n * Agent-dir config file channel (D-075 S4 fourth batch): the same path the\n * host's pre-split `builtinCapabilityConfigPath(agentDir, \"builtin.memory\")`\n * resolved for the embedded capability. Hosts that declare `api.host.agentDir`\n * have this file read here and merged over the manifest config — the exact\n * merge-over-defaults semantics the embedded `withCapabilityConfig` channel\n * had. A missing file is the normal unconfigured state; an unreadable file,\n * invalid JSON, or a non-object payload fails the plugin load explicitly\n * (D-028: this plugin only, never the session). A host without `agentDir`\n * loads the plugin with the manifest config alone.\n */\nconst CAPABILITY_CONFIG_RELATIVE_PATH = join(\"capabilities\", \"builtin.memory.json\");\n\n/** Reads the agent-dir config channel; `undefined` means \"no file\" (normal unconfigured state). */\nfunction readAgentDirConfig(configPath: string | undefined): PluginConfig | undefined {\n\tif (configPath === undefined) return undefined;\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(configPath, \"utf8\");\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow new Error(`Failed to read ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (error) {\n\t\tthrow new Error(`${configPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${configPath} must contain a JSON object`);\n\t}\n\treturn parsed as PluginConfig;\n}\n\n/**\n * The string-valued config key or `undefined`. A present-but-non-string value\n * (only possible through the raw JSON channels) is reported by the caller —\n * never silently coerced.\n */\nfunction stringConfigValue(\n\tconfig: PluginConfig,\n\tkey: string,\n): { readonly value?: string; readonly invalid?: PluginConfigValue } {\n\tconst raw = config[key];\n\tif (raw === undefined) return {};\n\tif (typeof raw === \"string\") return { value: raw };\n\treturn { invalid: raw };\n}\n\n/**\n * 记忆共享推理服务进程的档位解析 (Slice B1): bin 入口没有宿主插件配置面,\n * 解析链 = env `AGENT_FORGE_MEMORY_MODE` (resolver 内建) → agent-dir 配置文件\n * 的 `memorySettingsMode` → 默认 light — 与会话装配同一 resolver, 同一配置\n * 键。off (显式关闭/非法 fail-closed) 时服务不启动 (结构化 error)。\n */\nexport function resolveMemoryServiceMode(\n\tagentDir: string,\n\tenv: NodeJS.ProcessEnv,\n): { readonly mode: \"light\" | \"full\" } | { readonly error: string } {\n\tconst fileConfig = readAgentDirConfig(join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH));\n\tconst settingsMode = fileConfig === undefined ? undefined : stringConfigValue(fileConfig, \"memorySettingsMode\");\n\tif (settingsMode?.invalid !== undefined) {\n\t\treturn {\n\t\t\terror: \"memorySettingsMode config must be a string; the inference service refuses to start (fail-closed)\",\n\t\t};\n\t}\n\tconst resolution = resolveMemoryMode(undefined, env, settingsMode?.value);\n\tif (resolution.mode === \"off\") {\n\t\treturn { error: \"memory mode resolved to off — the inference service does not start\" };\n\t}\n\treturn { mode: resolution.mode };\n}\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * Service mapping (D-075 S4 fourth batch): the host facts the embedded\n * capability received as constructor context are assembled here from\n * `api.host` and the merged config —\n * - `api.host.agentDir` roots the durable ledger (`<agentDir>/memory/`) and\n * opens the agent-dir config channel;\n * - `api.host.memoryStorage` → the A1/A2 storage injection face\n * (`MemoryStorageComponentsV1`: store/ledger factories plus optional\n * vector components); absent = the plugin's built-in local implementation;\n * - mode resolution reuses the migrated `resolveMemoryMode` with the same\n * precedence the host assembler had: explicit config `memoryMode` (host\n * configOverride injects it, wiring lands with the host cutover batch) →\n * env `AGENT_FORGE_MEMORY_MODE` (read here via the resolver's process.env\n * default) → config `memorySettingsMode` (the persistent settings face) →\n * legacy alias → off.\n *\n * A resolved mode of \"off\", or a host without `agentDir`, registers NOTHING\n * (zero tools, zero commands, zero events) with one debug log line — the same\n * tool-face-absent semantics the embedded capability had for mode=off; the\n * factory never throws for a disabled configuration.\n *\n * `vectorComponents` (the test-only seam) deliberately does NOT ride the\n * entry: it stays on the library face (`createCapabilityWithVectorComponents`)\n * for embedders and tests, per the deterministic-mock gate.\n *\n * The factory returns its registrations as an array; the wrapper disposes them\n * in reverse order on plugin teardown — the same disposal semantics as the\n * host's embedded `syncRegistrationFactory`.\n */\nexport default function createMemoryPluginEntry(api: CapabilityAPI): { dispose: () => void } {\n\tconst agentDir = api.host.agentDir;\n\tif (agentDir === undefined) {\n\t\t// No agent dir = no durable memory location; the tool face stays absent\n\t\t// instead of failing the plugin (the host opted out of disk state).\n\t\tapi.logger?.debug(\"memory plugin idle: host declares no agentDir\");\n\t\treturn { dispose: () => {} };\n\t}\n\tconst configPath = join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH);\n\tconst fileConfig = readAgentDirConfig(configPath);\n\tconst effectiveConfig: PluginConfig = fileConfig === undefined ? api.config : { ...api.config, ...fileConfig };\n\n\tconst mode = stringConfigValue(effectiveConfig, \"memoryMode\");\n\tif (mode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memoryMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\tconst settingsMode = stringConfigValue(effectiveConfig, \"memorySettingsMode\");\n\tif (settingsMode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memorySettingsMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\t// resolveMemoryMode's env parameter defaults to process.env; passing the\n\t// default explicitly keeps the entry's \"env read here\" contract visible.\n\t// Type-invalid config values fail closed to off as well: they never enter\n\t// the resolution chain, so without this guard they would fall through to\n\t// the default tier (light since the 2026-10-05 flip) and turn the\n\t// \"memory stays off (fail-closed)\" warn above into a lie.\n\tconst resolution =\n\t\tmode.invalid !== undefined || settingsMode.invalid !== undefined\n\t\t\t? { mode: \"off\" as const }\n\t\t\t: resolveMemoryMode(mode.value, process.env, settingsMode.value);\n\tif (resolution.invalidEnvValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid AGENT_FORGE_MEMORY_MODE value \"${resolution.invalidEnvValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.invalidSettingsValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid memory.mode setting \"${resolution.invalidSettingsValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.mode === \"off\") {\n\t\tapi.logger?.debug(\"memory plugin idle (mode=off)\");\n\t\treturn { dispose: () => {} };\n\t}\n\t// 征询拒绝的持久化 (2026-10-05 用户裁决「拒绝即把记忆改为 off, 想用再显式\n\t// 改回来」): 拒绝标记写在本插件的 agent-dir 配置文件 (memoryConsent 键), 只\n\t// 抑制默认档——env / settings.json 的显式档位仍然生效, 用户日后显式启用时\n\t// 首次使用会再次走到征询门。\n\tconst consent = stringConfigValue(effectiveConfig, \"memoryConsent\");\n\tif (\n\t\tconsent.value === MEMORY_CONSENT_DECLINED_VALUE &&\n\t\tmemoryModeSourceIsDefault(mode.value, process.env, settingsMode.value)\n\t) {\n\t\tapi.logger?.debug(\"memory plugin idle (declined by user; set memory.mode in settings.json to re-enable)\");\n\t\treturn { dispose: () => {} };\n\t}\n\n\tconst memoryStorage = api.host.memoryStorage;\n\t// 宿主重依赖路径注入 (安装店可见性): 装载器把 hostDependencyPaths 并进\n\t// manifest config (specifier → 宿主 node_modules 入口绝对路径)。onnxruntime\n\t// 供 native 预检; lancedb/transformers 供运行时按绝对路径原生 import (安装店\n\t// 副本的裸 import 无法解析)。非字符串值忽略 (fail-closed 由消费侧兜底)。\n\tconst dependencyPaths = effectiveConfig.hostDependencyPaths;\n\tconst dependencyPathMap: Record<string, PluginConfigValue> | undefined =\n\t\tArray.isArray(dependencyPaths) || typeof dependencyPaths !== \"object\" || dependencyPaths === null\n\t\t\t? undefined\n\t\t\t: (dependencyPaths as Record<string, PluginConfigValue>);\n\tconst stringDependencyPath = (key: string): string | undefined => {\n\t\tconst value = dependencyPathMap?.[key];\n\t\treturn typeof value === \"string\" ? value : undefined;\n\t};\n\tconst hostOnnxRuntimeEntryPath = stringDependencyPath(\"onnxruntimeNode\");\n\tconst hostLancedbEntryPath = stringDependencyPath(\"lancedb\");\n\tconst hostTransformersEntryPath = stringDependencyPath(\"transformers\");\n\tconst registrations = createMemoryCapability(api, {\n\t\tagentDir,\n\t\t...(hostOnnxRuntimeEntryPath === undefined ? {} : { hostOnnxRuntimeEntryPath }),\n\t\t...(hostLancedbEntryPath === undefined ? {} : { hostLancedbEntryPath }),\n\t\t...(hostTransformersEntryPath === undefined ? {} : { hostTransformersEntryPath }),\n\t\tmemory: {\n\t\t\tmode: resolution.mode,\n\t\t\t...(settingsMode.value === undefined ? {} : { settingsMode: settingsMode.value }),\n\t\t},\n\t\t...(memoryStorage === undefined ? {} : { storage: memoryStorage }),\n\t});\n\treturn {\n\t\tdispose: () => {\n\t\t\tfor (const registration of [...registrations].reverse()) {\n\t\t\t\t// Registration disposal in the capability runtime is synchronous;\n\t\t\t\t// void consumes the declared Promise possibility of the contract.\n\t\t\t\tvoid registration.dispose();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
package/dist/entry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { createMemoryCapability, resolveMemoryMode } from "./capability.js";
|
|
3
|
+
import { createMemoryCapability, MEMORY_CONSENT_DECLINED_VALUE, memoryModeSourceIsDefault, resolveMemoryMode, } from "./capability.js";
|
|
4
4
|
/**
|
|
5
5
|
* Agent-dir config file channel (D-075 S4 fourth batch): the same path the
|
|
6
6
|
* host's pre-split `builtinCapabilityConfigPath(agentDir, "builtin.memory")`
|
|
@@ -51,6 +51,26 @@ function stringConfigValue(config, key) {
|
|
|
51
51
|
return { value: raw };
|
|
52
52
|
return { invalid: raw };
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* 记忆共享推理服务进程的档位解析 (Slice B1): bin 入口没有宿主插件配置面,
|
|
56
|
+
* 解析链 = env `AGENT_FORGE_MEMORY_MODE` (resolver 内建) → agent-dir 配置文件
|
|
57
|
+
* 的 `memorySettingsMode` → 默认 light — 与会话装配同一 resolver, 同一配置
|
|
58
|
+
* 键。off (显式关闭/非法 fail-closed) 时服务不启动 (结构化 error)。
|
|
59
|
+
*/
|
|
60
|
+
export function resolveMemoryServiceMode(agentDir, env) {
|
|
61
|
+
const fileConfig = readAgentDirConfig(join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH));
|
|
62
|
+
const settingsMode = fileConfig === undefined ? undefined : stringConfigValue(fileConfig, "memorySettingsMode");
|
|
63
|
+
if (settingsMode?.invalid !== undefined) {
|
|
64
|
+
return {
|
|
65
|
+
error: "memorySettingsMode config must be a string; the inference service refuses to start (fail-closed)",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const resolution = resolveMemoryMode(undefined, env, settingsMode?.value);
|
|
69
|
+
if (resolution.mode === "off") {
|
|
70
|
+
return { error: "memory mode resolved to off — the inference service does not start" };
|
|
71
|
+
}
|
|
72
|
+
return { mode: resolution.mode };
|
|
73
|
+
}
|
|
54
74
|
/**
|
|
55
75
|
* Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.
|
|
56
76
|
*
|
|
@@ -103,7 +123,13 @@ export default function createMemoryPluginEntry(api) {
|
|
|
103
123
|
}
|
|
104
124
|
// resolveMemoryMode's env parameter defaults to process.env; passing the
|
|
105
125
|
// default explicitly keeps the entry's "env read here" contract visible.
|
|
106
|
-
|
|
126
|
+
// Type-invalid config values fail closed to off as well: they never enter
|
|
127
|
+
// the resolution chain, so without this guard they would fall through to
|
|
128
|
+
// the default tier (light since the 2026-10-05 flip) and turn the
|
|
129
|
+
// "memory stays off (fail-closed)" warn above into a lie.
|
|
130
|
+
const resolution = mode.invalid !== undefined || settingsMode.invalid !== undefined
|
|
131
|
+
? { mode: "off" }
|
|
132
|
+
: resolveMemoryMode(mode.value, process.env, settingsMode.value);
|
|
107
133
|
if (resolution.invalidEnvValue !== undefined) {
|
|
108
134
|
api.logger?.warn(`invalid AGENT_FORGE_MEMORY_MODE value "${resolution.invalidEnvValue}"; memory stays off (fail-closed)`);
|
|
109
135
|
}
|
|
@@ -114,6 +140,16 @@ export default function createMemoryPluginEntry(api) {
|
|
|
114
140
|
api.logger?.debug("memory plugin idle (mode=off)");
|
|
115
141
|
return { dispose: () => { } };
|
|
116
142
|
}
|
|
143
|
+
// 征询拒绝的持久化 (2026-10-05 用户裁决「拒绝即把记忆改为 off, 想用再显式
|
|
144
|
+
// 改回来」): 拒绝标记写在本插件的 agent-dir 配置文件 (memoryConsent 键), 只
|
|
145
|
+
// 抑制默认档——env / settings.json 的显式档位仍然生效, 用户日后显式启用时
|
|
146
|
+
// 首次使用会再次走到征询门。
|
|
147
|
+
const consent = stringConfigValue(effectiveConfig, "memoryConsent");
|
|
148
|
+
if (consent.value === MEMORY_CONSENT_DECLINED_VALUE &&
|
|
149
|
+
memoryModeSourceIsDefault(mode.value, process.env, settingsMode.value)) {
|
|
150
|
+
api.logger?.debug("memory plugin idle (declined by user; set memory.mode in settings.json to re-enable)");
|
|
151
|
+
return { dispose: () => { } };
|
|
152
|
+
}
|
|
117
153
|
const memoryStorage = api.host.memoryStorage;
|
|
118
154
|
// 宿主重依赖路径注入 (安装店可见性): 装载器把 hostDependencyPaths 并进
|
|
119
155
|
// manifest config (specifier → 宿主 node_modules 入口绝对路径)。onnxruntime
|
package/dist/entry.js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IACH,OAAO;QACN,OAAO,EAAE,GAAG,EAAE,CAAC;YACd,KAAK,MAAM,YAAY,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;gBACzD,kEAAkE;gBAClE,kEAAkE;gBAClE,KAAK,YAAY,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { CapabilityAPI, PluginConfig, PluginConfigValue } from \"@agent-forge/plugin-sdk\";\nimport { createMemoryCapability, resolveMemoryMode } from \"./capability.ts\";\n\n/**\n * Agent-dir config file channel (D-075 S4 fourth batch): the same path the\n * host's pre-split `builtinCapabilityConfigPath(agentDir, \"builtin.memory\")`\n * resolved for the embedded capability. Hosts that declare `api.host.agentDir`\n * have this file read here and merged over the manifest config — the exact\n * merge-over-defaults semantics the embedded `withCapabilityConfig` channel\n * had. A missing file is the normal unconfigured state; an unreadable file,\n * invalid JSON, or a non-object payload fails the plugin load explicitly\n * (D-028: this plugin only, never the session). A host without `agentDir`\n * loads the plugin with the manifest config alone.\n */\nconst CAPABILITY_CONFIG_RELATIVE_PATH = join(\"capabilities\", \"builtin.memory.json\");\n\n/** Reads the agent-dir config channel; `undefined` means \"no file\" (normal unconfigured state). */\nfunction readAgentDirConfig(configPath: string | undefined): PluginConfig | undefined {\n\tif (configPath === undefined) return undefined;\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(configPath, \"utf8\");\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow new Error(`Failed to read ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (error) {\n\t\tthrow new Error(`${configPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${configPath} must contain a JSON object`);\n\t}\n\treturn parsed as PluginConfig;\n}\n\n/**\n * The string-valued config key or `undefined`. A present-but-non-string value\n * (only possible through the raw JSON channels) is reported by the caller —\n * never silently coerced.\n */\nfunction stringConfigValue(\n\tconfig: PluginConfig,\n\tkey: string,\n): { readonly value?: string; readonly invalid?: PluginConfigValue } {\n\tconst raw = config[key];\n\tif (raw === undefined) return {};\n\tif (typeof raw === \"string\") return { value: raw };\n\treturn { invalid: raw };\n}\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * Service mapping (D-075 S4 fourth batch): the host facts the embedded\n * capability received as constructor context are assembled here from\n * `api.host` and the merged config —\n * - `api.host.agentDir` roots the durable ledger (`<agentDir>/memory/`) and\n * opens the agent-dir config channel;\n * - `api.host.memoryStorage` → the A1/A2 storage injection face\n * (`MemoryStorageComponentsV1`: store/ledger factories plus optional\n * vector components); absent = the plugin's built-in local implementation;\n * - mode resolution reuses the migrated `resolveMemoryMode` with the same\n * precedence the host assembler had: explicit config `memoryMode` (host\n * configOverride injects it, wiring lands with the host cutover batch) →\n * env `AGENT_FORGE_MEMORY_MODE` (read here via the resolver's process.env\n * default) → config `memorySettingsMode` (the persistent settings face) →\n * legacy alias → off.\n *\n * A resolved mode of \"off\", or a host without `agentDir`, registers NOTHING\n * (zero tools, zero commands, zero events) with one debug log line — the same\n * tool-face-absent semantics the embedded capability had for mode=off; the\n * factory never throws for a disabled configuration.\n *\n * `vectorComponents` (the test-only seam) deliberately does NOT ride the\n * entry: it stays on the library face (`createCapabilityWithVectorComponents`)\n * for embedders and tests, per the deterministic-mock gate.\n *\n * The factory returns its registrations as an array; the wrapper disposes them\n * in reverse order on plugin teardown — the same disposal semantics as the\n * host's embedded `syncRegistrationFactory`.\n */\nexport default function createMemoryPluginEntry(api: CapabilityAPI): { dispose: () => void } {\n\tconst agentDir = api.host.agentDir;\n\tif (agentDir === undefined) {\n\t\t// No agent dir = no durable memory location; the tool face stays absent\n\t\t// instead of failing the plugin (the host opted out of disk state).\n\t\tapi.logger?.debug(\"memory plugin idle: host declares no agentDir\");\n\t\treturn { dispose: () => {} };\n\t}\n\tconst configPath = join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH);\n\tconst fileConfig = readAgentDirConfig(configPath);\n\tconst effectiveConfig: PluginConfig = fileConfig === undefined ? api.config : { ...api.config, ...fileConfig };\n\n\tconst mode = stringConfigValue(effectiveConfig, \"memoryMode\");\n\tif (mode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memoryMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\tconst settingsMode = stringConfigValue(effectiveConfig, \"memorySettingsMode\");\n\tif (settingsMode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memorySettingsMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\t// resolveMemoryMode's env parameter defaults to process.env; passing the\n\t// default explicitly keeps the entry's \"env read here\" contract visible.\n\tconst resolution = resolveMemoryMode(mode.value, process.env, settingsMode.value);\n\tif (resolution.invalidEnvValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid AGENT_FORGE_MEMORY_MODE value \"${resolution.invalidEnvValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.invalidSettingsValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid memory.mode setting \"${resolution.invalidSettingsValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.mode === \"off\") {\n\t\tapi.logger?.debug(\"memory plugin idle (mode=off)\");\n\t\treturn { dispose: () => {} };\n\t}\n\n\tconst memoryStorage = api.host.memoryStorage;\n\t// 宿主重依赖路径注入 (安装店可见性): 装载器把 hostDependencyPaths 并进\n\t// manifest config (specifier → 宿主 node_modules 入口绝对路径)。onnxruntime\n\t// 供 native 预检; lancedb/transformers 供运行时按绝对路径原生 import (安装店\n\t// 副本的裸 import 无法解析)。非字符串值忽略 (fail-closed 由消费侧兜底)。\n\tconst dependencyPaths = effectiveConfig.hostDependencyPaths;\n\tconst dependencyPathMap: Record<string, PluginConfigValue> | undefined =\n\t\tArray.isArray(dependencyPaths) || typeof dependencyPaths !== \"object\" || dependencyPaths === null\n\t\t\t? undefined\n\t\t\t: (dependencyPaths as Record<string, PluginConfigValue>);\n\tconst stringDependencyPath = (key: string): string | undefined => {\n\t\tconst value = dependencyPathMap?.[key];\n\t\treturn typeof value === \"string\" ? value : undefined;\n\t};\n\tconst hostOnnxRuntimeEntryPath = stringDependencyPath(\"onnxruntimeNode\");\n\tconst hostLancedbEntryPath = stringDependencyPath(\"lancedb\");\n\tconst hostTransformersEntryPath = stringDependencyPath(\"transformers\");\n\tconst registrations = createMemoryCapability(api, {\n\t\tagentDir,\n\t\t...(hostOnnxRuntimeEntryPath === undefined ? {} : { hostOnnxRuntimeEntryPath }),\n\t\t...(hostLancedbEntryPath === undefined ? {} : { hostLancedbEntryPath }),\n\t\t...(hostTransformersEntryPath === undefined ? {} : { hostTransformersEntryPath }),\n\t\tmemory: {\n\t\t\tmode: resolution.mode,\n\t\t\t...(settingsMode.value === undefined ? {} : { settingsMode: settingsMode.value }),\n\t\t},\n\t\t...(memoryStorage === undefined ? {} : { storage: memoryStorage }),\n\t});\n\treturn {\n\t\tdispose: () => {\n\t\t\tfor (const registration of [...registrations].reverse()) {\n\t\t\t\t// Registration disposal in the capability runtime is synchronous;\n\t\t\t\t// void consumes the declared Promise possibility of the contract.\n\t\t\t\tvoid registration.dispose();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACN,sBAAsB,EACtB,6BAA6B,EAC7B,yBAAyB,EACzB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;A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EAAE,CAAC;YAC7B,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { CapabilityAPI, PluginConfig, PluginConfigValue } from \"@agent-forge/plugin-sdk\";\nimport {\n\tcreateMemoryCapability,\n\tMEMORY_CONSENT_DECLINED_VALUE,\n\tmemoryModeSourceIsDefault,\n\tresolveMemoryMode,\n} from \"./capability.ts\";\n\n/**\n * Agent-dir config file channel (D-075 S4 fourth batch): the same path the\n * host's pre-split `builtinCapabilityConfigPath(agentDir, \"builtin.memory\")`\n * resolved for the embedded capability. Hosts that declare `api.host.agentDir`\n * have this file read here and merged over the manifest config — the exact\n * merge-over-defaults semantics the embedded `withCapabilityConfig` channel\n * had. A missing file is the normal unconfigured state; an unreadable file,\n * invalid JSON, or a non-object payload fails the plugin load explicitly\n * (D-028: this plugin only, never the session). A host without `agentDir`\n * loads the plugin with the manifest config alone.\n */\nconst CAPABILITY_CONFIG_RELATIVE_PATH = join(\"capabilities\", \"builtin.memory.json\");\n\n/** Reads the agent-dir config channel; `undefined` means \"no file\" (normal unconfigured state). */\nfunction readAgentDirConfig(configPath: string | undefined): PluginConfig | undefined {\n\tif (configPath === undefined) return undefined;\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(configPath, \"utf8\");\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow new Error(`Failed to read ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (error) {\n\t\tthrow new Error(`${configPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${configPath} must contain a JSON object`);\n\t}\n\treturn parsed as PluginConfig;\n}\n\n/**\n * The string-valued config key or `undefined`. A present-but-non-string value\n * (only possible through the raw JSON channels) is reported by the caller —\n * never silently coerced.\n */\nfunction stringConfigValue(\n\tconfig: PluginConfig,\n\tkey: string,\n): { readonly value?: string; readonly invalid?: PluginConfigValue } {\n\tconst raw = config[key];\n\tif (raw === undefined) return {};\n\tif (typeof raw === \"string\") return { value: raw };\n\treturn { invalid: raw };\n}\n\n/**\n * 记忆共享推理服务进程的档位解析 (Slice B1): bin 入口没有宿主插件配置面,\n * 解析链 = env `AGENT_FORGE_MEMORY_MODE` (resolver 内建) → agent-dir 配置文件\n * 的 `memorySettingsMode` → 默认 light — 与会话装配同一 resolver, 同一配置\n * 键。off (显式关闭/非法 fail-closed) 时服务不启动 (结构化 error)。\n */\nexport function resolveMemoryServiceMode(\n\tagentDir: string,\n\tenv: NodeJS.ProcessEnv,\n): { readonly mode: \"light\" | \"full\" } | { readonly error: string } {\n\tconst fileConfig = readAgentDirConfig(join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH));\n\tconst settingsMode = fileConfig === undefined ? undefined : stringConfigValue(fileConfig, \"memorySettingsMode\");\n\tif (settingsMode?.invalid !== undefined) {\n\t\treturn {\n\t\t\terror: \"memorySettingsMode config must be a string; the inference service refuses to start (fail-closed)\",\n\t\t};\n\t}\n\tconst resolution = resolveMemoryMode(undefined, env, settingsMode?.value);\n\tif (resolution.mode === \"off\") {\n\t\treturn { error: \"memory mode resolved to off — the inference service does not start\" };\n\t}\n\treturn { mode: resolution.mode };\n}\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * Service mapping (D-075 S4 fourth batch): the host facts the embedded\n * capability received as constructor context are assembled here from\n * `api.host` and the merged config —\n * - `api.host.agentDir` roots the durable ledger (`<agentDir>/memory/`) and\n * opens the agent-dir config channel;\n * - `api.host.memoryStorage` → the A1/A2 storage injection face\n * (`MemoryStorageComponentsV1`: store/ledger factories plus optional\n * vector components); absent = the plugin's built-in local implementation;\n * - mode resolution reuses the migrated `resolveMemoryMode` with the same\n * precedence the host assembler had: explicit config `memoryMode` (host\n * configOverride injects it, wiring lands with the host cutover batch) →\n * env `AGENT_FORGE_MEMORY_MODE` (read here via the resolver's process.env\n * default) → config `memorySettingsMode` (the persistent settings face) →\n * legacy alias → off.\n *\n * A resolved mode of \"off\", or a host without `agentDir`, registers NOTHING\n * (zero tools, zero commands, zero events) with one debug log line — the same\n * tool-face-absent semantics the embedded capability had for mode=off; the\n * factory never throws for a disabled configuration.\n *\n * `vectorComponents` (the test-only seam) deliberately does NOT ride the\n * entry: it stays on the library face (`createCapabilityWithVectorComponents`)\n * for embedders and tests, per the deterministic-mock gate.\n *\n * The factory returns its registrations as an array; the wrapper disposes them\n * in reverse order on plugin teardown — the same disposal semantics as the\n * host's embedded `syncRegistrationFactory`.\n */\nexport default function createMemoryPluginEntry(api: CapabilityAPI): { dispose: () => void } {\n\tconst agentDir = api.host.agentDir;\n\tif (agentDir === undefined) {\n\t\t// No agent dir = no durable memory location; the tool face stays absent\n\t\t// instead of failing the plugin (the host opted out of disk state).\n\t\tapi.logger?.debug(\"memory plugin idle: host declares no agentDir\");\n\t\treturn { dispose: () => {} };\n\t}\n\tconst configPath = join(agentDir, CAPABILITY_CONFIG_RELATIVE_PATH);\n\tconst fileConfig = readAgentDirConfig(configPath);\n\tconst effectiveConfig: PluginConfig = fileConfig === undefined ? api.config : { ...api.config, ...fileConfig };\n\n\tconst mode = stringConfigValue(effectiveConfig, \"memoryMode\");\n\tif (mode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memoryMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\tconst settingsMode = stringConfigValue(effectiveConfig, \"memorySettingsMode\");\n\tif (settingsMode.invalid !== undefined) {\n\t\tapi.logger?.warn(`memorySettingsMode config must be a string; memory stays off (fail-closed)`);\n\t}\n\t// resolveMemoryMode's env parameter defaults to process.env; passing the\n\t// default explicitly keeps the entry's \"env read here\" contract visible.\n\t// Type-invalid config values fail closed to off as well: they never enter\n\t// the resolution chain, so without this guard they would fall through to\n\t// the default tier (light since the 2026-10-05 flip) and turn the\n\t// \"memory stays off (fail-closed)\" warn above into a lie.\n\tconst resolution =\n\t\tmode.invalid !== undefined || settingsMode.invalid !== undefined\n\t\t\t? { mode: \"off\" as const }\n\t\t\t: resolveMemoryMode(mode.value, process.env, settingsMode.value);\n\tif (resolution.invalidEnvValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid AGENT_FORGE_MEMORY_MODE value \"${resolution.invalidEnvValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.invalidSettingsValue !== undefined) {\n\t\tapi.logger?.warn(\n\t\t\t`invalid memory.mode setting \"${resolution.invalidSettingsValue}\"; memory stays off (fail-closed)`,\n\t\t);\n\t}\n\tif (resolution.mode === \"off\") {\n\t\tapi.logger?.debug(\"memory plugin idle (mode=off)\");\n\t\treturn { dispose: () => {} };\n\t}\n\t// 征询拒绝的持久化 (2026-10-05 用户裁决「拒绝即把记忆改为 off, 想用再显式\n\t// 改回来」): 拒绝标记写在本插件的 agent-dir 配置文件 (memoryConsent 键), 只\n\t// 抑制默认档——env / settings.json 的显式档位仍然生效, 用户日后显式启用时\n\t// 首次使用会再次走到征询门。\n\tconst consent = stringConfigValue(effectiveConfig, \"memoryConsent\");\n\tif (\n\t\tconsent.value === MEMORY_CONSENT_DECLINED_VALUE &&\n\t\tmemoryModeSourceIsDefault(mode.value, process.env, settingsMode.value)\n\t) {\n\t\tapi.logger?.debug(\"memory plugin idle (declined by user; set memory.mode in settings.json to re-enable)\");\n\t\treturn { dispose: () => {} };\n\t}\n\n\tconst memoryStorage = api.host.memoryStorage;\n\t// 宿主重依赖路径注入 (安装店可见性): 装载器把 hostDependencyPaths 并进\n\t// manifest config (specifier → 宿主 node_modules 入口绝对路径)。onnxruntime\n\t// 供 native 预检; lancedb/transformers 供运行时按绝对路径原生 import (安装店\n\t// 副本的裸 import 无法解析)。非字符串值忽略 (fail-closed 由消费侧兜底)。\n\tconst dependencyPaths = effectiveConfig.hostDependencyPaths;\n\tconst dependencyPathMap: Record<string, PluginConfigValue> | undefined =\n\t\tArray.isArray(dependencyPaths) || typeof dependencyPaths !== \"object\" || dependencyPaths === null\n\t\t\t? undefined\n\t\t\t: (dependencyPaths as Record<string, PluginConfigValue>);\n\tconst stringDependencyPath = (key: string): string | undefined => {\n\t\tconst value = dependencyPathMap?.[key];\n\t\treturn typeof value === \"string\" ? value : undefined;\n\t};\n\tconst hostOnnxRuntimeEntryPath = stringDependencyPath(\"onnxruntimeNode\");\n\tconst hostLancedbEntryPath = stringDependencyPath(\"lancedb\");\n\tconst hostTransformersEntryPath = stringDependencyPath(\"transformers\");\n\tconst registrations = createMemoryCapability(api, {\n\t\tagentDir,\n\t\t...(hostOnnxRuntimeEntryPath === undefined ? {} : { hostOnnxRuntimeEntryPath }),\n\t\t...(hostLancedbEntryPath === undefined ? {} : { hostLancedbEntryPath }),\n\t\t...(hostTransformersEntryPath === undefined ? {} : { hostTransformersEntryPath }),\n\t\tmemory: {\n\t\t\tmode: resolution.mode,\n\t\t\t...(settingsMode.value === undefined ? {} : { settingsMode: settingsMode.value }),\n\t\t},\n\t\t...(memoryStorage === undefined ? {} : { storage: memoryStorage }),\n\t});\n\treturn {\n\t\tdispose: () => {\n\t\t\tfor (const registration of [...registrations].reverse()) {\n\t\t\t\t// Registration disposal in the capability runtime is synchronous;\n\t\t\t\t// void consumes the declared Promise possibility of the contract.\n\t\t\t\tvoid registration.dispose();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,12 @@ export * from "./memory/curation.ts";
|
|
|
25
25
|
export * from "./memory/egress-policy.ts";
|
|
26
26
|
export * from "./memory/embedding-provider.ts";
|
|
27
27
|
export * from "./memory/embedding-reranker.ts";
|
|
28
|
+
export { MODEL_MIN_WEIGHT_BYTES, missingHeavyDependencyModules, modelFilesCheck, RERANKER_MIN_WEIGHT_BYTES, remoteHostsForEnabling, VECTOR_PRESET_FULL, VECTOR_PRESET_LIGHT, vectorPresetForMode, } from "./memory/enabling.ts";
|
|
28
29
|
export * from "./memory/foundation.ts";
|
|
30
|
+
export * from "./memory/inference-client.ts";
|
|
31
|
+
export * from "./memory/inference-protocol.ts";
|
|
32
|
+
export * from "./memory/inference-server.ts";
|
|
33
|
+
export * from "./memory/inference-service-main.ts";
|
|
29
34
|
export * from "./memory/ledger.ts";
|
|
30
35
|
export * from "./memory/lifecycle.ts";
|
|
31
36
|
export * from "./memory/memory-network.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAG/C,OAAO,EACN,sBAAsB,EACtB,6BAA6B,EAC7B,eAAe,EACf,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC","sourcesContent":["/**\n * First-party memory capability plugin: the model-facing\n * memory_write / memory_recall / memory_list / memory_forget surface over the\n * M5 Memory Foundation, extracted from the host's embedded builtin capability\n * `agent-forge.builtin.memory` (D-075 S4, fourth batch).\n *\n * Library face (`createMemoryCapability(api, context, override?)`) keeps the\n * explicit-context signature for embedders and tests; the plugin entry\n * (`./entry.ts`, manifest-loaded) assembles the same context from the host\n * services (`api.host.agentDir` / `api.host.memoryStorage`) plus the\n * agent-dir config channel. The 29 Foundation/semantic modules and the\n * deterministic memory testkit migrate with the capability and are\n * re-exported here so consumers keep one import face. The memory public\n * contracts (canonical atom family, store/ledger/vector seams,\n * `MemoryStorageComponentsV1`, `MEMORY_RECALL_TOOL_NAME`) live in\n * `@agent-forge/plugin-sdk` and are re-exported through `./capability.ts`.\n */\n\nexport * from \"./capability.ts\";\nexport * from \"./memory/assistant-card.ts\";\nexport * from \"./memory/candidates.ts\";\nexport * from \"./memory/code-memory.ts\";\nexport * from \"./memory/compaction-sequencer.ts\";\nexport * from \"./memory/continuation.ts\";\nexport * from \"./memory/curation.ts\";\nexport * from \"./memory/egress-policy.ts\";\nexport * from \"./memory/embedding-provider.ts\";\nexport * from \"./memory/embedding-reranker.ts\";\n// 拆分战役 slice 1: enabling 模块的公共面仅为 capability.ts 原有导出的同名\n// 符号 (export * 会把仅供 capability 装配的内部前置检查 helper 泄入包面)。\nexport {\n\tMODEL_MIN_WEIGHT_BYTES,\n\tmissingHeavyDependencyModules,\n\tmodelFilesCheck,\n\tRERANKER_MIN_WEIGHT_BYTES,\n\tremoteHostsForEnabling,\n\tVECTOR_PRESET_FULL,\n\tVECTOR_PRESET_LIGHT,\n\tvectorPresetForMode,\n} from \"./memory/enabling.ts\";\nexport * from \"./memory/foundation.ts\";\nexport * from \"./memory/inference-client.ts\";\nexport * from \"./memory/inference-protocol.ts\";\nexport * from \"./memory/inference-server.ts\";\nexport * from \"./memory/inference-service-main.ts\";\nexport * from \"./memory/ledger.ts\";\nexport * from \"./memory/lifecycle.ts\";\nexport * from \"./memory/memory-network.ts\";\nexport * from \"./memory/preference-disambiguator.ts\";\nexport * from \"./memory/preference-lifecycle.ts\";\nexport * from \"./memory/preference-promotion.ts\";\nexport * from \"./memory/preference-resolver.ts\";\nexport * from \"./memory/purge.ts\";\nexport * from \"./memory/purge-journal.ts\";\nexport * from \"./memory/recall-agent.ts\";\nexport * from \"./memory/recall-index.ts\";\nexport * from \"./memory/recall-packet.ts\";\nexport * from \"./memory/scheduler.ts\";\nexport * from \"./memory/scheduler-api.ts\";\nexport * from \"./memory/store.ts\";\nexport * from \"./memory/suite-memory.ts\";\nexport * from \"./memory/transfer.ts\";\nexport * from \"./memory/vector-index.ts\";\nexport * from \"./memory/write-budget.ts\";\nexport * from \"./testing/memory-testkit.ts\";\n"]}
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,14 @@ export * from "./memory/curation.js";
|
|
|
25
25
|
export * from "./memory/egress-policy.js";
|
|
26
26
|
export * from "./memory/embedding-provider.js";
|
|
27
27
|
export * from "./memory/embedding-reranker.js";
|
|
28
|
+
// 拆分战役 slice 1: enabling 模块的公共面仅为 capability.ts 原有导出的同名
|
|
29
|
+
// 符号 (export * 会把仅供 capability 装配的内部前置检查 helper 泄入包面)。
|
|
30
|
+
export { MODEL_MIN_WEIGHT_BYTES, missingHeavyDependencyModules, modelFilesCheck, RERANKER_MIN_WEIGHT_BYTES, remoteHostsForEnabling, VECTOR_PRESET_FULL, VECTOR_PRESET_LIGHT, vectorPresetForMode, } from "./memory/enabling.js";
|
|
28
31
|
export * from "./memory/foundation.js";
|
|
32
|
+
export * from "./memory/inference-client.js";
|
|
33
|
+
export * from "./memory/inference-protocol.js";
|
|
34
|
+
export * from "./memory/inference-server.js";
|
|
35
|
+
export * from "./memory/inference-service-main.js";
|
|
29
36
|
export * from "./memory/ledger.js";
|
|
30
37
|
export * from "./memory/lifecycle.js";
|
|
31
38
|
export * from "./memory/memory-network.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC","sourcesContent":["/**\n * First-party memory capability plugin: the model-facing\n * memory_write / memory_recall / memory_list / memory_forget surface over the\n * M5 Memory Foundation, extracted from the host's embedded builtin capability\n * `agent-forge.builtin.memory` (D-075 S4, fourth batch).\n *\n * Library face (`createMemoryCapability(api, context, override?)`) keeps the\n * explicit-context signature for embedders and tests; the plugin entry\n * (`./entry.ts`, manifest-loaded) assembles the same context from the host\n * services (`api.host.agentDir` / `api.host.memoryStorage`) plus the\n * agent-dir config channel. The 29 Foundation/semantic modules and the\n * deterministic memory testkit migrate with the capability and are\n * re-exported here so consumers keep one import face. The memory public\n * contracts (canonical atom family, store/ledger/vector seams,\n * `MemoryStorageComponentsV1`, `MEMORY_RECALL_TOOL_NAME`) live in\n * `@agent-forge/plugin-sdk` and are re-exported through `./capability.ts`.\n */\n\nexport * from \"./capability.ts\";\nexport * from \"./memory/assistant-card.ts\";\nexport * from \"./memory/candidates.ts\";\nexport * from \"./memory/code-memory.ts\";\nexport * from \"./memory/compaction-sequencer.ts\";\nexport * from \"./memory/continuation.ts\";\nexport * from \"./memory/curation.ts\";\nexport * from \"./memory/egress-policy.ts\";\nexport * from \"./memory/embedding-provider.ts\";\nexport * from \"./memory/embedding-reranker.ts\";\nexport * from \"./memory/foundation.ts\";\nexport * from \"./memory/ledger.ts\";\nexport * from \"./memory/lifecycle.ts\";\nexport * from \"./memory/memory-network.ts\";\nexport * from \"./memory/preference-disambiguator.ts\";\nexport * from \"./memory/preference-lifecycle.ts\";\nexport * from \"./memory/preference-promotion.ts\";\nexport * from \"./memory/preference-resolver.ts\";\nexport * from \"./memory/purge.ts\";\nexport * from \"./memory/purge-journal.ts\";\nexport * from \"./memory/recall-agent.ts\";\nexport * from \"./memory/recall-index.ts\";\nexport * from \"./memory/recall-packet.ts\";\nexport * from \"./memory/scheduler.ts\";\nexport * from \"./memory/scheduler-api.ts\";\nexport * from \"./memory/store.ts\";\nexport * from \"./memory/suite-memory.ts\";\nexport * from \"./memory/transfer.ts\";\nexport * from \"./memory/vector-index.ts\";\nexport * from \"./memory/write-budget.ts\";\nexport * from \"./testing/memory-testkit.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,8FAAwD;AACxD,+FAAuD;AACvD,OAAO,EACN,sBAAsB,EACtB,6BAA6B,EAC7B,eAAe,EACf,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC","sourcesContent":["/**\n * First-party memory capability plugin: the model-facing\n * memory_write / memory_recall / memory_list / memory_forget surface over the\n * M5 Memory Foundation, extracted from the host's embedded builtin capability\n * `agent-forge.builtin.memory` (D-075 S4, fourth batch).\n *\n * Library face (`createMemoryCapability(api, context, override?)`) keeps the\n * explicit-context signature for embedders and tests; the plugin entry\n * (`./entry.ts`, manifest-loaded) assembles the same context from the host\n * services (`api.host.agentDir` / `api.host.memoryStorage`) plus the\n * agent-dir config channel. The 29 Foundation/semantic modules and the\n * deterministic memory testkit migrate with the capability and are\n * re-exported here so consumers keep one import face. The memory public\n * contracts (canonical atom family, store/ledger/vector seams,\n * `MemoryStorageComponentsV1`, `MEMORY_RECALL_TOOL_NAME`) live in\n * `@agent-forge/plugin-sdk` and are re-exported through `./capability.ts`.\n */\n\nexport * from \"./capability.ts\";\nexport * from \"./memory/assistant-card.ts\";\nexport * from \"./memory/candidates.ts\";\nexport * from \"./memory/code-memory.ts\";\nexport * from \"./memory/compaction-sequencer.ts\";\nexport * from \"./memory/continuation.ts\";\nexport * from \"./memory/curation.ts\";\nexport * from \"./memory/egress-policy.ts\";\nexport * from \"./memory/embedding-provider.ts\";\nexport * from \"./memory/embedding-reranker.ts\";\n// 拆分战役 slice 1: enabling 模块的公共面仅为 capability.ts 原有导出的同名\n// 符号 (export * 会把仅供 capability 装配的内部前置检查 helper 泄入包面)。\nexport {\n\tMODEL_MIN_WEIGHT_BYTES,\n\tmissingHeavyDependencyModules,\n\tmodelFilesCheck,\n\tRERANKER_MIN_WEIGHT_BYTES,\n\tremoteHostsForEnabling,\n\tVECTOR_PRESET_FULL,\n\tVECTOR_PRESET_LIGHT,\n\tvectorPresetForMode,\n} from \"./memory/enabling.ts\";\nexport * from \"./memory/foundation.ts\";\nexport * from \"./memory/inference-client.ts\";\nexport * from \"./memory/inference-protocol.ts\";\nexport * from \"./memory/inference-server.ts\";\nexport * from \"./memory/inference-service-main.ts\";\nexport * from \"./memory/ledger.ts\";\nexport * from \"./memory/lifecycle.ts\";\nexport * from \"./memory/memory-network.ts\";\nexport * from \"./memory/preference-disambiguator.ts\";\nexport * from \"./memory/preference-lifecycle.ts\";\nexport * from \"./memory/preference-promotion.ts\";\nexport * from \"./memory/preference-resolver.ts\";\nexport * from \"./memory/purge.ts\";\nexport * from \"./memory/purge-journal.ts\";\nexport * from \"./memory/recall-agent.ts\";\nexport * from \"./memory/recall-index.ts\";\nexport * from \"./memory/recall-packet.ts\";\nexport * from \"./memory/scheduler.ts\";\nexport * from \"./memory/scheduler-api.ts\";\nexport * from \"./memory/store.ts\";\nexport * from \"./memory/suite-memory.ts\";\nexport * from \"./memory/transfer.ts\";\nexport * from \"./memory/vector-index.ts\";\nexport * from \"./memory/write-budget.ts\";\nexport * from \"./testing/memory-testkit.ts\";\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-forge-memory-inference — 记忆共享推理服务进程入口 (记忆共享推理服务
|
|
3
|
+
* 设计 §3.1, Slice B1)。插件自带 bin: 宿主零改动, 能力实现与进程入口都在
|
|
4
|
+
* plugins/memory (架构宪法: 宿主提供机制, 能力在插件)。
|
|
5
|
+
*
|
|
6
|
+
* 拉起方 (B2 会话接线) 负责注入环境并保证拉起时机:
|
|
7
|
+
* - `AGENT_FORGE_MEMORY_AGENT_DIR` (必填): 记忆 ledger/模型缓存/向量库根;
|
|
8
|
+
* - `AGENT_FORGE_MEMORY_MODE` (可选): 档位覆盖 (缺省读 agent-dir 配置文件
|
|
9
|
+
* memorySettingsMode, 再缺省 light — 与会话装配同源);
|
|
10
|
+
* - `AGENT_FORGE_MEMORY_INFERENCE_PORT` (可选): 端口覆盖 (本入口读取并显式
|
|
11
|
+
* 传入服务 — 服务端本身不读 env, 非法值在此结构化失败)。
|
|
12
|
+
*
|
|
13
|
+
* 服务日志双写 (设计 §3.1/§7-6): stderr (手跑 bin 可见) +
|
|
14
|
+
* `<agentDir>/memory/inference-service.log` (会话懒拉起 stdio ignore 时
|
|
15
|
+
* stderr 不可达, 文件是唯一离线诊断入口; 启动时 >1MB 截断, 跨世代有界)。
|
|
16
|
+
*
|
|
17
|
+
* 本进程不做 consent 判定、永不自主下载模型 (runMemoryInferenceService 的
|
|
18
|
+
* 守门): 模型缺失即退出, 拉起方按服务不可用处理 (裁决 A)。
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=inference-bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-bin.d.ts","sourceRoot":"","sources":["../src/inference-bin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG","sourcesContent":["/**\n * agent-forge-memory-inference — 记忆共享推理服务进程入口 (记忆共享推理服务\n * 设计 §3.1, Slice B1)。插件自带 bin: 宿主零改动, 能力实现与进程入口都在\n * plugins/memory (架构宪法: 宿主提供机制, 能力在插件)。\n *\n * 拉起方 (B2 会话接线) 负责注入环境并保证拉起时机:\n * - `AGENT_FORGE_MEMORY_AGENT_DIR` (必填): 记忆 ledger/模型缓存/向量库根;\n * - `AGENT_FORGE_MEMORY_MODE` (可选): 档位覆盖 (缺省读 agent-dir 配置文件\n * memorySettingsMode, 再缺省 light — 与会话装配同源);\n * - `AGENT_FORGE_MEMORY_INFERENCE_PORT` (可选): 端口覆盖 (本入口读取并显式\n * 传入服务 — 服务端本身不读 env, 非法值在此结构化失败)。\n *\n * 服务日志双写 (设计 §3.1/§7-6): stderr (手跑 bin 可见) +\n * `<agentDir>/memory/inference-service.log` (会话懒拉起 stdio ignore 时\n * stderr 不可达, 文件是唯一离线诊断入口; 启动时 >1MB 截断, 跨世代有界)。\n *\n * 本进程不做 consent 判定、永不自主下载模型 (runMemoryInferenceService 的\n * 守门): 模型缺失即退出, 拉起方按服务不可用处理 (裁决 A)。\n */\n\nimport { appendFileSync, existsSync, mkdirSync, statSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { resolveMemoryServiceMode } from \"./entry.ts\";\nimport { resolveMemoryInferencePort } from \"./memory/inference-client.ts\";\nimport { runMemoryInferenceService } from \"./memory/inference-service-main.ts\";\n\n// 日志双写 (设计 §3.1/§7-6): 会话懒拉起经 stdio ignore, stderr 不可达 —\n// 服务生命周期与结构化失败必须落到文件才满足 §4「全部失败路径可观察」;\n// 手跑 bin 时 stderr 仍然可见。启动时超限截断, 文件跨服务世代有界。\nconst LOG_FILE_MAX_BYTES = 1_000_000;\n\nconst agentDir = process.env.AGENT_FORGE_MEMORY_AGENT_DIR;\nconst log = (line: string): void => {\n\tprocess.stderr.write(`${line}\\n`);\n\tif (agentDir === undefined) return;\n\ttry {\n\t\tappendFileSync(join(agentDir, \"memory\", \"inference-service.log\"), `${new Date().toISOString()} ${line}\\n`);\n\t} catch {\n\t\t// 日志落盘失败不反向阻断服务: stderr 已带出本行。\n\t}\n};\n\nif (agentDir === undefined || agentDir.trim() === \"\") {\n\tlog(\"memory-inference: AGENT_FORGE_MEMORY_AGENT_DIR is required (injected by the spawning session)\");\n\tprocess.exit(64);\n}\n\ntry {\n\tmkdirSync(join(agentDir, \"memory\"), { recursive: true });\n\tconst logFilePath = join(agentDir, \"memory\", \"inference-service.log\");\n\tif (existsSync(logFilePath) && statSync(logFilePath).size > LOG_FILE_MAX_BYTES) writeFileSync(logFilePath, \"\");\n} catch {\n\t// 截断/建目录失败不阻断启动: 附录失败只影响日志历史, 服务本体可运行。\n}\n\nconst resolution = resolveMemoryServiceMode(agentDir, process.env);\nif (\"error\" in resolution) {\n\tlog(`memory-inference: ${resolution.error}`);\n\tprocess.exit(1);\n}\n\nlet port: number;\ntry {\n\tport = resolveMemoryInferencePort(undefined, process.env);\n} catch (error) {\n\tlog(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);\n\tprocess.exit(1);\n}\n\nconst controller = new AbortController();\nprocess.on(\"SIGINT\", () => controller.abort());\nprocess.on(\"SIGTERM\", () => controller.abort());\n\ntry {\n\tconst server = await runMemoryInferenceService({\n\t\tagentDir,\n\t\tmode: resolution.mode,\n\t\tport,\n\t\tsignal: controller.signal,\n\t\tlog,\n\t});\n\tawait server.closed;\n\tprocess.exit(0);\n} catch (error) {\n\tlog(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);\n\tprocess.exit(1);\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-forge-memory-inference — 记忆共享推理服务进程入口 (记忆共享推理服务
|
|
3
|
+
* 设计 §3.1, Slice B1)。插件自带 bin: 宿主零改动, 能力实现与进程入口都在
|
|
4
|
+
* plugins/memory (架构宪法: 宿主提供机制, 能力在插件)。
|
|
5
|
+
*
|
|
6
|
+
* 拉起方 (B2 会话接线) 负责注入环境并保证拉起时机:
|
|
7
|
+
* - `AGENT_FORGE_MEMORY_AGENT_DIR` (必填): 记忆 ledger/模型缓存/向量库根;
|
|
8
|
+
* - `AGENT_FORGE_MEMORY_MODE` (可选): 档位覆盖 (缺省读 agent-dir 配置文件
|
|
9
|
+
* memorySettingsMode, 再缺省 light — 与会话装配同源);
|
|
10
|
+
* - `AGENT_FORGE_MEMORY_INFERENCE_PORT` (可选): 端口覆盖 (本入口读取并显式
|
|
11
|
+
* 传入服务 — 服务端本身不读 env, 非法值在此结构化失败)。
|
|
12
|
+
*
|
|
13
|
+
* 服务日志双写 (设计 §3.1/§7-6): stderr (手跑 bin 可见) +
|
|
14
|
+
* `<agentDir>/memory/inference-service.log` (会话懒拉起 stdio ignore 时
|
|
15
|
+
* stderr 不可达, 文件是唯一离线诊断入口; 启动时 >1MB 截断, 跨世代有界)。
|
|
16
|
+
*
|
|
17
|
+
* 本进程不做 consent 判定、永不自主下载模型 (runMemoryInferenceService 的
|
|
18
|
+
* 守门): 模型缺失即退出, 拉起方按服务不可用处理 (裁决 A)。
|
|
19
|
+
*/
|
|
20
|
+
import { appendFileSync, existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { resolveMemoryServiceMode } from "./entry.js";
|
|
23
|
+
import { resolveMemoryInferencePort } from "./memory/inference-client.js";
|
|
24
|
+
import { runMemoryInferenceService } from "./memory/inference-service-main.js";
|
|
25
|
+
// 日志双写 (设计 §3.1/§7-6): 会话懒拉起经 stdio ignore, stderr 不可达 —
|
|
26
|
+
// 服务生命周期与结构化失败必须落到文件才满足 §4「全部失败路径可观察」;
|
|
27
|
+
// 手跑 bin 时 stderr 仍然可见。启动时超限截断, 文件跨服务世代有界。
|
|
28
|
+
const LOG_FILE_MAX_BYTES = 1_000_000;
|
|
29
|
+
const agentDir = process.env.AGENT_FORGE_MEMORY_AGENT_DIR;
|
|
30
|
+
const log = (line) => {
|
|
31
|
+
process.stderr.write(`${line}\n`);
|
|
32
|
+
if (agentDir === undefined)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
appendFileSync(join(agentDir, "memory", "inference-service.log"), `${new Date().toISOString()} ${line}\n`);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// 日志落盘失败不反向阻断服务: stderr 已带出本行。
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (agentDir === undefined || agentDir.trim() === "") {
|
|
42
|
+
log("memory-inference: AGENT_FORGE_MEMORY_AGENT_DIR is required (injected by the spawning session)");
|
|
43
|
+
process.exit(64);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
mkdirSync(join(agentDir, "memory"), { recursive: true });
|
|
47
|
+
const logFilePath = join(agentDir, "memory", "inference-service.log");
|
|
48
|
+
if (existsSync(logFilePath) && statSync(logFilePath).size > LOG_FILE_MAX_BYTES)
|
|
49
|
+
writeFileSync(logFilePath, "");
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// 截断/建目录失败不阻断启动: 附录失败只影响日志历史, 服务本体可运行。
|
|
53
|
+
}
|
|
54
|
+
const resolution = resolveMemoryServiceMode(agentDir, process.env);
|
|
55
|
+
if ("error" in resolution) {
|
|
56
|
+
log(`memory-inference: ${resolution.error}`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
let port;
|
|
60
|
+
try {
|
|
61
|
+
port = resolveMemoryInferencePort(undefined, process.env);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
log(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
process.on("SIGINT", () => controller.abort());
|
|
69
|
+
process.on("SIGTERM", () => controller.abort());
|
|
70
|
+
try {
|
|
71
|
+
const server = await runMemoryInferenceService({
|
|
72
|
+
agentDir,
|
|
73
|
+
mode: resolution.mode,
|
|
74
|
+
port,
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
log,
|
|
77
|
+
});
|
|
78
|
+
await server.closed;
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
log(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=inference-bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-bin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,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,IAAI;QACJ,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,GAAG;KACH,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,MAAM,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IAChB,GAAG,CAAC,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC","sourcesContent":["/**\n * agent-forge-memory-inference — 记忆共享推理服务进程入口 (记忆共享推理服务\n * 设计 §3.1, Slice B1)。插件自带 bin: 宿主零改动, 能力实现与进程入口都在\n * plugins/memory (架构宪法: 宿主提供机制, 能力在插件)。\n *\n * 拉起方 (B2 会话接线) 负责注入环境并保证拉起时机:\n * - `AGENT_FORGE_MEMORY_AGENT_DIR` (必填): 记忆 ledger/模型缓存/向量库根;\n * - `AGENT_FORGE_MEMORY_MODE` (可选): 档位覆盖 (缺省读 agent-dir 配置文件\n * memorySettingsMode, 再缺省 light — 与会话装配同源);\n * - `AGENT_FORGE_MEMORY_INFERENCE_PORT` (可选): 端口覆盖 (本入口读取并显式\n * 传入服务 — 服务端本身不读 env, 非法值在此结构化失败)。\n *\n * 服务日志双写 (设计 §3.1/§7-6): stderr (手跑 bin 可见) +\n * `<agentDir>/memory/inference-service.log` (会话懒拉起 stdio ignore 时\n * stderr 不可达, 文件是唯一离线诊断入口; 启动时 >1MB 截断, 跨世代有界)。\n *\n * 本进程不做 consent 判定、永不自主下载模型 (runMemoryInferenceService 的\n * 守门): 模型缺失即退出, 拉起方按服务不可用处理 (裁决 A)。\n */\n\nimport { appendFileSync, existsSync, mkdirSync, statSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { resolveMemoryServiceMode } from \"./entry.ts\";\nimport { resolveMemoryInferencePort } from \"./memory/inference-client.ts\";\nimport { runMemoryInferenceService } from \"./memory/inference-service-main.ts\";\n\n// 日志双写 (设计 §3.1/§7-6): 会话懒拉起经 stdio ignore, stderr 不可达 —\n// 服务生命周期与结构化失败必须落到文件才满足 §4「全部失败路径可观察」;\n// 手跑 bin 时 stderr 仍然可见。启动时超限截断, 文件跨服务世代有界。\nconst LOG_FILE_MAX_BYTES = 1_000_000;\n\nconst agentDir = process.env.AGENT_FORGE_MEMORY_AGENT_DIR;\nconst log = (line: string): void => {\n\tprocess.stderr.write(`${line}\\n`);\n\tif (agentDir === undefined) return;\n\ttry {\n\t\tappendFileSync(join(agentDir, \"memory\", \"inference-service.log\"), `${new Date().toISOString()} ${line}\\n`);\n\t} catch {\n\t\t// 日志落盘失败不反向阻断服务: stderr 已带出本行。\n\t}\n};\n\nif (agentDir === undefined || agentDir.trim() === \"\") {\n\tlog(\"memory-inference: AGENT_FORGE_MEMORY_AGENT_DIR is required (injected by the spawning session)\");\n\tprocess.exit(64);\n}\n\ntry {\n\tmkdirSync(join(agentDir, \"memory\"), { recursive: true });\n\tconst logFilePath = join(agentDir, \"memory\", \"inference-service.log\");\n\tif (existsSync(logFilePath) && statSync(logFilePath).size > LOG_FILE_MAX_BYTES) writeFileSync(logFilePath, \"\");\n} catch {\n\t// 截断/建目录失败不阻断启动: 附录失败只影响日志历史, 服务本体可运行。\n}\n\nconst resolution = resolveMemoryServiceMode(agentDir, process.env);\nif (\"error\" in resolution) {\n\tlog(`memory-inference: ${resolution.error}`);\n\tprocess.exit(1);\n}\n\nlet port: number;\ntry {\n\tport = resolveMemoryInferencePort(undefined, process.env);\n} catch (error) {\n\tlog(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);\n\tprocess.exit(1);\n}\n\nconst controller = new AbortController();\nprocess.on(\"SIGINT\", () => controller.abort());\nprocess.on(\"SIGTERM\", () => controller.abort());\n\ntry {\n\tconst server = await runMemoryInferenceService({\n\t\tagentDir,\n\t\tmode: resolution.mode,\n\t\tport,\n\t\tsignal: controller.signal,\n\t\tlog,\n\t});\n\tawait server.closed;\n\tprocess.exit(0);\n} catch (error) {\n\tlog(`memory-inference: ${error instanceof Error ? error.message : String(error)}`);\n\tprocess.exit(1);\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命令面(capability 拆分战役 slice 6):memory_list / memory_forget 工具、
|
|
3
|
+
* /memory 与 /promote 命令、memory_enable 征询执行面与 memory.scheduler 能力
|
|
4
|
+
* 声明。物理删除的授权引用构造在本面(用户命令链专用); decline/download 仍
|
|
5
|
+
* 薄委托 vectorChannelCtl(slice 3b 先例, 经 deps 下的 channel 对象调用);
|
|
6
|
+
* 搬移函数体逐字节保留。
|
|
7
|
+
*/
|
|
8
|
+
import type { CapabilityAPI, DisposableRegistration } from "@agent-forge/plugin-sdk";
|
|
9
|
+
import type { DurableMemoryLedgerV1 } from "./ledger.ts";
|
|
10
|
+
import type { MemoryPurgeGateV1 } from "./purge.ts";
|
|
11
|
+
import type { MemoryPurgeJournalV1 } from "./purge-journal.ts";
|
|
12
|
+
import type { MemoryStoreV1 } from "./store.ts";
|
|
13
|
+
import { type SuiteMemoryDomainV1 } from "./suite-memory.ts";
|
|
14
|
+
import type { MemoryVectorChannelV1 } from "./vector-channel.ts";
|
|
15
|
+
import type { MemoryVectorProjectionV1 } from "./vector-projection.ts";
|
|
16
|
+
/**
|
|
17
|
+
* 命令面对 capability 闭包的显式依赖视图 (slice 6): 逐项来自
|
|
18
|
+
* createMemoryCapabilityHarness 的闭包捕获核实。状态机 (vectorChannelCtl)、
|
|
19
|
+
* 写侧投影 (vectorProjection) 与 purge 组件归 capability 装配所有, 本模块经
|
|
20
|
+
* 对象只读消费; capability 模块级纯函数经 deps 注入避免双头定义。
|
|
21
|
+
*/
|
|
22
|
+
export interface MemoryCommandFaceDepsV1 {
|
|
23
|
+
/** 工具注册面 (api.registerTool): memory_list/forget/enable 经同一公共通道注册。 */
|
|
24
|
+
readonly registerTool: CapabilityAPI["registerTool"];
|
|
25
|
+
/** 命令注册面 (api.registerCommand): /memory 与 /promote。 */
|
|
26
|
+
readonly registerCommand: CapabilityAPI["registerCommand"];
|
|
27
|
+
/** 事件发布面 (api.publish): memory.changed forgotten 事件。 */
|
|
28
|
+
readonly publish: CapabilityAPI["publish"];
|
|
29
|
+
/** 能力声明面 (api.capabilities): memory.scheduler@1 provide。 */
|
|
30
|
+
readonly capabilities: CapabilityAPI["capabilities"];
|
|
31
|
+
/** 检索行 owner (capability.BUILTIN_MEMORY_OWNER)。 */
|
|
32
|
+
readonly owner: string;
|
|
33
|
+
/** 会话 id (harness sessionId): forget 授权引用 confirmationRef 组成。 */
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
/** capability 清单 (capabilityManifest): issuedBy / authorizedBy / 事件 correlationId 来源。 */
|
|
36
|
+
readonly manifest: {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
};
|
|
39
|
+
/** agent 根目录 (MemoryCapabilityContext.agentDir): 档位持久化路径域。 */
|
|
40
|
+
readonly agentDir: string;
|
|
41
|
+
/** 已解析的全局档位 (harness memoryMode, off 已被工厂入口拦截)。 */
|
|
42
|
+
readonly memoryMode: "light" | "full";
|
|
43
|
+
/** 时钟 (harness now)。 */
|
|
44
|
+
readonly now: () => number;
|
|
45
|
+
/** canonical store (per-capability 单例): 列表/成员判定/晋升回查。 */
|
|
46
|
+
readonly store: MemoryStoreV1;
|
|
47
|
+
/** purge 门 (capability.purgeGate): 物理删除唯一生产入口的授权面。 */
|
|
48
|
+
readonly purgeGate: MemoryPurgeGateV1;
|
|
49
|
+
/** purge 日志 (capability.purgeJournal)。 */
|
|
50
|
+
readonly purgeJournal: MemoryPurgeJournalV1;
|
|
51
|
+
/** 写侧投影 (slice 3a 的 vectorProjection): forget 批次的 index 副本分派与晋升埋点。 */
|
|
52
|
+
readonly vectorProjection: MemoryVectorProjectionV1;
|
|
53
|
+
/** 向量通道 (slice 3b 的 vectorChannelCtl): 状态行与 decline/download 薄委托。 */
|
|
54
|
+
readonly vectorChannelCtl: MemoryVectorChannelV1;
|
|
55
|
+
/** 域解析 (capability.resolveDomain): 每次调用时惰性解析 (B1 语义)。 */
|
|
56
|
+
readonly resolveDomain: () => {
|
|
57
|
+
readonly domain: SuiteMemoryDomainV1;
|
|
58
|
+
readonly domainName: string;
|
|
59
|
+
readonly ledger: DurableMemoryLedgerV1;
|
|
60
|
+
};
|
|
61
|
+
readonly assertNonEmptyString: (value: unknown, label: string) => asserts value is string;
|
|
62
|
+
readonly memoryToolInput: (first: unknown, second: unknown) => Record<string, unknown>;
|
|
63
|
+
readonly statementOf: (payload: unknown) => string;
|
|
64
|
+
readonly unwrapEgressStatement: (statement: string) => string;
|
|
65
|
+
/** 升档声明只读视图 (/memory 状态行 pending 尾巴)。 */
|
|
66
|
+
readonly tierUpgradePending: () => boolean;
|
|
67
|
+
/** 用户显式档位表达取代本实例升档声明 (/memory light)。 */
|
|
68
|
+
readonly clearTierUpgrade: () => void;
|
|
69
|
+
}
|
|
70
|
+
/** 命令面工厂产物: 注册项集合 (capability registrations 按既有顺序收集)。 */
|
|
71
|
+
export interface MemoryCommandFaceV1 {
|
|
72
|
+
/** memory_list 工具注册项。 */
|
|
73
|
+
readonly listTool: DisposableRegistration;
|
|
74
|
+
/** memory_forget 工具注册项 (仅登记请求, 物理删除在 /memory forget)。 */
|
|
75
|
+
readonly forgetTool: DisposableRegistration;
|
|
76
|
+
/** memory_enable 工具注册项 (征询门执行面)。 */
|
|
77
|
+
readonly enableTool: DisposableRegistration;
|
|
78
|
+
/** /memory 命令注册项。 */
|
|
79
|
+
readonly memoryCommand: DisposableRegistration;
|
|
80
|
+
/** /promote 命令注册项。 */
|
|
81
|
+
readonly promoteCommand: DisposableRegistration;
|
|
82
|
+
/** memory.scheduler@1 plugin capability 声明注册项。 */
|
|
83
|
+
readonly schedulerCapability: DisposableRegistration;
|
|
84
|
+
}
|
|
85
|
+
export declare function createMemoryCommandFace(deps: MemoryCommandFaceDepsV1): MemoryCommandFaceV1;
|
|
86
|
+
//# sourceMappingURL=command-face.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-face.d.ts","sourceRoot":"","sources":["../../src/memory/command-face.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAIN,KAAK,mBAAmB,EAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AA2BvE;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACvC,mGAAqE;IACrE,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACrD,qEAAuD;IACvD,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC3D,wEAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC3C,wEAA4D;IAC5D,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACrD,2DAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mFAAiE;IACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uGAAyF;IACzF,QAAQ,CAAC,Q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AO,CAAC;IAC3C,6EAAyC;IACzC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC;CACtC;AAED,iGAAyD;AACzD,MAAM,WAAW,mBAAmB;IACnC,qCAAyB;IACzB,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAC1C,yFAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC;IAC5C,4DAAoC;IACpC,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC;IAC5C,iCAAqB;IACrB,QAAQ,CAAC,aAAa,EAAE,sBAAsB,CAAC;IAC/C,kCAAsB;IACtB,QAAQ,CAAC,cAAc,EAAE,sBAAsB,CAAC;IAChD,8DAAkD;IAClD,QAAQ,CAAC,mBAAmB,EAAE,sBAAsB,CAAC;CACrD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,uBAAuB,GAAG,mBAAmB,CA6Y1F","sourcesContent":["/**\n * 命令面(capability 拆分战役 slice 6):memory_list / memory_forget 工具、\n * /memory 与 /promote 命令、memory_enable 征询执行面与 memory.scheduler 能力\n * 声明。物理删除的授权引用构造在本面(用户命令链专用); decline/download 仍\n * 薄委托 vectorChannelCtl(slice 3b 先例, 经 deps 下的 channel 对象调用);\n * 搬移函数体逐字节保留。\n */\nimport type { CapabilityAPI, DisposableRegistration } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\nimport { writeMemorySettingsMode } from \"./enabling.ts\";\nimport type { DurableMemoryLedgerV1 } from \"./ledger.ts\";\nimport { promotePreferenceToUserDefault } from \"./preference-promotion.ts\";\nimport type { MemoryPurgeGateV1 } from \"./purge.ts\";\nimport type { MemoryPurgeJournalV1 } from \"./purge-journal.ts\";\nimport type { MemoryStoreV1 } from \"./store.ts\";\nimport {\n\tforgetDomainMemory,\n\tlistDomainMemories,\n\ttype SuiteForgetAuthorizationRefV1,\n\ttype SuiteMemoryDomainV1,\n\ttype SuiteMemoryListEntryV1,\n} from \"./suite-memory.ts\";\nimport type { MemoryVectorChannelV1 } from \"./vector-channel.ts\";\nimport type { MemoryVectorProjectionV1 } from \"./vector-projection.ts\";\nimport { EVENT_TYPE } from \"./write-face.ts\";\n\nconst DEFAULT_LIST_LIMIT = 20;\n\nconst listSchema = Type.Object({\n\tlimit: Type.Optional(\n\t\tType.Integer({ description: \"Maximum number of entries to list (1-100)\", minimum: 1, maximum: 100 }),\n\t),\n});\n\nconst forgetSchema = Type.Object({\n\tmemoryId: Type.String({\n\t\tdescription: \"The memoryId of the memory to forget, as returned by memory_write or memory_list\",\n\t}),\n});\n\nconst enableSchema = Type.Object({\n\taction: Type.Union([Type.Literal(\"download\"), Type.Literal(\"decline\"), Type.Literal(\"retry\")], {\n\t\tdescription:\n\t\t\t'\"download\" / \"retry\" run the one-time model download (retry re-runs after a failure); \"decline\" persists memory off for this machine',\n\t}),\n});\n\n/** Canonical memoryId of the promoted copy of one preference (promotePreferenceToUserDefault suffix). */\nconst userDefaultMemoryId = (memoryId: string): string => `${memoryId}-user-default`;\n\n/**\n * 命令面对 capability 闭包的显式依赖视图 (slice 6): 逐项来自\n * createMemoryCapabilityHarness 的闭包捕获核实。状态机 (vectorChannelCtl)、\n * 写侧投影 (vectorProjection) 与 purge 组件归 capability 装配所有, 本模块经\n * 对象只读消费; capability 模块级纯函数经 deps 注入避免双头定义。\n */\nexport interface MemoryCommandFaceDepsV1 {\n\t/** 工具注册面 (api.registerTool): memory_list/forget/enable 经同一公共通道注册。 */\n\treadonly registerTool: CapabilityAPI[\"registerTool\"];\n\t/** 命令注册面 (api.registerCommand): /memory 与 /promote。 */\n\treadonly registerCommand: CapabilityAPI[\"registerCommand\"];\n\t/** 事件发布面 (api.publish): memory.changed forgotten 事件。 */\n\treadonly publish: CapabilityAPI[\"publish\"];\n\t/** 能力声明面 (api.capabilities): memory.scheduler@1 provide。 */\n\treadonly capabilities: CapabilityAPI[\"capabilities\"];\n\t/** 检索行 owner (capability.BUILTIN_MEMORY_OWNER)。 */\n\treadonly owner: string;\n\t/** 会话 id (harness sessionId): forget 授权引用 confirmationRef 组成。 */\n\treadonly sessionId: string;\n\t/** capability 清单 (capabilityManifest): issuedBy / authorizedBy / 事件 correlationId 来源。 */\n\treadonly manifest: { readonly id: string };\n\t/** agent 根目录 (MemoryCapabilityContext.agentDir): 档位持久化路径域。 */\n\treadonly agentDir: string;\n\t/** 已解析的全局档位 (harness memoryMode, off 已被工厂入口拦截)。 */\n\treadonly memoryMode: \"light\" | \"full\";\n\t/** 时钟 (harness now)。 */\n\treadonly now: () => number;\n\t/** canonical store (per-capability 单例): 列表/成员判定/晋升回查。 */\n\treadonly store: MemoryStoreV1;\n\t/** purge 门 (capability.purgeGate): 物理删除唯一生产入口的授权面。 */\n\treadonly purgeGate: MemoryPurgeGateV1;\n\t/** purge 日志 (capability.purgeJournal)。 */\n\treadonly purgeJournal: MemoryPurgeJournalV1;\n\t/** 写侧投影 (slice 3a 的 vectorProjection): forget 批次的 index 副本分派与晋升埋点。 */\n\treadonly vectorProjection: MemoryVectorProjectionV1;\n\t/** 向量通道 (slice 3b 的 vectorChannelCtl): 状态行与 decline/download 薄委托。 */\n\treadonly vectorChannelCtl: MemoryVectorChannelV1;\n\t/** 域解析 (capability.resolveDomain): 每次调用时惰性解析 (B1 语义)。 */\n\treadonly resolveDomain: () => {\n\t\treadonly domain: SuiteMemoryDomainV1;\n\t\treadonly domainName: string;\n\t\treadonly ledger: DurableMemoryLedgerV1;\n\t};\n\t// ---- capability 模块级纯函数 (留守方, 经 deps 注入避免双头定义) ----\n\treadonly assertNonEmptyString: (value: unknown, label: string) => asserts value is string;\n\treadonly memoryToolInput: (first: unknown, second: unknown) => Record<string, unknown>;\n\treadonly statementOf: (payload: unknown) => string;\n\treadonly unwrapEgressStatement: (statement: string) => string;\n\t// ---- 写入面闭包视图 (slice 5 的 writeFace): 升档声明状态归 write-face 所有 ----\n\t/** 升档声明只读视图 (/memory 状态行 pending 尾巴)。 */\n\treadonly tierUpgradePending: () => boolean;\n\t/** 用户显式档位表达取代本实例升档声明 (/memory light)。 */\n\treadonly clearTierUpgrade: () => void;\n}\n\n/** 命令面工厂产物: 注册项集合 (capability registrations 按既有顺序收集)。 */\nexport interface MemoryCommandFaceV1 {\n\t/** memory_list 工具注册项。 */\n\treadonly listTool: DisposableRegistration;\n\t/** memory_forget 工具注册项 (仅登记请求, 物理删除在 /memory forget)。 */\n\treadonly forgetTool: DisposableRegistration;\n\t/** memory_enable 工具注册项 (征询门执行面)。 */\n\treadonly enableTool: DisposableRegistration;\n\t/** /memory 命令注册项。 */\n\treadonly memoryCommand: DisposableRegistration;\n\t/** /promote 命令注册项。 */\n\treadonly promoteCommand: DisposableRegistration;\n\t/** memory.scheduler@1 plugin capability 声明注册项。 */\n\treadonly schedulerCapability: DisposableRegistration;\n}\n\nexport function createMemoryCommandFace(deps: MemoryCommandFaceDepsV1): MemoryCommandFaceV1 {\n\tconst {\n\t\tregisterTool,\n\t\tregisterCommand,\n\t\tpublish,\n\t\tcapabilities,\n\t\towner,\n\t\tsessionId,\n\t\tagentDir,\n\t\tmemoryMode,\n\t\tnow,\n\t\tstore,\n\t\tpurgeGate,\n\t\tpurgeJournal,\n\t\tvectorProjection,\n\t\tvectorChannelCtl,\n\t\tresolveDomain,\n\t\tmemoryToolInput,\n\t\tstatementOf,\n\t\tunwrapEgressStatement,\n\t\ttierUpgradePending,\n\t\tclearTierUpgrade,\n\t} = deps;\n\tconst { manifest: capabilityManifest } = deps;\n\n\t/** Recency-first payload projection: unwraps the `{ statement }` payload convention. */\n\tfunction entryToToolEntry(entry: SuiteMemoryListEntryV1): Record<string, unknown> {\n\t\treturn {\n\t\t\tmemoryId: entry.memoryId,\n\t\t\tkind: entry.memoryKind,\n\t\t\tstatement: statementOf(entry.payload),\n\t\t\toccurredAt: entry.occurredAt,\n\t\t\t...(entry.preference === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tpreference: {\n\t\t\t\t\t\t\tsubject: entry.preference.subject,\n\t\t\t\t\t\t\tkey: entry.preference.key,\n\t\t\t\t\t\t\tscopeLevel: entry.preference.scopeLevel,\n\t\t\t\t\t\t\tcrossSuiteVisible: entry.preference.crossSuiteVisible,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t};\n\t}\n\n\tconst listTool = registerTool({\n\t\tname: \"memory_list\",\n\t\tlabel: \"List memories\",\n\t\tdescription: \"List this suite's durable memories (the explicit management surface for personal data)\",\n\t\tparameters: listSchema,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\tconst input = memoryToolInput(first, second);\n\t\t\tconst rawLimit: unknown = input.limit;\n\t\t\tconst limit =\n\t\t\t\trawLimit === undefined\n\t\t\t\t\t? DEFAULT_LIST_LIMIT\n\t\t\t\t\t: ((): number => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\ttypeof rawLimit !== \"number\" ||\n\t\t\t\t\t\t\t\t!Number.isSafeInteger(rawLimit) ||\n\t\t\t\t\t\t\t\trawLimit < 1 ||\n\t\t\t\t\t\t\t\trawLimit > 100\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthrow new Error(\"limit must be an integer between 1 and 100\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn rawLimit;\n\t\t\t\t\t\t})();\n\t\t\tconst { domain } = resolveDomain();\n\t\t\tconst page = listDomainMemories({ store }, { owner, domain });\n\t\t\treturn {\n\t\t\t\tdomain: page.domain,\n\t\t\t\tentries: page.entries.slice(0, limit).map(entryToToolEntry),\n\t\t\t\ttotal: page.entries.length,\n\t\t\t\tpreferenceCount: page.preferenceCount,\n\t\t\t\tfactCount: page.factCount,\n\t\t\t\tfilter: page.filter,\n\t\t\t};\n\t\t},\n\t});\n\n\t/**\n\t * 物理删除唯一生产入口 (诚实化设计 §2, 2026-10-05 裁决): 用户命令链\n\t * `/memory forget <id> confirm`。授权引用由命令分发构造 (structured\n\t * confirmationRef `memory-forget-command:<session>:<memoryId>:confirmed`),\n\t * 模型工具面不再签发 user-immediate 授权 (记忆系统设计 :997 — 授权不能由\n\t * 模型生成)。\n\t */\n\tconst purgeMemoryViaUserCommand = (memoryId: string) => {\n\t\tconst { domain, ledger } = resolveDomain();\n\t\tconst authorizationRef: SuiteForgetAuthorizationRefV1 = {\n\t\t\tmode: \"user-immediate\",\n\t\t\tissuedAt: now(),\n\t\t\tissuedBy: `${capabilityManifest.id}:/memory-forget-confirm`,\n\t\t\tconfirmationRef: `memory-forget-command:${sessionId}:${memoryId}:confirmed`,\n\t\t};\n\t\treturn forgetDomainMemory(\n\t\t\t{\n\t\t\t\tstore,\n\t\t\t\tpurgeGate,\n\t\t\t\tpurgeJournal,\n\t\t\t\t// index 副本分派 (混合检索工程化): canonical 走下方原回调, 向量投影由\n\t\t\t\t// suite-memory 的 executePurgeBatch 按副本路由到这里。\n\t\t\t\tpurgeIndexReplica: vectorProjection.purgeMemories,\n\t\t\t\tnow,\n\t\t\t},\n\t\t\t{\n\t\t\t\towner,\n\t\t\t\tdomain,\n\t\t\t\tmemoryId,\n\t\t\t\tauthorizedBy: `${capabilityManifest.id}:memory-forget-command`,\n\t\t\t\tauthorizationRef,\n\t\t\t},\n\t\t\t(memoryIds) => {\n\t\t\t\tconst purged = new Set(memoryIds);\n\t\t\t\t// Physical replica purge: rewrite the durable ledger without the\n\t\t\t\t// purged atoms, then evict them from the in-memory store so the\n\t\t\t\t// running process cannot recall them either (both idempotent for\n\t\t\t\t// purge_eligible retries).\n\t\t\t\tledger.rewrite(ledger.atomsSnapshot().filter((atom) => !purged.has(atom.memoryId)));\n\t\t\t\tfor (const id of memoryIds) store.evict(id);\n\t\t\t},\n\t\t);\n\t};\n\n\tconst forgetTool = registerTool({\n\t\tname: \"memory_forget\",\n\t\tlabel: \"File a forget request\",\n\t\tdescription:\n\t\t\t\"File a request to forget one memory of this suite by memoryId. This tool never deletes anything — physical deletion is user-only: the user confirms via /memory forget <memoryId> confirm\",\n\t\tparameters: forgetSchema,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\tconst input = memoryToolInput(first, second);\n\t\t\tdeps.assertNonEmptyString(input.memoryId, \"memoryId\");\n\t\t\tconst { domain, domainName } = resolveDomain();\n\t\t\tconst unscoped = store.get(input.memoryId, { owner });\n\t\t\tif (unscoped === undefined) {\n\t\t\t\treturn { status: \"not_found\" as const, memoryId: input.memoryId };\n\t\t\t}\n\t\t\t// 域成员判定与 forgetDomainMemory 同判据 (suiteId 匹配 / legacy 为\n\t\t\t// undefined): 请求面同样拒绝外域 id — 模型连\"请求遗忘\"都不能指向别的域。\n\t\t\tconst isMember =\n\t\t\t\tdomain.kind === \"suite\" ? unscoped.atom.suiteId === domain.suiteId : unscoped.atom.suiteId === undefined;\n\t\t\tif (!isMember) {\n\t\t\t\treturn { status: \"foreign_domain\" as const, memoryId: input.memoryId };\n\t\t\t}\n\t\t\t// 请求的登记价值由返回文本承载 (转告用户确认命令); 无进程内状态 —\n\t\t\t// 重复请求幂等 (同一提示再次返回)。\n\t\t\treturn {\n\t\t\t\tstatus: \"requested\" as const,\n\t\t\t\tmemoryId: input.memoryId,\n\t\t\t\trequest:\n\t\t\t\t\t`Forget request filed for \"${unwrapEgressStatement(statementOf(unscoped.atom.payload))}\" in domain ${domainName}. ` +\n\t\t\t\t\t`Nothing is deleted yet — tell the user to confirm the deletion with: /memory forget ${input.memoryId} confirm`,\n\t\t\t};\n\t\t},\n\t});\n\n\t/**\n\t * /promote (偏好晋升触发, B2; 2026-10-05 诚实化裁决起两步确认): the production\n\t * caller of {@link promotePreferenceToUserDefault}. Promotes one of THIS\n\t * session's preferences to the user-default scope: the promoted canonical atom\n\t * is appended to the session domain's durable ledger and committed to the\n\t * store, so every suite's preference-card read (which applies the suite read\n\t * boundary across all of the owner's ledgers) sees it from now on. The\n\t * original atom is never rewritten. Promotion is an irreversible cross-suite\n\t * authorization face, so the first run only shows the target and asks the\n\t * user to re-run with `confirm`. Errors (unknown id, non-preference, already\n\t * promoted) surface as error results, never as thrown failures — a slash\n\t * command must not crash the host.\n\t */\n\tconst promoteCommand = registerCommand({\n\t\tname: \"promote\",\n\t\tdescription:\n\t\t\t\"Promote a memory preference to the user-default scope (visible in every suite; two-step — re-run with confirm)\",\n\t\targumentHint: \"<memoryId> [confirm]\",\n\t\texecute: async (args: string) => {\n\t\t\tconst tokens = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\tconst memoryId = tokens[0] ?? \"\";\n\t\t\tconst confirmed = tokens[1] === \"confirm\";\n\t\t\tif (memoryId === \"\" || tokens.length > 2 || (tokens[1] !== undefined && !confirmed)) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\tmessage: \"Usage: /promote <memoryId> [confirm] — run memory_list for this suite's memory ids\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst record = store.get(memoryId, { owner });\n\t\t\tif (!record) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\tmessage: `No memory found with id ${memoryId}; run memory_list for this suite's memory ids`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst atom = record.atom;\n\t\t\tif (atom.memoryKind !== \"preference\" || atom.preference === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\tmessage: `${memoryId} is a fact, not a preference; only preferences can be promoted`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (store.get(userDefaultMemoryId(memoryId), { owner }) !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\tmessage: `Preference ${memoryId} is already promoted to the user-default scope`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!confirmed) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"success\" as const,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Promotion target: \"${unwrapEgressStatement(statementOf(atom.payload))}\"\\n` +\n\t\t\t\t\t\t\"This makes the preference visible in EVERY suite (user-default scope, permanent). Nothing is promoted yet — re-run to confirm:\\n\" +\n\t\t\t\t\t\t`/promote ${memoryId} confirm`,\n\t\t\t\t};\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst promoted = promotePreferenceToUserDefault({\n\t\t\t\t\tatom,\n\t\t\t\t\tauthorizedBy: \"user:/promote\",\n\t\t\t\t\tconfirmedAt: new Date(now()).toISOString(),\n\t\t\t\t});\n\t\t\t\tconst { domainName, ledger } = resolveDomain();\n\t\t\t\tledger.append(promoted);\n\t\t\t\tstore.commit(promoted);\n\t\t\t\t// 向量投影埋点: 与 memory_write 同一异步旁路 (失败不阻塞命令返回)。\n\t\t\t\tvectorProjection.upsertAtom(promoted);\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"success\" as const,\n\t\t\t\t\tmessage: `Promoted \"${unwrapEgressStatement(statementOf(promoted.payload))}\" to the user-default scope; it is now visible in every suite`,\n\t\t\t\t\tdata: { memoryId: promoted.memoryId, sourceMemoryId: memoryId, domain: domainName },\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\treturn { status: \"error\" as const, message: error instanceof Error ? error.message : String(error) };\n\t\t\t}\n\t\t},\n\t});\n\n\t// memory.scheduler@1 plugin capability (宪法 §3 显式声明面): a declarative\n\t// marker only — the scheduler enforcement itself (per-instance single\n\t// lease, acquired above) stays carried by the host builtin implementation.\n\t// The declaration anchors \"this suite's memory scheduling is provided by\n\t// this plugin\" so the code Profile assembly check (requiresMemoryScheduler)\n\t// and third-party replacement detection have an explicit surface:\n\t// list()-visible, a same-id double provide fails explicitly (no override\n\t// priority), and after dispose a replacement provider can take the id.\n\tconst schedulerCapability = capabilities.provide({ id: \"memory.scheduler\", version: 1, kind: \"service\" }, () =>\n\t\tObject.freeze({\n\t\t\tid: \"memory.scheduler\",\n\t\t\tversion: 1,\n\t\t\towner: \"agent-forge.builtin.memory\",\n\t\t\tleaseScope: \"per-agent-instance\",\n\t\t}),\n\t);\n\n\t// ---- 征询门执行面 (2026-10-05 用户裁决「首次使用征询、拒绝/失败可跳过」) ----\n\t// memory_enable 是 consent-required / failed 态的唯一下载入口: consentGranted\n\t// 只在这里置位, recall/auto-recall 永不触发下载。decline 同时持久化\n\t// (writeMemoryConsentDeclined), 只抑制默认档——用户显式设置 memory.mode 后\n\t// 下次启用会在首次使用时再次走到征询门。\n\t// ---- 记忆模型下载控制面 (2026-10-05 流程裁决「后台预热、不阻塞提问」) ----\n\t// 生产入口 (交互模式会话绑定后) 经公共工具面调用 memory_enable download\n\t// 触发后台预热; 命令面 /memory off|retry 是用户的直接出口。decline/download\n\t// 核心在 memory/vector-channel.ts (slice 3b), 工具与命令面经\n\t// vectorChannelCtl.decline()/download() 薄委托; decline 持久化只抑制默认档。\n\tconst memoryStatusLine = (): string => {\n\t\t// pending 尾巴只对仍有效的升档声明 (declined 分支里档位键已被删除, 显示\n\t\t// pending 会失实 — 2026-10-06 复审 P2-1)。\n\t\tconst declined = vectorChannelCtl.declined();\n\t\tconst pendingUpgrade = tierUpgradePending() && !declined;\n\t\tconst modeLine = `mode=${memoryMode}${pendingUpgrade ? \", auto-upgrade to full pending (next session)\" : \"\"}`;\n\t\tif (declined) {\n\t\t\treturn `${modeLine}, off (declined on this machine). Set memory.mode (light|full) in settings.json and restart the session to re-enable`;\n\t\t}\n\t\tconst channelState = vectorChannelCtl.rawState();\n\t\tif (channelState === \"ready\") return `${modeLine}, ready`;\n\t\tif (channelState === \"degraded\") return `${modeLine}, ready (degraded)`;\n\t\tif (channelState === \"failed\")\n\t\t\treturn `${modeLine}, failed: ${vectorChannelCtl.failure()?.reason ?? \"unknown reason\"}`;\n\t\tif (channelState === \"consent-required\")\n\t\t\treturn `${modeLine}, waiting for the model download decision (/memory retry to start it)`;\n\t\treturn `${modeLine}, loading models in the background`;\n\t};\n\tconst enableTool = registerTool({\n\t\tname: \"memory_enable\",\n\t\tlabel: \"Enable memory\",\n\t\tdescription:\n\t\t\t'Run or decline the one-time memory model download. The host starts it in the background at session start; call it with \"retry\" after a failure, or with \"decline\" when the user chooses to keep memory off',\n\t\tparameters: enableSchema,\n\t\texecute: async (first: unknown, second?: unknown) => {\n\t\t\tconst input = memoryToolInput(first, second);\n\t\t\tconst action: unknown = input.action;\n\t\t\tif (action !== \"download\" && action !== \"decline\" && action !== \"retry\") {\n\t\t\t\tthrow new Error('action must be \"download\", \"decline\", or \"retry\"');\n\t\t\t}\n\t\t\tif (action === \"decline\") return vectorChannelCtl.decline();\n\t\t\treturn vectorChannelCtl.download();\n\t\t},\n\t});\n\tconst memoryCommand = registerCommand({\n\t\tname: \"memory\",\n\t\tdescription:\n\t\t\t\"Memory controls: bare shows status; light|full switches the model preset (persisted, effective next session); off persists disable; retry re-runs the model download; forget <memoryId> [confirm] is the user-only physical delete (two-step)\",\n\t\targumentHint: \"[light|full|off|retry|forget <memoryId> [confirm]]\",\n\t\texecute: async (args: string) => {\n\t\t\tconst tokens = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\tif (tokens[0] === \"forget\") {\n\t\t\t\tconst memoryId = tokens[1] ?? \"\";\n\t\t\t\tconst confirmed = tokens[2] === \"confirm\";\n\t\t\t\tif (memoryId === \"\" || tokens.length > 3 || (tokens[2] !== undefined && !confirmed)) {\n\t\t\t\t\treturn { status: \"error\" as const, message: \"Usage: /memory forget <memoryId> [confirm]\" };\n\t\t\t\t}\n\t\t\t\tconst { domain, domainName } = resolveDomain();\n\t\t\t\tconst unscoped = store.get(memoryId, { owner });\n\t\t\t\tif (unscoped === undefined) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\t\tmessage: `No memory found with id ${memoryId}; run memory_list for this suite's memory ids`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst isMember =\n\t\t\t\t\tdomain.kind === \"suite\" ? unscoped.atom.suiteId === domain.suiteId : unscoped.atom.suiteId === undefined;\n\t\t\t\tif (!isMember) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"error\" as const,\n\t\t\t\t\t\tmessage: `${memoryId} belongs to another suite; each suite forgets only its own memories`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (!confirmed) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"success\" as const,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Forget target: \"${unwrapEgressStatement(statementOf(unscoped.atom.payload))}\"\\n` +\n\t\t\t\t\t\t\t\"This permanently deletes the memory (irreversible, purge-gated). Nothing is deleted yet — re-run to confirm:\\n\" +\n\t\t\t\t\t\t\t`/memory forget ${memoryId} confirm`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst result = purgeMemoryViaUserCommand(memoryId);\n\t\t\t\tif (result.status === \"completed\") {\n\t\t\t\t\tawait publish({\n\t\t\t\t\t\ttype: EVENT_TYPE,\n\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\tcorrelationId: capabilityManifest.id,\n\t\t\t\t\t\tdata: { action: \"forgotten\", memoryId, domain: domainName, batchId: result.batchId },\n\t\t\t\t\t});\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"success\" as const,\n\t\t\t\t\t\tmessage: `Forgot ${memoryId} (${domainName}): the memory is physically deleted`,\n\t\t\t\t\t\tdata: { memoryId, domain: domainName, batchId: result.batchId },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn { status: \"error\" as const, message: `forget failed: ${result.status}` };\n\t\t\t}\n\t\t\tconst sub = args.trim().toLowerCase();\n\t\t\tif (sub === \"\" || sub === \"status\") {\n\t\t\t\treturn { status: \"success\" as const, message: `memory: ${memoryStatusLine()}` };\n\t\t\t}\n\t\t\tif (sub === \"light\" || sub === \"full\") {\n\t\t\t\t// 无\"已是该档\"早退: 持久化档位与会话内已解析档位是两回事——会话可能\n\t\t\t\t// 因默认档而运行 light, 用户降档仍需把持久化值落盘 (或覆盖旧档)。\n\t\t\t\twriteMemorySettingsMode(agentDir, sub);\n\t\t\t\t// 升/降档清了文件里的拒绝标记, 内存标记同步翻回: 用户最新的显式\n\t\t\t\t// 意图是启用——本会话恢复对当前预置的响应 (retry 可用), 新档与\n\t\t\t\t// 新模型下载在下一会话生效。\n\t\t\t\tvectorChannelCtl.clearDeclined();\n\t\t\t\t// 用户的显式档位表达取代本实例的自动升档声明: 降回 light 后 pending\n\t\t\t\t// 尾巴不再显示, 且显式 light 会让自动升档在后续写入中跳过 (复审 P2-1)。\n\t\t\t\tif (sub === \"light\") clearTierUpgrade();\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"success\" as const,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`memory: preset ${sub} persisted (capabilities/builtin.memory.json). It takes effect next session — ` +\n\t\t\t\t\t\t(sub === \"full\"\n\t\t\t\t\t\t\t? \"the larger embedding model (bge-m3, hundreds of MB) downloads in the background at the next start, disk headroom ≥2GB, and write-side semantic dedup turns on. \"\n\t\t\t\t\t\t\t: \"\") +\n\t\t\t\t\t\t\"Existing memories carry over: the projection rebuilds onto the new model automatically.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\t// 命令面结果映射: 工具闭包的 completed/failed 面转 CapabilityCommandResult\n\t\t\t// 的 success/error; 行动清单/next 指引并入 message (命令结果无 actions 字段)。\n\t\t\tconst toCommandResult = (\n\t\t\t\tresult: Awaited<ReturnType<typeof vectorChannelCtl.download>>,\n\t\t\t): { status: \"success\" | \"error\"; message: string } => ({\n\t\t\t\tstatus: result.status === \"completed\" ? \"success\" : \"error\",\n\t\t\t\tmessage:\n\t\t\t\t\tresult.status === \"failed\"\n\t\t\t\t\t\t? [result.message, ...(result.actions ?? []), result.next].filter(Boolean).join(\" — \")\n\t\t\t\t\t\t: result.message,\n\t\t\t});\n\t\t\tif (sub === \"off\") return toCommandResult(vectorChannelCtl.decline());\n\t\t\tif (sub === \"retry\") return toCommandResult(await vectorChannelCtl.download());\n\t\t\treturn {\n\t\t\t\tstatus: \"error\" as const,\n\t\t\t\tmessage: \"Usage: /memory [light|full|off|retry|forget <memoryId> [confirm]]\",\n\t\t\t};\n\t\t},\n\t});\n\n\treturn { listTool, forgetTool, enableTool, memoryCommand, promoteCommand, schedulerCapability };\n}\n"]}
|