@howaboua/pi-agent-board 0.0.5 → 0.0.7

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +4 -2
  3. package/dist/viewer/archive.js +24 -17
  4. package/dist/viewer/web/posts.js +0 -1
  5. package/index.ts +5 -69
  6. package/package.json +14 -11
  7. package/runtime.ts +2 -0
  8. package/scripts/build-viewer.mjs +9 -0
  9. package/src/board/AGENTS.md +12 -0
  10. package/src/{awareness.ts → board/awareness.ts} +4 -10
  11. package/src/board/briefing.ts +25 -0
  12. package/src/{contract.ts → board/contract.ts} +31 -27
  13. package/src/board/feature.ts +91 -0
  14. package/src/{identity.ts → board/identity.ts} +50 -30
  15. package/src/board/protocol.ts +117 -0
  16. package/src/{queries.ts → board/queries.ts} +9 -11
  17. package/src/{response.ts → board/response.ts} +7 -1
  18. package/src/board/runtime/activation.ts +50 -0
  19. package/src/{runtime → board/runtime}/coordinator.ts +76 -43
  20. package/src/board/runtime/engine.ts +40 -0
  21. package/src/board/runtime/index.ts +63 -0
  22. package/src/{runtime → board/runtime}/owner.ts +16 -12
  23. package/src/{runtime → board/runtime}/routing.ts +2 -2
  24. package/src/{runtime → board/runtime}/turns.ts +9 -1
  25. package/src/{search.ts → board/search.ts} +5 -5
  26. package/src/board/settings/panel.ts +196 -0
  27. package/src/{store.ts → board/store.ts} +5 -4
  28. package/src/{summarizer.ts → board/summarizer.ts} +3 -2
  29. package/src/{tool.ts → board/tool.ts} +5 -0
  30. package/src/board/viewer/AGENTS.md +1 -0
  31. package/src/{viewer → board/viewer}/archive.ts +24 -17
  32. package/src/{viewer → board/viewer}/index.ts +5 -1
  33. package/src/{viewer → board/viewer}/web/posts.js +0 -1
  34. package/src/guidance.ts +121 -0
  35. package/src/settings-navigation.ts +11 -0
  36. package/src/timestamps.ts +3 -0
  37. package/tsconfig.json +6 -2
  38. package/tsconfig.viewer.json +11 -0
  39. package/src/briefing.ts +0 -32
  40. package/src/protocol.ts +0 -78
  41. package/src/runtime/index.ts +0 -113
  42. package/src/settings/panel.ts +0 -87
  43. /package/src/{activity.ts → board/activity.ts} +0 -0
  44. /package/src/{archive.ts → board/archive.ts} +0 -0
  45. /package/src/{config.ts → board/config.ts} +0 -0
  46. /package/src/{consolidation.ts → board/consolidation.ts} +0 -0
  47. /package/src/{context-briefing.ts → board/context-briefing.ts} +0 -0
  48. /package/src/{delivery.ts → board/delivery.ts} +0 -0
  49. /package/src/{integration.ts → board/integration.ts} +0 -0
  50. /package/src/{paging.ts → board/paging.ts} +0 -0
  51. /package/src/{runtime → board/runtime}/catchup.ts +0 -0
  52. /package/src/{summaries.ts → board/summaries.ts} +0 -0
  53. /package/src/{viewer → board/viewer}/config.ts +0 -0
  54. /package/src/{viewer → board/viewer}/contracts.ts +0 -0
  55. /package/src/{viewer → board/viewer}/server.ts +0 -0
  56. /package/src/{viewer → board/viewer}/source.ts +0 -0
  57. /package/src/{viewer → board/viewer}/web/app.js +0 -0
  58. /package/src/{viewer → board/viewer}/web/index.html +0 -0
  59. /package/src/{viewer → board/viewer}/web/navigation.js +0 -0
  60. /package/src/{viewer → board/viewer}/web/render.js +0 -0
  61. /package/src/{viewer → board/viewer}/web/session.js +0 -0
  62. /package/src/{viewer → board/viewer}/web/style.css +0 -0
  63. /package/src/{viewer → board/viewer}/web/updates.js +0 -0
