@github/copilot-sdk 1.0.9-preview.1 → 1.0.9-preview.3

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.
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Union of all session event variants emitted by the Copilot CLI runtime.
7
7
  */
8
- export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | WarningEvent | ModelChangeEvent | ModeChangedEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ContextChangedEvent | UsageInfoEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantTurnRetryEvent | AssistantIntentEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | ModelCallStartEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | FactoryRunUpdatedEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
8
+ export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | WarningEvent | ModelChangeEvent | ModeChangedEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ContextChangedEvent | UsageInfoEvent | ContextClearedEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantIntentEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | FactoryRunUpdatedEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
9
9
  /**
10
10
  * Hosting platform type of the repository (github or ado)
11
11
  */
@@ -274,7 +274,9 @@ export type AbortReason =
274
274
  /** A remote command requested the abort. */
275
275
  | "remote_command"
276
276
  /** An MCP server delivered a user.abort notification. */
277
- | "user_abort";
277
+ | "user_abort"
278
+ /** Autopilot stopped the run because the active objective reached its user-set --max-ai-credits limit. */
279
+ | "autopilot_credit_limit";
278
280
  /**
279
281
  * Allowed values for the `ToolExecutionStartToolDescriptionMetaUIVisibility` enumeration.
280
282
  */
@@ -365,7 +367,7 @@ export type SystemMessageRole =
365
367
  /**
366
368
  * Structured metadata identifying what triggered this notification
367
369
  */
368
- export type SystemNotification = SystemNotificationAgentCompleted | SystemNotificationAgentIdle | SystemNotificationNewInboxMessage | SystemNotificationShellCompleted | SystemNotificationShellDetachedCompleted | SystemNotificationInstructionDiscovered | SystemNotificationUnclassified;
370
+ export type SystemNotification = SystemNotificationAgentCompleted | SystemNotificationAgentIdle | SystemNotificationNewInboxMessage | SystemNotificationShellCompleted | SystemNotificationShellDetachedCompleted | SystemNotificationInstructionDiscovered | SystemNotificationFactoryCompleted | SystemNotificationUnclassified;
369
371
  /**
370
372
  * Whether the agent completed successfully or failed
371
373
  */
@@ -374,10 +376,22 @@ export type SystemNotificationAgentCompletedStatus =
374
376
  "completed"
375
377
  /** The agent failed. */
376
378
  | "failed";
379
+ /**
380
+ * Terminal status reached by a factory execution attempt.
381
+ */
382
+ export type SystemNotificationFactoryCompletedStatus =
383
+ /** The factory completed successfully. */
384
+ "completed"
385
+ /** The factory was halted. */
386
+ | "halted"
387
+ /** The factory was cancelled. */
388
+ | "cancelled"
389
+ /** The factory failed. */
390
+ | "error";
377
391
  /**
378
392
  * Details of the permission being requested
379
393
  */
380
- export type PermissionRequest = PermissionRequestShell | PermissionRequestWrite | PermissionRequestRead | PermissionRequestMcp | PermissionRequestUrl | PermissionRequestMemory | PermissionRequestCustomTool | PermissionRequestHook | PermissionRequestExtensionManagement | PermissionRequestExtensionPermissionAccess;
394
+ export type PermissionRequest = PermissionRequestShell | PermissionRequestWrite | PermissionRequestRead | PermissionRequestMcp | PermissionRequestUrl | PermissionRequestMemory | PermissionRequestCustomTool | PermissionRequestHook | PermissionRequestExtensionManagement | PermissionRequestFactory | PermissionRequestExtensionPermissionAccess;
381
395
  /**
382
396
  * Whether this is a store or vote memory operation
383
397
  */
@@ -394,10 +408,18 @@ export type PermissionRequestMemoryDirection =
394
408
  "upvote"
395
409
  /** Vote that the memory is incorrect or outdated. */
396
410
  | "downvote";
