Files
ECC/scripts/lib/install-targets/antigravity-project.js
T
Gaurav DubeyandClaude Opus 5.5 ee7156c0f6 fix(install): give Antigravity rules an activation trigger
Antigravity only attaches a workspace rule when its frontmatter declares
a trigger. The antigravity target copied rules verbatim: common rules
have no frontmatter and language rules carry Claude's `paths:` list, so
every ECC rule landed in .agents/rules/ and was never loaded.

Add an antigravity-rule-frontmatter content transform and apply it to
rule pack files on both the manifest and legacy install paths. Rules
without frontmatter become `trigger: always_on`; `paths:` becomes
`trigger: glob` with matching `globs:`. A rule that already declares a
trigger is left alone, and rules/README.md stays inert. Canonical rule
sources are unchanged.

Fixes #3548

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 02:39:52 +00:00

137 lines
4.4 KiB
JavaScript

const path = require('path');
const {
createFlatRuleOperations,
createInstallTargetAdapter,
createManagedOperation,
createManagedScaffoldOperation,
normalizeRelativePath,
} = require('./helpers');
const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills'];
function supportsAntigravitySourcePath(sourceRelativePath) {
const normalizedPath = normalizeRelativePath(sourceRelativePath);
return SUPPORTED_SOURCE_PREFIXES.some(prefix => (
normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`)
));
}
// Rule packs live one level down (rules/common/, rules/python/, ...). The
// top-level rules/README.md is installer documentation and stays inert.
function isRulePackMarkdown(sourceRelativePath) {
const segments = normalizeRelativePath(sourceRelativePath).split('/');
return segments[0] === 'rules'
&& segments.length >= 3
&& /\.md$/i.test(segments[segments.length - 1]);
}
function withAntigravityRuleTrigger(operation) {
return isRulePackMarkdown(operation.sourceRelativePath)
? { ...operation, contentTransform: 'antigravity-rule-frontmatter' }
: operation;
}
module.exports = createInstallTargetAdapter({
id: 'antigravity-project',
target: 'antigravity',
kind: 'project',
rootSegments: ['.agents'],
installStatePathSegments: ['ecc-install-state.json'],
supportsModule(module) {
const paths = Array.isArray(module && module.paths) ? module.paths : [];
return paths.length > 0;
},
planOperations(input, adapter) {
const modules = Array.isArray(input.modules)
? input.modules
: (input.module ? [input.module] : []);
const {
repoRoot,
projectRoot,
homeDir,
} = input;
const planningInput = {
repoRoot,
projectRoot,
homeDir,
};
const targetRoot = adapter.resolveRoot(planningInput);
return modules.flatMap(module => {
const paths = Array.isArray(module.paths) ? module.paths : [];
return paths
.filter(supportsAntigravitySourcePath)
.flatMap(sourceRelativePath => {
const normalizedSourcePath = normalizeRelativePath(sourceRelativePath);
if (
normalizedSourcePath === 'rules'
|| normalizedSourcePath.startsWith('rules/')
) {
return createFlatRuleOperations({
moduleId: module.id,
repoRoot,
sourceRelativePath: normalizedSourcePath,
destinationDir: path.join(targetRoot, 'rules'),
}).map(withAntigravityRuleTrigger);
}
if (
normalizedSourcePath === 'commands'
|| normalizedSourcePath.startsWith('commands/')
) {
const commandRelativePath = normalizedSourcePath === 'commands'
? ''
: normalizedSourcePath.slice('commands/'.length);
return [
createManagedScaffoldOperation(
module.id,
normalizedSourcePath,
path.join(targetRoot, 'workflows', commandRelativePath),
'preserve-relative-path'
),
];
}
if (
normalizedSourcePath === 'agents'
|| normalizedSourcePath.startsWith('agents/')
) {
const agentRelativePath = normalizedSourcePath === 'agents'
? ''
: normalizedSourcePath.slice('agents/'.length);
return [
createManagedOperation({
moduleId: module.id,
sourceRelativePath: normalizedSourcePath,
destinationPath: path.join(targetRoot, 'agents', agentRelativePath),
strategy: 'preserve-relative-path',
contentTransform: 'antigravity-agent-frontmatter',
}),
];
}
if (
normalizedSourcePath === 'skills'
|| normalizedSourcePath.startsWith('skills/')
) {
const skillRelativePath = normalizedSourcePath === 'skills'
? ''
: normalizedSourcePath.slice('skills/'.length);
return [
createManagedScaffoldOperation(
module.id,
normalizedSourcePath,
path.join(targetRoot, 'skills', skillRelativePath),
'preserve-relative-path'
),
];
}
return [];
});
});
},
});