@howaboua/pi-agent-board 0.0.3 → 0.0.5

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.
@@ -3,9 +3,9 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
- import { sendPolicyMessage } from "./delivery.js";
7
- import { type BoardBinding, binding } from "./identity.js";
8
- import type { BoardEnvelope } from "./protocol.js";
6
+ import { sendPolicyMessage } from "../delivery.js";
7
+ import { type BoardBinding, binding } from "../identity.js";
8
+ import type { BoardEnvelope } from "../protocol.js";
9
9
 
10
10
  type ActiveEnvelope = Extract<BoardEnvelope, { operation: "board-active" }>;
11
11
  type NoticeEnvelope = Extract<BoardEnvelope, { operation: "board-notify" }>;
package/src/search.ts CHANGED
@@ -19,10 +19,12 @@ export function searchBoard(
19
19
  args.push(params.channel_name);
20
20
  }
21
21
  if (params.author !== undefined) {
22
- clauses.push(`(author=? OR (kind='summary' AND EXISTS (
23
- SELECT 1 FROM posts a WHERE a.board_id=c.board_id AND a.root=c.thread_id AND a.author=?)))`);
24
- const author = agentPath(params.author, "/root");
25
- args.push(author, author);
22
+ clauses.push(`(author IN (SELECT value FROM json_each(?)) OR (kind='summary' AND EXISTS (
23
+ SELECT 1 FROM posts a WHERE a.board_id=c.board_id AND a.root=c.thread_id AND a.author IN (SELECT value FROM json_each(?)))))`);
24
+ const authors = JSON.stringify(
25
+ store.agentIdentities(agentPath(params.author, "/root")),
26
+ );
27
+ args.push(authors, authors);
26
28
  }
