@heyhuynhgiabuu/pi-task 0.1.5 → 0.2.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/CHANGELOG.md +116 -4
- package/README.md +16 -11
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/dist/conversation.d.ts +76 -21
- package/dist/conversation.js +280 -70
- package/dist/helpers.d.ts +8 -8
- package/dist/helpers.js +34 -15
- package/dist/index.d.ts +6 -23
- package/dist/index.js +233 -634
- package/dist/lifecycle/completion.d.ts +3 -0
- package/dist/lifecycle/completion.js +50 -0
- package/dist/lifecycle/index.d.ts +5 -0
- package/dist/lifecycle/index.js +5 -0
- package/dist/lifecycle/polling.d.ts +16 -0
- package/dist/lifecycle/polling.js +61 -0
- package/dist/lifecycle/restore.d.ts +2 -0
- package/dist/lifecycle/restore.js +34 -0
- package/dist/lifecycle/toolStats.d.ts +2 -0
- package/dist/lifecycle/toolStats.js +17 -0
- package/dist/lifecycle/widget.d.ts +8 -0
- package/dist/lifecycle/widget.js +75 -0
- package/dist/session-text.d.ts +11 -2
- package/dist/session-text.js +78 -2
- package/dist/subagent/buildArgv.d.ts +1 -0
- package/dist/subagent/buildArgv.js +1 -1
- package/dist/subagent/runSdk.js +50 -26
- package/dist/subagent/tmux.d.ts +12 -9
- package/dist/subagent/tmux.js +107 -44
- package/dist/subagent/waitCompletion.d.ts +5 -5
- package/dist/subagent/waitCompletion.js +32 -41
- package/dist/task-widget.d.ts +21 -0
- package/dist/task-widget.js +122 -0
- package/dist/tool/index.d.ts +5 -0
- package/dist/tool/index.js +5 -0
- package/dist/tool/prompt.d.ts +8 -0
- package/dist/tool/prompt.js +17 -0
- package/dist/tool/renderCall.d.ts +3 -0
- package/dist/tool/renderCall.js +12 -0
- package/dist/tool/renderResult.d.ts +8 -0
- package/dist/tool/renderResult.js +51 -0
- package/dist/tool/schema.d.ts +8 -0
- package/dist/tool/schema.js +24 -0
- package/dist/tool/taskComplete.d.ts +8 -0
- package/dist/tool/taskComplete.js +65 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import { keyHint, keyText, rawKeyHint } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
/**
|
|
4
|
+
* Renderer for background task completion notifications.
|
|
5
|
+
* Supports collapsed/expanded views with Ctrl+O.
|
|
6
|
+
*/
|
|
7
|
+
export function createTaskCompleteRenderer() {
|
|
8
|
+
return (message, { expanded }, theme) => {
|
|
9
|
+
const d = message.details;
|
|
10
|
+
if (!d)
|
|
11
|
+
return undefined;
|
|
12
|
+
const agentType = d.agent_type || "";
|
|
13
|
+
const desc = d.description || "";
|
|
14
|
+
const result = (d.result || "").trim();
|
|
15
|
+
const durationMs = d.duration_ms || 0;
|
|
16
|
+
const toolUses = d.tool_uses || 0;
|
|
17
|
+
let line = " " + theme.fg("accent", agentType);
|
|
18
|
+
if (desc)
|
|
19
|
+
line += theme.fg("dim", ` - ${desc}`);
|
|
20
|
+
const useStr = toolUses > 0 ? `${toolUses} toolcalls` : "";
|
|
21
|
+
const durStr = durationMs >= 1000 ? formatMs(durationMs) : "";
|
|
22
|
+
const statsParts = [useStr, durStr].filter(Boolean);
|
|
23
|
+
const statsText = statsParts.join(" • ");
|
|
24
|
+
if (statsText) {
|
|
25
|
+
line += "\n " + theme.fg("dim", statsText);
|
|
26
|
+
}
|
|
27
|
+
const expandHint = expandCollapseHint("to expand");
|
|
28
|
+
const collapseHint = expandCollapseHint("to collapse");
|
|
29
|
+
if (expanded) {
|
|
30
|
+
if (result)
|
|
31
|
+
line += "\n " + theme.fg("muted", result);
|
|
32
|
+
line += "\n " + theme.fg("dim", ` (${collapseHint})`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const preview = result.slice(0, 120);
|
|
36
|
+
if (preview) {
|
|
37
|
+
line +=
|
|
38
|
+
"\n " +
|
|
39
|
+
theme.fg("dim", ` ⎿ ${preview}`) +
|
|
40
|
+
(result.length > 120 ? theme.fg("dim", "…") : "");
|
|
41
|
+
}
|
|
42
|
+
if (result.length > 120) {
|
|
43
|
+
line += "\n " + theme.fg("dim", ` (${expandHint})`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!line.trim())
|
|
47
|
+
return undefined;
|
|
48
|
+
const subtleBg = (text) => `\x1b[48;2;30;28;44m${text}\x1b[0m`;
|
|
49
|
+
return new Text(line, 0, 1, subtleBg);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function expandCollapseHint(action) {
|
|
53
|
+
return keyText("app.tools.expand").trim()
|
|
54
|
+
? keyHint("app.tools.expand", action)
|
|
55
|
+
: rawKeyHint("Ctrl+O", action);
|
|
56
|
+
}
|
|
57
|
+
function formatMs(ms) {
|
|
58
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
59
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
60
|
+
const seconds = totalSeconds % 60;
|
|
61
|
+
if (minutes > 0) {
|
|
62
|
+
return `${minutes}m ${seconds}s`;
|
|
63
|
+
}
|
|
64
|
+
return `${seconds}s`;
|
|
65
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ToolCallRecord } from "./helpers.js";
|
|
2
|
+
export interface BackgroundTask {
|
|
3
|
+
dir: string;
|
|
4
|
+
agentType: string;
|
|
5
|
+
sessionName: string;
|
|
6
|
+
paneId?: string;
|
|
7
|
+
originalPane: string | null;
|
|
8
|
+
description: string;
|
|
9
|
+
startedAt: number;
|
|
10
|
+
toolUses: number;
|
|
11
|
+
turns: number;
|
|
12
|
+
conversationId?: string;
|
|
13
|
+
/** Most recent tool calls (capped), updated every COUNT_POLL_MS. */
|
|
14
|
+
recentCalls: ToolCallRecord[];
|
|
15
|
+
/** Consecutive completion-poll failures; reset to 0 on a successful poll. */
|
|
16
|
+
pollErrors?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Serializable subset for active task registry persistence. */
|
|
19
|
+
export interface RegistryEntry {
|
|
20
|
+
id: string;
|
|
21
|
+
agentType: string;
|
|
22
|
+
description: string;
|
|
23
|
+
sessionName: string;
|
|
24
|
+
startedAt: number;
|
|
25
|
+
paneId?: string;
|
|
26
|
+
piDir: string;
|
|
27
|
+
dir: string;
|
|
28
|
+
conversationId?: string;
|
|
29
|
+
sessionRef?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Durable task→session mapping used for resume after task completion. */
|
|
32
|
+
export interface TaskSessionHistoryEntry extends RegistryEntry {
|
|
33
|
+
status: "running" | "done" | "cancelled" | "aborted" | "failed" | "timeout";
|
|
34
|
+
completedAt?: number;
|
|
35
|
+
background: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Details attached to tool result for rendering. */
|
|
38
|
+
export interface TaskDetails {
|
|
39
|
+
task_id: string;
|
|
40
|
+
agent_type: string;
|
|
41
|
+
description: string;
|
|
42
|
+
conversation_id?: string;
|
|
43
|
+
phase: "done" | "timeout" | "aborted" | "failed";
|
|
44
|
+
status?: string;
|
|
45
|
+
summary?: string;
|
|
46
|
+
findings?: string;
|
|
47
|
+
evidence?: string;
|
|
48
|
+
confidence?: string;
|
|
49
|
+
duration_ms?: number;
|
|
50
|
+
turn_count?: number;
|
|
51
|
+
tool_uses?: number;
|
|
52
|
+
background?: boolean;
|
|
53
|
+
tmux_session?: string;
|
|
54
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyhuynhgiabuu/pi-task",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Delegating task/subagent extension for Pi: foreground/background subagents, widgets, tmux observability, SDK fallback.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|