mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 08:15:29 +00:00
When npm hoists ajv beside ecc-universal, path.relative(repoRoot, ...) recorded sources like ../ajv/..., which doctor flags as unsafe-repair-source and repair refuses. Record dependency sources as node_modules/<name>[/node_modules/<name>...]/<file>, mirroring the installed layout, and resolve each package from the repository with Node module resolution at plan and repair time. Paths still reject traversal, absolute paths, and malformed package names, and resolved files must stay inside their package root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.5 KiB
JavaScript
73 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { createManagedScaffoldOperation } = require('./install-targets/helpers');
|
|
const { formatPackageSourcePath } = require('./install/package-source');
|
|
|
|
/**
|
|
* Antigravity MCP Configuration Generator
|
|
*
|
|
* Generates valid Antigravity mcp_config.json containing the ECC Memory Vault
|
|
* stdio server so that Antigravity agents have native access to .ecc/memory/.
|
|
*/
|
|
|
|
function buildAntigravityMcpConfig(options = {}) {
|
|
const { memoryScript } = options;
|
|
if (typeof memoryScript !== 'string' || !path.isAbsolute(memoryScript) || memoryScript.includes('\0')) {
|
|
throw new Error('memoryScript must be an absolute path');
|
|
}
|
|
|
|
return {
|
|
mcpServers: {
|
|
'ecc-memory': {
|
|
command: 'node',
|
|
args: [memoryScript],
|
|
env: {
|
|
ECC_MEMORY_HARNESS: 'antigravity',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
function planAntigravityMemoryRuntime(moduleId, repoRoot, targetRoot) {
|
|
const sourcePaths = [
|
|
'package.json',
|
|
'scripts/memory-mcp.mjs',
|
|
'scripts/lib/missing-dependency.js',
|
|
'scripts/lib/memory-vault.js',
|
|
'scripts/lib/memory-vault-format.js',
|
|
'scripts/lib/path-safety.js',
|
|
];
|
|
const operations = sourcePaths.map(sourcePath => createManagedScaffoldOperation(
|
|
moduleId, sourcePath, path.join(targetRoot, sourcePath), 'preserve-relative-path'
|
|
));
|
|
function addDependency(name, fromRoot, destinationRoot, ancestors = [], packageChain = []) {
|
|
let manifestPath;
|
|
try {
|
|
manifestPath = require.resolve(`${name}/package.json`, { paths: [fromRoot] });
|
|
} catch (error) {
|
|
throw new Error(`Cannot install Antigravity memory dependency ${name}. Run npm install in ${repoRoot}: ${error.message}`);
|
|
}
|
|
if (ancestors.includes(manifestPath)) return;
|
|
const packageRoot = path.dirname(manifestPath);
|
|
const destinationPath = path.join(destinationRoot, 'node_modules', name);
|
|
const sourceChain = [...packageChain, name];
|
|
operations.push(createManagedScaffoldOperation(
|
|
moduleId, formatPackageSourcePath(sourceChain), destinationPath, 'preserve-relative-path'
|
|
));
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
for (const dependency of Object.keys(manifest.dependencies || {})) {
|
|
addDependency(dependency, packageRoot, destinationPath, [...ancestors, manifestPath], sourceChain);
|
|
}
|
|
}
|
|
addDependency('ajv', repoRoot, targetRoot);
|
|
return operations;
|
|
}
|
|
|
|
module.exports = {
|
|
buildAntigravityMcpConfig,
|
|
planAntigravityMemoryRuntime,
|
|
};
|