Repository navigation
Commit d9498f8
feat(cli): send rich context with shelltime q (#315)
* fix(model): classify compound commands for auto-run
ClassifyCommand only looked at the first word, so with ai.agent.view
enabled `curl ... | sh`, `ls | xargs rm -rf` or `cat a; rm -rf ~` were
auto-run as "view". `shelltime q` is about to send repository-controlled
text (file names, commit subjects, script names) to the model, so the
classifier has to be safe against a manipulated suggestion.
- Split pipelines, lists and substitutions (quote and escape aware) and
return the most severe segment.
- Treat interpreters and wrappers (sh, python, xargs, sudo, eval, env
with a command, find -exec, ...) and multi-line scripts as "other",
which never auto-runs.
- Upgrade view commands that redirect output to a file, and downloads
(curl -o, wget), to "edit".
- Classify git, docker/podman, kubectl and systemctl by subcommand:
read-only subcommands stay "view", `git reset --hard`, forced pushes,
branch/stash deletion and `kubectl delete` are "delete", and exec,
reboot and global git options are "other".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gybkwT4DrTkNF4wKq54JT
* feat(cli): send rich context with shelltime q
`shelltime q` only sent the shell, OS, working directory and hostname,
so suggestions guessed at the repository, project tooling and machine.
When ai.shareContext is enabled (the default) it now also sends a
`context` object, collected concurrently within 500ms:
- system: OS version, kernel, arch, CPU count, uptime, load average,
root, SSH, container, multiplexer, terminal, timezone and local time
(read from /proc and sysctl, no forks)
- git: path in repo, branch, upstream, ahead/behind, staged, unstaged,
untracked and conflicted counts, in-progress operation, remote hosts
and the last 3 commit subjects; falls back to HEAD if `git status` is
slow
- project: types and package managers from manifest and lock files,
walking up to the repo root for monorepos, plus package.json script,
Makefile target and justfile recipe names
- tools found on PATH, and up to 40 names from the current directory
The shell is now taken from the parent process when it is a known
shell, so a fish session started from a zsh login shell is reported as
fish. `shelltime q --show-context "..."` prints the request without
calling the AI. With ai.shareContext: false only shell, OS and query
are sent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gybkwT4DrTkNF4wKq54JT
* fix(model): stop global flags and odd justfile lines defeating q safety
- classifyDocker, classifyKubectl and classifySystemctl read the first
argument as the subcommand, so `kubectl -n prod delete pod web`,
`docker --context x rm -f web` or `systemctl --force poweroff` fell
through to "edit" and auto-ran with ai.agent.edit. A leading global
option now classifies as "other" (never auto-run), as git already did.
- ParseJustRecipes indexed fields[0] on lines made only of non-ASCII
whitespace (\v, \f, NBSP), panicking inside a collector goroutine and
crashing `shelltime q`. Skip such lines.
- Recover panics in query context collectors so a collector bug can
only drop that piece of context.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gybkwT4DrTkNF4wKq54JT
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c8dd39c commit d9498f8
25 files changed
Lines changed: 2527 additions & 114 deletions
File tree
- commands
- daemon
- docs
- fixtures/query_context
- model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
28 | | - | |
| 42 | + | |
| 43 | + | |
29 | 44 | | |
30 | 45 | | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
34 | 49 | | |
35 | | - | |
36 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
37 | 54 | | |
38 | 55 | | |
39 | 56 | | |
| |||
59 | 76 | | |
60 | 77 | | |
61 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
62 | 89 | | |
63 | 90 | | |
64 | 91 | | |
65 | 92 | | |
66 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
67 | 99 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
74 | 105 | | |
75 | 106 | | |
76 | 107 | | |
| |||
156 | 187 | | |
157 | 188 | | |
158 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
159 | 209 | | |
160 | 210 | | |
161 | 211 | | |
| |||
189 | 239 | | |
190 | 240 | | |
191 | 241 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | 242 | | |
207 | | - | |
208 | | - | |
| 243 | + | |
| 244 | + | |
209 | 245 | | |
210 | 246 | | |
211 | 247 | | |
212 | 248 | | |
213 | | - | |
214 | | - | |
215 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
216 | 252 | | |
217 | 253 | | |
218 | 254 | | |
| |||
0 commit comments