@jiangyuan1209/yuan-claw 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +28 -0
- package/README.md +441 -0
- package/dist/agent/build-system-prompt.js +46 -0
- package/dist/agent/message-types.js +1 -0
- package/dist/agent/message-utils.js +239 -0
- package/dist/agent/parse-agent-response.js +48 -0
- package/dist/agent/prompts.js +27 -0
- package/dist/agent/protocol.js +1 -0
- package/dist/agent/read-approval.js +45 -0
- package/dist/agent/read-confirmation.js +17 -0
- package/dist/agent/run-local-agent-loop.js +272 -0
- package/dist/cli/help.js +24 -0
- package/dist/cli/main.js +108 -0
- package/dist/cli/parse-args.js +75 -0
- package/dist/cli/repl.js +188 -0
- package/dist/config/config-path.js +9 -0
- package/dist/config/init-user-config.js +39 -0
- package/dist/config/load-config.js +46 -0
- package/dist/config.js +29 -0
- package/dist/events/event-bus.js +62 -0
- package/dist/lib/initGlobalProxy.js +52 -0
- package/dist/memory/session-store.js +43 -0
- package/dist/memory/types.js +1 -0
- package/dist/model/client.js +7 -0
- package/dist/model/providers/openai-compatible.js +42 -0
- package/dist/scripts/test-brave.js +16 -0
- package/dist/security/network-policy.js +19 -0
- package/dist/security/path-guards.js +18 -0
- package/dist/security/shell-policy.js +40 -0
- package/dist/shared/utils.js +1 -0
- package/dist/tools/file/grep-text.js +85 -0
- package/dist/tools/file/list-files.js +52 -0
- package/dist/tools/file/read-file.js +39 -0
- package/dist/tools/file/write-file.js +37 -0
- package/dist/tools/git/git-diff.js +54 -0
- package/dist/tools/git/git-status.js +44 -0
- package/dist/tools/registry.js +41 -0
- package/dist/tools/shell/shell-exec.js +41 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/web/extract-readable-text.js +54 -0
- package/dist/tools/web/http-fetch.js +55 -0
- package/dist/tools/web/index.js +4 -0
- package/dist/tools/web/search-providers/brave.js +31 -0
- package/dist/tools/web/web-search.js +33 -0
- package/package.json +26 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function createBraveSearchProvider(options) {
|
|
2
|
+
const baseUrl = options.baseUrl ?? "https://api.search.brave.com/res/v1/web/search";
|
|
3
|
+
return async function braveSearch(query, count) {
|
|
4
|
+
const url = new URL(baseUrl);
|
|
5
|
+
url.searchParams.set("q", query);
|
|
6
|
+
url.searchParams.set("count", String(count));
|
|
7
|
+
const response = await fetch(url.toString(), {
|
|
8
|
+
method: "GET",
|
|
9
|
+
headers: {
|
|
10
|
+
Accept: "application/json",
|
|
11
|
+
"X-Subscription-Token": options.apiKey,
|
|
12
|
+
"User-Agent": "Mozilla/5.0 (compatible; XSimpleWebSearch/1.0)",
|
|
13
|
+
...options.headers,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
const errorText = await response.text().catch(() => "");
|
|
18
|
+
throw new Error(`Brave search failed: ${response.status} ${response.statusText}${errorText ? ` - ${errorText}` : ""}`);
|
|
19
|
+
}
|
|
20
|
+
const data = (await response.json());
|
|
21
|
+
return (data.web?.results ?? [])
|
|
22
|
+
.slice(0, count)
|
|
23
|
+
.map((item) => ({
|
|
24
|
+
title: item.title ?? "",
|
|
25
|
+
url: item.url ?? "",
|
|
26
|
+
snippet: item.description ?? "",
|
|
27
|
+
source: "brave",
|
|
28
|
+
}))
|
|
29
|
+
.filter((item) => item.url.trim().length > 0);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const WebSearchInputSchema = z.object({
|
|
3
|
+
query: z.string().min(1),
|
|
4
|
+
count: z.number().int().min(1).max(10).default(5),
|
|
5
|
+
});
|
|
6
|
+
export function createWebSearchTool(options) {
|
|
7
|
+
return {
|
|
8
|
+
name: "web_search",
|
|
9
|
+
description: "Search the web and return relevant results with title, url, and snippet",
|
|
10
|
+
riskLevel: "safe",
|
|
11
|
+
inputSchema: WebSearchInputSchema,
|
|
12
|
+
async execute(rawArgs) {
|
|
13
|
+
try {
|
|
14
|
+
const args = WebSearchInputSchema.parse(rawArgs);
|
|
15
|
+
const results = await options.provider(args.query, args.count);
|
|
16
|
+
return {
|
|
17
|
+
success: true,
|
|
18
|
+
output: {
|
|
19
|
+
query: args.query,
|
|
20
|
+
count: args.count,
|
|
21
|
+
results,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: error instanceof Error ? error.message : String(error),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jiangyuan1209/yuan-claw",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A local CLI agent with tools, search, and interactive approval.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"yuan-claw": "dist/cli/main.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
".env.example"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsx src/cli/main.ts",
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"start": "node dist/cli/main.js",
|
|
19
|
+
"check": "tsc --noEmit",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
}
|
|
26
|
+
}
|