jeopi-cli 16.6.13 → 16.6.14
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 +10 -0
- package/README.md +1 -1
- package/dist/cli.js +4034 -4034
- package/dist/types/cli/messenger-cli.d.ts +4 -1
- package/dist/types/messenger/gateway.d.ts +7 -0
- package/dist/types/messenger/session-pool.d.ts +38 -0
- package/dist/types/messenger/session-worker.d.ts +49 -0
- package/package.json +12 -12
- package/src/cli/messenger-cli.ts +22 -24
- package/src/cli.ts +13 -0
- package/src/internal-urls/docs-index.generated.txt +1 -1
- package/src/messenger/gateway.ts +130 -77
- package/src/messenger/session-pool.ts +332 -0
- package/src/messenger/session-worker.ts +79 -0
- package/src/messenger/session.ts +2 -4
|
@@ -6,5 +6,8 @@ export interface MessengerCommandArgs {
|
|
|
6
6
|
config: string;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Check is deliberately local-only: it never starts a transport. The gateway process itself never loads the
|
|
11
|
+
* SDK; every conversation's AgentSession lives in its own session process.
|
|
12
|
+
*/
|
|
10
13
|
export declare function runMessengerCommand(cmd: MessengerCommandArgs): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { MessengerAdapter, MessengerConfig, MessengerMessage, MessengerReply } from "./types";
|
|
2
2
|
/** Include the sender even in shared threads: remote histories must not cross users. */
|
|
3
3
|
export declare function messengerConversationKey(message: MessengerMessage): string;
|
|
4
|
+
/** Stable per-conversation route shared by the persisted session file and its session process. */
|
|
5
|
+
export declare function messengerSessionRoute(cwd: string, message: MessengerMessage): string;
|
|
4
6
|
export declare function isMessengerMessageAllowed(message: MessengerMessage, config: MessengerConfig): boolean;
|
|
5
7
|
export interface MessengerGateway {
|
|
6
8
|
run(signal: AbortSignal): Promise<void>;
|
|
@@ -9,5 +11,10 @@ export interface MessengerGateway {
|
|
|
9
11
|
export interface MessengerGatewayOptions {
|
|
10
12
|
/** Minimum spacing between in-place activity edits for one request. */
|
|
11
13
|
activityIntervalMs?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Requests processed at once (default 1). Requests of one prepared conversation still answer and deliver in
|
|
16
|
+
* order; above 1 the reply implementation must accept concurrent turns for different conversations.
|
|
17
|
+
*/
|
|
18
|
+
concurrency?: number;
|
|
12
19
|
}
|
|
13
20
|
export declare function createMessengerGateway(config: MessengerConfig, adapters: MessengerAdapter[], reply: MessengerReply, options?: MessengerGatewayOptions): MessengerGateway;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MessengerSessionInbound, MessengerSessionOutbound } from "./session-worker";
|
|
2
|
+
import type { MessengerConfig, MessengerReply } from "./types";
|
|
3
|
+
/** Hidden CLI selector that re-enters jeopi as one conversation's session process (dispatched in `cli.ts`). */
|
|
4
|
+
export declare const MESSENGER_SESSION_WORKER_ARG = "__omp_worker_messenger_session";
|
|
5
|
+
/** One conversation's jeopi session process, as the pool sees it. */
|
|
6
|
+
export interface MessengerSessionProcess {
|
|
7
|
+
send(message: MessengerSessionInbound): void;
|
|
8
|
+
onMessage(handler: (message: MessengerSessionOutbound) => void): () => void;
|
|
9
|
+
/** Settles when the process has exited for any reason. */
|
|
10
|
+
exited: Promise<unknown>;
|
|
11
|
+
kill(): void;
|
|
12
|
+
}
|
|
13
|
+
/** Spawn a real session process (the pool's default). */
|
|
14
|
+
export declare function spawnMessengerSessionProcess(config: MessengerConfig): MessengerSessionProcess;
|
|
15
|
+
/** `jeopi --smoke-test` probe: the session process loads its module graph and answers over IPC. */
|
|
16
|
+
export declare function smokeTestMessengerSessionWorker({ timeoutMs, }?: {
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
export interface MessengerSessionPoolOptions {
|
|
20
|
+
/** Resident session processes; at the limit a new conversation retires the least recently used idle one. */
|
|
21
|
+
maxProcesses?: number;
|
|
22
|
+
/** Idle time after which a conversation's process exits; its session file keeps the history. */
|
|
23
|
+
idleMs?: number;
|
|
24
|
+
/** Test seam: start one conversation's session process. */
|
|
25
|
+
spawn?: (config: MessengerConfig) => MessengerSessionProcess;
|
|
26
|
+
}
|
|
27
|
+
export interface MessengerSessionPool {
|
|
28
|
+
reply: MessengerReply;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Give every conversation (a Discord thread or DM, a Telegram chat or topic, a Slack thread) its own jeopi
|
|
33
|
+
* session process: the first message starts it, later turns reuse it, and it exits after idling; the next
|
|
34
|
+
* message resumes the persisted session in a fresh process. Turns of one conversation run strictly in order
|
|
35
|
+
* (including retirement), while different conversations run concurrently. At most `maxProcesses` processes
|
|
36
|
+
* are resident: a new conversation waits for the least recently used idle one to retire, or for a slot.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createMessengerSessionPool(config: MessengerConfig, options?: MessengerSessionPoolOptions): MessengerSessionPool;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createMessengerSessionBridge } from "./session";
|
|
2
|
+
import type { MessengerConfig, MessengerMessage } from "./types";
|
|
3
|
+
/** Gateway pool → session process. */
|
|
4
|
+
export type MessengerSessionInbound = {
|
|
5
|
+
type: "ping";
|
|
6
|
+
id: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: "init";
|
|
9
|
+
id: string;
|
|
10
|
+
config: MessengerConfig;
|
|
11
|
+
} | {
|
|
12
|
+
type: "turn";
|
|
13
|
+
id: string;
|
|
14
|
+
message: MessengerMessage;
|
|
15
|
+
} | {
|
|
16
|
+
type: "abort";
|
|
17
|
+
id: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "close";
|
|
20
|
+
id: string;
|
|
21
|
+
};
|
|
22
|
+
/** Session process → gateway pool. Failures carry no detail: tool output and provider errors stay here. */
|
|
23
|
+
export type MessengerSessionOutbound = {
|
|
24
|
+
type: "pong";
|
|
25
|
+
id: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "activity";
|
|
28
|
+
id: string;
|
|
29
|
+
text: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "reply";
|
|
32
|
+
id: string;
|
|
33
|
+
text: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "failed";
|
|
36
|
+
id: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "closed";
|
|
39
|
+
id: string;
|
|
40
|
+
};
|
|
41
|
+
export interface MessengerSessionTransport {
|
|
42
|
+
send(message: MessengerSessionOutbound): void;
|
|
43
|
+
onMessage(handler: (message: MessengerSessionInbound) => void): () => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Serve one conversation's isolated AgentSession inside its own session process. The pool serializes turns, so
|
|
47
|
+
* the bridge sees one turn at a time and keeps its tool isolation and persisted history unchanged.
|
|
48
|
+
*/
|
|
49
|
+
export declare function startMessengerSessionWorker(transport: MessengerSessionTransport, createBridge?: typeof createMessengerSessionBridge): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "jeopi-cli",
|
|
4
|
-
"version": "16.6.
|
|
4
|
+
"version": "16.6.14",
|
|
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.6.
|
|
61
|
-
"jeopi-stats": "16.6.
|
|
62
|
-
"jeopi-agent-core": "16.6.
|
|
63
|
-
"jeopi-ai": "16.6.
|
|
64
|
-
"jeopi-catalog": "16.6.
|
|
65
|
-
"jeopi-mnemopi": "16.6.
|
|
66
|
-
"jeopi-natives": "16.6.
|
|
67
|
-
"jeopi-tui": "16.6.
|
|
68
|
-
"jeopi-utils": "16.6.
|
|
69
|
-
"jeopi-wire": "16.6.
|
|
70
|
-
"jeopi-snapcompact": "16.6.
|
|
60
|
+
"jeopi-hashline": "16.6.14",
|
|
61
|
+
"jeopi-stats": "16.6.14",
|
|
62
|
+
"jeopi-agent-core": "16.6.14",
|
|
63
|
+
"jeopi-ai": "16.6.14",
|
|
64
|
+
"jeopi-catalog": "16.6.14",
|
|
65
|
+
"jeopi-mnemopi": "16.6.14",
|
|
66
|
+
"jeopi-natives": "16.6.14",
|
|
67
|
+
"jeopi-tui": "16.6.14",
|
|
68
|
+
"jeopi-utils": "16.6.14",
|
|
69
|
+
"jeopi-wire": "16.6.14",
|
|
70
|
+
"jeopi-snapcompact": "16.6.14",
|
|
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",
|
package/src/cli/messenger-cli.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { loadMessengerConfig, validateMessengerEnvironment } from "../messenger/config";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { createDiscordAdapter } from "../messenger/discord";
|
|
3
|
+
import { createMessengerGateway } from "../messenger/gateway";
|
|
4
|
+
import { createMessengerSessionPool, type MessengerSessionPool } from "../messenger/session-pool";
|
|
5
|
+
import { createSlackAdapter } from "../messenger/slack";
|
|
6
|
+
import { createTelegramAdapter } from "../messenger/telegram";
|
|
7
|
+
import type { MessengerAdapter, MessengerConfig } from "../messenger/types";
|
|
4
8
|
|
|
5
9
|
export const MESSENGER_ACTIONS = ["check", "run"] as const;
|
|
6
10
|
export type MessengerAction = (typeof MESSENGER_ACTIONS)[number];
|
|
@@ -9,7 +13,13 @@ export interface MessengerCommandArgs {
|
|
|
9
13
|
flags: { config: string };
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
/**
|
|
16
|
+
/** Conversations answered at once; each conversation runs in its own session process. */
|
|
17
|
+
const MESSENGER_CONCURRENCY = 4;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check is deliberately local-only: it never starts a transport. The gateway process itself never loads the
|
|
21
|
+
* SDK; every conversation's AgentSession lives in its own session process.
|
|
22
|
+
*/
|
|
13
23
|
export async function runMessengerCommand(cmd: MessengerCommandArgs): Promise<void> {
|
|
14
24
|
if (!MESSENGER_ACTIONS.includes(cmd.action)) throw new Error("Unknown messenger action");
|
|
15
25
|
if (!cmd.flags.config) throw new Error("Messenger requires --config <file>");
|
|
@@ -38,35 +48,23 @@ export async function runMessengerCommand(cmd: MessengerCommandArgs): Promise<vo
|
|
|
38
48
|
const stop = (): void => controller.abort();
|
|
39
49
|
process.once("SIGINT", stop);
|
|
40
50
|
process.once("SIGTERM", stop);
|
|
41
|
-
let
|
|
51
|
+
let pool: MessengerSessionPool | undefined;
|
|
42
52
|
let failure: Error | undefined;
|
|
43
53
|
try {
|
|
44
|
-
|
|
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
|
+
pool = createMessengerSessionPool(config);
|
|
54
55
|
const adapters: MessengerAdapter[] = [];
|
|
55
|
-
if (config.platforms.telegram) adapters.push(
|
|
56
|
-
if (config.platforms.discord) adapters.push(
|
|
57
|
-
if (config.platforms.slack) adapters.push(
|
|
58
|
-
const gateway = createMessengerGateway(config, adapters,
|
|
56
|
+
if (config.platforms.telegram) adapters.push(createTelegramAdapter(config.platforms.telegram));
|
|
57
|
+
if (config.platforms.discord) adapters.push(createDiscordAdapter(config.platforms.discord));
|
|
58
|
+
if (config.platforms.slack) adapters.push(createSlackAdapter(config.platforms.slack));
|
|
59
|
+
const gateway = createMessengerGateway(config, adapters, pool.reply, { concurrency: MESSENGER_CONCURRENCY });
|
|
59
60
|
process.stdout.write(`Starting messenger: ${platforms.join(", ")}. Press Ctrl+C to stop.\n`);
|
|
60
61
|
await gateway.run(controller.signal);
|
|
61
|
-
} catch
|
|
62
|
-
failure =
|
|
63
|
-
error instanceof MessengerFatalError
|
|
64
|
-
? error
|
|
65
|
-
: new Error("Messenger gateway failed; check local configuration and provider access");
|
|
62
|
+
} catch {
|
|
63
|
+
failure = new Error("Messenger gateway failed; check local configuration and provider access");
|
|
66
64
|
} finally {
|
|
67
65
|
controller.abort();
|
|
68
66
|
try {
|
|
69
|
-
await
|
|
67
|
+
await pool?.close();
|
|
70
68
|
} catch {
|
|
71
69
|
failure ??= new Error("Messenger session shutdown failed");
|
|
72
70
|
} finally {
|
package/src/cli.ts
CHANGED
|
@@ -63,6 +63,9 @@ async function runSmokeTest(): Promise<void> {
|
|
|
63
63
|
const { smokeTestTtsWorker } = await import("./tts/tts-client");
|
|
64
64
|
const { smokeTestMnemopiEmbedWorker } = await import("./mnemopi/embed-client");
|
|
65
65
|
const { smokeTestJsEvalWorker } = await import("./eval/js/context-manager");
|
|
66
|
+
// Dynamic like its siblings: `session-pool` imports `jeopi-utils`, whose env module loads `.env` at import
|
|
67
|
+
// time and must not run before profile bootstrap (see the note above `showHelp`).
|
|
68
|
+
const { smokeTestMessengerSessionWorker } = await import("./messenger/session-pool");
|
|
66
69
|
await smokeTestSyncWorker();
|
|
67
70
|
|
|
68
71
|
const statsServer = await startServer(0);
|
|
@@ -82,6 +85,7 @@ async function runSmokeTest(): Promise<void> {
|
|
|
82
85
|
await smokeTestJsEvalWorker();
|
|
83
86
|
await smokeTestTtsWorker();
|
|
84
87
|
await smokeTestMnemopiEmbedWorker();
|
|
88
|
+
await smokeTestMessengerSessionWorker();
|
|
85
89
|
process.stdout.write("smoke-test: ok\n");
|
|
86
90
|
}
|
|
87
91
|
|
|
@@ -92,6 +96,8 @@ const JS_EVAL_WORKER_ARG = "__omp_worker_js_eval";
|
|
|
92
96
|
const STT_WORKER_ARG = "__omp_worker_stt";
|
|
93
97
|
const TTS_WORKER_ARG = "__omp_worker_tts";
|
|
94
98
|
const MNEMOPI_EMBED_WORKER_ARG = "__omp_worker_mnemopi_embed";
|
|
99
|
+
/** Must match `MESSENGER_SESSION_WORKER_ARG` in `messenger/session-pool.ts`, which this entry cannot import early. */
|
|
100
|
+
const MESSENGER_SESSION_WORKER_ARG = "__omp_worker_messenger_session";
|
|
95
101
|
|
|
96
102
|
async function runWorkerEntrypoint(arg: string | undefined): Promise<boolean> {
|
|
97
103
|
if (arg === TINY_WORKER_ARG) {
|
|
@@ -152,6 +158,13 @@ async function runWorkerEntrypoint(arg: string | undefined): Promise<boolean> {
|
|
|
152
158
|
await runIpcSubprocessWorker(startMnemopiEmbedWorker);
|
|
153
159
|
return true;
|
|
154
160
|
}
|
|
161
|
+
if (arg === MESSENGER_SESSION_WORKER_ARG) {
|
|
162
|
+
// Dynamic: the session process loads the agent SDK only after profile bootstrap and worker dispatch;
|
|
163
|
+
// a static import would load it into every CLI start and every other worker kind.
|
|
164
|
+
const { startMessengerSessionWorker } = await import("./messenger/session-worker");
|
|
165
|
+
await runIpcSubprocessWorker(startMessengerSessionWorker);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
155
168
|
return false;
|
|
156
169
|
}
|
|
157
170
|
|