@kanadego/dsh-heartbeat 2.1.2 → 2.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/bili-login.ts"],"sourcesContent":["// `heartbeat bili login` — bilibili QR-code login (v2.2.0).\n//\n// Scans a QR code to log the user into bilibili and lands SESSDATA in the\n// vault as <dataDir>/bilibili-session.json (shape: { sessdata, savedAt }).\n// That file/field pair is a CROSS-SUBTASK contract with the data-source\n// module (it reads `sessdata` back verbatim) — rename it and you break the\n// reader, so treat it like a wire format.\n//\n// Flow (passport web QR login):\n// 1. POST-less generate: GET .../web/qrcode/generate -> { url, qrcode_key }\n// 2. Render the login url as a PNG (~400x400, margin 2) into the OS temp dir\n// 3. Open it with the platform's default viewer (spawn the system command\n// directly, no shell wrapper). No GUI / missing viewer is NOT an error:\n// print the image path, its directory and the login url so the user can\n// open it by hand, then keep polling.\n// 4. Poll .../web/qrcode/poll every 2s for up to 3 minutes. The login state\n// lives in data.code (the outer code is the API call status and stays 0\n// while the QR flow runs; data.code ?? code keeps old flat shapes\n// working):\n// 0 success -> pull SESSDATA out of Set-Cookie (preferred) or the\n// data.url query string, store it, delete the PNG\n// 86101 not scanned yet -> keep going\n// 86090 scanned, not confirmed -> keep going\n// 86038 / 86103 QR expired -> tell the user to rerun, exit non-zero\n// other unknown protocol code -> report the code only, exit non-zero\n// 5. SESSDATA never reaches a log line, an error message, or stdout — the\n// only trace of it is the ciphertext in the vault container.\n//\n// Every side effect (fetch, render, open, sleep, clock, storage) is injected\n// through BiliLoginDeps so the whole state machine runs in tests with a fake\n// fetch and a fake renderer. Only `runBiliLogin`'s default wiring touches the\n// real world; `main` (cli/index.ts) builds that wiring.\n\nimport { spawn } from 'node:child_process';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { openerFor } from '../core/open-path.js';\nimport type { PathGuard } from '../core/path-guard.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { loadJson, saveJson } from '../vault/vault.js';\n\nconst GENERATE_URL = 'https://passport.bilibili.com/x/passport-login/web/qrcode/generate';\nconst POLL_URL = 'https://passport.bilibili.com/x/passport-login/web/qrcode/poll';\n\n/**\n * Where the login cookie lands. CROSS-SUBTASK CONTRACT (reviewer, q-cbcb4c51c3b20b39):\n * the data-source module reads SESSDATA back from\n * file: <dataDir>/bilibili-session.json (KHBV2 container via vault.saveJson)\n * shape: { \"sessdata\": \"<SESSDATA value>\", \"savedAt\": <ms timestamp> }\n * This file holds only the bilibili session — do not grow it into a flat key\n * table, and do not move or rename it without syncing the reader.\n */\nexport const BILI_SESSION_FILE_NAME = 'bilibili-session.json';\n\nexport function bilibiliSessionFilePath(paths: WorkspacePaths): string {\n return path.join(paths.dataDir, BILI_SESSION_FILE_NAME);\n}\n\nexport interface BiliSessionRecord {\n sessdata: string;\n savedAt: number;\n}\n\n/**\n * Write the login cookie into the vault-managed session file (KHBV2 container\n * via vault.saveJson — the cookie value never touches the disk in plaintext).\n */\nexport function saveBiliSession(guard: PathGuard, paths: WorkspacePaths, value: string): void {\n const record: BiliSessionRecord = { sessdata: value, savedAt: Date.now() };\n saveJson(guard, bilibiliSessionFilePath(paths), record);\n}\n\nexport interface BiliLoginDeps {\n fetchImpl: typeof fetch;\n /** Render `url` as a PNG at `file` (production: qrcode, 400x400, margin 2). */\n renderQrPng: (url: string, file: string) => Promise<void>;\n /** Open a file with the system viewer; false = could not (no GUI etc.). */\n openImage: (file: string) => Promise<boolean>;\n sleep: (ms: number) => Promise<void>;\n /** Line logger (stdout). Must never receive the cookie value. */\n log: (line: string) => void;\n /** Wall clock, ms. Injectable so the 3-minute deadline is testable. */\n now: () => number;\n /** Directory the QR PNG goes to (production: os.tmpdir()). */\n tmpDir?: string;\n platform: NodeJS.Platform;\n pollIntervalMs?: number;\n maxDurationMs?: number;\n /** Where the cookie is stored on success (production: vault). */\n saveCredential?: (value: string) => void;\n}\n\ninterface GenerateOk {\n code: number;\n data: { url: string; qrcode_key: string };\n}\n\ninterface PollResponse {\n code: number;\n message?: string;\n data?: { url?: string; code?: number; message?: string };\n}\n\n/**\n * Pull SESSDATA out of the poll response's Set-Cookie header(s). The cookie\n * is the primary source because it is what a browser session would carry.\n */\nexport function sessdataFromCookies(resp: Response): string | null {\n const cookies = typeof resp.headers.getSetCookie === 'function' ? resp.headers.getSetCookie() : [];\n for (const cookie of cookies) {\n const first = cookie.split(';')[0]!.trim();\n if (first.startsWith('SESSDATA=')) {\n const value = first.slice('SESSDATA='.length);\n return value.length > 0 ? value : null;\n }\n }\n return null;\n}\n\n/**\n * Fallback source: the SESSDATA query parameter on data.url (a redirect).\n * Extracted raw (URLSearchParams would percent-decode `%2C` into `,`), because\n * the value is stored and later sent as a Cookie — which carries the encoded\n * form — exactly like the Set-Cookie source above.\n */\nexport function sessdataFromUrl(url: string | undefined | null): string | null {\n if (!url) return null;\n try {\n const m = /[?&]SESSDATA=([^&]*)/.exec(new URL(url).search);\n return m && m[1]!.length > 0 ? m[1]! : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Spawn the platform's default viewer directly (win32: `cmd /c start \"\" <path>`,\n * darwin: `open <path>`, linux: `xdg-open <path>` — the same command table as\n * core/open-path.ts) and report whether the spawn went out. Unlike openPath,\n * the caller needs to KNOW about failure: the no-GUI branch must print the\n * image path + directory + login url instead of silently doing nothing.\n * The `error` event is async (ENOENT does not throw synchronously), so wait\n * for either `spawn` (success) or `error`.\n */\nexport function tryOpenImage(platform: NodeJS.Platform, file: string): Promise<boolean> {\n const opener = openerFor(platform);\n return new Promise((resolve) => {\n try {\n const child = spawn(opener.cmd, opener.args(file), { detached: true, stdio: 'ignore' });\n child.once('error', () => resolve(false));\n child.once('spawn', () => resolve(true));\n // A viewer that exits nonzero (e.g. xdg-open with no DE) still opened\n // nothing, but the spawn itself went out — same contract as openPath.\n } catch {\n resolve(false);\n }\n });\n}\n\n/** Production QR renderer: `qrcode` is pure JS, PNG straight to file. */\nasync function renderQrPngProduction(url: string, file: string): Promise<void> {\n const { default: QRCode } = await import('qrcode');\n await QRCode.toFile(file, url, { type: 'png', width: 400, margin: 2 });\n}\n\n/** Status line for a poll code, without echoing anything sensitive. */\nfunction pollStatusLine(code: number): string {\n if (code === 86101) return '等待扫码…';\n if (code === 86090) return '已扫码,请在手机上确认登录…';\n return `poll code ${code}`;\n}\n\n/**\n * The whole login flow. Returns the process exit code:\n * 0 = SESSDATA stored, 1 = expired / timed out / protocol error.\n */\nexport async function runBiliLogin(deps: BiliLoginDeps): Promise<number> {\n const pollIntervalMs = deps.pollIntervalMs ?? 2_000;\n const maxDurationMs = deps.maxDurationMs ?? 3 * 60_000;\n const platform = deps.platform;\n const tmpDir = deps.tmpDir ?? os.tmpdir();\n\n // 1. Generate.\n let gen: GenerateOk;\n try {\n const resp = await deps.fetchImpl(GENERATE_URL);\n gen = (await resp.json()) as GenerateOk;\n } catch (e) {\n deps.log(`获取二维码失败:${e instanceof Error ? e.message : String(e)}`);\n return 1;\n }\n if (gen.code !== 0 || !gen.data?.url || !gen.data?.qrcode_key) {\n deps.log(`获取二维码失败:generate code=${gen.code}`);\n return 1;\n }\n const { url, qrcode_key } = gen.data;\n\n // 2. Render the PNG into the OS temp dir.\n const pngPath = path.join(tmpDir, `bili-login-qr-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.png`);\n try {\n await deps.renderQrPng(url, pngPath);\n } catch (e) {\n deps.log(`二维码渲染失败:${e instanceof Error ? e.message : String(e)}`);\n return 1;\n }\n\n // 3. Try to open it; failure is a fallback, not an error.\n const opened = await deps.openImage(pngPath);\n if (!opened) {\n deps.log('无法自动打开图片(无 GUI 或缺少查看器)。请自己打开这张图用手机扫:');\n deps.log(` 图片:${pngPath}`);\n deps.log(` 目录:${path.dirname(pngPath)}`);\n deps.log(` 链接:${url}`);\n }\n\n // 4. Poll until success / expiry / deadline.\n const deadline = deps.now() + maxDurationMs;\n try {\n for (;;) {\n let poll: PollResponse | null = null;\n let resp: Response | null = null;\n try {\n resp = await deps.fetchImpl(`${POLL_URL}?qrcode_key=${encodeURIComponent(qrcode_key)}`);\n poll = (await resp.json()) as PollResponse;\n } catch (e) {\n deps.log(`轮询网络错误,重试中:${e instanceof Error ? e.message : String(e)}`);\n }\n if (poll) {\n // The login state lives in data.code; the outer code is the API call\n // status (stays 0 while the QR flow runs). Fall back to the outer code\n // for old flat shapes without data.code.\n const state = poll.data?.code ?? poll.code;\n if (state === 0) {\n // SESSDATA: Set-Cookie first, then the data.url query param.\n const value = (resp ? sessdataFromCookies(resp) : null) ?? sessdataFromUrl(poll.data?.url);\n if (!value) {\n deps.log('登录成功但响应里找不到 SESSDATA(Set-Cookie 与 data.url 都没有),未写入。');\n return 1;\n }\n deps.saveCredential?.(value);\n deps.log('登录成功。SESSDATA 已加密存入 vault(bilibili-session.json 的 sessdata 字段),未在日志中显示原文。');\n return 0;\n }\n if (state === 86038 || state === 86103) {\n deps.log('二维码已过期,请重跑 `heartbeat bili login` 生成新的二维码。');\n return 1;\n }\n if (state === 86101 || state === 86090) {\n deps.log(pollStatusLine(state));\n } else {\n // Unknown protocol code: report code only (message text is third-party).\n deps.log(`${pollStatusLine(state)},终止。`);\n return 1;\n }\n }\n if (deps.now() >= deadline) {\n deps.log('等待超时(3 分钟内未完成扫码确认),请重跑 `heartbeat bili login`。');\n return 1;\n }\n await deps.sleep(pollIntervalMs);\n }\n } finally {\n // 5. The temp PNG holds no secret, but it is a one-shot credential prompt —\n // remove it whichever way the flow ends.\n try {\n fs.rmSync(pngPath, { force: true });\n } catch {\n /* best effort */\n }\n }\n}\n\n// ── Reusable login service (panel RPC, v2.3.0) ─────────────────────────────\n// The flow above is a blocking CLI loop; the panel needs the same protocol\n// chopped into two awaited steps (start = get a QR, poll = one poll call).\n// Same wire protocol (login state in data.code, SESSDATA from Set-Cookie →\n// data.url), same vault contract via the injected saveCredential. The session\n// lives in a memory Map for 3 minutes and a poll/start sweep drops expired\n// entries; a consumed (successful) session is removed immediately, so a second\n// poll on it reports expired instead of re-saving the cookie.\n\nexport type BiliRpcPollState = 'waiting' | 'scanned' | 'success' | 'expired' | 'error';\n\nexport interface BiliRpcPollResult {\n state: BiliRpcPollState;\n /** Detail for the error state (protocol code or network message) — never the cookie. */\n message?: string;\n}\n\nexport interface BiliRpcStartResult {\n sessionId: string;\n qrDataUrl: string;\n expiresAt: number;\n}\n\nexport interface BiliLoginServiceDeps {\n fetchImpl: typeof fetch;\n /** Render the login url as a PNG data URL (production: qrcode.toDataURL). */\n renderQrDataUrl: (url: string) => Promise<string>;\n /** Wall clock, ms — also drives the 3-minute session TTL. */\n now: () => number;\n /** Where the cookie is stored on success (production: saveBiliSession). */\n saveCredential?: (value: string) => void;\n}\n\nexport interface BiliLoginService {\n startBiliLogin(): Promise<BiliRpcStartResult>;\n pollBiliLogin(sessionId: string): Promise<BiliRpcPollResult>;\n}\n\ninterface BiliRpcSession {\n qrcodeKey: string;\n expiresAt: number;\n}\n\nconst RPC_SESSION_TTL_MS = 3 * 60_000;\n\n/**\n * Two-step (start/poll) QR login for the panel. Every side effect (fetch,\n * render, clock, storage) is injected, exactly like runBiliLogin, so the whole\n * service runs in tests with a fake fetch; rpc.ts builds the production one.\n */\nexport function createBiliLoginService(deps: BiliLoginServiceDeps): BiliLoginService {\n const sessions = new Map<string, BiliRpcSession>();\n // Every start/poll sweeps: no background timer, expired entries die lazily.\n const sweep = (): void => {\n const t = deps.now();\n for (const [id, session] of sessions) {\n if (t >= session.expiresAt) sessions.delete(id);\n }\n };\n\n const startBiliLogin = async (): Promise<BiliRpcStartResult> => {\n sweep();\n const resp = await deps.fetchImpl(GENERATE_URL);\n const gen = (await resp.json()) as GenerateOk;\n if (gen.code !== 0 || !gen.data?.url || !gen.data?.qrcode_key) {\n throw new Error(`generate code=${gen.code}`);\n }\n const qrDataUrl = await deps.renderQrDataUrl(gen.data.url);\n if (!qrDataUrl.startsWith('data:image/png;base64,')) {\n throw new Error('qr renderer did not return a png data URL');\n }\n const now = deps.now();\n const sessionId = `bili-${now.toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n const expiresAt = now + RPC_SESSION_TTL_MS;\n sessions.set(sessionId, { qrcodeKey: gen.data.qrcode_key, expiresAt });\n return { sessionId, qrDataUrl, expiresAt };\n };\n\n const pollBiliLogin = async (sessionId: string): Promise<BiliRpcPollResult> => {\n sweep();\n const session = sessions.get(sessionId);\n if (!session) return { state: 'expired' };\n if (deps.now() >= session.expiresAt) {\n sessions.delete(sessionId);\n return { state: 'expired' };\n }\n let resp: Response;\n let poll: PollResponse;\n try {\n resp = await deps.fetchImpl(`${POLL_URL}?qrcode_key=${encodeURIComponent(session.qrcodeKey)}`);\n poll = (await resp.json()) as PollResponse;\n } catch (e) {\n return { state: 'error', message: e instanceof Error ? e.message : String(e) };\n }\n // Same state mapping as runBiliLogin: the login state lives in data.code\n // (the outer code is the API call status); fall back for old flat shapes.\n const state = poll.data?.code ?? poll.code;\n if (state === 0) {\n const value = sessdataFromCookies(resp) ?? sessdataFromUrl(poll.data?.url);\n if (!value) return { state: 'error', message: 'no SESSDATA in poll response' };\n deps.saveCredential?.(value);\n sessions.delete(sessionId); // one-shot: never write the cookie twice\n return { state: 'success' };\n }\n if (state === 86038 || state === 86103) {\n sessions.delete(sessionId);\n return { state: 'expired' };\n }\n if (state === 86101) return { state: 'waiting' };\n if (state === 86090) return { state: 'scanned' };\n return { state: 'error', message: `poll code ${state}` };\n };\n\n return { startBiliLogin, pollBiliLogin };\n}\n\n/** Production wiring for `openImage` (platform command table). */\nexport function openImageProduction(platform: NodeJS.Platform): (file: string) => Promise<boolean> {\n return (file: string) => tryOpenImage(platform, file);\n}\n\nexport { renderQrPngProduction, GENERATE_URL, POLL_URL };\n"],"mappings":";;;;;;;;AAiCA,SAAS,aAAa;AACtB,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAMjB,IAAM,eAAe;AACrB,IAAM,WAAW;AAUV,IAAM,yBAAyB;AAE/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,SAAS;AACzB,aAAO,EAAE,OAAO,UAAU;AAAA,IAC5B;AACA,QAAI;AACJ,QAAI;AACJ,QAAI;AACF,aAAO,MAAM,KAAK,UAAU,GAAG,QAAQ,eAAe,mBAAmB,QAAQ,SAAS,CAAC,EAAE;AAC7F,aAAQ,MAAM,KAAK,KAAK;AAAA,IAC1B,SAAS,GAAG;AACV,aAAO,EAAE,OAAO,SAAS,SAAS,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAE;AAAA,IAC/E;AAGA,UAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK;AACtC,QAAI,UAAU,GAAG;AACf,YAAM,QAAQ,oBAAoB,IAAI,KAAK,gBAAgB,KAAK,MAAM,GAAG;AACzE,UAAI,CAAC,MAAO,QAAO,EAAE,OAAO,SAAS,SAAS,+BAA+B;AAC7E,WAAK,iBAAiB,KAAK;AAC3B,eAAS,OAAO,SAAS;AACzB,aAAO,EAAE,OAAO,UAAU;AAAA,IAC5B;AACA,QAAI,UAAU,SAAS,UAAU,OAAO;AACtC,eAAS,OAAO,SAAS;AACzB,aAAO,EAAE,OAAO,UAAU;AAAA,IAC5B;AACA,QAAI,UAAU,MAAO,QAAO,EAAE,OAAO,UAAU;AAC/C,QAAI,UAAU,MAAO,QAAO,EAAE,OAAO,UAAU;AAC/C,WAAO,EAAE,OAAO,SAAS,SAAS,aAAa,KAAK,GAAG;AAAA,EACzD;AAEA,SAAO,EAAE,gBAAgB,cAAc;AACzC;AAGO,SAAS,oBAAoB,UAA+D;AACjG,SAAO,CAAC,SAAiB,aAAa,UAAU,IAAI;AACtD;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  loadPool,
4
4
  normalizeCategory,
