telecoder 0.0.0-stage → 1.2.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/.env.example +363 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE +22 -0
- package/README.md +126 -2
- package/dist/audio/transcribe.js +50 -0
- package/dist/bin/mcp-server.js +378 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +592 -0
- package/dist/bot/file-access.js +141 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +827 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/btw.js +224 -0
- package/dist/bot/handlers/command/cost.js +409 -0
- package/dist/bot/handlers/command/media.js +197 -0
- package/dist/bot/handlers/command/model.js +305 -0
- package/dist/bot/handlers/command/prefs-scope.js +197 -0
- package/dist/bot/handlers/command/project.js +536 -0
- package/dist/bot/handlers/command/resume.js +321 -0
- package/dist/bot/handlers/command/session.js +438 -0
- package/dist/bot/handlers/command/settings.js +1012 -0
- package/dist/bot/handlers/command/shared.js +210 -0
- package/dist/bot/handlers/command/streaming-mode.js +16 -0
- package/dist/bot/handlers/command/tasks.js +513 -0
- package/dist/bot/handlers/command/topic-store.js +113 -0
- package/dist/bot/handlers/command/topic.js +80 -0
- package/dist/bot/handlers/command.handler.js +772 -0
- package/dist/bot/handlers/fork.handler.js +1109 -0
- package/dist/bot/handlers/media-fallback.js +121 -0
- package/dist/bot/handlers/message/replies.js +133 -0
- package/dist/bot/handlers/message/shared.js +117 -0
- package/dist/bot/handlers/message/throttle.js +49 -0
- package/dist/bot/handlers/message/turn-notify.js +169 -0
- package/dist/bot/handlers/message/turn-runner.js +141 -0
- package/dist/bot/handlers/message.handler.js +107 -0
- package/dist/bot/handlers/newbot.handler.js +221 -0
- package/dist/bot/handlers/photo.handler.js +327 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/schedule.handler.js +303 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +209 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +139 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +971 -0
- package/dist/bot/middleware/stale-filter.js +31 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/agent-watchdog.js +162 -0
- package/dist/claude/agent.js +1458 -0
- package/dist/claude/ask-user.js +295 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +126 -0
- package/dist/claude/available-commands.js +153 -0
- package/dist/claude/carry-over.js +27 -0
- package/dist/claude/ccr-shim.js +46 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +121 -0
- package/dist/claude/command-parser.js +200 -0
- package/dist/claude/cost-overlay-scraper.js +129 -0
- package/dist/claude/enabled-plugins.js +56 -0
- package/dist/claude/fork-tree.js +393 -0
- package/dist/claude/held-query.js +190 -0
- package/dist/claude/in-flight-tracker.js +61 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +453 -0
- package/dist/claude/mcp-tools.js +354 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +450 -0
- package/dist/claude/model-catalog.js +85 -0
- package/dist/claude/monitor-relay.js +597 -0
- package/dist/claude/pending-forks.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +337 -0
- package/dist/claude/permission-mode.js +178 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-provider.js +2214 -0
- package/dist/claude/pty-spawn-config.js +296 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/request-queue.js +135 -0
- package/dist/claude/scheduled-runner.js +91 -0
- package/dist/claude/scheduler.js +237 -0
- package/dist/claude/scope-guard.js +274 -0
- package/dist/claude/sdk-permission-gate.js +77 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-cost.js +41 -0
- package/dist/claude/session-history.js +286 -0
- package/dist/claude/session-jsonl.js +920 -0
- package/dist/claude/session-manager.js +195 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +249 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/system-prompt.js +162 -0
- package/dist/claude/tasks-overlay-scraper.js +94 -0
- package/dist/claude/tip-scraper.js +78 -0
- package/dist/claude/tui-modal.js +501 -0
- package/dist/claude/tui-state.js +384 -0
- package/dist/claude/turn-end.js +91 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +305 -0
- package/dist/cli/commands/help.js +25 -0
- package/dist/cli/commands/init.js +123 -0
- package/dist/cli/commands/service.js +678 -0
- package/dist/cli/commands/start.js +53 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/dispatch.js +79 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +638 -0
- package/dist/cli/init/prompter.js +116 -0
- package/dist/cli/init/telegram.js +94 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +500 -0
- package/dist/index.js +367 -0
- package/dist/launcher.js +933 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +149 -0
- package/dist/providers/ccr-provider.js +60 -0
- package/dist/providers/claude-provider.js +63 -0
- package/dist/providers/prefs-sync.js +164 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +127 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/sdk-provider.js +37 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +214 -0
- package/dist/restart-when-idle.js +153 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +173 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +684 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +336 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +27 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +57 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1287 -0
- package/dist/telegram/prompt-label.js +142 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +105 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +209 -0
- package/dist/telegram/telegraph-settings.js +31 -0
- package/dist/telegram/telegraph.js +453 -0
- package/dist/telegram/terminal-renderer.js +671 -0
- package/dist/telegram/terminal-settings.js +25 -0
- package/dist/telegram/thread-titles.js +190 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/tts/tts-settings.js +62 -0
- package/dist/tts/tts.js +245 -0
- package/dist/tts/voice-reply.js +78 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-token.js +74 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +50 -0
- package/dist/utils/claude-env.js +54 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/debug-agent.js +117 -0
- package/dist/utils/debug-watchdog.js +121 -0
- package/dist/utils/download.js +111 -0
- package/dist/utils/exit-codes.js +48 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +81 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/project-data-dir.js +33 -0
- package/dist/utils/reasoning-summary.js +12 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +63 -0
- package/dist/utils/respawn-backoff.js +19 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +76 -4
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /resume, the way Claude Code's own /resume works: every conversation Claude
|
|
3
|
+
* Code has on disk for this project, newest first — from a terminal, another
|
|
4
|
+
* bot or this chat alike — with a toggle to every project, `/resume <words>`
|
|
5
|
+
* to search them, and `/resume <session id>` to open one directly.
|
|
6
|
+
*
|
|
7
|
+
* Picking one that another Claude process still has open starts a copy, as
|
|
8
|
+
* Claude Code does, so two writers never append to one transcript. Picking
|
|
9
|
+
* one another backend wrote (DeepSeek via CCR, or Claude while on CCR) goes on
|
|
10
|
+
* as a new session that starts with a recap: the old one's thinking blocks
|
|
11
|
+
* can't be replayed across backends.
|
|
12
|
+
*
|
|
13
|
+
* The `resume:<conversationId>` callback of the older, history-based picker is
|
|
14
|
+
* still what the ↩️ Back button sends; session.ts handles it.
|
|
15
|
+
*/
|
|
16
|
+
import * as crypto from 'crypto';
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import { BOT_ID } from '../../../config.js';
|
|
20
|
+
import { sessionManager } from '../../../claude/session-manager.js';
|
|
21
|
+
import { sessionHistory, allHistoryOwners } from '../../../claude/session-history.js';
|
|
22
|
+
import { detectOwnerProvider, rewriteJsonlSessionId } from '../../../claude/session-jsonl.js';
|
|
23
|
+
import { findSession, isSessionId, isSessionOpenElsewhere, listSessions, matchesQuery, } from '../../../claude/session-scan.js';
|
|
24
|
+
import { setPendingCarryOver } from '../../../claude/carry-over.js';
|
|
25
|
+
import { isProcessing } from '../../../claude/request-queue.js';
|
|
26
|
+
import { clearConversation, getActiveProviderName } from '../../../providers/provider-router.js';
|
|
27
|
+
import { buildCarryOverPreamble } from '../../../providers/provider-switch.js';
|
|
28
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
29
|
+
import { buildLetteredKeyboard, letteredOptionLines } from '../../../telegram/lettered-options.js';
|
|
30
|
+
import { cutLabel, promptLabel } from '../../../telegram/prompt-label.js';
|
|
31
|
+
import { editCallbackMessage, replyFormatted } from '../../../telegram/send.js';
|
|
32
|
+
import { taskListDisplay } from '../../../telegram/task-list.js';
|
|
33
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
34
|
+
import { formatTimeAgo, parseCallback, projectStatusSuffix, replyMd, resumeCommandMessage } from './shared.js';
|
|
35
|
+
import { restoreTopicAndRefreshBotName } from './topic.js';
|
|
36
|
+
import { sendView } from '../view.js';
|
|
37
|
+
import { resumeHistoryEntry, sendRecapHint } from './session.js';
|
|
38
|
+
/** Sessions per page: letters A–H, short enough to read on a phone. */
|
|
39
|
+
const PAGE_SIZE = 8;
|
|
40
|
+
const MAX_NAME_CHARS = 90;
|
|
41
|
+
export function buildResumePicker(p) {
|
|
42
|
+
const options = p.entries.map((e) => ({
|
|
43
|
+
label: e.name,
|
|
44
|
+
description: [formatTimeAgo(new Date(e.mtimeMs)), ...e.marks].join(' · '),
|
|
45
|
+
}));
|
|
46
|
+
const text = new EntityText().add('📜 ').bold(p.heading).add('\n\n').add(letteredOptionLines(options).join('\n'));
|
|
47
|
+
if (p.paging && (p.paging.page > 0 || p.paging.more))
|
|
48
|
+
text.add(`\n\nPage ${p.paging.page + 1}`);
|
|
49
|
+
if (p.footer)
|
|
50
|
+
text.add('\n\n').italic(p.footer);
|
|
51
|
+
const keyboard = buildLetteredKeyboard(p.entries.map((e) => ({ label: e.name, callbackData: `resume:s:${e.sessionId}` })));
|
|
52
|
+
const nav = [];
|
|
53
|
+
if (p.paging && p.paging.page > 0) {
|
|
54
|
+
nav.push({ text: '◀ Newer', callback_data: `resume:l:${p.paging.scope}:${p.paging.page - 1}` });
|
|
55
|
+
}
|
|
56
|
+
if (p.paging?.more) {
|
|
57
|
+
nav.push({ text: 'Older ▶', callback_data: `resume:l:${p.paging.scope}:${p.paging.page + 1}` });
|
|
58
|
+
}
|
|
59
|
+
if (nav.length)
|
|
60
|
+
keyboard.push(nav);
|
|
61
|
+
if (p.toggle)
|
|
62
|
+
keyboard.push([{ text: p.toggle.label, callback_data: `resume:l:${p.toggle.scope}:0` }]);
|
|
63
|
+
return { text: text.build(), keyboard };
|
|
64
|
+
}
|
|
65
|
+
/** The newest TeleCoder topic any chat gave each conversation. */
|
|
66
|
+
function topicsById(owners) {
|
|
67
|
+
const topics = new Map();
|
|
68
|
+
for (const [id, list] of owners) {
|
|
69
|
+
const latest = list
|
|
70
|
+
.filter((o) => o.entry.topic)
|
|
71
|
+
.sort((a, b) => b.entry.lastActivity.localeCompare(a.entry.lastActivity))[0];
|
|
72
|
+
if (latest?.entry.topic)
|
|
73
|
+
topics.set(id, latest.entry.topic);
|
|
74
|
+
}
|
|
75
|
+
return topics;
|
|
76
|
+
}
|
|
77
|
+
/** What a session is called: a /rename, then a chat's topic, then Claude Code's title, then the first prompt. */
|
|
78
|
+
function titleOf(s, topics) {
|
|
79
|
+
const firstPrompt = s.firstPrompt ? promptLabel(s.firstPrompt) : undefined;
|
|
80
|
+
return s.customTitle ?? topics.get(s.sessionId) ?? s.aiTitle ?? firstPrompt ?? 'Untitled';
|
|
81
|
+
}
|
|
82
|
+
function isForeignModel(model) {
|
|
83
|
+
return model !== undefined && !model.startsWith('claude-');
|
|
84
|
+
}
|
|
85
|
+
function toEntry(s, topics, withProject, currentId) {
|
|
86
|
+
const title = titleOf(s, topics);
|
|
87
|
+
const name = withProject ? `${path.basename(s.projectPath)} · ${title}` : title;
|
|
88
|
+
const marks = [];
|
|
89
|
+
if (s.sessionId === currentId)
|
|
90
|
+
marks.push('current');
|
|
91
|
+
else if (isSessionOpenElsewhere(s.sessionId))
|
|
92
|
+
marks.push('open elsewhere');
|
|
93
|
+
if (isForeignModel(s.lastModel))
|
|
94
|
+
marks.push('via CCR');
|
|
95
|
+
return { sessionId: s.sessionId, name: cutLabel(name, MAX_NAME_CHARS), mtimeMs: s.mtimeMs, marks };
|
|
96
|
+
}
|
|
97
|
+
/** The picker for `scope` at `page`, or undefined when there is nothing to list. */
|
|
98
|
+
function listView(sessionKey, scope, page) {
|
|
99
|
+
const session = sessionManager.getSession(sessionKey);
|
|
100
|
+
const projectPath = scope === 'p' ? session?.workingDirectory : undefined;
|
|
101
|
+
const owners = allHistoryOwners(BOT_ID);
|
|
102
|
+
const { sessions, more } = listSessions({
|
|
103
|
+
projectPath,
|
|
104
|
+
knownIds: new Set(owners.keys()),
|
|
105
|
+
offset: page * PAGE_SIZE,
|
|
106
|
+
limit: PAGE_SIZE,
|
|
107
|
+
});
|
|
108
|
+
if (sessions.length === 0 && page === 0)
|
|
109
|
+
return undefined;
|
|
110
|
+
const topics = topicsById(owners);
|
|
111
|
+
const projectName = projectPath ? path.basename(projectPath) : undefined;
|
|
112
|
+
return buildResumePicker({
|
|
113
|
+
heading: projectName ? `Sessions in ${projectName}` : 'Sessions in all projects',
|
|
114
|
+
entries: sessions.map((s) => toEntry(s, topics, !projectPath, session?.claudeSessionId)),
|
|
115
|
+
paging: { scope: projectPath ? 'p' : 'a', page, more },
|
|
116
|
+
toggle: projectPath
|
|
117
|
+
? { label: '🌐 All projects', scope: 'a' }
|
|
118
|
+
: session ? { label: `📁 Only ${path.basename(session.workingDirectory)}`, scope: 'p' } : undefined,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// ── /resume ──────────────────────────────────────────────────────────────
|
|
122
|
+
export async function handleResume(ctx) {
|
|
123
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
124
|
+
if (!keyInfo)
|
|
125
|
+
return;
|
|
126
|
+
const { sessionKey } = keyInfo;
|
|
127
|
+
// After a restart the chat's project is only on disk; it decides the scope.
|
|
128
|
+
const { session } = sessionManager.getOrRestoreSession(sessionKey);
|
|
129
|
+
const arg = (ctx.message?.text ?? '').split(' ').slice(1).join(' ').trim();
|
|
130
|
+
if (!arg) {
|
|
131
|
+
const view = listView(sessionKey, session ? 'p' : 'a', 0) ?? (session ? listView(sessionKey, 'a', 0) : undefined);
|
|
132
|
+
if (!view) {
|
|
133
|
+
await replyMd(ctx, 'ℹ️ No conversations to resume yet.\n\nUse `/project <name>` to start one.');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
await sendView(ctx, view, 'reply');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isSessionId(arg)) {
|
|
140
|
+
const found = findSession(arg, session?.workingDirectory);
|
|
141
|
+
if (!found) {
|
|
142
|
+
await replyMd(ctx, `ℹ️ No session \`${arg}\` on this machine.`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await resumeScanned(ctx, sessionKey, found);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
await searchSessions(ctx, sessionKey, arg);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* `/resume <words>`: this project's sessions whose title or first prompt has
|
|
152
|
+
* every word, or every project's when none here do. One match opens straight
|
|
153
|
+
* away, as `claude --resume <name>` does.
|
|
154
|
+
*/
|
|
155
|
+
async function searchSessions(ctx, sessionKey, query) {
|
|
156
|
+
const session = sessionManager.getSession(sessionKey);
|
|
157
|
+
const owners = allHistoryOwners(BOT_ID);
|
|
158
|
+
const knownIds = new Set(owners.keys());
|
|
159
|
+
const topics = topicsById(owners);
|
|
160
|
+
const match = (s) => matchesQuery(s, query, topics.get(s.sessionId));
|
|
161
|
+
const search = (projectPath) => listSessions({ projectPath, knownIds, match, offset: 0, limit: PAGE_SIZE });
|
|
162
|
+
let projectPath = session?.workingDirectory;
|
|
163
|
+
let found = projectPath ? search(projectPath) : { sessions: [], more: false };
|
|
164
|
+
if (found.sessions.length === 0) {
|
|
165
|
+
projectPath = undefined;
|
|
166
|
+
found = search();
|
|
167
|
+
}
|
|
168
|
+
if (found.sessions.length === 0) {
|
|
169
|
+
await replyFormatted(ctx, new EntityText().add('ℹ️ No session matches “').add(query).add('”.').build());
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (found.sessions.length === 1) {
|
|
173
|
+
await resumeScanned(ctx, sessionKey, found.sessions[0]);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
await sendView(ctx, buildResumePicker({
|
|
177
|
+
heading: `Sessions matching “${query}”` + (projectPath ? ` in ${path.basename(projectPath)}` : ''),
|
|
178
|
+
entries: found.sessions.map((s) => toEntry(s, topics, !projectPath, session?.claudeSessionId)),
|
|
179
|
+
footer: found.more ? `Showing the newest ${PAGE_SIZE}. Add words to narrow it down.` : undefined,
|
|
180
|
+
}), 'reply');
|
|
181
|
+
}
|
|
182
|
+
export async function handleResumeCallback(ctx) {
|
|
183
|
+
const cb = parseCallback(ctx, 'resume:');
|
|
184
|
+
if (!cb)
|
|
185
|
+
return;
|
|
186
|
+
const { sessionKey, data } = cb;
|
|
187
|
+
const list = /^resume:l:([pa]):(\d+)$/.exec(data);
|
|
188
|
+
if (list) {
|
|
189
|
+
const view = listView(sessionKey, list[1], Number(list[2]));
|
|
190
|
+
if (!view) {
|
|
191
|
+
await ctx.answerCallbackQuery({ text: 'Nothing more to list.' });
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
await sendView(ctx, view, 'edit');
|
|
195
|
+
await ctx.answerCallbackQuery();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (data.startsWith('resume:s:')) {
|
|
199
|
+
const id = data.slice('resume:s:'.length);
|
|
200
|
+
const found = findSession(id, sessionManager.getSession(sessionKey)?.workingDirectory);
|
|
201
|
+
if (!found) {
|
|
202
|
+
await ctx.answerCallbackQuery({ text: "That session's transcript is gone from disk." });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
await resumeScanned(ctx, sessionKey, found);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
await resumeHistoryEntry(ctx, sessionKey, data.slice('resume:'.length));
|
|
209
|
+
}
|
|
210
|
+
// ── Opening one ──────────────────────────────────────────────────────────
|
|
211
|
+
const BACKEND_NAMES = { claude: 'Claude', ccr: 'CCR' };
|
|
212
|
+
/**
|
|
213
|
+
* A copy of a transcript under a fresh id, for a session another process is
|
|
214
|
+
* still writing to. A line it was halfway through writing is left out.
|
|
215
|
+
*/
|
|
216
|
+
function copyTranscript(s) {
|
|
217
|
+
try {
|
|
218
|
+
let raw = fs.readFileSync(s.file, 'utf-8');
|
|
219
|
+
if (!raw.endsWith('\n'))
|
|
220
|
+
raw = raw.slice(0, raw.lastIndexOf('\n') + 1);
|
|
221
|
+
const newId = crypto.randomUUID();
|
|
222
|
+
// Beside the original: Claude Code names the directory, and encodes more
|
|
223
|
+
// of a path's characters than sessionJsonlPath does.
|
|
224
|
+
const target = path.join(path.dirname(s.file), `${newId}.jsonl`);
|
|
225
|
+
fs.writeFileSync(target, rewriteJsonlSessionId(raw, newId), { mode: 0o600 });
|
|
226
|
+
return newId;
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
console.error('[Resume] Could not copy transcript:', err);
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** Answer a button tap, or reply to the command. */
|
|
234
|
+
async function tell(ctx, text) {
|
|
235
|
+
if (ctx.callbackQuery)
|
|
236
|
+
await ctx.answerCallbackQuery({ text, show_alert: text.length > 60 });
|
|
237
|
+
else
|
|
238
|
+
await ctx.reply(text);
|
|
239
|
+
}
|
|
240
|
+
async function resumeScanned(ctx, sessionKey, s) {
|
|
241
|
+
const current = sessionManager.getSession(sessionKey);
|
|
242
|
+
if (current?.claudeSessionId === s.sessionId) {
|
|
243
|
+
await tell(ctx, "You're already in this conversation.");
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (isProcessing(sessionKey)) {
|
|
247
|
+
await tell(ctx, 'A reply is still running here — wait for it to finish, or /cancel it, then try again.');
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (!fs.existsSync(s.projectPath)) {
|
|
251
|
+
await tell(ctx, `That conversation ran in ${s.projectPath}, which no longer exists.`);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const notes = [];
|
|
255
|
+
let sessionId = s.sessionId;
|
|
256
|
+
if (isSessionOpenElsewhere(s.sessionId)) {
|
|
257
|
+
const copyId = copyTranscript(s);
|
|
258
|
+
if (!copyId) {
|
|
259
|
+
await tell(ctx, 'That session is open in another Claude Code process, and copying it failed.');
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Claude Code's own wording for the same case.
|
|
263
|
+
notes.push(`Session ${s.sessionId} is open in another Claude Code process, so this started a copy as ${copyId}. The original conversation is unchanged.`);
|
|
264
|
+
sessionId = copyId;
|
|
265
|
+
}
|
|
266
|
+
// This chat's own entry brings back its conversation and topic; any other
|
|
267
|
+
// chat's or bot's topic is the next best name for it.
|
|
268
|
+
const own = sessionHistory.findByClaudeSessionId(sessionId).find((o) => o.sessionKey === sessionKey)?.entry;
|
|
269
|
+
let topic;
|
|
270
|
+
if (own) {
|
|
271
|
+
sessionManager.resumeSession(sessionKey, own.conversationId);
|
|
272
|
+
topic = own.topic;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (current && current.workingDirectory === s.projectPath)
|
|
276
|
+
sessionManager.startNewConversation(sessionKey);
|
|
277
|
+
else
|
|
278
|
+
sessionManager.setWorkingDirectory(sessionKey, s.projectPath);
|
|
279
|
+
topic = topicsById(allHistoryOwners(BOT_ID)).get(s.sessionId);
|
|
280
|
+
}
|
|
281
|
+
topic ??= s.customTitle ?? s.aiTitle;
|
|
282
|
+
const owner = own?.ownerProvider ?? detectOwnerProvider(s.file);
|
|
283
|
+
sessionManager.setClaudeSessionId(sessionKey, sessionId, owner);
|
|
284
|
+
// Drops the live process and in-memory state of the conversation this chat
|
|
285
|
+
// was in, so the next turn resumes the one just picked. After
|
|
286
|
+
// setClaudeSessionId, which it leaves alone.
|
|
287
|
+
clearConversation(sessionKey);
|
|
288
|
+
const provider = getActiveProviderName(sessionKey);
|
|
289
|
+
let carriedOver = false;
|
|
290
|
+
if (owner && owner !== provider) {
|
|
291
|
+
const preamble = buildCarryOverPreamble(sessionKey);
|
|
292
|
+
if (preamble)
|
|
293
|
+
setPendingCarryOver(sessionKey, preamble);
|
|
294
|
+
sessionManager.startNewConversation(sessionKey);
|
|
295
|
+
carriedOver = true;
|
|
296
|
+
notes.push(`This conversation ran on ${BACKEND_NAMES[owner] ?? owner} and this chat is on ${BACKEND_NAMES[provider] ?? provider}, ` +
|
|
297
|
+
`which can't replay its thinking. It goes on as a new session that starts with a recap of the last exchanges. ` +
|
|
298
|
+
`To continue it as it is, switch with /provider ${owner} and resume it again.`);
|
|
299
|
+
}
|
|
300
|
+
await restoreTopicAndRefreshBotName(ctx, sessionKey, topic);
|
|
301
|
+
const message = new EntityText()
|
|
302
|
+
.add('✅ Resumed ').bold(topic ?? sessionId)
|
|
303
|
+
.add('\n\nWorking directory: ').code(s.projectPath)
|
|
304
|
+
.append(projectStatusSuffix(sessionKey));
|
|
305
|
+
for (const note of notes)
|
|
306
|
+
message.add('\n\n').italic(note);
|
|
307
|
+
const text = message.build();
|
|
308
|
+
if (ctx.callbackQuery) {
|
|
309
|
+
await ctx.answerCallbackQuery({ text: 'Session resumed!' });
|
|
310
|
+
await editCallbackMessage(ctx, text);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
await replyFormatted(ctx, text);
|
|
314
|
+
}
|
|
315
|
+
if (carriedOver)
|
|
316
|
+
return;
|
|
317
|
+
await replyFormatted(ctx, resumeCommandMessage(sessionId));
|
|
318
|
+
await taskListDisplay.showRestored(ctx.api, sessionKey, sessionId);
|
|
319
|
+
await sendRecapHint(ctx, sessionKey);
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=resume.js.map
|