@hybridlabor-api/aos 4.8.0 → 4.10.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 (186) hide show
  1. package/.agents/{agents.md → AGENTS.md} +3 -1
  2. package/.agents/nodes.json +3 -1
  3. package/.agents/vendor-manifest.json +23 -1
  4. package/.claude/agents/godmode-media-eventtech.md +1 -1
  5. package/.claude/hooks/conventional-commits.mjs +125 -0
  6. package/.claude/hooks/env-file-protection.mjs +105 -0
  7. package/.claude/hooks/go-gate.mjs +101 -81
  8. package/.claude/hooks/memb-inject.mjs +29 -1
  9. package/.claude/settings.json +13 -0
  10. package/.claude/workflows/startcycle-dispatch.mjs +23 -1
  11. package/.opencode/agents/godmode-media-eventtech.md +1 -1
  12. package/.opencode/plugins/bdb-aos.js +31 -4
  13. package/CLAUDE.md +0 -571
  14. package/README.de.md +1 -1
  15. package/README.md +1 -1
  16. package/README.pt.md +1 -1
  17. package/THIRD_PARTY_NOTICES.md +126 -0
  18. package/bin/aos-doctor.mjs +1 -1
  19. package/docs/skills_table.md +1 -1
  20. package/installer.js +187 -55
  21. package/package.json +7 -3
  22. package/packages/aos-cli/README.md +80 -0
  23. package/packages/aos-cli/bin/aos-cli.mjs +134 -0
  24. package/packages/aos-cli/core-skills.json +12 -0
  25. package/packages/aos-cli/extensions/aos.ts +321 -0
  26. package/packages/aos-cli/package-lock.json +1923 -0
  27. package/packages/aos-cli/package.json +29 -0
  28. package/packages/aos-cli/scripts/check-theme.mjs +63 -0
  29. package/packages/aos-cli/themes/aos.json +97 -0
  30. package/scripts/build-plugin-manifest.mjs +131 -0
  31. package/scripts/validate-skills.mjs +81 -6
  32. package/skills/basic/ao-orchestrator/SKILL.md +116 -0
  33. package/skills/basic/bdb-eventagency-skill/SKILL.md +252 -0
  34. package/skills/basic/bdb-shipping-skill/SKILL.md +161 -0
  35. package/skills/basic/godmode-eventtech/SKILL.md +4 -1
  36. package/skills/global_config/agenttrail/SKILL.md +6 -1
  37. package/skills/global_config/aos-project-init/SKILL.md +2 -0
  38. package/skills/global_config/aos-project-init/assets/AGENTS.template.md +1 -1
  39. package/skills/global_config/aos-project-init/scripts/aos-project-doctor.mjs +1 -1
  40. package/skills/global_config/aos-setup/SKILL.md +1 -1
  41. package/skills/global_config/aos-setup/scripts/aos-doctor.mjs +1 -1
  42. package/skills/global_config/ask-tim/SKILL.md +7 -7
  43. package/skills/global_config/bash-script-generator/SKILL.md +201 -0
  44. package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
  45. package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
  46. package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
  47. package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
  48. package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
  49. package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
  50. package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
  51. package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
  52. package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
  53. package/skills/global_config/bash-script-validator/SKILL.md +249 -0
  54. package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
  55. package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
  56. package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
  57. package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
  58. package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
  59. package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
  60. package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
  61. package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
  62. package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
  63. package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
  64. package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
  65. package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
  66. package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
  67. package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
  68. package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
  69. package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
  70. package/skills/global_config/ci-pipeline/SKILL.md +135 -0
  71. package/skills/global_config/deja-memory/SKILL.md +3 -1
  72. package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
  73. package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
  74. package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
  75. package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
  76. package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
  77. package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
  78. package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
  79. package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
  80. package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
  81. package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
  82. package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
  83. package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
  84. package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
  85. package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
  86. package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
  87. package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
  88. package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
  89. package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
  90. package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
  91. package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
  92. package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
  93. package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
  94. package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
  95. package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
  96. package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
  97. package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
  98. package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
  99. package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
  100. package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
  101. package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
  102. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
  103. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
  104. package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
  105. package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
  106. package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
  107. package/skills/global_config/github-actions-generator/SKILL.md +353 -0
  108. package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
  109. package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
  110. package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
  111. package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
  112. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
  113. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
  114. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
  115. package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
  116. package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
  117. package/skills/global_config/github-actions-generator/examples/README.md +147 -0
  118. package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
  119. package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
  120. package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
  121. package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
  122. package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
  123. package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
  124. package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
  125. package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
  126. package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
  127. package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
  128. package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
  129. package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
  130. package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
  131. package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
  132. package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
  133. package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
  134. package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
  135. package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
  136. package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
  137. package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
  138. package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
  139. package/skills/global_config/github-actions-templates/SKILL.md +7 -0
  140. package/skills/global_config/github-actions-validator/SKILL.md +576 -0
  141. package/skills/global_config/github-actions-validator/examples/README.md +88 -0
  142. package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
  143. package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
  144. package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
  145. package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
  146. package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
  147. package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
  148. package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
  149. package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
  150. package/skills/global_config/github-actions-validator/references/runners.md +317 -0
  151. package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
  152. package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
  153. package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
  154. package/skills/global_config/makefile-generator/SKILL.md +614 -0
  155. package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
  156. package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
  157. package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
  158. package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
  159. package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
  160. package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
  161. package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
  162. package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
  163. package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
  164. package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
  165. package/skills/global_config/makefile-validator/SKILL.md +244 -0
  166. package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
  167. package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
  168. package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
  169. package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
  170. package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
  171. package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
  172. package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
  173. package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
  174. package/skills/global_config/plan-canvas/SKILL.md +9 -2
  175. package/skills/global_config/plan-canvas/scripts/lib/plan-canvas/ui.js +10 -2
  176. package/skills/global_config/plan-canvas/scripts/plan-canvas.js +1 -1
  177. package/skills/global_config/read-the-damn-docs/SKILL.md +175 -0
  178. package/skills/global_config/requesting-code-review/SKILL.md +98 -0
  179. package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
  180. package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
  181. package/skills/global_config/verification-before-completion/SKILL.md +123 -0
  182. package/skills/global_config/writing-plans/SKILL.md +126 -46
  183. package/skills/global_config/writing-plans-legacy/SKILL.md +152 -0
  184. package/.claude/CLAUDE.md +0 -12
  185. package/mcps/RhinoMCP/docs/content/docs/getting-started/gemini.md +0 -61
  186. /package/{GEMINI.md → RULES.md} +0 -0
