emdash icon indicating copy to clipboard operation
emdash copied to clipboard

[feat]: Per-project Linear account (support multiple Linear workspaces)

Open crblabs opened this issue 2 months ago • 1 comments

Feature Summary

Allow more than one Linear account to be connected at once, and let each project pick which one it uses, the same way #2235 / #2398 did for GitHub. Today only one Linear credential can exist, so anyone working across several Linear workspaces has to keep swapping the API key.

Problem or Use Case

A Linear API key is scoped to a single workspace. I work in three workspaces (personal projects plus work), so I hold three keys. Emdash only stores one Linear credential, and the issue picker for every project reads that one credential. To pull issues for a work project I have to disconnect Linear, paste the work key, and later swap back. With several projects open at the same time there is no key that works for all of them.

The same limitation applies to every other issue tracker integration (Jira, GitLab, Plane, ...), but Linear is the one I hit daily.

What the GitHub work did (the model to follow)

#2398 "feat: support for multiple GitHub accounts" resolved #2235. The pieces that matter here:

  • Account registry. GitHub accounts became rows in the provider_accounts table (one per provider + account id, with an is_default flag). A management RPC was added to the GitHub contract: listAccounts, setDefaultAccount, removeAccount, importCliAccounts.
  • Accounts UI. The settings integrations area lists connected accounts, marks the default, and lets you connect another one. Connecting an already-connected account shows a toast instead of duplicating. Removing an account that projects still pin warns first (countProjectsUsingGithubAccount).
  • Per-project setting. Project git settings gained githubAccount: { kind: 'account', accountId } | { kind: 'none' }, with "absent = infer". It is exposed in the project settings form and in the add-project modal.
  • Resolver. createProjectGitHubAccountResolver in src/core/features/github/api/node/services/project-github-account-resolver.ts turns a project id into the account its API calls run as, with provenance (set / inferred / unresolvable). A dangling pin fails closed rather than silently using another identity.
  • Consumers. PR sync, issue listing, and automation flows take the resolved account instead of a global token, and account errors are surfaced in the PR and issue surfaces.
  • Migration. A run-once step backfilled the legacy single token into the registry.

Where Linear stands today

The storage layer is already shared with GitHub, so a good part of the groundwork exists:

  • Integration credentials live in the same provider_accounts registry via IntegrationCredentialStore (src/core/features/integrations/node/integration-credential-store.ts). The store already supports getAccount(integrationId, accountId), per-account delete, and upsert by account id.
  • IntegrationConnectionService.connect already derives the account id from verify()'s account field when a plugin returns one, and falls back to the 'default' id otherwise.

What is missing:

  1. Linear's verify() returns no account identity (packages/plugins/src/integrations/impl/linear/client.ts returns only displayName / displayDetail), so every connect writes to the 'default' account id and a second workspace overwrites the first.
  2. Disconnect is all-or-nothing. The integrations wire contract only has list / connect / disconnect(integrationId), and disconnect removes every account for the integration. There is no listAccounts / removeAccount / setDefaultAccount equivalent.
  3. Issue fetching ignores projects. createPluginIssueProvider (src/core/features/integrations/api/node/plugin-issue-provider.ts) calls getIntegrationCredentialStore().get(provider) with no account id, so it always uses the default account. The issues contract (listIssues / searchIssues / getIssueContext) takes a provider but no projectId, so nothing could be resolved per project even if the store held several accounts.
  4. No per-project setting. Project settings have githubAccount but no equivalent for issue-tracker integrations.
  5. Settings UI is single-account. The integrations card / detail sidebar shows one connection per integration.

Proposed Solution

Mirror the GitHub design, generalised to integrations rather than Linear-specific where it is cheap to do so:

  1. Plugin identity. Make Linear's verify() return account: { id: organization.id, login: organization.urlKey } and displayDetail: organization.name, so the account id becomes linear:<orgId>. Other trackers can opt in the same way; anything that keeps returning no account stays single-account with the 'default' id.
  2. Account management RPC. Extend the integrations contract with listAccounts(integrationId), setDefaultAccount(integrationId, accountId), and removeAccount(integrationId, accountId). Keep disconnect for the single-account path or make it call removeAccount on the default.
  3. Settings UI. In the integration detail sidebar, list connected accounts (display name + workspace name), mark the default, add a "Connect another workspace" action, and warn before removing an account that projects still pin.
  4. Per-project setting. Add issueTrackerAccounts?: Record<integrationId, { kind: 'account', accountId } | { kind: 'none' }> (or a Linear-only linearAccount if that is judged simpler) to stored project settings, editable in project settings, absent = use the integration's default account. Include it in countProjectsUsing... for the removal warning.
  5. Resolution. Add a small resolver alongside project-github-account-resolver.ts that maps (projectId, integrationId) to an account id: explicit pin if set and still present, otherwise the default account, unresolvable if the pin dangles.
  6. Plumb it through. Add an optional projectId to the issues contract inputs and to the issue provider options, and have createPluginIssueProvider resolve the account before calling the plugin. The task-creation issue picker already knows the project, so it passes it along.

Alternatives Considered

  • Swapping the API key by hand every time I switch context. That is what I do today; it is error-prone and impossible with several projects open.
  • One Linear account with access to all workspaces. Not possible across separate personal and employer workspaces.
  • A single "active Linear workspace" toggle. Better than nothing, but still a global switch with the same problem #2235 called out for gh auth switch.

Additional Context

  • #2235 (per-project GitHub account) and #2398 (the implementing PR) are the precedent.
  • #104 ("Account management", closed) asked for Linear account management in broad terms but only led to the settings reorganisation.
  • Related: #1930 (sync linked issue status) would also need per-project account resolution once it lands.

crblabs avatar Sep 16 '26 08:09 crblabs

hi, thank you for opening the issue and the pr! while I was looking into it, I decided to add multi account support for all integrations, not just linear and also consolidated a lot of things. this is in the current v1.2.5 release! will therefore close your pr

jschwxrz avatar Sep 18 '26 09:09 jschwxrz