@oisin-ee/pi-dogsled 0.29.3 → 0.31.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 CHANGED
@@ -19,7 +19,7 @@ mise use github:oisin-ee/dogsled@v0.28.0
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.29.3
22
+ pi install npm:@oisin-ee/pi-dogsled@0.31.0
23
23
  ```
24
24
 
25
25
  At session start the extension compares its version with `dogsled --version` and warns when they differ.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oisin-ee/pi-dogsled",
3
- "version": "0.29.3",
3
+ "version": "0.31.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/index.ts CHANGED
@@ -130,10 +130,7 @@ export default function dogsled(pi: ExtensionAPI) {
130
130
 
131
131
  async function publication(ctx: ExtensionContext): Promise<void> {
132
132
  if (!owner) return;
133
- const current = generation;
134
- const location: unknown = JSON.parse(await exec(["board", "--todo-path", "--owner", owner, "--json"]));
135
- if (current !== generation) return;
136
- publisher.configure(location);
133
+ publisher.configure();
137
134
  publishTodos(ctx);
138
135
  }
139
136
 
package/pi/work-todo.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { TodoPresenter, TodoWork } from "./todo/src/work.ts";
2
2
  import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
3
- import { randomUUID } from "node:crypto";
4
- import { rename, rm, writeFile } from "node:fs/promises";
3
+ import { execFile } from "node:child_process";
5
4
 
6
5
  /** The provider owns rendering and state interpretation; this is an in-process capability. */
7
6
  export interface TodoViewHost {
@@ -48,49 +47,54 @@ export interface TodoPayload {
48
47
  sections: readonly TodoSection[];
49
48
  }
50
49
 
51
- /** Atomic per-pane publication into Dogsled's ledger. One ordered writer per Pi session. */
50
+ /** The binary owns typed persistence; Pi only sends the provider's snapshot. */
51
+ type Publish = (pane: string, payload: TodoPayload | undefined) => Promise<void>;
52
+
53
+ function publishCommand(pane: string, payload: TodoPayload | undefined): Promise<void> {
54
+ const args = ["todo-publish", "--pane", pane];
55
+ if (!payload) args.push("--clear");
56
+ return new Promise((resolve, reject) => {
57
+ const child = execFile(process.env["DOGSLED_BIN"] ?? "dogsled", args, (error, _stdout, stderr) => {
58
+ if (error) reject(new Error(`todo publication failed: ${stderr.trim() || error.message}`));
59
+ else resolve();
60
+ });
61
+ child.stdin?.on("error", reject);
62
+ child.stdin?.end(payload ? JSON.stringify(payload) : undefined);
63
+ });
64
+ }
65
+
66
+ /** One ordered publication queue per Pi session. */
52
67
  export class TodoPublisher {
53
- private path: string | undefined;
68
+ private enabled = false;
54
69
  private published: TodoSnapshot | undefined;
55
70
  private queue = Promise.resolve();
56
71
  private readonly pane: string;
57
72
  private readonly failed: (error: unknown) => void;
58
- constructor(pane: string, failed: (error: unknown) => void) { this.pane = pane; this.failed = failed; }
59
-
60
- configure(value: unknown): void {
61
- if (!record(value) || typeof value["path"] !== "string") throw new Error("Invalid todo publication path");
62
- if (this.path !== value["path"]) this.published = undefined;
63
- this.path = value["path"];
73
+ private readonly send: Publish;
74
+ constructor(pane: string, failed: (error: unknown) => void, send: Publish = publishCommand) {
75
+ this.pane = pane; this.failed = failed; this.send = send;
64
76
  }
65
77
 
78
+ configure(): void { this.enabled = true; }
79
+
66
80
  publish(next: TodoSnapshot | undefined): void {
67
- const path = this.path;
68
- if (!path || (next && next === this.published)) return;
81
+ if (!this.enabled || (next && next === this.published)) return;
69
82
  const payload: TodoPayload | undefined = next
70
83
  ? { session: next.session, branch: next.branch, revision: next.revision, current: next.display.current, pane: this.pane, sections: next.display.sections }
71
84
  : undefined;
72
85
  this.published = next;
73
- this.queue = this.queue.then(async () => {
74
- if (!payload) { await rm(path, { force: true }); return; }
75
- const temporary = `${path}.${randomUUID()}.tmp`;
76
- try {
77
- await writeFile(temporary, JSON.stringify(payload), { flag: "wx", mode: 0o600 });
78
- await rename(temporary, path);
79
- } finally { await rm(temporary, { force: true }); }
80
- }).catch(error => { this.published = undefined; this.failed(error); });
86
+ this.queue = this.queue.then(() => this.send(this.pane, payload))
87
+ .catch(error => { this.published = undefined; this.failed(error); });
81
88
  }
82
89
 
83
90
  async clear(): Promise<void> {
84
- const path = this.path;
85
91
  this.published = undefined;
86
- this.queue = this.queue.then(async () => { if (path) await rm(path, { force: true }); }).catch(this.failed);
92
+ this.queue = this.queue.then(async () => { if (this.enabled) await this.send(this.pane, undefined); }).catch(this.failed);
87
93
  await this.queue;
88
94
  }
89
95
  async flushed(): Promise<void> { await this.queue; }
90
96
  }
91
97
 
92
- function record(value: unknown): value is Record<string, unknown> { return typeof value === "object" && value !== null; }
93
-
94
98
  /** A view lease catches provider failures on every path and disposes exactly once. */
95
99
  class HostedTodo implements TodoView {
96
100
  private disposed = false;