@hasna/terminal 1.2.0 → 1.2.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/dist/ai.js +11 -3
- package/package.json +1 -1
- package/src/ai.ts +11 -3
package/dist/ai.js
CHANGED
|
@@ -40,6 +40,9 @@ const IRREVERSIBLE_PATTERNS = [
|
|
|
40
40
|
/\bkill\b/, /\bkillall\b/, /\bpkill\b/,
|
|
41
41
|
// Git push/force operations
|
|
42
42
|
/\bgit\s+push\b/, /\bgit\s+reset\s+--hard\b/, /\bgit\s+force\b/,
|
|
43
|
+
// Code modification / package installation (security risk)
|
|
44
|
+
/\bnpx\s+\S+/, /\bnpm\s+install\b/, /\bbun\s+add\b/, /\bpip\s+install\b/,
|
|
45
|
+
/\bcodemod\b/, /\bsed\s+-i\b/, /\bawk\s.*>/, /\bperl\s+-[pi]\b/,
|
|
43
46
|
];
|
|
44
47
|
export function isIrreversible(command) {
|
|
45
48
|
return IRREVERSIBLE_PATTERNS.some((r) => r.test(command));
|
|
@@ -106,12 +109,12 @@ function detectProjectContext() {
|
|
|
106
109
|
// Top-level dirs
|
|
107
110
|
const topLevel = execSync("ls -1", { cwd, encoding: "utf8", timeout: 2000 }).trim();
|
|
108
111
|
parts.push(`Top-level: ${topLevel.split("\n").join(", ")}`);
|
|
109
|
-
// src/ structure
|
|
112
|
+
// src/ structure — include FILES so AI knows exact filenames + extensions
|
|
110
113
|
for (const srcDir of ["src", "lib", "app"]) {
|
|
111
114
|
if (existsSync(join(cwd, srcDir))) {
|
|
112
|
-
const tree = execSync(`find ${srcDir} -maxdepth
|
|
115
|
+
const tree = execSync(`find ${srcDir} -maxdepth 3 -not -path '*/node_modules/*' -not -path '*/dist/*' -not -name '*.test.*' -not -name '*.spec.*' 2>/dev/null | sort | head -60`, { cwd, encoding: "utf8", timeout: 2000 }).trim();
|
|
113
116
|
if (tree)
|
|
114
|
-
parts.push(`
|
|
117
|
+
parts.push(`Files in ${srcDir}/:\n${tree}`);
|
|
115
118
|
break;
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -160,6 +163,11 @@ RULES:
|
|
|
160
163
|
- For text search in code, use grep -rn, NOT nm or objdump (those are for compiled binaries)
|
|
161
164
|
- On macOS: for memory use vm_stat or top -l 1, for disk use df -h, for processes use ps aux
|
|
162
165
|
- NEVER invent commands that don't exist. Stick to standard Unix/macOS commands.
|
|
166
|
+
- NEVER install packages (npx, npm install, pip install, brew install). This is a READ-ONLY terminal.
|
|
167
|
+
- NEVER modify source code (sed -i, codemod, awk with redirect). Only observe, never change.
|
|
168
|
+
- Search src/ directory, NOT dist/ or node_modules/ for code queries.
|
|
169
|
+
- For compound questions ("how many X and are they Y"), prefer ONE command that captures all info. Do NOT chain with &&.
|
|
170
|
+
- Use exact file paths from the project context below. Do NOT guess paths.
|
|
163
171
|
cwd: ${process.cwd()}
|
|
164
172
|
shell: zsh / macOS${projectContext}${restrictionBlock}${contextBlock}`;
|
|
165
173
|
}
|
package/package.json
CHANGED
package/src/ai.ts
CHANGED
|
@@ -48,6 +48,9 @@ const IRREVERSIBLE_PATTERNS = [
|
|
|
48
48
|
/\bkill\b/, /\bkillall\b/, /\bpkill\b/,
|
|
49
49
|
// Git push/force operations
|
|
50
50
|
/\bgit\s+push\b/, /\bgit\s+reset\s+--hard\b/, /\bgit\s+force\b/,
|
|
51
|
+
// Code modification / package installation (security risk)
|
|
52
|
+
/\bnpx\s+\S+/, /\bnpm\s+install\b/, /\bbun\s+add\b/, /\bpip\s+install\b/,
|
|
53
|
+
/\bcodemod\b/, /\bsed\s+-i\b/, /\bawk\s.*>/, /\bperl\s+-[pi]\b/,
|
|
51
54
|
];
|
|
52
55
|
|
|
53
56
|
export function isIrreversible(command: string): boolean {
|
|
@@ -135,14 +138,14 @@ function detectProjectContext(): string {
|
|
|
135
138
|
const topLevel = execSync("ls -1", { cwd, encoding: "utf8", timeout: 2000 }).trim();
|
|
136
139
|
parts.push(`Top-level: ${topLevel.split("\n").join(", ")}`);
|
|
137
140
|
|
|
138
|
-
// src/ structure
|
|
141
|
+
// src/ structure — include FILES so AI knows exact filenames + extensions
|
|
139
142
|
for (const srcDir of ["src", "lib", "app"]) {
|
|
140
143
|
if (existsSync(join(cwd, srcDir))) {
|
|
141
144
|
const tree = execSync(
|
|
142
|
-
`find ${srcDir} -maxdepth
|
|
145
|
+
`find ${srcDir} -maxdepth 3 -not -path '*/node_modules/*' -not -path '*/dist/*' -not -name '*.test.*' -not -name '*.spec.*' 2>/dev/null | sort | head -60`,
|
|
143
146
|
{ cwd, encoding: "utf8", timeout: 2000 }
|
|
144
147
|
).trim();
|
|
145
|
-
if (tree) parts.push(`
|
|
148
|
+
if (tree) parts.push(`Files in ${srcDir}/:\n${tree}`);
|
|
146
149
|
break;
|
|
147
150
|
}
|
|
148
151
|
}
|
|
@@ -195,6 +198,11 @@ RULES:
|
|
|
195
198
|
- For text search in code, use grep -rn, NOT nm or objdump (those are for compiled binaries)
|
|
196
199
|
- On macOS: for memory use vm_stat or top -l 1, for disk use df -h, for processes use ps aux
|
|
197
200
|
- NEVER invent commands that don't exist. Stick to standard Unix/macOS commands.
|
|
201
|
+
- NEVER install packages (npx, npm install, pip install, brew install). This is a READ-ONLY terminal.
|
|
202
|
+
- NEVER modify source code (sed -i, codemod, awk with redirect). Only observe, never change.
|
|
203
|
+
- Search src/ directory, NOT dist/ or node_modules/ for code queries.
|
|
204
|
+
- For compound questions ("how many X and are they Y"), prefer ONE command that captures all info. Do NOT chain with &&.
|
|
205
|
+
- Use exact file paths from the project context below. Do NOT guess paths.
|
|
198
206
|
cwd: ${process.cwd()}
|
|
199
207
|
shell: zsh / macOS${projectContext}${restrictionBlock}${contextBlock}`;
|
|
200
208
|
}
|