@oisin-ee/pi-dogsled 0.37.1 → 0.37.3

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 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.37.1 # x-release-please-version
16
+ mise use github:oisin-ee/dogsled@v0.37.3 # 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.37.1 # x-release-please-version
22
+ pi install npm:@oisin-ee/pi-dogsled@0.37.3 # 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.
@@ -91,6 +91,11 @@ The server listens only on the loopback address.
91
91
  The port defaults to 7465. Set `[web] port` in `dogsled.toml`, or pass `dogsled web --port PORT`.
92
92
  If the portal uses another port, set `DOGSLED_WEB_PORT` for the Pi tools so they can find it.
93
93
 
94
+ Pi sessions publish their live activity and model settings to their own host's `dogsled serve`, not to the portal.
95
+ `serve` answers them on `producer.sock` in the state directory on every host. The socket has mode 0600, so it needs no token.
96
+ The portal reads activity and settings from each host's `serve`, so a Pi session on a host without a portal shows its activity and model picker.
97
+ After an upgrade, restart `serve` before you start new Pi sessions. A running Pi session keeps the extension it started with.
98
+
94
99
  The portal creates its token at `~/.local/state/dogsled/web/token`, or `$DOGSLED_STATE/web/token` with a custom state directory.
95
100
  Only the owner can read the token file. Agent API requests use it as a Bearer credential.
96
101
  Release archives include `dev.dogsled.web.plist` for the macOS login service.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oisin-ee/pi-dogsled",
3
- "version": "0.37.1",
3
+ "version": "0.37.3",
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 CHANGED
@@ -4,7 +4,7 @@ import { existsSync } from "node:fs";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
5
  import type { PortalClient } from "./portal-client.ts";
6
6
 
