@cat-factory/app 0.202.0 → 0.205.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.
Files changed (48) hide show
  1. package/README.md +62 -10
  2. package/app/components/binaryOutput/BinaryOutputReport.vue +220 -0
  3. package/app/components/initiative/InitiativePlanReview.vue +11 -1
  4. package/app/components/panels/AgentStepDetail.vue +10 -0
  5. package/app/components/panels/ResultWindowShell.vue +86 -0
  6. package/app/components/pipeline/BinaryOutputStepPicker.vue +274 -0
  7. package/app/components/pipeline/PipelineBuilder.vue +54 -0
  8. package/app/components/settings/OpenRouterCatalogPanel.vue +6 -3
  9. package/app/components/tutorial/TutorialCatalogue.logic.spec.ts +103 -0
  10. package/app/components/tutorial/TutorialCatalogue.logic.ts +102 -0
  11. package/app/components/tutorial/TutorialCatalogue.vue +150 -0
  12. package/app/components/tutorial/TutorialOverlay.vue +9 -2
  13. package/app/components/tutorial/TutorialPrompt.vue +40 -33
  14. package/app/composables/useNavContributions.ts +4 -1
  15. package/app/composables/usePipelineErrorToast.ts +4 -0
  16. package/app/composables/useTutorialLaunch.ts +50 -0
  17. package/app/composables/useTutorialTours.ts +37 -9
  18. package/app/docs/consumer-extensions.md +24 -11
  19. package/app/modular/agent-kinds.ts +6 -0
  20. package/app/modular/nav-contributions.spec.ts +7 -0
  21. package/app/modular/nav-contributions.ts +25 -13
  22. package/app/modular/slots.ts +5 -2
  23. package/app/modular/tutorial-tours.spec.ts +92 -43
  24. package/app/modular/tutorial-tours.ts +57 -8
  25. package/app/pages/index.vue +7 -2
  26. package/app/stores/agents.ts +20 -0
  27. package/app/stores/pipelines/draftBinaryOutput.spec.ts +70 -0
  28. package/app/stores/pipelines/draftStepConfig.ts +44 -2
  29. package/app/stores/tutorial.spec.ts +75 -0
  30. package/app/stores/tutorial.ts +66 -1
  31. package/app/stores/workspace/hydrate.ts +3 -0
  32. package/app/types/domain.ts +9 -0
  33. package/app/types/execution.ts +5 -0
  34. package/app/utils/binaryOutput.spec.ts +421 -0
  35. package/app/utils/binaryOutput.ts +444 -0
  36. package/app/utils/tutorial.spec.ts +120 -8
  37. package/app/utils/tutorial.ts +166 -21
  38. package/i18n/locales/de.json +105 -8
  39. package/i18n/locales/en.json +111 -8
  40. package/i18n/locales/es.json +105 -8
  41. package/i18n/locales/fr.json +105 -8
  42. package/i18n/locales/he.json +105 -8
  43. package/i18n/locales/it.json +105 -8
  44. package/i18n/locales/ja.json +105 -8
  45. package/i18n/locales/pl.json +105 -8
  46. package/i18n/locales/tr.json +105 -8
  47. package/i18n/locales/uk.json +105 -8
  48. package/package.json +2 -2
