ework-web 0.10.21 → 0.10.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-web",
3
- "version": "0.10.21",
3
+ "version": "0.10.22",
4
4
  "type": "module",
5
5
  "description": "ework-web — standalone multi-project issue tracker. Local SQLite-backed, no external API dependency. Bun + TypeScript + SSR HTML.",
6
6
  "license": "MIT",
@@ -68,3 +68,38 @@ export async function listAllDaemons(): Promise<DaemonDetail[]> {
68
68
  return [];
69
69
  }
70
70
  }
71
+
72
+ export interface SessionDaemonInfo {
73
+ daemonId: number;
74
+ displayName: string;
75
+ endpoint: string;
76
+ }
77
+
78
+ export async function getSessionDaemonMap(): Promise<Map<string, SessionDaemonInfo>> {
79
+ try {
80
+ const rows = await getDB().all<{
81
+ opencode_session_id: string;
82
+ daemon_id: number;
83
+ display_name: string | null;
84
+ internal_endpoint: string | null;
85
+ }>(
86
+ `SELECT s.opencode_session_id, d.id AS daemon_id, d.display_name, d.internal_endpoint
87
+ FROM {{d_op_sessions}} s
88
+ JOIN {{d_issues}} i ON i.uid = s.issue_id
89
+ LEFT JOIN {{d_daemons}} d ON d.id = i.owner_daemon_id
90
+ WHERE s.opencode_session_id IS NOT NULL AND s.opencode_session_id != ''`,
91
+ );
92
+ const map = new Map<string, SessionDaemonInfo>();
93
+ for (const r of rows) {
94
+ map.set(r.opencode_session_id, {
95
+ daemonId: r.daemon_id,
96
+ displayName: r.display_name ?? `daemon-${r.daemon_id}`,
97
+ endpoint: r.internal_endpoint ?? "",
98
+ });
99
+ }
100
+ return map;
101
+ } catch (e) {
102
+ log.info(`coordination: session-daemon map failed (${e instanceof Error ? e.message : String(e)})`);
103
+ return new Map();
104
+ }
105
+ }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ import { homedir } from "os";
6
6
  import { loadConfig, DB_OVERRIDABLE, parseOverride, resolveTtsBackend } from "./config";
7
7
  import type { Config } from "./config";
8
8
  import { setConfig, initDB, getDB } from "./db";
9
- import { getActiveDaemons, listAllDaemons } from "./coordination";
9
+ import { getActiveDaemons, listAllDaemons, getSessionDaemonMap } from "./coordination";
10
10
  import { testMysqlConnection, migrateSqliteToMysql, writeMysqlEnv, migrateMysqlToSqlite, writeSqliteEnv, migrateDaemonSqliteToMysql, generateMysqlDDL } from "./db-admin";
11
11
  import type { MysqlTargetOpts } from "./db-admin";
12
12
  import { checkAuth, makeAuthCookieHeader, clearAuthCookieHeader, loginHTML, sanitizeNext, ensureBootstrapAdmin, ensureBootstrapSystem, isReservedSystemLogin } from "./auth";
@@ -610,7 +610,8 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
610
610
  if (url.pathname.match(SESSIONS_RE)) {
611
611
  const q = url.searchParams.get("q")?.trim() ?? "";
612
612
  try {
613
- const { html: body } = await buildSessionList(opencode, q);
613
+ const daemonMap = await getSessionDaemonMap();
614
+ const { html: body } = await buildSessionList(opencode, q, daemonMap);
614
615
  return html(body);
615
616
  } catch (e) {
616
617
  return html(errorPage("加载失败", errMsg(e)), e instanceof OpencodeError ? e.status : 502);
package/src/opencode.ts CHANGED
@@ -29,6 +29,7 @@ export interface SessionListItem {
29
29
  directory?: string;
30
30
  peakTokens?: number;
31
31
  msgCount?: number;
32
+ daemon?: { displayName: string; endpoint: string };
32
33
  }
33
34
 
34
35
  export interface SessionInfo {
@@ -1,4 +1,5 @@
1
1
  import type { OpencodeClientInterface, SessionListItem, SessionExport, SessionMessage, MessagePart, ToolState } from "../opencode";
2
+ import type { SessionDaemonInfo } from "../coordination";
2
3
  import { THEME_CSS, escapeHtml, escapeAttr, tabNavHTML } from "../render/layout";
3
4
  import { renderMarkdown, linkifySessionIDs, linkifyAbsPaths } from "../render/markdown";
4
5
  import { BUILD_ID } from "../build";
@@ -8,8 +9,19 @@ import { homedir } from "os";
8
9
 
9
10
  const LIST_LIMIT = 100;
10
11
 
11
- export async function buildSessionList(client: OpencodeClientInterface, q: string): Promise<{ html: string }> {
12
+ export async function buildSessionList(
13
+ client: OpencodeClientInterface,
14
+ q: string,
15
+ daemonMap?: Map<string, SessionDaemonInfo>,
16
+ ): Promise<{ html: string }> {
12
17
  let sessions = await client.listSessions(LIST_LIMIT);
18
+ if (daemonMap) {
19
+ sessions = sessions.map((s) => {
20
+ const di = daemonMap.get(s.id);
21
+ if (di) return { ...s, daemon: { displayName: di.displayName, endpoint: di.endpoint } };
22
+ return s;
23
+ });
24
+ }
13
25
  const needle = q.trim().toLowerCase();
14
26
  if (needle) {
15
27
  sessions = sessions.filter((s) => s.title.toLowerCase().includes(needle) || s.id.toLowerCase().includes(needle));
@@ -32,6 +44,7 @@ export async function buildSessionList(client: OpencodeClientInterface, q: strin
32
44
  .srow .st{font-weight:600;color:var(--text);font-size:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
33
45
  .srow .sm{display:flex;gap:1rem;color:var(--text-muted);font-size:12px;margin-top:.25rem;flex-wrap:wrap}
34
46
  .srow .sid{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
47
+ .sd-badge{background:var(--bg);border:1px solid var(--border);border-radius:4px;padding:0 .3rem;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px}
35
48
  .empty{padding:2rem;text-align:center;color:var(--text-muted)}
36
49
  </style></head><body>
37
50
  <header class="nav" style="display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px"><a href="/" style="color:var(--header-text)">🏠 ework-web</a><span style="opacity:.8"> · OpenCode 会话 ${sessions.length}</span></header>
@@ -50,6 +63,7 @@ function sessionRow(s: SessionListItem): string {
50
63
  const badges = [
51
64
  s.peakTokens ? `<span>🧮 峰值 ${kfmt(s.peakTokens)}</span>` : "",
52
65
  s.msgCount ? `<span>💬 ${s.msgCount}</span>` : "",
66
+ s.daemon ? `<span class="sd-badge" title="${escapeAttr(s.daemon.endpoint)}">🖥️ ${escapeHtml(s.daemon.displayName)} ${escapeHtml(s.daemon.endpoint)}</span>` : "",
53
67
  ].join("");
54
68
  return `<a class="srow" href="${escapeAttr(href)}">
55
69
  <div class="st">${escapeHtml(s.title)}</div>