@hasna/terminal 2.0.5 → 2.3.0
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/cli.js +52 -21
- package/package.json +1 -1
- package/src/ai.ts +77 -130
- package/src/cli.tsx +51 -21
- package/src/command-validator.ts +11 -0
- package/src/context-hints.ts +291 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-processor.ts +7 -18
- package/src/output-store.ts +65 -0
- package/src/providers/base.ts +3 -1
- package/src/providers/groq.ts +108 -0
- package/src/providers/index.ts +26 -2
- package/src/providers/providers.test.ts +4 -2
- package/src/providers/xai.ts +108 -0
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
- 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 -368
- package/dist/cache.js +0 -41
- package/dist/command-rewriter.js +0 -64
- package/dist/command-validator.js +0 -77
- package/dist/compression.js +0 -107
- package/dist/diff-cache.js +0 -107
- package/dist/economy.js +0 -79
- package/dist/expand-store.js +0 -38
- 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 -98
- package/dist/mcp/server.js +0 -569
- package/dist/noise-filter.js +0 -86
- package/dist/output-processor.js +0 -136
- package/dist/output-router.js +0 -41
- 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 -39
- package/dist/providers/base.js +0 -4
- package/dist/providers/cerebras.js +0 -95
- package/dist/providers/index.js +0 -49
- package/dist/recipes/model.js +0 -20
- package/dist/recipes/storage.js +0 -136
- package/dist/search/content-search.js +0 -68
- 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 -320
- package/dist/session-boot.js +0 -59
- package/dist/session-context.js +0 -55
- package/dist/sessions-db.js +0 -120
- 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/tree.js +0 -94
- package/dist/usage-cache.js +0 -65
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Determining projects to restore...
|
|
2
|
+
All projects are up-to-date for restore.
|
|
3
|
+
RtkDotnetSmoke -> /private/tmp/RtkDotnetSmoke/bin/Debug/net10.0/RtkDotnetSmoke.dll
|
|
4
|
+
Test run for /private/tmp/RtkDotnetSmoke/bin/Debug/net10.0/RtkDotnetSmoke.dll (.NETCoreApp,Version=v10.0)
|
|
5
|
+
VSTest version 18.0.1 (arm64)
|
|
6
|
+
|
|
7
|
+
Starting test execution, please wait...
|
|
8
|
+
A total of 1 test files matched the specified pattern.
|
|
9
|
+
[xUnit.net 00:00:00.11] RtkDotnetSmoke.UnitTest1.Test1 [FAIL]
|
|
10
|
+
Failed RtkDotnetSmoke.UnitTest1.Test1 [4 ms]
|
|
11
|
+
Error Message:
|
|
12
|
+
Assert.Equal() Failure: Values differ
|
|
13
|
+
Expected: 2
|
|
14
|
+
Actual: 3
|
|
15
|
+
Stack Trace:
|
|
16
|
+
at RtkDotnetSmoke.UnitTest1.Test1() in /private/tmp/RtkDotnetSmoke/UnitTest1.cs:line 8
|
|
17
|
+
|
|
18
|
+
Failed! - Failed: 1, Passed: 0, Skipped: 0, Total: 1, Duration: 13 ms - RtkDotnetSmoke.dll (net10.0)
|
package/dist/App.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/FuzzyPicker.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/Onboarding.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|