@prmichaelsen/remember-mcp 3.0.0 → 3.13.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 (208) hide show
  1. package/AGENT.md +296 -250
  2. package/CHANGELOG.md +358 -0
  3. package/README.md +68 -45
  4. package/agent/commands/acp.clarification-create.md +382 -0
  5. package/agent/commands/acp.project-info.md +309 -0
  6. package/agent/commands/acp.project-remove.md +379 -0
  7. package/agent/commands/acp.project-update.md +296 -0
  8. package/agent/commands/acp.task-create.md +17 -9
  9. package/agent/commands/git.commit.md +13 -1
  10. package/agent/design/comment-memory-type.md +2 -2
  11. package/agent/design/local.collaborative-memory-sync.md +265 -0
  12. package/agent/design/local.content-flags.md +210 -0
  13. package/agent/design/local.ghost-persona-system.md +273 -0
  14. package/agent/design/local.group-acl-integration.md +338 -0
  15. package/agent/design/local.memory-acl-schema.md +352 -0
  16. package/agent/design/local.memory-collection-pattern-v2.md +348 -0
  17. package/agent/design/local.moderation-and-space-config.md +257 -0
  18. package/agent/design/local.v2-api-reference.md +621 -0
  19. package/agent/design/local.v2-migration-guide.md +191 -0
  20. package/agent/design/local.v2-usage-examples.md +265 -0
  21. package/agent/design/permissions-storage-architecture.md +11 -3
  22. package/agent/design/trust-escalation-prevention.md +9 -2
  23. package/agent/design/trust-system-implementation.md +12 -3
  24. package/agent/milestones/milestone-14-memory-collection-v2.md +182 -0
  25. package/agent/milestones/milestone-15-moderation-space-config.md +126 -0
  26. package/agent/progress.yaml +628 -49
  27. package/agent/scripts/acp.common.sh +2 -0
  28. package/agent/scripts/acp.install.sh +11 -1
  29. package/agent/scripts/acp.package-install-optimized.sh +454 -0
  30. package/agent/scripts/acp.package-install.sh +247 -300
  31. package/agent/scripts/acp.project-info.sh +218 -0
  32. package/agent/scripts/acp.project-remove.sh +302 -0
  33. package/agent/scripts/acp.project-update.sh +296 -0
  34. package/agent/scripts/acp.yaml-parser.sh +128 -10
  35. package/agent/tasks/milestone-14-memory-collection-v2/task-165-core-infrastructure-setup.md +171 -0
  36. package/agent/tasks/milestone-14-memory-collection-v2/task-166-update-remember-publish.md +191 -0
  37. package/agent/tasks/milestone-14-memory-collection-v2/task-167-update-remember-retract.md +186 -0
  38. package/agent/tasks/milestone-14-memory-collection-v2/task-168-implement-remember-revise.md +184 -0
  39. package/agent/tasks/milestone-14-memory-collection-v2/task-169-update-remember-search-space.md +179 -0
  40. package/agent/tasks/milestone-14-memory-collection-v2/task-170-update-remember-create-update.md +139 -0
  41. package/agent/tasks/milestone-14-memory-collection-v2/task-172-performance-testing-optimization.md +161 -0
  42. package/agent/tasks/milestone-14-memory-collection-v2/task-173-documentation-examples.md +258 -0
  43. package/agent/tasks/milestone-15-moderation-space-config/task-174-add-moderation-schema-fields.md +57 -0
  44. package/agent/tasks/milestone-15-moderation-space-config/task-175-create-space-config-service.md +64 -0
  45. package/agent/tasks/milestone-15-moderation-space-config/task-176-wire-moderation-publish-flow.md +45 -0
  46. package/agent/tasks/milestone-15-moderation-space-config/task-177-add-moderation-search-filters.md +70 -0
  47. package/agent/tasks/milestone-15-moderation-space-config/task-178-create-remember-moderate-tool.md +69 -0
  48. package/agent/tasks/milestone-15-moderation-space-config/task-179-documentation-integration-tests.md +58 -0
  49. package/agent/tasks/milestone-16-ghost-system/task-187-ghost-config-firestore.md +41 -0
  50. package/agent/tasks/milestone-16-ghost-system/task-188-trust-filter-integration.md +44 -0
  51. package/agent/tasks/milestone-16-ghost-system/task-189-ghost-memory-filtering.md +43 -0
  52. package/agent/tasks/milestone-16-ghost-system/task-190-ghost-config-tools.md +45 -0
  53. package/agent/tasks/milestone-16-ghost-system/task-191-escalation-firestore.md +38 -0
  54. package/agent/tasks/milestone-16-ghost-system/task-192-documentation-verification.md +39 -0
  55. package/agent/tasks/milestone-7-trust-permissions/task-180-access-result-permission-types.md +69 -0
  56. package/agent/tasks/milestone-7-trust-permissions/task-181-firestore-permissions-access-logs.md +56 -0
  57. package/agent/tasks/milestone-7-trust-permissions/task-182-trust-enforcement-service.md +68 -0
  58. package/agent/tasks/milestone-7-trust-permissions/task-183-access-control-service.md +70 -0
  59. package/agent/tasks/milestone-7-trust-permissions/task-184-permission-tools.md +79 -0
  60. package/agent/tasks/milestone-7-trust-permissions/task-185-wire-trust-into-search-query.md +55 -0
  61. package/agent/tasks/milestone-7-trust-permissions/task-186-documentation-verification.md +56 -0
  62. package/agent/tasks/task-76-fix-indexnullstate-schema-bug.md +197 -0
  63. package/dist/collections/composite-ids.d.ts +106 -0
  64. package/dist/collections/core-infrastructure.spec.d.ts +11 -0
  65. package/dist/collections/dot-notation.d.ts +106 -0
  66. package/dist/collections/tracking-arrays.d.ts +176 -0
  67. package/dist/constants/content-types.d.ts +1 -0
  68. package/dist/schema/v2-collections-comments.spec.d.ts +8 -0
  69. package/dist/schema/v2-collections.d.ts +210 -0
  70. package/dist/server-factory.d.ts +15 -0
  71. package/dist/server-factory.js +2798 -1029
  72. package/dist/server.js +2526 -1012
  73. package/dist/services/access-control.d.ts +103 -0
  74. package/dist/services/access-control.spec.d.ts +2 -0
  75. package/dist/services/credentials-provider.d.ts +24 -0
  76. package/dist/services/credentials-provider.spec.d.ts +2 -0
  77. package/dist/services/escalation.service.d.ts +22 -0
  78. package/dist/services/escalation.service.spec.d.ts +2 -0
  79. package/dist/services/ghost-config.service.d.ts +55 -0
  80. package/dist/services/ghost-config.service.spec.d.ts +2 -0
  81. package/dist/services/space-config.service.d.ts +23 -0
  82. package/dist/services/space-config.service.spec.d.ts +2 -0
  83. package/dist/services/trust-enforcement.d.ts +83 -0
  84. package/dist/services/trust-enforcement.spec.d.ts +2 -0
  85. package/dist/services/trust-validator.d.ts +43 -0
  86. package/dist/services/trust-validator.spec.d.ts +2 -0
  87. package/dist/tools/confirm-publish-moderation.spec.d.ts +8 -0
  88. package/dist/tools/confirm.d.ts +8 -1
  89. package/dist/tools/create-memory.d.ts +2 -1
  90. package/dist/tools/create-memory.spec.d.ts +10 -0
  91. package/dist/tools/create-relationship.d.ts +2 -1
  92. package/dist/tools/delete-memory.d.ts +2 -1
  93. package/dist/tools/delete-relationship.d.ts +2 -1
  94. package/dist/tools/deny.d.ts +2 -1
  95. package/dist/tools/find-similar.d.ts +2 -1
  96. package/dist/tools/get-preferences.d.ts +2 -1
  97. package/dist/tools/ghost-config.d.ts +27 -0
  98. package/dist/tools/ghost-config.spec.d.ts +2 -0
  99. package/dist/tools/moderate.d.ts +20 -0
  100. package/dist/tools/moderate.spec.d.ts +5 -0
  101. package/dist/tools/publish.d.ts +11 -3
  102. package/dist/tools/query-memory.d.ts +3 -1
  103. package/dist/tools/query-space.d.ts +4 -1
  104. package/dist/tools/retract.d.ts +29 -0
  105. package/dist/tools/revise.d.ts +45 -0
  106. package/dist/tools/revise.spec.d.ts +8 -0
  107. package/dist/tools/search-memory.d.ts +2 -1
  108. package/dist/tools/search-relationship.d.ts +2 -1
  109. package/dist/tools/search-space.d.ts +25 -5
  110. package/dist/tools/search-space.spec.d.ts +9 -0
  111. package/dist/tools/set-preference.d.ts +2 -1
  112. package/dist/tools/update-memory.d.ts +2 -1
  113. package/dist/tools/update-relationship.d.ts +2 -1
  114. package/dist/types/access-result.d.ts +48 -0
  115. package/dist/types/access-result.spec.d.ts +2 -0
  116. package/dist/types/auth.d.ts +46 -0
  117. package/dist/types/ghost-config.d.ts +36 -0
  118. package/dist/types/memory.d.ts +3 -1
  119. package/dist/types/preferences.d.ts +1 -1
  120. package/dist/utils/auth-helpers.d.ts +14 -0
  121. package/dist/utils/auth-helpers.spec.d.ts +2 -0
  122. package/dist/utils/test-data-generator.d.ts +124 -0
  123. package/dist/utils/test-data-generator.spec.d.ts +12 -0
  124. package/dist/v2-performance.e2e.d.ts +17 -0
  125. package/dist/v2-smoke.e2e.d.ts +14 -0
  126. package/dist/weaviate/client.d.ts +5 -8
  127. package/dist/weaviate/space-schema.d.ts +2 -2
  128. package/docs/performance/v2-benchmarks.md +80 -0
  129. package/jest.e2e.config.js +14 -3
  130. package/package.json +1 -1
  131. package/scripts/.collection-recreation-state.yaml +16 -0
  132. package/scripts/.gitkeep +5 -0
  133. package/scripts/README-collection-recreation.md +224 -0
  134. package/scripts/README.md +51 -0
  135. package/scripts/backup-collections.ts +543 -0
  136. package/scripts/delete-collection.ts +137 -0
  137. package/scripts/migrate-recreate-collections.ts +578 -0
  138. package/scripts/migrate-v1-to-v2.ts +1094 -0
  139. package/scripts/package-lock.json +1113 -0
  140. package/scripts/package.json +27 -0
  141. package/src/collections/composite-ids.ts +193 -0
  142. package/src/collections/core-infrastructure.spec.ts +353 -0
  143. package/src/collections/dot-notation.ts +212 -0
  144. package/src/collections/tracking-arrays.ts +298 -0
  145. package/src/constants/content-types.ts +20 -0
  146. package/src/schema/v2-collections-comments.spec.ts +141 -0
  147. package/src/schema/v2-collections.ts +433 -0
  148. package/src/server-factory.ts +89 -20
  149. package/src/server.ts +45 -17
  150. package/src/services/access-control.spec.ts +383 -0
  151. package/src/services/access-control.ts +291 -0
  152. package/src/services/credentials-provider.spec.ts +22 -0
  153. package/src/services/credentials-provider.ts +34 -0
  154. package/src/services/escalation.service.spec.ts +183 -0
  155. package/src/services/escalation.service.ts +150 -0
  156. package/src/services/ghost-config.service.spec.ts +339 -0
  157. package/src/services/ghost-config.service.ts +219 -0
  158. package/src/services/space-config.service.spec.ts +102 -0
  159. package/src/services/space-config.service.ts +79 -0
  160. package/src/services/trust-enforcement.spec.ts +309 -0
  161. package/src/services/trust-enforcement.ts +197 -0
  162. package/src/services/trust-validator.spec.ts +108 -0
  163. package/src/services/trust-validator.ts +105 -0
  164. package/src/tools/confirm-publish-moderation.spec.ts +240 -0
  165. package/src/tools/confirm.ts +869 -135
  166. package/src/tools/create-memory.spec.ts +126 -0
  167. package/src/tools/create-memory.ts +20 -27
  168. package/src/tools/create-relationship.ts +17 -8
  169. package/src/tools/delete-memory.ts +13 -6
  170. package/src/tools/delete-relationship.ts +15 -6
  171. package/src/tools/deny.ts +8 -1
  172. package/src/tools/find-similar.ts +21 -8
  173. package/src/tools/get-preferences.ts +10 -1
  174. package/src/tools/ghost-config.spec.ts +180 -0
  175. package/src/tools/ghost-config.ts +230 -0
  176. package/src/tools/moderate.spec.ts +277 -0
  177. package/src/tools/moderate.ts +219 -0
  178. package/src/tools/publish.ts +99 -41
  179. package/src/tools/query-memory.ts +28 -6
  180. package/src/tools/query-space.ts +39 -4
  181. package/src/tools/retract.ts +292 -0
  182. package/src/tools/revise.spec.ts +146 -0
  183. package/src/tools/revise.ts +283 -0
  184. package/src/tools/search-memory.ts +30 -7
  185. package/src/tools/search-relationship.ts +11 -2
  186. package/src/tools/search-space.spec.ts +341 -0
  187. package/src/tools/search-space.ts +323 -99
  188. package/src/tools/set-preference.ts +10 -1
  189. package/src/tools/update-memory.ts +16 -5
  190. package/src/tools/update-relationship.ts +10 -1
  191. package/src/types/access-result.spec.ts +193 -0
  192. package/src/types/access-result.ts +62 -0
  193. package/src/types/auth.ts +52 -0
  194. package/src/types/ghost-config.ts +46 -0
  195. package/src/types/memory.ts +9 -1
  196. package/src/types/preferences.ts +2 -2
  197. package/src/utils/auth-helpers.spec.ts +75 -0
  198. package/src/utils/auth-helpers.ts +25 -0
  199. package/src/utils/test-data-generator.spec.ts +317 -0
  200. package/src/utils/test-data-generator.ts +292 -0
  201. package/src/utils/weaviate-filters.ts +4 -4
  202. package/src/v2-performance.e2e.ts +173 -0
  203. package/src/v2-smoke.e2e.ts +401 -0
  204. package/src/weaviate/client.spec.ts +5 -5
  205. package/src/weaviate/client.ts +51 -36
  206. package/src/weaviate/schema.ts +11 -256
  207. package/src/weaviate/space-schema.spec.ts +24 -24
  208. package/src/weaviate/space-schema.ts +18 -6
