chati-dev 4.0.11 → 4.1.1

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 (116) hide show
  1. package/README.md +14 -9
  2. package/bin/chati.js +17 -1
  3. package/framework/agents/build/dev.md +43 -10
  4. package/framework/agents/discover/brief.md +38 -8
  5. package/framework/agents/discover/brownfield-wu.md +44 -3
  6. package/framework/agents/discover/greenfield-wu.md +14 -0
  7. package/framework/agents/plan/architect-data-engineer.md +278 -0
  8. package/framework/agents/plan/architect-system.md +174 -0
  9. package/framework/agents/plan/architect.md +97 -301
  10. package/framework/agents/plan/detail.md +25 -0
  11. package/framework/agents/plan/tasks.md +29 -1
  12. package/framework/agents/plan/ux-brand-architect.md +215 -0
  13. package/framework/agents/plan/ux-component-engineer.md +289 -0
  14. package/framework/agents/plan/ux-researcher.md +166 -0
  15. package/framework/agents/plan/ux.md +126 -1008
  16. package/framework/agents/quality/qa-implementation.md +121 -22
  17. package/framework/agents/quality/qa-planning.md +18 -0
  18. package/framework/config.yaml +15 -4
  19. package/framework/constitution.md +9 -3
  20. package/framework/context/root.md +2 -2
  21. package/framework/data/entity-registry.yaml +59 -3
  22. package/framework/hooks/constitution-guard.js +67 -1
  23. package/framework/hooks/license-guard.js +4 -4
  24. package/framework/hooks/model-governance.js +2 -1
  25. package/framework/hooks/prism-engine.js +74 -6
  26. package/framework/hooks/read-protection.js +1 -1
  27. package/framework/hooks/session-digest.js +159 -7
  28. package/framework/hooks/settings.json +16 -4
  29. package/framework/hooks/style-guard.js +134 -0
  30. package/framework/hooks/undercover-guard.js +220 -0
  31. package/framework/i18n/en.yaml +2 -2
  32. package/framework/i18n/es.yaml +2 -2
  33. package/framework/i18n/fr.yaml +2 -2
  34. package/framework/i18n/pt.yaml +2 -2
  35. package/framework/intelligence/context-engine.md +21 -0
  36. package/framework/intelligence/hooks-performance.md +54 -0
  37. package/framework/intelligence/memory-layer.md +47 -0
  38. package/framework/migrations/v4.0-to-v4.1.yaml +165 -0
  39. package/framework/orchestrator/chati.md +327 -1067
  40. package/framework/schemas/session.schema.json +1 -1
  41. package/framework/templates/brandbook-html-tmpl.md +107 -0
  42. package/framework/templates/session-memory-tmpl.yaml +68 -0
  43. package/package.json +1 -1
  44. package/scripts/doctor/checks/agents.js +1 -1
  45. package/scripts/health-check.js +1 -1
  46. package/src/autonomy/build-state.js +1 -1
  47. package/src/autonomy/worktree-manager.js +13 -13
  48. package/src/config/agent-customizer.js +1 -1
  49. package/src/config/gemini-hooks-generator.js +149 -6
  50. package/src/config/ide-configs.js +1 -1
  51. package/src/context/bracket-tracker.js +25 -4
  52. package/src/context/engine.js +37 -7
  53. package/src/context/formatter.js +45 -1
  54. package/src/context/index.js +3 -3
  55. package/src/dashboard/data-reader.js +7 -7
  56. package/src/decision/engine.js +2 -2
  57. package/src/decision/registry-healer.js +1 -1
  58. package/src/decision/registry-updater.js +2 -2
  59. package/src/extensions/loader.js +1 -1
  60. package/src/gates/g1-planning-complete.js +1 -1
  61. package/src/gates/g2-qa-planning.js +1 -1
  62. package/src/gates/g3-implementation.js +4 -4
  63. package/src/gates/g4-qa-implementation.js +2 -2
  64. package/src/health/auto-fix.js +3 -3
  65. package/src/health/engine.js +2 -2
  66. package/src/installer/brownfield-upgrader.js +3 -3
  67. package/src/installer/manifest.js +1 -1
  68. package/src/installer/transaction.js +1 -1
  69. package/src/installer/validator.js +4 -4
  70. package/src/intelligence/decision-engine.js +1 -1
  71. package/src/intelligence/memory-manager.js +1 -1
  72. package/src/intelligence/registry-manager.js +2 -2
  73. package/src/intelligence/timeline.js +1 -1
  74. package/src/license/client.js +1 -1
  75. package/src/license/commands.js +2 -2
  76. package/src/memory/agent-memory.js +3 -3
  77. package/src/memory/daily-digest.js +170 -0
  78. package/src/memory/dream.js +254 -0
  79. package/src/memory/gotchas.js +2 -2
  80. package/src/memory/index.js +18 -0
  81. package/src/memory/magic-docs.js +98 -0
  82. package/src/memory/memory-extractor.js +163 -0
  83. package/src/memory/session-digest.js +144 -6
  84. package/src/merger/yaml-merger.js +1 -1
  85. package/src/orchestrator/cli.js +980 -0
  86. package/src/orchestrator/handoff-engine.js +31 -4
  87. package/src/orchestrator/index.js +9 -0
  88. package/src/orchestrator/session-manager.js +1 -1
  89. package/src/preview/detector.js +3 -3
  90. package/src/preview/launcher.js +2 -2
  91. package/src/quality/metrics-collector.js +1 -1
  92. package/src/quality/test-runner.js +2 -4
  93. package/src/scanning/density-scanner.js +51 -0
  94. package/src/scanning/env-scanner.js +97 -0
  95. package/src/scanning/index.js +7 -0
  96. package/src/scanning/leakage-scanner.js +54 -0
  97. package/src/scanning/placeholder-scanner.js +40 -0
  98. package/src/scanning/security-scanner.js +94 -0
  99. package/src/security/bash-security.js +335 -0
  100. package/src/security/index.js +9 -0
  101. package/src/telemetry/config.js +3 -3
  102. package/src/telemetry/sender.js +1 -1
  103. package/src/terminal/cli-registry.js +1 -1
  104. package/src/terminal/cost-tracker.js +1 -2
  105. package/src/terminal/prompt-builder.js +11 -27
  106. package/src/terminal/rate-limiter.js +1 -2
  107. package/src/terminal/run-agent.js +3 -3
  108. package/src/terminal/spawner.js +41 -4
  109. package/src/upgrade/checker.js +2 -2
  110. package/src/upgrade/migrator.js +1 -1
  111. package/src/utils/config-parser.js +1 -1
  112. package/src/utils/file-lock.js +3 -3
  113. package/src/utils/provider-limits.js +35 -4
  114. package/src/wizard/i18n.js +4 -4
  115. package/src/wizard/index.js +2 -1
  116. package/src/wizard/questions.js +4 -2
