dsh-plugin-tool-management 0.22.5 → 0.22.6
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/CHANGELOG.md +1624 -1415
- package/README.md +194 -177
- package/README_EN.md +194 -177
- package/docs/ARCHITECTURE.md +137 -134
- package/docs/COMPATIBILITY.md +12 -7
- package/docs/TROUBLESHOOTING.md +287 -285
- package/lib/client.js +14975 -12277
- package/lib/compat/capability-specs.js +66 -16
- package/lib/compat/host-contracts.js +11 -2
- package/lib/compat/host-roots.js +1 -1
- package/lib/compat/manual-review.js +1 -1
- package/lib/compat/preset-reach.js +1 -1
- package/lib/compat/probe.js +96 -11
- package/lib/confirm-gate.js +40 -6
- package/lib/context-inject-contract.js +31 -14
- package/lib/context-inject-delta.js +146 -0
- package/lib/context-inject-frame.js +38 -19
- package/lib/context-inject-select.js +33 -4
- package/lib/context-inject-surface.js +30 -10
- package/lib/context-inject.js +106 -14
- package/lib/evolution/cold.js +389 -0
- package/lib/evolution/config.js +507 -0
- package/lib/evolution/digest.js +48 -0
- package/lib/evolution/episodes.js +287 -0
- package/lib/evolution/evidence.js +167 -0
- package/lib/evolution/gates.js +874 -0
- package/lib/evolution/limits.js +21 -0
- package/lib/evolution/maintenance.js +516 -0
- package/lib/evolution/notes.js +328 -0
- package/lib/evolution/organize.js +118 -0
- package/lib/evolution/review.js +524 -0
- package/lib/evolution/route.js +91 -0
- package/lib/evolution/runtime.js +179 -0
- package/lib/evolution/scope-card.js +144 -0
- package/lib/evolution/state.js +514 -0
- package/lib/evolution/write.js +1773 -0
- package/lib/index.js +1328 -58
- package/lib/legacy-tool-names.js +19 -4
- package/lib/mcp/tool-visibility.js +127 -10
- package/lib/memories/catalog.js +215 -0
- package/lib/memories/constants.js +115 -7
- package/lib/memories/discovery.js +59 -25
- package/lib/memories/projection.js +116 -31
- package/lib/memories/render-auto.js +198 -0
- package/lib/memories/search.js +3 -5
- package/lib/memories/service.js +158 -14
- package/lib/memories/snapshot.js +174 -23
- package/lib/op-registry.js +59 -0
- package/lib/ops/compat.js +2 -0
- package/lib/ops/evolution.js +887 -0
- package/lib/ops/memory.js +95 -72
- package/lib/ops/trash.js +14 -2
- package/lib/prompts/service.js +4 -1
- package/lib/scope/workspace-key.js +39 -0
- package/lib/settings-sidecars.js +2 -2
- package/lib/skills/official.js +180 -36
- package/lib/subagents/run-provider.js +35 -22
- package/lib/text-width.js +59 -0
- package/lib/tool-table-switch.js +104 -16
- package/lib/tools/control.js +45 -12
- package/lib/tools/deps.js +2 -2
- package/lib/tools/mcp.js +6 -4
- package/lib/tools/memory.js +1045 -267
- package/lib/tools/note-ref.js +20 -0
- package/lib/tools/remove.js +1 -1
- package/lib/tools/scene.js +3 -3
- package/lib/tools/table.js +76 -20
- package/package.json +155 -156
- package/docs/UPDATE.md +0 -50
package/lib/legacy-tool-names.js
CHANGED
|
@@ -15,11 +15,17 @@
|
|
|
15
15
|
// 出厂口径;只开过其中一条的用户会看到合成的那条仍是关着的 —— 面板上一键就能开,
|
|
16
16
|
// 比原来分五条开省事。
|
|
17
17
|
export const LEGACY_TOOL_NAME_MAP = Object.freeze({
|
|
18
|
-
//
|
|
18
|
+
// 记忆族:write + update + save 三条并成 `memory_remember`(多对一)。
|
|
19
19
|
// (开发中途曾把整族改叫 `scene_memory_manager_*`,但那个名字**从未发布**,用户侧
|
|
20
20
|
// 不可能有它,因此不存在需要从它迁回来的数据。)
|
|
21
|
-
memory_manager_write: '
|
|
22
|
-
memory_manager_update: '
|
|
21
|
+
memory_manager_write: 'memory_remember',
|
|
22
|
+
memory_manager_update: 'memory_remember',
|
|
23
|
+
memory_manager_save: 'memory_remember',
|
|
24
|
+
// 清单并进 `memory_get`:用户显式关过清单的,升级后读取入口仍保持关闭。
|
|
25
|
+
// `memory_manager_read` / `_search` **不映射**:它们出厂就是关着的,映射到
|
|
26
|
+
// `memory_get` 会让升级用户的合并读取入口也变关 —— 那是唯一的发现路径。
|
|
27
|
+
// 旧名留在名单里只是死名,不影响任何工具。
|
|
28
|
+
memory_manager_list: 'memory_get',
|
|
23
29
|
mcp_manager_set_enabled: 'mcp_manager_switch',
|
|
24
30
|
mcp_manager_restart: 'mcp_manager_switch',
|
|
25
31
|
mcp_manager_add: 'mcp_manager_save',
|
|
@@ -29,7 +35,8 @@ export const LEGACY_TOOL_NAME_MAP = Object.freeze({
|
|
|
29
35
|
// 「拨一个开关」六域同形 —— `_set_enabled` → `_switch`(与 `mcp_manager_set_enabled`
|
|
30
36
|
// → `mcp_manager_switch` 同一条路)。**改的只是名字,参数不动**(仍是 `enabled` 布尔),
|
|
31
37
|
// 所以这里是一对一翻译、不涉及语义合并。
|
|
32
|
-
memory_manager_set_enabled: '
|
|
38
|
+
memory_manager_set_enabled: 'memory_switch',
|
|
39
|
+
memory_manager_switch: 'memory_switch',
|
|
33
40
|
skill_manager_set_enabled: 'skill_manager_switch',
|
|
34
41
|
subagent_manager_set_enabled: 'subagent_manager_switch',
|
|
35
42
|
// 删除族:五个域各一条 → 合成一条 `plugin_manager_remove`(**多对一**)。
|
|
@@ -39,6 +46,14 @@ export const LEGACY_TOOL_NAME_MAP = Object.freeze({
|
|
|
39
46
|
subagent_manager_remove: 'plugin_manager_remove',
|
|
40
47
|
scene_manager_remove: 'plugin_manager_remove',
|
|
41
48
|
prompt_manager_remove: 'plugin_manager_remove',
|
|
49
|
+
// 自主笔记:早期分开注册的四条,以及上一版合并后的 `memory_manager_auto`,都迁到
|
|
50
|
+
// `memory_note`。盘上的 `tool-table.json` / 场景快照可能留着旧名;任意一条被关过
|
|
51
|
+
// ⇒ 新工具也记成关过,别让旧名单变成一串永远认不出的死名。
|
|
52
|
+
memory_manager_learn: 'memory_note',
|
|
53
|
+
memory_manager_forget: 'memory_note',
|
|
54
|
+
memory_manager_organize: 'memory_note',
|
|
55
|
+
memory_manager_procedure_done: 'memory_note',
|
|
56
|
+
memory_manager_auto: 'memory_note',
|
|
42
57
|
});
|
|
43
58
|
/** 旧名 → 新名;不是旧名就原样返回。 */
|
|
44
59
|
export function translateLegacyToolName(name) {
|
|
@@ -400,6 +400,8 @@ export function createToolVisibility(deps) {
|
|
|
400
400
|
let appliedNamesKey = null;
|
|
401
401
|
/** 当前期望的**全局** deny 名单(agent 晚到 / 重放时用它,再叠加该 agent 自己那份)。 */
|
|
402
402
|
let desiredNames = [];
|
|
403
|
+
/** 最近一次成功枚举的已注册工具名全集:agent 上线时复用,免去每个子代理各做一次全量深拷贝。 */
|
|
404
|
+
let registeredNames = null;
|
|
403
405
|
/** agent → 撤掉这层限制的 disposer。 */
|
|
404
406
|
const agentRestrictions = new Map();
|
|
405
407
|
/** agent → 已应用的**合并后**名单键(名单现在与 agent 有关,不能再只记一份全局的)。 */
|
|
@@ -447,6 +449,102 @@ export function createToolVisibility(deps) {
|
|
|
447
449
|
catch (e) { /* ignore */ }
|
|
448
450
|
}
|
|
449
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* 同步段能算出的 deny 名单:全局名单 + 本会话模型工具表覆盖 + 载体让位。
|
|
454
|
+
*
|
|
455
|
+
* 子代理创建时,宿主在 `agent/created` 返回后立刻组装首轮工具表;限制层若等
|
|
456
|
+
* `tools.schemas()` 回来再装,那一轮就会先看到全部工具(子代理 fork 时表现为
|
|
457
|
+
* 「新增 24 / 移除 24」)。凡是判据本身同步可得的都必须在这里算完 ——
|
|
458
|
+
* 包括载体让位(`tools.get(name, agent)` 是同步的)。只有真的异步的(MCP 会话覆盖)
|
|
459
|
+
* 才留给随后的 `restrictAgent` 补齐。
|
|
460
|
+
*/
|
|
461
|
+
function syncDenyNamesFor(agent) {
|
|
462
|
+
const wanted = new Set(desiredNames);
|
|
463
|
+
// 启动早期 `desiredNames` 可能还没算出来;工具表设置本身是同步可读的,先并进来。
|
|
464
|
+
if (deps.pluginHiddenTools) {
|
|
465
|
+
try {
|
|
466
|
+
for (const name of deps.pluginHiddenTools())
|
|
467
|
+
wanted.add(name);
|
|
468
|
+
}
|
|
469
|
+
catch { /* 读设置失败 = 只装全局名单 */ }
|
|
470
|
+
}
|
|
471
|
+
// 载体让位(官方 `skill` 在场 → 藏 `skill_manager_read`)同样必须进同步段:
|
|
472
|
+
// 判据只是 `tools.get(name, agent)`,同步可得。漏掉这一条的后果与 issue #29 一模一样 ——
|
|
473
|
+
// 子代理首轮工具表里两条都在,随后异步段才摘掉一条,轨迹上就是「移除工具」。
|
|
474
|
+
//
|
|
475
|
+
// 单独收一份而不是并进 `wanted`:它**不受会话 allow 影响**。让位判的是"官方等价物
|
|
476
|
+
// 已经在场,这条只是重复",不是用户的可见性偏好 —— 会话把一条本不该在清单里的重复
|
|
477
|
+
// 工具重新打开,语义上说不通。并进 `wanted` 会让 allow 赢过它,而异步段
|
|
478
|
+
// (`restrictAgent`)的 `extra` 是加在 allow 之后的 —— 两段对同一份名单给出相反结论,
|
|
479
|
+
// 于是首轮有、第二步没,轨迹上又是一次「移除工具」。
|
|
480
|
+
const carrier = new Set();
|
|
481
|
+
if (deps.carrierHiddenTools) {
|
|
482
|
+
try {
|
|
483
|
+
const hidden = deps.carrierHiddenTools(agent);
|
|
484
|
+
// 异步实现拿不到这一轮结果:交给 `restrictAgent` 补(那一轮会重装并上报)。
|
|
485
|
+
if (typeof hidden?.then !== 'function') {
|
|
486
|
+
for (const name of hidden)
|
|
487
|
+
carrier.add(name);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch { /* 判据失败 = 不让位(宁可多花 token,也不让模型少一条路) */ }
|
|
491
|
+
}
|
|
492
|
+
let allow = [];
|
|
493
|
+
if (deps.sessionToolTableOverlay) {
|
|
494
|
+
try {
|
|
495
|
+
const ov = deps.sessionToolTableOverlay(agent);
|
|
496
|
+
// 覆盖实现是异步的时拿不到这一轮结果:只装全局名单,交给 `restrictAgent` 补。
|
|
497
|
+
if (ov !== undefined && typeof ov.then !== 'function') {
|
|
498
|
+
const sync = ov;
|
|
499
|
+
if (sync.allow !== undefined)
|
|
500
|
+
allow = sync.allow;
|
|
501
|
+
if (sync.deny !== undefined)
|
|
502
|
+
for (const name of sync.deny)
|
|
503
|
+
wanted.add(name);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
catch { /* 取不到 = 跟随全局 */ }
|
|
507
|
+
}
|
|
508
|
+
// 与 `restrictAgent` 同一条边界:停用表读不出来时,会话 allow 不得越过它把 mcp__* 放回来。
|
|
509
|
+
const allowSet = disabledToolsState() === 'unknown'
|
|
510
|
+
? new Set([...allow].filter((name) => !name.startsWith(MCP_TOOL_PREFIX)))
|
|
511
|
+
: new Set(allow);
|
|
512
|
+
// 与 `restrictAgent` 同形:会话 allow 只减全局那半边,载体让位加在它之后。
|
|
513
|
+
const names = [...new Set([...[...wanted].filter((name) => !allowSet.has(name)), ...carrier])];
|
|
514
|
+
// 官方 `restrict` 对认不出的名字是整份名单抛错。同步段没有注册全集可求交,
|
|
515
|
+
// 改问全局视图(同步、无 I/O);已被限制摘掉的名字在这里仍算 known。
|
|
516
|
+
return typeof deps.tools.get === 'function'
|
|
517
|
+
? names.filter((name) => { try {
|
|
518
|
+
return deps.tools.get(name) !== undefined;
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
return false;
|
|
522
|
+
} })
|
|
523
|
+
: names;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* 同步装层,赶在宿主组装首轮工具表之前(只给 `attachAgent` 用)。
|
|
527
|
+
*
|
|
528
|
+
* 失败不在这里上报:随后的 `restrictAgent` 会重试并如实上报,两处都失败才是问题。
|
|
529
|
+
*/
|
|
530
|
+
function installSyncRestriction(agent) {
|
|
531
|
+
const scoped = scopedToolsOf(agent);
|
|
532
|
+
if (!scoped || typeof scoped.restrict !== 'function')
|
|
533
|
+
return;
|
|
534
|
+
const denyNames = syncDenyNamesFor(agent);
|
|
535
|
+
const denyKey = denyNames.slice().sort().join('\u0000');
|
|
536
|
+
if (appliedByAgent.get(agent) === denyKey)
|
|
537
|
+
return;
|
|
538
|
+
liftRestriction(agent);
|
|
539
|
+
if (denyNames.length === 0)
|
|
540
|
+
return;
|
|
541
|
+
try {
|
|
542
|
+
const dispose = scoped.restrict({ deny: denyNames });
|
|
543
|
+
agentRestrictions.set(agent, typeof dispose === 'function' ? dispose : () => { });
|
|
544
|
+
appliedByAgent.set(agent, denyKey);
|
|
545
|
+
}
|
|
546
|
+
catch { /* 异步那一轮会重试并上报 */ }
|
|
547
|
+
}
|
|
450
548
|
/**
|
|
451
549
|
* 把该 agent 该背的名单装到它 scope 上(全局那份 ∓ 会话覆盖 ∪ 它自己那份;空名单 = 不碰它)。
|
|
452
550
|
*
|
|
@@ -507,7 +605,18 @@ export function createToolVisibility(deps) {
|
|
|
507
605
|
const effectiveAllow = disabledToolsState() === 'unknown'
|
|
508
606
|
? new Set([...allowSet].filter((name) => !name.startsWith(MCP_TOOL_PREFIX)))
|
|
509
607
|
: allowSet;
|
|
510
|
-
|
|
608
|
+
// 全局名单以 `desiredNames` 为底,再并一次当前的工具表设置:启动早期
|
|
609
|
+
// `applyToolRestrictions` 可能还没算出 `desiredNames`,而 `attachAgent` 的同步段
|
|
610
|
+
// 已经按设置装了一层 —— 两边必须同源,否则异步这一轮会把同步层撤掉。
|
|
611
|
+
const globalNames = new Set(desiredNames);
|
|
612
|
+
if (deps.pluginHiddenTools) {
|
|
613
|
+
try {
|
|
614
|
+
for (const name of deps.pluginHiddenTools())
|
|
615
|
+
globalNames.add(name);
|
|
616
|
+
}
|
|
617
|
+
catch { /* 读设置失败 = 只装已算出的全局名单 */ }
|
|
618
|
+
}
|
|
619
|
+
const names = [...new Set([...globalNames].filter((name) => !effectiveAllow.has(name)).concat(extra))];
|
|
511
620
|
const scoped = scopedToolsOf(agent);
|
|
512
621
|
if (!scoped || typeof scoped.restrict !== 'function') {
|
|
513
622
|
if (names.length === 0)
|
|
@@ -597,22 +706,29 @@ export function createToolVisibility(deps) {
|
|
|
597
706
|
}
|
|
598
707
|
}
|
|
599
708
|
/**
|
|
600
|
-
* agent 上线(`agent/created` 或启动期的 agent
|
|
709
|
+
* agent 上线(`agent/created` 或启动期的 agent 列表):登记,先同步装一层,再异步补齐。
|
|
601
710
|
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
711
|
+
* 同步那层是给宿主首轮工具表用的(见 `installSyncRestriction`);异步那层补 MCP 会话
|
|
712
|
+
* 覆盖与载体工具。注册全集优先复用 `registeredNames`,没有才枚举一次。事件频率是
|
|
713
|
+
* "每个会话一次",与 `tools/change` 那条热路径无关 —— 后者在 `applyToolRestrictions`
|
|
714
|
+
* 里共用一份。
|
|
604
715
|
*/
|
|
605
716
|
function attachAgent(agent) {
|
|
606
717
|
if (!agent || (typeof agent !== 'object' && typeof agent !== 'function'))
|
|
607
718
|
return;
|
|
608
719
|
seenAgents.add(agent);
|
|
720
|
+
// 先同步装一层:`agent/created` 返回后宿主就组装首轮工具表,等异步枚举回来已经晚了一轮。
|
|
721
|
+
installSyncRestriction(agent);
|
|
609
722
|
void (async () => {
|
|
610
|
-
let registered;
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
723
|
+
let registered = registeredNames;
|
|
724
|
+
if (registered === null) {
|
|
725
|
+
try {
|
|
726
|
+
registered = new Set((await deps.tools.schemas()).map((schema) => String(schema.name)));
|
|
727
|
+
registeredNames = registered;
|
|
728
|
+
}
|
|
729
|
+
catch {
|
|
730
|
+
registered = new Set();
|
|
731
|
+
}
|
|
616
732
|
}
|
|
617
733
|
await restrictAgent(agent, registered);
|
|
618
734
|
})().catch(() => { });
|
|
@@ -647,6 +763,7 @@ export function createToolVisibility(deps) {
|
|
|
647
763
|
let registered;
|
|
648
764
|
try {
|
|
649
765
|
registered = new Set((await deps.tools.schemas()).map((schema) => String(schema.name)));
|
|
766
|
+
registeredNames = registered;
|
|
650
767
|
// 枚举成功 = 上一轮「schemas 失败」已恢复;no-restrict 也在前面那道检查里确认过。
|
|
651
768
|
// 逐 agent 的 partial 若仍成立,restrictAgent 会在下面重新上报。
|
|
652
769
|
clearRuntimeNote('mcp-tool-visibility');
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// 自动记忆的注入索引(`evolution/catalog.json`)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么需要它:注入热路径不能读正文。300 条 × 2 KB 全读约 100–300ms,而只读这份派生索引
|
|
4
|
+
// 约 10ms。条数再多,注入成本也应该基本不变 —— 这是"记忆多了也不会变慢"的那一半。
|
|
5
|
+
//
|
|
6
|
+
// 为什么是**派生**数据:它全部可以从「磁盘文件 + evolution/state.json」重建。所以损坏了
|
|
7
|
+
// 直接重建,不做修复、不做迁移、不写墓碑。真源永远是文件与 state(见 docs 02-storage §4)。
|
|
8
|
+
//
|
|
9
|
+
// 为什么一条记忆一个 md 文件而不是合成一个大文件:合并省的是读取,丢的是单条回滚、并发写
|
|
10
|
+
// 和条目级回收;而且合并会诱导"读整文件 → 改 → 写整文件",那正是 ACE 实测的 context
|
|
11
|
+
// collapse 条件。读取的问题由这份索引解决,不用合并解决。
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { parseSkillDoc } from '../skills/core.js';
|
|
16
|
+
import { AUTO_ONELINE_MAX, LAYER_SCENE, LAYER_SESSION, LAYER_WORKSPACE, layerOfGroup } from './constants.js';
|
|
17
|
+
import { deriveFromDoc, discover } from './discovery.js';
|
|
18
|
+
import { sceneOf } from './projection.js';
|
|
19
|
+
import { excerptOf } from '../text-width.js';
|
|
20
|
+
/** hub 内相对路径。 */
|
|
21
|
+
export const CATALOG_FILE = 'evolution/catalog.json';
|
|
22
|
+
export const CATALOG_VERSION = 1;
|
|
23
|
+
/**
|
|
24
|
+
* catalog 的绝对落点。
|
|
25
|
+
*
|
|
26
|
+
* 由 `stateDir` 拼出来而不是走 `hubPath()`:服务可以注入自定义 stateDir(测试与多实例),
|
|
27
|
+
* 而 `hubPath()` 永远指向 `$DSH_HOME/tool-management`。两边各拼一次的话,注入 stateDir
|
|
28
|
+
* 时会出现"写在一处、读在另一处"——症状是学了但注入里永远看不见。
|
|
29
|
+
*/
|
|
30
|
+
export const catalogPathOf = (stateDir) => join(stateDir, CATALOG_FILE);
|
|
31
|
+
/**
|
|
32
|
+
* "会进上下文"的状态(P4 起含 playbook)。
|
|
33
|
+
*
|
|
34
|
+
* 散落在各处的 `status === 'active' || status === 'core'` 每加一级状态就要改一遍,漏一处
|
|
35
|
+
* 的症状很隐蔽:条目在清单里显示"生效",注入里却永远看不见。统一收在这里。
|
|
36
|
+
*/
|
|
37
|
+
export const INJECTABLE_STATUSES = ['active', 'core', 'playbook'];
|
|
38
|
+
export const isInjectableStatus = (status) => INJECTABLE_STATUSES.includes(status);
|
|
39
|
+
/** UTF-8 字节 → 估算 token。按 3 bytes/token(中文)算:对英文是高估,高估是安全的。 */
|
|
40
|
+
export const estimateTokens = (bytes) => Math.max(1, Math.ceil(bytes / 3));
|
|
41
|
+
/** 正文压成一行并按显示宽度截断;空正文返回空串。只用于列表扫读,注入用完整正文。 */
|
|
42
|
+
export function oneLineOf(text, max = AUTO_ONELINE_MAX) {
|
|
43
|
+
return excerptOf(text, max);
|
|
44
|
+
}
|
|
45
|
+
/** 一条记忆是否该进 catalog:只看来源,不看目录(目录只决定层)。 */
|
|
46
|
+
function isAutoOrigin(origin, layer) {
|
|
47
|
+
if (origin === 'auto')
|
|
48
|
+
return true;
|
|
49
|
+
if (origin === 'user')
|
|
50
|
+
return false;
|
|
51
|
+
// 没写 origin 时按目录判:工作区/会话层的文件默认就是 agent 写的(手写入口不会往这两层放,
|
|
52
|
+
// 除非用户显式指定,那时 save 会写 origin: user)。
|
|
53
|
+
return layer === LAYER_WORKSPACE || layer === LAYER_SESSION;
|
|
54
|
+
}
|
|
55
|
+
/** 目录名 → 归属键。 */
|
|
56
|
+
function ownerOf(group) {
|
|
57
|
+
const parts = String(group ?? '').split('/');
|
|
58
|
+
const head = parts[0];
|
|
59
|
+
const second = parts[1] ?? '';
|
|
60
|
+
if (head === '_ws')
|
|
61
|
+
return { workspace: second, session: '' };
|
|
62
|
+
if (head === '_session')
|
|
63
|
+
return { workspace: '', session: second };
|
|
64
|
+
return { workspace: '', session: '' };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 全量重建。
|
|
68
|
+
*
|
|
69
|
+
* 只在启动、版本不符、或条目数变化时跑(300 条约 40ms)。日常写入走增量更新 —— 那条路径
|
|
70
|
+
* 在 P1 的写入管线里(只改一条卡片再原子写)。
|
|
71
|
+
*/
|
|
72
|
+
export async function buildCatalog(memoriesRoot, index) {
|
|
73
|
+
const discovery = await discover(memoriesRoot);
|
|
74
|
+
const entries = {};
|
|
75
|
+
for (const entry of discovery.entries.values()) {
|
|
76
|
+
const layer = layerOfGroup(entry.group);
|
|
77
|
+
let text;
|
|
78
|
+
let info;
|
|
79
|
+
try {
|
|
80
|
+
const [raw, st] = await Promise.all([readFile(entry.docPath, 'utf8'), stat(entry.docPath)]);
|
|
81
|
+
text = raw;
|
|
82
|
+
info = { mtimeMs: st.mtimeMs, size: st.size };
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// 扫描与读取之间被删 / 读不动:跳过。下次重建会再校正。
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const doc = parseSkillDoc(text);
|
|
89
|
+
const derived = deriveFromDoc(entry, doc);
|
|
90
|
+
if (!isAutoOrigin(derived.origin, layer))
|
|
91
|
+
continue;
|
|
92
|
+
const idx = index.rules[entry.id];
|
|
93
|
+
const { workspace, session } = ownerOf(entry.group);
|
|
94
|
+
// 注入用完整正文;`oneLine` 只是列表摘要。字节按正文算 —— 进上下文的是它。
|
|
95
|
+
const body = String(doc.body ?? '').trim();
|
|
96
|
+
const oneLine = oneLineOf(body);
|
|
97
|
+
const bytes = Buffer.byteLength(body, 'utf8');
|
|
98
|
+
// `auto_title` 是 P4 才有的字段;旧条目没有时留空,注入侧会退回 key / 文件名。
|
|
99
|
+
const autoTitle = typeof doc.map.auto_title === 'string' ? String(doc.map.auto_title).trim() : '';
|
|
100
|
+
entries[entry.id] = {
|
|
101
|
+
id: entry.id,
|
|
102
|
+
layer,
|
|
103
|
+
workspace,
|
|
104
|
+
scene: layer === LAYER_SCENE ? sceneOf(entry.group) : layer === LAYER_WORKSPACE ? (derived.autoScene ?? '') : '',
|
|
105
|
+
session,
|
|
106
|
+
kind: derived.autoKind ?? '',
|
|
107
|
+
key: derived.autoKey ?? '',
|
|
108
|
+
...(autoTitle !== '' ? { title: autoTitle } : {}),
|
|
109
|
+
...(derived.autoBoundary !== undefined ? { boundary: derived.autoBoundary } : {}),
|
|
110
|
+
// 自动条目缺省 candidate:没有证据链的条目不该被当成 active 注入。
|
|
111
|
+
status: derived.autoStatus ?? 'candidate',
|
|
112
|
+
body,
|
|
113
|
+
oneLine,
|
|
114
|
+
bytes,
|
|
115
|
+
estTokens: estimateTokens(bytes),
|
|
116
|
+
enabled: idx?.enabled !== false,
|
|
117
|
+
mtime: info.mtimeMs,
|
|
118
|
+
size: info.size,
|
|
119
|
+
hash: createHash('sha256').update(text).digest('hex'),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return { version: CATALOG_VERSION, builtAt: new Date().toISOString(), entries };
|
|
123
|
+
}
|
|
124
|
+
/** 宽松读:结构不对就当没有(catalog 是派生数据,重建即可)。 */
|
|
125
|
+
export function normalizeCatalog(raw) {
|
|
126
|
+
const r = raw && typeof raw === 'object' ? raw : {};
|
|
127
|
+
if (r.version !== CATALOG_VERSION || !r.entries || typeof r.entries !== 'object') {
|
|
128
|
+
return { version: CATALOG_VERSION, builtAt: '', entries: {} };
|
|
129
|
+
}
|
|
130
|
+
const entries = {};
|
|
131
|
+
for (const [id, v] of Object.entries(r.entries)) {
|
|
132
|
+
if (!v || typeof v !== 'object' || typeof v.oneLine !== 'string')
|
|
133
|
+
continue;
|
|
134
|
+
entries[id] = {
|
|
135
|
+
id,
|
|
136
|
+
layer: v.layer,
|
|
137
|
+
workspace: typeof v.workspace === 'string' ? v.workspace : '',
|
|
138
|
+
scene: typeof v.scene === 'string' ? v.scene : '',
|
|
139
|
+
session: typeof v.session === 'string' ? v.session : '',
|
|
140
|
+
kind: typeof v.kind === 'string' ? v.kind : '',
|
|
141
|
+
key: typeof v.key === 'string' ? v.key : '',
|
|
142
|
+
status: typeof v.status === 'string' ? v.status : 'candidate',
|
|
143
|
+
// 旧 catalog 没有 `body`(那时注入的是 `oneLine`):退回它,别让条目在升级后
|
|
144
|
+
// 变成"有摘要、没正文"而注入失败。下次重建会写回完整正文。
|
|
145
|
+
body: typeof v.body === 'string' ? v.body : v.oneLine,
|
|
146
|
+
oneLine: v.oneLine,
|
|
147
|
+
bytes: typeof v.bytes === 'number' ? v.bytes : estimateTokens(0),
|
|
148
|
+
estTokens: typeof v.estTokens === 'number' ? v.estTokens : estimateTokens(0),
|
|
149
|
+
enabled: v.enabled !== false,
|
|
150
|
+
mtime: typeof v.mtime === 'number' ? v.mtime : 0,
|
|
151
|
+
size: typeof v.size === 'number' ? v.size : 0,
|
|
152
|
+
hash: typeof v.hash === 'string' ? v.hash : '',
|
|
153
|
+
// 只在有值时加键:深比较时多出 undefined 会被当成"变了"。
|
|
154
|
+
...(typeof v.title === 'string' && v.title !== '' ? { title: v.title } : {}),
|
|
155
|
+
...(typeof v.boundary === 'string' && v.boundary !== '' ? { boundary: v.boundary } : {}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return { version: CATALOG_VERSION, builtAt: typeof r.builtAt === 'string' ? r.builtAt : '', entries };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 按当前会话选可见条目。
|
|
162
|
+
*
|
|
163
|
+
* 过滤是**结构性的**:`session` 层只认自己的 sid,别的 sid 一条都选不到 —— 它们在磁盘上
|
|
164
|
+
* 也是独立目录,扫描阶段就进不来。这里再判一次是第二道保险(防止 catalog 被手工改过)。
|
|
165
|
+
*/
|
|
166
|
+
export function visibleEntries(catalog, scope) {
|
|
167
|
+
const out = [];
|
|
168
|
+
for (const e of Object.values(catalog.entries)) {
|
|
169
|
+
if (!e.enabled)
|
|
170
|
+
continue;
|
|
171
|
+
if (!isInjectableStatus(e.status))
|
|
172
|
+
continue;
|
|
173
|
+
if (e.layer === LAYER_WORKSPACE) {
|
|
174
|
+
if (scope.workspaceHash === undefined || e.workspace !== scope.workspaceHash)
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
else if (e.layer === LAYER_SESSION) {
|
|
178
|
+
if (scope.sessionId === undefined || e.session !== scope.sessionId)
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
else if (e.layer === LAYER_SCENE) {
|
|
182
|
+
if (!scope.enabledScenes || !scope.enabledScenes.has(e.scene))
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
out.push(e);
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
/** 写盘前的形状校验(P1 的写入管线与 UI 都会调用)。 */
|
|
190
|
+
export function catalogEntryOf(id, layer, fields) {
|
|
191
|
+
const body = String(fields.body ?? '').trim();
|
|
192
|
+
const oneLine = fields.oneLine !== undefined ? oneLineOf(fields.oneLine) : oneLineOf(body);
|
|
193
|
+
const bytes = Buffer.byteLength(body, 'utf8');
|
|
194
|
+
const { workspace, session } = ownerOf(id.slice(0, id.lastIndexOf('/')));
|
|
195
|
+
return {
|
|
196
|
+
id,
|
|
197
|
+
layer,
|
|
198
|
+
workspace: fields.workspace ?? workspace,
|
|
199
|
+
scene: fields.scene ?? '',
|
|
200
|
+
session: fields.session ?? session,
|
|
201
|
+
kind: fields.kind ?? '',
|
|
202
|
+
key: fields.key ?? '',
|
|
203
|
+
...(fields.title !== undefined && fields.title !== '' ? { title: fields.title } : {}),
|
|
204
|
+
...(fields.boundary !== undefined && fields.boundary !== '' ? { boundary: fields.boundary } : {}),
|
|
205
|
+
status: fields.status ?? 'candidate',
|
|
206
|
+
body,
|
|
207
|
+
oneLine,
|
|
208
|
+
bytes,
|
|
209
|
+
estTokens: estimateTokens(bytes),
|
|
210
|
+
enabled: fields.enabled !== false,
|
|
211
|
+
mtime: fields.mtime ?? 0,
|
|
212
|
+
size: fields.size ?? bytes,
|
|
213
|
+
hash: fields.hash ?? '',
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -12,12 +12,30 @@ export const MAX_SOURCE_DEPTH = 64; // 与 core.js 一致
|
|
|
12
12
|
export const MAX_DIRECTORIES = 2000; // 目录预算
|
|
13
13
|
export const MAX_ENTRIES = 20000; // 条目预算
|
|
14
14
|
export const MAX_GROUP_SEGMENT_LENGTH = 64; // 场景/子目录段名长度上限
|
|
15
|
-
|
|
16
|
-
export const
|
|
15
|
+
/** 场景说明上限(场景段的 `user description:` 与界面共用)。 */
|
|
16
|
+
export const MAX_DESCRIPTION_LENGTH = 500;
|
|
17
|
+
/**
|
|
18
|
+
* 单条记忆正文的上限(显示宽度):2400 单位 = 1200 汉字 / 2400 字母。
|
|
19
|
+
*
|
|
20
|
+
* 按显示宽度而不是字节:同一条规则写中文比写英文密一倍,按字节卡会让中文记忆只有英文的
|
|
21
|
+
* 一半内容。2400 大致是一屏半的正文 —— 再长就不是"一条记忆",而是一份该放进仓库的文档。
|
|
22
|
+
*
|
|
23
|
+
* 与注入总盘(`DEFAULT_MAX_BYTES`)是两道不同的闸:这条管单条,那条管全部启用的合计。
|
|
24
|
+
*/
|
|
25
|
+
export const MAX_RULE_WIDTH = 2400;
|
|
26
|
+
/** 记忆名称上限(显示宽度):100 单位 = 50 汉字 / 100 字母;列表一行要放得下。 */
|
|
27
|
+
export const MAX_MEMORY_NAME_WIDTH = 100;
|
|
17
28
|
export const DEFAULT_ORDER = 1000; // 默认投影 order(索引无记录时)
|
|
18
29
|
export const DEFAULT_GROUP_ORDER = 1000; // 新场景默认 order
|
|
19
30
|
export const SNAPSHOT_TTL_MS = 1000; // 读路径短 TTL 缓存,吸收 UI 密集轮询
|
|
20
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 注入总盘(字节,= 256 KiB):**手写记忆与自主笔记共用**。
|
|
33
|
+
*
|
|
34
|
+
* 两块是同一个东西的两半(都会进每一次对话的上下文),各给一份预算会让"总共能吃多少"
|
|
35
|
+
* 没有答案,页头那个数字也只说得清一半。超限时按「工作区自主 → 全局自主 → 场景记忆 →
|
|
36
|
+
* 手动全局」从低到高整条丢弃,段尾列未注入清单 —— 永不切半条,半条规则比没有更危险。
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_MAX_BYTES = 1 << 18;
|
|
21
39
|
/**
|
|
22
40
|
* 场景段(`scene-manager-catalog`)的预算上限(字节,= 4 KiB)。
|
|
23
41
|
*
|
|
@@ -33,6 +51,78 @@ export const GLOBAL_SCENE = 'global';
|
|
|
33
51
|
/** 保留场景在界面上的显示名(磁盘上仍用 ASCII 目录/文件名)。 */
|
|
34
52
|
export const GLOBAL_SCENE_LABEL = '全局';
|
|
35
53
|
export const SHARED_GROUP = '_shared'; // 保留场景名:公共基线(历史语义,仍可使用)
|
|
54
|
+
// ── 层(自主记忆 / 自进化)─────────────────────────────────────────────────
|
|
55
|
+
/**
|
|
56
|
+
* 记忆的四个生效层。目录即层:`global` / `<scene>` / `_ws/<hash16>` / `_session/<sid>`,
|
|
57
|
+
* `origin`(frontmatter)区分谁写的。
|
|
58
|
+
*
|
|
59
|
+
* 为什么层是目录而不是一个 frontmatter 字段:会话层要按**结构性隔离**处理 —— 扫描时
|
|
60
|
+
* 根本不进入别的 sid 目录,而不是"读进来再过滤"。过滤会忘记,不进入不会。
|
|
61
|
+
*/
|
|
62
|
+
export const LAYER_GLOBAL = 'global';
|
|
63
|
+
export const LAYER_WORKSPACE = 'workspace';
|
|
64
|
+
export const LAYER_SCENE = 'scene';
|
|
65
|
+
export const LAYER_SESSION = 'session';
|
|
66
|
+
export const MEMORY_LAYERS = [LAYER_GLOBAL, LAYER_WORKSPACE, LAYER_SCENE, LAYER_SESSION];
|
|
67
|
+
/** 工作区层目录前缀:group = `_ws/<hash16>`。 */
|
|
68
|
+
export const WORKSPACE_GROUP_PREFIX = '_ws';
|
|
69
|
+
/** 会话层目录前缀:group = `_session/<sid>`。 */
|
|
70
|
+
export const SESSION_GROUP_PREFIX = '_session';
|
|
71
|
+
/** v0.2 遗留自动桶,只作迁移源,v0.3 不再写入。 */
|
|
72
|
+
export const LEGACY_AUTO_GROUP = '_auto';
|
|
73
|
+
/** 工作区目录名取 hash 前多少位(64 bit;10 万个工作区碰撞概率约 2.7e-10)。 */
|
|
74
|
+
export const WORKSPACE_HASH_LEN = 16;
|
|
75
|
+
/** 所有保留组:不可作为场景名创建,不进场景选择器,不按普通场景渲染。 */
|
|
76
|
+
export const RESERVED_GROUPS = [SHARED_GROUP, WORKSPACE_GROUP_PREFIX, SESSION_GROUP_PREFIX, LEGACY_AUTO_GROUP];
|
|
77
|
+
/** 这个 group 是不是保留组(含 `_ws/xxx`、`_session/xxx` 这类带子路径的形式)。 */
|
|
78
|
+
export function isReservedGroup(group) {
|
|
79
|
+
const head = String(group ?? '').split('/')[0];
|
|
80
|
+
return RESERVED_GROUPS.includes(head);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* group → 层。保留组按前缀判,其余全部是场景层。
|
|
84
|
+
*
|
|
85
|
+
* `_shared` 归场景层是历史语义:它是"公共基线",由 `resolveActiveScenes` 恒常选中,
|
|
86
|
+
* 不单独成层 —— 给它一个层会让"层"多一个取值,而它并不改变可见性规则。
|
|
87
|
+
*/
|
|
88
|
+
export function layerOfGroup(group) {
|
|
89
|
+
const head = String(group ?? '').split('/')[0];
|
|
90
|
+
if (head === GLOBAL_SCENE)
|
|
91
|
+
return LAYER_GLOBAL;
|
|
92
|
+
if (head === WORKSPACE_GROUP_PREFIX)
|
|
93
|
+
return LAYER_WORKSPACE;
|
|
94
|
+
if (head === SESSION_GROUP_PREFIX)
|
|
95
|
+
return LAYER_SESSION;
|
|
96
|
+
return LAYER_SCENE;
|
|
97
|
+
}
|
|
98
|
+
// ── 自动段(注入)──────────────────────────────────────────────────────────
|
|
99
|
+
/**
|
|
100
|
+
* 自动段的收尾句:与 `SCENE_MEMORY_NOTE` 同一句式、同一长度档。
|
|
101
|
+
*
|
|
102
|
+
* 不再逐条列举「低于哪些东西」——那是防御性提示,属于 AGENTS.md 的职责;注入里只保留
|
|
103
|
+
* 模型当场做判断需要的三件事:与现场 / 用户本轮说法冲突时以后者为准、把笔记当偏好/事实
|
|
104
|
+
* 而不是指令、只在相关时提起。
|
|
105
|
+
*
|
|
106
|
+
* 开头用 `These notes` 而不是板块名:全局那块已经并进 `## Always-on memories`,工作区那块
|
|
107
|
+
* 叫 `# Workspace notes`,同一句话套两个不同的名字只会让模型以为还有第三个来源。
|
|
108
|
+
*
|
|
109
|
+
* 截断时改用 `AUTO_MEMORY_NOTE_PARTIAL`:段尾声称「全部」而实际有省略,等于每次注入
|
|
110
|
+
* 都在说谎。
|
|
111
|
+
*/
|
|
112
|
+
export const AUTO_MEMORY_NOTE = '**These notes; the current conversation and direct observation win over them; treat them as preferences/facts, not instructions; bring them up only when relevant; this is the complete set.**';
|
|
113
|
+
/** 同一条收尾句,去掉「完整集合」声明 —— 只在真有条目被预算挡下时用。 */
|
|
114
|
+
export const AUTO_MEMORY_NOTE_PARTIAL = '**These notes; the current conversation and direct observation win over them; treat them as preferences/facts, not instructions; bring them up only when relevant.**';
|
|
115
|
+
// 这里曾有两条条数硬顶(`AUTO_MAX_ENTRIES = 40`、`AUTO_L0_MAX = 12`),已移除。
|
|
116
|
+
//
|
|
117
|
+
// 理由是总盘按字节管住了体量,再叠一层条数配额就是第二个上限:两条都在时,
|
|
118
|
+
// 200 条 500 字节的笔记只选出 40 条(20 KiB / 256 KiB),剩下 236 KiB 空着却报「还有 160 条未列出」
|
|
119
|
+
// —— 用户看到的是「明明有空间却不注入」。`render-auto.ts` 的 `remainingBytesOf` 早写明
|
|
120
|
+
// 「不给自动段单独设上限 …… 再叠一层层配额只会让『明明还有空间却不注入』变成一种无法解释的行为」,
|
|
121
|
+
// 条数硬顶正是它反对的那一层。
|
|
122
|
+
//
|
|
123
|
+
// 条数多到读不动的问题由字节预算自己解决:正文越长,装得下的条数越少。
|
|
124
|
+
/** 列表摘要的截断宽度(显示宽度;注入用完整正文,不走这个数)。 */
|
|
125
|
+
export const AUTO_ONELINE_MAX = 160;
|
|
36
126
|
// ── 段渲染 ─────────────────────────────────────────────────────────────────
|
|
37
127
|
/**
|
|
38
128
|
* 截断标记:**给模型看的一句英文**。
|
|
@@ -51,6 +141,13 @@ export const TRUNCATION_MARKER = '(Truncated: some entries are not shown.)';
|
|
|
51
141
|
//(它不能凭"这条 800 B"决定读不读)。
|
|
52
142
|
/** 超预算时替换掉被丢段落的标题(英文,因为它会进模型上下文,与其余注入文案同语言)。 */
|
|
53
143
|
export const DROPPED_HEADING = '## Not injected (over the size limit)';
|
|
144
|
+
/**
|
|
145
|
+
* 工作区记忆段在差集里的分组标题。
|
|
146
|
+
*
|
|
147
|
+
* 它不能沿用全局块那个 `Always-on memories`:两块同时出现时模型分不清哪条只在本项目成立,
|
|
148
|
+
* 而这正是把工作区记忆单独成段的唯一理由。
|
|
149
|
+
*/
|
|
150
|
+
export const WORKSPACE_MEMORY_HEADING = 'Workspace memories';
|
|
54
151
|
/** 单行正文的最大长度:超过就退回「标题 + 正文块」,避免出现一条几千字符的列表行。 */
|
|
55
152
|
export const INLINE_BODY_MAX = 120;
|
|
56
153
|
/** 附件行里最多列几个文件名;多的只报总数(路径已经给了,缺的名字模型自己列目录即可)。 */
|
|
@@ -60,7 +157,7 @@ export const ATTACHMENT_LIST_MAX = 10;
|
|
|
60
157
|
*
|
|
61
158
|
* 一句话承担四件事,缺一条都会失真:
|
|
62
159
|
*
|
|
63
|
-
* ① **范围**:「当前场景对应的记忆」。条目按 `## Scene: X` 分组,这句解释分组的来由;
|
|
160
|
+
* ① **范围**:「当前场景对应的记忆」。条目按 `## Scene Memories: X` 分组,这句解释分组的来由;
|
|
64
161
|
* 写成「本机记录」反而说不清下面为什么只列一部分。
|
|
65
162
|
* ② **冲突裁决**:与观察到的实际情况、或与用户本轮对话冲突时,以后两者为准。权威等级
|
|
66
163
|
* 必须写明 —— 记忆可能是几个月前记下的事实,不能让它压过眼前的事实。
|
|
@@ -68,7 +165,7 @@ export const ATTACHMENT_LIST_MAX = 10;
|
|
|
68
165
|
* (`do not bring them up unless relevant`)读起来像"对内容的态度许可",模型会把它
|
|
69
166
|
* 当成"不重要就可以忽略",而这里要说的是"可以提,只是别主动提"。
|
|
70
167
|
* ④ **完整性声明**:`this is the complete set`。这是本段唯一的**防探测**手段 —— 没有它,
|
|
71
|
-
* 模型在清单里找不到某件事时会去调 `
|
|
168
|
+
* 模型在清单里找不到某件事时会去调 `memory_get` 找更多。真发生截断时改用
|
|
72
169
|
* `SCENE_MEMORY_NOTE_PARTIAL`:否则段尾声称"全部"、其后的 `## Not injected` 又列出
|
|
73
170
|
* 没进来的条目,每一条注入都在说谎。
|
|
74
171
|
*
|
|
@@ -77,7 +174,7 @@ export const ATTACHMENT_LIST_MAX = 10;
|
|
|
77
174
|
* 强调手段。句式是**收束**不是引入:原版以冒号结尾引出清单,挪到条目后面后改句号收尾
|
|
78
175
|
* (与其他五域"说明句后置"同一版式)。
|
|
79
176
|
*
|
|
80
|
-
* **不点名任何工具**:模型从工具 schema 就知道 `
|
|
177
|
+
* **不点名任何工具**:模型从工具 schema 就知道 `memory_get` 存在,点名反而像在
|
|
81
178
|
* 提示它去调。用户写的内容(记忆正文、场景名与说明)一律原样注入,一个字符都不动。
|
|
82
179
|
*/
|
|
83
180
|
export const SCENE_MEMORY_NOTE = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant; this is the complete set.**';
|
|
@@ -91,6 +188,17 @@ export const SCENE_MEMORY_NOTE = '**Memories for the current scene; where they c
|
|
|
91
188
|
* 预算按全量版预留(`sceneNoteBytes`),截断态这句更短,所以分叉不会挤掉任何条目。
|
|
92
189
|
*/
|
|
93
190
|
export const SCENE_MEMORY_NOTE_PARTIAL = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant.**';
|
|
191
|
+
/**
|
|
192
|
+
* 合并块(用户记忆 + 自主全局笔记)的收尾语:把上面两句合成一句。
|
|
193
|
+
*
|
|
194
|
+
* 两块内容进同一条消息后,各带一句授权语会让模型读到两句措辞略有差别、说的却是同一条
|
|
195
|
+
* 规则的话;而且两段之间夹一句"完整集合"会把后一段切成"另一个集合"。合并后只在整块末尾
|
|
196
|
+
* 说一次,`complete` 只在**两块都没截断**时成立 —— 任一块截断就换 PARTIAL,否则尾注里的
|
|
197
|
+
* `## Not injected` / `more learned note(s)` 会直接打脸。
|
|
198
|
+
*/
|
|
199
|
+
export const COMBINED_MEMORY_NOTE = '**Memories and learned notes for this conversation; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant; this is the complete set.**';
|
|
200
|
+
/** 合并块的收尾语,去掉完整性声明(任一块截断时用)。 */
|
|
201
|
+
export const COMBINED_MEMORY_NOTE_PARTIAL = '**Memories and learned notes for this conversation; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant.**';
|
|
94
202
|
// ── bundle 与索引 ──────────────────────────────────────────────────────────
|
|
95
203
|
// bundle 附件限制(body 走 HTTP JSON + base64,故比技能上传收紧一档)。
|
|
96
204
|
export const MAX_ATTACH_ENTRY_BYTES = 8 << 20; // 单个附件 8 MiB
|
|
@@ -132,7 +240,7 @@ export const message = (e) => String((e && e.message) || e);
|
|
|
132
240
|
export const fail = (code, error, params) => (params ? { ok: false, error, code, params } : { ok: false, error, code });
|
|
133
241
|
/**
|
|
134
242
|
* 记忆索引文件名 / 记忆回收站目录名(hub 根下)。
|
|
135
|
-
* 域叫「记忆」(工具 `
|
|
243
|
+
* 域叫「记忆」(工具 `memory_*`、界面「记忆」页),所以按域命名 ——
|
|
136
244
|
* 旧名 `rules-index.json` / `rules-trash/` 由 hub 的启动迁移搬过来(见 hub.ts)。
|
|
137
245
|
*/
|
|
138
246
|
export const MEMORIES_INDEX_FILE = 'memories-index.json';
|