pi-quests 0.1.0 → 0.2.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 +29 -12
- package/package.json +1 -1
- package/src/commands/changelog.ts +9 -0
- package/src/commands/handler.ts +134 -0
- package/src/commands/parse-args.ts +78 -0
- package/src/index.ts +48 -3
- package/src/logger.ts +11 -2
- package/src/quest/dataplane.ts +337 -0
- package/src/quest/formatters.ts +34 -0
- package/src/quest/tracker.ts +87 -0
- package/src/quest/types.ts +33 -0
- package/src/renderers/commands.ts +9 -2
- package/src/renderers/tools.ts +17 -22
- package/src/tools/handler.ts +100 -0
- package/src/tools/params.ts +24 -0
- package/src/version.ts +9 -2
- package/src/commands/quests.ts +0 -220
- package/src/quests.ts +0 -222
- package/src/tools/quest.ts +0 -136
package/src/tools/quest.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { StringEnum } from "@mariozechner/pi-ai";
|
|
2
|
-
import type { AgentToolResult, ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
3
|
-
import { type Static, Type } from "@sinclair/typebox";
|
|
4
|
-
import { logger } from "../logger.js";
|
|
5
|
-
import {
|
|
6
|
-
formatBatchAddResult,
|
|
7
|
-
formatClearResult,
|
|
8
|
-
formatDeleteResult,
|
|
9
|
-
formatNotFound,
|
|
10
|
-
formatQuestList,
|
|
11
|
-
formatToggleResult,
|
|
12
|
-
formatUpdateResult,
|
|
13
|
-
makeToolResult,
|
|
14
|
-
type QuestLog,
|
|
15
|
-
} from "../quests.js";
|
|
16
|
-
import { renderQuestCall, renderQuestResult } from "../renderers/tools.js";
|
|
17
|
-
|
|
18
|
-
export const QuestParams = Type.Object({
|
|
19
|
-
action: StringEnum(["add", "list", "toggle", "update", "delete", "clear", "revert"] as const),
|
|
20
|
-
description: Type.Optional(Type.String()),
|
|
21
|
-
descriptions: Type.Optional(Type.Array(Type.String())),
|
|
22
|
-
id: Type.Optional(Type.Number()),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export async function questToolExecute(
|
|
26
|
-
questLog: QuestLog,
|
|
27
|
-
toolCallId: string,
|
|
28
|
-
params: Static<typeof QuestParams>,
|
|
29
|
-
): Promise<AgentToolResult<unknown>> {
|
|
30
|
-
logger.debug("quests:tool", "execute", { toolCallId, action: params.action, id: params.id });
|
|
31
|
-
|
|
32
|
-
switch (params.action) {
|
|
33
|
-
case "add": {
|
|
34
|
-
if (params.descriptions && params.descriptions.length > 0) {
|
|
35
|
-
logger.debug("quests:tool", "add-batch", { count: params.descriptions.length, toolCallId });
|
|
36
|
-
const added: { id: number; description: string }[] = [];
|
|
37
|
-
for (const desc of params.descriptions) {
|
|
38
|
-
const q = questLog.add(desc);
|
|
39
|
-
added.push({ id: q.id, description: q.description });
|
|
40
|
-
}
|
|
41
|
-
logger.debug("quests:tool", "add-batch-complete", { toolCallId, added: added.length });
|
|
42
|
-
return makeToolResult(formatBatchAddResult(added), questLog);
|
|
43
|
-
}
|
|
44
|
-
if (!params.description) {
|
|
45
|
-
logger.debug("quests:tool", "add-missing-description", { toolCallId });
|
|
46
|
-
return makeToolResult("Error: description is required for add action", questLog);
|
|
47
|
-
}
|
|
48
|
-
const q = questLog.add(params.description);
|
|
49
|
-
logger.debug("quests:tool", "add-complete", { toolCallId, id: q.id });
|
|
50
|
-
return makeToolResult(`Added quest #${q.id}: ${q.description}`, questLog);
|
|
51
|
-
}
|
|
52
|
-
case "list": {
|
|
53
|
-
const quests = questLog.getAll();
|
|
54
|
-
logger.debug("quests:tool", "list", { toolCallId, count: quests.length });
|
|
55
|
-
return makeToolResult(formatQuestList(quests), questLog);
|
|
56
|
-
}
|
|
57
|
-
case "toggle": {
|
|
58
|
-
if (params.id === undefined) {
|
|
59
|
-
logger.debug("quests:tool", "toggle-missing-id", { toolCallId });
|
|
60
|
-
return makeToolResult("Error: id is required for toggle action", questLog);
|
|
61
|
-
}
|
|
62
|
-
const q = questLog.toggle(params.id);
|
|
63
|
-
if (!q) {
|
|
64
|
-
logger.debug("quests:tool", "toggle-not-found", { toolCallId, id: params.id });
|
|
65
|
-
return makeToolResult(formatNotFound(params.id), questLog);
|
|
66
|
-
}
|
|
67
|
-
logger.debug("quests:tool", "toggle-complete", {
|
|
68
|
-
toolCallId,
|
|
69
|
-
id: params.id,
|
|
70
|
-
state: q.done,
|
|
71
|
-
});
|
|
72
|
-
return makeToolResult(formatToggleResult(params.id, q.done), questLog);
|
|
73
|
-
}
|
|
74
|
-
case "update": {
|
|
75
|
-
if (params.id === undefined) {
|
|
76
|
-
logger.debug("quests:tool", "update-missing-id", { toolCallId });
|
|
77
|
-
return makeToolResult("Error: id is required for update action", questLog);
|
|
78
|
-
}
|
|
79
|
-
if (!params.description) {
|
|
80
|
-
logger.debug("quests:tool", "update-missing-description", { toolCallId, id: params.id });
|
|
81
|
-
return makeToolResult("Error: description is required for update action", questLog);
|
|
82
|
-
}
|
|
83
|
-
const q = questLog.update(params.id, params.description);
|
|
84
|
-
if (!q) {
|
|
85
|
-
logger.debug("quests:tool", "update-not-found", { toolCallId, id: params.id });
|
|
86
|
-
return makeToolResult(formatNotFound(params.id), questLog);
|
|
87
|
-
}
|
|
88
|
-
logger.debug("quests:tool", "update-complete", { toolCallId, id: params.id });
|
|
89
|
-
return makeToolResult(formatUpdateResult(q), questLog);
|
|
90
|
-
}
|
|
91
|
-
case "delete": {
|
|
92
|
-
if (params.id === undefined) {
|
|
93
|
-
logger.debug("quests:tool", "delete-missing-id", { toolCallId });
|
|
94
|
-
return makeToolResult("Error: id is required for delete action", questLog);
|
|
95
|
-
}
|
|
96
|
-
const q = questLog.delete(params.id);
|
|
97
|
-
if (!q) {
|
|
98
|
-
logger.debug("quests:tool", "delete-not-found", { toolCallId, id: params.id });
|
|
99
|
-
return makeToolResult(formatNotFound(params.id), questLog);
|
|
100
|
-
}
|
|
101
|
-
logger.debug("quests:tool", "delete-complete", { toolCallId, id: params.id });
|
|
102
|
-
return makeToolResult(formatDeleteResult(q), questLog);
|
|
103
|
-
}
|
|
104
|
-
case "clear": {
|
|
105
|
-
const count = questLog.clear();
|
|
106
|
-
logger.debug("quests:tool", "clear-complete", { toolCallId, count });
|
|
107
|
-
return makeToolResult(formatClearResult(count), questLog);
|
|
108
|
-
}
|
|
109
|
-
case "revert": {
|
|
110
|
-
const result = questLog.revert();
|
|
111
|
-
logger.debug("quests:tool", "revert-complete", { toolCallId, success: result.success });
|
|
112
|
-
return makeToolResult(result.message, questLog);
|
|
113
|
-
}
|
|
114
|
-
default: {
|
|
115
|
-
logger.debug("quests:tool", "unknown-action", {
|
|
116
|
-
toolCallId,
|
|
117
|
-
action: (params as { action: string }).action,
|
|
118
|
-
});
|
|
119
|
-
return makeToolResult(`Unknown action: ${(params as { action: string }).action}`, questLog);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function registerQuestTool(pi: ExtensionAPI, questLog: QuestLog): void {
|
|
125
|
-
logger.debug("quests:tool", "register");
|
|
126
|
-
pi.registerTool({
|
|
127
|
-
name: "quest",
|
|
128
|
-
label: "Quest",
|
|
129
|
-
description: "Manage the session quest log",
|
|
130
|
-
parameters: QuestParams,
|
|
131
|
-
execute: (toolCallId, params, _signal, _onUpdate, _ctx) =>
|
|
132
|
-
questToolExecute(questLog, toolCallId, params),
|
|
133
|
-
renderCall: renderQuestCall,
|
|
134
|
-
renderResult: renderQuestResult,
|
|
135
|
-
});
|
|
136
|
-
}
|