kenaz 0.3.17 → 0.3.19

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 (316) hide show
  1. package/core/.claude/commands/agent-worker.md +1 -1
  2. package/core/.claude/commands/architect.md +1 -2
  3. package/core/.claude/commands/spec.md +1 -1
  4. package/core/.claude/commands//347/224/242/345/223/201.md +1 -1
  5. package/core/.claude/hooks/__tests__/task-1977-dedupe-guard.test.js +8 -8
  6. package/core/.claude/hooks/synapse-first-investigation.js +15 -0
  7. package/core/.claude/skills/architect_agent/SKILL.md +11 -92
  8. package/core/.claude/skills/assessment_agent/SKILL.md +0 -1
  9. package/core/.claude/skills/backend_engineer/SKILL.md +3 -6
  10. package/core/.claude/skills/code_reviewer/SKILL.md +1 -1
  11. package/core/.claude/skills/code_reviewer/patterns.yaml +1 -1
  12. package/core/.claude/skills/designer/SKILL.md +3 -6
  13. package/core/.claude/skills/dev_agent/SKILL.md +30 -491
  14. package/core/.claude/skills/developer/SKILL.md +3 -6
  15. package/core/.claude/skills/feature_agent/SKILL.md +3 -17
  16. package/core/.claude/skills/product_manager/SKILL.md +29 -1064
  17. package/core/.claude/skills/qa_engineer/SKILL.md +12 -17
  18. package/core/.claude/skills/spec_optimizer/SKILL.md +25 -275
  19. package/core/.claude/skills/sre_agent/SKILL.md +3 -6
  20. package/core/.collaboration/README.md +2 -3
  21. package/core/.collaboration/core/task-api.js +5 -138
  22. package/core/.collaboration/docs/CLI.md +0 -2
  23. package/core/.failure/INDEX.yaml +6 -40
  24. package/core/.failure/agent-execution/FAIL-013-search-cwd-drift-and-case-mismatch.yaml +1 -1
  25. package/core/.failure/tools/README.md +9 -227
  26. package/core/.formation/bifrost/exec.js +29 -4
  27. package/core/.formation/bifrost/launch.js +1 -6
  28. package/core/.formation/bifrost/launch.test.js +1 -1
  29. package/core/.formation/bifrost/provider-launch.js +18 -11
  30. package/core/.formation/bifrost/provider-launch.test.js +26 -2
  31. package/core/.formation/bifrost/shared/ansuz-boot-policy.js +3 -3
  32. package/core/.formation/bifrost/shared/ansuz-boot-policy.test.js +1 -2
  33. package/core/.formation/tools/__tests__/dispatch-cwd-project.test.js +42 -0
  34. package/core/.formation/tools/__tests__/m1-hmap-convid.test.js +1 -124
  35. package/core/.formation/tools/__tests__/subagent-executor.test.js +3 -2
  36. package/core/.formation/tools/dispatch.js +15 -2
  37. package/core/.formation/tools/loader.js +17 -140
  38. package/core/.formation/tools/post-complete.js +0 -31
  39. package/core/.rule/INDEX.yaml +0 -18
  40. package/core/.rule/general/agent-workflow.yaml +14 -164
  41. package/core/.rule/general/project-self-containment.yaml +8 -19
  42. package/core/.rule/general/rust-verify-target.yaml +6 -5
  43. package/core/.rule/general/synapse-code-intelligence.yaml +3 -3
  44. package/core/.specialist/Amelia/capability.yaml +12 -12
  45. package/core/.specialist/Amelia/workflow.yaml +2 -2
  46. package/core/.specialist/Ansuz/SYSTEM_DOC.md +20 -578
  47. package/core/.specialist/Ansuz/cognitive_principles.yaml +2 -3
  48. package/core/.specialist/Ansuz/concepts/boot_rules_summary.yaml +0 -1
  49. package/core/.specialist/Ansuz/concepts/deep_knowledge_pointers.yaml +1 -2
  50. package/core/.specialist/Ansuz/core.yaml +6 -108
  51. package/core/.specialist/Ansuz/guards/lesson_guards.yaml +0 -3
  52. package/core/.specialist/Ansuz/identity_contract.yaml +0 -1
  53. package/core/.specialist/Ansuz/knowledge.yaml +0 -4
  54. package/core/.specialist/Ansuz/rule.yaml +0 -1
  55. package/core/.specialist/Ansuz/tools/handoff-session-identity.test.js +6 -150
  56. package/core/.specialist/tests/runtime-discovery/README.md +1 -1
  57. package/core/.specialist/tools/__tests__/task-2374-usage-counter.test.js +1 -12
  58. package/core/.specialist/tools/prompt-files.test.js +1 -0
  59. package/core/.specialist/tools/task-bridge.js +1 -66
  60. package/core/.system/README.md +11 -552
  61. package/core/.system/collaboration/README.md +10 -174
  62. package/core/CLAUDE.md +1 -6
  63. package/core/KENAZ_CORE_VERSION +1 -1
  64. package/core/dev/scripts/js-yaml-resolution.test.js +1 -1
  65. package/core/dev/scripts/run-rust-tests.js +30 -46
  66. package/core/dev/scripts/run-rust-tests.test.js +17 -0
  67. package/core/dev/scripts/rust-verify-worktree.js +4 -4
  68. package/core/dev/scripts/verify-target-dir.js +6 -6
  69. package/core/plugins/kenaz/INVENTORY.md +8 -8
  70. package/core/plugins/kenaz/commands/architect.md +1 -2
  71. package/core/plugins/kenaz/commands/spec.md +1 -1
  72. package/core/plugins/kenaz/commands//347/224/242/345/223/201.md +1 -1
  73. package/core/plugins/kenaz/guidance.md +1 -1
  74. package/core/plugins/kenaz/scripts/sync.js +1 -1
  75. package/core/plugins/kenaz/scripts/ygg.js +6 -0
  76. package/core/plugins/kenaz/skills/architect_agent/SKILL.md +11 -92
  77. package/core/plugins/kenaz/skills/assessment_agent/SKILL.md +0 -1
  78. package/core/plugins/kenaz/skills/backend_engineer/SKILL.md +3 -6
  79. package/core/plugins/kenaz/skills/code_reviewer/SKILL.md +1 -1
  80. package/core/plugins/kenaz/skills/code_reviewer/patterns.yaml +1 -1
  81. package/core/plugins/kenaz/skills/designer/SKILL.md +3 -6
  82. package/core/plugins/kenaz/skills/dev_agent/SKILL.md +30 -491
  83. package/core/plugins/kenaz/skills/developer/SKILL.md +3 -6
  84. package/core/plugins/kenaz/skills/feature_agent/SKILL.md +3 -17
  85. package/core/plugins/kenaz/skills/product_manager/SKILL.md +29 -1064
  86. package/core/plugins/kenaz/skills/qa_engineer/SKILL.md +12 -17
  87. package/core/plugins/kenaz/skills/spec_optimizer/SKILL.md +25 -275
  88. package/core/plugins/kenaz/skills/sre_agent/SKILL.md +3 -6
  89. package/package.json +6 -6
  90. package/core/.claude/commands/archive.md +0 -24
  91. package/core/.claude/commands/init.md +0 -112
  92. package/core/.claude/commands/legacy_dev.md +0 -18
  93. package/core/.claude/commands/product-review.md +0 -131
  94. package/core/.claude/commands/strategy.md +0 -141
  95. package/core/.claude/commands/sunny.md +0 -1
  96. package/core/.claude/commands//347/224/242/345/223/201/346/252/242/350/246/226.md +0 -129
  97. package/core/.claude/commands//351/200/262/345/272/246.md +0 -15
  98. package/core/.claude/hooks/__tests__/substrate.test.js +0 -122
  99. package/core/.claude/hooks/_substrate-paths.js +0 -95
  100. package/core/.claude/hooks/context-check.js +0 -51
  101. package/core/.claude/hooks/fatigue-check.js +0 -52
  102. package/core/.claude/hooks/handoff-snapshot-on-commit.js +0 -154
  103. package/core/.claude/hooks/handoff-snapshot-on-question.js +0 -158
  104. package/core/.claude/hooks/handoff-staleness.js +0 -197
  105. package/core/.claude/hooks/jev-thalamus-context.js +0 -17
  106. package/core/.claude/hooks/jev-thalamus-context.test.js +0 -41
  107. package/core/.claude/hooks/lease-release.js +0 -119
  108. package/core/.claude/hooks/lease-touch.js +0 -96
  109. package/core/.claude/hooks/reflex-feedback.js +0 -5
  110. package/core/.claude/hooks/session-init.ps1 +0 -49
  111. package/core/.claude/hooks/sound-event.js +0 -70
  112. package/core/.claude/hooks/sound-event.sh +0 -37
  113. package/core/.claude/hooks/stream-delta.js +0 -169
  114. package/core/.claude/no-hooks.settings.json +0 -3
  115. package/core/.claude/skills/legacy_dev/SKILL.md +0 -202
  116. package/core/.claude/skills/sunny/SKILL.md +0 -74
  117. package/core/.collaboration/cli/commands/assign.js +0 -39
  118. package/core/.collaboration/cli/commands/claim.js +0 -33
  119. package/core/.collaboration/cli/commands/complete.js +0 -44
  120. package/core/.collaboration/cli/commands/create.js +0 -110
  121. package/core/.collaboration/cli/commands/get.js +0 -83
  122. package/core/.collaboration/cli/commands/index.js +0 -52
  123. package/core/.collaboration/cli/commands/list.js +0 -51
  124. package/core/.collaboration/cli/commands/lock.js +0 -45
  125. package/core/.collaboration/cli/commands/rebuild.js +0 -39
  126. package/core/.collaboration/cli/commands/search.js +0 -61
  127. package/core/.collaboration/cli/commands/stats.js +0 -61
  128. package/core/.collaboration/cli/commands/transfer.js +0 -41
  129. package/core/.collaboration/cli/commands/unlock.js +0 -48
  130. package/core/.collaboration/cli/formatters/help-formatter.js +0 -70
  131. package/core/.collaboration/cli/formatters/index.js +0 -7
  132. package/core/.collaboration/cli/task-cli.js +0 -46
  133. package/core/.collaboration/cli/utils/arg-parser.js +0 -74
  134. package/core/.collaboration/cli/utils/git-user.js +0 -25
  135. package/core/.collaboration/cli/utils/index.js +0 -9
  136. package/core/.collaboration/cli/utils/output.js +0 -10
  137. package/core/.collaboration/config/default.yaml +0 -189
  138. package/core/.collaboration/core/conflict-resolver.js +0 -461
  139. package/core/.collaboration/core/conflict-resolver.test.js +0 -389
  140. package/core/.collaboration/core/migrate-legacy.js +0 -260
  141. package/core/.collaboration/docs/API.md +0 -787
  142. package/core/.collaboration/docs/ARCHITECTURE.md +0 -596
  143. package/core/.collaboration/docs/FAQ.md +0 -695
  144. package/core/.collaboration/docs/MIGRATION.md +0 -804
  145. package/core/.collaboration/docs/examples/README.md +0 -320
  146. package/core/.collaboration/docs/examples/advanced-queries.js +0 -261
  147. package/core/.collaboration/docs/examples/basic-usage.js +0 -184
  148. package/core/.collaboration/docs/examples/team-workflow.js +0 -352
  149. package/core/.failure/agent-execution/FAIL-001-agent-no-output.yaml +0 -391
  150. package/core/.failure/agent-execution/FAIL-007-pm-lead-wrong-team-invocation.yaml +0 -0
  151. package/core/.failure/agent-execution/FAIL-010-phase0-poem-format-skipped.yaml +0 -28
  152. package/core/.failure/agent-execution/FAIL-010-skipping-cognitive-checkpoint-after-verification.yaml +0 -59
  153. package/core/.failure/agent-execution/FAIL-012-grep-shortcut-during-investigation.yaml +0 -85
  154. package/core/.failure/architecture/FAIL-006-python-version-compatibility.yaml +0 -445
  155. package/core/.failure/pipeline/FAIL-003-queue-pollution.yaml +0 -335
  156. package/core/.failure/pipeline/README.md +0 -95
  157. package/core/.failure/retired/FAIL-009-skipping-synapse-pulse-before-code-change.yaml +0 -49
  158. package/core/.failure/tools/USAGE_GUIDE.md +0 -323
  159. package/core/.failure/tools/check_failures.ps1 +0 -387
  160. package/core/.failure/tools/log_failure.ps1 +0 -474
  161. package/core/.formation/.episode-input.json +0 -10
  162. package/core/.formation/.merge-lock +0 -1
  163. package/core/.formation/lead.yaml +0 -118
  164. package/core/.formation/legacy.bak/designer.yaml +0 -57
  165. package/core/.formation/legacy.bak/pm.yaml +0 -57
  166. package/core/.formation/legacy.bak/qa.yaml +0 -57
  167. package/core/.formation/legacy.bak/review.yaml +0 -62
  168. package/core/.formation/legacy.bak/scheduler.yaml +0 -129
  169. package/core/.formation/legacy.bak/sre.yaml +0 -57
  170. package/core/.formation/role-map.yaml +0 -274
  171. package/core/.formation/roles/_shared/modules/code_review.yaml +0 -98
  172. package/core/.formation/roles/_shared/modules/security.yaml +0 -103
  173. package/core/.formation/roles/_shared/modules/testing.yaml +0 -14
  174. package/core/.formation/roles/backend/role.yaml +0 -93
  175. package/core/.formation/roles/code_reviewer/role.yaml +0 -102
  176. package/core/.formation/roles/database_optimizer/role.yaml +0 -107
  177. package/core/.formation/roles/designer/role.yaml +0 -66
  178. package/core/.formation/roles/developer/role.yaml +0 -75
  179. package/core/.formation/roles/frontend/role.yaml +0 -134
  180. package/core/.formation/roles/incident_response/role.yaml +0 -89
  181. package/core/.formation/roles/qa/role.yaml +0 -89
  182. package/core/.formation/roles/security/role.yaml +0 -87
  183. package/core/.formation/roles/sre/role.yaml +0 -66
  184. package/core/.formation/skills/coordinator.yaml +0 -52
  185. package/core/.formation/solo/diagnosis.yaml +0 -78
  186. package/core/.formation/solo/strategy.yaml +0 -121
  187. package/core/.formation/tests/hello.txt +0 -2
  188. package/core/.formation/tools/coordinator.js +0 -350
  189. package/core/.formation/tools/jev-correction.js +0 -214
  190. package/core/.formation/tools/jev-correction.test.js +0 -178
  191. package/core/.formation/tools/log-reader.js +0 -232
  192. package/core/.formation/tools/revert-daemon-state.js +0 -162
  193. package/core/.formation/tools/test-drift.js +0 -148
  194. package/core/.formation/unit/heimdall.yaml +0 -96
  195. package/core/.formation/unit/plan.yaml +0 -67
  196. package/core/.formation/unit/think.yaml +0 -58
  197. package/core/.kenaz/MUNINN_SNAPSHOT9_EPISODE.json +0 -32
  198. package/core/.kenaz/MUNINN_SNAPSHOT9_RUNE.json +0 -23
  199. package/core/.kenaz/MUNINN_SNAPSHOT9_SUMMARY.md +0 -89
  200. package/core/.kenaz/ash_TASK_1428-20260507.json +0 -14
  201. package/core/.kenaz/muninn_episode_write.ps1 +0 -17
  202. package/core/.kenaz/muninn_snapshot11_rune_candidates.md +0 -63
  203. package/core/.kenaz/muninn_snapshot1_rune_candidates.md +0 -49
  204. package/core/.kenaz/runes_TASK_1428.json +0 -57
  205. package/core/.kenaz/tmp_heimdall_proposal_8d3e392.json +0 -13
  206. package/core/.kenaz/tmp_props.json +0 -1
  207. package/core/.kenaz/tmp_sounddrop_t1_prompt.txt +0 -371
  208. package/core/.rule/MECHANIZED.md +0 -61
  209. package/core/.rule/general/cortex-memory-recall.yaml +0 -446
  210. package/core/.rule/general/pipeline.yaml +0 -246
  211. package/core/.rule/general/sunny-access-control.yaml +0 -60
  212. package/core/.rule/general/system-invariants.yaml +0 -231
  213. package/core/.rule/pipeline/PPL-002-completed-task-archival.yaml +0 -528
  214. package/core/.rule/pipeline/auto-update.yaml +0 -282
  215. package/core/.rule/pipeline/task-execution.yaml +0 -365
  216. package/core/.specialist/Ansuz/concepts/phase_protocol.yaml +0 -65
  217. package/core/.specialist/Ansuz/experiments/boot_ablation_replay.js +0 -197
  218. package/core/.specialist/Ansuz/tools/bootstrap-anchors.js +0 -289
  219. package/core/.specialist/Ansuz/workflow.yaml +0 -1225
  220. package/core/.specialist/experiments/rg_benchmark.js +0 -523
  221. package/core/.specialist/experiments/rg_benchmark_results.json +0 -27
  222. package/core/.specialist/tools/jev-optional-context.js +0 -107
  223. package/core/.specialist/tools/jev-optional-context.test.js +0 -152
  224. package/core/.specialist/tools/memory-action-log.js +0 -839
  225. package/core/.specialist/tools/phase-gate.js +0 -3534
  226. package/core/.specialist/tools/phase-gate.test.js +0 -85
  227. package/core/.specialist/tools/precompute-runner.js +0 -444
  228. package/core/.specialist/tools/rule-engine.js +0 -621
  229. package/core/.specialist/tools/task-bridge-jev.test.js +0 -170
  230. package/core/.synapse/memory-shared.json.sync +0 -1
  231. package/core/.system/agent-skills/README.md +0 -724
  232. package/core/.system/cli-tools/README.md +0 -724
  233. package/core/.system/cortex/MODULES.md +0 -1046
  234. package/core/.system/dashboard/FRONTEND.md +0 -812
  235. package/core/.system/dashboard/README.md +0 -737
  236. package/core/.system/failure/README.md +0 -723
  237. package/core/.system/formation/LEGACY_SKILLS.md +0 -974
  238. package/core/.system/formation/POST_COMPLETE.md +0 -602
  239. package/core/.system/formation/README.md +0 -1094
  240. package/core/.system/formation/TOOLS_REFERENCE.md +0 -1145
  241. package/core/.system/kenaz/README.md +0 -787
  242. package/core/.system/memory/README.md +0 -719
  243. package/core/.system/pipeline/README.md +0 -712
  244. package/core/.system/rule/README.md +0 -794
  245. package/core/.system/sunny/README.md +0 -476
  246. package/core/.system/sunny/RULES.json +0 -89
  247. package/core/.system/sunny/knowledge/INDEX.md +0 -37
  248. package/core/.system/sunny/knowledge/agent-teams-api.md +0 -0
  249. package/core/.system/sunny/knowledge/ansuz-specialist.md +0 -500
  250. package/core/.system/sunny/knowledge/claude-cli-spawn.md +0 -177
  251. package/core/.system/sunny/knowledge/collaboration-api.md +0 -925
  252. package/core/.system/sunny/teammates/README.md +0 -107
  253. package/core/.system/sunny/teammates/how_to_use.yaml +0 -101
  254. package/core/.system/sunny/teammates/tools/headless/launcher.js +0 -318
  255. package/core/.system/sunny/teammates/tools/powershell/launcher.js +0 -241
  256. package/core/.system/sunny/teammates/tools/powershell/start.bat +0 -50
  257. package/core/.system/sunny/teammates/tools/utils/env.js +0 -96
  258. package/core/.system/sunny/teammates/tools/utils/format-output.js +0 -329
  259. package/core/.system/sunny/tools.json +0 -101
  260. package/core/dev/scripts/cleanup-queue.js +0 -184
  261. package/core/dev/scripts/cleanup_queue.js +0 -86
  262. package/core/dev/scripts/legacy/README.md +0 -39
  263. package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +0 -536
  264. package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +0 -1978
  265. package/core/dev/scripts/matrix/CLI_README.md +0 -214
  266. package/core/dev/scripts/matrix/README.md +0 -310
  267. package/core/dev/scripts/matrix/package-lock.json +0 -4266
  268. package/core/dev/scripts/matrix/package.json +0 -55
  269. package/core/dev/scripts/matrix/src/abbreviations.ts +0 -295
  270. package/core/dev/scripts/matrix/src/cli/commands/convert.ts +0 -211
  271. package/core/dev/scripts/matrix/src/cli/commands/create.ts +0 -95
  272. package/core/dev/scripts/matrix/src/cli/commands/delete.ts +0 -102
  273. package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +0 -140
  274. package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +0 -173
  275. package/core/dev/scripts/matrix/src/cli/commands/query.ts +0 -261
  276. package/core/dev/scripts/matrix/src/cli/commands/read.ts +0 -77
  277. package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +0 -168
  278. package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +0 -126
  279. package/core/dev/scripts/matrix/src/cli/commands/update.ts +0 -147
  280. package/core/dev/scripts/matrix/src/cli/commands/validate.ts +0 -275
  281. package/core/dev/scripts/matrix/src/cli/index.ts +0 -350
  282. package/core/dev/scripts/matrix/src/cli/utils/file-handler.ts +0 -72
  283. package/core/dev/scripts/matrix/src/cli/utils/logger.ts +0 -65
  284. package/core/dev/scripts/matrix/src/index.ts +0 -62
  285. package/core/dev/scripts/matrix/src/indexer/tag-indexer.ts +0 -165
  286. package/core/dev/scripts/matrix/src/parser.ts +0 -281
  287. package/core/dev/scripts/matrix/src/serializer.ts +0 -151
  288. package/core/dev/scripts/matrix/src/validator.ts +0 -301
  289. package/core/dev/scripts/matrix/tests/abbreviations.test.ts +0 -122
  290. package/core/dev/scripts/matrix/tests/cli.test.ts +0 -177
  291. package/core/dev/scripts/matrix/tests/convert.test.ts +0 -143
  292. package/core/dev/scripts/matrix/tests/parser.test.ts +0 -203
  293. package/core/dev/scripts/matrix/tests/query.test.ts +0 -85
  294. package/core/dev/scripts/matrix/tests/serializer.test.ts +0 -197
  295. package/core/dev/scripts/matrix/tests/validate.test.ts +0 -141
  296. package/core/dev/scripts/matrix/tests/validator.test.ts +0 -167
  297. package/core/dev/scripts/matrix/tsconfig.json +0 -20
  298. package/core/dev/scripts/matrix/types/index.d.ts +0 -111
  299. package/core/dev/scripts/matrix/types/index.d.ts.map +0 -1
  300. package/core/dev/scripts/matrix/types/index.js +0 -8
  301. package/core/dev/scripts/matrix/types/index.js.map +0 -1
  302. package/core/dev/scripts/matrix/types/index.ts +0 -124
  303. package/core/dev/scripts/memory-usage-report.js +0 -152
  304. package/core/dev/scripts/probe/ansuz-scaffold-ablation.js +0 -579
  305. package/core/dev/scripts/probe/ansuz-scaffold-ablation.test.js +0 -244
  306. package/core/dev/scripts/probe/hook-latency-probe.js +0 -315
  307. package/core/dev/scripts/probe/hook-latency-probe.test.js +0 -105
  308. package/core/dev/scripts/probe/prediction-signal-auc.js +0 -483
  309. package/core/dev/scripts/probe/prediction-signal-auc.test.js +0 -200
  310. package/core/dev/scripts/test-pty-ws-tunnel.js +0 -229
  311. package/core/dev/scripts/validate_pipeline.js +0 -197
  312. package/core/dev/spikes/task2145-evidence-20261004/backend-log-excerpt.txt +0 -56
  313. package/core/dev/spikes/task2145-evidence-20261004/graph.shadow +0 -0
  314. package/core/dev/spikes/task2145-evidence-20261004/graph.wal +0 -0
  315. package/core/dev/spikes/task2145-evidence-20261004/graph_corrupt_suspect.marker +0 -1
  316. package/core/plugins/kenaz/commands/strategy.md +0 -141
