@mohammadhprp/system-prompt 0.13.0 → 0.13.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.
@@ -0,0 +1,124 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+
4
+ import { categories } from '../catalog.js';
5
+ import { loadMcpConfigs } from '../config/mcp.js';
6
+ import { generateOpenCodeConfig } from '../config/opencode.js';
7
+ import { generateTuiConfig } from '../config/tui.js';
8
+ import { LOCK_CATEGORIES, isCopyable, isFileBased } from '../item-layout.js';
9
+ import { getPackageVersion } from '../paths.js';
10
+ import { collectMcpEnvExamples, writeMergedEnv } from './env.js';
11
+ import { copySelectedDirs, copySelectedFiles, deleteSelectedItems, writeManagedFile } from './files.js';
12
+ import { createLockData, lockToSelections, validateLock, writeLockFile } from './lock.js';
13
+ import { mergeGitignore, mergeJsonFile } from './merge.js';
14
+ import { AGENTS_MD } from './templates.js';
15
+
16
+ export function validateSelections(selections) {
17
+ if (!selections || typeof selections !== 'object' || Array.isArray(selections)) {
18
+ throw new Error('Selections must be an object');
19
+ }
20
+ for (const [category, ids] of Object.entries(selections)) {
21
+ const config = categories[category];
22
+ if (!config || !Array.isArray(ids)) throw new Error(`Unknown or invalid category: ${category}`);
23
+ const knownIds = new Set(config.items.map(item => item.id));
24
+ if (ids.some(id => !knownIds.has(id))) throw new Error(`Unknown ${category} item selected`);
25
+ }
26
+ return selections;
27
+ }
28
+
29
+ export async function install({ targetDir, agentType, selections, includeAgentsMd = true, writeAgentsMd, oldSelections, oldLock, force = false, dryRun = false, tuiPreferences }) {
30
+ validateSelections(selections);
31
+ if (oldLock) validateLock(oldLock);
32
+ writeAgentsMd = writeAgentsMd ?? includeAgentsMd;
33
+ const absTarget = resolve(process.cwd(), targetDir);
34
+ if (!dryRun) await mkdir(absTarget, { recursive: true });
35
+ const options = {
36
+ targetDir: absTarget,
37
+ oldLock,
38
+ force,
39
+ dryRun,
40
+ managedFiles: {},
41
+ fileOwners: {},
42
+ };
43
+ if (oldLock) {
44
+ for (const category of LOCK_CATEGORIES) {
45
+ for (const [id, entry] of Object.entries(oldLock[category] || {})) {
46
+ for (const [path, checksum] of Object.entries(entry.files || {})) {
47
+ if (!(path in options.managedFiles)) {
48
+ options.managedFiles[path] = checksum;
49
+ options.fileOwners[path] = { category, id };
50
+ }
51
+ }
52
+ }
53
+ }
54
+ for (const [path, entry] of Object.entries(oldLock.generated || {})) {
55
+ if (!(path in options.managedFiles)) {
56
+ options.managedFiles[path] = entry.computedHash;
57
+ options.fileOwners[path] = { generated: true };
58
+ }
59
+ }
60
+ }
61
+
62
+ // Delete items that are no longer selected.
63
+ if (oldSelections) {
64
+ for (const cat of Object.keys(oldSelections)) {
65
+ const oldIds = new Set(oldSelections[cat] || []);
66
+ const newIds = new Set(selections[cat] || []);
67
+ const removedIds = [...oldIds].filter(id => !newIds.has(id));
68
+ await deleteSelectedItems(absTarget, cat, removedIds, oldLock, force, dryRun);
69
+ }
70
+ }
71
+
72
+ const tasks = [];
73
+ for (const category of LOCK_CATEGORIES) {
74
+ if (!isCopyable(category) || !selections[category]?.length) continue;
75
+ tasks.push(isFileBased(category)
76
+ ? copySelectedFiles(absTarget, category, selections[category], options)
77
+ : copySelectedDirs(absTarget, category, selections[category], options));
78
+ }
79
+ await Promise.all(tasks);
80
+
81
+ if (writeAgentsMd) {
82
+ await writeManagedFile(resolve(absTarget, 'AGENTS.md'), Buffer.from(AGENTS_MD), 'AGENTS.md', options, { generated: true });
83
+ }
84
+
85
+ if (agentType === 'opencode') {
86
+ let mcpEntries = {};
87
+ if (selections.mcps?.length) mcpEntries = await loadMcpConfigs(selections.mcps);
88
+ let previousOpenCodeConfig;
89
+ let previousTuiConfig;
90
+ if (oldLock) {
91
+ const previousSelections = lockToSelections(oldLock);
92
+ let previousMcpEntries = {};
93
+ if (previousSelections.mcps?.length) previousMcpEntries = await loadMcpConfigs(previousSelections.mcps);
94
+ previousOpenCodeConfig = JSON.parse(generateOpenCodeConfig({
95
+ selections: previousSelections,
96
+ mcpEntries: previousMcpEntries,
97
+ includeAgentsMd: oldLock.includeAgentsMd ?? true,
98
+ }));
99
+ previousTuiConfig = JSON.parse(generateTuiConfig({ selections: previousSelections, preferences: tuiPreferences }));
100
+ }
101
+ const configJson = generateOpenCodeConfig({ selections, mcpEntries, includeAgentsMd });
102
+ await mergeJsonFile(resolve(absTarget, 'opencode.json'), JSON.parse(configJson), 'opencode.json', options, previousOpenCodeConfig);
103
+ await mergeJsonFile(resolve(absTarget, 'tui.json'), JSON.parse(generateTuiConfig({ selections, preferences: tuiPreferences })), 'tui.json', options, previousTuiConfig);
104
+ await mergeGitignore(resolve(absTarget, '.gitignore'), options);
105
+ }
106
+
107
+ if (selections.mcps?.length) {
108
+ const envExamples = await collectMcpEnvExamples(selections.mcps);
109
+ await writeMergedEnv(absTarget, envExamples, options);
110
+ }
111
+
112
+ if (dryRun) return absTarget;
113
+ const pkgVersion = await getPackageVersion();
114
+ const lockData = createLockData({
115
+ agentType,
116
+ includeAgentsMd,
117
+ selections,
118
+ managedFiles: options.managedFiles,
119
+ fileOwners: options.fileOwners,
120
+ source: `system-prompt@${pkgVersion}`,
121
+ });
122
+ await writeLockFile(absTarget, lockData);
123
+ return absTarget;
124
+ }
@@ -0,0 +1,159 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+
4
+ import { categories } from '../catalog.js';
5
+ import { hash } from '../hash.js';
6
+ import { LOCK_CATEGORIES, isRemoved, itemSourcePath } from '../item-layout.js';
7
+ import { isMissing } from '../paths.js';
8
+
9
+ export const LOCK_VERSION = 1;
10
+
11
+ export function lockToSelections(lock) {
12
+ const selections = {};
13
+ if (!lock) return selections;
14
+ for (const category of LOCK_CATEGORIES) {
15
+ const ids = Object.keys(lock[category] || {});
16
+ if (ids.length) selections[category] = ids;
17
+ }
18
+ return selections;
19
+ }
20
+
21
+ export function getExpectedHash(oldLock, relativePath) {
22
+ const generated = oldLock?.generated?.[relativePath]?.computedHash;
23
+ if (generated) return generated;
24
+ for (const category of LOCK_CATEGORIES) {
25
+ const entries = oldLock?.[category];
26
+ if (!entries) continue;
27
+ for (const entry of Object.values(entries)) {
28
+ const value = entry?.files?.[relativePath];
29
+ if (value) return value;
30
+ }
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ export async function loadLockFile(absTarget) {
36
+ try {
37
+ const content = await readFile(resolve(absTarget, 'system-prompt-lock.json'), 'utf-8');
38
+ const lock = JSON.parse(content);
39
+ validateLock(lock);
40
+ return lock;
41
+ } catch (error) {
42
+ if (isMissing(error)) return null;
43
+ if (error instanceof SyntaxError || error.message?.startsWith('Invalid system-prompt lock')) {
44
+ throw new Error(`${error.message}. Remove or repair system-prompt-lock.json before reinstalling.`);
45
+ }
46
+ throw error;
47
+ }
48
+ }
49
+
50
+ export function validateLock(lock) {
51
+ if (!lock || typeof lock !== 'object' || Array.isArray(lock)) {
52
+ throw new Error('Invalid system-prompt lock: expected an object');
53
+ }
54
+ if (lock.selections !== undefined || lock.managedFiles !== undefined) {
55
+ throw new Error('Invalid system-prompt lock: legacy lock format no longer supported');
56
+ }
57
+ if (lock.version !== LOCK_VERSION) {
58
+ throw new Error('Invalid system-prompt lock: unsupported version');
59
+ }
60
+ if (typeof lock.agentType !== 'string' || typeof lock.installedAt !== 'string') {
61
+ throw new Error('Invalid system-prompt lock: missing installation metadata');
62
+ }
63
+ if (typeof lock.includeAgentsMd !== 'boolean') {
64
+ throw new Error('Invalid system-prompt lock: includeAgentsMd must be a boolean');
65
+ }
66
+ const allowed = new Set(['version', 'agentType', 'installedAt', 'includeAgentsMd', 'generated', ...LOCK_CATEGORIES]);
67
+ for (const key of Object.keys(lock)) {
68
+ if (!allowed.has(key)) {
69
+ throw new Error(`Invalid system-prompt lock: unknown key ${key}`);
70
+ }
71
+ }
72
+ for (const category of LOCK_CATEGORIES) {
73
+ const entries = lock[category];
74
+ if (entries === undefined) continue;
75
+ if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {
76
+ throw new Error(`Invalid system-prompt lock: invalid ${category} selection`);
77
+ }
78
+ const config = categories[category];
79
+ const knownIds = new Set(config.items.map(item => item.id));
80
+ for (const [id, entry] of Object.entries(entries)) {
81
+ if (!knownIds.has(id)) {
82
+ throw new Error(`Invalid system-prompt lock: unknown ${category} item`);
83
+ }
84
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
85
+ throw new Error(`Invalid system-prompt lock: invalid ${category} entry`);
86
+ }
87
+ if (typeof entry.source !== 'string' || typeof entry.sourceType !== 'string' || typeof entry.itemPath !== 'string') {
88
+ throw new Error(`Invalid system-prompt lock: invalid ${category} entry source`);
89
+ }
90
+ if (!/^[a-f0-9]{64}$/.test(entry.computedHash || '')) {
91
+ throw new Error(`Invalid system-prompt lock: invalid ${category} entry hash`);
92
+ }
93
+ if (!entry.files || typeof entry.files !== 'object' || Array.isArray(entry.files)) {
94
+ throw new Error(`Invalid system-prompt lock: invalid ${category} entry files`);
95
+ }
96
+ for (const [path, checksum] of Object.entries(entry.files)) {
97
+ if (path.startsWith('/') || path.split('/').includes('..') || !/^[a-f0-9]{64}$/.test(checksum)) {
98
+ throw new Error('Invalid system-prompt lock: unsafe managed file entry');
99
+ }
100
+ }
101
+ }
102
+ }
103
+ const generated = lock.generated;
104
+ if (generated !== undefined) {
105
+ if (!generated || typeof generated !== 'object' || Array.isArray(generated)) {
106
+ throw new Error('Invalid system-prompt lock: generated must be an object');
107
+ }
108
+ for (const [path, entry] of Object.entries(generated)) {
109
+ if (path.startsWith('/') || path.split('/').includes('..') || !/^[a-f0-9]{64}$/.test(entry?.computedHash || '')) {
110
+ throw new Error('Invalid system-prompt lock: unsafe generated file entry');
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ export function createLockData({ agentType, includeAgentsMd, selections, managedFiles, fileOwners, source }) {
117
+ const lockData = {
118
+ version: LOCK_VERSION,
119
+ agentType,
120
+ installedAt: new Date().toISOString(),
121
+ includeAgentsMd,
122
+ };
123
+ for (const category of LOCK_CATEGORIES) {
124
+ const entries = {};
125
+ for (const id of selections[category] || []) {
126
+ if (isRemoved(category, id)) continue;
127
+ const files = {};
128
+ for (const [path, checksum] of Object.entries(managedFiles)) {
129
+ const owner = fileOwners[path];
130
+ if (owner?.category === category && owner?.id === id) files[path] = checksum;
131
+ }
132
+ entries[id] = {
133
+ source,
134
+ sourceType: 'bundled',
135
+ itemPath: itemSourcePath(category, id),
136
+ computedHash: buildComputedHash(files, id),
137
+ files,
138
+ };
139
+ }
140
+ lockData[category] = entries;
141
+ }
142
+ const generated = {};
143
+ for (const [path, checksum] of Object.entries(managedFiles)) {
144
+ if (fileOwners[path]?.generated) generated[path] = { computedHash: checksum };
145
+ }
146
+ lockData.generated = generated;
147
+ return lockData;
148
+ }
149
+
150
+ export async function writeLockFile(absTarget, lockData) {
151
+ await writeFile(resolve(absTarget, 'system-prompt-lock.json'), JSON.stringify(lockData, null, 2));
152
+ }
153
+
154
+ function buildComputedHash(files, fallbackId) {
155
+ const keys = Object.keys(files).sort();
156
+ if (keys.length === 0) return hash(fallbackId);
157
+ if (keys.length === 1) return files[keys[0]];
158
+ return hash(keys.map(path => `${path}:${files[path]}`).join('\n'));
159
+ }
@@ -0,0 +1,62 @@
1
+ import { readFile } from 'node:fs/promises';
2
+
3
+ import { isMissing } from '../paths.js';
4
+ import { writeManagedFile } from './files.js';
5
+ import { OPENCODE_GITIGNORE } from './templates.js';
6
+
7
+ export async function mergeJsonFile(destFile, generated, relativePath, options, previousGenerated = generated) {
8
+ let existing = {};
9
+ try {
10
+ existing = JSON.parse(await readFile(destFile, 'utf-8'));
11
+ } catch (error) {
12
+ if (!isMissing(error)) {
13
+ if (error instanceof SyntaxError) throw new Error(`Cannot merge invalid JSON file: ${relativePath}`);
14
+ throw error;
15
+ }
16
+ }
17
+ const merged = { ...existing, ...generated };
18
+ if (Array.isArray(existing.instructions) && Array.isArray(generated.instructions)) {
19
+ const previous = new Set(previousGenerated.instructions || []);
20
+ merged.instructions = [...new Set([
21
+ ...existing.instructions.filter(item => !previous.has(item)),
22
+ ...generated.instructions,
23
+ ])];
24
+ }
25
+ if (Array.isArray(existing.plugin)) {
26
+ const previous = new Set(previousGenerated.plugin || []);
27
+ const plugins = [...new Set([
28
+ ...existing.plugin.filter(item => !previous.has(item)),
29
+ ...(generated.plugin || []),
30
+ ])];
31
+ if (plugins.length) merged.plugin = plugins;
32
+ else delete merged.plugin;
33
+ }
34
+ for (const key of ['mcp', 'references']) {
35
+ if (existing[key] && typeof existing[key] === 'object') {
36
+ const previous = previousGenerated[key] || {};
37
+ const preserved = Object.fromEntries(Object.entries(existing[key]).filter(([name]) => !(name in previous)));
38
+ const values = { ...preserved, ...(generated[key] || {}) };
39
+ if (Object.keys(values).length) merged[key] = values;
40
+ else delete merged[key];
41
+ }
42
+ }
43
+ return writeManagedFile(destFile, Buffer.from(JSON.stringify(merged, null, 4)), relativePath, {
44
+ ...options,
45
+ allowExistingMerge: !options.oldLock,
46
+ }, { generated: true });
47
+ }
48
+
49
+ export async function mergeGitignore(destFile, options) {
50
+ let existing = '';
51
+ try {
52
+ existing = await readFile(destFile, 'utf-8');
53
+ } catch (error) {
54
+ if (!isMissing(error)) throw error;
55
+ }
56
+ const lines = new Set(existing.split('\n').filter(Boolean));
57
+ for (const line of OPENCODE_GITIGNORE.split('\n').filter(Boolean)) lines.add(line);
58
+ return writeManagedFile(destFile, Buffer.from(`${[...lines].join('\n')}\n`), '.gitignore', {
59
+ ...options,
60
+ allowExistingMerge: !options.oldLock,
61
+ }, { generated: true });
62
+ }
@@ -0,0 +1,76 @@
1
+ export const AGENTS_MD = `# AGENTS.md
2
+
3
+ Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
4
+
5
+ Read CONTEXT.md for repository-specific setup, commands, architecture, tests, and workflow guidance.
6
+
7
+ **Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
8
+
9
+ ## 1. Think Before Coding
10
+
11
+ **Don't assume. Don't hide confusion. Surface tradeoffs.**
12
+
13
+ Before implementing:
14
+ - State your assumptions explicitly. If uncertain, ask.
15
+ - If multiple interpretations exist, present them - don't pick silently.
16
+ - If a simpler approach exists, say so. Push back when warranted.
17
+ - If something is unclear, stop. Name what's confusing. Ask.
18
+
19
+ ## 2. Simplicity First
20
+
21
+ **Minimum code that solves the problem. Nothing speculative.**
22
+
23
+ - No features beyond what was asked.
24
+ - No abstractions for single-use code.
25
+ - No "flexibility" or "configurability" that wasn't requested.
26
+ - No error handling for impossible scenarios.
27
+ - If you write 200 lines, and it could be 50, rewrite it.
28
+
29
+ Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
30
+
31
+ ## 3. Surgical Changes
32
+
33
+ **Touch only what you must. Clean up only your own mess.**
34
+
35
+ When editing existing code:
36
+ - Don't "improve" adjacent code, comments, or formatting.
37
+ - Don't refactor things that aren't broken.
38
+ - Match existing style, even if you'd do it differently.
39
+ - If you notice unrelated dead code, mention it - don't delete it.
40
+
41
+ When your changes create orphans:
42
+ - Remove imports/variables/functions that YOUR changes made unused.
43
+ - Don't remove pre-existing dead code unless asked.
44
+
45
+ The test: Every changed line should trace directly to the user's request.
46
+
47
+ ## 4. Goal-Driven Execution
48
+
49
+ **Define success criteria. Loop until verified.**
50
+
51
+ Transform tasks into verifiable goals:
52
+ - "Add validation" → "Write tests for invalid inputs, then make them pass"
53
+ - "Fix the bug" → "Write a test that reproduces it, then make it pass"
54
+ - "Refactor X" → "Ensure tests pass before and after"
55
+
56
+ For multistep tasks, state a brief plan:
57
+
58
+ 1. [Step] → verify: [check]
59
+ 2. [Step] → verify: [check]
60
+ 3. [Step] → verify: [check]
61
+
62
+
63
+ Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
64
+
65
+ ---
66
+
67
+ **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
68
+
69
+ `;
70
+
71
+ export const OPENCODE_GITIGNORE = `.env*
72
+ node_modules
73
+ package.json
74
+ package-lock.json
75
+ bun.lock
76
+ `;
@@ -0,0 +1,31 @@
1
+ import { categories } from './catalog.js';
2
+
3
+ export const LOCK_CATEGORIES = Object.keys(categories);
4
+
5
+ export function isFileBased(category) {
6
+ return categories[category]?.itemLayout === 'file';
7
+ }
8
+
9
+ export function isCopyable(category) {
10
+ const config = categories[category];
11
+ return Boolean(config?.itemLayout) && config.copyItems !== false;
12
+ }
13
+
14
+ export function targetSubdir(sourceDir) {
15
+ return sourceDir.replace(/^framework\//, '');
16
+ }
17
+
18
+ export function itemSourcePath(category, id) {
19
+ const config = categories[category];
20
+ return isFileBased(category) ? `${config.sourceDir}/${id}.md` : `${config.sourceDir}/${id}`;
21
+ }
22
+
23
+ export function itemRelativePath(category, id) {
24
+ const dir = targetSubdir(categories[category].sourceDir);
25
+ return isFileBased(category) ? `${dir}/${id}.md` : `${dir}/${id}`;
26
+ }
27
+
28
+ export function isRemoved(category, id) {
29
+ const item = categories[category]?.items.find(entry => entry.id === id);
30
+ return item?.removed === true;
31
+ }
package/src/paths.js ADDED
@@ -0,0 +1,59 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { dirname, isAbsolute, relative, resolve } from 'node:path';
3
+ import { lstat, readFile } from 'node:fs/promises';
4
+
5
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
6
+
7
+ export const packageRoot = resolve(moduleDir, '..');
8
+
9
+ export function resolveSource(subpath) {
10
+ return resolve(packageRoot, subpath);
11
+ }
12
+
13
+ export async function getPackageVersion() {
14
+ try {
15
+ const pkg = JSON.parse(await readFile(resolve(packageRoot, 'package.json'), 'utf-8'));
16
+ return pkg.version || '0.0.0';
17
+ } catch {
18
+ return '0.0.0';
19
+ }
20
+ }
21
+
22
+ export function isMissing(error) {
23
+ return error?.code === 'ENOENT';
24
+ }
25
+
26
+ function isInside(parent, child) {
27
+ const relativePath = relative(parent, child);
28
+ return relativePath === '' || (!relativePath.startsWith('../') && relativePath !== '..' && !isAbsolute(relativePath));
29
+ }
30
+
31
+ export function assertSafePath(targetDir, path) {
32
+ if (!isInside(targetDir, path)) {
33
+ throw new Error(`Refusing to access path outside installation directory: ${path}`);
34
+ }
35
+ }
36
+
37
+ export async function assertSafeDestination(targetDir, path) {
38
+ assertSafePath(targetDir, path);
39
+ try {
40
+ if ((await lstat(targetDir)).isSymbolicLink()) {
41
+ throw new Error(`Refusing to install through symlink target: ${targetDir}`);
42
+ }
43
+ } catch (error) {
44
+ if (!isMissing(error)) throw error;
45
+ }
46
+ const relativePath = relative(targetDir, path);
47
+ let current = targetDir;
48
+ for (const part of relativePath.split('/').filter(Boolean)) {
49
+ current = resolve(current, part);
50
+ try {
51
+ if ((await lstat(current)).isSymbolicLink()) {
52
+ throw new Error(`Refusing to access symlink inside installation directory: ${current}`);
53
+ }
54
+ } catch (error) {
55
+ if (isMissing(error)) break;
56
+ throw error;
57
+ }
58
+ }
59
+ }
package/src/ui.js ADDED
@@ -0,0 +1,32 @@
1
+ const RESET = '\u001b[0m';
2
+
3
+ const COLORS = {
4
+ red: '\u001b[31m',
5
+ green: '\u001b[32m',
6
+ yellow: '\u001b[33m',
7
+ cyan: '\u001b[36m',
8
+ };
9
+
10
+ const STATUS = {
11
+ success: { symbol: '✓', color: 'green' },
12
+ info: { symbol: '›', color: 'cyan' },
13
+ warn: { symbol: '!', color: 'yellow' },
14
+ error: { symbol: '✗', color: 'red' },
15
+ };
16
+
17
+ export function colorEnabled(stream = process.stdout) {
18
+ if ('NO_COLOR' in process.env) return false;
19
+ if (process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0') return true;
20
+ return Boolean(stream?.isTTY);
21
+ }
22
+
23
+ function style(text, color, { enabled = colorEnabled() } = {}) {
24
+ const code = COLORS[color];
25
+ if (!enabled || !code) return text;
26
+ return `${code}${text}${RESET}`;
27
+ }
28
+
29
+ export function status(kind, message, options = {}) {
30
+ const config = STATUS[kind] || STATUS.info;
31
+ return `${style(config.symbol, config.color, options)} ${message}`;
32
+ }
@@ -1,100 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
- import { dirname, resolve } from 'node:path';
3
- import { readFile } from 'node:fs/promises';
4
-
5
- const __dirname = dirname(fileURLToPath(import.meta.url));
6
- const packageRoot = resolve(__dirname, '..');
7
-
8
- export async function loadMcpConfigs(selectedIds) {
9
- const entries = {};
10
- for (const id of selectedIds) {
11
- try {
12
- const configPath = resolve(packageRoot, `framework/mcps/${id}/configs/opencode.json`);
13
- const raw = await readFile(configPath, 'utf-8');
14
- const parsed = JSON.parse(raw);
15
- if (parsed.mcp) {
16
- Object.assign(entries, parsed.mcp);
17
- }
18
- } catch (error) {
19
- if (error.code === 'ENOENT') {
20
- console.warn(` ⚠ No opencode.json config found for MCP: ${id}`);
21
- continue;
22
- }
23
- throw error;
24
- }
25
- }
26
- return entries;
27
- }
28
-
29
- export function generateOpenCodeConfig({ selections, mcpEntries, includeAgentsMd }) {
30
- const plugins = [];
31
- if (selections.plugins?.includes('opencode-goal-plugin')) {
32
- plugins.push('@prevalentware/opencode-goal-plugin');
33
- }
34
- if (selections.plugins?.includes('ponytail')) {
35
- plugins.push('@dietrichgebert/ponytail');
36
- }
37
-
38
- const instructions = [];
39
- if (includeAgentsMd) instructions.push('AGENTS.md');
40
- if (selections.memory?.length) instructions.push('.opencode/memory/*.md');
41
-
42
- const config = {
43
- $schema: 'https://opencode.ai/config.json',
44
- formatter: true,
45
- lsp: false,
46
- instructions,
47
- };
48
-
49
- if (plugins.length > 0) {
50
- config.plugin = plugins;
51
- }
52
-
53
- const references = {};
54
- if (selections.standards?.length) {
55
- references.standards = {
56
- path: 'references/standards',
57
- description: 'Canonical engineering standards referenced by skills.',
58
- };
59
- }
60
- if (selections.templates?.length) {
61
- references.templates = {
62
- path: 'references/templates',
63
- description: 'Ready-to-use workflow documents.',
64
- };
65
- }
66
- if (Object.keys(references).length > 0) {
67
- config.references = references;
68
- }
69
-
70
- if (Object.keys(mcpEntries).length > 0) {
71
- config.mcp = mcpEntries;
72
- }
73
-
74
- return JSON.stringify(config, null, 4);
75
- }
76
-
77
- export function generateTuiConfig({ selections }) {
78
- const config = {
79
- $schema: 'https://opencode.ai/tui.json',
80
- theme: 'system',
81
- scroll_speed: 3,
82
- scroll_acceleration: {
83
- enabled: true,
84
- },
85
- diff_style: 'auto',
86
- mouse: true,
87
- attention: {
88
- enabled: true,
89
- notifications: true,
90
- sound: true,
91
- volume: 0.4,
92
- },
93
- };
94
-
95
- if (selections.plugins?.includes('opencode-goal-plugin')) {
96
- config.plugin = ['@prevalentware/opencode-goal-plugin'];
97
- }
98
-
99
- return JSON.stringify(config, null, 4);
100
- }