@oisin-ee/pi-dogsled 0.25.2 → 0.26.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 +20 -7
- package/package.json +1 -1
- package/pi/interview.ts +155 -14
- package/pi/plan-mode.ts +11 -7
- package/pi/portal-client.ts +19 -3
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.26.0
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Pi (extension, tools, and skill), from npm or as part of `@oisin-ee/oisinpi`:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
pi install npm:@oisin-ee/pi-dogsled@0.
|
|
22
|
+
pi install npm:@oisin-ee/pi-dogsled@0.26.0
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
At session start the extension compares its version with `dogsled --version` and warns when they differ.
|
|
@@ -27,14 +27,14 @@ At session start the extension compares its version with `dogsled --version` and
|
|
|
27
27
|
Claude Code (hooks, tools, and skill):
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
-
claude plugin marketplace add oisin-ee/dogsled#v0.
|
|
30
|
+
claude plugin marketplace add oisin-ee/dogsled#v0.26.0
|
|
31
31
|
claude plugin install dogsled@dogsled
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
Codex (hooks, tools, and skill):
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
|
-
codex plugin marketplace add oisin-ee/dogsled --ref v0.
|
|
37
|
+
codex plugin marketplace add oisin-ee/dogsled --ref v0.26.0
|
|
38
38
|
codex plugin add dogsled@dogsled
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ The [Codex CLI reference](https://developers.openai.com/codex/cli/reference#code
|
|
|
44
44
|
Herdr (left-docked work board):
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
herdr plugin install oisin-ee/dogsled --ref v0.
|
|
47
|
+
herdr plugin install oisin-ee/dogsled --ref v0.26.0 --yes
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
The Claude and Codex plugins use the binary on `PATH`. The Herdr plugin's build step (`plugin/fetch.sh`) installs its own binary at `bin/dogsled`: the release archive for the manifest version, checked against its published SHA-256. When that release has no archive for the platform, it runs `cargo build --release --locked` instead, which needs Rust at the crate's `rust-version` or newer. A checksum mismatch stops the install. `DOGSLED_RELEASES` replaces the download base, such as a mirror. `herdr plugin link` skips build steps, so run `sh plugin/fetch.sh` in a linked checkout. No plugin starts host services.
|
|
@@ -113,6 +113,8 @@ Without a branch, a remote non-repository `--cwd` must exist there.
|
|
|
113
113
|
Repository directories map to the same path relative to home. A linked-worktree caller needs `--branch` to preserve its branch remotely.
|
|
114
114
|
|
|
115
115
|
The pane runs `dogsled exec ID -- COMMAND`. Output goes to the pane and `jobs/ID.log` on that host.
|
|
116
|
+
A job runs only from its own durable claim in `jobs/ID.json`. `exec` refuses a job whose record is missing, unreadable, for another job, incomplete, for another command, already started, ended, or uncertain. A refusal starts no new process, log, or pane: a job that already started keeps the process and log it already has.
|
|
117
|
+
The launch publishes a non-executable intent before it allocates a pane, and an executable claim once the pane is known. An allocation that stops, or a dispatch that was never proved, stays uncertain and never runs again. A launch replays a saved receipt only when the receipt matches the request and the recorded job; a claim alone is not a receipt.
|
|
116
118
|
If the pane output closes, capture continues to the log and preserves the child exit code.
|
|
117
119
|
The atomic `jobs/ID.json` contains the command, directory, host, owner, exit code, signal, reason, and millisecond timestamps.
|
|
118
120
|
After the job ends, `exec` saves this final record, reports completion, then closes its own pane and tab.
|
|
@@ -176,9 +178,12 @@ Closed children retain TO LAND rows: `<child>: branch <b> +N to land`. These row
|
|
|
176
178
|
```sh
|
|
177
179
|
dogsled close w2:p1
|
|
178
180
|
dogsled close w9:p1 --host netcup --json
|
|
181
|
+
dogsled drop <item-id> --host netcup
|
|
179
182
|
dogsled done # as a child: my whole task is complete
|
|
180
183
|
```
|
|
181
184
|
|
|
185
|
+
`drop` deletes a closed child's retained local and origin branches, including unmerged commits. Only the item's owner can use it. It refuses a branch checked out in a worktree. Already absent branches count as success. The item and its done mark stay settled and leave the board.
|
|
186
|
+
|
|
182
187
|
`close` ends a child now, for an owner who does not want to wait for the sweep. `--host` defaults to the host of the pane's open item, else local.
|
|
183
188
|
|
|
184
189
|
For an interrupted launch with no final receipt, explicit `close` can retire its exact idle shell under the request and pane locks. This closes **only the pane**, retaining the checkout, preparation holds, and unknown launch evidence. It does not report that the task never started. Competing launch records, a changed terminal, any agent, or incomplete foreground evidence refuse recovery. Automatic cleanup never uses this recovery path; normal cleanup can assess the retained checkout after its holds are resolved.
|
|
@@ -542,7 +547,15 @@ With `--branch`, `place`, `agent`, and `run` use the branch's worktree on the se
|
|
|
542
547
|
Before repository work, dogsled verifies the selected host's checkout against the caller's `git remote get-url origin`.
|
|
543
548
|
If the host has no checkout of the repository, dogsled clones it from the caller's origin into the same path relative to home first.
|
|
544
549
|
An existing path with a different origin, or a non-repository path, is an error. Dogsled does not overwrite it.
|
|
545
|
-
Clone errors identify the host and
|
|
550
|
+
Clone errors identify the selected host and a safe cause. Dogsled does not show credential-bearing origins or command output.
|
|
551
|
+
Dogsled does not silently move the work elsewhere.
|
|
552
|
+
|
|
553
|
+
Remote preparation errors include a versioned `diagnostic` object in CLI JSON and MCP error results.
|
|
554
|
+
The object contains the operation, a stable cause code, validated context, and available status and request correlation.
|
|
555
|
+
Known causes include an unavailable base, an existing branch with `--base`, an occupied workspace, a checkout identity mismatch, and clone or setup failure.
|
|
556
|
+
Admission records, failed tickets, unit responses, and owner notifications retain the safe cause.
|
|
557
|
+
Unknown or malformed peer diagnostics state why Dogsled withheld the detail. Host-health summaries remain categorical.
|
|
558
|
+
A missing-base check never fetches commits or changes branches or worktrees.
|
|
546
559
|
After a fresh clone, dogsled checks mise configuration. If mise reports missing trust, dogsled trusts only that new checkout's configuration.
|
|
547
560
|
For peers, a checkout under the local home maps to the same relative path under the peer's home.
|
|
548
561
|
The peer reads its own host policy.
|
|
@@ -597,7 +610,7 @@ Plugin commands end with `|| true`. Pi also leaves the prompt unchanged if the b
|
|
|
597
610
|
|
|
598
611
|
### Tools
|
|
599
612
|
|
|
600
|
-
`dogsled mcp` serves the dogsled commands as MCP tools over stdio: `status`, `spawn`, `run`, `send`, `inbox`, `read`, `close`, `done`, `stop`, `cancel`, and `place`.
|
|
613
|
+
`dogsled mcp` serves the dogsled commands as MCP tools over stdio: `status`, `spawn`, `run`, `send`, `inbox`, `read`, `close`, `drop`, `done`, `stop`, `cancel`, and `place`.
|
|
601
614
|
Tools share the CLI action code. `spawn` returns a durable queued ticket, even when a host has room.
|
|
602
615
|
The service owns startup confirmation outside the MCP call budget. `dogsled agent` still starts synchronously under `--max`.
|
|
603
616
|
Startup errors include recent pane output in the launch record and ticket when the pane read succeeds.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oisin-ee/pi-dogsled",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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/interview.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { readFileSync } from "node:fs";
|
|
|
8
8
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
10
10
|
import { isAbsolute, join } from "node:path";
|
|
11
|
-
import type { AgentToolResult, ExtensionAPI, ExtensionToolContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import { PortalClient, PortalDown, sleep, startOneShot } from "./portal-client.ts";
|
|
11
|
+
import type { AgentToolResult, AgentToolUpdateCallback, ExtensionAPI, ExtensionToolContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { openInBrowser, PortalClient, PortalDown, portalUrl, sleep, startOneShot } from "./portal-client.ts";
|
|
13
13
|
|
|
14
14
|
/** How long the tool waits between two polls for the answers. */
|
|
15
15
|
const POLL_MS = 500;
|
|
@@ -37,10 +37,10 @@ const interviewParameters = {
|
|
|
37
37
|
},
|
|
38
38
|
} as const;
|
|
39
39
|
|
|
40
|
-
/** The
|
|
40
|
+
/** The interview description with the portal's browser transport. */
|
|
41
41
|
const interviewDescription =
|
|
42
42
|
"Present an interactive form to gather user responses. " +
|
|
43
|
-
"Opens
|
|
43
|
+
"Opens the Dogsled portal, or a fallback browser tab when the portal is not running. " +
|
|
44
44
|
"Use proactively when: choosing between multiple approaches, gathering requirements before implementation, " +
|
|
45
45
|
"exploring design tradeoffs, or when decisions have multiple dimensions worth discussing. " +
|
|
46
46
|
"Provides better UX than back-and-forth chat for structured input. " +
|
|
@@ -204,6 +204,36 @@ function resolveQuestionPath(input: string, cwd: string): string {
|
|
|
204
204
|
return isAbsolute(expanded) ? expanded : join(cwd, expanded);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Whether a source names a file on this host, rather than a URL the browser
|
|
209
|
+
* can load on its own.
|
|
210
|
+
*
|
|
211
|
+
* A form the model writes names its images by the path they have on the
|
|
212
|
+
* agent's machine. That machine is not the machine the browser runs on, so
|
|
213
|
+
* the path never loads. An `http:` or `data:` source already carries its
|
|
214
|
+
* bytes, so it is left alone.
|
|
215
|
+
*/
|
|
216
|
+
function isLocalSource(src: string): boolean {
|
|
217
|
+
return !/^(?:https?:|data:)/i.test(src);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The bytes of an image, or an error that names the file. */
|
|
221
|
+
function readImage(path: string): Buffer {
|
|
222
|
+
try {
|
|
223
|
+
return readFileSync(path);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
const code = (error as { code?: string }).code;
|
|
226
|
+
if (code === "ENOENT") throw new Error(`Image not found: ${path}`);
|
|
227
|
+
throw new Error(`Cannot read the image ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The URL the portal serves an attachment from. */
|
|
232
|
+
function attachmentUrl(path: string): string {
|
|
233
|
+
const name = path.split(/[\\/]/).pop() ?? "";
|
|
234
|
+
return `/api/attachments/${name}`;
|
|
235
|
+
}
|
|
236
|
+
|
|
207
237
|
/**
|
|
208
238
|
* The answers the portal returns. The contract is one body: the id of the
|
|
209
239
|
* form, and the responses of the form. The questions are not part of it, so
|
|
@@ -230,15 +260,17 @@ function isResponseItem(value: unknown): value is ResponseItem {
|
|
|
230
260
|
export class InterviewTool {
|
|
231
261
|
private readonly client: PortalClient;
|
|
232
262
|
private readonly deliver: (content: string) => void;
|
|
263
|
+
private readonly open: (url: string) => void;
|
|
233
264
|
/** The background waits of the async interviews, so the session can close them. */
|
|
234
265
|
private readonly pending = new Set<AbortController>();
|
|
235
|
-
constructor(client: PortalClient = new PortalClient(), deliver: (content: string) => void = () => undefined) {
|
|
266
|
+
constructor(client: PortalClient = new PortalClient(), deliver: (content: string) => void = () => undefined, open: (url: string) => void = openInBrowser) {
|
|
236
267
|
this.client = client;
|
|
237
268
|
this.deliver = deliver;
|
|
269
|
+
this.open = open;
|
|
238
270
|
}
|
|
239
271
|
|
|
240
272
|
/** Run one interview. The tool's `signal` withdraws the form. */
|
|
241
|
-
async run(params: { questions: string; timeout?: number; verbose?: boolean; async?: boolean }, ctx: ExtensionToolContext, signal: AbortSignal | undefined): Promise<AgentToolResult<InterviewDetails>> {
|
|
273
|
+
async run(params: { questions: string; timeout?: number; verbose?: boolean; async?: boolean }, ctx: ExtensionToolContext, signal: AbortSignal | undefined, onUpdate?: AgentToolUpdateCallback<InterviewDetails>): Promise<AgentToolResult<InterviewDetails>> {
|
|
242
274
|
const cwd = ctx.cwd;
|
|
243
275
|
const session = ctx.sessionManager.getSessionId();
|
|
244
276
|
const pane = process.env["HERDR_PANE_ID"] ?? "";
|
|
@@ -247,15 +279,26 @@ export class InterviewTool {
|
|
|
247
279
|
const file = loadQuestions(params.questions, cwd);
|
|
248
280
|
let created: { id?: unknown };
|
|
249
281
|
try {
|
|
282
|
+
// The images of the form are uploaded first, so the browser loads
|
|
283
|
+
// them from the portal instead of from the agent's own disk.
|
|
284
|
+
const questions = await this.uploadMedia(file, cwd, signal);
|
|
250
285
|
created = await this.client.json<{ id?: unknown }>("POST", "/api/questions", {
|
|
251
|
-
questions
|
|
286
|
+
questions, pane, session, cwd,
|
|
252
287
|
}, signal);
|
|
253
288
|
} catch (error) {
|
|
254
289
|
if (!(error instanceof PortalDown)) throw error;
|
|
290
|
+
// The portal is down, so the form goes to the one-shot interview
|
|
291
|
+
// with the questions as the model wrote them.
|
|
255
292
|
return this.fallback(file, params, ctx, signal);
|
|
256
293
|
}
|
|
257
294
|
const id = typeof created?.id === "string" ? created.id : "";
|
|
258
295
|
if (!id) throw new Error("dogsled web did not return an interview id");
|
|
296
|
+
const url = portalUrl(`/?question=${encodeURIComponent(id)}&pane=${encodeURIComponent(pane)}`, this.client.env);
|
|
297
|
+
this.open(url);
|
|
298
|
+
onUpdate?.({
|
|
299
|
+
content: [{ type: "text", text: `Interview ${id} started: ${url}. Waiting for your answers.` }],
|
|
300
|
+
details: { status: "started", responses: [], url },
|
|
301
|
+
});
|
|
259
302
|
|
|
260
303
|
if (params.async) {
|
|
261
304
|
// The form runs on its own: the tool's own signal no longer owns it, and the
|
|
@@ -267,22 +310,22 @@ export class InterviewTool {
|
|
|
267
310
|
.catch(error => { this.deliver(`Interview ${id} did not finish: ${error instanceof Error ? error.message : String(error)}`); })
|
|
268
311
|
.finally(() => { this.pending.delete(own); });
|
|
269
312
|
return {
|
|
270
|
-
content: [{ type: "text", text: `Interview ${id} started. The answer arrives later as a message; keep working and do not poll.` }],
|
|
271
|
-
details: { status: "started", responses: [], url
|
|
313
|
+
content: [{ type: "text", text: `Interview ${id} started: ${url}. The answer arrives later as a message; keep working and do not poll.` }],
|
|
314
|
+
details: { status: "started", responses: [], url },
|
|
272
315
|
};
|
|
273
316
|
}
|
|
274
317
|
|
|
275
318
|
try {
|
|
276
319
|
const answers = await this.wait(id, file, signal, params.timeout);
|
|
277
320
|
return {
|
|
278
|
-
content: [{ type: "text", text: `User completed the interview form
|
|
279
|
-
details: { status: "completed", responses: answers.responses, url
|
|
321
|
+
content: [{ type: "text", text: `User completed the interview form: ${url}\n\nAnswered responses:\n${answers.text}` }],
|
|
322
|
+
details: { status: "completed", responses: answers.responses, url },
|
|
280
323
|
};
|
|
281
324
|
} catch (error) {
|
|
282
325
|
// An aborted interview withdraws its form, so the portal does not wait for an answer.
|
|
283
326
|
if (signal?.aborted) {
|
|
284
327
|
await this.client.request("DELETE", `/api/questions/${encodeURIComponent(id)}`).catch(() => undefined);
|
|
285
|
-
return { content: [{ type: "text", text: "Interview was aborted." }], details: { status: "aborted", responses: [], url
|
|
328
|
+
return { content: [{ type: "text", text: "Interview was aborted." }], details: { status: "aborted", responses: [], url } };
|
|
286
329
|
}
|
|
287
330
|
throw error;
|
|
288
331
|
}
|
|
@@ -343,6 +386,104 @@ export class InterviewTool {
|
|
|
343
386
|
this.pending.clear();
|
|
344
387
|
}
|
|
345
388
|
|
|
389
|
+
/**
|
|
390
|
+
* The form with its local images uploaded to the portal.
|
|
391
|
+
*
|
|
392
|
+
* An image whose `src` names a file on this host is a path the browser
|
|
393
|
+
* cannot reach, because the file lives on the agent's machine and the
|
|
394
|
+
* browser runs on the owner's. The bytes go to the portal as an
|
|
395
|
+
* attachment, and the `src` becomes the URL the portal serves.
|
|
396
|
+
*
|
|
397
|
+
* The portal is asked whether it is there before the first local file is
|
|
398
|
+
* read, so a portal that is down falls back to the one-shot interview
|
|
399
|
+
* with the questions as the model wrote them, and a missing file stays a
|
|
400
|
+
* tool error only when there is a portal to upload it to.
|
|
401
|
+
*/
|
|
402
|
+
private async uploadMedia(file: QuestionsFile, cwd: string, signal: AbortSignal | undefined): Promise<QuestionsFile> {
|
|
403
|
+
const list = file["questions"];
|
|
404
|
+
if (!Array.isArray(list)) return file;
|
|
405
|
+
const local = this.localImages(list, cwd);
|
|
406
|
+
if (local.length === 0) return file;
|
|
407
|
+
// The portal that would hold the images has to be there.
|
|
408
|
+
await this.client.request("GET", "/api/questions", { signal });
|
|
409
|
+
const questions: Record<string, unknown>[] = [];
|
|
410
|
+
for (const entry of list) {
|
|
411
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
412
|
+
questions.push(entry as Record<string, unknown>);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const question: Record<string, unknown> = { ...(entry as Record<string, unknown>) };
|
|
416
|
+
const media = question["media"];
|
|
417
|
+
if (!media || typeof media !== "object" || Array.isArray(media)) {
|
|
418
|
+
questions.push(question);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const block = media as Record<string, unknown>;
|
|
422
|
+
const src = block["src"];
|
|
423
|
+
if (block["type"] !== "image" || typeof src !== "string" || !src || !isLocalSource(src)) {
|
|
424
|
+
questions.push(question);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const path = resolveQuestionPath(src, cwd);
|
|
428
|
+
const bytes = readImage(path);
|
|
429
|
+
const url = await this.uploadAttachment(bytes, path, signal);
|
|
430
|
+
question["media"] = { ...block, src: url };
|
|
431
|
+
questions.push(question);
|
|
432
|
+
}
|
|
433
|
+
return { ...file, questions };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** The local images of a form, as the paths they name. */
|
|
437
|
+
private localImages(list: unknown[], cwd: string): string[] {
|
|
438
|
+
const paths: string[] = [];
|
|
439
|
+
for (const entry of list) {
|
|
440
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
441
|
+
const media = (entry as Record<string, unknown>)["media"];
|
|
442
|
+
if (!media || typeof media !== "object" || Array.isArray(media)) continue;
|
|
443
|
+
const block = media as Record<string, unknown>;
|
|
444
|
+
const src = block["src"];
|
|
445
|
+
if (block["type"] !== "image" || typeof src !== "string" || !src || !isLocalSource(src)) continue;
|
|
446
|
+
paths.push(resolveQuestionPath(src, cwd));
|
|
447
|
+
}
|
|
448
|
+
return paths;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* The bytes of an image, as an attachment of the portal.
|
|
453
|
+
*
|
|
454
|
+
* A portal that cannot be reached is a `PortalDown` error, so the form
|
|
455
|
+
* falls back to the one-shot interview. A portal that refuses the image
|
|
456
|
+
* is an error that names the file.
|
|
457
|
+
*/
|
|
458
|
+
private async uploadAttachment(bytes: Buffer, path: string, signal: AbortSignal | undefined): Promise<string> {
|
|
459
|
+
let response: Response;
|
|
460
|
+
const init: RequestInit = {
|
|
461
|
+
method: "POST",
|
|
462
|
+
headers: {
|
|
463
|
+
authorization: `Bearer ${this.client.token()}`,
|
|
464
|
+
"content-type": "application/octet-stream",
|
|
465
|
+
},
|
|
466
|
+
body: new Uint8Array(bytes),
|
|
467
|
+
};
|
|
468
|
+
if (signal) init.signal = signal;
|
|
469
|
+
try {
|
|
470
|
+
response = await fetch(`http://127.0.0.1:${this.client.port}/api/attachments`, init);
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (signal?.aborted) throw error;
|
|
473
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
474
|
+
const detail = cause instanceof Error ? cause.message : error instanceof Error ? error.message : String(error);
|
|
475
|
+
throw new PortalDown(detail);
|
|
476
|
+
}
|
|
477
|
+
if (!response.ok) {
|
|
478
|
+
throw new Error(`Cannot use the image ${path}: dogsled web POST /api/attachments failed: ${response.status} ${(await response.text()).trim()}`);
|
|
479
|
+
}
|
|
480
|
+
const payload = (await response.json()) as { path?: unknown };
|
|
481
|
+
if (typeof payload.path !== "string" || !payload.path) {
|
|
482
|
+
throw new Error(`Cannot use the image ${path}: dogsled web did not return an attachment path`);
|
|
483
|
+
}
|
|
484
|
+
return attachmentUrl(payload.path);
|
|
485
|
+
}
|
|
486
|
+
|
|
346
487
|
/** Poll the portal until it has the answers, the form is withdrawn, or the wait ends. */
|
|
347
488
|
private async wait(id: string, file: QuestionsFile, signal: AbortSignal | undefined, timeout: number | undefined): Promise<{ text: string; responses: ResponseItem[] }> {
|
|
348
489
|
const seconds = timeout ?? 600;
|
|
@@ -372,10 +513,10 @@ export function registerInterview(pi: ExtensionAPI, client: PortalClient = new P
|
|
|
372
513
|
description: interviewDescription,
|
|
373
514
|
promptSnippet: "Gather structured user input through an interactive form for requirements, tradeoffs, or multi-dimensional decisions.",
|
|
374
515
|
parameters: interviewParameters,
|
|
375
|
-
async execute(_toolCallId, params, signal,
|
|
516
|
+
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
376
517
|
const question = params as { questions?: unknown };
|
|
377
518
|
if (typeof question.questions !== "string" || !question.questions) throw new Error("interview needs the questions, as inline JSON or a path to a questions file");
|
|
378
|
-
return await tool.run(question as { questions: string }, ctx, signal);
|
|
519
|
+
return await tool.run(question as { questions: string }, ctx, signal, onUpdate);
|
|
379
520
|
},
|
|
380
521
|
});
|
|
381
522
|
return tool;
|
package/pi/plan-mode.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { readFile } from "node:fs/promises";
|
|
|
7
7
|
import { extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
8
8
|
import type { ExtensionAPI, ExtensionContext, ToolCallEvent, ToolCallEventResult } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { Key } from "@earendil-works/pi-tui";
|
|
10
|
-
import { PortalClient, PortalDown, sleep, startOneShot } from "./portal-client.ts";
|
|
10
|
+
import { openInBrowser, PortalClient, PortalDown, portalUrl, sleep, startOneShot } from "./portal-client.ts";
|
|
11
11
|
|
|
12
12
|
/** The tool that sends a plan to the portal. */
|
|
13
13
|
const SUBMIT_PLAN = "submit_plan";
|
|
@@ -117,6 +117,7 @@ interface ReviewCreated { id: string; revision: number }
|
|
|
117
117
|
export class PlanMode {
|
|
118
118
|
private readonly pi: PlanHost;
|
|
119
119
|
private readonly client: PortalClient;
|
|
120
|
+
private readonly open: (url: string) => void;
|
|
120
121
|
private planning = false;
|
|
121
122
|
private framed = false;
|
|
122
123
|
private watching: AbortController | undefined;
|
|
@@ -126,9 +127,10 @@ export class PlanMode {
|
|
|
126
127
|
/** The reviews the portal acknowledged. A review that was delivered but not acked is acked again, not delivered again. */
|
|
127
128
|
private readonly acked = new Set<string>();
|
|
128
129
|
|
|
129
|
-
constructor(pi: PlanHost, client: PortalClient = new PortalClient()) {
|
|
130
|
+
constructor(pi: PlanHost, client: PortalClient = new PortalClient(), open: (url: string) => void = openInBrowser) {
|
|
130
131
|
this.pi = pi;
|
|
131
132
|
this.client = client;
|
|
133
|
+
this.open = open;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
/** Whether the model is planning. */
|
|
@@ -166,7 +168,7 @@ export class PlanMode {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
/** Send a plan to the portal and start waiting for its decision. */
|
|
169
|
-
async submit(filePath: string, ctx: ExtensionContext): Promise<ReviewCreated | { fallback: true }> {
|
|
171
|
+
async submit(filePath: string, ctx: ExtensionContext): Promise<(ReviewCreated & { url: string }) | { fallback: true }> {
|
|
170
172
|
const path = isAbsolute(filePath) ? filePath : resolve(ctx.cwd, filePath);
|
|
171
173
|
const content = await readFile(path, "utf8");
|
|
172
174
|
let created: ReviewCreated;
|
|
@@ -183,8 +185,10 @@ export class PlanMode {
|
|
|
183
185
|
const id = typeof created?.id === "string" ? created.id : "";
|
|
184
186
|
const revision = Number(created?.revision);
|
|
185
187
|
if (!id || !Number.isFinite(revision)) throw new Error("dogsled web did not return a review id and revision");
|
|
188
|
+
const url = portalUrl(`/?review=${encodeURIComponent(id)}`, this.client.env);
|
|
189
|
+
if (revision === 1) this.open(url);
|
|
186
190
|
this.watch(ctx);
|
|
187
|
-
return { id, revision };
|
|
191
|
+
return { id, revision, url };
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
/** Start a temporary review server without holding the tool call open. */
|
|
@@ -299,7 +303,7 @@ export class PlanMode {
|
|
|
299
303
|
}
|
|
300
304
|
|
|
301
305
|
/** Register the plan mode: the submit tool, the command, and the shortcut. */
|
|
302
|
-
export function registerPlanMode(pi: ExtensionAPI, client: PortalClient = new PortalClient()): PlanMode {
|
|
306
|
+
export function registerPlanMode(pi: ExtensionAPI, client: PortalClient = new PortalClient(), open: (url: string) => void = openInBrowser): PlanMode {
|
|
303
307
|
const host: PlanHost = {
|
|
304
308
|
events: pi.events,
|
|
305
309
|
sendUserMessage: (content, options) => { pi.sendUserMessage(content, options); },
|
|
@@ -307,7 +311,7 @@ export function registerPlanMode(pi: ExtensionAPI, client: PortalClient = new Po
|
|
|
307
311
|
getActiveTools: () => pi.getActiveTools(),
|
|
308
312
|
setActiveTools: names => { pi.setActiveTools(names); },
|
|
309
313
|
};
|
|
310
|
-
const mode = new PlanMode(host, client);
|
|
314
|
+
const mode = new PlanMode(host, client, open);
|
|
311
315
|
pi.registerTool({
|
|
312
316
|
name: SUBMIT_PLAN,
|
|
313
317
|
label: "Submit plan",
|
|
@@ -326,7 +330,7 @@ export function registerPlanMode(pi: ExtensionAPI, client: PortalClient = new Po
|
|
|
326
330
|
if (typeof filePath !== "string" || !filePath) throw new Error("submit_plan needs the path of the plan file");
|
|
327
331
|
const review = await mode.submit(filePath, ctx);
|
|
328
332
|
return {
|
|
329
|
-
content: [{ type: "text", text: `${"fallback" in review ? "Started a review in a browser tab" : `Pushed as revision ${review.revision}`}; the decision arrives later as a message; end your turn.` }],
|
|
333
|
+
content: [{ type: "text", text: `${"fallback" in review ? "Started a review in a browser tab" : `Pushed as revision ${review.revision}: ${review.url}`}; the decision arrives later as a message; end your turn.` }],
|
|
330
334
|
details: review,
|
|
331
335
|
};
|
|
332
336
|
},
|
package/pi/portal-client.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// The client for the loopback portal server, `dogsled web`. The portal owns the
|
|
2
2
|
// interactive parts of Pi: the interview form and the plan review. This module
|
|
3
|
-
//
|
|
3
|
+
// speaks HTTP to it and opens its deep links. Every call carries the portal's bearer token, and the
|
|
4
4
|
// server answers with the board, a form, a review, or a decision.
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
5
|
+
import { spawn, type ChildProcess, type SpawnOptions } from "node:child_process";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { join } from "node:path";
|
|
@@ -23,6 +23,22 @@ function portalPort(env: NodeJS.ProcessEnv): number {
|
|
|
23
23
|
return Number.isInteger(port) && port > 0 && port < 65536 ? port : DEFAULT_PORT;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** A portal URL using the same port as the HTTP client. */
|
|
27
|
+
export function portalUrl(path: string, env: NodeJS.ProcessEnv = process.env): string {
|
|
28
|
+
return `http://127.0.0.1:${portalPort(env)}${path}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Open a portal link without holding the agent open or failing its tool call. */
|
|
32
|
+
export function openInBrowser(url: string, launch: (command: string, args: string[], options: SpawnOptions) => ChildProcess = spawn): void {
|
|
33
|
+
const child = launch(process.platform === "darwin" ? "open" : "xdg-open", [url], { detached: true, stdio: "ignore" });
|
|
34
|
+
const report = (detail: string) => { console.error(`Could not open the Dogsled portal: ${detail}. Open ${url} in your browser.`); };
|
|
35
|
+
child.once("error", error => { report(error.message); });
|
|
36
|
+
child.once("exit", (code, signal) => {
|
|
37
|
+
if (code !== 0) report(signal ? `browser opener received ${signal}` : `browser opener exited with ${code}`);
|
|
38
|
+
});
|
|
39
|
+
child.unref();
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
/** The dogsled state directory: `DOGSLED_STATE`, else `$XDG_STATE_HOME/dogsled`, else `~/.local/state/dogsled`. */
|
|
27
43
|
function stateDirectory(env: NodeJS.ProcessEnv): string {
|
|
28
44
|
const state = env["DOGSLED_STATE"];
|
|
@@ -113,7 +129,7 @@ export class PortalClient {
|
|
|
113
129
|
}
|
|
114
130
|
if (options.signal) init.signal = options.signal;
|
|
115
131
|
try {
|
|
116
|
-
return await fetch(
|
|
132
|
+
return await fetch(portalUrl(path, this.env), init);
|
|
117
133
|
} catch (error) {
|
|
118
134
|
if (options.signal?.aborted) throw error;
|
|
119
135
|
const cause = error instanceof Error ? error.cause : undefined;
|