@howaboua/pi-agent-board 0.0.3 → 0.0.4
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 +6 -3
- package/INTEGRATION.md +7 -7
- package/README.md +12 -8
- package/dist/viewer/server.js +5 -0
- package/dist/viewer/web/app.js +29 -456
- package/dist/viewer/web/navigation.js +72 -0
- package/dist/viewer/web/posts.js +106 -0
- package/dist/viewer/web/render.js +147 -0
- package/dist/viewer/web/session.js +86 -0
- package/dist/viewer/web/updates.js +106 -0
- package/index.ts +3 -80
- package/package.json +5 -5
- package/src/briefing.ts +6 -8
- package/src/context-briefing.ts +49 -31
- package/src/contract.ts +13 -11
- package/src/queries.ts +1 -2
- package/src/runtime/catchup.ts +96 -0
- package/src/runtime/coordinator.ts +278 -0
- package/src/runtime/index.ts +113 -0
- package/src/runtime/owner.ts +139 -0
- package/src/runtime/routing.ts +137 -0
- package/src/{turns.ts → runtime/turns.ts} +3 -3
- package/src/settings/panel.ts +87 -0
- package/src/tool.ts +1 -1
- package/src/viewer/server.ts +5 -0
- package/src/viewer/web/app.js +29 -456
- package/src/viewer/web/navigation.js +72 -0
- package/src/viewer/web/posts.js +106 -0
- package/src/viewer/web/render.js +147 -0
- package/src/viewer/web/session.js +86 -0
- package/src/viewer/web/updates.js +106 -0
- package/src/runtime.ts +0 -610
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { executeArchive, readSubscribedUpdates } from "../archive.js";
|
|
3
|
+
import {
|
|
4
|
+
agentPath,
|
|
5
|
+
type BoardParams,
|
|
6
|
+
boardHelp,
|
|
7
|
+
parseBoardRequest,
|
|
8
|
+
} from "../contract.js";
|
|
9
|
+
import { binding, members } from "../identity.js";
|
|
10
|
+
import type { BoardAdapter } from "../integration.js";
|
|
11
|
+
import type { BoardEnvelope } from "../protocol.js";
|
|
12
|
+
import type { BoardSummarizer } from "../summarizer.js";
|
|
13
|
+
import type { BoardTurns } from "./turns.js";
|
|
14
|
+
|
|
15
|
+
/** Owner execution begins at membership validation; archive commit precedes delivery. */
|
|
16
|
+
export class BoardOwner {
|
|
17
|
+
private readonly turns: BoardTurns;
|
|
18
|
+
private readonly summarizer: BoardSummarizer;
|
|
19
|
+
private readonly adapterOrUndefined: () => BoardAdapter | undefined;
|
|
20
|
+
private readonly adapter: () => BoardAdapter;
|
|
21
|
+
private readonly notify: (
|
|
22
|
+
ctx: ExtensionContext,
|
|
23
|
+
request: BoardEnvelope,
|
|
24
|
+
signal?: AbortSignal,
|
|
25
|
+
) => Promise<unknown>;
|
|
26
|
+
constructor(
|
|
27
|
+
turns: BoardTurns,
|
|
28
|
+
summarizer: BoardSummarizer,
|
|
29
|
+
adapterOrUndefined: () => BoardAdapter | undefined,
|
|
30
|
+
adapter: () => BoardAdapter,
|
|
31
|
+
notify: (
|
|
32
|
+
ctx: ExtensionContext,
|
|
33
|
+
request: BoardEnvelope,
|
|
34
|
+
signal?: AbortSignal,
|
|
35
|
+
) => Promise<unknown>,
|
|
36
|
+
) {
|
|
37
|
+
this.turns = turns;
|
|
38
|
+
this.summarizer = summarizer;
|
|
39
|
+
this.adapterOrUndefined = adapterOrUndefined;
|
|
40
|
+
this.adapter = adapter;
|
|
41
|
+
this.notify = notify;
|
|
42
|
+
}
|
|
43
|
+
async execute(
|
|
44
|
+
ctx: ExtensionContext,
|
|
45
|
+
request: BoardEnvelope,
|
|
46
|
+
): Promise<unknown> {
|
|
47
|
+
const own = binding(ctx);
|
|
48
|
+
if (!("caller" in request)) throw new Error("Invalid board owner request");
|
|
49
|
+
const directory = members(ctx);
|
|
50
|
+
const caller = directory.find(
|
|
51
|
+
(member) =>
|
|
52
|
+
member.sessionId === request.caller.sessionId &&
|
|
53
|
+
member.agentName === request.caller.agentName,
|
|
54
|
+
);
|
|
55
|
+
if (
|
|
56
|
+
!caller ||
|
|
57
|
+
request.caller.boardId !== own.boardId ||
|
|
58
|
+
request.caller.databasePath !== own.databasePath
|
|
59
|
+
)
|
|
60
|
+
throw new Error("Caller not bound to this board");
|
|
61
|
+
if (
|
|
62
|
+
request.operation === "board-unregister" ||
|
|
63
|
+
request.operation === "board-register"
|
|
64
|
+
)
|
|
65
|
+
return this.adapter().commitDirectory(own, directory, caller, request);
|
|
66
|
+
if (request.operation === "board-active") {
|
|
67
|
+
if (own.enabled) this.turns.register(caller, request);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (request.operation === "board-catchup")
|
|
71
|
+
return own.enabled ? readSubscribedUpdates(caller, request.seen) : [];
|
|
72
|
+
if (request.operation !== "board-call")
|
|
73
|
+
throw new Error("Invalid board owner operation");
|
|
74
|
+
const params = parseBoardRequest(request.params);
|
|
75
|
+
if (params.action === "help")
|
|
76
|
+
return {
|
|
77
|
+
...boardHelp,
|
|
78
|
+
rules: this.adapterOrUndefined()
|
|
79
|
+
? boardHelp.rules
|
|
80
|
+
: {
|
|
81
|
+
...boardHelp.rules,
|
|
82
|
+
agents:
|
|
83
|
+
"Absolute /root/... or child path relative to you; notices require registered members",
|
|
84
|
+
},
|
|
85
|
+
enabled: own.enabled,
|
|
86
|
+
};
|
|
87
|
+
if (!own.enabled)
|
|
88
|
+
throw new Error("Board is off; the user can enable it with /board on");
|
|
89
|
+
const prepared: BoardParams =
|
|
90
|
+
params.author === undefined
|
|
91
|
+
? params
|
|
92
|
+
: { ...params, author: agentPath(params.author, caller.agentName) };
|
|
93
|
+
const active = new Map(this.turns.active);
|
|
94
|
+
const result = await executeArchive(
|
|
95
|
+
{ ...caller, enabled: own.enabled },
|
|
96
|
+
directory.map((member) => member.agentName),
|
|
97
|
+
prepared,
|
|
98
|
+
request.requestId,
|
|
99
|
+
);
|
|
100
|
+
if ("notice" in result && result.notice) {
|
|
101
|
+
// Replayed mutations have no notice: never start or cancel twice for a retry.
|
|
102
|
+
if (params.action === "set_status") {
|
|
103
|
+
if (params.status === "open")
|
|
104
|
+
this.summarizer.cancel(own.boardId, result.notice.thread_id);
|
|
105
|
+
else
|
|
106
|
+
this.summarizer.start(
|
|
107
|
+
ctx,
|
|
108
|
+
own,
|
|
109
|
+
result.notice.thread_id,
|
|
110
|
+
result.notice.message_id,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
for (let start = 0; start < result.recipients.length; start += 16) {
|
|
114
|
+
await Promise.all(
|
|
115
|
+
result.recipients.slice(start, start + 16).map(async (target) => {
|
|
116
|
+
const turn = active.get(target);
|
|
117
|
+
if (!turn) return;
|
|
118
|
+
try {
|
|
119
|
+
await this.notify(
|
|
120
|
+
ctx,
|
|
121
|
+
{
|
|
122
|
+
operation: "board-notify",
|
|
123
|
+
boardId: own.boardId,
|
|
124
|
+
target,
|
|
125
|
+
...turn,
|
|
126
|
+
notice: result.notice,
|
|
127
|
+
},
|
|
128
|
+
AbortSignal.timeout(750),
|
|
129
|
+
);
|
|
130
|
+
} catch {
|
|
131
|
+
/* Committed posts succeed even when a running turn stops accepting. */
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result.value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { binding, 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: BoardTurns;
|
|
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: BoardTurns,
|
|
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
|
+
if (
|
|
44
|
+
!ctx.isIdle() ||
|
|
45
|
+
ctx.sessionManager
|
|
46
|
+
.getEntries()
|
|
47
|
+
.some(
|
|
48
|
+
(entry) =>
|
|
49
|
+
(entry.type === "message" &&
|
|
50
|
+
["user", "assistant"].includes(entry.message.role)) ||
|
|
51
|
+
(entry.type === "custom" &&
|
|
52
|
+
entry.customType === "shepherdr-board-binding"),
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Bind board identity only in a fresh idle child before its first task",
|
|
57
|
+
);
|
|
58
|
+
const adopted = { ...request.binding, sessionId: own.sessionId };
|
|
59
|
+
saveBinding(this.pi, adopted);
|
|
60
|
+
await this.refresh(ctx);
|
|
61
|
+
return adopted;
|
|
62
|
+
}
|
|
63
|
+
if (request.operation === "board-enabled") {
|
|
64
|
+
if (!own.upstream || request.boardId !== own.boardId)
|
|
65
|
+
throw new Error("Invalid board setting route");
|
|
66
|
+
saveBinding(this.pi, { ...own, enabled: request.enabled });
|
|
67
|
+
await this.refresh(ctx);
|
|
68
|
+
await this.propagateEnabled(ctx, request.enabled);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (request.operation === "board-notify") {
|
|
72
|
+
if (!own.enabled || request.boardId !== own.boardId) return false;
|
|
73
|
+
if (request.target === own.agentName) return this.turns.deliver(request);
|
|
74
|
+
return this.routeNotice(ctx, request, signal);
|
|
75
|
+
}
|
|
76
|
+
return this.toOwner(ctx, request, signal);
|
|
77
|
+
}
|
|
78
|
+
async toOwner(
|
|
79
|
+
ctx: ExtensionContext,
|
|
80
|
+
request: BoardEnvelope,
|
|
81
|
+
signal?: AbortSignal,
|
|
82
|
+
): Promise<unknown> {
|
|
83
|
+
const own = binding(ctx);
|
|
84
|
+
if (own.upstream) {
|
|
85
|
+
try {
|
|
86
|
+
const result = await this.requireAdapter().request(
|
|
87
|
+
own.upstream,
|
|
88
|
+
request,
|
|
89
|
+
signal,
|
|
90
|
+
);
|
|
91
|
+
this.reportAvailability(ctx);
|
|
92
|
+
return result;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (
|
|
95
|
+
error instanceof Error &&
|
|
96
|
+
error.message.startsWith("Shared context response was lost")
|
|
97
|
+
)
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Board response lost; a mutation may have completed. Read the channel/thread before retrying",
|
|
100
|
+
{ cause: error },
|
|
101
|
+
);
|
|
102
|
+
if (
|
|
103
|
+
error instanceof Error &&
|
|
104
|
+
error.message.startsWith("Shared context owner is unavailable")
|
|
105
|
+
)
|
|
106
|
+
throw new Error(
|
|
107
|
+
"Board owner unavailable; resume its Pi session and reconnect its machine",
|
|
108
|
+
{ cause: error },
|
|
109
|
+
);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return this.owner.execute(ctx, request);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private async routeNotice(
|
|
117
|
+
ctx: ExtensionContext,
|
|
118
|
+
request: Extract<BoardEnvelope, { operation: "board-notify" }>,
|
|
119
|
+
signal?: AbortSignal,
|
|
120
|
+
) {
|
|
121
|
+
return this.requireAdapter().routeNotice(ctx, request, signal);
|
|
122
|
+
}
|
|
123
|
+
async propagateEnabled(ctx: ExtensionContext, enabled: boolean) {
|
|
124
|
+
await this.adapter?.propagateEnabled(ctx, enabled);
|
|
125
|
+
}
|
|
126
|
+
attach(adapter: BoardAdapter) {
|
|
127
|
+
if (this.adapter) throw new Error("Board integration already attached");
|
|
128
|
+
this.adapter = adapter;
|
|
129
|
+
}
|
|
130
|
+
requireAdapter() {
|
|
131
|
+
if (!this.adapter)
|
|
132
|
+
throw new Error(
|
|
133
|
+
"Board member route unavailable; load the extension that manages this session's board membership",
|
|
134
|
+
);
|
|
135
|
+
return this.adapter;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
ExtensionAPI,
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import { sendPolicyMessage } from "
|
|
7
|
-
import { type BoardBinding, binding } from "
|
|
8
|
-
import type { BoardEnvelope } from "
|
|
6
|
+
import { sendPolicyMessage } from "../delivery.js";
|
|
7
|
+
import { type BoardBinding, binding } from "../identity.js";
|
|
8
|
+
import type { BoardEnvelope } from "../protocol.js";
|
|
9
9
|
|
|
10
10
|
type ActiveEnvelope = Extract<BoardEnvelope, { operation: "board-active" }>;
|
|
11
11
|
type NoticeEnvelope = Extract<BoardEnvelope, { operation: "board-notify" }>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import {
|
|
6
|
+
readBoardSummaryConfig,
|
|
7
|
+
resolveBoardSummaryModel,
|
|
8
|
+
writeBoardSummarySelection,
|
|
9
|
+
} from "../config.js";
|
|
10
|
+
import { requestBoardConsolidation } from "../consolidation.js";
|
|
11
|
+
import { binding } from "../identity.js";
|
|
12
|
+
import type { BoardRuntime } from "../runtime/coordinator.js";
|
|
13
|
+
|
|
14
|
+
export async function openBoardSettings(
|
|
15
|
+
pi: ExtensionAPI,
|
|
16
|
+
ctx: ExtensionContext,
|
|
17
|
+
board: BoardRuntime,
|
|
18
|
+
) {
|
|
19
|
+
if (!ctx.hasUI) {
|
|
20
|
+
ctx.ui.notify("Use /board settings in an interactive session", "warning");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
if (binding(ctx).upstream)
|
|
25
|
+
throw new Error("Change Board settings in the owning root session");
|
|
26
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
27
|
+
const consolidate =
|
|
28
|
+
"Consolidate one-off threads (sends a prompt to this session's agent)";
|
|
29
|
+
const setting = await ctx.ui.select("Board settings and actions", [
|
|
30
|
+
"Automatic summaries",
|
|
31
|
+
"Summary model",
|
|
32
|
+
consolidate,
|
|
33
|
+
]);
|
|
34
|
+
if (setting === consolidate) {
|
|
35
|
+
if (ctx.sessionManager.getSessionId() !== sessionId)
|
|
36
|
+
throw new Error("Session changed; reopen Board settings");
|
|
37
|
+
requestBoardConsolidation(pi, ctx);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!setting) return;
|
|
41
|
+
const config = readBoardSummaryConfig(ctx.cwd);
|
|
42
|
+
if (setting === "Automatic summaries") {
|
|
43
|
+
const selected = await ctx.ui.select(
|
|
44
|
+
`Automatic summaries: ${config.automatic ? "on" : "off"}. Summarise on closure? Uses model quota.`,
|
|
45
|
+
["Off", "On"],
|
|
46
|
+
);
|
|
47
|
+
if (selected !== "Off" && selected !== "On") return;
|
|
48
|
+
board.setAutomaticSummaries(ctx, selected === "On");
|
|
49
|
+
ctx.ui.notify(
|
|
50
|
+
`Automatic board summaries: ${selected.toLowerCase()}.`,
|
|
51
|
+
"info",
|
|
52
|
+
);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (setting !== "Summary model") return;
|
|
56
|
+
const selected = await ctx.ui.select(
|
|
57
|
+
`Board summary model (global; current: ${config.selection === "luna" ? "Luna" : "Custom"})`,
|
|
58
|
+
["Luna", "Custom"],
|
|
59
|
+
);
|
|
60
|
+
if (selected !== "Luna" && selected !== "Custom") return;
|
|
61
|
+
writeBoardSummarySelection(
|
|
62
|
+
ctx.cwd,
|
|
63
|
+
selected === "Luna" ? "luna" : "custom",
|
|
64
|
+
);
|
|
65
|
+
try {
|
|
66
|
+
resolveBoardSummaryModel(ctx.cwd);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
ctx.ui.notify(
|
|
69
|
+
`Custom selected. ${error instanceof Error ? error.message : String(error)}`,
|
|
70
|
+
"warning",
|
|
71
|
+
);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
ctx.ui.notify(
|
|
75
|
+
selected === "Custom"
|
|
76
|
+
? `Board summary model: Custom. Edit board.summary.custom in ${config.path}: set provider, model and reasoning.`
|
|
77
|
+
: "Board summary model: Luna (high).",
|
|
78
|
+
"info",
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
ctx.ui.notify(
|
|
82
|
+
error instanceof Error ? error.message : String(error),
|
|
83
|
+
"error",
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
package/src/tool.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { BoardParameters } from "./contract.js";
|
|
3
3
|
import { serializeBoardToolResult } from "./response.js";
|
|
4
|
-
import type { BoardRuntime } from "./runtime.js";
|
|
4
|
+
import type { BoardRuntime } from "./runtime/coordinator.js";
|
|
5
5
|
|
|
6
6
|
export function createBoardTool(board: BoardRuntime) {
|
|
7
7
|
return defineTool({
|
package/src/viewer/server.ts
CHANGED
|
@@ -15,6 +15,11 @@ export const PROTOCOL = "pi-board-viewer/1";
|
|
|
15
15
|
const assets = new Map<string, readonly [string, string]>([
|
|
16
16
|
["/", ["web/index.html", "text/html; charset=utf-8"]],
|
|
17
17
|
["/app.js", ["web/app.js", "text/javascript; charset=utf-8"]],
|
|
18
|
+
["/session.js", ["web/session.js", "text/javascript; charset=utf-8"]],
|
|
19
|
+
["/posts.js", ["web/posts.js", "text/javascript; charset=utf-8"]],
|
|
20
|
+
["/render.js", ["web/render.js", "text/javascript; charset=utf-8"]],
|
|
21
|
+
["/navigation.js", ["web/navigation.js", "text/javascript; charset=utf-8"]],
|
|
22
|
+
["/updates.js", ["web/updates.js", "text/javascript; charset=utf-8"]],
|
|
18
23
|
["/style.css", ["web/style.css", "text/css; charset=utf-8"]],
|
|
19
24
|
[
|
|
20
25
|
"/vendor/marked.js",
|