principles-disciple 1.72.0 → 1.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/openclaw.plugin.json +10 -5
  2. package/package.json +17 -19
  3. package/scripts/acceptance-test.mjs +16 -73
  4. package/scripts/sync-plugin.mjs +382 -77
  5. package/src/commands/archive-impl.ts +2 -1
  6. package/src/commands/capabilities.ts +2 -2
  7. package/src/commands/context.ts +2 -2
  8. package/src/commands/disable-impl.ts +2 -1
  9. package/src/commands/evolution-status.ts +16 -16
  10. package/src/commands/export.ts +12 -67
  11. package/src/commands/pain.ts +91 -1
  12. package/src/commands/principle-rollback.ts +2 -1
  13. package/src/commands/promote-impl.ts +7 -43
  14. package/src/commands/rollback-impl.ts +2 -1
  15. package/src/commands/rollback.ts +2 -1
  16. package/src/commands/samples.ts +2 -1
  17. package/src/commands/thinking-os.ts +2 -1
  18. package/src/config/errors.ts +18 -2
  19. package/src/constants/diagnostician.ts +2 -2
  20. package/src/constants/tools.ts +2 -1
  21. package/src/core/__tests__/focus-history.test.ts +210 -0
  22. package/src/core/config.ts +1 -1
  23. package/src/core/confirm-first-gate.ts +255 -0
  24. package/src/core/correction-cue-learner.ts +2 -136
  25. package/src/core/correction-types.ts +16 -88
  26. package/src/core/dictionary.ts +19 -20
  27. package/src/core/empathy-keyword-matcher.ts +17 -289
  28. package/src/core/empathy-types.ts +18 -229
  29. package/src/core/event-log.ts +38 -132
  30. package/src/core/evolution-reducer.ts +21 -2
  31. package/src/core/evolution-types.ts +76 -464
  32. package/src/core/file-store.ts +80 -0
  33. package/src/core/focus-history.ts +228 -955
  34. package/src/core/local-worker-routing.ts +34 -314
  35. package/src/core/merge-gate-audit.ts +0 -195
  36. package/src/core/pain-diagnostic-gate.ts +154 -0
  37. package/src/core/pain-signal.ts +21 -138
  38. package/src/core/pain.ts +15 -88
  39. package/src/core/pd-task-reconciler.ts +26 -115
  40. package/src/core/pd-task-service.ts +9 -9
  41. package/src/core/pd-task-types.ts +23 -127
  42. package/src/core/principle-compiler/__tests__/compiler-replay-gate.test.ts +174 -0
  43. package/src/core/principle-compiler/code-validator.ts +15 -42
  44. package/src/core/principle-compiler/compiler.ts +100 -15
  45. package/src/core/principle-compiler/index.ts +5 -2
  46. package/src/core/principle-compiler/template-generator.ts +4 -104
  47. package/src/core/principle-injection.ts +10 -202
  48. package/src/core/principle-internalization/filesystem-lifecycle-datasource.ts +42 -0
  49. package/src/core/principle-internalization/lifecycle-read-model.ts +39 -242
  50. package/src/core/principle-internalization/principle-lifecycle-service.ts +12 -10
  51. package/src/core/principle-tree-ledger-adapter.ts +145 -0
  52. package/src/core/principle-tree-ledger.ts +8 -6
  53. package/src/core/reflection/reflection-context.ts +14 -109
  54. package/src/core/replay-engine.ts +8 -500
  55. package/src/core/rule-host-helpers.ts +5 -35
  56. package/src/core/rule-host-types.ts +10 -82
  57. package/src/core/rule-host.ts +6 -63
  58. package/src/core/runtime-v2-prompt-activation-reader.ts +231 -0
  59. package/src/core/session-tracker.ts +87 -101
  60. package/src/core/shadow-observation-registry.ts +19 -48
  61. package/src/core/trajectory.ts +3 -1
  62. package/src/core/workflow-funnel-loader.ts +62 -68
  63. package/src/core/workspace-context.ts +46 -0
  64. package/src/core/workspace-dir-service.ts +1 -1
  65. package/src/core/workspace-dir-validation.ts +18 -9
  66. package/src/hooks/AGENTS.md +1 -1
  67. package/src/hooks/gate-block-helper.ts +46 -44
  68. package/src/hooks/gate.ts +207 -7
  69. package/src/hooks/lifecycle.ts +30 -32
  70. package/src/hooks/llm.ts +60 -32
  71. package/src/hooks/pain.ts +297 -103
  72. package/src/hooks/prompt.ts +459 -439
  73. package/src/hooks/subagent.ts +2 -29
  74. package/src/i18n/commands.ts +2 -10
  75. package/src/index.ts +95 -85
  76. package/src/openclaw-sdk.ts +311 -0
  77. package/src/service/central-database.ts +8 -4
  78. package/src/service/evolution-queue-migration.ts +2 -1
  79. package/src/service/evolution-worker.ts +163 -1786
  80. package/src/service/internalization-trigger-adapter.ts +302 -0
  81. package/src/service/keyword-optimization-service.ts +4 -4
  82. package/src/service/monitoring-query-service.ts +1 -215
  83. package/src/service/queue-io.ts +60 -331
  84. package/src/service/runtime-summary-service.ts +59 -16
  85. package/src/service/subagent-workflow/index.ts +0 -41
  86. package/src/service/subagent-workflow/types.ts +9 -120
  87. package/src/service/subagent-workflow/workflow-store.ts +2 -119
  88. package/src/service/workflow-watchdog.ts +0 -43
  89. package/src/types/event-payload.ts +16 -74
  90. package/src/types/event-types.ts +39 -547
  91. package/src/types/hygiene-types.ts +7 -30
  92. package/src/types/principle-tree-schema.ts +20 -222
  93. package/src/types/queue.ts +15 -70
  94. package/src/types/runtime-summary.ts +5 -49
  95. package/src/utils/io.ts +10 -0
  96. package/src/utils/retry.ts +1 -1
  97. package/src/utils/shadow-fingerprint.ts +2 -2
  98. package/src/utils/workspace-resolver.ts +50 -0
  99. package/templates/langs/en/core/AGENTS.md +2 -2
  100. package/templates/langs/en/core/BOOT.md +1 -1
  101. package/templates/langs/en/core/HEARTBEAT.md +2 -2
  102. package/templates/langs/en/skills/ai-sprint-orchestration/references/agent-registry.json +1 -72
  103. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/bugfix-complex-template.json +6 -6
  104. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/feature-complex-template.json +6 -6
  105. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal-verify.json +2 -12
  106. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal.json +2 -12
  107. package/templates/langs/en/skills/ai-sprint-orchestration/runtime/.gitignore +2 -2
  108. package/templates/langs/en/skills/ai-sprint-orchestration/scripts/run.mjs +51 -15
  109. package/templates/langs/en/skills/evolve-task/SKILL.md +1 -1
  110. package/templates/langs/en/skills/pd-cli-operator/SKILL.md +67 -0
  111. package/templates/langs/en/skills/pd-diagnostician/SKILL.md +1 -1
  112. package/templates/langs/en/skills/pd-mentor/SKILL.md +1 -1
  113. package/templates/langs/en/skills/pd-pain-signal/SKILL.md +17 -39
  114. package/templates/langs/en/skills/pd-runtime-v2/SKILL.md +61 -0
  115. package/templates/langs/zh/core/AGENTS.md +2 -2
  116. package/templates/langs/zh/core/BOOT.md +1 -1
  117. package/templates/langs/zh/core/HEARTBEAT.md +2 -2
  118. package/templates/langs/zh/skills/ai-sprint-orchestration/references/agent-registry.json +1 -72
  119. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/bugfix-complex-template.json +6 -6
  120. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/feature-complex-template.json +6 -6
  121. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/nocturnal-trinity-quality-enhancement.json +8 -8
  122. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal-verify.json +2 -12
  123. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal.json +2 -12
  124. package/templates/langs/zh/skills/ai-sprint-orchestration/runtime/.gitignore +2 -2
  125. package/templates/langs/zh/skills/ai-sprint-orchestration/scripts/run.mjs +51 -15
  126. package/templates/langs/zh/skills/ai-sprint-orchestration/test/run.test.mjs +21 -5
  127. package/templates/langs/zh/skills/evolve-task/SKILL.md +2 -2
  128. package/templates/langs/zh/skills/pd-cli-operator/SKILL.md +67 -0
  129. package/templates/langs/zh/skills/pd-diagnostician/SKILL.md +1 -1
  130. package/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -1
  131. package/templates/langs/zh/skills/pd-pain-signal/SKILL.md +17 -38
  132. package/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +61 -0
  133. package/tests/build-artifacts.test.ts +1 -3
  134. package/tests/commands/evolution-status.test.ts +0 -118
  135. package/tests/core/bootstrap-rules.test.ts +1 -1
  136. package/tests/core/config.test.ts +1 -1
  137. package/tests/core/event-log.test.ts +35 -0
  138. package/tests/core/evolution-engine.test.ts +610 -0
  139. package/tests/core/file-store.test.ts +102 -0
  140. package/tests/core/focus-history.test.ts +203 -11
  141. package/tests/core/merge-gate-audit.test.ts +2 -169
  142. package/tests/core/model-deployment-registry.test.ts +7 -1
  143. package/tests/core/model-training-registry.test.ts +19 -0
  144. package/tests/core/observability.test.ts +0 -1
  145. package/tests/core/pain-diagnostic-gate.test.ts +498 -0
  146. package/tests/core/pain.test.ts +0 -1
  147. package/tests/core/principle-internalization/deprecated-readiness.test.ts +2 -2
  148. package/tests/core/principle-internalization/lifecycle-metrics.test.ts +2 -2
  149. package/tests/core/principle-internalization/{internalization-routing-policy.test.ts → lifecycle-routing-policy.test.ts} +6 -6
  150. package/tests/core/principle-internalization/lineage-source-retired.test.ts +56 -0
  151. package/tests/core/principle-internalization/principle-lifecycle-service.test.ts +1 -23
  152. package/tests/core/principle-tree-ledger-adapter.test.ts +253 -0
  153. package/tests/core/reflection-context.test.ts +0 -14
  154. package/tests/core/replay-engine.test.ts +127 -215
  155. package/tests/core/rule-host-helpers.test.ts +2 -2
  156. package/tests/core/rule-implementation-runtime.test.ts +0 -27
  157. package/tests/core/workflow-funnel-loader.test.ts +162 -0
  158. package/tests/core/workspace-dir-validation.test.ts +8 -1
  159. package/tests/core-anti-growth.test.ts +192 -0
  160. package/tests/hook-workspace-nextaction-contract.test.ts +42 -0
  161. package/tests/hooks/confirm-first-gate.test.ts +333 -0
  162. package/tests/hooks/gate-auto-correct-shadow.test.ts +310 -0
  163. package/tests/hooks/gate-auto-correct.test.ts +665 -0
  164. package/tests/hooks/gate-rule-host-pipeline.test.ts +2 -1
  165. package/tests/hooks/pain.test.ts +269 -12
  166. package/tests/hooks/prompt-characterization.test.ts +500 -0
  167. package/tests/hooks/prompt-size-guard.test.ts +32 -17
  168. package/tests/hooks/runtime-v2-prompt-activation.test.ts +869 -0
  169. package/tests/index.test.ts +94 -1
  170. package/tests/integration/auto-entry-gate.test.ts +248 -0
  171. package/tests/integration/internalization-trigger-guard.test.ts +69 -0
  172. package/tests/integration/m8-legacy-paths.test.ts +63 -0
  173. package/tests/integration/runtime-v2-pain-guard.test.ts +125 -0
  174. package/tests/plugin-config-resolution-cutover.test.ts +359 -0
  175. package/tests/runtime-v2-discovery-guard.test.ts +154 -0
  176. package/tests/service/central-database.test.ts +457 -0
  177. package/tests/service/evolution-worker.correction-observer.test.ts +173 -0
  178. package/tests/service/evolution-worker.timeout.test.ts +11 -129
  179. package/tests/service/internalization-trigger-adapter.test.ts +251 -0
  180. package/tests/service/monitoring-query-service.test.ts +1 -47
  181. package/tests/service/queue-io.test.ts +1 -62
  182. package/tests/service/runtime-summary-service.test.ts +3 -1
  183. package/tests/service/workflow-watchdog.test.ts +0 -91
  184. package/tests/utils/file-lock.test.ts +5 -3
  185. package/tests/utils/session-key.test.ts +52 -0
  186. package/tests/utils/subagent-probe.test.ts +48 -1
  187. package/vitest.config.ts +4 -11
  188. package/.planning/codebase/ARCHITECTURE.md +0 -157
  189. package/.planning/codebase/CONCERNS.md +0 -145
  190. package/.planning/codebase/CONVENTIONS.md +0 -148
  191. package/.planning/codebase/INTEGRATIONS.md +0 -81
  192. package/.planning/codebase/STACK.md +0 -87
  193. package/.planning/codebase/STRUCTURE.md +0 -193
  194. package/.planning/codebase/TESTING.md +0 -243
  195. package/.planning/phases/01-basic-visualization/01-GAP-CLOSURE-VERIFICATION.md +0 -113
  196. package/docs/COMMAND_REFERENCE.md +0 -76
  197. package/docs/COMMAND_REFERENCE_EN.md +0 -79
  198. package/scripts/build-web.mjs +0 -46
  199. package/scripts/diagnose-nocturnal.mjs +0 -537
  200. package/scripts/seed-nocturnal-scenarios.mjs +0 -384
  201. package/src/commands/nocturnal-review.ts +0 -322
  202. package/src/commands/nocturnal-rollout.ts +0 -790
  203. package/src/commands/nocturnal-train.ts +0 -986
  204. package/src/commands/pd-reflect.ts +0 -88
  205. package/src/core/adaptive-thresholds.ts +0 -478
  206. package/src/core/diagnostician-task-store.ts +0 -192
  207. package/src/core/nocturnal-arbiter.ts +0 -715
  208. package/src/core/nocturnal-artifact-lineage.ts +0 -116
  209. package/src/core/nocturnal-artificer.ts +0 -257
  210. package/src/core/nocturnal-candidate-scoring.ts +0 -530
  211. package/src/core/nocturnal-compliance.ts +0 -1146
  212. package/src/core/nocturnal-dataset.ts +0 -763
  213. package/src/core/nocturnal-executability.ts +0 -428
  214. package/src/core/nocturnal-export.ts +0 -499
  215. package/src/core/nocturnal-paths.ts +0 -240
  216. package/src/core/nocturnal-reasoning-deriver.ts +0 -343
  217. package/src/core/nocturnal-rule-implementation-validator.ts +0 -246
  218. package/src/core/nocturnal-snapshot-contract.ts +0 -99
  219. package/src/core/nocturnal-trajectory-extractor.ts +0 -512
  220. package/src/core/nocturnal-trinity-types.ts +0 -218
  221. package/src/core/nocturnal-trinity.ts +0 -2680
  222. package/src/core/principle-internalization/deprecated-readiness.ts +0 -93
  223. package/src/core/principle-internalization/internalization-routing-policy.ts +0 -208
  224. package/src/core/principle-internalization/lifecycle-metrics.ts +0 -152
  225. package/src/http/principles-console-route.ts +0 -709
  226. package/src/service/central-health-service.ts +0 -49
  227. package/src/service/central-overview-service.ts +0 -138
  228. package/src/service/control-ui-query-service.ts +0 -900
  229. package/src/service/cooldown-strategy.ts +0 -97
  230. package/src/service/evolution-pain-context.ts +0 -79
  231. package/src/service/evolution-query-service.ts +0 -407
  232. package/src/service/health-query-service.ts +0 -1038
  233. package/src/service/nocturnal-config.ts +0 -214
  234. package/src/service/nocturnal-runtime.ts +0 -734
  235. package/src/service/nocturnal-service.ts +0 -1605
  236. package/src/service/nocturnal-target-selector.ts +0 -545
  237. package/src/service/sleep-cycle.ts +0 -157
  238. package/src/service/startup-reconciler.ts +0 -112
  239. package/src/service/subagent-workflow/correction-observer-types.ts +0 -82
  240. package/src/service/subagent-workflow/correction-observer-workflow-manager.ts +0 -250
  241. package/src/service/subagent-workflow/deep-reflect-workflow-manager.ts +0 -1
  242. package/src/service/subagent-workflow/dynamic-timeout.ts +0 -30
  243. package/src/service/subagent-workflow/empathy-observer-workflow-manager.ts +0 -268
  244. package/src/service/subagent-workflow/nocturnal-workflow-manager.ts +0 -795
  245. package/src/service/subagent-workflow/runtime-direct-driver.ts +0 -268
  246. package/src/service/subagent-workflow/workflow-manager-base.ts +0 -580
  247. package/src/tools/write-pain-flag.ts +0 -215
  248. package/tests/commands/nocturnal-review.test.ts +0 -448
  249. package/tests/commands/nocturnal-train.test.ts +0 -97
  250. package/tests/commands/pd-reflect.test.ts +0 -49
  251. package/tests/core/adaptive-thresholds.test.ts +0 -261
  252. package/tests/core/nocturnal-arbiter.test.ts +0 -559
  253. package/tests/core/nocturnal-artifact-lineage.test.ts +0 -53
  254. package/tests/core/nocturnal-artificer.test.ts +0 -241
  255. package/tests/core/nocturnal-candidate-scoring.test.ts +0 -532
  256. package/tests/core/nocturnal-compliance-p-principles.test.ts +0 -133
  257. package/tests/core/nocturnal-compliance.test.ts +0 -646
  258. package/tests/core/nocturnal-dataset.test.ts +0 -892
  259. package/tests/core/nocturnal-e2e.test.ts +0 -234
  260. package/tests/core/nocturnal-executability.test.ts +0 -357
  261. package/tests/core/nocturnal-export.test.ts +0 -517
  262. package/tests/core/nocturnal-reasoning-deriver.test.ts +0 -372
  263. package/tests/core/nocturnal-reviewed-subset-comparison.test.ts +0 -428
  264. package/tests/core/nocturnal-rule-implementation-validator.test.ts +0 -127
  265. package/tests/core/nocturnal-snapshot-contract.test.ts +0 -121
  266. package/tests/core/nocturnal-trajectory-extractor.test.ts +0 -634
  267. package/tests/core/nocturnal-trinity.test.ts +0 -2053
  268. package/tests/core/pain-auto-repair.test.ts +0 -96
  269. package/tests/core/pain-integration.test.ts +0 -510
  270. package/tests/fixtures/nocturnal-reviewed-subset.json +0 -183
  271. package/tests/http/principles-console-route.test.ts +0 -162
  272. package/tests/integration/chaos-resilience.test.ts +0 -348
  273. package/tests/integration/empathy-workflow-integration.test.ts +0 -626
  274. package/tests/integration/pain-diagnostician-loop.e2e.test.ts +0 -380
  275. package/tests/service/control-ui-query-service.test.ts +0 -121
  276. package/tests/service/cooldown-strategy.test.ts +0 -164
  277. package/tests/service/data-endpoints-regression.test.ts +0 -834
  278. package/tests/service/empathy-observer-workflow-manager.test.ts +0 -175
  279. package/tests/service/evolution-worker.nocturnal.test.ts +0 -601
  280. package/tests/service/nocturnal-runtime-hardening.test.ts +0 -118
  281. package/tests/service/nocturnal-runtime.test.ts +0 -473
  282. package/tests/service/nocturnal-service-code-candidate.test.ts +0 -330
  283. package/tests/service/nocturnal-target-selector.test.ts +0 -615
  284. package/tests/service/startup-reconciler.test.ts +0 -148
  285. package/tests/tools/write-pain-flag.test.ts +0 -358
  286. package/ui/src/App.tsx +0 -45
  287. package/ui/src/api.ts +0 -220
  288. package/ui/src/charts.tsx +0 -955
  289. package/ui/src/components/ErrorState.tsx +0 -6
  290. package/ui/src/components/Loading.tsx +0 -13
  291. package/ui/src/components/ProtectedRoute.tsx +0 -12
  292. package/ui/src/components/Shell.tsx +0 -91
  293. package/ui/src/components/WorkspaceConfig.tsx +0 -178
  294. package/ui/src/components/index.ts +0 -5
  295. package/ui/src/context/auth.tsx +0 -80
  296. package/ui/src/context/theme.tsx +0 -66
  297. package/ui/src/hooks/useAutoRefresh.ts +0 -39
  298. package/ui/src/i18n/ui.ts +0 -473
  299. package/ui/src/main.tsx +0 -16
  300. package/ui/src/pages/EvolutionPage.tsx +0 -333
  301. package/ui/src/pages/FeedbackPage.tsx +0 -138
  302. package/ui/src/pages/GateMonitorPage.tsx +0 -136
  303. package/ui/src/pages/LoginPage.tsx +0 -89
  304. package/ui/src/pages/OverviewPage.tsx +0 -599
  305. package/ui/src/pages/SamplesPage.tsx +0 -174
  306. package/ui/src/pages/ThinkingModelsPage.tsx +0 -702
  307. package/ui/src/styles.css +0 -2020
  308. package/ui/src/types.ts +0 -384
  309. package/ui/src/utils/format.ts +0 -15
