The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | /** Adapter and client match these dialog strings; reword them only here. */ |
| 2 | export const CLAUDE_RESUME_COMPACTION_NEVER_ANSWER = "Don't ask again"; |
| 3 | export const CLAUDE_RESUME_COMPACTION_COMPACT_ANSWER = "Compact and continue"; |
| 4 | |
| 5 | export function formatClaudeResumeCompactionQuestion(input: { |
| 6 | readonly ageMinutes: number; |
| 7 | readonly estimatedTokens: number; |
| 8 | }): string { |
| 9 | const ageLabel = |
| 10 | input.ageMinutes >= 60 |
| 11 | ? `${Math.floor(input.ageMinutes / 60)}h ${input.ageMinutes % 60}m` |
| 12 | : `${input.ageMinutes}m`; |
| 13 | return `This session is ${ageLabel} old and uses ${input.estimatedTokens.toLocaleString("en-US")} tokens. Compact it before continuing?`; |
| 14 | } |
| 15 | |
| 16 | const CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN = |
| 17 | /^This session is (\d+h \d+m|\d+m) old and uses \d{1,3}(?:,\d{3})* tokens\. Compact it before continuing\?$/u; |
| 18 | |
| 19 | export function isClaudeResumeCompactionQuestion(question: string): boolean { |
| 20 | return CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN.test(question); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * The session age from an answered resume question whose answer was to compact, or null. Answers |
| 25 | * are keyed by question id, and the id may itself be the question text. |
| 26 | */ |
| 27 | export function claudeResumeCompactionAge(questionAnswer: { |
| 28 | readonly questionTextById?: Readonly<Record<string, string>> | undefined; |
| 29 | readonly answers: Readonly<Record<string, unknown>>; |
| 30 | }): string | null { |
| 31 | for (const [id, answer] of Object.entries(questionAnswer.answers)) { |
| 32 | const age = CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN.exec( |
| 33 | questionAnswer.questionTextById?.[id] ?? id, |
| 34 | )?.[1]; |
| 35 | const chosen = Array.isArray(answer) ? answer : [answer]; |
| 36 | if (age !== undefined && chosen.includes(CLAUDE_RESUME_COMPACTION_COMPACT_ANSWER)) return age; |
| 37 | } |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Context size below which T3 does not suggest or run a Claude compaction: |
| 43 | * the stale-thread Compact chip and idle compaction. Matches Claude Code's |
| 44 | * idleCompaction default of 200K. |
| 45 | */ |
| 46 | export const COMPACTION_SUGGESTION_MIN_TOKENS = 200_000; |