amazingteam 3.0.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 (164) hide show
  1. package/.ai-team/agents/architect.md +144 -0
  2. package/.ai-team/agents/ci-analyst.md +188 -0
  3. package/.ai-team/agents/developer.md +176 -0
  4. package/.ai-team/agents/planner.md +355 -0
  5. package/.ai-team/agents/qa.md +189 -0
  6. package/.ai-team/agents/reviewer.md +211 -0
  7. package/.ai-team/agents/triage.md +146 -0
  8. package/.ai-team/commands/ci-analyze.md +116 -0
  9. package/.ai-team/commands/design.md +100 -0
  10. package/.ai-team/commands/implement.md +108 -0
  11. package/.ai-team/commands/release-check.md +142 -0
  12. package/.ai-team/commands/review.md +142 -0
  13. package/.ai-team/commands/test.md +115 -0
  14. package/.ai-team/commands/triage.md +138 -0
  15. package/.ai-team/memory/architect/architecture_notes.md +67 -0
  16. package/.ai-team/memory/architect/design_rationale.md +113 -0
  17. package/.ai-team/memory/architect/module_map.md +84 -0
  18. package/.ai-team/memory/ci-analyst/failure_patterns.md +102 -0
  19. package/.ai-team/memory/ci-analyst/runbook_references.md +87 -0
  20. package/.ai-team/memory/developer/bug_investigation.md +102 -0
  21. package/.ai-team/memory/developer/build_issues.md +115 -0
  22. package/.ai-team/memory/developer/implementation_notes.md +83 -0
  23. package/.ai-team/memory/failures/failure_library.md +103 -0
  24. package/.ai-team/memory/planner/decomposition_notes.md +82 -0
  25. package/.ai-team/memory/planner/flow_rules.md +86 -0
  26. package/.ai-team/memory/planner/github_issue_patterns.md +229 -0
  27. package/.ai-team/memory/qa/regression_cases.md +101 -0
  28. package/.ai-team/memory/qa/test_strategy.md +138 -0
  29. package/.ai-team/memory/qa/validation_notes.md +110 -0
  30. package/.ai-team/memory/reviewer/quality_rules.md +105 -0
  31. package/.ai-team/memory/reviewer/recurring_risks.md +109 -0
  32. package/.ai-team/memory/reviewer/review_notes.md +124 -0
  33. package/.ai-team/memory/triage/classification_heuristics.md +82 -0
  34. package/.ai-team/memory/triage/debug_notes.md +87 -0
  35. package/.ai-team/opencode.template.jsonc +216 -0
  36. package/.ai-team/skills/bugfix-playbook/skill.md +174 -0
  37. package/.ai-team/skills/ci-failure-analysis/skill.md +176 -0
  38. package/.ai-team/skills/issue-triage/skill.md +163 -0
  39. package/.ai-team/skills/regression-checklist/skill.md +176 -0
  40. package/.ai-team/skills/release-readiness-check/skill.md +216 -0
  41. package/.ai-team/skills/repo-architecture-reader/skill.md +139 -0
  42. package/.ai-team/skills/safe-refactor-checklist/skill.md +215 -0
  43. package/.ai-team/skills/task-breakdown-and-dispatch/skill.md +151 -0
  44. package/.ai-team/skills/test-first-feature-dev/skill.md +205 -0
  45. package/.ai-team/workflows/ci.yml +81 -0
  46. package/.ai-team/workflows/nightly-ai-maintenance.yml +129 -0
  47. package/.ai-team/workflows/opencode.yml +33 -0
  48. package/.ai-team/workflows/pr-check.yml +41 -0
  49. package/.foundation/foundation.lock +38 -0
  50. package/.foundation/local-overrides.md +97 -0
  51. package/.foundation/upgrade-history.md +38 -0
  52. package/.opencode/agents/architect.md +38 -0
  53. package/.opencode/agents/ci-analyst.md +38 -0
  54. package/.opencode/agents/developer.md +43 -0
  55. package/.opencode/agents/planner.md +47 -0
  56. package/.opencode/agents/qa.md +34 -0
  57. package/.opencode/agents/reviewer.md +38 -0
  58. package/.opencode/agents/triage.md +37 -0
  59. package/.opencode/commands/auto.md +264 -0
  60. package/.opencode/commands/breakdown-issue.md +94 -0
  61. package/.opencode/commands/ci-analyze.md +15 -0
  62. package/.opencode/commands/close-parent-task.md +122 -0
  63. package/.opencode/commands/design.md +15 -0
  64. package/.opencode/commands/dispatch-next.md +102 -0
  65. package/.opencode/commands/implement.md +16 -0
  66. package/.opencode/commands/release-check.md +16 -0
  67. package/.opencode/commands/resume.md +88 -0
  68. package/.opencode/commands/review.md +15 -0
  69. package/.opencode/commands/show-blockers.md +97 -0
  70. package/.opencode/commands/summarize-parent.md +121 -0
  71. package/.opencode/commands/test.md +15 -0
  72. package/.opencode/commands/triage.md +109 -0
  73. package/.opencode/skills/bugfix-playbook/SKILL.md +81 -0
  74. package/.opencode/skills/ci-failure-analysis/SKILL.md +94 -0
  75. package/.opencode/skills/issue-triage/SKILL.md +80 -0
  76. package/.opencode/skills/regression-checklist/SKILL.md +81 -0
  77. package/.opencode/skills/release-readiness-check/SKILL.md +81 -0
  78. package/.opencode/skills/repo-architecture-reader/SKILL.md +65 -0
  79. package/.opencode/skills/safe-refactor-checklist/SKILL.md +76 -0
  80. package/.opencode/skills/task-breakdown-and-dispatch/SKILL.md +255 -0
  81. package/.opencode/skills/test-first-feature-dev/SKILL.md +78 -0
  82. package/AGENTS.md +879 -0
  83. package/CHANGELOG.md +261 -0
  84. package/LICENSE +21 -0
  85. package/README.md +1215 -0
  86. package/VERSION +1 -0
  87. package/action/__tests__/downloader.test.js +251 -0
  88. package/action/__tests__/merger.test.js +156 -0
  89. package/action/__tests__/path-resolver.test.js +199 -0
  90. package/action/__tests__/validator.test.js +310 -0
  91. package/action/action.yml +61 -0
  92. package/action/index.js +223 -0
  93. package/action/lib/downloader.js +344 -0
  94. package/action/lib/merger.js +170 -0
  95. package/action/lib/path-resolver.js +176 -0
  96. package/action/lib/setup.js +286 -0
  97. package/action/lib/validator.js +324 -0
  98. package/cli/__tests__/cli.test.js +270 -0
  99. package/cli/amazingteam.cjs +225 -0
  100. package/cli/commands/check-update.cjs +159 -0
  101. package/cli/commands/init.cjs +412 -0
  102. package/cli/commands/local.cjs +264 -0
  103. package/cli/commands/migrate.cjs +316 -0
  104. package/cli/commands/status.cjs +241 -0
  105. package/cli/commands/upgrade.cjs +213 -0
  106. package/cli/commands/validate.cjs +259 -0
  107. package/cli/commands/version.cjs +59 -0
  108. package/cli/sync.cjs +237 -0
  109. package/dist/index.js +35 -0
  110. package/docs/architecture/overview.md +138 -0
  111. package/docs/blocker_resolution_design.md +372 -0
  112. package/docs/bootstrap-model.md +356 -0
  113. package/docs/config-reference.md +458 -0
  114. package/docs/how-to-use.md +178 -0
  115. package/docs/migration-to-v3.md +355 -0
  116. package/docs/overlay-guide.md +156 -0
  117. package/docs/patterns/README.md +67 -0
  118. package/docs/quick-start-v3.md +330 -0
  119. package/docs/releases/README.md +64 -0
  120. package/docs/runbooks/ci/README.md +62 -0
  121. package/docs/runbooks/ci/build-debug.md +120 -0
  122. package/docs/runbooks/ci/flaky-tests.md +127 -0
  123. package/docs/runbooks/getting-started.md +81 -0
  124. package/docs/upgrade-policy.md +188 -0
  125. package/docs/versioning.md +199 -0
  126. package/overlays/README.md +30 -0
  127. package/overlays/ai-agent-product/.ai-team/skills/llm-integration/skill.md +99 -0
  128. package/overlays/ai-agent-product/docs/ai-agent-architecture.md +68 -0
  129. package/overlays/ai-agent-product/overlay.yaml +26 -0
  130. package/overlays/cpp-qt-desktop/.ai-team/skills/qt-signals-slots/skill.md +60 -0
  131. package/overlays/cpp-qt-desktop/docs/qt-conventions.md +64 -0
  132. package/overlays/cpp-qt-desktop/overlay.yaml +22 -0
  133. package/overlays/python-backend/.ai-team/skills/python-testing/skill.md +90 -0
  134. package/overlays/python-backend/docs/python-style.md +78 -0
  135. package/overlays/python-backend/overlay.yaml +22 -0
  136. package/overlays/web-fullstack/.ai-team/skills/frontend-testing/skill.md +70 -0
  137. package/overlays/web-fullstack/docs/frontend-conventions.md +68 -0
  138. package/overlays/web-fullstack/overlay.yaml +26 -0
  139. package/package.json +84 -0
  140. package/presets/default.yaml +161 -0
  141. package/presets/go.yaml +43 -0
  142. package/presets/python.yaml +43 -0
  143. package/presets/typescript.yaml +40 -0
  144. package/schemas/config.schema.json +239 -0
  145. package/scripts/diff_foundation_vs_project.sh +134 -0
  146. package/scripts/generate_docs.sh +200 -0
  147. package/scripts/init_project.sh +455 -0
  148. package/scripts/plan_upgrade.sh +268 -0
  149. package/scripts/upgrade_foundation.sh +365 -0
  150. package/scripts/validate-foundation.cjs +278 -0
  151. package/scripts/validate_foundation.sh +192 -0
  152. package/scripts/validate_project_setup.sh +171 -0
  153. package/tasks/README.md +94 -0
  154. package/tasks/_template/analysis.md +76 -0
  155. package/tasks/_template/design.md +121 -0
  156. package/tasks/_template/implementation.md +121 -0
  157. package/tasks/_template/release.md +119 -0
  158. package/tasks/_template/review.md +131 -0
  159. package/tasks/_template/subtasks/task.yaml +24 -0
  160. package/tasks/_template/task.yaml +75 -0
  161. package/tasks/_template/validation.md +128 -0
  162. package/templates/amazingteam.yml +81 -0
  163. package/templates/gitignore +14 -0
  164. package/templates/opencode.jsonc +216 -0
