@hasna/terminal 2.0.3 → 2.0.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.
@@ -47,15 +47,25 @@ export async function processOutput(command, output, originalPrompt) {
47
47
  output.slice(-tailChars);
48
48
  }
49
49
  try {
50
- // Pre-parse: extract test counts so AI can't misread them
51
- let preParseHint = "";
50
+ // Pre-parse: if output contains clear pass/fail counts, extract and return directly
51
+ // No hardcoded test runner list — works for ANY tool that outputs "X pass, Y fail"
52
52
  const passMatch = output.match(/(\d+)\s+pass/i);
53
53
  const failMatch = output.match(/(\d+)\s+fail/i);
54
- if (passMatch || failMatch) {
55
- preParseHint = `\nPRE-PARSED TEST RESULTS: ${passMatch?.[1] ?? 0} passed, ${failMatch?.[1] ?? 0} failed. USE THESE NUMBERS.`;
54
+ // Pre-parse fires when output has BOTH pass+fail counts AND the user asked about tests
55
+ if (passMatch && failMatch && originalPrompt && /test|pass|fail/i.test(originalPrompt)) {
56
+ const passed = parseInt(passMatch[1]);
57
+ const failed = parseInt(failMatch[1]);
58
+ const answer = failed === 0
59
+ ? `✓ Yes, all ${passed} tests pass.`
60
+ : `✗ ${failed} of ${passed + failed} tests failed.`;
61
+ const savedTokens = estimateTokens(output) - estimateTokens(answer);
62
+ return {
63
+ summary: answer, full: output, tokensSaved: Math.max(0, savedTokens),
64
+ aiTokensUsed: 0, aiProcessed: true, aiCostUsd: 0, savingsValueUsd: 0, netSavingsUsd: 0,
65
+ };
56
66
  }
57
67
  const provider = getProvider();
58
- const summary = await provider.complete(`${originalPrompt ? `User asked: ${originalPrompt}\n` : ""}Command: ${command}${preParseHint}\nOutput (${lines.length} lines):\n${toSummarize}`, {
68
+ const summary = await provider.complete(`${originalPrompt ? `User asked: ${originalPrompt}\n` : ""}Command: ${command}\nOutput (${lines.length} lines):\n${toSummarize}`, {
59
69
  system: SUMMARIZE_PROMPT,
60
70
  maxTokens: 300,
61
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/terminal",
3
- "version": "2.0.3",
3
+ "version": "2.0.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": {
@@ -79,17 +79,27 @@ export async function processOutput(
79
79
  }
80
80
 
81
81
  try {
82
- // Pre-parse: extract test counts so AI can't misread them
83
- let preParseHint = "";
82
+ // Pre-parse: if output contains clear pass/fail counts, extract and return directly
83
+ // No hardcoded test runner list — works for ANY tool that outputs "X pass, Y fail"
84
84
  const passMatch = output.match(/(\d+)\s+pass/i);
85
85
  const failMatch = output.match(/(\d+)\s+fail/i);
86
- if (passMatch || failMatch) {
87
- preParseHint = `\nPRE-PARSED TEST RESULTS: ${passMatch?.[1] ?? 0} passed, ${failMatch?.[1] ?? 0} failed. USE THESE NUMBERS.`;
86
+ // Pre-parse fires when output has BOTH pass+fail counts AND the user asked about tests
87
+ if (passMatch && failMatch && originalPrompt && /test|pass|fail/i.test(originalPrompt)) {
88
+ const passed = parseInt(passMatch[1]);
89
+ const failed = parseInt(failMatch[1]);
90
+ const answer = failed === 0
91
+ ? `✓ Yes, all ${passed} tests pass.`
92
+ : `✗ ${failed} of ${passed + failed} tests failed.`;
93
+ const savedTokens = estimateTokens(output) - estimateTokens(answer);
94
+ return {
95
+ summary: answer, full: output, tokensSaved: Math.max(0, savedTokens),
96
+ aiTokensUsed: 0, aiProcessed: true, aiCostUsd: 0, savingsValueUsd: 0, netSavingsUsd: 0,
97
+ };
88
98
  }
89
99
 
90
100
  const provider = getProvider();
91
101
  const summary = await provider.complete(
92
- `${originalPrompt ? `User asked: ${originalPrompt}\n` : ""}Command: ${command}${preParseHint}\nOutput (${lines.length} lines):\n${toSummarize}`,
102
+ `${originalPrompt ? `User asked: ${originalPrompt}\n` : ""}Command: ${command}\nOutput (${lines.length} lines):\n${toSummarize}`,
93
103
  {
94
104
  system: SUMMARIZE_PROMPT,
95
105
  maxTokens: 300,