jeopi-cli 16.5.6 → 16.6.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.
@@ -0,0 +1,10 @@
1
+ export declare const MESSENGER_ACTIONS: readonly ["check", "run"];
2
+ export type MessengerAction = (typeof MESSENGER_ACTIONS)[number];
3
+ export interface MessengerCommandArgs {
4
+ action: MessengerAction;
5
+ flags: {
6
+ config: string;
7
+ };
8
+ }
9
+ /** Check is deliberately local-only: it never imports the SDK or starts a transport. */
10
+ export declare function runMessengerCommand(cmd: MessengerCommandArgs): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { Command } from "jeopi-utils/cli";
2
+ export default class Messenger extends Command {
3
+ static description: string;
4
+ static args: {
5
+ action: import("jeopi-utils/cli").ArgDescriptor & {
6
+ description: string;
7
+ required: false;
8
+ options: ("check" | "run")[];
9
+ };
10
+ };
11
+ static flags: {
12
+ config: import("jeopi-utils/cli").FlagDescriptor<"string"> & {
13
+ description: string;
14
+ };
15
+ };
16
+ static examples: string[];
17
+ run(): Promise<void>;
18
+ }
@@ -2,7 +2,7 @@ import type { Api, Context, Model, ModelSpec, RemoteCompactionConfig, SimpleStre
2
2
  import type { AssistantMessageEventStream } from "jeopi-ai/utils/event-stream";
3
3
  import { type ModelRefreshStrategy } from "jeopi-catalog/model-manager";
4
4
  import type { ApiKeyResolver, FetchImpl } from "jeopi-ai";
5
- import type { OAuthCredentials, OAuthLoginCallbacks } from "jeopi-ai/oauth/types";
5
+ import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderId } from "jeopi-ai/oauth/types";
6
6
  import type { AuthStorage } from "../session/auth-storage";
7
7
  import { type ApiKeyResolverModel, type ApiKeyResolverOptions } from "./api-key-resolver";
8
8
  import type { ConfigError } from "./config-file";
