Skip to content

Commit 361f2b1

Browse files
committed
fix(cli): 验证 --resume 参数中的会话ID有效性
- 在启动 TUI 之前校验传入的 resumeSessionId 是否在本地会话索引中存在 - 读取用户主目录下的 sessions-index.json 文件进行会话ID验证 - 未找到匹配会话时输出错误信息并退出进程 - 在 App 组件中移除对会话ID重复验证的注释补充说明 - 确保 resumeSessionId 已经校验通过后才调用 handleSelectSession
1 parent ad11d9a commit 361f2b1

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/cli/src/cli.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from "react";
22
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";
47
import { checkForNpmUpdate, promptForPendingUpdate, type PackageInfo } from "./common/update-check";
58
import { AppContainer } from "./ui";
69
import { extractInitialPrompt, extractResumeSessionId } from "./cli-args";
@@ -65,6 +68,23 @@ const resumeSessionId = extractResumeSessionId(args);
6568
const projectRoot = process.cwd();
6669
configureWindowsShell();
6770

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+
6888
if (!process.stdin.isTTY) {
6989
process.stderr.write("deepcode requires an interactive terminal (TTY). " + "Re-run from a real terminal session.\n");
7090
process.exit(1);

packages/cli/src/ui/views/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
519519
refreshSessionsList();
520520
navigateToSubView("session-list");
521521
} else {
522+
// Session ID already validated in cli.tsx — guaranteed to exist
522523
handleSelectSession(resumeSessionId);
523524
}
524525
}, [handleSelectSession, navigateToSubView, refreshSessionsList, resumeSessionId]);

0 commit comments

Comments
 (0)