@garuda-agent/garuda 0.0.1 → 0.15.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 +77 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +1097 -0
- package/SECURITY.md +32 -0
- package/dist/acpCommand-FZ2P5JFO.js +153 -0
- package/dist/anthropic-NQDBCHJU.js +327 -0
- package/dist/chunk-23FXBNBB.js +46 -0
- package/dist/chunk-2S62ZNTC.js +320 -0
- package/dist/chunk-2TAXSFWN.js +49 -0
- package/dist/chunk-36GQIVGT.js +526 -0
- package/dist/chunk-3CEPHS4C.js +231 -0
- package/dist/chunk-3NJNVZTK.js +123 -0
- package/dist/chunk-42DSA4EA.js +116 -0
- package/dist/chunk-4JSUUDFQ.js +118 -0
- package/dist/chunk-4P26OKTP.js +100 -0
- package/dist/chunk-5DEWP3YX.js +139 -0
- package/dist/chunk-A2QAIRQL.js +45 -0
- package/dist/chunk-ATW7BNIG.js +31 -0
- package/dist/chunk-B25VL4RU.js +242 -0
- package/dist/chunk-EPKWDCV4.js +9 -0
- package/dist/chunk-EU7PA45O.js +324 -0
- package/dist/chunk-FARS4R67.js +206 -0
- package/dist/chunk-G2AX7MGS.js +36 -0
- package/dist/chunk-HRGX53VC.js +173 -0
- package/dist/chunk-HUIK3WXO.js +234 -0
- package/dist/chunk-INRZR772.js +73 -0
- package/dist/chunk-K3SIUOAG.js +138 -0
- package/dist/chunk-K7KK7U44.js +9358 -0
- package/dist/chunk-KKB5W47S.js +231 -0
- package/dist/chunk-N4I6YS3E.js +73 -0
- package/dist/chunk-NXJ4XLB5.js +19 -0
- package/dist/chunk-OUCV3FCT.js +205 -0
- package/dist/chunk-PQNT34LY.js +1247 -0
- package/dist/chunk-PZS3V6P3.js +46 -0
- package/dist/chunk-S77XDSD4.js +157 -0
- package/dist/chunk-SI2QJYCR.js +1341 -0
- package/dist/chunk-WMOLXTBU.js +61 -0
- package/dist/chunk-YFQJXRIJ.js +193 -0
- package/dist/chunk-YQTGMCU6.js +111 -0
- package/dist/chunk-ZAE25JM2.js +158 -0
- package/dist/cli/index.js +1203 -0
- package/dist/create-N4I7TIZE.js +223 -0
- package/dist/deadline-F5RJJ2QW.js +86 -0
- package/dist/detect-LARDSLLZ.js +10 -0
- package/dist/evalCommand-3SSFMZQD.js +2798 -0
- package/dist/export-HN3CT7AV.js +158 -0
- package/dist/inkChat-34BTFG2K.js +1193 -0
- package/dist/install-VRPBZY5H.js +17 -0
- package/dist/job-3NYDMP2M.js +31 -0
- package/dist/jobCommand-XJ5GULS5.js +30 -0
- package/dist/launchd-QVHQ3VNN.js +40 -0
- package/dist/lspCommand-XNTBHXLA.js +99 -0
- package/dist/manager-4PMSXT47.js +14 -0
- package/dist/manager-CSI76AWF.js +847 -0
- package/dist/nightCommand-CR6ZHYGP.js +247 -0
- package/dist/oauth-W6OK6XXO.js +23 -0
- package/dist/openaiCompatible-CJWVJP5M.js +501 -0
- package/dist/policy-EJPLEEXP.js +31 -0
- package/dist/proxy-XJAHCZB2.js +192 -0
- package/dist/remove-LE7Q7K46.js +59 -0
- package/dist/run-ML6GSPN4.js +888 -0
- package/dist/server-R3GNIC33.js +676 -0
- package/dist/servers-6YDGWOZ6.js +24 -0
- package/dist/text-J2GD647J.js +11 -0
- package/package.json +84 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/mcp/sanitize.ts
|
|
4
|
+
var ESCAPES = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-_]|\u009b[0-?]*[ -/]*[@-~]/g;
|
|
5
|
+
var CONTROLS = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
6
|
+
var INVISIBLE = /[\u200b-\u200f\u202a-\u202e\u2060-\u2064\u2066-\u2069\ufeff]/g;
|
|
7
|
+
var TAGS = /[\u{e0000}-\u{e007f}]/gu;
|
|
8
|
+
function cleanText(text) {
|
|
9
|
+
return text.replace(/\r\n?/g, "\n").replace(ESCAPES, "").replace(CONTROLS, "").replace(INVISIBLE, "").replace(TAGS, "");
|
|
10
|
+
}
|
|
11
|
+
function cleanLine(text) {
|
|
12
|
+
return cleanText(text).replace(/\s+/g, " ").trim();
|
|
13
|
+
}
|
|
14
|
+
function capText(text, max) {
|
|
15
|
+
if (text.length <= max) return text;
|
|
16
|
+
const head = Math.floor(max * 0.7);
|
|
17
|
+
const tail = max - head;
|
|
18
|
+
return `${text.slice(0, head)}
|
|
19
|
+
[\u2026 ${text.length - max} characters cut by Garuda \u2026]
|
|
20
|
+
${text.slice(-tail)}`;
|
|
21
|
+
}
|
|
22
|
+
function cleanJson(value) {
|
|
23
|
+
if (typeof value === "string") return cleanText(value);
|
|
24
|
+
if (Array.isArray(value)) return value.map(cleanJson);
|
|
25
|
+
if (value !== null && typeof value === "object") {
|
|
26
|
+
return Object.fromEntries(
|
|
27
|
+
Object.entries(value).map(([k, v]) => [
|
|
28
|
+
cleanText(k),
|
|
29
|
+
cleanJson(v)
|
|
30
|
+
])
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function neutralizeTags(text) {
|
|
36
|
+
return text.replace(/<(\/?)(mcp_result|web_result|garuda_note|skill_file|skill)/gi, "<\\$1$2");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
cleanText,
|
|
41
|
+
cleanLine,
|
|
42
|
+
capText,
|
|
43
|
+
cleanJson,
|
|
44
|
+
neutralizeTags
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=chunk-PZS3V6P3.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
hostCommand,
|
|
4
|
+
shellWord
|
|
5
|
+
} from "./chunk-2TAXSFWN.js";
|
|
6
|
+
import {
|
|
7
|
+
JOBS_DIR
|
|
8
|
+
} from "./chunk-KKB5W47S.js";
|
|
9
|
+
|
|
10
|
+
// src/jobs/launchd.ts
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import { existsSync, readFileSync } from "fs";
|
|
13
|
+
import { mkdir, rm, writeFile } from "fs/promises";
|
|
14
|
+
import { homedir } from "os";
|
|
15
|
+
import { basename, join } from "path";
|
|
16
|
+
function defaultAgentEnv() {
|
|
17
|
+
const shell = process.env.SHELL ?? "";
|
|
18
|
+
return {
|
|
19
|
+
home: homedir(),
|
|
20
|
+
uid: process.getuid?.() ?? 501,
|
|
21
|
+
shell: /\/(zsh|bash)$/.test(shell) ? shell : "/bin/zsh",
|
|
22
|
+
node: process.execPath,
|
|
23
|
+
script: process.argv[1] ?? ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function agentLabel(id) {
|
|
27
|
+
return `dev.garuda.job.${id}`;
|
|
28
|
+
}
|
|
29
|
+
function agentPath(home, id) {
|
|
30
|
+
return join(home, "Library", "LaunchAgents", `${agentLabel(id)}.plist`);
|
|
31
|
+
}
|
|
32
|
+
function nextTime(at, now = /* @__PURE__ */ new Date()) {
|
|
33
|
+
const [hour, minute] = at.split(":").map(Number);
|
|
34
|
+
const next = new Date(now);
|
|
35
|
+
next.setHours(hour, minute, 0, 0);
|
|
36
|
+
if (next.getTime() <= now.getTime()) next.setDate(next.getDate() + 1);
|
|
37
|
+
return next;
|
|
38
|
+
}
|
|
39
|
+
var xml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
40
|
+
function jobSpec(job) {
|
|
41
|
+
return {
|
|
42
|
+
label: agentLabel(job.id),
|
|
43
|
+
root: job.root,
|
|
44
|
+
args: ["run", job.id, "--from-launchd"],
|
|
45
|
+
log: join(job.root, JOBS_DIR, `${job.id}.log`)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function nightSpec(root) {
|
|
49
|
+
const hash = createHash("sha256").update(root).digest("hex").slice(0, 8);
|
|
50
|
+
const name = basename(root).replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 40) || "project";
|
|
51
|
+
return {
|
|
52
|
+
label: `dev.garuda.night.${name}-${hash}`,
|
|
53
|
+
root,
|
|
54
|
+
args: ["night", "--from-launchd"],
|
|
55
|
+
log: join(root, JOBS_DIR, "night.log")
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function specPath(home, spec) {
|
|
59
|
+
return join(home, "Library", "LaunchAgents", `${spec.label}.plist`);
|
|
60
|
+
}
|
|
61
|
+
function agentPlist(job, env, when) {
|
|
62
|
+
return specPlist(jobSpec(job), env, when);
|
|
63
|
+
}
|
|
64
|
+
function specPlist(spec, env, when) {
|
|
65
|
+
const program = env.script === "" || env.script === env.node ? shellWord(env.node) : `${shellWord(env.node)} ${shellWord(env.script)}`;
|
|
66
|
+
const command = `cd ${shellWord(spec.root)} && exec ${program} ${spec.args.map(shellWord).join(" ")}`;
|
|
67
|
+
const args = ["/usr/bin/caffeinate", "-i", env.shell, "-lic", command];
|
|
68
|
+
const int = (key, value) => ` <key>${key}</key><integer>${value}</integer>`;
|
|
69
|
+
return [
|
|
70
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
71
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
72
|
+
'<plist version="1.0">',
|
|
73
|
+
" <dict>",
|
|
74
|
+
` <key>Label</key><string>${xml(spec.label)}</string>`,
|
|
75
|
+
" <key>ProgramArguments</key>",
|
|
76
|
+
" <array>",
|
|
77
|
+
...args.map((a) => ` <string>${xml(a)}</string>`),
|
|
78
|
+
" </array>",
|
|
79
|
+
` <key>WorkingDirectory</key><string>${xml(spec.root)}</string>`,
|
|
80
|
+
" <key>StartCalendarInterval</key>",
|
|
81
|
+
" <dict>",
|
|
82
|
+
int("Month", when.getMonth() + 1),
|
|
83
|
+
int("Day", when.getDate()),
|
|
84
|
+
int("Hour", when.getHours()),
|
|
85
|
+
int("Minute", when.getMinutes()),
|
|
86
|
+
" </dict>",
|
|
87
|
+
" <key>RunAtLoad</key><false/>",
|
|
88
|
+
` <key>StandardOutPath</key><string>${xml(spec.log)}</string>`,
|
|
89
|
+
` <key>StandardErrorPath</key><string>${xml(spec.log)}</string>`,
|
|
90
|
+
" </dict>",
|
|
91
|
+
"</plist>",
|
|
92
|
+
""
|
|
93
|
+
].join("\n");
|
|
94
|
+
}
|
|
95
|
+
async function installAgent(executor, job, env, now = /* @__PURE__ */ new Date()) {
|
|
96
|
+
if (job.at === void 0) throw new Error("The job has no time.");
|
|
97
|
+
return installSpec(executor, jobSpec(job), env, nextTime(job.at, now));
|
|
98
|
+
}
|
|
99
|
+
async function installSpec(executor, spec, env, when) {
|
|
100
|
+
const plist = specPath(env.home, spec);
|
|
101
|
+
await mkdir(join(env.home, "Library", "LaunchAgents"), { recursive: true });
|
|
102
|
+
await writeFile(plist, specPlist(spec, env, when), { mode: 420 });
|
|
103
|
+
await hostCommand(executor, spec.root, ["launchctl", "bootout", `gui/${env.uid}/${spec.label}`], {
|
|
104
|
+
check: false
|
|
105
|
+
});
|
|
106
|
+
await hostCommand(executor, spec.root, ["launchctl", "bootstrap", `gui/${env.uid}`, plist]);
|
|
107
|
+
return { plist, when };
|
|
108
|
+
}
|
|
109
|
+
async function removeSpec(executor, spec, env) {
|
|
110
|
+
const plist = specPath(env.home, spec);
|
|
111
|
+
const had = existsSync(plist);
|
|
112
|
+
await rm(plist, { force: true });
|
|
113
|
+
const out = await hostCommand(
|
|
114
|
+
executor,
|
|
115
|
+
spec.root,
|
|
116
|
+
["launchctl", "bootout", `gui/${env.uid}/${spec.label}`],
|
|
117
|
+
{ check: false }
|
|
118
|
+
);
|
|
119
|
+
return had || out.exitCode === 0;
|
|
120
|
+
}
|
|
121
|
+
function nightAgentTime(root, env) {
|
|
122
|
+
let text;
|
|
123
|
+
try {
|
|
124
|
+
text = readFileSync(specPath(env.home, nightSpec(root)), "utf8");
|
|
125
|
+
} catch {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
const n = (key) => Number(new RegExp(`<key>${key}</key><integer>(\\d+)</integer>`).exec(text)?.[1]);
|
|
129
|
+
const month = n("Month");
|
|
130
|
+
const day = n("Day");
|
|
131
|
+
if (Number.isNaN(month) || Number.isNaN(day)) return void 0;
|
|
132
|
+
const now = /* @__PURE__ */ new Date();
|
|
133
|
+
const when = new Date(now.getFullYear(), month - 1, day, n("Hour"), n("Minute"));
|
|
134
|
+
if (when.getTime() < now.getTime() - 180 * 864e5) when.setFullYear(now.getFullYear() + 1);
|
|
135
|
+
return when;
|
|
136
|
+
}
|
|
137
|
+
async function removeAgent(executor, job, env) {
|
|
138
|
+
return removeSpec(executor, jobSpec(job), env);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
defaultAgentEnv,
|
|
143
|
+
agentLabel,
|
|
144
|
+
agentPath,
|
|
145
|
+
nextTime,
|
|
146
|
+
jobSpec,
|
|
147
|
+
nightSpec,
|
|
148
|
+
specPath,
|
|
149
|
+
agentPlist,
|
|
150
|
+
specPlist,
|
|
151
|
+
installAgent,
|
|
152
|
+
installSpec,
|
|
153
|
+
removeSpec,
|
|
154
|
+
nightAgentTime,
|
|
155
|
+
removeAgent
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=chunk-S77XDSD4.js.map
|