@cat-factory/app 0.155.0 → 0.157.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,9 +78,10 @@ example ships in [`deploy/frontend`](../../deploy/frontend) (the `acme:security`
78
78
  docs/issues/scenarios. Decisions resolve via `DecisionModal`.
79
79
  - **Pipeline builder** (`components/pipeline`) — assemble/edit agent chains and
80
80
  watch `PipelineProgress`.
81
- - **Integrations** — modals/panels for `github`, `bootstrap`, `documents`,
82
- `tasks`, `requirements` (review), `scenarios` (acceptance), and `fragments`
83
- (the prompt-fragment library).
81
+ - **Integrations** — modals/panels for `github` (the source-control panel, shared
82
+ by every VCS provider), `vcs` (the GitLab personal-access-token connect),
83
+ `bootstrap`, `documents`, `tasks`, `requirements` (review), `scenarios`
84
+ (acceptance), and `fragments` (the prompt-fragment library).
84
85
  - **Auth** (`components/auth`) — `AuthGate` / `LoginScreen` / `UserMenu`; the app
85
86
  is gated when the backend requires sign-in.
86
87
 
@@ -2,28 +2,24 @@
2
2
  import { computed, ref, watch } from 'vue'
3
3
  import { apiErrorEnvelope } from '~/composables/api/errors'
4
4
  import SecretInput from '~/components/common/SecretInput.vue'
5
+ import type { VcsProvider } from '~/types/domain'
6
+ import { VCS_PROVIDER_ICONS, VCS_PROVIDER_LABELS, VCS_PROVIDER_TOKEN_URLS } from '~/utils/vcs'
5
7
 
6
8
  const auth = useAuthStore()
7
9
  const { t } = useI18n()
8
10
 
9
11
  // Local-mode source-control PAT login. The PAT lives server-side in env (GITHUB_PAT /
10
12
  // GITLAB_PAT); the login screen only SELECTS a configured provider — no token is ever typed
11
- // into or shown in the browser. GitHub/GitLab are brand names (kept verbatim across locales),
12
- // as are the token-settings URLs, so they're inline constants rather than catalog keys — same
13
- // convention as the provider descriptors in ApiKeysSection. The "create a token" link prefers
14
- // the server's scopes-preselected deep link (`patLogin.setupUrls`); these are the fallback.
15
- type PatProvider = 'github' | 'gitlab'
13
+ // into or shown in the browser. The brand labels / icons / token-settings URLs are the shared
14
+ // provider descriptors in `~/utils/vcs` (brand names stay verbatim across locales, so they are
15
+ // constants rather than catalog keys — the same convention as ApiKeysSection). The "create a
16
+ // token" link prefers the server's scopes-preselected deep link (`patLogin.setupUrls`); the
17
+ // descriptor's URL is the fallback.
18
+ type PatProvider = VcsProvider
16
19
  const ALL_PROVIDERS: PatProvider[] = ['github', 'gitlab']
17
- const PROVIDER_LABELS: Record<PatProvider, string> = { github: 'GitHub', gitlab: 'GitLab' }
18
- const PROVIDER_ICONS: Record<PatProvider, string> = {
19
- github: 'i-lucide-github',
20
- gitlab: 'i-lucide-gitlab',
21
- }
22
- // Fallback token-creation pages, used only if the server didn't advertise a deep link.
23
- const PROVIDER_TOKEN_URLS: Record<PatProvider, string> = {
24
- github: 'https://github.com/settings/tokens/new',
25
- gitlab: 'https://gitlab.com/-/user_settings/personal_access_tokens',
26
- }
20
+ const PROVIDER_LABELS = VCS_PROVIDER_LABELS
21
+ const PROVIDER_ICONS = VCS_PROVIDER_ICONS
22
+ const PROVIDER_TOKEN_URLS = VCS_PROVIDER_TOKEN_URLS
27
23
 
28
24
  const patLoginCfg = computed(() => auth.localMode?.patLogin)
29
25
  // Only providers whose PAT is configured in env can sign in (the token is the operational
@@ -1,16 +1,29 @@
1
1
  <script setup lang="ts">
2
- // Hard onboarding gate shown after login when the GitHub integration is enabled
3
- // but the workspace has no App installation yet. cat-factory's whole flow runs on
4
- // the App (agents open PRs on the user's repos), so the board is withheld until
5
- // the App is installed/connected. Reuses <GitHubConnect>, which drives the
6
- // account-level install (https://github.com/apps/<slug>/installations/new — the
2
+ // Hard onboarding gate shown after login when the VCS integration is enabled but the workspace
3
+ // has no connection yet. cat-factory's whole flow runs on a connected repository host (agents
4
+ // open pull/merge requests on the user's repos), so the board is withheld until the workspace
5
+ // connects one. Renders the connect surfaces the deployment can actually serve: <GitHubConnect>
6
+ // drives the account-level App install (https://github.com/apps/<slug>/installations/new — the
7
7
  // user picks the account/org and grants all or a subset of repos) plus the
8
- // pick-an-existing-installation path. A "Sign out" escape hatch avoids trapping a
9
- // user who needs to switch GitHub accounts.
8
+ // pick-an-existing-installation path, and <GitLabConnect> takes a pasted GitLab PAT. A "Sign
9
+ // out" escape hatch avoids trapping a user who needs to switch accounts.
10
10
  import GitHubConnect from '~/components/github/GitHubConnect.vue'
11
+ import GitLabConnect from '~/components/vcs/GitLabConnect.vue'
12
+ import { VCS_PROVIDER_ICONS, VCS_PROVIDER_LABELS } from '~/utils/vcs'
11
13
 
12
14
  const { t } = useI18n()
13
15
  const auth = useAuthStore()
16
+ const github = useGitHubStore()
17
+
18
+ // A deployment that serves exactly one provider names it; one serving several stays neutral
19
+ // (the per-surface copy below then says which is which).
20
+ const sole = computed(() => github.soleConnectProvider)
21
+ const icon = computed(() => (sole.value ? VCS_PROVIDER_ICONS[sole.value] : 'i-lucide-git-branch'))
22
+ const title = computed(() =>
23
+ sole.value
24
+ ? t('vcs.onboarding.title', { provider: VCS_PROVIDER_LABELS[sole.value] })
25
+ : t('vcs.onboarding.titleAny'),
26
+ )
14
27
  </script>
15
28
 
16
29
  <template>
@@ -21,14 +34,29 @@ const auth = useAuthStore()
21
34
  class="my-8 w-full max-w-md rounded-xl border border-slate-800 bg-slate-900/80 p-8 backdrop-blur"
22
35
  >
23
36
  <div class="mb-5 text-center">
24
- <UIcon name="i-lucide-github" class="mx-auto mb-3 h-10 w-10 text-indigo-400" />
25
- <h1 class="mb-1 text-lg font-semibold text-white">{{ t('github.onboarding.title') }}</h1>
37
+ <UIcon :name="icon" class="mx-auto mb-3 h-10 w-10 text-indigo-400" />
38
+ <h1 class="mb-1 text-lg font-semibold text-white">{{ title }}</h1>
26
39
  <p class="text-sm text-slate-400">
27
- {{ t('github.onboarding.intro') }}
40
+ {{ t('vcs.onboarding.intro') }}
28
41
  </p>
29
42
  </div>
30
43
 
31
- <GitHubConnect />
44
+ <template v-if="github.canConnectGitHubApp">
45
+ <p class="mb-3 text-sm text-slate-400">{{ t('github.onboarding.appIntro') }}</p>
46
+ <GitHubConnect />
47
+ </template>
48
+ <USeparator
49
+ v-if="github.canConnectGitHubApp && github.canConnectGitLabPat"
50
+ class="my-4"
51
+ :label="t('vcs.connect.or')"
52
+ />
53
+ <GitLabConnect v-if="github.canConnectGitLabPat" />
54
+ <p
55
+ v-if="!github.canConnectGitHubApp && !github.canConnectGitLabPat"
56
+ class="rounded-md border border-dashed border-slate-800 px-3 py-3 text-sm text-slate-400"
57
+ >
58
+ {{ t('vcs.connect.noneConfigured') }}
59
+ </p>
32
60
 
33
61
  <p
34
62
  v-if="auth.required && auth.user"
@@ -4,13 +4,15 @@
4
4
  // pull requests and issues the backend caches in D1. Mirrors the document-source
5
5
  // connect/import surface, but for GitHub. Writes (new branch, open/merge PR,
6
6
  // comment) go straight to the repo via the backend's installation token.
7
- import type { GitHubPullRequest, GitHubRepo } from '~/types/domain'
7
+ import type { GitHubPullRequest, GitHubRepo, VcsProvider } from '~/types/domain'
8
8
  // Explicit import: the auto-import name for a component nested under a
9
9
  // like-named directory (github/GitHubConnect) doesn't match the `<GitHubConnect>`
10
10
  // tag, so it silently renders as an empty element. Importing it directly binds
11
11
  // the tag unambiguously.
12
12
  import GitHubConnect from './GitHubConnect.vue'
13
+ import GitLabConnect from '~/components/vcs/GitLabConnect.vue'
13
14
  import IntegrationBackTitle from '~/components/layout/IntegrationBackTitle.vue'
15
+ import { VCS_PROVIDER_ICONS, VCS_PROVIDER_LABELS } from '~/utils/vcs'
14
16
 
15
17
  const { t } = useI18n()
16
18
  const ui = useUiStore()
@@ -26,6 +28,32 @@ const open = computed({
26
28
  })
27
29
  const back = useIntegrationBack(open)
28
30
 
31
+ // Provider-aware chrome: once connected, the panel is titled for the provider the workspace
32
+ // actually connected; before that it names the sole connectable provider, or stays neutral when
33
+ // the deployment serves several. Brand names are verbatim in every locale (see `~/utils/vcs`).
34
+ const chromeProvider = computed(() =>
35
+ github.connected ? github.provider : github.soleConnectProvider,
36
+ )
37
+ const panelTitle = computed(() =>
38
+ chromeProvider.value ? VCS_PROVIDER_LABELS[chromeProvider.value] : t('vcs.panel.title'),
39
+ )
40
+ const providerIcon = computed(() =>
41
+ chromeProvider.value ? VCS_PROVIDER_ICONS[chromeProvider.value] : 'i-lucide-git-branch',
42
+ )
43
+
44
+ // What the connection line says under the account: a GitHub App connection is identified by its
45
+ // installation, a PAT connection by the credential it rides. Keyed by an exhaustive Record of
46
+ // literal `t()` keys, so a new provider fails the typecheck rather than rendering App vocabulary.
47
+ const CONNECTION_META: Record<VcsProvider, () => string> = {
48
+ github: () =>
49
+ t('github.panel.installationMeta', {
50
+ targetType: github.connection?.targetType ?? '',
51
+ id: github.connection?.installationId ?? '',
52
+ }),
53
+ gitlab: () => t('vcs.panel.patMeta'),
54
+ }
55
+ const connectionMeta = computed(() => CONNECTION_META[github.provider]())
56
+
29
57
  // On open: refresh projections when connected. The not-connected state renders
30
58
  // <GitHubConnect>, which discovers and links installations on its own.
31
59
  watch(
@@ -48,8 +76,10 @@ function notifyError(title: string, e: unknown) {
48
76
 
49
77
  async function disconnect() {
50
78
  const ok = await confirm({
51
- title: t('github.panel.confirmDisconnect.title'),
52
- description: t('github.panel.confirmDisconnect.body'),
79
+ title: t('vcs.panel.confirmDisconnect.title', {
80
+ provider: VCS_PROVIDER_LABELS[github.provider],
81
+ }),
82
+ description: t('vcs.panel.confirmDisconnect.body'),
53
83
  variant: 'destructive',
54
84
  confirmLabel: t('common.disconnect'),
55
85
  icon: 'i-lucide-unplug',
@@ -57,7 +87,10 @@ async function disconnect() {
57
87
  if (!ok) return
58
88
  try {
59
89
  await github.disconnect()
60
- toast.add({ title: t('github.panel.toast.disconnected'), icon: 'i-lucide-unplug' })
90
+ toast.add({
91
+ title: t('vcs.panel.toast.disconnected', { provider: VCS_PROVIDER_LABELS[github.provider] }),
92
+ icon: 'i-lucide-unplug',
93
+ })
61
94
  } catch (e) {
62
95
  notifyError(t('github.panel.errors.disconnect'), e)
63
96
  }
@@ -241,19 +274,32 @@ async function merge(pr: GitHubPullRequest) {
241
274
  </script>
242
275
 
243
276
  <template>
244
- <UModal v-model:open="open" title="GitHub" :ui="{ content: 'max-w-2xl' }">
277
+ <UModal v-model:open="open" :title="panelTitle" :ui="{ content: 'max-w-2xl' }">
245
278
  <template #title>
246
- <IntegrationBackTitle title="GitHub" @back="back" />
279
+ <IntegrationBackTitle :title="panelTitle" @back="back" />
247
280
  </template>
248
281
  <template #body>
249
282
  <div class="space-y-5">
250
283
  <!-- not connected: connect -->
251
284
  <template v-if="!github.connected">
252
- <p class="text-sm text-slate-400">
253
- {{ t('github.panel.connectIntro') }}
285
+ <!-- One connect surface per method the deployment actually serves: the App
286
+ installation picker only where a GitHub App is configured, the PAT box only
287
+ where the per-workspace GitLab connect is wired. -->
288
+ <template v-if="github.canConnectGitHubApp">
289
+ <p class="text-sm text-slate-400">{{ t('github.panel.connectIntro') }}</p>
290
+ <GitHubConnect />
291
+ </template>
292
+ <USeparator
293
+ v-if="github.canConnectGitHubApp && github.canConnectGitLabPat"
294
+ :label="t('vcs.connect.or')"
295
+ />
296
+ <GitLabConnect v-if="github.canConnectGitLabPat" />
297
+ <p
298
+ v-if="!github.canConnectGitHubApp && !github.canConnectGitLabPat"
299
+ class="rounded-md border border-dashed border-slate-800 px-3 py-3 text-sm text-slate-400"
300
+ >
301
+ {{ t('vcs.connect.noneConfigured') }}
254
302
  </p>
255
-
256
- <GitHubConnect />
257
303
  </template>
258
304
 
259
305
  <!-- connected: manage + browse -->
@@ -263,19 +309,12 @@ async function merge(pr: GitHubPullRequest) {
263
309
  class="flex items-center justify-between gap-2 rounded-md border border-slate-800 bg-slate-900/60 px-3 py-2"
264
310
  >
265
311
  <div class="flex items-center gap-2 min-w-0">
266
- <UIcon name="i-lucide-github" class="h-5 w-5 text-slate-300" />
312
+ <UIcon :name="providerIcon" class="h-5 w-5 text-slate-300" />
267
313
  <div class="min-w-0">
268
314
  <div class="truncate text-sm text-slate-200">
269
315
  {{ github.connection?.accountLogin }}
270
316
  </div>
271
- <div class="text-[11px] text-slate-500">
272
- {{
273
- t('github.panel.installationMeta', {
274
- targetType: github.connection?.targetType,
275
- id: github.connection?.installationId,
276
- })
277
- }}
278
- </div>
317
+ <div class="text-[11px] text-slate-500">{{ connectionMeta }}</div>
279
318
  </div>
280
319
  </div>
281
320
  <div class="flex items-center gap-1">
@@ -183,6 +183,11 @@ function setCommentOnPrOpen(value: WritebackOverride | null) {
183
183
  function setResolveOnMerge(value: WritebackOverride | null) {
184
184
  board.updateBlock(props.block.id, { trackerResolveOnMerge: value })
185
185
  }
186
+ // Only consulted for runs started through the public API — a task started here keeps its in-app
187
+ // clarification window regardless (docs/initiatives/headless-clarification-loop.md).
188
+ function setQuestionsOnPark(value: WritebackOverride | null) {
189
+ board.updateBlock(props.block.id, { trackerQuestionsOnPark: value })
190
+ }
186
191
  function writebackMenu(set: (value: WritebackOverride | null) => void) {
187
192
  return [
188
193
  [
@@ -212,6 +217,9 @@ const commentOnPrOpenLabel = computed(() =>
212
217
  const resolveOnMergeLabel = computed(() =>
213
218
  writebackLabel(props.block.trackerResolveOnMerge, tracker.settings.writebackResolveOnMerge),
214
219
  )
220
+ const questionsOnParkLabel = computed(() =>
221
+ writebackLabel(props.block.trackerQuestionsOnPark, tracker.settings.writebackQuestionsOnPark),
222
+ )
215
223
 
216
224
  // ---- technical label (tri-state) -------------------------------------------
217
225
  // Whether this is a purely technical task (the implementer then treats the task
@@ -520,6 +528,21 @@ const technicalLabel = computed(() => {
520
528
  </UButton>
521
529
  </UDropdownMenu>
522
530
  </div>
531
+ <div class="flex items-center justify-between">
532
+ <span class="text-[11px] text-slate-400">{{
533
+ t('inspector.runSettings.questionsOnPark')
534
+ }}</span>
535
+ <UDropdownMenu :items="writebackMenu(setQuestionsOnPark)">
536
+ <UButton
537
+ size="xs"
538
+ variant="ghost"
539
+ color="neutral"
540
+ trailing-icon="i-lucide-chevron-down"
541
+ >
542
+ {{ questionsOnParkLabel }}
543
+ </UButton>
544
+ </UDropdownMenu>
545
+ </div>
523
546
  </div>
524
547
  <div class="mt-1 text-[11px] text-slate-500">
525
548
  {{ t('inspector.runSettings.writebackHint') }}
@@ -29,6 +29,7 @@ const jiraProjectKey = ref('')
29
29
  const linearTeamId = ref('')
30
30
  const commentOnPrOpen = ref(false)
31
31
  const resolveOnMerge = ref(false)
32
+ const questionsOnPark = ref(false)
32
33
  const saving = ref(false)
33
34
 
34
35
  function hydrate() {
@@ -37,6 +38,7 @@ function hydrate() {
37
38
  linearTeamId.value = tracker.settings.linearTeamId ?? ''
38
39
  commentOnPrOpen.value = tracker.settings.writebackCommentOnPrOpen
39
40
  resolveOnMerge.value = tracker.settings.writebackResolveOnMerge
41
+ questionsOnPark.value = tracker.settings.writebackQuestionsOnPark
40
42
  }
41
43
  onMounted(() => {
42
44
  hydrate()
@@ -111,6 +113,7 @@ async function save() {
111
113
  linearTeamId: trackerKind.value === 'linear' ? linearTeamId.value.trim() : null,
112
114
  writebackCommentOnPrOpen: commentOnPrOpen.value,
113
115
  writebackResolveOnMerge: resolveOnMerge.value,
116
+ writebackQuestionsOnPark: questionsOnPark.value,
114
117
  })
115
118
  toast.add({
116
119
  title: t('settings.issueTracker.toast.saved'),
@@ -591,6 +594,18 @@ const STATUS_UI: Record<
591
594
  </span>
592
595
  </span>
593
596
  </label>
597
+
598
+ <label class="flex items-start gap-3 rounded-lg border border-slate-700 bg-slate-800/40 p-3">
599
+ <USwitch v-model="questionsOnPark" />
600
+ <span class="text-sm">
601
+ <span class="block text-slate-200">
602
+ {{ t('settings.issueTracker.writeback.questionsOnPark.label') }}
603
+ </span>
604
+ <span class="block text-xs text-slate-500">
605
+ {{ t('settings.issueTracker.writeback.questionsOnPark.help') }}
606
+ </span>
607
+ </span>
608
+ </label>
594
609
  </section>
595
610
 
596
611
  <div class="flex justify-end">
@@ -0,0 +1,85 @@
1
+ <script setup lang="ts">
2
+ // Per-workspace GitLab connect surface — the PAT analogue of <GitHubConnect>. GitLab has no
3
+ // App-installation concept, so there is nothing to discover and nothing to redirect to: the
4
+ // user pastes a personal access token, the backend validates it upstream, seals it, and writes
5
+ // the same projection rows the GitHub connect writes (stamped `provider: 'gitlab'`). Once
6
+ // connected, every repo surface downstream is the shared GitHub-shaped one.
7
+ //
8
+ // The token never persists in the browser: it lives in the field for the length of the request
9
+ // and is cleared on success. A rejected token comes back as a typed API error whose message
10
+ // says why (invalid, revoked, or missing the `api` scope), so it is shown inline rather than
11
+ // flattened into a generic toast.
12
+ import SecretInput from '~/components/common/SecretInput.vue'
13
+ import { apiErrorEnvelope } from '~/composables/api/errors'
14
+ import { VCS_PROVIDER_TOKEN_URLS } from '~/utils/vcs'
15
+
16
+ const { t } = useI18n()
17
+ const github = useGitHubStore()
18
+ const toast = useToast()
19
+
20
+ const pat = ref('')
21
+ const connecting = ref(false)
22
+ const error = ref<string | null>(null)
23
+
24
+ const tokenUrl = VCS_PROVIDER_TOKEN_URLS.gitlab
25
+
26
+ async function connect() {
27
+ const token = pat.value.trim()
28
+ if (!token || connecting.value) return
29
+ connecting.value = true
30
+ error.value = null
31
+ try {
32
+ await github.connectGitLab(token)
33
+ pat.value = ''
34
+ toast.add({
35
+ title: t('vcs.connect.gitlab.toast.connected'),
36
+ icon: 'i-lucide-check',
37
+ color: 'success',
38
+ })
39
+ } catch (e) {
40
+ error.value =
41
+ apiErrorEnvelope(e)?.message ??
42
+ (e instanceof Error ? e.message : t('vcs.connect.gitlab.errors.connect'))
43
+ } finally {
44
+ connecting.value = false
45
+ }
46
+ }
47
+ </script>
48
+
49
+ <template>
50
+ <section class="space-y-3">
51
+ <p class="text-sm text-slate-400">{{ t('vcs.connect.gitlab.intro') }}</p>
52
+
53
+ <UFormField :label="t('vcs.connect.gitlab.tokenLabel')" :hint="t('vcs.connect.gitlab.scope')">
54
+ <SecretInput
55
+ v-model="pat"
56
+ placeholder="glpat-…"
57
+ autocomplete="off"
58
+ class="w-full"
59
+ data-testid="gitlab-pat-input"
60
+ @keyup.enter="connect"
61
+ />
62
+ </UFormField>
63
+
64
+ <p class="text-[11px] text-slate-500">
65
+ <ULink :to="tokenUrl" target="_blank" class="text-indigo-400 hover:underline">
66
+ {{ t('vcs.connect.gitlab.createToken') }}
67
+ </ULink>
68
+ </p>
69
+
70
+ <p v-if="error" class="text-sm text-rose-400" data-testid="gitlab-connect-error">
71
+ {{ error }}
72
+ </p>
73
+
74
+ <UButton
75
+ color="primary"
76
+ icon="i-lucide-gitlab"
77
+ :loading="connecting"
78
+ :disabled="!pat.trim()"
79
+ data-testid="gitlab-connect-submit"
80
+ @click="connect"
81
+ >
82
+ {{ t('vcs.connect.gitlab.submit') }}
83
+ </UButton>
84
+ </section>
85
+ </template>
@@ -0,0 +1,33 @@
1
+ import {
2
+ connectGitLabContract,
3
+ disconnectGitLabContract,
4
+ getGitLabConnectionContract,
5
+ listVcsConnectOptionsContract,
6
+ } from '@cat-factory/contracts'
7
+ import type { ApiContext } from './context'
8
+
9
+ /**
10
+ * Provider-neutral VCS connect surface: which connect methods the deployment serves, plus the
11
+ * per-workspace GitLab PAT connect. The GitHub App connect lives in `githubApi` (it is
12
+ * App-specific); everything a workspace does with a repo AFTER connecting — browse, link, sync,
13
+ * pulls, issues — stays on the GitHub-shaped endpoints, which serve GitLab through the adapter.
14
+ */
15
+ export function vcsApi({ send, ws }: ApiContext) {
16
+ return {
17
+ // Capability probe: `[]` (or a 403/503) means this workspace has no connect surface at all.
18
+ listVcsConnectOptions: (workspaceId: string) =>
19
+ send(listVcsConnectOptionsContract, { pathPrefix: ws(workspaceId) }),
20
+
21
+ // The workspace's GitLab connection, or null. A 503 means GitLab connect isn't wired.
22
+ getGitLabConnection: (workspaceId: string) =>
23
+ send(getGitLabConnectionContract, { pathPrefix: ws(workspaceId) }),
24
+
25
+ // Connect by pasting a PAT; the backend validates it upstream before sealing it, so an
26
+ // invalid/insufficient token comes back as a 4xx with a human-readable message.
27
+ connectGitLab: (workspaceId: string, pat: string) =>
28
+ send(connectGitLabContract, { pathPrefix: ws(workspaceId), body: { pat } }),
29
+
30
+ disconnectGitLab: (workspaceId: string) =>
31
+ send(disconnectGitLabContract, { pathPrefix: ws(workspaceId) }),
32
+ }
33
+ }
@@ -14,6 +14,7 @@ import { prReviewApi } from './api/prReview'
14
14
  import { fragmentsApi } from './api/fragments'
15
15
  import { skillsApi } from './api/skills'
16
16
  import { githubApi } from './api/github'
17
+ import { vcsApi } from './api/vcs'
17
18
  import { humanReviewApi } from './api/humanReview'
18
19
  import { humanTestApi } from './api/humanTest'
19
20
  import { infraHandlersApi } from './api/infraHandlers'
@@ -144,6 +145,7 @@ export function useApi() {
144
145
  ...recurringApi(ctx),
145
146
  ...sandboxApi(ctx),
146
147
  ...githubApi(ctx),
148
+ ...vcsApi(ctx),
147
149
  ...slackApi(ctx),
148
150
  ...bootstrapApi(ctx),
149
151
  ...userSecretsApi(ctx),
@@ -1,4 +1,4 @@
1
- import type { ResyncRequest } from '~/types/domain'
1
+ import type { ResyncRequest, VcsProvider } from '~/types/domain'
2
2
  import type { GitHubStoreContext } from './context'
3
3
 
4
4
  /**
@@ -6,6 +6,11 @@ import type { GitHubStoreContext } from './context'
6
6
  * triggering a resync of the projections. Extracted from the store setup; each operation closes
7
7
  * over the shared {@link GitHubStoreContext} so behaviour is identical to the original
8
8
  * in-closure functions — the split is purely to keep every function within the size budget.
9
+ *
10
+ * Disconnecting is the one operation that spans providers (a workspace holds at most one
11
+ * connection, of either kind), so it dispatches on the connection's `provider` through an
12
+ * exhaustive map — a new provider fails the typecheck here instead of silently falling back to
13
+ * the GitHub route.
9
14
  */
10
15
  export function createGitHubConnectionActions(ctx: GitHubStoreContext) {
11
16
  const { api, workspace, available, connection, installations, loadingInstallations } = ctx
@@ -34,8 +39,14 @@ export function createGitHubConnectionActions(ctx: GitHubStoreContext) {
34
39
  await load()
35
40
  }
36
41
 
42
+ const DISCONNECT_BY_PROVIDER: Record<VcsProvider, (workspaceId: string) => Promise<unknown>> = {
43
+ github: (id) => api.disconnectGitHub(id),
44
+ gitlab: (id) => api.disconnectGitLab(id),
45
+ }
46
+
37
47
  async function disconnect() {
38
- await api.disconnectGitHub(workspace.requireId())
48
+ // Backends predating the discriminator omit `provider`; those connections are GitHub App ones.
49
+ await DISCONNECT_BY_PROVIDER[connection.value?.provider ?? 'github'](workspace.requireId())
39
50
  connection.value = null
40
51
  repos.value = []
41
52
  availableRepos.value = []
@@ -8,6 +8,7 @@ import type {
8
8
  GitHubPullRequest,
9
9
  GitHubRepo,
10
10
  RepoTreeEntry,
11
+ VcsConnectOption,
11
12
  } from '~/types/domain'
12
13
  import { useWorkspaceStore } from '~/stores/workspace'
13
14
 
@@ -26,6 +27,8 @@ export interface GitHubStoreContext {
26
27
  workspace: ReturnType<typeof useWorkspaceStore>
27
28
  available: Ref<boolean | null>
28
29
  connection: Ref<GitHubConnection | null>
30
+ /** The connect surfaces this deployment can serve (GitHub App / GitLab PAT / …). */
31
+ connectOptions: Ref<VcsConnectOption[]>
29
32
  installations: Ref<GitHubInstallationOption[]>
30
33
  loadingInstallations: Ref<boolean>
31
34
  repos: Ref<GitHubRepo[]>
@@ -0,0 +1,40 @@
1
+ import type { GitHubStoreContext } from './context'
2
+
3
+ /**
4
+ * The provider-neutral half of the connection lifecycle: which connect surfaces the deployment
5
+ * serves, and the per-workspace **PAT** connect (GitLab today). The GitHub-App installation
6
+ * lifecycle lives in {@link createGitHubConnectionActions}; everything AFTER connecting — repos,
7
+ * branches, pulls, issues — is the one GitHub-shaped surface both providers ride, so there is no
8
+ * GitLab store (see the VCS section of CLAUDE.md).
9
+ */
10
+ export function createVcsConnectActions(ctx: GitHubStoreContext) {
11
+ const { api, workspace, available, connection, connectOptions, load } = ctx
12
+
13
+ /**
14
+ * Load the deployment's connect capability. Best-effort: a 403 (a member without
15
+ * `integrations.manage`) or a 503 leaves the list empty, which renders as "no connect
16
+ * surface" rather than a broken picker.
17
+ */
18
+ async function loadConnectOptions(): Promise<void> {
19
+ try {
20
+ const { options } = await api.listVcsConnectOptions(workspace.requireId())
21
+ connectOptions.value = options
22
+ } catch {
23
+ connectOptions.value = []
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Connect the workspace by pasting a GitLab PAT. The backend validates the token upstream
29
+ * before sealing it, so a rejected token surfaces here as a thrown API error with the reason;
30
+ * on success the returned connection carries `provider: 'gitlab'` and the projection loads
31
+ * through the same reads the GitHub connection uses.
32
+ */
33
+ async function connectGitLab(pat: string): Promise<void> {
34
+ connection.value = await api.connectGitLab(workspace.requireId(), pat.trim())
35
+ available.value = true
36
+ await load()
37
+ }
38
+
39
+ return { loadConnectOptions, connectGitLab }
40
+ }