paseo-follow-up 2.6.0 → 2.7.0-beta.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 +35 -17
- package/client/about.tsx +8 -2
- package/client/agents.tsx +1 -1
- package/client/brief-since.tsx +13 -7
- package/client/brief.tsx +61 -39
- package/client/button-visibility.ts +7 -3
- package/client/card-data.ts +24 -2
- package/client/catch-up.tsx +13 -10
- package/client/chat.tsx +15 -4
- package/client/created.tsx +15 -34
- package/client/daily-brief.tsx +83 -0
- package/client/dismiss.tsx +21 -6
- package/client/display.tsx +64 -38
- package/client/floating-surface.tsx +2 -1
- package/client/home-chrome.tsx +33 -9
- package/client/home-data.ts +18 -4
- package/client/home-list.tsx +80 -25
- package/client/home-view.ts +38 -3
- package/client/home.tsx +77 -48
- package/client/i18n.tsx +45 -0
- package/client/inbox-store.ts +34 -4
- package/client/inbox.tsx +19 -5
- package/client/install-scope.ts +80 -0
- package/client/job-rows.tsx +11 -4
- package/client/kit.tsx +11 -4
- package/client/last-known.ts +70 -0
- package/client/live.tsx +29 -14
- package/client/moments.tsx +66 -0
- package/client/more-context.tsx +19 -3
- package/client/motion.tsx +25 -2
- package/client/move-testids.ts +6 -0
- package/client/needs-you.tsx +15 -10
- package/client/onboarding-read.ts +12 -0
- package/client/onboarding.tsx +97 -152
- package/client/panel.tsx +37 -1
- package/client/pending-removals.ts +45 -0
- package/client/pill.tsx +16 -11
- package/client/pr-controls.tsx +6 -1
- package/client/pr-sheet.tsx +72 -3
- package/client/question-context.tsx +30 -18
- package/client/question-draft.ts +117 -0
- package/client/questions.tsx +193 -81
- package/client/release-notes.tsx +8 -7
- package/client/review-mode.tsx +2 -2
- package/client/row-actions.ts +30 -8
- package/client/row-chips.tsx +246 -0
- package/client/search-focus.ts +24 -4
- package/client/search-key.ts +8 -4
- package/client/settings.tsx +3 -3
- package/client/setup-gate.tsx +28 -4
- package/client/setup-ui.ts +10 -3
- package/client/shipping.tsx +23 -6
- package/client/shown-cards.tsx +18 -10
- package/client/sidebar-view.tsx +19 -4
- package/client/stacks.tsx +2 -1
- package/client/timeline-card.tsx +54 -0
- package/client/toast-store.ts +22 -7
- package/client/toasts.tsx +2 -2
- package/client/turn-view.tsx +68 -10
- package/client/updates.tsx +2 -0
- package/client/view-at.ts +19 -0
- package/client/view-r-header.tsx +155 -0
- package/client/view-r.tsx +715 -0
- package/client/workspace-data.ts +7 -1
- package/index.client.tsx +42 -7
- package/index.server.ts +117 -31
- package/package.json +2 -1
- package/scripts/inline.mjs +22 -8
- package/server/about.ts +30 -4
- package/server/agent-actions.ts +71 -18
- package/server/agent-hook.mjs +24 -6
- package/server/agent-hooks.ts +29 -0
- package/server/agent-parity.ts +7 -3
- package/server/ai-jobs.ts +44 -10
- package/server/ask.ts +2 -2
- package/server/brief-sources.ts +5 -5
- package/server/brief-timeline.ts +9 -1
- package/server/compass.ts +4 -1
- package/server/daemon-endpoint/index.d.mts +24 -0
- package/server/daemon-endpoint/index.mjs +145 -0
- package/{shared → server}/daemon-url.d.mts +3 -1
- package/server/daemon-url.mjs +48 -0
- package/server/daemon.ts +5 -4
- package/server/discovery.ts +3 -3
- package/server/engine.ts +57 -8
- package/server/github.ts +7 -3
- package/server/hook-source.ts +72 -35
- package/server/inbox.ts +65 -6
- package/server/mcp-source.ts +252 -81
- package/server/mcp.mjs +33 -36
- package/server/message-queue.ts +5 -0
- package/server/onboarding.ts +16 -3
- package/server/pr-actions.ts +3 -0
- package/server/pr-workflow.ts +9 -6
- package/server/ranker.ts +29 -8
- package/server/rename.ts +1 -1
- package/server/tasks.ts +17 -4
- package/server/turn-end.ts +17 -0
- package/server/turn-events.ts +2 -2
- package/server/turn-usage.ts +47 -0
- package/server/update-watchdog-source.ts +174 -18
- package/server/update-watchdog.mjs +3 -2
- package/server/usage-record.ts +69 -0
- package/server/wait-jobs.ts +11 -8
- package/shared/about.ts +2 -1
- package/shared/agent-settings.ts +10 -1
- package/shared/agent-text.d.mts +5 -1
- package/shared/agent-text.mjs +48 -29
- package/shared/attention.ts +29 -19
- package/shared/brief-sources.ts +6 -3
- package/shared/brief.ts +35 -4
- package/shared/catch-up.ts +6 -0
- package/shared/chat.ts +30 -22
- package/shared/contracts.ts +24 -6
- package/shared/daily-brief.ts +184 -0
- package/shared/display.ts +34 -2
- package/shared/errors.ts +3 -1
- package/shared/headline.ts +6 -2
- package/shared/home.ts +70 -12
- package/shared/i18n.ts +224 -0
- package/shared/inbox.ts +46 -5
- package/shared/job-rows.ts +7 -4
- package/shared/last-known.ts +63 -0
- package/shared/model.ts +28 -1
- package/shared/moments.ts +166 -0
- package/shared/onboarding.ts +77 -67
- package/shared/optimistic-removals.ts +145 -0
- package/shared/peek.ts +26 -1
- package/shared/pr-workflow.ts +64 -4
- package/shared/question-draft.ts +60 -0
- package/shared/questions.ts +21 -1
- package/shared/row-chips.ts +167 -0
- package/shared/row-menu.ts +26 -13
- package/shared/search-focus.ts +34 -2
- package/shared/search-key.ts +10 -0
- package/shared/send-decision.ts +32 -2
- package/shared/settings-nav.ts +1 -1
- package/shared/settings.ts +11 -0
- package/shared/setup-popup.ts +10 -3
- package/shared/spin.ts +17 -0
- package/shared/status-invariants.ts +187 -5
- package/shared/status.ts +21 -4
- package/shared/task-status.ts +23 -1
- package/shared/task-view.ts +1 -1
- package/shared/usage-record.ts +84 -0
- package/shared/view-r.ts +173 -0
- package/client/card-store.ts +0 -21
- package/shared/daemon-url.mjs +0 -39
package/client/pr-sheet.tsx
CHANGED
|
@@ -2,11 +2,14 @@ import { checksState } from "../shared/pr-status";
|
|
|
2
2
|
import { openLinkQuietly } from "./open-link";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import { Text } from "./text";
|
|
5
|
-
import { Icon, Modal } from "@getpaseo/plugin/client/ui";
|
|
6
|
-
import type { Workspace } from "../shared/model";
|
|
5
|
+
import { Icon, Modal, useToast } from "@getpaseo/plugin/client/ui";
|
|
6
|
+
import type { Pr, Workspace } from "../shared/model";
|
|
7
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
8
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
9
|
+
import { controlRpc } from "../shared/contracts";
|
|
7
10
|
import { compactPrStatus, graphitePrUrl, staleHint } from "../shared/presentation";
|
|
8
11
|
import { ago, prTone, stackOrder } from "../shared/attention";
|
|
9
|
-
import { Button, Chip, text, type Theme } from "./kit";
|
|
12
|
+
import { Button, Chip, errorText, text, type Theme } from "./kit";
|
|
10
13
|
import { PrControls } from "./pr-controls";
|
|
11
14
|
import { DialogFrame } from "./dialog-frame";
|
|
12
15
|
import { toneColor } from "./theme";
|
|
@@ -70,3 +73,69 @@ export function PrSheet({ workspace: w, prKey, intent, theme, compact, browserRe
|
|
|
70
73
|
</DialogFrame>
|
|
71
74
|
</Modal>;
|
|
72
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* One PR inline (the new view's reader, client/view-r.tsx): the same facts, controls and links as the sheet, drawn in the flow.
|
|
79
|
+
*/
|
|
80
|
+
export function PrDetail({ workspace: w, prKey, intent, theme, compact, browserReady }: { workspace: Workspace; prKey: string; intent: "merge" | "reviewers" | null; theme: Theme; compact: boolean; browserReady: boolean }) {
|
|
81
|
+
const c = theme.colors; const t = text(c, compact);
|
|
82
|
+
const pr = w.prs.find(p => p.key === prKey) ?? null;
|
|
83
|
+
const s = pr?.snapshot;
|
|
84
|
+
const open = (url: string) => openLinkQuietly(url, { workspaceId: w.id });
|
|
85
|
+
const status = pr ? compactPrStatus(pr) : null;
|
|
86
|
+
const tone = pr ? prTone(pr) : "unknown";
|
|
87
|
+
const stack = pr ? stackOrder(w.prs.filter(p => p.stack === pr.stack)) : [];
|
|
88
|
+
const parent = pr?.parent ? w.prs.find(p => p.key === pr.parent) : null;
|
|
89
|
+
const reviewers = s?.reviewers?.complete ? [...new Set([...s.reviewers.requested, ...s.reviewers.teams.map(team => `team/${team}`), ...s.reviewers.reviewed])] : [];
|
|
90
|
+
if (!pr) return null;
|
|
91
|
+
return <View style={{ gap: compact ? 16 : 14 }}>
|
|
92
|
+
<View style={{ gap: 6 }}>
|
|
93
|
+
<Text selectable style={compact ? t.title : [t.title, { fontSize: 16, lineHeight: 22 }]}>{s?.title ?? `${pr.repo} pull request`}</Text>
|
|
94
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
|
|
95
|
+
{status && <Chip theme={theme} label={status.label} color={toneColor(c, tone === "pending" || tone === "draft" ? "unknown" : tone)} />}
|
|
96
|
+
<Text style={t.meta}>{pr.repo} · {pr.stack}{stack.length > 1 ? ` · ${stack.indexOf(pr) + 1} of ${stack.length}` : ""}</Text>
|
|
97
|
+
</View>
|
|
98
|
+
</View>
|
|
99
|
+
<View style={{ gap: 8 }}>
|
|
100
|
+
{/* A known status stays; a failed read after it only makes the Checked line say how old it is. */}
|
|
101
|
+
{pr.error && !s?.complete && <Fact theme={theme} icon="TriangleAlert" color={c.statusWarning}>{pr.error}</Fact>}
|
|
102
|
+
{parent && <Fact theme={theme} icon="CornerLeftDown">Stacked on #{parent.number} · {parent.snapshot?.title ?? parent.stack}</Fact>}
|
|
103
|
+
{s?.conflict && <Fact theme={theme} icon="TriangleAlert" color={c.statusDanger}>Conflicts with its base branch</Fact>}
|
|
104
|
+
{!!s?.failedChecks.length && <Fact theme={theme} icon="CircleX" color={c.statusDanger}>Required checks failed: {s.failedChecks.join(", ")}</Fact>}
|
|
105
|
+
{/* Each failing optional check with Add to repairs (invariant 222): a required one is repaired already. */}
|
|
106
|
+
{s?.state === "OPEN" && (s.otherFailedChecks ?? []).map(check => <View key={check} style={{ flexDirection: "row", alignItems: "center", gap: 8, flexWrap: "wrap" }}>
|
|
107
|
+
<View style={{ flex: 1, minWidth: 180 }}><Fact theme={theme} icon="CircleX" color={c.statusWarning}>Optional check failed (not required to merge): {check}</Fact></View>
|
|
108
|
+
<AddToRepairs workspace={w} pr={pr} check={check} theme={theme} compact={compact} />
|
|
109
|
+
</View>)}
|
|
110
|
+
{s?.state === "OPEN" && checksState(s) === "running" && <Fact theme={theme} icon="LoaderCircle">Required checks are still running</Fact>}
|
|
111
|
+
{s?.state === "OPEN" && checksState(s) === "not-started" && <Fact theme={theme} icon="CircleDashed">Required checks haven't started on this PR</Fact>}
|
|
112
|
+
{!!s?.threads.length && <Fact theme={theme} icon="MessageSquare" color={c.statusWarning}>{s.threads.length} unresolved review thread{s.threads.length === 1 ? "" : "s"}</Fact>}
|
|
113
|
+
{s?.reviewDecision === "CHANGES_REQUESTED" && <Fact theme={theme} icon="MessageSquareWarning" color={c.statusWarning}>Changes requested</Fact>}
|
|
114
|
+
{reviewers.length > 0 && <Fact theme={theme} icon="Users">Reviewers: {reviewers.join(", ")}</Fact>}
|
|
115
|
+
{s?.deployment?.environment && <Fact theme={theme} icon="Rocket">{s.deployment.evidence}</Fact>}
|
|
116
|
+
{s?.observedAt && <Fact theme={theme} icon="Clock">{staleHint(pr, ago) ?? `Checked ${ago(s.observedAt)}`}</Fact>}
|
|
117
|
+
</View>
|
|
118
|
+
{s?.state === "OPEN" && <View style={{ paddingTop: 12, borderTopWidth: 1, borderTopColor: c.border }}>
|
|
119
|
+
<PrControls key={`${pr.key}:${intent ?? ""}`} pr={pr} workspace={w} theme={theme} compact={compact} browserReady={browserReady} intent={intent} />
|
|
120
|
+
</View>}
|
|
121
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8 }}>
|
|
122
|
+
{s?.prWorkflow !== "github" && <View style={compact ? { flex: 1 } : undefined}><Button theme={theme} compact={compact} grow={compact} icon="ExternalLink" title="Open in Graphite" accessibilityLabel={`Open ${pr.repo} pull request ${pr.number} in Graphite`} onPress={() => open(graphitePrUrl(pr))} /></View>}
|
|
123
|
+
{s?.url && s.prWorkflow === "github" && <View style={compact ? { flex: 1 } : undefined}><Button theme={theme} compact={compact} grow={compact} icon="ExternalLink" title="Open on GitHub" accessibilityLabel={`Open ${pr.repo} pull request ${pr.number} on GitHub`} onPress={() => open(s.url)} /></View>}
|
|
124
|
+
{s?.url && s.prWorkflow !== "github" && <View style={compact ? { flex: 1 } : undefined}><Button theme={theme} compact={compact} grow={compact} kind={compact ? "secondary" : "ghost"} icon="Github" title="GitHub" accessibilityLabel={`Open ${pr.repo} pull request ${pr.number} on GitHub`} onPress={() => open(s.url)} /></View>}
|
|
125
|
+
</View>
|
|
126
|
+
</View>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Add to repairs beside a failing optional check (invariant 222): the same follow.control the add_repair tool runs. A
|
|
131
|
+
* required check is repaired already, so only optional ones carry it; one already added says so.
|
|
132
|
+
*/
|
|
133
|
+
export function AddToRepairs({ workspace: w, pr, check, theme, compact }: { workspace: Workspace; pr: Pr; check: string; theme: Theme; compact: boolean }) {
|
|
134
|
+
const control = useRpc(controlRpc); const toast = useToast(); const cache = useQueryClient();
|
|
135
|
+
const added = !!pr.repairChecks?.includes(check);
|
|
136
|
+
const run = useMutation({ mutationFn: () => control({ workspaceId: w.id, repairCheck: { prKey: pr.key, check } }),
|
|
137
|
+
onSuccess: () => { toast.show(`${check} is in the next message to the main agent`, { variant: "success" }); void cache.invalidateQueries({ queryKey: ["follow-up"] }); }, onError: e => toast.error(errorText(e)) });
|
|
138
|
+
if (added || run.isSuccess) return <Text style={[text(theme.colors, compact).small, { flexShrink: 0 }]}>In repairs</Text>;
|
|
139
|
+
return <Button theme={theme} compact={compact} kind="ghost" icon="Wrench" title="Add to repairs" accessibilityLabel={`Add ${check} to the repairs for #${pr.number}`} loading={run.isPending} onPress={() => run.mutate()} />;
|
|
140
|
+
}
|
|
141
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// A question's own context, the same on every surface that shows it (one-answer-flow-for-every-question): the agent's
|
|
2
2
|
import { useOpenLink } from "./open-link";
|
|
3
|
-
// note, its
|
|
3
|
+
// note, the links its text doesn't carry, the PR it is about, and More context. QuestionBody draws it, and so does the brief card for
|
|
4
4
|
// each decision that is a tracked question, so a question in the chat timeline never drops what the panel shows.
|
|
5
5
|
import { View } from "react-native";
|
|
6
6
|
import { Pressable, Text } from "./text";
|
|
@@ -13,34 +13,48 @@ import { PrLinksProvider, RichText } from "./rich-text";
|
|
|
13
13
|
import { QuestionMoreContext } from "./more-context";
|
|
14
14
|
import { CardLinkRow } from "./shown-cards";
|
|
15
15
|
import { CardHere } from "./card-data";
|
|
16
|
-
import { useContext } from "react";
|
|
16
|
+
import { useContext, useState } from "react";
|
|
17
|
+
import { questionText } from "../shared/questions";
|
|
17
18
|
|
|
18
19
|
export function hostOf(url: string): string {
|
|
19
20
|
try { return new URL(url).host.replace(/^www\./, ""); } catch { return ""; }
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* Whether a question has context to draw: its note, links
|
|
24
|
-
* the question's title, which the Needs you block's header already says).
|
|
24
|
+
* Whether a question has context to draw: its note, the links its text doesn't carry, or its PR.
|
|
25
25
|
*/
|
|
26
|
-
export function hasQuestionContext(w: Pick<ListWorkspace, "prs" | "obligations">, q: ListQuestion,
|
|
27
|
-
|
|
28
|
-
return !!q.background || !!q.links?.length || (!!q.prKey && w.prs.some(p => p.key === q.prKey)) || (!!task && !(inline && task.title.trim() === q.title.trim()));
|
|
26
|
+
export function hasQuestionContext(w: Pick<ListWorkspace, "prs" | "obligations">, q: ListQuestion, _inline = false): boolean {
|
|
27
|
+
return !!q.background || questionText(q.question, q.links ?? []).below.length > 0 || (!!q.prKey && w.prs.some(p => p.key === q.prKey));
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
/**
|
|
30
|
+
/** A note longer than this many characters (or lines) folds to three lines with More (one-question-block). */
|
|
31
|
+
const NOTE_FOLD_CHARS = 220;
|
|
32
|
+
const folds = (note: string) => note.length > NOTE_FOLD_CHARS || note.split("\n").length > 3;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The note (three lines, then More), the links the question's text doesn't already carry, and the PR line. No task
|
|
36
|
+
* line: the task's own row says it waits on the question (one-question-block). `dense` (the pill) keeps only the note.
|
|
37
|
+
*/
|
|
32
38
|
export function QuestionContext({ workspace: w, question: q, theme, dense = false, inline = false, compact = false }: { workspace: Pick<ListWorkspace, "prs" | "obligations"> & Partial<Pick<ListWorkspace, "id" | "shownCards">>; question: ListQuestion; theme: Theme; compact?: boolean; dense?: boolean; inline?: boolean }) {
|
|
33
39
|
const open = useOpenLink();
|
|
34
40
|
const here = useContext(CardHere);
|
|
41
|
+
const [noteOpen, setNoteOpen] = useState(false);
|
|
35
42
|
if (!hasQuestionContext(w, q, inline)) return null;
|
|
36
43
|
const c = theme.colors; const t = text(c);
|
|
37
44
|
const pr = q.prKey ? w.prs.find(p => p.key === q.prKey) : null;
|
|
38
|
-
const
|
|
45
|
+
const links = questionText(q.question, q.links ?? []).below;
|
|
46
|
+
const note = q.background ?? "";
|
|
47
|
+
const fold = folds(note) && !noteOpen;
|
|
39
48
|
return <View style={{ gap: 8 }}>
|
|
40
|
-
{!!
|
|
49
|
+
{!!note && <View>
|
|
50
|
+
<RichText selectable linkColor={c.foreground} numberOfLines={dense || fold ? 3 : undefined} style={t.meta}>{note}</RichText>
|
|
51
|
+
{!dense && folds(note) && <Pressable accessibilityRole="button" accessibilityLabel={noteOpen ? `Show less of ${q.id}'s note` : `Show all of ${q.id}'s note`} hitSlop={6} onPress={() => setNoteOpen(o => !o)} style={{ alignSelf: "flex-start", minHeight: compact ? 44 : undefined, justifyContent: "center" }}>
|
|
52
|
+
<Text style={[t.meta, { color: c.foreground, fontWeight: "600" }]}>{noteOpen ? "Less" : "More"}</Text>
|
|
53
|
+
</Pressable>}
|
|
54
|
+
</View>}
|
|
41
55
|
{/* A card the agent showed in the view: one row (its thumbnail, title, what it holds, "below"); dense, one line. */}
|
|
42
|
-
{w.id &&
|
|
43
|
-
{!dense &&
|
|
56
|
+
{w.id && links.filter(link => link.card && link.card !== here).map((link, i) => <CardLinkRow key={`card${i}`} workspace={{ id: w.id!, shownCards: w.shownCards }} cardId={link.card!} theme={theme} compact={compact} dense={dense} />)}
|
|
57
|
+
{!dense && links.filter(link => !link.card).map((link, i) => <View key={i} style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
44
58
|
<Icon name={link.url ? "Globe" : "FileText"} size={13} color={c.foregroundMuted} />
|
|
45
59
|
{link.url ? <Pressable accessibilityRole="link" accessibilityLabel={`Open ${link.label || link.url}`} onPress={() => open(link.url!)} hitSlop={4}
|
|
46
60
|
style={state => ({ flexShrink: 1, flexDirection: "row", alignItems: "baseline", gap: 8, opacity: state.pressed ? 0.7 : 1 })}>
|
|
@@ -54,17 +68,15 @@ export function QuestionContext({ workspace: w, question: q, theme, dense = fals
|
|
|
54
68
|
{/* "#142" opens the PR (a-row-that-names-a-pr-opens-it-in-one-click). */}
|
|
55
69
|
<PrLinksProvider prs={prLinksByNumber([pr])}><RichText linkColor={c.foreground} numberOfLines={1} style={[t.meta, { flexShrink: 1 }]}>{`About #${pr.number}${pr.snapshot?.title ? ` · ${pr.snapshot.title}` : ""}`}</RichText></PrLinksProvider>
|
|
56
70
|
</View>}
|
|
57
|
-
{!dense && task && !(inline && task.title.trim() === q.title.trim()) && <View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
58
|
-
<Icon name="ListChecks" size={13} color={c.foregroundMuted} />
|
|
59
|
-
<RichText linkColor={c.foreground} numberOfLines={2} style={[t.meta, { flexShrink: 1 }]}>{`Task: ${task.title}`}</RichText>
|
|
60
|
-
</View>}
|
|
61
71
|
</View>;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
/** The context, then More context while the question is open: what QuestionBody and the brief card draw under the ask. */
|
|
65
|
-
export function QuestionContextBlock({ workspace: w, question: q, theme, compact, dense = false, inline = false, open, moreContext = true, openAgent }: { workspace: ListWorkspace; question: ListQuestion; theme: Theme; compact: boolean; dense?: boolean; inline?: boolean; open: boolean; moreContext?: boolean; openAgent?: (agentId: string) => void
|
|
75
|
+
export function QuestionContextBlock({ workspace: w, question: q, theme, compact, dense = false, inline = false, open, moreContext = true, openAgent, asking }: { workspace: ListWorkspace; question: ListQuestion; theme: Theme; compact: boolean; dense?: boolean; inline?: boolean; open: boolean; moreContext?: boolean; openAgent?: (agentId: string) => void;
|
|
76
|
+
/** The question block's More context: its icon sits in the block's action row, so here only the ask's sheet and answer draw. */
|
|
77
|
+
asking?: { open: boolean; setOpen: (open: boolean) => void } }) {
|
|
66
78
|
return <>
|
|
67
79
|
<QuestionContext workspace={w} question={q} theme={theme} compact={compact} dense={dense} inline={inline} />
|
|
68
|
-
{open && moreContext && <QuestionMoreContext workspace={w} question={q} theme={theme} compact={compact} openAgent={openAgent} />}
|
|
80
|
+
{open && moreContext && <QuestionMoreContext workspace={w} question={q} theme={theme} compact={compact} openAgent={openAgent} controlled={asking} />}
|
|
69
81
|
</>;
|
|
70
82
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
import { DRAFTS_KEPT, draftExpired, emptyDraft, patchDraft, readDraft, type QuestionDraft } from "../shared/question-draft";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The one store of answers in progress (`an-answer-in-progress-is-never-lost`, AGENTS.md invariant 205), keyed by
|
|
6
|
+
* question (`questionDraftKey`) or, for a brief's decision with no tracked question, by decision (`decisionDraftKey`).
|
|
7
|
+
* Every surface that answers a question reads and writes it here, never in its own component state, so the chat's card
|
|
8
|
+
* and the workspace view show one draft, and a surface that unmounts and comes back (the chat item remounting, the view
|
|
9
|
+
* rebuilt, the panel closed and opened) finds it as it was. Memory first, then this device's localStorage, so a reload
|
|
10
|
+
* keeps it too. A Send clears it (the pending answer holds the payload from then on: client/pending-answers.ts).
|
|
11
|
+
* Pasted images ride the same key through the image field's own draft (client/reply-draft.ts, IndexedDB on the web).
|
|
12
|
+
* Where there is no localStorage (Paseo's phone app) the draft lives in memory for the app session; no read or write
|
|
13
|
+
* here ever throws. A surface that shows a question no longer open (answered, withdrawn, removed) drops its draft
|
|
14
|
+
* (`clearDraft`), and anything untouched for `DRAFT_MAX_AGE_MS` is dropped when read, so storage never grows.
|
|
15
|
+
*
|
|
16
|
+
* 2026-12-02, the developer: "when I'm writing an answer, or choosing one, and the question disappears from chat for
|
|
17
|
+
* some reason and then comes back, or from the view, it doesn't save the answer". The panel's form kept its pick and
|
|
18
|
+
* words in memory but reset them to the server's copy on every mount, its note field was plain component state, and
|
|
19
|
+
* the chat's card kept its own stores keyed by the brief, so the two never showed the same draft.
|
|
20
|
+
*/
|
|
21
|
+
const mem = new Map<string, QuestionDraft | null>();
|
|
22
|
+
const listeners = new Set<() => void>();
|
|
23
|
+
const PREFIX = "follow-up:answer-draft:";
|
|
24
|
+
|
|
25
|
+
const storage = (): Storage | null => { try { return (globalThis as { localStorage?: Storage }).localStorage ?? null; } catch { return null; } };
|
|
26
|
+
|
|
27
|
+
let prunedOnce = false;
|
|
28
|
+
|
|
29
|
+
/** Memory's copy when there is one, so an unchanged draft is the same object (a stable useSyncExternalStore snapshot). */
|
|
30
|
+
function load(key: string): QuestionDraft | undefined {
|
|
31
|
+
if (mem.has(key)) return mem.get(key) ?? undefined;
|
|
32
|
+
// Once per session, on the first read from the device: expired drafts and those past the cap go.
|
|
33
|
+
if (!prunedOnce) { prunedOnce = true; const s = storage(); if (s) try { prune(s); } catch { /* memory only */ } }
|
|
34
|
+
let d: QuestionDraft | undefined;
|
|
35
|
+
try { const raw = storage()?.getItem(PREFIX + key); d = raw ? readDraft(JSON.parse(raw)) : undefined; } catch { d = undefined; }
|
|
36
|
+
if (d && draftExpired(d, Date.now())) { try { storage()?.removeItem(PREFIX + key); } catch { /* memory only */ } d = undefined; }
|
|
37
|
+
mem.set(key, d ?? null);
|
|
38
|
+
return d;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function save(key: string, d: QuestionDraft | undefined): void {
|
|
42
|
+
// A key first written adds a draft to the device, so that is when the cap is checked; an update (a keystroke) never scans.
|
|
43
|
+
const added = !mem.get(key) && !!d;
|
|
44
|
+
mem.delete(key); mem.set(key, d ?? null);
|
|
45
|
+
// The oldest drafts go first, in memory and on the device.
|
|
46
|
+
while (mem.size > DRAFTS_KEPT * 2) mem.delete(mem.keys().next().value!);
|
|
47
|
+
const s = storage(); if (!s) return;
|
|
48
|
+
try {
|
|
49
|
+
if (!d) { s.removeItem(PREFIX + key); return; }
|
|
50
|
+
s.setItem(PREFIX + key, JSON.stringify(d));
|
|
51
|
+
if (added) prune(s);
|
|
52
|
+
} catch { /* memory only */ }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function prune(s: Storage): void {
|
|
56
|
+
const kept: { k: string; at: number }[] = [];
|
|
57
|
+
for (let i = 0; i < s.length; i++) {
|
|
58
|
+
const k = s.key(i); if (!k?.startsWith(PREFIX)) continue;
|
|
59
|
+
try { kept.push({ k, at: readDraft(JSON.parse(s.getItem(k) ?? ""))?.at ?? 0 }); } catch { kept.push({ k, at: 0 }); }
|
|
60
|
+
}
|
|
61
|
+
kept.sort((a, b) => a.at - b.at);
|
|
62
|
+
const now = Date.now();
|
|
63
|
+
// Expired and malformed drafts go, then the oldest past the cap.
|
|
64
|
+
const drop = kept.filter((x, i) => draftExpired(x, now) || i < kept.length - DRAFTS_KEPT);
|
|
65
|
+
for (const { k } of drop) s.removeItem(k);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function emit(): void { for (const l of listeners) l(); }
|
|
69
|
+
|
|
70
|
+
export function subscribeDrafts(l: () => void): () => void { listeners.add(l); return () => { listeners.delete(l); }; }
|
|
71
|
+
|
|
72
|
+
export function getDraft(key: string): QuestionDraft | undefined { return load(key); }
|
|
73
|
+
|
|
74
|
+
/** Changes a draft; one that ends up holding nothing is forgotten. */
|
|
75
|
+
export function setDraft(key: string, patch: Partial<Omit<QuestionDraft, "at">>, at = Date.now()): void {
|
|
76
|
+
const prev = load(key);
|
|
77
|
+
const next = patchDraft(prev, patch, at);
|
|
78
|
+
if (prev && prev.choice === next.choice && prev.words === next.words && prev.noteOpen === next.noteOpen) return;
|
|
79
|
+
save(key, emptyDraft(next) ? undefined : next);
|
|
80
|
+
emit();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Sent (or answered elsewhere): the draft goes. */
|
|
84
|
+
export function clearDraft(key: string): void {
|
|
85
|
+
if (!load(key)) return;
|
|
86
|
+
save(key, undefined);
|
|
87
|
+
emit();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Tests: forget the memory copy (as a reload does), and with `device` the device's copy too. */
|
|
91
|
+
export function forgetDrafts({ device = false } = {}): void {
|
|
92
|
+
mem.clear(); prunedOnce = false;
|
|
93
|
+
const s = storage();
|
|
94
|
+
if (device && s) try { for (let i = s.length - 1; i >= 0; i--) { const k = s.key(i); if (k?.startsWith(PREFIX)) s.removeItem(k); } } catch { /* nothing kept */ }
|
|
95
|
+
emit();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A draft and its setter. The snapshot is this key's draft alone, so typing in one question re-renders that question's
|
|
100
|
+
* surfaces and no other (Home's pane with many asks, the view, the pill).
|
|
101
|
+
*/
|
|
102
|
+
export function useDraft(key: string): [QuestionDraft | undefined, (patch: Partial<Omit<QuestionDraft, "at">>) => void] {
|
|
103
|
+
const get = useCallback(() => load(key), [key]);
|
|
104
|
+
const draft = useSyncExternalStore(subscribeDrafts, get, get);
|
|
105
|
+
const set = useCallback((patch: Partial<Omit<QuestionDraft, "at">>) => setDraft(key, patch), [key]);
|
|
106
|
+
return [draft, set];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A card that reads several drafts (a brief with several decisions) re-renders when one of those changes, and no other;
|
|
111
|
+
* it reads them with getDraft. The snapshot is the drafts' change times, a string, so it compares by value.
|
|
112
|
+
*/
|
|
113
|
+
export function useDrafts(keys: readonly string[]): void {
|
|
114
|
+
const sig = keys.join("\n");
|
|
115
|
+
const get = useCallback(() => sig.split("\n").map(k => load(k)?.at ?? 0).join(","), [sig]);
|
|
116
|
+
useSyncExternalStore(subscribeDrafts, get, get);
|
|
117
|
+
}
|