refactor(telegram-pairing): remove TTL expiry from pairing codes

Pairing codes no longer expire on a timer. They are consumed on match
or invalidated by wrong guesses. Removes ttlMs/expiresAt/deadline from
the pairing primitive, setup CLI, and tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gabi-simons
2026-04-16 10:54:48 +00:00
parent 39d2af9981
commit a1a324097e
3 changed files with 57 additions and 82 deletions

View File

@@ -21,14 +21,8 @@ import {
} from '../src/channels/telegram-pairing.js';
import { emitStatus } from './status.js';
interface Args {
intent: PairingIntent;
ttlMs: number;
}
function parseArgs(args: string[]): Args {
function parseArgs(args: string[]): PairingIntent {
let intent: PairingIntent = 'main';
let ttlMs = 5 * 60 * 1000;
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case '--intent': {
@@ -44,12 +38,9 @@ function parseArgs(args: string[]): Args {
}
break;
}
case '--ttl-ms':
ttlMs = parseInt(args[++i] || '300000', 10);
break;
}
}
return { intent, ttlMs };
return intent;
}
function intentToString(intent: PairingIntent): string {
@@ -58,7 +49,7 @@ function intentToString(intent: PairingIntent): string {
}
export async function run(args: string[]): Promise<void> {
const { intent, ttlMs } = parseArgs(args);
const intent = parseArgs(args);
// Pairing reads/writes its JSON store under DATA_DIR; the DB isn't strictly
// required for the pairing primitive itself, but the inbound interceptor
@@ -68,11 +59,10 @@ export async function run(args: string[]): Promise<void> {
runMigrations(db);
const MAX_REGENERATIONS = 5;
let record = await createPairing(intent, { ttlMs });
let record = await createPairing(intent);
emitStatus('PAIR_TELEGRAM_ISSUED', {
CODE: record.code,
INTENT: intentToString(intent),
EXPIRES_AT: record.expiresAt,
INSTRUCTIONS: `Send "${record.code}" from the Telegram chat you want to register (or "@<botname> ${record.code}" in a group with privacy on).`,
REMINDER_TO_ASSISTANT: `Your next user-visible message MUST include this CODE in plain text — the bash tool output this block is in gets collapsed in the UI.`,
});
@@ -80,7 +70,6 @@ export async function run(args: string[]): Promise<void> {
for (let regen = 0; regen <= MAX_REGENERATIONS; regen++) {
try {
const consumed = await waitForPairing(record.code, {
timeoutMs: ttlMs,
onAttempt: (a) => {
emitStatus('PAIR_TELEGRAM_ATTEMPT', {
EXPECTED_CODE: record.code,
@@ -105,11 +94,10 @@ export async function run(args: string[]): Promise<void> {
const message = err instanceof Error ? err.message : String(err);
const invalidated = /invalidated by wrong code/.test(message);
if (invalidated && regen < MAX_REGENERATIONS) {
record = await createPairing(intent, { ttlMs });
record = await createPairing(intent);
emitStatus('PAIR_TELEGRAM_NEW_CODE', {
CODE: record.code,
INTENT: intentToString(intent),
EXPIRES_AT: record.expiresAt,
REASON: 'previous code invalidated by wrong attempt',
REGENERATIONS_LEFT: MAX_REGENERATIONS - regen - 1,
INSTRUCTIONS: `Send "${record.code}" from the Telegram chat you want to register.`,