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,193 @@
1
+ #!/usr/bin/env bash
2
+ # Guardian Local Developer Workflow — Stage Runner
3
+ #
4
+ # Runs a specific CI stage locally.
5
+ #
6
+ # Usage:
7
+ # ./run_stage.sh docs_policy
8
+ # ./run_stage.sh architecture_conformance
9
+ # ./run_stage.sh lint
10
+ # ./run_stage.sh static_analysis
11
+ # ./run_stage.sh unit
12
+ # ./run_stage.sh integration
13
+ # ./run_stage.sh security
14
+ # ./run_stage.sh migration_verify
15
+ # ./run_stage.sh package_build
16
+ # ./run_stage.sh release_readiness
17
+
18
+ set -euo pipefail
19
+
20
+ PI_DIR=".pi"
21
+ CI_DIR="${PI_DIR}/scripts/ci"
22
+
23
+ # Colors
24
+ RED='\033[0;31m'
25
+ GREEN='\033[0;32m'
26
+ YELLOW='\033[1;33m'
27
+ NC='\033[0m'
28
+
29
+ STAGE="${1:-}"
30
+
31
+ if [[ -z "$STAGE" ]]; then
32
+ echo "Usage: $0 <stage_name>"
33
+ echo ""
34
+ echo "Available stages:"
35
+ echo " docs_policy MR traceability, docs sync"
36
+ echo " architecture_conformance 11+ architectural contract checks"
37
+ echo " lint Language-specific linting"
38
+ echo " static_analysis Type checking, import boundaries"
39
+ echo " unit Unit tests"
40
+ echo " integration Integration tests (requires PostgreSQL, Redis)"
41
+ echo " security Secret scan, dependency audit"
42
+ echo " migration_verify Migration apply + verification"
43
+ echo " package_build Docker build"
44
+ echo " release_readiness Runbook, observability, release policy"
45
+ exit 1
46
+ fi
47
+
48
+ echo -e "${YELLOW}Running stage: ${STAGE}${NC}"
49
+ echo ""
50
+
51
+ case "$STAGE" in
52
+ docs_policy)
53
+ if [[ -f "${CI_DIR}/run_stage_docs_policy.sh" ]]; then
54
+ bash "${CI_DIR}/run_stage_docs_policy.sh"
55
+ elif [[ -f "${CI_DIR}/stage_docs_policy.sh" ]]; then
56
+ bash "${CI_DIR}/stage_docs_policy.sh"
57
+ else
58
+ echo -e "${RED}✗ Script not found${NC}"
59
+ exit 1
60
+ fi
61
+ ;;
62
+
63
+ architecture_conformance)
64
+ if [[ -f "${CI_DIR}/check_architecture_conformance.sh" ]]; then
65
+ bash "${CI_DIR}/check_architecture_conformance.sh"
66
+ else
67
+ echo -e "${RED}✗ Script not found${NC}"
68
+ exit 1
69
+ fi
70
+ ;;
71
+
72
+ lint)
73
+ # Auto-detect and run language-specific lint
74
+ if [[ -f "pyproject.toml" ]]; then
75
+ echo "Python project detected"
76
+ ruff check . && ruff format --check .
77
+ elif [[ -f "package.json" ]]; then
78
+ echo "TypeScript project detected"
79
+ biome check . && biome format --check .
80
+ elif [[ -f "Cargo.toml" ]]; then
81
+ echo "Rust project detected"
82
+ cargo clippy -- -D warnings && cargo fmt --check
83
+ elif [[ -f "go.mod" ]]; then
84
+ echo "Go project detected"
85
+ golangci-lint run && gofmt -d .
86
+ else
87
+ echo -e "${YELLOW}⊘ No project configuration found${NC}"
88
+ fi
89
+ ;;
90
+
91
+ static_analysis)
92
+ if [[ -f "pyproject.toml" ]]; then
93
+ mypy . --ignore-missing-imports || true
94
+ elif [[ -f "tsconfig.json" ]]; then
95
+ tsc --noEmit || true
96
+ elif [[ -f "Cargo.toml" ]]; then
97
+ cargo check || true
98
+ fi
99
+ if [[ -f "${CI_DIR}/check_arch_sanity.sh" ]]; then
100
+ bash "${CI_DIR}/check_arch_sanity.sh"
101
+ fi
102
+ if [[ -f "${CI_DIR}/check_import_boundaries.sh" ]]; then
103
+ bash "${CI_DIR}/check_import_boundaries.sh"
104
+ fi
105
+ ;;
106
+
107
+ unit)
108
+ if command -v pytest &>/dev/null; then
109
+ pytest tests/unit -v
110
+ elif command -v bun &>/dev/null; then
111
+ bun test
112
+ elif command -v cargo &>/dev/null; then
113
+ cargo test
114
+ elif command -v go &>/dev/null; then
115
+ go test ./...
116
+ else
117
+ echo -e "${YELLOW}⊘ No test runner found${NC}"
118
+ fi
119
+ ;;
120
+
121
+ integration)
122
+ # Check services
123
+ if ! command -v psql &>/dev/null || ! psql -h localhost -U postgres -c "SELECT 1" &>/dev/null 2>&1; then
124
+ echo -e "${YELLOW}⊘ PostgreSQL not available${NC}"
125
+ echo " docker run -d --name postgres -e POSTGRES_PASSWORD=test -p 5432:5432 postgres:16"
126
+ exit 0
127
+ fi
128
+ if ! command -v redis-cli &>/dev/null || ! redis-cli ping 2>/dev/null | grep -q "PONG"; then
129
+ echo -e "${YELLOW}⊘ Redis not available${NC}"
130
+ echo " docker run -d --name redis -p 6379:6379 redis:7"
131
+ exit 0
132
+ fi
133
+
134
+ if command -v pytest &>/dev/null; then
135
+ pytest tests/integration -v
136
+ else
137
+ echo -e "${YELLOW}⊘ No integration test runner found${NC}"
138
+ fi
139
+ ;;
140
+
141
+ security)
142
+ if [[ -f "${CI_DIR}/stage_security.sh" ]]; then
143
+ bash "${CI_DIR}/stage_security.sh"
144
+ else
145
+ # Fallback: secret scan
146
+ echo "Running secret scan..."
147
+ if grep -rE "(sk-[A-Za-z0-9]{32,}|ghp_[A-Za-z0-9]{36}|AKIA[0-9A-Z]{16})" . --include="*.py" --include="*.ts" --include="*.env" 2>/dev/null | grep -v ".git" | grep -v "node_modules" | grep -q .; then
148
+ echo -e "${RED}✗ Potential secrets found${NC}"
149
+ exit 1
150
+ fi
151
+ echo -e "${GREEN}✓ No secrets detected${NC}"
152
+ fi
153
+ ;;
154
+
155
+ migration_verify)
156
+ if ! command -v psql &>/dev/null || ! psql -h localhost -U postgres -c "SELECT 1" &>/dev/null 2>&1; then
157
+ echo -e "${YELLOW}⊘ PostgreSQL not available${NC}"
158
+ exit 0
159
+ fi
160
+ if command -v alembic &>/dev/null; then
161
+ alembic upgrade head
162
+ else
163
+ echo -e "${YELLOW}⊘ alembic not installed${NC}"
164
+ fi
165
+ ;;
166
+
167
+ package_build)
168
+ if ! command -v docker &>/dev/null; then
169
+ echo -e "${YELLOW}⊘ Docker not available${NC}"
170
+ exit 0
171
+ fi
172
+ if [[ ! -f "Dockerfile" ]]; then
173
+ echo -e "${YELLOW}⊘ No Dockerfile found${NC}"
174
+ exit 0
175
+ fi
176
+ docker build -t guardian:local .
177
+ ;;
178
+
179
+ release_readiness)
180
+ if [[ -f "${PI_DIR}/scripts/validate-architecture-readiness.sh" ]]; then
181
+ bash "${PI_DIR}/scripts/validate-architecture-readiness.sh"
182
+ else
183
+ echo -e "${YELLOW}⊘ validate-architecture-readiness.sh not found${NC}"
184
+ fi
185
+ ;;
186
+
187
+ *)
188
+ echo -e "${RED}✗ Unknown stage: ${STAGE}${NC}"
189
+ echo ""
190
+ echo "Available stages: docs_policy, architecture_conformance, lint, static_analysis, unit, integration, security, migration_verify, package_build, release_readiness"
191
+ exit 1
192
+ ;;
193
+ esac
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env bash
2
+ # Stage 1: Docs Policy
3
+ #
4
+ # Verifies:
5
+ # - MR traceability: Every changed file has a canonical reference to architecture
6
+ # - Docs sync guard: Architecture docs are updated when implementation changes
7
+
8
+ set -euo pipefail
9
+
10
+ PI_DIR=".pi"
11
+ ARCH_DIR="${PI_DIR}/architecture"
12
+
13
+ PASS=0
14
+ FAIL=0
15
+
16
+ log_pass() { echo " ✓ PASS: $1"; ((PASS++)); }
17
+ log_fail() { echo " ✗ FAIL: $1 — $2"; ((FAIL++)); }
18
+
19
+ echo " Checking MR traceability..."
20
+
21
+ # Check 1: MR Traceability
22
+ # Every changed implementation file should have a canonical reference
23
+ if command -v git &>/dev/null; then
24
+ changed_files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -E '\.(py|ts|rs|go)$' || true)
25
+ if [[ -n "$changed_files" ]]; then
26
+ files_without_ref=0
27
+ while IFS= read -r file; do
28
+ if ! grep -q "Canonical Reference\|canonical.*reference" "$file" 2>/dev/null; then
29
+ ((files_without_ref++))
30
+ log_fail "MR traceability" "${file} missing canonical reference to architecture"
31
+ fi
32
+ done <<< "$changed_files"
33
+ if [[ $files_without_ref -eq 0 ]]; then
34
+ log_pass "MR traceability (all changed files have canonical references)"
35
+ fi
36
+ else
37
+ log_pass "MR traceability (no implementation files changed)"
38
+ fi
39
+ else
40
+ log_fail "MR traceability" "git not available"
41
+ fi
42
+
43
+ echo " Checking docs sync guard..."
44
+
45
+ # Check 2: Docs Sync Guard
46
+ # If implementation files changed in a module, the module doc should have been updated
47
+ if command -v git &>/dev/null; then
48
+ module_dirs=$(ls -d "${ARCH_DIR}"/modules/ 2>/dev/null || true)
49
+ if [[ -n "$module_dirs" ]]; then
50
+ docs_updated=true
51
+ for module_file in "${ARCH_DIR}"/modules/*.md; do
52
+ [[ -f "$module_file" ]] || continue
53
+ module_name=$(basename "$module_file" .md)
54
+ # Check if files related to this module changed
55
+ if git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -qi "${module_name}" 2>/dev/null; then
56
+ # Module files changed — check if the module doc was also touched
57
+ if ! git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -q "$(basename "$module_file")" 2>/dev/null; then
58
+ # Check if the module doc has a recent "Last Updated" that matches
59
+ if grep -q "Last Updated.*$(date +%Y-%m-%d)" "$module_file" 2>/dev/null; then
60
+ docs_updated=true
61
+ else
62
+ docs_updated=false
63
+ log_fail "Docs sync guard" "Files in ${module_name} changed but module doc not updated"
64
+ fi
65
+ fi
66
+ fi
67
+ done
68
+ if [[ "$docs_updated" == "true" ]]; then
69
+ log_pass "Docs sync guard (architecture docs in sync with implementation)"
70
+ fi
71
+ else
72
+ log_pass "Docs sync guard (no architecture modules found)"
73
+ fi
74
+ fi
75
+
76
+ if [[ $FAIL -gt 0 ]]; then
77
+ echo " Docs policy FAILED (${FAIL} failure(s))"
78
+ exit 1
79
+ fi
80
+
81
+ echo " Docs policy passed (${PASS} check(s))"
82
+ exit 0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Stage: integration
3
+ exec bash "$(dirname "$0")/stage_remaining.sh" "integration"
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env bash
2
+ # Stage 3: Lint
3
+ #
4
+ # Verifies:
5
+ # - Language-specific linting (ruff/biome/clippy/golangci-lint)
6
+ # - Format check
7
+ # - Coverage report generation
8
+
9
+ set -euo pipefail
10
+
11
+ FAIL=0
12
+ PASS=0
13
+
14
+ log_pass() { echo " ✓ PASS: $1"; ((PASS++)); }
15
+ log_fail() { echo " ✗ FAIL: $1 — $2"; ((FAIL++)); }
16
+
17
+ echo " Running lint checks..."
18
+
19
+ # Determine language
20
+ if [[ -f "pyproject.toml" || -f "requirements.txt" || -f "Pipfile" ]]; then
21
+ LANG="python"
22
+ elif [[ -f "package.json" ]]; then
23
+ LANG="typescript"
24
+ elif [[ -f "Cargo.toml" ]]; then
25
+ LANG="rust"
26
+ elif [[ -f "go.mod" ]]; then
27
+ LANG="go"
28
+ else
29
+ echo " No project configuration found, skipping lint."
30
+ exit 0
31
+ fi
32
+
33
+ case "$LANG" in
34
+ python)
35
+ echo " Linting: Python"
36
+ if command -v ruff &>/dev/null; then
37
+ if ruff check . 2>/dev/null; then
38
+ log_pass "ruff lint"
39
+ else
40
+ log_fail "ruff lint" "Lint errors found"
41
+ fi
42
+ if ruff format --check . 2>/dev/null; then
43
+ log_pass "ruff format check"
44
+ else
45
+ log_fail "ruff format check" "Format errors found"
46
+ fi
47
+ elif command -v flake8 &>/dev/null; then
48
+ if flake8 . 2>/dev/null; then
49
+ log_pass "flake8 lint"
50
+ else
51
+ log_fail "flake8 lint" "Lint errors found"
52
+ fi
53
+ else
54
+ log_fail "ruff lint" "ruff not installed"
55
+ fi
56
+
57
+ # Coverage report
58
+ if command -v pytest &>/dev/null; then
59
+ if pytest --cov=app --cov-report=xml --cov-report=term 2>/dev/null; then
60
+ log_pass "coverage report"
61
+ else
62
+ log_fail "coverage report" "Tests or coverage failed"
63
+ fi
64
+ fi
65
+ ;;
66
+
67
+ typescript)
68
+ echo " Linting: TypeScript"
69
+ if command -v biome &>/dev/null; then
70
+ if biome check . 2>/dev/null; then
71
+ log_pass "biome lint"
72
+ else
73
+ log_fail "biome lint" "Lint errors found"
74
+ fi
75
+ if biome format . --check 2>/dev/null; then
76
+ log_pass "biome format check"
77
+ else
78
+ log_fail "biome format check" "Format errors found"
79
+ fi
80
+ elif command -v eslint &>/dev/null; then
81
+ if eslint . 2>/dev/null; then
82
+ log_pass "eslint lint"
83
+ else
84
+ log_fail "eslint lint" "Lint errors found"
85
+ fi
86
+ fi
87
+ ;;
88
+
89
+ rust)
90
+ echo " Linting: Rust"
91
+ if command -v cargo &>/dev/null; then
92
+ if cargo clippy --all-targets -- -D warnings 2>/dev/null; then
93
+ log_pass "cargo clippy"
94
+ else
95
+ log_fail "cargo clippy" "Clippy warnings found"
96
+ fi
97
+ if cargo fmt --check 2>/dev/null; then
98
+ log_pass "cargo fmt check"
99
+ else
100
+ log_fail "cargo fmt check" "Format errors found"
101
+ fi
102
+ fi
103
+ ;;
104
+
105
+ go)
106
+ echo " Linting: Go"
107
+ if command -v golangci-lint &>/dev/null; then
108
+ if golangci-lint run 2>/dev/null; then
109
+ log_pass "golangci-lint"
110
+ else
111
+ log_fail "golangci-lint" "Lint errors found"
112
+ fi
113
+ fi
114
+ if command -v gofmt &>/dev/null; then
115
+ if gofmt -d . 2>/dev/null | grep -q .; then
116
+ log_fail "gofmt check" "Format errors found"
117
+ else
118
+ log_pass "gofmt check"
119
+ fi
120
+ fi
121
+ ;;
122
+ esac
123
+
124
+ if [[ $FAIL -gt 0 ]]; then
125
+ echo " Lint stage FAILED (${FAIL} failure(s))"
126
+ exit 1
127
+ fi
128
+
129
+ echo " Lint stage passed (${PASS} check(s))"
130
+ exit 0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Stage: migration_verify
3
+ exec bash "$(dirname "$0")/stage_remaining.sh" "migration_verify"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Stage: package_build
3
+ exec bash "$(dirname "$0")/stage_remaining.sh" "package_build"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Stage: release_readiness
3
+ exec bash "$(dirname "$0")/stage_remaining.sh" "release_readiness"
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env bash
2
+ # Stage 6: Integration Tests
3
+ # Stage 7: Security
4
+ # Stage 8: Migration Verify
5
+ # Stage 9: Package Build
6
+ # Stage 10: Release Readiness
7
+ #
8
+ # Combined stage runner for all remaining stages.
9
+
10
+ set -euo pipefail
11
+
12
+ PI_DIR=".pi"
13
+ FAIL=0
14
+ PASS=0
15
+
16
+ log_pass() { echo " ✓ PASS: $1"; ((PASS++)); }
17
+ log_fail() { echo " ✗ FAIL: $1 — $2"; ((FAIL++)); }
18
+
19
+ STAGE="${1:-all}"
20
+
21
+ run_stage_6_integration() {
22
+ echo " Running integration tests..."
23
+ if command -v pytest &>/dev/null && [[ -d "tests/integration" ]]; then
24
+ if pytest tests/integration -v 2>/dev/null; then
25
+ log_pass "integration tests"
26
+ else
27
+ log_fail "integration tests" "Integration test failures"
28
+ fi
29
+ elif command -v bun &>/dev/null && [[ -d "tests/integration" ]]; then
30
+ if bun test tests/integration 2>/dev/null; then
31
+ log_pass "integration tests (bun)"
32
+ else
33
+ log_fail "integration tests (bun)" "Integration test failures"
34
+ fi
35
+ elif command -v cargo &>/dev/null; then
36
+ if cargo test --test integration 2>/dev/null; then
37
+ log_pass "integration tests (cargo)"
38
+ else
39
+ log_pass "integration tests (cargo) (no integration tests found)"
40
+ fi
41
+ else
42
+ log_pass "integration tests (no integration test directory found)"
43
+ fi
44
+ }
45
+
46
+ run_stage_7_security() {
47
+ echo " Running security checks..."
48
+
49
+ # SBOM generation
50
+ if [[ -f "${PI_DIR}/scripts/ci/generate_sbom.py" ]]; then
51
+ if python3 "${PI_DIR}/scripts/ci/generate_sbom.py" 2>/dev/null; then
52
+ log_pass "SBOM generation"
53
+ else
54
+ log_fail "SBOM generation" "SBOM generation failed"
55
+ fi
56
+ else
57
+ log_pass "SBOM generation (no script found, skipping)"
58
+ fi
59
+
60
+ # Secret scan
61
+ if [[ -f "${PI_DIR}/scripts/ci/secret_scan.py" ]]; then
62
+ if python3 "${PI_DIR}/scripts/ci/secret_scan.py" 2>/dev/null; then
63
+ log_pass "secret scan"
64
+ else
65
+ log_fail "secret scan" "Secrets detected in codebase"
66
+ fi
67
+ else
68
+ # Fallback: grep for common secret patterns
69
+ local secrets_found=0
70
+ for pattern in "sk-[A-Za-z0-9]{32,}" "ghp_[A-Za-z0-9]{36}" "AKIA[0-9A-Z]{16}" "BEGIN (RSA |EC )?PRIVATE KEY"; do
71
+ if grep -rE "$pattern" . --include="*.py" --include="*.ts" --include="*.env" 2>/dev/null | grep -v ".git" | grep -v "node_modules" | head -1 | grep -q .; then
72
+ ((secrets_found++))
73
+ log_fail "secret scan" "Potential secret pattern detected: $pattern"
74
+ fi
75
+ done
76
+ if [[ $secrets_found -eq 0 ]]; then
77
+ log_pass "secret scan (no secrets detected)"
78
+ fi
79
+ fi
80
+
81
+ # Dependency audit
82
+ if command -v pip-audit &>/dev/null; then
83
+ if pip-audit --path . --skip-editable 2>/dev/null; then
84
+ log_pass "dependency audit (pip-audit)"
85
+ else
86
+ log_fail "dependency audit (pip-audit)" "Vulnerable dependencies found"
87
+ fi
88
+ elif command -v npm &>/dev/null && [[ -f "package.json" ]]; then
89
+ if npm audit --audit-level=high 2>/dev/null; then
90
+ log_pass "dependency audit (npm)"
91
+ else
92
+ log_fail "dependency audit (npm)" "High/critical vulnerabilities found"
93
+ fi
94
+ elif command -v cargo &>/dev/null && [[ -f "Cargo.toml" ]]; then
95
+ if cargo audit 2>/dev/null; then
96
+ log_pass "dependency audit (cargo-audit)"
97
+ else
98
+ log_pass "dependency audit (cargo-audit) (cargo-audit not installed)"
99
+ fi
100
+ else
101
+ log_pass "dependency audit (no package manager found)"
102
+ fi
103
+
104
+ # Container scan (Trivy)
105
+ if command -v trivy &>/dev/null && [[ -f "Dockerfile" ]]; then
106
+ if trivy image --severity HIGH,CRITICAL --exit-code 1 --timeout 10m . 2>/dev/null; then
107
+ log_pass "container scan (Trivy)"
108
+ else
109
+ log_fail "container scan (Trivy)" "HIGH/CRITICAL vulnerabilities found"
110
+ fi
111
+ else
112
+ log_pass "container scan (Trivy not available or no Dockerfile)"
113
+ fi
114
+ }
115
+
116
+ run_stage_8_migration() {
117
+ echo " Running migration verification..."
118
+ if command -v alembic &>/dev/null && [[ -d "alembic" || -d "migrations" ]]; then
119
+ if alembic upgrade head 2>/dev/null; then
120
+ log_pass "migration apply check"
121
+ else
122
+ log_fail "migration apply check" "Migration failed to apply"
123
+ fi
124
+
125
+ if [[ -f "${PI_DIR}/scripts/ci/verify_indexes_and_policies.py" ]]; then
126
+ if python3 "${PI_DIR}/scripts/ci/verify_indexes_and_policies.py" 2>/dev/null; then
127
+ log_pass "index policy verify"
128
+ else
129
+ log_fail "index policy verify" "Index or policy violations found"
130
+ fi
131
+ else
132
+ log_pass "index policy verify (no script found)"
133
+ fi
134
+ else
135
+ log_pass "migration verification (no migration framework found)"
136
+ fi
137
+ }
138
+
139
+ run_stage_9_package() {
140
+ echo " Running package build..."
141
+ if [[ -f "Dockerfile" ]] && command -v docker &>/dev/null; then
142
+ local tag="${CI_COMMIT_SHA:-local}"
143
+ if docker build -t app:"${tag}" . 2>/dev/null; then
144
+ log_pass "package build (Docker)"
145
+ else
146
+ log_fail "package build (Docker)" "Build failed"
147
+ fi
148
+ else
149
+ log_pass "package build (no Dockerfile or Docker not available)"
150
+ fi
151
+ }
152
+
153
+ run_stage_10_release() {
154
+ echo " Running release readiness checks..."
155
+
156
+ # Runbook readiness
157
+ if [[ -f "${PI_DIR}/scripts/ci/check_runbook_readiness.py" ]]; then
158
+ if python3 "${PI_DIR}/scripts/ci/check_runbook_readiness.py" 2>/dev/null; then
159
+ log_pass "runbook readiness"
160
+ else
161
+ log_fail "runbook readiness" "Runbook not ready"
162
+ fi
163
+ else
164
+ # Fallback: check for runbook file
165
+ if [[ -f "docs/runbook.md" || -f "docs/RUNBOOK.md" || -f "RUNBOOK.md" ]]; then
166
+ log_pass "runbook readiness (runbook file exists)"
167
+ else
168
+ log_fail "runbook readiness" "No runbook.md found"
169
+ fi
170
+ fi
171
+
172
+ # Observability readiness
173
+ if [[ -f "${PI_DIR}/scripts/ci/check_observability_readiness.py" ]]; then
174
+ if python3 "${PI_DIR}/scripts/ci/check_observability_readiness.py" 2>/dev/null; then
175
+ log_pass "observability readiness"
176
+ else
177
+ log_fail "observability readiness" "Observability not ready"
178
+ fi
179
+ else
180
+ # Fallback: check for tracing/metrics setup
181
+ local has_observability=false
182
+ for f in $(find . -name "*.py" -o -name "*.ts" 2>/dev/null | head -30); do
183
+ if grep -qiE "(opentelemetry|prometheus|datadog|jaeger|tracing|metrics)" "$f" 2>/dev/null; then
184
+ has_observability=true
185
+ break
186
+ fi
187
+ done
188
+ if [[ "$has_observability" == "true" ]]; then
189
+ log_pass "observability readiness (observability patterns detected)"
190
+ else
191
+ log_pass "observability readiness (no observability patterns found, skipping)"
192
+ fi
193
+ fi
194
+
195
+ # Release policy check
196
+ if [[ -f "${PI_DIR}/scripts/ci/check_release_policy.py" ]]; then
197
+ if python3 "${PI_DIR}/scripts/ci/check_release_policy.py" 2>/dev/null; then
198
+ log_pass "release policy check"
199
+ else
200
+ log_fail "release policy check" "Release policy violations found"
201
+ fi
202
+ else
203
+ log_pass "release policy check (no script found)"
204
+ fi
205
+ }
206
+
207
+ case "$STAGE" in
208
+ 6|integration)
209
+ run_stage_6_integration
210
+ ;;
211
+ 7|security)
212
+ run_stage_7_security
213
+ ;;
214
+ 8|migration)
215
+ run_stage_8_migration
216
+ ;;
217
+ 9|package)
218
+ run_stage_9_package
219
+ ;;
220
+ 10|release)
221
+ run_stage_10_release
222
+ ;;
223
+ all)
224
+ run_stage_6_integration
225
+ echo ""
226
+ run_stage_7_security
227
+ echo ""
228
+ run_stage_8_migration
229
+ echo ""
230
+ run_stage_9_package
231
+ echo ""
232
+ run_stage_10_release
233
+ ;;
234
+ esac
235
+
236
+ if [[ $FAIL -gt 0 ]]; then
237
+ echo " Stage FAILED (${FAIL} failure(s))"
238
+ exit 1
239
+ fi
240
+
241
+ echo " Stage passed (${PASS} check(s))"
242
+ exit 0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Stage: security
3
+ exec bash "$(dirname "$0")/stage_remaining.sh" "security"