@hasna/terminal 1.3.1 → 1.3.3
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/dist/cli.js +13 -11
- package/package.json +1 -1
- package/src/ai.ts +10 -2
- package/src/cli.tsx +13 -10
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 ───────────────────────────────────────────────────────────────
|
|
@@ -210,10 +218,10 @@ export async function translateToCommand(nl, perms, sessionEntries, onToken) {
|
|
|
210
218
|
if (!t)
|
|
211
219
|
return false;
|
|
212
220
|
// Skip obvious reasoning lines
|
|
213
|
-
if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To )/.test(t))
|
|
221
|
+
if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To |However|BLOCKED:)/.test(t))
|
|
214
222
|
return false;
|
|
215
|
-
if (/^[A-Z][a-z]
|
|
216
|
-
return false; // English sentence ending with period
|
|
223
|
+
if (/^[A-Z][a-z].*[.;:]$/.test(t))
|
|
224
|
+
return false; // English sentence ending with period/semicolon/colon
|
|
217
225
|
return true;
|
|
218
226
|
});
|
|
219
227
|
cleaned = commandLines.join("\n").trim() || cleaned;
|
package/dist/cli.js
CHANGED
|
@@ -462,18 +462,11 @@ else if (args.length > 0) {
|
|
|
462
462
|
console.log(formatWatchResult(result));
|
|
463
463
|
process.exit(0);
|
|
464
464
|
}
|
|
465
|
-
//
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const saved = rawTokens - estimateTokens(JSON.stringify(lazy));
|
|
469
|
-
if (saved > 0)
|
|
470
|
-
recordSaving("compressed", saved);
|
|
471
|
-
console.log(JSON.stringify(lazy, null, 2));
|
|
472
|
-
process.exit(0);
|
|
473
|
-
}
|
|
474
|
-
// AI answer framing — ALWAYS use in NL mode (even for small output)
|
|
475
|
-
// The AI needs to ANSWER the question, not just pass through data
|
|
465
|
+
// Frame-first pipeline: AI answers the question, lazy is fallback
|
|
466
|
+
// For question-type prompts, answer framing runs BEFORE lazy mode
|
|
467
|
+
const isQuestion = /^(what|which|how|is|are|does|do|can|should|where|who|why|am|was|were|has|have|will)\b/i.test(prompt) || prompt.includes("?");
|
|
476
468
|
if (clean.length > 10) {
|
|
469
|
+
// Try AI answer framing first (especially for questions)
|
|
477
470
|
const processed = await processOutput(actualCmd, clean, prompt);
|
|
478
471
|
if (processed.aiProcessed) {
|
|
479
472
|
if (processed.tokensSaved > 0)
|
|
@@ -484,6 +477,15 @@ else if (args.length > 0) {
|
|
|
484
477
|
process.exit(0);
|
|
485
478
|
}
|
|
486
479
|
}
|
|
480
|
+
// Lazy mode — fallback when AI framing didn't run or failed
|
|
481
|
+
if (shouldBeLazy(clean, actualCmd)) {
|
|
482
|
+
const lazy = toLazy(clean, actualCmd);
|
|
483
|
+
const saved = rawTokens - estimateTokens(JSON.stringify(lazy));
|
|
484
|
+
if (saved > 0)
|
|
485
|
+
recordSaving("compressed", saved);
|
|
486
|
+
console.log(JSON.stringify(lazy, null, 2));
|
|
487
|
+
process.exit(0);
|
|
488
|
+
}
|
|
487
489
|
// Fallback: AI unavailable — pass through clean
|
|
488
490
|
console.log(clean);
|
|
489
491
|
const saved = rawTokens - estimateTokens(clean);
|
package/package.json
CHANGED
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
|
|
|
@@ -251,8 +259,8 @@ export async function translateToCommand(
|
|
|
251
259
|
const t = l.trim();
|
|
252
260
|
if (!t) return false;
|
|
253
261
|
// 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]
|
|
262
|
+
if (/^(Based on|I |This |The |Let me|Here|Note:|Since|Looking|To |However|BLOCKED:)/.test(t)) return false;
|
|
263
|
+
if (/^[A-Z][a-z].*[.;:]$/.test(t)) return false; // English sentence ending with period/semicolon/colon
|
|
256
264
|
return true;
|
|
257
265
|
});
|
|
258
266
|
cleaned = commandLines.join("\n").trim() || cleaned;
|
package/src/cli.tsx
CHANGED
|
@@ -446,18 +446,12 @@ else if (args.length > 0) {
|
|
|
446
446
|
process.exit(0);
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const saved = rawTokens - estimateTokens(JSON.stringify(lazy));
|
|
453
|
-
if (saved > 0) recordSaving("compressed", saved);
|
|
454
|
-
console.log(JSON.stringify(lazy, null, 2));
|
|
455
|
-
process.exit(0);
|
|
456
|
-
}
|
|
449
|
+
// Frame-first pipeline: AI answers the question, lazy is fallback
|
|
450
|
+
// For question-type prompts, answer framing runs BEFORE lazy mode
|
|
451
|
+
const isQuestion = /^(what|which|how|is|are|does|do|can|should|where|who|why|am|was|were|has|have|will)\b/i.test(prompt) || prompt.includes("?");
|
|
457
452
|
|
|
458
|
-
// AI answer framing — ALWAYS use in NL mode (even for small output)
|
|
459
|
-
// The AI needs to ANSWER the question, not just pass through data
|
|
460
453
|
if (clean.length > 10) {
|
|
454
|
+
// Try AI answer framing first (especially for questions)
|
|
461
455
|
const processed = await processOutput(actualCmd, clean, prompt);
|
|
462
456
|
if (processed.aiProcessed) {
|
|
463
457
|
if (processed.tokensSaved > 0) recordSaving("compressed", processed.tokensSaved);
|
|
@@ -467,6 +461,15 @@ else if (args.length > 0) {
|
|
|
467
461
|
}
|
|
468
462
|
}
|
|
469
463
|
|
|
464
|
+
// Lazy mode — fallback when AI framing didn't run or failed
|
|
465
|
+
if (shouldBeLazy(clean, actualCmd)) {
|
|
466
|
+
const lazy = toLazy(clean, actualCmd);
|
|
467
|
+
const saved = rawTokens - estimateTokens(JSON.stringify(lazy));
|
|
468
|
+
if (saved > 0) recordSaving("compressed", saved);
|
|
469
|
+
console.log(JSON.stringify(lazy, null, 2));
|
|
470
|
+
process.exit(0);
|
|
471
|
+
}
|
|
472
|
+
|
|
470
473
|
// Fallback: AI unavailable — pass through clean
|
|
471
474
|
console.log(clean);
|
|
472
475
|
const saved = rawTokens - estimateTokens(clean);
|