bnpanel 0.6.6 → 0.6.8

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/index.js CHANGED
@@ -10,6 +10,8 @@ import path15 from "node:path";
10
10
 
11
11
  // src/host/app.js
12
12
  import { spawn as spawn2 } from "node:child_process";
13
+ import { once } from "node:events";
14
+ import { finished } from "node:stream/promises";
13
15
  import crypto8 from "node:crypto";
14
16
  import fs14 from "node:fs";
15
17
  import path14 from "node:path";
@@ -7122,6 +7124,8 @@ var EntitlementsSchema = external_exports.object({
7122
7124
  expiresAt: external_exports.string(),
7123
7125
  graceUntil: external_exports.string(),
7124
7126
  issuedAt: external_exports.string(),
7127
+ /** 代理归属码,激活许可证时由服务端根据 license.reseller_id 写入,面板据此区分代理。 */
7128
+ resellerCode: external_exports.string().optional(),
7125
7129
  /** Detached ed25519 signature over the other fields; verified offline by the panel. */
7126
7130
  signature: external_exports.string().optional()
7127
7131
  });
@@ -7797,6 +7801,37 @@ var LicenseClient = class {
7797
7801
  if (body.state === "revoked") return { state: "revoked", notices: (body.notices ?? []).map((n) => n.body), product: cache.product };
7798
7802
  return { state: body.state, notices: (body.notices ?? []).map((n) => n.body), product: cache.product };
7799
7803
  }