@@ -0,0 +1,274 @@
1
+ <script setup lang="ts">
2
+ // The per-step storage + context selection for a BINARY-OUTPUT kind — a generator whose
3
+ // deliverable is binary artifacts stored through a foundational service the org already runs
4
+ // (docs/initiatives/binary-output-foundational-storage.md).
5
+ //
6
+ // Shown on a step whose kind carries the `binary-output` trait, projected onto the workspace
7
+ // snapshot as `CustomAgentKind.binaryOutput`. Unlike the variant picker beside it this is NOT
8
+ // an override of a default: the selection is REQUIRED — an enabled generator step without one
9
+ // is refused at pipeline save AND at run start — so it stays in BOTH interface tiers. Hiding a
10
+ // required input in basic mode leaves a step that cannot be saved and no way to find out why.
11
+ //
12
+ // The storage half offers only services from the RESOLVED catalog that declare the
13
+ // `asset-storage` capability, because that is exactly what run admission re-validates against
14
+ // at every start/retry/restart. Offering an id from a stale client copy would let a step save
15
+ // clean and fail one refusal cycle later.
16
+ //
17
+ // The GENERATIVE half answers the other question — what MAKES the artifacts — and its candidates
18
+ // come from a different place: the integrations are registered in the deployment's CODE, so they
19
+ // ride the workspace snapshot (`binaryGenerators`) rather than a catalog read. Both halves are
20
+ // offered here because a step needs both to work, and only this surface can tell a human that the
21
+ // content types it promises to deliver are not covered by anything it selected.
22
+ import { computed } from 'vue'
23
+ import {
24
+ ASSET_STORAGE_CAPABILITY,
25
+ GENERATION_CONTEXT_CAPABILITY,
26
+ type BinaryModality,
27
+ type BinaryOutputConfig,
28
+ } from '@cat-factory/contracts'
29
+ import { binaryOutputPickIssues, type BinaryOutputPickIssue } from '~/utils/binaryOutput'
30
+
31
+ const props = defineProps<{ index: number }>()
32
+
33
+ const pipelines = usePipelinesStore()
34
+ const catalog = useFoundationalServicesStore()
35
+ const agents = useAgentsStore()
36
+ const { t } = useI18n()
37
+
38
+ /**
39
+ * The content-type vocabulary, as STATIC literal `t()` keys — one per member, never a key
40
+ * assembled at runtime, so the typed-message-key check covers them (the standing i18n rule for
41
+ * an enum-keyed set).
42
+ */
43
+ const MODALITY_LABELS: Record<BinaryModality, () => string> = {
44
+ image: () => t('pipeline.builder.binaryOutputModality.image'),
45
+ audio: () => t('pipeline.builder.binaryOutputModality.audio'),
46
+ video: () => t('pipeline.builder.binaryOutputModality.video'),
47
+ '3d': () => t('pipeline.builder.binaryOutputModality.3d'),
48
+ document: () => t('pipeline.builder.binaryOutputModality.document'),
49
+ }
50
+ const MODALITY_ORDER: BinaryModality[] = ['image', 'audio', 'video', '3d', 'document']
51
+ function modalityLabel(modality: BinaryModality): string {
52
+ return MODALITY_LABELS[modality]()
53
+ }
54
+
55
+ const config = computed(() => pipelines.draftBinaryOutput(props.index))
56
+
57
+ /** Storage candidates: the capability tag is a REQUIREMENT here, enforced by admission. */
58
+ const storageItems = computed(() =>
59
+ catalog.resolved
60
+ .filter((service) => service.capabilities.includes(ASSET_STORAGE_CAPABILITY))
61
+ .map((service) => ({ label: service.name, value: service.id })),
62
+ )
63
+
64
+ /**
65
+ * Context candidates: the WHOLE resolved catalog, with `generation-context`-tagged services
66
+ * ordered first. The tag is conventional and never a filter — any service with a readable
67
+ * contract can inform scope, and admission enforces existence only — so filtering on it here
68
+ * would hide a valid choice the backend would happily accept.
69
+ */
70
+ const contextItems = computed(() =>
71
+ [...catalog.resolved]
72
+ .sort((a, b) => {
73
+ const rank = (tags: readonly string[]) =>
74
+ tags.includes(GENERATION_CONTEXT_CAPABILITY) ? 0 : 1
75
+ return rank(a.capabilities) - rank(b.capabilities) || a.name.localeCompare(b.name)
76
+ })
77
+ .map((service) => ({ label: service.name, value: service.id })),
78
+ )
79
+
80
+ /**
81
+ * Generative candidates: every integration the deployment registered, labelled with what it
82
+ * produces so the choice is legible without cross-referencing. No filter — unlike the storage
83
+ * half there is no capability to require, and any registered integration is one admission accepts.
84
+ */
85
+ const generatorItems = computed(() =>
86
+ agents.binaryGenerators.map((generator) => ({
87
+ label: `${generator.name} — ${generator.modalities.map(modalityLabel).join(', ')}`,
88
+ value: generator.id,
89
+ })),
90
+ )
91
+
92
+ const modalityItems = computed(() =>
93
+ MODALITY_ORDER.map((modality) => ({ label: modalityLabel(modality), value: modality })),
94
+ )
95
+
96
+ const pick = computed(() =>
97
+ binaryOutputPickIssues(
98
+ config.value,
99
+ catalog.resolved,
100
+ catalog.available,
101
+ agents.binaryGenerators,
102
+ ),
103
+ )
104
+ function has(issue: BinaryOutputPickIssue): boolean {
105
+ return pick.value.issues.includes(issue)
106
+ }
107
+
108
+ /**
109
+ * Clearing the storage target drops the WHOLE selection — context and generative halves included:
110
+ * every other id only means anything as part of a generation that has somewhere to land, and a
111
+ * step carrying them alone would persist a shape the backend has no rule for. Setting a target
112
+ * carries the rest through, so re-pointing storage is not a silent reset of the other two.
113
+ */
114
+ function setStorage(storageServiceId: string | undefined) {
115
+ const current = config.value
116
+ pipelines.setDraftBinaryOutput(
117
+ props.index,
118
+ storageServiceId ? { ...current, storageServiceId } : undefined,
119
+ )
120
+ }
121
+
122
+ /**
123
+ * Patch one half of the selection, carrying the others through. Every setter but `setStorage`
124
+ * goes via here so a change to one half can never silently drop another — the store rebuilds the
125
+ * whole `binaryOutput` bag from what it is handed, so an omitted field is a deletion.
126
+ */
127
+ function patch(fields: Partial<BinaryOutputConfig>) {
128
+ const current = config.value
129
+ const storageServiceId = current?.storageServiceId
130
+ if (!storageServiceId) return
131
+ pipelines.setDraftBinaryOutput(props.index, { ...current, storageServiceId, ...fields })
132
+ }
133
+
134
+ function setContext(ids: string[]) {
135
+ patch({ contextServiceIds: ids })
136
+ }
137
+
138
+ function setGenerators(ids: string[]) {
139
+ patch({ generatorIds: ids })
140
+ }
141
+
142
+ function setModalities(modalities: BinaryModality[]) {
143
+ patch({ modalities })
144
+ }
145
+ </script>
146
+
147
+ <template>
148
+ <div class="ms-6 flex flex-col gap-1.5" data-testid="binary-output-picker">
149
+ <div class="flex items-center gap-2">
150
+ <span class="text-[10px] text-slate-500">{{
151
+ t('pipeline.builder.binaryOutputStorage')
152
+ }}</span>
153
+ <USelect
154
+ class="w-56"
155
+ :model-value="config?.storageServiceId ?? ''"
156
+ :items="storageItems"
157
+ value-key="value"
158
+ size="xs"
159
+ :placeholder="t('pipeline.builder.binaryOutputPlaceholder')"
160
+ :disabled="!storageItems.length"
161
+ data-testid="binary-output-storage-select"
162
+ @update:model-value="setStorage($event)"
163
+ />
164
+ </div>
165
+
166
+ <div v-if="config?.storageServiceId" class="flex items-center gap-2">
167
+ <span class="text-[10px] text-slate-500">{{
168
+ t('pipeline.builder.binaryOutputContext')
169
+ }}</span>
170
+ <USelectMenu
171
+ class="w-56"
172
+ multiple
173
+ :model-value="config.contextServiceIds ?? []"
174
+ :items="contextItems"
175
+ value-key="value"
176
+ size="xs"
177
+ :placeholder="t('pipeline.builder.binaryOutputContextPlaceholder')"
178
+ data-testid="binary-output-context-select"
179
+ @update:model-value="setContext($event)"
180
+ />
181
+ </div>
182
+
183
+ <div v-if="config?.storageServiceId" class="flex items-center gap-2">
184
+ <span class="text-[10px] text-slate-500">{{
185
+ t('pipeline.builder.binaryOutputGenerators')
186
+ }}</span>
187
+ <USelectMenu
188
+ class="w-56"
189
+ multiple
190
+ :model-value="config.generatorIds ?? []"
191
+ :items="generatorItems"
192
+ value-key="value"
193
+ size="xs"
194
+ :placeholder="t('pipeline.builder.binaryOutputGeneratorsPlaceholder')"
195
+ :disabled="!generatorItems.length"
196
+ data-testid="binary-output-generator-select"
197
+ @update:model-value="setGenerators($event)"
198
+ />
199
+ </div>
200
+
201
+ <div v-if="config?.storageServiceId" class="flex items-center gap-2">
202
+ <span class="text-[10px] text-slate-500">{{
203
+ t('pipeline.builder.binaryOutputModalities')
204
+ }}</span>
205
+ <USelectMenu
206
+ class="w-56"
207
+ multiple
208
+ :model-value="config.modalities ?? []"
209
+ :items="modalityItems"
210
+ value-key="value"
211
+ size="xs"
212
+ :placeholder="t('pipeline.builder.binaryOutputModalitiesPlaceholder')"
213
+ data-testid="binary-output-modality-select"
214
+ @update:model-value="setModalities($event)"
215
+ />
216
+ </div>
217
+
218
+ <!-- Every refusal this step would hit, named where it is fixable. Each is its own line
219
+ with its own remedy: an unreachable catalog is not an empty one, a lost service is not
220
+ an untagged one, and a lost CONTEXT service is not a lost storage target. -->
221
+ <p
222
+ v-if="has('catalog_unavailable')"
223
+ class="text-[10px] text-amber-400"
224
+ data-testid="binary-output-unavailable"
225
+ >
226
+ {{ t('pipeline.builder.binaryOutputUnavailable') }}
227
+ </p>
228
+ <p
229
+ v-else-if="has('no_storage_service')"
230
+ class="text-[10px] text-amber-400"
231
+ data-testid="binary-output-no-storage"
232
+ >
233
+ {{ t('pipeline.builder.binaryOutputNoStorage', { capability: ASSET_STORAGE_CAPABILITY }) }}
234
+ </p>
235
+ <p v-if="has('unknown_service')" class="text-[10px] text-amber-400">
236
+ {{ t('pipeline.builder.binaryOutputMissing') }}
237
+ </p>
238
+ <p v-if="has('not_storage_capable')" class="text-[10px] text-amber-400">
239
+ {{ t('pipeline.builder.binaryOutputNotStorage', { capability: ASSET_STORAGE_CAPABILITY }) }}
240
+ </p>
241
+ <p v-if="has('unknown_context_service')" class="text-[10px] text-amber-400">
242
+ {{
243
+ t('pipeline.builder.binaryOutputContextMissing', {
244
+ ids: pick.unknownContextIds.join(', '),
245
+ })
246
+ }}
247
+ </p>
248
+ <!-- The generative refusals stay their own lines, and their remedies point somewhere else
249
+ entirely: an unregistered integration is fixed in the DEPLOYMENT'S BUILD, not in this
250
+ workspace, which is the whole reason the backend keeps the two reason codes apart. -->
251
+ <p
252
+ v-if="has('unknown_generator')"
253
+ class="text-[10px] text-amber-400"
254
+ data-testid="binary-output-unknown-generator"
255
+ >
256
+ {{
257
+ t('pipeline.builder.binaryOutputGeneratorMissing', {
258
+ ids: pick.unknownGeneratorIds.join(', '),
259
+ })
260
+ }}
261
+ </p>
262
+ <p
263
+ v-if="has('modality_uncovered')"
264
+ class="text-[10px] text-amber-400"
265
+ data-testid="binary-output-modality-uncovered"
266
+ >
267
+ {{
268
+ t('pipeline.builder.binaryOutputModalityUncovered', {
269
+ modalities: pick.uncoveredModalities.map(modalityLabel).join(', '),
270
+ })
271
+ }}
272
+ </p>
273
+ </div>
274
+ </template>
@@ -7,6 +7,7 @@ import AgentKindIcon from '~/components/pipeline/AgentKindIcon.vue'
7
7
  import AgentPromptEditor from '~/components/pipeline/AgentPromptEditor.vue'