5
5
  seedsFilePath
6
- } from "./chunk-63E5OYSI.js";
6
+ } from "./chunk-N6SMIGYJ.js";
7
7
  import {
8
8
  appendAuditLine
9
9
  } from "./chunk-ECXYNTEV.js";
@@ -599,4 +599,4 @@ export {
599
599
  buildWeeklyPrompt,
600
600
  renderTemplateReport
601
601
  };
602
- //# sourceMappingURL=chunk-LPPRI53J.js.map
602
+ //# sourceMappingURL=chunk-XYBII5PR.js.map
package/dist/cli/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  presetStatus,
18
18
  readExcerpts,
19
19
  removeExcerpt
20
- } from "../chunk-HE6IF6OU.js";
20
+ } from "../chunk-F2XVKX55.js";
21
21
  import {
22
22
  adviseWander,
23
23
  appendEntry,
@@ -34,7 +34,10 @@ import {
34
34
  scanPending,
35
35
  sendNewMessageHint,
36
36
  weeklyDirPath
37
- } from "../chunk-LPPRI53J.js";
37
+ } from "../chunk-XYBII5PR.js";
38
+ import {
39
+ openPath
40
+ } from "../chunk-OCBE2AKW.js";
38
41
  import {
39
42
  activeSeeds,
40
43
  addSeed,
@@ -44,7 +47,7 @@ import {
44
47
  loadPool,
45
48
  seedsFilePath,
46
49
  surfaceSeed
47
- } from "../chunk-63E5OYSI.js";
50
+ } from "../chunk-N6SMIGYJ.js";
48
51
  import {
49
52
  appendAuditLine,
50
53
  loadProfile,
@@ -69,9 +72,9 @@ import {
69
72
  } from "../chunk-IBBAISSW.js";
70
73
 
71
74
  // src/cli/index.ts
72
- import { spawn } from "child_process";
73
75
  import fs2 from "fs";
74
76
  import path2 from "path";
77
+ import { pathToFileURL } from "url";
75
78
 
76
79
  // src/vault/burn-list.ts
77
80
  import fs from "fs";
@@ -267,7 +270,8 @@ function usage() {
267
270
  " migrate import <file> restore a container into this workspace (passphrase: 1 stdin line)",
268
271
  " burn [--yes] [--all] shred runtime data (settings kept unless --all)",
269
272
  " preset status bundled agent preset: target dir + installed?",
270
- " preset install [--force] install the bundled preset (never overwrites unless --force)"
273
+ " preset install [--force] install the bundled preset (never overwrites unless --force)",
274
+ " bili login bilibili \u626B\u7801\u767B\u5F55\uFF0CSESSDATA \u5199\u5165 vault (bilibili-session.json)"
271
275
  ].join("\n");
272
276
  }
