@f5-sales-demo/xcsh 21.21.0 → 21.21.2

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.
package/CHANGELOG.md CHANGED
@@ -48,6 +48,9 @@
48
48
 
49
49
  ### Fixed
50
50
 
51
+ - Routed MCP and Gemini web-search OAuth refreshes through the shared durable refresh coordinator,
52
+ including proactive refresh and forced retry after authentication failures
53
+ ([#3796](https://github.com/f5-sales-demo/xcsh/issues/3796)).
51
54
  - Kept `/login` honest after live validation by reporting reachable keyless vLLM services as
52
55
  `keyless configured` and unreachable keyless services as `unreachable`
53
56
  ([#3783](https://github.com/f5-sales-demo/xcsh/issues/3783)).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5-sales-demo/xcsh",
4
- "version": "21.21.0",
4
+ "version": "21.21.2",
5
5
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
6
6
  "homepage": "https://github.com/f5-sales-demo/xcsh",
7
7
  "author": "Can Boluk",
@@ -62,13 +62,13 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@agentclientprotocol/sdk": "1.3.0",
65
- "@f5-sales-demo/pi-agent-core": "21.21.0",
66
- "@f5-sales-demo/pi-ai": "21.21.0",
67
- "@f5-sales-demo/pi-natives": "21.21.0",
68
- "@f5-sales-demo/pi-resource-management": "21.21.0",
69
- "@f5-sales-demo/pi-tui": "21.21.0",
70
- "@f5-sales-demo/pi-utils": "21.21.0",
71
- "@f5-sales-demo/xcsh-stats": "21.21.0",
65
+ "@f5-sales-demo/pi-agent-core": "21.21.2",
66
+ "@f5-sales-demo/pi-ai": "21.21.2",
67
+ "@f5-sales-demo/pi-natives": "21.21.2",
68
+ "@f5-sales-demo/pi-resource-management": "21.21.2",
69
+ "@f5-sales-demo/pi-tui": "21.21.2",
70
+ "@f5-sales-demo/pi-utils": "21.21.2",
71
+ "@f5-sales-demo/xcsh-stats": "21.21.2",
72
72
  "@mozilla/readability": "^0.6",
73
73
  "@sinclair/typebox": "^0.34",
74
74
  "@xterm/headless": "^6.0",
@@ -2569,7 +2569,7 @@ export interface ProviderConfigInput {
2569
2569
  oauth?: {
2570
2570
  name: string;
2571
2571
  login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials | string>;
2572
- refreshToken?(credentials: OAuthCredentials): Promise<OAuthCredentials>;
2572
+ refreshToken?(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;
2573
2573
  getApiKey?(credentials: OAuthCredentials): string;
2574
2574
  modifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];
2575
2575
  };
@@ -171,6 +171,11 @@ function nativeCapability(): string | undefined {
171
171
  return typeof value === "string" && value.length > 0 ? value : undefined;
172
172
  }
173
173
 
174
+ /** Protocol 23 adds a workspace receipt without changing native action semantics. */
175
+ function supportsNativeLifecycle(protocol: number | undefined): boolean {
176
+ return protocol === 22 || protocol === 23;
177
+ }
178
+
174
179
  function persistedTurns(ctx: ExtensionContext): PersistedTurn[] {
175
180
  try {
176
181
  const entries = ctx.sessionManager?.getEntries?.() as unknown[] | undefined;
@@ -476,12 +481,12 @@ export default function herdrReporter(pi: ExtensionAPI): void {
476
481
  }
477
482
  const capability = nativeCapability();
478
483
  const frame =
479
- client.protocolVersion === 22 && capability
484
+ supportsNativeLifecycle(client.protocolVersion) && capability
480
485
  ? { ...baseFrame, native_capability: capability }
481
486
  : baseFrame;
482
487
  const response = await client.request<Record<string, unknown>>(TURN_REPORT_METHOD, frame);
483
- if (client.protocolVersion === 22 && response.type !== "agent_turn") {
484
- throw new Error("Herdr did not confirm the protocol-22 turn journal write");
488
+ if (supportsNativeLifecycle(client.protocolVersion) && response.type !== "agent_turn") {
489
+ throw new Error("Herdr did not confirm the native turn journal write");
485
490
  }
486
491
  pi.appendEntry(TURN_ENTRY_TYPE, { ...event, delivered: true });
487
492
  delivered = true;
@@ -522,7 +527,7 @@ export default function herdrReporter(pi: ExtensionAPI): void {
522
527
  try {
523
528
  const client = getHerdrClient(socketPath);
524
529
  await client.ensureProtocol();
525
- if (client.protocolVersion !== 22) return false;
530
+ if (!supportsNativeLifecycle(client.protocolVersion)) return false;
526
531
  const response = await client.request<Record<string, unknown>>(TURN_ACTION_ACK_METHOD, {
527
532
  ...target,
528
533
  action_id: action.actionId,
@@ -679,7 +684,8 @@ export default function herdrReporter(pi: ExtensionAPI): void {
679
684
  const registered = await reportSemanticTurn("starting");
680
685
  const socketPath = process.env.HERDR_SOCKET_PATH;
681
686
  const client = socketPath ? getHerdrClient(socketPath) : undefined;
682
- nativeActionsEnabled = registered && client?.protocolVersion === 22 && nativeCapability() !== undefined;
687
+ nativeActionsEnabled =
688
+ registered && supportsNativeLifecycle(client?.protocolVersion) && nativeCapability() !== undefined;
683
689
  if (nativeActionsEnabled) startActionPolling(ctx);
684
690
  };
685
691
 
@@ -1245,7 +1245,7 @@ export interface ProviderConfig {
1245
1245
  /** Run the provider login flow and return credentials (or a plain API key) to persist. */
1246
1246
  login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials | string>;
1247
1247
  /** Refresh expired credentials. */
1248
- refreshToken?(credentials: OAuthCredentials): Promise<OAuthCredentials>;
1248
+ refreshToken?(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;
1249
1249
  /** Convert credentials to an API key string for requests. */
1250
1250
  getApiKey?(credentials: OAuthCredentials): string;
1251
1251
  /** Optional model rewrite hook for credential-aware routing (e.g., enterprise URLs). */
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { connect } from "node:net";
3
3
 
4
4
  export const HERDR_PROTOCOL_MIN_VERSION = 19;
5
- export const HERDR_PROTOCOL_MAX_VERSION = 22;
5
+ export const HERDR_PROTOCOL_MAX_VERSION = 23;
6
6
  const DEFAULT_TIMEOUT_MS = 5_000;
7
7
  const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
8
8
 
@@ -17,17 +17,17 @@ export interface BuildInfo {
17
17
  }
18
18
 
19
19
  export const BUILD_INFO: BuildInfo = {
20
- "version": "21.21.0",
21
- "commit": "1d087d1f95b4fd1cfebe3d6dcb1b156e8212733c",
22
- "shortCommit": "1d087d1",
20
+ "version": "21.21.2",
21
+ "commit": "543254c7b2d3468a5af620a1905064da069837eb",
22
+ "shortCommit": "543254c",
23
23
  "branch": "main",
24
- "tag": "v21.21.0",
25
- "commitDate": "2026-09-09T11:06:00+00:00",
26
- "buildDate": "2026-09-09T12:00:55.126Z",
24
+ "tag": "v21.21.2",
25
+ "commitDate": "2026-09-09T14:40:15+00:00",
26
+ "buildDate": "2026-09-09T15:51:38.046Z",
27
27
  "dirty": true,
28
28
  "prNumber": "",
29
29
  "repoUrl": "https://github.com/f5-sales-demo/xcsh",
30
30
  "repoSlug": "f5-sales-demo/xcsh",
31
- "commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/1d087d1f95b4fd1cfebe3d6dcb1b156e8212733c",
32
- "releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.21.0"
31
+ "commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/543254c7b2d3468a5af620a1905064da069837eb",
32
+ "releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.21.2"
33
33
  };
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import * as path from "node:path";
8
8
  import * as url from "node:url";
9
+ import { isDefinitiveOAuthFailure } from "@f5-sales-demo/pi-ai";
9
10
  import { logger } from "@f5-sales-demo/pi-utils";
10
11
  import type { TSchema } from "@sinclair/typebox";
11
12
  import type { SourceMeta } from "../capability/types";
@@ -593,8 +594,8 @@ export class MCPManager {
593
594
  /**
594
595
  * Resolve auth and shell-command substitutions in config before connecting.
595
596
  */
596
- async prepareConfig(config: MCPServerConfig): Promise<MCPServerConfig> {
597
- return this.#resolveAuthConfig(config);
597
+ async prepareConfig(config: MCPServerConfig, forceRefresh = false): Promise<MCPServerConfig> {
598
+ return this.#resolveAuthConfig(config, forceRefresh);
598
599
  }
599
600
 
600
601
  /**
@@ -1071,15 +1072,32 @@ export class MCPManager {
1071
1072
  forceRefresh || (credential.expires && Date.now() >= credential.expires - REFRESH_BUFFER_MS);
1072
1073
  if (shouldRefresh && credential.refresh && auth.tokenUrl) {
1073
1074
  try {
1074
- const refreshed = await refreshMCPOAuthToken(
1075
- auth.tokenUrl,
1076
- credential.refresh,
1077
- auth.clientId,
1078
- auth.clientSecret,
1079
- );
1080
- const refreshedCredential = { type: "oauth" as const, ...refreshed };
1081
- await this.#authStorage.set(credentialId, refreshedCredential);
1082
- credential = refreshedCredential;
1075
+ const row = this.#authStorage
1076
+ .listStoredCredentials(credentialId)
1077
+ .find(entry => entry.credential.type === "oauth");
1078
+ if (row?.credential.type === "oauth") {
1079
+ const outcome = await this.#authStorage.refreshStoredOAuthCredential(credentialId, {
1080
+ credentialId: row.id,
1081
+ observedCredential: credential,
1082
+ credentialFromRow: current => current,
1083
+ forceRefresh,
1084
+ refreshSkewMs: REFRESH_BUFFER_MS,
1085
+ canRefresh: current => Boolean(current.refresh && auth.tokenUrl),
1086
+ refresh: (current, signal) =>
1087
+ refreshMCPOAuthToken(
1088
+ auth.tokenUrl!,
1089
+ current.refresh,
1090
+ auth.clientId,
1091
+ auth.clientSecret,
1092
+ signal,
1093
+ ),
1094
+ isDefinitiveFailure: isDefinitiveOAuthFailure,
1095
+ disabledCause: error =>
1096
+ `oauth refresh failed: ${error instanceof Error ? error.message : String(error)}`,
1097
+ keepCredentialOnRefreshFailure: true,
1098
+ });
1099
+ credential = outcome.credential;
1100
+ }
1083
1101
  } catch (refreshError) {
1084
1102
  logger.warn("MCP OAuth refresh failed, using existing token", {
1085
1103
  credentialId,
@@ -1088,22 +1106,24 @@ export class MCPManager {
1088
1106
  }
1089
1107
  }
1090
1108
 
1091
- if (resolved.type === "http" || resolved.type === "sse") {
1092
- resolved = {
1093
- ...resolved,
1094
- headers: {
1095
- ...resolved.headers,
1096
- Authorization: `Bearer ${credential.access}`,
1097
- },
1098
- };
1099
- } else {
1100
- resolved = {
1101
- ...resolved,
1102
- env: {
1103
- ...resolved.env,
1104
- OAUTH_ACCESS_TOKEN: credential.access,
1105
- },
1106
- };
1109
+ if (credential) {
1110
+ if (resolved.type === "http" || resolved.type === "sse") {
1111
+ resolved = {
1112
+ ...resolved,
1113
+ headers: {
1114
+ ...resolved.headers,
1115
+ Authorization: `Bearer ${credential.access}`,
1116
+ },
1117
+ };
1118
+ } else {
1119
+ resolved = {
1120
+ ...resolved,
1121
+ env: {
1122
+ ...resolved.env,
1123
+ OAUTH_ACCESS_TOKEN: credential.access,
1124
+ },
1125
+ };
1126
+ }
1107
1127
  }
1108
1128
  }
1109
1129
  } catch (error) {
@@ -352,8 +352,9 @@ export class MCPOAuthFlow extends OAuthCallbackFlow {
352
352
  export async function refreshMCPOAuthToken(
353
353
  tokenUrl: string,
354
354
  refreshToken: string,
355
- clientId?: string,
356
- clientSecret?: string,
355
+ clientId: string | undefined,
356
+ clientSecret: string | undefined,
357
+ signal: AbortSignal,
357
358
  ): Promise<OAuthCredentials> {
358
359
  const params = new URLSearchParams({
359
360
  grant_type: "refresh_token",
@@ -366,11 +367,21 @@ export async function refreshMCPOAuthToken(
366
367
  method: "POST",
367
368
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
368
369
  body: params.toString(),
370
+ signal,
369
371
  });
370
372
 
371
373
  if (!response.ok) {
372
- const text = await response.text();
373
- throw new Error(`MCP OAuth refresh failed: ${response.status} ${text}`);
374
+ let payload: unknown;
375
+ try {
376
+ payload = await response.json();
377
+ } catch {
378
+ payload = undefined;
379
+ }
380
+ const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : undefined;
381
+ const rawCode = (record as { error?: unknown } | undefined)?.error;
382
+ const code =
383
+ typeof rawCode === "string" && /^[a-z][a-z0-9_.-]{0,63}$/i.test(rawCode.trim()) ? rawCode.trim() : undefined;
384
+ throw new Error(`MCP OAuth refresh failed (HTTP ${response.status}${code ? `; error=${code}` : ""})`);
374
385
  }
375
386
 
376
387
  const data = (await response.json()) as {
@@ -7,13 +7,14 @@
7
7
  */
8
8
  import {
9
9
  ANTIGRAVITY_SYSTEM_INSTRUCTION,
10
+ AuthStorage,
10
11
  extractRetryDelay,
11
12
  getAntigravityHeaders,
12
13
  getGeminiCliHeaders,
13
- refreshGoogleCloudToken,
14
+ isDefinitiveOAuthFailure,
15
+ refreshOAuthToken,
14
16
  } from "@f5-sales-demo/pi-ai";
15
17
  import { getAgentDbPath } from "@f5-sales-demo/pi-utils";
16
- import { AgentStorage } from "../../../session/agent-storage";
17
18
  import type { SearchCitation, SearchResponse, SearchSource } from "../../../web/search/types";
18
19
  import { SearchProviderError } from "../../../web/search/types";
19
20
  import type { SearchParams } from "./base";
@@ -55,23 +56,12 @@ export function buildGeminiRequestTools(params: GeminiToolParams): Array<Record<
55
56
  return tools;
56
57
  }
57
58
 
58
- /** OAuth credential stored in agent.db */
59
- interface GeminiOAuthCredential {
60
- type: "oauth";
61
- access: string;
62
- refresh?: string;
63
- expires: number;
64
- projectId?: string;
65
- }
66
-
67
59
  /** Auth info for Gemini API requests */
68
60
  interface GeminiAuth {
69
61
  accessToken: string;
70
62
  refreshToken?: string;
71
63
  projectId: string;
72
64
  isAntigravity: boolean;
73
- storage: AgentStorage;
74
- credentialId: number;
75
65
  }
76
66
 
77
67
  /**
@@ -80,72 +70,49 @@ interface GeminiAuth {
80
70
  * @returns OAuth credential with access token and project ID, or null if none found
81
71
  */
82
72
  export async function findGeminiAuth(): Promise<GeminiAuth | null> {
83
- const expiryBuffer = 5 * 60 * 1000; // 5 minutes
84
- const now = Date.now();
85
-
86
73
  // Try providers in deterministic order: gemini-cli first, then antigravity
87
74
  const providers = ["google-gemini-cli", "google-antigravity"] as const;
75
+ let storage: AuthStorage | undefined;
88
76
 
89
77
  try {
90
- const storage = await AgentStorage.open(getAgentDbPath());
78
+ storage = await AuthStorage.create(getAgentDbPath());
91
79
 
92
80
  for (const provider of providers) {
93
- const records = storage.listAuthCredentials(provider);
81
+ const records = storage.listStoredCredentials(provider);
94
82
 
95
83
  for (const record of records) {
96
84
  const credential = record.credential;
97
85
  if (credential.type !== "oauth") continue;
98
-
99
- const oauthCred = credential as GeminiOAuthCredential;
100
- if (!oauthCred.access) continue;
101
-
102
- // Get projectId from credential
103
- const projectId = oauthCred.projectId;
104
- if (!projectId) continue;
105
-
106
- // Check if token is expired (or about to expire)
107
- if (oauthCred.expires <= now + expiryBuffer) {
108
- // Try to refresh if we have a refresh token
109
- if (oauthCred.refresh) {
110
- try {
111
- const refreshed = await refreshGoogleCloudToken(oauthCred.refresh, projectId);
112
- // Update the credential in storage
113
- const updated = {
114
- ...oauthCred,
115
- access: refreshed.access,
116
- refresh: refreshed.refresh ?? oauthCred.refresh,
117
- expires: refreshed.expires,
118
- };
119
- storage.updateAuthCredential(record.id, updated);
120
- return {
121
- accessToken: refreshed.access,
122
- refreshToken: refreshed.refresh ?? oauthCred.refresh,
123
- projectId,
124
- isAntigravity: provider === "google-antigravity",
125
- storage,
126
- credentialId: record.id,
127
- };
128
- } catch {
129
- // Refresh failed, skip this credential
130
- continue;
131
- }
132
- }
133
- // No refresh token or refresh failed
134
- continue;
86
+ if (!credential.access || !credential.projectId) continue;
87
+ try {
88
+ const outcome = await storage.refreshStoredOAuthCredential(provider, {
89
+ credentialId: record.id,
90
+ observedCredential: credential,
91
+ credentialFromRow: current => current,
92
+ refreshSkewMs: 5 * 60_000,
93
+ canRefresh: current => Boolean(current.refresh && current.projectId),
94
+ refresh: (current, signal) => refreshOAuthToken(provider, current, signal),
95
+ isDefinitiveFailure: isDefinitiveOAuthFailure,
96
+ disabledCause: error =>
97
+ `oauth refresh failed: ${error instanceof Error ? error.message : String(error)}`,
98
+ });
99
+ const current = outcome.credential;
100
+ if (!current?.access || !current.projectId || outcome.reauthenticationRequired) continue;
101
+ return {
102
+ accessToken: current.access,
103
+ refreshToken: current.refresh,
104
+ projectId: current.projectId,
105
+ isAntigravity: provider === "google-antigravity",
106
+ };
107
+ } catch {
108
+ // Refresh failed; try the next credential.
135
109
  }
136
-
137
- return {
138
- accessToken: oauthCred.access,
139
- refreshToken: oauthCred.refresh,
140
- projectId,
141
- isAntigravity: provider === "google-antigravity",
142
- storage,
143
- credentialId: record.id,
144
- };
145
110
  }
146
111
  }
147
112
  } catch {
148
113
  return null;
114
+ } finally {
115
+ storage?.close();
149
116
  }
150
117
 
151
118
  return null;