@github/copilot-sdk-win32-x64 1.0.16 → 1.0.17-preview.0

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.
@@ -3876,7 +3876,7 @@ var init_ffiRuntimeHost = __esm({
3876
3876
  );
3877
3877
  if (!this.connectionId) {
3878
3878
  this.unregisterCallback();
3879
- this.lib.hostShutdown(this.serverId);
3879
+ await this.shutdownHost();
3880
3880
  this.serverId = 0;
3881
3881
  throw new Error("copilot_runtime_connection_open failed.");
3882
3882
  }
@@ -3885,7 +3885,7 @@ var init_ffiRuntimeHost = __esm({
3885
3885
  } finally {
3886
3886
  this.starting = false;
3887
3887
  if (this.disposed) {
3888
- void this.tryFinalizeCleanup();
3888
+ await this.tryFinalizeCleanup();
3889
3889
  }
3890
3890
  }
3891
3891
  }
@@ -3924,6 +3924,17 @@ var init_ffiRuntimeHost = __esm({
3924
3924
  );
3925
3925
  }
3926
3926
  }
3927
+ shutdownHost() {
3928
+ return new Promise((resolvePromise, rejectPromise) => {
3929
+ this.lib.hostShutdown.async(this.serverId, (error, result) => {
3930
+ if (error) {
3931
+ rejectPromise(error);
3932
+ } else {
3933
+ resolvePromise(result);
3934
+ }
3935
+ });
3936
+ });
3937
+ }
3927
3938
  unregisterCallback() {
3928
3939
  if (this.outboundCallback === void 0) {
3929
3940
  return true;
@@ -3996,7 +4007,7 @@ var init_ffiRuntimeHost = __esm({
3996
4007
  }
3997
4008
  if (this.serverId) {
3998
4009
  try {
3999
- if (!this.lib.hostShutdown(this.serverId)) {
4010
+ if (!await this.shutdownHost()) {
4000
4011
  console.error(
4001
4012
  `In-process FFI host shutdown did not recognize server ${this.serverId}.`
4002
4013
  );
@@ -4660,15 +4671,45 @@ function createServerRpc(connection) {
4660
4671
  /** @experimental */
4661
4672
  managedSettings: {
4662
4673
  /**
4663
- * Discovers device-managed settings from production MDM and managed-file sources, validates them against the runtime-owned managed-settings schema, and returns the canonical JSON without requiring a session.
4674
+ * Discovers device-managed settings from production MDM and managed-file sources, validates them against the runtime-owned managed-settings schema, and returns the canonical JSON without requiring a session. `managedSettings.resolve` returns the same device settings together with the account's server policy.
4664
4675
  *
4665
4676
  * @returns Validated device-managed settings discovered before a session exists.
4666
4677
  */
4667
4678
  read: async () => connection.sendRequest("managedSettings.read", {}),
4668
4679
  /**
4669
- * Force-refreshes enterprise managed settings for every account: wipes the persistent server-policy cache (the whole `<cacheHome>/managed-settings` directory) and drops this runtime process's in-memory retained server policy. It does not itself fetch policy — the effect is that the next time a session resolves managed settings for an account, that resolution re-fetches the account's org policy from the network instead of serving a cached response. Note that `managedSettings.read` returns only device/MDM settings and never triggers the account server-policy fetch, so a host implementing "sync account policy" should start a fresh session resolution rather than treat a subsequent `managedSettings.read` as the refreshed org policy. Mirrors the invalidation a sign-out performs, broadened from the one signing-out account to all of them; device/MDM layers describe the machine, not the account, and are left untouched. Rejects if the on-disk cache cannot be removed.
4680
+ * Force-refreshes enterprise managed settings for every account: wipes the persistent server-policy cache (the whole `<cacheHome>/managed-settings` directory) and drops this runtime process's in-memory retained server policy. It does not itself fetch policy — the effect is that the next time a session resolves managed settings for an account, that resolution re-fetches the account's org policy from the network instead of serving a cached response. Note that `managedSettings.read` returns only device/MDM settings and never triggers the account server-policy fetch, so a host implementing "sync account policy" should call `managedSettings.resolve` or start a fresh session resolution rather than treat a subsequent `managedSettings.read` as the refreshed org policy. Mirrors the invalidation a sign-out performs, broadened from the one signing-out account to all of them; device/MDM layers describe the machine, not the account, and are left untouched. Rejects if the on-disk cache cannot be removed.
4681
+ */
4682
+ clearCache: async () => connection.sendRequest("managedSettings.clearCache", {}),
4683
+ /**
4684
+ * Resolves the effective enterprise managed settings without a session, from the device channel and, when an account is available, the account's server policy through the same per-account cache sessions use. A cached server policy less than an hour old is used without a fetch; otherwise the policy is fetched, and when the fetch fails a cached policy up to 24 hours old is used instead, unless `forceRemoteSettingsRefresh` requires a live fetch. With no account requested or signed in, it reports device policy only; signing out removes the account's cached policy. It can fetch server policy over the network when the cache is stale, so call it off latency-critical paths such as startup rather than before listing models. The policy helper is not run. `layers` lists each channel's document before merging, and `values` and `meta` carry typed effective values and their lock state for the keys typed so far.
4685
+ *
4686
+ * @param params Optional opaque account selection or GitHub token whose managed settings are resolved.
4687
+ *
4688
+ * @returns Effective enterprise managed settings for an account, resolved without a session.
4689
+ */
4690
+ resolve: async (params) => connection.sendRequest("managedSettings.resolve", params),
4691
+ /**
4692
+ * Returns the managed-settings authoring JSON schema with descriptive `x-composition` annotations aligned with the shared settings-engine vocabulary. These annotations are not a complete runtime composition contract: model, effortLevel, and contextTier remain coupled. Use `managedSettings.compose` for the runtime's effective result. Performs no I/O.
4693
+ *
4694
+ * @returns The authoring JSON schema for managed settings recognized by this runtime.
4695
+ */
4696
+ schema: async () => connection.sendRequest("managedSettings.schema", {}),
4697
+ /**
4698
+ * Validates a candidate managed-settings document the way the runtime validates delivered policy, without applying it. Reports errors that would reject the document, warnings for content the runtime ignores, and the canonical document it would apply. Document text nested more than 64 levels deep is rejected. Performs no I/O.
4699
+ *
4700
+ * @param params A candidate managed-settings document to validate without applying it.
4701
+ *
4702
+ * @returns Result of validating a managed-settings document.
4703
+ */
4704
+ validate: async (params) => connection.sendRequest("managedSettings.validate", params),
4705
+ /**
4706
+ * Merges candidate managed-settings documents for the device, server, and policy-helper channels into the effective settings the runtime would enforce on this host, using the same precedence and composition rules as live resolution, without applying them. Like live resolution, a server's advisory sandbox force-enable is declined on a host that cannot run the sandbox. Does not fetch policy or read policy files, but may perform blocking OS or subprocess probes for sandbox support. Preview documents are limited to 1 MiB and 64 levels of nesting.
4707
+ *
4708
+ * @param params Candidate managed-settings documents to merge without applying them.
4709
+ *
4710
+ * @returns The effective managed settings the runtime would enforce for the given documents, in the same shape `managedSettings.resolve` returns.
4670
4711
  */
4671
- clearCache: async () => connection.sendRequest("managedSettings.clearCache", {})
4712
+ compose: async (params) => connection.sendRequest("managedSettings.compose", params)
4672
4713
  },
4673
4714
  /** @experimental */
4674
4715
  runtime: {
@@ -6116,6 +6157,12 @@ function createSessionRpc(connection, sessionId) {
6116
6157
  * @returns Feature detection and hard polling limits for the EXPERIMENTAL session connector API.
6117
6158
  */
6118
6159
  getCapabilities: async () => connection.sendRequest("session.connectors.getCapabilities", { sessionId }),
6160
+ /**
6161
+ * Returns the session account selection, or null.
6162
+ *
6163
+ * @returns Session account selection, or null.
6164
+ */
6165
+ getAccount: async () => connection.sendRequest("session.connectors.getAccount", { sessionId }),
6119
6166
  /**
6120
6167
  * Returns authoritative session Connector state from current availability, pinned account selection, cached catalog, and live MCP projection without performing a Connector service request.
6121
6168
  *
@@ -6184,7 +6231,7 @@ function createSessionRpc(connection, sessionId) {
6184
6231
  /**
6185
6232
  * Waits for the live session's in-flight managed-settings application, then returns the retained effective snapshot used by runtime enforcement and by `session.managed_settings_resolved`. It does not perform another account, device, or server resolution, and rejects when resolution has not produced a snapshot.
6186
6233
  *
6187
- * @returns Enterprise managed-settings resolution: the effective managed settings the session applied and which channels contributed, so SDK clients can show users what is enterprise-managed. Fires whenever managed policy is (re)applied — at session start, on resume, and on account switch. This is an ephemeral live snapshot (delivered to subscribers but not persisted to the session event log), because at session start it resolves before `session.start` is emitted. Device values take precedence over server values, then the policy helper, per ordinary key, while permissions compose restrictively across device, server, policy-helper, and SDK-client layers. The account-scoped `getManagedSettings()` API does not include session-local client injection. Marked experimental while the managed-settings surface stabilizes.
6234
+ * @returns Effective enterprise managed settings and contributing channels. Session events report applied policy; sessionless resolve reports an account/device snapshot, and compose reports a non-applying preview of candidate documents. Device values take precedence over server values, then the policy helper, per ordinary key, while permissions compose restrictively. Session-local SDK-client policy is included only in session results. Marked experimental while the managed-settings surface stabilizes.
6188
6235
  */
6189
6236
  get: async () => connection.sendRequest("session.managedSettings.get", { sessionId })
6190
6237
  },
@@ -9054,6 +9101,7 @@ var CopilotSession = class {
9054
9101
  sessionId;
9055
9102
  connection;
9056
9103
  _workspacePath;
9104
+ _transcriptRecovery;
9057
9105
  eventHandlers = /* @__PURE__ */ new Set();
9058
9106
  typedEventHandlers = /* @__PURE__ */ new Map();
9059
9107
  toolHandlers = /* @__PURE__ */ new Map();
@@ -9243,6 +9291,14 @@ var CopilotSession = class {
9243
9291
  get workspacePath() {
9244
9292
  return this._workspacePath;
9245
9293
  }
9294
+ /** Recovery observed while loading this session; undefined on a clean resume. */
9295
+ get transcriptRecovery() {
9296
+ return this._transcriptRecovery;
9297
+ }
9298
+ /** @internal */
9299
+ setTranscriptRecovery(recovery) {
9300
+ this._transcriptRecovery = recovery;
9301
+ }
9246
9302
  /**
9247
9303
  * Host capabilities reported when the session was created or resumed.
9248
9304
  * Use this to check feature support before calling capability-gated APIs.
@@ -11447,6 +11503,7 @@ var CopilotClient = class _CopilotClient {
11447
11503
  requestAdapter = null;
11448
11504
  messageWriter = null;
11449
11505
  connectionClosed = false;
11506
+ connectionEpoch = 0;
11450
11507
  socket = null;
11451
11508
  runtimePort = null;
11452
11509
  actualHost = "localhost";
@@ -11856,6 +11913,7 @@ var CopilotClient = class _CopilotClient {
11856
11913
  }
11857
11914
  async doStart() {
11858
11915
  this.forceStopping = false;
11916
+ this.connectionEpoch++;
11859
11917
  this.connectionClosed = false;
11860
11918
  this.processTransportError = null;
11861
11919
  this.state = "connecting";
@@ -11891,6 +11949,9 @@ var CopilotClient = class _CopilotClient {
11891
11949
  if (this.requestHandler) {
11892
11950
  await this.connection.sendRequest("llmInference.setProvider", {});
11893
11951
  }
11952
+ if (this.connectionClosed) {
11953
+ throw new Error("CLI server connection closed during startup");
11954
+ }
11894
11955
  this.state = "connected";
11895
11956
  } catch (error) {
11896
11957
  const startupError = this.processTransportError ?? error;
@@ -12010,10 +12071,23 @@ var CopilotClient = class _CopilotClient {
12010
12071
  this.socket = null;
12011
12072
  try {
12012
12073
  if (!socket.destroyed) {
12013
- await new Promise((resolve22) => {
12014
- socket.once("close", () => resolve22());
12015
- socket.end();
12016
- });
12074
+ let timeout;
12075
+ try {
12076
+ await new Promise((resolve22) => {
12077
+ socket.once("close", () => resolve22());
12078
+ if (this.connectionClosed) {
12079
+ socket.destroy();
12080
+ } else {
12081
+ timeout = setTimeout(
12082
+ () => socket.destroy(),
12083
+ RUNTIME_SHUTDOWN_TIMEOUT_MS
12084
+ );
12085
+ socket.end();
12086
+ }
12087
+ });
12088
+ } finally {
12089
+ if (timeout !== void 0) clearTimeout(timeout);
12090
+ }
12017
12091
  }
12018
12092
  } catch (error) {
12019
12093
  errors.push(
@@ -12676,6 +12750,7 @@ var CopilotClient = class _CopilotClient {
12676
12750
  allowedModels: config.allowedModels,
12677
12751
  ...await getTraceContext(this.onGetTraceContext),
12678
12752
  sessionId,
12753
+ allowTranscriptRecovery: config.allowTranscriptRecovery,
12679
12754
  clientName: config.clientName,
12680
12755
  model: config.model,
12681
12756
  reasoningEffort: config.reasoningEffort,
@@ -12782,10 +12857,11 @@ var CopilotClient = class _CopilotClient {
12782
12857
  }
12783
12858
  }
12784
12859
  }
12785
- const { workspacePath, capabilities, openCanvases } = response;
12860
+ const { workspacePath, capabilities, openCanvases, transcriptRecovery } = response;
12786
12861
  session["_workspacePath"] = workspacePath;
12787
12862
  session.setCapabilities(capabilities);
12788
12863
  session.setOpenCanvases(openCanvases ?? []);
12864
+ session.setTranscriptRecovery(transcriptRecovery);
12789
12865
  if (config.onMcpAuthRequest) {
12790
12866
  await this.connection.sendRequest("session.eventLog.registerInterest", {
12791
12867
  sessionId,
@@ -13774,8 +13850,13 @@ stderr: ${stderrOutput}` : ""}`
13774
13850
  );
13775
13851
  const connection = this.connection;
13776
13852
  const messageWriter = this.messageWriter;
13853
+ const cliProcess = this.isExternalServer ? null : this.cliProcess;
13854
+ const connectionEpoch = this.connectionEpoch;
13855
+ const isCurrentConnection = () => connectionEpoch === this.connectionEpoch && this.connection === connection && (cliProcess === null || this.cliProcess === cliProcess);
13856
+ let disconnecting = false;
13857
+ let exitFallback;
13777
13858
  const markDisconnected = () => {
13778
- if (this.connection !== connection) {
13859
+ if (!isCurrentConnection()) {
13779
13860
  connection.dispose();
13780
13861
  return;
13781
13862
  }
@@ -13789,13 +13870,48 @@ stderr: ${stderrOutput}` : ""}`
13789
13870
  this.githubTokenProviders.clear();
13790
13871
  this.requestAdapter?.cancelPending();
13791
13872
  connection.dispose();
13873
+ this.socket?.destroy();
13874
+ this.connection = null;
13875
+ this.messageWriter = null;
13876
+ this._rpc = null;
13877
+ this._internalRpc = null;
13878
+ this.modelsCache = null;
13792
13879
  };
13793
- this.connection.onClose(() => {
13880
+ const disconnectAfterDrain = () => {
13881
+ if (exitFallback !== void 0) {
13882
+ clearTimeout(exitFallback);
13883
+ exitFallback = void 0;
13884
+ }
13885
+ if (!isCurrentConnection()) {
13886
+ connection.dispose();
13887
+ return;
13888
+ }
13889
+ if (disconnecting) return;
13890
+ disconnecting = true;
13891
+ this.connectionClosed = true;
13794
13892
  if (messageWriter) messageWriter.suppressWriteErrors = true;
13795
13893
  void connection.drain().then(markDisconnected);
13796
- });
13894
+ };
13895
+ this.connection.onClose(disconnectAfterDrain);
13896
+ if (cliProcess) {
13897
+ cliProcess.once("exit", () => {
13898
+ if (!isCurrentConnection()) {
13899
+ connection.dispose();
13900
+ return;
13901
+ }
13902
+ if (disconnecting) return;
13903
+ if (this.socket) {
13904
+ disconnectAfterDrain();
13905
+ return;
13906
+ }
13907
+ this.connectionClosed = true;
13908
+ if (messageWriter) messageWriter.suppressWriteErrors = true;
13909
+ exitFallback = setTimeout(disconnectAfterDrain, RUNTIME_SHUTDOWN_TIMEOUT_MS);
13910
+ exitFallback.unref();
13911
+ });
13912
+ }
13797
13913
  this.connection.onError(() => {
13798
- if (this.connection === connection) {
13914
+ if (connectionEpoch === this.connectionEpoch && this.connection === connection) {
13799
13915
  this.state = "disconnected";
13800
13916
  }
13801
13917
  });
@@ -1,7 +1,7 @@
1
1
  import { createSessionRpc } from "./generated/rpc.js";
2
2
  import type { ModelSwitchAutoTierResult } from "./generated/rpc.js";
3
3
  import type { OpenCanvasInstance } from "./generated/rpc.js";
4
- import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
4
+ import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TranscriptRecovery, TypedSessionEventHandler } from "./types.js";
5
5
  import { type SessionWorkflowApi } from "./workflow.js";
6
6
  /** Assistant message event - the final response from the assistant. */
7
7
  export type AssistantMessageEvent = Extract<SessionEvent, {
@@ -41,6 +41,7 @@ export declare class CopilotSession {
41
41
  readonly sessionId: string;
42
42
  private connection;
43
43
  private _workspacePath?;
44
+ private _transcriptRecovery?;
44
45
  private eventHandlers;
45
46
  private typedEventHandlers;
46
47
  private toolHandlers;
@@ -97,6 +98,8 @@ export declare class CopilotSession {
97
98
  * Undefined if infinite sessions are disabled.
98
99
  */
99
100
  get workspacePath(): string | undefined;
101
+ /** Recovery observed while loading this session; undefined on a clean resume. */
102
+ get transcriptRecovery(): TranscriptRecovery | undefined;
100
103
  /**
101
104
  * Host capabilities reported when the session was created or resumed.
102
105
  * Use this to check feature support before calling capability-gated APIs.
@@ -14,7 +14,7 @@ import type { ToolSet } from "./toolSet.js";
14
14
  export type { RemoteSessionMode } from "./generated/rpc.js";
15
15
  export type { CurrentToolMetadata } from "./generated/rpc.js";
16
16
  export type { SandboxConfigSource } from "./generated/rpc.js";
17
- export type { ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorStatus, ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, } from "./generated/rpc.js";
17
+ export type { AuthIdentityMetadata, AuthInfoType, ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorSessionAccount, ConnectorSessionAccountResult, ConnectorStatus, ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, } from "./generated/rpc.js";
18
18
  /**
19
19
  * Arguments passed to a session's {@link GitHubTokenProvider}.
20
20
  *
@@ -2444,6 +2444,11 @@ export interface SessionConfig extends SessionConfigBase {
2444
2444
  * {@link CopilotClient.resumeSession}.
2445
2445
  */
2446
2446
  export interface ResumeSessionConfig extends SessionConfigBase {
2447
+ /**
2448
+ * Allow the runtime to recover a damaged transcript during resume.
2449
+ * Defaults to true in all modes. Set false to reject recovery.
2450
+ */
2451
+ allowTranscriptRecovery?: boolean;
2447
2452
  /**
2448
2453
  * When true, skips emitting the session.resume event.
2449
2454
  * Useful for reconnecting to a session without triggering resume-related side effects.
@@ -2453,7 +2458,8 @@ export interface ResumeSessionConfig extends SessionConfigBase {
2453
2458
  /**
2454
2459
  * When true, the runtime continues any tool calls or permission prompts that were
2455
2460
  * still pending when the session was last suspended. When false (the default), the
2456
- * runtime treats pending work as interrupted on resume.
2461
+ * runtime treats pending work as interrupted on resume. Completed tool results
2462
+ * already durably recorded by the runtime are preserved.
2457
2463
  *
2458
2464
  * For permission requests, the runtime re-emits `permission.requested` so the
2459
2465
  * registered `onPermissionRequest` handler can re-prompt; for external tool calls,
@@ -2469,6 +2475,15 @@ export interface ResumeSessionConfig extends SessionConfigBase {
2469
2475
  */
2470
2476
  openCanvases?: OpenCanvasInstance[];
2471
2477
  }
2478
+ /** Transcript repair proposed during the most recent resume. */
2479
+ export interface TranscriptRecovery {
2480
+ /** Planned backup path; the backup is written on the next append. */
2481
+ plannedBackupPath: string;
2482
+ /** One-based physical line numbers removed from the transcript. */
2483
+ invalidLineNumbers: number[];
2484
+ /** Whether an existing session.start event was moved to the beginning. */
2485
+ sessionStartMoved: boolean;
2486
+ }
2472
2487
  /**
2473
2488
  * Arguments passed to a {@link BearerTokenProvider} callback when the runtime needs a
2474
2489
  * fresh bearer token for a BYOK provider.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@github/copilot-sdk-win32-x64",
3
- "version": "1.0.16",
3
+ "version": "1.0.17-preview.0",
4
4
  "description": "Platform runtime for @github/copilot-sdk (win32-x64)",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/github/copilot-sdk.git"
7
+ "url": "https://github.com/github/copilot-agent-runtime.git",
8
+ "directory": "src/sdk/nodejs"
8
9
  },
9
10
  "license": "MIT",
10
11
  "os": [
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/prebuilds/win32-x64/runtime.node
3
- size: 104111904 bytes
4
- sha256: 41ebb48367f96c984babde61afb68f22a85ab8fd9c037fdccf1778881c4bba05
3
+ size: 104363296 bytes
4
+ sha256: 6abed5dc44c7982d5886f291f5b1ddd410d61e7cf22422f3144a683a88e0ba6c
Binary file