fix(coding-agent): persist implicit project trust on reload
This commit is contained in:
@@ -85,7 +85,7 @@ import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.ts";
|
||||
import type { SourceInfo } from "../../core/source-info.ts";
|
||||
import { isInstallTelemetryEnabled } from "../../core/telemetry.ts";
|
||||
import type { TruncationResult } from "../../core/tools/truncate.ts";
|
||||
import { hasProjectTrustInputs, ProjectTrustStore } from "../../core/trust-manager.ts";
|
||||
import { hasProjectConfigDir, hasProjectTrustInputs, ProjectTrustStore } from "../../core/trust-manager.ts";
|
||||
import { getChangelogPath, getNewEntries, parseChangelog } from "../../utils/changelog.ts";
|
||||
import { copyToClipboard } from "../../utils/clipboard.ts";
|
||||
import { extensionForImageMimeType, readClipboardImage } from "../../utils/clipboard-image.ts";
|
||||
@@ -249,6 +249,8 @@ export interface InteractiveModeOptions {
|
||||
migratedProviders?: string[];
|
||||
/** Warning message if session model couldn't be restored */
|
||||
modelFallbackMessage?: string;
|
||||
/** Cwd to trust after reload if it gained a .pi directory during this implicitly trusted session. */
|
||||
autoTrustOnReloadCwd?: string;
|
||||
/** Initial message to send on startup (can include @file content) */
|
||||
initialMessage?: string;
|
||||
/** Images to attach to the initial message */
|
||||
@@ -367,6 +369,7 @@ export class InteractiveMode {
|
||||
private customHeader: (Component & { dispose?(): void }) | undefined = undefined;
|
||||
|
||||
private options: InteractiveModeOptions;
|
||||
private autoTrustOnReloadCwd: string | undefined;
|
||||
|
||||
// Convenience accessors
|
||||
private get session(): AgentSession {
|
||||
@@ -385,6 +388,7 @@ export class InteractiveMode {
|
||||
constructor(runtimeHost: AgentSessionRuntime, options: InteractiveModeOptions = {}) {
|
||||
this.runtimeHost = runtimeHost;
|
||||
this.options = options;
|
||||
this.autoTrustOnReloadCwd = options.autoTrustOnReloadCwd;
|
||||
this.runtimeHost.setBeforeSessionInvalidate(() => {
|
||||
this.resetExtensionUI();
|
||||
});
|
||||
@@ -4163,6 +4167,32 @@ export class InteractiveMode {
|
||||
}
|
||||
}
|
||||
|
||||
private maybeSaveImplicitProjectTrustAfterReload(): boolean {
|
||||
const cwd = this.sessionManager.getCwd();
|
||||
if (this.autoTrustOnReloadCwd !== cwd) {
|
||||
return false;
|
||||
}
|
||||
if (!this.settingsManager.isProjectTrusted() || !hasProjectConfigDir(cwd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const trustStore = new ProjectTrustStore(this.runtimeHost.services.agentDir);
|
||||
try {
|
||||
if (trustStore.get(cwd) !== null) {
|
||||
this.autoTrustOnReloadCwd = undefined;
|
||||
return false;
|
||||
}
|
||||
trustStore.set(cwd, true);
|
||||
this.autoTrustOnReloadCwd = undefined;
|
||||
return true;
|
||||
} catch (error) {
|
||||
this.showWarning(
|
||||
`Could not save project trust after reload: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private showTrustSelector(): void {
|
||||
const cwd = this.sessionManager.getCwd();
|
||||
const trustStore = new ProjectTrustStore(this.runtimeHost.services.agentDir);
|
||||
@@ -5047,11 +5077,16 @@ export class InteractiveMode {
|
||||
force: false,
|
||||
showDiagnosticsWhenQuiet: true,
|
||||
});
|
||||
const savedImplicitProjectTrust = this.maybeSaveImplicitProjectTrustAfterReload();
|
||||
const modelsJsonError = this.session.modelRegistry.getError();
|
||||
if (modelsJsonError) {
|
||||
this.showError(`models.json error: ${modelsJsonError}`);
|
||||
}
|
||||
this.showStatus("Reloaded keybindings, extensions, skills, prompts, themes");
|
||||
this.showStatus(
|
||||
savedImplicitProjectTrust
|
||||
? "Reloaded keybindings, extensions, skills, prompts, themes; saved project trust"
|
||||
: "Reloaded keybindings, extensions, skills, prompts, themes",
|
||||
);
|
||||
} catch (error) {
|
||||
dismissReloadBox(previousEditor as Component);
|
||||
this.showError(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
|
||||
|
||||
Reference in New Issue
Block a user