@renxqoo/renx-code 0.0.8 → 0.0.10

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 (286) hide show
  1. package/README.md +114 -40
  2. package/bin/renx.cjs +79 -42
  3. package/bin/renx.exe +0 -0
  4. package/package.json +10 -28
  5. package/src/App.tsx +0 -297
  6. package/src/agent/runtime/event-format.ts +0 -258
  7. package/src/agent/runtime/model-types.ts +0 -13
  8. package/src/agent/runtime/runtime.context-usage.test.ts +0 -192
  9. package/src/agent/runtime/runtime.error-handling.test.ts +0 -235
  10. package/src/agent/runtime/runtime.simple.test.ts +0 -16
  11. package/src/agent/runtime/runtime.test.ts +0 -296
  12. package/src/agent/runtime/runtime.ts +0 -875
  13. package/src/agent/runtime/runtime.usage-forwarding.test.ts +0 -228
  14. package/src/agent/runtime/source-modules.test.ts +0 -38
  15. package/src/agent/runtime/source-modules.ts +0 -370
  16. package/src/agent/runtime/tool-call-buffer.test.ts +0 -65
  17. package/src/agent/runtime/tool-call-buffer.ts +0 -60
  18. package/src/agent/runtime/tool-confirmation.test.ts +0 -56
  19. package/src/agent/runtime/tool-confirmation.ts +0 -15
  20. package/src/agent/runtime/types.ts +0 -99
  21. package/src/commands/slash-commands.test.ts +0 -216
  22. package/src/commands/slash-commands.ts +0 -64
  23. package/src/components/chat/assistant-reply.test.tsx +0 -47
  24. package/src/components/chat/assistant-reply.tsx +0 -136
  25. package/src/components/chat/assistant-segment.test.ts +0 -99
  26. package/src/components/chat/assistant-segment.tsx +0 -125
  27. package/src/components/chat/assistant-tool-group.tsx +0 -900
  28. package/src/components/chat/code-block.test.tsx +0 -206
  29. package/src/components/chat/code-block.tsx +0 -313
  30. package/src/components/chat/prompt-card.tsx +0 -81
  31. package/src/components/chat/segment-groups.test.ts +0 -52
  32. package/src/components/chat/segment-groups.ts +0 -106
  33. package/src/components/chat/turn-item.tsx +0 -39
  34. package/src/components/conversation-panel.tsx +0 -43
  35. package/src/components/file-mention-menu.tsx +0 -77
  36. package/src/components/file-picker-dialog.tsx +0 -206
  37. package/src/components/footer-hints.tsx +0 -75
  38. package/src/components/model-picker-dialog.tsx +0 -248
  39. package/src/components/prompt.tsx +0 -233
  40. package/src/components/slash-command-menu.tsx +0 -65
  41. package/src/components/tool-confirm-dialog-content.test.ts +0 -103
  42. package/src/components/tool-confirm-dialog-content.ts +0 -186
  43. package/src/components/tool-confirm-dialog.tsx +0 -187
  44. package/src/components/tool-display-config.ts +0 -119
  45. package/src/context-usage-regressions.test.ts +0 -26
  46. package/src/files/attachment-capabilities.test.ts +0 -30
  47. package/src/files/attachment-capabilities.ts +0 -50
  48. package/src/files/attachment-content.ts +0 -153
  49. package/src/files/file-mention-query.test.ts +0 -34
  50. package/src/files/file-mention-query.ts +0 -32
  51. package/src/files/prompt-display.ts +0 -13
  52. package/src/files/types.ts +0 -5
  53. package/src/files/workspace-files.ts +0 -61
  54. package/src/hooks/agent-event-handlers.test.ts +0 -207
  55. package/src/hooks/agent-event-handlers.ts +0 -196
  56. package/src/hooks/chat-local-replies.fixed.test.ts +0 -119
  57. package/src/hooks/chat-local-replies.test.ts +0 -153
  58. package/src/hooks/chat-local-replies.ts +0 -63
  59. package/src/hooks/turn-updater.test.ts +0 -70
  60. package/src/hooks/turn-updater.ts +0 -166
  61. package/src/hooks/use-agent-chat.context.test.ts +0 -10
  62. package/src/hooks/use-agent-chat.status.test.ts +0 -14
  63. package/src/hooks/use-agent-chat.test.ts +0 -80
  64. package/src/hooks/use-agent-chat.ts +0 -621
  65. package/src/hooks/use-file-mention-menu.ts +0 -196
  66. package/src/hooks/use-file-picker.ts +0 -185
  67. package/src/hooks/use-model-picker.ts +0 -196
  68. package/src/hooks/use-slash-command-menu.ts +0 -154
  69. package/src/index.tsx +0 -55
  70. package/src/runtime/clipboard.test.ts +0 -43
  71. package/src/runtime/clipboard.ts +0 -89
  72. package/src/runtime/exit.test.ts +0 -177
  73. package/src/runtime/exit.ts +0 -98
  74. package/src/runtime/runtime-support.test.ts +0 -31
  75. package/src/runtime/terminal-theme.test.ts +0 -55
  76. package/src/runtime/terminal-theme.ts +0 -196
  77. package/src/types/chat.ts +0 -32
  78. package/src/types/message-content.ts +0 -48
  79. package/src/ui/open-code-theme.ts +0 -176
  80. package/src/ui/opencode-markdown.ts +0 -211
  81. package/src/ui/theme.simple.test.ts +0 -52
  82. package/src/ui/theme.test.ts +0 -151
  83. package/src/ui/theme.ts +0 -152
  84. package/src/utils/time.test.ts +0 -144
  85. package/src/utils/time.ts +0 -7
  86. package/tsconfig.json +0 -30
  87. package/vendor/agent-root/src/agent/ENTERPRISE_ACCEPTANCE_CHECKLIST.md +0 -95
  88. package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.html +0 -1345
  89. package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.md +0 -1353
  90. package/vendor/agent-root/src/agent/ERROR_CONTRACT.md +0 -60
  91. package/vendor/agent-root/src/agent/TEST_COVERAGE_ANALYSIS.md +0 -278
  92. package/vendor/agent-root/src/agent/__test__/error-contract.test.ts +0 -72
  93. package/vendor/agent-root/src/agent/__test__/types.test.ts +0 -137
  94. package/vendor/agent-root/src/agent/agent/__test__/abort-runtime.test.ts +0 -83
  95. package/vendor/agent-root/src/agent/agent/__test__/callback-safety.test.ts +0 -34
  96. package/vendor/agent-root/src/agent/agent/__test__/compaction.test.ts +0 -323
  97. package/vendor/agent-root/src/agent/agent/__test__/concurrency.test.ts +0 -290
  98. package/vendor/agent-root/src/agent/agent/__test__/error-normalizer.test.ts +0 -377
  99. package/vendor/agent-root/src/agent/agent/__test__/error.test.ts +0 -212
  100. package/vendor/agent-root/src/agent/agent/__test__/fault-injection.test.ts +0 -295
  101. package/vendor/agent-root/src/agent/agent/__test__/index.test.ts +0 -3607
  102. package/vendor/agent-root/src/agent/agent/__test__/logger.test.ts +0 -35
  103. package/vendor/agent-root/src/agent/agent/__test__/message-utils.test.ts +0 -517
  104. package/vendor/agent-root/src/agent/agent/__test__/telemetry.test.ts +0 -97
  105. package/vendor/agent-root/src/agent/agent/__test__/timeout-budget.test.ts +0 -479
  106. package/vendor/agent-root/src/agent/agent/__test__/tool-call-merge.test.ts +0 -80
  107. package/vendor/agent-root/src/agent/agent/__test__/tool-execution-ledger.test.ts +0 -76
  108. package/vendor/agent-root/src/agent/agent/__test__/write-buffer.test.ts +0 -173
  109. package/vendor/agent-root/src/agent/agent/__test__/write-file-session.test.ts +0 -109
  110. package/vendor/agent-root/src/agent/agent/abort-runtime.ts +0 -71
  111. package/vendor/agent-root/src/agent/agent/callback-safety.ts +0 -33
  112. package/vendor/agent-root/src/agent/agent/compaction.ts +0 -291
  113. package/vendor/agent-root/src/agent/agent/concurrency.ts +0 -103
  114. package/vendor/agent-root/src/agent/agent/error-normalizer.ts +0 -190
  115. package/vendor/agent-root/src/agent/agent/error.ts +0 -198
  116. package/vendor/agent-root/src/agent/agent/index.ts +0 -1772
  117. package/vendor/agent-root/src/agent/agent/logger.ts +0 -65
  118. package/vendor/agent-root/src/agent/agent/message-utils.ts +0 -101
  119. package/vendor/agent-root/src/agent/agent/stream-events.ts +0 -61
  120. package/vendor/agent-root/src/agent/agent/telemetry.ts +0 -123
  121. package/vendor/agent-root/src/agent/agent/timeout-budget.ts +0 -227
  122. package/vendor/agent-root/src/agent/agent/tool-call-merge.ts +0 -111
  123. package/vendor/agent-root/src/agent/agent/tool-execution-ledger.ts +0 -164
  124. package/vendor/agent-root/src/agent/agent/write-buffer.ts +0 -188
  125. package/vendor/agent-root/src/agent/agent/write-file-session.ts +0 -238
  126. package/vendor/agent-root/src/agent/app/__test__/agent-app-service.test.ts +0 -1053
  127. package/vendor/agent-root/src/agent/app/__test__/minimal-agent-application.test.ts +0 -158
  128. package/vendor/agent-root/src/agent/app/__test__/sqlite-agent-app-store.test.ts +0 -437
  129. package/vendor/agent-root/src/agent/app/agent-app-service.ts +0 -748
  130. package/vendor/agent-root/src/agent/app/contracts.ts +0 -109
  131. package/vendor/agent-root/src/agent/app/index.ts +0 -5
  132. package/vendor/agent-root/src/agent/app/minimal-agent-application.ts +0 -151
  133. package/vendor/agent-root/src/agent/app/ports.ts +0 -72
  134. package/vendor/agent-root/src/agent/app/sqlite-agent-app-store.ts +0 -1182
  135. package/vendor/agent-root/src/agent/app/sqlite-client.ts +0 -177
  136. package/vendor/agent-root/src/agent/docs/cli-app-layer/00-README.md +0 -36
  137. package/vendor/agent-root/src/agent/docs/cli-app-layer/01-scope-and-goals.md +0 -33
  138. package/vendor/agent-root/src/agent/docs/cli-app-layer/02-architecture-overview.md +0 -40
  139. package/vendor/agent-root/src/agent/docs/cli-app-layer/03-domain-model-and-contracts.md +0 -91
  140. package/vendor/agent-root/src/agent/docs/cli-app-layer/04-ports-and-interfaces.md +0 -116
  141. package/vendor/agent-root/src/agent/docs/cli-app-layer/05-run-orchestration-and-state-machine.md +0 -52
  142. package/vendor/agent-root/src/agent/docs/cli-app-layer/06-cli-commands-and-ux.md +0 -53
  143. package/vendor/agent-root/src/agent/docs/cli-app-layer/07-storage-design-local.md +0 -52
  144. package/vendor/agent-root/src/agent/docs/cli-app-layer/08-error-and-observability.md +0 -40
  145. package/vendor/agent-root/src/agent/docs/cli-app-layer/09-security-and-policy-boundary.md +0 -19
  146. package/vendor/agent-root/src/agent/docs/cli-app-layer/10-test-plan-and-acceptance.md +0 -28
  147. package/vendor/agent-root/src/agent/docs/cli-app-layer/11-implementation-phases.md +0 -26
  148. package/vendor/agent-root/src/agent/docs/cli-app-layer/12-open-questions-and-risks.md +0 -30
  149. package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md +0 -567
  150. package/vendor/agent-root/src/agent/docs/cli-app-layer/14-project-flow-mermaid.md +0 -583
  151. package/vendor/agent-root/src/agent/docs/cli-app-layer/15-openclaw-style-project-blueprint.md +0 -972
  152. package/vendor/agent-root/src/agent/error-contract.ts +0 -154
  153. package/vendor/agent-root/src/agent/prompts/system.ts +0 -246
  154. package/vendor/agent-root/src/agent/prompts/system1.ts +0 -208
  155. package/vendor/agent-root/src/agent/storage/__test__/file-history-store.test.ts +0 -98
  156. package/vendor/agent-root/src/agent/storage/file-history-store.ts +0 -313
  157. package/vendor/agent-root/src/agent/storage/file-storage-config.ts +0 -94
  158. package/vendor/agent-root/src/agent/storage/file-system.ts +0 -31
  159. package/vendor/agent-root/src/agent/storage/file-write-service.ts +0 -21
  160. package/vendor/agent-root/src/agent/tool/__test__/base-tool.test.ts +0 -413
  161. package/vendor/agent-root/src/agent/tool/__test__/bash-policy.test.ts +0 -356
  162. package/vendor/agent-root/src/agent/tool/__test__/bash.mocked-coverage.test.ts +0 -375
  163. package/vendor/agent-root/src/agent/tool/__test__/bash.test.ts +0 -372
  164. package/vendor/agent-root/src/agent/tool/__test__/error.test.ts +0 -108
  165. package/vendor/agent-root/src/agent/tool/__test__/file-edit-tool.test.ts +0 -258
  166. package/vendor/agent-root/src/agent/tool/__test__/file-history-tools.test.ts +0 -121
  167. package/vendor/agent-root/src/agent/tool/__test__/file-read-tool.test.ts +0 -210
  168. package/vendor/agent-root/src/agent/tool/__test__/glob.test.ts +0 -139
  169. package/vendor/agent-root/src/agent/tool/__test__/grep.mocked-coverage.test.ts +0 -456
  170. package/vendor/agent-root/src/agent/tool/__test__/grep.test.ts +0 -192
  171. package/vendor/agent-root/src/agent/tool/__test__/lsp.test.ts +0 -300
  172. package/vendor/agent-root/src/agent/tool/__test__/outside-workspace-confirmation.test.ts +0 -214
  173. package/vendor/agent-root/src/agent/tool/__test__/path-security.test.ts +0 -336
  174. package/vendor/agent-root/src/agent/tool/__test__/skill-loader.test.ts +0 -494
  175. package/vendor/agent-root/src/agent/tool/__test__/skill-parser.test.ts +0 -543
  176. package/vendor/agent-root/src/agent/tool/__test__/skill-tool.test.ts +0 -172
  177. package/vendor/agent-root/src/agent/tool/__test__/task-concurrency-and-version.test.ts +0 -116
  178. package/vendor/agent-root/src/agent/tool/__test__/task-create-get-list-update.test.ts +0 -267
  179. package/vendor/agent-root/src/agent/tool/__test__/task-create.test.ts +0 -519
  180. package/vendor/agent-root/src/agent/tool/__test__/task-errors.test.ts +0 -225
  181. package/vendor/agent-root/src/agent/tool/__test__/task-output-blocking.test.ts +0 -223
  182. package/vendor/agent-root/src/agent/tool/__test__/task-output.test.ts +0 -184
  183. package/vendor/agent-root/src/agent/tool/__test__/task-parent-abort.test.ts +0 -287
  184. package/vendor/agent-root/src/agent/tool/__test__/task-real-runner-adapter.test.ts +0 -190
  185. package/vendor/agent-root/src/agent/tool/__test__/task-run-lifecycle.test.ts +0 -352
  186. package/vendor/agent-root/src/agent/tool/__test__/task-store-runner-branches.test.ts +0 -395
  187. package/vendor/agent-root/src/agent/tool/__test__/task-store.test.ts +0 -391
  188. package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config-integration.test.ts +0 -176
  189. package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config.test.ts +0 -68
  190. package/vendor/agent-root/src/agent/tool/__test__/task-tools-core-edges.test.ts +0 -630
  191. package/vendor/agent-root/src/agent/tool/__test__/task-tools-runtime-edges.test.ts +0 -732
  192. package/vendor/agent-root/src/agent/tool/__test__/task-types.test.ts +0 -494
  193. package/vendor/agent-root/src/agent/tool/__test__/task-utils-branches.test.ts +0 -175
  194. package/vendor/agent-root/src/agent/tool/__test__/tool-manager.test.ts +0 -505
  195. package/vendor/agent-root/src/agent/tool/__test__/types.test.ts +0 -55
  196. package/vendor/agent-root/src/agent/tool/__test__/web-fetch.test.ts +0 -244
  197. package/vendor/agent-root/src/agent/tool/__test__/web-search.test.ts +0 -290
  198. package/vendor/agent-root/src/agent/tool/__test__/write-file.test.ts +0 -368
  199. package/vendor/agent-root/src/agent/tool/base-tool.ts +0 -345
  200. package/vendor/agent-root/src/agent/tool/bash-policy.ts +0 -636
  201. package/vendor/agent-root/src/agent/tool/bash.ts +0 -688
  202. package/vendor/agent-root/src/agent/tool/error.ts +0 -131
  203. package/vendor/agent-root/src/agent/tool/file-edit-tool.ts +0 -264
  204. package/vendor/agent-root/src/agent/tool/file-history-list.ts +0 -103
  205. package/vendor/agent-root/src/agent/tool/file-history-restore.ts +0 -149
  206. package/vendor/agent-root/src/agent/tool/file-read-tool.ts +0 -211
  207. package/vendor/agent-root/src/agent/tool/glob.ts +0 -171
  208. package/vendor/agent-root/src/agent/tool/grep.ts +0 -496
  209. package/vendor/agent-root/src/agent/tool/lsp.ts +0 -481
  210. package/vendor/agent-root/src/agent/tool/path-security.ts +0 -117
  211. package/vendor/agent-root/src/agent/tool/search/common.ts +0 -153
  212. package/vendor/agent-root/src/agent/tool/skill/index.ts +0 -13
  213. package/vendor/agent-root/src/agent/tool/skill/loader.ts +0 -229
  214. package/vendor/agent-root/src/agent/tool/skill/parser.ts +0 -124
  215. package/vendor/agent-root/src/agent/tool/skill/types.ts +0 -27
  216. package/vendor/agent-root/src/agent/tool/skill-tool.ts +0 -143
  217. package/vendor/agent-root/src/agent/tool/task-create.ts +0 -186
  218. package/vendor/agent-root/src/agent/tool/task-errors.ts +0 -42
  219. package/vendor/agent-root/src/agent/tool/task-get.ts +0 -116
  220. package/vendor/agent-root/src/agent/tool/task-graph.ts +0 -78
  221. package/vendor/agent-root/src/agent/tool/task-list.ts +0 -141
  222. package/vendor/agent-root/src/agent/tool/task-mock-runner-adapter.ts +0 -232
  223. package/vendor/agent-root/src/agent/tool/task-output.ts +0 -223
  224. package/vendor/agent-root/src/agent/tool/task-parent-abort.ts +0 -115
  225. package/vendor/agent-root/src/agent/tool/task-real-runner-adapter.ts +0 -336
  226. package/vendor/agent-root/src/agent/tool/task-runner-adapter.ts +0 -55
  227. package/vendor/agent-root/src/agent/tool/task-stop.ts +0 -187
  228. package/vendor/agent-root/src/agent/tool/task-store.ts +0 -217
  229. package/vendor/agent-root/src/agent/tool/task-subagent-config.ts +0 -149
  230. package/vendor/agent-root/src/agent/tool/task-types.ts +0 -264
  231. package/vendor/agent-root/src/agent/tool/task-update.ts +0 -315
  232. package/vendor/agent-root/src/agent/tool/task.ts +0 -209
  233. package/vendor/agent-root/src/agent/tool/tool-manager.ts +0 -361
  234. package/vendor/agent-root/src/agent/tool/tool-prompts.ts +0 -242
  235. package/vendor/agent-root/src/agent/tool/types.ts +0 -116
  236. package/vendor/agent-root/src/agent/tool/web-fetch.ts +0 -227
  237. package/vendor/agent-root/src/agent/tool/web-search.ts +0 -208
  238. package/vendor/agent-root/src/agent/tool/write-file.ts +0 -497
  239. package/vendor/agent-root/src/agent/types.ts +0 -232
  240. package/vendor/agent-root/src/agent/utils/__tests__/index.test.ts +0 -18
  241. package/vendor/agent-root/src/agent/utils/__tests__/message-utils.test.ts +0 -610
  242. package/vendor/agent-root/src/agent/utils/__tests__/message.test.ts +0 -223
  243. package/vendor/agent-root/src/agent/utils/__tests__/token.test.ts +0 -42
  244. package/vendor/agent-root/src/agent/utils/index.ts +0 -16
  245. package/vendor/agent-root/src/agent/utils/message.ts +0 -171
  246. package/vendor/agent-root/src/agent/utils/token.ts +0 -28
  247. package/vendor/agent-root/src/config/__tests__/load-config-to-env.test.ts +0 -238
  248. package/vendor/agent-root/src/config/__tests__/loader.test.ts +0 -361
  249. package/vendor/agent-root/src/config/__tests__/runtime.test.ts +0 -88
  250. package/vendor/agent-root/src/config/index.ts +0 -55
  251. package/vendor/agent-root/src/config/loader.ts +0 -494
  252. package/vendor/agent-root/src/config/paths.ts +0 -30
  253. package/vendor/agent-root/src/config/runtime.ts +0 -163
  254. package/vendor/agent-root/src/config/types.ts +0 -96
  255. package/vendor/agent-root/src/logger/index.ts +0 -57
  256. package/vendor/agent-root/src/logger/logger.ts +0 -819
  257. package/vendor/agent-root/src/logger/types.ts +0 -150
  258. package/vendor/agent-root/src/providers/__tests__/errors.test.ts +0 -441
  259. package/vendor/agent-root/src/providers/__tests__/index.test.ts +0 -16
  260. package/vendor/agent-root/src/providers/__tests__/openai-compatible.options.test.ts +0 -318
  261. package/vendor/agent-root/src/providers/__tests__/openai-compatible.test.ts +0 -600
  262. package/vendor/agent-root/src/providers/__tests__/registry.test.ts +0 -523
  263. package/vendor/agent-root/src/providers/__tests__/responses-adapter.test.ts +0 -298
  264. package/vendor/agent-root/src/providers/adapters/__tests__/anthropic.test.ts +0 -354
  265. package/vendor/agent-root/src/providers/adapters/__tests__/kimi.test.ts +0 -58
  266. package/vendor/agent-root/src/providers/adapters/__tests__/standard.test.ts +0 -261
  267. package/vendor/agent-root/src/providers/adapters/anthropic.ts +0 -572
  268. package/vendor/agent-root/src/providers/adapters/base.ts +0 -131
  269. package/vendor/agent-root/src/providers/adapters/kimi.ts +0 -48
  270. package/vendor/agent-root/src/providers/adapters/responses.ts +0 -732
  271. package/vendor/agent-root/src/providers/adapters/standard.ts +0 -120
  272. package/vendor/agent-root/src/providers/http/__tests__/client.timeout.test.ts +0 -313
  273. package/vendor/agent-root/src/providers/http/client.ts +0 -289
  274. package/vendor/agent-root/src/providers/http/stream-parser.ts +0 -109
  275. package/vendor/agent-root/src/providers/index.ts +0 -76
  276. package/vendor/agent-root/src/providers/kimi-headers.ts +0 -177
  277. package/vendor/agent-root/src/providers/openai-compatible.ts +0 -387
  278. package/vendor/agent-root/src/providers/registry/model-config.ts +0 -477
  279. package/vendor/agent-root/src/providers/registry/provider-factory.ts +0 -127
  280. package/vendor/agent-root/src/providers/registry.ts +0 -135
  281. package/vendor/agent-root/src/providers/types/api.ts +0 -284
  282. package/vendor/agent-root/src/providers/types/config.ts +0 -58
  283. package/vendor/agent-root/src/providers/types/errors.ts +0 -323
  284. package/vendor/agent-root/src/providers/types/index.ts +0 -72
  285. package/vendor/agent-root/src/providers/types/provider.ts +0 -45
  286. package/vendor/agent-root/src/providers/types/registry.ts +0 -68
