@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.
Files changed (3) hide show
  1. package/dist/ai.js +11 -3
  2. package/package.json +1 -1
  3. 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 (2 levels deep, most important for path resolution)
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 2 -type d -not -path '*/node_modules/*' 2>/dev/null | head -30`, { cwd, encoding: "utf8", timeout: 2000 }).trim();
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(`Directories in ${srcDir}/:\n${tree}`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/terminal",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Smart terminal wrapper for AI agents and humans — structured output, token compression, MCP server, natural language",
5
5
  "type": "module",
6
6
  "bin": {
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 (2 levels deep, most important for path resolution)
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 2 -type d -not -path '*/node_modules/*' 2>/dev/null | head -30`,
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(`Directories in ${srcDir}/:\n${tree}`);
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
  }