@co0ontty/wand 1.21.10 → 1.21.12

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/dist/server.js CHANGED
@@ -13,6 +13,7 @@ import { WebSocketServer } from "ws";
13
13
  import { ensureAvatarSeed, getAvatarSvg } from "./avatar.js";
14
14
  import { createSession, revokeSession, setAuthStorage, validateSession } from "./auth.js";
15
15
  import { ensureCertificates } from "./cert.js";
16
+ import { buildChildEnv } from "./env-utils.js";
16
17
  import { isExecutionMode, PREFERENCE_KEYS, resolveConfigDir, saveConfig, writePreferenceToStorage, } from "./config.js";
17
18
  import { getCachedModels, refreshModels } from "./models.js";
18
19
  import { ProcessManager } from "./process-manager.js";
@@ -554,6 +555,7 @@ export async function startServer(config, configPath) {
554
555
  ? path.join(SERVER_MODULE_DIR, "web-ui", "content")
555
556
  : path.join(RUNTIME_ROOT_DIR, "src", "web-ui", "content");
556
557
  app.use("/vendor/wterm", express.static(path.join(contentDir, "vendor", "wterm"), vendorCacheOpts));
558
+ app.use("/vendor/qrcode", express.static(path.join(contentDir, "vendor", "qrcode"), vendorCacheOpts));
557
559
  // ── Web UI and PWA endpoints ──
558
560
  app.get("/", (_req, res) => {
559
561
  res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
@@ -803,6 +805,45 @@ export async function startServer(config, configPath) {
803
805
  github: ghApk ? { fileName: ghApk.fileName, version: ghApk.version, size: ghApk.size, downloadUrl: ghApk.downloadUrl } : null,
804
806
  });
805
807
  });
808
+ // 返回当前 inheritEnv 配置下,wand 启动 PTY / 结构化子进程时实际会传给
809
+ // claude / codex 的环境变量集合。值会按下面的规则做掩码:
810
+ // - 名字里含 KEY/TOKEN/SECRET/PASSWORD/AUTH/CREDENTIAL/COOKIE/SESSION 的视为敏感
811
+ // - 敏感值默认显示为 ***(保留长度提示),可通过 ?reveal=1 取消掩码
812
+ // 即使开启 reveal,仍只对已认证用户可见(路由由全局 requireAuth 保护)。
813
+ app.get("/api/settings/env-preview", (req, res) => {
814
+ const inheritEnv = config.inheritEnv !== false;
815
+ // 复用与 process-manager / structured-session-manager 相同的组装逻辑,
816
+ // 这样 UI 上看到的就是真正会被注入到子进程的那一份环境。
817
+ const env = buildChildEnv(inheritEnv, {
818
+ // PTY runner 还会注入 WAND_* 用于 mode 协调,这里也展示出来便于排查。
819
+ WAND_MODE: "<runtime>",
820
+ WAND_AUTO_CONFIRM: "<runtime>",
821
+ WAND_AUTO_EDIT: "<runtime>",
822
+ });
823
+ const reveal = req.query.reveal === "1" || req.query.reveal === "true";
824
+ const SENSITIVE_PATTERN = /(KEY|TOKEN|SECRET|PASSWORD|AUTH|CREDENTIAL|COOKIE|SESSION)/i;
825
+ const entries = Object.keys(env)
826
+ .sort()
827
+ .map((name) => {
828
+ const raw = env[name] ?? "";
829
+ const sensitive = SENSITIVE_PATTERN.test(name);
830
+ const masked = sensitive && !reveal;
831
+ // WAND_* 占位值不算敏感,保持原样。
832
+ const isPlaceholder = raw.startsWith("<") && raw.endsWith(">");
833
+ return {
834
+ name,
835
+ value: masked && !isPlaceholder ? "***" : raw,
836
+ length: raw.length,
837
+ sensitive,
838
+ };
839
+ });
840
+ res.json({
841
+ inheritEnv,
842
+ total: entries.length,
843
+ reveal,
844
+ entries,
845
+ });
846
+ });
806
847
  app.get("/api/app-connect-code", requireAuth, (req, res) => {
807
848
  const dbPassword = storage.getPassword();
808
849
  const effectivePassword = dbPassword ?? config.password;
@@ -1536,9 +1536,13 @@ export class StructuredSessionManager {
1536
1536
  : `Please respond in ${language}. Use ${language} for all your explanations, comments, and conversational text.`);
1537
1537
  }
1538
1538
  const sdkClaudeBinary = resolveSdkClaudeBinary();
1539
+ // SDK 默认会把整个 process.env 透传给 claude 子进程;这里显式按 inheritEnv 配置组装,
1540
+ // 否则关闭"继承环境变量"开关时 SDK 路径会被静默忽略。
1541
+ const sdkEnv = buildChildEnv(this.config.inheritEnv !== false);
1539
1542
  const sdkOptions = {
1540
1543
  cwd: session.cwd,
1541
1544
  abortController,
1545
+ env: sdkEnv,
1542
1546
  permissionMode,
1543
1547
  ...(permissionMode === "bypassPermissions" ? { allowDangerouslySkipPermissions: true } : {}),
1544
1548
  ...(allowedToolsForRoot ? { allowedTools: allowedToolsForRoot } : {}),