@octopi-agent/engine 0.58.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 (226) hide show
  1. package/dist/config-schema/context.d.ts +1 -1
  2. package/dist/config-schema/context.js +1 -1
  3. package/dist/config-schema/engine.d.ts +122 -1
  4. package/dist/config-schema/engine.js +4 -1
  5. package/dist/config-schema/substrate.d.ts +123 -0
  6. package/dist/config-schema/substrate.js +161 -0
  7. package/dist/config.d.ts +101 -1
  8. package/dist/harness/agent/builder.d.ts +15 -1
  9. package/dist/harness/agent/builder.js +41 -4
  10. package/dist/harness/agent/config-bridge.js +17 -4
  11. package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.d.ts +1 -1
  12. package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.js +1 -1
  13. package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.d.ts +1 -1
  14. package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.js +1 -1
  15. package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.d.ts +1 -1
  16. package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.js +13 -3
  17. package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.d.ts +1 -1
  18. package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.js +13 -4
  19. package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.d.ts +1 -1
  20. package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.js +25 -5
  21. package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.d.ts +1 -1
  22. package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.js +1 -1
  23. package/dist/harness/{context/capabilities → capabilities}/document/errors.d.ts +1 -1
  24. package/dist/harness/{context/capabilities → capabilities}/document/errors.js +1 -1
  25. package/dist/harness/capabilities/document/factory.d.ts +33 -0
  26. package/dist/harness/capabilities/document/factory.js +37 -0
  27. package/dist/harness/{context/capabilities → capabilities}/document/format.d.ts +1 -1
  28. package/dist/harness/{context/capabilities → capabilities}/document/format.js +1 -1
  29. package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.d.ts +1 -1
  30. package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.js +1 -1
  31. package/dist/harness/{context/capabilities → capabilities}/document/index.d.ts +3 -1
  32. package/dist/harness/{context/capabilities → capabilities}/document/index.js +2 -1
  33. package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.d.ts +3 -1
  34. package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.js +3 -1
  35. package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.d.ts +3 -1
  36. package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.js +44 -1
  37. package/dist/harness/{context/capabilities → capabilities}/document/port.d.ts +1 -1
  38. package/dist/harness/{context/capabilities → capabilities}/document/port.js +4 -4
  39. package/dist/harness/{context/capabilities → capabilities}/document/types.d.ts +11 -1
  40. package/dist/harness/{context/capabilities → capabilities}/document/types.js +1 -1
  41. package/dist/harness/capabilities/document/worker-port.d.ts +13 -0
  42. package/dist/harness/capabilities/document/worker-port.js +78 -0
  43. package/dist/harness/context/capabilities/index.d.ts +2 -2
  44. package/dist/harness/context/capabilities/index.js +2 -2
  45. package/dist/harness/context/capabilities/summary/gate.js +2 -2
  46. package/dist/harness/context/capabilities/summary/policies.js +5 -5
  47. package/dist/harness/context/capabilities/summary/registry.js +29 -24
  48. package/dist/harness/context/layer-health.js +3 -2
  49. package/dist/harness/context/layers.d.ts +27 -13
  50. package/dist/harness/context/layers.js +76 -66
  51. package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
  52. package/dist/harness/context/system-prompt-assembler.js +11 -1
  53. package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
  54. package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
  55. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
  56. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
  57. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
  58. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
  59. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
  60. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
  61. package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
  62. package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
  63. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  64. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  65. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
  66. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.d.ts +10 -0
  67. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +102 -5
  68. package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
  69. package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
  70. package/dist/harness/index.d.ts +8 -5
  71. package/dist/harness/index.js +4 -2
  72. package/dist/harness/knowledge/adapters.d.ts +8 -5
  73. package/dist/harness/knowledge/adapters.js +53 -13
  74. package/dist/harness/knowledge/client.d.ts +197 -0
  75. package/dist/harness/knowledge/client.js +237 -0
  76. package/dist/harness/knowledge/connector-fetcher.d.ts +2 -2
  77. package/dist/harness/knowledge/connectors.d.ts +3 -3
  78. package/dist/harness/knowledge/connectors.js +14 -8
  79. package/dist/harness/knowledge/db.d.ts +40 -5
  80. package/dist/harness/knowledge/db.js +441 -113
  81. package/dist/harness/knowledge/document-extract-worker.js +55 -12
  82. package/dist/harness/knowledge/embed-runner.d.ts +53 -0
  83. package/dist/harness/knowledge/embed-runner.js +171 -0
  84. package/dist/harness/knowledge/engine-thread.d.ts +1 -0
  85. package/dist/harness/knowledge/engine-thread.js +302 -0
  86. package/dist/harness/knowledge/extract-document.d.ts +21 -5
  87. package/dist/harness/knowledge/extract-document.js +32 -8
  88. package/dist/harness/knowledge/fetchers.d.ts +14 -3
  89. package/dist/harness/knowledge/fetchers.js +52 -16
  90. package/dist/harness/knowledge/file-identity.d.ts +53 -0
  91. package/dist/harness/knowledge/file-identity.js +172 -0
  92. package/dist/harness/knowledge/file-index-store.d.ts +50 -0
  93. package/dist/harness/knowledge/file-index-store.js +132 -0
  94. package/dist/harness/knowledge/file-limits.d.ts +86 -0
  95. package/dist/harness/knowledge/file-limits.js +175 -0
  96. package/dist/harness/knowledge/fts.d.ts +60 -0
  97. package/dist/harness/knowledge/fts.js +218 -0
  98. package/dist/harness/knowledge/grounding.d.ts +3 -2
  99. package/dist/harness/knowledge/http-app.d.ts +50 -0
  100. package/dist/harness/knowledge/http-app.js +652 -0
  101. package/dist/harness/knowledge/http-bridge.d.ts +49 -0
  102. package/dist/harness/knowledge/http-bridge.js +17 -0
  103. package/dist/harness/knowledge/index-store.d.ts +158 -93
  104. package/dist/harness/knowledge/index-store.js +982 -441
  105. package/dist/harness/knowledge/index.d.ts +45 -5
  106. package/dist/harness/knowledge/index.js +23 -2
  107. package/dist/harness/knowledge/ingest.d.ts +262 -87
  108. package/dist/harness/knowledge/ingest.js +1072 -480
  109. package/dist/harness/knowledge/job-control-state.d.ts +29 -0
  110. package/dist/harness/knowledge/job-control-state.js +44 -0
  111. package/dist/harness/knowledge/job-control.d.ts +35 -0
  112. package/dist/harness/knowledge/job-control.js +86 -0
  113. package/dist/harness/knowledge/job-queue.d.ts +62 -0
  114. package/dist/harness/knowledge/job-queue.js +173 -0
  115. package/dist/harness/knowledge/knowledge-serve-child.d.ts +1 -0
  116. package/dist/harness/knowledge/knowledge-serve-child.js +100 -0
  117. package/dist/harness/knowledge/local-stack.d.ts +27 -0
  118. package/dist/harness/knowledge/local-stack.js +63 -0
  119. package/dist/harness/knowledge/membership-store.d.ts +65 -0
  120. package/dist/harness/knowledge/membership-store.js +198 -0
  121. package/dist/harness/knowledge/network-guard.d.ts +11 -2
  122. package/dist/harness/knowledge/network-guard.js +130 -85
  123. package/dist/harness/knowledge/parse-text-in-worker.d.ts +32 -0
  124. package/dist/harness/knowledge/parse-text-in-worker.js +158 -0
  125. package/dist/harness/knowledge/query-service.d.ts +272 -0
  126. package/dist/harness/knowledge/query-service.js +326 -0
  127. package/dist/harness/knowledge/query-worker-client.d.ts +96 -0
  128. package/dist/harness/knowledge/query-worker-client.js +207 -0
  129. package/dist/harness/knowledge/query-worker.d.ts +1 -0
  130. package/dist/harness/knowledge/query-worker.js +186 -0
  131. package/dist/harness/knowledge/read-http.d.ts +35 -0
  132. package/dist/harness/knowledge/read-http.js +373 -0
  133. package/dist/harness/knowledge/retriever.d.ts +22 -5
  134. package/dist/harness/knowledge/retriever.js +66 -35
  135. package/dist/harness/knowledge/secret-scan.d.ts +13 -2
  136. package/dist/harness/knowledge/secret-scan.js +25 -2
  137. package/dist/harness/knowledge/serve.d.ts +48 -0
  138. package/dist/harness/knowledge/serve.js +336 -0
  139. package/dist/harness/knowledge/source-store.d.ts +97 -19
  140. package/dist/harness/knowledge/source-store.js +166 -94
  141. package/dist/harness/knowledge/start-service-process.d.ts +49 -0
  142. package/dist/harness/knowledge/start-service-process.js +158 -0
  143. package/dist/harness/knowledge/text-parse-worker.d.ts +1 -0
  144. package/dist/harness/knowledge/text-parse-worker.js +54 -0
  145. package/dist/harness/knowledge/types.d.ts +1 -1
  146. package/dist/harness/knowledge/types.js +1 -1
  147. package/dist/harness/knowledge/vector-ann.d.ts +42 -0
  148. package/dist/harness/knowledge/vector-ann.js +68 -0
  149. package/dist/harness/knowledge/writer-lock.d.ts +13 -0
  150. package/dist/harness/knowledge/writer-lock.js +71 -0
  151. package/dist/harness/knowledge/writer-service.d.ts +194 -0
  152. package/dist/harness/knowledge/writer-service.js +355 -0
  153. package/dist/harness/knowledge/writer-worker-client.d.ts +102 -0
  154. package/dist/harness/knowledge/writer-worker-client.js +381 -0
  155. package/dist/harness/knowledge/writer-worker.d.ts +1 -0
  156. package/dist/harness/knowledge/writer-worker.js +189 -0
  157. package/dist/harness/memory/cognition-decay.d.ts +36 -0
  158. package/dist/harness/memory/cognition-decay.js +55 -0
  159. package/dist/harness/memory/cognition-gates.d.ts +60 -0
  160. package/dist/harness/memory/cognition-gates.js +191 -0
  161. package/dist/harness/memory/cognition-trigger.d.ts +30 -0
  162. package/dist/harness/memory/cognition-trigger.js +41 -0
  163. package/dist/harness/memory/cognition-types.d.ts +1 -1
  164. package/dist/harness/memory/cognition.d.ts +40 -8
  165. package/dist/harness/memory/cognition.js +432 -79
  166. package/dist/harness/memory/conceptualizer.d.ts +66 -0
  167. package/dist/harness/memory/conceptualizer.js +246 -0
  168. package/dist/harness/memory/index.d.ts +16 -2
  169. package/dist/harness/memory/index.js +11 -1
  170. package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
  171. package/dist/harness/memory/sqlite/agent-db.js +118 -15
  172. package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
  173. package/dist/harness/memory/sqlite/cognition-store.js +591 -144
  174. package/dist/harness/memory/sqlite/embedding.d.ts +5 -2
  175. package/dist/harness/memory/sqlite/embedding.js +109 -16
  176. package/dist/harness/memory/sqlite/keyword-search.d.ts +21 -0
  177. package/dist/harness/memory/sqlite/keyword-search.js +64 -0
  178. package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
  179. package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
  180. package/dist/harness/memory/types.d.ts +331 -16
  181. package/dist/harness/memory/types.js +49 -0
  182. package/dist/harness/memory/wisdom-formation.d.ts +101 -0
  183. package/dist/harness/memory/wisdom-formation.js +304 -0
  184. package/dist/harness/memory/wisdom-gates.d.ts +50 -0
  185. package/dist/harness/memory/wisdom-gates.js +204 -0
  186. package/dist/harness/memory/wisdom-policy.d.ts +107 -0
  187. package/dist/harness/memory/wisdom-policy.js +220 -0
  188. package/dist/harness/memory/wisdom-types.d.ts +3 -2
  189. package/dist/harness/memory/wisdom-types.js +2 -2
  190. package/dist/harness/memory/wisdom.d.ts +27 -0
  191. package/dist/harness/memory/wisdom.js +181 -0
  192. package/dist/harness/run/agent/agent.d.ts +9 -0
  193. package/dist/harness/run/agent/agent.js +19 -0
  194. package/dist/harness/run/reliability/run-agent.js +6 -2
  195. package/dist/harness/run/runner.js +2 -1
  196. package/dist/harness/session/attachments/service.d.ts +1 -1
  197. package/dist/harness/session/attachments/service.js +1 -1
  198. package/dist/harness/session/index.d.ts +1 -0
  199. package/dist/harness/session/index.js +1 -0
  200. package/dist/harness/session/title.d.ts +86 -0
  201. package/dist/harness/session/title.js +268 -0
  202. package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
  203. package/dist/harness/shared/events/agent-event-map.js +1 -0
  204. package/dist/index.d.ts +7 -3
  205. package/dist/index.js +3 -1
  206. package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
  207. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
  208. package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
  209. package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
  210. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
  211. package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
  212. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
  213. package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
  214. package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
  215. package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
  216. package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
  217. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
  218. package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
  219. package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
  220. package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
  221. package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
  222. package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
  223. package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
  224. package/dist/worker-path.d.ts +8 -0
  225. package/dist/worker-path.js +15 -0
  226. package/package.json +2 -2
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 将 .doc/.xls/.ppt 转为 OOXML 后走 T0 抽取;不常驻、用完即退。
5
5
  *