273
277
  function readStdinText() {
@@ -282,7 +286,7 @@ function flag(argv, name) {
282
286
  return i > -1 ? argv[i + 1] : void 0;
283
287
  }
284
288
  var SEED_TAGS = ["news", "fandom", "scene", "promise"];
285
- var SEED_SOURCES = ["chat", "screen", "browse", "hand", "profile"];
289
+ var SEED_SOURCES = ["chat", "screen", "browse", "bilibili", "hand", "profile"];
286
290
  function flagOneOf(argv, name, allowed) {
287
291
  const v = flag(argv, name);
288
292
  if (v === void 0) return void 0;
@@ -419,7 +423,7 @@ async function verbLedger(c) {
419
423
  if (!fs2.existsSync(f)) {
420
424
  console.log(`(ledger will be created at ${f})`);
421
425
  }
422
- spawn("cmd", ["/c", "start", "", f], { detached: true, stdio: "ignore" }).unref();
426
+ openPath(f);
423
427
  console.log(`opened ${f}`);
424
428
  return 0;
425
429
  }
@@ -470,7 +474,7 @@ async function verbExcerpt(c) {
470
474
  fs2.mkdirSync(path2.dirname(f), { recursive: true });
471
475
  fs2.writeFileSync(f, EXCERPT_HEADER, "utf8");
472
476
  }
473
- spawn("cmd", ["/c", "start", "", f], { detached: true, stdio: "ignore" }).unref();
477
+ openPath(f);
474
478
  console.log(`opened ${f}`);
475
479
  return 0;
476
480
  }
@@ -735,7 +739,7 @@ async function verbSessions(c) {
735
739
  const root = path2.join(dshHomeDir(), "sessions");
736
740
  let found = 0;
737
741
  if (fs2.existsSync(root)) {
738
- const { homeSessionId } = await import("../orchestrator-MNFCPH43.js");
742
+ const { homeSessionId } = await import("../orchestrator-5BHYQ77Y.js");
739
743
  const own = homeSessionId(guard, paths);
740
744
  for (const slug of fs2.readdirSync(root)) {
741
745
  for (const id of fs2.readdirSync(path2.join(root, slug))) {
@@ -754,7 +758,7 @@ async function verbBind(c) {
754
758
  switch (sub) {
755
759
  case "list": {
756
760
  const data = loadBindings(guard, paths.settingsDir);
757
- const { homeSessionId } = await import("../orchestrator-MNFCPH43.js");
761
+ const { homeSessionId } = await import("../orchestrator-5BHYQ77Y.js");
758
762
  const own = homeSessionId(guard, paths);
759
763
  if (own) console.log(`\u5FC3\u8DF3\u6B63\u8EAB: ${own}\uFF08\u51B3\u7B56\u8F6E\u6B21\u53D1\u751F\u5730\uFF1Bbind remove \u5B83 = \u91CD\u7F6E\u6B63\u8EAB\uFF09`);
760
764
  for (const b of data.bindings) {
@@ -782,7 +786,7 @@ async function verbBind(c) {
782
786
  return 1;
783
787
  }
784
788
  console.log(removeBinding(guard, paths.settingsDir, id) ? `UNBOUND ${id}` : "NOT_FOUND");
785
- const { resetHomeSession } = await import("../orchestrator-MNFCPH43.js");
789
+ const { resetHomeSession } = await import("../orchestrator-5BHYQ77Y.js");
786
790
  if (resetHomeSession(guard, paths, id)) {
787
791
  console.log("\u6CE8\u610F\uFF1A\u8FD9\u662F\u5FC3\u8DF3\u6B63\u8EAB\u4F1A\u8BDD\u3002\u5DF2\u91CD\u7F6E\u2014\u2014\u4E0B\u6B21\u5FC3\u8DF3\u5C06\u521B\u5EFA\u65B0\u7684\u6B63\u8EAB\u4F1A\u8BDD\uFF08\u65E7\u4F1A\u8BDD\u4E0D\u518D\u6709\u5FC3\u8DF3\uFF09");
788
792
  }
@@ -856,7 +860,7 @@ async function verbVault(c) {
856
860
  async function verbFocus(c) {
857
861
  const { sub, rest, decisionLog } = c;
858
862
  const { readFocusState, writeFocusState, clearFocusState } = await import("../focus-store-RNHBAFYS.js");
859
- const { formatFocusClock } = await import("../orchestrator-MNFCPH43.js");
863
+ const { formatFocusClock } = await import("../orchestrator-5BHYQ77Y.js");
860
864
  const audit = (entry) => {
861
865
  try {
862
866
  appendAuditLine(decisionLog, entry);
@@ -888,6 +892,34 @@ async function verbFocus(c) {
888
892
  console.error("usage: heartbeat focus <minutes> | focus off | focus");
889
893
  return 1;
890
894
  }
895
+ async function verbBili(c) {
896
+ const { guard, paths, sub, decisionLog } = c;
897
+ if (sub !== "login") {
898
+ console.error("usage: bili login");
899
+ return 1;
900
+ }
901
+ const {
902
+ runBiliLogin,
903
+ openImageProduction,
904
+ renderQrPngProduction,
905
+ saveBiliSession
906
+ } = await import("../bili-login-XQVEE4M6.js");
907
+ const outcome = await runBiliLogin({
908
+ fetchImpl: fetch,
909
+ renderQrPng: renderQrPngProduction,
910
+ openImage: openImageProduction(process.platform),
911
+ sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
912
+ log: (line) => console.log(line),
913
+ now: () => Date.now(),
914
+ platform: process.platform,
915
+ saveCredential: (value) => saveBiliSession(guard, paths, value)
916
+ });
917
+ try {
918
+ appendAuditLine(decisionLog, { event: "bili_login", outcome });
919
+ } catch {
920
+ }
921
+ return outcome;
922
+ }
891
923
  var VERBS = {
892
924
  status: verbStatus,
893
925
  seeds: verbSeeds,
@@ -904,7 +936,8 @@ var VERBS = {
904
936
  migrate: verbMigrate,
905
937
  sessions: verbSessions,
906
938
  bind: verbBind,
907
- preset: verbPreset
939
+ preset: verbPreset,
940
+ bili: verbBili
908
941
  };
909
942
  async function main(argv) {
910
943
  const [cmd, sub, ...rest] = argv;
@@ -942,7 +975,7 @@ async function main(argv) {
942
975
  seedAudit
943
976
  });
944
977
  }
945
- if (process.argv[1] && import.meta.url === new URL(`file:///${process.argv[1].replace(/\\/g, "/")}`).href) {
978
+ if (process.argv[1] && import.meta.url === pathToFileURL(path2.resolve(process.argv[1])).href) {
946
979
  void main(process.argv.slice(2)).then((code) => {
947
980
  process.exitCode = code;
948
981
  }).catch((e) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/index.ts","../../src/vault/burn-list.ts"],"sourcesContent":["// Operational CLI (design doc §14). Commands grow per module.\n// Run: node dist/cli/index.js <command> [args] (or via tsx in dev)\n//\n// H-42: `main` used to be a 530-line function with a switch holding every\n// verb's body. The verbs are module-level functions now (see CliCtx below) and\n// `main` only builds the shared context and dispatches — one place to add a\n// command, and each verb is readable on its own.\n\nimport { spawn } from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { dshHomeDir, initWorkspace } from '../core/paths.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { createPathGuard } from '../core/path-guard.js';\nimport type { PathGuard } from '../core/path-guard.js';\nimport { appendAuditLine, pruneAuditFile } from '../core/audit-log.js';\nimport { atomicWriteFileSync } from '../core/atomic-fs.js';\nimport { localDayKey } from '../core/time-window.js';\nimport { loadPolicy } from '../config/load.js';\nimport type { Policy } from '../config/schema.js';\nimport {\n addSeed,\n archiveSeedById,\n gcPool,\n loadPool,\n activeSeeds,\n archivedSeeds,\n seedsFilePath,\n surfaceSeed,\n} from '../seeds/pool.js';\nimport type { SeedSource, SeedTag } from '../seeds/types.js';\nimport {\n appendEntry,\n ledgerFilePath,\n markDone,\n readLedger,\n scanPending,\n} from '../ledger/ledger.js';\nimport {\n EXCERPT_HEADER,\n appendExcerpt,\n excerptFilePath,\n readExcerpts,\n removeExcerpt,\n} from '../excerpt/excerpt.js';\nimport {\n adviseWander,\n browseStatus,\n completeWander,\n loadInterests,\n} from '../browse/browse.js';\nimport { ensureRegistered, sendNewMessageHint } from '../notify/notify.js';\nimport {\n loadProfile,\n profileFilePath,\n verifyProfile,\n rebuildProfile,\n wipeProfile,\n} from '../profile/store.js';\nimport { planBurn, executeBurn } from '../vault/burn-list.js';\nimport {\n collectMigrationEntries,\n encryptContainer,\n decryptContainer,\n applyMigrationEntries,\n} from '../vault/migrate.js';\nimport { listWeeklyReports, readWeeklyReport, weeklyDirPath } from '../weekly/report.js';\nimport {\n containerKind,\n upgradeVaultTree,\n vaultKeyPath,\n writeText,\n} from '../vault/vault.js';\nimport { matchFilesRecursive } from '../core/fs-walk.js';\nimport {\n BUNDLED_PRESET_ID,\n conventionalUserPresetRoot,\n describeInstall,\n installBundledPreset,\n presetStatus,\n} from '../core/preset-install.js';\n\nfunction usage(): string {\n return [\n 'usage: heartbeat <command> [args]',\n '',\n 'commands:',\n ' status workspace paths + policy summary',\n ' seeds add <text> [--tag t] [--source s] [--topic x] [--confidence n]',\n ' seeds list [--archived] list active (or archived) seeds',\n ' seeds surface <id> count a surfacing (rule 1 accounting)',\n ' seeds archive <id> deliberate retirement (completed)',\n ' seeds gc run deterministic eviction rules 1-3',\n ' seeds stats pool status JSON',\n ' ledger add <text> register an open item',\n ' ledger list [--pending] list entries',\n ' ledger done <id|substring> mark an entry done',\n ' ledger open open ledger.md in the default editor',\n ' excerpt add <text> keep a line in the notebook',\n ' excerpt list [n] list entries (newest n if given)',\n ' excerpt remove <id|substring> tear a page out',\n ' excerpt open open excerpts.md in the default editor',\n ' logs cleanup [--dry-run] apply log retention now',\n ' browse status browse state summary (wander)',\n ' browse dry wander adjudication with forced noon window',\n ' browse done <focus> CODE-side registration after a wander visit',\n ' focus focus-mode status (paused until HH:MM or not)',\n ' focus <minutes> pause the heartbeat for N minutes (1-1440)',\n ' focus off lift the pause now',\n ' bind list list session bindings (D13)',\n ' bind add <sessionId> [--observe] bind a session (deliver by default)',\n ' bind remove <sessionId> unbind a session',\n ' sessions list enumerate persisted sessions (ids)',\n ' notify check|register|send toast channel (D12: hint only, no body)',\n ' profile list [--all] current valid (or all incl. expired) entries',\n ' profile export decrypted Markdown export to data/exports/',\n ' profile verify journal replay vs disk (report only)',\n ' profile rebuild [--check] rebuild materialized view from journal',\n ' profile snapshot [--force] fold the journal into a snapshot + archive shard',\n ' profile wipe wipe profile data (asks --yes)',\n ' weekly list list generated weekly reports',\n ' weekly show [file] print a report (default: newest)',\n ' vault status encryption containers on disk + master key file',\n ' vault upgrade rewrite legacy KHBV1 files as KHBV2 (in place)',\n ' migrate export [file] pack memory files into a passphrase container (passphrase: 2 stdin lines)',\n ' migrate import <file> restore a container into this workspace (passphrase: 1 stdin line)',\n ' burn [--yes] [--all] shred runtime data (settings kept unless --all)',\n ' preset status bundled agent preset: target dir + installed?',\n ' preset install [--force] install the bundled preset (never overwrites unless --force)',\n ].join('\\n');\n}\n\nfunction readStdinText(): string {\n try {\n return fs.readFileSync(0, 'utf8').trim();\n } catch {\n return '';\n }\n}\n\nfunction flag(argv: string[], name: string): string | undefined {\n const i = argv.indexOf(name);\n return i > -1 ? argv[i + 1] : undefined;\n}\n\n/** H-42: the seed flags used to be written `flag(rest, '--tag') as never` — the\n * escape hatch threw the type away, so a typo landed in the seed record\n * unchecked. Validate against the known sets instead (the `satisfies` clauses\n * keep these lists in step with the types). */\nconst SEED_TAGS = ['news', 'fandom', 'scene', 'promise'] as const satisfies readonly SeedTag[];\nconst SEED_SOURCES = ['chat', 'screen', 'browse', 'hand', 'profile'] as const satisfies readonly SeedSource[];\n\nfunction flagOneOf<T extends string>(argv: string[], name: string, allowed: readonly T[]): T | undefined {\n const v = flag(argv, name);\n if (v === undefined) return undefined;\n return (allowed as readonly string[]).includes(v) ? (v as T) : undefined;\n}\n\n/** Read N lines from stdin (passphrase prompts for migrate). */\nasync function readLines(prompts: string[]): Promise<string[]> {\n const readline = await import('node:readline/promises');\n const it = readline.createInterface({ input: process.stdin });\n const out: string[] = [];\n for (const p of prompts) out.push((await it.question(p)).trim());\n it.close();\n return out;\n}\n\n/** Everything a verb needs. Built once in {@link main}; `sub`/`rest` are the\n * positional split of argv, `argv` stays available for top-level flags. */\ninterface CliCtx {\n paths: WorkspacePaths;\n guard: PathGuard;\n policy: Policy;\n sub: string | undefined;\n rest: string[];\n argv: string[];\n seedsFile: string;\n ledgerFile: string;\n excerptFile: string;\n decisionLog: string;\n seedAudit: (entry: Record<string, unknown>) => void;\n}\n\ntype Verb = (c: CliCtx) => Promise<number>;\n\nasync function verbStatus(c: CliCtx): Promise<number> {\n const { paths, policy } = c;\n console.log(JSON.stringify({\n dataDir: paths.dataDir,\n heartbeatIntervalMin: policy.heartbeat.intervalMin,\n maxDailySend: policy.gate.maxDailySend,\n seedsMaxActive: policy.seeds.maxActive,\n psyEnabled: policy.profile.psyEnabled,\n }, null, 2));\n return 0;\n}\n\nasync function verbSeeds(c: CliCtx): Promise<number> {\n const { guard, policy, sub, rest, seedsFile, seedAudit } = c;\n switch (sub) {\n case 'add': {\n let text = rest[0]?.trim() ?? '';\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: seeds add <text|-> [--tag t] [--source s] [--topic x] [--confidence n]');\n return 1;\n }\n const result = addSeed(guard, seedsFile, policy, {\n text,\n tag: flagOneOf(rest, '--tag', SEED_TAGS),\n source: flagOneOf(rest, '--source', SEED_SOURCES),\n topic: flag(rest, '--topic'),\n confidence: flag(rest, '--confidence') ? Number(flag(rest, '--confidence')) : undefined,\n }, Date.now(), seedAudit);\n if (result.kind === 'duplicate') {\n console.log(`DUPLICATE: active seed ${result.seed.id} has the same text`);\n return 0;\n }\n console.log(`${result.kind.toUpperCase()} ${result.seed.id}` +\n ` (${activeSeeds(loadPool(guard, seedsFile)).length}/${policy.seeds.maxActive})` +\n (result.evicted ? ` [evicted ${result.evicted.id}: ${result.evicted.retireReason}]` : ''));\n return 0;\n }\n case 'list': {\n const db = loadPool(guard, seedsFile);\n const items = rest.includes('--archived') ? archivedSeeds(db) : activeSeeds(db);\n for (const s of items) {\n const ageDays = Math.floor((Date.now() - Date.parse(s.bornAt)) / 86_400_000);\n console.log(`${s.id} [${s.tag}/${s.source}] d${ageDays} used:${s.used}` +\n `${s.protected ? ' *' : ''} ${s.text.slice(0, 60)}`);\n }\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'surface': {\n const s = surfaceSeed(guard, seedsFile, policy, rest[0] ?? '', Date.now(), seedAudit);\n if (!s) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`SURFACED ${s.id} used:${s.used}${s.status === 'archived' ? ' -> archived (consumed)' : ''}`);\n return 0;\n }\n case 'archive': {\n const s = archiveSeedById(guard, seedsFile, rest[0] ?? '', 'completed', Date.now(), seedAudit);\n if (!s) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`ARCHIVED ${s.id}`);\n return 0;\n }\n case 'gc': {\n const report = gcPool(guard, seedsFile, policy, Date.now(), seedAudit);\n console.log(`GC consumed:${report.consumed} expired:${report.expired} cold_bench:${report.coldBench}` +\n ` archive_trimmed:${report.archiveTrimmed} -> active ${report.activeAfter}/${policy.seeds.maxActive}` +\n ` archive ${archivedSeeds(loadPool(guard, seedsFile)).length}/${policy.seeds.archiveCap}`);\n return 0;\n }\n case 'stats': {\n const db = loadPool(guard, seedsFile);\n console.log(JSON.stringify({\n active: activeSeeds(db).length,\n archived: archivedSeeds(db).length,\n cap: policy.seeds.maxActive,\n seq: db.seq,\n }, null, 2));\n return 0;\n }\n default:\n console.error(`unknown seeds subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbLedger(c: CliCtx): Promise<number> {\n const { guard, sub, rest, ledgerFile } = c;\n switch (sub) {\n case 'add': {\n let text = rest.join(' ').trim();\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: ledger add <text|->');\n return 1;\n }\n const e = appendEntry(guard, ledgerFile, text);\n console.log(`OPEN #${e.id} ${e.text.slice(0, 60)}`);\n return 0;\n }\n case 'list': {\n const { entries } = readLedger(guard, ledgerFile);\n const items = rest.includes('--pending') ? scanPending(guard, ledgerFile) : entries;\n for (const e of items) console.log(`${e.status === 'open' ? ' ' : 'x'} #${e.id} ${e.date} ${e.text.slice(0, 60)}`);\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'done': {\n const key = rest.join(' ').trim();\n if (!key) {\n console.error('usage: ledger done <id|substring>');\n return 1;\n }\n const e = markDone(guard, ledgerFile, key);\n if (!e) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`DONE #${e.id}`);\n return 0;\n }\n case 'open': {\n const f = ledgerFile;\n if (!fs.existsSync(f)) {\n console.log(`(ledger will be created at ${f})`);\n }\n spawn('cmd', ['/c', 'start', '', f], { detached: true, stdio: 'ignore' }).unref();\n console.log(`opened ${f}`);\n return 0;\n }\n default:\n console.error(`unknown ledger subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbExcerpt(c: CliCtx): Promise<number> {\n const { guard, sub, rest, excerptFile } = c;\n switch (sub) {\n case 'add': {\n let text = rest.join(' ').trim();\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: excerpt add <text|->');\n return 1;\n }\n const e = appendExcerpt(guard, excerptFile, text);\n console.log(`KEPT #${e.id} ${e.text.slice(0, 60)}`);\n return 0;\n }\n case 'list': {\n const all = readExcerpts(guard, excerptFile).entries;\n const n = Number.parseInt(rest[0] ?? '', 10);\n const items = Number.isFinite(n) && n > 0 ? all.slice(-n) : all;\n for (const e of items) console.log(`#${e.id} ${e.date} ${e.time} ${e.text.slice(0, 60)}`);\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'remove': {\n const key = rest.join(' ').trim();\n if (!key) {\n console.error('usage: excerpt remove <id|substring>');\n return 1;\n }\n const e = removeExcerpt(guard, excerptFile, key);\n if (!e) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`REMOVED #${e.id}`);\n return 0;\n }\n case 'open': {\n const f = excerptFile;\n if (!fs.existsSync(f)) {\n fs.mkdirSync(path.dirname(f), { recursive: true });\n fs.writeFileSync(f, EXCERPT_HEADER, 'utf8');\n }\n spawn('cmd', ['/c', 'start', '', f], { detached: true, stdio: 'ignore' }).unref();\n console.log(`opened ${f}`);\n return 0;\n }\n default:\n console.error(`unknown excerpt subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbWeekly(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const reports = listWeeklyReports(guard, paths.dataDir);\n if (sub === 'list' || sub === undefined) {\n if (reports.length === 0) console.log('(no reports yet — heartbeat generates one every 7 days)');\n for (const r of reports) console.log(`${r.file} ${r.start.slice(0, 10)} ~ ${r.end.slice(0, 10)} [${r.source}]`);\n return 0;\n }\n if (sub === 'show') {\n const file = rest[0] ?? reports[0]?.file;\n if (!file) {\n console.log('(no reports yet)');\n return 1;\n }\n const rep = readWeeklyReport(guard, paths.dataDir, file);\n if (!rep) {\n console.error(`no such report: ${file} (see: weekly list; files live in ${weeklyDirPath(paths.dataDir)})`);\n return 1;\n }\n console.log(`# ${rep.start.slice(0, 10)} ~ ${rep.end.slice(0, 10)} [${rep.source}]`);\n console.log(rep.text);\n return 0;\n }\n console.error(`unknown weekly subcommand: ${sub}`);\n return 1;\n}\n\nasync function verbLogs(c: CliCtx): Promise<number> {\n const { paths, policy, sub, rest, decisionLog } = c;\n if (sub !== 'cleanup') {\n console.error('usage: logs cleanup [--dry-run]');\n return 1;\n }\n const dry = rest.includes('--dry-run');\n const envPulse = path.join(paths.logsDir, 'envpulse.jsonl');\n const cut1 = policy.retention.envPulseHours * 3600_000;\n const cut2 = policy.retention.decisionLogDays * 86_400_000;\n if (dry) {\n console.log(`(dry-run) would prune ${envPulse} to ${policy.retention.envPulseHours}h` +\n ` and ${decisionLog} to ${policy.retention.decisionLogDays}d`);\n return 0;\n }\n const a = pruneAuditFile(envPulse, cut1);\n const b = pruneAuditFile(decisionLog, cut2);\n appendAuditLine(decisionLog, { event: 'retention', pruned_envpulse: a, pruned_decision: b });\n console.log(`PRUNED envpulse:${a} decision:${b}`);\n return 0;\n}\n\nasync function verbBrowse(c: CliCtx): Promise<number> {\n const { guard, paths, policy, sub, rest } = c;\n switch (sub) {\n case 'status': {\n const st = browseStatus(guard, paths);\n const interests = loadInterests(paths);\n console.log(JSON.stringify({\n lastWanderAt: st.wander.last_wander_at ? new Date(st.wander.last_wander_at).toISOString() : null,\n focusCount: st.wander.focusCount,\n interestCount: interests.interests?.length ?? 0,\n }, null, 2));\n return 0;\n }\n case 'dry': {\n const forced = new Date();\n forced.setHours(12, 0, 0, 0);\n const advice = adviseWander(guard, paths, policy, forced);\n console.log(JSON.stringify(advice, null, 2));\n return 0;\n }\n case 'done': {\n const focus = rest.join(' ').trim();\n if (!focus) {\n console.error('usage: browse done <focus>');\n return 1;\n }\n const r = completeWander(guard, paths, focus);\n console.log(JSON.stringify(r));\n return 0;\n }\n default:\n console.error(`unknown browse subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbNotify(c: CliCtx): Promise<number> {\n const { paths, sub } = c;\n switch (sub) {\n case 'check':\n console.log(await ensureRegistered(paths) ? 'REGISTERED: yes' : 'REGISTERED: no');\n return 0;\n case 'register':\n await ensureRegistered(paths);\n console.log('register attempted');\n return 0;\n case 'send':\n console.log(await sendNewMessageHint(paths) ? 'SENT' : 'FAILED');\n return 0;\n default:\n console.error('usage: notify check|register|send');\n return 1;\n }\n}\n\nasync function verbProfile(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const doc = loadProfile(guard, profileFilePath(paths.dataDir));\n const all = rest.includes('--all');\n switch (sub) {\n case 'list': {\n let n = 0;\n for (const p of ['interest', 'projects', 'comm', 'psy'] as const) {\n for (const e of doc.partitions[p]!.entries) {\n if (!all && e.validTo !== null) continue;\n n += 1;\n console.log(`${e.id} [${e.partition}/${e.topic}/${e.subTopic}] ${e.temporal}` +\n ` conf=${e.confidence.toFixed(2)}${e.lowActivity ? ' 久未验证' : ''}${e.validTo ? ' [失效]' : ''}: ${e.content.slice(0, 60)}`);\n }\n }\n if (n === 0) console.log('(empty)');\n return 0;\n }\n case 'export': {\n const lines = [`# 画像导出 ${new Date().toISOString()}`, ''];\n for (const p of ['interest', 'projects', 'comm', 'psy'] as const) {\n lines.push(`## ${p}`);\n for (const e of doc.partitions[p]!.entries) {\n if (e.validTo !== null) continue;\n lines.push(`- [${e.topic}/${e.subTopic}] ${e.content} (conf ${e.confidence.toFixed(2)}, ${e.temporal})`);\n }\n }\n const out = path.join(paths.exportsDir, `profile-export-${Date.now()}.md`);\n writeText(guard, out, lines.join('\\n') + '\\n');\n console.log(`EXPORTED: ${out}`);\n return 0;\n }\n case 'verify': {\n const r = verifyProfile(guard, paths.dataDir);\n console.log(JSON.stringify(r, null, 2));\n return r.ok ? 0 : 1;\n }\n case 'rebuild': {\n const r = rebuildProfile(guard, paths.dataDir, { check: rest.includes('--check') });\n console.log(JSON.stringify(r, null, 2));\n return r.ok ? 0 : 1;\n }\n case 'wipe': {\n if (!rest.includes('--yes')) {\n console.log('REFUSED: add --yes to wipe profile data (live files, snapshot, journal archives, migration copies)');\n return 1;\n }\n // HB-21: the snapshot and the archive shards replay into the profile, so\n // the old three-file wipe was undone by the next rebuild (and migration\n // backups held yet another copy). wipeProfile covers everything the\n // profile can be rebuilt from — see its comment in profile/store.ts.\n const removed = wipeProfile(guard, paths.dataDir);\n console.log(`WIPED ${removed.length} file(s) (settings preserved; use burn for full shredding)`);\n for (const f of removed) console.log(` - ${f}`);\n return 0;\n }\n case 'snapshot': {\n const { snapshotDue, snapshotProfile, SNAPSHOT_THRESHOLD } = await import('../profile/snapshot.js');\n const { needed, lines } = snapshotDue(guard, paths.dataDir);\n console.log(`journal ${lines} 条(阈值 ${SNAPSHOT_THRESHOLD})`);\n if (!needed && !rest.includes('--force')) {\n console.log('未到阈值,未执行(加 --force 强制折叠)。');\n return 0;\n }\n const report = snapshotProfile(guard, paths.dataDir);\n if (!report.ok) {\n console.log(`未执行:${report.reason}`);\n return 0;\n }\n console.log(`已折叠 ${report.folded} 条 → 快照(baseline ${report.baselineTs}),归档 ${report.archiveFile},live journal 已清空。`);\n console.log('verify/rebuild 自动从快照基点重放,无需额外操作。');\n return 0;\n }\n default:\n console.error(`unknown profile subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbBurn(c: CliCtx): Promise<number> {\n const { guard, paths, rest } = c;\n const yes = rest.includes('--yes');\n const all = rest.includes('--all');\n const plan = planBurn(guard, paths, all);\n console.log('预演(不会执行):');\n for (const p of plan) console.log(` [${p.exists ? '存在' : '无 '}] ${p.target.file ?? p.target.dir} ${p.target.note}`);\n if (!yes) {\n console.log('\\n此操作会让心跳 agent 失忆。确认执行请加 --yes(' + (all ? '含 --all 连用户设定' : '用户设定保留') + ')');\n return 0;\n }\n const result = executeBurn(guard, paths, { all });\n console.log(`BURNED: ${result.burned.length} 项;MISSING: ${result.missing.length} 项`);\n return 0;\n}\n\nasync function verbMigrate(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n if (sub === 'export') {\n const defaultOut = path.join(paths.exportsDir, `heartbeat-memory-${localDayKey()}.hbmig`);\n const outfile = rest[0] ?? defaultOut;\n let outCanon: string;\n try {\n outCanon = guard.assert(outfile);\n } catch {\n console.error(`导出文件必须落在插件 data/ 目录内(路径守卫拒绝):${outfile}\\n默认位置:${defaultOut}`);\n return 1;\n }\n const [pw1, pw2] = await readLines(['设置口令(用于加密迁移包): ', '再输入一次确认: ']);\n if (!pw1 || pw1 !== pw2) {\n console.error('两次输入不一致或为空,已取消。');\n return 1;\n }\n const { entries, progress } = collectMigrationEntries(guard, paths);\n if (entries.length === 0) {\n console.log('没有可打包的记忆文件(data/ 是空的)。');\n return 1;\n }\n fs.mkdirSync(path.dirname(outCanon), { recursive: true });\n atomicWriteFileSync(outCanon, encryptContainer(entries, pw1));\n console.log(`已打包 ${entries.length} 个文件 → ${outCanon}`);\n console.log(` 打包:${progress.packed.join(', ')}`);\n if (progress.missing.length > 0) console.log(` 跳过(不存在):${progress.missing.join(', ')}`);\n console.log('容器是口令加密的,可安全拷贝到新机器;DPAPI 会在导入时用新机器重新加密。');\n return 0;\n }\n if (sub === 'import') {\n const infile = rest[0];\n if (!infile) {\n console.error('usage: migrate import <container-file>');\n return 1;\n }\n const [pw] = await readLines(['输入迁移包口令: ']);\n let text: string;\n try {\n text = fs.readFileSync(infile, 'utf8');\n } catch {\n console.error(`读不到迁移包:${infile}`);\n return 1;\n }\n let files;\n try {\n files = decryptContainer(text, pw ?? '');\n } catch (e) {\n console.error(String(e instanceof Error ? e.message : e));\n return 1;\n }\n const result = applyMigrationEntries(guard, paths, files.files);\n console.log(`恢复 ${result.restored.length} 个文件;备份 ${result.backedUp.length} 个被覆盖文件;跳过 ${result.skipped.length} 个。`);\n for (const r of result.restored) console.log(` 恢复: ${r}`);\n for (const b of result.backedUp) console.log(` 备份: ${b}.bak-migrate-*`);\n if (result.skipped.length > 0) console.log(` 跳过: ${result.skipped.join(', ')}`);\n if (result.error) console.log(` 失败并已回滚:${result.error}`);\n console.log('重启 DSH 后生效。');\n return result.error ? 1 : 0;\n }\n console.error(`unknown migrate subcommand: ${sub}`);\n return 1;\n}\n\nasync function verbSessions(c: CliCtx): Promise<number> {\n const { guard, paths } = c;\n // Read-only enumeration of the host's persisted sessions (ids from the\n // on-disk store; titles live server-side and are not listed here).\n const root = path.join(dshHomeDir(), 'sessions');\n let found = 0;\n if (fs.existsSync(root)) {\n const { homeSessionId } = await import('../core/orchestrator.js');\n const own = homeSessionId(guard, paths);\n for (const slug of fs.readdirSync(root)) {\n for (const id of fs.readdirSync(path.join(root, slug))) {\n found += 1;\n const mark = id === own ? ' ← 心跳正身' : '';\n console.log(`${id} [${slug}]${mark}`);\n }\n }\n }\n if (found === 0) console.log('(no persisted sessions found)');\n return 0;\n}\n\nasync function verbBind(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const { loadBindings, addBinding, removeBinding } = await import('../core/bindings.js');\n switch (sub) {\n case 'list': {\n const data = loadBindings(guard, paths.settingsDir);\n const { homeSessionId } = await import('../core/orchestrator.js');\n const own = homeSessionId(guard, paths);\n if (own) console.log(`心跳正身: ${own}(决策轮次发生地;bind remove 它 = 重置正身)`);\n for (const b of data.bindings) {\n console.log(`${b.sessionId} deliver:${b.deliver ? '√' : '×'} observe:${b.observe ? '√' : '×'}`);\n }\n if (data.bindings.length === 0 && !own) console.log('(no bindings — expressions stay in the dedicated heartbeat session)');\n return 0;\n }\n case 'add': {\n const id = rest[0];\n if (!id || !id.startsWith('session-')) {\n console.error('usage: bind add <sessionId> [--observe] [--no-deliver] (see: sessions list)');\n return 1;\n }\n const observe = rest.includes('--observe') || rest.includes('--observe-only');\n const deliver = !rest.includes('--no-deliver') && !rest.includes('--observe-only');\n const b = addBinding(guard, paths.settingsDir, id, { deliver, observe });\n console.log(`BOUND ${b.sessionId} deliver:${b.deliver} observe:${b.observe}`);\n return 0;\n }\n case 'remove': {\n const id = rest[0];\n if (!id) {\n console.error('usage: bind remove <sessionId>');\n return 1;\n }\n console.log(removeBinding(guard, paths.settingsDir, id) ? `UNBOUND ${id}` : 'NOT_FOUND');\n // Unbinding the HOME session resets it: the next beat creates a fresh\n // dedicated session (the old one goes quiet after restart). H-09/H-45:\n // the shared path also drops the orchestrator's cached agent — the\n // inline delete here used to leave it pointing at the released session.\n const { resetHomeSession } = await import('../core/orchestrator.js');\n if (resetHomeSession(guard, paths, id)) {\n console.log('注意:这是心跳正身会话。已重置——下次心跳将创建新的正身会话(旧会话不再有心跳)');\n }\n return 0;\n }\n default:\n console.error('usage: bind list | add <sessionId> | remove <sessionId>');\n return 1;\n }\n}\n\nasync function verbPreset(c: CliCtx): Promise<number> {\n const { sub, rest, argv } = c;\n const id = flag(argv, '--id') ?? BUNDLED_PRESET_ID;\n // The plugin installs into the roster's own user root; the CLI has no\n // roster, so it reports/uses the conventional one ($DSH_HOME or ~/.dsh).\n const root = conventionalUserPresetRoot();\n const status = presetStatus(import.meta.url, id, root);\n if (sub === undefined || sub === 'status') {\n console.log(`preset id : ${status.id}`);\n console.log(`installed : ${status.installed ? 'yes' : 'no'}`);\n console.log(`target dir : ${status.dir}`);\n console.log(`bundled at : ${status.bundledDir ?? '(not found next to the plugin)'}`);\n if (status.installed) {\n console.log(\n `composition : ${status.compositionMatches ? 'matches the bundled template' : 'differs from the bundled template (hand-edited, or an older version)'}`,\n );\n }\n if (!status.installed) {\n console.log('hint: the plugin installs this itself on the next DSH start (installPreset=true, default);');\n console.log(' or run `preset install` now.');\n }\n return status.installed ? 0 : 1;\n }\n if (sub === 'install') {\n const result = installBundledPreset({\n moduleUrl: import.meta.url,\n id,\n root,\n force: rest.includes('--force'),\n });\n console.log(describeInstall(result));\n return result.action === 'error' ? 1 : 0;\n }\n console.error('usage: preset status | install [--force] [--id <presetId>]');\n return 1;\n}\n\n/**\n * Encryption containers on disk. `upgrade` is the migration step v2.0 owes the\n * users of 1.x: reads already accept the legacy container, this rewrites the\n * files so the plugin stops shelling out to PowerShell for each of them.\n */\nasync function verbVault(c: CliCtx): Promise<number> {\n const { guard, paths, sub } = c;\n const keyFile = vaultKeyPath();\n const files = matchFilesRecursive(paths.dataDir, /./).filter(\n (rel) => rel !== 'vault.key' && !rel.startsWith('tmp/'),\n );\n const counts = { v1: 0, v2: 0, plain: 0 };\n for (const rel of files) {\n counts[containerKind(path.join(paths.dataDir, rel.split('/').join(path.sep)))] += 1;\n }\n if (sub === undefined || sub === 'status') {\n console.log(`data dir : ${paths.dataDir}`);\n console.log(`master key : ${keyFile}${fs.existsSync(keyFile) ? '' : ' (not created yet; the next write makes it)'}`);\n console.log(`containers : ${counts.v2} KHBV2 (current), ${counts.v1} KHBV1 (legacy), ${counts.plain} plaintext`);\n if (counts.v1 > 0) console.log('hint: run `vault upgrade` to rewrite the legacy files in place.');\n return 0;\n }\n if (sub === 'upgrade') {\n const r = upgradeVaultTree(guard, paths.dataDir);\n console.log(`UPGRADED ${r.upgraded} of ${r.scanned} file(s) to KHBV2`);\n for (const f of r.failed) console.log(` ! ${f.file}: ${f.reason}`);\n return r.failed.length === 0 ? 0 : 1;\n }\n console.error('usage: vault status | upgrade');\n return 1;\n}\n\n/**\n * Focus mode (v2.1.0): runtime pause of the beat, no policy file involved.\n *\n * CROSS-PROCESS BOUNDARY: this CLI is its own process (`node dist/cli/index.js`),\n * so `pauseFocus()` here only ever touched the CLI's own module variable — the\n * host kept beating. The pause therefore lives in data/focus.json: this command\n * writes it, the host's beat() reads it at the top of every tick. The RPC path\n * (settings card) keeps module state AND the file in sync.\n */\nasync function verbFocus(c: CliCtx): Promise<number> {\n const { sub, rest, decisionLog } = c;\n const { readFocusState, writeFocusState, clearFocusState } = await import('../core/focus-store.js');\n const { formatFocusClock } = await import('../core/orchestrator.js');\n const audit = (entry: Record<string, unknown>): void => {\n try {\n appendAuditLine(decisionLog, entry);\n } catch { /* audit must never break the command */ }\n };\n const minutes = Number(sub);\n if (sub === 'off') {\n clearFocusState(c.guard, c.paths);\n audit({ event: 'focus_resumed', via: 'cli' });\n console.log('FOCUS_OFF');\n return 0;\n }\n if ((sub ?? '').trim() !== '' && Number.isFinite(minutes) && minutes > 0) {\n const state = writeFocusState(c.guard, c.paths, minutes, Date.now(), 'cli');\n audit({ event: 'focus_paused', via: 'cli', minutes: state.minutes, until: new Date(state.until).toISOString() });\n console.log(`FOCUSED until ${new Date(state.until).toISOString()} (${formatFocusClock(state.until)})`);\n return 0;\n }\n if (sub === undefined && rest.length === 0) {\n const state = readFocusState(c.guard, c.paths);\n if (state) {\n console.log(`FOCUSED until ${new Date(state.until).toISOString()} (${formatFocusClock(state.until)}), set via ${state.via}`);\n } else {\n console.log('FOCUS_OFF (beats run on the normal rhythm; use `focus <minutes>` to pause)');\n }\n return 0;\n }\n console.error('usage: heartbeat focus <minutes> | focus off | focus');\n return 1;\n}\n\n/** Command table. Adding a verb = one function above plus one line here. */\nconst VERBS: Record<string, Verb> = {\n status: verbStatus,\n seeds: verbSeeds,\n ledger: verbLedger,\n excerpt: verbExcerpt,\n weekly: verbWeekly,\n logs: verbLogs,\n browse: verbBrowse,\n focus: verbFocus,\n notify: verbNotify,\n profile: verbProfile,\n vault: verbVault,\n burn: verbBurn,\n migrate: verbMigrate,\n sessions: verbSessions,\n bind: verbBind,\n preset: verbPreset,\n};\n\nexport async function main(argv: string[]): Promise<number> {\n const [cmd, sub, ...rest] = argv;\n if (!cmd || cmd === 'help' || cmd === '--help') {\n console.log(usage());\n return 0;\n }\n const verb = VERBS[cmd];\n if (!verb) {\n console.error(`unknown command: ${cmd}`);\n console.log(usage());\n return 1;\n }\n const paths = initWorkspace();\n const guard = createPathGuard(paths.dataDir);\n const policy = loadPolicy(guard, paths.configDir, paths.settingsDir);\n const decisionLog = path.join(paths.logsDir, 'heartbeat.jsonl');\n /** Seed lifecycle audit (v1.9.0): CLI edits land in the same log as the beat's. */\n const seedAudit = (entry: Record<string, unknown>): void => {\n try {\n appendAuditLine(decisionLog, entry);\n } catch { /* audit must never break the command */ }\n };\n return verb({\n paths,\n guard,\n policy,\n sub,\n rest,\n argv,\n seedsFile: seedsFilePath(paths.dataDir),\n ledgerFile: ledgerFilePath(paths.dataDir),\n excerptFile: excerptFilePath(paths.dataDir),\n decisionLog,\n seedAudit,\n });\n}\n\nif (process.argv[1] && import.meta.url === new URL(`file:///${process.argv[1].replace(/\\\\/g, '/')}`).href) {\n // Direct execution guard; the CLI is also importable for tests.\n void main(process.argv.slice(2))\n .then((code) => { process.exitCode = code; })\n .catch((e: unknown) => {\n // H-44: no unhandled rejection — print and exit non-zero.\n console.error(e);\n process.exitCode = 1;\n });\n}\n","// Burn list - SINGLE SOURCE OF TRUTH (design doc §10.10; v1 shipped two\n// hardcoded lists and one drifted). burn and uninstall --purge both consume\n// this list. Settings (data/settings/) are NOT burned by default: losing\n// memory != losing the charter/gates the user configured (--all overrides).\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport type { PathGuard } from '../core/path-guard.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { shredFileSync } from '../core/atomic-fs.js';\nimport { appendAuditLine } from '../core/audit-log.js';\nimport { matchFilesRecursive } from '../core/fs-walk.js';\n\nexport interface BurnTarget {\n /** Relative to dataDir. Files are shredded (overwrite x3) then deleted. */\n file?: string;\n /** Every dataDir file whose name starts with this prefix — a family of\n * timestamped files a bare `file` cannot name (journal archive shards).\n * Shredded like files. */\n prefix?: string;\n /** Every file ANYWHERE below dataDir whose NAME matches this pattern. Used for\n * families a prefix cannot reach: `${name}.bak-migrate-${stamp}` and the\n * `.incoming-` staging leftovers sit next to whatever they copied, which may\n * be a subdirectory. Shredded like files. */\n match?: RegExp;\n /** Directories are removed recursively (no shred - content is files). */\n dir?: string;\n note: string;\n}\n\nexport const BURN_LIST: BurnTarget[] = [\n { file: 'profile.json', note: '画像物化视图' },\n { file: 'profile_inbox.jsonl', note: '观察收件箱' },\n { file: 'profile_journal.jsonl', note: '画像操作流水' },\n // H-19: the rotation shards hold the whole profile history and are written\n // in PLAINTEXT — a burn that leaves them behind leaves the memory readable.\n { prefix: 'profile_journal.archive-', note: '画像流水归档分片(明文;journal 轮转产物)' },\n // HB-07 (2026-10-17): applyMigrationEntries copies every file it overwrites\n // to `${abs}.bak-migrate-${stamp}`. Those copies hold the OLD memory — a burn\n // that left them behind left the thing the user asked to destroy. The\n // `.incoming-` staging files are the same data, only younger.\n { match: /\\.bak-migrate-\\d{14}$/, note: '迁移备份(迁移导入时的原文件副本)' },\n { match: /\\.incoming-\\d{14}$/, note: '迁移暂存残留(崩溃遗留的导入副本)' },\n { file: 'profile_rhythm.json', note: '作息聚合(纯统计)' },\n { file: 'screen.json', note: '屏幕快照(加密)' },\n { file: 'screen.jpg', note: '截图(加密)' },\n { file: 'sent.json', note: '表达记录(加密)' },\n { file: 'browse.json', note: '浏览流状态(加密)' },\n { file: 'seeds.jsonl', note: '素材池(加密)' },\n { file: 'ledger.md', note: '账本(明文,人可读是设计目标)' },\n { file: 'envpulse.json', note: '环境温度计快照' },\n { file: 'gate.json', note: '闸门运行时计数' },\n // v1.9.0 completion (H-19): these carry memory just as much as the rows\n // above — the persona report log records WHAT SHE SAID (spoken / seed_ids /\n // profile_ids / reason), so a burn that skips it is a burn that lies.\n { file: 'profile_snapshot.json', note: '画像快照(journal 轮转基线)' },\n { file: 'cursors.json', note: '观察游标(会话事件位点)' },\n { file: 'seed_report.jsonl', note: '投递报账日志(加密)' },\n { file: 'preference.json', note: '话题偏好统计' },\n { dir: 'weekly', note: '周报(画像与素材散文)' },\n { dir: 'tmp', note: '解锁临时文件(崩溃残留的解密明文是最该烧的东西)' },\n { dir: 'logs', note: '审计与决策日志' },\n { dir: 'exports', note: '导出产物' },\n];\n\nconst SETTINGS_DIR = 'settings'; // excluded unless --all\n\n/** dataDir files matching a prefix target, name-sorted for stable output. */\nfunction prefixMatches(guard: PathGuard, paths: WorkspacePaths, prefix: string): string[] {\n try {\n return fs.readdirSync(guard.assert(paths.dataDir))\n .filter((f) => f.startsWith(prefix))\n .sort();\n } catch {\n return [];\n }\n}\n\n/** Same as prefixMatches, but for the recursive `match` family. */\nfunction matchTargets(guard: PathGuard, paths: WorkspacePaths, re: RegExp): string[] {\n try {\n return matchFilesRecursive(guard.assert(paths.dataDir), re);\n } catch {\n return [];\n }\n}\n\nexport interface BurnPlanItem {\n target: BurnTarget;\n exists: boolean;\n}\n\n/** Preview: what exists, what would be removed. No writes. */\nexport function planBurn(guard: PathGuard, paths: WorkspacePaths, all = false): BurnPlanItem[] {\n const plan: BurnPlanItem[] = [];\n for (const t of BURN_LIST) {\n const rel = t.file ?? t.dir ?? t.prefix ?? String(t.match ?? '');\n if (!all && rel === SETTINGS_DIR) continue;\n let exists = false;\n if (t.match) {\n exists = matchTargets(guard, paths, t.match).length > 0;\n } else if (t.prefix) {\n exists = prefixMatches(guard, paths, t.prefix).length > 0;\n } else {\n try {\n exists = fs.existsSync(guard.assert(path.join(paths.dataDir, rel)));\n } catch {\n exists = false;\n }\n }\n plan.push({ target: t, exists });\n }\n if (all) {\n plan.push({ target: { dir: SETTINGS_DIR, note: '用户设定(隐私宪章/闸门参数)——仅 --all 连带' }, exists: fs.existsSync(paths.settingsDir) });\n }\n return plan;\n}\n\n/**\n * Execute the burn: overwrite x3 + delete files, remove dirs. Irreversible.\n * Returns per-target results and writes a BURN_EVENT into the (recreated)\n * journal afterwards - the only trace, on purpose (transparency).\n */\nexport function executeBurn(\n guard: PathGuard,\n paths: WorkspacePaths,\n opts: { all?: boolean; shredPasses?: number } = {},\n): { burned: string[]; missing: string[] } {\n const burned: string[] = [];\n const missing: string[] = [];\n const passes = opts.shredPasses ?? 3;\n for (const t of BURN_LIST) {\n if (t.match) {\n const matches = matchTargets(guard, paths, t.match);\n if (matches.length === 0) {\n missing.push(String(t.match));\n continue;\n }\n for (const f of matches) {\n try {\n shredFileSync(guard.assert(path.join(paths.dataDir, f)), passes);\n burned.push(f);\n } catch { /* vanished between listing and shredding: not fatal */ }\n }\n continue;\n }\n // H-19: a prefix target is a family of files (timestamped archive shards);\n // shred every match individually.\n if (t.prefix) {\n const matches = prefixMatches(guard, paths, t.prefix);\n if (matches.length === 0) {\n missing.push(`${t.prefix}*`);\n continue;\n }\n for (const f of matches) {\n try {\n shredFileSync(guard.assert(path.join(paths.dataDir, f)), passes);\n burned.push(f);\n } catch { /* vanished between listing and shredding: not fatal */ }\n }\n continue;\n }\n const rel = t.file ?? t.dir ?? String(t.match ?? '');\n const abs = path.join(paths.dataDir, rel);\n let absCanon: string;\n try {\n absCanon = guard.assert(abs);\n } catch {\n missing.push(rel);\n continue;\n }\n if (t.file) {\n if (fs.existsSync(absCanon)) {\n shredFileSync(absCanon, passes);\n burned.push(rel);\n } else {\n missing.push(rel);\n }\n } else if (fs.existsSync(absCanon)) {\n fs.rmSync(absCanon, { recursive: true, force: true });\n burned.push(rel);\n } else {\n missing.push(rel);\n }\n }\n if (opts.all) {\n fs.rmSync(paths.settingsDir, { recursive: true, force: true });\n burned.push(SETTINGS_DIR);\n }\n // BURN_EVENT: recreate the journal; data dir is now re-initializable.\n appendAuditLine(guard.assert(path.join(paths.dataDir, 'profile_journal.jsonl')), {\n event: 'BURN_EVENT',\n burned: burned.length,\n missing: missing.length,\n settingsPreserved: !opts.all,\n });\n return { burned, missing };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,SAAS,aAAa;AACtB,OAAOA,SAAQ;AACf,OAAOC,WAAU;;;ACLjB,OAAO,QAAQ;AACf,OAAO,UAAU;AAwBV,IAAM,YAA0B;AAAA,EACrC,EAAE,MAAM,gBAAgB,MAAM,uCAAS;AAAA,EACvC,EAAE,MAAM,uBAAuB,MAAM,iCAAQ;AAAA,EAC7C,EAAE,MAAM,yBAAyB,MAAM,uCAAS;AAAA;AAAA;AAAA,EAGhD,EAAE,QAAQ,4BAA4B,MAAM,iHAA4B;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxE,EAAE,OAAO,yBAAyB,MAAM,yGAAoB;AAAA,EAC5D,EAAE,OAAO,sBAAsB,MAAM,yGAAoB;AAAA,EACzD,EAAE,MAAM,uBAAuB,MAAM,yDAAY;AAAA,EACjD,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gB,aAAa,KAAK;AAAA,IACpC,QAAQ;AAAA,IAA2C;AAAA,EACrD;AACA,SAAO,KAAK;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,cAAc,MAAM,OAAO;AAAA,IACtC,YAAY,eAAe,MAAM,OAAO;AAAA,IACxC,aAAa,gBAAgB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,IAAI,QAAQ,KAAK,CAAC,KAAK,YAAY,QAAQ,IAAI,IAAI,WAAW,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG,CAAC,EAAE,EAAE,MAAM;AAEzG,OAAK,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAC5B,KAAK,CAAC,SAAS;AAAE,YAAQ,WAAW;AAAA,EAAM,CAAC,EAC3C,MAAM,CAAC,MAAe;AAErB,YAAQ,MAAM,CAAC;AACf,YAAQ,WAAW;AAAA,EACrB,CAAC;AACL;","names":["fs","path","fs","path"]}
1
+ {"version":3,"sources":["../../src/cli/index.ts","../../src/vault/burn-list.ts"],"sourcesContent":["// Operational CLI (design doc §14). Commands grow per module.\n// Run: node dist/cli/index.js <command> [args] (or via tsx in dev)\n//\n// H-42: `main` used to be a 530-line function with a switch holding every\n// verb's body. The verbs are module-level functions now (see CliCtx below) and\n// `main` only builds the shared context and dispatches — one place to add a\n// command, and each verb is readable on its own.\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { dshHomeDir, initWorkspace } from '../core/paths.js';\nimport { openPath } from '../core/open-path.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { createPathGuard } from '../core/path-guard.js';\nimport type { PathGuard } from '../core/path-guard.js';\nimport { appendAuditLine, pruneAuditFile } from '../core/audit-log.js';\nimport { atomicWriteFileSync } from '../core/atomic-fs.js';\nimport { localDayKey } from '../core/time-window.js';\nimport { loadPolicy } from '../config/load.js';\nimport type { Policy } from '../config/schema.js';\nimport {\n addSeed,\n archiveSeedById,\n gcPool,\n loadPool,\n activeSeeds,\n archivedSeeds,\n seedsFilePath,\n surfaceSeed,\n} from '../seeds/pool.js';\nimport type { SeedSource, SeedTag } from '../seeds/types.js';\nimport {\n appendEntry,\n ledgerFilePath,\n markDone,\n readLedger,\n scanPending,\n} from '../ledger/ledger.js';\nimport {\n EXCERPT_HEADER,\n appendExcerpt,\n excerptFilePath,\n readExcerpts,\n removeExcerpt,\n} from '../excerpt/excerpt.js';\nimport {\n adviseWander,\n browseStatus,\n completeWander,\n loadInterests,\n} from '../browse/browse.js';\nimport { ensureRegistered, sendNewMessageHint } from '../notify/notify.js';\nimport {\n loadProfile,\n profileFilePath,\n verifyProfile,\n rebuildProfile,\n wipeProfile,\n} from '../profile/store.js';\nimport { planBurn, executeBurn } from '../vault/burn-list.js';\nimport {\n collectMigrationEntries,\n encryptContainer,\n decryptContainer,\n applyMigrationEntries,\n} from '../vault/migrate.js';\nimport { listWeeklyReports, readWeeklyReport, weeklyDirPath } from '../weekly/report.js';\nimport {\n containerKind,\n upgradeVaultTree,\n vaultKeyPath,\n writeText,\n} from '../vault/vault.js';\nimport { matchFilesRecursive } from '../core/fs-walk.js';\nimport {\n BUNDLED_PRESET_ID,\n conventionalUserPresetRoot,\n describeInstall,\n installBundledPreset,\n presetStatus,\n} from '../core/preset-install.js';\n\nfunction usage(): string {\n return [\n 'usage: heartbeat <command> [args]',\n '',\n 'commands:',\n ' status workspace paths + policy summary',\n ' seeds add <text> [--tag t] [--source s] [--topic x] [--confidence n]',\n ' seeds list [--archived] list active (or archived) seeds',\n ' seeds surface <id> count a surfacing (rule 1 accounting)',\n ' seeds archive <id> deliberate retirement (completed)',\n ' seeds gc run deterministic eviction rules 1-3',\n ' seeds stats pool status JSON',\n ' ledger add <text> register an open item',\n ' ledger list [--pending] list entries',\n ' ledger done <id|substring> mark an entry done',\n ' ledger open open ledger.md in the default editor',\n ' excerpt add <text> keep a line in the notebook',\n ' excerpt list [n] list entries (newest n if given)',\n ' excerpt remove <id|substring> tear a page out',\n ' excerpt open open excerpts.md in the default editor',\n ' logs cleanup [--dry-run] apply log retention now',\n ' browse status browse state summary (wander)',\n ' browse dry wander adjudication with forced noon window',\n ' browse done <focus> CODE-side registration after a wander visit',\n ' focus focus-mode status (paused until HH:MM or not)',\n ' focus <minutes> pause the heartbeat for N minutes (1-1440)',\n ' focus off lift the pause now',\n ' bind list list session bindings (D13)',\n ' bind add <sessionId> [--observe] bind a session (deliver by default)',\n ' bind remove <sessionId> unbind a session',\n ' sessions list enumerate persisted sessions (ids)',\n ' notify check|register|send toast channel (D12: hint only, no body)',\n ' profile list [--all] current valid (or all incl. expired) entries',\n ' profile export decrypted Markdown export to data/exports/',\n ' profile verify journal replay vs disk (report only)',\n ' profile rebuild [--check] rebuild materialized view from journal',\n ' profile snapshot [--force] fold the journal into a snapshot + archive shard',\n ' profile wipe wipe profile data (asks --yes)',\n ' weekly list list generated weekly reports',\n ' weekly show [file] print a report (default: newest)',\n ' vault status encryption containers on disk + master key file',\n ' vault upgrade rewrite legacy KHBV1 files as KHBV2 (in place)',\n ' migrate export [file] pack memory files into a passphrase container (passphrase: 2 stdin lines)',\n ' migrate import <file> restore a container into this workspace (passphrase: 1 stdin line)',\n ' burn [--yes] [--all] shred runtime data (settings kept unless --all)',\n ' preset status bundled agent preset: target dir + installed?',\n ' preset install [--force] install the bundled preset (never overwrites unless --force)',\n ' bili login bilibili 扫码登录,SESSDATA 写入 vault (bilibili-session.json)',\n ].join('\\n');\n}\n\nfunction readStdinText(): string {\n try {\n return fs.readFileSync(0, 'utf8').trim();\n } catch {\n return '';\n }\n}\n\nfunction flag(argv: string[], name: string): string | undefined {\n const i = argv.indexOf(name);\n return i > -1 ? argv[i + 1] : undefined;\n}\n\n/** H-42: the seed flags used to be written `flag(rest, '--tag') as never` — the\n * escape hatch threw the type away, so a typo landed in the seed record\n * unchecked. Validate against the known sets instead (the `satisfies` clauses\n * keep these lists in step with the types). */\nconst SEED_TAGS = ['news', 'fandom', 'scene', 'promise'] as const satisfies readonly SeedTag[];\nconst SEED_SOURCES = ['chat', 'screen', 'browse', 'bilibili', 'hand', 'profile'] as const satisfies readonly SeedSource[];\n\nfunction flagOneOf<T extends string>(argv: string[], name: string, allowed: readonly T[]): T | undefined {\n const v = flag(argv, name);\n if (v === undefined) return undefined;\n return (allowed as readonly string[]).includes(v) ? (v as T) : undefined;\n}\n\n/** Read N lines from stdin (passphrase prompts for migrate). */\nasync function readLines(prompts: string[]): Promise<string[]> {\n const readline = await import('node:readline/promises');\n const it = readline.createInterface({ input: process.stdin });\n const out: string[] = [];\n for (const p of prompts) out.push((await it.question(p)).trim());\n it.close();\n return out;\n}\n\n/** Everything a verb needs. Built once in {@link main}; `sub`/`rest` are the\n * positional split of argv, `argv` stays available for top-level flags. */\ninterface CliCtx {\n paths: WorkspacePaths;\n guard: PathGuard;\n policy: Policy;\n sub: string | undefined;\n rest: string[];\n argv: string[];\n seedsFile: string;\n ledgerFile: string;\n excerptFile: string;\n decisionLog: string;\n seedAudit: (entry: Record<string, unknown>) => void;\n}\n\ntype Verb = (c: CliCtx) => Promise<number>;\n\nasync function verbStatus(c: CliCtx): Promise<number> {\n const { paths, policy } = c;\n console.log(JSON.stringify({\n dataDir: paths.dataDir,\n heartbeatIntervalMin: policy.heartbeat.intervalMin,\n maxDailySend: policy.gate.maxDailySend,\n seedsMaxActive: policy.seeds.maxActive,\n psyEnabled: policy.profile.psyEnabled,\n }, null, 2));\n return 0;\n}\n\nasync function verbSeeds(c: CliCtx): Promise<number> {\n const { guard, policy, sub, rest, seedsFile, seedAudit } = c;\n switch (sub) {\n case 'add': {\n let text = rest[0]?.trim() ?? '';\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: seeds add <text|-> [--tag t] [--source s] [--topic x] [--confidence n]');\n return 1;\n }\n const result = addSeed(guard, seedsFile, policy, {\n text,\n tag: flagOneOf(rest, '--tag', SEED_TAGS),\n source: flagOneOf(rest, '--source', SEED_SOURCES),\n topic: flag(rest, '--topic'),\n confidence: flag(rest, '--confidence') ? Number(flag(rest, '--confidence')) : undefined,\n }, Date.now(), seedAudit);\n if (result.kind === 'duplicate') {\n console.log(`DUPLICATE: active seed ${result.seed.id} has the same text`);\n return 0;\n }\n console.log(`${result.kind.toUpperCase()} ${result.seed.id}` +\n ` (${activeSeeds(loadPool(guard, seedsFile)).length}/${policy.seeds.maxActive})` +\n (result.evicted ? ` [evicted ${result.evicted.id}: ${result.evicted.retireReason}]` : ''));\n return 0;\n }\n case 'list': {\n const db = loadPool(guard, seedsFile);\n const items = rest.includes('--archived') ? archivedSeeds(db) : activeSeeds(db);\n for (const s of items) {\n const ageDays = Math.floor((Date.now() - Date.parse(s.bornAt)) / 86_400_000);\n console.log(`${s.id} [${s.tag}/${s.source}] d${ageDays} used:${s.used}` +\n `${s.protected ? ' *' : ''} ${s.text.slice(0, 60)}`);\n }\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'surface': {\n const s = surfaceSeed(guard, seedsFile, policy, rest[0] ?? '', Date.now(), seedAudit);\n if (!s) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`SURFACED ${s.id} used:${s.used}${s.status === 'archived' ? ' -> archived (consumed)' : ''}`);\n return 0;\n }\n case 'archive': {\n const s = archiveSeedById(guard, seedsFile, rest[0] ?? '', 'completed', Date.now(), seedAudit);\n if (!s) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`ARCHIVED ${s.id}`);\n return 0;\n }\n case 'gc': {\n const report = gcPool(guard, seedsFile, policy, Date.now(), seedAudit);\n console.log(`GC consumed:${report.consumed} expired:${report.expired} cold_bench:${report.coldBench}` +\n ` archive_trimmed:${report.archiveTrimmed} -> active ${report.activeAfter}/${policy.seeds.maxActive}` +\n ` archive ${archivedSeeds(loadPool(guard, seedsFile)).length}/${policy.seeds.archiveCap}`);\n return 0;\n }\n case 'stats': {\n const db = loadPool(guard, seedsFile);\n console.log(JSON.stringify({\n active: activeSeeds(db).length,\n archived: archivedSeeds(db).length,\n cap: policy.seeds.maxActive,\n seq: db.seq,\n }, null, 2));\n return 0;\n }\n default:\n console.error(`unknown seeds subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbLedger(c: CliCtx): Promise<number> {\n const { guard, sub, rest, ledgerFile } = c;\n switch (sub) {\n case 'add': {\n let text = rest.join(' ').trim();\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: ledger add <text|->');\n return 1;\n }\n const e = appendEntry(guard, ledgerFile, text);\n console.log(`OPEN #${e.id} ${e.text.slice(0, 60)}`);\n return 0;\n }\n case 'list': {\n const { entries } = readLedger(guard, ledgerFile);\n const items = rest.includes('--pending') ? scanPending(guard, ledgerFile) : entries;\n for (const e of items) console.log(`${e.status === 'open' ? ' ' : 'x'} #${e.id} ${e.date} ${e.text.slice(0, 60)}`);\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'done': {\n const key = rest.join(' ').trim();\n if (!key) {\n console.error('usage: ledger done <id|substring>');\n return 1;\n }\n const e = markDone(guard, ledgerFile, key);\n if (!e) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`DONE #${e.id}`);\n return 0;\n }\n case 'open': {\n const f = ledgerFile;\n if (!fs.existsSync(f)) {\n console.log(`(ledger will be created at ${f})`);\n }\n openPath(f);\n console.log(`opened ${f}`);\n return 0;\n }\n default:\n console.error(`unknown ledger subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbExcerpt(c: CliCtx): Promise<number> {\n const { guard, sub, rest, excerptFile } = c;\n switch (sub) {\n case 'add': {\n let text = rest.join(' ').trim();\n if (text === '-') text = readStdinText();\n if (!text) {\n console.error('usage: excerpt add <text|->');\n return 1;\n }\n const e = appendExcerpt(guard, excerptFile, text);\n console.log(`KEPT #${e.id} ${e.text.slice(0, 60)}`);\n return 0;\n }\n case 'list': {\n const all = readExcerpts(guard, excerptFile).entries;\n const n = Number.parseInt(rest[0] ?? '', 10);\n const items = Number.isFinite(n) && n > 0 ? all.slice(-n) : all;\n for (const e of items) console.log(`#${e.id} ${e.date} ${e.time} ${e.text.slice(0, 60)}`);\n if (items.length === 0) console.log('(empty)');\n return 0;\n }\n case 'remove': {\n const key = rest.join(' ').trim();\n if (!key) {\n console.error('usage: excerpt remove <id|substring>');\n return 1;\n }\n const e = removeExcerpt(guard, excerptFile, key);\n if (!e) {\n console.log('NOT_FOUND');\n return 1;\n }\n console.log(`REMOVED #${e.id}`);\n return 0;\n }\n case 'open': {\n const f = excerptFile;\n if (!fs.existsSync(f)) {\n fs.mkdirSync(path.dirname(f), { recursive: true });\n fs.writeFileSync(f, EXCERPT_HEADER, 'utf8');\n }\n openPath(f);\n console.log(`opened ${f}`);\n return 0;\n }\n default:\n console.error(`unknown excerpt subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbWeekly(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const reports = listWeeklyReports(guard, paths.dataDir);\n if (sub === 'list' || sub === undefined) {\n if (reports.length === 0) console.log('(no reports yet — heartbeat generates one every 7 days)');\n for (const r of reports) console.log(`${r.file} ${r.start.slice(0, 10)} ~ ${r.end.slice(0, 10)} [${r.source}]`);\n return 0;\n }\n if (sub === 'show') {\n const file = rest[0] ?? reports[0]?.file;\n if (!file) {\n console.log('(no reports yet)');\n return 1;\n }\n const rep = readWeeklyReport(guard, paths.dataDir, file);\n if (!rep) {\n console.error(`no such report: ${file} (see: weekly list; files live in ${weeklyDirPath(paths.dataDir)})`);\n return 1;\n }\n console.log(`# ${rep.start.slice(0, 10)} ~ ${rep.end.slice(0, 10)} [${rep.source}]`);\n console.log(rep.text);\n return 0;\n }\n console.error(`unknown weekly subcommand: ${sub}`);\n return 1;\n}\n\nasync function verbLogs(c: CliCtx): Promise<number> {\n const { paths, policy, sub, rest, decisionLog } = c;\n if (sub !== 'cleanup') {\n console.error('usage: logs cleanup [--dry-run]');\n return 1;\n }\n const dry = rest.includes('--dry-run');\n const envPulse = path.join(paths.logsDir, 'envpulse.jsonl');\n const cut1 = policy.retention.envPulseHours * 3600_000;\n const cut2 = policy.retention.decisionLogDays * 86_400_000;\n if (dry) {\n console.log(`(dry-run) would prune ${envPulse} to ${policy.retention.envPulseHours}h` +\n ` and ${decisionLog} to ${policy.retention.decisionLogDays}d`);\n return 0;\n }\n const a = pruneAuditFile(envPulse, cut1);\n const b = pruneAuditFile(decisionLog, cut2);\n appendAuditLine(decisionLog, { event: 'retention', pruned_envpulse: a, pruned_decision: b });\n console.log(`PRUNED envpulse:${a} decision:${b}`);\n return 0;\n}\n\nasync function verbBrowse(c: CliCtx): Promise<number> {\n const { guard, paths, policy, sub, rest } = c;\n switch (sub) {\n case 'status': {\n const st = browseStatus(guard, paths);\n const interests = loadInterests(paths);\n console.log(JSON.stringify({\n lastWanderAt: st.wander.last_wander_at ? new Date(st.wander.last_wander_at).toISOString() : null,\n focusCount: st.wander.focusCount,\n interestCount: interests.interests?.length ?? 0,\n }, null, 2));\n return 0;\n }\n case 'dry': {\n const forced = new Date();\n forced.setHours(12, 0, 0, 0);\n const advice = adviseWander(guard, paths, policy, forced);\n console.log(JSON.stringify(advice, null, 2));\n return 0;\n }\n case 'done': {\n const focus = rest.join(' ').trim();\n if (!focus) {\n console.error('usage: browse done <focus>');\n return 1;\n }\n const r = completeWander(guard, paths, focus);\n console.log(JSON.stringify(r));\n return 0;\n }\n default:\n console.error(`unknown browse subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbNotify(c: CliCtx): Promise<number> {\n const { paths, sub } = c;\n switch (sub) {\n case 'check':\n console.log(await ensureRegistered(paths) ? 'REGISTERED: yes' : 'REGISTERED: no');\n return 0;\n case 'register':\n await ensureRegistered(paths);\n console.log('register attempted');\n return 0;\n case 'send':\n console.log(await sendNewMessageHint(paths) ? 'SENT' : 'FAILED');\n return 0;\n default:\n console.error('usage: notify check|register|send');\n return 1;\n }\n}\n\nasync function verbProfile(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const doc = loadProfile(guard, profileFilePath(paths.dataDir));\n const all = rest.includes('--all');\n switch (sub) {\n case 'list': {\n let n = 0;\n for (const p of ['interest', 'projects', 'comm', 'psy'] as const) {\n for (const e of doc.partitions[p]!.entries) {\n if (!all && e.validTo !== null) continue;\n n += 1;\n console.log(`${e.id} [${e.partition}/${e.topic}/${e.subTopic}] ${e.temporal}` +\n ` conf=${e.confidence.toFixed(2)}${e.lowActivity ? ' 久未验证' : ''}${e.validTo ? ' [失效]' : ''}: ${e.content.slice(0, 60)}`);\n }\n }\n if (n === 0) console.log('(empty)');\n return 0;\n }\n case 'export': {\n const lines = [`# 画像导出 ${new Date().toISOString()}`, ''];\n for (const p of ['interest', 'projects', 'comm', 'psy'] as const) {\n lines.push(`## ${p}`);\n for (const e of doc.partitions[p]!.entries) {\n if (e.validTo !== null) continue;\n lines.push(`- [${e.topic}/${e.subTopic}] ${e.content} (conf ${e.confidence.toFixed(2)}, ${e.temporal})`);\n }\n }\n const out = path.join(paths.exportsDir, `profile-export-${Date.now()}.md`);\n writeText(guard, out, lines.join('\\n') + '\\n');\n console.log(`EXPORTED: ${out}`);\n return 0;\n }\n case 'verify': {\n const r = verifyProfile(guard, paths.dataDir);\n console.log(JSON.stringify(r, null, 2));\n return r.ok ? 0 : 1;\n }\n case 'rebuild': {\n const r = rebuildProfile(guard, paths.dataDir, { check: rest.includes('--check') });\n console.log(JSON.stringify(r, null, 2));\n return r.ok ? 0 : 1;\n }\n case 'wipe': {\n if (!rest.includes('--yes')) {\n console.log('REFUSED: add --yes to wipe profile data (live files, snapshot, journal archives, migration copies)');\n return 1;\n }\n // HB-21: the snapshot and the archive shards replay into the profile, so\n // the old three-file wipe was undone by the next rebuild (and migration\n // backups held yet another copy). wipeProfile covers everything the\n // profile can be rebuilt from — see its comment in profile/store.ts.\n const removed = wipeProfile(guard, paths.dataDir);\n console.log(`WIPED ${removed.length} file(s) (settings preserved; use burn for full shredding)`);\n for (const f of removed) console.log(` - ${f}`);\n return 0;\n }\n case 'snapshot': {\n const { snapshotDue, snapshotProfile, SNAPSHOT_THRESHOLD } = await import('../profile/snapshot.js');\n const { needed, lines } = snapshotDue(guard, paths.dataDir);\n console.log(`journal ${lines} 条(阈值 ${SNAPSHOT_THRESHOLD})`);\n if (!needed && !rest.includes('--force')) {\n console.log('未到阈值,未执行(加 --force 强制折叠)。');\n return 0;\n }\n const report = snapshotProfile(guard, paths.dataDir);\n if (!report.ok) {\n console.log(`未执行:${report.reason}`);\n return 0;\n }\n console.log(`已折叠 ${report.folded} 条 → 快照(baseline ${report.baselineTs}),归档 ${report.archiveFile},live journal 已清空。`);\n console.log('verify/rebuild 自动从快照基点重放,无需额外操作。');\n return 0;\n }\n default:\n console.error(`unknown profile subcommand: ${sub}`);\n return 1;\n }\n}\n\nasync function verbBurn(c: CliCtx): Promise<number> {\n const { guard, paths, rest } = c;\n const yes = rest.includes('--yes');\n const all = rest.includes('--all');\n const plan = planBurn(guard, paths, all);\n console.log('预演(不会执行):');\n for (const p of plan) console.log(` [${p.exists ? '存在' : '无 '}] ${p.target.file ?? p.target.dir} ${p.target.note}`);\n if (!yes) {\n console.log('\\n此操作会让心跳 agent 失忆。确认执行请加 --yes(' + (all ? '含 --all 连用户设定' : '用户设定保留') + ')');\n return 0;\n }\n const result = executeBurn(guard, paths, { all });\n console.log(`BURNED: ${result.burned.length} 项;MISSING: ${result.missing.length} 项`);\n return 0;\n}\n\nasync function verbMigrate(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n if (sub === 'export') {\n const defaultOut = path.join(paths.exportsDir, `heartbeat-memory-${localDayKey()}.hbmig`);\n const outfile = rest[0] ?? defaultOut;\n let outCanon: string;\n try {\n outCanon = guard.assert(outfile);\n } catch {\n console.error(`导出文件必须落在插件 data/ 目录内(路径守卫拒绝):${outfile}\\n默认位置:${defaultOut}`);\n return 1;\n }\n const [pw1, pw2] = await readLines(['设置口令(用于加密迁移包): ', '再输入一次确认: ']);\n if (!pw1 || pw1 !== pw2) {\n console.error('两次输入不一致或为空,已取消。');\n return 1;\n }\n const { entries, progress } = collectMigrationEntries(guard, paths);\n if (entries.length === 0) {\n console.log('没有可打包的记忆文件(data/ 是空的)。');\n return 1;\n }\n fs.mkdirSync(path.dirname(outCanon), { recursive: true });\n atomicWriteFileSync(outCanon, encryptContainer(entries, pw1));\n console.log(`已打包 ${entries.length} 个文件 → ${outCanon}`);\n console.log(` 打包:${progress.packed.join(', ')}`);\n if (progress.missing.length > 0) console.log(` 跳过(不存在):${progress.missing.join(', ')}`);\n console.log('容器是口令加密的,可安全拷贝到新机器;DPAPI 会在导入时用新机器重新加密。');\n return 0;\n }\n if (sub === 'import') {\n const infile = rest[0];\n if (!infile) {\n console.error('usage: migrate import <container-file>');\n return 1;\n }\n const [pw] = await readLines(['输入迁移包口令: ']);\n let text: string;\n try {\n text = fs.readFileSync(infile, 'utf8');\n } catch {\n console.error(`读不到迁移包:${infile}`);\n return 1;\n }\n let files;\n try {\n files = decryptContainer(text, pw ?? '');\n } catch (e) {\n console.error(String(e instanceof Error ? e.message : e));\n return 1;\n }\n const result = applyMigrationEntries(guard, paths, files.files);\n console.log(`恢复 ${result.restored.length} 个文件;备份 ${result.backedUp.length} 个被覆盖文件;跳过 ${result.skipped.length} 个。`);\n for (const r of result.restored) console.log(` 恢复: ${r}`);\n for (const b of result.backedUp) console.log(` 备份: ${b}.bak-migrate-*`);\n if (result.skipped.length > 0) console.log(` 跳过: ${result.skipped.join(', ')}`);\n if (result.error) console.log(` 失败并已回滚:${result.error}`);\n console.log('重启 DSH 后生效。');\n return result.error ? 1 : 0;\n }\n console.error(`unknown migrate subcommand: ${sub}`);\n return 1;\n}\n\nasync function verbSessions(c: CliCtx): Promise<number> {\n const { guard, paths } = c;\n // Read-only enumeration of the host's persisted sessions (ids from the\n // on-disk store; titles live server-side and are not listed here).\n const root = path.join(dshHomeDir(), 'sessions');\n let found = 0;\n if (fs.existsSync(root)) {\n const { homeSessionId } = await import('../core/orchestrator.js');\n const own = homeSessionId(guard, paths);\n for (const slug of fs.readdirSync(root)) {\n for (const id of fs.readdirSync(path.join(root, slug))) {\n found += 1;\n const mark = id === own ? ' ← 心跳正身' : '';\n console.log(`${id} [${slug}]${mark}`);\n }\n }\n }\n if (found === 0) console.log('(no persisted sessions found)');\n return 0;\n}\n\nasync function verbBind(c: CliCtx): Promise<number> {\n const { guard, paths, sub, rest } = c;\n const { loadBindings, addBinding, removeBinding } = await import('../core/bindings.js');\n switch (sub) {\n case 'list': {\n const data = loadBindings(guard, paths.settingsDir);\n const { homeSessionId } = await import('../core/orchestrator.js');\n const own = homeSessionId(guard, paths);\n if (own) console.log(`心跳正身: ${own}(决策轮次发生地;bind remove 它 = 重置正身)`);\n for (const b of data.bindings) {\n console.log(`${b.sessionId} deliver:${b.deliver ? '√' : '×'} observe:${b.observe ? '√' : '×'}`);\n }\n if (data.bindings.length === 0 && !own) console.log('(no bindings — expressions stay in the dedicated heartbeat session)');\n return 0;\n }\n case 'add': {\n const id = rest[0];\n if (!id || !id.startsWith('session-')) {\n console.error('usage: bind add <sessionId> [--observe] [--no-deliver] (see: sessions list)');\n return 1;\n }\n const observe = rest.includes('--observe') || rest.includes('--observe-only');\n const deliver = !rest.includes('--no-deliver') && !rest.includes('--observe-only');\n const b = addBinding(guard, paths.settingsDir, id, { deliver, observe });\n console.log(`BOUND ${b.sessionId} deliver:${b.deliver} observe:${b.observe}`);\n return 0;\n }\n case 'remove': {\n const id = rest[0];\n if (!id) {\n console.error('usage: bind remove <sessionId>');\n return 1;\n }\n console.log(removeBinding(guard, paths.settingsDir, id) ? `UNBOUND ${id}` : 'NOT_FOUND');\n // Unbinding the HOME session resets it: the next beat creates a fresh\n // dedicated session (the old one goes quiet after restart). H-09/H-45:\n // the shared path also drops the orchestrator's cached agent — the\n // inline delete here used to leave it pointing at the released session.\n const { resetHomeSession } = await import('../core/orchestrator.js');\n if (resetHomeSession(guard, paths, id)) {\n console.log('注意:这是心跳正身会话。已重置——下次心跳将创建新的正身会话(旧会话不再有心跳)');\n }\n return 0;\n }\n default:\n console.error('usage: bind list | add <sessionId> | remove <sessionId>');\n return 1;\n }\n}\n\nasync function verbPreset(c: CliCtx): Promise<number> {\n const { sub, rest, argv } = c;\n const id = flag(argv, '--id') ?? BUNDLED_PRESET_ID;\n // The plugin installs into the roster's own user root; the CLI has no\n // roster, so it reports/uses the conventional one ($DSH_HOME or ~/.dsh).\n const root = conventionalUserPresetRoot();\n const status = presetStatus(import.meta.url, id, root);\n if (sub === undefined || sub === 'status') {\n console.log(`preset id : ${status.id}`);\n console.log(`installed : ${status.installed ? 'yes' : 'no'}`);\n console.log(`target dir : ${status.dir}`);\n console.log(`bundled at : ${status.bundledDir ?? '(not found next to the plugin)'}`);\n if (status.installed) {\n console.log(\n `composition : ${status.compositionMatches ? 'matches the bundled template' : 'differs from the bundled template (hand-edited, or an older version)'}`,\n );\n }\n if (!status.installed) {\n console.log('hint: the plugin installs this itself on the next DSH start (installPreset=true, default);');\n console.log(' or run `preset install` now.');\n }\n return status.installed ? 0 : 1;\n }\n if (sub === 'install') {\n const result = installBundledPreset({\n moduleUrl: import.meta.url,\n id,\n root,\n force: rest.includes('--force'),\n });\n console.log(describeInstall(result));\n return result.action === 'error' ? 1 : 0;\n }\n console.error('usage: preset status | install [--force] [--id <presetId>]');\n return 1;\n}\n\n/**\n * Encryption containers on disk. `upgrade` is the migration step v2.0 owes the\n * users of 1.x: reads already accept the legacy container, this rewrites the\n * files so the plugin stops shelling out to PowerShell for each of them.\n */\nasync function verbVault(c: CliCtx): Promise<number> {\n const { guard, paths, sub } = c;\n const keyFile = vaultKeyPath();\n const files = matchFilesRecursive(paths.dataDir, /./).filter(\n (rel) => rel !== 'vault.key' && !rel.startsWith('tmp/'),\n );\n const counts = { v1: 0, v2: 0, plain: 0 };\n for (const rel of files) {\n counts[containerKind(path.join(paths.dataDir, rel.split('/').join(path.sep)))] += 1;\n }\n if (sub === undefined || sub === 'status') {\n console.log(`data dir : ${paths.dataDir}`);\n console.log(`master key : ${keyFile}${fs.existsSync(keyFile) ? '' : ' (not created yet; the next write makes it)'}`);\n console.log(`containers : ${counts.v2} KHBV2 (current), ${counts.v1} KHBV1 (legacy), ${counts.plain} plaintext`);\n if (counts.v1 > 0) console.log('hint: run `vault upgrade` to rewrite the legacy files in place.');\n return 0;\n }\n if (sub === 'upgrade') {\n const r = upgradeVaultTree(guard, paths.dataDir);\n console.log(`UPGRADED ${r.upgraded} of ${r.scanned} file(s) to KHBV2`);\n for (const f of r.failed) console.log(` ! ${f.file}: ${f.reason}`);\n return r.failed.length === 0 ? 0 : 1;\n }\n console.error('usage: vault status | upgrade');\n return 1;\n}\n\n/**\n * Focus mode (v2.1.0): runtime pause of the beat, no policy file involved.\n *\n * CROSS-PROCESS BOUNDARY: this CLI is its own process (`node dist/cli/index.js`),\n * so `pauseFocus()` here only ever touched the CLI's own module variable — the\n * host kept beating. The pause therefore lives in data/focus.json: this command\n * writes it, the host's beat() reads it at the top of every tick. The RPC path\n * (settings card) keeps module state AND the file in sync.\n */\nasync function verbFocus(c: CliCtx): Promise<number> {\n const { sub, rest, decisionLog } = c;\n const { readFocusState, writeFocusState, clearFocusState } = await import('../core/focus-store.js');\n const { formatFocusClock } = await import('../core/orchestrator.js');\n const audit = (entry: Record<string, unknown>): void => {\n try {\n appendAuditLine(decisionLog, entry);\n } catch { /* audit must never break the command */ }\n };\n const minutes = Number(sub);\n if (sub === 'off') {\n clearFocusState(c.guard, c.paths);\n audit({ event: 'focus_resumed', via: 'cli' });\n console.log('FOCUS_OFF');\n return 0;\n }\n if ((sub ?? '').trim() !== '' && Number.isFinite(minutes) && minutes > 0) {\n const state = writeFocusState(c.guard, c.paths, minutes, Date.now(), 'cli');\n audit({ event: 'focus_paused', via: 'cli', minutes: state.minutes, until: new Date(state.until).toISOString() });\n console.log(`FOCUSED until ${new Date(state.until).toISOString()} (${formatFocusClock(state.until)})`);\n return 0;\n }\n if (sub === undefined && rest.length === 0) {\n const state = readFocusState(c.guard, c.paths);\n if (state) {\n console.log(`FOCUSED until ${new Date(state.until).toISOString()} (${formatFocusClock(state.until)}), set via ${state.via}`);\n } else {\n console.log('FOCUS_OFF (beats run on the normal rhythm; use `focus <minutes>` to pause)');\n }\n return 0;\n }\n console.error('usage: heartbeat focus <minutes> | focus off | focus');\n return 1;\n}\n\n/**\n * Bilibili QR login (v2.2.0). All the flow logic lives in bili-login.ts behind\n * injected deps; this just wires the real-world implementations (network\n * fetch, qrcode renderer, platform image opener, vault-backed storage) and\n * lands the outcome in the decision log (code only — never the cookie).\n */\nasync function verbBili(c: CliCtx): Promise<number> {\n const { guard, paths, sub, decisionLog } = c;\n if (sub !== 'login') {\n console.error('usage: bili login');\n return 1;\n }\n const {\n runBiliLogin,\n openImageProduction,\n renderQrPngProduction,\n saveBiliSession,\n } = await import('./bili-login.js');\n const outcome = await runBiliLogin({\n fetchImpl: fetch,\n renderQrPng: renderQrPngProduction,\n openImage: openImageProduction(process.platform),\n sleep: (ms) => new Promise((r) => setTimeout(r, ms)),\n log: (line) => console.log(line),\n now: () => Date.now(),\n platform: process.platform,\n saveCredential: (value) => saveBiliSession(guard, paths, value),\n });\n try {\n appendAuditLine(decisionLog, { event: 'bili_login', outcome });\n } catch { /* audit must never break the command */ }\n return outcome;\n}\n\n/** Command table. Adding a verb = one function above plus one line here. */\nconst VERBS: Record<string, Verb> = {\n status: verbStatus,\n seeds: verbSeeds,\n ledger: verbLedger,\n excerpt: verbExcerpt,\n weekly: verbWeekly,\n logs: verbLogs,\n browse: verbBrowse,\n focus: verbFocus,\n notify: verbNotify,\n profile: verbProfile,\n vault: verbVault,\n burn: verbBurn,\n migrate: verbMigrate,\n sessions: verbSessions,\n bind: verbBind,\n preset: verbPreset,\n bili: verbBili,\n};\n\nexport async function main(argv: string[]): Promise<number> {\n const [cmd, sub, ...rest] = argv;\n if (!cmd || cmd === 'help' || cmd === '--help') {\n console.log(usage());\n return 0;\n }\n const verb = VERBS[cmd];\n if (!verb) {\n console.error(`unknown command: ${cmd}`);\n console.log(usage());\n return 1;\n }\n const paths = initWorkspace();\n const guard = createPathGuard(paths.dataDir);\n const policy = loadPolicy(guard, paths.configDir, paths.settingsDir);\n const decisionLog = path.join(paths.logsDir, 'heartbeat.jsonl');\n /** Seed lifecycle audit (v1.9.0): CLI edits land in the same log as the beat's. */\n const seedAudit = (entry: Record<string, unknown>): void => {\n try {\n appendAuditLine(decisionLog, entry);\n } catch { /* audit must never break the command */ }\n };\n return verb({\n paths,\n guard,\n policy,\n sub,\n rest,\n argv,\n seedsFile: seedsFilePath(paths.dataDir),\n ledgerFile: ledgerFilePath(paths.dataDir),\n excerptFile: excerptFilePath(paths.dataDir),\n decisionLog,\n seedAudit,\n });\n}\n\n// Direct execution guard; the CLI is also importable for tests.\n// Built by hand as `file:///${argv[1]}` before: on Windows that happens to\n// yield `file:///C:/...`, but a POSIX argv[1] starts with `/`, so the template\n// produced `file:////root/...` and never matched — every `heartbeat <verb>`\n// exited 0 with no output at all. `pathToFileURL` gets the host/path split and\n// percent-encoding right on every platform (`path.resolve` is defensive: Node\n// always hands out an absolute argv[1], but a relative one would otherwise be\n// read as a relative file: URL and silently fail to match again).\nif (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {\n void main(process.argv.slice(2))\n .then((code) => { process.exitCode = code; })\n .catch((e: unknown) => {\n // H-44: no unhandled rejection — print and exit non-zero.\n console.error(e);\n process.exitCode = 1;\n });\n}\n","// Burn list - SINGLE SOURCE OF TRUTH (design doc §10.10; v1 shipped two\n// hardcoded lists and one drifted). burn and uninstall --purge both consume\n// this list. Settings (data/settings/) are NOT burned by default: losing\n// memory != losing the charter/gates the user configured (--all overrides).\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport type { PathGuard } from '../core/path-guard.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { shredFileSync } from '../core/atomic-fs.js';\nimport { appendAuditLine } from '../core/audit-log.js';\nimport { matchFilesRecursive } from '../core/fs-walk.js';\n\nexport interface BurnTarget {\n /** Relative to dataDir. Files are shredded (overwrite x3) then deleted. */\n file?: string;\n /** Every dataDir file whose name starts with this prefix — a family of\n * timestamped files a bare `file` cannot name (journal archive shards).\n * Shredded like files. */\n prefix?: string;\n /** Every file ANYWHERE below dataDir whose NAME matches this pattern. Used for\n * families a prefix cannot reach: `${name}.bak-migrate-${stamp}` and the\n * `.incoming-` staging leftovers sit next to whatever they copied, which may\n * be a subdirectory. Shredded like files. */\n match?: RegExp;\n /** Directories are removed recursively (no shred - content is files). */\n dir?: string;\n note: string;\n}\n\nexport const BURN_LIST: BurnTarget[] = [\n { file: 'profile.json', note: '画像物化视图' },\n { file: 'profile_inbox.jsonl', note: '观察收件箱' },\n { file: 'profile_journal.jsonl', note: '画像操作流水' },\n // H-19: the rotation shards hold the whole profile history and are written\n // in PLAINTEXT — a burn that leaves them behind leaves the memory readable.\n { prefix: 'profile_journal.archive-', note: '画像流水归档分片(明文;journal 轮转产物)' },\n // HB-07 (2026-10-17): applyMigrationEntries copies every file it overwrites\n // to `${abs}.bak-migrate-${stamp}`. Those copies hold the OLD memory — a burn\n // that left them behind left the thing the user asked to destroy. The\n // `.incoming-` staging files are the same data, only younger.\n { match: /\\.bak-migrate-\\d{14}$/, note: '迁移备份(迁移导入时的原文件副本)' },\n { match: /\\.incoming-\\d{14}$/, note: '迁移暂存残留(崩溃遗留的导入副本)' },\n { file: 'profile_rhythm.json', note: '作息聚合(纯统计)' },\n { file: 'screen.json', note: '屏幕快照(加密)' },\n { file: 'screen.jpg', note: '截图(加密)' },\n { file: 'sent.json', note: '表达记录(加密)' },\n { file: 'browse.json', note: '浏览流状态(加密)' },\n { file: 'seeds.jsonl', note: '素材池(加密)' },\n { file: 'ledger.md', note: '账本(明文,人可读是设计目标)' },\n { file: 'envpulse.json', note: '环境温度计快照' },\n { file: 'gate.json', note: '闸门运行时计数' },\n // v1.9.0 completion (H-19): these carry memory just as much as the rows\n // above — the persona report log records WHAT SHE SAID (spoken / seed_ids /\n // profile_ids / reason), so a burn that skips it is a burn that lies.\n { file: 'profile_snapshot.json', note: '画像快照(journal 轮转基线)' },\n { file: 'cursors.json', note: '观察游标(会话事件位点)' },\n { file: 'seed_report.jsonl', note: '投递报账日志(加密)' },\n { file: 'preference.json', note: '话题偏好统计' },\n { dir: 'weekly', note: '周报(画像与素材散文)' },\n { dir: 'tmp', note: '解锁临时文件(崩溃残留的解密明文是最该烧的东西)' },\n { dir: 'logs', note: '审计与决策日志' },\n { dir: 'exports', note: '导出产物' },\n];\n\nconst SETTINGS_DIR = 'settings'; // excluded unless --all\n\n/** dataDir files matching a prefix target, name-sorted for stable output. */\nfunction prefixMatches(guard: PathGuard, paths: WorkspacePaths, prefix: string): string[] {\n try {\n return fs.readdirSync(guard.assert(paths.dataDir))\n .filter((f) => f.startsWith(prefix))\n .sort();\n } catch {\n return [];\n }\n}\n\n/** Same as prefixMatches, but for the recursive `match` family. */\nfunction matchTargets(guard: PathGuard, paths: WorkspacePaths, re: RegExp): string[] {\n try {\n return matchFilesRecursive(guard.assert(paths.dataDir), re);\n } catch {\n return [];\n }\n}\n\nexport interface BurnPlanItem {\n target: BurnTarget;\n exists: boolean;\n}\n\n/** Preview: what exists, what would be removed. No writes. */\nexport function planBurn(guard: PathGuard, paths: WorkspacePaths, all = false): BurnPlanItem[] {\n const plan: BurnPlanItem[] = [];\n for (const t of BURN_LIST) {\n const rel = t.file ?? t.dir ?? t.prefix ?? String(t.match ?? '');\n if (!all && rel === SETTINGS_DIR) continue;\n let exists = false;\n if (t.match) {\n exists = matchTargets(guard, paths, t.match).length > 0;\n } else if (t.prefix) {\n exists = prefixMatches(guard, paths, t.prefix).length > 0;\n } else {\n try {\n exists = fs.existsSync(guard.assert(path.join(paths.dataDir, rel)));\n } catch {\n exists = false;\n }\n }\n plan.push({ target: t, exists });\n }\n if (all) {\n plan.push({ target: { dir: SETTINGS_DIR, note: '用户设定(隐私宪章/闸门参数)——仅 --all 连带' }, exists: fs.existsSync(paths.settingsDir) });\n }\n return plan;\n}\n\n/**\n * Execute the burn: overwrite x3 + delete files, remove dirs. Irreversible.\n * Returns per-target results and writes a BURN_EVENT into the (recreated)\n * journal afterwards - the only trace, on purpose (transparency).\n */\nexport function executeBurn(\n guard: PathGuard,\n paths: WorkspacePaths,\n opts: { all?: boolean; shredPasses?: number } = {},\n): { burned: string[]; missing: string[] } {\n const burned: string[] = [];\n const missing: string[] = [];\n const passes = opts.shredPasses ?? 3;\n for (const t of BURN_LIST) {\n if (t.match) {\n const matches = matchTargets(guard, paths, t.match);\n if (matches.length === 0) {\n missing.push(String(t.match));\n continue;\n }\n for (const f of matches) {\n try {\n shredFileSync(guard.assert(path.join(paths.dataDir, f)), passes);\n burned.push(f);\n } catch { /* vanished between listing and shredding: not fatal */ }\n }\n continue;\n }\n // H-19: a prefix target is a family of files (timestamped archive shards);\n // shred every match individually.\n if (t.prefix) {\n const matches = prefixMatches(guard, paths, t.prefix);\n if (matches.length === 0) {\n missing.push(`${t.prefix}*`);\n continue;\n }\n for (const f of matches) {\n try {\n shredFileSync(guard.assert(path.join(paths.dataDir, f)), passes);\n burned.push(f);\n } catch { /* vanished between listing and shredding: not fatal */ }\n }\n continue;\n }\n const rel = t.file ?? t.dir ?? String(t.match ?? '');\n const abs = path.join(paths.dataDir, rel);\n let absCanon: string;\n try {\n absCanon = guard.assert(abs);\n } catch {\n missing.push(rel);\n continue;\n }\n if (t.file) {\n if (fs.existsSync(absCanon)) {\n shredFileSync(absCanon, passes);\n burned.push(rel);\n } else {\n missing.push(rel);\n }\n } else if (fs.existsSync(absCanon)) {\n fs.rmSync(absCanon, { recursive: true, force: true });\n burned.push(rel);\n } else {\n missing.push(rel);\n }\n }\n if (opts.all) {\n fs.rmSync(paths.settingsDir, { recursive: true, force: true });\n burned.push(SETTINGS_DIR);\n }\n // BURN_EVENT: recreate the journal; data dir is now re-initializable.\n appendAuditLine(guard.assert(path.join(paths.dataDir, 'profile_journal.jsonl')), {\n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CAAC,UAAyC;AAC1D,QAAI;AACF,sBAAgB,aAAa,KAAK;AAAA,IACpC,QAAQ;AAAA,IAA2C;AAAA,EACrD;AACA,SAAO,KAAK;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,cAAc,MAAM,OAAO;AAAA,IACtC,YAAY,eAAe,MAAM,OAAO;AAAA,IACxC,aAAa,gBAAgB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAUA,IAAI,QAAQ,KAAK,CAAC,KAAK,YAAY,QAAQ,cAAcA,MAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM;AAC5F,OAAK,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAC5B,KAAK,CAAC,SAAS;AAAE,YAAQ,WAAW;AAAA,EAAM,CAAC,EAC3C,MAAM,CAAC,MAAe;AAErB,YAAQ,MAAM,CAAC;AACf,YAAQ,WAAW;AAAA,EACrB,CAAC;AACL;","names":["fs","path","fs","path"]}
package/dist/index.d.ts CHANGED
@@ -77,6 +77,17 @@ interface Policy {
77
77
  envPulseHours: number;
78
78
  decisionLogDays: number;
79
79
  };
80
+ /** v2.2 optional per-source config. Absent = every source's own default
81
+ * behaviour (bilibili: on iff a credential exists). OPTIONAL so pre-2.2
82
+ * policy layers still validate. */
83
+ sources?: {
84
+ bilibili?: {
85
+ /** false = hard-disable the source even with a credential. */
86
+ enabled?: boolean;
87
+ /** Fallback credential: text file whose content parses as SESSDATA. */
88
+ cookieFile?: string;
89
+ };
90
+ };
80
91
  }
81
92
  /** Recursive merge: user values win; objects merge, arrays and scalars replace. */
82
93
  declare function deepMerge<T>(base: T, override: unknown): T;