@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
package/dist/blocked.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Count blocked tasks by the dependency class the record actually stores. */
|
|
2
|
+
export function blockedDependencyCounts(todos) {
|
|
3
|
+
const counts = { user: 0, agent: 0, unclassified: 0 };
|
|
4
|
+
for (const todo of todos) {
|
|
5
|
+
if (todo.status !== "blocked")
|
|
6
|
+
continue;
|
|
7
|
+
if (todo.dependentOn === "user-decision")
|
|
8
|
+
counts.user++;
|
|
9
|
+
else if (todo.dependentOn === "another-agent")
|
|
10
|
+
counts.agent++;
|
|
11
|
+
else
|
|
12
|
+
counts.unclassified++;
|
|
13
|
+
}
|
|
14
|
+
return counts;
|
|
15
|
+
}
|
|
16
|
+
/** Null for legacy records that never stored the transition time. */
|
|
17
|
+
export function blockedAgeMs(todo, now = Date.now()) {
|
|
18
|
+
if (todo.status !== "blocked" || todo.blockedAt === undefined)
|
|
19
|
+
return null;
|
|
20
|
+
return Math.max(0, now - todo.blockedAt);
|
|
21
|
+
}
|
|
22
|
+
/** Compact age such as `18h`; absent when the record stores no transition time. */
|
|
23
|
+
export function formatBlockedAge(ageMs) {
|
|
24
|
+
if (ageMs === null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const minutes = Math.floor(ageMs / 60_000);
|
|
27
|
+
if (minutes < 60)
|
|
28
|
+
return `${minutes}m`;
|
|
29
|
+
const hours = Math.floor(minutes / 60);
|
|
30
|
+
if (hours < 48)
|
|
31
|
+
return `${hours}h`;
|
|
32
|
+
return `${Math.floor(hours / 24)}d`;
|
|
33
|
+
}
|
|
34
|
+
export function blockedDependencyLabel(todo) {
|
|
35
|
+
if (todo.status !== "blocked")
|
|
36
|
+
return undefined;
|
|
37
|
+
if (todo.dependentOn === "user-decision")
|
|
38
|
+
return "blocked on you";
|
|
39
|
+
if (todo.dependentOn === "another-agent")
|
|
40
|
+
return "waiting on agents";
|
|
41
|
+
return "blocked";
|
|
42
|
+
}
|
|
43
|
+
/** Compact header summary; the two dependency classes stay visibly separate. */
|
|
44
|
+
export function compactBlockedSummary(counts) {
|
|
45
|
+
const parts = [];
|
|
46
|
+
if (counts.user)
|
|
47
|
+
parts.push(`${counts.user} on you`);
|
|
48
|
+
if (counts.agent)
|
|
49
|
+
parts.push(`${counts.agent} on agents`);
|
|
50
|
+
if (counts.unclassified)
|
|
51
|
+
parts.push(`${counts.unclassified} blocked`);
|
|
52
|
+
return parts.length ? `${parts.join(" · ")}` : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** Row suffix such as `blocked on you · 18h`; active rows and a record with no stored age have none. */
|
|
55
|
+
export function blockedRowLabel(todo, now = Date.now()) {
|
|
56
|
+
const label = blockedDependencyLabel(todo);
|
|
57
|
+
if (label === undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
const age = formatBlockedAge(blockedAgeMs(todo, now));
|
|
60
|
+
return age === undefined ? label : `${label} · ${age}`;
|
|
61
|
+
}
|
|
62
|
+
function quoted(value, max = 180) {
|
|
63
|
+
const single = value.replace(/\s+/gu, " ").trim();
|
|
64
|
+
return single.length > max ? `${single.slice(0, max - 1)}…` : single;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Read-only reconciliation block attached to a review that is already being
|
|
68
|
+
* delivered. It never changes a record and never creates a wake of its own.
|
|
69
|
+
* Linked decision questions are grouped so one answer can reconcile every task
|
|
70
|
+
* that references it.
|
|
71
|
+
*/
|
|
72
|
+
export function blockedAuditPrompt(todos, now = Date.now()) {
|
|
73
|
+
const blocked = todos.filter((todo) => todo.status === "blocked");
|
|
74
|
+
if (blocked.length === 0)
|
|
75
|
+
return undefined;
|
|
76
|
+
const byQuestion = new Map();
|
|
77
|
+
for (const todo of blocked) {
|
|
78
|
+
if (todo.dependentOn !== "user-decision" || todo.decisionQuestionId === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
byQuestion.set(todo.decisionQuestionId, [...(byQuestion.get(todo.decisionQuestionId) ?? []), todo.taskId]);
|
|
81
|
+
}
|
|
82
|
+
const rows = blocked.map((todo) => {
|
|
83
|
+
const dependency = blockedDependencyLabel(todo) ?? "blocked";
|
|
84
|
+
const age = formatBlockedAge(blockedAgeMs(todo, now));
|
|
85
|
+
const since = age === undefined ? "" : ` · ${age}`;
|
|
86
|
+
const question = todo.decisionQuestionId === undefined ? ""
|
|
87
|
+
: ` · question ${todo.decisionQuestionId}${(byQuestion.get(todo.decisionQuestionId)?.length ?? 0) > 1
|
|
88
|
+
? ` (shared by ${byQuestion.get(todo.decisionQuestionId)?.join(", ")})` : ""}`;
|
|
89
|
+
const reason = todo.blockedReason ?? todo.finalThoughts ?? "no reason recorded";
|
|
90
|
+
return `- ${todo.taskId} “${quoted(todo.taskName)}” — ${dependency}${since}${question} — ${quoted(reason)}`;
|
|
91
|
+
});
|
|
92
|
+
const shared = [...byQuestion].filter(([, ids]) => ids.length > 1)
|
|
93
|
+
.map(([questionId, ids]) => `${ids.join(", ")} all reference question ${questionId}; one answer must reconcile every linked task`);
|
|
94
|
+
return [
|
|
95
|
+
`Blocked task audit (${blocked.length}):`,
|
|
96
|
+
...rows,
|
|
97
|
+
...(shared.length ? [`Shared decisions: ${shared.join(". ")}.`] : []),
|
|
98
|
+
"For each row, confirm in this turn that the dependency still exists and the record is accurate. If it no longer exists, update the task in this same turn: return it to active with the next concrete step, complete it with evidence, or take an obsolete task through the human cancellation decision with the superseding reason. If it still exists, keep the task blocked with the exact unblock condition and make sure the question or monitor that will resume it is live. Saying in conversation that no input is needed without changing the record is a lifecycle defect. Never clear a genuine blocker, invent an answer, or change status merely to finish this review.",
|
|
99
|
+
].join("\n");
|
|
100
|
+
}
|
package/dist/command.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { GitStatusCache } from "./git-status.js";
|
|
3
3
|
import type { TaskState } from "./state.js";
|
|
4
|
-
export declare function registerWorksCommand(pi: ExtensionAPI, state: TaskState, git: GitStatusCache, getOpenCommand: () => string[]): void;
|
|
4
|
+
export declare function registerWorksCommand(pi: ExtensionAPI, state: TaskState, git: GitStatusCache, getOpenCommand: () => string[], handleAction: (args: string, ctx: ExtensionCommandContext) => Promise<void>): void;
|
package/dist/command.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runWorksOverlay } from "./ui/overlay.js";
|
|
2
2
|
import { WorksDashboard } from "./ui/works-dashboard.js";
|
|
3
|
-
export function registerWorksCommand(pi, state, git, getOpenCommand) {
|
|
3
|
+
export function registerWorksCommand(pi, state, git, getOpenCommand, handleAction) {
|
|
4
4
|
let closeActiveDashboard;
|
|
5
5
|
pi.on("session_start", () => {
|
|
6
6
|
closeActiveDashboard?.();
|
|
@@ -11,8 +11,12 @@ export function registerWorksCommand(pi, state, git, getOpenCommand) {
|
|
|
11
11
|
closeActiveDashboard = undefined;
|
|
12
12
|
});
|
|
13
13
|
pi.registerCommand("works", {
|
|
14
|
-
description: "Open the
|
|
15
|
-
handler: async (
|
|
14
|
+
description: "Open the dashboard; compact-on/off controls the Pi display, herdr-on/off controls the native panel",
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
if (args.trim()) {
|
|
17
|
+
await handleAction(args.trim(), ctx);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
16
20
|
if (ctx.mode !== "tui") {
|
|
17
21
|
ctx.ui.notify("/works requires interactive TUI mode", "error");
|
|
18
22
|
return;
|
package/dist/delegated-time.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { TaskState } from "./state.js";
|
|
3
|
-
export
|
|
3
|
+
export interface TimingInspection {
|
|
4
|
+
reportPath: string;
|
|
5
|
+
timing: "placeholder" | "measured";
|
|
6
|
+
workerSessionId: string | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validate an existing timing report for a delegated assignment. Legacy reports may
|
|
10
|
+
* contain a placeholder; new assignments register the expected path in task state
|
|
11
|
+
* and create no report until the worker exports measured effort.
|
|
12
|
+
*/
|
|
13
|
+
export declare function inspectTimingReport(ctx: ExtensionContext, taskDir: string, workId: string, taskId: string, reportPath: string, reportRoot?: string): Promise<TimingInspection>;
|
|
14
|
+
export declare function createTimingReport(ctx: ExtensionContext, taskDir: string, workId: string, taskId: string, reportRoot?: string): Promise<string>;
|
|
4
15
|
export declare function registerDelegatedTimeTools(pi: ExtensionAPI, state: TaskState): void;
|
package/dist/delegated-time.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { readFile, realpath, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { link, lstat, mkdir, readFile, realpath, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { Type } from "typebox";
|
|
@@ -23,6 +23,38 @@ async function reportDirectory(cwd, path) {
|
|
|
23
23
|
throw new Error("Timing reports must be below the repository's var/ directory.");
|
|
24
24
|
return directory;
|
|
25
25
|
}
|
|
26
|
+
/** Find the nearest existing ancestor without following a final symlink. */
|
|
27
|
+
async function existingAncestor(path) {
|
|
28
|
+
let current = path;
|
|
29
|
+
while (true) {
|
|
30
|
+
try {
|
|
31
|
+
await lstat(current);
|
|
32
|
+
return current;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code !== "ENOENT")
|
|
36
|
+
throw error;
|
|
37
|
+
const parent = dirname(current);
|
|
38
|
+
if (parent === current)
|
|
39
|
+
return current;
|
|
40
|
+
current = parent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Create a missing delegated-task directory only below the repository's real var/ tree. */
|
|
45
|
+
async function ensureReportDirectory(cwd, requested) {
|
|
46
|
+
const repository = await realpath(cwd);
|
|
47
|
+
const root = resolve(repository, "var");
|
|
48
|
+
const lexicalAncestor = await existingAncestor(requested);
|
|
49
|
+
const prospective = resolve(await realpath(lexicalAncestor), relative(lexicalAncestor, requested));
|
|
50
|
+
if (!inside(root, prospective))
|
|
51
|
+
throw new Error("Timing reports and task artifacts must be created below the repository's var/ directory.");
|
|
52
|
+
await mkdir(requested, { recursive: true });
|
|
53
|
+
const directory = await realpath(requested);
|
|
54
|
+
if (!inside(root, directory))
|
|
55
|
+
throw new Error("Timing reports must be below the repository's var/ directory.");
|
|
56
|
+
return directory;
|
|
57
|
+
}
|
|
26
58
|
async function reportFile(cwd, path) {
|
|
27
59
|
const requested = resolve(cwd, path);
|
|
28
60
|
const directory = await reportDirectory(cwd, dirname(requested));
|
|
@@ -60,15 +92,31 @@ async function readReport(path) {
|
|
|
60
92
|
throw new Error("Timing report has no worker measurement.");
|
|
61
93
|
return data;
|
|
62
94
|
}
|
|
63
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Validate an existing timing report for a delegated assignment. Legacy reports may
|
|
97
|
+
* contain a placeholder; new assignments register the expected path in task state
|
|
98
|
+
* and create no report until the worker exports measured effort.
|
|
99
|
+
*/
|
|
100
|
+
export async function inspectTimingReport(ctx, taskDir, workId, taskId, reportPath, reportRoot = ctx.cwd) {
|
|
64
101
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const report =
|
|
70
|
-
|
|
71
|
-
|
|
102
|
+
const directory = await reportDirectory(reportRoot, resolve(reportRoot, taskDir));
|
|
103
|
+
const actual = await reportFile(reportRoot, reportPath);
|
|
104
|
+
if (dirname(actual) !== directory)
|
|
105
|
+
throw new Error("Timing report is not in the delegated task directory.");
|
|
106
|
+
const report = await readReport(actual);
|
|
107
|
+
if (report.parentSessionId !== sessionId || report.parentWorkId !== workId || report.parentTaskId !== taskId) {
|
|
108
|
+
throw new Error("Timing report belongs to another parent assignment.");
|
|
109
|
+
}
|
|
110
|
+
return { reportPath: actual, timing: report.workerSessionId === null ? "placeholder" : "measured", workerSessionId: report.workerSessionId };
|
|
111
|
+
}
|
|
112
|
+
export async function createTimingReport(ctx, taskDir, workId, taskId, reportRoot = ctx.cwd) {
|
|
113
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
114
|
+
if (!SESSION_ID.test(sessionId) || !WORK_ID.test(workId) || !TASK_ID.test(taskId))
|
|
115
|
+
throw new Error("Invalid parent identity for timing handoff.");
|
|
116
|
+
const directory = await ensureReportDirectory(reportRoot, resolve(reportRoot, taskDir));
|
|
117
|
+
if (basename(directory) !== taskId || basename(dirname(directory)) !== workId || basename(dirname(dirname(directory))) !== sessionId)
|
|
118
|
+
throw new Error("Timing directory does not match the parent assignment.");
|
|
119
|
+
return resolve(directory, `delegated-time-${randomUUID()}.json`);
|
|
72
120
|
}
|
|
73
121
|
function measuredTotal(report) {
|
|
74
122
|
if (!report.tasks.length || report.tasks.some((task) => task.elapsedMs === null))
|
|
@@ -94,9 +142,28 @@ export function registerDelegatedTimeTools(pi, state) {
|
|
|
94
142
|
...execution,
|
|
95
143
|
async execute(_id, params, _signal, _update, ctx) {
|
|
96
144
|
requireMainWork();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
145
|
+
const requested = resolve(ctx.cwd, params.reportPath);
|
|
146
|
+
const directory = await reportDirectory(ctx.cwd, dirname(requested));
|
|
147
|
+
if (!/^delegated-time-[0-9a-f-]{36}\.json$/i.test(basename(requested)) || requested !== resolve(directory, basename(requested)))
|
|
148
|
+
throw new Error("Invalid timing report path.");
|
|
149
|
+
return withFileMutationQueue(requested, async () => {
|
|
150
|
+
let previous;
|
|
151
|
+
let exists = true;
|
|
152
|
+
try {
|
|
153
|
+
previous = await readReport(await reportFile(ctx.cwd, requested));
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (error.code !== "ENOENT")
|
|
157
|
+
throw error;
|
|
158
|
+
exists = false;
|
|
159
|
+
const parentTaskId = basename(directory);
|
|
160
|
+
const parentWorkId = basename(dirname(directory));
|
|
161
|
+
const parentSessionId = basename(dirname(dirname(directory)));
|
|
162
|
+
if (!TASK_ID.test(parentTaskId) || !WORK_ID.test(parentWorkId) || !SESSION_ID.test(parentSessionId))
|
|
163
|
+
throw new Error("Timing report directory does not identify a parent assignment.");
|
|
164
|
+
previous = { version: 1, parentSessionId, parentWorkId, parentTaskId, workerSessionId: null, tasks: [] };
|
|
165
|
+
}
|
|
166
|
+
const path = requested;
|
|
100
167
|
const workerSessionId = ctx.sessionManager.getSessionId();
|
|
101
168
|
if (!SESSION_ID.test(workerSessionId) || workerSessionId === previous.parentSessionId)
|
|
102
169
|
throw new Error("Timing export requires a distinct worker session.");
|
|
@@ -119,7 +186,10 @@ export function registerDelegatedTimeTools(pi, state) {
|
|
|
119
186
|
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
120
187
|
try {
|
|
121
188
|
await writeFile(temporary, `${JSON.stringify(report, null, 2)}\n`, { flag: "wx", mode: 0o600 });
|
|
122
|
-
|
|
189
|
+
if (exists)
|
|
190
|
+
await rename(temporary, path);
|
|
191
|
+
else
|
|
192
|
+
await link(temporary, path);
|
|
123
193
|
}
|
|
124
194
|
finally {
|
|
125
195
|
await unlink(temporary).catch((error) => { if (error.code !== "ENOENT")
|
|
@@ -144,14 +214,25 @@ export function registerDelegatedTimeTools(pi, state) {
|
|
|
144
214
|
throw new Error("This task has no timing handoff registered by AgentCreate.");
|
|
145
215
|
const updates = [];
|
|
146
216
|
for (const source of todo.delegatedTimes) {
|
|
147
|
-
const
|
|
217
|
+
const root = source.reportRoot ?? ctx.cwd;
|
|
218
|
+
let path;
|
|
219
|
+
try {
|
|
220
|
+
path = await reportFile(root, source.reportPath);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (error.code !== "ENOENT")
|
|
224
|
+
throw error;
|
|
225
|
+
await reportDirectory(root, dirname(source.reportPath));
|
|
226
|
+
updates.push({ reportPath: source.reportPath, reportRoot: source.reportRoot, workerSessionId: source.workerSessionId, elapsedMs: null });
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
148
229
|
const report = await readReport(path);
|
|
149
230
|
if (report.parentSessionId !== ctx.sessionManager.getSessionId() || report.parentWorkId !== todo.workId || report.parentTaskId !== todo.taskId) {
|
|
150
231
|
throw new Error("Timing report belongs to another parent assignment.");
|
|
151
232
|
}
|
|
152
233
|
if (source.workerSessionId && source.workerSessionId !== report.workerSessionId)
|
|
153
234
|
throw new Error("Timing report belongs to another worker session.");
|
|
154
|
-
updates.push({ reportPath: source.reportPath, workerSessionId: report.workerSessionId ?? undefined, elapsedMs: measuredTotal(report) });
|
|
235
|
+
updates.push({ reportPath: source.reportPath, reportRoot: source.reportRoot, workerSessionId: report.workerSessionId ?? undefined, elapsedMs: measuredTotal(report) });
|
|
155
236
|
}
|
|
156
237
|
for (const source of updates)
|
|
157
238
|
state.setDelegatedTime(todo.taskId, source);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The only two valid reasons a Pi task may be blocked. */
|
|
2
|
+
export declare const TASK_DEPENDENCIES: readonly ["user-decision", "another-agent"];
|
|
3
|
+
export type TaskDependency = (typeof TASK_DEPENDENCIES)[number];
|
|
4
|
+
export declare const DEPENDENCY_LABELS: Record<TaskDependency, string>;
|
|
5
|
+
export declare const DEPENDENCY_GUIDANCE = "Only a blocked task has dependentOn. When entering blocked, supply exactly one of \"user-decision\" for a user response, decision, or permission, or \"another-agent\" for another agent's output or review. Nonblocked tasks omit it and leaving blocked clears it. Do not mark a task blocked when a service, tool or access failed and nobody can act on it yet; keep the task active, preserve safety, and report the unavailable dependency truthfully. Do mark it blocked with \"user-decision\" when only the user can clear that obstacle, for example by signing in or reconnecting a browser profile, granting access, supplying a missing identifier, or choosing between options. When the blocker is a pi-decisions page, record its questionId in decisionQuestionId so a pending page can be re-armed or withdrawn and every task waiting on that question is reconciled together. If you conclude in conversation that a blocked dependency no longer exists, update the task record in that same turn; saying no input is needed without clearing or re-recording the blocker is a lifecycle defect, and a task that is proved obsolete must go through the human cancellation decision with the superseding reason rather than staying active.";
|
|
6
|
+
export declare function isTaskDependency(value: unknown): value is TaskDependency;
|
|
7
|
+
export declare function dependentOnLabel(value: TaskDependency | null | undefined): string | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The only two valid reasons a Pi task may be blocked. */
|
|
2
|
+
export const TASK_DEPENDENCIES = ["user-decision", "another-agent"];
|
|
3
|
+
export const DEPENDENCY_LABELS = {
|
|
4
|
+
"user-decision": "User decision",
|
|
5
|
+
"another-agent": "Another agent",
|
|
6
|
+
};
|
|
7
|
+
export const DEPENDENCY_GUIDANCE = "Only a blocked task has dependentOn. When entering blocked, supply exactly one of \"user-decision\" for a user response, decision, or permission, or \"another-agent\" for another agent's output or review. Nonblocked tasks omit it and leaving blocked clears it. Do not mark a task blocked when a service, tool or access failed and nobody can act on it yet; keep the task active, preserve safety, and report the unavailable dependency truthfully. Do mark it blocked with \"user-decision\" when only the user can clear that obstacle, for example by signing in or reconnecting a browser profile, granting access, supplying a missing identifier, or choosing between options. When the blocker is a pi-decisions page, record its questionId in decisionQuestionId so a pending page can be re-armed or withdrawn and every task waiting on that question is reconciled together. If you conclude in conversation that a blocked dependency no longer exists, update the task record in that same turn; saying no input is needed without clearing or re-recording the blocker is a lifecycle defect, and a task that is proved obsolete must go through the human cancellation decision with the superseding reason rather than staying active.";
|
|
8
|
+
export function isTaskDependency(value) {
|
|
9
|
+
return typeof value === "string" && TASK_DEPENDENCIES.includes(value);
|
|
10
|
+
}
|
|
11
|
+
export function dependentOnLabel(value) {
|
|
12
|
+
return value === null || value === undefined ? undefined : DEPENDENCY_LABELS[value];
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Extension } from "@earendil-works/pi-durable";
|
|
2
|
+
import { type TaskDependency } from "./dependency.js";
|
|
3
|
+
/** Plain serializable settings accepted at factory creation. No callbacks. */
|
|
4
|
+
export interface TasksDurableSettings {
|
|
5
|
+
/** Maximum works per conversation. Default 100. Must be an integer from 1 to 10000. */
|
|
6
|
+
readonly maxWorks?: number;
|
|
7
|
+
/** Maximum todos per conversation. Default 500. Must be an integer from 1 to 10000. */
|
|
8
|
+
readonly maxTodos?: number;
|
|
9
|
+
}
|
|
10
|
+
export type DurableTaskStatus = "active" | "blocked" | "completed" | "closed" | "cancelled";
|
|
11
|
+
export type DurableWork = {
|
|
12
|
+
workId: string;
|
|
13
|
+
workName: string;
|
|
14
|
+
workInfo: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
};
|
|
18
|
+
export type DurableTodo = {
|
|
19
|
+
taskId: string;
|
|
20
|
+
workId: string;
|
|
21
|
+
taskName: string;
|
|
22
|
+
/** Hidden coordination metadata: owner declaration, artifact paths, parent IDs. */
|
|
23
|
+
taskInfo: string;
|
|
24
|
+
/** The only user-visible task text. */
|
|
25
|
+
finalThoughts?: string;
|
|
26
|
+
status: DurableTaskStatus;
|
|
27
|
+
blockedReason: string | null;
|
|
28
|
+
dependentOn: TaskDependency | null;
|
|
29
|
+
/** When the current blocked state began; absent on legacy records. */
|
|
30
|
+
blockedAt?: number;
|
|
31
|
+
/** Linked pi-decisions question for a user-decision blocker. */
|
|
32
|
+
decisionQuestionId?: string;
|
|
33
|
+
completionPercent: number | null;
|
|
34
|
+
createdAt: number;
|
|
35
|
+
updatedAt: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Create a native Work/Todo tracking extension from serializable settings.
|
|
39
|
+
* The host opens its own Harness with models/storage/env and installs the result.
|
|
40
|
+
* Record tools only: effort timing is unsupported natively (see module docs).
|
|
41
|
+
*/
|
|
42
|
+
export declare function createTasksDurableExtension(settings?: TasksDurableSettings): Extension;
|