@@ -552,6 +552,8 @@ add_package_to_manifest() {
552
552
  print " patterns: []"
553
553
  print " commands: []"
554
554
  print " designs: []"
555
+ print " scripts: []"
556
+ print " files: []"
555
557
  next
556
558
  }
557
559
  { print }
@@ -67,20 +67,29 @@ mkdir -p "$TARGET_DIR/agent/commands"
67
67
  mkdir -p "$TARGET_DIR/agent/scripts"
68
68
  mkdir -p "$TARGET_DIR/agent/schemas"
69
69
  mkdir -p "$TARGET_DIR/agent/reports"
70
+ mkdir -p "$TARGET_DIR/agent/drafts"
71
+ mkdir -p "$TARGET_DIR/agent/clarifications"
72
+ mkdir -p "$TARGET_DIR/agent/feedback"
73
+ mkdir -p "$TARGET_DIR/agent/preferences"
70
74
 
71
75
  # Create .gitkeep files
72
76
  touch "$TARGET_DIR/agent/design/.gitkeep"
73
77
  touch "$TARGET_DIR/agent/milestones/.gitkeep"
74
78
  touch "$TARGET_DIR/agent/patterns/.gitkeep"
75
79
  touch "$TARGET_DIR/agent/tasks/.gitkeep"