@@ -17,6 +17,14 @@ Four brackets define behavior based on remaining context:
17
17
  | **DEPLETED** | 25-40% | 3 layers (L0-L2). Heavy reinforcement (4.0%) — significant context loss. Chunk memory recovery. |
18
18
  | **CRITICAL** | <25% | 2 layers (L0-L1). Maximum reinforcement (5.0%) — last interactions before handoff. Full memory dump. |
19
19
 
20
+ ### Static/Dynamic PRISM Boundary
21
+
22
+ The PRISM engine separates context into a **static prefix** (L0 Constitution + L1 Global rules) and a **dynamic suffix** (L2-L5, changes per turn). A `<!-- STATIC_BOUNDARY -->` marker separates them in the XML output.
23
+
24
+ This enables prompt cache reuse — the static prefix is identical across turns within the same mode, so the LLM provider can cache it and only reprocess the dynamic portion.
25
+
26
+ The static cache is invalidated when the governance mode changes (planning → build → deploy).
27
+
20
28
  ---
21
29
 
22
30
  ## Layered Context Injection
@@ -100,6 +108,19 @@ bracket = calculateBracket(100 - contextPercent)
100
108
 
101
109
  The orchestrator recalculates the bracket before each agent interaction and adjusts injection accordingly.
102
110
 
111
+ ### Token-Based Bracket Estimation
112
+
113
+ Context remaining percentage is estimated from actual prompt content size rather than conversation turn count:
114
+
115
+ ```
116
+ estimatedTokens = promptText.length / 4
117
+ remainingPercent = (1 - estimatedTokens / providerLimit) * 100
118
+ ```
119
+
120
+ This replaces the legacy heuristic (`turnCount / maxTurns`) which was inaccurate for sessions with large tool results or long agent outputs. The token-based approach scales correctly across providers (Claude 200K, Gemini 1M, Codex 128K).
121
+
122
+ Fallback: If prompt text is unavailable, the turn-count heuristic is used.
123
+
103
124
  ---
104
125
 
105
126
  ## Autonomous Context Recovery
