@hasna/terminal 1.3.2 → 1.3.4

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 +12 -3
  2. package/package.json +1 -1
  3. package/src/ai.ts +11 -2
package/dist/ai.js CHANGED
@@ -46,7 +46,15 @@ const IRREVERSIBLE_PATTERNS = [
46
46
  // File creation/modification (READ-ONLY terminal)
47
47
  /\btouch\b/, /\bmkdir\b/, /\becho\s.*>/, /\btee\b/, /\bcp\b/, /\bmv\b/,
48
48
  ];
49
+ // Commands that are ALWAYS safe (read-only git, etc.)
50
+ const SAFE_OVERRIDES = [
51
+ /^\s*git\s+(log|show|diff|branch|status|blame|tag|remote|stash\s+list)\b/,
52
+ /^\s*git\s+log\b/,
53
+ ];
49
54
  export function isIrreversible(command) {
55
+ // Safe overrides take priority
56
+ if (SAFE_OVERRIDES.some((r) => r.test(command)))
57
+ return false;
50
58
  return IRREVERSIBLE_PATTERNS.some((r) => r.test(command));
51
59
  }
52
60
  // ── permissions ───────────────────────────────────────────────────────────────
@@ -164,6 +172,7 @@ RULES:
164
172
  - For "show who changed each line" use git blame, for "show remote urls" use git remote -v
165
173
  - For text search in code, use grep -rn, NOT nm or objdump (those are for compiled binaries)
166
174
  - On macOS: for memory use vm_stat or top -l 1, for disk use df -h, for processes use ps aux
175
+ - macOS uses BSD tools, NOT GNU. Use: du -d 1 (not --max-depth), ls (not ls --color), sort -r (not sort --reverse), ps aux (not ps --sort)
167
176
  - NEVER invent commands that don't exist. Stick to standard Unix/macOS commands.
168
177
  - NEVER install packages (npx, npm install, pip install, brew install). This is a READ-ONLY terminal.
169
178
  - NEVER modify source code (sed -i, codemod, awk with redirect). Only observe, never change.
@@ -210,10 +219,10 @@ export async function translateToCommand(nl, perms, sessionEntries, onToken) {
210
219
  if (!t)
211
220
  return false;
212
221
  // Skip obvious reasoning lines
213
- if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To )/.test(t))
222
+ if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To |However|BLOCKED:)/.test(t))
214
223
  return false;
215
- if (/^[A-Z][a-z].*\.$/.test(t))
216
- return false; // English sentence ending with period
224
+ if (/^[A-Z][a-z].*[.;:]$/.test(t))
225
+ return false; // English sentence ending with period/semicolon/colon
217
226
  return true;
218
227
  });
219
228
  cleaned = commandLines.join("\n").trim() || cleaned;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/terminal",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
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
@@ -55,7 +55,15 @@ const IRREVERSIBLE_PATTERNS = [
55
55
  /\btouch\b/, /\bmkdir\b/, /\becho\s.*>/, /\btee\b/, /\bcp\b/, /\bmv\b/,
56
56
  ];
57
57
 
58
+ // Commands that are ALWAYS safe (read-only git, etc.)
59
+ const SAFE_OVERRIDES = [
60
+ /^\s*git\s+(log|show|diff|branch|status|blame|tag|remote|stash\s+list)\b/,
61
+ /^\s*git\s+log\b/,
62
+ ];
63
+
58
64
  export function isIrreversible(command: string): boolean {
65
+ // Safe overrides take priority
66
+ if (SAFE_OVERRIDES.some((r) => r.test(command))) return false;
59
67
  return IRREVERSIBLE_PATTERNS.some((r) => r.test(command));
60
68
  }
61
69
 
@@ -199,6 +207,7 @@ RULES:
199
207
  - For "show who changed each line" use git blame, for "show remote urls" use git remote -v
200
208
  - For text search in code, use grep -rn, NOT nm or objdump (those are for compiled binaries)
201
209
  - On macOS: for memory use vm_stat or top -l 1, for disk use df -h, for processes use ps aux
210
+ - macOS uses BSD tools, NOT GNU. Use: du -d 1 (not --max-depth), ls (not ls --color), sort -r (not sort --reverse), ps aux (not ps --sort)
202
211
  - NEVER invent commands that don't exist. Stick to standard Unix/macOS commands.
203
212
  - NEVER install packages (npx, npm install, pip install, brew install). This is a READ-ONLY terminal.
204
213
  - NEVER modify source code (sed -i, codemod, awk with redirect). Only observe, never change.
@@ -251,8 +260,8 @@ export async function translateToCommand(
251
260
  const t = l.trim();
252
261
  if (!t) return false;
253
262
  // Skip obvious reasoning lines
254
- if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To )/.test(t)) return false;
255
- if (/^[A-Z][a-z].*\.$/.test(t)) return false; // English sentence ending with period
263
+ if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To |However|BLOCKED:)/.test(t)) return false;
264
+ if (/^[A-Z][a-z].*[.;:]$/.test(t)) return false; // English sentence ending with period/semicolon/colon
256
265
  return true;
257
266
  });
258
267
  cleaned = commandLines.join("\n").trim() || cleaned;