@octopi-agent/engine 0.65.0 → 0.70.7

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.
Files changed (99) hide show
  1. package/dist/config-schema/engine.d.ts +84 -0
  2. package/dist/config-schema/engine.js +4 -1
  3. package/dist/config-schema/substrate.d.ts +86 -0
  4. package/dist/config-schema/substrate.js +114 -0
  5. package/dist/config.d.ts +71 -0
  6. package/dist/harness/agent/builder.d.ts +1 -1
  7. package/dist/harness/agent/builder.js +27 -2
  8. package/dist/harness/agent/config-bridge.js +17 -4
  9. package/dist/harness/context/capabilities/summary/gate.js +2 -2
  10. package/dist/harness/context/capabilities/summary/policies.js +5 -5
  11. package/dist/harness/context/capabilities/summary/registry.js +29 -24
  12. package/dist/harness/context/layer-health.js +3 -2
  13. package/dist/harness/context/layers.d.ts +27 -13
  14. package/dist/harness/context/layers.js +76 -66
  15. package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
  16. package/dist/harness/context/system-prompt-assembler.js +11 -1
  17. package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
  18. package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
  19. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
  20. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
  21. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
  22. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
  23. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
  24. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
  25. package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
  26. package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
  27. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  28. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  29. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
  30. package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
  31. package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
  32. package/dist/harness/index.d.ts +4 -3
  33. package/dist/harness/index.js +2 -1
  34. package/dist/harness/knowledge/query-service.js +5 -5
  35. package/dist/harness/knowledge/retriever.js +1 -1
  36. package/dist/harness/knowledge/source-store.d.ts +17 -2
  37. package/dist/harness/knowledge/source-store.js +6 -5
  38. package/dist/harness/memory/cognition-decay.d.ts +36 -0
  39. package/dist/harness/memory/cognition-decay.js +55 -0
  40. package/dist/harness/memory/cognition-gates.d.ts +60 -0
  41. package/dist/harness/memory/cognition-gates.js +191 -0
  42. package/dist/harness/memory/cognition-trigger.d.ts +30 -0
  43. package/dist/harness/memory/cognition-trigger.js +41 -0
  44. package/dist/harness/memory/cognition-types.d.ts +1 -1
  45. package/dist/harness/memory/cognition.d.ts +40 -8
  46. package/dist/harness/memory/cognition.js +432 -79
  47. package/dist/harness/memory/conceptualizer.d.ts +66 -0
  48. package/dist/harness/memory/conceptualizer.js +246 -0
  49. package/dist/harness/memory/index.d.ts +16 -2
  50. package/dist/harness/memory/index.js +11 -1
  51. package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
  52. package/dist/harness/memory/sqlite/agent-db.js +118 -15
  53. package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
  54. package/dist/harness/memory/sqlite/cognition-store.js +591 -144
  55. package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
  56. package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
  57. package/dist/harness/memory/types.d.ts +331 -16
  58. package/dist/harness/memory/types.js +49 -0
  59. package/dist/harness/memory/wisdom-formation.d.ts +101 -0
  60. package/dist/harness/memory/wisdom-formation.js +304 -0
  61. package/dist/harness/memory/wisdom-gates.d.ts +50 -0
  62. package/dist/harness/memory/wisdom-gates.js +204 -0
  63. package/dist/harness/memory/wisdom-policy.d.ts +107 -0
  64. package/dist/harness/memory/wisdom-policy.js +220 -0
  65. package/dist/harness/memory/wisdom-types.d.ts +3 -2
  66. package/dist/harness/memory/wisdom-types.js +2 -2
  67. package/dist/harness/memory/wisdom.d.ts +27 -0
  68. package/dist/harness/memory/wisdom.js +181 -0
  69. package/dist/harness/run/agent/agent.d.ts +9 -0
  70. package/dist/harness/run/agent/agent.js +19 -0
  71. package/dist/harness/run/reliability/run-agent.js +6 -2
  72. package/dist/harness/run/runner.js +2 -1
  73. package/dist/harness/session/index.d.ts +1 -0
  74. package/dist/harness/session/index.js +1 -0
  75. package/dist/harness/session/title.d.ts +86 -0
  76. package/dist/harness/session/title.js +268 -0
  77. package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
  78. package/dist/harness/shared/events/agent-event-map.js +1 -0
  79. package/dist/index.d.ts +3 -1
  80. package/dist/index.js +1 -0
  81. package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
  82. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
  83. package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
  84. package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
  85. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
  86. package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
  87. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
  88. package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
  89. package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
  90. package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
  91. package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
  92. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
  93. package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
  94. package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
  95. package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
  96. package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
  97. package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
  98. package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
  99. package/package.json +2 -2