@@ -0,0 +1,54 @@
1
+ # Hook Performance Reference
2
+
3
+ ## Execution Model
4
+
5
+ Each hook runs as a separate Node.js process via stdin/stdout JSON protocol.
6
+ Hooks execute SEQUENTIALLY within the same event matcher.
7
+ Claude Code spawns each hook as a child process, waits for JSON output, then proceeds.
8
+
9
+ ## Hook Registry (11 total)
10
+
11
+ | Event | Matcher | Hook | Purpose |
12
+ |-------|---------|------|---------|
13
+ | UserPromptSubmit | `.*` | license-guard.js | License validation + session ping |
14
+ | UserPromptSubmit | `.*` | prism-engine.js | Context injection (bracket, memory, frustration) |
15
+ | UserPromptSubmit | `.*` | model-governance.js | Model assignment advisory |
16
+ | PreCompact | `.*` | session-digest.js | Session state capture + auto-dream + daily digest |
17
+ | PreToolUse | `Read` | read-protection.js | Block reading sensitive files |
18
+ | PreToolUse | `Write\|Edit` | mode-governance.js | Write scope enforcement by phase |
19
+ | PreToolUse | `Write\|Edit` | constitution-guard.js | Secret detection + 23 shell injection checks |
20
+ | PreToolUse | `Write\|Edit` | undercover-guard.js | Sanitize framework terms from deliverables |
21
+ | PreToolUse | `Write\|Edit` | style-guard.js | Em-dash and emoji enforcement |
22
+ | PreToolUse | `Bash` | constitution-guard.js | Destructive command + shell injection checks |
23
+ | PreToolUse | `Bash` | undercover-guard.js | Sanitize framework terms from git commits |
24
+ | PreToolUse | `Bash` | style-guard.js | Em-dash and emoji in commit messages |
25
+
26
+ ## Latency Budget
27
+
28
+ | Event | Hook Count | Expected Latency | Notes |
29
+ |-------|-----------|-----------------|-------|
30
+ | UserPromptSubmit | 3 | ~150ms | Runs before every user message |
31
+ | PreCompact | 1 | ~50-200ms | Runs rarely (context compaction). Auto-dream may add 5-10s if triggered |
32
+ | PreToolUse (Read) | 1 | ~30ms | Minimal overhead per file read |
33
+ | PreToolUse (Write/Edit) | 4 | ~200ms | Heaviest path. 4 sequential hooks |
34
+ | PreToolUse (Bash) | 3 | ~150ms | 23 regex checks in constitution-guard are negligible (<5ms) |
35
+
36
+ ## Performance Characteristics
37
+
38
+ - **Fastest path**: Read (1 hook, ~30ms)
39
+ - **Heaviest path**: Write/Edit (4 hooks, ~200ms)
40
+ - **Most frequent**: UserPromptSubmit (3 hooks on every message)
41
+ - **Rarest**: PreCompact (1 hook, only on context compaction)
42
+
43
+ ## Optimization Notes
44
+
45
+ 1. constitution-guard's 23 shell injection regex checks run in <5ms total (all patterns compiled once)
46
+ 2. undercover-guard and style-guard could be skipped in discover/plan phases (no code being written)
47
+ 3. If latency becomes noticeable, consider merging undercover-guard + style-guard into one hook (same event, similar logic)
48
+ 4. license-guard has a 5-minute ping throttle to avoid network latency on every message
49
+
50
+ ## When to Worry
51
+
52
+ - If Write/Edit operations feel sluggish (>500ms added latency), profile hooks individually
53
+ - If auto-dream triggers during PreCompact and takes >10s, consider increasing the trigger threshold from 100 to 150 entries
54
+ - If UserPromptSubmit hooks add noticeable delay, license-guard's network call is the most likely culprit (has 3s timeout)
@@ -157,6 +157,22 @@ Where:
157
157
 
158
158
  ---
159
159
 
160
+ ## Memory Consolidation (Dream System)
161
+
162
+ The `/chati dream` command triggers a 4-phase consolidation cycle inspired by Claude Code's autoDream:
163
+
164
+ | Phase | Name | Action |
165
+ |-------|------|--------|
166
+ | 1 | Orient | Scan all agent MEMORY.md files, count entries, assess landscape |
167
+ | 2 | Gather | Read all memories and recent session digests into unified list |
168
+ | 3 | Consolidate | Deduplicate by content hash, merge cross-agent entries, increment evidence_count |
169
+ | 4 | Prune | If total > 200 entries, remove by tier (cold first) then confidence then access_count. Archive removed to `.chati/memories/shared/archive/` |
170
+
171
+ Consolidation is non-destructive — removed entries are archived, not deleted.
172
+ The consolidation report includes: merged count, pruned count, archived count, remaining entries, contradictions found.
173
+
174
+ ---
175
+
160
176
  ## Agent Privacy