@@ -1,243 +0,0 @@
1
- # Testing Patterns
2
-
3
- **Analysis Date:** 2026-04-15
4
-
5
- ## Test Framework
6
-
7
- **Runner:** Vitest 4.1.0
8
- - Config: `vitest.config.ts`
9
- - Environment: `node`
10
- - Pool: `threads` (required for `better-sqlite3` native handle cleanup)
11
-
12
- **Assertion Library:** Vitest built-in (`expect`)
13
-
14
- **Coverage:** `@vitest/coverage-v8`
15
- - Thresholds: lines 70%, functions 70%, branches 60%, statements 70%
16
- - Excludes: `tests/**`
17
-
18
- **Run Commands:**
19
- ```bash
20
- npm test # Run unit tests (fast, parallel)
21
- npm run test:unit # Alias for above
22
- npm run test:integration # Run integration tests only
23
- npm run test:coverage # Run with coverage report
24
- npm run test:all # Run all tests (unit + integration)
25
- ```
26
-
27
- ## Test File Organization
28
-
29
- **Location:**
30
- - Tests co-located in `tests/` directory, mirroring `src/` structure
31
- - `tests/core/`, `tests/commands/`, `tests/hooks/`, `tests/service/`, `tests/utils/`
32
- - Integration tests in `tests/integration/`
33
-
34
- **Naming:**
35
- - `*.test.ts` suffix for all test files
36
- - Example: `tests/core/detection-service.test.ts`
37
-
38
- **Structure:**
39
- ```
40
- tests/
41
- ├── commands/ # Command handlers
42
- ├── core/ # Core services and logic
43
- ├── fixtures/ # Shared fixtures
44
- ├── hooks/ # Hook handlers
45
- ├── integration/ # End-to-end tests
46
- ├── scripts/ # Script tests
47
- └── service/ # Service layer
48
- ```
49
-
50
- ## Test Structure
51
-
52
- **Suite Organization:**
53
- ```typescript
54
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
55
-
56
- describe('DetectionService', () => {
57
- beforeEach(() => {
58
- vi.clearAllMocks();
59
- // Reset state between tests
60
- DetectionService.reset();
61
- });
62
-
63
- it('should create a new instance on first get', () => {
64
- // Test implementation
65
- });
66
- });
67
- ```
68
-
69
- **Patterns:**
70
- - `beforeEach` for setup, `afterEach` for teardown
71
- - `vi.clearAllMocks()` between tests (not `vi.resetAllMocks()`)
72
- - `vi.useFakeTimers()` / `vi.useRealTimers()` for time-sensitive tests
73
-
74
- ## Mocking
75
-
76
- **Framework:** Vitest's `vi.fn()` and `vi.mock()`
77
-
78
- **Module Mocking:**
79
- ```typescript
80
- vi.mock('../../src/core/dictionary-service.js');
81
- vi.mock('../../src/core/detection-funnel.js');
82
-
83
- // Then configure mock implementations
84
- vi.mocked(DictionaryService.get).mockReturnValue(mockDict as any);
85
- ```
86
-
87
- **Built-in Module Mocking:**
88
- ```typescript
89
- vi.mock('fs');
90
- vi.mocked(fs.existsSync).mockReturnValue(true);
91
- vi.mocked(fs.readFileSync).mockImplementation((p) => {
92
- if (p.toString() === configPath) return JSON.stringify(mockConfig);
93
- return '';
94
- });
95
- ```
96
-
97
- **Mock Reset:**
98
- - `vi.clearAllMocks()` clears call history but keeps implementations
99
- - `vi.resetAllMocks()` clears both (use with caution)
100
- - Reset singleton state: `DetectionService.reset()`, `WorkspaceContext.clearCache()`
101
-
102
- **Partial Mocks:**
103
- ```typescript
104
- vi.mocked(fs.existsSync).mockImplementation((p) => p.toString() === configPath);
105
- ```
106
-
107
- ## Fixtures and Factories
108
-
109
- **Temp Directory Pattern (integration tests):**
110
- ```typescript
111
- const tempDirs: string[] = [];
112
-
113
- function makeWorkspace(): string {
114
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-runtime-summary-'));
115
- tempDirs.push(dir);
116
- fs.mkdirSync(path.join(dir, '.state', 'sessions'), { recursive: true });
117
- return dir;
118
- }
119
-
120
- afterEach(() => {
121
- for (const dir of tempDirs.splice(0)) {
122
- fs.rmSync(dir, { recursive: true, force: true });
123
- }
124
- });
125
- ```
126
-
127
- **JSON Fixture Writing:**
128
- ```typescript
129
- function writeJson(filePath: string, value: unknown): void {
130
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
131
- fs.writeFileSync(filePath, JSON.stringify(value, null, 2), 'utf8');
132
- }
133
- ```
134
-
135
- **Session File Helper:**
136
- ```typescript
137
- function writeSession(workspace: string, sessionId: string, payload: Record<string, unknown>): void {
138
- writeJson(path.join(workspace, '.state', 'sessions', `${sessionId}.json`), {
139
- sessionId,
140
- ...payload,
141
- });
142
- }
143
- ```
144
-
145
- ## Integration Tests
146
-
147
- **Requirements:**
148
- - Real SQLite database via `better-sqlite3`
149
- - Thread pool required (not `vm` pool) due to native handle cleanup issues
150
- - Explicit file list in `vitest.config.ts` integration array
151
-
152
- **Integration Test Files:**
153
- ```typescript
154
- const integrationTests = [
155
- 'tests/core/control-ui-db.test.ts',
156
- 'tests/core/evolution-logger.test.ts',
157
- 'tests/core/nocturnal-e2e.test.ts',
158
- // ...
159
- ];
160
- ```
161
-
162
- ## Common Patterns
163
-
164
- **Async Testing with Fake Timers:**
165
- ```typescript
166
- beforeEach(() => {
167
- vi.useFakeTimers();
168
- });
169
-
170
- afterEach(() => {
171
- vi.useRealTimers();
172
- });
173
-
174
- it('should retry on retryable error', async () => {
175
- const fn = vi.fn()
176
- .mockRejectedValueOnce(new Error('ETIMEDOUT'))
177
- .mockResolvedValue('success');
178
-
179
- const resultPromise = retryAsync(fn, { initialDelayMs: 100 });
180
- await vi.advanceTimersByTimeAsync(100);
181
- const result = await resultPromise;
182
- expect(result).toBe('success');
183
- });
184
- ```
185
-
186
- **Error Testing:**
187
- ```typescript
188
- it('should throw after max retries exceeded', async () => {
189
- vi.useRealTimers();
190
- const fn = vi.fn().mockRejectedValue(new Error('ETIMEDOUT'));
191
-
192
- await expect(retryAsync(fn, { maxRetries: 1, initialDelayMs: 1, logger: { warn: vi.fn() } }))
193
- .rejects.toThrow('ETIMEDOUT');
194
- });
195
- ```
196
-
197
- **Singleton Reset Pattern:**
198
- ```typescript
199
- // Many services use singleton pattern requiring reset between tests
200
- DetectionService.reset();
201
- WorkspaceContext.clearCache();
202
- clearSession('live-session');
203
- ```
204
-
205
- ## Test Naming and Documentation
206
-
207
- **Descriptive Test Names:**
208
- ```typescript
209
- it('should block risk path writes at Seed tier (EP system)', () => { ... });
210
- it('should return default values if file does not exist', () => { ... });
211
- ```
212
-
213
- **Test Comments for Context:**
214
- ```typescript
215
- // Task 4: Default Values Consistency Tests
216
- describe('Gate Default Values Consistency', () => {
217
- /**
218
- * PURPOSE: Prove that gate.ts inline defaults match PROFILE_DEFAULTS.
219
- * If gate.ts has inline defaults that differ from normalizeProfile(),
220
- * this is a bug - the defaults should come from a single source of truth.
221
- */
222
- });
223
- ```
224
-
225
- ## Test Isolation
226
-
227
- **Environment Variable Injection:**
228
- ```typescript
229
- // Set env before module load
230
- process.env.PD_TEST_AGENTS_DIR = TEST_AGENTS_DIR;
231
- ```
232
-
233
- **Path Traversal Protection Tests:**
234
- ```typescript
235
- it('rejects path traversal session IDs', async () => {
236
- const result = await extractRecentConversation('../../etc/passwd', 'main');
237
- expect(result).toBe('');
238
- });
239
- ```
240
-
241
- ---
242
-
243
- *Testing analysis: 2026-04-15*
@@ -1,113 +0,0 @@
1
- ---
2
- phase: "01-basic-visualization"
3
- plan: "01-GAP-CLOSURE"
4
- verified: 2026-04-17T15:30:00Z
5
- status: passed
6
- score: "4/4 must-haves verified"
7
- overrides_applied: 0
8
- re_verification: false
9
- gaps: []
10
- deferred: []
11
- human_verification: []
12
- requirement_mismatch:
13
- note: "Requirement IDs provided (SDK-CORE-03, SDK-ADP-07, SDK-ADP-08, SDK-TEST-02, SDK-TEST-03, SDK-MGMT-01, SDK-MGMT-02) are SDK Core Implementation Phase 1 requirements per REQUIREMENTS.md. This phase (01-basic-visualization) addresses VIZ-04 (Empty state optimization) - a different domain. Requirement coverage cannot be established for IDs that do not belong to this phase."
14
- ---
15
-
16
- # Phase 01-basic-visualization: GAP-CLOSURE Verification Report
17
-
18
- **Phase Goal:** Close verification gaps from Phase 01 by implementing missing i18n fixes for LineChart component and coverage trend empty state.
19
- **Verified:** 2026-04-17T15:30:00Z
20
- **Status:** passed
21
- **Re-verification:** No — initial verification
22
-
23
- ## Goal Achievement
24
-
25
- ### Observable Truths
26
-
27
- | # | Truth | Status | Evidence |
28
- | --- | ----- | ------ | -------- |
29
- | 1 | LineChart interface has emptyText prop for i18n | VERIFIED | `emptyText?: string;` at line 864 in charts.tsx |
30
- | 2 | LineChart renders emptyText prop instead of hardcoded '暂无数据' | VERIFIED | Conditional render at lines 878-885: `if (!emptyText) return null;` then `{emptyText}` |
31
- | 3 | Coverage trend section shows EmptyState when no data | VERIFIED | Ternary at line 259: `data.coverageTrend.length >= 1 ? (...) : (<EmptyState ...>)` |
32
- | 4 | All LineChart usages pass emptyText prop | VERIFIED | Lines 272, 454, 521 all have `emptyText={t('common.noData')}` |
33
-
34
- **Score:** 4/4 truths verified
35
-
36
- ### Deferred Items
37
-
38
- None
39
-
40
- ### Required Artifacts
41
-
42
- | Artifact | Expected | Status | Details |
43
- | -------- | -------- | ------ | ------- |
44
- | `charts.tsx:864` | `emptyText?: string` in LineChartProps | VERIFIED | Prop exists at correct line |
45
- | `charts.tsx:876` | Default value `emptyText = ''` | VERIFIED | Default empty string assigned |
46
- | `charts.tsx:878-885` | Conditional render using emptyText | VERIFIED | Returns null if no emptyText, renders div with {emptyText} otherwise |
47
- | `ThinkingModelsPage.tsx:259` | Ternary operator for coverage trend | VERIFIED | `data.coverageTrend.length >= 1 ? (...) : (<EmptyState ...>)` |
48
- | `ThinkingModelsPage.tsx:272` | LineChart with emptyText prop | VERIFIED | `emptyText={t('common.noData')}` |
49
- | `ThinkingModelsPage.tsx:454` | LineChart with emptyText prop | VERIFIED | `emptyText={t('common.noData')}` |
50
- | `ThinkingModelsPage.tsx:521` | LineChart with emptyText prop | VERIFIED | `emptyText={t('common.noData')}` |
51
-
52
- ### Key Link Verification
53
-
54
- | From | To | Via | Status | Details |
55
- | ---- | --- | --- | ------ | ------- |
56
- | LineChart | i18n system | emptyText prop | WIRED | emptyText prop accepts i18n string and renders it |
57
- | Coverage trend | EmptyState | ternary operator | WIRED | Ternary correctly switches between LineChart and EmptyState |
58
- | ThinkingModelsPage | common.noData | t() function | WIRED | All LineChart usages pass i18n key |
59
- | EmptyState | i18n keys | t() function | WIRED | `t('thinkingModels.emptyCoverageTrend')` and `t('thinkingModels.emptyCoverageTrendDesc')` used |
60
-
61
- ### Data-Flow Trace (Level 4)
62
-
63
- | Artifact | Data Variable | Source | Produces Real Data | Status |
64
- | -------- | ------------- | ------ | ------------------ | ------ |
65
- | LineChart emptyText | emptyText prop | Parent component via t('common.noData') | N/A | STATIC — i18n key is static, not dynamic |
66
-
67
- ### Behavioral Spot-Checks
68
-
69
- | Behavior | Command | Result | Status |
70
- | -------- | ------- | ------ | ------ |
71
- | emptyText in interface | `grep -n "emptyText?: string" charts.tsx` | `864: emptyText?: string;` | PASS |
72
- | No hardcoded Chinese | `grep -n "暂无数据" charts.tsx` | No matches | PASS |
73
- | Ternary for coverage | `grep -n "coverageTrend.length.*?" ThinkingModelsPage.tsx` | `259: {data.coverageTrend.length >= 1 ?` | PASS |
74
- | EmptyState for coverage | `grep -n "EmptyState" ThinkingModelsPage.tsx \| head -3` | Lines 276-279 with i18n keys | PASS |
75
- | All LineChart have emptyText | `grep -B5 -A10 "<LineChart" ThinkingModelsPage.tsx \| grep -c "emptyText"` | 3 | PASS |
76
-
77
- ### Requirements Coverage
78
-
79
- **IMPORTANT - Requirement Mismatch Found:**
80
-
81
- | Requirement | Source | Description | Status | Evidence |
82
- | ----------- | ------ | ----------- | ------ | -------- |
83
- | SDK-CORE-03 | User-provided | Implement universal PainSignal interface logic | N/A | Does not belong to 01-basic-visualization phase |
84
- | SDK-ADP-07 | User-provided | Implement Coding domain adapter | N/A | Does not belong to 01-basic-visualization phase |
85
- | SDK-ADP-08 | User-provided | Implement second domain adapter | N/A | Does not belong to 01-basic-visualization phase |
86
- | SDK-TEST-02 | User-provided | Implement full Adapter conformance test suite | N/A | Does not belong to 01-basic-visualization phase |
87
- | SDK-TEST-03 | User-provided | Execute and publish performance benchmarks | N/A | Does not belong to 01-basic-visualization phase |
88
- | SDK-MGMT-01 | User-provided | Package SDK as @principles/core npm package | N/A | Does not belong to 01-basic-visualization phase |
89
- | SDK-MGMT-02 | User-provided | Establish Semver versioning and migration guides | N/A | Does not belong to 01-basic-visualization phase |
90
- | VIZ-04 | GAP-CLOSURE-PLAN | Empty state optimization | VERIFIED | All 4 must_haves from GAP-CLOSURE-PLAN verified |
91
-
92
- **The 7 requirement IDs provided are SDK Core Implementation Phase 1 requirements per REQUIREMENTS.md. They do not map to the 01-basic-visualization phase. The phase's actual scope is VIZ-04 (Empty state optimization), which has been verified through must_haves.**
93
-
94
- ### Anti-Patterns Found
95
-
96
- | File | Line | Pattern | Severity | Impact |
97
- | ---- | ---- | ------- | -------- | ------ |
98
- | None | - | No anti-patterns detected | - | - |
99
-
100
- ### Human Verification Required
101
-
102
- None required — all truths verifiable via static analysis.
103
-
104
- ### Gaps Summary
105
-
106
- **None.** All 4 must_haves verified. Phase goal achieved.
107
-
108
- **Notable finding:** The requirement IDs provided by user (SDK-CORE-03, SDK-ADP-07, SDK-ADP-08, SDK-TEST-02, SDK-TEST-03, SDK-MGMT-01, SDK-MGMT-02) are SDK Core Implementation Phase 1 requirements per REQUIREMENTS.md. This phase (01-basic-visualization) addresses VIZ-04 (Empty state optimization for visualization) - a different scope. Requirement coverage cannot be established for IDs that do not belong to this phase.
109
-
110
- ---
111
-
112
- _Verified: 2026-04-17T15:30:00Z_
113
- _Verifier: Claude (gsd-verifier)_
@@ -1,76 +0,0 @@
1
- # Principles Disciple Command Reference
2
-
3
- > 当前版本重点:EP (Evolution Points) 系统已接替 trust score 成为唯一门控机制。
4
- > `rollback` 只回滚 `user_empathy` slice,`/pd-evolution-status` 读的是运行时 summary。
5
-
6
- ---
7
-
8
- ## 核心命令
9
-
10
- | 命令 | 用途 | 当前口径 |
11
- |---|---|---|
12
- | `/pd-evolution-status` | 查看控制面与进化面的当前状态 | 读取 `RuntimeSummaryService` 的 canonical state |
13
- | `/pd-status empathy` | 查看情绪/共情事件统计 | 用于观察 `user_empathy` 与 `system_infer` 事件是否稳定落日志 |
14
- | `/pd-rollback last` | 回滚最近一次情绪惩罚 | 只回滚 `user_empathy` 对应的 GFI slice |
15
- | `/pd-evolve` | 执行进化任务 | 属于学习面,通过 EP 积累提升权限 |
16
- | `/pd-help` | 显示帮助 | |
17
-
18
- ---
19
-
20
- ## `/pd-evolution-status`
21
-
22
- ### 它现在显示什么
23
-
24
- - `EP Tier`: 当前 EP 等级 (Seed → Sprout → Sapling → Tree → Forest)
25
- - `Session GFI`: 当前会话 GFI 与峰值
26
- - `GFI Sources`: 当前 summary 能解释出来的 friction 来源
27
- - `Pain Flag`: pain flag 是否激活
28
- - `Gate Events`: 最近的 block / bypass
29
- - `Queue / Directive`: evolution queue 与 directive 的当前状态
30
-
31
- ### 重要说明
32
-
33
- - 这是当前控制面的权威读模型入口。
34
- - 它优先读取 canonical `.state`,并尽量合并 live session / buffered events。
35
- - 如果数据不完整,会显示 `partial` 或 warning,而不是静默显示 `0`。
36
-
37
- ---
38
-
39
- ## `/pd-rollback`
40
-
41
- ### 当前行为
42
-
43
- - `/pd-rollback last`
44
- - `/pd-rollback <event-id>`
45
-
46
- 回滚的是最近一次或指定的 `user_empathy` 事件。
47
-
48
- ### 重要变化
49
-
50
- - 现在只回滚 `user_empathy` 对应的 GFI slice
51
- - 不再把整段 session GFI 一起清空
52
- - 如果事件不存在或来源不匹配,不会误伤其他 friction
53
-
54
- ---
55
-
56
- ## EP 等级说明
57
-
58
- | 等级 | EP 要求 | 权限 |
59
- |---|---|---|
60
- | Seed | 0 | 只读 + 基础文档 |
61
- | Sprout | 50 | 单文件编辑 |
62
- | Sapling | 200 | 多文件 + 测试 + 子智能体 |
63
- | Tree | 500 | 重构 + 风险路径 |
64
- | Forest | 1000 | 无限制 |
65
-
66
- ---
67
-
68
- ## 观察窗口建议
69
-
70
- 在进入 `Phase 3 capability shadow` 之前,优先每天检查:
71
-
72
- 1. `user_empathy` / `system_infer` 是否稳定进入 `events.jsonl`
73
- 2. rollback 是否只影响 empathy slice
74
- 3. `evolution_queue.json`、`evolution_directive.json` 与 status 是否一致
75
- 4. summary 是否仍然需要 `partial` 警告才能解释当前状态
76
- 5. EP 积累是否正常驱动等级提升
@@ -1,79 +0,0 @@
1
- # Principles Disciple Command Reference (English)
2
-
3
- > Current state: EP (Evolution Points) system is the primary growth system, fully operational and enabled by default.
4
-
5
- ---
6
-
7
- ## Core Commands
8
-
9
- | Command | Purpose |
10
- |---|---|
11
- | `/pd-evolution-status` | View EP tier, GFI, pain flag, and gate events |
12
- | `/pd-status empathy` | Inspect empathy/frustration event statistics |
13
- | `/pd-rollback last` | Roll back the latest empathy penalty |
14
- | `/pd-evolve` | Run an evolution task |
15
- | `/pd-evolution-points` | View current EP balance and tier |
16
-
17
- ---
18
-
19
- ## `/pd-evolution-status`
20
-
21
- ### What it shows
22
-
23
- - `EP Tier`: Current evolution tier (Seed → Sprout → Sapling → Tree → Forest)
24
- - `Session GFI`: Current session GFI and peak
25
- - `GFI Sources`: Currently attributable friction sources
26
- - `Pain Flag`: Whether a pain flag is active
27
- - `Gate Events`: Recent block / bypass counts
28
- - `Queue / Directive`: Evolution queue and directive state
29
-
30
- ### Important notes
31
-
32
- - This is the main operator entry point into the control plane.
33
- - It reads canonical `.state` and tries to merge live session state and buffered events when available.
34
- - When data is incomplete, it surfaces `partial` or warnings instead of silently printing `0`.
35
-
36
- ---
37
-
38
- ## `/pd-rollback`
39
-
40
- ### Current behavior
41
-
42
- - `/pd-rollback last`
43
- - `/pd-rollback <event-id>`
44
-
45
- It rolls back the latest or specified `user_empathy` event.
46
-
47
- ### Important notes
48
-
49
- - It subtracts only the `user_empathy` GFI slice
50
- - It no longer wipes the whole session GFI
51
- - If the event is missing or the source does not match, unrelated friction remains untouched
52
-
53
- ---
54
-
55
- ## EP Tier System
56
-
57
- | Tier | EP Required | Max Lines/Write |
58
- |------|-------------|-----------------|
59
- | Seed | 0 | 150 |
60
- | Sprout | 50 | 300 |
61
- | Sapling | 200 | 500 |
62
- | Tree | 500 | 1000 |
63
- | Forest | 1000 | Unlimited |
64
-
65
- EP is earned through successful task completion and problem resolution.
66
-
67
- ---
68
-
69
- ## Observation Window Checklist
70
-
71
- Before entering new capability phases, check daily:
72
-
73
- 1. EP tier and queue are functioning correctly
74
- 2. `user_empathy` and `system_infer` appear in `events.jsonl`
75
- 3. rollback affects only the empathy slice
76
- 4. `evolution_queue.json`, `evolution_directive.json`, and status stay aligned
77
- 5. summary warnings still accurately explain partial data quality
78
-
79
- (End of file - total 84 lines)
@@ -1,46 +0,0 @@
1
- import { build } from "esbuild";
2
- import { mkdirSync, writeFileSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
- import path from "node:path";
5
-
6
- const isProduction = process.argv.includes("--production");
7
- const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
8
- const outDir = path.join(rootDir, "dist", "web");
9
- const assetsDir = path.join(outDir, "assets");
10
-
11
- mkdirSync(assetsDir, { recursive: true });
12
-
13
- await build({
14
- entryPoints: [path.join(rootDir, "ui", "src", "main.tsx")],
15
- bundle: true,
16
- format: "esm",
17
- platform: "browser",
18
- target: ["es2022"],
19
- outfile: path.join(assetsDir, "app.js"),
20
- sourcemap: isProduction ? false : "inline",
21
- minify: isProduction,
22
- jsx: "automatic",
23
- loader: {
24
- ".css": "css",
25
- },
26
- define: {
27
- "process.env.NODE_ENV": JSON.stringify(isProduction ? "production" : "development"),
28
- },
29
- });
30
-
31
- const html = `<!doctype html>
32
- <html lang="zh-CN">
33
- <head>
34
- <meta charset="utf-8" />
35
- <meta name="viewport" content="width=device-width, initial-scale=1" />
36
- <title>Principles Console</title>
37
- <link rel="stylesheet" href="/plugins/principles/assets/app.css" />
38
- </head>
39
- <body>
40
- <div id="root"></div>
41
- <script type="module" src="/plugins/principles/assets/app.js"></script>
42
- </body>
43
- </html>
44
- `;
45
-
46
- writeFileSync(path.join(outDir, "index.html"), html, "utf8");