@hasna/terminal 2.3.0 → 2.3.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.
- package/dist/App.js +404 -0
- package/dist/Browse.js +79 -0
- package/dist/FuzzyPicker.js +47 -0
- package/dist/Onboarding.js +51 -0
- package/dist/Spinner.js +12 -0
- package/dist/StatusBar.js +49 -0
- package/dist/ai.js +322 -0
- package/dist/cache.js +41 -0
- package/dist/cli.js +64 -16
- package/dist/command-rewriter.js +64 -0
- package/dist/command-validator.js +86 -0
- package/dist/compression.js +107 -0
- package/dist/context-hints.js +275 -0
- package/dist/diff-cache.js +107 -0
- package/dist/discover.js +212 -0
- package/dist/economy.js +123 -0
- package/dist/expand-store.js +38 -0
- package/dist/file-cache.js +72 -0
- package/dist/file-index.js +62 -0
- package/dist/history.js +62 -0
- package/dist/lazy-executor.js +54 -0
- package/dist/line-dedup.js +59 -0
- package/dist/loop-detector.js +75 -0
- package/dist/mcp/install.js +98 -0
- package/dist/mcp/server.js +569 -0
- package/dist/noise-filter.js +86 -0
- package/dist/output-processor.js +129 -0
- package/dist/output-router.js +41 -0
- package/dist/output-store.js +111 -0
- package/dist/parsers/base.js +2 -0
- package/dist/parsers/build.js +64 -0
- package/dist/parsers/errors.js +101 -0
- package/dist/parsers/files.js +78 -0
- package/dist/parsers/git.js +99 -0
- package/dist/parsers/index.js +48 -0
- package/dist/parsers/tests.js +89 -0
- package/dist/providers/anthropic.js +39 -0
- package/dist/providers/base.js +4 -0
- package/dist/providers/cerebras.js +95 -0
- package/dist/providers/groq.js +95 -0
- package/dist/providers/index.js +73 -0
- package/dist/providers/xai.js +95 -0
- package/dist/recipes/model.js +20 -0
- package/dist/recipes/storage.js +136 -0
- package/dist/search/content-search.js +68 -0
- package/dist/search/file-search.js +61 -0
- package/dist/search/filters.js +34 -0
- package/dist/search/index.js +5 -0
- package/dist/search/semantic.js +320 -0
- package/dist/session-boot.js +59 -0
- package/dist/session-context.js +55 -0
- package/dist/sessions-db.js +173 -0
- package/dist/smart-display.js +286 -0
- package/dist/snapshots.js +51 -0
- package/dist/supervisor.js +112 -0
- package/dist/test-watchlist.js +131 -0
- package/dist/tool-profiles.js +122 -0
- package/dist/tree.js +94 -0
- package/dist/usage-cache.js +65 -0
- package/package.json +8 -1
- package/src/ai.ts +8 -0
- package/src/cli.tsx +57 -18
- package/src/output-processor.ts +6 -1
- package/src/output-store.ts +58 -12
- package/src/tool-profiles.ts +139 -0
- package/.claude/scheduled_tasks.lock +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
- package/CONTRIBUTING.md +0 -80
- package/benchmarks/benchmark.mjs +0 -115
- package/imported_modules.txt +0 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +0 -221
- package/temp/rtk/.claude/agents/debugger.md +0 -519
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +0 -461
- package/temp/rtk/.claude/agents/rust-rtk.md +0 -511
- package/temp/rtk/.claude/agents/technical-writer.md +0 -355
- package/temp/rtk/.claude/commands/diagnose.md +0 -352
- package/temp/rtk/.claude/commands/test-routing.md +0 -362
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +0 -16
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +0 -70
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +0 -152
- package/temp/rtk/.claude/rules/cli-testing.md +0 -526
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +0 -348
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +0 -134
- package/temp/rtk/.claude/skills/performance.md +0 -435
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +0 -315
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +0 -71
- package/temp/rtk/.claude/skills/repo-recap.md +0 -206
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +0 -78
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +0 -124
- package/temp/rtk/.claude/skills/security-guardian.md +0 -503
- package/temp/rtk/.claude/skills/ship.md +0 -404
- package/temp/rtk/.github/workflows/benchmark.yml +0 -34
- package/temp/rtk/.github/workflows/dco-check.yaml +0 -12
- package/temp/rtk/.github/workflows/release-please.yml +0 -51
- package/temp/rtk/.github/workflows/release.yml +0 -343
- package/temp/rtk/.github/workflows/security-check.yml +0 -135
- package/temp/rtk/.github/workflows/validate-docs.yml +0 -78
- package/temp/rtk/.release-please-manifest.json +0 -3
- package/temp/rtk/ARCHITECTURE.md +0 -1491
- package/temp/rtk/CHANGELOG.md +0 -640
- package/temp/rtk/CLAUDE.md +0 -605
- package/temp/rtk/CONTRIBUTING.md +0 -199
- package/temp/rtk/Cargo.lock +0 -1668
- package/temp/rtk/Cargo.toml +0 -64
- package/temp/rtk/Formula/rtk.rb +0 -43
- package/temp/rtk/INSTALL.md +0 -390
- package/temp/rtk/LICENSE +0 -21
- package/temp/rtk/README.md +0 -386
- package/temp/rtk/README_es.md +0 -159
- package/temp/rtk/README_fr.md +0 -197
- package/temp/rtk/README_ja.md +0 -159
- package/temp/rtk/README_ko.md +0 -159
- package/temp/rtk/README_zh.md +0 -167
- package/temp/rtk/ROADMAP.md +0 -15
- package/temp/rtk/SECURITY.md +0 -217
- package/temp/rtk/TEST_EXEC_TIME.md +0 -102
- package/temp/rtk/build.rs +0 -57
- package/temp/rtk/docs/AUDIT_GUIDE.md +0 -432
- package/temp/rtk/docs/FEATURES.md +0 -1410
- package/temp/rtk/docs/TROUBLESHOOTING.md +0 -309
- package/temp/rtk/docs/filter-workflow.md +0 -102
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +0 -583
- package/temp/rtk/hooks/opencode-rtk.ts +0 -39
- package/temp/rtk/hooks/rtk-awareness.md +0 -29
- package/temp/rtk/hooks/rtk-rewrite.sh +0 -61
- package/temp/rtk/hooks/test-rtk-rewrite.sh +0 -442
- package/temp/rtk/install.sh +0 -124
- package/temp/rtk/release-please-config.json +0 -10
- package/temp/rtk/scripts/benchmark.sh +0 -592
- package/temp/rtk/scripts/check-installation.sh +0 -162
- package/temp/rtk/scripts/install-local.sh +0 -37
- package/temp/rtk/scripts/rtk-economics.sh +0 -137
- package/temp/rtk/scripts/test-all.sh +0 -561
- package/temp/rtk/scripts/test-aristote.sh +0 -227
- package/temp/rtk/scripts/test-tracking.sh +0 -79
- package/temp/rtk/scripts/update-readme-metrics.sh +0 -32
- package/temp/rtk/scripts/validate-docs.sh +0 -73
- package/temp/rtk/src/aws_cmd.rs +0 -880
- package/temp/rtk/src/binlog.rs +0 -1645
- package/temp/rtk/src/cargo_cmd.rs +0 -1727
- package/temp/rtk/src/cc_economics.rs +0 -1157
- package/temp/rtk/src/ccusage.rs +0 -340
- package/temp/rtk/src/config.rs +0 -187
- package/temp/rtk/src/container.rs +0 -855
- package/temp/rtk/src/curl_cmd.rs +0 -134
- package/temp/rtk/src/deps.rs +0 -268
- package/temp/rtk/src/diff_cmd.rs +0 -367
- package/temp/rtk/src/discover/mod.rs +0 -274
- package/temp/rtk/src/discover/provider.rs +0 -388
- package/temp/rtk/src/discover/registry.rs +0 -2022
- package/temp/rtk/src/discover/report.rs +0 -202
- package/temp/rtk/src/discover/rules.rs +0 -667
- package/temp/rtk/src/display_helpers.rs +0 -402
- package/temp/rtk/src/dotnet_cmd.rs +0 -1771
- package/temp/rtk/src/dotnet_format_report.rs +0 -133
- package/temp/rtk/src/dotnet_trx.rs +0 -593
- package/temp/rtk/src/env_cmd.rs +0 -204
- package/temp/rtk/src/filter.rs +0 -462
- package/temp/rtk/src/filters/README.md +0 -52
- package/temp/rtk/src/filters/ansible-playbook.toml +0 -34
- package/temp/rtk/src/filters/basedpyright.toml +0 -47
- package/temp/rtk/src/filters/biome.toml +0 -45
- package/temp/rtk/src/filters/brew-install.toml +0 -37
- package/temp/rtk/src/filters/composer-install.toml +0 -40
- package/temp/rtk/src/filters/df.toml +0 -16
- package/temp/rtk/src/filters/dotnet-build.toml +0 -64
- package/temp/rtk/src/filters/du.toml +0 -16
- package/temp/rtk/src/filters/fail2ban-client.toml +0 -15
- package/temp/rtk/src/filters/gcc.toml +0 -49
- package/temp/rtk/src/filters/gcloud.toml +0 -22
- package/temp/rtk/src/filters/hadolint.toml +0 -24
- package/temp/rtk/src/filters/helm.toml +0 -29
- package/temp/rtk/src/filters/iptables.toml +0 -27
- package/temp/rtk/src/filters/jj.toml +0 -28
- package/temp/rtk/src/filters/jq.toml +0 -24
- package/temp/rtk/src/filters/make.toml +0 -41
- package/temp/rtk/src/filters/markdownlint.toml +0 -24
- package/temp/rtk/src/filters/mix-compile.toml +0 -27
- package/temp/rtk/src/filters/mix-format.toml +0 -15
- package/temp/rtk/src/filters/mvn-build.toml +0 -44
- package/temp/rtk/src/filters/oxlint.toml +0 -43
- package/temp/rtk/src/filters/ping.toml +0 -63
- package/temp/rtk/src/filters/pio-run.toml +0 -40
- package/temp/rtk/src/filters/poetry-install.toml +0 -50
- package/temp/rtk/src/filters/pre-commit.toml +0 -35
- package/temp/rtk/src/filters/ps.toml +0 -16
- package/temp/rtk/src/filters/quarto-render.toml +0 -41
- package/temp/rtk/src/filters/rsync.toml +0 -48
- package/temp/rtk/src/filters/shellcheck.toml +0 -27
- package/temp/rtk/src/filters/shopify-theme.toml +0 -29
- package/temp/rtk/src/filters/skopeo.toml +0 -45
- package/temp/rtk/src/filters/sops.toml +0 -16
- package/temp/rtk/src/filters/ssh.toml +0 -44
- package/temp/rtk/src/filters/stat.toml +0 -34
- package/temp/rtk/src/filters/swift-build.toml +0 -41
- package/temp/rtk/src/filters/systemctl-status.toml +0 -33
- package/temp/rtk/src/filters/terraform-plan.toml +0 -35
- package/temp/rtk/src/filters/tofu-fmt.toml +0 -16
- package/temp/rtk/src/filters/tofu-init.toml +0 -38
- package/temp/rtk/src/filters/tofu-plan.toml +0 -35
- package/temp/rtk/src/filters/tofu-validate.toml +0 -17
- package/temp/rtk/src/filters/trunk-build.toml +0 -39
- package/temp/rtk/src/filters/ty.toml +0 -50
- package/temp/rtk/src/filters/uv-sync.toml +0 -37
- package/temp/rtk/src/filters/xcodebuild.toml +0 -99
- package/temp/rtk/src/filters/yamllint.toml +0 -25
- package/temp/rtk/src/find_cmd.rs +0 -598
- package/temp/rtk/src/format_cmd.rs +0 -386
- package/temp/rtk/src/gain.rs +0 -723
- package/temp/rtk/src/gh_cmd.rs +0 -1651
- package/temp/rtk/src/git.rs +0 -2012
- package/temp/rtk/src/go_cmd.rs +0 -592
- package/temp/rtk/src/golangci_cmd.rs +0 -254
- package/temp/rtk/src/grep_cmd.rs +0 -288
- package/temp/rtk/src/gt_cmd.rs +0 -810
- package/temp/rtk/src/hook_audit_cmd.rs +0 -283
- package/temp/rtk/src/hook_check.rs +0 -171
- package/temp/rtk/src/init.rs +0 -1859
- package/temp/rtk/src/integrity.rs +0 -537
- package/temp/rtk/src/json_cmd.rs +0 -231
- package/temp/rtk/src/learn/detector.rs +0 -628
- package/temp/rtk/src/learn/mod.rs +0 -119
- package/temp/rtk/src/learn/report.rs +0 -184
- package/temp/rtk/src/lint_cmd.rs +0 -694
- package/temp/rtk/src/local_llm.rs +0 -316
- package/temp/rtk/src/log_cmd.rs +0 -248
- package/temp/rtk/src/ls.rs +0 -324
- package/temp/rtk/src/main.rs +0 -2482
- package/temp/rtk/src/mypy_cmd.rs +0 -389
- package/temp/rtk/src/next_cmd.rs +0 -241
- package/temp/rtk/src/npm_cmd.rs +0 -236
- package/temp/rtk/src/parser/README.md +0 -267
- package/temp/rtk/src/parser/error.rs +0 -46
- package/temp/rtk/src/parser/formatter.rs +0 -336
- package/temp/rtk/src/parser/mod.rs +0 -311
- package/temp/rtk/src/parser/types.rs +0 -119
- package/temp/rtk/src/pip_cmd.rs +0 -302
- package/temp/rtk/src/playwright_cmd.rs +0 -479
- package/temp/rtk/src/pnpm_cmd.rs +0 -573
- package/temp/rtk/src/prettier_cmd.rs +0 -221
- package/temp/rtk/src/prisma_cmd.rs +0 -482
- package/temp/rtk/src/psql_cmd.rs +0 -382
- package/temp/rtk/src/pytest_cmd.rs +0 -384
- package/temp/rtk/src/read.rs +0 -217
- package/temp/rtk/src/rewrite_cmd.rs +0 -50
- package/temp/rtk/src/ruff_cmd.rs +0 -402
- package/temp/rtk/src/runner.rs +0 -271
- package/temp/rtk/src/summary.rs +0 -297
- package/temp/rtk/src/tee.rs +0 -405
- package/temp/rtk/src/telemetry.rs +0 -248
- package/temp/rtk/src/toml_filter.rs +0 -1655
- package/temp/rtk/src/tracking.rs +0 -1416
- package/temp/rtk/src/tree.rs +0 -209
- package/temp/rtk/src/tsc_cmd.rs +0 -259
- package/temp/rtk/src/utils.rs +0 -432
- package/temp/rtk/src/verify_cmd.rs +0 -47
- package/temp/rtk/src/vitest_cmd.rs +0 -385
- package/temp/rtk/src/wc_cmd.rs +0 -401
- package/temp/rtk/src/wget_cmd.rs +0 -260
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +0 -11
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +0 -31
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +0 -1
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +0 -12
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +0 -18
- package/tsconfig.json +0 -15
package/dist/App.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback, useRef } from "react";
|
|
3
|
+
import { Box, Text, useInput, useApp } from "ink";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { translateToCommand, explainCommand, fixCommand, checkPermissions, isIrreversible } from "./ai.js";
|
|
6
|
+
import { loadHistory, appendHistory, loadConfig, saveConfig } from "./history.js";
|
|
7
|
+
import { loadCache } from "./cache.js";
|
|
8
|
+
import Onboarding from "./Onboarding.js";
|
|
9
|
+
import StatusBar from "./StatusBar.js";
|
|
10
|
+
import Spinner from "./Spinner.js";
|
|
11
|
+
import Browse from "./Browse.js";
|
|
12
|
+
import FuzzyPicker from "./FuzzyPicker.js";
|
|
13
|
+
import { createSession, logInteraction, updateInteraction } from "./sessions-db.js";
|
|
14
|
+
import { smartDisplay } from "./smart-display.js";
|
|
15
|
+
import { processOutput, shouldProcess } from "./output-processor.js";
|
|
16
|
+
loadCache();
|
|
17
|
+
const MAX_LINES = 20;
|
|
18
|
+
// ── helpers ───────────────────────────────────────────────────────────────────
|
|
19
|
+
function insertAt(s, pos, ch) { return s.slice(0, pos) + ch + s.slice(pos); }
|
|
20
|
+
function deleteAt(s, pos) { return pos <= 0 ? s : s.slice(0, pos - 1) + s.slice(pos); }
|
|
21
|
+
/** Detect if output lines look like file paths */
|
|
22
|
+
function extractFilePaths(lines) {
|
|
23
|
+
return lines.filter(l => /^\.?\//.test(l.trim()) || /\.(ts|tsx|js|json|md|py|sh|go|rs|txt|yaml|yml|env)$/.test(l.trim()));
|
|
24
|
+
}
|
|
25
|
+
/** Ghost text: find the best NL match that starts with the current input */
|
|
26
|
+
function ghostText(input, history) {
|
|
27
|
+
if (!input.trim())
|
|
28
|
+
return "";
|
|
29
|
+
const lower = input.toLowerCase();
|
|
30
|
+
const match = [...history].reverse().find(h => h.toLowerCase().startsWith(lower) && h.length > input.length);
|
|
31
|
+
return match ? match.slice(input.length) : "";
|
|
32
|
+
}
|
|
33
|
+
/** Detect cd and change process cwd */
|
|
34
|
+
function maybeCd(command) {
|
|
35
|
+
const m = command.match(/^\s*cd\s+(.+)\s*$/);
|
|
36
|
+
if (!m)
|
|
37
|
+
return null;
|
|
38
|
+
let target = m[1].trim().replace(/^['"]|['"]$/g, "");
|
|
39
|
+
if (target.startsWith("~"))
|
|
40
|
+
target = target.replace("~", process.env.HOME ?? "");
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
function newTab(id, cwd) {
|
|
44
|
+
return {
|
|
45
|
+
id, cwd,
|
|
46
|
+
scroll: [], sessionEntries: [], sessionNl: [],
|
|
47
|
+
phase: { type: "input", value: "", cursor: 0, histIdx: -1, raw: false },
|
|
48
|
+
streamLines: [],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function runCommand(command, cwd, onLine, onDone, signal) {
|
|
52
|
+
const proc = spawn("/bin/zsh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
53
|
+
const handle = (d) => d.toString().split("\n").forEach(l => { if (l)
|
|
54
|
+
onLine(l); });
|
|
55
|
+
proc.stdout?.on("data", handle);
|
|
56
|
+
proc.stderr?.on("data", handle);
|
|
57
|
+
proc.on("close", code => onDone(code ?? 0));
|
|
58
|
+
signal.addEventListener("abort", () => { try {
|
|
59
|
+
proc.kill("SIGTERM");
|
|
60
|
+
}
|
|
61
|
+
catch { } });
|
|
62
|
+
}
|
|
63
|
+
// ── App ───────────────────────────────────────────────────────────────────────
|
|
64
|
+
export default function App() {
|
|
65
|
+
const { exit } = useApp();
|
|
66
|
+
const [config, setConfig] = useState(() => loadConfig());
|
|
67
|
+
const [nlHistory] = useState(() => loadHistory().map(h => h.nl).filter(Boolean));
|
|
68
|
+
const [tabs, setTabs] = useState([newTab(1, process.cwd())]);
|
|
69
|
+
const [activeTab, setActiveTab] = useState(0);
|
|
70
|
+
const abortRef = useRef(null);
|
|
71
|
+
let nextTabId = useRef(2);
|
|
72
|
+
const sessionIdRef = useRef("");
|
|
73
|
+
const interactionIdRef = useRef(0);
|
|
74
|
+
const tab = tabs[activeTab];
|
|
75
|
+
const allNl = [...nlHistory, ...tab.sessionNl];
|
|
76
|
+
// ── tab helpers ─────────────────────────────────────────────────────────────
|
|
77
|
+
const updateTab = (updater) => setTabs(ts => ts.map((t, i) => i === activeTab ? updater(t) : t));
|
|
78
|
+
const setPhase = (phase) => updateTab(t => ({ ...t, phase }));
|
|
79
|
+
const setStreamLines = (lines) => updateTab(t => ({ ...t, streamLines: lines }));
|
|
80
|
+
const inputPhase = (overrides = {}) => {
|
|
81
|
+
updateTab(t => ({
|
|
82
|
+
...t,
|
|
83
|
+
streamLines: [],
|
|
84
|
+
phase: { type: "input", value: "", cursor: 0, histIdx: -1, raw: false, ...overrides },
|
|
85
|
+
}));
|
|
86
|
+
};
|
|
87
|
+
const pushScroll = (entry) => updateTab(t => ({ ...t, scroll: [...t.scroll, { ...entry, expanded: false }] }));
|
|
88
|
+
const commitStream = async (nl, cmd, lines, error) => {
|
|
89
|
+
const filePaths = !error ? extractFilePaths(lines) : [];
|
|
90
|
+
// Smart display: first try pattern-based compression, then AI if still large
|
|
91
|
+
let displayLines = !error && lines.length > 5 ? smartDisplay(lines) : lines;
|
|
92
|
+
// AI-powered processing for large outputs (no hardcoded patterns)
|
|
93
|
+
if (!error && shouldProcess(lines.join("\n"))) {
|
|
94
|
+
try {
|
|
95
|
+
const processed = await processOutput(cmd, lines.join("\n"));
|
|
96
|
+
if (processed.aiProcessed && processed.tokensSaved > 50) {
|
|
97
|
+
displayLines = processed.summary.split("\n");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch { /* fallback to smartDisplay result */ }
|
|
101
|
+
}
|
|
102
|
+
const truncated = displayLines.length > MAX_LINES;
|
|
103
|
+
// Build short output summary for session context (first 10 lines of ORIGINAL output)
|
|
104
|
+
const shortOutput = lines.slice(0, 10).join("\n") + (lines.length > 10 ? `\n... (${lines.length} lines total)` : "");
|
|
105
|
+
const entry = { nl, cmd, output: shortOutput, error: error || undefined };
|
|
106
|
+
updateTab(t => ({
|
|
107
|
+
...t,
|
|
108
|
+
streamLines: [],
|
|
109
|
+
sessionEntries: [...t.sessionEntries.slice(-9), entry],
|
|
110
|
+
scroll: [...t.scroll, {
|
|
111
|
+
nl, cmd,
|
|
112
|
+
lines: truncated ? displayLines.slice(0, MAX_LINES) : displayLines,
|
|
113
|
+
truncated, expanded: false,
|
|
114
|
+
error: error || undefined,
|
|
115
|
+
filePaths: filePaths.length ? filePaths : undefined,
|
|
116
|
+
}],
|
|
117
|
+
}));
|
|
118
|
+
appendHistory({ nl, cmd, output: lines.join("\n"), ts: Date.now(), error });
|
|
119
|
+
// Log to SQLite session
|
|
120
|
+
if (interactionIdRef.current) {
|
|
121
|
+
updateInteraction(interactionIdRef.current, { output: shortOutput, exitCode: error ? 1 : 0 });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
// ── run command ─────────────────────────────────────────────────────────────
|
|
125
|
+
const runPhase = async (nl, command, raw) => {
|
|
126
|
+
setPhase({ type: "running", nl, command });
|
|
127
|
+
updateTab(t => ({ ...t, streamLines: [] }));
|
|
128
|
+
const abort = new AbortController();
|
|
129
|
+
abortRef.current = abort;
|
|
130
|
+
const lines = [];
|
|
131
|
+
const cwd = tabs[activeTab].cwd;
|
|
132
|
+
await new Promise(resolve => {
|
|
133
|
+
runCommand(command, cwd, line => { lines.push(line); setStreamLines([...lines]); }, code => {
|
|
134
|
+
// handle cd — update tab cwd
|
|
135
|
+
const cdTarget = maybeCd(command);
|
|
136
|
+
if (cdTarget) {
|
|
137
|
+
try {
|
|
138
|
+
const { resolve: resolvePath } = require("path");
|
|
139
|
+
const newCwd = require("path").resolve(cwd, cdTarget);
|
|
140
|
+
process.chdir(newCwd);
|
|
141
|
+
updateTab(t => ({ ...t, cwd: newCwd }));
|
|
142
|
+
}
|
|
143
|
+
catch { }
|
|
144
|
+
}
|
|
145
|
+
commitStream(nl, command, lines, code !== 0).then(() => {
|
|
146
|
+
abortRef.current = null;
|
|
147
|
+
if (code !== 0 && !raw) {
|
|
148
|
+
setPhase({ type: "autofix", nl, command, errorOutput: lines.join("\n") });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
inputPhase({ raw });
|
|
152
|
+
}
|
|
153
|
+
resolve();
|
|
154
|
+
});
|
|
155
|
+
}, abort.signal);
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
// ── translate + run ─────────────────────────────────────────────────────────
|
|
159
|
+
const translateAndRun = async (nl, raw) => {
|
|
160
|
+
updateTab(t => ({ ...t, sessionNl: [...t.sessionNl, nl] }));
|
|
161
|
+
// Lazy session creation — only when user actually types something
|
|
162
|
+
if (!sessionIdRef.current) {
|
|
163
|
+
sessionIdRef.current = createSession(process.cwd());
|
|
164
|
+
}
|
|
165
|
+
// Log interaction start
|
|
166
|
+
const startTime = Date.now();
|
|
167
|
+
interactionIdRef.current = logInteraction(sessionIdRef.current, { nl });
|
|
168
|
+
if (raw) {
|
|
169
|
+
await runPhase(nl, nl, true);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const sessionEntries = tabs[activeTab].sessionEntries;
|
|
173
|
+
setPhase({ type: "thinking", nl, partial: "" });
|
|
174
|
+
try {
|
|
175
|
+
const command = await translateToCommand(nl, config.permissions, sessionEntries, partial => setPhase({ type: "thinking", nl, partial }));
|
|
176
|
+
// Update interaction with generated command
|
|
177
|
+
updateInteraction(interactionIdRef.current, { command });
|
|
178
|
+
const blocked = checkPermissions(command, config.permissions);
|
|
179
|
+
if (blocked) {
|
|
180
|
+
pushScroll({ nl, cmd: command, lines: [`blocked: ${blocked}`], truncated: false, error: true });
|
|
181
|
+
inputPhase();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const danger = isIrreversible(command);
|
|
185
|
+
if (!config.confirm && !danger) {
|
|
186
|
+
await runPhase(nl, command, false);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
setPhase({ type: "confirm", nl, command, danger });
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
setPhase({ type: "error", message: e.message });
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
// ── input handler ───────────────────────────────────────────────────────────
|
|
196
|
+
useInput(useCallback(async (input, key) => {
|
|
197
|
+
const phase = tabs[activeTab].phase;
|
|
198
|
+
// ── global: ctrl+c always exits ─────────────────────────────────────────
|
|
199
|
+
if (key.ctrl && input === "c" && phase.type !== "running") {
|
|
200
|
+
exit();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// ── running: ctrl+c cancels ──────────────────────────────────────────────
|
|
204
|
+
if (phase.type === "running") {
|
|
205
|
+
if (key.ctrl && input === "c") {
|
|
206
|
+
abortRef.current?.abort();
|
|
207
|
+
inputPhase();
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
// ── browse ───────────────────────────────────────────────────────────────
|
|
212
|
+
if (phase.type === "browse")
|
|
213
|
+
return; // handled by Browse component
|
|
214
|
+
// ── fuzzy ────────────────────────────────────────────────────────────────
|
|
215
|
+
if (phase.type === "fuzzy")
|
|
216
|
+
return; // handled by FuzzyPicker component
|
|
217
|
+
// ── input ────────────────────────────────────────────────────────────────
|
|
218
|
+
if (phase.type === "input") {
|
|
219
|
+
// global shortcuts
|
|
220
|
+
if (key.ctrl && input === "l") {
|
|
221
|
+
updateTab(t => ({ ...t, scroll: [] }));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (key.ctrl && input === "b") {
|
|
225
|
+
setPhase({ type: "browse", cwd: tab.cwd });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (key.ctrl && input === "r") {
|
|
229
|
+
setPhase({ type: "fuzzy" });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// tab management
|
|
233
|
+
if (key.ctrl && input === "t") {
|
|
234
|
+
const id = nextTabId.current++;
|
|
235
|
+
setTabs(ts => [...ts, newTab(id, tab.cwd)]);
|
|
236
|
+
setActiveTab(tabs.length); // new tab index
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (key.ctrl && input === "w") {
|
|
240
|
+
if (tabs.length > 1) {
|
|
241
|
+
setTabs(ts => ts.filter((_, i) => i !== activeTab));
|
|
242
|
+
setActiveTab(i => Math.min(i, tabs.length - 2));
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (key.tab) {
|
|
247
|
+
setActiveTab(i => (i + 1) % tabs.length);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
// history nav
|
|
251
|
+
if (key.upArrow) {
|
|
252
|
+
const idx = Math.min(phase.histIdx + 1, allNl.length - 1);
|
|
253
|
+
const val = allNl[allNl.length - 1 - idx] ?? "";
|
|
254
|
+
setPhase({ ...phase, value: val, cursor: val.length, histIdx: idx });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (key.downArrow) {
|
|
258
|
+
const idx = Math.max(phase.histIdx - 1, -1);
|
|
259
|
+
const val = idx === -1 ? "" : allNl[allNl.length - 1 - idx] ?? "";
|
|
260
|
+
setPhase({ ...phase, value: val, cursor: val.length, histIdx: idx });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
// cursor movement
|
|
264
|
+
if (key.leftArrow) {
|
|
265
|
+
setPhase({ ...phase, cursor: Math.max(0, phase.cursor - 1) });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (key.rightArrow) {
|
|
269
|
+
// right arrow at end → accept ghost text
|
|
270
|
+
const ghost = ghostText(phase.value, allNl);
|
|
271
|
+
if (phase.cursor === phase.value.length && ghost) {
|
|
272
|
+
const full = phase.value + ghost;
|
|
273
|
+
setPhase({ ...phase, value: full, cursor: full.length });
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
setPhase({ ...phase, cursor: Math.min(phase.value.length, phase.cursor + 1) });
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (key.tab) {
|
|
281
|
+
// tab → accept ghost text
|
|
282
|
+
const ghost = ghostText(phase.value, allNl);
|
|
283
|
+
if (ghost) {
|
|
284
|
+
const full = phase.value + ghost;
|
|
285
|
+
setPhase({ ...phase, value: full, cursor: full.length });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (key.return) {
|
|
290
|
+
const nl = phase.value.trim();
|
|
291
|
+
if (!nl)
|
|
292
|
+
return;
|
|
293
|
+
await translateAndRun(nl, phase.raw);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (key.backspace || key.delete) {
|
|
297
|
+
const val = deleteAt(phase.value, phase.cursor);
|
|
298
|
+
setPhase({ ...phase, value: val, cursor: Math.max(0, phase.cursor - 1), histIdx: -1 });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (input && !key.ctrl && !key.meta) {
|
|
302
|
+
const val = insertAt(phase.value, phase.cursor, input);
|
|
303
|
+
setPhase({ ...phase, value: val, cursor: phase.cursor + 1, histIdx: -1 });
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
// ── confirm ──────────────────────────────────────────────────────────────
|
|
308
|
+
if (phase.type === "confirm") {
|
|
309
|
+
if (input === "?") {
|
|
310
|
+
const { nl, command } = phase;
|
|
311
|
+
setPhase({ type: "thinking", nl, partial: "" });
|
|
312
|
+
try {
|
|
313
|
+
const explanation = await explainCommand(command);
|
|
314
|
+
setPhase({ type: "explain", nl, command, explanation });
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
setPhase({ type: "confirm", nl, command, danger: phase.danger });
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (input === "y" || input === "Y" || key.return) {
|
|
322
|
+
await runPhase(phase.nl, phase.command, false);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (input === "n" || input === "N" || key.escape) {
|
|
326
|
+
inputPhase();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (input === "e" || input === "E") {
|
|
330
|
+
setPhase({ type: "input", value: phase.command, cursor: phase.command.length, histIdx: -1, raw: false });
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
// ── explain ──────────────────────────────────────────────────────────────
|
|
336
|
+
if (phase.type === "explain") {
|
|
337
|
+
setPhase({ type: "confirm", nl: phase.nl, command: phase.command, danger: isIrreversible(phase.command) });
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
// ── autofix ──────────────────────────────────────────────────────────────
|
|
341
|
+
if (phase.type === "autofix") {
|
|
342
|
+
if (input === "y" || input === "Y" || key.return) {
|
|
343
|
+
const { nl, command, errorOutput } = phase;
|
|
344
|
+
setPhase({ type: "thinking", nl, partial: "" });
|
|
345
|
+
try {
|
|
346
|
+
const fixed = await fixCommand(nl, command, errorOutput, config.permissions, tab.sessionEntries);
|
|
347
|
+
const danger = isIrreversible(fixed);
|
|
348
|
+
if (!config.confirm && !danger) {
|
|
349
|
+
await runPhase(nl, fixed, false);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
setPhase({ type: "confirm", nl, command: fixed, danger });
|
|
353
|
+
}
|
|
354
|
+
catch (e) {
|
|
355
|
+
setPhase({ type: "error", message: e.message });
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
inputPhase();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
// ── error ────────────────────────────────────────────────────────────────
|
|
363
|
+
if (phase.type === "error") {
|
|
364
|
+
inputPhase();
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}, [tabs, activeTab, allNl, config, exit]));
|
|
368
|
+
// ── onboarding ───────────────────────────────────────────────────────────────
|
|
369
|
+
if (!config.onboarded) {
|
|
370
|
+
return _jsx(Onboarding, { onDone: (perms) => {
|
|
371
|
+
const next = { onboarded: true, confirm: false, permissions: perms };
|
|
372
|
+
setConfig(next);
|
|
373
|
+
saveConfig(next);
|
|
374
|
+
} });
|
|
375
|
+
}
|
|
376
|
+
const phase = tab.phase;
|
|
377
|
+
const isRaw = phase.type === "input" && phase.raw;
|
|
378
|
+
const ghost = phase.type === "input" ? ghostText(phase.value, allNl) : "";
|
|
379
|
+
// ── browse overlay ────────────────────────────────────────────────────────
|
|
380
|
+
if (phase.type === "browse") {
|
|
381
|
+
return (_jsxs(Box, { flexDirection: "column", children: [tabs.length > 1 && _jsx(TabBar, { tabs: tabs, active: activeTab }), _jsx(Browse, { cwd: phase.cwd, onCd: path => setPhase({ type: "browse", cwd: path }), onSelect: path => {
|
|
382
|
+
// fill input with the path
|
|
383
|
+
setPhase({ type: "input", value: path, cursor: path.length, histIdx: -1, raw: false });
|
|
384
|
+
}, onExit: () => inputPhase() }), _jsx(StatusBar, { permissions: config.permissions })] }));
|
|
385
|
+
}
|
|
386
|
+
// ── fuzzy overlay ──────────────────────────────────────────────────────────
|
|
387
|
+
if (phase.type === "fuzzy") {
|
|
388
|
+
return (_jsxs(Box, { flexDirection: "column", children: [tabs.length > 1 && _jsx(TabBar, { tabs: tabs, active: activeTab }), _jsx(FuzzyPicker, { history: allNl, onSelect: nl => {
|
|
389
|
+
setPhase({ type: "input", value: nl, cursor: nl.length, histIdx: -1, raw: false });
|
|
390
|
+
}, onExit: () => inputPhase() }), _jsx(StatusBar, { permissions: config.permissions })] }));
|
|
391
|
+
}
|
|
392
|
+
// ── main render ───────────────────────────────────────────────────────────
|
|
393
|
+
return (_jsxs(Box, { flexDirection: "column", children: [tabs.length > 1 && _jsx(TabBar, { tabs: tabs, active: activeTab }), tab.scroll.map((entry, i) => (_jsxs(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2, children: [_jsxs(Box, { gap: 2, children: [_jsx(Text, { dimColor: true, children: "\u203A" }), _jsx(Text, { dimColor: true, children: entry.nl })] }), entry.nl !== entry.cmd && (_jsxs(Box, { gap: 2, paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: "$" }), _jsx(Text, { dimColor: true, children: entry.cmd })] })), entry.lines.length > 0 && (_jsxs(Box, { flexDirection: "column", paddingLeft: 4, children: [(entry.expanded ? entry.lines : entry.lines).map((line, j) => (_jsx(Text, { color: entry.error ? "red" : undefined, children: line }, j))), entry.truncated && !entry.expanded && (_jsx(Text, { dimColor: true, children: " \u2026 more lines" }))] }))] }, i))), phase.type === "confirm" && (_jsxs(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2, children: [_jsxs(Box, { gap: 2, children: [_jsx(Text, { dimColor: true, children: "\u203A" }), _jsx(Text, { dimColor: true, children: phase.nl })] }), _jsxs(Box, { gap: 2, paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: "$" }), _jsx(Text, { children: phase.command }), phase.danger && _jsx(Text, { color: "red", children: " \u26A0 irreversible" })] }), _jsx(Box, { paddingLeft: 4, children: _jsx(Text, { dimColor: true, children: "enter n e ?" }) })] })), phase.type === "explain" && (_jsxs(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2, children: [_jsxs(Box, { gap: 2, paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: "$" }), _jsx(Text, { children: phase.command })] }), _jsx(Box, { paddingLeft: 4, children: _jsx(Text, { dimColor: true, children: phase.explanation }) }), _jsx(Box, { paddingLeft: 4, children: _jsx(Text, { dimColor: true, children: "any key \u2192" }) })] })), phase.type === "autofix" && (_jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "failed \u2014 retry with fix? [enter / n]" }) })), phase.type === "thinking" && (phase.partial ? (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { gap: 2, children: [_jsx(Text, { dimColor: true, children: "\u203A" }), _jsx(Text, { dimColor: true, children: phase.nl })] }), _jsxs(Box, { gap: 2, paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: "$" }), _jsx(Text, { dimColor: true, children: phase.partial })] })] })) : _jsx(Spinner, { label: "translating" })), phase.type === "running" && (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [_jsxs(Box, { gap: 2, children: [_jsx(Text, { dimColor: true, children: "$" }), _jsx(Text, { dimColor: true, children: phase.command })] }), _jsx(Box, { flexDirection: "column", paddingLeft: 2, children: tab.streamLines.slice(-MAX_LINES).map((l, i) => _jsx(Text, { children: l }, i)) }), _jsx(Spinner, { label: "ctrl+c to cancel" })] })), phase.type === "error" && (_jsx(Box, { paddingLeft: 2, children: _jsx(Text, { color: "red", children: phase.message }) })), phase.type === "input" && (_jsxs(Box, { gap: 2, paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: isRaw ? "$" : "›" }), _jsxs(Box, { children: [_jsx(Text, { children: phase.value.slice(0, phase.cursor) }), _jsx(Text, { inverse: true, children: phase.value[phase.cursor] ?? " " }), _jsx(Text, { children: phase.value.slice(phase.cursor + 1) }), ghost && phase.cursor === phase.value.length && (_jsx(Text, { dimColor: true, children: ghost }))] })] })), _jsx(StatusBar, { permissions: config.permissions, cwd: tab.cwd })] }));
|
|
394
|
+
}
|
|
395
|
+
// ── TabBar ────────────────────────────────────────────────────────────────────
|
|
396
|
+
function TabBar({ tabs, active }) {
|
|
397
|
+
return (_jsxs(Box, { gap: 1, paddingLeft: 2, marginBottom: 1, children: [tabs.map((t, i) => {
|
|
398
|
+
const label = ` ${i + 1} `;
|
|
399
|
+
const cwd = t.cwd.split("/").pop() || t.cwd;
|
|
400
|
+
return (_jsx(Box, { children: i === active
|
|
401
|
+
? _jsxs(Text, { inverse: true, children: [label, cwd] })
|
|
402
|
+
: _jsxs(Text, { dimColor: true, children: [label, cwd] }) }, t.id));
|
|
403
|
+
}), _jsx(Text, { dimColor: true, children: " ctrl+t new tab switch ctrl+w close" })] }));
|
|
404
|
+
}
|
package/dist/Browse.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
import { Box, Text, useInput } from "ink";
|
|
4
|
+
import { readdirSync, statSync } from "fs";
|
|
5
|
+
import { join, dirname } from "path";
|
|
6
|
+
function readDir(dir) {
|
|
7
|
+
try {
|
|
8
|
+
const names = readdirSync(dir);
|
|
9
|
+
const entries = [];
|
|
10
|
+
for (const name of names) {
|
|
11
|
+
try {
|
|
12
|
+
const stat = statSync(join(dir, name));
|
|
13
|
+
entries.push({ name, isDir: stat.isDirectory() });
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
entries.push({ name, isDir: false });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
entries.sort((a, b) => {
|
|
20
|
+
if (a.isDir !== b.isDir)
|
|
21
|
+
return a.isDir ? -1 : 1;
|
|
22
|
+
return a.name.localeCompare(b.name);
|
|
23
|
+
});
|
|
24
|
+
return entries;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const PAGE = 20;
|
|
31
|
+
export default function Browse({ cwd, onCd, onSelect, onExit }) {
|
|
32
|
+
const [cursor, setCursor] = useState(0);
|
|
33
|
+
const entries = readDir(cwd);
|
|
34
|
+
const total = entries.length;
|
|
35
|
+
const safeIndex = Math.min(cursor, Math.max(0, total - 1));
|
|
36
|
+
const start = Math.max(0, Math.min(safeIndex - Math.floor(PAGE / 2), total - PAGE));
|
|
37
|
+
const slice = entries.slice(Math.max(0, start), Math.max(0, start) + PAGE);
|
|
38
|
+
useInput(useCallback((_input, key) => {
|
|
39
|
+
if (key.upArrow) {
|
|
40
|
+
setCursor(c => (c <= 0 ? Math.max(0, total - 1) : c - 1));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (key.downArrow) {
|
|
44
|
+
setCursor(c => (total === 0 ? 0 : (c >= total - 1 ? 0 : c + 1)));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (key.return) {
|
|
48
|
+
if (total === 0)
|
|
49
|
+
return;
|
|
50
|
+
const entry = entries[safeIndex];
|
|
51
|
+
if (!entry)
|
|
52
|
+
return;
|
|
53
|
+
const full = join(cwd, entry.name);
|
|
54
|
+
if (entry.isDir) {
|
|
55
|
+
setCursor(0);
|
|
56
|
+
onCd(full);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
onSelect(full);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (key.backspace || key.delete || key.leftArrow) {
|
|
64
|
+
setCursor(0);
|
|
65
|
+
onCd(dirname(cwd));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (key.escape) {
|
|
69
|
+
onExit();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}, [cwd, entries, safeIndex, total, onCd, onSelect, onExit]));
|
|
73
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: cwd }), total === 0 && _jsx(Text, { dimColor: true, children: " (empty)" }), slice.map((entry, i) => {
|
|
74
|
+
const absIdx = Math.max(0, start) + i;
|
|
75
|
+
const selected = absIdx === safeIndex;
|
|
76
|
+
const icon = entry.isDir ? "▸" : "·";
|
|
77
|
+
return (_jsx(Box, { children: _jsx(Text, { inverse: selected, children: ` ${icon} ${entry.name}${entry.isDir ? "/" : ""} ` }) }, entry.name));
|
|
78
|
+
}), _jsx(Text, { dimColor: true, children: " enter backspace esc" })] }));
|
|
79
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
import { Box, Text, useInput } from "ink";
|
|
4
|
+
const MAX_MATCHES = 10;
|
|
5
|
+
export default function FuzzyPicker({ history, onSelect, onExit }) {
|
|
6
|
+
const [query, setQuery] = useState("");
|
|
7
|
+
const [cursor, setCursor] = useState(0);
|
|
8
|
+
const matches = query === ""
|
|
9
|
+
? history.slice().reverse().slice(0, MAX_MATCHES)
|
|
10
|
+
: history.slice().reverse().filter(h => h.toLowerCase().includes(query.toLowerCase())).slice(0, MAX_MATCHES);
|
|
11
|
+
const safeCursor = Math.min(cursor, Math.max(0, matches.length - 1));
|
|
12
|
+
useInput(useCallback((_input, key) => {
|
|
13
|
+
if (key.escape || key.ctrl && _input === "c") {
|
|
14
|
+
onExit();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (key.return) {
|
|
18
|
+
if (matches.length > 0) {
|
|
19
|
+
onSelect(matches[safeCursor]);
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (key.upArrow) {
|
|
24
|
+
setCursor(c => Math.max(0, c - 1));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (key.downArrow) {
|
|
28
|
+
setCursor(c => Math.min(matches.length - 1, c + 1));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (key.backspace || key.delete) {
|
|
32
|
+
setQuery(q => q.slice(0, -1));
|
|
33
|
+
setCursor(0);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!key.ctrl && !key.meta && _input && _input.length === 1) {
|
|
37
|
+
setQuery(q => q + _input);
|
|
38
|
+
setCursor(0);
|
|
39
|
+
}
|
|
40
|
+
}, [matches, safeCursor, onSelect, onExit]));
|
|
41
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: ` / ${query}_` }), matches.length === 0
|
|
42
|
+
? _jsx(Text, { dimColor: true, children: " no matches" })
|
|
43
|
+
: matches.map((m, i) => {
|
|
44
|
+
const selected = i === safeCursor;
|
|
45
|
+
return (_jsx(Box, { children: _jsx(Text, { inverse: selected, dimColor: !selected, children: ` ${m} ` }) }, i));
|
|
46
|
+
}), _jsx(Text, { dimColor: true, children: " enter esc" })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Box, Text, useInput } from "ink";
|
|
4
|
+
import { DEFAULT_PERMISSIONS } from "./history.js";
|
|
5
|
+
const PERM_KEYS = [
|
|
6
|
+
{ key: "destructive", label: "destructive", hint: "rm, delete, drop…" },
|
|
7
|
+
{ key: "network", label: "network", hint: "curl, wget, ssh…" },
|
|
8
|
+
{ key: "sudo", label: "sudo", hint: "root-level commands" },
|
|
9
|
+
{ key: "install", label: "install", hint: "brew, npm -g, pip…" },
|
|
10
|
+
{ key: "write_outside_cwd", label: "write outside", hint: "files outside current dir" },
|
|
11
|
+
];
|
|
12
|
+
export default function Onboarding({ onDone }) {
|
|
13
|
+
const [step, setStep] = useState("welcome");
|
|
14
|
+
const [cursor, setCursor] = useState(0);
|
|
15
|
+
const [perms, setPerms] = useState({ ...DEFAULT_PERMISSIONS });
|
|
16
|
+
useInput((input, key) => {
|
|
17
|
+
if (key.ctrl && input === "c")
|
|
18
|
+
process.exit(0);
|
|
19
|
+
if (step === "welcome") {
|
|
20
|
+
setStep("permissions");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (step === "permissions") {
|
|
24
|
+
if (key.upArrow) {
|
|
25
|
+
setCursor((c) => Math.max(0, c - 1));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (key.downArrow) {
|
|
29
|
+
setCursor((c) => Math.min(PERM_KEYS.length - 1, c + 1));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (input === " ") {
|
|
33
|
+
const k = PERM_KEYS[cursor].key;
|
|
34
|
+
setPerms((p) => ({ ...p, [k]: !p[k] }));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (key.return) {
|
|
38
|
+
onDone(perms);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (step === "welcome") {
|
|
44
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, gap: 1, paddingTop: 1, children: [_jsx(Text, { children: "terminal" }), _jsx(Text, { dimColor: true, children: "speak plain english, run commands" }), _jsxs(Box, { flexDirection: "column", marginTop: 1, gap: 0, children: [_jsx(Text, { dimColor: true, children: "\u203A type what you want" }), _jsx(Text, { dimColor: true, children: "$ see the command before it runs" }), _jsx(Text, { dimColor: true, children: "\u2191\u2193 browse history" }), _jsx(Text, { dimColor: true, children: "? explain a command before running" }), _jsx(Text, { dimColor: true, children: "ctrl+r toggle raw shell mode" })] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "any key to set permissions \u2192" }) })] }));
|
|
45
|
+
}
|
|
46
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, gap: 1, paddingTop: 1, children: [_jsx(Text, { dimColor: true, children: "what can the AI run?" }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: PERM_KEYS.map((p, i) => {
|
|
47
|
+
const active = cursor === i;
|
|
48
|
+
const on = perms[p.key];
|
|
49
|
+
return (_jsxs(Box, { gap: 2, children: [_jsx(Text, { dimColor: true, children: active ? "›" : " " }), _jsx(Text, { color: on ? undefined : "red", children: on ? "✓" : "✗" }), _jsx(Text, { bold: active, children: p.label }), _jsx(Text, { dimColor: true, children: p.hint })] }, p.key));
|
|
50
|
+
}) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "space toggle \u00B7 enter confirm" }) }), _jsx(Text, { dimColor: true, children: "edit later: ~/.terminal/config.json" })] }));
|
|
51
|
+
}
|
package/dist/Spinner.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { Text } from "ink";
|
|
4
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
5
|
+
export default function Spinner({ label }) {
|
|
6
|
+
const [frame, setFrame] = useState(0);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const t = setInterval(() => setFrame((f) => (f + 1) % FRAMES.length), 80);
|
|
9
|
+
return () => clearInterval(t);
|
|
10
|
+
}, []);
|
|
11
|
+
return (_jsxs(Text, { dimColor: true, children: [" ", FRAMES[frame], " ", label] }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
function formatCwd(cwd) {
|
|
6
|
+
const home = homedir();
|
|
7
|
+
return cwd.startsWith(home) ? "~" + cwd.slice(home.length) : cwd;
|
|
8
|
+
}
|
|
9
|
+
function getGitBranch(cwd) {
|
|
10
|
+
try {
|
|
11
|
+
return execSync("git branch --show-current 2>/dev/null", {
|
|
12
|
+
cwd,
|
|
13
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
14
|
+
}).toString().trim() || null;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function getGitDirty(cwd) {
|
|
21
|
+
try {
|
|
22
|
+
return execSync("git status --porcelain 2>/dev/null", {
|
|
23
|
+
cwd,
|
|
24
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
25
|
+
}).toString().trim().length > 0;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function activePerms(perms) {
|
|
32
|
+
const labels = [
|
|
33
|
+
["destructive", "del"],
|
|
34
|
+
["network", "net"],
|
|
35
|
+
["sudo", "sudo"],
|
|
36
|
+
["install", "pkg"],
|
|
37
|
+
["write_outside_cwd", "write"],
|
|
38
|
+
];
|
|
39
|
+
// only show disabled ones — full access is the default so no need to clutter
|
|
40
|
+
const disabled = labels.filter(([k]) => !perms[k]).map(([, l]) => `no-${l}`);
|
|
41
|
+
return disabled;
|
|
42
|
+
}
|
|
43
|
+
export default function StatusBar({ permissions, cwd: cwdProp }) {
|
|
44
|
+
const cwd = cwdProp ?? process.cwd();
|
|
45
|
+
const branch = getGitBranch(cwd);
|
|
46
|
+
const dirty = branch ? getGitDirty(cwd) : false;
|
|
47
|
+
const restricted = activePerms(permissions);
|
|
48
|
+
return (_jsxs(Box, { gap: 2, paddingLeft: 2, marginTop: 1, children: [_jsx(Text, { dimColor: true, children: formatCwd(cwd) }), branch && _jsxs(Text, { dimColor: true, children: [branch, dirty ? " ●" : ""] }), restricted.length > 0 && _jsx(Text, { dimColor: true, children: restricted.join(" · ") })] }));
|
|
49
|
+
}
|