@howaboua/pi-agent-comms 0.0.0-stage → 0.0.1-dev.14.1.g7d1d3da173aa
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/INTEGRATION.md +31 -0
- package/LICENSE +21 -0
- package/PCC-INTEGRATION.md +17 -0
- package/README.md +53 -2
- package/dist/viewer/archive.js +249 -0
- package/dist/viewer/config.js +85 -0
- package/dist/viewer/contracts.js +1 -0
- package/dist/viewer/server.js +177 -0
- package/dist/viewer/source.js +29 -0
- package/dist/viewer/web/app.js +88 -0
- package/dist/viewer/web/index.html +41 -0
- package/dist/viewer/web/navigation.js +72 -0
- package/dist/viewer/web/posts.js +105 -0
- package/dist/viewer/web/render.js +147 -0
- package/dist/viewer/web/session.js +86 -0
- package/dist/viewer/web/style.css +517 -0
- package/dist/viewer/web/updates.js +106 -0
- package/docs/BOARD-CHANGELOG.md +49 -0
- package/docs/BOARD.md +124 -0
- package/docs/NOTES-CHANGELOG.md +127 -0
- package/docs/NOTES.md +122 -0
- package/index.ts +21 -0
- package/package.json +75 -5
- package/src/board/AGENTS.md +12 -0
- package/src/board/activity.ts +274 -0
- package/src/board/archive.ts +118 -0
- package/src/board/awareness.ts +179 -0
- package/src/board/briefing.ts +25 -0
- package/src/board/config.ts +192 -0
- package/src/board/consolidation.ts +32 -0
- package/src/board/context-briefing.ts +245 -0
- package/src/board/contract.ts +254 -0
- package/src/board/delivery.ts +85 -0
- package/src/board/feature.ts +91 -0
- package/src/board/identity.ts +238 -0
- package/src/board/integration.ts +55 -0
- package/src/board/paging.ts +54 -0
- package/src/board/protocol.ts +78 -0
- package/src/board/queries.ts +168 -0
- package/src/board/response.ts +82 -0
- package/src/board/runtime/activation.ts +50 -0
- package/src/board/runtime/catchup.ts +96 -0
- package/src/board/runtime/coordinator.ts +311 -0
- package/src/board/runtime/engine.ts +40 -0
- package/src/board/runtime/index.ts +63 -0
- package/src/board/runtime/owner.ts +168 -0
- package/src/board/runtime/routing.ts +152 -0
- package/src/board/runtime/turns.ts +109 -0
- package/src/board/search.ts +95 -0
- package/src/board/settings/panel.ts +193 -0
- package/src/board/store.ts +427 -0
- package/src/board/summaries.ts +124 -0
- package/src/board/summarizer.ts +201 -0
- package/src/board/tool.ts +27 -0
- package/src/board/viewer/AGENTS.md +1 -0
- package/src/board/viewer/archive.ts +308 -0
- package/src/board/viewer/config.ts +111 -0
- package/src/board/viewer/contracts.ts +98 -0
- package/src/board/viewer/index.ts +162 -0
- package/src/board/viewer/server.ts +204 -0
- package/src/board/viewer/source.ts +33 -0
- package/src/board/viewer/web/app.js +88 -0
- package/src/board/viewer/web/index.html +41 -0
- package/src/board/viewer/web/navigation.js +72 -0
- package/src/board/viewer/web/posts.js +105 -0
- package/src/board/viewer/web/render.js +147 -0
- package/src/board/viewer/web/session.js +86 -0
- package/src/board/viewer/web/style.css +517 -0
- package/src/board/viewer/web/updates.js +106 -0
- package/src/guidance.ts +121 -0
- package/src/notes/AGENTS.md +27 -0
- package/src/notes/activation.ts +150 -0
- package/src/notes/agent-identity.ts +221 -0
- package/src/notes/attachment-sharing.ts +165 -0
- package/src/notes/attachment-snapshot.ts +113 -0
- package/src/notes/binding-startup.ts +30 -0
- package/src/notes/bridge.ts +130 -0
- package/src/notes/compaction-projection.ts +88 -0
- package/src/notes/context-owner.ts +99 -0
- package/src/notes/context-sharing.ts +178 -0
- package/src/notes/extension-hooks.ts +200 -0
- package/src/notes/extension-sharing.ts +133 -0
- package/src/notes/feature.ts +168 -0
- package/src/notes/fresh-checkpoint.ts +143 -0
- package/src/notes/fresh-notes.ts +323 -0
- package/src/notes/history-search-protocol.ts +39 -0
- package/src/notes/history-search-pruning.mjs +120 -0
- package/src/notes/history-search-worker.mjs +258 -0
- package/src/notes/history-search.ts +269 -0
- package/src/notes/history-windows.ts +221 -0
- package/src/notes/history.ts +158 -0
- package/src/notes/idle-admission.ts +201 -0
- package/src/notes/index.ts +125 -0
- package/src/notes/integrations.ts +174 -0
- package/src/notes/lifecycle.ts +308 -0
- package/src/notes/model-role-config.ts +79 -0
- package/src/notes/model-role-screen.ts +74 -0
- package/src/notes/model-roles.ts +225 -0
- package/src/notes/note-query.ts +148 -0
- package/src/notes/note-result.ts +88 -0
- package/src/notes/note-save-marker.ts +128 -0
- package/src/notes/notes-lookup.ts +115 -0
- package/src/notes/notes.ts +302 -0
- package/src/notes/query-executor.ts +242 -0
- package/src/notes/query-input.ts +126 -0
- package/src/notes/remote.ts +376 -0
- package/src/notes/rollover.ts +224 -0
- package/src/notes/saved-session-access.ts +117 -0
- package/src/notes/saved-session-index.mjs +83 -0
- package/src/notes/saved-session.mjs +241 -0
- package/src/notes/saved-session.ts +51 -0
- package/src/notes/saved-sharing-records.ts +135 -0
- package/src/notes/session-pruning-content.ts +237 -0
- package/src/notes/session-pruning-plan.ts +243 -0
- package/src/notes/session-pruning-policy.ts +20 -0
- package/src/notes/session-pruning-screen.ts +204 -0
- package/src/notes/session-pruning-source.ts +44 -0
- package/src/notes/session-pruning-transaction.ts +141 -0
- package/src/notes/session-pruning.ts +155 -0
- package/src/notes/settings-command.ts +95 -0
- package/src/notes/settings-controls.ts +199 -0
- package/src/notes/settings-screen.ts +113 -0
- package/src/notes/settings.ts +287 -0
- package/src/notes/shared-notes.ts +411 -0
- package/src/notes/shared-session-reader.ts +143 -0
- package/src/notes/sharing-service.ts +282 -0
- package/src/notes/sqlite.mjs +33 -0
- package/src/notes/store.ts +283 -0
- package/src/notes/task-boundary.ts +37 -0
- package/src/notes/tool-contracts.ts +312 -0
- package/src/notes/tools.ts +148 -0
- package/src/notes/tree-archive-manifest.mjs +27 -0
- package/src/notes/tree-archive.ts +129 -0
- package/src/notes/tree-checkpoint.ts +170 -0
- package/src/notes/tree-handoff-read.ts +192 -0
- package/src/notes/window-checkpoint.ts +105 -0
- package/src/notes/window-message.ts +185 -0
- package/src/notes/windows.ts +272 -0
- package/src/settings-navigation.ts +11 -0
- package/src/timestamps.ts +3 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { binding, parseBinding, saveBinding } from "../identity.js";
|
|
6
|
+
import type { BoardAdapter } from "../integration.js";
|
|
7
|
+
import { type BoardEnvelope, parseEnvelope } from "../protocol.js";
|
|
8
|
+
import type { BoardOwner } from "./owner.js";
|
|
9
|
+
import type { BoardTurns } from "./turns.js";
|
|
10
|
+
|
|
11
|
+
/** Routes membership/setting/notice envelopes; lifecycle refresh stays with the runtime. */
|
|
12
|
+
export class BoardRouting {
|
|
13
|
+
private readonly pi: ExtensionAPI;
|
|
14
|
+
private readonly turns: Pick<BoardTurns, "deliver">;
|
|
15
|
+
private readonly owner: BoardOwner;
|
|
16
|
+
private readonly refresh: (ctx: ExtensionContext) => Promise<void>;
|
|
17
|
+
private readonly reportAvailability: (
|
|
18
|
+
ctx: ExtensionContext,
|
|
19
|
+
error?: unknown,
|
|
20
|
+
) => void;
|
|
21
|
+
adapter: BoardAdapter | undefined;
|
|
22
|
+
constructor(
|
|
23
|
+
pi: ExtensionAPI,
|
|
24
|
+
turns: Pick<BoardTurns, "deliver">,
|
|
25
|
+
owner: BoardOwner,
|
|
26
|
+
refresh: (ctx: ExtensionContext) => Promise<void>,
|
|
27
|
+
reportAvailability: (ctx: ExtensionContext, error?: unknown) => void,
|
|
28
|
+
) {
|
|
29
|
+
this.pi = pi;
|
|
30
|
+
this.turns = turns;
|
|
31
|
+
this.owner = owner;
|
|
32
|
+
this.refresh = refresh;
|
|
33
|
+
this.reportAvailability = reportAvailability;
|
|
34
|
+
}
|
|
35
|
+
async handle(
|
|
36
|
+
ctx: ExtensionContext,
|
|
37
|
+
value: unknown,
|
|
38
|
+
signal?: AbortSignal,
|
|
39
|
+
): Promise<unknown> {
|
|
40
|
+
const request = parseEnvelope(value);
|
|
41
|
+
const own = binding(ctx);
|
|
42
|
+
if (request.operation === "board-bind") {
|
|
43
|
+
parseBinding(request.binding);
|
|
44
|
+
if (own.sessionId === request.binding.sessionId)
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Child and controller have the same Pi session ID; start the child with a different ID",
|
|
47
|
+
);
|
|
48
|
+
if (request.binding.agentName !== `/${request.binding.sessionId}`)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Restart the controller with updated extensions before spawning shared-board agents",
|
|
51
|
+
);
|
|
52
|
+
if (
|
|
53
|
+
!ctx.isIdle() ||
|
|
54
|
+
ctx.sessionManager
|
|
55
|
+
.getEntries()
|
|
56
|
+
.some(
|
|
57
|
+
(entry) =>
|
|
58
|
+
(entry.type === "message" &&
|
|
59
|
+
["user", "assistant"].includes(entry.message.role)) ||
|
|
60
|
+
(entry.type === "custom" &&
|
|
61
|
+
entry.customType === "shepherdr-board-binding"),
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
throw new Error(
|
|
65
|
+
"Bind board identity only in a fresh idle child before its first task",
|
|
66
|
+
);
|
|
67
|
+
const { legacyAgentName: _legacy, ...proposed } = request.binding;
|
|
68
|
+
const adopted = {
|
|
69
|
+
...proposed,
|
|
70
|
+
sessionId: own.sessionId,
|
|
71
|
+
agentName: own.agentName,
|
|
72
|
+
parentSessionId: request.binding.sessionId,
|
|
73
|
+
};
|
|
74
|
+
saveBinding(this.pi, adopted);
|
|
75
|
+
await this.refresh(ctx);
|
|
76
|
+
return adopted;
|
|
77
|
+
}
|
|
78
|
+
if (request.operation === "board-enabled") {
|
|
79
|
+
if (!own.upstream || request.boardId !== own.boardId)
|
|
80
|
+
throw new Error("Invalid board setting route");
|
|
81
|
+
saveBinding(this.pi, { ...own, enabled: request.enabled });
|
|
82
|
+
await this.refresh(ctx);
|
|
83
|
+
await this.propagateEnabled(ctx, request.enabled);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (request.operation === "board-notify") {
|
|
87
|
+
if (!own.enabled || request.boardId !== own.boardId) return false;
|
|
88
|
+
if (request.target === own.agentName) return this.turns.deliver(request);
|
|
89
|
+
return this.routeNotice(ctx, request, signal);
|
|
90
|
+
}
|
|
91
|
+
return this.toOwner(ctx, request, signal);
|
|
92
|
+
}
|
|
93
|
+
async toOwner(
|
|
94
|
+
ctx: ExtensionContext,
|
|
95
|
+
request: BoardEnvelope,
|
|
96
|
+
signal?: AbortSignal,
|
|
97
|
+
): Promise<unknown> {
|
|
98
|
+
const own = binding(ctx);
|
|
99
|
+
if (own.upstream) {
|
|
100
|
+
try {
|
|
101
|
+
const result = await this.requireAdapter().request(
|
|
102
|
+
own.upstream,
|
|
103
|
+
request,
|
|
104
|
+
signal,
|
|
105
|
+
);
|
|
106
|
+
this.reportAvailability(ctx);
|
|
107
|
+
return result;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (
|
|
110
|
+
error instanceof Error &&
|
|
111
|
+
error.message.startsWith("Shared context response was lost")
|
|
112
|
+
)
|
|
113
|
+
throw new Error(
|
|
114
|
+
"Board response lost; a mutation may have completed. Read the channel/thread before retrying",
|
|
115
|
+
{ cause: error },
|
|
116
|
+
);
|
|
117
|
+
if (
|
|
118
|
+
error instanceof Error &&
|
|
119
|
+
error.message.startsWith("Shared context owner is unavailable")
|
|
120
|
+
)
|
|
121
|
+
throw new Error(
|
|
122
|
+
"Board owner unavailable; resume its Pi session and reconnect its machine",
|
|
123
|
+
{ cause: error },
|
|
124
|
+
);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return this.owner.execute(ctx, request);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private async routeNotice(
|
|
132
|
+
ctx: ExtensionContext,
|
|
133
|
+
request: Extract<BoardEnvelope, { operation: "board-notify" }>,
|
|
134
|
+
signal?: AbortSignal,
|
|
135
|
+
) {
|
|
136
|
+
return this.requireAdapter().routeNotice(ctx, request, signal);
|
|
137
|
+
}
|
|
138
|
+
async propagateEnabled(ctx: ExtensionContext, enabled: boolean) {
|
|
139
|
+
await this.adapter?.propagateEnabled(ctx, enabled);
|
|
140
|
+
}
|
|
141
|
+
attach(adapter: BoardAdapter) {
|
|
142
|
+
if (this.adapter) throw new Error("Board integration already attached");
|
|
143
|
+
this.adapter = adapter;
|
|
144
|
+
}
|
|
145
|
+
requireAdapter() {
|
|
146
|
+
if (!this.adapter)
|
|
147
|
+
throw new Error(
|
|
148
|
+
"Board member route unavailable; load the extension that manages this session's board membership",
|
|
149
|
+
);
|
|
150
|
+
return this.adapter;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionAPI,
|
|
4
|
+
ExtensionContext,
|
|
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";
|
|
9
|
+
|
|
10
|
+
type ActiveEnvelope = Extract<BoardEnvelope, { operation: "board-active" }>;
|
|
11
|
+
type NoticeEnvelope = Extract<BoardEnvelope, { operation: "board-notify" }>;
|
|
12
|
+
|
|
13
|
+
/** Turn IDs are transient capabilities. A stale snapshot cannot reach a later turn. */
|
|
14
|
+
export class BoardTurns {
|
|
15
|
+
private current: { ctx: ExtensionContext; turnId: string } | undefined;
|
|
16
|
+
readonly active = new Map<string, { sessionId: string; turnId: string }>();
|
|
17
|
+
constructor(
|
|
18
|
+
pi: ExtensionAPI,
|
|
19
|
+
register: (
|
|
20
|
+
ctx: ExtensionContext,
|
|
21
|
+
request: ActiveEnvelope,
|
|
22
|
+
) => Promise<unknown>,
|
|
23
|
+
availability: (ctx: ExtensionContext, error?: unknown) => void,
|
|
24
|
+
seen: (ctx: ExtensionContext, ids: string[]) => void,
|
|
25
|
+
) {
|
|
26
|
+
pi.on("session_start", () => {
|
|
27
|
+
this.current = undefined;
|
|
28
|
+
this.active.clear();
|
|
29
|
+
});
|
|
30
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
31
|
+
const own = binding(ctx);
|
|
32
|
+
if (!own.enabled) return;
|
|
33
|
+
const turnId = randomUUID();
|
|
34
|
+
this.current = { ctx, turnId };
|
|
35
|
+
try {
|
|
36
|
+
await register(ctx, { operation: "board-active", caller: own, turnId });
|
|
37
|
+
availability(ctx);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
availability(ctx, error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const stop = async () => {
|
|
43
|
+
const current = this.current;
|
|
44
|
+
this.current = undefined;
|
|
45
|
+
if (!current) return;
|
|
46
|
+
try {
|
|
47
|
+
await register(current.ctx, {
|
|
48
|
+
operation: "board-active",
|
|
49
|
+
caller: binding(current.ctx),
|
|
50
|
+
turnId: null,
|
|
51
|
+
previousTurnId: current.turnId,
|
|
52
|
+
});
|
|
53
|
+
} catch {
|
|
54
|
+
/* No retry or delayed removal may affect a later turn. */
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
pi.on("agent_end", stop);
|
|
58
|
+
pi.on("agent_settled", stop);
|
|
59
|
+
pi.on("session_shutdown", async () => {
|
|
60
|
+
await stop();
|
|
61
|
+
this.active.clear();
|
|
62
|
+
});
|
|
63
|
+
this.deliver = (request) => {
|
|
64
|
+
const current = this.current;
|
|
65
|
+
if (!current || current.turnId !== request.turnId || current.ctx.isIdle())
|
|
66
|
+
return false;
|
|
67
|
+
const own = binding(current.ctx);
|
|
68
|
+
if (
|
|
69
|
+
!own.enabled ||
|
|
70
|
+
own.boardId !== request.boardId ||
|
|
71
|
+
own.sessionId !== request.sessionId ||
|
|
72
|
+
own.agentName !== request.target
|
|
73
|
+
)
|
|
74
|
+
return false;
|
|
75
|
+
const {
|
|
76
|
+
message_id,
|
|
77
|
+
channel_name,
|
|
78
|
+
author,
|
|
79
|
+
thread_id,
|
|
80
|
+
text_preview,
|
|
81
|
+
truncated,
|
|
82
|
+
} = request.notice;
|
|
83
|
+
// No await between running-turn check and steering. Never use the idle kickoff.
|
|
84
|
+
sendPolicyMessage(
|
|
85
|
+
pi,
|
|
86
|
+
{
|
|
87
|
+
customType: "shepherdr-board-post",
|
|
88
|
+
content: `Board post ${JSON.stringify({ message_id, channel_name, author, thread_id, text_preview, truncated })}`,
|
|
89
|
+
display: true,
|
|
90
|
+
},
|
|
91
|
+
{ deliverAs: "steer" },
|
|
92
|
+
);
|
|
93
|
+
seen(current.ctx, [request.notice.message_id]);
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
readonly deliver: (request: NoticeEnvelope) => boolean;
|
|
98
|
+
register(caller: BoardBinding, request: ActiveEnvelope) {
|
|
99
|
+
if (request.turnId)
|
|
100
|
+
this.active.set(caller.agentName, {
|
|
101
|
+
sessionId: caller.sessionId,
|
|
102
|
+
turnId: request.turnId,
|
|
103
|
+
});
|
|
104
|
+
else if (
|
|
105
|
+
this.active.get(caller.agentName)?.turnId === request.previousTurnId
|
|
106
|
+
)
|
|
107
|
+
this.active.delete(caller.agentName);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { caseFold } from "unicode-case-folding";
|
|
2
|
+
import { agentPath, type BoardParams } from "./contract.js";
|
|
3
|
+
import { budget, type PostRecord, page, preview, window } from "./paging.js";
|
|
4
|
+
import type { BoardStore } from "./store.js";
|
|
5
|
+
import { summaryPreview } from "./summaries.js";
|
|
6
|
+
|
|
7
|
+
/** Summaries replace their source posts, never supplement them in default search. */
|
|
8
|
+
export function searchBoard(
|
|
9
|
+
store: BoardStore,
|
|
10
|
+
board: string,
|
|
11
|
+
params: BoardParams,
|
|
12
|
+
) {
|
|
13
|
+
const { limit, offset } = window(params);
|
|
14
|
+
const summarized = store.summaries.available && !params.full;
|
|
15
|
+
const clauses = ["board_id=?"];
|
|
16
|
+
const args: (string | number)[] = [board];
|
|
17
|
+
if (params.channel_name !== undefined) {
|
|
18
|
+
clauses.push("channel_name=?");
|
|
19
|
+
args.push(params.channel_name);
|
|
20
|
+
}
|
|
21
|
+
if (params.author !== undefined) {
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
if (params.query !== undefined) {
|
|
30
|
+
clauses.push("instr(body_search,?)>0");
|
|
31
|
+
args.push(caseFold(params.query));
|
|
32
|
+
}
|
|
33
|
+
if (params.after_message_id !== undefined) {
|
|
34
|
+
const after = store.one<{ seq: number }>(
|
|
35
|
+
"SELECT seq FROM posts WHERE board_id=? AND id=?",
|
|
36
|
+
board,
|
|
37
|
+
params.after_message_id,
|
|
38
|
+
);
|
|
39
|
+
if (!after) throw new Error("Post not found in this board");
|
|
40
|
+
clauses.push("seq>?");
|
|
41
|
+
args.push(after.seq);
|
|
42
|
+
}
|
|
43
|
+
const rows = store.all<
|
|
44
|
+
| (PostRecord & { kind: "post" })
|
|
45
|
+
| (Omit<PostRecord, "author"> & { kind: "summary"; author: null })
|
|
46
|
+
>(
|
|
47
|
+
`WITH candidates AS (
|
|
48
|
+
SELECT p.board_id,p.id AS message_id,p.channel AS channel_name,p.author,p.root AS thread_id,
|
|
49
|
+
p.created_at,p.text,p.body_search,p.seq,'post' AS kind FROM posts p
|
|
50
|
+
${summarized ? "WHERE NOT EXISTS (SELECT 1 FROM thread_summaries s WHERE s.board_id=p.board_id AND s.thread_id=p.root)" : ""}
|
|
51
|
+
${
|
|
52
|
+
summarized
|
|
53
|
+
? `UNION ALL
|
|
54
|
+
SELECT s.board_id,p.id,p.channel,NULL,s.thread_id,p.created_at,s.text,s.body_search,p.seq,'summary'
|
|
55
|
+
FROM thread_summaries s JOIN posts p ON p.board_id=s.board_id AND p.id=s.through_message_id`
|
|
56
|
+
: ""
|
|
57
|
+
}
|
|
58
|
+
) SELECT * FROM candidates c WHERE ${clauses.join(" AND ")}
|
|
59
|
+
ORDER BY seq DESC LIMIT ? OFFSET ?`,
|
|
60
|
+
...args,
|
|
61
|
+
limit + 1,
|
|
62
|
+
offset,
|
|
63
|
+
);
|
|
64
|
+
const chars = budget(params, Math.min(rows.length, limit));
|
|
65
|
+
return page(
|
|
66
|
+
rows.map((row) => {
|
|
67
|
+
const status = store.threadStatus(board, row.thread_id);
|
|
68
|
+
if (row.kind === "summary") {
|
|
69
|
+
const summary = store.summaries.get(board, row.thread_id);
|
|
70
|
+
if (!summary)
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Thread summary is no longer available; repeat the search",
|
|
73
|
+
);
|
|
74
|
+
return {
|
|
75
|
+
kind: "summary",
|
|
76
|
+
thread_id: row.thread_id,
|
|
77
|
+
channel_name: row.channel_name,
|
|
78
|
+
...status,
|
|
79
|
+
summary: summaryPreview(summary, chars),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Do not expose SQL-only columns as post metadata.
|
|
83
|
+
const post: PostRecord = {
|
|
84
|
+
message_id: row.message_id,
|
|
85
|
+
channel_name: row.channel_name,
|
|
86
|
+
author: row.author,
|
|
87
|
+
thread_id: row.thread_id,
|
|
88
|
+
created_at: row.created_at,
|
|
89
|
+
text: row.text,
|
|
90
|
+
};
|
|
91
|
+
return { kind: "post", ...preview(post, chars), ...status };
|
|
92
|
+
}),
|
|
93
|
+
params,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -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
|
+
}
|