80
+ touch "$TARGET_DIR/agent/clarifications/.gitkeep"
76
81
 
77
- # Create agent/.gitignore to exclude reports from version control
82
+ # Create agent/.gitignore to exclude local-only directories from version control
78
83
  cat > "$TARGET_DIR/agent/.gitignore" << 'EOF'
79
84
  # Agent Context Protocol - Local Files
80
85
  # These files are generated locally and should not be committed
81
86
 
82
87
  # Reports directory - generated by @acp.report command
83
88
  reports/
89
+ clarifications/
90
+ feedback/
91
+ drafts/
92
+ preferences/
84
93
  EOF
85
94
 
86
95
  echo "${GREEN}✓${NC} Directory structure created"
@@ -94,6 +103,7 @@ find "$TEMP_DIR/agent/design" -maxdepth 1 -name "*.template.md" -exec cp {} "$TA
94
103
  find "$TEMP_DIR/agent/milestones" -maxdepth 1 -name "*.template.md" -exec cp {} "$TARGET_DIR/agent/milestones/" \;
95
104
  find "$TEMP_DIR/agent/patterns" -maxdepth 1 -name "*.template.md" -exec cp {} "$TARGET_DIR/agent/patterns/" \;
96
105
  find "$TEMP_DIR/agent/tasks" -maxdepth 1 -name "*.template.md" -exec cp {} "$TARGET_DIR/agent/tasks/" \;
