@jun133/athlete 0.0.2

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 (61) hide show
  1. package/README.md +146 -0
  2. package/dist/cli.js +22731 -0
  3. package/dist/cli.js.map +1 -0
  4. package/package.json +72 -0
  5. package/scripts/postinstall-playwright.mjs +79 -0
  6. package/spec/README.md +56 -0
  7. package/spec/adr/ADR-0001-/345/215/225/346/250/241/345/274/217/345/205/250/346/235/203/351/231/220.md +16 -0
  8. package/spec/adr/ADR-0002-/345/215/225agent/350/265/267/346/255/245/345/271/266/351/242/204/347/225/231/345/244/232agent/350/276/271/347/225/214.md +19 -0
  9. package/spec/adr/ADR-0003-openai-compatible/344/274/230/345/205/210.md +16 -0
  10. package/spec/architecture//346/200/273/344/275/223/346/236/266/346/236/204.md +111 -0
  11. package/spec/architecture//347/212/266/346/200/201/344/270/216/347/234/237/347/233/270/346/272/220.md +117 -0
  12. package/spec/architecture//350/277/220/350/241/214/346/227/266/345/276/252/347/216/257.md +82 -0
  13. package/spec/implementation/README.md +17 -0
  14. package/spec/implementation//346/250/241/345/235/227/347/272/247/345/274/200/345/217/221/344/273/273/345/212/241/345/215/225.md +55 -0
  15. package/spec/implementation//347/233/256/345/275/225/347/273/223/346/236/204/345/210/260/344/273/243/347/240/201/346/226/207/344/273/266/346/230/240/345/260/204/350/241/250.md +101 -0
  16. package/spec/interfaces/InteractionShell.md +85 -0
  17. package/spec/interfaces/ProviderAdapter.md +23 -0
  18. package/spec/interfaces/README.md +17 -0
  19. package/spec/interfaces/RuntimeLoop.md +28 -0
  20. package/spec/interfaces/SessionStore.md +22 -0
  21. package/spec/interfaces/ToolRegistry.md +21 -0
  22. package/spec/modules/config-system.md +51 -0
  23. package/spec/modules/interactive-terminal.md +112 -0
  24. package/spec/modules/lightweight-context-runtime.md +63 -0
  25. package/spec/modules/provider-adapter.md +20 -0
  26. package/spec/modules/runtime-metrics.md +132 -0
  27. package/spec/modules/runtime-rules.md +33 -0
  28. package/spec/modules/session-resume-compact.md +49 -0
  29. package/spec/modules/task-state.md +34 -0
  30. package/spec/modules/telegram-private-chat.md +290 -0
  31. package/spec/modules/tool-registry.md +79 -0
  32. package/spec/modules/weixin-private-chat.md +291 -0
  33. package/spec/modules/workspace-isolation.md +24 -0
  34. package/spec/modules//346/211/251/345/261/225/346/234/272/345/210/266.md +105 -0
  35. package/spec/overview/v0/350/214/203/345/233/264.md +54 -0
  36. package/spec/overview//344/272/247/345/223/201/345/256/232/344/271/211.md +59 -0
  37. package/spec/principles/P01-/344/270/200/344/270/252/345/276/252/347/216/257/344/270/200/344/270/252/346/231/272/350/203/275/344/275/223.md +31 -0
  38. package/spec/principles/P02-/345/212/240/344/270/200/344/270/252/345/267/245/345/205/267/345/217/252/345/212/240/344/270/200/344/270/252/345/244/204/347/220/206/345/231/250.md +28 -0
  39. package/spec/principles/P03-/345/205/210/350/256/241/345/210/222/345/206/215/345/212/250/346/211/213.md +25 -0
  40. package/spec/principles/P04-/345/244/247/344/273/273/345/212/241/346/213/206/347/273/231/345/255/220/346/231/272/350/203/275/344/275/223.md +26 -0
  41. package/spec/principles/P05-/347/237/245/350/257/206/346/214/211/351/234/200/345/212/240/350/275/275.md +29 -0
  42. package/spec/principles/P06-/344/270/212/344/270/213/346/226/207/350/246/201/350/203/275/345/216/213/347/274/251.md +23 -0
  43. package/spec/principles/P07-/344/273/273/345/212/241/345/233/276/350/246/201/350/220/275/347/233/230.md +20 -0
  44. package/spec/principles/P08-/346/205/242/346/223/215/344/275/234/346/224/276/345/220/216/345/217/260.md +23 -0
  45. package/spec/principles/P09-/344/273/273/345/212/241/345/244/252/345/244/247/345/260/261/345/210/206/347/273/231/351/230/237/345/217/213.md +21 -0
  46. package/spec/principles/P10-/351/230/237/345/217/213/344/271/213/351/227/264/350/246/201/346/234/211/347/273/237/344/270/200/345/215/217/350/256/256.md +23 -0
  47. package/spec/principles/P11-/351/230/237/345/217/213/350/207/252/345/267/261/350/256/244/351/242/206/344/273/273/345/212/241.md +25 -0
  48. package/spec/principles/P12-/345/267/245/344/275/234/345/214/272/345/222/214/344/273/273/345/212/241/350/246/201/351/232/224/347/246/273.md +20 -0
  49. package/spec/principles/P13-session/346/230/257/344/273/273/345/212/241/347/216/260/345/234/272.md +30 -0
  50. package/spec/principles/P14-/346/211/247/350/241/214/347/272/246/346/235/237/344/270/215/346/230/257/345/256/211/345/205/250/347/255/226/347/225/245.md +27 -0
  51. package/spec/principles/P15-provider/345/277/205/351/241/273/345/217/257/346/233/277/346/215/242.md +22 -0
  52. package/spec/principles/P16-/351/205/215/347/275/256/345/217/252/350/203/275/346/234/211/344/270/200/344/270/252/345/205/245/345/217/243.md +22 -0
  53. package/spec/principles/P17-/346/211/251/345/261/225/351/235/240/344/272/213/344/273/266/347/224/237/351/225/277.md +32 -0
  54. package/spec/principles/P18-/344/270/273/345/276/252/347/216/257/345/222/214/346/226/207/344/273/266/351/203/275/344/270/215/350/203/275/351/225/277/350/203/226.md +36 -0
  55. package/spec/principles/P19-/345/205/210/345/206/231/345/244/261/350/264/245/346/265/213/350/257/225/345/206/215/345/206/231/345/256/236/347/216/260.md +29 -0
  56. package/spec/principles/README.md +39 -0
  57. package/spec/repo//345/274/200/345/217/221/350/247/204/345/210/231.md +39 -0
  58. package/spec/repo//346/234/254/345/234/260/345/221/275/344/273/244/344/270/216/346/265/201/347/250/213.md +32 -0
  59. package/spec/testing/fail-first-/347/254/254/344/270/200/346/211/271/346/265/213/350/257/225/345/210/227/350/241/250.md +11 -0
  60. package/spec/testing/fixtures-/350/247/204/350/214/203.md +20 -0
  61. package/spec/testing//346/265/213/350/257/225/347/255/226/347/225/245.md +97 -0
