guardian-framework 0.1.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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +463 -0
  3. package/dist/cli.js +12958 -0
  4. package/dist/exports.js +12765 -0
  5. package/package.json +61 -0
  6. package/templates/languages/go-patterns.md +411 -0
  7. package/templates/languages/java-patterns.md +545 -0
  8. package/templates/languages/python-patterns.md +312 -0
  9. package/templates/languages/rust-patterns.md +232 -0
  10. package/templates/languages/typescript-patterns.md +313 -0
  11. package/templates/pi/INDEX.md +437 -0
  12. package/templates/pi/agent/AGENTS.md +166 -0
  13. package/templates/pi/agents/architecture-coordinator.md +40 -0
  14. package/templates/pi/agents/architecture-validator.md +36 -0
  15. package/templates/pi/agents/bootstrap-implementer.md +37 -0
  16. package/templates/pi/agents/issue-factory.md +31 -0
  17. package/templates/pi/agents/operations-validator.md +32 -0
  18. package/templates/pi/agents/security-validator.md +33 -0
  19. package/templates/pi/architecture/CHANGELOG.md +78 -0
  20. package/templates/pi/architecture/decisions/ADR-template.md +76 -0
  21. package/templates/pi/architecture/diagrams/system-overview.md +159 -0
  22. package/templates/pi/architecture/modules/module-template.md +152 -0
  23. package/templates/pi/context/checklists.md +91 -0
  24. package/templates/pi/context/domain-workflow.md +180 -0
  25. package/templates/pi/context/output-formats.md +135 -0
  26. package/templates/pi/context/patterns-base.md +47 -0
  27. package/templates/pi/context/patterns.md +38 -0
  28. package/templates/pi/context/project.md +88 -0
  29. package/templates/pi/domain/exploration.md +93 -0
  30. package/templates/pi/domain/ubiquitous-language.md +24 -0
  31. package/templates/pi/extensions/architect-lib/generators.ts +528 -0
  32. package/templates/pi/extensions/architect-lib/helpers.ts +344 -0
  33. package/templates/pi/extensions/architect-lib/types.ts +117 -0
  34. package/templates/pi/extensions/architect.ts +1425 -0
  35. package/templates/pi/extensions/ask-user-question.ts +579 -0
  36. package/templates/pi/extensions/bash-guard.ts +556 -0
  37. package/templates/pi/extensions/config-reload.ts +115 -0
  38. package/templates/pi/extensions/coordinator.ts +304 -0
  39. package/templates/pi/extensions/curator.ts +543 -0
  40. package/templates/pi/extensions/domain-explorer.ts +990 -0
  41. package/templates/pi/extensions/filechanges.ts +656 -0
  42. package/templates/pi/extensions/goal-loop.ts +717 -0
  43. package/templates/pi/extensions/hooks.ts +452 -0
  44. package/templates/pi/extensions/kanban.ts +547 -0
  45. package/templates/pi/extensions/pipeline.ts +1246 -0
  46. package/templates/pi/extensions/plan-mode.ts +209 -0
  47. package/templates/pi/extensions/project-scaffolder.ts +284 -0
  48. package/templates/pi/extensions/read-only-mode.ts +192 -0
  49. package/templates/pi/extensions/redaction.ts +128 -0
  50. package/templates/pi/extensions/session-persistence.ts +174 -0
  51. package/templates/pi/extensions/slash-commands.ts +229 -0
  52. package/templates/pi/extensions/snippets.ts +201 -0
  53. package/templates/pi/extensions/validation-runner.ts +100 -0
  54. package/templates/pi/github/agents/architecture-coordinator.agent.md +27 -0
  55. package/templates/pi/github/agents/architecture-validator.agent.md +20 -0
  56. package/templates/pi/github/agents/bootstrap-implementer.agent.md +20 -0
  57. package/templates/pi/github/agents/epic-planner.agent.md +70 -0
  58. package/templates/pi/github/agents/issue-factory.agent.md +20 -0
  59. package/templates/pi/github/agents/operations-validator.agent.md +20 -0
  60. package/templates/pi/github/agents/security-validator.agent.md +20 -0
  61. package/templates/pi/github/copilot/settings.json +16 -0
  62. package/templates/pi/github/copilot-instructions.md +155 -0
  63. package/templates/pi/github/instructions/architecture.instructions.md +71 -0
  64. package/templates/pi/github/instructions/validation.instructions.md +69 -0
  65. package/templates/pi/github/workflows/01-planning-workflow.md +75 -0
  66. package/templates/pi/github/workflows/02-issue-generation-workflow.md +69 -0
  67. package/templates/pi/github/workflows/03-implementation-workflow.md +80 -0
  68. package/templates/pi/github/workflows/04-validation-workflow.md +68 -0
  69. package/templates/pi/preflight_report.json +99 -0
  70. package/templates/pi/prompts/blueprint-update.md +262 -0
  71. package/templates/pi/prompts/blueprint-validate.md +218 -0
  72. package/templates/pi/prompts/bug-fix.md +50 -0
  73. package/templates/pi/prompts/ci-blueprint.md +131 -0
  74. package/templates/pi/prompts/context-refresh.md +258 -0
  75. package/templates/pi/prompts/epic-plan.md +356 -0
  76. package/templates/pi/prompts/epic-template.md +186 -0
  77. package/templates/pi/prompts/feature-development.md +131 -0
  78. package/templates/pi/prompts/git-issues.md +243 -0
  79. package/templates/pi/prompts/hotfix.md +71 -0
  80. package/templates/pi/prompts/issue-closeout.md +342 -0
  81. package/templates/pi/prompts/issue-draft.md +218 -0
  82. package/templates/pi/prompts/issue-implementation-series.md +173 -0
  83. package/templates/pi/prompts/issue-merge.md +372 -0
  84. package/templates/pi/prompts/issue-template-set.md +392 -0
  85. package/templates/pi/prompts/issue-template.md +207 -0
  86. package/templates/pi/prompts/pattern-extract.md +269 -0
  87. package/templates/pi/prompts/plan-to-issues.md +430 -0
  88. package/templates/pi/prompts/refactoring.md +82 -0
  89. package/templates/pi/prompts/scope-analyzer.md +254 -0
  90. package/templates/pi/prompts/sync-check.md +230 -0
  91. package/templates/pi/scripts/categorize-issues.sh +171 -0
  92. package/templates/pi/scripts/ci/check_architecture_conformance.sh +748 -0
  93. package/templates/pi/scripts/ci/check_planning_packet.py +228 -0
  94. package/templates/pi/scripts/ci/run_hardening_stages.sh +264 -0
  95. package/templates/pi/scripts/ci/run_preflight.sh +649 -0
  96. package/templates/pi/scripts/ci/run_stage.sh +193 -0
  97. package/templates/pi/scripts/ci/stage_docs_policy.sh +82 -0
  98. package/templates/pi/scripts/ci/stage_integration.sh +3 -0
  99. package/templates/pi/scripts/ci/stage_lint.sh +130 -0
  100. package/templates/pi/scripts/ci/stage_migration_verify.sh +3 -0
  101. package/templates/pi/scripts/ci/stage_package_build.sh +3 -0
  102. package/templates/pi/scripts/ci/stage_release_readiness.sh +3 -0
  103. package/templates/pi/scripts/ci/stage_remaining.sh +242 -0
  104. package/templates/pi/scripts/ci/stage_security.sh +3 -0
  105. package/templates/pi/scripts/ci/stage_static_analysis.sh +114 -0
  106. package/templates/pi/scripts/ci/stage_unit.sh +119 -0
  107. package/templates/pi/scripts/ci/validate_agent_output.py +181 -0
  108. package/templates/pi/scripts/ci/validate_agent_output.sh +243 -0
  109. package/templates/pi/scripts/create-feature-branch.sh +136 -0
  110. package/templates/pi/scripts/create-mr.sh +117 -0
  111. package/templates/pi/scripts/fetch-issues.sh +131 -0
  112. package/templates/pi/scripts/generate-architecture.sh +161 -0
  113. package/templates/pi/scripts/git/close-epic.sh +69 -0
  114. package/templates/pi/scripts/git/close-issue.sh +35 -0
  115. package/templates/pi/scripts/git/create-tracking-issue.sh +174 -0
  116. package/templates/pi/scripts/git/link-issue-to-epic.sh +51 -0
  117. package/templates/pi/scripts/git/update-tracking-issue.sh +66 -0
  118. package/templates/pi/scripts/languages/go/validate-architecture.sh +139 -0
  119. package/templates/pi/scripts/languages/go/validate-canonical.sh +129 -0
  120. package/templates/pi/scripts/languages/go/validate-ci.sh +132 -0
  121. package/templates/pi/scripts/languages/go/validate-integration.sh +156 -0
  122. package/templates/pi/scripts/languages/go/validate-operations.sh +146 -0
  123. package/templates/pi/scripts/languages/go/validate-security.sh +135 -0
  124. package/templates/pi/scripts/languages/go/validate-tests.sh +125 -0
  125. package/templates/pi/scripts/languages/java/validate-annotations.sh +185 -0
  126. package/templates/pi/scripts/languages/java/validate-architecture.sh +159 -0
  127. package/templates/pi/scripts/languages/java/validate-canonical.sh +114 -0
  128. package/templates/pi/scripts/languages/java/validate-ci.sh +269 -0
  129. package/templates/pi/scripts/languages/java/validate-integration.sh +149 -0
  130. package/templates/pi/scripts/languages/java/validate-operations.sh +142 -0
  131. package/templates/pi/scripts/languages/java/validate-security.sh +174 -0
  132. package/templates/pi/scripts/languages/java/validate-spring-architecture.sh +227 -0
  133. package/templates/pi/scripts/languages/java/validate-tests.sh +159 -0
  134. package/templates/pi/scripts/languages/python/validate-architecture.sh +99 -0
  135. package/templates/pi/scripts/languages/python/validate-canonical.sh +124 -0
  136. package/templates/pi/scripts/languages/python/validate-ci.sh +130 -0
  137. package/templates/pi/scripts/languages/python/validate-integration.sh +119 -0
  138. package/templates/pi/scripts/languages/python/validate-operations.sh +107 -0
  139. package/templates/pi/scripts/languages/python/validate-security.sh +68 -0
  140. package/templates/pi/scripts/languages/python/validate-tests.sh +102 -0
  141. package/templates/pi/scripts/languages/rust/validate-architecture.sh +188 -0
  142. package/templates/pi/scripts/languages/rust/validate-canonical.sh +146 -0
  143. package/templates/pi/scripts/languages/rust/validate-ci.sh +147 -0
  144. package/templates/pi/scripts/languages/rust/validate-integration.sh +149 -0
  145. package/templates/pi/scripts/languages/rust/validate-operations.sh +154 -0
  146. package/templates/pi/scripts/languages/rust/validate-security.sh +153 -0
  147. package/templates/pi/scripts/languages/rust/validate-tests.sh +150 -0
  148. package/templates/pi/scripts/languages/typescript/validate-architecture.sh +157 -0
  149. package/templates/pi/scripts/languages/typescript/validate-canonical.sh +135 -0
  150. package/templates/pi/scripts/languages/typescript/validate-ci.sh +244 -0
  151. package/templates/pi/scripts/languages/typescript/validate-integration.sh +166 -0
  152. package/templates/pi/scripts/languages/typescript/validate-operations.sh +162 -0
  153. package/templates/pi/scripts/languages/typescript/validate-security.sh +169 -0
  154. package/templates/pi/scripts/languages/typescript/validate-tests.sh +158 -0
  155. package/templates/pi/scripts/merge-mr.sh +95 -0
  156. package/templates/pi/scripts/mr-validation.sh +228 -0
  157. package/templates/pi/scripts/validate-architecture-readiness.sh +153 -0
  158. package/templates/pi/scripts/validate-architecture.sh +22 -0
  159. package/templates/pi/scripts/validate-canonical.sh +22 -0
  160. package/templates/pi/scripts/validate-ci.sh +37 -0
  161. package/templates/pi/scripts/validate-integration.sh +22 -0
  162. package/templates/pi/scripts/validate-operations.sh +22 -0
  163. package/templates/pi/scripts/validate-security.sh +22 -0
  164. package/templates/pi/scripts/validate-tests.sh +22 -0
  165. package/templates/pi/scripts/validate-ubiquitous-language.sh +291 -0
  166. package/templates/pi/scripts/validation-cache.sh +139 -0
  167. package/templates/pi/skills/agents/architecture-coordinator.md +178 -0
  168. package/templates/pi/skills/agents/architecture-generator.md +79 -0
  169. package/templates/pi/skills/agents/architecture-validator.md +74 -0
  170. package/templates/pi/skills/agents/ci-mr-validator.md +46 -0
  171. package/templates/pi/skills/agents/code-developer.md +76 -0
  172. package/templates/pi/skills/agents/commit.md +46 -0
  173. package/templates/pi/skills/agents/curator.md +71 -0
  174. package/templates/pi/skills/agents/debug.md +59 -0
  175. package/templates/pi/skills/agents/documentation-maintainer.md +36 -0
  176. package/templates/pi/skills/agents/goal-loop.md +125 -0
  177. package/templates/pi/skills/agents/hooks.md +122 -0
  178. package/templates/pi/skills/agents/integration-validator.md +35 -0
  179. package/templates/pi/skills/agents/issue-creator.md +75 -0
  180. package/templates/pi/skills/agents/issue-factory.md +143 -0
  181. package/templates/pi/skills/agents/kanban.md +85 -0
  182. package/templates/pi/skills/agents/land.md +59 -0
  183. package/templates/pi/skills/agents/operations-validator.md +43 -0
  184. package/templates/pi/skills/agents/pipeline.md +113 -0
  185. package/templates/pi/skills/agents/plan-mode.md +77 -0
  186. package/templates/pi/skills/agents/pull.md +40 -0
  187. package/templates/pi/skills/agents/push.md +41 -0
  188. package/templates/pi/skills/agents/security-validator.md +85 -0
  189. package/templates/pi/skills/agents/session-persistence.md +119 -0
  190. package/templates/pi/skills/agents/slash-commands.md +117 -0
  191. package/templates/pi/skills/agents/snippets.md +99 -0
  192. package/templates/pi/skills/agents/subagent-registry.md +78 -0
  193. package/templates/pi/skills/agents/test-validator.md +42 -0
  194. package/templates/pi/skills/validators/architecture-validator.md +43 -0
  195. package/templates/pi/skills/validators/ci-validator.md +27 -0
  196. package/templates/pi/skills/validators/context-compaction.md +73 -0
  197. package/templates/pi/skills/validators/integration-validator.md +38 -0
  198. package/templates/pi/skills/validators/model-registry.md +96 -0
  199. package/templates/pi/skills/validators/operations-validator.md +34 -0
  200. package/templates/pi/skills/validators/security-guards.md +72 -0
  201. package/templates/pi/skills/validators/security-validator.md +41 -0
  202. package/templates/pi/skills/validators/system-prompt-tiers.md +69 -0
  203. package/templates/pi/skills/validators/test-validator.md +33 -0
  204. package/templates/pi/types.ts +62 -0
  205. package/templates/pi/validators/README.md +93 -0
  206. package/templates/pi/validators/default.toml +209 -0
  207. package/templates/pi/validators/spring.toml +142 -0
  208. package/templates/pi/workpad.md +53 -0
  209. package/templates/project/java/Dockerfile +14 -0
  210. package/templates/project/java/README.md +40 -0
  211. package/templates/project/java/pom.xml +132 -0
  212. package/templates/project/typescript/Dockerfile +15 -0
  213. package/templates/project/typescript/README.md +29 -0
  214. package/templates/project/typescript/package.json +23 -0
  215. package/templates/project/typescript/tsconfig.json +21 -0
  216. package/templates/workflow.md +123 -0
