chati-dev 1.4.0 → 2.0.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 (200) hide show
  1. package/README.md +3 -3
  2. package/framework/agents/build/dev.md +343 -0
  3. package/framework/agents/clarity/architect.md +112 -0
  4. package/framework/agents/clarity/brief.md +182 -0
  5. package/framework/agents/clarity/brownfield-wu.md +181 -0
  6. package/framework/agents/clarity/detail.md +110 -0
  7. package/framework/agents/clarity/greenfield-wu.md +153 -0
  8. package/framework/agents/clarity/ux.md +112 -0
  9. package/framework/config.yaml +3 -3
  10. package/framework/constitution.md +31 -1
  11. package/framework/context/governance.md +37 -0
  12. package/framework/context/protocols.md +34 -0
  13. package/framework/context/quality.md +27 -0
  14. package/framework/context/root.md +24 -0
  15. package/framework/domains/agents/architect.yaml +51 -0
  16. package/framework/domains/agents/brief.yaml +47 -0
  17. package/framework/domains/agents/brownfield-wu.yaml +49 -0
  18. package/framework/domains/agents/detail.yaml +47 -0
  19. package/framework/domains/agents/dev.yaml +49 -0
  20. package/framework/domains/agents/devops.yaml +43 -0
  21. package/framework/domains/agents/greenfield-wu.yaml +47 -0
  22. package/framework/domains/agents/orchestrator.yaml +49 -0
  23. package/framework/domains/agents/phases.yaml +47 -0
  24. package/framework/domains/agents/qa-implementation.yaml +43 -0
  25. package/framework/domains/agents/qa-planning.yaml +44 -0
  26. package/framework/domains/agents/tasks.yaml +48 -0
  27. package/framework/domains/agents/ux.yaml +50 -0
  28. package/framework/domains/constitution.yaml +77 -0
  29. package/framework/domains/global.yaml +64 -0
  30. package/framework/domains/workflows/brownfield-discovery.yaml +16 -0
  31. package/framework/domains/workflows/brownfield-fullstack.yaml +26 -0
  32. package/framework/domains/workflows/brownfield-service.yaml +22 -0
  33. package/framework/domains/workflows/brownfield-ui.yaml +22 -0
  34. package/framework/domains/workflows/greenfield-fullstack.yaml +26 -0
  35. package/framework/hooks/constitution-guard.js +101 -0
  36. package/framework/hooks/mode-governance.js +92 -0
  37. package/framework/hooks/model-governance.js +76 -0
  38. package/framework/hooks/prism-engine.js +89 -0
  39. package/framework/hooks/session-digest.js +60 -0
  40. package/framework/hooks/settings.json +44 -0
  41. package/framework/migrations/v1.4-to-v2.0.yaml +167 -0
  42. package/framework/migrations/v2.0-to-v2.0.1.yaml +132 -0
  43. package/framework/orchestrator/chati.md +284 -6
  44. package/framework/tasks/architect-api-design.md +63 -0
  45. package/framework/tasks/architect-consolidate.md +47 -0
  46. package/framework/tasks/architect-db-design.md +73 -0
  47. package/framework/tasks/architect-design.md +95 -0
  48. package/framework/tasks/architect-security-review.md +62 -0
  49. package/framework/tasks/architect-stack-selection.md +53 -0
  50. package/framework/tasks/brief-consolidate.md +249 -0
  51. package/framework/tasks/brief-constraint-identify.md +277 -0
  52. package/framework/tasks/brief-extract-requirements.md +339 -0
  53. package/framework/tasks/brief-stakeholder-map.md +176 -0
  54. package/framework/tasks/brief-validate-completeness.md +121 -0
  55. package/framework/tasks/brownfield-wu-architecture-map.md +394 -0
  56. package/framework/tasks/brownfield-wu-deep-discovery.md +312 -0
  57. package/framework/tasks/brownfield-wu-dependency-scan.md +359 -0
  58. package/framework/tasks/brownfield-wu-migration-plan.md +483 -0
  59. package/framework/tasks/brownfield-wu-report.md +325 -0
  60. package/framework/tasks/brownfield-wu-risk-assess.md +424 -0
  61. package/framework/tasks/detail-acceptance-criteria.md +372 -0
  62. package/framework/tasks/detail-consolidate.md +138 -0
  63. package/framework/tasks/detail-edge-case-analysis.md +300 -0
  64. package/framework/tasks/detail-expand-prd.md +389 -0
  65. package/framework/tasks/detail-nfr-extraction.md +223 -0
  66. package/framework/tasks/dev-code-review.md +404 -0
  67. package/framework/tasks/dev-consolidate.md +543 -0
  68. package/framework/tasks/dev-debug.md +322 -0
  69. package/framework/tasks/dev-implement.md +252 -0
  70. package/framework/tasks/dev-iterate.md +411 -0
  71. package/framework/tasks/dev-pr-prepare.md +497 -0
  72. package/framework/tasks/dev-refactor.md +342 -0
  73. package/framework/tasks/dev-test-write.md +306 -0
  74. package/framework/tasks/devops-ci-setup.md +412 -0
  75. package/framework/tasks/devops-consolidate.md +712 -0
  76. package/framework/tasks/devops-deploy-config.md +598 -0
  77. package/framework/tasks/devops-monitoring-setup.md +658 -0
  78. package/framework/tasks/devops-release-prepare.md +673 -0
  79. package/framework/tasks/greenfield-wu-analyze-empty.md +169 -0
  80. package/framework/tasks/greenfield-wu-report.md +266 -0
  81. package/framework/tasks/greenfield-wu-scaffold-detection.md +203 -0
  82. package/framework/tasks/greenfield-wu-tech-stack-assess.md +255 -0
  83. package/framework/tasks/orchestrator-deviation.md +260 -0
  84. package/framework/tasks/orchestrator-escalate.md +276 -0
  85. package/framework/tasks/orchestrator-handoff.md +243 -0
  86. package/framework/tasks/orchestrator-health.md +372 -0
  87. package/framework/tasks/orchestrator-mode-switch.md +262 -0
  88. package/framework/tasks/orchestrator-resume.md +189 -0
  89. package/framework/tasks/orchestrator-route.md +169 -0
  90. package/framework/tasks/orchestrator-spawn-terminal.md +358 -0
  91. package/framework/tasks/orchestrator-status.md +260 -0
  92. package/framework/tasks/orchestrator-suggest-mode.md +372 -0
  93. package/framework/tasks/phases-breakdown.md +91 -0
  94. package/framework/tasks/phases-dependency-mapping.md +67 -0
  95. package/framework/tasks/phases-mvp-scoping.md +94 -0
  96. package/framework/tasks/qa-impl-consolidate.md +522 -0
  97. package/framework/tasks/qa-impl-performance-test.md +487 -0
  98. package/framework/tasks/qa-impl-regression-check.md +413 -0
  99. package/framework/tasks/qa-impl-sast-scan.md +402 -0
  100. package/framework/tasks/qa-impl-test-execute.md +344 -0
  101. package/framework/tasks/qa-impl-verdict.md +339 -0
  102. package/framework/tasks/qa-planning-consolidate.md +309 -0
  103. package/framework/tasks/qa-planning-coverage-plan.md +338 -0
  104. package/framework/tasks/qa-planning-gate-define.md +339 -0
  105. package/framework/tasks/qa-planning-risk-matrix.md +631 -0
  106. package/framework/tasks/qa-planning-test-strategy.md +217 -0
  107. package/framework/tasks/tasks-acceptance-write.md +75 -0
  108. package/framework/tasks/tasks-consolidate.md +57 -0
  109. package/framework/tasks/tasks-decompose.md +80 -0
  110. package/framework/tasks/tasks-estimate.md +66 -0
  111. package/framework/tasks/ux-a11y-check.md +49 -0
  112. package/framework/tasks/ux-component-map.md +55 -0
  113. package/framework/tasks/ux-consolidate.md +46 -0
  114. package/framework/tasks/ux-user-flow.md +46 -0
  115. package/framework/tasks/ux-wireframe.md +76 -0
  116. package/package.json +1 -1
  117. package/scripts/bundle-framework.js +2 -0
  118. package/scripts/changelog-generator.js +222 -0
  119. package/scripts/codebase-mapper.js +728 -0
  120. package/scripts/commit-message-generator.js +167 -0
  121. package/scripts/coverage-analyzer.js +260 -0
  122. package/scripts/dependency-analyzer.js +280 -0
  123. package/scripts/framework-analyzer.js +308 -0
  124. package/scripts/generate-constitution-domain.js +253 -0
  125. package/scripts/health-check.js +481 -0
  126. package/scripts/ide-sync.js +327 -0
  127. package/scripts/performance-analyzer.js +325 -0
  128. package/scripts/plan-tracker.js +278 -0
  129. package/scripts/populate-entity-registry.js +481 -0
  130. package/scripts/pr-review.js +317 -0
  131. package/scripts/rollback-manager.js +310 -0
  132. package/scripts/stuck-detector.js +343 -0
  133. package/scripts/test-quality-assessment.js +257 -0
  134. package/scripts/validate-agents.js +367 -0
  135. package/scripts/validate-tasks.js +465 -0
  136. package/src/autonomy/autonomous-gate.js +293 -0
  137. package/src/autonomy/index.js +51 -0
  138. package/src/autonomy/mode-manager.js +225 -0
  139. package/src/autonomy/mode-suggester.js +283 -0
  140. package/src/autonomy/progress-reporter.js +268 -0
  141. package/src/autonomy/safety-net.js +320 -0
  142. package/src/context/bracket-tracker.js +79 -0
  143. package/src/context/domain-loader.js +107 -0
  144. package/src/context/engine.js +144 -0
  145. package/src/context/formatter.js +184 -0
  146. package/src/context/index.js +4 -0
  147. package/src/context/layers/l0-constitution.js +28 -0
  148. package/src/context/layers/l1-global.js +37 -0
  149. package/src/context/layers/l2-agent.js +39 -0
  150. package/src/context/layers/l3-workflow.js +42 -0
  151. package/src/context/layers/l4-task.js +24 -0
  152. package/src/decision/analyzer.js +167 -0
  153. package/src/decision/engine.js +270 -0
  154. package/src/decision/index.js +38 -0
  155. package/src/decision/registry-healer.js +450 -0
  156. package/src/decision/registry-updater.js +330 -0
  157. package/src/gates/circuit-breaker.js +119 -0
  158. package/src/gates/g1-planning-complete.js +153 -0
  159. package/src/gates/g2-qa-planning.js +153 -0
  160. package/src/gates/g3-implementation.js +188 -0
  161. package/src/gates/g4-qa-implementation.js +207 -0
  162. package/src/gates/g5-deploy-ready.js +180 -0
  163. package/src/gates/gate-base.js +144 -0
  164. package/src/gates/index.js +46 -0
  165. package/src/installer/brownfield-upgrader.js +249 -0
  166. package/src/installer/core.js +55 -3
  167. package/src/installer/file-hasher.js +51 -0
  168. package/src/installer/manifest.js +117 -0
  169. package/src/installer/templates.js +17 -15
  170. package/src/installer/transaction.js +229 -0
  171. package/src/installer/validator.js +18 -1
  172. package/src/memory/agent-memory.js +255 -0
  173. package/src/memory/gotchas-injector.js +72 -0
  174. package/src/memory/gotchas.js +361 -0
  175. package/src/memory/index.js +35 -0
  176. package/src/memory/search.js +233 -0
  177. package/src/memory/session-digest.js +239 -0
  178. package/src/merger/env-merger.js +112 -0
  179. package/src/merger/index.js +56 -0
  180. package/src/merger/replace-merger.js +51 -0
  181. package/src/merger/yaml-merger.js +127 -0
  182. package/src/orchestrator/agent-selector.js +285 -0
  183. package/src/orchestrator/deviation-handler.js +350 -0
  184. package/src/orchestrator/handoff-engine.js +271 -0
  185. package/src/orchestrator/index.js +67 -0
  186. package/src/orchestrator/intent-classifier.js +264 -0
  187. package/src/orchestrator/pipeline-manager.js +492 -0
  188. package/src/orchestrator/pipeline-state.js +223 -0
  189. package/src/orchestrator/session-manager.js +409 -0
  190. package/src/tasks/executor.js +195 -0
  191. package/src/tasks/handoff.js +226 -0
  192. package/src/tasks/index.js +4 -0
  193. package/src/tasks/loader.js +210 -0
  194. package/src/tasks/router.js +182 -0
  195. package/src/terminal/collector.js +216 -0
  196. package/src/terminal/index.js +30 -0
  197. package/src/terminal/isolation.js +129 -0
  198. package/src/terminal/monitor.js +277 -0
  199. package/src/terminal/spawner.js +269 -0
  200. package/src/upgrade/checker.js +1 -1