7
- export type Phase = "idle" | "working" | "thinking" | "responding" | "tool_running";
7
+ export type Phase = "idle" | "working" | "thinking" | "responding" | "tool_running" | "compacting";
8
8
  export interface ActiveTool {
9
9
  call_id: string;
10
10
  name: string;
@@ -17,6 +17,7 @@ export type Payload =
17
17
  | { kind: "closed" };
18
18
  export type ActivityEvent =
19
19
  | { type: "agent_start" | "agent_end" | "settled" | "message_end" }
20
+ | { type: "compaction"; running: boolean }
20
21
  | {
21
22
  type: "block";
22
23
  index: number;
@@ -61,6 +62,7 @@ export class ActivityReducer {
61
62
  private tools = new Map<string, ActiveTool>();
62
63
  private gap: "resyncing" | "overflow" | undefined;
63
64
  private idle: boolean;
65
+ private compacting = false;
64
66
 
65
67
  constructor(idle: boolean) {
66
68
  this.idle = idle;
@@ -74,36 +76,51 @@ export class ActivityReducer {
74
76
  this.tools.clear();
75
77
  this.gap = undefined;
76
78
  this.idle = true;
77
- } else if (!this.gap) {
78
- if (event.type === "agent_start" || event.type === "agent_end") this.idle = false;
79
- else if (event.type === "message_end") {
80
- this.blocks.clear();
81
- this.thoughts.clear();
82
- } else if (event.type === "block") {
83
- this.idle = false;
84
- this.blocks.delete(event.index);
85
- if (!event.ended) this.blocks.set(event.index, event.phase);
86
- if (event.phase === "thinking") {
87
- this.thoughts.set(
88
- event.index,
89
- (this.thoughts.get(event.index) ?? "") + (event.delta ?? ""),
90
- );
91
- }
92
- } else if (event.type === "tool_start") {
93
- this.idle = false;
94
- this.tools.set(event.tool.call_id, { ...event.tool });
95
- } else if (event.type === "tool_end") this.tools.delete(event.id);
96
- if (this.blocks.size > 64 || this.thoughts.size > 64 || this.tools.size > 64) {
97
- this.gap = "overflow";
98
- this.blocks.clear();
99
- this.thoughts.clear();
100
- this.tools.clear();
101
- }
79
+ this.compacting = false;
80
+ } else if (event.type === "compaction") {
81
+ // Pi compacts between turns, so the compaction is the session's whole activity.
82
+ this.compacting = event.running;
83
+ } else {
84
+ // A new run starts only after any compaction ended.
85
+ if (event.type === "agent_start") this.compacting = false;
86
+ if (!this.gap) this.step(event);
102
87
  }
103
88
  return this.snapshot();
104
89
  }
105
90
 
91
+ private step(event: ActivityEvent): void {
92
+ if (event.type === "agent_start" || event.type === "agent_end") this.idle = false;
93
+ else if (event.type === "message_end") {
94
+ this.blocks.clear();
95
+ this.thoughts.clear();
96
+ } else if (event.type === "block") {
97
+ this.idle = false;
98
+ this.blocks.delete(event.index);
99
+ if (!event.ended) this.blocks.set(event.index, event.phase);
100
+ if (event.phase === "thinking") {
101
+ this.thoughts.set(
102
+ event.index,
103
+ (this.thoughts.get(event.index) ?? "") + (event.delta ?? ""),
104
+ );
105
+ }
106
+ } else if (event.type === "tool_start") {
107
+ this.idle = false;
108
+ this.tools.set(event.tool.call_id, { ...event.tool });
109
+ } else if (event.type === "tool_end") this.tools.delete(event.id);
110
+ if (this.blocks.size > 64 || this.thoughts.size > 64 || this.tools.size > 64) {
111
+ this.gap = "overflow";
112
+ this.blocks.clear();
113
+ this.thoughts.clear();
114
+ this.tools.clear();
115
+ }
116
+ }
117
+
106
118
  snapshot(): Payload {
119
+ // Compaction runs between turns, with no tool or block open, so it is known even when
120
+ // the turn's own detail is not.
121
+ if (this.compacting) {
122
+ return { kind: "snapshot", state: { phase: "compacting", active_tools: [] } };
123
+ }
107
124
  if (this.gap) return { kind: "unavailable", reason: this.gap };
108
125
  const active_tools = [...this.tools.values()].map((tool) => ({ ...tool }));
109
126
  const phase = active_tools.length
@@ -590,4 +607,14 @@ export function registerActivity(pi: ExtensionAPI, client: Client, pane: string
590
607
  pi.on("tool_execution_end", (event) => {
591
608
  runtime?.event({ type: "tool_end", id: event.toolCallId });
592
609
  });
610
+ // Pi reports every started compaction's end, including a cancel, as one of these outcomes.
611
+ pi.on("session_before_compact", () => {
612
+ runtime?.event({ type: "compaction", running: true });
613
+ });
614
+ pi.on("session_compact", () => {
615
+ runtime?.event({ type: "compaction", running: false });
616
+ });
617
+ pi.on("session_compact_failed", () => {
618
+ runtime?.event({ type: "compaction", running: false });
619
+ });
593
620
  }
package/pi/index.ts CHANGED
@@ -15,6 +15,7 @@ import { registerPlanMode } from "./plan-mode.ts";
15
15
  import { PortalClient } from "./portal-client.ts";
16
16
  import { registerActivity } from "./activity.ts";
17
17
  import { registerSettings } from "./settings.ts";
18
+ import { ServeClient } from "./serve-client.ts";
18
19
  import { createTodo } from "./todo/src/index.ts";
19
20
 
20
21
  const REFRESH_MS = 10_000;
@@ -59,10 +60,12 @@ export default function dogsled(pi: ExtensionAPI) {
59
60
 
60
61
  const inbox = new InboxReader(pi, exec);
61
62
  const units = new UnitBridge(pi, binary, todo.tasks);
63
+ // The host's serve owns live activity and model settings on every host.
64
+ const serve = new ServeClient();
65
+ registerActivity(pi, serve, owner);
66
+ registerSettings(pi, serve, owner);
62
67
  // The portal owns the interactive parts of Pi: the interview form and the plan review.
63
68
  const portal = new PortalClient();
64
- registerActivity(pi, portal, owner);
65
- registerSettings(pi, portal, owner);
66
69
  const planMode = registerPlanMode(pi, todo.approve, portal);
67
70
  const interviews = registerInterview(pi, portal);
68
71
  // One handler owns the tool call: the unit bridge first, then the plan-mode gate.
@@ -40,7 +40,7 @@ export function openInBrowser(url: string, launch: (command: string, args: strin
40
40
  }
41
41
 
42
42
  /** The dogsled state directory: `DOGSLED_STATE`, else `$XDG_STATE_HOME/dogsled`, else `~/.local/state/dogsled`. */
43
- function stateDirectory(env: NodeJS.ProcessEnv): string {
43
+ export function stateDirectory(env: NodeJS.ProcessEnv): string {
44
44
  const state = env["DOGSLED_STATE"];
45
45
  if (state) return state;
46
46
  const xdg = env["XDG_STATE_HOME"];
@@ -49,10 +49,10 @@ function stateDirectory(env: NodeJS.ProcessEnv): string {
49
49
  }
50
50
 
51
51
  /** One Server-Sent Event: its name and its data. */
52
- interface ServerEvent { event: string; data: string }
52
+ export interface ServerEvent { event: string; data: string }
53
53
 
54
54
  /** Parse a Server-Sent Events stream into events. Comments and unnamed fields are skipped. */
55
- async function* serverEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<ServerEvent> {
55
+ export async function* serverEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<ServerEvent> {
56
56
  const reader = body.getReader();
57
57
  const decoder = new TextDecoder();
58
58
  let buffer = "";
@@ -102,6 +102,8 @@ async function* serverEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<S
102
102
  /** The HTTP client for the loopback portal server. Every call carries the bearer token. */
103
103
  export class PortalClient {
104
104
  readonly env: NodeJS.ProcessEnv;
105
+ /** The server named in errors. */
106
+ protected readonly server: string = "dogsled web";
105
107
  constructor(env: NodeJS.ProcessEnv = process.env) { this.env = env; }
106
108
 
107
109
  /** The port this client talks to. */
@@ -141,7 +143,7 @@ export class PortalClient {
141
143
  /** Send a request and return its JSON body; any other status is an error. An empty body is `undefined`. */
142
144
  async json<T>(method: string, path: string, body?: unknown, signal?: AbortSignal): Promise<T> {
143
145
  const response = await this.request(method, path, { body, signal });
144
- if (!response.ok) throw new Error(`dogsled web ${method} ${path} failed: ${response.status} ${(await response.text()).trim()}`);
146
+ if (!response.ok) throw new Error(`${this.server} ${method} ${path} failed: ${response.status} ${(await response.text()).trim()}`);
145
147
  const text = await response.text();
146
148
  if (!text.trim()) return undefined as T;
147
149
  return JSON.parse(text) as T;
@@ -150,7 +152,7 @@ export class PortalClient {
150
152
  /** Open a Server-Sent Events stream. */
151
153
  async events(path: string, signal: AbortSignal): Promise<AsyncGenerator<ServerEvent>> {
152
154
  const response = await this.request("GET", path, { accept: "text/event-stream", signal });
153
- if (!response.ok || !response.body) throw new Error(`dogsled web GET ${path} failed: ${response.status}`);
155
+ if (!response.ok || !response.body) throw new Error(`${this.server} GET ${path} failed: ${response.status}`);
154
156
  return serverEvents(response.body);
155
157
  }
156
158
  }
@@ -0,0 +1,83 @@
1
+ // The client for Pi's producer endpoint: `dogsled serve` answers it on `producer.sock` in
2
+ // the state directory on every host. A Pi session publishes its live activity and model
3
+ // settings there, and receives settings changes, whether or not its host runs the portal.
4
+ // The socket is private to the user (mode 0600), so requests carry no bearer token.
5
+ import { createHash } from "node:crypto";
6
+ import { realpathSync } from "node:fs";
7
+ import { request as httpRequest } from "node:http";
8
+ import { join } from "node:path";
9
+ import { Readable } from "node:stream";
10
+ import { PortalClient, stateDirectory } from "./portal-client.ts";
11
+
12
+ const SOCKET = "producer.sock";
13
+
14
+ /** `dogsled serve` could not be reached on its producer socket. */
15
+ export class ServeDown extends Error {
16
+ constructor(detail: string) {
17
+ super(`dogsled serve is not running (${detail}). Start it with \`dogsled serve\`.`);
18
+ this.name = "ServeDown";
19
+ }
20
+ }
21
+
22
+ /** The longest socket path the platform accepts, excluding the terminating NUL. */
23
+ function socketPathLimit(platform: NodeJS.Platform): number {
24
+ return platform === "linux" ? 107 : 103;
25
+ }
26
+
27
+ /**
28
+ * The producer socket path, by the same rule as serve's `socket_path`: the state directory
29
+ * when the path fits, else a hashed name in the private runtime directory.
30
+ */
31
+ export function producerSocket(
32
+ env: NodeJS.ProcessEnv = process.env,
33
+ platform: NodeJS.Platform = process.platform,
34
+ realpath: (path: string) => string = realpathSync,
35
+ uid: number = process.getuid?.() ?? 0,
36
+ ): string {
37
+ const state = stateDirectory(env);
38
+ const ordinary = join(state, SOCKET);
39
+ if (Buffer.byteLength(ordinary) <= socketPathLimit(platform)) return ordinary;
40
+ const runtime = env["XDG_RUNTIME_DIR"] ? join(env["XDG_RUNTIME_DIR"], "dogsled") : `/tmp/dogsled-${uid}`;
41
+ const hash = createHash("sha256").update(realpath(state)).digest().subarray(0, 16).toString("hex");
42
+ return join(runtime, `${hash}-producer.sock`);
43
+ }
44
+
45
+ /** HTTP over serve's producer socket, with the same request, JSON and event calls as the portal client. */
46
+ export class ServeClient extends PortalClient {
47
+ protected override readonly server = "dogsled serve";
48
+ private readonly socket: string;
49
+ constructor(env: NodeJS.ProcessEnv = process.env, socket: string = producerSocket(env)) {
50
+ super(env);
51
+ this.socket = socket;
52
+ }
53
+
54
+ override async request(method: string, path: string, options: { body?: unknown; signal?: AbortSignal | undefined; accept?: string } = {}): Promise<Response> {
55
+ const headers: Record<string, string> = { host: "localhost" };
56
+ if (options.accept) headers["accept"] = options.accept;
57
+ let payload: string | undefined;
58
+ if (options.body !== undefined) {
59
+ payload = JSON.stringify(options.body);
60
+ headers["content-type"] = "application/json";
61
+ headers["content-length"] = String(Buffer.byteLength(payload));
62
+ }
63
+ const signal = options.signal;
64
+ if (signal?.aborted) throw signal.reason;
65
+ return await new Promise<Response>((resolve, reject) => {
66
+ const call = httpRequest({ socketPath: this.socket, path, method, headers, ...(signal ? { signal } : {}) }, reply => {
67
+ const status = reply.statusCode ?? 502;
68
+ const replyHeaders = new Headers();
69
+ for (let index = 0; index + 1 < reply.rawHeaders.length; index += 2) {
70
+ replyHeaders.append(reply.rawHeaders[index]!, reply.rawHeaders[index + 1]!);
71
+ }
72
+ const empty = method === "HEAD" || status === 204 || status === 304;
73
+ if (empty) reply.resume();
74
+ const body = empty ? null : Readable.toWeb(reply) as ReadableStream<Uint8Array>;
75
+ resolve(new Response(body, { status, headers: replyHeaders }));
76
+ });
77
+ call.once("error", error => {
78
+ reject(signal?.aborted ? error : new ServeDown(error.message));
79
+ });
80
+ call.end(payload);
81
+ });
82
+ }
83
+ }
@@ -8,8 +8,8 @@ Write these sections in this order:
8
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
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
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.
11
+ 5. **Acceptance.** Give the exact command and expected result, or the evidence required for a research result. The command runs the changed functionality on the real system, or is a cheap check. It is never a heavy check: heavy checks run only before a release. 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 cheap checks for this repository, run on the host, 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
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.
@@ -1,8 +1,8 @@
1
1
  # Land the change
2
2
 
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, fix its cause yourself on the same branch. Then run only the failed targets again.
3
+ 1. Do not run the heavy gate to land a change. Heavy checks (full builds, full test suites, acceptance) run only before a release. Confirm that the cheap checks passed on the host at the final revision, and that you ran the changed functionality on the real system and saw it work. Work is only completed when it is merged to main.
4
4
  2. Run `gh pr ready <n>`, then merge the PR. Then confirm that its state is `MERGED`.
5
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 reuses the passing CI proof of the tree under the release commit, or runs the full CI suite on the release commit when no run proved that tree. Then it tags the release commit 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
- 4. If GitHub Actions does not run because of billing, the local gate is the evidence. Say so once in the PR body.
6
+ 4. Pull requests start no hosted CI. The release workflow runs the full CI suite on the release commit before it tags the release.
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.
@@ -10,6 +10,6 @@ For a writer reply:
10
10
 
11
11
  1. Read the diff on the reported branch: `git diff <base>...<branch>`.
12
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`).
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.
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. Never run the repository's heavy gate; it runs only before a release. Run the changed functionality on the real system and see it work. A docs-only unit needs no build or test run.
14
14
  4. If something is wrong, fix it yourself on the same branch. Check out the kept branch in a repo-local `.worktrees/` worktree, fix the cause, and run the failed check again. The finished writer is closed, so its context is gone. If the user asks for a worker to make the fix, add a follow-up `writer` unit with the specific defect and start it on the same branch: `spawn {unit: {id}, branch: <same branch>}`.
15
15
  5. When the unit is accepted, mark its todo done with the evidence: the SHA, the command, and the result.