@qlingzzy/qling 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (512) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/LICENSE +21 -0
  3. package/README.en.md +129 -0
  4. package/README.md +416 -0
  5. package/dist/agent/subtask.d.ts +21 -0
  6. package/dist/agent/subtask.d.ts.map +1 -0
  7. package/dist/agent/subtask.js +55 -0
  8. package/dist/agent-loop.d.ts +151 -0
  9. package/dist/agent-loop.d.ts.map +1 -0
  10. package/dist/agent-loop.js +1498 -0
  11. package/dist/agents/isolation-policy.d.ts +14 -0
  12. package/dist/agents/isolation-policy.d.ts.map +1 -0
  13. package/dist/agents/isolation-policy.js +52 -0
  14. package/dist/channels/console-channel.d.ts +15 -0
  15. package/dist/channels/console-channel.d.ts.map +1 -0
  16. package/dist/channels/console-channel.js +66 -0
  17. package/dist/channels/registry.d.ts +10 -0
  18. package/dist/channels/registry.d.ts.map +1 -0
  19. package/dist/channels/registry.js +25 -0
  20. package/dist/channels/slack-channel.d.ts +35 -0
  21. package/dist/channels/slack-channel.d.ts.map +1 -0
  22. package/dist/channels/slack-channel.js +232 -0
  23. package/dist/channels/telegram-channel.d.ts +32 -0
  24. package/dist/channels/telegram-channel.d.ts.map +1 -0
  25. package/dist/channels/telegram-channel.js +167 -0
  26. package/dist/channels/types.d.ts +31 -0
  27. package/dist/channels/types.d.ts.map +1 -0
  28. package/dist/channels/types.js +4 -0
  29. package/dist/cli/bootstrap.d.ts +39 -0
  30. package/dist/cli/bootstrap.d.ts.map +1 -0
  31. package/dist/cli/bootstrap.js +138 -0
  32. package/dist/cli/channel-bootstrap.d.ts +23 -0
  33. package/dist/cli/channel-bootstrap.d.ts.map +1 -0
  34. package/dist/cli/channel-bootstrap.js +46 -0
  35. package/dist/cli/daemon-control.d.ts +31 -0
  36. package/dist/cli/daemon-control.d.ts.map +1 -0
  37. package/dist/cli/daemon-control.js +177 -0
  38. package/dist/cli/guidance-panel.d.ts +11 -0
  39. package/dist/cli/guidance-panel.d.ts.map +1 -0
  40. package/dist/cli/guidance-panel.js +16 -0
  41. package/dist/cli/mcp-control.d.ts +7 -0
  42. package/dist/cli/mcp-control.d.ts.map +1 -0
  43. package/dist/cli/mcp-control.js +119 -0
  44. package/dist/cli/mission-views.d.ts +13 -0
  45. package/dist/cli/mission-views.d.ts.map +1 -0
  46. package/dist/cli/mission-views.js +82 -0
  47. package/dist/cli/setup.d.ts +9 -0
  48. package/dist/cli/setup.d.ts.map +1 -0
  49. package/dist/cli/setup.js +140 -0
  50. package/dist/cli/startup-contract.d.ts +23 -0
  51. package/dist/cli/startup-contract.d.ts.map +1 -0
  52. package/dist/cli/startup-contract.js +694 -0
  53. package/dist/commands/agents.d.ts +3 -0
  54. package/dist/commands/agents.d.ts.map +1 -0
  55. package/dist/commands/agents.js +44 -0
  56. package/dist/commands/checkpoint.d.ts +3 -0
  57. package/dist/commands/checkpoint.d.ts.map +1 -0
  58. package/dist/commands/checkpoint.js +52 -0
  59. package/dist/commands/claude-style.d.ts +12 -0
  60. package/dist/commands/claude-style.d.ts.map +1 -0
  61. package/dist/commands/claude-style.js +560 -0
  62. package/dist/commands/clear.d.ts +3 -0
  63. package/dist/commands/clear.d.ts.map +1 -0
  64. package/dist/commands/clear.js +20 -0
  65. package/dist/commands/compact.d.ts +3 -0
  66. package/dist/commands/compact.d.ts.map +1 -0
  67. package/dist/commands/compact.js +23 -0
  68. package/dist/commands/config.d.ts +3 -0
  69. package/dist/commands/config.d.ts.map +1 -0
  70. package/dist/commands/config.js +22 -0
  71. package/dist/commands/connect.d.ts +3 -0
  72. package/dist/commands/connect.d.ts.map +1 -0
  73. package/dist/commands/connect.js +102 -0
  74. package/dist/commands/context.d.ts +3 -0
  75. package/dist/commands/context.d.ts.map +1 -0
  76. package/dist/commands/context.js +13 -0
  77. package/dist/commands/dashboard.d.ts +3 -0
  78. package/dist/commands/dashboard.d.ts.map +1 -0
  79. package/dist/commands/dashboard.js +22 -0
  80. package/dist/commands/detach.d.ts +3 -0
  81. package/dist/commands/detach.d.ts.map +1 -0
  82. package/dist/commands/detach.js +44 -0
  83. package/dist/commands/distill.d.ts +3 -0
  84. package/dist/commands/distill.d.ts.map +1 -0
  85. package/dist/commands/distill.js +23 -0
  86. package/dist/commands/doctor.d.ts +3 -0
  87. package/dist/commands/doctor.d.ts.map +1 -0
  88. package/dist/commands/doctor.js +13 -0
  89. package/dist/commands/dream.d.ts +3 -0
  90. package/dist/commands/dream.d.ts.map +1 -0
  91. package/dist/commands/dream.js +59 -0
  92. package/dist/commands/export.d.ts +3 -0
  93. package/dist/commands/export.d.ts.map +1 -0
  94. package/dist/commands/export.js +18 -0
  95. package/dist/commands/exports.d.ts +3 -0
  96. package/dist/commands/exports.d.ts.map +1 -0
  97. package/dist/commands/exports.js +15 -0
  98. package/dist/commands/goal.d.ts +3 -0
  99. package/dist/commands/goal.d.ts.map +1 -0
  100. package/dist/commands/goal.js +147 -0
  101. package/dist/commands/help.d.ts +4 -0
  102. package/dist/commands/help.d.ts.map +1 -0
  103. package/dist/commands/help.js +75 -0
  104. package/dist/commands/hooks.d.ts +3 -0
  105. package/dist/commands/hooks.d.ts.map +1 -0
  106. package/dist/commands/hooks.js +14 -0
  107. package/dist/commands/index.d.ts +29 -0
  108. package/dist/commands/index.d.ts.map +1 -0
  109. package/dist/commands/index.js +417 -0
  110. package/dist/commands/knowledge.d.ts +8 -0
  111. package/dist/commands/knowledge.d.ts.map +1 -0
  112. package/dist/commands/knowledge.js +191 -0
  113. package/dist/commands/loop.d.ts +3 -0
  114. package/dist/commands/loop.d.ts.map +1 -0
  115. package/dist/commands/loop.js +138 -0
  116. package/dist/commands/mcp.d.ts +3 -0
  117. package/dist/commands/mcp.d.ts.map +1 -0
  118. package/dist/commands/mcp.js +57 -0
  119. package/dist/commands/memory.d.ts +3 -0
  120. package/dist/commands/memory.d.ts.map +1 -0
  121. package/dist/commands/memory.js +215 -0
  122. package/dist/commands/mission.d.ts +3 -0
  123. package/dist/commands/mission.d.ts.map +1 -0
  124. package/dist/commands/mission.js +129 -0
  125. package/dist/commands/permissions.d.ts +3 -0
  126. package/dist/commands/permissions.d.ts.map +1 -0
  127. package/dist/commands/permissions.js +82 -0
  128. package/dist/commands/privacy.d.ts +3 -0
  129. package/dist/commands/privacy.d.ts.map +1 -0
  130. package/dist/commands/privacy.js +13 -0
  131. package/dist/commands/recap.d.ts +3 -0
  132. package/dist/commands/recap.d.ts.map +1 -0
  133. package/dist/commands/recap.js +11 -0
  134. package/dist/commands/repomap.d.ts +3 -0
  135. package/dist/commands/repomap.d.ts.map +1 -0
  136. package/dist/commands/repomap.js +146 -0
  137. package/dist/commands/resume.d.ts +3 -0
  138. package/dist/commands/resume.d.ts.map +1 -0
  139. package/dist/commands/resume.js +42 -0
  140. package/dist/commands/runtime.d.ts +61 -0
  141. package/dist/commands/runtime.d.ts.map +1 -0
  142. package/dist/commands/runtime.js +20 -0
  143. package/dist/commands/sessions.d.ts +3 -0
  144. package/dist/commands/sessions.d.ts.map +1 -0
  145. package/dist/commands/sessions.js +34 -0
  146. package/dist/commands/shortcuts.d.ts +3 -0
  147. package/dist/commands/shortcuts.d.ts.map +1 -0
  148. package/dist/commands/shortcuts.js +12 -0
  149. package/dist/commands/skill.d.ts +3 -0
  150. package/dist/commands/skill.d.ts.map +1 -0
  151. package/dist/commands/skill.js +20 -0
  152. package/dist/commands/status.d.ts +3 -0
  153. package/dist/commands/status.d.ts.map +1 -0
  154. package/dist/commands/status.js +31 -0
  155. package/dist/commands/statusline.d.ts +3 -0
  156. package/dist/commands/statusline.d.ts.map +1 -0
  157. package/dist/commands/statusline.js +40 -0
  158. package/dist/commands/storage.d.ts +3 -0
  159. package/dist/commands/storage.d.ts.map +1 -0
  160. package/dist/commands/storage.js +122 -0
  161. package/dist/commands/tasks.d.ts +3 -0
  162. package/dist/commands/tasks.d.ts.map +1 -0
  163. package/dist/commands/tasks.js +117 -0
  164. package/dist/commands/types.d.ts +14 -0
  165. package/dist/commands/types.d.ts.map +1 -0
  166. package/dist/commands/types.js +1 -0
  167. package/dist/commands/verify.d.ts +3 -0
  168. package/dist/commands/verify.d.ts.map +1 -0
  169. package/dist/commands/verify.js +86 -0
  170. package/dist/config-report.d.ts +35 -0
  171. package/dist/config-report.d.ts.map +1 -0
  172. package/dist/config-report.js +100 -0
  173. package/dist/config.d.ts +217 -0
  174. package/dist/config.d.ts.map +1 -0
  175. package/dist/config.js +690 -0
  176. package/dist/context-compactor.d.ts +27 -0
  177. package/dist/context-compactor.d.ts.map +1 -0
  178. package/dist/context-compactor.js +489 -0
  179. package/dist/context-report.d.ts +35 -0
  180. package/dist/context-report.d.ts.map +1 -0
  181. package/dist/context-report.js +172 -0
  182. package/dist/daemon.d.ts +2 -0
  183. package/dist/daemon.d.ts.map +1 -0
  184. package/dist/daemon.js +316 -0
  185. package/dist/dashboard-server.d.ts +18 -0
  186. package/dist/dashboard-server.d.ts.map +1 -0
  187. package/dist/dashboard-server.js +325 -0
  188. package/dist/discovery-registry.d.ts +28 -0
  189. package/dist/discovery-registry.d.ts.map +1 -0
  190. package/dist/discovery-registry.js +106 -0
  191. package/dist/discovery-types.d.ts +54 -0
  192. package/dist/discovery-types.d.ts.map +1 -0
  193. package/dist/discovery-types.js +5 -0
  194. package/dist/doctor.d.ts +31 -0
  195. package/dist/doctor.d.ts.map +1 -0
  196. package/dist/doctor.js +343 -0
  197. package/dist/eval/runner.d.ts +10 -0
  198. package/dist/eval/runner.d.ts.map +1 -0
  199. package/dist/eval/runner.js +78 -0
  200. package/dist/eval/tasks.d.ts +3 -0
  201. package/dist/eval/tasks.d.ts.map +1 -0
  202. package/dist/eval/tasks.js +179 -0
  203. package/dist/eval/types.d.ts +31 -0
  204. package/dist/eval/types.d.ts.map +1 -0
  205. package/dist/eval/types.js +4 -0
  206. package/dist/git/auto-commit.d.ts +28 -0
  207. package/dist/git/auto-commit.d.ts.map +1 -0
  208. package/dist/git/auto-commit.js +112 -0
  209. package/dist/guard/approval.d.ts +16 -0
  210. package/dist/guard/approval.d.ts.map +1 -0
  211. package/dist/guard/approval.js +68 -0
  212. package/dist/guard/content-filter.d.ts +15 -0
  213. package/dist/guard/content-filter.d.ts.map +1 -0
  214. package/dist/guard/content-filter.js +102 -0
  215. package/dist/guard/permissions.d.ts +17 -0
  216. package/dist/guard/permissions.d.ts.map +1 -0
  217. package/dist/guard/permissions.js +54 -0
  218. package/dist/guard/rate-limit.d.ts +14 -0
  219. package/dist/guard/rate-limit.d.ts.map +1 -0
  220. package/dist/guard/rate-limit.js +47 -0
  221. package/dist/guard.d.ts +21 -0
  222. package/dist/guard.d.ts.map +1 -0
  223. package/dist/guard.js +144 -0
  224. package/dist/help-topics.d.ts +19 -0
  225. package/dist/help-topics.d.ts.map +1 -0
  226. package/dist/help-topics.js +391 -0
  227. package/dist/hooks-report.d.ts +23 -0
  228. package/dist/hooks-report.d.ts.map +1 -0
  229. package/dist/hooks-report.js +44 -0
  230. package/dist/i18n/index.d.ts +5 -0
  231. package/dist/i18n/index.d.ts.map +1 -0
  232. package/dist/i18n/index.js +4 -0
  233. package/dist/i18n/zh-cn.d.ts +180 -0
  234. package/dist/i18n/zh-cn.d.ts.map +1 -0
  235. package/dist/i18n/zh-cn.js +184 -0
  236. package/dist/index.d.ts +3 -0
  237. package/dist/index.d.ts.map +1 -0
  238. package/dist/index.js +1157 -0
  239. package/dist/knowledge-agent.d.ts +47 -0
  240. package/dist/knowledge-agent.d.ts.map +1 -0
  241. package/dist/knowledge-agent.js +320 -0
  242. package/dist/local-status-report.d.ts +23 -0
  243. package/dist/local-status-report.d.ts.map +1 -0
  244. package/dist/local-status-report.js +63 -0
  245. package/dist/local-storage-report.d.ts +32 -0
  246. package/dist/local-storage-report.d.ts.map +1 -0
  247. package/dist/local-storage-report.js +171 -0
  248. package/dist/mcp/bridge.d.ts +11 -0
  249. package/dist/mcp/bridge.d.ts.map +1 -0
  250. package/dist/mcp/bridge.js +37 -0
  251. package/dist/mcp/client.d.ts +26 -0
  252. package/dist/mcp/client.d.ts.map +1 -0
  253. package/dist/mcp/client.js +209 -0
  254. package/dist/mcp/http-transport.d.ts +21 -0
  255. package/dist/mcp/http-transport.d.ts.map +1 -0
  256. package/dist/mcp/http-transport.js +126 -0
  257. package/dist/mcp/presets.d.ts +22 -0
  258. package/dist/mcp/presets.d.ts.map +1 -0
  259. package/dist/mcp/presets.js +80 -0
  260. package/dist/mcp/registry.d.ts +23 -0
  261. package/dist/mcp/registry.d.ts.map +1 -0
  262. package/dist/mcp/registry.js +85 -0
  263. package/dist/mcp/stdio-transport.d.ts +25 -0
  264. package/dist/mcp/stdio-transport.d.ts.map +1 -0
  265. package/dist/mcp/stdio-transport.js +92 -0
  266. package/dist/mcp/store.d.ts +41 -0
  267. package/dist/mcp/store.d.ts.map +1 -0
  268. package/dist/mcp/store.js +100 -0
  269. package/dist/mcp/types.d.ts +40 -0
  270. package/dist/mcp/types.d.ts.map +1 -0
  271. package/dist/mcp/types.js +4 -0
  272. package/dist/mcp-report.d.ts +30 -0
  273. package/dist/mcp-report.d.ts.map +1 -0
  274. package/dist/mcp-report.js +104 -0
  275. package/dist/memory/cognitive-index.d.ts +56 -0
  276. package/dist/memory/cognitive-index.d.ts.map +1 -0
  277. package/dist/memory/cognitive-index.js +265 -0
  278. package/dist/memory/compactor.d.ts +28 -0
  279. package/dist/memory/compactor.d.ts.map +1 -0
  280. package/dist/memory/compactor.js +92 -0
  281. package/dist/memory/consolidation.d.ts +13 -0
  282. package/dist/memory/consolidation.d.ts.map +1 -0
  283. package/dist/memory/consolidation.js +77 -0
  284. package/dist/memory/embedding.d.ts +15 -0
  285. package/dist/memory/embedding.d.ts.map +1 -0
  286. package/dist/memory/embedding.js +59 -0
  287. package/dist/memory/memory-llm-dream.d.ts +3 -0
  288. package/dist/memory/memory-llm-dream.d.ts.map +1 -0
  289. package/dist/memory/memory-llm-dream.js +59 -0
  290. package/dist/memory/projection-worker.d.ts +30 -0
  291. package/dist/memory/projection-worker.d.ts.map +1 -0
  292. package/dist/memory/projection-worker.js +92 -0
  293. package/dist/memory/semantic-index.d.ts +18 -0
  294. package/dist/memory/semantic-index.d.ts.map +1 -0
  295. package/dist/memory/semantic-index.js +86 -0
  296. package/dist/memory/wal.d.ts +33 -0
  297. package/dist/memory/wal.d.ts.map +1 -0
  298. package/dist/memory/wal.js +131 -0
  299. package/dist/memory-report.d.ts +120 -0
  300. package/dist/memory-report.d.ts.map +1 -0
  301. package/dist/memory-report.js +726 -0
  302. package/dist/memory.d.ts +149 -0
  303. package/dist/memory.d.ts.map +1 -0
  304. package/dist/memory.js +632 -0
  305. package/dist/metrics/agent-telemetry.d.ts +14 -0
  306. package/dist/metrics/agent-telemetry.d.ts.map +1 -0
  307. package/dist/metrics/agent-telemetry.js +44 -0
  308. package/dist/metrics/collector.d.ts +17 -0
  309. package/dist/metrics/collector.d.ts.map +1 -0
  310. package/dist/metrics/collector.js +137 -0
  311. package/dist/metrics/types.d.ts +14 -0
  312. package/dist/metrics/types.d.ts.map +1 -0
  313. package/dist/metrics/types.js +4 -0
  314. package/dist/mission/manager.d.ts +28 -0
  315. package/dist/mission/manager.d.ts.map +1 -0
  316. package/dist/mission/manager.js +208 -0
  317. package/dist/mission/types.d.ts +37 -0
  318. package/dist/mission/types.d.ts.map +1 -0
  319. package/dist/mission/types.js +5 -0
  320. package/dist/onboarding/tutorial.d.ts +33 -0
  321. package/dist/onboarding/tutorial.d.ts.map +1 -0
  322. package/dist/onboarding/tutorial.js +96 -0
  323. package/dist/output-style.d.ts +14 -0
  324. package/dist/output-style.d.ts.map +1 -0
  325. package/dist/output-style.js +29 -0
  326. package/dist/package-version.d.ts +12 -0
  327. package/dist/package-version.d.ts.map +1 -0
  328. package/dist/package-version.js +42 -0
  329. package/dist/permissions-report.d.ts +42 -0
  330. package/dist/permissions-report.d.ts.map +1 -0
  331. package/dist/permissions-report.js +120 -0
  332. package/dist/pipeline/consistency-checker.d.ts +8 -0
  333. package/dist/pipeline/consistency-checker.d.ts.map +1 -0
  334. package/dist/pipeline/consistency-checker.js +40 -0
  335. package/dist/pipeline/example-generator.d.ts +4 -0
  336. package/dist/pipeline/example-generator.d.ts.map +1 -0
  337. package/dist/pipeline/example-generator.js +64 -0
  338. package/dist/pipeline/hooks.d.ts +68 -0
  339. package/dist/pipeline/hooks.d.ts.map +1 -0
  340. package/dist/pipeline/hooks.js +377 -0
  341. package/dist/pipeline/sections.d.ts +41 -0
  342. package/dist/pipeline/sections.d.ts.map +1 -0
  343. package/dist/pipeline/sections.js +244 -0
  344. package/dist/pipeline/verification.d.ts +12 -0
  345. package/dist/pipeline/verification.d.ts.map +1 -0
  346. package/dist/pipeline/verification.js +138 -0
  347. package/dist/privacy-report.d.ts +24 -0
  348. package/dist/privacy-report.d.ts.map +1 -0
  349. package/dist/privacy-report.js +78 -0
  350. package/dist/providers/presets.d.ts +25 -0
  351. package/dist/providers/presets.d.ts.map +1 -0
  352. package/dist/providers/presets.js +205 -0
  353. package/dist/recap.d.ts +38 -0
  354. package/dist/recap.d.ts.map +1 -0
  355. package/dist/recap.js +154 -0
  356. package/dist/repl.d.ts +41 -0
  357. package/dist/repl.d.ts.map +1 -0
  358. package/dist/repl.js +396 -0
  359. package/dist/runtime-paths.d.ts +32 -0
  360. package/dist/runtime-paths.d.ts.map +1 -0
  361. package/dist/runtime-paths.js +134 -0
  362. package/dist/sdk.d.ts +12 -0
  363. package/dist/sdk.d.ts.map +1 -0
  364. package/dist/sdk.js +18 -0
  365. package/dist/session/daemon-session-api.d.ts +22 -0
  366. package/dist/session/daemon-session-api.d.ts.map +1 -0
  367. package/dist/session/daemon-session-api.js +48 -0
  368. package/dist/session/durable-session-supervisor.d.ts +24 -0
  369. package/dist/session/durable-session-supervisor.d.ts.map +1 -0
  370. package/dist/session/durable-session-supervisor.js +195 -0
  371. package/dist/session/goal-controller.d.ts +43 -0
  372. package/dist/session/goal-controller.d.ts.map +1 -0
  373. package/dist/session/goal-controller.js +77 -0
  374. package/dist/session/goal-evaluator.d.ts +29 -0
  375. package/dist/session/goal-evaluator.d.ts.map +1 -0
  376. package/dist/session/goal-evaluator.js +100 -0
  377. package/dist/session/loop-prompt.d.ts +14 -0
  378. package/dist/session/loop-prompt.d.ts.map +1 -0
  379. package/dist/session/loop-prompt.js +49 -0
  380. package/dist/session/session-goal-manager.d.ts +51 -0
  381. package/dist/session/session-goal-manager.d.ts.map +1 -0
  382. package/dist/session/session-goal-manager.js +118 -0
  383. package/dist/session/session-registry.d.ts +40 -0
  384. package/dist/session/session-registry.d.ts.map +1 -0
  385. package/dist/session/session-registry.js +124 -0
  386. package/dist/session/session-scheduler.d.ts +59 -0
  387. package/dist/session/session-scheduler.d.ts.map +1 -0
  388. package/dist/session/session-scheduler.js +170 -0
  389. package/dist/session-checkpoint-report.d.ts +22 -0
  390. package/dist/session-checkpoint-report.d.ts.map +1 -0
  391. package/dist/session-checkpoint-report.js +99 -0
  392. package/dist/session-export-index.d.ts +23 -0
  393. package/dist/session-export-index.d.ts.map +1 -0
  394. package/dist/session-export-index.js +96 -0
  395. package/dist/session-export.d.ts +28 -0
  396. package/dist/session-export.d.ts.map +1 -0
  397. package/dist/session-export.js +99 -0
  398. package/dist/session-goal-report.d.ts +37 -0
  399. package/dist/session-goal-report.d.ts.map +1 -0
  400. package/dist/session-goal-report.js +219 -0
  401. package/dist/session-list-report.d.ts +16 -0
  402. package/dist/session-list-report.d.ts.map +1 -0
  403. package/dist/session-list-report.js +60 -0
  404. package/dist/session-task-report.d.ts +23 -0
  405. package/dist/session-task-report.d.ts.map +1 -0
  406. package/dist/session-task-report.js +183 -0
  407. package/dist/shortcuts.d.ts +2 -0
  408. package/dist/shortcuts.d.ts.map +1 -0
  409. package/dist/shortcuts.js +32 -0
  410. package/dist/skills/registry.d.ts +8 -0
  411. package/dist/skills/registry.d.ts.map +1 -0
  412. package/dist/skills/registry.js +119 -0
  413. package/dist/skills/types.d.ts +7 -0
  414. package/dist/skills/types.d.ts.map +1 -0
  415. package/dist/skills/types.js +4 -0
  416. package/dist/statusline.d.ts +37 -0
  417. package/dist/statusline.d.ts.map +1 -0
  418. package/dist/statusline.js +207 -0
  419. package/dist/tools/bash.d.ts +10 -0
  420. package/dist/tools/bash.d.ts.map +1 -0
  421. package/dist/tools/bash.js +278 -0
  422. package/dist/tools/browser-fetch.d.ts +7 -0
  423. package/dist/tools/browser-fetch.d.ts.map +1 -0
  424. package/dist/tools/browser-fetch.js +133 -0
  425. package/dist/tools/error-utils.d.ts +9 -0
  426. package/dist/tools/error-utils.d.ts.map +1 -0
  427. package/dist/tools/error-utils.js +35 -0
  428. package/dist/tools/index.d.ts +27 -0
  429. package/dist/tools/index.d.ts.map +1 -0
  430. package/dist/tools/index.js +86 -0
  431. package/dist/tools/patch.d.ts +22 -0
  432. package/dist/tools/patch.d.ts.map +1 -0
  433. package/dist/tools/patch.js +458 -0
  434. package/dist/tools/planner.d.ts +7 -0
  435. package/dist/tools/planner.d.ts.map +1 -0
  436. package/dist/tools/planner.js +148 -0
  437. package/dist/tools/read.d.ts +8 -0
  438. package/dist/tools/read.d.ts.map +1 -0
  439. package/dist/tools/read.js +114 -0
  440. package/dist/tools/search.d.ts +11 -0
  441. package/dist/tools/search.d.ts.map +1 -0
  442. package/dist/tools/search.js +636 -0
  443. package/dist/tools/skill.d.ts +8 -0
  444. package/dist/tools/skill.d.ts.map +1 -0
  445. package/dist/tools/skill.js +181 -0
  446. package/dist/tools/subtask.d.ts +9 -0
  447. package/dist/tools/subtask.d.ts.map +1 -0
  448. package/dist/tools/subtask.js +120 -0
  449. package/dist/tools/todo.d.ts +8 -0
  450. package/dist/tools/todo.d.ts.map +1 -0
  451. package/dist/tools/todo.js +170 -0
  452. package/dist/tools/url-fetch.d.ts +11 -0
  453. package/dist/tools/url-fetch.d.ts.map +1 -0
  454. package/dist/tools/url-fetch.js +208 -0
  455. package/dist/tools/vision-analyze.d.ts +9 -0
  456. package/dist/tools/vision-analyze.d.ts.map +1 -0
  457. package/dist/tools/vision-analyze.js +179 -0
  458. package/dist/tools/write.d.ts +7 -0
  459. package/dist/tools/write.d.ts.map +1 -0
  460. package/dist/tools/write.js +128 -0
  461. package/dist/tui/chrome.d.ts +7 -0
  462. package/dist/tui/chrome.d.ts.map +1 -0
  463. package/dist/tui/chrome.js +22 -0
  464. package/dist/tui/input-buffer.d.ts +37 -0
  465. package/dist/tui/input-buffer.d.ts.map +1 -0
  466. package/dist/tui/input-buffer.js +228 -0
  467. package/dist/tui/input-history.d.ts +11 -0
  468. package/dist/tui/input-history.d.ts.map +1 -0
  469. package/dist/tui/input-history.js +69 -0
  470. package/dist/tui/input-queue.d.ts +27 -0
  471. package/dist/tui/input-queue.d.ts.map +1 -0
  472. package/dist/tui/input-queue.js +85 -0
  473. package/dist/tui/markdown.d.ts +10 -0
  474. package/dist/tui/markdown.d.ts.map +1 -0
  475. package/dist/tui/markdown.js +396 -0
  476. package/dist/tui/progress.d.ts +3 -0
  477. package/dist/tui/progress.d.ts.map +1 -0
  478. package/dist/tui/progress.js +13 -0
  479. package/dist/tui/shell.d.ts +67 -0
  480. package/dist/tui/shell.d.ts.map +1 -0
  481. package/dist/tui/shell.js +271 -0
  482. package/dist/tui/streaming-repl.d.ts +39 -0
  483. package/dist/tui/streaming-repl.d.ts.map +1 -0
  484. package/dist/tui/streaming-repl.js +460 -0
  485. package/dist/tui/streaming-tui.d.ts +174 -0
  486. package/dist/tui/streaming-tui.d.ts.map +1 -0
  487. package/dist/tui/streaming-tui.js +1049 -0
  488. package/dist/types.d.ts +221 -0
  489. package/dist/types.d.ts.map +1 -0
  490. package/dist/types.js +37 -0
  491. package/dist/utils/symbol-extractor.d.ts +8 -0
  492. package/dist/utils/symbol-extractor.d.ts.map +1 -0
  493. package/dist/utils/symbol-extractor.js +190 -0
  494. package/dist/workflow-runtime.d.ts +45 -0
  495. package/dist/workflow-runtime.d.ts.map +1 -0
  496. package/dist/workflow-runtime.js +146 -0
  497. package/dist/workflow-types.d.ts +73 -0
  498. package/dist/workflow-types.d.ts.map +1 -0
  499. package/dist/workflow-types.js +34 -0
  500. package/docs/docker.md +66 -0
  501. package/docs/install.md +159 -0
  502. package/docs/sdk.md +67 -0
  503. package/docs/skills.md +51 -0
  504. package/package.json +102 -0
  505. package/scripts/bootstrap.mjs +63 -0
  506. package/scripts/check_image.ps1 +18 -0
  507. package/scripts/clean-dist.mjs +18 -0
  508. package/scripts/copy_image.ps1 +5 -0
  509. package/scripts/eval-smoke.mjs +17 -0
  510. package/skills/examples/repo-triage/SKILL.md +50 -0
  511. package/skills/qling.md +42 -0
  512. package/skills/templates/SKILL.md +37 -0
