@agentsky/sky 3.42.0 → 3.43.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/{chunk-ALJRHTMX.js → chunk-44XF4EGE.js} +2 -108
- package/dist/chunk-4A4PDUT5.js +8 -0
- package/dist/{trace-ZZLFGVWA.js → chunk-4MVM65ET.js} +23 -21
- package/dist/chunk-AB7SUDX4.js +413 -0
- package/dist/{chunk-YY2ZSZDH.js → chunk-BIZJ4VZL.js} +8 -10
- package/dist/chunk-J3KIEZXM.js +761 -0
- package/dist/chunk-OKNWK75U.js +745 -0
- package/dist/chunk-UJ7IXSJX.js +404 -0
- package/dist/index.js +2732 -2717
- package/dist/local-skills-AVLHV36B.js +27 -0
- package/dist/local-skills-run-UJK4ZO4P.js +49 -0
- package/dist/trace-H3FVIFE3.js +54 -0
- package/dist/trace-exclusions-MYECULMA.js +20 -0
- package/dist/{trace-library-536NQQJJ.js → trace-library-XLBJHI3I.js} +576 -413
- package/package.json +2 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
USER_AGENT
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4A4PDUT5.js";
|
|
4
4
|
import {
|
|
5
5
|
apiBase,
|
|
6
6
|
apiToken,
|
|
7
|
-
configPath,
|
|
8
7
|
currentUniverse
|
|
9
8
|
} from "./chunk-XHZJG3QT.js";
|
|
10
9
|
|
|
@@ -197,108 +196,6 @@ async function apiRaw(method, path, init = {}) {
|
|
|
197
196
|
});
|
|
198
197
|
}
|
|
199
198
|
|
|
200
|
-
// src/resumable-upload.ts
|
|
201
|
-
import { createHash } from "crypto";
|
|
202
|
-
import { mkdirSync, openSync, readFileSync, readSync, closeSync, rmSync, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
203
|
-
import { basename, dirname, join, resolve } from "path";
|
|
204
|
-
var SINGLE_REQUEST_MAX_BYTES = 32 * 1024 * 1024;
|
|
205
|
-
var MAX_ATTEMPTS = 8;
|
|
206
|
-
function statePath(path, size, mtimeMs, universe) {
|
|
207
|
-
const key = createHash("sha256").update(`${resolve(path)}\0${size}\0${mtimeMs}\0${universe ?? ""}`).digest("hex").slice(0, 32);
|
|
208
|
-
return join(dirname(configPath()), "uploads", `${key}.json`);
|
|
209
|
-
}
|
|
210
|
-
function loadSession(file, expiresInSeconds, universe) {
|
|
211
|
-
try {
|
|
212
|
-
const saved = JSON.parse(readFileSync(file, "utf8"));
|
|
213
|
-
if (saved.expiresInSeconds !== expiresInSeconds || saved.universe !== universe) return null;
|
|
214
|
-
if (Date.parse(saved.expires_at) - Date.now() < 3600 * 1e3) return null;
|
|
215
|
-
return saved;
|
|
216
|
-
} catch {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function acknowledged(res) {
|
|
221
|
-
const range = res.headers.get("range")?.match(/^bytes=0-(\d+)$/);
|
|
222
|
-
return range ? Number(range[1]) + 1 : 0;
|
|
223
|
-
}
|
|
224
|
-
async function probe(session) {
|
|
225
|
-
const res = await fetch(session.upload_url, {
|
|
226
|
-
method: "PUT",
|
|
227
|
-
headers: { "user-agent": USER_AGENT, "content-range": `bytes */${session.size_bytes}` }
|
|
228
|
-
});
|
|
229
|
-
if (res.status === 200 || res.status === 201) return "done";
|
|
230
|
-
if (res.status === 308) return acknowledged(res);
|
|
231
|
-
if (res.status === 404 || res.status === 410) throw new ApiError(res.status, "upload_expired", "the upload session is gone");
|
|
232
|
-
throw new ApiError(res.status, "upload_failed", `upload status check failed: ${res.status} ${res.statusText}`);
|
|
233
|
-
}
|
|
234
|
-
async function sendChunk(session, fd, offset) {
|
|
235
|
-
const length = Math.min(session.chunk_size, session.size_bytes - offset);
|
|
236
|
-
const chunk = Buffer.alloc(length);
|
|
237
|
-
let read = 0;
|
|
238
|
-
while (read < length) read += readSync(fd, chunk, read, length - read, offset + read);
|
|
239
|
-
const res = await fetch(session.upload_url, {
|
|
240
|
-
method: "PUT",
|
|
241
|
-
headers: {
|
|
242
|
-
"user-agent": USER_AGENT,
|
|
243
|
-
"content-range": `bytes ${offset}-${offset + length - 1}/${session.size_bytes}`
|
|
244
|
-
},
|
|
245
|
-
body: chunk
|
|
246
|
-
});
|
|
247
|
-
if (res.status === 200 || res.status === 201) return "done";
|
|
248
|
-
if (res.status === 308) return acknowledged(res);
|
|
249
|
-
if (res.status >= 500 || res.status === 429) throw new Error(`transient ${res.status}`);
|
|
250
|
-
throw new ApiError(res.status, "upload_failed", `chunk upload failed: ${res.status} ${(await res.text()).slice(0, 200)}`);
|
|
251
|
-
}
|
|
252
|
-
async function transfer(session, path, onProgress) {
|
|
253
|
-
const fd = openSync(path, "r");
|
|
254
|
-
try {
|
|
255
|
-
let failures = 0;
|
|
256
|
-
let state = await probe(session);
|
|
257
|
-
while (state !== "done") {
|
|
258
|
-
onProgress(state, session.size_bytes);
|
|
259
|
-
try {
|
|
260
|
-
state = await sendChunk(session, fd, state);
|
|
261
|
-
failures = 0;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
if (error instanceof ApiError || ++failures >= MAX_ATTEMPTS) throw error;
|
|
264
|
-
await new Promise((done) => setTimeout(done, Math.min(3e4, 500 * 2 ** failures)));
|
|
265
|
-
state = await probe(session);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
onProgress(session.size_bytes, session.size_bytes);
|
|
269
|
-
} finally {
|
|
270
|
-
closeSync(fd);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async function uploadLargeFile(path, mediaType, expiresInSeconds, onProgress, universe) {
|
|
274
|
-
const { size, mtimeMs } = statSync(path);
|
|
275
|
-
const stateFile = statePath(path, size, mtimeMs, universe);
|
|
276
|
-
let session = loadSession(stateFile, expiresInSeconds, universe);
|
|
277
|
-
if (session) {
|
|
278
|
-
try {
|
|
279
|
-
await probe(session);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
if (!(error instanceof ApiError) || error.status !== 404 && error.status !== 410) throw error;
|
|
282
|
-
session = null;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (!session) {
|
|
286
|
-
session = await api("POST", "/files/uploads", {
|
|
287
|
-
filename: basename(path),
|
|
288
|
-
size_bytes: size,
|
|
289
|
-
mime_type: mediaType,
|
|
290
|
-
...expiresInSeconds ? { expires_in_seconds: expiresInSeconds } : {}
|
|
291
|
-
}, { universe });
|
|
292
|
-
mkdirSync(dirname(stateFile), { recursive: true });
|
|
293
|
-
const saved = { ...session, path: resolve(path), mtimeMs, expiresInSeconds, universe };
|
|
294
|
-
writeFileSync2(stateFile, JSON.stringify(saved), { mode: 384 });
|
|
295
|
-
}
|
|
296
|
-
await transfer(session, path, onProgress);
|
|
297
|
-
const file = await api("POST", `/files/uploads/${encodeURIComponent(session.id)}/complete`, void 0, { universe });
|
|
298
|
-
rmSync(stateFile, { force: true });
|
|
299
|
-
return file;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
199
|
export {
|
|
303
200
|
ApiError,
|
|
304
201
|
parseError,
|
|
@@ -311,8 +208,5 @@ export {
|
|
|
311
208
|
apiBytes,
|
|
312
209
|
resolveSessionRef,
|
|
313
210
|
streamEvents,
|
|
314
|
-
apiRaw
|
|
315
|
-
SINGLE_REQUEST_MAX_BYTES,
|
|
316
|
-
transfer,
|
|
317
|
-
uploadLargeFile
|
|
211
|
+
apiRaw
|
|
318
212
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TRACE_CONTENT_SCOPES,
|
|
3
|
-
USER_AGENT,
|
|
4
3
|
redactTraceText
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BIZJ4VZL.js";
|
|
5
|
+
import {
|
|
6
|
+
USER_AGENT
|
|
7
|
+
} from "./chunk-4A4PDUT5.js";
|
|
6
8
|
import {
|
|
7
9
|
configPath
|
|
8
10
|
} from "./chunk-XHZJG3QT.js";
|
|
9
|
-
import "./chunk-MLKGABMK.js";
|
|
10
11
|
|
|
11
12
|
// src/trace.ts
|
|
12
13
|
import { randomBytes } from "crypto";
|
|
@@ -348,28 +349,29 @@ function chosenPaths(files, dirs) {
|
|
|
348
349
|
};
|
|
349
350
|
return { files: files.map((path) => check(path, "file")), dirs: dirs.map((path) => check(path, "folder")) };
|
|
350
351
|
}
|
|
352
|
+
|
|
351
353
|
export {
|
|
352
|
-
BATCH_MAX,
|
|
353
|
-
FinalRefusal,
|
|
354
|
-
RETRY_WINDOW_MS,
|
|
355
354
|
SPOOL_MAX_BYTES,
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
contentEvent,
|
|
360
|
-
contentForClaudeHook,
|
|
361
|
-
eventsForClaudeHook,
|
|
362
|
-
fileAllowed,
|
|
363
|
-
fileEvent,
|
|
364
|
-
flush,
|
|
365
|
-
grantSender,
|
|
366
|
-
installClaudeHooks,
|
|
367
|
-
parseContentScopes,
|
|
355
|
+
RETRY_WINDOW_MS,
|
|
356
|
+
BATCH_MAX,
|
|
357
|
+
traceDir,
|
|
368
358
|
readState,
|
|
359
|
+
writeState,
|
|
360
|
+
clearState,
|
|
361
|
+
stamp,
|
|
369
362
|
record,
|
|
363
|
+
grantSender,
|
|
364
|
+
FinalRefusal,
|
|
365
|
+
flush,
|
|
370
366
|
spoolStatus,
|
|
371
|
-
|
|
372
|
-
|
|
367
|
+
eventsForClaudeHook,
|
|
368
|
+
claudeHooksConfig,
|
|
369
|
+
installClaudeHooks,
|
|
373
370
|
uninstallClaudeHooks,
|
|
374
|
-
|
|
371
|
+
parseContentScopes,
|
|
372
|
+
fileAllowed,
|
|
373
|
+
contentEvent,
|
|
374
|
+
fileEvent,
|
|
375
|
+
contentForClaudeHook,
|
|
376
|
+
chosenPaths
|
|
375
377
|
};
|
|
@@ -0,0 +1,413 @@
|
|
|
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
|
+
};
|