@agentsky/sky 3.43.0 → 3.44.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/dist/{trace-library-XLBJHI3I.js → chunk-3FQZZNQP.js} +566 -156
- package/dist/chunk-BCSZO4BR.js +555 -0
- package/dist/{chunk-4A4PDUT5.js → chunk-CXRMG3HQ.js} +1 -1
- package/dist/{chunk-OKNWK75U.js → chunk-EBCVJDIL.js} +39 -287
- package/dist/{chunk-J3KIEZXM.js → chunk-F6V2GGMP.js} +14 -190
- package/dist/chunk-HGLVOMHL.js +2124 -0
- package/dist/{chunk-4MVM65ET.js → chunk-KTSUD2BU.js} +1 -1
- package/dist/{chunk-44XF4EGE.js → chunk-W2WEEVIM.js} +1 -1
- package/dist/chunk-ZVNQJPMS.js +193 -0
- package/dist/compute-KNUZU4AO.js +35 -0
- package/dist/compute-report-AT642XES.js +34 -0
- package/dist/index.js +591 -2424
- package/dist/{local-skills-AVLHV36B.js → local-skills-HHTAWGYV.js} +3 -2
- package/dist/{local-skills-run-UJK4ZO4P.js → local-skills-run-OYPW36ZG.js} +11 -8
- package/dist/mcp-serve-EJ7YKBMM.js +103 -0
- package/dist/{trace-H3FVIFE3.js → trace-754MK5OE.js} +2 -2
- package/dist/trace-library-WE3C5OBP.js +67 -0
- package/package.json +1 -1
- package/dist/chunk-AB7SUDX4.js +0 -413
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
skillTargets,
|
|
10
10
|
syncLocalSkills,
|
|
11
11
|
unpinLocalSkill
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-ZVNQJPMS.js";
|
|
13
|
+
import "./chunk-F6V2GGMP.js";
|
|
14
|
+
import "./chunk-CXRMG3HQ.js";
|
|
14
15
|
import "./chunk-XHZJG3QT.js";
|
|
15
16
|
import "./chunk-MLKGABMK.js";
|
|
16
17
|
export {
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SetupJournal,
|
|
3
|
-
detectHermes,
|
|
4
|
-
detectLocalAgents,
|
|
5
3
|
workspaceSlug
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import
|
|
4
|
+
} from "./chunk-EBCVJDIL.js";
|
|
5
|
+
import {
|
|
6
|
+
detectHermes,
|
|
7
|
+
detectLocalAgents
|
|
8
|
+
} from "./chunk-BCSZO4BR.js";
|
|
9
|
+
import "./chunk-W2WEEVIM.js";
|
|
8
10
|
import {
|
|
9
11
|
checkedWithin,
|
|
10
12
|
skillTargets,
|
|
11
13
|
syncLocalSkills
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-ZVNQJPMS.js";
|
|
15
|
+
import "./chunk-F6V2GGMP.js";
|
|
16
|
+
import "./chunk-CXRMG3HQ.js";
|
|
14
17
|
import "./chunk-XHZJG3QT.js";
|
|
15
18
|
import "./chunk-MLKGABMK.js";
|
|
16
19
|
|
|
@@ -18,7 +21,7 @@ import "./chunk-MLKGABMK.js";
|
|
|
18
21
|
var HOOK_RECHECK_MS = 5 * 60 * 1e3;
|
|
19
22
|
async function localSkillWorkspace(explicit) {
|
|
20
23
|
if (explicit) return explicit;
|
|
21
|
-
const { loadSyncConfig } = await import("./trace-library-
|
|
24
|
+
const { loadSyncConfig } = await import("./trace-library-WE3C5OBP.js");
|
|
22
25
|
return loadSyncConfig().fallback ?? await workspaceSlug();
|
|
23
26
|
}
|
|
24
27
|
async function refreshLocalSkills(opts = {}) {
|
|
@@ -27,7 +30,7 @@ async function refreshLocalSkills(opts = {}) {
|
|
|
27
30
|
const targets = skillTargets(detectLocalAgents(), hermes?.root ?? null);
|
|
28
31
|
const workspace = await localSkillWorkspace(opts.workspace);
|
|
29
32
|
if (!targets.length) return { workspace, checked: false, skills: [] };
|
|
30
|
-
const { libraryRequest } = await import("./trace-library-
|
|
33
|
+
const { libraryRequest } = await import("./trace-library-WE3C5OBP.js");
|
|
31
34
|
const journal = opts.dryRun ? void 0 : new SetupJournal();
|
|
32
35
|
try {
|
|
33
36
|
return await syncLocalSkills({ workspace, targets, journal, dryRun: opts.dryRun, request: (method, path, slug) => libraryRequest(method, path, slug) });
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cachedSettingsBlock,
|
|
3
|
+
mcpUrlFor
|
|
4
|
+
} from "./chunk-BCSZO4BR.js";
|
|
5
|
+
import "./chunk-W2WEEVIM.js";
|
|
6
|
+
import "./chunk-F6V2GGMP.js";
|
|
7
|
+
import {
|
|
8
|
+
USER_AGENT
|
|
9
|
+
} from "./chunk-CXRMG3HQ.js";
|
|
10
|
+
import {
|
|
11
|
+
apiBase,
|
|
12
|
+
apiToken
|
|
13
|
+
} from "./chunk-XHZJG3QT.js";
|
|
14
|
+
import "./chunk-MLKGABMK.js";
|
|
15
|
+
|
|
16
|
+
// src/mcp-serve.ts
|
|
17
|
+
import { createInterface } from "readline";
|
|
18
|
+
var defaults = () => ({
|
|
19
|
+
fetch,
|
|
20
|
+
token: apiToken,
|
|
21
|
+
url: () => mcpUrlFor(apiBase(), "short"),
|
|
22
|
+
settings: cachedSettingsBlock,
|
|
23
|
+
write: (line) => process.stdout.write(`${line}
|
|
24
|
+
`)
|
|
25
|
+
});
|
|
26
|
+
function failure(id, message) {
|
|
27
|
+
return JSON.stringify({ jsonrpc: "2.0", id: id ?? null, error: { code: -32e3, message } });
|
|
28
|
+
}
|
|
29
|
+
function answersIn(body, type) {
|
|
30
|
+
const texts = type?.includes("text/event-stream") ? body.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).filter(Boolean) : body.trim() ? [body] : [];
|
|
31
|
+
return texts.flatMap((text) => {
|
|
32
|
+
const parsed = JSON.parse(text);
|
|
33
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async function forwardLine(line, deps = defaults(), protocol = {}) {
|
|
37
|
+
let message;
|
|
38
|
+
try {
|
|
39
|
+
message = JSON.parse(line);
|
|
40
|
+
} catch {
|
|
41
|
+
return deps.write(failure(null, "not a JSON-RPC message"));
|
|
42
|
+
}
|
|
43
|
+
const token = deps.token();
|
|
44
|
+
const expectsAnswer = message.id !== void 0 && message.id !== null;
|
|
45
|
+
if (!token) {
|
|
46
|
+
if (expectsAnswer) deps.write(failure(message.id, "sky is not signed in on this computer: run `sky auth login`"));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let response;
|
|
50
|
+
try {
|
|
51
|
+
response = await deps.fetch(deps.url(), {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: {
|
|
54
|
+
"user-agent": USER_AGENT,
|
|
55
|
+
authorization: `Bearer ${token}`,
|
|
56
|
+
"content-type": "application/json",
|
|
57
|
+
accept: "application/json, text/event-stream",
|
|
58
|
+
...protocol.version ? { "mcp-protocol-version": protocol.version } : {}
|
|
59
|
+
},
|
|
60
|
+
body: line
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (expectsAnswer) deps.write(failure(message.id, `AgentSky could not be reached: ${error instanceof Error ? error.message : String(error)}`));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const body = await response.text();
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
if (expectsAnswer) deps.write(failure(message.id, `AgentSky answered ${response.status}`));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let answers;
|
|
72
|
+
try {
|
|
73
|
+
answers = answersIn(body, response.headers.get("content-type"));
|
|
74
|
+
} catch {
|
|
75
|
+
if (expectsAnswer) deps.write(failure(message.id, "AgentSky's answer was not JSON"));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const answer of answers) {
|
|
79
|
+
if (message.method === "initialize" && answer.result) {
|
|
80
|
+
const version = answer.result.protocolVersion;
|
|
81
|
+
if (typeof version === "string") protocol.version = version;
|
|
82
|
+
const settings = deps.settings();
|
|
83
|
+
if (settings) answer.result.instructions = `${answer.result.instructions ?? ""}
|
|
84
|
+
|
|
85
|
+
${settings}`.trim();
|
|
86
|
+
}
|
|
87
|
+
deps.write(JSON.stringify(answer));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function serveMcp(deps = defaults()) {
|
|
91
|
+
const protocol = {};
|
|
92
|
+
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
93
|
+
let queue = Promise.resolve();
|
|
94
|
+
for await (const line of lines) {
|
|
95
|
+
if (!line.trim()) continue;
|
|
96
|
+
queue = queue.then(() => forwardLine(line, deps, protocol));
|
|
97
|
+
}
|
|
98
|
+
await queue;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
forwardLine,
|
|
102
|
+
serveMcp
|
|
103
|
+
};
|
|
@@ -22,9 +22,9 @@ import {
|
|
|
22
22
|
traceDir,
|
|
23
23
|
uninstallClaudeHooks,
|
|
24
24
|
writeState
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-KTSUD2BU.js";
|
|
26
26
|
import "./chunk-BIZJ4VZL.js";
|
|
27
|
-
import "./chunk-
|
|
27
|
+
import "./chunk-CXRMG3HQ.js";
|
|
28
28
|
import "./chunk-XHZJG3QT.js";
|
|
29
29
|
import "./chunk-MLKGABMK.js";
|
|
30
30
|
export {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LAUNCHD_LABEL,
|
|
3
|
+
SYNC_HOOK_COMMAND,
|
|
4
|
+
collectorBody,
|
|
5
|
+
collectorHarness,
|
|
6
|
+
discoverSessions,
|
|
7
|
+
hookSessionRef,
|
|
8
|
+
importExport,
|
|
9
|
+
installLaunchd,
|
|
10
|
+
installSyncHooks,
|
|
11
|
+
isTrivial,
|
|
12
|
+
lastUploads,
|
|
13
|
+
launchdPlist,
|
|
14
|
+
launchdPlistPath,
|
|
15
|
+
libraryRequest,
|
|
16
|
+
loadSyncConfig,
|
|
17
|
+
parseClaudeSession,
|
|
18
|
+
parseCodexSession,
|
|
19
|
+
projectOf,
|
|
20
|
+
repoRemote,
|
|
21
|
+
routeSession,
|
|
22
|
+
saveSyncConfig,
|
|
23
|
+
sessionDigest,
|
|
24
|
+
sourceFolders,
|
|
25
|
+
supportedAgents,
|
|
26
|
+
syncConfigPath,
|
|
27
|
+
syncDir,
|
|
28
|
+
syncTraces
|
|
29
|
+
} from "./chunk-3FQZZNQP.js";
|
|
30
|
+
import "./chunk-KTSUD2BU.js";
|
|
31
|
+
import "./chunk-UJ7IXSJX.js";
|
|
32
|
+
import "./chunk-BIZJ4VZL.js";
|
|
33
|
+
import "./chunk-W2WEEVIM.js";
|
|
34
|
+
import "./chunk-ZVNQJPMS.js";
|
|
35
|
+
import "./chunk-F6V2GGMP.js";
|
|
36
|
+
import "./chunk-CXRMG3HQ.js";
|
|
37
|
+
import "./chunk-XHZJG3QT.js";
|
|
38
|
+
import "./chunk-MLKGABMK.js";
|
|
39
|
+
export {
|
|
40
|
+
LAUNCHD_LABEL,
|
|
41
|
+
SYNC_HOOK_COMMAND,
|
|
42
|
+
collectorBody,
|
|
43
|
+
collectorHarness,
|
|
44
|
+
discoverSessions,
|
|
45
|
+
hookSessionRef,
|
|
46
|
+
importExport,
|
|
47
|
+
installLaunchd,
|
|
48
|
+
installSyncHooks,
|
|
49
|
+
isTrivial,
|
|
50
|
+
lastUploads,
|
|
51
|
+
launchdPlist,
|
|
52
|
+
launchdPlistPath,
|
|
53
|
+
libraryRequest,
|
|
54
|
+
loadSyncConfig,
|
|
55
|
+
parseClaudeSession,
|
|
56
|
+
parseCodexSession,
|
|
57
|
+
projectOf,
|
|
58
|
+
repoRemote,
|
|
59
|
+
routeSession,
|
|
60
|
+
saveSyncConfig,
|
|
61
|
+
sessionDigest,
|
|
62
|
+
sourceFolders,
|
|
63
|
+
supportedAgents,
|
|
64
|
+
syncConfigPath,
|
|
65
|
+
syncDir,
|
|
66
|
+
syncTraces
|
|
67
|
+
};
|
package/package.json
CHANGED
package/dist/chunk-AB7SUDX4.js
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiError,
|
|
3
|
-
api
|
|
4
|
-
} from "./chunk-44XF4EGE.js";
|
|
5
|
-
import {
|
|
6
|
-
USER_AGENT
|
|
7
|
-
} from "./chunk-4A4PDUT5.js";
|
|
8
|
-
import {
|
|
9
|
-
configPath
|
|
10
|
-
} from "./chunk-XHZJG3QT.js";
|
|
11
|
-
|
|
12
|
-
// src/resumable-upload.ts
|
|
13
|
-
import { createHash } from "crypto";
|
|
14
|
-
import { mkdirSync, openSync, readFileSync, readSync, closeSync, rmSync, statSync, writeFileSync } from "fs";
|
|
15
|
-
import { basename, dirname, join, resolve } from "path";
|
|
16
|
-
var SINGLE_REQUEST_MAX_BYTES = 32 * 1024 * 1024;
|
|
17
|
-
var MAX_ATTEMPTS = 8;
|
|
18
|
-
function statePath(path, size, mtimeMs, universe) {
|
|
19
|
-
const key = createHash("sha256").update(`${resolve(path)}\0${size}\0${mtimeMs}\0${universe ?? ""}`).digest("hex").slice(0, 32);
|
|
20
|
-
return join(dirname(configPath()), "uploads", `${key}.json`);
|
|
21
|
-
}
|
|
22
|
-
function loadSession(file, expiresInSeconds, universe) {
|
|
23
|
-
try {
|
|
24
|
-
const saved = JSON.parse(readFileSync(file, "utf8"));
|
|
25
|
-
if (saved.expiresInSeconds !== expiresInSeconds || saved.universe !== universe) return null;
|
|
26
|
-
if (Date.parse(saved.expires_at) - Date.now() < 3600 * 1e3) return null;
|
|
27
|
-
return saved;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function acknowledged(res) {
|
|
33
|
-
const range = res.headers.get("range")?.match(/^bytes=0-(\d+)$/);
|
|
34
|
-
return range ? Number(range[1]) + 1 : 0;
|
|
35
|
-
}
|
|
36
|
-
async function probe(session) {
|
|
37
|
-
const res = await fetch(session.upload_url, {
|
|
38
|
-
method: "PUT",
|
|
39
|
-
headers: { "user-agent": USER_AGENT, "content-range": `bytes */${session.size_bytes}` }
|
|
40
|
-
});
|
|
41
|
-
if (res.status === 200 || res.status === 201) return "done";
|
|
42
|
-
if (res.status === 308) return acknowledged(res);
|
|
43
|
-
if (res.status === 404 || res.status === 410) throw new ApiError(res.status, "upload_expired", "the upload session is gone");
|
|
44
|
-
throw new ApiError(res.status, "upload_failed", `upload status check failed: ${res.status} ${res.statusText}`);
|
|
45
|
-
}
|
|
46
|
-
async function sendChunk(session, fd, offset) {
|
|
47
|
-
const length = Math.min(session.chunk_size, session.size_bytes - offset);
|
|
48
|
-
const chunk = Buffer.alloc(length);
|
|
49
|
-
let read = 0;
|
|
50
|
-
while (read < length) read += readSync(fd, chunk, read, length - read, offset + read);
|
|
51
|
-
const res = await fetch(session.upload_url, {
|
|
52
|
-
method: "PUT",
|
|
53
|
-
headers: {
|
|
54
|
-
"user-agent": USER_AGENT,
|
|
55
|
-
"content-range": `bytes ${offset}-${offset + length - 1}/${session.size_bytes}`
|
|
56
|
-
},
|
|
57
|
-
body: chunk
|
|
58
|
-
});
|
|
59
|
-
if (res.status === 200 || res.status === 201) return "done";
|
|
60
|
-
if (res.status === 308) return acknowledged(res);
|
|
61
|
-
if (res.status >= 500 || res.status === 429) throw new Error(`transient ${res.status}`);
|
|
62
|
-
throw new ApiError(res.status, "upload_failed", `chunk upload failed: ${res.status} ${(await res.text()).slice(0, 200)}`);
|
|
63
|
-
}
|
|
64
|
-
async function transfer(session, path, onProgress) {
|
|
65
|
-
const fd = openSync(path, "r");
|
|
66
|
-
try {
|
|
67
|
-
let failures = 0;
|
|
68
|
-
let state = await probe(session);
|
|
69
|
-
while (state !== "done") {
|
|
70
|
-
onProgress(state, session.size_bytes);
|
|
71
|
-
try {
|
|
72
|
-
state = await sendChunk(session, fd, state);
|
|
73
|
-
failures = 0;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (error instanceof ApiError || ++failures >= MAX_ATTEMPTS) throw error;
|
|
76
|
-
await new Promise((done) => setTimeout(done, Math.min(3e4, 500 * 2 ** failures)));
|
|
77
|
-
state = await probe(session);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
onProgress(session.size_bytes, session.size_bytes);
|
|
81
|
-
} finally {
|
|
82
|
-
closeSync(fd);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function uploadLargeFile(path, mediaType, expiresInSeconds, onProgress, universe) {
|
|
86
|
-
const { size, mtimeMs } = statSync(path);
|
|
87
|
-
const stateFile = statePath(path, size, mtimeMs, universe);
|
|
88
|
-
let session = loadSession(stateFile, expiresInSeconds, universe);
|
|
89
|
-
if (session) {
|
|
90
|
-
try {
|
|
91
|
-
await probe(session);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
if (!(error instanceof ApiError) || error.status !== 404 && error.status !== 410) throw error;
|
|
94
|
-
session = null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (!session) {
|
|
98
|
-
session = await api("POST", "/files/uploads", {
|
|
99
|
-
filename: basename(path),
|
|
100
|
-
size_bytes: size,
|
|
101
|
-
mime_type: mediaType,
|
|
102
|
-
...expiresInSeconds ? { expires_in_seconds: expiresInSeconds } : {}
|
|
103
|
-
}, { universe });
|
|
104
|
-
mkdirSync(dirname(stateFile), { recursive: true });
|
|
105
|
-
const saved = { ...session, path: resolve(path), mtimeMs, expiresInSeconds, universe };
|
|
106
|
-
writeFileSync(stateFile, JSON.stringify(saved), { mode: 384 });
|
|
107
|
-
}
|
|
108
|
-
await transfer(session, path, onProgress);
|
|
109
|
-
const file = await api("POST", `/files/uploads/${encodeURIComponent(session.id)}/complete`, void 0, { universe });
|
|
110
|
-
rmSync(stateFile, { force: true });
|
|
111
|
-
return file;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/import-workspace.ts
|
|
115
|
-
import { spawnSync } from "child_process";
|
|
116
|
-
import { existsSync, readdirSync, readFileSync as readFileSync2, realpathSync, statSync as statSync2 } from "fs";
|
|
117
|
-
import { homedir } from "os";
|
|
118
|
-
import { basename as basename2, dirname as dirname2, join as join2, relative, resolve as resolve2, sep } from "path";
|
|
119
|
-
import { parse as parseToml } from "smol-toml";
|
|
120
|
-
function importReadAllowed(path, allowed) {
|
|
121
|
-
if (!allowed) return true;
|
|
122
|
-
if (!allowed(path)) return false;
|
|
123
|
-
try {
|
|
124
|
-
return allowed(realpathSync(path));
|
|
125
|
-
} catch {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
var SECRET_FILE = /(^|\/)(\.env(\..*)?|\.netrc|\.npmrc|\.pypirc|\.git-credentials|\.?credentials(\.json)?|auth\.json|\.claude\.json|id_(rsa|ed25519|ecdsa)[^/]*|.*\.(pem|key|p12|pfx|keystore|jks|kdbx|sqlite|db))$|\/\.ssh\/|\/\.aws\/|\/\.gnupg\/|\/\.docker\/config\.json$|\/Keychains\//i;
|
|
130
|
-
var SKIP_DIR = /(^|\/)(node_modules|\.git|\.next|dist|build|__pycache__|\.venv)(\/|$)/;
|
|
131
|
-
function importPathAllowed(path) {
|
|
132
|
-
const normalized = resolve2(path).split(sep).join("/");
|
|
133
|
-
return !SECRET_FILE.test(normalized) && !SKIP_DIR.test(normalized) && !/(^|\/)(\.ssh|\.aws|\.gnupg|Keychains)(\/|$)/i.test(normalized);
|
|
134
|
-
}
|
|
135
|
-
var MAX_TREE = 5e3;
|
|
136
|
-
var SKILL_LINE = /Base directory for this skill: (\/[^\n\r"'\\<>]+)/g;
|
|
137
|
-
function git(cwd, ...args) {
|
|
138
|
-
const run = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 1e4, maxBuffer: 32 * 1024 * 1024 });
|
|
139
|
-
return run.status === 0 ? run.stdout : null;
|
|
140
|
-
}
|
|
141
|
-
function repositoryRoot(cwd, allowed) {
|
|
142
|
-
if (!cwd || !importReadAllowed(cwd, allowed)) return null;
|
|
143
|
-
for (let dir = resolve2(cwd); ; dir = dirname2(dir)) {
|
|
144
|
-
if (!importReadAllowed(dir, allowed)) return null;
|
|
145
|
-
if (existsSync(join2(dir, ".git"))) {
|
|
146
|
-
if (!importReadAllowed(join2(dir, ".git"), allowed)) return null;
|
|
147
|
-
const root = git(cwd, "rev-parse", "--show-toplevel")?.trim();
|
|
148
|
-
return root && importReadAllowed(root, allowed) ? realpathSync(root) : null;
|
|
149
|
-
}
|
|
150
|
-
if (dir === dirname2(dir)) return null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
var isFile = (path) => {
|
|
154
|
-
try {
|
|
155
|
-
return statSync2(path).isFile();
|
|
156
|
-
} catch {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
var isDir = (path) => {
|
|
161
|
-
try {
|
|
162
|
-
return statSync2(path).isDirectory();
|
|
163
|
-
} catch {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
function sharedInstructionPaths(home = homedir(), allowed) {
|
|
168
|
-
const rules = join2(home, ".agents", "rules");
|
|
169
|
-
let ruleFiles = [];
|
|
170
|
-
try {
|
|
171
|
-
ruleFiles = (importReadAllowed(rules, allowed) ? readdirSync(rules) : []).filter((name) => name.endsWith(".md")).sort().map((name) => join2(rules, name));
|
|
172
|
-
} catch {
|
|
173
|
-
}
|
|
174
|
-
return [join2(home, "AGENTS.md"), join2(home, "MEMORY.md"), ...ruleFiles].filter((path) => importReadAllowed(path, allowed) && isFile(path));
|
|
175
|
-
}
|
|
176
|
-
function strings(value, out, depth = 0) {
|
|
177
|
-
if (depth > 12) return;
|
|
178
|
-
if (typeof value === "string") out.push(value);
|
|
179
|
-
else if (Array.isArray(value)) for (const item of value) strings(item, out, depth + 1);
|
|
180
|
-
else if (value && typeof value === "object") for (const item of Object.values(value)) strings(item, out, depth + 1);
|
|
181
|
-
}
|
|
182
|
-
function skillRoots(cwd, home) {
|
|
183
|
-
const claude = process.env.CLAUDE_CONFIG_DIR ?? join2(home, ".claude");
|
|
184
|
-
const codex = process.env.CODEX_HOME ?? join2(home, ".codex");
|
|
185
|
-
return [
|
|
186
|
-
...cwd ? [join2(cwd, ".claude", "skills"), join2(cwd, ".agents", "skills")] : [],
|
|
187
|
-
join2(home, ".agents", "skills"),
|
|
188
|
-
join2(claude, "skills"),
|
|
189
|
-
join2(codex, "skills"),
|
|
190
|
-
join2(home, ".hermes", "skills")
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
function pluginSkill(plugin, skill, home, allowed) {
|
|
194
|
-
const walk = (dir, depth, underPlugin) => {
|
|
195
|
-
if (depth > 7 || !importReadAllowed(dir, allowed)) return null;
|
|
196
|
-
let entries;
|
|
197
|
-
try {
|
|
198
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
199
|
-
} catch {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
for (const entry of entries) {
|
|
203
|
-
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name === ".git") continue;
|
|
204
|
-
const path = join2(dir, entry.name);
|
|
205
|
-
if (entry.name === skill && basename2(dir) === "skills" && (underPlugin || path.includes(`${sep}${plugin}${sep}`)) && importReadAllowed(join2(path, "SKILL.md"), allowed) && isFile(join2(path, "SKILL.md"))) return realpathSync(path);
|
|
206
|
-
const found = walk(path, depth + 1, underPlugin);
|
|
207
|
-
if (found) return found;
|
|
208
|
-
}
|
|
209
|
-
return null;
|
|
210
|
-
};
|
|
211
|
-
return walk(join2(process.env.CLAUDE_CONFIG_DIR ?? join2(home, ".claude"), "plugins"), 0, false) ?? walk(join2(home, "Library", "Application Support", "Claude", "local-agent-mode-sessions", "skills-plugin"), 0, true);
|
|
212
|
-
}
|
|
213
|
-
function findSkill(name, cwd, home, allowed) {
|
|
214
|
-
const [scope, skill] = name.includes(":") ? name.split(":", 2) : [null, name];
|
|
215
|
-
if (scope && skill) return pluginSkill(scope, skill, home, allowed);
|
|
216
|
-
for (const root of skillRoots(cwd, home)) {
|
|
217
|
-
const direct = join2(root, name);
|
|
218
|
-
if (importReadAllowed(join2(direct, "SKILL.md"), allowed) && isFile(join2(direct, "SKILL.md"))) return realpathSync(direct);
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
function loadedSkills(records, touched, cwd, home = homedir(), allowed) {
|
|
223
|
-
const dirs = /* @__PURE__ */ new Map();
|
|
224
|
-
const missing = /* @__PURE__ */ new Set();
|
|
225
|
-
const add = (dir, name = basename2(dir)) => {
|
|
226
|
-
if (!importReadAllowed(join2(dir, "SKILL.md"), allowed) || !isFile(join2(dir, "SKILL.md"))) return false;
|
|
227
|
-
const real = realpathSync(dir);
|
|
228
|
-
if (![...dirs.values()].includes(real)) dirs.set(name, real);
|
|
229
|
-
return true;
|
|
230
|
-
};
|
|
231
|
-
const called = [];
|
|
232
|
-
for (const record of records) {
|
|
233
|
-
const texts = [];
|
|
234
|
-
strings(record, texts);
|
|
235
|
-
for (const text of texts) for (const match of text.matchAll(SKILL_LINE)) add(match[1].trim().replace(/[.,;:)]+$/, ""));
|
|
236
|
-
const content = record?.message?.content;
|
|
237
|
-
if (!Array.isArray(content)) continue;
|
|
238
|
-
for (const block of content) {
|
|
239
|
-
const b = block;
|
|
240
|
-
if (b?.type === "tool_use" && b.name === "Skill" && typeof b.input?.skill === "string") called.push(b.input.skill.replace(/^\//, ""));
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
for (const path of touched) if (basename2(path) === "SKILL.md") add(dirname2(path));
|
|
244
|
-
for (const name of called) {
|
|
245
|
-
if (!name || dirs.has(name) || [...dirs.keys()].some((key) => key.endsWith(`:${name}`) || name.endsWith(`:${key}`))) continue;
|
|
246
|
-
const dir = findSkill(name, cwd, home, allowed);
|
|
247
|
-
if (!dir || !add(dir, name)) missing.add(name);
|
|
248
|
-
}
|
|
249
|
-
return { found: [...dirs].map(([name, dir]) => ({ name: name.replace(/[^A-Za-z0-9._:-]/g, "-"), dir })), missing: [...missing] };
|
|
250
|
-
}
|
|
251
|
-
function readJson(path, allowed) {
|
|
252
|
-
if (!importReadAllowed(path, allowed)) return null;
|
|
253
|
-
try {
|
|
254
|
-
const value = JSON.parse(readFileSync2(path, "utf8"));
|
|
255
|
-
return value && typeof value === "object" ? value : null;
|
|
256
|
-
} catch {
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function names(value) {
|
|
261
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
262
|
-
const keys = Object.keys(value).sort();
|
|
263
|
-
return keys.length ? keys : void 0;
|
|
264
|
-
}
|
|
265
|
-
function safeUrl(raw) {
|
|
266
|
-
try {
|
|
267
|
-
const url = new URL(raw);
|
|
268
|
-
if (!/^https?:$/.test(url.protocol)) return null;
|
|
269
|
-
const query = [.../* @__PURE__ */ new Set([...url.searchParams.keys()])].sort();
|
|
270
|
-
return { url: `${url.protocol}//${url.host}${url.pathname}`, ...query.length ? { query } : {} };
|
|
271
|
-
} catch {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function serverEntry(name, def, scope) {
|
|
276
|
-
if (!def || typeof def !== "object") return null;
|
|
277
|
-
const env = names(def.env);
|
|
278
|
-
const headers = names(def.headers ?? def.http_headers);
|
|
279
|
-
if (typeof def.url === "string") {
|
|
280
|
-
const url = safeUrl(def.url);
|
|
281
|
-
if (!url) return null;
|
|
282
|
-
const type = def.type === "sse" ? "sse" : "http";
|
|
283
|
-
return { name, scope, transport: type, ...url, ...headers ? { headers } : {}, ...env ? { env } : {} };
|
|
284
|
-
}
|
|
285
|
-
if (typeof def.command !== "string" || !def.command) return null;
|
|
286
|
-
const args = Array.isArray(def.args) ? def.args.filter((arg) => typeof arg === "string") : [];
|
|
287
|
-
return { name, scope, transport: "stdio", command: def.command, ...args.length ? { args } : {}, ...env ? { env } : {} };
|
|
288
|
-
}
|
|
289
|
-
function mcpServers(harness, cwd, home = homedir(), allowed) {
|
|
290
|
-
const out = [];
|
|
291
|
-
const push = (servers, scope) => {
|
|
292
|
-
if (!servers || typeof servers !== "object") return;
|
|
293
|
-
for (const [name, def] of Object.entries(servers)) {
|
|
294
|
-
const entry = serverEntry(name, def, scope);
|
|
295
|
-
if (entry && !out.some((existing) => existing.name === name)) out.push(entry);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
if (harness === "claude_code") {
|
|
299
|
-
const config = readJson(join2(process.env.CLAUDE_CONFIG_DIR ? dirname2(process.env.CLAUDE_CONFIG_DIR) : home, ".claude.json"), allowed);
|
|
300
|
-
const projects = config?.projects && typeof config.projects === "object" ? config.projects : {};
|
|
301
|
-
const root = cwd && importReadAllowed(cwd, allowed) ? repositoryRoot(cwd, allowed) || cwd : "";
|
|
302
|
-
if (cwd) push(projects[cwd]?.mcpServers ?? projects[root]?.mcpServers, "local");
|
|
303
|
-
if (root) push(readJson(join2(root, ".mcp.json"), allowed)?.mcpServers, "project");
|
|
304
|
-
push(config?.mcpServers, "user");
|
|
305
|
-
}
|
|
306
|
-
if (harness === "codex") {
|
|
307
|
-
try {
|
|
308
|
-
const path = join2(process.env.CODEX_HOME ?? join2(home, ".codex"), "config.toml");
|
|
309
|
-
if (!importReadAllowed(path, allowed)) return out;
|
|
310
|
-
const config = parseToml(readFileSync2(path, "utf8"));
|
|
311
|
-
push(config.mcp_servers, "user");
|
|
312
|
-
} catch {
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return out;
|
|
316
|
-
}
|
|
317
|
-
function remoteWithoutCredentials(remote) {
|
|
318
|
-
return remote.trim().replace(/\/\/[^@/]+@/, "//").replace(/^[^@/]+@([^:]+):/, "$1:");
|
|
319
|
-
}
|
|
320
|
-
function workspaceState(cwd, harness, skills, home = homedir(), title = null, allowed) {
|
|
321
|
-
const present = !!cwd && importReadAllowed(cwd, allowed) && isDir(cwd);
|
|
322
|
-
const root = present ? repositoryRoot(cwd, allowed) : null;
|
|
323
|
-
let gitState = null;
|
|
324
|
-
let tree = [];
|
|
325
|
-
let patch = null;
|
|
326
|
-
if (root && importReadAllowed(root, allowed)) {
|
|
327
|
-
const dirty = (git(root, "status", "--porcelain=v1", "--untracked-files=normal") ?? "").split("\n").filter(Boolean).map((line) => line.slice(3));
|
|
328
|
-
const ahead = git(root, "rev-list", "--count", "@{upstream}..HEAD");
|
|
329
|
-
const remote = git(root, "remote", "get-url", "origin");
|
|
330
|
-
const branch = git(root, "rev-parse", "--abbrev-ref", "HEAD")?.trim() || null;
|
|
331
|
-
gitState = {
|
|
332
|
-
remote: remote ? remoteWithoutCredentials(remote) : null,
|
|
333
|
-
branch: branch === "HEAD" ? null : branch,
|
|
334
|
-
commit: git(root, "rev-parse", "HEAD")?.trim() || null,
|
|
335
|
-
dirty: dirty.slice(0, 500),
|
|
336
|
-
ahead: ahead === null ? null : Number(ahead.trim()) || 0
|
|
337
|
-
};
|
|
338
|
-
tree = (git(cwd, "-c", "core.quotePath=false", "ls-files") ?? "").split("\n").filter(Boolean);
|
|
339
|
-
if (dirty.length) {
|
|
340
|
-
const changed = (git(cwd, "diff", "HEAD", "--name-only", "-z", "--relative", "--", ".") ?? "").split("\0").filter(Boolean);
|
|
341
|
-
const paths = changed.filter((path) => {
|
|
342
|
-
const absolute = resolve2(cwd, path);
|
|
343
|
-
return importPathAllowed(absolute) && importReadAllowed(absolute, allowed) && (!existsSync(absolute) || importPathAllowed(realpathSync(absolute)));
|
|
344
|
-
});
|
|
345
|
-
if (paths.length) patch = git(cwd, "diff", "HEAD", "--no-color", "--no-ext-diff", "--no-textconv", "--relative", "--", ...paths) || null;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return {
|
|
349
|
-
manifest: {
|
|
350
|
-
format: "agentsky.import-workspace",
|
|
351
|
-
format_version: 1,
|
|
352
|
-
harness,
|
|
353
|
-
title: title?.trim().slice(0, 120) || null,
|
|
354
|
-
cwd: cwd ? cwd.replace(home, "~") : null,
|
|
355
|
-
project: cwd ? basename2(root ?? cwd) : null,
|
|
356
|
-
git: gitState,
|
|
357
|
-
tree: tree.slice(0, MAX_TREE),
|
|
358
|
-
tree_truncated: tree.length > MAX_TREE,
|
|
359
|
-
skills: [...skills.found.map((skill) => ({ name: skill.name, found: true })), ...skills.missing.map((name) => ({ name, found: false }))],
|
|
360
|
-
mcp_servers: mcpServers(harness, cwd, home, allowed)
|
|
361
|
-
},
|
|
362
|
-
patch
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function skillFiles(skill, allowed) {
|
|
366
|
-
const out = [];
|
|
367
|
-
const walk = (dir, depth) => {
|
|
368
|
-
if (depth > 8 || out.length > 400 || !importReadAllowed(dir, allowed)) return;
|
|
369
|
-
let entries;
|
|
370
|
-
try {
|
|
371
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
372
|
-
} catch {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
for (const entry of entries) {
|
|
376
|
-
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === "__pycache__" || entry.name === ".venv") continue;
|
|
377
|
-
const path = join2(dir, entry.name);
|
|
378
|
-
if (entry.isDirectory()) walk(path, depth + 1);
|
|
379
|
-
else if (entry.isFile() && importReadAllowed(path, allowed)) out.push({ path, name: `skills/${skill.name}/${relative(skill.dir, path).split(sep).join("/")}` });
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
if (existsSync(skill.dir)) walk(skill.dir, 0);
|
|
383
|
-
return out;
|
|
384
|
-
}
|
|
385
|
-
function codexThreadName(sessionId, home = homedir()) {
|
|
386
|
-
let name = null;
|
|
387
|
-
try {
|
|
388
|
-
for (const line of readFileSync2(join2(process.env.CODEX_HOME ?? join2(home, ".codex"), "session_index.jsonl"), "utf8").split("\n")) {
|
|
389
|
-
if (!line.includes(sessionId)) continue;
|
|
390
|
-
try {
|
|
391
|
-
const entry = JSON.parse(line);
|
|
392
|
-
if (entry.id === sessionId && typeof entry.thread_name === "string" && entry.thread_name.trim()) name = entry.thread_name.trim();
|
|
393
|
-
} catch {
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
} catch {
|
|
397
|
-
}
|
|
398
|
-
return name;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
export {
|
|
402
|
-
importReadAllowed,
|
|
403
|
-
importPathAllowed,
|
|
404
|
-
repositoryRoot,
|
|
405
|
-
sharedInstructionPaths,
|
|
406
|
-
loadedSkills,
|
|
407
|
-
workspaceState,
|
|
408
|
-
skillFiles,
|
|
409
|
-
codexThreadName,
|
|
410
|
-
SINGLE_REQUEST_MAX_BYTES,
|
|
411
|
-
transfer,
|
|
412
|
-
uploadLargeFile
|
|
413
|
-
};
|