Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
One-time setup that gathers your project's design context and saves it to CLAUDE.md for future sessions.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/live-resume.mjs
1#!/usr/bin/env node2/**3* Recover the next agent action from the durable live-session journal.4*/56import { createLiveSessionStore } from './live/session-store.mjs';78function manualApplyReplyCommand(eventOrId = 'EVENT_ID') {9const id = typeof eventOrId === 'string' ? eventOrId : eventOrId?.id || 'EVENT_ID';10return `live-poll.mjs --reply ${id} done --data '<json>'`;11}1213export function manualApplyResumeHint(event = {}) {14const summary = event.manualApplySummary || summarizeManualApplyEvent(event);15const parts = [];16if (summary.pageUrl) parts.push(`page ${summary.pageUrl}`);17if (summary.chunk) parts.push(`chunk ${summary.chunk.index}/${summary.chunk.total}`);18if (Number.isFinite(summary.opCount)) parts.push(`${summary.opCount} op(s)`);19if (Number.isFinite(summary.entryCount)) parts.push(`${summary.entryCount} entr${summary.entryCount === 1 ? 'y' : 'ies'}`);20if (summary.files?.length) parts.push(`likely files: ${summary.files.join(', ')}`);21const scope = parts.length ? ` (${parts.join(', ')})` : '';22return `Manual Apply pending${scope}. If you have not already leased it, run live-poll.mjs. Apply the source edits from the manual_edit_apply batch, then reply with ${manualApplyReplyCommand(event.id)}. Polling only leases this work item; it does not commit source edits. Do not run live-commit-manual-edits.mjs for this leased event. Do not poll again before replying.`;23}2425function summarizeManualApplyEvent(event = {}) {26const entries = Array.isArray(event.batch?.entries) ? event.batch.entries : [];27const opCount = entries.reduce((sum, entry) => sum + (Array.isArray(entry.ops) ? entry.ops.length : 0), 0);28return {29pageUrl: event.pageUrl || null,30chunk: event.chunk || null,31entryCount: entries.length,32opCount,33files: collectManualApplyFiles(event.batch),34};35}3637function collectManualApplyFiles(batch) {38const files = [];39for (const entry of batch?.entries || []) {40for (const op of entry.ops || []) files.push(op.sourceHint?.file);41}42for (const candidate of batch?.candidates || []) {43files.push(candidate.sourceHint?.relativeFile, candidate.sourceHint?.file);44for (const item of candidate.textMatches || []) files.push(item.file);45for (const item of candidate.objectKeyMatches || []) files.push(item.file);46for (const item of candidate.locatorMatches || []) files.push(item.file);47for (const item of candidate.contextTextMatches || []) files.push(item.file);48}49return [...new Set(files.filter((file) => typeof file === 'string' && file.length > 0))].sort();50}5152function parseArgs(argv) {53const out = { id: null };54for (let i = 0; i < argv.length; i++) {55const arg = argv[i];56if (arg === '--id') out.id = argv[++i];57else if (arg.startsWith('--id=')) out.id = arg.slice('--id='.length);58else if (arg === '--help' || arg === '-h') out.help = true;59}60return out;61}6263export async function resumeCli() {64const args = parseArgs(process.argv.slice(2));65if (args.help) {66console.log(`Usage: node live-resume.mjs [--id SESSION_ID]\n\nPrint the active durable session checkpoint and the next safe agent action.`);67return;68}6970const store = createLiveSessionStore({ cwd: process.cwd(), sessionId: args.id || undefined });71const snapshot = args.id ? store.getSnapshot(args.id) : store.listActiveSessions()[0] || null;72if (!snapshot) {73console.log(JSON.stringify({ active: false, nextAction: 'No active durable live session found.' }, null, 2));74return;75}7677const pending = snapshot.pendingEvent || null;78const nextAction = pending79? pending.type === 'manual_edit_apply'80? manualApplyResumeHint(pending)81: `Run live-poll.mjs, handle ${pending.type} ${pending.id}, then acknowledge with live-poll.mjs --reply ${pending.id} done.`82: snapshot.phase === 'carbonize_required'83? `Finish carbonize cleanup${snapshot.sourceFile ? ` in ${snapshot.sourceFile}` : ''}, then run live-complete.mjs --id ${snapshot.id}.`84: snapshot.phase === 'accept_requested'85? `Run live-complete.mjs --id ${snapshot.id} after verifying the accepted variant is written.`86: `Inspect ${snapshot.id}; no pending agent event is currently queued.`;8788console.log(JSON.stringify({ active: true, snapshot, pendingEvent: pending, nextAction }, null, 2));89}9091const _running = process.argv[1];92if (_running?.endsWith('live-resume.mjs') || _running?.endsWith('live-resume.mjs/')) {93resumeCli();94}95