@@ -0,0 +1,291 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-ubiquitous-language.sh — Detect Code Drift from Ubiquitous Language
4
+ #
5
+ # Parses .pi/domain/ubiquitous-language.md for the canonical term list,
6
+ # then greps src/ for class/function/variable/type names, flagging any
7
+ # that use an alias/synonym instead of the canonical term.
8
+ #
9
+ # Canonical Reference: .pi/architecture/modules/core-libraries.md
10
+ # Implements: Ubiquitous Language drift detection
11
+ # Issue: (add issue number here)
12
+ # Last Architecture Sync: 2026-05-31
13
+ #
14
+ # Usage:
15
+ # bash .pi/scripts/validate-ubiquitous-language.sh [src_dir]
16
+ #
17
+ # Exit codes:
18
+ # 0 = No drift detected (all code uses canonical terms)
19
+ # 1 = Drift detected (one or more aliases found)
20
+ # ============================================================================
21
+ set -euo pipefail
22
+
23
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
24
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
25
+ GLOSSARY_FILE="${PROJECT_ROOT}/.pi/domain/ubiquitous-language.md"
26
+ SRC_DIR="${1:-${PROJECT_ROOT}/src}"
27
+
28
+ PASS_COUNT=0; ERROR_COUNT=0; WARN_COUNT=0; DRIFT_FOUND=0
29
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
30
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
31
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERROR_COUNT=$((ERROR_COUNT + 1)); DRIFT_FOUND=1; }
32
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARN_COUNT=$((WARN_COUNT + 1)); }
33
+ info() { echo -e "${BLUE}ℹ️ INFO${NC} $1"; }
34
+
35
+ echo "============================================"
36
+ echo " Ubiquitous Language Validation"
37
+ echo "============================================"
38
+ echo ""
39
+
40
+ # ─────────────────────────────────────────────────────────────────────────────
41
+ # Check: Glossary file exists
42
+ # ─────────────────────────────────────────────────────────────────────────────
43
+ echo "--- Preflight ---"
44
+ if [ ! -f "$GLOSSARY_FILE" ]; then
45
+ fail "Glossary not found at: $GLOSSARY_FILE"
46
+ info "Run the validator from the project root."
47
+ echo ""
48
+ echo "============================================"
49
+ echo " Summary"
50
+ echo "============================================"
51
+ echo -e " Passed: ${GREEN}0${NC}"
52
+ echo -e " Failed: ${RED}1${NC}"
53
+ exit 1
54
+ fi
55
+ pass "Glossary found: $GLOSSARY_FILE"
56
+
57
+ if [ ! -d "$SRC_DIR" ]; then
58
+ fail "Source directory not found: $SRC_DIR"
59
+ echo ""
60
+ echo "============================================"
61
+ echo " Summary"
62
+ echo "============================================"
63
+ echo -e " Passed: ${GREEN}0${NC}"
64
+ echo -e " Failed: ${RED}1${NC}"
65
+ exit 1
66
+ fi
67
+ pass "Source directory found: $SRC_DIR"
68
+
69
+ # ─────────────────────────────────────────────────────────────────────────────
70
+ # Parse Glossary — extract canonical terms and aliases
71
+ # ─────────────────────────────────────────────────────────────────────────────
72
+ echo ""
73
+ echo "--- Parsing Glossary ---"
74
+
75
+ # Parse the markdown table:
76
+ # Format: | Term | Definition | Bounded Context | Aliases/Synonyms | Examples |
77
+ # We need columns 1 (Term) and 4 (Aliases/Synonyms)
78
+ #
79
+ # Strategy: extract lines starting with "|", skip header/separator, parse columns
80
+
81
+ declare -a CANONICAL_TERMS=()
82
+ declare -a ALIAS_LISTS=() # Same index as CANONICAL_TERMS, pipe-separated aliases
83
+ GLOSSARY_ENTRIES=0
84
+
85
+ while IFS='|' read -r _ term _ _ aliases _; do
86
+ # Trim whitespace
87
+ term=$(echo "$term" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
88
+ aliases=$(echo "$aliases" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
89
+
90
+ # Skip header row, separator row, and empty rows
91
+ [ -z "$term" ] && continue
92
+ [ "$term" = "Term" ] && continue
93
+ [ "$(echo "$term" | tr -d ' -')" = "" ] && continue
94
+
95
+ # Skip if term contains only dashes (separator row like |------|)
96
+ [[ "$term" =~ ^-+$ ]] && continue
97
+
98
+ CANONICAL_TERMS+=("$term")
99
+ ALIAS_LISTS+=("$aliases")
100
+ GLOSSARY_ENTRIES=$((GLOSSARY_ENTRIES + 1))
101
+ done < <(grep '^|' "$GLOSSARY_FILE")
102
+
103
+ if [ "$GLOSSARY_ENTRIES" -eq 0 ]; then
104
+ fail "No glossary entries found in $GLOSSARY_FILE"
105
+ echo ""
106
+ echo "============================================"
107
+ echo " Summary"
108
+ echo "============================================"
109
+ echo -e " Passed: ${GREEN}0${NC}"
110
+ echo -e " Failed: ${RED}1${NC}"
111
+ exit 1
112
+ fi
113
+ pass "Parsed $GLOSSARY_ENTRIES glossary entries"
114
+
115
+ # Debug: show parsed terms and aliases
116
+ for i in "${!CANONICAL_TERMS[@]}"; do
117
+ term="${CANONICAL_TERMS[$i]}"
118
+ aliases="${ALIAS_LISTS[$i]}"
119
+ if [ -n "$aliases" ]; then
120
+ info " • \"$term\" → aliases: $aliases"
121
+ fi
122
+ done
123
+
124
+ # ─────────────────────────────────────────────────────────────────────────────
125
+ # Find TypeScript identifiers in src/
126
+ # ─────────────────────────────────────────────────────────────────────────────
127
+ echo ""
128
+ echo "--- Scanning Source Code ---"
129
+
130
+ TS_FILES=$(find "$SRC_DIR" -type f \( -name "*.ts" -o -name "*.tsx" \) 2>/dev/null | sort)
131
+ TS_FILE_COUNT=$(echo "$TS_FILES" | grep -c . 2>/dev/null || echo "0")
132
+
133
+ if [ "$TS_FILE_COUNT" -eq 0 ]; then
134
+ warn "No TypeScript files found in $SRC_DIR"
135
+ echo ""
136
+ echo "============================================"
137
+ echo " Summary"
138
+ echo "============================================"
139
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
140
+ echo -e " Warnings: ${YELLOW}${WARN_COUNT}${NC}"
141
+ exit 0
142
+ fi
143
+ pass "Found $TS_FILE_COUNT TypeScript files to scan"
144
+
145
+ # ─────────────────────────────────────────────────────────────────────────────
146
+ # Extract identifiers from TypeScript files
147
+ # ─────────────────────────────────────────────────────────────────────────────
148
+ # We extract:
149
+ # - Class/interface/type/enum names (after keyword)
150
+ # - Function names (after "function" or in arrow-function const assignments)
151
+ # - Exported const/variable names
152
+ # - Import aliases (e.g., "import { X as Y }")
153
+ # - Named exports (export function/class/interface/type)
154
+
155
+ # Build a temporary file of all identifiers with their file:line locations
156
+ IDENTIFIER_FILE=$(mktemp)
157
+ trap 'rm -f "$IDENTIFIER_FILE"' EXIT
158
+
159
+ # Use perl for portable regex extraction with capturing groups
160
+ perl -nle '
161
+ # Skip non-source files
162
+ next unless -f $ARGV;
163
+
164
+ my $file = $ARGV;
165
+ my $line_no = $.;
166
+ chomp;
167
+
168
+ # Match: export (class|interface|type|enum|function) Name
169
+ if (/\bexport\s+(class|interface|type|enum|function)\s+([A-Za-z_][A-Za-z0-9_]*)/) {
170
+ print "$file:$line_no:$2";
171
+ }
172
+
173
+ # Match: (class|interface|type|enum|function) Name (without export)
174
+ if (/\b(class|interface|type|enum|function)\s+([A-Za-z_][A-Za-z0-9_]*)/) {
175
+ print "$file:$line_no:$2";
176
+ }
177
+
178
+ # Match: (const|let|var) Name
179
+ if (/\b(const|let|var)\s+([A-Za-z_][A-Za-z0-9_]*)\s*[=:]/) {
180
+ print "$file:$line_no:$2";
181
+ }
182
+
183
+ # Match: export default (class|function) Name
184
+ if (/\bexport\s+default\s+(class|function)\s+([A-Za-z_][A-Za-z0-9_]*)/) {
185
+ print "$file:$line_no:$2";
186
+ }
187
+
188
+ # Match: import { ... as Alias }
189
+ if (/\bimport\s*\{[^}]*\}\s*from/) {
190
+ # Find all "as X" patterns
191
+ my $rest = $_;
192
+ while ($rest =~ /\bas\s+([A-Za-z_][A-Za-z0-9_]*)/g) {
193
+ print "$file:$line_no:$1";
194
+ }
195
+ }
196
+
197
+ # Match: function Name(...)
198
+ if (/\bfunction\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(/) {
199
+ print "$file:$line_no:$1";
200
+ }
201
+ ' $TS_FILES 2>/dev/null >> "$IDENTIFIER_FILE" || true
202
+
203
+ IDENTIFIER_COUNT=$(wc -l < "$IDENTIFIER_FILE" | tr -d ' ')
204
+ if [ "$IDENTIFIER_COUNT" -eq 0 ]; then
205
+ warn "No identifiers extracted from TypeScript files"
206
+ else
207
+ info "Extracted $IDENTIFIER_COUNT identifiers"
208
+ fi
209
+
210
+ # ─────────────────────────────────────────────────────────────────────────────
211
+ # Check each identifier against canonical terms and aliases
212
+ # ─────────────────────────────────────────────────────────────────────────────
213
+ echo ""
214
+ echo "--- Drift Detection ---"
215
+
216
+ DRIFT_COUNT=0
217
+
218
+ for i in "${!CANONICAL_TERMS[@]}"; do
219
+ canonical="${CANONICAL_TERMS[$i]}"
220
+ aliases="${ALIAS_LISTS[$i]}"
221
+
222
+ # Skip if no aliases defined for this term
223
+ [ -z "$aliases" ] && continue
224
+
225
+ # Split aliases by comma and check each one
226
+ IFS=',' read -ra ALIAS_ARRAY <<< "$aliases"
227
+ for alias in "${ALIAS_ARRAY[@]}"; do
228
+ # Trim whitespace
229
+ alias=$(echo "$alias" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
230
+ [ -z "$alias" ] && continue
231
+
232
+ # Check if this alias is the same as the canonical term (skip)
233
+ if [ "$alias" = "$canonical" ]; then
234
+ continue
235
+ fi
236
+
237
+ # Search identifiers for this alias
238
+ # Use grep -F for exact string matching, -w for whole word
239
+ MATCHES=$(grep -F ":$alias" "$IDENTIFIER_FILE" 2>/dev/null || true)
240
+
241
+ if [ -n "$MATCHES" ]; then
242
+ # Found drift — this alias is used in code
243
+ while IFS= read -r match; do
244
+ # Parse file:line:identifier
245
+ match_file=$(echo "$match" | cut -d: -f1)
246
+ match_line=$(echo "$match" | cut -d: -f2)
247
+ match_id=$(echo "$match" | cut -d: -f3-)
248
+
249
+ # Convert to relative path
250
+ rel_file="${match_file#$PROJECT_ROOT/}"
251
+
252
+ fail "Alias \"$alias\" used instead of canonical \"$canonical\" → ${rel_file}:${match_line} (identifier: $match_id)"
253
+ DRIFT_COUNT=$((DRIFT_COUNT + 1))
254
+ done <<< "$MATCHES"
255
+ fi
256
+ done
257
+ done
258
+
259
+ if [ "$DRIFT_COUNT" -eq 0 ]; then
260
+ pass "No drift detected — all code uses canonical terms"
261
+ fi
262
+
263
+ # ─────────────────────────────────────────────────────────────────────────────
264
+ # Also check for case variations of canonical terms
265
+ # Note: Canonical term case variation checks are intentionally omitted.
266
+ # TypeScript convention uses PascalCase for types (e.g., Result, Manifest)
267
+ # and camelCase for variable instances (e.g., result, manifest).
268
+ # Both are correct in context and not drift.
269
+
270
+ # ─────────────────────────────────────────────────────────────────────────────
271
+ # Summary
272
+ # ─────────────────────────────────────────────────────────────────────────────
273
+ echo ""
274
+ echo "============================================"
275
+ echo " Summary"
276
+ echo "============================================"
277
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
278
+ echo -e " Warnings: ${YELLOW}${WARN_COUNT}${NC}"
279
+ echo -e " Drift: ${RED}${DRIFT_COUNT}${NC}"
280
+
281
+ if [ "$DRIFT_FOUND" -eq 1 ]; then
282
+ echo ""
283
+ echo -e "${RED}❌ Ubiquitous language drift detected.${NC}"
284
+ echo " Fix: Replace aliases with canonical terms in the listed files."
285
+ echo " Then re-run this validator."
286
+ exit 1
287
+ fi
288
+
289
+ echo ""
290
+ echo -e "${GREEN}✅ Ubiquitous language validation passed.${NC}"
291
+ exit 0
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validation-cache.sh — Validation Result Caching System
4
+ #
5
+ # Caches passed validation checks so retries only re-check failed items.
6
+ #
7
+ # Usage:
8
+ # bash .pi/scripts/validation-cache.sh init [task-id]
9
+ # bash .pi/scripts/validation-cache.sh record [task-id] [validator] [check] [pass|fail]
10
+ # bash .pi/scripts/validation-cache.sh get-failed [task-id] [validator]
11
+ # bash .pi/scripts/validation-cache.sh summary [task-id]
12
+ # bash .pi/scripts/validation-cache.sh clear [task-id]
13
+ #
14
+ # Exit codes: 0 = success, 1 = error
15
+ # ============================================================================
16
+ set -euo pipefail
17
+
18
+ CACHE_DIR=".claude/validation-cache"
19
+ mkdir -p "$CACHE_DIR"
20
+
21
+ ACTION="${1:-help}"
22
+ TASK_ID="${2:-}"
23
+ VALIDATOR="${3:-}"
24
+ CHECK="${4:-}"
25
+ STATUS="${5:-}"
26
+
27
+ CACHE_FILE() { echo "${CACHE_DIR}/${TASK_ID}.cache"; }
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # Init — create empty cache for a task
31
+ # ---------------------------------------------------------------------------
32
+ init_cache() {
33
+ if [ -z "$TASK_ID" ]; then
34
+ echo "Usage: $0 init <task-id>"
35
+ exit 1
36
+ fi
37
+ echo "# Validation Cache: $TASK_ID" > "$(CACHE_FILE)"
38
+ echo "# Format: validator|check|status|timestamp" >> "$(CACHE_FILE)"
39
+ echo "Initialized cache for task: $TASK_ID"
40
+ }
41
+
42
+ # ---------------------------------------------------------------------------
43
+ # Record — log a validation result
44
+ # ---------------------------------------------------------------------------
45
+ record_result() {
46
+ if [ -z "$TASK_ID" ] || [ -z "$VALIDATOR" ] || [ -z "$CHECK" ] || [ -z "$STATUS" ]; then
47
+ echo "Usage: $0 record <task-id> <validator> <check> <pass|fail>"
48
+ exit 1
49
+ fi
50
+ TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
51
+ echo "${VALIDATOR}|${CHECK}|${STATUS}|${TIMESTAMP}" >> "$(CACHE_FILE)"
52
+ }
53
+
54
+ # ---------------------------------------------------------------------------
55
+ # Get Failed — list only failed checks for a validator (for retry)
56
+ # ---------------------------------------------------------------------------
57
+ get_failed() {
58
+ if [ -z "$TASK_ID" ] || [ -z "$VALIDATOR" ]; then
59
+ echo "Usage: $0 get-failed <task-id> <validator>"
60
+ exit 1
61
+ fi
62
+ if [ ! -f "$(CACHE_FILE)" ]; then
63
+ echo "No cache found for task: $TASK_ID"
64
+ exit 1
65
+ fi
66
+ FAILED=$(grep "^${VALIDATOR}|" "$(CACHE_FILE)" | grep "|fail|" | cut -d'|' -f2 || true)
67
+ if [ -z "$FAILED" ]; then
68
+ echo "ALL_PASSED"
69
+ else
70
+ echo "$FAILED"
71
+ fi
72
+ }
73
+
74
+ # ---------------------------------------------------------------------------
75
+ # Summary — show full validation status for a task
76
+ # ---------------------------------------------------------------------------
77
+ show_summary() {
78
+ if [ -z "$TASK_ID" ]; then
79
+ echo "Usage: $0 summary <task-id>"
80
+ exit 1
81
+ fi
82
+ if [ ! -f "$(CACHE_FILE)" ]; then
83
+ echo "No cache found for task: $TASK_ID"
84
+ exit 1
85
+ fi
86
+
87
+ TOTAL=$(grep -v "^#" "$(CACHE_FILE)" | wc -l | tr -d ' ')
88
+ PASSED=$(grep -v "^#" "$(CACHE_FILE)" | grep "|pass|" | wc -l | tr -d ' ')
89
+ FAILED=$(grep -v "^#" "$(CACHE_FILE)" | grep "|fail|" | wc -l | tr -d ' ')
90
+
91
+ echo "============================================"
92
+ echo " Validation Summary: $TASK_ID"
93
+ echo "============================================"
94
+ echo " Total: $TOTAL"
95
+ echo " Passed: $PASSED"
96
+ echo " Failed: $FAILED"
97
+ echo ""
98
+
99
+ if [ "$FAILED" -gt 0 ]; then
100
+ echo "Failed checks:"
101
+ grep -v "^#" "$(CACHE_FILE)" | grep "|fail|" | while IFS='|' read -r val chk sts ts; do
102
+ echo " [$val] $chk"
103
+ done
104
+ fi
105
+ }
106
+
107
+ # ---------------------------------------------------------------------------
108
+ # Clear — remove cache for a task
109
+ # ---------------------------------------------------------------------------
110
+ clear_cache() {
111
+ if [ -z "$TASK_ID" ]; then
112
+ echo "Usage: $0 clear <task-id>"
113
+ exit 1
114
+ fi
115
+ rm -f "$(CACHE_FILE)"
116
+ echo "Cleared cache for task: $TASK_ID"
117
+ }
118
+
119
+ # ---------------------------------------------------------------------------
120
+ # Dispatch
121
+ # ---------------------------------------------------------------------------
122
+ case "$ACTION" in
123
+ init) init_cache ;;
124
+ record) record_result ;;
125
+ get-failed) get_failed ;;
126
+ summary) show_summary ;;
127
+ clear) clear_cache ;;
128
+ *)
129
+ echo "Usage: $0 {init|record|get-failed|summary|clear} [args...]"
130
+ echo ""
131
+ echo "Commands:"
132
+ echo " init <task-id> Create empty cache"
133
+ echo " record <task-id> <validator> <check> <status> Record result"
134
+ echo " get-failed <task-id> <validator> List failed checks"
135
+ echo " summary <task-id> Show full status"
136
+ echo " clear <task-id> Remove cache"
137
+ exit 1
138
+ ;;
139
+ esac
@@ -0,0 +1,178 @@
1
+ ---
2
+ name: architecture-coordinator
3
+ description: Master orchestrator. Classifies scope, reviews ADRs, challenges architecture, spawns validators, makes final decisions. Use for multi-component features or complex changes.
4
+ model: inherit
5
+ tools: [Read, Write, Edit, Bash, Grep, Glob, Agent]
6
+ ---
7
+
8
+ # Architecture Coordinator
9
+
10
+ You are the master orchestrator. You classify tasks, spawn validators, and make final decisions.
11
+
12
+ ## Understand Before You Build
13
+
14
+ **THE MOST IMPORTANT RULE: YOU DON'T ASSUME, YOU VERIFY.** Ground all communication in evidence-based facts. Follow your knowledge but always check your work and back it up with hard, up-to-date data that you looked up yourself.
15
+
16
+ Never start implementing until you are **100% certain** of what needs to be done. If you catch yourself thinking "I think this is how it works" — STOP. That's a signal to ask or scout, not to start coding.
17
+
18
+ **Fill knowledge gaps with:**
19
+ - **`ask_user_question`** — ambiguous requirements, preference between approaches, any detail that would materially change the implementation. One question per call. Never guess what the user wants.
20
+ - **Automated validation scripts** — how the codebase works, which files are involved, what patterns exist. Run `grep`, `find`, `ls`, targeted `read`.
21
+ - **Subagent validators** — architecture, security, operations compliance.
22
+
23
+ **Before any non-trivial implementation, you must know:**
24
+ - Exactly what the change does (confirmed with user)
25
+ - Exactly which files are involved (verified with grep/find/read)
26
+ - Exactly which patterns to follow (verified in existing code)
27
+
28
+ If any of those are fuzzy, you're not ready to implement.
29
+
30
+ ## Context (Load ONCE)
31
+ - `.pi/architecture/modules/` — module architecture docs (read relevant modules only)
32
+ - `.pi/architecture/decisions/` — ADRs (review all accepted/proposed ADRs relevant to scope)
33
+ - `.pi/architecture/CHANGELOG.md` — recent architecture changes
34
+ - `.pi/context/project.md` — project knowledge
35
+ - `.pi/context/checklists.md` — validation checklists
36
+ - `.pi/context/output-formats.md` — report templates
37
+
38
+ ## Protocol
39
+
40
+ ### Phase 1: Discovery
41
+ 1. **Classify scope** using scope table (files changed, lines affected, module touched)
42
+ 2. **Load relevant ADRs** — find all accepted/proposed ADRs that affect the modules in scope
43
+ 3. **Review module docs** — read `.pi/architecture/modules/[affected-module].md` for affected modules only
44
+
45
+ ### Phase 2: Architecture Challenge
46
+ 4. **Challenge the current design** — before accepting the approach, ask:
47
+ - Does this align with existing ADRs? If not, should we update them or propose a new ADR?
48
+ - Are there better patterns already established in the codebase? (grep for similar implementations)
49
+ - Does this create tight coupling between modules? Check module dependency graph.
50
+ - Is there a simpler approach that achieves the same outcome?
51
+ - What are the long-term maintenance implications?
52
+ 5. **If architecture gaps found:** propose ADR updates or new ADRs *before* proceeding. Get user alignment.
53
+
54
+ ### Phase 3: Validation
55
+ 6. **Determine validators** per scope classification
56
+ 7. **Spawn validators in parallel** for plan review (NOT code review yet)
57
+ 8. **Synthesize results** → Design Proposal (use `.pi/context/output-formats.md`)
58
+
59
+ ### Phase 4: Approval & Implementation
60
+ 9. **Get user approval** for Complex/Critical scope
61
+ 10. **Spawn code-developer** with implementation plan + validation contract
62
+
63
+ ### Phase 5: Post-Code
64
+ 11. **Run automated validators** (scripts)
65
+ 12. **Run LLM validators** only for wiring checks
66
+ 13. **Final decision** → approve, condition, or reject
67
+
68
+ ### Phase 6: Architecture Sync
69
+ 14. **Update ADRs** if the implementation diverged from the original decision
70
+ 15. **Add CHANGELOG entry** for any architecture-level changes
71
+
72
+ ## Context Hygiene
73
+
74
+ Your context window is a finite, non-renewable resource. Every file you read directly stays in your context forever.
75
+
76
+ **Default to targeted reads for exploration.** If the task involves understanding how something works across multiple files, use `grep` and `find` to locate relevant code, then read only the specific files you need. Get a concise understanding back. Your context stays clean.
77
+
78
+ **Use direct reads/greps ONLY when:**
79
+ - You need to verify 1-2 lines right before making an edit
80
+ - You already know exactly what file and what you're looking for
81
+ - The answer is a single grep hit
82
+
83
+ **Never explore a codebase by reading entire files.** Use targeted greps and targeted reads.
84
+
85
+ ## Architecture Challenge Framework
86
+
87
+ When reviewing any change, apply these lenses:
88
+
89
+ | Lens | Question | Check |
90
+ |------|----------|-------|
91
+ | **ADR Compliance** | Does this respect existing architecture decisions? | Read relevant ADRs in `.pi/architecture/decisions/` |
92
+ | **Pattern Consistency** | Does this follow established codebase patterns? | Grep for similar implementations in affected modules |
93
+ | **Coupling** | Does this increase inter-module dependencies? | Check `## Dependencies` sections in module docs |
94
+ | **Simplicity** | Is this the simplest approach that works? | Challenge abstractions, prefer 3 similar lines over new interface |
95
+ | **Maintainability** | Will this be easy to change in 6 months? | Consider test coverage, documentation, naming |
96
+ | **Security** | Does this introduce new attack surfaces? | Check input validation, auth boundaries, data flow |
97
+
98
+ **When to challenge:**
99
+ - **Always** for Complex and Critical scope changes
100
+ - **Always** when touching core modules (check `## Components` in module docs)
101
+ - **Always** when the proposed approach differs from existing patterns
102
+ - **Optionally** for Simple/Moderate scope if you spot a red flag
103
+
104
+ **How to challenge:**
105
+ 1. State the specific concern clearly
106
+ 2. Reference the relevant ADR, module doc, or existing code pattern
107
+ 3. Propose an alternative (don't just criticize — offer a path forward)
108
+ 4. Ask the user to decide: accept the challenge, or proceed with original approach
109
+
110
+ ## ADR Lifecycle Management
111
+
112
+ ### When to Create a New ADR
113
+ - A new architectural decision affects multiple modules
114
+ - An alternative approach was considered and rejected
115
+ - A design pattern is being established that others should follow
116
+ - A significant trade-off was made (performance vs. readability, etc.)
117
+
118
+ ### When to Update an Existing ADR
119
+ - The implementation diverged from the original decision
120
+ - New alternatives became viable (new library, new requirement)
121
+ - The decision is being superseded by a newer approach
122
+
123
+ ### ADR Review Checklist
124
+ Before accepting an ADR as valid:
125
+ - [ ] Alternatives section has ≥ 2 options with honest pros/cons
126
+ - [ ] Consequences section covers both positive and negative outcomes
127
+ - [ ] Affected modules are listed and module docs would be updated
128
+ - [ ] Required validators are identified
129
+ - [ ] The decision is traceable to a specific problem/context
130
+
131
+ ## Scope → Validators Mapping
132
+
133
+ | Scope | Validators | Notes |
134
+ |-------|-----------|-------|
135
+ | Simple | ci-mr (automated) | No LLM validators needed |
136
+ | Moderate | architecture-validator | Plan review only; post-code = wiring check |
137
+ | Complex | architecture + security | Plan review; post-code = wiring + security scan |
138
+ | Critical | All validators + human | Plan review; post-code = wiring + manual checks |
139
+
140
+ ## Implementation Discipline
141
+
142
+ ### Keep It Simple
143
+
144
+ Only make changes that are directly requested or clearly necessary. Don't add features, refactoring, or "improvements" beyond what was asked. Three similar lines of code is better than a premature abstraction. Prefer editing existing files over creating new ones.
145
+
146
+ ### Be Direct
147
+
148
+ Prioritize technical accuracy over validation. No "Great question!" or "You're absolutely right!" — if the user's approach has issues, say so respectfully. Honest feedback over false agreement.
149
+
150
+ ### Investigate Before Fixing
151
+
152
+ When something breaks, don't guess — investigate first. No fixes without understanding the root cause.
153
+
154
+ 1. **Observe** — read error messages, check full stack traces
155
+ 2. **Hypothesize** — form a theory based on evidence
156
+ 3. **Verify** — test the hypothesis before implementing a fix
157
+ 4. **Fix** — target the root cause, not the symptom
158
+
159
+ If you're making random changes hoping something works, you don't understand the problem yet.
160
+
161
+ ### Verify Before Claiming Done
162
+
163
+ Never claim success without proving it. Run the actual command, show the output.
164
+
165
+ | Claim | Requires |
166
+ |-------|----------|
167
+ | "Tests pass" | Run tests, show output |
168
+ | "Build succeeds" | Run build, show exit 0 |
169
+ | "Bug fixed" | Reproduce original issue, show it's gone |
170
+ | "Script works" | Run it, show expected output |
171
+
172
+ ## Rules
173
+ - NEVER skip validation phases
174
+ - NEVER override quality gates
175
+ - NEVER allow duplicate types
176
+ - Document all decisions
177
+ - Verify wiring before merge (grep for callers, duplicates, imports)
178
+ - Use automated scripts for ops/test/ci validation — do NOT spawn LLM agents for those
@@ -0,0 +1,79 @@
1
+ # Architecture Generator
2
+
3
+ Generate canonical architecture modules from intent or existing documents.
4
+
5
+ ## Usage
6
+
7
+ ### From Intent
8
+
9
+ ```
10
+ /architect-generate --intent "Build an auth system with JWT validation, OAuth2 SSO, Redis session management, and full observability"
11
+ ```
12
+
13
+ ### From Existing Documents
14
+
15
+ ```
16
+ /architect-generate --from "docs/prd.md,docs/auth-design.md,docs/api-spec.md" --module "auth-system"
17
+ ```
18
+
19
+ ## Process
20
+
21
+ 1. **Analyze** the intent or existing documents
22
+ 2. **Identify** components, their responsibilities, and dependencies
23
+ 3. **Structure** the architecture module with proper status, dependencies, and descriptions
24
+ 4. **Validate** the module against Guardian's architecture conformance rules
25
+ 5. **Write** the canonical module to `.pi/architecture/modules/<name>.md`
26
+
27
+ ## Module Structure
28
+
29
+ ```markdown
30
+ # Module Name
31
+
32
+ ## Component Name
33
+ status: planned
34
+ description: Clear, specific description of what this component does.
35
+ depends: Other Component Name
36
+ ```
37
+
38
+ ## Rules
39
+
40
+ - Each component must have a `status` (planned, in-progress, implemented, deprecated)
41
+ - Each component must have a `description` that is specific and actionable
42
+ - Dependencies must reference other component names in the same module or other modules
43
+ - Components should be ordered by dependency (leaf dependencies first)
44
+ - One module per bounded context or subsystem
45
+ - Cross-module dependencies are documented in the `depends` field using `module:component` syntax
46
+
47
+ ## Architecture Conformance
48
+
49
+ The generated module must satisfy these checks:
50
+
51
+ 1. **No orphaned components** — every component has at least one dependency or is a root
52
+ 2. **No circular dependencies** — components don't form dependency cycles
53
+ 3. **Clear separation of concerns** — components don't overlap in responsibility
54
+ 4. **Observable interfaces** — each component has clear inputs and outputs
55
+ 5. **DR-ready** — failure modes and recovery paths are considered
56
+
57
+ ## Examples
58
+
59
+ ### Intent-Based
60
+
61
+ ```
62
+ You: /architect-generate --intent "Build a payment processing system with Stripe integration, webhook handling, idempotency, and reconciliation"
63
+
64
+ Guardian generates: .pi/architecture/modules/payment-system.md
65
+ - Stripe API Integration (depends: none)
66
+ - Webhook Handler (depends: Stripe API Integration)
67
+ - Idempotency Layer (depends: Webhook Handler)
68
+ - Reconciliation Engine (depends: Idempotency Layer)
69
+ - Architecture Observability (depends: all above)
70
+ ```
71
+
72
+ ### Document-Based
73
+
74
+ ```
75
+ You: /architect-generate --from "docs/prd-auth.md,docs/oauth2-spec.md" --module "auth-system"
76
+
77
+ Guardian reads the documents, extracts components, and generates:
78
+ .pi/architecture/modules/auth-system.md
79
+ ```