@hasna/terminal 4.2.0 → 4.3.1
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/package.json +5 -3
- package/src/ai.ts +4 -4
- package/src/mcp/server.ts +36 -1640
- package/src/mcp/tools/batch.ts +106 -0
- package/src/mcp/tools/execute.ts +248 -0
- package/src/mcp/tools/files.ts +369 -0
- package/src/mcp/tools/git.ts +306 -0
- package/src/mcp/tools/helpers.ts +92 -0
- package/src/mcp/tools/memory.ts +170 -0
- package/src/mcp/tools/meta.ts +202 -0
- package/src/mcp/tools/process.ts +94 -0
- package/src/mcp/tools/project.ts +297 -0
- package/src/mcp/tools/search.ts +118 -0
- package/src/output-processor.ts +7 -2
- package/src/snapshots.ts +2 -2
- package/dist/App.js +0 -404
- package/dist/Browse.js +0 -79
- package/dist/FuzzyPicker.js +0 -47
- package/dist/Onboarding.js +0 -51
- package/dist/Spinner.js +0 -12
- package/dist/StatusBar.js +0 -49
- package/dist/ai.js +0 -315
- package/dist/cache.js +0 -42
- package/dist/cli.js +0 -778
- package/dist/command-rewriter.js +0 -64
- package/dist/command-validator.js +0 -86
- package/dist/compression.js +0 -91
- package/dist/context-hints.js +0 -285
- package/dist/diff-cache.js +0 -107
- package/dist/discover.js +0 -212
- package/dist/economy.js +0 -155
- package/dist/expand-store.js +0 -44
- package/dist/file-cache.js +0 -72
- package/dist/file-index.js +0 -62
- package/dist/history.js +0 -62
- package/dist/lazy-executor.js +0 -54
- package/dist/line-dedup.js +0 -59
- package/dist/loop-detector.js +0 -75
- package/dist/mcp/install.js +0 -189
- package/dist/mcp/server.js +0 -1306
- package/dist/noise-filter.js +0 -94
- package/dist/output-processor.js +0 -229
- package/dist/output-router.js +0 -41
- package/dist/output-store.js +0 -111
- package/dist/parsers/base.js +0 -2
- package/dist/parsers/build.js +0 -64
- package/dist/parsers/errors.js +0 -101
- package/dist/parsers/files.js +0 -78
- package/dist/parsers/git.js +0 -99
- package/dist/parsers/index.js +0 -48
- package/dist/parsers/tests.js +0 -89
- package/dist/providers/anthropic.js +0 -43
- package/dist/providers/base.js +0 -4
- package/dist/providers/cerebras.js +0 -8
- package/dist/providers/groq.js +0 -8
- package/dist/providers/index.js +0 -142
- package/dist/providers/openai-compat.js +0 -93
- package/dist/providers/xai.js +0 -8
- package/dist/recipes/model.js +0 -20
- package/dist/recipes/storage.js +0 -153
- package/dist/search/content-search.js +0 -70
- package/dist/search/file-search.js +0 -61
- package/dist/search/filters.js +0 -34
- package/dist/search/index.js +0 -5
- package/dist/search/semantic.js +0 -346
- package/dist/session-boot.js +0 -59
- package/dist/session-context.js +0 -55
- package/dist/sessions-db.js +0 -231
- package/dist/smart-display.js +0 -286
- package/dist/snapshots.js +0 -51
- package/dist/supervisor.js +0 -112
- package/dist/test-watchlist.js +0 -131
- package/dist/tokens.js +0 -17
- package/dist/tool-profiles.js +0 -129
- package/dist/tree.js +0 -94
- package/dist/usage-cache.js +0 -65
package/dist/test-watchlist.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// Test focus tracker — tracks test status across runs, only reports changes
|
|
2
|
-
// Instead of showing "248 passed, 2 failed" every time, shows:
|
|
3
|
-
// "auth.login: FIXED, auth.logout: STILL FAILING, 246 unchanged"
|
|
4
|
-
// Per-cwd watchlist
|
|
5
|
-
const watchlists = new Map();
|
|
6
|
-
/** Extract test names and status from test runner output (any runner) */
|
|
7
|
-
function extractTests(output) {
|
|
8
|
-
const tests = [];
|
|
9
|
-
const lines = output.split("\n");
|
|
10
|
-
for (let i = 0; i < lines.length; i++) {
|
|
11
|
-
const line = lines[i];
|
|
12
|
-
// PASS/FAIL with test name: "PASS src/auth.test.ts" or "✓ login works" or "✗ logout fails"
|
|
13
|
-
const passMatch = line.match(/(?:PASS|✓|✔|✅)\s+(.+)/);
|
|
14
|
-
if (passMatch) {
|
|
15
|
-
tests.push({ name: passMatch[1].trim(), status: "pass" });
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
const failMatch = line.match(/(?:FAIL|✗|✕|❌|×)\s+(.+)/);
|
|
19
|
-
if (failMatch) {
|
|
20
|
-
// Capture error from next few lines
|
|
21
|
-
const errorLines = [];
|
|
22
|
-
for (let j = i + 1; j < Math.min(i + 5, lines.length); j++) {
|
|
23
|
-
if (lines[j].match(/(?:PASS|FAIL|✓|✗|✔|✕|Tests:|^\s*$)/))
|
|
24
|
-
break;
|
|
25
|
-
errorLines.push(lines[j].trim());
|
|
26
|
-
}
|
|
27
|
-
tests.push({ name: failMatch[1].trim(), status: "fail", error: errorLines.join(" ").slice(0, 200) });
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
// Jest/vitest style: " ● test name" for failures
|
|
31
|
-
const jestFail = line.match(/^\s*●\s+(.+)/);
|
|
32
|
-
if (jestFail) {
|
|
33
|
-
tests.push({ name: jestFail[1].trim(), status: "fail" });
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return tests;
|
|
38
|
-
}
|
|
39
|
-
/** Detect if output looks like test runner output */
|
|
40
|
-
export function isTestOutput(output, command) {
|
|
41
|
-
// If the command is explicitly a test command, trust it
|
|
42
|
-
if (command && /\b(bun\s+test|npm\s+test|jest|vitest|pytest|cargo\s+test|go\s+test)\b/.test(command))
|
|
43
|
-
return true;
|
|
44
|
-
// Otherwise require BOTH a summary line AND a test runner marker in the output
|
|
45
|
-
const summaryLine = /(?:\d+\s+pass|\d+\s+fail|Tests?:\s+\d+|Ran\s+\d+\s+tests?)\s*$/im;
|
|
46
|
-
const testMarkers = /(?:✓|✗|✔|✕|PASS\s+\S+\.test|FAIL\s+\S+\.test|bun test v|jest|vitest|pytest)/;
|
|
47
|
-
return summaryLine.test(output) && testMarkers.test(output);
|
|
48
|
-
}
|
|
49
|
-
/** Track test results and return only changes */
|
|
50
|
-
export function trackTests(cwd, output) {
|
|
51
|
-
const current = extractTests(output);
|
|
52
|
-
const prev = watchlists.get(cwd);
|
|
53
|
-
// Count totals from raw output (more reliable than extracted tests)
|
|
54
|
-
let totalPassed = 0, totalFailed = 0;
|
|
55
|
-
const summaryMatch = output.match(/(\d+)\s+pass/i);
|
|
56
|
-
const failMatch = output.match(/(\d+)\s+fail/i);
|
|
57
|
-
if (summaryMatch)
|
|
58
|
-
totalPassed = parseInt(summaryMatch[1]);
|
|
59
|
-
if (failMatch)
|
|
60
|
-
totalFailed = parseInt(failMatch[1]);
|
|
61
|
-
// Fallback to extracted counts
|
|
62
|
-
if (totalPassed === 0)
|
|
63
|
-
totalPassed = current.filter(t => t.status === "pass").length;
|
|
64
|
-
if (totalFailed === 0)
|
|
65
|
-
totalFailed = current.filter(t => t.status === "fail").length;
|
|
66
|
-
// Store current for next comparison
|
|
67
|
-
const currentMap = new Map();
|
|
68
|
-
for (const t of current)
|
|
69
|
-
currentMap.set(t.name, t);
|
|
70
|
-
watchlists.set(cwd, currentMap);
|
|
71
|
-
// First run — no comparison possible
|
|
72
|
-
if (!prev) {
|
|
73
|
-
return {
|
|
74
|
-
changed: [],
|
|
75
|
-
newTests: current.filter(t => t.status === "fail"), // only show failures on first run
|
|
76
|
-
totalPassed,
|
|
77
|
-
totalFailed,
|
|
78
|
-
unchangedCount: 0,
|
|
79
|
-
firstRun: true,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// Compare with previous
|
|
83
|
-
const changed = [];
|
|
84
|
-
const newTests = [];
|
|
85
|
-
let unchangedCount = 0;
|
|
86
|
-
for (const [name, test] of currentMap) {
|
|
87
|
-
const prevTest = prev.get(name);
|
|
88
|
-
if (!prevTest) {
|
|
89
|
-
newTests.push(test);
|
|
90
|
-
}
|
|
91
|
-
else if (prevTest.status !== test.status) {
|
|
92
|
-
changed.push({ name, from: prevTest.status, to: test.status, error: test.error });
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
unchangedCount++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return { changed, newTests, totalPassed, totalFailed, unchangedCount, firstRun: false };
|
|
99
|
-
}
|
|
100
|
-
/** Format watchlist result for display */
|
|
101
|
-
export function formatWatchResult(result) {
|
|
102
|
-
const lines = [];
|
|
103
|
-
if (result.firstRun) {
|
|
104
|
-
lines.push(`${result.totalPassed} passed, ${result.totalFailed} failed`);
|
|
105
|
-
if (result.newTests.length > 0) {
|
|
106
|
-
for (const t of result.newTests) {
|
|
107
|
-
lines.push(` ✗ ${t.name}${t.error ? `: ${t.error}` : ""}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return lines.join("\n");
|
|
111
|
-
}
|
|
112
|
-
// Status changes
|
|
113
|
-
for (const c of result.changed) {
|
|
114
|
-
if (c.to === "pass")
|
|
115
|
-
lines.push(` ✓ FIXED: ${c.name}`);
|
|
116
|
-
else
|
|
117
|
-
lines.push(` ✗ BROKE: ${c.name}${c.error ? ` — ${c.error}` : ""}`);
|
|
118
|
-
}
|
|
119
|
-
// New failures
|
|
120
|
-
for (const t of result.newTests.filter(t => t.status === "fail")) {
|
|
121
|
-
lines.push(` ✗ NEW FAIL: ${t.name}${t.error ? ` — ${t.error}` : ""}`);
|
|
122
|
-
}
|
|
123
|
-
// Summary
|
|
124
|
-
if (result.changed.length === 0 && result.newTests.filter(t => t.status === "fail").length === 0) {
|
|
125
|
-
lines.push(`✓ ${result.totalPassed} passed, ${result.totalFailed} failed (no changes)`);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
lines.push(`${result.totalPassed} passed, ${result.totalFailed} failed, ${result.unchangedCount} unchanged`);
|
|
129
|
-
}
|
|
130
|
-
return lines.join("\n");
|
|
131
|
-
}
|
package/dist/tokens.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Token estimation utility — shared across all modules
|
|
2
|
-
// Uses content-aware heuristic: code/JSON averages ~3.3 chars/token,
|
|
3
|
-
// English prose averages ~4.2 chars/token.
|
|
4
|
-
/** Detect if content is primarily code/JSON vs English prose */
|
|
5
|
-
function isCodeLike(text) {
|
|
6
|
-
// Count structural characters common in code/JSON
|
|
7
|
-
const structural = (text.match(/[{}[\]();:=<>,"'`|&\\/@#$%^*+~!?]/g) || []).length;
|
|
8
|
-
const ratio = structural / Math.max(text.length, 1);
|
|
9
|
-
return ratio > 0.08; // >8% structural chars = code-like
|
|
10
|
-
}
|
|
11
|
-
/** Estimate token count for a string with content-aware heuristic */
|
|
12
|
-
export function estimateTokens(text) {
|
|
13
|
-
if (!text)
|
|
14
|
-
return 0;
|
|
15
|
-
const charsPerToken = isCodeLike(text) ? 3.3 : 4.2;
|
|
16
|
-
return Math.ceil(text.length / charsPerToken);
|
|
17
|
-
}
|
package/dist/tool-profiles.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// Tool profiles — config-driven AI enhancement for specific command categories
|
|
2
|
-
// Profiles are loaded from ~/.terminal/profiles/ (user-customizable)
|
|
3
|
-
// Each profile tells the AI how to handle a specific tool's output
|
|
4
|
-
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
const PROFILES_DIR = join(process.env.HOME ?? "~", ".terminal", "profiles");
|
|
7
|
-
/** Built-in profiles — sensible defaults, user can override */
|
|
8
|
-
const BUILTIN_PROFILES = [
|
|
9
|
-
{
|
|
10
|
-
name: "git",
|
|
11
|
-
detect: "^git\\b",
|
|
12
|
-
hints: {
|
|
13
|
-
compress: "For git output: show branch, file counts, insertions/deletions summary. Collapse individual diffs to file-level stats.",
|
|
14
|
-
errors: "Git errors often include a suggested fix (e.g., 'did you mean X?'). Extract the suggestion.",
|
|
15
|
-
success: "Clean working tree, successful push/pull, merge complete.",
|
|
16
|
-
},
|
|
17
|
-
output: { preservePatterns: ["conflict", "CONFLICT", "fatal", "error", "diverged"] },
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: "test",
|
|
21
|
-
detect: "\\b(bun|npm|yarn|pnpm)\\s+(test|run\\s+test)|\\bpytest\\b|\\bcargo\\s+test\\b|\\bgo\\s+test\\b",
|
|
22
|
-
hints: {
|
|
23
|
-
compress: "For test output: show pass/fail counts FIRST, then list ONLY failing test names with error snippets. Skip passing tests entirely.",
|
|
24
|
-
errors: "Test failures have: test name, expected vs actual, stack trace. Extract all three.",
|
|
25
|
-
success: "All tests passing = one line: '✓ N tests pass, 0 fail'",
|
|
26
|
-
},
|
|
27
|
-
output: { preservePatterns: ["FAIL", "fail", "Error", "✗", "expected", "received"] },
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "build",
|
|
31
|
-
detect: "\\b(tsc|bun\\s+run\\s+build|npm\\s+run\\s+build|cargo\\s+build|go\\s+build|make)\\b",
|
|
32
|
-
hints: {
|
|
33
|
-
compress: "For build output: if success with no errors, say '✓ Build succeeded'. If errors, list each error with file:line and message.",
|
|
34
|
-
errors: "Build errors have file:line:column format. Group by file.",
|
|
35
|
-
success: "Empty output or exit 0 = build succeeded.",
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "lint",
|
|
40
|
-
detect: "\\b(eslint|biome|ruff|clippy|golangci-lint|prettier|tsc\\s+--noEmit)\\b",
|
|
41
|
-
hints: {
|
|
42
|
-
compress: "For lint output: group violations by rule name, show count per rule, one example per rule. Skip clean files.",
|
|
43
|
-
errors: "Lint violations: file:line rule-name message. Group by rule.",
|
|
44
|
-
},
|
|
45
|
-
output: { maxLines: 100 },
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "install",
|
|
49
|
-
detect: "\\b(npm\\s+install|bun\\s+install|yarn|pip\\s+install|cargo\\s+build|go\\s+mod)\\b",
|
|
50
|
-
hints: {
|
|
51
|
-
compress: "For install output: show only errors and final summary (packages added/removed/updated). Strip progress bars, funding notices, deprecation warnings.",
|
|
52
|
-
},
|
|
53
|
-
output: { stripPatterns: ["npm warn", "packages are looking for funding", "run `npm fund`"] },
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "find",
|
|
57
|
-
detect: "^find\\b",
|
|
58
|
-
hints: {
|
|
59
|
-
compress: "For find output: if >50 results, group by top-level directory with counts. Show first 10 results as examples.",
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: "docker",
|
|
64
|
-
detect: "\\b(docker|kubectl|helm)\\b",
|
|
65
|
-
hints: {
|
|
66
|
-
compress: "For container output: show container status, image, ports. Strip pull progress and layer hashes.",
|
|
67
|
-
errors: "Docker errors: extract the error message after 'Error response from daemon:'",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
/** Load user profiles from ~/.terminal/profiles/ */
|
|
72
|
-
function loadUserProfiles() {
|
|
73
|
-
if (!existsSync(PROFILES_DIR))
|
|
74
|
-
return [];
|
|
75
|
-
const profiles = [];
|
|
76
|
-
try {
|
|
77
|
-
for (const file of readdirSync(PROFILES_DIR)) {
|
|
78
|
-
if (!file.endsWith(".json"))
|
|
79
|
-
continue;
|
|
80
|
-
try {
|
|
81
|
-
const content = JSON.parse(readFileSync(join(PROFILES_DIR, file), "utf8"));
|
|
82
|
-
if (content.name && content.detect)
|
|
83
|
-
profiles.push(content);
|
|
84
|
-
}
|
|
85
|
-
catch { }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch { }
|
|
89
|
-
return profiles;
|
|
90
|
-
}
|
|
91
|
-
/** Get all profiles — user profiles override builtins by name (cached 30s) */
|
|
92
|
-
let _cachedProfiles = null;
|
|
93
|
-
let _cachedProfilesAt = 0;
|
|
94
|
-
export function getProfiles() {
|
|
95
|
-
const now = Date.now();
|
|
96
|
-
if (_cachedProfiles && now - _cachedProfilesAt < 30_000)
|
|
97
|
-
return _cachedProfiles;
|
|
98
|
-
const user = loadUserProfiles();
|
|
99
|
-
const userNames = new Set(user.map(p => p.name));
|
|
100
|
-
const builtins = BUILTIN_PROFILES.filter(p => !userNames.has(p.name));
|
|
101
|
-
_cachedProfiles = [...user, ...builtins];
|
|
102
|
-
_cachedProfilesAt = now;
|
|
103
|
-
return _cachedProfiles;
|
|
104
|
-
}
|
|
105
|
-
/** Find the matching profile for a command */
|
|
106
|
-
export function matchProfile(command) {
|
|
107
|
-
for (const profile of getProfiles()) {
|
|
108
|
-
try {
|
|
109
|
-
if (new RegExp(profile.detect).test(command))
|
|
110
|
-
return profile;
|
|
111
|
-
}
|
|
112
|
-
catch { }
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
/** Format profile hints for injection into AI prompt */
|
|
117
|
-
export function formatProfileHints(command) {
|
|
118
|
-
const profile = matchProfile(command);
|
|
119
|
-
if (!profile)
|
|
120
|
-
return "";
|
|
121
|
-
const lines = [`TOOL PROFILE (${profile.name}):`];
|
|
122
|
-
if (profile.hints.compress)
|
|
123
|
-
lines.push(` Compression: ${profile.hints.compress}`);
|
|
124
|
-
if (profile.hints.errors)
|
|
125
|
-
lines.push(` Errors: ${profile.hints.errors}`);
|
|
126
|
-
if (profile.hints.success)
|
|
127
|
-
lines.push(` Success: ${profile.hints.success}`);
|
|
128
|
-
return lines.join("\n");
|
|
129
|
-
}
|
package/dist/tree.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Tree compression — convert flat file paths to compact tree representation
|
|
2
|
-
import { readdirSync, statSync } from "fs";
|
|
3
|
-
import { join, basename } from "path";
|
|
4
|
-
import { DEFAULT_EXCLUDE_DIRS } from "./search/filters.js";
|
|
5
|
-
/** Build a tree from a directory */
|
|
6
|
-
export function buildTree(dirPath, options = {}) {
|
|
7
|
-
const { maxDepth = 2, includeHidden = false, depth = 0 } = options;
|
|
8
|
-
const name = basename(dirPath) || dirPath;
|
|
9
|
-
const node = { name, type: "dir", children: [], fileCount: 0 };
|
|
10
|
-
if (depth >= maxDepth) {
|
|
11
|
-
// Count files without listing them
|
|
12
|
-
try {
|
|
13
|
-
const entries = readdirSync(dirPath);
|
|
14
|
-
node.fileCount = entries.length;
|
|
15
|
-
node.children = undefined; // don't expand
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
node.fileCount = 0;
|
|
19
|
-
}
|
|
20
|
-
return node;
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const entries = readdirSync(dirPath);
|
|
24
|
-
for (const entry of entries) {
|
|
25
|
-
if (!includeHidden && entry.startsWith("."))
|
|
26
|
-
continue;
|
|
27
|
-
if (DEFAULT_EXCLUDE_DIRS.includes(entry)) {
|
|
28
|
-
// Show as collapsed with count
|
|
29
|
-
try {
|
|
30
|
-
const subPath = join(dirPath, entry);
|
|
31
|
-
const subStat = statSync(subPath);
|
|
32
|
-
if (subStat.isDirectory()) {
|
|
33
|
-
node.children.push({ name: entry, type: "dir", fileCount: -1 }); // -1 = hidden
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const fullPath = join(dirPath, entry);
|
|
42
|
-
try {
|
|
43
|
-
const stat = statSync(fullPath);
|
|
44
|
-
if (stat.isDirectory()) {
|
|
45
|
-
node.children.push(buildTree(fullPath, { maxDepth, includeHidden, depth: depth + 1 }));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
node.children.push({ name: entry, type: "file", size: stat.size });
|
|
49
|
-
node.fileCount++;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch { }
|
|
58
|
-
return node;
|
|
59
|
-
}
|
|
60
|
-
/** Render tree as compact string (for agents — minimum tokens) */
|
|
61
|
-
export function compactTree(node, indent = 0) {
|
|
62
|
-
const pad = " ".repeat(indent);
|
|
63
|
-
if (node.type === "file")
|
|
64
|
-
return `${pad}${node.name}`;
|
|
65
|
-
if (node.fileCount === -1)
|
|
66
|
-
return `${pad}${node.name}/ (hidden)`;
|
|
67
|
-
if (!node.children || node.children.length === 0)
|
|
68
|
-
return `${pad}${node.name}/ (empty)`;
|
|
69
|
-
if (!node.children.some(c => c.children)) {
|
|
70
|
-
// Leaf directory — compact single line
|
|
71
|
-
const files = node.children.filter(c => c.type === "file").map(c => c.name);
|
|
72
|
-
const dirs = node.children.filter(c => c.type === "dir");
|
|
73
|
-
const parts = [];
|
|
74
|
-
if (files.length <= 5) {
|
|
75
|
-
parts.push(...files);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
parts.push(`${files.length} files`);
|
|
79
|
-
}
|
|
80
|
-
for (const d of dirs) {
|
|
81
|
-
parts.push(`${d.name}/${d.fileCount != null ? ` (${d.fileCount === -1 ? "hidden" : d.fileCount + " files"})` : ""}`);
|
|
82
|
-
}
|
|
83
|
-
return `${pad}${node.name}/ [${parts.join(", ")}]`;
|
|
84
|
-
}
|
|
85
|
-
const lines = [`${pad}${node.name}/`];
|
|
86
|
-
for (const child of node.children) {
|
|
87
|
-
lines.push(compactTree(child, indent + 1));
|
|
88
|
-
}
|
|
89
|
-
return lines.join("\n");
|
|
90
|
-
}
|
|
91
|
-
/** Render tree as JSON (for MCP) */
|
|
92
|
-
export function treeToJson(node) {
|
|
93
|
-
return node;
|
|
94
|
-
}
|
package/dist/usage-cache.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Usage learning cache — zero-cost repeated queries
|
|
2
|
-
// After 3 identical prompt→command mappings, cache locally
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
4
|
-
import { homedir } from "os";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
import { createHash } from "crypto";
|
|
7
|
-
const DIR = join(homedir(), ".terminal");
|
|
8
|
-
const CACHE_FILE = join(DIR, "learned.json");
|
|
9
|
-
function ensureDir() {
|
|
10
|
-
if (!existsSync(DIR))
|
|
11
|
-
mkdirSync(DIR, { recursive: true });
|
|
12
|
-
}
|
|
13
|
-
function hash(s) {
|
|
14
|
-
return createHash("md5").update(s).digest("hex").slice(0, 12);
|
|
15
|
-
}
|
|
16
|
-
function cacheKey(prompt) {
|
|
17
|
-
const projectHash = hash(process.cwd());
|
|
18
|
-
const promptHash = hash(prompt.toLowerCase().trim());
|
|
19
|
-
return `${projectHash}:${promptHash}`;
|
|
20
|
-
}
|
|
21
|
-
function loadCache() {
|
|
22
|
-
ensureDir();
|
|
23
|
-
if (!existsSync(CACHE_FILE))
|
|
24
|
-
return {};
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(readFileSync(CACHE_FILE, "utf8"));
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function saveCache(cache) {
|
|
33
|
-
ensureDir();
|
|
34
|
-
writeFileSync(CACHE_FILE, JSON.stringify(cache));
|
|
35
|
-
}
|
|
36
|
-
/** Check if we have a learned command for this prompt (3+ identical mappings) */
|
|
37
|
-
export function getLearned(prompt) {
|
|
38
|
-
const key = cacheKey(prompt);
|
|
39
|
-
const cache = loadCache();
|
|
40
|
-
const entry = cache[key];
|
|
41
|
-
if (entry && entry.count >= 3)
|
|
42
|
-
return entry.command;
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
/** Record a prompt→command mapping */
|
|
46
|
-
export function recordMapping(prompt, command) {
|
|
47
|
-
const key = cacheKey(prompt);
|
|
48
|
-
const cache = loadCache();
|
|
49
|
-
const existing = cache[key];
|
|
50
|
-
if (existing && existing.command === command) {
|
|
51
|
-
existing.count++;
|
|
52
|
-
existing.lastUsed = Date.now();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
cache[key] = { command, count: 1, lastUsed: Date.now() };
|
|
56
|
-
}
|
|
57
|
-
saveCache(cache);
|
|
58
|
-
}
|
|
59
|
-
/** Get cache stats */
|
|
60
|
-
export function learnedStats() {
|
|
61
|
-
const cache = loadCache();
|
|
62
|
-
const entries = Object.keys(cache).length;
|
|
63
|
-
const cached = Object.values(cache).filter(e => e.count >= 3).length;
|
|
64
|
-
return { entries, cached };
|
|
65
|
-
}
|