package/dist/memory.js ADDED
@@ -0,0 +1,632 @@
1
+ // ============================================================
2
+ // 轻灵 - Memory 系统 v3(WAL + 投影 Worker + LLM Dream)
3
+ // 三层架构:Scratchpad(会话)→ Conversation(对话)→ Persisted(持久化)
4
+ // ============================================================
5
+ import * as fs from "fs/promises";
6
+ import * as path from "path";
7
+ import { ProjectionWorker } from "./memory/projection-worker.js";
8
+ import { MemoryCompactor } from "./memory/compactor.js";
9
+ import * as crypto from "crypto";
10
+ const DEFAULT_CONFIG = {
11
+ enabled: true,
12
+ turnThreshold: 24,
13
+ transcriptWindow: 4,
14
+ semanticEnabled: false,
15
+ };
16
+ // --- PersistedMemory(长期存储,WAL 模式可选)---
17
+ export class PersistedMemory {
18
+ entries = [];
19
+ memoryDir;
20
+ wal = null;
21
+ projectionWorker = null;
22
+ // v0.5 认知引擎
23
+ cognitiveIndex = null;
24
+ embeddingClient = null;
25
+ constructor(memoryDir) {
26
+ this.memoryDir = memoryDir;
27
+ }
28
+ setWAL(wal, options = {}) {
29
+ this.wal = wal;
30
+ this.projectionWorker = new ProjectionWorker(wal, {
31
+ applyEntry: (entry) => this.applyWALEntry(entry),
32
+ getEntries: () => this.entries,
33
+ onCheckpoint: async (entries) => this.syncCognitiveIndex(entries),
34
+ }, {
35
+ intervalMs: options.intervalMs,
36
+ maxPendingEntries: options.maxPendingEntries,
37
+ });
38
+ }
39
+ setCognitiveIndex(index, client) {
40
+ this.cognitiveIndex = index;
41
+ this.embeddingClient = client;
42
+ }
43
+ async init() {
44
+ await fs.mkdir(this.memoryDir, { recursive: true });
45
+ await this.loadFromDisk();
46
+ if (this.cognitiveIndex) {
47
+ await this.cognitiveIndex.init();
48
+ }
49
+ }
50
+ add(content, source, importance = 0.5) {
51
+ const entry = {
52
+ id: "mem_" + Date.now() + "_" + Math.random().toString(36).slice(2, 7),
53
+ content,
54
+ source,
55
+ createdAt: Date.now(),
56
+ importance,
57
+ };
58
+ this.entries.push(entry);
59
+ this.entries.sort((a, b) => b.importance - a.importance);
60
+ }
61
+ remove(id) {
62
+ const idx = this.entries.findIndex((e) => e.id === id);
63
+ if (idx === -1)
64
+ return false;
65
+ this.entries.splice(idx, 1);
66
+ return true;
67
+ }
68
+ update(id, updates) {
69
+ const entry = this.entries.find((e) => e.id === id);
70
+ if (!entry)
71
+ return false;
72
+ if (updates.content !== undefined)
73
+ entry.content = updates.content;
74
+ if (updates.importance !== undefined)
75
+ entry.importance = updates.importance;
76
+ this.entries.sort((a, b) => b.importance - a.importance);
77
+ return true;
78
+ }
79
+ applyWALEntry(entry) {
80
+ switch (entry.op) {
81
+ case "add": {
82
+ const data = entry.data;
83
+ if (!this.entries.some((e) => e.id === data.id)) {
84
+ this.entries.push(data);
85
+ this.entries.sort((a, b) => b.importance - a.importance);
86
+ }
87
+ break;
88
+ }
89
+ case "remove": {
90
+ const data = entry.data;
91
+ this.entries = this.entries.filter((e) => e.id !== data.id);
92
+ break;
93
+ }
94
+ case "update": {
95
+ const data = entry.data;
96
+ const existing = this.entries.find((e) => e.id === data.id);
97
+ if (existing) {
98
+ if (data.content !== undefined)
99
+ existing.content = data.content;
100
+ if (data.importance !== undefined)
101
+ existing.importance = data.importance;
102
+ }
103
+ break;
104
+ }
105
+ case "compact": {
106
+ const data = entry.data;
107
+ this.entries = data;
108
+ break;
109
+ }
110
+ }
111
+ }
112
+ async getRelevant(query, limit = 5) {
113
+ const now = Date.now();
114
+ // 1. 关键词检索
115
+ const keywordResults = this.entries.map((e) => {
116
+ let score = e.importance;
117
+ const ageHours = (now - e.createdAt) / (1000 * 60 * 60);
118
+ score *= Math.pow(0.9, ageHours / 24);
119
+ const keywords = query.toLowerCase().split(/\s+/);
120
+ const content = e.content.toLowerCase();
121
+ const matches = keywords.filter((k) => content.includes(k)).length;
122
+ score += matches * 0.1;
123
+ return { entry: e, score, source: "keyword" };
124
+ });
125
+ // 2. 向量检索 (v0.3+)
126
+ let semanticResults = [];
127
+ if (this.cognitiveIndex && this.embeddingClient && query.trim()) {
128
+ try {
129
+ const queryVector = await this.embeddingClient.getEmbedding(query);
130
+ const searchHits = this.cognitiveIndex.searchVector(queryVector, limit * 2);
131
+ semanticResults = searchHits.map(h => ({
132
+ entry: h.entry,
133
+ score: h.score * 0.8,
134
+ source: "vector"
135
+ }));
136
+ }
137
+ catch (err) {
138
+ // 专项修复:处理 404 (Endpoint 不支持)
139
+ if (err.message.includes("404")) {
140
+ if (!this._warned404) {
141
+ console.warn(`[Memory] ⚠️ 当前提供商不支持 Embedding 接口 (404),已降级为纯关键词检索模式。`);
142
+ this._warned404 = true;
143
+ }
144
+ }
145
+ else {
146
+ console.error(`[PersistedMemory] Vector search failed: ${err.message}`);
147
+ }
148
+ }
149
+ }
150
+ // 3. 经验检索 (v0.5 M1)
151
+ const practices = this.cognitiveIndex?.getRelatedPractices(query) || [];
152
+ const practiceResults = practices.map(p => ({
153
+ id: p.id,
154
+ content: `[最佳实践] 任务模式: ${p.task_pattern} | 成功路径: ${JSON.parse(p.action_json).join(" -> ")}`,
155
+ source: "practice",
156
+ importance: p.confidence,
157
+ createdAt: p.created_at
158
+ }));
159
+ // 4. 混合排序 (Hybrid Rerank)
160
+ const merged = new Map();
161
+ keywordResults.forEach(r => merged.set(r.entry.id, r));
162
+ semanticResults.forEach(r => {
163
+ const existing = merged.get(r.entry.id);
164
+ if (existing)
165
+ existing.score += r.score;
166
+ else
167
+ merged.set(r.entry.id, r);
168
+ });
169
+ practiceResults.forEach(p => {
170
+ merged.set(p.id, { entry: p, score: 2.0 });
171
+ });
172
+ return Array.from(merged.values())
173
+ .sort((a, b) => b.score - a.score)
174
+ .slice(0, limit)
175
+ .map((s) => s.entry);
176
+ }
177
+ async syncCognitiveIndex(entries) {
178
+ if (!this.cognitiveIndex || !this.embeddingClient)
179
+ return;
180
+ const batchSize = 10;
181
+ const entriesToIndex = entries.slice(-batchSize);
182
+ try {
183
+ const vectors = await this.embeddingClient.getEmbeddings(entriesToIndex.map(e => e.content));
184
+ for (let i = 0; i < entriesToIndex.length; i++) {
185
+ this.cognitiveIndex.upsertVector(entriesToIndex[i], vectors[i]);
186
+ }
187
+ }
188
+ catch (err) {
189
+ const msg = err.message || String(err);
190
+ if (msg.includes("404")) {
191
+ if (!this._semanticWarned404) {
192
+ console.warn(`[Memory] ⚠️ 当前提供商不支持 Embedding 接口 (404),已禁用语义索引(降级为关键词+实践检索)。请为语义记忆配置支持 embeddings 的 provider(如 OpenAI)或设置 QLING_MEMORY_SEMANTIC_ENDPOINT / _MODEL。`);
193
+ this._semanticWarned404 = true;
194
+ // 禁用后续索引
195
+ this.embeddingClient = null;
196
+ }
197
+ }
198
+ else {
199
+ console.error(`[PersistedMemory] Async cognitive indexing failed: ${msg}`);
200
+ }
201
+ }
202
+ }
203
+ /** 建立知识关联 */
204
+ link(source, relation, target) {
205
+ this.cognitiveIndex?.link(source, relation, target);
206
+ }
207
+ linkSessionToEntities(sessionId, summary, files, tasks) {
208
+ this.cognitiveIndex?.linkSessionToEntities(sessionId, summary, files, tasks);
209
+ }
210
+ /** 记录最佳实践 */
211
+ addPractice(pattern, commands, files, confidence = 1.0) {
212
+ this.cognitiveIndex?.addPractice({
213
+ id: "prac_" + Date.now(),
214
+ task_pattern: pattern,
215
+ successful_commands: commands,
216
+ files_involved: files,
217
+ confidence,
218
+ });
219
+ }
220
+ formatForPrompt(limit = 10) {
221
+ if (this.entries.length === 0)
222
+ return "";
223
+ const relevant = this.getRelevantSync("", limit);
224
+ if (relevant.length === 0)
225
+ return "";
226
+ return relevant
227
+ .map((e) => "[" + e.source + "] " + e.content)
228
+ .join("\n");
229
+ }
230
+ getRelevantSync(query, limit = 5) {
231
+ const now = Date.now();
232
+ const scored = this.entries.map((e) => {
233
+ let score = e.importance;
234
+ const ageHours = (now - e.createdAt) / (1000 * 60 * 60);
235
+ score *= Math.pow(0.9, ageHours / 24);
236
+ const keywords = query.toLowerCase().split(/\s+/);
237
+ const content = e.content.toLowerCase();
238
+ const matches = keywords.filter((k) => content.includes(k)).length;
239
+ score += matches * 0.1;
240
+ return { entry: e, score };
241
+ });
242
+ return scored
243
+ .sort((a, b) => b.score - a.score)
244
+ .slice(0, limit)
245
+ .map((s) => s.entry);
246
+ }
247
+ async saveToDisk() {
248
+ if (this.wal) {
249
+ await this.wal.append("compact", this.entries);
250
+ }
251
+ else {
252
+ const file = path.join(this.memoryDir, "memory.json");
253
+ await fs.writeFile(file, JSON.stringify(this.entries, null, 2), "utf-8");
254
+ }
255
+ }
256
+ async loadFromDisk() {
257
+ try {
258
+ const file = path.join(this.memoryDir, "memory.json");
259
+ const data = await fs.readFile(file, "utf-8");
260
+ this.entries = JSON.parse(data);
261
+ }
262
+ catch {
263
+ this.entries = [];
264
+ }
265
+ }
266
+ merge(entries) {
267
+ const existing = new Map(this.entries.map((e) => [e.id, e]));
268
+ for (const entry of entries) {
269
+ existing.set(entry.id, entry);
270
+ }
271
+ this.entries = Array.from(existing.values());
272
+ this.entries.sort((a, b) => b.importance - a.importance);
273
+ }
274
+ getAll() {
275
+ return [...this.entries];
276
+ }
277
+ compact(maxEntries = 1000) {
278
+ const compactor = new MemoryCompactor({ maxEntries });
279
+ const result = compactor.compactWithEntries(this.entries);
280
+ this.entries = result.entries;
281
+ }
282
+ startProjection() {
283
+ this.projectionWorker?.start();
284
+ }
285
+ stopProjection() {
286
+ this.projectionWorker?.stop();
287
+ }
288
+ async forceCheckpoint() {
289
+ await this.projectionWorker?.forceCheckpoint();
290
+ }
291
+ async rebuildSemanticIndex() {
292
+ if (!this.cognitiveIndex || !this.embeddingClient)
293
+ return;
294
+ this.cognitiveIndex.close();
295
+ await this.cognitiveIndex.init();
296
+ const batchSize = 10;
297
+ for (let i = 0; i < this.entries.length; i += batchSize) {
298
+ const batch = this.entries.slice(i, i + batchSize);
299
+ try {
300
+ const vectors = await this.embeddingClient.getEmbeddings(batch.map(e => e.content));
301
+ for (let j = 0; j < batch.length; j++) {
302
+ this.cognitiveIndex.upsertVector(batch[j], vectors[j]);
303
+ }
304
+ }
305
+ catch (err) {
306
+ console.error(`[PersistedMemory] rebuildSemanticIndex batch failed: ${err.message}`);
307
+ break; // stop on failure
308
+ }
309
+ }
310
+ }
311
+ async shutdown() {
312
+ this.stopProjection();
313
+ await this.forceCheckpoint();
314
+ if (this.cognitiveIndex) {
315
+ this.cognitiveIndex.close();
316
+ }
317
+ }
318
+ getCognitiveIndex() {
319
+ return this.cognitiveIndex;
320
+ }
321
+ }
322
+ // --- ScratchpadMemory(会话笔记,临时,Agent 自己写入读取)---
323
+ export class ScratchpadMemory {
324
+ notes = new Map();
325
+ set(key, value) {
326
+ this.notes.set(key, value);
327
+ }
328
+ get(key) {
329
+ return this.notes.get(key);
330
+ }
331
+ has(key) {
332
+ return this.notes.has(key);
333
+ }
334
+ delete(key) {
335
+ this.notes.delete(key);
336
+ }
337
+ entries() {
338
+ return this.notes.entries();
339
+ }
340
+ formatForPrompt() {
341
+ if (this.notes.size === 0)
342
+ return "";
343
+ const lines = Array.from(this.notes.entries()).map(([k, v]) => "- " + k + ": " + v);
344
+ return "[会话笔记]\n" + lines.join("\n");
345
+ }
346
+ clear() {
347
+ this.notes.clear();
348
+ }
349
+ }
350
+ export class ConversationMemory {
351
+ turns = [];
352
+ add(role, content) {
353
+ this.turns.push({ role, content, timestamp: Date.now() });
354
+ }
355
+ getRecent(count = 10) {
356
+ return this.turns.slice(-count);
357
+ }
358
+ getAll() {
359
+ return [...this.turns];
360
+ }
361
+ count() {
362
+ return this.turns.length;
363
+ }
364
+ clear() {
365
+ this.turns = [];
366
+ }
367
+ extractKeyInfo() {
368
+ const recent = this.turns.slice(-8);
369
+ const lines = [];
370
+ for (const t of recent) {
371
+ const paths = t.content.match(/[/\.a-zA-Z0-9_-]+\.(ts|js|py|md|json|yml|yaml|sh)/g);
372
+ if (paths)
373
+ lines.push(...paths);
374
+ const techs = t.content.match(/(?:使用|调用|通过)\s+(\S+)/g);
375
+ if (techs)
376
+ lines.push(...techs);
377
+ }
378
+ return Array.from(new Set(lines));
379
+ }
380
+ }
381
+ // --- Unified MemoryStore(统一入口,组合三层)---
382
+ export class MemoryStore {
383
+ persisted; // Workspace persisted memory (for compatibility)
384
+ globalPersisted;
385
+ scratchpad;
386
+ conversation;
387
+ config;
388
+ workspaceMemoryDir;
389
+ globalMemoryDir;
390
+ constructor(memoryDir, config = {}) {
391
+ this.config = { ...DEFAULT_CONFIG, ...config };
392
+ const workspaceDir = config.workspaceDir || process.cwd();
393
+ const wsHash = crypto.createHash("sha256").update(path.resolve(workspaceDir)).digest("hex").slice(0, 16);
394
+ // If memoryDir ends with "memory", assume it is the runtime root memory directory.
395
+ const parentDir = memoryDir.endsWith("memory") ? memoryDir : path.join(path.dirname(memoryDir), "memory");
396
+ this.globalMemoryDir = path.join(parentDir, "global");
397
+ this.workspaceMemoryDir = path.join(parentDir, "workspace", wsHash);
398
+ this.persisted = new PersistedMemory(this.workspaceMemoryDir);
399
+ this.globalPersisted = new PersistedMemory(this.globalMemoryDir);
400
+ this.scratchpad = new ScratchpadMemory();
401
+ this.conversation = new ConversationMemory();
402
+ }
403
+ async init() {
404
+ await this.globalPersisted.init();
405
+ await this.persisted.init();
406
+ }
407
+ setWAL(wal, options = {}) {
408
+ this.persisted.setWAL(wal, options);
409
+ }
410
+ setCognitiveIndex(index, client) {
411
+ this.persisted.setCognitiveIndex(index, client);
412
+ }
413
+ startProjection() {
414
+ this.persisted.startProjection();
415
+ }
416
+ stopProjection() {
417
+ this.persisted.stopProjection();
418
+ }
419
+ async forceCheckpoint() {
420
+ await this.persisted.forceCheckpoint();
421
+ }
422
+ async shutdown() {
423
+ await this.globalPersisted.shutdown();
424
+ await this.persisted.shutdown();
425
+ }
426
+ async rebuildSemanticIndex() {
427
+ await this.persisted.rebuildSemanticIndex();
428
+ }
429
+ getCognitiveIndex() {
430
+ return this.persisted.getCognitiveIndex();
431
+ }
432
+ // --- Persisted(对外 API)---
433
+ add(content, source, importance = 0.5, scope = "workspace") {
434
+ if (scope === "global") {
435
+ this.globalPersisted.add(content, source, importance);
436
+ }
437
+ else {
438
+ this.persisted.add(content, source, importance);
439
+ }
440
+ }
441
+ remove(id, scope = "workspace") {
442
+ if (scope === "global") {
443
+ return this.globalPersisted.remove(id);
444
+ }
445
+ else {
446
+ return this.persisted.remove(id);
447
+ }
448
+ }
449
+ update(id, updates, scope = "workspace") {
450
+ if (scope === "global") {
451
+ return this.globalPersisted.update(id, updates);
452
+ }
453
+ else {
454
+ return this.persisted.update(id, updates);
455
+ }
456
+ }
457
+ applyOperations(ops, scope = "workspace") {
458
+ for (const op of ops) {
459
+ switch (op.action) {
460
+ case "ADD":
461
+ this.add(op.fact, "dream-consolidation", 0.6, scope);
462
+ break;
463
+ case "UPDATE":
464
+ if (op.targetId) {
465
+ this.update(op.targetId, { content: op.fact }, scope);
466
+ }
467
+ break;
468
+ case "DELETE":
469
+ if (op.targetId) {
470
+ this.remove(op.targetId, scope);
471
+ }
472
+ break;
473
+ }
474
+ }
475
+ }
476
+ async getRelevant(query, limit = 5) {
477
+ const wsHits = await this.persisted.getRelevant(query, limit);
478
+ const globalHits = await this.globalPersisted.getRelevant(query, limit);
479
+ const merged = new Map();
480
+ // Project/workspace memories get a weight multiplier of 1.0
481
+ wsHits.forEach((entry, idx) => {
482
+ const score = (limit - idx) * 1.0;
483
+ merged.set("ws:" + entry.id, { entry, score });
484
+ });
485
+ // Global memories get a weight multiplier of 0.7
486
+ globalHits.forEach((entry, idx) => {
487
+ const score = (limit - idx) * 0.7;
488
+ const key = "global:" + entry.id;
489
+ merged.set(key, { entry, score });
490
+ });
491
+ return Array.from(merged.values())
492
+ .sort((a, b) => b.score - a.score)
493
+ .slice(0, limit)
494
+ .map((s) => s.entry);
495
+ }
496
+ // --- Cognitive Layer (M1) ---
497
+ link(source, relation, target) {
498
+ this.persisted.link(source, relation, target);
499
+ }
500
+ linkSessionToEntities(sessionId, summary, files, tasks) {
501
+ this.persisted.linkSessionToEntities(sessionId, summary, files, tasks);
502
+ }
503
+ addPractice(pattern, commands, files) {
504
+ this.persisted.addPractice(pattern, commands, files);
505
+ }
506
+ // --- Scratchpad(对外 API)---
507
+ setNote(key, value) {
508
+ this.scratchpad.set(key, value);
509
+ }
510
+ getNote(key) {
511
+ return this.scratchpad.get(key);
512
+ }
513
+ deleteNote(key) {
514
+ this.scratchpad.delete(key);
515
+ }
516
+ // --- Conversation(对外 API)---
517
+ addConversationTurn(role, content) {
518
+ this.conversation.add(role, content);
519
+ }
520
+ getConversationCount() {
521
+ return this.conversation.count();
522
+ }
523
+ // --- Scratchpad → Persisted(笔记提升为持久记忆)---
524
+ promoteNoteToMemory(key, importance = 0.6) {
525
+ const value = this.scratchpad.get(key);
526
+ if (!value)
527
+ return false;
528
+ this.persisted.add("[笔记->记忆] " + key + ": " + value, "manual", importance);
529
+ this.scratchpad.delete(key);
530
+ return true;
531
+ }
532
+ // --- 统一接口:格式化提示字符串 ---
533
+ formatPromptForContext(limit = 10) {
534
+ const parts = [];
535
+ const scratchpadStr = this.scratchpad.formatForPrompt();
536
+ if (scratchpadStr)
537
+ parts.push(scratchpadStr);
538
+ const persistedStr = this.persisted.formatForPrompt(limit);
539
+ if (persistedStr)
540
+ parts.push(persistedStr);
541
+ const globalStr = this.globalPersisted.formatForPrompt(limit);
542
+ if (globalStr)
543
+ parts.push("[全局记忆]\n" + globalStr);
544
+ if (parts.length === 0)
545
+ return null;
546
+ return parts.join("\n\n");
547
+ }
548
+ // --- 统一接口:保存到磁盘 ---
549
+ async saveToDisk() {
550
+ await this.globalPersisted.saveToDisk();
551
+ await this.persisted.saveToDisk();
552
+ }
553
+ // --- 会话重置(不清持久化)---
554
+ resetSession() {
555
+ this.scratchpad.clear();
556
+ this.conversation.clear();
557
+ }
558
+ // --- 全量导出(用于压缩合并)---
559
+ exportPersisted() {
560
+ return this.persisted.getAll();
561
+ }
562
+ // --- 全量导入(用于压缩合并后恢复)---
563
+ importPersisted(entries) {
564
+ this.persisted.merge(entries);
565
+ }
566
+ compactPersisted(maxEntries) {
567
+ this.persisted.compact(maxEntries);
568
+ }
569
+ getWorkspaceMemoryDir() {
570
+ return this.workspaceMemoryDir;
571
+ }
572
+ getGlobalMemoryDir() {
573
+ return this.globalMemoryDir;
574
+ }
575
+ }
576
+ export async function extractDreamMemories(ctx, config) {
577
+ if (ctx.turnCount < config.turnThreshold)
578
+ return [];
579
+ const recent = ctx.transcript.slice(-(config.transcriptWindow ?? 4));
580
+ const combined = recent.join("\n---\n");
581
+ const patterns = [
582
+ /(?:记住|记得|重要|不要忘记)[::]\s*(.+)/gi,
583
+ /(?:项目|技术栈|框架)[::]\s*(\S+)/gi,
584
+ /(?:工作目录)[::]\s*(\S+)/gi,
585
+ /(?:使用|调用)[::]\s*(\S+)/gi,
586
+ /([/\.a-zA-Z0-9_-]+\.(?:ts|js|py|md|json|yml|yaml|sh))/g,
587
+ ];
588
+ const memories = [];
589
+ for (const pat of patterns) {
590
+ let match;
591
+ while ((match = pat.exec(combined)) !== null) {
592
+ memories.push(match[1].trim());
593
+ }
594
+ }
595
+ return Array.from(new Set(memories));
596
+ }
597
+ // --- Token Budget Manager ---
598
+ export class TokenBudgetManager {
599
+ maxTokens;
600
+ nudgeThreshold;
601
+ usedTokens;
602
+ constructor(maxTokens, nudgeThreshold = 0.2, usedTokens = 0) {
603
+ this.maxTokens = maxTokens;
604
+ this.nudgeThreshold = nudgeThreshold;
605
+ this.usedTokens = usedTokens;
606
+ }
607
+ addUsage(tokens) {
608
+ this.usedTokens += tokens;
609
+ }
610
+ syncUsage(actualTokens) {
611
+ this.usedTokens = actualTokens;
612
+ }
613
+ reset() {
614
+ this.usedTokens = 0;
615
+ }
616
+ getRemaining() {
617
+ return this.maxTokens - this.usedTokens;
618
+ }
619
+ getRemainingPct() {
620
+ return this.getRemaining() / this.maxTokens;
621
+ }
622
+ shouldNudge() {
623
+ return this.getRemainingPct() < this.nudgeThreshold;
624
+ }
625
+ buildNudgeMessage() {
626
+ const pct = Math.round(this.getRemainingPct() * 100);
627
+ return "Token 预算即将耗尽(剩余 " + pct + "%),请精简回复,减少工具调用频率。";
628
+ }
629
+ estimateMessagesCost(messages) {
630
+ return messages.reduce((sum, m) => sum + m.content.length * 4, 0);
631
+ }
632
+ }
@@ -0,0 +1,14 @@
1
+ import { MetricsCollector } from "./collector.js";
2
+ export declare class AgentTelemetry {
3
+ private collector;
4
+ private sessionId;
5
+ constructor(collector: MetricsCollector, sessionId: string);
6
+ recordTurnStart(turn: number): void;
7
+ recordTurnEnd(turn: number, toolCalls: number, toolFailures: number, tokens: number): void;
8
+ recordToolCall(toolName: string, durationMs: number, success: boolean): void;
9
+ recordCompaction(before: number, after: number): void;
10
+ recordMemoryWrite(source: string): void;
11
+ recordSessionEnd(): void;
12
+ flush(): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=agent-telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-telemetry.d.ts","sourceRoot":"","sources":["../../src/metrics/agent-telemetry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM;IAK1D,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAInC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO1F,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAO5E,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAOrD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOvC,gBAAgB,IAAI,IAAI;IAIlB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,44 @@
1
+ // ============================================================
2
+ // 轻灵 - Agent Telemetry(Agent 遥测封装)
3
+ // ============================================================
4
+ export class AgentTelemetry {
5
+ collector;
6
+ sessionId;
7
+ constructor(collector, sessionId) {
8
+ this.collector = collector;
9
+ this.sessionId = sessionId;
10
+ }
11
+ recordTurnStart(turn) {
12
+ this.collector.record({ type: "turn_complete", data: { turn, phase: "start" } });
13
+ }
14
+ recordTurnEnd(turn, toolCalls, toolFailures, tokens) {
15
+ this.collector.record({
16
+ type: "turn_complete",
17
+ data: { turn, toolCalls, toolFailures, tokens },
18
+ });
19
+ }
20
+ recordToolCall(toolName, durationMs, success) {
21
+ this.collector.record({
22
+ type: success ? "tool_call" : "tool_error",
23
+ data: { toolName, durationMs },
24
+ });
25
+ }
26
+ recordCompaction(before, after) {
27
+ this.collector.record({
28
+ type: "compaction",
29
+ data: { before, after, removed: before - after },
30
+ });
31
+ }
32
+ recordMemoryWrite(source) {
33
+ this.collector.record({
34
+ type: "memory_write",
35
+ data: { source },
36
+ });
37
+ }
38
+ recordSessionEnd() {
39
+ this.collector.record({ type: "session_end", data: {} });
40
+ }
41
+ async flush() {
42
+ await this.collector.flush();
43
+ }
44
+ }