Files
PaperClipAI/ui/src/components/ExecutionBlockerNotice.tsx
T
scotttongandScott Tong fb6632530d feat(onboarding): start the first chat with a welcome and choices (#23334)
## Thinking Path

> - Paperclip helps people assign and track work with AI agents.
> - Onboarding connects the first agent and opens its chat.
> - A new user needs a clear way to start a conversation.
> - A saved welcome can appear as soon as chat opens.
> - The standard question card lets the user pick a goal, a product
overview, or a task.
> - The connected model replies after the user sends the choice.

## Linked Issues or Issue Description

**Subsystem affected**

Onboarding, agent chat, and subscription sign-in.

**Problem or motivation**

New users can land in a chat before they know what to ask. The original
welcome depended on a model run, which could delay the first
interaction. Local Claude sign-in could lose its code field if the
browser reloaded the onboarding tab during authorization.

**Proposed solution**

Save a personalized welcome and a standard question card. Type the
welcome when the chat opens, then show the card above the composer. Use
the choice and any task description to guide the connected model. Resume
the local Claude sign-in attempt when the onboarding tab reloads.

**Alternatives considered**

A model-written welcome can vary, but it adds a model call before the
user has chosen what to do. The saved welcome gives the user the same
starting points each time.

**Roadmap alignment**

This improves the existing first-agent flow for local and Cloud-managed
instances.

Related PRs: #22433 covers clearing the organization name after Back.
#23326 adds the separate Cloud mobile-to-desktop handoff.

## What Changed

- Save the greeting and question card together. Reuse the saved chat on
entry and keep the transcript in order after a reload.
- Type the greeting in the chat and reveal the standard question card
above the composer. Honor reduced motion.
- Collect a task description before starting the first model turn for
the task option. Guide the first reply for each choice.
- Restore the original local Claude sign-in attempt when the onboarding
tab reloads. Show progress while it connects, and offer retry on a
failed or stalled code exchange.
- Update the organization name helper text and the onboarding
walkthrough tests.

## Verification

- See the first-chat test drive for manual steps and the credential-free
browser fixture.
- 659 focused Vitest tests passed, with one skipped. The UI and server
typechecks and the feature map validator passed.
- All 18 Chromium tests passed across the first-chat, onboarding,
sign-in resume, and mobile desktop handoff specs. Coverage includes the
saved greeting, chat ordering, question handoff, Claude code submission
and resume, and the Cloud-managed starter model path with scripted
replies.
- The published Cloud service and live subscriber credentials need
separate acceptance testing.

## Risks

- The greeting uses the existing conversation and interaction records.
No database migration is needed.
- Existing in-flight model greetings can finish through the previous
path.
- The Claude PTY change depends on the CLI's bracketed-paste support.
The runner preserves separate input writes for terminals that do not
announce support.

## Model Used

OpenAI Codex, GPT-6.2 Sol and GPT-6.2 Astra, with terminal and browser
tooling.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <1504818+scotttong@users.noreply.github.com>
2026-11-30 23:01:24 +00:00

156 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describeError } from "../api/errors";
import type { IssueRelationIssueSummary, TaskInterruptionPresentation } from "@paperclipai/shared";
import { AlertCircle } from "lucide-react";
import { Link } from "@/lib/router";
import { createIssueDetailPath } from "../lib/issueDetailBreadcrumb";
import { Button } from "./ui/button";
import { cn } from "../lib/utils";
import { useSecondTick } from "../hooks/useSecondTick";
import { TaskProjectAccessNotice } from "./TaskProjectAccessNotice";
import { ProviderFailureNotice } from "./ProviderFailureNotice";
import { LockedIssueChip, isLockedIssueStub } from "./LockedIssueChip";
import { PreviousServerStopConfirmation } from "./WorkspaceExportRecovery";
import { issuesApi } from "../api/issues";
const recoveryStepText: Record<NonNullable<TaskInterruptionPresentation["recoveryStep"]>, string> = {
checking_previous_run: "Checking that the previous attempt stopped",
saving_previous_files: "Saving files from the previous attempt",
finishing_recovery: "Finishing recovery of saved work",
};
/** A budget hard stop holds saved work. Only a task that already ran has an
* attempt to report; a task refused before its first run just waits. */
function budgetWaitText(presentation: TaskInterruptionPresentation) {
const wait = "It is waiting for the budget to allow new work. Raise the budget in Costs.";
return presentation.observedRunId || presentation.sourceRunIds.length
? `Couldn’t finish this attempt. Your message is saved. ${wait}`
: `This task has not started. ${wait}`;
}
const isBudgetWait = (presentation: TaskInterruptionPresentation | null | undefined) =>
presentation?.state === "waiting_for_user" && presentation.userAction === "budget";
const blockerAction: Record<string, string> = {
blocked: "Blocked: open it to Retry",
cancelled: "Cancelled: remove or replace it",
done: "Saving its files",
};
/** One ordinary interruption surface. Technical records remain in diagnostics. */
export function ExecutionBlockerNotice({ presentation, canRetry, onRetry, optimistic, takingLonger, error, className, issueId, companyId, agentName, projectName, blockers, hideQuestionReminder }: {
presentation: TaskInterruptionPresentation | null | undefined;
companyId?: string;
blockers?: IssueRelationIssueSummary[];
hideQuestionReminder?: boolean;
canRetry: boolean;
onRetry: () => void;
optimistic?: boolean;
takingLonger?: boolean;
error?: Error | null;
className?: string;
issueId?: string;
agentName?: string;
projectName?: string;
}) {
useSecondTick(presentation?.state === "retry_scheduled");
if (presentation?.projectAccess && !optimistic && !takingLonger) return <TaskProjectAccessNotice
access={presentation.projectAccess} issueId={issueId} agentName={agentName} projectName={projectName}
canRetry={canRetry && presentation.canRetry} onRetry={onRetry} error={error} className={className} />;
if (error && !optimistic && !takingLonger) return <div role="alert" className={cn("flex items-center justify-between gap-2 text-sm text-destructive", className)}><span>{describeError(error).body}</span>{canRetry && <Button variant="outline" size="sm" onClick={onRetry} data-testid="task-execution-retry">Retry</Button>}</div>;
if (takingLonger) return <div role="status" className={cn("flex items-center justify-between gap-2 text-sm text-muted-foreground", className)}><span>Taking longer than usual…</span>{canRetry && <Button variant="outline" size="sm" onClick={onRetry} data-testid="task-execution-retry">Retry</Button>}</div>;
const step = !optimistic && presentation?.responsibility === "system" && presentation.recoveryStep
&& ["working", "retry_scheduled"].includes(presentation.state) ? recoveryStepText[presentation.recoveryStep] : null;
const seconds = Math.max(0, Math.ceil((Date.parse(presentation?.nextRetryAt ?? "") - Date.now()) / 1000));
const retryIn = `Trying again in ${seconds > 60 ? `${Math.ceil(seconds / 60)}m` : `${seconds}s`}…`;
if (!optimistic && presentation?.state === "waiting_for_user" && presentation.userAction === "question") {
if (hideQuestionReminder && !(canRetry && presentation.canRetry)) return null;
return <div role="status" data-testid="task-execution-waiting" className={cn("flex items-center justify-between gap-2 text-sm text-muted-foreground", className)}>
{!hideQuestionReminder && <span>Respond to the pending question to continue.</span>}
{canRetry && presentation.canRetry && <Button variant="outline" size="sm" onClick={onRetry} data-testid="task-execution-retry">Retry</Button>}
</div>;
}
if (!optimistic && !presentation?.retryWait && presentation?.providerFailure && ["failed", "retry_scheduled", "waiting_for_user"].includes(presentation.state)) {
// Saved-work recovery is what the task waits for, so name it over the
// generic automatic-retry line while keeping the provider explanation.
return <ProviderFailureNotice failure={presentation.providerFailure} className={className}
actions={<>
{presentation.userAction === "provider_billing" && <Button variant="outline" size="sm" asChild><Link to="/apps">Review AI account</Link></Button>}
{canRetry && presentation.canRetry && <Button variant="outline" size="sm" onClick={onRetry} data-testid="task-execution-retry">Retry</Button>}
</>}>
{presentation.state === "retry_scheduled" && <p>{step ? `${step}. ${retryIn}` : "Paperclip will retry automatically."}</p>}
{presentation.userAction === "provider_billing" && <p>Check your provider account’s billing and usage allowance, then retry.</p>}
{isBudgetWait(presentation) && <p data-testid="task-execution-waiting">It is waiting for the budget to allow new work. Raise the budget in Costs.</p>}
</ProviderFailureNotice>;
}
if (step && presentation?.state === "working") return <div role="status" aria-label="Task status"
className={cn("text-sm text-muted-foreground", className)}>{`${step}…`}</div>;
if (!optimistic && presentation?.state === "working" && presentation.retryAction === "move_forward" && presentation.canRetry)
return <div role="status" aria-label="Task status" className={cn("flex items-center justify-between gap-3 text-sm text-muted-foreground", className)}>
<span className="min-w-0 flex-1">Waiting for the agent to finish other work. Paperclip continues this task by itself.</span>
{canRetry && <Button variant="outline" size="sm" className="shrink-0" onClick={onRetry} data-testid="task-execution-move-forward">Move it forward now</Button>}
</div>;
// A task that has not started yet names the admission hold it waits for.
if (!optimistic && presentation?.state === "working" && presentation.retryWait) {
const dependencies = presentation.retryWait.reason === "dependency_blocked" ? blockers ?? [] : [];
const unfinished = dependencies.filter(blocker => isLockedIssueStub(blocker) || blocker.status !== "done");
const waitingOn = unfinished.length ? unfinished : dependencies;
return <div role="status" aria-label="Task status" className={cn("text-sm text-muted-foreground", className)}>
<p>{presentation.retryWait.message}</p>
{waitingOn.length ? <ul className="mt-1 space-y-0.5" data-testid="retry-waiting-on">
{waitingOn.map(blocker => isLockedIssueStub(blocker)
? <li key={blocker.id} className="flex min-w-0 items-center gap-2"><LockedIssueChip identifier={blocker.identifier} /></li>
: <li key={blocker.id} className="flex min-w-0 items-center gap-2">
<Link to={createIssueDetailPath(blocker.identifier ?? blocker.id)}
className="font-mono text-xs text-foreground underline-offset-2 hover:underline">
{blocker.identifier ?? "Task"}
</Link>
<span className="min-w-0 truncate">{blocker.title}</span>
<span className="shrink-0 text-xs">{blockerAction[blocker.status] ?? blocker.status.replace(/_/g, " ")}</span>
</li>)}
</ul> : null}
</div>;
}
if (!optimistic && presentation?.userAction === "confirm_run_stopped" && presentation.observedRunId && issueId && companyId) {
const runId = presentation.observedRunId;
return <PreviousServerStopConfirmation key={`${issueId}:${runId}`} runId={runId} formId={runId} issueId={issueId} companyId={companyId}
className={className} confirmStop={stopEvidence => issuesApi.confirmRunStopped(issueId, { runId, stopEvidence })}
copy={{ waiting: presentation.retryWait?.message ?? "Paperclip can't confirm that the previous run stopped. Your message is saved.",
question: "How did you confirm that no agent is still working on this task?",
placeholder: "For example: no codex or claude process for this task is running on the server host.",
resuming: "Starting your Retry…", confirm: "Confirm it stopped" }} />;
}
// Other person-owned decisions have their own card on the task (approval,
// project access, ...). A budget hold has none, so name it here and keep the
// failure visible. The saved attempt starts by itself once the budget allows.
if (!optimistic && presentation && isBudgetWait(presentation)) return (
<div className={cn("pt-4", className)}>
<div role="status" aria-label="Task status" data-testid="task-execution-waiting"
className="flex items-center gap-3 rounded-lg bg-destructive/10 p-4 text-sm text-foreground">
<AlertCircle className="size-5 shrink-0 text-destructive" aria-hidden="true" />
<span className="min-w-0 flex-1">{budgetWaitText(presentation)}</span>
</div>
</div>
);
if (optimistic || !presentation || presentation.responsibility !== "system" ||
!["failed", "retry_scheduled"].includes(presentation.state)) return null;
return (
<div className={cn(presentation.state === "failed" && "pt-4", className)}>
<div role="status" aria-label="Task status" className={cn(
"flex items-center justify-between gap-3 text-sm",
presentation.state === "failed" ? "rounded-lg bg-destructive/10 p-4 text-foreground" : "text-muted-foreground",
)}>
{presentation.state === "failed" && <AlertCircle className="size-5 shrink-0 text-destructive" aria-hidden="true" />}
<span className="min-w-0 flex-1">{presentation.state === "retry_scheduled"
? step ? `${step}. ${retryIn}`
: presentation.setupFailure ? `${presentation.setupFailure.message}. ${retryIn}` : retryIn
: presentation.retryWait ? presentation.retryWait.message
: presentation.workspaceFailure
? <>Couldn’t prepare the task folders. {presentation.workspaceFailure.message}</>
: presentation.setupFailure
? <>Couldn’t set up the task workspace. {presentation.setupFailure.message}. Fix the command in the project’s workspace settings, then retry.</>
: "Couldn’t finish this attempt. Your message is saved."}</span>
{canRetry && presentation.canRetry && <Button variant="outline" size="sm" className="shrink-0" onClick={onRetry} data-testid="task-execution-retry">Retry</Button>}
</div>
</div>
);
}