@howaboua/pi-agent-board 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -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 +6 -8
- package/src/archive.ts +17 -7
- package/src/awareness.ts +2 -1
- package/src/briefing.ts +6 -8
- package/src/context-briefing.ts +49 -31
- package/src/contract.ts +25 -17
- package/src/identity.ts +81 -17
- package/src/integration.ts +1 -0
- package/src/protocol.ts +2 -2
- 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 +164 -0
- package/src/runtime/routing.ts +152 -0
- package/src/{turns.ts → runtime/turns.ts} +3 -3
- package/src/search.ts +6 -4
- package/src/settings/panel.ts +87 -0
- package/src/store.ts +40 -5
- 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/changelog.ts +0 -337
- package/src/runtime.ts +0 -610
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { marked } from "/vendor/marked.js";
|
|
2
|
+
import DOMPurify from "/vendor/purify.js";
|
|
3
|
+
|
|
4
|
+
export function node(tag, className, text) {
|
|
5
|
+
const element = document.createElement(tag);
|
|
6
|
+
if (className) element.className = className;
|
|
7
|
+
if (text !== undefined) element.textContent = text;
|
|
8
|
+
return element;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function shortName(name) {
|
|
12
|
+
return (name.split("/").filter(Boolean).at(-1) || name).replace(
|
|
13
|
+
/-[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i,
|
|
14
|
+
"",
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
export function author(name) {
|
|
18
|
+
const element = node("span", "author", shortName(name));
|
|
19
|
+
element.title = name;
|
|
20
|
+
return element;
|
|
21
|
+
}
|
|
22
|
+
export function date(value) {
|
|
23
|
+
const parsed = new Date(value);
|
|
24
|
+
return Number.isNaN(parsed.getTime())
|
|
25
|
+
? value
|
|
26
|
+
: parsed.toLocaleString(undefined, {
|
|
27
|
+
month: "short",
|
|
28
|
+
day: "numeric",
|
|
29
|
+
hour: "2-digit",
|
|
30
|
+
minute: "2-digit",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function empty(target, text) {
|
|
34
|
+
target.replaceChildren(node("p", "empty", text));
|
|
35
|
+
}
|
|
36
|
+
export function statusLabel(status) {
|
|
37
|
+
return node(
|
|
38
|
+
"span",
|
|
39
|
+
`thread-status status-${status}`,
|
|
40
|
+
{
|
|
41
|
+
open: "Open",
|
|
42
|
+
completed: "Completed",
|
|
43
|
+
abandoned: "Abandoned",
|
|
44
|
+
}[status],
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function renderPost(post, root, summary = false) {
|
|
49
|
+
const article = node("article", "post");
|
|
50
|
+
if (root) article.append(node("div", "post-channel", post.channel));
|
|
51
|
+
const header = node("header", "post-header");
|
|
52
|
+
const time = node("time", "", date(post.createdAt));
|
|
53
|
+
time.dateTime = post.createdAt;
|
|
54
|
+
time.title = post.createdAt;
|
|
55
|
+
header.append(
|
|
56
|
+
summary ? node("strong", "", "Summary") : author(post.author),
|
|
57
|
+
time,
|
|
58
|
+
);
|
|
59
|
+
const body = node("div", "prose");
|
|
60
|
+
body.innerHTML = DOMPurify.sanitize(
|
|
61
|
+
marked.parse(post.text, { async: false }),
|
|
62
|
+
{
|
|
63
|
+
ALLOWED_TAGS: [
|
|
64
|
+
"p",
|
|
65
|
+
"br",
|
|
66
|
+
"hr",
|
|
67
|
+
"strong",
|
|
68
|
+
"em",
|
|
69
|
+
"del",
|
|
70
|
+
"blockquote",
|
|
71
|
+
"pre",
|
|
72
|
+
"code",
|
|
73
|
+
"ul",
|
|
74
|
+
"ol",
|
|
75
|
+
"li",
|
|
76
|
+
"h1",
|
|
77
|
+
"h2",
|
|
78
|
+
"h3",
|
|
79
|
+
"h4",
|
|
80
|
+
"h5",
|
|
81
|
+
"h6",
|
|
82
|
+
"a",
|
|
83
|
+
"table",
|
|
84
|
+
"thead",
|
|
85
|
+
"tbody",
|
|
86
|
+
"tr",
|
|
87
|
+
"th",
|
|
88
|
+
"td",
|
|
89
|
+
],
|
|
90
|
+
ALLOWED_ATTR: ["href", "title", "start", "colspan", "rowspan"],
|
|
91
|
+
ALLOW_DATA_ATTR: false,
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
for (const link of body.querySelectorAll("a")) {
|
|
95
|
+
const href = link.getAttribute("href");
|
|
96
|
+
// Relative links could carry the capability fragment to another local page.
|
|
97
|
+
if (!href || !/^(https?:|mailto:)/i.test(href))
|
|
98
|
+
link.removeAttribute("href");
|
|
99
|
+
else {
|
|
100
|
+
link.rel = "noopener noreferrer";
|
|
101
|
+
link.target = "_blank";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
article.append(header, body);
|
|
105
|
+
return article;
|
|
106
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { $, state, run, selectionURL } from "./session.js";
|
|
2
|
+
import {
|
|
3
|
+
node,
|
|
4
|
+
shortName,
|
|
5
|
+
author,
|
|
6
|
+
date,
|
|
7
|
+
empty,
|
|
8
|
+
statusLabel,
|
|
9
|
+
renderPost,
|
|
10
|
+
} from "./posts.js";
|
|
11
|
+
|
|
12
|
+
export function createBoardRenderer(loadList, openThread) {
|
|
13
|
+
function renderBoard() {
|
|
14
|
+
const detail = state.detail;
|
|
15
|
+
const channels = [
|
|
16
|
+
{ name: "", label: "All activity" },
|
|
17
|
+
...detail.channels.map((channel) => ({
|
|
18
|
+
name: channel.name,
|
|
19
|
+
label: channel.name,
|
|
20
|
+
posts: channel.posts,
|
|
21
|
+
})),
|
|
22
|
+
];
|
|
23
|
+
$("channels").replaceChildren(
|
|
24
|
+
...channels.map((channel) => {
|
|
25
|
+
const button = node("button", "", channel.label);
|
|
26
|
+
button.type = "button";
|
|
27
|
+
button.dataset.channel = channel.name;
|
|
28
|
+
button.setAttribute(
|
|
29
|
+
"aria-current",
|
|
30
|
+
String(state.channel === channel.name),
|
|
31
|
+
);
|
|
32
|
+
if (channel.posts !== undefined)
|
|
33
|
+
button.append(node("small", "", String(channel.posts)));
|
|
34
|
+
button.onclick = () =>
|
|
35
|
+
run(async () => {
|
|
36
|
+
state.channel = channel.name;
|
|
37
|
+
await loadList();
|
|
38
|
+
renderBoard();
|
|
39
|
+
});
|
|
40
|
+
return button;
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
// Polling never replaces focused controls when their options have not changed.
|
|
44
|
+
const options = [
|
|
45
|
+
{ name: "", label: "All agents" },
|
|
46
|
+
...detail.agents.map((agent) => ({
|
|
47
|
+
name: agent.name,
|
|
48
|
+
label: shortName(agent.name),
|
|
49
|
+
})),
|
|
50
|
+
];
|
|
51
|
+
const signature = JSON.stringify(options);
|
|
52
|
+
if ($("author").dataset.options !== signature) {
|
|
53
|
+
$("author").replaceChildren(
|
|
54
|
+
...options.map((option) => {
|
|
55
|
+
const element = node("option", "", option.label);
|
|
56
|
+
element.value = option.name;
|
|
57
|
+
element.title = option.name;
|
|
58
|
+
return element;
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
$("author").dataset.options = signature;
|
|
62
|
+
}
|
|
63
|
+
$("author").value = state.author;
|
|
64
|
+
const watching = detail.subscriptions.filter(
|
|
65
|
+
(subscription) => subscription.enabled,
|
|
66
|
+
);
|
|
67
|
+
$("subscriptions").replaceChildren(
|
|
68
|
+
...watching.map((subscription) => {
|
|
69
|
+
const line = node("p");
|
|
70
|
+
line.append(
|
|
71
|
+
author(subscription.agent),
|
|
72
|
+
document.createTextNode(` watches ${subscription.target}`),
|
|
73
|
+
);
|
|
74
|
+
return line;
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
$("watching").hidden = !watching.length;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function renderThreads() {
|
|
81
|
+
$("list-title").textContent = state.channel || "All activity";
|
|
82
|
+
$("threads").replaceChildren(
|
|
83
|
+
...state.page.threads.map((thread) => {
|
|
84
|
+
const link = node("a", "thread");
|
|
85
|
+
link.href = selectionURL(thread.id);
|
|
86
|
+
link.dataset.thread = thread.id;
|
|
87
|
+
link.setAttribute("aria-current", String(thread.id === state.thread));
|
|
88
|
+
const meta = node("div", "thread-meta");
|
|
89
|
+
meta.append(
|
|
90
|
+
author(thread.author),
|
|
91
|
+
node("span", "", date(thread.lastActivity)),
|
|
92
|
+
);
|
|
93
|
+
const foot = node("div", "thread-foot");
|
|
94
|
+
foot.append(
|
|
95
|
+
statusLabel(thread.status),
|
|
96
|
+
node("span", "", thread.channel),
|
|
97
|
+
node(
|
|
98
|
+
"span",
|
|
99
|
+
"",
|
|
100
|
+
`${thread.replies} ${thread.replies === 1 ? "reply" : "replies"}`,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
if (thread.summarized) foot.append(node("span", "", "Summary"));
|
|
104
|
+
link.append(meta, node("p", "thread-preview", thread.preview), foot);
|
|
105
|
+
link.onclick = (event) => {
|
|
106
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
107
|
+
return;
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
run(() => openThread(thread.id));
|
|
110
|
+
};
|
|
111
|
+
return link;
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
if (!state.page.threads.length)
|
|
115
|
+
empty(
|
|
116
|
+
$("threads"),
|
|
117
|
+
state.query || state.author ? "No matches" : "No posts",
|
|
118
|
+
);
|
|
119
|
+
$("more-threads").hidden = !state.page.nextCursor;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderConversation() {
|
|
123
|
+
const conversation = state.conversation;
|
|
124
|
+
const summary = conversation.summary;
|
|
125
|
+
$("thread-status").replaceChildren(statusLabel(conversation.status));
|
|
126
|
+
$("discussion-mode").hidden = !summary;
|
|
127
|
+
$("full-discussion").checked = state.full;
|
|
128
|
+
const snapshot = $("summary-snapshot");
|
|
129
|
+
snapshot.hidden = !summary;
|
|
130
|
+
snapshot.textContent = summary
|
|
131
|
+
? `Summary saved ${date(summary.createdAt)} · ${summary.provider}/${summary.model} · ${summary.reasoning} · Through ${summary.throughMessageId}`
|
|
132
|
+
: "";
|
|
133
|
+
if (summary?.hasNewerPosts)
|
|
134
|
+
snapshot.prepend(node("strong", "", "New replies after this summary. "));
|
|
135
|
+
$("posts").replaceChildren(
|
|
136
|
+
...(conversation.root
|
|
137
|
+
? [renderPost(conversation.root, true)]
|
|
138
|
+
: summary
|
|
139
|
+
? [renderPost(summary, false, true)]
|
|
140
|
+
: []),
|
|
141
|
+
...conversation.replies.map((post) => renderPost(post, false)),
|
|
142
|
+
);
|
|
143
|
+
$("more-replies").hidden = !conversation.nextCursor;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return { renderBoard, renderThreads, renderConversation };
|
|
147
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const $ = (id) => document.getElementById(id);
|
|
2
|
+
export const fragment = new URLSearchParams(location.hash.slice(1));
|
|
3
|
+
export const token = fragment.get("view");
|
|
4
|
+
export const state = {
|
|
5
|
+
board: "",
|
|
6
|
+
channel: "",
|
|
7
|
+
author: "",
|
|
8
|
+
query: "",
|
|
9
|
+
searchFull: false,
|
|
10
|
+
full: false,
|
|
11
|
+
thread: "",
|
|
12
|
+
detail: null,
|
|
13
|
+
page: null,
|
|
14
|
+
conversation: null,
|
|
15
|
+
firstPage: null,
|
|
16
|
+
firstConversation: null,
|
|
17
|
+
threadPages: 1,
|
|
18
|
+
replyPages: 1,
|
|
19
|
+
};
|
|
20
|
+
let queue = Promise.resolve();
|
|
21
|
+
export let busy = 0;
|
|
22
|
+
export let changed = false;
|
|
23
|
+
|
|
24
|
+
export function run(action) {
|
|
25
|
+
busy++;
|
|
26
|
+
queue = queue.then(async () => {
|
|
27
|
+
try {
|
|
28
|
+
await action();
|
|
29
|
+
$("status").textContent = "";
|
|
30
|
+
} catch (error) {
|
|
31
|
+
$("status").textContent = error.message;
|
|
32
|
+
} finally {
|
|
33
|
+
busy--;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return queue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function api(path, params = {}) {
|
|
40
|
+
const url = new URL(path, location.origin);
|
|
41
|
+
for (const [key, value] of Object.entries(params))
|
|
42
|
+
if (value) url.searchParams.set(key, value);
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
45
|
+
cache: "no-store",
|
|
46
|
+
signal: AbortSignal.timeout(10_000),
|
|
47
|
+
});
|
|
48
|
+
const data = await response.json();
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
if (response.status === 401) $("live").checked = false;
|
|
51
|
+
throw new Error(
|
|
52
|
+
typeof data.error === "string"
|
|
53
|
+
? data.error
|
|
54
|
+
: `Request failed (${response.status}).`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function selectionURL(thread = state.thread) {
|
|
61
|
+
const params = new URLSearchParams();
|
|
62
|
+
params.set("view", token);
|
|
63
|
+
if (state.board) params.set("board", state.board);
|
|
64
|
+
if (thread) params.set("thread", thread);
|
|
65
|
+
return `#${params}`;
|
|
66
|
+
}
|
|
67
|
+
export function saveSelection() {
|
|
68
|
+
history.replaceState(null, "", selectionURL());
|
|
69
|
+
}
|
|
70
|
+
export function threadParams() {
|
|
71
|
+
return {
|
|
72
|
+
boardId: state.board,
|
|
73
|
+
channel: state.channel,
|
|
74
|
+
author: state.author,
|
|
75
|
+
q: state.query,
|
|
76
|
+
full: state.searchFull ? "true" : "",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function same(a, b) {
|
|
80
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function setChanged(value) {
|
|
84
|
+
changed = value;
|
|
85
|
+
$("refresh").textContent = value ? "New activity · Refresh" : "Refresh";
|
|
86
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { $, state, api, threadParams, setChanged, same } from "./session.js";
|
|
2
|
+
import { renderPost } from "./posts.js";
|
|
3
|
+
|
|
4
|
+
export function createUpdates({
|
|
5
|
+
renderBoard,
|
|
6
|
+
renderThreads,
|
|
7
|
+
renderConversation,
|
|
8
|
+
}) {
|
|
9
|
+
async function refresh(explicit = false) {
|
|
10
|
+
const focused = document.activeElement;
|
|
11
|
+
const focusKey =
|
|
12
|
+
focused?.dataset?.channel !== undefined
|
|
13
|
+
? ["channel", focused.dataset.channel]
|
|
14
|
+
: focused?.dataset?.thread
|
|
15
|
+
? ["thread", focused.dataset.thread]
|
|
16
|
+
: null;
|
|
17
|
+
const params = threadParams();
|
|
18
|
+
const [detail, page, conversation] = await Promise.all([
|
|
19
|
+
api("/api/board", { boardId: state.board }),
|
|
20
|
+
api("/api/threads", params),
|
|
21
|
+
state.thread
|
|
22
|
+
? api("/api/thread", {
|
|
23
|
+
boardId: state.board,
|
|
24
|
+
id: state.thread,
|
|
25
|
+
full: state.full ? "true" : "",
|
|
26
|
+
})
|
|
27
|
+
: Promise.resolve(null),
|
|
28
|
+
]);
|
|
29
|
+
if (!explicit && (state.threadPages > 1 || state.replyPages > 1)) {
|
|
30
|
+
// Compare only loaded first pages. Never splice fresh cursors into an old tail.
|
|
31
|
+
if (
|
|
32
|
+
!same(detail, state.detail) ||
|
|
33
|
+
!same(page, state.firstPage) ||
|
|
34
|
+
!same(conversation, state.firstConversation)
|
|
35
|
+
)
|
|
36
|
+
setChanged(true);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!same(detail, state.detail)) {
|
|
40
|
+
state.detail = detail;
|
|
41
|
+
renderBoard();
|
|
42
|
+
}
|
|
43
|
+
if (!same(page, state.page)) {
|
|
44
|
+
state.page = page;
|
|
45
|
+
renderThreads();
|
|
46
|
+
}
|
|
47
|
+
if (conversation && !same(conversation, state.conversation)) {
|
|
48
|
+
state.conversation = conversation;
|
|
49
|
+
renderConversation();
|
|
50
|
+
}
|
|
51
|
+
state.threadPages = 1;
|
|
52
|
+
state.replyPages = 1;
|
|
53
|
+
state.firstPage = page;
|
|
54
|
+
state.firstConversation = conversation;
|
|
55
|
+
setChanged(false);
|
|
56
|
+
if (focusKey && !focused.isConnected) {
|
|
57
|
+
const target = [
|
|
58
|
+
...document.querySelectorAll(`[data-${focusKey[0]}]`),
|
|
59
|
+
].find((element) => element.dataset[focusKey[0]] === focusKey[1]);
|
|
60
|
+
target?.focus({ preventScroll: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function moreThreads() {
|
|
65
|
+
if (!state.page.nextCursor) return;
|
|
66
|
+
const page = await api("/api/threads", {
|
|
67
|
+
...threadParams(),
|
|
68
|
+
cursor: state.page.nextCursor,
|
|
69
|
+
});
|
|
70
|
+
if (state.threadPages === 1) state.firstPage = state.page;
|
|
71
|
+
state.page = {
|
|
72
|
+
threads: [
|
|
73
|
+
...state.page.threads,
|
|
74
|
+
...page.threads.filter(
|
|
75
|
+
(thread) => !state.page.threads.some((old) => old.id === thread.id),
|
|
76
|
+
),
|
|
77
|
+
],
|
|
78
|
+
nextCursor: page.nextCursor,
|
|
79
|
+
};
|
|
80
|
+
state.threadPages++;
|
|
81
|
+
renderThreads();
|
|
82
|
+
}
|
|
83
|
+
async function moreReplies() {
|
|
84
|
+
if (!state.conversation.nextCursor) return;
|
|
85
|
+
const page = await api("/api/thread", {
|
|
86
|
+
boardId: state.board,
|
|
87
|
+
id: state.thread,
|
|
88
|
+
full: state.full ? "true" : "",
|
|
89
|
+
cursor: state.conversation.nextCursor,
|
|
90
|
+
});
|
|
91
|
+
if (state.replyPages === 1) state.firstConversation = state.conversation;
|
|
92
|
+
const replies = page.replies.filter(
|
|
93
|
+
(post) => !state.conversation.replies.some((old) => old.id === post.id),
|
|
94
|
+
);
|
|
95
|
+
state.conversation = {
|
|
96
|
+
...state.conversation,
|
|
97
|
+
replies: [...state.conversation.replies, ...replies],
|
|
98
|
+
nextCursor: page.nextCursor,
|
|
99
|
+
};
|
|
100
|
+
state.replyPages++;
|
|
101
|
+
$("posts").append(...replies.map((post) => renderPost(post, false)));
|
|
102
|
+
$("more-replies").hidden = !page.nextCursor;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { refresh, moreThreads, moreReplies };
|
|
106
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
readBoardSummaryConfig,
|
|
4
|
-
resolveBoardSummaryModel,
|
|
5
|
-
writeBoardSummarySelection,
|
|
6
|
-
} from "./src/config.js";
|
|
7
|
-
import { requestBoardConsolidation } from "./src/consolidation.js";
|
|
8
2
|
import { binding } from "./src/identity.js";
|
|
9
|
-
import { acquireBoard } from "./src/runtime.js";
|
|
3
|
+
import { acquireBoard } from "./src/runtime/index.js";
|
|
4
|
+
import { openBoardSettings } from "./src/settings/panel.js";
|
|
10
5
|
import { openBoardViewer } from "./src/viewer/index.js";
|
|
11
6
|
|
|
12
7
|
export default async function agentBoardExtension(pi: ExtensionAPI) {
|
|
@@ -27,79 +22,7 @@ export default async function agentBoardExtension(pi: ExtensionAPI) {
|
|
|
27
22
|
.map((value) => ({ label: value, value }));
|
|
28
23
|
},
|
|
29
24
|
async handler(args, ctx) {
|
|
30
|
-
if (args.trim() === "settings")
|
|
31
|
-
if (!ctx.hasUI) {
|
|
32
|
-
ctx.ui.notify(
|
|
33
|
-
"Use /board settings in an interactive session",
|
|
34
|
-
"warning",
|
|
35
|
-
);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
if (binding(ctx).upstream)
|
|
40
|
-
throw new Error("Change Board settings in the owning root session");
|
|
41
|
-
const sessionId = ctx.sessionManager.getSessionId();
|
|
42
|
-
const consolidate =
|
|
43
|
-
"Consolidate one-off threads (sends a prompt to this session's agent)";
|
|
44
|
-
const setting = await ctx.ui.select("Board settings and actions", [
|
|
45
|
-
"Automatic summaries",
|
|
46
|
-
"Summary model",
|
|
47
|
-
consolidate,
|
|
48
|
-
]);
|
|
49
|
-
if (setting === consolidate) {
|
|
50
|
-
if (ctx.sessionManager.getSessionId() !== sessionId)
|
|
51
|
-
throw new Error("Session changed; reopen Board settings");
|
|
52
|
-
requestBoardConsolidation(pi, ctx);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (!setting) return;
|
|
56
|
-
const config = readBoardSummaryConfig(ctx.cwd);
|
|
57
|
-
if (setting === "Automatic summaries") {
|
|
58
|
-
const selected = await ctx.ui.select(
|
|
59
|
-
`Automatic summaries: ${config.automatic ? "on" : "off"}. Summarise on closure? Uses model quota.`,
|
|
60
|
-
["Off", "On"],
|
|
61
|
-
);
|
|
62
|
-
if (selected !== "Off" && selected !== "On") return;
|
|
63
|
-
board.setAutomaticSummaries(ctx, selected === "On");
|
|
64
|
-
ctx.ui.notify(
|
|
65
|
-
`Automatic board summaries: ${selected.toLowerCase()}.`,
|
|
66
|
-
"info",
|
|
67
|
-
);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (setting !== "Summary model") return;
|
|
71
|
-
const selected = await ctx.ui.select(
|
|
72
|
-
`Board summary model (global; current: ${config.selection === "luna" ? "Luna" : "Custom"})`,
|
|
73
|
-
["Luna", "Custom"],
|
|
74
|
-
);
|
|
75
|
-
if (selected !== "Luna" && selected !== "Custom") return;
|
|
76
|
-
writeBoardSummarySelection(
|
|
77
|
-
ctx.cwd,
|
|
78
|
-
selected === "Luna" ? "luna" : "custom",
|
|
79
|
-
);
|
|
80
|
-
try {
|
|
81
|
-
resolveBoardSummaryModel(ctx.cwd);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
ctx.ui.notify(
|
|
84
|
-
`Custom selected. ${error instanceof Error ? error.message : String(error)}`,
|
|
85
|
-
"warning",
|
|
86
|
-
);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
ctx.ui.notify(
|
|
90
|
-
selected === "Custom"
|
|
91
|
-
? `Board summary model: Custom. Edit board.summary.custom in ${config.path}: set provider, model and reasoning.`
|
|
92
|
-
: "Board summary model: Luna (high).",
|
|
93
|
-
"info",
|
|
94
|
-
);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
ctx.ui.notify(
|
|
97
|
-
error instanceof Error ? error.message : String(error),
|
|
98
|
-
"error",
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
25
|
+
if (args.trim() === "settings") return openBoardSettings(pi, ctx, board);
|
|
103
26
|
const [command = "", scope = "session", ...extra] = args
|
|
104
27
|
.trim()
|
|
105
28
|
.split(/\s+/);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-agent-board",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Standalone agent message boards and a read-only browser viewer for Pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,18 +17,16 @@
|
|
|
17
17
|
"INTEGRATION.md",
|
|
18
18
|
"LICENSE",
|
|
19
19
|
"tsconfig.json",
|
|
20
|
-
"changelog.ts",
|
|
21
20
|
"CHANGELOG.md"
|
|
22
21
|
],
|
|
23
22
|
"main": "index.ts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": "./index.ts",
|
|
26
|
-
"./runtime": "./src/runtime.ts",
|
|
25
|
+
"./runtime": "./src/runtime/index.ts",
|
|
27
26
|
"./integration": "./src/integration.ts"
|
|
28
27
|
},
|
|
29
28
|
"pi": {
|
|
30
29
|
"extensions": [
|
|
31
|
-
"./changelog.ts",
|
|
32
30
|
"./index.ts"
|
|
33
31
|
]
|
|
34
32
|
},
|
|
@@ -45,14 +43,14 @@
|
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
45
|
"dompurify": "3.4.17",
|
|
48
|
-
"marked": "18.1.
|
|
46
|
+
"marked": "18.1.2",
|
|
49
47
|
"unicode-case-folding": "1.1.2"
|
|
50
48
|
},
|
|
51
49
|
"peerDependencies": {
|
|
52
50
|
"@earendil-works/pi-ai": ">=1.1.0",
|
|
53
|
-
"@earendil-works/pi-coding-agent": ">=1.
|
|
51
|
+
"@earendil-works/pi-coding-agent": ">=1.5.0",
|
|
54
52
|
"@earendil-works/pi-tui": ">=1.1.0",
|
|
55
|
-
"@howaboua/pi-codex-conversion": ">=4.0.
|
|
53
|
+
"@howaboua/pi-codex-conversion": ">=4.0.8",
|
|
56
54
|
"typebox": "*"
|
|
57
55
|
},
|
|
58
56
|
"peerDependenciesMeta": {
|
|
@@ -64,6 +62,6 @@
|
|
|
64
62
|
"access": "public"
|
|
65
63
|
},
|
|
66
64
|
"devDependencies": {
|
|
67
|
-
"@howaboua/pi-codex-conversion": "4.0.
|
|
65
|
+
"@howaboua/pi-codex-conversion": "4.0.8"
|
|
68
66
|
}
|
|
69
67
|
}
|
package/src/archive.ts
CHANGED
|
@@ -8,22 +8,27 @@ import { boundedBoardRead, checkMutationBudget } from "./response.js";
|
|
|
8
8
|
export async function readSubscribedUpdates(
|
|
9
9
|
caller: BoardBinding,
|
|
10
10
|
seen: string[],
|
|
11
|
+
aliases: [string, string][] = [],
|
|
11
12
|
) {
|
|
12
13
|
if (!existsSync(caller.databasePath)) return [];
|
|
13
14
|
const { BoardStore } = await import("./store.js");
|
|
14
|
-
const store = new BoardStore(caller.databasePath, false);
|
|
15
|
+
const store = new BoardStore(caller.databasePath, false, aliases);
|
|
15
16
|
try {
|
|
17
|
+
const identities = JSON.stringify(store.agentIdentities(caller.agentName));
|
|
16
18
|
return store.all<{ message_id: string; thread_id: string }>(
|
|
17
19
|
`SELECT p.id AS message_id,p.root AS thread_id FROM posts p
|
|
18
|
-
WHERE p.board_id=? AND p.author
|
|
20
|
+
WHERE p.board_id=? AND p.author NOT IN (SELECT value FROM json_each(?)) AND NOT EXISTS
|
|
19
21
|
(SELECT 1 FROM json_each(?) WHERE value=p.id) AND EXISTS
|
|
20
22
|
(SELECT 1 FROM subscriptions s WHERE s.board_id=p.board_id
|
|
21
|
-
AND s.agent
|
|
22
|
-
|
|
23
|
+
AND s.agent IN (SELECT value FROM json_each(?)) AND s.enabled=1
|
|
24
|
+
AND (s.agent=? OR NOT EXISTS (SELECT 1 FROM subscriptions n WHERE n.board_id=s.board_id AND n.target=s.target AND n.agent=?))
|
|
25
|
+
AND s.target=CASE WHEN p.id=p.root THEN 'channel:'||p.channel ELSE 'thread:'||p.root END)
|
|
23
26
|
ORDER BY p.seq ASC LIMIT 50`,
|
|
24
27
|
caller.boardId,
|
|
25
|
-
|
|
28
|
+
identities,
|
|
26
29
|
JSON.stringify(seen),
|
|
30
|
+
identities,
|
|
31
|
+
caller.agentName,
|
|
27
32
|
caller.agentName,
|
|
28
33
|
);
|
|
29
34
|
} finally {
|
|
@@ -36,6 +41,7 @@ export async function executeArchive(
|
|
|
36
41
|
memberNames: readonly string[],
|
|
37
42
|
params: BoardParams,
|
|
38
43
|
requestId: string,
|
|
44
|
+
aliases: [string, string][] = [],
|
|
39
45
|
) {
|
|
40
46
|
if (
|
|
41
47
|
params.action === "set_status" &&
|
|
@@ -65,7 +71,8 @@ export async function executeArchive(
|
|
|
65
71
|
...(params.agents_to_notify ?? []),
|
|
66
72
|
...(params.target_agent === undefined ? [] : [params.target_agent]),
|
|
67
73
|
]) {
|
|
68
|
-
const
|
|
74
|
+
const path = agentPath(value, caller.legacyAgentName ?? caller.agentName);
|
|
75
|
+
const target = new Map(aliases).get(path) ?? path;
|
|
69
76
|
if (!memberNames.includes(target))
|
|
70
77
|
throw new Error(`Agent not bound to this tree: ${target}`);
|
|
71
78
|
}
|
|
@@ -87,7 +94,7 @@ export async function executeArchive(
|
|
|
87
94
|
return { value: page([], params), recipients: [] };
|
|
88
95
|
throw new Error("This board has no channels or posts yet");
|
|
89
96
|
}
|
|
90
|
-
const store = new storage.BoardStore(caller.databasePath, write);
|
|
97
|
+
const store = new storage.BoardStore(caller.databasePath, write, aliases);
|
|
91
98
|
try {
|
|
92
99
|
const scope = {
|
|
93
100
|
boardId: caller.boardId,
|
|
@@ -95,6 +102,9 @@ export async function executeArchive(
|
|
|
95
102
|
ownerFolder: caller.ownerFolder,
|
|
96
103
|
callerSessionId: caller.sessionId,
|
|
97
104
|
agentName: caller.agentName,
|
|
105
|
+
...(caller.legacyAgentName
|
|
106
|
+
? { legacyAgentName: caller.legacyAgentName }
|
|
107
|
+
: {}),
|
|
98
108
|
members: memberNames,
|
|
99
109
|
};
|
|
100
110
|
return write
|
package/src/awareness.ts
CHANGED
|
@@ -88,7 +88,8 @@ export class BoardAwareness {
|
|
|
88
88
|
ids?: unknown;
|
|
89
89
|
};
|
|
90
90
|
return data?.boardId === own.boardId &&
|
|
91
|
-
data.agentName === own.agentName
|
|
91
|
+
(data.agentName === own.agentName ||
|
|
92
|
+
data.agentName === own.legacyAgentName) &&
|
|
92
93
|
Array.isArray(data.ids)
|
|
93
94
|
? data.ids.filter((id): id is string => typeof id === "string")
|
|
94
95
|
: [];
|