mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
Disallow Object.create() and reflect. (#22408)
This commit is contained in:
committed by
GitHub
parent
e3df87cf1a
commit
ef5627eece
@@ -57,18 +57,8 @@ export async function scheduleAgentTools(
|
||||
} = options;
|
||||
|
||||
// Create a proxy/override of the config to provide the agent-specific tool registry.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const agentConfig: Config = Object.create(config);
|
||||
agentConfig.getToolRegistry = () => toolRegistry;
|
||||
agentConfig.getMessageBus = () => toolRegistry.messageBus;
|
||||
// Override toolRegistry property so AgentLoopContext reads the agent-specific registry.
|
||||
Object.defineProperty(agentConfig, 'toolRegistry', {
|
||||
get: () => toolRegistry,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const schedulerContext = {
|
||||
config: agentConfig,
|
||||
config,
|
||||
promptId: config.promptId,
|
||||
toolRegistry,
|
||||
messageBus: toolRegistry.messageBus,
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
} from '../tools/mcp-tool.js';
|
||||
import { CompressionStatus } from '../core/turn.js';
|
||||
import { type ToolCallRequestInfo } from '../scheduler/types.js';
|
||||
import { type Message } from '../confirmation-bus/types.js';
|
||||
import { ChatCompressionService } from '../services/chatCompressionService.js';
|
||||
import { getDirectoryContextString } from '../utils/environmentContext.js';
|
||||
import { promptIdContext } from '../utils/promptIdContext.js';
|
||||
@@ -128,19 +127,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
|
||||
const parentMessageBus = context.messageBus;
|
||||
|
||||
// Create an override object to inject the subagent name into tool confirmation requests
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const subagentMessageBus = Object.create(
|
||||
parentMessageBus,
|
||||
) as typeof parentMessageBus;
|
||||
subagentMessageBus.publish = async (message: Message) => {
|
||||
if (message.type === 'tool-confirmation-request') {
|
||||
return parentMessageBus.publish({
|
||||
...message,
|
||||
subagent: definition.name,
|
||||
});
|
||||
}
|
||||
return parentMessageBus.publish(message);
|
||||
};
|
||||
const subagentMessageBus = parentMessageBus.derive(definition.name);
|
||||
|
||||
// Create an isolated tool registry for this agent instance.
|
||||
const agentToolRegistry = new ToolRegistry(
|
||||
|
||||
@@ -520,23 +520,55 @@ export class AgentRegistry {
|
||||
return definition;
|
||||
}
|
||||
|
||||
// Use Object.create to preserve lazy getters on the definition object
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const merged: LocalAgentDefinition<TOutput> = Object.create(definition);
|
||||
|
||||
if (overrides.runConfig) {
|
||||
merged.runConfig = {
|
||||
...definition.runConfig,
|
||||
...overrides.runConfig,
|
||||
};
|
||||
}
|
||||
|
||||
if (overrides.modelConfig) {
|
||||
merged.modelConfig = ModelConfigService.merge(
|
||||
definition.modelConfig,
|
||||
overrides.modelConfig,
|
||||
);
|
||||
}
|
||||
// Preserve lazy getters on the definition object by wrapping in a new object with getters
|
||||
const merged: LocalAgentDefinition<TOutput> = {
|
||||
get kind() {
|
||||
return definition.kind;
|
||||
},
|
||||
get name() {
|
||||
return definition.name;
|
||||
},
|
||||
get displayName() {
|
||||
return definition.displayName;
|
||||
},
|
||||
get description() {
|
||||
return definition.description;
|
||||
},
|
||||
get experimental() {
|
||||
return definition.experimental;
|
||||
},
|
||||
get metadata() {
|
||||
return definition.metadata;
|
||||
},
|
||||
get inputConfig() {
|
||||
return definition.inputConfig;
|
||||
},
|
||||
get outputConfig() {
|
||||
return definition.outputConfig;
|
||||
},
|
||||
get promptConfig() {
|
||||
return definition.promptConfig;
|
||||
},
|
||||
get toolConfig() {
|
||||
return definition.toolConfig;
|
||||
},
|
||||
get processOutput() {
|
||||
return definition.processOutput;
|
||||
},
|
||||
get runConfig() {
|
||||
return overrides.runConfig
|
||||
? { ...definition.runConfig, ...overrides.runConfig }
|
||||
: definition.runConfig;
|
||||
},
|
||||
get modelConfig() {
|
||||
return overrides.modelConfig
|
||||
? ModelConfigService.merge(
|
||||
definition.modelConfig,
|
||||
overrides.modelConfig,
|
||||
)
|
||||
: definition.modelConfig;
|
||||
},
|
||||
};
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user