@@ -0,0 +1,268 @@
1
+ #!/bin/bash
2
+ # plan_upgrade.sh
3
+ # Compare downstream project against foundation and generate upgrade plan
4
+
5
+ set -e
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ FOUNDATION_ROOT="$(dirname "$SCRIPT_DIR")"
9
+ PROJECT_ROOT="${1:-.}"
10
+
11
+ # Resolve to absolute path
12
+ if [[ "${PROJECT_ROOT:0:1}" != "/" ]]; then
13
+ PROJECT_ROOT="$(pwd)/$PROJECT_ROOT"
14
+ fi
15
+
16
+ # Colors
17
+ RED='\033[0;31m'
18
+ GREEN='\033[0;32m'
19
+ YELLOW='\033[1;33m'
20
+ BLUE='\033[0;34m'
21
+ CYAN='\033[0;36m'
22
+ NC='\033[0m'
23
+
24
+ # File classification
25
+ # Class A: Auto-generatable (safe to create/replace)
26
+ # Class B: Auto-suggested, not auto-committed (review required)
27
+ # Class C: Protected (human approval mandatory)
28
+
29
+ CLASS_A_FILES=(
30
+ "tasks/_template/*"
31
+ ".github/ISSUE_TEMPLATE/*"
32
+ ".ai-team/memory/*/*.md"
33
+ )
34
+
35
+ CLASS_B_FILES=(
36
+ ".ai-team/agents/*.md"
37
+ ".ai-team/skills/*/skill.md"
38
+ ".ai-team/commands/*.md"
39
+ ".github/workflows/*.yml"
40
+ "AGENTS.md"
41
+ )
42
+
43
+ CLASS_C_FILES=(
44
+ "docs/architecture/*"
45
+ "docs/decisions/*"
46
+ )
47
+
48
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
49
+ echo -e "${CYAN} AI Team Foundation Upgrade Planner${NC}"
50
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
51
+ echo ""
52
+
53
+ # Read versions
54
+ FOUNDATION_VERSION=$(cat "$FOUNDATION_ROOT/VERSION" 2>/dev/null || echo "unknown")
55
+
56
+ LOCK_FILE="$PROJECT_ROOT/.foundation/foundation.lock"
57
+ if [[ -f "$LOCK_FILE" ]]; then
58
+ PROJECT_VERSION=$(grep "foundation_version:" "$LOCK_FILE" | cut -d: -f2 | tr -d ' ')
59
+ PROJECT_OVERLAY=$(grep "overlay:" "$LOCK_FILE" | cut -d: -f2 | tr -d ' ')
60
+ else
61
+ PROJECT_VERSION="unknown"
62
+ PROJECT_OVERLAY="none"
63
+ fi
64
+
65
+ echo -e "${CYAN}Foundation Version:${NC} $FOUNDATION_VERSION"
66
+ echo -e "${CYAN}Project Version:${NC} $PROJECT_VERSION"
67
+ echo -e "${CYAN}Project Overlay:${NC} $PROJECT_OVERLAY"
68
+ echo ""
69
+
70
+ # Track changes
71
+ MISSING_FILES=()
72
+ OUTDATED_FILES=()
73
+ PROTECTED_FILES=()
74
+ LOCAL_OVERRIDES=()
75
+
76
+ echo -e "${CYAN}[1] Checking for missing files...${NC}"
77
+ echo ""
78
+
79
+ # Check agents
80
+ for agent in planner architect developer qa reviewer triage ci-analyst; do
81
+ if [[ ! -f "$PROJECT_ROOT/.ai-team/agents/$agent.md" ]]; then
82
+ MISSING_FILES+=(".ai-team/agents/$agent.md (Class B)")
83
+ echo -e " ${YELLOW}Missing:${NC} .ai-team/agents/$agent.md"
84
+ fi
85
+ done
86
+
87
+ # Check skills
88
+ for skill_dir in "$FOUNDATION_ROOT/.ai-team/skills"/*; do
89
+ if [[ -d "$skill_dir" ]]; then
90
+ skill=$(basename "$skill_dir")
91
+ if [[ ! -f "$PROJECT_ROOT/.ai-team/skills/$skill/skill.md" ]]; then
92
+ MISSING_FILES+=(".ai-team/skills/$skill/skill.md (Class B)")
93
+ echo -e " ${YELLOW}Missing:${NC} .ai-team/skills/$skill/skill.md"
94
+ fi
95
+ fi
96
+ done
97
+
98
+ # Check commands
99
+ for cmd in triage design implement test review ci-analyze release-check; do
100
+ if [[ ! -f "$PROJECT_ROOT/.ai-team/commands/$cmd.md" ]]; then
101
+ MISSING_FILES+=(".ai-team/commands/$cmd.md (Class B)")
102
+ echo -e " ${YELLOW}Missing:${NC} .ai-team/commands/$cmd.md"
103
+ fi
104
+ done
105
+
106
+ # Check memory directories
107
+ for role in planner architect developer qa reviewer triage ci-analyst failures; do
108
+ if [[ ! -d "$PROJECT_ROOT/.ai-team/memory/$role" ]]; then
109
+ MISSING_FILES+=(".ai-team/memory/$role/ (Class A)")
110
+ echo -e " ${YELLOW}Missing:${NC} .ai-team/memory/$role/"
111
+ fi
112
+ done
113
+
114
+ # Check documentation zones
115
+ for zone in patterns releases runbooks/ci; do
116
+ if [[ ! -d "$PROJECT_ROOT/docs/$zone" ]]; then
117
+ MISSING_FILES+=("docs/$zone/ (Class A)")
118
+ echo -e " ${YELLOW}Missing:${NC} docs/$zone/"
119
+ fi
120
+ done
121
+
122
+ echo ""
123
+ echo -e "${CYAN}[2] Checking for outdated files...${NC}"
124
+ echo ""
125
+
126
+ # Compare file contents (simplified - in real implementation, use proper diff)
127
+ check_outdated() {
128
+ local foundation_file="$1"
129
+ local project_file="$2"
130
+ local file_class="$3"
131
+
132
+ if [[ -f "$foundation_file" ]] && [[ -f "$project_file" ]]; then
133
+ if ! diff -q "$foundation_file" "$project_file" > /dev/null 2>&1; then
134
+ OUTDATED_FILES+=("$project_file ($file_class)")
135
+ echo -e " ${BLUE}Modified:${NC} $project_file"
136
+ fi
137
+ fi
138
+ }
139
+
140
+ # Check key files for modifications
141
+ for agent in planner architect developer qa reviewer triage ci-analyst; do
142
+ check_outdated \
143
+ "$FOUNDATION_ROOT/.ai-team/agents/$agent.md" \
144
+ "$PROJECT_ROOT/.ai-team/agents/$agent.md" \
145
+ "Class B"
146
+ done
147
+
148
+ echo ""
149
+ echo -e "${CYAN}[3] Checking protected files...${NC}"
150
+ echo ""
151
+
152
+ # Check protected areas
153
+ for protected in "docs/architecture" "docs/decisions"; do
154
+ if [[ -d "$PROJECT_ROOT/$protected" ]]; then
155
+ file_count=$(find "$PROJECT_ROOT/$protected" -type f 2>/dev/null | wc -l)
156
+ if [[ $file_count -gt 0 ]]; then
157
+ PROTECTED_FILES+=("$protected/ ($file_count files)")
158
+ echo -e " ${RED}Protected:${NC} $protected/ ($file_count files)"
159
+ fi
160
+ fi
161
+ done
162
+
163
+ echo ""
164
+ echo -e "${CYAN}[4] Checking local overrides...${NC}"
165
+ echo ""
166
+
167
+ OVERRIDES_FILE="$PROJECT_ROOT/.foundation/local-overrides.md"
168
+ if [[ -f "$OVERRIDES_FILE" ]]; then
169
+ echo -e " Local overrides documented at: .foundation/local-overrides.md"
170
+ # In a real implementation, parse and display the overrides
171
+ else
172
+ echo -e " ${YELLOW}Warning:${NC} No local-overrides.md found"
173
+ fi
174
+
175
+ echo ""
176
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
177
+ echo -e "${CYAN}Upgrade Plan Summary${NC}"
178
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
179
+ echo ""
180
+
181
+ echo -e "${YELLOW}Missing Files:${NC} ${#MISSING_FILES[@]}"
182
+ for f in "${MISSING_FILES[@]:0:5}"; do
183
+ echo -e " - $f"
184
+ done
185
+ if [[ ${#MISSING_FILES[@]} -gt 5 ]]; then
186
+ echo -e " ... and $(( ${#MISSING_FILES[@]} - 5 )) more"
187
+ fi
188
+ echo ""
189
+
190
+ echo -e "${BLUE}Outdated Files:${NC} ${#OUTDATED_FILES[@]}"
191
+ for f in "${OUTDATED_FILES[@]:0:5}"; do
192
+ echo -e " - $f"
193
+ done
194
+ if [[ ${#OUTDATED_FILES[@]} -gt 5 ]]; then
195
+ echo -e " ... and $(( ${#OUTDATED_FILES[@]} - 5 )) more"
196
+ fi
197
+ echo ""
198
+
199
+ echo -e "${RED}Protected Files:${NC} ${#PROTECTED_FILES[@]}"
200
+ for f in "${PROTECTED_FILES[@]}"; do
201
+ echo -e " - $f"
202
+ done
203
+ echo ""
204
+
205
+ # Risk assessment
206
+ echo -e "${CYAN}Risk Assessment:${NC}"
207
+ if [[ ${#PROTECTED_FILES[@]} -gt 0 ]]; then
208
+ echo -e " ${RED}HIGH RISK${NC} - Protected files require manual review"
209
+ elif [[ ${#OUTDATED_FILES[@]} -gt 0 ]]; then
210
+ echo -e " ${YELLOW}MEDIUM RISK${NC} - Modified files need review before patching"
211
+ elif [[ ${#MISSING_FILES[@]} -gt 0 ]]; then
212
+ echo -e " ${GREEN}LOW RISK${NC} - Only additive changes needed"
213
+ else
214
+ echo -e " ${GREEN}NO CHANGES${NC} - Project is up to date"
215
+ fi
216
+ echo ""
217
+
218
+ # Generate upgrade report
219
+ REPORT_FILE="$PROJECT_ROOT/.foundation/upgrade-plan.md"
220
+ cat > "$REPORT_FILE" << EOF
221
+ # Upgrade Plan
222
+
223
+ Generated: $(date -I)
224
+ From: $PROJECT_VERSION
225
+ To: $FOUNDATION_VERSION
226
+
227
+ ## Summary
228
+
229
+ - Missing Files: ${#MISSING_FILES[@]}
230
+ - Outdated Files: ${#OUTDATED_FILES[@]}
231
+ - Protected Files: ${#PROTECTED_FILES[@]}
232
+
233
+ ## Missing Files
234
+
235
+ $(for f in "${MISSING_FILES[@]}"; do echo "- $f"; done)
236
+
237
+ ## Outdated Files
238
+
239
+ $(for f in "${OUTDATED_FILES[@]}"; do echo "- $f"; done)
240
+
241
+ ## Protected Files (Manual Review Required)
242
+
243
+ $(for f in "${PROTECTED_FILES[@]}"; do echo "- $f"; done)
244
+
245
+ ## Recommendations
246
+
247
+ $(if [[ ${#PROTECTED_FILES[@]} -gt 0 ]]; then
248
+ echo "1. Review all protected files before proceeding"
249
+ echo "2. Document any customizations in local-overrides.md"
250
+ echo "3. Run upgrade with --review flag"
251
+ elif [[ ${#OUTDATED_FILES[@]} -gt 0 ]]; then
252
+ echo "1. Review outdated file diffs"
253
+ echo "2. Decide which changes to keep"
254
+ echo "3. Run upgrade with selective files"
255
+ else
256
+ echo "1. Safe to run automatic upgrade"
257
+ echo "2. No conflicts detected"
258
+ fi)
259
+
260
+ ## Next Steps
261
+
262
+ 1. Review this plan
263
+ 2. Run: ./scripts/upgrade_foundation.sh
264
+ 3. Verify changes after upgrade
265
+ EOF
266
+
267
+ echo -e "${GREEN}Upgrade plan saved to:${NC} $REPORT_FILE"
268
+ echo ""
@@ -0,0 +1,365 @@
1
+ #!/bin/bash
2
+ # upgrade_foundation.sh
3
+ # Apply controlled upgrade to downstream project
4
+
5
+ set -e
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ FOUNDATION_ROOT="$(dirname "$SCRIPT_DIR")"
9
+ PROJECT_ROOT="${1:-.}"
10
+
11
+ # Colors
12
+ RED='\033[0;31m'
13
+ GREEN='\033[0;32m'
14
+ YELLOW='\033[1;33m'
15
+ BLUE='\033[0;34m'
16
+ CYAN='\033[0;36m'
17
+ NC='\033[0m'
18
+
19
+ # Flags
20
+ FORCE=false
21
+ DRY_RUN=false
22
+ SKIP_PROTECTED=true
23
+
24
+ usage() {
25
+ echo "Usage: $0 [OPTIONS] [project-path]"
26
+ echo ""
27
+ echo "Apply controlled foundation upgrade to a downstream project."
28
+ echo ""
29
+ echo "Options:"
30
+ echo " --force Skip confirmation prompts"
31
+ echo " --dry-run Show what would be done without making changes"
32
+ echo " --include-protected Attempt to upgrade protected files (dangerous)"
33
+ echo " -h, --help Show this help message"
34
+ echo ""
35
+ echo "Examples:"
36
+ echo " $0 ./my-project"
37
+ echo " $0 --dry-run ."
38
+ echo " $0 --force ./my-project"
39
+ }
40
+
41
+ parse_args() {
42
+ while [[ $# -gt 0 ]]; do
43
+ case $1 in
44
+ --force)
45
+ FORCE=true
46
+ shift
47
+ ;;
48
+ --dry-run)
49
+ DRY_RUN=true
50
+ shift
51
+ ;;
52
+ --include-protected)
53
+ SKIP_PROTECTED=false
54
+ shift
55
+ ;;
56
+ -h|--help)
57
+ usage
58
+ exit 0
59
+ ;;
60
+ *)
61
+ PROJECT_ROOT="$1"
62
+ shift
63
+ ;;
64
+ esac
65
+ done
66
+ }
67
+
68
+ log_info() {
69
+ echo -e "${CYAN}[INFO]${NC} $1"
70
+ }
71
+
72
+ log_success() {
73
+ echo -e "${GREEN}[SUCCESS]${NC} $1"
74
+ }
75
+
76
+ log_warning() {
77
+ echo -e "${YELLOW}[WARNING]${NC} $1"
78
+ }
79
+
80
+ log_error() {
81
+ echo -e "${RED}[ERROR]${NC} $1"
82
+ }
83
+
84
+ log_dry_run() {
85
+ echo -e "${BLUE}[DRY-RUN]${NC} Would: $1"
86
+ }
87
+
88
+ # File classification functions
89
+ is_class_a() {
90
+ local file="$1"
91
+ # Class A: Auto-generatable
92
+ [[ "$file" == tasks/_template/* ]] && return 0
93
+ [[ "$file" == .github/ISSUE_TEMPLATE/* ]] && return 0
94
+ [[ "$file" == .ai-team/memory/* ]] && return 0
95
+ return 1
96
+ }
97
+
98
+ is_class_b() {
99
+ local file="$1"
100
+ # Class B: Review required
101
+ [[ "$file" == .ai-team/agents/* ]] && return 0
102
+ [[ "$file" == .ai-team/skills/* ]] && return 0
103
+ [[ "$file" == .ai-team/commands/* ]] && return 0
104
+ [[ "$file" == .github/workflows/* ]] && return 0
105
+ [[ "$file" == AGENTS.md ]] && return 0
106
+ return 1
107
+ }
108
+
109
+ is_class_c() {
110
+ local file="$1"
111
+ # Class C: Protected
112
+ [[ "$file" == docs/architecture/* ]] && return 0
113
+ [[ "$file" == docs/decisions/* ]] && return 0
114
+ return 1
115
+ }
116
+
117
+ is_protected() {
118
+ local file="$1"
119
+ if [[ "$SKIP_PROTECTED" == true ]] && is_class_c "$file"; then
120
+ return 0
121
+ fi
122
+ return 1
123
+ }
124
+
125
+ # Backup function
126
+ create_backup() {
127
+ local backup_dir="$PROJECT_ROOT/.foundation/backup-$(date +%Y%m%d-%H%M%S)"
128
+ log_info "Creating backup at $backup_dir"
129
+
130
+ if [[ "$DRY_RUN" == true ]]; then
131
+ log_dry_run "create backup at $backup_dir"
132
+ else
133
+ mkdir -p "$backup_dir"
134
+ # Backup key directories
135
+ [[ -d "$PROJECT_ROOT/.ai-team" ]] && cp -r "$PROJECT_ROOT/.ai-team" "$backup_dir/"
136
+ [[ -f "$PROJECT_ROOT/AGENTS.md" ]] && cp "$PROJECT_ROOT/AGENTS.md" "$backup_dir/"
137
+ [[ -f "$PROJECT_ROOT/opencode.jsonc" ]] && cp "$PROJECT_ROOT/opencode.jsonc" "$backup_dir/"
138
+ fi
139
+ }
140
+
141
+ # Add missing files
142
+ add_missing_files() {
143
+ log_info "Adding missing files..."
144
+
145
+ local added=0
146
+ local skipped=0
147
+
148
+ # Agents
149
+ for agent in planner architect developer qa reviewer triage ci-analyst; do
150
+ local target="$PROJECT_ROOT/.ai-team/agents/$agent.md"
151
+ local source="$FOUNDATION_ROOT/.ai-team/agents/$agent.md"
152
+
153
+ if [[ ! -f "$target" ]] && [[ -f "$source" ]]; then
154
+ if [[ "$DRY_RUN" == true ]]; then
155
+ log_dry_run "add $target"
156
+ else
157
+ mkdir -p "$(dirname "$target")"
158
+ cp "$source" "$target"
159
+ log_success "Added: .ai-team/agents/$agent.md"
160
+ fi
161
+ ((added++))
162
+ fi
163
+ done
164
+
165
+ # Skills
166
+ for skill_dir in "$FOUNDATION_ROOT/.ai-team/skills"/*; do
167
+ if [[ -d "$skill_dir" ]]; then
168
+ local skill=$(basename "$skill_dir")
169
+ local target="$PROJECT_ROOT/.ai-team/skills/$skill/skill.md"
170
+ local source="$skill_dir/skill.md"
171
+
172
+ if [[ ! -f "$target" ]] && [[ -f "$source" ]]; then
173
+ if [[ "$DRY_RUN" == true ]]; then
174
+ log_dry_run "add $target"
175
+ else
176
+ mkdir -p "$(dirname "$target")"
177
+ cp "$source" "$target"
178
+ log_success "Added: .ai-team/skills/$skill/skill.md"
179
+ fi
180
+ ((added++))
181
+ fi
182
+ fi
183
+ done
184
+
185
+ # Memory directories
186
+ for role in planner architect developer qa reviewer triage ci-analyst failures; do
187
+ local target="$PROJECT_ROOT/.ai-team/memory/$role"
188
+ local source="$FOUNDATION_ROOT/.ai-team/memory/$role"
189
+
190
+ if [[ ! -d "$target" ]] && [[ -d "$source" ]]; then
191
+ if [[ "$DRY_RUN" == true ]]; then
192
+ log_dry_run "add $target/"
193
+ else
194
+ mkdir -p "$target"
195
+ cp -r "$source"/* "$target/" 2>/dev/null || true
196
+ log_success "Added: .ai-team/memory/$role/"
197
+ fi
198
+ ((added++))
199
+ fi
200
+ done
201
+
202
+ # Documentation zones
203
+ for zone in patterns releases runbooks/ci; do
204
+ local target="$PROJECT_ROOT/docs/$zone"
205
+ local source="$FOUNDATION_ROOT/docs/$zone"
206
+
207
+ if [[ ! -d "$target" ]] && [[ -d "$source" ]]; then
208
+ if [[ "$DRY_RUN" == true ]]; then
209
+ log_dry_run "add $target/"
210
+ else
211
+ mkdir -p "$target"
212
+ cp -r "$source"/* "$target/" 2>/dev/null || true
213
+ log_success "Added: docs/$zone/"
214
+ fi
215
+ ((added++))
216
+ fi
217
+ done
218
+
219
+ echo ""
220
+ log_info "Added: $added, Skipped: $skipped"
221
+ }
222
+
223
+ # Update outdated files (Class B only, with confirmation)
224
+ update_outdated_files() {
225
+ log_info "Checking for outdated files..."
226
+
227
+ local updated=0
228
+ local skipped=0
229
+
230
+ # Check agents (Class B)
231
+ for agent in planner architect developer qa reviewer triage ci-analyst; do
232
+ local target="$PROJECT_ROOT/.ai-team/agents/$agent.md"
233
+ local source="$FOUNDATION_ROOT/.ai-team/agents/$agent.md"
234
+
235
+ if [[ -f "$target" ]] && [[ -f "$source" ]]; then
236
+ if ! diff -q "$source" "$target" > /dev/null 2>&1; then
237
+ if [[ "$FORCE" == true ]]; then
238
+ if [[ "$DRY_RUN" == true ]]; then
239
+ log_dry_run "update $target"
240
+ else
241
+ cp "$source" "$target"
242
+ log_success "Updated: .ai-team/agents/$agent.md"
243
+ fi
244
+ ((updated++))
245
+ else
246
+ log_warning "Modified: .ai-team/agents/$agent.md (use --force to update)"
247
+ ((skipped++))
248
+ fi
249
+ fi
250
+ fi
251
+ done
252
+
253
+ echo ""
254
+ log_info "Updated: $updated, Skipped (use --force): $skipped"
255
+ }
256
+
257
+ # Update lock file
258
+ update_lock_file() {
259
+ local lock_file="$PROJECT_ROOT/.foundation/foundation.lock"
260
+ local foundation_version=$(cat "$FOUNDATION_ROOT/VERSION")
261
+
262
+ if [[ "$DRY_RUN" == true ]]; then
263
+ log_dry_run "update $lock_file"
264
+ return
265
+ fi
266
+
267
+ if [[ -f "$lock_file" ]]; then
268
+ # Update version and last_upgrade_at
269
+ sed -i "s/foundation_version:.*/foundation_version: $foundation_version/" "$lock_file"
270
+ sed -i "s/last_upgrade_at:.*/last_upgrade_at: $(date -I)/" "$lock_file"
271
+ log_success "Updated foundation.lock"
272
+ fi
273
+ }
274
+
275
+ # Update upgrade history
276
+ update_upgrade_history() {
277
+ local history_file="$PROJECT_ROOT/.foundation/upgrade-history.md"
278
+ local foundation_version=$(cat "$FOUNDATION_ROOT/VERSION")
279
+ local project_version="unknown"
280
+
281
+ if [[ -f "$PROJECT_ROOT/.foundation/foundation.lock" ]]; then
282
+ project_version=$(grep "foundation_version:" "$PROJECT_ROOT/.foundation/foundation.lock" | cut -d: -f2 | tr -d ' ')
283
+ fi
284
+
285
+ if [[ "$DRY_RUN" == true ]]; then
286
+ log_dry_run "update $history_file"
287
+ return
288
+ fi
289
+
290
+ cat >> "$history_file" << EOF
291
+
292
+ ## Upgrade - $(date -I)
293
+
294
+ - **From Version**: $project_version
295
+ - **To Version**: $foundation_version
296
+ - **Action**: Controlled upgrade applied
297
+ - **Protected Files**: Skipped
298
+ - **Manual Review Required**: No
299
+
300
+ EOF
301
+
302
+ log_success "Updated upgrade-history.md"
303
+ }
304
+
305
+ # Main
306
+ parse_args "$@"
307
+
308
+ # Resolve to absolute path
309
+ if [[ "${PROJECT_ROOT:0:1}" != "/" ]]; then
310
+ PROJECT_ROOT="$(pwd)/$PROJECT_ROOT"
311
+ fi
312
+
313
+ FOUNDATION_VERSION=$(cat "$FOUNDATION_ROOT/VERSION" 2>/dev/null || echo "unknown")
314
+
315
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
316
+ echo -e "${CYAN} AI Team Foundation Upgrade${NC}"
317
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
318
+ echo ""
319
+ echo -e "${CYAN}Foundation Version:${NC} $FOUNDATION_VERSION"
320
+ echo -e "${CYAN}Project Path:${NC} $PROJECT_ROOT"
321
+ if [[ "$DRY_RUN" == true ]]; then
322
+ echo -e "${BLUE}Mode:${NC} DRY RUN (no changes will be made)"
323
+ fi
324
+ echo ""
325
+
326
+ # Check if project has foundation lock
327
+ if [[ ! -f "$PROJECT_ROOT/.foundation/foundation.lock" ]]; then
328
+ log_warning "No foundation.lock found. Is this a foundation-initialized project?"
329
+ if [[ "$FORCE" != true ]]; then
330
+ echo "Use --force to proceed anyway."
331
+ exit 1
332
+ fi
333
+ fi
334
+
335
+ # Create backup
336
+ if [[ "$DRY_RUN" != true ]]; then
337
+ create_backup
338
+ fi
339
+ echo ""
340
+
341
+ # Add missing files (Class A - always safe)
342
+ add_missing_files
343
+ echo ""
344
+
345
+ # Update outdated files (Class B - needs review/force)
346
+ update_outdated_files
347
+ echo ""
348
+
349
+ # Update metadata
350
+ update_lock_file
351
+ update_upgrade_history
352
+ echo ""
353
+
354
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
355
+ echo -e "${CYAN}Upgrade Complete${NC}"
356
+ echo -e "${CYAN}══════════════════════════════════════════════════${NC}"
357
+ echo ""
358
+ echo -e "${GREEN}Foundation upgraded to version:${NC} $FOUNDATION_VERSION"
359
+ echo ""
360
+ echo -e "Next steps:"
361
+ echo " 1. Review changes"
362
+ echo " 2. Run: ./scripts/validate_project_setup.sh $PROJECT_ROOT"
363
+ echo " 3. Run: npm test (or your test command)"
364
+ echo " 4. Commit changes"
365
+ echo ""