-
-
Notifications
You must be signed in to change notification settings - Fork 328
feat(nx-plugin): emit AGENTS.md and CLAUDE.md from the app generator #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Tree } from '@nx/devkit'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| const AGENT_CONTEXT_FILES = ['AGENTS.md', 'CLAUDE.md']; | ||
|
|
||
| // Seeds agent context in the app so AI coding assistants pick up Analog | ||
| // conventions (see node_modules/@analogjs/platform/AGENTS.md). | ||
| export function addAgentContext(tree: Tree, projectRoot: string) { | ||
| for (const fileName of AGENT_CONTEXT_FILES) { | ||
| const filePath = `${projectRoot}/${fileName}`; | ||
|
|
||
| if (tree.exists(filePath)) { | ||
| continue; | ||
| } | ||
|
|
||
| tree.write( | ||
| filePath, | ||
| readFileSync(join(__dirname, '..', 'files', 'agents', fileName), 'utf-8'), | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,17 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { | |
| ensurePackage('rxjs', 'latest'); | ||
|
|
||
| const appTask = await import('../app/generator').then(({ appGenerator }) => | ||
| appGenerator(tree, options), | ||
| appGenerator(tree, { ...options, skipAgentContext: true }), | ||
| ); | ||
|
|
||
| // Seed agent context at the workspace root so AI coding assistants pick up | ||
| // Analog conventions (see node_modules/@analogjs/platform/AGENTS.md). | ||
| generateFiles(tree, join(__dirname, 'files'), '.', options); | ||
| generateFiles( | ||
| tree, | ||
| join(__dirname, '..', 'app', 'files', 'agents'), | ||
| '.', | ||
| options, | ||
| ); | ||
|
Comment on lines
+18
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== workspace files =="
git ls-files | rg '(^packages/nx-plugin/src/generators/preset/generator\.ts$|^apps/docs-analog/src/content/integrations/nx/index\.md$|^workspace\.json$|^nx\.json$|^package\.json$|jest|test|migrations|schematics|generators|agents|CLAUDE|AGENTS)' | head -200
echo
echo "== target preset generator =="
if [ -f packages/nx-plugin/src/generators/preset/generator.ts ]; then
cat -n packages/nx-plugin/src/generators/preset/generator.ts
fi
echo
echo "== generator files snippets =="
fd -t f 'generator\.ts$' packages/nx-plugin/src/generators | while read -r f; do
echo "--- $f"
rg -n "generateFiles|OverwriteStrategy|addAgentContext|CLAUDE|AGENTS|agents" "$f" || true
done
echo
echo "== app/agenerator files snippets =="
fd -t f 'generator\.ts$' packages/nx-plugin/src/generators | while read -r f; do
echo "--- $f"
rg -n "generateFiles\(|OverwriteStrategy|addAgentContext|AGENTS|CLAUDE|agents" "$f" || true
doneRepository: analogjs/analog Length of output: 14279 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== package deps nx version =="
node - <<'JS'
const fs = require('fs');
const p = JSON.parse(fs.readFileSync('package.json','utf8'));
if (p.devDependencies?.nx) console.log('package.json devDependencies.nx:', p.devDependencies.nx);
if (p.dependencies?.nx) console.log('package.json dependencies.nx:', p.dependencies.nx);
JS
echo
echo "== preset generator =="
cat -n packages/nx-plugin/src/generators/preset/generator.ts
echo
echo "== app generator relevant sections =="
cat -n packages/nx-plugin/src/generators/app/generator.ts | sed -n '1,220p'
echo
echo "== references to generateFiles and KeepExisting =="rg
rg -n "generateFiles\(|OverwriteStrategy|KeepExisting|addAgentContext|AGENTS\.md|CLAUDE\.md|agents" packages/nx-plugin packages -g '*.ts' -g '*.json' | head -200
echo
echo "== tests relevant references =="
rg -n "preset|generateFiles|KeepExisting|AGENTS|CLAUDE|agent" packages/nx-plugin -g '*.spec.ts' -g '*.ts' | head -200Repository: analogjs/analog Length of output: 21086 🌐 Web query:
💡 Result: In Nx, the generateFiles function supports an optional configuration to control how existing files are handled using the OverwriteStrategy [1][2]. To use the KeepExisting strategy, you pass an options object as the final argument to generateFiles [1][3]: generateFiles(tree, srcFolder, target, substitutions, { overwriteStrategy: OverwriteStrategy.KeepExisting }); Available strategies in the OverwriteStrategy enumeration include [4][5]: OverwriteStrategy.Overwrite (default): Automatically overwrites existing files [1][3]. OverwriteStrategy.KeepExisting: Only creates files if the target does not already exist; existing files are preserved [1][3]. OverwriteStrategy.ThrowIfExisting: Throws an exception if a target file already exists, which is useful when a pristine environment is required [1][3]. Citations:
Preserve existing root agent context files in preset-generated workspaces. Preset agent context generation uses
📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
| return appTask; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Cover preservation for both agent files.
The test seeds only
AGENTS.md. It does not prove that an existingCLAUDE.mdsurvives. Seed both files and assert that both custom contents remain after generation.Proposed test update
tree.write(`apps/${analogAppName}/AGENTS.md`, '# Custom guidance'); + tree.write( + `apps/${analogAppName}/CLAUDE.md`, + '# Custom Claude guidance', + ); await generator(tree, { analogAppName }); expect(tree.read(`apps/${analogAppName}/AGENTS.md`).toString()).toContain( '# Custom guidance', ); + expect(tree.read(`apps/${analogAppName}/CLAUDE.md`).toString()).toContain( + '# Custom Claude guidance', + ); expect(tree.exists(`apps/${analogAppName}/CLAUDE.md`)).toBe(true);As per coding guidelines, tests must validate behavior for new functionality.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines