gencode-ai 0.1.2 → 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/README.md +15 -17
- package/dist/agent/agent.d.ts +43 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +107 -4
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/types.d.ts +20 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/checkpointing/checkpoint-manager.d.ts +87 -0
- package/dist/checkpointing/checkpoint-manager.d.ts.map +1 -0
- package/dist/checkpointing/checkpoint-manager.js +281 -0
- package/dist/checkpointing/checkpoint-manager.js.map +1 -0
- package/dist/checkpointing/index.d.ts +29 -0
- package/dist/checkpointing/index.d.ts.map +1 -0
- package/dist/checkpointing/index.js +29 -0
- package/dist/checkpointing/index.js.map +1 -0
- package/dist/checkpointing/types.d.ts +98 -0
- package/dist/checkpointing/types.d.ts.map +1 -0
- package/dist/checkpointing/types.js +7 -0
- package/dist/checkpointing/types.js.map +1 -0
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +193 -7
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -1
- package/dist/cli/components/CommandSuggestions.js +5 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -1
- package/dist/cli/components/Messages.d.ts +7 -1
- package/dist/cli/components/Messages.d.ts.map +1 -1
- package/dist/cli/components/Messages.js +28 -2
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/components/ModeIndicator.d.ts +42 -0
- package/dist/cli/components/ModeIndicator.d.ts.map +1 -0
- package/dist/cli/components/ModeIndicator.js +52 -0
- package/dist/cli/components/ModeIndicator.js.map +1 -0
- package/dist/cli/components/PlanApproval.d.ts +36 -0
- package/dist/cli/components/PlanApproval.d.ts.map +1 -0
- package/dist/cli/components/PlanApproval.js +154 -0
- package/dist/cli/components/PlanApproval.js.map +1 -0
- package/dist/cli/components/QuestionPrompt.d.ts +23 -0
- package/dist/cli/components/QuestionPrompt.d.ts.map +1 -0
- package/dist/cli/components/QuestionPrompt.js +231 -0
- package/dist/cli/components/QuestionPrompt.js.map +1 -0
- package/dist/cli/components/index.d.ts +1 -0
- package/dist/cli/components/index.d.ts.map +1 -1
- package/dist/cli/components/index.js +1 -0
- package/dist/cli/components/index.js.map +1 -1
- package/dist/cli/components/theme.d.ts +9 -0
- package/dist/cli/components/theme.d.ts.map +1 -1
- package/dist/cli/components/theme.js +14 -1
- package/dist/cli/components/theme.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/permissions/types.d.ts.map +1 -1
- package/dist/permissions/types.js +2 -0
- package/dist/permissions/types.js.map +1 -1
- package/dist/planning/index.d.ts +13 -0
- package/dist/planning/index.d.ts.map +1 -0
- package/dist/planning/index.js +15 -0
- package/dist/planning/index.js.map +1 -0
- package/dist/planning/plan-file.d.ts +59 -0
- package/dist/planning/plan-file.d.ts.map +1 -0
- package/dist/planning/plan-file.js +278 -0
- package/dist/planning/plan-file.js.map +1 -0
- package/dist/planning/state.d.ts +127 -0
- package/dist/planning/state.d.ts.map +1 -0
- package/dist/planning/state.js +261 -0
- package/dist/planning/state.js.map +1 -0
- package/dist/planning/tools/enter-plan-mode.d.ts +25 -0
- package/dist/planning/tools/enter-plan-mode.d.ts.map +1 -0
- package/dist/planning/tools/enter-plan-mode.js +98 -0
- package/dist/planning/tools/enter-plan-mode.js.map +1 -0
- package/dist/planning/tools/exit-plan-mode.d.ts +24 -0
- package/dist/planning/tools/exit-plan-mode.d.ts.map +1 -0
- package/dist/planning/tools/exit-plan-mode.js +149 -0
- package/dist/planning/tools/exit-plan-mode.js.map +1 -0
- package/dist/planning/types.d.ts +100 -0
- package/dist/planning/types.d.ts.map +1 -0
- package/dist/planning/types.js +28 -0
- package/dist/planning/types.js.map +1 -0
- package/dist/pricing/calculator.d.ts +21 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +59 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/index.d.ts +7 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +7 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/models.d.ts +20 -0
- package/dist/pricing/models.d.ts.map +1 -0
- package/dist/pricing/models.js +322 -0
- package/dist/pricing/models.js.map +1 -0
- package/dist/pricing/types.d.ts +30 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +5 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +17 -10
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +21 -14
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +12 -8
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/types.d.ts +2 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/vertex-ai.d.ts.map +1 -1
- package/dist/providers/vertex-ai.js +17 -10
- package/dist/providers/vertex-ai.js.map +1 -1
- package/dist/session/manager.d.ts +4 -0
- package/dist/session/manager.d.ts.map +1 -1
- package/dist/session/manager.js +8 -0
- package/dist/session/manager.js.map +1 -1
- package/dist/tools/builtin/ask-user.d.ts +64 -0
- package/dist/tools/builtin/ask-user.d.ts.map +1 -0
- package/dist/tools/builtin/ask-user.js +148 -0
- package/dist/tools/builtin/ask-user.js.map +1 -0
- package/dist/tools/index.d.ts +19 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/registry.d.ts +13 -0
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +79 -2
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/types.d.ts +17 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/docs/cost-tracking-comparison.md +904 -0
- package/docs/operating-modes.md +96 -0
- package/docs/proposals/0012-ask-user-question.md +66 -1
- package/docs/proposals/0025-cost-tracking.md +60 -2
- package/docs/proposals/README.md +2 -2
- package/examples/test-ask-user.ts +167 -0
- package/examples/test-checkpointing.ts +121 -0
- package/examples/test-cost-tracking.ts +77 -0
- package/examples/test-interrupt-cleanup.ts +94 -0
- package/package.json +1 -1
- package/src/agent/agent.ts +130 -4
- package/src/agent/index.ts +1 -0
- package/src/agent/types.ts +19 -1
- package/src/checkpointing/checkpoint-manager.ts +327 -0
- package/src/checkpointing/index.ts +45 -0
- package/src/checkpointing/types.ts +104 -0
- package/src/cli/components/App.tsx +259 -8
- package/src/cli/components/CommandSuggestions.tsx +5 -0
- package/src/cli/components/Messages.tsx +66 -4
- package/src/cli/components/ModeIndicator.tsx +174 -0
- package/src/cli/components/PlanApproval.tsx +327 -0
- package/src/cli/components/QuestionPrompt.tsx +462 -0
- package/src/cli/components/index.ts +1 -0
- package/src/cli/components/theme.ts +14 -1
- package/src/index.ts +15 -0
- package/src/permissions/types.ts +2 -0
- package/src/planning/index.ts +53 -0
- package/src/planning/plan-file.ts +326 -0
- package/src/planning/state.ts +305 -0
- package/src/planning/tools/enter-plan-mode.ts +111 -0
- package/src/planning/tools/exit-plan-mode.ts +170 -0
- package/src/planning/types.ts +150 -0
- package/src/pricing/calculator.ts +71 -0
- package/src/pricing/index.ts +7 -0
- package/src/pricing/models.ts +334 -0
- package/src/pricing/types.ts +32 -0
- package/src/prompts/system/base.txt +42 -0
- package/src/prompts/tools/ask-user.txt +110 -0
- package/src/providers/anthropic.ts +21 -10
- package/src/providers/gemini.ts +25 -14
- package/src/providers/openai.ts +17 -8
- package/src/providers/types.ts +3 -0
- package/src/providers/vertex-ai.ts +21 -10
- package/src/session/manager.ts +9 -0
- package/src/tools/builtin/ask-user.ts +185 -0
- package/src/tools/index.ts +23 -0
- package/src/tools/registry.ts +95 -2
- package/src/tools/types.ts +18 -0
- package/.gencode/settings.local.json +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/planning/state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,QAAQ,EACR,aAAa,EACd,MAAM,YAAY,CAAC;AAOpB;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,cAAc,CAAsC;;IAO5D;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,QAAQ,IAAI,QAAQ,CAAC,aAAa,CAAC;IAInC;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;;OAGG;IACH,cAAc,IAAI,QAAQ;IAI1B;;OAEG;IACH,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAa3D;;OAEG;IACH,IAAI,CAAC,QAAQ,GAAE,OAAe,GAAG,IAAI;IASrC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IASnC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAOhC;;OAEG;IACH,QAAQ,IAAI,SAAS;IAIrB;;OAEG;IACH,uBAAuB,CAAC,WAAW,EAAE,aAAa,EAAE,GAAG,IAAI;IAI3D;;OAEG;IACH,uBAAuB,IAAI,aAAa,EAAE;IAI1C;;OAEG;IACH,eAAe,IAAI,MAAM,GAAG,IAAI;IAQhC;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IASxC;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQxC;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAO3B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAO3B;;OAEG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAY1C;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAO/D;;OAEG;IACH,OAAO,CAAC,IAAI;CASb;AAWD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CAKpD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAK3C;AAMD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAEzC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAElF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,GAAE,OAAe,GAAG,IAAI,CAE5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Mode State Management
|
|
3
|
+
*
|
|
4
|
+
* Singleton state manager for plan mode. Tracks whether plan mode
|
|
5
|
+
* is active, current phase, and manages tool filtering.
|
|
6
|
+
*/
|
|
7
|
+
import { PLAN_MODE_ALLOWED_TOOLS, PLAN_MODE_BLOCKED_TOOLS } from './types.js';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// State Manager
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Plan Mode State Manager
|
|
13
|
+
*
|
|
14
|
+
* Manages the plan mode state and provides methods for:
|
|
15
|
+
* - Entering/exiting plan mode
|
|
16
|
+
* - Phase transitions
|
|
17
|
+
* - Tool filtering
|
|
18
|
+
* - Event notifications
|
|
19
|
+
*/
|
|
20
|
+
export class PlanModeManager {
|
|
21
|
+
state;
|
|
22
|
+
eventListeners;
|
|
23
|
+
constructor() {
|
|
24
|
+
this.state = this.getInitialState();
|
|
25
|
+
this.eventListeners = new Set();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get initial state
|
|
29
|
+
*/
|
|
30
|
+
getInitialState() {
|
|
31
|
+
return {
|
|
32
|
+
active: false,
|
|
33
|
+
phase: 'understanding',
|
|
34
|
+
planFilePath: null,
|
|
35
|
+
originalRequest: null,
|
|
36
|
+
requestedPermissions: [],
|
|
37
|
+
enteredAt: null,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get current state (readonly)
|
|
42
|
+
*/
|
|
43
|
+
getState() {
|
|
44
|
+
return { ...this.state };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if plan mode is active
|
|
48
|
+
*/
|
|
49
|
+
isActive() {
|
|
50
|
+
return this.state.active;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get current mode type for UI
|
|
54
|
+
* Note: Returns 'plan' or 'normal'. 'accept' mode is managed at the App level.
|
|
55
|
+
*/
|
|
56
|
+
getCurrentMode() {
|
|
57
|
+
return this.state.active ? 'plan' : 'normal';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Enter plan mode
|
|
61
|
+
*/
|
|
62
|
+
enter(planFilePath, originalRequest) {
|
|
63
|
+
this.state = {
|
|
64
|
+
active: true,
|
|
65
|
+
phase: 'understanding',
|
|
66
|
+
planFilePath,
|
|
67
|
+
originalRequest: originalRequest ?? null,
|
|
68
|
+
requestedPermissions: [],
|
|
69
|
+
enteredAt: new Date(),
|
|
70
|
+
};
|
|
71
|
+
this.emit({ type: 'enter', planFilePath });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Exit plan mode
|
|
75
|
+
*/
|
|
76
|
+
exit(approved = false) {
|
|
77
|
+
const wasActive = this.state.active;
|
|
78
|
+
this.state = this.getInitialState();
|
|
79
|
+
if (wasActive) {
|
|
80
|
+
this.emit({ type: 'exit', approved });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Toggle plan mode (for Shift+Tab)
|
|
85
|
+
*/
|
|
86
|
+
toggle(planFilePath) {
|
|
87
|
+
if (this.state.active) {
|
|
88
|
+
this.exit(false);
|
|
89
|
+
}
|
|
90
|
+
else if (planFilePath) {
|
|
91
|
+
this.enter(planFilePath);
|
|
92
|
+
}
|
|
93
|
+
this.emit({ type: 'toggle' });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Update phase
|
|
97
|
+
*/
|
|
98
|
+
setPhase(phase) {
|
|
99
|
+
if (this.state.active) {
|
|
100
|
+
this.state.phase = phase;
|
|
101
|
+
this.emit({ type: 'phase_change', phase });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get current phase
|
|
106
|
+
*/
|
|
107
|
+
getPhase() {
|
|
108
|
+
return this.state.phase;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set requested permissions (from ExitPlanMode)
|
|
112
|
+
*/
|
|
113
|
+
setRequestedPermissions(permissions) {
|
|
114
|
+
this.state.requestedPermissions = permissions;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get requested permissions
|
|
118
|
+
*/
|
|
119
|
+
getRequestedPermissions() {
|
|
120
|
+
return [...this.state.requestedPermissions];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get plan file path
|
|
124
|
+
*/
|
|
125
|
+
getPlanFilePath() {
|
|
126
|
+
return this.state.planFilePath;
|
|
127
|
+
}
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// Tool Filtering
|
|
130
|
+
// ============================================================================
|
|
131
|
+
/**
|
|
132
|
+
* Check if a tool is allowed in the current mode
|
|
133
|
+
*/
|
|
134
|
+
isToolAllowed(toolName) {
|
|
135
|
+
if (!this.state.active) {
|
|
136
|
+
return true; // All tools allowed in build mode
|
|
137
|
+
}
|
|
138
|
+
// In plan mode, only allow read-only tools
|
|
139
|
+
return PLAN_MODE_ALLOWED_TOOLS.includes(toolName);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if a tool is blocked in the current mode
|
|
143
|
+
*/
|
|
144
|
+
isToolBlocked(toolName) {
|
|
145
|
+
if (!this.state.active) {
|
|
146
|
+
return false; // No tools blocked in build mode
|
|
147
|
+
}
|
|
148
|
+
return PLAN_MODE_BLOCKED_TOOLS.includes(toolName);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get list of allowed tools for current mode
|
|
152
|
+
*/
|
|
153
|
+
getAllowedTools() {
|
|
154
|
+
if (!this.state.active) {
|
|
155
|
+
return []; // Empty means all allowed
|
|
156
|
+
}
|
|
157
|
+
return [...PLAN_MODE_ALLOWED_TOOLS];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get list of blocked tools for current mode
|
|
161
|
+
*/
|
|
162
|
+
getBlockedTools() {
|
|
163
|
+
if (!this.state.active) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
return [...PLAN_MODE_BLOCKED_TOOLS];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Filter tool list based on current mode
|
|
170
|
+
*/
|
|
171
|
+
filterTools(toolNames) {
|
|
172
|
+
if (!this.state.active) {
|
|
173
|
+
return toolNames;
|
|
174
|
+
}
|
|
175
|
+
return toolNames.filter((name) => this.isToolAllowed(name));
|
|
176
|
+
}
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// Event System
|
|
179
|
+
// ============================================================================
|
|
180
|
+
/**
|
|
181
|
+
* Subscribe to plan mode events
|
|
182
|
+
*/
|
|
183
|
+
subscribe(listener) {
|
|
184
|
+
this.eventListeners.add(listener);
|
|
185
|
+
return () => {
|
|
186
|
+
this.eventListeners.delete(listener);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Emit an event to all listeners
|
|
191
|
+
*/
|
|
192
|
+
emit(event) {
|
|
193
|
+
for (const listener of this.eventListeners) {
|
|
194
|
+
try {
|
|
195
|
+
listener(event);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
console.error('Error in plan mode event listener:', error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// ============================================================================
|
|
204
|
+
// Singleton Instance
|
|
205
|
+
// ============================================================================
|
|
206
|
+
/**
|
|
207
|
+
* Global plan mode manager instance
|
|
208
|
+
*/
|
|
209
|
+
let globalPlanModeManager = null;
|
|
210
|
+
/**
|
|
211
|
+
* Get the global plan mode manager
|
|
212
|
+
*/
|
|
213
|
+
export function getPlanModeManager() {
|
|
214
|
+
if (!globalPlanModeManager) {
|
|
215
|
+
globalPlanModeManager = new PlanModeManager();
|
|
216
|
+
}
|
|
217
|
+
return globalPlanModeManager;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Reset the global plan mode manager (for testing)
|
|
221
|
+
*/
|
|
222
|
+
export function resetPlanModeManager() {
|
|
223
|
+
if (globalPlanModeManager) {
|
|
224
|
+
globalPlanModeManager.exit(false);
|
|
225
|
+
}
|
|
226
|
+
globalPlanModeManager = null;
|
|
227
|
+
}
|
|
228
|
+
// ============================================================================
|
|
229
|
+
// Convenience Functions
|
|
230
|
+
// ============================================================================
|
|
231
|
+
/**
|
|
232
|
+
* Check if plan mode is currently active
|
|
233
|
+
*/
|
|
234
|
+
export function isPlanModeActive() {
|
|
235
|
+
return getPlanModeManager().isActive();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get the current mode type
|
|
239
|
+
*/
|
|
240
|
+
export function getCurrentMode() {
|
|
241
|
+
return getPlanModeManager().getCurrentMode();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Enter plan mode
|
|
245
|
+
*/
|
|
246
|
+
export function enterPlanMode(planFilePath, originalRequest) {
|
|
247
|
+
getPlanModeManager().enter(planFilePath, originalRequest);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Exit plan mode
|
|
251
|
+
*/
|
|
252
|
+
export function exitPlanMode(approved = false) {
|
|
253
|
+
getPlanModeManager().exit(approved);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Toggle plan mode
|
|
257
|
+
*/
|
|
258
|
+
export function togglePlanMode(planFilePath) {
|
|
259
|
+
getPlanModeManager().toggle(planFilePath);
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/planning/state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE9E,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAClB,KAAK,CAAgB;IACrB,cAAc,CAAsC;IAE5D;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,eAAe;QACrB,OAAO;YACL,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,IAAI;YACrB,oBAAoB,EAAE,EAAE;YACxB,SAAS,EAAE,IAAI;SAChB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED;;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AAI,eAAe,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,qBAAqB,EAAE,CAAC;QAC1B,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,qBAAqB,GAAG,IAAI,CAAC;AAC/B,CAAC;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,kBAAkB,EAAE,CAAC,QAAQ,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,kBAAkB,EAAE,CAAC,cAAc,EAAE,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,YAAoB,EAAE,eAAwB;IAC1E,kBAAkB,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAAoB,KAAK;IACpD,kBAAkB,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,YAAqB;IAClD,kBAAkB,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Transitions the agent into plan mode for designing implementation
|
|
5
|
+
* approaches before writing code. In plan mode, only read-only tools
|
|
6
|
+
* are available.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import type { Tool } from '../../tools/types.js';
|
|
10
|
+
declare const EnterPlanModeInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
11
|
+
export type EnterPlanModeInput = z.infer<typeof EnterPlanModeInputSchema>;
|
|
12
|
+
/**
|
|
13
|
+
* EnterPlanMode Tool
|
|
14
|
+
*
|
|
15
|
+
* Use this tool when you need to plan an implementation before writing code.
|
|
16
|
+
* This is recommended for:
|
|
17
|
+
* - New feature implementations
|
|
18
|
+
* - Tasks with multiple valid approaches
|
|
19
|
+
* - Architectural decisions
|
|
20
|
+
* - Multi-file changes
|
|
21
|
+
* - Unclear requirements
|
|
22
|
+
*/
|
|
23
|
+
export declare const enterPlanModeTool: Tool<EnterPlanModeInput>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=enter-plan-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enter-plan-mode.d.ts","sourceRoot":"","sources":["../../../src/planning/tools/enter-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,sBAAsB,CAAC;AAS1E,QAAA,MAAM,wBAAwB,gCAAe,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,EAAE,IAAI,CAAC,kBAAkB,CA6EtD,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Transitions the agent into plan mode for designing implementation
|
|
5
|
+
* approaches before writing code. In plan mode, only read-only tools
|
|
6
|
+
* are available.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { getPlanModeManager } from '../state.js';
|
|
10
|
+
import { createPlanFile, getDisplayPath } from '../plan-file.js';
|
|
11
|
+
import { PLAN_MODE_ALLOWED_TOOLS, PLAN_MODE_BLOCKED_TOOLS } from '../types.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Tool Definition
|
|
14
|
+
// ============================================================================
|
|
15
|
+
const EnterPlanModeInputSchema = z.object({});
|
|
16
|
+
/**
|
|
17
|
+
* EnterPlanMode Tool
|
|
18
|
+
*
|
|
19
|
+
* Use this tool when you need to plan an implementation before writing code.
|
|
20
|
+
* This is recommended for:
|
|
21
|
+
* - New feature implementations
|
|
22
|
+
* - Tasks with multiple valid approaches
|
|
23
|
+
* - Architectural decisions
|
|
24
|
+
* - Multi-file changes
|
|
25
|
+
* - Unclear requirements
|
|
26
|
+
*/
|
|
27
|
+
export const enterPlanModeTool = {
|
|
28
|
+
name: 'EnterPlanMode',
|
|
29
|
+
description: `Transition into plan mode to design an implementation approach before writing code.
|
|
30
|
+
|
|
31
|
+
Use this tool when:
|
|
32
|
+
- Implementing new features that require design decisions
|
|
33
|
+
- Tasks with multiple valid approaches
|
|
34
|
+
- Changes that affect existing behavior or structure
|
|
35
|
+
- Architectural decisions between patterns or technologies
|
|
36
|
+
- Multi-file changes (more than 2-3 files)
|
|
37
|
+
- Unclear requirements that need exploration
|
|
38
|
+
|
|
39
|
+
In plan mode:
|
|
40
|
+
- Only read-only tools are available (Read, Glob, Grep, WebFetch, WebSearch, TodoWrite, AskUserQuestion)
|
|
41
|
+
- Write, Edit, and Bash tools are blocked
|
|
42
|
+
- You can explore the codebase and design an approach
|
|
43
|
+
- Use ExitPlanMode when ready to request user approval
|
|
44
|
+
|
|
45
|
+
This tool REQUIRES user approval before entering plan mode.`,
|
|
46
|
+
parameters: EnterPlanModeInputSchema,
|
|
47
|
+
async execute(_input, context) {
|
|
48
|
+
const manager = getPlanModeManager();
|
|
49
|
+
// Check if already in plan mode
|
|
50
|
+
if (manager.isActive()) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
output: '',
|
|
54
|
+
error: 'Already in plan mode. Use ExitPlanMode to exit first.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
// Create plan file
|
|
59
|
+
const planFile = await createPlanFile(context.cwd);
|
|
60
|
+
const displayPath = getDisplayPath(planFile.path, context.cwd);
|
|
61
|
+
// Enter plan mode
|
|
62
|
+
manager.enter(planFile.path);
|
|
63
|
+
// Build response
|
|
64
|
+
const output = `
|
|
65
|
+
Entered PLAN mode.
|
|
66
|
+
|
|
67
|
+
Plan file: ${displayPath}
|
|
68
|
+
|
|
69
|
+
In plan mode, you have access to read-only tools for exploration:
|
|
70
|
+
${PLAN_MODE_ALLOWED_TOOLS.map((t) => ` - ${t}`).join('\n')}
|
|
71
|
+
|
|
72
|
+
Blocked tools (write/execute operations):
|
|
73
|
+
${PLAN_MODE_BLOCKED_TOOLS.map((t) => ` - ${t}`).join('\n')}
|
|
74
|
+
|
|
75
|
+
Instructions:
|
|
76
|
+
1. Explore the codebase using Read, Glob, Grep tools
|
|
77
|
+
2. Research if needed using WebFetch, WebSearch
|
|
78
|
+
3. Design your implementation approach
|
|
79
|
+
4. Write your plan to the plan file using Write (plan file only)
|
|
80
|
+
5. Call ExitPlanMode when ready for user approval
|
|
81
|
+
|
|
82
|
+
Use Shift+Tab to toggle between Plan and Build modes.
|
|
83
|
+
`.trim();
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
output,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
output: '',
|
|
93
|
+
error: `Failed to enter plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=enter-plan-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enter-plan-mode.js","sourceRoot":"","sources":["../../../src/planning/tools/enter-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAA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AE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;CAU1D,CAAC,IAAI,EAAE,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aAC9F,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExitPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Exits plan mode and requests user approval for the implementation plan.
|
|
5
|
+
* Supports pre-approving permissions for bash commands needed during execution.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { Tool } from '../../tools/types.js';
|
|
9
|
+
declare const ExitPlanModeInputSchema: z.ZodObject<{
|
|
10
|
+
allowedPrompts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
11
|
+
tool: z.ZodLiteral<"Bash">;
|
|
12
|
+
prompt: z.ZodString;
|
|
13
|
+
}, z.core.$strip>>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type ExitPlanModeInput = z.infer<typeof ExitPlanModeInputSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* ExitPlanMode Tool
|
|
18
|
+
*
|
|
19
|
+
* Call this when you have finished writing your plan and are ready
|
|
20
|
+
* for user approval. The plan file should already be written.
|
|
21
|
+
*/
|
|
22
|
+
export declare const exitPlanModeTool: Tool<ExitPlanModeInput>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=exit-plan-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-plan-mode.d.ts","sourceRoot":"","sources":["../../../src/planning/tools/exit-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,sBAAsB,CAAC;AAc1E,QAAA,MAAM,uBAAuB;;;;;iBAK3B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,CAoIpD,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExitPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Exits plan mode and requests user approval for the implementation plan.
|
|
5
|
+
* Supports pre-approving permissions for bash commands needed during execution.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { getPlanModeManager } from '../state.js';
|
|
9
|
+
import { readPlanFile, parseFilesToChange, parsePreApprovedPermissions, getDisplayPath } from '../plan-file.js';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Tool Definition
|
|
12
|
+
// ============================================================================
|
|
13
|
+
const AllowedPromptSchema = z.object({
|
|
14
|
+
tool: z.literal('Bash').describe('The tool this permission applies to'),
|
|
15
|
+
prompt: z.string().describe('Semantic description of the action, e.g., "run tests", "install dependencies"'),
|
|
16
|
+
});
|
|
17
|
+
const ExitPlanModeInputSchema = z.object({
|
|
18
|
+
allowedPrompts: z
|
|
19
|
+
.array(AllowedPromptSchema)
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Prompt-based permissions needed to implement the plan'),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* ExitPlanMode Tool
|
|
25
|
+
*
|
|
26
|
+
* Call this when you have finished writing your plan and are ready
|
|
27
|
+
* for user approval. The plan file should already be written.
|
|
28
|
+
*/
|
|
29
|
+
export const exitPlanModeTool = {
|
|
30
|
+
name: 'ExitPlanMode',
|
|
31
|
+
description: `Exit plan mode and request user approval for the implementation plan.
|
|
32
|
+
|
|
33
|
+
## How This Tool Works
|
|
34
|
+
- You should have already written your plan to the plan file
|
|
35
|
+
- This tool reads the plan from the file you wrote
|
|
36
|
+
- The user will see the plan contents and approve/modify/cancel
|
|
37
|
+
|
|
38
|
+
## Requesting Permissions (allowedPrompts)
|
|
39
|
+
Request prompt-based permissions for bash commands your plan will need:
|
|
40
|
+
|
|
41
|
+
\`\`\`json
|
|
42
|
+
{
|
|
43
|
+
"allowedPrompts": [
|
|
44
|
+
{ "tool": "Bash", "prompt": "run tests" },
|
|
45
|
+
{ "tool": "Bash", "prompt": "install dependencies" },
|
|
46
|
+
{ "tool": "Bash", "prompt": "build the project" }
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
Guidelines for prompts:
|
|
52
|
+
- Use semantic descriptions that capture the action's purpose
|
|
53
|
+
- "run tests" matches: npm test, pytest, go test, etc.
|
|
54
|
+
- "install dependencies" matches: npm install, pip install, etc.
|
|
55
|
+
- Keep descriptions concise but descriptive
|
|
56
|
+
- Only request permissions you actually need
|
|
57
|
+
- Scope permissions narrowly
|
|
58
|
+
|
|
59
|
+
## When to Use This Tool
|
|
60
|
+
Only use this tool when you have finished planning and are ready for approval.
|
|
61
|
+
Do NOT use this tool for research tasks - only for implementation planning.`,
|
|
62
|
+
parameters: ExitPlanModeInputSchema,
|
|
63
|
+
async execute(input, context) {
|
|
64
|
+
const manager = getPlanModeManager();
|
|
65
|
+
// Check if in plan mode
|
|
66
|
+
if (!manager.isActive()) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
output: '',
|
|
70
|
+
error: 'Not in plan mode. Use EnterPlanMode first.',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const planFilePath = manager.getPlanFilePath();
|
|
74
|
+
if (!planFilePath) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
output: '',
|
|
78
|
+
error: 'No plan file found. This should not happen.',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
// Read plan file
|
|
83
|
+
const planFile = await readPlanFile(planFilePath);
|
|
84
|
+
if (!planFile) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
output: '',
|
|
88
|
+
error: `Could not read plan file: ${planFilePath}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Parse plan content
|
|
92
|
+
const filesToChange = parseFilesToChange(planFile.content);
|
|
93
|
+
const planPermissions = parsePreApprovedPermissions(planFile.content);
|
|
94
|
+
// Combine with input permissions
|
|
95
|
+
const requestedPermissions = [
|
|
96
|
+
...planPermissions,
|
|
97
|
+
...(input.allowedPrompts || []),
|
|
98
|
+
];
|
|
99
|
+
// Store permissions for approval UI
|
|
100
|
+
manager.setRequestedPermissions(requestedPermissions);
|
|
101
|
+
manager.setPhase('approval');
|
|
102
|
+
// Build response for the LLM
|
|
103
|
+
const displayPath = getDisplayPath(planFilePath, context.cwd);
|
|
104
|
+
let output = `
|
|
105
|
+
Plan ready for approval.
|
|
106
|
+
|
|
107
|
+
Plan file: ${displayPath}
|
|
108
|
+
|
|
109
|
+
`;
|
|
110
|
+
// Summary of files to change
|
|
111
|
+
if (filesToChange.length > 0) {
|
|
112
|
+
output += 'Files to change:\n';
|
|
113
|
+
for (const file of filesToChange) {
|
|
114
|
+
const icon = file.action === 'create' ? '+' : file.action === 'modify' ? '~' : '-';
|
|
115
|
+
output += ` ${icon} ${file.path} (${file.action})\n`;
|
|
116
|
+
}
|
|
117
|
+
output += '\n';
|
|
118
|
+
}
|
|
119
|
+
// Requested permissions
|
|
120
|
+
if (requestedPermissions.length > 0) {
|
|
121
|
+
output += 'Requested permissions:\n';
|
|
122
|
+
for (const perm of requestedPermissions) {
|
|
123
|
+
output += ` - ${perm.tool}(prompt: ${perm.prompt})\n`;
|
|
124
|
+
}
|
|
125
|
+
output += '\n';
|
|
126
|
+
}
|
|
127
|
+
output += `
|
|
128
|
+
The user will now be prompted to:
|
|
129
|
+
1. Approve - Accept plan and proceed with execution
|
|
130
|
+
2. Modify - Go back and modify the plan
|
|
131
|
+
3. Cancel - Exit plan mode without executing
|
|
132
|
+
|
|
133
|
+
Waiting for user decision...
|
|
134
|
+
`.trim();
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
output,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
output: '',
|
|
144
|
+
error: `Failed to exit plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=exit-plan-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-plan-mode.js","sourceRoot":"","sources":["../../../src/planning/tools/exit-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGhH,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IACvE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+EAA+E,CAAC;CAC7G,CAAC,CAAC;AAEH,MA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