mirror of
https://github.com/stablyai/orca.git
synced 2026-11-06 03:57:35 +00:00
* Revert "Revert Claude per-account folders (#24434, #26405) before release (#26638)"
This reverts commit 9ca9b4e36b.
* Move the terminal daemon protocol to 44 for the re-landed claude function
v43 daemons (the revert) lack the claude account function, so new terminals must not reuse them. v42 and v43 stay attachable.
* Move the local build compatibility contract to daemon protocol 44
* Point the old-terminal test at daemon protocol 44
* Claude accounts re-land: never sign anyone out, keep proxies working, accounts mirror ~/.claude (#26769)
* Run a Claude account on System default until it has its own login
An account saved before per-account folders has no login in its folder. While System default (~/.claude, or the user's own CLAUDE_CONFIG_DIR) is signed in to the same email, the router sends every launch there and writes that choice into the pointer file, so nobody is logged out by the update. Once the account signs in to its own folder, the next launch uses it. The WSL router follows the same rule with the guest's ~/.claude.
* Refresh each Claude account folder from ~/.claude before every launch
~/.claude (or the user's own CLAUDE_CONFIG_DIR) is now the master copy. Each account folder gets its whole settings.json, including the proxy address and its key, and every .claude.json key except the login, Claude's account caches and install ids, so first-run questions are not asked again. Every other top-level entry is linked (folders) or copied (files), except Claude's per-folder daemon, jobs, live sessions, login files and throwaways. sessions is no longer shared, and an earlier link is undone.
The refresh runs before every Claude Orca starts, for each new terminal and on account switch. Orca never writes back to ~/.claude. The ledger that tracked selective sharing is gone.
* Route chat auth and unselected-account usage through the Claude router
Chats decided whether to drop inherited Anthropic auth from the selection alone, so an account running on System default lost the user's own key. They now ask the router, as terminals, AI commit messages, automations and usage already do. Usage for an unselected account is read where its launches would run. A test reads every entry point through the fallback and fails if a launch path outside the router reads the Claude selection or builds an account folder. The router's two launch errors move to their own file to keep it under the line limit.
* Show Claude account sign-in prompts only when an account cannot run
With the fallback, an account System default is signed in to already works, so:
- The one-time "Finish setting up your Claude accounts" toast is gone.
- Accounts System default covers no longer need a sign-in: no Sign in in the status bar menu or Settings, and they can be selected.
- The old-terminal banner shows only when claude in that terminal would run a different account than the selected one, and asks again after a switch. Its wording is unchanged.
The retired toast's saved flag stays in the paired-client schema so an older client's write is still accepted. The email comparison moves beside the login reader to keep the router under the line limit.
* Keep the user's shell Anthropic auth on Claude account launches
A signed-in account's launches used to drop ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and CLAUDE_CODE_OAUTH_TOKEN from the inherited environment while ANTHROPIC_BASE_URL passed through, so a proxy set in the shell got the subscription login and answered 401. Host launches on an account now keep the shell's auth with its address, as System default does. Chats still name the account kind in a failed sign-in, now from the router rather than from whether auth was dropped.
* Share from ~/.claude only what Claude itself would seed into a new folder
The deny list missed much of Claude's runtime state, so tokens, locks and live files such as .session_ingress_token, server-sessions.json and remote-control were copied or linked over each account's own every launch. The list now mirrors the one Claude uses when it seeds a fresh config folder from ~/.claude: its runtime entries, every hidden entry, daemon files and agent memory. teams, ide, downloads and scratch are on it, so they stay per folder.
* Merge trusted folders and MCP servers into an account instead of replacing them
Each refresh replaced the account's projects and mcpServers with ~/.claude's, so folder trust and allowed tools recorded only in the account were lost, and a refresh landing between Orca's folder-trust write and Claude's start brought the trust dialog back. Both are now merged per folder path or server name: ~/.claude wins for entries it has, the account keeps the rest, and a folder trusted in the account stays trusted. Both writers take Claude's lock on the file, so the order no longer matters.
* Require the same organization before System default stands in for an account
The fallback compared emails only, so one email saved for two organizations made both accounts run on whichever organization System default was signed in to. When the saved account and System default's login both name an organization, it must now match too, on the host and in WSL, and the old-terminal banner uses the same comparison. The saved-account lookup the three checks repeated is now one helper.
* Treat v42 terminals as having the claude account function
v42 daemons shipped the same claude function and pointer path as v44, so claude in those terminals already follows the selected account. The old-terminal banner now shows only for daemons before v42 and for v43, the revert, which dropped the function.
* Fail the routing test when a new module resolves the claude binary
The census only caught code that read the Claude selection, not a new launcher that runs claude without asking the router. A second check now lists every module that resolves the claude binary or loads the Agent SDK, each with why it is routed, and fails on any new one, or on a listed one that no longer matches.
* Skip the account refresh on launches that run on System default
A launch that falls back to System default never uses the account folder, so starting a setup for it on every launch was wasted work. Account switches still set the folder up for a later sign-in.
* Give a terminal opened before the login shell's env only the account pointer
At startup, a pane could be routed before the login shell reported the user's own CLAUDE_CONFIG_DIR, so the fallback compared against ~/.claude.json instead. Until that env arrives a pane gets only the pointer, and the pointer is rewritten once it does, so claude typed there reads the right folder. The recent claude --version answer moves beside the version probe to keep the router under the line limit.
* Drop the chat-only Anthropic auth stripping and override refusal
Chats no longer drop the shell's Anthropic auth on any account, so the chat launch's override refusal and the policy's stripAuthEnv could only be reached from test fixtures. The structured auth policy is now just which login a failed sign-in names. Terminals keep their refusal, which still guards WSL launches; the failure reason stays in the shared vocabulary for older peers.
* Publish a new account state file whole
The first .claude.json write went straight to the target, so a crash mid-write could leave Claude a truncated state file. It is now written to a staged file and linked into place without replacing one Claude created meanwhile.
* Read an unselected WSL account's usage where the WSL router would run it
Usage for an unselected WSL account read its saved folder directly, so an account the guest's ~/.claude covers showed no usage, and the read bypassed the router. It now asks the WSL router, after the same check that the distro is already running.
* Keep the shell's Anthropic auth when the claude function runs an account
The claude shell function (POSIX, fish and PowerShell) unset ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, CLAUDE_CODE_OAUTH_TOKEN, AWS_BEARER_TOKEN_BEDROCK and auth-like ANTHROPIC_CUSTOM_HEADERS before running Claude in an account folder, so a proxy set in the shell lost its key while keeping its address. It now only sets CLAUDE_CONFIG_DIR and Orca's marker, as on System default. Protocol 44 is unreleased, so no new bump; the shell-wrapper snapshots are regenerated.
* Never drop the user's Anthropic auth from a Claude launch
Orca's launches stripped ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, CLAUDE_CODE_OAUTH_TOKEN, AWS_BEARER_TOKEN_BEDROCK and auth-like ANTHROPIC_CUSTOM_HEADERS for WSL terminals, terminal splits and through the preparation's stripAuthEnv flag, and refused a launch whose agent env set them. If the user's shell overrides the login, that is their setup: every launch now keeps it, on accounts, System default and WSL alike. The flag, the strip paths and the override refusal are gone; the refusal's reason stays in the shared vocabulary so older peers still decode it.
Orca's own process env and the claude --version probe still drop these variables: they are Orca's, not the user's launch.
* Leave out of an account's state everything Claude resets when it signs out
The .claude.json copy left out the login and keys matching cache patterns, but still carried account state such as additionalModelOptionsAnsweredAt, artifactRosterDenied, lastSeenOrgDefaultUpdatedAt and the subscription notices. The copy now leaves out the exact keys Claude resets on logout, beside the install ids, Console API key and first-token date; the cache patterns stay for account caches logout does not reset. Onboarding is still copied.
* Judge an old terminal's Claude banner by the pane's own runtime
The banner compared every old pane with the host selection and showed whenever only a WSL account was selected, so old host panes showed it with nothing to say and old WSL panes were judged by the host's account. The pane now names its runtime: a host pane is compared with the host selection, a WSL pane with its distro's selection through the WSL router, and a pane whose runtime is unknown, or with no account selected for it, stays hidden.
* Leave an account's settings file alone when only Orca's hooks differ from the default home's
* Reread a WSL account's Claude state only when the file changes
* Move tests merged from main onto the account-only Claude auth policy
355 lines
15 KiB
TypeScript
355 lines
15 KiB
TypeScript
// The sentence a person reads beside each failure fact, and the one constructor that writes both.
|
|
//
|
|
// A row's `text`, a rejected message's `reason` and a conversation command's `error` are what
|
|
// every released client prints as they are, so the host writes them here, from the fact, and
|
|
// nowhere else: never Orca's own error text, a refusal's message, or a probe's evidence. A
|
|
// provider's words reach the sentence only when the provider wrote them for a person. Each sentence
|
|
// is built from the pieces in `agent-session-failure-copy`, which desktop translates to word the
|
|
// same fact in the reader's language.
|
|
|
|
import {
|
|
isSubmissionRejectionFact,
|
|
type AgentSessionAttachmentProblem,
|
|
type AgentSessionAttachmentProblemReason,
|
|
type AgentSessionFailureFact,
|
|
type AgentSessionFailureKind,
|
|
type ProviderDiagnostic,
|
|
type SubmissionRejectionFact,
|
|
type SubmissionRejectionKind
|
|
} from './agent-session-failure'
|
|
import type { AgentSessionConversationCommand } from './agent-session-conversation-command'
|
|
import { cliMissingSentence, notSignedInSentence } from './agent-session-availability-sentences'
|
|
import {
|
|
sayAgentSessionFailureEnglish,
|
|
type AgentSessionFailureCopyId,
|
|
type AgentSessionFailureCopyValues,
|
|
type AgentSessionFailureSay
|
|
} from './agent-session-failure-copy'
|
|
import type { AgentSessionWireRefusalCode } from './agent-session-wire-refusals'
|
|
import { providerRetryWords, withRetryCause } from './agent-session-provider-retry-words'
|
|
import { commandRefusedByReason } from './agent-session-command-refusal-words'
|
|
import { joinSentences } from './sentence-joining'
|
|
import {
|
|
DISPATCH_REJECTED_CANCELLED,
|
|
DISPATCH_REJECTED_CODEX_QUEUE_FULL,
|
|
DISPATCH_REJECTED_QUEUE_FULL,
|
|
DISPATCH_REJECTED_WRITE_FAILED
|
|
} from './structured-agent-session-dispatch-rejection'
|
|
|
|
declare const failureSentence: unique symbol
|
|
|
|
/** Words only `agentSessionFailureWords` makes, so no writer can put its own beside a fact. */
|
|
export type AgentSessionFailureSentence = string & { readonly [failureSentence]: true }
|
|
|
|
/** A status row that reports a failure. */
|
|
export type AgentSessionFailureRowWords = {
|
|
text: AgentSessionFailureSentence
|
|
failure: AgentSessionFailureFact
|
|
}
|
|
|
|
/** A rejection as the host writes it: the sentence (or, for the cases released clients already
|
|
* hide, the legacy marker) they print, and the fact newer ones read. */
|
|
export type AgentJournalDispatchRejection = {
|
|
reason: AgentSessionFailureSentence
|
|
rejection: SubmissionRejectionFact
|
|
}
|
|
|
|
/** `row`: a status row, about the chat. `rejection`: a rejected message's reason, about it. */
|
|
export type AgentSessionFailureSurface = 'row' | 'rejection'
|
|
|
|
export type AgentSessionFailureWordsContext = {
|
|
/** The chat's agent, when the writer knows it. */
|
|
agentName?: string
|
|
/** Names the legacy queue-full marker; without it a full queue is worded as a sentence. */
|
|
provider?: 'claude' | 'codex'
|
|
/** The conversation command a failed start was for, so the next step is to run it again
|
|
* rather than to send a message. */
|
|
command?: AgentSessionConversationCommand
|
|
/** The surface retries for the person — its own Retry beside the words, or a read that reconnects
|
|
* on its own — so they leave out sending or trying again. */
|
|
retryControl?: boolean
|
|
/** A direct create has no submitted message to send again. */
|
|
messageSubmitted?: boolean
|
|
}
|
|
|
|
/**
|
|
* Whether a refused start leaves the chat anything to start again from. `false`: this host has
|
|
* nothing to restart it from — no record, or none it can run — so only a new chat continues.
|
|
* A new wire code does not compile until it is classified here.
|
|
*/
|
|
export const START_REFUSAL_RESUMABLE: Record<AgentSessionWireRefusalCode, boolean> = {
|
|
execution_owner_reconciling: true,
|
|
agent_session_conflict: true,
|
|
agent_session_checkpoint_stale: true,
|
|
agent_session_ownership_unknown: true,
|
|
agent_session_operation_capacity: true,
|
|
structured_agent_session_unsupported: false,
|
|
agent_session_operation_conflict: true,
|
|
agent_session_operation_expired: true,
|
|
agent_session_operation_invalid: true,
|
|
agent_session_operation_unknown: true,
|
|
agent_session_item_revision_stale: true,
|
|
agent_session_already_resolved: true,
|
|
agent_session_identity_required: false,
|
|
agent_session_journal_unreadable: true,
|
|
agent_session_owner_restart_failed: true
|
|
}
|
|
|
|
/** Person-facing provider text is quoted, but bounded so the sentence stays one. */
|
|
const MAX_QUOTED_DETAIL_CHARS = 512
|
|
const BYTES_PER_MB = 1024 * 1024
|
|
|
|
type Sentence = (
|
|
context: AgentSessionFailureWordsContext,
|
|
fact: AgentSessionFailureFact,
|
|
surface: AgentSessionFailureSurface,
|
|
say: AgentSessionFailureSay
|
|
) => string
|
|
|
|
function agent(say: AgentSessionFailureSay, { agentName }: AgentSessionFailureWordsContext) {
|
|
return { agent: agentName ?? say('theAgent') }
|
|
}
|
|
|
|
function quotingPersonDetail(
|
|
say: AgentSessionFailureSay,
|
|
lead: AgentSessionFailureCopyId,
|
|
quotedLead: AgentSessionFailureCopyId,
|
|
detail: ProviderDiagnostic | undefined,
|
|
values: AgentSessionFailureCopyValues = {}
|
|
): string {
|
|
const quoted =
|
|
detail?.audience === 'person'
|
|
? detail.text
|
|
.slice(0, MAX_QUOTED_DETAIL_CHARS)
|
|
.trim()
|
|
.replace(/[.\s]+$/, '')
|
|
: ''
|
|
return quoted ? say(quotedLead, { ...values, detail: quoted }) : say(lead, values)
|
|
}
|
|
|
|
/** The next step after a start or restart that failed: the command, or the message, again. */
|
|
function startRetry(
|
|
say: AgentSessionFailureSay,
|
|
{ command, retryControl, messageSubmitted }: AgentSessionFailureWordsContext,
|
|
sendAgain: 'sendToTryAgain' | 'sendAgainToTryOnceMore' = 'sendToTryAgain'
|
|
): string[] {
|
|
if (retryControl) {
|
|
return []
|
|
}
|
|
return [
|
|
command
|
|
? say('runCommandAgain', { command })
|
|
: say(messageSubmitted === false ? 'sendToTryAgain' : sendAgain)
|
|
]
|
|
}
|
|
|
|
function couldNot(verb: 'couldNotStart' | 'couldNotRestart'): Sentence {
|
|
return (context, fact, _surface, say) => {
|
|
const failed = say(verb, agent(say, context))
|
|
if (fact.argumentProblem) {
|
|
const problemCopy = {
|
|
unsupportedOption: 'argumentsUnsupportedOption',
|
|
missingValue: 'argumentsMissingValue',
|
|
multipleValues: 'argumentsMultipleValues',
|
|
positionalPrompt: 'argumentsPositionalPrompt'
|
|
} as const
|
|
return joinSentences([
|
|
failed,
|
|
say(problemCopy[fact.argumentProblem.problem], { option: fact.argumentProblem.option }),
|
|
say('editSavedArguments'),
|
|
...startRetry(say, context)
|
|
])
|
|
}
|
|
// Only a terminal agent an older build recorded holds a claim; quitting it frees the chat.
|
|
if (fact.refusal?.details?.reason === 'claimConflicted') {
|
|
return joinSentences([failed, say('terminalAgentHoldsChat'), say('quitTerminalAgent')])
|
|
}
|
|
// The previous process may still run, so nothing started: that, never that it exited.
|
|
if (fact.refusal?.details?.reason === 'previousExitUnverifiable') {
|
|
return joinSentences([
|
|
say('previousExitUnverifiable', agent(say, context)),
|
|
...startRetry(say, context, 'sendAgainToTryOnceMore')
|
|
])
|
|
}
|
|
const code = fact.refusal?.code
|
|
return joinSentences(
|
|
code && !START_REFUSAL_RESUMABLE[code]
|
|
? [failed, say('startNewChat')]
|
|
: [failed, ...startRetry(say, context)]
|
|
)
|
|
}
|
|
}
|
|
|
|
// The number only; each language's sentence carries its own unit.
|
|
function megabytes(bytes: number): string {
|
|
return String(Math.round((bytes / BYTES_PER_MB) * 10) / 10)
|
|
}
|
|
|
|
const ATTACHMENT_SENTENCES = {
|
|
empty: (say) => say('attachmentEmpty'),
|
|
tooLarge: (say, _, { limit }) =>
|
|
limit ? say('attachmentLargerThan', { size: megabytes(limit) }) : say('attachmentTooLarge'),
|
|
tooMany: (say, context, { limit }) =>
|
|
limit
|
|
? say('attachmentAtMost', { ...agent(say, context), limit: String(limit) })
|
|
: say('attachmentTooMany'),
|
|
totalTooLarge: (say, _, { limit }) =>
|
|
limit
|
|
? say('attachmentTotalMoreThan', { size: megabytes(limit) })
|
|
: say('attachmentTotalTooLarge'),
|
|
unsupportedType: (say, context) => say('attachmentUnsupportedType', agent(say, context)),
|
|
notAFile: (say) => say('attachmentNotAFile'),
|
|
noSource: (say) => say('attachmentNoSource')
|
|
} satisfies Record<
|
|
AgentSessionAttachmentProblemReason,
|
|
(
|
|
say: AgentSessionFailureSay,
|
|
context: AgentSessionFailureWordsContext,
|
|
problem: AgentSessionAttachmentProblem
|
|
) => string
|
|
>
|
|
|
|
const FAILURE_SENTENCES = {
|
|
providerStartFailed: (context, _fact, _surface, say) =>
|
|
joinSentences([say('providerStartFailed', agent(say, context)), ...startRetry(say, context)]),
|
|
startFailed: couldNot('couldNotStart'),
|
|
notSignedIn: (context, fact, surface, say) => notSignedInSentence(context, fact, say, surface),
|
|
cliMissing: (context, _fact, _surface, say) => cliMissingSentence(context, say),
|
|
historyTooLarge: (_context, _fact, _surface, say) =>
|
|
joinSentences([say('historyTooLarge'), say('startNewChat')]),
|
|
managedAccountEnvOverride: (_context, _fact, _surface, say) => say('managedAccountEnvOverride'),
|
|
accountSwitchInProgress: (_context, _fact, _surface, say) => say('accountSwitchInProgress'),
|
|
launchFolderMissing: (_context, _fact, _surface, say) => say('launchFolderMissing'),
|
|
historyInOtherAccount: (_context, _fact, _surface, say) => say('historyInOtherAccount'),
|
|
claudeAccountFolderMissing: (_context, _fact, _surface, say) => say('claudeAccountFolderMissing'),
|
|
claudeAccountSetupFailed: (_context, _fact, _surface, say) => say('claudeAccountSetupFailed'),
|
|
agentCommandNotRunnable: (context, _fact, _surface, say) =>
|
|
say('agentCommandNotRunnable', agent(say, context)),
|
|
managedAccountUnsupported: (context, _fact, _surface, say) =>
|
|
joinSentences([
|
|
say('managedAccountUnsupported'),
|
|
context.retryControl || context.messageSubmitted === false
|
|
? say('chooseClaudeAccount')
|
|
: context.command
|
|
? say('chooseClaudeAccountThenRunCommand', { command: context.command })
|
|
: say('chooseClaudeAccountThenSend')
|
|
]),
|
|
providerExited: (context, _fact, surface, say) =>
|
|
say(surface === 'row' ? 'providerExitedRow' : 'providerExitedRejection', agent(say, context)),
|
|
restartFailed: couldNot('couldNotRestart'),
|
|
providerRejected: (_context, fact, _surface, say) =>
|
|
quotingPersonDetail(say, 'providerRejected', 'providerRejectedQuoted', fact.detail),
|
|
attachmentInvalid: (context, fact, _surface, say) =>
|
|
fact.attachment
|
|
? ATTACHMENT_SENTENCES[fact.attachment.reason](say, context, fact.attachment)
|
|
: say('attachmentInvalid'),
|
|
attachmentUnreadable: (_context, _fact, _surface, say) => say('attachmentUnreadable'),
|
|
emptyMessage: (_context, _fact, _surface, say) => say('emptyMessage'),
|
|
queueFull: (_context, _fact, _surface, say) => say('queueFull'),
|
|
writeFailed: (_context, _fact, _surface, say) => say('writeFailed'),
|
|
cancelled: (_context, _fact, _surface, say) => say('cancelled'),
|
|
chatClosed: (_context, _fact, _surface, say) => say('chatClosed'),
|
|
hostRestarted: (_context, _fact, _surface, say) => say('hostRestarted'),
|
|
notDelivered: ({ retryControl }, _fact, _surface, say) =>
|
|
say(retryControl ? 'notDelivered' : 'notDeliveredSendAgain'),
|
|
commandRefused: (context, fact, _surface, say) =>
|
|
commandRefusedByReason(say, context, fact) ??
|
|
say(context.retryControl ? 'commandRefused' : 'commandRefusedTryAgain'),
|
|
compactionFailed: (_context, fact, _surface, say) =>
|
|
quotingPersonDetail(say, 'compactionFailed', 'compactionFailedQuoted', fact.detail),
|
|
compactionUnconfirmed: (_context, _fact, _surface, say) => say('compactionUnconfirmed'),
|
|
cancelUnconfirmed: (_context, _fact, _surface, say) => say('cancelUnconfirmed'),
|
|
// The agent was reached and declined, so the sentence says that, not that the Stop was lost.
|
|
stopRefused: (context, fact, _surface, say) =>
|
|
fact.detail?.audience === 'person'
|
|
? quotingPersonDetail(
|
|
say,
|
|
'stopRefused',
|
|
'stopRefusedQuoted',
|
|
fact.detail,
|
|
agent(say, context)
|
|
)
|
|
: say('noTurnToStop', agent(say, context)),
|
|
answerUnconfirmed: (_context, _fact, _surface, say) => say('answerUnconfirmed'),
|
|
hostFault: ({ retryControl }, _fact, _surface, say) =>
|
|
say(retryControl ? 'hostFault' : 'hostFaultTryAgain'),
|
|
hostStopped: (context, _fact, _surface, say) => say('hostStopped', agent(say, context)),
|
|
// A provider that says how its retry is going, for a person, is quoted: that is the progress.
|
|
providerRetrying: (context, { retry, detail }, _surface, say) =>
|
|
detail?.audience === 'person'
|
|
? withRetryCause(
|
|
quotingPersonDetail(
|
|
say,
|
|
'providerRetrying',
|
|
'providerRetryingQuoted',
|
|
detail,
|
|
agent(say, context)
|
|
),
|
|
retry?.cause
|
|
)
|
|
: providerRetryWords(say, agent(say, context), retry),
|
|
previousExitUnverifiable: (context, _fact, _surface, say) =>
|
|
say('previousExitUnverifiable', agent(say, context)),
|
|
sessionNotRestored: (context, _fact, _surface, say) =>
|
|
say('sessionNotRestored', agent(say, context))
|
|
} satisfies Record<AgentSessionFailureKind, Sentence>
|
|
|
|
/** The sentence a person reads for this fact on this surface; never a marker. */
|
|
export function agentSessionFailureSentence(
|
|
fact: AgentSessionFailureFact,
|
|
surface: AgentSessionFailureSurface,
|
|
context: AgentSessionFailureWordsContext = {},
|
|
/** Desktop passes its translations; the host and the phone keep English. */
|
|
say: AgentSessionFailureSay = sayAgentSessionFailureEnglish
|
|
): string {
|
|
const sentence: Sentence = FAILURE_SENTENCES[fact.kind]
|
|
return sentence(context, fact, surface, say)
|
|
}
|
|
|
|
/** The markers released clients hide, for the rejections that had one before rows carried a fact.
|
|
* A write failure is the bare marker: its error belongs in the log. */
|
|
const LEGACY_REJECTION_MARKERS: Partial<
|
|
Record<SubmissionRejectionKind, (context: AgentSessionFailureWordsContext) => string | undefined>
|
|
> = {
|
|
cancelled: () => DISPATCH_REJECTED_CANCELLED,
|
|
writeFailed: () => DISPATCH_REJECTED_WRITE_FAILED,
|
|
queueFull: ({ provider }) =>
|
|
provider === 'codex'
|
|
? DISPATCH_REJECTED_CODEX_QUEUE_FULL
|
|
: provider === 'claude'
|
|
? DISPATCH_REJECTED_QUEUE_FULL
|
|
: undefined
|
|
}
|
|
|
|
/** The words a status row reporting this fact records. */
|
|
export function agentSessionFailureWords(
|
|
fact: AgentSessionFailureFact,
|
|
context: AgentSessionFailureWordsContext & { surface: 'row' }
|
|
): AgentSessionFailureRowWords
|
|
/** The words a message rejected for this fact records. */
|
|
export function agentSessionFailureWords(
|
|
fact: SubmissionRejectionFact,
|
|
context: AgentSessionFailureWordsContext & { surface: 'rejection' }
|
|
): AgentJournalDispatchRejection
|
|
export function agentSessionFailureWords(
|
|
fact: AgentSessionFailureFact,
|
|
context: AgentSessionFailureWordsContext & { surface: AgentSessionFailureSurface }
|
|
): AgentSessionFailureRowWords | AgentJournalDispatchRejection {
|
|
if (context.surface === 'row') {
|
|
return { text: branded(agentSessionFailureSentence(fact, 'row', context)), failure: fact }
|
|
}
|
|
// The rejection overload admits only these; a caller that got past the types is Orca's bug.
|
|
if (!isSubmissionRejectionFact(fact)) {
|
|
throw new Error(`agent session failure kind ${fact.kind} cannot reject a message`)
|
|
}
|
|
const words =
|
|
LEGACY_REJECTION_MARKERS[fact.kind]?.(context) ??
|
|
agentSessionFailureSentence(fact, 'rejection', context)
|
|
return { reason: branded(words), rejection: fact }
|
|
}
|
|
|
|
function branded(words: string): AgentSessionFailureSentence {
|
|
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: only `agentSessionFailureWords` calls this, with words from the table or a legacy marker for its fact.
|
|
return words as AgentSessionFailureSentence
|
|
}
|