headlesscode 1.0.2

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.
Files changed (232) hide show
  1. package/ATTRIBUTION.md +53 -0
  2. package/CODE_OF_CONDUCT.md +130 -0
  3. package/CONTRIBUTING.md +107 -0
  4. package/LICENSE +202 -0
  5. package/README.md +486 -0
  6. package/SECURITY.md +211 -0
  7. package/bin/headlesscode.mjs +83 -0
  8. package/package.json +63 -0
  9. package/shared/prompts/review-mode-prompt-short.md +93 -0
  10. package/shared/prompts/review-mode-prompt.md +281 -0
  11. package/shared/rules-code/rules.md +22 -0
  12. package/shared/stacks/cpp/rules.md +30 -0
  13. package/shared/stacks/fastapi/rules.md +30 -0
  14. package/shared/stacks/javascript/rules.md +37 -0
  15. package/shared/stacks/postgresql/rules.md +31 -0
  16. package/shared/stacks/python/rules.md +35 -0
  17. package/shared/stacks/react/rules.md +11 -0
  18. package/shared/stacks/typescript/rules.md +10 -0
  19. package/src/budget/budget.ts +221 -0
  20. package/src/budget/concurrency.ts +126 -0
  21. package/src/budget/cost.ts +309 -0
  22. package/src/budget/index.ts +8 -0
  23. package/src/checkpoints/cli.ts +256 -0
  24. package/src/checkpoints/service.ts +227 -0
  25. package/src/cli.ts +1535 -0
  26. package/src/cloud/docker-provider.ts +334 -0
  27. package/src/cloud/provider.ts +300 -0
  28. package/src/codeintel/call-graph.ts +78 -0
  29. package/src/codeintel/find-references.ts +123 -0
  30. package/src/codeintel/go-to-definition.ts +193 -0
  31. package/src/codeintel/handlers.ts +190 -0
  32. package/src/codeintel/import-graph.ts +173 -0
  33. package/src/codeintel/outline.ts +180 -0
  34. package/src/codeintel/position.ts +77 -0
  35. package/src/codeintel/program.ts +350 -0
  36. package/src/codeintel/rename-symbol.ts +213 -0
  37. package/src/codeintel/tools.ts +280 -0
  38. package/src/codemap/build.ts +135 -0
  39. package/src/codemap/cli.ts +190 -0
  40. package/src/codemap/extract.ts +339 -0
  41. package/src/codemap/files.ts +236 -0
  42. package/src/codemap/fingerprint.ts +65 -0
  43. package/src/codemap/flows.ts +62 -0
  44. package/src/codemap/html.ts +451 -0
  45. package/src/codemap/lock.ts +80 -0
  46. package/src/codemap/types.ts +101 -0
  47. package/src/codesearch/airunner-embedder.ts +185 -0
  48. package/src/codesearch/chunk.ts +339 -0
  49. package/src/codesearch/cli.ts +223 -0
  50. package/src/codesearch/embedder.ts +332 -0
  51. package/src/codesearch/files.ts +280 -0
  52. package/src/codesearch/index.ts +469 -0
  53. package/src/codesearch/ollama-embedder.ts +205 -0
  54. package/src/codesearch/search.ts +141 -0
  55. package/src/codesearch/types.ts +100 -0
  56. package/src/config/mode-models.ts +218 -0
  57. package/src/dashboard/aggregate.ts +364 -0
  58. package/src/dashboard/chat-thread.ts +141 -0
  59. package/src/dashboard/checkpoints.ts +124 -0
  60. package/src/dashboard/cli.ts +193 -0
  61. package/src/dashboard/codemap.ts +44 -0
  62. package/src/dashboard/files.ts +121 -0
  63. package/src/dashboard/page.ts +2803 -0
  64. package/src/dashboard/self-improvement-metrics.ts +282 -0
  65. package/src/dashboard/server.ts +1103 -0
  66. package/src/dashboard/session-launch.ts +310 -0
  67. package/src/dashboard/timeline.ts +273 -0
  68. package/src/dashboard/tool-exec.ts +107 -0
  69. package/src/dashboard/trend-cli.ts +141 -0
  70. package/src/dashboard/trend.ts +413 -0
  71. package/src/decision-proxy/cli.ts +261 -0
  72. package/src/decision-proxy/proxy.ts +569 -0
  73. package/src/deploy/gate-cli.ts +147 -0
  74. package/src/deploy/gate.ts +254 -0
  75. package/src/engine/condense.ts +512 -0
  76. package/src/engine/events.ts +428 -0
  77. package/src/engine/handoff.ts +71 -0
  78. package/src/engine/lazy-tools.ts +160 -0
  79. package/src/engine/local-explore.ts +653 -0
  80. package/src/engine/logger.ts +96 -0
  81. package/src/engine/loop.ts +5517 -0
  82. package/src/engine/parser.ts +347 -0
  83. package/src/engine/prompt.ts +860 -0
  84. package/src/engine/reports.ts +47 -0
  85. package/src/engine/stacks.ts +448 -0
  86. package/src/engine/types.ts +291 -0
  87. package/src/engine/usage.ts +186 -0
  88. package/src/github/app-auth.ts +161 -0
  89. package/src/github/cli.ts +448 -0
  90. package/src/github/installations.ts +133 -0
  91. package/src/github/pr.ts +321 -0
  92. package/src/github/provision.ts +118 -0
  93. package/src/github/push.ts +122 -0
  94. package/src/index-util.ts +50 -0
  95. package/src/index.ts +81 -0
  96. package/src/init/cli.ts +248 -0
  97. package/src/init/gitignore.ts +74 -0
  98. package/src/llm/ollama.ts +308 -0
  99. package/src/llm/openrouter.ts +868 -0
  100. package/src/llm/preflight.ts +367 -0
  101. package/src/llm/transcript-capture.ts +84 -0
  102. package/src/memory/embed.ts +110 -0
  103. package/src/memory/index.ts +22 -0
  104. package/src/memory/local.ts +259 -0
  105. package/src/memory/summarizer.ts +283 -0
  106. package/src/memory/types.ts +153 -0
  107. package/src/memory/uwuchat.ts +157 -0
  108. package/src/migrate/cli.ts +115 -0
  109. package/src/orchestrator/analyze-cli.ts +104 -0
  110. package/src/orchestrator/auto-split.ts +206 -0
  111. package/src/orchestrator/cleanup.ts +1003 -0
  112. package/src/orchestrator/cli.ts +3571 -0
  113. package/src/orchestrator/cost-estimate.ts +564 -0
  114. package/src/orchestrator/cost-history-cli.ts +242 -0
  115. package/src/orchestrator/cost-history.ts +397 -0
  116. package/src/orchestrator/git-sync.ts +250 -0
  117. package/src/orchestrator/index.ts +153 -0
  118. package/src/orchestrator/log-analysis.ts +0 -0
  119. package/src/orchestrator/merge-check.ts +108 -0
  120. package/src/orchestrator/pipeline.ts +411 -0
  121. package/src/orchestrator/resume.ts +1940 -0
  122. package/src/orchestrator/reviewer.ts +503 -0
  123. package/src/orchestrator/split.ts +296 -0
  124. package/src/orchestrator/state.ts +542 -0
  125. package/src/orchestrator/status.ts +697 -0
  126. package/src/orchestrator/verification-gate.ts +134 -0
  127. package/src/orchestrator/watch.ts +898 -0
  128. package/src/permissions/commands.ts +1083 -0
  129. package/src/permissions/config.ts +241 -0
  130. package/src/permissions/index.ts +12 -0
  131. package/src/permissions/protected-files.ts +96 -0
  132. package/src/permissions/store-protection.ts +272 -0
  133. package/src/project-store.ts +648 -0
  134. package/src/projects/cli.ts +382 -0
  135. package/src/qa/qa.ts +487 -0
  136. package/src/tools/browser/handler.ts +346 -0
  137. package/src/tools/browser/service.ts +406 -0
  138. package/src/tools/browser/smoke.ts +78 -0
  139. package/src/tools/browser/tool.ts +99 -0
  140. package/src/tools/executor.ts +2575 -0
  141. package/src/tools/language-detect.ts +183 -0
  142. package/src/tools/output-summarizer.ts +369 -0
  143. package/src/tools/run-tests.ts +302 -0
  144. package/src/tools/set-indentation-tool.ts +49 -0
  145. package/src/tools/test-selection.ts +160 -0
  146. package/src/vendor/tests/smoke.ts +103 -0
  147. package/src/vendor/zoo-code/VENDOR-NOTES.md +213 -0
  148. package/src/vendor/zoo-code/shim/anthropic.ts +71 -0
  149. package/src/vendor/zoo-code/shim/openai.d.ts +60 -0
  150. package/src/vendor/zoo-code/shim/os-name.ts +18 -0
  151. package/src/vendor/zoo-code/shim/strip-bom.ts +14 -0
  152. package/src/vendor/zoo-code/shim/vscode.ts +76 -0
  153. package/src/vendor/zoo-code/src/core/config/CustomModesManager.ts +1015 -0
  154. package/src/vendor/zoo-code/src/core/diff/strategies/multi-search-replace.ts +670 -0
  155. package/src/vendor/zoo-code/src/core/prompts/sections/capabilities.ts +46 -0
  156. package/src/vendor/zoo-code/src/core/prompts/sections/custom-instructions.ts +559 -0
  157. package/src/vendor/zoo-code/src/core/prompts/sections/index.ts +10 -0
  158. package/src/vendor/zoo-code/src/core/prompts/sections/markdown-formatting.ts +7 -0
  159. package/src/vendor/zoo-code/src/core/prompts/sections/modes.ts +35 -0
  160. package/src/vendor/zoo-code/src/core/prompts/sections/objective.ts +13 -0
  161. package/src/vendor/zoo-code/src/core/prompts/sections/rules.ts +95 -0
  162. package/src/vendor/zoo-code/src/core/prompts/sections/skills.ts +105 -0
  163. package/src/vendor/zoo-code/src/core/prompts/sections/system-info.ts +30 -0
  164. package/src/vendor/zoo-code/src/core/prompts/sections/tool-use-guidelines.ts +9 -0
  165. package/src/vendor/zoo-code/src/core/prompts/sections/tool-use.ts +7 -0
  166. package/src/vendor/zoo-code/src/core/prompts/system.ts +176 -0
  167. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/access_mcp_resource.ts +41 -0
  168. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/apply_diff.ts +40 -0
  169. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/apply_patch.ts +61 -0
  170. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/ask_followup_question.ts +62 -0
  171. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/attempt_completion.ts +33 -0
  172. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/codebase_search.ts +43 -0
  173. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/converters.ts +109 -0
  174. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/edit.ts +48 -0
  175. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/edit_file.ts +72 -0
  176. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/execute_command.ts +54 -0
  177. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/generate_image.ts +51 -0
  178. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/index.ts +75 -0
  179. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/list_files.ts +41 -0
  180. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/mcp_server.ts +75 -0
  181. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/new_task.ts +39 -0
  182. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/read_command_output.ts +81 -0
  183. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/read_file.ts +169 -0
  184. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/run_slash_command.ts +31 -0
  185. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/search_files.ts +50 -0
  186. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/search_replace.ts +51 -0
  187. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/skill.ts +33 -0
  188. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/switch_mode.ts +31 -0
  189. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/update_todo_list.ts +54 -0
  190. package/src/vendor/zoo-code/src/core/prompts/tools/native-tools/write_to_file.ts +40 -0
  191. package/src/vendor/zoo-code/src/core/prompts/types.ts +12 -0
  192. package/src/vendor/zoo-code/src/i18n/index.ts +19 -0
  193. package/src/vendor/zoo-code/src/integrations/misc/extract-text.ts +81 -0
  194. package/src/vendor/zoo-code/src/services/checkpoints/RepoPerTaskCheckpointService.ts +15 -0
  195. package/src/vendor/zoo-code/src/services/checkpoints/ShadowCheckpointService.ts +553 -0
  196. package/src/vendor/zoo-code/src/services/checkpoints/excludes.ts +212 -0
  197. package/src/vendor/zoo-code/src/services/checkpoints/index.ts +3 -0
  198. package/src/vendor/zoo-code/src/services/checkpoints/types.ts +35 -0
  199. package/src/vendor/zoo-code/src/services/code-index/manager.ts +19 -0
  200. package/src/vendor/zoo-code/src/services/mcp/McpHub.ts +36 -0
  201. package/src/vendor/zoo-code/src/services/roo-config/index.ts +441 -0
  202. package/src/vendor/zoo-code/src/services/search/file-search.ts +143 -0
  203. package/src/vendor/zoo-code/src/services/skills/SkillsManager.ts +20 -0
  204. package/src/vendor/zoo-code/src/shared/globalFileNames.ts +9 -0
  205. package/src/vendor/zoo-code/src/shared/language.ts +43 -0
  206. package/src/vendor/zoo-code/src/shared/modes.ts +257 -0
  207. package/src/vendor/zoo-code/src/shared/tools.ts +385 -0
  208. package/src/vendor/zoo-code/src/utils/fs.ts +39 -0
  209. package/src/vendor/zoo-code/src/utils/globalContext.ts +22 -0
  210. package/src/vendor/zoo-code/src/utils/json-schema.ts +16 -0
  211. package/src/vendor/zoo-code/src/utils/logging.ts +21 -0
  212. package/src/vendor/zoo-code/src/utils/mcp-name.ts +190 -0
  213. package/src/vendor/zoo-code/src/utils/object.ts +18 -0
  214. package/src/vendor/zoo-code/src/utils/path.ts +94 -0
  215. package/src/vendor/zoo-code/src/utils/shell.ts +376 -0
  216. package/src/vendor/zoo-code/src/utils/text-normalization.ts +99 -0
  217. package/src/vendor/zoo-code/types/global-settings.ts +19 -0
  218. package/src/vendor/zoo-code/types/index.ts +22 -0
  219. package/src/vendor/zoo-code/types/message.ts +375 -0
  220. package/src/vendor/zoo-code/types/mode.ts +241 -0
  221. package/src/vendor/zoo-code/types/todo.ts +19 -0
  222. package/src/vendor/zoo-code/types/tool-params.ts +116 -0
  223. package/src/vendor/zoo-code/types/tool.ts +67 -0
  224. package/src/vendor/zoo-code/types/vscode.ts +84 -0
  225. package/src/vision/describe.ts +242 -0
  226. package/src/vision/tool.ts +91 -0
  227. package/src/watcher/cli.ts +369 -0
  228. package/src/watcher/github.ts +304 -0
  229. package/src/watcher/index.ts +59 -0
  230. package/src/watcher/state.ts +254 -0
  231. package/src/watcher/watch.ts +562 -0
  232. package/tsconfig.json +18 -0
