@howaboua/pi-agent-board 0.0.4 → 0.0.6

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 (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +3 -1
  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 +15 -14
  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/{archive.ts → board/archive.ts} +17 -7
  11. package/src/{awareness.ts → board/awareness.ts} +6 -11
  12. package/src/board/briefing.ts +25 -0
  13. package/src/{contract.ts → board/contract.ts} +39 -29
  14. package/src/board/feature.ts +91 -0
  15. package/src/{identity.ts → board/identity.ts} +121 -37
  16. package/src/{integration.ts → board/integration.ts} +1 -0
  17. package/src/board/protocol.ts +117 -0
  18. package/src/{queries.ts → board/queries.ts} +9 -11
  19. package/src/{response.ts → board/response.ts} +7 -1
  20. package/src/board/runtime/activation.ts +50 -0
  21. package/src/{runtime → board/runtime}/coordinator.ts +76 -43
  22. package/src/board/runtime/engine.ts +40 -0
  23. package/src/board/runtime/index.ts +63 -0
  24. package/src/{runtime → board/runtime}/owner.ts +44 -15
  25. package/src/{runtime → board/runtime}/routing.ts +19 -4
  26. package/src/{runtime → board/runtime}/turns.ts +9 -1
  27. package/src/{search.ts → board/search.ts} +11 -9
  28. package/src/board/settings/panel.ts +193 -0
  29. package/src/{store.ts → board/store.ts} +45 -9
  30. package/src/{summarizer.ts → board/summarizer.ts} +3 -2
  31. package/src/{tool.ts → board/tool.ts} +5 -0
  32. package/src/board/viewer/AGENTS.md +1 -0
  33. package/src/{viewer → board/viewer}/archive.ts +24 -17
  34. package/src/{viewer → board/viewer}/index.ts +5 -1
  35. package/src/{viewer → board/viewer}/web/posts.js +0 -1
  36. package/src/guidance.ts +121 -0
  37. package/src/settings-navigation.ts +11 -0
  38. package/src/timestamps.ts +3 -0
  39. package/tsconfig.json +6 -2
  40. package/tsconfig.viewer.json +11 -0
  41. package/changelog.ts +0 -337
  42. package/src/briefing.ts +0 -32
  43. package/src/protocol.ts +0 -78
  44. package/src/runtime/index.ts +0 -113
  45. package/src/settings/panel.ts +0 -87
  46. /package/src/{activity.ts → board/activity.ts} +0 -0
  47. /package/src/{config.ts → board/config.ts} +0 -0
  48. /package/src/{consolidation.ts → board/consolidation.ts} +0 -0
  49. /package/src/{context-briefing.ts → board/context-briefing.ts} +0 -0
  50. /package/src/{delivery.ts → board/delivery.ts} +0 -0
  51. /package/src/{paging.ts → board/paging.ts} +0 -0
  52. /package/src/{runtime → board/runtime}/catchup.ts +0 -0
  53. /package/src/{summaries.ts → board/summaries.ts} +0 -0
  54. /package/src/{viewer → board/viewer}/config.ts +0 -0
  55. /package/src/{viewer → board/viewer}/contracts.ts +0 -0
  56. /package/src/{viewer → board/viewer}/server.ts +0 -0
  57. /package/src/{viewer → board/viewer}/source.ts +0 -0
  58. /package/src/{viewer → board/viewer}/web/app.js +0 -0
  59. /package/src/{viewer → board/viewer}/web/index.html +0 -0
  60. /package/src/{viewer → board/viewer}/web/navigation.js +0 -0
  61. /package/src/{viewer → board/viewer}/web/render.js +0 -0
  62. /package/src/{viewer → board/viewer}/web/session.js +0 -0
  63. /package/src/{viewer → board/viewer}/web/style.css +0 -0
  64. /package/src/{viewer → board/viewer}/web/updates.js +0 -0
@@ -0,0 +1,193 @@
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 = "scope";
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: "scope",
46
+ label: "Scope",
47
+ currentValue: scope,
48
+ values: ["session", "folder", "global"],
49
+ },
50
+ {
51
+ id: "enabled",
52
+ label: "Board",
53
+ currentValue: board.enabled(ctx) ? "on" : "off",
54
+ values: ["off", "on"],
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
+ rule,
110
+ ].map((line) => truncateToWidth(line, width, ""));
111
+ },
112
+ invalidate: () => list.invalidate(),
113
+ handleInput(data) {
114
+ if (
115
+ tabs &&
116
+ (matchesKey(data, Key.tab) ||
117
+ matchesKey(data, Key.shift(Key.tab)))
118
+ )
119
+ return done("notes");
120
+ list.handleInput(data);
121
+ tui.requestRender();
122
+ },
123
+ };
124
+ });
125
+ if (action === "close") return;
126
+ if (action === "notes") return "notes";
127
+ selected = action.id;
128
+ if (ctx.sessionManager.getSessionId() !== sessionId)
129
+ throw new Error("Session changed; reopen Board settings");
130
+ if (action.id === "scope") {
131
+ if (
132
+ action.value === "session" ||
133
+ action.value === "folder" ||
134
+ action.value === "global"
135
+ )
136
+ scope = action.value;
137
+ continue;
138
+ }
139
+ if (binding(ctx).upstream)
140
+ throw new Error("Change Board settings in the owning root session");
141
+ if (action.id === "enabled")
142
+ await board.setSetting(ctx, scope, action.value === "on");
143
+ else if (action.id === "automatic")
144
+ board.setAutomaticSummaries(ctx, action.value === "on");
145
+ else if (action.id === "model") {
146
+ writeBoardSummarySelection(
147
+ ctx.cwd,
148
+ action.value === "Luna" ? "luna" : "custom",
149
+ );
150
+ try {
151
+ resolveBoardSummaryModel(ctx.cwd);
152
+ } catch (error) {
153
+ ctx.ui.notify(
154
+ `Custom selected. ${error instanceof Error ? error.message : String(error)}`,
155
+ "warning",
156
+ );
157
+ continue;
158
+ }
159
+ ctx.ui.notify(
160
+ action.value === "Custom"
161
+ ? `Board summary model: Custom. Edit board.summary.custom in ${config.path}: set provider, model and reasoning.`
162
+ : "Board summary model: Luna (high).",
163
+ "info",
164
+ );
165
+ } else if (action.id === "consolidate") {
166
+ requestBoardConsolidation(pi, ctx);
167
+ return;
168
+ } else if (action.id === "viewer") {
169
+ const { openBoardViewer } = await import("../viewer/index.js");
170
+ await openBoardViewer(pi, ctx, (context, sessionName) => {
171
+ const own = binding(context);
172
+ if (own.upstream)
173
+ throw new Error(
174
+ "Open /board in the owning root session to view this shared board",
175
+ );
176
+ return {
177
+ sessionId: own.sessionId,
178
+ sessionName: sessionName ?? null,
179
+ boardId: own.boardId,
180
+ folder: own.ownerFolder,
181
+ databasePath: own.databasePath,
182
+ };
183
+ });
184
+ }
185
+ } catch (error) {
186
+ ctx.ui.notify(
187
+ error instanceof Error ? error.message : String(error),
188
+ "error",
189
+ );
190
+ return;
191
+ }
192
+ }
193
+ }
@@ -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,
@@ -20,6 +21,7 @@ export interface BoardScope {
20
21
  rootSessionId: string;
21
22
  ownerFolder: string;
22
23
  agentName: string;
24
+ legacyAgentName?: string;
23
25
  callerSessionId: string;
24
26
  members: readonly string[];
25
27
  }
