@ai-agent-forge/plugin-memory 0.88.13 → 0.88.15
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/agent-forge.json +1 -1
- package/dist/capability.d.ts +10 -7
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +24 -14
- package/dist/capability.js.map +1 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +8 -1
- package/dist/entry.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inference-bin.bundle.js +77 -58
- package/dist/memory/command-face.d.ts.map +1 -1
- package/dist/memory/command-face.js +32 -10
- package/dist/memory/command-face.js.map +1 -1
- package/dist/memory/curator.d.ts +184 -0
- package/dist/memory/curator.d.ts.map +1 -0
- package/dist/memory/curator.js +551 -0
- package/dist/memory/curator.js.map +1 -0
- package/dist/memory/enabling.d.ts.map +1 -1
- package/dist/memory/enabling.js +6 -0
- package/dist/memory/enabling.js.map +1 -1
- package/dist/memory/hooks.d.ts +12 -55
- package/dist/memory/hooks.d.ts.map +1 -1
- package/dist/memory/hooks.js +2 -229
- package/dist/memory/hooks.js.map +1 -1
- package/dist/testing/memory-testkit.d.ts +3 -1
- package/dist/testing/memory-testkit.d.ts.map +1 -1
- package/dist/testing/memory-testkit.js +50 -7
- package/dist/testing/memory-testkit.js.map +1 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
|
@@ -2065,7 +2065,7 @@ var init_host_module_import = __esm({
|
|
|
2065
2065
|
});
|
|
2066
2066
|
|
|
2067
2067
|
// src/memory/embedding-provider.ts
|
|
2068
|
-
import { join as
|
|
2068
|
+
import { join as join5 } from "node:path";
|
|
2069
2069
|
function createTransformersEmbeddingProvider(options) {
|
|
2070
2070
|
const modelId = options.modelId ?? DEFAULT_TRANSFORMERS_MODEL_ID;
|
|
2071
2071
|
const dimensions = options.dimensions ?? DEFAULT_TRANSFORMERS_DIMENSIONS;
|
|
@@ -2090,7 +2090,7 @@ function createTransformersEmbeddingProvider(options) {
|
|
|
2090
2090
|
} catch (error) {
|
|
2091
2091
|
lastError = error;
|
|
2092
2092
|
if (disposed) throw error;
|
|
2093
|
-
purgeZeroByteCacheArtifacts(
|
|
2093
|
+
purgeZeroByteCacheArtifacts(join5(cacheDir, modelId));
|
|
2094
2094
|
}
|
|
2095
2095
|
try {
|
|
2096
2096
|
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
@@ -2099,7 +2099,7 @@ function createTransformersEmbeddingProvider(options) {
|
|
|
2099
2099
|
} catch (error) {
|
|
2100
2100
|
lastError = error;
|
|
2101
2101
|
if (disposed) throw error;
|
|
2102
|
-
purgeZeroByteCacheArtifacts(
|
|
2102
|
+
purgeZeroByteCacheArtifacts(join5(cacheDir, modelId));
|
|
2103
2103
|
}
|
|
2104
2104
|
}
|
|
2105
2105
|
if (lastError === void 0) throw new Error(`no remote hosts configured for model ${modelId}`);
|
|
@@ -2189,7 +2189,7 @@ var init_embedding_provider = __esm({
|
|
|
2189
2189
|
});
|
|
2190
2190
|
|
|
2191
2191
|
// src/memory/embedding-reranker.ts
|
|
2192
|
-
import { join as
|
|
2192
|
+
import { join as join6 } from "node:path";
|
|
2193
2193
|
function createTransformersReranker(options) {
|
|
2194
2194
|
const modelId = options.modelId ?? DEFAULT_RERANKER_MODEL_ID;
|
|
2195
2195
|
const cacheDir = options.cacheDir;
|
|
@@ -2212,7 +2212,7 @@ function createTransformersReranker(options) {
|
|
|
2212
2212
|
} catch (error) {
|
|
2213
2213
|
lastError = error;
|
|
2214
2214
|
if (disposed) throw error;
|
|
2215
|
-
purgeZeroByteCacheArtifacts(
|
|
2215
|
+
purgeZeroByteCacheArtifacts(join6(cacheDir, modelId));
|
|
2216
2216
|
}
|
|
2217
2217
|
try {
|
|
2218
2218
|
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
@@ -2221,7 +2221,7 @@ function createTransformersReranker(options) {
|
|
|
2221
2221
|
} catch (error) {
|
|
2222
2222
|
lastError = error;
|
|
2223
2223
|
if (disposed) throw error;
|
|
2224
|
-
purgeZeroByteCacheArtifacts(
|
|
2224
|
+
purgeZeroByteCacheArtifacts(join6(cacheDir, modelId));
|
|
2225
2225
|
}
|
|
2226
2226
|
}
|
|
2227
2227
|
if (lastError === void 0) throw new Error(`no remote hosts configured for model ${modelId}`);
|
|
@@ -2446,11 +2446,19 @@ var init_vector_index = __esm({
|
|
|
2446
2446
|
|
|
2447
2447
|
// src/inference-bin.ts
|
|
2448
2448
|
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, statSync as statSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2449
|
-
import { join as
|
|
2449
|
+
import { join as join8 } from "node:path";
|
|
2450
2450
|
|
|
2451
2451
|
// src/entry.ts
|
|
2452
2452
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
2453
|
-
import { join as
|
|
2453
|
+
import { join as join4 } from "node:path";
|
|
2454
|
+
|
|
2455
|
+
// ../../packages/plugin-sdk/src/agent-task-scheduler.ts
|
|
2456
|
+
var AGENT_TASK_SCHEDULER_MAX_PROMPT_BYTES = 48 * 1024;
|
|
2457
|
+
var AGENT_TASK_SCHEDULER_MAX_TEXT_BYTES = 32 * 1024;
|
|
2458
|
+
var textEncoder = new TextEncoder();
|
|
2459
|
+
|
|
2460
|
+
// ../../packages/plugin-sdk/src/browser-fetch.ts
|
|
2461
|
+
var BROWSER_FETCH_MAX_TEXT_CHARS = 16 * 1024;
|
|
2454
2462
|
|
|
2455
2463
|
// ../../packages/plugin-sdk/src/capability-manifest.ts
|
|
2456
2464
|
var import_semver = __toESM(require_semver2(), 1);
|
|
@@ -2462,6 +2470,10 @@ var DEFAULT_PLUGIN_CONTEXT_BUDGET_V1 = Object.freeze({
|
|
|
2462
2470
|
maxCellChars: 256
|
|
2463
2471
|
});
|
|
2464
2472
|
|
|
2473
|
+
// ../../packages/plugin-sdk/src/operation.ts
|
|
2474
|
+
var EVIDENCE_SUMMARY_MAX_CHARS_V1 = 128 * 1024;
|
|
2475
|
+
var PLUGIN_RESULT_SUMMARY_MAX_CHARS_V1 = 8 * 1024;
|
|
2476
|
+
|
|
2465
2477
|
// ../../packages/plugin-sdk/src/diff.ts
|
|
2466
2478
|
var DIFF_MAX_RESULT_BYTES_V1 = 64 * 1024;
|
|
2467
2479
|
|
|
@@ -7136,42 +7148,6 @@ __export(typebox_exports, {
|
|
|
7136
7148
|
// ../../node_modules/typebox/build/index.mjs
|
|
7137
7149
|
var build_default = typebox_exports;
|
|
7138
7150
|
|
|
7139
|
-
// src/memory/write-face.ts
|
|
7140
|
-
var MAX_TAGS = 8;
|
|
7141
|
-
var MEMORY_CONTENT_MAX_LENGTH = 700;
|
|
7142
|
-
var writeSchema = typebox_exports.Object({
|
|
7143
|
-
content: typebox_exports.String({
|
|
7144
|
-
description: "The memory content: one self-contained fact or preference statement",
|
|
7145
|
-
maxLength: MEMORY_CONTENT_MAX_LENGTH
|
|
7146
|
-
}),
|
|
7147
|
-
kind: typebox_exports.Union([typebox_exports.Literal("fact"), typebox_exports.Literal("preference")], {
|
|
7148
|
-
description: "fact = a durable piece of information; preference = a user preference (requires subject)"
|
|
7149
|
-
}),
|
|
7150
|
-
subject: typebox_exports.Optional(
|
|
7151
|
-
typebox_exports.Union([typebox_exports.Literal("user"), typebox_exports.Literal("project"), typebox_exports.Literal("task"), typebox_exports.Literal("environment")], {
|
|
7152
|
-
description: "Required when kind is preference: whose preference this is"
|
|
7153
|
-
})
|
|
7154
|
-
),
|
|
7155
|
-
tags: typebox_exports.Optional(
|
|
7156
|
-
typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
|
|
7157
|
-
description: "Optional short keywords; stored with the memory, full-text searchable and shown in memory_list; at most 8",
|
|
7158
|
-
maxItems: MAX_TAGS
|
|
7159
|
-
})
|
|
7160
|
-
),
|
|
7161
|
-
evidence: typebox_exports.Optional(
|
|
7162
|
-
typebox_exports.Object(
|
|
7163
|
-
{
|
|
7164
|
-
class: typebox_exports.Union([typebox_exports.Literal("user-stated"), typebox_exports.Literal("tool-observed"), typebox_exports.Literal("inferred")], {
|
|
7165
|
-
description: "How this content is known: user-stated = the user explicitly said it this session; tool-observed = a tool or test result verified it; inferred = your own conclusion. Default inferred \u2014 never dress an inference up as user-stated"
|
|
7166
|
-
})
|
|
7167
|
-
},
|
|
7168
|
-
{
|
|
7169
|
-
description: "Evidence declaration (defaults to inferred). Inferences must not be saved as facts at all; the class only grades honest writes"
|
|
7170
|
-
}
|
|
7171
|
-
)
|
|
7172
|
-
)
|
|
7173
|
-
});
|
|
7174
|
-
|
|
7175
7151
|
// src/memory/recall-pipeline.ts
|
|
7176
7152
|
var recallSchema = typebox_exports.Object({
|
|
7177
7153
|
query: typebox_exports.String({
|
|
@@ -7207,7 +7183,7 @@ var CborError = class extends Error {
|
|
|
7207
7183
|
this.name = "CborError";
|
|
7208
7184
|
}
|
|
7209
7185
|
};
|
|
7210
|
-
var
|
|
7186
|
+
var textEncoder2 = new TextEncoder();
|
|
7211
7187
|
var textDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
7212
7188
|
function resolveLimit(name, value, maximum) {
|
|
7213
7189
|
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) {
|
|
@@ -7458,7 +7434,7 @@ function isPlainObject(value) {
|
|
|
7458
7434
|
return prototype === Object.prototype || prototype === null;
|
|
7459
7435
|
}
|
|
7460
7436
|
function encodeText(writer, value, options) {
|
|
7461
|
-
const bytes =
|
|
7437
|
+
const bytes = textEncoder2.encode(value);
|
|
7462
7438
|
if (bytes.byteLength > options.maxByteLength) {
|
|
7463
7439
|
throw new CborError(`CBOR text string length exceeds configured limit of ${options.maxByteLength}`);
|
|
7464
7440
|
}
|
|
@@ -11504,6 +11480,42 @@ var VECTOR_RERANKER_MODEL_ID = "Xenova/bge-reranker-base";
|
|
|
11504
11480
|
var VECTOR_DB_DIRNAME = "vector";
|
|
11505
11481
|
var VECTOR_MODEL_CACHE_DIRNAME = "model-cache";
|
|
11506
11482
|
|
|
11483
|
+
// src/memory/write-face.ts
|
|
11484
|
+
var MAX_TAGS = 8;
|
|
11485
|
+
var MEMORY_CONTENT_MAX_LENGTH = 700;
|
|
11486
|
+
var writeSchema = typebox_exports.Object({
|
|
11487
|
+
content: typebox_exports.String({
|
|
11488
|
+
description: "The memory content: one self-contained fact or preference statement",
|
|
11489
|
+
maxLength: MEMORY_CONTENT_MAX_LENGTH
|
|
11490
|
+
}),
|
|
11491
|
+
kind: typebox_exports.Union([typebox_exports.Literal("fact"), typebox_exports.Literal("preference")], {
|
|
11492
|
+
description: "fact = a durable piece of information; preference = a user preference (requires subject)"
|
|
11493
|
+
}),
|
|
11494
|
+
subject: typebox_exports.Optional(
|
|
11495
|
+
typebox_exports.Union([typebox_exports.Literal("user"), typebox_exports.Literal("project"), typebox_exports.Literal("task"), typebox_exports.Literal("environment")], {
|
|
11496
|
+
description: "Required when kind is preference: whose preference this is"
|
|
11497
|
+
})
|
|
11498
|
+
),
|
|
11499
|
+
tags: typebox_exports.Optional(
|
|
11500
|
+
typebox_exports.Array(typebox_exports.String({ minLength: 1 }), {
|
|
11501
|
+
description: "Optional short keywords; stored with the memory, full-text searchable and shown in memory_list; at most 8",
|
|
11502
|
+
maxItems: MAX_TAGS
|
|
11503
|
+
})
|
|
11504
|
+
),
|
|
11505
|
+
evidence: typebox_exports.Optional(
|
|
11506
|
+
typebox_exports.Object(
|
|
11507
|
+
{
|
|
11508
|
+
class: typebox_exports.Union([typebox_exports.Literal("user-stated"), typebox_exports.Literal("tool-observed"), typebox_exports.Literal("inferred")], {
|
|
11509
|
+
description: "How this content is known: user-stated = the user explicitly said it this session; tool-observed = a tool or test result verified it; inferred = your own conclusion. Default inferred \u2014 never dress an inference up as user-stated"
|
|
11510
|
+
})
|
|
11511
|
+
},
|
|
11512
|
+
{
|
|
11513
|
+
description: "Evidence declaration (defaults to inferred). Inferences must not be saved as facts at all; the class only grades honest writes"
|
|
11514
|
+
}
|
|
11515
|
+
)
|
|
11516
|
+
)
|
|
11517
|
+
});
|
|
11518
|
+
|
|
11507
11519
|
// src/memory/command-face.ts
|
|
11508
11520
|
var listSchema = typebox_exports.Object({
|
|
11509
11521
|
limit: typebox_exports.Optional(
|
|
@@ -11521,9 +11533,8 @@ var enableSchema = typebox_exports.Object({
|
|
|
11521
11533
|
})
|
|
11522
11534
|
});
|
|
11523
11535
|
|
|
11524
|
-
// src/memory/
|
|
11525
|
-
|
|
11526
|
-
var SHORT_TERM_BOOST_EXPIRY_MS = 1 * DAY;
|
|
11536
|
+
// src/memory/curator.ts
|
|
11537
|
+
import { join as join3 } from "node:path";
|
|
11527
11538
|
|
|
11528
11539
|
// src/memory/transfer.ts
|
|
11529
11540
|
var MEMORY_CONTRACT_VERSION_V1 = "agent-forge/memory@1";
|
|
@@ -11533,6 +11544,13 @@ var MEMORY_CONTRACT_VERSIONS = Object.freeze([
|
|
|
11533
11544
|
MEMORY_CONTRACT_VERSION_V2
|
|
11534
11545
|
]);
|
|
11535
11546
|
|
|
11547
|
+
// src/memory/curator.ts
|
|
11548
|
+
var CURATION_JOURNAL_RELATIVE_PATH = join3("archive", "sessions", "curation-journal.jsonl");
|
|
11549
|
+
|
|
11550
|
+
// src/memory/lifecycle.ts
|
|
11551
|
+
var DAY = 24 * 60 * 60 * 1e3;
|
|
11552
|
+
var SHORT_TERM_BOOST_EXPIRY_MS = 1 * DAY;
|
|
11553
|
+
|
|
11536
11554
|
// src/capability.ts
|
|
11537
11555
|
var isMemoryModeV1 = (value) => value === "off" || value === "light" || value === "full";
|
|
11538
11556
|
function resolveMemoryMode(explicitMode, env = process.env, settingsMode) {
|
|
@@ -11559,14 +11577,15 @@ function resolveMemoryMode(explicitMode, env = process.env, settingsMode) {
|
|
|
11559
11577
|
}
|
|
11560
11578
|
|
|
11561
11579
|
// src/entry.ts
|
|
11562
|
-
var CAPABILITY_CONFIG_RELATIVE_PATH =
|
|
11580
|
+
var CAPABILITY_CONFIG_RELATIVE_PATH = join4("capabilities", "builtin.memory.json");
|
|
11563
11581
|
function readAgentDirConfig(configPath) {
|
|
11564
11582
|
if (configPath === void 0) return void 0;
|
|
11565
11583
|
let raw;
|
|
11566
11584
|
try {
|
|
11567
11585
|
raw = readFileSync2(configPath, "utf8");
|
|
11568
11586
|
} catch (error) {
|
|
11569
|
-
|
|
11587
|
+
const code = error.code;
|
|
11588
|
+
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
11570
11589
|
throw new Error(`Failed to read ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11571
11590
|
}
|
|
11572
11591
|
let parsed;
|
|
@@ -11587,7 +11606,7 @@ function stringConfigValue(config, key) {
|
|
|
11587
11606
|
return { invalid: raw };
|
|
11588
11607
|
}
|
|
11589
11608
|
function resolveMemoryServiceMode(agentDir2, env) {
|
|
11590
|
-
const fileConfig = readAgentDirConfig(
|
|
11609
|
+
const fileConfig = readAgentDirConfig(join4(agentDir2, CAPABILITY_CONFIG_RELATIVE_PATH));
|
|
11591
11610
|
const settingsMode = fileConfig === void 0 ? void 0 : stringConfigValue(fileConfig, "memorySettingsMode");
|
|
11592
11611
|
if (settingsMode?.invalid !== void 0) {
|
|
11593
11612
|
return {
|
|
@@ -11602,7 +11621,7 @@ function resolveMemoryServiceMode(agentDir2, env) {
|
|
|
11602
11621
|
}
|
|
11603
11622
|
|
|
11604
11623
|
// src/memory/inference-service-main.ts
|
|
11605
|
-
import { join as
|
|
11624
|
+
import { join as join7 } from "node:path";
|
|
11606
11625
|
init_embedding_provider();
|
|
11607
11626
|
init_embedding_reranker();
|
|
11608
11627
|
|
|
@@ -11927,7 +11946,7 @@ async function runMemoryInferenceService(options) {
|
|
|
11927
11946
|
const log2 = options.log ?? (() => {
|
|
11928
11947
|
});
|
|
11929
11948
|
const preset = vectorPresetForMode(options.mode);
|
|
11930
|
-
const modelCacheDir =
|
|
11949
|
+
const modelCacheDir = join7(options.agentDir, "memory", VECTOR_MODEL_CACHE_DIRNAME);
|
|
11931
11950
|
let backend = options.backend;
|
|
11932
11951
|
if (backend === void 0) {
|
|
11933
11952
|
const missingEmbedding = modelFilesCheck(
|
|
@@ -11956,7 +11975,7 @@ async function runMemoryInferenceService(options) {
|
|
|
11956
11975
|
...options.loadImpls?.reranker === void 0 ? {} : { loadImpl: options.loadImpls.reranker }
|
|
11957
11976
|
});
|
|
11958
11977
|
const vectorIndex = await createMemoryVectorIndex({
|
|
11959
|
-
dbPath:
|
|
11978
|
+
dbPath: join7(options.agentDir, "memory", VECTOR_DB_DIRNAME),
|
|
11960
11979
|
dimensions: preset.dimensions,
|
|
11961
11980
|
...options.moduleEntryPaths?.lancedb === void 0 ? {} : { moduleEntryPath: options.moduleEntryPaths.lancedb }
|
|
11962
11981
|
});
|
|
@@ -11988,7 +12007,7 @@ var log = (line) => {
|
|
|
11988
12007
|
`);
|
|
11989
12008
|
if (agentDir === void 0) return;
|
|
11990
12009
|
try {
|
|
11991
|
-
appendFileSync(
|
|
12010
|
+
appendFileSync(join8(agentDir, "memory", "inference-service.log"), `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
11992
12011
|
`);
|
|
11993
12012
|
} catch {
|
|
11994
12013
|
}
|
|
@@ -11998,8 +12017,8 @@ if (agentDir === void 0 || agentDir.trim() === "") {
|
|
|
11998
12017
|
process.exit(64);
|
|
11999
12018
|
}
|
|
12000
12019
|
try {
|
|
12001
|
-
mkdirSync2(
|
|
12002
|
-
const logFilePath =
|
|
12020
|
+
mkdirSync2(join8(agentDir, "memory"), { recursive: true });
|
|
12021
|
+
const logFilePath = join8(agentDir, "memory", "inference-service.log");
|
|
12003
12022
|
if (existsSync2(logFilePath) && statSync3(logFilePath).size > LOG_FILE_MAX_BYTES) writeFileSync2(logFilePath, "");
|
|
12004
12023
|
} catch {
|
|
12005
12024
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-face.d.ts","sourceRoot":"","sources":["../../src/memory/command-face.ts"],"names":[],"mappings":"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","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"]}
|
|
1
|
+
{"version":3,"file":"command-face.d.ts","sourceRoot":"","sources":["../../src/memory/command-face.ts"],"names":[],"mappings":"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","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, CapabilityCommandResult, 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\t/**\n\t * Structured status for host consoles (公共命令结果 data, additive):\n\t * the TUI `/memory` console reads mode/channel/domain without parsing the\n\t * human message. `channel` mirrors the vector state machine; decline is\n\t * reported as \"off\" (the line's existing semantics).\n\t */\n\tconst memoryStatusSnapshot = (): {\n\t\treadonly mode: \"light\" | \"full\";\n\t\treadonly channel: \"off\" | \"consent-required\" | \"enabling\" | \"ready\" | \"degraded\" | \"failed\";\n\t\treadonly declined: boolean;\n\t\treadonly pendingUpgrade: boolean;\n\t\treadonly failureReason?: string;\n\t} => {\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 failureReason = vectorChannelCtl.failure()?.reason;\n\t\treturn {\n\t\t\tmode: memoryMode,\n\t\t\tchannel: declined ? \"off\" : vectorChannelCtl.rawState(),\n\t\t\tdeclined,\n\t\t\tpendingUpgrade,\n\t\t\t...(failureReason === undefined ? {} : { failureReason }),\n\t\t};\n\t};\n\tconst memoryStatusLine = (status: ReturnType<typeof memoryStatusSnapshot>): string => {\n\t\tconst modeLine = `mode=${status.mode}${status.pendingUpgrade ? \", auto-upgrade to full pending (next session)\" : \"\"}`;\n\t\tif (status.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\tif (status.channel === \"ready\") return `${modeLine}, ready`;\n\t\tif (status.channel === \"degraded\") return `${modeLine}, ready (degraded)`;\n\t\tif (status.channel === \"failed\") return `${modeLine}, failed: ${status.failureReason ?? \"unknown reason\"}`;\n\t\tif (status.channel === \"consent-required\") {\n\t\t\treturn `${modeLine}, waiting for the model download decision (/memory retry to start it)`;\n\t\t}\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\tconst snapshot = memoryStatusSnapshot();\n\t\t\t\tconst statusResult: CapabilityCommandResult = {\n\t\t\t\t\tstatus: \"success\",\n\t\t\t\t\tmessage: `memory: ${memoryStatusLine(snapshot)}`,\n\t\t\t\t\tdata: { memoryStatus: snapshot },\n\t\t\t\t};\n\t\t\t\treturn statusResult;\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"]}
|
|
@@ -242,24 +242,40 @@ export function createMemoryCommandFace(deps) {
|
|
|
242
242
|
// 触发后台预热; 命令面 /memory off|retry 是用户的直接出口。decline/download
|
|
243
243
|
// 核心在 memory/vector-channel.ts (slice 3b), 工具与命令面经
|
|
244
244
|
// vectorChannelCtl.decline()/download() 薄委托; decline 持久化只抑制默认档。
|
|
245
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Structured status for host consoles (公共命令结果 data, additive):
|
|
247
|
+
* the TUI `/memory` console reads mode/channel/domain without parsing the
|
|
248
|
+
* human message. `channel` mirrors the vector state machine; decline is
|
|
249
|
+
* reported as "off" (the line's existing semantics).
|
|
250
|
+
*/
|
|
251
|
+
const memoryStatusSnapshot = () => {
|
|
246
252
|
// pending 尾巴只对仍有效的升档声明 (declined 分支里档位键已被删除, 显示
|
|
247
253
|
// pending 会失实 — 2026-10-06 复审 P2-1)。
|
|
248
254
|
const declined = vectorChannelCtl.declined();
|
|
249
255
|
const pendingUpgrade = tierUpgradePending() && !declined;
|
|
250
|
-
const
|
|
251
|
-
|
|
256
|
+
const failureReason = vectorChannelCtl.failure()?.reason;
|
|
257
|
+
return {
|
|
258
|
+
mode: memoryMode,
|
|
259
|
+
channel: declined ? "off" : vectorChannelCtl.rawState(),
|
|
260
|
+
declined,
|
|
261
|
+
pendingUpgrade,
|
|
262
|
+
...(failureReason === undefined ? {} : { failureReason }),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
const memoryStatusLine = (status) => {
|
|
266
|
+
const modeLine = `mode=${status.mode}${status.pendingUpgrade ? ", auto-upgrade to full pending (next session)" : ""}`;
|
|
267
|
+
if (status.declined) {
|
|
252
268
|
return `${modeLine}, off (declined on this machine). Set memory.mode (light|full) in settings.json and restart the session to re-enable`;
|
|
253
269
|
}
|
|
254
|
-
|
|
255
|
-
if (channelState === "ready")
|
|
270
|
+
if (status.channel === "ready")
|
|
256
271
|
return `${modeLine}, ready`;
|
|
257
|
-
if (
|
|
272
|
+
if (status.channel === "degraded")
|
|
258
273
|
return `${modeLine}, ready (degraded)`;
|
|
259
|
-
if (
|
|
260
|
-
return `${modeLine}, failed: ${
|
|
261
|
-
if (
|
|
274
|
+
if (status.channel === "failed")
|
|
275
|
+
return `${modeLine}, failed: ${status.failureReason ?? "unknown reason"}`;
|
|
276
|
+
if (status.channel === "consent-required") {
|
|
262
277
|
return `${modeLine}, waiting for the model download decision (/memory retry to start it)`;
|
|
278
|
+
}
|
|
263
279
|
return `${modeLine}, loading models in the background`;
|
|
264
280
|
};
|
|
265
281
|
const enableTool = registerTool({
|
|
@@ -331,7 +347,13 @@ export function createMemoryCommandFace(deps) {
|
|
|
331
347
|
}
|
|
332
348
|
const sub = args.trim().toLowerCase();
|
|
333
349
|
if (sub === "" || sub === "status") {
|
|
334
|
-
|
|
350
|
+
const snapshot = memoryStatusSnapshot();
|
|
351
|
+
const statusResult = {
|
|
352
|
+
status: "success",
|
|
353
|
+
message: `memory: ${memoryStatusLine(snapshot)}`,
|
|
354
|
+
data: { memoryStatus: snapshot },
|
|
355
|
+
};
|
|
356
|
+
return statusResult;
|
|
335
357
|
}
|
|
336
358
|
if (sub === "light" || sub === "full") {
|
|
337
359
|
// 无"已是该档"早退: 持久化档位与会话内已解析档位是两回事——会话可能
|