@co-engram/openclaw 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/adapter.d.ts +36 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +330 -0
- package/dist/adapter.js.map +1 -0
- package/dist/auto-onboard.d.ts +19 -0
- package/dist/auto-onboard.d.ts.map +1 -0
- package/dist/auto-onboard.js +35 -0
- package/dist/auto-onboard.js.map +1 -0
- package/dist/entry-example.d.ts +10 -0
- package/dist/entry-example.d.ts.map +1 -0
- package/dist/entry-example.js +10 -0
- package/dist/entry-example.js.map +1 -0
- package/dist/entry.d.ts +96 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +228 -0
- package/dist/entry.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schemas.d.ts +35 -0
- package/dist/json-schemas.d.ts.map +1 -0
- package/dist/json-schemas.js +432 -0
- package/dist/json-schemas.js.map +1 -0
- package/dist/list-intent-detector.d.ts +20 -0
- package/dist/list-intent-detector.d.ts.map +1 -0
- package/dist/list-intent-detector.js +50 -0
- package/dist/list-intent-detector.js.map +1 -0
- package/dist/llm-client.d.ts +29 -0
- package/dist/llm-client.d.ts.map +1 -0
- package/dist/llm-client.js +112 -0
- package/dist/llm-client.js.map +1 -0
- package/dist/maintenance-runtime.d.ts +31 -0
- package/dist/maintenance-runtime.d.ts.map +1 -0
- package/dist/maintenance-runtime.js +61 -0
- package/dist/maintenance-runtime.js.map +1 -0
- package/dist/memory-tools.d.ts +82 -0
- package/dist/memory-tools.d.ts.map +1 -0
- package/dist/memory-tools.js +237 -0
- package/dist/memory-tools.js.map +1 -0
- package/dist/plugin-entry.d.ts +98 -0
- package/dist/plugin-entry.d.ts.map +1 -0
- package/dist/plugin-entry.js +444 -0
- package/dist/plugin-entry.js.map +1 -0
- package/dist/prompt-builder.d.ts +48 -0
- package/dist/prompt-builder.d.ts.map +1 -0
- package/dist/prompt-builder.js +33 -0
- package/dist/prompt-builder.js.map +1 -0
- package/dist/types.d.ts +236 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/dist/viewer-loader.d.ts +36 -0
- package/dist/viewer-loader.d.ts.map +1 -0
- package/dist/viewer-loader.js +45 -0
- package/dist/viewer-loader.js.map +1 -0
- package/openclaw.plugin.json +137 -0
- package/package.json +61 -0
- package/scripts/setup.mjs +231 -0
- package/scripts/sync-deps.mjs +247 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-client.js","sourceRoot":"","sources":["../src/llm-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B;IAG3C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;QAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;QACzD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,OAAO,SAAS,CAAC;QAE3C,8DAA8D;QAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAQ,CAAC;QAC7D,MAAM,UAAU,GACd,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC;QACxC,IAAI,CAAC,UAAU;YAAE,OAAO,SAAS,CAAC;QAElC,MAAM,CAAC,WAAW,EAAE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C;YACjE,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7C,OAAO,SAAS,CAAC,IAAI,EAAE,CAAC;YAC1B,CAAC;YAED,qDAAqD;YACrD,MAAM,IAAI,KAAK,CACb,6CAA6C,YAAY,IAAI,SAAS,GAAG,CAC1E,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzC,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC5D,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,OAAO,GAAG,QAAQ,mBAAmB,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw Plugin Maintenance Runtime(P4 D.2)
|
|
3
|
+
*
|
|
4
|
+
* 把 @co-engram/core 的 MaintenanceEngine 桥接到 OpenClaw 插件生命周期。
|
|
5
|
+
*
|
|
6
|
+
* 职责:
|
|
7
|
+
* - 创建 DreamingScheduler + MaintenanceEngine(如果尚未提供)
|
|
8
|
+
* - 启动 setInterval + unref 自托管调度(不依赖 OpenClaw 的 cron API)
|
|
9
|
+
* - 把 MaintenanceConfig.trash 透传到 scheduler.deepOptions.trash
|
|
10
|
+
* - 提供 stop() 供宿主在 shutdown 时清理
|
|
11
|
+
*
|
|
12
|
+
* 使用:
|
|
13
|
+
* const { stop } = startMaintenanceRuntime({ repository, signalSink, dreamingScheduler })
|
|
14
|
+
* // ... 应用运行期间自动维护
|
|
15
|
+
* process.on('SIGTERM', () => stop())
|
|
16
|
+
*
|
|
17
|
+
* @module @co-engram/openclaw
|
|
18
|
+
*/
|
|
19
|
+
import { MaintenanceEngine, type MaintenanceConfig, type MaintenanceDeps } from "@co-engram/core";
|
|
20
|
+
/**
|
|
21
|
+
* 启动维护运行时
|
|
22
|
+
*
|
|
23
|
+
* 如果 deps.dreamingScheduler 未提供,会自动创建一个,并应用 trash 透传。
|
|
24
|
+
*
|
|
25
|
+
* @returns stop 函数(停止所有定时器)
|
|
26
|
+
*/
|
|
27
|
+
export declare function startMaintenanceRuntime(deps: MaintenanceDeps, config?: MaintenanceConfig): {
|
|
28
|
+
readonly engine: MaintenanceEngine;
|
|
29
|
+
readonly stop: () => void;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=maintenance-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintenance-runtime.d.ts","sourceRoot":"","sources":["../src/maintenance-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,iBAAiB,EAGjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAGrB,MAAM,iBAAiB,CAAC;AAYzB;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,eAAe,EACrB,MAAM,GAAE,iBAAsB,GAC7B;IAAE,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAiCnE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw Plugin Maintenance Runtime(P4 D.2)
|
|
3
|
+
*
|
|
4
|
+
* 把 @co-engram/core 的 MaintenanceEngine 桥接到 OpenClaw 插件生命周期。
|
|
5
|
+
*
|
|
6
|
+
* 职责:
|
|
7
|
+
* - 创建 DreamingScheduler + MaintenanceEngine(如果尚未提供)
|
|
8
|
+
* - 启动 setInterval + unref 自托管调度(不依赖 OpenClaw 的 cron API)
|
|
9
|
+
* - 把 MaintenanceConfig.trash 透传到 scheduler.deepOptions.trash
|
|
10
|
+
* - 提供 stop() 供宿主在 shutdown 时清理
|
|
11
|
+
*
|
|
12
|
+
* 使用:
|
|
13
|
+
* const { stop } = startMaintenanceRuntime({ repository, signalSink, dreamingScheduler })
|
|
14
|
+
* // ... 应用运行期间自动维护
|
|
15
|
+
* process.on('SIGTERM', () => stop())
|
|
16
|
+
*
|
|
17
|
+
* @module @co-engram/openclaw
|
|
18
|
+
*/
|
|
19
|
+
import { MaintenanceEngine, createDreamingScheduler, } from "@co-engram/core";
|
|
20
|
+
function trashToDeepOptions(trash) {
|
|
21
|
+
if (!trash?.enabled)
|
|
22
|
+
return undefined;
|
|
23
|
+
return {
|
|
24
|
+
afterDays: trash.afterDays,
|
|
25
|
+
purgeAfterDays: trash.purgeAfterDays,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 启动维护运行时
|
|
30
|
+
*
|
|
31
|
+
* 如果 deps.dreamingScheduler 未提供,会自动创建一个,并应用 trash 透传。
|
|
32
|
+
*
|
|
33
|
+
* @returns stop 函数(停止所有定时器)
|
|
34
|
+
*/
|
|
35
|
+
export function startMaintenanceRuntime(deps, config = {}) {
|
|
36
|
+
const schedulerConfig = {
|
|
37
|
+
lightIntervalMs: config.lightIntervalMs,
|
|
38
|
+
deepIntervalMs: config.deepIntervalMs,
|
|
39
|
+
remIntervalMs: config.remIntervalMs,
|
|
40
|
+
deepOptions: { trash: trashToDeepOptions(config.trash) },
|
|
41
|
+
};
|
|
42
|
+
const dreamingScheduler = deps.dreamingScheduler ??
|
|
43
|
+
createDreamingScheduler(deps.repository, schedulerConfig);
|
|
44
|
+
const engine = new MaintenanceEngine({
|
|
45
|
+
repository: deps.repository,
|
|
46
|
+
signalSink: deps.signalSink,
|
|
47
|
+
dreamingScheduler,
|
|
48
|
+
...(deps.effectivenessTracker
|
|
49
|
+
? { effectivenessTracker: deps.effectivenessTracker }
|
|
50
|
+
: {}),
|
|
51
|
+
...(deps.dataRoot ? { dataRoot: deps.dataRoot } : {}),
|
|
52
|
+
}, config);
|
|
53
|
+
engine.start();
|
|
54
|
+
return {
|
|
55
|
+
engine,
|
|
56
|
+
stop: () => {
|
|
57
|
+
engine.stop();
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=maintenance-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintenance-runtime.js","sourceRoot":"","sources":["../src/maintenance-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GAMxB,MAAM,iBAAiB,CAAC;AAEzB,SAAS,kBAAkB,CACzB,KAAyC;IAEzC,IAAI,CAAC,KAAK,EAAE,OAAO;QAAE,OAAO,SAAS,CAAC;IACtC,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAqB,EACrB,SAA4B,EAAE;IAE9B,MAAM,eAAe,GAA2B;QAC9C,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,WAAW,EAAE,EAAE,KAAK,EAAE,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;KACzD,CAAC;IAEF,MAAM,iBAAiB,GACrB,IAAI,CAAC,iBAAiB;QACtB,uBAAuB,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IAE5D,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAClC;QACE,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,iBAAiB;QACjB,GAAG,CAAC,IAAI,CAAC,oBAAoB;YAC3B,CAAC,CAAC,EAAE,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAAE;YACrD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,EACD,MAAM,CACP,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,OAAO;QACL,MAAM;QACN,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw 兼容的 memory_search / memory_get 工具
|
|
3
|
+
*
|
|
4
|
+
* 这两个工具是 co-engram 对 OpenClaw memory 标准协议的适配层:
|
|
5
|
+
* - 触发 OpenClaw 核心的 memory section 系统提示注入
|
|
6
|
+
* - 提供与 memory-core / flexmem-local 兼容的 schema
|
|
7
|
+
* - 内部仍走 co-engram 的 FTS + 图检索 + RPE 强化闭环
|
|
8
|
+
*
|
|
9
|
+
* 与 co-engram 原生 25 个工具的关系:
|
|
10
|
+
* - memory_search 是 engram_search 的"对外友好版"(隐藏内部术语)
|
|
11
|
+
* - memory_get 是 engram_get 的"对外友好版"(简化 schema)
|
|
12
|
+
* - 25 个原生工具仍全部注册,提供 synapse/RPE/metacognition 等高级功能
|
|
13
|
+
*
|
|
14
|
+
* @module @co-engram/openclaw
|
|
15
|
+
*/
|
|
16
|
+
import { type ToolContext, type Language } from "@co-engram/core";
|
|
17
|
+
import type { OpenClawToolDescriptor } from "./types.js";
|
|
18
|
+
/**
|
|
19
|
+
* memory_search 返回的单条结果(简化 schema,对 LLM 友好)
|
|
20
|
+
*
|
|
21
|
+
* 注:title 字段非 OpenClaw memory slot 协议核心字段,仅用于 adapter markdown 渲染
|
|
22
|
+
* 时显示可读标题(避免渲染为"(无标题)")。OpenClaw 核心协议不会因多出这个字段
|
|
23
|
+
* 报错(JSON schema 是 input 端,output 端是 ToolExecuteResult 不受 schema 约束)。
|
|
24
|
+
*/
|
|
25
|
+
export interface MemorySearchHit {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly title?: string;
|
|
28
|
+
readonly content: string;
|
|
29
|
+
readonly score: number;
|
|
30
|
+
readonly metadata: {
|
|
31
|
+
readonly createdAt: string;
|
|
32
|
+
readonly importance: number;
|
|
33
|
+
readonly truthScore?: number;
|
|
34
|
+
readonly tags: readonly string[];
|
|
35
|
+
readonly kind: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* memory_get 返回的富结构(单条 engram 详情)
|
|
40
|
+
*/
|
|
41
|
+
export interface MemoryGetResult {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly content: string;
|
|
44
|
+
readonly metadata: {
|
|
45
|
+
readonly createdAt: string;
|
|
46
|
+
readonly updatedAt: string;
|
|
47
|
+
readonly createdBy: string;
|
|
48
|
+
readonly importance: number;
|
|
49
|
+
readonly truthScore?: number;
|
|
50
|
+
readonly reinforcementCount: number;
|
|
51
|
+
readonly lastReinforcedAt: string | null;
|
|
52
|
+
readonly tags: readonly string[];
|
|
53
|
+
readonly kind: string;
|
|
54
|
+
readonly verificationStatus?: string;
|
|
55
|
+
};
|
|
56
|
+
readonly relatedIds: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 创建 memory_search 工具(OpenClaw 兼容)
|
|
60
|
+
*
|
|
61
|
+
* 内部调用 ctx.searchOrchestrator + ctx.repository.readDigest,
|
|
62
|
+
* 包装为 OpenClaw 期望的 ToolDescriptor。
|
|
63
|
+
*
|
|
64
|
+
* @param ctx co-engram ToolContext(含 repository + searchOrchestrator)
|
|
65
|
+
* @param language 错误消息语言
|
|
66
|
+
*/
|
|
67
|
+
export declare function createMemorySearchTool(ctx: ToolContext, language?: Language): OpenClawToolDescriptor;
|
|
68
|
+
/**
|
|
69
|
+
* 创建 memory_get 工具(OpenClaw 兼容)
|
|
70
|
+
*
|
|
71
|
+
* 返回单条 engram 的富结构(含完整 content + 元数据 + 相关 id 列表)。
|
|
72
|
+
* synapse 图不展开(relatedIds 仅返回 id),需要详情走 synapse_list。
|
|
73
|
+
*
|
|
74
|
+
* @param ctx co-engram ToolContext
|
|
75
|
+
* @param language 错误消息语言
|
|
76
|
+
*/
|
|
77
|
+
export declare function createMemoryGetTool(ctx: ToolContext, language?: Language): OpenClawToolDescriptor;
|
|
78
|
+
/**
|
|
79
|
+
* 批量创建两个 memory 工具
|
|
80
|
+
*/
|
|
81
|
+
export declare function createMemoryTools(ctx: ToolContext, language?: Language): readonly OpenClawToolDescriptor[];
|
|
82
|
+
//# sourceMappingURL=memory-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-tools.d.ts","sourceRoot":"","sources":["../src/memory-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,QAAQ,EAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,YAAY,CAAC;AAGpB;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;QACjC,QAAQ,CAAC,IAAI,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penClaw memory 标准协议的适配层:
|
|
5
|
+
* - 触发 OpenClaw 核心的 memory section 系统提示注入
|
|
6
|
+
* - 提供与 memory-core / flexmem-local 兼容的 schema
|
|
7
|
+
* - 内部仍走 co-engram 的 FTS + 图检索 + RPE 强化闭环
|
|
8
|
+
*
|
|
9
|
+
* 与 co-engram 原生 25 个工具的关系:
|
|
10
|
+
* - memory_search 是 engram_search 的"对外友好版"(隐藏内部术语)
|
|
11
|
+
* - memory_get 是 engram_get 的"对外友好版"(简化 schema)
|
|
12
|
+
* - 25 个原生工具仍全部注册,提供 synapse/RPE/metacognition 等高级功能
|
|
13
|
+
*
|
|
14
|
+
* @module @co-engram/openclaw
|
|
15
|
+
*/
|
|
16
|
+
import { DEFAULT_LANGUAGE, localizeToolDescription, } from "@co-engram/core";
|
|
17
|
+
import { toToolResult as toAdaptedToolResult } from "./adapter.js";
|
|
18
|
+
/**
|
|
19
|
+
* memory_search 的 JSON Schema
|
|
20
|
+
*/
|
|
21
|
+
const MEMORY_SEARCH_SCHEMA = {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
properties: {
|
|
25
|
+
query: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Natural language search query.",
|
|
28
|
+
minLength: 1,
|
|
29
|
+
},
|
|
30
|
+
maxResults: {
|
|
31
|
+
type: "number",
|
|
32
|
+
description: "Maximum number of results to return (default: 5, max: 20).",
|
|
33
|
+
minimum: 1,
|
|
34
|
+
maximum: 20,
|
|
35
|
+
},
|
|
36
|
+
minScore: {
|
|
37
|
+
type: "number",
|
|
38
|
+
description: "Minimum relevance score (0-1). Results below this are filtered out.",
|
|
39
|
+
minimum: 0,
|
|
40
|
+
maximum: 1,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ["query"],
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* memory_get 的 JSON Schema
|
|
47
|
+
*/
|
|
48
|
+
const MEMORY_GET_SCHEMA = {
|
|
49
|
+
type: "object",
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
properties: {
|
|
52
|
+
id: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "Engram ID returned by memory_search.",
|
|
55
|
+
minLength: 1,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["id"],
|
|
59
|
+
};
|
|
60
|
+
const DEFAULT_MAX_RESULTS = 5;
|
|
61
|
+
const HARD_MAX_RESULTS = 20;
|
|
62
|
+
const DEFAULT_MIN_SCORE = 0;
|
|
63
|
+
const CONTENT_SUMMARY_LIMIT = 500;
|
|
64
|
+
function toErrorResult(error, language) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
const prefix = language === "zh" ? "错误" : "Error";
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: `${prefix}: ${message}` }],
|
|
69
|
+
details: { ok: false, error: message },
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function clampMaxResults(value) {
|
|
73
|
+
const n = typeof value === "number" ? value : DEFAULT_MAX_RESULTS;
|
|
74
|
+
return Math.max(1, Math.min(n, HARD_MAX_RESULTS));
|
|
75
|
+
}
|
|
76
|
+
function clampMinScore(value) {
|
|
77
|
+
const n = typeof value === "number" ? value : DEFAULT_MIN_SCORE;
|
|
78
|
+
return Math.max(0, Math.min(n, 1));
|
|
79
|
+
}
|
|
80
|
+
function truncate(text, limit) {
|
|
81
|
+
if (text.length <= limit)
|
|
82
|
+
return text;
|
|
83
|
+
return text.slice(0, limit) + "...";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 把 EngramDigest 转为 MemorySearchHit
|
|
87
|
+
*
|
|
88
|
+
* 隐藏 co-engram 内部术语(emotionalValence / freshness / sourceType 等),
|
|
89
|
+
* 只暴露对 LLM 决策有用的字段。
|
|
90
|
+
*/
|
|
91
|
+
function digestToHit(digest, score) {
|
|
92
|
+
return {
|
|
93
|
+
id: digest.id,
|
|
94
|
+
title: digest.title,
|
|
95
|
+
content: truncate(digest.summary || digest.title, CONTENT_SUMMARY_LIMIT),
|
|
96
|
+
score,
|
|
97
|
+
metadata: {
|
|
98
|
+
createdAt: digest.updatedAt,
|
|
99
|
+
importance: digest.importance,
|
|
100
|
+
tags: digest.domainTags,
|
|
101
|
+
kind: digest.kind,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 创建 memory_search 工具(OpenClaw 兼容)
|
|
107
|
+
*
|
|
108
|
+
* 内部调用 ctx.searchOrchestrator + ctx.repository.readDigest,
|
|
109
|
+
* 包装为 OpenClaw 期望的 ToolDescriptor。
|
|
110
|
+
*
|
|
111
|
+
* @param ctx co-engram ToolContext(含 repository + searchOrchestrator)
|
|
112
|
+
* @param language 错误消息语言
|
|
113
|
+
*/
|
|
114
|
+
export function createMemorySearchTool(ctx, language = DEFAULT_LANGUAGE) {
|
|
115
|
+
return {
|
|
116
|
+
name: "memory_search",
|
|
117
|
+
label: "Memory Search",
|
|
118
|
+
description: localizeToolDescription("memory_search", language, "Search team memory (engrams) using natural language. Returns relevant memory snippets with relevance scores. Call this when the user asks about past decisions, preferences, people, dates, or project context."),
|
|
119
|
+
parameters: MEMORY_SEARCH_SCHEMA,
|
|
120
|
+
async execute(_toolCallId, params) {
|
|
121
|
+
try {
|
|
122
|
+
const p = (params ?? {});
|
|
123
|
+
const query = typeof p.query === "string" ? p.query : "";
|
|
124
|
+
if (!query.trim()) {
|
|
125
|
+
throw new Error("query is required and must be non-empty");
|
|
126
|
+
}
|
|
127
|
+
if (!ctx.searchOrchestrator) {
|
|
128
|
+
throw new Error("SearchOrchestrator not available");
|
|
129
|
+
}
|
|
130
|
+
const maxResults = clampMaxResults(p.maxResults);
|
|
131
|
+
const minScore = clampMinScore(p.minScore);
|
|
132
|
+
const rawResults = ctx.searchOrchestrator.search(query, undefined, maxResults);
|
|
133
|
+
const hits = [];
|
|
134
|
+
for (const r of rawResults) {
|
|
135
|
+
if (r.score < minScore)
|
|
136
|
+
continue;
|
|
137
|
+
const digest = ctx.repository.readDigest(r.id);
|
|
138
|
+
if (!digest)
|
|
139
|
+
continue;
|
|
140
|
+
hits.push(digestToHit(digest, r.score));
|
|
141
|
+
}
|
|
142
|
+
return toAdaptedToolResult({ results: hits, total: hits.length }, ctx);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return toErrorResult(error, language);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 创建 memory_get 工具(OpenClaw 兼容)
|
|
152
|
+
*
|
|
153
|
+
* 返回单条 engram 的富结构(含完整 content + 元数据 + 相关 id 列表)。
|
|
154
|
+
* synapse 图不展开(relatedIds 仅返回 id),需要详情走 synapse_list。
|
|
155
|
+
*
|
|
156
|
+
* @param ctx co-engram ToolContext
|
|
157
|
+
* @param language 错误消息语言
|
|
158
|
+
*/
|
|
159
|
+
export function createMemoryGetTool(ctx, language = DEFAULT_LANGUAGE) {
|
|
160
|
+
return {
|
|
161
|
+
name: "memory_get",
|
|
162
|
+
label: "Memory Get",
|
|
163
|
+
description: localizeToolDescription("memory_get", language, "Read full content of a single memory (engram) by ID. Returns content, metadata (importance, truthScore, reinforcementCount), and related memory IDs. Use after memory_search to dive into specifics."),
|
|
164
|
+
parameters: MEMORY_GET_SCHEMA,
|
|
165
|
+
async execute(_toolCallId, params) {
|
|
166
|
+
try {
|
|
167
|
+
const p = (params ?? {});
|
|
168
|
+
const id = typeof p.id === "string" ? p.id : "";
|
|
169
|
+
if (!id.trim()) {
|
|
170
|
+
throw new Error("id is required");
|
|
171
|
+
}
|
|
172
|
+
const engram = ctx.repository.readEngram(id);
|
|
173
|
+
const outgoingFile = safeReadSynapses(ctx, id);
|
|
174
|
+
const relatedIds = extractRelatedIds(id, outgoingFile);
|
|
175
|
+
return toAdaptedToolResult({
|
|
176
|
+
id: engram.id,
|
|
177
|
+
content: engram.content,
|
|
178
|
+
metadata: {
|
|
179
|
+
createdAt: engram.createdAt,
|
|
180
|
+
updatedAt: engram.updatedAt,
|
|
181
|
+
createdBy: engram.createdBy,
|
|
182
|
+
importance: engram.importance,
|
|
183
|
+
tags: engram.domainTags,
|
|
184
|
+
kind: engram.kind,
|
|
185
|
+
reinforcementCount: engram.effectiveRetrievals + engram.failedUses,
|
|
186
|
+
lastReinforcedAt: engram.lastEffectiveAt ?? null,
|
|
187
|
+
...(engram.confidence !== undefined
|
|
188
|
+
? { truthScore: engram.confidence }
|
|
189
|
+
: {}),
|
|
190
|
+
...(engram.verificationStatus
|
|
191
|
+
? { verificationStatus: engram.verificationStatus }
|
|
192
|
+
: {}),
|
|
193
|
+
},
|
|
194
|
+
relatedIds,
|
|
195
|
+
}, ctx);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return toErrorResult(error, language);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 安全读取 synapses(engram 可能没有 synapses 文件)
|
|
205
|
+
*/
|
|
206
|
+
function safeReadSynapses(ctx, id) {
|
|
207
|
+
try {
|
|
208
|
+
const file = ctx.repository.readSynapses(id);
|
|
209
|
+
return file ?? null;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 从 synapse outgoing 抽取邻居 id(不展开详情,不扫 incoming 以避免全表扫描)
|
|
217
|
+
*/
|
|
218
|
+
function extractRelatedIds(selfId, bundle) {
|
|
219
|
+
if (!bundle)
|
|
220
|
+
return [];
|
|
221
|
+
const ids = new Set();
|
|
222
|
+
for (const s of bundle.outgoing) {
|
|
223
|
+
if (s.to && s.to !== selfId)
|
|
224
|
+
ids.add(s.to);
|
|
225
|
+
}
|
|
226
|
+
return Array.from(ids);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 批量创建两个 memory 工具
|
|
230
|
+
*/
|
|
231
|
+
export function createMemoryTools(ctx, language = DEFAULT_LANGUAGE) {
|
|
232
|
+
return [
|
|
233
|
+
createMemorySearchTool(ctx, language),
|
|
234
|
+
createMemoryGetTool(ctx, language),
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=memory-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-tools.js","sourceRoot":"","sources":["../src/memory-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GAIxB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,cAAc,CAAC;AA4CnE;;GAEG;AACH,MAAM,oBAAoB,GAAqB;IAC7C,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gCAAgC;YAC7C,SAAS,EAAE,CAAC;SACb;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4DAA4D;YACzE,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,EAAE;SACZ;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,qEAAqE;YACvE,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;SACX;KACF;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,iBAAiB,GAAqB;IAC1C,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,EAAE,EAAE;YACF,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,sCAAsC;YACnD,SAAS,EAAE,CAAC;SACb;KACF;IACD,QAAQ,EAAE,CAAC,I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
|
+
*
|
|
4
|
+
* 用户在 openclaw 项目里通过如下方式使用:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { definePluginEntry } from 'openclaw/plugin-sdk/plugin-entry'
|
|
8
|
+
* import { registerCoEngramTools } from '@co-engram/openclaw'
|
|
9
|
+
* import { join } from 'node:path'
|
|
10
|
+
*
|
|
11
|
+
* export default definePluginEntry({
|
|
12
|
+
* id: 'co-engram',
|
|
13
|
+
* name: 'Co-Engram',
|
|
14
|
+
* description: 'Team memory with neuroscience-inspired plasticity',
|
|
15
|
+
* register(api) {
|
|
16
|
+
* registerCoEngramTools(api, {
|
|
17
|
+
* dataRoot: join(process.env.HOME!, 'team-memory'),
|
|
18
|
+
* })
|
|
19
|
+
* },
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @module @co-engram/openclaw
|
|
24
|
+
*/
|
|
25
|
+
import { EngramRepository, SearchOrchestrator, type ToolContext, type Language } from "@co-engram/core";
|
|
26
|
+
import type { CoEngramPluginConfig, CoEngramPluginHostApi } from "./types.js";
|
|
27
|
+
import { DEFAULT_CONFIG } from "./types.js";
|
|
28
|
+
import { type PromptSignals } from "./prompt-builder.js";
|
|
29
|
+
/**
|
|
30
|
+
* 构建 ToolContext(含 repository / searchOrchestrator / signalSink + 可选 observability)
|
|
31
|
+
*
|
|
32
|
+
* P4: 新增 signalSink 注入(默认 FileSignalSink 写入 dataRoot/.co-engram/signals.jsonl)。
|
|
33
|
+
* M1: 新增 auditLog / effectivenessTracker / proposalEngine 注入。
|
|
34
|
+
*/
|
|
35
|
+
export declare function createCoEngramContext(config?: CoEngramPluginConfig): ToolContext;
|
|
36
|
+
/**
|
|
37
|
+
* 重建搜索索引(全量)
|
|
38
|
+
*
|
|
39
|
+
* 用 collectDigestLines 取真实 DigestLine[](含 importance / decayHalfLifeDays /
|
|
40
|
+
* retrievalCount / reinforcementScore 等),让 SearchOrchestrator 的三因子打分
|
|
41
|
+
* (α·relevance + β·recency + γ·importance)能用真实数据,而不是全部默认 0.5。
|
|
42
|
+
*
|
|
43
|
+
* 这直接影响搜索质量:之前所有 engram importance 都被 stub 成 0.5,导致
|
|
44
|
+
* importance 因子对排名无贡献,高重要性 engram 没法浮上来。
|
|
45
|
+
*/
|
|
46
|
+
export declare function rebuildSearchIndex(search: SearchOrchestrator, repo: EngramRepository): void;
|
|
47
|
+
/**
|
|
48
|
+
* 注册所有 Co-Engram 工具到 OpenClaw 插件 API
|
|
49
|
+
*
|
|
50
|
+
* P4 新增:
|
|
51
|
+
* - 工具通过 wrapAllToolsWithSignalSink 包装,自动 append ToolCallEvent
|
|
52
|
+
* - 可选 startMaintenance=true 时启动 MaintenanceEngine(默认 false,需宿主显式开启)
|
|
53
|
+
*
|
|
54
|
+
* M3b 新增:
|
|
55
|
+
* - 如果 ctx.proposalEngine 存在 + api 提供 registerHook + enqueueNextTurnInjection,
|
|
56
|
+
* 注册 session 'new' hook,在会话开始时把候选提示注入下一轮 agent context
|
|
57
|
+
*
|
|
58
|
+
* @param api OpenClaw 插件 API(只需暴露 registerTool)
|
|
59
|
+
* @param config 配置(数据根路径等)
|
|
60
|
+
* @returns ctx + 可选的 maintenance stop 函数
|
|
61
|
+
*/
|
|
62
|
+
export declare function registerCoEngramTools(api: CoEngramPluginHostApi, config?: CoEngramPluginConfig): ToolContext & {
|
|
63
|
+
readonly stopMaintenance?: () => void;
|
|
64
|
+
/** 关闭跨进程 index watcher(主要用于插件卸载 / 测试隔离) */
|
|
65
|
+
readonly stopIndexWatcher?: () => void;
|
|
66
|
+
readonly language?: Language;
|
|
67
|
+
readonly promptSignals?: PromptSignals;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 异步启动 viewer
|
|
71
|
+
*
|
|
72
|
+
* 与 registerCoEngramTools 分离,因为 viewer 启动是异步的且需要 @co-engram/claude-code。
|
|
73
|
+
* 失败不抛到外层,只记 stderr——plugin 仍正常工作。
|
|
74
|
+
*
|
|
75
|
+
* @returns stop 函数;viewer 未启动时返回 undefined
|
|
76
|
+
*/
|
|
77
|
+
export declare function startCoEngramViewer(ctx: ToolContext & {
|
|
78
|
+
readonly language?: Language;
|
|
79
|
+
}, config?: CoEngramPluginConfig): Promise<{
|
|
80
|
+
readonly stopViewer?: () => Promise<void>;
|
|
81
|
+
readonly viewerPort?: number;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* 构造候选提示文本(OpenClaw 注入用)
|
|
85
|
+
*
|
|
86
|
+
* 与 MCP 侧保持一致,均走 i18n 字典。
|
|
87
|
+
*/
|
|
88
|
+
export declare function buildProposalPrompt(count: number, language?: Language): string;
|
|
89
|
+
/**
|
|
90
|
+
* 仅供测试/独立使用:构建一个内存中的 ctx + 注册结果
|
|
91
|
+
*/
|
|
92
|
+
export declare function createCoEngramTools(config?: CoEngramPluginConfig): {
|
|
93
|
+
ctx: ToolContext;
|
|
94
|
+
tools: readonly import("./types.js").OpenClawToolDescriptor[];
|
|
95
|
+
rebuild: () => void;
|
|
96
|
+
};
|
|
97
|
+
export { DEFAULT_CONFIG };
|
|
98
|
+
//# sourceMappingURL=plugin-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-entry.d.ts","sourceRoot":"","sources":["../src/plugin-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAkBlB,KAAK,WAAW,EAGhB,KAAK,QAAQ,EAGd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5C,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAW7B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,oBAAyB,GAChC,W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