codsh-cli 0.2.0 → 0.4.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 +5 -73
- package/bin/codsh.mjs +105 -43
- package/package.json +9 -127
- package/README.zh.md +0 -76
- package/agent-presets/code-cli/agent.cordis.yml +0 -322
- package/agent-presets/code-cli/preset.yml +0 -3
- package/cordis.patch.yml +0 -165
- package/lib/index.js +0 -4911
- package/lib/invariant.js +0 -23
- package/lib/startup.js +0 -64
- package/lib/types/approval.d.ts +0 -57
- package/lib/types/banner.d.ts +0 -30
- package/lib/types/completion.d.ts +0 -45
- package/lib/types/console.d.ts +0 -240
- package/lib/types/custom-commands.d.ts +0 -54
- package/lib/types/editor.d.ts +0 -186
- package/lib/types/index.d.ts +0 -48
- package/lib/types/inputbox.d.ts +0 -45
- package/lib/types/invariant.d.ts +0 -15
- package/lib/types/keys.d.ts +0 -123
- package/lib/types/markdown.d.ts +0 -73
- package/lib/types/preset-install.d.ts +0 -34
- package/lib/types/prompt.d.ts +0 -150
- package/lib/types/questions.d.ts +0 -65
- package/lib/types/screen.d.ts +0 -204
- package/lib/types/selector.d.ts +0 -98
- package/lib/types/spinner.d.ts +0 -63
- package/lib/types/startup.d.ts +0 -31
- package/lib/types/status.d.ts +0 -94
- package/lib/types/streaming.d.ts +0 -68
- package/lib/types/theme.d.ts +0 -75
- package/lib/types/transcript.d.ts +0 -129
- package/lib/types/wrap.d.ts +0 -27
package/lib/types/editor.d.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The prompt's editing model: a multi-line buffer, a cursor, history, and the
|
|
3
|
-
* completion menu.
|
|
4
|
-
*
|
|
5
|
-
* Pure state. It takes keys and answers with what changed, so every behaviour
|
|
6
|
-
* here is testable without a terminal — the rendering and the raw-mode plumbing
|
|
7
|
-
* are somebody else's job.
|
|
8
|
-
* @module codsh-cli/src/editor
|
|
9
|
-
*/
|
|
10
|
-
import type { CompletableCommand, CompletionResult } from './completion.ts';
|
|
11
|
-
import type { Key } from './keys.ts';
|
|
12
|
-
/** One entry offered in the completion menu. */
|
|
13
|
-
export interface Candidate {
|
|
14
|
-
/** The text that replaces the token when accepted. */
|
|
15
|
-
value: string;
|
|
16
|
-
/** What it does, shown beside it. Empty for a path, which explains itself. */
|
|
17
|
-
detail: string;
|
|
18
|
-
}
|
|
19
|
-
/** What the editor is showing right now. */
|
|
20
|
-
export interface EditorView {
|
|
21
|
-
/** Buffer lines; always at least one, possibly empty. */
|
|
22
|
-
lines: readonly string[];
|
|
23
|
-
/** Cursor line index. */
|
|
24
|
-
row: number;
|
|
25
|
-
/** Cursor column within that line, in code points. */
|
|
26
|
-
column: number;
|
|
27
|
-
/** Candidates to offer, empty when the menu is closed. */
|
|
28
|
-
candidates: readonly Candidate[];
|
|
29
|
-
/** Which candidate is selected, meaningless when there are none. */
|
|
30
|
-
selected: number;
|
|
31
|
-
/** The token under the cursor, which is what the candidates matched. */
|
|
32
|
-
token: string;
|
|
33
|
-
}
|
|
34
|
-
/** What the caller must do after a key. */
|
|
35
|
-
export type EditorAction = {
|
|
36
|
-
kind: 'none';
|
|
37
|
-
} | {
|
|
38
|
-
kind: 'submit';
|
|
39
|
-
text: string;
|
|
40
|
-
} | {
|
|
41
|
-
kind: 'interrupt';
|
|
42
|
-
} | {
|
|
43
|
-
kind: 'eof';
|
|
44
|
-
} | {
|
|
45
|
-
kind: 'escape';
|
|
46
|
-
};
|
|
47
|
-
/** How the editor finds candidates for the token under the cursor. */
|
|
48
|
-
export interface EditorSources {
|
|
49
|
-
/** The commands currently registered. */
|
|
50
|
-
commands(): readonly CompletableCommand[];
|
|
51
|
-
/** Path candidates for an `@` mention, as the completer produces them. */
|
|
52
|
-
paths(token: string): CompletionResult;
|
|
53
|
-
/**
|
|
54
|
-
* Argument candidates for one command's first argument.
|
|
55
|
-
*
|
|
56
|
-
* `/plan off`, `/permission workspace-write`, `/model <id>` — the values a
|
|
57
|
-
* command takes are the command's own knowledge, so the editor asks rather
|
|
58
|
-
* than guessing. Absent or empty means the argument is free-form.
|
|
59
|
-
* @param command - the command name without its slash.
|
|
60
|
-
* @param typed - what has been typed of the argument so far.
|
|
61
|
-
* @returns candidates to offer, best first.
|
|
62
|
-
*/
|
|
63
|
-
commandArguments?(command: string, typed: string): readonly Candidate[];
|
|
64
|
-
}
|
|
65
|
-
/** A multi-line prompt editor. */
|
|
66
|
-
export declare class Editor {
|
|
67
|
-
private readonly sources;
|
|
68
|
-
private lines;
|
|
69
|
-
private row;
|
|
70
|
-
private column;
|
|
71
|
-
private candidates;
|
|
72
|
-
private selected;
|
|
73
|
-
private readonly history;
|
|
74
|
-
/** Where the caller is in history; equals `history.length` when not browsing. */
|
|
75
|
-
private browsing;
|
|
76
|
-
/** The buffer set aside while history is being browsed. */
|
|
77
|
-
private stashed;
|
|
78
|
-
constructor(sources: EditorSources);
|
|
79
|
-
/** What to render. */
|
|
80
|
-
get view(): EditorView;
|
|
81
|
-
/** The buffer as one string. */
|
|
82
|
-
get text(): string;
|
|
83
|
-
/** Whether nothing has been typed. */
|
|
84
|
-
get empty(): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Replace the buffer with earlier text, cursor at its end.
|
|
87
|
-
*
|
|
88
|
-
* This is recall-for-editing: the second Escape puts the previous submission
|
|
89
|
-
* back so it can be corrected and resent.
|
|
90
|
-
* @param text - the text to edit, possibly multi-line.
|
|
91
|
-
*/
|
|
92
|
-
prefill(text: string): void;
|
|
93
|
-
/** Submissions this session recorded, oldest first, for persistence. */
|
|
94
|
-
get pastSubmissions(): readonly string[];
|
|
95
|
-
/**
|
|
96
|
-
* Preload history from an earlier session.
|
|
97
|
-
*
|
|
98
|
-
* Applied before any live submission, so recall starts where the last
|
|
99
|
-
* session ended rather than empty.
|
|
100
|
-
* @param entries - past submissions, oldest first.
|
|
101
|
-
*/
|
|
102
|
-
seedHistory(entries: readonly string[]): void;
|
|
103
|
-
/**
|
|
104
|
-
* Apply one key.
|
|
105
|
-
* @param key - the decoded keystroke.
|
|
106
|
-
* @returns what the caller must do about it.
|
|
107
|
-
*/
|
|
108
|
-
handle(key: Key): EditorAction;
|
|
109
|
-
/** The line the cursor is on. */
|
|
110
|
-
private line;
|
|
111
|
-
/** Replace the cursor's line. */
|
|
112
|
-
private setLine;
|
|
113
|
-
/**
|
|
114
|
-
* Insert text at the cursor, splitting lines on newlines.
|
|
115
|
-
* @param text - the text to insert.
|
|
116
|
-
* @returns always `none`; insertion never completes a read.
|
|
117
|
-
*/
|
|
118
|
-
private insert;
|
|
119
|
-
/**
|
|
120
|
-
* Submit, or accept the highlighted candidate when the menu is open.
|
|
121
|
-
* @returns the submission, or `none` when a candidate was taken instead.
|
|
122
|
-
*/
|
|
123
|
-
private accept;
|
|
124
|
-
/** Record a submission for history, collapsing an immediate repeat. */
|
|
125
|
-
private remember;
|
|
126
|
-
/**
|
|
127
|
-
* Open the menu, or move through it when it is already open.
|
|
128
|
-
* @returns always `none`.
|
|
129
|
-
*/
|
|
130
|
-
private complete;
|
|
131
|
-
/**
|
|
132
|
-
* Replace the token under the cursor with the selected candidate.
|
|
133
|
-
* @returns always `none`.
|
|
134
|
-
*/
|
|
135
|
-
private take;
|
|
136
|
-
/** Where the token under the cursor begins, in code points. */
|
|
137
|
-
private tokenStart;
|
|
138
|
-
/** The token under the cursor. */
|
|
139
|
-
private token;
|
|
140
|
-
/**
|
|
141
|
-
* Recompute the candidate list for the token under the cursor.
|
|
142
|
-
*
|
|
143
|
-
* Recomputed on every edit rather than only on Tab, which is what makes the
|
|
144
|
-
* menu appear as a command is typed instead of after a key that asks for it.
|
|
145
|
-
*/
|
|
146
|
-
private refresh;
|
|
147
|
-
/** Remove the character before the cursor, joining lines at a boundary. */
|
|
148
|
-
private backspace;
|
|
149
|
-
/** Remove the character after the cursor, joining lines at a boundary. */
|
|
150
|
-
private forwardDelete;
|
|
151
|
-
/** Move up a line, or back through history from the first line. */
|
|
152
|
-
private moveUp;
|
|
153
|
-
/** Move down a line, or forward through history from the last line. */
|
|
154
|
-
private moveDown;
|
|
155
|
-
/**
|
|
156
|
-
* Step through history.
|
|
157
|
-
* @param delta - -1 for older, 1 for newer.
|
|
158
|
-
* @returns always `none`.
|
|
159
|
-
*/
|
|
160
|
-
private recall;
|
|
161
|
-
/** Move the cursor one position left, wrapping to the previous line. */
|
|
162
|
-
private moveLeft;
|
|
163
|
-
/** Move the cursor one position right, wrapping to the next line. */
|
|
164
|
-
private moveRight;
|
|
165
|
-
/**
|
|
166
|
-
* Put the cursor at a column on the current line.
|
|
167
|
-
* @param column - the target column.
|
|
168
|
-
* @returns always `none`.
|
|
169
|
-
*/
|
|
170
|
-
private jump;
|
|
171
|
-
/** Drop everything after the cursor on this line. */
|
|
172
|
-
private killLine;
|
|
173
|
-
/** Drop everything before the cursor on this line. */
|
|
174
|
-
private killInput;
|
|
175
|
-
/** Move the cursor to the start of the word before it. */
|
|
176
|
-
private wordLeft;
|
|
177
|
-
/** Move the cursor past the end of the word after it. */
|
|
178
|
-
private wordRight;
|
|
179
|
-
/** Drop the word before the cursor. */
|
|
180
|
-
private killWord;
|
|
181
|
-
/**
|
|
182
|
-
* Close the menu, or report Escape when there is none to close.
|
|
183
|
-
* @returns `none` when a menu was dismissed, otherwise `escape`.
|
|
184
|
-
*/
|
|
185
|
-
private cancel;
|
|
186
|
-
}
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `codsh` — the interactive terminal surface. The bundle
|
|
3
|
-
* patch rides over dsh-base without Host, HTTP, or browser plugins; this runner
|
|
4
|
-
* composes one Agent from the roster's preset, renders its session log to the
|
|
5
|
-
* terminal, answers approvals and questions from the keyboard, and drives the
|
|
6
|
-
* conversation until the person leaves.
|
|
7
|
-
*
|
|
8
|
-
* The surface shares the process with the Agent, so it reads `ctx.agents`
|
|
9
|
-
* directly. The API gateway exists to carry out-of-process clients and would
|
|
10
|
-
* add a serialization hop with no reader on the other side.
|
|
11
|
-
*
|
|
12
|
-
* @module codsh
|
|
13
|
-
*/
|
|
14
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
-
import z from '@deepseek-ai/schemastery';
|
|
16
|
-
/** Stable Cordis plugin name. */
|
|
17
|
-
export declare const name = "coding-cli-runner";
|
|
18
|
-
/** Core services required before the surface can compose an agent. */
|
|
19
|
-
export declare const inject: string[];
|
|
20
|
-
/** Plugin config: the invocation resolved from this app's injected provider service. */
|
|
21
|
-
export interface Config {
|
|
22
|
-
/** Opening task, or the empty string to start at the prompt. */
|
|
23
|
-
task: string;
|
|
24
|
-
/** Session to reopen: an id, `'latest'`, or the empty string for a new session. */
|
|
25
|
-
resume: string;
|
|
26
|
-
/** Preset id overriding the roster default, or the empty string to accept it. */
|
|
27
|
-
preset: string;
|
|
28
|
-
/** Render the answer to `task` and exit rather than entering the prompt. */
|
|
29
|
-
print: boolean;
|
|
30
|
-
/** Ring the terminal bell when a decision waits or a long turn ends. */
|
|
31
|
-
bell: boolean;
|
|
32
|
-
/** How long a `!` passthrough command may run before it is killed. */
|
|
33
|
-
bangTimeoutMs: number;
|
|
34
|
-
/** Output lines a `!` passthrough keeps before summarizing the rest. */
|
|
35
|
-
bangOutputLines: number;
|
|
36
|
-
}
|
|
37
|
-
export declare const Config: z<Config>;
|
|
38
|
-
/** The process streams the surface binds to; tests substitute captures. */
|
|
39
|
-
export declare const internals: {
|
|
40
|
-
input: NodeJS.ReadableStream;
|
|
41
|
-
output: NodeJS.WriteStream;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Mount the interactive terminal surface.
|
|
45
|
-
* @param ctx - plugin context carrying core services and the launcher-provided exit request.
|
|
46
|
-
* @param config - validated invocation config.
|
|
47
|
-
*/
|
|
48
|
-
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/types/inputbox.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The input box: a framed, multi-line prompt that wraps long lines, grows with
|
|
3
|
-
* its content, and windows when it grows past its budget — with the completion
|
|
4
|
-
* menu under it.
|
|
5
|
-
*
|
|
6
|
-
* Pure layout. It turns an {@link EditorView} into the rows of the bottom region
|
|
7
|
-
* and says where the terminal cursor belongs, so the drawing code has no opinion
|
|
8
|
-
* about editing and this file has none about terminals.
|
|
9
|
-
*
|
|
10
|
-
* Wrapping is by display width, hard at the boundary: a wrap that respected word
|
|
11
|
-
* breaks would need the same word knowledge in the cursor mapping, and a cursor
|
|
12
|
-
* that disagrees with the wrap by one cell is worse than a word split across
|
|
13
|
-
* rows. Text is never truncated here — hiding typed text is how an input box
|
|
14
|
-
* loses a person's work.
|
|
15
|
-
* @module codsh-cli/src/inputbox
|
|
16
|
-
*/
|
|
17
|
-
import type { EditorView } from './editor.ts';
|
|
18
|
-
import type { Theme } from './theme.ts';
|
|
19
|
-
/** What the box is asked to show besides the buffer. */
|
|
20
|
-
export interface BoxOptions {
|
|
21
|
-
/** Dim text shown inside an empty box, e.g. what `/` and `@` do. */
|
|
22
|
-
placeholder?: string | undefined;
|
|
23
|
-
/** Dim text shown under the box when the menu is closed. */
|
|
24
|
-
hint?: string | undefined;
|
|
25
|
-
/** Styles the frame; absent frames dim. A mode announces itself here. */
|
|
26
|
-
accent?: ((text: string) => string) | undefined;
|
|
27
|
-
}
|
|
28
|
-
/** The rows to draw and where the cursor goes among them. */
|
|
29
|
-
export interface BoxLayout {
|
|
30
|
-
/** Rows, top to bottom, each already fitted to the terminal. */
|
|
31
|
-
rows: string[];
|
|
32
|
-
/** Index into {@link rows} where the cursor belongs. */
|
|
33
|
-
cursorRow: number;
|
|
34
|
-
/** Display column of the cursor on that row, from zero. */
|
|
35
|
-
cursorColumn: number;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Lay out the input box.
|
|
39
|
-
* @param view - what the editor is showing.
|
|
40
|
-
* @param theme - styling for the frame, the marker, and the menu.
|
|
41
|
-
* @param columns - display columns available.
|
|
42
|
-
* @param options - placeholder, hint, and frame accent.
|
|
43
|
-
* @returns the rows and cursor position.
|
|
44
|
-
*/
|
|
45
|
-
export declare function inputBox(view: EditorView, theme: Theme, columns: number, options?: BoxOptions): BoxLayout;
|
package/lib/types/invariant.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package-owned invariant companion for `codsh-cli`.
|
|
3
|
-
* @module codsh-cli/invariant
|
|
4
|
-
*/
|
|
5
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
-
/** Cordis companion plugin name. */
|
|
7
|
-
export declare const name = "coding-cli-invariant";
|
|
8
|
-
/** Service required before the companion can register. */
|
|
9
|
-
export declare const inject: string[];
|
|
10
|
-
/**
|
|
11
|
-
* Register this package's invariant companion.
|
|
12
|
-
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
-
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
-
*/
|
|
15
|
-
export declare const apply: (ctx: Context) => Promise<() => void>;
|
package/lib/types/keys.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminal bytes to key events.
|
|
3
|
-
*
|
|
4
|
-
* Owning the keyboard is what an input box costs: `readline` cannot report a
|
|
5
|
-
* lone Escape, cannot be asked to draw a completion menu, and decides for itself
|
|
6
|
-
* what Enter means. Decoding here is the price of deciding those things.
|
|
7
|
-
*
|
|
8
|
-
* The decoder is incremental because a terminal splits sequences across reads:
|
|
9
|
-
* an arrow key can arrive as `ESC`, then `[`, then `A`. Anything it cannot yet
|
|
10
|
-
* resolve is held until the next byte rather than guessed at.
|
|
11
|
-
* @module codsh-cli/src/keys
|
|
12
|
-
*/
|
|
13
|
-
/** What one keystroke means to the editor. */
|
|
14
|
-
export type Key = {
|
|
15
|
-
kind: 'text';
|
|
16
|
-
text: string;
|
|
17
|
-
} | {
|
|
18
|
-
kind: 'enter';
|
|
19
|
-
} | {
|
|
20
|
-
kind: 'newline';
|
|
21
|
-
} | {
|
|
22
|
-
kind: 'tab';
|
|
23
|
-
} | {
|
|
24
|
-
kind: 'backspace';
|
|
25
|
-
} | {
|
|
26
|
-
kind: 'delete';
|
|
27
|
-
} | {
|
|
28
|
-
kind: 'up';
|
|
29
|
-
} | {
|
|
30
|
-
kind: 'down';
|
|
31
|
-
} | {
|
|
32
|
-
kind: 'left';
|
|
33
|
-
} | {
|
|
34
|
-
kind: 'right';
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'home';
|
|
37
|
-
} | {
|
|
38
|
-
kind: 'end';
|
|
39
|
-
} | {
|
|
40
|
-
kind: 'escape';
|
|
41
|
-
} | {
|
|
42
|
-
kind: 'interrupt';
|
|
43
|
-
} | {
|
|
44
|
-
kind: 'eof';
|
|
45
|
-
} | {
|
|
46
|
-
kind: 'kill-line';
|
|
47
|
-
} | {
|
|
48
|
-
kind: 'kill-input';
|
|
49
|
-
} | {
|
|
50
|
-
kind: 'kill-word';
|
|
51
|
-
} | {
|
|
52
|
-
kind: 'word-left';
|
|
53
|
-
} | {
|
|
54
|
-
kind: 'word-right';
|
|
55
|
-
} | {
|
|
56
|
-
kind: 'shift-tab';
|
|
57
|
-
} | {
|
|
58
|
-
kind: 'clear-screen';
|
|
59
|
-
} | {
|
|
60
|
-
kind: 'expand-output';
|
|
61
|
-
} | {
|
|
62
|
-
kind: 'page';
|
|
63
|
-
direction: -1 | 1;
|
|
64
|
-
} | {
|
|
65
|
-
kind: 'scroll';
|
|
66
|
-
lines: number;
|
|
67
|
-
} | {
|
|
68
|
-
kind: 'scroll-end';
|
|
69
|
-
} | {
|
|
70
|
-
kind: 'paste';
|
|
71
|
-
text: string;
|
|
72
|
-
} | {
|
|
73
|
-
kind: 'mouse-down';
|
|
74
|
-
row: number;
|
|
75
|
-
column: number;
|
|
76
|
-
} | {
|
|
77
|
-
kind: 'mouse-drag';
|
|
78
|
-
row: number;
|
|
79
|
-
column: number;
|
|
80
|
-
} | {
|
|
81
|
-
kind: 'mouse-up';
|
|
82
|
-
row: number;
|
|
83
|
-
column: number;
|
|
84
|
-
};
|
|
85
|
-
/** Decodes terminal bytes into keys, holding partial sequences between reads. */
|
|
86
|
-
export declare class KeyDecoder {
|
|
87
|
-
private held;
|
|
88
|
-
private pasting;
|
|
89
|
-
private pasted;
|
|
90
|
-
/**
|
|
91
|
-
* Feed one read's worth of input.
|
|
92
|
-
* @param chunk - the bytes as text.
|
|
93
|
-
* @returns the keys this read completed, in order.
|
|
94
|
-
*/
|
|
95
|
-
push(chunk: string): Key[];
|
|
96
|
-
/** Whether bytes are held back awaiting the rest of a sequence. */
|
|
97
|
-
get pending(): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Resolve a held Escape that no further byte arrived for.
|
|
100
|
-
*
|
|
101
|
-
* `ESC` alone and the first byte of `ESC [ A` are the same byte, so the two can
|
|
102
|
-
* only be told apart by what follows — or by nothing following. The caller arms
|
|
103
|
-
* a short timer after each read and calls this when it expires: an arrow key
|
|
104
|
-
* split across reads completes long before that, and a key pressed by itself
|
|
105
|
-
* never completes at all.
|
|
106
|
-
* @returns the Escape key, or nothing when the held bytes are a real prefix.
|
|
107
|
-
*/
|
|
108
|
-
flush(): Key[];
|
|
109
|
-
/**
|
|
110
|
-
* Resolve the held bytes into one key, if they are enough.
|
|
111
|
-
* @returns the keys produced, or undefined when more bytes are needed.
|
|
112
|
-
*/
|
|
113
|
-
private take;
|
|
114
|
-
/**
|
|
115
|
-
* Collect bracketed-paste content up to its end marker.
|
|
116
|
-
* @returns the paste key once complete, otherwise undefined.
|
|
117
|
-
*/
|
|
118
|
-
private takePasted;
|
|
119
|
-
}
|
|
120
|
-
/** Ask the terminal to wrap pasted text in markers. */
|
|
121
|
-
export declare const ENABLE_PASTE_MARKERS = "\u001B[?2004h";
|
|
122
|
-
/** Stop the terminal wrapping pasted text, restoring what it did before. */
|
|
123
|
-
export declare const DISABLE_PASTE_MARKERS = "\u001B[?2004l";
|
package/lib/types/markdown.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown as terminal lines.
|
|
3
|
-
*
|
|
4
|
-
* A model answers in Markdown, and printing the source verbatim leaves the
|
|
5
|
-
* reader to parse `**` and fences by eye. This renders the constructs that
|
|
6
|
-
* actually change how an answer reads — headings, lists, quotes, emphasis,
|
|
7
|
-
* inline code, and fenced blocks — and leaves everything else exactly as it
|
|
8
|
-
* arrived. Anything unrecognised must survive unchanged: mangling prose to
|
|
9
|
-
* decorate it is worse than not decorating it.
|
|
10
|
-
* @module codsh-cli/src/markdown
|
|
11
|
-
*/
|
|
12
|
-
import type { SyntaxTheme, Theme } from './theme.ts';
|
|
13
|
-
/**
|
|
14
|
-
* Colour one line of code by token class.
|
|
15
|
-
*
|
|
16
|
-
* A heuristic, not a parser: it has no state between lines, so a string or
|
|
17
|
-
* comment spanning several lines is coloured only on the line where it opens.
|
|
18
|
-
* Getting that wrong costs a colour, never the text — every branch reproduces
|
|
19
|
-
* its input exactly.
|
|
20
|
-
* @param line - the code line.
|
|
21
|
-
* @param syntax - styling per token class.
|
|
22
|
-
* @returns the coloured line.
|
|
23
|
-
*/
|
|
24
|
-
export declare function highlightCode(line: string, syntax: SyntaxTheme): string;
|
|
25
|
-
/**
|
|
26
|
-
* Style the inline constructs of one line of prose.
|
|
27
|
-
* @param text - the line, with block syntax already stripped.
|
|
28
|
-
* @param theme - styling for emphasis, code spans, and link targets.
|
|
29
|
-
* @returns the styled line.
|
|
30
|
-
*/
|
|
31
|
-
export declare function renderInline(text: string, theme: Theme): string;
|
|
32
|
-
/**
|
|
33
|
-
* A Markdown renderer that consumes one line at a time.
|
|
34
|
-
*
|
|
35
|
-
* Stateful because fencing is: whether a line is code depends on a fence seen
|
|
36
|
-
* earlier, so a renderer that forgot between lines would style the inside of a
|
|
37
|
-
* code block as prose. This is the form streaming needs — a line can be
|
|
38
|
-
* rendered the moment it completes, without waiting for the whole answer.
|
|
39
|
-
*/
|
|
40
|
-
export interface MarkdownStream {
|
|
41
|
-
/**
|
|
42
|
-
* Render one input line.
|
|
43
|
-
* @param line - the line, without its terminator.
|
|
44
|
-
* @returns the output lines, which may be none (a fence delimiter, or a table
|
|
45
|
-
* row held until the table ends).
|
|
46
|
-
*/
|
|
47
|
-
line(line: string): string[];
|
|
48
|
-
/**
|
|
49
|
-
* Close the stream, rendering anything still held back.
|
|
50
|
-
*
|
|
51
|
-
* A table is only recognisable once its delimiter row arrives, so its rows
|
|
52
|
-
* buffer; an answer that ends mid-table must still show them.
|
|
53
|
-
* @returns the remaining output lines.
|
|
54
|
-
*/
|
|
55
|
-
flush(): string[];
|
|
56
|
-
/** Whether the renderer is currently inside a fenced block. */
|
|
57
|
-
readonly inCode: boolean;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build a line-at-a-time Markdown renderer.
|
|
61
|
-
* @param theme - styling for every construct.
|
|
62
|
-
* @param columns - display columns available, read per table; absent means
|
|
63
|
-
* unconstrained. A table wider than this prints as its source lines.
|
|
64
|
-
* @returns the renderer, carrying its own fence and table state.
|
|
65
|
-
*/
|
|
66
|
-
export declare function createMarkdownStream(theme: Theme, columns?: () => number): MarkdownStream;
|
|
67
|
-
/**
|
|
68
|
-
* Render a whole Markdown answer as terminal lines.
|
|
69
|
-
* @param text - the answer, as the model produced it.
|
|
70
|
-
* @param theme - styling for every construct.
|
|
71
|
-
* @returns the output lines, blocks included.
|
|
72
|
-
*/
|
|
73
|
-
export declare function renderMarkdown(text: string, theme: Theme): string[];
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Installing this bundle's own preset into the Harness home.
|
|
3
|
-
*
|
|
4
|
-
* The launcher owns the roster's `roots`: `composeProfile` overwrites that key
|
|
5
|
-
* with the installed app's shipped directory, so a bundle cannot contribute a
|
|
6
|
-
* search root of its own. What it can reach is the writable user root the
|
|
7
|
-
* roster appends by default, which is why a packaged preset is copied there
|
|
8
|
-
* rather than pointed at in place.
|
|
9
|
-
*
|
|
10
|
-
* The copy is idempotent and never overwrites: a preset a person edited — or
|
|
11
|
-
* one a newer package version would change — stays as it is, because the user
|
|
12
|
-
* root is theirs. Removing the directory restores the packaged copy.
|
|
13
|
-
* @module codsh-cli/src/preset-install
|
|
14
|
-
*/
|
|
15
|
-
/** The preset this bundle's patch names as the roster default. */
|
|
16
|
-
export declare const PACKAGED_PRESET = "code-cli";
|
|
17
|
-
/** What one install attempt did. */
|
|
18
|
-
export interface PresetInstallResult {
|
|
19
|
-
/** Absolute directory the preset occupies after the attempt. */
|
|
20
|
-
path: string;
|
|
21
|
-
/** Whether this call created it; false when it was already present. */
|
|
22
|
-
installed: boolean;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Where {@link installPackagedPreset} puts the preset by default.
|
|
26
|
-
* @returns the absolute preset directory under the Harness home's user root.
|
|
27
|
-
*/
|
|
28
|
-
export declare function packagedPresetPath(): string;
|
|
29
|
-
/**
|
|
30
|
-
* Copy the packaged preset into the user root unless it is already there.
|
|
31
|
-
* @param home - the user preset root; defaults to the Harness home's.
|
|
32
|
-
* @returns where the preset lives and whether this call wrote it.
|
|
33
|
-
*/
|
|
34
|
-
export declare function installPackagedPreset(home?: string): Promise<PresetInstallResult>;
|
package/lib/types/prompt.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The prompt as the person sees it: an input box, a completion menu, a working
|
|
3
|
-
* indicator, a status row, and — when a decision is being asked — a selection
|
|
4
|
-
* widget in the box's place.
|
|
5
|
-
*
|
|
6
|
-
* This is where the two input shapes meet. On a terminal it drives the editor
|
|
7
|
-
* from decoded keys and owns the bottom region; off one it reads lines from the
|
|
8
|
-
* pipe and draws nothing. Callers ask for the next submission either way.
|
|
9
|
-
* @module codsh-cli/src/prompt
|
|
10
|
-
*/
|
|
11
|
-
import type { TerminalConsole } from './console.ts';
|
|
12
|
-
import type { EditorSources } from './editor.ts';
|
|
13
|
-
import type { SelectOutcome, SelectSpec } from './selector.ts';
|
|
14
|
-
import type { Theme } from './theme.ts';
|
|
15
|
-
/** What the prompt reports to its owner. */
|
|
16
|
-
export interface PromptHandlers {
|
|
17
|
-
/** Ctrl-C: stop the work, or leave. */
|
|
18
|
-
interrupt(): void;
|
|
19
|
-
/** Escape with nothing of the prompt's own to dismiss: stop the work. */
|
|
20
|
-
escape(): void;
|
|
21
|
-
/** Ctrl-D on an untouched prompt: leave. */
|
|
22
|
-
eof(): void;
|
|
23
|
-
/** Shift-Tab: cycle the session's mode. */
|
|
24
|
-
shiftTab?(): void;
|
|
25
|
-
/** Ctrl-O: show the last clipped tool output in full. */
|
|
26
|
-
expandOutput?(): void;
|
|
27
|
-
}
|
|
28
|
-
/** Drives the input box and answers reads and selections. */
|
|
29
|
-
export declare class Prompt {
|
|
30
|
-
private readonly console;
|
|
31
|
-
private readonly theme;
|
|
32
|
-
private readonly handlers;
|
|
33
|
-
/** Dim text shown inside an empty box. */
|
|
34
|
-
private readonly placeholder?;
|
|
35
|
-
private readonly editor;
|
|
36
|
-
private pending;
|
|
37
|
-
private select_;
|
|
38
|
-
/**
|
|
39
|
-
* Submissions made before anything asked for them.
|
|
40
|
-
*
|
|
41
|
-
* Typing while the agent works — or in the instant before a read begins — must
|
|
42
|
-
* not be lost; the queue is what a line reader provides for free.
|
|
43
|
-
*/
|
|
44
|
-
private readonly queued;
|
|
45
|
-
/** The working indicator shown under the box. */
|
|
46
|
-
private hint;
|
|
47
|
-
/** A short-lived notice that borrows the hint row, e.g. the copy toast. */
|
|
48
|
-
private flash;
|
|
49
|
-
private flashTimer;
|
|
50
|
-
/** The always-current session facts shown as the region's last row. */
|
|
51
|
-
private status;
|
|
52
|
-
/** The assistant line still arriving, shown above the box. */
|
|
53
|
-
private streaming;
|
|
54
|
-
/** Frame styling for the current mode, e.g. plan mode's accent. */
|
|
55
|
-
private accent;
|
|
56
|
-
/** Whether a read is outstanding, which decides where a submission goes. */
|
|
57
|
-
private reading;
|
|
58
|
-
/** Wheel rows accumulated this tick, painted once — scrolling per event janks. */
|
|
59
|
-
private pendingScroll;
|
|
60
|
-
private scrollFlushQueued;
|
|
61
|
-
/**
|
|
62
|
-
* Whether the interactive session is running, which is when the box is worth
|
|
63
|
-
* drawing. The box stays up while the agent works — typing ahead must be
|
|
64
|
-
* visible, and a prompt that vanishes for every turn reads as losing focus —
|
|
65
|
-
* so this is session-scoped, not read-scoped.
|
|
66
|
-
*/
|
|
67
|
-
private engaged;
|
|
68
|
-
constructor(console: TerminalConsole, theme: Theme, sources: EditorSources, handlers: PromptHandlers,
|
|
69
|
-
/** Dim text shown inside an empty box. */
|
|
70
|
-
placeholder?: string | undefined);
|
|
71
|
-
/** The editor's submission history, for persistence. */
|
|
72
|
-
get history(): readonly string[];
|
|
73
|
-
/**
|
|
74
|
-
* Preload history from an earlier session.
|
|
75
|
-
* @param entries - past submissions, oldest first.
|
|
76
|
-
*/
|
|
77
|
-
seedHistory(entries: readonly string[]): void;
|
|
78
|
-
/** Whether the box holds no typed text. */
|
|
79
|
-
get empty(): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Show the input box from now on, independent of an outstanding read.
|
|
82
|
-
* @param engaged - whether the interactive session is running.
|
|
83
|
-
*/
|
|
84
|
-
setEngaged(engaged: boolean): void;
|
|
85
|
-
/**
|
|
86
|
-
* Put earlier text back into the box for editing.
|
|
87
|
-
* @param text - the text to edit.
|
|
88
|
-
*/
|
|
89
|
-
prefill(text: string): void;
|
|
90
|
-
/**
|
|
91
|
-
* Set the working indicator under the box.
|
|
92
|
-
* @param text - the text, or undefined to drop the row.
|
|
93
|
-
*/
|
|
94
|
-
setHint(text: string | undefined): void;
|
|
95
|
-
/**
|
|
96
|
-
* Show a notice on the hint row briefly, then give the row back.
|
|
97
|
-
*
|
|
98
|
-
* The hint row belongs to the working indicator, which repaints itself
|
|
99
|
-
* continuously — a notice written through setHint would last one tick. The
|
|
100
|
-
* flash outranks the hint until its moment passes.
|
|
101
|
-
* @param text - the styled notice.
|
|
102
|
-
*/
|
|
103
|
-
setFlash(text: string): void;
|
|
104
|
-
/**
|
|
105
|
-
* Set the status row, the region's always-current last line.
|
|
106
|
-
* @param text - the styled row, or undefined to drop it.
|
|
107
|
-
*/
|
|
108
|
-
setStatus(text: string | undefined): void;
|
|
109
|
-
/**
|
|
110
|
-
* Set the frame accent, which is how a mode shows on the box itself.
|
|
111
|
-
* @param accent - the styling, or undefined for the default frame.
|
|
112
|
-
*/
|
|
113
|
-
setAccent(accent: ((text: string) => string) | undefined): void;
|
|
114
|
-
/**
|
|
115
|
-
* Set the assistant line currently arriving, shown above the box.
|
|
116
|
-
* @param text - the partial line, or undefined when none is open.
|
|
117
|
-
*/
|
|
118
|
-
setStreaming(text: string | undefined): void;
|
|
119
|
-
/**
|
|
120
|
-
* Write one finished transcript line above the region.
|
|
121
|
-
* @param line - the line to keep.
|
|
122
|
-
*/
|
|
123
|
-
write(line: string): void;
|
|
124
|
-
/**
|
|
125
|
-
* Wait for the next submitted text.
|
|
126
|
-
* @param signal - abandons the read, which an aborted tool call does.
|
|
127
|
-
* @returns the text, or undefined when input ended or the read was abandoned.
|
|
128
|
-
*/
|
|
129
|
-
read(signal?: AbortSignal): Promise<string | undefined>;
|
|
130
|
-
/**
|
|
131
|
-
* Put one decision to the keyboard as an arrow-key selection.
|
|
132
|
-
*
|
|
133
|
-
* Only the terminal shape can offer this; the caller keeps a line-based
|
|
134
|
-
* fallback for pipes, where the selection keys cannot arrive.
|
|
135
|
-
* @param spec - the question and its options.
|
|
136
|
-
* @param signal - cancels the selection, which an aborted tool call does.
|
|
137
|
-
* @returns how the person decided.
|
|
138
|
-
*/
|
|
139
|
-
select(spec: SelectSpec, signal?: AbortSignal): Promise<SelectOutcome>;
|
|
140
|
-
/** Take the region down, so what follows lands at the bottom of the screen. */
|
|
141
|
-
clear(): void;
|
|
142
|
-
/**
|
|
143
|
-
* Apply one key: control keys to the owner, a selection's keys to the
|
|
144
|
-
* selector, everything else to the editor.
|
|
145
|
-
* @param key - the decoded keystroke.
|
|
146
|
-
*/
|
|
147
|
-
private onKey;
|
|
148
|
-
/** Recompose and redraw the bottom region. */
|
|
149
|
-
private render;
|
|
150
|
-
}
|