@narumitw/pi-goal 0.55.2 → 0.55.4

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.
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  goalSummary,
5
5
  parseTokenBudget
6
- } from "./chunk-BMHQ3WQY.ts";
6
+ } from "./chunk-OO6HXYSS.ts";
7
7
  import {
8
8
  formatDuration,
9
9
  formatTokenCount,
@@ -547,4 +547,4 @@ export {
547
547
  safeGoalMenuText,
548
548
  showGoalManager
549
549
  };
550
- //# sourceMappingURL=menu-JTGZ735U.ts.map
550
+ //# sourceMappingURL=menu-ITMIHMQS.ts.map
package/dist/index.ts CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  transitionGoal,
45
45
  usageLimitScope,
46
46
  validateObjective
47
- } from "./chunks/chunk-BMHQ3WQY.ts";
47
+ } from "./chunks/chunk-OO6HXYSS.ts";
48
48
  import {
49
49
  DEFAULT_GOAL_SETTINGS,
50
50
  currentTokenTotal,
@@ -64,7 +64,7 @@ import {
64
64
 
65
65
  // src/command-registration.ts
66
66
  function registerGoalCommand(pi, runtime, commands, options = {}) {
67
- const loadGoalManager = cachedModuleLoader(options.loadGoalManager ?? (() => import("./chunks/menu-JTGZ735U.ts")));
67
+ const loadGoalManager = cachedModuleLoader(options.loadGoalManager ?? (() => import("./chunks/menu-ITMIHMQS.ts")));
68
68
  const loadGoalSettings = cachedModuleLoader(options.loadGoalSettings ?? (() => import("./chunks/settings-ui-DK2DNBHR.ts")));
69
69
  pi.registerCommand("goal", {
70
70
  description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
@@ -1376,6 +1376,75 @@ import {
1376
1376
  } from "@earendil-works/pi-coding-agent";
1377
1377
  import { Markdown } from "@earendil-works/pi-tui";
1378
1378
  import { Type } from "typebox";
1379
+
1380
+ // src/wait-renderer.ts
1381
+ import { truncateToWidth } from "@earendil-works/pi-tui";
1382
+ import { hardWrapTerminalDocument, sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
1383
+ function renderGoalWaitCall(_args, theme) {
1384
+ return {
1385
+ render: (width) => Number.isFinite(width) && width >= 1 ? [truncateToWidth(theme.fg("toolTitle", theme.bold("Goal Wait")), Math.floor(width), "\u2026")] : [],
1386
+ invalidate() {
1387
+ }
1388
+ };
1389
+ }
1390
+ function renderGoalWaitResult(result, { expanded, isPartial }, theme, context = {}) {
1391
+ const textBlocks = result.content.filter((block) => block.type === "text" && typeof block.text === "string");
1392
+ const text = textBlocks.map((block) => block.text).join("\n").trim();
1393
+ const details = !isPartial && !context.isError && textBlocks.length === 1 && text.startsWith("Goal waiting:") ? readWaitDetails(result.details) : void 0;
1394
+ return {
1395
+ render(width) {
1396
+ if (!Number.isFinite(width) || width < 1) return [];
1397
+ const safeWidth = Math.floor(width);
1398
+ const body = hardWrapTerminalDocument(details?.reason ?? text, safeWidth);
1399
+ const clipped = !expanded && body.length > 2;
1400
+ const shown = clipped ? body.slice(0, 2) : body;
1401
+ if (clipped) shown[1] = `${truncateToWidth(shown[1] ?? "", safeWidth - 1, "")}\u2026`;
1402
+ const role = context.isError || text.startsWith("goal_wait rejected:") ? "warning" : "toolOutput";
1403
+ const lines = shown.map((line) => theme.fg(role, line));
1404
+ const secondary = (value) => {
1405
+ lines.push(...hardWrapTerminalDocument(value, safeWidth).map((line) => theme.fg("muted", line)));
1406
+ };
1407
+ if (details) {
1408
+ if (expanded) {
1409
+ if (details.goal) secondary(`Goal: ${details.goal}`);
1410
+ secondary(`Goal ID: ${details.goal_id}`);
1411
+ }
1412
+ if (details.resume_at !== void 0) secondary(`Safety wake: ${new Date(details.resume_at).toISOString()}`);
1413
+ secondary("Resume: external input or /goal resume");
1414
+ if (expanded && details.requested_resume_after_ms !== void 0) {
1415
+ secondary(`Requested delay: ${details.requested_resume_after_ms} ms`);
1416
+ if (details.resume_after_ms !== void 0) secondary(`Effective delay: ${details.resume_after_ms} ms`);
1417
+ }
1418
+ }
1419
+ if (!expanded && (details || clipped) && context.keyText?.("app.tools.expand") && context.keyHint) {
1420
+ secondary(context.keyHint("app.tools.expand", "to expand"));
1421
+ }
1422
+ return lines;
1423
+ },
1424
+ // Theme roles are evaluated on every render; there is no themed cache to clear.
1425
+ invalidate() {
1426
+ }
1427
+ };
1428
+ }
1429
+ function readWaitDetails(value) {
1430
+ if (!value || typeof value !== "object") return void 0;
1431
+ const details = value;
1432
+ if (typeof details.reason !== "string" || !details.reason.trim()) return void 0;
1433
+ if (typeof details.goal_id !== "string" || !details.goal_id.trim()) return void 0;
1434
+ if (details.goal !== void 0 && typeof details.goal !== "string") return void 0;
1435
+ if (details.resume_at !== void 0 && (!Number.isSafeInteger(details.resume_at) || details.resume_at < 0 || details.resume_at > 864e13)) {
1436
+ return void 0;
1437
+ }
1438
+ for (const delay of [details.requested_resume_after_ms, details.resume_after_ms]) {
1439
+ if (delay !== void 0 && (!Number.isSafeInteger(delay) || delay < 1)) return void 0;
1440
+ }
1441
+ return {
1442
+ ...details,
1443
+ reason: sanitizeTerminalDocument(details.reason)
1444
+ };
1445
+ }
1446
+
1447
+ // src/tools.ts
1379
1448
  var MAX_GOAL_TEXT_LENGTH = 4e3;
1380
1449
  var MAX_COMPLETION_SUMMARY_LENGTH = 4e3;
1381
1450
  var MAX_BLOCKER_REASON_LENGTH = 1e3;
@@ -1558,6 +1627,8 @@ function registerGoalTools(pi, runtime) {
1558
1627
  const goalWaitTool = defineTool({
1559
1628
  name: GOAL_WAIT_TOOL,
1560
1629
  label: "Goal Wait",
1630
+ renderCall: renderGoalWaitCall,
1631
+ renderResult: renderGoalWaitResult,
1561
1632
  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.`,
1562
1633
  parameters: Type.Object({
1563
1634
  goal_id: Type.String({