@@ -0,0 +1,539 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # add_standard_targets.sh
4
+ # Description: Add standard GNU targets to an existing Makefile
5
+ # Usage: bash add_standard_targets.sh [MAKEFILE] [TARGETS...]
6
+ #
7
+ # This script adds missing standard GNU Makefile targets to an existing Makefile.
8
+ # It will not overwrite existing targets.
9
+ #
10
+
11
+ set -euo pipefail
12
+
13
+ # Script metadata
14
+ readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
15
+ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
+ readonly -a ALL_TARGETS=(all install uninstall clean distclean test check help dist)
17
+
18
+ # Colors for output
19
+ if [[ -t 1 ]]; then
20
+ readonly RED='\033[0;31m'
21
+ readonly GREEN='\033[0;32m'
22
+ readonly YELLOW='\033[1;33m'
23
+ readonly BLUE='\033[0;34m'
24
+ readonly NC='\033[0m' # No Color
25
+ else
26
+ readonly RED=''
27
+ readonly GREEN=''
28
+ readonly YELLOW=''
29
+ readonly BLUE=''
30
+ readonly NC=''
31
+ fi
32
+
33
+ # Print functions
34
+ print_error() {
35
+ echo -e "${RED}ERROR:${NC} $*" >&2
36
+ }
37
+
38
+ print_success() {
39
+ echo -e "${GREEN}SUCCESS:${NC} $*"
40
+ }
41
+
42
+ print_info() {
43
+ echo -e "${YELLOW}INFO:${NC} $*"
44
+ }
45
+
46
+ print_added() {
47
+ echo -e "${GREEN}+${NC} Added target: ${BLUE}$1${NC}"
48
+ }
49
+
50
+ print_skipped() {
51
+ echo -e "${YELLOW}-${NC} Skipped (exists): ${BLUE}$1${NC}"
52
+ }
53
+
54
+ # Usage information
55
+ usage() {
56
+ cat << EOF
57
+ Usage: ${SCRIPT_NAME} [OPTIONS] [MAKEFILE] [TARGETS...]
58
+ ${SCRIPT_NAME} [OPTIONS] [TARGETS...]
59
+ ${SCRIPT_NAME} [OPTIONS] --file MAKEFILE [TARGETS...]
60
+ ${SCRIPT_NAME} [OPTIONS] [MAKEFILE] --targets TARGET [TARGET...]
61
+ ${SCRIPT_NAME} [OPTIONS] --file MAKEFILE --targets TARGET [TARGET...]
62
+
63
+ Add standard GNU targets to an existing Makefile.
64
+
65
+ Arguments:
66
+ MAKEFILE Path to Makefile (default: Makefile)
67
+ TARGETS Targets to add (default: all standard targets)
68
+
69
+ Available Targets:
70
+ all Build all targets (default target)
71
+ install Install built files to PREFIX
72
+ uninstall Remove installed files
73
+ clean Remove built files
74
+ distclean Remove all generated files
75
+ test Run tests
76
+ check Alias for test
77
+ help Show available targets
78
+ dist Create distribution tarball
79
+
80
+ Options:
81
+ -h, --help Show this help message
82
+ -l, --list List available targets
83
+ -n, --dry-run Show what would be added without modifying
84
+ --file PATH Explicit Makefile path
85
+ --targets ... Explicit target mode (consume target names)
86
+
87
+ Examples:
88
+ ${SCRIPT_NAME} # Add all missing targets to ./Makefile
89
+ ${SCRIPT_NAME} build.mk # Add all targets to build.mk
90
+ ${SCRIPT_NAME} Makefile clean test # Add only clean and test targets
91
+ ${SCRIPT_NAME} clean test # Add clean and test to ./Makefile
92
+ ${SCRIPT_NAME} --file custom.mk test # Add test target to custom.mk
93
+ ${SCRIPT_NAME} --targets clean test # Force target-mode on ./Makefile
94
+ ${SCRIPT_NAME} -n Makefile install # Preview install target addition
95
+
96
+ EOF
97
+ }
98
+
99
+ # List available targets
100
+ list_targets() {
101
+ cat << EOF
102
+ Available standard GNU targets:
103
+
104
+ all - Build all targets (default target)
105
+ install - Install built files to PREFIX
106
+ uninstall - Remove installed files from PREFIX
107
+ clean - Remove built files (keep configuration)
108
+ distclean - Remove all generated files
109
+ test - Run tests
110
+ check - Alias for test (GNU convention)
111
+ help - Show available targets and usage
112
+ dist - Create distribution tarball
113
+
114
+ EOF
115
+ }
116
+
117
+ # Check if a target name is part of the standard set
118
+ is_known_target() {
119
+ local candidate="$1"
120
+ local target
121
+ for target in "${ALL_TARGETS[@]}"; do
122
+ if [[ "$target" == "$candidate" ]]; then
123
+ return 0
124
+ fi
125
+ done
126
+ return 1
127
+ }
128
+
129
+ # Check if target exists in Makefile
130
+ target_exists() {
131
+ local target="$1"
132
+ local makefile="$2"
133
+ # Match target at beginning of line, followed by : (not ::)
134
+ grep -qE "^${target}[[:space:]]*:" "$makefile" 2>/dev/null
135
+ }
136
+
137
+ # Generate target code
138
+ generate_target() {
139
+ local target="$1"
140
+
141
+ case "$target" in
142
+ all)
143
+ cat << 'EOF'
144
+
145
+ ## Build all targets (default)
146
+ .PHONY: all
147
+ all: $(TARGET)
148
+ EOF
149
+ ;;
150
+ install)
151
+ cat << 'EOF'
152
+
153
+ ## Install built files to PREFIX
154
+ .PHONY: install
155
+ install: all
156
+ $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
157
+ $(INSTALL) -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/
158
+ EOF
159
+ ;;
160
+ uninstall)
161
+ cat << 'EOF'
162
+
163
+ ## Remove installed files
164
+ .PHONY: uninstall
165
+ uninstall:
166
+ $(RM) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
167
+ EOF
168
+ ;;
169
+ clean)
170
+ cat << 'EOF'
171
+
172
+ ## Remove built files
173
+ .PHONY: clean
174
+ clean:
175
+ $(RM) -r $(BUILDDIR)
176
+ $(RM) $(TARGET)
177
+ $(RM) *.o *.d
178
+ EOF
179
+ ;;
180
+ distclean)
181
+ cat << 'EOF'
182
+
183
+ ## Remove all generated files (including configuration)
184
+ .PHONY: distclean
185
+ distclean: clean
186
+ $(RM) config.h config.log config.status
187
+ $(RM) -r autom4te.cache/
188
+ EOF
189
+ ;;
190
+ test)
191
+ cat << 'EOF'
192
+
193
+ ## Run tests
194
+ .PHONY: test
195
+ test:
196
+ @echo "Running tests..."
197
+ # Add test commands here
198
+ # Examples:
199
+ # ./run_tests.sh
200
+ # python -m pytest
201
+ # go test ./...
202
+ EOF
203
+ ;;
204
+ check)
205
+ cat << 'EOF'
206
+
207
+ ## Alias for test (GNU convention)
208
+ .PHONY: check
209
+ check: test
210
+ EOF
211
+ ;;
212
+ help)
213
+ cat << 'EOF'
214
+
215
+ ## Show available targets
216
+ .PHONY: help
217
+ help:
218
+ @echo "$(PROJECT) - Build System"
219
+ @echo ""
220
+ @echo "Available targets:"
221
+ @sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed 's/^/ /'
222
+ @echo ""
223
+ @echo "Variables:"
224
+ @echo " PREFIX=$(PREFIX)"
225
+ @echo " CC=$(CC)"
226
+ @echo ""
227
+ @echo "Examples:"
228
+ @echo " make # Build the project"
229
+ @echo " make install # Install to PREFIX"
230
+ @echo " make clean # Remove built files"
231
+ EOF
232
+ ;;
233
+ dist)
234
+ cat << 'EOF'
235
+
236
+ ## Create distribution tarball
237
+ .PHONY: dist
238
+ dist:
239
+ @mkdir -p dist
240
+ tar -czf dist/$(PROJECT)-$(VERSION).tar.gz \
241
+ --transform 's,^,$(PROJECT)-$(VERSION)/,' \
242
+ --exclude='.git*' \
243
+ --exclude='*.o' \
244
+ --exclude='$(BUILDDIR)' \
245
+ .
246
+ EOF
247
+ ;;
248
+ *)
249
+ print_error "Unknown target: $target"
250
+ return 1
251
+ ;;
252
+ esac
253
+ }
254
+
255
+ # Add required variables if missing
256
+ add_missing_variables() {
257
+ local makefile="$1"
258
+ local added=0
259
+ local vars_to_add=""
260
+
261
+ # Check for essential variables
262
+ if ! grep -qE '^(PROJECT|TARGET)\s*[:?]?=' "$makefile"; then
263
+ vars_to_add+="
264
+ # Project configuration
265
+ PROJECT := myproject
266
+ TARGET := \$(PROJECT)
267
+ "
268
+ added=1
269
+ fi
270
+
271
+ if ! grep -qE '^PREFIX\s*\?=' "$makefile"; then
272
+ vars_to_add+="
273
+ # Installation prefix
274
+ PREFIX ?= /usr/local
275
+ "
276
+ added=1
277
+ fi
278
+
279
+ if ! grep -qE '^INSTALL\s*\?=' "$makefile"; then
280
+ vars_to_add+="
281
+ # Install command
282
+ INSTALL ?= install
283
+ "
284
+ added=1
285
+ fi
286
+
287
+ if ! grep -qE '^RM\s*\?=' "$makefile"; then
288
+ vars_to_add+="
289
+ # Remove command
290
+ RM ?= rm -f
291
+ "
292
+ added=1
293
+ fi
294
+
295
+ if ! grep -qE '^BUILDDIR\s*[:?]?=' "$makefile"; then
296
+ vars_to_add+="
297
+ # Build directory
298
+ BUILDDIR := build
299
+ "
300
+ added=1
301
+ fi
302
+
303
+ if ! grep -qE '^VERSION\s*[:?]?=' "$makefile"; then
304
+ vars_to_add+="
305
+ # Project version
306
+ VERSION := 1.0.0
307
+ "
308
+ added=1
309
+ fi
310
+
311
+ if [[ $added -eq 1 ]]; then
312
+ # Prepend variables to the file (after any header comments)
313
+ local header=""
314
+ local content=""
315
+
316
+ # Extract header comments (lines starting with #)
317
+ while IFS= read -r line; do
318
+ if [[ "$line" =~ ^# ]] || [[ -z "$line" ]]; then
319
+ header+="$line"$'\n'
320
+ else
321
+ break
322
+ fi
323
+ done < "$makefile"
324
+
325
+ # Get the rest of the file
326
+ content=$(tail -n +$(($(echo -n "$header" | grep -c $'\n') + 1)) "$makefile" 2>/dev/null || cat "$makefile")
327
+
328
+ # Reconstruct file
329
+ {
330
+ echo -n "$header"
331
+ echo "# ============================================"
332
+ echo "# Added by add_standard_targets.sh"
333
+ echo "# ============================================"
334
+ echo "$vars_to_add"
335
+ echo "$content"
336
+ } > "${makefile}.tmp"
337
+ mv "${makefile}.tmp" "$makefile"
338
+
339
+ print_info "Added missing variable definitions"
340
+ fi
341
+ }
342
+
343
+ # Main function
344
+ main() {
345
+ local dry_run=0
346
+ local makefile_path="Makefile"
347
+ local explicit_file=0
348
+ local explicit_targets=0
349
+ local -a targets=()
350
+ local -a positional=()
351
+
352
+ # Parse options and positional args.
353
+ while [[ $# -gt 0 ]]; do
354
+ case "$1" in
355
+ -h|--help)
356
+ usage
357
+ exit 0
358
+ ;;
359
+ -l|--list)
360
+ list_targets
361
+ exit 0
362
+ ;;
363
+ -n|--dry-run)
364
+ dry_run=1
365
+ shift
366
+ ;;
367
+ --file)
368
+ if [[ $# -lt 2 ]]; then
369
+ print_error "--file requires a path argument"
370
+ exit 1
371
+ fi
372
+ makefile_path="$2"
373
+ explicit_file=1
374
+ shift 2
375
+ ;;
376
+ --targets)
377
+ explicit_targets=1
378
+ shift
379
+ while [[ $# -gt 0 ]]; do
380
+ case "$1" in
381
+ --|--file|--targets|-h|--help|-l|--list|-n|--dry-run)
382
+ break
383
+ ;;
384
+ -*)
385
+ print_error "Unknown option: $1"
386
+ usage
387
+ exit 1
388
+ ;;
389
+ *)
390
+ targets+=("$1")
391
+ shift
392
+ ;;
393
+ esac
394
+ done
395
+ ;;
396
+ --)
397
+ shift
398
+ while [[ $# -gt 0 ]]; do
399
+ positional+=("$1")
400
+ shift
401
+ done
402
+ ;;
403
+ -*)
404
+ print_error "Unknown option: $1"
405
+ usage
406
+ exit 1
407
+ ;;
408
+ *)
409
+ positional+=("$1")
410
+ shift
411
+ ;;
412
+ esac
413
+ done
414
+
415
+ # Resolve positional args with backward compatibility for unambiguous usage.
416
+ if [[ ${#positional[@]} -gt 0 ]]; then
417
+ if [[ $explicit_targets -eq 1 ]]; then
418
+ if [[ $explicit_file -eq 1 ]]; then
419
+ print_error "Unexpected positional args with --file and --targets"
420
+ print_error "Use: ${SCRIPT_NAME} --file <path> --targets <target...>"
421
+ exit 1
422
+ fi
423
+ if [[ ${#positional[@]} -gt 1 ]]; then
424
+ print_error "Too many positional args with --targets"
425
+ print_error "Use: ${SCRIPT_NAME} [--file <path>] --targets <target...>"
426
+ exit 1
427
+ fi
428
+ makefile_path="${positional[0]}"
429
+ explicit_file=1
430
+ elif [[ $explicit_file -eq 1 ]]; then
431
+ targets+=("${positional[@]}")
432
+ else
433
+ if is_known_target "${positional[0]}"; then
434
+ if [[ -e "${positional[0]}" ]]; then
435
+ print_error "Ambiguous input '${positional[0]}': matches a target and existing path."
436
+ print_error "Use --file <path> or --targets <target...> explicitly."
437
+ exit 2
438
+ fi
439
+ targets=("${positional[@]}")
440
+ else
441
+ makefile_path="${positional[0]}"
442
+ if [[ ${#positional[@]} -gt 1 ]]; then
443
+ targets=("${positional[@]:1}")
444
+ fi
445
+ fi
446
+ fi
447
+ fi
448
+
449
+ if [[ $explicit_targets -eq 1 ]] && [[ ${#targets[@]} -eq 0 ]]; then
450
+ print_error "--targets requires at least one target name"
451
+ exit 1
452
+ fi
453
+
454
+ # Default target set when none explicitly requested
455
+ if [[ ${#targets[@]} -eq 0 ]]; then
456
+ targets=("${ALL_TARGETS[@]}")
457
+ fi
458
+
459
+ # Validate requested target names before modifying files
460
+ local target
461
+ for target in "${targets[@]}"; do
462
+ if ! is_known_target "$target"; then
463
+ print_error "Unknown target: $target"
464
+ echo ""
465
+ list_targets
466
+ exit 1
467
+ fi
468
+ done
469
+
470
+ # Check if Makefile exists
471
+ if [[ ! -f "$makefile_path" ]]; then
472
+ print_error "Makefile not found: $makefile_path"
473
+ exit 1
474
+ fi
475
+
476
+ print_info "Processing: $makefile_path"
477
+ echo ""
478
+
479
+ # Track what we'll add
480
+ local targets_added=0
481
+ local targets_skipped=0
482
+ local content_to_add=""
483
+ local -a added_targets=()
484
+
485
+ # Check each target
486
+ for target in "${targets[@]}"; do
487
+ if target_exists "$target" "$makefile_path"; then
488
+ print_skipped "$target"
489
+ targets_skipped=$((targets_skipped + 1))
490
+ continue
491
+ fi
492
+
493
+ if [[ $dry_run -eq 1 ]]; then
494
+ echo -e "${GREEN}+${NC} Would add: ${BLUE}$target${NC}"
495
+ else
496
+ content_to_add+="$(generate_target "$target")"
497
+ added_targets+=("$target")
498
+ fi
499
+ targets_added=$((targets_added + 1))
500
+ done
501
+
502
+ echo ""
503
+
504
+ # Apply changes if not dry run
505
+ if [[ $dry_run -eq 0 ]] && [[ $targets_added -gt 0 ]]; then
506
+ # Add missing variables first
507
+ add_missing_variables "$makefile_path"
508
+
509
+ # Append targets to Makefile
510
+ echo "$content_to_add" >> "$makefile_path"
511
+
512
+ # Report results
513
+ for target in "${added_targets[@]}"; do
514
+ print_added "$target"
515
+ done
516
+
517
+ print_success "Added $targets_added target(s) to $makefile_path"
518
+ elif [[ $dry_run -eq 1 ]]; then
519
+ print_info "Dry run - no changes made"
520
+ echo "Would add $targets_added target(s), skip $targets_skipped existing target(s)"
521
+ else
522
+ print_info "No targets to add (all requested targets already exist)"
523
+ fi
524
+
525
+ # Summary
526
+ echo ""
527
+ echo "Summary:"
528
+ echo " Targets added: $targets_added"
529
+ echo " Targets skipped: $targets_skipped"
530
+
531
+ if [[ $targets_added -gt 0 ]] && [[ $dry_run -eq 0 ]]; then
532
+ echo ""
533
+ print_info "Run 'make help' to see available targets"
534
+ print_info "Run 'make -n <target>' to preview what a target does"
535
+ fi
536
+ }
537
+
538
+ # Run main function
539
+ main "$@"