atom-lite 0.0.0-stage → 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/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +265 -2
- package/dist/agent/loop.d.ts +30 -0
- package/dist/agent/loop.js +199 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/types.d.ts +85 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli/app.d.ts +1 -0
- package/dist/cli/app.js +1060 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/approvals.d.ts +1 -0
- package/dist/cli/approvals.js +2 -0
- package/dist/cli/approvals.js.map +1 -0
- package/dist/cli/banner.d.ts +8 -0
- package/dist/cli/banner.js +29 -0
- package/dist/cli/banner.js.map +1 -0
- package/dist/cli/commands.d.ts +19 -0
- package/dist/cli/commands.js +61 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +22 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/picker.d.ts +26 -0
- package/dist/cli/picker.js +175 -0
- package/dist/cli/picker.js.map +1 -0
- package/dist/cli/renderer.d.ts +1 -0
- package/dist/cli/renderer.js +5 -0
- package/dist/cli/renderer.js.map +1 -0
- package/dist/cli/secret-input.d.ts +21 -0
- package/dist/cli/secret-input.js +101 -0
- package/dist/cli/secret-input.js.map +1 -0
- package/dist/cli/status-line.d.ts +18 -0
- package/dist/cli/status-line.js +35 -0
- package/dist/cli/status-line.js.map +1 -0
- package/dist/cli/stream-text.d.ts +22 -0
- package/dist/cli/stream-text.js +50 -0
- package/dist/cli/stream-text.js.map +1 -0
- package/dist/cli/transcript.d.ts +17 -0
- package/dist/cli/transcript.js +40 -0
- package/dist/cli/transcript.js.map +1 -0
- package/dist/config/credentials.d.ts +26 -0
- package/dist/config/credentials.js +79 -0
- package/dist/config/credentials.js.map +1 -0
- package/dist/config/defaults.d.ts +24 -0
- package/dist/config/defaults.js +25 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/load.d.ts +7 -0
- package/dist/config/load.js +105 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/paths.d.ts +4 -0
- package/dist/config/paths.js +14 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/schema.d.ts +83 -0
- package/dist/config/schema.js +52 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/write.d.ts +18 -0
- package/dist/config/write.js +61 -0
- package/dist/config/write.js.map +1 -0
- package/dist/context/budget.d.ts +2 -0
- package/dist/context/budget.js +13 -0
- package/dist/context/budget.js.map +1 -0
- package/dist/context/compaction.d.ts +1 -0
- package/dist/context/compaction.js +5 -0
- package/dist/context/compaction.js.map +1 -0
- package/dist/context/instructions.d.ts +3 -0
- package/dist/context/instructions.js +30 -0
- package/dist/context/instructions.js.map +1 -0
- package/dist/context/manager.d.ts +29 -0
- package/dist/context/manager.js +122 -0
- package/dist/context/manager.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/catalog.d.ts +60 -0
- package/dist/providers/catalog.js +289 -0
- package/dist/providers/catalog.js.map +1 -0
- package/dist/providers/context-window.d.ts +11 -0
- package/dist/providers/context-window.js +87 -0
- package/dist/providers/context-window.js.map +1 -0
- package/dist/providers/factory.d.ts +2 -0
- package/dist/providers/factory.js +54 -0
- package/dist/providers/factory.js.map +1 -0
- package/dist/providers/fake.d.ts +14 -0
- package/dist/providers/fake.js +23 -0
- package/dist/providers/fake.js.map +1 -0
- package/dist/providers/gemini.d.ts +24 -0
- package/dist/providers/gemini.js +228 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/ollama.d.ts +64 -0
- package/dist/providers/ollama.js +433 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +27 -0
- package/dist/providers/openai-compatible.js +282 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/registry.d.ts +7 -0
- package/dist/providers/registry.js +13 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/tool-calls.d.ts +18 -0
- package/dist/providers/tool-calls.js +42 -0
- package/dist/providers/tool-calls.js.map +1 -0
- package/dist/providers/types.d.ts +16 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/runtime/approvals.d.ts +20 -0
- package/dist/runtime/approvals.js +20 -0
- package/dist/runtime/approvals.js.map +1 -0
- package/dist/runtime/locks.d.ts +13 -0
- package/dist/runtime/locks.js +180 -0
- package/dist/runtime/locks.js.map +1 -0
- package/dist/runtime/scheduler.d.ts +7 -0
- package/dist/runtime/scheduler.js +103 -0
- package/dist/runtime/scheduler.js.map +1 -0
- package/dist/security/paths.d.ts +1 -0
- package/dist/security/paths.js +35 -0
- package/dist/security/paths.js.map +1 -0
- package/dist/security/process.d.ts +1 -0
- package/dist/security/process.js +8 -0
- package/dist/security/process.js.map +1 -0
- package/dist/security/redaction.d.ts +1 -0
- package/dist/security/redaction.js +4 -0
- package/dist/security/redaction.js.map +1 -0
- package/dist/sessions/events.d.ts +21 -0
- package/dist/sessions/events.js +87 -0
- package/dist/sessions/events.js.map +1 -0
- package/dist/sessions/index.d.ts +3 -0
- package/dist/sessions/index.js +4 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/recovery.d.ts +6 -0
- package/dist/sessions/recovery.js +35 -0
- package/dist/sessions/recovery.js.map +1 -0
- package/dist/sessions/store.d.ts +91 -0
- package/dist/sessions/store.js +356 -0
- package/dist/sessions/store.js.map +1 -0
- package/dist/skills/registry.d.ts +23 -0
- package/dist/skills/registry.js +129 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +159 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/diff.d.ts +7 -0
- package/dist/tools/diff.js +40 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +117 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +138 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/registry.d.ts +7 -0
- package/dist/tools/registry.js +13 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +27 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/webfetch.d.ts +2 -0
- package/dist/tools/webfetch.js +97 -0
- package/dist/tools/webfetch.js.map +1 -0
- package/dist/tools/websearch.d.ts +2 -0
- package/dist/tools/websearch.js +88 -0
- package/dist/tools/websearch.js.map +1 -0
- package/dist/tools/write.d.ts +2 -0
- package/dist/tools/write.js +91 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +74 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ArgsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
url: z.string(),
|
|
5
|
+
format: z.enum(["text", "markdown", "html"]).optional(),
|
|
6
|
+
timeout: z.number().int().positive().optional(),
|
|
7
|
+
})
|
|
8
|
+
.strict();
|
|
9
|
+
const MAX_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
11
|
+
const MAX_TIMEOUT = 120000;
|
|
12
|
+
export const webfetchTool = {
|
|
13
|
+
definition: {
|
|
14
|
+
name: "webfetch",
|
|
15
|
+
description: "Fetch content from an HTTP or HTTPS URL and return it as text, markdown, or HTML.",
|
|
16
|
+
parameters: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
url: { type: "string" },
|
|
20
|
+
format: { type: "string", enum: ["text", "markdown", "html"] },
|
|
21
|
+
timeout: { type: "integer", minimum: 1 },
|
|
22
|
+
},
|
|
23
|
+
required: ["url"],
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
async execute(call, ctx) {
|
|
28
|
+
const parsed = ArgsSchema.safeParse(call.arguments);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
return { toolCallId: call.id, name: "webfetch", content: "TOOL_ARGUMENT_INVALID: " + parsed.error.message, isError: true };
|
|
31
|
+
}
|
|
32
|
+
const { url, format = "markdown", timeout } = parsed.data;
|
|
33
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
34
|
+
return { toolCallId: call.id, name: "webfetch", content: "TOOL_ARGUMENT_INVALID: URL must start with http:// or https://", isError: true };
|
|
35
|
+
}
|
|
36
|
+
const timeoutMs = Math.min((timeout ?? 30) * 1000, MAX_TIMEOUT);
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
39
|
+
const headers = { "User-Agent": "atom-lite/0.1" };
|
|
40
|
+
let res;
|
|
41
|
+
try {
|
|
42
|
+
res = await fetch(url, { headers, signal: controller.signal });
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
return { toolCallId: call.id, name: "webfetch", content: `PROVIDER_CONNECTION_FAILED: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
47
|
+
}
|
|
48
|
+
// Cloudflare challenge retry
|
|
49
|
+
if (res.status === 403) {
|
|
50
|
+
try {
|
|
51
|
+
res = await fetch(url, { headers: { ...headers, "User-Agent": "atom-lite/0.1 (compatible)" }, signal: controller.signal });
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// ignore
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
return { toolCallId: call.id, name: "webfetch", content: `PROVIDER_INVALID_RESPONSE: ${res.status}`, isError: true };
|
|
60
|
+
}
|
|
61
|
+
const buf = await res.arrayBuffer();
|
|
62
|
+
if (buf.byteLength > MAX_BYTES) {
|
|
63
|
+
return { toolCallId: call.id, name: "webfetch", content: "OUTPUT_TRUNCATED: response too large", isError: true };
|
|
64
|
+
}
|
|
65
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
66
|
+
const raw = new TextDecoder().decode(buf);
|
|
67
|
+
let output = raw;
|
|
68
|
+
const isHtml = contentType.includes("text/html") || raw.trim().startsWith("<");
|
|
69
|
+
if (format === "markdown" && isHtml) {
|
|
70
|
+
try {
|
|
71
|
+
const TurndownService = (await import("turndown")).default;
|
|
72
|
+
const td = new TurndownService({ headingStyle: "atx", codeBlockStyle: "fenced" });
|
|
73
|
+
td.remove(["script", "style", "meta", "link", "noscript"]);
|
|
74
|
+
output = td.turndown(raw);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
output = stripHtml(raw);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (format === "text" && isHtml) {
|
|
81
|
+
output = stripHtml(raw);
|
|
82
|
+
}
|
|
83
|
+
// cap output
|
|
84
|
+
if (output.length > 30000)
|
|
85
|
+
output = output.slice(0, 30000) + "\nOUTPUT_TRUNCATED";
|
|
86
|
+
return { toolCallId: call.id, name: "webfetch", content: output };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
function stripHtml(html) {
|
|
90
|
+
return html
|
|
91
|
+
.replace(/<script[\s\S]*?<\/script>/gi, "")
|
|
92
|
+
.replace(/<style[\s\S]*?<\/style>/gi, "")
|
|
93
|
+
.replace(/<[^>]+>/g, " ")
|
|
94
|
+
.replace(/\s+/g, " ")
|
|
95
|
+
.trim();
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=webfetch.js.map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,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ArgsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
query: z.string(),
|
|
5
|
+
num_results: z.number().int().positive().optional(),
|
|
6
|
+
})
|
|
7
|
+
.strict();
|
|
8
|
+
export const websearchTool = {
|
|
9
|
+
definition: {
|
|
10
|
+
name: "websearch",
|
|
11
|
+
description: "Search the web for a query and return titles, URLs, and snippets.",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
query: { type: "string" },
|
|
16
|
+
num_results: { type: "integer", minimum: 1 },
|
|
17
|
+
},
|
|
18
|
+
required: ["query"],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
async execute(call, ctx) {
|
|
23
|
+
const parsed = ArgsSchema.safeParse(call.arguments);
|
|
24
|
+
if (!parsed.success) {
|
|
25
|
+
return { toolCallId: call.id, name: "websearch", content: "TOOL_ARGUMENT_INVALID: " + parsed.error.message, isError: true };
|
|
26
|
+
}
|
|
27
|
+
const { query, num_results = 8 } = parsed.data;
|
|
28
|
+
const limit = Math.min(num_results, 20);
|
|
29
|
+
const url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => controller.abort(), 30000);
|
|
32
|
+
let res;
|
|
33
|
+
try {
|
|
34
|
+
res = await fetch(url, {
|
|
35
|
+
headers: { "User-Agent": "atom-lite/0.1" },
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
return { toolCallId: call.id, name: "websearch", content: `PROVIDER_CONNECTION_FAILED: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
42
|
+
}
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
return { toolCallId: call.id, name: "websearch", content: `PROVIDER_INVALID_RESPONSE: ${res.status}`, isError: true };
|
|
46
|
+
}
|
|
47
|
+
const html = await res.text();
|
|
48
|
+
// Parse result blocks
|
|
49
|
+
const results = [];
|
|
50
|
+
const resultBlockRegex = /<a[^>]*class="result__a"[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
51
|
+
const snippetRegex = /<a[^>]*class="result__snippet"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
52
|
+
const titles = [];
|
|
53
|
+
let m;
|
|
54
|
+
while ((m = resultBlockRegex.exec(html)) !== null) {
|
|
55
|
+
const rawUrl = m[1];
|
|
56
|
+
const title = stripTags(m[2]).trim();
|
|
57
|
+
// DuckDuckGo wraps URLs in a redirect; extract uddg param
|
|
58
|
+
let finalUrl = rawUrl;
|
|
59
|
+
const uddg = rawUrl.match(/uddg=([^&]+)/);
|
|
60
|
+
if (uddg)
|
|
61
|
+
finalUrl = decodeURIComponent(uddg[1]);
|
|
62
|
+
titles.push({ url: finalUrl, title });
|
|
63
|
+
}
|
|
64
|
+
const snippets = [];
|
|
65
|
+
while ((m = snippetRegex.exec(html)) !== null) {
|
|
66
|
+
snippets.push(stripTags(m[1]).trim());
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < Math.min(titles.length, limit); i++) {
|
|
69
|
+
results.push({
|
|
70
|
+
title: titles[i].title,
|
|
71
|
+
url: titles[i].url,
|
|
72
|
+
snippet: snippets[i] ?? "",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (results.length === 0) {
|
|
76
|
+
return { toolCallId: call.id, name: "websearch", content: "No results found." };
|
|
77
|
+
}
|
|
78
|
+
const lines = results.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}\n ${r.snippet}`);
|
|
79
|
+
let output = `Search: ${query}\n\n${lines.join("\n\n")}`;
|
|
80
|
+
if (output.length > 30000)
|
|
81
|
+
output = output.slice(0, 30000) + "\nOUTPUT_TRUNCATED";
|
|
82
|
+
return { toolCallId: call.id, name: "websearch", content: output };
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
function stripTags(s) {
|
|
86
|
+
return s.replace(/<[^>]+>/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/\s+/g, " ");
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=websearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websearch.js","sourceRoot":"","sources":["../../src/tools/websearch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,UAAU,GAAG,CAAC;KACjB,MAAM,CAAC;IACN,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACpD,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,MAAM,aAAa,GAAS;IACjC,UAAU,EAAE;QACV,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,mEAAmE;QAChF,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACzB,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;aAC7C;YACD,QAAQ,EAAE,CAAC,OAAO,CAAC;YACnB,oBAAoB,EAAE,KAAK;SAC5B;KACF;IACD,KAAK,CAAC,OAAO,CAAC,IAAc,EAAE,GAAgB;QAC5C,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,CA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G,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC1K,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, } from "node:fs";
|
|
2
|
+
import { resolve, dirname } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { isWithinWorkspace } from "../security/paths.js";
|
|
5
|
+
import { renderAddedLines, renderDiff } from "./diff.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
const ArgsSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
path: z.string(),
|
|
10
|
+
content: z.string(),
|
|
11
|
+
expected_hash: z.string().optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
function sha256(buf) {
|
|
15
|
+
return createHash("sha256").update(buf).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
export const writeTool = {
|
|
18
|
+
definition: {
|
|
19
|
+
name: "write",
|
|
20
|
+
description: "Create a new file or replace the full contents of a file.",
|
|
21
|
+
parameters: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
path: { type: "string" },
|
|
25
|
+
content: { type: "string" },
|
|
26
|
+
expected_hash: { type: "string" },
|
|
27
|
+
},
|
|
28
|
+
required: ["path", "content"],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
async execute(call, ctx) {
|
|
33
|
+
const parsed = ArgsSchema.safeParse(call.arguments);
|
|
34
|
+
if (!parsed.success) {
|
|
35
|
+
return {
|
|
36
|
+
toolCallId: call.id,
|
|
37
|
+
name: "write",
|
|
38
|
+
content: "TOOL_ARGUMENT_INVALID: " + parsed.error.message,
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const { path, content, expected_hash } = parsed.data;
|
|
43
|
+
if (!isWithinWorkspace(ctx.workspace, path)) {
|
|
44
|
+
return {
|
|
45
|
+
toolCallId: call.id,
|
|
46
|
+
name: "write",
|
|
47
|
+
content: "PATH_OUTSIDE_WORKSPACE",
|
|
48
|
+
isError: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const full = resolve(ctx.workspace, path);
|
|
52
|
+
const existed = existsSync(full);
|
|
53
|
+
let oldText;
|
|
54
|
+
if (existed) {
|
|
55
|
+
const buf = readFileSync(full);
|
|
56
|
+
oldText = buf.toString("utf8");
|
|
57
|
+
const currentHash = sha256(buf);
|
|
58
|
+
if (expected_hash && expected_hash !== currentHash) {
|
|
59
|
+
return {
|
|
60
|
+
toolCallId: call.id,
|
|
61
|
+
name: "write",
|
|
62
|
+
content: "FILE_CHANGED_SINCE_READ",
|
|
63
|
+
isError: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!expected_hash) {
|
|
67
|
+
return {
|
|
68
|
+
toolCallId: call.id,
|
|
69
|
+
name: "write",
|
|
70
|
+
content: "TOOL_ARGUMENT_INVALID: expected_hash required when replacing an existing file",
|
|
71
|
+
isError: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// create parent dirs
|
|
76
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
77
|
+
const buf = Buffer.from(content, "utf8");
|
|
78
|
+
// atomic write
|
|
79
|
+
const tmp = full + ".tmp-" + process.pid;
|
|
80
|
+
writeFileSync(tmp, buf);
|
|
81
|
+
renameSync(tmp, full);
|
|
82
|
+
const newHash = sha256(buf);
|
|
83
|
+
return {
|
|
84
|
+
toolCallId: call.id,
|
|
85
|
+
name: "write",
|
|
86
|
+
content: `Wrote ${buf.length} bytes to ${path} (sha256:${newHash}).`,
|
|
87
|
+
diff: oldText === undefined ? renderAddedLines(content) : renderDiff(oldText, content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IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,yBAAyB;oBAClC,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO;oBACL,UAAU,EAAE,IAAI,CAAC,EAAE;oBACnB,IAAI,EAAE,OAAO;oBACb,OAAO,EACL,+EAA+E;oBACjF,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;QACD,qBAAqB;QACrB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzC,eAAe;QACf,MAAM,GAAG,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;QACzC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACxB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,EAAE;YACnB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,SAAS,GAAG,CAAC,MAAM,aAAa,IAAI,YAAY,OAAO,IAAI;YACpE,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;SACvF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export type ContentPart = {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
};
|
|
5
|
+
export type Message = {
|
|
6
|
+
role: "system";
|
|
7
|
+
content: string;
|
|
8
|
+
} | {
|
|
9
|
+
role: "user";
|
|
10
|
+
content: ContentPart[];
|
|
11
|
+
} | {
|
|
12
|
+
role: "assistant";
|
|
13
|
+
content?: ContentPart[];
|
|
14
|
+
toolCalls?: ToolCall[];
|
|
15
|
+
providerState?: unknown;
|
|
16
|
+
} | {
|
|
17
|
+
role: "tool";
|
|
18
|
+
toolCallId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
content: string;
|
|
21
|
+
};
|
|
22
|
+
export interface ToolCall {
|
|
23
|
+
id: string;
|
|
24
|
+
name: "read" | "write" | "edit" | "bash" | "webfetch" | "websearch" | "grep" | "glob";
|
|
25
|
+
arguments: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface ToolDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
parameters: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
export interface ModelInfo {
|
|
33
|
+
id: string;
|
|
34
|
+
contextWindow?: number;
|
|
35
|
+
supportsTools?: boolean;
|
|
36
|
+
supportsStreaming?: boolean;
|
|
37
|
+
supportsVision?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface TokenUsage {
|
|
40
|
+
input?: number;
|
|
41
|
+
output?: number;
|
|
42
|
+
total?: number;
|
|
43
|
+
}
|
|
44
|
+
export type FinishReason = "stop" | "tool_calls" | "length" | "error" | "cancelled";
|
|
45
|
+
export interface ModelRequest {
|
|
46
|
+
model: string;
|
|
47
|
+
messages: Message[];
|
|
48
|
+
tools?: ToolDefinition[];
|
|
49
|
+
options?: Record<string, unknown>;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}
|
|
52
|
+
export interface ModelResponse {
|
|
53
|
+
message: Message & {
|
|
54
|
+
role: "assistant";
|
|
55
|
+
};
|
|
56
|
+
toolCalls: ToolCall[];
|
|
57
|
+
finishReason: FinishReason;
|
|
58
|
+
usage?: TokenUsage;
|
|
59
|
+
providerState?: unknown;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
export type ModelStreamEvent = {
|
|
63
|
+
type: "text";
|
|
64
|
+
text: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "thinking";
|
|
67
|
+
text: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "tool_call";
|
|
70
|
+
toolCall: ToolCall;
|
|
71
|
+
} | {
|
|
72
|
+
type: "done";
|
|
73
|
+
response: ModelResponse;
|
|
74
|
+
};
|
|
75
|
+
export interface AgentLimits {
|
|
76
|
+
maxIterations: number;
|
|
77
|
+
maxToolCalls: number;
|
|
78
|
+
maxExecutionMs: number;
|
|
79
|
+
maxParallelToolCalls: number;
|
|
80
|
+
maxToolOutputBytes: number;
|
|
81
|
+
maxBashTimeMs: number;
|
|
82
|
+
}
|
|
83
|
+
export declare const DEFAULT_LIMITS: AgentLimits;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Canonical types shared across the runtime. Provider- and transport-agnostic.
|
|
2
|
+
export const DEFAULT_LIMITS = {
|
|
3
|
+
maxIterations: 40,
|
|
4
|
+
maxToolCalls: 100,
|
|
5
|
+
maxExecutionMs: 1_800_000,
|
|
6
|
+
maxParallelToolCalls: 4,
|
|
7
|
+
maxToolOutputBytes: 30_000,
|
|
8
|
+
maxBashTimeMs: 120_000,
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAiF/E,MAAM,CAAC,MAAM,cAAc,GAAgB;IACzC,aAAa,EAAE,EAAE;IACjB,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,SAAS;IACzB,oBAAoB,EAAE,CAAC;IACvB,kBAAkB,EAAE,MAAM;IAC1B,aAAa,EAAE,OAAO;CACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom-lite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first, model-agnostic coding agent for the terminal",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"agent",
|
|
8
|
+
"coding-agent",
|
|
9
|
+
"cli",
|
|
10
|
+
"tui",
|
|
11
|
+
"llm",
|
|
12
|
+
"local-first",
|
|
13
|
+
"ollama",
|
|
14
|
+
"openai",
|
|
15
|
+
"gemini"
|
|
16
|
+
],
|
|
17
|
+
"author": "Atom-lite contributors",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/beast-ofcourse/atom-lite.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/beast-ofcourse/atom-lite#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/beast-ofcourse/atom-lite/issues"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"bin": {
|
|
29
|
+
"atom-lite": "./dist/cli/main.js"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
50
|
+
"build": "tsc -p tsconfig.json",
|
|
51
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
52
|
+
"lint": "tsc --noEmit -p tsconfig.json",
|
|
53
|
+
"test": "npm run build && node --test",
|
|
54
|
+
"bench": "npm run build && node scripts/bench.mjs",
|
|
55
|
+
"start": "npm run build && node dist/cli/main.js",
|
|
56
|
+
"dev": "tsx src/cli/main.ts",
|
|
57
|
+
"format": "prettier --write .",
|
|
58
|
+
"format:check": "prettier --check .",
|
|
59
|
+
"prepack": "npm run build",
|
|
60
|
+
"prepublishOnly": "npm run typecheck && npm test"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22.19"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@earendil-works/pi-tui": "^1.5.0",
|
|
67
|
+
"turndown": "^7.2.4",
|
|
68
|
+
"zod": "^4.6.7"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/node": "^20.0.0",
|
|
72
|
+
"prettier": "^3.3.0",
|
|
73
|
+
"tsx": "^4.19.0",
|
|
74
|
+
"typescript": "^5.6.0"
|
|
75
|
+
}
|
|
76
|
+
}
|