@narumitw/pi-goal 0.4.1 → 0.4.2
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/package.json +2 -2
- package/src/goal.ts +9 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-goal",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Pi extension that keeps working on a /goal until the agent marks it complete.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@biomejs/biome": "2.4.14",
|
|
35
|
-
"@
|
|
35
|
+
"@earendil-works/pi-coding-agent": "0.74.0",
|
|
36
36
|
"typescript": "6.0.3"
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
package/src/goal.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { defineTool, type ExtensionAPI } from "@
|
|
5
|
+
import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { Type } from "typebox";
|
|
7
7
|
|
|
8
8
|
type GoalStatus = "active" | "paused" | "budget_limited" | "complete";
|
|
@@ -406,7 +406,7 @@ function updateGoalUsage(goal: ActiveGoal, ctx: StatusContext) {
|
|
|
406
406
|
goal.updatedAt = Date.now();
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
function parseCommand(args: string): CommandResult | string {
|
|
409
|
+
export function parseCommand(args: string): CommandResult | string {
|
|
410
410
|
const tokens = tokenize(args.trim());
|
|
411
411
|
if (tokens.length === 0) return { kind: "show" };
|
|
412
412
|
|
|
@@ -465,7 +465,7 @@ function tokenize(input: string): string[] {
|
|
|
465
465
|
return tokens;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
function parseTokenBudget(value: string): number | undefined {
|
|
468
|
+
export function parseTokenBudget(value: string): number | undefined {
|
|
469
469
|
const match = /^(\d+(?:\.\d+)?)([km])?$/iu.exec(value.trim());
|
|
470
470
|
if (!match) return undefined;
|
|
471
471
|
const amount = Number(match[1]);
|
|
@@ -474,7 +474,7 @@ function parseTokenBudget(value: string): number | undefined {
|
|
|
474
474
|
return Math.floor(amount * multiplier);
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
function validateObjective(objective: string): string | undefined {
|
|
477
|
+
export function validateObjective(objective: string): string | undefined {
|
|
478
478
|
const trimmed = objective.trim();
|
|
479
479
|
if (!trimmed) return "Usage: /goal <goal_to_complete>";
|
|
480
480
|
if (trimmed.length > MAX_OBJECTIVE_LENGTH) {
|
|
@@ -525,7 +525,7 @@ function updateStatus(ctx: StatusContext, goal: ActiveGoal) {
|
|
|
525
525
|
ctx.ui.setStatus(STATUS_KEY, formatStatus(goal));
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
function formatStatus(goal: ActiveGoal | undefined) {
|
|
528
|
+
export function formatStatus(goal: ActiveGoal | undefined) {
|
|
529
529
|
if (!goal) return undefined;
|
|
530
530
|
if (goal.status === "complete") return "🎯 complete";
|
|
531
531
|
if (goal.status === "paused") return "🎯 paused";
|
|
@@ -555,7 +555,7 @@ function goalCommandHint(status: GoalStatus) {
|
|
|
555
555
|
return "/goal edit <objective>, /goal clear";
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
-
function formatDuration(seconds: number) {
|
|
558
|
+
export function formatDuration(seconds: number) {
|
|
559
559
|
if (seconds < 60) return `${seconds}s`;
|
|
560
560
|
const minutes = Math.floor(seconds / 60);
|
|
561
561
|
if (minutes < 60) return `${minutes}m`;
|
|
@@ -563,7 +563,7 @@ function formatDuration(seconds: number) {
|
|
|
563
563
|
return `${hours}h${minutes % 60}m`;
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
function formatTokenCount(value: number) {
|
|
566
|
+
export function formatTokenCount(value: number) {
|
|
567
567
|
if (value < 1_000) return `${value}`;
|
|
568
568
|
if (value < 1_000_000) return `${Number.isInteger(value / 1_000) ? value / 1_000 : (value / 1_000).toFixed(1)}k`;
|
|
569
569
|
return `${Number.isInteger(value / 1_000_000) ? value / 1_000_000 : (value / 1_000_000).toFixed(1)}m`;
|
|
@@ -584,7 +584,7 @@ function buildResumePrompt(goal: ActiveGoal) {
|
|
|
584
584
|
return `The user explicitly resumed the paused /goal. Continue working toward this goal:\n\n${goalObjectiveBlock(goal)}${budgetLine}\n\n${goalPersistenceRules("this goal")}`;
|
|
585
585
|
}
|
|
586
586
|
|
|
587
|
-
function buildGoalSystemPrompt(goal: ActiveGoal) {
|
|
587
|
+
export function buildGoalSystemPrompt(goal: ActiveGoal) {
|
|
588
588
|
const budgetLine = goal.tokenBudget === undefined ? "" : `\n- Respect the goal token budget (${formatBudget(goal)} used).`;
|
|
589
589
|
return `Active /goal:\n${goalObjectiveBlock(goal)}\n\nGoal-mode rules:\n- Keep going until the active goal is completely resolved end-to-end.\n- Treat the current worktree, command output, tests, and external state as authoritative.\n- Do not redefine the goal into a smaller task; audit every requirement before completion.\n- Do not stop at analysis, a plan, TODO list, partial fixes, or suggested next steps.\n- Autonomously perform implementation and verification with the available tools when they are needed to complete the goal.\n- Persevere through recoverable tool failures by trying reasonable alternatives instead of yielding early.\n- If the goal is not complete at the end of a turn, expect an automatic continuation and keep working from where you left off.\n- Only call the goal_complete tool after the goal is fully complete and verified.${budgetLine}`;
|
|
590
590
|
}
|
|
@@ -652,7 +652,7 @@ function extractContinuationMarker(prompt: string) {
|
|
|
652
652
|
return CONTINUATION_MARKER_PATTERN.exec(prompt)?.[1];
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
-
function findFinalAssistantMessage(messages: unknown[]): AssistantMessageLike | undefined {
|
|
655
|
+
export function findFinalAssistantMessage(messages: unknown[]): AssistantMessageLike | undefined {
|
|
656
656
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
657
657
|
const message = messages[i];
|
|
658
658
|
if (!message || typeof message !== "object") continue;
|