chatccc 0.2.2 → 0.2.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/cards.ts CHANGED
@@ -126,17 +126,24 @@ export function buildCdContent(
126
126
  dirPath: string,
127
127
  entries: { name: string; isDir: boolean }[],
128
128
  isUpdate: boolean,
129
+ currentCwd?: string,
129
130
  maxFiles = 100
130
131
  ): string {
131
132
  const display = entries.slice(0, maxFiles);
132
133
  const overflow = entries.length > maxFiles ? `\n...(共 ${entries.length} 个条目,仅显示前 ${maxFiles} 个)` : "";
133
134
  const listing = display.map(e => e.isDir ? `📁 ${e.name}/` : `📄 ${e.name}`).join("\n");
134
135
 
136
+ const currentLine = currentCwd
137
+ ? `**当前会话工作路径:** \`${currentCwd}\``
138
+ : "";
139
+
135
140
  const statusLine = isUpdate
136
- ? `**新会话工作路径已切换至:** \`${dirPath}\``
141
+ ? `**新会话默认工作路径(已切换):** \`${dirPath}\``
137
142
  : `**新会话默认工作路径:** \`${dirPath}\``;
138
143
 
139
- return [
144
+ const lines: string[] = [];
145
+ if (currentLine) lines.push(currentLine, "");
146
+ lines.push(
140
147
  statusLine,
141
148
  ``,
142
149
  `此路径持久化在配置文件中,仅影响**新建会话**的工作路径。`,
@@ -145,7 +152,9 @@ export function buildCdContent(
145
152
  `**目录内容** (最多 ${maxFiles} 个):`,
146
153
  listing,
147
154
  overflow,
148
- ].join("\n");
155
+ );
156
+
157
+ return lines.join("\n");
149
158
  }
150
159
 
151
160
  // 所有会话列表卡片
package/src/config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { existsSync } from "node:fs";
2
+ import { homedir } from "node:os";
2
3
  import { dirname, join } from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
  import { appendFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
@@ -65,7 +66,7 @@ export const CLAUDE_EFFORT = process.env.CHATCCC_ANTHROPIC_EFFORT?.trim() || "de
65
66
  // 该路径仅影响通过 /new 新建的 Claude 会话,不影响已有会话的 resume。
66
67
  export const DEFAULT_CWD_FILE = join(PROJECT_ROOT, ".claude", "working_dir.txt");
67
68
 
68
- /** 读取 /cd 设置的默认工作路径。若文件不存在或路径已失效,回退到 PROJECT_ROOT。 */
69
+ /** 读取 /cd 设置的默认工作路径。若文件不存在或路径已失效,回退到用户主目录。 */
69
70
  export async function getDefaultCwd(): Promise<string> {
70
71
  try {
71
72
  const content = await readFile(DEFAULT_CWD_FILE, "utf-8");
@@ -77,7 +78,9 @@ export async function getDefaultCwd(): Promise<string> {
77
78
  } catch { /* path gone, fall through */ }
78
79
  }
79
80
  } catch { /* file doesn't exist yet */ }
80
- return PROJECT_ROOT;
81
+ // 用户未通过 /cd 设置过工作路径时,回退到操作系统用户主目录
82
+ // Windows: C:\Users\<用户名> Linux: /home/<用户名>
83
+ return homedir();
81
84
  }
82
85
 
83
86
  /** 设置新建会话的默认工作路径(由 /cd 命令调用) */
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  */
23
23
 
24
24
  import { spawn } from "node:child_process";
25
+ import { getSessionInfo } from "@anthropic-ai/claude-agent-sdk";
25
26
  import { readdir, stat } from "node:fs/promises";
26
27
  import { resolve, dirname, basename } from "node:path";
27
28
 
@@ -182,6 +183,18 @@ async function handleCommand(text: string, chatId: string, openId: string, msgTi
182
183
  if (text === "/cd" || text.startsWith("/cd ")) {
183
184
  const cdToken = await getTenantAccessToken();
184
185
  const currentDir = await getDefaultCwd();
186
+
187
+ // 获取当前会话的实际工作路径(若在会话群内)
188
+ let sessionCwd: string | undefined;
189
+ try {
190
+ const chatInfo = await getChatInfo(cdToken, chatId);
191
+ const sid = extractSessionId(chatInfo.description);
192
+ if (sid) {
193
+ const info = await getSessionInfo(sid);
194
+ sessionCwd = info?.cwd;
195
+ }
196
+ } catch { /* 非会话群或获取失败,不显示 */ }
197
+
185
198
  const arg = text.slice(3).trim(); // everything after "/cd" (may be empty)
186
199
 
187
200
  // Resolve target directory
@@ -234,7 +247,7 @@ async function handleCommand(text: string, chatId: string, openId: string, msgTi
234
247
  return a.name.localeCompare(b.name);
235
248
  });
236
249
 
237
- const content = buildCdContent(targetDir, withStats, isUpdate);
250
+ const content = buildCdContent(targetDir, withStats, isUpdate, sessionCwd);
238
251
  await sendCardReply(cdToken, chatId, "新会话工作路径", content, "blue");
239
252
  return;
240
253
  }