@narumitw/pi-goal 0.55.2 → 0.55.3
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 +6 -0
- package/README.md +7 -2
- package/dist/chunks/{chunk-BMHQ3WQY.ts → chunk-OO6HXYSS.ts} +2 -2
- package/dist/chunks/{chunk-BMHQ3WQY.ts.map → chunk-OO6HXYSS.ts.map} +2 -2
- package/dist/chunks/{menu-JTGZ735U.ts → menu-ITMIHMQS.ts} +2 -2
- package/dist/index.ts +73 -2
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/src/runtime.ts +1 -1
- package/src/tools.ts +3 -0
- package/src/wait-renderer.ts +106 -0
- /package/dist/chunks/{menu-JTGZ735U.ts.map → menu-ITMIHMQS.ts.map} +0 -0
package/package.json
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -1626,7 +1626,7 @@ export function formatStatus(
|
|
|
1626
1626
|
const automatic =
|
|
1627
1627
|
automaticTurnLimit === null ? "automatic Unlimited" : `automatic ${goal.automaticModelTurns}/${automaticTurnLimit}`;
|
|
1628
1628
|
if (goal.waiting) {
|
|
1629
|
-
return
|
|
1629
|
+
return "waiting";
|
|
1630
1630
|
}
|
|
1631
1631
|
if (goal.status === "paused" && goal.safetyPauseCause === "continuation_limit") {
|
|
1632
1632
|
if (automaticTurnLimit === null) {
|
package/src/tools.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
MIN_GOAL_WAIT_DELAY_MS,
|
|
30
30
|
resolveGoalWaitDelay,
|
|
31
31
|
} from "./wait.js";
|
|
32
|
+
import { renderGoalWaitCall, renderGoalWaitResult } from "./wait-renderer.js";
|
|
32
33
|
|
|
33
34
|
interface GoalCompleteDetails {
|
|
34
35
|
goal: string;
|
|
@@ -260,6 +261,8 @@ export function registerGoalTools(pi: ExtensionAPI, runtime: GoalRuntime) {
|
|
|
260
261
|
const goalWaitTool = defineTool({
|
|
261
262
|
name: GOAL_WAIT_TOOL,
|
|
262
263
|
label: "Goal Wait",
|
|
264
|
+
renderCall: renderGoalWaitCall,
|
|
265
|
+
renderResult: renderGoalWaitResult,
|
|
263
266
|
description: `Keep an active /goal quiet only when the latest effective Goal contract explicitly says Goal mode is active, supplies the matching current goal_id, and progress depends on an arranged external wake event or one safety deadline. Tool visibility alone does not activate Goal mode. Call goal_wait alone. Requests below ${MIN_GOAL_WAIT_DELAY_MS}ms are clamped to ${MIN_GOAL_WAIT_DELAY_MS}ms. Never call for ordinary unfinished work.`,
|
|
264
267
|
parameters: Type.Object({
|
|
265
268
|
goal_id: Type.String({
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Theme, ToolRenderers, ToolRenderResultOptions } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Component, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { hardWrapTerminalDocument, sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
|
|
4
|
+
|
|
5
|
+
interface WaitRenderResult {
|
|
6
|
+
content: Array<{ type: string; text?: string }>;
|
|
7
|
+
details?: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface WaitRenderDetails {
|
|
11
|
+
reason: string;
|
|
12
|
+
goal_id: string;
|
|
13
|
+
goal?: string;
|
|
14
|
+
resume_at?: number;
|
|
15
|
+
requested_resume_after_ms?: number;
|
|
16
|
+
resume_after_ms?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type WaitRenderContext = Partial<
|
|
20
|
+
Pick<Parameters<NonNullable<ToolRenderers["renderResult"]>>[3], "keyText" | "keyHint" | "isError">
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
export function renderGoalWaitCall(_args: unknown, theme: Theme): Component {
|
|
24
|
+
return {
|
|
25
|
+
render: (width) =>
|
|
26
|
+
Number.isFinite(width) && width >= 1
|
|
27
|
+
? [truncateToWidth(theme.fg("toolTitle", theme.bold("Goal Wait")), Math.floor(width), "…")]
|
|
28
|
+
: [],
|
|
29
|
+
invalidate() {},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function renderGoalWaitResult(
|
|
34
|
+
result: WaitRenderResult,
|
|
35
|
+
{ expanded, isPartial }: ToolRenderResultOptions,
|
|
36
|
+
theme: Theme,
|
|
37
|
+
context: WaitRenderContext = {},
|
|
38
|
+
): Component {
|
|
39
|
+
const textBlocks = result.content.filter((block) => block.type === "text" && typeof block.text === "string");
|
|
40
|
+
const text = textBlocks
|
|
41
|
+
.map((block) => block.text)
|
|
42
|
+
.join("\n")
|
|
43
|
+
.trim();
|
|
44
|
+
// Rejected calls also have wait details. Only a finalized accepted result can use them.
|
|
45
|
+
const details =
|
|
46
|
+
!isPartial && !context.isError && textBlocks.length === 1 && text.startsWith("Goal waiting:")
|
|
47
|
+
? readWaitDetails(result.details)
|
|
48
|
+
: undefined;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
render(width) {
|
|
52
|
+
if (!Number.isFinite(width) || width < 1) return [];
|
|
53
|
+
const safeWidth = Math.floor(width);
|
|
54
|
+
const body = hardWrapTerminalDocument(details?.reason ?? text, safeWidth);
|
|
55
|
+
const clipped = !expanded && body.length > 2;
|
|
56
|
+
const shown = clipped ? body.slice(0, 2) : body;
|
|
57
|
+
if (clipped) shown[1] = `${truncateToWidth(shown[1] ?? "", safeWidth - 1, "")}…`;
|
|
58
|
+
const role = context.isError || text.startsWith("goal_wait rejected:") ? "warning" : "toolOutput";
|
|
59
|
+
const lines = shown.map((line) => theme.fg(role, line));
|
|
60
|
+
const secondary = (value: string) => {
|
|
61
|
+
lines.push(...hardWrapTerminalDocument(value, safeWidth).map((line) => theme.fg("muted", line)));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (details) {
|
|
65
|
+
if (expanded) {
|
|
66
|
+
if (details.goal) secondary(`Goal: ${details.goal}`);
|
|
67
|
+
secondary(`Goal ID: ${details.goal_id}`);
|
|
68
|
+
}
|
|
69
|
+
if (details.resume_at !== undefined) secondary(`Safety wake: ${new Date(details.resume_at).toISOString()}`);
|
|
70
|
+
secondary("Resume: external input or /goal resume");
|
|
71
|
+
if (expanded && details.requested_resume_after_ms !== undefined) {
|
|
72
|
+
secondary(`Requested delay: ${details.requested_resume_after_ms} ms`);
|
|
73
|
+
if (details.resume_after_ms !== undefined) secondary(`Effective delay: ${details.resume_after_ms} ms`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!expanded && (details || clipped) && context.keyText?.("app.tools.expand") && context.keyHint) {
|
|
78
|
+
secondary(context.keyHint("app.tools.expand", "to expand"));
|
|
79
|
+
}
|
|
80
|
+
return lines;
|
|
81
|
+
},
|
|
82
|
+
// Theme roles are evaluated on every render; there is no themed cache to clear.
|
|
83
|
+
invalidate() {},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function readWaitDetails(value: unknown): WaitRenderDetails | undefined {
|
|
88
|
+
if (!value || typeof value !== "object") return undefined;
|
|
89
|
+
const details = value as WaitRenderDetails;
|
|
90
|
+
if (typeof details.reason !== "string" || !details.reason.trim()) return undefined;
|
|
91
|
+
if (typeof details.goal_id !== "string" || !details.goal_id.trim()) return undefined;
|
|
92
|
+
if (details.goal !== undefined && typeof details.goal !== "string") return undefined;
|
|
93
|
+
if (
|
|
94
|
+
details.resume_at !== undefined &&
|
|
95
|
+
(!Number.isSafeInteger(details.resume_at) || details.resume_at < 0 || details.resume_at > 8_640_000_000_000_000)
|
|
96
|
+
) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
for (const delay of [details.requested_resume_after_ms, details.resume_after_ms]) {
|
|
100
|
+
if (delay !== undefined && (!Number.isSafeInteger(delay) || delay < 1)) return undefined;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
...details,
|
|
104
|
+
reason: sanitizeTerminalDocument(details.reason),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
File without changes
|