8
8
  import EstimateThresholdFields from '~/components/pipeline/EstimateThresholdFields.vue'
9
9
  import OutputBudgetInput from '~/components/pipeline/OutputBudgetInput.vue'
10
+ import BinaryOutputStepPicker from '~/components/pipeline/BinaryOutputStepPicker.vue'
10
11
  import { ESTIMATE_AXES, ESTIMATE_AXIS_FIELD, type EstimateAxis } from '~/utils/estimateGating'
11
12
  import { showOverrideField } from '~/utils/uiMode'
12
13
  import {
@@ -202,6 +203,36 @@ const stepsDisallowedByPurpose = computed(() =>
202
203
  }),
203
204
  )
204
205
 
206
+ // The workspace's foundational-services catalog, for the binary-output storage/context picker.
207
+ const foundational = useFoundationalServicesStore()
208
+
209
+ /**
210
+ * Whether this step's kind is a BINARY-OUTPUT generator, and therefore needs the storage +
211
+ * context picker. Read off the kind's projected `binaryOutput` flag rather than a kind-id list,
212
+ * so a deployment's generator opts in by carrying the trait exactly as the engine's own checks
213
+ * key on it.
214
+ *
215
+ * Deliberately NOT behind `showOverrideField` / `isAdvanced` the way the variant picker is: a
216
+ * variant OVERRIDES what the kind ships, while this selection is REQUIRED. A basic-mode user
217
+ * who cannot see it has a step that cannot be saved and no way to find out why.
218
+ */
219
+ function showBinaryOutputPicker(kind: AgentKind): boolean {
220
+ return agentKindMeta(kind).binaryOutput === true
221
+ }
222
+
223
+ // An enabled generator step with no storage selection — mirrors the backend save/start
224
+ // rejection (`assertValidBinaryOutputSteps`), surfaced as an inline hint so the user fixes it
225
+ // before the round trip. Same disposition as `skillStepNeedsPick`, for the same reason: both
226
+ // are a step parametrized by a selection it cannot run without.
227
+ const binaryOutputStepNeedsPick = computed(() =>
228
+ pipelines.draft.some(
229
+ (kind, i) =>
230
+ showBinaryOutputPicker(kind) &&
231
+ pipelines.draftEnabled[i] !== false &&
232
+ !pipelines.draftBinaryOutput(i)?.storageServiceId,
233
+ ),
234
+ )
235
+
205
236
  // A step's picked skill id is no longer in the account catalog (the source dir was renamed or
