@yanzc/claude-pro 0.5.9 → 0.7.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/README.md +375 -357
- package/package.json +1 -1
- package/src/agents.js +3 -1
- package/src/attach.js +132 -0
- package/src/background.js +424 -0
- package/src/commands.js +119 -80
- package/src/config.js +16 -7
- package/src/connect.js +79 -0
- package/src/history.js +94 -0
- package/src/host.js +1410 -0
- package/src/main.js +54 -10
- package/src/peers.js +290 -215
- package/src/prompts.js +74 -58
- package/src/qr.js +1 -1
- package/src/remote.js +54 -17
- package/src/runtime.js +14 -8
- package/src/session.js +29 -2
- package/src/supervisor.js +6 -3
- package/src/tools/bash.js +5 -10
- package/src/tools/files.js +6 -10
- package/src/tools/index.js +1 -1
- package/src/tools/interaction.js +8 -37
- package/src/tools/search.js +15 -10
- package/src/tools/task.js +29 -7
- package/src/ui/dialogs.js +48 -0
- package/src/ui/render.js +10 -0
- package/src/ui/repl.js +393 -79
- package/src/ui/vterm.js +62 -0
package/src/tools/files.js
CHANGED
|
@@ -62,13 +62,13 @@ Assume this tool is able to read all files on the machine. If the user provides
|
|
|
62
62
|
Usage:
|
|
63
63
|
- The file_path parameter should be an absolute path
|
|
64
64
|
- By default, it reads up to ${MAX_LINES} lines starting from the beginning of the file
|
|
65
|
-
-
|
|
65
|
+
- Read a file whole when you need to understand it; when only a part of a long file matters, give offset and limit (find the place with Grep first if needed)
|
|
66
66
|
- Any lines longer than ${MAX_LINE_CHARS} characters will be truncated
|
|
67
|
-
- A file whose numbered text is longer than ${MAX_OUTPUT_CHARS} characters is refused (or cut there with offset/limit). When you need a large file whole, in one call, pass allow_large: true: then there is no line, character or line length limit, only the room left in the context, and a read that does not fit is refused.
|
|
67
|
+
- A file whose numbered text is longer than ${MAX_OUTPUT_CHARS} characters is refused (or cut there with offset/limit). When you need a large file whole, in one call, pass allow_large: true: then there is no line, character or line length limit, only the room left in the context, and a read that does not fit is refused.
|
|
68
68
|
- Results are returned using cat -n format, with line numbers starting at 1
|
|
69
69
|
- This tool can read images (PNG, JPG, GIF, WEBP) and Jupyter notebooks (.ipynb)
|
|
70
70
|
- This tool can only read files, not directories. To list a directory, use ls via the Bash tool.
|
|
71
|
-
-
|
|
71
|
+
- Do not read a file again just to check an edit you made to it: Edit and Write report an error when they fail.
|
|
72
72
|
- If you read a file that exists but has empty contents you will receive a warning in place of file contents.`,
|
|
73
73
|
input_schema: {
|
|
74
74
|
type: 'object',
|
|
@@ -206,10 +206,8 @@ export const WriteTool = {
|
|
|
206
206
|
|
|
207
207
|
Usage:
|
|
208
208
|
- This tool will overwrite the existing file if there is one at the provided path.
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
- Do not create documentation files (*.md, READMEs) unless the user asks for them or the task clearly calls for one.
|
|
212
|
-
- Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.`,
|
|
209
|
+
- An existing file must have been read with the Read tool first (a Grep result does not count); otherwise this tool fails.
|
|
210
|
+
- Missing parent directories are created.`,
|
|
213
211
|
input_schema: {
|
|
214
212
|
type: 'object',
|
|
215
213
|
properties: {
|
|
@@ -306,10 +304,8 @@ export const EditTool = {
|
|
|
306
304
|
description: `Performs exact string replacements in files.
|
|
307
305
|
|
|
308
306
|
Usage:
|
|
309
|
-
- You must use your \`Read\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
|
|
307
|
+
- You must use your \`Read\` tool at least once in the conversation before editing (a Grep result does not count). This tool will error if you attempt an edit without reading the file.
|
|
310
308
|
- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
|
|
311
|
-
- Prefer editing existing files when that is the natural place for a change; create new files whenever the task needs them.
|
|
312
|
-
- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
|
|
313
309
|
- The edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`.
|
|
314
310
|
- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.
|
|
315
311
|
- To create a new file, pass an empty old_string with the full content as new_string (the file must not exist).`,
|
package/src/tools/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { ListPeersTool, MessagePeerTool } from './peers.js';
|
|
|
15
15
|
// `peers`: an interactive session, which can talk to the other sessions on this machine.
|
|
16
16
|
export function buildTools(config, { agents, skills, mcpTools = [], restart = false, peers = false }) {
|
|
17
17
|
return [
|
|
18
|
-
makeTaskTool(agents),
|
|
18
|
+
makeTaskTool(agents, config),
|
|
19
19
|
...(skills?.size ? [makeSkillTool(skills)] : []),
|
|
20
20
|
TaskOutputTool,
|
|
21
21
|
TaskStopTool,
|
package/src/tools/interaction.js
CHANGED
|
@@ -4,44 +4,15 @@
|
|
|
4
4
|
export const TodoWriteTool = {
|
|
5
5
|
name: 'TodoWrite',
|
|
6
6
|
readOnly: true,
|
|
7
|
-
description: `
|
|
7
|
+
description: `Create and update a task list for the current request. It helps you keep track of a task with several steps and shows the user where you are.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Use this tool proactively in these scenarios:
|
|
11
|
-
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
12
|
-
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
13
|
-
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
14
|
-
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
15
|
-
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
16
|
-
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
17
|
-
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
9
|
+
When to use it: a task with several distinct steps, several tasks the user listed, or when the user asks for a list. Skip it for a single straightforward task, a few trivial steps, or a conversational request. Each update is a request that re-reads the conversation, so use the list where it helps, not as a formality.
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
4. The task is purely conversational or informational
|
|
25
|
-
|
|
26
|
-
## Task States and Management
|
|
27
|
-
1. **Task States**:
|
|
28
|
-
- pending: Task not yet started
|
|
29
|
-
- in_progress: Currently working on (limit to ONE task at a time)
|
|
30
|
-
- completed: Task finished successfully
|
|
31
|
-
**IMPORTANT**: Task descriptions must have two forms:
|
|
32
|
-
- content: The imperative form describing what needs to be done (e.g., "Run tests")
|
|
33
|
-
- activeForm: The present continuous form shown during execution (e.g., "Running tests")
|
|
34
|
-
2. **Task Management**:
|
|
35
|
-
- Update task status in real-time as you work
|
|
36
|
-
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
37
|
-
- Exactly ONE task must be in_progress at any time (not less, not more)
|
|
38
|
-
- Remove tasks that are no longer relevant from the list entirely
|
|
39
|
-
3. **Task Completion Requirements**:
|
|
40
|
-
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
41
|
-
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
42
|
-
- Never mark a task as completed if tests are failing, the implementation is partial, or you hit unresolved errors
|
|
43
|
-
|
|
44
|
-
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
11
|
+
How:
|
|
12
|
+
- Each item has \`content\`, the imperative form ("Run tests"), and \`activeForm\`, the present continuous form shown while it is in progress ("Running tests").
|
|
13
|
+
- Statuses are pending, in_progress and completed; keep exactly one item in_progress while you work.
|
|
14
|
+
- Keep it current: mark an item completed once it is done, in the same response as the next tool calls you make anyway rather than in a response of its own. Add follow-up items you discover and remove ones that no longer apply.
|
|
15
|
+
- Mark an item completed only when it is fully done: not while tests fail, the work is partial or an error is unresolved.`,
|
|
45
16
|
input_schema: {
|
|
46
17
|
type: 'object',
|
|
47
18
|
properties: {
|
|
@@ -66,7 +37,7 @@ When in doubt, use this tool. Being proactive with task management demonstrates
|
|
|
66
37
|
const todos = Array.isArray(input.todos) ? input.todos.filter((t) => t && t.content) : [];
|
|
67
38
|
ctx.agent.todos = todos.every((t) => t.status === 'completed') ? [] : todos;
|
|
68
39
|
return {
|
|
69
|
-
content: '
|
|
40
|
+
content: 'The todo list is updated.',
|
|
70
41
|
display: { todos },
|
|
71
42
|
};
|
|
72
43
|
},
|
package/src/tools/search.js
CHANGED
|
@@ -16,9 +16,7 @@ export const GlobTool = {
|
|
|
16
16
|
description: `- Fast file pattern matching tool that works with any codebase size
|
|
17
17
|
- Supports glob patterns like "**/*.js" or "src/**/*.ts"
|
|
18
18
|
- Returns matching file paths sorted by modification time (most recent first)
|
|
19
|
-
- Use this tool when you need to find files by name patterns
|
|
20
|
-
- When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the Task tool instead
|
|
21
|
-
- You can call multiple tools in a single response. It is always better to speculatively perform multiple searches in parallel if they are potentially useful.`,
|
|
19
|
+
- Use this tool when you need to find files by name patterns`,
|
|
22
20
|
input_schema: {
|
|
23
21
|
type: 'object',
|
|
24
22
|
properties: {
|
|
@@ -266,16 +264,24 @@ function runRg(bin, args, cwd, signal) {
|
|
|
266
264
|
});
|
|
267
265
|
}
|
|
268
266
|
|
|
267
|
+
// ripgrep takes inline flags at the start of a pattern, `(?i)` or `(?is)`; a JS RegExp does not, so they become
|
|
268
|
+
// flags. `m` is dropped: ^ and $ are line anchors here anyway, as in ripgrep.
|
|
269
|
+
export function inlineFlags(pattern) {
|
|
270
|
+
const m = /^\(\?([ims]+)\)/.exec(pattern);
|
|
271
|
+
return m ? { pattern: pattern.slice(m[0].length), i: m[1].includes('i'), s: m[1].includes('s') } : { pattern, i: false, s: false };
|
|
272
|
+
}
|
|
273
|
+
|
|
269
274
|
// JS scanner used when ripgrep isn't available. Returns output lines in rg's format.
|
|
270
275
|
async function jsGrep(input, base, mode, signal) {
|
|
271
276
|
const exts = input.type ? TYPE_EXT[String(input.type).toLowerCase()] : null;
|
|
272
277
|
if (input.type && !exts) throw new Error(`unrecognized file type: ${input.type} (known types: ${Object.keys(TYPE_EXT).join(', ')})`);
|
|
273
|
-
const
|
|
274
|
-
const
|
|
278
|
+
const inline = inlineFlags(input.pattern);
|
|
279
|
+
const flags = input['-i'] || inline.i ? 'i' : '';
|
|
280
|
+
const dotAll = input.multiline || inline.s ? 's' : '';
|
|
275
281
|
// ripgrep treats ^ and $ as line anchors, so whole-file matching needs the m flag.
|
|
276
|
-
const anyRe = new RegExp(
|
|
277
|
-
const allRe = new RegExp(
|
|
278
|
-
const lineRe = new RegExp(
|
|
282
|
+
const anyRe = new RegExp(inline.pattern, `${flags}m${dotAll}`);
|
|
283
|
+
const allRe = new RegExp(inline.pattern, `${flags}gm${dotAll}`);
|
|
284
|
+
const lineRe = new RegExp(inline.pattern, flags);
|
|
279
285
|
const content = mode === 'content';
|
|
280
286
|
const before = content ? Math.max(0, Number(input['-B'] ?? input['-C'] ?? 0) || 0) : 0;
|
|
281
287
|
const after = content ? Math.max(0, Number(input['-A'] ?? input['-C'] ?? 0) || 0) : 0;
|
|
@@ -359,11 +365,10 @@ export const GrepTool = {
|
|
|
359
365
|
description: `A powerful search tool built on ripgrep
|
|
360
366
|
|
|
361
367
|
Usage:
|
|
362
|
-
-
|
|
368
|
+
- Use this tool to search file contents rather than \`grep\` or \`rg\` through Bash (rg may not be installed on the machine).
|
|
363
369
|
- Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")
|
|
364
370
|
- Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")
|
|
365
371
|
- Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts
|
|
366
|
-
- Use Task tool for open-ended searches requiring multiple rounds
|
|
367
372
|
- Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)
|
|
368
373
|
- Multiline matching: By default patterns match within single lines only. For cross-line patterns like \`struct \\{[\\s\\S]*?field\`, use \`multiline: true\``,
|
|
369
374
|
input_schema: {
|
package/src/tools/task.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { taskResultText } from '../tasks.js';
|
|
6
6
|
import { EFFORTS } from '../agents.js';
|
|
7
|
+
import { priceOf } from '../pricing.js';
|
|
7
8
|
|
|
8
9
|
// Wait for `promise`, at most `ms`, or until `signal` aborts. The timer is always cleared so a
|
|
9
10
|
// finished wait never keeps the process alive.
|
|
@@ -20,14 +21,34 @@ function waitFor(promise, ms, signal) {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
// How to pick a sub-agent's model, where the main agent chooses it (Config.subagentModelChosen): the models the
|
|
25
|
+
// aliases stand for, with their prices. Built from the configuration of the moment, so that it follows /model and
|
|
26
|
+
// /login (which start a new prompt cache anyway); it holds nothing that changes otherwise.
|
|
27
|
+
export function modelChoiceText(config) {
|
|
28
|
+
if (!config?.subagentModelChosen) return '';
|
|
29
|
+
const main = config.mainModel.id;
|
|
30
|
+
const option = (alias) => {
|
|
31
|
+
const id = config.resolveModel(alias).id;
|
|
32
|
+
const p = priceOf(id);
|
|
33
|
+
return `${alias} (${id}${id === main ? ', your own model' : ''}${p ? `, $${p.input}/$${p.output} per million input/output tokens` : ''})`;
|
|
34
|
+
};
|
|
35
|
+
return `
|
|
36
|
+
|
|
37
|
+
Choosing the model: there is no fixed sub-agent model. Choose one for each task by how hard it is and how much you will rely on the report, and give it in \`model\`:
|
|
38
|
+
- ${option('haiku')}: mechanical work with a clear target: find where something is defined or used, list files, read files and quote the relevant parts.
|
|
39
|
+
- ${option('sonnet')}: searches across a codebase and well-specified subtasks whose steps are clear: gather the call sites of a function and how they use it, run tests and summarize the failures, make a change that is fully described.
|
|
40
|
+
- ${option('opus')}: work whose quality your answer depends on and that you will not redo yourself: hard debugging, design and trade-offs, reviewing code for subtle bugs, analysis that spans many files.
|
|
41
|
+
A shallow or wrong report that you rely on costs more than the difference in price; a strong model on a lookup only wastes money. Set \`effort\` with it (low suits lookups); without it the agent runs at your session's effort. Without \`model\` an agent runs on its definition's model, else on ${config.subagentModel.id}.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function makeTaskTool(agents, config = null) {
|
|
24
45
|
const list = [...agents.values()]
|
|
25
|
-
.map((a) => `- ${a.name}: ${a.description} (Tools: ${a.tools === '*' ? 'All tools' : a.tools.join(', ')})`)
|
|
46
|
+
.map((a) => `- ${a.name}: ${a.description} (Tools: ${a.tools === '*' ? 'All tools' : a.tools.join(', ')})${a.model ? ` (model: ${a.model})` : ''}`)
|
|
26
47
|
.join('\n');
|
|
27
48
|
return {
|
|
28
49
|
name: 'Task',
|
|
29
50
|
readOnly: true, // sub-agents ask for their own permissions; multiple tasks may run in parallel
|
|
30
|
-
description: `Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
51
|
+
description: () => `Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
31
52
|
|
|
32
53
|
Available agent types and the tools they have access to:
|
|
33
54
|
${list}
|
|
@@ -40,12 +61,13 @@ When NOT to use the Task tool:
|
|
|
40
61
|
- If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead
|
|
41
62
|
|
|
42
63
|
Usage notes:
|
|
43
|
-
-
|
|
64
|
+
- When several independent tasks are worth delegating, start them in a single message with multiple tool uses so that they run concurrently. Do not split closely coupled work between agents: they do not see each other's work, and each one costs its own context and tokens
|
|
44
65
|
- When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
|
|
45
66
|
- Each agent invocation is stateless. Your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message.
|
|
46
|
-
-
|
|
67
|
+
- Once you have delegated a search or an investigation, do not also do it yourself: wait for the report, doing other work meanwhile. Never make up or predict the result of an agent that is still running; if the user asks before it is done, say that it is still running.
|
|
68
|
+
- A sub-agent may run on a smaller model than yours. Use its report to find your way, but before you build an answer or a change on one of its findings, check that finding yourself (read the lines it cites)
|
|
47
69
|
- Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
|
|
48
|
-
- Set run_in_background: true to start the agent and continue working while it runs (e.g. a long investigation, or several independent jobs). You get a task id back immediately, and the agent's final report arrives automatically in a <task-notification> once it finishes; you do not need to poll. Use TaskOutput to check on or wait for it early, and TaskStop to cancel it. Do not start background agents that edit the same files at the same time
|
|
70
|
+
- Set run_in_background: true to start the agent and continue working while it runs (e.g. a long investigation, or several independent jobs). You get a task id back immediately, and the agent's final report arrives automatically in a <task-notification> once it finishes; you do not need to poll. Use TaskOutput to check on or wait for it early, and TaskStop to cancel it. Do not start background agents that edit the same files at the same time.${modelChoiceText(config)}`,
|
|
49
71
|
input_schema: {
|
|
50
72
|
type: 'object',
|
|
51
73
|
properties: {
|
|
@@ -53,7 +75,7 @@ Usage notes:
|
|
|
53
75
|
prompt: { type: 'string', description: 'The task for the agent to perform' },
|
|
54
76
|
subagent_type: { type: 'string', description: 'The type of specialized agent to use for this task' },
|
|
55
77
|
run_in_background: { type: 'boolean', description: 'Run the agent in the background and return immediately with a task id' },
|
|
56
|
-
model: { type: 'string', description: '
|
|
78
|
+
model: { type: 'string', description: 'Model for this agent: haiku, sonnet, opus or a full model id. Pick it by how hard the task is: a smaller model is cheaper and faster for lookups and clear subtasks, a stronger one is right when you rely on the quality of its report. Defaults to the agent definition\'s model, else the sub-agent default.' },
|
|
57
79
|
effort: { type: 'string', enum: EFFORTS, description: 'Optional effort level for this agent (default: the agent definition\'s, else the session\'s). Low suits quick lookups, high or above hard reasoning.' },
|
|
58
80
|
},
|
|
59
81
|
required: ['description', 'prompt', 'subagent_type'],
|
package/src/ui/dialogs.js
CHANGED
|
@@ -17,6 +17,54 @@ function box(lines, width, color) {
|
|
|
17
17
|
return out;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// A question answered with typed text: Enter submits, Esc cancels (shift/alt+Enter starts a new line when
|
|
21
|
+
// `multiline`). On the remote page it is a text box ({input: {placeholder, value, multiline}}, see App.remoteDialog).
|
|
22
|
+
export class TextDialog {
|
|
23
|
+
constructor({ title, body = [], question, placeholder = '', value = '', multiline = false, color = c.blue, onResolve, cancelValue = null }) {
|
|
24
|
+
this.title = title;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.question = question;
|
|
27
|
+
this.color = color;
|
|
28
|
+
this.onResolve = onResolve;
|
|
29
|
+
this.cancelValue = cancelValue;
|
|
30
|
+
this.input = { placeholder, multiline };
|
|
31
|
+
this.editor = new Editor();
|
|
32
|
+
if (value) this.editor.set(value, value.length);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get value() { return this.editor.text; }
|
|
36
|
+
|
|
37
|
+
resolve(value) {
|
|
38
|
+
const cb = this.onResolve;
|
|
39
|
+
this.onResolve = null;
|
|
40
|
+
cb?.(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
handleKey(str, key = {}) {
|
|
44
|
+
if (key.name === 'escape') { this.resolve(this.cancelValue); return true; }
|
|
45
|
+
if (key.name === 'return' && !key.meta && !key.shift) { this.resolve(this.editor.text); return true; }
|
|
46
|
+
if (key.name === 'return' && !this.input.multiline) return true;
|
|
47
|
+
this.editor.handleKey(str, key);
|
|
48
|
+
return true; // modal: everything else is the editor's
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
render(width) {
|
|
52
|
+
const lines = [];
|
|
53
|
+
if (this.title) lines.push(c.bold(this.color(this.title)), '');
|
|
54
|
+
lines.push(...this.body);
|
|
55
|
+
if (this.body.length) lines.push('');
|
|
56
|
+
if (this.question) lines.push(this.question, '');
|
|
57
|
+
const inner = Math.max(20, width - 1) - 4;
|
|
58
|
+
const r = this.editor.render(width - 4, { placeholder: this.input.placeholder || 'Type the answer' });
|
|
59
|
+
const top = lines.length + 1; // +1 for the box's top border
|
|
60
|
+
lines.push(...r.lines.map((l) => truncate(l, inner)));
|
|
61
|
+
const cursor = r.cursor ? { row: top + r.cursor.row, col: 2 + r.cursor.col } : null;
|
|
62
|
+
const out = box(lines, width, this.color);
|
|
63
|
+
out.push(c.dim(` Enter to submit${this.input.multiline ? ' · shift+Enter for a new line' : ''} · Esc to cancel`));
|
|
64
|
+
return { lines: out, cursor };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
20
68
|
export class SelectDialog {
|
|
21
69
|
// options: [{label, value, description?}]
|
|
22
70
|
// selected: the option highlighted at first.
|
package/src/ui/render.js
CHANGED
|
@@ -27,6 +27,16 @@ export function resultLines(lines) {
|
|
|
27
27
|
return lines.map((l, i) => (i === 0 ? c.gray(RESULT_PREFIX) : RESULT_INDENT) + l);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// A message of bash mode (`!command`, see App.runBashMode) as it was shown when it ran: the command, then its output
|
|
31
|
+
// (at most 40 lines, the middle left out). null for any other message.
|
|
32
|
+
export function bashModeLines(text) {
|
|
33
|
+
const m = /^<bash-input>([\s\S]*?)<\/bash-input>\n?(?:<bash-stdout>([\s\S]*?)<\/bash-stdout>)?\n?(?:<bash-stderr>([\s\S]*?)<\/bash-stderr>)?/.exec(String(text ?? ''));
|
|
34
|
+
if (!m) return null;
|
|
35
|
+
let lines = [m[2], m[3]].filter((s) => s != null && s !== '').join('\n').split('\n');
|
|
36
|
+
if (lines.length > 40) lines = [...lines.slice(0, 20), c.dim(`… +${lines.length - 40} lines`), ...lines.slice(-20)];
|
|
37
|
+
return [c.magenta('! ') + m[1], ...resultLines(lines.map((l) => c.dim(l)))];
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
function numberWidth(hunks) {
|
|
31
41
|
let max = 1;
|
|
32
42
|
for (const h of hunks) for (const l of h.lines) max = Math.max(max, l.oldNo || 0, l.newNo || 0);
|