feat: session goals - server-driven goal loop with independent small-model audit (#2148)
Arm the target button in the composer and the next prompt becomes a goal: the server keeps the session working toward it (idle tick -> small-model audit -> continuation) until the objective is verifiably complete, blocked, or out of budget — even with the UI closed. Server (packages/web/server/lib/session-goal): - event-driven loop on the global SSE hub; goal state lives in session.metadata.openchamber.goal (merge-safe patches, stale-write guard by goal id), so it survives restarts and syncs to every client for free - the small-model audit (objective + last assistant turn only, language pinned to the objective) is the sole termination authority; blocked needs 3 consecutive verdicts, audit outages tolerate one unaudited continuation then stop the goal as resumable-blocked - hard stops: optional token budget, auto-continuation cap (Resume grants a fresh allowance), turn errors; user abort pauses the goal instead of blocking it, and resuming over an aborted tail nudges immediately - token accounting as a snapshot of the latest turn (input + cache.read + output), goal-relative via a creation baseline and segmented across compactions; a compaction summary skips the audit and continues - continuations reuse the session's own provider/model/agent/variant UI: - three-mode target button (arm / disarm / manage dialog), informational goal strip with inline pause/resume and an Evaluating indicator, sidebar state glyph, objective length counter (2000-char server clamp), read-only completed goals - goal entry points: composer (sessions and drafts), start-new-session- from-answer dialog, plan implement dialog (plan content becomes the objective), scheduled tasks (Run as goal + budget) - Settings -> Chat -> Goal: feature toggle + default token budget with three-layer parity (web server, client persistence, VS Code bridge); VS Code renders goal state but hides the entry points (the loop runs in the web server only) Notifications: per-turn "ready" notifications are suppressed while a goal is active; settling sends one final notification (desktop, web-push, APNs generic titles with the session name as body) honoring the completion toggle. Error/question/permission notifications are untouched. Docs: user guide (session-goals) in all 9 locales + sidebar entry, scheduled-tasks cross-reference, server module DOCUMENTATION.md.
This commit is contained in:
committed by
GitHub
parent
82c039117a
commit
bb45164ae8
@@ -14,7 +14,7 @@ import { ThinkingPill } from '@/components/session/ThinkingPill';
|
||||
import { useConfigStore } from '@/stores/useConfigStore';
|
||||
import { useAgentsStore } from '@/stores/useAgentsStore';
|
||||
import { isPrimaryMode } from '@/components/chat/mobileControlsUtils';
|
||||
import { EXECUTION_FORK_DEFAULT_INSTRUCTIONS } from '@/lib/messages/executionMeta';
|
||||
import { EXECUTION_FORK_DEFAULT_INSTRUCTIONS, EXECUTION_FORK_GOAL_INSTRUCTIONS } from '@/lib/messages/executionMeta';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { isVSCodeRuntime } from '@/lib/desktop';
|
||||
|
||||
@@ -25,6 +25,7 @@ export type ForkSessionExecution = {
|
||||
agent: string;
|
||||
instructions: string;
|
||||
createWorktree?: boolean;
|
||||
runAsGoal?: boolean;
|
||||
};
|
||||
|
||||
type ForkSessionDialogProps = {
|
||||
@@ -54,7 +55,22 @@ export function ForkSessionDialog(props: ForkSessionDialogProps) {
|
||||
const [agent, setAgent] = React.useState(currentAgentName);
|
||||
const [instructions, setInstructions] = React.useState(EXECUTION_FORK_DEFAULT_INSTRUCTIONS);
|
||||
const [createWorktree, setCreateWorktree] = React.useState(false);
|
||||
const [runAsGoal, setRunAsGoal] = React.useState(false);
|
||||
const showCreateWorktree = React.useMemo(() => !isVSCodeRuntime(), []);
|
||||
// The goal loop lives in the web server; VS Code only renders goal state.
|
||||
const showRunAsGoal = React.useMemo(() => !isVSCodeRuntime(), []);
|
||||
|
||||
// Toggling goal mode swaps the prefilled instructions between the
|
||||
// report-back default and the assertive execute-to-completion variant —
|
||||
// but never clobbers text the user has edited.
|
||||
const handleToggleRunAsGoal = React.useCallback((next: boolean) => {
|
||||
setRunAsGoal(next);
|
||||
setInstructions((current) => {
|
||||
if (next && current === EXECUTION_FORK_DEFAULT_INSTRUCTIONS) return EXECUTION_FORK_GOAL_INSTRUCTIONS;
|
||||
if (!next && current === EXECUTION_FORK_GOAL_INSTRUCTIONS) return EXECUTION_FORK_DEFAULT_INSTRUCTIONS;
|
||||
return current;
|
||||
});
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open) return;
|
||||
@@ -75,6 +91,7 @@ export function ForkSessionDialog(props: ForkSessionDialogProps) {
|
||||
setAgent(config.currentAgentName || '');
|
||||
setInstructions(EXECUTION_FORK_DEFAULT_INSTRUCTIONS);
|
||||
setCreateWorktree(false);
|
||||
setRunAsGoal(false);
|
||||
}, [open]);
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -119,8 +136,9 @@ export function ForkSessionDialog(props: ForkSessionDialogProps) {
|
||||
agent,
|
||||
instructions,
|
||||
createWorktree: showCreateWorktree && createWorktree,
|
||||
runAsGoal: showRunAsGoal && runAsGoal,
|
||||
});
|
||||
}, [canConfirm, submitting, onConfirm, providerID, modelID, variant, agent, instructions, showCreateWorktree, createWorktree]);
|
||||
}, [canConfirm, submitting, onConfirm, providerID, modelID, variant, agent, instructions, showCreateWorktree, createWorktree, showRunAsGoal, runAsGoal]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open) return;
|
||||
@@ -186,25 +204,45 @@ export function ForkSessionDialog(props: ForkSessionDialogProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={`flex items-center gap-3 ${showCreateWorktree ? 'justify-between' : 'justify-end'}`}>
|
||||
{showCreateWorktree ? (
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<Checkbox
|
||||
checked={createWorktree}
|
||||
onChange={setCreateWorktree}
|
||||
disabled={submitting}
|
||||
ariaLabel={t('chat.messageBody.forkDialog.createWorktree')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={submitting}
|
||||
onClick={() => setCreateWorktree((value) => !value)}
|
||||
>
|
||||
{t('chat.messageBody.forkDialog.createWorktree')}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={`flex items-center gap-3 ${showCreateWorktree || showRunAsGoal ? 'justify-between' : 'justify-end'}`}>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1">
|
||||
{showCreateWorktree ? (
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<Checkbox
|
||||
checked={createWorktree}
|
||||
onChange={setCreateWorktree}
|
||||
disabled={submitting}
|
||||
ariaLabel={t('chat.messageBody.forkDialog.createWorktree')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={submitting}
|
||||
onClick={() => setCreateWorktree((value) => !value)}
|
||||
>
|
||||
{t('chat.messageBody.forkDialog.createWorktree')}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{showRunAsGoal ? (
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<Checkbox
|
||||
checked={runAsGoal}
|
||||
onChange={handleToggleRunAsGoal}
|
||||
disabled={submitting}
|
||||
ariaLabel={t('sessions.scheduledTasks.editor.goal.aria')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={submitting}
|
||||
onClick={() => handleToggleRunAsGoal(!runAsGoal)}
|
||||
>
|
||||
{t('sessions.scheduledTasks.editor.goal.label')}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button variant="ghost" size="sm" onClick={() => onOpenChange(false)} disabled={submitting}>
|
||||
{t('rightSidebar.contextNotesTodo.sendDialog.actions.cancel')}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { NumberInput } from '@/components/ui/number-input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { MobileOverlayPanel } from '@/components/ui/MobileOverlayPanel';
|
||||
import { toast } from '@/components/ui';
|
||||
@@ -466,6 +467,8 @@ type ScheduledTaskDraft = {
|
||||
modelID: string;
|
||||
variant: string;
|
||||
agent: string;
|
||||
goalEnabled: boolean;
|
||||
goalTokenBudget: number | null;
|
||||
};
|
||||
state?: ScheduledTask['state'];
|
||||
};
|
||||
@@ -515,6 +518,8 @@ const toDraft = (
|
||||
modelID: defaults.modelID,
|
||||
variant: defaults.variant,
|
||||
agent: defaults.agent,
|
||||
goalEnabled: false,
|
||||
goalTokenBudget: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -548,6 +553,10 @@ const toDraft = (
|
||||
modelID: task.execution.modelID,
|
||||
variant: task.execution.variant || '',
|
||||
agent: task.execution.agent || '',
|
||||
goalEnabled: task.execution.goalEnabled === true,
|
||||
goalTokenBudget: typeof task.execution.goalTokenBudget === 'number' && task.execution.goalTokenBudget > 0
|
||||
? task.execution.goalTokenBudget
|
||||
: null,
|
||||
},
|
||||
state: task.state,
|
||||
};
|
||||
@@ -1153,6 +1162,10 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
modelID: draft.execution.modelID,
|
||||
...(draft.execution.variant.trim() ? { variant: draft.execution.variant.trim() } : {}),
|
||||
...(draft.execution.agent.trim() ? { agent: draft.execution.agent.trim() } : {}),
|
||||
...(draft.execution.goalEnabled ? { goalEnabled: true } : {}),
|
||||
...(draft.execution.goalEnabled && draft.execution.goalTokenBudget
|
||||
? { goalTokenBudget: draft.execution.goalTokenBudget }
|
||||
: {}),
|
||||
},
|
||||
...(draft.state ? { state: draft.state } : {}),
|
||||
};
|
||||
@@ -1608,6 +1621,49 @@ export function ScheduledTaskEditorDialog(props: {
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-x-8 gap-y-2">
|
||||
<label className="inline-flex cursor-pointer items-center gap-2">
|
||||
<Checkbox
|
||||
checked={draft.execution.goalEnabled}
|
||||
onChange={(goalEnabled) => setDraft((prev) => ({
|
||||
...prev,
|
||||
execution: { ...prev.execution, goalEnabled },
|
||||
}))}
|
||||
ariaLabel={t('sessions.scheduledTasks.editor.goal.aria')}
|
||||
/>
|
||||
<span className="typography-meta">{t('sessions.scheduledTasks.editor.goal.label')}</span>
|
||||
</label>
|
||||
{draft.execution.goalEnabled ? (
|
||||
<label className="inline-flex cursor-pointer items-center gap-2">
|
||||
<Checkbox
|
||||
checked={draft.execution.goalTokenBudget !== null}
|
||||
onChange={(hasBudget) => setDraft((prev) => ({
|
||||
...prev,
|
||||
execution: { ...prev.execution, goalTokenBudget: hasBudget ? 200_000 : null },
|
||||
}))}
|
||||
ariaLabel={t('sessions.scheduledTasks.editor.goal.budgetAria')}
|
||||
/>
|
||||
<span className="typography-meta">{t('sessions.scheduledTasks.editor.goal.budgetLabel')}</span>
|
||||
</label>
|
||||
) : null}
|
||||
{draft.execution.goalEnabled && draft.execution.goalTokenBudget !== null ? (
|
||||
<NumberInput
|
||||
value={draft.execution.goalTokenBudget}
|
||||
onValueChange={(value) => {
|
||||
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
||||
setDraft((prev) => ({
|
||||
...prev,
|
||||
execution: { ...prev.execution, goalTokenBudget: Math.floor(value) },
|
||||
}));
|
||||
}
|
||||
}}
|
||||
min={1000}
|
||||
max={100000000}
|
||||
step={50000}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { isVSCodeRuntime } from '@/lib/desktop';
|
||||
import { ModelSelector } from '@/components/sections/agents/ModelSelector';
|
||||
import { AgentSelector } from '@/components/sections/commands/AgentSelector';
|
||||
import { ThinkingPill } from '@/components/session/ThinkingPill';
|
||||
@@ -21,6 +23,7 @@ export type TodoSendExecution = {
|
||||
modelID: string;
|
||||
variant: string;
|
||||
agent: string;
|
||||
runAsGoal?: boolean;
|
||||
};
|
||||
|
||||
type TodoSendDialogProps = {
|
||||
@@ -29,6 +32,8 @@ type TodoSendDialogProps = {
|
||||
target: TodoSendTarget;
|
||||
projectDirectory: string | null;
|
||||
submitting?: boolean;
|
||||
/** Offer a "Run as goal" checkbox (hidden in VS Code, where the loop does not run). */
|
||||
allowRunAsGoal?: boolean;
|
||||
onConfirm: (execution: TodoSendExecution) => Promise<void> | void;
|
||||
};
|
||||
|
||||
@@ -46,7 +51,8 @@ const getInitialExecution = (params: {
|
||||
|
||||
export function TodoSendDialog(props: TodoSendDialogProps) {
|
||||
const { t } = useI18n();
|
||||
const { open, onOpenChange, target, projectDirectory, submitting = false, onConfirm } = props;
|
||||
const { open, onOpenChange, target, projectDirectory, submitting = false, allowRunAsGoal = false, onConfirm } = props;
|
||||
const showRunAsGoal = allowRunAsGoal && !isVSCodeRuntime();
|
||||
|
||||
const loadProviders = useConfigStore((state) => state.loadProviders);
|
||||
const loadConfigAgents = useConfigStore((state) => state.loadAgents);
|
||||
@@ -177,7 +183,26 @@ export function TodoSendDialog(props: TodoSendDialogProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<div className={`flex items-center gap-3 ${showRunAsGoal ? 'justify-between' : 'justify-end'}`}>
|
||||
{showRunAsGoal ? (
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<Checkbox
|
||||
checked={execution.runAsGoal === true}
|
||||
onChange={(runAsGoal: boolean) => setExecution((prev) => ({ ...prev, runAsGoal }))}
|
||||
disabled={submitting}
|
||||
ariaLabel={t('sessions.scheduledTasks.editor.goal.aria')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={submitting}
|
||||
onClick={() => setExecution((prev) => ({ ...prev, runAsGoal: prev.runAsGoal !== true }))}
|
||||
>
|
||||
{t('sessions.scheduledTasks.editor.goal.label')}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button variant="ghost" size="sm" onClick={() => onOpenChange(false)} disabled={submitting}>
|
||||
{t('rightSidebar.contextNotesTodo.sendDialog.actions.cancel')}
|
||||
</Button>
|
||||
@@ -186,6 +211,7 @@ export function TodoSendDialog(props: TodoSendDialogProps) {
|
||||
? t('rightSidebar.contextNotesTodo.sendDialog.actions.sending')
|
||||
: t('rightSidebar.contextNotesTodo.sendDialog.actions.send')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@@ -34,6 +34,8 @@ import { useSessionUnseenCount } from '@/sync/notification-store';
|
||||
import { useSessionMultiSelectStore } from '@/stores/useSessionMultiSelectStore';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { useShiftKeyHeld } from '@/hooks/useShiftKeyHeld';
|
||||
import { getSessionGoal } from '@/lib/sessionGoalMetadata';
|
||||
import { sessionGoalStatusColor, sessionGoalStatusLabelKey } from '@/lib/sessionGoalPresentation';
|
||||
import { getRuntimeBearerTokenSync } from '@/lib/runtime-auth';
|
||||
import { getRuntimeApiBaseUrl } from '@/lib/runtime-switch';
|
||||
import { parseMultiRunSessionTitle } from '@/lib/multirun/title';
|
||||
@@ -353,6 +355,16 @@ function SessionNodeItemComponent(props: Props): React.ReactNode {
|
||||
);
|
||||
const sessionStatus = useGlobalSessionStatus(session.id);
|
||||
const sessionPermissions = useSessionPermissions(session.id, sessionDirectory ?? undefined);
|
||||
const sessionGoal = getSessionGoal(resolvedSession);
|
||||
const sessionGoalGlyph = sessionGoal ? (
|
||||
<span
|
||||
className="inline-flex flex-shrink-0 items-center"
|
||||
title={t(sessionGoalStatusLabelKey[sessionGoal.status] as never)}
|
||||
aria-label={t(sessionGoalStatusLabelKey[sessionGoal.status] as never)}
|
||||
>
|
||||
<Icon name="target" className="h-3 w-3" style={{ color: sessionGoalStatusColor[sessionGoal.status] }} />
|
||||
</span>
|
||||
) : null;
|
||||
const isActive = currentSessionId === session.id;
|
||||
const sessionTitle = resolvedSession.title || t('sessions.sidebar.session.untitled');
|
||||
const hasChildren = node.children.length > 0;
|
||||
@@ -1030,15 +1042,21 @@ function SessionNodeItemComponent(props: Props): React.ReactNode {
|
||||
>
|
||||
<div className={cn('flex w-full items-center min-w-0 flex-1 overflow-hidden', isMinimalMode ? 'gap-1' : 'gap-1')}>
|
||||
<div className={cn('block min-w-0 flex-1 truncate typography-ui-label font-normal', isActive ? 'text-primary' : 'text-foreground')}>{renderHighlightedText(sessionTitle, normalizedSessionSearchQuery)}</div>
|
||||
{alwaysShowActions ? <span className="ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75">{sessionCompactUpdatedLabel}</span> : null}
|
||||
{alwaysShowActions ? (
|
||||
<span className="ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75">
|
||||
{sessionGoalGlyph}
|
||||
{sessionCompactUpdatedLabel}
|
||||
</span>
|
||||
) : null}
|
||||
{!alwaysShowActions ? (
|
||||
<div className="relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end">
|
||||
<span className={cn(
|
||||
'whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150',
|
||||
'inline-flex items-center gap-1 whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150',
|
||||
isSessionMenuOpen
|
||||
? 'opacity-0'
|
||||
: hideOnHoverClass,
|
||||
)}>
|
||||
{sessionGoalGlyph}
|
||||
{sessionCompactUpdatedLabel}
|
||||
</span>
|
||||
</div>
|
||||
@@ -1105,6 +1123,7 @@ function SessionNodeItemComponent(props: Props): React.ReactNode {
|
||||
{!isMinimalMode ? (
|
||||
<div className="flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight" style={{ fontSize: 'calc(var(--text-ui-label) * 0.85)' }}>
|
||||
<div className={cn('flex min-w-0 items-center gap-1.5 overflow-hidden', metadataSubsessionChevron && hasChildren ? 'pl-4' : '')}>
|
||||
{sessionGoalGlyph}
|
||||
<span className="flex-shrink-0">{sessionUpdatedLabel}</span>
|
||||
{hasSecondaryProjectLabel ? <span className="truncate">{secondaryMeta?.projectLabel}</span> : null}
|
||||
{hasSecondaryBranchLabel ? <span className="inline-flex min-w-0 items-center gap-0.5"><Icon name="git-branch" className="h-3 w-3 flex-shrink-0 text-muted-foreground/70" /><span className="truncate">{secondaryMeta?.branchLabel}</span></span> : null}
|
||||
|
||||
Reference in New Issue
Block a user