@howaboua/pi-agent-board 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +4 -2
- package/dist/viewer/archive.js +24 -17
- package/dist/viewer/web/posts.js +0 -1
- package/index.ts +5 -69
- package/package.json +14 -11
- package/runtime.ts +2 -0
- package/scripts/build-viewer.mjs +9 -0
- package/src/board/AGENTS.md +12 -0
- package/src/{awareness.ts → board/awareness.ts} +4 -10
- package/src/board/briefing.ts +25 -0
- package/src/{contract.ts → board/contract.ts} +31 -27
- package/src/board/feature.ts +91 -0
- package/src/{identity.ts → board/identity.ts} +50 -30
- package/src/board/protocol.ts +117 -0
- package/src/{queries.ts → board/queries.ts} +9 -11
- package/src/{response.ts → board/response.ts} +7 -1
- package/src/board/runtime/activation.ts +50 -0
- package/src/{runtime → board/runtime}/coordinator.ts +76 -43
- package/src/board/runtime/engine.ts +40 -0
- package/src/board/runtime/index.ts +63 -0
- package/src/{runtime → board/runtime}/owner.ts +16 -12
- package/src/{runtime → board/runtime}/routing.ts +2 -2
- package/src/{runtime → board/runtime}/turns.ts +9 -1
- package/src/{search.ts → board/search.ts} +5 -5
- package/src/board/settings/panel.ts +196 -0
- package/src/{store.ts → board/store.ts} +5 -4
- package/src/{summarizer.ts → board/summarizer.ts} +3 -2
- package/src/{tool.ts → board/tool.ts} +5 -0
- package/src/board/viewer/AGENTS.md +1 -0
- package/src/{viewer → board/viewer}/archive.ts +24 -17
- package/src/{viewer → board/viewer}/index.ts +5 -1
- package/src/{viewer → board/viewer}/web/posts.js +0 -1
- package/src/guidance.ts +121 -0
- package/src/settings-navigation.ts +11 -0
- package/src/timestamps.ts +3 -0
- package/tsconfig.json +6 -2
- package/tsconfig.viewer.json +11 -0
- package/src/briefing.ts +0 -32
- package/src/protocol.ts +0 -78
- package/src/runtime/index.ts +0 -113
- package/src/settings/panel.ts +0 -87
- /package/src/{activity.ts → board/activity.ts} +0 -0
- /package/src/{archive.ts → board/archive.ts} +0 -0
- /package/src/{config.ts → board/config.ts} +0 -0
- /package/src/{consolidation.ts → board/consolidation.ts} +0 -0
- /package/src/{context-briefing.ts → board/context-briefing.ts} +0 -0
- /package/src/{delivery.ts → board/delivery.ts} +0 -0
- /package/src/{integration.ts → board/integration.ts} +0 -0
- /package/src/{paging.ts → board/paging.ts} +0 -0
- /package/src/{runtime → board/runtime}/catchup.ts +0 -0
- /package/src/{summaries.ts → board/summaries.ts} +0 -0
- /package/src/{viewer → board/viewer}/config.ts +0 -0
- /package/src/{viewer → board/viewer}/contracts.ts +0 -0
- /package/src/{viewer → board/viewer}/server.ts +0 -0
- /package/src/{viewer → board/viewer}/source.ts +0 -0
- /package/src/{viewer → board/viewer}/web/app.js +0 -0
- /package/src/{viewer → board/viewer}/web/index.html +0 -0
- /package/src/{viewer → board/viewer}/web/navigation.js +0 -0
- /package/src/{viewer → board/viewer}/web/render.js +0 -0
- /package/src/{viewer → board/viewer}/web/session.js +0 -0
- /package/src/{viewer → board/viewer}/web/style.css +0 -0
- /package/src/{viewer → board/viewer}/web/updates.js +0 -0
|
@@ -3,58 +3,75 @@ import type {
|
|
|
3
3
|
ExtensionAPI,
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
bool,
|
|
8
|
+
compile,
|
|
9
|
+
lit,
|
|
10
|
+
nul,
|
|
11
|
+
obj,
|
|
12
|
+
opt,
|
|
13
|
+
type Static,
|
|
14
|
+
str,
|
|
15
|
+
union,
|
|
16
|
+
} from "@earendil-works/pi-schema";
|
|
8
17
|
import { readBoardConfig } from "./config.js";
|
|
9
18
|
|
|
10
|
-
const nativeId =
|
|
11
|
-
export const BindingSchema =
|
|
19
|
+
const nativeId = str({ pattern: "^[a-zA-Z0-9_.-]+$" });
|
|
20
|
+
export const BindingSchema = obj(
|
|
12
21
|
{
|
|
13
|
-
protocol:
|
|
22
|
+
protocol: lit(1),
|
|
14
23
|
boardId: nativeId,
|
|
15
24
|
rootSessionId: nativeId,
|
|
16
25
|
sessionId: nativeId,
|
|
17
|
-
agentName:
|
|
26
|
+
agentName: str({
|
|
18
27
|
pattern: "^/[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_-]+)*$",
|
|
19
28
|
}),
|
|
20
|
-
legacyAgentName:
|
|
21
|
-
|
|
22
|
-
),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
enabled: Type.Boolean(),
|
|
27
|
-
upstream: Type.Optional(Type.String({ minLength: 1 })),
|
|
29
|
+
legacyAgentName: opt(str({ pattern: "^/root(?:/[a-zA-Z0-9_-]+)*$" })),
|
|
30
|
+
parentSessionId: opt(nativeId),
|
|
31
|
+
ownerFolder: str({ minLength: 1 }),
|
|
32
|
+
databasePath: str({ minLength: 1 }),
|
|
33
|
+
enabled: bool(),
|
|
34
|
+
upstream: opt(str({ minLength: 1 })),
|
|
28
35
|
},
|
|
29
|
-
{
|
|
36
|
+
{ open: false },
|
|
30
37
|
);
|
|
31
38
|
export type BoardBinding = Static<typeof BindingSchema>;
|
|
32
|
-
const ChildSchema =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
+
const ChildSchema = obj(
|
|
40
|
+
{
|
|
41
|
+
parentSessionId: nativeId,
|
|
42
|
+
binding: BindingSchema,
|
|
43
|
+
machine: str(),
|
|
44
|
+
sessionFile: str({ minLength: 1 }),
|
|
45
|
+
},
|
|
46
|
+
{ open: true },
|
|
47
|
+
);
|
|
48
|
+
type BoardChild = Static<typeof ChildSchema>;
|
|
39
49
|
const BINDING = "shepherdr-board-binding";
|
|
40
50
|
const MEMBER = "shepherdr-board-member";
|
|
41
51
|
const CHILD = "shepherdr-board-child";
|
|
42
52
|
const SETTING = "shepherdr-board-setting";
|
|
43
53
|
const defaults = new WeakMap<ExtensionContext["sessionManager"], boolean>();
|
|
54
|
+
const bindingSchemaValidator = compile(BindingSchema);
|
|
55
|
+
const childSchemaValidator = compile(ChildSchema);
|
|
56
|
+
|
|
44
57
|
export function setBoardDefault(ctx: ExtensionContext, enabled: boolean) {
|
|
45
58
|
defaults.set(ctx.sessionManager, enabled);
|
|
46
59
|
}
|
|
47
60
|
const REMOVED = "shepherdr-board-removed";
|
|
48
|
-
const SettingSchema =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
const SettingSchema = obj(
|
|
62
|
+
{
|
|
63
|
+
sessionId: nativeId,
|
|
64
|
+
enabled: union([bool(), nul()]),
|
|
65
|
+
},
|
|
66
|
+
{ open: true },
|
|
67
|
+
);
|
|
68
|
+
const settingSchemaValidator = compile(SettingSchema);
|
|
52
69
|
|
|
53
70
|
function sessionBoardSetting(ctx: ExtensionContext): boolean | undefined {
|
|
54
71
|
let enabled: boolean | undefined;
|
|
55
72
|
for (const entry of ctx.sessionManager.getEntries()) {
|
|
56
73
|
if (entry.type !== "custom" || entry.customType !== SETTING) continue;
|
|
57
|
-
if (!
|
|
74
|
+
if (!settingSchemaValidator.check(entry.data))
|
|
58
75
|
throw new Error("Invalid saved board setting");
|
|
59
76
|
const value = entry.data as Static<typeof SettingSchema>;
|
|
60
77
|
if (value.sessionId === ctx.sessionManager.getSessionId())
|
|
@@ -100,7 +117,7 @@ export function rootBoardSetting(ctx: ExtensionContext) {
|
|
|
100
117
|
}
|
|
101
118
|
|
|
102
119
|
export function parseBinding(value: unknown): BoardBinding {
|
|
103
|
-
if (!
|
|
120
|
+
if (!bindingSchemaValidator.check(value))
|
|
104
121
|
throw new Error("Invalid Shepherdr board binding");
|
|
105
122
|
const saved = value as BoardBinding;
|
|
106
123
|
assertSessionIdentity(saved.sessionId, saved.rootSessionId);
|
|
@@ -189,7 +206,7 @@ export function children(ctx: ExtensionContext): BoardChild[] {
|
|
|
189
206
|
continue;
|
|
190
207
|
}
|
|
191
208
|
if (entry.type !== "custom" || entry.customType !== CHILD) continue;
|
|
192
|
-
if (!
|
|
209
|
+
if (!childSchemaValidator.check(entry.data))
|
|
193
210
|
throw new Error("Invalid saved board child route");
|
|
194
211
|
const value = entry.data as BoardChild;
|
|
195
212
|
if (
|
|
@@ -224,7 +241,10 @@ export function boardAliases(
|
|
|
224
241
|
let member: BoardBinding;
|
|
225
242
|
if ([BINDING, MEMBER, REMOVED].includes(entry.customType))
|
|
226
243
|
member = parseBinding(entry.data);
|
|
227
|
-
else if (
|
|
244
|
+
else if (
|
|
245
|
+
entry.customType === CHILD &&
|
|
246
|
+
childSchemaValidator.check(entry.data)
|
|
247
|
+
)
|
|
228
248
|
member = parseBinding((entry.data as BoardChild).binding);
|
|
229
249
|
else continue;
|
|
230
250
|
if (member.boardId === boardId && member.legacyAgentName) {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
arr,
|
|
3
|
+
bool,
|
|
4
|
+
compile,
|
|
5
|
+
int,
|
|
6
|
+
lit,
|
|
7
|
+
nul,
|
|
8
|
+
obj,
|
|
9
|
+
opt,
|
|
10
|
+
type Static,
|
|
11
|
+
str,
|
|
12
|
+
union,
|
|
13
|
+
unknown,
|
|
14
|
+
} from "@earendil-works/pi-schema";
|
|
15
|
+
import { BindingSchema } from "./identity.js";
|
|
16
|
+
|
|
17
|
+
const NoticeSchema = obj(
|
|
18
|
+
{
|
|
19
|
+
message_id: str(),
|
|
20
|
+
channel_name: str(),
|
|
21
|
+
author: str(),
|
|
22
|
+
thread_id: str(),
|
|
23
|
+
created_at: str(),
|
|
24
|
+
text_preview: str({ maxLength: 300 }),
|
|
25
|
+
n_chars: int({ minimum: 0 }),
|
|
26
|
+
truncated: bool(),
|
|
27
|
+
},
|
|
28
|
+
{ open: false },
|
|
29
|
+
);
|
|
30
|
+
const Protocol = union([
|
|
31
|
+
obj(
|
|
32
|
+
{
|
|
33
|
+
operation: lit("board-catchup"),
|
|
34
|
+
caller: BindingSchema,
|
|
35
|
+
seen: arr(str()),
|
|
36
|
+
},
|
|
37
|
+
{ open: true },
|
|
38
|
+
),
|
|
39
|
+
obj(
|
|
40
|
+
{
|
|
41
|
+
operation: lit("board-bind"),
|
|
42
|
+
binding: BindingSchema,
|
|
43
|
+
},
|
|
44
|
+
{ open: true },
|
|
45
|
+
),
|
|
46
|
+
obj(
|
|
47
|
+
{
|
|
48
|
+
operation: lit("board-register"),
|
|
49
|
+
caller: BindingSchema,
|
|
50
|
+
member: BindingSchema,
|
|
51
|
+
},
|
|
52
|
+
{ open: true },
|
|
53
|
+
),
|
|
54
|
+
obj(
|
|
55
|
+
{
|
|
56
|
+
operation: lit("board-unregister"),
|
|
57
|
+
caller: BindingSchema,
|
|
58
|
+
member: BindingSchema,
|
|
59
|
+
},
|
|
60
|
+
{ open: true },
|
|
61
|
+
),
|
|
62
|
+
obj(
|
|
63
|
+
{
|
|
64
|
+
operation: lit("board-enabled"),
|
|
65
|
+
boardId: str(),
|
|
66
|
+
enabled: bool(),
|
|
67
|
+
},
|
|
68
|
+
{ open: true },
|
|
69
|
+
),
|
|
70
|
+
obj(
|
|
71
|
+
{
|
|
72
|
+
operation: lit("board-active"),
|
|
73
|
+
caller: BindingSchema,
|
|
74
|
+
turnId: union([str(), nul()]),
|
|
75
|
+
previousTurnId: opt(str()),
|
|
76
|
+
},
|
|
77
|
+
{ open: true },
|
|
78
|
+
),
|
|
79
|
+
obj(
|
|
80
|
+
{
|
|
81
|
+
operation: lit("board-call"),
|
|
82
|
+
caller: BindingSchema,
|
|
83
|
+
params: unknown(),
|
|
84
|
+
requestId: str(),
|
|
85
|
+
},
|
|
86
|
+
{ open: true },
|
|
87
|
+
),
|
|
88
|
+
obj(
|
|
89
|
+
{
|
|
90
|
+
operation: lit("board-notify"),
|
|
91
|
+
boardId: str(),
|
|
92
|
+
target: str(),
|
|
93
|
+
route: opt(arr(str())),
|
|
94
|
+
sessionId: str(),
|
|
95
|
+
turnId: str(),
|
|
96
|
+
notice: NoticeSchema,
|
|
97
|
+
},
|
|
98
|
+
{ open: true },
|
|
99
|
+
),
|
|
100
|
+
]);
|
|
101
|
+
export type BoardEnvelope = Static<typeof Protocol>;
|
|
102
|
+
const protocolValidator = compile(Protocol);
|
|
103
|
+
|
|
104
|
+
export function parseEnvelope(value: unknown): BoardEnvelope {
|
|
105
|
+
if (!protocolValidator.check(value))
|
|
106
|
+
throw new Error("Invalid board host request");
|
|
107
|
+
return value as BoardEnvelope;
|
|
108
|
+
}
|
|
109
|
+
export function isBoardEnvelope(value: unknown): boolean {
|
|
110
|
+
return (
|
|
111
|
+
!!value &&
|
|
112
|
+
typeof value === "object" &&
|
|
113
|
+
"operation" in value &&
|
|
114
|
+
typeof value.operation === "string" &&
|
|
115
|
+
value.operation.startsWith("board-")
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -32,10 +32,10 @@ export function queryBoard(
|
|
|
32
32
|
message_count: number;
|
|
33
33
|
}>(
|
|
34
34
|
`SELECT b.board_id,b.owner_folder,b.created_at,
|
|
35
|
-
COALESCE((SELECT
|
|
35
|
+
COALESCE((SELECT created_at FROM posts p WHERE p.board_id=b.board_id ORDER BY seq DESC LIMIT 1),(SELECT created_at FROM channels c WHERE c.board_id=b.board_id ORDER BY substr(created_at,1,16) DESC,name DESC LIMIT 1),b.created_at) AS last_activity_at,
|
|
36
36
|
(SELECT COUNT(*) FROM channels c WHERE c.board_id=b.board_id) AS channel_count,
|
|
37
37
|
(SELECT COUNT(*) FROM posts p WHERE p.board_id=b.board_id) AS message_count
|
|
38
|
-
FROM boards b ORDER BY last_activity_at DESC,board_id DESC LIMIT ? OFFSET ?`,
|
|
38
|
+
FROM boards b ORDER BY substr(last_activity_at,1,16) DESC,(SELECT MAX(seq) FROM posts p WHERE p.board_id=b.board_id) DESC,board_id DESC LIMIT ? OFFSET ?`,
|
|
39
39
|
limit + 1,
|
|
40
40
|
offset,
|
|
41
41
|
);
|
|
@@ -47,7 +47,8 @@ export function queryBoard(
|
|
|
47
47
|
if (params.action === "get_channels") {
|
|
48
48
|
const rows = store.all<{ name: string }>(
|
|
49
49
|
`SELECT name FROM channels c WHERE board_id=? AND instr(name_search,?)>0 ORDER BY
|
|
50
|
-
COALESCE((SELECT
|
|
50
|
+
COALESCE((SELECT substr(created_at,1,16) FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name ORDER BY seq DESC LIMIT 1),substr(c.created_at,1,16)) ${order},
|
|
51
|
+
(SELECT MAX(seq) FROM posts p WHERE p.board_id=c.board_id AND p.channel=c.name) ${order},name ${order} LIMIT ? OFFSET ?`,
|
|
51
52
|
board,
|
|
52
53
|
caseFold(params.query ?? ""),
|
|
53
54
|
limit + 1,
|
|
@@ -97,7 +98,7 @@ export function queryBoard(
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
const replies = store.all<PostRecord>(
|
|
100
|
-
`SELECT ${POST_COLUMNS} FROM posts WHERE board_id=? AND root=? AND id<>root ORDER BY
|
|
101
|
+
`SELECT ${POST_COLUMNS} FROM posts WHERE board_id=? AND root=? AND id<>root ORDER BY seq DESC LIMIT ? OFFSET ?`,
|
|
101
102
|
board,
|
|
102
103
|
root.message_id,
|
|
103
104
|
limit + 1,
|
|
@@ -121,8 +122,8 @@ export function queryBoard(
|
|
|
121
122
|
);
|
|
122
123
|
const sort =
|
|
123
124
|
params.sort === "activity"
|
|
124
|
-
? "(SELECT MAX(
|
|
125
|
-
: "p.
|
|
125
|
+
? "(SELECT MAX(seq) FROM posts r WHERE r.board_id=p.board_id AND r.root=p.id)"
|
|
126
|
+
: "p.seq";
|
|
126
127
|
const roots = store.all<PostRecord>(
|
|
127
128
|
`SELECT ${POST_COLUMNS} FROM posts p WHERE board_id=? AND channel=? AND id=root ORDER BY ${sort} ${order},seq ${order} LIMIT ? OFFSET ?`,
|
|
128
129
|
board,
|
|
@@ -135,7 +136,7 @@ export function queryBoard(
|
|
|
135
136
|
roots.map((root) => {
|
|
136
137
|
const summary = store.summaries.get(board, root.thread_id);
|
|
137
138
|
const reply = store.one<PostRecord>(
|
|
138
|
-
`SELECT ${POST_COLUMNS} FROM posts WHERE board_id=? AND root=? AND id<>root ORDER BY
|
|
139
|
+
`SELECT ${POST_COLUMNS} FROM posts WHERE board_id=? AND root=? AND id<>root ORDER BY seq DESC LIMIT 1`,
|
|
139
140
|
board,
|
|
140
141
|
root.message_id,
|
|
141
142
|
);
|
|
@@ -152,10 +153,7 @@ export function queryBoard(
|
|
|
152
153
|
? { summary: summaryPreview(summary, chars) }
|
|
153
154
|
: { root_post: preview(root, chars) }),
|
|
154
155
|
reply_count: count,
|
|
155
|
-
last_activity_at:
|
|
156
|
-
reply && reply.created_at > root.created_at
|
|
157
|
-
? reply.created_at
|
|
158
|
-
: root.created_at,
|
|
156
|
+
last_activity_at: reply?.created_at ?? root.created_at,
|
|
159
157
|
...(summary
|
|
160
158
|
? {}
|
|
161
159
|
: { latest_reply: reply ? preview(reply, chars) : null }),
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { minuteTimestamp } from "../timestamps.js";
|
|
1
2
|
import type { BoardParams } from "./contract.js";
|
|
2
3
|
|
|
3
4
|
// Includes UTF-8 text, JSON escaping and metadata, in every tool mode.
|
|
4
5
|
const MAX_RESPONSE_BYTES = 8000;
|
|
5
6
|
|
|
6
7
|
export function serializeBoardResult(value: unknown): string {
|
|
7
|
-
const text = JSON.stringify(value)
|
|
8
|
+
const text = JSON.stringify(value, (key, entry) =>
|
|
9
|
+
(key === "created_at" || key === "last_activity_at") &&
|
|
10
|
+
typeof entry === "string"
|
|
11
|
+
? minuteTimestamp(entry)
|
|
12
|
+
: entry,
|
|
13
|
+
);
|
|
8
14
|
if (Buffer.byteLength(text) > MAX_RESPONSE_BYTES)
|
|
9
15
|
throw new Error(
|
|
10
16
|
"Result exceeds the output budget. Reduce limit or max_chars_per_post; use read_post with a smaller limit_chars for long posts.",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { initializeDelivery, isMissingOptionalModule } from "../delivery.js";
|
|
3
|
+
import { createBoardTool } from "../tool.js";
|
|
4
|
+
import type { BoardRuntime } from "./coordinator.js";
|
|
5
|
+
|
|
6
|
+
export async function activateBoard(pi: ExtensionAPI, runtime: BoardRuntime) {
|
|
7
|
+
await initializeDelivery();
|
|
8
|
+
const tool = createBoardTool(runtime);
|
|
9
|
+
pi.registerTool(tool);
|
|
10
|
+
try {
|
|
11
|
+
const { registerGptPromptMode, prepareGptPromptMode } = await import(
|
|
12
|
+
"@howaboua/pi-codex-conversion/prompt-mode"
|
|
13
|
+
);
|
|
14
|
+
runtime.setPromptModePreparation((ctx) => prepareGptPromptMode(pi, ctx));
|
|
15
|
+
registerGptPromptMode(pi, (active) => {
|
|
16
|
+
runtime.gptPromptMode = active;
|
|
17
|
+
return [tool];
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (!isMissingOptionalModule(error, "prompt-mode")) throw error;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
|
|
24
|
+
await import("@howaboua/pi-codex-conversion/code-mode");
|
|
25
|
+
const registration = registerCodeModeExtensionTools(
|
|
26
|
+
pi,
|
|
27
|
+
() => [
|
|
28
|
+
adaptToolForCodeMode(tool, {
|
|
29
|
+
prepareInput: (input) =>
|
|
30
|
+
input === undefined || input === null ? {} : input,
|
|
31
|
+
discovery: "help",
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
{ isActive: (ctx) => runtime.enabled(ctx) },
|
|
35
|
+
);
|
|
36
|
+
runtime.setToolRefresh(() => registration.refresh());
|
|
37
|
+
pi.on("session_shutdown", () => registration.unregister());
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (!isMissingOptionalModule(error, "code-mode")) throw error;
|
|
40
|
+
if (
|
|
41
|
+
error instanceof Error &&
|
|
42
|
+
"code" in error &&
|
|
43
|
+
error.code === "ERR_PACKAGE_PATH_NOT_EXPORTED"
|
|
44
|
+
)
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Update Codex Conversion to use its Code and Notebook board tools",
|
|
47
|
+
{ cause: error },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -2,8 +2,10 @@ import type {
|
|
|
2
2
|
ExtensionAPI,
|
|
3
3
|
ExtensionContext,
|
|
4
4
|
} from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
recordBoardActivityMarker,
|
|
7
|
+
registerBoardActivityRenderer,
|
|
8
|
+
} from "../activity.js";
|
|
7
9
|
import {
|
|
8
10
|
type BoardScope,
|
|
9
11
|
writeBoardConfig,
|
|
@@ -20,72 +22,51 @@ import {
|
|
|
20
22
|
} from "../identity.js";
|
|
21
23
|
import type { BoardAdapter } from "../integration.js";
|
|
22
24
|
import { type BoardEnvelope } from "../protocol.js";
|
|
23
|
-
import {
|
|
24
|
-
import { BoardCatchup } from "./catchup.js";
|
|
25
|
+
import type { BoardEngine } from "./engine.js";
|
|
25
26
|
import { BoardOwner } from "./owner.js";
|
|
26
27
|
import { BoardRouting } from "./routing.js";
|
|
27
|
-
import { BoardTurns } from "./turns.js";
|
|
28
28
|
|
|
29
29
|
export class BoardRuntime {
|
|
30
30
|
gptPromptMode = false;
|
|
31
31
|
private preparePromptMode: ((ctx: ExtensionContext) => void) | undefined;
|
|
32
32
|
private readonly pi: ExtensionAPI;
|
|
33
33
|
private readonly routing: BoardRouting;
|
|
34
|
-
private readonly turns: BoardTurns;
|
|
35
34
|
private readonly owner: BoardOwner;
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
35
|
+
private engine: BoardEngine | undefined;
|
|
36
|
+
private engineReady: Promise<BoardEngine> | undefined;
|
|
37
|
+
private briefingReady: Promise<void> | undefined;
|
|
39
38
|
private refreshTools: (() => void) | undefined;
|
|
40
39
|
private lastSetting: { sessionId: string; enabled: boolean } | undefined;
|
|
41
40
|
private configError: string | undefined;
|
|
42
41
|
private availabilityWarning: string | undefined;
|
|
43
42
|
constructor(pi: ExtensionAPI) {
|
|
44
43
|
this.pi = pi;
|
|
44
|
+
registerBoardActivityRenderer(pi);
|
|
45
45
|
const availability = (ctx: ExtensionContext, error?: unknown) =>
|
|
46
46
|
this.reportAvailability(ctx, error);
|
|
47
|
-
this.awareness = new BoardAwareness(
|
|
48
|
-
pi,
|
|
49
|
-
(ctx) => this.population(ctx),
|
|
50
|
-
availability,
|
|
51
|
-
() => this.routing.adapter?.briefing,
|
|
52
|
-
() => this.gptPromptMode,
|
|
53
|
-
);
|
|
54
|
-
this.catchup = new BoardCatchup(
|
|
55
|
-
pi,
|
|
56
|
-
this.awareness,
|
|
57
|
-
(ctx, request) => this.toOwner(ctx, request),
|
|
58
|
-
availability,
|
|
59
|
-
() => this.gptPromptMode,
|
|
60
|
-
);
|
|
61
|
-
this.turns = new BoardTurns(
|
|
62
|
-
pi,
|
|
63
|
-
(ctx, request) => this.toOwner(ctx, request),
|
|
64
|
-
availability,
|
|
65
|
-
(ctx, ids) => this.awareness.markSeen(ctx, ids),
|
|
66
|
-
);
|
|
67
47
|
this.owner = new BoardOwner(
|
|
68
|
-
this.turns,
|
|
69
|
-
this.summarizer,
|
|
48
|
+
() => this.requireEngine().turns,
|
|
49
|
+
() => this.requireEngine().summarizer,
|
|
70
50
|
() => this.routing.adapter,
|
|
71
51
|
() => this.routing.requireAdapter(),
|
|
72
52
|
(ctx, request, signal) => this.handle(ctx, request, signal),
|
|
73
53
|
);
|
|
74
54
|
this.routing = new BoardRouting(
|
|
75
55
|
pi,
|
|
76
|
-
this.turns,
|
|
56
|
+
{ deliver: (request) => this.engine?.turns.deliver(request) ?? false },
|
|
77
57
|
this.owner,
|
|
78
58
|
(ctx) => this.refresh(ctx),
|
|
79
59
|
availability,
|
|
80
60
|
);
|
|
81
61
|
pi.on("session_start", (_event, ctx) => {
|
|
82
|
-
this.summarizer.cancelAll();
|
|
62
|
+
this.engine?.summarizer.cancelAll();
|
|
83
63
|
this.availabilityWarning = undefined;
|
|
84
64
|
setBoardDefault(ctx, true);
|
|
85
65
|
return this.refresh(ctx);
|
|
86
66
|
});
|
|
87
|
-
pi.on("session_shutdown", () => this.summarizer.cancelAll());
|
|
67
|
+
pi.on("session_shutdown", () => this.engine?.summarizer.cancelAll());
|
|
88
68
|
pi.on("before_agent_start", async (_event, ctx) => {
|
|
69
|
+
const prepared = this.preparePromptMode;
|
|
89
70
|
this.preparePromptMode?.(ctx);
|
|
90
71
|
// Reconcile resumed/offline children before tool/prompt preparation.
|
|
91
72
|
const own = binding(ctx);
|
|
@@ -111,6 +92,7 @@ export class BoardRuntime {
|
|
|
111
92
|
}
|
|
112
93
|
}
|
|
113
94
|
await this.refresh(ctx);
|
|
95
|
+
if (this.preparePromptMode !== prepared) this.preparePromptMode?.(ctx);
|
|
114
96
|
const catchup = await this.promptCatchup(ctx);
|
|
115
97
|
catchup.accepted();
|
|
116
98
|
if (catchup.content)
|
|
@@ -123,7 +105,7 @@ export class BoardRuntime {
|
|
|
123
105
|
};
|
|
124
106
|
});
|
|
125
107
|
}
|
|
126
|
-
|
|
108
|
+
reportAvailability(ctx: ExtensionContext, error?: unknown): void {
|
|
127
109
|
const own = binding(ctx);
|
|
128
110
|
if (error === undefined || !own.enabled) {
|
|
129
111
|
this.availabilityWarning = undefined;
|
|
@@ -146,7 +128,7 @@ export class BoardRuntime {
|
|
|
146
128
|
setPromptModePreparation(prepare: (ctx: ExtensionContext) => void) {
|
|
147
129
|
this.preparePromptMode = prepare;
|
|
148
130
|
}
|
|
149
|
-
|
|
131
|
+
async population(ctx: ExtensionContext) {
|
|
150
132
|
const own = binding(ctx);
|
|
151
133
|
if (own.upstream) {
|
|
152
134
|
const status = await this.toOwner(
|
|
@@ -182,11 +164,26 @@ export class BoardRuntime {
|
|
|
182
164
|
return ctx ? binding(ctx).enabled : false;
|
|
183
165
|
}
|
|
184
166
|
async promptCatchup(ctx: ExtensionContext) {
|
|
185
|
-
return this.
|
|
167
|
+
return this.enabled(ctx)
|
|
168
|
+
? (await this.ensureEngine()).catchup.read(ctx)
|
|
169
|
+
: { content: "", accepted() {} };
|
|
186
170
|
}
|
|
187
171
|
async refresh(ctx: ExtensionContext) {
|
|
188
172
|
const own = binding(ctx);
|
|
189
|
-
this.
|
|
173
|
+
if (own.enabled) await this.ensureEngine();
|
|
174
|
+
// Native Pi also needs projection of saved briefings while Board is off.
|
|
175
|
+
if (
|
|
176
|
+
own.enabled ||
|
|
177
|
+
ctx.sessionManager
|
|
178
|
+
.getEntries()
|
|
179
|
+
.some(
|
|
180
|
+
(entry) =>
|
|
181
|
+
entry.type === "custom" &&
|
|
182
|
+
entry.customType === "codex-context-briefing",
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
await this.ensureBriefing();
|
|
186
|
+
this.engine?.awareness.refresh(ctx);
|
|
190
187
|
const setting = own.upstream ? undefined : rootBoardSetting(ctx);
|
|
191
188
|
if (setting?.error && setting.error !== this.configError)
|
|
192
189
|
ctx.ui.notify(`Board disabled: ${setting.error}`, "error");
|
|
@@ -196,8 +193,8 @@ export class BoardRuntime {
|
|
|
196
193
|
this.pi.setActiveTools(active);
|
|
197
194
|
this.refreshTools?.();
|
|
198
195
|
if (!own.enabled) {
|
|
199
|
-
this.turns.active.clear();
|
|
200
|
-
this.summarizer.cancelAll();
|
|
196
|
+
this.engine?.turns.active.clear();
|
|
197
|
+
this.engine?.summarizer.cancelAll();
|
|
201
198
|
}
|
|
202
199
|
const changed =
|
|
203
200
|
this.lastSetting?.sessionId !== own.sessionId ||
|
|
@@ -223,7 +220,7 @@ export class BoardRuntime {
|
|
|
223
220
|
}
|
|
224
221
|
setAutomaticSummaries(ctx: ExtensionContext, automatic: boolean) {
|
|
225
222
|
writeBoardSummaryAutomatic(ctx.cwd, automatic);
|
|
226
|
-
if (!automatic) this.summarizer.cancelAll();
|
|
223
|
+
if (!automatic) this.engine?.summarizer.cancelAll();
|
|
227
224
|
}
|
|
228
225
|
async execute(ctx: ExtensionContext, input: unknown, requestId: string) {
|
|
229
226
|
const params = parseBoardRequest(input);
|
|
@@ -245,7 +242,7 @@ export class BoardRuntime {
|
|
|
245
242
|
ctx.signal,
|
|
246
243
|
);
|
|
247
244
|
if (params.action === "read_thread" || params.action === "read_post")
|
|
248
|
-
this.awareness.markRead(ctx, value);
|
|
245
|
+
this.engine?.awareness.markRead(ctx, value);
|
|
249
246
|
try {
|
|
250
247
|
recordBoardActivityMarker(this.pi, ctx, params, value, requestId);
|
|
251
248
|
} catch {
|
|
@@ -260,6 +257,7 @@ export class BoardRuntime {
|
|
|
260
257
|
: value;
|
|
261
258
|
}
|
|
262
259
|
async handle(ctx: ExtensionContext, value: unknown, signal?: AbortSignal) {
|
|
260
|
+
if (this.enabled(ctx)) await this.ensureEngine();
|
|
263
261
|
return this.routing.handle(ctx, value, signal);
|
|
264
262
|
}
|
|
265
263
|
async toOwner(
|
|
@@ -267,12 +265,47 @@ export class BoardRuntime {
|
|
|
267
265
|
request: BoardEnvelope,
|
|
268
266
|
signal?: AbortSignal,
|
|
269
267
|
) {
|
|
268
|
+
if (this.enabled(ctx)) await this.ensureEngine();
|
|
270
269
|
return this.routing.toOwner(ctx, request, signal);
|
|
271
270
|
}
|
|
271
|
+
private ensureEngine() {
|
|
272
|
+
return (this.engineReady ??= import("./engine.js").then(
|
|
273
|
+
async ({ createBoardEngine }) => {
|
|
274
|
+
const engine = await createBoardEngine(this.pi, this);
|
|
275
|
+
this.engine = engine;
|
|
276
|
+
return engine;
|
|
277
|
+
},
|
|
278
|
+
));
|
|
279
|
+
}
|
|
280
|
+
private ensureBriefing() {
|
|
281
|
+
return (this.briefingReady ??= import("../context-briefing.js").then(
|
|
282
|
+
({ registerContextBriefing }) => {
|
|
283
|
+
registerContextBriefing(
|
|
284
|
+
this.pi,
|
|
285
|
+
"board",
|
|
286
|
+
(ctx) => this.enabled(ctx),
|
|
287
|
+
async (ctx, windowId) => {
|
|
288
|
+
if (!this.enabled(ctx)) return;
|
|
289
|
+
return (await this.ensureEngine()).awareness.record(ctx, windowId);
|
|
290
|
+
},
|
|
291
|
+
);
|
|
292
|
+
},
|
|
293
|
+
));
|
|
294
|
+
}
|
|
295
|
+
private requireEngine() {
|
|
296
|
+
if (!this.engine) throw new Error("Board is not ready");
|
|
297
|
+
return this.engine;
|
|
298
|
+
}
|
|
299
|
+
get adapter() {
|
|
300
|
+
return this.routing.adapter;
|
|
301
|
+
}
|
|
272
302
|
attach(adapter: BoardAdapter) {
|
|
273
303
|
this.routing.attach(adapter);
|
|
274
304
|
}
|
|
275
305
|
get active() {
|
|
276
|
-
return
|
|
306
|
+
return (
|
|
307
|
+
this.engine?.turns.active ??
|
|
308
|
+
new Map<string, { sessionId: string; turnId: string }>()
|
|
309
|
+
);
|
|
277
310
|
}
|
|
278
311
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { BoardAwareness } from "../awareness.js";
|
|
3
|
+
import { BoardSummarizer } from "../summarizer.js";
|
|
4
|
+
import { activateBoard } from "./activation.js";
|
|
5
|
+
import { BoardCatchup } from "./catchup.js";
|
|
6
|
+
import type { BoardRuntime } from "./coordinator.js";
|
|
7
|
+
import { BoardTurns } from "./turns.js";
|
|
8
|
+
|
|
9
|
+
/** Optional inference, turn delivery and summary machinery, loaded only when on. */
|
|
10
|
+
export async function createBoardEngine(
|
|
11
|
+
pi: ExtensionAPI,
|
|
12
|
+
runtime: BoardRuntime,
|
|
13
|
+
) {
|
|
14
|
+
const availability = runtime.reportAvailability.bind(runtime);
|
|
15
|
+
const awareness = new BoardAwareness(
|
|
16
|
+
pi,
|
|
17
|
+
(ctx) => runtime.population(ctx),
|
|
18
|
+
availability,
|
|
19
|
+
() => runtime.adapter?.briefing,
|
|
20
|
+
() => runtime.gptPromptMode,
|
|
21
|
+
);
|
|
22
|
+
const catchup = new BoardCatchup(
|
|
23
|
+
pi,
|
|
24
|
+
awareness,
|
|
25
|
+
(ctx, request) => runtime.toOwner(ctx, request),
|
|
26
|
+
availability,
|
|
27
|
+
() => runtime.gptPromptMode,
|
|
28
|
+
);
|
|
29
|
+
const turns = new BoardTurns(
|
|
30
|
+
pi,
|
|
31
|
+
(ctx, request) => runtime.toOwner(ctx, request),
|
|
32
|
+
availability,
|
|
33
|
+
(ctx, ids) => awareness.markSeen(ctx, ids),
|
|
34
|
+
);
|
|
35
|
+
const summarizer = new BoardSummarizer();
|
|
36
|
+
await activateBoard(pi, runtime);
|
|
37
|
+
return { awareness, catchup, turns, summarizer };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type BoardEngine = Awaited<ReturnType<typeof createBoardEngine>>;
|