@oisin-ee/pi-dogsled 0.32.0 → 0.34.0
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/README.md +28 -5
- package/package.json +1 -1
- package/pi/activity.ts +470 -0
- package/pi/index.ts +30 -28
- package/pi/observation.ts +110 -0
- package/pi/panel.ts +10 -7
- package/pi/work-history.ts +6 -18
- package/plugins/dogsled/skills/dogsled/SKILL.md +16 -7
- package/plugins/dogsled/skills/dogsled/references/brief.md +6 -6
- package/plugins/dogsled/skills/dogsled/references/commands.md +1 -1
- package/plugins/dogsled/skills/dogsled/references/land.md +1 -1
- package/plugins/dogsled/skills/dogsled/references/review.md +6 -1
package/README.md
CHANGED
|
@@ -13,13 +13,13 @@ Install the binary on each Herdr host. Use the same release tag in each command.
|
|
|
13
13
|
Binary:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
mise use github:oisin-ee/dogsled@v0.
|
|
16
|
+
mise use github:oisin-ee/dogsled@v0.34.0 # x-release-please-version
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Pi (extension, tools, the `todo` tool, and skill), from npm:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
pi install npm:@oisin-ee/pi-dogsled@0.
|
|
22
|
+
pi install npm:@oisin-ee/pi-dogsled@0.34.0 # x-release-please-version
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
At session start the extension compares its version with `dogsled --version` and warns when they differ.
|
|
@@ -58,12 +58,21 @@ The bot uses `GITHUB_TOKEN`, so its release-PR updates do not start CI.
|
|
|
58
58
|
Nothing auto-merges the release PR.
|
|
59
59
|
|
|
60
60
|
When the user requests a release, merge the open release-please PR.
|
|
61
|
-
The merge runs the full CI suite through the reusable CI workflow.
|
|
61
|
+
The merge runs the full CI suite on the release commit through the reusable CI workflow.
|
|
62
62
|
After CI passes, the publish job creates `vX.Y.Z` at that release commit and dispatches dist.
|
|
63
63
|
Dist publishes the binaries and calls the existing npm publisher.
|
|
64
64
|
The publish job changes `autorelease: pending` to `autorelease: tagged` so release-please can prepare the next release.
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Until its tag exists, the merged release PR stays the outstanding release.
|
|
67
|
+
Every run of `release-please.yml` settles it, and `scripts/release-prepare.sh` decides what the run owes.
|
|
68
|
+
The gate validates only the commit the run is for, so only a run for the release commit itself can tag it.
|
|
69
|
+
|
|
70
|
+
- If CI failed for a reason outside the release commit, and `main` has not moved on, dispatch `release-please.yml` on `main` to retry it.
|
|
71
|
+
- If `main` has moved past the release commit, the run fails and names the commit to revert.
|
|
72
|
+
Revert it on `main` with a `chore(release):` subject.
|
|
73
|
+
The next run marks its PR `autorelease: superseded`, and release-please opens a fresh release PR for the same version.
|
|
74
|
+
- If a tag exists but its PR still has `autorelease: pending`, the next run changes the label to `autorelease: tagged`.
|
|
75
|
+
|
|
67
76
|
If dispatch fails after tag creation, dispatch the existing tag manually:
|
|
68
77
|
|
|
69
78
|
```sh
|
|
@@ -72,7 +81,6 @@ gh workflow run release.yml --ref vX.Y.Z -f tag=vX.Y.Z
|
|
|
72
81
|
|
|
73
82
|
Never move an existing tag.
|
|
74
83
|
A partial publication can leave conflicting assets and requires review before a retry.
|
|
75
|
-
If dispatch failed before the label change, change the merged PR label from `autorelease: pending` to `autorelease: tagged` after dispatch succeeds.
|
|
76
84
|
|
|
77
85
|
## Web portal
|
|
78
86
|
|
|
@@ -597,6 +605,21 @@ remote_command = ["mise", "x", "--", "dogsled"]
|
|
|
597
605
|
repositories = [] # for example "~/.config/mise"; `~/` is the home directory
|
|
598
606
|
```
|
|
599
607
|
|
|
608
|
+
`dogsled serve` publishes every GitHub repository that your `gh` account can access, including forks.
|
|
609
|
+
Archived repositories are excluded. The catalogue refreshes at startup and at most once per hour.
|
|
610
|
+
A failed refresh retains the last good list and publishes the error.
|
|
611
|
+
|
|
612
|
+
```sh
|
|
613
|
+
dogsled repo list
|
|
614
|
+
dogsled repo list --json
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
The portal’s New picker searches repository names and descriptions, newest pushes first.
|
|
618
|
+
`GET /api/repos` and `repo list --json` return `{repos, error}` from the published catalogue.
|
|
619
|
+
Each repository contains `slug`, `description`, `pushed_at`, and `private`.
|
|
620
|
+
Without a publication, readers report that the catalogue is unavailable.
|
|
621
|
+
Repository registration and the `repo add` and `repo remove` commands no longer exist.
|
|
622
|
+
|
|
600
623
|
Host policy has no worktree hooks. A `[hooks]` table is an unknown key, so it is an error. Worktree setup and teardown belong to each repository.
|
|
601
624
|
|
|
602
625
|
### Quota snapshots
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oisin-ee/pi-dogsled",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Pi extension for dogsled: the board, the /dogsled panel, the inbox reader, and the dogsled tools. Needs the dogsled binary of the same version.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/pi/activity.ts
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
// Session-scoped telemetry. Hooks reduce compact facts; only the publisher performs I/O.
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { PortalClient } from "./portal-client.ts";
|
|
5
|
+
|
|
6
|
+
export type Phase = "idle" | "working" | "thinking" | "responding" | "tool_running";
|
|
7
|
+
export interface ActiveTool {
|
|
8
|
+
call_id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
parent_call_id: string | null;
|
|
11
|
+
call?: string;
|
|
12
|
+
}
|
|
13
|
+
export type Payload =
|
|
14
|
+
| { kind: "snapshot"; state: { phase: Phase; active_tools: ActiveTool[]; reasoning?: string } }
|
|
15
|
+
| { kind: "unavailable"; reason: "resyncing" | "overflow" }
|
|
16
|
+
| { kind: "closed" };
|
|
17
|
+
export type ActivityEvent =
|
|
18
|
+
| { type: "agent_start" | "agent_end" | "settled" | "message_end" }
|
|
19
|
+
| { type: "block"; index: number; phase: "thinking" | "responding"; ended: boolean; delta?: string }
|
|
20
|
+
| { type: "tool_start"; tool: ActiveTool }
|
|
21
|
+
| { type: "tool_end"; id: string };
|
|
22
|
+
|
|
23
|
+
/** The same call-line rule is used by the transcript reader in src/activity.rs. */
|
|
24
|
+
export function callLine(name: string, arguments_: unknown): string {
|
|
25
|
+
let args = arguments_;
|
|
26
|
+
if (typeof args === "string") {
|
|
27
|
+
try {
|
|
28
|
+
args = JSON.parse(args);
|
|
29
|
+
} catch {
|
|
30
|
+
// Non-JSON strings remain literal arguments in the fallback display.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (record(args)) {
|
|
34
|
+
const command = args["command"] ?? args["cmd"];
|
|
35
|
+
if (typeof command === "string") return `$ ${command}`;
|
|
36
|
+
const path = args["path"] ?? args["file_path"];
|
|
37
|
+
if (typeof path === "string") return `${name.toLowerCase()} ${path}`;
|
|
38
|
+
}
|
|
39
|
+
return `${name} ${JSON.stringify(args) ?? "null"}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Newest UTF-8 bytes, without splitting a character. */
|
|
43
|
+
function tail(value: string, max: number): string {
|
|
44
|
+
const bytes = Buffer.from(value);
|
|
45
|
+
let start = Math.max(0, bytes.length - max);
|
|
46
|
+
while (start < bytes.length && ((bytes.at(start) ?? 0) & 0xc0) === 0x80) start++;
|
|
47
|
+
return bytes.subarray(start).toString();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Preparation events never enter this reducer. Overflow is sticky until verified settlement. */
|
|
51
|
+
export class ActivityReducer {
|
|
52
|
+
private blocks = new Map<number, "thinking" | "responding">();
|
|
53
|
+
private thoughts = new Map<number, string>();
|
|
54
|
+
private tools = new Map<string, ActiveTool>();
|
|
55
|
+
private gap: "resyncing" | "overflow" | undefined;
|
|
56
|
+
private idle: boolean;
|
|
57
|
+
|
|
58
|
+
constructor(idle: boolean) {
|
|
59
|
+
this.idle = idle;
|
|
60
|
+
if (!idle) this.gap = "resyncing";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
reduce(event: ActivityEvent): Payload {
|
|
64
|
+
if (event.type === "settled") {
|
|
65
|
+
this.blocks.clear();
|
|
66
|
+
this.thoughts.clear();
|
|
67
|
+
this.tools.clear();
|
|
68
|
+
this.gap = undefined;
|
|
69
|
+
this.idle = true;
|
|
70
|
+
} else if (!this.gap) {
|
|
71
|
+
if (event.type === "agent_start" || event.type === "agent_end") this.idle = false;
|
|
72
|
+
else if (event.type === "message_end") {
|
|
73
|
+
this.blocks.clear();
|
|
74
|
+
this.thoughts.clear();
|
|
75
|
+
} else if (event.type === "block") {
|
|
76
|
+
this.idle = false;
|
|
77
|
+
this.blocks.delete(event.index);
|
|
78
|
+
if (!event.ended) this.blocks.set(event.index, event.phase);
|
|
79
|
+
if (event.phase === "thinking") {
|
|
80
|
+
this.thoughts.set(event.index, (this.thoughts.get(event.index) ?? "") + (event.delta ?? ""));
|
|
81
|
+
}
|
|
82
|
+
} else if (event.type === "tool_start") {
|
|
83
|
+
this.idle = false;
|
|
84
|
+
this.tools.set(event.tool.call_id, { ...event.tool });
|
|
85
|
+
} else if (event.type === "tool_end") this.tools.delete(event.id);
|
|
86
|
+
if (this.blocks.size > 64 || this.thoughts.size > 64 || this.tools.size > 64) {
|
|
87
|
+
this.gap = "overflow";
|
|
88
|
+
this.blocks.clear();
|
|
89
|
+
this.thoughts.clear();
|
|
90
|
+
this.tools.clear();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return this.snapshot();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
snapshot(): Payload {
|
|
97
|
+
if (this.gap) return { kind: "unavailable", reason: this.gap };
|
|
98
|
+
const active_tools = [...this.tools.values()].map((tool) => ({ ...tool }));
|
|
99
|
+
const phase = active_tools.length
|
|
100
|
+
? "tool_running"
|
|
101
|
+
: ([...this.blocks.values()].at(-1) ?? (this.idle ? "idle" : "working"));
|
|
102
|
+
const reasoning = tail(
|
|
103
|
+
[...this.thoughts.entries()]
|
|
104
|
+
.sort(([a], [b]) => a - b)
|
|
105
|
+
.map(([, thought]) => thought)
|
|
106
|
+
.filter((thought) => thought.length > 0)
|
|
107
|
+
.join("\n\n"),
|
|
108
|
+
16 * 1024,
|
|
109
|
+
);
|
|
110
|
+
return { kind: "snapshot", state: { phase, active_tools, ...(reasoning ? { reasoning } : {}) } };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface Evidence {
|
|
115
|
+
session_file: string;
|
|
116
|
+
session_id: string;
|
|
117
|
+
}
|
|
118
|
+
interface Stamp {
|
|
119
|
+
epoch: string;
|
|
120
|
+
generation: number;
|
|
121
|
+
producer_id: string;
|
|
122
|
+
session: string;
|
|
123
|
+
}
|
|
124
|
+
interface Ack extends Stamp {
|
|
125
|
+
version: number;
|
|
126
|
+
pane: string;
|
|
127
|
+
sequence: number;
|
|
128
|
+
heartbeat_ms: number;
|
|
129
|
+
ttl_ms: number;
|
|
130
|
+
}
|
|
131
|
+
interface Request {
|
|
132
|
+
method: string;
|
|
133
|
+
path: string;
|
|
134
|
+
body?: unknown;
|
|
135
|
+
}
|
|
136
|
+
type Client = Pick<PortalClient, "request">;
|
|
137
|
+
const counter = (value: unknown): value is number =>
|
|
138
|
+
typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
139
|
+
const record = (value: unknown): value is Record<string, unknown> =>
|
|
140
|
+
typeof value === "object" && value !== null;
|
|
141
|
+
const text = (value: unknown, max: number): value is string =>
|
|
142
|
+
typeof value === "string" &&
|
|
143
|
+
Buffer.byteLength(value) > 0 &&
|
|
144
|
+
Buffer.byteLength(value) <= max &&
|
|
145
|
+
!/[\u0000-\u001f\u007f-\u009f]/u.test(value);
|
|
146
|
+
|
|
147
|
+
function acknowledgement(value: unknown, pane: string, producer: string): value is Ack {
|
|
148
|
+
return (
|
|
149
|
+
record(value) &&
|
|
150
|
+
value["version"] === 1 &&
|
|
151
|
+
value["pane"] === pane &&
|
|
152
|
+
value["producer_id"] === producer &&
|
|
153
|
+
text(value["epoch"], 256) &&
|
|
154
|
+
text(value["session"], 16384) &&
|
|
155
|
+
counter(value["generation"]) &&
|
|
156
|
+
value["generation"] > 0 &&
|
|
157
|
+
counter(value["sequence"]) &&
|
|
158
|
+
value["heartbeat_ms"] === 5000 &&
|
|
159
|
+
value["ttl_ms"] === 15000
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** One immutable request in flight, one replaceable pending snapshot, no hook awaits. */
|
|
164
|
+
export class ActivityPublisher {
|
|
165
|
+
readonly reducer: ActivityReducer;
|
|
166
|
+
private readonly path: string;
|
|
167
|
+
private readonly producer = randomUUID();
|
|
168
|
+
private disposed = false;
|
|
169
|
+
private stopped = false;
|
|
170
|
+
private busy = false;
|
|
171
|
+
private pending: Payload | undefined;
|
|
172
|
+
private request: Request | undefined;
|
|
173
|
+
private stamp: Stamp | undefined;
|
|
174
|
+
private sequence = 0;
|
|
175
|
+
private lastAttempt = -Infinity;
|
|
176
|
+
private retryAt = -Infinity;
|
|
177
|
+
private retryDelay = 500;
|
|
178
|
+
private timer: ReturnType<typeof setTimeout> | undefined;
|
|
179
|
+
private heartbeat: ReturnType<typeof setInterval>;
|
|
180
|
+
private controller: AbortController | undefined;
|
|
181
|
+
private flight: Promise<void> | undefined;
|
|
182
|
+
private readonly client: Client;
|
|
183
|
+
private readonly pane: string;
|
|
184
|
+
private readonly evidence: Evidence;
|
|
185
|
+
|
|
186
|
+
constructor(client: Client, pane: string, evidence: Evidence, idle: boolean) {
|
|
187
|
+
this.client = client;
|
|
188
|
+
this.pane = pane;
|
|
189
|
+
this.evidence = { ...evidence };
|
|
190
|
+
this.path = `/api/agents/local/${encodeURIComponent(pane)}/activity`;
|
|
191
|
+
this.reducer = new ActivityReducer(idle);
|
|
192
|
+
this.pending = this.reducer.snapshot();
|
|
193
|
+
this.request = { method: "GET", path: this.path };
|
|
194
|
+
this.heartbeat = setInterval(() => {
|
|
195
|
+
if (this.disposed || this.stopped) return;
|
|
196
|
+
this.pending = this.reducer.snapshot();
|
|
197
|
+
this.schedule();
|
|
198
|
+
}, 5000);
|
|
199
|
+
this.heartbeat.unref();
|
|
200
|
+
this.schedule();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
event(event: ActivityEvent): void {
|
|
204
|
+
if (this.disposed || this.stopped) return;
|
|
205
|
+
this.pending = this.reducer.reduce(event);
|
|
206
|
+
this.schedule();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private schedule(): void {
|
|
210
|
+
if (this.disposed || this.stopped || this.busy || this.timer) return;
|
|
211
|
+
this.timer = setTimeout(
|
|
212
|
+
() => {
|
|
213
|
+
if (this.disposed) return;
|
|
214
|
+
this.timer = undefined;
|
|
215
|
+
this.flight = this.pump();
|
|
216
|
+
},
|
|
217
|
+
Math.max(0, this.retryAt - performance.now(), 250 - (performance.now() - this.lastAttempt)),
|
|
218
|
+
);
|
|
219
|
+
this.timer.unref();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private async send(
|
|
223
|
+
request: Request,
|
|
224
|
+
controller: AbortController,
|
|
225
|
+
): Promise<{ status: number; body: unknown }> {
|
|
226
|
+
let deadline: ReturnType<typeof setTimeout> | undefined;
|
|
227
|
+
try {
|
|
228
|
+
return await Promise.race([
|
|
229
|
+
(async () => {
|
|
230
|
+
const response = await this.client.request(request.method, request.path, {
|
|
231
|
+
body: request.body,
|
|
232
|
+
signal: controller.signal,
|
|
233
|
+
});
|
|
234
|
+
return {
|
|
235
|
+
status: response.status,
|
|
236
|
+
body: response.ok
|
|
237
|
+
? ((await response.json()) as unknown)
|
|
238
|
+
: ((await response.json().catch(() => undefined)) as unknown),
|
|
239
|
+
};
|
|
240
|
+
})(),
|
|
241
|
+
new Promise<never>((_resolve, reject) => {
|
|
242
|
+
deadline = setTimeout(() => {
|
|
243
|
+
controller.abort();
|
|
244
|
+
reject(new Error("activity request deadline"));
|
|
245
|
+
}, 1000);
|
|
246
|
+
deadline.unref();
|
|
247
|
+
}),
|
|
248
|
+
]);
|
|
249
|
+
} finally {
|
|
250
|
+
if (deadline) clearTimeout(deadline);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private async pump(): Promise<void> {
|
|
255
|
+
if (this.disposed || this.stopped || this.busy) return;
|
|
256
|
+
if (!this.request && this.stamp && this.pending) {
|
|
257
|
+
this.request = {
|
|
258
|
+
method: "PUT",
|
|
259
|
+
path: this.path,
|
|
260
|
+
body: {
|
|
261
|
+
version: 1,
|
|
262
|
+
...this.stamp,
|
|
263
|
+
sequence: ++this.sequence,
|
|
264
|
+
payload: this.pending,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
this.pending = undefined;
|
|
268
|
+
}
|
|
269
|
+
const request = this.request;
|
|
270
|
+
if (!request) return;
|
|
271
|
+
this.busy = true;
|
|
272
|
+
this.lastAttempt = performance.now();
|
|
273
|
+
const controller = new AbortController();
|
|
274
|
+
this.controller = controller;
|
|
275
|
+
try {
|
|
276
|
+
const { status, body } = await this.send(request, controller);
|
|
277
|
+
if (this.disposed) return;
|
|
278
|
+
if (status < 200 || status >= 300) {
|
|
279
|
+
const code = record(body) && typeof body["error"] === "string" ? body["code"] : undefined;
|
|
280
|
+
if (
|
|
281
|
+
(request.method === "POST" &&
|
|
282
|
+
(code === "session_changed" ||
|
|
283
|
+
code === "session_unverified" ||
|
|
284
|
+
code === "upstream_unavailable" ||
|
|
285
|
+
code === "stale_generation")) ||
|
|
286
|
+
(request.method === "PUT" &&
|
|
287
|
+
(code === "stale_generation" ||
|
|
288
|
+
code === "session_changed" ||
|
|
289
|
+
code === "producer_closed"))
|
|
290
|
+
) {
|
|
291
|
+
this.stamp = undefined;
|
|
292
|
+
this.sequence = 0;
|
|
293
|
+
this.pending = this.reducer.snapshot();
|
|
294
|
+
this.request = { method: "GET", path: this.path };
|
|
295
|
+
this.retryAt = performance.now() + this.retryDelay;
|
|
296
|
+
this.retryDelay = Math.min(5000, this.retryDelay * 2);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
// A server failure may follow a committed mutation. Retry this exact request.
|
|
300
|
+
if (status >= 500) return;
|
|
301
|
+
this.stop();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (request.method === "GET") {
|
|
305
|
+
if (
|
|
306
|
+
!record(body) ||
|
|
307
|
+
body["version"] !== 1 ||
|
|
308
|
+
body["pane"] !== this.pane ||
|
|
309
|
+
!text(body["epoch"], 256) ||
|
|
310
|
+
!record(body["producer"]) ||
|
|
311
|
+
!counter(body["producer"]["generation"]) ||
|
|
312
|
+
(body["producer"]["id"] !== null && body["producer"]["id"] !== undefined)
|
|
313
|
+
) {
|
|
314
|
+
this.stop();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
// Freeze fresh compare-and-swap evidence only while the pane is unowned.
|
|
318
|
+
this.request = {
|
|
319
|
+
method: "POST",
|
|
320
|
+
path: `${this.path}/producer`,
|
|
321
|
+
body: {
|
|
322
|
+
version: 1,
|
|
323
|
+
epoch: body["epoch"],
|
|
324
|
+
expected_generation: body["producer"]["generation"],
|
|
325
|
+
producer_id: this.producer,
|
|
326
|
+
evidence: { ...this.evidence },
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
} else {
|
|
330
|
+
if (
|
|
331
|
+
!acknowledgement(body, this.pane, this.producer) ||
|
|
332
|
+
body.sequence !== (request.method === "POST" ? 0 : this.sequence) ||
|
|
333
|
+
(request.method === "POST" &&
|
|
334
|
+
record(request.body) &&
|
|
335
|
+
(body.epoch !== request.body["epoch"] ||
|
|
336
|
+
!counter(request.body["expected_generation"]) ||
|
|
337
|
+
body.generation <= request.body["expected_generation"])) ||
|
|
338
|
+
(this.stamp &&
|
|
339
|
+
(body.epoch !== this.stamp.epoch ||
|
|
340
|
+
body.generation !== this.stamp.generation ||
|
|
341
|
+
body.session !== this.stamp.session))
|
|
342
|
+
) {
|
|
343
|
+
this.stop();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
this.stamp = {
|
|
347
|
+
epoch: body.epoch,
|
|
348
|
+
generation: body.generation,
|
|
349
|
+
producer_id: body.producer_id,
|
|
350
|
+
session: body.session,
|
|
351
|
+
};
|
|
352
|
+
this.request = undefined;
|
|
353
|
+
this.retryDelay = 500;
|
|
354
|
+
this.retryAt = -Infinity;
|
|
355
|
+
}
|
|
356
|
+
} catch {
|
|
357
|
+
// Offline and ambiguous outcomes are telemetry gaps, never hook failures.
|
|
358
|
+
if (this.disposed) return;
|
|
359
|
+
} finally {
|
|
360
|
+
if (!this.disposed) {
|
|
361
|
+
this.busy = false;
|
|
362
|
+
this.controller = undefined;
|
|
363
|
+
if (this.request || this.pending) this.schedule();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private stop(): void {
|
|
369
|
+
this.stopped = true;
|
|
370
|
+
clearInterval(this.heartbeat);
|
|
371
|
+
if (this.timer) clearTimeout(this.timer);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
dispose(): void {
|
|
375
|
+
if (this.disposed) return;
|
|
376
|
+
this.disposed = true;
|
|
377
|
+
clearInterval(this.heartbeat);
|
|
378
|
+
if (this.timer) clearTimeout(this.timer);
|
|
379
|
+
this.controller?.abort();
|
|
380
|
+
// A close can only terminalize this acknowledged registration. Never wait in shutdown.
|
|
381
|
+
if (this.stamp) {
|
|
382
|
+
const request = {
|
|
383
|
+
method: "PUT",
|
|
384
|
+
path: this.path,
|
|
385
|
+
body: {
|
|
386
|
+
version: 1,
|
|
387
|
+
...this.stamp,
|
|
388
|
+
sequence: this.sequence + 1,
|
|
389
|
+
payload: { kind: "closed" },
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
const close = async () => {
|
|
393
|
+
await this.flight;
|
|
394
|
+
// Disposed is required here: closure is the only permitted post-disposal I/O.
|
|
395
|
+
if (!this.disposed) return;
|
|
396
|
+
await this.send(request, new AbortController());
|
|
397
|
+
};
|
|
398
|
+
void close().catch(() => undefined);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Register synchronous notification hooks before any session resources start. */
|
|
404
|
+
export function registerActivity(pi: ExtensionAPI, client: Client, pane: string | undefined): void {
|
|
405
|
+
let runtime: ActivityPublisher | undefined;
|
|
406
|
+
pi.on("session_start", (_event, ctx) => {
|
|
407
|
+
runtime?.dispose();
|
|
408
|
+
runtime = undefined;
|
|
409
|
+
if (!pane) return;
|
|
410
|
+
try {
|
|
411
|
+
const session_file = ctx.sessionManager.getSessionFile();
|
|
412
|
+
const session_id = ctx.sessionManager.getSessionId();
|
|
413
|
+
if (!session_file || !text(session_file, 4096) || !text(session_id, 1024) || !text(pane, 128))
|
|
414
|
+
return;
|
|
415
|
+
runtime = new ActivityPublisher(client, pane, { session_file, session_id }, ctx.isIdle());
|
|
416
|
+
} catch {
|
|
417
|
+
/* Missing native evidence leaves detail unavailable. */
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
pi.on("session_shutdown", () => {
|
|
421
|
+
runtime?.dispose();
|
|
422
|
+
runtime = undefined;
|
|
423
|
+
});
|
|
424
|
+
pi.on("agent_start", () => {
|
|
425
|
+
runtime?.event({ type: "agent_start" });
|
|
426
|
+
});
|
|
427
|
+
pi.on("agent_end", () => {
|
|
428
|
+
runtime?.event({ type: "agent_end" });
|
|
429
|
+
});
|
|
430
|
+
pi.on("agent_settled", () => {
|
|
431
|
+
runtime?.event({ type: "settled" });
|
|
432
|
+
});
|
|
433
|
+
pi.on("message_update", (event) => {
|
|
434
|
+
if (event.message.role !== "assistant") return;
|
|
435
|
+
const update = event.assistantMessageEvent;
|
|
436
|
+
switch (update.type) {
|
|
437
|
+
case "thinking_start":
|
|
438
|
+
case "thinking_delta":
|
|
439
|
+
case "thinking_end":
|
|
440
|
+
case "text_start":
|
|
441
|
+
case "text_delta":
|
|
442
|
+
case "text_end":
|
|
443
|
+
runtime?.event({
|
|
444
|
+
type: "block",
|
|
445
|
+
index: update.contentIndex,
|
|
446
|
+
phase: update.type.startsWith("thinking") ? "thinking" : "responding",
|
|
447
|
+
ended: update.type.endsWith("_end"),
|
|
448
|
+
...(update.type === "thinking_delta" ? { delta: update.delta } : {}),
|
|
449
|
+
});
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
pi.on("message_end", (event) => {
|
|
454
|
+
if (event.message.role === "assistant") runtime?.event({ type: "message_end" });
|
|
455
|
+
});
|
|
456
|
+
pi.on("tool_execution_start", (event) => {
|
|
457
|
+
runtime?.event({
|
|
458
|
+
type: "tool_start",
|
|
459
|
+
tool: {
|
|
460
|
+
call_id: event.toolCallId,
|
|
461
|
+
name: event.toolName,
|
|
462
|
+
parent_call_id: event.parentToolCallId ?? null,
|
|
463
|
+
call: tail(callLine(event.toolName, event.args), 512),
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
pi.on("tool_execution_end", (event) => {
|
|
468
|
+
runtime?.event({ type: "tool_end", id: event.toolCallId });
|
|
469
|
+
});
|
|
470
|
+
}
|
package/pi/index.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Box, Text, Key } from "@earendil-works/pi-tui";
|
|
4
|
-
import { type Board, clean,
|
|
4
|
+
import { type Board, clean, herdrAvailable } from "./board.ts";
|
|
5
5
|
import { WorkTodo, TodoPublisher } from "./work-todo.ts";
|
|
6
6
|
import { UnitBridge } from "./unit-bridge.ts";
|
|
7
7
|
import { workBoard, workText, type WorkState } from "./work.ts";
|
|
8
8
|
import { type Details, InboxReader, MESSAGE_TYPE } from "./inbox.ts";
|
|
9
9
|
import { openPanel } from "./panel.ts";
|
|
10
|
-
import {
|
|
10
|
+
import type { JobHistory } from "./work-history.ts";
|
|
11
|
+
import { Observation, type Observed } from "./observation.ts";
|
|
11
12
|
import { WorkPanel, WorkDetail, runWorkAction, type WorkAction, type WorkCursor, type WorkData, type WorkTab } from "./work-panel.ts";
|
|
12
13
|
import { registerInterview } from "./interview.ts";
|
|
13
14
|
import { registerPlanMode } from "./plan-mode.ts";
|
|
14
15
|
import { PortalClient } from "./portal-client.ts";
|
|
16
|
+
import { registerActivity } from "./activity.ts";
|
|
15
17
|
import { createTodo } from "./todo/src/index.ts";
|
|
16
18
|
|
|
17
19
|
const REFRESH_MS = 10_000;
|
|
@@ -58,6 +60,7 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
58
60
|
const units = new UnitBridge(pi, binary, todo.tasks);
|
|
59
61
|
// The portal owns the interactive parts of Pi: the interview form and the plan review.
|
|
60
62
|
const portal = new PortalClient();
|
|
63
|
+
registerActivity(pi, portal, owner);
|
|
61
64
|
const planMode = registerPlanMode(pi, todo.approve, portal);
|
|
62
65
|
const interviews = registerInterview(pi, portal);
|
|
63
66
|
// One handler owns the tool call: the unit bridge first, then the plan-mode gate.
|
|
@@ -115,6 +118,10 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
115
118
|
let requestWorkRender: (() => void) | undefined;
|
|
116
119
|
let sideDisplay = false;
|
|
117
120
|
let publicationFailure: string | undefined;
|
|
121
|
+
// The session's one publication client. Board and history arrive as serve publishes them.
|
|
122
|
+
const observation = owner ? new Observation(binary, owner, observed => {
|
|
123
|
+
if (context) observe(context, observed);
|
|
124
|
+
}) : undefined;
|
|
118
125
|
const publisher = new TodoPublisher(owner ?? "", error => context?.ui.notify(`Todo publication failed: ${String(error)}`, "error"));
|
|
119
126
|
const todos = new WorkTodo(todo.work, () => {
|
|
120
127
|
if (context) { publishTodos(context); draw(context); }
|
|
@@ -134,6 +141,19 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
134
141
|
publishTodos(ctx);
|
|
135
142
|
}
|
|
136
143
|
|
|
144
|
+
/** A frame replaces the board and history; unavailability is said once and keeps the last ones. */
|
|
145
|
+
function observe(ctx: ExtensionContext, observed: Observed): void {
|
|
146
|
+
if (observed.frame) {
|
|
147
|
+
failure = undefined;
|
|
148
|
+
board = observed.frame.board;
|
|
149
|
+
history = observed.frame.history;
|
|
150
|
+
} else {
|
|
151
|
+
if (observed.error !== failure) ctx.ui.notify(observed.error, "error");
|
|
152
|
+
failure = observed.error;
|
|
153
|
+
}
|
|
154
|
+
draw(ctx);
|
|
155
|
+
}
|
|
156
|
+
|
|
137
157
|
function state(): WorkState {
|
|
138
158
|
return { board, todo: todos.current, error: failure ?? todos.error };
|
|
139
159
|
}
|
|
@@ -148,7 +168,6 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
148
168
|
workPanel = undefined;
|
|
149
169
|
workDetail = undefined;
|
|
150
170
|
detail = undefined;
|
|
151
|
-
history = { jobs: [] };
|
|
152
171
|
draw(ctx);
|
|
153
172
|
}
|
|
154
173
|
|
|
@@ -162,11 +181,8 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
162
181
|
cursor = { tab, selected: undefined, history: false };
|
|
163
182
|
workPanel?.dispose();
|
|
164
183
|
workPanel = undefined;
|
|
165
|
-
|
|
184
|
+
// History is already published with the board: expanding reads nothing.
|
|
166
185
|
draw(ctx);
|
|
167
|
-
// Draw immediately; remote history must not delay expansion or typing.
|
|
168
|
-
if (refresh) await refresh;
|
|
169
|
-
if (current === generation && workOpen) await update(ctx);
|
|
170
186
|
}
|
|
171
187
|
|
|
172
188
|
async function act(ctx: ExtensionContext, action: WorkAction | undefined): Promise<void> {
|
|
@@ -237,26 +253,9 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
237
253
|
if (text !== publicationFailure) ctx.ui.notify(text, "warning");
|
|
238
254
|
publicationFailure = text;
|
|
239
255
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (current !== generation) return;
|
|
244
|
-
failure = undefined;
|
|
245
|
-
board = next;
|
|
246
|
-
if (workOpen) {
|
|
247
|
-
const loaded = await loadJobHistory(exec, owner);
|
|
248
|
-
if (current !== generation) return;
|
|
249
|
-
if (workOpen) history = loaded;
|
|
250
|
-
}
|
|
251
|
-
draw(ctx);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
// Say so once, not on every refresh; the last board stays on screen.
|
|
254
|
-
const text = String(error);
|
|
255
|
-
if (current !== generation) return;
|
|
256
|
-
if (text !== failure) ctx.ui.notify(text, "error");
|
|
257
|
-
failure = text;
|
|
258
|
-
draw(ctx);
|
|
259
|
-
}
|
|
256
|
+
// Resubscribe after the publisher went away. A live subscription costs nothing here.
|
|
257
|
+
// The side display draws nothing, but /dogsled reads the same subscription.
|
|
258
|
+
if (current === generation) observation?.start();
|
|
260
259
|
})().finally(() => { refresh = undefined; });
|
|
261
260
|
return refresh;
|
|
262
261
|
}
|
|
@@ -282,6 +281,7 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
282
281
|
requestWorkRender = undefined;
|
|
283
282
|
workPanel?.dispose();
|
|
284
283
|
if (timer) clearInterval(timer);
|
|
284
|
+
observation?.stop();
|
|
285
285
|
generation++;
|
|
286
286
|
workAbort?.abort();
|
|
287
287
|
workAbort = undefined;
|
|
@@ -322,6 +322,8 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
322
322
|
detail = undefined;
|
|
323
323
|
if (timer) clearInterval(timer);
|
|
324
324
|
timer = undefined;
|
|
325
|
+
observation?.stop();
|
|
326
|
+
history = { jobs: [] };
|
|
325
327
|
inbox.stop();
|
|
326
328
|
todos.stop();
|
|
327
329
|
await publisher.clear();
|
|
@@ -394,7 +396,7 @@ export default function dogsled(pi: ExtensionAPI) {
|
|
|
394
396
|
panelOpen = true;
|
|
395
397
|
draw(ctx);
|
|
396
398
|
try {
|
|
397
|
-
await openPanel(ctx, exec);
|
|
399
|
+
await openPanel(ctx, exec, () => ({ board, error: failure }));
|
|
398
400
|
} finally {
|
|
399
401
|
panelOpen = false;
|
|
400
402
|
draw(ctx);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The one publication client of a Pi session. `dogsled board --watch` subscribes to serve's
|
|
2
|
+
// publication and prints the owner's board and job history once per revision; this client
|
|
3
|
+
// only parses those frames. It never derives, probes, or polls state.
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { createInterface } from "node:readline";
|
|
6
|
+
import { type Board, clean, parseBoard } from "./board.ts";
|
|
7
|
+
import { type JobHistory, parseJobHistory } from "./work-history.ts";
|
|
8
|
+
|
|
9
|
+
export interface Frame { revision: number; board: Board; history: JobHistory }
|
|
10
|
+
|
|
11
|
+
/** A frame, or why the publication is unavailable. The last frame stays the caller's to keep. */
|
|
12
|
+
export type Observed = { frame: Frame; error?: undefined } | { frame?: undefined; error: string };
|
|
13
|
+
|
|
14
|
+
/** The parts of a child process this client uses, so tests can supply one. */
|
|
15
|
+
export interface Watcher {
|
|
16
|
+
stdout: NodeJS.ReadableStream | null;
|
|
17
|
+
stderr: NodeJS.ReadableStream | null;
|
|
18
|
+
kill(): unknown;
|
|
19
|
+
/** After exit and after its output is read, so no frame is lost. */
|
|
20
|
+
once(event: "close", listener: (code: number | null) => void): unknown;
|
|
21
|
+
once(event: "error", listener: (error: Error) => void): unknown;
|
|
22
|
+
}
|
|
23
|
+
export type Spawn = (binary: string, args: string[]) => Watcher;
|
|
24
|
+
|
|
25
|
+
const spawnWatcher: Spawn = (binary, args) => spawn(binary, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
26
|
+
|
|
27
|
+
/** One line of `dogsled board --watch --json`. */
|
|
28
|
+
export function parseFrame(line: string): Observed {
|
|
29
|
+
let value: unknown;
|
|
30
|
+
try { value = JSON.parse(line); } catch { return { error: "Dogsled observation sent an invalid frame" }; }
|
|
31
|
+
if (!value || typeof value !== "object") return { error: "Dogsled observation sent an invalid frame" };
|
|
32
|
+
const frame = value as Record<string, unknown>;
|
|
33
|
+
if (typeof frame["revision"] !== "number") return { error: "Dogsled observation sent an invalid frame" };
|
|
34
|
+
if (typeof frame["error"] === "string") return { error: clean(frame["error"]) };
|
|
35
|
+
try {
|
|
36
|
+
return { frame: { revision: frame["revision"], board: parseBoard(frame["board"]), history: parseJobHistory(frame["history"]) } };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return { error: clean(String(error)) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class Observation {
|
|
43
|
+
private watcher: Watcher | undefined;
|
|
44
|
+
private generation = 0;
|
|
45
|
+
private revision = 0;
|
|
46
|
+
|
|
47
|
+
private readonly binary: string;
|
|
48
|
+
private readonly owner: string;
|
|
49
|
+
private readonly listener: (observed: Observed) => void;
|
|
50
|
+
private readonly spawner: Spawn;
|
|
51
|
+
|
|
52
|
+
constructor(binary: string, owner: string, listener: (observed: Observed) => void, spawner: Spawn = spawnWatcher) {
|
|
53
|
+
this.binary = binary;
|
|
54
|
+
this.owner = owner;
|
|
55
|
+
this.listener = listener;
|
|
56
|
+
this.spawner = spawner;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get running(): boolean { return this.watcher !== undefined; }
|
|
60
|
+
|
|
61
|
+
/** Subscribe unless subscribed. After the watcher exits, the next call subscribes again. */
|
|
62
|
+
start(): void {
|
|
63
|
+
if (this.watcher) return;
|
|
64
|
+
const generation = ++this.generation;
|
|
65
|
+
const current = () => generation === this.generation;
|
|
66
|
+
let watcher: Watcher;
|
|
67
|
+
try {
|
|
68
|
+
watcher = this.spawner(this.binary, ["board", "--watch", "--json", "--owner", this.owner]);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.listener({ error: `Dogsled observation unavailable: ${clean(String(error))}` });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.watcher = watcher;
|
|
74
|
+
let stderr = "";
|
|
75
|
+
watcher.stderr?.setEncoding("utf8");
|
|
76
|
+
watcher.stderr?.on("data", (chunk: string) => { stderr = (stderr + chunk).slice(-2_000); });
|
|
77
|
+
const lines = createInterface({ input: watcher.stdout! });
|
|
78
|
+
lines.on("line", line => {
|
|
79
|
+
if (!current()) return;
|
|
80
|
+
const observed = parseFrame(line);
|
|
81
|
+
// Revisions only move forward within one subscription.
|
|
82
|
+
if (observed.frame) {
|
|
83
|
+
if (observed.frame.revision <= this.revision) return;
|
|
84
|
+
this.revision = observed.frame.revision;
|
|
85
|
+
}
|
|
86
|
+
this.listener(observed);
|
|
87
|
+
});
|
|
88
|
+
let done = false;
|
|
89
|
+
const ended = (detail: string) => {
|
|
90
|
+
if (done) return;
|
|
91
|
+
done = true;
|
|
92
|
+
lines.close();
|
|
93
|
+
if (!current()) return;
|
|
94
|
+
this.watcher = undefined;
|
|
95
|
+
this.revision = 0;
|
|
96
|
+
this.listener({ error: `Dogsled observation unavailable: ${clean(detail)}` });
|
|
97
|
+
};
|
|
98
|
+
watcher.once("close", code => ended(stderr.trim() || `dogsled board exited with ${code ?? "a signal"}`));
|
|
99
|
+
watcher.once("error", error => ended(String(error)));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** End the subscription. Frames and exits from it are ignored from now on. */
|
|
103
|
+
stop(): void {
|
|
104
|
+
this.generation++;
|
|
105
|
+
this.revision = 0;
|
|
106
|
+
const watcher = this.watcher;
|
|
107
|
+
this.watcher = undefined;
|
|
108
|
+
watcher?.kill();
|
|
109
|
+
}
|
|
110
|
+
}
|
package/pi/panel.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `/dogsled`: the control panel. It takes the board widget's place while open, so each row
|
|
2
|
-
// shows once. Status (the default)
|
|
3
|
-
// `dogsled
|
|
2
|
+
// shows once. Status (the default) comes from the session's publication subscription; Hosts,
|
|
3
|
+
// Profiles, and Inbox from `dogsled machine|profiles|inbox --json`. The panel only shows choices. Each choice
|
|
4
4
|
// closes it with an action that the command runs, so dialogs never open inside the panel.
|
|
5
5
|
import { readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import type { ExtensionCommandContext, KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
|
|
@@ -150,13 +150,16 @@ export class Panel {
|
|
|
150
150
|
|
|
151
151
|
type Exec = (args: string[]) => Promise<string>;
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
/** The session's last published board, and why the publication is unavailable, if it is. */
|
|
154
|
+
export type Observed = () => { board: Board; error?: string | undefined };
|
|
155
|
+
|
|
156
|
+
async function load(exec: Exec, observed: Observed, now: number): Promise<PanelData> {
|
|
157
|
+
const { board, error } = observed();
|
|
158
|
+
const data: PanelData = { board, machines: [], profiles: [], inbox: [], errors: error ? { status: error } : {}, now };
|
|
155
159
|
const read = async <T>(tab: Tab, args: string[], set: (value: T) => void) => {
|
|
156
160
|
try { set(JSON.parse(await exec(args)) as T); } catch (error) { data.errors[tab] = error instanceof Error ? error.message : String(error); }
|
|
157
161
|
};
|
|
158
162
|
await Promise.all([
|
|
159
|
-
read<Board>("status", ["board", "--json"], v => { data.board = v; }),
|
|
160
163
|
read<Machine[]>("hosts", ["machine", "list", "--json"], v => { data.machines = v; }),
|
|
161
164
|
read<Profile[]>("profiles", ["profiles", "--json"], v => { data.profiles = v; }),
|
|
162
165
|
read<{ lines: InboxLine[] }>("inbox", ["inbox", "list", "--json"], v => { data.inbox = v.lines; }),
|
|
@@ -210,10 +213,10 @@ async function run(action: NonNullable<Action>, ctx: ExtensionCommandContext, ex
|
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
/** Open the panel, run what the user picks, and reopen it until they close it. */
|
|
213
|
-
export async function openPanel(ctx: ExtensionCommandContext, exec: Exec, now: () => number = Date.now): Promise<void> {
|
|
216
|
+
export async function openPanel(ctx: ExtensionCommandContext, exec: Exec, observed: Observed, now: () => number = Date.now): Promise<void> {
|
|
214
217
|
let tab: Tab = "status";
|
|
215
218
|
for (;;) {
|
|
216
|
-
const data = await load(exec, now());
|
|
219
|
+
const data = await load(exec, observed, now());
|
|
217
220
|
const action = await ctx.ui.custom<Action>((_tui, theme, keys, done) => new Panel(tab, data, theme, keys, done));
|
|
218
221
|
if (!action) return;
|
|
219
222
|
tab = action.tab;
|
package/pi/work-history.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { clean } from "./board.ts";
|
|
2
|
-
|
|
3
1
|
export interface WorkJob {
|
|
4
2
|
id: string; host: string; owner: string; cmd: string[]; state: string;
|
|
5
3
|
ended_ms: number | null; exit: number | null;
|
|
@@ -14,20 +12,10 @@ function job(value: unknown): value is WorkJob {
|
|
|
14
12
|
&& (value["exit"] === null || typeof value["exit"] === "number");
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
/**
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!record(items) || !Array.isArray(items["items"]) || !Array.isArray(jobs) || !jobs.every(job)) throw new Error("Invalid Dogsled job history");
|
|
24
|
-
const allowed = new Set<string>();
|
|
25
|
-
for (const item of items["items"]) {
|
|
26
|
-
if (!record(item) || typeof item["id"] !== "string" || typeof item["host"] !== "string" || typeof item["owner_pane"] !== "string") throw new Error("Invalid Dogsled owner item");
|
|
27
|
-
if (item["owner_pane"] === owner && item["kind"] === "job") allowed.add(JSON.stringify([item["host"], item["id"]]));
|
|
28
|
-
}
|
|
29
|
-
return { jobs: jobs.filter(item => allowed.has(JSON.stringify([item.host, item.id]))), hosts };
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return { jobs: [], error: `History unavailable: ${clean(String(error))}` };
|
|
32
|
-
}
|
|
15
|
+
/** Serve publishes each owner's history, joined on host and job id; this only checks its shape. */
|
|
16
|
+
export function parseJobHistory(value: unknown): JobHistory {
|
|
17
|
+
if (!record(value) || !Array.isArray(value["jobs"]) || !value["jobs"].every(job)) throw new Error("Invalid Dogsled job history");
|
|
18
|
+
const hosts = value["hosts"];
|
|
19
|
+
if (!Array.isArray(hosts) || !hosts.every((host): host is { id: string; label: string } => record(host) && typeof host["id"] === "string" && typeof host["label"] === "string")) throw new Error("Invalid Dogsled host identities");
|
|
20
|
+
return { jobs: value["jobs"], hosts: hosts.map(host => ({ id: host.id, label: host.label })) };
|
|
33
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dogsled
|
|
3
|
-
description: Lead procedure for a change to code, config, or Git. It covers splitting the work, starting workers, and landing their results. Load it when a top-level session gets a change request. Do not load it in an exec session given prewalk. Do not load it
|
|
3
|
+
description: Lead procedure for a change to code, config, or Git. It covers splitting the work, starting workers, and landing their results. Load it when a top-level session gets a change request. Do not load it in an exec session given prewalk. Do not load it in a worker session, because the worker profile prompt is your whole job.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Exec agents given prewalk
|
|
@@ -25,19 +25,24 @@ Otherwise, do not edit code or config. Delegate it with steps 1 to 5.
|
|
|
25
25
|
|
|
26
26
|
## 1. Split
|
|
27
27
|
|
|
28
|
-
List the deliverables. Each one has one outcome,
|
|
28
|
+
List the deliverables. Each one has one outcome, an acceptance condition, and the paths it reads or owns.
|
|
29
29
|
Add each deliverable as a todo unit with a `worker` assignment and the profile from step 2.
|
|
30
30
|
Put deliverables that touch the same files in one unit.
|
|
31
31
|
Put small specified edits of one request in one unit, even across files. Never start one worker per small edit.
|
|
32
32
|
|
|
33
33
|
## 2. Pick the profile
|
|
34
34
|
|
|
35
|
+
Use only these two worker profiles:
|
|
36
|
+
|
|
35
37
|
| The unit is | Profile |
|
|
36
38
|
| --- | --- |
|
|
39
|
+
| Read-only investigation, diagnosis, design analysis, or review | `research` |
|
|
37
40
|
| A specified change: you know what to edit and why | `writer` |
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
Investigate ordinary questions in the lead session.
|
|
43
|
+
Delegate research only for a defined question that warrants a separate worker.
|
|
44
|
+
An unknown cause or design does not require a research worker.
|
|
45
|
+
Research produces evidence, not file changes or more agents.
|
|
41
46
|
|
|
42
47
|
The default writer uses GPT Sol for the whole session, with no typing-tier handoff. The profile owns model selection and effort.
|
|
43
48
|
|
|
@@ -47,8 +52,12 @@ Before you write your first brief in a session, read `references/brief.md`.
|
|
|
47
52
|
|
|
48
53
|
## 4. Start
|
|
49
54
|
|
|
50
|
-
Start each worker from its unit
|
|
51
|
-
|
|
55
|
+
Start each worker from its unit.
|
|
56
|
+
For a writer, use `spawn {unit: {id}, branch, base: "origin/main"}`.
|
|
57
|
+
For research, use `spawn {unit: {id}}` without a branch or base.
|
|
58
|
+
A bare `spawn` with a name does not link the unit, so the unit can never close.
|
|
59
|
+
Start independent units in the same turn.
|
|
60
|
+
Start a dependent unit only after its prerequisite is accepted and any prerequisite code changes are merged.
|
|
52
61
|
Then end your turn. Replies arrive in your inbox. Do not wait or poll.
|
|
53
62
|
|
|
54
63
|
## 5. Check each reply
|
|
@@ -5,12 +5,12 @@ The worker sees only the brief and the contract that its unit seeds. It uses tha
|
|
|
5
5
|
Write these sections in this order:
|
|
6
6
|
|
|
7
7
|
1. **Outcome.** One sentence that states what is true when the unit is done.
|
|
8
|
-
2. **Cause or
|
|
9
|
-
3. **Edits.**
|
|
10
|
-
4. **
|
|
11
|
-
5. **Acceptance.**
|
|
12
|
-
6. **Checks.** For a docs-only unit, name no build or test run. Otherwise, the light checks for this repository, for example `cargo clippy --all-targets -- -D warnings`, a type check of the package, or the unit tests of the changed files. Name them, because the writer runs only these.
|
|
8
|
+
2. **Cause or question.** For a writer, name the owning cause or design with file paths and line numbers. Resolve missing facts before dispatch. For research, name the unanswered question and the evidence required.
|
|
9
|
+
3. **Edits.** For a writer, list the files to change and what changes in each. For repeated edits, give one exemplar and a search command for the other sites. For research, state that the unit is read-only and cannot spawn agents.
|
|
10
|
+
4. **Paths.** A writer can change only its owned paths and generated files. A research unit has no owned paths. Name the paths it can read.
|
|
11
|
+
5. **Acceptance.** Give the exact command and expected result, or the evidence required for a research result. The command need not be light. The lead does not run it again if it already passed at the same revision.
|
|
12
|
+
6. **Checks.** For a research or docs-only unit, name no build or test run. Otherwise, the light checks for this repository, for example `cargo clippy --all-targets -- -D warnings`, a type check of the package, or the unit tests of the changed files. Name them, because the writer runs only these.
|
|
13
13
|
7. **Base.** The base commit SHA.
|
|
14
14
|
|
|
15
|
-
Before you send the brief, check it against the code. Confirm that the paths exist, that the exemplar compiles
|
|
15
|
+
Before you send the brief, check it against the code. Confirm that the paths exist. For a writer, also confirm that the exemplar compiles and no lint or generator rule conflicts with the brief.
|
|
16
16
|
Keep the brief under 60 lines. If it needs more, split the unit.
|
|
@@ -25,7 +25,7 @@ A unit dispatch is the lead's normal path: `spawn {unit:{id}, branch, base}` lin
|
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
27
|
dogsled agent --profile writer --name api-dups --message-file task.md --branch feat/api-dups
|
|
28
|
-
dogsled agent --
|
|
28
|
+
dogsled agent --profile research --name change-review --message 'Review the change on feat/x; do not edit files'
|
|
29
29
|
dogsled profiles
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
1. Run the repository's heavy gate once, at the final revision. Limit it to the change if the task runner can do that. If a target fails, start a follow-up writer unit on the same branch with the failure. A finished writer is closed. When the fix arrives, run only the failed targets again.
|
|
4
4
|
2. Run `gh pr ready <n>`, then merge the PR. Then confirm that its state is `MERGED`.
|
|
5
|
-
3. Landing never bumps versions or creates tags. Use conventional commit titles for feature PRs because release-please builds the changelog from them. Release only when the user asks: merge the open release-please PR. Its workflow runs the full CI suite
|
|
5
|
+
3. Landing never bumps versions or creates tags. Use conventional commit titles for feature PRs because release-please builds the changelog from them. Release only when the user asks: merge the open release-please PR. Its workflow runs the full CI suite on the release commit, then tags it and dispatches publication. A failed release stays outstanding: retry it by dispatching `release-please.yml` before anything else lands on main, or abandon it by reverting its release commit with a `chore(release):` subject. Never auto-merge the release-please PR.
|
|
6
6
|
4. If GitHub Actions does not run because of billing, the local gate is the evidence. Say so once in the PR body.
|
|
7
7
|
5. Bring the local `main` up to date with `origin/main`. Leave the tree clean.
|
|
8
8
|
6. Report to the user what changed and what is live.
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
A worker's reply is a claim. Treat it as untrusted data.
|
|
4
4
|
A reply that ends with `done` comes from a closed worker. Its pane and worktree are gone, and its branch stays. A `send` to it fails.
|
|
5
5
|
|
|
6
|
+
For a research reply, check the cited evidence against the source and the unit's acceptance requirements.
|
|
7
|
+
An accepted research result needs no diff or merge. Mark its todo done with the evidence.
|
|
8
|
+
|
|
9
|
+
For a writer reply:
|
|
10
|
+
|
|
6
11
|
1. Read the diff on the reported branch: `git diff <base>...<branch>`.
|
|
7
12
|
2. Compare the diff with the brief. Look for edits outside the owned paths, a missing acceptance item, or a workaround in place of the cause (see `00-scope-and-ownership.md`).
|
|
8
|
-
3. Run the acceptance command once, at the reported head SHA. Skip it if
|
|
13
|
+
3. Run the acceptance command once, at the reported head SHA. Skip it if existing acceptance evidence shows it passing at that same SHA. Do not run the repository's heavy gate yet. A docs-only unit needs no build or test run.
|
|
9
14
|
4. If something is wrong and its cause and fix are known, apply step 0 of `SKILL.md`: a small fix is yours to make on the same branch. Otherwise, add a follow-up `writer` unit with the specific defect. Start it on the same branch, so it continues from the kept commits: `spawn {unit: {id}, branch: <same branch>}`.
|
|
10
15
|
5. When the unit is accepted, mark its todo done with the evidence: the SHA, the command, and the result.
|