@mohammadhprp/system-prompt 0.13.1 → 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,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
+ `;
@@ -24,3 +24,8 @@ export function itemRelativePath(category, id) {
24
24
  const dir = targetSubdir(categories[category].sourceDir);
25
25
  return isFileBased(category) ? `${dir}/${id}.md` : `${dir}/${id}`;
26
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
+ }