proagents 1.0.11 → 1.0.13

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.
package/bin/proagents.js CHANGED
File without changes
@@ -103,11 +103,75 @@ export async function selectPlatforms() {
103
103
  return selected.length > 0 ? selected : ['claude']; // Default to Claude if nothing selected
104
104
  }
105
105
 
106
+ // ProAgents section markers
107
+ const PROAGENTS_START = '<!-- PROAGENTS:START -->';
108
+ const PROAGENTS_END = '<!-- PROAGENTS:END -->';
109
+
110
+ /**
111
+ * Wrap ProAgents content with markers
112
+ */
113
+ function wrapWithMarkers(content) {
114
+ return `${PROAGENTS_START}\n${content}\n${PROAGENTS_END}`;
115
+ }
116
+
117
+ /**
118
+ * Extract ProAgents section from content
119
+ */
120
+ function extractProagentsSection(content) {
121
+ const startIdx = content.indexOf(PROAGENTS_START);
122
+ const endIdx = content.indexOf(PROAGENTS_END);
123
+
124
+ if (startIdx !== -1 && endIdx !== -1) {
125
+ return {
126
+ before: content.substring(0, startIdx),
127
+ proagents: content.substring(startIdx, endIdx + PROAGENTS_END.length),
128
+ after: content.substring(endIdx + PROAGENTS_END.length)
129
+ };
130
+ }
131
+ return null;
132
+ }
133
+
134
+ /**
135
+ * Merge ProAgents instructions with existing file content
136
+ * - If file doesn't exist: create with ProAgents content
137
+ * - If file exists without ProAgents section: append ProAgents section
138
+ * - If file exists with ProAgents section: update only ProAgents section
139
+ */
140
+ function mergeAIInstructions(sourcePath, targetPath) {
141
+ const sourceContent = readFileSync(sourcePath, 'utf-8');
142
+ const wrappedSource = wrapWithMarkers(sourceContent);
143
+
144
+ if (!existsSync(targetPath)) {
145
+ // File doesn't exist - create new with wrapped content
146
+ writeFileSync(targetPath, wrappedSource);
147
+ return 'created';
148
+ }
149
+
150
+ const existingContent = readFileSync(targetPath, 'utf-8');
151
+ const sections = extractProagentsSection(existingContent);
152
+
153
+ if (sections) {
154
+ // ProAgents section exists - update it only
155
+ const newContent = sections.before + wrappedSource + sections.after;
156
+ writeFileSync(targetPath, newContent);
157
+ return 'updated';
158
+ } else {
159
+ // No ProAgents section - append to existing content
160
+ const newContent = existingContent.trim() + '\n\n' + wrappedSource + '\n';
161
+ writeFileSync(targetPath, newContent);
162
+ return 'merged';
163
+ }
164
+ }
165
+
106
166
  /**
107
167
  * Copy AI instruction files for selected platforms
168
+ * Merges with existing files instead of replacing them
169
+ * @param {string[]} selectedIds - Platform IDs to copy
170
+ * @param {string} sourceDir - Source directory (proagents folder)
171
+ * @param {string} targetDir - Target directory (project root)
108
172
  */
109
173
  export function copyPlatformFiles(selectedIds, sourceDir, targetDir) {
110
- const results = { created: [], skipped: [], failed: [] };
174
+ const results = { created: [], updated: [], merged: [], failed: [] };
111
175
 
112
176
  for (const id of selectedIds) {
113
177
  const platform = getPlatformById(id);
@@ -130,11 +194,13 @@ export function copyPlatformFiles(selectedIds, sourceDir, targetDir) {
130
194
 
131
195
  try {
132
196
  if (existsSync(sourcePath)) {
133
- if (!existsSync(targetPath)) {
134
- cpSync(sourcePath, targetPath);
197
+ const result = mergeAIInstructions(sourcePath, targetPath);
198
+ if (result === 'created') {
135
199
  results.created.push(platform.name);
136
- } else {
137
- results.skipped.push(platform.name);
200
+ } else if (result === 'updated') {
201
+ results.updated.push(platform.name);
202
+ } else if (result === 'merged') {
203
+ results.merged.push(platform.name);
138
204
  }
139
205
  }
140
206
  } catch (error) {
@@ -285,13 +351,16 @@ export async function aiAddCommand() {
285
351
 
286
352
  // Show results
287
353
  if (results.created.length > 0) {
288
- console.log(chalk.green(`\n✓ Added: ${results.created.join(', ')}`));
354
+ console.log(chalk.green(`\n✓ Created: ${results.created.join(', ')}`));
355
+ }
356
+ if (results.updated.length > 0) {
357
+ console.log(chalk.green(`✓ Updated: ${results.updated.join(', ')}`));
289
358
  }
290
- if (results.skipped.length > 0) {
291
- console.log(chalk.yellow(`⚠️ Already exist: ${results.skipped.join(', ')}`));
359
+ if (results.merged.length > 0) {
360
+ console.log(chalk.green(`✓ Merged with existing: ${results.merged.join(', ')}`));
292
361
  }
293
362
 
294
- console.log(chalk.gray('\nAI instruction files copied to project root.'));
363
+ console.log(chalk.gray('\nAI instruction files added to project root.'));
295
364
  console.log(chalk.gray('Config updated in proagents/proagents.config.yaml\n'));
296
365
  }
297
366