saeeol 1.2.0 → 1.2.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 (193) hide show
  1. package/package.json +14 -14
  2. package/src/cli/cmd/tui/component/dialog/dialog-agent.tsx +32 -0
  3. package/src/cli/cmd/tui/component/dialog/dialog-command.tsx +190 -0
  4. package/src/cli/cmd/tui/component/dialog/dialog-console-org.tsx +103 -0
  5. package/src/cli/cmd/tui/component/dialog/dialog-go-upsell.tsx +159 -0
  6. package/src/cli/cmd/tui/component/dialog/dialog-mcp.tsx +86 -0
  7. package/src/cli/cmd/tui/component/dialog/dialog-model.tsx +238 -0
  8. package/src/cli/cmd/tui/component/dialog/dialog-provider.tsx +343 -0
  9. package/src/cli/cmd/tui/component/dialog/dialog-session-delete-failed.tsx +103 -0
  10. package/src/cli/cmd/tui/component/dialog/dialog-session-list.tsx +301 -0
  11. package/src/cli/cmd/tui/component/dialog/dialog-session-rename.tsx +35 -0
  12. package/src/cli/cmd/tui/component/dialog/dialog-skill.tsx +37 -0
  13. package/src/cli/cmd/tui/component/dialog/dialog-stash.tsx +87 -0
  14. package/src/cli/cmd/tui/component/dialog/dialog-status.tsx +190 -0
  15. package/src/cli/cmd/tui/component/dialog/dialog-tag.tsx +44 -0
  16. package/src/cli/cmd/tui/component/dialog/dialog-theme-list.tsx +50 -0
  17. package/src/cli/cmd/tui/component/dialog/dialog-variant.tsx +39 -0
  18. package/src/cli/cmd/tui/component/dialog/dialog-workspace-create.tsx +200 -0
  19. package/src/cli/cmd/tui/component/dialog/dialog-workspace-unavailable.tsx +81 -0
  20. package/src/cli/cmd/tui/component/dialog-agent.tsx +1 -32
  21. package/src/cli/cmd/tui/component/dialog-command.tsx +1 -190
  22. package/src/cli/cmd/tui/component/dialog-console-org.tsx +1 -103
  23. package/src/cli/cmd/tui/component/dialog-go-upsell.tsx +1 -159
  24. package/src/cli/cmd/tui/component/dialog-mcp.tsx +1 -86
  25. package/src/cli/cmd/tui/component/dialog-model.tsx +1 -238
  26. package/src/cli/cmd/tui/component/dialog-provider.tsx +1 -343
  27. package/src/cli/cmd/tui/component/dialog-session-delete-failed.tsx +1 -103
  28. package/src/cli/cmd/tui/component/dialog-session-list.tsx +1 -301
  29. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +1 -35
  30. package/src/cli/cmd/tui/component/dialog-skill.tsx +1 -37
  31. package/src/cli/cmd/tui/component/dialog-stash.tsx +1 -87
  32. package/src/cli/cmd/tui/component/dialog-status.tsx +1 -190
  33. package/src/cli/cmd/tui/component/dialog-tag.tsx +1 -44
  34. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +1 -50
  35. package/src/cli/cmd/tui/component/dialog-variant.tsx +1 -39
  36. package/src/cli/cmd/tui/component/dialog-workspace-create.tsx +1 -200
  37. package/src/cli/cmd/tui/component/dialog-workspace-unavailable.tsx +1 -81
  38. package/src/session/compaction-helpers.ts +1 -169
  39. package/src/session/compaction.ts +1 -712
  40. package/src/session/core/compaction/compaction-helpers.ts +169 -0
  41. package/src/session/core/compaction/compaction.ts +712 -0
  42. package/src/session/core/compaction/overflow.ts +28 -0
  43. package/src/session/core/instruction.ts +234 -0
  44. package/src/session/core/llm.ts +504 -0
  45. package/src/session/core/network.ts +392 -0
  46. package/src/session/core/processor.ts +731 -0
  47. package/src/session/core/projectors.ts +139 -0
  48. package/src/session/core/resolve-tools.ts +241 -0
  49. package/src/session/core/retry.ts +149 -0
  50. package/src/session/core/revert.ts +173 -0
  51. package/src/session/core/run-state.ts +110 -0
  52. package/src/session/core/schema.ts +35 -0
  53. package/src/session/core/session-types.ts +160 -0
  54. package/src/session/core/session.sql.ts +124 -0
  55. package/src/session/core/session.ts +948 -0
  56. package/src/session/core/shell-exec.ts +205 -0
  57. package/src/session/core/status.ts +100 -0
  58. package/src/session/core/subtask.ts +268 -0
  59. package/src/session/core/summary.ts +173 -0
  60. package/src/session/core/system.ts +114 -0
  61. package/src/session/core/todo.ts +86 -0
  62. package/src/session/core/user-part.ts +293 -0
  63. package/src/session/instruction.ts +1 -234
  64. package/src/session/llm.ts +1 -504
  65. package/src/session/message/message-errors.ts +83 -0
  66. package/src/session/message/message-parts.ts +89 -0
  67. package/src/session/message/message-query.ts +107 -0
  68. package/src/session/message/message-transform.ts +156 -0
  69. package/src/session/message/message-types.ts +68 -0
  70. package/src/session/message/message-v2.ts +73 -0
  71. package/src/session/message/message.ts +192 -0
  72. package/src/session/message-errors.ts +1 -83
  73. package/src/session/message-parts.ts +1 -89
  74. package/src/session/message-query.ts +1 -107
  75. package/src/session/message-transform.ts +1 -156
  76. package/src/session/message-types.ts +1 -68
  77. package/src/session/message-v2.ts +1 -73
  78. package/src/session/message.ts +1 -192
  79. package/src/session/network.ts +1 -392
  80. package/src/session/overflow.ts +1 -28
  81. package/src/session/processor.ts +1 -731
  82. package/src/session/projectors.ts +2 -139
  83. package/src/session/prompt/prompt-command.ts +93 -0
  84. package/src/session/prompt/prompt-loop.ts +299 -0
  85. package/src/session/prompt/prompt-model.ts +44 -0
  86. package/src/session/prompt/prompt-reminders.ts +120 -0
  87. package/src/session/prompt/prompt-resolve.ts +42 -0
  88. package/src/session/prompt/prompt-schemas.ts +128 -0
  89. package/src/session/prompt/prompt-title.ts +55 -0
  90. package/src/session/prompt/prompt-types.ts +47 -0
  91. package/src/session/prompt/prompt-user-msg.ts +80 -0
  92. package/src/session/prompt/prompt.ts +211 -0
  93. package/src/session/prompt-command.ts +1 -93
  94. package/src/session/prompt-loop.ts +1 -299
  95. package/src/session/prompt-model.ts +1 -44
  96. package/src/session/prompt-reminders.ts +1 -120
  97. package/src/session/prompt-resolve.ts +1 -42
  98. package/src/session/prompt-schemas.ts +1 -128
  99. package/src/session/prompt-title.ts +1 -55
  100. package/src/session/prompt-types.ts +1 -47
  101. package/src/session/prompt-user-msg.ts +1 -80
  102. package/src/session/prompt.ts +1 -211
  103. package/src/session/resolve-tools.ts +1 -241
  104. package/src/session/retry.ts +1 -149
  105. package/src/session/revert.ts +1 -173
  106. package/src/session/run-state.ts +1 -110
  107. package/src/session/schema.ts +1 -35
  108. package/src/session/session-types.ts +1 -160
  109. package/src/session/session.sql.ts +1 -124
  110. package/src/session/session.ts +1 -948
  111. package/src/session/shell-exec.ts +1 -205
  112. package/src/session/status.ts +1 -100
  113. package/src/session/subtask.ts +1 -268
  114. package/src/session/summary.ts +1 -173
  115. package/src/session/system.ts +1 -114
  116. package/src/session/todo.ts +1 -86
  117. package/src/session/user-part.ts +1 -293
  118. package/src/tool/apply_patch.ts +1 -334
  119. package/src/tool/bash.ts +1 -656
  120. package/src/tool/core/external-directory.ts +55 -0
  121. package/src/tool/core/invalid.ts +21 -0
  122. package/src/tool/core/recall.ts +164 -0
  123. package/src/tool/core/recall.txt +12 -0
  124. package/src/tool/core/schema.ts +16 -0
  125. package/src/tool/core/tool.ts +162 -0
  126. package/src/tool/core/truncate.ts +160 -0
  127. package/src/tool/core/truncation-dir.ts +4 -0
  128. package/src/tool/diagnostics.ts +1 -20
  129. package/src/tool/edit-replacers.ts +1 -288
  130. package/src/tool/edit-utils.ts +1 -86
  131. package/src/tool/edit.ts +1 -262
  132. package/src/tool/external-directory.ts +1 -55
  133. package/src/tool/file/apply_patch.ts +334 -0
  134. package/src/tool/file/apply_patch.txt +33 -0
  135. package/src/tool/file/bash.ts +656 -0
  136. package/src/tool/file/bash.txt +119 -0
  137. package/src/tool/file/edit-replacers.ts +288 -0
  138. package/src/tool/file/edit-utils.ts +86 -0
  139. package/src/tool/file/edit.ts +262 -0
  140. package/src/tool/file/edit.txt +10 -0
  141. package/src/tool/file/read.ts +389 -0
  142. package/src/tool/file/read.txt +14 -0
  143. package/src/tool/file/write.ts +114 -0
  144. package/src/tool/file/write.txt +8 -0
  145. package/src/tool/glob.ts +1 -115
  146. package/src/tool/grep.ts +1 -151
  147. package/src/tool/integration/diagnostics.ts +20 -0
  148. package/src/tool/integration/lsp.ts +113 -0
  149. package/src/tool/integration/lsp.txt +24 -0
  150. package/src/tool/integration/mcp-exa.ts +73 -0
  151. package/src/tool/integration/package.ts +168 -0
  152. package/src/tool/integration/registry.ts +375 -0
  153. package/src/tool/invalid.ts +1 -21
  154. package/src/tool/lsp.ts +1 -113
  155. package/src/tool/mcp-exa.ts +1 -73
  156. package/src/tool/package.ts +1 -168
  157. package/src/tool/plan.ts +1 -30
  158. package/src/tool/question.ts +1 -52
  159. package/src/tool/read.ts +1 -389
  160. package/src/tool/recall.ts +1 -164
  161. package/src/tool/registry.ts +1 -375
  162. package/src/tool/schema.ts +1 -16
  163. package/src/tool/search/glob.ts +115 -0
  164. package/src/tool/search/glob.txt +6 -0
  165. package/src/tool/search/grep.ts +151 -0
  166. package/src/tool/search/grep.txt +8 -0
  167. package/src/tool/search/warpgrep.ts +107 -0
  168. package/src/tool/search/warpgrep.txt +10 -0
  169. package/src/tool/search/webfetch.ts +202 -0
  170. package/src/tool/search/webfetch.txt +13 -0
  171. package/src/tool/search/websearch.ts +71 -0
  172. package/src/tool/search/websearch.txt +14 -0
  173. package/src/tool/skill.ts +1 -91
  174. package/src/tool/task.ts +1 -197
  175. package/src/tool/todo.ts +1 -62
  176. package/src/tool/tool.ts +1 -162
  177. package/src/tool/truncate.ts +1 -160
  178. package/src/tool/truncation-dir.ts +1 -4
  179. package/src/tool/warpgrep.ts +1 -107
  180. package/src/tool/webfetch.ts +1 -202
  181. package/src/tool/websearch.ts +1 -71
  182. package/src/tool/workflow/plan-enter.txt +14 -0
  183. package/src/tool/workflow/plan-exit.txt +13 -0
  184. package/src/tool/workflow/plan.ts +30 -0
  185. package/src/tool/workflow/question.ts +52 -0
  186. package/src/tool/workflow/question.txt +11 -0
  187. package/src/tool/workflow/skill.ts +91 -0
  188. package/src/tool/workflow/skill.txt +5 -0
  189. package/src/tool/workflow/task.ts +197 -0
  190. package/src/tool/workflow/task.txt +57 -0
  191. package/src/tool/workflow/todo.ts +62 -0
  192. package/src/tool/workflow/todowrite.txt +167 -0
  193. package/src/tool/write.ts +1 -114
