@renxqoo/renx-code 0.0.9 → 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.
- package/README.md +14 -0
- package/bin/renx.cjs +79 -42
- package/bin/renx.exe +0 -0
- package/package.json +10 -28
- package/src/App.tsx +0 -297
- package/src/agent/runtime/event-format.ts +0 -258
- package/src/agent/runtime/model-types.ts +0 -13
- package/src/agent/runtime/runtime.context-usage.test.ts +0 -192
- package/src/agent/runtime/runtime.error-handling.test.ts +0 -235
- package/src/agent/runtime/runtime.simple.test.ts +0 -16
- package/src/agent/runtime/runtime.test.ts +0 -296
- package/src/agent/runtime/runtime.ts +0 -875
- package/src/agent/runtime/runtime.usage-forwarding.test.ts +0 -228
- package/src/agent/runtime/source-modules.test.ts +0 -38
- package/src/agent/runtime/source-modules.ts +0 -370
- package/src/agent/runtime/tool-call-buffer.test.ts +0 -65
- package/src/agent/runtime/tool-call-buffer.ts +0 -60
- package/src/agent/runtime/tool-confirmation.test.ts +0 -56
- package/src/agent/runtime/tool-confirmation.ts +0 -15
- package/src/agent/runtime/types.ts +0 -99
- package/src/commands/slash-commands.test.ts +0 -216
- package/src/commands/slash-commands.ts +0 -64
- package/src/components/chat/assistant-reply.test.tsx +0 -47
- package/src/components/chat/assistant-reply.tsx +0 -136
- package/src/components/chat/assistant-segment.test.ts +0 -99
- package/src/components/chat/assistant-segment.tsx +0 -125
- package/src/components/chat/assistant-tool-group.tsx +0 -900
- package/src/components/chat/code-block.test.tsx +0 -206
- package/src/components/chat/code-block.tsx +0 -313
- package/src/components/chat/prompt-card.tsx +0 -81
- package/src/components/chat/segment-groups.test.ts +0 -52
- package/src/components/chat/segment-groups.ts +0 -106
- package/src/components/chat/turn-item.tsx +0 -39
- package/src/components/conversation-panel.tsx +0 -43
- package/src/components/file-mention-menu.tsx +0 -77
- package/src/components/file-picker-dialog.tsx +0 -206
- package/src/components/footer-hints.tsx +0 -75
- package/src/components/model-picker-dialog.tsx +0 -248
- package/src/components/prompt.tsx +0 -233
- package/src/components/slash-command-menu.tsx +0 -65
- package/src/components/tool-confirm-dialog-content.test.ts +0 -103
- package/src/components/tool-confirm-dialog-content.ts +0 -186
- package/src/components/tool-confirm-dialog.tsx +0 -187
- package/src/components/tool-display-config.ts +0 -119
- package/src/context-usage-regressions.test.ts +0 -26
- package/src/files/attachment-capabilities.test.ts +0 -30
- package/src/files/attachment-capabilities.ts +0 -50
- package/src/files/attachment-content.ts +0 -153
- package/src/files/file-mention-query.test.ts +0 -34
- package/src/files/file-mention-query.ts +0 -32
- package/src/files/prompt-display.ts +0 -13
- package/src/files/types.ts +0 -5
- package/src/files/workspace-files.ts +0 -61
- package/src/hooks/agent-event-handlers.test.ts +0 -207
- package/src/hooks/agent-event-handlers.ts +0 -196
- package/src/hooks/chat-local-replies.fixed.test.ts +0 -119
- package/src/hooks/chat-local-replies.test.ts +0 -153
- package/src/hooks/chat-local-replies.ts +0 -63
- package/src/hooks/turn-updater.test.ts +0 -70
- package/src/hooks/turn-updater.ts +0 -166
- package/src/hooks/use-agent-chat.context.test.ts +0 -10
- package/src/hooks/use-agent-chat.status.test.ts +0 -14
- package/src/hooks/use-agent-chat.test.ts +0 -80
- package/src/hooks/use-agent-chat.ts +0 -621
- package/src/hooks/use-file-mention-menu.ts +0 -196
- package/src/hooks/use-file-picker.ts +0 -185
- package/src/hooks/use-model-picker.ts +0 -196
- package/src/hooks/use-slash-command-menu.ts +0 -154
- package/src/index.tsx +0 -55
- package/src/runtime/clipboard.test.ts +0 -43
- package/src/runtime/clipboard.ts +0 -89
- package/src/runtime/exit.test.ts +0 -177
- package/src/runtime/exit.ts +0 -98
- package/src/runtime/runtime-support.test.ts +0 -31
- package/src/runtime/terminal-theme.test.ts +0 -55
- package/src/runtime/terminal-theme.ts +0 -196
- package/src/types/chat.ts +0 -32
- package/src/types/message-content.ts +0 -48
- package/src/ui/open-code-theme.ts +0 -176
- package/src/ui/opencode-markdown.ts +0 -211
- package/src/ui/theme.simple.test.ts +0 -52
- package/src/ui/theme.test.ts +0 -151
- package/src/ui/theme.ts +0 -152
- package/src/utils/time.test.ts +0 -144
- package/src/utils/time.ts +0 -7
- package/tsconfig.json +0 -30
- package/vendor/agent-root/src/agent/ENTERPRISE_ACCEPTANCE_CHECKLIST.md +0 -95
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.html +0 -1345
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.md +0 -1353
- package/vendor/agent-root/src/agent/ERROR_CONTRACT.md +0 -60
- package/vendor/agent-root/src/agent/TEST_COVERAGE_ANALYSIS.md +0 -278
- package/vendor/agent-root/src/agent/__test__/error-contract.test.ts +0 -72
- package/vendor/agent-root/src/agent/__test__/types.test.ts +0 -137
- package/vendor/agent-root/src/agent/agent/__test__/abort-runtime.test.ts +0 -83
- package/vendor/agent-root/src/agent/agent/__test__/callback-safety.test.ts +0 -34
- package/vendor/agent-root/src/agent/agent/__test__/compaction.test.ts +0 -323
- package/vendor/agent-root/src/agent/agent/__test__/concurrency.test.ts +0 -290
- package/vendor/agent-root/src/agent/agent/__test__/error-normalizer.test.ts +0 -377
- package/vendor/agent-root/src/agent/agent/__test__/error.test.ts +0 -212
- package/vendor/agent-root/src/agent/agent/__test__/fault-injection.test.ts +0 -295
- package/vendor/agent-root/src/agent/agent/__test__/index.test.ts +0 -3607
- package/vendor/agent-root/src/agent/agent/__test__/logger.test.ts +0 -35
- package/vendor/agent-root/src/agent/agent/__test__/message-utils.test.ts +0 -517
- package/vendor/agent-root/src/agent/agent/__test__/telemetry.test.ts +0 -97
- package/vendor/agent-root/src/agent/agent/__test__/timeout-budget.test.ts +0 -479
- package/vendor/agent-root/src/agent/agent/__test__/tool-call-merge.test.ts +0 -80
- package/vendor/agent-root/src/agent/agent/__test__/tool-execution-ledger.test.ts +0 -76
- package/vendor/agent-root/src/agent/agent/__test__/write-buffer.test.ts +0 -173
- package/vendor/agent-root/src/agent/agent/__test__/write-file-session.test.ts +0 -109
- package/vendor/agent-root/src/agent/agent/abort-runtime.ts +0 -71
- package/vendor/agent-root/src/agent/agent/callback-safety.ts +0 -33
- package/vendor/agent-root/src/agent/agent/compaction.ts +0 -291
- package/vendor/agent-root/src/agent/agent/concurrency.ts +0 -103
- package/vendor/agent-root/src/agent/agent/error-normalizer.ts +0 -190
- package/vendor/agent-root/src/agent/agent/error.ts +0 -198
- package/vendor/agent-root/src/agent/agent/index.ts +0 -1772
- package/vendor/agent-root/src/agent/agent/logger.ts +0 -65
- package/vendor/agent-root/src/agent/agent/message-utils.ts +0 -101
- package/vendor/agent-root/src/agent/agent/stream-events.ts +0 -61
- package/vendor/agent-root/src/agent/agent/telemetry.ts +0 -123
- package/vendor/agent-root/src/agent/agent/timeout-budget.ts +0 -227
- package/vendor/agent-root/src/agent/agent/tool-call-merge.ts +0 -111
- package/vendor/agent-root/src/agent/agent/tool-execution-ledger.ts +0 -164
- package/vendor/agent-root/src/agent/agent/write-buffer.ts +0 -188
- package/vendor/agent-root/src/agent/agent/write-file-session.ts +0 -238
- package/vendor/agent-root/src/agent/app/__test__/agent-app-service.test.ts +0 -1053
- package/vendor/agent-root/src/agent/app/__test__/minimal-agent-application.test.ts +0 -158
- package/vendor/agent-root/src/agent/app/__test__/sqlite-agent-app-store.test.ts +0 -437
- package/vendor/agent-root/src/agent/app/agent-app-service.ts +0 -748
- package/vendor/agent-root/src/agent/app/contracts.ts +0 -109
- package/vendor/agent-root/src/agent/app/index.ts +0 -5
- package/vendor/agent-root/src/agent/app/minimal-agent-application.ts +0 -151
- package/vendor/agent-root/src/agent/app/ports.ts +0 -72
- package/vendor/agent-root/src/agent/app/sqlite-agent-app-store.ts +0 -1182
- package/vendor/agent-root/src/agent/app/sqlite-client.ts +0 -177
- package/vendor/agent-root/src/agent/docs/cli-app-layer/00-README.md +0 -36
- package/vendor/agent-root/src/agent/docs/cli-app-layer/01-scope-and-goals.md +0 -33
- package/vendor/agent-root/src/agent/docs/cli-app-layer/02-architecture-overview.md +0 -40
- package/vendor/agent-root/src/agent/docs/cli-app-layer/03-domain-model-and-contracts.md +0 -91
- package/vendor/agent-root/src/agent/docs/cli-app-layer/04-ports-and-interfaces.md +0 -116
- package/vendor/agent-root/src/agent/docs/cli-app-layer/05-run-orchestration-and-state-machine.md +0 -52
- package/vendor/agent-root/src/agent/docs/cli-app-layer/06-cli-commands-and-ux.md +0 -53
- package/vendor/agent-root/src/agent/docs/cli-app-layer/07-storage-design-local.md +0 -52
- package/vendor/agent-root/src/agent/docs/cli-app-layer/08-error-and-observability.md +0 -40
- package/vendor/agent-root/src/agent/docs/cli-app-layer/09-security-and-policy-boundary.md +0 -19
- package/vendor/agent-root/src/agent/docs/cli-app-layer/10-test-plan-and-acceptance.md +0 -28
- package/vendor/agent-root/src/agent/docs/cli-app-layer/11-implementation-phases.md +0 -26
- package/vendor/agent-root/src/agent/docs/cli-app-layer/12-open-questions-and-risks.md +0 -30
- package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md +0 -567
- package/vendor/agent-root/src/agent/docs/cli-app-layer/14-project-flow-mermaid.md +0 -583
- package/vendor/agent-root/src/agent/docs/cli-app-layer/15-openclaw-style-project-blueprint.md +0 -972
- package/vendor/agent-root/src/agent/error-contract.ts +0 -154
- package/vendor/agent-root/src/agent/prompts/system.ts +0 -246
- package/vendor/agent-root/src/agent/prompts/system1.ts +0 -208
- package/vendor/agent-root/src/agent/storage/__test__/file-history-store.test.ts +0 -98
- package/vendor/agent-root/src/agent/storage/file-history-store.ts +0 -313
- package/vendor/agent-root/src/agent/storage/file-storage-config.ts +0 -94
- package/vendor/agent-root/src/agent/storage/file-system.ts +0 -31
- package/vendor/agent-root/src/agent/storage/file-write-service.ts +0 -21
- package/vendor/agent-root/src/agent/tool/__test__/base-tool.test.ts +0 -413
- package/vendor/agent-root/src/agent/tool/__test__/bash-policy.test.ts +0 -356
- package/vendor/agent-root/src/agent/tool/__test__/bash.mocked-coverage.test.ts +0 -375
- package/vendor/agent-root/src/agent/tool/__test__/bash.test.ts +0 -372
- package/vendor/agent-root/src/agent/tool/__test__/error.test.ts +0 -108
- package/vendor/agent-root/src/agent/tool/__test__/file-edit-tool.test.ts +0 -258
- package/vendor/agent-root/src/agent/tool/__test__/file-history-tools.test.ts +0 -121
- package/vendor/agent-root/src/agent/tool/__test__/file-read-tool.test.ts +0 -210
- package/vendor/agent-root/src/agent/tool/__test__/glob.test.ts +0 -139
- package/vendor/agent-root/src/agent/tool/__test__/grep.mocked-coverage.test.ts +0 -456
- package/vendor/agent-root/src/agent/tool/__test__/grep.test.ts +0 -192
- package/vendor/agent-root/src/agent/tool/__test__/lsp.test.ts +0 -300
- package/vendor/agent-root/src/agent/tool/__test__/outside-workspace-confirmation.test.ts +0 -214
- package/vendor/agent-root/src/agent/tool/__test__/path-security.test.ts +0 -336
- package/vendor/agent-root/src/agent/tool/__test__/skill-loader.test.ts +0 -494
- package/vendor/agent-root/src/agent/tool/__test__/skill-parser.test.ts +0 -543
- package/vendor/agent-root/src/agent/tool/__test__/skill-tool.test.ts +0 -172
- package/vendor/agent-root/src/agent/tool/__test__/task-concurrency-and-version.test.ts +0 -116
- package/vendor/agent-root/src/agent/tool/__test__/task-create-get-list-update.test.ts +0 -267
- package/vendor/agent-root/src/agent/tool/__test__/task-create.test.ts +0 -519
- package/vendor/agent-root/src/agent/tool/__test__/task-errors.test.ts +0 -225
- package/vendor/agent-root/src/agent/tool/__test__/task-output-blocking.test.ts +0 -223
- package/vendor/agent-root/src/agent/tool/__test__/task-output.test.ts +0 -184
- package/vendor/agent-root/src/agent/tool/__test__/task-parent-abort.test.ts +0 -287
- package/vendor/agent-root/src/agent/tool/__test__/task-real-runner-adapter.test.ts +0 -190
- package/vendor/agent-root/src/agent/tool/__test__/task-run-lifecycle.test.ts +0 -352
- package/vendor/agent-root/src/agent/tool/__test__/task-store-runner-branches.test.ts +0 -395
- package/vendor/agent-root/src/agent/tool/__test__/task-store.test.ts +0 -391
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config-integration.test.ts +0 -176
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config.test.ts +0 -68
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-core-edges.test.ts +0 -630
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-runtime-edges.test.ts +0 -732
- package/vendor/agent-root/src/agent/tool/__test__/task-types.test.ts +0 -494
- package/vendor/agent-root/src/agent/tool/__test__/task-utils-branches.test.ts +0 -175
- package/vendor/agent-root/src/agent/tool/__test__/tool-manager.test.ts +0 -505
- package/vendor/agent-root/src/agent/tool/__test__/types.test.ts +0 -55
- package/vendor/agent-root/src/agent/tool/__test__/web-fetch.test.ts +0 -244
- package/vendor/agent-root/src/agent/tool/__test__/web-search.test.ts +0 -290
- package/vendor/agent-root/src/agent/tool/__test__/write-file.test.ts +0 -368
- package/vendor/agent-root/src/agent/tool/base-tool.ts +0 -345
- package/vendor/agent-root/src/agent/tool/bash-policy.ts +0 -636
- package/vendor/agent-root/src/agent/tool/bash.ts +0 -688
- package/vendor/agent-root/src/agent/tool/error.ts +0 -131
- package/vendor/agent-root/src/agent/tool/file-edit-tool.ts +0 -264
- package/vendor/agent-root/src/agent/tool/file-history-list.ts +0 -103
- package/vendor/agent-root/src/agent/tool/file-history-restore.ts +0 -149
- package/vendor/agent-root/src/agent/tool/file-read-tool.ts +0 -211
- package/vendor/agent-root/src/agent/tool/glob.ts +0 -171
- package/vendor/agent-root/src/agent/tool/grep.ts +0 -496
- package/vendor/agent-root/src/agent/tool/lsp.ts +0 -481
- package/vendor/agent-root/src/agent/tool/path-security.ts +0 -117
- package/vendor/agent-root/src/agent/tool/search/common.ts +0 -153
- package/vendor/agent-root/src/agent/tool/skill/index.ts +0 -13
- package/vendor/agent-root/src/agent/tool/skill/loader.ts +0 -229
- package/vendor/agent-root/src/agent/tool/skill/parser.ts +0 -124
- package/vendor/agent-root/src/agent/tool/skill/types.ts +0 -27
- package/vendor/agent-root/src/agent/tool/skill-tool.ts +0 -143
- package/vendor/agent-root/src/agent/tool/task-create.ts +0 -186
- package/vendor/agent-root/src/agent/tool/task-errors.ts +0 -42
- package/vendor/agent-root/src/agent/tool/task-get.ts +0 -116
- package/vendor/agent-root/src/agent/tool/task-graph.ts +0 -78
- package/vendor/agent-root/src/agent/tool/task-list.ts +0 -141
- package/vendor/agent-root/src/agent/tool/task-mock-runner-adapter.ts +0 -232
- package/vendor/agent-root/src/agent/tool/task-output.ts +0 -223
- package/vendor/agent-root/src/agent/tool/task-parent-abort.ts +0 -115
- package/vendor/agent-root/src/agent/tool/task-real-runner-adapter.ts +0 -336
- package/vendor/agent-root/src/agent/tool/task-runner-adapter.ts +0 -55
- package/vendor/agent-root/src/agent/tool/task-stop.ts +0 -187
- package/vendor/agent-root/src/agent/tool/task-store.ts +0 -217
- package/vendor/agent-root/src/agent/tool/task-subagent-config.ts +0 -149
- package/vendor/agent-root/src/agent/tool/task-types.ts +0 -264
- package/vendor/agent-root/src/agent/tool/task-update.ts +0 -315
- package/vendor/agent-root/src/agent/tool/task.ts +0 -209
- package/vendor/agent-root/src/agent/tool/tool-manager.ts +0 -361
- package/vendor/agent-root/src/agent/tool/tool-prompts.ts +0 -242
- package/vendor/agent-root/src/agent/tool/types.ts +0 -116
- package/vendor/agent-root/src/agent/tool/web-fetch.ts +0 -227
- package/vendor/agent-root/src/agent/tool/web-search.ts +0 -208
- package/vendor/agent-root/src/agent/tool/write-file.ts +0 -497
- package/vendor/agent-root/src/agent/types.ts +0 -232
- package/vendor/agent-root/src/agent/utils/__tests__/index.test.ts +0 -18
- package/vendor/agent-root/src/agent/utils/__tests__/message-utils.test.ts +0 -610
- package/vendor/agent-root/src/agent/utils/__tests__/message.test.ts +0 -223
- package/vendor/agent-root/src/agent/utils/__tests__/token.test.ts +0 -42
- package/vendor/agent-root/src/agent/utils/index.ts +0 -16
- package/vendor/agent-root/src/agent/utils/message.ts +0 -171
- package/vendor/agent-root/src/agent/utils/token.ts +0 -28
- package/vendor/agent-root/src/config/__tests__/load-config-to-env.test.ts +0 -238
- package/vendor/agent-root/src/config/__tests__/loader.test.ts +0 -361
- package/vendor/agent-root/src/config/__tests__/runtime.test.ts +0 -88
- package/vendor/agent-root/src/config/index.ts +0 -55
- package/vendor/agent-root/src/config/loader.ts +0 -494
- package/vendor/agent-root/src/config/paths.ts +0 -30
- package/vendor/agent-root/src/config/runtime.ts +0 -163
- package/vendor/agent-root/src/config/types.ts +0 -96
- package/vendor/agent-root/src/logger/index.ts +0 -57
- package/vendor/agent-root/src/logger/logger.ts +0 -819
- package/vendor/agent-root/src/logger/types.ts +0 -150
- package/vendor/agent-root/src/providers/__tests__/errors.test.ts +0 -441
- package/vendor/agent-root/src/providers/__tests__/index.test.ts +0 -16
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.options.test.ts +0 -318
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.test.ts +0 -600
- package/vendor/agent-root/src/providers/__tests__/registry.test.ts +0 -523
- package/vendor/agent-root/src/providers/__tests__/responses-adapter.test.ts +0 -298
- package/vendor/agent-root/src/providers/adapters/__tests__/anthropic.test.ts +0 -354
- package/vendor/agent-root/src/providers/adapters/__tests__/kimi.test.ts +0 -58
- package/vendor/agent-root/src/providers/adapters/__tests__/standard.test.ts +0 -261
- package/vendor/agent-root/src/providers/adapters/anthropic.ts +0 -572
- package/vendor/agent-root/src/providers/adapters/base.ts +0 -131
- package/vendor/agent-root/src/providers/adapters/kimi.ts +0 -48
- package/vendor/agent-root/src/providers/adapters/responses.ts +0 -732
- package/vendor/agent-root/src/providers/adapters/standard.ts +0 -120
- package/vendor/agent-root/src/providers/http/__tests__/client.timeout.test.ts +0 -313
- package/vendor/agent-root/src/providers/http/client.ts +0 -289
- package/vendor/agent-root/src/providers/http/stream-parser.ts +0 -109
- package/vendor/agent-root/src/providers/index.ts +0 -76
- package/vendor/agent-root/src/providers/kimi-headers.ts +0 -177
- package/vendor/agent-root/src/providers/openai-compatible.ts +0 -387
- package/vendor/agent-root/src/providers/registry/model-config.ts +0 -477
- package/vendor/agent-root/src/providers/registry/provider-factory.ts +0 -127
- package/vendor/agent-root/src/providers/registry.ts +0 -135
- package/vendor/agent-root/src/providers/types/api.ts +0 -284
- package/vendor/agent-root/src/providers/types/config.ts +0 -58
- package/vendor/agent-root/src/providers/types/errors.ts +0 -323
- package/vendor/agent-root/src/providers/types/index.ts +0 -72
- package/vendor/agent-root/src/providers/types/provider.ts +0 -45
- package/vendor/agent-root/src/providers/types/registry.ts +0 -68
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# 09. 安全边界与策略职责
|
|
2
|
-
|
|
3
|
-
## 1. 责任划分
|
|
4
|
-
|
|
5
|
-
- 内核策略:工具执行前校验(已存在)。
|
|
6
|
-
- 应用层策略:执行身份、会话归属、路径白名单注入、日志脱敏。
|
|
7
|
-
- CLI 层:参数基本校验与用户确认交互。
|
|
8
|
-
|
|
9
|
-
## 2. 应用层必须做的防护
|
|
10
|
-
|
|
11
|
-
- 校验 `conversationId/executionId` 格式。
|
|
12
|
-
- 禁止非法路径进入本地存储根目录之外。
|
|
13
|
-
- 对日志中的敏感字段做掩码(token/key/password)。
|
|
14
|
-
- 避免输出工具原始高危参数到终端。
|
|
15
|
-
|
|
16
|
-
## 3. 当前延期项说明
|
|
17
|
-
|
|
18
|
-
- `bash` 安全默认收敛与重写属于独立 P0 工作流。
|
|
19
|
-
- 本文档仅定义边界,不替代该重构任务。
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# 10. 测试计划与验收
|
|
2
|
-
|
|
3
|
-
## 1. 测试层级
|
|
4
|
-
|
|
5
|
-
- 单元测试:Port/Service/Mapper/状态机。
|
|
6
|
-
- 集成测试:`AgentAppService + LocalAdapter + StatelessAgent(mock)`。
|
|
7
|
-
- 端到端测试:CLI 命令运行与输出断言。
|
|
8
|
-
|
|
9
|
-
## 2. 关键测试点
|
|
10
|
-
|
|
11
|
-
- 执行状态流转正确。
|
|
12
|
-
- `runStream` 事件(含 `progress/compaction/reasoning_chunk`)可落库与转发。
|
|
13
|
-
- `tool_chunk -> tool_stream` 桥接事件可落库与转发。
|
|
14
|
-
- `onMessage` 每条都落库(或投影一致)。
|
|
15
|
-
- `checkpoint` 保存与查询正常。
|
|
16
|
-
- `done/error` 终态满足“先写 `events`,再写 `runs`”。
|
|
17
|
-
- `compaction` 不出现重复事件写入。
|
|
18
|
-
- `max_steps` 输出终止语义。
|
|
19
|
-
- `aborted/timeout/max_retries` 能正确映射终态。
|
|
20
|
-
- 默认无 ledger 缓存行为符合预期。
|
|
21
|
-
- 注入内存 ledger 时可幂等去重。
|
|
22
|
-
|
|
23
|
-
## 3. 验收标准(DoD)
|
|
24
|
-
|
|
25
|
-
- CLI `run` 能完整输出并落盘。
|
|
26
|
-
- `run-status` 与 `run-list` 数据一致。
|
|
27
|
-
- 异常场景下状态可追溯且错误契约完整。
|
|
28
|
-
- 关键路径测试覆盖率达到团队最低线(建议 80%+)。
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# 11. 分阶段实施计划
|
|
2
|
-
|
|
3
|
-
## Phase 1(当前目标)
|
|
4
|
-
|
|
5
|
-
- 建立 Port 接口与 SQLite 本地 Adapter。
|
|
6
|
-
- 实现 `AgentAppService.runForeground`。
|
|
7
|
-
- 实现 `run-status`、`run-list`。
|
|
8
|
-
- 完成单元+集成测试。
|
|
9
|
-
|
|
10
|
-
## Phase 2
|
|
11
|
-
|
|
12
|
-
- 加入 `abortRun` 与 `resumeRun`。
|
|
13
|
-
- 增加事件日志回放能力。
|
|
14
|
-
- 支持 checkpoint 恢复执行。
|
|
15
|
-
|
|
16
|
-
## Phase 3
|
|
17
|
-
|
|
18
|
-
- 后台运行模式(detach/attach)。
|
|
19
|
-
- 多执行并发治理与冲突检测。
|
|
20
|
-
- 提供稳定的 CLI 交互体验。
|
|
21
|
-
|
|
22
|
-
## Phase 4
|
|
23
|
-
|
|
24
|
-
- 引入 Redis/DB Adapter。
|
|
25
|
-
- 提供可选持久化 ledger 实现。
|
|
26
|
-
- 评估跨进程恢复与扩缩容行为。
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# 12. 开放问题与风险登记
|
|
2
|
-
|
|
3
|
-
## 1. 开放问题
|
|
4
|
-
|
|
5
|
-
- `executionId` 由 CLI 生成还是应用层统一生成?(待 ADR 决策)
|
|
6
|
-
- `run` 命令默认是否打印 `reasoning_chunk`?
|
|
7
|
-
- 失败重试策略由 CLI 触发还是应用层自动触发?
|
|
8
|
-
|
|
9
|
-
## 2. 风险
|
|
10
|
-
|
|
11
|
-
- R1:SQLite 并发写锁竞争(`database is locked`)。
|
|
12
|
-
- 缓解:WAL + `busy_timeout` + 短事务 + 失败重试。
|
|
13
|
-
- R2:异常中断导致状态不一致。
|
|
14
|
-
- 缓解:`events` 先写 + 投影可重建 + 启动时一致性修复。
|
|
15
|
-
- R3:接口先行导致实现偏差。
|
|
16
|
-
- 缓解:每阶段落地前跑契约测试。
|
|
17
|
-
- R4:`tool_ledger` pending 记录因进程崩溃长期悬挂。
|
|
18
|
-
- 缓解:增加租约字段(`pending_expires_at_ms`)+ 过期抢占规则 + 巡检清理。
|
|
19
|
-
- R5:`events.seq` 并发分配冲突导致写入失败抖动。
|
|
20
|
-
- 缓解:单事务原子分配 + 唯一约束冲突短重试 + 监控冲突率。
|
|
21
|
-
|
|
22
|
-
## 3. 决策记录建议
|
|
23
|
-
|
|
24
|
-
已决策:
|
|
25
|
-
- Phase 1 本地存储统一 SQLite,JSONL 仅历史兼容。
|
|
26
|
-
|
|
27
|
-
后续每个关键决策都新增 ADR 文档:
|
|
28
|
-
- `adr/ADR-001-storage-choice.md`
|
|
29
|
-
- `adr/ADR-002-execution-id-policy.md`
|
|
30
|
-
- `adr/ADR-003-event-schema-versioning.md`
|
package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md
DELETED
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
# 13. SQLite 设计(参考 OpenClaw)
|
|
2
|
-
|
|
3
|
-
> 本版按 OpenClaw 的真实数据库思路重构:
|
|
4
|
-
> - **运行状态层**:偏事务与可回放(run/execution/event)
|
|
5
|
-
> - **检索索引层**:偏搜索与召回(files/chunks/fts/vec/cache)
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 1. 参考基线(OpenClaw)
|
|
10
|
-
|
|
11
|
-
本设计直接参考以下 OpenClaw 结构与约定:
|
|
12
|
-
|
|
13
|
-
1. `src/memory/memory-schema.ts`
|
|
14
|
-
- `meta` / `files` / `chunks` / `embedding_cache` / `fts5`
|
|
15
|
-
2. `src/memory/manager-sync-ops.ts`
|
|
16
|
-
- `vec0` 向量表(`chunks_vec`)按需启用
|
|
17
|
-
3. `extensions/open-prose/skills/prose/state/sqlite.md`
|
|
18
|
-
- `run` / `execution` / `bindings` 的状态建模思想
|
|
19
|
-
|
|
20
|
-
核心结论:**不要把“运行状态”和“搜索索引”混在一张消息大表里**。
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 2. 总体分层
|
|
25
|
-
|
|
26
|
-
## 2.1 运行状态层(主库)
|
|
27
|
-
|
|
28
|
-
用于事务一致性、审计回放、执行恢复:
|
|
29
|
-
|
|
30
|
-
- `meta`
|
|
31
|
-
- `conversations`
|
|
32
|
-
- `runs`
|
|
33
|
-
- `execution_steps`
|
|
34
|
-
- `events`(append-only 真相源)
|
|
35
|
-
- `messages`(事件投影,便于读)
|
|
36
|
-
- `checkpoints`(恢复锚点,推荐)
|
|
37
|
-
- `summaries`
|
|
38
|
-
- `context_snapshots`
|
|
39
|
-
- `context_snapshot_items`
|
|
40
|
-
- `tool_ledger`
|
|
41
|
-
- `run_logs`(可选,运维技术日志)
|
|
42
|
-
|
|
43
|
-
## 2.2 检索索引层(可与主库同库或分库)
|
|
44
|
-
|
|
45
|
-
用于全文检索、语义检索、缓存复用:
|
|
46
|
-
|
|
47
|
-
- `files`
|
|
48
|
-
- `chunks`
|
|
49
|
-
- `embedding_cache`
|
|
50
|
-
- `chunks_fts`(FTS5 虚表,可选)
|
|
51
|
-
- `chunks_vec`(vec0 虚表,可选)
|
|
52
|
-
|
|
53
|
-
## 2.3 每个表的作用(职责总览)
|
|
54
|
-
|
|
55
|
-
| 表名 | 层级 | 作用 | 谁写入 | 谁读取 |
|
|
56
|
-
|---|---|---|---|---|
|
|
57
|
-
| `meta` | 运行/索引公共 | 保存 schema 版本、开关与索引元信息 | migration / indexer | 启动初始化、迁移器 |
|
|
58
|
-
| `conversations` | 运行状态 | 会话主记录(容器),承载会话级配置与状态 | orchestrator | 会话列表、run 创建逻辑 |
|
|
59
|
-
| `runs` | 运行状态 | 一次执行的生命周期记录(状态机、终止原因、错误) | orchestrator | run-status、恢复、审计 |
|
|
60
|
-
| `execution_steps` | 运行状态 | 运行内每个 step 的阶段状态与耗时 | orchestrator | 调试、性能分析 |
|
|
61
|
-
| `events` | 运行状态(真相源) | append-only 事件流,保留完整事实(含 chunk/progress) | orchestrator/agent bridge | 回放器、投影构建器、审计 |
|
|
62
|
-
| `messages` | 运行状态(投影) | 面向读取优化的消息视图(从 events 投影) | projector | 聊天渲染、上下文拼装 |
|
|
63
|
-
| `checkpoints` | 运行状态(恢复锚点) | 每步恢复点索引,快速恢复执行 | orchestrator | `resume`、恢复诊断 |
|
|
64
|
-
| `summaries` | 运行状态(派生) | 历史区间压缩摘要,降低上下文 token 成本 | compactor | 上下文选择器 |
|
|
65
|
-
| `context_snapshots` | 运行状态(派生) | 记录某步真正喂给模型的上下文快照头 | context builder | 排障、重放、可解释性分析 |
|
|
66
|
-
| `context_snapshot_items` | 运行状态(派生) | 快照条目明细(按顺序引用 message/summary) | context builder | prompt 重建器 |
|
|
67
|
-
| `tool_ledger` | 运行状态 | 工具调用幂等账本,避免副作用重复执行 | tool executor | tool executeOnce 去重逻辑 |
|
|
68
|
-
| `run_logs` | 运行状态(可选) | 技术日志流(warn/error 为主),用于运维排障 | orchestrator / runtime logger | 诊断面板、运维排障 |
|
|
69
|
-
| `files` | 检索索引 | 被索引文档的文件级登记 | indexer | 增量索引器、删除同步器 |
|
|
70
|
-
| `chunks` | 检索索引 | 文本分块主表(检索基础语料) | indexer | 搜索器、召回器 |
|
|
71
|
-
| `embedding_cache` | 检索索引 | embedding 结果缓存,减少重复向量计算 | embedder/indexer | 索引器、召回器 |
|
|
72
|
-
| `chunks_fts` | 检索索引(可选) | 关键词全文检索入口(FTS5) | indexer | keyword / hybrid search |
|
|
73
|
-
| `chunks_vec` | 检索索引(可选) | 向量近邻检索入口(vec0) | indexer | semantic / hybrid search |
|
|
74
|
-
|
|
75
|
-
说明:
|
|
76
|
-
- `events` 是唯一事实流水;`messages`/`summaries`/`context_*` 都是可重建派生层。
|
|
77
|
-
- 检索层表 (`files/chunks/fts/vec/cache`) 与运行状态表解耦,避免互相拖慢。
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## 3. 字段设计(含含义与原因)
|
|
82
|
-
|
|
83
|
-
## 3.1 `meta`(作用:保存系统元信息与版本开关)
|
|
84
|
-
|
|
85
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
86
|
-
|---|---|---|---|
|
|
87
|
-
| `key` | TEXT PK | 配置/版本键 | 兼容迁移,避免硬编码 |
|
|
88
|
-
| `value` | TEXT NOT NULL | 值(字符串/JSON) | 轻量可扩展 |
|
|
89
|
-
|
|
90
|
-
用于记录:
|
|
91
|
-
- `schema_version`
|
|
92
|
-
- `fts_enabled`
|
|
93
|
-
- `vector_enabled`
|
|
94
|
-
- `index_meta_v1`(模型、chunk 参数等)
|
|
95
|
-
|
|
96
|
-
## 3.2 `conversations`(作用:会话主记录与会话级配置容器)
|
|
97
|
-
|
|
98
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
99
|
-
|---|---|---|---|
|
|
100
|
-
| `conversation_id` | TEXT PK | 会话 ID | 全局主键 |
|
|
101
|
-
| `title` | TEXT | 会话名 | 列表展示 |
|
|
102
|
-
| `channel` | TEXT NULL | 来源通道(cli/webhook) | 与 OpenClaw session source 对齐 |
|
|
103
|
-
| `workspace_path` | TEXT NULL | 工作目录 | 多项目隔离 |
|
|
104
|
-
| `status` | TEXT NOT NULL | `active/archived` | 软归档 |
|
|
105
|
-
| `metadata_json` | TEXT NULL | 扩展元数据 | 减少频繁改表 |
|
|
106
|
-
| `created_at_ms` | INTEGER | 创建时间 | 审计 |
|
|
107
|
-
| `updated_at_ms` | INTEGER | 更新时间 | 最近活跃排序 |
|
|
108
|
-
|
|
109
|
-
## 3.3 `runs`(作用:一次运行生命周期状态机)
|
|
110
|
-
|
|
111
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
112
|
-
|---|---|---|---|
|
|
113
|
-
| `run_id` | TEXT PK | 一次运行 ID | 对齐 `executionId` |
|
|
114
|
-
| `conversation_id` | TEXT FK | 所属会话 | 归属关系 |
|
|
115
|
-
| `status` | TEXT NOT NULL | `created/queued/running/completed/failed/cancelled` | 状态机(Phase 1 可不启用 queued) |
|
|
116
|
-
| `terminal_reason` | TEXT NULL | `stop/max_steps/error/timeout/...` | 终止语义清晰 |
|
|
117
|
-
| `max_steps` | INTEGER NULL | 步数预算 | 可回放 |
|
|
118
|
-
| `step_index` | INTEGER NOT NULL | 当前/最终步数 | 恢复定位 |
|
|
119
|
-
| `last_checkpoint_seq` | INTEGER NULL | 最近 checkpoint 的会话序号 | 快速恢复锚点 |
|
|
120
|
-
| `request_json` | TEXT NULL | 入参快照(systemPrompt/tools/config) | 完整复现 |
|
|
121
|
-
| `error_json` | TEXT NULL | 错误包(code/category/message/httpStatus) | 对齐错误契约 |
|
|
122
|
-
| `created_at_ms` | INTEGER | 创建时间 | 生命周期 |
|
|
123
|
-
| `started_at_ms` | INTEGER NULL | 启动时间 | 性能分析 |
|
|
124
|
-
| `completed_at_ms` | INTEGER NULL | 结束时间 | 终态追踪 |
|
|
125
|
-
| `updated_at_ms` | INTEGER | 更新时间 | 列表查询 |
|
|
126
|
-
|
|
127
|
-
> 参考 OpenClaw 的 `run + execution` 分层:run 是一次完整运行容器。
|
|
128
|
-
|
|
129
|
-
## 3.4 `execution_steps`(作用:记录 run 内每步阶段状态与耗时)
|
|
130
|
-
|
|
131
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
132
|
-
|---|---|---|---|
|
|
133
|
-
| `run_id` | TEXT FK | 所属 run | 父子关系 |
|
|
134
|
-
| `step_index` | INTEGER | 第几步 | 主定位键 |
|
|
135
|
-
| `status` | TEXT NOT NULL | `pending/executing/completed/failed/skipped` | 类似 OpenClaw `execution.status` |
|
|
136
|
-
| `stage` | TEXT NULL | `llm/tool/checkpoint` | 分阶段追踪 |
|
|
137
|
-
| `started_at_ms` | INTEGER NULL | 开始时间 | 统计 |
|
|
138
|
-
| `completed_at_ms` | INTEGER NULL | 结束时间 | 统计 |
|
|
139
|
-
| `error_json` | TEXT NULL | 步骤错误 | 精细排障 |
|
|
140
|
-
| `metadata_json` | TEXT NULL | 附加信息 | 保持弹性 |
|
|
141
|
-
|
|
142
|
-
主键建议:`PRIMARY KEY(run_id, step_index)`。
|
|
143
|
-
|
|
144
|
-
## 3.5 `events`(作用:append-only 事实事件流,系统真相源)
|
|
145
|
-
|
|
146
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
147
|
-
|---|---|---|---|
|
|
148
|
-
| `event_id` | INTEGER PK AUTOINCREMENT | 事件流水号 | 严格时序 |
|
|
149
|
-
| `conversation_id` | TEXT FK | 所属会话 | 会话回放 |
|
|
150
|
-
| `run_id` | TEXT FK NULL | 所属 run | 运行回放 |
|
|
151
|
-
| `seq` | INTEGER NOT NULL | 会话内序号 | 业务顺序稳定 |
|
|
152
|
-
| `event_type` | TEXT NOT NULL | `user_message/assistant_message/chunk/reasoning_chunk/tool_call/tool_result/tool_stream/progress/checkpoint/compaction/done/error/...` | 统一事件模型(含应用层派生事件) |
|
|
153
|
-
| `payload_json` | TEXT NOT NULL | 原始事件负载 | 兼容字段演进 |
|
|
154
|
-
| `created_at_ms` | INTEGER NOT NULL | 事件时间 | 审计 |
|
|
155
|
-
|
|
156
|
-
为什么要 `events`:
|
|
157
|
-
- 完整保留事实,不丢增量信息(chunk/progress)
|
|
158
|
-
- 任意时间可重建 `messages`、`snapshots` 等投影
|
|
159
|
-
- 与 OpenClaw transcript-first 思路一致
|
|
160
|
-
|
|
161
|
-
## 3.6 `messages`(作用:从事件投影出的消息读模型)
|
|
162
|
-
|
|
163
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
164
|
-
|---|---|---|---|
|
|
165
|
-
| `message_id` | TEXT PK | 消息 ID | 快速随机访问 |
|
|
166
|
-
| `conversation_id` | TEXT FK | 所属会话 | 主查询维度 |
|
|
167
|
-
| `run_id` | TEXT FK NULL | 来源 run | 定位执行 |
|
|
168
|
-
| `seq` | INTEGER NOT NULL | 顺序 | 与 events 对齐 |
|
|
169
|
-
| `step_index` | INTEGER NULL | 所属 step | 排障 |
|
|
170
|
-
| `role` | TEXT NOT NULL | `system/user/assistant/tool` | 兼容 provider |
|
|
171
|
-
| `type` | TEXT NOT NULL | `assistant-text/tool-call/tool-result/summary/...` | UI 与逻辑分流 |
|
|
172
|
-
| `content_json` | TEXT NOT NULL | 内容(文本/多模态) | 对齐 `Message.content` |
|
|
173
|
-
| `reasoning_content` | TEXT NULL | 思考流 | 对齐模型输出 |
|
|
174
|
-
| `tool_call_id` | TEXT NULL | 工具调用关联 | tool 配对 |
|
|
175
|
-
| `tool_calls_json` | TEXT NULL | assistant 工具调用数组 | 多工具场景 |
|
|
176
|
-
| `usage_json` | TEXT NULL | token 使用明细 | 保留原始形态 |
|
|
177
|
-
| `metadata_json` | TEXT NULL | 扩展字段 | 兼容 |
|
|
178
|
-
| `created_at_ms` | INTEGER NOT NULL | 创建时间 | 排序 |
|
|
179
|
-
|
|
180
|
-
> 规则:`messages` 来自事件投影,可重建;不作为唯一真相源。
|
|
181
|
-
|
|
182
|
-
## 3.7 `summaries`(作用:历史区间压缩摘要)
|
|
183
|
-
|
|
184
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
185
|
-
|---|---|---|---|
|
|
186
|
-
| `summary_id` | TEXT PK | 摘要 ID | 可引用 |
|
|
187
|
-
| `conversation_id` | TEXT FK | 所属会话 | 查询维度 |
|
|
188
|
-
| `run_id` | TEXT FK NULL | 生成 run | 来源追踪 |
|
|
189
|
-
| `seq_from` | INTEGER NOT NULL | 覆盖起点 | 区间定位 |
|
|
190
|
-
| `seq_to` | INTEGER NOT NULL | 覆盖终点 | 区间定位 |
|
|
191
|
-
| `version` | INTEGER NOT NULL | 摘要策略版本 | 升级不覆盖历史 |
|
|
192
|
-
| `model` | TEXT NULL | 生成模型 | 质量归因 |
|
|
193
|
-
| `summary_text` | TEXT NOT NULL | 摘要正文 | 上下文拼装 |
|
|
194
|
-
| `token_stats_json` | TEXT NULL | token 统计 | 成本分析 |
|
|
195
|
-
| `metadata_json` | TEXT NULL | 扩展字段 | 策略演进 |
|
|
196
|
-
| `created_at_ms` | INTEGER NOT NULL | 创建时间 | 排序 |
|
|
197
|
-
|
|
198
|
-
唯一约束:`UNIQUE(conversation_id, seq_from, seq_to, version)`。
|
|
199
|
-
|
|
200
|
-
## 3.8 `context_snapshots`(作用:记录某步真实喂给模型的上下文快照头)
|
|
201
|
-
|
|
202
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
203
|
-
|---|---|---|---|
|
|
204
|
-
| `snapshot_id` | TEXT PK | 快照 ID | 主键 |
|
|
205
|
-
| `run_id` | TEXT FK | 所属 run | 回放维度 |
|
|
206
|
-
| `step_index` | INTEGER NOT NULL | 所属 step | 一步一快照 |
|
|
207
|
-
| `phase` | TEXT NOT NULL | `pre_llm` 等 | 多阶段扩展 |
|
|
208
|
-
| `strategy` | TEXT NULL | 选择策略 | 可解释性 |
|
|
209
|
-
| `token_budget` | INTEGER NULL | 预算 | 裁剪依据 |
|
|
210
|
-
| `token_used` | INTEGER NULL | 实际使用 | 预算命中 |
|
|
211
|
-
| `metadata_json` | TEXT NULL | 扩展 | 演进 |
|
|
212
|
-
| `created_at_ms` | INTEGER NOT NULL | 时间 | 审计 |
|
|
213
|
-
|
|
214
|
-
## 3.9 `context_snapshot_items`(作用:记录快照内按顺序引用的 message/summary 条目)
|
|
215
|
-
|
|
216
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
217
|
-
|---|---|---|---|
|
|
218
|
-
| `snapshot_id` | TEXT FK | 所属快照 | 父键 |
|
|
219
|
-
| `ordinal` | INTEGER NOT NULL | 顺序 | 保证 prompt 顺序 |
|
|
220
|
-
| `source_type` | TEXT NOT NULL | `message/summary` | 来源类型 |
|
|
221
|
-
| `source_id` | TEXT NOT NULL | `message_id` 或 `summary_id` | 统一引用键 |
|
|
222
|
-
| `seq_from` | INTEGER NULL | 覆盖区间起点 | 快速过滤 |
|
|
223
|
-
| `seq_to` | INTEGER NULL | 覆盖区间终点 | 快速过滤 |
|
|
224
|
-
| `token_estimate` | INTEGER NULL | token 估算 | 解释裁剪 |
|
|
225
|
-
| `metadata_json` | TEXT NULL | 扩展信息 | 兼容 |
|
|
226
|
-
|
|
227
|
-
主键:`PRIMARY KEY(snapshot_id, ordinal)`。
|
|
228
|
-
|
|
229
|
-
## 3.10 `tool_ledger`(作用:工具调用幂等账本,防副作用重复执行)
|
|
230
|
-
|
|
231
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
232
|
-
|---|---|---|---|
|
|
233
|
-
| `run_id` | TEXT FK | 所属 run | 幂等范围 |
|
|
234
|
-
| `tool_call_id` | TEXT | 工具调用 ID | 幂等键 |
|
|
235
|
-
| `status` | TEXT NOT NULL | `pending/success/failed` | 支持并发占位与结果态 |
|
|
236
|
-
| `lease_owner` | TEXT NULL | 当前占位执行者 | 崩溃恢复与诊断 |
|
|
237
|
-
| `pending_expires_at_ms` | INTEGER NULL | pending 过期时间 | 防止永久 pending |
|
|
238
|
-
| `result_json` | TEXT NULL | 输出与错误信息 | `pending` 阶段可为空,完成后回放复用 |
|
|
239
|
-
| `attempt_count` | INTEGER NOT NULL | 执行尝试次数 | 排障与重试分析 |
|
|
240
|
-
| `recorded_at_ms` | INTEGER NOT NULL | 创建时间 | 审计 |
|
|
241
|
-
| `updated_at_ms` | INTEGER NOT NULL | 更新时间 | 过期判定与清理 |
|
|
242
|
-
|
|
243
|
-
主键:`PRIMARY KEY(run_id, tool_call_id)`。
|
|
244
|
-
用途:与 `executeOnce` 语义对齐,防重放副作用。
|
|
245
|
-
|
|
246
|
-
推荐写入顺序:
|
|
247
|
-
1. 事务内 `INSERT ... status=pending, pending_expires_at_ms=now+ttl` 抢占执行权(主键冲突即并发命中)。
|
|
248
|
-
2. 赢家执行副作用工具。
|
|
249
|
-
3. 事务内 `UPDATE ... status=success/failed, result_json=..., updated_at_ms=now`。
|
|
250
|
-
4. 竞争方读取已落账本结果;若命中过期 pending 可按租约规则抢占。
|
|
251
|
-
|
|
252
|
-
## 3.11 `checkpoints`(作用:恢复锚点索引,降低 resume 成本)
|
|
253
|
-
|
|
254
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
255
|
-
|---|---|---|---|
|
|
256
|
-
| `run_id` | TEXT FK | 所属 run | 恢复定位 |
|
|
257
|
-
| `step_index` | INTEGER NOT NULL | 所属 step | 一步一断点 |
|
|
258
|
-
| `seq` | INTEGER NOT NULL | 对应事件序号 | 与 events 对齐 |
|
|
259
|
-
| `last_message_id` | TEXT NULL | 最近消息 ID | 快速恢复上下文 |
|
|
260
|
-
| `checkpoint_json` | TEXT NULL | 扩展载荷 | 兼容演进 |
|
|
261
|
-
| `created_at_ms` | INTEGER NOT NULL | 创建时间 | 审计 |
|
|
262
|
-
|
|
263
|
-
主键建议:`PRIMARY KEY(run_id, step_index)`。
|
|
264
|
-
|
|
265
|
-
## 3.12 `run_logs`(作用:记录运维技术日志,补充 events 之外的诊断信息,可选)
|
|
266
|
-
|
|
267
|
-
| 字段 | 类型 | 含义 | 为什么这么存 |
|
|
268
|
-
|---|---|---|---|
|
|
269
|
-
| `id` | INTEGER PK AUTOINCREMENT | 日志流水号 | 稳定时序与分页 |
|
|
270
|
-
| `run_id` | TEXT FK | 所属 run | 快速定位某次执行 |
|
|
271
|
-
| `step_index` | INTEGER NULL | 所属 step | 步骤级定位 |
|
|
272
|
-
| `level` | TEXT NOT NULL | `debug/info/warn/error` | 标准日志等级 |
|
|
273
|
-
| `code` | TEXT NULL | 机器可读错误/告警码 | 聚合分析与告警 |
|
|
274
|
-
| `source` | TEXT NULL | `agent/tool/runtime/store` | 日志来源分类 |
|
|
275
|
-
| `message` | TEXT NOT NULL | 日志正文 | 人类可读排障 |
|
|
276
|
-
| `context_json` | TEXT NULL | 上下文对象 | 保存结构化诊断细节 |
|
|
277
|
-
| `created_at_ms` | INTEGER NOT NULL | 记录时间 | 审计与排序 |
|
|
278
|
-
|
|
279
|
-
建议:
|
|
280
|
-
- 默认只落 `warn/error`,`info/debug` 通过开关采样,避免本地库膨胀。
|
|
281
|
-
- `run_logs` 不是业务真相源,不能替代 `events`。
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## 4. 检索索引层(OpenClaw 同款)
|
|
286
|
-
|
|
287
|
-
## 4.1 `files`(作用:被索引文档的文件级登记)
|
|
288
|
-
|
|
289
|
-
| 字段 | 类型 | 含义 |
|
|
290
|
-
|---|---|---|
|
|
291
|
-
| `path` | TEXT PK | 文档路径(可虚拟路径) |
|
|
292
|
-
| `source` | TEXT NOT NULL | 来源(`memory/session/conversation`) |
|
|
293
|
-
| `hash` | TEXT NOT NULL | 文档哈希 |
|
|
294
|
-
| `mtime` | INTEGER NOT NULL | 修改时间 |
|
|
295
|
-
| `size` | INTEGER NOT NULL | 字节大小 |
|
|
296
|
-
|
|
297
|
-
## 4.2 `chunks`(作用:文本分块主表,检索语料核心)
|
|
298
|
-
|
|
299
|
-
| 字段 | 类型 | 含义 |
|
|
300
|
-
|---|---|---|
|
|
301
|
-
| `id` | TEXT PK | chunk ID |
|
|
302
|
-
| `path` | TEXT NOT NULL | 所属 file path |
|
|
303
|
-
| `source` | TEXT NOT NULL | 来源 |
|
|
304
|
-
| `start_line` | INTEGER NOT NULL | 起始行/段 |
|
|
305
|
-
| `end_line` | INTEGER NOT NULL | 结束行/段 |
|
|
306
|
-
| `hash` | TEXT NOT NULL | chunk 哈希 |
|
|
307
|
-
| `model` | TEXT NOT NULL | embedding 模型 |
|
|
308
|
-
| `text` | TEXT NOT NULL | chunk 文本 |
|
|
309
|
-
| `embedding` | TEXT NOT NULL | embedding(JSON) |
|
|
310
|
-
| `updated_at` | INTEGER NOT NULL | 更新时间 |
|
|
311
|
-
|
|
312
|
-
> 对会话可用“伪路径”映射:`conversation/{conversation_id}/seq-{from}-{to}`。
|
|
313
|
-
|
|
314
|
-
## 4.3 `embedding_cache`(作用:向量计算缓存,降低重复 embedding 成本)
|
|
315
|
-
|
|
316
|
-
| 字段 | 类型 | 含义 |
|
|
317
|
-
|---|---|---|
|
|
318
|
-
| `provider` | TEXT NOT NULL | 提供商 |
|
|
319
|
-
| `model` | TEXT NOT NULL | 模型 |
|
|
320
|
-
| `provider_key` | TEXT NOT NULL | 租户/账号维度键 |
|
|
321
|
-
| `hash` | TEXT NOT NULL | 文本哈希 |
|
|
322
|
-
| `embedding` | TEXT NOT NULL | 向量(JSON/BLOB) |
|
|
323
|
-
| `dims` | INTEGER NULL | 维度 |
|
|
324
|
-
| `updated_at` | INTEGER NOT NULL | 更新时间 |
|
|
325
|
-
|
|
326
|
-
主键:`PRIMARY KEY(provider, model, provider_key, hash)`。
|
|
327
|
-
|
|
328
|
-
## 4.4 `chunks_fts`(作用:关键词全文检索入口,可选)
|
|
329
|
-
|
|
330
|
-
FTS5 虚表字段建议:
|
|
331
|
-
- `text`
|
|
332
|
-
- `id UNINDEXED`
|
|
333
|
-
- `path UNINDEXED`
|
|
334
|
-
- `source UNINDEXED`
|
|
335
|
-
- `model UNINDEXED`
|
|
336
|
-
- `start_line UNINDEXED`
|
|
337
|
-
- `end_line UNINDEXED`
|
|
338
|
-
|
|
339
|
-
## 4.5 `chunks_vec`(作用:向量近邻检索入口,可选)
|
|
340
|
-
|
|
341
|
-
`vec0` 虚表示例:
|
|
342
|
-
- `id TEXT PRIMARY KEY`
|
|
343
|
-
- `embedding FLOAT[dim]`
|
|
344
|
-
|
|
345
|
-
---
|
|
346
|
-
|
|
347
|
-
## 5. 关键约束与索引
|
|
348
|
-
|
|
349
|
-
运行层:
|
|
350
|
-
|
|
351
|
-
1. `events`:`UNIQUE(conversation_id, seq)`
|
|
352
|
-
2. `messages`:`UNIQUE(conversation_id, seq)`
|
|
353
|
-
3. `execution_steps`:`PRIMARY KEY(run_id, step_index)`
|
|
354
|
-
4. `checkpoints`:`PRIMARY KEY(run_id, step_index)`
|
|
355
|
-
5. `context_snapshots`:`UNIQUE(run_id, step_index, phase)`
|
|
356
|
-
6. `tool_ledger`:`PRIMARY KEY(run_id, tool_call_id)` + `INDEX(status, pending_expires_at_ms)`
|
|
357
|
-
7. `runs`:`INDEX(conversation_id, updated_at_ms DESC)` + `INDEX(conversation_id, status, updated_at_ms DESC)`
|
|
358
|
-
8. `events`:`INDEX(run_id, event_id)`
|
|
359
|
-
9. `run_logs`:`INDEX(run_id, created_at_ms)` + `INDEX(level, created_at_ms)`
|
|
360
|
-
|
|
361
|
-
检索层:
|
|
362
|
-
|
|
363
|
-
1. `idx_chunks_path` on `chunks(path)`
|
|
364
|
-
2. `idx_chunks_source` on `chunks(source)`
|
|
365
|
-
3. `idx_embedding_cache_updated_at` on `embedding_cache(updated_at)`
|
|
366
|
-
|
|
367
|
-
SQLite pragma 建议:
|
|
368
|
-
- `PRAGMA journal_mode=WAL;`
|
|
369
|
-
- `PRAGMA synchronous=NORMAL;`
|
|
370
|
-
- `PRAGMA busy_timeout=5000;`
|
|
371
|
-
- `PRAGMA foreign_keys=ON;`
|
|
372
|
-
|
|
373
|
-
---
|
|
374
|
-
|
|
375
|
-
## 6. 为什么这版比“单消息大表”更稳
|
|
376
|
-
|
|
377
|
-
1. **真相源明确**:`events` append-only,任何投影坏了都能重建。
|
|
378
|
-
2. **状态与检索解耦**:运行事务不被 FTS/向量索引拖慢。
|
|
379
|
-
3. **向 OpenClaw 对齐**:索引层直接复用 `files/chunks/fts/cache/vec` 习惯。
|
|
380
|
-
4. **可演进**:字段细节更多放 `*_json`,避免频繁迁移。
|
|
381
|
-
5. **无状态友好**:进程重启后,run/context/ledger 都能从库恢复。
|
|
382
|
-
|
|
383
|
-
---
|
|
384
|
-
|
|
385
|
-
## 7. 实施顺序(建议)
|
|
386
|
-
|
|
387
|
-
1. 先落运行层最小集:`meta/conversations/runs/events/messages/tool_ledger`
|
|
388
|
-
2. 再补恢复与步骤层:`execution_steps/checkpoints`
|
|
389
|
-
3. 再补上下文层:`summaries/context_snapshots/context_snapshot_items`
|
|
390
|
-
4. 最后接检索层:`files/chunks/embedding_cache/chunks_fts/chunks_vec`
|
|
391
|
-
5. 可选加运维日志:`run_logs`(需要技术排障能力时启用)
|
|
392
|
-
|
|
393
|
-
这样可以先保证 CLI 可跑,再逐步增加压缩与检索能力。
|
|
394
|
-
|
|
395
|
-
---
|
|
396
|
-
|
|
397
|
-
## 8. Mermaid:表关系图(ER)
|
|
398
|
-
|
|
399
|
-
```mermaid
|
|
400
|
-
erDiagram
|
|
401
|
-
CONVERSATIONS ||--o{ RUNS : "has"
|
|
402
|
-
RUNS ||--o{ EXECUTION_STEPS : "contains"
|
|
403
|
-
CONVERSATIONS ||--o{ EVENTS : "streams"
|
|
404
|
-
RUNS ||--o{ EVENTS : "emits"
|
|
405
|
-
CONVERSATIONS ||--o{ MESSAGES : "projects"
|
|
406
|
-
RUNS ||--o{ MESSAGES : "produces"
|
|
407
|
-
RUNS ||--o{ CHECKPOINTS : "anchors"
|
|
408
|
-
CONVERSATIONS ||--o{ SUMMARIES : "compresses"
|
|
409
|
-
RUNS ||--o{ SUMMARIES : "generates"
|
|
410
|
-
RUNS ||--o{ CONTEXT_SNAPSHOTS : "captures"
|
|
411
|
-
CONTEXT_SNAPSHOTS ||--o{ CONTEXT_SNAPSHOT_ITEMS : "includes"
|
|
412
|
-
RUNS ||--o{ TOOL_LEDGER : "idempotency"
|
|
413
|
-
RUNS ||--o{ RUN_LOGS : "ops_logs"
|
|
414
|
-
|
|
415
|
-
FILES ||--o{ CHUNKS : "has"
|
|
416
|
-
CHUNKS ||--o| CHUNKS_FTS : "indexed_by_fts"
|
|
417
|
-
CHUNKS ||--o| CHUNKS_VEC : "indexed_by_vec"
|
|
418
|
-
EMBEDDING_CACHE ||..|| CHUNKS : "reuse_embeddings"
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
说明:
|
|
422
|
-
- 运行状态主链路是:`conversations -> runs -> execution_steps`。
|
|
423
|
-
- 真相源是 `events`;`messages` 是事件投影。
|
|
424
|
-
- 上下文构造链路是:`summaries + messages -> context_snapshots -> context_snapshot_items`。
|
|
425
|
-
- 检索链路与运行链路解耦:`files/chunks/fts/vec/cache`。
|
|
426
|
-
|
|
427
|
-
## 8.1 `events.seq` 原子分配规则(必须)
|
|
428
|
-
|
|
429
|
-
- 必须在单事务内完成“分配 seq + 插入 events”。
|
|
430
|
-
- 推荐模式:`BEGIN IMMEDIATE` + `INSERT ... SELECT COALESCE(MAX(seq),0)+1 ... WHERE conversation_id=?`。
|
|
431
|
-
- 依赖 `UNIQUE(conversation_id, seq)` 兜底;冲突时短重试。
|
|
432
|
-
- 禁止应用层先 `SELECT nextSeq` 再 `INSERT` 的两段式流程。
|
|
433
|
-
|
|
434
|
-
---
|
|
435
|
-
|
|
436
|
-
## 9. Mermaid:运行时“什么时候写什么表”
|
|
437
|
-
|
|
438
|
-
```mermaid
|
|
439
|
-
flowchart TD
|
|
440
|
-
A["Start Run"] --> A1["INSERT runs(status=created)"]
|
|
441
|
-
A1 --> A2["INSERT execution_steps(step=1,status=pending)"]
|
|
442
|
-
A2 --> B["User Input Arrives"]
|
|
443
|
-
B --> B1["INSERT events(event_type=user_message,payload_json)"]
|
|
444
|
-
B1 --> B2["UPSERT messages(projected user message)"]
|
|
445
|
-
B2 --> C["Run Enters running"]
|
|
446
|
-
C --> C1["UPDATE runs(status=running,started_at_ms)"]
|
|
447
|
-
C1 --> C1L["IF info sampling enabled THEN INSERT run_logs(level=info,source=runtime,message='run started')"]
|
|
448
|
-
C1L --> D
|
|
449
|
-
D --> D1["INSERT context_snapshots(run_id,step_index,phase=pre_llm)"]
|
|
450
|
-
D1 --> D2["INSERT context_snapshot_items(ordered refs: message/summary)"]
|
|
451
|
-
D2 --> E{"LLM Streaming"}
|
|
452
|
-
E -->|"chunk/reasoning/tool_call/progress"| E1["INSERT events(event_type=chunk/progress/tool_call, payload_json)"]
|
|
453
|
-
E1 --> E
|
|
454
|
-
E -->|"assistant message complete"| E2["INSERT events(event_type=assistant_message,payload_json)"]
|
|
455
|
-
E2 --> E3["UPSERT messages(projected assistant message)"]
|
|
456
|
-
E3 --> F{"Has Tool Calls?"}
|
|
457
|
-
F -->|"Yes"| G["Tool Execute"]
|
|
458
|
-
G --> G1["BEGIN IMMEDIATE + INSERT tool_ledger(status=pending,pending_expires_at_ms)"]
|
|
459
|
-
G1 --> G2{"Insert Success?"}
|
|
460
|
-
G2 -->|"Yes (winner)"| G3["Execute tool then UPDATE tool_ledger(status,result_json,updated_at_ms)"]
|
|
461
|
-
G2 -->|"No (conflict)"| G4["SELECT/POLL tool_ledger;pending 过期可抢占"]
|
|
462
|
-
G3 --> G5["INSERT events(event_type=tool_result,payload_json)"]
|
|
463
|
-
G3 --> G3L["INSERT run_logs(level=warn/error when needed)"]
|
|
464
|
-
G3L --> G5
|
|
465
|
-
G4 --> G5
|
|
466
|
-
G5 --> G6["UPSERT messages(projected tool result)"]
|
|
467
|
-
G6 --> H["INSERT checkpoints(step_index,seq,last_message_id)"]
|
|
468
|
-
H --> H1["UPDATE runs(step_index,last_checkpoint_seq)"]
|
|
469
|
-
H1 --> I["UPDATE execution_steps(status=completed)"]
|
|
470
|
-
I --> I0{"Need Compaction?"}
|
|
471
|
-
I0 -->|"Yes"| I1["INSERT summaries(seq_from,seq_to,version,summary_text)"]
|
|
472
|
-
I1 --> I2["INSERT events(event_type=compaction,payload_json)"]
|
|
473
|
-
I0 -->|"No"| J["Next Step"]
|
|
474
|
-
I2 --> J
|
|
475
|
-
J --> K{"Terminal?"}
|
|
476
|
-
K -->|"No"| A2
|
|
477
|
-
K -->|"done/error/max_steps/abort"| L["INSERT events(event_type=done/error,payload_json)"]
|
|
478
|
-
L --> L1["INSERT run_logs(level=error or sampled info,source=runtime,message='run terminal')"]
|
|
479
|
-
L1 --> M["UPDATE runs(status,terminal_reason,error_json,completed_at_ms)"]
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
---
|
|
483
|
-
|
|
484
|
-
## 10. 触发点 -> 落表示例(速查)
|
|
485
|
-
|
|
486
|
-
| 触发点 | 必写表 | 可选写表 |
|
|
487
|
-
|---|---|---|
|
|
488
|
-
| 创建运行 | `runs` | `execution_steps` |
|
|
489
|
-
| 用户消息进入 | `events` | `messages` |
|
|
490
|
-
| 每次 LLM 调用前 | `context_snapshots`, `context_snapshot_items` | - |
|
|
491
|
-
| 流式 chunk/reasoning/tool_call/progress/tool_stream | `events` | - |
|
|
492
|
-
| assistant/tool 最终消息 | `events`, `messages` | `execution_steps` |
|
|
493
|
-
| 工具执行(防重) | `tool_ledger` | `events`, `messages` |
|
|
494
|
-
| step 断点落盘 | `checkpoints`, `runs` | `execution_steps` |
|
|
495
|
-
| 运行中的技术告警/错误 | `run_logs` | `events`(若需对外可见) |
|
|
496
|
-
| 触发压缩 | `summaries`, `events` | `context_snapshots*`(下一步重建时) |
|
|
497
|
-
| 运行终止 | `events`, `runs` | `execution_steps` |
|
|
498
|
-
| 建检索索引(异步) | `files`, `chunks` | `chunks_fts`, `chunks_vec`, `embedding_cache` |
|
|
499
|
-
|
|
500
|
-
---
|
|
501
|
-
|
|
502
|
-
## 11. `run_logs` 可执行 DDL 与使用建议
|
|
503
|
-
|
|
504
|
-
## 11.1 建表与索引(SQL)
|
|
505
|
-
|
|
506
|
-
```sql
|
|
507
|
-
CREATE TABLE IF NOT EXISTS run_logs (
|
|
508
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
509
|
-
run_id TEXT NOT NULL,
|
|
510
|
-
step_index INTEGER,
|
|
511
|
-
level TEXT NOT NULL CHECK(level IN ('debug', 'info', 'warn', 'error')),
|
|
512
|
-
code TEXT,
|
|
513
|
-
source TEXT,
|
|
514
|
-
message TEXT NOT NULL,
|
|
515
|
-
context_json TEXT,
|
|
516
|
-
created_at_ms INTEGER NOT NULL,
|
|
517
|
-
FOREIGN KEY (run_id) REFERENCES runs(run_id) ON DELETE CASCADE
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
CREATE INDEX IF NOT EXISTS idx_run_logs_run_created
|
|
521
|
-
ON run_logs(run_id, created_at_ms DESC);
|
|
522
|
-
|
|
523
|
-
CREATE INDEX IF NOT EXISTS idx_run_logs_level_created
|
|
524
|
-
ON run_logs(level, created_at_ms DESC);
|
|
525
|
-
|
|
526
|
-
CREATE INDEX IF NOT EXISTS idx_run_logs_code_created
|
|
527
|
-
ON run_logs(code, created_at_ms DESC);
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
## 11.2 写入策略(建议)
|
|
531
|
-
|
|
532
|
-
- 默认只写 `warn/error`。
|
|
533
|
-
- `info/debug` 通过配置开关采样写入(如 `runLogLevel=warn`)。
|
|
534
|
-
- `context_json` 仅放结构化诊断信息,避免把大文本重复写入(大文本仍走 `events/messages`)。
|
|
535
|
-
|
|
536
|
-
## 11.3 写入示例(SQL)
|
|
537
|
-
|
|
538
|
-
```sql
|
|
539
|
-
-- 运行开始(仅在开启 info 采样时)
|
|
540
|
-
INSERT INTO run_logs(run_id, step_index, level, code, source, message, context_json, created_at_ms)
|
|
541
|
-
VALUES (?, 0, 'info', 'RUN_STARTED', 'runtime', 'run started', ?, ?);
|
|
542
|
-
|
|
543
|
-
-- 工具失败(建议 warn/error)
|
|
544
|
-
INSERT INTO run_logs(run_id, step_index, level, code, source, message, context_json, created_at_ms)
|
|
545
|
-
VALUES (?, ?, 'error', 'TOOL_EXECUTION_FAILED', 'tool', 'tool execution failed', ?, ?);
|
|
546
|
-
|
|
547
|
-
-- 运行终止(done/error/max_steps/abort)
|
|
548
|
-
INSERT INTO run_logs(run_id, step_index, level, code, source, message, context_json, created_at_ms)
|
|
549
|
-
VALUES (?, ?, ?, 'RUN_TERMINAL', 'runtime', 'run terminal', ?, ?);
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
## 11.4 清理策略(SQL)
|
|
553
|
-
|
|
554
|
-
```sql
|
|
555
|
-
-- 按时间清理(例如仅保留 30 天)
|
|
556
|
-
DELETE FROM run_logs
|
|
557
|
-
WHERE created_at_ms < ?;
|
|
558
|
-
|
|
559
|
-
-- 可选:只清理低级别日志
|
|
560
|
-
DELETE FROM run_logs
|
|
561
|
-
WHERE level IN ('debug', 'info')
|
|
562
|
-
AND created_at_ms < ?;
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
说明:
|
|
566
|
-
- `run_logs` 用于运维诊断,不替代 `events`。
|
|
567
|
-
- 若磁盘预算紧张,优先保留 `warn/error`,并对 `debug/info` 做短期保留。
|