telecoder 0.0.0-stage → 1.3.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 +375 -0
- package/CHANGELOG.md +1867 -0
- package/LICENSE +22 -0
- package/README.md +130 -2
- package/dist/audio/transcribe.js +41 -0
- package/dist/bin/mcp-server.js +363 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +573 -0
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +150 -0
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/branch.handler.js +1096 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +803 -0
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/background.js +37 -0
- package/dist/bot/handlers/command/botname.js +76 -0
- package/dist/bot/handlers/command/btw.js +175 -0
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +226 -0
- package/dist/bot/handlers/command/prefs-scope.js +362 -0
- package/dist/bot/handlers/command/project.js +458 -0
- package/dist/bot/handlers/command/resume.js +325 -0
- package/dist/bot/handlers/command/session.js +299 -0
- package/dist/bot/handlers/command/settings.js +657 -0
- package/dist/bot/handlers/command/shared.js +207 -0
- package/dist/bot/handlers/command/tasks.js +681 -0
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +74 -0
- package/dist/bot/handlers/command/topic.js +27 -0
- package/dist/bot/handlers/command/usage.js +382 -0
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +446 -0
- package/dist/bot/handlers/loop.handler.js +389 -0
- package/dist/bot/handlers/media-fallback.js +126 -0
- package/dist/bot/handlers/message/replies.js +56 -0
- package/dist/bot/handlers/message/shared.js +95 -0
- package/dist/bot/handlers/message/turn-notify.js +135 -0
- package/dist/bot/handlers/message/turn-runner.js +56 -0
- package/dist/bot/handlers/message.handler.js +114 -0
- package/dist/bot/handlers/newbot.handler.js +230 -0
- package/dist/bot/handlers/photo.handler.js +286 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -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 +147 -0
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +145 -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 +1082 -0
- package/dist/bot/middleware/stale-filter.js +9 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +363 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +143 -0
- package/dist/claude/available-commands.js +156 -0
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/branch-tree.js +393 -0
- package/dist/claude/carry-over.js +25 -0
- package/dist/claude/ccr-shim.js +48 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +117 -0
- package/dist/claude/command-parser.js +206 -0
- package/dist/claude/cost-overlay-scraper.js +134 -0
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +52 -0
- package/dist/claude/in-flight-tracker.js +82 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +481 -0
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +817 -0
- package/dist/claude/model-catalog.js +102 -0
- package/dist/claude/monitor-relay.js +712 -0
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/pending-branches.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +338 -0
- package/dist/claude/permission-mode.js +152 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/prewarm.js +70 -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-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +2499 -0
- package/dist/claude/pty-spawn-config.js +343 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +107 -0
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +89 -0
- package/dist/claude/scheduler.js +241 -0
- package/dist/claude/scope-guard.js +279 -0
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-history.js +288 -0
- package/dist/claude/session-jsonl.js +1067 -0
- package/dist/claude/session-manager.js +216 -0
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +252 -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/tasks-overlay-scraper.js +217 -0
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +77 -0
- package/dist/claude/tui-modal.js +746 -0
- package/dist/claude/tui-state.js +456 -0
- package/dist/claude/turn-end.js +105 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +338 -0
- package/dist/cli/commands/help.js +34 -0
- package/dist/cli/commands/init.js +126 -0
- package/dist/cli/commands/service.js +710 -0
- package/dist/cli/commands/start.js +63 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +84 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +705 -0
- package/dist/cli/init/prompter.js +124 -0
- package/dist/cli/init/telegram.js +120 -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 +525 -0
- package/dist/index.js +443 -0
- package/dist/launcher.js +960 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +142 -0
- package/dist/providers/ccr-provider.js +59 -0
- package/dist/providers/claude-provider.js +10 -0
- package/dist/providers/prefs-sync.js +121 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +128 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +322 -0
- package/dist/restart-when-idle.js +173 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +161 -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 +522 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +282 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +26 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +96 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1019 -0
- package/dist/telegram/prompt-label.js +148 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +103 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +128 -0
- package/dist/telegram/terminal-renderer.js +667 -0
- package/dist/telegram/thread-titles.js +262 -0
- package/dist/telegram/threads-setup.js +117 -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-icon.js +248 -0
- package/dist/utils/bot-token.js +77 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +53 -0
- package/dist/utils/claude-env.js +53 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/download.js +137 -0
- package/dist/utils/exit-codes.js +59 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +78 -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/memory-pressure.js +60 -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/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +52 -0
- package/dist/utils/respawn-backoff.js +28 -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/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -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 +75 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Map an ImageAttachment mediaType to a sensible file extension. Falls back
|
|
6
|
+
* to `.bin` for unknowns — claude code's Read tool sniffs content anyway, the
|
|
7
|
+
* extension is mostly cosmetic.
|
|
8
|
+
*/
|
|
9
|
+
export function imageExtension(mediaType) {
|
|
10
|
+
if (mediaType === 'image/jpeg')
|
|
11
|
+
return 'jpg';
|
|
12
|
+
if (mediaType === 'image/png')
|
|
13
|
+
return 'png';
|
|
14
|
+
if (mediaType === 'image/gif')
|
|
15
|
+
return 'gif';
|
|
16
|
+
if (mediaType === 'image/webp')
|
|
17
|
+
return 'webp';
|
|
18
|
+
return 'bin';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Make every attachment reachable from the prompt text — exactly once.
|
|
22
|
+
*
|
|
23
|
+
* Claude turns an image path it finds in a pasted prompt into an `[Image #N]`
|
|
24
|
+
* chip and takes the path back out of the text. That is how an upload reaches
|
|
25
|
+
* the model as an image, and it needs no Read tool. But it fires once per
|
|
26
|
+
* distinct file, so staging a second copy of a picture the caller had already
|
|
27
|
+
* saved attached the same image twice: double the image tokens, and a note
|
|
28
|
+
* left reading "Saved at:" with nothing after it.
|
|
29
|
+
*
|
|
30
|
+
* So an image the caller already wrote to disk and named in the prompt needs
|
|
31
|
+
* nothing from us. Only an attachment with no on-disk copy is staged to /tmp,
|
|
32
|
+
* and only a path the prompt does not already carry is appended.
|
|
33
|
+
*
|
|
34
|
+
* Returns the prompt to send plus the temp files the caller must delete once
|
|
35
|
+
* the turn ends.
|
|
36
|
+
*/
|
|
37
|
+
export function stageImagesForPty(prompt, images) {
|
|
38
|
+
if (!images || images.length === 0)
|
|
39
|
+
return { prompt, tempPaths: [] };
|
|
40
|
+
const tempPaths = [];
|
|
41
|
+
const unreferenced = [];
|
|
42
|
+
for (const img of images) {
|
|
43
|
+
let filePath = img.path;
|
|
44
|
+
if (!filePath) {
|
|
45
|
+
const ext = imageExtension(img.mediaType);
|
|
46
|
+
filePath = path.join('/tmp', `telecoder-img-${randomUUID()}.${ext}`);
|
|
47
|
+
fs.writeFileSync(filePath, Buffer.from(img.data, 'base64'));
|
|
48
|
+
tempPaths.push(filePath);
|
|
49
|
+
}
|
|
50
|
+
if (!prompt.includes(filePath))
|
|
51
|
+
unreferenced.push(filePath);
|
|
52
|
+
}
|
|
53
|
+
if (unreferenced.length === 0)
|
|
54
|
+
return { prompt, tempPaths };
|
|
55
|
+
const imageList = unreferenced.map((p, i) => ` ${i + 1}. ${p}`).join('\n');
|
|
56
|
+
const augmented = `${prompt}
|
|
57
|
+
|
|
58
|
+
The user attached ${unreferenced.length === 1 ? 'an image' : `${unreferenced.length} images`} at:
|
|
59
|
+
${imageList}`;
|
|
60
|
+
return { prompt: augmented, tempPaths };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=stage-images.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool names that spawn a subagent (a nested Claude turn whose outcome arrives
|
|
3
|
+
* later as a task-notification). Historically Claude Code called this tool
|
|
4
|
+
* `Task`; newer builds renamed it to `Agent`. We match both so the async-tool
|
|
5
|
+
* relay (arming, `/tasks` tracking, completion notification) keeps working
|
|
6
|
+
* across versions. Add future aliases here — this is the single source of truth.
|
|
7
|
+
*/
|
|
8
|
+
export const SUBAGENT_TOOL_NAMES = new Set(['Task', 'Agent']);
|
|
9
|
+
export function isSubagentTool(toolName) {
|
|
10
|
+
return toolName != null && SUBAGENT_TOOL_NAMES.has(toolName);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=subagent-tools.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parseSessionKey } from '../utils/session-key.js';
|
|
2
|
+
export function buildSyntheticCtx({ api, sessionKey, syntheticText }) {
|
|
3
|
+
const { chatId, threadId } = parseSessionKey(sessionKey);
|
|
4
|
+
const threadOpts = threadId !== undefined ? { message_thread_id: threadId } : {};
|
|
5
|
+
// The `message` field mostly matters because `getSessionKeyFromCtx` reads
|
|
6
|
+
// `is_topic_message` + `message_thread_id` off it. We supply the minimum
|
|
7
|
+
// shape so threaded chats route scheduled posts back into the right topic.
|
|
8
|
+
const message = {
|
|
9
|
+
message_id: 0,
|
|
10
|
+
date: Math.floor(Date.now() / 1000),
|
|
11
|
+
text: syntheticText,
|
|
12
|
+
is_topic_message: threadId !== undefined,
|
|
13
|
+
message_thread_id: threadId,
|
|
14
|
+
chat: { id: chatId, type: 'private' },
|
|
15
|
+
from: { id: chatId, is_bot: false, first_name: 'scheduler' },
|
|
16
|
+
};
|
|
17
|
+
const ctx = {
|
|
18
|
+
api,
|
|
19
|
+
chat: { id: chatId, type: threadId !== undefined ? 'supergroup' : 'private' },
|
|
20
|
+
from: { id: chatId, is_bot: false, first_name: 'scheduler', username: 'scheduler' },
|
|
21
|
+
message,
|
|
22
|
+
callbackQuery: undefined,
|
|
23
|
+
me: undefined,
|
|
24
|
+
update: { update_id: 0, message },
|
|
25
|
+
async reply(text, opts = {}) {
|
|
26
|
+
return api.sendMessage(chatId, text, { ...threadOpts, ...opts });
|
|
27
|
+
},
|
|
28
|
+
async replyWithDocument(file, opts = {}) {
|
|
29
|
+
// Casts mirror Grammy's API which accepts the same union as InputFile.
|
|
30
|
+
return api.sendDocument(chatId, file, { ...threadOpts, ...opts });
|
|
31
|
+
},
|
|
32
|
+
async replyWithPhoto(file, opts = {}) {
|
|
33
|
+
return api.sendPhoto(chatId, file, { ...threadOpts, ...opts });
|
|
34
|
+
},
|
|
35
|
+
async replyWithVideo(file, opts = {}) {
|
|
36
|
+
return api.sendVideo(chatId, file, { ...threadOpts, ...opts });
|
|
37
|
+
},
|
|
38
|
+
async replyWithAudio(file, opts = {}) {
|
|
39
|
+
return api.sendAudio(chatId, file, { ...threadOpts, ...opts });
|
|
40
|
+
},
|
|
41
|
+
async replyWithVoice(file, opts = {}) {
|
|
42
|
+
return api.sendVoice(chatId, file, { ...threadOpts, ...opts });
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
// `as unknown as Context` is the contract: we promise the downstream
|
|
46
|
+
// pipeline only reads the methods/fields above. If a new code path starts
|
|
47
|
+
// touching different ctx surface, it'll surface immediately as a runtime
|
|
48
|
+
// error here rather than silently doing the wrong thing.
|
|
49
|
+
return ctx;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=synthetic-ctx.js.map
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrape Claude Code's `/tasks` overlay out of the rendered xterm buffer.
|
|
3
|
+
*
|
|
4
|
+
* `/tasks` (alias `/bashes`, "View and manage everything running in the
|
|
5
|
+
* background") is a `local-jsx` command: it draws an Ink overlay pinned to the
|
|
6
|
+
* bottom of the TUI and writes nothing to the session JSONL. It is the live
|
|
7
|
+
* process's own view of its background work, so it sees things our arm-time
|
|
8
|
+
* tracker cannot — shells claude backgrounded on its own, and anything that
|
|
9
|
+
* predates a bot restart.
|
|
10
|
+
*
|
|
11
|
+
* Two shapes, decided by claude, not by us. With several tasks it opens on the
|
|
12
|
+
* list (2.1.311 shown; up to 2.1.226 the rows read `sleep 500 (running)` with
|
|
13
|
+
* no bullet or status column):
|
|
14
|
+
*
|
|
15
|
+
* ────────────────────────────────────────────────────────────
|
|
16
|
+
* Background
|
|
17
|
+
* 3 active shells
|
|
18
|
+
*
|
|
19
|
+
* ❯ ● sleep 100 running
|
|
20
|
+
* ● sleep 150 running
|
|
21
|
+
* ● for i in $(seq 1 40); do echo "line $i";… running
|
|
22
|
+
*
|
|
23
|
+
* Earlier in this session (0)
|
|
24
|
+
*
|
|
25
|
+
* ↑/↓ to select · Enter to view · x to stop · Esc to close
|
|
26
|
+
*
|
|
27
|
+
* With exactly one it opens that task's detail instead, which Enter on a row
|
|
28
|
+
* opens too:
|
|
29
|
+
*
|
|
30
|
+
* Shell details
|
|
31
|
+
*
|
|
32
|
+
* Status: running
|
|
33
|
+
* Runtime: 22s
|
|
34
|
+
* Command: for i in $(seq 1 40); do echo "line $i"; sleep 2; done
|
|
35
|
+
*
|
|
36
|
+
* Output:
|
|
37
|
+
* ╭──────────────────────────────────────────────────────────╮
|
|
38
|
+
* │ line 4 │
|
|
39
|
+
* │ line 5 │
|
|
40
|
+
* ╰──────────────────────────────────────────────────────────╯
|
|
41
|
+
* Showing 9 lines
|
|
42
|
+
*
|
|
43
|
+
* ← to go back · Esc/Enter/Space to close · x to stop
|
|
44
|
+
*
|
|
45
|
+
* Anchor: the overlay sits under a full-width rule, and while it is open the
|
|
46
|
+
* input box (two rules around a `❯` row) is not drawn, so the lowest rule in
|
|
47
|
+
* the buffer is the overlay's — with everything above it being scrollback. Up
|
|
48
|
+
* to 2.1.226 that rule was `▔` (U+2594), a glyph nothing else used; 2.1.311
|
|
49
|
+
* draws it with the same `─` (U+2500) as the input box, so the body under the
|
|
50
|
+
* lowest rule has to identify itself: it opens with `Background` or a `…
|
|
51
|
+
* details` title. Returns null when no overlay is found, which callers
|
|
52
|
+
* surface as "couldn't read it" rather than guessing.
|
|
53
|
+
*/
|
|
54
|
+
/** The overlay's top rule. Full-width in practice; 10 is a safe floor. */
|
|
55
|
+
const OVERLAY_RULE_RE = /^(?:▔{10,}|─{10,})$/;
|
|
56
|
+
/**
|
|
57
|
+
* What the overlay's body opens with. `Background` is the list (and the idle
|
|
58
|
+
* view); `Shell details`, `Agent details`, … are a task. The status lines
|
|
59
|
+
* under a closed overlay's input box open with neither, which is what keeps
|
|
60
|
+
* them from being read as an overlay.
|
|
61
|
+
*/
|
|
62
|
+
const HEADING_RE = /^(?:Background|\S.* details)$/;
|
|
63
|
+
/**
|
|
64
|
+
* The trailing keyboard-hint line ("… Esc to close"). Useless over Telegram —
|
|
65
|
+
* there's no keyboard attached — so it gets dropped. Both shapes end in
|
|
66
|
+
* "to close" or carry on past it ("… Esc/Enter/Space to close · x to stop");
|
|
67
|
+
* the leading-glyph alternatives guard against a task whose own text happens
|
|
68
|
+
* to contain that phrase.
|
|
69
|
+
*/
|
|
70
|
+
const HINT_RE = /(?:↑\/↓|←|Esc|Enter)\s.*\bto close\b/;
|
|
71
|
+
/**
|
|
72
|
+
* Selection caret on the highlighted row; meaningless in a chat transcript.
|
|
73
|
+
* Replaced with its own width in spaces rather than deleted, so the selected
|
|
74
|
+
* row stays aligned with its unselected siblings.
|
|
75
|
+
*/
|
|
76
|
+
const CARET_RE = /^❯\s?/;
|
|
77
|
+
/** Strip the common leading indentation shared by every non-blank line. */
|
|
78
|
+
function dedent(lines) {
|
|
79
|
+
const indents = lines
|
|
80
|
+
.filter((l) => l.trim().length > 0)
|
|
81
|
+
.map((l) => l.length - l.trimStart().length);
|
|
82
|
+
const common = indents.length ? Math.min(...indents) : 0;
|
|
83
|
+
return lines.map((l) => (l.trim().length > 0 ? l.slice(common) : ''));
|
|
84
|
+
}
|
|
85
|
+
export function scrapeTasksOverlay(screenText) {
|
|
86
|
+
const lines = screenText.split('\n');
|
|
87
|
+
// The lowest rule, and only that one: the overlay is pinned to the bottom,
|
|
88
|
+
// and a rule higher up is the input box's or an earlier overlay's, still in
|
|
89
|
+
// scrollback. Reading past the lowest one would hand back stale data.
|
|
90
|
+
let ruleIndex = -1;
|
|
91
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
92
|
+
if (OVERLAY_RULE_RE.test(lines[i].trim())) {
|
|
93
|
+
ruleIndex = i;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (ruleIndex === -1)
|
|
98
|
+
return null;
|
|
99
|
+
let body = lines.slice(ruleIndex + 1);
|
|
100
|
+
// Drop the trailing hint line and any blank padding around it.
|
|
101
|
+
while (body.length > 0) {
|
|
102
|
+
const last = body[body.length - 1];
|
|
103
|
+
if (last.trim() === '' || HINT_RE.test(last)) {
|
|
104
|
+
body.pop();
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
body = dedent(body).map((l) => l.replace(CARET_RE, (m) => ' '.repeat(m.length)));
|
|
110
|
+
// Collapse runs of blank lines — the overlay pads generously for the TUI,
|
|
111
|
+
// which reads as dead space in a chat message.
|
|
112
|
+
const text = body
|
|
113
|
+
.join('\n')
|
|
114
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
115
|
+
.trim();
|
|
116
|
+
if (!text)
|
|
117
|
+
return null;
|
|
118
|
+
if (!HEADING_RE.test(text.split('\n', 1)[0].trim()))
|
|
119
|
+
return null;
|
|
120
|
+
// claude's own wording for the idle case. Matched loosely so a phrasing
|
|
121
|
+
// change degrades to "not empty" (we show the text) rather than a wrong
|
|
122
|
+
// "nothing running".
|
|
123
|
+
const empty = /\bno (?:tasks|shells|agents)\b.*\brunning\b/i.test(text);
|
|
124
|
+
return { text, empty };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A row: a `●` bullet, the label, and (2.1.311) two or more spaces before
|
|
128
|
+
* the status word. The `Earlier in this session (0)` section heading carries
|
|
129
|
+
* no bullet, so it isn't one.
|
|
130
|
+
*/
|
|
131
|
+
const ROW_RE = /^\s*●\s+(.+?)(?:\s{2,}(\S+))?\s*$/;
|
|
132
|
+
/**
|
|
133
|
+
* The list's rows, top to bottom. Cursor position `i` in the TUI is `i`
|
|
134
|
+
* presses of ↓ from the top, which is what makes the index worth having.
|
|
135
|
+
* Empty for a detail view, the idle view, or a layout without bullets.
|
|
136
|
+
*/
|
|
137
|
+
export function parseTaskRows(overlayText) {
|
|
138
|
+
const rows = [];
|
|
139
|
+
for (const line of overlayText.split('\n')) {
|
|
140
|
+
const m = ROW_RE.exec(line);
|
|
141
|
+
if (!m)
|
|
142
|
+
continue;
|
|
143
|
+
const raw = m[1].trim();
|
|
144
|
+
const truncated = /(?:…|\.\.\.)$/.test(raw);
|
|
145
|
+
rows.push({
|
|
146
|
+
label: truncated ? raw.replace(/(?:…|\.\.\.)$/, '').trimEnd() : raw,
|
|
147
|
+
status: m[2] ?? '',
|
|
148
|
+
truncated,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return rows;
|
|
152
|
+
}
|
|
153
|
+
const DETAIL_TITLE_RE = /^\S.* details$/;
|
|
154
|
+
const FIELD_RE = /^([A-Z][\w ]*):\s+(.*)$/;
|
|
155
|
+
const OUTPUT_HEADING_RE = /^Output:\s*$/;
|
|
156
|
+
/** The output box's top and bottom edges. */
|
|
157
|
+
const BOX_EDGE_RE = /^[╭╰]─*[╮╯]\s*$/;
|
|
158
|
+
/** A line inside the box: `│ text │`. */
|
|
159
|
+
const BOX_LINE_RE = /^│ ?(.*?)\s*│?\s*$/;
|
|
160
|
+
const NO_OUTPUT_RE = /^no output available$/i;
|
|
161
|
+
/**
|
|
162
|
+
* A task's detail view, or null when the overlay text is the list. The
|
|
163
|
+
* fields are kept as drawn rather than mapped to known names, so a field
|
|
164
|
+
* added in a later release shows up instead of vanishing.
|
|
165
|
+
*/
|
|
166
|
+
export function parseTaskDetail(overlayText) {
|
|
167
|
+
const lines = overlayText.split('\n');
|
|
168
|
+
const title = lines[0]?.trim() ?? '';
|
|
169
|
+
if (!DETAIL_TITLE_RE.test(title))
|
|
170
|
+
return null;
|
|
171
|
+
const fields = [];
|
|
172
|
+
const outputLines = [];
|
|
173
|
+
let note;
|
|
174
|
+
let inOutput = false;
|
|
175
|
+
let inBox = false;
|
|
176
|
+
for (const line of lines.slice(1)) {
|
|
177
|
+
if (!inOutput) {
|
|
178
|
+
if (OUTPUT_HEADING_RE.test(line.trim())) {
|
|
179
|
+
inOutput = true;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const m = FIELD_RE.exec(line.trim());
|
|
183
|
+
if (m)
|
|
184
|
+
fields.push({ label: m[1], value: m[2].trim() });
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const trimmed = line.trim();
|
|
188
|
+
if (BOX_EDGE_RE.test(trimmed)) {
|
|
189
|
+
inBox = !inBox;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (inBox) {
|
|
193
|
+
const m = BOX_LINE_RE.exec(trimmed);
|
|
194
|
+
outputLines.push(m ? m[1] : trimmed);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (trimmed === '')
|
|
198
|
+
continue;
|
|
199
|
+
if (NO_OUTPUT_RE.test(trimmed))
|
|
200
|
+
continue;
|
|
201
|
+
// Under the box: `Showing 9 lines`. Before any box: output drawn bare.
|
|
202
|
+
if (outputLines.length > 0)
|
|
203
|
+
note = trimmed;
|
|
204
|
+
else
|
|
205
|
+
outputLines.push(trimmed);
|
|
206
|
+
}
|
|
207
|
+
while (outputLines.length > 0 && outputLines[outputLines.length - 1].trim() === '') {
|
|
208
|
+
outputLines.pop();
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
title,
|
|
212
|
+
fields,
|
|
213
|
+
output: outputLines.length > 0 ? outputLines.join('\n') : null,
|
|
214
|
+
...(note !== undefined ? { note } : {}),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=tasks-overlay-scraper.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haiku's guess at which threads /threadcleanup can delete: for each, whether the
|
|
3
|
+
* work in it looks finished or has loose ends.
|
|
4
|
+
*
|
|
5
|
+
* One call for every thread at once, so a cleanup of thirty threads starts one
|
|
6
|
+
* claude, not thirty. All Haiku sees of a thread is what the chat history
|
|
7
|
+
* keeps: its topic, the last thing the user said and the end of the last
|
|
8
|
+
* reply. That's enough to tell "done, pushed" from "want me to go on?".
|
|
9
|
+
*
|
|
10
|
+
* The guess only decides which threads start ticked. The user reads the list
|
|
11
|
+
* and confirms, so a wrong guess costs a tap. Any failure (timeout, a reply
|
|
12
|
+
* out of format) gives no guess, and /threadcleanup says so.
|
|
13
|
+
*/
|
|
14
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
15
|
+
import { sideCallOptions } from './side-call-options.js';
|
|
16
|
+
const JUDGE_TIMEOUT_MS = 45_000;
|
|
17
|
+
const MAX_USER_CHARS = 300;
|
|
18
|
+
const MAX_REPLY_CHARS = 600;
|
|
19
|
+
const INSTRUCTIONS = 'Each numbered item below is a chat thread between a user and a coding agent: its topic, the user\'s last ' +
|
|
20
|
+
'message and the end of the agent\'s last reply. For each, decide whether the work looks finished (DONE) or ' +
|
|
21
|
+
'has loose ends the user may still want to come back to (OPEN): the agent asked a question or offered a next ' +
|
|
22
|
+
'step that wasn\'t taken up, work was left half done, something failed, or a plan was agreed but not carried out.\n' +
|
|
23
|
+
'When in doubt, answer OPEN.\n' +
|
|
24
|
+
'Output one line per item, nothing else, in the form "<number>: DONE" or "<number>: OPEN".\n\n';
|
|
25
|
+
function clip(text, max, fromEnd = false) {
|
|
26
|
+
const flat = (text ?? '').replace(/\s+/g, ' ').trim();
|
|
27
|
+
if (flat.length <= max)
|
|
28
|
+
return flat;
|
|
29
|
+
return fromEnd ? '…' + flat.slice(flat.length - max) : flat.slice(0, max) + '…';
|
|
30
|
+
}
|
|
31
|
+
export function buildJudgePrompt(threads) {
|
|
32
|
+
const items = threads.map((t, i) => [
|
|
33
|
+
`${i + 1}.`,
|
|
34
|
+
`Topic: ${clip(t.topic, 120) || '(none)'}`,
|
|
35
|
+
`User: ${clip(t.lastUserMessage, MAX_USER_CHARS) || '(nothing)'}`,
|
|
36
|
+
`Agent: ${clip(t.lastReply, MAX_REPLY_CHARS, true) || '(nothing)'}`,
|
|
37
|
+
].join('\n'));
|
|
38
|
+
return INSTRUCTIONS + items.join('\n\n');
|
|
39
|
+
}
|
|
40
|
+
/** The verdicts in a reply, by item; an item Haiku skipped stays undefined. */
|
|
41
|
+
export function parseVerdicts(reply, count) {
|
|
42
|
+
const verdicts = new Array(count).fill(undefined);
|
|
43
|
+
for (const line of reply.split('\n')) {
|
|
44
|
+
const m = /^\s*(\d+)\s*[:.)-]\s*\**\s*(DONE|OPEN)\b/i.exec(line);
|
|
45
|
+
if (!m)
|
|
46
|
+
continue;
|
|
47
|
+
const index = Number(m[1]) - 1;
|
|
48
|
+
if (index >= 0 && index < count)
|
|
49
|
+
verdicts[index] = m[2].toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
return verdicts;
|
|
52
|
+
}
|
|
53
|
+
/** A verdict per thread, or undefined when Haiku gave none at all. */
|
|
54
|
+
export async function judgeThreads(threads) {
|
|
55
|
+
if (threads.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const timer = setTimeout(() => controller.abort(), JUDGE_TIMEOUT_MS);
|
|
59
|
+
try {
|
|
60
|
+
const response = query({
|
|
61
|
+
prompt: buildJudgePrompt(threads),
|
|
62
|
+
options: sideCallOptions('You sort chat threads into finished and unfinished.', controller),
|
|
63
|
+
});
|
|
64
|
+
let collected = '';
|
|
65
|
+
for await (const message of response) {
|
|
66
|
+
if (message.type === 'assistant') {
|
|
67
|
+
for (const block of message.message.content) {
|
|
68
|
+
if (block.type === 'text')
|
|
69
|
+
collected += block.text;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (message.type === 'result')
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
const verdicts = parseVerdicts(collected, threads.length);
|
|
76
|
+
return verdicts.some((v) => v !== undefined) ? verdicts : undefined;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (!controller.signal.aborted) {
|
|
80
|
+
console.debug('[ThreadJudge] Haiku side-call failed:', err instanceof Error ? err.message : err);
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=thread-judge-haiku.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrape Claude Code's spinner "Tip:" line from the rendered xterm buffer.
|
|
3
|
+
*
|
|
4
|
+
* While a turn is running, Claude Code draws a status block at the bottom of
|
|
5
|
+
* the TUI that occasionally carries a contextual tip, e.g.:
|
|
6
|
+
*
|
|
7
|
+
* ✶ Percolating… (29s)
|
|
8
|
+
* ⎿ Tip: Working with HTML/CSS? Install the frontend-design plugin:
|
|
9
|
+
* /plugin install frontend-design@claude-plugins-official
|
|
10
|
+
*
|
|
11
|
+
* These tips are bundled into the CLI (with client-side relevance + per-session
|
|
12
|
+
* cooldown logic) and exist only in the live render. We already feed that
|
|
13
|
+
* render into an @xterm/headless buffer, so we can pull the tip back out and
|
|
14
|
+
* mirror it in the Telegram status indicator, exactly as Claude Code shows it.
|
|
15
|
+
*
|
|
16
|
+
* Detection: the spinner tip is rendered with a `⎿` tree connector preceding
|
|
17
|
+
* `Tip:`. That connector is the discriminator that distinguishes it from the
|
|
18
|
+
* startup "Update available" banner tip (which has no connector and lives in
|
|
19
|
+
* scrollback, not the live bottom rows). The tip can wrap onto a continuation
|
|
20
|
+
* line (the `/plugin install …` command), indented to align under `Tip: `.
|
|
21
|
+
*
|
|
22
|
+
* We scan the buffer bottom-up and return the lowest (most recent) match. The
|
|
23
|
+
* `⎿` connector is what makes this safe: the spinner block is redrawn in place
|
|
24
|
+
* and overwritten by committed output rather than scrolled into history, so a
|
|
25
|
+
* connector-prefixed tip only ever exists in the live block — there's no stale
|
|
26
|
+
* copy in scrollback to mismatch. (A fixed bottom-window scan can't be used: in
|
|
27
|
+
* an early session the live block sits near the top with empty viewport rows
|
|
28
|
+
* below it, pushing it outside any fixed window.)
|
|
29
|
+
*/
|
|
30
|
+
// Tip line signature: a `⎿` tree connector followed by `Tip:`.
|
|
31
|
+
const TIP_RE = /⎿\s*Tip:\s*(.+)$/u;
|
|
32
|
+
const MAX_TIP_LEN = 220;
|
|
33
|
+
function isContinuation(line) {
|
|
34
|
+
if (!line)
|
|
35
|
+
return false;
|
|
36
|
+
const trimmed = line.trim();
|
|
37
|
+
if (!trimmed)
|
|
38
|
+
return false;
|
|
39
|
+
// Stop at TUI chrome: input-box borders/body, prompt glyph, another tree
|
|
40
|
+
// connector, separators, or the spinner status line itself.
|
|
41
|
+
if (/^[╭╰╮╯│─━═⎿●]/u.test(trimmed))
|
|
42
|
+
return false;
|
|
43
|
+
if (trimmed.includes('❯'))
|
|
44
|
+
return false;
|
|
45
|
+
// A continuation is indented under "Tip: " — bail if the raw line isn't.
|
|
46
|
+
return /^\s/u.test(line);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return the spinner tip currently rendered (tip text plus any wrapped
|
|
50
|
+
* continuation, joined with a space), or null when none is on screen.
|
|
51
|
+
*/
|
|
52
|
+
export function scrapeTip(xterm) {
|
|
53
|
+
const buf = xterm.buffer.active;
|
|
54
|
+
for (let i = buf.length - 1; i >= 0; i--) {
|
|
55
|
+
const line = buf.getLine(i);
|
|
56
|
+
if (!line)
|
|
57
|
+
continue;
|
|
58
|
+
const raw = line.translateToString(true);
|
|
59
|
+
const m = TIP_RE.exec(raw);
|
|
60
|
+
if (!m)
|
|
61
|
+
continue;
|
|
62
|
+
let tip = m[1].trim();
|
|
63
|
+
// Pull in wrapped continuation lines (e.g. the `/plugin install …` command).
|
|
64
|
+
for (let j = i + 1; j < buf.length && j <= i + 3; j++) {
|
|
65
|
+
const contRaw = buf.getLine(j)?.translateToString(true) ?? '';
|
|
66
|
+
if (!isContinuation(contRaw))
|
|
67
|
+
break;
|
|
68
|
+
tip += ' ' + contRaw.trim();
|
|
69
|
+
}
|
|
70
|
+
tip = tip.replace(/\s+/gu, ' ').trim();
|
|
71
|
+
if (!tip)
|
|
72
|
+
return null;
|
|
73
|
+
return tip.length > MAX_TIP_LEN ? tip.slice(0, MAX_TIP_LEN - 1).trimEnd() + '…' : tip;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=tip-scraper.js.map
|