27
29
  if (params.query !== undefined) {
28
30
  clauses.push("instr(body_search,?)>0");
@@ -0,0 +1,87 @@
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
+ import {
6
+ readBoardSummaryConfig,
7
+ resolveBoardSummaryModel,
8
+ writeBoardSummarySelection,
9
+ } from "../config.js";
10
+ import { requestBoardConsolidation } from "../consolidation.js";
11
+ import { binding } from "../identity.js";
12
+ import type { BoardRuntime } from "../runtime/coordinator.js";
13
+
14
+ export async function openBoardSettings(
15
+ pi: ExtensionAPI,
16
+ ctx: ExtensionContext,
17
+ board: BoardRuntime,
18
+ ) {
19
+ if (!ctx.hasUI) {
20
+ ctx.ui.notify("Use /board settings in an interactive session", "warning");
21
+ return;
22
+ }
23
+ try {
24
+ if (binding(ctx).upstream)
25
+ throw new Error("Change Board settings in the owning root session");
26
+ const sessionId = ctx.sessionManager.getSessionId();
27
+ const consolidate =
28
+ "Consolidate one-off threads (sends a prompt to this session's agent)";
29
+ const setting = await ctx.ui.select("Board settings and actions", [
30
+ "Automatic summaries",
31
+ "Summary model",
32
+ consolidate,
33
+ ]);
34
+ if (setting === consolidate) {
35
+ if (ctx.sessionManager.getSessionId() !== sessionId)
36
+ throw new Error("Session changed; reopen Board settings");
37
+ requestBoardConsolidation(pi, ctx);
38
+ return;
39
+ }
40
+ if (!setting) return;
41
+ const config = readBoardSummaryConfig(ctx.cwd);
42
+ if (setting === "Automatic summaries") {
43
+ const selected = await ctx.ui.select(
44
+ `Automatic summaries: ${config.automatic ? "on" : "off"}. Summarise on closure? Uses model quota.`,
45
+ ["Off", "On"],
46
+ );
47
+ if (selected !== "Off" && selected !== "On") return;
48
+ board.setAutomaticSummaries(ctx, selected === "On");
49
+ ctx.ui.notify(
50
+ `Automatic board summaries: ${selected.toLowerCase()}.`,
51
+ "info",
52
+ );
53
+ return;
54
+ }
55
+ if (setting !== "Summary model") return;
56
+ const selected = await ctx.ui.select(
57
+ `Board summary model (global; current: ${config.selection === "luna" ? "Luna" : "Custom"})`,
58
+ ["Luna", "Custom"],
59
+ );
60
+ if (selected !== "Luna" && selected !== "Custom") return;
61
+ writeBoardSummarySelection(
62
+ ctx.cwd,
63
+ selected === "Luna" ? "luna" : "custom",
64
+ );
65
+ try {
66
+ resolveBoardSummaryModel(ctx.cwd);
67
+ } catch (error) {
68
+ ctx.ui.notify(
69
+ `Custom selected. ${error instanceof Error ? error.message : String(error)}`,
70
+ "warning",
71
+ );
72
+ return;
73
+ }
74
+ ctx.ui.notify(
75
+ selected === "Custom"
76
+ ? `Board summary model: Custom. Edit board.summary.custom in ${config.path}: set provider, model and reasoning.`
77
+ : "Board summary model: Luna (high).",
78
+ "info",
79
+ );
80
+ } catch (error) {
81
+ ctx.ui.notify(
82
+ error instanceof Error ? error.message : String(error),
83
+ "error",
84
+ );
85
+ }
86
+ return;
87
+ }
package/src/store.ts CHANGED
@@ -20,6 +20,7 @@ export interface BoardScope {
20
20
  rootSessionId: string;
21
21
  ownerFolder: string;
22
22
  agentName: string;
23
+ legacyAgentName?: string;
23
24
  callerSessionId: string;
24
25
  members: readonly string[];
25
26
  }
@@ -42,7 +43,9 @@ export class BoardStore {
42
43
  readonly db: DatabaseSync;
43
44
  readonly summaries: ThreadSummaries;
44
45
  private readonly hasThreadStatuses: boolean;
45
- constructor(path: string, write: boolean) {
46
+ private readonly aliases: Map<string, string>;
47
+ constructor(path: string, write: boolean, aliases: [string, string][] = []) {
48
+ this.aliases = new Map(aliases);
46
49
  const fresh = !existsSync(path);
47
50
  if (write && fresh) mkdirSync(dirname(path), { recursive: true });
48
51
  this.db = new DatabaseSync(path, { readOnly: !write });
@@ -75,6 +78,18 @@ export class BoardStore {
75
78
  throw error;
76
79
  }
77
80
  }
81
+ canonicalAgent(value: string) {
82
+ return this.aliases.get(value) ?? value;
83
+ }
84
+ agentIdentities(value: string) {
85
+ const canonical = this.canonicalAgent(value);
86
+ return [
87
+ canonical,
88
+ ...[...this.aliases]
89
+ .filter(([, native]) => native === canonical)
90
+ .map(([legacy]) => legacy),
91
+ ];
92
+ }
78
93
  one<T>(sql: string, ...args: SQLInputValue[]): T | undefined {
79
94
  return this.db.prepare(sql).get(...args) as T | undefined;
80
95
  }
@@ -186,6 +201,16 @@ export class BoardStore {
186
201
  enabled: boolean,
187
202
  implicit = false,
188
203
  ) {
204
+ if (
205
+ implicit &&
206
+ this.one(
207
+ "SELECT 1 FROM subscriptions WHERE board_id=? AND target=? AND agent IN (SELECT value FROM json_each(?))",
208
+ board,
209
+ target,
210
+ JSON.stringify(this.agentIdentities(agent)),
211
+ )
212
+ )
213
+ return;
189
214
  this.run(
190
215
  implicit
191
216
  ? "INSERT OR IGNORE INTO subscriptions VALUES(?,?,?,1)"
@@ -194,7 +219,9 @@ export class BoardStore {
194
219
  );
195
220
  }
196
221
  private resolve(scope: BoardScope, value: string) {
197
- const path = agentPath(value, scope.agentName);
222
+ const path = this.canonicalAgent(
223
+ agentPath(value, scope.legacyAgentName ?? scope.agentName),
224
+ );
198
225
  if (!scope.members.includes(path))
199
226
  throw new Error(`Agent not bound to this tree: ${path}`);
200
227
  return path;
@@ -307,11 +334,19 @@ export class BoardStore {
307
334
  ).channel_name;
308
335
  const target = root === id ? `channel:${channel}` : `thread:${root}`;
309
336
  for (const { agent } of this.all<{ agent: string }>(
310
- "SELECT agent FROM subscriptions WHERE board_id=? AND target=? AND enabled=1",
337
+ `SELECT s.agent FROM subscriptions s WHERE s.board_id=? AND s.target=? AND s.enabled=1`,
311
338
  board,
312
339
  target,
313
- ))
314
- recipients.add(agent);
340
+ )) {
341
+ const canonical = this.canonicalAgent(agent);
342
+ const override = this.one<{ enabled: number }>(
343
+ "SELECT enabled FROM subscriptions WHERE board_id=? AND target=? AND agent=?",
344
+ board,
345
+ target,
346
+ canonical,
347
+ );
348
+ if (!override || override.enabled) recipients.add(canonical);
349
+ }
315
350
  recipients.delete(scope.agentName);
316
351
  const post: PostRecord = {
317
352
  message_id: id,
package/src/tool.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
2
  import { BoardParameters } from "./contract.js";
3
3
  import { serializeBoardToolResult } from "./response.js";
4
- import type { BoardRuntime } from "./runtime.js";
4
+ import type { BoardRuntime } from "./runtime/coordinator.js";
5
5
 
6
6
  export function createBoardTool(board: BoardRuntime) {
7
7
  return defineTool({
@@ -15,6 +15,11 @@ export const PROTOCOL = "pi-board-viewer/1";
15
15
  const assets = new Map<string, readonly [string, string]>([
16
16
  ["/", ["web/index.html", "text/html; charset=utf-8"]],
17
17
  ["/app.js", ["web/app.js", "text/javascript; charset=utf-8"]],
18
+ ["/session.js", ["web/session.js", "text/javascript; charset=utf-8"]],
19
+ ["/posts.js", ["web/posts.js", "text/javascript; charset=utf-8"]],
20
+ ["/render.js", ["web/render.js", "text/javascript; charset=utf-8"]],
21
+ ["/navigation.js", ["web/navigation.js", "text/javascript; charset=utf-8"]],
22
+ ["/updates.js", ["web/updates.js", "text/javascript; charset=utf-8"]],
18
23
  ["/style.css", ["web/style.css", "text/css; charset=utf-8"]],
19
24
  [
20
25
  "/vendor/marked.js",