106
+ find "$TEMP_DIR/agent/clarifications" -maxdepth 1 -name "*.template.md" -exec cp {} "$TARGET_DIR/agent/clarifications/" \;
97
107
 
98
108
  # Copy command template
99
109
  cp "$TEMP_DIR/agent/commands/command.template.md" "$TARGET_DIR/agent/commands/"
@@ -0,0 +1,454 @@
1
+ #!/bin/bash
2
+
3
+ # Agent Context Protocol (ACP) Package Install Script - OPTIMIZED VERSION
4
+ # Installs third-party ACP packages with batched operations for 10x+ performance improvement
5
+
6
+ set -e
7
+
8
+ # Source common utilities
9
+ SCRIPT_DIR="$(dirname "$0")"
10
+ . "${SCRIPT_DIR}/acp.common.sh"
11
+ . "${SCRIPT_DIR}/acp.yaml-parser.sh"
12
+
13
+ # Initialize colors
14
+ init_colors
15
+
16
+ # Parse arguments (same as original)
17
+ REPO_URL=""
18
+ INSTALL_PATTERNS=false
19
+ INSTALL_COMMANDS=false
20
+ INSTALL_DESIGNS=false
21
+ PATTERN_FILES=()
22
+ COMMAND_FILES=()
23
+ DESIGN_FILES=()
24
+ LIST_ONLY=false
25
+ GLOBAL_INSTALL=false
26
+ INSTALL_EXPERIMENTAL=false
27
+ SKIP_CONFIRM=false
28
+
29
+ while [[ $# -gt 0 ]]; do
30
+ case $1 in
31
+ --repo)
32
+ REPO_URL="$2"
33
+ shift 2
34
+ ;;
35
+ --global)
36
+ GLOBAL_INSTALL=true
37
+ shift
38
+ ;;
39
+ --experimental)
40
+ INSTALL_EXPERIMENTAL=true
41
+ shift
42
+ ;;
43
+ -y|--yes)
44
+ SKIP_CONFIRM=true
45
+ shift
46
+ ;;
47
+ --patterns)
48
+ INSTALL_PATTERNS=true
49
+ shift
50
+ while [[ $# -gt 0 && ! $1 =~ ^-- ]]; do
51
+ PATTERN_FILES+=("$1")
52
+ shift
53
+ done
54
+ ;;
55
+ --commands)
56
+ INSTALL_COMMANDS=true
57
+ shift
58
+ while [[ $# -gt 0 && ! $1 =~ ^-- ]]; do
59
+ COMMAND_FILES+=("$1")
60
+ shift
61
+ done
62
+ ;;
63
+ --designs)
64
+ INSTALL_DESIGNS=true
65
+ shift
66
+ while [[ $# -gt 0 && ! $1 =~ ^-- ]]; do
67
+ DESIGN_FILES+=("$1")
68
+ shift
69
+ done
70
+ ;;
71
+ --list)
72
+ LIST_ONLY=true
73
+ shift
74
+ ;;
75
+ *)
76
+ echo "${RED}Error: Unknown option: $1${NC}"
77
+ echo "Use --repo to specify repository URL"
78
+ exit 1
79
+ ;;
80
+ esac
81
+ done
82
+
83
+ # Check if repository URL provided
84
+ if [ -z "$REPO_URL" ]; then
85
+ echo "${RED}Error: Repository URL required${NC}"
86
+ echo "Usage: $0 --repo <repository-url> [options]"
87
+ exit 1
88
+ fi
89
+
90
+ # Default: install everything if no selective flags specified
91
+ if [[ "$INSTALL_PATTERNS" == false && "$INSTALL_COMMANDS" == false && "$INSTALL_DESIGNS" == false ]]; then
92
+ INSTALL_PATTERNS=true
93
+ INSTALL_COMMANDS=true
94
+ INSTALL_DESIGNS=true
95
+ fi
96
+
97
+ echo "${BLUE}📦 ACP Package Installer (Optimized)${NC}"
98
+ echo "========================================"
99
+ echo ""
100
+ echo "Repository: $REPO_URL"
101
+ echo ""
102
+
103
+ # Validate URL format
104
+ if [[ ! "$REPO_URL" =~ ^https?:// ]] && [[ ! "$REPO_URL" =~ ^file:// ]] && [[ ! -d "$REPO_URL" ]]; then
105
+ echo "${RED}Error: Invalid repository URL${NC}"
106
+ exit 1
107
+ fi
108
+
109
+ # Create temporary directory
110
+ TEMP_DIR=$(mktemp -d)
111
+ trap "rm -rf $TEMP_DIR" EXIT
112
+
113
+ echo "Cloning repository..."
114
+ if ! git clone --depth 1 "$REPO_URL" "$TEMP_DIR" &>/dev/null; then
115
+ echo "${RED}Error: Failed to clone repository${NC}"
116
+ exit 1
117
+ fi
118
+
119
+ echo "${GREEN}✓${NC} Repository cloned"
120
+ echo ""
121
+
122
+ # Check for agent/ directory
123
+ if [ ! -d "$TEMP_DIR/agent" ]; then
124
+ echo "${RED}Error: No agent/ directory found${NC}"
125
+ exit 1
126
+ fi
127
+
128
+ # Determine installation directory and manifest
129
+ if [ "$GLOBAL_INSTALL" = true ]; then
130
+ INSTALL_BASE_DIR="$HOME/.acp/agent"
131
+ MANIFEST_FILE="$HOME/.acp/agent/manifest.yaml"
132
+ echo "${BLUE}Installing globally to ~/.acp/agent/${NC}"
133
+ echo ""
134
+ init_global_acp || {
135
+ echo "${RED}Error: Failed to initialize global infrastructure${NC}" >&2
136
+ exit 1
137
+ }
138
+ else
139
+ INSTALL_BASE_DIR="./agent"
140
+ MANIFEST_FILE="./agent/manifest.yaml"
141
+ echo "${BLUE}Installing locally to ./agent/${NC}"
142
+ echo ""
143
+ init_manifest
144
+ fi
145
+
146
+ # Parse package metadata
147
+ parse_package_metadata "$TEMP_DIR"
148
+ COMMIT_HASH=$(get_commit_hash "$TEMP_DIR")
149
+ info "Commit: $COMMIT_HASH"
150
+ echo ""
151
+
152
+ # List mode (unchanged)
153
+ if [ "$LIST_ONLY" = true ]; then
154
+ # ... (same as original)
155
+ exit 0
156
+ fi
157
+
158
+ # Validate dependencies
159
+ if [ -f "$TEMP_DIR/package.yaml" ]; then
160
+ if ! validate_project_dependencies "$TEMP_DIR/package.yaml"; then
161
+ echo "${RED}Installation cancelled due to dependency issues${NC}"
162
+ exit 1
163
+ fi
164
+ fi
165
+
166
+ # Directories to install from
167
+ INSTALL_DIRS=()
168
+ [ "$INSTALL_PATTERNS" = true ] && INSTALL_DIRS+=("patterns")
169
+ [ "$INSTALL_COMMANDS" = true ] && INSTALL_DIRS+=("commands")
170
+ [ "$INSTALL_DESIGNS" = true ] && INSTALL_DIRS+=("design")
171
+ [ "$INSTALL_COMMANDS" = true ] && INSTALL_DIRS+=("scripts")
172
+
173
+ # ============================================================================
174
+ # OPTIMIZATION: Collect all files first, then batch process
175
+ # ============================================================================
176
+
177
+ # Arrays to hold all files to install
178
+ declare -A ALL_FILES_TO_INSTALL # Key: dir, Value: space-separated file paths
179
+ declare -A FILE_METADATA # Key: "dir/filename", Value: "version|experimental"
180
+
181
+ INSTALLED_COUNT=0
182
+ SKIPPED_COUNT=0
183
+
184
+ echo "Scanning for installable files..."
185
+ echo ""
186
+
187
+ # Parse package.yaml once for experimental checking
188
+ if [ -f "$TEMP_DIR/package.yaml" ]; then
189
+ yaml_parse "$TEMP_DIR/package.yaml"
190
+ fi
191
+
192
+ # Collect all files to install
193
+ for dir in "${INSTALL_DIRS[@]}"; do
194
+ SOURCE_DIR="$TEMP_DIR/agent/$dir"
195
+
196
+ if [ ! -d "$SOURCE_DIR" ]; then
197
+ continue
198
+ fi
199
+
200
+ # Determine which files to process
201
+ declare -n FILE_LIST
202
+ case "$dir" in
203
+ patterns) FILE_LIST=PATTERN_FILES ;;
204
+ commands) FILE_LIST=COMMAND_FILES ;;
205
+ design) FILE_LIST=DESIGN_FILES ;;
206
+ scripts) FILE_LIST=COMMAND_FILES ;;
207
+ esac
208
+
209
+ # Collect files
210
+ FILES_TO_PROCESS=()
211
+ if [ ${#FILE_LIST[@]} -gt 0 ]; then
212
+ # Selective installation
213
+ for file_name in "${FILE_LIST[@]}"; do
214
+ if [ "$dir" = "scripts" ]; then
215
+ [[ "$file_name" != *.sh ]] && file_name="${file_name}.sh"
216
+ else
217
+ [[ "$file_name" != *.md ]] && file_name="${file_name}.md"
218
+ fi
219
+
220
+ file_path="$SOURCE_DIR/$file_name"
221
+ if [ -f "$file_path" ]; then
222
+ FILES_TO_PROCESS+=("$file_path")
223
+ else
224
+ echo "${YELLOW}⚠${NC} File not found in $dir/: $file_name"
225
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
226
+ fi
227
+ done
228
+ else
229
+ # Install all files
230
+ if [ "$dir" = "scripts" ]; then
231
+ while IFS= read -r file; do
232
+ [ -n "$file" ] && FILES_TO_PROCESS+=("$file")
233
+ done < <(find "$SOURCE_DIR" -maxdepth 1 -name "*.sh" ! -name "*.template.sh" -type f)
234
+ else
235
+ while IFS= read -r file; do
236
+ [ -n "$file" ] && FILES_TO_PROCESS+=("$file")
237
+ done < <(find "$SOURCE_DIR" -maxdepth 1 -name "*.md" ! -name "*.template.md" -type f)
238
+ fi
239
+ fi
240
+
241
+ if [ ${#FILES_TO_PROCESS[@]} -eq 0 ]; then
242
+ unset -n FILE_LIST
243
+ continue
244
+ fi
245
+
246
+ echo "${BLUE}📁 $dir/${NC} (${#FILES_TO_PROCESS[@]} file(s))"
247
+
248
+ # Validate files
249
+ VALID_FILES=()
250
+ for file in "${FILES_TO_PROCESS[@]}"; do
251
+ filename=$(basename "$file")
252
+
253
+ # Validation
254
+ if [ "$dir" = "commands" ]; then
255
+ if [[ "$filename" =~ ^acp\. ]]; then
256
+ echo " ${RED}✗${NC} $filename (reserved namespace 'acp')"
257
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
258
+ continue
259
+ fi
260
+ if ! grep -q "🤖 Agent Directive" "$file"; then
261
+ echo " ${YELLOW}⚠${NC} $filename (missing agent directive - skipping)"
262
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
263
+ continue
264
+ fi
265
+ fi
266
+
267
+ if [ "$dir" = "scripts" ]; then
268
+ if [[ "$filename" =~ ^acp\. ]]; then
269
+ echo " ${RED}✗${NC} $filename (reserved namespace 'acp')"
270
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
271
+ continue
272
+ fi
273
+ fi
274
+
275
+ # Check experimental status
276
+ local is_experimental=""
277
+ if [ -f "$TEMP_DIR/package.yaml" ]; then
278
+ is_experimental=$(grep -A 1000 "^ ${dir}:" "$TEMP_DIR/package.yaml" 2>/dev/null | grep -A 2 "name: ${filename}" | grep "^ *experimental: true" | grep -v "^[[:space:]]*#" | head -1)
279
+ fi
280
+
281
+ if [ -n "$is_experimental" ] && [ "$INSTALL_EXPERIMENTAL" = false ]; then
282
+ echo " ${DIM}⊘${NC} $filename (experimental - use --experimental)"
283
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
284
+ continue
285
+ fi
286
+
287
+ # Get file version
288
+ FILE_VERSION=$(get_file_version "$TEMP_DIR/package.yaml" "$dir" "$filename")
289
+
290
+ # Store metadata
291
+ FILE_METADATA["$dir/$filename"]="$FILE_VERSION|$is_experimental"
292
+
293
+ # Add to valid files
294
+ VALID_FILES+=("$file")
295
+
296
+ if [ -f "$INSTALL_BASE_DIR/$dir/$filename" ]; then
297
+ echo " ${YELLOW}⚠${NC} $filename (will overwrite)"
298
+ else
299
+ echo " ${GREEN}✓${NC} $filename"
300
+ fi
301
+
302
+ INSTALLED_COUNT=$((INSTALLED_COUNT + 1))
303
+ done
304
+
305
+ # Store valid files for this directory
306
+ if [ ${#VALID_FILES[@]} -gt 0 ]; then
307
+ ALL_FILES_TO_INSTALL["$dir"]="${VALID_FILES[*]}"
308
+ fi
309
+
310
+ unset -n FILE_LIST
311
+ echo ""
312
+ done
313
+
314
+ # Exit if nothing to install
315
+ if [ $INSTALLED_COUNT -eq 0 ]; then
316
+ echo "${RED}Error: No valid files to install${NC}"
317
+ [ $SKIPPED_COUNT -gt 0 ] && echo "Skipped $SKIPPED_COUNT file(s)"
318
+ exit 1
319
+ fi
320
+
321
+ # Confirm installation
322
+ echo "Ready to install $INSTALLED_COUNT file(s)"
323
+ [ $SKIPPED_COUNT -gt 0 ] && echo "($SKIPPED_COUNT file(s) will be skipped)"
324
+ echo ""
325
+
326
+ if [ "$SKIP_CONFIRM" = false ]; then
327
+ read -p "Proceed with installation? (y/N) " -n 1 -r
328
+ echo
329
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
330
+ echo "Installation cancelled."
331
+ exit 0
332
+ fi
333
+ else
334
+ echo "Auto-confirming installation (-y flag)"
335
+ fi
336
+
337
+ echo ""
338
+ echo "Installing files..."
339
+
340
+ # ============================================================================
341
+ # OPTIMIZATION: Batch file operations
342
+ # ============================================================================
343
+
344
+ # Add package to manifest once
345
+ add_package_to_manifest "$PACKAGE_NAME" "$REPO_URL" "$PACKAGE_VERSION" "$COMMIT_HASH"
346
+
347
+ # Batch copy all files
348
+ for dir in "${!ALL_FILES_TO_INSTALL[@]}"; do
349
+ mkdir -p "$INSTALL_BASE_DIR/$dir"
350
+
351
+ # Copy all files at once
352
+ for file in ${ALL_FILES_TO_INSTALL[$dir]}; do
353
+ filename=$(basename "$file")
354
+ cp "$file" "$INSTALL_BASE_DIR/$dir/$filename"
355
+
356
+ # Make scripts executable
357
+ if [ "$dir" = "scripts" ]; then
358
+ chmod +x "$INSTALL_BASE_DIR/$dir/$filename"
359
+ fi
360
+ done
361
+ done
362
+
363
+ # ============================================================================
364
+ # OPTIMIZATION: Batch checksum calculation
365
+ # ============================================================================
366
+
367
+ echo " ${BLUE}Calculating checksums...${NC}"
368
+
369
+ # Collect all installed files for batch checksum
370
+ ALL_INSTALLED_FILES=()
371
+ for dir in "${!ALL_FILES_TO_INSTALL[@]}"; do
372
+ for file in ${ALL_FILES_TO_INSTALL[$dir]}; do
373
+ filename=$(basename "$file")
374
+ ALL_INSTALLED_FILES+=("$INSTALL_BASE_DIR/$dir/$filename")
375
+ done
376
+ done
377
+
378
+ # Calculate all checksums in one pass
379
+ declare -A CHECKSUMS
380
+ if [ ${#ALL_INSTALLED_FILES[@]} -gt 0 ]; then
381
+ while IFS= read -r line; do
382
+ checksum=$(echo "$line" | awk '{print $1}')
383
+ filepath=$(echo "$line" | awk '{$1=""; print substr($0,2)}')
384
+ CHECKSUMS["$filepath"]="$checksum"
385
+ done < <(sha256sum "${ALL_INSTALLED_FILES[@]}" 2>/dev/null)
386
+ fi
387
+
388
+ # ============================================================================
389
+ # OPTIMIZATION: Batch manifest update
390
+ # ============================================================================
391
+
392
+ echo " ${BLUE}Updating manifest...${NC}"
393
+
394
+ # Parse manifest once
395
+ yaml_parse "$MANIFEST_FILE"
396
+
397
+ # Add all files to manifest in memory
398
+ timestamp=$(get_timestamp)
399
+ for dir in "${!ALL_FILES_TO_INSTALL[@]}"; do
400
+ for file in ${ALL_FILES_TO_INSTALL[$dir]}; do
401
+ filename=$(basename "$file")
402
+ filepath="$INSTALL_BASE_DIR/$dir/$filename"
403
+
404
+ # Get metadata
405
+ IFS='|' read -r file_version is_experimental <<< "${FILE_METADATA[$dir/$filename]}"
406
+
407
+ # Get checksum
408
+ checksum="${CHECKSUMS[$filepath]:-unknown}"
409
+
410
+ # Append to manifest
411
+ obj_node=$(yaml_array_append_object ".packages.${PACKAGE_NAME}.files.${dir}")
412
+ yaml_object_set "$obj_node" "name" "$filename" >/dev/null
413
+ yaml_object_set "$obj_node" "version" "$file_version" >/dev/null
414
+ yaml_object_set "$obj_node" "installed_at" "$timestamp" >/dev/null
415
+ yaml_object_set "$obj_node" "modified" "false" >/dev/null
416
+ yaml_object_set "$obj_node" "checksum" "sha256:$checksum" >/dev/null
417
+
418
+ if [ -n "$is_experimental" ]; then
419
+ yaml_object_set "$obj_node" "experimental" "true" >/dev/null
420
+ fi
421
+
422
+ if [ "$dir" = "scripts" ]; then
423
+ echo " ${GREEN}✓${NC} Installed $dir/$filename (v$file_version) [executable]"
424
+ else
425
+ echo " ${GREEN}✓${NC} Installed $dir/$filename (v$file_version)"
426
+ fi
427
+ done
428
+ done
429
+
430
+ # Write manifest once at the end
431
+ yaml_write "$MANIFEST_FILE"
432
+
433
+ echo ""
434
+
435
+ # Success message
436
+ if [ "$GLOBAL_INSTALL" = true ]; then
437
+ echo "${GREEN}✅ Package installed globally!${NC}"
438
+ echo ""
439
+ echo "Location: $INSTALL_BASE_DIR"
440
+ echo "Manifest: $MANIFEST_FILE"
441
+ else
442
+ echo "${GREEN}✅ Installation complete!${NC}"
443
+ echo ""
444
+ echo "Installed $INSTALLED_COUNT file(s) from:"
445
+ echo " $REPO_URL"
446
+ echo ""
447
+ echo "Package: $PACKAGE_NAME ($PACKAGE_VERSION)"
448
+ echo "Manifest: agent/manifest.yaml updated"
449
+ fi
450
+
451
+ echo ""
452
+ echo "${YELLOW}⚠️ Security Reminder:${NC}"
453
+ echo "Review installed files before using them."
454
+ echo ""