mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
feat(native-chat): show Grok's /goal in the goal banner (#42840)
Grok reports goal state as goal_updated events, so the banner shows it and offers Resume and Clear through Grok's own /goal.
This commit is contained in:
@@ -3,7 +3,7 @@ import { Pressable, ScrollView, Text, View } from 'react-native'
|
||||
import { ChevronDown, Goal, Pause, Play, Trash2 } from 'lucide-react-native'
|
||||
import {
|
||||
agentSessionThreadGoalElapsedSeconds,
|
||||
agentSessionThreadGoalStatusChange
|
||||
agentSessionThreadGoalOfferedStatusChange
|
||||
} from '../../../../../../src/shared/agent-session/agent-session-thread-goal'
|
||||
import {
|
||||
agentSessionThreadGoalStatusLabel,
|
||||
@@ -55,7 +55,13 @@ export function MobileNativeChatThreadGoalStrip({
|
||||
const elapsed = formatAgentSessionThreadGoalElapsed(
|
||||
agentSessionThreadGoalElapsedSeconds(goal, now - threadGoal.hostClockOffsetMs, runningTurn)
|
||||
)
|
||||
const statusChange = changes === 'host' ? agentSessionThreadGoalStatusChange(goal.status) : null
|
||||
const statusChange =
|
||||
changes === null
|
||||
? null
|
||||
: agentSessionThreadGoalOfferedStatusChange(goal.status, {
|
||||
hostChanges: changes === 'host',
|
||||
agentResumes: threadGoal.agentResumes
|
||||
})
|
||||
const toggleLabel = expanded
|
||||
? t('chat.goal.collapse', 'Hide full goal')
|
||||
: t('chat.goal.expand', 'Show full goal')
|
||||
@@ -102,7 +108,7 @@ export function MobileNativeChatThreadGoalStrip({
|
||||
? t('chat.goal.pause', 'Pause')
|
||||
: t('chat.goal.resume', 'Resume')
|
||||
}
|
||||
disabled={locked}
|
||||
disabled={changes === 'agent' ? threadGoal.clearLocked : locked}
|
||||
onPress={() => void threadGoal.change({ kind: 'status', status: statusChange })}
|
||||
icon={
|
||||
statusChange === 'paused' ? (
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||
import {
|
||||
AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND,
|
||||
agentOwnedThreadGoalCommand,
|
||||
agentSessionThreadGoalReport
|
||||
} from '../../../../../../src/shared/agent-session/agent-session-thread-goal-report'
|
||||
import { getNativeChatAgentProfile } from '../../../../../../src/shared/native-chat/native-chat-agent-profiles'
|
||||
import type {
|
||||
AgentSessionThreadGoalChange,
|
||||
AgentSessionThreadGoalResult
|
||||
@@ -32,8 +33,10 @@ export type MobileStructuredThreadGoal = {
|
||||
runningTurn: { startedAt: number | null } | null
|
||||
/** Phone clock minus host clock, for reading goal times on the host's clock. */
|
||||
hostClockOffsetMs: number
|
||||
/** As `locked`; an agent-owned clear is also a message the agent must take, so it waits while the chat works. */
|
||||
/** As `locked`; an agent-owned clear or resume is also a message the agent must take, so it waits while the chat works. */
|
||||
clearLocked: boolean
|
||||
/** An agent-owned goal resumes through the agent's `/goal resume`. */
|
||||
agentResumes: boolean
|
||||
/** False when the change was refused or not sent; the error reaches the chat's error banner. */
|
||||
change: (change: AgentSessionThreadGoalChange) => Promise<boolean>
|
||||
}
|
||||
@@ -45,7 +48,7 @@ type GoalCommands = Pick<StructuredAgentSessionComposerOptions, 'changeThreadGoa
|
||||
export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
session: Pick<
|
||||
MobileStructuredAgentSessionArgs,
|
||||
'hostSupport' | 'enabled' | 'connected' | 'onSendError'
|
||||
'hostSupport' | 'enabled' | 'connected' | 'onSendError' | 'agent'
|
||||
>,
|
||||
state: Pick<StructuredAgentSessionState, 'items' | 'epoch' | 'hostClock'>,
|
||||
chat: {
|
||||
@@ -87,9 +90,11 @@ export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
: session.hostSupport?.phoneThreadGoal === true && relayed
|
||||
? 'host'
|
||||
: null
|
||||
const agentResumes = getNativeChatAgentProfile(session.agent)?.resumesOwnGoal === true
|
||||
const change = useCallback(
|
||||
async (next: AgentSessionThreadGoalChange): Promise<boolean> => {
|
||||
if (changes === null || (changes === 'agent' && next.kind !== 'clear')) {
|
||||
const command = changes === 'agent' ? agentOwnedThreadGoalCommand(next, agentResumes) : null
|
||||
if (changes === null || (changes === 'agent' && command === null)) {
|
||||
return false
|
||||
}
|
||||
const count = (by: number) =>
|
||||
@@ -98,8 +103,8 @@ export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
)
|
||||
count(1)
|
||||
try {
|
||||
if (changes === 'agent') {
|
||||
return (await sendRef.current(AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND)) !== 'rejected'
|
||||
if (command !== null) {
|
||||
return (await sendRef.current(command)) !== 'rejected'
|
||||
}
|
||||
const result = await mutate<AgentSessionThreadGoalResult>(
|
||||
'agentSession.threadGoal',
|
||||
@@ -119,7 +124,7 @@ export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
count(-1)
|
||||
}
|
||||
},
|
||||
[changes, mutate, onSendError, sessionKey]
|
||||
[agentResumes, changes, mutate, onSendError, sessionKey]
|
||||
)
|
||||
const hostClockOffsetMs = mobileStructuredHostClockOffsetMs(state.hostClock)
|
||||
const locked = (pending[sessionKey] ?? 0) > 0 || !session.enabled || !session.connected
|
||||
@@ -136,6 +141,7 @@ export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
changes,
|
||||
locked,
|
||||
clearLocked,
|
||||
agentResumes,
|
||||
runningTurn:
|
||||
turnId === null
|
||||
? null
|
||||
@@ -148,6 +154,7 @@ export function useMobileStructuredThreadGoal<TCommands extends object>(
|
||||
}
|
||||
: null,
|
||||
[
|
||||
agentResumes,
|
||||
change,
|
||||
changes,
|
||||
clearLocked,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { AgentSessionAccountKind } from '../../../shared/agent-session/agent-session-availability'
|
||||
import type { AgentSessionContextUsage } from '../../../shared/agent-session/agent-session-context-usage'
|
||||
import type { AgentSessionUsageLimit } from '../../../shared/agent-session/failures/agent-session-usage-limit'
|
||||
import type { AgentJournalToolCallItem } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import type {
|
||||
AgentJournalThreadGoal,
|
||||
AgentJournalToolCallItem
|
||||
} from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import type { AgentSessionPromptResponse } from '../../../shared/agent-session/agent-session-question-answer'
|
||||
import type {
|
||||
NativeChatBackgroundTaskBlock,
|
||||
@@ -77,6 +80,16 @@ export type AcpChildSessionReport = {
|
||||
update?: SessionNotification
|
||||
}
|
||||
|
||||
/** The agent's own goal as it reported it; null means cleared. */
|
||||
export type AcpThreadGoalReport = {
|
||||
goal:
|
||||
| ({ id: string } & Pick<
|
||||
AgentJournalThreadGoal,
|
||||
'objective' | 'status' | 'tokenBudget' | 'tokensUsed' | 'timeUsedSeconds'
|
||||
>)
|
||||
| null
|
||||
}
|
||||
|
||||
export type AcpDialectNotification =
|
||||
| { disposition: 'ignore' }
|
||||
| {
|
||||
@@ -92,6 +105,7 @@ export type AcpDialectNotification =
|
||||
backgroundTasks?: AcpBackgroundTaskUpdate[]
|
||||
subagents?: AcpSubagentUpdate[]
|
||||
child?: AcpChildSessionReport
|
||||
threadGoal?: AcpThreadGoalReport
|
||||
}
|
||||
|
||||
/** Hook denial completes the turn rather than recording a user Stop. */
|
||||
|
||||
@@ -7,6 +7,7 @@ import { grokBackgroundTaskNotification, grokToolBackgroundTasks } from './grok-
|
||||
import { grokModelEfforts } from './grok-model-catalog'
|
||||
import { grokSubagentNotification, grokToolSubagents } from './grok-subagents'
|
||||
import { grokSubagentStop } from './grok-subagent-stop'
|
||||
import { grokThreadGoalReport } from './grok-goal-updates'
|
||||
import { grokBackgroundTaskStop } from './grok-background-task-stop'
|
||||
|
||||
const tokenCount = z.number().int().nonnegative()
|
||||
@@ -173,6 +174,14 @@ function notification(
|
||||
subagents: [subagent]
|
||||
}
|
||||
}
|
||||
const threadGoal = grokThreadGoalReport(envelope.update)
|
||||
if (threadGoal) {
|
||||
return {
|
||||
disposition: 'map',
|
||||
...(envelope._meta?.isReplay === true ? { replay: true } : {}),
|
||||
threadGoal
|
||||
}
|
||||
}
|
||||
const meta = turnMetaSchema.safeParse(envelope._meta)
|
||||
const completion = completionSchema.safeParse(envelope.update)
|
||||
const response = responseSchema.safeParse(envelope.update)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Grok 1.0.77 reports its /goal state as `goal_updated` session notifications (recorded traffic).
|
||||
|
||||
import { z } from 'zod'
|
||||
import type { AgentJournalThreadGoalStatus } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import type { AcpThreadGoalReport } from './acp-dialect'
|
||||
|
||||
const tokenCount = z.number().int().nonnegative()
|
||||
const goalUpdatedSchema = z.looseObject({
|
||||
sessionUpdate: z.literal('goal_updated'),
|
||||
goal_id: z.string(),
|
||||
objective: z.string(),
|
||||
status: z.string(),
|
||||
token_budget: tokenCount.nullish(),
|
||||
tokens_used: tokenCount.optional(),
|
||||
elapsed_ms: tokenCount.optional()
|
||||
})
|
||||
|
||||
// Grok splits pauses by cause; every one resumes with `/goal resume`.
|
||||
const STATUS: Readonly<Record<string, AgentJournalThreadGoalStatus>> = {
|
||||
active: 'active',
|
||||
user_paused: 'paused',
|
||||
back_off_paused: 'paused',
|
||||
no_progress_paused: 'paused',
|
||||
infra_paused: 'paused',
|
||||
doom_loop_paused: 'paused',
|
||||
blocked: 'blocked',
|
||||
budget_limited: 'budgetLimited',
|
||||
complete: 'complete'
|
||||
}
|
||||
|
||||
/** Undefined for other updates and for statuses this build cannot read. */
|
||||
export function grokThreadGoalReport(update: unknown): AcpThreadGoalReport | undefined {
|
||||
const parsed = goalUpdatedSchema.safeParse(update)
|
||||
if (!parsed.success) {
|
||||
return undefined
|
||||
}
|
||||
const { data } = parsed
|
||||
if (data.status === 'cleared') {
|
||||
return { goal: null }
|
||||
}
|
||||
const status = STATUS[data.status]
|
||||
const objective = data.objective.trim()
|
||||
if (!status || !data.goal_id || !objective) {
|
||||
return undefined
|
||||
}
|
||||
return {
|
||||
goal: {
|
||||
id: data.goal_id,
|
||||
objective,
|
||||
status,
|
||||
tokenBudget: data.token_budget ?? null,
|
||||
tokensUsed: data.tokens_used ?? 0,
|
||||
timeUsedSeconds: Math.floor((data.elapsed_ms ?? 0) / 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":0,"elapsed_ms":0,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00"},"_meta":{"eventId":"session-1-2","agentTimestampMs":1794778989360}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":0,"elapsed_ms":3,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-3","agentTimestampMs":1794778989363}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":0,"elapsed_ms":24,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-6","agentTimestampMs":1794778989385}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":6044,"elapsed_ms":2298,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"live_subagent_tokens":6044,"live_context_pct":2,"live_turn_count":1,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-11","agentTimestampMs":1794778991659}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":15687,"elapsed_ms":6292,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"live_subagent_tokens":15687,"live_context_pct":6,"live_turn_count":1,"live_tool_call_count":1,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-51","agentTimestampMs":1794778995653}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":17318,"elapsed_ms":28292,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":0,"live_subagent_tokens":17318,"live_context_pct":6,"live_turn_count":1,"live_tool_call_count":2,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-103","agentTimestampMs":1794779017653}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":17393,"elapsed_ms":29984,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":17393,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00","planning":true},"_meta":{"eventId":"session-1-112","agentTimestampMs":1794779019345}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":17393,"elapsed_ms":29984,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":17393,"last_event":"goal_created","last_event_timestamp":"2026-11-15T21:43:09.360289+00:00"},"_meta":{"eventId":"session-1-113","agentTimestampMs":1794779019345}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"user_paused","phase":"executing","tokens_used":43121,"elapsed_ms":44776,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":17393,"last_event":"goal_paused","last_event_detail":"user","last_event_timestamp":"2026-11-15T21:43:54.138557+00:00"},"_meta":{"eventId":"session-1-196","agentTimestampMs":1794779034138}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"active","phase":"executing","tokens_used":43121,"elapsed_ms":44776,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":17393,"last_event":"goal_resumed","last_event_timestamp":"2026-11-15T21:43:57.214274+00:00"},"_meta":{"eventId":"session-1-201","agentTimestampMs":1794779037214}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"1f63c3c5-118f-45b1-80d4-3278199b2dc6","objective":"Write a file notes.md in the repo root with five numbered tips about writing clear commit messages, each under 15 words. Done when notes.md has exactly five numbered lines.","status":"user_paused","phase":"executing","tokens_used":43121,"elapsed_ms":74768,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":1328,"finished_subagent_tokens":17393,"last_event":"goal_paused","last_event_detail":"user","last_event_timestamp":"2026-11-15T21:44:27.207201+00:00"},"_meta":{"eventId":"session-1-289","agentTimestampMs":1794779067207}}}}
|
||||
{"direction":"in","process":"A","message":{"jsonrpc":"2.0","method":"_x.ai/session_notification","params":{"sessionId":"session-1","update":{"sessionUpdate":"goal_updated","goal_id":"","objective":"","status":"cleared","phase":"idle","tokens_used":0,"elapsed_ms":0,"total_deliverables":0,"completed_deliverables":0,"total_worker_rounds":0,"total_verify_rounds":0,"token_baseline":0,"finished_subagent_tokens":0},"_meta":{"eventId":"session-1-295","agentTimestampMs":1794779070423}}}}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { AcpTimelineTranslator } from './acp-timeline-translator'
|
||||
import { GROK_ACP_DIALECT } from '../acp-dialects/grok-dialect'
|
||||
import { readAcpFixture } from './testing/acp-timeline-fixture.test-support'
|
||||
|
||||
describe('Grok goal rows', () => {
|
||||
it('journals a recorded set, Stop, resume, Stop and clear as goal transitions', async () => {
|
||||
const lane = new AcpTimelineTranslator({ sessionId: 'session-1', dialect: GROK_ACP_DIALECT })
|
||||
const rows = (await readAcpFixture('grok-v1.0.77-goal-lifecycle')).flatMap((frame, index) =>
|
||||
frame.message.method
|
||||
? lane
|
||||
.notification(frame.message.method, frame.message.params, 1_000 + index)
|
||||
.flatMap((event) =>
|
||||
event.type === 'item.update' && event.body.kind === 'status' && event.body.threadGoal
|
||||
? [
|
||||
event.body.threadGoal.state === 'set'
|
||||
? [
|
||||
event.item,
|
||||
event.body.threadGoal.goal.status,
|
||||
event.body.threadGoal.goal.timeUsedSeconds
|
||||
]
|
||||
: [event.item.split(':')[0], 'cleared']
|
||||
]
|
||||
: []
|
||||
)
|
||||
: []
|
||||
)
|
||||
const goal = 'goal:1f63c3c5-118f-45b1-80d4-3278199b2dc6'
|
||||
expect(rows).toEqual([
|
||||
[goal, 'active', 0],
|
||||
[goal, 'paused', 44],
|
||||
[goal, 'active', 44],
|
||||
[goal, 'paused', 74],
|
||||
['goal-cleared', 'cleared']
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
// An agent-owned goal becomes one revised status row per goal; each clear is a newer row so it outranks the goal.
|
||||
|
||||
import {
|
||||
AGENT_SESSION_THREAD_GOAL_ACCOUNTING_REVISION_SECONDS,
|
||||
AGENT_SESSION_THREAD_GOAL_PRESENTATION
|
||||
} from '../../../shared/agent-session/agent-session-thread-goal'
|
||||
import type { AgentJournalThreadGoal } from '../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import type {
|
||||
ProviderTimelineEvent,
|
||||
ProviderTimelineJoin
|
||||
} from '../../native-chat/agent-session-timeline/provider-timeline-event'
|
||||
import type { AcpThreadGoalReport } from '../acp-dialects/acp-dialect'
|
||||
|
||||
type Shown = { id: string; goal: AgentJournalThreadGoal } | 'cleared'
|
||||
|
||||
export class AcpThreadGoalTimeline {
|
||||
/** Null until this child reports a goal transition. */
|
||||
private shown: Shown | null = null
|
||||
|
||||
update(
|
||||
report: AcpThreadGoalReport | undefined,
|
||||
join: ProviderTimelineJoin,
|
||||
at: number
|
||||
): ProviderTimelineEvent[] {
|
||||
if (!report) {
|
||||
return []
|
||||
}
|
||||
const shown = this.shown
|
||||
if (report.goal === null) {
|
||||
if (shown === 'cleared') {
|
||||
return []
|
||||
}
|
||||
this.shown = 'cleared'
|
||||
return [
|
||||
{
|
||||
type: 'item.update',
|
||||
item: `goal-cleared:${at}`,
|
||||
body: {
|
||||
kind: 'status',
|
||||
text: 'Goal cleared',
|
||||
presentation: AGENT_SESSION_THREAD_GOAL_PRESENTATION,
|
||||
threadGoal: { state: 'cleared' }
|
||||
},
|
||||
join
|
||||
}
|
||||
]
|
||||
}
|
||||
const { id, ...reported } = report.goal
|
||||
const same = shown !== 'cleared' && shown?.id === id ? shown.goal : null
|
||||
if (
|
||||
same &&
|
||||
same.status === reported.status &&
|
||||
same.objective === reported.objective &&
|
||||
same.tokenBudget === reported.tokenBudget &&
|
||||
reported.timeUsedSeconds - same.timeUsedSeconds <
|
||||
AGENT_SESSION_THREAD_GOAL_ACCOUNTING_REVISION_SECONDS
|
||||
) {
|
||||
return []
|
||||
}
|
||||
const goal: AgentJournalThreadGoal = {
|
||||
...reported,
|
||||
createdAt: same?.createdAt ?? at,
|
||||
updatedAt: at
|
||||
}
|
||||
this.shown = { id, goal }
|
||||
return [
|
||||
{
|
||||
type: 'item.update',
|
||||
item: `goal:${id}`,
|
||||
body: {
|
||||
kind: 'status',
|
||||
text: `Goal: ${goal.objective}`,
|
||||
presentation: AGENT_SESSION_THREAD_GOAL_PRESENTATION,
|
||||
threadGoal: { state: 'set', goal }
|
||||
},
|
||||
join
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
type AcpSessionEvent
|
||||
} from '../protocol/acp-session-events'
|
||||
import { AcpContextTimeline } from './acp-context-usage'
|
||||
import { AcpThreadGoalTimeline } from './acp-thread-goal-timeline'
|
||||
import { AcpBackgroundTaskTimeline } from './acp-background-task-timeline'
|
||||
import {
|
||||
GENERIC_ACP_DIALECT,
|
||||
@@ -50,6 +51,7 @@ export class AcpTimelineTranslator {
|
||||
private readonly failures: AcpTurnFailures
|
||||
private loading = false
|
||||
private readonly context = new AcpContextTimeline()
|
||||
private readonly threadGoal = new AcpThreadGoalTimeline()
|
||||
protected activeTurn?: string
|
||||
|
||||
constructor(private readonly options: AcpTimelineTranslatorOptions) {
|
||||
@@ -228,6 +230,7 @@ export class AcpTimelineTranslator {
|
||||
if (extension?.usage) {
|
||||
events.push(...this.context.update(extension.usage, join))
|
||||
}
|
||||
events.push(...this.threadGoal.update(extension?.threadGoal, join, at))
|
||||
if (settledCommand || this.prompts.absorbCompaction(owner.turn, extension, update)) {
|
||||
return events
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AGENT_SESSION_THREAD_GOAL_ACCOUNTING_REVISION_SECONDS } from '../../../../shared/agent-session/agent-session-thread-goal'
|
||||
import { unhandledProviderFrameJournalItem } from '../../../native-chat/agent-session-wire/providers/unhandled-provider-frame'
|
||||
import type { StructuredAgentSessionEventSink } from '../../../native-chat/agent-session-wire/journal-ingress/structured-agent-session-event-sink'
|
||||
import {
|
||||
@@ -25,9 +26,6 @@ type GoalThreadState = {
|
||||
accounting: CodexGoalAccounting | null
|
||||
}
|
||||
|
||||
// Throttle persisted accounting revisions; readers extrapolate while the turn runs.
|
||||
const GOAL_ACCOUNTING_REVISION_SECONDS = 30
|
||||
|
||||
function accountingOutgrew(
|
||||
previous: CodexGoalAccounting | null,
|
||||
next: CodexGoalAccounting
|
||||
@@ -35,7 +33,8 @@ function accountingOutgrew(
|
||||
return (
|
||||
previous === null ||
|
||||
previous.tokenBudget !== next.tokenBudget ||
|
||||
Math.abs(next.timeUsedSeconds - previous.timeUsedSeconds) >= GOAL_ACCOUNTING_REVISION_SECONDS
|
||||
Math.abs(next.timeUsedSeconds - previous.timeUsedSeconds) >=
|
||||
AGENT_SESSION_THREAD_GOAL_ACCOUNTING_REVISION_SECONDS
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -168,5 +168,6 @@ export function structuredAgentSessionThreadGoalReport(
|
||||
if (hostChangesGoal) {
|
||||
return { threadGoal: { current, ...contextFloor } }
|
||||
}
|
||||
return current ? { reportedThreadGoal: { current, ...contextFloor } } : {}
|
||||
// Sent without a goal too, so a goal the agent sets mid-turn shows from its first journal row.
|
||||
return { reportedThreadGoal: { current, ...contextFloor } }
|
||||
}
|
||||
|
||||
+2
-1
@@ -73,6 +73,7 @@ function NativeChatStructuredGoalStrip(props: {
|
||||
}
|
||||
pending={threadGoal.pending}
|
||||
hostChanges={threadGoal.hostChanges}
|
||||
agentResumes={threadGoal.agentResumes}
|
||||
sendUnavailable={transport.sendOut === true || props.isWorking}
|
||||
startsHeld={startsHeld}
|
||||
isVisible={props.isVisible}
|
||||
@@ -85,7 +86,7 @@ function NativeChatStructuredGoalStrip(props: {
|
||||
if (startsHeld && startsTurn) {
|
||||
return
|
||||
}
|
||||
if (change.kind === 'clear' && !threadGoal.hostChanges) {
|
||||
if (!threadGoal.hostChanges) {
|
||||
transport.onSubmitted?.()
|
||||
}
|
||||
void threadGoal.change(change)
|
||||
|
||||
+12
-5
@@ -9,7 +9,7 @@ import { NativeChatComposerTabStrip } from '../../composer/controls/NativeChatCo
|
||||
import type { AgentJournalThreadGoal } from '../../../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import {
|
||||
agentSessionThreadGoalElapsedSeconds,
|
||||
agentSessionThreadGoalStatusChange
|
||||
agentSessionThreadGoalOfferedStatusChange
|
||||
} from '../../../../../../shared/agent-session/agent-session-thread-goal'
|
||||
import type { AgentSessionThreadGoalChange } from '../../../../../../shared/agent-session/agent-session-thread-goal-wire'
|
||||
import { formatAgentSessionThreadGoalElapsed } from '../../../../../../shared/agent-session/view/agent-session-thread-goal-presentation'
|
||||
@@ -48,6 +48,8 @@ export function NativeChatThreadGoalBanner(props: {
|
||||
pending: boolean
|
||||
/** False where only the agent's own `/goal` changes the goal, which has no pause. */
|
||||
hostChanges: boolean
|
||||
/** The agent's own `/goal` resumes a paused goal. */
|
||||
agentResumes?: boolean
|
||||
/** The composer cannot admit another message or the session is working. */
|
||||
sendUnavailable: boolean
|
||||
/** The host may take no turn now: Resume, and a clear that enters a turn, are held. */
|
||||
@@ -63,7 +65,13 @@ export function NativeChatThreadGoalBanner(props: {
|
||||
const { runningTurn } = props
|
||||
const now = useNow(1_000, props.isVisible && goal.status === 'active' && runningTurn !== null)
|
||||
const label = nativeChatThreadGoalStatusLabel(goal.status, runningTurn !== null, t)
|
||||
const statusChange = props.hostChanges ? agentSessionThreadGoalStatusChange(goal.status) : null
|
||||
const statusChange = agentSessionThreadGoalOfferedStatusChange(goal.status, {
|
||||
hostChanges: props.hostChanges,
|
||||
agentResumes: props.agentResumes === true
|
||||
})
|
||||
// An agent-owned change is a message that must enter a fresh turn, like a composer send.
|
||||
const agentCommandUnavailable =
|
||||
!props.hostChanges && (props.sendUnavailable || props.startsHeld === true)
|
||||
if (label === null) {
|
||||
return null
|
||||
}
|
||||
@@ -84,8 +92,7 @@ export function NativeChatThreadGoalBanner(props: {
|
||||
<div className="flex shrink-0 items-center">
|
||||
<GoalAction
|
||||
label={t('components.native-chat.goal.clear', 'Clear goal')}
|
||||
// Claude's `/goal clear` must enter a fresh turn, like a composer send.
|
||||
disabled={!props.hostChanges && (props.sendUnavailable || props.startsHeld === true)}
|
||||
disabled={agentCommandUnavailable}
|
||||
onClick={() => onChange({ kind: 'clear' })}
|
||||
>
|
||||
<Trash2 className="size-3.5" />
|
||||
@@ -101,7 +108,7 @@ export function NativeChatThreadGoalBanner(props: {
|
||||
) : statusChange === 'active' ? (
|
||||
<GoalAction
|
||||
label={t('components.native-chat.goal.resume', 'Resume goal')}
|
||||
disabled={props.startsHeld === true}
|
||||
disabled={props.startsHeld === true || agentCommandUnavailable}
|
||||
onClick={() => onChange({ kind: 'status', status: 'active' })}
|
||||
>
|
||||
<Play className="size-3.5" />
|
||||
|
||||
+10
-4
@@ -4,7 +4,7 @@ import type {
|
||||
AgentJournalThreadGoal
|
||||
} from '../../../../../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import {
|
||||
AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND,
|
||||
agentOwnedThreadGoalCommand,
|
||||
agentSessionThreadGoalReport
|
||||
} from '../../../../../../shared/agent-session/agent-session-thread-goal-report'
|
||||
import type { AgentSessionOptionsResult } from '../../../../../../shared/agent-session/options/protocol/agent-session-options-result'
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
AgentSessionThreadGoalChange,
|
||||
AgentSessionThreadGoalResult
|
||||
} from '../../../../../../shared/agent-session/agent-session-thread-goal-wire'
|
||||
import { getNativeChatAgentProfile } from '../../../../../../shared/native-chat/native-chat-agent-profiles'
|
||||
import type { StructuredAgentSessionMutate } from '../structured/writes/use-structured-agent-session-mutate'
|
||||
|
||||
export type StructuredAgentSessionThreadGoal = {
|
||||
@@ -19,6 +20,8 @@ export type StructuredAgentSessionThreadGoal = {
|
||||
pending: boolean
|
||||
/** False for agent-owned /goal: clear uses a command and pause is unavailable. */
|
||||
hostChanges: boolean
|
||||
/** An agent-owned goal resumes through the agent's `/goal resume`. */
|
||||
agentResumes: boolean
|
||||
/** Resolves false when the change was refused or not sent; the error surfaces separately. */
|
||||
change: (change: AgentSessionThreadGoalChange) => Promise<boolean>
|
||||
}
|
||||
@@ -32,8 +35,10 @@ export function useStructuredAgentSessionThreadGoal(args: {
|
||||
mutate: StructuredAgentSessionMutate
|
||||
/** Sends the agent a command, for a goal only its own `/goal` changes. */
|
||||
send: (text: string) => boolean | 'queued'
|
||||
agent: string
|
||||
}): StructuredAgentSessionThreadGoal | null {
|
||||
const { journalItems, mutate, support, reported, journalEpoch, send } = args
|
||||
const agentResumes = getNativeChatAgentProfile(args.agent)?.resumesOwnGoal === true
|
||||
const [pendingCount, setPendingCount] = useState(0)
|
||||
const report = useMemo(
|
||||
() => agentSessionThreadGoalReport({ journalItems, support, reported, journalEpoch }),
|
||||
@@ -43,7 +48,8 @@ export function useStructuredAgentSessionThreadGoal(args: {
|
||||
const change = useCallback(
|
||||
async (next: AgentSessionThreadGoalChange): Promise<boolean> => {
|
||||
if (!hostChanges) {
|
||||
return next.kind === 'clear' && send(AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND) !== false
|
||||
const command = agentOwnedThreadGoalCommand(next, agentResumes)
|
||||
return command !== null && send(command) !== false
|
||||
}
|
||||
setPendingCount((count) => count + 1)
|
||||
try {
|
||||
@@ -57,10 +63,10 @@ export function useStructuredAgentSessionThreadGoal(args: {
|
||||
setPendingCount((count) => count - 1)
|
||||
}
|
||||
},
|
||||
[hostChanges, mutate, send]
|
||||
[agentResumes, hostChanges, mutate, send]
|
||||
)
|
||||
if (report === null) {
|
||||
return null
|
||||
}
|
||||
return { goal: report.goal, pending: pendingCount > 0, hostChanges, change }
|
||||
return { goal: report.goal, pending: pendingCount > 0, hostChanges, agentResumes, change }
|
||||
}
|
||||
|
||||
+2
-1
@@ -196,7 +196,8 @@ export function useStructuredAgentSession(args: StructuredAgentSessionViewArgs)
|
||||
support: threadGoalSupport,
|
||||
reported: reportedThreadGoal,
|
||||
mutate,
|
||||
send
|
||||
send,
|
||||
agent
|
||||
})
|
||||
const transcriptPending = useMemo(
|
||||
() => pendingSendsOutsideQueuedCards(pending, queuedMessageIds, isWorking),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { currentAgentSessionThreadGoal } from './agent-session-thread-goal'
|
||||
import type { AgentSessionThreadGoalChange } from './agent-session-thread-goal-wire'
|
||||
import type {
|
||||
AgentJournalRenderItem,
|
||||
AgentJournalThreadGoal
|
||||
@@ -8,6 +9,19 @@ import type { AgentSessionOptionsResult } from './options/protocol/agent-session
|
||||
/** What clears a goal only the agent's own /goal changes. */
|
||||
export const AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND = '/goal clear'
|
||||
|
||||
/** The message an agent-owned goal change sends; null when the agent's /goal has no such command. */
|
||||
export function agentOwnedThreadGoalCommand(
|
||||
change: AgentSessionThreadGoalChange,
|
||||
agentResumes: boolean
|
||||
): string | null {
|
||||
if (change.kind === 'clear') {
|
||||
return AGENT_OWNED_THREAD_GOAL_CLEAR_COMMAND
|
||||
}
|
||||
return agentResumes && change.kind === 'status' && change.status === 'active'
|
||||
? '/goal resume'
|
||||
: null
|
||||
}
|
||||
|
||||
export type AgentSessionThreadGoalReport = {
|
||||
goal: AgentJournalThreadGoal | null
|
||||
/** False for an agent-owned /goal: clear goes through the agent's command and there is no pause. */
|
||||
|
||||
@@ -17,6 +17,12 @@ const GOAL_FRAME_KINDS = new Set([
|
||||
|
||||
type GoalCandidate = Pick<AgentJournalRenderItem, 'sequence' | 'body' | 'agentId'>
|
||||
|
||||
/** A goal row the transcript leaves to the goal banner. */
|
||||
export const AGENT_SESSION_THREAD_GOAL_PRESENTATION = 'thread-goal'
|
||||
|
||||
/** Persist counter-only goal revisions at most this often; readers extrapolate while a turn runs. */
|
||||
export const AGENT_SESSION_THREAD_GOAL_ACCOUNTING_REVISION_SECONDS = 30
|
||||
|
||||
export function isAgentJournalThreadGoalStatus(
|
||||
value: string
|
||||
): value is AgentJournalThreadGoalStatus {
|
||||
@@ -111,6 +117,15 @@ export function agentSessionThreadGoalStatusChange(
|
||||
}
|
||||
}
|
||||
|
||||
/** The status change a goal's controls offer; an agent-owned goal can only resume, and only when its agent's /goal does. */
|
||||
export function agentSessionThreadGoalOfferedStatusChange(
|
||||
status: AgentJournalThreadGoalStatus,
|
||||
control: { hostChanges: boolean; agentResumes: boolean }
|
||||
): 'active' | 'paused' | null {
|
||||
const change = agentSessionThreadGoalStatusChange(status)
|
||||
return control.hostChanges || (control.agentResumes && change === 'active') ? change : null
|
||||
}
|
||||
|
||||
/** Accrue beyond exact provider time only during an active running turn, starting at the later of updatedAt and turn start. */
|
||||
export function agentSessionThreadGoalElapsedSeconds(
|
||||
goal: AgentJournalThreadGoal,
|
||||
|
||||
@@ -35,7 +35,7 @@ export type AgentSessionOptionsResult = {
|
||||
/** Offer goal controls only with threadGoal support; current spans the whole journal, including unloaded pages. */
|
||||
threadGoal?: { current: AgentJournalThreadGoal | null; contextFloor?: AgentJournalCursor }
|
||||
/** Journal goal changed only by the agent's /goal; separate from threadGoal so older clients never offer host controls. */
|
||||
reportedThreadGoal?: { current: AgentJournalThreadGoal; contextFloor?: AgentJournalCursor }
|
||||
reportedThreadGoal?: { current: AgentJournalThreadGoal | null; contextFloor?: AgentJournalCursor }
|
||||
/** Present for sessions writing turn context facts; current takes each part from the whole journal, including unloaded pages. */
|
||||
contextUsage?: { current: AgentSessionContextUsage; contextFloor?: AgentJournalCursor }
|
||||
/** This session takes image attachments. Absent = unknown (an older host). */
|
||||
|
||||
@@ -22,6 +22,8 @@ export type NativeChatAgentProfile = {
|
||||
/** Catalog commands the model acts on when they arrive as prose, even though
|
||||
* the runtime has no slash parser of its own. */
|
||||
textDrivenCommands?: readonly string[]
|
||||
/** The agent's own /goal resumes a paused goal with `/goal resume`. */
|
||||
resumesOwnGoal?: true
|
||||
}
|
||||
|
||||
// Both lines read `.claude/skills` beside their own folders, and 2.x reports no skill as a command.
|
||||
@@ -60,7 +62,8 @@ const NATIVE_CHAT_AGENT_PROFILES: Partial<Record<AgentType, NativeChatAgentProfi
|
||||
},
|
||||
grok: {
|
||||
skillPrefix: '/',
|
||||
skillSourceOwner: 'grok'
|
||||
skillSourceOwner: 'grok',
|
||||
resumesOwnGoal: true
|
||||
},
|
||||
// Pi expands only `/skill:<name>`; a bare `/<name>` reaches the model as text.
|
||||
pi: {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isAgentSessionThreadGoalFrame } from '../../../agent-session/agent-session-thread-goal'
|
||||
import {
|
||||
AGENT_SESSION_THREAD_GOAL_PRESENTATION,
|
||||
isAgentSessionThreadGoalFrame
|
||||
} from '../../../agent-session/agent-session-thread-goal'
|
||||
import type { NativeChatMessage } from '../../native-chat-types'
|
||||
|
||||
/** Show goal transitions in the banner only; retain them in the journal. */
|
||||
@@ -12,7 +15,10 @@ export function isNativeChatThreadGoalRow(message: NativeChatMessage): boolean {
|
||||
return (
|
||||
message.role === 'system' &&
|
||||
message.blocks.some(
|
||||
(block) => block.type === 'text' && isAgentSessionThreadGoalFrame(block.providerFrame)
|
||||
(block) =>
|
||||
block.type === 'text' &&
|
||||
(block.presentation === AGENT_SESSION_THREAD_GOAL_PRESENTATION ||
|
||||
isAgentSessionThreadGoalFrame(block.providerFrame))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user