@@ -1,177 +0,0 @@
1
- import * as fs from 'node:fs/promises';
2
- import { createRequire } from 'node:module';
3
- import * as path from 'node:path';
4
-
5
- interface SqliteStatementLike {
6
- run: (...params: unknown[]) => unknown;
7
- get: (...params: unknown[]) => unknown;
8
- all: (...params: unknown[]) => unknown[];
9
- }
10
-
11
- interface SqliteDatabaseLike {
12
- exec: (sql: string) => void;
13
- prepare: (sql: string) => SqliteStatementLike;
14
- close: () => void;
15
- }
16
-
17
- interface BunSqliteStatementLike {
18
- run: (...params: unknown[]) => unknown;
19
- get: (...params: unknown[]) => unknown;
20
- all: (...params: unknown[]) => unknown[];
21
- }
22
-
23
- interface BunSqliteDatabaseLike {
24
- exec: (sql: string) => unknown;
25
- query: (sql: string) => BunSqliteStatementLike;
26
- close: () => unknown;
27
- }
28
-
29
- class BunSqliteDatabaseAdapter implements SqliteDatabaseLike {
30
- constructor(private readonly db: BunSqliteDatabaseLike) {}
31
-
32
- exec(sql: string): void {
33
- this.db.exec(sql);
34
- }
35
-
36
- prepare(sql: string): SqliteStatementLike {
37
- const statement = this.db.query(sql);
38
- return {
39
- run: (...params: unknown[]) => statement.run(...params),
40
- get: (...params: unknown[]) => statement.get(...params),
41
- all: (...params: unknown[]) => statement.all(...params),
42
- };
43
- }
44
-
45
- close(): void {
46
- this.db.close();
47
- }
48
- }
49
-
50
- /**
51
- * Agent-v4 app 专用 SQLite 客户端。
52
- * 只负责连接与事务,不执行通用 storage 模块的旧迁移。
53
- */
54
- export class AgentAppSqliteClient {
55
- private static readonly require = createRequire(import.meta.url);
56
- private db: SqliteDatabaseLike | null = null;
57
- private initialized = false;
58
- private initializePromise: Promise<void> | null = null;
59
-
60
- constructor(private readonly dbPath: string) {}
61
-
62
- async prepare(): Promise<void> {
63
- if (this.initialized) {
64
- return;
65
- }
66
- if (this.initializePromise) {
67
- return this.initializePromise;
68
- }
69
- this.initializePromise = this.doPrepare();
70
- try {
71
- await this.initializePromise;
72
- } finally {
73
- this.initializePromise = null;
74
- }
75
- }
76
-
77
- private async doPrepare(): Promise<void> {
78
- await fs.mkdir(path.dirname(this.dbPath), { recursive: true });
79
-
80
- this.db = this.tryCreateNodeSqlite() ?? this.tryCreateBunSqlite();
81
- if (!this.db) {
82
- throw new Error(
83
- 'Unable to initialize sqlite backend: neither "node:sqlite" nor "bun:sqlite" is available.'
84
- );
85
- }
86
-
87
- this.db.exec('PRAGMA foreign_keys = ON;');
88
- this.db.exec('PRAGMA journal_mode = WAL;');
89
- this.db.exec('PRAGMA synchronous = NORMAL;');
90
- this.db.exec('PRAGMA temp_store = MEMORY;');
91
- this.db.exec('PRAGMA busy_timeout = 5000;');
92
- this.initialized = true;
93
- }
94
-
95
- async exec(sql: string): Promise<void> {
96
- this.requireDb().exec(sql);
97
- }
98
-
99
- async run(sql: string, params: unknown[] = []): Promise<void> {
100
- this.requireDb()
101
- .prepare(sql)
102
- .run(...params);
103
- }
104
-
105
- async get<T>(sql: string, params: unknown[] = []): Promise<T | undefined> {
106
- return this.requireDb()
107
- .prepare(sql)
108
- .get(...params) as T | undefined;
109
- }
110
-
111
- async all<T>(sql: string, params: unknown[] = []): Promise<T[]> {
112
- return this.requireDb()
113
- .prepare(sql)
114
- .all(...params) as T[];
115
- }
116
-
117
- async transaction<T>(fn: () => Promise<T>): Promise<T> {
118
- const db = this.requireDb();
119
- db.exec('BEGIN IMMEDIATE;');
120
- try {
121
- const result = await fn();
122
- db.exec('COMMIT;');
123
- return result;
124
- } catch (error) {
125
- db.exec('ROLLBACK;');
126
- throw error;
127
- }
128
- }
129
-
130
- async close(): Promise<void> {
131
- if (this.initializePromise) {
132
- await this.initializePromise.catch(() => undefined);
133
- }
134
- if (this.db) {
135
- try {
136
- this.db.exec('PRAGMA wal_checkpoint(TRUNCATE);');
137
- } catch {
138
- // Ignore checkpoint errors during shutdown and still close the handle.
139
- }
140
- this.db.close();
141
- this.db = null;
142
- }
143
- this.initialized = false;
144
- }
145
-
146
- private tryCreateNodeSqlite(): SqliteDatabaseLike | null {
147
- try {
148
- const sqliteModule = AgentAppSqliteClient.require('node:sqlite') as {
149
- DatabaseSync: new (location: string) => SqliteDatabaseLike;
150
- };
151
- return new sqliteModule.DatabaseSync(this.dbPath);
152
- } catch {
153
- return null;
154
- }
155
- }
156
-
157
- private tryCreateBunSqlite(): SqliteDatabaseLike | null {
158
- try {
159
- const sqliteModule = AgentAppSqliteClient.require('bun:sqlite') as {
160
- Database: new (location: string, options?: { create?: boolean }) => BunSqliteDatabaseLike;
161
- };
162
- const db = new sqliteModule.Database(this.dbPath, { create: true });
163
- return new BunSqliteDatabaseAdapter(db);
164
- } catch {
165
- return null;
166
- }
167
- }
168
-
169
- private requireDb(): SqliteDatabaseLike {
170
- if (!this.db) {
171
- throw new Error('SQLite client not initialized. Call prepare() first.');
172
- }
173
- return this.db;
174
- }
175
- }
176
-
177
- export const AGENT_APP_SQLITE_CLIENT_MODULE = 'renx-app-sqlite-client';
@@ -1,36 +0,0 @@
1
- # Agent-V4 CLI 应用层技术文档总览
2
-
3
- 本目录用于沉淀 `agent-v4` 的应用层实现设计,目标是让 `StatelessAgent` 内核可稳定服务 CLI 场景,并保持无状态架构原则。
4
-
5
- ## 文档清单(按编号)
6
-
7
- - `01-scope-and-goals.md`:目标、范围、非目标、约束
8
- - `02-architecture-overview.md`:总体分层架构与依赖方向
9
- - `03-domain-model-and-contracts.md`:领域模型与核心数据契约
10
- - `04-ports-and-interfaces.md`:应用层 Port 接口定义
11
- - `05-run-orchestration-and-state-machine.md`:执行编排、状态机与时序
12
- - `06-cli-commands-and-ux.md`:CLI 命令与交互规范
13
- - `07-storage-design-local.md`:Phase 1 本地存储设计
14
- - `08-error-and-observability.md`:错误策略、日志、指标、追踪
15
- - `09-security-and-policy-boundary.md`:安全边界与策略层职责
16
- - `10-test-plan-and-acceptance.md`:测试计划与验收标准
17
- - `11-implementation-phases.md`:分阶段实施计划
18
- - `12-open-questions-and-risks.md`:开放问题与风险登记
19
- - `13-sqlite-schema-fields-and-rationale.md`:SQLite 表结构、字段释义与存储理由
20
- - `14-project-flow-mermaid.md`:项目级详细流程图(Mermaid)
21
-
22
- ## 使用方式
23
-
24
- 1. 先阅读 `01` 到 `05`,统一架构和执行语义。
25
- 2. 再阅读 `06` 到 `09`,明确 CLI 落地方式与运维安全边界。
26
- 3. 使用 `10` 和 `11` 驱动开发计划与验收。
27
- 4. `12` 用于实现前对齐决策,避免反复返工。
28
-
29
- ## 当前状态
30
-
31
- - 文档为“可实现级别”的设计稿。
32
- - 默认不改动 `agent-v4` 内核契约。
33
- - 应用层实现应以 Port + Adapter 方式扩展,避免反向侵入内核。
34
- ## 补充文档
35
-
36
- - `15-openclaw-style-project-blueprint.md`:说明如何在 `agent-v4` 之上实现一个类似 OpenClaw 的网关化、多渠道、插件化系统。
@@ -1,33 +0,0 @@
1
- # 01. 范围与目标
2
-
3
- ## 1. 背景
4
-
5
- `agent-v4` 已具备内核执行能力(LLM 调用、工具执行、流式事件、错误契约、超时预算)。当前缺口是可被 CLI 直接使用的应用层。
6
-
7
- ## 2. 目标
8
-
9
- - 提供可复用的应用层入口,将内核能力组装为 CLI 可用服务。
10
- - 保持无状态原则:执行真相进入存储,不依赖进程内全局状态。
11
- - 支持前台流式执行(Phase 1),并为后续后台化与恢复预留接口。
12
- - 提供清晰的执行生命周期:创建、运行、完成、失败、取消。
13
-
14
- ## 3. 范围(In Scope)
15
-
16
- - 应用层服务接口:`runForeground/getRun/listRuns`。
17
- - 事件桥接:`runStream` 流事件 + `onMessage/onCheckpoint/onCompaction/onError` 回调统一落库与发布。
18
- - 本地存储实现(Phase 1 统一采用 SQLite,文件存储仅作历史兼容方案)。
19
- - CLI 命令协议与输出事件模型。
20
- - 测试与验收规范。
21
-
22
- ## 4. 非目标(Out of Scope)
23
-
24
- - P0 级安全策略重构(如 `bash` 重写)
25
- - 分布式任务队列与多 Worker 编排
26
- - 跨主机高可用部署方案
27
- - Redis/DB 幂等账本生产实现(仅保留接口)
28
-
29
- ## 5. 关键约束
30
-
31
- - 不破坏 `StatelessAgent` 核心接口。
32
- - 应用层必须依赖抽象 Port,不直接耦合具体存储细节。
33
- - CLI 层仅做解析与展示,不承载业务编排逻辑。
@@ -1,40 +0,0 @@
1
- # 02. 总体架构
2
-
3
- ## 1. 分层
4
-
5
- - Kernel Layer:`StatelessAgent` 与工具内核。
6
- - Application Layer:执行编排、状态流转、回调桥接。
7
- - Port Layer:存储、上下文、事件、账本抽象。
8
- - Adapter Layer:本地文件/SQLite、CLI 事件输出实现。
9
- - Interface Layer:CLI 命令。
10
-
11
- ## 2. 依赖方向
12
-
13
- 仅允许:`CLI -> App -> Port -> Adapter`,以及 `App -> Kernel`。
14
-
15
- 禁止:
16
- - CLI 直接依赖 Kernel 内部模块。
17
- - Adapter 直接调用 Kernel。
18
- - Kernel 反向依赖 App/Adapter。
19
-
20
- ## 3. 核心设计原则
21
-
22
- - 单一职责:内核只执行,应用层只编排。
23
- - 无状态优先:跨执行状态一律外置到存储。
24
- - 事件源优先:`runStream` 事件作为事实源,读模型可重建。
25
- - 双通道桥接:`runStream` + `tool_chunk`(桥接为 `tool_stream`)。
26
- - 事件驱动:统一 `CliEvent`,屏蔽内核事件差异。
27
- - 可替换:所有外部依赖通过 Port 注入。
28
-
29
- ## 4. 逻辑结构图
30
-
31
- - `AgentAppService`:外部 Facade。
32
- - `RunOrchestrator`:单次执行调度器。
33
- - `ExecutionStorePort`:执行状态持久化。
34
- - `ExecutionStepStorePort`:步骤级状态持久化。
35
- - `EventStorePort`:事件事实源持久化。
36
- - `MessageProjectionStorePort`:消息读模型投影。
37
- - `CheckpointStorePort`:检查点持久化。
38
- - `ConversationStorePort`:会话存在性与元信息读取。
39
- - `EventSinkPort`:事件发布。
40
- - `ContextProviderPort`:上下文加载。
@@ -1,91 +0,0 @@
1
- # 03. 领域模型与数据契约
2
-
3
- ## 1. 核心实体
4
-
5
- ### RunRecord
6
- - `executionId: string`
7
- - `runId: string`(持久化层别名,默认与 `executionId` 一致)
8
- - `conversationId: string`
9
- - `status: CREATED | QUEUED | RUNNING | COMPLETED | FAILED | CANCELLED`(Phase 1 可不启用 `QUEUED`)
10
- - `createdAt: number`
11
- - `updatedAt: number`
12
- - `stepIndex: number`
13
- - `lastCheckpointSeq?: number`
14
- - `terminalReason?: stop | max_steps | error | aborted | timeout | rate_limit | max_retries`
15
- - `errorCode?: string`
16
- - `errorCategory?: string`
17
- - `errorMessage?: string`
18
-
19
- ### RunRequest
20
- - `conversationId: string`
21
- - `userInput: string`
22
- - `executionId?: string`
23
- - `maxSteps?: number`
24
-
25
- ### ExecutionStepRecord
26
- - `executionId: string`
27
- - `stepIndex: number`
28
- - `status: pending | executing | completed | failed | skipped`
29
- - `stage?: llm | tool | checkpoint`
30
- - `errorCode?: string`
31
- - `startedAt?: number`
32
- - `completedAt?: number`
33
-
34
- ### ConversationRecord
35
- - `conversationId: string`
36
- - `title?: string`
37
- - `status: active | archived`
38
- - `workspacePath?: string`
39
- - `createdAt: number`
40
- - `updatedAt: number`
41
-
42
- ### CliEvent(内核 `StreamEvent` + 应用层扩展)
43
- - `user_message`(应用层扩展)
44
- - `assistant_message`(应用层扩展)
45
- - `chunk`
46
- - `reasoning_chunk`
47
- - `tool_call`
48
- - `tool_result`
49
- - `tool_stream`(应用层由 `agent.on('tool_chunk')` 归一化桥接)
50
- - `progress`
51
- - `checkpoint`
52
- - `compaction`
53
- - `done`
54
- - `error`
55
-
56
- ### CliEventEnvelope
57
- - `conversationId: string`
58
- - `executionId: string`
59
- - `seq: number`(会话内单调递增)
60
- - `eventType: CliEvent['type']`
61
- - `data: unknown`
62
- - `createdAt: number`
63
-
64
- ## 2. 终止语义与状态映射
65
-
66
- - `done.finishReason=stop|max_steps` -> `RunRecord.status=COMPLETED`
67
- - `error.errorCode=AGENT_ABORTED` -> `RunRecord.status=CANCELLED`,`terminalReason=aborted`
68
- - `error.errorCode=AGENT_TIMEOUT_BUDGET_EXCEEDED` -> `RunRecord.status=FAILED`,`terminalReason=timeout`
69
- - `error.errorCode=AGENT_UPSTREAM_TIMEOUT` -> `RunRecord.status=FAILED`,`terminalReason=timeout`
70
- - `error.errorCode=AGENT_UPSTREAM_RATE_LIMIT` -> `RunRecord.status=FAILED`,`terminalReason=rate_limit`
71
- - `error.errorCode=AGENT_MAX_RETRIES_REACHED` -> `RunRecord.status=FAILED`,`terminalReason=max_retries`
72
- - 其他 `error` -> `RunRecord.status=FAILED`,`terminalReason=error`
73
-
74
- ## 3. 状态变更约束
75
-
76
- - `createdAt` 不可变。
77
- - `updatedAt` 每次状态更新必须刷新。
78
- - `stepIndex` 只能增长。
79
- - `COMPLETED/FAILED/CANCELLED` 为终态,不允许再切回 `RUNNING`。
80
-
81
- ## 4. ID 约束
82
-
83
- - `executionId` 全局唯一(可采用 `trace_` 风格时间戳+随机串)。
84
- - `conversationId` 由上层会话管理系统提供。
85
- - `runId` 是存储层主键名;对外 CLI/API 统一使用 `executionId`。
86
-
87
- ## 5. 兼容性约束
88
-
89
- - 应用层事件必须保留内核错误包:`errorCode/category/httpStatus/retryable`。
90
- - 对外事件字段采用增量扩展,不删除既有字段。
91
- - 应用层的持久化事实源以 `events` 为准,`messages` 为投影视图。
@@ -1,116 +0,0 @@
1
- # 04. Port 接口设计
2
-
3
- ## 1. ExecutionStorePort
4
-
5
- 职责:执行生命周期持久化。
6
-
7
- 接口:
8
- - `create(run: RunRecord): Promise<void>`
9
- - `patch(executionId: string, patch: Partial<RunRecord>): Promise<void>`
10
- - `get(executionId: string): Promise<RunRecord | null>`
11
- - `listByConversation(conversationId: string, opts?: { statuses?: RunRecord['status'][]; limit?: number; cursor?: string }): Promise<{ items: RunRecord[]; nextCursor?: string }>`
12
-
13
- ## 2. EventStorePort(事实源,必需)
14
-
15
- 职责:持久化 `runStream` 与回调产生的原始事件。
16
-
17
- 接口:
18
- - `appendAutoSeq(event: Omit<CliEventEnvelope, 'seq'>): Promise<CliEventEnvelope>`
19
- - `append(event: CliEventEnvelope): Promise<void>`(仅回放/导入使用)
20
- - `listByRun(executionId: string): Promise<CliEventEnvelope[]>`
21
- - `listByConversation(conversationId: string, opts?: { fromSeq?: number; limit?: number }): Promise<CliEventEnvelope[]>`
22
-
23
- 约束:
24
- - append-only,不允许覆盖历史事件。
25
- - 会话内序号必须单调递增。
26
- - `appendAutoSeq` 必须在单事务内原子分配 `seq`(禁止先查后写)。
27
-
28
- ## 3. MessageProjectionStorePort(投影层,可选但推荐)
29
-
30
- 职责:维护消息读模型(由事件投影构建)。
31
-
32
- 接口:
33
- - `upsertFromEvent(event: CliEventEnvelope): Promise<void>`
34
- - `list(conversationId: string): Promise<Message[]>`
35
-
36
- ## 4. ExecutionStepStorePort(推荐)
37
-
38
- 职责:步骤级状态明细(`run-status --verbose` 与调试)。
39
-
40
- 接口:
41
- - `upsert(step: ExecutionStepRecord): Promise<void>`
42
- - `listByRun(executionId: string, opts?: { limit?: number }): Promise<ExecutionStepRecord[]>`
43
- - `listLatestByRuns(executionIds: string[]): Promise<Record<string, ExecutionStepRecord | undefined>>`
44
-
45
- ## 5. CheckpointStorePort(可选)
46
-
47
- 职责:断点恢复位置存储。
48
-
49
- 接口:
50
- - `save(checkpoint: ExecutionCheckpoint): Promise<void>`
51
- - `getLatest(executionId: string): Promise<ExecutionCheckpoint | null>`
52
- - `clear(executionId: string): Promise<void>`
53
-
54
- 说明:
55
- - 若不建独立 `checkpoints` 表,可从 `events(event_type=checkpoint)` 投影实现。
56
-
57
- ## 6. ContextSnapshotStorePort(推荐)
58
-
59
- 职责:存储每步实际喂给模型的上下文快照。
60
-
61
- 接口:
62
- - `saveSnapshot(snapshot: ContextSnapshotRecord, items: ContextSnapshotItemRecord[]): Promise<void>`
63
- - `getByRun(executionId: string): Promise<ContextSnapshotRecord[]>`
64
-
65
- ## 7. SummaryStorePort(推荐)
66
-
67
- 职责:存储压缩摘要产物。
68
-
69
- 接口:
70
- - `append(summary: SummaryRecord): Promise<void>`
71
- - `listByConversation(conversationId: string): Promise<SummaryRecord[]>`
72
-
73
- ## 8. RunLogStorePort(可选)
74
-
75
- 职责:存储运维技术日志(`warn/error` 为主)。
76
-
77
- 接口:
78
- - `append(log: RunLogRecord): Promise<void>`
79
- - `listByRun(executionId: string, opts?: { level?: string; limit?: number }): Promise<RunLogRecord[]>`
80
-
81
- ## 9. ConversationStorePort(推荐)
82
-
83
- 职责:会话存在性与会话元信息读取。
84
-
85
- 接口:
86
- - `exists(conversationId: string): Promise<boolean>`
87
- - `get(conversationId: string): Promise<ConversationRecord | null>`
88
-
89
- ## 10. ContextProviderPort
90
-
91
- 职责:加载会话上下文输入。
92
-
93
- 接口:
94
- - `load(conversationId: string): Promise<{ messages: Message[]; systemPrompt?: string; tools?: Tool[] }>`
95
-
96
- ## 11. EventSinkPort
97
-
98
- 职责:发布应用层事件到 CLI。
99
-
100
- 接口:
101
- - `publish(executionId: string, event: CliEvent): Promise<void>`
102
- - `publishToolStream(executionId: string, chunk: { toolCallId: string; chunkType: 'stdout' | 'stderr' | 'progress'; chunk: string }): Promise<void>`
103
-
104
- 说明:
105
- - `tool_stream` 来自 `agent.on('tool_chunk')` 桥接,不是当前 `runStream` 直接产物。
106
-
107
- ## 12. LedgerProviderPort(预留)
108
-
109
- 职责:提供可选幂等账本实现。
110
-
111
- 接口:
112
- - `getLedger(conversationId: string): ToolExecutionLedger`
113
-
114
- 约束:
115
- - 默认返回 `NoopToolExecutionLedger`。
116
- - 生产环境可注入 Redis/DB 账本。
@@ -1,52 +0,0 @@
1
- # 05. 执行编排与状态机
2
-
3
- ## 1. RunOrchestrator 职责
4
-
5
- - 构建单次执行 `AgentInput`。
6
- - 消费 `runStream` 事件并桥接到存储与 CLI。
7
- - 消费 `agent.on('tool_chunk')` 并桥接为 `tool_stream`。
8
- - 处理 `onMessage/onCheckpoint/onCompaction/onError` 回调。
9
- - 维护运行状态机并保证终态收敛。
10
-
11
- ## 2. 执行主流程(事件源优先)
12
-
13
- 1. 创建 `RunRecord(CREATED)`。
14
- 2. 读取上下文与历史消息。
15
- 3. 追加用户输入(写 `events`,并更新消息投影)。
16
- 4. 更新状态为 `RUNNING`。
17
- 5. 调用 `runStream`,逐条消费事件并写 `EventStore`。
18
- 6. 并行消费 `tool_chunk`,归一化为 `tool_stream` 后写 `EventStore`。
19
- 7. 对关键事件更新投影与状态:
20
- - `progress`:更新 `stepIndex`
21
- - `checkpoint`:保存 checkpoint
22
- - `done/error`:先写 `events`,再收敛终态
23
- 8. 终态后停止接收后续事件并发布最终结果。
24
-
25
- ## 3. 桥接规则(按真实内核行为)
26
-
27
- - `runStream event=*`:`EventStore.append` + `EventSink.publish`(当前不含 `tool_stream`)
28
- - `agent.on('tool_chunk')`:归一化为 `tool_stream`,再 `EventStore.append` + `EventSink.publish`
29
- - `onMessage`:补充消息持久化(或校验事件投影一致性)
30
- - `onCheckpoint`:`CheckpointStore.save` + `ExecutionStore.patch(stepIndex)`
31
- - `onCompaction`:仅更新摘要/上下文快照派生层(不重复 append 事件)
32
- - `onError`:记录错误决策,不直接替代终态收敛逻辑
33
-
34
- 说明:
35
- - `progress` 以 `runStream` 事件为准,不依赖 `callbacks.onProgress`。
36
- - 终态收敛遵循“`events` 先写,`runs` 后更新”。
37
-
38
- ## 4. 状态机与终态映射
39
-
40
- - CREATED -> RUNNING
41
- - RUNNING -> COMPLETED(`done.finishReason=stop|max_steps`)
42
- - RUNNING -> FAILED(`error` 且非 `AGENT_ABORTED`)
43
- - RUNNING -> CANCELLED(`error.errorCode=AGENT_ABORTED`)
44
-
45
- 非法转换应拒绝并记录告警日志。
46
-
47
- ## 5. 并发与幂等
48
-
49
- - 同 `executionId` 并发启动应被拒绝或去重。
50
- - `toolExecutionLedger` 是否缓存由注入实现决定。
51
- - 应用层不得假定默认有跨进程幂等能力。
52
- - 事实层(`events`)必须可重放,投影层可重建。
@@ -1,53 +0,0 @@
1
- # 06. CLI 命令与交互规范
2
-
3
- ## 1. 命令集合(Phase 1)
4
-
5
- - `agent run --conversation <id> --message "..."`
6
- - `agent run-status --execution <id>`
7
- - `agent run-list --conversation <id>`
8
-
9
- ## 2. 输出策略
10
-
11
- - `chunk`:实时增量输出文本。
12
- - `reasoning_chunk`:默认隐藏,可通过 flag 打开。
13
- - `tool_stream`:工具 stdout/stderr/progress 流(由 `tool_chunk` 桥接,默认紧凑显示)。
14
- - `tool_call/tool_result`:结构化一行输出。
15
- - `progress`:紧凑模式刷新(可覆盖上行)。
16
- - `compaction`:输出压缩动作摘要(移除条数、stepIndex)。
17
- - `done/error`:尾部输出总结。
18
-
19
- ## 3. 退出码规范
20
-
21
- - `0`:完成(含 `finishReason=max_steps`)。
22
- - `1`:运行失败。
23
- - `130`:用户中断(SIGINT)。
24
-
25
- 终态映射建议:
26
- - `done.stop` -> `COMPLETED` + `0`
27
- - `done.max_steps` -> `COMPLETED` + `0`(提示可 `resume`)
28
- - `error.AGENT_ABORTED` -> `CANCELLED` + `130`
29
- - `error.AGENT_TIMEOUT_BUDGET_EXCEEDED` -> `FAILED(timeout)` + `1`
30
- - `error.AGENT_MAX_RETRIES_REACHED` -> `FAILED(max_retries)` + `1`
31
- - 其他 `error` -> `FAILED(error)` + `1`
32
-
33
- ## 4. 可观测输出字段
34
-
35
- 推荐统一打印:
36
- - `executionId`
37
- - `stepIndex`
38
- - `eventType`
39
- - `toolCallId`(可选)
40
- - `errorCode`(错误时)
41
-
42
- ## 5. 查询命令输出约定(`run-status` / `run-list`)
43
-
44
- - `run-status` 默认输出:`status/terminalReason/stepIndex/createdAt/updatedAt/completedAt`。
45
- - `run-status --verbose` 追加:最近 `execution_steps` 与尾部 `events`。
46
- - `run-status --watch`:按固定间隔刷新,终态后自动退出。
47
- - `run-list` 默认输出:`executionId/status/terminalReason/stepIndex/updatedAt`(按 `updatedAt` 倒序)。
48
- - `run-list --cursor <token>`:分页读取下一页;无下一页时返回空 `next_cursor`。
49
-
50
- 建议错误码:
51
- - 参数错误:`2`
52
- - 资源不存在(例如 execution 不存在):`2`
53
- - 查询成功(含空列表):`0`
@@ -1,52 +0,0 @@
1
- # 07. Phase 1 本地存储设计(SQLite 基线)
2
-
3
- ## 1. 目标
4
-
5
- 在不引入外部基础设施的前提下,让 CLI 应用层可落地并支持:
6
-
7
- - 事件级回放
8
- - 运行状态查询
9
- - 断点与上下文可追溯
10
-
11
- ## 2. 存储位置
12
-
13
- `<workspace>/.agent-v4/agent.db`
14
-
15
- 说明:
16
- - Phase 1 采用单库 SQLite。
17
- - JSON/JSONL 文件存储仅保留为迁移兼容,不作为默认主路径。
18
-
19
- ## 3. 最小必需表(Phase 1)
20
-
21
- - `runs`:执行状态
22
- - `events`:事实事件流(真相源)
23
- - `messages`:消息读模型(投影)
24
- - `tool_ledger`:工具幂等账本(可选注入)
25
- - `checkpoints`:断点恢复索引(推荐独立表;可由 `events` 投影重建)
26
-
27
- 建议同时落:
28
- - `meta`(schema/version/feature flags)
29
-
30
- ## 4. 写入策略
31
-
32
- - 统一事务:`events` 先写,再更新投影表(`messages/runs/...`)。
33
- - append-only:`events` 不更新不删除(仅归档/TTL 清理)。
34
- - 状态更新幂等:重复写同一终态不报错。
35
- - 开启 SQLite 保护:
36
- - `PRAGMA journal_mode=WAL;`
37
- - `PRAGMA busy_timeout=5000;`
38
- - `PRAGMA foreign_keys=ON;`
39
-
40
- ## 5. 读取策略
41
-
42
- - `run-status`:查询 `runs`。
43
- - `run-list`:按 `conversationId + updatedAt` 查询 `runs`。
44
- - 会话重建:
45
- - 优先读 `messages`(快)
46
- - 需要严格审计时读 `events` 并重放(准)
47
-
48
- ## 6. 兼容与升级
49
-
50
- - 使用 `meta` / `schema_migrations` 管理版本。
51
- - 投影可重建:当 `messages` 损坏时从 `events` 重算。
52
- - 后续切换 Redis/DB 时,Port 接口保持不变。
@@ -1,40 +0,0 @@
1
- # 08. 错误与可观测性设计
2
-
3
- ## 1. 错误模型
4
-
5
- 沿用 `agent-v4` 错误契约:
6
- - `errorCode`
7
- - `category`
8
- - `retryable`
9
- - `httpStatus`
10
-
11
- 应用层新增:
12
- - `executionId`
13
- - `stage`(bootstrap/run/callback/persist)
14
-
15
- ## 2. 错误处理原则
16
-
17
- - 内核错误:保留原始错误码,不做语义降级。
18
- - 存储错误:标记 `APP_STORAGE_*`,并尽量不中断 stdout 事件流。
19
- - 回调错误:不传播到用户主流程,但要记录日志。
20
-
21
- ## 3. 日志规范
22
-
23
- 每条日志最小字段:
24
- - `executionId`
25
- - `conversationId`
26
- - `stepIndex`
27
- - `event`
28
- - `latencyMs`
29
- - `errorCode`
30
-
31
- 落库建议:
32
- - 业务事实进入 `events`(真相源)。
33
- - 运维技术日志进入 `run_logs`(可选,默认 `warn/error`)。
34
-
35
- ## 4. 指标建议(后续)
36
-
37
- - `app.run.duration_ms`
38
- - `app.run.error.count`
39
- - `app.store.write.error.count`
40
- - `app.cli.render.delay_ms`