206
237
  // unlinked). The step will fail cleanly at dispatch; flag it so the user re-picks.
207
238
  function skillMissing(index: number): boolean {
@@ -226,6 +257,11 @@ watch(open, (isOpen) => {
226
257
  // The workspace's per-kind output ceilings, which the per-step field shows as its inherited
227
258
  // placeholder and the prompt editor edits. Best-effort on the same terms as the prompt index.
228
259
  if (isOpen) agentSettings.load().catch(() => {})
260
+ // The resolved foundational-services catalog, which the binary-output picker offers from.
261
+ // Single-flighted per workspace, so this shares the panel's load rather than adding one. A
262
+ // failure is not swallowed into an empty picker: the store records `available: false`, and
263
+ // the picker says the catalog is unreachable rather than "no services exist".
264
+ if (isOpen) void foundational.ensureProbed()
229
265
  })
230
266
 
231
267
  function add(kind: AgentKind) {
@@ -531,6 +567,15 @@ async function clone(p: Pipeline) {
531
567
  {{ t('pipeline.builder.skillNeedsPick') }}
532
568
  </p>
533
569
 
570
+ <p
571
+ v-if="binaryOutputStepNeedsPick"
572
+ class="mb-2 flex items-center gap-1.5 rounded-md border border-amber-800/50 bg-amber-950/30 px-2 py-1 text-[11px] text-amber-300"
573
+ data-testid="binary-output-needs-pick"
574
+ >
575
+ <UIcon name="i-lucide-alert-triangle" class="h-3.5 w-3.5 shrink-0" />
576
+ {{ t('pipeline.builder.binaryOutputNeedsPick') }}
577
+ </p>
578
+
534
579
  <p
535
580
  v-if="stepsDisallowedByPurpose.length"
536
581
  class="mb-2 flex items-center gap-1.5 rounded-md border border-amber-800/50 bg-amber-950/30 px-2 py-1 text-[11px] text-amber-300"
@@ -792,6 +837,15 @@ async function clone(p: Pipeline) {
792
837
  />
793
838
  </div>
794
839
 
840
+ <!-- Binary-output picker: a generator kind's step is parametrized by the
841
+ foundational STORAGE service its artifacts go through (`stepOptions.binaryOutput`)
842
+ plus any services consulted for the generation's scope. Required, not an
843
+ override — so it shows in both interface tiers. -->
844
+ <BinaryOutputStepPicker
845
+ v-if="showBinaryOutputPicker(unit.kind)"
846
+ :index="unit.index"
847
+ />
848
+
795
849
  <!-- This step's own output-token ceiling. An OVERRIDE of the workspace's per-kind
796
850
  setting (itself an override of the deployment routing default), so it is
797
851
  advanced-only until a value is pinned; empty inherits. -->
@@ -32,10 +32,13 @@ const back = useIntegrationBack(open)
32
32
  const RECOMMENDED_SLUGS = [
33
33
  'anthropic/claude-fable-5',
34
34
  'anthropic/claude-opus-5',
35
- 'openai/gpt-5.5',
36
- 'google/gemini-3-pro',
37
- 'deepseek/deepseek-chat',
35
+ 'openai/gpt-5.6-sol',
36
+ 'openai/gpt-5.6-terra',
37
+ 'google/gemini-3.1-pro-preview',
38
+ 'google/gemini-3.6-flash',
39
+ 'deepseek/deepseek-v4-flash',
38
40
  'moonshotai/kimi-k2.7-code',
41
+ 'z-ai/glm-5.2',
39
42
  ]
40
43
 
41
44
  // Whether the workspace/user has an OpenRouter key connected at any reachable scope.
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { buildCatalogueRows, summarizeProgress } from './TutorialCatalogue.logic'
3
+ import type { TutorialCatalogueEntry, TutorialTourState } from '~/utils/tutorial'
4
+
5
+ const entry = (
6
+ id: string,
7
+ availability: TutorialCatalogueEntry['availability'],
8
+ stepCount = 3,
9
+ ): TutorialCatalogueEntry => ({
10
+ tour: {
11
+ id,
12
+ order: 10,
13
+ titleKey: `tutorial.tours.${id}.title`,
14
+ descriptionKey: `tutorial.tours.${id}.description`,
15
+ steps: Array.from({ length: stepCount }, (_, i) => ({
16
+ id: `s${i}`,
17
+ titleKey: 't',
18
+ bodyKey: 'b',
19
+ })),
20
+ },
21
+ availability,
22
+ unmet:
23
+ availability === 'blocked'
24
+ ? [{ id: 'service', labelKey: 'tutorial.requirements.service', met: () => false }]
25
+ : [],
26
+ })
27
+
28
+ const states = (map: Record<string, TutorialTourState>) => (id: string) => map[id] ?? 'notStarted'
29
+
30
+ describe('buildCatalogueRows', () => {
31
+ it('carries every tour through, ready or not', () => {
32
+ const rows = buildCatalogueRows(
33
+ [entry('a', 'ready'), entry('b', 'blocked'), entry('c', 'not-applicable')],
34
+ states({}),
35
+ )
36
+ expect(rows.map((r) => r.tour.id)).toEqual(['a', 'b', 'c'])
37
+ expect(rows.map((r) => r.startable)).toEqual([true, false, false])
38
+ })
39
+
40
+ it('counts the steps of a runnable tour and withholds a count for the rest', () => {
41
+ // A blocked tour's resolved script is not what the user gets once they unblock it, and a
42
+ // number that quietly changes under them is worse than no number.
43
+ const rows = buildCatalogueRows([entry('a', 'ready', 4), entry('b', 'blocked', 4)], states({}))
44
+ expect(rows[0]?.stepCount).toBe(4)
45
+ expect(rows[1]?.stepCount).toBeNull()
46
+ })
47
+
48
+ it('labels each row from the user`s own progress', () => {
49
+ const rows = buildCatalogueRows(
50
+ [entry('a', 'ready'), entry('b', 'ready'), entry('c', 'ready')],
51
+ states({ a: 'completed', b: 'paused', c: 'inProgress' }),
52
+ )
53
+ expect(rows.map((r) => r.action)).toEqual(['restart', 'resume', 'continue'])
54
+ })
55
+
56
+ it('keeps a blocked tour`s unmet requirements for the reason list', () => {
57
+ const [row] = buildCatalogueRows([entry('a', 'blocked')], states({}))
58
+ expect(row?.unmet.map((r) => r.id)).toEqual(['service'])
59
+ })
60
+ })
61
+
62
+ describe('summarizeProgress', () => {
63
+ /** The launch offer is still unanswered, so only the rows can make anything resettable. */
64
+ const unanswered = { launchOfferAnswered: false }
65
+ const rows = (map: Record<string, TutorialTourState>, ids: string[]) =>
66
+ buildCatalogueRows(
67
+ ids.map((id) => entry(id, 'ready')),
68
+ states(map),
69
+ )
70
+
71
+ it('counts completions against the WHOLE catalog, not the runnable part', () => {
72
+ // Counting only what this board can offer today would move the denominator every time a
73
+ // repo was linked or a run finished — and "2 of 2" on a board with four walkthroughs
74
+ // still waiting reads as a finished tutorial, which is what this surface disproves.
75
+ const all = buildCatalogueRows(
76
+ [entry('a', 'ready'), entry('b', 'blocked'), entry('c', 'not-applicable')],
77
+ states({ a: 'completed' }),
78
+ )
79
+ expect(summarizeProgress(all, unanswered)).toMatchObject({ completed: 1, total: 3 })
80
+ })
81
+
82
+ it('offers a reset for a paused tour, not only for completed ones', () => {
83
+ expect(summarizeProgress(rows({}, ['a', 'b']), unanswered).resettable).toBe(false)
84
+ expect(summarizeProgress(rows({ a: 'paused' }, ['a', 'b']), unanswered).resettable).toBe(true)
85
+ expect(summarizeProgress(rows({ a: 'completed' }, ['a', 'b']), unanswered).resettable).toBe(
86
+ true,
87
+ )
88
+ })
89
+
90
+ it('offers a reset to a user who only ever answered the launch offer', () => {
91
+ // The case keying Reset off the rows alone got wrong, and the one that matters most: someone
92
+ // who clicked "No thanks" and took no tour has nothing completed and nothing paused, yet the
93
+ // saved answer is exactly what stops the prompt returning. Hiding the control left them no
94
+ // route back to the first-launch experience Reset promises.
95
+ expect(summarizeProgress(rows({}, ['a', 'b']), { launchOfferAnswered: true }).resettable).toBe(
96
+ true,
97
+ )
98
+ })
99
+
100
+ it('offers no reset on a genuinely untouched install', () => {
101
+ expect(summarizeProgress([], unanswered).resettable).toBe(false)
102
+ })
103
+ })
@@ -0,0 +1,102 @@
1
+ import { launchActionFor } from '~/utils/tutorial'
2
+ import type {
3
+ TutorialAvailability,
4
+ TutorialCatalogueEntry,
5
+ TutorialLaunchAction,
6
+ TutorialRequirement,
7
+ TutorialTour,
8
+ TutorialTourState,
9
+ } from '~/utils/tutorial'
10
+
11
+ /**
12
+ * What the catalogue renders per tour, and the progress line above the list.
13
+ *
14
+ * Extracted from `TutorialCatalogue.vue` for the same reason the overlay's decisions are
15
+ * (`TutorialOverlay.logic.ts`): the vitest setup has no SFC transform, so anything that
16
+ * DECIDES has to live outside the component to be tested. Here that is the whole of what the
17
+ * surface claims — which tours can be started, which are held back and by what, and how much
18
+ * of the catalog this user has been through.
19
+ */
20
+
21
+ /** One rendered row: an entry, plus everything derived from it and the user's progress. */
22
+ export interface TutorialCatalogueRow {
23
+ tour: TutorialTour
24
+ availability: TutorialAvailability
25
+ /** What is standing in the way, when {@link availability} is `blocked`. */
26
+ unmet: readonly TutorialRequirement[]
27
+ state: TutorialTourState
28
+ action: TutorialLaunchAction
29
+ /**
30
+ * How many steps a start would walk this board through — the RESOLVED count, not the
31
+ * declared one, since branch steps that don't apply here are already gone.
32
+ *
33
+ * Null for a tour that cannot run: its resolved script is not what the user would get once
34
+ * the missing requirement is met, and a number that quietly changes when they unblock it is
35
+ * worse than no number.
36
+ */
37
+ stepCount: number | null
38
+ /** Whether the row's button does anything (a blocked tour's is inert, not hidden). */
39
+ startable: boolean
40
+ }
41
+
42
+ /** The list, in catalog order — the entries arrive sorted by `resolveTourCatalogue`. */
43
+ export function buildCatalogueRows(
44
+ entries: readonly TutorialCatalogueEntry[],
45
+ stateOf: (tourId: string) => TutorialTourState,
46
+ ): TutorialCatalogueRow[] {
47
+ return entries.map((entry) => {
48
+ const ready = entry.availability === 'ready'
49
+ const state = stateOf(entry.tour.id)
50
+ return {
51
+ tour: entry.tour,
52
+ availability: entry.availability,
53
+ unmet: entry.unmet,
54
+ state,
55
+ action: launchActionFor(state),
56
+ stepCount: ready ? entry.tour.steps.length : null,
57
+ startable: ready,
58
+ }
59
+ })
60
+ }
61
+
62
+ /** The headline count. */
63
+ export interface TutorialProgressSummary {
64
+ completed: number
65
+ /** Every tour this deployment ships, available or not — the honest denominator. */
66
+ total: number
67
+ /**
68
+ * Whether there is anything for Reset to clear — which is everything `resetProgress` writes,
69
+ * not only what this list shows. See {@link summarizeProgress}.
70
+ */
71
+ resettable: boolean
72
+ }
73
+
74
+ /**
75
+ * Progress across the WHOLE catalog, not just the runnable part.
76
+ *
77
+ * Counting only what this board can offer today would move the denominator under the user
78
+ * every time they linked a repo or finished a run — "2 of 2 completed" on a board with four
79
+ * more walkthroughs waiting behind requirements reads as a finished tutorial, which is the
80
+ * one thing this surface exists to disprove.
81
+ *
82
+ * `launchOfferAnswered` is the store's `decision`, and it is here rather than derived from the
83
+ * rows because `resetProgress` clears it too — Reset restores the FIRST-LAUNCH experience, and
84
+ * the saved answer to "would you like a tour?" is most of that. Keying the control on the rows
85
+ * alone hid it from the one user who most needs it: someone who clicked "No thanks" and took no
86
+ * tour has nothing completed and nothing paused, so the only route back to the offer was the
87
+ * control that was not being drawn.
88
+ */
89
+ export function summarizeProgress(
90
+ rows: readonly TutorialCatalogueRow[],
91
+ input: { launchOfferAnswered: boolean },
92
+ ): TutorialProgressSummary {
93
+ const completed = rows.filter((row) => row.state === 'completed').length
94
+ return {
95
+ completed,
96
+ total: rows.length,
97
+ // A paused tour is progress too: clearing it is exactly what someone handing this to a
98
+ // colleague wants, and offering Reset only for completions would leave it behind.
99
+ resettable:
100
+ completed > 0 || rows.some((row) => row.state === 'paused') || input.launchOfferAnswered,
101
+ }
102
+ }