7804
+ /** 在线能力(如诊断)用:令牌临近过期先续期,避免用了 24 小时后突然失效。 */
7805
+ async ensureToken(product) {
7806
+ const cache = this.readCache(product);
7807
+ if (!cache) return null;
7808
+ const expires = cache.tokenExpiresAt ? Date.parse(cache.tokenExpiresAt) : 0;
7809
+ if (expires && expires - Date.now() > 5 * 6e4) return cache.token;
7810
+ return await this.refreshToken(product) ?? cache.token;
7811
+ }
7812
+ async refreshToken(product) {
7813
+ const cache = this.readCache(product);
7814
+ if (!cache) return null;
7815
+ try {
7816
+ const res = await fetch(`${this.cfg.baseUrl}/v1/refresh`, {
7817
+ method: "POST",
7818
+ headers: { "content-type": "application/json", authorization: `Bearer ${cache.token}` },
7819
+ body: JSON.stringify({ device: this.device(), token: cache.token })
7820
+ });
7821
+ const body = await res.json();
7822
+ if (!res.ok || !body?.token) return null;
7823
+ const store = this.readStore();
7824
+ store.products[cache.product] = {
7825
+ ...cache,
7826
+ token: String(body.token),
7827
+ tokenExpiresAt: String(body.expiresAt ?? cache.tokenExpiresAt)
7828
+ };
7829
+ this.writeStore(store);
7830
+ return String(body.token);
7831
+ } catch {
7832
+ return null;
7833
+ }
7834
+ }
7800
7835
  statusFor(product) {
7801
7836
  const cache = this.readCache(product);
7802
7837
  if (!cache) {
@@ -7843,6 +7878,11 @@ var LicenseClient = class {
7843
7878
  canUseProduct(product) {
7844
7879
  return this.statusFor(product).canExport;
7845
7880
  }
7881
+ /** 从已缓存的签名 entitlements 中取代理归属码;未激活或官方直售时返回 null。 */
7882
+ resellerCode(product) {
7883
+ const cache = this.readCache(product);
7884
+ return cache?.entitlements?.resellerCode ?? null;
7885
+ }
7846
7886
  tokenFor(product) {
7847
7887
  return this.readCache(product)?.token ?? null;
7848
7888
  }
@@ -8488,16 +8528,13 @@ function createChatBridge() {
8488
8528
  recent.unshift(entry);
8489
8529
  if (recent.length > 30) recent.length = 30;
8490
8530
  }
8491
- async function startSkillRun(opts) {
8492
- const skill = String(opts.skill || "").trim();
8531
+ async function openSession(opts) {
8493
8532
  const projectPath = path11.resolve(String(opts.projectPath || ""));
8494
8533
  const promptText = String(opts.promptText || "").trim();
8495
- const agentId = opts.agentId || skill;
8496
- if (!skill) return { ok: false, reason: "missing-skill" };
8534
+ const agentId = opts.agentId || "panel";
8535
+ const skill = opts.skill || "prompt";
8497
8536
  if (!promptText) return { ok: false, reason: "missing-prompt" };
8498
- if (!projectPath || !fs11.existsSync(projectPath)) {
8499
- return { ok: false, reason: "missing-project", error: `project path not found: ${projectPath}` };
8500
- }
8537
+ if (!projectPath) return { ok: false, reason: "missing-project", error: "project path is empty" };
8501
8538
  if (!available()) {
8502
8539
  const entry = {
8503
8540
  at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -8508,7 +8545,7 @@ function createChatBridge() {
8508
8545
  error: "sessionController unavailable (not running inside DSH)",
8509
8546
  projectPath
8510
8547
  };
8511
- remember(entry);
8548
+ if (opts.rememberRun !== false) remember(entry);
8512
8549
  return { ok: false, reason: "chat-unavailable", ...entry };
8513
8550
  }
8514
8551
  try {
@@ -8543,8 +8580,8 @@ function createChatBridge() {
8543
8580
  ok: true,
8544
8581
  projectPath
8545
8582
  };
8546
- remember(entry);
8547
- return { ok: true, sessionId, skill, projectPath };
8583
+ if (opts.rememberRun !== false) remember(entry);
8584
+ return { ok: true, sessionId, projectPath };
8548
8585
  } catch (err) {
8549
8586
  const entry = {
8550
8587
  at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -8555,14 +8592,28 @@ function createChatBridge() {
8555
8592
  error: err?.message || String(err),
8556
8593
  projectPath
8557
8594
  };
8558
- remember(entry);
8595
+ if (opts.rememberRun !== false) remember(entry);
8559
8596
  return { ok: false, reason: "kickoff-failed", error: entry.error, projectPath };
8560
8597
  }
8561
8598
  }
8599
+ async function startSkillRun(opts) {
8600
+ const skill = String(opts.skill || "").trim();
8601
+ if (!skill) return { ok: false, reason: "missing-skill" };
8602
+ const projectPath = path11.resolve(String(opts.projectPath || ""));
8603
+ if (!projectPath || !fs11.existsSync(projectPath)) {
8604
+ return { ok: false, reason: "missing-project", error: `project path not found: ${projectPath}` };
8605
+ }
8606
+ const result = await openSession({ ...opts, agentId: opts.agentId || skill, skill });
8607
+ return result.ok ? { ...result, skill } : result;
8608
+ }
8609
+ async function startPromptRun(opts) {
8610
+ return openSession({ ...opts, rememberRun: false });
8611
+ }
8562
8612
  return {
8563
8613
  setSessionController,
8564
8614
  available,
8565
8615
  startSkillRun,
8616
+ startPromptRun,
8566
8617
  listRecent,
8567
8618
  extractKickoffPrompt
8568
8619
  };
@@ -8811,7 +8862,29 @@ function resolveIconsDir() {
8811
8862
  return candidates[0];
8812
8863
  }
8813
8864
  var ICONS_DIR = resolveIconsDir();
8865
+ function resolveDiagnoseSkillDir(skillName = "account-diagnosis") {
8866
+ const here = path14.dirname(fileURLToPath2(import.meta.url));
8867
+ const candidates = [
8868
+ path14.join(here, "assets", "diagnose", skillName),
8869
+ path14.join(here, "..", "..", "assets", "diagnose", skillName)
8870
+ ];
8871
+ return candidates.find((dir) => fs14.existsSync(path14.join(dir, "SKILL.md"))) || null;
8872
+ }
8873
+ var DIAGNOSE_SKILL_DIRS = {
8874
+ "account-diagnosis": resolveDiagnoseSkillDir("account-diagnosis"),
8875
+ "creator-research": resolveDiagnoseSkillDir("creator-research"),
8876
+ "topic-planner": resolveDiagnoseSkillDir("topic-planner")
8877
+ };
8878
+ function seedDiagnoseSkill(projectDir, skillName = "account-diagnosis") {
8879
+ const sourceDir = DIAGNOSE_SKILL_DIRS[skillName];
8880
+ if (!sourceDir) throw new Error("\u8D26\u53F7\u589E\u957F\u5185\u6838\u7F3A\u5931\uFF0C\u8BF7\u66F4\u65B0\u9762\u677F");
8881
+ const destDir = path14.join(projectDir, ".agents", "skills", skillName);
8882
+ fs14.mkdirSync(path14.dirname(destDir), { recursive: true });
8883
+ fs14.cpSync(sourceDir, destDir, { recursive: true, force: true });
8884
+ return destDir;
8885
+ }
8814
8886
  var MAX_BODY = 256 * 1024;
8887
+ var GROWTH_LABELS = { research: "\u5BF9\u6807\u8C03\u7814", planner: "\u9009\u9898\u89C4\u5212", followup: "\u590D\u8BCA\u5BF9\u6BD4" };
8815
8888
  function send(res, status, body) {
8816
8889
  const data = JSON.stringify(body);
8817
8890
  res.writeHead(status, {
@@ -8846,12 +8919,17 @@ function createPanelApp(options = {}) {
8846
8919
  }
8847
8920
  const accountId = options.accountId ?? settings.accountId ?? "local-dev";
8848
8921
  const packageName = panelPackageName(options.packageName);
8849
- const resellerCode = panelResellerCode(options.resellerCode);
8850
- const buyPageUrl = () => withReseller(`${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`, resellerCode);
8922
+ const configResellerCode = panelResellerCode(options.resellerCode);
8923
+ const resellerCode = () => {
8924
+ const fromLicense = license.resellerCode();
8925
+ if (fromLicense) return fromLicense;
8926
+ return configResellerCode;
8927
+ };
8928
+ const buyPageUrl = () => withReseller(`${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`, resellerCode());
8851
8929
  const commerceUrl = (pathname) => {
8852
8930
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
8853
8931
  if (!base) return "";
8854
- return withReseller(`${base}${pathname}`, resellerCode);
8932
+ return withReseller(`${base}${pathname}`, resellerCode());
8855
8933
  };
8856
8934
  const panelInstallHint = (updating) => updating ? `\u5728 DSH \u7684\u63D2\u4EF6\u5217\u8868\u91CC\u66F4\u65B0\u9762\u677F\uFF0C\u7136\u540E\u91CD\u542F` : `\u5728 DSH \u91CC\u6DFB\u52A0\u63D2\u4EF6\u5E76\u5B89\u88C5\u9762\u677F`;
8857
8935
  const license = new LicenseClient({
@@ -9712,6 +9790,476 @@ function createPanelApp(options = {}) {
9712
9790
  queue.cancel(t.id);
9713
9791
  }
9714
9792
  }
9793
+ function memberInfo() {
9794
+ const rows = license.listProducts();
9795
+ const isOn = (status) => status && (status.state === "active" || status.state === "grace");
9796
+ const pick = rows.find((row) => row.product === "biupro" && isOn(row.status)) ?? null;
9797
+ const expiresAt = pick?.status?.expiresAt || null;
9798
+ const at2 = expiresAt ? Date.parse(expiresAt) : 0;
9799
+ return {
9800
+ active: !!isOn(pick?.status),
9801
+ product: pick?.product ?? null,
9802
+ expiresAt,
9803
+ daysLeft: at2 ? Math.max(0, Math.ceil((at2 - Date.now()) / 864e5)) : 0
9804
+ };
9805
+ }
9806
+ const DIAGNOSE_DIR = path14.join(paths.root, "diagnose");
9807
+ const GROWTH_DIR = path14.join(paths.root, "growth");
9808
+ const DIAGNOSE_MEDIA_DIR = path14.join(paths.root, "diagnose-media");
9809
+ const DIAGNOSE_SESSIONS_DIR = path14.join(paths.root, "diagnose-sessions");
9810
+ const DIAGNOSE_MAX_REPORTS = 60;
9811
+ const DIAGNOSE_MAX_UPLOAD = 300 * 1024 * 1024;
9812
+ const DIAGNOSE_IMAGE_EXT = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp", ".heic"]);
9813
+ const DIAGNOSE_VIDEO_EXT = /* @__PURE__ */ new Set([".mp4", ".mov", ".m4v", ".webm", ".avi", ".mkv"]);
9814
+ const DIAGNOSE_MEDIA_TYPES = /* @__PURE__ */ new Map([
9815
+ [".jpg", "image/jpeg"],
9816
+ [".jpeg", "image/jpeg"],
9817
+ [".png", "image/png"],
9818
+ [".webp", "image/webp"],
9819
+ [".gif", "image/gif"],
9820
+ [".bmp", "image/bmp"],
9821
+ [".heic", "image/heic"],
9822
+ [".mp4", "video/mp4"],
9823
+ [".m4v", "video/mp4"],
9824
+ [".mov", "video/quicktime"],
9825
+ [".webm", "video/webm"],
9826
+ [".avi", "video/x-msvideo"],
9827
+ [".mkv", "video/x-matroska"]
9828
+ ]);
9829
+ function assertDiagnoseMember() {
9830
+ const info = memberInfo();
9831
+ if (!info.active) throw Object.assign(new Error("\u53F7\u8109\u53CA\u589E\u957F\u80FD\u529B\u662F BiuPro \u4E13\u5C5E\u529F\u80FD\uFF0C\u8BF7\u5148\u5F00\u901A BiuPro"), { status: 403 });
9832
+ }
9833
+ async function saveDiagnoseUpload(req, query) {
9834
+ assertDiagnoseMember();
9835
+ const rawName = String(query.get("name") || "\u7D20\u6750").slice(0, 160);
9836
+ const ext = path14.extname(rawName).toLowerCase();
9837
+ const kind = DIAGNOSE_IMAGE_EXT.has(ext) ? "image" : DIAGNOSE_VIDEO_EXT.has(ext) ? "video" : "";
9838
+ if (!kind) throw Object.assign(new Error("\u53EA\u652F\u6301\u56FE\u7247\u6216\u89C6\u9891\uFF08jpg/png/webp/mp4/mov \u7B49\uFF09"), { status: 400 });
9839
+ const id = crypto8.randomUUID();
9840
+ const dir = path14.join(DIAGNOSE_MEDIA_DIR, id);
9841
+ fs14.mkdirSync(dir, { recursive: true });
9842
+ const file = path14.join(dir, `source${ext}`);
9843
+ const out = fs14.createWriteStream(file);
9844
+ let size = 0;
9845
+ try {
9846
+ for await (const chunk of req) {
9847
+ size += chunk.length;
9848
+ if (size > DIAGNOSE_MAX_UPLOAD) {
9849
+ throw Object.assign(new Error("\u6587\u4EF6\u592A\u5927\uFF0C\u5355\u4E2A\u7D20\u6750\u4E0A\u9650 300MB"), { status: 413 });
9850
+ }
9851
+ if (!out.write(chunk)) await once(out, "drain");
9852
+ }
9853
+ await new Promise((resolve, reject) => {
9854
+ out.once("error", reject);
9855
+ out.end(resolve);
9856
+ });
9857
+ await finished(out);
9858
+ } catch (error) {
9859
+ out.destroy();
9860
+ fs14.rmSync(dir, { recursive: true, force: true });
9861
+ throw error;
9862
+ }
9863
+ return {
9864
+ id,
9865
+ name: rawName,
9866
+ kind,
9867
+ size,
9868
+ mime: String(req.headers["content-type"] || "").split(";")[0] || DIAGNOSE_MEDIA_TYPES.get(ext) || "",
9869
+ url: `${basePath}/diagnose/media/${id}`,
9870
+ path: file
9871
+ };
9872
+ }
9873
+ function normalizeDiagnoseMedia(input) {
9874
+ const rows = Array.isArray(input) ? input : [];
9875
+ const out = [];
9876
+ for (const item of rows.slice(0, 12)) {
9877
+ const id = String(item?.id || "");
9878
+ if (!/^[0-9a-f-]{36}$/i.test(id)) continue;
9879
+ const dir = path14.join(DIAGNOSE_MEDIA_DIR, id);
9880
+ if (!fs14.existsSync(dir)) continue;
9881
+ const name2 = fs14.readdirSync(dir).find((entry) => entry.startsWith("source."));
9882
+ if (!name2) continue;
9883
+ const file = path14.join(dir, name2);
9884
+ const ext = path14.extname(name2).toLowerCase();
9885
+ out.push({
9886
+ id,
9887
+ name: String(item?.name || name2).slice(0, 120),
9888
+ kind: DIAGNOSE_IMAGE_EXT.has(ext) ? "image" : "video",
9889
+ size: Number(item?.size) || fs14.statSync(file).size,
9890
+ path: file
9891
+ });
9892
+ }
9893
+ return out;
9894
+ }
9895
+ function materializeDiagnoseMedia(projectPath, media) {
9896
+ if (!media.length) return [];
9897
+ const assetsDir = path14.join(projectPath, "assets");
9898
+ fs14.mkdirSync(assetsDir, { recursive: true });
9899
+ return media.map((item, index) => {
9900
+ const ext = path14.extname(item.path);
9901
+ const raw = String(item.name || path14.basename(item.path)).replace(/[^\w.\-]+/g, "_").slice(-60);
9902
+ const safe = raw || `media-${index + 1}${ext}`;
9903
+ const target = path14.join(assetsDir, `${String(index + 1).padStart(2, "0")}-${safe}`);
9904
+ if (!fs14.existsSync(target)) {
9905
+ try {
9906
+ fs14.linkSync(item.path, target);
9907
+ } catch {
9908
+ fs14.copyFileSync(item.path, target);
9909
+ }
9910
+ }
9911
+ return { ...item, path: target };
9912
+ });
9913
+ }
9914
+ function serveDiagnoseMedia(req, res, id) {
9915
+ assertDiagnoseMember();
9916
+ if (!/^[0-9a-f-]{36}$/i.test(id)) return send(res, 404, { error: "\u627E\u4E0D\u5230\u7D20\u6750" });
9917
+ const dir = path14.join(DIAGNOSE_MEDIA_DIR, id);
9918
+ if (!fs14.existsSync(dir)) return send(res, 404, { error: "\u627E\u4E0D\u5230\u7D20\u6750" });
9919
+ const name2 = fs14.readdirSync(dir).find((entry) => entry.startsWith("source."));
9920
+ if (!name2) return send(res, 404, { error: "\u627E\u4E0D\u5230\u7D20\u6750" });
9921
+ const file = path14.join(dir, name2);
9922
+ const type = DIAGNOSE_MEDIA_TYPES.get(path14.extname(name2).toLowerCase()) || "application/octet-stream";
9923
+ const stat = fs14.statSync(file);
9924
+ const headers = {
9925
+ "content-type": type,
9926
+ "accept-ranges": "bytes",
9927
+ "cache-control": "no-store"
9928
+ };
9929
+ const match = /^bytes=(\d+)-(\d*)$/.exec(String(req.headers.range || ""));
9930
+ if (match) {
9931
+ const start = Number(match[1]);
9932
+ const end = match[2] ? Math.min(Number(match[2]), stat.size - 1) : stat.size - 1;
9933
+ if (!Number.isFinite(start) || start > end || start >= stat.size) {
9934
+ res.writeHead(416, { "content-range": `bytes */${stat.size}` });
9935
+ return void res.end();
9936
+ }
9937
+ res.writeHead(206, { ...headers, "content-range": `bytes ${start}-${end}/${stat.size}`, "content-length": end - start + 1 });
9938
+ return void fs14.createReadStream(file, { start, end }).pipe(res);
9939
+ }
9940
+ res.writeHead(200, { ...headers, "content-length": stat.size });
9941
+ return void fs14.createReadStream(file).pipe(res);
9942
+ }
9943
+ function diagnoseReports() {
9944
+ if (!fs14.existsSync(DIAGNOSE_DIR)) return [];
9945
+ const rows = [];
9946
+ for (const name2 of fs14.readdirSync(DIAGNOSE_DIR)) {
9947
+ if (!/^[a-zA-Z0-9-]{8,64}\.json$/.test(name2)) continue;
9948
+ try {
9949
+ const item = JSON.parse(fs14.readFileSync(path14.join(DIAGNOSE_DIR, name2), "utf8"));
9950
+ if (item?.id && item?.snapshot) rows.push(item);
9951
+ } catch {
9952
+ }
9953
+ }
9954
+ return rows.sort((a, b2) => String(b2.createdAt || "").localeCompare(String(a.createdAt || "")));
9955
+ }
9956
+ function saveDiagnoseReport(snapshot, analysis, sessionId, extra = {}) {
9957
+ const text = String(analysis || "").slice(0, 2e4);
9958
+ const media = (Array.isArray(extra.media) ? extra.media : []).slice(0, 12).map((item) => ({
9959
+ id: String(item.id || ""),
9960
+ name: String(item.name || "").slice(0, 120),
9961
+ kind: item.kind === "video" ? "video" : "image",
9962
+ size: Number(item.size) || 0
9963
+ }));
9964
+ const record = {
9965
+ id: crypto8.randomUUID(),
9966
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
9967
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
9968
+ title: String(snapshot.title || snapshot.description || "\u672A\u547D\u540D\u8BCA\u65AD").slice(0, 80),
9969
+ snapshot,
9970
+ analysis: text,
9971
+ sessionId: String(sessionId || "").slice(0, 80),
9972
+ projectPath: String(extra.projectPath || "").slice(0, 400),
9973
+ media
9974
+ };
9975
+ const raw = JSON.stringify(record);
9976
+ if (Buffer.byteLength(raw) > 128 * 1024) {
9977
+ throw Object.assign(new Error("\u62A5\u544A\u592A\u5927\uFF0C\u4FDD\u5B58\u5931\u8D25"), { status: 413 });
9978
+ }
9979
+ fs14.mkdirSync(DIAGNOSE_DIR, { recursive: true });
9980
+ fs14.writeFileSync(path14.join(DIAGNOSE_DIR, `${record.id}.json`), raw, "utf8");
9981
+ for (const old of diagnoseReports().slice(DIAGNOSE_MAX_REPORTS)) {
9982
+ try {
9983
+ fs14.rmSync(path14.join(DIAGNOSE_DIR, `${old.id}.json`), { force: true });
9984
+ } catch {
9985
+ }
9986
+ }
9987
+ return record;
9988
+ }
9989
+ function diagnosePrompt(snapshot, opts = {}) {
9990
+ const data = snapshot || {};
9991
+ const stats = data.stats || {};
9992
+ const statLine = [
9993
+ stats.likes != null ? `\u70B9\u8D5E ${stats.likes}` : "",
9994
+ stats.comments != null ? `\u8BC4\u8BBA ${stats.comments}` : "",
9995
+ stats.collects != null ? `\u6536\u85CF ${stats.collects}` : "",
9996
+ stats.shares != null ? `\u8F6C\u53D1 ${stats.shares}` : "",
9997
+ stats.followers != null ? `\u7C89\u4E1D ${stats.followers}` : "",
9998
+ stats.works != null ? `\u4F5C\u54C1 ${stats.works}` : ""
9999
+ ].filter(Boolean).join(" \xB7 ");
10000
+ const media = Array.isArray(opts.media) ? opts.media : [];
10001
+ const projectPath = String(opts.projectPath || "");
10002
+ const skillPath = String(opts.skillPath || "");
10003
+ const hasVideo = media.some((item) => item.kind === "video");
10004
+ return [
10005
+ "\u8BF7\u6267\u884C\u4E00\u6B21\u300C\u6296\u97F3\u8D26\u53F7\u8BCA\u65AD\u300D\u3002\u8FD9\u662F\u8D26\u53F7\u7EA7\u6570\u636E\u8BCA\u65AD\uFF0C\u4E0D\u8981\u9000\u5316\u4E3A\u5355\u6761\u89C6\u9891\u70B9\u8BC4\u3002",
10006
+ projectPath ? `\u9879\u76EE\u76EE\u5F55\uFF1A${projectPath}` : "",
10007
+ skillPath ? `\u8BCA\u65AD\u6280\u80FD\u76EE\u5F55\uFF1A${skillPath}` : "",
10008
+ "\u5F00\u59CB\u524D\u5FC5\u987B\u5B8C\u6574\u9605\u8BFB\u6280\u80FD\u76EE\u5F55\u4E2D\u7684 SKILL.md\uFF0C\u5E76\u4E25\u683C\u9075\u5FAA\u5176\u4E2D\u7684\u6267\u884C\u6D41\u7A0B\u3001\u786C\u6027\u89C4\u5219\u548C\u8D28\u91CF\u81EA\u68C0\u6E05\u5355\u3002\u5FC5\u987B\u540C\u65F6\u8BFB\u53D6 references/diagnosis-framework.md\u3001references/prescription-library.md \u548C assets/report-template.md\uFF1B\u5904\u65B9\u53EA\u80FD\u4F7F\u7528\u8BE5\u5904\u65B9\u5E93\u4E2D\u53EF\u6EAF\u6E90\u7684\u6765\u6E90\uFF0C\u4E0D\u5F97\u81EA\u884C\u7F16\u9020\u51FA\u5904\u3002",
10009
+ "",
10010
+ media.length ? "\u7528\u6237\u4E0A\u4F20\u7684\u7D20\u6750\uFF1A" : "\u7528\u6237\u6CA1\u6709\u4E0A\u4F20\u7D20\u6750\uFF0C\u53EA\u80FD\u4F7F\u7528\u4E0B\u65B9\u8865\u5145\u4FE1\u606F\uFF1B\u4E0D\u8981\u56E0\u6B64\u7F16\u9020\u8D26\u53F7\u6570\u636E\u3002",
10011
+ ...media.map((item, index) => `${index + 1}. ${item.kind === "video" ? "\u89C6\u9891" : "\u56FE\u7247"}\uFF1A${item.path}`),
10012
+ media.some((item) => item.kind === "image") ? "\u540E\u53F0\u622A\u56FE\u5FC5\u987B\u9010\u5F20\u76F4\u63A5\u67E5\u770B\u3002\u5148\u63D0\u53D6\u4F5C\u54C1\u6807\u9898\u3001\u53D1\u5E03\u65F6\u95F4\u3001\u64AD\u653E\u3001\u70B9\u8D5E\u3001\u8BC4\u8BBA\u3001\u5206\u4EAB\u3001\u7C89\u4E1D\u7B49\u6240\u6709\u53EF\u8BFB\u6570\u636E\uFF0C\u518D\u9010\u9879\u6807\u6CE8\u300C\u4E8B\u5B9E / \u4F4E\u7F6E\u4FE1 / \u7F3A\u5931\u300D\uFF1B\u6A21\u7CCA\u8BFB\u6570\u4E0D\u5F97\u5F53\u4E8B\u5B9E\u3002" : "",
10013
+ hasVideo ? `\u89C6\u9891\u4E0D\u8981\u51ED\u7A7A\u731C\u5185\u5BB9\uFF1A\u5148\u7528 ffprobe \u8BFB\u65F6\u957F\uFF0C\u518D\u7528 ffmpeg \u62BD 6-9 \u5F20\u5173\u952E\u5E27\u5230\u9879\u76EE\u76EE\u5F55 frames/\uFF0C\u7136\u540E\u76F4\u63A5\u67E5\u770B\u8FD9\u4E9B\u5E27\u3002\u4F8B\u5982\uFF1Affmpeg -i "<\u89C6\u9891\u8DEF\u5F84>" -vf "fps=1/2,scale=720:-1" frames/f%03d.jpg\uFF1B\u955C\u5934\u53D8\u5316\u5927\u65F6\u53EF\u7528 -vf "select='gt(scene,0.3)',scale=720:-1" -vsync vfr\u3002\u9700\u8981\u53E3\u64AD\u65F6\u518D\u62BD\u97F3\u9891\uFF1Bffmpeg \u4E0D\u53EF\u7528\u5C31\u6362\u4F60\u80FD\u7528\u7684\u672C\u5730\u5DE5\u5177\uFF0C\u5E76\u8BF4\u660E\u3002\u89C6\u9891\u53EA\u80FD\u4F5C\u4E3A\u5185\u5BB9\u516C\u5F0F\u7B49\u7EF4\u5EA6\u7684\u8BC1\u636E\uFF0C\u4E0D\u80FD\u66FF\u4EE3\u8D26\u53F7\u540E\u53F0\u4F5C\u54C1\u6570\u636E\u3002` : "",
10014
+ "",
10015
+ data.author ? `\u4F5C\u8005 / \u8D26\u53F7\uFF1A${data.author}${data.authorId ? `\uFF08${data.authorId}\uFF09` : ""}` : "",
10016
+ data.music ? `\u914D\u4E50\uFF1A${data.music}` : "",
10017
+ statLine ? `\u5DF2\u63D0\u4F9B\u6570\u636E\uFF1A${statLine}` : "",
10018
+ data.notice ? `\u8BFB\u53D6\u63D0\u793A\uFF1A${data.notice}` : "",
10019
+ "",
10020
+ "\u7528\u6237\u8865\u5145\u7684\u6587\u6848\u3001\u6570\u636E\u6216\u8BCA\u65AD\u8BC9\u6C42\uFF1A",
10021
+ String(data.text || data.description || "").slice(0, 6e3) || "\uFF08\u65E0\uFF09",
10022
+ "",
10023
+ "\u4E25\u683C\u6309\u7167 assets/report-template.md \u8F93\u51FA\u5B8C\u6574\u8D26\u53F7\u8BCA\u65AD\u62A5\u544A\uFF0C\u4E0D\u9650\u5236\u4E3A\u7B80\u77ED\u70B9\u8BC4\u3002\u81F3\u5C11\u843D\u5B9E\uFF1A\u4E0D\u8D85\u8FC7 3 \u53E5\u7684\u4E00\u53E5\u8BDD\u7ED3\u8BBA\u3001\u6570\u636E\u4E8B\u5B9E\u4E0E\u7F6E\u4FE1\u5EA6\u3001\u57FA\u7EBF\u6307\u6807\u3001\u5C0F\u65F6\u7EA7\u53D1\u5E03\u65F6\u6BB5\u5206\u6790\u3001\u56DB\u7EF4\u8BCA\u65AD\u3001\u5185\u5BB9\u7C7B\u578B\u5224\u65AD\u3001\u56DB\u8981\u7D20\u9F50\u5168\u4E14\u6709\u51FA\u5904\u7684\u4F18\u5316\u5904\u65B9\u300130 \u5929\u53EF\u9A8C\u6536\u6307\u6807\u3001\u5F85\u8865\u8F93\u5165\u6E05\u5355\u3001\u8FED\u4EE3\u8BB0\u5F55\u3001\u65B9\u6CD5\u8BBA\u6765\u6E90\u6E05\u5355\u3002",
10024
+ "\u4F5C\u54C1\u5217\u8868\u4E0D\u8DB3 5 \u6761\u6216\u5B57\u6BB5\u4E0D\u5168\u65F6\u4ECD\u5148\u8BCA\u65AD\uFF0C\u4F46\u5FC5\u987B\u5728\u300A\u5F85\u8865\u8F93\u5165\u6E05\u5355\u300B\u8BF4\u660E\u5F71\u54CD\uFF1B\u6837\u672C\u4E0D\u8DB3\u4E0D\u5F97\u5F52\u56E0\uFF0C\u6309 SOP \u7ED9\u51FA\u63A7\u5236\u53D8\u91CF\u7684 A/B \u6D4B\u8BD5\u3002\u4E0D\u8981\u8F93\u51FA\u201C\u591A\u53D1\u4F18\u8D28\u5185\u5BB9\u201D\u7B49\u65E0\u51FA\u5904\u5EFA\u8BAE\u3002",
10025
+ "\u6807\u9898\u548C\u6587\u5B57\u8F6C\u5F55\u53EA\u80FD\u8BC1\u660E\u4E3B\u9898\uFF0C\u4E0D\u80FD\u8BC1\u660E\u53E3\u64AD\u3001\u5267\u60C5\u3001\u5B9E\u9645\u5F00\u573A\u6216\u955C\u5934\u8868\u73B0\uFF1B\u5355\u6761\u89C6\u9891\u4E5F\u4E0D\u80FD\u4EE3\u8868\u5168\u90E8\u4F5C\u54C1\u3002\u4F5C\u54C1\u5F62\u6001\u7F3A\u5931\u65F6\uFF0C\u5185\u5BB9\u7C7B\u578B\u53EA\u80FD\u6807\u4E3A\u300C\u6309\u4E3B\u9898\u6682\u5B9A / \u5F62\u6001\u5F85\u9A8C\u8BC1\u300D\uFF0C\u7C7B\u578B\u9650\u5B9A\u5904\u65B9\u53EA\u80FD\u6761\u4EF6\u9002\u7528\uFF0C\u5E76\u628A\u6240\u7F3A\u8BC1\u636E\u5217\u5165\u5F85\u8865\u8F93\u5165\u3002",
10026
+ "\u6807\u9898\u4E2D\u7684\u5E74\u9F84\u3001\u8EAB\u4EFD\u3001\u804C\u4E1A\u3001\u7ECF\u5386\u7B49\u5B57\u9762\u4FE1\u606F\u53EF\u6309\u7F6E\u4FE1\u5EA6\u5F15\u7528\uFF0C\u4F46\u4E0D\u5F97\u6269\u5C55\u6210\u672A\u63D0\u4F9B\u7684\u80CC\u666F\u6545\u4E8B\uFF1B\u5185\u5BB9\u7EBF\u53EA\u80FD\u6309\u5DF2\u6709\u8BC1\u636E\u79F0\u4E3A\u4E3B\u9898 / \u9009\u9898\u7EBF\uFF0C\u4E0D\u80FD\u51ED\u6807\u9898\u5224\u5B9A\u53D9\u4E8B\u5F62\u6001\uFF0C\u793A\u4F8B\u4E3B\u7EBF\u540C\u6837\u4E0D\u5F97\u65B0\u589E\u4EBA\u7269\u7ECF\u5386\u3002",
10027
+ "\u300C\u51E0\u4E4E\u4E3A 0\u300D\u300C\u7EA6\u300D\u7B49\u6982\u8FF0\u4E0D\u662F\u7CBE\u786E\u6570\u503C\u3002\u5047\u8BBE\u60C5\u666F\u8BA1\u7B97\u4E0D\u5F97\u5199\u6210\u4E0A\u754C\u3001\u4E0B\u754C\u6216\u9608\u503C\u5224\u5B9A\u8BC1\u636E\uFF1B\u4E92\u52A8\u7ED3\u679C\u4E0E\u4E92\u52A8\u8BBE\u8BA1\u539F\u56E0\u5FC5\u987B\u5206\u5F00\uFF0C\u8BC1\u636E\u4E0D\u8DB3\u5C31\u6807\u300C\u8BC1\u636E\u4E0D\u5B8C\u6574\u300D\u3002",
10028
+ "A/B \u6D4B\u8BD5\u6BCF\u7EC4 \u22653 \u6761\u4EC5\u7528\u4E8E\u65B9\u5411\u6027\u89C2\u5BDF\uFF0C\u4E0D\u5F97\u636E\u6B64\u8BC1\u660E\u300C\u65F6\u6BB5\u5047\u8BBE\u6210\u7ACB\u300D\u6216\u300C\u65E0\u65F6\u6BB5\u6548\u5E94\u300D\uFF1B\u8FBE\u5230\u6700\u4F4E\u6761\u6570\u4E5F\u4E0D\u7B49\u4E8E\u53EF\u4EE5\u5F52\u56E0\uFF0C\u65F6\u523B\u7CBE\u5EA6\u4E0D\u8DB3\u3001\u4E3B\u9898\u6DF7\u6742\u6216\u63A7\u5236\u53D8\u91CF\u4E0D\u6210\u7ACB\u65F6\u4ECD\u987B\u7EE7\u7EED\u6269\u6837\u3002",
10029
+ "\u6240\u6709\u6D4B\u8BD5\u4E0E\u680F\u76EE\u5FC5\u987B\u505A 30 \u5929\u4EA7\u80FD\u6838\u7B97\uFF1A\u6392\u671F\u6761\u6570\u4E0E\u66F4\u65B0\u9891\u7387\u4E00\u81F4\uFF0C\u4E0D\u540C\u5185\u5BB9\u7C7B\u578B\u4E0D\u5F97\u91CD\u590D\u8BA1\u6570\uFF1B\u5F53\u524D\u4EA7\u80FD\u653E\u4E0D\u4E0B\u65F6\uFF0C\u628A\u9A8C\u8BC1\u7A97\u53E3\u5EF6\u4F38\u5230 60 \u5929\uFF0C\u4E0D\u5F97\u4FDD\u7559\u4E92\u76F8\u51B2\u7A81\u7684\u6570\u91CF\u76EE\u6807\u3002",
10030
+ "\u5E73\u5747\u64AD\u653E\u65F6\u957F\u3001\u5B8C\u64AD\u7387\u300130 \u79D2\u7559\u5B58\u7B49\u5B57\u6BB5\u5404\u81EA\u72EC\u7ACB\uFF0C\u53EA\u8BB0\u5F55\u540E\u53F0\u5B9E\u9645\u63D0\u4F9B\u7684\u5B57\u6BB5\uFF0C\u4E0D\u5F97\u76F8\u4E92\u6362\u7B97\u6216\u865A\u6784\u6307\u6807\u3002\u81EA\u8BBE\u9636\u6BB5\u76EE\u6807\u5FC5\u987B\u6807\u660E\u4E3A\u8D26\u53F7\u7BA1\u7406\u76EE\u6807\uFF0C\u4E0D\u5F97\u5199\u6210\u5BF9\u9F50\u672A\u63D0\u4F9B\u7684\u5B98\u65B9\u6216\u540C\u7C7B\u53C2\u8003\u503C\u3002",
10031
+ "\u65B9\u6CD5\u8BBA\u6765\u6E90\u6E05\u5355\u53EA\u5217\u5904\u65B9\u5E93\u6765\u6E90\u6E05\u5355\u4E2D\u7684\u5B9E\u9645\u5F15\u7528\u9879\uFF1B\u4E0D\u5F97\u65B0\u589E\u300C\u6D41\u91CF\u6C60\u673A\u5236\u300D\u7B49\u65E0\u72EC\u7ACB\u51FA\u5904\u6761\u76EE\uFF0C\u4E5F\u4E0D\u5F97\u628A\u9AD8\u64AD\u653E\u89E3\u91CA\u6210\u5DF2\u8BC1\u5B9E\u7684\u5E73\u53F0\u673A\u5236\u3002",
10032
+ "\u4EA4\u4ED8\u524D\u9010\u9879\u6267\u884C SKILL.md \u7684\u8D28\u91CF\u81EA\u68C0\u6E05\u5355\uFF1B\u53D1\u73B0\u7F3A\u9879\u5148\u4FEE\u6B63\uFF0C\u518D\u4FDD\u5B58\u3002\u53EA\u6839\u636E\u7D20\u6750\u548C\u5DF2\u63D0\u4F9B\u4FE1\u606F\u5224\u65AD\uFF0C\u4E0D\u7F16\u9020\u753B\u9762\u3001\u6570\u5B57\u3001\u4F5C\u8005\u80CC\u666F\u6216\u5E73\u53F0\u673A\u5236\u3002",
10033
+ projectPath ? `\u5B8C\u6210\u540E\u628A\u6700\u7EC8\u5B8C\u6574\u62A5\u544A\u5199\u5165 ${projectPath}/report.md\uFF08UTF-8\u3001\u8986\u76D6\u5199\uFF09\uFF0C\u7136\u540E\u56DE\u590D\u300C\u5DF2\u5199\u5165 report.md\u300D\u3002` : "",
10034
+ media.length ? "\u4E0D\u8981\u4FEE\u6539\u6216\u5220\u9664\u7528\u6237\u4E0A\u4F20\u7684\u7D20\u6750\u3002" : ""
10035
+ ].join("\n").replace(/\n{3,}/g, "\n\n");
10036
+ }
10037
+ function growthError(message, status = 400) {
10038
+ return Object.assign(new Error(message), { status });
10039
+ }
10040
+ function growthKind(value) {
10041
+ const kind = String(value || "");
10042
+ if (!Object.hasOwn(GROWTH_LABELS, kind)) throw growthError("\u672A\u77E5\u7684\u8D26\u53F7\u589E\u957F\u529F\u80FD");
10043
+ return kind;
10044
+ }
10045
+ function growthRecordId(value) {
10046
+ const id = String(value || "");
10047
+ if (!/^[0-9a-f-]{36}$/i.test(id)) throw growthError("\u6863\u6848 ID \u65E0\u6548");
10048
+ return id;
10049
+ }
10050
+ function cleanGrowthInput(kind, raw) {
10051
+ const source = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
10052
+ const text = (key, max) => String(source[key] || "").slice(0, max);
10053
+ if (kind === "research") {
10054
+ return {
10055
+ accounts: text("accounts", 1e3),
10056
+ links: text("links", 4e3),
10057
+ positioning: text("positioning", 4e3),
10058
+ notes: text("notes", 6e3)
10059
+ };
10060
+ }
10061
+ if (kind === "planner") {
10062
+ const startDate = text("startDate", 10);
10063
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(startDate)) throw growthError("\u8BF7\u9009\u62E9\u6709\u6548\u7684\u5F00\u59CB\u65E5\u671F");
10064
+ const frequency = Number(source.frequency ?? 3);
10065
+ if (!Number.isInteger(frequency) || frequency < 1 || frequency > 14) throw growthError("\u6BCF\u5468\u53D1\u5E03\u4E0A\u9650\u987B\u4E3A 1\u201314 \u6761");
10066
+ return {
10067
+ diagnosisId: text("diagnosisId", 80),
10068
+ positioning: text("positioning", 4e3),
10069
+ startDate,
10070
+ frequency,
10071
+ notes: text("notes", 6e3)
10072
+ };
10073
+ }
10074
+ return { baselineId: text("baselineId", 80), currentId: text("currentId", 80), notes: text("notes", 6e3) };
10075
+ }
10076
+ function requireDiagnosisReport(id) {
10077
+ if (!/^[0-9a-f-]{36}$/i.test(String(id || ""))) throw growthError("\u4F53\u68C0\u62A5\u544A ID \u65E0\u6548");
10078
+ const report = diagnoseReports().find((item) => item.id === id);
10079
+ if (!report || !String(report.analysis || "").trim()) throw growthError("\u627E\u4E0D\u5230\u5DF2\u5B8C\u6210\u7684\u4F53\u68C0\u62A5\u544A\uFF0C\u8BF7\u5148\u56DE\u586B\u62A5\u544A");
10080
+ return report;
10081
+ }
10082
+ function growthLinksFromInput(kind, input) {
10083
+ if (kind === "planner") return { diagnosisId: input.diagnosisId || "" };
10084
+ if (kind === "followup") return { baselineId: input.baselineId || "", currentId: input.currentId || "" };
10085
+ return {};
10086
+ }
10087
+ function growthRecordTitle(kind, input) {
10088
+ if (kind === "research") return `${input.accounts.split(/[,,\n]/).map((x) => x.trim()).filter(Boolean)[0] || "\u5BF9\u6807\u8D26\u53F7"} \xB7 \u5BF9\u6807\u8C03\u7814`;
10089
+ if (kind === "planner") {
10090
+ const diagnosis = input.diagnosisId ? diagnoseReports().find((item) => item.id === input.diagnosisId) : null;
10091
+ return `${diagnosis?.title || input.positioning || "\u8D26\u53F7"} \xB7 \u9009\u9898\u89C4\u5212`.slice(0, 100);
10092
+ }
10093
+ const current = input.currentId ? diagnoseReports().find((item) => item.id === input.currentId) : null;
10094
+ return `${current?.title || "\u8D26\u53F7"} \xB7 \u590D\u8BCA\u5BF9\u6BD4`.slice(0, 100);
10095
+ }
10096
+ function growthRecords(kind) {
10097
+ const dir = path14.join(GROWTH_DIR, kind);
10098
+ if (!fs14.existsSync(dir)) return [];
10099
+ const rows = [];
10100
+ for (const name2 of fs14.readdirSync(dir)) {
10101
+ if (!/^[0-9a-f-]{36}\.json$/i.test(name2)) continue;
10102
+ try {
10103
+ const item = JSON.parse(fs14.readFileSync(path14.join(dir, name2), "utf8"));
10104
+ if (item?.id && item?.kind === kind) rows.push(item);
10105
+ } catch {
10106
+ }
10107
+ }
10108
+ return rows.sort((a, b2) => String(b2.createdAt || "").localeCompare(String(a.createdAt || "")));
10109
+ }
10110
+ function findGrowthRecord({ kind = "", id = "", sessionId = "" } = {}) {
10111
+ const kinds = kind ? [growthKind(kind)] : Object.keys(GROWTH_LABELS);
10112
+ for (const itemKind of kinds) {
10113
+ const hit = growthRecords(itemKind).find((item) => id && item.id === id || sessionId && item.sessionId === sessionId);
10114
+ if (hit) return hit;
10115
+ }
10116
+ return null;
10117
+ }
10118
+ function writeGrowthRecord(record) {
10119
+ const raw = JSON.stringify(record);
10120
+ if (Buffer.byteLength(raw) > 128 * 1024) throw growthError("\u62A5\u544A\u592A\u5927\uFF0C\u4FDD\u5B58\u5931\u8D25", 413);
10121
+ const dir = path14.join(GROWTH_DIR, record.kind);
10122
+ fs14.mkdirSync(dir, { recursive: true });
10123
+ const target = path14.join(dir, `${record.id}.json`);
10124
+ const temp = `${target}.tmp`;
10125
+ fs14.writeFileSync(temp, raw, "utf8");
10126
+ fs14.renameSync(temp, target);
10127
+ for (const old of growthRecords(record.kind).slice(60)) {
10128
+ try {
10129
+ fs14.rmSync(path14.join(dir, `${old.id}.json`), { force: true });
10130
+ } catch {
10131
+ }
10132
+ }
10133
+ return record;
10134
+ }
10135
+ function createGrowthRecord(kind, input, extra = {}) {
10136
+ const now = (/* @__PURE__ */ new Date()).toISOString();
10137
+ return writeGrowthRecord({
10138
+ id: crypto8.randomUUID(),
10139
+ kind,
10140
+ title: growthRecordTitle(kind, input),
10141
+ createdAt: now,
10142
+ updatedAt: now,
10143
+ input,
10144
+ analysis: String(extra.analysis || "").slice(0, 4e4),
10145
+ sessionId: String(extra.sessionId || "").slice(0, 100),
10146
+ projectPath: String(extra.projectPath || "").slice(0, 400),
10147
+ media: Array.isArray(extra.media) ? extra.media : [],
10148
+ links: growthLinksFromInput(kind, input)
10149
+ });
10150
+ }
10151
+ function diagnosisContext(report) {
10152
+ return [
10153
+ `# ${report.title || "\u8D26\u53F7\u4F53\u68C0"}`,
10154
+ `\u4F53\u68C0\u65F6\u95F4\uFF1A${report.createdAt || "\u672A\u8BB0\u5F55"}`,
10155
+ `\u8D26\u53F7\u5FEB\u7167\uFF1A${JSON.stringify(report.snapshot || {}).slice(0, 12e3)}`,
10156
+ "",
10157
+ String(report.analysis || "")
10158
+ ].join("\n");
10159
+ }
10160
+ function resolveGrowthContext(kind, input) {
10161
+ if (kind === "research") {
10162
+ if (!String(input.accounts || "").trim()) throw growthError("\u8BF7\u586B\u5199\u81F3\u5C11\u4E00\u4E2A\u5BF9\u6807\u8D26\u53F7\u540D");
10163
+ return {};
10164
+ }
10165
+ if (kind === "planner") {
10166
+ const diagnosis = input.diagnosisId ? requireDiagnosisReport(input.diagnosisId) : null;
10167
+ if (!diagnosis && !String(input.positioning || "").trim()) {
10168
+ throw growthError("\u8BF7\u9009\u62E9\u4F53\u68C0\u62A5\u544A\uFF0C\u6216\u586B\u5199\u8D26\u53F7\u5B9A\u4F4D");
10169
+ }
10170
+ return { diagnosis };
10171
+ }
10172
+ if (!input.baselineId || !input.currentId) throw growthError("\u8BF7\u9009\u62E9\u57FA\u7EBF\u4F53\u68C0\u548C\u672C\u6B21\u4F53\u68C0");
10173
+ if (input.baselineId === input.currentId) throw growthError("\u590D\u8BCA\u9700\u8981\u9009\u62E9\u4E24\u4EFD\u4E0D\u540C\u7684\u4F53\u68C0\u62A5\u544A");
10174
+ return {
10175
+ baseline: requireDiagnosisReport(input.baselineId),
10176
+ current: requireDiagnosisReport(input.currentId)
10177
+ };
10178
+ }
10179
+ function safeReportPath(projectPath) {
10180
+ const root = path14.resolve(DIAGNOSE_SESSIONS_DIR);
10181
+ const dir = path14.resolve(String(projectPath || ""));
10182
+ if (!dir.startsWith(root + path14.sep)) return null;
10183
+ return path14.join(dir, "report.md");
10184
+ }
10185
+ function growthPrompt(kind, input, media = [], linked = {}) {
10186
+ const projectPath = String(linked.projectPath || "");
10187
+ const skillPath = String(linked.skillPath || "");
10188
+ const common = [
10189
+ projectPath ? `\u9879\u76EE\u76EE\u5F55\uFF1A${projectPath}` : "",
10190
+ skillPath ? `\u6280\u80FD\u76EE\u5F55\uFF1A${skillPath}` : "",
10191
+ "\u5F00\u59CB\u524D\u5FC5\u987B\u5B8C\u6574\u9605\u8BFB\u4E0A\u8FF0\u6280\u80FD\u76EE\u5F55\u4E2D\u7684 SKILL.md\uFF0C\u4E25\u683C\u6267\u884C\u5176\u4E2D\u7684\u6D41\u7A0B\u3001\u786C\u6027\u89C4\u5219\u548C\u8D28\u91CF\u81EA\u68C0\u6E05\u5355\u3002",
10192
+ "\u53EA\u4F7F\u7528\u672C\u673A\u7D20\u6750\u3001\u7528\u6237\u8F93\u5165\u548C\u5B9E\u9645\u53EF\u8BBF\u95EE\u7684\u516C\u5F00\u4FE1\u606F\uFF1B\u4E0D\u5F97\u7F16\u9020\u6570\u636E\u3001\u4F5C\u54C1\u3001\u4EBA\u7269\u7ECF\u5386\u3001\u6765\u6E90\u6216\u5E73\u53F0\u673A\u5236\u3002",
10193
+ projectPath ? `\u5B8C\u6210\u540E\u628A\u6700\u7EC8\u5B8C\u6574\u62A5\u544A\u5199\u5165 ${projectPath}/report.md\uFF08UTF-8\u3001\u8986\u76D6\u5199\uFF09\uFF0C\u7136\u540E\u56DE\u590D\u300C\u5DF2\u5199\u5165 report.md\u300D\u3002` : "",
10194
+ media.length ? "\u4E0D\u8981\u4FEE\u6539\u6216\u5220\u9664\u7528\u6237\u4E0A\u4F20\u7684\u7D20\u6750\u3002" : ""
10195
+ ];
10196
+ if (kind === "research") {
10197
+ return [
10198
+ "\u8BF7\u6267\u884C\u4E00\u6B21\u72EC\u7ACB\u7684\u300C\u6296\u97F3\u5BF9\u6807\u8C03\u7814\u300D\uFF0C\u76EE\u6807\u662F\u63D0\u70BC\u53EF\u8FC1\u79FB\u7684\u5185\u5BB9\u7ED3\u6784\uFF0C\u4E0D\u662F\u5199\u8D26\u53F7\u7B80\u4ECB\u6216\u4E3B\u89C2\u5938\u8D5E\u3002",
10199
+ ...common.slice(0, 3),
10200
+ "\u540C\u65F6\u5B8C\u6574\u9605\u8BFB references/research-checklist.md\uFF0C\u5E76\u6309\u5176\u9010\u9879\u6838\u67E5\u3002",
10201
+ "",
10202
+ `\u5BF9\u6807\u8D26\u53F7\uFF1A${input.accounts}`,
10203
+ `\u4E3B\u9875\u6216\u4F5C\u54C1\u94FE\u63A5\uFF1A${input.links || "\uFF08\u672A\u63D0\u4F9B\uFF09"}`,
10204
+ `\u7528\u6237\u81EA\u5DF1\u7684\u8D26\u53F7\u5B9A\u4F4D\uFF1A${input.positioning || "\uFF08\u672A\u63D0\u4F9B\uFF1B\u53EF\u8FC1\u79FB\u6027\u53EA\u80FD\u6807\u4E3A\u5F85\u5224\u65AD\uFF09"}`,
10205
+ `\u8865\u5145\u8BF4\u660E\u4E0E\u771F\u5B9E\u8D44\u6E90\uFF1A${input.notes || "\uFF08\u65E0\uFF09"}`,
10206
+ "",
10207
+ media.length ? "\u7528\u6237\u4E0A\u4F20\u7684\u672C\u673A\u7D20\u6750\uFF1A" : "\u7528\u6237\u6CA1\u6709\u4E0A\u4F20\u622A\u56FE\u6216\u89C6\u9891\uFF1B\u4E0D\u5F97\u865A\u6784\u4F5C\u54C1\u5217\u8868\u548C\u4F5C\u54C1\u6570\u636E\u3002",
10208
+ ...media.map((item, index) => `${index + 1}. ${item.kind === "video" ? "\u89C6\u9891" : "\u56FE\u7247"}\uFF1A${item.path}`),
10209
+ media.some((item) => item.kind === "image") ? "\u6BCF\u5F20\u56FE\u7247\u90FD\u5FC5\u987B\u9010\u5F20\u76F4\u63A5\u67E5\u770B\uFF0C\u63D0\u53D6\u8D26\u53F7\u540D\u3001\u4F5C\u54C1\u6807\u9898\u3001\u53D1\u5E03\u65F6\u95F4\u548C\u53EF\u89C1\u4E92\u52A8\u6570\u636E\uFF0C\u5E76\u6807\u6CE8\u300C\u4E8B\u5B9E / \u4F4E\u7F6E\u4FE1 / \u7F3A\u5931\u300D\u3002" : "",
10210
+ media.some((item) => item.kind === "video") ? "\u6BCF\u4E2A\u89C6\u9891\u5148\u7528 ffprobe \u8BFB\u53D6\u65F6\u957F\uFF0C\u518D\u7528 ffmpeg \u62BD\u53D6 6\u20139 \u5F20\u5173\u952E\u5E27\u5230\u9879\u76EE\u76EE\u5F55 frames/ \u5E76\u9010\u5F20\u67E5\u770B\uFF1B\u9700\u8981\u53E3\u64AD\u8BC1\u636E\u65F6\u518D\u62BD\u97F3\u9891\u3002\u5DE5\u5177\u4E0D\u53EF\u7528\u65F6\u8BF4\u660E\u9650\u5236\uFF0C\u4E0D\u5F97\u731C\u753B\u9762\u3002" : "",
10211
+ "\u5982\u679C\u5177\u5907\u8054\u7F51\u6216\u7F51\u9875\u8BFB\u53D6\u80FD\u529B\uFF0C\u53EF\u8BBF\u95EE\u7528\u6237\u7ED9\u51FA\u7684\u94FE\u63A5\u5E76\u6838\u5B9E\u516C\u5F00\u62A5\u9053\u3001\u8BBF\u8C08\u548C\u672C\u4EBA\u516C\u5F00\u65B9\u6CD5\u8BBA\uFF0C\u9010\u6761\u9644 URL \u4E0E\u53D1\u5E03\u65E5\u671F\uFF1B\u6CA1\u6709\u8054\u7F51\u3001\u8BBF\u95EE\u5931\u8D25\u6216\u53EA\u6709\u8D26\u53F7\u540D\u65F6\uFF0C\u660E\u786E\u5199\u300C\u672C\u6B21\u672A\u6838\u5B9E\u516C\u5F00\u4FE1\u606F\u300D\uFF0C\u4E0D\u5F97\u5047\u88C5\u68C0\u7D22\u8FC7\u3002",
10212
+ "\u4E25\u683C\u533A\u5206\u300C\u516C\u5F00\u4FE1\u606F\uFF08\u9644\u6765\u6E90\u4E0E\u65F6\u95F4\uFF09/ \u4F5C\u54C1\u53EF\u89C1\u4E8B\u5B9E / \u63A8\u65AD / \u672A\u8BC1\u5B9E\u300D\u3002\u770B\u4E0D\u5230\u7684\u540E\u53F0\u6570\u636E\u3001\u6536\u5165\u3001\u56E2\u961F\u89C4\u6A21\u548C\u52A8\u673A\u4E00\u5F8B\u4E0D\u5F97\u63A8\u65AD\u6210\u4E8B\u5B9E\u3002",
10213
+ "\u5148\u6838\u5B9E\u672C\u4EBA\u662F\u5426\u6709\u516C\u5F00\u65B9\u6CD5\u8BBA\uFF1B\u6CA1\u6709\u53EF\u6EAF\u6E90\u65B9\u6CD5\u8BBA\u65F6\uFF0C\u660E\u786E\u964D\u7EA7\u4E3A\u300C\u4ECE\u4F5C\u54C1\u53CD\u63A8\u7684\u7ED3\u6784\u53C2\u8003\u300D\u3002\u8DE8\u5E73\u53F0\u5BF9\u8C61\u5FC5\u987B\u5148\u8BF4\u660E\u4E0E\u6296\u97F3\u7684\u5206\u53D1\u673A\u5236\u5DEE\u5F02\uFF0C\u4E0D\u5F97\u6362\u7B97\u6570\u636E\u8868\u73B0\u3002",
10214
+ "\u62A5\u544A\u5FC5\u987B\u5305\u542B\uFF1A\u4ED6\u662F\u8C01\u3001\u4F5C\u54C1\u6570\u636E\u8868\u3001\u4E94\u7EF4\u5185\u5BB9\u516C\u5F0F\uFF08\u8EAB\u4EFD\u53D9\u4E8B / \u9009\u9898\u6765\u6E90 / \u6807\u9898\u4E0E\u94A9\u5B50 / \u5F62\u5F0F\u4E0E\u8282\u594F / \u5206\u53D1\u4E0E\u53D8\u73B0\uFF0C\u6BCF\u7EF4\u9644\u4F5C\u54C1\u8BC1\u636E\u6216\u6807\u7F3A\u5931\uFF09\u3001\u53EF\u501F\u9274\u4E0E\u4E0D\u53EF\u7167\u642C\u6E05\u5355\u53CA\u8D44\u6E90\u7406\u7531\u3001\u4E0D\u8D85\u8FC7 3 \u6761\u4E0B\u5468\u53EF\u6267\u884C\u8FC1\u79FB\u52A8\u4F5C\u3001\u4FE1\u606F\u53EF\u9760\u6027\u8BF4\u660E\u3002",
10215
+ "\u8FC1\u79FB\u52A8\u4F5C\u5FC5\u987B\u5229\u7528\u7528\u6237\u73B0\u6709\u8D44\u6E90\uFF0C\u5199\u6E05\u7528\u4F55\u79CD\u66FF\u4EE3\u8DEF\u5F84\u8865\u8DB3\u5BF9\u65B9\u72EC\u6709\u8D44\u6E90\uFF1B\u4E0D\u5F97\u5EFA\u8BAE\u590D\u523B\u5177\u4F53\u9009\u9898\u3001\u6587\u6848\u6216\u4EBA\u8BBE\u3002\u8BC1\u636E\u4E0D\u8DB3\u7684\u7EF4\u5EA6\u4FDD\u7559\u7A7A\u7F3A\u5E76\u5217\u5165\u5F85\u8865\u7D20\u6750\u3002",
10216
+ ...common.slice(3)
10217
+ ].join("\n").replace(/\n{3,}/g, "\n\n");
10218
+ }
10219
+ if (kind === "planner") {
10220
+ const diagnosisFile = projectPath ? path14.join(projectPath, "inputs", "diagnosis-report.md") : "";
10221
+ return [
10222
+ "\u8BF7\u6267\u884C\u4E00\u6B21\u300C\u6296\u97F3\u9009\u9898\u89C4\u5212\u300D\uFF0C\u628A\u8D26\u53F7\u5B9A\u4F4D\u4E0E\u4F53\u68C0\u7ED3\u8BBA\u8F6C\u6210\u53EF\u62CD\u6444\u3001\u53EF\u9A8C\u6536\u7684\u771F\u5B9E\u5185\u5BB9\u65E5\u5386\u3002",
10223
+ ...common.slice(0, 3),
10224
+ "\u540C\u65F6\u5B8C\u6574\u9605\u8BFB references/formula-card.md\uFF1B\u5F15\u7528\u8BCA\u65AD\u5904\u65B9\u65F6\uFF0C\u9605\u8BFB\u76F8\u90BB account-diagnosis \u6280\u80FD\u7684 SKILL.md \u4E0E references/prescription-library.md\uFF0C\u4E0D\u5F97\u7F16\u9020\u65B9\u6CD5\u8BBA\u51FA\u5904\u3002",
10225
+ `\u8D26\u53F7\u5B9A\u4F4D\uFF1A${input.positioning || linked.diagnosis?.title || "\uFF08\u4EC5\u4F7F\u7528\u4F53\u68C0\u62A5\u544A\u4E2D\u7684\u5B9A\u4F4D\uFF0C\u7F3A\u5931\u65F6\u5148\u5217\u4E3A\u5F85\u8865\uFF09"}`,
10226
+ `\u5F00\u59CB\u65E5\u671F\uFF1A${input.startDate}`,
10227
+ `\u6BCF\u5468\u53D1\u5E03\u4E0A\u9650\uFF1A${input.frequency} \u6761\uFF08\u4E0D\u5F97\u8D85\u8FC7\uFF1B\u6570\u91CF\u4E0D\u8DB3\u4EE5\u8986\u76D6\u5168\u90E8\u7C7B\u578B\u65F6\u8BF4\u660E\u53D6\u820D\uFF0C\u4E0D\u5F97\u5077\u5077\u52A0\u91CF\uFF09`,
10228
+ `\u7528\u6237\u8865\u5145\u7684\u771F\u5B9E\u7D20\u6750\u3001\u65E5\u7A0B\u4E0E\u7EA6\u675F\uFF1A${input.notes || "\uFF08\u65E0\uFF1B\u4E0D\u5F97\u56E0\u6B64\u7F16\u9020\u53EF\u62CD\u4E8B\u4EF6\uFF09"}`,
10229
+ "",
10230
+ linked.diagnosis ? `\u5DF2\u5173\u8054\u4F53\u68C0\u62A5\u544A\uFF0C\u5168\u6587\u540C\u65F6\u4FDD\u5B58\u4E8E ${diagnosisFile}\uFF1B\u5FC5\u987B\u5148\u8BFB\u53D6\u8BE5\u6587\u4EF6\u3002\u4EE5\u4E0B\u4E3A\u540C\u4E00\u4EFD\u4F53\u68C0\u5168\u6587\uFF1A` : "\u672C\u6B21\u672A\u5173\u8054\u4F53\u68C0\u62A5\u544A\uFF0C\u53EA\u80FD\u4F9D\u636E\u4E0A\u65B9\u5B9A\u4F4D\u548C\u771F\u5B9E\u8865\u5145\u4FE1\u606F\u89C4\u5212\u3002",
10231
+ linked.diagnosis ? diagnosisContext(linked.diagnosis) : "",
10232
+ "",
10233
+ "\u4F53\u68C0\u4E2D\u7684\u7ED3\u8BBA\u987B\u843D\u5B9E\u5230\u9009\u9898\u8BBE\u8BA1\u903B\u8F91\uFF1A\u8BF4\u660E\u6BCF\u6761\u9009\u9898\u54CD\u5E94\u4E86\u54EA\u9879\u53D1\u73B0\u6216\u5904\u65B9\uFF1B\u4F53\u68C0\u540C\u6837\u8BC1\u636E\u4E0D\u8DB3\u7684\u7ED3\u8BBA\u4E0D\u5F97\u5F53\u6210\u4E8B\u5B9E\u653E\u5927\u3002",
10234
+ "\u6BCF\u6761\u9009\u9898\u5FC5\u987B\u7ED1\u5B9A\u7528\u6237\u771F\u5B9E\u5728\u505A\u7684\u4E8B\u3001\u771F\u5B9E\u53EF\u62CD\u4E8B\u4EF6\u6216\u771F\u5B9E\u516C\u5F00\u4FE1\u606F\uFF0C\u6CE8\u660E\u7D20\u6750\u6765\u6E90\uFF1B\u6CA1\u6709\u7D20\u6750\u5C31\u653E\u5165\u300C\u7D20\u6750\u5F85\u8865\u6E05\u5355\u300D\uFF0C\u4E0D\u5F97\u7F16\u9020\u7ECF\u5386\u3001\u4EA7\u54C1\u3001\u8BA2\u5355\u6216\u62CD\u6444\u6761\u4EF6\u3002",
10235
+ "\u8F93\u51FA\uFF1A\u5B9A\u4F4D\u590D\u8FF0\u4E0E\u672C\u5468\u7EA6\u675F\u3001\u4ECE\u5F00\u59CB\u65E5\u671F\u8D77\u7684\u4E00\u5468\u9009\u9898\u8868\uFF08\u65E5\u671F / \u6781\u7AEF\u5316\u6807\u9898 / 3 \u79D2\u94A9\u5B50 / \u5F62\u5F0F / \u7C7B\u578B / \u771F\u5B9E\u7D20\u6750\u6765\u6E90 / \u8BBE\u8BA1\u903B\u8F91\u4E0E\u51FA\u5904 / \u7ED3\u5C3E\u4E92\u52A8\u94A9\u5B50\uFF09\u3001\u9010\u6761\u516C\u5F0F\u5361\u3001\u672C\u5468\u6307\u6807\u4E0E\u68C0\u67E5\u70B9\u3001\u7D20\u6750\u5F85\u8865\u6E05\u5355\u3002",
10236
+ "\u81F3\u5C11\u5305\u542B 1 \u6761\u641C\u7D22\u9700\u6C42\u578B\u9009\u9898\uFF1B\u6709\u771F\u5B9E\u5728\u63A8\u8FDB\u7684\u4EA7\u54C1\u6216\u9879\u76EE\u65F6\u624D\u5B89\u6392\u4EA7\u54C1\u5C55\u793A\u578B\u3002\u6BCF\u6761\u516C\u5F0F\u5361\u5199\u5168\u6781\u7AEF\u5316\u6807\u9898\u30013 \u79D2\u94A9\u5B50\u3001\u5C71\u6D1E\u3001\u51B2\u7A81\u3001\u627F\u8BFA\u5151\u73B0\u3002\u6807\u660E A/B \u6D4B\u8BD5\u578B\u9009\u9898\uFF0C\u4F46\u4E0D\u5F97\u628A\u5C0F\u6837\u672C\u65B9\u5411\u89C2\u5BDF\u5199\u6210\u5DF2\u8BC1\u5B9E\u7ED3\u8BBA\u3002",
10237
+ "\u6392\u671F\u603B\u6761\u6570\u4E0D\u5F97\u8D85\u8FC7\u6BCF\u5468\u4E0A\u9650\uFF0C\u987B\u6838\u7B97\u7528\u6237\u4EA7\u80FD\uFF1B\u6240\u6709\u6307\u6807\u5206\u4E3A\u300C\u540E\u53F0\u5DF2\u6709\u57FA\u7EBF / \u81EA\u8BBE\u7BA1\u7406\u76EE\u6807 / \u5F85\u8865\u300D\uFF0C\u4E0D\u5F97\u865A\u6784\u540C\u7C7B\u6216\u5B98\u65B9\u53C2\u8003\u503C\u3002",
10238
+ ...common.slice(3)
10239
+ ].join("\n").replace(/\n{3,}/g, "\n\n");
10240
+ }
10241
+ const baselineFile = projectPath ? path14.join(projectPath, "inputs", "baseline-report.md") : "";
10242
+ const currentFile = projectPath ? path14.join(projectPath, "inputs", "current-report.md") : "";
10243
+ return [
10244
+ "\u8BF7\u6267\u884C\u4E00\u6B21\u300C\u8D26\u53F7\u590D\u8BCA\u5BF9\u6BD4\u300D\uFF1A\u5BF9\u7167\u6B64\u524D\u4E0E\u672C\u6B21\u4E24\u6B21\u4F53\u68C0\uFF0C\u5224\u65AD\u53D8\u5316\u3001\u5904\u65B9\u6267\u884C\u60C5\u51B5\u548C\u4E0B\u4E00\u6B65\uFF0C\u4E0D\u8981\u91CD\u65B0\u5199\u4E24\u4EFD\u4E92\u4E0D\u76F8\u5E72\u7684\u4F53\u68C0\u3002",
10245
+ ...common.slice(0, 3),
10246
+ "\u540C\u65F6\u9605\u8BFB references/diagnosis-framework.md \u4E0E references/prescription-library.md\uFF1B\u5904\u65B9\u53EA\u80FD\u6CBF\u7528\u53EF\u6EAF\u6E90\u6765\u6E90\uFF0C\u4E0D\u5F97\u81EA\u884C\u7F16\u9020\u51FA\u5904\u3002",
10247
+ `\u8865\u5145\u8BF4\u660E\uFF1A${input.notes || "\uFF08\u65E0\uFF09"}`,
10248
+ "",
10249
+ `\u57FA\u7EBF\u4F53\u68C0\u5168\u6587\u5DF2\u4FDD\u5B58\u4E8E ${baselineFile}\uFF0C\u672C\u6B21\u4F53\u68C0\u5168\u6587\u5DF2\u4FDD\u5B58\u4E8E ${currentFile}\uFF1B\u5FC5\u987B\u5148\u8BFB\u53D6\u4E24\u4EFD\u6587\u4EF6\u3002\u4EE5\u4E0B\u4F9D\u6B21\u5D4C\u5165\u76F8\u540C\u5168\u6587\uFF1A`,
10250
+ "===== \u57FA\u7EBF\u4F53\u68C0\uFF08\u6B64\u524D\uFF09 =====",
10251
+ diagnosisContext(linked.baseline),
10252
+ "===== \u672C\u6B21\u4F53\u68C0\uFF08\u6700\u8FD1\uFF09 =====",
10253
+ diagnosisContext(linked.current),
10254
+ "",
10255
+ "\u5148\u5217\u51FA\u4E24\u4EFD\u62A5\u544A\u7684\u4F53\u68C0\u65F6\u95F4\u3001\u6837\u672C\u8303\u56F4\u3001\u6570\u636E\u5B57\u6BB5\u548C\u7EDF\u8BA1\u53E3\u5F84\u3002\u53EA\u6BD4\u8F83\u4E24\u8FB9\u90FD\u5B9E\u9645\u5B58\u5728\u4E14\u5B9A\u4E49\u3001\u5355\u4F4D\u3001\u65F6\u95F4\u7A97\u53E3\u548C\u6837\u672C\u8303\u56F4\u4E00\u81F4\u7684\u6307\u6807\uFF1B\u5C55\u793A\u539F\u59CB\u503C\uFF0C\u518D\u8BA1\u7B97\u53D8\u5316\u503C\u6216\u53D8\u5316\u7387\u3002\u9664\u6570\u4E3A\u96F6\u6216\u4EFB\u4E00\u7AEF\u7F3A\u5931\u65F6\u4E0D\u7B97\u53D8\u5316\u7387\u3002",
10256
+ "\u4E0D\u540C\u5B57\u6BB5\u4E0D\u5F97\u4E92\u76F8\u6362\u7B97\uFF08\u5982\u5E73\u5747\u64AD\u653E\u65F6\u957F\u3001\u5B8C\u64AD\u7387\u300130 \u79D2\u7559\u5B58\uFF09\uFF1B\u4E0D\u540C\u6837\u672C\u91CF\u4E0D\u5F97\u76F4\u63A5\u62FC\u5E73\u5747\uFF0C\u4E0D\u540C\u53E3\u5F84\u4E0D\u5F97\u8BA1\u7B97\u3002\u65E0\u6CD5\u5BF9\u7167\u7684\u9879\u76EE\u7EDF\u4E00\u6807\u4E3A\u300C\u4E0D\u53EF\u6BD4\uFF1A\u7F3A\u5B57\u6BB5 / \u53E3\u5F84\u4E0D\u540C / \u6837\u672C\u4E0D\u540C\u300D\uFF0C\u4E0D\u5F97\u865A\u6784\u6570\u503C\u6216\u628A\u76F8\u5173\u6027\u5199\u6210\u56E0\u679C\u3002",
10257
+ "\u82E5\u62A5\u544A\u65E5\u671F\u6216\u57FA\u7EBF\uFF0F\u672C\u6B21\u987A\u5E8F\u770B\u8D77\u6765\u4E0D\u4E00\u81F4\uFF0C\u660E\u786E\u6307\u51FA\uFF0C\u4E0D\u5F97\u64C5\u81EA\u4EA4\u6362\u6216\u63A9\u76D6\u3002\u6807\u9898\u548C\u6587\u5B57\u8F6C\u5F55\u4ECD\u4E0D\u80FD\u8BC1\u660E\u672A\u63D0\u4F9B\u7684\u753B\u9762\u4E0E\u53E3\u64AD\u3002",
10258
+ "\u62A5\u544A\u5FC5\u987B\u5305\u542B\uFF1A\u6838\u5FC3\u7ED3\u8BBA\u3001\u540C\u53E3\u5F84\u6307\u6807\u5BF9\u7167\u8868\u3001\u5185\u5BB9\u7EBF\u4E0E\u53D1\u5E03\u6267\u884C\u53D8\u5316\u3001\u57FA\u7EBF\u5904\u65B9\u7684\u9010\u9879\u590D\u6838\uFF08\u4FDD\u7559 / \u505C\u6B62 / \u65B0\u589E\u53CA\u8BC1\u636E\uFF09\u3001\u4E0B\u4E00\u8F6E\u4E0D\u8D85\u8FC7 3 \u9879\u4F18\u5148\u52A8\u4F5C\u300130 \u5929\u9A8C\u6536\u6307\u6807\u4E0E\u68C0\u67E5\u70B9\u3001\u5F85\u8865\u8F93\u5165\u6E05\u5355\u3002",
10259
+ "\u4FDD\u7559\u3001\u505C\u6B62\u3001\u65B0\u589E\u90FD\u8981\u8BF4\u660E\u4F9D\u636E\uFF1B\u6CA1\u6709\u6267\u884C\u8BC1\u636E\u65F6\u6807\u300C\u6267\u884C\u5F85\u6838\u5B9E\u300D\uFF0C\u4E0D\u5F97\u5BA3\u79F0\u5904\u65B9\u6709\u6548\u6216\u65E0\u6548\u300230 \u5929\u76EE\u6807\u9700\u4E0E\u53D1\u5E03\u9891\u7387\u548C\u4EA7\u80FD\u4E00\u81F4\uFF0C\u81EA\u8BBE\u76EE\u6807\u987B\u660E\u786E\u6807\u6CE8\u3002",
10260
+ ...common.slice(3)
10261
+ ].join("\n").replace(/\n{3,}/g, "\n\n");
10262
+ }
9715
10263
  async function stateAsync() {
9716
10264
  await refreshTrialRuns();
9717
10265
  reconcileOrphanTasks();
@@ -9753,6 +10301,7 @@ function createPanelApp(options = {}) {
9753
10301
  store: storeView,
9754
10302
  license: license.status(),
9755
10303
  licenses: license.listProducts(),
10304
+ member: memberInfo(),
9756
10305
  buyUrl: buyPageUrl(),
9757
10306
  licenseBaseUrl: settings.licenseBaseUrl,
9758
10307
  trialRuns,
@@ -9794,6 +10343,7 @@ function createPanelApp(options = {}) {
9794
10343
  store: [],
9795
10344
  license: license.status(),
9796
10345
  licenses: license.listProducts(),
10346
+ member: memberInfo(),
9797
10347
  buyUrl: buyPageUrl(),
9798
10348
  licenseBaseUrl: settings.licenseBaseUrl,
9799
10349
  trialRuns,
@@ -9819,10 +10369,58 @@ function createPanelApp(options = {}) {
9819
10369
  };
9820
10370
  }
9821
10371
  let campaignCache = { at: 0, items: [] };
10372
+ function ownedCampaignProducts() {
10373
+ const owned = /* @__PURE__ */ new Set();
10374
+ for (const item of license.listProducts()) {
10375
+ if (item.status && item.status.canExport) owned.add(item.product);
10376
+ }
10377
+ return owned;
10378
+ }
10379
+ const TIER_SINGLE = 99;
10380
+ const TIER_PLUS = 159;
10381
+ const TIER_MAX = 229;
10382
+ function campaignTier(item) {
10383
+ const explicit = Number(item.tier) || 0;
10384
+ if (explicit) return explicit;
10385
+ const price = Number(item.price) || 0;
10386
+ if (price >= 200) return TIER_MAX;
10387
+ if (price >= 130) return TIER_PLUS;
10388
+ return TIER_SINGLE;
10389
+ }
10390
+ function hasResellerMark() {
10391
+ if (resellerCode()) return true;
10392
+ for (const item of license.listProducts()) {
10393
+ const cache = license.readCache(item.product);
10394
+ const code = cache && cache.entitlements && cache.entitlements.resellerCode;
10395
+ if (code) return true;
10396
+ }
10397
+ return false;
10398
+ }
10399
+ function currentTier() {
10400
+ if (hasResellerMark()) return TIER_MAX;
10401
+ const active = license.listProducts().filter((item) => item.status && item.status.canExport);
10402
+ if (!active.length) return 0;
10403
+ if (active.some((item) => String(item.product || "").startsWith("biupro"))) return TIER_PLUS;
10404
+ return TIER_SINGLE;
10405
+ }
10406
+ function filterCampaigns(items) {
10407
+ const tier = currentTier();
10408
+ if (!tier) return items;
10409
+ if (tier >= TIER_MAX) return [];
10410
+ if (tier === TIER_PLUS) return items.filter((item) => campaignTier(item) >= TIER_MAX);
10411
+ const owned = ownedCampaignProducts();
10412
+ return items.filter((item) => {
10413
+ const level = campaignTier(item);
10414
+ const slugs = (item.items || []).map((entry) => entry.productSlug).filter(Boolean);
10415
+ if (!slugs.length) return true;
10416
+ if (level >= TIER_PLUS) return true;
10417
+ return !slugs.every((slug) => owned.has(slug));
10418
+ });
10419
+ }
9822
10420
  async function loadPublicCampaigns() {
9823
- if (resellerCode || license.canExport()) return [];
10421
+ if (hasResellerMark()) return [];
9824
10422
  const now = Date.now();
9825
- if (now - campaignCache.at < 6e4) return campaignCache.items;
10423
+ if (now - campaignCache.at < 6e4) return filterCampaigns(campaignCache.items);
9826
10424
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9827
10425
  if (!base) {
9828
10426
  campaignCache = { at: now, items: [] };
@@ -9842,17 +10440,29 @@ function createPanelApp(options = {}) {
9842
10440
  compareAt: Number(item.compareAt) || 0,
9843
10441
  gradient: String(item.gradient || "lime"),
9844
10442
  kind: item.kind === "link" ? "link" : "sale",
9845
- linkUrl: String(item.linkUrl || "")
10443
+ linkUrl: String(item.linkUrl || ""),
10444
+ items: (Array.isArray(item.items) ? item.items : []).map((entry) => ({ productSlug: String(entry && entry.productSlug || "") })).filter((entry) => entry.productSlug)
9846
10445
  })).filter((item) => item.slug && item.name);
9847
10446
  campaignCache = { at: now, items };
9848
- return items;
10447
+ return filterCampaigns(items);
9849
10448
  } catch {
9850
10449
  campaignCache = { at: now, items: campaignCache.items };
9851
- return campaignCache.items;
10450
+ return filterCampaigns(campaignCache.items);
9852
10451
  }
9853
10452
  }
9854
10453
  let showcaseCache = { at: 0, promptsEnabled: false, cases: [], tutorials: [] };
9855
10454
  let docsCache = { at: 0, items: [] };
10455
+ function docsToken() {
10456
+ try {
10457
+ const active = license.listProducts().filter((item) => item.status && item.status.canExport);
10458
+ for (const item of active) {
10459
+ const token = license.tokenFor(item.product);
10460
+ if (token) return token;
10461
+ }
10462
+ } catch {
10463
+ }
10464
+ return "";
10465
+ }
9856
10466
  async function loadPublicDocs() {
9857
10467
  const now = Date.now();
9858
10468
  if (now - docsCache.at < 6e4) return docsCache.items;
@@ -9862,14 +10472,22 @@ function createPanelApp(options = {}) {
9862
10472
  return docsCache.items;
9863
10473
  }
9864
10474
  try {
9865
- const res = await fetch(`${base}/v1/docs`, { signal: AbortSignal.timeout(4e3) });
10475
+ const token = docsToken();
10476
+ const res = await fetch(`${base}/v1/docs`, {
10477
+ headers: token ? { "x-license-token": token } : void 0,
10478
+ signal: AbortSignal.timeout(4e3)
10479
+ });
9866
10480
  const data = await res.json().catch(() => ({}));
9867
10481
  if (!res.ok) throw new Error("docs unavailable");
9868
10482
  const items = (Array.isArray(data.docs) ? data.docs : []).map((item) => ({
9869
10483
  id: String(item.id || ""),
9870
10484
  title: String(item.title || ""),
9871
- url: String(item.url || "")
9872
- })).filter((item) => item.id && /^https?:\/\//i.test(item.url));
10485
+ url: String(item.url || ""),
10486
+ content: String(item.content || ""),
10487
+ manualKey: String(item.manualKey || ""),
10488
+ access: item.access === "member" || item.access === "pro" ? item.access : "free",
10489
+ locked: !!item.locked
10490
+ })).filter((item) => item.id && (item.content || /^https?:\/\//i.test(item.url) || item.locked));
9873
10491
  docsCache = { at: now, items };
9874
10492
  return items;
9875
10493
  } catch {
@@ -9992,6 +10610,7 @@ function createPanelApp(options = {}) {
9992
10610
  }
9993
10611
  async function handle(req, res, pathname) {
9994
10612
  const route = `${req.method} ${pathname}`;
10613
+ const query = new URL(req.url ?? "/", "http://local").searchParams;
9995
10614
  if (req.method === "GET" && pathname.startsWith("/icons/")) {
9996
10615
  const raw = pathname.slice("/icons/".length).replace(/[^a-zA-Z0-9._-]/g, "");
9997
10616
  const base = raw.replace(/\.(png|svg|webp)$/i, "") || "app";
@@ -10006,6 +10625,9 @@ function createPanelApp(options = {}) {
10006
10625
  res.writeHead(200, { "content-type": "image/svg+xml; charset=utf-8", "cache-control": "no-store" });
10007
10626
  return void res.end(placeholderIcon(base));
10008
10627
  }
10628
+ if (req.method === "GET" && pathname.startsWith("/diagnose/media/")) {
10629
+ return serveDiagnoseMedia(req, res, pathname.slice("/diagnose/media/".length).replace(/[^0-9a-f-]/gi, ""));
10630
+ }
10009
10631
  switch (route) {
10010
10632
  case "GET /state":
10011
10633
  return send(res, 200, await stateAsync());
@@ -10040,6 +10662,236 @@ function createPanelApp(options = {}) {
10040
10662
  });
10041
10663
  return void res.end(buf);
10042
10664
  }
10665
+ case "POST /diagnose/upload": {
10666
+ try {
10667
+ return send(res, 200, { media: await saveDiagnoseUpload(req, query) });
10668
+ } catch (error) {
10669
+ return send(res, error.status || 502, { error: error.message || "\u4E0A\u4F20\u5931\u8D25" });
10670
+ }
10671
+ }
10672
+ case "POST /diagnose/session": {
10673
+ try {
10674
+ assertDiagnoseMember();
10675
+ const body = await readJson(req);
10676
+ const media = normalizeDiagnoseMedia(body.media);
10677
+ if ((!body.snapshot || typeof body.snapshot !== "object") && !media.length) {
10678
+ return send(res, 400, { error: "\u8BF7\u5148\u4E0A\u4F20\u540E\u53F0\u622A\u56FE\u6216\u89C6\u9891" });
10679
+ }
10680
+ const snapshot = body.snapshot && typeof body.snapshot === "object" ? body.snapshot : { title: media[0].name, kind: "upload", media: media.map((item) => item.name) };
10681
+ const projectPath = path14.join(DIAGNOSE_SESSIONS_DIR, crypto8.randomUUID());
10682
+ fs14.mkdirSync(projectPath, { recursive: true });
10683
+ const sessionMedia = materializeDiagnoseMedia(projectPath, media);
10684
+ const skillPath = seedDiagnoseSkill(projectPath);
10685
+ const promptText = diagnosePrompt(snapshot, { media: sessionMedia, projectPath, skillPath });
10686
+ if (!dsh?.chat?.startPromptRun) {
10687
+ return send(res, 503, { error: "\u5F53\u524D\u73AF\u5883\u4E0D\u80FD\u76F4\u63A5\u5F00 DSH \u4F1A\u8BDD\uFF0C\u53EF\u4EE5\u590D\u5236\u63D0\u793A\u8BCD\u5230\u4EFB\u610F\u6A21\u578B", promptText });
10688
+ }
10689
+ const result = await dsh.chat.startPromptRun({
10690
+ agentId: "bn-diagnose",
10691
+ skill: "diagnose",
10692
+ title: "\u8D26\u53F7\u8BCA\u65AD \xB7 " + String(snapshot.title || "\u672A\u547D\u540D").slice(0, 40),
10693
+ promptText,
10694
+ projectPath
10695
+ });
10696
+ if (!result.ok) {
10697
+ return send(res, 502, { error: result.error || "\u5F00\u4E0D\u4E86 DSH \u4F1A\u8BDD\uFF0C\u53EF\u4EE5\u590D\u5236\u63D0\u793A\u8BCD\u5230\u4EFB\u610F\u6A21\u578B", promptText });
10698
+ }
10699
+ return send(res, 200, {
10700
+ ok: true,
10701
+ sessionId: result.sessionId,
10702
+ projectPath,
10703
+ media: media.map(({ path: _path, ...rest }) => rest),
10704
+ promptText
10705
+ });
10706
+ } catch (error) {
10707
+ return send(res, error.status || 502, { error: error.message || "\u5F00\u4E0D\u4E86 DSH \u4F1A\u8BDD" });
10708
+ }
10709
+ }
10710
+ case "GET /diagnose/session-report": {
10711
+ try {
10712
+ assertDiagnoseMember();
10713
+ const sessionId = String(query.get("sessionId") || "");
10714
+ if (!sessionId) return send(res, 400, { error: "\u7F3A\u5C11 sessionId" });
10715
+ const report = diagnoseReports().find((item) => item.sessionId === sessionId);
10716
+ if (!report) return send(res, 404, { error: "\u8FD8\u6CA1\u6709\u5B58\u6863", pending: true });
10717
+ const file = safeReportPath(report.projectPath);
10718
+ if (!file) return send(res, 400, { error: "\u62A5\u544A\u7F3A\u5C11\u6709\u6548\u7684\u4F1A\u8BDD\u76EE\u5F55" });
10719
+ if (!fs14.existsSync(file)) return send(res, 200, { pending: true, report });
10720
+ if (fs14.statSync(file).size > 256 * 1024) return send(res, 413, { error: "\u62A5\u544A\u6587\u4EF6\u592A\u5927" });
10721
+ const analysis = fs14.readFileSync(file, "utf8").slice(0, 2e4);
10722
+ if (analysis !== report.analysis) {
10723
+ report.analysis = analysis;
10724
+ report.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
10725
+ fs14.writeFileSync(path14.join(DIAGNOSE_DIR, `${report.id}.json`), JSON.stringify(report), "utf8");
10726
+ }
10727
+ return send(res, 200, { report });
10728
+ } catch (error) {
10729
+ return send(res, error.status || 500, { error: error.message || "\u8BFB\u53D6\u5931\u8D25" });
10730
+ }
10731
+ }
10732
+ case "GET /diagnose/reports":
10733
+ assertDiagnoseMember();
10734
+ return send(res, 200, { reports: diagnoseReports().slice(0, 50) });
10735
+ case "POST /diagnose/reports": {
10736
+ assertDiagnoseMember();
10737
+ const body = await readJson(req);
10738
+ if (!body.snapshot || typeof body.snapshot !== "object") {
10739
+ return send(res, 400, { error: "\u6CA1\u6709\u53EF\u4FDD\u5B58\u7684\u62A5\u544A" });
10740
+ }
10741
+ try {
10742
+ return send(res, 200, {
10743
+ report: saveDiagnoseReport(body.snapshot, body.analysis, body.sessionId, {
10744
+ projectPath: body.projectPath,
10745
+ media: body.media
10746
+ })
10747
+ });
10748
+ } catch (error) {
10749
+ return send(res, error.status || 500, { error: error.message || "\u4FDD\u5B58\u5931\u8D25" });
10750
+ }
10751
+ }
10752
+ case "POST /diagnose/reports/delete": {
10753
+ assertDiagnoseMember();
10754
+ const body = await readJson(req);
10755
+ const id = String(body.id || "");
10756
+ if (!/^[a-zA-Z0-9-]{8,64}$/.test(id)) return send(res, 400, { error: "\u62A5\u544A\u4E0D\u5B58\u5728" });
10757
+ fs14.rmSync(path14.join(DIAGNOSE_DIR, `${id}.json`), { force: true });
10758
+ return send(res, 200, { ok: true });
10759
+ }
10760
+ case "POST /growth/session": {
10761
+ let promptText = "";
10762
+ try {
10763
+ assertDiagnoseMember();
10764
+ const body = await readJson(req);
10765
+ const kind = growthKind(body.kind);
10766
+ const input = cleanGrowthInput(kind, body.input);
10767
+ const linked = resolveGrowthContext(kind, input);
10768
+ const projectPath = path14.join(DIAGNOSE_SESSIONS_DIR, crypto8.randomUUID());
10769
+ fs14.mkdirSync(projectPath, { recursive: true });
10770
+ const media = kind === "research" ? normalizeDiagnoseMedia(body.media) : [];
10771
+ const sessionMedia = materializeDiagnoseMedia(projectPath, media);
10772
+ let skillPath;
10773
+ if (kind === "research") {
10774
+ skillPath = seedDiagnoseSkill(projectPath, "creator-research");
10775
+ } else if (kind === "planner") {
10776
+ skillPath = seedDiagnoseSkill(projectPath, "topic-planner");
10777
+ seedDiagnoseSkill(projectPath, "account-diagnosis");
10778
+ if (linked.diagnosis) {
10779
+ const inputsDir = path14.join(projectPath, "inputs");
10780
+ fs14.mkdirSync(inputsDir, { recursive: true });
10781
+ fs14.writeFileSync(path14.join(inputsDir, "diagnosis-report.md"), diagnosisContext(linked.diagnosis), "utf8");
10782
+ }
10783
+ } else {
10784
+ skillPath = seedDiagnoseSkill(projectPath, "account-diagnosis");
10785
+ const inputsDir = path14.join(projectPath, "inputs");
10786
+ fs14.mkdirSync(inputsDir, { recursive: true });
10787
+ fs14.writeFileSync(path14.join(inputsDir, "baseline-report.md"), diagnosisContext(linked.baseline), "utf8");
10788
+ fs14.writeFileSync(path14.join(inputsDir, "current-report.md"), diagnosisContext(linked.current), "utf8");
10789
+ }
10790
+ promptText = growthPrompt(kind, input, sessionMedia, { ...linked, projectPath, skillPath });
10791
+ if (!dsh?.chat?.startPromptRun) {
10792
+ return send(res, 503, { error: "\u5F53\u524D\u73AF\u5883\u4E0D\u80FD\u76F4\u63A5\u5F00 DSH \u4F1A\u8BDD\uFF0C\u53EF\u4EE5\u590D\u5236\u63D0\u793A\u8BCD\u5230\u4EFB\u610F\u6A21\u578B", promptText });
10793
+ }
10794
+ const result = await dsh.chat.startPromptRun({
10795
+ agentId: "bn-diagnose",
10796
+ skill: "diagnose",
10797
+ title: `${GROWTH_LABELS[kind]} \xB7 ${growthRecordTitle(kind, input)}`.slice(0, 80),
10798
+ promptText,
10799
+ projectPath
10800
+ });
10801
+ if (!result.ok) {
10802
+ return send(res, 502, { error: result.error || "\u5F00\u4E0D\u4E86 DSH \u4F1A\u8BDD\uFF0C\u53EF\u4EE5\u590D\u5236\u63D0\u793A\u8BCD\u5230\u4EFB\u610F\u6A21\u578B", promptText });
10803
+ }
10804
+ const recordMedia = sessionMedia.map(({ path: _path, ...rest }) => rest);
10805
+ const record = createGrowthRecord(kind, input, {
10806
+ sessionId: result.sessionId,
10807
+ projectPath,
10808
+ media: recordMedia
10809
+ });
10810
+ return send(res, 200, {
10811
+ ok: true,
10812
+ sessionId: result.sessionId,
10813
+ projectPath,
10814
+ promptText,
10815
+ record,
10816
+ media: recordMedia
10817
+ });
10818
+ } catch (error) {
10819
+ return send(res, error.status || 502, { error: error.message || "\u5F00\u4E0D\u4E86 DSH \u4F1A\u8BDD", promptText });
10820
+ }
10821
+ }
10822
+ case "GET /growth/session-report": {
10823
+ try {
10824
+ assertDiagnoseMember();
10825
+ const sessionId = String(query.get("sessionId") || "");
10826
+ if (!sessionId) return send(res, 400, { error: "\u7F3A\u5C11 sessionId" });
10827
+ const report = findGrowthRecord({ sessionId });
10828
+ if (!report) return send(res, 404, { error: "\u8FD8\u6CA1\u6709\u5B58\u6863", pending: true });
10829
+ const file = safeReportPath(report.projectPath);
10830
+ if (!file) return send(res, 400, { error: "\u62A5\u544A\u7F3A\u5C11\u6709\u6548\u7684\u4F1A\u8BDD\u76EE\u5F55" });
10831
+ if (!fs14.existsSync(file)) return send(res, 200, { pending: true, report });
10832
+ if (fs14.statSync(file).size > 256 * 1024) return send(res, 413, { error: "\u62A5\u544A\u6587\u4EF6\u592A\u5927" });
10833
+ const analysis = fs14.readFileSync(file, "utf8").slice(0, 4e4);
10834
+ if (analysis !== report.analysis) {
10835
+ report.analysis = analysis;
10836
+ report.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
10837
+ writeGrowthRecord(report);
10838
+ }
10839
+ return send(res, 200, { report });
10840
+ } catch (error) {
10841
+ return send(res, error.status || 500, { error: error.message || "\u8BFB\u53D6\u5931\u8D25" });
10842
+ }
10843
+ }
10844
+ case "GET /growth/reports": {
10845
+ try {
10846
+ assertDiagnoseMember();
10847
+ const kind = growthKind(query.get("kind"));
10848
+ return send(res, 200, { reports: growthRecords(kind).slice(0, 60) });
10849
+ } catch (error) {
10850
+ return send(res, error.status || 500, { error: error.message || "\u8BFB\u53D6\u5931\u8D25" });
10851
+ }
10852
+ }
10853
+ case "POST /growth/reports": {
10854
+ try {
10855
+ assertDiagnoseMember();
10856
+ const body = await readJson(req);
10857
+ const kind = growthKind(body.kind);
10858
+ const input = cleanGrowthInput(kind, body.input);
10859
+ resolveGrowthContext(kind, input);
10860
+ const analysis = String(body.analysis || "").slice(0, 4e4);
10861
+ if (!analysis.trim()) return send(res, 400, { error: "\u6CA1\u6709\u53EF\u4FDD\u5B58\u7684\u62A5\u544A" });
10862
+ const existing = body.id ? findGrowthRecord({ kind, id: growthRecordId(body.id) }) : null;
10863
+ if (body.id && !existing) return send(res, 404, { error: "\u6863\u6848\u4E0D\u5B58\u5728" });
10864
+ const media = body.media === void 0 && existing ? existing.media : normalizeDiagnoseMedia(body.media).map(({ path: _path, ...rest }) => rest);
10865
+ const sessionId = String(body.sessionId ?? existing?.sessionId ?? "").slice(0, 100);
10866
+ const projectPath = String(body.projectPath ?? existing?.projectPath ?? "").slice(0, 400);
10867
+ const report = existing ? writeGrowthRecord({
10868
+ ...existing,
10869
+ title: growthRecordTitle(kind, input),
10870
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
10871
+ input,
10872
+ analysis,
10873
+ sessionId,
10874
+ projectPath,
10875
+ media,
10876
+ links: growthLinksFromInput(kind, input)
10877
+ }) : createGrowthRecord(kind, input, { analysis, sessionId, projectPath, media });
10878
+ return send(res, 200, { report });
10879
+ } catch (error) {
10880
+ return send(res, error.status || 500, { error: error.message || "\u4FDD\u5B58\u5931\u8D25" });
10881
+ }
10882
+ }
10883
+ case "POST /growth/reports/delete": {
10884
+ try {
10885
+ assertDiagnoseMember();
10886
+ const body = await readJson(req);
10887
+ const kind = growthKind(body.kind);
10888
+ const id = growthRecordId(body.id);
10889
+ fs14.rmSync(path14.join(GROWTH_DIR, kind, `${id}.json`), { force: true });
10890
+ return send(res, 200, { ok: true });
10891
+ } catch (error) {
10892
+ return send(res, error.status || 500, { error: error.message || "\u5220\u9664\u5931\u8D25" });
10893
+ }
10894
+ }
10043
10895
  case "GET /licenses":
10044
10896
  return send(res, 200, { licenses: license.listProducts(), aggregate: license.status() });
10045
10897
  case "POST /activate": {
@@ -10047,6 +10899,8 @@ function createPanelApp(options = {}) {
10047
10899
  if (typeof body.key !== "string") return send(res, 400, { error: "key is required" });
10048
10900
  try {
10049
10901
  const status = await license.activate(body.key.trim().toUpperCase(), body.product ? String(body.product) : void 0);
10902
+ campaignCache = { at: 0, items: campaignCache.items };
10903
+ docsCache = { at: 0, items: docsCache.items };
10050
10904
  return send(res, 200, { ok: true, status, licenses: license.listProducts() });
10051
10905
  } catch (error) {
10052
10906
  return send(res, 400, { error: error.message });
@@ -10055,6 +10909,8 @@ function createPanelApp(options = {}) {
10055
10909
  case "POST /signout": {
10056
10910
  const body = await readJson(req).catch(() => ({}));
10057
10911
  license.signOut(body.product ? String(body.product) : void 0);
10912
+ campaignCache = { at: 0, items: campaignCache.items };
10913
+ docsCache = { at: 0, items: docsCache.items };
10058
10914
  return send(res, 200, { ok: true, licenses: license.listProducts() });
10059
10915
  }
10060
10916
  case "POST /heartbeat": {