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,154 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-operations.sh — Rust
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0
8
+ ERRORS=()
9
+ WARNINGS=()
10
+
11
+ RED='\033[0;31m'
12
+ GREEN='\033[0;32m'
13
+ YELLOW='\033[1;33m'
14
+ NC='\033[0m'
15
+
16
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
17
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
18
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
19
+
20
+ echo "============================================"
21
+ echo " Operations Validation (Rust)"
22
+ echo "============================================"
23
+ echo ""
24
+
25
+ if [ ! -f "Cargo.toml" ]; then
26
+ warn "No Cargo.toml found (skipping Rust operations validation)"
27
+ echo ""
28
+ echo "============================================"
29
+ echo " Summary"
30
+ echo "============================================"
31
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
32
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
33
+ echo ""
34
+ echo -e "${GREEN}No Rust project detected, nothing to validate.${NC}"
35
+ exit 0
36
+ fi
37
+
38
+ # ---------------------------------------------------------------------------
39
+ # Structured logging
40
+ # ---------------------------------------------------------------------------
41
+ echo "--- Structured Logging ---"
42
+ HAS_LOGGING=0
43
+ if grep -qE '^\s*(tracing|slog)\s*=' Cargo.toml 2>/dev/null; then
44
+ HAS_LOGGING=1
45
+ pass "Structured logging detected"
46
+ elif grep -qE '^\s*log\s*=' Cargo.toml 2>/dev/null; then
47
+ HAS_LOGGING=1
48
+ warn "Basic log crate detected (consider upgrading to tracing or slog for structured logging)"
49
+ fi
50
+ if [ "$HAS_LOGGING" -eq 0 ]; then
51
+ warn "No logging crate found in Cargo.toml (tracing, slog, or log)"
52
+ fi
53
+
54
+ # ---------------------------------------------------------------------------
55
+ # Health checks
56
+ # ---------------------------------------------------------------------------
57
+ echo ""
58
+ echo "--- Health Checks ---"
59
+ HEALTH_FOUND=0
60
+ if grep -rqE '"/health"|"/healthz"' --include="*.rs" src/ 2>/dev/null; then
61
+ HEALTH_FOUND=1
62
+ pass "Health check endpoints detected (/health or /healthz)"
63
+ fi
64
+ if [ "$HEALTH_FOUND" -eq 0 ]; then
65
+ warn "No health check endpoints found (consider adding /health or /healthz)"
66
+ fi
67
+
68
+ # ---------------------------------------------------------------------------
69
+ # Graceful shutdown
70
+ # ---------------------------------------------------------------------------
71
+ echo ""
72
+ echo "--- Graceful Shutdown ---"
73
+ SHUTDOWN_FOUND=0
74
+ if grep -rqE 'tokio::signal|ctrlc|impl\s+Drop' --include="*.rs" src/ 2>/dev/null; then
75
+ SHUTDOWN_FOUND=1
76
+ pass "Graceful shutdown mechanism detected"
77
+ fi
78
+ if [ "$SHUTDOWN_FOUND" -eq 0 ]; then
79
+ warn "No graceful shutdown mechanism found (tokio::signal, ctrlc, or Drop)"
80
+ fi
81
+
82
+ # ---------------------------------------------------------------------------
83
+ # Metrics
84
+ # ---------------------------------------------------------------------------
85
+ echo ""
86
+ echo "--- Metrics ---"
87
+ if grep -qE '^\s*(prometheus|metrics|opentelemetry)\s*=' Cargo.toml 2>/dev/null; then
88
+ pass "Metrics library detected"
89
+ else
90
+ warn "No metrics library found in Cargo.toml (prometheus, metrics, or opentelemetry)"
91
+ fi
92
+
93
+ # ---------------------------------------------------------------------------
94
+ # Error handling
95
+ # ---------------------------------------------------------------------------
96
+ echo ""
97
+ echo "--- Error Handling ---"
98
+ if grep -qE '^\s*(thiserror|anyhow|eyre)\s*=' Cargo.toml 2>/dev/null; then
99
+ pass "Error handling library detected"
100
+ else
101
+ warn "No error handling library found in Cargo.toml (thiserror, anyhow, or eyre)"
102
+ fi
103
+
104
+ # ---------------------------------------------------------------------------
105
+ # Configuration
106
+ # ---------------------------------------------------------------------------
107
+ echo ""
108
+ echo "--- Configuration ---"
109
+ CONFIG_FOUND=0
110
+ if grep -qE '^\s*(config|dotenvy)\s*=' Cargo.toml 2>/dev/null; then
111
+ CONFIG_FOUND=1
112
+ pass "Configuration library detected"
113
+ fi
114
+ if [ "$CONFIG_FOUND" -eq 0 ]; then
115
+ # Check for std::env usage with defaults
116
+ if grep -rqE 'std::env::var' --include="*.rs" src/ 2>/dev/null; then
117
+ warn "Environment variables used without config library (consider config or dotenvy)"
118
+ else
119
+ warn "No configuration management detected"
120
+ fi
121
+ fi
122
+
123
+ # ---------------------------------------------------------------------------
124
+ # Async runtime
125
+ # ---------------------------------------------------------------------------
126
+ echo ""
127
+ echo "--- Async Runtime ---"
128
+ if grep -qE '^\s*(tokio|async-std)\s*=' Cargo.toml 2>/dev/null; then
129
+ pass "Async runtime detected"
130
+ else
131
+ warn "No async runtime found in Cargo.toml (tokio or async-std)"
132
+ fi
133
+
134
+ # ---------------------------------------------------------------------------
135
+ # Summary
136
+ # ---------------------------------------------------------------------------
137
+ echo ""
138
+ echo "============================================"
139
+ echo " Summary"
140
+ echo "============================================"
141
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
142
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
143
+ echo ""
144
+
145
+ if [ ${#ERRORS[@]} -gt 0 ]; then
146
+ echo "FAILURES:"
147
+ for err in "${ERRORS[@]}"; do
148
+ echo " - $err"
149
+ done
150
+ exit 1
151
+ fi
152
+
153
+ echo -e "${GREEN}Operations validation completed.${NC}"
154
+ exit 0
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-security.sh — Rust
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0
8
+ ERRORS=()
9
+ WARNINGS=()
10
+
11
+ RED='\033[0;31m'
12
+ GREEN='\033[0;32m'
13
+ YELLOW='\033[1;33m'
14
+ NC='\033[0m'
15
+
16
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
17
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
18
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
19
+
20
+ echo "============================================"
21
+ echo " Security Validation (Rust)"
22
+ echo "============================================"
23
+ echo ""
24
+
25
+ if [ ! -f "Cargo.toml" ]; then
26
+ warn "No Cargo.toml found (skipping Rust security validation)"
27
+ echo ""
28
+ echo "============================================"
29
+ echo " Summary"
30
+ echo "============================================"
31
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
32
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
33
+ echo ""
34
+ echo -e "${GREEN}No Rust project detected, nothing to validate.${NC}"
35
+ exit 0
36
+ fi
37
+
38
+ # ---------------------------------------------------------------------------
39
+ # Hardcoded secrets
40
+ # ---------------------------------------------------------------------------
41
+ echo "--- Hardcoded Secrets ---"
42
+ # Search for long literal strings assigned to variables in non-test files
43
+ SECRETS_FOUND=$(grep -rnE '=\s*"[A-Za-z0-9+/=_\-]{20,}"' --include="*.rs" src/ 2>/dev/null \
44
+ | grep -v '_test\.rs' \
45
+ | grep -v '#\[cfg(test)\]' \
46
+ | grep -v 'mod tests' \
47
+ | wc -l | tr -d ' ')
48
+ if [ "$SECRETS_FOUND" -gt 0 ]; then
49
+ fail "Possible hardcoded secrets found ($SECRETS_FOUND occurrences)"
50
+ else
51
+ pass "No hardcoded secrets detected"
52
+ fi
53
+
54
+ # ---------------------------------------------------------------------------
55
+ # SQL injection
56
+ # ---------------------------------------------------------------------------
57
+ echo ""
58
+ echo "--- SQL Injection ---"
59
+ SQL_INJECT=0
60
+ if grep -qE 'sqlx' Cargo.toml 2>/dev/null; then
61
+ # Check for unsafe query patterns: format! inside query! or query()
62
+ SQL_INJECT=$(grep -rE 'query\s*\(\s*(format!|format_args!)' src/ --include="*.rs" 2>/dev/null | wc -l | tr -d ' ')
63
+ fi
64
+ if [ "$SQL_INJECT" -gt 0 ]; then
65
+ fail "Potential SQL injection patterns found ($SQL_INJECT occurrences — avoid format! inside query)"
66
+ else
67
+ pass "No SQL injection patterns detected"
68
+ fi
69
+
70
+ # ---------------------------------------------------------------------------
71
+ # Dependency audit
72
+ # ---------------------------------------------------------------------------
73
+ echo ""
74
+ echo "--- Dependency Audit ---"
75
+ if command -v cargo &>/dev/null && cargo audit --version &>/dev/null; then
76
+ AUDIT_OUT=$(cargo audit 2>&1 || true)
77
+ if echo "$AUDIT_OUT" | grep -qE "No advisabilities found|No known vulnerabilities"; then
78
+ pass "No known vulnerabilities (cargo audit)"
79
+ else
80
+ warn "cargo audit reported findings (review manually)"
81
+ fi
82
+ elif command -v cargo &>/dev/null && cargo deny --version &>/dev/null; then
83
+ if cargo deny check 2>/dev/null; then
84
+ pass "No known vulnerabilities (cargo deny)"
85
+ else
86
+ warn "cargo deny reported issues (review manually)"
87
+ fi
88
+ else
89
+ warn "No Rust audit tools available (cargo audit / cargo deny)"
90
+ fi
91
+
92
+ # ---------------------------------------------------------------------------
93
+ # Unsafe code
94
+ # ---------------------------------------------------------------------------
95
+ echo ""
96
+ echo "--- Unsafe Code ---"
97
+ UNSAFE_BLOCKS=$(grep -rE 'unsafe\s*\{' --include="*.rs" src/ 2>/dev/null | wc -l | tr -d ' ')
98
+ if [ "$UNSAFE_BLOCKS" -gt 0 ]; then
99
+ warn "Unsafe code blocks found ($UNSAFE_BLOCKS occurrences — recommend manual audit)"
100
+ else
101
+ pass "No unsafe code blocks detected"
102
+ fi
103
+
104
+ # ---------------------------------------------------------------------------
105
+ # Panic-prone patterns
106
+ # ---------------------------------------------------------------------------
107
+ echo ""
108
+ echo "--- Panic-Prone Patterns ---"
109
+ PANIC_CALLS=$(grep -rE '\.unwrap\(\)|\.expect\(' --include="*.rs" src/ 2>/dev/null \
110
+ | grep -v '#\[cfg(test)\]' \
111
+ | grep -v 'mod tests' \
112
+ | grep -v '_test\.rs' \
113
+ | wc -l | tr -d ' ')
114
+ if [ "$PANIC_CALLS" -gt 0 ]; then
115
+ warn "Panic-prone patterns found ($PANIC_CALLS .unwrap()/.expect() calls in non-test code)"
116
+ else
117
+ pass "No panic-prone patterns in production code"
118
+ fi
119
+
120
+ # ---------------------------------------------------------------------------
121
+ # Cryptographic practices
122
+ # ---------------------------------------------------------------------------
123
+ echo ""
124
+ echo "--- Cryptographic Practices ---"
125
+ if grep -qE '^(ring|rustls)\s*=' Cargo.toml 2>/dev/null; then
126
+ pass "Modern crypto libraries detected (ring/rustls)"
127
+ elif grep -qE '^openssl\s*=' Cargo.toml 2>/dev/null; then
128
+ warn "OpenSSL detected (prefer ring or rustls for new projects)"
129
+ else
130
+ pass "No cryptographic library dependencies found"
131
+ fi
132
+
133
+ # ---------------------------------------------------------------------------
134
+ # Summary
135
+ # ---------------------------------------------------------------------------
136
+ echo ""
137
+ echo "============================================"
138
+ echo " Summary"
139
+ echo "============================================"
140
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
141
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
142
+ echo ""
143
+
144
+ if [ ${#ERRORS[@]} -gt 0 ]; then
145
+ echo "FAILURES:"
146
+ for err in "${ERRORS[@]}"; do
147
+ echo " - $err"
148
+ done
149
+ exit 1
150
+ fi
151
+
152
+ echo -e "${GREEN}Security validation completed.${NC}"
153
+ exit 0
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-tests.sh — Rust
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0
8
+ ERRORS=()
9
+ WARNINGS=()
10
+
11
+ RED='\033[0;31m'
12
+ GREEN='\033[0;32m'
13
+ YELLOW='\033[1;33m'
14
+ NC='\033[0m'
15
+
16
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
17
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
18
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
19
+
20
+ echo "============================================"
21
+ echo " Test Validation (Rust)"
22
+ echo "============================================"
23
+ echo ""
24
+
25
+ if [ ! -f "Cargo.toml" ]; then
26
+ warn "No Cargo.toml found (skipping Rust test validation)"
27
+ echo ""
28
+ echo "============================================"
29
+ echo " Summary"
30
+ echo "============================================"
31
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
32
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
33
+ echo ""
34
+ echo -e "${GREEN}No Rust project detected, nothing to validate.${NC}"
35
+ exit 0
36
+ fi
37
+
38
+ # ---------------------------------------------------------------------------
39
+ # Unit tests
40
+ # ---------------------------------------------------------------------------
41
+ echo "--- Unit Tests ---"
42
+ if cargo test --lib --quiet 2>/dev/null; then
43
+ pass "Library unit tests passed"
44
+ else
45
+ LIB_SOURCES=$(find src -name "*.rs" 2>/dev/null | wc -l | tr -d ' ')
46
+ if [ "$LIB_SOURCES" -eq 0 ]; then
47
+ pass "No library source files (skipped)"
48
+ else
49
+ fail "Library unit tests failed"
50
+ fi
51
+ fi
52
+
53
+ # ---------------------------------------------------------------------------
54
+ # Integration tests
55
+ # ---------------------------------------------------------------------------
56
+ echo ""
57
+ echo "--- Integration Tests ---"
58
+ if [ -d "tests" ]; then
59
+ # Try named integration test first, then all tests in tests/
60
+ if [ -f "tests/integration.rs" ] || ls tests/*integration* 1>/dev/null 2>&1; then
61
+ if cargo test --test integration --quiet 2>/dev/null; then
62
+ pass "Integration tests passed"
63
+ else
64
+ fail "Integration tests failed"
65
+ fi
66
+ else
67
+ # Run all integration test files
68
+ TEST_COUNT=$(find tests -name "*.rs" 2>/dev/null | wc -l | tr -d ' ')
69
+ if [ "$TEST_COUNT" -gt 0 ]; then
70
+ if cargo test --test '*' --quiet 2>/dev/null; then
71
+ pass "Integration tests passed"
72
+ else
73
+ fail "Integration tests failed"
74
+ fi
75
+ else
76
+ pass "Integration test files found but empty or skipped"
77
+ fi
78
+ fi
79
+ else
80
+ pass "No tests/ directory (no integration tests to run)"
81
+ fi
82
+
83
+ # ---------------------------------------------------------------------------
84
+ # Doctests
85
+ # ---------------------------------------------------------------------------
86
+ echo ""
87
+ echo "--- Doctests ---"
88
+ if cargo test --doc --quiet 2>/dev/null; then
89
+ pass "Doctests passed"
90
+ else
91
+ DOCS=$(grep -rl '//!\|///' src/ 2>/dev/null | wc -l | tr -d ' ')
92
+ if [ "$DOCS" -eq 0 ]; then
93
+ pass "No doc comments found (no doctests to run)"
94
+ else
95
+ warn "Doctests failed (may have compile errors in doc examples)"
96
+ fi
97
+ fi
98
+
99
+ # ---------------------------------------------------------------------------
100
+ # Coverage
101
+ # ---------------------------------------------------------------------------
102
+ echo ""
103
+ echo "--- Coverage ---"
104
+ if command -v cargo &>/dev/null && cargo tarpaulin --version &>/dev/null; then
105
+ TARP_OUT=$(cargo tarpaulin --out Html 2>&1 || true)
106
+ COVERAGE_PCT=$(echo "$TARP_OUT" | grep -oE '[0-9]+(\.[0-9]+)?%' | head -1 | tr -d '%' || echo "")
107
+ if [ -n "$COVERAGE_PCT" ]; then
108
+ # Compare coverage against 80% threshold using awk
109
+ MEETS_THRESHOLD=$(echo "$COVERAGE_PCT" | awk '{print ($1 >= 80) ? "yes" : "no"}')
110
+ if [ "$MEETS_THRESHOLD" = "yes" ]; then
111
+ pass "Code coverage: ${COVERAGE_PCT}% (≥ 80%)"
112
+ else
113
+ fail "Code coverage: ${COVERAGE_PCT}% (< 80%)"
114
+ fi
115
+ else
116
+ warn "Could not extract coverage percentage from tarpaulin output"
117
+ fi
118
+ elif command -v grcov &>/dev/null; then
119
+ # Use grcov as fallback
120
+ GRCOV_OUT=$(grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing 2>&1 || true)
121
+ if echo "$GRCOV_OUT" | grep -q "error\|Error"; then
122
+ warn "grcov encountered errors during coverage analysis"
123
+ else
124
+ pass "grcov coverage report generated"
125
+ fi
126
+ else
127
+ warn "No coverage tools available (cargo-tarpaulin / grcov), skipping coverage check"
128
+ fi
129
+
130
+ # ---------------------------------------------------------------------------
131
+ # Summary
132
+ # ---------------------------------------------------------------------------
133
+ echo ""
134
+ echo "============================================"
135
+ echo " Summary"
136
+ echo "============================================"
137
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
138
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
139
+ echo ""
140
+
141
+ if [ ${#ERRORS[@]} -gt 0 ]; then
142
+ echo "FAILURES:"
143
+ for err in "${ERRORS[@]}"; do
144
+ echo " - $err"
145
+ done
146
+ exit 1
147
+ fi
148
+
149
+ echo -e "${GREEN}All test validations passed.${NC}"
150
+ exit 0
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-architecture.sh — TypeScript
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0; ERRORS=(); WARNINGS=()
8
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
9
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
10
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
11
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
12
+
13
+ echo "============================================"
14
+ echo " Architecture Validation (TypeScript)"
15
+ echo "============================================"
16
+ echo ""
17
+
18
+ SRC_DIR="${1:-src}"
19
+
20
+ # ---------------------------------------------------------------------------
21
+ # Layer Structure
22
+ # ---------------------------------------------------------------------------
23
+ echo "--- Layer Structure ---"
24
+ if [ -d "$SRC_DIR" ]; then
25
+ HAS_DOMAIN=$(find "$SRC_DIR" -type d -name "domain" 2>/dev/null | head -1)
26
+ HAS_APPLICATION=$(find "$SRC_DIR" -type d -name "application" 2>/dev/null | head -1)
27
+ HAS_INFRASTRUCTURE=$(find "$SRC_DIR" -type d -name "infrastructure" 2>/dev/null | head -1)
28
+ if [ -n "$HAS_DOMAIN" ] && [ -n "$HAS_APPLICATION" ] && [ -n "$HAS_INFRASTRUCTURE" ]; then
29
+ pass "All three layers present (domain, application, infrastructure)"
30
+ elif [ -n "$HAS_DOMAIN" ] && [ -n "$HAS_INFRASTRUCTURE" ]; then
31
+ pass "Domain and infrastructure layers present"
32
+ elif [ -n "$HAS_DOMAIN" ]; then
33
+ pass "Domain layer present (architecture incremental)"
34
+ else
35
+ pass "Source tree initialized (clean architecture not yet layered)"
36
+ fi
37
+ else
38
+ warn "No src directory found, skipping layer checks"
39
+ fi
40
+
41
+ # ---------------------------------------------------------------------------
42
+ # Canonical References
43
+ # ---------------------------------------------------------------------------
44
+ echo ""
45
+ echo "--- Canonical References ---"
46
+ if [ -d ".pi/architecture/modules" ]; then
47
+ MODULE_COUNT=$(find .pi/architecture/modules -name "*.md" 2>/dev/null | wc -l | tr -d ' ')
48
+ pass "Canonical architecture documents found ($MODULE_COUNT modules)"
49
+ else
50
+ warn "No .pi/architecture/modules directory found"
51
+ fi
52
+
53
+ # ---------------------------------------------------------------------------
54
+ # Domain Models
55
+ # ---------------------------------------------------------------------------
56
+ echo ""
57
+ echo "--- Domain Models ---"
58
+ if [ -d "$SRC_DIR/domain" ]; then
59
+ DOMAIN_MODELS=$(find "$SRC_DIR/domain" -name "*.ts" -o -name "*.tsx" 2>/dev/null | xargs grep -lE '\b(interface|type|class)\b' 2>/dev/null | wc -l | tr -d ' ')
60
+ if [ "$DOMAIN_MODELS" -gt 0 ]; then
61
+ pass "Domain model definitions found ($DOMAIN_MODELS files with interface/type/class)"
62
+ else
63
+ warn "No interface/type/class definitions in domain layer"
64
+ fi
65
+ else
66
+ warn "No domain directory found, skipping domain model check"
67
+ fi
68
+
69
+ # ---------------------------------------------------------------------------
70
+ # Dependency Direction
71
+ # ---------------------------------------------------------------------------
72
+ echo ""
73
+ echo "--- Dependency Direction ---"
74
+ if [ -d "$SRC_DIR/domain" ]; then
75
+ DOMAIN_BAD_IMPORTS=0
76
+ for f in $(find "$SRC_DIR/domain" -name "*.ts" -o -name "*.tsx" 2>/dev/null); do
77
+ if grep -qE "from\s+['\"].*\/(infrastructure|api)\b" "$f" 2>/dev/null; then
78
+ DOMAIN_BAD_IMPORTS=$((DOMAIN_BAD_IMPORTS + 1))
79
+ fi
80
+ done
81
+ if [ "$DOMAIN_BAD_IMPORTS" -eq 0 ]; then
82
+ pass "Domain layer has no infrastructure or API imports (clean dependency direction)"
83
+ else
84
+ fail "Domain layer imports from infrastructure/API ($DOMAIN_BAD_IMPORTS files)"
85
+ fi
86
+ else
87
+ pass "No domain directory, skipping dependency direction check"
88
+ fi
89
+
90
+ # ---------------------------------------------------------------------------
91
+ # Error Handling
92
+ # ---------------------------------------------------------------------------
93
+ echo ""
94
+ echo "--- Error Handling ---"
95
+ if [ -d "$SRC_DIR" ]; then
96
+ ERROR_CLASSES=$(grep -rE "class\s+\w+Error.*extends\s+(Error|AppError)" "$SRC_DIR" 2>/dev/null | wc -l | tr -d ' ')
97
+ if [ "$ERROR_CLASSES" -gt 0 ]; then
98
+ pass "Custom error classes defined ($ERROR_CLASSES found)"
99
+ else
100
+ warn "No custom error classes (extends Error) found"
101
+ fi
102
+ else
103
+ warn "No source directory found, skipping error handling check"
104
+ fi
105
+
106
+ # ---------------------------------------------------------------------------
107
+ # Interfaces / Contracts
108
+ # ---------------------------------------------------------------------------
109
+ echo ""
110
+ echo "--- Interfaces / Contracts ---"
111
+ if [ -d "$SRC_DIR" ]; then
112
+ INTERFACE_COUNT=$(grep -rE "^\s*(export\s+)?interface\s+" "$SRC_DIR" --include="*.ts" --include="*.tsx" 2>/dev/null | wc -l | tr -d ' ')
113
+ if [ "$INTERFACE_COUNT" -gt 0 ]; then
114
+ pass "Interface contracts defined ($INTERFACE_COUNT found)"
115
+ else
116
+ warn "No interface definitions found in source"
117
+ fi
118
+ else
119
+ warn "No source directory found, skipping interface check"
120
+ fi
121
+
122
+ # ---------------------------------------------------------------------------
123
+ # TypeScript Strict Mode
124
+ # ---------------------------------------------------------------------------
125
+ echo ""
126
+ echo "--- TypeScript Strict Mode ---"
127
+ if [ -f "tsconfig.json" ]; then
128
+ if grep -q '"strict"\s*:\s*true' tsconfig.json 2>/dev/null; then
129
+ pass "TypeScript strict mode enabled"
130
+ else
131
+ warn "TypeScript strict mode not enabled in tsconfig.json"
132
+ fi
133
+ else
134
+ warn "No tsconfig.json found"
135
+ fi
136
+
137
+ # ---------------------------------------------------------------------------
138
+ # Summary
139
+ # ---------------------------------------------------------------------------
140
+ echo ""
141
+ echo "============================================"
142
+ echo " Summary"
143
+ echo "============================================"
144
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
145
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
146
+ echo ""
147
+
148
+ if [ ${#ERRORS[@]} -gt 0 ]; then
149
+ echo "FAILURES:"
150
+ for err in "${ERRORS[@]}"; do
151
+ echo " - $err"
152
+ done
153
+ exit 1
154
+ fi
155
+
156
+ echo -e "${GREEN}Architecture validation passed.${NC}"
157
+ exit 0