Refactor PolicyEngine to Core Package (#12325)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Allen Hutchison
2025-11-03 15:41:00 -08:00
committed by GitHub
parent 60d2c2cc90
commit ffc5e4d048
35 changed files with 1357 additions and 2156 deletions

View File

@@ -13,11 +13,11 @@ import type {
} from './config.js';
import {
Config,
ApprovalMode,
DEFAULT_FILE_FILTERING_OPTIONS,
HookType,
HookEventName,
} from './config.js';
import { ApprovalMode } from '../policy/types.js';
import * as path from 'node:path';
import { setGeminiMdFilename as mockSetGeminiMdFilename } from '../tools/memoryTool.js';
import {

View File

@@ -78,11 +78,7 @@ import { AgentRegistry } from '../agents/registry.js';
import { setGlobalProxy } from '../utils/fetch.js';
import { SubagentToolWrapper } from '../agents/subagent-tool-wrapper.js';
export enum ApprovalMode {
DEFAULT = 'default',
AUTO_EDIT = 'autoEdit',
YOLO = 'yolo',
}
import { ApprovalMode } from '../policy/types.js';
export interface AccessibilitySettings {
disableLoadingPhrases?: boolean;
@@ -152,7 +148,7 @@ import {
DEFAULT_FILE_FILTERING_OPTIONS,
DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
} from './constants.js';
import { debugLogger } from '../utils/debugLogger.js';
import {
type ExtensionLoader,
SimpleExtensionLoader,
@@ -1243,19 +1239,11 @@ export class Config {
// This first implementation is only focused on the general case of
// the tool registry.
const messageBusEnabled = this.getEnableMessageBusIntegration();
if (this.debugMode && messageBusEnabled) {
debugLogger.log(
`[DEBUG] enableMessageBusIntegration setting: ${messageBusEnabled}`,
);
}
const toolArgs = messageBusEnabled
? [...args, this.getMessageBus()]
: args;
if (this.debugMode && messageBusEnabled) {
debugLogger.log(
`[DEBUG] Registering ${className} with messageBus: ${messageBusEnabled ? 'YES' : 'NO'}`,
);
}
registry.registerTool(new ToolClass(...toolArgs));
}
};

View File

@@ -58,6 +58,23 @@ export class Storage {
return path.join(Storage.getGlobalGeminiDir(), 'policies');
}
static getSystemSettingsPath(): string {
if (process.env['GEMINI_CLI_SYSTEM_SETTINGS_PATH']) {
return process.env['GEMINI_CLI_SYSTEM_SETTINGS_PATH'];
}
if (os.platform() === 'darwin') {
return '/Library/Application Support/GeminiCli/settings.json';
} else if (os.platform() === 'win32') {
return 'C:\\ProgramData\\gemini-cli\\settings.json';
} else {
return '/etc/gemini-cli/settings.json';
}
}
static getSystemPoliciesDir(): string {
return path.join(path.dirname(Storage.getSystemSettingsPath()), 'policies');
}
static getGlobalTempDir(): string {
return path.join(Storage.getGlobalGeminiDir(), TMP_DIR_NAME);
}