feat(cli): send pwd and hostname with shelltime q#274
Conversation
Add `pwd` and `hostname` to the command-suggest payload so the server can record where each query was made. Both are best-effort: errors fall back to empty strings (the server treats them as optional) and a new `[ai] shareContext = false` opt-out in the user config suppresses them. https://claude.ai/code/session_01K1cG3jJD4TygQEsxmMc9hD
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 98 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a ShareContext configuration option to control the inclusion of the working directory and hostname in AI query contexts. The getSystemContext function was updated to collect this information by default, and the CommandSuggestVariables model now includes these fields. Feedback from the review suggests improving test coverage by explicitly verifying that these context fields are populated when the configuration is not provided, ensuring the default behavior is correctly maintained.
| context, err := getSystemContext(query, nil) | ||
| assert.Nil(s.T(), err) | ||
| assert.Equal(s.T(), "bash", context.Shell) | ||
| assert.Equal(s.T(), runtime.GOOS, context.Os) | ||
| assert.Equal(s.T(), query, context.Query) |
There was a problem hiding this comment.
The test for the default case (where ai is nil) should also verify that Pwd and Hostname are populated when ShareContext is not explicitly disabled. This ensures that the "default to true" behavior is correctly implemented and maintained.
| context, err := getSystemContext(query, nil) | |
| assert.Nil(s.T(), err) | |
| assert.Equal(s.T(), "bash", context.Shell) | |
| assert.Equal(s.T(), runtime.GOOS, context.Os) | |
| assert.Equal(s.T(), query, context.Query) | |
| context, err := getSystemContext(query, nil) | |
| assert.Nil(s.T(), err) | |
| assert.Equal(s.T(), "bash", context.Shell) | |
| assert.Equal(s.T(), runtime.GOOS, context.Os) | |
| assert.Equal(s.T(), query, context.Query) | |
| // Verify that context fields are populated by default | |
| assert.NotEmpty(s.T(), context.Pwd) | |
| assert.NotEmpty(s.T(), context.Hostname) |
Summary
Sends
pwd(fromos.Getwd) andhostname(fromos.Hostname)alongside the existing
shell,os, andqueryfields when invokingPOST /api/v1/ai/command-suggest. The server uses these to populatethe new "AI Query History" view in web/iOS clients.
Both fields are best-effort: collection errors fall back to empty
strings and the server treats them as optional. A new
[ai] shareContext = falsetoggle in~/.shelltime/config.toml(orconfig.local.toml) suppresses them entirely for users who don't wantlocal context leaving their machine.
Paired with:
shelltime/server#claude/show-command-context-info-ej2YW(requestschema accepts the new fields, validation max=4096 for pwd / max=255
for hostname, server records them and the captured IP).
shelltime/web#claude/show-command-context-info-ej2YWandshelltime/ios#claude/show-command-context-info-ej2YWrender thedata.
Test plan
go build ./...clean.shelltime q "list files"against a dev server and confirmthe request body includes
pwdandhostname.[ai] shareContext = falseand re-run; verify both fieldsare absent.
go test -run TestGetSystemContext ./commands/...(requiresmockeryto regeneratemock_*.gofirst).https://claude.ai/code/session_01K1cG3jJD4TygQEsxmMc9hD
Generated by Claude Code