mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
chore(telemetry): track conversation undo, shell mode, and effort changes (#1271)
* chore(telemetry): track conversation undo, shell mode, and effort changes
- conversation_undo: fires when an undo reverts history (double-Esc selector, /undo, /undo N)
- shell_command: fires when a ! shell command runs in the TUI
- thinking_toggle: now fires on any effort change (not just on/off flips) and carries { enabled, effort, from }; align the no-session TUI path to the same payload
* chore(telemetry): track conversation_undo in core undoHistory
Tracking it in the TUI only covered the TUI; web/acp/REST undos reach
core.rpc.undoHistory directly and were missed. Emit the event from the
agent undoHistory RPC after the undo succeeds so every host is covered,
and drop the now-redundant TUI track.
Addresses review feedback on #1271.
This commit is contained in:
parent
c070fbedde
commit
3cb7936cf5
6 changed files with 36 additions and 7 deletions
|
|
@ -422,7 +422,11 @@ async function performModelSwitch(
|
|||
host.track('model_switch', { model: alias });
|
||||
}
|
||||
if (effort !== prevEffort) {
|
||||
host.track('thinking_toggle', { effort });
|
||||
host.track('thinking_toggle', {
|
||||
enabled: effort !== 'off',
|
||||
effort,
|
||||
from: prevEffort,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -955,6 +955,8 @@ export class KimiTUI {
|
|||
this.setAppState({ streamingPhase: 'shell' });
|
||||
this.state.ui.requestRender();
|
||||
|
||||
this.track('shell_command');
|
||||
|
||||
void session.runShellCommand(command, { commandId }).then(
|
||||
({ stdout, stderr, isError, backgrounded }) => {
|
||||
this.finishShellOutput(commandId, stdout, stderr, isError, backgrounded);
|
||||
|
|
|
|||
|
|
@ -1766,13 +1766,15 @@ command = "vim"
|
|||
it('echoes a bash command with a $ prompt in the transcript', async () => {
|
||||
const runShellCommand = vi.fn(async () => ({ stdout: '', stderr: '', isError: false }));
|
||||
const session = makeSession({ runShellCommand });
|
||||
const { driver } = await makeDriver(session);
|
||||
const { driver, harness } = await makeDriver(session);
|
||||
driver.state.appState.inputMode = 'bash';
|
||||
driver.state.editor.inputMode = 'bash';
|
||||
|
||||
driver.handleUserInput('ls');
|
||||
await Promise.resolve();
|
||||
|
||||
expect(harness.track).toHaveBeenCalledWith('shell_command', undefined);
|
||||
|
||||
const transcript = stripSgr(driver.state.transcriptContainer.render(120).join('\n'));
|
||||
expect(transcript).toContain('$ ls');
|
||||
expect(transcript).not.toContain('! ls');
|
||||
|
|
|
|||
|
|
@ -344,13 +344,18 @@ export class Agent {
|
|||
},
|
||||
undoHistory: (payload) => {
|
||||
this.context.undo(payload.count);
|
||||
this.telemetry.track('conversation_undo', { count: payload.count });
|
||||
},
|
||||
setThinking: (payload) => {
|
||||
const wasEnabled = this.config.thinkingEffort !== 'off';
|
||||
const previousEffort = this.config.thinkingEffort;
|
||||
this.config.update({ thinkingEffort: payload.effort });
|
||||
const enabled = this.config.thinkingEffort !== 'off';
|
||||
if (enabled !== wasEnabled) {
|
||||
this.telemetry.track('thinking_toggle', { enabled });
|
||||
const effort = this.config.thinkingEffort;
|
||||
if (effort !== previousEffort) {
|
||||
this.telemetry.track('thinking_toggle', {
|
||||
enabled: effort !== 'off',
|
||||
effort,
|
||||
from: previousEffort,
|
||||
});
|
||||
}
|
||||
},
|
||||
setPermission: (payload) => {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { project } from '../../src/agent/context/projector';
|
|||
import type { ContextMessage } from '../../src/agent/context/types';
|
||||
import { estimateTokensForMessages } from '../../src/utils/tokens';
|
||||
import { createFakeKaos } from '../tools/fixtures/fake-kaos';
|
||||
import { recordingTelemetry, type TelemetryRecord } from '../fixtures/telemetry';
|
||||
import { testAgent } from './harness/agent';
|
||||
|
||||
describe('Agent context', () => {
|
||||
|
|
@ -58,6 +59,21 @@ describe('Agent context', () => {
|
|||
expect(ctx.agent.context.messages.some((message) => 'origin' in message)).toBe(false);
|
||||
});
|
||||
|
||||
it('tracks conversation_undo when undoHistory reverts a user message', async () => {
|
||||
const records: TelemetryRecord[] = [];
|
||||
const ctx = testAgent({ telemetry: recordingTelemetry(records) });
|
||||
ctx.configure();
|
||||
|
||||
ctx.agent.context.appendUserMessage([{ type: 'text', text: 'hello' }]);
|
||||
|
||||
await ctx.agent.rpcMethods.undoHistory({ count: 1 });
|
||||
|
||||
expect(records).toContainEqual({
|
||||
event: 'conversation_undo',
|
||||
properties: { count: 1 },
|
||||
});
|
||||
});
|
||||
|
||||
it('records bash input/output as shell_command origin with tagged content', () => {
|
||||
const ctx = testAgent();
|
||||
ctx.configure();
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ max_context_size = 1000000
|
|||
expect(resumeRecords).toContainEqual({
|
||||
event: 'thinking_toggle',
|
||||
sessionId: created.id,
|
||||
properties: { enabled: false },
|
||||
properties: { enabled: false, effort: 'off', from: 'high' },
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue