Fix Command Code smart-sort bump on new prompt while working (STA-350) (#5286)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -156,6 +156,8 @@ export type AgentStatusEntry = {
|
||||
/** Provider-owned conversation/session id captured from hook payloads.
|
||||
* Used only for exact CLI resume; Orca terminal ids are not agent-session ids. */
|
||||
providerSession?: AgentProviderSessionMetadata
|
||||
/** Live-only Command Code turn boundary key; not persisted to last-status.json. */
|
||||
promptInteractionKey?: string
|
||||
}
|
||||
|
||||
export type MigrationUnsupportedPtyEntry = {
|
||||
@@ -222,6 +224,8 @@ export type AgentStatusIpcPayload = ParsedAgentStatusPayload & {
|
||||
stateStartedAt: number
|
||||
orchestration?: AgentStatusOrchestrationContext
|
||||
providerSession?: AgentProviderSessionMetadata
|
||||
/** Live-only Command Code turn boundary key; not persisted to last-status.json. */
|
||||
promptInteractionKey?: string
|
||||
}
|
||||
|
||||
/** Maximum character length for the toolName field. */
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isCommandCodeNewTurnWhileWorking } from './command-code-turn-boundary'
|
||||
|
||||
describe('isCommandCodeNewTurnWhileWorking', () => {
|
||||
it('returns true when Command Code gets a new transcript prompt while still working', () => {
|
||||
expect(
|
||||
isCommandCodeNewTurnWhileWorking({
|
||||
agentType: 'command-code',
|
||||
previousState: 'working',
|
||||
incomingState: 'working',
|
||||
previousPrompt: 'first task',
|
||||
incomingPrompt: 'second task',
|
||||
hasExplicitPrompt: true
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true when the prompt interaction key changes', () => {
|
||||
expect(
|
||||
isCommandCodeNewTurnWhileWorking({
|
||||
agentType: 'command-code',
|
||||
previousState: 'working',
|
||||
incomingState: 'working',
|
||||
previousPrompt: 'same text',
|
||||
incomingPrompt: 'same text',
|
||||
hasExplicitPrompt: true,
|
||||
previousPromptInteractionKey: 'command-code-transcript-a',
|
||||
incomingPromptInteractionKey: 'command-code-transcript-b'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false for same-turn tool pings that keep the same prompt', () => {
|
||||
expect(
|
||||
isCommandCodeNewTurnWhileWorking({
|
||||
agentType: 'command-code',
|
||||
previousState: 'working',
|
||||
incomingState: 'working',
|
||||
previousPrompt: 'run pwd',
|
||||
incomingPrompt: 'run pwd',
|
||||
hasExplicitPrompt: true
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when main-process hooks explicitly deny prompt evidence', () => {
|
||||
expect(
|
||||
isCommandCodeNewTurnWhileWorking({
|
||||
agentType: 'command-code',
|
||||
previousState: 'working',
|
||||
incomingState: 'working',
|
||||
previousPrompt: 'first',
|
||||
incomingPrompt: 'second',
|
||||
hasExplicitPrompt: false
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for non-Command Code agents', () => {
|
||||
expect(
|
||||
isCommandCodeNewTurnWhileWorking({
|
||||
agentType: 'codex',
|
||||
previousState: 'working',
|
||||
incomingState: 'working',
|
||||
previousPrompt: 'first',
|
||||
incomingPrompt: 'second',
|
||||
hasExplicitPrompt: true
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { AgentType } from './agent-status-types'
|
||||
|
||||
type CommandCodeTurnBoundaryInput = {
|
||||
agentType: AgentType | undefined
|
||||
previousState?: string
|
||||
incomingState: string
|
||||
previousPrompt?: string
|
||||
incomingPrompt: string
|
||||
hasExplicitPrompt?: boolean
|
||||
previousPromptInteractionKey?: string
|
||||
incomingPromptInteractionKey?: string
|
||||
}
|
||||
|
||||
/** Command Code has no UserPromptSubmit hook; a new transcript prompt is the turn boundary. */
|
||||
export function isCommandCodeNewTurnWhileWorking({
|
||||
agentType,
|
||||
previousState,
|
||||
incomingState,
|
||||
previousPrompt,
|
||||
incomingPrompt,
|
||||
hasExplicitPrompt,
|
||||
previousPromptInteractionKey,
|
||||
incomingPromptInteractionKey
|
||||
}: CommandCodeTurnBoundaryInput): boolean {
|
||||
if (agentType !== 'command-code') {
|
||||
return false
|
||||
}
|
||||
if (previousState !== 'working' || incomingState !== 'working') {
|
||||
return false
|
||||
}
|
||||
|
||||
const nextPrompt = incomingPrompt.trim()
|
||||
if (nextPrompt.length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (
|
||||
incomingPromptInteractionKey !== undefined &&
|
||||
previousPromptInteractionKey !== undefined &&
|
||||
incomingPromptInteractionKey !== previousPromptInteractionKey
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (nextPrompt === (previousPrompt ?? '').trim()) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Main-process hooks can require explicit prompt evidence; renderer IPC does
|
||||
// not carry the flag yet, so a prompt text change is enough there.
|
||||
if (hasExplicitPrompt === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user