mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-30 06:17:06 +00:00
remove codex mcp backend
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildCodexStartConfig } from './codexStartConfig';
|
||||
import { codexSystemPrompt } from './systemPrompt';
|
||||
|
||||
describe('buildCodexStartConfig', () => {
|
||||
const mcpServers = { hapi: { command: 'node', args: ['mcp'] } };
|
||||
|
||||
it('applies CLI overrides when permission mode is default', () => {
|
||||
const config = buildCodexStartConfig({
|
||||
message: 'hello',
|
||||
mode: { permissionMode: 'default', collaborationMode: 'default' },
|
||||
first: true,
|
||||
mcpServers,
|
||||
cliOverrides: { sandbox: 'danger-full-access', approvalPolicy: 'never' }
|
||||
});
|
||||
|
||||
expect(config.sandbox).toBe('danger-full-access');
|
||||
expect(config['approval-policy']).toBe('never');
|
||||
expect(config.config).toEqual({
|
||||
mcp_servers: mcpServers,
|
||||
developer_instructions: codexSystemPrompt
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores CLI overrides when permission mode is not default', () => {
|
||||
const config = buildCodexStartConfig({
|
||||
message: 'hello',
|
||||
mode: { permissionMode: 'yolo', collaborationMode: 'default' },
|
||||
first: false,
|
||||
mcpServers,
|
||||
cliOverrides: { sandbox: 'read-only', approvalPolicy: 'never' }
|
||||
});
|
||||
|
||||
expect(config.sandbox).toBe('danger-full-access');
|
||||
expect(config['approval-policy']).toBe('never');
|
||||
});
|
||||
|
||||
it('keeps on-failure approvals for safe-yolo', () => {
|
||||
const config = buildCodexStartConfig({
|
||||
message: 'hello',
|
||||
mode: { permissionMode: 'safe-yolo', collaborationMode: 'default' },
|
||||
first: false,
|
||||
mcpServers
|
||||
});
|
||||
|
||||
expect(config.sandbox).toBe('workspace-write');
|
||||
expect(config['approval-policy']).toBe('on-failure');
|
||||
});
|
||||
|
||||
it('passes model when provided', () => {
|
||||
const config = buildCodexStartConfig({
|
||||
message: 'hello',
|
||||
mode: { permissionMode: 'default', model: 'o3', collaborationMode: 'default' },
|
||||
first: false,
|
||||
mcpServers
|
||||
});
|
||||
|
||||
expect(config.model).toBe('o3');
|
||||
});
|
||||
});
|
||||
@@ -1,50 +0,0 @@
|
||||
import type { CodexSessionConfig } from '../types';
|
||||
import type { EnhancedMode } from '../loop';
|
||||
import type { CodexCliOverrides } from './codexCliOverrides';
|
||||
import { codexSystemPrompt } from './systemPrompt';
|
||||
import { resolveCodexPermissionModeConfig } from './permissionModeConfig';
|
||||
|
||||
function resolveApprovalPolicy(mode: EnhancedMode): CodexSessionConfig['approval-policy'] {
|
||||
return resolveCodexPermissionModeConfig(mode.permissionMode).approvalPolicy;
|
||||
}
|
||||
|
||||
function resolveSandbox(mode: EnhancedMode): CodexSessionConfig['sandbox'] {
|
||||
return resolveCodexPermissionModeConfig(mode.permissionMode).sandbox;
|
||||
}
|
||||
|
||||
export function buildCodexStartConfig(args: {
|
||||
message: string;
|
||||
mode: EnhancedMode;
|
||||
first: boolean;
|
||||
mcpServers: Record<string, { command: string; args: string[] }>;
|
||||
cliOverrides?: CodexCliOverrides;
|
||||
developerInstructions?: string;
|
||||
}): CodexSessionConfig {
|
||||
const approvalPolicy = resolveApprovalPolicy(args.mode);
|
||||
const sandbox = resolveSandbox(args.mode);
|
||||
const allowCliOverrides = args.mode.permissionMode === 'default';
|
||||
const cliOverrides = allowCliOverrides ? args.cliOverrides : undefined;
|
||||
const resolvedApprovalPolicy = cliOverrides?.approvalPolicy ?? approvalPolicy;
|
||||
const resolvedSandbox = cliOverrides?.sandbox ?? sandbox;
|
||||
|
||||
const prompt = args.message;
|
||||
const baseInstructions = codexSystemPrompt;
|
||||
const config: Record<string, unknown> = {
|
||||
mcp_servers: args.mcpServers,
|
||||
developer_instructions: args.developerInstructions
|
||||
? `${baseInstructions}\n\n${args.developerInstructions}`
|
||||
: baseInstructions
|
||||
};
|
||||
const startConfig: CodexSessionConfig = {
|
||||
prompt,
|
||||
sandbox: resolvedSandbox,
|
||||
'approval-policy': resolvedApprovalPolicy,
|
||||
config
|
||||
};
|
||||
|
||||
if (args.mode.model) {
|
||||
startConfig.model = args.mode.model;
|
||||
}
|
||||
|
||||
return startConfig;
|
||||
}
|
||||
@@ -2,20 +2,8 @@ import { describe, expect, it } from 'vitest';
|
||||
import { shouldIgnoreTerminalEvent } from './terminalEventGuard';
|
||||
|
||||
describe('shouldIgnoreTerminalEvent', () => {
|
||||
it('returns false for non app-server mode', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: false,
|
||||
eventTurnId: null,
|
||||
currentTurnId: 'turn-1',
|
||||
turnInFlight: true
|
||||
});
|
||||
|
||||
expect(ignored).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores terminal events without turn_id when current turn id exists', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: null,
|
||||
currentTurnId: 'turn-1',
|
||||
turnInFlight: true
|
||||
@@ -26,7 +14,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('ignores terminal events without turn_id while a turn is still in flight', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: null,
|
||||
currentTurnId: null,
|
||||
turnInFlight: true
|
||||
@@ -37,7 +24,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('accepts terminal events without turn_id when anonymous terminal is explicitly allowed', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: null,
|
||||
currentTurnId: null,
|
||||
turnInFlight: true,
|
||||
@@ -49,7 +35,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('still ignores terminal events without turn_id when current turn id exists', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: null,
|
||||
currentTurnId: 'turn-1',
|
||||
turnInFlight: true,
|
||||
@@ -61,7 +46,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('ignores stale terminal events from another turn', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: 'turn-old',
|
||||
currentTurnId: 'turn-current',
|
||||
turnInFlight: true
|
||||
@@ -72,7 +56,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('accepts terminal events that match the current turn id', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: 'turn-current',
|
||||
currentTurnId: 'turn-current',
|
||||
turnInFlight: true
|
||||
@@ -83,7 +66,6 @@ describe('shouldIgnoreTerminalEvent', () => {
|
||||
|
||||
it('accepts terminal events without turn_id when no turn is active', () => {
|
||||
const ignored = shouldIgnoreTerminalEvent({
|
||||
useAppServer: true,
|
||||
eventTurnId: null,
|
||||
currentTurnId: null,
|
||||
turnInFlight: false
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export type TerminalEventGuardInput = {
|
||||
useAppServer: boolean;
|
||||
eventTurnId: string | null;
|
||||
currentTurnId: string | null;
|
||||
turnInFlight: boolean;
|
||||
@@ -9,10 +8,6 @@ export type TerminalEventGuardInput = {
|
||||
export function shouldIgnoreTerminalEvent(input: TerminalEventGuardInput): boolean {
|
||||
const allowAnonymousTerminalEvent = input.allowAnonymousTerminalEvent === true;
|
||||
|
||||
if (!input.useAppServer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.eventTurnId) {
|
||||
return Boolean(input.currentTurnId && input.eventTurnId !== input.currentTurnId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user