@narumitw/pi-goal 0.6.1 → 0.7.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/package.json +1 -1
- package/src/goal.ts +39 -0
package/package.json
CHANGED
package/src/goal.ts
CHANGED
|
@@ -49,6 +49,12 @@ interface CommandResult {
|
|
|
49
49
|
tokenBudget?: number;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
interface GoalArgumentCompletion {
|
|
53
|
+
value: string;
|
|
54
|
+
label: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
interface StatusContext {
|
|
53
59
|
cwd: string;
|
|
54
60
|
ui: {
|
|
@@ -66,6 +72,19 @@ const GOAL_STATE_ENTRY_TYPE = "goal-state";
|
|
|
66
72
|
const MAX_OBJECTIVE_LENGTH = 4_000;
|
|
67
73
|
const MAX_CANCELLED_CONTINUATION_PROMPTS = 20;
|
|
68
74
|
const CONTINUATION_MARKER_PREFIX = "pi-goal-continuation:";
|
|
75
|
+
const GOAL_ARGUMENT_COMPLETIONS: readonly GoalArgumentCompletion[] = [
|
|
76
|
+
{ value: "pause", label: "pause", description: "Pause the active goal" },
|
|
77
|
+
{ value: "resume", label: "resume", description: "Resume a paused or budget-limited goal" },
|
|
78
|
+
{ value: "clear", label: "clear", description: "Clear the current goal" },
|
|
79
|
+
{ value: "edit", label: "edit", description: "Edit the current goal objective" },
|
|
80
|
+
{ value: "status", label: "status", description: "Show the current goal" },
|
|
81
|
+
{ value: "--tokens ", label: "--tokens", description: "Set a token budget before the goal" },
|
|
82
|
+
];
|
|
83
|
+
const EDIT_TOKEN_COMPLETION: GoalArgumentCompletion = {
|
|
84
|
+
value: "edit --tokens ",
|
|
85
|
+
label: "--tokens",
|
|
86
|
+
description: "Set a token budget before the updated goal",
|
|
87
|
+
};
|
|
69
88
|
const STATE_FILE = join(
|
|
70
89
|
process.env.PI_CODING_AGENT_DIR ?? join(process.env.HOME ?? ".", ".pi", "agent"),
|
|
71
90
|
"pi-goal-state.json",
|
|
@@ -123,6 +142,7 @@ export default function goal(pi: ExtensionAPI) {
|
|
|
123
142
|
|
|
124
143
|
pi.registerCommand("goal", {
|
|
125
144
|
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
145
|
+
getArgumentCompletions: completeGoalArguments,
|
|
126
146
|
handler: async (args, ctx) => {
|
|
127
147
|
const result = parseCommand(args);
|
|
128
148
|
if (typeof result === "string") {
|
|
@@ -406,6 +426,25 @@ function updateGoalUsage(goal: ActiveGoal, ctx: StatusContext) {
|
|
|
406
426
|
goal.updatedAt = Date.now();
|
|
407
427
|
}
|
|
408
428
|
|
|
429
|
+
export function completeGoalArguments(argumentPrefix: string): GoalArgumentCompletion[] | null {
|
|
430
|
+
const prefix = argumentPrefix.trimStart();
|
|
431
|
+
if (prefix === "") return [...GOAL_ARGUMENT_COMPLETIONS];
|
|
432
|
+
|
|
433
|
+
const editOptionPrefix = /^edit\s+(\S*)$/.exec(prefix)?.[1];
|
|
434
|
+
if (editOptionPrefix !== undefined) {
|
|
435
|
+
return editOptionPrefix === "" || "--tokens".startsWith(editOptionPrefix)
|
|
436
|
+
? [EDIT_TOKEN_COMPLETION]
|
|
437
|
+
: null;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (/\s/.test(prefix)) return null;
|
|
441
|
+
|
|
442
|
+
const matches = GOAL_ARGUMENT_COMPLETIONS.filter(
|
|
443
|
+
(item) => item.value.startsWith(prefix) || item.label.startsWith(prefix),
|
|
444
|
+
);
|
|
445
|
+
return matches.length > 0 ? [...matches] : null;
|
|
446
|
+
}
|
|
447
|
+
|
|
409
448
|
export function parseCommand(args: string): CommandResult | string {
|
|
410
449
|
const tokens = tokenize(args.trim());
|
|
411
450
|
if (tokens.length === 0) return { kind: "show" };
|