@abhishek944/pi-tasks 0.15.0 → 0.16.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 +59 -12
- package/dist/agents/delegation.d.ts +4 -0
- package/dist/agents/delegation.js +59 -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 +160 -27
- package/dist/command.d.ts +2 -2
- package/dist/command.js +7 -3
- package/dist/delegated-time.d.ts +11 -0
- package/dist/delegated-time.js +51 -2
- package/dist/dependency.d.ts +7 -0
- package/dist/dependency.js +13 -0
- package/dist/durable.d.ts +38 -0
- package/dist/durable.js +515 -0
- package/dist/herdr-header.d.ts +3 -0
- package/dist/herdr-header.js +100 -0
- package/dist/herdr-panel.d.ts +7 -0
- package/dist/herdr-panel.js +182 -0
- package/dist/index.js +96 -56
- package/dist/markdown.js +3 -1
- package/dist/panel-settings.d.ts +11 -0
- package/dist/panel-settings.js +30 -0
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.js +123 -0
- package/dist/state.d.ts +21 -18
- package/dist/state.js +357 -286
- package/dist/thoughts.d.ts +11 -0
- package/dist/thoughts.js +14 -0
- package/dist/timing.js +2 -1
- package/dist/tools.js +48 -29
- package/dist/tracking.js +18 -11
- package/dist/types.d.ts +9 -2
- package/dist/ui/panel.js +17 -10
- package/dist/ui/task-view.d.ts +7 -0
- package/dist/ui/task-view.js +10 -0
- package/dist/ui/works-dashboard.js +22 -15
- package/docs/REFERENCE.md +56 -28
- package/docs/USAGE_GUIDE.md +112 -50
- package/herdr/pi-tasks/README.md +45 -0
- package/herdr/pi-tasks/header.js +192 -0
- package/herdr/pi-tasks/main.js +413 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abhishek944/pi-tasks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Session-scoped work and todo tracking for Pi.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/",
|
|
20
|
+
"herdr/pi-tasks/main.js",
|
|
21
|
+
"herdr/pi-tasks/header.js",
|
|
22
|
+
"herdr/pi-tasks/spinner.svg",
|
|
23
|
+
"herdr/pi-tasks/mod.json",
|
|
24
|
+
"herdr/pi-tasks/README.md",
|
|
20
25
|
"docs/USAGE_GUIDE.md",
|
|
21
26
|
"docs/REFERENCE.md",
|
|
22
27
|
"README.md",
|
|
@@ -28,14 +33,25 @@
|
|
|
28
33
|
"import": "./dist/index.js",
|
|
29
34
|
"default": "./dist/index.js"
|
|
30
35
|
},
|
|
36
|
+
"./durable": {
|
|
37
|
+
"types": "./dist/durable.d.ts",
|
|
38
|
+
"import": "./dist/durable.js",
|
|
39
|
+
"default": "./dist/durable.js"
|
|
40
|
+
},
|
|
31
41
|
"./package.json": "./package.json"
|
|
32
42
|
},
|
|
33
43
|
"peerDependencies": {
|
|
34
44
|
"@earendil-works/pi-coding-agent": ">=0.85.1",
|
|
45
|
+
"@earendil-works/pi-durable": "1.1.0",
|
|
35
46
|
"@earendil-works/pi-tui": ">=0.85.1",
|
|
36
47
|
"@earendil-works/pi-ai": "*",
|
|
37
48
|
"typebox": "*"
|
|
38
49
|
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@earendil-works/pi-durable": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
39
55
|
"scripts": {
|
|
40
56
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
41
57
|
"build": "npm run clean && tsc",
|
|
@@ -49,6 +65,7 @@
|
|
|
49
65
|
"@earendil-works/pi-ai": "0.85.1",
|
|
50
66
|
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
51
67
|
"@earendil-works/pi-tui": "0.85.1",
|
|
68
|
+
"@earendil-works/pi-durable": "1.1.0",
|
|
52
69
|
"@types/node": "^26.1.2",
|
|
53
70
|
"typebox": "1.3.16",
|
|
54
71
|
"typescript": "^7.0.2"
|
|
@@ -57,5 +74,13 @@
|
|
|
57
74
|
"extensions": [
|
|
58
75
|
"./dist/index.js"
|
|
59
76
|
]
|
|
77
|
+
},
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "https://github.com/abhishek944/astack.git",
|
|
81
|
+
"directory": "packages/pi-tasks"
|
|
82
|
+
},
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
60
85
|
}
|
|
61
86
|
}
|
package/dist/agents/tools.d.ts
DELETED
package/dist/agents/tools.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import { createTimingReport } from "../delegated-time.js";
|
|
3
|
-
import { taskOwner } from "../ownership.js";
|
|
4
|
-
import { renderTaskCall, renderTaskResult, taskResult } from "../tool-result.js";
|
|
5
|
-
import { areTrackingToolsActive } from "../tracking.js";
|
|
6
|
-
import { herdr, herdrText, object, PANE_ID } from "./herdr.js";
|
|
7
|
-
import { delegateLink, focusPane, withPaneLink } from "./links.js";
|
|
8
|
-
const PaneId = Type.String({ pattern: PANE_ID.source, description: "Actual paneId returned by Herdr, not a pane name." });
|
|
9
|
-
const Target = Type.Object({ paneId: PaneId }, { additionalProperties: false });
|
|
10
|
-
const output = { outputSchema: Type.Object({}, { additionalProperties: true }) };
|
|
11
|
-
const nested = { reachesTools: () => ["MonitorCreate", "MonitorStop"] };
|
|
12
|
-
const mutation = { annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true } };
|
|
13
|
-
const readOnly = { annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } };
|
|
14
|
-
function monitorHost(ctx) {
|
|
15
|
-
const host = ctx;
|
|
16
|
-
if (typeof host.executeTool !== "function" || !["MonitorCreate", "MonitorList", "MonitorStop"].every((name) => host.tools?.some((tool) => tool.name === name))) {
|
|
17
|
-
throw new Error("AgentCreate/Close require modern Pi nested calls and callable pi-loop-monitor tools.");
|
|
18
|
-
}
|
|
19
|
-
return host;
|
|
20
|
-
}
|
|
21
|
-
async function monitor(ctx, name, args, signal) {
|
|
22
|
-
const outcome = object(await monitorHost(ctx).executeTool(name, args, { signal }));
|
|
23
|
-
const details = object(object(outcome?.result)?.details);
|
|
24
|
-
if (outcome?.isError !== false || !details || details.tone === "error")
|
|
25
|
-
throw new Error(`${name} failed. Inspect its tool result.`);
|
|
26
|
-
return details;
|
|
27
|
-
}
|
|
28
|
-
function result(name, data) {
|
|
29
|
-
return { ...taskResult(JSON.stringify(data, null, 2), name, data, `${name}${data.paneId ? ` · ${data.paneId}` : ""}`), structuredContent: data };
|
|
30
|
-
}
|
|
31
|
-
export function registerAgentTools(pi, state) {
|
|
32
|
-
const requireMainWork = () => {
|
|
33
|
-
if (!areTrackingToolsActive(pi))
|
|
34
|
-
throw new Error("Use agent tools in tracked main-conversation work, not /ask or /btw.");
|
|
35
|
-
};
|
|
36
|
-
pi.registerTool({
|
|
37
|
-
name: "AgentCreate", label: "AgentCreate",
|
|
38
|
-
description: "Wrap a timing descriptor, Herdr tab creation, Pi startup and MonitorCreate. Requires an existing canonical taskDir inside repository var/. Returns reportPath, actual paneId/tabId/monitorId and a prepared assignment with timing-export instructions; automatically links the task's delegate badge and marks the parent task blocked while awaiting the worker. Does NOT send work: confirm MonitorList shows subscription ready, then AgentSend the returned assignment. onSignal wakes the parent for worker state changes; optional onDone handles monitor termination, not task completion. No private agent registry, automatic recovery or process checks.",
|
|
39
|
-
promptGuidelines: ["Prefer these agent tools over CLI for supported operations; use Herdr CLI only for missing capabilities.", "Choose explicit provider/model/thinking/Fast through model-routing-policy. Create only authorized agents, never in /ask or /btw.", "After AgentCreate, confirm MonitorList shows the pane subscription ready before AgentSend. Do not add a duplicate monitor. Read actual output/files before completing tasks."],
|
|
40
|
-
parameters: Type.Object({
|
|
41
|
-
workId: Type.String({ pattern: "^W[1-9][0-9]*$" }), taskId: Type.String({ pattern: "^T[1-9][0-9]*$" }),
|
|
42
|
-
taskDir: Type.String({ minLength: 1, description: "Existing canonical parent task artifact directory from implement, inside repository var/. A unique timing descriptor is written here and passed to the worker; no directory is created by this wrapper." }),
|
|
43
|
-
assignment: Type.String({ minLength: 1, maxLength: 32_000 }), provider: Type.String({ minLength: 1 }), model: Type.String({ minLength: 1 }),
|
|
44
|
-
thinking: Type.String({ minLength: 1, description: "Explicit thinking level supported by the chosen model." }),
|
|
45
|
-
fast: Type.Optional(Type.Boolean({ description: "Forward --fast only when requested and supported." })),
|
|
46
|
-
onSignal: Type.String({ minLength: 1, maxLength: 10_000, description: "Instructions waking the parent on worker state changes. The monitor stays subscribed for follow-ups." }),
|
|
47
|
-
onDone: Type.Optional(Type.String({ minLength: 1, maxLength: 10_000, description: "Instructions if the monitor process ends, not when the worker finishes. Omit for MonitorCreate's default recovery instruction." })),
|
|
48
|
-
}, { additionalProperties: false }),
|
|
49
|
-
...output, ...nested, ...mutation, executionMode: "sequential",
|
|
50
|
-
async execute(_id, params, signal, _update, ctx) {
|
|
51
|
-
requireMainWork();
|
|
52
|
-
monitorHost(ctx);
|
|
53
|
-
const todo = state.getTodo(params.taskId);
|
|
54
|
-
if (!todo || todo.workId !== params.workId || taskOwner(todo.taskInfo) !== "delegate")
|
|
55
|
-
throw new Error("Use an existing task in this work with owner: delegate.");
|
|
56
|
-
const reportPath = await createTimingReport(ctx, params.taskDir, params.workId, params.taskId);
|
|
57
|
-
const handles = { reportPath };
|
|
58
|
-
try {
|
|
59
|
-
const current = object((await herdr(["pane", "current"], ctx.cwd, signal)).pane);
|
|
60
|
-
if (typeof current?.workspace_id !== "string")
|
|
61
|
-
throw new Error("Herdr returned no current workspace ID.");
|
|
62
|
-
const created = await herdr(["tab", "create", "--workspace", current.workspace_id, "--cwd", ctx.cwd, "--label", params.taskId, "--no-focus"], ctx.cwd, signal);
|
|
63
|
-
const pane = object(created.root_pane);
|
|
64
|
-
if (typeof pane?.pane_id !== "string" || !PANE_ID.test(pane.pane_id))
|
|
65
|
-
throw new Error(`Herdr returned no root pane ID: ${JSON.stringify(created)}`);
|
|
66
|
-
Object.assign(handles, { paneId: pane.pane_id, tabId: pane.tab_id });
|
|
67
|
-
await herdr(["pane", "rename", pane.pane_id, params.taskId], ctx.cwd, signal);
|
|
68
|
-
const args = ["agent", "start", `task-${params.taskId.toLowerCase()}-${pane.pane_id.replace(":", "-").toLowerCase()}`, "--kind", "pi", "--pane", pane.pane_id,
|
|
69
|
-
"--", "--provider", params.provider, "--model", params.model, "--thinking", params.thinking];
|
|
70
|
-
if (params.fast)
|
|
71
|
-
args.push("--fast");
|
|
72
|
-
await herdr(args, ctx.cwd, signal, 45_000);
|
|
73
|
-
const watched = await monitor(ctx, "MonitorCreate", { herdrPaneId: pane.pane_id, description: `Agent ${params.taskId} (${pane.pane_id})`, timeout: 0,
|
|
74
|
-
onSignal: `${params.onSignal}\nWhen worker output is available, call TaskTimeImport for taskId ${params.taskId} to import measured effort from its timing report. Timing import does not verify or complete the task.`, ...(params.onDone === undefined ? {} : { onDone: params.onDone }) }, signal);
|
|
75
|
-
if (typeof watched.monitorId !== "string")
|
|
76
|
-
throw new Error("Update pi-loop-monitor: MonitorCreate must return details.monitorId.");
|
|
77
|
-
handles.monitorId = watched.monitorId;
|
|
78
|
-
const currentTodo = state.getTodo(params.taskId);
|
|
79
|
-
if (!currentTodo || currentTodo.workId !== params.workId)
|
|
80
|
-
throw new Error("The parent task is no longer available for linking.");
|
|
81
|
-
state.setDelegatedTime(params.taskId, { reportPath, elapsedMs: null });
|
|
82
|
-
state.updateTodo(params.taskId, { status: "blocked", blockedReason: "Waiting for the delegated agent. Resume when its output is available for inspection and verification.", taskInfo: withPaneLink(currentTodo.taskInfo, pane.pane_id, watched.monitorId) });
|
|
83
|
-
const assignment = `Parent session ${ctx.sessionManager.getSessionId()}, work ${params.workId}, task ${params.taskId}. Exact parentTaskDir: ${params.taskDir}. Read global implement and applicable skills. Obtain your own PI_SESSION_ID through your shell, establish your own Work and active Todo using WorkList/TodoList and create/update tools before executing, keep them current, and return your IDs, nested task artifact path, changed files, checks and blockers. Parent IDs are context, not shared records. This handoff grants no additional permissions. Timing reportPath: ${JSON.stringify(reportPath)}. Before returning results, pause or complete every assignment task, import any nested delegates with TaskTimeImport, then call TaskTimeExport with this exact reportPath and all assignment-local taskIds (including cancelled tasks, excluding unrelated work). Never calculate or type durations yourself. After follow-ups, export the cumulative set again to the same reportPath. If export is unavailable or fails, report that limitation; do not hand-write the timing file.\n\n${params.assignment}`;
|
|
84
|
-
return result("AgentCreate", { ...handles, taskDir: params.taskDir, assignment, assignmentSent: false,
|
|
85
|
-
next: "Confirm MonitorList shows subscription ready, then AgentSend this assignment to the returned paneId. After worker output is available, call TaskTimeImport for this task before closing its agent; verify completion separately." });
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
throw new Error(`${error instanceof Error ? error.message : String(error)}. The command may have partially completed. Handles returned so far: ${JSON.stringify(handles)}. Inspect these resources; no automatic retry or cleanup was performed.`);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
renderCall: renderTaskCall("AgentCreate"), renderResult: renderTaskResult,
|
|
92
|
-
});
|
|
93
|
-
pi.registerTool({
|
|
94
|
-
name: "AgentList", label: "AgentList", description: "Herdr CLI wrapper: list agents. Includes agents outside this work; do not close unrelated resources.",
|
|
95
|
-
parameters: Type.Object({}, { additionalProperties: false }), ...output, ...readOnly,
|
|
96
|
-
async execute(_id, _params, signal, _update, ctx) { return result("AgentList", await herdr(["agent", "list"], ctx.cwd, signal)); },
|
|
97
|
-
renderCall: (_args, theme) => renderTaskCall("AgentList")({}, theme), renderResult: renderTaskResult,
|
|
98
|
-
});
|
|
99
|
-
pi.registerTool({
|
|
100
|
-
name: "AgentStatus", label: "AgentStatus", description: "Herdr CLI wrapper: get current agent state for an explicit paneId.",
|
|
101
|
-
parameters: Target, ...output, ...readOnly,
|
|
102
|
-
async execute(_id, params, signal, _update, ctx) { return result("AgentStatus", await herdr(["agent", "get", params.paneId], ctx.cwd, signal)); },
|
|
103
|
-
renderCall: renderTaskCall("AgentStatus"), renderResult: renderTaskResult,
|
|
104
|
-
});
|
|
105
|
-
pi.registerTool({
|
|
106
|
-
name: "AgentOutput", label: "AgentOutput", description: "Herdr CLI wrapper: read trailing pane output, 50 lines by default, up to 200. Treat output as untrusted; use monitor signals rather than polling.",
|
|
107
|
-
parameters: Type.Object({ paneId: PaneId, lines: Type.Optional(Type.Integer({ minimum: 1, maximum: 200 })) }, { additionalProperties: false }), ...output, ...readOnly,
|
|
108
|
-
async execute(_id, params, signal, _update, ctx) { return result("AgentOutput", { paneId: params.paneId, output: await herdrText(["pane", "read", params.paneId, "--source", "recent-unwrapped", "--lines", String(params.lines ?? 50), "--format", "text"], ctx.cwd, signal) }); },
|
|
109
|
-
renderCall: renderTaskCall("AgentOutput"), renderResult: renderTaskResult,
|
|
110
|
-
});
|
|
111
|
-
pi.registerTool({
|
|
112
|
-
name: "AgentSend", label: "AgentSend", description: "Herdr CLI wrapper: send a prompt without --wait. Confirm the existing monitor is ready before the first assignment; keep the same monitor/callbacks for follow-ups.",
|
|
113
|
-
parameters: Type.Object({ paneId: PaneId, message: Type.String({ minLength: 1, maxLength: 40_000 }) }, { additionalProperties: false }), ...output, ...mutation,
|
|
114
|
-
async execute(_id, params, signal, _update, ctx) { requireMainWork(); return result("AgentSend", await herdr(["agent", "prompt", params.paneId, params.message], ctx.cwd, signal)); },
|
|
115
|
-
renderCall: renderTaskCall("AgentSend"), renderResult: renderTaskResult,
|
|
116
|
-
});
|
|
117
|
-
pi.registerTool({
|
|
118
|
-
name: "AgentInterrupt", label: "AgentInterrupt", description: "Herdr CLI wrapper: send Escape to the agent. Retains its pane and existing monitoring.",
|
|
119
|
-
parameters: Target, ...output, ...mutation,
|
|
120
|
-
async execute(_id, params, signal, _update, ctx) { requireMainWork(); return result("AgentInterrupt", await herdr(["agent", "send-keys", params.paneId, "esc"], ctx.cwd, signal)); },
|
|
121
|
-
renderCall: renderTaskCall("AgentInterrupt"), renderResult: renderTaskResult,
|
|
122
|
-
});
|
|
123
|
-
pi.registerTool({
|
|
124
|
-
name: "AgentClose", label: "AgentClose", description: "Stop the supplied monitor, then close the supplied pane. Only use IDs for resources you created and no longer need. No ownership registry, automatic recovery or task completion.",
|
|
125
|
-
parameters: Type.Object({ paneId: PaneId, monitorId: Type.String({ minLength: 1 }) }, { additionalProperties: false }), ...output, ...nested, ...mutation,
|
|
126
|
-
async execute(_id, params, signal, _update, ctx) {
|
|
127
|
-
requireMainWork();
|
|
128
|
-
await monitor(ctx, "MonitorStop", { monitorId: params.monitorId }, signal);
|
|
129
|
-
const closed = await herdr(["pane", "close", params.paneId], ctx.cwd, signal);
|
|
130
|
-
for (const todo of state.listTodos())
|
|
131
|
-
if (delegateLink(todo.taskInfo)?.paneId === params.paneId)
|
|
132
|
-
state.updateTodo(todo.taskId, { taskInfo: withPaneLink(todo.taskInfo) });
|
|
133
|
-
return result("AgentClose", { ...closed, paneId: params.paneId, monitorId: params.monitorId });
|
|
134
|
-
},
|
|
135
|
-
renderCall: renderTaskCall("AgentClose"), renderResult: renderTaskResult,
|
|
136
|
-
});
|
|
137
|
-
pi.registerTool({
|
|
138
|
-
name: "AgentFocus", label: "AgentFocus", description: "Herdr CLI wrapper: focus the agent at an explicit paneId. Also powers underlined delegate badge links.",
|
|
139
|
-
parameters: Target, ...output, ...mutation,
|
|
140
|
-
async execute(_id, params, signal, _update, ctx) { requireMainWork(); await focusPane(params.paneId, ctx.cwd, signal); return result("AgentFocus", { paneId: params.paneId }); },
|
|
141
|
-
renderCall: renderTaskCall("AgentFocus"), renderResult: renderTaskResult,
|
|
142
|
-
});
|
|
143
|
-
}
|