@@ -0,0 +1,268 @@
1
+ /**
2
+ * 会话标题策略 — 临时截断 / 小模型摘要触发条件
3
+ *
4
+ * 目标:历史列表一眼可认;「你好」类碎消息不浪费 LLM 调用。
5
+ */
6
+ import { getTextContent } from '@octopi-agent/core/types.js';
7
+ /** 首条有效用户消息达到该长度才可直接摘要 */
8
+ export const TITLE_MIN_FIRST_USER_CHARS = 16;
9
+ /** 累计有效用户内容达到该长度(且至少 1 轮完成)可摘要 */
10
+ export const TITLE_MIN_TOTAL_USER_CHARS = 40;
11
+ /** 临时截断标题最大长度 */
12
+ export const TITLE_SNIPPET_MAX_CHARS = 24;
13
+ /** 生成标题最大长度 */
14
+ export const TITLE_MAX_CHARS = 40;
15
+ /** 参与标题信号统计的用户消息(排除 slash 命令留痕) */
16
+ function isTitleRelevantUserMessage(msg) {
17
+ if (msg.role !== 'user')
18
+ return false;
19
+ const kind = msg.metadata?.kind;
20
+ if (kind === 'command' || kind === 'command_result')
21
+ return false;
22
+ return true;
23
+ }
24
+ /** 提取纯文本并压空白 */
25
+ function messageText(msg) {
26
+ return getTextContent(msg.content).replace(/\s+/g, ' ').trim();
27
+ }
28
+ function safeDecodeURIComponent(s) {
29
+ try {
30
+ return decodeURIComponent(s);
31
+ }
32
+ catch {
33
+ // 非法 percent-encoding 原样返回,不因个别字符丢掉整段
34
+ return s;
35
+ }
36
+ }
37
+ /** 从 URL / 路径 token 取文件名(尽量解码 percent-encoding) */
38
+ function filenameFromUrlLike(token) {
39
+ const withoutScheme = token.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '');
40
+ const withoutDrive = withoutScheme.replace(/^[A-Za-z]:[\\/]?/, '');
41
+ const last = withoutDrive.split(/[\\/]/).filter(Boolean).pop() ?? '';
42
+ const base = last.split(/[?#]/)[0] ?? '';
43
+ const decoded = safeDecodeURIComponent(base).trim();
44
+ if (!decoded)
45
+ return '路径';
46
+ return decoded.length > 40 ? `${decoded.slice(0, 39)}…` : decoded;
47
+ }
48
+ /**
49
+ * 压缩 URL / 本地路径,避免路径噪声占满 snippet 与摘要 prompt。
50
+ *
51
+ * 长 percent-encoded file:// 路径会把 24 字 snippet 截成「帮我评估一下, file:///…」,
52
+ * 也会把送入小模型的前 400 字预算吃光,导致摘要失败或弱标题。
53
+ *
54
+ * @param text - 原始消息文本
55
+ * @returns 路径替换为文件名后的文本
56
+ */
57
+ export function compactTitleText(text) {
58
+ return text
59
+ .replace(/\b(?:file|https?):\/\/[^\s<>"']+/gi, (m) => filenameFromUrlLike(m))
60
+ .replace(/\b[A-Za-z]:[\\/][^\s<>"']+/g, (m) => filenameFromUrlLike(m))
61
+ .replace(/(?:^|[\s((「『])((?:\/[\w.@-]+){2,})/g, (m, path) => {
62
+ const lead = m.slice(0, m.length - path.length);
63
+ return `${lead}${filenameFromUrlLike(path)}`;
64
+ })
65
+ .replace(/\s+/g, ' ')
66
+ .trim();
67
+ }
68
+ /** 标题用文本:纯文本 + 路径压缩 */
69
+ function titleText(msg) {
70
+ return compactTitleText(messageText(msg));
71
+ }
72
+ /** 收集标题相关的用户文本(按时间序,已压缩路径) */
73
+ export function collectTitleUserTexts(messages) {
74
+ return messages.filter(isTitleRelevantUserMessage).map(titleText).filter(Boolean);
75
+ }
76
+ /**
77
+ * 是否已具备生成摘要标题的语义信号。
78
+ *
79
+ * @param session - 会话数据(用 messages 判断)
80
+ * @returns 首条/最新用户消息够长,或累计用户内容够长且已有助手回复
81
+ */
82
+ export function isTitleSignalReady(session) {
83
+ const userTexts = collectTitleUserTexts(session.messages);
84
+ if (userTexts.length === 0)
85
+ return false;
86
+ // 首条或「最新一条」够长即可(覆盖「你好」后接复杂问题的场景)
87
+ if (userTexts[0].length >= TITLE_MIN_FIRST_USER_CHARS ||
88
+ userTexts[userTexts.length - 1].length >= TITLE_MIN_FIRST_USER_CHARS) {
89
+ return true;
90
+ }
91
+ const totalUser = userTexts.reduce((n, t) => n + t.length, 0);
92
+ const hasAssistant = session.messages.some((m) => m.role === 'assistant' && messageText(m));
93
+ return hasAssistant && totalUser >= TITLE_MIN_TOTAL_USER_CHARS;
94
+ }
95
+ /**
96
+ * 是否应尝试更新标题(尊重手动重命名与已生成有效 auto)。
97
+ *
98
+ * @param meta - 会话元数据
99
+ * @returns true = 允许写入 snippet 或重新生成 auto
100
+ */
101
+ export function shouldUpdateTitle(meta) {
102
+ if (meta.titleSource === 'user')
103
+ return false;
104
+ // 有效 auto 不再覆盖;「你好」这类弱 auto/snippet 仍可升级
105
+ if (meta.titleSource === 'auto' && meta.title && !isWeakTitle(meta.title))
106
+ return false;
107
+ return true;
108
+ }
109
+ /**
110
+ * 是否像代码 / 标记 / 工具载荷——不适合当会话标题。
111
+ *
112
+ * 只拦「本身就是载荷」的开头,不误伤「npm 依赖冲突」这类正常主题。
113
+ *
114
+ * @param text - 候选标题或消息正文
115
+ * @returns true = 应跳过或视为弱标题
116
+ */
117
+ export function looksLikeCodeOrMarkup(text) {
118
+ const t = text.trim();
119
+ if (!t)
120
+ return true;
121
+ // XML/HTML/自定义标签开头(含 </…>、<!…>、<?…>)
122
+ if (/^<[a-zA-Z!?/]/.test(t))
123
+ return true;
124
+ // 被转义的尖括号标签
125
+ if (/^(?:&lt;|&#60;)/i.test(t))
126
+ return true;
127
+ // 完整 JSON / 配置块
128
+ if (t.length > 20 && /^[{[][\s\S]*[}\]]$/.test(t))
129
+ return true;
130
+ return false;
131
+ }
132
+ /** 是否几乎只是路径 / URL / percent-encoding 堆叠 */
133
+ function isPathDominated(text) {
134
+ const t = text.trim();
135
+ if (!t)
136
+ return true;
137
+ if (/^(?:file|https?):\/\//i.test(t))
138
+ return true;
139
+ if (/^[A-Za-z]:[\\/]/.test(t))
140
+ return true;
141
+ if (t.startsWith('/'))
142
+ return true;
143
+ // percent-encoding 占比过高:解码后语义信息量不足
144
+ const stripped = t.replace(/%[0-9A-Fa-f]{2}/g, '');
145
+ if (t.length >= 12 && stripped.length < t.length * 0.4)
146
+ return true;
147
+ // 纯 ASCII 文件名(无语义词),如 report.pdf / data.json
148
+ if (/^[\w.-]+\.[A-Za-z0-9]{1,8}$/.test(t))
149
+ return true;
150
+ return false;
151
+ }
152
+ /** 开场客套前缀——截断前去掉,让 snippet 落在事项上 */
153
+ const LEAD_IN_RE = /^(?:请|麻烦|帮我|给我|帮忙|能不能|可不可以|想请你|请问|你好[,,]?\s*)+/;
154
+ /**
155
+ * 构建临时标题:优先首条「有语义」的用户消息,否则取最长一条。
156
+ *
157
+ * 避免「你好」占位后复杂提问也一直显示「你好」;路径已压缩为文件名。
158
+ *
159
+ * @param messages - 会话消息
160
+ * @returns 截断后的 snippet;无有效用户消息时返回 null
161
+ */
162
+ export function buildSnippetTitle(messages) {
163
+ const userTexts = collectTitleUserTexts(messages)
164
+ .map((t) => t.replace(LEAD_IN_RE, '').trim() || t)
165
+ .filter((t) => !looksLikeCodeOrMarkup(t) && !isPathDominated(t));
166
+ if (userTexts.length === 0)
167
+ return null;
168
+ const substantial = userTexts.find((t) => t.length >= TITLE_MIN_FIRST_USER_CHARS);
169
+ const preferred = substantial
170
+ ?? userTexts.reduce((a, b) => (b.length > a.length ? b : a));
171
+ if (preferred.length <= TITLE_SNIPPET_MAX_CHARS)
172
+ return preferred;
173
+ return `${preferred.slice(0, TITLE_SNIPPET_MAX_CHARS - 1)}…`;
174
+ }
175
+ /**
176
+ * 规范化模型输出的标题(去引号/换行、限长)。
177
+ *
178
+ * @param raw - 模型原始输出
179
+ * @returns 单行短标题;空输出返回 null
180
+ */
181
+ export function normalizeGeneratedTitle(raw) {
182
+ const firstLine = raw
183
+ .split('\n')
184
+ .map((line) => line.trim())
185
+ .filter(Boolean)[0] ?? '';
186
+ let t = firstLine
187
+ .replace(/^(?:["'「『]|&quot;)+/, '')
188
+ .replace(/(?:["'」』]|&quot;)+$/, '')
189
+ .replace(/\s+/g, ' ')
190
+ .trim();
191
+ // 去掉一层简单包裹标签,如 <title>xxx</title>
192
+ t = t.replace(/^<([a-zA-Z][\w:-]*)[^>]*>([\s\S]*)<\/\1>$/, '$2').trim();
193
+ if (!t)
194
+ return null;
195
+ if (looksLikeCodeOrMarkup(t))
196
+ return null;
197
+ if (t.length > TITLE_MAX_CHARS)
198
+ t = `${t.slice(0, TITLE_MAX_CHARS - 1)}…`;
199
+ return t;
200
+ }
201
+ /** 无信息量的寒暄(标题信号不足时仍可进 snippet,但不进摘要 prompt) */
202
+ const GREETING_ONLY_RE = /^(?:你好|您好|哈喽|hello|hi|hey|在吗|在么|早上好|中午好|下午好|晚上好|谢谢|感谢|好的|ok|okay|嗯|哦)[!!。~~.\s]*$/i;
203
+ /** 短问候回复,如「你好!有什么可以帮你?」 */
204
+ const PLEASANTRY_RE = /你好|您好|哈喽|hello|hi\b|帮你|有什么可以|请问需要|很高兴|欢迎/i;
205
+ function isNoiseForTitle(text) {
206
+ if (text.length < 4)
207
+ return true;
208
+ if (GREETING_ONLY_RE.test(text))
209
+ return true;
210
+ return text.length <= 20 && PLEASANTRY_RE.test(text);
211
+ }
212
+ /**
213
+ * 弱标题(寒暄/过短/无信息量)——即使已标成 auto 也允许再升级。
214
+ *
215
+ * @param title - 当前标题
216
+ * @returns true = 不应视为最终摘要标题
217
+ */
218
+ export function isWeakTitle(title) {
219
+ if (!title)
220
+ return true;
221
+ const t = title.trim();
222
+ if (!t)
223
+ return true;
224
+ if (looksLikeCodeOrMarkup(t))
225
+ return true;
226
+ if (isPathDominated(t))
227
+ return true;
228
+ return isNoiseForTitle(t);
229
+ }
230
+ /**
231
+ * 构建摘要标题的 LLM 消息。
232
+ *
233
+ * 标题语义 = 「这段对话面向的是什么事」(主题标签),不是对话内容复述。
234
+ * 正文先压缩 URL/路径,避免 percent-encoded 路径吃光上下文预算。
235
+ *
236
+ * @param messages - 会话消息(跳过寒暄与命令留痕)
237
+ * @returns 送给 ModelProvider.chat 的 messages
238
+ */
239
+ export function buildTitlePrompt(messages) {
240
+ const entries = [];
241
+ for (const msg of messages) {
242
+ if (msg.role !== 'user' && msg.role !== 'assistant')
243
+ continue;
244
+ const kind = msg.metadata?.kind;
245
+ if (kind === 'command' || kind === 'command_result')
246
+ continue;
247
+ const text = titleText(msg);
248
+ if (!text)
249
+ continue;
250
+ entries.push({ role: msg.role === 'user' ? 'user' : 'assistant', text });
251
+ }
252
+ // 有实质内容时丢掉纯寒暄,避免标题被「你好」带偏
253
+ const meaningful = entries.filter((e) => !isNoiseForTitle(e.text));
254
+ const picked = meaningful.length > 0 ? meaningful : entries;
255
+ const lines = picked.slice(0, 6).map((e) => `${e.role === 'user' ? '用户' : '助手'}: ${e.text.slice(0, 400)}`);
256
+ const dialogue = lines.join('\n');
257
+ return [
258
+ {
259
+ role: 'system',
260
+ content: '你是会话标题生成器。判断这段对话「面向的是什么事」,输出一个主题式短标题。\n' +
261
+ '写法:像文件名/标签,点明对象+事项,优先保留专名(项目名、系统名、模块名、文档名)。\n' +
262
+ '忽略路径、URL、命令行等载荷噪音,标题写实际要做的事。\n' +
263
+ '使用与对话相同的语言。6–16 个字为宜,不超过 20 字。\n' +
264
+ '不要引号、不要句号、不要解释,只输出标题本身。',
265
+ },
266
+ { role: 'user', content: dialogue },
267
+ ];
268
+ }
@@ -102,6 +102,13 @@ export interface AgentEventMap {
102
102
  agentId?: string;
103
103
  reason?: string;
104
104
  };
105
+ /** 会话展示元数据变更(标题等;UI 列表刷新) */
106
+ 'session.updated': {
107
+ sessionId: string;
108
+ title?: string;
109
+ titleSource?: 'snippet' | 'auto' | 'user';
110
+ updatedAt?: number;
111
+ };
105
112
  /** Persona 磁盘解析失败(Runner) */
106
113
  'persona.resolve.failed': {
107
114
  error: string;
@@ -245,6 +252,7 @@ export declare const AgentEvents: {
245
252
  readonly RUN_GUARD_RECOVERED: "run_guard.recovered";
246
253
  readonly SESSION_LIFECYCLE_UPDATED: "session.lifecycle.updated";
247
254
  readonly SESSION_ENDED: "session.ended";
255
+ readonly SESSION_UPDATED: "session.updated";
248
256
  readonly PERSONA_RESOLVE_FAILED: "persona.resolve.failed";
249
257
  readonly CONTEXT_COMPACT_START: "context.compact.start";
250
258
  readonly CONTEXT_COMPACT_END: "context.compact.end";
@@ -32,6 +32,7 @@ export const AgentEvents = {
32
32
  RUN_GUARD_RECOVERED: 'run_guard.recovered',
33
33
  SESSION_LIFECYCLE_UPDATED: 'session.lifecycle.updated',
34
34
  SESSION_ENDED: 'session.ended',
35
+ SESSION_UPDATED: 'session.updated',
35
36
  PERSONA_RESOLVE_FAILED: 'persona.resolve.failed',
36
37
  CONTEXT_COMPACT_START: 'context.compact.start',
37
38
  CONTEXT_COMPACT_END: 'context.compact.end',
package/dist/index.d.ts CHANGED
@@ -69,6 +69,8 @@ export type { SkillDefinition, SkillManager } from './harness/extension/plugin-e
69
69
  /** 产品装配 DTO(非 Kernel);ModelInfo/ToolPolicy 仍从 core/types 导出 */
70
70
  export type { AgentPersona, ModelConfig, AgentDefinition } from './harness/shared/types/agent-definition.js';
71
71
  export { DefaultToolBus } from './harness/extension/plugin-ecosystem/tools/tool-bus.js';
72
+ export { createClientTool, makeClientToolCallId, ClientToolRegistry, DEFAULT_CLIENT_TOOL_TIMEOUT_MS, } from './harness/extension/plugin-ecosystem/client-tools/index.js';
73
+ export type { ClientToolCall, ClientToolCallId, ClientToolCallOutcome, ClientToolDescriptor, ClientToolDeviceMeta, ClientToolErrorReason, ClientToolInvoker, ClientToolInteraction, ClientToolName, ClientToolProvider, ClientToolResult, ClientToolSensitivity, ClientToolRouteDecision, } from './harness/extension/plugin-ecosystem/client-tools/index.js';
72
74
  export { getBuiltinTools, createShellTool, createFileReadTool, createFileWriteTool, createFileListTool } from './harness/extension/plugin-ecosystem/tools/builtin.js';
73
75
  export { createToolSet } from './harness/extension/plugin-ecosystem/tools/tool-set.js';
74
76
  export { createSummaryPort, applyToolOutputGate, createCompactEngine } from './harness/context/capabilities/index.js';
@@ -111,7 +113,7 @@ export { getBuiltinModelInfo, mergeWithBuiltinInfo } from './builtin-model-info.
111
113
  export * from '@octopi-agent/core/types.js';
112
114
  export { getTextContent, hasMediaContent } from '@octopi-agent/core/types.js';
113
115
  export type { AsyncTaskStore, AsyncTaskRecord } from './harness/collaboration/orchestration/async-task-store.js';
114
- export type { MemoryStore, MemoryEntry, MemoryType, MemoryQuery, MemoryStats, WisdomStore, WisdomEntry, ConceptGraphStore, ConceptNode, ConceptEdge, ConceptGraph, KnowledgeCatalogItem, KnowledgeCatalogProvider, Planner, Reflector, AgentState, } from './harness/index.js';
116
+ export type { MemoryStore, MemoryEntry, MemoryType, MemoryQuery, MemoryStats, WisdomStore, WisdomEntry, WisdomStatus, WisdomOrigin, WisdomKind, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomOutcomes, AdmitWisdomInput, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomStats, ConceptGraphStore, ConceptNode, ConceptEdge, ConceptGraph, ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, MergeCandidate, ConceptGateReason, KnowledgeCatalogItem, KnowledgeCatalogProvider, Planner, Reflector, AgentState, } from './harness/index.js';
115
117
  export type { McpClient, McpManager, McpServerConfig, McpToolDefinition, McpToolResult, } from './harness/extension/plugin-ecosystem/mcp/types.js';
116
118
  export type { MessageChannel, ProcessMessage, } from './harness/collaboration/multi-agent/message-channel-types.js';
117
119
  export type { ApprovalProvider, ApprovalPolicy, ApprovalRequest, ApprovalDecision, } from './harness/governance/human-in-the-loop/types.js';
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ export { CapabilityRegistry } from './harness/extension/plugin-ecosystem/plugins
45
45
  export { validateManifest, parseManifest } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
46
46
  export { DefaultSkillManager, FileSystemSkillSource } from './harness/extension/plugin-ecosystem/skills/manager.js';
47
47
  export { DefaultToolBus } from './harness/extension/plugin-ecosystem/tools/tool-bus.js';
48
+ export { createClientTool, makeClientToolCallId, ClientToolRegistry, DEFAULT_CLIENT_TOOL_TIMEOUT_MS, } from './harness/extension/plugin-ecosystem/client-tools/index.js';
48
49
  export { getBuiltinTools, createShellTool, createFileReadTool, createFileWriteTool, createFileListTool } from './harness/extension/plugin-ecosystem/tools/builtin.js';
49
50
  export { createToolSet } from './harness/extension/plugin-ecosystem/tools/tool-set.js';
50
51
  export { createSummaryPort, applyToolOutputGate, createCompactEngine } from './harness/context/capabilities/index.js';
@@ -0,0 +1,43 @@
1
+ # Cognition Steward Conceptualize
2
+
3
+ 你是概念化助手。从**命题 + 证据语境**中提取可复用概念与关系假设,输出结构化 JSON。
4
+
5
+ 本文是 system 认知指令;用户消息仅提供 Memory 命题与 contextSlice。不要复述本文规则。
6
+
7
+ ## 输出
8
+
9
+ 严格 JSON 对象:
10
+
11
+ ```json
12
+ {
13
+ "nodes": [
14
+ {
15
+ "name": "会话租约",
16
+ "kind": "construct",
17
+ "description": "sessionId 级互斥租约",
18
+ "domain": ["session", "concurrency"]
19
+ }
20
+ ],
21
+ "edges": [
22
+ {
23
+ "fromName": "会话租约",
24
+ "toName": "Session",
25
+ "relationType": "part_of",
26
+ "evidenceClass": "mereonymy",
27
+ "cue": "证据中的原句片段"
28
+ }
29
+ ],
30
+ "rejected": []
31
+ }
32
+ ```
33
+
34
+ ## 规则
35
+
36
+ - 概念是**可复用判别单元**(entity/construct/method/problem/constraint),不是每个名词
37
+ - `relationType`:causes / part_of / opposes / similar_to / evolves_to / related
38
+ - `evidenceClass`:causal / mereonymy / negation / analogy / evolution / cooccur
39
+ - **强关系必须给 cue**(证据原句片段);无把握时只用 `related` + `cooccur`
40
+ - 禁止假因果:非因果证据不得标 causes
41
+ - 两个义项不同时**禁止合并成一个 name**;宁可拆开
42
+ - 没有值得记的概念返回 `{"nodes":[],"edges":[],"rejected":[]}`
43
+ - kind 只能是 entity / construct / method / problem / constraint
@@ -0,0 +1,50 @@
1
+ id: cognition.steward.conceptualize
2
+ name: Cognition Steward Conceptualize
3
+ description: 命题+语境 → 概念图谱(持证关系;写 concepts/concept_edges)
4
+
5
+ sense:
6
+ source: eventBus
7
+ filter:
8
+ condition: "true"
9
+ events: ['cognition.conceptualize.request']
10
+ emits: ['cognition.conceptualized']
11
+ isolation: isolated
12
+
13
+ think:
14
+ implementation: llm
15
+ strategy: single
16
+ maxIterations: 1
17
+
18
+ act:
19
+ mode: inject
20
+
21
+ signal:
22
+ severity: info
23
+ channel: [event]
24
+
25
+ boundary:
26
+ visibility: isolated
27
+ authority: act
28
+ security: trusted
29
+
30
+ tools:
31
+ mode: none
32
+
33
+ session:
34
+ mode: ephemeral
35
+ scope: agent
36
+
37
+ lifecycle:
38
+ maxConcurrent: 1
39
+ maxDurationMs: 30000
40
+
41
+ runtimeInject:
42
+ requires: ['conceptGraphStore']
43
+
44
+ observability:
45
+ eventPrefix: cognition.steward.conceptualize
46
+
47
+ metadata:
48
+ config:
49
+ maxNodesPerProposition: 6
50
+ maxEdgesPerProposition: 12
@@ -0,0 +1,9 @@
1
+ /**
2
+ * cognition.steward.conceptualize — 命题 + contextSlice → 概念/边(持证)
3
+ *
4
+ * 失败语义:缺 llmPort / LLM 错误 / 解析失败 → act.status=failed。
5
+ * 只写 ConceptGraphStore(E3);不写 Memory / Wisdom / Knowledge。
6
+ */
7
+ import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
8
+ declare function handler(input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
9
+ export default handler;
@@ -0,0 +1,125 @@
1
+ /**
2
+ * cognition.steward.conceptualize — 命题 + contextSlice → 概念/边(持证)
3
+ *
4
+ * 失败语义:缺 llmPort / LLM 错误 / 解析失败 → act.status=failed。
5
+ * 只写 ConceptGraphStore(E3);不写 Memory / Wisdom / Knowledge。
6
+ */
7
+ import { readFileSync } from 'node:fs';
8
+ import { dirname, join } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
11
+ import { conceptualizeAndAdmit, parseConceptualizerJson, } from '../../../harness/memory/conceptualizer.js';
12
+ const DEP_CONCEPT_GRAPH = 'conceptGraphStore';
13
+ const DEP_CONFIG = '__subsystem_config__';
14
+ function resolveSubsystemPrompt(deps, llmPort) {
15
+ const fromDeps = deps?.[DEP_SUBSYSTEM_PROMPT];
16
+ if (typeof fromDeps === 'string' && fromDeps.trim())
17
+ return fromDeps;
18
+ if (llmPort?.cognitivePrompt?.trim())
19
+ return llmPort.cognitivePrompt;
20
+ try {
21
+ const here = dirname(fileURLToPath(import.meta.url));
22
+ return readFileSync(join(here, 'SUBSYSTEM.md'), 'utf8');
23
+ }
24
+ catch {
25
+ return '';
26
+ }
27
+ }
28
+ function failOutput(message, reason) {
29
+ return {
30
+ act: {
31
+ mode: 'inject',
32
+ status: 'failed',
33
+ error: message,
34
+ target: 'concept-graph',
35
+ messages: [{ role: 'system', content: `cognition.steward.conceptualize.failed reason=${reason}` }],
36
+ },
37
+ signals: [{ action: 'alert', reason: message, data: { reason } }],
38
+ };
39
+ }
40
+ async function handler(input, deps) {
41
+ const store = deps?.[DEP_CONCEPT_GRAPH];
42
+ if (!store) {
43
+ throw new Error('cognition.steward.conceptualize: conceptGraphStore not injected');
44
+ }
45
+ const llmPort = deps?.[DEP_LLM_PORT];
46
+ if (!llmPort?.chat) {
47
+ return failOutput('llmPort missing', 'llm_port_missing');
48
+ }
49
+ const payload = (input.payload ?? {});
50
+ const proposition = String(payload.proposition ?? '').trim();
51
+ const memoryId = String(payload.memoryId ?? '');
52
+ const evidence = String(payload.evidence ?? '');
53
+ const contextSlice = String(payload.contextSlice ?? payload.context_slice ?? '');
54
+ const memoryType = String(payload.memoryType ?? payload.type ?? 'fact');
55
+ const memoryStatus = payload.memoryStatus ?? undefined;
56
+ if (!proposition || !memoryId) {
57
+ return failOutput('missing proposition/memoryId', 'bad_payload');
58
+ }
59
+ if (!contextSlice.trim() && !evidence.trim()) {
60
+ return failOutput('no context slice', 'no_context_slice');
61
+ }
62
+ const systemPrompt = resolveSubsystemPrompt(deps, llmPort);
63
+ const userText = [
64
+ `memoryType: ${memoryType}`,
65
+ `proposition: ${proposition}`,
66
+ `evidence: ${evidence}`,
67
+ `contextSlice: ${contextSlice}`,
68
+ ].join('\n');
69
+ let llmText = '';
70
+ try {
71
+ const res = await llmPort.chat({
72
+ systemPrompt: systemPrompt || undefined,
73
+ messages: [{ role: 'user', content: userText }],
74
+ temperature: 0.2,
75
+ maxTokens: 2048,
76
+ });
77
+ if (res.finishReason === 'error') {
78
+ return failOutput(res.content || 'llm chat error', 'llm_error');
79
+ }
80
+ llmText = res.content ?? '';
81
+ }
82
+ catch (err) {
83
+ return failOutput(err instanceof Error ? err.message : String(err), 'llm_error');
84
+ }
85
+ const parsed = parseConceptualizerJson(llmText);
86
+ if (!parsed) {
87
+ return failOutput('parse_failed', 'parse_failed');
88
+ }
89
+ const result = await conceptualizeAndAdmit(parsed, {
90
+ proposition,
91
+ memoryId,
92
+ memoryType,
93
+ evidence,
94
+ contextSlice,
95
+ memoryStatus,
96
+ }, store);
97
+ const created = result.nodes.filter((n) => n.admit.action === 'created' || n.admit.action === 'merged').length;
98
+ const edgesIn = result.edges.filter((e) => e.admit && e.admit.action !== 'rejected').length;
99
+ return {
100
+ act: {
101
+ mode: 'inject',
102
+ status: 'success',
103
+ target: 'concept-graph',
104
+ messages: [
105
+ {
106
+ role: 'system',
107
+ content: `cognition.steward.conceptualized nodes=${created} edges=${edgesIn} rejected=${result.rejected.length}`,
108
+ },
109
+ ],
110
+ },
111
+ signals: [
112
+ {
113
+ action: 'suggest',
114
+ reason: 'conceptualized',
115
+ data: {
116
+ memoryId,
117
+ nodes: created,
118
+ edges: edgesIn,
119
+ rejected: result.rejected,
120
+ },
121
+ },
122
+ ],
123
+ };
124
+ }
125
+ export default handler;
@@ -0,0 +1,6 @@
1
+ # Cognition Steward Consolidate
2
+
3
+ 确定性巩固批:衰减 → merge_candidates 裁决钩子 → 晋升 → GC。
4
+
5
+ 不调用 LLM(候选裁决由外部/管理面 resolveMerge);不写 Memory/Wisdom。
6
+ 本文仅作认知指令占位(think.implementation=code)。
@@ -0,0 +1,54 @@
1
+ id: cognition.steward.consolidate
2
+ name: Cognition Steward Consolidate
3
+ description: 概念图巩固:衰减、晋升、GC、容量检查(事件+TTL)
4
+
5
+ sense:
6
+ source: schedule
7
+ interval: 86400000
8
+ filter:
9
+ condition: "true"
10
+ events: ['cognition.consolidate.request', 'session.ended', 'memory.steward.governed']
11
+ emits: ['cognition.consolidated']
12
+ isolation: isolated
13
+
14
+ think:
15
+ implementation: code
16
+ strategy: deterministic
17
+ maxIterations: 1
18
+
19
+ act:
20
+ mode: inject
21
+
22
+ signal:
23
+ severity: info
24
+ channel: [event]
25
+
26
+ boundary:
27
+ visibility: isolated
28
+ authority: act
29
+ security: trusted
30
+
31
+ tools:
32
+ mode: none
33
+
34
+ session:
35
+ mode: ephemeral
36
+ scope: agent
37
+
38
+ lifecycle:
39
+ maxConcurrent: 1
40
+ maxDurationMs: 15000
41
+
42
+ runtimeInject:
43
+ requires: ['conceptGraphStore']
44
+
45
+ observability:
46
+ eventPrefix: cognition.steward.consolidate
47
+
48
+ metadata:
49
+ config:
50
+ promoteMinSupport: 3
51
+ warnNodes: 5000
52
+ warnEdges: 20000
53
+ stopNodes: 10000
54
+ stopEdges: 40000
@@ -0,0 +1,12 @@
1
+ /**
2
+ * cognition.steward.consolidate — 概念图巩固批
3
+ *
4
+ * 本轮实现:衰减 → 指纹冲突 keep_split → 按支撑晋升 → 容量水位。
5
+ * 未实现步骤(LLM 合并裁决 / causal_candidate 转正 / Wisdom 信号 / anchor:missing GC)
6
+ * 显式记入 skipped,不得假装完成规格 §7.2 全部步骤。
7
+ *
8
+ * 只写 ConceptGraphStore;不写 Memory / Wisdom。
9
+ */
10
+ import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
11
+ declare function handler(_input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
12
+ export default handler;