@0xmaxma/claude-gateway 2.1.14 → 2.1.16
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/dist/agent/model-catalog.d.ts +10 -0
- package/dist/agent/model-catalog.d.ts.map +1 -1
- package/dist/agent/model-catalog.js +93 -25
- package/dist/agent/model-catalog.js.map +1 -1
- package/dist/agent/model-registry.d.ts +15 -0
- package/dist/agent/model-registry.d.ts.map +1 -1
- package/dist/agent/model-registry.js +26 -0
- package/dist/agent/model-registry.js.map +1 -1
- package/dist/agent/runner.d.ts +5 -1
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +48 -29
- package/dist/agent/runner.js.map +1 -1
- package/dist/api/gateway-router.js +2 -2
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/packages.d.ts.map +1 -1
- package/dist/api/packages.js +12 -11
- package/dist/api/packages.js.map +1 -1
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +9 -7
- package/dist/api/router.js.map +1 -1
- package/dist/build-provenance.json +4 -4
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +18 -7
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cron/manager.d.ts.map +1 -1
- package/dist/cron/manager.js +6 -3
- package/dist/cron/manager.js.map +1 -1
- package/dist/cron/scheduler.d.ts +1 -0
- package/dist/cron/scheduler.d.ts.map +1 -1
- package/dist/cron/scheduler.js +76 -5
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/cron/validate.d.ts +10 -0
- package/dist/cron/validate.d.ts.map +1 -0
- package/dist/cron/validate.js +37 -0
- package/dist/cron/validate.js.map +1 -0
- package/dist/heartbeat/parser.d.ts +12 -3
- package/dist/heartbeat/parser.d.ts.map +1 -1
- package/dist/heartbeat/parser.js +35 -97
- package/dist/heartbeat/parser.js.map +1 -1
- package/dist/history/types.d.ts +1 -1
- package/dist/history/types.js +1 -1
- package/dist/orchestration/agent-cli-session.d.ts +58 -6
- package/dist/orchestration/agent-cli-session.d.ts.map +1 -1
- package/dist/orchestration/agent-cli-session.js +207 -27
- package/dist/orchestration/agent-cli-session.js.map +1 -1
- package/dist/orchestration/bridge.d.ts +2 -0
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +54 -14
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/context-delivery.d.ts +2 -0
- package/dist/orchestration/context-delivery.d.ts.map +1 -1
- package/dist/orchestration/context-delivery.js +8 -0
- package/dist/orchestration/context-delivery.js.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.d.ts +2 -0
- package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.js +4 -2
- package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
- package/dist/orchestration/input-images.d.ts +4 -0
- package/dist/orchestration/input-images.d.ts.map +1 -1
- package/dist/orchestration/input-images.js +28 -0
- package/dist/orchestration/input-images.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +5 -0
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +105 -46
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/session-compaction.d.ts.map +1 -1
- package/dist/orchestration/session-compaction.js +16 -6
- package/dist/orchestration/session-compaction.js.map +1 -1
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +12 -1
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/pool.d.ts +3 -2
- package/dist/orchestration/tasks/pool.d.ts.map +1 -1
- package/dist/orchestration/tasks/pool.js +4 -3
- package/dist/orchestration/tasks/pool.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +3 -0
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +24 -3
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/token-ledger.d.ts +6 -0
- package/dist/orchestration/token-ledger.d.ts.map +1 -1
- package/dist/orchestration/token-ledger.js +2 -1
- package/dist/orchestration/token-ledger.js.map +1 -1
- package/dist/orchestration/types.d.ts +4 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js.map +1 -1
- package/dist/packages/npm-staging.d.ts +55 -0
- package/dist/packages/npm-staging.d.ts.map +1 -0
- package/dist/packages/npm-staging.js +349 -0
- package/dist/packages/npm-staging.js.map +1 -0
- package/dist/packages/registry.d.ts +24 -10
- package/dist/packages/registry.d.ts.map +1 -1
- package/dist/packages/registry.js +125 -66
- package/dist/packages/registry.js.map +1 -1
- package/dist/types.d.ts +12 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/memory-activity.js +1 -1
- package/mcp/tools/telegram/callback-failure.ts +10 -4
- package/mcp/tools/telegram/model-menu-request.ts +4 -1
- package/mcp/tools/telegram/receiver-server.ts +47 -53
- package/mcp/tools/telegram/session-list.ts +82 -0
- package/mcp/tools/telegram/task-browser.ts +2 -1
- package/package.json +1 -1
- package/dist/session/compactor.d.ts +0 -53
- package/dist/session/compactor.d.ts.map +0 -1
- package/dist/session/compactor.js +0 -274
- package/dist/session/compactor.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { InlineKeyboard } from 'grammy'
|
|
2
|
+
import { CallbackHttpError, callbackRejection } from './callback-failure'
|
|
3
|
+
|
|
4
|
+
export type SessionListEntry = { id: string; name: string; messageCount: number; lastActive: number }
|
|
5
|
+
|
|
6
|
+
/** Sessions shown per /sessions page. Each costs up to two buttons, so a page
|
|
7
|
+
* stays far below Telegram's 100-button limit on one inline keyboard. */
|
|
8
|
+
export const SESSIONS_PER_PAGE = 8
|
|
9
|
+
/** Telegram caps callback_data at 64 UTF-8 bytes. */
|
|
10
|
+
const MAX_DATA_BYTES = 64
|
|
11
|
+
|
|
12
|
+
const fits = (data: string) => Buffer.byteLength(data, 'utf8') <= MAX_DATA_BYTES
|
|
13
|
+
// Cut on code points: a split surrogate pair is invalid UTF-8 and Telegram
|
|
14
|
+
// rejects the whole message. An empty button label is rejected too.
|
|
15
|
+
const clip = (value: string, max: number) => {
|
|
16
|
+
const chars = [...value.replace(/\s+/g, ' ').trim()]
|
|
17
|
+
return chars.length > max ? chars.slice(0, max - 1).join('') + '…' : chars.join('') || 'Untitled'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function age(now: number, lastActive: number): string {
|
|
21
|
+
const minutes = Math.max(0, Math.round((now - lastActive) / 60000))
|
|
22
|
+
return minutes < 60 ? `${minutes}m ago` : `${Math.round(minutes / 60)}h ago`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Builds one page of the /sessions menu, newest first. `page` is clamped, so a
|
|
26
|
+
* stale Prev/Next button after a delete still lands on a real page. */
|
|
27
|
+
export function sessionListMenu(sessions: SessionListEntry[], activeId: string, page: number, now = Date.now()): { text: string; reply_markup: InlineKeyboard; page: number; pages: number } {
|
|
28
|
+
// A session whose callback would exceed 64 bytes cannot be switched to or
|
|
29
|
+
// deleted from a button, so it is listed in the count but never sent as one.
|
|
30
|
+
// Each tap re-reads the list, so a session active between taps moves to page 1.
|
|
31
|
+
const sorted = [...sessions].sort((a, b) => b.lastActive - a.lastActive || a.id.localeCompare(b.id))
|
|
32
|
+
const pages = Math.max(1, Math.ceil(sorted.length / SESSIONS_PER_PAGE))
|
|
33
|
+
const current = Math.min(Math.max(0, Number.isInteger(page) ? page : 0), pages - 1)
|
|
34
|
+
const shown = sorted.slice(current * SESSIONS_PER_PAGE, (current + 1) * SESSIONS_PER_PAGE)
|
|
35
|
+
|
|
36
|
+
const keyboard = new InlineKeyboard()
|
|
37
|
+
for (const s of shown) {
|
|
38
|
+
const switchData = `session_switch:${s.id}`
|
|
39
|
+
if (!fits(switchData)) continue
|
|
40
|
+
const label = s.id === activeId ? `🟢 ${clip(s.name, 38)}` : clip(s.name, 40)
|
|
41
|
+
keyboard.text(label, switchData)
|
|
42
|
+
if (sorted.length > 1 && fits(`session_delete_confirm:${s.id}`)) keyboard.text('🗑', `session_delete:${s.id}`)
|
|
43
|
+
keyboard.row()
|
|
44
|
+
}
|
|
45
|
+
if (current > 0) keyboard.text('‹ Prev', `session_page:${current - 1}`)
|
|
46
|
+
if (current + 1 < pages) keyboard.text('Next ›', `session_page:${current + 1}`)
|
|
47
|
+
if (pages > 1) keyboard.row()
|
|
48
|
+
keyboard.text('➕ New Session', 'session_new').row()
|
|
49
|
+
keyboard.text('Dismiss', 'session_back')
|
|
50
|
+
|
|
51
|
+
const lines = [`🗂 Sessions (${sorted.length})${pages > 1 ? ` · Page ${current + 1}/${pages}` : ''}`, '']
|
|
52
|
+
for (const s of shown) {
|
|
53
|
+
lines.push(`${s.id === activeId ? '🟢' : '⚪'} ${clip(s.name, 60)} · ${s.messageCount} msgs · ${age(now, s.lastActive)}`)
|
|
54
|
+
}
|
|
55
|
+
lines.push('', 'Tap a session to switch, 🗑 to delete')
|
|
56
|
+
return { text: lines.join('\n'), reply_markup: keyboard, page: current, pages }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Reads the chat's sessions from the agent (`list_sessions`). Throws with the
|
|
60
|
+
* HTTP status or the agent's reason so the failure log keeps the cause. */
|
|
61
|
+
export async function listSessionsRequest(base: string | undefined, chatId: string, timeoutMs = 10000): Promise<{ sessions: SessionListEntry[]; activeId: string }> {
|
|
62
|
+
if (!base) throw Error('not_configured')
|
|
63
|
+
const response = await fetch(base + '/command', {
|
|
64
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, signal: AbortSignal.timeout(timeoutMs),
|
|
65
|
+
body: JSON.stringify({ command: 'list_sessions', chat_id: chatId }),
|
|
66
|
+
})
|
|
67
|
+
const result = await response.json().catch(error => { throw response.ok ? error : new CallbackHttpError(response.status) }) as { success?: boolean; sessions?: unknown; activeSessionId?: unknown } | null
|
|
68
|
+
if (!response.ok) throw new CallbackHttpError(response.status, result)
|
|
69
|
+
// A successful list_sessions reply carries `sessions` and no `success` flag.
|
|
70
|
+
if (result?.success === false || !Array.isArray(result?.sessions)) throw callbackRejection(result)
|
|
71
|
+
// Only the id is needed to switch or delete; the other fields are display-only,
|
|
72
|
+
// so a row missing them is still listed (an unnamed one shows as Untitled).
|
|
73
|
+
const rows = result.sessions as Array<Partial<SessionListEntry> | null>
|
|
74
|
+
const sessions = rows.filter(s => typeof s?.id === 'string' && s.id !== '').map(s => ({
|
|
75
|
+
id: s!.id!,
|
|
76
|
+
name: typeof s!.name === 'string' ? s!.name : '',
|
|
77
|
+
messageCount: Number.isFinite(s!.messageCount) ? s!.messageCount! : 0,
|
|
78
|
+
lastActive: Number.isFinite(s!.lastActive) ? s!.lastActive! : 0,
|
|
79
|
+
}))
|
|
80
|
+
if (sessions.length < rows.length) process.stderr.write(`telegram channel: /sessions skipped ${rows.length - sessions.length} session row(s) without an id\n`)
|
|
81
|
+
return { sessions, activeId: typeof result.activeSessionId === 'string' ? result.activeSessionId : '' }
|
|
82
|
+
}
|
|
@@ -26,7 +26,8 @@ interface Dependencies {
|
|
|
26
26
|
}
|
|
27
27
|
const description = (e: any) => String(e?.description ?? e?.message ?? '');
|
|
28
28
|
const absent = (e: any) => /message to (?:edit|delete) not found|message_id_invalid/i.test(description(e));
|
|
29
|
-
|
|
29
|
+
/** Telegram refused an edit because the message already shows this content. */
|
|
30
|
+
export const unchanged = (e: any) => /message is not modified/i.test(description(e));
|
|
30
31
|
export class LiveTaskBrowser {
|
|
31
32
|
private entries = new Map<string, Entry>();
|
|
32
33
|
private locks = new Map<string, Promise<unknown>>();
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ChatChannelOrApi } from '../history/types';
|
|
2
|
-
import { SessionStore } from './store';
|
|
3
|
-
export interface CompactionResult {
|
|
4
|
-
beforeMessages: number;
|
|
5
|
-
afterMessages: number;
|
|
6
|
-
beforeTokens: number;
|
|
7
|
-
afterTokens: number;
|
|
8
|
-
reductionPct: number;
|
|
9
|
-
contextPctBefore: number;
|
|
10
|
-
contextPctAfter: number;
|
|
11
|
-
}
|
|
12
|
-
export declare class NotEnoughMessagesError extends Error {
|
|
13
|
-
constructor(count: number);
|
|
14
|
-
}
|
|
15
|
-
/** Reports chunk-summarization progress during a multi-chunk compact (done, total). */
|
|
16
|
-
export type CompactProgress = (done: number, total: number) => void;
|
|
17
|
-
export interface ClaudeCliResult {
|
|
18
|
-
status: number | null;
|
|
19
|
-
stdout: string;
|
|
20
|
-
stderr: string;
|
|
21
|
-
error?: Error;
|
|
22
|
-
}
|
|
23
|
-
/** Injectable so tests can drive the compactor without a real `claude` binary. */
|
|
24
|
-
export type ClaudeCliSpawnFn = (bin: string, args: string[], input: string) => Promise<ClaudeCliResult>;
|
|
25
|
-
/**
|
|
26
|
-
* Async `claude` CLI spawn. Replaces the prior `spawnSync` call: `spawnSync`
|
|
27
|
-
* blocks the daemon's single event loop for the full duration of the call — and
|
|
28
|
-
* every agent shares one process, so one compaction call froze ALL agents/
|
|
29
|
-
* channels until it returned (up to SUMMARY_TIMEOUT_MS, x N chunks sequentially
|
|
30
|
-
* on large sessions). `spawn` yields the event loop while the child runs.
|
|
31
|
-
* Mirrors the sync `{status, stdout, stderr, error}` contract so callers'
|
|
32
|
-
* existing error handling is unchanged.
|
|
33
|
-
*/
|
|
34
|
-
export declare function defaultSpawnClaude(bin: string, args: string[], input: string): Promise<ClaudeCliResult>;
|
|
35
|
-
export declare class SessionCompactor {
|
|
36
|
-
private readonly sessionStore;
|
|
37
|
-
private readonly spawnClaude;
|
|
38
|
-
constructor(sessionStore: SessionStore, spawnClaude?: ClaudeCliSpawnFn);
|
|
39
|
-
compact(agentId: string, chatId: string, sessionId: string, model: string, contextWindow: number, channel?: ChatChannelOrApi, onProgress?: CompactProgress): Promise<CompactionResult>;
|
|
40
|
-
private summarizeWithChunking;
|
|
41
|
-
/** Bounded worker pool (mirrors the pattern in apps/installer.ts restoreRunningApps): at
|
|
42
|
-
* most CHUNK_CONCURRENCY `claude --print` calls in flight; results land by index so
|
|
43
|
-
* output order matches chunk order regardless of completion order. */
|
|
44
|
-
private summarizeChunksConcurrently;
|
|
45
|
-
/** Summarize one chunk; after CHUNK_MAX_ATTEMPTS failures, degrade to a truncated raw
|
|
46
|
-
* excerpt instead of throwing, so one bad chunk can't fail the whole compact job. */
|
|
47
|
-
private summarizeChunkWithFallback;
|
|
48
|
-
/** Merge per-chunk summaries into one; degrade to the unmerged concatenation on repeated failure. */
|
|
49
|
-
private mergeChunkSummaries;
|
|
50
|
-
private splitIntoChunks;
|
|
51
|
-
private callClaudeForSummary;
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=compactor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compactor.d.ts","sourceRoot":"","sources":["../../src/session/compactor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,KAAK,EAAE,MAAM;CAI1B;AAkCD,uFAAuF;AACvF,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,kFAAkF;AAClF,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;AAExG;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA2CvG;AAED,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW;gBADX,YAAY,EAAE,YAAY,EAC1B,WAAW,GAAE,gBAAqC;IAG/D,OAAO,CACX,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,gBAA6B,EACtC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,gBAAgB,CAAC;YA2Cd,qBAAqB;IAmBnC;;2EAEuE;YACzD,2BAA2B;IAqBzC;0FACsF;YACxE,0BAA0B;IAkBxC,qGAAqG;YACvF,mBAAmB;IAejC,OAAO,CAAC,eAAe;YAkBT,oBAAoB;CA2BnC"}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SessionCompactor = exports.NotEnoughMessagesError = void 0;
|
|
37
|
-
exports.defaultSpawnClaude = defaultSpawnClaude;
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const child_process_1 = require("child_process");
|
|
41
|
-
const claude_bin_1 = require("./claude-bin");
|
|
42
|
-
const plugin_info_1 = require("../pstack/plugin-info");
|
|
43
|
-
class NotEnoughMessagesError extends Error {
|
|
44
|
-
constructor(count) {
|
|
45
|
-
super(`Not enough messages to compact (${count} messages, minimum 5 required)`);
|
|
46
|
-
this.name = 'NotEnoughMessagesError';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.NotEnoughMessagesError = NotEnoughMessagesError;
|
|
50
|
-
// Max characters per chunk sent to claude CLI (~100K chars ≈ ~25K tokens, well within 200K limit)
|
|
51
|
-
const CHUNK_CHARS = 100000;
|
|
52
|
-
// Number of recent messages to keep verbatim; older messages are summarized
|
|
53
|
-
const KEEP_LAST_MESSAGES = 45;
|
|
54
|
-
// Prompt used to merge multiple chunk summaries into one
|
|
55
|
-
const MERGE_SUMMARIES_PROMPT = 'These are summaries of sequential parts of a conversation. Merge them into a single concise summary preserving key facts, decisions, context, and any open tasks.';
|
|
56
|
-
// Default instruction for summarizing a single conversation or chunk
|
|
57
|
-
const SINGLE_SUMMARY_INSTRUCTION = 'Summarize this conversation concisely, preserving key facts, decisions, context the assistant should remember, and any open questions or unfinished tasks.';
|
|
58
|
-
// System prompt prepended to every claude CLI summarization call
|
|
59
|
-
const COMPACTOR_SYSTEM_PROMPT = 'You are a conversation archiver. Your ONLY task is to produce a concise summary of the conversation transcript below. Do NOT respond to the conversation. Do NOT ask questions. Output ONLY the summary.';
|
|
60
|
-
// Max concurrent `claude --print` chunk-summary calls in flight at once. Bounded
|
|
61
|
-
// (not "all N chunks at once") to cap worst-case concurrent model calls/memory,
|
|
62
|
-
// while still cutting sequential wall time roughly by this factor on large sessions.
|
|
63
|
-
const CHUNK_CONCURRENCY = 4;
|
|
64
|
-
// Attempts per chunk (1 initial + retries) before degrading to a truncated raw
|
|
65
|
-
// excerpt instead of failing the whole compact job over one bad chunk.
|
|
66
|
-
const CHUNK_MAX_ATTEMPTS = 2;
|
|
67
|
-
// Raw-excerpt length used when a chunk exhausts its summarization attempts.
|
|
68
|
-
const DEGRADED_EXCERPT_CHARS = 2000;
|
|
69
|
-
// Hard ceiling on a single `claude --print` summarization spawn — mirrors the
|
|
70
|
-
// prior spawnSync timeout, but non-blocking (see defaultSpawnClaude below).
|
|
71
|
-
const SUMMARY_TIMEOUT_MS = 300000;
|
|
72
|
-
// Rough token estimate: ~4 chars per token
|
|
73
|
-
function estimateTokens(messages) {
|
|
74
|
-
return Math.round(messages.reduce((acc, m) => acc + m.content.length, 0) / 4);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Async `claude` CLI spawn. Replaces the prior `spawnSync` call: `spawnSync`
|
|
78
|
-
* blocks the daemon's single event loop for the full duration of the call — and
|
|
79
|
-
* every agent shares one process, so one compaction call froze ALL agents/
|
|
80
|
-
* channels until it returned (up to SUMMARY_TIMEOUT_MS, x N chunks sequentially
|
|
81
|
-
* on large sessions). `spawn` yields the event loop while the child runs.
|
|
82
|
-
* Mirrors the sync `{status, stdout, stderr, error}` contract so callers'
|
|
83
|
-
* existing error handling is unchanged.
|
|
84
|
-
*/
|
|
85
|
-
function defaultSpawnClaude(bin, args, input) {
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
let settled = false;
|
|
88
|
-
let stdout = '';
|
|
89
|
-
let stderr = '';
|
|
90
|
-
const settle = (r) => {
|
|
91
|
-
if (settled)
|
|
92
|
-
return;
|
|
93
|
-
settled = true;
|
|
94
|
-
clearTimeout(timer);
|
|
95
|
-
resolve(r);
|
|
96
|
-
};
|
|
97
|
-
const timer = setTimeout(() => {
|
|
98
|
-
try {
|
|
99
|
-
child.kill('SIGKILL');
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
/* already gone */
|
|
103
|
-
}
|
|
104
|
-
settle({ status: null, stdout: '', stderr, error: new Error(`claude CLI timed out after ${SUMMARY_TIMEOUT_MS}ms`) });
|
|
105
|
-
}, SUMMARY_TIMEOUT_MS);
|
|
106
|
-
const child = (0, child_process_1.spawn)(bin, args, {
|
|
107
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
108
|
-
env: { ...process.env, PATH: (0, claude_bin_1.pathWithNativeBin)() },
|
|
109
|
-
});
|
|
110
|
-
child.stdout?.on('data', (d) => {
|
|
111
|
-
stdout += String(d);
|
|
112
|
-
});
|
|
113
|
-
child.stderr?.on('data', (d) => {
|
|
114
|
-
stderr += String(d);
|
|
115
|
-
});
|
|
116
|
-
child.on('error', (err) => settle({ status: null, stdout: '', stderr, error: err }));
|
|
117
|
-
child.on('close', (code) => settle({ status: code, stdout, stderr }));
|
|
118
|
-
// stdin emits its own async 'error' (e.g. EPIPE if the child exits before we
|
|
119
|
-
// finish writing) separate from the child's 'error' event — must be handled
|
|
120
|
-
// or an unhandled stream error crashes the daemon.
|
|
121
|
-
child.stdin?.on('error', () => { });
|
|
122
|
-
try {
|
|
123
|
-
child.stdin?.write(input);
|
|
124
|
-
child.stdin?.end();
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
settle({ status: null, stdout: '', stderr, error: err });
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
class SessionCompactor {
|
|
132
|
-
constructor(sessionStore, spawnClaude = defaultSpawnClaude) {
|
|
133
|
-
this.sessionStore = sessionStore;
|
|
134
|
-
this.spawnClaude = spawnClaude;
|
|
135
|
-
}
|
|
136
|
-
async compact(agentId, chatId, sessionId, model, contextWindow, channel = 'telegram', onProgress) {
|
|
137
|
-
// Load current history
|
|
138
|
-
const messages = await this.sessionStore.loadTelegramSession(agentId, chatId, sessionId, channel);
|
|
139
|
-
if (messages.length < 5) {
|
|
140
|
-
throw new NotEnoughMessagesError(messages.length);
|
|
141
|
-
}
|
|
142
|
-
const beforeMessages = messages.length;
|
|
143
|
-
const beforeTokens = estimateTokens(messages);
|
|
144
|
-
// Archive original before compaction
|
|
145
|
-
const agentsBaseDir = this.sessionStore.getAgentsBaseDir();
|
|
146
|
-
const sessionDir = path.join(agentsBaseDir, agentId, 'sessions', `${channel}-${chatId}`);
|
|
147
|
-
fs.mkdirSync(sessionDir, { recursive: true });
|
|
148
|
-
const archivePath = path.join(sessionDir, `${sessionId}.pre-compact-${Date.now()}.json`);
|
|
149
|
-
fs.writeFileSync(archivePath, JSON.stringify(messages, null, 2), 'utf-8');
|
|
150
|
-
// Keep last N messages verbatim; summarize only the older portion (or all if < N)
|
|
151
|
-
const tail = messages.slice(-KEEP_LAST_MESSAGES);
|
|
152
|
-
const toSummarize = messages.length > KEEP_LAST_MESSAGES ? messages.slice(0, -KEEP_LAST_MESSAGES) : messages;
|
|
153
|
-
const historyText = toSummarize
|
|
154
|
-
.map(m => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}`)
|
|
155
|
-
.join('\n\n');
|
|
156
|
-
const summaryText = await this.summarizeWithChunking(historyText, model, onProgress);
|
|
157
|
-
const compacted = [
|
|
158
|
-
{ role: 'system', content: `[Conversation Summary]\n${summaryText}`, ts: Date.now() },
|
|
159
|
-
...tail,
|
|
160
|
-
];
|
|
161
|
-
// Save compacted history (original already archived above)
|
|
162
|
-
await this.sessionStore.saveTelegramSession(agentId, chatId, sessionId, compacted, channel);
|
|
163
|
-
const afterMessages = compacted.length;
|
|
164
|
-
const afterTokens = estimateTokens(compacted);
|
|
165
|
-
const reductionPct = beforeTokens > 0 ? Math.max(0, Math.round((1 - afterTokens / beforeTokens) * 100)) : 0;
|
|
166
|
-
const contextPctBefore = Math.round((beforeTokens / contextWindow) * 100);
|
|
167
|
-
const contextPctAfter = Math.round((afterTokens / contextWindow) * 100);
|
|
168
|
-
return { beforeMessages, afterMessages, beforeTokens, afterTokens, reductionPct, contextPctBefore, contextPctAfter };
|
|
169
|
-
}
|
|
170
|
-
async summarizeWithChunking(historyText, model, onProgress) {
|
|
171
|
-
// If small enough, summarize directly. No chunking → no chunk to retry/degrade
|
|
172
|
-
// against, so a failure here still fails the compact job (original behavior).
|
|
173
|
-
if (historyText.length <= CHUNK_CHARS) {
|
|
174
|
-
return this.callClaudeForSummary(historyText, model);
|
|
175
|
-
}
|
|
176
|
-
// Split into chunks and summarize with bounded concurrency; a single bad
|
|
177
|
-
// chunk degrades to a raw excerpt instead of failing the whole job.
|
|
178
|
-
const chunks = this.splitIntoChunks(historyText, CHUNK_CHARS);
|
|
179
|
-
const chunkSummaries = await this.summarizeChunksConcurrently(chunks, model, onProgress);
|
|
180
|
-
// Merge chunk summaries into final summary. If the merge call itself can't
|
|
181
|
-
// be completed, fall back to the concatenated per-part summaries rather than
|
|
182
|
-
// losing the whole compaction — still far smaller than the raw history.
|
|
183
|
-
const mergedText = chunkSummaries.join('\n\n');
|
|
184
|
-
return this.mergeChunkSummaries(mergedText, model);
|
|
185
|
-
}
|
|
186
|
-
/** Bounded worker pool (mirrors the pattern in apps/installer.ts restoreRunningApps): at
|
|
187
|
-
* most CHUNK_CONCURRENCY `claude --print` calls in flight; results land by index so
|
|
188
|
-
* output order matches chunk order regardless of completion order. */
|
|
189
|
-
async summarizeChunksConcurrently(chunks, model, onProgress) {
|
|
190
|
-
const results = new Array(chunks.length);
|
|
191
|
-
let completed = 0;
|
|
192
|
-
let cursor = 0;
|
|
193
|
-
const worker = async () => {
|
|
194
|
-
while (cursor < chunks.length) {
|
|
195
|
-
const i = cursor++;
|
|
196
|
-
results[i] = await this.summarizeChunkWithFallback(chunks[i], model, i, chunks.length);
|
|
197
|
-
completed++;
|
|
198
|
-
onProgress?.(completed, chunks.length);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const poolSize = Math.min(CHUNK_CONCURRENCY, chunks.length);
|
|
202
|
-
await Promise.all(Array.from({ length: poolSize }, () => worker()));
|
|
203
|
-
return results;
|
|
204
|
-
}
|
|
205
|
-
/** Summarize one chunk; after CHUNK_MAX_ATTEMPTS failures, degrade to a truncated raw
|
|
206
|
-
* excerpt instead of throwing, so one bad chunk can't fail the whole compact job. */
|
|
207
|
-
async summarizeChunkWithFallback(chunk, model, index, total) {
|
|
208
|
-
const instruction = `This is part ${index + 1} of ${total} of a longer conversation. Summarize this segment concisely.`;
|
|
209
|
-
let lastErr;
|
|
210
|
-
for (let attempt = 1; attempt <= CHUNK_MAX_ATTEMPTS; attempt++) {
|
|
211
|
-
try {
|
|
212
|
-
const summary = await this.callClaudeForSummary(chunk, model, instruction);
|
|
213
|
-
return `[Part ${index + 1}/${total}]\n${summary}`;
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
lastErr = err;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const excerpt = chunk.length > DEGRADED_EXCERPT_CHARS ? `${chunk.slice(0, DEGRADED_EXCERPT_CHARS)}…(truncated)` : chunk;
|
|
220
|
-
console.error(`[SessionCompactor] Chunk ${index + 1}/${total} summarization failed after ${CHUNK_MAX_ATTEMPTS} attempts (${lastErr?.message ?? 'unknown error'}); using truncated raw excerpt.`);
|
|
221
|
-
return `[Part ${index + 1}/${total} — summarization failed after ${CHUNK_MAX_ATTEMPTS} attempts (${lastErr?.message ?? 'unknown error'}); showing truncated raw excerpt]\n${excerpt}`;
|
|
222
|
-
}
|
|
223
|
-
/** Merge per-chunk summaries into one; degrade to the unmerged concatenation on repeated failure. */
|
|
224
|
-
async mergeChunkSummaries(mergedText, model) {
|
|
225
|
-
let lastErr;
|
|
226
|
-
for (let attempt = 1; attempt <= CHUNK_MAX_ATTEMPTS; attempt++) {
|
|
227
|
-
try {
|
|
228
|
-
return await this.callClaudeForSummary(mergedText, model, MERGE_SUMMARIES_PROMPT);
|
|
229
|
-
}
|
|
230
|
-
catch (err) {
|
|
231
|
-
lastErr = err;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
console.error(`[SessionCompactor] Merge-summaries call failed after ${CHUNK_MAX_ATTEMPTS} attempts (${lastErr?.message ?? 'unknown error'}); using unmerged per-chunk summaries.`);
|
|
235
|
-
return mergedText;
|
|
236
|
-
}
|
|
237
|
-
splitIntoChunks(text, maxChars) {
|
|
238
|
-
const chunks = [];
|
|
239
|
-
let start = 0;
|
|
240
|
-
while (start < text.length) {
|
|
241
|
-
let end = start + maxChars;
|
|
242
|
-
if (end < text.length) {
|
|
243
|
-
// Break at a newline boundary to avoid splitting mid-message
|
|
244
|
-
const boundary = text.lastIndexOf('\n\n', end);
|
|
245
|
-
if (boundary > start)
|
|
246
|
-
end = boundary;
|
|
247
|
-
}
|
|
248
|
-
chunks.push(text.slice(start, end));
|
|
249
|
-
start = end;
|
|
250
|
-
}
|
|
251
|
-
return chunks;
|
|
252
|
-
}
|
|
253
|
-
async callClaudeForSummary(text, model, instruction = SINGLE_SUMMARY_INSTRUCTION) {
|
|
254
|
-
// Wrap content in XML tags so claude treats it as data to analyze, not an active conversation
|
|
255
|
-
const prompt = `${COMPACTOR_SYSTEM_PROMPT}\n\n${instruction}\n\n<transcript>\n${text}\n</transcript>\n\nWrite a concise summary of the above transcript now:`;
|
|
256
|
-
// Resolve claude the same way the session subprocess does: honor CLAUDE_BIN
|
|
257
|
-
// (which may carry args), else probe PATH and the native/legacy install
|
|
258
|
-
// locations. This runs in the gateway's own (possibly minimal) PATH, so
|
|
259
|
-
// without resolution `claude --print` would fail identically to a session
|
|
260
|
-
// spawn after the native-installer migration.
|
|
261
|
-
const { command: claudeBin, args: claudeBinArgs } = (0, claude_bin_1.claudeCommand)();
|
|
262
|
-
const result = await this.spawnClaude(claudeBin, [...claudeBinArgs, '--print', '--model', model, '--settings', JSON.stringify(plugin_info_1.PSTACK_OFF_SETTINGS)], prompt);
|
|
263
|
-
if (result.error) {
|
|
264
|
-
throw new Error(`claude CLI error: ${result.error.message}`);
|
|
265
|
-
}
|
|
266
|
-
if (result.status !== 0) {
|
|
267
|
-
const stderr = result.stderr?.trim() ?? '';
|
|
268
|
-
throw new Error(`claude CLI exited with status ${result.status}: ${stderr}`);
|
|
269
|
-
}
|
|
270
|
-
return result.stdout?.trim() ?? '';
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
exports.SessionCompactor = SessionCompactor;
|
|
274
|
-
//# sourceMappingURL=compactor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compactor.js","sourceRoot":"","sources":["../../src/session/compactor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,gDA2CC;AA3HD,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAsC;AAItC,6CAAgE;AAChE,uDAA4D;AAY5D,M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