feat(coding-agent): allow project trust extensions to defer
This commit is contained in:
@@ -100,6 +100,7 @@ export type {
|
||||
ModelSelectSource,
|
||||
ProjectTrustContext,
|
||||
ProjectTrustEvent,
|
||||
ProjectTrustEventDecision,
|
||||
ProjectTrustEventResult,
|
||||
ProjectTrustHandler,
|
||||
// Provider Registration
|
||||
|
||||
@@ -202,13 +202,16 @@ export async function emitProjectTrustEvent(
|
||||
const errors: ExtensionError[] = [];
|
||||
for (const ext of extensionsResult.extensions) {
|
||||
// A single extension may register multiple handlers for the same event.
|
||||
// The first project_trust handler that returns a decision wins.
|
||||
// The first project_trust handler that returns yes/no wins; undecided falls through.
|
||||
const handlers = ext.handlers.get("project_trust");
|
||||
if (!handlers || handlers.length === 0) continue;
|
||||
|
||||
for (const handler of handlers) {
|
||||
try {
|
||||
const handlerResult = (await handler(event, ctx)) as ProjectTrustEventResult;
|
||||
if (handlerResult.trusted === "undecided") {
|
||||
continue;
|
||||
}
|
||||
return { result: handlerResult, errors };
|
||||
} catch (error) {
|
||||
errors.push({
|
||||
|
||||
@@ -503,8 +503,10 @@ export interface ProjectTrustEvent {
|
||||
cwd: string;
|
||||
}
|
||||
|
||||
export type ProjectTrustEventDecision = "yes" | "no" | "undecided";
|
||||
|
||||
export interface ProjectTrustEventResult {
|
||||
trusted: boolean;
|
||||
trusted: ProjectTrustEventDecision;
|
||||
remember?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ export type {
|
||||
MessageRenderOptions,
|
||||
ProjectTrustContext,
|
||||
ProjectTrustEvent,
|
||||
ProjectTrustEventDecision,
|
||||
ProjectTrustEventResult,
|
||||
ProjectTrustHandler,
|
||||
ProviderConfig,
|
||||
|
||||
@@ -648,10 +648,11 @@ async function resolveProjectTrusted(options: {
|
||||
options.onExtensionError?.(`Extension "${error.extensionPath}" project_trust error: ${error.error}`);
|
||||
}
|
||||
if (result) {
|
||||
const trusted = result.trusted === "yes";
|
||||
if (result.remember === true) {
|
||||
options.trustStore.set(options.cwd, result.trusted);
|
||||
options.trustStore.set(options.cwd, trusted);
|
||||
}
|
||||
return result.trusted;
|
||||
return trusted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user