161
177
 
162
178
  Each agent has:
@@ -167,6 +183,37 @@ This prevents cross-contamination while enabling knowledge sharing.
167
183
 
168
184
  ---
169
185
 
186
+ ## Per-Turn Memory Extraction
187
+
188
+ The memory extraction system automatically captures knowledge from agent output after each turn.
189
+
190
+ **Extraction patterns:**
191
+ - Decisions: "decided to", "chose", "selected" → type: decision, sector: episodic
192
+ - Resolutions: "fixed by", "resolved", "solved" → type: resolution, sector: procedural
193
+ - User corrections: "actually", "no, use" → type: user_correction, sector: reflective
194
+ - Validated patterns: "confirmed", "verified", "works" → type: validated_pattern, sector: semantic
195
+ - Error patterns: "error:", "failed because" → type: error_pattern, sector: episodic
196
+
197
+ **Budget:** Maximum 3 memories per turn. Confidence starts at 0.5 (warm tier).
198
+ **Deduplication:** Content is normalized and hashed to prevent duplicate entries.
199
+
200
+ ---
201
+
202
+ ## Daily Digest (KAIROS Lite)
203
+
204
+ The `/chati digest` command displays cumulative daily activity logs stored in `.chati/memories/shared/daily/YYYY-MM-DD.md`.
205
+
206
+ Each session appends an entry with:
207
+ - Timestamp and pipeline phase
208
+ - Current agent and completion stats
209
+ - Agent scores (average and per-agent)
210
+ - Decisions made and gotchas found
211
+ - Session duration
212
+
213
+ Digests are append-only (never overwritten) and accumulate throughout the day.
214
+
215
+ ---
216
+
170
217
  ## Integration with Context Engine
171
218
 
172
219
  | Bracket | Memory Level | Behavior |