@@ -0,0 +1,63 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import type { BoardRuntime } from "./coordinator.js";
3
+
4
+ export type { BoardRuntime };
5
+
6
+ const CLAIM = "@howaboua/pi-agent-board.owner/v1";
7
+ const AVAILABLE = "@howaboua/pi-agent-board.available/v1";
8
+ interface OwnerClaim {
9
+ runtime: Promise<BoardRuntime>;
10
+ }
11
+
12
+ /** Discover an explicitly loaded owner, including one loaded after this adapter. */
13
+ export function discoverBoard(
14
+ pi: ExtensionAPI,
15
+ attach: (runtime: BoardRuntime) => void,
16
+ ) {
17
+ let attached = false;
18
+ const accept = (runtime: BoardRuntime) => {
19
+ if (attached) return;
20
+ attached = true;
21
+ attach(runtime);
22
+ };
23
+ const request = () =>
24
+ pi.events.emit(CLAIM, {
25
+ accept: (claim: OwnerClaim) => {
26
+ void claim.runtime.then(accept);
27
+ },
28
+ });
29
+ const stop = pi.events.on(AVAILABLE, request);
30
+ request();
31
+ pi.on("session_shutdown", stop);
32
+ }
33
+
34
+ /** Only an explicitly loaded Board extension claims the owner; its engine stays lazy. */
35
+ export async function acquireBoard(pi: ExtensionAPI): Promise<BoardRuntime> {
36
+ let claim: OwnerClaim | undefined;
37
+ pi.events.emit(CLAIM, {
38
+ accept(value: OwnerClaim) {
39
+ claim = value;
40
+ },
41
+ });
42
+ if (!claim) {
43
+ const created: OwnerClaim = {
44
+ runtime: import("./coordinator.js").then(
45
+ ({ BoardRuntime }) => new BoardRuntime(pi),
46
+ ),
47
+ };
48
+ claim = created;
49
+ const stop = pi.events.on(CLAIM, (value) => {
50
+ if (
51
+ value &&
52
+ typeof value === "object" &&
53
+ "accept" in value &&
54
+ typeof value.accept === "function"
55
+ )
56
+ value.accept(created);
57
+ });
58
+ pi.on("session_shutdown", stop);
59
+ }
60
+ const runtime = await claim.runtime;
61
+ pi.events.emit(AVAILABLE, undefined);
62
+ return runtime;
63
+ }
@@ -1,5 +1,4 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { executeArchive, readSubscribedUpdates } from "../archive.js";
3
2
  import {
4
3
  agentPath,
5
4
  type BoardParams,
@@ -14,8 +13,8 @@ import type { BoardTurns } from "./turns.js";
14
13
 
15
14
  /** Owner execution begins at membership validation; archive commit precedes delivery. */
16
15
  export class BoardOwner {
17
- private readonly turns: BoardTurns;
18
- private readonly summarizer: BoardSummarizer;
16
+ private readonly getTurns: () => BoardTurns;
17
+ private readonly getSummarizer: () => BoardSummarizer;
19
18
  private readonly adapterOrUndefined: () => BoardAdapter | undefined;
20
19
  private readonly adapter: () => BoardAdapter;
21
20
  private readonly notify: (
@@ -24,8 +23,8 @@ export class BoardOwner {
24
23
  signal?: AbortSignal,
25
24
  ) => Promise<unknown>;
26
25
  constructor(
27
- turns: BoardTurns,
28
- summarizer: BoardSummarizer,
26
+ turns: () => BoardTurns,
27
+ summarizer: () => BoardSummarizer,
29
28
  adapterOrUndefined: () => BoardAdapter | undefined,
30
29
  adapter: () => BoardAdapter,
31
30
  notify: (
@@ -34,8 +33,8 @@ export class BoardOwner {
34
33
  signal?: AbortSignal,
35
34
  ) => Promise<unknown>,
36
35
  ) {
37
- this.turns = turns;
38
- this.summarizer = summarizer;
36
+ this.getTurns = turns;
37
+ this.getSummarizer = summarizer;
39
38
  this.adapterOrUndefined = adapterOrUndefined;
40
39
  this.adapter = adapter;
41
40
  this.notify = notify;
@@ -64,12 +63,16 @@ export class BoardOwner {
64
63
  )
65
64
  return this.adapter().commitDirectory(own, directory, caller, request);
66
65
  if (request.operation === "board-active") {
67
- if (own.enabled) this.turns.register(caller, request);
66
+ if (own.enabled) this.getTurns().register(caller, request);
68
67
  return true;
69
68
  }
70
69
  if (request.operation === "board-catchup")
71
70
  return own.enabled
72
- ? readSubscribedUpdates(caller, request.seen, boardAliases(ctx))
71
+ ? (await import("../archive.js")).readSubscribedUpdates(
72
+ caller,
73
+ request.seen,
74
+ boardAliases(ctx),
75
+ )
73
76
  : [];
74
77
  if (request.operation !== "board-call")
75
78
  throw new Error("Invalid board owner operation");
@@ -98,7 +101,8 @@ export class BoardOwner {
98
101
  caller.legacyAgentName ?? caller.agentName,
99
102
  ),
100
103
  };
101
- const active = new Map(this.turns.active);
104
+ const active = new Map(this.getTurns().active);
105
+ const { executeArchive } = await import("../archive.js");
102
106
  const result = await executeArchive(
103
107
  { ...caller, enabled: own.enabled },
104
108
  directory.map((member) => member.agentName),
@@ -110,9 +114,9 @@ export class BoardOwner {
110
114
  // Replayed mutations have no notice: never start or cancel twice for a retry.
111
115
  if (params.action === "set_status") {
112
116
  if (params.status === "open")
113
- this.summarizer.cancel(own.boardId, result.notice.thread_id);
117
+ this.getSummarizer().cancel(own.boardId, result.notice.thread_id);
114
118
  else
115
- this.summarizer.start(
119
+ this.getSummarizer().start(
116
120
  ctx,
117
121
  own,
118
122
  result.notice.thread_id,
@@ -11,7 +11,7 @@ import type { BoardTurns } from "./turns.js";
11
11
  /** Routes membership/setting/notice envelopes; lifecycle refresh stays with the runtime. */
12
12
  export class BoardRouting {
13
13
  private readonly pi: ExtensionAPI;
14
- private readonly turns: BoardTurns;
14
+ private readonly turns: Pick<BoardTurns, "deliver">;
15
15
  private readonly owner: BoardOwner;
16
16
  private readonly refresh: (ctx: ExtensionContext) => Promise<void>;
17
17
  private readonly reportAvailability: (
@@ -21,7 +21,7 @@ export class BoardRouting {
21
21
  adapter: BoardAdapter | undefined;
22
22
  constructor(
23
23
  pi: ExtensionAPI,
24
- turns: BoardTurns,
24
+ turns: Pick<BoardTurns, "deliver">,
25
25
  owner: BoardOwner,
26
26
  refresh: (ctx: ExtensionContext) => Promise<void>,
27
27
  reportAvailability: (ctx: ExtensionContext, error?: unknown) => void,
@@ -72,12 +72,20 @@ export class BoardTurns {
72
72
  own.agentName !== request.target
73
73
  )
74
74
  return false;
75
+ const {
76
+ message_id,
77
+ channel_name,
78
+ author,
79
+ thread_id,
80
+ text_preview,
81
+ truncated,
82
+ } = request.notice;
75
83
  // No await between running-turn check and steering. Never use the idle kickoff.
76
84
  sendPolicyMessage(
77
85
  pi,
78
86
  {
79
87
  customType: "shepherdr-board-post",
80
- content: `Board post ${JSON.stringify(request.notice)}`,
88
+ content: `Board post ${JSON.stringify({ message_id, channel_name, author, thread_id, text_preview, truncated })}`,
81
89
  display: true,
82
90
  },
83
91
  { deliverAs: "steer" },
@@ -31,14 +31,14 @@ export function searchBoard(
31
31
  args.push(caseFold(params.query));
32
32
  }
33
33
  if (params.after_message_id !== undefined) {
34
- const after = store.one<{ created_at: string; seq: number }>(
35
- "SELECT created_at,seq FROM posts WHERE board_id=? AND id=?",
34
+ const after = store.one<{ seq: number }>(
35
+ "SELECT seq FROM posts WHERE board_id=? AND id=?",
36
36
  board,
37
37
  params.after_message_id,
38
38
  );
39
39
  if (!after) throw new Error("Post not found in this board");
40
- clauses.push("(created_at,seq)>(?,?)");
41
- args.push(after.created_at, after.seq);
40
+ clauses.push("seq>?");
41
+ args.push(after.seq);
42
42
  }
43
43
  const rows = store.all<
44
44
  | (PostRecord & { kind: "post" })
@@ -56,7 +56,7 @@ export function searchBoard(
56
56
  : ""
57
57
  }
58
58
  ) SELECT * FROM candidates c WHERE ${clauses.join(" AND ")}
59
- ORDER BY created_at DESC,seq DESC LIMIT ? OFFSET ?`,
59
+ ORDER BY seq DESC LIMIT ? OFFSET ?`,
60
60
  ...args,
61
61
  limit + 1,
62
62
  offset,
@@ -0,0 +1,196 @@
1
+ import {
2
+ type ExtensionAPI,
3
+ type ExtensionContext,
4
+ getSettingsListTheme,
5
+ } from "@earendil-works/pi-coding-agent";
6
+ import {
7
+ Key,
8
+ matchesKey,
9
+ SettingsList,
10
+ truncateToWidth,
11
+ wrapTextWithAnsi,
12
+ } from "@earendil-works/pi-tui";
13
+ import {
14
+ type BoardScope,
15
+ readBoardSummaryConfig,
16
+ resolveBoardSummaryModel,
17
+ writeBoardSummarySelection,
18
+ } from "../config.js";
19
+ import { requestBoardConsolidation } from "../consolidation.js";
20
+ import { binding } from "../identity.js";
21
+ import type { BoardRuntime } from "../runtime/coordinator.js";
22
+
23
+ type Action = { id: string; value: string } | "close" | "notes";
24
+
25
+ export async function openBoardSettings(
26
+ pi: ExtensionAPI,
27
+ ctx: ExtensionContext,
28
+ board: BoardRuntime,
29
+ tabs = true,
30
+ ): Promise<"notes" | undefined> {
31
+ if (!ctx.hasUI) {
32
+ ctx.ui.notify("Use /board settings in an interactive session", "warning");
33
+ return;
34
+ }
35
+ let scope: BoardScope = "session";
36
+ let selected = "enabled";
37
+ const sessionId = ctx.sessionManager.getSessionId();
38
+ while (true) {
39
+ try {
40
+ const config = readBoardSummaryConfig(ctx.cwd);
41
+ const action = await ctx.ui.custom<Action>((tui, theme, _kb, done) => {
42
+ const list = new SettingsList(
43
+ [
44
+ {
45
+ id: "enabled",
46
+ label: "Enabled",
47
+ currentValue: board.enabled(ctx) ? "On" : "Off",
48
+ values: ["Off", "On"],
49
+ },
50
+ {
51
+ id: "scope",
52
+ label: "Scope",
53
+ currentValue: scope,
54
+ values: ["session", "folder", "global"],
55
+ },
56
+ {
57
+ id: "automatic",
58
+ label: "Automatic summaries",
59
+ description: "Summarise on closure. Uses model quota.",
60
+ currentValue: config.automatic ? "on" : "off",
61
+ values: ["off", "on"],
62
+ },
63
+ {
64
+ id: "model",
65
+ label: "Summary model",
66
+ description: "Global preference.",
67
+ currentValue: config.selection === "luna" ? "Luna" : "Custom",
68
+ values: ["Luna", "Custom"],
69
+ },
70
+ {
71
+ id: "consolidate",
72
+ label: "Consolidate one-off threads",
73
+ description: "Sends a prompt to this session's agent.",
74
+ currentValue: "select…",
75
+ values: ["select…", "run…"],
76
+ },
77
+ {
78
+ id: "viewer",
79
+ label: "Open viewer",
80
+ currentValue: "select…",
81
+ values: ["select…", "open…"],
82
+ },
83
+ ],
84
+ 6,
85
+ getSettingsListTheme(),
86
+ (id, value) => done({ id, value }),
87
+ () => done("close"),
88
+ { enableSearch: false },
89
+ );
90
+ list.selectItem(selected);
91
+ return {
92
+ render(width) {
93
+ const wrap = (text: string) =>
94
+ wrapTextWithAnsi(text, Math.max(1, width - 2)).map(
95
+ (line) => ` ${line}`,
96
+ );
97
+ const rule = theme.fg("accent", "─".repeat(Math.max(0, width)));
98
+ return [
99
+ rule,
100
+ ` ${tabs ? `${theme.fg("dim", "Notes")} / ` : ""}${theme.bold("Board")}`,
101
+ "",
102
+ ...wrap(board.status(ctx, false)),
103
+ "",
104
+ ...list.render(width).slice(0, -2),
105
+ "",
106
+ ...wrap(
107
+ `${tabs ? "Tab switch tab · " : ""}↑/↓ select · Enter/Space change · Esc close`,
108
+ ).map((line) => theme.fg("dim", line)),
109
+ ...wrap("Settings saved immediately").map((line) =>
110
+ theme.fg("dim", line),
111
+ ),
112
+ rule,
113
+ ].map((line) => truncateToWidth(line, width, ""));
114
+ },
115
+ invalidate: () => list.invalidate(),
116
+ handleInput(data) {
117
+ if (
118
+ tabs &&
119
+ (matchesKey(data, Key.tab) ||
120
+ matchesKey(data, Key.shift(Key.tab)))
121
+ )
122
+ return done("notes");
123
+ list.handleInput(data);
124
+ tui.requestRender();
125
+ },
126
+ };
127
+ });
128
+ if (action === "close") return;
129
+ if (action === "notes") return "notes";
130
+ selected = action.id;
131
+ if (ctx.sessionManager.getSessionId() !== sessionId)
132
+ throw new Error("Session changed; reopen Board settings");
133
+ if (action.id === "scope") {
134
+ if (
135
+ action.value === "session" ||
136
+ action.value === "folder" ||
137
+ action.value === "global"
138
+ )
139
+ scope = action.value;
140
+ continue;
141
+ }
142
+ if (binding(ctx).upstream)
143
+ throw new Error("Change Board settings in the owning root session");
144
+ if (action.id === "enabled")
145
+ await board.setSetting(ctx, scope, action.value === "On");
146
+ else if (action.id === "automatic")
147
+ board.setAutomaticSummaries(ctx, action.value === "on");
148
+ else if (action.id === "model") {
149
+ writeBoardSummarySelection(
150
+ ctx.cwd,
151
+ action.value === "Luna" ? "luna" : "custom",
152
+ );
153
+ try {
154
+ resolveBoardSummaryModel(ctx.cwd);
155
+ } catch (error) {
156
+ ctx.ui.notify(
157
+ `Custom selected. ${error instanceof Error ? error.message : String(error)}`,
158
+ "warning",
159
+ );
160
+ continue;
161
+ }
162
+ ctx.ui.notify(
163
+ action.value === "Custom"
164
+ ? `Board summary model: Custom. Edit board.summary.custom in ${config.path}: set provider, model and reasoning.`
165
+ : "Board summary model: Luna (high).",
166
+ "info",
167
+ );
168
+ } else if (action.id === "consolidate") {
169
+ requestBoardConsolidation(pi, ctx);
170
+ return;
171
+ } else if (action.id === "viewer") {
172
+ const { openBoardViewer } = await import("../viewer/index.js");
173
+ await openBoardViewer(pi, ctx, (context, sessionName) => {
174
+ const own = binding(context);
175
+ if (own.upstream)
176
+ throw new Error(
177
+ "Open /board in the owning root session to view this shared board",
178
+ );
179
+ return {
180
+ sessionId: own.sessionId,
181
+ sessionName: sessionName ?? null,
182
+ boardId: own.boardId,
183
+ folder: own.ownerFolder,
184
+ databasePath: own.databasePath,
185
+ };
186
+ });
187
+ }
188
+ } catch (error) {
189
+ ctx.ui.notify(
190
+ error instanceof Error ? error.message : String(error),
191
+ "error",
192
+ );
193
+ return;
194
+ }
195
+ }
196
+ }
@@ -3,6 +3,7 @@ import { chmodSync, existsSync, mkdirSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  import { DatabaseSync, type SQLInputValue } from "node:sqlite";
5
5
  import { caseFold } from "unicode-case-folding";
6
+ import { minuteTimestamp } from "../timestamps.js";
6
7
  import {
7
8
  agentPath,
8
9
  type BoardParams,
@@ -141,7 +142,7 @@ export class BoardStore {
141
142
  }>(
142
143
  `SELECT name AS channel_name,created_at,author AS created_by,
143
144
  (SELECT COUNT(*) FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name) AS message_count,
144
- (SELECT id FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name ORDER BY created_at DESC,seq DESC LIMIT 1) AS last_message_id
145
+ (SELECT id FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name ORDER BY seq DESC LIMIT 1) AS last_message_id
145
146
  FROM channels c WHERE board_id=? AND name=?`,
146
147
  board,
147
148
  name,
@@ -232,7 +233,7 @@ export class BoardStore {
232
233
  return this.publish(scope, params, requestId);
233
234
  if (params.action === "create_channel") {
234
235
  const name = required(params.channel_name, "channel_name");
235
- const now = new Date().toISOString();
236
+ const now = minuteTimestamp();
236
237
  this.ensureBoard(scope, now);
237
238
  this.insertChannel(scope, name, now);
238
239
  if (params.subscribe !== false)
@@ -257,7 +258,7 @@ export class BoardStore {
257
258
  : `channel:${channel.channel_name}`;
258
259
  const last = root
259
260
  ? (this.one<{ id: string }>(
260
- "SELECT id FROM posts WHERE board_id=? AND root=? ORDER BY created_at DESC,seq DESC LIMIT 1",
261
+ "SELECT id FROM posts WHERE board_id=? AND root=? ORDER BY seq DESC LIMIT 1",
261
262
  board,
262
263
  root.thread_id,
263
264
  )?.id ?? null)
@@ -307,7 +308,7 @@ export class BoardStore {
307
308
  const recipients = new Set(
308
309
  (params.agents_to_notify ?? []).map((name) => this.resolve(scope, name)),
309
310
  );
310
- const now = new Date().toISOString();
311
+ const now = minuteTimestamp();
311
312
  const id = randomUUID();
312
313
  let channel: string;
313
314
  let root: string = id;
@@ -4,6 +4,7 @@ import {
4
4
  type ExtensionContext,
5
5
  estimateTokens,
6
6
  } from "@earendil-works/pi-coding-agent";
7
+ import { minuteTimestamp } from "../timestamps.js";
7
8
  import { readBoardSummaryConfig, resolveBoardSummaryModel } from "./config.js";
8
9
  import type { BoardBinding } from "./identity.js";
9
10
 
@@ -60,7 +61,7 @@ async function snapshot(
60
61
  status: state.status,
61
62
  posts: posts.map((post) => ({
62
63
  author: post.author,
63
- timestamp: post.created_at,
64
+ timestamp: minuteTimestamp(post.created_at),
64
65
  text: post.text,
65
66
  ...(post.id === state.status_message_id
66
67
  ? { closing_comment: true }
@@ -181,7 +182,7 @@ export class BoardSummarizer {
181
182
  thread_id: thread,
182
183
  status_message_id: input.status_message_id,
183
184
  through_message_id: input.through_message_id,
184
- created_at: new Date().toISOString(),
185
+ created_at: minuteTimestamp(),
185
186
  provider: response.provider,
186
187
  model: response.model,
187
188
  reasoning: response.thinkingLevel ?? selected.reasoning,
@@ -1,8 +1,11 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
+ import { compile } from "@earendil-works/pi-schema";
2
3
  import { BoardParameters } from "./contract.js";
3
4
  import { serializeBoardToolResult } from "./response.js";
4
5
  import type { BoardRuntime } from "./runtime/coordinator.js";
5
6
 
7
+ const boardParametersValidator = compile(BoardParameters);
8
+
6
9
  export function createBoardTool(board: BoardRuntime) {
7
10
  return defineTool({
8
11
  name: "board",
@@ -12,6 +15,8 @@ export function createBoardTool(board: BoardRuntime) {
12
15
  executionMode: "sequential",
13
16
  async execute(id, params, signal, _onUpdate, ctx) {
14
17
  signal?.throwIfAborted();
18
+ if (!boardParametersValidator.check(params))
19
+ throw new Error("Invalid board request; call board help");
15
20
  const value = await board.execute(ctx, params, id);
16
21
  return {
17
22
  content: [
@@ -0,0 +1 @@
1
+ - The viewer compiles independently under `tsconfig.viewer.json`. Keep runtime imports inside this subtree or packaged dependencies, not extension modules outside its build root.
@@ -30,15 +30,18 @@ function count(row: Row, key: string): number {
30
30
  throw new Error(`Invalid board archive count: ${key}`);
31
31
  return value;
32
32
  }
33
- function nullableText(row: Row, key: string): string | null {
34
- return row[key] === null ? null : text(row, key);
33
+ function timestamp(row: Row, key: string): string {
34
+ return new Date(text(row, key)).toISOString().slice(0, 16) + "Z";
35
+ }
36
+ function nullableTimestamp(row: Row, key: string): string | null {
37
+ return row[key] === null ? null : timestamp(row, key);
35
38
  }
36
39
  function post(row: Row): Post {
37
40
  return {
38
41
  id: text(row, "id"),
39
42
  channel: text(row, "channel"),
40
43
  author: text(row, "author"),
41
- createdAt: text(row, "created_at"),
44
+ createdAt: timestamp(row, "created_at"),
42
45
  text: text(row, "text"),
43
46
  };
44
47
  }
@@ -102,7 +105,7 @@ export class Archive {
102
105
  return row
103
106
  ? {
104
107
  text: text(row, "text"),
105
- createdAt: text(row, "created_at"),
108
+ createdAt: timestamp(row, "created_at"),
106
109
  throughMessageId: text(row, "through_message_id"),
107
110
  hasNewerPosts: count(row, "has_newer_posts") === 1,
108
111
  provider: text(row, "provider"),
@@ -116,17 +119,17 @@ export class Archive {
116
119
  const { databasePath: _path, ...context } = this.source;
117
120
  const boards: BoardSummary[] = this.all(
118
121
  `SELECT b.board_id,b.root_session_id,b.created_at,
119
- (SELECT MAX(created_at) FROM posts WHERE board_id=b.board_id) AS last_activity,
122
+ (SELECT created_at FROM posts WHERE board_id=b.board_id ORDER BY seq DESC LIMIT 1) AS last_activity,
120
123
  (SELECT COUNT(*) FROM channels WHERE board_id=b.board_id) AS channels,
121
124
  (SELECT COUNT(*) FROM posts WHERE board_id=b.board_id) AS posts,
122
125
  (SELECT COUNT(DISTINCT author) FROM posts WHERE board_id=b.board_id) AS agents
123
- FROM boards b WHERE owner_folder=? ORDER BY COALESCE(last_activity,b.created_at) DESC`,
126
+ FROM boards b WHERE owner_folder=? ORDER BY substr(COALESCE(last_activity,b.created_at),1,16) DESC,(SELECT MAX(seq) FROM posts WHERE board_id=b.board_id) DESC,b.board_id DESC`,
124
127
  this.source.folder,
125
128
  ).map((row) => ({
126
129
  id: text(row, "board_id"),
127
130
  rootSessionId: text(row, "root_session_id"),
128
- createdAt: text(row, "created_at"),
129
- lastActivity: nullableText(row, "last_activity"),
131
+ createdAt: timestamp(row, "created_at"),
132
+ lastActivity: nullableTimestamp(row, "last_activity"),
130
133
  channels: count(row, "channels"),
131
134
  posts: count(row, "posts"),
132
135
  agents: count(row, "agents"),
@@ -154,25 +157,28 @@ export class Archive {
154
157
  const board = this.board(id);
155
158
  const channels = this.all(
156
159
  `SELECT c.name,c.author,c.created_at,COUNT(p.id) AS posts,
157
- COUNT(CASE WHEN p.id=p.root THEN 1 END) AS threads,MAX(p.created_at) AS last_activity
160
+ COUNT(CASE WHEN p.id=p.root THEN 1 END) AS threads,
161
+ (SELECT created_at FROM posts latest WHERE latest.board_id=c.board_id AND latest.channel=c.name ORDER BY seq DESC LIMIT 1) AS last_activity
158
162
  FROM channels c LEFT JOIN posts p ON p.board_id=c.board_id AND p.channel=c.name
159
- WHERE c.board_id=? GROUP BY c.name ORDER BY COALESCE(last_activity,c.created_at) DESC,c.name`,
163
+ WHERE c.board_id=? GROUP BY c.name ORDER BY substr(COALESCE(last_activity,c.created_at),1,16) DESC,MAX(p.seq) DESC,c.name`,
160
164
  id,
161
165
  ).map((row) => ({
162
166
  name: text(row, "name"),
163
167
  author: text(row, "author"),
164
- createdAt: text(row, "created_at"),
168
+ createdAt: timestamp(row, "created_at"),
165
169
  posts: count(row, "posts"),
166
170
  threads: count(row, "threads"),
167
- lastActivity: nullableText(row, "last_activity"),
171
+ lastActivity: nullableTimestamp(row, "last_activity"),
168
172
  }));
169
173
  const agents = this.all(
170
- "SELECT author,COUNT(*) AS posts,MAX(created_at) AS last_activity FROM posts WHERE board_id=? GROUP BY author ORDER BY posts DESC,author",
174
+ `SELECT author,COUNT(*) AS posts,
175
+ (SELECT created_at FROM posts latest WHERE latest.board_id=p.board_id AND latest.author=p.author ORDER BY seq DESC LIMIT 1) AS last_activity
176
+ FROM posts p WHERE board_id=? GROUP BY author ORDER BY posts DESC,author`,
171
177
  id,
172
178
  ).map((row) => ({
173
179
  name: text(row, "author"),
174
180
  posts: count(row, "posts"),
175
- lastActivity: text(row, "last_activity"),
181
+ lastActivity: timestamp(row, "last_activity"),
176
182
  }));
177
183
  const subscriptions = this.all(
178
184
  "SELECT target,agent,enabled FROM subscriptions WHERE board_id=? ORDER BY target,agent",
@@ -230,7 +236,8 @@ export class Archive {
230
236
  const cursor = this.cursor(params);
231
237
  const rows = this.all(
232
238
  `SELECT r.id,r.channel,r.author,r.text,r.created_at,
233
- MAX(p.created_at) AS last_activity,MAX(p.seq) AS last_seq,COUNT(*)-1 AS replies
239
+ (SELECT created_at FROM posts latest WHERE latest.board_id=r.board_id AND latest.root=r.id ORDER BY seq DESC LIMIT 1) AS last_activity,
240
+ MAX(p.seq) AS last_seq,COUNT(*)-1 AS replies
234
241
  FROM posts r JOIN posts p ON p.board_id=r.board_id AND p.root=r.id
235
242
  WHERE ${where.join(" AND ")} GROUP BY r.id HAVING MAX(p.seq)<? ORDER BY last_seq DESC LIMIT 41`,
236
243
  ...args,
@@ -252,8 +259,8 @@ export class Archive {
252
259
  ? text(row, "text")
253
260
  : (summary?.text ?? text(row, "text"))
254
261
  ).slice(0, 600),
255
- createdAt: text(row, "created_at"),
256
- lastActivity: text(row, "last_activity"),
262
+ createdAt: timestamp(row, "created_at"),
263
+ lastActivity: timestamp(row, "last_activity"),
257
264
  replies: count(row, "replies"),
258
265
  };
259
266
  }),
@@ -76,7 +76,11 @@ async function ensureServer(config: ViewerConfig): Promise<string> {
76
76
  try {
77
77
  const child = spawn(
78
78
  process.execPath,
79
- [fileURLToPath(new URL("../../dist/viewer/server.js", import.meta.url))],
79
+ [
80
+ fileURLToPath(
81
+ new URL("../../../dist/viewer/server.js", import.meta.url),
82
+ ),
83
+ ],
80
84
  { detached: true, stdio: ["ignore", log, log], windowsHide: true },
81
85
  );
82
86
  child.once("error", (error) => {
@@ -51,7 +51,6 @@ export function renderPost(post, root, summary = false) {
51
51
  const header = node("header", "post-header");
52
52
  const time = node("time", "", date(post.createdAt));
53
53
  time.dateTime = post.createdAt;
54
- time.title = post.createdAt;
55
54
  header.append(
56
55
  summary ? node("strong", "", "Summary") : author(post.author),
57
56
  time,