@aabadin/project-memory-context 0.1.0 → 0.1.2
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/cli/setup.mjs +24 -1
- package/package.json +1 -1
- package/src/platform.mjs +13 -0
- package/src/setup-bootstrap.mjs +22 -0
- package/src/template-installer.mjs +1 -1
package/cli/setup.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import { spawnSync } from 'node:child_process';
|
|
|
7
7
|
|
|
8
8
|
import { bootstrapProjectInstall } from '../src/setup-bootstrap.mjs';
|
|
9
9
|
import { runDoctor } from '../src/doctor.mjs';
|
|
10
|
-
import { resolvePythonBin } from '../src/platform.mjs';
|
|
10
|
+
import { detectSetupAgentType, resolveConfigDirs, resolvePythonBin } from '../src/platform.mjs';
|
|
11
|
+
import { installAgentTemplates } from '../src/template-installer.mjs';
|
|
11
12
|
|
|
12
13
|
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
14
|
|
|
@@ -26,11 +27,22 @@ function spawnCheck(bin, args) {
|
|
|
26
27
|
return { exitCode: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
function parseArgs(args) {
|
|
31
|
+
const parsed = { agent: null };
|
|
32
|
+
for (let i = 0; i < args.length; i++) {
|
|
33
|
+
if (args[i] === '--agent' && args[i + 1]) {
|
|
34
|
+
parsed.agent = args[++i];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return parsed;
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
const rl = createInterface({ input, output });
|
|
30
41
|
const cwd = resolve(process.cwd());
|
|
31
42
|
|
|
32
43
|
try {
|
|
33
44
|
console.log('\n─── pmc setup ───────────────────────────────────────\n');
|
|
45
|
+
const { agent: requestedAgent } = parseArgs(process.argv.slice(2));
|
|
34
46
|
|
|
35
47
|
const ollamaBaseUrl =
|
|
36
48
|
(await rl.question('Ollama base URL [http://localhost:11434]: ')).trim() ||
|
|
@@ -49,6 +61,17 @@ try {
|
|
|
49
61
|
ollamaModel,
|
|
50
62
|
});
|
|
51
63
|
|
|
64
|
+
const agent = detectSetupAgentType(cwd, { requestedAgent });
|
|
65
|
+
const { globalConfig } = resolveConfigDirs(cwd);
|
|
66
|
+
console.log(`\n Detected agent: ${agent}`);
|
|
67
|
+
await installAgentTemplates({
|
|
68
|
+
projectRoot: cwd,
|
|
69
|
+
agent,
|
|
70
|
+
packageRoot,
|
|
71
|
+
globalConfigDir: agent === 'opencode' ? globalConfig : undefined,
|
|
72
|
+
});
|
|
73
|
+
console.log(` Installed ${agent} templates.`);
|
|
74
|
+
|
|
52
75
|
console.log('\n─── Installation complete ───────────────────────────\n');
|
|
53
76
|
console.log(` Memory DB path: ${result.installState.memoryDbPath}`);
|
|
54
77
|
console.log(` Embedding cache: ${result.installState.embeddingCachePath}`);
|
package/package.json
CHANGED
package/src/platform.mjs
CHANGED
|
@@ -33,6 +33,19 @@ export function detectAgentType(projectRoot) {
|
|
|
33
33
|
return 'generic';
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export function detectSetupAgentType(projectRoot, options = {}) {
|
|
37
|
+
if (options.requestedAgent) return options.requestedAgent;
|
|
38
|
+
|
|
39
|
+
const projectAgent = detectAgentType(projectRoot);
|
|
40
|
+
if (projectAgent !== 'generic') return projectAgent;
|
|
41
|
+
|
|
42
|
+
const exists = options.exists ?? existsSync;
|
|
43
|
+
const homeDir = options.homeDir ?? homedir();
|
|
44
|
+
if (exists(join(homeDir, '.config', 'opencode'))) return 'opencode';
|
|
45
|
+
|
|
46
|
+
return projectAgent;
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
export function resolveConfigDirs(projectRoot = process.cwd(), options = {}) {
|
|
37
50
|
const root = resolve(projectRoot);
|
|
38
51
|
const exists = options.exists ?? existsSync;
|
package/src/setup-bootstrap.mjs
CHANGED
|
@@ -31,6 +31,24 @@ function buildMcpConfig(installState) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function buildOpencodeMcpConfig(installState) {
|
|
35
|
+
return {
|
|
36
|
+
mcp: {
|
|
37
|
+
'agent-memory': {
|
|
38
|
+
type: 'local',
|
|
39
|
+
command: ['npx', '-y', '@aabadin/agent-memory-mcp'],
|
|
40
|
+
enabled: true,
|
|
41
|
+
environment: {
|
|
42
|
+
MEMORY_DB_PATH: installState.memoryDbPath,
|
|
43
|
+
...(installState.embeddingCachePath
|
|
44
|
+
? { EMBEDDING_CACHE_PATH: installState.embeddingCachePath }
|
|
45
|
+
: {}),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
34
52
|
async function writeMcpJson(projectRoot, installState) {
|
|
35
53
|
const mcpPath = join(projectRoot, '.mcp.json');
|
|
36
54
|
const existing = await readJson(mcpPath, {});
|
|
@@ -56,6 +74,10 @@ async function ensureAgentConfigRegistration(projectRoot, installState) {
|
|
|
56
74
|
if (!existing.includes('@aabadin/project-memory-context')) {
|
|
57
75
|
config.plugin = [...existing, '@aabadin/project-memory-context'];
|
|
58
76
|
}
|
|
77
|
+
config.mcp = {
|
|
78
|
+
...(config.mcp ?? {}),
|
|
79
|
+
...buildOpencodeMcpConfig(installState).mcp,
|
|
80
|
+
};
|
|
59
81
|
await mkdir(dirname(configPath), { recursive: true });
|
|
60
82
|
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
|
61
83
|
// Also write .mcp.json so agent-memory is available immediately
|
|
@@ -107,7 +107,7 @@ async function installOpencode({ projectRoot, packageRoot, placeholders, globalC
|
|
|
107
107
|
await readTemplate(packageRoot, 'opencode/agent/enrich.md'),
|
|
108
108
|
placeholders,
|
|
109
109
|
);
|
|
110
|
-
await writeIfMissingOrForced(join(globalDir, '
|
|
110
|
+
await writeIfMissingOrForced(join(globalDir, 'agents', 'enrich.md'), enrichTemplate, { force: true });
|
|
111
111
|
|
|
112
112
|
const agentsMdPath = join(projectRoot, 'AGENTS.md');
|
|
113
113
|
const autostartBlock = renderTemplate(
|