@@ -0,0 +1,165 @@
1
+ # Migration: v4.0.x → v4.1.0 "Phoenix"
2
+ # Intelligence Upgrade inspired by Claude Code source leak analysis
3
+
4
+ from_version: "4.0.4"
5
+ to_version: "4.1.0"
6
+ created_at: "2026-04-02"
7
+ description: >
8
+ Intelligence Upgrade: orchestrator v2 (thin prompt + CLI handler),
9
+ memory extraction, dream consolidation, daily digest, undercover mode,
10
+ style guard, bash security (23 checks), model-aware context windows,
11
+ brandbook HTML, frustration detection, static/dynamic PRISM boundary,
12
+ microcompact advisory, model fallback (opus→sonnet).
13
+ breaking: false
14
+
15
+ preconditions:
16
+ - type: version_gte
17
+ version: "4.0.0"
18
+ message: "Requires chati.dev v4.0.0 or later"
19
+ - type: constitution_articles
20
+ count: 19
21
+ message: "Requires Constitution with 19 Articles"
22
+
23
+ backup:
24
+ directories:
25
+ - chati.dev/hooks
26
+ - chati.dev/orchestrator
27
+ - chati.dev/intelligence
28
+ - chati.dev/templates
29
+ - chati.dev/agents/plan
30
+ - chati.dev/context
31
+ - chati.dev/data
32
+ files:
33
+ - chati.dev/config.yaml
34
+ - chati.dev/constitution.md
35
+
36
+ operations:
37
+ # --- New hooks ---
38
+ - type: copy_file
39
+ source: chati.dev/hooks/undercover-guard.js
40
+ destination: chati.dev/hooks/undercover-guard.js
41
+ strategy: replace
42
+ description: "Undercover mode: sanitize framework terms from deliverables"
43
+
44
+ - type: copy_file
45
+ source: chati.dev/hooks/style-guard.js
46
+ destination: chati.dev/hooks/style-guard.js
47
+ strategy: replace
48
+ description: "Style guard: em-dash and emoji enforcement"
49
+
50
+ # --- Hook settings (includes new hooks) ---
51
+ - type: copy_file
52
+ source: chati.dev/hooks/settings.json
53
+ destination: chati.dev/hooks/settings.json
54
+ strategy: replace
55
+ description: "Register undercover-guard and style-guard hooks"
56
+
57
+ # --- Updated hooks (security checks, model-aware context, etc.) ---
58
+ - type: copy_file
59
+ source: chati.dev/hooks/constitution-guard.js
60
+ destination: chati.dev/hooks/constitution-guard.js
61
+ strategy: replace
62
+ description: "23-point shell injection defense system"
63
+
64
+ - type: copy_file
65
+ source: chati.dev/hooks/prism-engine.js
66
+ destination: chati.dev/hooks/prism-engine.js
67
+ strategy: replace
68
+ description: "Model-aware context, frustration detection, microcompact advisory"
69
+
70
+ - type: copy_file
71
+ source: chati.dev/hooks/session-digest.js
72
+ destination: chati.dev/hooks/session-digest.js
73
+ strategy: replace
74
+ description: "Structured 8-section digest, auto daily digest, auto dream consolidation"
75
+
76
+ # --- New templates ---
77
+ - type: copy_file
78
+ source: chati.dev/templates/session-memory-tmpl.yaml
79
+ destination: chati.dev/templates/session-memory-tmpl.yaml
80
+ strategy: replace
81
+ description: "8-section structured session memory template"
82
+
83
+ - type: copy_file
84
+ source: chati.dev/templates/brandbook-html-tmpl.md
85
+ destination: chati.dev/templates/brandbook-html-tmpl.md
86
+ strategy: replace
87
+ description: "Brandbook HTML visual style guide spec"
88
+
89
+ # --- Orchestrator v2 ---
90
+ - type: copy_file
91
+ source: chati.dev/orchestrator/chati.md
92
+ destination: chati.dev/orchestrator/chati.md
93
+ strategy: replace
94
+ description: "Orchestrator v2: thin prompt + CLI handler"
95
+
96
+ # --- Constitution (Article XIII expanded) ---
97
+ - type: copy_file
98
+ source: chati.dev/constitution.md
99
+ destination: chati.dev/constitution.md
100
+ strategy: replace
101
+ description: "Article XIII: 7→10 points (dream, extraction, digest)"
102
+
103
+ # --- Intelligence docs ---
104
+ - type: copy_file
105
+ source: chati.dev/intelligence/memory-layer.md
106
+ destination: chati.dev/intelligence/memory-layer.md
107
+ strategy: replace
108
+ description: "Memory Consolidation, Per-Turn Extraction, Daily Digest sections"
109
+
110
+ - type: copy_file
111
+ source: chati.dev/intelligence/context-engine.md
112
+ destination: chati.dev/intelligence/context-engine.md
113
+ strategy: replace
114
+ description: "Static/Dynamic PRISM Boundary, Token-Based Estimation"
115
+
116
+ # --- Entity registry ---
117
+ - type: copy_file
118
+ source: chati.dev/data/entity-registry.yaml
119
+ destination: chati.dev/data/entity-registry.yaml
120
+ strategy: replace
121
+ description: "7 new entities (55→62)"
122
+
123
+ # --- Context files ---
124
+ - type: copy_file
125
+ source: chati.dev/context/root.md
126
+ destination: chati.dev/context/root.md
127
+ strategy: replace
128
+ description: "Version bump to 4.1.0"
129
+
130
+ # --- UX agent (brandbook HTML) ---
131
+ - type: copy_file
132
+ source: chati.dev/agents/plan/ux.md
133
+ destination: chati.dev/agents/plan/ux.md
134
+ strategy: replace
135
+ description: "Mandatory brandbook.html output (criterion #21)"
136
+
137
+ # --- Config (version + 10 new feature flags) ---
138
+ - type: update_yaml
139
+ path: chati.dev/config.yaml
140
+ changes:
141
+ version: "4.1.0"
142
+ installer_version: "4.1.0"
143
+ description: "Bump version and add Intelligence Upgrade feature flags"
144
+
145
+ validation:
146
+ - type: file_exists
147
+ path: chati.dev/hooks/undercover-guard.js
148
+ - type: file_exists
149
+ path: chati.dev/hooks/style-guard.js
150
+ - type: file_exists
151
+ path: chati.dev/templates/session-memory-tmpl.yaml
152
+ - type: file_exists
153
+ path: chati.dev/templates/brandbook-html-tmpl.md
154
+ - type: yaml_field
155
+ path: chati.dev/config.yaml
156
+ field: version
157
+ value: "4.1.0"
158
+ - type: yaml_field
159
+ path: chati.dev/data/entity-registry.yaml
160
+ field: metadata.entity_count
161
+ value: 62
162
+
163
+ rollback:
164
+ description: "Restore from backup created before migration"
165
+ command: "npx chati-dev upgrade --rollback"