klaus-agent 0.2.2 → 0.3.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.
@@ -0,0 +1,71 @@
1
+ // Planning tools — todo management + phase switching
2
+
3
+ import { Type } from "@sinclair/typebox";
4
+ import type { AgentTool, AgentToolResult } from "../tools/types.js";
5
+ import type { PlanningManager } from "./planning-manager.js";
6
+ import { PLANNING_TOOL_NAMES } from "./types.js";
7
+ import type { TodoStatus } from "./types.js";
8
+
9
+ export function createPlanningTools(manager: PlanningManager): AgentTool[] {
10
+ return [
11
+ {
12
+ name: PLANNING_TOOL_NAMES.todo,
13
+ label: "Todo",
14
+ description:
15
+ "Manage your task list. Use this tool to plan work, track progress, and stay on track. " +
16
+ "Only one todo can be in_progress at a time. Update todos frequently to reflect your current state.",
17
+ parameters: Type.Object({
18
+ items: Type.Array(
19
+ Type.Object({
20
+ id: Type.String({ description: "Unique ID for the todo item." }),
21
+ text: Type.String({ description: "Description of the task." }),
22
+ status: Type.Union(
23
+ [Type.Literal("pending"), Type.Literal("in_progress"), Type.Literal("completed")],
24
+ { description: "Task status. Only one item can be in_progress at a time." },
25
+ ),
26
+ }),
27
+ { description: "The full updated todo list (replaces previous list)." },
28
+ ),
29
+ }),
30
+ async execute(
31
+ _toolCallId: string,
32
+ params: { items: Array<{ id: string; text: string; status: TodoStatus }> },
33
+ ): Promise<AgentToolResult> {
34
+ const result = manager.updateTodos(params.items);
35
+ return { content: [{ type: "text", text: result }] };
36
+ },
37
+ },
38
+ {
39
+ name: PLANNING_TOOL_NAMES.planMode,
40
+ label: "Plan Mode",
41
+ description:
42
+ "Switch between planning and execution phases. " +
43
+ "In planning phase, only read-only tools are available — use this time to analyze and create todos. " +
44
+ "In execution phase, all tools are available and nag reminders will prompt you to update todos.",
45
+ parameters: Type.Object({
46
+ action: Type.Union(
47
+ [Type.Literal("start_execution"), Type.Literal("switch_to_planning"), Type.Literal("status")],
48
+ { description: "Action to perform." },
49
+ ),
50
+ }),
51
+ async execute(
52
+ _toolCallId: string,
53
+ params: { action: "start_execution" | "switch_to_planning" | "status" },
54
+ ): Promise<AgentToolResult> {
55
+ let result: string;
56
+ switch (params.action) {
57
+ case "start_execution":
58
+ result = manager.startExecution();
59
+ break;
60
+ case "switch_to_planning":
61
+ result = manager.switchToPlanning();
62
+ break;
63
+ case "status":
64
+ result = manager.render();
65
+ break;
66
+ }
67
+ return { content: [{ type: "text", text: result }] };
68
+ },
69
+ },
70
+ ];
71
+ }
@@ -0,0 +1,40 @@
1
+ // Planning module types — two-phase planning + structured todo tracking
2
+
3
+ export const PLANNING_TOOL_NAMES = {
4
+ todo: "todo",
5
+ planMode: "plan_mode",
6
+ } as const;
7
+
8
+ export type TodoStatus = "pending" | "in_progress" | "completed";
9
+
10
+ export interface TodoItem {
11
+ id: string;
12
+ text: string;
13
+ status: TodoStatus;
14
+ }
15
+
16
+ export type PlanPhase = "planning" | "executing";
17
+
18
+ export interface PlanningState {
19
+ phase: PlanPhase;
20
+ todos: TodoItem[];
21
+ roundsSinceTodoUpdate: number;
22
+ }
23
+
24
+ export interface PlanningConfig {
25
+ /**
26
+ * Tool names allowed during the planning phase (read-only tools).
27
+ * If omitted or empty, all tools are available during planning
28
+ * (phase separation is advisory only via system prompt).
29
+ */
30
+ readOnlyTools?: string[];
31
+
32
+ /** Number of rounds without a todo update before injecting a nag reminder. Default: 3. */
33
+ nagAfterRounds?: number;
34
+
35
+ /** Custom nag reminder text. */
36
+ nagMessage?: string;
37
+
38
+ /** Maximum number of todo items. Default: 50. */
39
+ maxTodos?: number;
40
+ }