@abhishek944/pi-tasks 0.15.0 → 0.17.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 +63 -14
- package/dist/agents/delegation.d.ts +4 -0
- package/dist/agents/delegation.js +130 -0
- package/dist/agents/herdr.d.ts +10 -3
- package/dist/agents/herdr.js +39 -12
- package/dist/agents/links.d.ts +3 -3
- package/dist/agents/links.js +42 -19
- package/dist/auto-continue.js +409 -33
- package/dist/blocked.d.ts +29 -0
- package/dist/blocked.js +100 -0
- package/dist/command.d.ts +2 -2
- package/dist/command.js +7 -3
- package/dist/delegated-time.d.ts +12 -1
- package/dist/delegated-time.js +96 -15
- package/dist/dependency.d.ts +7 -0
- package/dist/dependency.js +13 -0
- package/dist/durable.d.ts +42 -0
- package/dist/durable.js +577 -0
- package/dist/herdr-header.d.ts +3 -0
- package/dist/herdr-header.js +100 -0
- package/dist/herdr-panel.d.ts +15 -0
- package/dist/herdr-panel.js +219 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -56
- package/dist/markdown.js +3 -1
- package/dist/panel-settings.d.ts +11 -0
- package/dist/panel-settings.js +30 -0
- package/dist/progress.js +1 -1
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.js +166 -0
- package/dist/state.d.ts +43 -18
- package/dist/state.js +581 -289
- package/dist/thoughts.d.ts +11 -0
- package/dist/thoughts.js +14 -0
- package/dist/timing.js +9 -2
- package/dist/tools.js +295 -34
- package/dist/tracking.js +25 -13
- package/dist/transition.d.ts +9 -0
- package/dist/transition.js +26 -0
- package/dist/types.d.ts +76 -3
- package/dist/ui/panel.js +38 -19
- package/dist/ui/task-view.d.ts +7 -0
- package/dist/ui/task-view.js +10 -0
- package/dist/ui/works-dashboard.js +37 -19
- package/docs/REFERENCE.md +85 -31
- package/docs/USAGE_GUIDE.md +129 -55
- package/herdr/pi-tasks/README.md +46 -0
- package/herdr/pi-tasks/header.js +212 -0
- package/herdr/pi-tasks/main.js +488 -0
- package/herdr/pi-tasks/mod.json +3 -0
- package/herdr/pi-tasks/spinner.svg +1 -0
- package/package.json +26 -1
- package/dist/agents/tools.d.ts +0 -3
- package/dist/agents/tools.js +0 -143
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { app, object } from "./agents/herdr.js";
|
|
4
|
+
const HEADER = "pi-tasks-pane-header";
|
|
5
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
6
|
+
function frames(value) {
|
|
7
|
+
const node = object(value);
|
|
8
|
+
if (!node)
|
|
9
|
+
return [];
|
|
10
|
+
const content = object(node.content);
|
|
11
|
+
const pane = content?.tab === "active" ? object(content.pane) : undefined;
|
|
12
|
+
return [...(pane ? [pane] : []), ...(Array.isArray(node.children) ? node.children.flatMap(frames) : [])];
|
|
13
|
+
}
|
|
14
|
+
async function exists(path) {
|
|
15
|
+
try {
|
|
16
|
+
await access(path);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error.code === "ENOENT")
|
|
21
|
+
return false;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The native header belongs to the layout, not the content mod. Preserve originals. */
|
|
26
|
+
export async function ensureHerdrTasksHeader(ctx, home) {
|
|
27
|
+
const status = await app(["status"], ctx.cwd, ctx.signal);
|
|
28
|
+
const name = status.layout;
|
|
29
|
+
if (typeof name !== "string" || !NAME.test(name))
|
|
30
|
+
throw new Error("Herdr returned no usable current layout.");
|
|
31
|
+
const current = JSON.parse(await readFile(join(home, "layouts", `${name}.json`), "utf8"));
|
|
32
|
+
const panes = frames(current);
|
|
33
|
+
if (!panes.length)
|
|
34
|
+
throw new Error("This Herdr layout has no framed active-tab pane. Use a layout with a visible top pane header for Tasks.");
|
|
35
|
+
const headers = panes.map((pane) => object(pane.header));
|
|
36
|
+
if (headers.some((header) => !header || (header.position ?? "top") !== "top" || header.reveal === "hover")) {
|
|
37
|
+
throw new Error("Tasks needs an always-visible top pane header. This layout has an absent, hidden, or bottom header; it has not been changed.");
|
|
38
|
+
}
|
|
39
|
+
const names = headers.map((header) => object(header?.content)?.mod);
|
|
40
|
+
if (names.every((value) => value === HEADER)) {
|
|
41
|
+
if (headers.some((header) => typeof header?.height !== "number" || header.height < 32)) {
|
|
42
|
+
throw new Error("The personal Tasks header must be at least 32px high. Its layout was preserved; adjust it before opening Tasks.");
|
|
43
|
+
}
|
|
44
|
+
await access(join(home, "mods", HEADER, "main.js"));
|
|
45
|
+
await access(join(home, "mods", HEADER, "base.js"));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const source = names[0];
|
|
49
|
+
if (typeof source !== "string" || !NAME.test(source) || names.some((value) => value !== source)) {
|
|
50
|
+
throw new Error("Tasks cannot safely adapt this layout's mixed or unsupported pane headers. Its files have not been changed.");
|
|
51
|
+
}
|
|
52
|
+
const destination = `pi-tasks-${name}`;
|
|
53
|
+
const layoutFile = join(home, "layouts", `${destination}.json`);
|
|
54
|
+
const headerDirectory = join(home, "mods", HEADER);
|
|
55
|
+
if (await exists(layoutFile)) {
|
|
56
|
+
const saved = JSON.parse(await readFile(layoutFile, "utf8"));
|
|
57
|
+
const savedFrames = frames(saved);
|
|
58
|
+
if (!savedFrames.length || savedFrames.some((pane) => {
|
|
59
|
+
const header = object(pane.header);
|
|
60
|
+
return object(header?.content)?.mod !== HEADER || (header?.position ?? "top") !== "top"
|
|
61
|
+
|| header?.reveal === "hover" || typeof header?.height !== "number" || header.height < 32;
|
|
62
|
+
})) {
|
|
63
|
+
throw new Error(`The existing personal ${destination} layout is incompatible with the Tasks top/always/32px header. It was preserved; adjust or rename it before opening Tasks.`);
|
|
64
|
+
}
|
|
65
|
+
await access(join(headerDirectory, "main.js"));
|
|
66
|
+
await access(join(headerDirectory, "base.js"));
|
|
67
|
+
await app(["do", "layout.switch", JSON.stringify({ name: destination })], ctx.cwd, ctx.signal);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (await exists(headerDirectory)) {
|
|
71
|
+
const manifest = object(JSON.parse(await readFile(join(headerDirectory, "mod.json"), "utf8")));
|
|
72
|
+
if (object(manifest?.cloned_from)?.name !== source || !await exists(join(headerDirectory, "base.js"))) {
|
|
73
|
+
throw new Error(`The personal ${HEADER} mod already exists or is incomplete. It was preserved; resolve that conflict before opening Tasks.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Clone commands are structural writes. Never retry an uncertain outcome.
|
|
78
|
+
await app(["do", "mod.clone", JSON.stringify({ name: source, as: HEADER })], ctx.cwd, ctx.signal);
|
|
79
|
+
const base = await readFile(join(headerDirectory, "main.js"));
|
|
80
|
+
await writeFile(join(headerDirectory, "base.js"), base, { flag: "wx" });
|
|
81
|
+
const adapter = await readFile(new URL("../herdr/pi-tasks/header.js", import.meta.url));
|
|
82
|
+
await writeFile(join(headerDirectory, "main.js"), adapter);
|
|
83
|
+
const manifest = object(JSON.parse(await readFile(join(headerDirectory, "mod.json"), "utf8")));
|
|
84
|
+
if (!manifest)
|
|
85
|
+
throw new Error("The cloned header manifest is invalid; its original files remain intact.");
|
|
86
|
+
await writeFile(join(headerDirectory, "mod.json"), `${JSON.stringify({ ...manifest, pi_activity_header: 1 }, null, 2)}\n`);
|
|
87
|
+
}
|
|
88
|
+
await app(["do", "layout.clone", JSON.stringify({ name, as: destination })], ctx.cwd, ctx.signal);
|
|
89
|
+
const clone = JSON.parse(await readFile(layoutFile, "utf8"));
|
|
90
|
+
for (const pane of frames(clone)) {
|
|
91
|
+
const header = object(pane.header);
|
|
92
|
+
const content = object(header?.content);
|
|
93
|
+
if (!header || !content || content.mod !== source)
|
|
94
|
+
throw new Error("The new layout's pane header changed during setup. Its original layout remains intact.");
|
|
95
|
+
content.mod = HEADER;
|
|
96
|
+
// The existing 30px host header needs 32px for the requested close hit target.
|
|
97
|
+
header.height = Math.max(typeof header.height === "number" ? header.height : 30, 32);
|
|
98
|
+
}
|
|
99
|
+
await app(["do", "layout.set", JSON.stringify({ layout: clone })], ctx.cwd, ctx.signal);
|
|
100
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
export interface HerdrTasksModStatus {
|
|
3
|
+
/** Assets written because the mods folder had none. */
|
|
4
|
+
installed: string[];
|
|
5
|
+
/** Assets replaced because the installed copy differed from this package's version. */
|
|
6
|
+
refreshed: string[];
|
|
7
|
+
/** Timestamped copies of the replaced files, kept beside them. */
|
|
8
|
+
backups: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface HerdrTasksPaneOptions {
|
|
11
|
+
/** Close this terminal's Tasks pane from an earlier session before opening the current one. */
|
|
12
|
+
replaceStale?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Show beside this terminal, or hide only its same-session Tasks mod panes. */
|
|
15
|
+
export declare function setHerdrTasksPaneVisible(ctx: ExtensionContext, visible: boolean, snapshot: string, openCommand?: string[], options?: HerdrTasksPaneOptions): Promise<HerdrTasksModStatus | null>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
5
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
+
import { app, hc, object, TERMINAL_ID } from "./agents/herdr.js";
|
|
7
|
+
import { ensureHerdrTasksHeader } from "./herdr-header.js";
|
|
8
|
+
import { readSnapshot } from "./snapshot.js";
|
|
9
|
+
/** Replace a watched file in one step, so a concurrent mod read cannot see a half-written viewer. */
|
|
10
|
+
async function writeAtomic(destination, contents) {
|
|
11
|
+
const temporary = `${destination}.tmp-${process.pid}-${Date.now()}`;
|
|
12
|
+
await writeFile(temporary, contents, { flag: "wx" });
|
|
13
|
+
try {
|
|
14
|
+
await rename(temporary, destination);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
await unlink(temporary).catch(() => { });
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Keep the shipped viewer in step with this package's snapshot contract. The pane is a read-only
|
|
23
|
+
* viewer of records this package writes, so a viewer from another package version can reject
|
|
24
|
+
* records it does not know: a differing copy is kept as a timestamped backup and replaced, while
|
|
25
|
+
* an identical copy is never rewritten. The personal header mod is a separate, cloned mod.
|
|
26
|
+
*/
|
|
27
|
+
async function installBundledMod(appHome) {
|
|
28
|
+
const assets = await Promise.all(["README.md", "main.js", "mod.json", "spinner.svg"].map(async (name) => ({
|
|
29
|
+
name, contents: await readFile(new URL(`../herdr/pi-tasks/${name}`, import.meta.url)),
|
|
30
|
+
})));
|
|
31
|
+
const directory = join(appHome, "mods", "pi-tasks");
|
|
32
|
+
await mkdir(directory, { recursive: true });
|
|
33
|
+
const status = { installed: [], refreshed: [], backups: [] };
|
|
34
|
+
for (const asset of assets) {
|
|
35
|
+
const destination = join(directory, asset.name);
|
|
36
|
+
let current = null;
|
|
37
|
+
try {
|
|
38
|
+
current = await readFile(destination);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code !== "ENOENT")
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
if (current === null) {
|
|
45
|
+
await writeFile(destination, asset.contents, { flag: "wx" });
|
|
46
|
+
status.installed.push(asset.name);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (current.equals(asset.contents))
|
|
50
|
+
continue;
|
|
51
|
+
const backup = `${destination}.bak-${new Date().toISOString().replace(/[:.]/g, "-")}`;
|
|
52
|
+
await writeFile(backup, current, { flag: "wx" });
|
|
53
|
+
status.backups.push(backup);
|
|
54
|
+
await writeAtomic(destination, asset.contents);
|
|
55
|
+
status.refreshed.push(asset.name);
|
|
56
|
+
}
|
|
57
|
+
return status;
|
|
58
|
+
}
|
|
59
|
+
/** Public Core document read only. One connection per deliberate opener, no service. */
|
|
60
|
+
async function readAppDocument(ctx) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const child = spawn("hc", ["connect"], { cwd: ctx.cwd, signal: ctx.signal, stdio: ["pipe", "pipe", "pipe"] });
|
|
63
|
+
let output = "";
|
|
64
|
+
const timer = setTimeout(() => finish(new Error("Core pane inventory timed out.")), 10_000);
|
|
65
|
+
let settled = false;
|
|
66
|
+
function finish(error, value) {
|
|
67
|
+
if (settled)
|
|
68
|
+
return;
|
|
69
|
+
settled = true;
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
child.kill();
|
|
72
|
+
if (error)
|
|
73
|
+
reject(error);
|
|
74
|
+
else
|
|
75
|
+
resolve(value);
|
|
76
|
+
}
|
|
77
|
+
child.on("error", (error) => finish(error));
|
|
78
|
+
child.on("close", () => { if (!settled)
|
|
79
|
+
finish(new Error("Core closed before returning its pane inventory.")); });
|
|
80
|
+
child.stdin.on("error", (error) => finish(error));
|
|
81
|
+
child.stderr.resume();
|
|
82
|
+
child.stdout.setEncoding("utf8");
|
|
83
|
+
child.stdout.on("data", (chunk) => {
|
|
84
|
+
output += chunk;
|
|
85
|
+
if (output.length > 2 * 1024 * 1024) {
|
|
86
|
+
finish(new Error("Core pane inventory is too large."));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const end = output.indexOf("\n");
|
|
90
|
+
if (end < 0)
|
|
91
|
+
return;
|
|
92
|
+
try {
|
|
93
|
+
const reply = object(JSON.parse(output.slice(0, end)));
|
|
94
|
+
const value = object(object(reply?.result)?.value);
|
|
95
|
+
if (reply?.id !== "activity-pane-read" || !value || reply.error)
|
|
96
|
+
throw new Error("Core returned no usable pane inventory.");
|
|
97
|
+
finish(undefined, value);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
finish(error instanceof Error ? error : new Error(String(error)));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: "activity-pane-read", method: "doc.get", params: { name: "herdr-app" } })}\n`);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function blocks(value) {
|
|
107
|
+
const node = object(value);
|
|
108
|
+
if (!node)
|
|
109
|
+
return [];
|
|
110
|
+
return [...(node.type === "block" ? [node] : []), ...(Array.isArray(node.children) ? node.children.flatMap(blocks) : [])];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A pane's content copy cannot name its own pane: Herdr passes a pane header `{pane, terminal}`
|
|
114
|
+
* but a content mod only the props it was created with. The Tasks status filter is view state
|
|
115
|
+
* keyed by that pane id, so this opener, which knows both ids, publishes the hosting pane beside
|
|
116
|
+
* the session task file. The view reads it and stays unfiltered while it is absent.
|
|
117
|
+
*/
|
|
118
|
+
function tasksPaneFile(snapshot) {
|
|
119
|
+
return snapshot.endsWith(".json") ? `${snapshot.slice(0, -5)}.pane` : `${snapshot}.pane`;
|
|
120
|
+
}
|
|
121
|
+
async function publishTasksPane(snapshot, pane) {
|
|
122
|
+
const path = tasksPaneFile(snapshot);
|
|
123
|
+
await mkdir(dirname(path), { recursive: true });
|
|
124
|
+
await writeFile(path, `${pane}\n`);
|
|
125
|
+
}
|
|
126
|
+
/** Show beside this terminal, or hide only its same-session Tasks mod panes. */
|
|
127
|
+
export async function setHerdrTasksPaneVisible(ctx, visible, snapshot, openCommand = ["cursor"], options = {}) {
|
|
128
|
+
if (visible && (typeof snapshot !== "string" || !isAbsolute(snapshot))) {
|
|
129
|
+
throw new Error("This Pi instance has no session task snapshot binding. Restart Pi, resume this session, then run /works herdr-on again.");
|
|
130
|
+
}
|
|
131
|
+
if (visible && !readSnapshot(snapshot, ctx.sessionManager.getSessionId())) {
|
|
132
|
+
throw new Error("This session's task snapshot is missing. Restart/resume Pi to initialize session task storage, or restore the missing task file, before opening Herdr Tasks.");
|
|
133
|
+
}
|
|
134
|
+
const terminal = process.env.HC_TERMINAL_ID;
|
|
135
|
+
if (!terminal || !TERMINAL_ID.test(terminal))
|
|
136
|
+
throw new Error("Open this Pi session in Herdr Core before opening its Tasks pane.");
|
|
137
|
+
const current = await hc(["get", terminal], ctx.cwd, ctx.signal);
|
|
138
|
+
if (current.address !== terminal || current.state !== "live")
|
|
139
|
+
throw new Error("The originating Core terminal is not live.");
|
|
140
|
+
const appHome = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "herdr-app");
|
|
141
|
+
const inventory = await app(["ls"], ctx.cwd, ctx.signal);
|
|
142
|
+
const document = await readAppDocument(ctx);
|
|
143
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
144
|
+
for (const rawSpace of Array.isArray(inventory.spaces) ? inventory.spaces : []) {
|
|
145
|
+
const space = object(rawSpace);
|
|
146
|
+
for (const rawTab of Array.isArray(space?.tabs) ? space.tabs : []) {
|
|
147
|
+
const tab = object(rawTab);
|
|
148
|
+
for (const rawTerminal of Array.isArray(tab?.terminals) ? tab.terminals : []) {
|
|
149
|
+
const item = object(rawTerminal);
|
|
150
|
+
if (item?.terminal !== terminal || typeof item.pane !== "string")
|
|
151
|
+
continue;
|
|
152
|
+
if (space?.machine)
|
|
153
|
+
throw new Error("The file-backed Tasks pane currently supports local Herdr sessions only.");
|
|
154
|
+
const documentSpace = (Array.isArray(document.spaces) ? document.spaces : []).map(object).find((entry) => entry?.id === space?.id);
|
|
155
|
+
const documentTab = (Array.isArray(documentSpace?.tabs) ? documentSpace.tabs : []).map(object).find((entry) => entry?.id === tab?.id);
|
|
156
|
+
const panes = blocks(documentTab?.root);
|
|
157
|
+
if (!panes.some((pane) => pane.id === item.pane && object(pane.content)?.terminal === terminal)) {
|
|
158
|
+
throw new Error("The source terminal pane changed. Retry opening Tasks from this session.");
|
|
159
|
+
}
|
|
160
|
+
const matches = (pane, mod) => {
|
|
161
|
+
const content = object(pane.content);
|
|
162
|
+
const binding = object(content?.props);
|
|
163
|
+
return typeof pane.id === "string" && content?.terminal == null && content?.mod === mod && binding?.sessionId === sessionId && binding.terminal === terminal;
|
|
164
|
+
};
|
|
165
|
+
const existing = panes.filter((pane) => matches(pane, "pi-tasks"));
|
|
166
|
+
if (!visible) {
|
|
167
|
+
for (const pane of existing)
|
|
168
|
+
await app(["do", "pane.close", JSON.stringify({ pane: pane.id })], ctx.cwd, ctx.signal);
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const status = await installBundledMod(appHome);
|
|
172
|
+
// A fresh pane loads the mod code it finds, so a viewer this call refreshed needs a new
|
|
173
|
+
// pane; focusing the old one would keep rendering the replaced contract.
|
|
174
|
+
if (existing.length && !status.refreshed.length) {
|
|
175
|
+
const pane = existing[0];
|
|
176
|
+
if (typeof pane.id !== "string")
|
|
177
|
+
throw new Error("The existing Tasks pane has no pane ID.");
|
|
178
|
+
await app(["do", "pane.focus", JSON.stringify({ pane: pane.id })], ctx.cwd, ctx.signal);
|
|
179
|
+
await publishTasksPane(snapshot, pane.id);
|
|
180
|
+
return status;
|
|
181
|
+
}
|
|
182
|
+
for (const pane of existing)
|
|
183
|
+
await app(["do", "pane.close", JSON.stringify({ pane: pane.id })], ctx.cwd, ctx.signal);
|
|
184
|
+
if (options.replaceStale) {
|
|
185
|
+
for (const pane of panes) {
|
|
186
|
+
const content = object(pane.content);
|
|
187
|
+
const binding = object(content?.props);
|
|
188
|
+
if (typeof pane.id === "string" && content?.terminal == null && content?.mod === "pi-tasks"
|
|
189
|
+
&& binding?.terminal === terminal && binding.sessionId !== sessionId) {
|
|
190
|
+
await app(["do", "pane.close", JSON.stringify({ pane: pane.id })], ctx.cwd, ctx.signal);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const activity = panes.find((pane) => matches(pane, "pi-loop-monitor"));
|
|
195
|
+
await ensureHerdrTasksHeader(ctx, appHome);
|
|
196
|
+
const args = ["do", "pane.split", JSON.stringify({ pane: activity?.id ?? item.pane, direction: activity ? "down" : "right", mod: "pi-tasks", props: { sessionId: ctx.sessionManager.getSessionId(), snapshot, terminal, openCommand, paneFile: tasksPaneFile(snapshot) } })];
|
|
197
|
+
let result;
|
|
198
|
+
try {
|
|
199
|
+
result = await app(args, ctx.cwd, ctx.signal);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
const failure = object(error);
|
|
203
|
+
const message = [error instanceof Error ? error.message : "", failure?.stdout, failure?.stderr].filter((part) => typeof part === "string").join("\n");
|
|
204
|
+
// Herdr discovers new folders asynchronously. This exact rejection
|
|
205
|
+
// happens before pane creation, so one discovery retry cannot duplicate it.
|
|
206
|
+
if (!message.includes('no mod "pi-tasks" in mods/') && !message.includes('no mod \\"pi-tasks\\" in mods/'))
|
|
207
|
+
throw error;
|
|
208
|
+
await delay(1_000, undefined, { signal: ctx.signal });
|
|
209
|
+
result = await app(args, ctx.cwd, ctx.signal);
|
|
210
|
+
}
|
|
211
|
+
if (typeof result.pane !== "string")
|
|
212
|
+
throw new Error("Herdr did not return a Tasks pane ID.");
|
|
213
|
+
await publishTasksPane(snapshot, result.pane);
|
|
214
|
+
return status;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
throw new Error("This Pi terminal has no pane in the running Herdr app. Open its terminal tab first.");
|
|
219
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Session-scoped work and todo tracking for Pi. */
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
export default function tasksExtension(pi: ExtensionAPI): void;
|
|
4
|
-
export type { DelegatedTime, Todo, TodoStatus, Work, WorkWithTodos } from "./types.js";
|
|
4
|
+
export type { CloseoutAttempt, DelegatedTime, TaskGoal, Todo, TodoStatus, Work, WorkWithTodos } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/** Session-scoped work and todo tracking for Pi. */
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { registerDelegationBridge } from "./agents/delegation.js";
|
|
4
|
+
import { delegateLink, focusTerminal } from "./agents/links.js";
|
|
3
5
|
import { registerTaskAutoContinue } from "./auto-continue.js";
|
|
6
|
+
import { blockedAuditPrompt } from "./blocked.js";
|
|
4
7
|
import { registerWorksCommand } from "./command.js";
|
|
5
8
|
import { registerDelegatedTimeTools } from "./delegated-time.js";
|
|
6
9
|
import { GitStatusCache } from "./git-status.js";
|
|
10
|
+
import { setHerdrTasksPaneVisible } from "./herdr-panel.js";
|
|
7
11
|
import { openRepository, openSession, readOpenCommand } from "./open-repository.js";
|
|
12
|
+
import { readHerdrPanelSettings, readPanelSettings } from "./panel-settings.js";
|
|
8
13
|
import { TaskState } from "./state.js";
|
|
9
14
|
import { safeSingleLine } from "./text.js";
|
|
10
15
|
import { registerTaskTiming } from "./timing.js";
|
|
@@ -15,74 +20,138 @@ export default function tasksExtension(pi) {
|
|
|
15
20
|
let panel;
|
|
16
21
|
const state = new TaskState(pi, () => panel?.update());
|
|
17
22
|
const git = new GitStatusCache();
|
|
18
|
-
const
|
|
23
|
+
const getSettings = () => pi.getSettings?.();
|
|
24
|
+
const getOpenCommand = () => readOpenCommand(getSettings());
|
|
25
|
+
let visibleMode = "floating";
|
|
19
26
|
panel = new TasksPanelHost(state, git, getOpenCommand);
|
|
27
|
+
// A refreshed viewer is a package upgrade, not a failure; keep the replaced files findable.
|
|
28
|
+
const notifyModRefresh = (ctx, status) => {
|
|
29
|
+
if (!status?.backups.length)
|
|
30
|
+
return;
|
|
31
|
+
ctx.ui.notify(`Refreshed the installed Herdr Tasks mod for this pi-tasks version. Previous files: ${status.backups.map((path) => basename(path)).join(", ")}.`, "info");
|
|
32
|
+
};
|
|
33
|
+
async function openHerdrTasksPaneOnStart(ctx) {
|
|
34
|
+
if (!process.env.HC_TERMINAL_ID)
|
|
35
|
+
return;
|
|
36
|
+
let enabled;
|
|
37
|
+
try {
|
|
38
|
+
enabled = readHerdrPanelSettings(getSettings()).enabled;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
ctx.ui.notify(error instanceof Error ? error.message : "Invalid Herdr panel settings.", "error");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!enabled)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const status = await setHerdrTasksPaneVisible(ctx, true, state.snapshotPath, getOpenCommand(), { replaceStale: true });
|
|
48
|
+
notifyModRefresh(ctx, status);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// The native pane is an optional display; /works herdr-on reports the reason.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
20
54
|
registerTaskTools(pi, state);
|
|
21
55
|
registerDelegatedTimeTools(pi, state);
|
|
22
56
|
registerTaskTiming(pi, state);
|
|
23
|
-
|
|
57
|
+
registerDelegationBridge(pi, state);
|
|
24
58
|
registerTrackingGuidance(pi);
|
|
25
59
|
registerTaskAutoContinue(pi, state);
|
|
26
|
-
registerWorksCommand(pi, state, git, getOpenCommand)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const todo = state.getTodo(delegateTask);
|
|
34
|
-
const link = todo ? delegateLink(todo.taskInfo) : undefined;
|
|
35
|
-
if (!link) {
|
|
36
|
-
ctx.ui.notify("This task has no Herdr delegate link, or Pi is not running inside Herdr.", "warning");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
await focusPane(link.paneId, ctx.cwd);
|
|
41
|
-
ctx.ui.notify("Opened delegated agent in Herdr.", "info");
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
const reason = error instanceof Error ? safeSingleLine(error.message) : "Unknown error.";
|
|
45
|
-
ctx.ui.notify(`Could not open delegate. ${reason}`, "error");
|
|
46
|
-
}
|
|
47
|
-
return;
|
|
60
|
+
registerWorksCommand(pi, state, git, getOpenCommand, async (requested, ctx) => {
|
|
61
|
+
if (requested === "herdr-on" || requested === "herdr-off") {
|
|
62
|
+
try {
|
|
63
|
+
const visible = requested === "herdr-on";
|
|
64
|
+
const status = await setHerdrTasksPaneVisible(ctx, visible, visible ? state.snapshotPath : "", visible ? getOpenCommand() : undefined);
|
|
65
|
+
ctx.ui.notify(visible ? "Opened the Herdr Tasks pane." : "Closed this session’s Herdr Tasks pane.", "info");
|
|
66
|
+
notifyModRefresh(ctx, status);
|
|
48
67
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const command = getOpenCommand();
|
|
52
|
-
if (requested === "open-session")
|
|
53
|
-
await openSession(ctx.cwd, ctx.sessionManager.getSessionId(), command);
|
|
54
|
-
else
|
|
55
|
-
await openRepository(ctx.cwd, command);
|
|
56
|
-
ctx.ui.notify(requested === "open-session" ? "Opened session artifacts." : "Opened repository.", "info");
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
const reason = error instanceof Error ? ` ${safeSingleLine(error.message)}` : "";
|
|
60
|
-
ctx.ui.notify(`Could not open directory. Check pi-tasks.openCommand and that its executable is installed on PATH.${reason}`, "error");
|
|
61
|
-
}
|
|
62
|
-
return;
|
|
68
|
+
catch (error) {
|
|
69
|
+
ctx.ui.notify(error instanceof Error ? safeSingleLine(error.message) : "Could not change the Herdr Tasks pane visibility.", "error");
|
|
63
70
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const delegateTask = /^delegate\s+(T\d+)$/.exec(requested)?.[1];
|
|
74
|
+
if (delegateTask) {
|
|
75
|
+
const todo = state.getTodo(delegateTask);
|
|
76
|
+
const link = todo ? delegateLink(todo.taskInfo) : undefined;
|
|
77
|
+
if (!link) {
|
|
78
|
+
ctx.ui.notify("This task has no valid Core delegate terminal link.", "warning");
|
|
67
79
|
return;
|
|
68
80
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
ctx.ui.notify("
|
|
72
|
-
|
|
81
|
+
try {
|
|
82
|
+
await focusTerminal(link.terminalId, ctx.cwd);
|
|
83
|
+
ctx.ui.notify("Opened delegated agent in Herdr.", "info");
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const reason = error instanceof Error ? safeSingleLine(error.message) : "Unknown error.";
|
|
87
|
+
ctx.ui.notify(`Could not open delegate. ${reason}`, "error");
|
|
73
88
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (requested === "open" || requested === "open-session") {
|
|
92
|
+
try {
|
|
93
|
+
const command = getOpenCommand();
|
|
94
|
+
if (requested === "open-session")
|
|
95
|
+
await openSession(ctx.cwd, ctx.sessionManager.getSessionId(), command);
|
|
96
|
+
else
|
|
97
|
+
await openRepository(ctx.cwd, command);
|
|
98
|
+
ctx.ui.notify(requested === "open-session" ? "Opened session artifacts." : "Opened repository.", "info");
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const reason = error instanceof Error ? ` ${safeSingleLine(error.message)}` : "";
|
|
102
|
+
ctx.ui.notify(`Could not open directory. Check pi-tasks.openCommand and that its executable is installed on PATH.${reason}`, "error");
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (requested === "minimize" || requested === "maximize") {
|
|
107
|
+
panel?.setMinimized(requested === "minimize");
|
|
108
|
+
ctx.ui.notify(`Works panel: ${requested}d`, "info");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const mode = requested === "compact-on" ? visibleMode : requested === "compact-off" ? "off" : requested === "floating" || requested === "widget" ? requested : undefined;
|
|
112
|
+
if (!mode) {
|
|
113
|
+
ctx.ui.notify("Usage: /works [compact-on|compact-off|herdr-on|herdr-off|floating|widget|minimize|maximize|open|open-session] or /works delegate T<number>", "info");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (mode !== "off")
|
|
117
|
+
visibleMode = mode;
|
|
118
|
+
panel?.setMode(mode);
|
|
119
|
+
ctx.ui.notify(`Works compact display: ${mode}`, "info");
|
|
77
120
|
});
|
|
78
|
-
pi.on("session_start", (
|
|
79
|
-
state.restore(ctx);
|
|
121
|
+
pi.on("session_start", async (event, ctx) => {
|
|
122
|
+
state.restore(ctx, event.reason === "fork");
|
|
80
123
|
git.setCwd(ctx.cwd);
|
|
81
|
-
|
|
124
|
+
try {
|
|
125
|
+
const settings = readPanelSettings(getSettings());
|
|
126
|
+
visibleMode = settings.mode;
|
|
127
|
+
panel?.setMode(settings.enabled ? visibleMode : "off");
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
panel?.setMode("off");
|
|
131
|
+
ctx.ui.notify(error instanceof Error ? error.message : "Invalid task panel settings.", "error");
|
|
132
|
+
}
|
|
133
|
+
if (ctx.mode === "tui") {
|
|
82
134
|
panel?.attach(ctx.ui, ctx.cwd, ctx.sessionManager.getSessionId());
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
135
|
+
await openHerdrTasksPaneOnStart(ctx);
|
|
136
|
+
}
|
|
137
|
+
// A reload/restart stops decision watchers and agent monitors. Surface every
|
|
138
|
+
// blocked record once for any restored start (startup, /reload, resume) so a
|
|
139
|
+
// stale blocker cannot survive silently. A fresh fork keeps its isolation; a
|
|
140
|
+
// new session has no inherited store. This audit changes nothing itself.
|
|
141
|
+
if (event.reason === "startup" || event.reason === "reload" || event.reason === "resume") {
|
|
142
|
+
const audit = blockedAuditPrompt(state.listTodos({ status: "blocked" }));
|
|
143
|
+
if (audit) {
|
|
144
|
+
pi.sendMessage({
|
|
145
|
+
customType: "pi-tasks-review",
|
|
146
|
+
content: [
|
|
147
|
+
"[pi-tasks] Session-start blocked-task audit after a resume. No task status was changed; reloads and session switches stop decision watchers and agent monitors, so a retained blocker may no longer have a live wake.",
|
|
148
|
+
audit,
|
|
149
|
+
"If a linked decision page is still needed, call WaitForAnswer once to re-arm its watcher. If it is superseded, withdraw it and update every linked task in the same turn. Do not clear a genuine blocker or change a task merely to end this audit.",
|
|
150
|
+
].join("\n\n"),
|
|
151
|
+
display: true,
|
|
152
|
+
}, { triggerTurn: true, deliverAs: "followUp" });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
86
155
|
});
|
|
87
156
|
pi.on("tool_result", (event) => {
|
|
88
157
|
if (event.toolName === "write" || event.toolName === "edit" || event.toolName === "bash")
|
package/dist/markdown.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { dependentOnLabel } from "./dependency.js";
|
|
1
2
|
import { formatCompletion, taskCompletion, workCompletion } from "./progress.js";
|
|
2
3
|
import { safeMultiline, safeSingleLine } from "./text.js";
|
|
4
|
+
import { finalThoughtsFor } from "./thoughts.js";
|
|
3
5
|
import { formatTime, taskTime, workTime } from "./time.js";
|
|
4
6
|
export function formatWorksMarkdown(works) {
|
|
5
7
|
const lines = ["# Works and Todos", ""];
|
|
@@ -12,7 +14,7 @@ export function formatWorksMarkdown(works) {
|
|
|
12
14
|
continue;
|
|
13
15
|
}
|
|
14
16
|
for (const todo of work.tasks) {
|
|
15
|
-
lines.push(`#### ${todo.taskId} — ${escapeMarkdownInline(safeSingleLine(todo.taskName))}`, "", `**Status:** ${todo.status}`,
|
|
17
|
+
lines.push(`#### ${todo.taskId} — ${escapeMarkdownInline(safeSingleLine(todo.taskName))}`, "", `**Status:** ${todo.status}`, `**Completion:** ${formatCompletion(taskCompletion(todo))}`, `**Time:** ${formatTime(taskTime(todo))}${todo.workingSince === undefined ? "" : " (running)"}`, "", `**Final thoughts${dependentOnLabel(todo.dependentOn) === undefined ? "" : ` (Dependent on: ${dependentOnLabel(todo.dependentOn)})`}:**`, "", markdownBody(finalThoughtsFor(todo) ?? "No final thoughts recorded."), "");
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
return `${lines.join("\n").trimEnd()}\n`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PanelSettings {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
mode: "floating" | "widget";
|
|
4
|
+
}
|
|
5
|
+
export interface HerdrPanelSettings {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Startup default for the native Herdr Tasks pane; commands still override this running instance. */
|
|
9
|
+
export declare function readHerdrPanelSettings(settings: unknown): HerdrPanelSettings;
|
|
10
|
+
/** Defaults apply on startup/reload; slash commands only override this running instance. */
|
|
11
|
+
export declare function readPanelSettings(settings: unknown): PanelSettings;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Startup default for the native Herdr Tasks pane; commands still override this running instance. */
|
|
2
|
+
export function readHerdrPanelSettings(settings) {
|
|
3
|
+
const root = object(settings);
|
|
4
|
+
const config = object(root?.["pi-tasks"]);
|
|
5
|
+
const raw = config?.herdrPanel;
|
|
6
|
+
if (raw === undefined)
|
|
7
|
+
return { enabled: false };
|
|
8
|
+
const panel = object(raw);
|
|
9
|
+
if (!panel || (panel.enabled !== undefined && typeof panel.enabled !== "boolean")) {
|
|
10
|
+
throw new Error("pi-tasks.herdrPanel must contain an optional boolean enabled field.");
|
|
11
|
+
}
|
|
12
|
+
return { enabled: panel.enabled === true };
|
|
13
|
+
}
|
|
14
|
+
/** Defaults apply on startup/reload; slash commands only override this running instance. */
|
|
15
|
+
export function readPanelSettings(settings) {
|
|
16
|
+
const root = object(settings);
|
|
17
|
+
const config = object(root?.["pi-tasks"]);
|
|
18
|
+
const raw = config?.panel;
|
|
19
|
+
if (raw === undefined)
|
|
20
|
+
return { enabled: false, mode: "floating" };
|
|
21
|
+
const panel = object(raw);
|
|
22
|
+
if (!panel || (panel.enabled !== undefined && typeof panel.enabled !== "boolean")
|
|
23
|
+
|| (panel.mode !== undefined && panel.mode !== "floating" && panel.mode !== "widget")) {
|
|
24
|
+
throw new Error("pi-tasks.panel must contain an optional boolean enabled and mode floating|widget.");
|
|
25
|
+
}
|
|
26
|
+
return { enabled: panel.enabled === true, mode: panel.mode === "widget" ? "widget" : "floating" };
|
|
27
|
+
}
|
|
28
|
+
function object(value) {
|
|
29
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
30
|
+
}
|
package/dist/progress.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function taskCompletion(todo) {
|
|
2
|
-
if (todo.status === "completed")
|
|
2
|
+
if (todo.status === "completed" || todo.status === "closed")
|
|
3
3
|
return 100;
|
|
4
4
|
const value = todo.completionPercent;
|
|
5
5
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value < 100 ? value : null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Todo, Work } from "./types.js";
|
|
2
|
+
/** Shared on-disk contract for Pi and the read-only Herdr mod. */
|
|
3
|
+
export interface TaskSnapshot {
|
|
4
|
+
version: 1;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
terminalId?: string;
|
|
8
|
+
updatedAt: number;
|
|
9
|
+
nextWorkId: number;
|
|
10
|
+
nextTaskId: number;
|
|
11
|
+
works: Work[];
|
|
12
|
+
todos: Todo[];
|
|
13
|
+
agentRunning: boolean;
|
|
14
|
+
focusedTaskId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function taskSnapshotPath(sessionId: string): string;
|
|
17
|
+
export declare function emptySnapshot(sessionId: string, cwd: string): TaskSnapshot;
|
|
18
|
+
/** Reject damaged files rather than silently replacing user task data. */
|
|
19
|
+
export declare function validateSnapshot(value: unknown, sessionId: string): asserts value is TaskSnapshot;
|
|
20
|
+
/** Only ENOENT is an uninitialized store; parse/identity/permission failures propagate. */
|
|
21
|
+
export declare function readSnapshot(path: string, sessionId: string): TaskSnapshot | undefined;
|
|
22
|
+
/** One synchronous Pi writer, atomic replacement; Herdr is a reader only. */
|
|
23
|
+
export declare function writeSnapshot(path: string, snapshot: TaskSnapshot): void;
|