mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat(codex): preserve native exploration actions (#1139)
This commit is contained in:
@@ -132,27 +132,49 @@ describe('AppServerEventConverter', () => {
|
||||
|
||||
it('maps command execution items and output deltas', () => {
|
||||
const converter = new AppServerEventConverter();
|
||||
const commandActions = [{
|
||||
type: 'listFiles',
|
||||
command: 'ls',
|
||||
path: '.'
|
||||
}];
|
||||
|
||||
const started = converter.handleNotification('item/started', {
|
||||
item: { id: 'cmd-1', type: 'commandExecution', command: 'ls' }
|
||||
item: {
|
||||
id: 'cmd-1',
|
||||
type: 'commandExecution',
|
||||
command: 'ls',
|
||||
source: 'agent',
|
||||
commandActions
|
||||
}
|
||||
});
|
||||
expect(started).toEqual([{
|
||||
type: 'exec_command_begin',
|
||||
call_id: 'cmd-1',
|
||||
command: 'ls'
|
||||
command: 'ls',
|
||||
command_actions: commandActions,
|
||||
command_source: 'agent'
|
||||
}]);
|
||||
|
||||
converter.handleNotification('item/commandExecution/outputDelta', { itemId: 'cmd-1', delta: 'ok' });
|
||||
const completed = converter.handleNotification('item/completed', {
|
||||
item: { id: 'cmd-1', type: 'commandExecution', exitCode: 0 }
|
||||
item: {
|
||||
id: 'cmd-1',
|
||||
type: 'commandExecution',
|
||||
aggregatedOutput: 'final output',
|
||||
exitCode: 0,
|
||||
durationMs: 42
|
||||
}
|
||||
});
|
||||
|
||||
expect(completed).toEqual([{
|
||||
type: 'exec_command_end',
|
||||
call_id: 'cmd-1',
|
||||
command: 'ls',
|
||||
output: 'ok',
|
||||
exit_code: 0
|
||||
command_actions: commandActions,
|
||||
command_source: 'agent',
|
||||
output: 'final output',
|
||||
exit_code: 0,
|
||||
duration_ms: 42
|
||||
}]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1022,10 +1022,18 @@ export class AppServerEventConverter {
|
||||
const command = extractCommand(item.command ?? item.cmd ?? item.args);
|
||||
const cwd = asString(item.cwd ?? item.workingDirectory ?? item.working_directory);
|
||||
const autoApproved = asBoolean(item.autoApproved ?? item.auto_approved);
|
||||
const commandActions = Array.isArray(item.commandActions)
|
||||
? item.commandActions
|
||||
: Array.isArray(item.command_actions)
|
||||
? item.command_actions
|
||||
: null;
|
||||
const source = asString(item.source);
|
||||
const meta: Record<string, unknown> = {};
|
||||
if (command) meta.command = command;
|
||||
if (cwd) meta.cwd = cwd;
|
||||
if (autoApproved !== null) meta.auto_approved = autoApproved;
|
||||
if (commandActions) meta.command_actions = commandActions;
|
||||
if (source) meta.command_source = source;
|
||||
this.commandMeta.set(itemId, meta);
|
||||
|
||||
events.push(scoped({
|
||||
@@ -1037,10 +1045,12 @@ export class AppServerEventConverter {
|
||||
|
||||
if (method === 'item/completed') {
|
||||
const meta = this.commandMeta.get(itemId) ?? {};
|
||||
const output = asString(item.output ?? item.result ?? item.stdout) ?? this.commandOutputBuffers.get(itemId);
|
||||
const output = asString(item.aggregatedOutput ?? item.aggregated_output ?? item.output ?? item.result ?? item.stdout)
|
||||
?? this.commandOutputBuffers.get(itemId);
|
||||
const stderr = asString(item.stderr);
|
||||
const error = asString(item.error);
|
||||
const exitCode = asNumber(item.exitCode ?? item.exit_code ?? item.exitcode);
|
||||
const durationMs = asNumber(item.durationMs ?? item.duration_ms);
|
||||
const status = asString(item.status);
|
||||
|
||||
events.push(scoped({
|
||||
@@ -1051,6 +1061,7 @@ export class AppServerEventConverter {
|
||||
...(stderr ? { stderr } : {}),
|
||||
...(error ? { error } : {}),
|
||||
...(exitCode !== null ? { exit_code: exitCode } : {}),
|
||||
...(durationMs !== null ? { duration_ms: durationMs } : {}),
|
||||
...(status ? { status } : {})
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user