@wu529778790/open-im 1.11.3 → 1.11.4-beta.1

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.
@@ -378,9 +378,9 @@ export class ClaudeSDKAdapter {
378
378
  let actualSessionId;
379
379
  let hadSessionInvalid = false;
380
380
  try {
381
- // 先尝试自动恢复 CLI 的最新 session(如果用户没有指定 sessionId)
381
+ // 先尝试自动恢复 CLI 的最新 session(如果用户没有指定 sessionId,且不是 /new 后的新 session
382
382
  let resumeId = sessionId;
383
- if (!resumeId) {
383
+ if (!resumeId && !options?.skipAutoResume) {
384
384
  const latest = await findLatestClaudeSession(workDir);
385
385
  if (latest) {
386
386
  const cliActive = isCliSessionActive(latest.sessionId, latest.filePath);
@@ -34,6 +34,8 @@ export interface RunOptions {
34
34
  fallbackModel?: string;
35
35
  /** 禁用的工具列表 */
36
36
  disallowedTools?: string[];
37
+ /** /new 后跳过自动恢复 CLI session */
38
+ skipAutoResume?: boolean;
37
39
  }
38
40
  export interface RunHandle {
39
41
  abort: () => void;
package/dist/index.js CHANGED
@@ -209,17 +209,9 @@ function buildNotification(opts) {
209
209
  return lines.join("\n\n");
210
210
  }
211
211
  function buildStartupMessage(platform, appVersion, aiCommand, defaultWorkDir, sessionManager) {
212
- let sessionDir;
213
- // Telegram 私聊、企业微信当前实现里,活跃 chatId 可直接对应到 session userId。
214
- if (platform === "telegram" || platform === "wework") {
215
- const activeChatId = getActiveChatId(platform);
216
- if (activeChatId) {
217
- sessionDir = sessionManager.getWorkDir(activeChatId);
218
- }
219
- }
220
212
  const platformName = PLATFORM_DISPLAY_NAMES[platform] ?? platform;
221
213
  const toolName = getAIToolDisplayName(aiCommand);
222
- const dir = escapePathForMarkdown(sessionDir || defaultWorkDir);
214
+ const dir = escapePathForMarkdown(sessionManager.getMostRecentWorkDir());
223
215
  return buildNotification({
224
216
  emoji: "✅",
225
217
  title: `open-im v${appVersion} 已就绪`,
@@ -17,6 +17,16 @@ export declare class SessionManager {
17
17
  getSessionIdForThread(_userId: string, _threadId: string, _toolId: ToolId): string | undefined;
18
18
  setSessionIdForThread(userId: string, threadId: string, toolId: ToolId, sessionId: string): void;
19
19
  getWorkDir(userId: string): string;
20
+ /**
21
+ * 检查 session 是否是 /new 后的新 session
22
+ * 如果是,不应该自动恢复 CLI session
23
+ */
24
+ isFreshSession(userId: string): boolean;
25
+ /**
26
+ * 获取最近活跃的 session 的工作目录
27
+ * 如果没有 session,返回默认工作目录
28
+ */
29
+ getMostRecentWorkDir(): string;
20
30
  hasUserSession(userId: string): boolean;
21
31
  getConvId(userId: string): string;
22
32
  setWorkDir(userId: string, workDir: string): Promise<{
@@ -84,7 +84,37 @@ export class SessionManager {
84
84
  this.save();
85
85
  }
86
86
  getWorkDir(userId) {
87
- return this.sessions.get(userId)?.workDir ?? this.defaultWorkDir;
87
+ const s = this.sessions.get(userId);
88
+ if (s) {
89
+ s.lastActiveAt = Date.now();
90
+ // 首次访问后清除 freshSession 标记(允许后续消息恢复 CLI session)
91
+ if (s.freshSession)
92
+ s.freshSession = false;
93
+ return s.workDir;
94
+ }
95
+ return this.defaultWorkDir;
96
+ }
97
+ /**
98
+ * 检查 session 是否是 /new 后的新 session
99
+ * 如果是,不应该自动恢复 CLI session
100
+ */
101
+ isFreshSession(userId) {
102
+ return this.sessions.get(userId)?.freshSession === true;
103
+ }
104
+ /**
105
+ * 获取最近活跃的 session 的工作目录
106
+ * 如果没有 session,返回默认工作目录
107
+ */
108
+ getMostRecentWorkDir() {
109
+ let mostRecent;
110
+ let latestTime = 0;
111
+ for (const [, session] of this.sessions) {
112
+ if (session.lastActiveAt && session.lastActiveAt > latestTime) {
113
+ latestTime = session.lastActiveAt;
114
+ mostRecent = session.workDir;
115
+ }
116
+ }
117
+ return mostRecent ?? this.defaultWorkDir;
88
118
  }
89
119
  hasUserSession(userId) {
90
120
  return this.sessions.has(userId);
@@ -138,6 +168,7 @@ export class SessionManager {
138
168
  s.sessionIds = {};
139
169
  s.activeConvId = randomBytes(4).toString('hex');
140
170
  s.totalTurns = 0;
171
+ s.freshSession = true; // 标记为新 session,阻止自动恢复 CLI session
141
172
  this.flushSync();
142
173
  log.info(`New session for user ${userId}: oldConvId=${oldConvId}, oldSessionIds=${JSON.stringify(oldSessionIds)}, newConvId=${s.activeConvId}, sessionIds={}`);
143
174
  return true;
@@ -294,6 +294,8 @@ export function runAITask(deps, ctx, prompt, toolAdapter, platformAdapter) {
294
294
  chatId: ctx.chatId,
295
295
  // 默认跳过权限确认,保持全自动执行(可通过 config 或环境变量关闭)
296
296
  skipPermissions: config.skipPermissions ?? true,
297
+ // /new 后跳过自动恢复 CLI session
298
+ skipAutoResume: sessionManager.isFreshSession(ctx.userId),
297
299
  ...(aiCommand === 'codex' && config.codexProxy ? { proxy: config.codexProxy } : {}),
298
300
  });
299
301
  return activeHandle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.11.3",
3
+ "version": "1.11.4-beta.1",
4
4
  "description": "Your AI coding assistant, in every chat app. Multi-platform IM bridge for Claude Code, Codex, and CodeBuddy.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",