@@ -0,0 +1,101 @@
1
+ # 目录结构到代码文件映射表
2
+
3
+ ## 当前主要目录
4
+
5
+ - `src/agent/`: 主循环、prompt、continuation、verification、closeout
6
+ - `src/agent/checkpoint/`: checkpoint 归一化、推导、resume 输入、prompt block
7
+ - `src/agent/runtimeMetrics/`: runtime metrics 累积与 runtime summary
8
+ - `src/tools/`: 模型可见工具与 handler
9
+ - `src/skills/`: skill schema、discovery、matching、loading、workflow guard
10
+ - `src/mcp/`: MCP 总接入层
11
+ - `src/mcp/playwright/`: Playwright MCP 配置、路径、artifact、调用归一化
12
+ - `src/context/`: repo root、state root、AGENTS、skills、ignore 发现
13
+ - `src/config/`: 配置读取、环境变量、runtime config、app paths
14
+ - `src/tasks/`: 持久化 task 真相源
15
+ - `src/team/`: teammate、消息、协议、policy
16
+ - `src/background/`: 后台任务
17
+ - `src/worktrees/`: 目录隔离
18
+ - `src/subagent/`: 一次性子智能体
19
+ - `src/interaction/`: 共享交互控制层与 shell 契约
20
+ - `src/shell/cli/`: CLI shell 输入、输出、turn 展示、intro
21
+ - `src/ui/`: CLI 文本格式化、runtime summary 和兼容导出
22
+ - `src/telegram/`: Telegram 私聊通道、delivery、附件、CLI、process lock
23
+ - `src/weixin/`: Weixin 私聊通道、OpeniLink client、delivery、context_token、CLI、process lock
24
+
25
+ ## 当前 lightweight context 对应代码
26
+
27
+ - `src/agent/promptSections.ts`: static / dynamic prompt layer
28
+ - `src/agent/toolResultStorage.ts`: externalized tool result 落盘
29
+ - `src/agent/toolResultPreview.ts`: tool payload 预览与 transport 压缩
30
+ - `src/tools/files/toolResultArtifact.ts`: `.athlete/tool-results/...` 的紧凑 artifact read
31
+ - `src/agent/contextBuilder.ts`: 使用轻量 payload 的请求上下文构建
32
+
33
+ ## 当前 checkpoint / continuation 对应代码
34
+
35
+ - `src/agent/checkpoint.ts`: checkpoint 对外导出面
36
+ - `src/agent/checkpoint/base.ts`: checkpoint 默认结构与从 session 派生
37
+ - `src/agent/checkpoint/state.ts`: checkpoint 归一化与生命周期更新
38
+ - `src/agent/checkpoint/derivation.ts`: completedSteps / nextStep / artifact 推导
39
+ - `src/agent/checkpoint/prompt.ts`: checkpoint 恢复输入与 prompt block
40
+ - `src/agent/turnPersistence.ts`: turn 开始、yield、recovery、tool batch 的 session 持久化接线
41
+ - `src/agent/managedTurn.ts`: continuation 输入通过 checkpoint 生成
42
+
43
+ ## 当前 runtime metrics / 仪表盘 对应代码
44
+
45
+ - `src/agent/runtimeMetrics.ts`: runtime metrics 对外导出面
46
+ - `src/agent/runtimeMetrics/state.ts`: `runtimeStats` 归一化与事件累积
47
+ - `src/agent/runtimeMetrics/summary.ts`: session runtime summary 生成
48
+ - `src/agent/api.ts`: provider request timing 与 provider usage 采集
49
+ - `src/agent/runTurn.ts`: tool execution、compression、recovery 等运行事件统计接线
50
+ - `src/ui/runtimeSummary.ts`: 交互态 runtime summary 文本格式化
51
+ - `src/interaction/localCommands.ts`: 共享本地命令语义与 `/runtime` / `/stats` / `/仪表盘` 路由
52
+ - `src/ui/localCommands.ts`: CLI 默认输出适配与兼容导出
53
+
54
+ ## 当前交互 shell 对应代码
55
+
56
+ - `src/interaction/sessionDriver.ts`: 共享交互 session loop、multiline、interrupt、turn 生命周期
57
+ - `src/interaction/shell.ts`: `InteractionShell` / `ShellInputPort` / `ShellOutputPort` / `InteractionTurnDisplay`
58
+ - `src/shell/cli/readlineInput.ts`: CLI 输入适配
59
+ - `src/shell/cli/output.ts`: CLI 文本输出适配
60
+ - `src/shell/cli/turnDisplay.ts`: CLI spinner + stream renderer 适配
61
+ - `src/shell/cli/intro.ts`: CLI banner 与 launch hints
62
+ - `src/shell/cli/shell.ts`: CLI shell 组装
63
+ - `src/ui/interactive.ts`: CLI 入口薄壳,组装 shell 并启动共享 driver
64
+
65
+ ## 当前 Playwright MCP 对应代码
66
+
67
+ - `src/mcp/config.ts`: MCP 配置归一化
68
+ - `src/mcp/playwright/config.ts`: Playwright MCP 配置归一化与 server args
69
+ - `src/mcp/playwright/paths.ts`: `.athlete/playwright-mcp/` 路径约定
70
+ - `src/mcp/playwright/artifacts.ts`: artifact 目录准备、迁移、生成配置
71
+ - `src/mcp/playwright/invoke.ts`: relative filename 归一化
72
+ - `src/mcp/stdioClient.ts`: 真实 stdio MCP client
73
+ - `src/mcp/toolAdapter.ts`: MCP tool 适配进 Athlete registry
74
+ - `src/tools/runtimeRegistry.ts`: runtime registry 组装 built-in tools 与 MCP tools
75
+
76
+ ## 当前 closeout / verification 对应代码
77
+
78
+ - `src/agent/finalize.ts`: tool-less turn 的最终收口与 verification / pause 行为
79
+ - `src/agent/closeout.ts`: closeout 阶段的工具过滤与 stale todo 容忍规则
80
+ - `src/agent/verificationState.ts`: verification 真相源
81
+ - `src/agent/verificationSignals.ts`: lightweight verification signals 与 auto-readback
82
+ - `src/agent/runTurn.ts`: 调度这些规则,但不持有它们的内部实现细节
83
+
84
+ ## 当前文档 / 验证位置
85
+
86
+ - `skills/web-research/SKILL.md`
87
+ - `skills/browser-automation/SKILL.md`
88
+ - `spec/modules/lightweight-context-runtime.md`
89
+ - `spec/modules/session-resume-compact.md`
90
+ - `spec/modules/runtime-metrics.md`
91
+ - `tests/playwright-mcp.test.ts`
92
+ - `tests/browser-tool-priority.test.ts`
93
+ - `tests/playwright-workflow-guard.test.ts`
94
+ - `tests/agent-closeout.test.ts`
95
+ - `tests/runtime-lightweight-context.test.ts`
96
+ - `tests/runtime-checkpoint-resume.test.ts`
97
+ - `tests/runtime-observability.test.ts`
98
+ - `scripts/verify-runtime-lightweight-context-api.mjs`
99
+ - `scripts/verify-runtime-checkpoint-api.mjs`
100
+ - `scripts/verify-runtime-observability-api.mjs`
101
+ - `validation/`
@@ -0,0 +1,85 @@
1
+ # InteractionShell
2
+
3
+ ## 作用
4
+
5
+ `InteractionShell` 是共享交互控制层和具体外壳之间的正式边界。
6
+
7
+ 它让 Athlete 的交互 session loop 可以复用同一个大脑,同时替换 CLI、桌面等不同壳。
8
+
9
+ ## 当前真实能力
10
+
11
+ ### 参与者
12
+
13
+ - `InteractiveSessionDriver`: 共享交互控制器
14
+ - `InteractionShell`: 壳总接口
15
+ - `ShellInputPort`: 输入端口
16
+ - `ShellOutputPort`: 输出端口
17
+ - `InteractionTurnDisplay`: turn 展示端口
18
+
19
+ ### 当前契约语义
20
+
21
+ #### `ShellInputPort`
22
+
23
+ 负责:
24
+
25
+ - 读取普通输入
26
+ - 读取 multiline 输入
27
+ - 绑定 interrupt 事件
28
+
29
+ 不负责:
30
+
31
+ - 决定 task / runtime 真相
32
+ - 自己执行 agent turn
33
+
34
+ #### `ShellOutputPort`
35
+
36
+ 负责:
37
+
38
+ - 输出 `plain / info / warn / error / dim / heading / tool / interrupt`
39
+ - 保持壳自己的展示风格
40
+
41
+ 不负责:
42
+
43
+ - 修改 session 真相
44
+ - 决定本地命令语义
45
+
46
+ #### `InteractionTurnDisplay`
47
+
48
+ 负责:
49
+
50
+ - 接收 turn 生命周期内的 `AgentCallbacks`
51
+ - 展示流式 assistant / reasoning / tool 状态
52
+ - 在 turn 结束或中断时 flush / dispose
53
+
54
+ #### `InteractionShell`
55
+
56
+ 负责把上面三部分组装给共享 driver 使用。
57
+
58
+ ## 当前 CLI 实现
59
+
60
+ - `src/shell/cli/readlineInput.ts`
61
+ - `src/shell/cli/output.ts`
62
+ - `src/shell/cli/turnDisplay.ts`
63
+ - `src/shell/cli/shell.ts`
64
+
65
+ CLI 当前通过这些适配器接入:
66
+
67
+ - `readline`
68
+ - `process.stdin` / `process.stdout`
69
+ - `chalk`
70
+ - spinner / stream renderer
71
+
72
+ 这些都必须留在 CLI shell 内,不进入共享 driver。
73
+
74
+ ## 规则
75
+
76
+ 1. `InteractiveSessionDriver` 不能依赖 `readline`、stdio、`chalk`。
77
+ 2. shell 只能提供输入、输出和 turn 展示适配,不能把控制面状态偷搬到壳里。
78
+ 3. 本地命令的语义应落在共享交互层,shell 只负责把结果显示出来。
79
+ 4. interrupt 的来源可以因壳不同而不同,但共享 driver 的 abort 语义必须一致。
80
+
81
+ ## 未来方向
82
+
83
+ - 桌面壳可以实现自己的 `ShellInputPort`,例如输入框提交、多行编辑器、停止按钮。
84
+ - 桌面壳可以实现自己的 `ShellOutputPort` / `InteractionTurnDisplay`,例如富文本消息区和状态面板。
85
+ - 未来如果出现 web / mobile 壳,也应优先复用这组契约,而不是复制一套 session loop。
@@ -0,0 +1,23 @@
1
+ # ProviderAdapter
2
+
3
+ ## 作用
4
+
5
+ ProviderAdapter 把 Athlete 的请求发送到具体模型服务,并返回统一结果。
6
+
7
+ ## 最小职责
8
+
9
+ - 接收消息数组
10
+ - 接收模型名
11
+ - 接收工具定义
12
+ - 返回 assistant 文本、reasoning、tool calls
13
+ - 对常见 provider 错误提供可恢复语义
14
+
15
+ ## 不负责
16
+
17
+ - 任务拆分
18
+ - 控制面状态判断
19
+ - 工具执行
20
+
21
+ ## 稳定边界
22
+
23
+ 只要 adapter 还能提供统一输出,底层 provider 可以继续替换。
@@ -0,0 +1,17 @@
1
+ # 接口契约
2
+
3
+ 这一组文档不追求把所有 TypeScript 细节抄一遍。
4
+
5
+ 它们只说明 Athlete 内核最关键的抽象边界:
6
+
7
+ - provider adapter
8
+ - runtime loop
9
+ - session store
10
+ - tool registry
11
+ - interaction shell
12
+
13
+ ## 使用规则
14
+
15
+ 1. 接口文档写稳定边界,不写瞬时实现细节。
16
+ 2. 新能力优先问“该落在哪个接口”,再问“该落在哪个文件”。
17
+ 3. 如果某个改动让接口职责明显变混,优先拆接口。
@@ -0,0 +1,28 @@
1
+ # RuntimeLoop
2
+
3
+ ## 作用
4
+
5
+ RuntimeLoop 负责驱动一个 turn,直到:
6
+
7
+ - 完成
8
+ - 暂停
9
+ - yield
10
+ - 报错
11
+
12
+ ## 最小职责
13
+
14
+ - 组装请求上下文
15
+ - 读运行时状态
16
+ - 调模型
17
+ - 执行工具
18
+ - 处理 continuation / compact / verification
19
+
20
+ ## 不负责
21
+
22
+ - 保存长期任务真相
23
+ - 发明新工具
24
+ - 实现具体业务流程
25
+
26
+ ## 下一阶段要求
27
+
28
+ 总指挥层可以成为 loop 的上游决策来源,但不能把 RuntimeLoop 变成一个巨大的业务文件。
@@ -0,0 +1,22 @@
1
+ # SessionStore
2
+
3
+ ## 作用
4
+
5
+ SessionStore 负责保存和恢复任务现场。
6
+
7
+ ## 最小职责
8
+
9
+ - 创建 session
10
+ - 追加消息
11
+ - 保存 todo / verification / taskState
12
+ - 加载既有 session
13
+
14
+ ## 不负责
15
+
16
+ - 任务板真相
17
+ - teammate roster
18
+ - worktree 生命周期
19
+
20
+ ## 关键要求
21
+
22
+ session 恢复不能破坏 Athlete 的耐跑能力。
@@ -0,0 +1,21 @@
1
+ # ToolRegistry
2
+
3
+ ## 作用
4
+
5
+ ToolRegistry 负责统一管理模型可见工具。
6
+
7
+ ## 最小职责
8
+
9
+ - 返回工具定义
10
+ - 按名称执行工具
11
+ - 根据 mode / runtime 过滤工具集
12
+
13
+ ## 不负责
14
+
15
+ - provider 请求
16
+ - session 存储
17
+ - 任务真相维护
18
+
19
+ ## 关键要求
20
+
21
+ 无论未来 tools、skills、MCP 怎么扩,模型看到的动作入口都要保持统一。
@@ -0,0 +1,51 @@
1
+ # config system
2
+
3
+ ## 作用
4
+
5
+ 配置系统负责统一读取 Athlete 的运行参数,并把项目级默认值、用户配置和环境变量合并成最终 runtime config。
6
+
7
+ ## 当前范围
8
+
9
+ - API key / base URL / model
10
+ - mode
11
+ - paths
12
+ - MCP 总开关与 server 配置
13
+ - Playwright MCP repo 级默认值
14
+ - context / continuation / read limits 等运行阈值
15
+
16
+ ## 当前规则
17
+
18
+ 1. 配置入口统一。
19
+ 2. 业务模块不直接散读环境变量。
20
+ 3. 用户能从 runtime config 理解当前行为从哪来。
21
+ 4. 项目级默认值允许放在 `.athlete/.env`,但仍由统一配置入口解析。
22
+
23
+ ## Playwright MCP 当前事实
24
+
25
+ 当前支持的 repo 级 Playwright MCP 环境变量:
26
+
27
+ - `ATHLETE_MCP_ENABLED`
28
+ - `ATHLETE_MCP_PLAYWRIGHT_ENABLED`
29
+ - `ATHLETE_MCP_PLAYWRIGHT_BROWSER`
30
+ - `ATHLETE_MCP_PLAYWRIGHT_HEADLESS`
31
+ - `ATHLETE_MCP_PLAYWRIGHT_OUTPUT_MODE`
32
+ - `ATHLETE_MCP_PLAYWRIGHT_SAVE_SESSION`
33
+
34
+ 当前仓库默认行为:
35
+
36
+ - Playwright MCP 在项目级 `.athlete/.env` 中默认启用
37
+ - 默认浏览器为 `chrome`
38
+ - 默认不是 headless
39
+ - 默认 output mode 为 `file`
40
+ - 默认 save session 为开启
41
+
42
+ ## 路径约定
43
+
44
+ 当前 Playwright MCP 状态目录:
45
+
46
+ - `.athlete/playwright-mcp/config.json`
47
+ - `.athlete/playwright-mcp/profile/`
48
+ - `.athlete/playwright-mcp/output/`
49
+ - `.athlete/playwright-mcp/legacy-root-artifacts/`
50
+
51
+ 这些路径由配置系统和 `src/mcp/playwright/` 统一导出,不允许在调用侧随意拼接。
@@ -0,0 +1,112 @@
1
+ # interactive terminal
2
+
3
+ ## 作用
4
+
5
+ 交互终端是 Athlete 的表现层外壳,不是控制面真相源。
6
+
7
+ ## 当前真实能力
8
+
9
+ ### 当前分层
10
+
11
+ - `src/interaction/`: 共享交互控制层
12
+ - `src/shell/cli/`: CLI shell 适配层
13
+ - `src/ui/`: CLI 文本格式化、runtime summary 和兼容导出
14
+
15
+ ### 共享交互控制层职责
16
+
17
+ - 驱动交互 session loop
18
+ - 处理普通输入和 multiline 分支
19
+ - 处理本地命令路由
20
+ - 管理 turn in-flight 状态与 abort controller 生命周期
21
+ - 接线 `runManagedAgentTurn`
22
+ - 维护当前 session 的内存态,并在 turn 完成后接收最新 session
23
+
24
+ ### 当前 CLI shell 职责
25
+
26
+ - 提供 persistent input / multiline input
27
+ - 绑定终端 interrupt
28
+ - 展示 assistant 流式输出
29
+ - 展示 tool 调用和状态消息
30
+ - 展示 banner、launch hints、dim/warn/plain/stderr 风格
31
+ - 展示当前 session 的 runtime summary
32
+
33
+ ## 规则
34
+
35
+ 1. UI 不能反向定义 task、protocol、worktree、checkpoint、runtimeStats 等控制面事实。
36
+ 2. spinner、stream renderer、本地命令格式化都只属于表现层。
37
+ 3. Athlete 可以替换 UI,但不能因此破坏 runtime kernel。
38
+ 4. `/runtime`、`/stats`、`/仪表盘` 只是 `SessionRecord.runtimeStats` 的只读 summary 视图。
39
+ 5. UI 可以读取并展示真相源,但不能绕过真相源另造状态。
40
+ 6. 交互 session loop 不能直接绑死 `readline`、`process.stdin/stdout`、`chalk` 这类 CLI 细节。
41
+ 7. shell 只能提供输入、输出和 turn 展示适配,不能自己发明 task / protocol / runtime 真相。
42
+ ## 当前本地命令入口
43
+
44
+ - `/session`
45
+ - `/config`
46
+ - `/todos`
47
+ - `/tasks`
48
+ - `/team`
49
+ - `/background`
50
+ - `/worktrees`
51
+ - `/inbox`
52
+ - `/runtime`
53
+ - `/stats`
54
+ - `/仪表盘`
55
+ - `/reset`
56
+
57
+ ## Runtime Summary 展示范围
58
+
59
+ 当前交互态最小 runtime summary 包含:
60
+
61
+ - session health
62
+ - model request count
63
+ - model wait total
64
+ - tool call count
65
+ - tool duration total
66
+ - yield / continuation / recovery / compression count
67
+ - externalized result count / bytes
68
+ - top tools
69
+
70
+ ## Reset Boundary
71
+
72
+ - `/reset` 是显式 destructive local command,不是普通的窗口关闭动作。
73
+ - `/reset` 清空当前项目 `.athlete/` 下的运行时状态,但保留 `.athlete/.env` 和 `.athlete/.env.example`。
74
+ - `/reset` 还会删除当前项目相关的持久化 session,因此 `resume` 不应恢复已经 reset 掉的运行时。
75
+ - `/reset` 会尽量先通过正式 worktree / process 清理路径收尾,再删除状态目录。
76
+ - reset 行为必须落在 runtime / project state 层,UI 只能触发它,不能自己维护一套平行 reset 状态。
77
+
78
+ ## 当前边界
79
+
80
+ ### 共享边界
81
+
82
+ - `InteractiveSessionDriver`: 共享交互控制器
83
+ - `InteractionShell`: 壳适配接口
84
+ - `ShellInputPort`: 普通输入 / multiline 输入 / interrupt 订阅
85
+ - `ShellOutputPort`: info / warn / plain / dim / interrupt 等展示输出
86
+ - `InteractionTurnDisplay`: turn 期间的流式展示适配
87
+
88
+ ### 当前 CLI 接线
89
+
90
+ - `src/ui/interactive.ts`: CLI 入口薄壳,只负责组装 shell、打印 intro、启动 driver
91
+ - `src/shell/cli/readlineInput.ts`: CLI 输入适配
92
+ - `src/shell/cli/output.ts`: `chalk` + stdio 输出适配
93
+ - `src/shell/cli/turnDisplay.ts`: spinner + stream renderer 适配
94
+ - `src/interaction/localCommands.ts`: 共享本地命令语义
95
+
96
+ ## 当前展示边界
97
+
98
+ 交互终端当前只负责把这些状态展示清楚:
99
+
100
+ - task board
101
+ - teammate 状态
102
+ - background 状态
103
+ - skill load 状态
104
+ - runtime summary
105
+
106
+ 但它不负责发明这些状态。
107
+
108
+ ## 未来方向
109
+
110
+ - 桌面壳应直接实现 `InteractionShell` 契约,而不是复用 CLI 的 `readline` / stdio 细节。
111
+ - 桌面壳可以自己提供输入框、停止按钮、流式消息区和状态面板。
112
+ - 只要继续复用 `InteractiveSessionDriver`,桌面壳与 CLI 壳就应共享同一套本地命令、turn 驱动和中断语义。
@@ -0,0 +1,63 @@
1
+ # lightweight context runtime
2
+
3
+ ## 目标
4
+
5
+ 这一层负责让 Athlete 在长任务里继续跑,但不要把 prompt 和 session 越跑越重。
6
+
7
+ ## 运行时约定
8
+
9
+ 1. system prompt 按两层正式组装:
10
+ - `Static operating layer`
11
+ - `Dynamic runtime layer`
12
+ 2. 静态层放稳定规则、模式规则、身份规则、项目说明。
13
+ 3. 动态层放 cwd / root / date / taskState / todo / verification / task board / team / worktree / protocol / background / skill runtime。
14
+ 4. 压缩后的会话总结不再直接拼回静态层,而是追加为 `Compressed conversation memory`。
15
+
16
+ ## 大 tool result 外置化
17
+
18
+ 1. 当 tool output 超过约 `12,000` chars 或 `16 KB` 时,进入外置化路径。
19
+ 2. 原始 output 落盘到项目 state root 下:
20
+ - `.athlete/tool-results/<sessionId>/<timestamp>-<tool>-<hash>.json|txt`
21
+ 3. session 里保留的 tool message 只存轻量引用:
22
+ - `externalized: true`
23
+ - `storagePath`
24
+ - `summary`
25
+ - `preview`
26
+ - `byteLength`
27
+ - `charLength`
28
+ 4. 小结果继续走原来的 inline message 路径,不做无差别外置化。
29
+ 5. 当 agent 读取 `.athlete/tool-results/...` 中的 artifact 文件时,`read_file` 默认返回紧凑摘要视图;只有显式 line range 读取才继续走原始逐行查看路径。
30
+
31
+ ## 闭环要求
32
+
33
+ 1. continuation 继续使用 session 中的轻量 tool message,而不是重新塞回原始大正文。
34
+ 2. contextBuilder 在压缩历史时继续保留 `storagePath` 和预览信息。
35
+ 3. recovery 的 context shrink 也要保住结构化引用,不能把它打回不可追踪的大字符串。
36
+ 4. session 保存和加载后,外置化引用仍然可以恢复到落盘文件。
37
+ 5. 已通过 streaming delta 发出的 assistant 文本不会在 finalize 阶段再次整段重放。
38
+
39
+ ## 验证方式
40
+
41
+ 1. fail-first 测试:
42
+ - `tests/runtime-lightweight-context.test.ts`
43
+ 2. 核心回归:
44
+ - `npm run test:build`
45
+ - `npm run test:core`
46
+ 3. 真实 API:
47
+ - `npm run verify:runtime-context-api`
48
+ ## Checkpoint Runtime Contract
49
+
50
+ - `SessionRecord` now persists a structured `checkpoint` inside the existing session truth source.
51
+ - `checkpoint` is a runtime summary, not a transcript dump. It carries:
52
+ - objective
53
+ - completedSteps
54
+ - currentStep
55
+ - nextStep
56
+ - recentToolBatch
57
+ - flow phase (`active / continuation / resume / recovery`)
58
+ - priorityArtifacts (externalized tool-result refs, previews, pending paths)
59
+ - continuation, reload/resume, and dynamic prompt rendering must all consume the same checkpoint instead of inventing separate recovery hints.
60
+ - objective changes reset checkpoint progress so old work does not pollute the new task.
61
+ - externalized tool results remain the preferred recoverable context, and checkpoint keeps the references lightweight.
62
+ - fail-first test for this layer: `tests/runtime-checkpoint-resume.test.ts`
63
+ - real API verification entry for this layer: `npm run verify:runtime-checkpoint-api`
@@ -0,0 +1,20 @@
1
+ # provider adapter
2
+
3
+ ## 作用
4
+
5
+ provider adapter 负责把 Athlete 的请求发送到具体模型服务。
6
+
7
+ ## 当前策略
8
+
9
+ - 优先 OpenAI-compatible
10
+ - 运行时对网络错误、超时、上下文过长有恢复策略
11
+
12
+ ## 规则
13
+
14
+ 1. provider 能换,主循环不跟着重写。
15
+ 2. provider 问题先在 adapter 层处理,不外溢到任务语义层。
16
+ 3. 模型 fallback 属于运行时策略,不属于业务模块。
17
+
18
+ ## 下一阶段要求
19
+
20
+ 总指挥层不依赖某一家 provider 特性。
@@ -0,0 +1,132 @@
1
+ # runtime metrics
2
+
3
+ ## 作用
4
+
5
+ 这一层开始,Athlete 的 session 会持久化结构化 `runtimeStats`,
6
+ 作为正式运行态仪表盘的真相源。
7
+
8
+ 它回答的是:
9
+
10
+ - 这次 session 一共发了多少次 provider request
11
+ - 模型等待总耗时是多少
12
+ - tool 一共调用了多少次、各自累计耗时多少
13
+ - yield / continuation / recovery / compression 各发生了多少次
14
+ - 有多少 tool result 被 externalize,以及累计字节数是多少
15
+ - provider usage 是 available、partial 还是 unavailable
16
+
17
+ ## 真相源位置
18
+
19
+ - `SessionRecord.runtimeStats`
20
+ - 仍然持久化在既有 session JSON 文件里
21
+ - 不新建平行 JSON 真相源
22
+
23
+ ## 当前结构
24
+
25
+ `runtimeStats` 当前包含:
26
+
27
+ - `version`
28
+ - `model.requestCount`
29
+ - `model.waitDurationMsTotal`
30
+ - `model.usage.requestsWithUsage`
31
+ - `model.usage.requestsWithoutUsage`
32
+ - `model.usage.inputTokensTotal`
33
+ - `model.usage.outputTokensTotal`
34
+ - `model.usage.totalTokensTotal`
35
+ - `model.usage.reasoningTokensTotal`
36
+ - `tools.callCount`
37
+ - `tools.durationMsTotal`
38
+ - `tools.byName`
39
+ - `events.continuationCount`
40
+ - `events.yieldCount`
41
+ - `events.recoveryCount`
42
+ - `events.compressionCount`
43
+ - `externalizedToolResults.count`
44
+ - `externalizedToolResults.byteLengthTotal`
45
+ - `updatedAt`
46
+
47
+ ## 来源
48
+
49
+ ### model request
50
+
51
+ - 来源:`src/agent/api.ts`
52
+ - 统计粒度:真实 provider request attempt
53
+ - 包括 streaming、non-streaming fallback、retry、retry fallback
54
+
55
+ ### tool execution
56
+
57
+ - 来源:`src/agent/runTurn.ts`
58
+ - 统计粒度:真实 runtime tool execution
59
+ - `tools.byName` 记录每个 tool 的调用次数、累计耗时、成功次数、失败次数
60
+
61
+ ### yield / continuation / recovery
62
+
63
+ - 来源:`src/agent/turnPersistence.ts`
64
+ - continuation 包括:
65
+ - managed continuation 的内部续跑输入
66
+ - 用户显式 `continue` / `resume` 这类恢复输入
67
+
68
+ ### compression
69
+
70
+ - 来源:`src/agent/runTurn.ts`
71
+ - 当 `buildRequestContext(...)` 返回 `compressed = true` 时记一次
72
+
73
+ ### externalized tool results
74
+
75
+ - 来源:`src/agent/runTurn.ts` + `src/agent/toolResultStorage.ts`
76
+ - 只在 tool result 实际被 externalize 时累计
77
+
78
+ ## 用户入口
79
+
80
+ 当前最小仪表盘入口:
81
+
82
+ - `/runtime`
83
+ - `/stats`
84
+ - `/仪表盘`
85
+
86
+ 这些命令只读取并格式化当前 session summary,
87
+ 不发明新的运行态事实。
88
+
89
+ ## 当前 summary 最少包含
90
+
91
+ - model request 次数
92
+ - model wait 总耗时
93
+ - tool call 次数
94
+ - tool 总耗时
95
+ - yields / continuations / recoveries / compressions
96
+ - externalized result count / bytes
97
+ - top tools
98
+ - slowest step
99
+ - usage availability
100
+ - session health
101
+
102
+ ## usage 规则
103
+
104
+ - 只有 provider 明确返回 usage 时才记录 usage
105
+ - 如果 provider 没返回 usage,summary 必须显示 `unavailable` 或 `partial`
106
+ - 不根据字符数、消息数、模型名去估算 token
107
+
108
+ ## 健康状态
109
+
110
+ 当前 summary 会给出:
111
+
112
+ - `healthy`
113
+ - `warning`
114
+ - `recovering`
115
+
116
+ 它来自 checkpoint phase、verification state、recovery 事件等正式状态的推导视图,
117
+ 不是另一份单独持久化的状态。
118
+
119
+ ## 真实验证
120
+
121
+ 当前真实 API 验证入口:
122
+
123
+ - `npm run verify:runtime-observability-api`
124
+
125
+ 它至少要确认:
126
+
127
+ - `runtimeStats` 已写进 session
128
+ - reload session 后 `runtimeStats` 仍然存在
129
+ - 真实 model request 被统计
130
+ - 真实 tool call 被统计
131
+ - 用户可读的 runtime summary 路径可用
132
+ - lightweight context 与 checkpoint runtime 没被打坏