dsh-lowtide 0.2.8 → 0.3.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.
package/lib/index.js CHANGED
@@ -5608,6 +5608,87 @@ function forkSeedBoundary(events) {
5608
5608
  function sleep(ms) {
5609
5609
  return new Promise((resolve) => setTimeout(resolve, ms));
5610
5610
  }
5611
+ /** Longest a busy source conversation may hold a task up before the runner
5612
+ * falls back to a fork. Capped at 30s and applied with min(timeoutMs, this):
5613
+ * spending the whole off-peak budget waiting on someone's live conversation
5614
+ * would silently eat the window. */
5615
+ const LIVE_WAIT_MAX_MS = 3e4;
5616
+ /**
5617
+ * Resolve once `agent` is idle, or `false` after `timeoutMs`. The losing timer
5618
+ * is cleared as soon as the race settles, so an idle wait leaves no pending
5619
+ * handle (and no lingering ref) behind.
5620
+ */
5621
+ async function waitIdleFor(agent, timeoutMs) {
5622
+ let timer;
5623
+ const timeout = new Promise((resolve) => {
5624
+ timer = setTimeout(() => resolve(false), timeoutMs);
5625
+ });
5626
+ try {
5627
+ return await Promise.race([agent.whenIdle().then(() => true, () => false), timeout]);
5628
+ } finally {
5629
+ if (timer !== void 0) clearTimeout(timer);
5630
+ }
5631
+ }
5632
+ /**
5633
+ * Canonical form of a directory for comparison. `fs.realpath` folds symlinks,
5634
+ * `..` segments and short/long spellings; on Windows the result is case-folded
5635
+ * because NTFS is case-insensitive (a task recorded as `C:\\Repo` must match
5636
+ * the live session's `C:\\repo`). Unresolvable paths are compared as written.
5637
+ */
5638
+ function canonicalPath(path) {
5639
+ let resolved = path;
5640
+ try {
5641
+ resolved = realpathSync(path);
5642
+ } catch {}
5643
+ const trimmed = resolved.replace(/[\\/]+$/, "");
5644
+ return process.platform === "win32" ? trimmed.toLowerCase() : trimmed;
5645
+ }
5646
+ /**
5647
+ * Capture the preset a borrowed conversation must be handed back with.
5648
+ * `custom` has no catalog entry (set(session, 'custom') throws), and an empty,
5649
+ * unreadable or unknown value cannot be proven equivalent — all of those mean
5650
+ * the conversation must NOT be driven in place.
5651
+ */
5652
+ function captureRestorablePreset(ctx, session) {
5653
+ let previous;
5654
+ try {
5655
+ previous = ctx.permissionPresets.current(session);
5656
+ } catch {
5657
+ return { reason: "无法读取原会话的权限档,跑完无法还原" };
5658
+ }
5659
+ if (previous === "custom") return { reason: "原会话的权限档是自定义档,跑完无法还原" };
5660
+ if (previous === void 0 || previous === "") return { reason: "无法确定原会话的权限档,跑完无法还原" };
5661
+ try {
5662
+ const names = ctx.permissionPresets.names;
5663
+ if (names.length > 0 && !names.includes(previous)) return { reason: `原会话的权限档「${previous}」不在预设表里,跑完无法还原` };
5664
+ } catch {}
5665
+ return { previous };
5666
+ }
5667
+ /** Hand a borrowed conversation's preset back. Never throws. */
5668
+ function presetRestore(ctx, session, previous) {
5669
+ return () => {
5670
+ try {
5671
+ ctx.permissionPresets.set(session, previous);
5672
+ } catch (error) {
5673
+ console.error("[lowtide] permission preset restore failed:", error);
5674
+ }
5675
+ };
5676
+ }
5677
+ function liveAgentBlocker(ctx, agent, expected, preset) {
5678
+ const captured = preset ?? captureRestorablePreset(ctx, agent.session);
5679
+ if (captured.reason !== void 0) return captured.reason;
5680
+ const inbox = agent.inbox;
5681
+ if ((inbox?.nextTurn?.length ?? 0) > 0 || (inbox?.nextStep?.length ?? 0) > 0) return "原会话里还有排队未处理的消息";
5682
+ const liveCwd = agent.session.header?.cwd;
5683
+ if (expected.cwd !== void 0) {
5684
+ if (liveCwd === void 0 || liveCwd === "") return "原会话没有记录工作目录,无法确认与任务工作目录一致";
5685
+ if (canonicalPath(liveCwd) !== canonicalPath(expected.cwd)) return `原会话的工作目录是 ${liveCwd},与任务工作目录 ${expected.cwd} 不一致`;
5686
+ }
5687
+ const options = agent.options;
5688
+ if (options?.provider !== expected.provider) return options?.provider === void 0 ? `原会话没有记录模型线路,与任务的 ${expected.provider} 线路不一致` : `原会话走 ${options.provider} 线路,与任务的 ${expected.provider} 线路不一致`;
5689
+ if (options?.model !== expected.model) return options?.model === void 0 ? `原会话没有记录模型,与任务的 ${expected.model} 模型不一致` : `原会话用 ${options.model} 模型,与任务的 ${expected.model} 模型不一致`;
5690
+ if (expected.reasoning !== void 0 && String(options?.reasoningEffort ?? "") !== expected.reasoning) return `原会话的推理档是 ${options?.reasoningEffort === void 0 ? "未设置" : String(options.reasoningEffort)},与任务的 ${expected.reasoning} 不一致`;
5691
+ }
5611
5692
  function usageOf(raw) {
5612
5693
  const u = raw;
5613
5694
  const toNum = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
@@ -5757,21 +5838,64 @@ async function executeTurns(ctx, task, nextMessage, timeoutMs, reasoning, resume
5757
5838
  let resumeNote;
5758
5839
  let resumed = false;
5759
5840
  let forked = false;
5841
+ let borrowedSession = false;
5842
+ let liveBlocker;
5760
5843
  let handle;
5844
+ /** The borrowed session's preset, captured once and reused by the restore. */
5845
+ let borrowedPreset;
5846
+ /** Hand the borrowed conversation's preset back (first thing in finally). */
5847
+ let restorePreset;
5761
5848
  if (resumeSessionId !== void 0) try {
5762
- handle = await ctx.agents.resume({
5763
- resumeSessionId: SessionId(resumeSessionId),
5764
- agentOptions: {
5849
+ const liveAgent = ctx.agents.get(SessionId(resumeSessionId));
5850
+ if (liveAgent !== void 0) {
5851
+ borrowedPreset = captureRestorablePreset(ctx, liveAgent.session);
5852
+ liveBlocker = liveAgentBlocker(ctx, liveAgent, {
5853
+ ...task.workspace === "" ? {} : { cwd: workspacePath },
5765
5854
  provider: selection.provider,
5766
- model: selection.model
5767
- },
5768
- setup
5769
- });
5770
- resumed = true;
5771
- console.log(`[lowtide] ✓ resumed conversation ${resumeSessionId} in place`);
5855
+ model: selection.model,
5856
+ ...selection.reasoningEffort === void 0 ? {} : { reasoning: String(selection.reasoningEffort) }
5857
+ }, borrowedPreset);
5858
+ }
5859
+ if (liveAgent !== void 0 && liveBlocker === void 0) {
5860
+ const waitMs = Math.min(timeoutMs, LIVE_WAIT_MAX_MS);
5861
+ if (await waitIdleFor(liveAgent, waitMs)) {
5862
+ handle = {
5863
+ agent: liveAgent,
5864
+ dispose: async () => {}
5865
+ };
5866
+ borrowedSession = true;
5867
+ resumed = true;
5868
+ if (borrowedPreset?.previous !== void 0) restorePreset = presetRestore(ctx, liveAgent.session, borrowedPreset.previous);
5869
+ console.log(`[lowtide] ✓ driving the live conversation ${resumeSessionId} in place`);
5870
+ } else liveBlocker = `原会话仍在执行中(等待 ${Math.round(waitMs / 1e3)}s 未空闲)`;
5871
+ }
5872
+ if (handle === void 0) {
5873
+ const resumedHandle = await ctx.agents.resume({
5874
+ resumeSessionId: SessionId(resumeSessionId),
5875
+ agentOptions: {
5876
+ provider: selection.provider,
5877
+ model: selection.model
5878
+ },
5879
+ setup
5880
+ });
5881
+ borrowedPreset = captureRestorablePreset(ctx, resumedHandle.agent.session);
5882
+ if (borrowedPreset.reason !== void 0) {
5883
+ resumeNote = `原会话不能原地续接(${borrowedPreset.reason}),本次改为分支续接`;
5884
+ const refusal = new Error(borrowedPreset.reason);
5885
+ refusal.presetNotRestorable = true;
5886
+ throw refusal;
5887
+ }
5888
+ handle = resumedHandle;
5889
+ resumed = true;
5890
+ borrowedSession = true;
5891
+ if (borrowedPreset.previous !== void 0) restorePreset = presetRestore(ctx, resumedHandle.agent.session, borrowedPreset.previous);
5892
+ resumeNote = void 0;
5893
+ console.log(`[lowtide] ✓ resumed conversation ${resumeSessionId} in place`);
5894
+ }
5772
5895
  } catch (error) {
5896
+ const refused = error?.presetNotRestorable === true;
5773
5897
  const reason = error instanceof Error ? error.message : String(error);
5774
- console.error(`[lowtide] resume ${resumeSessionId} failed (${reason}) — trying fork-style continuation`);
5898
+ console.error(refused ? `[lowtide] refusing to drive ${resumeSessionId} in place (${reason}) — trying fork-style continuation` : `[lowtide] resume ${resumeSessionId} failed (${reason}) — trying fork-style continuation`);
5775
5899
  const live = ctx.sessions.get(SessionId(resumeSessionId));
5776
5900
  const liveCompat = live;
5777
5901
  const newSessionApi = typeof liveCompat?.snapshotEvents === "function";
@@ -5810,9 +5934,11 @@ async function executeTurns(ctx, task, nextMessage, timeoutMs, reasoning, resume
5810
5934
  setup
5811
5935
  });
5812
5936
  forked = true;
5937
+ if (liveBlocker !== void 0) resumeNote = `原会话不能原地续接(${liveBlocker}),本次改为分支续接`;
5813
5938
  console.log(`[lowtide] ✓ continuation session ${handle.agent.session.id} seeded with ${seed.length} events from ${resumeSessionId} (lossless fork)`);
5814
5939
  } else {
5815
- resumeNote = live === void 0 ? `会话续接失败(${reason}),且源会话不在运行中,已新建会话执行` : "所选会话还没有完整的对话轮次,无法续接其上下文,已新建会话执行";
5940
+ const because = live === void 0 ? `会话续接失败(${reason}),且源会话不在运行中` : "所选会话还没有完整的对话轮次,无法续接其上下文";
5941
+ resumeNote ??= liveBlocker === void 0 ? `${because},已新建会话执行` : `${because}(${liveBlocker}),已新建会话执行`;
5816
5942
  console.error(`[lowtide] fork-style continuation unavailable for ${resumeSessionId} (live=${live !== void 0}), using a fresh session:`, error);
5817
5943
  handle = await ctx.agents.create({
5818
5944
  sessionId: SessionId(`lt-${task.id}-${Date.now()}`),
@@ -5834,20 +5960,23 @@ async function executeTurns(ctx, task, nextMessage, timeoutMs, reasoning, resume
5834
5960
  },
5835
5961
  setup
5836
5962
  });
5963
+ if (handle === void 0) throw new Error("continuation produced no agent handle");
5837
5964
  const { agent } = handle;
5838
- if (workspaceEntity !== void 0) try {
5965
+ if (!borrowedSession && workspaceEntity !== void 0) try {
5839
5966
  await workspaceEntity.attachSession(agent.session.id);
5840
5967
  console.log(`[lowtide] ✓ session ${agent.session.id} attached to workspace "${workspacePath}"`);
5841
5968
  } catch (error) {
5842
5969
  console.error(`[lowtide] ✗ attach failed for session ${agent.session.id}:`, error);
5843
5970
  }
5844
- const titleService = ctx.get("sessionTitle");
5845
- if (titleService !== void 0) try {
5846
- titleService.rename(agent.session, taskSessionTitle(task, resumed ? "resumed" : forked ? "forked" : "task"));
5847
- } catch (error) {
5848
- console.error(`[lowtide] session title set failed for ${agent.session.id}:`, error);
5971
+ if (!borrowedSession) {
5972
+ const titleService = ctx.get("sessionTitle");
5973
+ if (titleService !== void 0) try {
5974
+ titleService.rename(agent.session, taskSessionTitle(task, resumed ? "resumed" : forked ? "forked" : "task"));
5975
+ } catch (error) {
5976
+ console.error(`[lowtide] session title set failed for ${agent.session.id}:`, error);
5977
+ }
5978
+ else console.warn("[lowtide] sessionTitle service unavailable — sessions keep auto-generated titles");
5849
5979
  }
5850
- else console.warn("[lowtide] sessionTitle service unavailable — sessions keep auto-generated titles");
5851
5980
  try {
5852
5981
  await agent.whenIdle();
5853
5982
  ctx.permissionPresets.set(agent.session, task.permissionPreset);
@@ -5926,6 +6055,7 @@ async function executeTurns(ctx, task, nextMessage, timeoutMs, reasoning, resume
5926
6055
  ...forked ? { forked: true } : {}
5927
6056
  };
5928
6057
  } finally {
6058
+ if (restorePreset !== void 0) restorePreset();
5929
6059
  const sessions = ctx.get("sessions");
5930
6060
  if (sessions !== void 0) try {
5931
6061
  await sessions.flush(agent.session);
@@ -5933,7 +6063,7 @@ async function executeTurns(ctx, task, nextMessage, timeoutMs, reasoning, resume
5933
6063
  console.error("[lowtide] session flush failed:", error);
5934
6064
  }
5935
6065
  else console.error("[lowtide] sessions service not available — session may not persist");
5936
- if (workspaceEntity !== void 0) try {
6066
+ if (workspaceEntity !== void 0 && !borrowedSession) try {
5937
6067
  await workspaceEntity.attachSession(agent.session.id);
5938
6068
  } catch (error) {
5939
6069
  console.error(`[lowtide] re-attach failed for session ${agent.session.id}:`, error);
@@ -6343,6 +6473,8 @@ async function executeStrategy(ctx, store, task, timeoutMs) {
6343
6473
  if (strategy === "review") {
6344
6474
  const res = await executeTurns(ctx, task, (index) => index === 0 ? prompt : null, timeoutMs, reasoning, resumeSessionId);
6345
6475
  if (res.resumeNote !== void 0) resumeNote = res.resumeNote;
6476
+ if (res.resumed) resumed = true;
6477
+ if (res.forked) forked = true;
6346
6478
  if (res.status !== "done") return {
6347
6479
  final: res.status,
6348
6480
  elapsedMs: res.elapsedMs,
@@ -6356,7 +6488,7 @@ async function executeStrategy(ctx, store, task, timeoutMs) {
6356
6488
  };
6357
6489
  const resultText = res.turns[0]?.text ?? "";
6358
6490
  const reviewPrompt = reviewPromptOf(task.prompt, resultText, task.strategyHint);
6359
- const rev = await executeTurns(ctx, task, (index) => index === 0 ? reviewPrompt : null, timeoutMs, reasoning, resumeSessionId);
6491
+ const rev = await executeTurns(ctx, task, (index) => index === 0 ? reviewPrompt : null, timeoutMs, reasoning);
6360
6492
  if (rev.resumeNote !== void 0) resumeNote = rev.resumeNote;
6361
6493
  if (rev.resumed) resumed = true;
6362
6494
  if (rev.forked) forked = true;
@@ -6400,6 +6532,8 @@ async function executeStrategy(ctx, store, task, timeoutMs) {
6400
6532
  const next = (index) => index === 0 ? prompt : null;
6401
6533
  const res = await executeTurns(ctx, task, next, timeoutMs, reasoning, resumeSessionId);
6402
6534
  if (res.resumeNote !== void 0) resumeNote = res.resumeNote;
6535
+ if (res.resumed) resumed = true;
6536
+ if (res.forked) forked = true;
6403
6537
  const totalUsage = sumTurns(res.turns);
6404
6538
  const finalText = res.turns.length > 0 ? res.turns[res.turns.length - 1].text : "";
6405
6539
  return {
@@ -6857,22 +6991,18 @@ function canTransition(status, action) {
6857
6991
  //#endregion
6858
6992
  //#region src/session-picker.ts
6859
6993
  /**
6860
- * Workspace session picker (functional-fix round): enumerate dsh
6861
- * conversations from the official storage files, grouped by workspace, so a
6862
- * new off-peak task can RESUME an existing conversation (agents.resume at
6863
- * execution time). Read-only; payloads (session.jsonl.zstd) are loaded by
6864
- * dsh itself on resume.
6994
+ * Workspace session picker: enumerate dsh conversations from the official
6995
+ * storage files, grouped by workspace, so a new off-peak task can resume an
6996
+ * existing conversation. Read-only; session payloads are loaded by dsh itself.
6865
6997
  *
6866
- * Data sources (verified against a live profile):
6998
+ * Data sources:
6867
6999
  * $DSH_HOME/storages/workspace.json
6868
7000
  * tables.workspaces.<id> = { path, title, sessionIds, updatedAt }
6869
- * $DSH_HOME/storages/session_projcache.json
6870
- * tables.sessions.<sessionId> = { identity: { createdAt, cwd },
6871
- * rows: { title: { val },
6872
- * sessionListMetadata: { val: { lastPromptAt } } } }
7001
+ * Legacy: $DSH_HOME/storages/session_projcache.json
7002
+ * tables.sessions.<sessionId> = { identity, rows }
7003
+ * Current: $DSH_HOME/storages/session_projcache/sessions/<sessionId>.json
7004
+ * { version, record: { identity, rows } }
6873
7005
  * Last activity = lastPromptAt (fallback: createdAt).
6874
- * Lowtide's own task sessions (prefix lt- or ns-) are NOT listed in
6875
- * workspace.sessionIds, so starting from the workspace table excludes them.
6876
7006
  */
6877
7007
  function storagesDir() {
6878
7008
  return join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "storages");
@@ -6886,6 +7016,25 @@ function readJsonSafe(file) {
6886
7016
  return null;
6887
7017
  }
6888
7018
  }
7019
+ function projectionRecord(value) {
7020
+ if (value === null || typeof value !== "object") return null;
7021
+ const record = value;
7022
+ if (record.identity === null || typeof record.identity !== "object") return null;
7023
+ if (record.rows === null || typeof record.rows !== "object") return null;
7024
+ return record;
7025
+ }
7026
+ function readPerRecordProjection(dir, id) {
7027
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id)) return null;
7028
+ return projectionRecord(readJsonSafe(join(dir, "session_projcache", "sessions", `${id}.json`))?.record);
7029
+ }
7030
+ function displayTitle(record) {
7031
+ const title = record?.rows?.title?.val;
7032
+ if (typeof title === "string" && title.trim() !== "") return title;
7033
+ const firstPrompt = record?.rows?.titleInput?.val?.first?.text;
7034
+ if (typeof firstPrompt !== "string" || firstPrompt.trim() === "") return null;
7035
+ const summary = firstPrompt.replace(/\s+/g, " ").trim();
7036
+ return summary.length > 80 ? `${summary.slice(0, 80)}…` : summary;
7037
+ }
6889
7038
  /** List conversations per workspace, most recently active first. */
6890
7039
  function listWorkspaceSessions(limitPerWorkspace = 30) {
6891
7040
  const dir = storagesDir();
@@ -6901,15 +7050,14 @@ function listWorkspaceSessions(limitPerWorkspace = 30) {
6901
7050
  const ids = Array.isArray(entry.sessionIds) ? entry.sessionIds.filter((id) => typeof id === "string" && !id.startsWith("lt-") && !id.startsWith("ns-")) : [];
6902
7051
  const sessions = [];
6903
7052
  for (const id of ids) {
6904
- const cached = projSessions?.[id];
7053
+ const cached = readPerRecordProjection(dir, id) ?? projSessions?.[id];
6905
7054
  if (cached?.rows?.sessionListMetadata?.val?.blank === true) continue;
6906
7055
  if (archived.has(id)) continue;
6907
- const titleVal = cached?.rows?.title?.val;
6908
7056
  const createdAt = cached?.identity?.createdAt;
6909
7057
  const lastPromptAt = cached?.rows?.sessionListMetadata?.val?.lastPromptAt;
6910
7058
  sessions.push({
6911
7059
  id,
6912
- title: typeof titleVal === "string" ? titleVal : null,
7060
+ title: displayTitle(cached),
6913
7061
  lastModified: typeof lastPromptAt === "number" ? lastPromptAt : typeof createdAt === "number" ? createdAt : 0
6914
7062
  });
6915
7063
  }
@@ -7336,6 +7484,7 @@ function registerRoutes(ctx, routes) {
7336
7484
  });
7337
7485
  return;
7338
7486
  }
7487
+ if (typeof body?.continuesFromSession !== "string" || body.continuesFromSession === "") result.task.continuesFromSession = void 0;
7339
7488
  const edited = store.editTask(id, result.task);
7340
7489
  broadcastState(ctx, routes);
7341
7490
  reply(res, 200, {
@@ -7468,10 +7617,13 @@ function registerRoutes(ctx, routes) {
7468
7617
  }
7469
7618
  })();
7470
7619
  };
7471
- ctx.webServer.register({
7472
- kind: "prefix",
7473
- path: "/ds-lowtide",
7474
- handler
7620
+ ctx.effect(() => {
7621
+ const dispose = ctx.webServer.register({
7622
+ kind: "prefix",
7623
+ path: "/ds-lowtide",
7624
+ handler
7625
+ });
7626
+ return typeof dispose === "function" ? dispose : () => {};
7475
7627
  });
7476
7628
  }
7477
7629
  /** Semantic validation for a config update beyond zod shape checks. */
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Optional dsh-better-sidebar bridge: contributes the queue panel as a tab, so
3
+ * the same panel can live in the native right sidebar and in the host's bottom
4
+ * workbench instead of (or alongside) the composer dock.
5
+ *
6
+ * A plain descriptor (no `hidden`, no `bottomOnly`) is listed by BOTH "+" menus
7
+ * — DSH's native right sidebar guide and better-sidebar's own bottom workbench
8
+ * — so one registration serves the sidebar and the bottom bar.
9
+ *
10
+ * better-sidebar is optional and its service lives in the browser half only
11
+ * (`ctx.provide('betterSidebar', …)`). Cordis has no "optional inject", so a
12
+ * static `inject` entry would keep this whole client half dormant on installs
13
+ * without the host; `ctx.inject` waits for the service instead and re-runs when
14
+ * it appears or disappears (HMR / disable), which is the pattern the host's own
15
+ * client code uses for its tab registries.
16
+ *
17
+ * The host API used here (0.28.x): `registerTab` returns a disposer;
18
+ * `openTab` silently no-ops for an unregistered type or a session-less
19
+ * snapshot; `isTabEnabled` reports the user's per-type switch; `subscribe`
20
+ * fires on registry changes and `subscribeState` on enablement/session changes.
21
+ * Nothing from the host package is imported — the service is described by a
22
+ * local structural interface so the plugin adds no dependency.
23
+ */
24
+ import type { Context as ClientContext } from '@deepseek-ai/cordis';
25
+ /** Structural view of the host's tab descriptor. */
26
+ interface SidebarTab {
27
+ id: string;
28
+ title: string | (() => string);
29
+ icon?: React.ReactNode | ((size: number) => React.ReactNode);
30
+ order?: number;
31
+ single?: boolean;
32
+ badge?: () => string | number | null;
33
+ component: () => React.JSX.Element;
34
+ }
35
+ /** The slice of the host's client service this plugin uses. Declared locally,
36
+ * like the other optional host services read here, so the integration adds no
37
+ * dependency and the plugin still loads on installs without the host.
38
+ * `getTab` / `getSnapshot` / `subscribeState` are newer and optional: an older
39
+ * host simply makes those checks fall back to `isTabEnabled`. */
40
+ interface SidebarHost {
41
+ registerTab(tab: SidebarTab): () => void;
42
+ openTab(seed: {
43
+ type: string;
44
+ }): void;
45
+ isTabEnabled(type: string): boolean;
46
+ subscribe(listener: () => void): () => void;
47
+ getTab?(id: string): SidebarTab | undefined;
48
+ getSnapshot?(): {
49
+ sessionId: string | undefined;
50
+ };
51
+ subscribeState?(listener: () => void): () => void;
52
+ }
53
+ /** Tab type of the queue panel (also its `SidebarTab.id`). */
54
+ export declare const QUEUE_TAB_ID = "dsh-lowtide:queue";
55
+ /**
56
+ * True when the host would actually put this tab on screen: the type is
57
+ * registered, the user has not switched it off, and a session is in view.
58
+ * Anything else means `openTab` is a silent no-op, so the dock has to stay.
59
+ */
60
+ export declare function hostedNow(sidebar: SidebarHost): boolean;
61
+ /** Open (or focus) the queue tab. Falls back to expanding the composer dock
62
+ * when no sidebar host is present or the host would not show the tab, so
63
+ * "enqueued" always lands somewhere visible. */
64
+ export declare function openQueueTab(): void;
65
+ /** Wire the queue tab into better-sidebar when — and only when — it is there. */
66
+ export declare function installQueueTab(ctx: ClientContext): void;
67
+ export {};
@@ -1,20 +1,6 @@
1
1
  import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
2
- import type { ComposerChainProps } from '@deepseek-ai/dsh-client-ui-conversation/client';
3
2
  import { type NsTranslate } from '../i18n.ts';
4
- export interface InterceptMatched {
5
- kind: 'lt-intercept';
6
- }
7
- /**
8
- * Pure chain routing: priced window ∧ not dismissed ∧ session present ∧
9
- * draft non-empty. The draft condition keeps the native bar (and the queue
10
- * dock) visible until the user actually starts typing (PLAN §6.2).
11
- *
12
- * v0.2.2: the tier comes from the local clock (`store.tier`), so a stalled
13
- * push stream can neither hide nor freeze the intercept card at a boundary.
14
- */
15
- export declare function selectIntercept(owner: ComposerChainProps): InterceptMatched | null;
16
- export type InterceptCardProps = PropsRuntime<'conversation.composer'> & {
17
- matched: InterceptMatched;
3
+ export type InterceptCardProps = PropsRuntime<'conversation.input.dock'> & {
18
4
  t: NsTranslate;
19
5
  };
20
- export declare function InterceptCard(props: InterceptCardProps): React.JSX.Element;
6
+ export declare function InterceptCard(props: InterceptCardProps): React.JSX.Element | null;
@@ -4,5 +4,13 @@ import { NewTaskModal } from './NewTaskModal.tsx';
4
4
  export type QueueDockProps = PropsRuntime<'conversation.input.dock'> & {
5
5
  t: NsTranslate;
6
6
  };
7
- export declare function QueueDock(props: QueueDockProps): React.JSX.Element;
7
+ /** Body props: `t` comes from the slot seat or from a locale-bound thunk. */
8
+ export interface QueueDockViewProps {
9
+ t: NsTranslate;
10
+ /** `dock` = composer chrome; `panel` = fill a sidebar tab. */
11
+ seat?: 'dock' | 'panel';
12
+ }
13
+ /** Slot entry (conversation.input.dock). */
14
+ export declare function QueueDock(props: QueueDockProps): React.JSX.Element | null;
15
+ export declare function QueueDockView(props: QueueDockViewProps): React.JSX.Element | null;
8
16
  export { NewTaskModal };
@@ -5,16 +5,15 @@
5
5
  * A fully CONTROLLED presentational component — the caller owns the state:
6
6
  * - NewTaskModal (variant="modal") holds local state and submits via the
7
7
  * task API; it also owns `advancedOpen` (the separate advanced window);
8
- * - InterceptCard (variant="intercept") binds the prompt to the host input
9
- * store (inputActions.setDraft) and keeps the workspace in local state.
8
+ * - InterceptCard (variant="intercept") keeps only the workspace in local
9
+ * state; the native composer remains the sole prompt editor.
10
10
  *
11
11
  * modal: prompt (placeholder follows the strategy) + workspace/priority
12
12
  * side by side + strategy (plain pills, hover tooltips, dynamic
13
13
  * explanation line, rounds for iterative/sampling, per-strategy
14
14
  * guidance text) + permission + an "advanced" gear button that
15
15
  * opens a separate SMALL WINDOW (reasoning effort, locked files).
16
- * intercept: prompt + workspace + empty-workspace warning only — the quick
17
- * enqueue surface stays minimal.
16
+ * intercept: workspace + empty-workspace warning only.
18
17
  */
19
18
  import type { ReactElement } from 'react';
20
19
  import { type NsTranslate } from '../i18n.ts';
@@ -41,6 +41,7 @@ declare const zh: {
41
41
  'dock.disconnected': string;
42
42
  'dock.retry': string;
43
43
  'dock.title': string;
44
+ 'dock.tabTitle': string;
44
45
  'dock.pending': string;
45
46
  'pill.queued': string;
46
47
  'dock.report': string;
@@ -174,7 +175,6 @@ declare const zh: {
174
175
  'intercept.title': string;
175
176
  'intercept.tierPeak': string;
176
177
  'intercept.tierCustom': string;
177
- 'intercept.inputPlaceholder': string;
178
178
  'intercept.workspaceLabel': string;
179
179
  'intercept.workspacePlaceholder': string;
180
180
  'intercept.workspaceWarning': string;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dsh-lowtide browser half (Phase 1 assembly + review round 1 polish).
3
3
  * Six-surface registrations: ① PricePill (header utilities), ② InterceptCard
4
- * (composer chain), ③ QueueDock (input dock), ⑤ MorningReport (shell overlay).
4
+ * and ③ QueueDock (input dock), ⑤ MorningReport (shell overlay).
5
5
  * ④ ConfirmGate and ⑥ Settings land in the same overlay/settings slots.
6
6
  * Polling drives the entry store (SSE is the live path, polling the fallback).
7
7
  *
@@ -182,6 +182,12 @@ export interface ClientUiState {
182
182
  /** Last state-fetch error message (null when the last poll succeeded). */
183
183
  error: string | null;
184
184
  queueOpen: boolean;
185
+ /**
186
+ * True while an external sidebar host (dsh-better-sidebar) really shows the
187
+ * queue tab: the type is registered, the user has not switched it off and a
188
+ * session is in view. The composer dock then yields to the tab.
189
+ */
190
+ sidebarHosted: boolean;
185
191
  reportOpen: boolean;
186
192
  reportHistoryOpen: boolean;
187
193
  reportUnread: boolean;
@@ -194,7 +200,7 @@ export interface ClientUiState {
194
200
  activeLocale: string;
195
201
  /**
196
202
  * Tier derived from the local clock + the host's windows. This is what the
197
- * pill and the intercept card DISPLAY, so a stalled stream can never freeze
203
+ * pill and the peak prompt DISPLAY, so a stalled stream can never freeze
198
204
  * 闲时/忙时; the host's `price.tier` stays the pricing/ledger authority.
199
205
  */
200
206
  tier: TierSnapshot;
@@ -1,6 +1,6 @@
1
1
  export interface WorkspaceSession {
2
2
  id: string;
3
- /** Conversation title from the proj cache (null when never titled). */
3
+ /** Conversation title or first-prompt label from the projection cache. */
4
4
  title: string | null;
5
5
  lastModified: number;
6
6
  }
@@ -1,4 +1,5 @@
1
1
  import { SessionId } from '@deepseek-ai/dsh-session';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
3
  import type { Context } from '@deepseek-ai/cordis';
3
4
  import { type ReasoningEffort, type Task, type UsageLike } from 'lowtide-core';
4
5
  export interface TurnOutcome {
@@ -52,6 +53,59 @@ export declare function forkSeedBoundary(events: readonly {
52
53
  seq: number;
53
54
  }[]): number | null;
54
55
  export declare function sleep(ms: number): Promise<void>;
56
+ /**
57
+ * Resolve once `agent` is idle, or `false` after `timeoutMs`. The losing timer
58
+ * is cleared as soon as the race settles, so an idle wait leaves no pending
59
+ * handle (and no lingering ref) behind.
60
+ */
61
+ export declare function waitIdleFor(agent: Agent, timeoutMs: number): Promise<boolean>;
62
+ /**
63
+ * Canonical form of a directory for comparison. `fs.realpath` folds symlinks,
64
+ * `..` segments and short/long spellings; on Windows the result is case-folded
65
+ * because NTFS is case-insensitive (a task recorded as `C:\\Repo` must match
66
+ * the live session's `C:\\repo`). Unresolvable paths are compared as written.
67
+ */
68
+ export declare function canonicalPath(path: string): string;
69
+ export interface LiveExpectation {
70
+ /** Canonical task workspace; undefined = the task has no workspace. */
71
+ cwd?: string;
72
+ provider: string;
73
+ model: string;
74
+ /** The task's EXPLICIT reasoning effort; undefined = no requirement. */
75
+ reasoning?: string;
76
+ }
77
+ /**
78
+ * Why the source conversation cannot be driven in place — undefined means it
79
+ * can. Everything checked here is something a run would otherwise CHANGE on
80
+ * the user's own conversation: the permission preset (restored afterwards,
81
+ * but only if it maps back into the preset table), the workspace (fixed per
82
+ * session), the model route and the reasoning effort. A live conversation
83
+ * whose settings cannot be proven equivalent must be forked, never silently
84
+ * reconfigured.
85
+ */
86
+ /**
87
+ * The borrowed conversation's permission preset, captured ONCE. The same value
88
+ * feeds the guard and the finally restore, so a state change between two reads
89
+ * can never leave the user's conversation parked on the task's preset.
90
+ */
91
+ export interface PresetCapture {
92
+ /** The preset to hand back afterwards; undefined when it is unrestorable. */
93
+ previous?: string;
94
+ /** Why the preset cannot be restored; undefined when it can. */
95
+ reason?: string;
96
+ }
97
+ /**
98
+ * Capture the preset a borrowed conversation must be handed back with.
99
+ * `custom` has no catalog entry (set(session, 'custom') throws), and an empty,
100
+ * unreadable or unknown value cannot be proven equivalent — all of those mean
101
+ * the conversation must NOT be driven in place.
102
+ */
103
+ export declare function captureRestorablePreset(ctx: Context, session: unknown): PresetCapture;
104
+ /** Hand a borrowed conversation's preset back. Never throws. */
105
+ export declare function presetRestore(ctx: Context, session: unknown, previous: string): () => void;
106
+ export declare function liveAgentBlocker(ctx: Context, agent: Agent, expected: LiveExpectation,
107
+ /** Reuse the caller's single capture instead of reading the preset again. */
108
+ preset?: PresetCapture): string | undefined;
55
109
  export declare function usageOf(raw: unknown): UsageLike;
56
110
  /** Best-effort human-readable summary of a failed turn/end reason. */
57
111
  export declare function summarizeReason(reason: unknown, kind: string): string;