@@ -42,7 +44,9 @@ export class BoardStore {
42
44
  readonly db: DatabaseSync;
43
45
  readonly summaries: ThreadSummaries;
44
46
  private readonly hasThreadStatuses: boolean;
45
- constructor(path: string, write: boolean) {
47
+ private readonly aliases: Map<string, string>;
48
+ constructor(path: string, write: boolean, aliases: [string, string][] = []) {
49
+ this.aliases = new Map(aliases);
46
50
  const fresh = !existsSync(path);
47
51
  if (write && fresh) mkdirSync(dirname(path), { recursive: true });
48
52
  this.db = new DatabaseSync(path, { readOnly: !write });
@@ -75,6 +79,18 @@ export class BoardStore {
75
79
  throw error;
76
80
  }
77
81
  }
82
+ canonicalAgent(value: string) {
83
+ return this.aliases.get(value) ?? value;
84
+ }
85
+ agentIdentities(value: string) {
86
+ const canonical = this.canonicalAgent(value);
87
+ return [
88
+ canonical,
89
+ ...[...this.aliases]
90
+ .filter(([, native]) => native === canonical)
91
+ .map(([legacy]) => legacy),
92
+ ];
93
+ }
78
94
  one<T>(sql: string, ...args: SQLInputValue[]): T | undefined {
79
95
  return this.db.prepare(sql).get(...args) as T | undefined;
80
96
  }
@@ -126,7 +142,7 @@ export class BoardStore {
126
142
  }>(
127
143
  `SELECT name AS channel_name,created_at,author AS created_by,
128
144
  (SELECT COUNT(*) FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name) AS message_count,
129
- (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
130
146
  FROM channels c WHERE board_id=? AND name=?`,
131
147
  board,
132
148
  name,
@@ -186,6 +202,16 @@ export class BoardStore {
186
202
  enabled: boolean,
187
203
  implicit = false,
188
204
  ) {
205
+ if (
206
+ implicit &&
207
+ this.one(
208
+ "SELECT 1 FROM subscriptions WHERE board_id=? AND target=? AND agent IN (SELECT value FROM json_each(?))",
209
+ board,
210
+ target,
211
+ JSON.stringify(this.agentIdentities(agent)),
212
+ )
213
+ )
214
+ return;
189
215
  this.run(
190
216
  implicit
191
217
  ? "INSERT OR IGNORE INTO subscriptions VALUES(?,?,?,1)"
@@ -194,7 +220,9 @@ export class BoardStore {
194
220
  );
195
221
  }
196
222
  private resolve(scope: BoardScope, value: string) {
197
- const path = agentPath(value, scope.agentName);
223
+ const path = this.canonicalAgent(
224
+ agentPath(value, scope.legacyAgentName ?? scope.agentName),
225
+ );
198
226
  if (!scope.members.includes(path))
199
227
  throw new Error(`Agent not bound to this tree: ${path}`);
200
228
  return path;
@@ -205,7 +233,7 @@ export class BoardStore {
205
233
  return this.publish(scope, params, requestId);
206
234
  if (params.action === "create_channel") {
207
235
  const name = required(params.channel_name, "channel_name");
208
- const now = new Date().toISOString();
236
+ const now = minuteTimestamp();
209
237
  this.ensureBoard(scope, now);
210
238
  this.insertChannel(scope, name, now);
211
239
  if (params.subscribe !== false)
@@ -230,7 +258,7 @@ export class BoardStore {
230
258
  : `channel:${channel.channel_name}`;
231
259
  const last = root
232
260
  ? (this.one<{ id: string }>(
233
- "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",
234
262
  board,
235
263
  root.thread_id,
236
264
  )?.id ?? null)
@@ -280,7 +308,7 @@ export class BoardStore {
280
308
  const recipients = new Set(
281
309
  (params.agents_to_notify ?? []).map((name) => this.resolve(scope, name)),
282
310
  );
283
- const now = new Date().toISOString();
311
+ const now = minuteTimestamp();
284
312
  const id = randomUUID();
285
313
  let channel: string;
286
314
  let root: string = id;
@@ -307,11 +335,19 @@ export class BoardStore {
307
335
  ).channel_name;
308
336
  const target = root === id ? `channel:${channel}` : `thread:${root}`;
309
337
  for (const { agent } of this.all<{ agent: string }>(
310
- "SELECT agent FROM subscriptions WHERE board_id=? AND target=? AND enabled=1",
338
+ `SELECT s.agent FROM subscriptions s WHERE s.board_id=? AND s.target=? AND s.enabled=1`,
311
339
  board,
312
340
  target,
313
- ))
314
- recipients.add(agent);
341
+ )) {
342
+ const canonical = this.canonicalAgent(agent);
343
+ const override = this.one<{ enabled: number }>(
344
+ "SELECT enabled FROM subscriptions WHERE board_id=? AND target=? AND agent=?",
345
+ board,
346
+ target,
347
+ canonical,
348
+ );
349
+ if (!override || override.enabled) recipients.add(canonical);
350
+ }
315
351
  recipients.delete(scope.agentName);
316
352
  const post: PostRecord = {
317
353
  message_id: 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,
@@ -0,0 +1,121 @@
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
+ import {
6
+ contextBriefingWindow,
7
+ recordContextBriefing,
8
+ registerContextBriefing,
9
+ } from "./board/context-briefing.js";
10
+ import type { FeatureSettings } from "./settings-navigation.js";
11
+
12
+ export interface CommsFeature extends FeatureSettings {
13
+ enabled(ctx: ExtensionContext): boolean;
14
+ gptPromptMode(): boolean;
15
+ }
16
+
17
+ /** Routing belongs here; feature carriers retain identity, recovery and navigation. */
18
+ function communicationGuidance(
19
+ notes: boolean,
20
+ board: boolean,
21
+ agents: boolean,
22
+ gpt = false,
23
+ ): string {
24
+ return [
25
+ board
26
+ ? gpt
27
+ ? "Board→peer findings/discovery, ownership/decisions/blockers affecting peers. Self-contained detail welcome; direct discovery≠parent relay. Existing thread replies; known shared peers→link≠repeat. No ack/status spam/duplicate completion reports."
28
+ : "Board: share findings, discoveries, ownership, decisions and blockers that change peers' work. Self-contained detail lets peers read directly, without a parent relay. Reply in existing threads. Link rather than repeat for peers with known Board access. Skip acknowledgements, routine status and duplicate completion reports."
29
+ : "",
30
+ notes
31
+ ? [
32
+ board
33
+ ? gpt
34
+ ? "Notes→current work/progress/recovery + Board references."
35
+ : "Notes: current work, progress and recovery, with Board references."
36
+ : "",
37
+ gpt
38
+ ? "Keep Notes checkpoints. Known recipient access→brief outcome/blocker + path; recipient READS checkpoint≠request full report."
39
+ : "Keep checkpoints in Notes. When the recipient is known to have access, return a brief outcome or blocker plus its path. The recipient reads the checkpoint for details rather than asking for a full report.",
40
+ ]
41
+ .filter(Boolean)
42
+ .join(" ")
43
+ : "",
44
+ notes || board
45
+ ? gpt
46
+ ? `${notes && board ? "Notes/Board" : notes ? "Notes" : "Board"} available here≠recipient access. Unknown/unshared access→self-contained actions taken/findings/unresolved state, not bare references.`
47
+ : `${notes && board ? "Notes and Board" : notes ? "Notes" : "Board"} availability here does not establish recipient access. If access is unknown or unshared, send a self-contained account of what you did, found and left unresolved, not just private references.`
48
+ : "",
49
+ agents && notes && board
50
+ ? gpt
51
+ ? "agents→assignments/urgent action≠default peer knowledge bus."
52
+ : "Use agents for assignments and urgent action, not as the default peer knowledge relay."
53
+ : "",
54
+ ]
55
+ .filter(Boolean)
56
+ .join(" ");
57
+ }
58
+
59
+ export function registerCommunicationGuidance(
60
+ pi: ExtensionAPI,
61
+ notes?: CommsFeature,
62
+ board?: CommsFeature,
63
+ ): void {
64
+ const owner =
65
+ notes && board
66
+ ? "agent-comms-routing"
67
+ : notes
68
+ ? "notes-routing"
69
+ : "board-routing";
70
+ registerContextBriefing(
71
+ pi,
72
+ "communication",
73
+ (ctx) => Boolean(notes?.enabled(ctx) || board?.enabled(ctx)),
74
+ async (ctx, windowId, messages) => {
75
+ // Feature owners supply enablement independently of provider declarations.
76
+ // Shepherdr keeps agents active, including as a nested Code/Notebook tool.
77
+ const capabilities = [
78
+ notes?.enabled(ctx) ?? false,
79
+ board?.enabled(ctx) ?? false,
80
+ pi.getActiveTools().includes("agents"),
81
+ Boolean(notes?.gptPromptMode() || board?.gptPromptMode()),
82
+ ] as const;
83
+ const routing = communicationGuidance(...capabilities);
84
+ const previous = messages
85
+ ?.flatMap((message) => {
86
+ if (
87
+ message.role !== "custom" ||
88
+ message.customType !== "codex-context-briefing"
89
+ )
90
+ return [];
91
+ const details = message.details;
92
+ return details &&
93
+ typeof details === "object" &&
94
+ "owner" in details &&
95
+ details.owner === owner &&
96
+ "id" in details &&
97
+ typeof details.id === "string"
98
+ ? [{ id: details.id, content: message.content }]
99
+ : [];
100
+ })
101
+ .at(-1);
102
+ if (!routing && !previous) return;
103
+ const content =
104
+ routing ||
105
+ `${notes && board ? "Notes and Board are" : notes ? "Notes is" : "Board is"} currently inactive. Earlier communication routing no longer applies.`;
106
+ if (previous?.content === content) return;
107
+ await recordContextBriefing(
108
+ pi,
109
+ ctx,
110
+ owner,
111
+ JSON.stringify([
112
+ ctx.sessionManager.getSessionId(),
113
+ contextBriefingWindow(ctx, windowId),
114
+ ...capabilities,
115
+ previous?.id,
116
+ ]),
117
+ async () => content,
118
+ );
119
+ },
120
+ );
121
+ }
@@ -0,0 +1,11 @@
1
+ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+
3
+ export type SettingsTab = "notes" | "board";
4
+ export type OpenSettings = (
5
+ ctx: ExtensionCommandContext,
6
+ tab: SettingsTab,
7
+ ) => Promise<void>;
8
+
9
+ export interface FeatureSettings {
10
+ openSettings(ctx: ExtensionCommandContext): Promise<SettingsTab | undefined>;
11
+ }
@@ -0,0 +1,3 @@
1
+ export function minuteTimestamp(value: string | number = Date.now()): string {
2
+ return new Date(value).toISOString().slice(0, 16) + "Z";
3
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,9 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
- "compilerOptions": { "allowImportingTsExtensions": true },
4
- "include": ["index.ts", "src/**/*.ts"]
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "checkJs": true,
6
+ "allowImportingTsExtensions": true
7
+ },
8
+ "include": ["*.ts", "src/**/*.ts", "src/**/*.mjs"]
5
9
  }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "noEmitOnError": true,
6
+ "rewriteRelativeImportExtensions": true,
7
+ "rootDir": "src/board/viewer",
8
+ "outDir": "dist/viewer"
9
+ },
10
+ "include": ["src/board/viewer/server.ts"]
11
+ }