Skip to content

Commit ccaca5e

Browse files
committed
test(agent-status): cover Kimi compact guards and share harness helper
Address Greptile/CodeRabbit review on #11353: extract a shared shouldIgnoreHarnessInjectedUserPromptSubmit helper for Claude and Kimi, and add Kimi harness + PreCompact/PostCompact regression tests so the parallel path cannot drift.
1 parent 8346d7d commit ccaca5e

2 files changed

Lines changed: 85 additions & 9 deletions

File tree

‎src/shared/agent-hook-listener.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,76 @@ describe('shared agent-hook-listener', () => {
14521452
expect(stopped?.providerSession).toMatchObject({ key: 'session_id', id: 'session_abc' })
14531453
})
14541454

1455+
// Why: Kimi shares Claude-compatible compact/harness hooks; cover the same sticky-working
1456+
// guards so a Kimi-only regression cannot slip past the Claude-only tests (issue #11352).
1457+
it('ignores harness-injected UserPromptSubmit for Kimi', () => {
1458+
normalizeHookPayload(
1459+
state,
1460+
'kimi',
1461+
{
1462+
paneKey: PANE_KEY,
1463+
payload: {
1464+
hook_event_name: 'UserPromptSubmit',
1465+
prompt: [{ type: 'text', text: 'list the files here' }]
1466+
}
1467+
},
1468+
'production'
1469+
)
1470+
const harness = normalizeHookPayload(
1471+
state,
1472+
'kimi',
1473+
{
1474+
paneKey: PANE_KEY,
1475+
payload: {
1476+
hook_event_name: 'UserPromptSubmit',
1477+
prompt:
1478+
'This session is being continued from a previous conversation that ran out of context.'
1479+
}
1480+
},
1481+
'production'
1482+
)
1483+
expect(harness).toBeNull()
1484+
const tool = normalizeHookPayload(
1485+
state,
1486+
'kimi',
1487+
{
1488+
paneKey: PANE_KEY,
1489+
payload: {
1490+
hook_event_name: 'PreToolUse',
1491+
tool_name: 'Bash',
1492+
tool_input: { command: 'ls' }
1493+
}
1494+
},
1495+
'production'
1496+
)
1497+
expect(tool).not.toBeNull()
1498+
expect(tool!.payload.state).toBe('working')
1499+
expect(tool!.payload.prompt).toBe('list the files here')
1500+
expect(tool!.payload.agentType).toBe('kimi')
1501+
})
1502+
1503+
it('maps Kimi PreCompact to working and PostCompact to done (issue #11352)', () => {
1504+
const pre = normalizeHookPayload(
1505+
state,
1506+
'kimi',
1507+
{ paneKey: PANE_KEY, payload: { hook_event_name: 'PreCompact', trigger: 'manual' } },
1508+
'production'
1509+
)
1510+
expect(pre).not.toBeNull()
1511+
expect(pre!.payload.state).toBe('working')
1512+
expect(pre!.payload.agentType).toBe('kimi')
1513+
1514+
const post = normalizeHookPayload(
1515+
state,
1516+
'kimi',
1517+
{ paneKey: PANE_KEY, payload: { hook_event_name: 'PostCompact', trigger: 'manual' } },
1518+
'production'
1519+
)
1520+
expect(post).not.toBeNull()
1521+
expect(post!.payload.state).toBe('done')
1522+
expect(post!.payload.agentType).toBe('kimi')
1523+
})
1524+
14551525
it('normalizes MiMo Code OpenCode-compatible lifecycle events as mimo-code status', () => {
14561526
const message = normalizeHookPayload(
14571527
state,

‎src/shared/agent-hook-listener.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ function stripGrokUserQueryWrapper(promptText: string): string {
489489
return text.trim()
490490
}
491491

492+
// Why: harness-injected UserPromptSubmit (compact summary, task-notification envelopes,
493+
// system-reminders, local-command machinery) is not a real user turn. Emitting `working`
494+
// with no matching Stop left worktrees stuck on the spinner after /compact (issue #11352).
495+
// Shared by Claude and Kimi so the two Claude-compatible paths cannot drift on this bug class.
496+
function shouldIgnoreHarnessInjectedUserPromptSubmit(
497+
eventName: unknown,
498+
promptText: string
499+
): boolean {
500+
return eventName === 'UserPromptSubmit' && isKnownHarnessInjectedUserTurnText(promptText)
501+
}
502+
492503
function resolvePrompt(
493504
state: HookListenerState,
494505
paneKey: string,
@@ -2559,12 +2570,9 @@ function normalizeClaudeEvent(
25592570
return normalizeClaudeSubagentLifecycleEvent(state, eventName, paneKey, hookPayload)
25602571
}
25612572

2562-
// Why: harness-injected UserPromptSubmit (compact summary, task-notification envelopes,
2563-
// system-reminders, local-command machinery) is not a real user turn. Emitting `working`
2564-
// with no matching Stop left worktrees stuck on the spinner after /compact (issue #11352).
2565-
// Real tool activity still arrives as PreToolUse/PostToolUse; do not mint a working row
2566-
// from machinery alone. resolvePrompt already preserves the cached user prompt for labels.
2567-
if (eventName === 'UserPromptSubmit' && isKnownHarnessInjectedUserTurnText(promptText)) {
2573+
// Why: do not mint a working row from machinery alone; real tool activity still arrives as
2574+
// PreToolUse/PostToolUse. resolvePrompt already preserves the cached user prompt for labels.
2575+
if (shouldIgnoreHarnessInjectedUserPromptSubmit(eventName, promptText)) {
25682576
return null
25692577
}
25702578

@@ -2784,9 +2792,7 @@ function normalizeKimiEvent(
27842792
paneKey: string,
27852793
hookPayload: Record<string, unknown>
27862794
): ParsedAgentStatusPayload | null {
2787-
// Why: Kimi shares Claude's harness-injected UserPromptSubmit shapes; same sticky-working
2788-
// risk after compact/local-command machinery (issue #11352).
2789-
if (eventName === 'UserPromptSubmit' && isKnownHarnessInjectedUserTurnText(promptText)) {
2795+
if (shouldIgnoreHarnessInjectedUserPromptSubmit(eventName, promptText)) {
27902796
return null
27912797
}
27922798

0 commit comments

Comments
 (0)