@bike4mind/cli 4.6.0 → 4.9.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.
- package/README.md +119 -0
- package/bin/bike4mind-cli.mjs +342 -239
- package/dist/{AgentHistoryStore--J3sgO_-.mjs → AgentHistoryStore-jktM0SmD.mjs} +140 -73
- package/dist/{ApiClient-CdO4Gamg.mjs → ApiClient-CczpydlW.mjs} +3 -3
- package/dist/{BubblewrapRuntime-3jAbC60G.mjs → BubblewrapRuntime-aGfDSJPY.mjs} +2 -2
- package/dist/ConfigStore-BAJ4hIHa.mjs +2 -0
- package/dist/{ConfigStore-Dusy6glb.mjs → ConfigStore-CO6kREaL.mjs} +101 -27
- package/dist/{Logger-C1Wj6xla.mjs → Logger-CHKCF5hd.mjs} +5095 -495
- package/dist/{RemoteSkillSource-qTvRkaNA.mjs → RemoteSkillSource-D_F99yBR.mjs} +5 -0
- package/dist/{SandboxOrchestrator-CQwYq_uy.mjs → SandboxOrchestrator-ULWvuUct.mjs} +1 -1
- package/dist/{SandboxRuntimeAdapter-BsT2iLky.mjs → SandboxRuntimeAdapter-DpDSET-A.mjs} +2 -2
- package/dist/{SandboxRuntimeAdapter-Zg_0th7V.mjs → SandboxRuntimeAdapter-FpZRkE6D.mjs} +1 -1
- package/dist/{SeatbeltRuntime-C2DEkrjy.mjs → SeatbeltRuntime-C0GJ3nnY.mjs} +2 -2
- package/dist/{WorkItemsClient-CxNZaOmc.mjs → WorkItemsClient-aCxMV_Wm.mjs} +1 -1
- package/dist/{buildToolSearch-DOb7mx6F.mjs → buildToolSearch-CbLeZ5wP.mjs} +2 -2
- package/dist/commands/acpCommand.mjs +6 -6
- package/dist/commands/apiCommand.mjs +1 -1
- package/dist/commands/doctorCommand.mjs +2 -2
- package/dist/commands/envCommand.mjs +1 -1
- package/dist/commands/headlessCommand.mjs +7 -7
- package/dist/commands/hostCommand.mjs +2 -2
- package/dist/commands/mcpCommand.mjs +3 -3
- package/dist/commands/mirrorCommand.mjs +2 -2
- package/dist/commands/modelsCommand.mjs +5 -5
- package/dist/commands/pluginCommand.mjs +1 -1
- package/dist/commands/skillsCommand.mjs +4 -4
- package/dist/commands/updateCommand.mjs +2 -2
- package/dist/{dist-CbViwiS9.mjs → dist-BOxr8LQA.mjs} +185 -12
- package/dist/{dist-Citbv0y0.mjs → dist-K7a9yOUb.mjs} +3 -3
- package/dist/{fit-CVWDiavv.mjs → fit-BHDTSpfd.mjs} +4 -4
- package/dist/{grepSearch-BgoOOwGe-B388GxRD.mjs → grepSearch-CLtEqT4j-BnKPtNWr.mjs} +2 -2
- package/dist/index.mjs +2780 -251
- package/dist/{modelServers-BaegigV-.mjs → modelServers-CVufZd1f.mjs} +2 -2
- package/dist/{package-C9pfAdGF.mjs → package-TACInPbw.mjs} +1 -1
- package/dist/{serve-8wyGb8of.mjs → serve-OywSzShu.mjs} +733 -62
- package/dist/{store-BbvSi3KK.mjs → store-CmOg7JIt.mjs} +4 -0
- package/dist/store-OGMXhD4A.mjs +2 -0
- package/dist/{updateChecker-BAKb8KWP.mjs → updateChecker-5v_8LhXy.mjs} +1 -1
- package/package.json +14 -14
- package/dist/ConfigStore-CausUCzY.mjs +0 -2
- package/dist/store-BYeE0shc.mjs +0 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { T as ChatModels, t as logger } from "./Logger-CHKCF5hd.mjs";
|
|
3
3
|
import { t as DEFAULT_SANDBOX_CONFIG } from "./types-CxrzVXel.mjs";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
5
|
import { existsSync, promises } from "fs";
|
|
5
6
|
import { homedir, hostname } from "os";
|
|
6
7
|
import path from "path";
|
|
@@ -10,7 +11,6 @@ import * as fs from "node:fs";
|
|
|
10
11
|
import { z as z$1 } from "zod";
|
|
11
12
|
import axios, { isAxiosError } from "axios";
|
|
12
13
|
import { createHash } from "node:crypto";
|
|
13
|
-
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import { homedir as homedir$1 } from "node:os";
|
|
15
15
|
//#region src/utils/sanitizeTerminalText.ts
|
|
16
16
|
/**
|
|
@@ -195,6 +195,15 @@ var NotAuthenticatedError = class extends Error {
|
|
|
195
195
|
this.name = "NotAuthenticatedError";
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
+
/** A captured session no longer owns this operation. */
|
|
199
|
+
var SessionChangedError = class extends Error {
|
|
200
|
+
beforeRequest;
|
|
201
|
+
constructor(beforeRequest = false) {
|
|
202
|
+
super("The account or environment changed. Please try again from the current session.");
|
|
203
|
+
this.beforeRequest = beforeRequest;
|
|
204
|
+
this.name = "SessionChangedError";
|
|
205
|
+
}
|
|
206
|
+
};
|
|
198
207
|
/** Enough of an error body to classify it; a 401 body is a few hundred bytes. */
|
|
199
208
|
const ERROR_BODY_LIMIT = 65536;
|
|
200
209
|
function isReadableStream(data) {
|
|
@@ -228,7 +237,8 @@ function bearerToken(config) {
|
|
|
228
237
|
* Authenticated API client for B4M services.
|
|
229
238
|
* Injects access tokens from the supplied {@link TokenStore} and refreshes them on a 401.
|
|
230
239
|
*/
|
|
231
|
-
var AuthenticatedApiClient = class {
|
|
240
|
+
var AuthenticatedApiClient = class AuthenticatedApiClient {
|
|
241
|
+
options;
|
|
232
242
|
client;
|
|
233
243
|
tokenStore;
|
|
234
244
|
oauthClient;
|
|
@@ -240,8 +250,10 @@ var AuthenticatedApiClient = class {
|
|
|
240
250
|
refreshUnexpiredOn401;
|
|
241
251
|
reauthMessages;
|
|
242
252
|
/** The one refresh exchange in flight, shared by every caller - see {@link refreshSession}. */
|
|
243
|
-
|
|
253
|
+
refreshState = { inFlight: null };
|
|
254
|
+
sessionAdapters = /* @__PURE__ */ new WeakMap();
|
|
244
255
|
constructor(options) {
|
|
256
|
+
this.options = options;
|
|
245
257
|
this.tokenStore = options.tokenStore;
|
|
246
258
|
this.oauthClient = options.oauthClient;
|
|
247
259
|
this.logger = options.logger;
|
|
@@ -266,31 +278,37 @@ var AuthenticatedApiClient = class {
|
|
|
266
278
|
});
|
|
267
279
|
this.client.interceptors.request.use(async (config) => {
|
|
268
280
|
if (this.apiKey) {
|
|
281
|
+
this.assertSession(null, !("_retry" in config && config._retry === true));
|
|
282
|
+
this.guardTransport(config, null);
|
|
269
283
|
config.headers["x-api-key"] = this.apiKey;
|
|
270
284
|
return config;
|
|
271
285
|
}
|
|
272
286
|
const tokens = await this.tokenStore.getAuthTokens();
|
|
287
|
+
this.assertSession(tokens, !("_retry" in config && config._retry === true));
|
|
288
|
+
if (this.options.isSessionCurrent && !tokens) throw new SessionChangedError(!("_retry" in config && config._retry === true));
|
|
289
|
+
this.guardTransport(config, tokens);
|
|
273
290
|
if (tokens) config.headers.Authorization = `Bearer ${tokens.accessToken}`;
|
|
274
291
|
return config;
|
|
275
292
|
}, (error) => Promise.reject(error));
|
|
276
293
|
this.client.interceptors.response.use((response) => response, async (error) => {
|
|
277
294
|
const originalRequest = error.config;
|
|
278
295
|
if (error.response?.status === 401) this.logger.debug("AUTH: Received 401 Unauthorized");
|
|
279
|
-
else if (error.response?.status === 403) this.logger.error("403 Forbidden"
|
|
296
|
+
else if (error.response?.status === 403) this.logger.error("AUTH: Received 403 Forbidden");
|
|
280
297
|
if (this.apiKey) return Promise.reject(error);
|
|
281
298
|
if (error.response?.status === 401) await bufferStreamedBody(error.response);
|
|
282
299
|
if (error.response?.status === 401 && this.isPassThrough401?.(error.response.data)) return Promise.reject(error);
|
|
283
300
|
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
284
301
|
originalRequest._retry = true;
|
|
285
302
|
const tokens = await this.tokenStore.getAuthTokens();
|
|
303
|
+
this.assertSession(tokens);
|
|
286
304
|
if (!tokens) throw new NotAuthenticatedError(notLoggedIn);
|
|
287
305
|
const sentAccessToken = bearerToken(originalRequest);
|
|
288
|
-
if (sentAccessToken !== tokens.accessToken && !isExpired(tokens) && !this.
|
|
306
|
+
if (sentAccessToken !== tokens.accessToken && !isExpired(tokens) && !this.refreshState.inFlight) {
|
|
289
307
|
this.logger.debug("AUTH: Retrying with the access token stored since this request was sent");
|
|
290
308
|
originalRequest.headers.Authorization = `Bearer ${tokens.accessToken}`;
|
|
291
309
|
return this.client(originalRequest);
|
|
292
310
|
}
|
|
293
|
-
if (!this.refreshUnexpiredOn401 && !isExpired(tokens) && !this.
|
|
311
|
+
if (!this.refreshUnexpiredOn401 && !isExpired(tokens) && !this.refreshState.inFlight) {
|
|
294
312
|
this.logger.debug("AUTH: Access token has not expired, skipping refresh - 401 is likely transient");
|
|
295
313
|
return Promise.reject(error);
|
|
296
314
|
}
|
|
@@ -298,9 +316,8 @@ var AuthenticatedApiClient = class {
|
|
|
298
316
|
try {
|
|
299
317
|
refreshed = await this.refreshSession(sentAccessToken);
|
|
300
318
|
} catch (refreshError) {
|
|
301
|
-
if (refreshError instanceof SessionRevokedError || refreshError instanceof NotAuthenticatedError) throw refreshError;
|
|
302
|
-
|
|
303
|
-
this.logger.warn(`AUTH: Token refresh failed: ${refreshMsg}`);
|
|
319
|
+
if (refreshError instanceof SessionRevokedError || refreshError instanceof NotAuthenticatedError || refreshError instanceof SessionChangedError) throw refreshError;
|
|
320
|
+
this.logger.warn("AUTH: Token refresh temporarily unavailable");
|
|
304
321
|
throw new Error(refreshUnavailable);
|
|
305
322
|
}
|
|
306
323
|
originalRequest.headers.Authorization = `Bearer ${refreshed.accessToken}`;
|
|
@@ -308,8 +325,10 @@ var AuthenticatedApiClient = class {
|
|
|
308
325
|
return this.client(originalRequest);
|
|
309
326
|
}
|
|
310
327
|
if (error.response?.status === 401 && originalRequest._retry) {
|
|
328
|
+
const current = await this.readStoredTokens();
|
|
329
|
+
this.assertSession(current);
|
|
311
330
|
this.logger.debug("AUTH: Token refresh retry failed");
|
|
312
|
-
this.onStillUnauthorized?.("a request was still refused after the session was refreshed");
|
|
331
|
+
if (current?.accessToken === bearerToken(originalRequest)) this.onStillUnauthorized?.("a request was still refused after the session was refreshed");
|
|
313
332
|
throw new SessionRevokedError(stillUnauthorized);
|
|
314
333
|
}
|
|
315
334
|
return Promise.reject(error);
|
|
@@ -330,11 +349,38 @@ var AuthenticatedApiClient = class {
|
|
|
330
349
|
* the one case in which the stored tokens are cleared. Any other failure (network, timeout,
|
|
331
350
|
* 5xx, 429) is rethrown as-is and leaves the tokens untouched.
|
|
332
351
|
*/
|
|
333
|
-
refreshSession(rejectedAccessToken) {
|
|
334
|
-
|
|
335
|
-
|
|
352
|
+
async refreshSession(rejectedAccessToken) {
|
|
353
|
+
await this.readStoredTokens();
|
|
354
|
+
if (!this.refreshState.inFlight) this.refreshState.inFlight = this.lockedExchange(rejectedAccessToken).finally(() => {
|
|
355
|
+
this.refreshState.inFlight = null;
|
|
356
|
+
});
|
|
357
|
+
const refreshed = await this.refreshState.inFlight;
|
|
358
|
+
this.assertSession(refreshed);
|
|
359
|
+
return refreshed;
|
|
360
|
+
}
|
|
361
|
+
/** A session-bound client that shares refresh rotations with this client. */
|
|
362
|
+
withSessionGuard(isSessionCurrent) {
|
|
363
|
+
const inherited = this.options.isSessionCurrent;
|
|
364
|
+
const fork = new AuthenticatedApiClient({
|
|
365
|
+
...this.options,
|
|
366
|
+
isSessionCurrent: (tokens) => (inherited === void 0 || inherited(tokens) === true) && isSessionCurrent(tokens) === true
|
|
336
367
|
});
|
|
337
|
-
|
|
368
|
+
fork.refreshState = this.refreshState;
|
|
369
|
+
return fork;
|
|
370
|
+
}
|
|
371
|
+
assertSession(tokens, beforeRequest = false) {
|
|
372
|
+
if (this.options.isSessionCurrent && this.options.isSessionCurrent(tokens) !== true) throw new SessionChangedError(beforeRequest);
|
|
373
|
+
}
|
|
374
|
+
guardTransport(config, tokens) {
|
|
375
|
+
if (!this.options.isSessionCurrent) return;
|
|
376
|
+
const selected = axios.getAdapter(config.adapter ?? this.client.defaults.adapter);
|
|
377
|
+
const adapter = this.sessionAdapters.get(selected) ?? selected;
|
|
378
|
+
const guarded = (request) => {
|
|
379
|
+
this.assertSession(tokens, !("_retry" in request && request._retry === true));
|
|
380
|
+
return adapter(request);
|
|
381
|
+
};
|
|
382
|
+
this.sessionAdapters.set(guarded, adapter);
|
|
383
|
+
config.adapter = guarded;
|
|
338
384
|
}
|
|
339
385
|
async lockedExchange(rejectedAccessToken) {
|
|
340
386
|
const store = this.tokenStore;
|
|
@@ -354,9 +400,11 @@ var AuthenticatedApiClient = class {
|
|
|
354
400
|
}
|
|
355
401
|
this.logger.debug("AUTH: Attempting token refresh");
|
|
356
402
|
let response;
|
|
403
|
+
this.assertSession(presented);
|
|
357
404
|
try {
|
|
358
405
|
response = await this.oauthClient.refreshToken(presented.refreshToken);
|
|
359
406
|
} catch (refreshError) {
|
|
407
|
+
if (this.options.isSessionCurrent) await this.readStoredTokens();
|
|
360
408
|
const status = isAxiosError(refreshError) ? refreshError.response?.status : void 0;
|
|
361
409
|
if (status !== 400 && status !== 401) throw refreshError;
|
|
362
410
|
const current = await this.readStoredTokens();
|
|
@@ -367,15 +415,18 @@ var AuthenticatedApiClient = class {
|
|
|
367
415
|
if (current) {
|
|
368
416
|
const reason = `refresh token rejected by the server (HTTP ${status})`;
|
|
369
417
|
this.logger.warn(`AUTH: Clearing stored tokens: ${reason}`);
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
418
|
+
this.assertSession(current);
|
|
419
|
+
const cleared = await this.tokenStore.clearAuthTokens(presented.refreshToken);
|
|
420
|
+
const now = await this.readStoredTokens();
|
|
421
|
+
this.assertSession(now);
|
|
422
|
+
if (now && (now.accessToken !== presented.accessToken || now.refreshToken !== presented.refreshToken || now.userId !== presented.userId)) return now;
|
|
423
|
+
if (!now && cleared !== false) this.onTokensCleared?.(reason);
|
|
374
424
|
}
|
|
375
425
|
throw new SessionRevokedError(this.reauthMessages.refreshFailed);
|
|
376
426
|
}
|
|
377
427
|
this.logger.debug("AUTH: Token refresh successful");
|
|
378
428
|
const current = await this.readStoredTokens();
|
|
429
|
+
this.assertSession(current);
|
|
379
430
|
if (!current) throw new NotAuthenticatedError(this.reauthMessages.notLoggedIn);
|
|
380
431
|
if (current.refreshToken !== presented.refreshToken) {
|
|
381
432
|
this.logger.debug("AUTH: Stored tokens changed during refresh, keeping the stored ones");
|
|
@@ -394,8 +445,10 @@ var AuthenticatedApiClient = class {
|
|
|
394
445
|
}
|
|
395
446
|
return next;
|
|
396
447
|
}
|
|
397
|
-
readStoredTokens() {
|
|
398
|
-
|
|
448
|
+
async readStoredTokens() {
|
|
449
|
+
const tokens = await (this.tokenStore.reloadAuthTokens ? this.tokenStore.reloadAuthTokens() : this.tokenStore.getAuthTokens());
|
|
450
|
+
this.assertSession(tokens);
|
|
451
|
+
return tokens;
|
|
399
452
|
}
|
|
400
453
|
/**
|
|
401
454
|
* Make a GET request
|
|
@@ -407,8 +460,7 @@ var AuthenticatedApiClient = class {
|
|
|
407
460
|
* Make a POST request
|
|
408
461
|
*/
|
|
409
462
|
async post(url, data, config) {
|
|
410
|
-
this.logger.debug(
|
|
411
|
-
this.logger.debug(`[ApiClient] Request body: ${JSON.stringify(data)}`);
|
|
463
|
+
this.logger.debug("[ApiClient] POST request");
|
|
412
464
|
const response = await this.client.post(url, data, config);
|
|
413
465
|
this.logger.debug(`[ApiClient] Response status: ${response.status}`);
|
|
414
466
|
return response.data;
|
|
@@ -435,6 +487,7 @@ var AuthenticatedApiClient = class {
|
|
|
435
487
|
* Check if user is authenticated
|
|
436
488
|
*/
|
|
437
489
|
async isAuthenticated() {
|
|
490
|
+
if (this.options.isSessionCurrent) return await this.readStoredTokens() !== null;
|
|
438
491
|
return this.tokenStore.isAuthenticated();
|
|
439
492
|
}
|
|
440
493
|
/**
|
|
@@ -442,7 +495,7 @@ var AuthenticatedApiClient = class {
|
|
|
442
495
|
*/
|
|
443
496
|
async getCurrentUser() {
|
|
444
497
|
try {
|
|
445
|
-
const tokens = await this.
|
|
498
|
+
const tokens = await this.readStoredTokens();
|
|
446
499
|
if (!tokens) return null;
|
|
447
500
|
return { id: tokens.userId };
|
|
448
501
|
} catch {
|
|
@@ -690,6 +743,21 @@ const CORE_TOOL_DESCRIPTORS = new Map(Object.entries({
|
|
|
690
743
|
effect: "read",
|
|
691
744
|
approval: "auto_approve"
|
|
692
745
|
},
|
|
746
|
+
peer_list: {
|
|
747
|
+
source: CLI,
|
|
748
|
+
effect: "read",
|
|
749
|
+
approval: "prompt_default"
|
|
750
|
+
},
|
|
751
|
+
peer_status: {
|
|
752
|
+
source: CLI,
|
|
753
|
+
effect: "read",
|
|
754
|
+
approval: "prompt_default"
|
|
755
|
+
},
|
|
756
|
+
peer_send: {
|
|
757
|
+
source: CLI,
|
|
758
|
+
effect: "execute",
|
|
759
|
+
approval: "auto_approve"
|
|
760
|
+
},
|
|
693
761
|
ask_user_question: {
|
|
694
762
|
source: CORE,
|
|
695
763
|
effect: "session",
|
|
@@ -1552,10 +1620,16 @@ function migrateApiConfig(raw) {
|
|
|
1552
1620
|
const { environment, customUrl } = old;
|
|
1553
1621
|
raw.apiConfig = environment === "custom" && customUrl ? { customUrl } : {};
|
|
1554
1622
|
}
|
|
1623
|
+
/**
|
|
1624
|
+
* The default model every config was born with before 0.3.0. It is deprecated, so each
|
|
1625
|
+
* chat on it was served by its successor anyway and counted as a deprecated-model request.
|
|
1626
|
+
*/
|
|
1627
|
+
const LEGACY_DEFAULT_MODEL = ChatModels.CLAUDE_4_5_SONNET;
|
|
1555
1628
|
/** The one-time upgrade of a file not yet at CONFIG_SCHEMA_VERSION, in place. */
|
|
1556
1629
|
function upgradeConfig(raw) {
|
|
1557
1630
|
const preferences = raw.preferences;
|
|
1558
|
-
if (typeof preferences === "object" && preferences?.maxTokens === LEGACY_PINNED_MAX_TOKENS) delete preferences.maxTokens;
|
|
1631
|
+
if ((raw.version === void 0 || raw.version === "0.1.0") && typeof preferences === "object" && preferences?.maxTokens === LEGACY_PINNED_MAX_TOKENS) delete preferences.maxTokens;
|
|
1632
|
+
if (raw.defaultModel === LEGACY_DEFAULT_MODEL) raw.defaultModel = DEFAULT_CONFIG.defaultModel;
|
|
1559
1633
|
raw.version = CONFIG_SCHEMA_VERSION;
|
|
1560
1634
|
}
|
|
1561
1635
|
/** A refresh lock whose heartbeat stopped this long ago (ms) is abandoned. */
|
|
@@ -1693,14 +1767,14 @@ function removeRawListItems(raw, key, drop) {
|
|
|
1693
1767
|
* rewritten at the current version; a file already at it is left alone. Bump this when
|
|
1694
1768
|
* adding a migration, and gate the new step on the version it needs to run from.
|
|
1695
1769
|
*/
|
|
1696
|
-
const CONFIG_SCHEMA_VERSION = "0.
|
|
1770
|
+
const CONFIG_SCHEMA_VERSION = "0.3.0";
|
|
1697
1771
|
/**
|
|
1698
1772
|
* Default configuration
|
|
1699
1773
|
*/
|
|
1700
1774
|
const DEFAULT_CONFIG = {
|
|
1701
1775
|
version: CONFIG_SCHEMA_VERSION,
|
|
1702
1776
|
userId: v4(),
|
|
1703
|
-
defaultModel: ChatModels.
|
|
1777
|
+
defaultModel: ChatModels.CLAUDE_5_5_SONNET,
|
|
1704
1778
|
toolApiKeys: {
|
|
1705
1779
|
openweather: void 0,
|
|
1706
1780
|
serper: void 0
|