Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

refactor(cli): emit ASTRYX:START/END markers, read both for compat (#3067)

EJ Hammond797f7618c486
diff --git a/packages/cli/src/api/doctor.mjs b/packages/cli/src/api/doctor.mjs
index 2ac88dbcda..daa61e104b 100644
--- a/packages/cli/src/api/doctor.mjs
+++ b/packages/cli/src/api/doctor.mjs
@@ -355,8 +355,8 @@ export function checkAgentDocs(ctx) {
try {
const content = fs.readFileSync(path.join(ctx.cwd, rel), 'utf-8');
return (
- content.includes('<!-- XDS:START -->') &&
- content.includes('<!-- XDS:END -->')
+ (content.includes('<!-- ASTRYX:START -->') || content.includes('<!-- XDS:START -->')) &&
+ (content.includes('<!-- ASTRYX:END -->') || content.includes('<!-- XDS:END -->'))
);
} catch {
return false;
@@ -368,7 +368,7 @@ export function checkAgentDocs(ctx) {
id: 'agent-docs',
label: 'AI agent docs',
status: 'warn',
- message: `Agent docs present (${present.join(', ')}) but no XDS section markers found.`,
+ message: `Agent docs present (${present.join(', ')}) but no Astryx section markers found.`,
fix: 'Add the XDS section to your agent docs with `astryx init --features agents`.',
};
}
diff --git a/packages/cli/src/commands/agent-docs.mjs b/packages/cli/src/commands/agent-docs.mjs
index 780d7ee77d..a97cd22881 100644
--- a/packages/cli/src/commands/agent-docs.mjs
+++ b/packages/cli/src/commands/agent-docs.mjs
@@ -31,8 +31,11 @@ const AGENTS_MD = 'AGENTS.md';
const CLAUDE_MD = 'CLAUDE.md';
const CLAUDE_DIR_MD = path.join('.claude', 'CLAUDE.md');
-const XDS_MARKER_START = '<!-- XDS:START -->';
-const XDS_MARKER_END = '<!-- XDS:END -->';
+const MARKER_START = '<!-- ASTRYX:START -->';
+const MARKER_END = '<!-- ASTRYX:END -->';
+// Legacy markers — read during migration so the script finds existing XDS blocks
+const LEGACY_MARKER_START = '<!-- XDS:START -->';
+const LEGACY_MARKER_END = '<!-- XDS:END -->';
/**
* Agent tool presets — maps tool names to their file search paths.
@@ -99,7 +102,7 @@ export function resolveAgentPaths(targetDir, agent) {
*/
export function generateCompressedIndex(version, {coreDir, runPrefix = getRunPrefix()} = {}) {
const run = `${runPrefix} astryx`;
- const lines = [XDS_MARKER_START];
+ const lines = [MARKER_START];
// Component count from live discovery
let componentCount = '90+';
@@ -177,7 +180,7 @@ export function generateCompressedIndex(version, {coreDir, runPrefix = getRunPre
lines.push(`${run} swizzle <Name> eject source (--gap to report why)`);
lines.push(`${run} upgrade --apply codemods after version bump`);
lines.push(`after @astryxdesign/core bump, always run ${run} upgrade --apply`);
- lines.push(XDS_MARKER_END);
+ lines.push(MARKER_END);
return lines.join('\n');
}
@@ -218,14 +221,21 @@ export function injectXdsBlock(filePath, compressedIndex, {createIfMissing = fal
if (fs.existsSync(filePath)) {
content = fs.readFileSync(filePath, 'utf-8');
- const startIdx = content.indexOf(XDS_MARKER_START);
- const endIdx = content.indexOf(XDS_MARKER_END);
+ // Find existing section — try new markers first, fall back to legacy XDS markers
+ let startIdx = content.indexOf(MARKER_START);
+ let endIdx = content.indexOf(MARKER_END);
+ let markerEndLength = MARKER_END.length;
+ if (startIdx === -1) {
+ startIdx = content.indexOf(LEGACY_MARKER_START);
+ endIdx = content.indexOf(LEGACY_MARKER_END);
+ markerEndLength = LEGACY_MARKER_END.length;
+ }
if (startIdx !== -1 && endIdx !== -1) {
content =
content.slice(0, startIdx) +
compressedIndex +
- content.slice(endIdx + XDS_MARKER_END.length);
+ content.slice(endIdx + markerEndLength);
} else if (onlyReplace) {
// File exists but has no Astryx markers — skip it
return false;
@@ -277,13 +287,20 @@ export function removeXdsBlock(filePath, {deleteIfEmpty = false} = {}) {
if (!fs.existsSync(filePath)) return false;
let content = fs.readFileSync(filePath, 'utf-8');
- const startIdx = content.indexOf(XDS_MARKER_START);
- const endIdx = content.indexOf(XDS_MARKER_END);
+ // Find existing section — try new markers first, fall back to legacy
+ let startIdx = content.indexOf(MARKER_START);
+ let endIdx = content.indexOf(MARKER_END);
+ let markerEndLen = MARKER_END.length;
+ if (startIdx === -1) {
+ startIdx = content.indexOf(LEGACY_MARKER_START);
+ endIdx = content.indexOf(LEGACY_MARKER_END);
+ markerEndLen = LEGACY_MARKER_END.length;
+ }
if (startIdx === -1 || endIdx === -1) return false;
const before = content.slice(0, startIdx).trimEnd();
- const after = content.slice(endIdx + XDS_MARKER_END.length).trimStart();
+ const after = content.slice(endIdx + markerEndLen).trimStart();
content = before + (after ? '\n\n' + after : '') + '\n';
if (deleteIfEmpty) {
diff --git a/packages/cli/src/commands/agent-docs.test.mjs b/packages/cli/src/commands/agent-docs.test.mjs
index 106bcc23e3..f76d863c60 100644
--- a/packages/cli/src/commands/agent-docs.test.mjs
+++ b/packages/cli/src/commands/agent-docs.test.mjs
@@ -32,8 +32,8 @@ describe('generateCompressedIndex', () => {
it('includes the version number', () => {
const result = generateCompressedIndex('1.2.3');
expect(result).toContain('Astryx v1.2.3');
- expect(result).toContain('<!-- XDS:START -->');
- expect(result).toContain('<!-- XDS:END -->');
+ expect(result).toContain('<!-- ASTRYX:START -->');
+ expect(result).toContain('<!-- ASTRYX:END -->');
});
it('includes theme nudge rule', () => {
@@ -82,19 +82,19 @@ describe('injectXdsBlock', () => {
const filePath = path.join(tmpDir, 'test.md');
fs.writeFileSync(filePath, '# Existing content\n');
- const result = injectXdsBlock(filePath, '<!-- XDS:START -->\nnew\n<!-- XDS:END -->');
+ const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->');
expect(result).toBe(true);
const content = fs.readFileSync(filePath, 'utf-8');
expect(content).toContain('# Existing content');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
});
it('replaces existing markers', () => {
const filePath = path.join(tmpDir, 'test.md');
fs.writeFileSync(filePath, 'before\n<!-- XDS:START -->\nold\n<!-- XDS:END -->\nafter\n');
- injectXdsBlock(filePath, '<!-- XDS:START -->\nnew\n<!-- XDS:END -->');
+ injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->');
const content = fs.readFileSync(filePath, 'utf-8');
expect(content).toContain('new');
@@ -106,7 +106,7 @@ describe('injectXdsBlock', () => {
it('returns false and does not create file when createIfMissing is false', () => {
const filePath = path.join(tmpDir, 'nonexistent.md');
- const result = injectXdsBlock(filePath, '<!-- XDS:START -->\ncontent\n<!-- XDS:END -->');
+ const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\ncontent\n<!-- ASTRYX:END -->');
expect(result).toBe(false);
expect(fs.existsSync(filePath)).toBe(false);
@@ -116,11 +116,11 @@ describe('injectXdsBlock', () => {
const filePath = path.join(tmpDir, 'test.md');
fs.writeFileSync(filePath, '# Existing content\n\nNo XDS markers here.\n');
- const result = injectXdsBlock(filePath, '<!-- XDS:START -->\nnew\n<!-- XDS:END -->', {onlyReplace: true});
+ const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->', {onlyReplace: true});
expect(result).toBe(false);
const content = fs.readFileSync(filePath, 'utf-8');
- expect(content).not.toContain('<!-- XDS:START -->');
+ expect(content).not.toContain('<!-- ASTRYX:START -->');
expect(content).toBe('# Existing content\n\nNo XDS markers here.\n');
});
@@ -128,7 +128,7 @@ describe('injectXdsBlock', () => {
const filePath = path.join(tmpDir, 'test.md');
fs.writeFileSync(filePath, 'before\n<!-- XDS:START -->\nold\n<!-- XDS:END -->\nafter\n');
- const result = injectXdsBlock(filePath, '<!-- XDS:START -->\nnew\n<!-- XDS:END -->', {onlyReplace: true});
+ const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\nnew\n<!-- ASTRYX:END -->', {onlyReplace: true});
expect(result).toBe(true);
const content = fs.readFileSync(filePath, 'utf-8');
@@ -139,7 +139,7 @@ describe('injectXdsBlock', () => {
it('creates file when createIfMissing is true', () => {
const filePath = path.join(tmpDir, 'new.md');
- const result = injectXdsBlock(filePath, '<!-- XDS:START -->\ncontent\n<!-- XDS:END -->', {
+ const result = injectXdsBlock(filePath, '<!-- ASTRYX:START -->\ncontent\n<!-- ASTRYX:END -->', {
createIfMissing: true,
header: '# Header',
});
@@ -147,7 +147,7 @@ describe('injectXdsBlock', () => {
expect(result).toBe(true);
const content = fs.readFileSync(filePath, 'utf-8');
expect(content).toContain('# Header');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
});
});
@@ -157,9 +157,9 @@ describe('injectAgentsMd', () => {
const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
expect(content).toContain('# AGENTS.md');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
expect(content).toContain('Astryx v1.0.0');
- expect(content).toContain('<!-- XDS:END -->');
+ expect(content).toContain('<!-- ASTRYX:END -->');
});
it('updates existing AGENTS.md by replacing XDS markers', () => {
@@ -195,7 +195,7 @@ Existing agent docs.
const content = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
expect(content).toContain('Existing agent docs.');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
expect(content).toContain('Astryx v1.0.0');
});
});
@@ -210,7 +210,7 @@ describe('injectClaudeMd', () => {
const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
expect(content).toContain('# Claude Config');
expect(content).toContain('Existing rules.');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
expect(content).toContain('Astryx v1.0.0');
});
@@ -322,7 +322,7 @@ describe('installAgentDocs', () => {
expect(fs.existsSync(path.join(tmpDir, '.claude', 'CLAUDE.md'))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
const content = fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
});
it('injects into CLAUDE.md at root when it exists', () => {
@@ -334,7 +334,7 @@ describe('installAgentDocs', () => {
expect(written).toEqual(['CLAUDE.md']);
expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(false);
const claudeContent = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
- expect(claudeContent).toContain('<!-- XDS:START -->');
+ expect(claudeContent).toContain('<!-- ASTRYX:START -->');
expect(claudeContent).toContain('Project rules.');
});
@@ -349,8 +349,8 @@ describe('installAgentDocs', () => {
expect(written).toContain('CLAUDE.md');
const agentsContent = fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8');
const claudeContent = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
- expect(agentsContent).toContain('<!-- XDS:START -->');
- expect(claudeContent).toContain('<!-- XDS:START -->');
+ expect(agentsContent).toContain('<!-- ASTRYX:START -->');
+ expect(claudeContent).toContain('<!-- ASTRYX:START -->');
});
it('updates existing .claude/CLAUDE.md', () => {
@@ -363,7 +363,7 @@ describe('installAgentDocs', () => {
expect(written).toEqual(['.claude/CLAUDE.md']);
const content = fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8');
expect(content).toContain('Existing content.');
- expect(content).toContain('<!-- XDS:START -->');
+ expect(content).toContain('<!-- ASTRYX:START -->');
});
it('respects --agent claude preset: finds existing CLAUDE.md', () => {
@@ -410,7 +410,7 @@ describe('installAgentDocs', () => {
expect(written).toEqual([]);
const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
- expect(content).not.toContain('<!-- XDS:START -->');
+ expect(content).not.toContain('<!-- ASTRYX:START -->');
expect(content).toBe('# Claude\n\nProject rules only.\n');
});