@@ -1,375 +1 @@
1
- import { PlanExitTool } from "./plan"
2
- import { Session } from "@/session/session"
3
- import { QuestionTool } from "./question"
4
- import { SuggestTool } from "../overlay/suggestion/tool"
5
- import { BashTool } from "./bash"
6
- import { EditTool } from "./edit"
7
- import { GlobTool } from "./glob"
8
- import { GrepTool } from "./grep"
9
- import { ReadTool } from "./read"
10
- import { TaskTool } from "./task"
11
- import { TodoWriteTool } from "./todo"
12
- import { WebFetchTool } from "./webfetch"
13
- import { WriteTool } from "./write"
14
- import { InvalidTool } from "./invalid"
15
- import { SkillTool } from "./skill"
16
- import { PackageTool } from "./package"
17
- import * as Tool from "./tool"
18
- import { Config } from "@/config/config"
19
- import { type ToolContext as PluginToolContext, type ToolDefinition } from "@saeeol/plugin"
20
- import { Schema } from "effect"
21
- import z from "zod"
22
- import { ZodOverride } from "@/util/effect-zod"
23
- import { Plugin } from "../plugin"
24
- import { Provider } from "@/provider/provider"
25
- import { ProviderID, type ModelID } from "../provider/schema"
26
- import { WebSearchTool } from "./websearch"
27
- import { SaeeolToolRegistry } from "../overlay/tool/registry"
28
- import { makeRuntime } from "@/effect/run-service"
29
- import { Flag } from "@saeeol/core/flag/flag"
30
- import * as Log from "@saeeol/core/util/log"
31
- import { LspTool } from "./lsp"
32
- import * as Truncate from "./truncate"
33
- import { ApplyPatchTool } from "./apply_patch"
34
- import { Glob } from "@saeeol/core/util/glob"
35
- import path from "path"
36
- import { pathToFileURL } from "url"
37
- import { Effect, Layer, Context } from "effect"
38
- import { FetchHttpClient, HttpClient } from "effect/unstable/http"
39
- import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
40
- import { CrossSpawnSpawner } from "@saeeol/core/cross-spawn-spawner"
41
- import { Ripgrep } from "../file/ripgrep"
42
- import { Format } from "../format"
43
- import { InstanceState } from "@/effect/instance-state"
44
- import { Question } from "../question"
45
- import { Todo } from "../session/todo"
46
- import { LSP } from "@/lsp/lsp"
47
- import { Instruction } from "../session/instruction"
48
- import { AppFileSystem } from "@saeeol/core/filesystem"
49
- import { Bus } from "../bus"
50
- import { Agent } from "../agent/agent"
51
- import { Skill } from "../skill"
52
- import { Permission } from "@/permission"
53
-
54
- const log = Log.create({ service: "tool.registry" })
55
-
56
- type TaskDef = Tool.InferDef<typeof TaskTool>
57
- type ReadDef = Tool.InferDef<typeof ReadTool>
58
-
59
- type State = {
60
- custom: Tool.Def[]
61
- builtin: Tool.Def[]
62
- task: TaskDef
63
- read: ReadDef
64
- }
65
-
66
- export interface Interface {
67
- readonly ids: () => Effect.Effect<string[]>
68
- readonly all: () => Effect.Effect<Tool.Def[]>
69
- readonly named: () => Effect.Effect<{ task: TaskDef; read: ReadDef }>
70
- readonly tools: (model: { providerID: ProviderID; modelID: ModelID; agent: Agent.Info }) => Effect.Effect<Tool.Def[]>
71
- }
72
-
73
- export class Service extends Context.Service<Service, Interface>()("@saeeol/ToolRegistry") {}
74
-
75
- export const layer: Layer.Layer<
76
- Service,
77
- never,
78
- | Config.Service
79
- | Plugin.Service
80
- | Question.Service
81
- | Todo.Service
82
- | Agent.Service
83
- | Skill.Service
84
- | Session.Service
85
- | Provider.Service
86
- | LSP.Service
87
- | Instruction.Service
88
- | AppFileSystem.Service
89
- | Bus.Service
90
- | HttpClient.HttpClient
91
- | ChildProcessSpawner
92
- | Ripgrep.Service
93
- | Format.Service
94
- | Truncate.Service
95
- > = Layer.effect(
96
- Service,
97
- Effect.gen(function* () {
98
- const config = yield* Config.Service
99
- const plugin = yield* Plugin.Service
100
- const agents = yield* Agent.Service
101
- const skill = yield* Skill.Service
102
- const truncate = yield* Truncate.Service
103
-
104
- const invalid = yield* InvalidTool
105
- const task = yield* TaskTool
106
- const read = yield* ReadTool
107
- const question = yield* QuestionTool
108
- const todo = yield* TodoWriteTool
109
- const lsptool = yield* LspTool
110
- const plan = yield* PlanExitTool
111
- const webfetch = yield* WebFetchTool
112
- const websearch = yield* WebSearchTool
113
- const bash = yield* BashTool
114
- const globtool = yield* GlobTool
115
- const writetool = yield* WriteTool
116
- const edit = yield* EditTool
117
- const greptool = yield* GrepTool
118
- const patchtool = yield* ApplyPatchTool
119
- const skilltool = yield* SkillTool
120
- const packagetool = yield* PackageTool
121
- const agent = yield* Agent.Service
122
- const suggesttool = yield* SuggestTool
123
- const saeeolToolInfos = yield* SaeeolToolRegistry.infos()
124
-
125
- const state = yield* InstanceState.make<State>(
126
- Effect.fn("ToolRegistry.state")(function* (ctx) {
127
- const custom: Tool.Def[] = []
128
-
129
- function fromPlugin(id: string, def: ToolDefinition): Tool.Def {
130
- // Plugin tools define their args as a raw Zod shape. Wrap the
131
- // derived Zod object in a `Schema.declare` so it slots into the
132
- // Schema-typed framework, and annotate with `ZodOverride` so the
133
- // walker emits the original Zod object for LLM JSON Schema.
134
- const zodParams = z.object(def.args)
135
- const parameters = Schema.declare<unknown>((u): u is unknown => zodParams.safeParse(u).success).annotate({
136
- [ZodOverride]: zodParams,
137
- })
138
- return {
139
- id,
140
- parameters,
141
- description: def.description,
142
- execute: (args, toolCtx) =>
143
- Effect.gen(function* () {
144
- const pluginCtx: PluginToolContext = {
145
- ...toolCtx,
146
- ask: (req) => toolCtx.ask(req),
147
- directory: ctx.directory,
148
- worktree: ctx.worktree,
149
- }
150
- const result = yield* Effect.promise(() => def.execute(args as any, pluginCtx))
151
- const output = typeof result === "string" ? result : result.output
152
- const metadata = typeof result === "string" ? {} : (result.metadata ?? {})
153
- const info = yield* agent.get(toolCtx.agent)
154
- const out = yield* truncate.output(output, {}, info)
155
- return {
156
- title: "",
157
- output: out.truncated ? out.content : output,
158
- metadata: {
159
- ...metadata,
160
- truncated: out.truncated,
161
- ...(out.truncated && { outputPath: out.outputPath }),
162
- },
163
- }
164
- }).pipe(
165
- Effect.withSpan("Tool.execute", {
166
- attributes: {
167
- "tool.name": id,
168
- "session.id": toolCtx.sessionID,
169
- "message.id": toolCtx.messageID,
170
- ...(toolCtx.callID ? { "tool.call_id": toolCtx.callID } : {}),
171
- },
172
- }),
173
- ),
174
- }
175
- }
176
-
177
- const dirs = yield* config.directories()
178
- const matches = dirs.flatMap((dir) =>
179
- Glob.scanSync("{tool,tools}/*.{js,ts}", { cwd: dir, absolute: true, dot: true, symlink: true }),
180
- )
181
- if (matches.length) yield* config.waitForDependencies()
182
- for (const match of matches) {
183
- const namespace = path.basename(match, path.extname(match))
184
- // `match` is an absolute filesystem path from `Glob.scanSync(..., { absolute: true })`.
185
- // Import it as `file://` so Node on Windows accepts the dynamic import.
186
- const mod = yield* Effect.promise(() => import(pathToFileURL(match).href))
187
- for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
188
- custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
189
- }
190
- }
191
-
192
- const plugins = yield* plugin.list()
193
- for (const p of plugins) {
194
- for (const [id, def] of Object.entries(p.tool ?? {})) {
195
- custom.push(fromPlugin(id, def))
196
- }
197
- }
198
-
199
- const cfg = yield* config.get()
200
- const questionEnabled =
201
- ["app", "cli", "desktop", "vscode"].includes(Flag.SAEEOL_CLIENT) || Flag.SAEEOL_ENABLE_QUESTION_TOOL
202
-
203
- const tool = yield* Effect.all({
204
- invalid: Tool.init(invalid),
205
- bash: Tool.init(bash),
206
- read: Tool.init(read),
207
- glob: Tool.init(globtool),
208
- grep: Tool.init(greptool),
209
- edit: Tool.init(edit),
210
- write: Tool.init(writetool),
211
- task: Tool.init(task),
212
- fetch: Tool.init(webfetch),
213
- todo: Tool.init(todo),
214
- search: Tool.init(websearch),
215
- skill: Tool.init(skilltool),
216
- package: Tool.init(packagetool),
217
- patch: Tool.init(patchtool),
218
- question: Tool.init(question),
219
- lsp: Tool.init(lsptool),
220
- plan: Tool.init(plan),
221
- suggest: Tool.init(suggesttool),
222
- })
223
-
224
- const saeeol = yield* SaeeolToolRegistry.build(saeeolToolInfos, { agent: agents, truncate })
225
-
226
- return {
227
- custom,
228
- builtin: SaeeolToolRegistry.describe(
229
- [
230
- tool.invalid,
231
- ...(questionEnabled ? [tool.question] : []),
232
- tool.bash,
233
- tool.read,
234
- tool.glob,
235
- tool.grep,
236
- tool.edit,
237
- tool.write,
238
- tool.task,
239
- tool.fetch,
240
- tool.todo,
241
- tool.search,
242
- tool.skill,
243
- tool.package,
244
- tool.patch,
245
- tool.plan,
246
- ...(["cli", "vscode"].includes(Flag.SAEEOL_CLIENT) ? [tool.suggest] : []),
247
- ...SaeeolToolRegistry.extra(saeeol, cfg),
248
- ...(Flag.SAEEOL_EXPERIMENTAL_LSP_TOOL ? [tool.lsp] : []),
249
- ],
250
- saeeol,
251
- ),
252
- task: tool.task,
253
- read: tool.read,
254
- }
255
- }),
256
- )
257
-
258
- const all: Interface["all"] = Effect.fn("ToolRegistry.all")(function* () {
259
- const s = yield* InstanceState.get(state)
260
- return [...s.builtin, ...s.custom] as Tool.Def[]
261
- })
262
-
263
- const ids: Interface["ids"] = Effect.fn("ToolRegistry.ids")(function* () {
264
- return (yield* all()).map((tool) => tool.id)
265
- })
266
-
267
- const describeSkill = Effect.fn("ToolRegistry.describeSkill")(function* (agent: Agent.Info) {
268
- const list = yield* skill.available(agent)
269
- if (list.length === 0) return "No skills are currently available."
270
- return [
271
- "Load a specialized skill that provides domain-specific instructions and workflows.",
272
- "",
273
- "When you recognize that a task matches one of the available skills listed below, use this tool to load the full skill instructions.",
274
- "",
275
- "The skill will inject detailed instructions, workflows, and access to bundled resources (scripts, references, templates) into the conversation context.",
276
- "",
277
- 'Tool output includes a `<skill_content name="...">` block with the loaded content.',
278
- "",
279
- "The following skills provide specialized sets of instructions for particular tasks",
280
- "Invoke this tool to load a skill when a task matches one of the available skills listed below:",
281
- "",
282
- Skill.fmt(list, { verbose: false }),
283
- ].join("\n")
284
- })
285
-
286
- const describeTask = Effect.fn("ToolRegistry.describeTask")(function* (agent: Agent.Info) {
287
- const items = (yield* agents.list()).filter((item) => item.mode !== "primary")
288
- const filtered = items.filter(
289
- (item) => Permission.evaluate("task", item.name, agent.permission).action !== "deny",
290
- )
291
- const list = filtered.toSorted((a, b) => a.name.localeCompare(b.name))
292
- const description = list
293
- .map(
294
- (item) =>
295
- `- ${item.name}: ${item.description ?? "This subagent should only be called manually by the user."}`,
296
- )
297
- .join("\n")
298
- return ["Available agent types and the tools they have access to:", description].join("\n")
299
- })
300
-
301
- const tools: Interface["tools"] = Effect.fn("ToolRegistry.tools")(function* (input) {
302
- const filtered = (yield* all()).filter((tool) => {
303
- if (tool.id === WebSearchTool.id) {
304
- return input.providerID === ProviderID.saeeol || Flag.SAEEOL_ENABLE_EXA
305
- }
306
-
307
- const usePatch =
308
- !!process.env["SAEEOL_E2E_LLM_URL"] ||
309
- (input.modelID.includes("gpt-") && !input.modelID.includes("oss") && !input.modelID.includes("gpt-4"))
310
- if (tool.id === ApplyPatchTool.id) return usePatch
311
- if (tool.id === EditTool.id) return !usePatch
312
-
313
- return true
314
- })
315
-
316
- return yield* Effect.forEach(
317
- filtered,
318
- Effect.fnUntraced(function* (tool: Tool.Def) {
319
- using _ = log.time(tool.id)
320
- const output = {
321
- description: tool.description,
322
- parameters: tool.parameters,
323
- }
324
- yield* plugin.trigger("tool.definition", { toolID: tool.id }, output)
325
- return {
326
- id: tool.id,
327
- description: [
328
- output.description,
329
- tool.id === TaskTool.id ? yield* describeTask(input.agent) : undefined,
330
- tool.id === SkillTool.id ? yield* describeSkill(input.agent) : undefined,
331
- ]
332
- .filter(Boolean)
333
- .join("\n"),
334
- parameters: output.parameters,
335
- execute: tool.execute,
336
- formatValidationError: tool.formatValidationError,
337
- }
338
- }),
339
- { concurrency: "unbounded" },
340
- )
341
- })
342
-
343
- const named: Interface["named"] = Effect.fn("ToolRegistry.named")(function* () {
344
- const s = yield* InstanceState.get(state)
345
- return { task: s.task, read: s.read }
346
- })
347
-
348
- return Service.of({ ids, all, named, tools })
349
- }),
350
- )
351
-
352
- export const defaultLayer = Layer.suspend(() =>
353
- layer.pipe(
354
- Layer.provide(Config.defaultLayer),
355
- Layer.provide(Plugin.defaultLayer),
356
- Layer.provide(Question.defaultLayer),
357
- Layer.provide(Todo.defaultLayer),
358
- Layer.provide(Skill.defaultLayer),
359
- Layer.provide(Agent.defaultLayer),
360
- Layer.provide(Session.defaultLayer),
361
- Layer.provide(Provider.defaultLayer),
362
- Layer.provide(LSP.defaultLayer),
363
- Layer.provide(Instruction.defaultLayer),
364
- Layer.provide(AppFileSystem.defaultLayer),
365
- Layer.provide(Bus.layer),
366
- Layer.provide(FetchHttpClient.layer),
367
- Layer.provide(Format.defaultLayer),
368
- Layer.provide(CrossSpawnSpawner.defaultLayer),
369
- Layer.provide(Ripgrep.defaultLayer),
370
- Layer.provide(Truncate.defaultLayer),
371
- ),
372
- )
373
- const { runPromise } = makeRuntime(Service, defaultLayer)
374
- export const ids = () => runPromise((svc) => svc.ids())
375
- export * as ToolRegistry from "./registry"
1
+ export * from "./integration/registry"
@@ -1,16 +1 @@
1
- import { Schema } from "effect"
2
-
3
- import { Identifier } from "@/id/id"
4
- import { zod, ZodOverride } from "@/util/effect-zod"
5
- import { withStatics } from "@/util/schema"
6
-
7
- const toolIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("tool") }).pipe(Schema.brand("ToolID"))
8
-
9
- export type ToolID = typeof toolIdSchema.Type
10
-
11
- export const ToolID = toolIdSchema.pipe(
12
- withStatics((schema: typeof toolIdSchema) => ({
13
- ascending: (id?: string) => schema.make(Identifier.ascending("tool", id)),
14
- zod: zod(schema),
15
- })),
16
- )
1
+ export * from "./core/schema"
@@ -0,0 +1,115 @@
1
+ import path from "path"
2
+ import { Effect, Option, Schema } from "effect"
3
+ import * as Stream from "effect/Stream"
4
+ import { InstanceState } from "@/effect/instance-state"
5
+ import { AppFileSystem } from "@saeeol/core/filesystem"
6
+ import { Ripgrep } from "../../file/ripgrep"
7
+ import { assertExternalDirectoryEffect } from "../core/external-directory"
8
+ import DESCRIPTION from "./glob.txt"
9
+ import * as Tool from "../core/tool"
10
+ function normalize(p: string) {
11
+ return p.replaceAll("\\", "/")
12
+ }
13
+
14
+ function split(pattern: string) {
15
+ const normalized = normalize(pattern)
16
+ if (!path.isAbsolute(normalized)) return
17
+ const index = normalized.search(/[*?{[]/)
18
+ if (index === -1) return { dir: normalized, pattern: "*" }
19
+ const slice = normalized.slice(0, index)
20
+ const cut = slice.lastIndexOf("/")
21
+ const dir = cut > 0 ? slice.slice(0, cut) : "/"
22
+ const next = normalized.slice(cut + 1)
23
+ return { dir, pattern: next || "*" }
24
+ }
25
+
26
+ export const Parameters = Schema.Struct({
27
+ pattern: Schema.String.annotate({ description: "The glob pattern to match files against" }),
28
+ path: Schema.optional(Schema.String).annotate({
29
+ description: `The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.`,
30
+ }),
31
+ })
32
+
33
+ export const GlobTool = Tool.define(
34
+ "glob",
35
+ Effect.gen(function* () {
36
+ const rg = yield* Ripgrep.Service
37
+ const fs = yield* AppFileSystem.Service
38
+
39
+ return {
40
+ description: DESCRIPTION,
41
+ parameters: Parameters,
42
+ execute: (params: { pattern: string; path?: string }, ctx: Tool.Context) =>
43
+ Effect.gen(function* () {
44
+ const ins = yield* InstanceState.context
45
+ const absolute = split(params.pattern)
46
+ yield* ctx.ask({
47
+ permission: "glob",
48
+ patterns: [params.pattern],
49
+ always: ["*"],
50
+ metadata: {
51
+ pattern: params.pattern,
52
+ path: params.path,
53
+ },
54
+ })
55
+
56
+ const base = absolute?.dir ?? params.path ?? ins.directory
57
+ const search = path.isAbsolute(base) ? base : path.resolve(ins.directory, base)
58
+ const info = yield* fs.stat(search).pipe(Effect.catch(() => Effect.succeed(undefined)))
59
+ if (info?.type === "File") {
60
+ throw new Error(`glob path must be a directory: ${search}`)
61
+ }
62
+ yield* assertExternalDirectoryEffect(ctx, search, { kind: "directory" })
63
+
64
+ const limit = 100
65
+ let truncated = false
66
+ const files = yield* rg
67
+ .files({ cwd: search, glob: [absolute?.pattern ?? params.pattern], signal: ctx.abort })
68
+ .pipe(
69
+ Stream.mapEffect((file) =>
70
+ Effect.gen(function* () {
71
+ const full = path.resolve(search, file)
72
+ const info = yield* fs.stat(full).pipe(Effect.catch(() => Effect.succeed(undefined)))
73
+ const mtime =
74
+ info?.mtime.pipe(
75
+ Option.map((date) => date.getTime()),
76
+ Option.getOrElse(() => 0),
77
+ ) ?? 0
78
+ return { path: full, mtime }
79
+ }),
80
+ ),
81
+ Stream.take(limit + 1),
82
+ Stream.runCollect,
83
+ Effect.map((chunk) => [...chunk]),
84
+ )
85
+
86
+ if (files.length > limit) {
87
+ truncated = true
88
+ files.length = limit
89
+ }
90
+ files.sort((a, b) => b.mtime - a.mtime)
91
+
92
+ const output = []
93
+ if (files.length === 0) output.push("No files found")
94
+ if (files.length > 0) {
95
+ output.push(...files.map((file) => file.path))
96
+ if (truncated) {
97
+ output.push("")
98
+ output.push(
99
+ `(Results are truncated: showing first ${limit} results. Consider using a more specific path or pattern.)`,
100
+ )
101
+ }
102
+ }
103
+
104
+ return {
105
+ title: path.relative(ins.worktree, search),
106
+ metadata: {
107
+ count: files.length,
108
+ truncated,
109
+ },
110
+ output: output.join("\n"),
111
+ }
112
+ }).pipe(Effect.orDie),
113
+ }
114
+ }),
115
+ )
@@ -0,0 +1,6 @@
1
+ - Fast file pattern matching tool that works with any codebase size
2
+ - Supports glob patterns like "**/*.js" or "src/**/*.ts"
3
+ - Returns matching file paths sorted by modification time
4
+ - Use this tool when you need to find files by name patterns
5
+ - When you are doing an open-ended search that may require multiple rounds of globbing and grepping, use the Task tool instead
6
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches as a batch that are potentially useful.
@@ -0,0 +1,151 @@
1
+ import path from "path"
2
+ import { Schema } from "effect"
3
+ import { Effect, Option } from "effect"
4
+ import { InstanceState } from "@/effect/instance-state"
5
+ import { AppFileSystem } from "@saeeol/core/filesystem"
6
+ import { Ripgrep } from "../../file/ripgrep"
7
+ import { assertExternalDirectoryEffect } from "../core/external-directory"
8
+ import DESCRIPTION from "./grep.txt"
9
+ import * as Tool from "../core/tool"
10
+
11
+ const MAX_LINE_LENGTH = 2000
12
+
13
+ export const Parameters = Schema.Struct({
14
+ pattern: Schema.String.annotate({ description: "The regex pattern to search for in file contents" }),
15
+ path: Schema.optional(Schema.String).annotate({
16
+ description: "The directory to search in. Defaults to the current working directory.",
17
+ }),
18
+ include: Schema.optional(Schema.String).annotate({
19
+ description: 'File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")',
20
+ }),
21
+ })
22
+
23
+ export const GrepTool = Tool.define(
24
+ "grep",
25
+ Effect.gen(function* () {
26
+ const fs = yield* AppFileSystem.Service
27
+ const rg = yield* Ripgrep.Service
28
+
29
+ return {
30
+ description: DESCRIPTION,
31
+ parameters: Parameters,
32
+ execute: (params: { pattern: string; path?: string; include?: string }, ctx: Tool.Context) =>
33
+ Effect.gen(function* () {
34
+ const empty = {
35
+ title: params.pattern,
36
+ metadata: { matches: 0, truncated: false },
37
+ output: "No files found",
38
+ }
39
+ if (!params.pattern) {
40
+ throw new Error("pattern is required")
41
+ }
42
+
43
+ yield* ctx.ask({
44
+ permission: "grep",
45
+ patterns: [params.pattern],
46
+ always: ["*"],
47
+ metadata: {
48
+ pattern: params.pattern,
49
+ path: params.path,
50
+ include: params.include,
51
+ },
52
+ })
53
+
54
+ const ins = yield* InstanceState.context
55
+ const search = AppFileSystem.resolve(
56
+ path.isAbsolute(params.path ?? ins.directory)
57
+ ? (params.path ?? ins.directory)
58
+ : path.join(ins.directory, params.path ?? "."),
59
+ )
60
+ const info = yield* fs.stat(search).pipe(Effect.catch(() => Effect.succeed(undefined)))
61
+ const cwd = info?.type === "Directory" ? search : path.dirname(search)
62
+ const file = info?.type === "Directory" ? undefined : [path.relative(cwd, search)]
63
+ yield* assertExternalDirectoryEffect(ctx, search, {
64
+ kind: info?.type === "Directory" ? "directory" : "file",
65
+ })
66
+
67
+ const result = yield* rg.search({
68
+ cwd,
69
+ pattern: params.pattern,
70
+ glob: params.include ? [params.include] : undefined,
71
+ file,
72
+ signal: ctx.abort,
73
+ })
74
+ if (result.items.length === 0) return empty
75
+
76
+ const rows = result.items.map((item) => ({
77
+ path: AppFileSystem.resolve(
78
+ path.isAbsolute(item.path.text) ? item.path.text : path.join(cwd, item.path.text),
79
+ ),
80
+ line: item.line_number,
81
+ text: item.lines.text,
82
+ }))
83
+ const times = new Map(
84
+ (yield* Effect.forEach(
85
+ [...new Set(rows.map((row) => row.path))],
86
+ Effect.fnUntraced(function* (file) {
87
+ const info = yield* fs.stat(file).pipe(Effect.catch(() => Effect.succeed(undefined)))
88
+ if (!info || info.type === "Directory") return undefined
89
+ return [
90
+ file,
91
+ info.mtime.pipe(
92
+ Option.map((time) => time.getTime()),
93
+ Option.getOrElse(() => 0),
94
+ ) ?? 0,
95
+ ] as const
96
+ }),
97
+ { concurrency: 16 },
98
+ )).filter((entry): entry is readonly [string, number] => Boolean(entry)),
99
+ )
100
+ const matches = rows.flatMap((row) => {
101
+ const mtime = times.get(row.path)
102
+ if (mtime === undefined) return []
103
+ return [{ ...row, mtime }]
104
+ })
105
+
106
+ matches.sort((a, b) => b.mtime - a.mtime)
107
+
108
+ const limit = 100
109
+ const truncated = matches.length > limit
110
+ const final = truncated ? matches.slice(0, limit) : matches
111
+ if (final.length === 0) return empty
112
+
113
+ const total = matches.length
114
+ const output = [`Found ${total} matches${truncated ? ` (showing first ${limit})` : ""}`]
115
+
116
+ let current = ""
117
+ for (const match of final) {
118
+ if (current !== match.path) {
119
+ if (current !== "") output.push("")
120
+ current = match.path
121
+ output.push(`${match.path}:`)
122
+ }
123
+ const text =
124
+ match.text.length > MAX_LINE_LENGTH ? match.text.substring(0, MAX_LINE_LENGTH) + "..." : match.text
125
+ output.push(` Line ${match.line}: ${text}`)
126
+ }
127
+
128
+ if (truncated) {
129
+ output.push("")
130
+ output.push(
131
+ `(Results truncated: showing ${limit} of ${total} matches (${total - limit} hidden). Consider using a more specific path or pattern.)`,
132
+ )
133
+ }
134
+
135
+ if (result.partial) {
136
+ output.push("")
137
+ output.push("(Some paths were inaccessible and skipped)")
138
+ }
139
+
140
+ return {
141
+ title: params.pattern,
142
+ metadata: {
143
+ matches: total,
144
+ truncated,
145
+ },
146
+ output: output.join("\n"),
147
+ }
148
+ }).pipe(Effect.orDie),
149
+ }
150
+ }),
151
+ )
@@ -0,0 +1,8 @@
1
+ - Fast content search tool that works with any codebase size
2
+ - Searches file contents using regular expressions
3
+ - Supports full regex syntax (eg. "log.*Error", "function\s+\w+", etc.)
4
+ - Filter files by pattern with the include parameter (eg. "*.js", "*.{ts,tsx}")
5
+ - Returns file paths and line numbers with at least one match sorted by modification time
6
+ - Use this tool when you need to find files containing specific patterns
7
+ - If you need to identify/count the number of matches within files, use the Bash tool with `rg` (ripgrep) directly. Do NOT use `grep`.
8
+ - When you are doing a deep search that may require multiple tool invocations, use the Task tool instead