march-cli 0.1.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/bin/march.mjs +13 -0
- package/package.json +36 -0
- package/src/agent/command-exec-tool.mjs +91 -0
- package/src/agent/context-stats-tool.mjs +57 -0
- package/src/agent/editing/diff-apply.mjs +28 -0
- package/src/agent/editing/diff-format.mjs +57 -0
- package/src/agent/file-edit-tool.mjs +276 -0
- package/src/agent/find-tool.mjs +112 -0
- package/src/agent/model-payload-dumper.mjs +201 -0
- package/src/agent/pi-session/pi-session-sidecar-failure.mjs +10 -0
- package/src/agent/provider/payload-messages.mjs +138 -0
- package/src/agent/read-file-tool.mjs +112 -0
- package/src/agent/runner/fast-model.mjs +36 -0
- package/src/agent/runner/runner-cleanup.mjs +12 -0
- package/src/agent/runner/runner-init.mjs +15 -0
- package/src/agent/runner/runner-session-state.mjs +40 -0
- package/src/agent/runner.mjs +266 -0
- package/src/agent/runtime/runner-runtime-host.mjs +73 -0
- package/src/agent/runtime/runtime-factory.mjs +42 -0
- package/src/agent/runtime/runtime-host.mjs +34 -0
- package/src/agent/session/session-auto-name.mjs +41 -0
- package/src/agent/session/session-binding.mjs +12 -0
- package/src/agent/session/session-options.mjs +46 -0
- package/src/agent/tool-names.mjs +1 -0
- package/src/agent/tool-result.mjs +3 -0
- package/src/agent/tools.mjs +54 -0
- package/src/agent/turn/turn-events.mjs +64 -0
- package/src/agent/turn/turn-runner.mjs +103 -0
- package/src/auth/login-command.mjs +90 -0
- package/src/auth/storage.mjs +33 -0
- package/src/cli/args.mjs +71 -0
- package/src/cli/commands/copy-command.mjs +73 -0
- package/src/cli/commands/export-command.mjs +206 -0
- package/src/cli/commands/extensions-command.mjs +53 -0
- package/src/cli/commands/help-command.mjs +7 -0
- package/src/cli/commands/model-command.mjs +110 -0
- package/src/cli/commands/paste-image-command.mjs +43 -0
- package/src/cli/commands/provider-command.mjs +55 -0
- package/src/cli/commands/status-command.mjs +157 -0
- package/src/cli/commands/thinking-command.mjs +80 -0
- package/src/cli/fallback-ui.mjs +156 -0
- package/src/cli/input/attachment-tokens.mjs +20 -0
- package/src/cli/input/autocomplete.mjs +106 -0
- package/src/cli/input/external-editor.mjs +39 -0
- package/src/cli/input/history-store.mjs +35 -0
- package/src/cli/input/image-clipboard.mjs +55 -0
- package/src/cli/input/keybinding-dispatch.mjs +76 -0
- package/src/cli/input/keybindings.mjs +96 -0
- package/src/cli/input/mode-state.mjs +43 -0
- package/src/cli/input/prompt-templates.mjs +84 -0
- package/src/cli/input/select-with-keyboard.mjs +67 -0
- package/src/cli/permissions.mjs +103 -0
- package/src/cli/repl-commands.mjs +86 -0
- package/src/cli/repl-loop.mjs +157 -0
- package/src/cli/selector-list.mjs +21 -0
- package/src/cli/session/pi-session-switch-command.mjs +41 -0
- package/src/cli/session/session-command.mjs +23 -0
- package/src/cli/session/session-list-command.mjs +68 -0
- package/src/cli/session/session-name-command.mjs +26 -0
- package/src/cli/session/session-source-command.mjs +89 -0
- package/src/cli/session/session-switch-command.mjs +1 -0
- package/src/cli/shell/shell-command.mjs +55 -0
- package/src/cli/shell/shell-drawer-controls.mjs +33 -0
- package/src/cli/shell/shell-drawer.mjs +192 -0
- package/src/cli/shell/shell-split-layout.mjs +70 -0
- package/src/cli/slash-commands.mjs +176 -0
- package/src/cli/startup/startup-banner.mjs +17 -0
- package/src/cli/startup/startup-session.mjs +51 -0
- package/src/cli/status-line-updater.mjs +74 -0
- package/src/cli/tool-output.mjs +9 -0
- package/src/cli/tui/editor/external-editor-runner.mjs +24 -0
- package/src/cli/tui/input/mouse-selection-controller.mjs +89 -0
- package/src/cli/tui/input/mouse-tracking.mjs +20 -0
- package/src/cli/tui/layout/main-pane-layout.mjs +38 -0
- package/src/cli/tui/layout/safe-render-boundary.mjs +46 -0
- package/src/cli/tui/markdown-renderer.mjs +279 -0
- package/src/cli/tui/output/scroll-state.mjs +79 -0
- package/src/cli/tui/output/tool-card-renderer.mjs +59 -0
- package/src/cli/tui/output-buffer.mjs +297 -0
- package/src/cli/tui/permission-request-ui.mjs +18 -0
- package/src/cli/tui/recall-rendering.mjs +25 -0
- package/src/cli/tui/select/editor-select-list.mjs +111 -0
- package/src/cli/tui/selection-screen.mjs +212 -0
- package/src/cli/tui/status/retry-status.mjs +72 -0
- package/src/cli/tui/status/spinner-status.mjs +42 -0
- package/src/cli/tui/status/status-bar.mjs +88 -0
- package/src/cli/tui/syntax/highlighting.mjs +277 -0
- package/src/cli/tui/syntax/languages.mjs +91 -0
- package/src/cli/tui/syntax/tree-sitter/bash.highlights.scm +261 -0
- package/src/cli/tui/syntax/tree-sitter/c.highlights.scm +341 -0
- package/src/cli/tui/syntax/tree-sitter/cpp.highlights.scm +268 -0
- package/src/cli/tui/syntax/tree-sitter/csharp.highlights.scm +577 -0
- package/src/cli/tui/syntax/tree-sitter/css.highlights.scm +109 -0
- package/src/cli/tui/syntax/tree-sitter/diff.highlights.scm +49 -0
- package/src/cli/tui/syntax/tree-sitter/go.highlights.scm +254 -0
- package/src/cli/tui/syntax/tree-sitter/html.highlights.scm +13 -0
- package/src/cli/tui/syntax/tree-sitter/java.highlights.scm +330 -0
- package/src/cli/tui/syntax/tree-sitter/json.highlights.scm +38 -0
- package/src/cli/tui/syntax/tree-sitter/php.highlights.scm +203 -0
- package/src/cli/tui/syntax/tree-sitter/python.highlights.scm +137 -0
- package/src/cli/tui/syntax/tree-sitter/ruby.highlights.scm +309 -0
- package/src/cli/tui/syntax/tree-sitter/rust.highlights.scm +531 -0
- package/src/cli/tui/syntax/tree-sitter/toml.highlights.scm +39 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-bash.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c-sharp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-cpp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-css.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-diff.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-go.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-html.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-java.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-json.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-php.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-python.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-ruby.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-rust.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-toml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-yaml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tsx.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/typescript.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/yaml.highlights.scm +99 -0
- package/src/cli/tui/tool-rendering.mjs +194 -0
- package/src/cli/tui/tui-diff-rendering.mjs +157 -0
- package/src/cli/tui/tui-handlers.mjs +110 -0
- package/src/cli/tui/tui-input-controller.mjs +61 -0
- package/src/cli/tui/ui-theme.mjs +148 -0
- package/src/cli/ui.mjs +299 -0
- package/src/config/config-json.mjs +73 -0
- package/src/config/dotenv.mjs +20 -0
- package/src/config/features.mjs +75 -0
- package/src/config/loader.mjs +109 -0
- package/src/config/settings-command.mjs +97 -0
- package/src/context/diagnostics.mjs +70 -0
- package/src/context/engine.mjs +148 -0
- package/src/context/injections.mjs +26 -0
- package/src/context/project-context.mjs +20 -0
- package/src/context/session-status.mjs +15 -0
- package/src/context/shell-layers.mjs +23 -0
- package/src/context/system-core/base.md +60 -0
- package/src/context/system-core/prompts/deepseek-v4-pro.md +3 -0
- package/src/context/system-core/prompts/default.md +3 -0
- package/src/context/system-core.mjs +35 -0
- package/src/debug/model-context-dumper.mjs +52 -0
- package/src/extensions/discovery.mjs +40 -0
- package/src/extensions/lifecycle-adapter.mjs +210 -0
- package/src/extensions/lifecycle-manifest.mjs +69 -0
- package/src/image-gen/index.mjs +7 -0
- package/src/image-gen/provider.mjs +231 -0
- package/src/image-gen/tool.mjs +84 -0
- package/src/lsp/client.mjs +204 -0
- package/src/lsp/diagnostic-store.mjs +39 -0
- package/src/lsp/servers.mjs +212 -0
- package/src/lsp/service.mjs +65 -0
- package/src/main.mjs +294 -0
- package/src/mcp/client.mjs +195 -0
- package/src/mcp/config.mjs +130 -0
- package/src/mcp/index.mjs +48 -0
- package/src/mcp/tools.mjs +98 -0
- package/src/memory/database.mjs +219 -0
- package/src/memory/glossary.mjs +124 -0
- package/src/memory/graph/graph-cascades.mjs +109 -0
- package/src/memory/graph/graph-diagnostics.mjs +73 -0
- package/src/memory/graph/graph-path-removal.mjs +50 -0
- package/src/memory/graph/graph-path-utils.mjs +17 -0
- package/src/memory/graph/graph-primitives.mjs +103 -0
- package/src/memory/graph/graph-read.mjs +159 -0
- package/src/memory/graph.mjs +282 -0
- package/src/memory/markdown/markdown-delete.mjs +23 -0
- package/src/memory/markdown/markdown-format.mjs +128 -0
- package/src/memory/markdown/markdown-recall.mjs +28 -0
- package/src/memory/markdown/ripgrep.mjs +16 -0
- package/src/memory/markdown/sqlite-index.mjs +87 -0
- package/src/memory/markdown-store.mjs +286 -0
- package/src/memory/markdown-tools.mjs +103 -0
- package/src/memory/search.mjs +142 -0
- package/src/memory/snapshot.mjs +86 -0
- package/src/memory/system-views.mjs +120 -0
- package/src/memory/tools.mjs +282 -0
- package/src/notification/desktop-notifier.mjs +85 -0
- package/src/platform/open-file.mjs +28 -0
- package/src/provider/config-command.mjs +129 -0
- package/src/provider/presets.mjs +72 -0
- package/src/session/attachment-display.mjs +16 -0
- package/src/session/attachment-references.mjs +65 -0
- package/src/session/attachments.mjs +140 -0
- package/src/session/persist.mjs +1 -0
- package/src/session/pi-manager.mjs +34 -0
- package/src/session/session-utils.mjs +16 -0
- package/src/session/sidecar-sync.mjs +19 -0
- package/src/session/sidecar.mjs +68 -0
- package/src/session/transcript.mjs +83 -0
- package/src/session/tree.mjs +42 -0
- package/src/shell/cli-runtime.mjs +11 -0
- package/src/shell/hints.mjs +12 -0
- package/src/shell/node-pty-adapter.mjs +81 -0
- package/src/shell/runtime-state.mjs +126 -0
- package/src/shell/runtime.mjs +244 -0
- package/src/shell/screen-buffer.mjs +136 -0
- package/src/shell/tool-read.mjs +74 -0
- package/src/shell/tools.mjs +299 -0
- package/src/supergrok/actions/image-generate.mjs +60 -0
- package/src/supergrok/actions/search.mjs +78 -0
- package/src/supergrok/auth.mjs +36 -0
- package/src/supergrok/constants.mjs +18 -0
- package/src/supergrok/oauth-provider.mjs +278 -0
- package/src/supergrok/provider.mjs +36 -0
- package/src/supergrok/response.mjs +76 -0
- package/src/supergrok/tool.mjs +61 -0
- package/src/text/ansi.mjs +3 -0
- package/src/web/config-command.mjs +43 -0
- package/src/web/fetch.mjs +78 -0
- package/src/web/presets.mjs +16 -0
- package/src/web/search.mjs +83 -0
- package/src/web/tools.mjs +107 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
(boolean_scalar) @boolean
|
|
2
|
+
|
|
3
|
+
(null_scalar) @constant.builtin
|
|
4
|
+
|
|
5
|
+
(double_quote_scalar) @string
|
|
6
|
+
|
|
7
|
+
(single_quote_scalar) @string
|
|
8
|
+
|
|
9
|
+
((block_scalar) @string
|
|
10
|
+
(#set! priority 99))
|
|
11
|
+
|
|
12
|
+
(string_scalar) @string
|
|
13
|
+
|
|
14
|
+
(escape_sequence) @string.escape
|
|
15
|
+
|
|
16
|
+
(integer_scalar) @number
|
|
17
|
+
|
|
18
|
+
(float_scalar) @number
|
|
19
|
+
|
|
20
|
+
(comment) @comment @spell
|
|
21
|
+
|
|
22
|
+
[
|
|
23
|
+
(anchor_name)
|
|
24
|
+
(alias_name)
|
|
25
|
+
] @label
|
|
26
|
+
|
|
27
|
+
(tag) @type
|
|
28
|
+
|
|
29
|
+
[
|
|
30
|
+
(yaml_directive)
|
|
31
|
+
(tag_directive)
|
|
32
|
+
(reserved_directive)
|
|
33
|
+
] @keyword.directive
|
|
34
|
+
|
|
35
|
+
(block_mapping_pair
|
|
36
|
+
key: (flow_node
|
|
37
|
+
[
|
|
38
|
+
(double_quote_scalar)
|
|
39
|
+
(single_quote_scalar)
|
|
40
|
+
] @property))
|
|
41
|
+
|
|
42
|
+
(block_mapping_pair
|
|
43
|
+
key: (flow_node
|
|
44
|
+
(plain_scalar
|
|
45
|
+
(string_scalar) @property)))
|
|
46
|
+
|
|
47
|
+
(flow_mapping
|
|
48
|
+
(_
|
|
49
|
+
key: (flow_node
|
|
50
|
+
[
|
|
51
|
+
(double_quote_scalar)
|
|
52
|
+
(single_quote_scalar)
|
|
53
|
+
] @property)))
|
|
54
|
+
|
|
55
|
+
(flow_mapping
|
|
56
|
+
(_
|
|
57
|
+
key: (flow_node
|
|
58
|
+
(plain_scalar
|
|
59
|
+
(string_scalar) @property))))
|
|
60
|
+
|
|
61
|
+
[
|
|
62
|
+
","
|
|
63
|
+
"-"
|
|
64
|
+
":"
|
|
65
|
+
">"
|
|
66
|
+
"?"
|
|
67
|
+
"|"
|
|
68
|
+
] @punctuation.delimiter
|
|
69
|
+
|
|
70
|
+
[
|
|
71
|
+
"["
|
|
72
|
+
"]"
|
|
73
|
+
"{"
|
|
74
|
+
"}"
|
|
75
|
+
] @punctuation.bracket
|
|
76
|
+
|
|
77
|
+
[
|
|
78
|
+
"*"
|
|
79
|
+
"&"
|
|
80
|
+
"---"
|
|
81
|
+
"..."
|
|
82
|
+
] @punctuation.special
|
|
83
|
+
|
|
84
|
+
; help deal with for yaml's norway problem https://www.bram.us/2022/01/11/yaml-the-norway-problem/
|
|
85
|
+
; only using `true` and `false`, since Treesitter parser targets YAML spec 1.2 https://github.com/nvim-treesitter/nvim-treesitter/pull/7512#issuecomment-2565397302
|
|
86
|
+
(block_mapping_pair
|
|
87
|
+
value: (block_node
|
|
88
|
+
(block_sequence
|
|
89
|
+
(block_sequence_item
|
|
90
|
+
(flow_node
|
|
91
|
+
(plain_scalar
|
|
92
|
+
(string_scalar) @boolean
|
|
93
|
+
(#any-of? @boolean "TRUE" "FALSE" "True" "False")))))))
|
|
94
|
+
|
|
95
|
+
(block_mapping_pair
|
|
96
|
+
value: (flow_node
|
|
97
|
+
(plain_scalar
|
|
98
|
+
(string_scalar) @boolean
|
|
99
|
+
(#any-of? @boolean "TRUE" "FALSE" "True" "False"))))
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { extractToolOutput } from "../tool-output.mjs";
|
|
2
|
+
import { dim, red } from "./ui-theme.mjs";
|
|
3
|
+
|
|
4
|
+
const TOOL_BODY_LIMIT = 40;
|
|
5
|
+
const TOOL_ERROR_LIMIT = 6;
|
|
6
|
+
|
|
7
|
+
export function writeToolStart({ output, name, args }) {
|
|
8
|
+
const block = createToolCardBlock({ name, args });
|
|
9
|
+
writeStructuredLines(output, block);
|
|
10
|
+
return block;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createToolCardBlock({ name, args }) {
|
|
14
|
+
return {
|
|
15
|
+
type: "tool-card",
|
|
16
|
+
name,
|
|
17
|
+
args,
|
|
18
|
+
title: formatToolStartLine(name, args),
|
|
19
|
+
state: "running",
|
|
20
|
+
isError: false,
|
|
21
|
+
summary: "running",
|
|
22
|
+
bodyLines: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function writeToolEnd({
|
|
27
|
+
output,
|
|
28
|
+
name,
|
|
29
|
+
isError,
|
|
30
|
+
result,
|
|
31
|
+
toolsExpanded = false,
|
|
32
|
+
extractToolOutputImpl = extractToolOutput,
|
|
33
|
+
toolBlock = null,
|
|
34
|
+
}) {
|
|
35
|
+
const card = formatToolEndCard({ name, isError, result, extractToolOutputImpl });
|
|
36
|
+
if (toolBlock?.type === "tool-card") {
|
|
37
|
+
Object.assign(toolBlock, card, { expanded: toolsExpanded });
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const lines = renderToolEndFallbackLines({ name, card, toolsExpanded });
|
|
42
|
+
if (!lines.length) return false;
|
|
43
|
+
writeStructuredLines(output, { type: "tool", lines });
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function formatToolStartLine(name, args = {}) {
|
|
48
|
+
if (name === "edit_file") {
|
|
49
|
+
const path = compactPath(args?.path ?? "");
|
|
50
|
+
const editCount = Array.isArray(args?.edits) ? args.edits.length : 0;
|
|
51
|
+
const mode = args?.mode ?? "patch";
|
|
52
|
+
const summary = mode === "patch" ? `${editCount} edit${editCount === 1 ? "" : "s"}` : mode;
|
|
53
|
+
return joinToolParts("◆", name, [path, summary]);
|
|
54
|
+
}
|
|
55
|
+
if (name === "command_exec") return joinToolParts("◆", name, [compactText(args?.command ?? "")]);
|
|
56
|
+
if (name === "terminal_send") return joinToolParts("◆", name, [args?.shell_id, formatTerminalSendAction(args)]);
|
|
57
|
+
if (name?.startsWith?.("terminal_")) return joinToolParts("◆", name, [args?.shell_id, formatTerminalDetails(args)]);
|
|
58
|
+
if (name === "web_search") return joinToolParts("◆", name, [quoteCompact(args?.query ?? "")]);
|
|
59
|
+
if (name === "web_fetch") return joinToolParts("◆", name, [compactText(args?.url ?? "")]);
|
|
60
|
+
if (name === "context_stats") return joinToolParts("◆", name, []);
|
|
61
|
+
if (name === "read") {
|
|
62
|
+
const path = compactPath(args?.path ?? args?.filePath ?? "");
|
|
63
|
+
return joinToolParts("→", name, [path, formatReadRange(args)]);
|
|
64
|
+
}
|
|
65
|
+
if (name === "grep") {
|
|
66
|
+
const path = compactPath(args?.path ?? "");
|
|
67
|
+
return joinToolParts("✱", name, [quoteCompact(args?.pattern ?? ""), path]);
|
|
68
|
+
}
|
|
69
|
+
if (name === "glob") {
|
|
70
|
+
const path = compactPath(args?.path ?? "");
|
|
71
|
+
return joinToolParts("✱", name, [quoteCompact(args?.pattern ?? ""), path]);
|
|
72
|
+
}
|
|
73
|
+
if (name === "find") {
|
|
74
|
+
const path = compactPath(args?.path ?? "");
|
|
75
|
+
return joinToolParts("✱", name, [quoteCompact(args?.pattern ?? ""), path]);
|
|
76
|
+
}
|
|
77
|
+
return joinToolParts("◆", name, [formatSmallOptions(args)]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function formatToolSuccessSummary(name, result, out = "") {
|
|
81
|
+
if (name === "grep") {
|
|
82
|
+
const matches = result?.details?.results?.length ?? countMatchLines(out);
|
|
83
|
+
return `${matches} match${matches === 1 ? "" : "es"}`;
|
|
84
|
+
}
|
|
85
|
+
if (name === "glob") {
|
|
86
|
+
const matches = Array.isArray(result?.details?.matches) ? result.details.matches.length : countNonEmptyLines(out);
|
|
87
|
+
return `${matches} file${matches === 1 ? "" : "s"}`;
|
|
88
|
+
}
|
|
89
|
+
if (name === "find") {
|
|
90
|
+
const matches = result?.details?.count ?? countNonEmptyLines(out);
|
|
91
|
+
return `${matches} file${matches === 1 ? "" : "s"}`;
|
|
92
|
+
}
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function formatToolEndCard({ name, isError, result, extractToolOutputImpl }) {
|
|
97
|
+
const out = extractToolOutputImpl(result);
|
|
98
|
+
if (isError) {
|
|
99
|
+
return {
|
|
100
|
+
state: "done",
|
|
101
|
+
isError: true,
|
|
102
|
+
summary: "failed",
|
|
103
|
+
bodyLines: out.split("\n").filter(Boolean).slice(0, TOOL_ERROR_LIMIT).map((line) => line.slice(0, 120)),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const summary = formatToolSuccessSummary(name, result, out) || "done";
|
|
108
|
+
return {
|
|
109
|
+
state: "done",
|
|
110
|
+
isError: false,
|
|
111
|
+
summary,
|
|
112
|
+
bodyLines: out ? out.split("\n").slice(0, TOOL_BODY_LIMIT).map((line) => line.slice(0, 120)) : [],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function renderToolEndFallbackLines({ name, card, toolsExpanded }) {
|
|
117
|
+
if (card.isError) {
|
|
118
|
+
return [
|
|
119
|
+
red(` ◆ ${name} failed`),
|
|
120
|
+
...card.bodyLines.map((line) => red(` ${line}`)),
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
if (!toolsExpanded) return card.summary && card.summary !== "done" ? [dim(` ${card.summary}`)] : [];
|
|
124
|
+
return card.bodyLines.map((line) => dim(` ${line}`));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function writeStructuredLines(output, block) {
|
|
128
|
+
if (typeof output.addBlock === "function") output.addBlock(block);
|
|
129
|
+
else {
|
|
130
|
+
const lines = block.lines ?? [dim(` ${block.title}`)];
|
|
131
|
+
for (const line of lines) output.writeln(line);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function joinToolParts(icon, name, parts) {
|
|
136
|
+
const clean = parts.map((part) => String(part ?? "").trim()).filter(Boolean);
|
|
137
|
+
return `${icon} ${name}${clean.length ? ` · ${clean.join(" · ")}` : ""}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function formatReadRange(args = {}) {
|
|
141
|
+
if (args.offset == null && args.limit == null) return "";
|
|
142
|
+
if (args.offset != null && args.limit != null) return `lines ${args.offset}-${Number(args.offset) + Number(args.limit) - 1}`;
|
|
143
|
+
if (args.offset != null) return `from line ${args.offset}`;
|
|
144
|
+
return `limit ${args.limit}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function formatTerminalSendAction(args = {}) {
|
|
148
|
+
const hasText = typeof args.text === "string" && args.text.length > 0;
|
|
149
|
+
const key = args.key ? String(args.key) : "";
|
|
150
|
+
if (hasText && key) return `text+${key}`;
|
|
151
|
+
if (hasText) return args.text.includes("\n") || args.text.includes("\r") ? "text+enter" : "text";
|
|
152
|
+
return key || "send";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function formatTerminalDetails(args = {}) {
|
|
156
|
+
const details = [];
|
|
157
|
+
if (args.pattern) details.push(quoteCompact(args.pattern));
|
|
158
|
+
if (args.cols && args.rows) details.push(`${args.cols}x${args.rows}`);
|
|
159
|
+
if (args.command) details.push(compactText(args.command));
|
|
160
|
+
return details.join(" · ");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function formatSmallOptions(args = {}) {
|
|
164
|
+
const parts = [];
|
|
165
|
+
for (const [key, value] of Object.entries(args ?? {})) {
|
|
166
|
+
if (value == null || typeof value === "object") continue;
|
|
167
|
+
parts.push(`${key}=${compactText(value)}`);
|
|
168
|
+
if (parts.length >= 2) break;
|
|
169
|
+
}
|
|
170
|
+
return parts.join(", ");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function compactPath(path) {
|
|
174
|
+
return String(path ?? "").split(/[/\\]/).filter(Boolean).slice(-4).join("\\");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function quoteCompact(value) {
|
|
178
|
+
return JSON.stringify(compactText(value));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function compactText(value, limit = 80) {
|
|
182
|
+
const text = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
183
|
+
return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function countMatchLines(text) {
|
|
187
|
+
const match = String(text ?? "").match(/(\d+)\s+matches?\b/i);
|
|
188
|
+
if (match) return Number(match[1]);
|
|
189
|
+
return countNonEmptyLines(text);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function countNonEmptyLines(text) {
|
|
193
|
+
return String(text ?? "").split("\n").filter(Boolean).length;
|
|
194
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { bold, dim, red, green, brightBlack } from "./ui-theme.mjs";
|
|
3
|
+
import { highlightCodeLine, styleSyntax } from "./syntax/highlighting.mjs";
|
|
4
|
+
|
|
5
|
+
const SPLIT_DIFF_MIN_WIDTH = 121;
|
|
6
|
+
const BG_DEL = "48;2;55;34;44";
|
|
7
|
+
const BG_ADD = "48;2;32;48;59";
|
|
8
|
+
const BG_CTX = "";
|
|
9
|
+
|
|
10
|
+
export function writeEditDiff({ output, path, diffLines }) {
|
|
11
|
+
const lines = formatEditDiffLines({ path, diffLines });
|
|
12
|
+
if (typeof output.addBlock === "function") output.addBlock({ type: "diff", path, diffLines, lines });
|
|
13
|
+
else for (const line of lines) output.writeln(line);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function renderEditDiffBlock(block, width) {
|
|
17
|
+
return formatEditDiffLines({ path: block.path, diffLines: block.diffLines ?? [], width });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formatEditDiffLines({ path, diffLines, width = 0 }) {
|
|
21
|
+
if (width >= SPLIT_DIFF_MIN_WIDTH) return formatSplitDiffLines({ path, diffLines, width });
|
|
22
|
+
return formatUnifiedDiffLines({ path, diffLines });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatUnifiedDiffLines({ path, diffLines }) {
|
|
26
|
+
const counts = countChanges(diffLines);
|
|
27
|
+
const summary = [`± ${path}`];
|
|
28
|
+
if (counts.del > 0) summary.push(red(`${counts.del}-`));
|
|
29
|
+
if (counts.add > 0) summary.push(green(`${counts.add}+`));
|
|
30
|
+
|
|
31
|
+
const lines = [bold(summary.join(" "))];
|
|
32
|
+
const gutterWidth = maxLineNumber(diffLines);
|
|
33
|
+
for (const line of diffLines) {
|
|
34
|
+
const num = line.lineNum != null ? String(line.lineNum).padStart(gutterWidth) : " ".repeat(gutterWidth);
|
|
35
|
+
if (line.type === "del") lines.push(formatUnifiedSide({ num, sign: "-", text: line.text, type: "del", path }));
|
|
36
|
+
else if (line.type === "add") lines.push(formatUnifiedSide({ num, sign: "+", text: line.text, type: "add", path }));
|
|
37
|
+
else lines.push(`${brightBlack(`${num} │`)} ${dim(` ${line.text}`)}`);
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function formatSplitDiffLines({ path, diffLines, width }) {
|
|
43
|
+
const rows = pairDiffRows(diffLines);
|
|
44
|
+
const counts = countChanges(diffLines);
|
|
45
|
+
const summary = [`± ${path}`];
|
|
46
|
+
if (counts.del > 0) summary.push(red(`${counts.del}-`));
|
|
47
|
+
if (counts.add > 0) summary.push(green(`${counts.add}+`));
|
|
48
|
+
|
|
49
|
+
const gutterWidth = maxLineNumber(diffLines);
|
|
50
|
+
const sep = brightBlack(" │ ");
|
|
51
|
+
const sepWidth = 3;
|
|
52
|
+
const sideWidth = Math.floor((width - sepWidth) / 2);
|
|
53
|
+
if (sideWidth < gutterWidth + 12) return formatUnifiedDiffLines({ path, diffLines });
|
|
54
|
+
|
|
55
|
+
const lines = [bold(summary.join(" "))];
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const left = formatSplitSide({ side: row.left, sideWidth, gutterWidth, path, fallbackType: row.type });
|
|
58
|
+
const right = formatSplitSide({ side: row.right, sideWidth: width - sepWidth - sideWidth, gutterWidth, path, fallbackType: row.type });
|
|
59
|
+
lines.push(`${left}${sep}${right}`);
|
|
60
|
+
}
|
|
61
|
+
return lines;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function formatUnifiedSide({ num, sign, text, type, path }) {
|
|
65
|
+
const bg = type === "del" ? BG_DEL : BG_ADD;
|
|
66
|
+
const signScope = type === "del" ? "comment" : "string";
|
|
67
|
+
return `${stylePlain(`${num} │ `, "90", bg)}${styleSyntax(`${sign} `, signScope, bg)}${highlightCodeLine(text, path, { bg })}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function formatSplitSide({ side, sideWidth, gutterWidth, path, fallbackType }) {
|
|
71
|
+
if (!side) return formatEmptySplitSide({ sideWidth, gutterWidth });
|
|
72
|
+
const type = side.type ?? fallbackType;
|
|
73
|
+
const bg = type === "del" ? BG_DEL : type === "add" ? BG_ADD : BG_CTX;
|
|
74
|
+
const sign = type === "del" ? "-" : type === "add" ? "+" : " ";
|
|
75
|
+
const signScope = type === "del" ? "comment" : type === "add" ? "string" : "default";
|
|
76
|
+
const num = side.lineNum != null ? String(side.lineNum).padStart(gutterWidth) : " ".repeat(gutterWidth);
|
|
77
|
+
const line = [
|
|
78
|
+
stylePlain(`${num} │ `, "90", bg),
|
|
79
|
+
styleSyntax(`${sign} `, signScope, bg),
|
|
80
|
+
highlightCodeLine(side.text ?? "", path, { bg }),
|
|
81
|
+
].join("");
|
|
82
|
+
return fitAnsiToWidth(line, sideWidth, bg);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function formatEmptySplitSide({ sideWidth, gutterWidth }) {
|
|
86
|
+
const line = [
|
|
87
|
+
stylePlain(`${" ".repeat(gutterWidth)} │ `, "90", ""),
|
|
88
|
+
styleSyntax(" ", "default", ""),
|
|
89
|
+
].join("");
|
|
90
|
+
return fitAnsiToWidth(line, sideWidth, "");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function fitAnsiToWidth(text, width, bg = "") {
|
|
94
|
+
const fitted = truncateToWidth(String(text ?? ""), width, "…", false);
|
|
95
|
+
const padding = Math.max(0, width - visibleWidth(fitted));
|
|
96
|
+
return `${fitted}${stylePlain(" ".repeat(padding), "", bg)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function pairDiffRows(lines) {
|
|
100
|
+
const rows = [];
|
|
101
|
+
for (let i = 0; i < lines.length;) {
|
|
102
|
+
const line = lines[i];
|
|
103
|
+
if (line.type === "ctx") {
|
|
104
|
+
rows.push({ type: "ctx", left: line, right: line });
|
|
105
|
+
i++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (line.type === "del") {
|
|
110
|
+
const del = [];
|
|
111
|
+
while (i < lines.length && lines[i].type === "del") del.push(lines[i++]);
|
|
112
|
+
const add = [];
|
|
113
|
+
while (i < lines.length && lines[i].type === "add") add.push(lines[i++]);
|
|
114
|
+
const max = Math.max(del.length, add.length);
|
|
115
|
+
for (let n = 0; n < max; n++) rows.push({ type: del[n] && add[n] ? "mod" : del[n] ? "del" : "add", left: del[n], right: add[n] });
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (line.type === "add") {
|
|
120
|
+
rows.push({ type: "add", left: null, right: line });
|
|
121
|
+
i++;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
return rows;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function countChanges(lines) {
|
|
131
|
+
let del = 0; let add = 0;
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
if (line.type === "del") del += 1;
|
|
134
|
+
if (line.type === "add") add += 1;
|
|
135
|
+
}
|
|
136
|
+
return { del, add };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function maxLineNumber(lines) {
|
|
140
|
+
let max = 0;
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
if (line.lineNum != null && line.lineNum > max) max = line.lineNum;
|
|
143
|
+
}
|
|
144
|
+
return max > 0 ? String(max).length : 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function stylePlain(text, fg = "", bg = "") {
|
|
148
|
+
const plain = stripAnsi(String(text ?? ""));
|
|
149
|
+
const codes = [];
|
|
150
|
+
if (fg) codes.push(fg);
|
|
151
|
+
if (bg) codes.push(bg);
|
|
152
|
+
return codes.length ? `\x1b[${codes.join(";")}m${plain}\x1b[0m` : plain;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function stripAnsi(text) {
|
|
156
|
+
return String(text ?? "").replace(/\x1b(?:\][^\x07]*(?:\x07|\x1b\\)|[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
157
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { buildModelSelectItems, persistModelSelection } from "../commands/model-command.mjs";
|
|
2
|
+
import { pasteClipboardImage } from "../commands/paste-image-command.mjs";
|
|
3
|
+
import { buildThinkingSelectItems } from "../commands/thinking-command.mjs";
|
|
4
|
+
import { brightBlack } from "./ui-theme.mjs";
|
|
5
|
+
|
|
6
|
+
export function wireTuiHandlers({
|
|
7
|
+
ui,
|
|
8
|
+
runner,
|
|
9
|
+
sessionState,
|
|
10
|
+
projectMarchDir,
|
|
11
|
+
refreshStatusBar = () => {},
|
|
12
|
+
isTurnRunning = () => false,
|
|
13
|
+
modeState = null,
|
|
14
|
+
pasteClipboardImageImpl = pasteClipboardImage,
|
|
15
|
+
configHomeDir,
|
|
16
|
+
} = {}) {
|
|
17
|
+
let lastIdleCtrlCAt = 0;
|
|
18
|
+
ui.setEscapeHandler(() => {
|
|
19
|
+
lastIdleCtrlCAt = 0;
|
|
20
|
+
if (isTurnRunning()) {
|
|
21
|
+
runner.abort();
|
|
22
|
+
refreshStatusBar.markAborted?.();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
ui.setCtrlCHandler?.(() => {
|
|
26
|
+
if (isTurnRunning()) {
|
|
27
|
+
lastIdleCtrlCAt = 0;
|
|
28
|
+
runner.abort();
|
|
29
|
+
refreshStatusBar.markAborted?.();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
if (now - lastIdleCtrlCAt > 2000) {
|
|
34
|
+
lastIdleCtrlCAt = now;
|
|
35
|
+
ui.status?.("press Ctrl+C again to exit");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
ui.requestExit?.();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const selectThinkingLevel = async () => {
|
|
42
|
+
try {
|
|
43
|
+
const levels = runner.getAvailableThinkingLevels?.() || [];
|
|
44
|
+
if (!ui.selectList || levels.length === 0) {
|
|
45
|
+
ui.writeln(brightBlack(`● thinking: no selector available`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const current = runner.getThinkingLevel?.();
|
|
49
|
+
const selectedIndex = Math.max(0, levels.indexOf(current));
|
|
50
|
+
const item = await ui.selectList({
|
|
51
|
+
items: buildThinkingSelectItems(levels, current),
|
|
52
|
+
selectedIndex,
|
|
53
|
+
width: 48,
|
|
54
|
+
});
|
|
55
|
+
if (!item) {
|
|
56
|
+
ui.writeln(brightBlack(`● thinking: unchanged`));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
ui.writeln(brightBlack(`● thinking: ${runner.setThinkingLevel(item.level)}`));
|
|
60
|
+
refreshStatusBar();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
ui.writeln(`Error: ${err.message}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
ui.setShiftTabHandler(selectThinkingLevel);
|
|
67
|
+
ui.setToggleModeHandler?.(() => {
|
|
68
|
+
const mode = modeState?.toggle?.();
|
|
69
|
+
if (!mode) return;
|
|
70
|
+
refreshStatusBar();
|
|
71
|
+
});
|
|
72
|
+
ui.setCtrlTHandler(selectThinkingLevel);
|
|
73
|
+
|
|
74
|
+
ui.setCtrlLHandler(async () => {
|
|
75
|
+
try {
|
|
76
|
+
const scopedModels = runner.getScopedModels?.() || [];
|
|
77
|
+
if (ui.selectList && scopedModels.length > 0) {
|
|
78
|
+
const current = runner.getCurrentModel?.();
|
|
79
|
+
const selectedIndex = Math.max(0, scopedModels.findIndex(({ model }) =>
|
|
80
|
+
current && model.id === current.id && model.provider === current.provider
|
|
81
|
+
));
|
|
82
|
+
const item = await ui.selectList({
|
|
83
|
+
items: buildModelSelectItems({ current, scopedModels }),
|
|
84
|
+
selectedIndex,
|
|
85
|
+
width: 72,
|
|
86
|
+
});
|
|
87
|
+
if (!item) {
|
|
88
|
+
ui.writeln(brightBlack(`● model: unchanged`));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const model = await runner.setModel(item.model);
|
|
92
|
+
persistModelSelection(model, { configHomeDir });
|
|
93
|
+
const name = model.name || model.id;
|
|
94
|
+
ui.writeln(brightBlack(`● model: ${name} (${model.provider})`));
|
|
95
|
+
refreshStatusBar();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
ui.writeln(brightBlack(`● model: no selector available`));
|
|
99
|
+
} catch (err) {
|
|
100
|
+
ui.writeln(`Error: ${err.message}`);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
ui.setPasteImageHandler(() => {
|
|
105
|
+
const sessionId = runner.getSessionStats?.().sessionId ?? sessionState.sessionId;
|
|
106
|
+
for (const line of pasteClipboardImageImpl({ ui, projectMarchDir, sessionId })) {
|
|
107
|
+
ui.status(line);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolveAttachmentTokens, uniqueAttachmentToken, withLeadingSpace } from "../input/attachment-tokens.mjs";
|
|
2
|
+
|
|
3
|
+
export function createTuiInputController({ editor, requestRender, historyStore = null }) {
|
|
4
|
+
let onSubmitResolve = null;
|
|
5
|
+
const attachmentTokens = new Map();
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
readline() {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
onSubmitResolve = resolve;
|
|
11
|
+
editor.disableSubmit = false;
|
|
12
|
+
editor.onSubmit = (text) => {
|
|
13
|
+
const resolvedText = resolveAttachmentTokens(text, attachmentTokens);
|
|
14
|
+
if (attachmentTokens.size === 0) {
|
|
15
|
+
editor.addToHistory(text);
|
|
16
|
+
saveHistory();
|
|
17
|
+
}
|
|
18
|
+
clearSubmitState();
|
|
19
|
+
attachmentTokens.clear();
|
|
20
|
+
resolve(resolvedText);
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
requestExit() {
|
|
26
|
+
if (!onSubmitResolve) return;
|
|
27
|
+
const resolve = onSubmitResolve;
|
|
28
|
+
clearSubmitState();
|
|
29
|
+
attachmentTokens.clear();
|
|
30
|
+
resolve(null);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
getInputText() {
|
|
34
|
+
return editor.getText();
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
insertTextAtCursor(text) {
|
|
38
|
+
editor.insertTextAtCursor(text);
|
|
39
|
+
requestRender();
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
insertAttachmentAtCursor({ marker, label }) {
|
|
43
|
+
const token = uniqueAttachmentToken(label || "[image]", attachmentTokens);
|
|
44
|
+
attachmentTokens.set(token, marker);
|
|
45
|
+
editor.insertTextAtCursor(withLeadingSpace(editor.getText(), token));
|
|
46
|
+
requestRender();
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function clearSubmitState() {
|
|
51
|
+
editor.disableSubmit = true;
|
|
52
|
+
editor.onSubmit = undefined;
|
|
53
|
+
onSubmitResolve = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function saveHistory() {
|
|
57
|
+
try {
|
|
58
|
+
historyStore?.save?.(editor.history);
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
}
|