mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-26 22:51:47 +02:00
v1.87.0.0 feat: add verified CSO audits and replayable repair bundles (#2852)
* feat(cso): add verified audits and replayable repair bundles * fix(cso): harden qualification and setup boundaries * fix(cso): assemble security canaries at runtime * fix(cso): bound release proof and maintenance work Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): require complete evaluation reports Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): replay expired snapshots from supplied source Co-Authored-By: OpenAI Codex <noreply@openai.com> * test(cso): synchronize DNS cancellation assertion Co-Authored-By: OpenAI Codex <noreply@openai.com> * chore(ship): exempt repository owner from liveness proof Co-Authored-By: OpenAI Codex <noreply@openai.com> * test(cso): make recheck retention overlap deterministic Co-Authored-By: OpenAI Codex <noreply@openai.com> * chore: bump version and changelog (v1.85.0.0) Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): pass native release gates Co-Authored-By: OpenAI Codex <noreply@openai.com> * chore: move release to v1.86.0.0 Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): resolve rechecks by finding Co-Authored-By: OpenAI Codex <noreply@openai.com> * chore: move release to v1.87.0.0 Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): pass macOS and Windows release gates Normalize BSD wc output, compare Windows paths by filesystem identity, preserve portable snapshot race coverage, and narrow POSIX-only Windows fixtures. Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix(cso): harden native verification gates * fix(cso): refine Windows native diagnostics * test(cso): isolate Windows Git startup failure * test(cso): stabilize Windows native diagnostics * fix(cso): support hardened Git on Windows * fix(cso): close final verification gaps * test(cso): bound cold Docker fixture setup * fix(cso): restore cross-platform free-suite gates --------- Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
9f81911136
commit
4a3c6a8a3c
@@ -1,9 +1,22 @@
|
||||
import type { ProviderAdapter, RunOpts, RunResult, AvailabilityCheck } from './types';
|
||||
import {
|
||||
csoProducerChildEnvironment,
|
||||
csoProducerHelperHome,
|
||||
csoProducerHelperLauncher,
|
||||
csoProducerProviderCommand,
|
||||
csoProducerStateDirectory,
|
||||
validateCsoProducerStateDirectory,
|
||||
type ProviderAdapter,
|
||||
type RunOpts,
|
||||
type RunResult,
|
||||
type AvailabilityCheck,
|
||||
} from './types';
|
||||
import { estimateCostUsd } from '../pricing';
|
||||
import { execFileSync, spawnSync } from 'child_process';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { atomicWriteSync } from '../../../lib/fs-atomic';
|
||||
|
||||
export type GeminiStreamParse = {
|
||||
output: string;
|
||||
@@ -112,15 +125,16 @@ export class GeminiAdapter implements ProviderAdapter {
|
||||
readonly name = 'gemini';
|
||||
readonly family = 'gemini' as const;
|
||||
|
||||
async available(): Promise<AvailabilityCheck> {
|
||||
const res = spawnSync('sh', ['-c', 'command -v gemini'], { timeout: 2000 });
|
||||
async available(opts?: RunOpts): Promise<AvailabilityCheck> {
|
||||
const producerCommand = csoProducerProviderCommand(opts ?? { prompt: '', workdir: '/', timeoutMs: 1 });
|
||||
const res = producerCommand ? { status: 0 } : spawnSync('sh', ['-c', 'command -v gemini'], { timeout: 2000 });
|
||||
if (res.status !== 0) {
|
||||
return { ok: false, reason: 'gemini CLI not found on PATH. Install per https://github.com/google-gemini/gemini-cli' };
|
||||
}
|
||||
const legacyCfgDir = path.join(os.homedir(), '.config', 'gemini');
|
||||
const newCfgDir = path.join(os.homedir(), '.gemini');
|
||||
const newOauth = path.join(newCfgDir, 'oauth_creds.json');
|
||||
const hasCfg = fs.existsSync(legacyCfgDir) || fs.existsSync(newOauth);
|
||||
const hasCfg = !opts?.csoProducer && (fs.existsSync(legacyCfgDir) || fs.existsSync(newOauth));
|
||||
// CLI accepts either name; Google AI Studio keys are usually GEMINI_API_KEY.
|
||||
const hasKey = !!(process.env.GOOGLE_API_KEY || process.env.GEMINI_API_KEY);
|
||||
if (!hasCfg && !hasKey) {
|
||||
@@ -138,23 +152,15 @@ export class GeminiAdapter implements ProviderAdapter {
|
||||
// Default to --yolo (non-interactive) and stream-json output so we can parse
|
||||
// tokens + tool calls. Callers can override via extraArgs. (--skip-trust was
|
||||
// removed in gemini-cli 0.34; passing it errors at argv parse.)
|
||||
const args = ['-p', opts.prompt, '--output-format', 'stream-json', '--yolo'];
|
||||
if (opts.model) args.push('--model', opts.model);
|
||||
if (opts.extraArgs) args.push(...opts.extraArgs);
|
||||
|
||||
try {
|
||||
const out = execFileSync('gemini', args, {
|
||||
cwd: opts.workdir,
|
||||
const args = geminiExecArgs(opts);
|
||||
const command = csoProducerProviderCommand(opts);
|
||||
const out = execFileSync(command?.executable ?? 'gemini', [...(command?.argsPrefix ?? []), ...args], {
|
||||
cwd: geminiExecWorkingDirectory(opts),
|
||||
timeout: opts.timeoutMs,
|
||||
encoding: 'utf-8',
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
// Prefer GEMINI_API_KEY when only that is set (CLI reads both).
|
||||
...(process.env.GEMINI_API_KEY && !process.env.GOOGLE_API_KEY
|
||||
? { GOOGLE_API_KEY: process.env.GEMINI_API_KEY }
|
||||
: {}),
|
||||
},
|
||||
env: geminiExecEnvironment(opts, process.env),
|
||||
});
|
||||
return resultFromGeminiStream(out, { model: opts.model, durationMs: Date.now() - start });
|
||||
} catch (err: unknown) {
|
||||
@@ -189,3 +195,124 @@ export class GeminiAdapter implements ProviderAdapter {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface GeminiProducerPaths {
|
||||
root: string;
|
||||
home: string;
|
||||
workdir: string;
|
||||
systemDefaults: string;
|
||||
systemSettings: string;
|
||||
}
|
||||
|
||||
export function geminiProducerPaths(stateDirectory: string): GeminiProducerPaths {
|
||||
validateCsoProducerStateDirectory(stateDirectory);
|
||||
const root = path.join(stateDirectory, 'gemini-provider');
|
||||
return {
|
||||
root,
|
||||
home: path.join(root, 'home'),
|
||||
workdir: path.join(root, 'work'),
|
||||
systemDefaults: path.join(root, 'system-defaults.json'),
|
||||
systemSettings: path.join(root, 'system-settings.json'),
|
||||
};
|
||||
}
|
||||
|
||||
/** Highest-precedence Gemini policy for a clean, one-cell producer host. */
|
||||
const GEMINI_PRODUCER_BLOCKED_ENVIRONMENT = [
|
||||
'GEMINI_API_KEY', 'GOOGLE_API_KEY', 'GOOGLE_CLOUD_PROJECT', 'GOOGLE_CLOUD_LOCATION',
|
||||
] as const;
|
||||
|
||||
export function geminiProducerSystemSettings(contextFileName: string, helperLauncher: string) {
|
||||
if (!/^\.gstack-cso-context-[a-f0-9]{32}\.md$/.test(contextFileName)) throw new Error('INVALID_GEMINI_CONTEXT_FILENAME');
|
||||
const helper = csoProducerHelperLauncher({ prompt: '', workdir: '/', timeoutMs: 1, csoProducer: { stateDirectory: '/', sourceDirectory: '/source', helperLauncher, helperGeneration: path.join(path.dirname(helperLauncher), '.gstack-cso-generation'), providerCommand: { executable: '/provider', argsPrefix: [] } } });
|
||||
if (!helper) throw new Error('CSO producer helper launcher is required');
|
||||
const tools = [`run_shell_command(${helper})`, 'write_file'];
|
||||
return {
|
||||
advanced: { ignoreLocalEnv: true },
|
||||
admin: {
|
||||
extensions: { enabled: false },
|
||||
mcp: { enabled: false },
|
||||
skills: { enabled: false },
|
||||
},
|
||||
context: {
|
||||
fileName: [contextFileName],
|
||||
includeDirectoryTree: false,
|
||||
loadMemoryFromIncludeDirectories: false,
|
||||
memoryBoundaryMarkers: [],
|
||||
},
|
||||
hooksConfig: { enabled: false },
|
||||
privacy: { usageStatisticsEnabled: false },
|
||||
security: {
|
||||
environmentVariableRedaction: { allowed: [], blocked: [...GEMINI_PRODUCER_BLOCKED_ENVIRONMENT], enabled: true },
|
||||
folderTrust: { enabled: false },
|
||||
toolSandboxing: false,
|
||||
},
|
||||
skills: { enabled: false },
|
||||
telemetry: { enabled: false, logPrompts: false },
|
||||
tools: { allowed: tools, core: tools, sandbox: false },
|
||||
};
|
||||
}
|
||||
|
||||
export function prepareGeminiProducerState(stateDirectory: string, helperLauncher: string): GeminiProducerPaths {
|
||||
const paths = geminiProducerPaths(stateDirectory);
|
||||
if (fs.existsSync(paths.root)) throw new Error('GEMINI_PRODUCER_STATE_EXISTS');
|
||||
fs.mkdirSync(paths.root, { mode: 0o700 });
|
||||
fs.mkdirSync(paths.home, { mode: 0o700 });
|
||||
fs.mkdirSync(paths.workdir, { mode: 0o700 });
|
||||
const contextFileName = `.gstack-cso-context-${randomBytes(16).toString('hex')}.md`;
|
||||
atomicWriteSync(paths.systemDefaults, '{}\n', { mode: 0o600, noReplace: true });
|
||||
atomicWriteSync(paths.systemSettings, `${JSON.stringify(geminiProducerSystemSettings(contextFileName, helperLauncher), null, 2)}\n`, { mode: 0o600, noReplace: true });
|
||||
return paths;
|
||||
}
|
||||
|
||||
export function removeGeminiProducerState(stateDirectory: string): void {
|
||||
const paths = geminiProducerPaths(stateDirectory);
|
||||
fs.rmSync(paths.root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
export function geminiExecArgs(opts: RunOpts): string[] {
|
||||
const stateDirectory = csoProducerStateDirectory(opts);
|
||||
const args = ['-p', opts.prompt, '--output-format', 'stream-json'];
|
||||
if (stateDirectory) {
|
||||
if (opts.extraArgs?.length) throw new Error('CSO producer does not accept extra provider arguments');
|
||||
args.push(
|
||||
'--approval-mode', 'yolo',
|
||||
'--include-directories', geminiProducerPaths(stateDirectory).workdir,
|
||||
'-e', 'none',
|
||||
);
|
||||
} else {
|
||||
args.push('--yolo');
|
||||
}
|
||||
if (opts.model) args.push('--model', opts.model);
|
||||
if (opts.extraArgs) args.push(...opts.extraArgs);
|
||||
return args;
|
||||
}
|
||||
|
||||
export function geminiExecWorkingDirectory(opts: RunOpts): string {
|
||||
const stateDirectory = csoProducerStateDirectory(opts);
|
||||
return stateDirectory ? geminiProducerPaths(stateDirectory).workdir : opts.workdir;
|
||||
}
|
||||
|
||||
export function geminiExecEnvironment(
|
||||
opts: RunOpts,
|
||||
source: NodeJS.ProcessEnv = process.env,
|
||||
): Record<string, string> {
|
||||
const stateDirectory = csoProducerStateDirectory(opts);
|
||||
const paths = stateDirectory ? geminiProducerPaths(stateDirectory) : undefined;
|
||||
const env = paths ? csoProducerChildEnvironment('gemini', source) : { ...source } as Record<string, string>;
|
||||
// Prefer GEMINI_API_KEY when only that is set (CLI reads both).
|
||||
if (env.GEMINI_API_KEY && !env.GOOGLE_API_KEY) env.GOOGLE_API_KEY = env.GEMINI_API_KEY;
|
||||
if (paths) {
|
||||
env.HOME = paths.home;
|
||||
env.GSTACK_HOME = csoProducerHelperHome(opts)!;
|
||||
env.GEMINI_SANDBOX = 'false';
|
||||
env.GEMINI_TELEMETRY_ENABLED = 'false';
|
||||
env.GEMINI_TELEMETRY_LOG_PROMPTS = 'false';
|
||||
env.GEMINI_CLI_TRUST_WORKSPACE = 'true';
|
||||
env.GEMINI_SYSTEM_MD = 'false';
|
||||
env.GEMINI_WRITE_SYSTEM_MD = 'false';
|
||||
env.GEMINI_CLI_HOME = paths.home;
|
||||
env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH = paths.systemDefaults;
|
||||
env.GEMINI_CLI_SYSTEM_SETTINGS_PATH = paths.systemSettings;
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user