@wu529778790/open-im 1.10.9-beta.8 → 1.10.9-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,11 +9,6 @@
|
|
|
9
9
|
* 认证:ANTHROPIC_API_KEY 或 CLAUDE_CODE_OAUTH_TOKEN
|
|
10
10
|
*/
|
|
11
11
|
import type { ToolAdapter, RunCallbacks, RunOptions, RunHandle } from './tool-adapter.interface.js';
|
|
12
|
-
/**
|
|
13
|
-
* 标记某个 workDir 下的用户显式执行了 /new,下次创建会话时跳过 auto-resume。
|
|
14
|
-
* 由命令处理器在 /new 时调用。
|
|
15
|
-
*/
|
|
16
|
-
export declare function markSkipAutoResume(workDir: string): void;
|
|
17
12
|
interface ClaudeSessionMeta {
|
|
18
13
|
sessionId: string;
|
|
19
14
|
mtime: number;
|
|
@@ -97,14 +97,6 @@ function isCliSessionActive(sessionId, sessionFilePath) {
|
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
/**
|
|
101
|
-
* 标记某个 workDir 下的用户显式执行了 /new,下次创建会话时跳过 auto-resume。
|
|
102
|
-
* 由命令处理器在 /new 时调用。
|
|
103
|
-
*/
|
|
104
|
-
export function markSkipAutoResume(workDir) {
|
|
105
|
-
skipAutoResumeFor.add(workDir);
|
|
106
|
-
log.info(`Marked skip auto-resume for workDir: ${workDir}`);
|
|
107
|
-
}
|
|
108
100
|
/**
|
|
109
101
|
* 扫描 ~/.claude/projects/<encoded-path>/ 找到最新的 CLI session。
|
|
110
102
|
* 只返回 JSONL 文件(排除子目录如 subagents/),按修改时间倒序。
|
|
@@ -187,9 +179,6 @@ function validateSessionFile(filePath, expectedSessionId) {
|
|
|
187
179
|
// 存储所有活跃的 SDKSession 对象,key 为 sessionId
|
|
188
180
|
// 使用 Map 而不是 Set,因为我们需要通过 sessionId 获取 session
|
|
189
181
|
const activeSessions = new Map();
|
|
190
|
-
// 用户显式执行 /new 后标记跳过 auto-resume,避免立即接回旧 CLI session
|
|
191
|
-
// key 格式: `${workDir}\0${sessionIdPrefix}`(用 workDir 区分不同项目目录)
|
|
192
|
-
const skipAutoResumeFor = new Set();
|
|
193
182
|
// 记录每个 session 创建/恢复时的 workDir,防止跨 workDir 复用已固定 cwd 的子进程
|
|
194
183
|
const sessionWorkDirs = new Map();
|
|
195
184
|
// 存储正在进行的流式迭代器,用于中断
|
|
@@ -390,38 +379,31 @@ async function getOrCreateSession(sessionId, workDir, model, permissionMode, onS
|
|
|
390
379
|
// 没有指定 sessionId 时,尝试自动恢复 Claude Code CLI 的最新 session
|
|
391
380
|
// 实现手机/电脑无缝切换:同目录下默认共享同一个对话
|
|
392
381
|
if (!sessionId) {
|
|
393
|
-
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
session = unstable_v2_resumeSession(latest.sessionId, sessionOptions);
|
|
411
|
-
activeSessions.set(latest.sessionId, session);
|
|
412
|
-
sessionWorkDirs.set(latest.sessionId, workDir);
|
|
413
|
-
sessionLastUsed.set(latest.sessionId, Date.now());
|
|
414
|
-
log.info(`Successfully auto-resumed CLI session: ${latest.sessionId}`);
|
|
415
|
-
return { session, sessionId: latest.sessionId };
|
|
416
|
-
}
|
|
417
|
-
catch (err) {
|
|
418
|
-
log.warn(`Failed to auto-resume CLI session ${latest.sessionId}, skipping auto-resume: ${err}`);
|
|
419
|
-
}
|
|
382
|
+
const latest = findLatestClaudeSession(workDir);
|
|
383
|
+
if (latest) {
|
|
384
|
+
// 安全检查:如果 CLI 正在使用该 session(文件 30 秒内有写入),不能接管
|
|
385
|
+
if (isCliSessionActive(latest.sessionId, latest.filePath)) {
|
|
386
|
+
log.info(`CLI is actively using session ${latest.sessionId}, skipping auto-resume`);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// 验证文件内容一致性
|
|
390
|
+
if (validateSessionFile(latest.filePath, latest.sessionId)) {
|
|
391
|
+
try {
|
|
392
|
+
log.info(`Auto-resuming latest CLI session: ${latest.sessionId}`);
|
|
393
|
+
session = unstable_v2_resumeSession(latest.sessionId, sessionOptions);
|
|
394
|
+
activeSessions.set(latest.sessionId, session);
|
|
395
|
+
sessionWorkDirs.set(latest.sessionId, workDir);
|
|
396
|
+
sessionLastUsed.set(latest.sessionId, Date.now());
|
|
397
|
+
log.info(`Successfully auto-resumed CLI session: ${latest.sessionId}`);
|
|
398
|
+
return { session, sessionId: latest.sessionId };
|
|
420
399
|
}
|
|
421
|
-
|
|
422
|
-
log.warn(`
|
|
400
|
+
catch (err) {
|
|
401
|
+
log.warn(`Failed to auto-resume CLI session ${latest.sessionId}, skipping auto-resume: ${err}`);
|
|
423
402
|
}
|
|
424
403
|
}
|
|
404
|
+
else {
|
|
405
|
+
log.warn(`Session file validation failed for ${latest.sessionId}, skipping`);
|
|
406
|
+
}
|
|
425
407
|
}
|
|
426
408
|
}
|
|
427
409
|
}
|
package/dist/commands/handler.js
CHANGED
|
@@ -2,7 +2,6 @@ import { resolvePlatformAiCommand } from '../config.js';
|
|
|
2
2
|
import { escapePathForMarkdown } from '../shared/utils.js';
|
|
3
3
|
import { TERMINAL_ONLY_COMMANDS } from '../constants.js';
|
|
4
4
|
import { createLogger } from '../logger.js';
|
|
5
|
-
import { markSkipAutoResume } from '../adapters/claude-sdk-adapter.js';
|
|
6
5
|
const log = createLogger('Commands');
|
|
7
6
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
7
|
import { execFile } from 'node:child_process';
|
|
@@ -136,8 +135,6 @@ export class CommandHandler {
|
|
|
136
135
|
}
|
|
137
136
|
async handleNew(chatId, userId) {
|
|
138
137
|
this.deps.requestQueue.cancelUser(userId);
|
|
139
|
-
const workDir = this.deps.sessionManager.getWorkDir(userId);
|
|
140
|
-
markSkipAutoResume(workDir);
|
|
141
138
|
const ok = this.deps.sessionManager.newSession(userId);
|
|
142
139
|
await this.replySender().sendTextReply(chatId, ok
|
|
143
140
|
? '✅ AI 会话已重置,下一条消息将使用全新上下文。'
|