@@ -1,737 +0,0 @@
1
- # Dashboard Tauri 後端架構
2
-
3
- > **專案位置**: `dashboard/src-tauri/src/`
4
- > **技術棧**: Rust + Tauri + Axum (HTTP Server) + Portable-Pty (Terminal)
5
- > **職責**: 桌面應用後端 API、進程管理、Scheduler 協調、終端服務
6
-
7
- ---
8
-
9
- ## 📋 系統概述
10
-
11
- Dashboard Tauri 後端是 **Kenaz AI Desktop Application** 的核心服務層,提供:
12
-
13
- 1. **Tauri Commands**:桌面應用 IPC(前端呼叫 Rust)
14
- 2. **HTTP Server**:Web 模式 API(Axum + 狀態共享)
15
- 3. **PTY Server**:終端會話管理(Portable-Pty)
16
- 4. **Scheduler 協調**:Multi-Agent 和 Single-Agent 排程器管理
17
- 5. **自動更新**:應用版本檢查與安裝
18
-
19
- ### 核心設計原則
20
-
21
- **「雙模式架構 = Desktop IPC + HTTP API」**
22
-
23
- - **Desktop 模式**:透過 Tauri Commands 呼叫 Rust 函數(零網路延遲)
24
- - **Web 模式**:透過 HTTP Server 呼叫相同邏輯(跨平台)
25
- - **狀態共享**:`HttpAppState` 持有所有 `Arc<XxxState>`,確保狀態一致性
26
-
27
- ---
28
-
29
- ## 🏗️ 架構層級
30
-
31
- ```
32
- ┌─────────────────────────────────────────────────────────────────┐
33
- │ lib.rs (Application Entry) │
34
- │ ├── Tauri Commands Registration (261 commands) │
35
- │ ├── App State Management (Arc<ProcessState>, Arc<SchedulerState>)│
36
- │ ├── HTTP Server Setup (Port Fallback + Health Monitoring) │
37
- │ ├── PTY Server Setup (Terminal Sessions) │
38
- │ └── Auto-Update Setup (Production Only) │
39
- └─────────────────────────────────────────────────────────────────┘
40
- ↓ ↓ ↓
41
- ┌─────────────────┐ ┌────────────────────┐ ┌──────────────────┐
42
- │ features/ │ │ infrastructure/ │ │ pty/ │
43
- │ (Business) │ │ (Foundation) │ │ (Terminal) │
44
- │ │ │ │ │ │
45
- │ • task │ │ • fs │ │ • commands/ │
46
- │ • proposal │ │ • git │ │ - spawn │
47
- │ • script │ │ • process_manager │ │ - io │
48
- │ • agent │ │ • path_lock_mgr │ │ - resize │
49
- │ • metrics │ │ • recovery │ │ - lifecycle │
50
- │ • progress │ │ • http_server │ │ - state │
51
- │ • config │ │ • pty_server │ │ • pty_manager │
52
- │ • autocomplete │ │ │ │ │
53
- │ • scheduler │ └────────────────────┘ └──────────────────┘
54
- │ • single_agent │
55
- │ • spec │
56
- └─────────────────┘
57
- ```
58
-
59
- ---
60
-
61
- ## 📁 目錄結構
62
-
63
- ### lib.rs(應用入口)
64
-
65
- **職責**:
66
- - 註冊所有 Tauri Commands(261 個)
67
- - 管理共享狀態(`Arc<T>` 注入)
68
- - 啟動 HTTP Server + PTY Server
69
- - 配置自動更新(Production)
70
- - Debug 模式自動開啟 DevTools
71
-
72
- **關鍵邏輯**:
73
- ```rust
74
- // 狀態注入
75
- .manage(Arc::new(ProcessState::new()))
76
- .manage(Arc::new(SchedulerAppState::new()))
77
- .manage(Arc::new(SingleAgentAppState::new()))
78
- .manage(Arc::new(PtyManagerState::new()))
79
-
80
- // HTTP Server 啟動(Port Fallback)
81
- for port_offset in 0..max_port_attempts {
82
- let port = base_port + port_offset;
83
- match HttpServer::from_env().start_with_state(http_state.clone()).await {
84
- Ok(handle) => {
85
- // Health Monitoring (每 30 秒檢查一次,3 次失敗後警告)
86
- break;
87
- }
88
- Err(e) => continue
89
- }
90
- }
91
-
92
- // PTY Server 啟動(Terminal Sessions)
93
- let pty_launcher = PtyServerLauncher::from_env();
94
- pty_launcher.start().await;
95
- pty_launcher.start_health_monitoring();
96
- ```
97
-
98
- ---
99
-
100
- ### features/(業務邏輯層)
101
-
102
- **設計模式**:每個 feature 獨立模組,遵循 `manager.rs` + `mod.rs` + `manager_tests.rs` 結構。
103
-
104
- | Feature | 模組路徑 | 職責 | 關鍵檔案 |
105
- |---------|---------|------|---------|
106
- | **task** | `features/task/` | 任務管理、佇列操作、依賴解析 | `manager.rs`, `types.rs`, `queue.rs` |
107
- | **proposal** | `features/proposal/` | 優化建議管理 | `manager.rs`, `types.rs` |
108
- | **script** | `features/script/` | 腳本執行管理(ProcessState) | `manager.rs`, `types.rs` |
109
- | **agent** | `features/agent/` | Agent 狀態管理 | `manager.rs` |
110
- | **metrics** | `features/metrics/` | Token 統計、RAG 狀態 | `manager.rs` |
111
- | **progress** | `features/progress/` | 開發進度追蹤 | `manager.rs` |
112
- | **config** | `features/config/` | 應用配置管理 | `manager.rs`, `types.rs` |
113
- | **autocomplete** | `features/autocomplete/` | 檔案路徑自動完成 | `manager.rs` |
114
- | **scheduler** | `features/scheduler/` | Multi-Agent 排程器 | `core.rs`, `commands.rs`, `agent.rs`, `events/` |
115
- | **single_agent** | `features/single_agent/` | Single-Agent 排程器 | `core.rs`, `commands.rs` |
116
- | **spec** | `features/spec/` | 規格檔案解析與驗證 | `manager.rs`, `parser.rs`, `validator.rs` |
117
-
118
- #### 重點模組:scheduler(Multi-Agent 排程器)
119
-
120
- **目錄結構**:
121
- ```
122
- scheduler/
123
- ├── mod.rs # 模組定義與 re-export
124
- ├── core.rs # Scheduler 核心邏輯(鎖定、分派、恢復)
125
- ├── config.rs # SchedulerConfig(環境變數載入)
126
- ├── agent.rs # Agent 分派邏輯(dispatch_to_agent)
127
- ├── state.rs # SchedulerAppState(Arc<Mutex<HashMap>>)
128
- ├── types.rs # 類型定義(PathLock, LockState, ProcessInfo)
129
- ├── errors.rs # 錯誤處理(SchedulerError)
130
- ├── commands.rs # Tauri Commands(start_scheduler, stop_scheduler)
131
- ├── recovery_commands.rs # 錯誤恢復 Commands(full_recovery, check_consistency)
132
- ├── multi_project.rs # 多專案管理(list_projects, stop_all_schedulers)
133
- ├── events/ # 即時事件系統
134
- │ ├── mod.rs # EVENT_* 常量定義
135
- │ ├── emitter.rs # SchedulerEventEmitter(Tauri Emit + Heartbeat)
136
- │ ├── heartbeat.rs # HeartbeatManager(每 2 秒心跳)
137
- │ ├── payloads.rs # AgentUpdatePayload, TaskUpdatePayload, etc.
138
- │ └── warnings.rs # WarningPayload, WarningCode(狀態異常警告)
139
- ├── helpers.rs # 工具函數
140
- └── helpers_tests.rs # 工具函數測試
141
- ```
142
-
143
- **關鍵機制**:
144
- - **路徑鎖定**:防止多個 Agent 同時修改同一檔案(`path_lock_manager`)
145
- - **依賴解析**:Python `dependency_resolver.py` 拓撲排序
146
- - **即時事件**:透過 Tauri Event System 推送狀態更新(`emit_scheduler_heartbeat`)
147
- - **錯誤恢復**:檢測 Stale State(長時間未更新)、清理殘留鎖定(`full_recovery`)
148
-
149
- #### 重點模組:single_agent(Single-Agent 排程器)
150
-
151
- **目錄結構**:
152
- ```
153
- single_agent/
154
- ├── mod.rs # 模組定義與 re-export
155
- ├── core.rs # SingleAgentScheduler 核心邏輯
156
- ├── state.rs # SingleAgentAppState(Arc<Mutex<HashMap>>)
157
- ├── commands.rs # Tauri Commands(start_single_agent, stop_single_agent)
158
- └── types.rs # 類型定義(SingleAgentInfo, SingleAgentStatus)
159
- ```
160
-
161
- **關鍵差異**:
162
- - **無路徑鎖定**:單 Agent 不需要並行衝突檢測
163
- - **簡化狀態**:只追蹤 Agent PID、狀態、日誌
164
- - **適用場景**:單一 Agent 連續開發(Dev Agent Mode)
165
-
166
- ---
167
-
168
- ### infrastructure/(基礎設施層)
169
-
170
- **設計模式**:跨 feature 的共用基礎能力,零業務邏輯。
171
-
172
- | 模組 | 模組路徑 | 職責 | 關鍵檔案 |
173
- |------|---------|------|---------|
174
- | **fs** | `infrastructure/fs/` | 檔案系統操作(JSON/Text 讀寫、目錄列表) | `commands.rs`, `helpers.rs`, `types.rs` |
175
- | **git** | `infrastructure/git/` | Git 操作(Branch 隔離、Repo 狀態) | `manager.rs`, `types.rs` |
176
- | **process_manager** | `infrastructure/process_manager/` | 進程生命週期管理(Spawn、Kill、Timeout) | `manager.rs`, `config.rs` |
177
- | **path_lock_manager** | `infrastructure/path_lock_manager/` | 路徑鎖定機制(衝突檢測) | `manager.rs`, `types.rs` |
178
- | **recovery** | `infrastructure/recovery/` | 錯誤恢復邏輯(Panic Catch、Shutdown Signal) | `manager.rs`, `types.rs` |
179
- | **http_server** | `infrastructure/http_server/` | HTTP API Server(Axum + 狀態共享) | `mod.rs`, `config.rs`, `routes/` |
180
- | **pty_server_launcher** | `infrastructure/pty_server_launcher/` | PTY Server 啟動器(Terminal Sessions) | `mod.rs`, `config.rs` |
181
-
182
- #### 重點模組:http_server(HTTP API Server)
183
-
184
- **目錄結構**:
185
- ```
186
- http_server/
187
- ├── mod.rs # HttpServer 啟動邏輯 + HttpAppState
188
- ├── config.rs # HttpServerConfig(環境變數載入)
189
- ├── config_tests.rs
190
- └── routes/ # Axum Routes
191
- ├── mod.rs # Router 組裝
192
- ├── agents.rs # /api/agents/*
193
- ├── health.rs # /api/health
194
- ├── scheduler.rs # /api/scheduler/*
195
- ├── single_agent.rs # /api/single-agent/*
196
- └── tasks.rs # /api/tasks/*
197
- ```
198
-
199
- **關鍵邏輯**:
200
- ```rust
201
- // HttpAppState(持有所有 Arc<XxxState>)
202
- pub struct HttpAppState {
203
- pub app_handle: Option<tauri::AppHandle>,
204
- pub scheduler_state: Arc<SchedulerAppState>,
205
- pub single_agent_state: Arc<SingleAgentAppState>,
206
- pub process_state: Arc<ProcessState>,
207
- }
208
-
209
- // Port Fallback(5500 → 5501 → 5502 ...)
210
- let base_port = HttpServerConfig::from_env().port; // 預設 5500
211
- for port_offset in 0..5 {
212
- let port = base_port + port_offset;
213
- match HttpServer::start(port).await {
214
- Ok(_) => break,
215
- Err(_) => continue
216
- }
217
- }
218
-
219
- // Health Monitoring(每 30 秒檢查,3 次失敗警告)
220
- tokio::spawn(async move {
221
- loop {
222
- tokio::time::sleep(Duration::from_secs(30)).await;
223
- match TcpStream::connect(&addr).await {
224
- Ok(_) => consecutive_failures = 0,
225
- Err(_) => {
226
- consecutive_failures += 1;
227
- if consecutive_failures >= 3 {
228
- eprintln!("[HTTP Server] crashed after 3 failures");
229
- break;
230
- }
231
- }
232
- }
233
- }
234
- });
235
- ```
236
-
237
- #### 重點模組:pty_server_launcher(PTY Server)
238
-
239
- **職責**:
240
- - 啟動 PTY Server(`pty-server/index.ts`)
241
- - 提供 Terminal Session API(Web 模式用)
242
- - Health Monitoring(每 15 秒檢查)
243
-
244
- **環境變數**:
245
- ```bash
246
- KENAZ_PTY_PORT=5501 # PTY Server 監聽 Port
247
- KENAZ_PTY_HEALTH_CHECK_INTERVAL=15 # Health Check 間隔(秒)
248
- ```
249
-
250
- **啟動流程**:
251
- ```rust
252
- // 偵測 pty-server/ 目錄是否存在
253
- let pty_server_dir = current_dir.join("pty-server");
254
- if !pty_server_dir.exists() {
255
- return Err(PtyServerError::NotFound);
256
- }
257
-
258
- // 啟動 Node.js 進程
259
- let child = Command::new("node")
260
- .arg("index.ts")
261
- .current_dir(&pty_server_dir)
262
- .spawn()?;
263
-
264
- // Health Monitoring
265
- tokio::spawn(async move {
266
- loop {
267
- tokio::time::sleep(Duration::from_secs(15)).await;
268
- match TcpStream::connect(&addr).await {
269
- Ok(_) => {},
270
- Err(_) => eprintln!("[PTY Server] Health check FAILED")
271
- }
272
- }
273
- });
274
- ```
275
-
276
- ---
277
-
278
- ### pty/(終端管理層)
279
-
280
- **職責**:提供 Desktop 模式的終端會話管理(Tauri 原生 PTY)。
281
-
282
- **目錄結構**:
283
- ```
284
- pty/
285
- ├── mod.rs # PTY 核心實作(portable_pty)
286
- ├── pty_manager.rs # PtyManagerState(Arc<RwLock<HashMap>>)
287
- └── commands/ # Tauri Commands
288
- ├── mod.rs # 模組定義
289
- ├── spawn.rs # pty_spawn(建立新會話)
290
- ├── io.rs # pty_write(寫入輸入)
291
- ├── resize.rs # pty_resize(調整視窗大小)
292
- ├── lifecycle.rs # pty_close(關閉會話)
293
- └── state.rs # pty_list, pty_get_session(查詢狀態)
294
- ```
295
-
296
- **關鍵實作**:
297
- ```rust
298
- // PtyManager(使用 portable_pty)
299
- pub struct PtyManager {
300
- sessions: Arc<RwLock<HashMap<String, PtySession>>>,
301
- }
302
-
303
- // 建立新會話
304
- pub fn spawn(&self, id: &str, shell: &str, cwd: &str) -> Result<(), PtyError> {
305
- let pair = self.pty_system.openpty(PtySize::default())?;
306
- let cmd = CommandBuilder::new(shell);
307
- let child = pair.slave.spawn_command(cmd)?;
308
-
309
- // 啟動輸出監聽(Event Emit)
310
- let reader = pair.master.try_clone_reader()?;
311
- tokio::spawn(async move {
312
- // 讀取輸出 → Tauri Event Emit
313
- });
314
-
315
- self.sessions.write().insert(id, session);
316
- Ok(())
317
- }
318
- ```
319
-
320
- ---
321
-
322
- ### commands/(全域 Commands)
323
-
324
- **職責**:不屬於任何 feature 的全域性命令。
325
-
326
- **檔案**:
327
- - `commands/mod.rs`:系統資訊、心跳更新、環境檢查
328
-
329
- **關鍵 Commands**:
330
- ```rust
331
- #[tauri::command]
332
- fn get_system_info() -> SystemInfo {
333
- SystemInfo {
334
- os: std::env::consts::OS,
335
- arch: std::env::consts::ARCH,
336
- version: env!("CARGO_PKG_VERSION"),
337
- }
338
- }
339
-
340
- #[tauri::command]
341
- fn update_heartbeat(project_path: String) -> Result<(), String> {
342
- // 更新專案心跳時間戳
343
- }
344
-
345
- #[tauri::command]
346
- fn check_environment() -> EnvironmentCheckResult {
347
- // 檢查 Node.js, Python, Git 版本
348
- }
349
- ```
350
-
351
- ---
352
-
353
- ### updater/(自動更新)
354
-
355
- **職責**:Production 模式自動檢查與安裝應用更新(tauri-plugin-updater)。
356
-
357
- **關鍵邏輯**:
358
- ```rust
359
- // 每 5 秒檢查一次更新
360
- #[cfg(not(debug_assertions))]
361
- {
362
- let handle = app.handle().clone();
363
- tauri::async_runtime::spawn(async move {
364
- tokio::time::sleep(Duration::from_secs(5)).await;
365
- let _ = updater::check_for_updates(handle).await;
366
- });
367
- }
368
- ```
369
-
370
- **環境配置**:
371
- - 更新 Manifest:`tauri.conf.json` → `updater.endpoints`
372
- - Windows Installer:生成 `.msi` 或 `.exe`
373
-
374
- ---
375
-
376
- ## 🔄 狀態管理策略
377
-
378
- ### 狀態共享模式
379
-
380
- 所有共享狀態使用 `Arc<T>` 包裝,確保跨執行緒安全:
381
-
382
- | 狀態類型 | Arc<T> | 內部鎖 | 用途 |
383
- |---------|--------|--------|------|
384
- | `ProcessState` | `Arc<ProcessState>` | `RwLock<HashMap>` | 腳本執行進程追蹤 |
385
- | `SchedulerAppState` | `Arc<SchedulerAppState>` | `Mutex<HashMap>` | Multi-Agent Scheduler 狀態 |
386
- | `SingleAgentAppState` | `Arc<SingleAgentAppState>` | `Mutex<HashMap>` | Single-Agent Scheduler 狀態 |
387
- | `PtyManagerState` | `Arc<PtyManagerState>` | `RwLock<HashMap>` | PTY 會話追蹤 |
388
- | `HttpAppState` | - | `Arc<T>` 組合 | HTTP Server 持有所有狀態的引用 |
389
-
390
- ### 狀態注入流程
391
-
392
- ```rust
393
- // 1. 建立狀態
394
- let process_state = Arc::new(ProcessState::new());
395
- let scheduler_state = Arc::new(SchedulerAppState::new());
396
- let single_agent_state = Arc::new(SingleAgentAppState::new());
397
- let pty_state = Arc::new(PtyManagerState::new());
398
-
399
- // 2. 注入 Tauri App
400
- tauri::Builder::default()
401
- .manage(process_state.clone())
402
- .manage(scheduler_state.clone())
403
- .manage(single_agent_state.clone())
404
- .manage(pty_state.clone())
405
-
406
- // 3. HTTP Server 狀態共享
407
- let http_state = HttpAppState::with_full_state(
408
- app_handle,
409
- scheduler_state,
410
- single_agent_state,
411
- process_state
412
- );
413
-
414
- // 4. Tauri Command 中取得狀態
415
- #[tauri::command]
416
- fn my_command(state: tauri::State<Arc<ProcessState>>) -> Result<(), String> {
417
- let processes = state.inner().processes.read().unwrap();
418
- // ...
419
- }
420
- ```
421
-
422
- ---
423
-
424
- ## 🚀 啟動流程
425
-
426
- ### Desktop 模式啟動
427
-
428
- ```bash
429
- cd dashboard
430
- npm run tauri dev # 開發模式
431
- npm run tauri build # 生產模式
432
- ```
433
-
434
- **啟動順序**:
435
- 1. Tauri 啟動(Rust 後端)
436
- 2. 注入共享狀態(`Arc<ProcessState>`, `Arc<SchedulerAppState>` 等)
437
- 3. 註冊 261 個 Tauri Commands
438
- 4. 啟動 PTY Server(Terminal Sessions)→ Port 5501
439
- 5. 啟動 HTTP Server(Web API)→ Port 5500(Fallback 5501-5504)
440
- 6. HTTP Health Monitoring 開始(每 30 秒檢查)
441
- 7. PTY Health Monitoring 開始(每 15 秒檢查)
442
- 8. [Production Only] 自動更新檢查(5 秒後)
443
- 9. [Debug Only] 自動開啟 DevTools
444
-
445
- ### Web 模式啟動
446
-
447
- **前端連接 HTTP Server**(`http://127.0.0.1:5500`):
448
- ```typescript
449
- // dashboard/src/lib/api.ts
450
- export async function getTasks(projectPath: string) {
451
- const response = await fetch(`http://127.0.0.1:5500/api/tasks?path=${projectPath}`);
452
- return response.json();
453
- }
454
- ```
455
-
456
- **Port Fallback 策略**:
457
- ```rust
458
- // 嘗試 5500 → 5501 → 5502 → 5503 → 5504
459
- for port_offset in 0..5 {
460
- let port = 5500 + port_offset;
461
- match HttpServer::start(port).await {
462
- Ok(handle) => {
463
- println!("HTTP Server started on {}", port);
464
- break;
465
- }
466
- Err(_) => continue
467
- }
468
- }
469
- ```
470
-
471
- ---
472
-
473
- ## 📡 API 設計
474
-
475
- ### Tauri Commands(Desktop IPC)
476
-
477
- **呼叫方式**(TypeScript):
478
- ```typescript
479
- import { invoke } from '@tauri-apps/api/core';
480
-
481
- // 取得任務列表
482
- const tasks = await invoke<Task[]>('get_tasks', { projectPath: '/path/to/project' });
483
-
484
- // 啟動 Scheduler
485
- const result = await invoke<StartSchedulerResponse>('start_scheduler', {
486
- projectPath: '/path/to/project',
487
- config: { maxAgents: 3 }
488
- });
489
- ```
490
-
491
- **註冊方式**(Rust):
492
- ```rust
493
- .invoke_handler(tauri::generate_handler![
494
- get_tasks,
495
- start_scheduler,
496
- stop_scheduler,
497
- // ... 258 個其他 Commands
498
- ])
499
- ```
500
-
501
- ### HTTP REST API(Web 模式)
502
-
503
- **Base URL**:`http://127.0.0.1:5500`
504
-
505
- | Endpoint | Method | 說明 |
506
- |----------|--------|------|
507
- | `/api/health` | GET | 健康檢查 |
508
- | `/api/tasks` | GET | 取得任務列表 |
509
- | `/api/tasks/:id` | GET | 取得任務詳情 |
510
- | `/api/agents` | GET | 取得 Agent 列表 |
511
- | `/api/scheduler/start` | POST | 啟動 Scheduler |
512
- | `/api/scheduler/stop` | POST | 停止 Scheduler |
513
- | `/api/scheduler/status` | GET | 取得 Scheduler 狀態 |
514
- | `/api/single-agent/start` | POST | 啟動 Single-Agent |
515
- | `/api/single-agent/stop` | POST | 停止 Single-Agent |
516
-
517
- **範例請求**:
518
- ```bash
519
- # 取得任務列表
520
- curl "http://127.0.0.1:5500/api/tasks?path=/path/to/project"
521
-
522
- # 啟動 Scheduler
523
- curl -X POST "http://127.0.0.1:5500/api/scheduler/start" \
524
- -H "Content-Type: application/json" \
525
- -d '{"project_path": "/path/to/project", "max_agents": 3}'
526
- ```
527
-
528
- ---
529
-
530
- ## 🛠️ 錯誤處理
531
-
532
- ### 錯誤類型定義
533
-
534
- 每個模組定義專屬錯誤類型,統一格式:
535
-
536
- ```rust
537
- // features/scheduler/errors.rs
538
- #[derive(Debug, Serialize, Deserialize)]
539
- pub enum SchedulerErrorCode {
540
- LockConflict,
541
- TaskNotFound,
542
- AgentTimeout,
543
- InvalidState,
544
- }
545
-
546
- #[derive(Debug, Serialize, Deserialize)]
547
- pub struct SchedulerError {
548
- pub code: SchedulerErrorCode,
549
- pub message: String,
550
- pub details: Option<String>,
551
- }
552
- ```
553
-
554
- ### 錯誤傳播
555
-
556
- Tauri Command 回傳 `Result<T, String>`:
557
-
558
- ```rust
559
- #[tauri::command]
560
- pub fn start_scheduler(
561
- project_path: String,
562
- state: tauri::State<Arc<SchedulerAppState>>
563
- ) -> Result<StartSchedulerResponse, String> {
564
- Scheduler::start(&project_path)
565
- .map_err(|e| e.to_string())?;
566
-
567
- Ok(StartSchedulerResponse { success: true })
568
- }
569
- ```
570
-
571
- ### Panic Recovery
572
-
573
- 所有關鍵邏輯包裹在 `catch_panic`:
574
-
575
- ```rust
576
- use crate::infrastructure::recovery::catch_panic;
577
-
578
- pub fn critical_operation() -> Result<(), String> {
579
- catch_panic(|| {
580
- // 可能 panic 的代碼
581
- risky_operation();
582
- }, "critical_operation")
583
- .map_err(|e| format!("Operation failed: {}", e))
584
- }
585
- ```
586
-
587
- ---
588
-
589
- ## 🧪 測試策略
590
-
591
- ### 測試檔案命名
592
-
593
- 所有模組遵循 `*_tests.rs` 命名:
594
-
595
- ```
596
- manager.rs → manager_tests.rs
597
- config.rs → config_tests.rs
598
- helpers.rs → helpers_tests.rs
599
- ```
600
-
601
- ### 測試覆蓋範圍
602
-
603
- | 模組 | 單元測試 | 整合測試 | E2E 測試 |
604
- |------|---------|---------|---------|
605
- | `features/scheduler` | ✅ | ✅ | ⏳ |
606
- | `infrastructure/fs` | ✅ | ✅ | - |
607
- | `infrastructure/process_manager` | ✅ | ✅ | - |
608
- | `pty/` | ✅ | ⏳ | - |
609
- | `http_server` | ⏳ | ⏳ | - |
610
-
611
- ### 執行測試
612
-
613
- ```bash
614
- cd dashboard/src-tauri
615
-
616
- # 執行所有測試
617
- cargo test
618
-
619
- # 執行特定模組測試
620
- cargo test --package kenaz-dashboard --lib features::scheduler::helpers_tests
621
-
622
- # 顯示輸出
623
- cargo test -- --nocapture
624
- ```
625
-
626
- ---
627
-
628
- ## 📊 效能考量
629
-
630
- ### 狀態鎖定策略
631
-
632
- - **讀多寫少**:使用 `RwLock`(如 `PtyManagerState`)
633
- - **寫操作頻繁**:使用 `Mutex`(如 `SchedulerAppState`)
634
- - **避免死鎖**:統一鎖定順序,限制鎖持有時間
635
-
636
- ### 並行處理
637
-
638
- ```rust
639
- // HTTP Server 使用 Tokio 異步執行
640
- #[tokio::main]
641
- async fn main() {
642
- let listener = TcpListener::bind("127.0.0.1:5500").await.unwrap();
643
- axum::serve(listener, app).await.unwrap();
644
- }
645
-
646
- // Tauri Commands 在獨立執行緒執行
647
- tauri::async_runtime::spawn(async move {
648
- // 長時間運行的任務
649
- });
650
- ```
651
-
652
- ### Port Fallback 優化
653
-
654
- 避免無限等待,設置最大嘗試次數:
655
-
656
- ```rust
657
- let max_port_attempts = 5;
658
- for port_offset in 0..max_port_attempts {
659
- // 嘗試啟動
660
- }
661
-
662
- if _http_handle.is_none() {
663
- eprintln!("FATAL: Failed to start after {} attempts", max_port_attempts);
664
- }
665
- ```
666
-
667
- ---
668
-
669
- ## 🔍 監控與日誌
670
-
671
- ### Health Monitoring
672
-
673
- **HTTP Server**:
674
- - 檢查間隔:30 秒
675
- - 失敗閾值:3 次連續失敗
676
- - 檢查方式:TCP 連線測試
677
-
678
- **PTY Server**:
679
- - 檢查間隔:15 秒
680
- - 檢查方式:TCP 連線測試
681
-
682
- ### 日誌格式
683
-
684
- ```rust
685
- // 統一使用 eprintln! 輸出
686
- eprintln!("[HTTP Server] Started on http://127.0.0.1:{}", port);
687
- eprintln!("[PTY Server] Health check FAILED - connection refused");
688
- eprintln!("[Scheduler] Agent dispatched: {:?}", agent_info);
689
- ```
690
-
691
- ### Tauri Event System(即時推送)
692
-
693
- ```rust
694
- // Scheduler 狀態更新
695
- app_handle.emit("scheduler:agent_update", AgentUpdatePayload {
696
- agent_id: "agent_001",
697
- action: "dispatched",
698
- timestamp: Utc::now().timestamp(),
699
- });
700
-
701
- // 前端監聽
702
- import { listen } from '@tauri-apps/api/event';
703
-
704
- listen('scheduler:agent_update', (event) => {
705
- console.log('Agent update:', event.payload);
706
- });
707
- ```
708
-
709
- ---
710
-
711
- ## 🚧 已知限制與未來改進
712
-
713
- ### 已知限制
714
-
715
- 1. **HTTP Server 單執行緒**:目前無多執行緒支援(Axum 預設單執行緒)
716
- 2. **PTY Server 重啟**:PTY Server 崩潰後不會自動重啟(需手動重啟)
717
- 3. **日誌持久化**:目前只輸出到 stderr,未寫入檔案
718
- 4. **測試覆蓋率**:部分模組測試不完整(如 `http_server`)
719
-
720
- ### 未來改進
721
-
722
- - [ ] 實作日誌輪轉(Log Rotation)
723
- - [ ] 增加 Metrics 收集(Prometheus)
724
- - [ ] HTTP Server 支援 HTTPS
725
- - [ ] PTY Server 自動重啟機制
726
- - [ ] 完善 E2E 測試覆蓋率
727
-
728
- ---
729
-
730
- ## 📚 相關文檔
731
-
732
- - [Tauri 官方文檔](https://tauri.app/)
733
- - [Axum Web Framework](https://github.com/tokio-rs/axum)
734
- - [Portable-Pty](https://github.com/wez/wezterm/tree/main/pty)
735
- - [Scheduler 系統設計](../.system/pipeline/README.md)
736
- - [Formation 系統](../.system/formation/README.md)
737
- - [失敗學習系統](../.system/failure/README.md)