411
+ /**
412
+ * Operation gated by a factory permission request.
413
+ */
414
+ export type FactoryPermissionOperation =
415
+ /** Running a registered factory, which spends subagents, active time, and AI credits under the approved limits. */
416
+ "run"
417
+ /** Authoring a factory, which writes JavaScript into a session-scoped extension and loads it. */
418
+ | "author";
397
419
  /**
398
420
  * Derived user-facing permission prompt details for UI consumers
399
421
  */
400
- export type PermissionPromptRequest = PermissionPromptRequestCommands | PermissionPromptRequestWrite | PermissionPromptRequestRead | PermissionPromptRequestMcp | PermissionPromptRequestUrl | PermissionPromptRequestMemory | PermissionPromptRequestCustomTool | PermissionPromptRequestPath | PermissionPromptRequestHook | PermissionPromptRequestExtensionManagement | PermissionPromptRequestExtensionPermissionAccess;
422
+ export type PermissionPromptRequest = PermissionPromptRequestCommands | PermissionPromptRequestWrite | PermissionPromptRequestRead | PermissionPromptRequestMcp | PermissionPromptRequestUrl | PermissionPromptRequestMemory | PermissionPromptRequestCustomTool | PermissionPromptRequestPath | PermissionPromptRequestHook | PermissionPromptRequestExtensionManagement | PermissionPromptRequestFactory | PermissionPromptRequestExtensionPermissionAccess;
401
423
  /**
402
424
  * Why the auto-approval judge produced no usable recommendation. Present only alongside an `error` recommendation, where the human-readable reason is a fixed string and therefore cannot distinguish these cases. Intended to make a judge failure reportable by a consumer that has no access to the host's logs.
403
425
  */
@@ -443,7 +465,7 @@ export type PermissionResult = PermissionApproved | PermissionApprovedForSession
443
465
  /**
444
466
  * The approval to add as a session-scoped rule
445
467
  */
446
- export type UserToolSessionApproval = UserToolSessionApprovalCommands | UserToolSessionApprovalRead | UserToolSessionApprovalWrite | UserToolSessionApprovalMcp | UserToolSessionApprovalMemory | UserToolSessionApprovalCustomTool | UserToolSessionApprovalExtensionManagement | UserToolSessionApprovalExtensionPermissionAccess;
468
+ export type UserToolSessionApproval = UserToolSessionApprovalCommands | UserToolSessionApprovalRead | UserToolSessionApprovalWrite | UserToolSessionApprovalMcp | UserToolSessionApprovalMemory | UserToolSessionApprovalCustomTool | UserToolSessionApprovalExtensionManagement | UserToolSessionApprovalFactory | UserToolSessionApprovalExtensionPermissionAccess;
447
469
  /**
448
470
  * Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to "form" when absent.
449
471
  */
@@ -607,7 +629,7 @@ export type McpServerSource =
607
629
  /** Server bundled with the runtime. */
608
630
  | "builtin";
609
631
  /**
610
- * Connection status: connected, failed, needs-auth, pending, disabled, or not_configured
632
+ * Connection status: connected, failed, needs-auth, pending, disabled, stopped, or not_configured
611
633
  */
612
634
  export type McpServerStatus =
613
635
  /** The server is connected and available. */
@@ -620,6 +642,8 @@ export type McpServerStatus =
620
642
  | "pending"
621
643
  /** The server is configured but disabled. */
622
644
  | "disabled"
645
+ /** The server was intentionally stopped and can be restarted on demand when policy permits; a server quarantined by restrictive managed policy stays stopped and cannot be restarted until the policy allows it. */
646
+ | "stopped"
623
647
  /** The server is not configured for this session. */
624
648
  | "not_configured";
625
649
  /**
@@ -709,6 +733,7 @@ export interface StartData {
709
733
  * When set, identifies a parent session whose context this session continues — e.g., a detached headless rem-agent run launched on the parent's interactive shutdown. Telemetry from this session is reported under the parent's session_id.
710
734
  */
711
735
  detachedFromSpawningParentSessionId?: string;
736
+ githubMcpToolConfig?: GitHubMcpToolConfig;
712
737
  /**
713
738
  * Identifier of the software producing the events (e.g., "copilot-agent")
714
739
  */
@@ -779,6 +804,27 @@ export interface WorkingDirectoryContext {
779
804
  */
780
805
  repositoryHost?: string;
781
806
  }
