@thegitai/cli 1.6.0 → 1.8.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 +2 -0
- package/dist/src/api/voice.js +96 -0
- package/dist/src/help-text.js +239 -226
- package/dist/src/keybindings-file.js +38 -0
- package/dist/src/keyboard-shortcuts.js +62 -0
- package/dist/src/preferences.js +8 -2
- package/dist/src/ui/repl.js +162 -5
- package/dist/src/ui/slash-commands.js +3 -1
- package/dist/src/ui/tui/bridge.js +50 -0
- package/dist/src/ui/tui/build-frame.js +64 -15
- package/dist/src/ui/tui/shell-input.js +12 -14
- package/dist/src/ui/tui/shortcuts.js +10 -5
- package/dist/src/ui/tui/voice-dictation.js +438 -0
- package/package.json +10 -7
package/dist/src/help-text.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import chalk from './colors.js';
|
|
2
|
+
import { shortcutLabel } from './keyboard-shortcuts.js';
|
|
2
3
|
import { getCliVersion, getPlatformTag } from './version.js';
|
|
3
4
|
function pasteShortcutForPlatform() {
|
|
4
5
|
switch (process.platform) {
|
|
@@ -11,227 +12,239 @@ function pasteShortcutForPlatform() {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
const PASTE_SHORTCUT = pasteShortcutForPlatform();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
15
|
+
function helpMarkdown(shortcuts = {}) {
|
|
16
|
+
const key = (id) => shortcutLabel(id, shortcuts);
|
|
17
|
+
return [
|
|
18
|
+
'# TheGitAI',
|
|
19
|
+
'',
|
|
20
|
+
'Interactive terminal coding agent. Local repo search, file edits, and',
|
|
21
|
+
'shell commands run on your machine. Model inference and server-executed',
|
|
22
|
+
'tools run on the server.',
|
|
23
|
+
'',
|
|
24
|
+
'## Usage',
|
|
25
|
+
'',
|
|
26
|
+
'- `ai` - start an interactive chat session in the current repo',
|
|
27
|
+
'- `ai "<request>"` - start an interactive session with `<request>` as the first message',
|
|
28
|
+
'- Coding sessions require terminal stdin and stdout; piped prompts are not supported.',
|
|
29
|
+
'',
|
|
30
|
+
'## Auth',
|
|
31
|
+
'',
|
|
32
|
+
'- `ai` - signs you in if you are not already, then starts a session',
|
|
33
|
+
'- `ai login` - the same thing; kept for muscle memory',
|
|
34
|
+
'- Signing in opens your browser. When it cannot open one - over SSH, in a',
|
|
35
|
+
' container, or when the browser you want is on another device - the same',
|
|
36
|
+
' screen prints a URL you can open anywhere and takes the code that page',
|
|
37
|
+
' gives you back. There is no mode to pick and no flag to remember.',
|
|
38
|
+
'- `ai whoami` - show the signed-in account',
|
|
39
|
+
'- `ai --usage` - show account usage percentage and reset times',
|
|
40
|
+
'- `ai logout` - sign out',
|
|
41
|
+
'',
|
|
42
|
+
'## MCP servers',
|
|
43
|
+
'',
|
|
44
|
+
'- `ai mcp add <name> -- <command> [args...]` - connect a local MCP server',
|
|
45
|
+
'- `ai mcp add --transport http <name> <url>` - connect a remote MCP server',
|
|
46
|
+
'- `ai mcp --help` - configuration, headers, environment variables and commands',
|
|
47
|
+
'- Short setup flags: `-t` transport, `-e` environment, `-H` header, `-s user` scope.',
|
|
48
|
+
'- `/mcp` - check connections and available tools; changes apply next turn',
|
|
49
|
+
'- Default mode asks before MCP calls; approvals can cover one tool for the session.',
|
|
50
|
+
'- Bypass mode also approves MCP calls. Plan mode blocks MCP calls.',
|
|
51
|
+
'- Invalid servers are reported individually; chat continues with available tools.',
|
|
52
|
+
'- `/mcp` retries connections; tool lists are cached for one minute.',
|
|
53
|
+
'- MCP supports tools over stdio and Streamable HTTP. OAuth, prompts and resources',
|
|
54
|
+
' are not supported yet. Add only servers you trust.',
|
|
55
|
+
'',
|
|
56
|
+
'## Sessions',
|
|
57
|
+
'',
|
|
58
|
+
'- `ai --list-sessions` - list saved sessions for this repo',
|
|
59
|
+
'- `ai --session <id|name>` - resume a saved session by id or name',
|
|
60
|
+
'- Sessions are stored locally and can be listed or resumed in the same repo.',
|
|
61
|
+
' Continuing one requires the TheGitAI account used for that session.',
|
|
62
|
+
'',
|
|
63
|
+
'## Updates',
|
|
64
|
+
'',
|
|
65
|
+
'- On start, `ai` says when a newer release is published and offers to install',
|
|
66
|
+
' it. TheGitAI works best on the latest version, and an older CLI may not',
|
|
67
|
+
' work optimally.',
|
|
68
|
+
'- **Update now** is selected when the offer appears, so **Enter** takes the',
|
|
69
|
+
' update; **↑/↓** moves to **Skip**, and the number keys still jump straight',
|
|
70
|
+
' to a row. The CLI installs the update and asks you to start `ai` again, so',
|
|
71
|
+
' the whole session runs one version.',
|
|
72
|
+
'- Skipping starts the session on the version you have and asks again next',
|
|
73
|
+
' time. A release cannot be silenced for good - that is what keeps a broken',
|
|
74
|
+
' combination from lasting.',
|
|
75
|
+
'- **Ctrl+C** at the prompt quits without installing anything and without',
|
|
76
|
+
' starting the session.',
|
|
77
|
+
'',
|
|
78
|
+
'## Options',
|
|
79
|
+
'',
|
|
80
|
+
'- `-y, --yes` - start in Bypass all permissions mode',
|
|
81
|
+
'- `-h, --help` - show this help',
|
|
82
|
+
'- `-v, --version` - print the version and exit',
|
|
83
|
+
'',
|
|
84
|
+
'## Modes',
|
|
85
|
+
'',
|
|
86
|
+
'- Default · Ask for Approval - asks before creating, editing or deleting',
|
|
87
|
+
' files, before running commands, and before touching a website. Each answer',
|
|
88
|
+
' can be remembered for the rest of the session, and once it is, Default',
|
|
89
|
+
' stops asking for that action; see Safety & approvals.',
|
|
90
|
+
'- Bypass all permissions - approves every command, file edit, deletion and',
|
|
91
|
+
' browser action for the rest of the session, without asking. Shown in red',
|
|
92
|
+
' in the footer. Blocked commands stay blocked.',
|
|
93
|
+
'- Plan - read-only; the agent can inspect, ask typed questions, and plan,',
|
|
94
|
+
' with file-reading shell commands only. It will not edit files or run tests,',
|
|
95
|
+
' builds, diagnostics, package managers, project code, or network probes.',
|
|
96
|
+
`- In the TUI, press **?** on an empty composer for the keyboard-and-mouse panel. ${key('cycleMode')} cycles Default → Bypass → Plan (refused while the agent is working), mouse drag copies transcript/footer text, left-click opens rendered links, right-click copies rendered links or pastes in the sticky composer/footer when no selection is active, double-click copies a word, and triple-click copies a row.`,
|
|
97
|
+
'',
|
|
98
|
+
'## Keys & clipboard',
|
|
99
|
+
'',
|
|
100
|
+
'- **?** on an empty composer opens the keyboard-and-mouse panel.',
|
|
101
|
+
`- **Enter** sends • **${key('cycleMode')}** cycles Default → Bypass → Plan (only`,
|
|
102
|
+
' between turns) • **Esc** cancels the turn •',
|
|
103
|
+
' **Ctrl+C** clears the composer or the queued message, and quits once there',
|
|
104
|
+
' is nothing left to clear. These are the same on macOS, Linux, and Windows.',
|
|
105
|
+
'- **While the agent is working**, Enter queues your message and locks the',
|
|
106
|
+
' composer. Press **Enter** again to send it into the running turn: the agent',
|
|
107
|
+
' picks it up at its next step instead of waiting for the turn to finish, and',
|
|
108
|
+
' the Your messages panel tracks it from queued to delivered. **↑** brings it',
|
|
109
|
+
' back for editing and **Esc**/**Ctrl+C** discards it; both unlock the',
|
|
110
|
+
` composer for the next message. **${key('pasteImage')}** pastes a screenshot onto the`,
|
|
111
|
+
' queued message, and it is delivered into the running turn with the text.',
|
|
112
|
+
`- **/voice** turns voice dictation on, and it stays on between sessions. Then hold **${key('pushToTalk')}**`,
|
|
113
|
+
' to talk and let go to stop: your words land in the composer at the cursor and',
|
|
114
|
+
' are never sent on their own. **Esc** or **Ctrl+C** cancels a recording.',
|
|
115
|
+
' `/voice tap` switches to tap to start and tap again to stop, `/voice hold`',
|
|
116
|
+
' switches back, and `/voice off` turns it off. The microphone is used only',
|
|
117
|
+
' while you record.',
|
|
118
|
+
`- **${key('notifications')}** turns desktop notifications on or off. One is raised when a turn`,
|
|
119
|
+
' ends and when a permission prompt or a question is waiting for you, but',
|
|
120
|
+
' only while the terminal is in the background - if you are looking at the',
|
|
121
|
+
' session you are told nothing. Coming back clears it. The choice is',
|
|
122
|
+
' remembered between sessions.',
|
|
123
|
+
`- **Paste** into the composer with your terminal's paste shortcut (\`${PASTE_SHORTCUT}\``,
|
|
124
|
+
' on this system) or by right-clicking the composer.',
|
|
125
|
+
'- **Copy** from the transcript by dragging to select; double-click copies a',
|
|
126
|
+
' word and triple-click copies a row. Left-click opens rendered links.',
|
|
127
|
+
...(process.platform === 'darwin'
|
|
128
|
+
? ['- On Mac laptops without dedicated keys, **Home/End** are `Fn+←` / `Fn+→`.']
|
|
129
|
+
: []),
|
|
130
|
+
'',
|
|
131
|
+
'## Questions',
|
|
132
|
+
'',
|
|
133
|
+
'- The agent can pause a turn to ask up to four questions in one form.',
|
|
134
|
+
' **↑/↓** moves, the option number or **Enter** chooses, **←/→** moves',
|
|
135
|
+
' between questions, and the last question has a **Submit answers** row.',
|
|
136
|
+
'- Only the option you are on shows its description, so the whole form fits',
|
|
137
|
+
' on screen. Move to an option to read what it means.',
|
|
138
|
+
'- **Something else / add details** is the numbered final option: focus it',
|
|
139
|
+
' and type. **Enter** commits the note and moves to the next question, or to',
|
|
140
|
+
' Submit on the last one - it never submits the form for you.',
|
|
141
|
+
'- **Esc** closes an open note first, and otherwise cancels the form.',
|
|
142
|
+
'',
|
|
143
|
+
'## Chat commands',
|
|
144
|
+
'',
|
|
145
|
+
'- Type `/` to open the command picker. It ranks what you type, so a typo or',
|
|
146
|
+
' a stray plural (`/moddel`, `/models`) still finds the command, and a word',
|
|
147
|
+
' from the description does too (`/bug` finds `/report`). It shows the five',
|
|
148
|
+
' best matches and counts the rest; **↑/↓** chooses, **Tab** or **Enter**',
|
|
149
|
+
' accepts, **Esc** closes it.',
|
|
150
|
+
'- `/help` - show this help',
|
|
151
|
+
'- `/mcp` - check MCP connections and list available tools',
|
|
152
|
+
'- `/skills` - list your skills and any that failed to load',
|
|
153
|
+
'- `/skills add <source>` - install a skill from GitHub (`owner/repo/path`',
|
|
154
|
+
' or a GitHub URL) or from a local folder into ~/.thegitai/skills; add',
|
|
155
|
+
' `--project` to put it in this project\'s .thegitai/skills instead',
|
|
156
|
+
'- `/memory` - see the topics the agent has saved on this computer; also',
|
|
157
|
+
' `/memory show <number>`, `/memory delete <number>`, `/memory off`, `/memory on`',
|
|
158
|
+
'- `/<skill> [what to do]` - run a skill yourself. Skills show up in the',
|
|
159
|
+
' command picker, and the agent also loads a matching skill on its own',
|
|
160
|
+
'- `/about` - show version and platform info',
|
|
161
|
+
'- `/report` - report a bug or request a feature privately through the TheGitAI website in your',
|
|
162
|
+
' browser (sign in with your existing account)',
|
|
163
|
+
'- `/usage` - show account usage percentage and reset times',
|
|
164
|
+
'- `/model` - ↑/↓ picks a model, ←/→ adjusts effort; Enter saves for this project, Esc cancels',
|
|
165
|
+
'- `/model <id>` - switch the active model without clearing history',
|
|
166
|
+
'- `/resume` - resume a saved session for this repo',
|
|
167
|
+
'- `/jobs` - manage long-running commands like dev servers and watchers:',
|
|
168
|
+
' browse them, press Enter to expand one and read its output, k to stop it',
|
|
169
|
+
`- ${key('backgroundJobs')} - open the same jobs picker, and the only way in while the agent`,
|
|
170
|
+
' is working; press it again or Esc to close without touching the turn',
|
|
171
|
+
'- `/jobs output <id>` - print one job\'s full captured output',
|
|
172
|
+
'- `/jobs kill <id>` - stop one background job',
|
|
173
|
+
`- \`/notify\` - turn desktop notifications on or off (same as ${key('notifications')})`,
|
|
174
|
+
'- `/voice` - turn voice dictation on or off; `/voice hold` or `/voice tap` picks how you record',
|
|
175
|
+
'- `/keybindings` - change the keys for the agent mode, image paste, background',
|
|
176
|
+
' jobs, notifications and dictation',
|
|
177
|
+
'- `/new` - start a new conversation; this session remains saved',
|
|
178
|
+
'- `/logout` - sign out and quit',
|
|
179
|
+
'- `/exit` - quit the session',
|
|
180
|
+
'',
|
|
181
|
+
'## Safety & approvals',
|
|
182
|
+
'',
|
|
183
|
+
'- In Default mode TheGitAI asks before it creates a file, edits an existing',
|
|
184
|
+
' file, deletes a file, or runs a command. These are four separate',
|
|
185
|
+
' permissions: allowing edits does not allow deletions, and allowing file',
|
|
186
|
+
' changes does not allow commands.',
|
|
187
|
+
'- At each prompt: **↑/↓** moves between choices, **Enter** confirms the',
|
|
188
|
+
' highlighted one, and **Esc** denies. Deny is selected by default.',
|
|
189
|
+
' Single-letter shortcuts were removed on purpose: a prompt can appear',
|
|
190
|
+
' while you are typing, and a stray letter must never approve anything.',
|
|
191
|
+
'- Every prompt offers Approve once, an "Always allow" for that kind of',
|
|
192
|
+
' action, and Deny. A command also offers to remember just its prefix - for',
|
|
193
|
+
' example approving `npm test -- --watch=false` can allow `npm test`.',
|
|
194
|
+
'- A prefix is only offered when the command shows a plain verb, as in',
|
|
195
|
+
' `npm test` or `git status`. Commands with no verb (`ls -la`), interpreters',
|
|
196
|
+
' and wrappers (`bash -c`, `python -c`, `env`, `timeout`, `make`), and',
|
|
197
|
+
' destructive or network binaries (`rm`, `sudo`, `curl`) are never offered',
|
|
198
|
+
' one - a bare binary grant would mean "anything this program can do".',
|
|
199
|
+
' `npm run` must name its script, so the grant is `npm run build`.',
|
|
200
|
+
'- A remembered prefix never covers a command that chains, pipes, redirects,',
|
|
201
|
+
' or substitutes, so allowing `npm test` can never green-light',
|
|
202
|
+
' `npm test && rm -rf build`.',
|
|
203
|
+
'- Everything you allow lasts for the current session only and is forgotten',
|
|
204
|
+
' when it ends. `/new` clears it immediately.',
|
|
205
|
+
'- If an approved `sudo` command needs a password, the TUI shows the exact',
|
|
206
|
+
' command and keeps the password masked and local.',
|
|
207
|
+
'- `-y` / `--yes` at startup auto-approves every shell command and file',
|
|
208
|
+
' edit for the whole session - use with care.',
|
|
209
|
+
'- Using desktop apps (Linux and macOS, preview) always asks first, even in',
|
|
210
|
+
' Bypass all permissions mode: in the background, on a screen of its own',
|
|
211
|
+
' you watch in a small window while you keep your mouse and keyboard, or on',
|
|
212
|
+
' your screen, where Esc takes over. The answer lasts for the task, or for',
|
|
213
|
+
' the session if you choose that.',
|
|
214
|
+
'- Long-running commands (e.g. dev servers) can run as managed background',
|
|
215
|
+
' jobs after the same approval as any other command. Background output',
|
|
216
|
+
' stays quiet once the model has responded; the footer shows only a compact',
|
|
217
|
+
' shell-running indicator, `/jobs` lists, inspects, and kills jobs, and',
|
|
218
|
+
' killed jobs disappear immediately. While a turn is running the indicator',
|
|
219
|
+
` points at ${key('backgroundJobs')} instead, which opens the same picker without cancelling`,
|
|
220
|
+
' or interrupting the turn. Every job is killed when the session ends.',
|
|
221
|
+
'- File and shell operations are confined to the target repo root.',
|
|
222
|
+
'- Sensitive directories (`.git`, `node_modules`, build output) are',
|
|
223
|
+
' excluded from search and listing.',
|
|
224
|
+
'',
|
|
225
|
+
'## Troubleshooting',
|
|
226
|
+
'',
|
|
227
|
+
'- Auth or permission errors → run `ai whoami` to confirm the signed-in',
|
|
228
|
+
' account.',
|
|
229
|
+
'- Usage or quota errors → run `ai --usage`.',
|
|
230
|
+
'- Signed in with the wrong account → `/logout` (or `ai logout`), then run',
|
|
231
|
+
' `ai` and sign in as the account you intended to use.',
|
|
232
|
+
'- The browser did not open, or opened on the wrong machine → open the URL',
|
|
233
|
+
' printed on the sign-in screen anywhere you like, choose "On another',
|
|
234
|
+
' computer" on that page, and paste the code back into the terminal.',
|
|
235
|
+
'- A local session was used with a different sign-in → sign in with the',
|
|
236
|
+
' account you used for that session or start a new session.',
|
|
237
|
+
'- The connection drops mid-turn → nothing to do: the CLI reconnects to the',
|
|
238
|
+
' same turn up to three times, ten seconds apart, without running anything',
|
|
239
|
+
' twice. Esc stops it. If it cannot reconnect it says so; some actions may',
|
|
240
|
+
' already have completed, and a queued message waits in the composer.',
|
|
241
|
+
' If the service restarted mid-turn, the turn continues from the steps that',
|
|
242
|
+
' had finished. Starting `ai` while the service is briefly unavailable waits',
|
|
243
|
+
' the same way.',
|
|
244
|
+
'- For anything else, re-run the command and file the printed error',
|
|
245
|
+
' message with `/report` - there is no client-side debug mode by design.',
|
|
246
|
+
].join('\n');
|
|
247
|
+
}
|
|
235
248
|
export function formatAboutCard() {
|
|
236
249
|
return [
|
|
237
250
|
'```',
|
|
@@ -243,14 +256,14 @@ export function formatAboutCard() {
|
|
|
243
256
|
].join('\n');
|
|
244
257
|
}
|
|
245
258
|
export function formatHelpMarkdown() {
|
|
246
|
-
return
|
|
259
|
+
return helpMarkdown();
|
|
247
260
|
}
|
|
248
|
-
export function formatInteractiveHelpText() {
|
|
249
|
-
return
|
|
261
|
+
export function formatInteractiveHelpText(shortcuts) {
|
|
262
|
+
return helpMarkdown(shortcuts);
|
|
250
263
|
}
|
|
251
264
|
export function formatCliHelpText({ color = false } = {}) {
|
|
252
265
|
if (!color) {
|
|
253
|
-
return
|
|
266
|
+
return helpMarkdown().split('\n')
|
|
254
267
|
.map((line) => line
|
|
255
268
|
.replace(/^#{1,6}\s+/, '')
|
|
256
269
|
.replace(/^-\s+/, ' ')
|
|
@@ -258,7 +271,7 @@ export function formatCliHelpText({ color = false } = {}) {
|
|
|
258
271
|
.replace(/\*\*([^*]+)\*\*/g, '$1'))
|
|
259
272
|
.join('\n');
|
|
260
273
|
}
|
|
261
|
-
return
|
|
274
|
+
return helpMarkdown().split('\n')
|
|
262
275
|
.map((line) => {
|
|
263
276
|
const heading = line.match(/^(#{1,6})\s+(.*)$/);
|
|
264
277
|
if (heading) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, unwatchFile, watchFile, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getClientStateDir } from './client-state.js';
|
|
4
|
+
import { defaultShortcuts, parseShortcutFile } from './keyboard-shortcuts.js';
|
|
5
|
+
export function keybindingsPath(env) {
|
|
6
|
+
return path.join(getClientStateDir(env), 'keybindings.json');
|
|
7
|
+
}
|
|
8
|
+
export function prepareKeybindings(file, platform = process.platform) {
|
|
9
|
+
mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
10
|
+
const defaults = Object.entries(defaultShortcuts(platform)).map(([id, keys]) => [id, keys.length === 1 ? keys[0] : keys]);
|
|
11
|
+
const content = {
|
|
12
|
+
$docs: 'https://thegit.ai/docs/basics/keyboard-and-mouse#customize-cli-shortcuts',
|
|
13
|
+
...Object.fromEntries(defaults),
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
writeFileSync(file, JSON.stringify(content, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code !== 'EEXIST')
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function watchKeybindings(file, update, error) {
|
|
24
|
+
function reload() {
|
|
25
|
+
try {
|
|
26
|
+
update(parseShortcutFile(JSON.parse(readFileSync(file, 'utf8'))));
|
|
27
|
+
}
|
|
28
|
+
catch (reason) {
|
|
29
|
+
if (reason.code === 'ENOENT')
|
|
30
|
+
update({});
|
|
31
|
+
else
|
|
32
|
+
error(`Could not apply ${file}: ${reason.message} Your previous keys still work.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
watchFile(file, { persistent: false, interval: 450 }, reload);
|
|
36
|
+
reload();
|
|
37
|
+
return () => unwatchFile(file, reload);
|
|
38
|
+
}
|