@ghl-ai/aw 0.1.39-beta.16 → 0.1.39-beta.18
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/integrate.mjs +38 -73
- package/package.json +1 -1
package/integrate.mjs
CHANGED
|
@@ -114,12 +114,41 @@ function shouldResetHomeInstructionFile(content, file) {
|
|
|
114
114
|
return legacyMarkers.some(marker => content.includes(marker));
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
function stripLegacyRepoInstructionContent(content, file) {
|
|
118
|
+
const legacyMarkers = file === 'CLAUDE.md'
|
|
119
|
+
? [
|
|
120
|
+
'# CLAUDE.md — ',
|
|
121
|
+
'## Routing Rule (ABSOLUTE)',
|
|
122
|
+
'This supplements the root `AGENTS.md` with Codex-specific guidance.',
|
|
123
|
+
'<!-- BEGIN ECC -->',
|
|
124
|
+
]
|
|
125
|
+
: [
|
|
126
|
+
'# AGENTS.md — ',
|
|
127
|
+
'# ECC for Codex CLI',
|
|
128
|
+
'# AW SDLC Repo Instructions',
|
|
129
|
+
'Use the repo-local AW SDLC files as the source of truth for routing and stage behavior.',
|
|
130
|
+
'## Agent System',
|
|
131
|
+
'<!-- BEGIN ECC -->',
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const startIndexes = legacyMarkers
|
|
135
|
+
.map(marker => content.indexOf(marker))
|
|
136
|
+
.filter(idx => idx !== -1);
|
|
137
|
+
|
|
138
|
+
if (startIndexes.length === 0) return content;
|
|
139
|
+
|
|
140
|
+
const startIdx = Math.min(...startIndexes);
|
|
141
|
+
const preserved = content.slice(0, startIdx).trimEnd();
|
|
142
|
+
return preserved ? `${preserved}\n` : '';
|
|
143
|
+
}
|
|
144
|
+
|
|
117
145
|
function applyManagedInstructionSections(content, file, rulesSections = {}, options = {}) {
|
|
118
146
|
const rulesHeader = file === 'CLAUDE.md' ? CLAUDE_RULES_HEADER : AGENTS_RULES_HEADER;
|
|
119
147
|
const rulesSection = file === 'CLAUDE.md' ? rulesSections.claudeSection : rulesSections.agentsSection;
|
|
120
148
|
const includeBridge = options.includeBridge !== false;
|
|
121
149
|
|
|
122
|
-
let next =
|
|
150
|
+
let next = stripLegacyRepoInstructionContent(content, file);
|
|
151
|
+
next = stripManagedBlock(next, AW_ROUTER_BRIDGE_START_MARKER, AW_ROUTER_BRIDGE_END_MARKER);
|
|
123
152
|
next = stripManagedSection(next, AW_ROUTER_BRIDGE_HEADER, [rulesHeader]);
|
|
124
153
|
next = stripManagedSection(next, rulesHeader);
|
|
125
154
|
next = next.trimEnd();
|
|
@@ -194,99 +223,35 @@ function findFiles(dir, typeName) {
|
|
|
194
223
|
return results;
|
|
195
224
|
}
|
|
196
225
|
|
|
197
|
-
/**
|
|
198
|
-
* Read consumer config to decide whether to write managed sections into
|
|
199
|
-
* the repo's AGENTS.md / CLAUDE.md.
|
|
200
|
-
*
|
|
201
|
-
* Default behaviour: do NOT touch repo-local AGENTS.md/CLAUDE.md. The same
|
|
202
|
-
* AW Router Bridge + Platform Rules content is already injected into the
|
|
203
|
-
* GLOBAL files (~/.claude/CLAUDE.md and ~/.codex/AGENTS.md) by aw init,
|
|
204
|
-
* and Claude/Codex always read those. Modifying the repo file is invasive
|
|
205
|
-
* and bloats it with content that's already loaded globally.
|
|
206
|
-
*
|
|
207
|
-
* Repos that DO want managed sections in their repo file (e.g. for editors
|
|
208
|
-
* that don't read the global files, or to share AW context with collaborators
|
|
209
|
-
* who haven't run aw init) can opt in via .aw/config.json:
|
|
210
|
-
*
|
|
211
|
-
* { "writeRepoInstructionFiles": true }
|
|
212
|
-
*
|
|
213
|
-
* Existing repo files with managed sections are STRIPPED on next aw init
|
|
214
|
-
* (so users see the managed content go away — clean migration). Repos with
|
|
215
|
-
* the opt-in flag get them updated as before.
|
|
216
|
-
*/
|
|
217
|
-
function shouldWriteRepoInstructionFiles(cwd) {
|
|
218
|
-
const configPath = join(cwd, '.aw', 'config.json');
|
|
219
|
-
if (!existsSync(configPath)) return false;
|
|
220
|
-
try {
|
|
221
|
-
const config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
222
|
-
return config.writeRepoInstructionFiles === true;
|
|
223
|
-
} catch {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
226
|
/**
|
|
229
227
|
* Refresh rules sections in any existing AGENTS.md/CLAUDE.md at the repo
|
|
230
228
|
* root.
|
|
231
229
|
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
230
|
+
* Repo instruction files are user-owned. aw init no longer creates or updates
|
|
231
|
+
* managed sections in repo-local AGENTS.md / CLAUDE.md.
|
|
234
232
|
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
233
|
+
* The only repo-file behavior left is cleanup: if a repo still contains old
|
|
234
|
+
* aw-managed sections from prior versions, strip those sections while leaving
|
|
235
|
+
* the user's own content intact.
|
|
238
236
|
*/
|
|
239
237
|
export function copyInstructions(cwd, tempDir, namespace) {
|
|
240
238
|
const rulesSections = renderRules(cwd);
|
|
241
|
-
const writeManaged = shouldWriteRepoInstructionFiles(cwd);
|
|
242
239
|
const createdFiles = [];
|
|
243
240
|
|
|
244
241
|
for (const file of ['AGENTS.md', 'CLAUDE.md']) {
|
|
245
242
|
const dest = join(cwd, file);
|
|
246
243
|
if (existsSync(dest)) {
|
|
247
244
|
const existing = readFileSync(dest, 'utf8');
|
|
248
|
-
const updated =
|
|
249
|
-
? applyManagedInstructionSections(existing, file, rulesSections, { includeBridge: false })
|
|
250
|
-
: applyManagedInstructionSections(existing, file, {}, { includeBridge: false });
|
|
245
|
+
const updated = applyManagedInstructionSections(existing, file, {}, { includeBridge: false });
|
|
251
246
|
|
|
252
247
|
if (updated !== existing) {
|
|
253
248
|
writeFileSync(dest, updated);
|
|
254
|
-
|
|
255
|
-
fmt.logSuccess(`Updated ${file}`);
|
|
256
|
-
} else {
|
|
257
|
-
fmt.logStep(`Stripped aw-managed sections from ${file} (now in ~/.claude/CLAUDE.md / ~/.codex/AGENTS.md)`);
|
|
258
|
-
}
|
|
249
|
+
fmt.logStep(`Stripped aw-managed sections from ${file} (now in ~/.claude/CLAUDE.md / ~/.codex/AGENTS.md)`);
|
|
259
250
|
}
|
|
260
251
|
continue;
|
|
261
252
|
}
|
|
262
253
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// Only CREATE a repo AGENTS.md if writeRepoInstructionFiles is opted in.
|
|
266
|
-
// Without the opt-in, repo files are user-owned and aw init never creates them.
|
|
267
|
-
if (!writeManaged) continue;
|
|
268
|
-
|
|
269
|
-
if (tempDir) {
|
|
270
|
-
const src = join(tempDir, '.aw_registry', file);
|
|
271
|
-
if (existsSync(src)) {
|
|
272
|
-
let content = readFileSync(src, 'utf8');
|
|
273
|
-
if (namespace) {
|
|
274
|
-
content = content.replace(/\{\{TEAM\}\}/g, namespace);
|
|
275
|
-
}
|
|
276
|
-
content = applyManagedInstructionSections(content, file, rulesSections, { includeBridge: false });
|
|
277
|
-
writeFileSync(dest, content);
|
|
278
|
-
fmt.logSuccess(`Created ${file}`);
|
|
279
|
-
createdFiles.push(dest);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const content = generateAgentsMd(cwd, namespace, rulesSections);
|
|
285
|
-
if (content) {
|
|
286
|
-
writeFileSync(dest, applyManagedInstructionSections(content, file, rulesSections, { includeBridge: false }));
|
|
287
|
-
fmt.logSuccess(`Created ${file}`);
|
|
288
|
-
createdFiles.push(dest);
|
|
289
|
-
}
|
|
254
|
+
// Never create repo instruction files anymore.
|
|
290
255
|
}
|
|
291
256
|
return createdFiles;
|
|
292
257
|
}
|