Skip to content

feat(cli): send pwd and hostname with shelltime q#274

Merged
AnnatarHe merged 1 commit into
mainfrom
claude/show-command-context-info-ej2YW
May 16, 2026
Merged

feat(cli): send pwd and hostname with shelltime q#274
AnnatarHe merged 1 commit into
mainfrom
claude/show-command-context-info-ej2YW

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

Summary

Sends pwd (from os.Getwd) and hostname (from os.Hostname)
alongside the existing shell, os, and query fields when invoking
POST /api/v1/ai/command-suggest. The server uses these to populate
the 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 = false toggle in ~/.shelltime/config.toml (or
config.local.toml) suppresses them entirely for users who don't want
local context leaving their machine.

Paired with:

  • shelltime/server#claude/show-command-context-info-ej2YW (request
    schema 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-ej2YW and
    shelltime/ios#claude/show-command-context-info-ej2YW render the
    data.

Test plan

  • go build ./... clean.
  • Run shelltime q "list files" against a dev server and confirm
    the request body includes pwd and hostname.
  • Set [ai] shareContext = false and re-run; verify both fields
    are absent.
  • go test -run TestGetSystemContext ./commands/... (requires
    mockery to regenerate mock_*.go first).

https://claude.ai/code/session_01K1cG3jJD4TygQEsxmMc9hD


Generated by Claude Code

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
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 40.28% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
commands/query.go 87.96% <100.00%> (+0.25%) ⬆️
model/ai_service.go 82.69% <ø> (+2.38%) ⬆️

... and 98 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread commands/query_test.go
Comment on lines +329 to 333
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

@AnnatarHe AnnatarHe merged commit e3adc84 into main May 16, 2026
5 checks passed
@AnnatarHe AnnatarHe deleted the claude/show-command-context-info-ej2YW branch May 16, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants