pi-quests 0.3.0 → 0.4.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/CHANGELOG.md +8 -0
- package/README.md +20 -1
- package/package.json +1 -1
- package/src/commands/handler.ts +28 -11
- package/src/commands/parse-args.ts +42 -28
- package/src/config.ts +148 -0
- package/src/index.ts +52 -21
- package/src/prompts.ts +5 -2
- package/src/quest/dataplane.ts +322 -94
- package/src/quest/formatters.ts +30 -16
- package/src/quest/tracker.ts +34 -25
- package/src/quest/types.ts +5 -2
- package/src/renderers/commands.ts +46 -24
- package/src/renderers/quests.ts +45 -0
- package/src/renderers/tools.ts +80 -31
- package/src/tools/handler.ts +15 -8
- package/src/tools/params.ts +44 -30
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2026-04-13
|
|
6
|
+
|
|
7
|
+
- feat: add configurable shortcut to open quest list, default: `ctrl+shift+l`
|
|
8
|
+
- feat: add sub-quest support with lifecycle management
|
|
9
|
+
- feat: add user-configurable settings via pi settings files
|
|
10
|
+
- feat: use random 2-digit hex IDs and targetId-based reorder
|
|
11
|
+
- fix: add .pi/setting.json for development
|
|
12
|
+
|
|
5
13
|
## [0.3.0] - 2026-04-11
|
|
6
14
|
|
|
7
15
|
- feat: add reorder action to move quests by position (dataplane, tool, /quests command, renderer, revert support)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-quests
|
|
2
2
|
|
|
3
|
-
[](CHANGELOG.md)
|
|
4
4
|
[](LICENSE.md)
|
|
5
5
|
[](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent)
|
|
6
6
|
|
|
@@ -47,6 +47,24 @@ Available /quests subcommands:
|
|
|
47
47
|

|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
pi-quests reads configuration from pi's settings files. Global settings live at `~/.pi/agent/settings.json` and project overrides go in `.pi/settings.json`.
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"pi-quests": {
|
|
57
|
+
"ids": { "length": 2 },
|
|
58
|
+
"display": {
|
|
59
|
+
"pageSize": 10,
|
|
60
|
+
"progressBarMaxWidth": 24
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
See [docs/configuration.md](docs/configuration.md) for the full options reference.
|
|
67
|
+
|
|
50
68
|
## Documentation
|
|
51
69
|
|
|
52
70
|
| Doc | Description |
|
|
@@ -54,6 +72,7 @@ Available /quests subcommands:
|
|
|
54
72
|
| [Pattern](docs/pattern.md) | "How do I...?" recipes for common workflows |
|
|
55
73
|
| [Quests](docs/quests.md) | What are quests? |
|
|
56
74
|
| [Reference](docs/reference.md) | Complete tool and command schemas, types |
|
|
75
|
+
| [Configuration](docs/configuration.md) | Settings, overrides, and examples |
|
|
57
76
|
| [Architecture](docs/architecture.md) | Module map, data flow diagrams, design decisions |
|
|
58
77
|
| [Changelog](CHANGELOG.md) | Version history |
|
|
59
78
|
|
package/package.json
CHANGED
package/src/commands/handler.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionAPI,
|
|
4
|
+
ExtensionCommandContext,
|
|
5
|
+
ExtensionContext,
|
|
6
|
+
} from "@mariozechner/pi-coding-agent";
|
|
7
|
+
import type { ResolvedConfig } from "../config.js";
|
|
3
8
|
import { logger } from "../logger.js";
|
|
4
9
|
import type { QuestAction, QuestLog } from "../quest/dataplane.js";
|
|
5
10
|
import { QUEST_ACTIONS } from "../quest/types.js";
|
|
@@ -25,7 +30,11 @@ type MutatingCommand = Extract<
|
|
|
25
30
|
const commandActionBuilders: {
|
|
26
31
|
[K in MutatingCommand]: (parsed: Extract<ParsedArgs, { action: K }>) => QuestAction;
|
|
27
32
|
} = {
|
|
28
|
-
[QUEST_ACTIONS.add]: (p) => ({
|
|
33
|
+
[QUEST_ACTIONS.add]: (p) => ({
|
|
34
|
+
type: QUEST_ACTIONS.add,
|
|
35
|
+
descriptions: p.descriptions,
|
|
36
|
+
parentId: p.parentId,
|
|
37
|
+
}),
|
|
29
38
|
[QUEST_ACTIONS.toggle]: (p) => ({ type: QUEST_ACTIONS.toggle, id: p.id }),
|
|
30
39
|
[QUEST_ACTIONS.update]: (p) => ({
|
|
31
40
|
type: QUEST_ACTIONS.update,
|
|
@@ -37,16 +46,27 @@ const commandActionBuilders: {
|
|
|
37
46
|
[QUEST_ACTIONS.reorder]: (p) => ({
|
|
38
47
|
type: QUEST_ACTIONS.reorder,
|
|
39
48
|
id: p.id,
|
|
40
|
-
|
|
49
|
+
targetId: p.targetId,
|
|
41
50
|
}),
|
|
42
51
|
[QUEST_ACTIONS.revert]: () => ({ type: QUEST_ACTIONS.revert }),
|
|
43
52
|
};
|
|
44
53
|
|
|
45
|
-
export function
|
|
54
|
+
export function openQuestList(
|
|
55
|
+
_pi: ExtensionAPI,
|
|
56
|
+
questLog: QuestLog,
|
|
57
|
+
config: ResolvedConfig,
|
|
58
|
+
ctx: ExtensionContext,
|
|
59
|
+
): Promise<void> {
|
|
60
|
+
return ctx.ui.custom(
|
|
61
|
+
(_, theme, __, done) => new QuestListWidget(questLog, theme, () => done(undefined), config),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createQuestsHandler(pi: ExtensionAPI, questLog: QuestLog, config: ResolvedConfig) {
|
|
46
66
|
return async function handler(args: string, ctx: ExtensionCommandContext): Promise<void> {
|
|
47
67
|
logger.debug("quests:cmd", "handler", { args, hasUI: ctx.hasUI });
|
|
48
68
|
|
|
49
|
-
const parsed = parseQuestArgs(args);
|
|
69
|
+
const parsed = parseQuestArgs(args, config.ids.length);
|
|
50
70
|
if ("error" in parsed) {
|
|
51
71
|
logger.debug("quests:cmd", "handler-error", { error: parsed.error });
|
|
52
72
|
ctx.ui.notify(parsed.error, "error");
|
|
@@ -94,10 +114,7 @@ export function createQuestsHandler(pi: ExtensionAPI, questLog: QuestLog) {
|
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
logger.debug("quests:cmd", "list-open-widget", { count: questLog.getAll().length });
|
|
97
|
-
await ctx
|
|
98
|
-
(_, theme, __, done) =>
|
|
99
|
-
new QuestListWidget(questLog.getAll(), theme, () => done(undefined)),
|
|
100
|
-
);
|
|
117
|
+
await openQuestList(pi, questLog, config, ctx);
|
|
101
118
|
|
|
102
119
|
logger.debug("quests:cmd", "list-widget-closed");
|
|
103
120
|
return;
|
|
@@ -121,12 +138,12 @@ export function createQuestsHandler(pi: ExtensionAPI, questLog: QuestLog) {
|
|
|
121
138
|
logger.debug("quests:cmd", "help");
|
|
122
139
|
|
|
123
140
|
const lines = ["Available /quests subcommands:"];
|
|
124
|
-
lines.push(" add <description> - Add a new quest");
|
|
141
|
+
lines.push(" add [--parent <id>] <description> - Add a new quest or sub-quest");
|
|
125
142
|
lines.push(" list - List all quests");
|
|
126
143
|
lines.push(" toggle <id> - Toggle quest completion");
|
|
127
144
|
lines.push(" delete <id> - Delete a quest");
|
|
128
145
|
lines.push(" update <id> <desc> - Update a quest description");
|
|
129
|
-
lines.push(" reorder <id> <
|
|
146
|
+
lines.push(" reorder <id> <targetId> - Reorder a quest before the target quest");
|
|
130
147
|
lines.push(" revert - Revert the last quest change");
|
|
131
148
|
lines.push(" clear [all] - Clear completed quests, or optionally all quests");
|
|
132
149
|
lines.push(" version - Show version");
|
|
@@ -2,13 +2,13 @@ import { logger } from "../logger.js";
|
|
|
2
2
|
import { QUEST_ACTIONS } from "../quest/types.js";
|
|
3
3
|
|
|
4
4
|
export type ParsedArgs =
|
|
5
|
-
| { action: typeof QUEST_ACTIONS.add; descriptions: string[] }
|
|
5
|
+
| { action: typeof QUEST_ACTIONS.add; descriptions: string[]; parentId?: string }
|
|
6
6
|
| { action: typeof QUEST_ACTIONS.list }
|
|
7
|
-
| { action: typeof QUEST_ACTIONS.toggle; id:
|
|
8
|
-
| { action: typeof QUEST_ACTIONS.update; id:
|
|
9
|
-
| { action: typeof QUEST_ACTIONS.delete; id:
|
|
7
|
+
| { action: typeof QUEST_ACTIONS.toggle; id: string }
|
|
8
|
+
| { action: typeof QUEST_ACTIONS.update; id: string; description: string }
|
|
9
|
+
| { action: typeof QUEST_ACTIONS.delete; id: string }
|
|
10
10
|
| { action: typeof QUEST_ACTIONS.clear; all?: boolean }
|
|
11
|
-
| { action: typeof QUEST_ACTIONS.reorder; id:
|
|
11
|
+
| { action: typeof QUEST_ACTIONS.reorder; id: string; targetId: string }
|
|
12
12
|
| { action: typeof QUEST_ACTIONS.revert }
|
|
13
13
|
| { action: "help" }
|
|
14
14
|
| { action: "version" }
|
|
@@ -18,7 +18,7 @@ export type ParsedArgs =
|
|
|
18
18
|
/**
|
|
19
19
|
* Parse user input from the /quests command into structured arguments.
|
|
20
20
|
*/
|
|
21
|
-
export function parseQuestArgs(args: string): ParsedArgs {
|
|
21
|
+
export function parseQuestArgs(args: string, idLength = 2): ParsedArgs {
|
|
22
22
|
logger.debug("quests:cmd", "parse-args", { args });
|
|
23
23
|
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
24
24
|
|
|
@@ -41,37 +41,48 @@ export function parseQuestArgs(args: string): ParsedArgs {
|
|
|
41
41
|
if (command === QUEST_ACTIONS.revert) return { action: QUEST_ACTIONS.revert };
|
|
42
42
|
|
|
43
43
|
// Quest actions with arguments
|
|
44
|
-
if (command === QUEST_ACTIONS.add) return parseAddArgs(rest);
|
|
45
|
-
if (command === QUEST_ACTIONS.toggle) return parseIdAction(QUEST_ACTIONS.toggle, rest);
|
|
46
|
-
if (command === QUEST_ACTIONS.delete) return parseIdAction(QUEST_ACTIONS.delete, rest);
|
|
47
|
-
if (command === QUEST_ACTIONS.update) return parseUpdateArgs(rest);
|
|
48
|
-
if (command === QUEST_ACTIONS.reorder) return parseReorderArgs(rest);
|
|
44
|
+
if (command === QUEST_ACTIONS.add) return parseAddArgs(rest, idLength);
|
|
45
|
+
if (command === QUEST_ACTIONS.toggle) return parseIdAction(QUEST_ACTIONS.toggle, rest, idLength);
|
|
46
|
+
if (command === QUEST_ACTIONS.delete) return parseIdAction(QUEST_ACTIONS.delete, rest, idLength);
|
|
47
|
+
if (command === QUEST_ACTIONS.update) return parseUpdateArgs(rest, idLength);
|
|
48
|
+
if (command === QUEST_ACTIONS.reorder) return parseReorderArgs(rest, idLength);
|
|
49
49
|
|
|
50
50
|
return { error: `Unknown subcommand: ${command}. Use /quests help to see available commands.` };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function parseAddArgs(tokens: string[]): ParsedArgs {
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
function parseAddArgs(tokens: string[], idLength: number): ParsedArgs {
|
|
54
|
+
let parentId: string | undefined;
|
|
55
|
+
let descTokens = tokens;
|
|
56
|
+
const pIdx = tokens.indexOf("--parent");
|
|
57
|
+
if (pIdx !== -1) {
|
|
58
|
+
const pid = tokens[pIdx + 1]?.toLowerCase() ?? "";
|
|
59
|
+
const pattern = new RegExp(`^[0-9a-f]{${idLength}}$`);
|
|
60
|
+
if (!pattern.test(pid)) return { error: "Usage: /quests add [--parent <id>] <description>" };
|
|
61
|
+
parentId = pid;
|
|
62
|
+
descTokens = tokens.slice(0, pIdx).concat(tokens.slice(pIdx + 2));
|
|
63
|
+
}
|
|
64
|
+
const description = descTokens.join(" ").trim();
|
|
65
|
+
if (!description) return { error: "Usage: /quests add [--parent <id>] <description>" };
|
|
56
66
|
|
|
57
|
-
return { action: QUEST_ACTIONS.add, descriptions: [description] };
|
|
67
|
+
return { action: QUEST_ACTIONS.add, descriptions: [description], parentId };
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
function parseIdAction(
|
|
61
71
|
action: typeof QUEST_ACTIONS.toggle | typeof QUEST_ACTIONS.delete,
|
|
62
72
|
tokens: string[],
|
|
73
|
+
idLength: number,
|
|
63
74
|
): ParsedArgs {
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
75
|
+
const id = tokens[0] ? tokens[0].toLowerCase() : "";
|
|
76
|
+
const pattern = new RegExp(`^[0-9a-f]{${idLength}}$`);
|
|
77
|
+
if (!pattern.test(id)) return { error: `Usage: /quests ${action} <id>` };
|
|
67
78
|
|
|
68
79
|
return { action, id };
|
|
69
80
|
}
|
|
70
81
|
|
|
71
|
-
function parseUpdateArgs(tokens: string[]): ParsedArgs {
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
82
|
+
function parseUpdateArgs(tokens: string[], idLength: number): ParsedArgs {
|
|
83
|
+
const id = tokens[0] ? tokens[0].toLowerCase() : "";
|
|
84
|
+
const pattern = new RegExp(`^[0-9a-f]{${idLength}}$`);
|
|
85
|
+
if (!pattern.test(id)) return { error: "Usage: /quests update <id> <description>" };
|
|
75
86
|
|
|
76
87
|
const description = tokens.slice(1).join(" ").trim();
|
|
77
88
|
if (!description) return { error: "Usage: /quests update <id> <description>" };
|
|
@@ -85,10 +96,13 @@ function parseClearArgs(tokens: string[]): ParsedArgs {
|
|
|
85
96
|
return { action: QUEST_ACTIONS.clear, all };
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
function parseReorderArgs(tokens: string[]): ParsedArgs {
|
|
89
|
-
const id =
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
function parseReorderArgs(tokens: string[], idLength: number): ParsedArgs {
|
|
100
|
+
const id = tokens[0] ? tokens[0].toLowerCase() : "";
|
|
101
|
+
const targetId = tokens[1] ? tokens[1].toLowerCase() : "";
|
|
102
|
+
const pattern = new RegExp(`^[0-9a-f]{${idLength}}$`);
|
|
103
|
+
|
|
104
|
+
if (!pattern.test(id) || !pattern.test(targetId))
|
|
105
|
+
return { error: "Usage: /quests reorder <id> <targetId>" };
|
|
106
|
+
|
|
107
|
+
return { action: QUEST_ACTIONS.reorder, id, targetId };
|
|
94
108
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
4
|
+
import { getAgentDir } from "@mariozechner/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
export interface ResolvedConfig {
|
|
7
|
+
ids: { length: number };
|
|
8
|
+
display: { pageSize: number; progressBarMaxWidth: number };
|
|
9
|
+
nudges: {
|
|
10
|
+
toolCallThreshold: number;
|
|
11
|
+
hintIntervalMinutes: number;
|
|
12
|
+
timeBasedToolCallThreshold: number;
|
|
13
|
+
zeroActiveToolCallThreshold: number;
|
|
14
|
+
staleProgressToolCallThreshold: number;
|
|
15
|
+
subQuestSuggestionToolCallThreshold: number;
|
|
16
|
+
complexTaskKeywords: string[];
|
|
17
|
+
};
|
|
18
|
+
validation: { fakeDonePattern: string };
|
|
19
|
+
shortcuts?: { openQuests?: string };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_COMPLEX_TASK_KEYWORDS = [
|
|
23
|
+
"implement",
|
|
24
|
+
"refactor",
|
|
25
|
+
"investigate",
|
|
26
|
+
"review",
|
|
27
|
+
"analyze",
|
|
28
|
+
"audit",
|
|
29
|
+
"plan",
|
|
30
|
+
"design",
|
|
31
|
+
"create",
|
|
32
|
+
"build",
|
|
33
|
+
"write",
|
|
34
|
+
"fix",
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
export const DEFAULT_FAKE_DONE_PATTERN = String.raw`\s[-\u2013\u2014]\s*(DONE|COMPLETED|FINISHED)$|\s[([](DONE|COMPLETED|FINISHED)[)\]]$`;
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_CONFIG: ResolvedConfig = {
|
|
40
|
+
ids: { length: 2 },
|
|
41
|
+
display: { pageSize: 10, progressBarMaxWidth: 24 },
|
|
42
|
+
nudges: {
|
|
43
|
+
toolCallThreshold: 3,
|
|
44
|
+
hintIntervalMinutes: 8,
|
|
45
|
+
timeBasedToolCallThreshold: 3,
|
|
46
|
+
zeroActiveToolCallThreshold: 5,
|
|
47
|
+
staleProgressToolCallThreshold: 10,
|
|
48
|
+
subQuestSuggestionToolCallThreshold: 6,
|
|
49
|
+
complexTaskKeywords: [...DEFAULT_COMPLEX_TASK_KEYWORDS],
|
|
50
|
+
},
|
|
51
|
+
validation: { fakeDonePattern: DEFAULT_FAKE_DONE_PATTERN },
|
|
52
|
+
shortcuts: {},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function deepMerge(
|
|
56
|
+
target: Record<string, unknown>,
|
|
57
|
+
source: Record<string, unknown>,
|
|
58
|
+
): Record<string, unknown> {
|
|
59
|
+
const result: Record<string, unknown> = { ...target };
|
|
60
|
+
for (const key of Object.keys(source)) {
|
|
61
|
+
if (
|
|
62
|
+
source[key] &&
|
|
63
|
+
typeof source[key] === "object" &&
|
|
64
|
+
!Array.isArray(source[key]) &&
|
|
65
|
+
result[key] &&
|
|
66
|
+
typeof result[key] === "object" &&
|
|
67
|
+
!Array.isArray(result[key])
|
|
68
|
+
) {
|
|
69
|
+
result[key] = deepMerge(
|
|
70
|
+
result[key] as Record<string, unknown>,
|
|
71
|
+
source[key] as Record<string, unknown>,
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
result[key] = source[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function loadSettings(cwd: string): Record<string, unknown> {
|
|
81
|
+
const settings: Record<string, unknown> = {};
|
|
82
|
+
const globalPath = join(getAgentDir(), "settings.json");
|
|
83
|
+
if (existsSync(globalPath)) {
|
|
84
|
+
try {
|
|
85
|
+
Object.assign(settings, JSON.parse(readFileSync(globalPath, "utf-8")));
|
|
86
|
+
} catch {
|
|
87
|
+
/* ignore */
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const projectPath = join(cwd, ".pi", "settings.json");
|
|
91
|
+
if (existsSync(projectPath)) {
|
|
92
|
+
try {
|
|
93
|
+
const project = JSON.parse(readFileSync(projectPath, "utf-8")) as Record<string, unknown>;
|
|
94
|
+
if (project["pi-quests"] && typeof project["pi-quests"] === "object") {
|
|
95
|
+
const globalPiQuests =
|
|
96
|
+
settings["pi-quests"] && typeof settings["pi-quests"] === "object"
|
|
97
|
+
? (settings["pi-quests"] as Record<string, unknown>)
|
|
98
|
+
: {};
|
|
99
|
+
settings["pi-quests"] = deepMerge(
|
|
100
|
+
globalPiQuests,
|
|
101
|
+
project["pi-quests"] as Record<string, unknown>,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
/* ignore */
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return settings;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getConfig(ctx: Pick<ExtensionContext, "cwd">): ResolvedConfig {
|
|
112
|
+
const settings = loadSettings(ctx.cwd);
|
|
113
|
+
const user = (settings["pi-quests"] ?? {}) as Partial<ResolvedConfig>;
|
|
114
|
+
return {
|
|
115
|
+
ids: { length: user.ids?.length ?? DEFAULT_CONFIG.ids.length },
|
|
116
|
+
display: {
|
|
117
|
+
pageSize: user.display?.pageSize ?? DEFAULT_CONFIG.display.pageSize,
|
|
118
|
+
progressBarMaxWidth:
|
|
119
|
+
user.display?.progressBarMaxWidth ?? DEFAULT_CONFIG.display.progressBarMaxWidth,
|
|
120
|
+
},
|
|
121
|
+
nudges: {
|
|
122
|
+
toolCallThreshold: user.nudges?.toolCallThreshold ?? DEFAULT_CONFIG.nudges.toolCallThreshold,
|
|
123
|
+
hintIntervalMinutes:
|
|
124
|
+
user.nudges?.hintIntervalMinutes ?? DEFAULT_CONFIG.nudges.hintIntervalMinutes,
|
|
125
|
+
timeBasedToolCallThreshold:
|
|
126
|
+
user.nudges?.timeBasedToolCallThreshold ?? DEFAULT_CONFIG.nudges.timeBasedToolCallThreshold,
|
|
127
|
+
zeroActiveToolCallThreshold:
|
|
128
|
+
user.nudges?.zeroActiveToolCallThreshold ??
|
|
129
|
+
DEFAULT_CONFIG.nudges.zeroActiveToolCallThreshold,
|
|
130
|
+
staleProgressToolCallThreshold:
|
|
131
|
+
user.nudges?.staleProgressToolCallThreshold ??
|
|
132
|
+
DEFAULT_CONFIG.nudges.staleProgressToolCallThreshold,
|
|
133
|
+
subQuestSuggestionToolCallThreshold:
|
|
134
|
+
user.nudges?.subQuestSuggestionToolCallThreshold ??
|
|
135
|
+
DEFAULT_CONFIG.nudges.subQuestSuggestionToolCallThreshold,
|
|
136
|
+
complexTaskKeywords: [
|
|
137
|
+
...(user.nudges?.complexTaskKeywords ?? DEFAULT_CONFIG.nudges.complexTaskKeywords),
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
validation: {
|
|
141
|
+
fakeDonePattern:
|
|
142
|
+
user.validation?.fakeDonePattern ?? DEFAULT_CONFIG.validation.fakeDonePattern,
|
|
143
|
+
},
|
|
144
|
+
shortcuts: {
|
|
145
|
+
openQuests: user.shortcuts?.openQuests,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { UserMessage } from "@mariozechner/pi-ai";
|
|
2
2
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
3
|
-
import {
|
|
3
|
+
import type { KeyId } from "@mariozechner/pi-tui";
|
|
4
|
+
import { createQuestsHandler, openQuestList } from "./commands/handler.js";
|
|
5
|
+
import { DEFAULT_CONFIG, getConfig, type ResolvedConfig } from "./config.js";
|
|
6
|
+
import { logger } from "./logger.js";
|
|
4
7
|
import { QUEST_PROMPT_GATE, QUEST_PROMPT_REMINDER } from "./prompts.js";
|
|
5
8
|
import { QuestLog } from "./quest/dataplane.js";
|
|
9
|
+
import { formatQuestList } from "./quest/formatters.js";
|
|
6
10
|
import { QuestUsageTracker } from "./quest/tracker.js";
|
|
7
11
|
import { questChangelogRenderer } from "./renderers/changelog.js";
|
|
8
12
|
import { registerQuestTool } from "./tools/handler.js";
|
|
@@ -18,10 +22,42 @@ import { registerQuestTool } from "./tools/handler.js";
|
|
|
18
22
|
* - Provide rollback support to restore a previous snapshot.
|
|
19
23
|
*/
|
|
20
24
|
export default function (pi: ExtensionAPI): void {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
let questLog = new QuestLog();
|
|
26
|
+
let tracker = new QuestUsageTracker(DEFAULT_CONFIG);
|
|
27
|
+
let config: ResolvedConfig = DEFAULT_CONFIG;
|
|
28
|
+
|
|
29
|
+
const shortcutKey = getConfig({ cwd: process.cwd() }).shortcuts?.openQuests ?? "ctrl+shift+l";
|
|
30
|
+
logger.debug("quests:shortcut", "register", { key: shortcutKey });
|
|
31
|
+
pi.registerShortcut(shortcutKey as KeyId, {
|
|
32
|
+
description: "Open quest list",
|
|
33
|
+
handler: async (ctx) => {
|
|
34
|
+
logger.debug("quests:shortcut", "handler", { hasUI: ctx.hasUI });
|
|
35
|
+
if (!ctx.hasUI) {
|
|
36
|
+
logger.debug("quests:shortcut", "no-ui");
|
|
37
|
+
ctx.ui.notify("Interactive mode required", "error");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
logger.debug("quests:shortcut", "open", { questCount: questLog.getAll().length });
|
|
41
|
+
await openQuestList(pi, questLog, config, ctx);
|
|
42
|
+
logger.debug("quests:shortcut", "closed");
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
47
|
+
config = getConfig(ctx);
|
|
48
|
+
questLog = new QuestLog(config);
|
|
49
|
+
tracker = new QuestUsageTracker(config);
|
|
50
|
+
questLog.reconstructFromSession(ctx);
|
|
51
|
+
|
|
52
|
+
registerQuestTool(pi, questLog, config);
|
|
53
|
+
|
|
54
|
+
const questsHandler = createQuestsHandler(pi, questLog, config);
|
|
55
|
+
pi.registerCommand("quests", {
|
|
56
|
+
description: "Quest commands: /quests [help] to see usage",
|
|
57
|
+
handler: questsHandler,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
23
60
|
|
|
24
|
-
pi.on("session_start", async (_event, ctx) => questLog.reconstructFromSession(ctx));
|
|
25
61
|
pi.on("session_tree", async (_event, ctx) => questLog.reconstructFromSession(ctx));
|
|
26
62
|
|
|
27
63
|
pi.on("turn_start", async () => tracker.clearTurnNudge());
|
|
@@ -36,17 +72,22 @@ export default function (pi: ExtensionAPI): void {
|
|
|
36
72
|
.map((m) => (typeof m.content === "string" ? m.content : ""))
|
|
37
73
|
.join("\n");
|
|
38
74
|
|
|
39
|
-
const
|
|
40
|
-
const
|
|
75
|
+
const allQuests = questLog.getAll();
|
|
76
|
+
const activeQuests = allQuests.filter((q) => !q.done);
|
|
77
|
+
const activeQuestCount = activeQuests.length;
|
|
78
|
+
const activeTopLevel = activeQuests.filter((q) => !(q as { parentId?: string }).parentId);
|
|
79
|
+
const hasTopLevelQuestWithoutSubs = activeTopLevel.some(
|
|
80
|
+
(q) => !allQuests.some((sq) => (sq as { parentId?: string }).parentId === q.id),
|
|
81
|
+
);
|
|
82
|
+
const nudge = tracker.getNudge(activeQuestCount, latestPrompt, hasTopLevelQuestWithoutSubs);
|
|
41
83
|
|
|
42
|
-
const fakeDoneRegex =
|
|
43
|
-
/\s[-–—]\s*(DONE|COMPLETED|FINISHED)$|\s[([](DONE|COMPLETED|FINISHED)[)\]]$/i;
|
|
84
|
+
const fakeDoneRegex = new RegExp(config.validation.fakeDonePattern, "i");
|
|
44
85
|
const fakeDone = questLog.getAll().find((q) => !q.done && fakeDoneRegex.test(q.description));
|
|
45
86
|
if (!nudge && !fakeDone) return undefined;
|
|
46
87
|
|
|
47
88
|
let content = nudge ?? "";
|
|
48
89
|
if (fakeDone) {
|
|
49
|
-
content += `\nQUEST REMINDER: Quest
|
|
90
|
+
content += `\nQUEST REMINDER: Quest [${fakeDone.id}] has a completion marker appended to its description but is not toggled done. Use the toggle action to mark it done. NEVER append completion markers to descriptions via the update action.`;
|
|
50
91
|
}
|
|
51
92
|
|
|
52
93
|
const reminder: UserMessage = {
|
|
@@ -62,26 +103,16 @@ export default function (pi: ExtensionAPI): void {
|
|
|
62
103
|
let reminder = QUEST_PROMPT_REMINDER.join("\n");
|
|
63
104
|
if (quests.length > 0) {
|
|
64
105
|
const remaining = quests.filter((q) => !q.done).length;
|
|
65
|
-
const list = quests
|
|
66
|
-
.map((q) => `#${q.id} [${q.done ? "x" : " "}] ${q.description}`)
|
|
67
|
-
.join("\n");
|
|
106
|
+
const list = formatQuestList(quests);
|
|
68
107
|
|
|
69
108
|
reminder += `\n\nActive quests (${remaining}/${quests.length}):\n${list}`;
|
|
70
109
|
}
|
|
71
110
|
|
|
72
111
|
return {
|
|
73
|
-
systemPrompt: `# Quest Management\n${QUEST_PROMPT_GATE}${event.systemPrompt}\n\n## Quest Management\n${reminder}
|
|
112
|
+
systemPrompt: `# Quest Management\n${QUEST_PROMPT_GATE}${event.systemPrompt}\n\n## Quest Management\n${reminder}. Before adding any independent quests, clear any previously completed quests from the log to keep it focused on current work.`,
|
|
74
113
|
};
|
|
75
114
|
});
|
|
76
115
|
|
|
77
|
-
registerQuestTool(pi, questLog);
|
|
78
|
-
|
|
79
116
|
// Register custom message renderers
|
|
80
117
|
pi.registerMessageRenderer("quest-changelog", questChangelogRenderer);
|
|
81
|
-
|
|
82
|
-
// Register the top-level /quests command dispatcher.
|
|
83
|
-
pi.registerCommand("quests", {
|
|
84
|
-
description: "Quest commands: /quests [help] to see usage",
|
|
85
|
-
handler: createQuestsHandler(pi, questLog),
|
|
86
|
-
});
|
|
87
118
|
}
|
package/src/prompts.ts
CHANGED
|
@@ -6,10 +6,13 @@ export const QUEST_PROMPT_REMINDER = [
|
|
|
6
6
|
"When reading a skill file, implementation plan, or protocol document that contains numbered steps or checklists, add those steps as quests immediately so they are tracked, and reorder them as needed in the quest log.",
|
|
7
7
|
"It is critical that you toggle quests to done as soon as you complete them. Do NOT batch completions.",
|
|
8
8
|
"ALWAYS use the toggle action to mark a quest done. NEVER use the update action to append 'DONE', '- DONE', or any completion marker to a quest description.",
|
|
9
|
-
"
|
|
9
|
+
"ALWAYS use sub-quests to break down a complex quest into smaller steps. To create a sub-quest, use the `add` action and set `parentId` to the parent quest's hex ID. Use sub-quests for multi-step tasks, minion delegations, or when a quest has more than one distinct deliverable.",
|
|
10
|
+
"A parent quest cannot be toggled done until all of its sub-quests are completed. Sub-quests cannot be reordered independently.",
|
|
10
11
|
"Before delegating to a minion, add a quest for the delegated task.",
|
|
11
|
-
"
|
|
12
|
+
"As work evolves, use the reorder action to reflect changes in priority",
|
|
13
|
+
"For reorder, provide the targetId (the hex ID of the quest to insert before).",
|
|
12
14
|
"If you are unsure what to do next, use the list action to check active quests.",
|
|
15
|
+
"Always use the hex ID shown in brackets (e.g. 0a, ff, 44e1, f712a) for toggle, update, delete, and reorder actions.",
|
|
13
16
|
] as const;
|
|
14
17
|
|
|
15
18
|
export const QUEST_PROMPT_GATE =
|