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.
- package/package.json +14 -14
- package/src/cli/cmd/tui/component/dialog/dialog-agent.tsx +32 -0
- package/src/cli/cmd/tui/component/dialog/dialog-command.tsx +190 -0
- package/src/cli/cmd/tui/component/dialog/dialog-console-org.tsx +103 -0
- package/src/cli/cmd/tui/component/dialog/dialog-go-upsell.tsx +159 -0
- package/src/cli/cmd/tui/component/dialog/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog/dialog-model.tsx +238 -0
- package/src/cli/cmd/tui/component/dialog/dialog-provider.tsx +343 -0
- package/src/cli/cmd/tui/component/dialog/dialog-session-delete-failed.tsx +103 -0
- package/src/cli/cmd/tui/component/dialog/dialog-session-list.tsx +301 -0
- package/src/cli/cmd/tui/component/dialog/dialog-session-rename.tsx +35 -0
- package/src/cli/cmd/tui/component/dialog/dialog-skill.tsx +37 -0
- package/src/cli/cmd/tui/component/dialog/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog/dialog-status.tsx +190 -0
- package/src/cli/cmd/tui/component/dialog/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/dialog/dialog-variant.tsx +39 -0
- package/src/cli/cmd/tui/component/dialog/dialog-workspace-create.tsx +200 -0
- package/src/cli/cmd/tui/component/dialog/dialog-workspace-unavailable.tsx +81 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +1 -32
- package/src/cli/cmd/tui/component/dialog-command.tsx +1 -190
- package/src/cli/cmd/tui/component/dialog-console-org.tsx +1 -103
- package/src/cli/cmd/tui/component/dialog-go-upsell.tsx +1 -159
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +1 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +1 -238
- package/src/cli/cmd/tui/component/dialog-provider.tsx +1 -343
- package/src/cli/cmd/tui/component/dialog-session-delete-failed.tsx +1 -103
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +1 -301
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +1 -35
- package/src/cli/cmd/tui/component/dialog-skill.tsx +1 -37
- package/src/cli/cmd/tui/component/dialog-stash.tsx +1 -87
- package/src/cli/cmd/tui/component/dialog-status.tsx +1 -190
- package/src/cli/cmd/tui/component/dialog-tag.tsx +1 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +1 -50
- package/src/cli/cmd/tui/component/dialog-variant.tsx +1 -39
- package/src/cli/cmd/tui/component/dialog-workspace-create.tsx +1 -200
- package/src/cli/cmd/tui/component/dialog-workspace-unavailable.tsx +1 -81
- package/src/session/compaction-helpers.ts +1 -169
- package/src/session/compaction.ts +1 -712
- package/src/session/core/compaction/compaction-helpers.ts +169 -0
- package/src/session/core/compaction/compaction.ts +712 -0
- package/src/session/core/compaction/overflow.ts +28 -0
- package/src/session/core/instruction.ts +234 -0
- package/src/session/core/llm.ts +504 -0
- package/src/session/core/network.ts +392 -0
- package/src/session/core/processor.ts +731 -0
- package/src/session/core/projectors.ts +139 -0
- package/src/session/core/resolve-tools.ts +241 -0
- package/src/session/core/retry.ts +149 -0
- package/src/session/core/revert.ts +173 -0
- package/src/session/core/run-state.ts +110 -0
- package/src/session/core/schema.ts +35 -0
- package/src/session/core/session-types.ts +160 -0
- package/src/session/core/session.sql.ts +124 -0
- package/src/session/core/session.ts +948 -0
- package/src/session/core/shell-exec.ts +205 -0
- package/src/session/core/status.ts +100 -0
- package/src/session/core/subtask.ts +268 -0
- package/src/session/core/summary.ts +173 -0
- package/src/session/core/system.ts +114 -0
- package/src/session/core/todo.ts +86 -0
- package/src/session/core/user-part.ts +293 -0
- package/src/session/instruction.ts +1 -234
- package/src/session/llm.ts +1 -504
- package/src/session/message/message-errors.ts +83 -0
- package/src/session/message/message-parts.ts +89 -0
- package/src/session/message/message-query.ts +107 -0
- package/src/session/message/message-transform.ts +156 -0
- package/src/session/message/message-types.ts +68 -0
- package/src/session/message/message-v2.ts +73 -0
- package/src/session/message/message.ts +192 -0
- package/src/session/message-errors.ts +1 -83
- package/src/session/message-parts.ts +1 -89
- package/src/session/message-query.ts +1 -107
- package/src/session/message-transform.ts +1 -156
- package/src/session/message-types.ts +1 -68
- package/src/session/message-v2.ts +1 -73
- package/src/session/message.ts +1 -192
- package/src/session/network.ts +1 -392
- package/src/session/overflow.ts +1 -28
- package/src/session/processor.ts +1 -731
- package/src/session/projectors.ts +2 -139
- package/src/session/prompt/prompt-command.ts +93 -0
- package/src/session/prompt/prompt-loop.ts +299 -0
- package/src/session/prompt/prompt-model.ts +44 -0
- package/src/session/prompt/prompt-reminders.ts +120 -0
- package/src/session/prompt/prompt-resolve.ts +42 -0
- package/src/session/prompt/prompt-schemas.ts +128 -0
- package/src/session/prompt/prompt-title.ts +55 -0
- package/src/session/prompt/prompt-types.ts +47 -0
- package/src/session/prompt/prompt-user-msg.ts +80 -0
- package/src/session/prompt/prompt.ts +211 -0
- package/src/session/prompt-command.ts +1 -93
- package/src/session/prompt-loop.ts +1 -299
- package/src/session/prompt-model.ts +1 -44
- package/src/session/prompt-reminders.ts +1 -120
- package/src/session/prompt-resolve.ts +1 -42
- package/src/session/prompt-schemas.ts +1 -128
- package/src/session/prompt-title.ts +1 -55
- package/src/session/prompt-types.ts +1 -47
- package/src/session/prompt-user-msg.ts +1 -80
- package/src/session/prompt.ts +1 -211
- package/src/session/resolve-tools.ts +1 -241
- package/src/session/retry.ts +1 -149
- package/src/session/revert.ts +1 -173
- package/src/session/run-state.ts +1 -110
- package/src/session/schema.ts +1 -35
- package/src/session/session-types.ts +1 -160
- package/src/session/session.sql.ts +1 -124
- package/src/session/session.ts +1 -948
- package/src/session/shell-exec.ts +1 -205
- package/src/session/status.ts +1 -100
- package/src/session/subtask.ts +1 -268
- package/src/session/summary.ts +1 -173
- package/src/session/system.ts +1 -114
- package/src/session/todo.ts +1 -86
- package/src/session/user-part.ts +1 -293
- package/src/tool/apply_patch.ts +1 -334
- package/src/tool/bash.ts +1 -656
- package/src/tool/core/external-directory.ts +55 -0
- package/src/tool/core/invalid.ts +21 -0
- package/src/tool/core/recall.ts +164 -0
- package/src/tool/core/recall.txt +12 -0
- package/src/tool/core/schema.ts +16 -0
- package/src/tool/core/tool.ts +162 -0
- package/src/tool/core/truncate.ts +160 -0
- package/src/tool/core/truncation-dir.ts +4 -0
- package/src/tool/diagnostics.ts +1 -20
- package/src/tool/edit-replacers.ts +1 -288
- package/src/tool/edit-utils.ts +1 -86
- package/src/tool/edit.ts +1 -262
- package/src/tool/external-directory.ts +1 -55
- package/src/tool/file/apply_patch.ts +334 -0
- package/src/tool/file/apply_patch.txt +33 -0
- package/src/tool/file/bash.ts +656 -0
- package/src/tool/file/bash.txt +119 -0
- package/src/tool/file/edit-replacers.ts +288 -0
- package/src/tool/file/edit-utils.ts +86 -0
- package/src/tool/file/edit.ts +262 -0
- package/src/tool/file/edit.txt +10 -0
- package/src/tool/file/read.ts +389 -0
- package/src/tool/file/read.txt +14 -0
- package/src/tool/file/write.ts +114 -0
- package/src/tool/file/write.txt +8 -0
- package/src/tool/glob.ts +1 -115
- package/src/tool/grep.ts +1 -151
- package/src/tool/integration/diagnostics.ts +20 -0
- package/src/tool/integration/lsp.ts +113 -0
- package/src/tool/integration/lsp.txt +24 -0
- package/src/tool/integration/mcp-exa.ts +73 -0
- package/src/tool/integration/package.ts +168 -0
- package/src/tool/integration/registry.ts +375 -0
- package/src/tool/invalid.ts +1 -21
- package/src/tool/lsp.ts +1 -113
- package/src/tool/mcp-exa.ts +1 -73
- package/src/tool/package.ts +1 -168
- package/src/tool/plan.ts +1 -30
- package/src/tool/question.ts +1 -52
- package/src/tool/read.ts +1 -389
- package/src/tool/recall.ts +1 -164
- package/src/tool/registry.ts +1 -375
- package/src/tool/schema.ts +1 -16
- package/src/tool/search/glob.ts +115 -0
- package/src/tool/search/glob.txt +6 -0
- package/src/tool/search/grep.ts +151 -0
- package/src/tool/search/grep.txt +8 -0
- package/src/tool/search/warpgrep.ts +107 -0
- package/src/tool/search/warpgrep.txt +10 -0
- package/src/tool/search/webfetch.ts +202 -0
- package/src/tool/search/webfetch.txt +13 -0
- package/src/tool/search/websearch.ts +71 -0
- package/src/tool/search/websearch.txt +14 -0
- package/src/tool/skill.ts +1 -91
- package/src/tool/task.ts +1 -197
- package/src/tool/todo.ts +1 -62
- package/src/tool/tool.ts +1 -162
- package/src/tool/truncate.ts +1 -160
- package/src/tool/truncation-dir.ts +1 -4
- package/src/tool/warpgrep.ts +1 -107
- package/src/tool/webfetch.ts +1 -202
- package/src/tool/websearch.ts +1 -71
- package/src/tool/workflow/plan-enter.txt +14 -0
- package/src/tool/workflow/plan-exit.txt +13 -0
- package/src/tool/workflow/plan.ts +30 -0
- package/src/tool/workflow/question.ts +52 -0
- package/src/tool/workflow/question.txt +11 -0
- package/src/tool/workflow/skill.ts +91 -0
- package/src/tool/workflow/skill.txt +5 -0
- package/src/tool/workflow/task.ts +197 -0
- package/src/tool/workflow/task.txt +57 -0
- package/src/tool/workflow/todo.ts +62 -0
- package/src/tool/workflow/todowrite.txt +167 -0
- package/src/tool/write.ts +1 -114
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import * as Tool from "../core/tool"
|
|
3
|
+
import { WarpGrepClient } from "@morphllm/morphsdk/tools/warp-grep/client"
|
|
4
|
+
import { Telemetry } from "@saeeol/telemetry"
|
|
5
|
+
import { Instance } from "../../project/instance"
|
|
6
|
+
import { Bus } from "../../bus"
|
|
7
|
+
import { TuiEvent } from "../../cli/cmd/tui/event"
|
|
8
|
+
import DESCRIPTION from "./warpgrep.txt"
|
|
9
|
+
|
|
10
|
+
// FREE_PERIOD_TODO: Remove SAEEOL_WARPGREP_PROXY_URL constant and the proxy
|
|
11
|
+
// fallback below. After the free period ends, require MORPH_API_KEY and
|
|
12
|
+
// return an error when it is missing.
|
|
13
|
+
const SAEEOL_WARPGREP_PROXY_URL = "https://api.saeeol.ai/api/gateway"
|
|
14
|
+
|
|
15
|
+
const Parameters = Schema.Struct({
|
|
16
|
+
query: Schema.String.annotate({
|
|
17
|
+
description: "Search query describing what code you are looking for. Be specific and descriptive for best results.",
|
|
18
|
+
}),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const CodebaseSearchTool = Tool.define(
|
|
22
|
+
"codebase_search",
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
return {
|
|
25
|
+
description: DESCRIPTION,
|
|
26
|
+
parameters: Parameters,
|
|
27
|
+
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
|
|
28
|
+
Effect.gen(function* () {
|
|
29
|
+
yield* ctx.ask({
|
|
30
|
+
permission: "codebase_search",
|
|
31
|
+
patterns: [params.query],
|
|
32
|
+
always: ["*"],
|
|
33
|
+
metadata: { query: params.query },
|
|
34
|
+
})
|
|
35
|
+
Telemetry.trackToolUsed("codebase_search", ctx.sessionID)
|
|
36
|
+
|
|
37
|
+
const apiKey = process.env["MORPH_API_KEY"]
|
|
38
|
+
|
|
39
|
+
// FREE_PERIOD_TODO: Remove proxy fallback — require apiKey, error if missing:
|
|
40
|
+
// if (!apiKey) return { title: ..., output: "Set MORPH_API_KEY to use codebase search.", metadata: {} }
|
|
41
|
+
const client = new WarpGrepClient({
|
|
42
|
+
morphApiKey: apiKey ?? "saeeol-free",
|
|
43
|
+
...(apiKey ? {} : { morphApiUrl: SAEEOL_WARPGREP_PROXY_URL }),
|
|
44
|
+
timeout: 60_000,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const result = yield* Effect.promise(() =>
|
|
48
|
+
client.execute({
|
|
49
|
+
searchTerm: params.query,
|
|
50
|
+
repoRoot: Instance.directory,
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if (!result.success || !result.contexts?.length) {
|
|
55
|
+
// FREE_PERIOD_TODO: When the proxy stops serving free requests, errors
|
|
56
|
+
// from the proxy (401/402/429) will surface here. The message below
|
|
57
|
+
// tells the user exactly what to do.
|
|
58
|
+
const isAuthOrRateLimit =
|
|
59
|
+
result.error && /401|402|429|rate.limit|free.period|unauthorized/i.test(result.error)
|
|
60
|
+
const apiKeyMsg =
|
|
61
|
+
"Codebase search unavailable: free period ended. Set MORPH_API_KEY to continue. Get your key at https://www.morphllm.com/"
|
|
62
|
+
if (isAuthOrRateLimit) {
|
|
63
|
+
yield* Effect.promise(() =>
|
|
64
|
+
Bus.publish(TuiEvent.ToastShow, {
|
|
65
|
+
title: "Codebase Search Unavailable",
|
|
66
|
+
message: "Free period has ended. Set MORPH_API_KEY to continue. Get your key at morphllm.com",
|
|
67
|
+
variant: "error",
|
|
68
|
+
duration: 10000,
|
|
69
|
+
}).catch(() => {}),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
title: `Codebase Search: ${params.query}`,
|
|
74
|
+
output: isAuthOrRateLimit ? apiKeyMsg : (result.error ?? "No relevant code found."),
|
|
75
|
+
metadata: { count: 0 },
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const MAX_OUTPUT_CHARS = 45_000
|
|
80
|
+
const fullOutput = result.contexts.map((c) => `### ${c.file}\n\`\`\`\n${c.content}\n\`\`\``).join("\n\n")
|
|
81
|
+
|
|
82
|
+
let output: string
|
|
83
|
+
if (fullOutput.length > MAX_OUTPUT_CHARS) {
|
|
84
|
+
const summary = result.contexts
|
|
85
|
+
.map((c) => {
|
|
86
|
+
const lineInfo = !c.lines
|
|
87
|
+
? ""
|
|
88
|
+
: c.lines === "*"
|
|
89
|
+
? " (full file)"
|
|
90
|
+
: ` (lines ${c.lines.map((r) => r.join("-")).join(", ")})`
|
|
91
|
+
return `- ${c.file}${lineInfo}`
|
|
92
|
+
})
|
|
93
|
+
.join("\n")
|
|
94
|
+
output = `Results too large to show inline. Showing file paths and line ranges. Use Read tool to view specific files.\n\n${summary}`
|
|
95
|
+
} else {
|
|
96
|
+
output = fullOutput
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
title: `Codebase Search: ${params.query}`,
|
|
101
|
+
output,
|
|
102
|
+
metadata: { count: result.contexts.length },
|
|
103
|
+
}
|
|
104
|
+
}).pipe(Effect.orDie),
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
- Searches the codebase using a natural language search string
|
|
2
|
+
- Takes a natural language search string as input: a question about something you want to understand, or a description of what you're looking for
|
|
3
|
+
- This is not pattern matching or semantic search — it is an AI-powered search agent that performs intelligent multi-step searches across the repository, returning only the most relevant spans
|
|
4
|
+
- Use this when you're looking for a feature or implementation, or trying to understand how something works in a large codebase but are unclear about the exact patterns to search for
|
|
5
|
+
|
|
6
|
+
Usage notes:
|
|
7
|
+
- This does NOT accept regex or keyword dumps — use natural language
|
|
8
|
+
- Best practice is using this at the start of long codebase explorations when you haven't yet mapped out the relevant areas
|
|
9
|
+
- Firing two or three concurrent codebase_search calls at different angles helps go through a large codebase faster
|
|
10
|
+
- This tool is read-only and does not modify any files
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import { HttpClient, HttpClientRequest } from "effect/unstable/http"
|
|
3
|
+
import * as Tool from "../core/tool"
|
|
4
|
+
import TurndownService from "turndown"
|
|
5
|
+
import DESCRIPTION from "./webfetch.txt"
|
|
6
|
+
import { isImageAttachment } from "@/util/media"
|
|
7
|
+
import { normalizeUrls } from "@/saeeol/util/url"
|
|
8
|
+
|
|
9
|
+
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024 // 5MB
|
|
10
|
+
const DEFAULT_TIMEOUT = 30 * 1000 // 30 seconds
|
|
11
|
+
const MAX_TIMEOUT = 120 * 1000 // 2 minutes
|
|
12
|
+
|
|
13
|
+
export const Parameters = Schema.Struct({
|
|
14
|
+
url: Schema.String.annotate({ description: "The URL to fetch content from" }),
|
|
15
|
+
format: Schema.Literals(["text", "markdown", "html"])
|
|
16
|
+
.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed("markdown" as const)))
|
|
17
|
+
.annotate({
|
|
18
|
+
description: "The format to return the content in (text, markdown, or html). Defaults to markdown.",
|
|
19
|
+
}),
|
|
20
|
+
timeout: Schema.optional(Schema.Number).annotate({ description: "Optional timeout in seconds (max 120)" }),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const WebFetchTool = Tool.define(
|
|
24
|
+
"webfetch",
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const http = yield* HttpClient.HttpClient
|
|
27
|
+
const httpOk = HttpClient.filterStatusOk(http)
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
description: DESCRIPTION,
|
|
31
|
+
parameters: Parameters,
|
|
32
|
+
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
if (!params.url.startsWith("http://") && !params.url.startsWith("https://")) {
|
|
35
|
+
throw new Error("URL must start with http:// or https://")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const url = normalizeUrls(params.url)
|
|
39
|
+
|
|
40
|
+
yield* ctx.ask({
|
|
41
|
+
permission: "webfetch",
|
|
42
|
+
patterns: [url],
|
|
43
|
+
always: ["*"],
|
|
44
|
+
metadata: {
|
|
45
|
+
url,
|
|
46
|
+
format: params.format,
|
|
47
|
+
timeout: params.timeout,
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const timeout = Math.min((params.timeout ?? DEFAULT_TIMEOUT / 1000) * 1000, MAX_TIMEOUT)
|
|
52
|
+
|
|
53
|
+
// Build Accept header based on requested format with q parameters for fallbacks
|
|
54
|
+
let acceptHeader = "*/*"
|
|
55
|
+
switch (params.format) {
|
|
56
|
+
case "markdown":
|
|
57
|
+
acceptHeader = "text/markdown;q=1.0, text/x-markdown;q=0.9, text/plain;q=0.8, text/html;q=0.7, */*;q=0.1"
|
|
58
|
+
break
|
|
59
|
+
case "text":
|
|
60
|
+
acceptHeader = "text/plain;q=1.0, text/markdown;q=0.9, text/html;q=0.8, */*;q=0.1"
|
|
61
|
+
break
|
|
62
|
+
case "html":
|
|
63
|
+
acceptHeader =
|
|
64
|
+
"text/html;q=1.0, application/xhtml+xml;q=0.9, text/plain;q=0.8, text/markdown;q=0.7, */*;q=0.1"
|
|
65
|
+
break
|
|
66
|
+
default:
|
|
67
|
+
acceptHeader =
|
|
68
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"
|
|
69
|
+
}
|
|
70
|
+
const headers = {
|
|
71
|
+
"User-Agent":
|
|
72
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
|
73
|
+
Accept: acceptHeader,
|
|
74
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const request = HttpClientRequest.get(url).pipe(HttpClientRequest.setHeaders(headers))
|
|
78
|
+
|
|
79
|
+
// Retry with honest UA if blocked by Cloudflare bot detection (TLS fingerprint mismatch)
|
|
80
|
+
const response = yield* httpOk.execute(request).pipe(
|
|
81
|
+
Effect.catchIf(
|
|
82
|
+
(err) =>
|
|
83
|
+
err.reason._tag === "StatusCodeError" &&
|
|
84
|
+
err.reason.response.status === 403 &&
|
|
85
|
+
err.reason.response.headers["cf-mitigated"] === "challenge",
|
|
86
|
+
() =>
|
|
87
|
+
httpOk.execute(
|
|
88
|
+
HttpClientRequest.get(url).pipe(
|
|
89
|
+
HttpClientRequest.setHeaders({ ...headers, "User-Agent": "saeeol" }),
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
Effect.timeoutOrElse({ duration: timeout, orElse: () => Effect.die(new Error("Request timed out")) }),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
// Check content length
|
|
97
|
+
const contentLength = response.headers["content-length"]
|
|
98
|
+
if (contentLength && parseInt(contentLength) > MAX_RESPONSE_SIZE) {
|
|
99
|
+
throw new Error("Response too large (exceeds 5MB limit)")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const arrayBuffer = yield* response.arrayBuffer
|
|
103
|
+
if (arrayBuffer.byteLength > MAX_RESPONSE_SIZE) {
|
|
104
|
+
throw new Error("Response too large (exceeds 5MB limit)")
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const contentType = response.headers["content-type"] || ""
|
|
108
|
+
const mime = contentType.split(";")[0]?.trim().toLowerCase() || ""
|
|
109
|
+
const title = `${url} (${contentType})`
|
|
110
|
+
|
|
111
|
+
if (isImageAttachment(mime)) {
|
|
112
|
+
const base64Content = Buffer.from(arrayBuffer).toString("base64")
|
|
113
|
+
return {
|
|
114
|
+
title,
|
|
115
|
+
output: "Image fetched successfully",
|
|
116
|
+
metadata: {},
|
|
117
|
+
attachments: [
|
|
118
|
+
{
|
|
119
|
+
type: "file" as const,
|
|
120
|
+
mime,
|
|
121
|
+
url: `data:${mime};base64,${base64Content}`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const content = new TextDecoder().decode(arrayBuffer)
|
|
128
|
+
|
|
129
|
+
// Handle content based on requested format and actual content type
|
|
130
|
+
switch (params.format) {
|
|
131
|
+
case "markdown":
|
|
132
|
+
if (contentType.includes("text/html")) {
|
|
133
|
+
const markdown = convertHTMLToMarkdown(content)
|
|
134
|
+
return {
|
|
135
|
+
output: markdown,
|
|
136
|
+
title,
|
|
137
|
+
metadata: {},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { output: content, title, metadata: {} }
|
|
141
|
+
|
|
142
|
+
case "text":
|
|
143
|
+
if (contentType.includes("text/html")) {
|
|
144
|
+
const text = yield* Effect.promise(() => extractTextFromHTML(content))
|
|
145
|
+
return { output: text, title, metadata: {} }
|
|
146
|
+
}
|
|
147
|
+
return { output: content, title, metadata: {} }
|
|
148
|
+
|
|
149
|
+
case "html":
|
|
150
|
+
return { output: content, title, metadata: {} }
|
|
151
|
+
|
|
152
|
+
default:
|
|
153
|
+
return { output: content, title, metadata: {} }
|
|
154
|
+
}
|
|
155
|
+
}).pipe(Effect.orDie),
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
async function extractTextFromHTML(html: string) {
|
|
161
|
+
let text = ""
|
|
162
|
+
let skipContent = false
|
|
163
|
+
|
|
164
|
+
const rewriter = new HTMLRewriter()
|
|
165
|
+
.on("script, style, noscript, iframe, object, embed", {
|
|
166
|
+
element() {
|
|
167
|
+
skipContent = true
|
|
168
|
+
},
|
|
169
|
+
text() {
|
|
170
|
+
// Skip text content inside these elements
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
.on("*", {
|
|
174
|
+
element(element) {
|
|
175
|
+
// Reset skip flag when entering other elements
|
|
176
|
+
if (!["script", "style", "noscript", "iframe", "object", "embed"].includes(element.tagName)) {
|
|
177
|
+
skipContent = false
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
text(input) {
|
|
181
|
+
if (!skipContent) {
|
|
182
|
+
text += input.text
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
.transform(new Response(html))
|
|
187
|
+
|
|
188
|
+
await rewriter.text()
|
|
189
|
+
return text.trim()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function convertHTMLToMarkdown(html: string): string {
|
|
193
|
+
const turndownService = new TurndownService({
|
|
194
|
+
headingStyle: "atx",
|
|
195
|
+
hr: "---",
|
|
196
|
+
bulletListMarker: "-",
|
|
197
|
+
codeBlockStyle: "fenced",
|
|
198
|
+
emDelimiter: "*",
|
|
199
|
+
})
|
|
200
|
+
turndownService.remove(["script", "style", "meta", "link"])
|
|
201
|
+
return turndownService.turndown(html)
|
|
202
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
- Fetches content from a specified URL
|
|
2
|
+
- Takes a URL and optional format as input
|
|
3
|
+
- Fetches the URL content, converts to requested format (markdown by default)
|
|
4
|
+
- Returns the content in the specified format
|
|
5
|
+
- Use this tool when you need to retrieve and analyze web content
|
|
6
|
+
|
|
7
|
+
Usage notes:
|
|
8
|
+
- IMPORTANT: if another tool is present that offers better web fetching capabilities, is more targeted to the task, or has fewer restrictions, prefer using that tool instead of this one.
|
|
9
|
+
- The URL must be a fully-formed valid URL
|
|
10
|
+
- HTTP URLs will be automatically upgraded to HTTPS
|
|
11
|
+
- Format options: "markdown" (default), "text", or "html"
|
|
12
|
+
- This tool is read-only and does not modify any files
|
|
13
|
+
- Results may be summarized if the content is very large
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import { HttpClient } from "effect/unstable/http"
|
|
3
|
+
import * as Tool from "../core/tool"
|
|
4
|
+
import * as McpExa from "../integration/mcp-exa"
|
|
5
|
+
import DESCRIPTION from "./websearch.txt"
|
|
6
|
+
|
|
7
|
+
export const Parameters = Schema.Struct({
|
|
8
|
+
query: Schema.String.annotate({ description: "Websearch query" }),
|
|
9
|
+
numResults: Schema.optional(Schema.Number).annotate({
|
|
10
|
+
description: "Number of search results to return (default: 8)",
|
|
11
|
+
}),
|
|
12
|
+
livecrawl: Schema.optional(Schema.Literals(["fallback", "preferred"])).annotate({
|
|
13
|
+
description:
|
|
14
|
+
"Live crawl mode - 'fallback': use live crawling as backup if cached content unavailable, 'preferred': prioritize live crawling (default: 'fallback')",
|
|
15
|
+
}),
|
|
16
|
+
type: Schema.optional(Schema.Literals(["auto", "fast", "deep"])).annotate({
|
|
17
|
+
description: "Search type - 'auto': balanced search (default), 'fast': quick results, 'deep': comprehensive search",
|
|
18
|
+
}),
|
|
19
|
+
contextMaxCharacters: Schema.optional(Schema.Number).annotate({
|
|
20
|
+
description: "Maximum characters for context string optimized for LLMs (default: 10000)",
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export const WebSearchTool = Tool.define(
|
|
25
|
+
"websearch",
|
|
26
|
+
Effect.gen(function* () {
|
|
27
|
+
const http = yield* HttpClient.HttpClient
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
get description() {
|
|
31
|
+
return DESCRIPTION.replace("{{year}}", new Date().getFullYear().toString())
|
|
32
|
+
},
|
|
33
|
+
parameters: Parameters,
|
|
34
|
+
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
|
|
35
|
+
Effect.gen(function* () {
|
|
36
|
+
yield* ctx.ask({
|
|
37
|
+
permission: "websearch",
|
|
38
|
+
patterns: [params.query],
|
|
39
|
+
always: ["*"],
|
|
40
|
+
metadata: {
|
|
41
|
+
query: params.query,
|
|
42
|
+
numResults: params.numResults,
|
|
43
|
+
livecrawl: params.livecrawl,
|
|
44
|
+
type: params.type,
|
|
45
|
+
contextMaxCharacters: params.contextMaxCharacters,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const result = yield* McpExa.call(
|
|
50
|
+
http,
|
|
51
|
+
"web_search_exa",
|
|
52
|
+
McpExa.SearchArgs,
|
|
53
|
+
{
|
|
54
|
+
query: params.query,
|
|
55
|
+
type: params.type || "auto",
|
|
56
|
+
numResults: params.numResults || 8,
|
|
57
|
+
livecrawl: params.livecrawl || "fallback",
|
|
58
|
+
contextMaxCharacters: params.contextMaxCharacters,
|
|
59
|
+
},
|
|
60
|
+
"25 seconds",
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
output: result ?? "No search results found. Please try a different query.",
|
|
65
|
+
title: `Web search: ${params.query}`,
|
|
66
|
+
metadata: {},
|
|
67
|
+
}
|
|
68
|
+
}).pipe(Effect.orDie),
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
- Search the web using Exa AI - performs real-time web searches and can scrape content from specific URLs
|
|
2
|
+
- Provides up-to-date information for current events and recent data
|
|
3
|
+
- Supports configurable result counts and returns the content from the most relevant websites
|
|
4
|
+
- Use this tool for accessing information beyond knowledge cutoff
|
|
5
|
+
- Searches are performed automatically within a single API call
|
|
6
|
+
|
|
7
|
+
Usage notes:
|
|
8
|
+
- Supports live crawling modes: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
|
|
9
|
+
- Search types: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
|
|
10
|
+
- Configurable context length for optimal LLM integration
|
|
11
|
+
- Domain filtering and advanced search options available
|
|
12
|
+
|
|
13
|
+
The current year is {{year}}. You MUST use this year when searching for recent information or current events
|
|
14
|
+
- Example: If the current year is 2026 and the user asks for "latest AI news", search for "AI news 2026", NOT "AI news 2025"
|
package/src/tool/skill.ts
CHANGED
|
@@ -1,91 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { pathToFileURL } from "url"
|
|
3
|
-
import { Effect, Schema } from "effect"
|
|
4
|
-
import * as Stream from "effect/Stream"
|
|
5
|
-
import { Ripgrep } from "../file/ripgrep"
|
|
6
|
-
import { Skill } from "../skill"
|
|
7
|
-
import * as Tool from "./tool"
|
|
8
|
-
import DESCRIPTION from "./skill.txt"
|
|
9
|
-
|
|
10
|
-
export const Parameters = Schema.Struct({
|
|
11
|
-
name: Schema.String.annotate({ description: "The name of the skill from available_skills" }),
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export const SkillTool = Tool.define(
|
|
15
|
-
"skill",
|
|
16
|
-
Effect.gen(function* () {
|
|
17
|
-
const skill = yield* Skill.Service
|
|
18
|
-
const rg = yield* Ripgrep.Service
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
description: DESCRIPTION,
|
|
22
|
-
parameters: Parameters,
|
|
23
|
-
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
|
|
24
|
-
Effect.gen(function* () {
|
|
25
|
-
const info = yield* skill.get(params.name)
|
|
26
|
-
if (!info) {
|
|
27
|
-
const all = yield* skill.all()
|
|
28
|
-
const available = all.map((item) => item.name).join(", ")
|
|
29
|
-
throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
yield* ctx.ask({
|
|
33
|
-
permission: "skill",
|
|
34
|
-
patterns: [params.name],
|
|
35
|
-
always: [params.name],
|
|
36
|
-
metadata: {},
|
|
37
|
-
})
|
|
38
|
-
if (info.location === Skill.BUILTIN_LOCATION) {
|
|
39
|
-
return {
|
|
40
|
-
title: `Loaded skill: ${info.name}`,
|
|
41
|
-
output: [
|
|
42
|
-
`<skill_content name="${info.name}">`,
|
|
43
|
-
`# Skill: ${info.name}`,
|
|
44
|
-
"",
|
|
45
|
-
info.content.trim(),
|
|
46
|
-
"</skill_content>",
|
|
47
|
-
].join("\n"),
|
|
48
|
-
metadata: {
|
|
49
|
-
name: info.name,
|
|
50
|
-
dir: Skill.BUILTIN_LOCATION,
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const dir = path.dirname(info.location)
|
|
56
|
-
const base = pathToFileURL(dir).href
|
|
57
|
-
const limit = 10
|
|
58
|
-
const files = yield* rg.files({ cwd: dir, follow: false, hidden: true, signal: ctx.abort }).pipe(
|
|
59
|
-
Stream.filter((file) => !file.includes("SKILL.md")),
|
|
60
|
-
Stream.map((file) => path.resolve(dir, file)),
|
|
61
|
-
Stream.take(limit),
|
|
62
|
-
Stream.runCollect,
|
|
63
|
-
Effect.map((chunk) => [...chunk].map((file) => `<file>${file}</file>`).join("\n")),
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
title: `Loaded skill: ${info.name}`,
|
|
68
|
-
output: [
|
|
69
|
-
`<skill_content name="${info.name}">`,
|
|
70
|
-
`# Skill: ${info.name}`,
|
|
71
|
-
"",
|
|
72
|
-
info.content.trim(),
|
|
73
|
-
"",
|
|
74
|
-
`Base directory for this skill: ${base}`,
|
|
75
|
-
"Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
|
|
76
|
-
"Note: file list is sampled.",
|
|
77
|
-
"",
|
|
78
|
-
"<skill_files>",
|
|
79
|
-
files,
|
|
80
|
-
"</skill_files>",
|
|
81
|
-
"</skill_content>",
|
|
82
|
-
].join("\n"),
|
|
83
|
-
metadata: {
|
|
84
|
-
name: info.name,
|
|
85
|
-
dir,
|
|
86
|
-
},
|
|
87
|
-
}
|
|
88
|
-
}).pipe(Effect.orDie),
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
)
|
|
1
|
+
export * from "./workflow/skill"
|