@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,372 @@
1
+ /**
2
+ * ClientStreamTransport — Host 侧 source/sink 采样通道
3
+ *
4
+ * LLM 不可见:不注册 stream_read/write/close。域工具封装生命周期,
5
+ * 样本经事件回调给 UI/插件;大字节仍走 asset。
6
+ */
7
+ import { requireDevicePurpose, validateClientToolArgs } from './invoke.js';
8
+ function defaultStreamId() {
9
+ return `cs_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
10
+ }
11
+ /**
12
+ * 会话流通道注册表 + 节流广播。
13
+ * 通道操作仅 Host/插件调用,不进入 LLM tool 面。
14
+ */
15
+ export class ClientStreamTransport {
16
+ deps;
17
+ channels = new Map();
18
+ throttleMs;
19
+ maxBatch;
20
+ defaultMaxDurationMs;
21
+ makeStreamId;
22
+ now;
23
+ constructor(deps) {
24
+ this.deps = deps;
25
+ this.throttleMs = deps.throttleMs ?? 200;
26
+ this.maxBatch = deps.maxBatch ?? 32;
27
+ this.defaultMaxDurationMs = deps.defaultMaxDurationMs ?? 300_000;
28
+ this.makeStreamId = deps.makeStreamId ?? defaultStreamId;
29
+ this.now = deps.now ?? Date.now;
30
+ }
31
+ open(input) {
32
+ const at = this.now();
33
+ const maxDurationMs = input.maxDurationMs ?? this.defaultMaxDurationMs;
34
+ const channel = {
35
+ streamId: this.makeStreamId(),
36
+ direction: input.direction,
37
+ sampleHint: input.sampleHint,
38
+ owner: {
39
+ sessionId: input.sessionId,
40
+ clientInstanceId: input.clientInstanceId,
41
+ toolCallId: input.toolCallId,
42
+ toolName: input.toolName,
43
+ },
44
+ status: 'open',
45
+ openedAt: at,
46
+ maxDurationMs,
47
+ };
48
+ const internal = { channel, pending: [] };
49
+ this.channels.set(channel.streamId, internal);
50
+ if (maxDurationMs > 0) {
51
+ internal.ttlTimer = setTimeout(() => {
52
+ this.close(channel.streamId, 'ttl');
53
+ }, maxDurationMs);
54
+ }
55
+ this.deps.emitEvent({
56
+ type: 'client_stream.opened',
57
+ sessionId: input.sessionId,
58
+ timestamp: at,
59
+ data: { channel: { ...channel } },
60
+ });
61
+ return { ...channel, owner: { ...channel.owner } };
62
+ }
63
+ /**
64
+ * 写入样本(source:client 上报;sink:host 下发前镜像给 UI)。
65
+ * 超过 maxBatch 的可丢样本在本窗丢弃。
66
+ */
67
+ writeSamples(streamId, samples) {
68
+ const entry = this.channels.get(streamId);
69
+ if (!entry || entry.channel.status !== 'open')
70
+ return false;
71
+ const at = this.now();
72
+ let dropped = 0;
73
+ for (const s of samples) {
74
+ if (entry.pending.length >= this.maxBatch) {
75
+ dropped += 1;
76
+ continue;
77
+ }
78
+ entry.pending.push({ data: s.data, at });
79
+ }
80
+ if (dropped > 0) {
81
+ this.deps.emitEvent({
82
+ type: 'client_stream.sample',
83
+ sessionId: entry.channel.owner.sessionId,
84
+ timestamp: at,
85
+ data: { streamId, samples: [], dropped },
86
+ });
87
+ }
88
+ this.scheduleFlush(entry);
89
+ return true;
90
+ }
91
+ scheduleFlush(entry) {
92
+ if (entry.sampleTimer !== undefined)
93
+ return;
94
+ entry.sampleTimer = setTimeout(() => {
95
+ entry.sampleTimer = undefined;
96
+ this.flush(entry);
97
+ }, this.throttleMs);
98
+ }
99
+ flush(entry) {
100
+ if (entry.pending.length === 0)
101
+ return;
102
+ const batch = entry.pending.splice(0, this.maxBatch);
103
+ this.deps.emitEvent({
104
+ type: 'client_stream.sample',
105
+ sessionId: entry.channel.owner.sessionId,
106
+ timestamp: this.now(),
107
+ data: {
108
+ streamId: entry.channel.streamId,
109
+ samples: batch.map((s) => ({ data: s.data, at: s.at })),
110
+ dropped: 0,
111
+ },
112
+ });
113
+ if (entry.pending.length > 0)
114
+ this.scheduleFlush(entry);
115
+ }
116
+ close(streamId, reason = 'closed') {
117
+ const entry = this.channels.get(streamId);
118
+ if (!entry)
119
+ return null;
120
+ if (entry.channel.status === 'closed') {
121
+ return { ...entry.channel, owner: { ...entry.channel.owner } };
122
+ }
123
+ this.flush(entry);
124
+ entry.channel.status = 'closed';
125
+ entry.channel.closedAt = this.now();
126
+ if (entry.ttlTimer !== undefined) {
127
+ clearTimeout(entry.ttlTimer);
128
+ entry.ttlTimer = undefined;
129
+ }
130
+ if (entry.sampleTimer !== undefined) {
131
+ clearTimeout(entry.sampleTimer);
132
+ entry.sampleTimer = undefined;
133
+ }
134
+ this.channels.delete(streamId);
135
+ this.deps.emitEvent({
136
+ type: 'client_stream.closed',
137
+ sessionId: entry.channel.owner.sessionId,
138
+ timestamp: entry.channel.closedAt,
139
+ data: { channel: { ...entry.channel }, reason },
140
+ });
141
+ return { ...entry.channel, owner: { ...entry.channel.owner } };
142
+ }
143
+ /** Run abort / session 结束 / client 下线时联动关闭 */
144
+ closeWhere(match, reason = 'closed') {
145
+ let n = 0;
146
+ for (const entry of [...this.channels.values()]) {
147
+ if (match({ ...entry.channel, owner: { ...entry.channel.owner } })) {
148
+ this.close(entry.channel.streamId, reason);
149
+ n += 1;
150
+ }
151
+ }
152
+ return n;
153
+ }
154
+ get(streamId) {
155
+ const entry = this.channels.get(streamId);
156
+ return entry ? { ...entry.channel, owner: { ...entry.channel.owner } } : undefined;
157
+ }
158
+ list(sessionId) {
159
+ return [...this.channels.values()]
160
+ .filter((e) => !sessionId || e.channel.owner.sessionId === sessionId)
161
+ .map((e) => ({ ...e.channel, owner: { ...e.channel.owner } }));
162
+ }
163
+ /** 同 session 内某域工具仍打开的通道(复用,避免每次 invoke 新开) */
164
+ findOpenByTool(sessionId, toolName, clientInstanceId) {
165
+ for (const entry of this.channels.values()) {
166
+ const c = entry.channel;
167
+ if (c.status !== 'open')
168
+ continue;
169
+ if (c.owner.sessionId !== sessionId)
170
+ continue;
171
+ if (c.owner.toolName !== toolName)
172
+ continue;
173
+ if (clientInstanceId && c.owner.clientInstanceId !== clientInstanceId)
174
+ continue;
175
+ return { ...c, owner: { ...c.owner } };
176
+ }
177
+ return undefined;
178
+ }
179
+ }
180
+ function samplesFromArgs(args) {
181
+ const raw = args.samples;
182
+ if (!Array.isArray(raw) || raw.length === 0)
183
+ return [];
184
+ return raw.map((data) => ({ data }));
185
+ }
186
+ function requiresDeviceConsent(descriptor) {
187
+ return (descriptor.interaction === 'device' &&
188
+ (descriptor.device?.consent ?? 'prompt') !== 'none');
189
+ }
190
+ /** 通道属主校验:禁止跨 session 读写/关闭(§15.1) */
191
+ function assertSameSession(channel, sessionId) {
192
+ if (!sessionId)
193
+ return 'sessionId is required';
194
+ if (!channel)
195
+ return 'stream not found';
196
+ if (channel.status !== 'open')
197
+ return `stream "${channel.streamId}" is not open`;
198
+ if (channel.owner.sessionId !== sessionId) {
199
+ return `stream "${channel.streamId}" belongs to another session`;
200
+ }
201
+ return null;
202
+ }
203
+ /**
204
+ * source 域工具样板(location_watch 类):返回 value 域句柄,样本走 Host 通道。
205
+ * 不是通用 stream_read;生命周期由配对 stop 工具或 TTL 收口。
206
+ * 默认 sticky:同 session 已有 open 通道则复用,避免重复开流。
207
+ */
208
+ export function createSourceStreamTool(descriptor, deps) {
209
+ return buildStreamTool(descriptor, { reuse: 'sticky', ...deps }, 'source');
210
+ }
211
+ /**
212
+ * sink 域工具样板(play 类):打开 host→client 下行通道,返回 value 域句柄。
213
+ * 默认 append:同 session / playId 续写样本,持续下发不新开通道。
214
+ */
215
+ export function createSinkStreamTool(descriptor, deps) {
216
+ return buildStreamTool(descriptor, { reuse: 'append', ...deps }, 'sink');
217
+ }
218
+ function buildStreamTool(descriptor, deps, direction) {
219
+ const handleKey = deps.handleKey ?? (direction === 'source' ? 'watchId' : 'playId');
220
+ const reuse = deps.reuse ?? 'none';
221
+ return {
222
+ definition: {
223
+ name: descriptor.name,
224
+ description: descriptor.description,
225
+ parameters: descriptor.parameters,
226
+ version: descriptor.version,
227
+ requiresConfirmation: requiresDeviceConsent(descriptor),
228
+ },
229
+ handler: async (args, context) => {
230
+ const argError = validateClientToolArgs(descriptor.parameters ?? {}, args);
231
+ if (argError)
232
+ return { error: 'invalid_arguments', hint: argError };
233
+ const purposeError = requireDevicePurpose(descriptor, args);
234
+ if (purposeError)
235
+ return { error: 'invalid_arguments', hint: purposeError };
236
+ const sessionId = context?.sessionId;
237
+ // 1) 显式句柄:续写 / 确认已有通道(校验属主)
238
+ const explicit = args[handleKey] ?? args.playId ?? args.watchId;
239
+ if (reuse !== 'none' && typeof explicit === 'string' && explicit) {
240
+ const existing = deps.transport.get(explicit);
241
+ if (existing && existing.status === 'open') {
242
+ const denied = assertSameSession(existing, sessionId);
243
+ if (denied)
244
+ return { error: 'permission_denied', hint: denied };
245
+ const extra = samplesFromArgs(args);
246
+ if (extra.length > 0)
247
+ deps.transport.writeSamples(existing.streamId, extra);
248
+ return {
249
+ kind: 'value',
250
+ data: {
251
+ [handleKey]: existing.streamId,
252
+ status: existing.status,
253
+ direction: existing.direction,
254
+ reused: true,
255
+ sampleHint: existing.sampleHint,
256
+ maxDurationMs: existing.maxDurationMs,
257
+ },
258
+ };
259
+ }
260
+ }
261
+ // 2) 同名 open 通道:sticky 返回 / append 续写
262
+ if (reuse !== 'none') {
263
+ const found = sessionId
264
+ ? deps.transport.findOpenByTool(sessionId, descriptor.name)
265
+ : undefined;
266
+ if (found) {
267
+ const denied = assertSameSession(found, sessionId);
268
+ if (denied)
269
+ return { error: 'permission_denied', hint: denied };
270
+ const extra = samplesFromArgs(args);
271
+ if (reuse === 'append' && extra.length > 0) {
272
+ deps.transport.writeSamples(found.streamId, extra);
273
+ }
274
+ return {
275
+ kind: 'value',
276
+ data: {
277
+ [handleKey]: found.streamId,
278
+ status: found.status,
279
+ direction: found.direction,
280
+ reused: true,
281
+ sampleHint: found.sampleHint,
282
+ maxDurationMs: found.maxDurationMs,
283
+ },
284
+ };
285
+ }
286
+ }
287
+ // 3) 新开通道
288
+ let opened;
289
+ try {
290
+ opened = deps.openChannel({ args, context });
291
+ }
292
+ catch (err) {
293
+ return {
294
+ error: 'internal',
295
+ hint: err instanceof Error ? err.message : String(err),
296
+ };
297
+ }
298
+ const channel = deps.transport.open({
299
+ ...opened,
300
+ direction,
301
+ toolName: descriptor.name,
302
+ });
303
+ try {
304
+ if (samplesFromArgs(args).length > 0) {
305
+ deps.transport.writeSamples(channel.streamId, samplesFromArgs(args));
306
+ }
307
+ deps.onOpen?.(channel, args, deps.transport);
308
+ }
309
+ catch {
310
+ // 附加样本失败不回滚已打开通道;工具结果仍返回句柄
311
+ }
312
+ return {
313
+ kind: 'value',
314
+ data: {
315
+ [handleKey]: channel.streamId,
316
+ status: channel.status,
317
+ direction: channel.direction,
318
+ reused: false,
319
+ sampleHint: channel.sampleHint,
320
+ maxDurationMs: channel.maxDurationMs,
321
+ },
322
+ };
323
+ },
324
+ };
325
+ }
326
+ /**
327
+ * 域工具 stop 样板:按域句柄关通道。不是通用 stream_close。
328
+ */
329
+ export function createStreamStopTool(descriptor, deps) {
330
+ const handleKey = deps.handleKey ?? 'watchId';
331
+ return {
332
+ definition: {
333
+ name: descriptor.name,
334
+ description: descriptor.description,
335
+ parameters: descriptor.parameters,
336
+ version: descriptor.version,
337
+ },
338
+ handler: async (args, context) => {
339
+ const argError = validateClientToolArgs(descriptor.parameters ?? {}, args);
340
+ if (argError)
341
+ return { error: 'invalid_arguments', hint: argError };
342
+ const raw = args[handleKey] ?? args.playId ?? args.watchId;
343
+ const streamId = typeof raw === 'string' ? raw : '';
344
+ if (!streamId) {
345
+ return { error: 'invalid_arguments', hint: `missing ${handleKey}` };
346
+ }
347
+ const existing = deps.transport.get(streamId);
348
+ const denied = assertSameSession(existing, context?.sessionId);
349
+ if (denied) {
350
+ return {
351
+ error: denied === 'stream not found' ? 'unsupported' : 'permission_denied',
352
+ hint: denied,
353
+ };
354
+ }
355
+ const closed = deps.transport.close(streamId, 'stop');
356
+ if (!closed) {
357
+ return {
358
+ error: 'unsupported',
359
+ hint: `no open stream "${streamId}"`,
360
+ };
361
+ }
362
+ return {
363
+ kind: 'value',
364
+ data: {
365
+ [handleKey]: closed.streamId,
366
+ status: closed.status,
367
+ closedAt: closed.closedAt,
368
+ },
369
+ };
370
+ },
371
+ };
372
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Client Tool 契约 — 客户端能力接入 agent tool 面
3
+ *
4
+ * 设计见 arch/client-tools.md。与 Server Tool 同构进 tool 面;
5
+ * 结果只允许小结构化 value 或 asset 引用(禁止大字节内联)。
6
+ * 解释(OCR/抽取)在 server,client 只规范化。
7
+ */
8
+ import type { ToolParameter } from '@octopi-agent/core/types/tools.js';
9
+ /** 注册名(进 LLM tool 列表;snake_case) */
10
+ export type ClientToolName = string;
11
+ /** 调用归属单元 id(Gateway 生成) */
12
+ export type ClientToolCallId = string;
13
+ export type ClientToolInteraction = 'silent' | 'ui' | 'device';
14
+ export type ClientToolSensitivity = 'public' | 'personal' | 'sensitive';
15
+ export interface ClientToolDeviceMeta {
16
+ class?: 'sensor' | 'actuator' | 'media_io';
17
+ sensitivity?: ClientToolSensitivity;
18
+ /** none | prompt | strict — sensitive 不得为 none */
19
+ consent?: 'none' | 'prompt' | 'strict';
20
+ }
21
+ /** 候选端过滤(LLM 不可见 instanceId;钉端走注册描述符) */
22
+ export interface ClientToolClientFilter {
23
+ platforms?: string[];
24
+ instanceId?: string;
25
+ }
26
+ /**
27
+ * 插件/客户端注册的工具描述符。
28
+ * `parameters` 与 Core `ToolDefinition.parameters` 同形,便于直接装进 tool 面。
29
+ */
30
+ export interface ClientToolDescriptor {
31
+ name: ClientToolName;
32
+ /** 工具描述:用途/输入/结果。禁止 UI 控件与布局词汇 */
33
+ description: string;
34
+ parameters: Record<string, ToolParameter>;
35
+ interaction?: ClientToolInteraction;
36
+ device?: ClientToolDeviceMeta;
37
+ /** 哪些端可执行;缺省 = 任一已声明该 name 的 live client */
38
+ clientFilter?: ClientToolClientFilter;
39
+ /** 声明可能的结果种类(LLM 结果仅 value/asset;source/sink 为 Host 通道) */
40
+ resultKinds?: Array<'value' | 'asset'>;
41
+ /** 解释发生地:默认 server;local 仅标注端上处理(审计),schema 校验不变 */
42
+ processing?: 'server' | 'local';
43
+ /**
44
+ * 声明为 Host 流通道域工具(§15.1):
45
+ * source=watch 类,sink=播放类。LLM 仍只拿 value 域句柄。
46
+ */
47
+ stream?: {
48
+ /** source=watch 类;sink=播放类;stop=按域句柄关通道 */
49
+ direction: 'source' | 'sink' | 'stop';
50
+ /** value 句柄字段名,默认 watchId / playId */
51
+ handleKey?: string;
52
+ };
53
+ version?: string;
54
+ }
55
+ export type ClientToolResult = {
56
+ kind: 'value';
57
+ data: unknown;
58
+ } | {
59
+ kind: 'asset';
60
+ assetId: string;
61
+ mime: string;
62
+ sizeBytes: number;
63
+ name?: string;
64
+ preview?: string;
65
+ };
66
+ export type ClientToolErrorReason = 'invalid_arguments' | 'client_unavailable' | 'consent_denied' | 'permission_denied' | 'expired' | 'cancelled' | 'unsupported' | 'internal';
67
+ export type ClientToolCallOutcome = {
68
+ status: 'ok';
69
+ result: ClientToolResult;
70
+ processing?: 'server' | 'local';
71
+ } | {
72
+ status: 'error';
73
+ reason: ClientToolErrorReason;
74
+ hint?: string;
75
+ processing?: 'server' | 'local';
76
+ };
77
+ export interface ClientToolCall {
78
+ id: ClientToolCallId;
79
+ name: ClientToolName;
80
+ sessionId: string;
81
+ runId?: string;
82
+ agentId: string;
83
+ args: Record<string, unknown>;
84
+ /** 路由解析后的目标端;未解析时 undefined */
85
+ targetClientInstanceId?: string;
86
+ state: 'pending' | 'running' | 'succeeded' | 'failed';
87
+ outcome?: ClientToolCallOutcome;
88
+ completedByPrincipalId?: string;
89
+ /** html_ui 等大正文落 attachment 后的引用 */
90
+ assetId?: string;
91
+ /** 解释发生地(审计) */
92
+ processing?: 'server' | 'local';
93
+ /** 调用解析时的敏感度(换端判定,§15.3) */
94
+ sensitivity?: ClientToolSensitivity;
95
+ /** 调用解析时是否 clientFilter 钉端(钉端不换端) */
96
+ pinnedClient?: boolean;
97
+ createdAt: number;
98
+ ttlAt: number;
99
+ }
100
+ /** 已注册到某客户端实例的能力 */
101
+ export interface ClientToolProvider {
102
+ clientInstanceId: string;
103
+ sessionId: string;
104
+ platform?: string;
105
+ principalId?: string;
106
+ /** 最近活跃时间戳,用于默认路由(最近活跃端) */
107
+ lastActiveAt: number;
108
+ descriptors: ClientToolDescriptor[];
109
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Client Tool 契约 — 客户端能力接入 agent tool 面
3
+ *
4
+ * 设计见 arch/client-tools.md。与 Server Tool 同构进 tool 面;
5
+ * 结果只允许小结构化 value 或 asset 引用(禁止大字节内联)。
6
+ * 解释(OCR/抽取)在 server,client 只规范化。
7
+ */
8
+ export {};
@@ -5,6 +5,7 @@
5
5
  */
6
6
  export * from './plugins/index.js';
7
7
  export * from './tools/index.js';
8
+ export * from './client-tools/index.js';
8
9
  export type { ChannelAdapter, ChannelMessage, ChannelReply } from './channel-types.js';
9
10
  export { DefaultSkillManager, FileSystemSkillSource } from './skills/manager.js';
10
11
  export type { SkillSource, DiscoveredSkill } from './skills/manager.js';
@@ -5,6 +5,7 @@
5
5
  */
6
6
  export * from './plugins/index.js';
7
7
  export * from './tools/index.js';
8
+ export * from './client-tools/index.js';
8
9
  export { DefaultSkillManager, FileSystemSkillSource } from './skills/manager.js';
9
10
  export * from './mcp/index.js';
10
11
  export * from './commands/index.js';
@@ -219,7 +219,7 @@ export function createFileReadTool(options) {
219
219
  const selected = lines.slice(start, end).join('\n');
220
220
  const { applyToolOutputGate, resolveSupportBinding } = await import('../../../context/capabilities/summary/index.js');
221
221
  const support = options?.summary;
222
- const binding = resolveSupportBinding('file_read', support, 12000);
222
+ const binding = resolveSupportBinding('file_read', support, 36000);
223
223
  const applied = await applyToolOutputGate({
224
224
  tool: 'file_read',
225
225
  rawBody: selected,
@@ -4,7 +4,7 @@
4
4
  * 写入经 confidence + gates;检索含 shadow、排除 deleted。
5
5
  */
6
6
  import type { RegisteredTool } from '@octopi-agent/core/types.js';
7
- import type { MemoryStore } from '../../../memory/types.js';
7
+ import type { MemoryChannel, MemoryStore, MemoryType } from '../../../memory/types.js';
8
8
  import { type ConfidenceProfileConfig } from '../../../memory/confidence.js';
9
9
  import { type GateConfig } from '../../../memory/gates.js';
10
10
  export interface MemoryToolOptions {
@@ -12,6 +12,16 @@ export interface MemoryToolOptions {
12
12
  gates?: GateConfig;
13
13
  /** 每次触发默认最大写入条数提示(工具描述用) */
14
14
  maxWritesPerTrigger?: number;
15
+ /** 成功落库后回调(概念化触发等);不得抛错打断写路径 */
16
+ onStored?: (info: {
17
+ id: string;
18
+ proposition: string;
19
+ evidence: string;
20
+ type: MemoryType;
21
+ status: string;
22
+ channel: MemoryChannel;
23
+ sessionId?: string;
24
+ }) => void;
15
25
  }
16
26
  /** 创建记忆工具集 */
17
27
  export declare function createMemoryTools(store: MemoryStore, options?: MemoryToolOptions): RegisteredTool[];
@@ -136,6 +136,20 @@ export function createMemoryStoreTool(store, options) {
136
136
  winnerId: id,
137
137
  });
138
138
  }
139
+ try {
140
+ options?.onStored?.({
141
+ id,
142
+ proposition,
143
+ evidence,
144
+ type,
145
+ status,
146
+ channel,
147
+ sessionId: context.sessionId,
148
+ });
149
+ }
150
+ catch {
151
+ // 触发回调失败不影响 Memory 已落库事实
152
+ }
139
153
  return {
140
154
  id,
141
155
  stored: true,
@@ -95,12 +95,13 @@ export type { AgentRuntimeConfig, Trigger, TriggerType, TriggerPayload, TriggerS
95
95
  export type { KnowledgeCatalogItem, KnowledgeCatalogProvider } from './knowledge/catalog-index.js';
96
96
  export { KnowledgeDatabase, KnowledgeSourceStore, KnowledgeIndexStore, KnowledgeIngest, KnowledgeRetriever, GroundingAssembler, formatKnowledgeGroundingMessage, resolveGroundingQuery, wrapUntrustedKnowledgeBlock, isKnowledgeGroundingMessage, stripKnowledgeGrounding, KnowledgeHitLog, KnowledgePurger, FormatAdapterRegistry, resolveKnowledgePaths, generateKnowledgeDescription, heuristicDescription, scanSecretShapes, hashContent, textAdapter, markdownAdapter, codeAdapter, } from './knowledge/index.js';
97
97
  export type { KnowledgeDatabaseOptions, KnowledgePaths, KnowledgeDescribePort, KnowledgeDescribeOptions, KnowledgeDescribeResult, KnowledgeSource, KnowledgeSourceInput, KnowledgeSourcePatch, KnowledgeSourceKind, KnowledgeSourceStatus, KnowledgeSourceSync, KnowledgeSourceError, KnowledgeScopeRef, KnowledgeScopeLevel, KnowledgeIngestOptions, IngestProgressEvent, IngestJobKind, HybridSearchOptions, HybridSearchResult, AutoGroundDecision, GroundingMode, KnowledgeRetrieverOptions, KnowledgeHitRecord, KnowledgeHitStats, PromotionCandidate, PurgeResult, FormatAdapter, KnowledgeChunkDraft, IndexedFileRecord, ChunkHit, } from './knowledge/index.js';
98
- export { InMemoryMemoryStore, InMemoryConceptGraph, AgentDatabase, SqliteMemoryStore, SqliteWisdomStore, SqliteConceptGraph, createEmbeddingProvider } from './memory/index.js';
98
+ export { InMemoryMemoryStore, InMemoryWisdomStore, InMemoryConceptGraph, AgentDatabase, SqliteMemoryStore, SqliteWisdomStore, SqliteConceptGraph, createEmbeddingProvider } from './memory/index.js';
99
99
  export type { AgentDatabaseOptions, SqliteMemoryStoreOptions, SqliteConceptGraphOptions, EmbeddingProvider, EmbeddingConfig } from './memory/index.js';
100
100
  export { createEmbeddingProviderFromModels, resolveEmbeddingRuntime, isEmbeddingEnabled, tokenizeKeywordQuery, scoreKeywordFields, } from './memory/index.js';
101
101
  export type { MemoryType, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore } from './memory/types.js';
102
- export type { WisdomEntry, WisdomStore } from './memory/types.js';
103
- export type { ConceptNode, ConceptEdge, ConceptGraph, ConceptGraphStore } from './memory/types.js';
102
+ export type { WisdomEntry, WisdomStore, WisdomStatus, WisdomOrigin, WisdomKind, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomOutcomes, AdmitWisdomInput, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomStats, } from './memory/types.js';
103
+ export type { ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './memory/types.js';
104
+ export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, } from './memory/index.js';
104
105
  export type { Planner, Reflector, AgentState, AgentStats, Plan, PlanStep, StepResult, ExecutionRecord, Assessment, Pattern, } from './collaboration/orchestration/cognitive-loop.js';
105
106
  export type { SessionData, SessionLifecycleMeta, SessionLifecycleStatus, MemoryExtractionStatus } from './session/types.js';
106
107
  export { SessionAwareRunner } from './run/runner.js';
@@ -75,8 +75,9 @@ export { KnowledgeDatabase, KnowledgeSourceStore, KnowledgeIndexStore, Knowledge
75
75
  // ── Concurrency ──
76
76
  // (exported from concurrency/index.ts)
77
77
  // ── Memory ──
78
- export { InMemoryMemoryStore, InMemoryConceptGraph, AgentDatabase, SqliteMemoryStore, SqliteWisdomStore, SqliteConceptGraph, createEmbeddingProvider } from './memory/index.js';
78
+ export { InMemoryMemoryStore, InMemoryWisdomStore, InMemoryConceptGraph, AgentDatabase, SqliteMemoryStore, SqliteWisdomStore, SqliteConceptGraph, createEmbeddingProvider } from './memory/index.js';
79
79
  export { createEmbeddingProviderFromModels, resolveEmbeddingRuntime, isEmbeddingEnabled, tokenizeKeywordQuery, scoreKeywordFields, } from './memory/index.js';
80
+ export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, } from './memory/index.js';
80
81
  // ── Runner ──
81
82
  export { SessionAwareRunner } from './run/runner.js';
82
83
  // ── Tool effect isolation (I5) ──
@@ -100,7 +100,7 @@ export class LocalKnowledgeQueryService {
100
100
  }
101
101
  async principalStats(agentId, identity) {
102
102
  const { sources, db } = this.deps;
103
- const visible = sources.listVisible(agentId).filter((s) => {
103
+ const visible = sources.listVisible(agentId, undefined, identity).filter((s) => {
104
104
  return !identity || this.gatewayVisible(s, identity);
105
105
  });
106
106
  const stats = db.stats();
@@ -110,7 +110,7 @@ export class LocalKnowledgeQueryService {
110
110
  assignedProjects: sources
111
111
  .list()
112
112
  .filter((s) => s.scopeRef.level === 'project' &&
113
- sources.isVisible(s, agentId) &&
113
+ sources.isVisible(s, agentId, undefined, identity) &&
114
114
  (!identity || this.gatewayVisible(s, identity)))
115
115
  .map((s) => s.scopeRef.key),
116
116
  hiddenSourceIds: sources.listHidden(agentId, identity ?? {}),
@@ -119,7 +119,7 @@ export class LocalKnowledgeQueryService {
119
119
  };
120
120
  }
121
121
  async catalog(agentId, identity) {
122
- const items = this.deps.sources.catalogFor(agentId);
122
+ const items = this.deps.sources.catalogFor(agentId, { identity });
123
123
  if (!identity)
124
124
  return items;
125
125
  return items.filter((item) => {
@@ -134,7 +134,7 @@ export class LocalKnowledgeQueryService {
134
134
  return null;
135
135
  if (identity && !this.gatewayVisible(src, identity))
136
136
  return null;
137
- if (!sources.isVisible(src, agentId, sessionId))
137
+ if (!sources.isVisible(src, agentId, sessionId, identity))
138
138
  return null;
139
139
  return index.listChunksByPath(sourceId, path);
140
140
  }
@@ -145,7 +145,7 @@ export class LocalKnowledgeQueryService {
145
145
  return false;
146
146
  if (identity && !this.gatewayVisible(src, identity))
147
147
  return false;
148
- return sources.isVisible(src, agentId, sessionId);
148
+ return sources.isVisible(src, agentId, sessionId, identity);
149
149
  };
150
150
  if (body.chunkId) {
151
151
  const row = index.getChunk(body.chunkId);
@@ -33,7 +33,7 @@ export class KnowledgeRetriever {
33
33
  */
34
34
  visibleSourceIds(agentId, sessionId, identity) {
35
35
  return this.sources
36
- .listVisible(agentId, sessionId)
36
+ .listVisible(agentId, sessionId, identity)
37
37
  .filter((s) => this.sources.isGatewayVisible(s, identity))
38
38
  .map((s) => s.id);
39
39
  }