@hank-warren/pi-plan-mode 0.1.0 → 1.0.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.
@@ -1,98 +0,0 @@
1
- import type { ToolInfo } from "@earendil-works/pi-coding-agent";
2
- import { PLAN_MODE_COMPLETE_TOOL_NAME } from "./completion-tool.js";
3
- import { PLAN_MODE_QUESTION_TOOL_NAME } from "./question-tool.js";
4
- import { withRequiredPlanModeTools } from "./required-tools.js";
5
- import {
6
- canSelectToolInPlanMode,
7
- classifyPlanModeTool,
8
- isBuiltinTool,
9
- SAFE_BUILTIN_PLAN_TOOLS,
10
- } from "./tool-policy.js";
11
-
12
- export function toolNameFromLegacyKey(key: string, tools: ToolInfo[]) {
13
- const directName = tools.find((tool) => tool.name === key)?.name;
14
- if (directName) return directName;
15
- const [name] = key.split("\u001f");
16
- return tools.find((tool) => tool.name === name) ? name : undefined;
17
- }
18
-
19
- export function compareTools(left: ToolInfo, right: ToolInfo) {
20
- const leftBuiltin = isBuiltinTool(left);
21
- const rightBuiltin = isBuiltinTool(right);
22
- if (leftBuiltin !== rightBuiltin) return leftBuiltin ? -1 : 1;
23
- return left.name.localeCompare(right.name);
24
- }
25
-
26
- export function toolPolicyLabel(tool: ToolInfo) {
27
- const policy = classifyPlanModeTool(tool);
28
- if (policy === "read-only") return "built-in read-only";
29
- if (policy === "limited") return "built-in limited";
30
- if (policy === "blocked") return "built-in blocked";
31
- return `user opt-in: ${toolSourceLabel(tool)}`;
32
- }
33
-
34
- function toolSourceLabel(tool: ToolInfo) {
35
- const sourceInfo = tool.sourceInfo;
36
- const source = `${sourceInfo.scope}/${sourceInfo.source}`;
37
- return sourceInfo.path ? `${source} ${sourceInfo.path}` : source;
38
- }
39
-
40
- export function unique(values: string[]) {
41
- return Array.from(new Set(values));
42
- }
43
-
44
- export function filterAvailableSelectedToolNames(names: string[], tools: ToolInfo[]) {
45
- const availableNames = new Set(tools.filter(canSelectToolInPlanMode).map((tool) => tool.name));
46
- return unique(names.filter((name) => availableNames.has(name)));
47
- }
48
-
49
- export function defaultPlanModeToolNames(tools: ToolInfo[], configuredNames: string[] | undefined) {
50
- if (configuredNames !== undefined) {
51
- return filterAvailableSelectedToolNames(configuredNames, tools);
52
- }
53
- return tools
54
- .filter((tool) => isBuiltinTool(tool) && SAFE_BUILTIN_PLAN_TOOLS.has(tool.name))
55
- .map((tool) => tool.name);
56
- }
57
-
58
- interface PlanModeToolSelectionSnapshot {
59
- selectedToolNames?: string[];
60
- selectedToolKeys?: string[];
61
- defaultPlanTools?: string[];
62
- }
63
-
64
- export function snapshotPlanModeSelectedNames(
65
- tools: ToolInfo[],
66
- selection: PlanModeToolSelectionSnapshot,
67
- ) {
68
- const selectedToolNames =
69
- selection.selectedToolNames ??
70
- selection.selectedToolKeys
71
- ?.map((key) => toolNameFromLegacyKey(key, tools))
72
- .filter((name): name is string => name !== undefined);
73
- return new Set(
74
- selectedToolNames === undefined
75
- ? defaultPlanModeToolNames(tools, selection.defaultPlanTools)
76
- : filterAvailableSelectedToolNames(selectedToolNames, tools),
77
- );
78
- }
79
-
80
- export function snapshotPlanModeToolNames(
81
- tools: ToolInfo[],
82
- selectedNames: ReadonlySet<string>,
83
- selection: PlanModeToolSelectionSnapshot,
84
- ) {
85
- if (
86
- tools.length === 0 &&
87
- selection.selectedToolNames === undefined &&
88
- selection.selectedToolKeys === undefined &&
89
- selection.defaultPlanTools === undefined
90
- ) {
91
- return ["read", "bash", PLAN_MODE_QUESTION_TOOL_NAME, PLAN_MODE_COMPLETE_TOOL_NAME];
92
- }
93
- return withRequiredPlanModeTools(
94
- tools
95
- .filter((tool) => selectedNames.has(tool.name) && canSelectToolInPlanMode(tool))
96
- .map((tool) => tool.name),
97
- );
98
- }