Skip to content

feat: add multi-profile support#25

Open
jjuanrivvera99 wants to merge 1 commit into
chatwoot:mainfrom
jjuanrivvera:feat/multi-profile
Open

feat: add multi-profile support#25
jjuanrivvera99 wants to merge 1 commit into
chatwoot:mainfrom
jjuanrivvera:feat/multi-profile

Conversation

@jjuanrivvera99

Copy link
Copy Markdown

Summary

Adds named profiles so the CLI can manage more than one Chatwoot instance/account. A global --profile flag, the CHATWOOT_PROFILE env var, and a profiles / profile <name> show|use|remove command tree (following the existing noun grammar), each profile with its own keyring-stored token. Resolution order: --profileCHATWOOT_PROFILE → configured default → default.

Implements the proposal in #24.

The existing flat config.yaml migrates into a default profile on first load, and that profile keeps its historical keyring entry, so current users keep working with no re-login.

One naming question worth settling before merge: profile already names the dev/prod build tag, so I relabeled that to Build: in config view and reserved "profile" for instances. Happy to adjust if you'd prefer different wording.

Tests

internal/config/store_test.go and additions to credentials_test.go cover store migration, active-profile precedence (flag/env/default), default promotion on remove, and per-profile credential isolation. internal/cmd/profile_test.go covers the profiles / profile commands, and main_test.go covers the id-first grammar for string-id nouns. All existing tests pass unchanged.

Green locally: go vet, go build, go test -race -covermode=atomic ./..., govulncheck, golangci-lint, and go mod tidy -diff.

Notes

README usage, the agent skill (command table + read-only allowlist), CHANGELOG, and the package CLAUDE.mds are updated. The default profile keeps the legacy api-key keyring entry; named profiles use a profile:<name> entry.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0df477a530

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/cmd/app.go
Comment on lines +28 to 30
store, err := config.LoadStore()
if err != nil {
return nil, fmt.Errorf("failed to load config: %w", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid loading config before skip-auth commands

Because this runs before the skipAuth check, commands that are intentionally local/no-auth, such as chatwoot auth login, chatwoot config path, and chatwoot version, now fail with failed to load config whenever ~/.chatwoot/config.yaml is malformed or unreadable. That removes the normal recovery path for a user with a corrupt config; defer this load for skip-auth commands or make profile resolution non-fatal there.

Useful? React with 👍 / 👎.

Comment thread cmd/chatwoot/main.go Outdated
Comment on lines +112 to +116
if !stringIDNouns[args[i]] {
if _, err := strconv.Atoi(id); err != nil {
return args
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard verb-first profile commands from being rewritten

For string-ID nouns this accepts any second token, so when a legal profile is named use, remove, or show, verb-first commands such as chatwoot profile show use or chatwoot profile remove use are misclassified as id-first forms and rewritten to profile use show / profile use remove, changing the operation to setting the default profile. Either reserve those names when profiles are created or skip the rewrite when the second token is already a profile verb.

Useful? React with 👍 / 👎.

Save and switch between multiple Chatwoot instances/accounts.

A global --profile flag, the CHATWOOT_PROFILE env var, and a
`profiles` / `profile <name> show|use|remove` command tree manage named
profiles, each with its own keyring-stored token. Resolution order is
--profile flag -> CHATWOOT_PROFILE -> configured default -> "default".

- config.yaml now stores a `profiles` map with `default_profile`; legacy
  single-instance configs migrate into the `default` profile on first
  load, and that profile keeps its historical keyring entry, so upgrades
  need no re-login.
- `auth login --profile <name>` saves into a named profile; `auth logout`
  signs out of only the active profile; `config view` and `auth status`
  report the active profile.
- Keyring entries are per-profile (default keeps the "api-key" entry;
  named profiles use profile:<name>), so switching never crosses tokens.

Implements the "Add profile support" TODO in internal/config. Docs,
CHANGELOG, and the agent skill are updated; adds Store/migration,
per-profile credential, profile-command, and id-first grammar tests.
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.

1 participant