807
+ /**
808
+ * Per-session configuration for the built-in GitHub MCP server
809
+ */
810
+ export interface GitHubMcpToolConfig {
811
+ /**
812
+ * Additional GitHub MCP tools requested by the session
813
+ */
814
+ additionalTools?: string[];
815
+ /**
816
+ * Additional GitHub MCP toolsets requested by the session
817
+ */
818
+ additionalToolsets?: string[];
819
+ /**
820
+ * Whether to use the read-write endpoint and request all toolsets
821
+ */
822
+ enableAllTools?: boolean;
823
+ /**
824
+ * Whether to request the GitHub MCP insiders build
825
+ */
826
+ enableInsidersMode?: boolean;
827
+ }
782
828
  /**
783
829
  * Optional session limits.
784
830
  */
@@ -1386,7 +1432,7 @@ export interface ModelChangeEvent {
1386
1432
  */
1387
1433
  export interface ModelChangeData {
1388
1434
  /**
1389
- * Reason the change happened, when not user-initiated. Currently `"rate_limit_auto_switch"` for changes triggered by the auto-mode-switch rate-limit recovery path. UI clients can use this to render contextual copy.
1435
+ * Reason the change happened, when not user-initiated. `"rate_limit_auto_switch"` for changes triggered by the auto-mode-switch rate-limit recovery path, or `"refusal_fallback"` when the active model declined a request (content refusal) and the runtime switched to the configured refusal-fallback model. UI clients can use this to render contextual copy.
1390
1436
  */
1391
1437
  cause?: string;
1392
1438
  /**
@@ -2159,6 +2205,49 @@ export interface UsageInfoData {
2159
2205
  */
2160
2206
  toolDefinitionsTokens?: number;
2161
2207
  }
2208
+ /**
2209
+ * Session event "session.context_cleared". Context-cleared details emitted when the host clears the conversation (the session.history.clearContext RPC / Session.clearContextMessages)
2210
+ */
2211
+ export interface ContextClearedEvent {
2212
+ /**
2213
+ * Sub-agent instance identifier. Absent for events from the root/main agent and session-level events.
2214
+ */
2215
+ agentId?: string;
2216
+ data: ContextClearedData;
2217
+ /**
2218
+ * When true, the event is transient and not persisted to the session event log on disk
2219
+ */
2220
+ ephemeral?: boolean;
2221
+ /**
2222
+ * Unique event identifier (UUID v4), generated when the event is emitted
2223
+ */
2224
+ id: string;
2225
+ /**
2226
+ * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event.
2227
+ */
2228
+ parentId: string | null;
2229
+ /**
2230
+ * ISO 8601 timestamp when the event was created
2231
+ */
2232
+ timestamp: string;
2233
+ /**
2234
+ * Type discriminator. Always "session.context_cleared".
2235
+ */
2236
+ type: "session.context_cleared";
2237
+ }
2238
+ /**
2239
+ * Context-cleared details emitted when the host clears the conversation (the session.history.clearContext RPC / Session.clearContextMessages)
2240
+ */
2241
+ export interface ContextClearedData {
2242
+ /**
2243
+ * Optional initial message set after clearing
2244
+ */
2245
+ initialMessage?: string;
2246
+ /**
2247
+ * Number of conversation messages that were cleared
2248
+ */
2249
+ messagesCleared: number;
2250
+ }
2162
2251
  /**
2163
2252
  * Session event "session.compaction_start". Context window breakdown at the start of LLM-powered conversation compaction
2164
2253
  */
@@ -3025,23 +3114,6 @@ export interface AssistantTurnStartData {
3025
3114
  */
3026
3115
  turnId: string;
3027
3116
  }
3028
- /**
3029
- * Metadata for an additional model inference attempt within an existing assistant turn
3030
- */
3031
- export interface AssistantTurnRetryData {
3032
- /**
3033
- * Model identifier used for this retry, when known
3034
- */
3035
- model?: string;
3036
- /**
3037
- * Provider or runtime classification that caused the retry, when known
3038
- */
3039
- reason?: string;
3040
- /**
3041
- * Identifier of the turn whose model inference is being retried
3042
- */
3043
- turnId: string;
3044
- }
3045
3117
  /**
3046
3118
  * Session event "assistant.intent". Agent intent description for current activity or plan
3047
3119
  */
@@ -3340,6 +3412,14 @@ export interface AssistantMessageData {
3340
3412
  * Provider's completion / response identifier; shared across all chunks of a single API call. Used to group multi-chunk assistant utterances.
3341
3413
  */
3342
3414
  apiCallId?: string;
3415
+ /**
3416
+ * Total messages the model call's response was split into, one per reasoning boundary. Absent for a single-message response; the last chunk is the one where chunkIndex is chunkCount - 1.
3417
+ */
3418
+ chunkCount?: number;
3419
+ /**
3420
+ * Zero-based position of this message within its model call's response. Absent when the response was not split into chunks.
3421
+ */
3422
+ chunkIndex?: number;
3343
3423
  /**
3344
3424
  * Provider-agnostic citations linking spans of this message's content to the sources that support them. Experimental; only populated when citation emission is enabled.
3345
3425
  *
@@ -4052,19 +4132,6 @@ export interface ModelCallFailureRequestFingerprint {
4052
4132
  */
4053
4133
  toolResultMessageCount: number;
4054
4134
  }
4055
- /**
4056
- * Model API dispatch metadata for internal telemetry
4057
- */
4058
- export interface ModelCallStartData {
4059
- /**
4060
- * Model identifier used for this API call, when known
4061
- */
4062
- model?: string;
4063
- /**
4064
- * Identifier of the assistant turn that initiated the model call
4065
- */
4066
- turnId: string;
4067
- }
4068
4135
  /**
4069
4136
  * Session event "abort". Turn abort information including the reason for termination
4070
4137
  */
@@ -4231,6 +4298,12 @@ export interface ToolExecutionStartData {
4231
4298
  * Shell-aware path hints for a shell tool's command, captured at start time so consumers can snapshot a file's pre-image before the tool runs.
4232
4299
  */
4233
4300
  export interface ToolExecutionStartShellToolInfo {
4301
+ /**
4302
+ * The command with a redundant leading `cd` into the working directory removed, present only when there was one to remove. Computed with the same routine the shell driver applies before spawning, so a surface that renders this shows the text that actually runs. Consumers that display it should keep the original tool arguments available on demand.
4303
+ *
4304
+ * @experimental
4305
+ */
4306
+ displayCommand?: string;
4234
4307
  /**
4235
4308
  * Whether the command includes a file write redirection (e.g., > or >>).
4236
4309
  */
@@ -5759,6 +5832,54 @@ export interface SystemNotificationInstructionDiscovered {
5759
5832
  */
5760
5833
  type: "instruction_discovered";
5761
5834
  }
5835
+ /**
5836
+ * System notification metadata for a factory execution attempt that reached a terminal state.
5837
+ */
5838
+ export interface SystemNotificationFactoryCompleted {
5839
+ /**
5840
+ * Execution attempt that reached this terminal state.
5841
+ */
5842
+ attempt: number;
5843
+ /**
5844
+ * Consumed AI usage in nano-AIU.
5845
+ */
5846
+ consumedNanoAiu: number;
5847
+ /**
5848
+ * Subagents consumed by the run across all attempts.
5849
+ */
5850
+ consumedSubagents: number;
5851
+ /**
5852
+ * Accumulated active execution time in milliseconds.
5853
+ */
5854
+ elapsedMs: number;
5855
+ /**
5856
+ * Persisted factory name.
5857
+ */
5858
+ factoryName: string;
5859
+ /**
5860
+ * Machine-readable terminal failure details, when present.
5861
+ */
5862
+ failure?: {
5863
+ [k: string]: unknown | undefined;
5864
+ };
5865
+ /**
5866
+ * Bounded prompt-safe preview of the completed result.
5867
+ */
5868
+ resultPreview?: string;
5869
+ /**
5870
+ * Actionable run_factory resume guidance for a resource-limit failure.
5871
+ */
5872
+ retryGuidance?: string;
5873
+ /**
5874
+ * Factory run identifier.
5875
+ */
5876
+ runId: string;
5877
+ status: SystemNotificationFactoryCompletedStatus;
5878
+ /**
5879
+ * Type discriminator. Always "factory_completed".
5880
+ */
5881
+ type: "factory_completed";
5882
+ }
5762
5883
  /**
5763
5884
  * System notification metadata from an external host that does not match a runtime-owned notification kind.
5764
5885
  */
@@ -6177,6 +6298,73 @@ export interface PermissionRequestExtensionManagement {
6177
6298
  */
6178
6299
  toolCallId?: string;
6179
6300
  }
6301
+ /**
6302
+ * Factory run or authoring permission request
6303
+ */
6304
+ export interface PermissionRequestFactory {
6305
+ /**
6306
+ * Canonical key used for scoped factory approvals
6307
+ */
6308
+ approvalKey: string;
6309
+ /**
6310
+ * Whether this factory is eligible for persistent approval
6311
+ */
6312
+ canPersistApproval: boolean;
6313
+ declaredMaxAiCredits?: number;
6314
+ declaredMaxConcurrentSubagents?: number;
6315
+ declaredMaxTotalSubagents?: number;
6316
+ declaredTimeoutSeconds?: number;
6317
+ /**
6318
+ * Factory description
6319
+ */
6320
+ description: string;
6321
+ /**
6322
+ * Permission kind discriminator
6323
+ */
6324
+ kind: "factory";
6325
+ /**
6326
+ * Effective AI-credit limit; omitted means unlimited
6327
+ */
6328
+ maxAiCredits?: number;
6329
+ /**
6330
+ * Effective concurrent-subagent limit; omitted means unlimited
6331
+ */
6332
+ maxConcurrentSubagents?: number;
6333
+ /**
6334
+ * Effective total-subagent limit; omitted means unlimited
6335
+ */
6336
+ maxTotalSubagents?: number;
6337
+ /**
6338
+ * Factory name
6339
+ */
6340
+ name: string;
6341
+ operation: FactoryPermissionOperation;
6342
+ /**
6343
+ * Declared factory phases
6344
+ */
6345
+ phases: FactoryPermissionPhase[];
6346
+ /**
6347
+ * Effective active-time limit in seconds; omitted means unlimited
6348
+ */
6349
+ timeoutSeconds?: number;
6350
+ /**
6351
+ * Tool call ID that triggered this permission request
6352
+ */
6353
+ toolCallId?: string;
6354
+ }
6355
+ /**
6356
+ * A declared phase shown in a factory permission prompt.
6357
+ */
6358
+ export interface FactoryPermissionPhase {
6359
+ /**
6360
+ * Optional phase detail
6361
+ */
6362
+ detail?: string;
6363
+ /**
6364
+ * Phase title
6365
+ */
6366
+ title: string;
6367
+ }
6180
6368
  /**
6181
6369
  * Extension permission access request
6182
6370
  */
@@ -6565,6 +6753,70 @@ export interface PermissionPromptRequestExtensionManagement {
6565
6753
  */
6566
6754
  toolCallId?: string;
6567
6755
  }
6756
+ /**
6757
+ * Factory run or authoring permission prompt
6758
+ */
6759
+ export interface PermissionPromptRequestFactory {
6760
+ /**
6761
+ * Canonical key used for scoped factory approvals
6762
+ */
6763
+ approvalKey: string;
6764
+ /**
6765
+ * Auto-approval judge information for this request; present only when auto mode is enabled.
6766
+ *
6767
+ * @experimental
6768
+ */
6769
+ autoApproval?: PermissionAutoApproval;
6770
+ /**
6771
+ * Whether this factory is eligible for persistent approval
6772
+ */
6773
+ canPersistApproval: boolean;
6774
+ declaredMaxAiCredits?: number;
6775
+ declaredMaxConcurrentSubagents?: number;
6776
+ declaredMaxTotalSubagents?: number;
6777
+ declaredTimeoutSeconds?: number;
6778
+ /**
6779
+ * Factory description
6780
+ */
6781
+ description: string;
6782
+ /**
6783
+ * Prompt kind discriminator
6784
+ */
6785
+ kind: "factory";
6786
+ /**
6787
+ * Whether managed policy requires a human response and forbids host auto-approval
6788
+ */
6789
+ managedApprovalRequired?: boolean;
6790
+ /**
6791
+ * Effective AI-credit limit; omitted means unlimited
6792
+ */
6793
+ maxAiCredits?: number;
6794
+ /**
6795
+ * Effective concurrent-subagent limit; omitted means unlimited
6796
+ */
6797
+ maxConcurrentSubagents?: number;
6798
+ /**
6799
+ * Effective total-subagent limit; omitted means unlimited
6800
+ */
6801
+ maxTotalSubagents?: number;
6802
+ /**
6803
+ * Factory name
6804
+ */
6805
+ name: string;
6806
+ operation: FactoryPermissionOperation;
6807
+ /**
6808
+ * Declared factory phases
6809
+ */
6810
+ phases: FactoryPermissionPhase[];
6811
+ /**
6812
+ * Effective active-time limit in seconds; omitted means unlimited
6813
+ */
6814
+ timeoutSeconds?: number;
6815
+ /**
6816
+ * Tool call ID that triggered this permission request
6817
+ */
6818
+ toolCallId?: string;
6819
+ }
6568
6820
  /**
6569
6821
  * Extension permission access prompt
6570
6822
  */
@@ -6738,6 +6990,19 @@ export interface UserToolSessionApprovalExtensionManagement {
6738
6990
  */
6739
6991
  operation?: string;
6740
6992
  }
6993
+ /**
6994
+ * Session-scoped factory approval, optionally narrowed by approval key.
6995
+ */
6996
+ export interface UserToolSessionApprovalFactory {
6997
+ /**
6998
+ * Optional factory operation name or canonical approval key
6999
+ */
7000
+ approvalKey?: string;
7001
+ /**
7002
+ * Factory approval kind
7003
+ */
7004
+ kind: "factory";
7005
+ }
6741
7006
  /**
6742
7007
  * Session-scoped tool-approval rule for an extension's permission-gated capability access, keyed by extension name.
6743
7008
  */
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export { defineFactory, FactoryResumeError, isFactoryRunTerminal } from "./facto
11
11
  export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
12
12
  export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SessionFsSqliteTransactionFailure, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
13
13
  export type * from "./generated/session-events.js";
14
- export type { CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, CopilotClientMode, CopilotClientOptions, CopilotExpAssignmentResponse, StdioRuntimeConnection, InProcessRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, ChildProcessRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExpConfigEntry, ExpFlagValue, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, FactoryLimits, FactoryMeta, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionHooks, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SessionFsSqliteStatement, SessionFsSqliteTransactionErrorClass, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
14
+ export type { CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, CopilotClientMode, CopilotClientOptions, CopilotExpAssignmentResponse, StdioRuntimeConnection, InProcessRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, ChildProcessRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExpConfigEntry, ExpFlagValue, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubMcpToolConfig, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, FactoryLimits, FactoryMeta, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestedData, PermissionRequestedEvent, PermissionRequestResult, ProviderConfig, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionHooks, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SessionFsSqliteStatement, SessionFsSqliteTransactionErrorClass, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
15
15
  export type { RunOptions, ResumeOptions, FactoryResumeErrorCode, SessionFactoryApi, FactoryAgentOptions, FactoryContext, FactoryDefinition, FactoryHandle, FactoryJsonSchema, JsonValue, FactoryPipelineStage, FactoryStepOptions, FactoryRunResult, FactoryRunStatus, FactoryRunSummary, FactoryRunDetail, FactoryProgressPage, FactoryProgressLine, FactoryPhaseObservation, FactoryPhaseStatus, FactoryAgentSummary, } from "./factory.js";
package/dist/session.d.ts CHANGED
@@ -58,6 +58,7 @@ export declare class CopilotSession {
58
58
  private transformCallbacks?;
59
59
  private _rpc;
60
60
  private traceContextProvider?;
61
+ private readonly managedSettingsEnabled;
61
62
  private _capabilities;
62
63
  private openCanvasInstances;
63
64
  private disconnected;
@@ -68,6 +69,14 @@ export declare class CopilotSession {
68
69
  * change or be removed in future SDK or CLI releases.
69
70
  */
70
71
  readonly factory: SessionFactoryApi;
72
+ /**
73
+ * Resolve a start/resume envelope into the terminal envelope callers expect.
74
+ *
75
+ * The CLI may answer `session.factory.run` and `session.factory.resume`
76
+ * before the run settles, so a non-terminal envelope is followed by a wait
77
+ * on the run's terminal state.
78
+ */
79
+ private settleFactoryRun;
71
80
  /**
72
81
  * Resolve when a factory run reaches a terminal status.
73
82
  *
package/dist/session.js CHANGED
@@ -205,6 +205,7 @@ class CopilotSession {
205
205
  this._workspacePath = _workspacePath;
206
206
  this.traceContextProvider = traceContextProvider;
207
207
  this.mcpAuthHandler = options?.mcpAuthHandler;
208
+ this.managedSettingsEnabled = options?.managedSettingsEnabled === true;
208
209
  }
209
210
  sessionId;
210
211
  connection;
@@ -227,6 +228,7 @@ class CopilotSession {
227
228
  transformCallbacks;
228
229
  _rpc = null;
229
230
  traceContextProvider;
231
+ managedSettingsEnabled;
230
232
  _capabilities = {};
231
233
  openCanvasInstances = [];
232
234
  disconnected = false;
@@ -253,7 +255,7 @@ class CopilotSession {
253
255
  limits: options?.limits
254
256
  }
255
257
  });
256
- return toPublicFactoryRunResult(envelope);
258
+ return this.settleFactoryRun(envelope);
257
259
  }),
258
260
  resume: (async (runId, options) => {
259
261
  let response;
@@ -271,7 +273,7 @@ class CopilotSession {
271
273
  }
272
274
  throw error;
273
275
  }
274
- return toPublicFactoryRunResult(response.run);
276
+ return this.settleFactoryRun(response.run);
275
277
  }),
276
278
  getRun: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.getRun({ runId })),
277
279
  waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
@@ -280,6 +282,19 @@ class CopilotSession {
280
282
  getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
281
283
  cancel: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.cancel({ runId }))
282
284
  };
285
+ /**
286
+ * Resolve a start/resume envelope into the terminal envelope callers expect.
287
+ *
288
+ * The CLI may answer `session.factory.run` and `session.factory.resume`
289
+ * before the run settles, so a non-terminal envelope is followed by a wait
290
+ * on the run's terminal state.
291
+ */
292
+ settleFactoryRun(envelope) {
293
+ if (isFactoryRunTerminal(envelope.status)) {
294
+ return Promise.resolve(toPublicFactoryRunResult(envelope));
295
+ }
296
+ return this.waitForFactoryRun(envelope.runId);
297
+ }
283
298
  /**
284
299
  * Resolve when a factory run reaches a terminal status.
285
300
  *
@@ -685,7 +700,8 @@ class CopilotSession {
685
700
  async _executePermissionAndRespond(requestId, permissionRequest) {
686
701
  try {
687
702
  const result = await this.permissionHandler(permissionRequest, {
688
- sessionId: this.sessionId
703
+ sessionId: this.sessionId,
704
+ managedSettingsEnabled: this.managedSettingsEnabled
689
705
  });
690
706
  if (result.kind === "no-result") {
691
707
  return;
@@ -694,10 +710,15 @@ class CopilotSession {
694
710
  return;
695
711
  }
696
712
  await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
697
- } catch (_error) {
713
+ } catch (error) {
698
714
  if (this.disconnected) {
699
715
  return;
700
716
  }
717
+ console.error("Permission handler or response delivery failed", {
718
+ sessionId: this.sessionId,
719
+ requestId,
720
+ error
721
+ });
701
722
  try {
702
723
  await this.rpc.permissions.handlePendingPermissionRequest({
703
724
  requestId,