cc-viewer 1.9.39 → 1.9.40

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/cli.js CHANGED
@@ -708,7 +708,8 @@ async function waitForImServerPort(serverMod) {
708
708
  // skip-permissions」的 runCliMode,外加:全局唯一锁、CC_APPEND_SYSTEM.md 人格预置/迁移、IM 专属 env。
709
709
  // 注意:裸 `--im` 与 `--im-sdk` 现在都走 runImSdkMode(SDK),本函数仅由 --im-pty 触发。
710
710
  async function runImMode(platformId) {
711
- const { getDescriptor } = await import('./server/lib/im/im-config.js');
711
+ const { getDescriptor, loadConfig } = await import('./server/lib/im/im-config.js');
712
+ const { applyImProxyProfile } = await import('./server/lib/im/im-proxy-profile.js');
712
713
  if (!getDescriptor(platformId)) {
713
714
  console.error(t('cli.imUnknownPlatform', { id: platformId }));
714
715
  process.exit(1);
@@ -757,6 +758,13 @@ async function runImMode(platformId) {
757
758
  // 解析,确保 ensureHooks() 与子进程读取同一目录。
758
759
  await resolveImClaudeConfigDir();
759
760
 
761
+ // Pin cwd to the IM dir so the interceptor binds this platform's workspace (IM_<id>), and apply
762
+ // the platform's proxy-profile pin BEFORE runCliMode imports server/proxy.js (which loads the
763
+ // interceptor). Same contract as runImSdkMode; non-fatal on write failure.
764
+ process.chdir(dir);
765
+ try { applyImProxyProfile(platformId, loadConfig(platformId).proxyProfileId); }
766
+ catch (err) { reportSwallowed('cli.imProxyProfileApply', err); }
767
+
760
768
  // worker 全自动:skip-permissions + 不开浏览器,工作目录设为 IM_<id>/
761
769
  return runCliMode(['--dangerously-skip-permissions'], dir, true);
762
770
  }
@@ -765,7 +773,8 @@ async function runImMode(platformId) {
765
773
  // 与 runImMode 共享:全局唯一锁、IM_<id>/ 工作目录、CC_APPEND_SYSTEM.md 人格、内置技能、
766
774
  // 7050-7099 loopback 端口段、CCV_IM_DENY=1 硬拦截。由 im-process-manager 以 `--im-sdk`(或裸 `--im`)拉起。
767
775
  async function runImSdkMode(platformId) {
768
- const { getDescriptor } = await import('./server/lib/im/im-config.js');
776
+ const { getDescriptor, loadConfig } = await import('./server/lib/im/im-config.js');
777
+ const { applyImProxyProfile } = await import('./server/lib/im/im-proxy-profile.js');
769
778
  if (!getDescriptor(platformId)) {
770
779
  console.error(t('cli.imUnknownPlatform', { id: platformId }));
771
780
  process.exit(1);
@@ -787,6 +796,10 @@ async function runImSdkMode(platformId) {
787
796
 
788
797
  const dir = imDir(platformId);
789
798
  mkdirSync(dir, { recursive: true });
799
+ // Pin the process cwd to the IM dir so the interceptor binds this platform's workspace
800
+ // (IM_<id>) even when a worker is hand-started from another directory; manager-spawned
801
+ // workers already run with cwd=dir, so this is a no-op there.
802
+ process.chdir(dir);
790
803
 
791
804
  // 1) 全局唯一锁(与 runImMode 一致;exit 钩子按身份释放)
792
805
  const lockRes = acquireImLock(platformId);
@@ -836,6 +849,12 @@ async function runImSdkMode(platformId) {
836
849
  process.env.CCV_SDK_MODE = '1';
837
850
  process.env.CCV_PROJECT_DIR = dir;
838
851
  process.env.CCV_PROXY_MODE = '1';
852
+ // Apply this platform's pinned proxy profile BEFORE importing proxy.js — that import runs
853
+ // setupInterceptor(), and interceptor.js binds the workspace from process.cwd() (= IM_<id>)
854
+ // and reads <LOG_DIR>/IM_<id>/active-profile.json at module top. Non-fatal: on failure the
855
+ // worker falls back to the existing/global profile.
856
+ try { applyImProxyProfile(platformId, loadConfig(platformId).proxyProfileId); }
857
+ catch (err) { reportSwallowed('cli.imProxyProfileApply', err); }
839
858
  const { startProxy } = await import('./server/proxy.js');
840
859
  const proxyPort = await startProxy();
841
860
  process.env.CCV_PROXY_PORT = String(proxyPort);
@@ -976,7 +995,6 @@ async function runImSdkMode(platformId) {
976
995
 
977
996
  // 13) 启动 SDK 形状的 IM bridge —— 必须在 initSdkSession 之后(session 已注册,消息不丢)。
978
997
  const imCore = await import('./server/lib/im/im-bridge-core.js');
979
- const { loadConfig } = await import('./server/lib/im/im-config.js');
980
998
  await imCore.startBridge(platformId, {
981
999
  // 入站:结构化推送(sendUserMessage),无需 bracketed-paste 转义帧。
982
1000
  sendPrompt: (text, cb) => {