@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,254 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import { Check } from "typebox/value";
|
|
3
|
+
|
|
4
|
+
function StringEnum<T extends readonly string[]>(values: T) {
|
|
5
|
+
return Type.Unsafe<T[number]>({ type: "string", enum: values });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const BOARD_ACTIONS = [
|
|
9
|
+
"help",
|
|
10
|
+
"list_boards",
|
|
11
|
+
"create_channel",
|
|
12
|
+
"get_channels",
|
|
13
|
+
"post",
|
|
14
|
+
"set_status",
|
|
15
|
+
"list_threads",
|
|
16
|
+
"read_thread",
|
|
17
|
+
"read_post",
|
|
18
|
+
"search_posts",
|
|
19
|
+
"subscribe",
|
|
20
|
+
"unsubscribe",
|
|
21
|
+
] as const;
|
|
22
|
+
const THREAD_STATUSES = ["open", "completed", "abandoned"] as const;
|
|
23
|
+
export type ThreadStatus = (typeof THREAD_STATUSES)[number];
|
|
24
|
+
export const BoardParameters = Type.Object({
|
|
25
|
+
action: Type.Optional(StringEnum(BOARD_ACTIONS)),
|
|
26
|
+
});
|
|
27
|
+
const positive = Type.Optional(
|
|
28
|
+
Type.Integer({ minimum: 1, maximum: 0xffffffff }),
|
|
29
|
+
);
|
|
30
|
+
const string = Type.Optional(Type.String());
|
|
31
|
+
const Request = Type.Object(
|
|
32
|
+
{
|
|
33
|
+
action: StringEnum(BOARD_ACTIONS),
|
|
34
|
+
channel_name: string,
|
|
35
|
+
new_channel_name: string,
|
|
36
|
+
thread_id: string,
|
|
37
|
+
message_id: string,
|
|
38
|
+
text: string,
|
|
39
|
+
status: Type.Optional(StringEnum(THREAD_STATUSES)),
|
|
40
|
+
comment: string,
|
|
41
|
+
query: string,
|
|
42
|
+
author: string,
|
|
43
|
+
target_agent: string,
|
|
44
|
+
after_message_id: string,
|
|
45
|
+
board_id: string,
|
|
46
|
+
cursor: string,
|
|
47
|
+
full: Type.Optional(Type.Boolean()),
|
|
48
|
+
subscribe: Type.Optional(Type.Boolean()),
|
|
49
|
+
recent_first: Type.Optional(Type.Boolean()),
|
|
50
|
+
sort: Type.Optional(StringEnum(["created", "activity"])),
|
|
51
|
+
limit: positive,
|
|
52
|
+
max_chars_per_post: positive,
|
|
53
|
+
limit_chars: positive,
|
|
54
|
+
offset_chars: Type.Optional(
|
|
55
|
+
Type.Integer({ minimum: 0, maximum: 0xffffffff }),
|
|
56
|
+
),
|
|
57
|
+
agents_to_notify: Type.Optional(
|
|
58
|
+
Type.Array(Type.String(), { maxItems: 256 }),
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
{ additionalProperties: false },
|
|
62
|
+
);
|
|
63
|
+
export type BoardParams = Static<typeof Request>;
|
|
64
|
+
export type BoardAction = BoardParams["action"];
|
|
65
|
+
export const MUTATIONS = new Set<BoardAction>([
|
|
66
|
+
"create_channel",
|
|
67
|
+
"post",
|
|
68
|
+
"set_status",
|
|
69
|
+
"subscribe",
|
|
70
|
+
"unsubscribe",
|
|
71
|
+
]);
|
|
72
|
+
const paging = ["limit", "cursor"];
|
|
73
|
+
const reads = ["board_id"];
|
|
74
|
+
const fields: Record<BoardAction, string[]> = {
|
|
75
|
+
help: [],
|
|
76
|
+
list_boards: paging,
|
|
77
|
+
create_channel: ["channel_name", "subscribe"],
|
|
78
|
+
get_channels: ["query", "recent_first", ...paging, ...reads],
|
|
79
|
+
post: [
|
|
80
|
+
"text",
|
|
81
|
+
"channel_name",
|
|
82
|
+
"new_channel_name",
|
|
83
|
+
"thread_id",
|
|
84
|
+
"agents_to_notify",
|
|
85
|
+
],
|
|
86
|
+
set_status: ["thread_id", "status", "comment"],
|
|
87
|
+
list_threads: [
|
|
88
|
+
"channel_name",
|
|
89
|
+
"sort",
|
|
90
|
+
"recent_first",
|
|
91
|
+
"max_chars_per_post",
|
|
92
|
+
...paging,
|
|
93
|
+
...reads,
|
|
94
|
+
],
|
|
95
|
+
read_thread: ["thread_id", "full", "max_chars_per_post", ...paging, ...reads],
|
|
96
|
+
read_post: ["message_id", "offset_chars", "limit_chars", ...reads],
|
|
97
|
+
search_posts: [
|
|
98
|
+
"channel_name",
|
|
99
|
+
"query",
|
|
100
|
+
"full",
|
|
101
|
+
"author",
|
|
102
|
+
"after_message_id",
|
|
103
|
+
"max_chars_per_post",
|
|
104
|
+
...paging,
|
|
105
|
+
...reads,
|
|
106
|
+
],
|
|
107
|
+
subscribe: ["channel_name", "thread_id", "target_agent"],
|
|
108
|
+
unsubscribe: ["channel_name", "thread_id", "target_agent"],
|
|
109
|
+
};
|
|
110
|
+
const requiredFields: Partial<Record<BoardAction, string[]>> = {
|
|
111
|
+
create_channel: ["channel_name"],
|
|
112
|
+
post: ["text"],
|
|
113
|
+
set_status: ["thread_id", "status", "comment"],
|
|
114
|
+
list_threads: ["channel_name"],
|
|
115
|
+
read_thread: ["thread_id"],
|
|
116
|
+
read_post: ["message_id"],
|
|
117
|
+
};
|
|
118
|
+
export function parseBoardRequest(value: unknown): BoardParams {
|
|
119
|
+
if (
|
|
120
|
+
value === undefined ||
|
|
121
|
+
(typeof value === "object" &&
|
|
122
|
+
value !== null &&
|
|
123
|
+
!Array.isArray(value) &&
|
|
124
|
+
Object.keys(value).length === 0)
|
|
125
|
+
)
|
|
126
|
+
return { action: "help" };
|
|
127
|
+
if (!Check(Request, value))
|
|
128
|
+
throw new Error("Invalid board request; call board help");
|
|
129
|
+
const request = { ...(value as BoardParams) };
|
|
130
|
+
const allowed = new Set(["action", ...fields[request.action]]);
|
|
131
|
+
if (Object.keys(request).some((field) => !allowed.has(field)))
|
|
132
|
+
throw new Error(`Unknown ${request.action} field; board_id is read-only`);
|
|
133
|
+
for (const field of requiredFields[request.action] ?? []) {
|
|
134
|
+
if (!(field in request)) throw new Error(`${field} is required`);
|
|
135
|
+
}
|
|
136
|
+
for (const field of [
|
|
137
|
+
"thread_id",
|
|
138
|
+
"message_id",
|
|
139
|
+
"after_message_id",
|
|
140
|
+
] as const) {
|
|
141
|
+
const id = request[field];
|
|
142
|
+
if (
|
|
143
|
+
id !== undefined &&
|
|
144
|
+
!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(
|
|
145
|
+
id,
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
throw new Error(`${field} must be a UUID`);
|
|
149
|
+
if (id !== undefined) request[field] = id.toLowerCase();
|
|
150
|
+
}
|
|
151
|
+
if (
|
|
152
|
+
request.board_id !== undefined &&
|
|
153
|
+
!/^[a-zA-Z0-9_.-]+$/.test(request.board_id)
|
|
154
|
+
)
|
|
155
|
+
throw new Error("Invalid board_id");
|
|
156
|
+
if (request.action === "post")
|
|
157
|
+
exactlyOne(request, ["channel_name", "new_channel_name", "thread_id"]);
|
|
158
|
+
if (request.action === "subscribe" || request.action === "unsubscribe")
|
|
159
|
+
exactlyOne(request, ["channel_name", "thread_id"]);
|
|
160
|
+
return request;
|
|
161
|
+
}
|
|
162
|
+
function exactlyOne(value: BoardParams, keys: (keyof BoardParams)[]) {
|
|
163
|
+
if (keys.filter((key) => value[key] !== undefined).length !== 1)
|
|
164
|
+
throw new Error(`Provide exactly one of ${keys.join(", ")}`);
|
|
165
|
+
}
|
|
166
|
+
export function required(value: string | undefined, field: string): string {
|
|
167
|
+
if (value === undefined) throw new Error(`${field} is required`);
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
export function agentPath(value: string, caller: string): string {
|
|
171
|
+
const path = value.startsWith("/") ? value : `${caller}/${value}`;
|
|
172
|
+
if (!/^\/[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_-]+)*$/.test(path))
|
|
173
|
+
throw new Error("Invalid agent path");
|
|
174
|
+
return path;
|
|
175
|
+
}
|
|
176
|
+
export const boardHelp = {
|
|
177
|
+
actions: Object.fromEntries(
|
|
178
|
+
Object.entries(fields).map(([action, values]) => [
|
|
179
|
+
action,
|
|
180
|
+
values
|
|
181
|
+
.map(
|
|
182
|
+
(field) =>
|
|
183
|
+
`${field === "status" ? `status=${THREAD_STATUSES.join("|")}` : field}${requiredFields[action as BoardAction]?.includes(field) ? "" : "?"}`,
|
|
184
|
+
)
|
|
185
|
+
.join(" "),
|
|
186
|
+
]),
|
|
187
|
+
),
|
|
188
|
+
rules: {
|
|
189
|
+
scope:
|
|
190
|
+
"Defaults to your tree; board_id browses history, never writes. list_boards discovers saved boards",
|
|
191
|
+
post: "text required; exactly one of channel_name, new_channel_name, thread_id. Thread ID is the first post ID. New channel subscribes author to first posts",
|
|
192
|
+
set_status:
|
|
193
|
+
"Parent session only. Mark completed when the user confirms it's done, or abandoned when they drop it—not merely when agents finish. Closed threads reject replies; reopen first",
|
|
194
|
+
subscriptions:
|
|
195
|
+
"Exactly one of channel_name/thread_id; channel covers first posts, thread covers replies. target_agent defaults to you. Posting subscribes author to thread unless explicitly unsubscribed",
|
|
196
|
+
notify:
|
|
197
|
+
"agents_to_notify is one-time, excludes author; only running turns, no waking or offline notices",
|
|
198
|
+
agents:
|
|
199
|
+
"Agent reference /<Pi session ID>; saved legacy references remain valid",
|
|
200
|
+
paging:
|
|
201
|
+
"limit default20, cap50; cursor opaque, keep query/sort/full unchanged. Concurrent changes may shift pages",
|
|
202
|
+
summaries:
|
|
203
|
+
"Closing may start summarization if enabled. Summarized threads return/search only summaries. full=true reads/searches original posts. Summary author filters match participants; read_post always reads originals",
|
|
204
|
+
order:
|
|
205
|
+
"Newest first; get_channels by activity, list_threads sort=created|activity. read_thread pages newest replies with root on every page",
|
|
206
|
+
text: "Case-insensitive substring search; max_chars_per_post default1000. read_post offsets count Unicode characters, limit_chars default20000. Continue at next_offset_chars<n_chars",
|
|
207
|
+
budget:
|
|
208
|
+
"Post cap64KiB, channel1-128 UTF-8 bytes without edge whitespace/control characters. Results cap8000 serialized UTF-8 bytes; reads may reduce limits, continue with returned cursor/offset",
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Select only owned guidance. Routing metadata and adapter-provided prose stay intact.
|
|
213
|
+
export function gptBoardHelp(value: unknown): unknown {
|
|
214
|
+
if (
|
|
215
|
+
!value ||
|
|
216
|
+
typeof value !== "object" ||
|
|
217
|
+
!("rules" in value) ||
|
|
218
|
+
!value.rules ||
|
|
219
|
+
typeof value.rules !== "object"
|
|
220
|
+
)
|
|
221
|
+
return value;
|
|
222
|
+
const compact: typeof boardHelp.rules = {
|
|
223
|
+
scope:
|
|
224
|
+
"Default=your tree; board_id→saved history READONLY; discover→list_boards",
|
|
225
|
+
post: "text required; EXACTLY one: channel_name|new_channel_name|thread_id. thread_id=first post ID; new channel→author subscribed to first posts",
|
|
226
|
+
set_status:
|
|
227
|
+
"Parent session ONLY; completed=user confirms done; abandoned=user drops it; NOT agents finish. Closed→reopen BEFORE reply",
|
|
228
|
+
subscriptions:
|
|
229
|
+
"EXACTLY one: channel_name|thread_id; channel=first posts, thread=replies; target_agent=you by default; posting→subscribe author UNLESS explicitly unsubscribed",
|
|
230
|
+
notify:
|
|
231
|
+
"agents_to_notify=once, excludes author; running turns ONLY; NO waking/offline notices",
|
|
232
|
+
agents: "Agent=/<Pi session ID>; legacy references accepted",
|
|
233
|
+
paging:
|
|
234
|
+
"limit default20 cap50; opaque cursor→unchanged query/sort/full; concurrent changes MAY shift pages",
|
|
235
|
+
summaries:
|
|
236
|
+
"Closing MAY summarise IF enabled; summarised threads return/search summaries ONLY; full=true reads/searches originals; summary author filters=participants; read_post=originals ALWAYS",
|
|
237
|
+
order:
|
|
238
|
+
"Newest first; get_channels→activity; list_threads sort=created|activity; read_thread→newest replies+root EVERY page",
|
|
239
|
+
text: "Case-insensitive substring; max_chars_per_post default1000; read_post→Unicode-char offsets, limit_chars default20000; next_offset_chars<n_chars→continue",
|
|
240
|
+
budget:
|
|
241
|
+
"Post≤64KiB; channel=1-128 UTF-8 bytes, NO edge whitespace/control chars; results≤8000 serialized UTF-8 bytes; reads MAY lower limits; continue returned cursor/offset",
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
...value,
|
|
245
|
+
rules: Object.fromEntries(
|
|
246
|
+
Object.entries(value.rules).map(([key, text]) => [
|
|
247
|
+
key,
|
|
248
|
+
text === boardHelp.rules[key as keyof typeof compact]
|
|
249
|
+
? compact[key as keyof typeof compact]
|
|
250
|
+
: text,
|
|
251
|
+
]),
|
|
252
|
+
),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type {
|
|
3
|
+
CodexContextBriefingHandler,
|
|
4
|
+
CodexDeveloperCustomMessage,
|
|
5
|
+
CodexDeveloperMessageOptions,
|
|
6
|
+
} from "@howaboua/pi-codex-conversion/developer-messages";
|
|
7
|
+
|
|
8
|
+
type Delivery =
|
|
9
|
+
typeof import("@howaboua/pi-codex-conversion/developer-messages");
|
|
10
|
+
let optionalDelivery: Promise<Delivery | undefined> | undefined;
|
|
11
|
+
|
|
12
|
+
function loadDelivery() {
|
|
13
|
+
return (optionalDelivery ??= import(
|
|
14
|
+
"@howaboua/pi-codex-conversion/developer-messages"
|
|
15
|
+
).catch((error) => {
|
|
16
|
+
if (isMissingOptionalModule(error, "developer-messages")) return undefined;
|
|
17
|
+
throw error;
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isMissingOptionalModule(error: unknown, subpath: string) {
|
|
22
|
+
if (!(error instanceof Error) || !("code" in error)) return false;
|
|
23
|
+
const name = "@howaboua/pi-codex-conversion";
|
|
24
|
+
if (error.code === "ERR_PACKAGE_PATH_NOT_EXPORTED")
|
|
25
|
+
return (
|
|
26
|
+
error.message.includes(name) && error.message.includes(`./${subpath}`)
|
|
27
|
+
);
|
|
28
|
+
if (
|
|
29
|
+
error.code !== "ERR_MODULE_NOT_FOUND" &&
|
|
30
|
+
error.code !== "MODULE_NOT_FOUND"
|
|
31
|
+
)
|
|
32
|
+
return false;
|
|
33
|
+
const missing = error.message.match(
|
|
34
|
+
/Cannot find (?:package|module) ['"]([^'"]+)['"]/,
|
|
35
|
+
)?.[1];
|
|
36
|
+
return missing === name || missing === `${name}/${subpath}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let delivery: Delivery | undefined;
|
|
40
|
+
export async function initializeDelivery() {
|
|
41
|
+
delivery = await loadDelivery();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function preparePolicyMessage(message: CodexDeveloperCustomMessage) {
|
|
45
|
+
return (
|
|
46
|
+
delivery?.withCodexDeveloperMessageDetails?.({
|
|
47
|
+
...message,
|
|
48
|
+
details: message.details ?? {},
|
|
49
|
+
}) ?? message
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function registerInferenceBriefing(
|
|
54
|
+
pi: ExtensionAPI,
|
|
55
|
+
handler: CodexContextBriefingHandler,
|
|
56
|
+
) {
|
|
57
|
+
let unregister: (() => void) | undefined;
|
|
58
|
+
const ready = loadDelivery().then((api) => {
|
|
59
|
+
delivery = api;
|
|
60
|
+
unregister = api?.registerCodexContextBriefing?.(pi, handler);
|
|
61
|
+
});
|
|
62
|
+
pi.on("session_shutdown", () => unregister?.());
|
|
63
|
+
return {
|
|
64
|
+
ready,
|
|
65
|
+
hosted: () => delivery?.hasCodexContextBriefingHost?.(pi) ?? false,
|
|
66
|
+
get outdated() {
|
|
67
|
+
return Boolean(delivery && !delivery.registerCodexContextBriefing);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function sendPolicyMessage(
|
|
73
|
+
pi: ExtensionAPI,
|
|
74
|
+
message: CodexDeveloperCustomMessage,
|
|
75
|
+
options: CodexDeveloperMessageOptions,
|
|
76
|
+
) {
|
|
77
|
+
if (delivery?.trySendCodexDeveloperCustomMessage?.(pi, message, options))
|
|
78
|
+
return;
|
|
79
|
+
pi.sendMessage(
|
|
80
|
+
message,
|
|
81
|
+
options.deliverAs === "nextTurn"
|
|
82
|
+
? { ...options, deliverAs: "steer" }
|
|
83
|
+
: options,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { CommsFeature } from "../guidance.js";
|
|
6
|
+
import type { OpenSettings } from "../settings-navigation.js";
|
|
7
|
+
import { binding } from "./identity.js";
|
|
8
|
+
import { acquireBoard } from "./runtime/index.js";
|
|
9
|
+
|
|
10
|
+
export async function createBoardFeature(
|
|
11
|
+
pi: ExtensionAPI,
|
|
12
|
+
openSettings?: OpenSettings,
|
|
13
|
+
): Promise<CommsFeature> {
|
|
14
|
+
const board = await acquireBoard(pi);
|
|
15
|
+
const open = async (ctx: ExtensionContext) => {
|
|
16
|
+
const { openBoardSettings } = await import("./settings/panel.js");
|
|
17
|
+
return openBoardSettings(pi, ctx, board, Boolean(openSettings));
|
|
18
|
+
};
|
|
19
|
+
pi.registerCommand("board", {
|
|
20
|
+
description: `${openSettings ? "Board settings" : "Board viewer; settings"}; status, on|off [session|folder|global]`,
|
|
21
|
+
getArgumentCompletions(prefix) {
|
|
22
|
+
const commands = ["settings", "status", "on", "off"];
|
|
23
|
+
const scopes = ["session", "folder", "global"];
|
|
24
|
+
const options = prefix.includes(" ")
|
|
25
|
+
? ["on", "off"].flatMap((command) =>
|
|
26
|
+
scopes.map((scope) => `${command} ${scope}`),
|
|
27
|
+
)
|
|
28
|
+
: commands;
|
|
29
|
+
return options
|
|
30
|
+
.filter((value) => value.startsWith(prefix))
|
|
31
|
+
.map((value) => ({ label: value, value }));
|
|
32
|
+
},
|
|
33
|
+
async handler(args, ctx) {
|
|
34
|
+
if (args.trim() === "settings" || (!args.trim() && openSettings)) {
|
|
35
|
+
if (openSettings) return openSettings(ctx, "board");
|
|
36
|
+
await open(ctx);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const [command = "", scope = "session", ...extra] = args
|
|
40
|
+
.trim()
|
|
41
|
+
.split(/\s+/);
|
|
42
|
+
if (
|
|
43
|
+
(command === "on" || command === "off") &&
|
|
44
|
+
(scope === "session" || scope === "folder" || scope === "global") &&
|
|
45
|
+
!extra.length
|
|
46
|
+
) {
|
|
47
|
+
try {
|
|
48
|
+
await board.setSetting(ctx, scope, command === "on");
|
|
49
|
+
ctx.ui.notify(board.status(ctx), "info");
|
|
50
|
+
} catch (error) {
|
|
51
|
+
ctx.ui.notify(
|
|
52
|
+
error instanceof Error ? error.message : String(error),
|
|
53
|
+
"error",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (args.trim() === "status") {
|
|
59
|
+
ctx.ui.notify(board.status(ctx), "info");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (command) {
|
|
63
|
+
ctx.ui.notify(
|
|
64
|
+
"Use /board, /board settings, /board status or /board on|off [session|folder|global]",
|
|
65
|
+
"warning",
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const { openBoardViewer } = await import("./viewer/index.js");
|
|
70
|
+
await openBoardViewer(pi, ctx, (context, sessionName) => {
|
|
71
|
+
const own = binding(context);
|
|
72
|
+
if (own.upstream)
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Open /board in the owning root session to view this shared board",
|
|
75
|
+
);
|
|
76
|
+
return {
|
|
77
|
+
sessionId: own.sessionId,
|
|
78
|
+
sessionName: sessionName ?? null,
|
|
79
|
+
boardId: own.boardId,
|
|
80
|
+
folder: own.ownerFolder,
|
|
81
|
+
databasePath: own.databasePath,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
enabled: (ctx) => board.enabled(ctx),
|
|
88
|
+
gptPromptMode: () => board.gptPromptMode,
|
|
89
|
+
openSettings: open,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionAPI,
|
|
4
|
+
ExtensionContext,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { type Static, Type } from "typebox";
|
|
7
|
+
import { Check } from "typebox/value";
|
|
8
|
+
import { readBoardConfig } from "./config.js";
|
|
9
|
+
|
|
10
|
+
const nativeId = Type.String({ pattern: "^[a-zA-Z0-9_.-]+$" });
|
|
11
|
+
export const BindingSchema = Type.Object(
|
|
12
|
+
{
|
|
13
|
+
protocol: Type.Literal(1),
|
|
14
|
+
boardId: nativeId,
|
|
15
|
+
rootSessionId: nativeId,
|
|
16
|
+
sessionId: nativeId,
|
|
17
|
+
agentName: Type.String({
|
|
18
|
+
pattern: "^/[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_-]+)*$",
|
|
19
|
+
}),
|
|
20
|
+
legacyAgentName: Type.Optional(
|
|
21
|
+
Type.String({ pattern: "^/root(?:/[a-zA-Z0-9_-]+)*$" }),
|
|
22
|
+
),
|
|
23
|
+
parentSessionId: Type.Optional(nativeId),
|
|
24
|
+
ownerFolder: Type.String({ minLength: 1 }),
|
|
25
|
+
databasePath: Type.String({ minLength: 1 }),
|
|
26
|
+
enabled: Type.Boolean(),
|
|
27
|
+
upstream: Type.Optional(Type.String({ minLength: 1 })),
|
|
28
|
+
},
|
|
29
|
+
{ additionalProperties: false },
|
|
30
|
+
);
|
|
31
|
+
export type BoardBinding = Static<typeof BindingSchema>;
|
|
32
|
+
const ChildSchema = Type.Object({
|
|
33
|
+
parentSessionId: nativeId,
|
|
34
|
+
binding: BindingSchema,
|
|
35
|
+
machine: Type.String(),
|
|
36
|
+
sessionFile: Type.String({ minLength: 1 }),
|
|
37
|
+
});
|
|
38
|
+
type BoardChild = Static<typeof ChildSchema>;
|
|
39
|
+
const BINDING = "shepherdr-board-binding";
|
|
40
|
+
const MEMBER = "shepherdr-board-member";
|
|
41
|
+
const CHILD = "shepherdr-board-child";
|
|
42
|
+
const SETTING = "shepherdr-board-setting";
|
|
43
|
+
const defaults = new WeakMap<ExtensionContext["sessionManager"], boolean>();
|
|
44
|
+
export function setBoardDefault(ctx: ExtensionContext, enabled: boolean) {
|
|
45
|
+
defaults.set(ctx.sessionManager, enabled);
|
|
46
|
+
}
|
|
47
|
+
const REMOVED = "shepherdr-board-removed";
|
|
48
|
+
const SettingSchema = Type.Object({
|
|
49
|
+
sessionId: nativeId,
|
|
50
|
+
enabled: Type.Union([Type.Boolean(), Type.Null()]),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function sessionBoardSetting(ctx: ExtensionContext): boolean | undefined {
|
|
54
|
+
let enabled: boolean | undefined;
|
|
55
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
56
|
+
if (entry.type !== "custom" || entry.customType !== SETTING) continue;
|
|
57
|
+
if (!Check(SettingSchema, entry.data))
|
|
58
|
+
throw new Error("Invalid saved board setting");
|
|
59
|
+
const value = entry.data as Static<typeof SettingSchema>;
|
|
60
|
+
if (value.sessionId === ctx.sessionManager.getSessionId())
|
|
61
|
+
enabled = value.enabled ?? undefined;
|
|
62
|
+
}
|
|
63
|
+
return enabled;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function saveBoardSetting(
|
|
67
|
+
pi: ExtensionAPI,
|
|
68
|
+
ctx: ExtensionContext,
|
|
69
|
+
enabled: boolean,
|
|
70
|
+
) {
|
|
71
|
+
pi.appendEntry(SETTING, {
|
|
72
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
73
|
+
enabled,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function rootBoardSetting(ctx: ExtensionContext) {
|
|
78
|
+
try {
|
|
79
|
+
const config = readBoardConfig(
|
|
80
|
+
resolve(ctx.sessionManager.getCwd()),
|
|
81
|
+
defaults.get(ctx.sessionManager),
|
|
82
|
+
);
|
|
83
|
+
const session = sessionBoardSetting(ctx);
|
|
84
|
+
return {
|
|
85
|
+
enabled: session ?? config.folder ?? config.global,
|
|
86
|
+
source:
|
|
87
|
+
session !== undefined
|
|
88
|
+
? "session"
|
|
89
|
+
: config.folder !== undefined
|
|
90
|
+
? "folder"
|
|
91
|
+
: "global default",
|
|
92
|
+
};
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {
|
|
95
|
+
enabled: false,
|
|
96
|
+
source: "invalid configuration",
|
|
97
|
+
error: String(error),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function parseBinding(value: unknown): BoardBinding {
|
|
103
|
+
if (!Check(BindingSchema, value))
|
|
104
|
+
throw new Error("Invalid Shepherdr board binding");
|
|
105
|
+
const saved = value as BoardBinding;
|
|
106
|
+
assertSessionIdentity(saved.sessionId, saved.rootSessionId);
|
|
107
|
+
const agentName = `/${saved.sessionId}`;
|
|
108
|
+
if (saved.agentName !== agentName && !/^\/root(?:\/|$)/.test(saved.agentName))
|
|
109
|
+
throw new Error("Board agent reference does not match its native session");
|
|
110
|
+
return {
|
|
111
|
+
...saved,
|
|
112
|
+
agentName,
|
|
113
|
+
...(saved.agentName !== agentName && !saved.legacyAgentName
|
|
114
|
+
? { legacyAgentName: saved.agentName }
|
|
115
|
+
: {}),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function binding(ctx: ExtensionContext): BoardBinding {
|
|
119
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
120
|
+
assertSessionIdentity(sessionId);
|
|
121
|
+
let saved: BoardBinding | undefined;
|
|
122
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
123
|
+
if (entry.type !== "custom" || entry.customType !== BINDING) continue;
|
|
124
|
+
const candidate = parseBinding(entry.data);
|
|
125
|
+
if (candidate.sessionId === sessionId) saved = candidate;
|
|
126
|
+
}
|
|
127
|
+
const ownerFolder = resolve(ctx.sessionManager.getCwd());
|
|
128
|
+
if (saved?.upstream) return saved;
|
|
129
|
+
return {
|
|
130
|
+
...(saved ?? {
|
|
131
|
+
protocol: 1,
|
|
132
|
+
sessionId,
|
|
133
|
+
rootSessionId: sessionId,
|
|
134
|
+
boardId: sessionId,
|
|
135
|
+
agentName: `/${sessionId}`,
|
|
136
|
+
ownerFolder,
|
|
137
|
+
databasePath: resolve(ownerFolder, ".pi", "agent-message-board.sqlite"),
|
|
138
|
+
enabled: false,
|
|
139
|
+
}),
|
|
140
|
+
enabled: rootBoardSetting(ctx).enabled,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function assertSessionIdentity(...ids: string[]) {
|
|
144
|
+
if (ids.includes("root"))
|
|
145
|
+
throw new Error(
|
|
146
|
+
"Pi session ID root conflicts with the legacy /root reference; start a session with another ID",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
export function saveBinding(pi: ExtensionAPI, value: BoardBinding) {
|
|
150
|
+
pi.appendEntry(BINDING, value);
|
|
151
|
+
}
|
|
152
|
+
export function members(ctx: ExtensionContext): BoardBinding[] {
|
|
153
|
+
const own = binding(ctx);
|
|
154
|
+
const found = new Map([[own.sessionId, own]]);
|
|
155
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
156
|
+
if (entry.type === "custom" && entry.customType === REMOVED) {
|
|
157
|
+
const value = parseBinding(entry.data);
|
|
158
|
+
if (value.boardId === own.boardId) found.delete(value.sessionId);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (entry.type !== "custom" || entry.customType !== MEMBER) continue;
|
|
162
|
+
const value = parseBinding(entry.data);
|
|
163
|
+
if (value.rootSessionId === own.sessionId && value.boardId === own.boardId)
|
|
164
|
+
found.set(value.sessionId, value);
|
|
165
|
+
}
|
|
166
|
+
const directory = [...found.values()];
|
|
167
|
+
return directory.map((member) => {
|
|
168
|
+
if (member.parentSessionId || !member.legacyAgentName) return member;
|
|
169
|
+
const path = member.legacyAgentName;
|
|
170
|
+
const parent = directory.find(
|
|
171
|
+
(entry) =>
|
|
172
|
+
(entry.legacyAgentName ??
|
|
173
|
+
(entry.sessionId === own.rootSessionId ? "/root" : undefined)) ===
|
|
174
|
+
path.slice(0, path.lastIndexOf("/")),
|
|
175
|
+
);
|
|
176
|
+
return parent ? { ...member, parentSessionId: parent.sessionId } : member;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export function saveMember(pi: ExtensionAPI, value: BoardBinding) {
|
|
180
|
+
pi.appendEntry(MEMBER, value);
|
|
181
|
+
}
|
|
182
|
+
export function children(ctx: ExtensionContext): BoardChild[] {
|
|
183
|
+
const own = binding(ctx);
|
|
184
|
+
const found = new Map<string, BoardChild>();
|
|
185
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
186
|
+
if (entry.type === "custom" && entry.customType === REMOVED) {
|
|
187
|
+
const value = parseBinding(entry.data);
|
|
188
|
+
if (value.boardId === own.boardId) found.delete(value.sessionId);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (entry.type !== "custom" || entry.customType !== CHILD) continue;
|
|
192
|
+
if (!Check(ChildSchema, entry.data))
|
|
193
|
+
throw new Error("Invalid saved board child route");
|
|
194
|
+
const value = entry.data as BoardChild;
|
|
195
|
+
if (
|
|
196
|
+
value.parentSessionId === own.sessionId &&
|
|
197
|
+
value.binding.boardId === own.boardId
|
|
198
|
+
)
|
|
199
|
+
found.set(value.binding.sessionId, {
|
|
200
|
+
...value,
|
|
201
|
+
binding: parseBinding(value.binding),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return [...found.values()];
|
|
205
|
+
}
|
|
206
|
+
export function saveChild(pi: ExtensionAPI, value: BoardChild) {
|
|
207
|
+
pi.appendEntry(CHILD, value);
|
|
208
|
+
}
|
|
209
|
+
export function removeMember(pi: ExtensionAPI, value: BoardBinding) {
|
|
210
|
+
pi.appendEntry(REMOVED, value);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Legacy names are aliases from native-session records, never access grants. */
|
|
214
|
+
export function boardAliases(
|
|
215
|
+
ctx: ExtensionContext,
|
|
216
|
+
boardId = binding(ctx).boardId,
|
|
217
|
+
): [string, string][] {
|
|
218
|
+
const own = binding(ctx);
|
|
219
|
+
const aliases = new Map<string, string>();
|
|
220
|
+
if (own.boardId === boardId && own.sessionId === own.rootSessionId)
|
|
221
|
+
aliases.set("/root", own.agentName);
|
|
222
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
223
|
+
if (entry.type !== "custom") continue;
|
|
224
|
+
let member: BoardBinding;
|
|
225
|
+
if ([BINDING, MEMBER, REMOVED].includes(entry.customType))
|
|
226
|
+
member = parseBinding(entry.data);
|
|
227
|
+
else if (entry.customType === CHILD && Check(ChildSchema, entry.data))
|
|
228
|
+
member = parseBinding((entry.data as BoardChild).binding);
|
|
229
|
+
else continue;
|
|
230
|
+
if (member.boardId === boardId && member.legacyAgentName) {
|
|
231
|
+
const previous = aliases.get(member.legacyAgentName);
|
|
232
|
+
if (previous && previous !== member.agentName)
|
|
233
|
+
throw new Error("Ambiguous saved board agent reference");
|
|
234
|
+
aliases.set(member.legacyAgentName, member.agentName);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return [...aliases];
|
|
238
|
+
}
|