@@ -0,0 +1,50 @@
1
+ # UX Agent Domain — Authority boundaries and behavioral rules for PRISM L2
2
+ mission: "Design user experience: wireframes, user flows, component maps, accessibility validation"
3
+
4
+ authority:
5
+ exclusive:
6
+ - Wireframe design and mockups
7
+ - User flow mapping
8
+ - Component hierarchy design
9
+ - Accessibility (a11y) validation
10
+ - Responsive design patterns
11
+ allowed:
12
+ - Create low-fidelity and high-fidelity wireframes
13
+ - Design navigation patterns
14
+ - Map user journeys and task flows
15
+ - Specify component states (default, hover, active, disabled, error)
16
+ - Define design tokens (colors, typography, spacing)
17
+ - Validate WCAG 2.1 AA compliance
18
+ blocked:
19
+ - Code implementation (that's dev's role)
20
+ - Backend logic design
21
+ - Database schema design
22
+ - API contract design
23
+ - Deployment configuration
24
+ redirectMessage: "UX design is complete. Redirecting to dev agent for implementation."
25
+
26
+ outputs:
27
+ - ux-spec.yaml
28
+ - component-map.yaml
29
+ - wireframes.yaml
30
+
31
+ rules:
32
+ - id: ux-01
33
+ text: "MUST validate all designs against WCAG 2.1 Level AA accessibility standards"
34
+ priority: critical
35
+
36
+ - id: ux-02
37
+ text: "MUST design responsive layouts for mobile, tablet, and desktop breakpoints"
38
+ priority: high
39
+
40
+ - id: ux-03
41
+ text: "MUST map complete user flows from entry point to goal completion, including error paths"
42
+ priority: high
43
+
44
+ - id: ux-04
45
+ text: "MUST specify all component states and transitions in component-map.yaml"
46
+ priority: normal
47
+
48
+ - id: ux-05
49
+ text: "MUST NOT design backend logic or data flows; focus on user-facing experience only"
50
+ priority: critical
@@ -0,0 +1,77 @@
1
+ # Constitution Domain — Extracted governance rules for PRISM L0
2
+ # Source: chati.dev/constitution.md (16 Articles + Preamble)
3
+
4
+ summary: >
5
+ Constitution governance: self-validation required (loop until quality >= 95%),
6
+ guided options (1,2,3 format), persistent session state, two-layer handoff,
7
+ language protocol (interaction=user lang, artifacts=English),
8
+ deviation protocol, mode governance (clarity/build/deploy),
9
+ context brackets, memory governance, registry governance,
10
+ session lock, model governance.
11
+
12
+ articleCount: 16
13
+
14
+ rules:
15
+ - id: art-i
16
+ text: "Agents must follow their assigned role, authority boundaries, and domain scope."
17
+ priority: critical
18
+
19
+ - id: art-ii
20
+ text: "Quality >= 95% self-validation required. Loop until threshold met."
21
+ priority: critical
22
+
23
+ - id: art-iii
24
+ text: "Memory and context must be managed through designated systems (PRISM, RECALL)."
25
+ priority: high
26
+
27
+ - id: art-iv
28
+ text: "No destructive operations without user confirmation. No secrets in system files. SAST mandatory."
29
+ priority: critical
30
+
31
+ - id: art-v
32
+ text: "Communication follows structured protocol: guided options (1,2,3), clear formatting."
33
+ priority: normal
34
+
35
+ - id: art-vi
36
+ text: "Design system tokens must be respected when generating UI code."
37
+ priority: normal
38
+
39
+ - id: art-vii
40
+ text: "All documentation and artifacts must be in English."
41
+ priority: high
42
+
43
+ - id: art-viii
44
+ text: "Two-layer handoff documents required between agents (executive summary + detailed)."
45
+ priority: high
46
+
47
+ - id: art-ix
48
+ text: "Agent-driven interaction model with power user escape hatch."
49
+ priority: normal
50
+
51
+ - id: art-x
52
+ text: "Dynamic self-validation with binary pass/fail criteria."
53
+ priority: high
54
+
55
+ - id: art-xi
56
+ text: "Mode governance: clarity (read all, write chati.dev/), build (full), deploy (full + infra)."
57
+ priority: critical
58
+
59
+ - id: art-xii
60
+ text: "Context brackets are calculated, not hardcoded. CRITICAL = L0+L1 only. Handoff mandatory at < 15%."
61
+ priority: high
62
+
63
+ - id: art-xiii
64
+ text: "Memory capture is automatic. Never auto-modify user files. Proposals require explicit approval."
65
+ priority: high
66
+
67
+ - id: art-xiv
68
+ text: "Framework registry is source of truth. REUSE > ADAPT > CREATE preference."
69
+ priority: normal
70
+
71
+ - id: art-xv
72
+ text: "Session lock is mandatory when session is active. Exit requires explicit user intent."
73
+ priority: critical
74
+
75
+ - id: art-xvi
76
+ text: "Model governance: respect per-agent model assignments. No downgrade from assigned model."
77
+ priority: high
@@ -0,0 +1,64 @@
1
+ # Global Domain — Coding standards, bracket behavior, mode constraints
2
+ # Injected by PRISM L1 layer
3
+
4
+ rules:
5
+ - id: code-english
6
+ text: "All code, comments, and variable names must be in English."
7
+ priority: high
8
+
9
+ - id: code-conventions
10
+ text: "Follow existing codebase conventions. Check patterns before creating new ones."
11
+ priority: normal
12
+
13
+ - id: artifacts-english
14
+ text: "All artifacts (PRD, architecture docs, task definitions) must be in English."
15
+ priority: high
16
+
17
+ - id: interaction-lang
18
+ text: "Interact with user in their preferred language. Artifacts stay in English."
19
+ priority: normal
20
+
21
+ modes:
22
+ clarity:
23
+ writeScope: "chati.dev/"
24
+ allowedActions:
25
+ - read_any_file
26
+ - write_chati_dev_only
27
+ - create_artifacts
28
+ - run_analysis
29
+ blockedActions:
30
+ - modify_project_code
31
+ - run_destructive_commands
32
+ - deploy
33
+
34
+ build:
35
+ writeScope: "*"
36
+ allowedActions:
37
+ - read_any_file
38
+ - write_any_file
39
+ - run_tests
40
+ - run_linting
41
+ - git_operations
42
+ blockedActions:
43
+ - deploy_to_production
44
+ - modify_infrastructure
45
+
46
+ deploy:
47
+ writeScope: "*"
48
+ allowedActions:
49
+ - read_any_file
50
+ - write_any_file
51
+ - deploy_to_production
52
+ - modify_infrastructure
53
+ - run_tests
54
+ blockedActions: []
55
+
56
+ brackets:
57
+ FRESH:
58
+ behavior: "Full context injection. All layers active. Include detailed rules and examples."
59
+ MODERATE:
60
+ behavior: "Standard injection. Skip task detail layer (L4). Summarize long rules."
61
+ DEPLETED:
62
+ behavior: "Minimal injection. Only L0+L1+L2. Use rule IDs instead of full text."
63
+ CRITICAL:
64
+ behavior: "Emergency. L0+L1 only. Trigger handoff advisory. Preserve essential state."
@@ -0,0 +1,16 @@
1
+ # Brownfield Discovery Workflow Domain — PRISM L3
2
+ # Discovery-only pipeline (no implementation)
3
+
4
+ steps:
5
+ - brownfield-wu
6
+ - brief
7
+ - detail
8
+ - architect
9
+
10
+ rules:
11
+ - id: disc-deep
12
+ text: "Deep discovery is mandatory. Analyze full codebase before proceeding."
13
+ priority: critical
14
+ - id: disc-readonly
15
+ text: "Discovery workflow does not modify project code."
16
+ priority: high
@@ -0,0 +1,26 @@
1
+ # Brownfield Fullstack Workflow Domain — PRISM L3
2
+ # Full pipeline for existing projects (deep discovery required)
3
+
4
+ steps:
5
+ - brownfield-wu
6
+ - brief
7
+ - detail
8
+ - architect
9
+ - ux
10
+ - phases
11
+ - tasks
12
+ - qa-planning
13
+ - dev
14
+ - qa-implementation
15
+ - devops
16
+
17
+ rules:
18
+ - id: bf-deep
19
+ text: "Brownfield ALWAYS uses deep discovery. No Quick or Scout modes."
20
+ priority: critical
21
+ - id: bf-preserve
22
+ text: "Existing codebase conventions must be respected. REUSE > ADAPT > CREATE."
23
+ priority: high
24
+ - id: bf-risk
25
+ text: "Risk assessment from WU must be addressed in architecture decisions."
26
+ priority: high
@@ -0,0 +1,22 @@
1
+ # Brownfield Service Workflow Domain — PRISM L3
2
+ # Backend/API-focused pipeline (skip UX)
3
+
4
+ steps:
5
+ - brownfield-wu
6
+ - brief
7
+ - detail
8
+ - architect
9
+ - phases
10
+ - tasks
11
+ - qa-planning
12
+ - dev
13
+ - qa-implementation
14
+ - devops
15
+
16
+ rules:
17
+ - id: svc-no-ux
18
+ text: "Service workflow skips UX agent. Focus on API and backend."
19
+ priority: high
20
+ - id: svc-api
21
+ text: "API design is mandatory in architect phase."
22
+ priority: high
@@ -0,0 +1,22 @@
1
+ # Brownfield UI Workflow Domain — PRISM L3
2
+ # Frontend/UI-focused pipeline
3
+
4
+ steps:
5
+ - brownfield-wu
6
+ - brief
7
+ - detail
8
+ - ux
9
+ - phases
10
+ - tasks
11
+ - qa-planning
12
+ - dev
13
+ - qa-implementation
14
+ - devops
15
+
16
+ rules:
17
+ - id: ui-ux-required
18
+ text: "UX phase is mandatory for UI workflows. Do not skip."
19
+ priority: high
20
+ - id: ui-a11y
21
+ text: "Accessibility validation (a11y) is required during UX phase."
22
+ priority: high
@@ -0,0 +1,26 @@
1
+ # Greenfield Fullstack Workflow Domain — PRISM L3
2
+ # Full pipeline for new projects
3
+
4
+ steps:
5
+ - greenfield-wu
6
+ - brief
7
+ - detail
8
+ - architect
9
+ - ux
10
+ - phases
11
+ - tasks
12
+ - qa-planning
13
+ - dev
14
+ - qa-implementation
15
+ - devops
16
+
17
+ rules:
18
+ - id: gf-order
19
+ text: "Follow pipeline order strictly. WU must complete before Brief."
20
+ priority: high
21
+ - id: gf-parallel
22
+ text: "Detail, Architect, and UX can run in parallel after Brief."
23
+ priority: normal
24
+ - id: gf-gate
25
+ text: "QA-Planning gate must pass before entering BUILD phase."
26
+ priority: critical
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Constitution Guard Hook — PreToolUse (Write/Edit/Bash)
4
+ *
5
+ * BLOCKS operations that violate Constitution Article IV:
6
+ * - Writing files that contain secrets/credentials
7
+ * - Destructive operations without explicit user confirmation
8
+ *
9
+ * Also enforces Article XV: Session lock awareness.
10
+ */
11
+
12
+ const SECRET_PATTERNS = [
13
+ /(?:api[_-]?key|apikey)\s*[:=]\s*["']?[A-Za-z0-9_\-]{20,}/i,
14
+ /(?:secret|password|passwd|pwd)\s*[:=]\s*["']?[^\s"']{8,}/i,
15
+ /(?:token)\s*[:=]\s*["']?[A-Za-z0-9_\-]{20,}/i,
16
+ /(?:AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY)\s*[:=]/i,
17
+ /(?:PRIVATE[_-]?KEY|-----BEGIN (?:RSA |EC )?PRIVATE KEY)/i,
18
+ /(?:Bearer\s+)[A-Za-z0-9_\-./]{20,}/,
19
+ ];
20
+
21
+ const DESTRUCTIVE_COMMANDS = [
22
+ /rm\s+-rf\s+[/~]/,
23
+ /git\s+reset\s+--hard/,
24
+ /git\s+push\s+--force/,
25
+ /drop\s+(?:table|database)/i,
26
+ /truncate\s+table/i,
27
+ /DELETE\s+FROM\s+\w+\s*(?:;|$)/i,
28
+ ];
29
+
30
+ /**
31
+ * Check if content contains potential secrets.
32
+ */
33
+ function containsSecrets(content) {
34
+ if (!content || typeof content !== 'string') return [];
35
+ const found = [];
36
+ for (const pattern of SECRET_PATTERNS) {
37
+ if (pattern.test(content)) {
38
+ found.push(pattern.source.slice(0, 40));
39
+ }
40
+ }
41
+ return found;
42
+ }
43
+
44
+ /**
45
+ * Check if a bash command is destructive.
46
+ */
47
+ function isDestructiveCommand(command) {
48
+ if (!command || typeof command !== 'string') return false;
49
+ return DESTRUCTIVE_COMMANDS.some(pattern => pattern.test(command));
50
+ }
51
+
52
+ async function main() {
53
+ let input = '';
54
+ for await (const chunk of process.stdin) {
55
+ input += chunk;
56
+ }
57
+
58
+ try {
59
+ const event = JSON.parse(input);
60
+ const toolName = event.tool_name || '';
61
+ const toolInput = event.tool_input || {};
62
+
63
+ // Check Write/Edit operations for secrets
64
+ if (toolName === 'Write' || toolName === 'Edit') {
65
+ const content = toolInput.content || toolInput.new_string || '';
66
+ const secrets = containsSecrets(content);
67
+
68
+ if (secrets.length > 0) {
69
+ process.stdout.write(JSON.stringify({
70
+ decision: 'block',
71
+ reason: `[Article IV] Potential secret detected in file content. Pattern: ${secrets[0]}. Use environment variables instead.`,
72
+ }));
73
+ return;
74
+ }
75
+ }
76
+
77
+ // Check Bash operations for destructive commands
78
+ if (toolName === 'Bash') {
79
+ const command = toolInput.command || '';
80
+ if (isDestructiveCommand(command)) {
81
+ process.stdout.write(JSON.stringify({
82
+ decision: 'block',
83
+ reason: `[Article IV] Destructive command detected: "${command.slice(0, 60)}...". This requires explicit user confirmation.`,
84
+ }));
85
+ return;
86
+ }
87
+ }
88
+
89
+ process.stdout.write(JSON.stringify({ decision: 'allow' }));
90
+ } catch {
91
+ process.stdout.write(JSON.stringify({ decision: 'allow' }));
92
+ }
93
+ }
94
+
95
+ export { containsSecrets, isDestructiveCommand, SECRET_PATTERNS, DESTRUCTIVE_COMMANDS };
96
+
97
+ // Only run main when executed directly (not imported by tests)
98
+ import { fileURLToPath } from 'url';
99
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
100
+ main();
101
+ }
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Mode Governance Hook — PreToolUse (Write/Edit)
4
+ *
5
+ * BLOCKS write operations outside the scope of the current mode:
6
+ * - clarity mode: can only write to chati.dev/ and .chati/
7
+ * - build mode: can write anywhere
8
+ * - deploy mode: can write anywhere + infra
9
+ *
10
+ * Constitution Article XI enforcement.
11
+ */
12
+
13
+ import { existsSync, readFileSync } from 'fs';
14
+ import { join, relative, isAbsolute } from 'path';
15
+
16
+ const MODE_SCOPES = {
17
+ clarity: {
18
+ allowed: ['chati.dev/', '.chati/', 'chati.dev/artifacts/'],
19
+ description: 'Clarity mode: write only to chati.dev/ and .chati/',
20
+ },
21
+ build: {
22
+ allowed: ['*'],
23
+ description: 'Build mode: full write access',
24
+ },
25
+ deploy: {
26
+ allowed: ['*'],
27
+ description: 'Deploy mode: full write access including infrastructure',
28
+ },
29
+ };
30
+
31
+ function getCurrentMode(projectDir) {
32
+ const sessionPath = join(projectDir, '.chati', 'session.yaml');
33
+ if (!existsSync(sessionPath)) return 'clarity'; // Default to most restrictive
34
+
35
+ const raw = readFileSync(sessionPath, 'utf-8');
36
+ const match = raw.match(/^\s*mode:\s*(.+)$/m);
37
+ return match ? match[1].trim().replace(/^["']|["']$/g, '') : 'clarity';
38
+ }
39
+
40
+ function isPathAllowed(filePath, projectDir, mode) {
41
+ const scope = MODE_SCOPES[mode];
42
+ if (!scope) return false;
43
+
44
+ const rel = isAbsolute(filePath) ? relative(projectDir, filePath) : filePath;
45
+ // Block paths that escape the project — regardless of mode
46
+ if (rel.startsWith('..')) return false;
47
+
48
+ if (scope.allowed.includes('*')) return true;
49
+ return scope.allowed.some(prefix => rel.startsWith(prefix));
50
+ }
51
+
52
+ async function main() {
53
+ let input = '';
54
+ for await (const chunk of process.stdin) {
55
+ input += chunk;
56
+ }
57
+
58
+ try {
59
+ const event = JSON.parse(input);
60
+ const projectDir = event.cwd || process.cwd();
61
+ const toolInput = event.tool_input || {};
62
+ const filePath = toolInput.file_path || toolInput.path || '';
63
+
64
+ if (!filePath) {
65
+ process.stdout.write(JSON.stringify({ decision: 'allow' }));
66
+ return;
67
+ }
68
+
69
+ const mode = getCurrentMode(projectDir);
70
+
71
+ if (isPathAllowed(filePath, projectDir, mode)) {
72
+ process.stdout.write(JSON.stringify({ decision: 'allow' }));
73
+ } else {
74
+ const scope = MODE_SCOPES[mode];
75
+ process.stdout.write(JSON.stringify({
76
+ decision: 'block',
77
+ reason: `[Article XI] ${scope.description}. Cannot write to "${filePath}" in ${mode} mode.`,
78
+ }));
79
+ }
80
+ } catch {
81
+ // On error, allow (fail-open to avoid blocking legitimate work)
82
+ process.stdout.write(JSON.stringify({ decision: 'allow' }));
83
+ }
84
+ }
85
+
86
+ export { getCurrentMode, isPathAllowed, MODE_SCOPES };
87
+
88
+ // Only run main when executed directly (not imported by tests)
89
+ import { fileURLToPath } from 'url';
90
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
91
+ main();
92
+ }
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Model Governance Hook — UserPromptSubmit
4
+ *
5
+ * Validates that the model being used matches the agent's assignment.
6
+ * Constitution Article XVI enforcement.
7
+ *
8
+ * Model assignments (from agent definitions):
9
+ * - orchestrator: opus
10
+ * - brief, detail, phases, tasks: sonnet
11
+ * - architect, dev: sonnet | upgrade: opus if complex
12
+ * - ux: sonnet
13
+ * - qa-planning, qa-implementation: sonnet
14
+ * - devops: sonnet
15
+ * - greenfield-wu, brownfield-wu: sonnet
16
+ *
17
+ * This hook is advisory — it warns but does not block.
18
+ */
19
+
20
+ import { existsSync, readFileSync } from 'fs';
21
+ import { join } from 'path';
22
+
23
+ const AGENT_MODELS = {
24
+ orchestrator: 'opus',
25
+ 'greenfield-wu': 'sonnet',
26
+ 'brownfield-wu': 'sonnet',
27
+ brief: 'sonnet',
28
+ detail: 'sonnet',
29
+ architect: 'sonnet',
30
+ ux: 'sonnet',
31
+ phases: 'sonnet',
32
+ tasks: 'sonnet',
33
+ 'qa-planning': 'sonnet',
34
+ 'qa-implementation': 'sonnet',
35
+ dev: 'sonnet',
36
+ devops: 'sonnet',
37
+ };
38
+
39
+ function getCurrentAgent(projectDir) {
40
+ const sessionPath = join(projectDir, '.chati', 'session.yaml');
41
+ if (!existsSync(sessionPath)) return null;
42
+
43
+ const raw = readFileSync(sessionPath, 'utf-8');
44
+ const match = raw.match(/^\s*current_agent:\s*(.+)$/m);
45
+ return match ? match[1].trim().replace(/^["']|["']$/g, '') : null;
46
+ }
47
+
48
+ async function main() {
49
+ let input = '';
50
+ for await (const chunk of process.stdin) {
51
+ input += chunk;
52
+ }
53
+
54
+ try {
55
+ const event = JSON.parse(input);
56
+ const projectDir = event.cwd || process.cwd();
57
+ const agent = getCurrentAgent(projectDir);
58
+
59
+ if (agent && AGENT_MODELS[agent]) {
60
+ const expected = AGENT_MODELS[agent];
61
+ // Advisory note — appended to context
62
+ process.stdout.write(JSON.stringify({
63
+ result: 'allow',
64
+ prefix: `<!-- [Article XVI] Agent "${agent}" assigned model: ${expected} -->`,
65
+ }));
66
+ } else {
67
+ process.stdout.write(JSON.stringify({ result: 'allow' }));
68
+ }
69
+ } catch {
70
+ process.stdout.write(JSON.stringify({ result: 'allow' }));
71
+ }
72
+ }
73
+
74
+ export { AGENT_MODELS, getCurrentAgent };
75
+
76
+ main();
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PRISM Engine Hook — UserPromptSubmit
4
+ *
5
+ * Injects PRISM context block into every user prompt.
6
+ * Reads session state to determine bracket, agent, and mode,
7
+ * then runs the PRISM pipeline to produce XML context.
8
+ *
9
+ * Claude Code Hook: triggers on every user message submission.
10
+ */
11
+
12
+ import { existsSync, readFileSync } from 'fs';
13
+ import { join } from 'path';
14
+
15
+ /**
16
+ * Read session.yaml and extract key fields for PRISM.
17
+ */
18
+ function readSessionState(projectDir) {
19
+ const sessionPath = join(projectDir, '.chati', 'session.yaml');
20
+ if (!existsSync(sessionPath)) return null;
21
+
22
+ const raw = readFileSync(sessionPath, 'utf-8');
23
+ // Lightweight YAML extraction (avoid dependency)
24
+ const extract = (key) => {
25
+ const match = raw.match(new RegExp(`^\\s*${key}:\\s*(.+)$`, 'm'));
26
+ return match ? match[1].trim().replace(/^["']|["']$/g, '') : null;
27
+ };
28
+
29
+ return {
30
+ mode: extract('mode') || 'clarity',
31
+ currentAgent: extract('current_agent') || null,
32
+ workflow: extract('workflow') || null,
33
+ pipelinePosition: extract('pipeline_position') || null,
34
+ turnCount: parseInt(extract('turn_count') || '0', 10),
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Main hook handler.
40
+ * Reads stdin for hook event, outputs context to inject.
41
+ */
42
+ async function main() {
43
+ let input = '';
44
+ for await (const chunk of process.stdin) {
45
+ input += chunk;
46
+ }
47
+
48
+ try {
49
+ const event = JSON.parse(input);
50
+ const projectDir = event.cwd || process.cwd();
51
+ const session = readSessionState(projectDir);
52
+
53
+ if (!session) {
54
+ // No active session — don't inject anything
55
+ process.stdout.write(JSON.stringify({ result: 'allow' }));
56
+ return;
57
+ }
58
+
59
+ // Estimate remaining context from turn count
60
+ const maxTurns = 40;
61
+ const remainingPercent = Math.max(0, Math.round((1 - session.turnCount / maxTurns) * 100));
62
+
63
+ // Determine bracket
64
+ let bracket = 'FRESH';
65
+ if (remainingPercent < 25) bracket = 'CRITICAL';
66
+ else if (remainingPercent < 40) bracket = 'DEPLETED';
67
+ else if (remainingPercent < 60) bracket = 'MODERATE';
68
+
69
+ // Build minimal context block (full PRISM pipeline is used by orchestrator internally)
70
+ const contextBlock = [
71
+ `<chati-context bracket="${bracket}">`,
72
+ ` <mode>${session.mode}</mode>`,
73
+ session.currentAgent ? ` <agent>${session.currentAgent}</agent>` : '',
74
+ session.pipelinePosition ? ` <pipeline-position>${session.pipelinePosition}</pipeline-position>` : '',
75
+ bracket === 'CRITICAL' ? ' <advisory>Context running low. Consider handoff or summary.</advisory>' : '',
76
+ '</chati-context>',
77
+ ].filter(Boolean).join('\n');
78
+
79
+ process.stdout.write(JSON.stringify({
80
+ result: 'allow',
81
+ prefix: contextBlock,
82
+ }));
83
+ } catch {
84
+ // On error, allow without injection
85
+ process.stdout.write(JSON.stringify({ result: 'allow' }));
86
+ }
87
+ }
88
+
89
+ main();