mythos-code 1.0.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.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/bin/mythos.js +94 -0
  3. package/package.json +25 -0
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Mythos Code
2
+
3
+ KI-Coding-Agent im Terminal – by Mythoscraft.
4
+
5
+ ```
6
+ npm install -g mythos-code
7
+ mythos login
8
+ mythos
9
+ ```
package/bin/mythos.js ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ // Mythos Code CLI – Agent mit Zugriff auf Dateien & Shell (mit Bestätigung)
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import os from "node:os";
6
+ import readline from "node:readline";
7
+ import { execSync } from "node:child_process";
8
+
9
+ const API = process.env.MYTHOS_API_URL || "https://rdxaqiacoitzeowehdts.supabase.co/functions/v1/v1-messages";
10
+ const CFG = path.join(os.homedir(), ".mythos-code.json");
11
+ const C = { c: "\x1b[36m", g: "\x1b[32m", y: "\x1b[33m", r: "\x1b[31m", d: "\x1b[2m", b: "\x1b[1m", x: "\x1b[0m" };
12
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
13
+ const ask = (q) => new Promise((r) => rl.question(q, r));
14
+ const load = () => { try { return JSON.parse(fs.readFileSync(CFG, "utf8")); } catch { return {}; } };
15
+ const save = (c) => fs.writeFileSync(CFG, JSON.stringify(c, null, 2));
16
+ let cfg = load();
17
+ let autoYes = process.argv.includes("--yes");
18
+
19
+ const SYSTEM = `Du bist Mythos Code, ein autonomer Coding-Agent im Terminal des Nutzers (OS: ${process.platform}, CWD: ${process.cwd()}).
20
+ Du kannst Werkzeuge nutzen. Um ein Werkzeug aufzurufen, antworte mit GENAU EINEM Block:
21
+ <tool>{"name":"run","cmd":"..."}</tool> -> Shell-Befehl ausführen
22
+ <tool>{"name":"read","path":"..."}</tool> -> Datei lesen
23
+ <tool>{"name":"write","path":"...","content":"..."}</tool> -> Datei schreiben/erstellen
24
+ <tool>{"name":"ls","path":"."}</tool> -> Ordner auflisten
25
+ Nach jedem Werkzeug bekommst du das Ergebnis. Arbeite Schritt für Schritt, bis die Aufgabe erledigt ist, dann antworte normal ohne <tool>. Sei präzise.`;
26
+
27
+ async function login() {
28
+ console.log(C.c + "Hol dir einen kostenlosen API-Key im Mythos Dashboard (sk-ant-mythos-...)." + C.x);
29
+ const k = (await ask("API-Key: ")).trim();
30
+ if (!k.startsWith("sk-ant-mythos-")) { console.log(C.r + "Ungültiger Key." + C.x); process.exit(1); }
31
+ cfg.key = k; save(cfg); console.log(C.g + "✓ Gespeichert in " + CFG + C.x);
32
+ }
33
+
34
+ async function call(messages) {
35
+ const r = await fetch(API, {
36
+ method: "POST",
37
+ headers: { "content-type": "application/json", "x-api-key": cfg.key, "anthropic-version": "2023-06-01" },
38
+ body: JSON.stringify({ model: cfg.model || "mythos-code", max_tokens: 8000, system: SYSTEM, messages }),
39
+ });
40
+ const j = await r.json().catch(() => ({}));
41
+ if (!r.ok) throw new Error(j?.error?.message || ("HTTP " + r.status));
42
+ return (j.content || []).map((p) => p.text || "").join("");
43
+ }
44
+
45
+ async function runTool(t) {
46
+ const show = t.name === "write" ? `write ${t.path} (${(t.content || "").length} Zeichen)` : `${t.name} ${t.cmd || t.path || ""}`;
47
+ console.log(C.y + "⚙ " + show + C.x);
48
+ if ((t.name === "run" || t.name === "write") && !autoYes) {
49
+ const a = (await ask(C.d + " Erlauben? [j/N/a=immer] " + C.x)).trim().toLowerCase();
50
+ if (a === "a") autoYes = true; else if (a !== "j" && a !== "y") return "Vom Nutzer abgelehnt.";
51
+ }
52
+ try {
53
+ if (t.name === "run") return execSync(t.cmd, { encoding: "utf8", stdio: "pipe", timeout: 120000, maxBuffer: 1e7 }).slice(-8000) || "(keine Ausgabe)";
54
+ if (t.name === "read") return fs.readFileSync(t.path, "utf8").slice(0, 20000);
55
+ if (t.name === "write") { fs.mkdirSync(path.dirname(path.resolve(t.path)), { recursive: true }); fs.writeFileSync(t.path, t.content ?? ""); return "OK geschrieben: " + t.path; }
56
+ if (t.name === "ls") return fs.readdirSync(t.path || ".", { withFileTypes: true }).map((e) => (e.isDirectory() ? "📁 " : " ") + e.name).join("\n");
57
+ return "Unbekanntes Werkzeug";
58
+ } catch (e) { return "FEHLER: " + (e.stdout || "") + (e.stderr || "") + e.message; }
59
+ }
60
+
61
+ async function turn(history, input) {
62
+ history.push({ role: "user", content: input });
63
+ for (let i = 0; i < 25; i++) {
64
+ process.stdout.write(C.d + "… denkt" + C.x + "\r");
65
+ const out = await call(history);
66
+ history.push({ role: "assistant", content: out });
67
+ const m = out.match(/<tool>([\s\S]*?)<\/tool>/);
68
+ const text = out.replace(/<tool>[\s\S]*?<\/tool>/g, "").trim();
69
+ if (text) console.log(C.b + "Mythos: " + C.x + text + "\n");
70
+ if (!m) return;
71
+ let t; try { t = JSON.parse(m[1]); } catch { history.push({ role: "user", content: "Tool-JSON ungültig." }); continue; }
72
+ const res = await runTool(t);
73
+ history.push({ role: "user", content: "Werkzeug-Ergebnis:\n" + res });
74
+ }
75
+ }
76
+
77
+ async function main() {
78
+ const args = process.argv.slice(2).filter((a) => a !== "--yes");
79
+ if (args[0] === "login" || !cfg.key) await login();
80
+ if (args[0] === "login") process.exit(0);
81
+ if (args[0] === "logout") { save({}); console.log("Abgemeldet."); process.exit(0); }
82
+ console.log(C.c + C.b + "\n ✦ MYTHOS CODE" + C.x + C.d + " – by Mythoscraft · /exit zum Beenden · /clear leeren\n" + C.x);
83
+ const history = [];
84
+ if (args.length) { await turn(history, args.join(" ")); }
85
+ while (true) {
86
+ const q = (await ask(C.c + "› " + C.x)).trim();
87
+ if (!q) continue;
88
+ if (q === "/exit") break;
89
+ if (q === "/clear") { history.length = 0; console.log("Verlauf geleert."); continue; }
90
+ try { await turn(history, q); } catch (e) { console.log(C.r + "Fehler: " + e.message + C.x); }
91
+ }
92
+ rl.close();
93
+ }
94
+ main();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "mythos-code",
3
+ "version": "1.0.0",
4
+ "description": "Mythos Code – KI-Coding-Agent im Terminal (by Mythoscraft)",
5
+ "bin": {
6
+ "mythos": "bin/mythos.js",
7
+ "mythos-code": "bin/mythos.js"
8
+ },
9
+ "type": "module",
10
+ "files": [
11
+ "bin",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "keywords": [
18
+ "ai",
19
+ "cli",
20
+ "agent",
21
+ "mythos",
22
+ "coding"
23
+ ],
24
+ "license": "MIT"
25
+ }