diff --git a/apps/desktop/Sources/StimDesktop/Views/TutorialCompletionCard.swift b/apps/desktop/Sources/StimDesktop/Views/TutorialCompletionCard.swift new file mode 100644 index 0000000000..6668abb472 --- /dev/null +++ b/apps/desktop/Sources/StimDesktop/Views/TutorialCompletionCard.swift @@ -0,0 +1,120 @@ +import StimKit +import SwiftUI + +struct TutorialCompletionCard: View { + var snapshot: TutorialSnapshot + var steps: [TutorialStep] + var archiveOff: Bool + var openArchived: () -> Void + + private var record: TutorialRecord { snapshot.record } + private var stats: TutorialStats { record.stats ?? TutorialStats() } + + var body: some View { + VStack(alignment: .leading, spacing: Space.lg) { + VStack(alignment: .leading, spacing: Space.xxs) { + Label("Tutorial Complete", systemImage: "checkmark.circle.fill") + .font(.stim(.headline)).foregroundStyle(Palette.success) + if let total { + Text("\(Format.duration(total)) from clone to archive") + .font(.stim(.footnote)).foregroundStyle(Palette.secondary) + } + } + if !tiles.isEmpty { + LazyVGrid(columns: [GridItem(.flexible(), spacing: Space.md), GridItem(.flexible())], spacing: Space.md) { + ForEach(tiles, id: \.caption) { tile in + VStack(alignment: .leading, spacing: Space.xxs) { + Text(tile.value).font(.stim(.headline)).monospacedDigit() + Text(tile.caption).font(.stim(.caption)).foregroundStyle(Palette.secondary) + .fixedSize(horizontal: false, vertical: true) + } + .frame(maxWidth: .infinity, alignment: .leading) + .padding(Space.md) + .background(RoundedRectangle(cornerRadius: Radius.card).fill(Palette.surface)) + .overlay(RoundedRectangle(cornerRadius: Radius.card).strokeBorder(Palette.border)) + .accessibilityElement(children: .combine) + } + } + } + if !achievements.isEmpty { + FlowLayout(spacing: Space.sm) { + ForEach(achievements, id: \.title) { achievement in + Text(achievement.title) + .font(.stim(.caption)) + .foregroundStyle(achievement.earned ? Palette.primary : Palette.tertiary) + .padding(.horizontal, Space.md) + .padding(.vertical, Space.xxs) + .overlay( + Capsule().strokeBorder( + achievement.earned ? Palette.primary : Palette.tertiary, + style: StrokeStyle(lineWidth: 1, dash: achievement.earned ? [] : [3, 3])) + ) + .accessibilityLabel("\(achievement.title), \(achievement.earned ? "earned" : "skipped")") + } + } + } + Text( + archiveOff + ? "Archived is off. The tutorial workspace has been removed." + : "Your workspace, builds, logs and recordings stay in Archived when archiving is enabled." + ) + .foregroundStyle(Palette.secondary) + .fixedSize(horizontal: false, vertical: true) + Button("Open Archived", action: openArchived) + .buttonStyle(.stim(.primary)).accessibilityLabel("Open Archived workspaces") + } + } + + private static func time(_ ms: Double) -> String { + ms < 60_000 ? "\(Int(ms / 1000))s" : Format.elapsed(ms: ms) + } + + private var total: TimeInterval? { + let end = record.stepTimes?["delete"] ?? record.stepTimes?["done"] + return end.map { $0.timeIntervalSince(record.startedAt) }.flatMap { $0 > 0 ? $0 : nil } + } + + private struct Tile { + var value: String + var caption: String + } + + private var tiles: [Tile] { + var tiles: [Tile] = [] + if let ms = stats.firstBuild?.durationMs { + tiles.append(Tile(value: Self.time(ms), caption: "first build")) + } + if let second = stats.secondBuild, let ms = second.durationMs { + let saved = stats.savedMs.map { ", saved \(Self.time($0))" } ?? "" + tiles.append( + Tile(value: Self.time(ms), caption: (second.cache == "none" ? "second build" : "cache hit") + saved)) + } + if record.secondPath != nil { + tiles.append( + Tile(value: "2", caption: stats.buildsOverlapped == true ? "worktrees building at once" : "worktrees side by side")) + } + if let actions = stats.agentActions, actions > 0 { + tiles.append(Tile(value: "\(actions)", caption: actions == 1 ? "agent action to replay" : "agent actions to replay")) + } + if record.done.contains("delete"), let bytes = stats.measuredBytes, bytes > 0 { + tiles.append(Tile(value: Format.fileSize(Int64(bytes)), caption: "freed")) + } + return tiles + } + + private struct Achievement { + var title: String + var earned: Bool + } + + private static let titles = [ + "device": "Hands on", "agent": "Replay", "logs": "Logs", "phone": "Pocket Stim", "share": "Shared", + "delete": "Clean slate", + ] + + private var achievements: [Achievement] { + steps.filter { $0.optional && (record.done.contains($0.id) || record.skipped.contains($0.id)) }.compactMap { step in + Self.titles[step.id].map { Achievement(title: $0, earned: record.done.contains(step.id)) } + } + } +} diff --git a/apps/desktop/Sources/StimDesktop/Views/TutorialPanel.swift b/apps/desktop/Sources/StimDesktop/Views/TutorialPanel.swift index 013f16d6c7..8266f8d621 100644 --- a/apps/desktop/Sources/StimDesktop/Views/TutorialPanel.swift +++ b/apps/desktop/Sources/StimDesktop/Views/TutorialPanel.swift @@ -91,16 +91,10 @@ struct TutorialPanel: View { private var stepList: some View { VStack(alignment: .leading, spacing: Space.lg) { if snapshot.isFinished { - Label("Tutorial Complete", systemImage: "checkmark.circle.fill") - .font(.stim(.headline)).foregroundStyle(Palette.success) - Text( - snapshot.steps.first(where: { $0.id == "finish" })?.detail == "Archived is off" - ? "Archived is off. The tutorial workspace has been removed." - : "Your workspace, builds, logs and recordings stay in Archived when archiving is enabled." - ) - .foregroundStyle(Palette.secondary) - Button("Open Archived", action: openArchived) - .buttonStyle(.stim(.primary)).accessibilityLabel("Open Archived workspaces") + TutorialCompletionCard( + snapshot: snapshot, steps: steps, + archiveOff: snapshot.steps.first(where: { $0.id == "finish" })?.detail == "Archived is off", + openArchived: openArchived) } ForEach(steps, id: \.id) { step in if let state = snapshot.steps.first(where: { $0.id == step.id }) { diff --git a/apps/desktop/Tests/VisualFixtureTests/TutorialScreenshotTests.swift b/apps/desktop/Tests/VisualFixtureTests/TutorialScreenshotTests.swift index cb8ed3811a..30ed300be2 100644 --- a/apps/desktop/Tests/VisualFixtureTests/TutorialScreenshotTests.swift +++ b/apps/desktop/Tests/VisualFixtureTests/TutorialScreenshotTests.swift @@ -116,6 +116,20 @@ if name == "done", let index = snapshot.steps.firstIndex(where: { $0.id == "phone" }) { snapshot.steps[index].state = .skipped } + if name == "done" { + snapshot.record.skipped = ["logs", "phone"] + snapshot.record.done.removeAll { snapshot.record.skipped.contains($0) } + snapshot.record.secondPath = "/Users/example/stim-tutorial-second" + snapshot.record.stepTimes = ["done": now.addingTimeInterval(1120)] + snapshot.record.stats = try! JSONDecoder().decode( + TutorialStats.self, + from: Data( + """ + {"firstBuild":{"durationMs":221000,"cache":"none","startedAt":0,"finishedAt":221}, + "secondBuild":{"durationMs":22000,"cache":"local","startedAt":120,"finishedAt":142}, + "agentActions":4,"worktreeBytes":{"/a":600000000,"/b":550000000,"/c":350000000}} + """.utf8)) + } return snapshot } } diff --git a/website/docs/desktop.md b/website/docs/desktop.md index 64112f0ef3..41d842d888 100644 --- a/website/docs/desktop.md +++ b/website/docs/desktop.md @@ -104,6 +104,8 @@ a tiny Expo app, and shows: - **Finish and Archive:** the prompt names the two worktrees; your agent stops their apps and removes only those, dropping their changes (a forced removal is allowed for exactly those two, after a plain remove refuses). The clone stays. **Open Archived** opens the same workspace page as a read-only archive, with retained build history, logs and recordings. Archived sidebar rows keep the live repository/worktree grouping and app labels. - **Delete the Test App (optional):** a prompt to remove the tutorial for good. Your agent removes any worktrees of the clone and then the clone itself with a plain `stim worktree remove`, stopping to ask if one holds changes, so their simulators, Metro ports and Stim records are torn down, and then deletes the clone's folder. The step completes when Stim no longer lists the clone and its folder is gone. Press **Next** to keep the clone. +When the tutorial ends, the panel shows a completion card: the time from clone to archive, the first build, the second build's cache hit and the time it saved, the two worktrees, the agent actions you can replay, and the space Delete freed, each only when Stim measured it. Each optional step you finished is a badge; a skipped one stays dashed. + Your agent checks each change on its simulator with agent-device, following `stim guide tutorial run`: it taps **Tap me**, toggles **Dark accent**, types a name and takes a screenshot, so Desktop records its actions for the Agent