Review Feature Access

Nucleic-Session: 85A6233A-F3F6-44B2-AD0B-261D49EE9C35
Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
2026-07-02 19:20:11 -07:00
co-authored by Nucleic
parent 3c2774d140
commit 4e1f0ec9da
@@ -588,51 +588,45 @@ final class RemoteStore: ObservableObject {
} }
/// Stream a short, believable canned turn for a session: assistant prose, a tool call + /// Stream a short, believable canned turn for a session: assistant prose, a tool call +
/// result, usage, and a finish — flipping the summary running → awaiting-input. /// result, usage, and a finish — flipping the summary running → awaiting-input. Each step
/// re-checks demo mode and cancellation so `exitDemo()` stops it cleanly. Runs entirely on the
/// main actor (the store is `@MainActor`, and a `Task` in an isolated method inherits it).
private func demoRun(_ sessionID: SessionID, userText: String?) { private func demoRun(_ sessionID: SessionID, userText: String?) {
if let userText, !userText.isEmpty { if let userText, !userText.isEmpty {
demoAppend(sessionID, .userText(TextChunk(messageID: UUID().uuidString, text: userText, isPartial: false))) demoAppend(sessionID, .userText(TextChunk(messageID: UUID().uuidString, text: userText, isPartial: false)))
} }
demoUpdateSession(sessionID) { $0.demoCopy(status: .running, disposition: .some(nil)) } demoUpdateSession(sessionID) { $0.demoCopy(status: .running, disposition: .some(nil)) }
let toolID = UUID().uuidString
let task = Task { [weak self] in let task = Task { [weak self] in
let toolID = UUID().uuidString func pause(_ ms: Int) async -> Bool {
guard await self?.demoStep(sessionID, delayMs: 600, { try? await Task.sleep(for: .milliseconds(ms))
$0.demoAppend(sessionID, .assistantText(TextChunk( return !Task.isCancelled && (self?.demoMode ?? false)
messageID: UUID().uuidString, text: "On it — let me take a look.", isPartial: false))) }
}) == true else { return } guard let self else { return }
guard await self?.demoStep(sessionID, delayMs: 700, { guard await pause(600) else { return }
$0.demoAppend(sessionID, .toolCallStarted(ToolCall( self.demoAppend(sessionID, .assistantText(TextChunk(
toolCallID: toolID, name: "Bash", input: ["command": "npm test"]))) messageID: UUID().uuidString, text: "On it — let me take a look.", isPartial: false)))
}) == true else { return } guard await pause(700) else { return }
guard await self?.demoStep(sessionID, delayMs: 900, { self.demoAppend(sessionID, .toolCallStarted(ToolCall(
$0.demoAppend(sessionID, .toolResult(ToolResult( toolCallID: toolID, name: "Bash", input: ["command": "npm test"])))
toolCallID: toolID, content: "42 passing\n0 failing", isError: false))) guard await pause(900) else { return }
}) == true else { return } self.demoAppend(sessionID, .toolResult(ToolResult(
guard await self?.demoStep(sessionID, delayMs: 700, { toolCallID: toolID, content: "42 passing\n0 failing", isError: false)))
$0.demoAppend(sessionID, .assistantText(TextChunk( guard await pause(700) else { return }
messageID: UUID().uuidString, self.demoAppend(sessionID, .assistantText(TextChunk(
text: "All green — tests pass and the change is in place. Anything else?", messageID: UUID().uuidString,
isPartial: false))) text: "All green — tests pass and the change is in place. Anything else?",
$0.demoAppend(sessionID, .usage(Usage( isPartial: false)))
inputTokens: 12_400, outputTokens: 640, costUSD: 0.0088, contextInputTokens: 12_400))) self.demoAppend(sessionID, .usage(Usage(
$0.demoAppend(sessionID, .runFinished(RunFinished(outcome: .completed, finalText: "Done."))) inputTokens: 12_400, outputTokens: 640, costUSD: 0.0088, contextInputTokens: 12_400)))
}) == true else { return } self.demoAppend(sessionID, .runFinished(RunFinished(outcome: .completed, finalText: "Done.")))
await self?.demoUpdateSession(sessionID) { self.demoUpdateSession(sessionID) {
$0.demoCopy(status: .awaitingInput, disposition: .some(.completed)) $0.demoCopy(status: .awaitingInput, disposition: .some(.completed))
} }
} }
demoTasks.append(task) demoTasks.append(task)
} }
/// One step of a simulated run: sleep, then (if still in demo and not cancelled) apply a
/// mutation on the main actor. Returns false to abort the remaining steps.
private func demoStep(_ sessionID: SessionID, delayMs: UInt64, _ body: @MainActor (RemoteStore) -> Void) async -> Bool {
try? await Task.sleep(for: .milliseconds(Int(delayMs)))
guard !Task.isCancelled, demoMode else { return false }
body(self)
return true
}
private func demoStartChat(_ req: StartChatRequest) { private func demoStartChat(_ req: StartChatRequest) {
let project = dashboard.projects.first { $0.id == req.projectID } let project = dashboard.projects.first { $0.id == req.projectID }
let id = SessionID(rawValue: "demo-\(UUID().uuidString.prefix(8))") let id = SessionID(rawValue: "demo-\(UUID().uuidString.prefix(8))")