@@ -73,6 +73,8 @@ export declare class ModelRegistry {
73
73
  constructor(authStorage: AuthStorage, modelsPath?: string, options?: {
74
74
  fetch?: FetchImpl;
75
75
  });
76
+ /** Save login credentials, then bypass the catalog TTL for the authenticated provider. */
77
+ login(providerId: OAuthProviderId, callbacks: OAuthLoginCallbacks): Promise<void>;
76
78
  /**
77
79
  * Reload models from disk (built-in + custom config).
78
80
  */
@@ -0,0 +1,4 @@
1
+ import type { MessengerConfig } from "./types";
2
+ export declare function parseMessengerConfig(value: unknown, baseDir: string): MessengerConfig;
3
+ export declare function loadMessengerConfig(file: string): Promise<MessengerConfig>;
4
+ export declare function validateMessengerEnvironment(config: MessengerConfig, env?: Record<string, string | undefined>): void;
@@ -0,0 +1,10 @@
1
+ import type { MessengerAdapter, MessengerPlatformConfig, MessengerTransportDeps } from "./types";
2
+ export interface DiscordClock {
3
+ /** Schedule once and return an idempotent cancellation function. */
4
+ schedule(callback: () => void, delayMs: number): () => void;
5
+ random(): number;
6
+ }
7
+ export interface DiscordTransportDeps extends MessengerTransportDeps {
8
+ clock?: DiscordClock;
9
+ }
10
+ export declare function createDiscordAdapter(config: MessengerPlatformConfig, env?: Record<string, string | undefined>, deps?: DiscordTransportDeps): MessengerAdapter;
@@ -0,0 +1,9 @@
1
+ import type { MessengerAdapter, MessengerConfig, MessengerMessage, MessengerReply } from "./types";
2
+ /** Include the sender even in shared threads: remote histories must not cross users. */
3
+ export declare function messengerConversationKey(message: MessengerMessage): string;
4
+ export declare function isMessengerMessageAllowed(message: MessengerMessage, config: MessengerConfig): boolean;
5
+ export interface MessengerGateway {
6
+ run(signal: AbortSignal): Promise<void>;
7
+ handle(message: MessengerMessage, signal?: AbortSignal): Promise<void>;
8
+ }
9
+ export declare function createMessengerGateway(config: MessengerConfig, adapters: MessengerAdapter[], reply: MessengerReply): MessengerGateway;
@@ -0,0 +1,9 @@
1
+ export declare class MessengerHttpError extends Error {
2
+ readonly status: number;
3
+ readonly retryAfterMs?: number | undefined;
4
+ constructor(status: number, retryAfterMs?: number | undefined);
5
+ }
6
+ /** Provider limits count UTF-16 units; do not bisect supplementary characters. */
7
+ export declare function splitMessengerText(text: string, limit: number): string[];
8
+ export declare function messengerFetchJson(url: string, init: RequestInit, signal?: AbortSignal, fetchImpl?: typeof fetch): Promise<unknown>;
9
+ export declare function waitForMessengerRetry(ms: number, signal: AbortSignal): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import type { Model } from "jeopi-ai";
2
+ import type { ModelRegistry } from "../config/model-registry";
3
+ import type { AuthStorage } from "../session/auth-storage";
4
+ import { type MessengerConfig, type MessengerReply } from "./types";
5
+ export interface MessengerSessionBridge {
6
+ reply: MessengerReply;
7
+ close(): Promise<void>;
8
+ }
9
+ /** Explicit SDK resources for embedded callers; security policy remains bridge-owned. */
10
+ export interface MessengerSessionDependencies {
11
+ agentDir: string;
12
+ authStorage: AuthStorage;
13
+ modelRegistry: ModelRegistry;
14
+ model: Model;
15
+ }
16
+ /** One Main session owns the SDK's process-global lifecycle until gateway shutdown. */
17
+ export declare function createMessengerSessionBridge(config: MessengerConfig, dependencies?: MessengerSessionDependencies): MessengerSessionBridge;
@@ -0,0 +1,2 @@
1
+ import type { MessengerAdapter, MessengerPlatformConfig, MessengerTransportDeps } from "./types";
2
+ export declare function createSlackAdapter(config: MessengerPlatformConfig, env?: Record<string, string | undefined>, deps?: MessengerTransportDeps): MessengerAdapter;
@@ -0,0 +1,2 @@
1
+ import type { MessengerAdapter, MessengerPlatformConfig, MessengerTransportDeps } from "./types";
2
+ export declare function createTelegramAdapter(config: MessengerPlatformConfig, env?: Record<string, string | undefined>, deps?: MessengerTransportDeps): MessengerAdapter;
@@ -0,0 +1,38 @@
1
+ export type MessengerPlatform = "discord" | "telegram" | "slack";
2
+ export interface MessengerMessage {
3
+ platform: MessengerPlatform;
4
+ accountId: string;
5
+ channelId: string;
6
+ senderId: string;
7
+ messageId: string;
8
+ text: string;
9
+ threadId?: string;
10
+ direct: boolean;
11
+ mentioned: boolean;
12
+ }
13
+ export interface MessengerAdapter {
14
+ platform: MessengerPlatform;
15
+ start(onMessage: (message: MessengerMessage) => Promise<void>, signal: AbortSignal): Promise<void>;
16
+ send(message: MessengerMessage, text: string, signal?: AbortSignal): Promise<void>;
17
+ }
18
+ export interface MessengerPlatformConfig {
19
+ tokenEnv: string;
20
+ appTokenEnv?: string;
21
+ allowedUserIds: string[];
22
+ allowedChannelIds?: string[];
23
+ }
24
+ export interface MessengerConfig {
25
+ cwd: string;
26
+ sessionDir: string;
27
+ toolNames: string[];
28
+ platforms: Partial<Record<MessengerPlatform, MessengerPlatformConfig>>;
29
+ }
30
+ export interface MessengerTransportDeps {
31
+ fetch?: typeof fetch;
32
+ WebSocket?: typeof WebSocket;
33
+ }
34
+ export type MessengerReply = (message: MessengerMessage, signal: AbortSignal) => Promise<string>;
35
+ /** A partially initialized SDK must not be retried inside a live gateway. */
36
+ export declare class MessengerFatalError extends Error {
37
+ constructor();
38
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "jeopi-cli",
4
- "version": "16.5.6",
4
+ "version": "16.6.2",
5
5
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
6
6
  "homepage": "https://github.com/akillness/jeopi",
7
7
  "author": "Can Boluk",
@@ -57,17 +57,17 @@
57
57
  "@agentclientprotocol/sdk": "0.25.0",
58
58
  "@babel/parser": "^7.29.7",
59
59
  "@mozilla/readability": "^0.6.0",
60
- "jeopi-hashline": "16.5.6",
61
- "jeopi-stats": "16.5.6",
62
- "jeopi-agent-core": "16.5.6",
63
- "jeopi-ai": "16.5.6",
64
- "jeopi-catalog": "16.5.6",
65
- "jeopi-mnemopi": "16.5.6",
66
- "jeopi-natives": "16.5.6",
67
- "jeopi-tui": "16.5.6",
68
- "jeopi-utils": "16.5.6",
69
- "jeopi-wire": "16.5.6",
70
- "jeopi-snapcompact": "16.5.6",
60
+ "jeopi-hashline": "16.6.2",
61
+ "jeopi-stats": "16.6.2",
62
+ "jeopi-agent-core": "16.6.2",
63
+ "jeopi-ai": "16.6.2",
64
+ "jeopi-catalog": "16.6.2",
65
+ "jeopi-mnemopi": "16.6.2",
66
+ "jeopi-natives": "16.6.2",
67
+ "jeopi-tui": "16.6.2",
68
+ "jeopi-utils": "16.6.2",
69
+ "jeopi-wire": "16.6.2",
70
+ "jeopi-snapcompact": "16.6.2",
71
71
  "@opentelemetry/api": "^1.9.1",
72
72
  "@opentelemetry/context-async-hooks": "^2.7.1",
73
73
  "@opentelemetry/exporter-trace-otlp-proto": "^0.218.0",
@@ -0,0 +1,78 @@
1
+ import { loadMessengerConfig, validateMessengerEnvironment } from "../messenger/config";
2
+ import type { MessengerSessionBridge } from "../messenger/session";
3
+ import { type MessengerAdapter, type MessengerConfig, MessengerFatalError } from "../messenger/types";
4
+
5
+ export const MESSENGER_ACTIONS = ["check", "run"] as const;
6
+ export type MessengerAction = (typeof MESSENGER_ACTIONS)[number];
7
+ export interface MessengerCommandArgs {
8
+ action: MessengerAction;
9
+ flags: { config: string };
10
+ }
11
+
12
+ /** Check is deliberately local-only: it never imports the SDK or starts a transport. */
13
+ export async function runMessengerCommand(cmd: MessengerCommandArgs): Promise<void> {
14
+ if (!MESSENGER_ACTIONS.includes(cmd.action)) throw new Error("Unknown messenger action");
15
+ if (!cmd.flags.config) throw new Error("Messenger requires --config <file>");
16
+ // Do not echo parse errors, paths, configuration values, or environment secrets.
17
+ let config: MessengerConfig;
18
+ try {
19
+ config = await loadMessengerConfig(cmd.flags.config);
20
+ validateMessengerEnvironment(config);
21
+ } catch {
22
+ throw new Error("Messenger configuration or required environment is invalid");
23
+ }
24
+ const platforms = Object.keys(config.platforms);
25
+ if (cmd.action === "check") {
26
+ process.stdout.write(
27
+ `Messenger configuration valid: ${platforms.join(", ")}; ${config.toolNames.length} tools enabled. No network checks performed.\n`,
28
+ );
29
+ return;
30
+ }
31
+ if (config.toolNames.length > 0) {
32
+ process.stderr.write(
33
+ "Warning: enabled messenger tools grant authorized remote users local machine authority; this is not a sandbox.\n",
34
+ );
35
+ }
36
+
37
+ const controller = new AbortController();
38
+ const stop = (): void => controller.abort();
39
+ process.once("SIGINT", stop);
40
+ process.once("SIGTERM", stop);
41
+ let bridge: MessengerSessionBridge | undefined;
42
+ let failure: Error | undefined;
43
+ try {
44
+ const [{ createMessengerSessionBridge }, { createMessengerGateway }, telegram, discord, slack] =
45
+ await Promise.all([
46
+ import("../messenger/session"),
47
+ import("../messenger/gateway"),
48
+ import("../messenger/telegram"),
49
+ import("../messenger/discord"),
50
+ import("../messenger/slack"),
51
+ ]);
52
+ if (controller.signal.aborted) return;
53
+ bridge = createMessengerSessionBridge(config);
54
+ const adapters: MessengerAdapter[] = [];
55
+ if (config.platforms.telegram) adapters.push(telegram.createTelegramAdapter(config.platforms.telegram));
56
+ if (config.platforms.discord) adapters.push(discord.createDiscordAdapter(config.platforms.discord));
57
+ if (config.platforms.slack) adapters.push(slack.createSlackAdapter(config.platforms.slack));
58
+ const gateway = createMessengerGateway(config, adapters, bridge.reply);
59
+ process.stdout.write(`Starting messenger: ${platforms.join(", ")}. Press Ctrl+C to stop.\n`);
60
+ await gateway.run(controller.signal);
61
+ } catch (error) {
62
+ failure =
63
+ error instanceof MessengerFatalError
64
+ ? error
65
+ : new Error("Messenger gateway failed; check local configuration and provider access");
66
+ } finally {
67
+ controller.abort();
68
+ try {
69
+ await bridge?.close();
70
+ } catch {
71
+ failure ??= new Error("Messenger session shutdown failed");
72
+ } finally {
73
+ process.off("SIGINT", stop);
74
+ process.off("SIGTERM", stop);
75
+ }
76
+ }
77
+ if (failure) throw failure;
78
+ }
@@ -16,6 +16,7 @@ export const commands: CommandEntry[] = [
16
16
  { name: "acp", load: () => import("./commands/acp").then(m => m.default) },
17
17
  { name: "auth-broker", load: () => import("./commands/auth-broker").then(m => m.default) },
18
18
  { name: "auth-gateway", load: () => import("./commands/auth-gateway").then(m => m.default) },
19
+ { name: "messenger", load: () => import("./commands/messenger").then(m => m.default) },
19
20
  { name: "agents", load: () => import("./commands/agents").then(m => m.default) },
20
21
  { name: "bench", load: () => import("./commands/bench").then(m => m.default) },
21
22
  { name: "commit", load: () => import("./commands/commit").then(m => m.default) },
@@ -0,0 +1,30 @@
1
+ import { APP_NAME } from "jeopi-utils";
2
+ import { Args, Command, Flags, renderCommandHelp } from "jeopi-utils/cli";
3
+ import { MESSENGER_ACTIONS, type MessengerAction, runMessengerCommand } from "../cli/messenger-cli";
4
+
5
+ export default class Messenger extends Command {
6
+ static description = "Run authorized Discord, Telegram, and Slack text bots";
7
+
8
+ static args = {
9
+ action: Args.string({ description: "Sub-command", required: false, options: [...MESSENGER_ACTIONS] }),
10
+ };
11
+
12
+ static flags = {
13
+ config: Flags.string({ description: "Path to messenger JSON configuration" }),
14
+ };
15
+
16
+ static examples = [
17
+ "jeopi messenger check --config ./messenger.json",
18
+ "jeopi messenger run --config ./messenger.json",
19
+ ];
20
+
21
+ async run(): Promise<void> {
22
+ const { args, flags } = await this.parse(Messenger);
23
+ if (!args.action) {
24
+ renderCommandHelp(APP_NAME, "messenger", Messenger);
25
+ return;
26
+ }
27
+ if (!flags.config) throw new Error("Messenger requires --config <file>");
28
+ await runMessengerCommand({ action: args.action as MessengerAction, flags: { config: flags.config } });
29
+ }
30
+ }
@@ -50,8 +50,8 @@ const STARTUP_MODEL_CACHE_PROVIDER_IDS: readonly string[] = [
50
50
  const LOCAL_PROVIDER_PLACEHOLDERS = new Set<string>(["llama-cpp-local", "lm-studio-local", "vllm-local"]);
51
51
 
52
52
  import type { ApiKeyResolver, FetchImpl } from "jeopi-ai";
53
- import { registerOAuthProvider, unregisterOAuthProviders } from "jeopi-ai/oauth";
54
- import type { OAuthCredentials, OAuthLoginCallbacks } from "jeopi-ai/oauth/types";
53
+ import { getOAuthProviders, registerOAuthProvider, unregisterOAuthProviders } from "jeopi-ai/oauth";
54
+ import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderId } from "jeopi-ai/oauth/types";
55
55
  import { getBundledModelReferenceIndex, resolveModelReference } from "jeopi-catalog/identity";
56
56
  import { isBunTestRuntime, isRecord, logger, wrapFetchForExtraCa } from "jeopi-utils";
57
57
  import { parseModelString, resolveProviderModelReference } from "../config/model-resolver";
@@ -788,6 +788,14 @@ export class ModelRegistry {
788
788
  this.#loadModels();
789
789
  }
790
790
 
791
+ /** Save login credentials, then bypass the catalog TTL for the authenticated provider. */
792
+ async login(providerId: OAuthProviderId, callbacks: OAuthLoginCallbacks): Promise<void> {
793
+ await this.authStorage.login(providerId, callbacks);
794
+ const modelProviderId =
795
+ getOAuthProviders().find(provider => provider.id === providerId)?.storeCredentialsAs ?? providerId;
796
+ await this.refreshProvider(modelProviderId, "online");
797
+ }
798
+
791
799
  /**
792
800
  * Reload models from disk (built-in + custom config).
793
801
  */
@@ -1643,13 +1651,40 @@ export class ModelRegistry {
1643
1651
  }> = [
1644
1652
  {
1645
1653
  providerId: "google-antigravity",
1646
- resolveKey: extractGoogleOAuthToken,
1647
- createOptions: oauthToken =>
1648
- googleAntigravityModelManagerOptions({
1654
+ resolveKey: value =>
1655
+ extractGoogleOAuthToken(value) ?? this.authStorage.getOAuthCredential("google-antigravity")?.access,
1656
+ createOptions: oauthToken => {
1657
+ // Pin discovery to one stable account, including when its access token has expired.
1658
+ // Independent peek/getApiKey calls otherwise advance round-robin and poison the cache scope.
1659
+ const account = this.authStorage.listOAuthAccounts("google-antigravity")[0];
1660
+ const cacheScope = account
1661
+ ? JSON.stringify([account.credentialId, account.accountId ?? account.email, account.projectId])
1662
+ : undefined;
1663
+ return googleAntigravityModelManagerOptions({
1649
1664
  oauthToken,
1650
- endpoint: this.getProviderBaseUrl("google-antigravity"),
1665
+ cacheScope,
1666
+ endpoint:
1667
+ this.#runtimeProviderOverrides.get("google-antigravity")?.baseUrl ??
1668
+ this.#providerOverrides.get("google-antigravity")?.baseUrl ??
1669
+ this.getProviderBaseUrl("google-antigravity"),
1651
1670
  fetch: this.#fetch,
1652
- }),
1671
+ resolveOAuthToken: async signal => {
1672
+ if (!account) {
1673
+ return extractGoogleOAuthToken(
1674
+ await this.getApiKeyForProvider("google-antigravity", undefined, { signal }),
1675
+ );
1676
+ }
1677
+ const current = this.authStorage
1678
+ .listOAuthAccounts("google-antigravity")
1679
+ .find(entry => entry.credentialId === account.credentialId);
1680
+ if (!current) return undefined;
1681
+ const access = await this.authStorage.getOAuthAccessAt("google-antigravity", current.position, {
1682
+ signal,
1683
+ });
1684
+ return access?.ok ? access.accessToken : undefined;
1685
+ },
1686
+ });
1687
+ },
1653
1688
  },
1654
1689
  {
1655
1690
  providerId: "google-gemini-cli",
@@ -1747,7 +1782,7 @@ export class ModelRegistry {
1747
1782
  model.provider === options.providerId ? model : { ...model, provider: options.providerId },
1748
1783
  );
1749
1784
  const authoritativeProviders = new Set<string>();
1750
- if (options.dynamicModelsAuthoritative && !result.stale) {
1785
+ if (options.dynamicModelsAuthoritative && (!result.stale || result.preservedAuthoritativeCache)) {
1751
1786
  authoritativeProviders.add(options.providerId);
1752
1787
  }
1753
1788
  return { models, authoritativeProviders };