|
1 | 1 | import React from "react"; |
2 | 2 | import { render } from "ink"; |
3 | | -import { setShellIfWindows } from "@vegamo/deepcode-core"; |
| 3 | +import { readFileSync, existsSync } from "node:fs"; |
| 4 | +import { join } from "node:path"; |
| 5 | +import { homedir } from "node:os"; |
| 6 | +import { setShellIfWindows, getProjectCode } from "@vegamo/deepcode-core"; |
4 | 7 | import { checkForNpmUpdate, promptForPendingUpdate, type PackageInfo } from "./common/update-check"; |
5 | 8 | import { AppContainer } from "./ui"; |
6 | 9 | import { extractInitialPrompt, extractResumeSessionId } from "./cli-args"; |
@@ -65,6 +68,23 @@ const resumeSessionId = extractResumeSessionId(args); |
65 | 68 | const projectRoot = process.cwd(); |
66 | 69 | configureWindowsShell(); |
67 | 70 |
|
| 71 | +// Validate --resume <sessionId> before entering TUI |
| 72 | +if (typeof resumeSessionId === "string") { |
| 73 | + const projectCode = getProjectCode(projectRoot); |
| 74 | + const indexPath = join(homedir(), ".deepcode", "projects", projectCode, "sessions-index.json"); |
| 75 | + try { |
| 76 | + const index = JSON.parse(readFileSync(indexPath, "utf-8")); |
| 77 | + const found = Array.isArray(index?.entries) && index.entries.some((e: { id: string }) => e.id === resumeSessionId); |
| 78 | + if (!found) { |
| 79 | + process.stderr.write(`No saved session found with ID "${resumeSessionId}".\n`); |
| 80 | + process.exit(1); |
| 81 | + } |
| 82 | + } catch { |
| 83 | + process.stderr.write(`No saved session found with ID "${resumeSessionId}".\n`); |
| 84 | + process.exit(1); |
| 85 | + } |
| 86 | +} |
| 87 | + |
68 | 88 | if (!process.stdin.isTTY) { |
69 | 89 | process.stderr.write("deepcode requires an interactive terminal (TTY). " + "Re-run from a real terminal session.\n"); |
70 | 90 | process.exit(1); |
|
0 commit comments