@@ -0,0 +1,375 @@
1
+ import { z } from "zod"
2
+
3
+ /**
4
+ * ClineAsk
5
+ */
6
+
7
+ /**
8
+ * Array of possible ask types that the LLM can use to request user interaction or approval.
9
+ * These represent different scenarios where the assistant needs user input to proceed.
10
+ *
11
+ * @constant
12
+ * @readonly
13
+ *
14
+ * Ask type descriptions:
15
+ * - `followup`: LLM asks a clarifying question to gather more information needed to complete the task
16
+ * - `command`: Permission to execute a terminal/shell command
17
+ * - `command_output`: Permission to read the output from a previously executed command
18
+ * - `completion_result`: Task has been completed, awaiting user feedback or a new task
19
+ * - `tool`: Permission to use a tool for file operations (read, write, search, etc.)
20
+ * - `api_req_failed`: API request failed, asking user whether to retry
21
+ * - `resume_task`: Confirmation needed to resume a previously paused task
22
+ * - `resume_completed_task`: Confirmation needed to resume a task that was already marked as completed
23
+ * - `mistake_limit_reached`: Too many errors encountered, needs user guidance on how to proceed
24
+ * - `use_mcp_server`: Permission to use Model Context Protocol (MCP) server functionality
25
+ * - `auto_approval_max_req_reached`: Auto-approval limit has been reached, manual approval required
26
+ */
27
+ export const clineAsks = [
28
+ "followup",
29
+ "command",
30
+ "command_output",
31
+ "completion_result",
32
+ "tool",
33
+ "api_req_failed",
34
+ "resume_task",
35
+ "resume_completed_task",
36
+ "mistake_limit_reached",
37
+ "use_mcp_server",
38
+ "auto_approval_max_req_reached",
39
+ ] as const
40
+
41
+ export const clineAskSchema = z.enum(clineAsks)
42
+
43
+ export type ClineAsk = z.infer<typeof clineAskSchema>
44
+ /**
45
+ * IdleAsk
46
+ *
47
+ * Asks that put the task into an "idle" state.
48
+ */
49
+
50
+ export const idleAsks = [
51
+ "completion_result",
52
+ "api_req_failed",
53
+ "resume_completed_task",
54
+ "mistake_limit_reached",
55
+ "auto_approval_max_req_reached",
56
+ ] as const satisfies readonly ClineAsk[]
57
+
58
+ export type IdleAsk = (typeof idleAsks)[number]
59
+
60
+ export function isIdleAsk(ask: ClineAsk): ask is IdleAsk {
61
+ return (idleAsks as readonly ClineAsk[]).includes(ask)
62
+ }
63
+
64
+ /**
65
+ * ResumableAsk
66
+ *
67
+ * Asks that put the task into an "resumable" state.
68
+ */
69
+
70
+ export const resumableAsks = ["resume_task"] as const satisfies readonly ClineAsk[]
71
+
72
+ export type ResumableAsk = (typeof resumableAsks)[number]
73
+
74
+ export function isResumableAsk(ask: ClineAsk): ask is ResumableAsk {
75
+ return (resumableAsks as readonly ClineAsk[]).includes(ask)
76
+ }
77
+
78
+ /**
79
+ * InteractiveAsk
80
+ *
81
+ * Asks that put the task into an "user interaction required" state.
82
+ */
83
+
84
+ export const interactiveAsks = ["followup", "command", "tool", "use_mcp_server"] as const satisfies readonly ClineAsk[]
85
+
86
+ export type InteractiveAsk = (typeof interactiveAsks)[number]
87
+
88
+ export function isInteractiveAsk(ask: ClineAsk): ask is InteractiveAsk {
89
+ return (interactiveAsks as readonly ClineAsk[]).includes(ask)
90
+ }
91
+
92
+ /**
93
+ * NonBlockingAsk
94
+ *
95
+ * Asks that are not associated with an actual approval, and are only used
96
+ * to update chat messages.
97
+ */
98
+
99
+ export const nonBlockingAsks = ["command_output"] as const satisfies readonly ClineAsk[]
100
+
101
+ export type NonBlockingAsk = (typeof nonBlockingAsks)[number]
102
+
103
+ export function isNonBlockingAsk(ask: ClineAsk): ask is NonBlockingAsk {
104
+ return (nonBlockingAsks as readonly ClineAsk[]).includes(ask)
105
+ }
106
+
107
+ /**
108
+ * ClineSay
109
+ */
110
+
111
+ /**
112
+ * Array of possible say types that represent different kinds of messages the assistant can send.
113
+ * These are used to categorize and handle various types of communication from the LLM to the user.
114
+ *
115
+ * @constant
116
+ * @readonly
117
+ *
118
+ * Say type descriptions:
119
+ * - `error`: General error message
120
+ * - `api_req_started`: Indicates an API request has been initiated
121
+ * - `api_req_finished`: Indicates an API request has completed successfully
122
+ * - `api_req_retried`: Indicates an API request is being retried after a failure
123
+ * - `api_req_retry_delayed`: Indicates an API request retry has been delayed
124
+ * - `api_req_rate_limit_wait`: Indicates a configured rate-limit wait (not an error)
125
+ * - `api_req_deleted`: Indicates an API request has been deleted/cancelled
126
+ * - `text`: General text message or assistant response
127
+ * - `reasoning`: Assistant's reasoning or thought process (often hidden from user)
128
+ * - `completion_result`: Final result of task completion
129
+ * - `user_feedback`: Message containing user feedback
130
+ * - `user_feedback_diff`: Diff-formatted feedback from user showing requested changes
131
+ * - `command_output`: Output from an executed command
132
+ * - `shell_integration_warning`: Warning about shell integration issues or limitations
133
+ * - `mcp_server_request_started`: MCP server request has been initiated
134
+ * - `mcp_server_response`: Response received from MCP server
135
+ * - `subtask_result`: Result of a completed subtask
136
+ * - `checkpoint_saved`: Indicates a checkpoint has been saved
137
+ * - `rooignore_error`: Error related to .rooignore file processing
138
+ * - `diff_error`: Error occurred while applying a diff/patch
139
+ * - `condense_context`: Context condensation/summarization has started
140
+ * - `condense_context_error`: Error occurred during context condensation
141
+ * - `codebase_search_result`: Results from searching the codebase
142
+ * - `too_many_tools_warning`: Warning that too many MCP tools are enabled, which may confuse the LLM
143
+ */
144
+ export const clineSays = [
145
+ "error",
146
+ "api_req_started",
147
+ "api_req_finished",
148
+ "api_req_retried",
149
+ "api_req_retry_delayed",
150
+ "api_req_rate_limit_wait",
151
+ "api_req_deleted",
152
+ "text",
153
+ "task",
154
+ "image",
155
+ "reasoning",
156
+ "completion_result",
157
+ "user_feedback",
158
+ "user_feedback_diff",
159
+ "command_output",
160
+ "shell_integration_warning",
161
+ "mcp_server_request_started",
162
+ "mcp_server_response",
163
+ "subtask_result",
164
+ "checkpoint_saved",
165
+ "rooignore_error",
166
+ "diff_error",
167
+ "condense_context",
168
+ "condense_context_error",
169
+ "sliding_window_truncation",
170
+ "codebase_search_result",
171
+ "user_edit_todos",
172
+ "too_many_tools_warning",
173
+ "tool",
174
+ ] as const
175
+
176
+ export const clineSaySchema = z.enum(clineSays)
177
+
178
+ export type ClineSay = z.infer<typeof clineSaySchema>
179
+
180
+ /**
181
+ * ToolProgressStatus
182
+ */
183
+
184
+ export const toolProgressStatusSchema = z.object({
185
+ icon: z.string().optional(),
186
+ text: z.string().optional(),
187
+ })
188
+
189
+ export type ToolProgressStatus = z.infer<typeof toolProgressStatusSchema>
190
+
191
+ /**
192
+ * ContextCondense
193
+ *
194
+ * Data associated with a successful context condensation event.
195
+ * This is attached to messages with `say: "condense_context"` when
196
+ * the condensation operation completes successfully.
197
+ *
198
+ * @property cost - The API cost incurred for the condensation operation
199
+ * @property prevContextTokens - Token count before condensation
200
+ * @property newContextTokens - Token count after condensation
201
+ * @property summary - The condensed summary that replaced the original context
202
+ * @property condenseId - Optional unique identifier for this condensation operation
203
+ */
204
+ export const contextCondenseSchema = z.object({
205
+ cost: z.number(),
206
+ prevContextTokens: z.number(),
207
+ newContextTokens: z.number(),
208
+ summary: z.string(),
209
+ condenseId: z.string().optional(),
210
+ })
211
+
212
+ export type ContextCondense = z.infer<typeof contextCondenseSchema>
213
+
214
+ /**
215
+ * ContextTruncation
216
+ *
217
+ * Data associated with a sliding window truncation event.
218
+ * This is attached to messages with `say: "sliding_window_truncation"` when
219
+ * messages are removed from the conversation history to stay within token limits.
220
+ *
221
+ * Unlike condensation, truncation simply removes older messages without
222
+ * summarizing them. This is a faster but less context-preserving approach.
223
+ *
224
+ * @property truncationId - Unique identifier for this truncation operation
225
+ * @property messagesRemoved - Number of conversation messages that were removed
226
+ * @property prevContextTokens - Token count before truncation occurred
227
+ * @property newContextTokens - Token count after truncation occurred
228
+ */
229
+ export const contextTruncationSchema = z.object({
230
+ truncationId: z.string(),
231
+ messagesRemoved: z.number(),
232
+ prevContextTokens: z.number(),
233
+ newContextTokens: z.number(),
234
+ })
235
+
236
+ export type ContextTruncation = z.infer<typeof contextTruncationSchema>
237
+
238
+ /**
239
+ * ClineMessage
240
+ *
241
+ * The main message type used for communication between the extension and webview.
242
+ * Messages can either be "ask" (requiring user response) or "say" (informational).
243
+ *
244
+ * Context Management Fields:
245
+ * - `contextCondense`: Present when `say: "condense_context"` and condensation succeeded
246
+ * - `contextTruncation`: Present when `say: "sliding_window_truncation"` and truncation occurred
247
+ *
248
+ * Note: These fields are mutually exclusive - a message will have at most one of them.
249
+ */
250
+ export const clineMessageSchema = z.object({
251
+ ts: z.number(),
252
+ type: z.union([z.literal("ask"), z.literal("say")]),
253
+ ask: clineAskSchema.optional(),
254
+ say: clineSaySchema.optional(),
255
+ text: z.string().optional(),
256
+ images: z.array(z.string()).optional(),
257
+ partial: z.boolean().optional(),
258
+ reasoning: z.string().optional(),
259
+ conversationHistoryIndex: z.number().optional(),
260
+ checkpoint: z.record(z.string(), z.unknown()).optional(),
261
+ progressStatus: toolProgressStatusSchema.optional(),
262
+ /**
263
+ * Data for successful context condensation.
264
+ * Present when `say: "condense_context"` and `partial: false`.
265
+ */
266
+ contextCondense: contextCondenseSchema.optional(),
267
+ /**
268
+ * Data for sliding window truncation.
269
+ * Present when `say: "sliding_window_truncation"`.
270
+ */
271
+ contextTruncation: contextTruncationSchema.optional(),
272
+ isProtected: z.boolean().optional(),
273
+ apiProtocol: z.union([z.literal("openai"), z.literal("anthropic")]).optional(),
274
+ isAnswered: z.boolean().optional(),
275
+ })
276
+
277
+ export type ClineMessage = z.infer<typeof clineMessageSchema>
278
+
279
+ export interface CompletionCheckpoint {
280
+ ts: number
281
+ commitHash: string
282
+ }
283
+
284
+ const isInitialTaskMessage = (message: ClineMessage | undefined): boolean => {
285
+ return message?.type === "say" && (message.say === "text" || message.say === "task")
286
+ }
287
+
288
+ const isUserFeedbackMessage = (message: ClineMessage): boolean => {
289
+ return message.type === "say" && message.say === "user_feedback"
290
+ }
291
+
292
+ const isCompletionMessage = (message: ClineMessage): boolean => {
293
+ return (
294
+ (message.type === "ask" && message.ask === "completion_result") ||
295
+ (message.type === "say" && message.say === "completion_result")
296
+ )
297
+ }
298
+
299
+ const isCheckpointMessage = (message: ClineMessage): boolean => {
300
+ return message.type === "say" && message.say === "checkpoint_saved" && typeof message.text === "string"
301
+ }
302
+
303
+ function findLastIndexBefore(
304
+ messages: ClineMessage[],
305
+ beforeIndex: number,
306
+ predicate: (message: ClineMessage) => boolean,
307
+ ): number {
308
+ for (let i = beforeIndex - 1; i >= 0; i--) {
309
+ const message = messages[i]
310
+
311
+ if (message && predicate(message)) {
312
+ return i
313
+ }
314
+ }
315
+
316
+ return -1
317
+ }
318
+
319
+ /**
320
+ * Finds the checkpoint that should anchor completion-result actions.
321
+ *
322
+ * The baseline is the first checkpoint created after the latest user prompt in
323
+ * the turn that produced the completion. Restoring to that checkpoint reverts
324
+ * changes made for the latest prompt, and diffing from it shows the same scoped
325
+ * changes.
326
+ */
327
+ export function getCompletionCheckpoint(messages: ClineMessage[]): CompletionCheckpoint | undefined {
328
+ const completionIndex = findLastIndexBefore(messages, messages.length, isCompletionMessage)
329
+ const searchEnd = completionIndex === -1 ? messages.length : completionIndex
330
+ const latestUserFeedbackIndex = findLastIndexBefore(messages, searchEnd, isUserFeedbackMessage)
331
+ const latestUserPromptIndex =
332
+ latestUserFeedbackIndex !== -1 ? latestUserFeedbackIndex : isInitialTaskMessage(messages[0]) ? 0 : -1
333
+
334
+ if (latestUserPromptIndex === -1) {
335
+ return undefined
336
+ }
337
+
338
+ for (let i = latestUserPromptIndex + 1; i < searchEnd; i++) {
339
+ const message = messages[i]
340
+
341
+ if (message && isCheckpointMessage(message)) {
342
+ return { ts: message.ts, commitHash: message.text! }
343
+ }
344
+ }
345
+
346
+ return undefined
347
+ }
348
+
349
+ /**
350
+ * TokenUsage
351
+ */
352
+
353
+ export const tokenUsageSchema = z.object({
354
+ totalTokensIn: z.number(),
355
+ totalTokensOut: z.number(),
356
+ totalCacheWrites: z.number().optional(),
357
+ totalCacheReads: z.number().optional(),
358
+ totalCost: z.number(),
359
+ contextTokens: z.number(),
360
+ })
361
+
362
+ export type TokenUsage = z.infer<typeof tokenUsageSchema>
363
+
364
+ /**
365
+ * QueuedMessage
366
+ */
367
+
368
+ export const queuedMessageSchema = z.object({
369
+ timestamp: z.number(),
370
+ id: z.string(),
371
+ text: z.string(),
372
+ images: z.array(z.string()).optional(),
373
+ })
374
+
375
+ export type QueuedMessage = z.infer<typeof queuedMessageSchema>
@@ -0,0 +1,241 @@
1
+ import { z } from "zod"
2
+
3
+ import { deprecatedToolGroups, toolGroupsSchema } from "./tool.js"
4
+
5
+ /**
6
+ * GroupOptions
7
+ */
8
+
9
+ export const groupOptionsSchema = z.object({
10
+ fileRegex: z
11
+ .string()
12
+ .optional()
13
+ .refine(
14
+ (pattern) => {
15
+ if (!pattern) {
16
+ return true // Optional, so empty is valid.
17
+ }
18
+
19
+ try {
20
+ new RegExp(pattern)
21
+ return true
22
+ } catch {
23
+ return false
24
+ }
25
+ },
26
+ { message: "Invalid regular expression pattern" },
27
+ ),
28
+ description: z.string().optional(),
29
+ })
30
+
31
+ export type GroupOptions = z.infer<typeof groupOptionsSchema>
32
+
33
+ /**
34
+ * GroupEntry
35
+ */
36
+
37
+ export const groupEntrySchema = z.union([toolGroupsSchema, z.tuple([toolGroupsSchema, groupOptionsSchema])])
38
+
39
+ export type GroupEntry = z.infer<typeof groupEntrySchema>
40
+
41
+ /**
42
+ * ModeConfig
43
+ */
44
+
45
+ /**
46
+ * Checks if a group entry references a deprecated tool group.
47
+ * Handles both string entries ("browser") and tuple entries (["browser", { ... }]).
48
+ */
49
+ function isDeprecatedGroupEntry(entry: unknown): boolean {
50
+ if (typeof entry === "string") {
51
+ return deprecatedToolGroups.includes(entry)
52
+ }
53
+ if (Array.isArray(entry) && entry.length >= 1 && typeof entry[0] === "string") {
54
+ return deprecatedToolGroups.includes(entry[0])
55
+ }
56
+ return false
57
+ }
58
+
59
+ /**
60
+ * Raw schema for validating group entries after deprecated groups are stripped.
61
+ */
62
+ const rawGroupEntryArraySchema = z.array(groupEntrySchema).refine(
63
+ (groups) => {
64
+ const seen = new Set()
65
+
66
+ return groups.every((group) => {
67
+ // For tuples, check the group name (first element).
68
+ const groupName = Array.isArray(group) ? group[0] : group
69
+
70
+ if (seen.has(groupName)) {
71
+ return false
72
+ }
73
+
74
+ seen.add(groupName)
75
+ return true
76
+ })
77
+ },
78
+ { message: "Duplicate groups are not allowed" },
79
+ )
80
+
81
+ /**
82
+ * Schema for mode group entries. Preprocesses the input to strip deprecated
83
+ * tool groups (e.g., "browser") before validation, ensuring backward compatibility
84
+ * with older user configs.
85
+ *
86
+ * The type assertion to `z.ZodType<GroupEntry[], z.ZodTypeDef, GroupEntry[]>` is
87
+ * required because `z.preprocess` erases the input type to `unknown`, which
88
+ * propagates through `modeConfigSchema → rooCodeSettingsSchema → createRunSchema`
89
+ * and breaks `zodResolver` generic inference in downstream consumers.
90
+ */
91
+ export const groupEntryArraySchema = z.preprocess((val) => {
92
+ if (!Array.isArray(val)) return val
93
+ return val.filter((entry) => !isDeprecatedGroupEntry(entry))
94
+ }, rawGroupEntryArraySchema) as z.ZodType<GroupEntry[], z.ZodTypeDef, GroupEntry[]>
95
+
96
+ export const modeConfigSchema = z.object({
97
+ slug: z.string().regex(/^[a-zA-Z0-9-]+$/, "Slug must contain only letters numbers and dashes"),
98
+ name: z.string().min(1, "Name is required"),
99
+ roleDefinition: z.string().min(1, "Role definition is required"),
100
+ whenToUse: z.string().optional(),
101
+ description: z.string().optional(),
102
+ customInstructions: z.string().optional(),
103
+ groups: groupEntryArraySchema,
104
+ source: z.enum(["global", "project"]).optional(),
105
+ allowedMcpServers: z
106
+ .array(z.string())
107
+ .describe(
108
+ "Optional list of MCP server names to include. When omitted, all servers are available. When set, only the listed servers are injected.",
109
+ )
110
+ .optional(),
111
+ })
112
+
113
+ export type ModeConfig = z.infer<typeof modeConfigSchema>
114
+
115
+ /**
116
+ * CustomModesSettings
117
+ */
118
+
119
+ export const customModesSettingsSchema = z.object({
120
+ customModes: z.array(modeConfigSchema).refine(
121
+ (modes) => {
122
+ const slugs = new Set()
123
+
124
+ return modes.every((mode) => {
125
+ if (slugs.has(mode.slug)) {
126
+ return false
127
+ }
128
+
129
+ slugs.add(mode.slug)
130
+ return true
131
+ })
132
+ },
133
+ {
134
+ message: "Duplicate mode slugs are not allowed",
135
+ },
136
+ ),
137
+ })
138
+
139
+ export type CustomModesSettings = z.infer<typeof customModesSettingsSchema>
140
+
141
+ /**
142
+ * PromptComponent
143
+ */
144
+
145
+ export const promptComponentSchema = z.object({
146
+ roleDefinition: z.string().optional(),
147
+ whenToUse: z.string().optional(),
148
+ description: z.string().optional(),
149
+ customInstructions: z.string().optional(),
150
+ })
151
+
152
+ export type PromptComponent = z.infer<typeof promptComponentSchema>
153
+
154
+ /**
155
+ * CustomModePrompts
156
+ */
157
+
158
+ export const customModePromptsSchema = z.record(z.string(), promptComponentSchema.optional())
159
+
160
+ export type CustomModePrompts = z.infer<typeof customModePromptsSchema>
161
+
162
+ /**
163
+ * CustomSupportPrompts
164
+ */
165
+
166
+ export const customSupportPromptsSchema = z.record(z.string(), z.string().optional())
167
+
168
+ export type CustomSupportPrompts = z.infer<typeof customSupportPromptsSchema>
169
+
170
+ /**
171
+ * DEFAULT_MODES
172
+ */
173
+
174
+ export const DEFAULT_MODES: readonly ModeConfig[] = [
175
+ {
176
+ slug: "architect",
177
+ name: "🏗️ Architect",
178
+ roleDefinition:
179
+ "You are Zoo, an experienced technical leader who is inquisitive and an excellent planner. Your goal is to gather information and get context to create a detailed plan for accomplishing the user's task, which the user will review and approve before they switch into another mode to implement the solution.",
180
+ whenToUse:
181
+ "Use this mode when you need to plan, design, or strategize before implementation. Perfect for breaking down complex problems, creating technical specifications, designing system architecture, or brainstorming solutions before coding.",
182
+ description: "Plan and design before implementation",
183
+ // Deviates from upstream Zoo/Roo Code (which gives architect no
184
+ // "command" group at all, so it can't run anything — not even
185
+ // read-only exploration commands like `grep`/`find`/test runners).
186
+ // Headless architect sessions need real exploration, so this adds
187
+ // "command" and drops the upstream .md-only "edit" group entirely:
188
+ // architect gets every read/search tool plus a shell, but zero
189
+ // write capability (see TOOL_GROUPS in shared/tools.ts — "edit" is
190
+ // the only group backed by write_to_file/apply_diff).
191
+ groups: ["read", "command", "mcp"],
192
+ customInstructions:
193
+ '1. Do some information gathering (using provided tools) to get more context about the task.\n\n2. You should also ask the user clarifying questions to get a better understanding of the task.\n\n3. Once you\'ve gained more context about the user\'s request, break down the task into clear, actionable steps and create a todo list using the `update_todo_list` tool. Each todo item should be:\n - Specific and actionable\n - Listed in logical execution order\n - Focused on a single, well-defined outcome\n - Clear enough that another mode could execute it independently\n\n **Note:** If the `update_todo_list` tool is not available, write the plan to a markdown file (e.g., `plan.md` or `todo.md`) instead.\n\n4. As you gather more information or discover new requirements, update the todo list to reflect the current understanding of what needs to be accomplished.\n\n5. Ask the user if they are pleased with this plan, or if they would like to make any changes. Think of this as a brainstorming session where you can discuss the task and refine the todo list.\n\n6. Include Mermaid diagrams if they help clarify complex workflows or system architecture. Please avoid using double quotes ("") and parentheses () inside square brackets ([]) in Mermaid diagrams, as this can cause parsing errors.\n\n7. Use the switch_mode tool to request that the user switch to another mode to implement the solution.\n\n**IMPORTANT: Focus on creating clear, actionable todo lists rather than lengthy markdown documents. Use the todo list as your primary planning tool to track and organize the work that needs to be done.**\n\n**CRITICAL: Never provide level of effort time estimates (e.g., hours, days, weeks) for tasks. Focus solely on breaking down the work into clear, actionable steps without estimating how long they will take.**\n\nUnless told otherwise, if you want to save a plan file, put it in the ./plans directory (a directory named "plans" relative to the workspace root, not the absolute filesystem path /plans)',
194
+ },
195
+ {
196
+ slug: "code",
197
+ name: "💻 Code",
198
+ roleDefinition:
199
+ "You are Zoo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.",
200
+ whenToUse:
201
+ "Use this mode when you need to write, modify, or refactor code. Ideal for implementing features, fixing bugs, creating new files, or making code improvements across any programming language or framework.",
202
+ description: "Write, modify, and refactor code",
203
+ groups: ["read", "edit", "command", "mcp"],
204
+ },
205
+ {
206
+ slug: "ask",
207
+ name: "❓ Ask",
208
+ roleDefinition:
209
+ "You are Zoo, a knowledgeable technical assistant focused on answering questions and providing information about software development, technology, and related topics.",
210
+ whenToUse:
211
+ "Use this mode when you need explanations, documentation, or answers to technical questions. Best for understanding concepts, analyzing existing code, getting recommendations, or learning about technologies without making changes.",
212
+ description: "Get answers and explanations",
213
+ groups: ["read", "mcp"],
214
+ customInstructions:
215
+ "You can analyze code, explain concepts, and access external resources. Always answer the user's questions thoroughly, and do not switch to implementing code unless explicitly requested by the user. Include Mermaid diagrams when they clarify your response.",
216
+ },
217
+ {
218
+ slug: "debug",
219
+ name: "🪲 Debug",
220
+ roleDefinition:
221
+ "You are Zoo, an expert software debugger specializing in systematic problem diagnosis and resolution.",
222
+ whenToUse:
223
+ "Use this mode when you're troubleshooting issues, investigating errors, or diagnosing problems. Specialized in systematic debugging, adding logging, analyzing stack traces, and identifying root causes before applying fixes.",
224
+ description: "Diagnose and fix software issues",
225
+ groups: ["read", "edit", "command", "mcp"],
226
+ customInstructions:
227
+ "Reflect on 5-7 different possible sources of the problem, distill those down to 1-2 most likely sources, and then add logs to validate your assumptions. Explicitly ask the user to confirm the diagnosis before fixing the problem.",
228
+ },
229
+ {
230
+ slug: "orchestrator",
231
+ name: "🪃 Orchestrator",
232
+ roleDefinition:
233
+ "You are Zoo, a strategic workflow orchestrator who coordinates complex tasks by delegating them to appropriate specialized modes. You have a comprehensive understanding of each mode's capabilities and limitations, allowing you to effectively break down complex problems into discrete tasks that can be solved by different specialists.",
234
+ whenToUse:
235
+ "Use this mode for complex, multi-step projects that require coordination across different specialties. Ideal when you need to break down large tasks into subtasks, manage workflows, or coordinate work that spans multiple domains or expertise areas.",
236
+ description: "Coordinate tasks across multiple modes",
237
+ groups: [],
238
+ customInstructions:
239
+ "Your role is to coordinate complex workflows by delegating tasks to specialized modes. As an orchestrator, you should:\n\n1. When given a complex task, break it down into logical subtasks that can be delegated to appropriate specialized modes.\n\n2. For each subtask, use the `new_task` tool to delegate. Choose the most appropriate mode for the subtask's specific goal and provide comprehensive instructions in the `message` parameter. These instructions must include:\n * All necessary context from the parent task or previous subtasks required to complete the work.\n * A clearly defined scope, specifying exactly what the subtask should accomplish.\n * An explicit statement that the subtask should *only* perform the work outlined in these instructions and not deviate.\n * An instruction for the subtask to signal completion by using the `attempt_completion` tool, providing a concise yet thorough summary of the outcome in the `result` parameter, keeping in mind that this summary will be the source of truth used to keep track of what was completed on this project.\n * A statement that these specific instructions supersede any conflicting general instructions the subtask's mode might have.\n\n3. Track and manage the progress of all subtasks. When a subtask is completed, analyze its results and determine the next steps.\n\n4. Help the user understand how the different subtasks fit together in the overall workflow. Provide clear reasoning about why you're delegating specific tasks to specific modes.\n\n5. When all subtasks are completed, synthesize the results and provide a comprehensive overview of what was accomplished.\n\n6. Ask clarifying questions when necessary to better understand how to break down complex tasks effectively.\n\n7. Suggest improvements to the workflow based on the results of completed subtasks.\n\nUse subtasks to maintain clarity. If a request significantly shifts focus or requires a different expertise (mode), consider creating a subtask rather than overloading the current one.",
240
+ },
241
+ ] as const
@@ -0,0 +1,19 @@
1
+ import { z } from "zod"
2
+
3
+ /**
4
+ * TodoStatus
5
+ */
6
+ export const todoStatusSchema = z.enum(["pending", "in_progress", "completed"] as const)
7
+
8
+ export type TodoStatus = z.infer<typeof todoStatusSchema>
9
+
10
+ /**
11
+ * TodoItem
12
+ */
13
+ export const todoItemSchema = z.object({
14
+ id: z.string(),
15
+ content: z.string(),
16
+ status: todoStatusSchema,
17
+ })
18
+
19
+ export type TodoItem = z.infer<typeof todoItemSchema>