@narumitw/pi-goal 0.49.6 → 0.49.7
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/README.md +1 -1
- package/package.json +1 -1
- package/src/command-registration.ts +59 -7
- package/src/commands.ts +1 -2
- package/src/errors.ts +8 -0
- package/src/menu.ts +4 -9
package/README.md
CHANGED
|
@@ -314,7 +314,7 @@ packages/pi-goal/
|
|
|
314
314
|
├── src/
|
|
315
315
|
│ ├── index.ts # Pi package entrypoint
|
|
316
316
|
│ ├── goal.ts # Order-explicit extension composition root
|
|
317
|
-
│ ├── command-registration.ts #
|
|
317
|
+
│ ├── command-registration.ts # Lightweight slash-command adapter with lazy manager/settings UI
|
|
318
318
|
│ ├── commands.ts # Per-factory user-command and queue mutation controller
|
|
319
319
|
│ ├── tools.ts # Goal completion and blocker tool adapters
|
|
320
320
|
│ ├── lifecycle.ts # Pi session, agent, tool, and compaction event adapter
|
package/package.json
CHANGED
|
@@ -2,12 +2,15 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-c
|
|
|
2
2
|
import { completeGoalArguments, parseCommand } from "./command.js";
|
|
3
3
|
import type { GoalCommandController } from "./commands.js";
|
|
4
4
|
import { notifyTerminal, safeTerminalText } from "./errors.js";
|
|
5
|
-
import { showGoalManager } from "./menu.js";
|
|
6
5
|
import type { GoalRuntime } from "./runtime.js";
|
|
7
|
-
import { showGoalSettings } from "./settings-ui.js";
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
type GoalManagerModule = Pick<typeof import("./menu.js"), "showGoalManager">;
|
|
8
|
+
type GoalSettingsModule = Pick<typeof import("./settings-ui.js"), "showGoalSettings">;
|
|
9
|
+
|
|
10
|
+
export interface GoalCommandRegistrationOptions {
|
|
10
11
|
settingsPath?: string;
|
|
12
|
+
loadGoalManager?: () => Promise<GoalManagerModule>;
|
|
13
|
+
loadGoalSettings?: () => Promise<GoalSettingsModule>;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export function registerGoalCommand(
|
|
@@ -16,6 +19,13 @@ export function registerGoalCommand(
|
|
|
16
19
|
commands: GoalCommandController,
|
|
17
20
|
options: GoalCommandRegistrationOptions = {},
|
|
18
21
|
) {
|
|
22
|
+
const loadGoalManager = cachedModuleLoader(
|
|
23
|
+
options.loadGoalManager ?? (() => import("./menu.js")),
|
|
24
|
+
);
|
|
25
|
+
const loadGoalSettings = cachedModuleLoader(
|
|
26
|
+
options.loadGoalSettings ?? (() => import("./settings-ui.js")),
|
|
27
|
+
);
|
|
28
|
+
|
|
19
29
|
pi.registerCommand("goal", {
|
|
20
30
|
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
21
31
|
getArgumentCompletions: (prefix) =>
|
|
@@ -31,15 +41,35 @@ export function registerGoalCommand(
|
|
|
31
41
|
return;
|
|
32
42
|
}
|
|
33
43
|
if (result.kind === "show" && args.trim() === "") {
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
const menuIsCurrent = captureMenuOwnership(runtime);
|
|
45
|
+
let managerModule: GoalManagerModule;
|
|
46
|
+
try {
|
|
47
|
+
managerModule = await loadGoalManager();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!menuIsCurrent()) return;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
if (!menuIsCurrent()) return;
|
|
53
|
+
const { showGoalManager } = managerModule;
|
|
54
|
+
await showGoalManager(runtime, commands, ctx, async (menuCtx, target) => {
|
|
55
|
+
const settingsAreCurrent = captureMenuOwnership(runtime);
|
|
56
|
+
let settingsModule: GoalSettingsModule;
|
|
57
|
+
try {
|
|
58
|
+
settingsModule = await loadGoalSettings();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!settingsAreCurrent()) return;
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (!settingsAreCurrent()) return;
|
|
64
|
+
const { showGoalSettings } = settingsModule;
|
|
65
|
+
await showGoalSettings(runtime, menuCtx, {
|
|
36
66
|
settingsPath: options.settingsPath,
|
|
37
67
|
initialScreen: target,
|
|
38
68
|
onQueueUnfrozen: async (settingsCtx) => {
|
|
39
69
|
await commands.resumeQueueAfterUnfreeze(settingsCtx);
|
|
40
70
|
},
|
|
41
|
-
})
|
|
42
|
-
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
43
73
|
return;
|
|
44
74
|
}
|
|
45
75
|
if (runtime.queueFrozen) {
|
|
@@ -98,3 +128,25 @@ function reportCommandError(message: string, ctx: ExtensionCommandContext) {
|
|
|
98
128
|
if (ctx.mode === "print" || ctx.mode === "json") throw new Error(safeMessage);
|
|
99
129
|
notifyTerminal(ctx.ui, safeMessage, "warning");
|
|
100
130
|
}
|
|
131
|
+
|
|
132
|
+
function captureMenuOwnership(runtime: GoalRuntime): () => boolean {
|
|
133
|
+
const generation = runtime.menuGeneration;
|
|
134
|
+
const controller = runtime.menuController;
|
|
135
|
+
return () =>
|
|
136
|
+
runtime.menuGeneration === generation &&
|
|
137
|
+
runtime.menuController === controller &&
|
|
138
|
+
!controller.signal.aborted;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {
|
|
142
|
+
let pending: Promise<Module> | undefined;
|
|
143
|
+
return () => {
|
|
144
|
+
if (!pending) {
|
|
145
|
+
pending = load().catch((error) => {
|
|
146
|
+
pending = undefined;
|
|
147
|
+
throw error;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return pending;
|
|
151
|
+
};
|
|
152
|
+
}
|
package/src/commands.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { checkpointGoalActiveTime, currentTokenTotal, formatTokenCount } from "./accounting.js";
|
|
2
2
|
import { validateObjective } from "./command.js";
|
|
3
|
-
import { notifyTerminal } from "./errors.js";
|
|
4
|
-
import { safeGoalMenuText } from "./menu.js";
|
|
3
|
+
import { notifyTerminal, safeGoalMenuText } from "./errors.js";
|
|
5
4
|
import type { ActiveGoal } from "./persistence.js";
|
|
6
5
|
import { buildGoalPrompt, buildObjectiveUpdatedPrompt, buildResumePrompt } from "./prompts.js";
|
|
7
6
|
import {
|
package/src/errors.ts
CHANGED
|
@@ -48,6 +48,14 @@ export function safeTerminalText(value: string) {
|
|
|
48
48
|
.trim();
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export function safeGoalMenuText(value: string, maxCharacters = 120) {
|
|
52
|
+
const sanitized = safeTerminalText(value).replace(/\s+/gu, " ").trim();
|
|
53
|
+
const characters = [...sanitized];
|
|
54
|
+
return characters.length <= maxCharacters
|
|
55
|
+
? sanitized
|
|
56
|
+
: `${characters.slice(0, maxCharacters).join("")}…`;
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
export function notifyTerminal(
|
|
52
60
|
ui: { notify: (message: string, level?: "info" | "warning" | "error") => void },
|
|
53
61
|
message: string,
|
package/src/menu.ts
CHANGED
|
@@ -3,7 +3,10 @@ import type { ActionMenuItem } from "@narumitw/pi-tui-kit";
|
|
|
3
3
|
import { formatTokenCount as formatCompactTokenCount, formatDuration } from "./accounting.js";
|
|
4
4
|
import { parseTokenBudget } from "./command.js";
|
|
5
5
|
import type { GoalCommandController } from "./commands.js";
|
|
6
|
-
import { notifyTerminal,
|
|
6
|
+
import { notifyTerminal, safeGoalMenuText } from "./errors.js";
|
|
7
|
+
|
|
8
|
+
export { safeGoalMenuText } from "./errors.js";
|
|
9
|
+
|
|
7
10
|
import type { ActiveGoal, PendingQueueAction } from "./persistence.js";
|
|
8
11
|
import { goalQueueIdentity } from "./queue.js";
|
|
9
12
|
import { type GoalRuntime, goalSummary } from "./runtime.js";
|
|
@@ -623,14 +626,6 @@ function refreshGoalMenuState(runtime: GoalMenuRuntimeView, ctx: ExtensionComman
|
|
|
623
626
|
runtime.updateStatus?.(ctx, goal);
|
|
624
627
|
}
|
|
625
628
|
|
|
626
|
-
export function safeGoalMenuText(value: string, maxCharacters = 120) {
|
|
627
|
-
const sanitized = safeTerminalText(value).replace(/\s+/gu, " ").trim();
|
|
628
|
-
const characters = [...sanitized];
|
|
629
|
-
return characters.length <= maxCharacters
|
|
630
|
-
? sanitized
|
|
631
|
-
: `${characters.slice(0, maxCharacters).join("")}…`;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
629
|
async function startFromMenu(commands: GoalCommandController, ctx: ExtensionCommandContext) {
|
|
635
630
|
const objective = (await ctx.ui.editor("Goal objective", ""))?.trim();
|
|
636
631
|
if (!objective) return;
|