pi-plus-sdk 0.2.20 → 0.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/api.d.ts +84 -5
  2. package/api.js +184 -125
  3. package/package.json +1 -1
package/api.d.ts CHANGED
@@ -181,18 +181,88 @@ export declare function createPlusSdkExtensionFactories(agentDir?: string): Inli
181
181
  /** Default env-fallback binding: `createPlusSdkExtensionFactories()`. */
182
182
  export declare const plusSdkExtensionFactories: InlineExtension[];
183
183
 
184
- // --- pi-plus-permissions (bypass | acceptEdits | plan tool-call gate) ------
184
+ // --- pi-plus-permissions (bypass | acceptEdits | auto | plan tool-call gate) ---
185
185
 
186
- export type PermissionMode = "bypass" | "acceptEdits" | "plan";
186
+ export type PermissionMode = "bypass" | "acceptEdits" | "auto" | "plan";
187
187
 
188
188
  /** Canonical order; hosts cycle forward through this list on their shortcut. */
189
189
  export declare const PERMISSION_MODES: PermissionMode[];
190
190
 
191
191
  export declare const PERMISSION_MODE_LABELS: Record<PermissionMode, string>;
192
192
 
193
+ /**
194
+ * Auto mode replaces "ask the human" with "ask the model": reads and
195
+ * in-project edits run unattended, everything else is judged by an action
196
+ * classifier (session model by default). A block is offered to the user for
197
+ * override when a UI is present; with no UI the block is final. Paths holding
198
+ * agent/VCS/startup configuration are denied before the classifier and are
199
+ * never classifier-approvable.
200
+ */
201
+
202
+ /** Verdict on one pending tool call. `unavailable` means "no verdict". */
203
+ export interface ClassifierDecision {
204
+ status: "allow" | "block" | "unavailable";
205
+ reason?: string;
206
+ }
207
+
208
+ /** What the classifier is shown about a pending call. */
209
+ export interface ClassifierAction {
210
+ toolName: string;
211
+ /** Human-readable one-liner (tool + arguments). */
212
+ description: string;
213
+ /** Truncated serialization of the tool input. */
214
+ input?: string;
215
+ }
216
+
217
+ /** Signature of the judge: default model-backed, replaceable by hosts/tests. */
218
+ export type ActionClassifier = (
219
+ action: ClassifierAction,
220
+ ctx: ExtensionContext,
221
+ signal?: AbortSignal,
222
+ ) => Promise<ClassifierDecision>;
223
+
224
+ /** Consecutive-deny counter used to warn once when auto mode keeps blocking. */
225
+ export declare class DenialTracker {
226
+ readonly maxConsecutive: number;
227
+ constructor(maxConsecutive?: number);
228
+ recordBlock(): number;
229
+ recordAllow(): void;
230
+ shouldNotify(): boolean;
231
+ }
232
+
193
233
  /** Mutable holder shared between the host and the extension. */
194
234
  export interface PermissionModeState {
195
235
  mode: PermissionMode;
236
+ /** Auto-mode deny streak tracking; created lazily by the gate. */
237
+ denials?: DenialTracker;
238
+ }
239
+
240
+ /** User-editable auto-mode policy bullets (`autoMode` setting). */
241
+ export interface AutoModeRules {
242
+ allow: string[];
243
+ deny: string[];
244
+ environment: string[];
245
+ }
246
+
247
+ export declare function readAutoModeRules(cwd: string): AutoModeRules;
248
+ export declare function formatAutoModeRules(rules: AutoModeRules): string | undefined;
249
+ export declare function buildClassifierSystemPrompt(policyAddendum?: string): string;
250
+ export declare function buildClassifierUserPrompt(action: ClassifierAction, transcript: string): string;
251
+ export declare function buildTranscript(ctx: ExtensionContext, maxChars?: number): string;
252
+ export declare function parseClassifierResponse(
253
+ text: string,
254
+ ): { block: boolean; reason?: string } | undefined;
255
+ export declare function classifyAction(
256
+ action: ClassifierAction,
257
+ params: unknown,
258
+ ): Promise<ClassifierDecision>;
259
+ export declare function createModelClassifier(options?: unknown): ActionClassifier;
260
+ /** Why writing `path` is denied in auto mode regardless of the classifier. */
261
+ export declare function autoModeWriteDenial(path: string, cwd: string): string | undefined;
262
+
263
+ export interface PermissionGateDeps {
264
+ classifier?: ActionClassifier;
265
+ state?: PermissionModeState;
196
266
  }
197
267
 
198
268
  export interface PermissionsExtensionOptions {
@@ -200,6 +270,8 @@ export interface PermissionsExtensionOptions {
200
270
  state?: PermissionModeState;
201
271
  /** Called after every mode change, including host-side writes. */
202
272
  onModeChange?: (mode: PermissionMode) => void;
273
+ /** Override the auto-mode action classifier (tests or a custom model). */
274
+ classifier?: ActionClassifier;
203
275
  }
204
276
 
205
277
  export declare function parsePermissionMode(arg: string): PermissionMode | undefined;
@@ -208,6 +280,7 @@ export declare function gatePermissionToolCall(
208
280
  event: ToolCallEvent,
209
281
  mode: PermissionMode,
210
282
  ctx: ExtensionContext,
283
+ deps?: PermissionGateDeps,
211
284
  ): Promise<ToolCallEventResult | undefined>;
212
285
 
213
286
  /** Build the pi-plus-permissions inline extension for a host. */
@@ -233,10 +306,16 @@ export declare function notifyActivePermissionModeChange(mode: PermissionMode):
233
306
  /**
234
307
  * Pick from a host's dedicated plan-review dialog (pi-plus-desktop renders
235
308
  * the plan as markdown with Claude Code style choices). "approveAcceptEdits" /
236
- * "approveBypass" approve AND select the post-approval permission mode, so
237
- * the plan runs with the chosen level of automation. undefined = dismissed.
309
+ * "approveAuto" / "approveBypass" approve AND select the post-approval
310
+ * permission mode, so the plan runs with the chosen level of automation.
311
+ * undefined = dismissed.
238
312
  */
239
- export type PlanReviewDialogChoice = "approveAcceptEdits" | "approveBypass" | "edit" | "stay";
313
+ export type PlanReviewDialogChoice =
314
+ | "approveAcceptEdits"
315
+ | "approveAuto"
316
+ | "approveBypass"
317
+ | "edit"
318
+ | "stay";
240
319
 
241
320
  /**
242
321
  * Optional ExtensionUIContext extension SDK hosts provide via