6
- * @module harness/context/capabilities/document/legacy/soffice
6
+ * @module harness/capabilities/document/legacy/soffice
7
7
  */
8
8
  import { spawn } from 'node:child_process';
9
9
  import { createHash } from 'node:crypto';
@@ -31,6 +31,7 @@ export function createSofficeLegacyConverter(options = {}) {
31
31
  const timeoutMs = options.timeoutMs ?? 60_000;
32
32
  const maxInputBytes = options.maxInputBytes ?? 50 * 1024 * 1024;
33
33
  const cacheDir = options.cacheDir?.trim() || null;
34
+ const cacheMaxBytes = options.cacheMaxBytes ?? 256 * 1024 * 1024;
34
35
  return {
35
36
  id: 'soffice',
36
37
  async isAvailable() {
@@ -72,6 +73,7 @@ export function createSofficeLegacyConverter(options = {}) {
72
73
  try {
73
74
  await mkdir(cacheDir, { recursive: true });
74
75
  await writeFile(join(cacheDir, cacheKey), result.data);
76
+ await evictCacheDir(cacheDir, cacheMaxBytes);
75
77
  }
76
78
  catch {
77
79
  // cache write is best-effort
@@ -81,6 +83,47 @@ export function createSofficeLegacyConverter(options = {}) {
81
83
  },
82
84
  };
83
85
  }
86
+ /** 缓存超限时按 mtime 淘汰最旧(含当前新写入后仍超的情况) */
87
+ async function evictCacheDir(cacheDir, maxBytes) {
88
+ if (maxBytes <= 0)
89
+ return;
90
+ const { readdir } = await import('node:fs/promises');
91
+ let entries;
92
+ try {
93
+ entries = (await readdir(cacheDir, { withFileTypes: true }))
94
+ .filter((e) => e.isFile())
95
+ .map((e) => ({ name: e.name, mtimeMs: 0, size: 0 }));
96
+ }
97
+ catch {
98
+ return;
99
+ }
100
+ let total = 0;
101
+ for (const e of entries) {
102
+ try {
103
+ const st = await stat(join(cacheDir, e.name));
104
+ e.mtimeMs = st.mtimeMs;
105
+ e.size = st.size;
106
+ total += st.size;
107
+ }
108
+ catch {
109
+ // 已消失
110
+ }
111
+ }
112
+ if (total <= maxBytes)
113
+ return;
114
+ entries.sort((a, b) => a.mtimeMs - b.mtimeMs);
115
+ for (const e of entries) {
116
+ if (total <= maxBytes)
117
+ break;
118
+ try {
119
+ await rm(join(cacheDir, e.name), { force: true });
120
+ total -= e.size;
121
+ }
122
+ catch {
123
+ // 淘汰失败跳过
124
+ }
125
+ }
126
+ }
84
127
  async function readSourcePath(source, maxInputBytes) {
85
128
  if (!source.path) {
86
129
  throw new DocumentExtractError('INVALID_SOURCE', 'legacy convert requires path or data');
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * createDefaultDocumentPort — DocumentPort 工厂 / 默认路由
3
3
  *
4
- * @module harness/context/capabilities/document/port
4
+ * @module harness/capabilities/document/port
5
5
  */
6
6
  import type { CreateDocumentPortOptions, DocumentExtractBackend, DocumentPort } from './types.js';
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * createDefaultDocumentPort — DocumentPort 工厂 / 默认路由
3
3
  *
4
- * @module harness/context/capabilities/document/port
4
+ * @module harness/capabilities/document/port
5
5
  */
6
6
  import { open, readFile, stat } from 'node:fs/promises';
7
7
  import { resolve, sep } from 'node:path';
@@ -64,8 +64,8 @@ function tierOrder(tier) {
64
64
  return ['t2', 't1', 't0'];
65
65
  return ['t0', 't1', 't2'];
66
66
  }
67
- async function resolveBytes(source, config) {
68
- const maxBytes = config.maxFileBytes ?? DEFAULT_CONFIG.maxFileBytes;
67
+ async function resolveBytes(source, config, extractOptions) {
68
+ const maxBytes = extractOptions?.maxFileBytes ?? config.maxFileBytes ?? DEFAULT_CONFIG.maxFileBytes;
69
69
  if (source.data) {
70
70
  if (source.data.byteLength > maxBytes) {
71
71
  throw new DocumentExtractError('FILE_TOO_LARGE', `document exceeds maxFileBytes (${maxBytes})`);
@@ -243,7 +243,7 @@ export function createDefaultDocumentPort(options = {}) {
243
243
  if (config.enabled === false) {
244
244
  throw new DocumentExtractError('BACKEND_UNAVAILABLE', 'document extract is disabled');
245
245
  }
246
- const { data, name } = await resolveBytes(source, config);
246
+ const { data, name } = await resolveBytes(source, config, extractOptions);
247
247
  const head = data.subarray(0, 8);
248
248
  let format = resolveFormat(source, head);
249
249
  if (format === 'unknown') {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 读路径统一抽取为 Markdown;写路径不进本 Port。
5
5
  *
6
- * @module harness/context/capabilities/document/types
6
+ * @module harness/capabilities/document/types
7
7
  */
8
8
  /** 品牌 ID:后端名 / 转换器名 */
9
9
  export type DocumentBackendId = string;
@@ -32,6 +32,16 @@ export interface ExtractOptions {
32
32
  tier?: ExtractTier;
33
33
  /** 取消 / 会话级 abort */
34
34
  signal?: AbortSignal;
35
+ /** 本次调用的大小闸门(覆盖 port 配置;知识索引 partial 用) */
36
+ maxFileBytes?: number;
37
+ /** 部分抽取:xlsx 最大 sheet 数 */
38
+ maxSheets?: number;
39
+ /** 部分抽取:xlsx 每 sheet 最大行数 */
40
+ maxRowsPerSheet?: number;
41
+ /** 部分抽取:pdf 最大页数 */
42
+ maxPages?: number;
43
+ /** 部分抽取:纯文本最大字符数 */
44
+ maxTextChars?: number;
35
45
  }
36
46
  export interface DocumentMeta {
37
47
  format: DocumentFormatHint;
@@ -3,6 +3,6 @@
3
3
  *
4
4
  * 读路径统一抽取为 Markdown;写路径不进本 Port。
5
5
  *
6
- * @module harness/context/capabilities/document/types
6
+ * @module harness/capabilities/document/types
7
7
  */
8
8
  export {};
@@ -0,0 +1,13 @@
1
+ import type { DocumentPort } from './types.js';
2
+ import type { DocumentCapabilityConfig } from './factory.js';
3
+ /**
4
+ * 创建 extract 走 worker 的 DocumentPort。
5
+ *
6
+ * @param options.documentConfig - documents.* 根配置
7
+ * @param options.concurrency - 并发 worker 上限(默认 2)
8
+ * @returns DocumentPort(probe/capabilities 仍进程内,轻量)
9
+ */
10
+ export declare function createWorkerDocumentPort(options?: {
11
+ documentConfig?: DocumentCapabilityConfig | null;
12
+ concurrency?: number;
13
+ }): DocumentPort;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * WorkerDocumentPort — DocumentPort.extract 走独立线程
3
+ *
4
+ * Gateway 侧 attachments / document_read 用本包装:SheetJS 同步解析不得占主事件循环。
5
+ * 实现复用 knowledge 的 extractDocumentInWorker(单条 worker 抽取路径)。
6
+ */
7
+ import { extractDocumentInWorker } from '../../knowledge/extract-document.js';
8
+ import { createDocumentPortFromConfig } from './factory.js';
9
+ const DEFAULT_CONCURRENCY = 2;
10
+ let inFlight = 0;
11
+ const waiters = [];
12
+ /** 槽位移交:唤醒 waiter 时把槽交给对方,防止减后加窗口超卖 */
13
+ async function acquire(max) {
14
+ if (inFlight < max) {
15
+ inFlight += 1;
16
+ return;
17
+ }
18
+ await new Promise((resolve) => waiters.push(resolve));
19
+ }
20
+ function release() {
21
+ const next = waiters.shift();
22
+ if (next) {
23
+ next();
24
+ return;
25
+ }
26
+ inFlight = Math.max(0, inFlight - 1);
27
+ }
28
+ /**
29
+ * 创建 extract 走 worker 的 DocumentPort。
30
+ *
31
+ * @param options.documentConfig - documents.* 根配置
32
+ * @param options.concurrency - 并发 worker 上限(默认 2)
33
+ * @returns DocumentPort(probe/capabilities 仍进程内,轻量)
34
+ */
35
+ export function createWorkerDocumentPort(options) {
36
+ const inner = createDocumentPortFromConfig(options?.documentConfig ?? null);
37
+ const max = options?.concurrency ?? DEFAULT_CONCURRENCY;
38
+ return {
39
+ async extract(source, extractOptions) {
40
+ if (source.data) {
41
+ // 内联 buffer:仍经工厂进程内抽(无路径可开 worker;保持 DocumentPort 契约)
42
+ return inner.extract(source, extractOptions);
43
+ }
44
+ if (!source.path) {
45
+ return inner.extract(source, extractOptions);
46
+ }
47
+ await acquire(max);
48
+ try {
49
+ const { result } = await extractDocumentInWorker(source.path, {
50
+ ...(extractOptions?.timeoutMs != null ? { timeoutMs: extractOptions.timeoutMs } : {}),
51
+ ...(extractOptions?.maxFileBytes != null
52
+ ? { maxFileBytes: extractOptions.maxFileBytes }
53
+ : {}),
54
+ ...(extractOptions?.maxSheets != null ? { maxSheets: extractOptions.maxSheets } : {}),
55
+ ...(extractOptions?.maxRowsPerSheet != null
56
+ ? { maxRowsPerSheet: extractOptions.maxRowsPerSheet }
57
+ : {}),
58
+ ...(extractOptions?.maxPages != null ? { maxPages: extractOptions.maxPages } : {}),
59
+ ...(extractOptions?.maxTextChars != null
60
+ ? { maxTextChars: extractOptions.maxTextChars }
61
+ : {}),
62
+ ...(extractOptions?.signal ? { signal: extractOptions.signal } : {}),
63
+ documentConfig: options?.documentConfig ?? null,
64
+ });
65
+ return result;
66
+ }
67
+ finally {
68
+ release();
69
+ }
70
+ },
71
+ capabilities() {
72
+ return inner.capabilities();
73
+ },
74
+ probe(source) {
75
+ return inner.probe(source);
76
+ },
77
+ };
78
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Harness 公用能力(capabilities)门面
2
+ * Context 组装公用能力门面(Summary / Compact)
3
3
  *
4
4
  * 横切可注入能力;不是 LLM 工具面,不计入业务领域口径。
5
+ * 跨域文档抽取在 `harness/capabilities/document`(session/knowledge/tools 共用)。
5
6
  *
6
7
  * @module harness/context/capabilities
7
8
  */
8
9
  export * from './summary/index.js';
9
10
  export * from './compact/index.js';
10
- export * from './document/index.js';
11
11
  export { createMemorySummaryCache } from './summary/memory-cache.js';
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Harness 公用能力(capabilities)门面
2
+ * Context 组装公用能力门面(Summary / Compact)
3
3
  *
4
4
  * 横切可注入能力;不是 LLM 工具面,不计入业务领域口径。
5
+ * 跨域文档抽取在 `harness/capabilities/document`(session/knowledge/tools 共用)。
5
6
  *
6
7
  * @module harness/context/capabilities
7
8
  */
8
9
  export * from './summary/index.js';
9
10
  export * from './compact/index.js';
10
- export * from './document/index.js';
11
11
  export { createMemorySummaryCache } from './summary/memory-cache.js';
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import { estimateTextTokens } from '../../token-estimate-fns.js';
7
7
  export const DEFAULT_GATE = {
8
- minTokens: 2000,
9
- minBytes: 8000,
8
+ minTokens: 6000,
9
+ minBytes: 24000,
10
10
  respectPolicyBudget: true,
11
11
  };
12
12
  /**
@@ -38,7 +38,7 @@ export function createDefaultSummaryPolicies() {
38
38
  ],
39
39
  },
40
40
  preserve: ['full URLs', 'error codes', 'version numbers', 'prices and dates'],
41
- budget: { maxInputTokens: 24000, maxOutputTokens: 2000 },
41
+ budget: { maxInputTokens: 24000, maxOutputTokens: 6000 },
42
42
  output: 'text',
43
43
  oversized: DEFAULT_OVERSIZE,
44
44
  },
@@ -62,7 +62,7 @@ export function createDefaultSummaryPolicies() {
62
62
  exclude: ['Boilerplate repeats'],
63
63
  },
64
64
  preserve: ['paths', 'config keys', 'literal values'],
65
- budget: { maxInputTokens: 20000, maxOutputTokens: 1800 },
65
+ budget: { maxInputTokens: 20000, maxOutputTokens: 5400 },
66
66
  output: 'text',
67
67
  oversized: DEFAULT_OVERSIZE,
68
68
  },
@@ -74,7 +74,7 @@ export function createDefaultSummaryPolicies() {
74
74
  exclude: ['Full source paste', 'Generated noise'],
75
75
  },
76
76
  preserve: ['export names', 'file paths', 'error strings'],
77
- budget: { maxInputTokens: 20000, maxOutputTokens: 1600 },
77
+ budget: { maxInputTokens: 20000, maxOutputTokens: 4800 },
78
78
  output: 'text',
79
79
  oversized: DEFAULT_OVERSIZE,
80
80
  },
@@ -86,7 +86,7 @@ export function createDefaultSummaryPolicies() {
86
86
  exclude: ['Marketing fluff'],
87
87
  },
88
88
  preserve: ['procedure order', 'exact option names'],
89
- budget: { maxInputTokens: 20000, maxOutputTokens: 1800 },
89
+ budget: { maxInputTokens: 20000, maxOutputTokens: 5400 },
90
90
  output: 'text',
91
91
  oversized: DEFAULT_OVERSIZE,
92
92
  },
@@ -98,7 +98,7 @@ export function createDefaultSummaryPolicies() {
98
98
  exclude: ['Repetitive healthy heartbeats unless asked'],
99
99
  },
100
100
  preserve: ['error codes', 'timestamps', 'request ids'],
101
- budget: { maxInputTokens: 16000, maxOutputTokens: 1400 },
101
+ budget: { maxInputTokens: 16000, maxOutputTokens: 4200 },
102
102
  output: 'text',
103
103
  oversized: TOOL_WINDOW_OVERSIZE,
104
104
  },
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module harness/context/capabilities/summary/registry
5
5
  */
6
- /** 文件扩展名 → ContentKind(声明式路由,非正文抽取) */
6
+ /** 文件扩展名 → ContentKind(声明式路由,非正文抽取;code 优先走 CODE_EXTS) */
7
7
  const EXT_KIND = {
8
8
  '.md': 'file_text',
9
9
  '.markdown': 'file_text',
@@ -11,31 +11,36 @@ const EXT_KIND = {
11
11
  '.log': 'log',
12
12
  '.html': 'web_page',
13
13
  '.htm': 'web_page',
14
- '.json': 'api_json',
15
- '.ts': 'code',
16
- '.tsx': 'code',
17
- '.js': 'code',
18
- '.jsx': 'code',
19
- '.mjs': 'code',
20
- '.cjs': 'code',
21
- '.py': 'code',
22
- '.go': 'code',
23
- '.rs': 'code',
24
- '.java': 'code',
25
- '.kt': 'code',
26
- '.c': 'code',
27
- '.h': 'code',
28
- '.cpp': 'code',
29
- '.css': 'code',
30
- '.yml': 'file_text',
31
- '.yaml': 'file_text',
32
- '.toml': 'file_text',
33
- '.xml': 'file_text',
34
14
  '.csv': 'file_text',
35
15
  };
16
+ /**
17
+ * 可编辑源码/配置/结构化源:kind=code。
18
+ * 含语言、样式、脚本、配置序列化、IDL/构建——agent 通常需要可编辑原文,不走 L2 摘要。
19
+ */
36
20
  const CODE_EXTS = new Set([
37
- '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.py', '.go', '.rs',
38
- '.java', '.kt', '.c', '.h', '.cpp', '.css', '.sql', '.sh',
21
+ // languages
22
+ '.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs',
23
+ '.py', '.pyi', '.pyw',
24
+ '.go', '.rs', '.java', '.kt', '.kts',
25
+ '.c', '.h', '.cc', '.cpp', '.cxx', '.hpp', '.hh', '.hxx',
26
+ '.cs', '.fs', '.fsx', '.vb',
27
+ '.swift', '.scala', '.lua', '.php', '.rb', '.r', '.dart',
28
+ '.pl', '.pm', '.ex', '.exs', '.erl', '.hrl', '.hs',
29
+ '.clj', '.cljs', '.cljc', '.edn',
30
+ '.zig', '.nim', '.cr', '.jl', '.groovy', '.gradle',
31
+ '.vue', '.svelte', '.astro',
32
+ // styles
33
+ '.css', '.scss', '.sass', '.less', '.styl',
34
+ // shell / scripts
35
+ '.sh', '.bash', '.zsh', '.ksh', '.fish', '.ps1', '.bat', '.cmd', '.awk',
36
+ // config / structured source
37
+ '.json', '.jsonl', '.ndjson', '.json5', '.jsonc',
38
+ '.yml', '.yaml', '.toml', '.xml', '.plist',
39
+ '.ini', '.cfg', '.conf', '.config', '.properties',
40
+ '.tf', '.tfvars', '.hcl',
41
+ '.proto', '.thrift', '.graphql', '.gql', '.avsc', '.avdl',
42
+ // build / query
43
+ '.sql', '.cmake', '.mk', '.bazel', '.bzl', '.ninja',
39
44
  ]);
40
45
  /**
41
46
  * 从 MIME 推断 ContentKind
@@ -129,7 +134,7 @@ export function createDefaultToolBindings() {
129
134
  file_read: {
130
135
  tool: 'file_read',
131
136
  mode: 'kind_sensitive',
132
- maxReturnChars: 12000,
137
+ maxReturnChars: 36000,
133
138
  kindFromSource: true,
134
139
  // code 默认不 L2,保护「需要可编辑原文」的场景
135
140
  informationalKinds: ['document', 'log', 'file_text', 'web_page'],
@@ -96,8 +96,9 @@ export async function probeContextLayerHealth(deps) {
96
96
  let wisdomEntries;
97
97
  if (deps.wisdomStore) {
98
98
  try {
99
- const all = await deps.wisdomStore.getAll();
100
- wisdomEntries = all.length;
99
+ const stats = await deps.wisdomStore.stats();
100
+ // 未退役条目(含 trial/contested);不是注入命中数
101
+ wisdomEntries = stats.total - (stats.byStatus.retired ?? 0) - (stats.byStatus.superseded ?? 0);
101
102
  summary.wisdom = wisdomEntries;
102
103
  }
103
104
  catch {
@@ -106,19 +106,35 @@ export declare class CognitionLayer extends BaseLayer {
106
106
  assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
107
107
  }
108
108
  /**
109
- * Wisdom 层 — 从 WisdomStore 读取高优先思维范式
109
+ * Wisdom 层 — 小核心 + 场景匹配注入判断范式
110
110
  *
111
- * 当前薄实现:取全部并按 priority 排序后截断。
112
- * 后续可改为场景匹配 / applicableScenarios 过滤。
111
+ * 不做全量 dump。匹配失败只注入 core(宁缺毋滥)。
113
112
  */
114
113
  export declare class WisdomLayer extends BaseLayer {
115
- private readonly getEntries;
114
+ private readonly select;
115
+ private readonly onInjected?;
116
+ private readonly coreMaxItems?;
117
+ private readonly scenarioMaxItems?;
116
118
  constructor(options: {
117
- getEntries: () => Promise<Array<{
118
- id: string;
119
- content: string;
120
- priority: number;
119
+ select: (query: string) => Promise<Array<{
120
+ entry: {
121
+ id: string;
122
+ statement: string;
123
+ scenario: {
124
+ problemTypes: string[];
125
+ antiScenarios?: string[];
126
+ };
127
+ effect: {
128
+ posture?: string;
129
+ questions?: string[];
130
+ };
131
+ };
132
+ bucket: 'core' | 'scenario';
121
133
  }>>;
134
+ /** S1 applied 入账(注入命中) */
135
+ onInjected?: (ids: string[]) => void | Promise<void>;
136
+ coreMaxItems?: number;
137
+ scenarioMaxItems?: number;
122
138
  order?: number;
123
139
  });
124
140
  assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
@@ -133,11 +149,9 @@ export interface CreateDefaultLayersOptions {
133
149
  knowledgeShowProgress?: 'off' | 'bucket' | 'exact';
134
150
  memoryStore?: MemoryStore;
135
151
  cognitionStore?: ConceptGraphStore;
136
- wisdomEntries?: () => Promise<Array<{
137
- id: string;
138
- content: string;
139
- priority: number;
140
- }>>;
152
+ wisdomStore?: import('../memory/types.js').WisdomStore;
153
+ wisdomCoreMaxItems?: number;
154
+ wisdomScenarioMaxItems?: number;
141
155
  }
142
156
  /**
143
157
  * 按可用依赖创建启用层列表