@agentsky/sky 3.48.2 → 3.49.1
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-A45NGV2Q.js → chunk-4O5BYMBY.js} +2 -2
- package/dist/chunk-BKNZQZZD.js +857 -0
- package/dist/{chunk-UJS4JIE2.js → chunk-EIIYZVDB.js} +10 -10
- package/dist/{chunk-ZF2P6PKM.js → chunk-GITJNXCT.js} +2 -2
- package/dist/{chunk-OJ5ERABF.js → chunk-IO2N34S2.js} +1 -1
- package/dist/{chunk-FVIPGI3E.js → chunk-J5Y3GBFE.js} +5 -5
- package/dist/{chunk-ZRV3UUW5.js → chunk-KAUYD6LR.js} +1 -1
- package/dist/{chunk-NAIYHS6Q.js → chunk-ONI4XI52.js} +2 -1
- package/dist/{chunk-PGX3AGCZ.js → chunk-OPV2FXUQ.js} +1 -1
- package/dist/{chunk-CV2ZRIF7.js → chunk-PO4BEXQ7.js} +4 -4
- package/dist/chunk-TGU7T4O7.js +1363 -0
- package/dist/{chunk-6D36IT7T.js → chunk-UZ7DE7B4.js} +2 -2
- package/dist/{chunk-RKMMLSGJ.js → chunk-WOTYAQGN.js} +1 -1
- package/dist/{chunk-W24YSGH4.js → chunk-X77A5HMO.js} +7 -856
- package/dist/{chunk-NJPIE762.js → chunk-YHO5UDFS.js} +43 -24
- package/dist/chunk-YO2XUCCF.js +30 -0
- package/dist/{compute-AERPKXJ3.js → compute-XAJFVSFL.js} +2 -2
- package/dist/{compute-report-CTT4WBSQ.js → compute-report-GKDPX4XS.js} +15 -13
- package/dist/grok-bot-export-7LSTXWJW.js +57 -0
- package/dist/index.js +603 -1770
- package/dist/{local-skills-E56TR7O6.js → local-skills-MTVILHBQ.js} +3 -3
- package/dist/{local-skills-run-TST44QSA.js → local-skills-run-DPAEXDNS.js} +9 -9
- package/dist/{mcp-register-HDOVT4QT.js → mcp-register-W7EVHT6T.js} +3 -3
- package/dist/{mcp-serve-2LBAEAJX.js → mcp-serve-QTQXSRME.js} +6 -6
- package/dist/{trace-S2XZC75N.js → trace-CMWC4LFX.js} +4 -3
- package/dist/{trace-exclusions-JEGMUPWQ.js → trace-exclusions-2KLVHVSW.js} +3 -2
- package/dist/trace-handoff-CD5LOS7B.js +116 -0
- package/dist/{trace-library-HN5TU5EJ.js → trace-library-XVUYQB5X.js} +14 -8
- package/dist/trace-privacy-DU3TL5EO.js +11 -0
- package/package.json +1 -1
- package/vendor/trace-collect/SOURCE.json +2 -1
- package/vendor/trace-collect/sources/_pii.mjs +56 -0
- package/vendor/trace-collect/sources/grok-bot.mjs +180 -0
- package/vendor/trace-collect/sources/index.mjs +4 -2
- package/vendor/trace-collect/sources/muse-agent.mjs +95 -0
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
skyCommand,
|
|
18
18
|
takeBack,
|
|
19
19
|
waitForAnswer
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-EIIYZVDB.js";
|
|
21
21
|
import {
|
|
22
22
|
SINGLE_REQUEST_MAX_BYTES,
|
|
23
23
|
codexThreadName,
|
|
@@ -30,14 +30,19 @@ import {
|
|
|
30
30
|
transfer,
|
|
31
31
|
uploadLargeFile,
|
|
32
32
|
workspaceState
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-YHO5UDFS.js";
|
|
34
|
+
import "./chunk-IO2N34S2.js";
|
|
34
35
|
import {
|
|
35
36
|
SetupJournal,
|
|
36
37
|
TOKEN_ENV,
|
|
37
38
|
shellEnvFiles,
|
|
38
39
|
shellStartupFiles,
|
|
39
40
|
writeShellEnv
|
|
40
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-UZ7DE7B4.js";
|
|
42
|
+
import {
|
|
43
|
+
convertSession,
|
|
44
|
+
isEngine
|
|
45
|
+
} from "./chunk-TGU7T4O7.js";
|
|
41
46
|
import {
|
|
42
47
|
SHELL_AGENT,
|
|
43
48
|
agentKeysPath,
|
|
@@ -46,7 +51,7 @@ import {
|
|
|
46
51
|
runsUnattended,
|
|
47
52
|
shortToolCount,
|
|
48
53
|
wantsInteractiveClientKey
|
|
49
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-PO4BEXQ7.js";
|
|
50
55
|
import {
|
|
51
56
|
addPolicy,
|
|
52
57
|
deleteWorkspace,
|
|
@@ -70,7 +75,7 @@ import {
|
|
|
70
75
|
withoutSettingsBlock,
|
|
71
76
|
workspaceSlug,
|
|
72
77
|
writeSettingsBlocks
|
|
73
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-4O5BYMBY.js";
|
|
74
79
|
import {
|
|
75
80
|
ApiError,
|
|
76
81
|
api,
|
|
@@ -84,7 +89,7 @@ import {
|
|
|
84
89
|
streamEvents,
|
|
85
90
|
uploadFile,
|
|
86
91
|
writeResponseFile
|
|
87
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-ONI4XI52.js";
|
|
88
93
|
import {
|
|
89
94
|
NO_TOOLS,
|
|
90
95
|
detectClaudeApp,
|
|
@@ -96,36 +101,13 @@ import {
|
|
|
96
101
|
refreshMcpRegistrations,
|
|
97
102
|
registerMcpServer,
|
|
98
103
|
systemCommandRunner
|
|
99
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-WOTYAQGN.js";
|
|
100
105
|
import {
|
|
101
106
|
detectLocalAgents,
|
|
102
107
|
selectLocalAgents
|
|
103
108
|
} from "./chunk-2H4W5ZKZ.js";
|
|
104
|
-
import "./chunk-
|
|
105
|
-
import
|
|
106
|
-
skillTargets,
|
|
107
|
-
syncLocalSkills
|
|
108
|
-
} from "./chunk-ZF2P6PKM.js";
|
|
109
|
-
import {
|
|
110
|
-
SKILL_NAME,
|
|
111
|
-
installSkill,
|
|
112
|
-
isInstalledSkill,
|
|
113
|
-
skillPaths
|
|
114
|
-
} from "./chunk-PGX3AGCZ.js";
|
|
115
|
-
import {
|
|
116
|
-
apiBase,
|
|
117
|
-
apiToken,
|
|
118
|
-
configPath,
|
|
119
|
-
consoleBase,
|
|
120
|
-
currentUniverse,
|
|
121
|
-
loadConfig,
|
|
122
|
-
saveConfig
|
|
123
|
-
} from "./chunk-XHZJG3QT.js";
|
|
124
|
-
import {
|
|
125
|
-
CLI_VERSION,
|
|
126
|
-
USER_AGENT
|
|
127
|
-
} from "./chunk-ZRV3UUW5.js";
|
|
128
|
-
import "./chunk-OJ5ERABF.js";
|
|
109
|
+
import "./chunk-YO2XUCCF.js";
|
|
110
|
+
import "./chunk-J5Y3GBFE.js";
|
|
129
111
|
import {
|
|
130
112
|
AGENT_TYPES,
|
|
131
113
|
MODEL_SUBSCRIPTION_PLAN_PHRASE,
|
|
@@ -144,14 +126,38 @@ import {
|
|
|
144
126
|
modelSubscriptionProviderFor,
|
|
145
127
|
preinstalledManifest,
|
|
146
128
|
reasoningEffortDocLine,
|
|
147
|
-
redactLine,
|
|
148
|
-
redactPlainText,
|
|
149
|
-
redactSecretValues,
|
|
150
129
|
splitMcpServers,
|
|
151
130
|
storeSkillRefSchema,
|
|
152
|
-
supersededBy
|
|
153
|
-
|
|
154
|
-
|
|
131
|
+
supersededBy
|
|
132
|
+
} from "./chunk-X77A5HMO.js";
|
|
133
|
+
import {
|
|
134
|
+
redactLine,
|
|
135
|
+
redactPlainText,
|
|
136
|
+
redactSecretValues
|
|
137
|
+
} from "./chunk-BKNZQZZD.js";
|
|
138
|
+
import {
|
|
139
|
+
skillTargets,
|
|
140
|
+
syncLocalSkills
|
|
141
|
+
} from "./chunk-GITJNXCT.js";
|
|
142
|
+
import {
|
|
143
|
+
SKILL_NAME,
|
|
144
|
+
installSkill,
|
|
145
|
+
isInstalledSkill,
|
|
146
|
+
skillPaths
|
|
147
|
+
} from "./chunk-OPV2FXUQ.js";
|
|
148
|
+
import {
|
|
149
|
+
apiBase,
|
|
150
|
+
apiToken,
|
|
151
|
+
configPath,
|
|
152
|
+
consoleBase,
|
|
153
|
+
currentUniverse,
|
|
154
|
+
loadConfig,
|
|
155
|
+
saveConfig
|
|
156
|
+
} from "./chunk-XHZJG3QT.js";
|
|
157
|
+
import {
|
|
158
|
+
CLI_VERSION,
|
|
159
|
+
USER_AGENT
|
|
160
|
+
} from "./chunk-KAUYD6LR.js";
|
|
155
161
|
import "./chunk-MLKGABMK.js";
|
|
156
162
|
|
|
157
163
|
// src/session-show.ts
|
|
@@ -416,7 +422,10 @@ var administrationArgumentSchemas = {
|
|
|
416
422
|
device_save_arena_chart: chartSource,
|
|
417
423
|
device_configure_local_sync: syncArguments,
|
|
418
424
|
device_relaunch: empty,
|
|
419
|
-
device_restart_to_update: empty
|
|
425
|
+
device_restart_to_update: empty,
|
|
426
|
+
device_permission_state: empty,
|
|
427
|
+
device_request_permission: external_exports.object({ permission: external_exports.enum(["screen_recording", "accessibility", "keychain"]), waitSeconds: external_exports.number().int().min(0).max(50).optional() }).strict(),
|
|
428
|
+
device_set_chat_permission_mode: external_exports.object({ chatId: external_exports.string().min(1).max(200), mode: external_exports.enum(["bypass", "auto", "manual"]) }).strict()
|
|
420
429
|
};
|
|
421
430
|
var administrationOperations = [
|
|
422
431
|
"legacy_drafts_list",
|
|
@@ -438,7 +447,10 @@ var administrationOperations = [
|
|
|
438
447
|
"device_save_arena_chart",
|
|
439
448
|
"device_configure_local_sync",
|
|
440
449
|
"device_relaunch",
|
|
441
|
-
"device_restart_to_update"
|
|
450
|
+
"device_restart_to_update",
|
|
451
|
+
"device_permission_state",
|
|
452
|
+
"device_request_permission",
|
|
453
|
+
"device_set_chat_permission_mode"
|
|
442
454
|
];
|
|
443
455
|
var administrationOperationSchema = external_exports.enum(administrationOperations);
|
|
444
456
|
var administrationRequestIdSchema = external_exports.string().regex(/^[A-Za-z0-9_-]{16,200}$/);
|
|
@@ -448,6 +460,7 @@ function parseAdministrationCall(operation, input) {
|
|
|
448
460
|
}
|
|
449
461
|
|
|
450
462
|
// src/mac-administration.ts
|
|
463
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
451
464
|
function registerMacAdministrationCommands(mac2) {
|
|
452
465
|
mac2.command("administration <machine> <operation>").description("invoke an exact native owner operation; requires your unrestricted account-wide admin key").option("--arguments <json>", "operation arguments matching its published schema", "{}").requiredOption("--request-id <id>", "stable operation identity; reuse on retry").option("--workspace <slug>", "checked operation context; does not grant account-owner authority").option("--personal-workspace", "explicitly select your default workspace").addHelpText("after", `
|
|
453
466
|
Exact operations:
|
|
@@ -467,6 +480,16 @@ Sign-out, relaunch and restart-to-update return pending admission, not completed
|
|
|
467
480
|
const result = await api("POST", `/desktop/machines/${encodeURIComponent(machine)}/administration/${encodeURIComponent(operation)}${query}`, input);
|
|
468
481
|
console.log(JSON.stringify(result, null, 2));
|
|
469
482
|
});
|
|
483
|
+
const administer = async (machine, operation, args) => {
|
|
484
|
+
const input = parseAdministrationCall(operation, { arguments: args, request_id: `sky_${randomUUID2().replace(/-/g, "")}` });
|
|
485
|
+
return api("POST", `/desktop/machines/${encodeURIComponent(machine)}/administration/${operation}`, input);
|
|
486
|
+
};
|
|
487
|
+
mac2.command("permissions <machine>").description("read whether the Mac app has Screen Recording and Accessibility, and whether it waits on Keychain access").action(async (machine) => console.log(JSON.stringify(await administer(machine, "device_permission_state", {}), null, 2)));
|
|
488
|
+
mac2.command("request-permission <machine> <permission>").description("make the Mac app ask macOS for screen_recording, accessibility or keychain; the person answers the dialog on the Mac").option("--wait <seconds>", "how long to wait for their answer (0-50)", "30").action(async (machine, permission, options) => {
|
|
489
|
+
const result = await administer(machine, "device_request_permission", { permission, waitSeconds: Number.parseInt(options.wait, 10) });
|
|
490
|
+
console.log(JSON.stringify(result, null, 2));
|
|
491
|
+
});
|
|
492
|
+
mac2.command("chat-mode <machine> <chat> <mode>").description("set one of your local chats on the Mac to bypass, auto or manual; a looser mode waits for the person to allow it on the Mac").action(async (machine, chatId, mode) => console.log(JSON.stringify(await administer(machine, "device_set_chat_permission_mode", { chatId, mode }), null, 2)));
|
|
470
493
|
}
|
|
471
494
|
|
|
472
495
|
// src/mac-sign-in.ts
|
|
@@ -497,10 +520,10 @@ async function localMacAuthRequest(socketPath, path2, body) {
|
|
|
497
520
|
return new Promise((done, reject) => {
|
|
498
521
|
const req = request2({ socketPath, path: path2, method: body === void 0 ? "GET" : "POST", headers: body === void 0 ? {} : { "content-type": "application/json", "content-length": Buffer.byteLength(body) } }, (res) => {
|
|
499
522
|
const chunks = [];
|
|
500
|
-
let
|
|
523
|
+
let size = 0;
|
|
501
524
|
res.on("data", (chunk) => {
|
|
502
|
-
|
|
503
|
-
if (
|
|
525
|
+
size += chunk.length;
|
|
526
|
+
if (size > LIMIT) {
|
|
504
527
|
req.destroy();
|
|
505
528
|
reject(new Error("Local authentication response too large"));
|
|
506
529
|
} else chunks.push(chunk);
|
|
@@ -523,11 +546,11 @@ async function localMacAuthRequest(socketPath, path2, body) {
|
|
|
523
546
|
async function readMacSignInKey(input, isTTY = false) {
|
|
524
547
|
if (isTTY) throw new Error("Pipe a key from your credential loader; interactive key input is not accepted");
|
|
525
548
|
const chunks = [];
|
|
526
|
-
let
|
|
549
|
+
let size = 0;
|
|
527
550
|
for await (const chunk of input) {
|
|
528
551
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
529
|
-
|
|
530
|
-
if (
|
|
552
|
+
size += buffer.length;
|
|
553
|
+
if (size > 4098) throw new Error("Key input too large");
|
|
531
554
|
chunks.push(buffer);
|
|
532
555
|
}
|
|
533
556
|
const key = Buffer.concat(chunks).toString("utf8").trim();
|
|
@@ -621,7 +644,7 @@ function registerMacAutomationCommands(mac2) {
|
|
|
621
644
|
}
|
|
622
645
|
|
|
623
646
|
// src/mac-control.ts
|
|
624
|
-
import { randomUUID as
|
|
647
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
625
648
|
var controllers = (machine) => `/desktop/machines/${encodeURIComponent(machine)}/controllers`;
|
|
626
649
|
function registerMacControlCommands(mac2) {
|
|
627
650
|
const print = (value) => console.log(JSON.stringify(value, null, 2));
|
|
@@ -639,15 +662,15 @@ function registerMacControlCommands(mac2) {
|
|
|
639
662
|
print({ removed: controller });
|
|
640
663
|
});
|
|
641
664
|
mac2.command("stop <session>").description("stop a chat running on your Mac (this key must be paired with it)").option("--request-id <id>", "stable retry identity; a retry stops once").action(async (session2, options) => {
|
|
642
|
-
print(await api("POST", `/desktop/sessions/${encodeURIComponent(session2)}/stop`, { request_id: options.requestId ??
|
|
665
|
+
print(await api("POST", `/desktop/sessions/${encodeURIComponent(session2)}/stop`, { request_id: options.requestId ?? randomUUID3(), surface: "api" }));
|
|
643
666
|
});
|
|
644
667
|
mac2.command("start <text>").description("start a new chat on your newest online Mac with your own Claude Code or Codex (this key must be paired with it); the Mac picks the folder from the request").option("--agent <agent>", "claude_code or codex", "claude_code").option("--repository <owner/name>", "the GitHub repository the task is about, to find its folder").option("--request-id <id>", "stable retry identity; a retry starts it once").action(async (text2, options) => {
|
|
645
668
|
if (options.agent !== "claude_code" && options.agent !== "codex") throw new Error("agent must be claude_code or codex");
|
|
646
|
-
print(await api("POST", "/desktop/chats", { text: text2, request_id: options.requestId ??
|
|
669
|
+
print(await api("POST", "/desktop/chats", { text: text2, request_id: options.requestId ?? randomUUID3(), agent: options.agent, ...options.repository ? { repository: options.repository } : {}, surface: "api" }));
|
|
647
670
|
});
|
|
648
671
|
mac2.command("answer <session> <prompt> <decision>").description("allow or deny a command a chat on your Mac waits on; keychain commands are answered on the Mac only").option("--request-id <id>", "stable retry identity; a retry answers once").action(async (session2, prompt, decision, options) => {
|
|
649
672
|
if (decision !== "allow" && decision !== "deny") throw new Error("decision must be allow or deny");
|
|
650
|
-
print(await api("POST", `/desktop/sessions/${encodeURIComponent(session2)}/prompts/${encodeURIComponent(prompt)}/answer`, { request_id: options.requestId ??
|
|
673
|
+
print(await api("POST", `/desktop/sessions/${encodeURIComponent(session2)}/prompts/${encodeURIComponent(prompt)}/answer`, { request_id: options.requestId ?? randomUUID3(), decision, surface: "api" }));
|
|
651
674
|
});
|
|
652
675
|
}
|
|
653
676
|
|
|
@@ -768,13 +791,13 @@ var cost = (money) => money ? `, $${money.amount}` : "";
|
|
|
768
791
|
function renderSearch(search) {
|
|
769
792
|
if (search.status === "running") return `${search.id} running
|
|
770
793
|
still running: run the same search again with --request-id ${search.request_id}`;
|
|
771
|
-
const
|
|
772
|
-
if (search.answer)
|
|
773
|
-
for (const result of search.results)
|
|
794
|
+
const lines = [`${search.endpoint}${cost(search.cost)}${search.filtered ? `, ${search.filtered} non-public results dropped` : ""}`];
|
|
795
|
+
if (search.answer) lines.push(search.answer, "");
|
|
796
|
+
for (const result of search.results) lines.push(`${result.rank}. ${result.title ?? result.url}
|
|
774
797
|
${result.url}${result.snippet ? `
|
|
775
798
|
${result.snippet}` : ""}`);
|
|
776
|
-
if (search.truncated)
|
|
777
|
-
return
|
|
799
|
+
if (search.truncated) lines.push("(more results: raise --limit)");
|
|
800
|
+
return lines.join("\n");
|
|
778
801
|
}
|
|
779
802
|
function renderJob(job) {
|
|
780
803
|
const head = `${job.id} ${job.status}${cost(job.cost)}`;
|
|
@@ -838,7 +861,7 @@ async function deploy(name, dir, opts = {}) {
|
|
|
838
861
|
|
|
839
862
|
// src/site-domains.ts
|
|
840
863
|
function domainLines(domain) {
|
|
841
|
-
return [`${domain.hostname} ${domain.status}`, ...domain.records.map((
|
|
864
|
+
return [`${domain.hostname} ${domain.status}`, ...domain.records.map((record) => ` ${record.type.padEnd(5)} ${record.name} ${record.value}`)];
|
|
842
865
|
}
|
|
843
866
|
async function addDomain(name, hostname3) {
|
|
844
867
|
return api("POST", `/sites/${encodeURIComponent(name)}/domains`, { hostname: hostname3 });
|
|
@@ -878,7 +901,7 @@ function registerEmailCommands(emailCommand2) {
|
|
|
878
901
|
// src/plugins.ts
|
|
879
902
|
import { chmodSync, lstatSync as lstatSync3, mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
880
903
|
import { basename as basename2, dirname as dirname2, isAbsolute, resolve as resolve3, sep as sep2 } from "path";
|
|
881
|
-
import { randomUUID as
|
|
904
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
882
905
|
|
|
883
906
|
// src/skills-store.ts
|
|
884
907
|
import { readdirSync as readdirSync2, readFileSync as readFileSync5, statSync } from "fs";
|
|
@@ -1257,10 +1280,10 @@ async function answerPlugin(id2, where) {
|
|
|
1257
1280
|
return api("PUT", `/plugins/${encodeURIComponent(id2)}/answer`, { ...target(where), ...where.connection ? { connection_id: where.connection } : {} });
|
|
1258
1281
|
}
|
|
1259
1282
|
function renderAdd(answer) {
|
|
1260
|
-
const
|
|
1261
|
-
if (answer.next?.url)
|
|
1262
|
-
for (const step of answer.next?.steps ?? [])
|
|
1263
|
-
return
|
|
1283
|
+
const lines = [answer.status === "added" ? `Added ${answer.plugin_id}.` : `${answer.plugin_id} needs you to finish:`];
|
|
1284
|
+
if (answer.next?.url) lines.push(` open ${answer.next.url}`);
|
|
1285
|
+
for (const step of answer.next?.steps ?? []) lines.push(` ${step}`);
|
|
1286
|
+
return lines.join("\n");
|
|
1264
1287
|
}
|
|
1265
1288
|
async function requestPlugin(id2, session2) {
|
|
1266
1289
|
return api("POST", `/plugins/${encodeURIComponent(id2)}/request`, { session_id: session2 });
|
|
@@ -1291,16 +1314,16 @@ function renderPropose(answer) {
|
|
|
1291
1314
|
return `Proposed ${answer.draft_id} ${answer.revision}. The person answers on its card; end your turn, then propose again to finish.`;
|
|
1292
1315
|
}
|
|
1293
1316
|
function renderTest(answer) {
|
|
1294
|
-
const
|
|
1295
|
-
for (const result of answer.results)
|
|
1296
|
-
return
|
|
1317
|
+
const lines = [`${answer.id} ${answer.revision}: ${answer.status}`];
|
|
1318
|
+
for (const result of answer.results) lines.push(` ${result.passed ? "pass" : result.skipped ? "skip" : "fail"} ${result.sample}${result.reason ? `: ${result.reason}` : ""}${result.skipped ? `: ${result.skipped}` : ""}`);
|
|
1319
|
+
return lines.join("\n");
|
|
1297
1320
|
}
|
|
1298
1321
|
function renderDraft(answer) {
|
|
1299
|
-
const
|
|
1300
|
-
for (const [tool2, effect] of Object.entries(answer.effects))
|
|
1301
|
-
if (answer.problems.length === 0)
|
|
1302
|
-
for (const problem of answer.problems)
|
|
1303
|
-
return
|
|
1322
|
+
const lines = [`${answer.id} ${answer.name ?? answer.path} ${answer.revision}${answer.created ? " (new revision)" : ""}`];
|
|
1323
|
+
for (const [tool2, effect] of Object.entries(answer.effects)) lines.push(` tool ${tool2}: ${effect}`);
|
|
1324
|
+
if (answer.problems.length === 0) lines.push("No problems.");
|
|
1325
|
+
for (const problem of answer.problems) lines.push(` ${problem.path}: ${problem.message}`);
|
|
1326
|
+
return lines.join("\n");
|
|
1304
1327
|
}
|
|
1305
1328
|
function renderOff(answer) {
|
|
1306
1329
|
const where = answer.agent_id ? `agent ${answer.agent_id}` : `chat ${answer.session_id}`;
|
|
@@ -1311,26 +1334,26 @@ function statusWord(plugin) {
|
|
|
1311
1334
|
return plugin.status === "added" ? "" : ` ${PLUGIN_STATUS_LABEL[plugin.status].toLowerCase()}`;
|
|
1312
1335
|
}
|
|
1313
1336
|
function renderPluginList(list) {
|
|
1314
|
-
const
|
|
1315
|
-
for (const gap of list.unavailable)
|
|
1316
|
-
if (list.next_cursor)
|
|
1317
|
-
return
|
|
1337
|
+
const lines = list.data.map((plugin) => `${plugin.id} ${plugin.name} ${priceLine(plugin)}${statusWord(plugin)}`);
|
|
1338
|
+
for (const gap of list.unavailable) lines.push(`(${gap.message})`);
|
|
1339
|
+
if (list.next_cursor) lines.push(`more: --cursor ${list.next_cursor}`);
|
|
1340
|
+
return lines.length ? lines.join("\n") : "nothing here yet: sky plugins list --view discover";
|
|
1318
1341
|
}
|
|
1319
1342
|
function renderPlugin(plugin) {
|
|
1320
|
-
const
|
|
1343
|
+
const lines = [
|
|
1321
1344
|
`${plugin.name} (${plugin.id})`,
|
|
1322
1345
|
` ${[priceLine(plugin), PLUGIN_STATUS_LABEL[plugin.status], plugin.scope === "me" ? "yours" : "workspace"].filter(Boolean).join(" \xB7 ")}`
|
|
1323
1346
|
];
|
|
1324
|
-
if (plugin.description)
|
|
1325
|
-
if (plugin.mcp && plugin.mcp.url !== plugin.description)
|
|
1326
|
-
if (plugin.mcp)
|
|
1327
|
-
for (const gift of plugin.gives)
|
|
1328
|
-
for (const part of plugin.parts ?? [])
|
|
1329
|
-
for (const need of plugin.requires)
|
|
1330
|
-
if (plugin.next?.url)
|
|
1331
|
-
for (const step of plugin.next?.steps ?? [])
|
|
1332
|
-
for (const gap of plugin.unavailable)
|
|
1333
|
-
return
|
|
1347
|
+
if (plugin.description) lines.push(` ${plugin.description}`);
|
|
1348
|
+
if (plugin.mcp && plugin.mcp.url !== plugin.description) lines.push(` ${plugin.mcp.url}`);
|
|
1349
|
+
if (plugin.mcp) lines.push(` ${plugin.mcp.has_token ? "token saved" : "no token"}`);
|
|
1350
|
+
for (const gift of plugin.gives) lines.push(` gives ${gift.type}: ${gift.name}`);
|
|
1351
|
+
for (const part of plugin.parts ?? []) lines.push(` part ${PLUGIN_PART_LABEL[part.type].toLowerCase()}: ${part.name}${part.category ? ` (any ${part.category} app)` : ""}${part.status === "added" ? "" : ` ${part.status.replace("_", " ")}`}`);
|
|
1352
|
+
for (const need of plugin.requires) lines.push(` needs ${need.plugin_id}: ${need.reason}`);
|
|
1353
|
+
if (plugin.next?.url) lines.push(` finish at ${plugin.next.url}`);
|
|
1354
|
+
for (const step of plugin.next?.steps ?? []) lines.push(` next: ${step}`);
|
|
1355
|
+
for (const gap of plugin.unavailable) lines.push(` (${gap.message})`);
|
|
1356
|
+
return lines.join("\n");
|
|
1334
1357
|
}
|
|
1335
1358
|
async function pluginShares(id2, connection) {
|
|
1336
1359
|
const query = connection ? `?${new URLSearchParams({ connection_id: connection })}` : "";
|
|
@@ -1369,7 +1392,7 @@ async function callDeclaredPluginAction(id2, options) {
|
|
|
1369
1392
|
action_id: action.id,
|
|
1370
1393
|
session_id: options.session,
|
|
1371
1394
|
input: { ...action.input, ...options.input }
|
|
1372
|
-
}, { idempotencyKey: options.requestId ??
|
|
1395
|
+
}, { idempotencyKey: options.requestId ?? randomUUID4() });
|
|
1373
1396
|
}
|
|
1374
1397
|
async function connectionsThroughPlugins() {
|
|
1375
1398
|
const page = await listPluginResources({ view: "yours", source: "app", include: ["connections"] });
|
|
@@ -1408,10 +1431,10 @@ function writeExportFiles(dir, files2) {
|
|
|
1408
1431
|
}
|
|
1409
1432
|
return targets.map(({ file }) => file.path);
|
|
1410
1433
|
}
|
|
1411
|
-
async function runImport(
|
|
1412
|
-
if (
|
|
1434
|
+
async function runImport(plan, env = process.env) {
|
|
1435
|
+
if (plan.core) return [{ part: plan.core, result: "already_in_workspace", plugin_id: plan.core, detail: "AgentSky core plugins are in every workspace; switch it on in Plugins." }];
|
|
1413
1436
|
const results = [];
|
|
1414
|
-
for (const skill of
|
|
1437
|
+
for (const skill of plan.skills) {
|
|
1415
1438
|
try {
|
|
1416
1439
|
const uploaded = await uploadSkillPlugin(skill.dir, skill.name);
|
|
1417
1440
|
results.push({ part: `skills/${skill.name}`, result: "added", plugin_id: `skill:${uploaded.skill.id}` });
|
|
@@ -1419,7 +1442,7 @@ async function runImport(plan2, env = process.env) {
|
|
|
1419
1442
|
results.push({ part: `skills/${skill.name}`, result: "failed", detail: error instanceof Error ? error.message : String(error) });
|
|
1420
1443
|
}
|
|
1421
1444
|
}
|
|
1422
|
-
for (const server of
|
|
1445
|
+
for (const server of plan.servers) {
|
|
1423
1446
|
const token = server.tokenEnv ? env[server.tokenEnv] : void 0;
|
|
1424
1447
|
try {
|
|
1425
1448
|
const added = await addPlugin(void 0, { mcpUrl: server.url, name: server.name, ...token ? { token } : {} });
|
|
@@ -1521,18 +1544,18 @@ function recordedTools(records, cwd) {
|
|
|
1521
1544
|
const out = [];
|
|
1522
1545
|
let context2 = cwd;
|
|
1523
1546
|
records.forEach((raw, index) => {
|
|
1524
|
-
const
|
|
1525
|
-
if (!
|
|
1526
|
-
const payload = obj(
|
|
1527
|
-
if (
|
|
1528
|
-
const base = str(
|
|
1547
|
+
const record = obj(raw);
|
|
1548
|
+
if (!record) return;
|
|
1549
|
+
const payload = obj(record.payload);
|
|
1550
|
+
if (record.type === "turn_context" || record.type === "session_meta") context2 = str(payload?.cwd) || context2;
|
|
1551
|
+
const base = str(record.cwd) || context2;
|
|
1529
1552
|
const add = (name, input) => out.push({ name, input, cwd: str(obj(input)?.workdir) || str(obj(input)?.cwd) || base, record: index });
|
|
1530
|
-
const content = obj(
|
|
1531
|
-
if (
|
|
1553
|
+
const content = obj(record.message)?.content;
|
|
1554
|
+
if (record.type === "assistant" && Array.isArray(content)) for (const rawBlock of content) {
|
|
1532
1555
|
const block = obj(rawBlock);
|
|
1533
1556
|
if (block?.type === "tool_use") add(str(block.name), block.input);
|
|
1534
1557
|
}
|
|
1535
|
-
if (
|
|
1558
|
+
if (record.type === "response_item" && (payload?.type === "function_call" || payload?.type === "custom_tool_call")) {
|
|
1536
1559
|
let input = payload.arguments ?? payload.input ?? "";
|
|
1537
1560
|
if (typeof input === "string") {
|
|
1538
1561
|
try {
|
|
@@ -1745,11 +1768,11 @@ function collectSessionFiles(records, opts) {
|
|
|
1745
1768
|
leftOut.push({ path: path2, reason: "credential or build file" });
|
|
1746
1769
|
return;
|
|
1747
1770
|
}
|
|
1748
|
-
let
|
|
1771
|
+
let size;
|
|
1749
1772
|
try {
|
|
1750
1773
|
const stat = statSync2(path2);
|
|
1751
1774
|
if (!stat.isFile()) return;
|
|
1752
|
-
|
|
1775
|
+
size = stat.size;
|
|
1753
1776
|
} catch {
|
|
1754
1777
|
leftOut.push({ path: path2, reason: "missing" });
|
|
1755
1778
|
return;
|
|
@@ -1759,16 +1782,16 @@ function collectSessionFiles(records, opts) {
|
|
|
1759
1782
|
leftOut.push({ path: path2, reason: "unsupported type" });
|
|
1760
1783
|
return;
|
|
1761
1784
|
}
|
|
1762
|
-
if (
|
|
1785
|
+
if (size > MAX_ATTACHED_FILE_BYTES) {
|
|
1763
1786
|
leftOut.push({ path: path2, reason: "too large" });
|
|
1764
1787
|
return;
|
|
1765
1788
|
}
|
|
1766
|
-
candidates.push({ path: path2, name, ...type, size
|
|
1789
|
+
candidates.push({ path: path2, name, ...type, size });
|
|
1767
1790
|
};
|
|
1768
1791
|
for (const path2 of [...instructionPaths(opts.cwd, opts.harness, home, opts.pathAllowed), ...workspaces.flatMap((workspace2) => instructionPaths(workspace2.cwd, opts.harness, home, opts.pathAllowed)), ...touched]) consider(path2, resourceName(path2, opts.cwd, home));
|
|
1769
1792
|
for (const skill of skills2.found) for (const file of skillFiles(skill, opts.pathAllowed)) consider(file.path, file.name);
|
|
1770
1793
|
candidates.sort((a, b) => ORDER[a.kind] - ORDER[b.kind] || a.size - b.size);
|
|
1771
|
-
const
|
|
1794
|
+
const lines = [];
|
|
1772
1795
|
const attached = [];
|
|
1773
1796
|
let bytes = 0;
|
|
1774
1797
|
const state = workspaceState(opts.cwd, opts.harness, skills2, home, opts.title ?? null, opts.pathAllowed);
|
|
@@ -1793,13 +1816,13 @@ function collectSessionFiles(records, opts) {
|
|
|
1793
1816
|
leftOut.push({ path: file.name, reason: "could not be redacted safely" });
|
|
1794
1817
|
continue;
|
|
1795
1818
|
}
|
|
1796
|
-
const
|
|
1797
|
-
if (bytes +
|
|
1819
|
+
const size = Buffer.byteLength(line2);
|
|
1820
|
+
if (bytes + size > opts.budget) {
|
|
1798
1821
|
leftOut.push({ path: file.name, reason: "over the upload budget" });
|
|
1799
1822
|
continue;
|
|
1800
1823
|
}
|
|
1801
|
-
bytes +=
|
|
1802
|
-
|
|
1824
|
+
bytes += size;
|
|
1825
|
+
lines.push(line2);
|
|
1803
1826
|
attached.push({ name: file.name, kind: "text", bytes: file.data.length });
|
|
1804
1827
|
}
|
|
1805
1828
|
for (const file of candidates) {
|
|
@@ -1822,13 +1845,13 @@ function collectSessionFiles(records, opts) {
|
|
|
1822
1845
|
leftOut.push({ path: file.path, reason: file.kind === "text" && !isUtf8(data) ? "not valid UTF-8 text" : "could not be redacted safely" });
|
|
1823
1846
|
continue;
|
|
1824
1847
|
}
|
|
1825
|
-
const
|
|
1826
|
-
if (bytes +
|
|
1848
|
+
const size = Buffer.byteLength(line2);
|
|
1849
|
+
if (bytes + size > opts.budget) {
|
|
1827
1850
|
leftOut.push({ path: file.path, reason: "over the upload budget" });
|
|
1828
1851
|
continue;
|
|
1829
1852
|
}
|
|
1830
|
-
bytes +=
|
|
1831
|
-
|
|
1853
|
+
bytes += size;
|
|
1854
|
+
lines.push(line2);
|
|
1832
1855
|
attached.push({ name: file.name, kind: file.kind, bytes: data.length });
|
|
1833
1856
|
}
|
|
1834
1857
|
const setup = {
|
|
@@ -1837,7 +1860,7 @@ function collectSessionFiles(records, opts) {
|
|
|
1837
1860
|
mcpServers: state.manifest.mcp_servers.map((server) => server.name),
|
|
1838
1861
|
git: state.manifest.git !== null
|
|
1839
1862
|
};
|
|
1840
|
-
return { lines
|
|
1863
|
+
return { lines, bytes, attached, leftOut, setup };
|
|
1841
1864
|
}
|
|
1842
1865
|
|
|
1843
1866
|
// src/import-environment.ts
|
|
@@ -1974,13 +1997,13 @@ function importLayout(files2, sourceCwd, platform, wholeFolder) {
|
|
|
1974
1997
|
}
|
|
1975
1998
|
var TAR_BLOCK = 512;
|
|
1976
1999
|
var TAR_END = Buffer.alloc(TAR_BLOCK * 2);
|
|
1977
|
-
function header(name,
|
|
2000
|
+
function header(name, size, type) {
|
|
1978
2001
|
const block = Buffer.alloc(TAR_BLOCK);
|
|
1979
2002
|
block.write(name, 0, 100, "utf8");
|
|
1980
2003
|
block.write("0000644\0", 100);
|
|
1981
2004
|
block.write("0000000\0", 108);
|
|
1982
2005
|
block.write("0000000\0", 116);
|
|
1983
|
-
block.write(
|
|
2006
|
+
block.write(size.toString(8).padStart(11, "0") + "\0", 124);
|
|
1984
2007
|
block.write("00000000000\0", 136);
|
|
1985
2008
|
block.write(" ", 148);
|
|
1986
2009
|
block.write(type, 156);
|
|
@@ -2000,14 +2023,14 @@ function paxRecord(key, value) {
|
|
|
2000
2023
|
length += 1;
|
|
2001
2024
|
}
|
|
2002
2025
|
}
|
|
2003
|
-
function tarPadding(
|
|
2004
|
-
const rest =
|
|
2026
|
+
function tarPadding(size) {
|
|
2027
|
+
const rest = size % TAR_BLOCK;
|
|
2005
2028
|
return Buffer.alloc(rest ? TAR_BLOCK - rest : 0);
|
|
2006
2029
|
}
|
|
2007
|
-
function tarHeader(path2,
|
|
2008
|
-
if (Buffer.byteLength(path2) <= 100) return header(path2,
|
|
2030
|
+
function tarHeader(path2, size) {
|
|
2031
|
+
if (Buffer.byteLength(path2) <= 100) return header(path2, size, "0");
|
|
2009
2032
|
const pax = paxRecord("path", path2);
|
|
2010
|
-
return Buffer.concat([header("PaxHeader", pax.length, "x"), pax, tarPadding(pax.length), header(path2,
|
|
2033
|
+
return Buffer.concat([header("PaxHeader", pax.length, "x"), pax, tarPadding(pax.length), header(path2, size, "0")]);
|
|
2011
2034
|
}
|
|
2012
2035
|
|
|
2013
2036
|
// src/import-environment.ts
|
|
@@ -2039,8 +2062,8 @@ function listFiles(cwd) {
|
|
|
2039
2062
|
walk(cwd, "");
|
|
2040
2063
|
return out;
|
|
2041
2064
|
}
|
|
2042
|
-
function textOf(path2,
|
|
2043
|
-
if (
|
|
2065
|
+
function textOf(path2, size) {
|
|
2066
|
+
if (size > MAX_REDACTED_TEXT_BYTES) return null;
|
|
2044
2067
|
const data = readFileSync7(path2);
|
|
2045
2068
|
if (data.subarray(0, 8e3).includes(0) || !isUtf82(data)) return null;
|
|
2046
2069
|
return data;
|
|
@@ -2147,12 +2170,12 @@ async function packEnvironment(cwd, resources, platform = IMPORT_PLATFORM) {
|
|
|
2147
2170
|
throw error;
|
|
2148
2171
|
}
|
|
2149
2172
|
}
|
|
2150
|
-
function resourcesOf(
|
|
2151
|
-
return
|
|
2173
|
+
function resourcesOf(lines) {
|
|
2174
|
+
return lines.flatMap((line2) => {
|
|
2152
2175
|
try {
|
|
2153
|
-
const
|
|
2154
|
-
if (
|
|
2155
|
-
return [{ name:
|
|
2176
|
+
const record = JSON.parse(line2);
|
|
2177
|
+
if (record.type !== "import.resource" || typeof record.name !== "string" || typeof record.media_type !== "string" || typeof record.data !== "string") return [];
|
|
2178
|
+
return [{ name: record.name, mediaType: record.media_type, data: Buffer.from(record.data, "base64") }];
|
|
2156
2179
|
} catch {
|
|
2157
2180
|
return [];
|
|
2158
2181
|
}
|
|
@@ -2413,7 +2436,7 @@ function prepareImport(session2, summaryPath, options = {}) {
|
|
|
2413
2436
|
const maximum = 16 * 1024 * 1024;
|
|
2414
2437
|
let inputBytes = 0;
|
|
2415
2438
|
let outputBytes = 0;
|
|
2416
|
-
const
|
|
2439
|
+
const lines = [];
|
|
2417
2440
|
const digest = createHash3("sha256");
|
|
2418
2441
|
let nativeId;
|
|
2419
2442
|
let redactionCount = 0;
|
|
@@ -2428,15 +2451,15 @@ function prepareImport(session2, summaryPath, options = {}) {
|
|
|
2428
2451
|
const text2 = readFileSync8(path2, "utf8");
|
|
2429
2452
|
for (const raw of text2.split("\n")) {
|
|
2430
2453
|
if (!raw.trim()) continue;
|
|
2431
|
-
let
|
|
2454
|
+
let record;
|
|
2432
2455
|
try {
|
|
2433
|
-
|
|
2456
|
+
record = JSON.parse(raw);
|
|
2434
2457
|
} catch {
|
|
2435
2458
|
unreadableCount++;
|
|
2436
2459
|
continue;
|
|
2437
2460
|
}
|
|
2438
|
-
if (!
|
|
2439
|
-
const rec =
|
|
2461
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) throw new Error("Transcript records must be JSON objects.");
|
|
2462
|
+
const rec = record;
|
|
2440
2463
|
if (String(rec.type).startsWith("import.")) throw new Error("Native transcripts cannot supply import protocol records.");
|
|
2441
2464
|
if (path2 === session2.files[0]) source.push(rec);
|
|
2442
2465
|
records.push(rec);
|
|
@@ -2457,10 +2480,10 @@ function prepareImport(session2, summaryPath, options = {}) {
|
|
|
2457
2480
|
outputBytes += Buffer.byteLength(line2);
|
|
2458
2481
|
if (outputBytes > maximum) throw new Error("Redacted transcript exceeds the 16 MiB limit.");
|
|
2459
2482
|
digest.update(line2);
|
|
2460
|
-
|
|
2483
|
+
lines.push(line2);
|
|
2461
2484
|
}
|
|
2462
2485
|
}
|
|
2463
|
-
if (!
|
|
2486
|
+
if (!lines.length) throw new Error("The selected transcript is empty.");
|
|
2464
2487
|
const sourceId = nativeId ?? session2.sessionId;
|
|
2465
2488
|
if (!/^[A-Za-z0-9_-]{1,200}$/.test(sourceId) || redactLine2(JSON.stringify(sourceId)) !== JSON.stringify(sourceId)) throw new Error("The source conversation has an invalid identifier.");
|
|
2466
2489
|
const meta = source.result();
|
|
@@ -2498,13 +2521,13 @@ function prepareImport(session2, summaryPath, options = {}) {
|
|
|
2498
2521
|
};
|
|
2499
2522
|
summaryJson = JSON.stringify(summary);
|
|
2500
2523
|
}
|
|
2501
|
-
const body =
|
|
2524
|
+
const body = lines.join("") + files2.lines.join("") + JSON.stringify({ type: "import.summary", package: JSON.parse(summaryJson) }) + "\n" + JSON.stringify({ type: "import.end", records: lines.length + files2.lines.length + 1 }) + "\n";
|
|
2502
2525
|
const gaps = [];
|
|
2503
2526
|
if (encryptedReasoningCount > 0) gaps.push({ kind: "encrypted_reasoning", count: encryptedReasoningCount });
|
|
2504
2527
|
if (compactionCount > 0) gaps.push({ kind: "compaction", count: compactionCount });
|
|
2505
2528
|
if (unreadableCount > 0) gaps.push({ kind: "unreadable", count: unreadableCount });
|
|
2506
2529
|
const cwd = meta.cwd ?? (session2.harness === "claude_code" ? session2.workspace : "");
|
|
2507
|
-
return { body, transcriptLines:
|
|
2530
|
+
return { body, transcriptLines: lines.length, outputBytes, redactionCount, gaps, attachedFiles: files2.attached, leftOutFiles: files2.leftOut, setup: files2.setup, cwd, resourceLines: files2.lines };
|
|
2508
2531
|
}
|
|
2509
2532
|
async function importSession(opts) {
|
|
2510
2533
|
const base = (opts.agentUseUrl ?? agentUseBase()).replace(/\/$/, "");
|
|
@@ -2595,25 +2618,25 @@ import { spawn } from "child_process";
|
|
|
2595
2618
|
// src/local-access.ts
|
|
2596
2619
|
var reason = (error) => (error instanceof Error ? error.message : String(error)).split("\n")[0];
|
|
2597
2620
|
async function syncLocalAccess(signedIn, clients = detectMcpClients(), deps = {}) {
|
|
2598
|
-
const
|
|
2621
|
+
const lines = [];
|
|
2599
2622
|
if (!signedIn) {
|
|
2600
2623
|
const shell = writeShellEnv(void 0);
|
|
2601
|
-
|
|
2624
|
+
lines.push(shell.outcome === "failed" ? ` ${TOKEN_ENV} not updated for new shells: ${shell.detail}` : ` new shells no longer get ${TOKEN_ENV}`);
|
|
2602
2625
|
const holding = clients.filter((client) => hasMcpServer(client)).map((client) => client.name);
|
|
2603
|
-
if (holding.length)
|
|
2604
|
-
return
|
|
2626
|
+
if (holding.length) lines.push(` the agentsky MCP server in ${holding.join(", ")} still holds a key sky made for it: revoke it in Developer \u2192 API keys, or \`sky auth login\` replaces it`);
|
|
2627
|
+
return lines;
|
|
2605
2628
|
}
|
|
2606
2629
|
try {
|
|
2607
2630
|
const shell = writeShellEnv(await localAgentKey(SHELL_AGENT, deps));
|
|
2608
|
-
|
|
2631
|
+
lines.push(shell.outcome === "failed" ? ` ${TOKEN_ENV} not updated for new shells: ${shell.detail}` : ` new shells get ${TOKEN_ENV}: a key of their own, not this login's`);
|
|
2609
2632
|
} catch (error) {
|
|
2610
|
-
|
|
2633
|
+
lines.push(` ${TOKEN_ENV} not updated for new shells: ${reason(error)}`);
|
|
2611
2634
|
}
|
|
2612
2635
|
for (const registered of await refreshMcpRegistrations({ token: (client) => localAgentKey(client.id, deps), apiBase: apiBase() }, clients)) {
|
|
2613
2636
|
const name = clients.find((client) => client.id === registered.agent)?.name ?? registered.agent;
|
|
2614
|
-
|
|
2637
|
+
lines.push(registered.outcome === "registered" ? ` agentsky MCP server for ${name} now uses a key of its own` : ` agentsky MCP server for ${name} not updated: ${registered.detail ?? registered.outcome} \u2014 run \`sky setup skill\``);
|
|
2615
2638
|
}
|
|
2616
|
-
return
|
|
2639
|
+
return lines;
|
|
2617
2640
|
}
|
|
2618
2641
|
async function withdrawLocalAgentKeys(revoke) {
|
|
2619
2642
|
const { revoked, left } = await revokeLocalAgentKeys(revoke).catch(() => ({ revoked: 0, left: -1 }));
|
|
@@ -3687,7 +3710,7 @@ function describe(event) {
|
|
|
3687
3710
|
case "plan":
|
|
3688
3711
|
return ` ${event.provider} plan: ${event.outcome === "already" ? "already connected" : event.outcome}${event.detail ? ` (${event.detail})` : ""}`;
|
|
3689
3712
|
case "found": {
|
|
3690
|
-
const
|
|
3713
|
+
const lines = [
|
|
3691
3714
|
` ${event.skills.length} skill${event.skills.length === 1 ? "" : "s"}${event.skills.length ? `: ${event.skills.map((skill) => skill.name).join(", ")}` : ""}`,
|
|
3692
3715
|
...event.instructions.map((item) => ` instructions from ${item.agent}: ${item.path} (${kb(item.bytes)}${item.imports.length ? `, with ${item.imports.length} imported file${item.imports.length === 1 ? "" : "s"}` : ""})`),
|
|
3693
3716
|
...event.instructions.length ? [] : [" no global instructions file"],
|
|
@@ -3695,7 +3718,7 @@ function describe(event) {
|
|
|
3695
3718
|
...event.secrets.map((secret) => ` key for ${secret.name} (${secret.url}), from ${secret.agent}`),
|
|
3696
3719
|
...event.gcloud ? [` gcloud login${event.gcloud.account ? ` for ${event.gcloud.account}` : ""}`] : []
|
|
3697
3720
|
];
|
|
3698
|
-
return
|
|
3721
|
+
return lines.join("\n");
|
|
3699
3722
|
}
|
|
3700
3723
|
case "imported_skill":
|
|
3701
3724
|
return ` skill ${event.name}: ${event.outcome}`;
|
|
@@ -3714,8 +3737,8 @@ function describe(event) {
|
|
|
3714
3737
|
}
|
|
3715
3738
|
case "settings": {
|
|
3716
3739
|
if (event.outcome === "unavailable") return ` workspace settings not written into the agents' instruction files${event.detail ? ` (${event.detail})` : ""}; the next scheduled sync tries again`;
|
|
3717
|
-
const
|
|
3718
|
-
return
|
|
3740
|
+
const lines = event.files.filter((file) => file.outcome !== "current").map((file) => ` workspace settings ${file.outcome === "planned" ? "would be written" : file.outcome} in ${file.path}${file.detail ? ` (${file.detail})` : ""}`);
|
|
3741
|
+
return lines.length ? lines.join("\n") : " workspace settings already current in every agent";
|
|
3719
3742
|
}
|
|
3720
3743
|
case "computer":
|
|
3721
3744
|
return event.outcome === "reported" ? " this computer is listed under Settings \u203A Compute" : ` this computer could not be listed under Settings \u203A Compute: ${event.detail ?? "unknown error"}`;
|
|
@@ -3888,8 +3911,8 @@ async function setUp(opts, journal, afterwards = []) {
|
|
|
3888
3911
|
await syncConfig(sources2, opts.syncAs, emit);
|
|
3889
3912
|
return;
|
|
3890
3913
|
}
|
|
3891
|
-
const
|
|
3892
|
-
if (
|
|
3914
|
+
const claudeCode = agents.find((agent2) => agent2.id === "claude_code");
|
|
3915
|
+
if (claudeCode && !opts.dryRun) afterwards.push(keepClaudeCodeSideEffects(claudeCode, journal));
|
|
3893
3916
|
const run3 = { agents: [], plans: [] };
|
|
3894
3917
|
let captureNotices = [];
|
|
3895
3918
|
const earlier = loadReport();
|
|
@@ -3912,7 +3935,7 @@ async function setUp(opts, journal, afterwards = []) {
|
|
|
3912
3935
|
const workspace2 = engines.length && (has("skill") || has("capture")) ? await workspaceSlug().catch(() => null) : null;
|
|
3913
3936
|
let install = false;
|
|
3914
3937
|
if (engines.length && (has("skill") || has("capture") || has("plugins"))) {
|
|
3915
|
-
const captureNoticeLines = has("capture") && workspace2 ? captureNotice(workspace2, await (await import("./trace-library-
|
|
3938
|
+
const captureNoticeLines = has("capture") && workspace2 ? captureNotice(workspace2, await (await import("./trace-library-XVUYQB5X.js")).sourceFolders()) : [];
|
|
3916
3939
|
if (interactive) for (const line2 of captureNoticeLines) console.log(line2);
|
|
3917
3940
|
install = await agreed(installQuestion(engines.map((engine) => engine.name), { capture: captureNoticeLines.length > 0 }));
|
|
3918
3941
|
if (!interactive && captureNoticeLines.length) captureNotices = captureNoticeLines;
|
|
@@ -3964,9 +3987,9 @@ async function setUp(opts, journal, afterwards = []) {
|
|
|
3964
3987
|
for (const client of mcpOnly) await registerMcp(client);
|
|
3965
3988
|
if (token) {
|
|
3966
3989
|
try {
|
|
3967
|
-
const { localSkillWorkspace } = await import("./local-skills-run-
|
|
3990
|
+
const { localSkillWorkspace } = await import("./local-skills-run-DPAEXDNS.js");
|
|
3968
3991
|
const workspace3 = await localSkillWorkspace();
|
|
3969
|
-
const { libraryRequest } = await import("./trace-library-
|
|
3992
|
+
const { libraryRequest } = await import("./trace-library-XVUYQB5X.js");
|
|
3970
3993
|
const local = await syncLocalSkills({
|
|
3971
3994
|
workspace: workspace3,
|
|
3972
3995
|
targets: skillTargets(agents, hermes?.root ?? null),
|
|
@@ -4094,45 +4117,45 @@ async function connectPlans(agents, opts, interactive, emit, run3) {
|
|
|
4094
4117
|
const only = planProviders(opts.plans);
|
|
4095
4118
|
const wanted = (provider) => only === null || only.has(provider);
|
|
4096
4119
|
const connected = opts.dryRun && !apiToken() ? /* @__PURE__ */ new Set() : await connectedProviders();
|
|
4097
|
-
const
|
|
4120
|
+
const record = (provider, outcome, detail) => {
|
|
4098
4121
|
emit({ type: "plan", provider, outcome, ...detail ? { detail } : {} });
|
|
4099
4122
|
if (outcome === "available") return;
|
|
4100
4123
|
run3.plans.push({ provider, outcome: outcome === "already" ? "connected" : outcome });
|
|
4101
4124
|
};
|
|
4102
4125
|
const copy = async (provider, name, read) => {
|
|
4103
|
-
if (connected.has(provider)) return
|
|
4126
|
+
if (connected.has(provider)) return record(provider, "already");
|
|
4104
4127
|
let found;
|
|
4105
4128
|
try {
|
|
4106
4129
|
found = read();
|
|
4107
4130
|
} catch (error) {
|
|
4108
4131
|
if (error instanceof ApiError && error.status === 404) return;
|
|
4109
|
-
return
|
|
4132
|
+
return record(provider, "failed", message(error));
|
|
4110
4133
|
}
|
|
4111
|
-
if (opts.dryRun) return
|
|
4134
|
+
if (opts.dryRun) return record(provider, "available", found.account ? `account ${found.account}` : void 0);
|
|
4112
4135
|
if (interactive && !await confirm2(`Use the ${name} sign-in on this computer${found.account ? ` (account ${found.account})` : ""} for your cloud agents?`)) {
|
|
4113
|
-
return
|
|
4136
|
+
return record(provider, "skipped");
|
|
4114
4137
|
}
|
|
4115
4138
|
try {
|
|
4116
4139
|
await put(provider, found.raw);
|
|
4117
|
-
|
|
4140
|
+
record(provider, "connected");
|
|
4118
4141
|
} catch (error) {
|
|
4119
|
-
|
|
4142
|
+
record(provider, "failed", message(error));
|
|
4120
4143
|
}
|
|
4121
4144
|
};
|
|
4122
4145
|
if (agents.some((agent2) => agent2.id === "claude_code") && wanted("anthropic")) {
|
|
4123
|
-
if (connected.has("anthropic"))
|
|
4124
|
-
else if (opts.dryRun)
|
|
4125
|
-
else if (opts.json || opts.yes || opts.claude === false)
|
|
4126
|
-
else if (!await confirm2("Connect your Claude plan? It opens the browser for one approval and does not sign Claude Code out."))
|
|
4146
|
+
if (connected.has("anthropic")) record("anthropic", "already");
|
|
4147
|
+
else if (opts.dryRun) record("anthropic", "available");
|
|
4148
|
+
else if (opts.json || opts.yes || opts.claude === false) record("anthropic", "skipped", "needs a browser approval");
|
|
4149
|
+
else if (!await confirm2("Connect your Claude plan? It opens the browser for one approval and does not sign Claude Code out.")) record("anthropic", "skipped");
|
|
4127
4150
|
else {
|
|
4128
4151
|
const token = await mintClaudeToken();
|
|
4129
|
-
if (!token)
|
|
4152
|
+
if (!token) record("anthropic", "failed", "`claude setup-token` did not return a token");
|
|
4130
4153
|
else {
|
|
4131
4154
|
try {
|
|
4132
4155
|
await put("anthropic", token);
|
|
4133
|
-
|
|
4156
|
+
record("anthropic", "connected");
|
|
4134
4157
|
} catch (error) {
|
|
4135
|
-
|
|
4158
|
+
record("anthropic", "failed", message(error));
|
|
4136
4159
|
}
|
|
4137
4160
|
}
|
|
4138
4161
|
}
|
|
@@ -4397,9 +4420,9 @@ function interruptLine(res) {
|
|
|
4397
4420
|
}
|
|
4398
4421
|
|
|
4399
4422
|
// src/index.ts
|
|
4400
|
-
import { createHash as
|
|
4423
|
+
import { createHash as createHash12 } from "crypto";
|
|
4401
4424
|
import { existsSync as existsSync15, readFileSync as readFileSync28, writeFileSync as writeFileSync13 } from "fs";
|
|
4402
|
-
import { basename as
|
|
4425
|
+
import { basename as basename8, resolve as resolve13 } from "path";
|
|
4403
4426
|
import { createInterface as createInterface5 } from "readline";
|
|
4404
4427
|
import { Command, Option } from "commander";
|
|
4405
4428
|
|
|
@@ -4411,27 +4434,27 @@ function eventsQuery(opts) {
|
|
|
4411
4434
|
return query ? `?${query}` : "";
|
|
4412
4435
|
}
|
|
4413
4436
|
function renderEventPage(page) {
|
|
4414
|
-
const
|
|
4437
|
+
const lines = page.data.map((event) => {
|
|
4415
4438
|
const who = event.actor.session_id ? `agent ${event.actor.session_id}` : event.actor.kind;
|
|
4416
4439
|
const objects = event.objects.map((object) => `${object.type}:${object.id.length > 24 ? `${object.id.slice(0, 12)}\u2026` : object.id}${object.role ? `(${object.role})` : ""}`).join(" ");
|
|
4417
4440
|
return `${event.occurred_at} ${event.id} ${event.kind.padEnd(26)} ${who} via ${event.surface} ${objects}`;
|
|
4418
4441
|
});
|
|
4419
|
-
if (!page.data.length)
|
|
4420
|
-
if (page.next_cursor)
|
|
4421
|
-
return
|
|
4442
|
+
if (!page.data.length) lines.push("no events on this page");
|
|
4443
|
+
if (page.next_cursor) lines.push(`more: --cursor ${page.next_cursor}`);
|
|
4444
|
+
return lines.join("\n");
|
|
4422
4445
|
}
|
|
4423
4446
|
function renderDigestPage(page) {
|
|
4424
4447
|
if (!page.data.length) return "no digests in this range";
|
|
4425
4448
|
return page.data.map((digest) => {
|
|
4426
|
-
const
|
|
4427
|
-
if (digest.summary)
|
|
4449
|
+
const lines = [`${digest.window?.key ?? digest.id} ${digest.title ?? ""} (${digest.stats?.events ?? 0} events, ${digest.id})`];
|
|
4450
|
+
if (digest.summary) lines.push(digest.summary);
|
|
4428
4451
|
for (const activity of digest.activities ?? []) {
|
|
4429
|
-
|
|
4430
|
-
for (const decision of activity.decisions)
|
|
4431
|
-
for (const output2 of activity.outputs)
|
|
4432
|
-
|
|
4452
|
+
lines.push(`- ${activity.title}${activity.where ? ` [${activity.where}]` : ""}: ${activity.what}`);
|
|
4453
|
+
for (const decision of activity.decisions) lines.push(` decision: ${decision}`);
|
|
4454
|
+
for (const output2 of activity.outputs) lines.push(` output: ${output2}`);
|
|
4455
|
+
lines.push(` events: ${activity.event_ids.join(" ")}`);
|
|
4433
4456
|
}
|
|
4434
|
-
return
|
|
4457
|
+
return lines.join("\n");
|
|
4435
4458
|
}).join("\n\n");
|
|
4436
4459
|
}
|
|
4437
4460
|
function renderTimelinePause(paused) {
|
|
@@ -4477,22 +4500,22 @@ function renderMyDigests(digests) {
|
|
|
4477
4500
|
return `${what}: ${digests.enabled ? "on" : "off"}${digests.workspace_enabled ? "" : " (the workspace has digests off)"}.`;
|
|
4478
4501
|
}
|
|
4479
4502
|
function renderCapturePage(page) {
|
|
4480
|
-
const
|
|
4503
|
+
const lines = [];
|
|
4481
4504
|
if (page.sources) {
|
|
4482
4505
|
for (const source of page.sources) {
|
|
4483
|
-
if (source.kind === "message")
|
|
4484
|
-
else if (source.days?.length)
|
|
4506
|
+
if (source.kind === "message") lines.push(`${source.source}: ${source.count} messages, ${source.first_at?.slice(0, 10)} to ${source.last_at?.slice(0, 10)}`);
|
|
4507
|
+
else if (source.days?.length) lines.push(`${source.source}: ${source.days.length} days (${source.days[0]} to ${source.days.at(-1)})`);
|
|
4485
4508
|
}
|
|
4486
|
-
if (
|
|
4509
|
+
if (lines.length) lines.push("");
|
|
4487
4510
|
}
|
|
4488
4511
|
for (const item of page.data) {
|
|
4489
|
-
if (item.kind === "segment")
|
|
4490
|
-
else
|
|
4512
|
+
if (item.kind === "segment") lines.push(`${item.day} ${item.source} ${item.segment} ${item.files} files, ${item.bytes} bytes${item.sealed ? "" : " (uploading)"}`);
|
|
4513
|
+
else lines.push(`${item.occurred_at} ${item.source} ${item.thread ?? item.conversation} ${item.sender ?? "?"}: ${(item.subject ?? item.preview ?? "").replace(/\s+/g, " ").slice(0, 100)}${item.files ? ` [${item.files} files]` : ""}`);
|
|
4491
4514
|
}
|
|
4492
|
-
if (!
|
|
4493
|
-
if (page.partial)
|
|
4494
|
-
if (page.next_cursor)
|
|
4495
|
-
return
|
|
4515
|
+
if (!lines.length) lines.push("Nothing captured.");
|
|
4516
|
+
if (page.partial) lines.push("Some days hold more than one read lists; ask for one day at a time.");
|
|
4517
|
+
if (page.next_cursor) lines.push(`more: --cursor ${page.next_cursor}`);
|
|
4518
|
+
return lines.join("\n");
|
|
4496
4519
|
}
|
|
4497
4520
|
function renderCaptureDeletion(total) {
|
|
4498
4521
|
if (total.deleted_messages !== void 0) return `Deleted ${total.deleted_messages} ${total.source} messages.`;
|
|
@@ -4502,10 +4525,10 @@ function renderCaptureDeletion(total) {
|
|
|
4502
4525
|
// src/sky-progress.ts
|
|
4503
4526
|
var STAGE = { assigned: "assigned", in_progress: "in progress", delivered: "delivered", landed: "landed" };
|
|
4504
4527
|
function renderProgressPage(page) {
|
|
4505
|
-
const
|
|
4506
|
-
if (!
|
|
4507
|
-
if (page.next_cursor)
|
|
4508
|
-
return
|
|
4528
|
+
const lines = page.threads.map((thread2) => `${thread2.needs_you ? "needs you " : " "}${STAGE[thread2.stage].padEnd(12)}${thread2.title} \u2014 ${thread2.sentence}${thread2.owner?.name ? ` (${thread2.owner.name})` : ""} ${thread2.task_id}`);
|
|
4529
|
+
if (!lines.length) lines.push("no threads");
|
|
4530
|
+
if (page.next_cursor) lines.push(`more: --cursor ${page.next_cursor}`);
|
|
4531
|
+
return lines.join("\n");
|
|
4509
4532
|
}
|
|
4510
4533
|
|
|
4511
4534
|
// src/files.ts
|
|
@@ -4687,30 +4710,30 @@ function driverLine(goal2) {
|
|
|
4687
4710
|
}
|
|
4688
4711
|
function renderGoal(goal2) {
|
|
4689
4712
|
if (!goal2) return 'No goal. Set one: sky goal set <session> "<objective>"';
|
|
4690
|
-
const
|
|
4713
|
+
const lines = [];
|
|
4691
4714
|
const state = goal2.status === "stopped" && goal2.stop_reason ? `stopped (${goal2.stop_reason})` : goal2.status;
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
if (goal2.driver !== void 0)
|
|
4715
|
+
lines.push(`${goal2.id} ${state} iteration ${goal2.iteration}/${goal2.max_iterations}`);
|
|
4716
|
+
lines.push(`objective: ${goal2.objective}`);
|
|
4717
|
+
if (goal2.driver !== void 0) lines.push(driverLine(goal2));
|
|
4695
4718
|
const spend = goal2.max_spend ? `${dollars2(goal2.consumed_spend.amount)} of ${dollars2(goal2.max_spend.amount)}` : dollars2(goal2.consumed_spend.amount);
|
|
4696
4719
|
const tokens = goal2.max_tokens === null ? `${goal2.consumed_tokens}` : `${goal2.consumed_tokens} of ${goal2.max_tokens}`;
|
|
4697
|
-
|
|
4720
|
+
lines.push(`spent: ${spend} tokens: ${tokens}${goal2.deadline_at ? ` deadline: ${goal2.deadline_at}` : ""}`);
|
|
4698
4721
|
const verdicts = new Map((goal2.last_evaluation?.criteria ?? []).map((c) => [c.id, c]));
|
|
4699
|
-
|
|
4722
|
+
lines.push(`criteria${goal2.criteria_source === "derived" ? " (written from the objective)" : ""}:`);
|
|
4700
4723
|
for (const criterion of goal2.criteria) {
|
|
4701
4724
|
const verdict = verdicts.get(criterion.id);
|
|
4702
4725
|
const mark = verdict ? verdict.met ? "[x]" : "[ ]" : "[?]";
|
|
4703
|
-
|
|
4704
|
-
if (criterion.command)
|
|
4705
|
-
for (const file of criterion.files ?? [])
|
|
4726
|
+
lines.push(` ${mark} ${criterion.id} ${criterion.text}`);
|
|
4727
|
+
if (criterion.command) lines.push(` $ ${criterion.command}`);
|
|
4728
|
+
for (const file of criterion.files ?? []) lines.push(` frozen: ${file.path} (sha256 ${file.sha256.slice(0, 12)})`);
|
|
4706
4729
|
const ran = verdict && ranLine(verdict);
|
|
4707
|
-
if (ran)
|
|
4708
|
-
if (verdict && !verdict.met && verdict.reason)
|
|
4730
|
+
if (ran) lines.push(` ${ran}`);
|
|
4731
|
+
if (verdict && !verdict.met && verdict.reason) lines.push(` ${verdict.reason}`);
|
|
4709
4732
|
}
|
|
4710
4733
|
if (goal2.last_evaluation && goal2.last_evaluation.result !== "satisfied") {
|
|
4711
|
-
|
|
4734
|
+
lines.push(`last check (iteration ${goal2.last_evaluation.iteration}): ${goal2.last_evaluation.explanation}`);
|
|
4712
4735
|
}
|
|
4713
|
-
return
|
|
4736
|
+
return lines.join("\n");
|
|
4714
4737
|
}
|
|
4715
4738
|
|
|
4716
4739
|
// src/account.ts
|
|
@@ -4741,10 +4764,10 @@ var usd = (value) => `$${value.toFixed(2)}`;
|
|
|
4741
4764
|
var centsUsd = (money) => money.amount_usd !== void 0 ? `$${Number(money.amount_usd).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 6, useGrouping: false })}` : `$${(Number(money.amount) / 100).toFixed(2)}`;
|
|
4742
4765
|
function renderAutoTopup(settings) {
|
|
4743
4766
|
const state = settings.enabled ? `on \u2014 below ${usd(settings.threshold_usd)}, the saved card adds ${usd(settings.amount_usd)}` : `off${settings.opted_out ? " (you turned it off)" : ""} \u2014 would add ${usd(settings.amount_usd)} below ${usd(settings.threshold_usd)}`;
|
|
4744
|
-
const
|
|
4745
|
-
if (settings.card_on_file === false)
|
|
4746
|
-
if (settings.failure)
|
|
4747
|
-
return
|
|
4767
|
+
const lines = [`auto top-up: ${state}`];
|
|
4768
|
+
if (settings.card_on_file === false) lines.push(" no saved card \u2014 `sky billing card` adds one");
|
|
4769
|
+
if (settings.failure) lines.push(` last charge failed${settings.failure.paused ? " (paused)" : ""}: ${settings.failure.reason}`);
|
|
4770
|
+
return lines.join("\n");
|
|
4748
4771
|
}
|
|
4749
4772
|
function renderBalance(balance) {
|
|
4750
4773
|
return `balance: ${usd(balance.balance_usd)} card on file: ${balance.card_on_file ? "yes" : "no"}`;
|
|
@@ -4762,13 +4785,13 @@ function measureLine(m) {
|
|
|
4762
4785
|
return `${String(m.calls).padStart(6)} calls ${String(m.inputTokens).padStart(10)} in ${String(m.outputTokens).padStart(9)} out ${`$${m.billedCostUsd.toFixed(4)}`.padStart(10)}`;
|
|
4763
4786
|
}
|
|
4764
4787
|
function renderUsage(summary) {
|
|
4765
|
-
const
|
|
4788
|
+
const lines = [`usage ${summary.range.from} \u2192 ${summary.range.to} (end exclusive), by ${summary.groupBy}`];
|
|
4766
4789
|
for (const group of summary.groups) {
|
|
4767
|
-
|
|
4790
|
+
lines.push(` ${group.label.padEnd(28).slice(0, 28)} ${group.source.padEnd(8)} ${measureLine(group)}`);
|
|
4768
4791
|
}
|
|
4769
|
-
if (!summary.groups.length)
|
|
4770
|
-
|
|
4771
|
-
return
|
|
4792
|
+
if (!summary.groups.length) lines.push(" no usage in this range");
|
|
4793
|
+
lines.push(` ${"total".padEnd(37)} ${measureLine(summary.totals)}`);
|
|
4794
|
+
return lines.join("\n");
|
|
4772
4795
|
}
|
|
4773
4796
|
function usageQuery(opts) {
|
|
4774
4797
|
const params = new URLSearchParams();
|
|
@@ -4923,16 +4946,16 @@ function refArgument(ref) {
|
|
|
4923
4946
|
return `'${JSON.stringify(ref).replace(/'/g, "'\\''")}'`;
|
|
4924
4947
|
}
|
|
4925
4948
|
function renderContextPage(page) {
|
|
4926
|
-
const
|
|
4949
|
+
const lines = [];
|
|
4927
4950
|
for (const hit of page.hits) {
|
|
4928
|
-
|
|
4929
|
-
|
|
4951
|
+
lines.push(`${hit.path ?? hit.title}${hit.line ? `:${hit.line}` : ""}: ${hit.snippet.replace(/\s+/g, " ").slice(0, 160)}`);
|
|
4952
|
+
lines.push(` sky context read ${refArgument(hit.ref)}`);
|
|
4930
4953
|
}
|
|
4931
|
-
if (!page.hits.length)
|
|
4954
|
+
if (!page.hits.length) lines.push("no matches on this page");
|
|
4932
4955
|
const missed = (page.sources ?? []).filter((source) => source.status === "failed" || source.status === "partial").map((source) => source.source);
|
|
4933
|
-
if (page.partial)
|
|
4934
|
-
if (page.nextCursor)
|
|
4935
|
-
return
|
|
4956
|
+
if (page.partial) lines.push(`partial: ${missed.length ? `${missed.join(", ")} not fully searched` : "not every source was searched"}`);
|
|
4957
|
+
if (page.nextCursor) lines.push(`more: --cursor ${page.nextCursor}`);
|
|
4958
|
+
return lines.join("\n");
|
|
4936
4959
|
}
|
|
4937
4960
|
|
|
4938
4961
|
// src/agent-manifest-file.ts
|
|
@@ -5119,14 +5142,14 @@ function deployReport(id2, spec, before, after, promptChanged) {
|
|
|
5119
5142
|
if (promptChanged) changed.push("prompt");
|
|
5120
5143
|
if (after.version !== before.version) changed.push("settings");
|
|
5121
5144
|
if (!changed.length) return [`${id2} is up to date \u2014 nothing to deploy (version ${after.version})`];
|
|
5122
|
-
const
|
|
5145
|
+
const lines = [`Deployed ${id2}: ${changed.join(" and ")} updated (version ${before.version} \u2192 ${after.version})`];
|
|
5123
5146
|
if (after.agentType !== before.agentType || after.llm !== before.llm) {
|
|
5124
|
-
|
|
5147
|
+
lines.push(` now ${after.agentType} \xB7 ${after.llm} for new sessions (was ${before.agentType} \xB7 ${before.llm})`);
|
|
5125
5148
|
}
|
|
5126
5149
|
if (spec.skills && after.version !== before.version) {
|
|
5127
|
-
|
|
5150
|
+
lines.push(` Skills apply to new sessions; running sessions keep the skills they started with \u2014 start one with \`sky session create ${id2}\`.`);
|
|
5128
5151
|
}
|
|
5129
|
-
return
|
|
5152
|
+
return lines;
|
|
5130
5153
|
}
|
|
5131
5154
|
|
|
5132
5155
|
// src/agent-manifest-file.ts
|
|
@@ -5163,30 +5186,30 @@ function stampManifestId(path2, id2) {
|
|
|
5163
5186
|
writeFileSync7(path2, stampIdText(readFileSync17(path2, "utf8"), id2));
|
|
5164
5187
|
}
|
|
5165
5188
|
function lineOfField(text2, field) {
|
|
5166
|
-
const
|
|
5189
|
+
const lines = text2.split("\n");
|
|
5167
5190
|
const [top, index, key] = field.split(".");
|
|
5168
|
-
const keyLine = (name, from = 0, to =
|
|
5169
|
-
const at =
|
|
5191
|
+
const keyLine = (name, from = 0, to = lines.length) => {
|
|
5192
|
+
const at = lines.slice(from, to).findIndex((line3) => new RegExp(`^\\s*"?${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"?\\s*=`).test(line3));
|
|
5170
5193
|
return at < 0 ? null : from + at;
|
|
5171
5194
|
};
|
|
5172
5195
|
if (top === void 0) return null;
|
|
5173
5196
|
if (index !== void 0 && /^\d+$/.test(index)) {
|
|
5174
|
-
const headers =
|
|
5197
|
+
const headers = lines.map((line3, at) => new RegExp(`^\\s*\\[\\[\\s*${top}\\s*\\]\\]`).test(line3) ? at : -1).filter((at) => at >= 0);
|
|
5175
5198
|
const header2 = headers[Number(index)];
|
|
5176
5199
|
if (header2 !== void 0) {
|
|
5177
|
-
const end =
|
|
5178
|
-
const within = key ? keyLine(key, header2 + 1, end < 0 ?
|
|
5200
|
+
const end = lines.findIndex((line3, at) => at > header2 && /^\s*\[/.test(line3));
|
|
5201
|
+
const within = key ? keyLine(key, header2 + 1, end < 0 ? lines.length : end) : null;
|
|
5179
5202
|
return (within ?? header2) + 1;
|
|
5180
5203
|
}
|
|
5181
5204
|
}
|
|
5182
|
-
const tableHeader =
|
|
5205
|
+
const tableHeader = lines.findIndex((line3) => new RegExp(`^\\s*\\[\\s*${top}\\s*\\]`).test(line3));
|
|
5183
5206
|
if (tableHeader >= 0) {
|
|
5184
|
-
const end =
|
|
5185
|
-
const within = index !== void 0 ? keyLine(index, tableHeader + 1, end < 0 ?
|
|
5207
|
+
const end = lines.findIndex((line3, at) => at > tableHeader && /^\s*\[/.test(line3));
|
|
5208
|
+
const within = index !== void 0 ? keyLine(index, tableHeader + 1, end < 0 ? lines.length : end) : null;
|
|
5186
5209
|
return (within ?? tableHeader) + 1;
|
|
5187
5210
|
}
|
|
5188
|
-
const firstTable =
|
|
5189
|
-
const line2 = keyLine(top, 0, firstTable < 0 ?
|
|
5211
|
+
const firstTable = lines.findIndex((line3) => /^\s*\[/.test(line3));
|
|
5212
|
+
const line2 = keyLine(top, 0, firstTable < 0 ? lines.length : firstTable);
|
|
5190
5213
|
return line2 === null ? null : line2 + 1;
|
|
5191
5214
|
}
|
|
5192
5215
|
function refusalLines(label, text2, issues) {
|
|
@@ -5253,7 +5276,7 @@ async function setEngineStatus(engine, status, reason2) {
|
|
|
5253
5276
|
var uses = (agent2) => `${agent2.stats.uses} ${agent2.stats.uses === 1 ? "use" : "uses"}`;
|
|
5254
5277
|
var mine = (agent2) => agent2.visibility === "workspace" ? " (yours)" : "";
|
|
5255
5278
|
function renderCatalogAgent(agent2) {
|
|
5256
|
-
const section = (title,
|
|
5279
|
+
const section = (title, lines) => lines.length ? [`${title}:`, ...lines.map((line2) => ` - ${line2}`)] : [];
|
|
5257
5280
|
return [
|
|
5258
5281
|
`@${agent2.handle} ${agent2.name}${mine(agent2)}`,
|
|
5259
5282
|
agent2.tagline,
|
|
@@ -5833,6 +5856,15 @@ async function slackBot(agentId, team, wait) {
|
|
|
5833
5856
|
async function unpublishFromSlack(agentId, team) {
|
|
5834
5857
|
return api("DELETE", `/channels/agent-bots/slack/${encodeURIComponent(agentId)}${teamQuery(team)}`);
|
|
5835
5858
|
}
|
|
5859
|
+
async function connectAgentSlackDm(agentId) {
|
|
5860
|
+
return api("POST", `/channels/agent-bots/slack/${encodeURIComponent(agentId)}/dm`);
|
|
5861
|
+
}
|
|
5862
|
+
async function agentSlackDm(agentId) {
|
|
5863
|
+
return api("GET", `/channels/agent-bots/slack/${encodeURIComponent(agentId)}/dm`);
|
|
5864
|
+
}
|
|
5865
|
+
async function disconnectAgentSlackDm(agentId) {
|
|
5866
|
+
return api("DELETE", `/channels/agent-bots/slack/${encodeURIComponent(agentId)}/dm`);
|
|
5867
|
+
}
|
|
5836
5868
|
|
|
5837
5869
|
// src/routine-triggers.ts
|
|
5838
5870
|
var triggerPath = (id2, resource) => `/routines/${encodeURIComponent(id2)}/${resource}`;
|
|
@@ -5875,1364 +5907,8 @@ import { spawnSync as spawnSync2 } from "child_process";
|
|
|
5875
5907
|
import { createHash as createHash8, randomUUID as randomUUID5 } from "crypto";
|
|
5876
5908
|
import { existsSync as existsSync12, lstatSync as lstatSync5, mkdirSync as mkdirSync5, readdirSync as readdirSync8, readFileSync as readFileSync20, renameSync as renameSync2, statSync as statSync6, writeFileSync as writeFileSync9 } from "fs";
|
|
5877
5909
|
import { homedir as homedir11, hostname as hostname2, tmpdir as tmpdir3 } from "os";
|
|
5878
|
-
import { basename as
|
|
5910
|
+
import { basename as basename6, dirname as dirname10, join as join16, relative as relative4, resolve as resolve10 } from "path";
|
|
5879
5911
|
import { inflateRawSync } from "zlib";
|
|
5880
|
-
|
|
5881
|
-
// ../../packages/spec/src/native/triage.ts
|
|
5882
|
-
var KEPT_ATTACHMENT_KINDS = /* @__PURE__ */ new Set([
|
|
5883
|
-
"queued_command",
|
|
5884
|
-
"edited_text_file"
|
|
5885
|
-
]);
|
|
5886
|
-
var DROPPED_ATTACHMENT_KINDS = /* @__PURE__ */ new Set([
|
|
5887
|
-
"total_tokens_reminder",
|
|
5888
|
-
"batching_reminder_sent",
|
|
5889
|
-
"hook_success",
|
|
5890
|
-
"hook_non_blocking_error",
|
|
5891
|
-
"hook_additional_context",
|
|
5892
|
-
"environment",
|
|
5893
|
-
"deferred_tools_delta",
|
|
5894
|
-
"compact_file_reference"
|
|
5895
|
-
]);
|
|
5896
|
-
var DROPPED_LINE_TYPES = /* @__PURE__ */ new Set([
|
|
5897
|
-
"bridge-session",
|
|
5898
|
-
"queue-operation",
|
|
5899
|
-
"last-prompt",
|
|
5900
|
-
"custom-title",
|
|
5901
|
-
"atis-latch",
|
|
5902
|
-
"pr-link",
|
|
5903
|
-
"frame-link",
|
|
5904
|
-
"mode",
|
|
5905
|
-
"file-history-snapshot",
|
|
5906
|
-
"file-history-delta",
|
|
5907
|
-
"ai-title",
|
|
5908
|
-
"agent-setting",
|
|
5909
|
-
"permission-mode",
|
|
5910
|
-
"cost-state",
|
|
5911
|
-
"relocated",
|
|
5912
|
-
"artifact-autoreact-ledger",
|
|
5913
|
-
"artifact-comment-monitor"
|
|
5914
|
-
]);
|
|
5915
|
-
function isInjectedTurn(line2) {
|
|
5916
|
-
return line2.isMeta === true || line2.isSynthetic === true || line2.isCompactSummary === true;
|
|
5917
|
-
}
|
|
5918
|
-
function isImageCompanion(blocks) {
|
|
5919
|
-
if (blocks.length === 0) return false;
|
|
5920
|
-
return blocks.every((block) => {
|
|
5921
|
-
if (typeof block !== "object" || block === null) return false;
|
|
5922
|
-
const b = block;
|
|
5923
|
-
return b.type === "text" && typeof b.text === "string" && /^\s*\[Image:\s*source:/.test(b.text);
|
|
5924
|
-
});
|
|
5925
|
-
}
|
|
5926
|
-
function triage(line2) {
|
|
5927
|
-
const type = typeof line2.type === "string" ? line2.type : null;
|
|
5928
|
-
if (type === null) return { keep: false, reason: "no line type" };
|
|
5929
|
-
if (type === "attachment") {
|
|
5930
|
-
const payload = typeof line2.attachment === "object" && line2.attachment !== null ? line2.attachment : line2;
|
|
5931
|
-
const kind = typeof payload.type === "string" ? payload.type : "";
|
|
5932
|
-
if (KEPT_ATTACHMENT_KINDS.has(kind)) return { keep: true, reason: `attachment:${kind}` };
|
|
5933
|
-
if (DROPPED_ATTACHMENT_KINDS.has(kind)) return { keep: false, reason: `bookkeeping:${kind}` };
|
|
5934
|
-
return { keep: true, reason: `attachment:unclassified:${kind || "unnamed"}` };
|
|
5935
|
-
}
|
|
5936
|
-
if (DROPPED_LINE_TYPES.has(type)) return { keep: false, reason: `bookkeeping:${type}` };
|
|
5937
|
-
if (type === "user" || type === "assistant") return { keep: true, reason: type };
|
|
5938
|
-
if (type === "system") return { keep: false, reason: "harness system line" };
|
|
5939
|
-
return { keep: true, reason: `unclassified:${type}` };
|
|
5940
|
-
}
|
|
5941
|
-
|
|
5942
|
-
// ../../packages/spec/src/native/claude-code.ts
|
|
5943
|
-
var INTERRUPT_MARKERS = [
|
|
5944
|
-
"[Request interrupted by user",
|
|
5945
|
-
"Tool use was rejected"
|
|
5946
|
-
];
|
|
5947
|
-
function textOf2(value) {
|
|
5948
|
-
return typeof value === "string" ? value : "";
|
|
5949
|
-
}
|
|
5950
|
-
function basename6(path2) {
|
|
5951
|
-
const parts = path2.split(/[\\/]/);
|
|
5952
|
-
return parts[parts.length - 1] ?? path2;
|
|
5953
|
-
}
|
|
5954
|
-
function guessMediaType(name) {
|
|
5955
|
-
const ext = name.slice(name.lastIndexOf(".") + 1).toLowerCase();
|
|
5956
|
-
const map = {
|
|
5957
|
-
png: "image/png",
|
|
5958
|
-
jpg: "image/jpeg",
|
|
5959
|
-
jpeg: "image/jpeg",
|
|
5960
|
-
gif: "image/gif",
|
|
5961
|
-
webp: "image/webp",
|
|
5962
|
-
pdf: "application/pdf",
|
|
5963
|
-
json: "application/json",
|
|
5964
|
-
csv: "text/csv",
|
|
5965
|
-
md: "text/markdown",
|
|
5966
|
-
html: "text/html",
|
|
5967
|
-
css: "text/css",
|
|
5968
|
-
js: "text/javascript",
|
|
5969
|
-
ts: "text/typescript",
|
|
5970
|
-
tsx: "text/typescript",
|
|
5971
|
-
py: "text/x-python"
|
|
5972
|
-
};
|
|
5973
|
-
return map[ext] ?? "text/plain";
|
|
5974
|
-
}
|
|
5975
|
-
function looksInterrupted(blocks) {
|
|
5976
|
-
return blocks.some((block) => {
|
|
5977
|
-
if (typeof block !== "object" || block === null) return false;
|
|
5978
|
-
const text2 = textOf2(block.text);
|
|
5979
|
-
return INTERRUPT_MARKERS.some((marker) => text2.includes(marker));
|
|
5980
|
-
});
|
|
5981
|
-
}
|
|
5982
|
-
function imageBlockToPart(block, index) {
|
|
5983
|
-
const source = typeof block.source === "object" && block.source !== null ? block.source : {};
|
|
5984
|
-
const data = textOf2(source.data);
|
|
5985
|
-
const uri = textOf2(source.url) || textOf2(block.url);
|
|
5986
|
-
if (!data && !uri) return null;
|
|
5987
|
-
const embedded = uri && isEmbeddedImage(uri) ? uri : "";
|
|
5988
|
-
if (!data && !embedded) return { type: "text", index, text: imageLinkText(uri) };
|
|
5989
|
-
return {
|
|
5990
|
-
type: "image",
|
|
5991
|
-
index,
|
|
5992
|
-
media_type: textOf2(source.media_type) || imageMediaType(embedded || uri || `data:${textOf2(source.type)};`),
|
|
5993
|
-
...embedded ? { uri: embedded } : {},
|
|
5994
|
-
...data ? { data } : {}
|
|
5995
|
-
};
|
|
5996
|
-
}
|
|
5997
|
-
function documentBlockToPart(block, index) {
|
|
5998
|
-
const source = typeof block.source === "object" && block.source !== null ? block.source : {};
|
|
5999
|
-
const mediaType = textOf2(source.media_type) || "application/pdf";
|
|
6000
|
-
const name = textOf2(block.title) || `document.${mediaType === "application/pdf" ? "pdf" : mediaType === "text/plain" ? "txt" : "bin"}`;
|
|
6001
|
-
if (source.type === "base64" && textOf2(source.data)) {
|
|
6002
|
-
const data = textOf2(source.data);
|
|
6003
|
-
return { type: "file", index, name, media_type: mediaType, data, size_bytes: Math.floor(data.replace(/=+$/, "").length * 3 / 4) };
|
|
6004
|
-
}
|
|
6005
|
-
if (source.type === "text" && textOf2(source.data)) {
|
|
6006
|
-
const bytes = new TextEncoder().encode(textOf2(source.data));
|
|
6007
|
-
let binary = "";
|
|
6008
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
6009
|
-
return { type: "file", index, name, media_type: "text/plain", data: btoa(binary), size_bytes: bytes.length };
|
|
6010
|
-
}
|
|
6011
|
-
const url = textOf2(source.url);
|
|
6012
|
-
return url ? { type: "text", index, text: remoteLinkText("document", url) } : null;
|
|
6013
|
-
}
|
|
6014
|
-
function isEmbeddedImage(url) {
|
|
6015
|
-
return /^data:/i.test(url);
|
|
6016
|
-
}
|
|
6017
|
-
function imageLinkText(url) {
|
|
6018
|
-
return remoteLinkText("image", url);
|
|
6019
|
-
}
|
|
6020
|
-
function remoteLinkText(kind, url) {
|
|
6021
|
-
return `[${kind} not carried, linked at ${url}]`;
|
|
6022
|
-
}
|
|
6023
|
-
function imageMediaType(url) {
|
|
6024
|
-
const data = /^data:([a-zA-Z0-9.+-]+\/[a-zA-Z0-9.+-]+)[;,]/.exec(url);
|
|
6025
|
-
if (data) return data[1].toLowerCase();
|
|
6026
|
-
const ext = /\.([a-zA-Z0-9]+)(?:[?#]|$)/.exec(url)?.[1]?.toLowerCase();
|
|
6027
|
-
const byExtension = {
|
|
6028
|
-
png: "image/png",
|
|
6029
|
-
jpg: "image/jpeg",
|
|
6030
|
-
jpeg: "image/jpeg",
|
|
6031
|
-
gif: "image/gif",
|
|
6032
|
-
webp: "image/webp",
|
|
6033
|
-
svg: "image/svg+xml",
|
|
6034
|
-
bmp: "image/bmp",
|
|
6035
|
-
avif: "image/avif"
|
|
6036
|
-
};
|
|
6037
|
-
return ext && byExtension[ext] || "application/octet-stream";
|
|
6038
|
-
}
|
|
6039
|
-
function assistantParts(blocks) {
|
|
6040
|
-
const parts = [];
|
|
6041
|
-
const calls = [];
|
|
6042
|
-
blocks.forEach((raw, index) => {
|
|
6043
|
-
if (typeof raw !== "object" || raw === null) return;
|
|
6044
|
-
const block = raw;
|
|
6045
|
-
switch (block.type) {
|
|
6046
|
-
case "text": {
|
|
6047
|
-
const text2 = textOf2(block.text);
|
|
6048
|
-
if (text2) parts.push({ type: "text", index, text: text2 });
|
|
6049
|
-
return;
|
|
6050
|
-
}
|
|
6051
|
-
case "thinking": {
|
|
6052
|
-
const text2 = textOf2(block.thinking);
|
|
6053
|
-
if (text2) parts.push({ type: "reasoning", index, text: text2, redacted: false });
|
|
6054
|
-
return;
|
|
6055
|
-
}
|
|
6056
|
-
case "image": {
|
|
6057
|
-
const part = imageBlockToPart(block, index);
|
|
6058
|
-
if (part) parts.push(part);
|
|
6059
|
-
return;
|
|
6060
|
-
}
|
|
6061
|
-
case "tool_use": {
|
|
6062
|
-
calls.push({
|
|
6063
|
-
type: "agent.tool_use",
|
|
6064
|
-
part: {
|
|
6065
|
-
type: "tool_call",
|
|
6066
|
-
index,
|
|
6067
|
-
call_id: textOf2(block.id),
|
|
6068
|
-
tool_name: textOf2(block.name),
|
|
6069
|
-
args: block.input ?? {}
|
|
6070
|
-
}
|
|
6071
|
-
});
|
|
6072
|
-
return;
|
|
6073
|
-
}
|
|
6074
|
-
default:
|
|
6075
|
-
return;
|
|
6076
|
-
}
|
|
6077
|
-
});
|
|
6078
|
-
return { parts, calls };
|
|
6079
|
-
}
|
|
6080
|
-
function toolResults(blocks) {
|
|
6081
|
-
const out = [];
|
|
6082
|
-
blocks.forEach((raw, index) => {
|
|
6083
|
-
if (typeof raw !== "object" || raw === null) return;
|
|
6084
|
-
const block = raw;
|
|
6085
|
-
if (block.type !== "tool_result") return;
|
|
6086
|
-
const content = block.content;
|
|
6087
|
-
const output2 = typeof content === "string" ? content : content === void 0 ? "" : JSON.stringify(content);
|
|
6088
|
-
out.push({
|
|
6089
|
-
type: "agent.tool_result",
|
|
6090
|
-
part: {
|
|
6091
|
-
type: "tool_result",
|
|
6092
|
-
index,
|
|
6093
|
-
call_id: textOf2(block.tool_use_id),
|
|
6094
|
-
tool_name: "",
|
|
6095
|
-
status: block.is_error === true ? "error" : "ok",
|
|
6096
|
-
result: { output: output2 }
|
|
6097
|
-
}
|
|
6098
|
-
});
|
|
6099
|
-
});
|
|
6100
|
-
return out;
|
|
6101
|
-
}
|
|
6102
|
-
var RENDERED_BLOCKS = /* @__PURE__ */ new Set(["text", "thinking", "image", "document", "tool_use", "tool_result"]);
|
|
6103
|
-
function unsupportedBlock(content) {
|
|
6104
|
-
if (!Array.isArray(content)) return false;
|
|
6105
|
-
return content.some((raw) => {
|
|
6106
|
-
if (typeof raw !== "object" || raw === null) return false;
|
|
6107
|
-
const type = raw.type;
|
|
6108
|
-
return typeof type === "string" && !RENDERED_BLOCKS.has(type);
|
|
6109
|
-
});
|
|
6110
|
-
}
|
|
6111
|
-
function preservedAsJson(label, filename, payload, reason2) {
|
|
6112
|
-
const text2 = JSON.stringify(payload);
|
|
6113
|
-
const bytes = new TextEncoder().encode(text2);
|
|
6114
|
-
let binary = "";
|
|
6115
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
6116
|
-
return {
|
|
6117
|
-
events: [{ type: "agent.message", parts: [
|
|
6118
|
-
{ type: "text", index: 0, text: label },
|
|
6119
|
-
{ type: "file", index: 1, name: filename, media_type: "application/json", data: btoa(binary), size_bytes: bytes.length }
|
|
6120
|
-
] }],
|
|
6121
|
-
notes: [{ kind: "unsupported", reason: reason2 }]
|
|
6122
|
-
};
|
|
6123
|
-
}
|
|
6124
|
-
function decodeLine(line2) {
|
|
6125
|
-
const verdict = triage(line2);
|
|
6126
|
-
if (!verdict.keep) return { events: [], notes: [{ kind: "dropped", reason: verdict.reason }] };
|
|
6127
|
-
const type = line2.type;
|
|
6128
|
-
if (type === "attachment") {
|
|
6129
|
-
const payload = typeof line2.attachment === "object" && line2.attachment !== null ? line2.attachment : line2;
|
|
6130
|
-
if (payload.type === "queued_command") {
|
|
6131
|
-
const text2 = textOf2(payload.prompt);
|
|
6132
|
-
if (!text2) return { events: [], notes: [] };
|
|
6133
|
-
return {
|
|
6134
|
-
events: [{ type: "user.message", parts: [{ type: "text", index: 0, text: text2 }] }],
|
|
6135
|
-
notes: []
|
|
6136
|
-
};
|
|
6137
|
-
}
|
|
6138
|
-
if (payload.type === "file" || payload.type === "edited_text_file") {
|
|
6139
|
-
const name = textOf2(payload.displayPath) || basename6(textOf2(payload.filename)) || "attachment.txt";
|
|
6140
|
-
const content2 = payload.content;
|
|
6141
|
-
const nested = content2 && typeof content2 === "object" ? content2 : {};
|
|
6142
|
-
const file = nested.file && typeof nested.file === "object" ? nested.file : {};
|
|
6143
|
-
const text2 = typeof content2 === "string" ? content2 : textOf2(file.content) || textOf2(nested.content) || textOf2(payload.snippet);
|
|
6144
|
-
const bytes = new TextEncoder().encode(text2);
|
|
6145
|
-
let binary = "";
|
|
6146
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
6147
|
-
if (!name) return { events: [], notes: [] };
|
|
6148
|
-
return {
|
|
6149
|
-
events: [
|
|
6150
|
-
{
|
|
6151
|
-
type: "user.message",
|
|
6152
|
-
parts: [{ type: "file", index: 0, name, media_type: guessMediaType(name), ...text2 ? { data: btoa(binary), size_bytes: bytes.length } : {} }]
|
|
6153
|
-
}
|
|
6154
|
-
],
|
|
6155
|
-
notes: []
|
|
6156
|
-
};
|
|
6157
|
-
}
|
|
6158
|
-
return preservedAsJson(
|
|
6159
|
-
`Source attachment: ${textOf2(payload.type) || "unnamed"}`,
|
|
6160
|
-
"source-attachment.json",
|
|
6161
|
-
payload,
|
|
6162
|
-
`attachment:${textOf2(payload.type) || "unnamed"} preserved as JSON`
|
|
6163
|
-
);
|
|
6164
|
-
}
|
|
6165
|
-
const messageContent = typeof line2.message === "object" && line2.message !== null ? line2.message.content : null;
|
|
6166
|
-
if (unsupportedBlock(messageContent)) {
|
|
6167
|
-
return preservedAsJson(
|
|
6168
|
-
`Source record: ${type || "untyped"} (it carries a block this reader does not render)`,
|
|
6169
|
-
"source-record.json",
|
|
6170
|
-
line2,
|
|
6171
|
-
`unsupported-block:${type || "untyped"} preserved as JSON`
|
|
6172
|
-
);
|
|
6173
|
-
}
|
|
6174
|
-
if (verdict.reason.startsWith("unclassified:")) {
|
|
6175
|
-
return preservedAsJson(
|
|
6176
|
-
`Source record: ${type || "untyped"}`,
|
|
6177
|
-
"source-record.json",
|
|
6178
|
-
line2,
|
|
6179
|
-
`${verdict.reason} preserved as JSON`
|
|
6180
|
-
);
|
|
6181
|
-
}
|
|
6182
|
-
const message2 = typeof line2.message === "object" && line2.message !== null ? line2.message : null;
|
|
6183
|
-
if (!message2) return { events: [], notes: [] };
|
|
6184
|
-
const content = message2.content;
|
|
6185
|
-
if (type === "user") {
|
|
6186
|
-
if (typeof content === "string") {
|
|
6187
|
-
if (isInjectedTurn(line2) || !content.trim()) return { events: [], notes: [] };
|
|
6188
|
-
return {
|
|
6189
|
-
events: [{ type: "user.message", parts: [{ type: "text", index: 0, text: content }] }],
|
|
6190
|
-
notes: []
|
|
6191
|
-
};
|
|
6192
|
-
}
|
|
6193
|
-
if (!Array.isArray(content)) return { events: [], notes: [] };
|
|
6194
|
-
if (looksInterrupted(content)) {
|
|
6195
|
-
return {
|
|
6196
|
-
events: [
|
|
6197
|
-
{ type: "agent.status", part: { type: "status", index: 0, level: "idle", text: "Conversation interrupted" } }
|
|
6198
|
-
],
|
|
6199
|
-
notes: [{ kind: "interrupted" }]
|
|
6200
|
-
};
|
|
6201
|
-
}
|
|
6202
|
-
const results = toolResults(content);
|
|
6203
|
-
if (isInjectedTurn(line2)) {
|
|
6204
|
-
if (results.length > 0) return { events: results, notes: [] };
|
|
6205
|
-
if (isImageCompanion(content)) {
|
|
6206
|
-
const parts2 = [];
|
|
6207
|
-
let images = 0;
|
|
6208
|
-
content.forEach((raw, index) => {
|
|
6209
|
-
if (typeof raw !== "object" || raw === null) return;
|
|
6210
|
-
const b = raw;
|
|
6211
|
-
if (b.type === "image") {
|
|
6212
|
-
const part = imageBlockToPart(b, index);
|
|
6213
|
-
if (part) {
|
|
6214
|
-
parts2.push(part);
|
|
6215
|
-
images += 1;
|
|
6216
|
-
}
|
|
6217
|
-
} else if (typeof b.text === "string" && b.text) {
|
|
6218
|
-
parts2.push({ type: "text", index, text: b.text });
|
|
6219
|
-
}
|
|
6220
|
-
});
|
|
6221
|
-
if (parts2.length === 0) return { events: [], notes: [{ kind: "dropped", reason: "injected turn" }] };
|
|
6222
|
-
return {
|
|
6223
|
-
events: [{ type: "user.message", parts: parts2 }],
|
|
6224
|
-
notes: [{ kind: "image-companion", count: images }]
|
|
6225
|
-
};
|
|
6226
|
-
}
|
|
6227
|
-
return { events: [], notes: [{ kind: "dropped", reason: "injected turn" }] };
|
|
6228
|
-
}
|
|
6229
|
-
const parts = [];
|
|
6230
|
-
content.forEach((raw, index) => {
|
|
6231
|
-
if (typeof raw !== "object" || raw === null) return;
|
|
6232
|
-
const b = raw;
|
|
6233
|
-
if (b.type === "text") {
|
|
6234
|
-
const text2 = textOf2(b.text);
|
|
6235
|
-
if (text2.trim()) parts.push({ type: "text", index, text: text2 });
|
|
6236
|
-
} else if (b.type === "image") {
|
|
6237
|
-
const part = imageBlockToPart(b, index);
|
|
6238
|
-
if (part) parts.push(part);
|
|
6239
|
-
} else if (b.type === "document") {
|
|
6240
|
-
const part = documentBlockToPart(b, index);
|
|
6241
|
-
if (part) parts.push(part);
|
|
6242
|
-
}
|
|
6243
|
-
});
|
|
6244
|
-
const events2 = [...results];
|
|
6245
|
-
if (parts.length > 0) events2.push({ type: "user.message", parts });
|
|
6246
|
-
return { events: events2, notes: [] };
|
|
6247
|
-
}
|
|
6248
|
-
if (type === "assistant" && Array.isArray(content)) {
|
|
6249
|
-
const { parts, calls } = assistantParts(content);
|
|
6250
|
-
const events2 = [];
|
|
6251
|
-
if (parts.length > 0) events2.push({ type: "agent.message", parts });
|
|
6252
|
-
events2.push(...calls);
|
|
6253
|
-
return {
|
|
6254
|
-
events: events2,
|
|
6255
|
-
notes: [],
|
|
6256
|
-
spec: {
|
|
6257
|
-
llm: textOf2(message2.model) || void 0,
|
|
6258
|
-
reasoningEffort: textOf2(line2.effort) || void 0
|
|
6259
|
-
}
|
|
6260
|
-
};
|
|
6261
|
-
}
|
|
6262
|
-
return { events: [], notes: [] };
|
|
6263
|
-
}
|
|
6264
|
-
|
|
6265
|
-
// ../../packages/spec/src/native/codex.ts
|
|
6266
|
-
var EMPTY = { events: [], spec: {} };
|
|
6267
|
-
function str2(value) {
|
|
6268
|
-
return typeof value === "string" ? value : "";
|
|
6269
|
-
}
|
|
6270
|
-
function record(value) {
|
|
6271
|
-
return typeof value === "object" && value !== null ? value : null;
|
|
6272
|
-
}
|
|
6273
|
-
function messageText(content) {
|
|
6274
|
-
if (typeof content === "string") return content;
|
|
6275
|
-
if (!Array.isArray(content)) return "";
|
|
6276
|
-
return content.map((block) => {
|
|
6277
|
-
const b = record(block);
|
|
6278
|
-
if (!b) return "";
|
|
6279
|
-
return str2(b.text) || str2(b.output_text);
|
|
6280
|
-
}).join("");
|
|
6281
|
-
}
|
|
6282
|
-
function imageMediaType2(url) {
|
|
6283
|
-
const data = /^data:([a-zA-Z0-9.+-]+\/[a-zA-Z0-9.+-]+)[;,]/.exec(url);
|
|
6284
|
-
if (data) return data[1].toLowerCase();
|
|
6285
|
-
const ext = /\.([a-zA-Z0-9]+)(?:[?#]|$)/.exec(url)?.[1]?.toLowerCase();
|
|
6286
|
-
const byExtension = {
|
|
6287
|
-
png: "image/png",
|
|
6288
|
-
jpg: "image/jpeg",
|
|
6289
|
-
jpeg: "image/jpeg",
|
|
6290
|
-
gif: "image/gif",
|
|
6291
|
-
webp: "image/webp",
|
|
6292
|
-
svg: "image/svg+xml",
|
|
6293
|
-
bmp: "image/bmp",
|
|
6294
|
-
avif: "image/avif"
|
|
6295
|
-
};
|
|
6296
|
-
return ext && byExtension[ext] || "application/octet-stream";
|
|
6297
|
-
}
|
|
6298
|
-
function messageParts(content) {
|
|
6299
|
-
if (typeof content === "string") {
|
|
6300
|
-
return content ? { parts: [{ type: "text", index: 0, text: content }], text: content } : { parts: [], text: "" };
|
|
6301
|
-
}
|
|
6302
|
-
if (!Array.isArray(content)) return { parts: [], text: "" };
|
|
6303
|
-
const parts = [];
|
|
6304
|
-
let text2 = "";
|
|
6305
|
-
for (const raw of content) {
|
|
6306
|
-
const b = record(raw);
|
|
6307
|
-
if (!b) continue;
|
|
6308
|
-
if (b.type === "input_image" || b.type === "image" || b.type === "image_url") {
|
|
6309
|
-
const url = str2(b.image_url) || str2(record(b.image_url)?.url) || str2(b.url);
|
|
6310
|
-
const declared = str2(b.media_type) || str2(b.mime_type);
|
|
6311
|
-
if (url && isEmbeddedImage(url)) parts.push({ type: "image", index: parts.length, media_type: declared || imageMediaType2(url), uri: url });
|
|
6312
|
-
else if (url) parts.push({ type: "text", index: parts.length, text: imageLinkText(url) });
|
|
6313
|
-
continue;
|
|
6314
|
-
}
|
|
6315
|
-
const chunk = str2(b.text) || str2(b.output_text);
|
|
6316
|
-
if (!chunk) continue;
|
|
6317
|
-
text2 += chunk;
|
|
6318
|
-
const last = parts[parts.length - 1];
|
|
6319
|
-
if (last && last.type === "text") last.text += chunk;
|
|
6320
|
-
else parts.push({ type: "text", index: parts.length, text: chunk });
|
|
6321
|
-
}
|
|
6322
|
-
return { parts, text: text2 };
|
|
6323
|
-
}
|
|
6324
|
-
function reasoningText(payload) {
|
|
6325
|
-
const direct = str2(payload.text);
|
|
6326
|
-
if (direct) return direct;
|
|
6327
|
-
const summary = payload.summary;
|
|
6328
|
-
if (typeof summary === "string") return summary;
|
|
6329
|
-
if (Array.isArray(summary)) {
|
|
6330
|
-
return summary.map((entry) => typeof entry === "string" ? entry : str2(record(entry)?.text)).filter(Boolean).join("\n");
|
|
6331
|
-
}
|
|
6332
|
-
return "";
|
|
6333
|
-
}
|
|
6334
|
-
function callArgs(payload) {
|
|
6335
|
-
const raw = payload.arguments;
|
|
6336
|
-
if (typeof raw === "string" && raw.trim()) {
|
|
6337
|
-
if (unsafeNumberSpans(raw).length > 0) return { arguments: raw };
|
|
6338
|
-
try {
|
|
6339
|
-
const parsed = JSON.parse(raw);
|
|
6340
|
-
if (record(parsed)) return parsed;
|
|
6341
|
-
return { arguments: parsed };
|
|
6342
|
-
} catch {
|
|
6343
|
-
return { arguments: raw };
|
|
6344
|
-
}
|
|
6345
|
-
}
|
|
6346
|
-
return record(payload.action) ?? record(payload.input) ?? {};
|
|
6347
|
-
}
|
|
6348
|
-
var INJECTED_USER_OPENERS = [
|
|
6349
|
-
"# AGENTS.md instructions",
|
|
6350
|
-
"<INSTRUCTIONS>",
|
|
6351
|
-
"<codex_internal_context",
|
|
6352
|
-
"<in-app-browser-context",
|
|
6353
|
-
"<user_instructions>",
|
|
6354
|
-
"<environment_context>",
|
|
6355
|
-
"[Context: repo="
|
|
6356
|
-
];
|
|
6357
|
-
function looksInjected(text2) {
|
|
6358
|
-
const head = text2.trimStart();
|
|
6359
|
-
return INJECTED_USER_OPENERS.some((marker) => head.startsWith(marker));
|
|
6360
|
-
}
|
|
6361
|
-
function toolName(payload) {
|
|
6362
|
-
const named = str2(payload.name);
|
|
6363
|
-
if (named) return named;
|
|
6364
|
-
if (payload.type === "local_shell_call") return "shell";
|
|
6365
|
-
return str2(payload.type) || "tool";
|
|
6366
|
-
}
|
|
6367
|
-
function callIdOf(payload) {
|
|
6368
|
-
return str2(payload.call_id);
|
|
6369
|
-
}
|
|
6370
|
-
function callOrOwnId(payload) {
|
|
6371
|
-
return str2(payload.call_id) || str2(payload.id);
|
|
6372
|
-
}
|
|
6373
|
-
function decodeCodexLine(line2) {
|
|
6374
|
-
const type = str2(line2.type);
|
|
6375
|
-
const payload = record(line2.payload);
|
|
6376
|
-
if (type === "session_meta") {
|
|
6377
|
-
if (!payload) return EMPTY;
|
|
6378
|
-
return {
|
|
6379
|
-
events: [],
|
|
6380
|
-
spec: {}
|
|
6381
|
-
};
|
|
6382
|
-
}
|
|
6383
|
-
if (type === "turn_context") {
|
|
6384
|
-
if (!payload) return EMPTY;
|
|
6385
|
-
return {
|
|
6386
|
-
events: [],
|
|
6387
|
-
spec: {
|
|
6388
|
-
llm: str2(payload.model) || void 0,
|
|
6389
|
-
reasoningEffort: str2(payload.effort) || str2(payload.reasoning_effort) || void 0
|
|
6390
|
-
}
|
|
6391
|
-
};
|
|
6392
|
-
}
|
|
6393
|
-
if (type === "compacted") return { events: [], spec: {} };
|
|
6394
|
-
if (type !== "event_msg" && type !== "response_item") return EMPTY;
|
|
6395
|
-
if (!payload) return EMPTY;
|
|
6396
|
-
const kind = str2(payload.type);
|
|
6397
|
-
if (kind === "message") {
|
|
6398
|
-
const role = str2(payload.role);
|
|
6399
|
-
if (role === "developer" || role === "system") return EMPTY;
|
|
6400
|
-
const { parts, text: text2 } = messageParts(payload.content);
|
|
6401
|
-
if (parts.length === 0) return EMPTY;
|
|
6402
|
-
if (role === "user" && text2.trim() && looksInjected(text2)) return EMPTY;
|
|
6403
|
-
if (role === "user") return { events: [{ type: "user.message", parts }], spec: {} };
|
|
6404
|
-
if (role === "assistant") return { events: [{ type: "agent.message", parts }], spec: {} };
|
|
6405
|
-
return EMPTY;
|
|
6406
|
-
}
|
|
6407
|
-
if (kind === "agent_message" || kind === "agent_message_delta") {
|
|
6408
|
-
const text2 = messageText(payload.content) || str2(payload.delta) || str2(payload.text);
|
|
6409
|
-
if (!text2) return EMPTY;
|
|
6410
|
-
const from = str2(payload.author) || "agent";
|
|
6411
|
-
const to = str2(payload.recipient);
|
|
6412
|
-
return { events: [{ type: "agent.message", parts: [{ type: "text", index: 0, text: `[${from}${to ? ` \u2192 ${to}` : ""}]
|
|
6413
|
-
${text2}` }] }], spec: {} };
|
|
6414
|
-
}
|
|
6415
|
-
if (kind === "reasoning") {
|
|
6416
|
-
const text2 = reasoningText(payload);
|
|
6417
|
-
if (!text2.trim()) return EMPTY;
|
|
6418
|
-
return {
|
|
6419
|
-
events: [
|
|
6420
|
-
{ type: "agent.reasoning", part: { type: "reasoning", index: 0, text: text2, redacted: false } }
|
|
6421
|
-
],
|
|
6422
|
-
spec: {}
|
|
6423
|
-
};
|
|
6424
|
-
}
|
|
6425
|
-
if (kind === "function_call" || kind === "local_shell_call" || kind === "custom_tool_call") {
|
|
6426
|
-
const id2 = callOrOwnId(payload);
|
|
6427
|
-
if (!id2) return EMPTY;
|
|
6428
|
-
return {
|
|
6429
|
-
events: [
|
|
6430
|
-
{
|
|
6431
|
-
type: "agent.tool_use",
|
|
6432
|
-
part: {
|
|
6433
|
-
type: "tool_call",
|
|
6434
|
-
index: 0,
|
|
6435
|
-
call_id: id2,
|
|
6436
|
-
tool_name: toolName(payload),
|
|
6437
|
-
args: callArgs(payload)
|
|
6438
|
-
}
|
|
6439
|
-
}
|
|
6440
|
-
],
|
|
6441
|
-
spec: {}
|
|
6442
|
-
};
|
|
6443
|
-
}
|
|
6444
|
-
if (kind === "function_call_output" || kind === "custom_tool_call_output") {
|
|
6445
|
-
const id2 = callIdOf(payload);
|
|
6446
|
-
if (!id2) return {
|
|
6447
|
-
events: [{ type: "agent.message", parts: [{
|
|
6448
|
-
type: "text",
|
|
6449
|
-
index: 0,
|
|
6450
|
-
text: `[Imported tool output: ${str2(payload.name) || "unknown tool"}; source has no call ID]
|
|
6451
|
-
${typeof payload.output === "string" ? payload.output : JSON.stringify(payload.output ?? "")}`
|
|
6452
|
-
}] }],
|
|
6453
|
-
spec: {},
|
|
6454
|
-
unattachedResult: true
|
|
6455
|
-
};
|
|
6456
|
-
const output2 = payload.output;
|
|
6457
|
-
const inner = record(output2);
|
|
6458
|
-
const text2 = typeof output2 === "string" ? output2 : inner && typeof inner.output === "string" ? inner.output : JSON.stringify(output2 ?? "");
|
|
6459
|
-
const failed = inner && inner.success === false || record(inner?.metadata)?.exit_code !== void 0 && record(inner?.metadata)?.exit_code !== 0;
|
|
6460
|
-
return {
|
|
6461
|
-
events: [
|
|
6462
|
-
{
|
|
6463
|
-
type: "agent.tool_result",
|
|
6464
|
-
part: {
|
|
6465
|
-
type: "tool_result",
|
|
6466
|
-
index: 0,
|
|
6467
|
-
call_id: id2,
|
|
6468
|
-
tool_name: "",
|
|
6469
|
-
status: failed ? "error" : "ok",
|
|
6470
|
-
result: { output: text2 }
|
|
6471
|
-
}
|
|
6472
|
-
}
|
|
6473
|
-
],
|
|
6474
|
-
spec: {}
|
|
6475
|
-
};
|
|
6476
|
-
}
|
|
6477
|
-
if (kind === "turn_aborted") {
|
|
6478
|
-
return {
|
|
6479
|
-
events: [
|
|
6480
|
-
{
|
|
6481
|
-
type: "agent.status",
|
|
6482
|
-
part: { type: "status", index: 0, level: "idle", text: "Turn interrupted" }
|
|
6483
|
-
}
|
|
6484
|
-
],
|
|
6485
|
-
spec: {}
|
|
6486
|
-
};
|
|
6487
|
-
}
|
|
6488
|
-
if (type === "response_item" && kind) {
|
|
6489
|
-
const text2 = JSON.stringify(line2);
|
|
6490
|
-
const bytes = new TextEncoder().encode(text2);
|
|
6491
|
-
let binary = "";
|
|
6492
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
6493
|
-
return {
|
|
6494
|
-
events: [{ type: "agent.message", parts: [
|
|
6495
|
-
{ type: "text", index: 0, text: `Source record: ${kind} (this reader does not render it)` },
|
|
6496
|
-
{ type: "file", index: 1, name: "source-record.json", media_type: "application/json", data: btoa(binary), size_bytes: bytes.length }
|
|
6497
|
-
] }],
|
|
6498
|
-
spec: {}
|
|
6499
|
-
};
|
|
6500
|
-
}
|
|
6501
|
-
return EMPTY;
|
|
6502
|
-
}
|
|
6503
|
-
|
|
6504
|
-
// ../../packages/spec/src/native/index.ts
|
|
6505
|
-
function parseNative(engine, records) {
|
|
6506
|
-
const parse = { events: [], notes: [], spec: {}, unattachedResults: 0 };
|
|
6507
|
-
const absorb = (spec) => {
|
|
6508
|
-
for (const [key, value] of Object.entries(spec ?? {})) {
|
|
6509
|
-
if (value !== void 0) parse.spec[key] = value;
|
|
6510
|
-
}
|
|
6511
|
-
};
|
|
6512
|
-
for (const record3 of records) {
|
|
6513
|
-
if (engine === "codex") {
|
|
6514
|
-
const decoded2 = decodeCodexLine(record3);
|
|
6515
|
-
parse.events.push(...decoded2.events);
|
|
6516
|
-
if (decoded2.unattachedResult) parse.unattachedResults += 1;
|
|
6517
|
-
absorb(decoded2.spec);
|
|
6518
|
-
} else {
|
|
6519
|
-
const decoded2 = decodeLine(record3);
|
|
6520
|
-
parse.events.push(...decoded2.events);
|
|
6521
|
-
parse.notes.push(...decoded2.notes);
|
|
6522
|
-
absorb(decoded2.spec);
|
|
6523
|
-
}
|
|
6524
|
-
}
|
|
6525
|
-
return parse;
|
|
6526
|
-
}
|
|
6527
|
-
|
|
6528
|
-
// ../../packages/conversation/src/platform-text.ts
|
|
6529
|
-
var INPUT_SCOPE = /\n\n<agentsky-input-scope>[^\n]*<\/agentsky-input-scope>(?=$|\n\n<attachments>\n)/;
|
|
6530
|
-
var SYSTEM_SECTION = /^<system-reminder>\n([\s\S]*?)\n<\/system-reminder>(?:\n\n|$)/;
|
|
6531
|
-
var APP_CONTEXT = /\s*<app_context>[\s\S]*?(?:<\/app_context>|$)/g;
|
|
6532
|
-
var HAS_APP_CONTEXT = /<app_context>/;
|
|
6533
|
-
var HARNESS_TURN = /^\s*(?:<(task-notification|local-command-caveat|local-command-stdout|local-command-stderr|command-name|command-message|command-args)>[\s\S]*?<\/\1>\s*)+$/;
|
|
6534
|
-
var RECOVERY_NOTICE_CLOSING = "Preserve completed work; do not repeat completed actions.";
|
|
6535
|
-
var RECOVERY_NOTICE_OPENING = /^(?:The subscription usage limit that stopped the previous request has reset\.|.{0,240}?Continue the interrupted task from its current state\.)/s;
|
|
6536
|
-
var EARLIER = /<earlier_conversation>\n([\s\S]*?)\n?<\/earlier_conversation>/;
|
|
6537
|
-
function earlierTurns(system) {
|
|
6538
|
-
const block = EARLIER.exec(system)?.[1];
|
|
6539
|
-
if (!block) return [];
|
|
6540
|
-
const turns = [];
|
|
6541
|
-
for (const line2 of block.split("\n")) {
|
|
6542
|
-
try {
|
|
6543
|
-
const entry = JSON.parse(line2);
|
|
6544
|
-
if (typeof entry.text !== "string" || !entry.text.trim()) continue;
|
|
6545
|
-
turns.push({ role: entry.from === "Agent" ? "agent" : "user", text: entry.text, at: typeof entry.at === "string" ? entry.at : "" });
|
|
6546
|
-
} catch {
|
|
6547
|
-
continue;
|
|
6548
|
-
}
|
|
6549
|
-
}
|
|
6550
|
-
return turns;
|
|
6551
|
-
}
|
|
6552
|
-
function isRecoveryNotice(text2) {
|
|
6553
|
-
const trimmed = text2.trim();
|
|
6554
|
-
return trimmed.endsWith(RECOVERY_NOTICE_CLOSING) && RECOVERY_NOTICE_OPENING.test(trimmed);
|
|
6555
|
-
}
|
|
6556
|
-
function personText(raw) {
|
|
6557
|
-
let text2 = raw.replace(INPUT_SCOPE, "");
|
|
6558
|
-
const earlier = [];
|
|
6559
|
-
for (let section = SYSTEM_SECTION.exec(text2); section; section = SYSTEM_SECTION.exec(text2)) {
|
|
6560
|
-
earlier.push(...earlierTurns(section[1] ?? ""));
|
|
6561
|
-
text2 = text2.slice(section[0].length);
|
|
6562
|
-
}
|
|
6563
|
-
text2 = text2.replace(INPUT_SCOPE, "");
|
|
6564
|
-
if (HAS_APP_CONTEXT.test(text2)) text2 = text2.replace(APP_CONTEXT, "").trim();
|
|
6565
|
-
if (!text2.trim() || HARNESS_TURN.test(text2) || isRecoveryNotice(text2)) text2 = "";
|
|
6566
|
-
return { text: text2, earlier };
|
|
6567
|
-
}
|
|
6568
|
-
|
|
6569
|
-
// ../../packages/conversation/src/read.ts
|
|
6570
|
-
var THINKING_BLOCKS = /* @__PURE__ */ new Set(["thinking", "redacted_thinking"]);
|
|
6571
|
-
var PRESERVED_RECORDS = /* @__PURE__ */ new Set(["source-record.json", "source-attachment.json"]);
|
|
6572
|
-
function record2(value) {
|
|
6573
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
6574
|
-
}
|
|
6575
|
-
function str3(value) {
|
|
6576
|
-
return typeof value === "string" ? value : "";
|
|
6577
|
-
}
|
|
6578
|
-
function jsonLines(text2) {
|
|
6579
|
-
const lines2 = [];
|
|
6580
|
-
for (const line2 of text2.split("\n")) {
|
|
6581
|
-
if (!line2.trim()) continue;
|
|
6582
|
-
try {
|
|
6583
|
-
const parsed = record2(JSON.parse(line2));
|
|
6584
|
-
if (parsed) lines2.push(parsed);
|
|
6585
|
-
} catch {
|
|
6586
|
-
continue;
|
|
6587
|
-
}
|
|
6588
|
-
}
|
|
6589
|
-
return lines2;
|
|
6590
|
-
}
|
|
6591
|
-
function reasoningOf(block, index) {
|
|
6592
|
-
return block.type === "thinking" ? { type: "reasoning", index, text: str3(block.thinking), redacted: false } : { type: "reasoning", index, text: "", redacted: true };
|
|
6593
|
-
}
|
|
6594
|
-
function withoutThinking(line2) {
|
|
6595
|
-
const message2 = record2(line2.message);
|
|
6596
|
-
if (line2.type !== "assistant" || !message2 || !Array.isArray(message2.content)) return { line: line2, reasoning: [] };
|
|
6597
|
-
const reasoning = [];
|
|
6598
|
-
const content = message2.content.filter((raw, index) => {
|
|
6599
|
-
const block = record2(raw);
|
|
6600
|
-
if (!block || !THINKING_BLOCKS.has(str3(block.type))) return true;
|
|
6601
|
-
reasoning.push(reasoningOf(block, index));
|
|
6602
|
-
return false;
|
|
6603
|
-
});
|
|
6604
|
-
return { line: { ...line2, message: { ...message2, content } }, reasoning };
|
|
6605
|
-
}
|
|
6606
|
-
var Fold = class {
|
|
6607
|
-
messages = [];
|
|
6608
|
-
calls = /* @__PURE__ */ new Map();
|
|
6609
|
-
engine;
|
|
6610
|
-
constructor(engine) {
|
|
6611
|
-
this.engine = engine;
|
|
6612
|
-
}
|
|
6613
|
-
open(role, at) {
|
|
6614
|
-
const message2 = { id: `m${this.messages.length}`, role, created_at: at, parts: [], metadata: { engine: this.engine } };
|
|
6615
|
-
this.messages.push(message2);
|
|
6616
|
-
return message2;
|
|
6617
|
-
}
|
|
6618
|
-
step(at) {
|
|
6619
|
-
const last = this.messages.at(-1);
|
|
6620
|
-
if (last && last.role === "agent" && !last.parts.some((part) => part.type === "tool_result")) return last;
|
|
6621
|
-
return this.open("agent", at);
|
|
6622
|
-
}
|
|
6623
|
-
add(message2, part) {
|
|
6624
|
-
message2.parts.push({ ...part, index: message2.parts.length });
|
|
6625
|
-
}
|
|
6626
|
-
reasoning(parts, at) {
|
|
6627
|
-
if (!parts.length) return;
|
|
6628
|
-
const message2 = this.step(at);
|
|
6629
|
-
for (const part of parts) this.add(message2, part);
|
|
6630
|
-
}
|
|
6631
|
-
event(event, at) {
|
|
6632
|
-
switch (event.type) {
|
|
6633
|
-
case "user.message": {
|
|
6634
|
-
const parts = [];
|
|
6635
|
-
for (const part of event.parts) {
|
|
6636
|
-
if (part.type === "file" && PRESERVED_RECORDS.has(part.name)) continue;
|
|
6637
|
-
if (part.type !== "text") {
|
|
6638
|
-
parts.push(part);
|
|
6639
|
-
continue;
|
|
6640
|
-
}
|
|
6641
|
-
const { text: text2, earlier } = personText(part.text);
|
|
6642
|
-
if (!this.messages.length) for (const turn of earlier) this.add(this.open(turn.role, turn.at || at), { type: "text", index: 0, text: turn.text });
|
|
6643
|
-
if (text2) parts.push({ ...part, text: text2 });
|
|
6644
|
-
}
|
|
6645
|
-
if (!parts.length) return;
|
|
6646
|
-
const message2 = this.open("user", at);
|
|
6647
|
-
for (const part of parts) this.add(message2, part);
|
|
6648
|
-
return;
|
|
6649
|
-
}
|
|
6650
|
-
case "agent.message": {
|
|
6651
|
-
if (event.parts.some((part) => part.type === "file" && PRESERVED_RECORDS.has(part.name))) return;
|
|
6652
|
-
const message2 = this.step(at);
|
|
6653
|
-
for (const part of event.parts) this.add(message2, part);
|
|
6654
|
-
return;
|
|
6655
|
-
}
|
|
6656
|
-
case "agent.reasoning":
|
|
6657
|
-
this.add(this.step(at), event.part);
|
|
6658
|
-
return;
|
|
6659
|
-
case "agent.tool_use": {
|
|
6660
|
-
const message2 = this.step(at);
|
|
6661
|
-
this.add(message2, event.part);
|
|
6662
|
-
this.calls.set(event.part.call_id, { message: message2, call: message2.parts.at(-1) });
|
|
6663
|
-
return;
|
|
6664
|
-
}
|
|
6665
|
-
case "agent.tool_result": {
|
|
6666
|
-
const owner = this.calls.get(event.part.call_id);
|
|
6667
|
-
if (!owner) return;
|
|
6668
|
-
this.add(owner.message, { ...event.part, tool_name: owner.call.tool_name });
|
|
6669
|
-
return;
|
|
6670
|
-
}
|
|
6671
|
-
default:
|
|
6672
|
-
return;
|
|
6673
|
-
}
|
|
6674
|
-
}
|
|
6675
|
-
};
|
|
6676
|
-
function claudeCode(lines2) {
|
|
6677
|
-
const fold = new Fold("claude_code");
|
|
6678
|
-
let nativeId = null;
|
|
6679
|
-
let cwd = null;
|
|
6680
|
-
let model = null;
|
|
6681
|
-
for (const raw of lines2) {
|
|
6682
|
-
if (raw.isSidechain === true) continue;
|
|
6683
|
-
nativeId ??= str3(raw.sessionId) || null;
|
|
6684
|
-
cwd ??= str3(raw.cwd) || null;
|
|
6685
|
-
const at = str3(raw.timestamp);
|
|
6686
|
-
const { line: line2, reasoning } = withoutThinking(raw);
|
|
6687
|
-
const parse = parseNative("claude_code", [line2]);
|
|
6688
|
-
if (parse.spec.llm && parse.spec.llm !== "<synthetic>") model = parse.spec.llm;
|
|
6689
|
-
fold.reasoning(reasoning, at);
|
|
6690
|
-
for (const event of parse.events) fold.event(event, at);
|
|
6691
|
-
}
|
|
6692
|
-
return { engine: "claude_code", nativeId, cwd, model, messages: fold.messages };
|
|
6693
|
-
}
|
|
6694
|
-
function codex(lines2) {
|
|
6695
|
-
const fold = new Fold("codex");
|
|
6696
|
-
let nativeId = null;
|
|
6697
|
-
let cwd = null;
|
|
6698
|
-
let model = null;
|
|
6699
|
-
let rollout = null;
|
|
6700
|
-
for (const line2 of lines2) {
|
|
6701
|
-
const meta = line2.type === "session_meta" ? record2(line2.payload) : null;
|
|
6702
|
-
if (meta) {
|
|
6703
|
-
rollout ??= str3(meta.id) || null;
|
|
6704
|
-
if (str3(meta.id) !== rollout) continue;
|
|
6705
|
-
nativeId ??= rollout;
|
|
6706
|
-
cwd ??= str3(meta.cwd) || null;
|
|
6707
|
-
continue;
|
|
6708
|
-
}
|
|
6709
|
-
if (record2(line2.payload)?.author && record2(line2.payload)?.author !== "/root") continue;
|
|
6710
|
-
const at = str3(line2.timestamp);
|
|
6711
|
-
const parse = parseNative("codex", [line2]);
|
|
6712
|
-
if (parse.spec.llm) model = parse.spec.llm;
|
|
6713
|
-
const item = record2(line2.payload);
|
|
6714
|
-
for (const event of parse.events) {
|
|
6715
|
-
if (event.type === "agent.tool_use" && item?.type === "custom_tool_call" && typeof item.input === "string") {
|
|
6716
|
-
fold.event({ ...event, part: { ...event.part, args: { input: item.input } } }, at);
|
|
6717
|
-
} else fold.event(event, at);
|
|
6718
|
-
}
|
|
6719
|
-
}
|
|
6720
|
-
return { engine: "codex", nativeId, cwd, model, messages: fold.messages };
|
|
6721
|
-
}
|
|
6722
|
-
function readConversation(engine, text2) {
|
|
6723
|
-
const lines2 = jsonLines(text2);
|
|
6724
|
-
return engine === "codex" ? codex(lines2) : claudeCode(lines2);
|
|
6725
|
-
}
|
|
6726
|
-
|
|
6727
|
-
// ../../packages/conversation/src/write.ts
|
|
6728
|
-
import { randomBytes as randomBytes2, randomUUID as randomUUID4 } from "crypto";
|
|
6729
|
-
|
|
6730
|
-
// ../../packages/conversation/src/conversation.ts
|
|
6731
|
-
var ENGINE_LABEL = { claude_code: "Claude Code", codex: "Codex" };
|
|
6732
|
-
var OTHER_LABELS = { hermes: "Hermes", openclaw: "OpenClaw", pi: "Pi", cursor: "Cursor", grok: "Grok", gemini: "Gemini" };
|
|
6733
|
-
function engineLabel(engine) {
|
|
6734
|
-
return ENGINE_LABEL[engine] ?? OTHER_LABELS[engine] ?? engine;
|
|
6735
|
-
}
|
|
6736
|
-
function isEngine(value) {
|
|
6737
|
-
return value === "claude_code" || value === "codex";
|
|
6738
|
-
}
|
|
6739
|
-
function messageText2(message2) {
|
|
6740
|
-
return message2.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
6741
|
-
}
|
|
6742
|
-
function resultText(part) {
|
|
6743
|
-
const output2 = part.result.output;
|
|
6744
|
-
if (typeof output2 === "string") return output2;
|
|
6745
|
-
return output2 === void 0 ? JSON.stringify(part.result) : JSON.stringify(output2);
|
|
6746
|
-
}
|
|
6747
|
-
|
|
6748
|
-
// ../../packages/conversation/src/fit.ts
|
|
6749
|
-
var CONTEXT_BUDGET_CHARS = { claude_code: 48e4, codex: 64e4 };
|
|
6750
|
-
var PORTABLE_BUDGET_CHARS = 2e5;
|
|
6751
|
-
var MAX_TOOL_OUTPUT_CHARS = 6e4;
|
|
6752
|
-
var IMAGE_CHARS = 6e3;
|
|
6753
|
-
var SUMMARY_SHARE = 0.15;
|
|
6754
|
-
var LINE_CHARS = 400;
|
|
6755
|
-
function size(message2) {
|
|
6756
|
-
let total = 0;
|
|
6757
|
-
for (const part of message2.parts) {
|
|
6758
|
-
if (part.type === "text") total += part.text.length;
|
|
6759
|
-
else if (part.type === "tool_call") total += JSON.stringify(part.args).length + part.tool_name.length;
|
|
6760
|
-
else if (part.type === "tool_result") total += Math.min(resultText(part).length, MAX_TOOL_OUTPUT_CHARS);
|
|
6761
|
-
else if (part.type === "image" || part.type === "file") total += IMAGE_CHARS;
|
|
6762
|
-
}
|
|
6763
|
-
return total;
|
|
6764
|
-
}
|
|
6765
|
-
function clip(text2, max) {
|
|
6766
|
-
const flat = text2.replace(/\s+/g, " ").trim();
|
|
6767
|
-
return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
|
|
6768
|
-
}
|
|
6769
|
-
function fromBothEnds(entries, maxChars) {
|
|
6770
|
-
const order = entries.map((_, index) => index % 2 ? entries.length - 1 - (index >> 1) : index >> 1);
|
|
6771
|
-
const kept = /* @__PURE__ */ new Set();
|
|
6772
|
-
let length = 0;
|
|
6773
|
-
for (const index of order) {
|
|
6774
|
-
if (length + entries[index].length + 1 > maxChars) break;
|
|
6775
|
-
kept.add(index);
|
|
6776
|
-
length += entries[index].length + 1;
|
|
6777
|
-
}
|
|
6778
|
-
const out = [];
|
|
6779
|
-
entries.forEach((entry, index) => {
|
|
6780
|
-
if (kept.has(index)) out.push(entry);
|
|
6781
|
-
else if (kept.has(index - 1) || index === 0 && !kept.has(0)) out.push(`(${entries.length - kept.size} entries left out here)`);
|
|
6782
|
-
});
|
|
6783
|
-
return out;
|
|
6784
|
-
}
|
|
6785
|
-
var listAskedAndAnswered = (older, { maxChars }) => {
|
|
6786
|
-
const tools = /* @__PURE__ */ new Map();
|
|
6787
|
-
const all = [];
|
|
6788
|
-
const asked = [];
|
|
6789
|
-
for (const message2 of older) {
|
|
6790
|
-
for (const part of message2.parts) if (part.type === "tool_call") tools.set(part.tool_name, (tools.get(part.tool_name) ?? 0) + 1);
|
|
6791
|
-
const text2 = messageText2(message2);
|
|
6792
|
-
if (!text2.trim()) continue;
|
|
6793
|
-
const entry = `${message2.role === "user" ? "Asked" : "Answered"}: ${clip(text2, LINE_CHARS)}`;
|
|
6794
|
-
all.push(entry);
|
|
6795
|
-
if (message2.role === "user") asked.push(entry);
|
|
6796
|
-
}
|
|
6797
|
-
const used = [...tools].map(([name, count]) => `${name} \xD7${count}`).join(", ");
|
|
6798
|
-
const tail = used ? `
|
|
6799
|
-
Tools used in that part: ${used}.` : "";
|
|
6800
|
-
const room = maxChars - tail.length;
|
|
6801
|
-
const fits = (entries) => entries.reduce((sum, entry) => sum + entry.length + 1, 0) <= room;
|
|
6802
|
-
const body = fits(all) ? all : fits(asked) ? asked : fromBothEnds(asked, room - 40);
|
|
6803
|
-
return body.join("\n") + tail;
|
|
6804
|
-
};
|
|
6805
|
-
function startsTurn(message2) {
|
|
6806
|
-
return message2.role === "user" && message2.parts.some((part) => part.type === "text" || part.type === "image");
|
|
6807
|
-
}
|
|
6808
|
-
function fitConversation(conversation, to, opts = {}) {
|
|
6809
|
-
const budget = opts.budgetChars ?? (to ? CONTEXT_BUDGET_CHARS[to] : PORTABLE_BUDGET_CHARS);
|
|
6810
|
-
const sizes = conversation.messages.map(size);
|
|
6811
|
-
const total = sizes.reduce((sum, value) => sum + value, 0);
|
|
6812
|
-
if (total <= budget) return { messages: conversation.messages, summarised: 0 };
|
|
6813
|
-
const room = budget * (1 - SUMMARY_SHARE);
|
|
6814
|
-
let start = conversation.messages.length;
|
|
6815
|
-
let kept = 0;
|
|
6816
|
-
for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
|
|
6817
|
-
if (kept + sizes[index] > room) break;
|
|
6818
|
-
kept += sizes[index];
|
|
6819
|
-
start = index;
|
|
6820
|
-
}
|
|
6821
|
-
while (start < conversation.messages.length && !startsTurn(conversation.messages[start])) start += 1;
|
|
6822
|
-
if (start >= conversation.messages.length) {
|
|
6823
|
-
start = conversation.messages.length - 1;
|
|
6824
|
-
while (start > 0 && !startsTurn(conversation.messages[start])) start -= 1;
|
|
6825
|
-
}
|
|
6826
|
-
const older = conversation.messages.slice(0, start);
|
|
6827
|
-
const maxChars = Math.floor(budget * SUMMARY_SHARE);
|
|
6828
|
-
const summary = (opts.summarize ?? listAskedAndAnswered)(older, { from: conversation.engine, to, maxChars }).slice(0, maxChars);
|
|
6829
|
-
const first = older[0]?.created_at ?? "";
|
|
6830
|
-
const note = {
|
|
6831
|
-
id: "summary",
|
|
6832
|
-
role: "user",
|
|
6833
|
-
created_at: first,
|
|
6834
|
-
parts: [{ type: "text", index: 0, text: `[This conversation was continued from ${engineLabel(conversation.engine)}. Its oldest ${older.length} messages were too long to carry and are summarised below; everything after this note is the original conversation, word for word.]
|
|
6835
|
-
|
|
6836
|
-
${summary}` }],
|
|
6837
|
-
metadata: { summary_of: older.length }
|
|
6838
|
-
};
|
|
6839
|
-
return { messages: [note, ...conversation.messages.slice(start)], summarised: older.length };
|
|
6840
|
-
}
|
|
6841
|
-
|
|
6842
|
-
// ../../packages/conversation/src/tools.ts
|
|
6843
|
-
var CLAUDE_CODE_TOOLS = /* @__PURE__ */ new Set([
|
|
6844
|
-
"Bash",
|
|
6845
|
-
"Read",
|
|
6846
|
-
"Write",
|
|
6847
|
-
"Edit",
|
|
6848
|
-
"MultiEdit",
|
|
6849
|
-
"Glob",
|
|
6850
|
-
"Grep",
|
|
6851
|
-
"LS",
|
|
6852
|
-
"WebFetch",
|
|
6853
|
-
"WebSearch",
|
|
6854
|
-
"Task",
|
|
6855
|
-
"Agent",
|
|
6856
|
-
"TodoWrite",
|
|
6857
|
-
"NotebookEdit",
|
|
6858
|
-
"NotebookRead",
|
|
6859
|
-
"BashOutput",
|
|
6860
|
-
"KillShell",
|
|
6861
|
-
"ExitPlanMode",
|
|
6862
|
-
"Skill",
|
|
6863
|
-
"SlashCommand"
|
|
6864
|
-
]);
|
|
6865
|
-
var CODEX_FUNCTIONS = /* @__PURE__ */ new Set(["shell", "shell_command", "exec_command", "write_stdin", "update_plan", "view_image", "web_search"]);
|
|
6866
|
-
function str4(value) {
|
|
6867
|
-
return typeof value === "string" ? value : "";
|
|
6868
|
-
}
|
|
6869
|
-
function quote(value) {
|
|
6870
|
-
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
|
|
6871
|
-
}
|
|
6872
|
-
function absolute(path2, cwd) {
|
|
6873
|
-
if (path2.startsWith("/") || !cwd) return path2;
|
|
6874
|
-
return `${cwd.replace(/\/+$/, "")}/${path2.replace(/^\.\//, "")}`;
|
|
6875
|
-
}
|
|
6876
|
-
function relativeTo(path2, cwd) {
|
|
6877
|
-
if (!cwd) return path2;
|
|
6878
|
-
const root2 = `${cwd.replace(/\/+$/, "")}/`;
|
|
6879
|
-
return path2.startsWith(root2) ? path2.slice(root2.length) : path2;
|
|
6880
|
-
}
|
|
6881
|
-
function lines(text2) {
|
|
6882
|
-
const split = text2.split("\n");
|
|
6883
|
-
if (split.at(-1) === "") split.pop();
|
|
6884
|
-
return split;
|
|
6885
|
-
}
|
|
6886
|
-
function codexCommand(call) {
|
|
6887
|
-
const args = call.args;
|
|
6888
|
-
const workdir = str4(args.workdir) || str4(args.working_directory);
|
|
6889
|
-
if (call.tool_name === "exec_command") return str4(args.cmd) ? { command: str4(args.cmd), workdir } : null;
|
|
6890
|
-
if (call.tool_name === "shell_command") return str4(args.command) ? { command: str4(args.command), workdir } : null;
|
|
6891
|
-
if (call.tool_name !== "shell") return null;
|
|
6892
|
-
const argv = Array.isArray(args.command) ? args.command.filter((part) => typeof part === "string") : [];
|
|
6893
|
-
if (!argv.length) return str4(args.command) ? { command: str4(args.command), workdir } : null;
|
|
6894
|
-
if (argv.length === 3 && /(^|\/)(ba|z)?sh$/.test(argv[0]) && (argv[1] === "-lc" || argv[1] === "-c")) return { command: argv[2], workdir };
|
|
6895
|
-
if (argv[0] === "apply_patch") return null;
|
|
6896
|
-
return { command: argv.map(quote).join(" "), workdir };
|
|
6897
|
-
}
|
|
6898
|
-
function codexPatch(call) {
|
|
6899
|
-
if (call.tool_name === "apply_patch") return str4(call.args.input) || str4(call.args.patch) || null;
|
|
6900
|
-
const argv = Array.isArray(call.args.command) ? call.args.command : [];
|
|
6901
|
-
return call.tool_name === "shell" && argv[0] === "apply_patch" && typeof argv[1] === "string" ? argv[1] : null;
|
|
6902
|
-
}
|
|
6903
|
-
function parsePatch(patch) {
|
|
6904
|
-
const all = lines(patch.replace(/\r\n/g, "\n"));
|
|
6905
|
-
if (all[0]?.trim() !== "*** Begin Patch" || all.at(-1)?.trim() !== "*** End Patch") return null;
|
|
6906
|
-
const files2 = [];
|
|
6907
|
-
for (const line2 of all.slice(1, -1)) {
|
|
6908
|
-
const header2 = /^\*\*\* (Add|Update|Delete) File: (.+)$/.exec(line2);
|
|
6909
|
-
if (header2) {
|
|
6910
|
-
files2.push({ action: header2[1].toLowerCase(), path: header2[2].trim(), moveTo: null, body: [] });
|
|
6911
|
-
continue;
|
|
6912
|
-
}
|
|
6913
|
-
const current = files2.at(-1);
|
|
6914
|
-
if (!current) return null;
|
|
6915
|
-
const move = /^\*\*\* Move to: (.+)$/.exec(line2);
|
|
6916
|
-
if (move) current.moveTo = move[1].trim();
|
|
6917
|
-
else current.body.push(line2);
|
|
6918
|
-
}
|
|
6919
|
-
return files2;
|
|
6920
|
-
}
|
|
6921
|
-
function patchToClaudeCode(patch, cwd) {
|
|
6922
|
-
const files2 = parsePatch(patch);
|
|
6923
|
-
if (!files2 || files2.length !== 1) return null;
|
|
6924
|
-
const [file] = files2;
|
|
6925
|
-
if (file.moveTo) return null;
|
|
6926
|
-
if (file.action === "add") {
|
|
6927
|
-
if (file.body.some((line2) => !line2.startsWith("+"))) return null;
|
|
6928
|
-
return { name: "Write", input: { file_path: absolute(file.path, cwd), content: file.body.map((line2) => `${line2.slice(1)}
|
|
6929
|
-
`).join("") } };
|
|
6930
|
-
}
|
|
6931
|
-
if (file.action !== "update") return null;
|
|
6932
|
-
const body = file.body.filter((line2) => line2 !== "*** End of File");
|
|
6933
|
-
if (body.filter((line2) => line2.startsWith("@@")).length > 1) return null;
|
|
6934
|
-
const old = [];
|
|
6935
|
-
const next = [];
|
|
6936
|
-
for (const line2 of body.filter((line3) => !line3.startsWith("@@"))) {
|
|
6937
|
-
if (line2.startsWith("-")) old.push(line2.slice(1));
|
|
6938
|
-
else if (line2.startsWith("+")) next.push(line2.slice(1));
|
|
6939
|
-
else if (line2.startsWith(" ") || line2 === "") {
|
|
6940
|
-
old.push(line2.slice(1));
|
|
6941
|
-
next.push(line2.slice(1));
|
|
6942
|
-
} else return null;
|
|
6943
|
-
}
|
|
6944
|
-
if (!old.length) return null;
|
|
6945
|
-
return { name: "Edit", input: { file_path: absolute(file.path, cwd), old_string: old.join("\n"), new_string: next.join("\n") } };
|
|
6946
|
-
}
|
|
6947
|
-
function toClaudeCode(call, cwd) {
|
|
6948
|
-
if (CLAUDE_CODE_TOOLS.has(call.tool_name)) return { name: call.tool_name, input: call.args };
|
|
6949
|
-
const patch = codexPatch(call);
|
|
6950
|
-
if (patch) return patchToClaudeCode(patch, cwd);
|
|
6951
|
-
const shell = codexCommand(call);
|
|
6952
|
-
if (!shell) return null;
|
|
6953
|
-
const inPlace = !shell.workdir || shell.workdir === cwd;
|
|
6954
|
-
return { name: "Bash", input: { command: inPlace ? shell.command : `cd ${quote(shell.workdir)} && ${shell.command}` } };
|
|
6955
|
-
}
|
|
6956
|
-
function shellCall(command, cwd) {
|
|
6957
|
-
return { kind: "function", name: "shell", arguments: { command: ["bash", "-lc", command], ...cwd ? { workdir: cwd } : {} } };
|
|
6958
|
-
}
|
|
6959
|
-
function patchCall(body) {
|
|
6960
|
-
return { kind: "custom", name: "apply_patch", input: ["*** Begin Patch", ...body, "*** End Patch"].join("\n") };
|
|
6961
|
-
}
|
|
6962
|
-
function toCodex(call, cwd) {
|
|
6963
|
-
const args = call.args;
|
|
6964
|
-
if (call.tool_name === "apply_patch") return str4(args.input) ? { kind: "custom", name: "apply_patch", input: str4(args.input) } : null;
|
|
6965
|
-
if (CODEX_FUNCTIONS.has(call.tool_name)) return { kind: "function", name: call.tool_name, arguments: args };
|
|
6966
|
-
switch (call.tool_name) {
|
|
6967
|
-
case "Bash":
|
|
6968
|
-
return str4(args.command) ? shellCall(str4(args.command), cwd) : null;
|
|
6969
|
-
case "Read": {
|
|
6970
|
-
const path2 = str4(args.file_path);
|
|
6971
|
-
if (!path2) return null;
|
|
6972
|
-
const offset = typeof args.offset === "number" ? args.offset : null;
|
|
6973
|
-
const limit = typeof args.limit === "number" ? args.limit : null;
|
|
6974
|
-
if (offset === null && limit === null) return shellCall(`cat -n ${quote(path2)}`, cwd);
|
|
6975
|
-
const first = offset ?? 1;
|
|
6976
|
-
return shellCall(`cat -n ${quote(path2)} | sed -n '${first},${limit === null ? "$" : first + limit - 1}p'`, cwd);
|
|
6977
|
-
}
|
|
6978
|
-
case "Write": {
|
|
6979
|
-
const path2 = str4(args.file_path);
|
|
6980
|
-
if (!path2 || typeof args.content !== "string") return null;
|
|
6981
|
-
return patchCall([`*** Add File: ${relativeTo(path2, cwd)}`, ...lines(args.content).map((line2) => `+${line2}`)]);
|
|
6982
|
-
}
|
|
6983
|
-
case "Edit": {
|
|
6984
|
-
const path2 = str4(args.file_path);
|
|
6985
|
-
if (!path2 || typeof args.old_string !== "string" || typeof args.new_string !== "string" || args.replace_all === true) return null;
|
|
6986
|
-
return patchCall([`*** Update File: ${relativeTo(path2, cwd)}`, "@@", ...lines(args.old_string).map((line2) => `-${line2}`), ...lines(args.new_string).map((line2) => `+${line2}`)]);
|
|
6987
|
-
}
|
|
6988
|
-
default:
|
|
6989
|
-
return null;
|
|
6990
|
-
}
|
|
6991
|
-
}
|
|
6992
|
-
|
|
6993
|
-
// ../../packages/conversation/src/write.ts
|
|
6994
|
-
function cut(text2) {
|
|
6995
|
-
if (text2.length <= MAX_TOOL_OUTPUT_CHARS) return text2;
|
|
6996
|
-
const half = Math.floor(MAX_TOOL_OUTPUT_CHARS / 2);
|
|
6997
|
-
return `${text2.slice(0, half)}
|
|
6998
|
-
[\u2026 ${text2.length - 2 * half} characters left out \u2026]
|
|
6999
|
-
${text2.slice(-half)}`;
|
|
7000
|
-
}
|
|
7001
|
-
function callAsText(from, call, result) {
|
|
7002
|
-
const outcome = result ? `${result.status === "error" ? "It failed" : "It returned"}:
|
|
7003
|
-
${cut(resultText(result))}` : "No result was recorded.";
|
|
7004
|
-
return `[In ${engineLabel(from)} I called ${call.tool_name} with ${JSON.stringify(call.args)}. ${outcome}]`;
|
|
7005
|
-
}
|
|
7006
|
-
function decoded(part) {
|
|
7007
|
-
if (!part.data || !/^text\/|json/.test(part.media_type)) return `[Attached file: ${part.name}]`;
|
|
7008
|
-
return `[Attached file: ${part.name}]
|
|
7009
|
-
${Buffer.from(part.data, "base64").toString("utf8")}`;
|
|
7010
|
-
}
|
|
7011
|
-
function imageData(part) {
|
|
7012
|
-
if (part.data) return { mediaType: part.media_type, data: part.data };
|
|
7013
|
-
const match2 = /^data:([^;,]+);base64,(.*)$/s.exec(part.uri ?? "");
|
|
7014
|
-
return match2 ? { mediaType: match2[1], data: match2[2] } : null;
|
|
7015
|
-
}
|
|
7016
|
-
function plan(conversation, to, opts, map) {
|
|
7017
|
-
const { messages, summarised } = fitConversation(conversation, to, { budgetChars: opts.budgetChars, summarize: opts.summarize });
|
|
7018
|
-
const report = { messages: { user: 0, agent: 0 }, toolCalls: { mapped: 0, asText: 0 }, reasoningLeftOut: 0, summarised };
|
|
7019
|
-
const planned = messages.map((message2) => {
|
|
7020
|
-
const answered = new Set(message2.parts.filter((part) => part.type === "tool_result").map((part) => part.call_id));
|
|
7021
|
-
const mapped = /* @__PURE__ */ new Map();
|
|
7022
|
-
for (const part of message2.parts) {
|
|
7023
|
-
if (part.type === "reasoning") report.reasoningLeftOut += 1;
|
|
7024
|
-
if (part.type !== "tool_call") continue;
|
|
7025
|
-
if (answered.has(part.call_id) && map(part)) {
|
|
7026
|
-
mapped.set(part.call_id, true);
|
|
7027
|
-
report.toolCalls.mapped += 1;
|
|
7028
|
-
} else report.toolCalls.asText += 1;
|
|
7029
|
-
}
|
|
7030
|
-
return { message: message2, mapped };
|
|
7031
|
-
});
|
|
7032
|
-
return { planned, report };
|
|
7033
|
-
}
|
|
7034
|
-
function resultsOf(message2) {
|
|
7035
|
-
return new Map(message2.parts.filter((part) => part.type === "tool_result").map((part) => [part.call_id, part]));
|
|
7036
|
-
}
|
|
7037
|
-
function iso(at, fallback) {
|
|
7038
|
-
const parsed = Date.parse(at);
|
|
7039
|
-
return Number.isFinite(parsed) ? new Date(parsed).toISOString() : fallback.toISOString();
|
|
7040
|
-
}
|
|
7041
|
-
function claudeProjectFolder(cwd) {
|
|
7042
|
-
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
7043
|
-
}
|
|
7044
|
-
function writeClaudeCode(conversation, opts = {}) {
|
|
7045
|
-
const cwd = opts.cwd ?? conversation.cwd ?? "/";
|
|
7046
|
-
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
7047
|
-
const nativeId = opts.nativeId ?? randomUUID4();
|
|
7048
|
-
const calls = /* @__PURE__ */ new Map();
|
|
7049
|
-
const { planned, report } = plan(conversation, "claude_code", opts, (call) => {
|
|
7050
|
-
const native = toClaudeCode(call, cwd);
|
|
7051
|
-
if (native) calls.set(call.call_id, native);
|
|
7052
|
-
return native;
|
|
7053
|
-
});
|
|
7054
|
-
const lines2 = [];
|
|
7055
|
-
let parent = null;
|
|
7056
|
-
const push = (type, message2, at) => {
|
|
7057
|
-
const uuid2 = randomUUID4();
|
|
7058
|
-
lines2.push(JSON.stringify({
|
|
7059
|
-
parentUuid: parent,
|
|
7060
|
-
isSidechain: false,
|
|
7061
|
-
userType: "external",
|
|
7062
|
-
cwd,
|
|
7063
|
-
sessionId: nativeId,
|
|
7064
|
-
version: opts.version ?? "2.1.0",
|
|
7065
|
-
type,
|
|
7066
|
-
message: message2,
|
|
7067
|
-
uuid: uuid2,
|
|
7068
|
-
timestamp: iso(at, now)
|
|
7069
|
-
}));
|
|
7070
|
-
parent = uuid2;
|
|
7071
|
-
};
|
|
7072
|
-
for (const { message: message2, mapped } of planned) {
|
|
7073
|
-
if (message2.role === "user" || message2.role === "system") {
|
|
7074
|
-
const content2 = [];
|
|
7075
|
-
for (const part of message2.parts) {
|
|
7076
|
-
if (part.type === "text") content2.push({ type: "text", text: part.text });
|
|
7077
|
-
else if (part.type === "image") {
|
|
7078
|
-
const image = imageData(part);
|
|
7079
|
-
content2.push(image ? { type: "image", source: { type: "base64", media_type: image.mediaType, data: image.data } } : { type: "text", text: "[image]" });
|
|
7080
|
-
} else if (part.type === "file") content2.push({ type: "text", text: decoded(part) });
|
|
7081
|
-
}
|
|
7082
|
-
if (!content2.length) continue;
|
|
7083
|
-
report.messages.user += 1;
|
|
7084
|
-
const only = content2.length === 1 && content2[0].type === "text" ? content2[0].text : null;
|
|
7085
|
-
push("user", { role: "user", content: only ?? content2 }, message2.created_at);
|
|
7086
|
-
continue;
|
|
7087
|
-
}
|
|
7088
|
-
const results = resultsOf(message2);
|
|
7089
|
-
const content = [];
|
|
7090
|
-
const answers = [];
|
|
7091
|
-
for (const part of message2.parts) {
|
|
7092
|
-
if (part.type === "text") content.push({ type: "text", text: part.text });
|
|
7093
|
-
else if (part.type === "image") content.push({ type: "text", text: "[image]" });
|
|
7094
|
-
else if (part.type === "tool_call") {
|
|
7095
|
-
const result = results.get(part.call_id);
|
|
7096
|
-
const native = calls.get(part.call_id);
|
|
7097
|
-
if (mapped.has(part.call_id) && native && result) {
|
|
7098
|
-
content.push({ type: "tool_use", id: part.call_id, name: native.name, input: native.input });
|
|
7099
|
-
answers.push({ type: "tool_result", tool_use_id: part.call_id, content: cut(resultText(result)), ...result.status === "error" ? { is_error: true } : {} });
|
|
7100
|
-
} else content.push({ type: "text", text: callAsText(conversation.engine, part, result) });
|
|
7101
|
-
}
|
|
7102
|
-
}
|
|
7103
|
-
if (!content.length) continue;
|
|
7104
|
-
report.messages.agent += 1;
|
|
7105
|
-
push("assistant", {
|
|
7106
|
-
id: `msg_${randomBytes2(12).toString("hex")}`,
|
|
7107
|
-
type: "message",
|
|
7108
|
-
role: "assistant",
|
|
7109
|
-
model: conversation.model ?? "unknown",
|
|
7110
|
-
content,
|
|
7111
|
-
stop_reason: answers.length ? "tool_use" : "end_turn",
|
|
7112
|
-
stop_sequence: null,
|
|
7113
|
-
usage: { input_tokens: 0, output_tokens: 0 }
|
|
7114
|
-
}, message2.created_at);
|
|
7115
|
-
if (answers.length) push("user", { role: "user", content: answers }, message2.created_at);
|
|
7116
|
-
}
|
|
7117
|
-
return {
|
|
7118
|
-
engine: "claude_code",
|
|
7119
|
-
nativeId,
|
|
7120
|
-
cwd,
|
|
7121
|
-
path: `projects/${claudeProjectFolder(cwd)}/${nativeId}.jsonl`,
|
|
7122
|
-
content: lines2.map((line2) => `${line2}
|
|
7123
|
-
`).join(""),
|
|
7124
|
-
resume: `claude --resume ${nativeId}`,
|
|
7125
|
-
report
|
|
7126
|
-
};
|
|
7127
|
-
}
|
|
7128
|
-
function rolloutStamp(at) {
|
|
7129
|
-
return at.toISOString().slice(0, 19).replace(/:/g, "-");
|
|
7130
|
-
}
|
|
7131
|
-
function writeCodex(conversation, opts = {}) {
|
|
7132
|
-
const cwd = opts.cwd ?? conversation.cwd ?? "/";
|
|
7133
|
-
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
7134
|
-
const nativeId = opts.nativeId ?? randomUUID4();
|
|
7135
|
-
const calls = /* @__PURE__ */ new Map();
|
|
7136
|
-
const { planned, report } = plan(conversation, "codex", opts, (call) => {
|
|
7137
|
-
const native = toCodex(call, cwd);
|
|
7138
|
-
if (native) calls.set(call.call_id, native);
|
|
7139
|
-
return native;
|
|
7140
|
-
});
|
|
7141
|
-
const lines2 = [];
|
|
7142
|
-
const push = (type, payload, at) => lines2.push(JSON.stringify({ timestamp: iso(at, now), type, payload }));
|
|
7143
|
-
push("session_meta", {
|
|
7144
|
-
id: nativeId,
|
|
7145
|
-
timestamp: now.toISOString(),
|
|
7146
|
-
cwd,
|
|
7147
|
-
originator: "codex_cli_rs",
|
|
7148
|
-
cli_version: opts.version ?? "0.61.0",
|
|
7149
|
-
instructions: null,
|
|
7150
|
-
source: "cli",
|
|
7151
|
-
model_provider: "openai"
|
|
7152
|
-
}, now.toISOString());
|
|
7153
|
-
for (const { message: message2, mapped } of planned) {
|
|
7154
|
-
if (message2.role === "user" || message2.role === "system") {
|
|
7155
|
-
const content = [];
|
|
7156
|
-
for (const part of message2.parts) {
|
|
7157
|
-
if (part.type === "text") content.push({ type: "input_text", text: part.text });
|
|
7158
|
-
else if (part.type === "image") {
|
|
7159
|
-
const image = imageData(part);
|
|
7160
|
-
content.push(image ? { type: "input_image", image_url: `data:${image.mediaType};base64,${image.data}` } : { type: "input_text", text: "[image]" });
|
|
7161
|
-
} else if (part.type === "file") content.push({ type: "input_text", text: decoded(part) });
|
|
7162
|
-
}
|
|
7163
|
-
if (!content.length) continue;
|
|
7164
|
-
report.messages.user += 1;
|
|
7165
|
-
push("response_item", { type: "message", role: "user", content }, message2.created_at);
|
|
7166
|
-
const text2 = content.filter((block) => block.type === "input_text").map((block) => block.text).join("\n");
|
|
7167
|
-
push("event_msg", { type: "user_message", message: text2, images: [] }, message2.created_at);
|
|
7168
|
-
continue;
|
|
7169
|
-
}
|
|
7170
|
-
const results = resultsOf(message2);
|
|
7171
|
-
let wrote = false;
|
|
7172
|
-
let pending = "";
|
|
7173
|
-
const say = () => {
|
|
7174
|
-
if (!pending) return;
|
|
7175
|
-
push("response_item", { type: "message", role: "assistant", content: [{ type: "output_text", text: pending }] }, message2.created_at);
|
|
7176
|
-
push("event_msg", { type: "agent_message", message: pending }, message2.created_at);
|
|
7177
|
-
pending = "";
|
|
7178
|
-
wrote = true;
|
|
7179
|
-
};
|
|
7180
|
-
for (const part of message2.parts) {
|
|
7181
|
-
if (part.type === "text") pending = pending ? `${pending}
|
|
7182
|
-
|
|
7183
|
-
${part.text}` : part.text;
|
|
7184
|
-
else if (part.type === "image") pending = pending ? `${pending}
|
|
7185
|
-
|
|
7186
|
-
[image]` : "[image]";
|
|
7187
|
-
else if (part.type === "tool_call") {
|
|
7188
|
-
const result = results.get(part.call_id);
|
|
7189
|
-
const native = calls.get(part.call_id);
|
|
7190
|
-
if (!(mapped.has(part.call_id) && native && result)) {
|
|
7191
|
-
const text2 = callAsText(conversation.engine, part, result);
|
|
7192
|
-
pending = pending ? `${pending}
|
|
7193
|
-
|
|
7194
|
-
${text2}` : text2;
|
|
7195
|
-
continue;
|
|
7196
|
-
}
|
|
7197
|
-
say();
|
|
7198
|
-
push("response_item", native.kind === "custom" ? { type: "custom_tool_call", status: "completed", call_id: part.call_id, name: native.name, input: native.input } : { type: "function_call", name: native.name, arguments: JSON.stringify(native.arguments), call_id: part.call_id }, message2.created_at);
|
|
7199
|
-
wrote = true;
|
|
7200
|
-
} else if (part.type === "tool_result" && mapped.has(part.call_id)) {
|
|
7201
|
-
say();
|
|
7202
|
-
const native = calls.get(part.call_id);
|
|
7203
|
-
const output2 = cut(resultText(part));
|
|
7204
|
-
push(
|
|
7205
|
-
"response_item",
|
|
7206
|
-
native.kind === "custom" ? { type: "custom_tool_call_output", call_id: part.call_id, output: output2 } : { type: "function_call_output", call_id: part.call_id, output: JSON.stringify({ output: output2, metadata: { exit_code: part.status === "error" ? 1 : 0, duration_seconds: 0 } }) },
|
|
7207
|
-
message2.created_at
|
|
7208
|
-
);
|
|
7209
|
-
}
|
|
7210
|
-
}
|
|
7211
|
-
say();
|
|
7212
|
-
if (wrote) report.messages.agent += 1;
|
|
7213
|
-
}
|
|
7214
|
-
const day = now.toISOString().slice(0, 10).split("-").join("/");
|
|
7215
|
-
return {
|
|
7216
|
-
engine: "codex",
|
|
7217
|
-
nativeId,
|
|
7218
|
-
cwd,
|
|
7219
|
-
path: `sessions/${day}/rollout-${rolloutStamp(now)}-${nativeId}.jsonl`,
|
|
7220
|
-
content: lines2.map((line2) => `${line2}
|
|
7221
|
-
`).join(""),
|
|
7222
|
-
resume: `codex resume ${nativeId}`,
|
|
7223
|
-
report
|
|
7224
|
-
};
|
|
7225
|
-
}
|
|
7226
|
-
function writeConversation(to, conversation, opts = {}) {
|
|
7227
|
-
return to === "codex" ? writeCodex(conversation, opts) : writeClaudeCode(conversation, opts);
|
|
7228
|
-
}
|
|
7229
|
-
|
|
7230
|
-
// ../../packages/conversation/src/index.ts
|
|
7231
|
-
function convertSession(from, text2, to, opts = {}) {
|
|
7232
|
-
return writeConversation(to, readConversation(from, text2), opts);
|
|
7233
|
-
}
|
|
7234
|
-
|
|
7235
|
-
// src/session-workspace.ts
|
|
7236
5912
|
var SINGLE_IMPORT_MAX = 25 * 1024 * 1024;
|
|
7237
5913
|
var PART_SIZE = 8 * 1024 * 1024;
|
|
7238
5914
|
var SKIPPED3 = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
@@ -7245,8 +5921,8 @@ async function listFiles2(id2, path2, hidden) {
|
|
|
7245
5921
|
return api("GET", `${workspacePath(id2)}/files${qs ? `?${qs}` : ""}`);
|
|
7246
5922
|
}
|
|
7247
5923
|
function entryLine(e) {
|
|
7248
|
-
const
|
|
7249
|
-
return `${e.type === "directory" ? "d" : "-"} ${
|
|
5924
|
+
const size = e.type === "directory" ? "-" : String(e.size ?? 0);
|
|
5925
|
+
return `${e.type === "directory" ? "d" : "-"} ${size.padStart(10)} ${(e.mtime ?? "").slice(0, 16).replace("T", " ")} ${e.name}${e.type === "directory" ? "/" : ""}`;
|
|
7250
5926
|
}
|
|
7251
5927
|
async function readFile(id2, path2) {
|
|
7252
5928
|
return (await apiBytes("GET", `${workspacePath(id2)}/files/content?path=${encodeURIComponent(path2)}`)).bytes;
|
|
@@ -7291,7 +5967,7 @@ function folderArchive(dir, files2) {
|
|
|
7291
5967
|
}
|
|
7292
5968
|
async function importFolder(id2, dir, opts = {}) {
|
|
7293
5969
|
const root2 = resolve10(dir);
|
|
7294
|
-
const name = opts.name ??
|
|
5970
|
+
const name = opts.name ?? basename6(root2);
|
|
7295
5971
|
const archive = opts.archive ?? folderArchive(root2, folderFiles(root2));
|
|
7296
5972
|
if (archive.length <= SINGLE_IMPORT_MAX) {
|
|
7297
5973
|
const res = await apiBytes("POST", `${workspacePath(id2)}/import?name=${encodeURIComponent(name)}`, { bytes: archive, mediaType: "application/gzip" });
|
|
@@ -7314,17 +5990,17 @@ async function importFolder(id2, dir, opts = {}) {
|
|
|
7314
5990
|
return { path: upload.path ?? name, files: upload.files ?? 0 };
|
|
7315
5991
|
}
|
|
7316
5992
|
function renderAccess(a) {
|
|
7317
|
-
const
|
|
5993
|
+
const lines = [
|
|
7318
5994
|
`${a.session_id}${a.title ? ` \u2014 ${a.title}` : ""}`,
|
|
7319
5995
|
` ${a.visibility === "private" ? "private to its owner" : `visible to ${a.workspace.name} (${a.workspace.slug})`} \xB7 you are its ${a.access}`,
|
|
7320
5996
|
` owner: ${a.owner.name ?? a.owner.email ?? "unknown"}`
|
|
7321
5997
|
];
|
|
7322
|
-
if (a.viewers)
|
|
5998
|
+
if (a.viewers) lines.push(a.viewers.length ? ` viewers: ${a.viewers.map((v) => v.notification === "not_sent" ? `${v.email} (email not sent; send them the link)` : v.email).join(", ")}` : " viewers: none");
|
|
7323
5999
|
if (a.logins_shared?.enabled) {
|
|
7324
6000
|
const sites = a.logins_shared.sites?.join(", ") ?? "every site except Google";
|
|
7325
|
-
|
|
6001
|
+
lines.push(` owner's logins shared: ${sites}${a.logins_shared.suspended ? " (not used while anyone with the link can send messages)" : ""}`);
|
|
7326
6002
|
}
|
|
7327
|
-
return
|
|
6003
|
+
return lines;
|
|
7328
6004
|
}
|
|
7329
6005
|
function accessPatch(opts) {
|
|
7330
6006
|
if (opts.private && opts.members) throw new ApiError(400, "invalid_request", "pass --private or --members, not both");
|
|
@@ -7377,11 +6053,11 @@ function zipEntries(archive) {
|
|
|
7377
6053
|
let at = archive.readUInt32LE(end + 16);
|
|
7378
6054
|
for (let index = archive.readUInt16LE(end + 10); index > 0; index -= 1) {
|
|
7379
6055
|
const method = archive.readUInt16LE(at + 10);
|
|
7380
|
-
const
|
|
6056
|
+
const size = archive.readUInt32LE(at + 20);
|
|
7381
6057
|
const nameLength = archive.readUInt16LE(at + 28);
|
|
7382
6058
|
const local = archive.readUInt32LE(at + 42);
|
|
7383
6059
|
const start = local + 30 + archive.readUInt16LE(local + 26) + archive.readUInt16LE(local + 28);
|
|
7384
|
-
const packed = archive.subarray(start, start +
|
|
6060
|
+
const packed = archive.subarray(start, start + size);
|
|
7385
6061
|
if (method !== 0 && method !== 8) throw new ApiError(422, "checkpoint_invalid", "the downloaded conversation uses an unsupported compression");
|
|
7386
6062
|
entries.set(archive.subarray(at + 46, at + 46 + nameLength).toString("utf8"), method === 8 ? inflateRawSync(packed) : Buffer.from(packed));
|
|
7387
6063
|
at += 46 + nameLength + archive.readUInt16LE(at + 30) + archive.readUInt16LE(at + 32);
|
|
@@ -7488,7 +6164,7 @@ async function handBack(sessionId) {
|
|
|
7488
6164
|
// src/render.ts
|
|
7489
6165
|
var dim = (s) => `\x1B[2m${s}\x1B[0m`;
|
|
7490
6166
|
var red = (s) => `\x1B[31m${s}\x1B[0m`;
|
|
7491
|
-
function
|
|
6167
|
+
function clip(value, max = 120) {
|
|
7492
6168
|
const text2 = typeof value === "string" ? value : JSON.stringify(value);
|
|
7493
6169
|
return text2.length > max ? `${text2.slice(0, max)}\u2026` : text2;
|
|
7494
6170
|
}
|
|
@@ -7529,10 +6205,10 @@ function renderOther(event, data) {
|
|
|
7529
6205
|
const part = data.part;
|
|
7530
6206
|
switch (event) {
|
|
7531
6207
|
case "agent.reasoning":
|
|
7532
|
-
console.log(dim(`\xB7 ${
|
|
6208
|
+
console.log(dim(`\xB7 ${clip(part?.text ?? "")}`));
|
|
7533
6209
|
break;
|
|
7534
6210
|
case "agent.tool_use":
|
|
7535
|
-
console.log(dim(`\u2192 ${String(part?.tool_name ?? "tool")}(${
|
|
6211
|
+
console.log(dim(`\u2192 ${String(part?.tool_name ?? "tool")}(${clip(part?.args ?? {}, 80)})`));
|
|
7536
6212
|
break;
|
|
7537
6213
|
case "agent.tool_result":
|
|
7538
6214
|
console.log(dim(`\u2190 ${String(part?.tool_name ?? "tool")} ${String(part?.status ?? "")}`));
|
|
@@ -7722,62 +6398,62 @@ function scrub(text2, names) {
|
|
|
7722
6398
|
return out.length > TEXT_MAX ? `${out.slice(0, TEXT_MAX)}
|
|
7723
6399
|
\u2026[cut]` : out;
|
|
7724
6400
|
}
|
|
7725
|
-
function
|
|
6401
|
+
function textOf2(event) {
|
|
7726
6402
|
if (typeof event.text === "string" && event.text.trim()) return event.text;
|
|
7727
6403
|
if (Array.isArray(event.content)) {
|
|
7728
6404
|
return event.content.map((block) => block.type === "text" && typeof block.text === "string" ? block.text : "").filter(Boolean).join("\n");
|
|
7729
6405
|
}
|
|
7730
6406
|
return "";
|
|
7731
6407
|
}
|
|
7732
|
-
function firstAsk(
|
|
7733
|
-
const root2 =
|
|
6408
|
+
function firstAsk(record) {
|
|
6409
|
+
const root2 = record.threads.find((thread2) => thread2.relation === "primary") ?? record.threads[0];
|
|
7734
6410
|
if (!root2) return null;
|
|
7735
|
-
for (const event of
|
|
6411
|
+
for (const event of record.events[root2.id] ?? []) {
|
|
7736
6412
|
if (event.type === "user.message") {
|
|
7737
|
-
const text2 =
|
|
6413
|
+
const text2 = textOf2(event).trim();
|
|
7738
6414
|
if (text2) return text2;
|
|
7739
6415
|
}
|
|
7740
6416
|
}
|
|
7741
6417
|
return null;
|
|
7742
6418
|
}
|
|
7743
|
-
function decisionsOf(
|
|
6419
|
+
function decisionsOf(record) {
|
|
7744
6420
|
const out = [];
|
|
7745
|
-
for (const thread2 of
|
|
7746
|
-
for (const event of
|
|
6421
|
+
for (const thread2 of record.threads) {
|
|
6422
|
+
for (const event of record.events[thread2.id] ?? []) {
|
|
7747
6423
|
if (event.type === "human.decision" || event.type === "outcome.observed") out.push({ ...event, thread_id: thread2.id });
|
|
7748
6424
|
}
|
|
7749
6425
|
}
|
|
7750
6426
|
return out.sort((a, b) => (a.at ?? "").localeCompare(b.at ?? ""));
|
|
7751
6427
|
}
|
|
7752
|
-
function adoptedSession(
|
|
7753
|
-
const decisions = decisionsOf(
|
|
6428
|
+
function adoptedSession(record) {
|
|
6429
|
+
const decisions = decisionsOf(record).filter((event) => event.type === "human.decision");
|
|
7754
6430
|
for (const event of [...decisions].reverse()) {
|
|
7755
6431
|
if (event.kind === "adopt") return event.target_session_id ?? event.thread_id;
|
|
7756
6432
|
if (event.kind === "vote" && event.target_session_id) return event.target_session_id;
|
|
7757
6433
|
}
|
|
7758
6434
|
return null;
|
|
7759
6435
|
}
|
|
7760
|
-
function stepsOf(
|
|
7761
|
-
const root2 =
|
|
6436
|
+
function stepsOf(record, names) {
|
|
6437
|
+
const root2 = record.threads.find((thread2) => thread2.relation === "primary") ?? record.threads[0];
|
|
7762
6438
|
if (!root2) return [];
|
|
7763
|
-
const events2 =
|
|
6439
|
+
const events2 = record.events[root2.id] ?? [];
|
|
7764
6440
|
const steps = [];
|
|
7765
6441
|
events2.forEach((event, index) => {
|
|
7766
6442
|
if (event.type !== "human.decision" || event.kind !== "revise" && event.kind !== "rerun") return;
|
|
7767
|
-
const next = events2.slice(index + 1).find((later) => later.type === "user.message" &&
|
|
7768
|
-
const words2 = next ?
|
|
6443
|
+
const next = events2.slice(index + 1).find((later) => later.type === "user.message" && textOf2(later).trim());
|
|
6444
|
+
const words2 = next ? textOf2(next) : event.reason ?? "";
|
|
7769
6445
|
if (!words2.trim()) return;
|
|
7770
6446
|
steps.push({ at: event.at ?? "", instruction: scrub(words2, names) });
|
|
7771
6447
|
});
|
|
7772
6448
|
return steps;
|
|
7773
6449
|
}
|
|
7774
|
-
function rubricOf(
|
|
7775
|
-
if (
|
|
7776
|
-
const verdicts = new Map((
|
|
6450
|
+
function rubricOf(record, instruction, names) {
|
|
6451
|
+
if (record.goal && record.goal.criteria.length) {
|
|
6452
|
+
const verdicts = new Map((record.goal.last_evaluation?.criteria ?? []).map((row) => [row.id, row.verdict]));
|
|
7777
6453
|
return {
|
|
7778
6454
|
version: 1,
|
|
7779
6455
|
source: "goal",
|
|
7780
|
-
criteria:
|
|
6456
|
+
criteria: record.goal.criteria.map((criterion) => ({
|
|
7781
6457
|
id: criterion.id,
|
|
7782
6458
|
text: scrub(criterion.text, names),
|
|
7783
6459
|
must: true,
|
|
@@ -7872,17 +6548,17 @@ cd "$(dirname "$0")"
|
|
|
7872
6548
|
mkdir -p /workspace/outputs
|
|
7873
6549
|
if [ -d files ]; then cp -R files/. /workspace/outputs/; fi
|
|
7874
6550
|
`;
|
|
7875
|
-
function buildHarborTask(
|
|
6551
|
+
function buildHarborTask(record, opts) {
|
|
7876
6552
|
const names = opts.redactNames;
|
|
7877
6553
|
const out = /* @__PURE__ */ new Map();
|
|
7878
|
-
const ask3 =
|
|
6554
|
+
const ask3 = record.goal?.objective ?? firstAsk(record) ?? record.title ?? "Complete the task described by the workspace.";
|
|
7879
6555
|
const instruction = scrub(ask3, names);
|
|
7880
|
-
const root2 =
|
|
7881
|
-
const harnesses = [...new Set(
|
|
7882
|
-
const decisions = decisionsOf(
|
|
7883
|
-
const adopted = adoptedSession(
|
|
7884
|
-
const steps = stepsOf(
|
|
7885
|
-
const idHash = createHash9("sha256").update(
|
|
6556
|
+
const root2 = record.threads.find((thread2) => thread2.relation === "primary") ?? record.threads[0];
|
|
6557
|
+
const harnesses = [...new Set(record.threads.map((thread2) => thread2.agent.harness))];
|
|
6558
|
+
const decisions = decisionsOf(record);
|
|
6559
|
+
const adopted = adoptedSession(record);
|
|
6560
|
+
const steps = stepsOf(record, names);
|
|
6561
|
+
const idHash = createHash9("sha256").update(record.task_id).digest("hex").slice(0, 16);
|
|
7886
6562
|
out.set("instruction.md", `${instruction.trim()}
|
|
7887
6563
|
|
|
7888
6564
|
Write your deliverables under /workspace/outputs.
|
|
@@ -7895,18 +6571,18 @@ Write your deliverables under /workspace/outputs.
|
|
|
7895
6571
|
tier: opts.tier,
|
|
7896
6572
|
source: "agentsky-session-record",
|
|
7897
6573
|
source_task: idHash,
|
|
7898
|
-
exported_at:
|
|
6574
|
+
exported_at: record.exported_at,
|
|
7899
6575
|
harnesses,
|
|
7900
|
-
has_goal: Boolean(
|
|
6576
|
+
has_goal: Boolean(record.goal),
|
|
7901
6577
|
decisions: decisions.length,
|
|
7902
6578
|
steps: steps.length,
|
|
7903
6579
|
adopted_session: adopted ?? "",
|
|
7904
|
-
did_the_job:
|
|
6580
|
+
did_the_job: record.completion_answer?.did_the_job ?? "unknown"
|
|
7905
6581
|
},
|
|
7906
6582
|
verifier: { kind: "rubric_judge", rubric: "tests/rubric.json", reward: "/logs/verifier/reward.json" }
|
|
7907
6583
|
})
|
|
7908
6584
|
);
|
|
7909
|
-
const env =
|
|
6585
|
+
const env = record.environment ?? root2?.environment ?? null;
|
|
7910
6586
|
if (env && typeof env.repo === "string" && typeof env.commit === "string") {
|
|
7911
6587
|
out.set(
|
|
7912
6588
|
"environment/Dockerfile",
|
|
@@ -7922,7 +6598,7 @@ RUN git clone ${env.repo} repo && cd repo && git checkout ${env.commit}
|
|
|
7922
6598
|
"This task is a real execution, not a resettable environment: the record carries no repository and commit to rebuild from.\nAuthor environment/Dockerfile by hand from solution/files (the task's own files at export) before running it with Harbor, or keep it as trajectory data.\n"
|
|
7923
6599
|
);
|
|
7924
6600
|
}
|
|
7925
|
-
const rubric = rubricOf(
|
|
6601
|
+
const rubric = rubricOf(record, instruction, names);
|
|
7926
6602
|
out.set("tests/rubric.json", `${JSON.stringify(rubric, null, 2)}
|
|
7927
6603
|
`);
|
|
7928
6604
|
out.set("tests/judge.py", JUDGE_PY);
|
|
@@ -7930,12 +6606,12 @@ RUN git clone ${env.repo} repo && cd repo && git checkout ${env.commit}
|
|
|
7930
6606
|
out.set("solution/solve.sh", SOLVE_SH);
|
|
7931
6607
|
out.set(
|
|
7932
6608
|
"solution/deliverables.json",
|
|
7933
|
-
`${JSON.stringify({ files:
|
|
6609
|
+
`${JSON.stringify({ files: record.files.map((file) => ({ path: file.path, bytes: file.size_bytes ?? null })), adopted_session: adopted }, null, 2)}
|
|
7934
6610
|
`
|
|
7935
6611
|
);
|
|
7936
6612
|
for (const [path2, bytes] of opts.fileBytes ?? []) out.set(`solution/files/${path2}`, bytes);
|
|
7937
6613
|
const scrubbedEvents = {};
|
|
7938
|
-
for (const [threadId, events2] of Object.entries(
|
|
6614
|
+
for (const [threadId, events2] of Object.entries(record.events)) {
|
|
7939
6615
|
scrubbedEvents[threadId] = events2.map((event) => ({
|
|
7940
6616
|
...event,
|
|
7941
6617
|
...typeof event.text === "string" ? { text: scrub(event.text, names) } : {},
|
|
@@ -7944,7 +6620,7 @@ RUN git clone ${env.repo} repo && cd repo && git checkout ${env.commit}
|
|
|
7944
6620
|
..."parts" in event ? { parts: void 0 } : {}
|
|
7945
6621
|
}));
|
|
7946
6622
|
}
|
|
7947
|
-
out.set("rollout/record.json", `${JSON.stringify({ ...
|
|
6623
|
+
out.set("rollout/record.json", `${JSON.stringify({ ...record, title: record.title ? scrub(record.title, names) : null, events: scrubbedEvents, goal: record.goal ? { ...record.goal, objective: scrub(record.goal.objective, names) } : null }, null, 2)}
|
|
7948
6624
|
`);
|
|
7949
6625
|
out.set("rollout/decisions.json", `${JSON.stringify(decisions.map((event) => ({ ...event, reason: typeof event.reason === "string" ? scrub(event.reason, names) : event.reason })), null, 2)}
|
|
7950
6626
|
`);
|
|
@@ -7988,16 +6664,16 @@ async function fetchTaskRecord(taskRef) {
|
|
|
7988
6664
|
}
|
|
7989
6665
|
var FILE_BYTES_MAX = 50 * 1024 * 1024;
|
|
7990
6666
|
async function exportTaskHarbor(taskRef, outDir, opts) {
|
|
7991
|
-
const
|
|
6667
|
+
const record = await fetchTaskRecord(taskRef);
|
|
7992
6668
|
const fileBytes = /* @__PURE__ */ new Map();
|
|
7993
6669
|
let total = 0;
|
|
7994
|
-
for (const file of
|
|
6670
|
+
for (const file of record.files) {
|
|
7995
6671
|
if (total + (file.size_bytes ?? 0) > FILE_BYTES_MAX) break;
|
|
7996
|
-
const bytes = await readTaskFile(
|
|
6672
|
+
const bytes = await readTaskFile(record.task_id, file.path);
|
|
7997
6673
|
total += bytes.byteLength;
|
|
7998
6674
|
fileBytes.set(file.path, bytes);
|
|
7999
6675
|
}
|
|
8000
|
-
const files2 = buildHarborTask(
|
|
6676
|
+
const files2 = buildHarborTask(record, { ...opts, fileBytes });
|
|
8001
6677
|
const written = [];
|
|
8002
6678
|
for (const [path2, content] of files2) {
|
|
8003
6679
|
const target2 = join17(outDir, path2);
|
|
@@ -8005,7 +6681,7 @@ async function exportTaskHarbor(taskRef, outDir, opts) {
|
|
|
8005
6681
|
writeFileSync10(target2, content, typeof content === "string" ? { mode: path2.endsWith(".sh") || path2.endsWith(".py") ? 493 : 420 } : void 0);
|
|
8006
6682
|
written.push(path2);
|
|
8007
6683
|
}
|
|
8008
|
-
return { written, record
|
|
6684
|
+
return { written, record };
|
|
8009
6685
|
}
|
|
8010
6686
|
function parseRedactNames(values) {
|
|
8011
6687
|
return (values ?? []).map((value) => {
|
|
@@ -8125,8 +6801,8 @@ function line(section, row) {
|
|
|
8125
6801
|
return joined([row.name, row.kind, row.path]);
|
|
8126
6802
|
case "changes": {
|
|
8127
6803
|
const checks = row.checks;
|
|
8128
|
-
const
|
|
8129
|
-
return joined([row.title, row.repo, row.state,
|
|
6804
|
+
const lines = row.additions == null && row.deletions == null ? "" : `+${text(row.additions ?? 0)} -${text(row.deletions ?? 0)}`;
|
|
6805
|
+
return joined([row.title, row.repo, row.state, lines, checks ? `${checks.passed} of ${checks.total} checks passed` : "", row.url]);
|
|
8130
6806
|
}
|
|
8131
6807
|
case "members_plugins":
|
|
8132
6808
|
return joined([row.kind, row.name, row.needs_sign_in ? "needs sign-in" : row.online ? "online" : ""]);
|
|
@@ -8137,14 +6813,14 @@ function line(section, row) {
|
|
|
8137
6813
|
}
|
|
8138
6814
|
}
|
|
8139
6815
|
function renderSessionOverview(overview) {
|
|
8140
|
-
const
|
|
8141
|
-
if (overview.context_percent !== void 0)
|
|
6816
|
+
const lines = [overview.title ? `${overview.title} (${overview.session_id})` : overview.session_id];
|
|
6817
|
+
if (overview.context_percent !== void 0) lines.push(`context ${overview.context_percent}% full`);
|
|
8142
6818
|
for (const section of overview.sections) {
|
|
8143
|
-
|
|
8144
|
-
for (const row of section.rows)
|
|
8145
|
-
if (section.id === "runs" && section.finished)
|
|
6819
|
+
lines.push("", section.id === "spend" ? `${TITLES.spend} ${usd2(section.total_usd)}` : TITLES[section.id] ?? section.id);
|
|
6820
|
+
for (const row of section.rows) lines.push(` ${line(section.id, row)}`);
|
|
6821
|
+
if (section.id === "runs" && section.finished) lines.push(` ${section.finished} finished`);
|
|
8146
6822
|
}
|
|
8147
|
-
return
|
|
6823
|
+
return lines.join("\n");
|
|
8148
6824
|
}
|
|
8149
6825
|
|
|
8150
6826
|
// src/task-email.ts
|
|
@@ -8339,15 +7015,15 @@ function renderBrowserProfileShare(share) {
|
|
|
8339
7015
|
}
|
|
8340
7016
|
function renderBrowserProfile(profile) {
|
|
8341
7017
|
const title = profile.scope === "mine" ? "your browser" : profile.scope === "shared" ? `shared with you by ${profile.owner?.email ?? profile.owner?.name ?? profile.owner?.id ?? "someone"}` : "shared with this workspace";
|
|
8342
|
-
const
|
|
8343
|
-
for (const site2 of profile.sites)
|
|
8344
|
-
for (const share of profile.shares ?? [])
|
|
8345
|
-
return
|
|
7018
|
+
const lines = [`${title} revision: ${profile.revision} sites: ${profile.sites.length}`];
|
|
7019
|
+
for (const site2 of profile.sites) lines.push(` ${renderBrowserProfileSite(site2)}`);
|
|
7020
|
+
for (const share of profile.shares ?? []) lines.push(` ${renderBrowserProfileShare(share)}`);
|
|
7021
|
+
return lines.join("\n");
|
|
8346
7022
|
}
|
|
8347
7023
|
|
|
8348
7024
|
// src/portable-import.ts
|
|
8349
7025
|
import { existsSync as existsSync13, readdirSync as readdirSync9, readFileSync as readFileSync21, statSync as statSync7 } from "fs";
|
|
8350
|
-
import { basename as
|
|
7026
|
+
import { basename as basename7, join as join18, resolve as resolve11 } from "path";
|
|
8351
7027
|
import { parse as parseToml4 } from "smol-toml";
|
|
8352
7028
|
var isObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8353
7029
|
function readJson4(path2) {
|
|
@@ -8429,7 +7105,7 @@ function planImport(path2) {
|
|
|
8429
7105
|
const target2 = resolve11(path2);
|
|
8430
7106
|
if (!existsSync13(target2)) throw new Error(`Nothing at ${path2}`);
|
|
8431
7107
|
if (statSync7(target2).isFile()) {
|
|
8432
|
-
const name2 =
|
|
7108
|
+
const name2 = basename7(target2).replace(/\.(json|toml)$/, "");
|
|
8433
7109
|
if (target2.endsWith(".toml")) return { name: name2, format: "codex-config", skills: [], ...codexConfigServers(readFileSync21(target2, "utf-8")) };
|
|
8434
7110
|
const value = readJson4(target2);
|
|
8435
7111
|
if (value === null) throw new Error(`${path2} is not JSON or TOML`);
|
|
@@ -8466,7 +7142,7 @@ function planImport(path2) {
|
|
|
8466
7142
|
skipped.push(...read.skipped);
|
|
8467
7143
|
}
|
|
8468
7144
|
for (const part of ["commands", "agents", "hooks"]) if (existsSync13(at(part))) skipped.push({ part, reason: part === "hooks" ? "hooks run code and are not imported" : `${part} import with the plugin from GitHub (sky plugins add --source github:\u2026)` });
|
|
8469
|
-
const name = isObject(manifest) && typeof manifest.name === "string" ? manifest.name :
|
|
7145
|
+
const name = isObject(manifest) && typeof manifest.name === "string" ? manifest.name : basename7(target2);
|
|
8470
7146
|
return { name, format, skills: skillDirs(target2), servers, skipped };
|
|
8471
7147
|
}
|
|
8472
7148
|
|
|
@@ -8617,22 +7293,22 @@ function fieldNames(node, components, seen, out) {
|
|
|
8617
7293
|
return;
|
|
8618
7294
|
}
|
|
8619
7295
|
if (typeof node !== "object" || node === null) return;
|
|
8620
|
-
const
|
|
8621
|
-
if (typeof
|
|
8622
|
-
if (seen.has(
|
|
8623
|
-
seen.add(
|
|
8624
|
-
const target2 =
|
|
7296
|
+
const record = node;
|
|
7297
|
+
if (typeof record.$ref === "string") {
|
|
7298
|
+
if (seen.has(record.$ref)) return;
|
|
7299
|
+
seen.add(record.$ref);
|
|
7300
|
+
const target2 = record.$ref.replace(/^#\/components\//, "").split("/").reduce((at, key) => at?.[key], components);
|
|
8625
7301
|
fieldNames(target2, components, seen, out);
|
|
8626
7302
|
return;
|
|
8627
7303
|
}
|
|
8628
|
-
if (typeof
|
|
8629
|
-
if (typeof
|
|
8630
|
-
for (const [name, schema] of Object.entries(
|
|
7304
|
+
if (typeof record.in === "string" && typeof record.name === "string") out.add(record.name);
|
|
7305
|
+
if (typeof record.properties === "object" && record.properties !== null) {
|
|
7306
|
+
for (const [name, schema] of Object.entries(record.properties)) {
|
|
8631
7307
|
out.add(name);
|
|
8632
7308
|
fieldNames(schema, components, seen, out);
|
|
8633
7309
|
}
|
|
8634
7310
|
}
|
|
8635
|
-
for (const key of ["schema", "items", "allOf", "oneOf", "anyOf", "content", "application/json"]) fieldNames(
|
|
7311
|
+
for (const key of ["schema", "items", "allOf", "oneOf", "anyOf", "content", "application/json"]) fieldNames(record[key], components, seen, out);
|
|
8636
7312
|
}
|
|
8637
7313
|
function operationSearch(operations, components) {
|
|
8638
7314
|
const entries = operations.map((op) => {
|
|
@@ -8978,6 +7654,15 @@ function renderActed(result) {
|
|
|
8978
7654
|
return [result.acted, result.session_id, result.url].filter(Boolean).join(" ");
|
|
8979
7655
|
}
|
|
8980
7656
|
|
|
7657
|
+
// src/asks.ts
|
|
7658
|
+
import { createHash as createHash11 } from "crypto";
|
|
7659
|
+
|
|
7660
|
+
// ../../packages/spec/src/ask-decision.ts
|
|
7661
|
+
import { createHash as createHash10 } from "crypto";
|
|
7662
|
+
var ASK_DECISION_HEADER = "x-agentsky-ask-decision";
|
|
7663
|
+
var PERSON_REQUIRED = "person_required";
|
|
7664
|
+
var ASK_DECISION_TTL_MS = 2 * 60 * 1e3;
|
|
7665
|
+
|
|
8981
7666
|
// src/asks.ts
|
|
8982
7667
|
async function listAsks(query) {
|
|
8983
7668
|
const params = new URLSearchParams();
|
|
@@ -8988,17 +7673,67 @@ async function listAsks(query) {
|
|
|
8988
7673
|
if (query.direction) params.set("direction", query.direction);
|
|
8989
7674
|
return api("GET", `/asks${params.size ? `?${params}` : ""}`);
|
|
8990
7675
|
}
|
|
8991
|
-
|
|
8992
|
-
return
|
|
7676
|
+
function answerFields(opts) {
|
|
7677
|
+
return {
|
|
8993
7678
|
...opts.option ? { option_id: opts.option } : {},
|
|
8994
7679
|
...opts.text ? { text: opts.text } : {},
|
|
8995
7680
|
...opts.engine ? { agent_type: opts.engine } : {},
|
|
8996
7681
|
...opts.model ? { llm: opts.model } : {}
|
|
8997
|
-
}
|
|
7682
|
+
};
|
|
7683
|
+
}
|
|
7684
|
+
function askAnswerCode(id2, opts) {
|
|
7685
|
+
return createHash11("sha256").update(`${id2}
|
|
7686
|
+
${JSON.stringify(answerFields(opts))}`).digest("hex").slice(0, 6).toUpperCase();
|
|
7687
|
+
}
|
|
7688
|
+
function refusalToAnswerAsPerson(env) {
|
|
7689
|
+
if (!env.stdinTTY || !env.stdoutTTY) return "sky asks answer needs you at an interactive terminal for an Ask only you may answer: it does not read a piped answer, so an agent cannot answer for you. Run it yourself, or answer it in AgentSky.";
|
|
7690
|
+
if (env.tokenFromEnv) return "SKY_API_TOKEN is set, so sky would answer with that key, not your own sign-in. Unset it and run sky asks answer again.";
|
|
7691
|
+
if (!env.signedIn) return "sky is not signed in on this computer: run `sky auth login`, then answer again.";
|
|
7692
|
+
return null;
|
|
7693
|
+
}
|
|
7694
|
+
function renderPersonAnswer(ask3, opts) {
|
|
7695
|
+
const answer = opts.text ?? (opts.option ? `option ${opts.option}` : "this answer");
|
|
7696
|
+
return [
|
|
7697
|
+
ask3 ? `${ask3.who.name}: ${ask3.need}` : "An Ask only you may answer.",
|
|
7698
|
+
...ask3?.detail ? [` ${ask3.detail}`] : [],
|
|
7699
|
+
` Your answer: ${answer}`,
|
|
7700
|
+
"Approve sends this answer as yours. Anything else leaves it waiting."
|
|
7701
|
+
];
|
|
7702
|
+
}
|
|
7703
|
+
var MAX_PAGES = 5;
|
|
7704
|
+
async function findAsk(id2) {
|
|
7705
|
+
let cursor;
|
|
7706
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
7707
|
+
const listed = await listAsks({ limit: "100", ...cursor ? { cursor } : {} });
|
|
7708
|
+
const found = listed.data.find((ask3) => ask3.id === id2);
|
|
7709
|
+
if (found) return found;
|
|
7710
|
+
if (!listed.next_cursor) return null;
|
|
7711
|
+
cursor = listed.next_cursor;
|
|
7712
|
+
}
|
|
7713
|
+
return null;
|
|
7714
|
+
}
|
|
7715
|
+
function isPersonOnly(error) {
|
|
7716
|
+
return error instanceof ApiError && error.status === 409 && error.code === PERSON_REQUIRED;
|
|
7717
|
+
}
|
|
7718
|
+
async function answerAsk(id2, opts, decisionId) {
|
|
7719
|
+
return api("POST", `/asks/${encodeURIComponent(id2)}/answer`, answerFields(opts), decisionId ? { headers: { [ASK_DECISION_HEADER]: decisionId } } : {});
|
|
7720
|
+
}
|
|
7721
|
+
async function recordDecision2(id2, opts) {
|
|
7722
|
+
const recorded = await api("POST", "/confirmations/ask-decisions", { ask_id: id2, answer: answerFields(opts) });
|
|
7723
|
+
return recorded.decision_id;
|
|
7724
|
+
}
|
|
7725
|
+
async function answerWithDecision(id2, opts, env, readCode, known) {
|
|
7726
|
+
const refusal = refusalToAnswerAsPerson(env);
|
|
7727
|
+
if (refusal) throw new Error(refusal);
|
|
7728
|
+
const code = askAnswerCode(id2, opts);
|
|
7729
|
+
const typed = await readCode(code, renderPersonAnswer(known, opts));
|
|
7730
|
+
if (typed.trim().toUpperCase() !== code) return { waiting: true };
|
|
7731
|
+
const decision = await recordDecision2(id2, opts);
|
|
7732
|
+
return { answered: await answerAsk(id2, opts, decision) };
|
|
8998
7733
|
}
|
|
8999
7734
|
function renderAsk(ask3) {
|
|
9000
7735
|
const choices = ask3.answer.options.length ? ` (${ask3.answer.options.map((option) => `${option.id}: ${option.label}`).join(", ")})` : "";
|
|
9001
|
-
const by = ask3.answer.answered_by === "person" ? ", only you
|
|
7736
|
+
const by = ask3.answer.answered_by === "person" ? ", only you" : "";
|
|
9002
7737
|
const why = ask3.why ? ` \u2014 ${ask3.why}` : "";
|
|
9003
7738
|
const member = (end) => end.name ?? (end.kind === "person" ? "you" : end.kind);
|
|
9004
7739
|
const ends = ask3.from && ask3.to ? `
|
|
@@ -9206,15 +7941,15 @@ function fileTableFrom(dir) {
|
|
|
9206
7941
|
}
|
|
9207
7942
|
function renderDesignSystem(system) {
|
|
9208
7943
|
const tokens = system.tokens;
|
|
9209
|
-
const
|
|
7944
|
+
const lines = [
|
|
9210
7945
|
`${system.artifact_id} ${system.title} v${system.version}${system.editable ? "" : " read-only"}`,
|
|
9211
7946
|
tokens ? `themes ${tokens.themes.map((theme) => theme.id).join(", ")} \xB7 ${tokens.colors.length} colors \xB7 ${tokens.typeGroups.reduce((sum, group) => sum + group.styles.length, 0)} type styles \xB7 ${tokens.spacing.length} spacing \xB7 ${tokens.radius.length} radius` : "no tokens.json",
|
|
9212
7947
|
`components: ${system.components.map((component) => component.name).join(", ") || "none"}`,
|
|
9213
7948
|
`assets: ${system.assets.map((group) => `${group.name} (${group.files.length})`).join(", ") || "none"}`
|
|
9214
7949
|
];
|
|
9215
|
-
if (system.last_change)
|
|
9216
|
-
for (const token of tokens?.dropped ?? [])
|
|
9217
|
-
return
|
|
7950
|
+
if (system.last_change) lines.push(`last change: ${system.last_change.by}${system.last_change.via ? ` via ${system.last_change.via}` : ""} at ${system.last_change.at}`);
|
|
7951
|
+
for (const token of tokens?.dropped ?? []) lines.push(`not read: ${token.family} ${token.name || "(unnamed)"}: ${token.reason}`);
|
|
7952
|
+
return lines.join("\n");
|
|
9218
7953
|
}
|
|
9219
7954
|
async function designComments(id2, input) {
|
|
9220
7955
|
return api(input ? "POST" : "GET", `/artifacts/${encodeURIComponent(id2)}/design-system/comments`, input);
|
|
@@ -9270,16 +8005,16 @@ function joinCodingPlan(dollars3, requestId2) {
|
|
|
9270
8005
|
return api("POST", "/billing/coding-plan", { amount_usd: amount, request_id: requestId2 });
|
|
9271
8006
|
}
|
|
9272
8007
|
var cancelCodingPlan = () => api("DELETE", "/billing/coding-plan");
|
|
9273
|
-
function renderCodingPlan(
|
|
9274
|
-
if (!
|
|
9275
|
-
const
|
|
9276
|
-
if (
|
|
9277
|
-
return
|
|
8008
|
+
function renderCodingPlan(plan) {
|
|
8009
|
+
if (!plan.active) {
|
|
8010
|
+
const lines2 = [`coding plan: not a member (enrollment ${plan.enrollment}; monthly amounts $${plan.amounts_usd.join(", $")})`];
|
|
8011
|
+
if (plan.charge_failure) lines2.push(` last charge failed: ${plan.charge_failure}`);
|
|
8012
|
+
return lines2.join("\n");
|
|
9278
8013
|
}
|
|
9279
|
-
const until =
|
|
9280
|
-
const
|
|
9281
|
-
if (
|
|
9282
|
-
return
|
|
8014
|
+
const until = plan.current_period_end?.slice(0, 10) ?? "?";
|
|
8015
|
+
const lines = [`coding plan: $${plan.monthly_credit_usd}/month, paid until ${until}, ${plan.renews ? "renews" : "does not renew"}`];
|
|
8016
|
+
if (plan.charge_failure) lines.push(` last charge failed: ${plan.charge_failure}`);
|
|
8017
|
+
return lines.join("\n");
|
|
9283
8018
|
}
|
|
9284
8019
|
function readRequestUsage(opts) {
|
|
9285
8020
|
const query = usageQuery(opts);
|
|
@@ -9287,10 +8022,10 @@ function readRequestUsage(opts) {
|
|
|
9287
8022
|
return api("GET", `/billing/usage/requests${query}${cursor}`);
|
|
9288
8023
|
}
|
|
9289
8024
|
function renderRequestUsage(page) {
|
|
9290
|
-
const
|
|
9291
|
-
if (!
|
|
9292
|
-
if (page.nextCursor)
|
|
9293
|
-
return
|
|
8025
|
+
const lines = page.rows.map((row) => `${row.at.slice(0, 19).replace("T", " ")} ${(row.apiKeyName ?? "").padEnd(16).slice(0, 16)} ${(row.model ?? "-").padEnd(28).slice(0, 28)} ${String(row.httpStatus ?? "-").padStart(3)} ${String(row.inputTokens ?? 0).padStart(9)} in ${String(row.outputTokens ?? 0).padStart(8)} out ${`$${(row.billedCostUsd ?? 0).toFixed(6)}`.padStart(11)}`);
|
|
8026
|
+
if (!lines.length) lines.push("no API requests in this range");
|
|
8027
|
+
if (page.nextCursor) lines.push(`more: --cursor ${page.nextCursor}`);
|
|
8028
|
+
return lines.join("\n");
|
|
9294
8029
|
}
|
|
9295
8030
|
var readReferralLinks = () => api("GET", "/billing/referral-links");
|
|
9296
8031
|
function referralLinkBody(opts) {
|
|
@@ -9312,17 +8047,17 @@ function referralLinkBody(opts) {
|
|
|
9312
8047
|
var createReferralLink = (opts) => api("POST", "/billing/referral-links", referralLinkBody(opts));
|
|
9313
8048
|
var disableReferralLink = (id2) => api("POST", `/billing/referral-links/${encodeURIComponent(id2)}/disable`);
|
|
9314
8049
|
function renderReferralLinks(dashboard) {
|
|
9315
|
-
const
|
|
8050
|
+
const lines = [`priced from ${dashboard.source_plan.name}: customers pay at least ${Math.round(dashboard.source_plan.multiplier * 100)}% of public price`];
|
|
9316
8051
|
for (const link2 of dashboard.links) {
|
|
9317
8052
|
const state = link2.disabled_at ? "disabled" : `expires ${link2.expires_at.slice(0, 10)}`;
|
|
9318
8053
|
const audience = link2.audience_email ? ` for ${link2.audience_email} (${link2.email_status})` : "";
|
|
9319
|
-
|
|
9320
|
-
|
|
8054
|
+
lines.push(` ${link2.id} ${Math.round(link2.customer_multiplier * 100)}% ${link2.redeemed_count}/${link2.max_redemptions} used ${state}${audience}`);
|
|
8055
|
+
lines.push(` ${link2.url}`);
|
|
9321
8056
|
}
|
|
9322
|
-
if (!dashboard.links.length)
|
|
8057
|
+
if (!dashboard.links.length) lines.push(" no links yet");
|
|
9323
8058
|
const earned = dashboard.earnings.reduce((sum, earning) => sum + earning.amount_usd, 0);
|
|
9324
|
-
|
|
9325
|
-
return
|
|
8059
|
+
lines.push(`earned $${earned.toFixed(2)} from ${dashboard.earnings.length} customer${dashboard.earnings.length === 1 ? "" : "s"}`);
|
|
8060
|
+
return lines.join("\n");
|
|
9326
8061
|
}
|
|
9327
8062
|
function multiplier(flag, value) {
|
|
9328
8063
|
const trimmed = value.trim();
|
|
@@ -9979,7 +8714,7 @@ agent.command("export <id>").description("write an agent as a manifest file that
|
|
|
9979
8714
|
console.log(`Wrote ${opts.output} (version ${version}) \u2014 change it and run \`sky agent apply -f ${opts.output}\`.`);
|
|
9980
8715
|
})
|
|
9981
8716
|
);
|
|
9982
|
-
var agentSlack = agent.command("slack").description("
|
|
8717
|
+
var agentSlack = agent.command("slack").description("an agent's thread in your DM with AgentSky, or its own Slack bot");
|
|
9983
8718
|
agentSlack.command("token").description("save the Slack app-configuration token agents' Slack apps are created with (refresh token, rotated by AgentSky from then on)").option("--refresh-token <token>", "a Slack app-configuration refresh token (xoxe-\u2026)").option("--from-slack-cli [team]", "take it from this computer's Slack CLI login (~/.slack/credentials.json); hands that login over, so run `slack login` again afterwards").action(
|
|
9984
8719
|
run2(async (opts) => {
|
|
9985
8720
|
const refreshToken = opts.refreshToken ?? (opts.fromSlackCli ? slackCliRefreshToken(typeof opts.fromSlackCli === "string" ? opts.fromSlackCli : void 0) : void 0);
|
|
@@ -10013,16 +8748,42 @@ agentSlack.command("unpublish <agent>").description("uninstall and delete the ag
|
|
|
10013
8748
|
console.log(`Removed from Slack: ${done.slack_app_ids.join(", ")}`);
|
|
10014
8749
|
})
|
|
10015
8750
|
);
|
|
8751
|
+
agentSlack.command("connect <agent>").description("connect the agent in Slack and open its messages").option("--no-open", "print the link instead of opening it").option("--json", "print the answer as JSON").action(
|
|
8752
|
+
run2(async (agentId, opts) => {
|
|
8753
|
+
const thread2 = await connectAgentSlackDm(agentId);
|
|
8754
|
+
if (opts.json) return void console.log(JSON.stringify(thread2, null, 2));
|
|
8755
|
+
const allow2 = thread2.status === "needs_you" ? thread2.next?.url : void 0;
|
|
8756
|
+
const url = allow2 ?? thread2.open_url;
|
|
8757
|
+
if (url && opts.open !== false) openBrowser(url);
|
|
8758
|
+
if (allow2) console.log(`Allow it in Slack: ${allow2}`);
|
|
8759
|
+
else console.log(thread2.open_url ? `Connected: ${thread2.open_url}` : "Connected.");
|
|
8760
|
+
})
|
|
8761
|
+
);
|
|
8762
|
+
agentSlack.command("dm <agent>").description("whether the agent is connected in Slack, and the link that opens it").option("--json", "print the answer as JSON").action(
|
|
8763
|
+
run2(async (agentId, opts) => {
|
|
8764
|
+
const thread2 = await agentSlackDm(agentId);
|
|
8765
|
+
if (opts.json) return void console.log(JSON.stringify(thread2, null, 2));
|
|
8766
|
+
const allow2 = thread2.status === "needs_you" ? thread2.next?.url : void 0;
|
|
8767
|
+
console.log(thread2.status === "published" ? `Connected: ${thread2.open_url}` : allow2 ? `Waiting for the Allow in Slack: ${allow2}` : thread2.installed ? "Not connected; the AgentSky app is already allowed in Slack." : "Not connected.");
|
|
8768
|
+
})
|
|
8769
|
+
);
|
|
8770
|
+
agentSlack.command("disconnect <agent>").description("take this agent out of Slack; your other agents stay").option("--json", "print the answer as JSON").action(
|
|
8771
|
+
run2(async (agentId, opts) => {
|
|
8772
|
+
const done = await disconnectAgentSlackDm(agentId);
|
|
8773
|
+
if (opts.json) return void console.log(JSON.stringify(done, null, 2));
|
|
8774
|
+
console.log("Disconnected. Your other agents stay.");
|
|
8775
|
+
})
|
|
8776
|
+
);
|
|
10016
8777
|
agent.command("record").description("how each harness and model did, as the session record tells it: sessions, decisions people recorded, spend").option("--since <date>", "ISO 8601 start (default: 30 days before --until)").option("--until <date>", "ISO 8601 end (default: now)").option("--json", "print the record as JSON").action(
|
|
10017
8778
|
run2(async (opts) => {
|
|
10018
|
-
const
|
|
8779
|
+
const record = await readAgentRecord(opts);
|
|
10019
8780
|
if (opts.json) {
|
|
10020
|
-
console.log(JSON.stringify(
|
|
8781
|
+
console.log(JSON.stringify(record, null, 2));
|
|
10021
8782
|
return;
|
|
10022
8783
|
}
|
|
10023
|
-
console.log(`${
|
|
10024
|
-
if (!
|
|
10025
|
-
for (const row of
|
|
8784
|
+
console.log(`${record.since.slice(0, 10)} \u2013 ${record.until.slice(0, 10)}`);
|
|
8785
|
+
if (!record.agents.length) console.log("no sessions in this window");
|
|
8786
|
+
for (const row of record.agents) console.log(renderAgentRecord(row));
|
|
10026
8787
|
})
|
|
10027
8788
|
);
|
|
10028
8789
|
agent.command("archive <id>").description("retire the spec \u2014 read-only, running sessions unaffected (admin scope)").action(
|
|
@@ -10511,12 +9272,12 @@ sessionSandbox.command("exec <ref> <command...>").description("run a shell comma
|
|
|
10511
9272
|
sessionSandbox.command("write <ref> <path> [file]").description("write a file in the workspace from a local file, or from stdin when none is given").option("--run <run>", "one of your own executions in the session: write on its own pod").action(
|
|
10512
9273
|
run2(async (ref, path2, file, opts) => {
|
|
10513
9274
|
const bytes = file ? readFileSync28(file) : readFileSync28(0);
|
|
10514
|
-
const { path: at, size
|
|
9275
|
+
const { path: at, size } = await api(
|
|
10515
9276
|
"PUT",
|
|
10516
9277
|
`/sessions/${encodeURIComponent(await resolveSessionRef(ref))}/sandbox/files`,
|
|
10517
9278
|
{ path: path2, content_base64: bytes.toString("base64"), ...opts.run ? { run_id: opts.run } : {} }
|
|
10518
9279
|
);
|
|
10519
|
-
console.log(`${at} (${
|
|
9280
|
+
console.log(`${at} (${size} bytes)`);
|
|
10520
9281
|
})
|
|
10521
9282
|
);
|
|
10522
9283
|
session.command("show-in-panel <id>").description("show something in the session's right panel, for whoever is watching on the web or the Mac").requiredOption("--kind <kind>", SHOW_KIND_CHOICES.join(", ")).option("--id <id>", "the artifact id").option("--artifact-version <n>", "an artifact's version; default the latest", Number).option("--url <url>", "the GitHub pull request URL").action(
|
|
@@ -10826,7 +9587,7 @@ async function launchFromFile(path2, spec, opts) {
|
|
|
10826
9587
|
console.log(`Launched ${created.id} (${created.agentType} \xB7 ${created.llm})`);
|
|
10827
9588
|
printModelBilling(session2);
|
|
10828
9589
|
console.log(opts.start ? " its first session is starting now" : " its first session starts on the first message");
|
|
10829
|
-
if (!spec.llm && !opts.llm) console.log(` model: ${created.llm}, the ${created.agentType} default \u2014 set llm = "\u2026" in ${
|
|
9590
|
+
if (!spec.llm && !opts.llm) console.log(` model: ${created.llm}, the ${created.agentType} default \u2014 set llm = "\u2026" in ${basename8(path2)} and run \`sky deploy\` to change it`);
|
|
10830
9591
|
console.log(` sky agent message ${created.id} "hello"`);
|
|
10831
9592
|
console.log(` sky agent chat ${created.id}`);
|
|
10832
9593
|
}
|
|
@@ -10834,7 +9595,7 @@ program.command("launch").description("scaffold ./agent.toml if absent, create t
|
|
|
10834
9595
|
run2(async (opts) => {
|
|
10835
9596
|
const path2 = resolve13(opts.file);
|
|
10836
9597
|
if (!existsSync15(path2)) {
|
|
10837
|
-
const name =
|
|
9598
|
+
const name = basename8(process.cwd()).replace(/[^a-zA-Z0-9 _-]/g, "") || "my-agent";
|
|
10838
9599
|
scaffoldAgentFile(path2, name);
|
|
10839
9600
|
console.log(`Scaffolded ${opts.file} \u2014 edit it anytime; re-apply with \`sky deploy\`.`);
|
|
10840
9601
|
}
|
|
@@ -11027,10 +9788,10 @@ Importing ${label} \u2026
|
|
|
11027
9788
|
);
|
|
11028
9789
|
var files = program.command("files").description("files: upload once, reference by id from any message");
|
|
11029
9790
|
function renderSearchPage(page) {
|
|
11030
|
-
const
|
|
11031
|
-
if (!
|
|
11032
|
-
if (page.nextCursor)
|
|
11033
|
-
return
|
|
9791
|
+
const lines = page.hits.map((hit) => `${hit.id} ${hit.path ?? hit.title}${hit.line ? `:${hit.line}` : ""} ${hit.snippet.replace(/\s+/g, " ").trim()}`);
|
|
9792
|
+
if (!lines.length) lines.push(page.partial ? "no hits on this page (some items could not be read)" : "no hits");
|
|
9793
|
+
if (page.nextCursor) lines.push(`\u2026 more: --cursor ${page.nextCursor}`);
|
|
9794
|
+
return lines.join("\n");
|
|
11034
9795
|
}
|
|
11035
9796
|
files.command("export").description("export the workspace's uploads with their Session mounts as an agentsky.files.v1 bundle").option("--out <file>", "write the bundle here instead of printing it").option("--reference", "carry each body by hash only (a copy inside this deployment)").option("--include-deleted", "list deleted uploads too").action(
|
|
11036
9797
|
run2(async (opts) => {
|
|
@@ -11241,8 +10002,8 @@ session.command("export <session>").description("write the session's record as a
|
|
|
11241
10002
|
run2(async (sessionId, opts) => {
|
|
11242
10003
|
const tier = opts.tier === "gold" || opts.tier === "exploratory" ? opts.tier : "silver";
|
|
11243
10004
|
const outDir = opts.out ?? `./harbor-${sessionId.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
|
11244
|
-
const { written, record
|
|
11245
|
-
console.log(`Wrote ${written.length} files to ${outDir} (${
|
|
10005
|
+
const { written, record } = await exportTaskHarbor(sessionId, outDir, { tier, redactNames: parseRedactNames(opts.redact) });
|
|
10006
|
+
console.log(`Wrote ${written.length} files to ${outDir} (${record.threads.length} thread${record.threads.length === 1 ? "" : "s"}, ${record.files.length} task file${record.files.length === 1 ? "" : "s"}${record.goal ? ", goal rubric" : ", no goal: derived rubric"})`);
|
|
11246
10007
|
if (!written.includes("environment/Dockerfile")) console.log("environment/: not resettable from the record \u2014 see environment/README.md before running with Harbor");
|
|
11247
10008
|
})
|
|
11248
10009
|
);
|
|
@@ -11561,13 +10322,13 @@ var USE_EXPORT = {
|
|
|
11561
10322
|
};
|
|
11562
10323
|
plugins.command("import <path>").description("add another agent platform's plugin as AgentSky plugins: a Claude Code or Codex plugin folder, a Codex config.toml, an mcp.json (generic, Cursor, ACP or xAI) or a folder sky plugins export wrote; skills and remote MCP servers map 1:1").option("--dry-run", "print what it would add and leave out, and add nothing").option("--json", "print the plan and the results as JSON").action(
|
|
11563
10324
|
run2(async (path2, opts) => {
|
|
11564
|
-
const
|
|
11565
|
-
const results = opts.dryRun ? [] : await runImport(
|
|
11566
|
-
if (opts.json) return void console.log(JSON.stringify({ plan
|
|
11567
|
-
console.log(`${
|
|
11568
|
-
for (const skill of
|
|
11569
|
-
for (const server of
|
|
11570
|
-
for (const skipped of
|
|
10325
|
+
const plan = planImport(path2);
|
|
10326
|
+
const results = opts.dryRun ? [] : await runImport(plan);
|
|
10327
|
+
if (opts.json) return void console.log(JSON.stringify({ plan, results }, null, 2));
|
|
10328
|
+
console.log(`${plan.name} (${plan.format}): ${plan.skills.length} skills, ${plan.servers.length} remote MCP servers${plan.core ? `, the core plugin ${plan.core}` : ""}.`);
|
|
10329
|
+
for (const skill of plan.skills) console.log(` skill ${skill.name}`);
|
|
10330
|
+
for (const server of plan.servers) console.log(` MCP server ${server.name} ${server.url}${server.tokenEnv ? ` (key from ${server.tokenEnv})` : ""}`);
|
|
10331
|
+
for (const skipped of plan.skipped) console.log(` left out ${skipped.part}: ${skipped.reason}`);
|
|
11571
10332
|
for (const result of results) console.log(` ${result.part}: ${result.result}${result.plugin_id ? ` ${result.plugin_id}` : ""}${result.detail ? ` \u2014 ${result.detail}` : ""}`);
|
|
11572
10333
|
})
|
|
11573
10334
|
);
|
|
@@ -11678,11 +10439,11 @@ skills.command("mine").description("your own skills, which follow you to every w
|
|
|
11678
10439
|
);
|
|
11679
10440
|
skills.command("local").description("the skills sky installed in this computer's engines (Claude Code, Codex, Cursor, Grok, Hermes), with each one's revision, layer and pin").option("--json", "print as JSON").option("--off", "stop installing skills on this computer and remove the folders sky wrote; folders you wrote stay").option("--on", "install the workspace's skills on this computer again from the next sync").action(
|
|
11680
10441
|
run2(async (opts) => {
|
|
11681
|
-
const { loadLocalSkillState, skillTargets: skillTargets2, turnOffLocalSkills, turnOnLocalSkills } = await import("./local-skills-
|
|
10442
|
+
const { loadLocalSkillState, skillTargets: skillTargets2, turnOffLocalSkills, turnOnLocalSkills } = await import("./local-skills-MTVILHBQ.js");
|
|
11682
10443
|
if (opts.off && opts.on) throw new Error("pass --off or --on, not both");
|
|
11683
10444
|
if (opts.off) {
|
|
11684
10445
|
const { detectLocalAgents: detectLocalAgents2 } = await import("./local-agents-O7PYSQGR.js");
|
|
11685
|
-
const { detectHermes: detectHermes2 } = await import("./mcp-register-
|
|
10446
|
+
const { detectHermes: detectHermes2 } = await import("./mcp-register-W7EVHT6T.js");
|
|
11686
10447
|
const removed = turnOffLocalSkills(skillTargets2(detectLocalAgents2(), detectHermes2()?.root ?? null, void 0, { all: true }));
|
|
11687
10448
|
return void console.log(`Skills are no longer installed on this computer${removed.length ? `; removed ${removed.length} that sky wrote` : ""}. \`sky skills local --on\` turns it back on.`);
|
|
11688
10449
|
}
|
|
@@ -11703,26 +10464,26 @@ skills.command("local").description("the skills sky installed in this computer's
|
|
|
11703
10464
|
);
|
|
11704
10465
|
skills.command("sync").description("install the workspace's skills and your own skills and changes in this computer's engines now; capture does this every 15 minutes").option("--workspace <slug>", "the workspace whose skills to install (default: where capture sends sessions, else your default)").option("--dry-run", "show what would change without writing").option("--json", "print the result as JSON").action(
|
|
11705
10466
|
run2(async (opts) => {
|
|
11706
|
-
const { describeLocalSkills, refreshLocalSkills } = await import("./local-skills-run-
|
|
10467
|
+
const { describeLocalSkills, refreshLocalSkills } = await import("./local-skills-run-DPAEXDNS.js");
|
|
11707
10468
|
const result = await refreshLocalSkills({ workspace: opts.workspace, dryRun: opts.dryRun });
|
|
11708
10469
|
if (opts.json) return void console.log(JSON.stringify(result, null, 2));
|
|
11709
10470
|
if (result.off) return void console.log("Skills are not installed on this computer (turned off); `sky skills local --on` turns it back on.");
|
|
11710
10471
|
if (!result.checked) return void console.log("no engine that reads skills is installed on this computer");
|
|
11711
|
-
const
|
|
11712
|
-
console.log(
|
|
11713
|
-
${
|
|
10472
|
+
const lines = describeLocalSkills(result);
|
|
10473
|
+
console.log(lines.length ? `Skills from ${result.workspace}:
|
|
10474
|
+
${lines.join("\n")}` : `Skills from ${result.workspace} are current.`);
|
|
11714
10475
|
})
|
|
11715
10476
|
);
|
|
11716
10477
|
skills.command("pin <name>").description("keep a skill installed on this computer at the revision it has now; syncs leave it until you unpin it").action(
|
|
11717
10478
|
run2(async (name) => {
|
|
11718
|
-
const { pinLocalSkill } = await import("./local-skills-
|
|
10479
|
+
const { pinLocalSkill } = await import("./local-skills-MTVILHBQ.js");
|
|
11719
10480
|
const pinned = pinLocalSkill(name);
|
|
11720
10481
|
console.log(`${name} stays at ${pinned.revision_id} on this computer`);
|
|
11721
10482
|
})
|
|
11722
10483
|
);
|
|
11723
10484
|
skills.command("unpin <name>").description("let a pinned skill follow its updates again from the next sync").action(
|
|
11724
10485
|
run2(async (name) => {
|
|
11725
|
-
const { unpinLocalSkill } = await import("./local-skills-
|
|
10486
|
+
const { unpinLocalSkill } = await import("./local-skills-MTVILHBQ.js");
|
|
11726
10487
|
console.log(unpinLocalSkill(name) ? `${name} follows its updates again` : `${name} was not pinned`);
|
|
11727
10488
|
})
|
|
11728
10489
|
);
|
|
@@ -11850,7 +10611,7 @@ library.command("list").description("your Library, newest first").option("--sear
|
|
|
11850
10611
|
library.command("upload <path>").description("save a file from this computer to your Library").option("--workspace <key>", "place it in this workspace").option("--session <id>", "save it as a result of this conversation of yours; the same name there saves a new version").action(
|
|
11851
10612
|
run2(async (path2, opts) => {
|
|
11852
10613
|
const bytes = readFileSync28(path2);
|
|
11853
|
-
const { artifact: artifact2 } = await uploadToLibrary({ bytes, name:
|
|
10614
|
+
const { artifact: artifact2 } = await uploadToLibrary({ bytes, name: basename8(path2), mediaType: "application/octet-stream" }, crypto.randomUUID(), opts.workspace, opts.session);
|
|
11854
10615
|
console.log(renderLibraryArtifact(artifact2));
|
|
11855
10616
|
})
|
|
11856
10617
|
);
|
|
@@ -11982,10 +10743,29 @@ asks.command("list").description("what waits on you: who is waiting, what is nee
|
|
|
11982
10743
|
if (page.partial?.length) console.log(`Could not read: ${page.partial.join(", ")}. This list is incomplete.`);
|
|
11983
10744
|
})
|
|
11984
10745
|
);
|
|
11985
|
-
asks.command("answer <id>").description("answer one; a payment, signature, plugin install or other approval
|
|
10746
|
+
asks.command("answer <id>").description("answer one; a payment, signature, plugin install or other approval is decided here after you type its code, at an interactive terminal signed in as yourself").option("--option <id>", "the option to answer with").option("--text <text>", "the answer, where free text is allowed").option("--engine <agentType>", "who starts, for a Start").option("--model <llm>", "the model they run").option("--json", "print as JSON").action(
|
|
11986
10747
|
run2(async (id2, opts) => {
|
|
11987
|
-
const
|
|
11988
|
-
|
|
10748
|
+
const env = { stdinTTY: Boolean(process.stdin.isTTY), stdoutTTY: Boolean(process.stdout.isTTY), tokenFromEnv: Boolean(process.env.SKY_API_TOKEN), signedIn: Boolean(loadConfig().token) };
|
|
10749
|
+
const known = await findAsk(id2).catch(() => null);
|
|
10750
|
+
const print = (result) => console.log(opts.json ? JSON.stringify(result, null, 2) : renderAnswered(result));
|
|
10751
|
+
const decide = async () => {
|
|
10752
|
+
const result = await answerWithDecision(id2, opts, env, async (code, lines) => {
|
|
10753
|
+
for (const line2 of lines) console.log(line2);
|
|
10754
|
+
const rl = createInterface5({ input: process.stdin, output: process.stdout });
|
|
10755
|
+
const typed = await new Promise((resolve14) => rl.question(`Type ${code} to answer as yourself, or press Enter to leave it waiting: `, resolve14));
|
|
10756
|
+
rl.close();
|
|
10757
|
+
return typed;
|
|
10758
|
+
}, known);
|
|
10759
|
+
if ("waiting" in result) return void console.log("Not answered: it is still waiting.");
|
|
10760
|
+
print(result.answered);
|
|
10761
|
+
};
|
|
10762
|
+
if (known?.answer.answered_by === "person") return decide();
|
|
10763
|
+
try {
|
|
10764
|
+
print(await answerAsk(id2, opts));
|
|
10765
|
+
} catch (error) {
|
|
10766
|
+
if (!isPersonOnly(error)) throw error;
|
|
10767
|
+
await decide();
|
|
10768
|
+
}
|
|
11989
10769
|
})
|
|
11990
10770
|
);
|
|
11991
10771
|
async function listApprovalsCommand(opts) {
|
|
@@ -12097,7 +10877,7 @@ artifact.command("copy <id>").description("copy one version into a new artifact
|
|
|
12097
10877
|
artifact.command("import [file]").description("bring in a file or, with --url, a public web page as a new artifact; its original is version 1's file").option("--url <url>", "a public https page to snapshot").option("--name <name>", "the artifact's name (default: the file's name or the page's title)").option("--task <session>", "the session whose shared folder holds it (default: your own imports folder)").option("--request-id <id>", "send the same value when retrying").action(
|
|
12098
10878
|
run2(async (file, opts) => {
|
|
12099
10879
|
if (Boolean(file) === Boolean(opts.url)) throw new Error("name a file or --url");
|
|
12100
|
-
console.log(renderArtifact(await importArtifact({ ...file ? { file: { name:
|
|
10880
|
+
console.log(renderArtifact(await importArtifact({ ...file ? { file: { name: basename8(file), bytes: readFileSync28(file) } } : { url: opts.url }, name: opts.name, taskId: opts.task, requestId: opts.requestId })));
|
|
12101
10881
|
})
|
|
12102
10882
|
);
|
|
12103
10883
|
artifact.command("export <id>").description("download an artifact in one of its formats (pdf, png, docx, html, markdown, csv, xlsx...); no --format is every file as a zip").option("--format <format>", "a format `sky artifact inspect` lists under export_formats").option("--artifact-version <version>", "an earlier version").requiredOption("-o, --out <path>", "where to write the bytes").action(
|
|
@@ -12531,17 +11311,17 @@ skyManager.command("autopilot").description("what your agents carry: each change
|
|
|
12531
11311
|
run2(async (opts) => {
|
|
12532
11312
|
const answer = await api("GET", "/sky/autopilot");
|
|
12533
11313
|
if (opts.json) return void console.log(JSON.stringify(answer, null, 2));
|
|
12534
|
-
const
|
|
12535
|
-
|
|
12536
|
-
for (const ask3 of answer.needs_you)
|
|
12537
|
-
for (const item of answer.work.filter((entry) => entry.needs_you))
|
|
12538
|
-
|
|
12539
|
-
for (const item of answer.work)
|
|
12540
|
-
|
|
12541
|
-
for (const wait of answer.waits)
|
|
12542
|
-
|
|
12543
|
-
for (const decision of answer.decisions)
|
|
12544
|
-
console.log(
|
|
11314
|
+
const lines = [];
|
|
11315
|
+
lines.push(`Needs you (${answer.needs_you.length + answer.work.filter((item) => item.needs_you).length})`);
|
|
11316
|
+
for (const ask3 of answer.needs_you) lines.push(` ${ask3.session_title ?? "Session"}: ${ask3.question} ${ask3.link}`);
|
|
11317
|
+
for (const item of answer.work.filter((entry) => entry.needs_you)) lines.push(` ${item.title}: ${item.ask}`);
|
|
11318
|
+
lines.push(`Work (${answer.work.length})`);
|
|
11319
|
+
for (const item of answer.work) lines.push(` [${LADDER_WORDS[item.stage] ?? item.stage}${item.evidence === "verified" ? "" : ", stated"}] ${item.title}${item.now ? ` \u2014 ${item.now}` : ""}`);
|
|
11320
|
+
lines.push(`Waiting (${answer.waits.length})`);
|
|
11321
|
+
for (const wait of answer.waits) lines.push(` ${wait.session_title ?? "Session"}: ${wait.what}${wait.last_seen ? ` (${wait.last_seen})` : ""}`);
|
|
11322
|
+
lines.push(`Decided for you today (${answer.decisions.length}); veto with: sky manager veto <id>`);
|
|
11323
|
+
for (const decision of answer.decisions) lines.push(` ${decision.id}${decision.status === "vetoed" ? " (vetoed)" : ""}: ${decision.what} \u2014 ${decision.why}`);
|
|
11324
|
+
console.log(lines.join("\n"));
|
|
12545
11325
|
})
|
|
12546
11326
|
);
|
|
12547
11327
|
skyManager.command("veto <decision>").description("veto a decision an agent made for you; its session is told to undo it").action(
|
|
@@ -13508,22 +12288,22 @@ program.command("capabilities").description("deprecated: sky plugins list --view
|
|
|
13508
12288
|
);
|
|
13509
12289
|
var mcpCommand = program.command("mcp").description("the AgentSky MCP server on this computer");
|
|
13510
12290
|
mcpCommand.command("serve").description("serve the AgentSky MCP server's short tool list over stdio, for a program that starts its servers itself (the Claude app's chat, as `sky setup` registers it); each request is sent with the token sky holds at that moment").action(run2(async () => {
|
|
13511
|
-
const { serveMcp } = await import("./mcp-serve-
|
|
12291
|
+
const { serveMcp } = await import("./mcp-serve-QTQXSRME.js");
|
|
13512
12292
|
await serveMcp();
|
|
13513
12293
|
}));
|
|
13514
12294
|
var compute = program.command("compute").description("the computers you set up with sky: the engines on each and whether each has the workspace's plugins, skills, capture and settings (the Compute group in Settings)");
|
|
13515
12295
|
compute.command("list", { isDefault: true }).description("every computer you set up with sky, newest report first, with what is not current on each engine").option("--json", "print the list as JSON").action(run2(async (opts) => {
|
|
13516
|
-
const { listComputeMachines, renderMachines } = await import("./compute-
|
|
12296
|
+
const { listComputeMachines, renderMachines } = await import("./compute-XAJFVSFL.js");
|
|
13517
12297
|
const machines = await listComputeMachines();
|
|
13518
12298
|
console.log(opts.json ? JSON.stringify({ machines }, null, 2) : renderMachines(machines));
|
|
13519
12299
|
}));
|
|
13520
12300
|
compute.command("repair <machine>").description("ask one of your computers to put its AgentSky setup right on its next scheduled run").option("--json", "print the answer as JSON").action(run2(async (machine, opts) => {
|
|
13521
|
-
const { requestRepair } = await import("./compute-
|
|
12301
|
+
const { requestRepair } = await import("./compute-XAJFVSFL.js");
|
|
13522
12302
|
const answer = await requestRepair(machine);
|
|
13523
12303
|
console.log(opts.json ? JSON.stringify({ machine: answer }, null, 2) : `${answer.name} repairs on its next run (at most 15 minutes while it is on).`);
|
|
13524
12304
|
}));
|
|
13525
12305
|
compute.command("remove <machine>").description("forget one of your computers; nothing on it changes (run `sky setup --remove` there to take AgentSky out)").action(run2(async (machine) => {
|
|
13526
|
-
const { removeMachine } = await import("./compute-
|
|
12306
|
+
const { removeMachine } = await import("./compute-XAJFVSFL.js");
|
|
13527
12307
|
await removeMachine(machine);
|
|
13528
12308
|
console.log(`Forgot ${machine}. It reports again on its next run unless \`sky setup --remove\` ran there.`);
|
|
13529
12309
|
}));
|
|
@@ -13610,7 +12390,7 @@ function bundleBody(file, requestId2, extra = {}) {
|
|
|
13610
12390
|
throw new Error(`${file} is not a JSON bundle`);
|
|
13611
12391
|
}
|
|
13612
12392
|
if (!bundle || typeof bundle !== "object" || Array.isArray(bundle)) throw new Error(`${file} is not a JSON bundle`);
|
|
13613
|
-
const derived = `import_${
|
|
12393
|
+
const derived = `import_${createHash12("sha256").update(text2).digest("hex").slice(0, 32)}`;
|
|
13614
12394
|
return { ...bundle, request_id: requestId2 ?? derived, ...extra };
|
|
13615
12395
|
}
|
|
13616
12396
|
function bundleQuery(entries) {
|
|
@@ -14192,7 +12972,7 @@ harness.command("connect").description("run an ACP agent (the command after --)
|
|
|
14192
12972
|
}));
|
|
14193
12973
|
var traceCmd = program.command("trace").description("correlate this machine's agent work with the cloud sessions it starts (metadata only unless you choose content)");
|
|
14194
12974
|
traceCmd.command("start").description("start a trace: a grant for this machine, a root span, and the spool the hooks write to").option("--name <name>", "a name for the task").option("--source <source>", "how this machine reports itself", "claude-code").option("--hooks [settings]", "also install the Claude Code hooks (default: ./.claude/settings.local.json)").option("--capture <scopes>", "also send content, redacted on this machine first: any of prompts,tool_output,files").option("--file <path>", "a file the files scope may send (repeatable)", collect).option("--dir <path>", "a folder whose files the files scope may send when a file tool touches them (repeatable)", collect).action(run2(async (opts) => {
|
|
14195
|
-
const { readState, writeState, record
|
|
12975
|
+
const { readState, writeState, record, installClaudeHooks, parseContentScopes, chosenPaths, fileEvent } = await import("./trace-CMWC4LFX.js");
|
|
14196
12976
|
if (readState()) throw new Error("a trace is already running here \u2014 `sky trace stop` it first");
|
|
14197
12977
|
const scopes = parseContentScopes(opts.capture);
|
|
14198
12978
|
const chosen = chosenPaths(opts.file ?? [], opts.dir ?? []);
|
|
@@ -14215,7 +12995,7 @@ traceCmd.command("start").description("start a trace: a grant for this machine,
|
|
|
14215
12995
|
...scopes.length ? { content_scopes: scopes, files: chosen.files, dirs: chosen.dirs } : {}
|
|
14216
12996
|
};
|
|
14217
12997
|
writeState(state);
|
|
14218
|
-
|
|
12998
|
+
record(() => [
|
|
14219
12999
|
{ span_id: root2, parent_span_id: null, kind: "start", name: opts.name ?? "task" },
|
|
14220
13000
|
...chosen.files.flatMap((path2) => fileEvent(root2, path2, state) ?? [])
|
|
14221
13001
|
]);
|
|
@@ -14227,11 +13007,11 @@ traceCmd.command("start").description("start a trace: a grant for this machine,
|
|
|
14227
13007
|
}));
|
|
14228
13008
|
traceCmd.command("hook").description("record one Claude Code hook event read from stdin (run by the installed hooks; never fails, prints nothing)").action(async () => {
|
|
14229
13009
|
try {
|
|
14230
|
-
const { readState, record
|
|
13010
|
+
const { readState, record, flush, grantSender, eventsForClaudeHook, contentForClaudeHook, clearState } = await import("./trace-CMWC4LFX.js");
|
|
14231
13011
|
const chunks = [];
|
|
14232
13012
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
14233
13013
|
const input = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
|
|
14234
|
-
if (!
|
|
13014
|
+
if (!record((state2) => [...eventsForClaudeHook(input, state2), ...contentForClaudeHook(input, state2)])) return;
|
|
14235
13015
|
const state = readState();
|
|
14236
13016
|
if (!state) return;
|
|
14237
13017
|
const outcome = await flush(grantSender(state, 3e3));
|
|
@@ -14240,14 +13020,14 @@ traceCmd.command("hook").description("record one Claude Code hook event read fro
|
|
|
14240
13020
|
}
|
|
14241
13021
|
});
|
|
14242
13022
|
traceCmd.command("flush").description("send what the spool holds, retrying with backoff").action(run2(async () => {
|
|
14243
|
-
const { readState, flush, grantSender } = await import("./trace-
|
|
13023
|
+
const { readState, flush, grantSender } = await import("./trace-CMWC4LFX.js");
|
|
14244
13024
|
const state = readState();
|
|
14245
13025
|
if (!state) throw new Error("no trace is running here");
|
|
14246
13026
|
const outcome = await flush(grantSender(state), { attempts: 4 });
|
|
14247
13027
|
console.log(`sent ${outcome.sent}, refused ${outcome.refused}, given up ${outcome.expired}, still pending ${outcome.pending}${outcome.stopped ? ` (stopped: ${outcome.stopped})` : ""}`);
|
|
14248
13028
|
}));
|
|
14249
13029
|
traceCmd.command("status").description("the running trace and its spool").action(run2(async () => {
|
|
14250
|
-
const { readState, spoolStatus } = await import("./trace-
|
|
13030
|
+
const { readState, spoolStatus } = await import("./trace-CMWC4LFX.js");
|
|
14251
13031
|
const state = readState();
|
|
14252
13032
|
if (!state) {
|
|
14253
13033
|
console.log("No trace is running here.");
|
|
@@ -14257,7 +13037,7 @@ traceCmd.command("status").description("the running trace and its spool").action
|
|
|
14257
13037
|
console.log(`${state.trace_id} as ${state.source}: ${spool.pending} pending, ${spool.dropped_full} dropped (spool full), ${spool.dropped_expired} given up, ${spool.refused} refused`);
|
|
14258
13038
|
}));
|
|
14259
13039
|
traceCmd.command("show [id]").description("the trace bundle: spans, the sessions they reach, cost counted once per session").option("--json", "print the bundle as JSON").action(run2(async (id2, opts) => {
|
|
14260
|
-
const { readState } = await import("./trace-
|
|
13040
|
+
const { readState } = await import("./trace-CMWC4LFX.js");
|
|
14261
13041
|
const ref = id2 ?? readState()?.trace_id;
|
|
14262
13042
|
if (!ref) throw new Error("name a trace, or start one here");
|
|
14263
13043
|
const bundle = await api("GET", `/traces/${ref}`);
|
|
@@ -14284,10 +13064,10 @@ traceCmd.command("show [id]").description("the trace bundle: spans, the sessions
|
|
|
14284
13064
|
for (const gap of bundle.gaps) console.log(` gap: ${gap.span_id} ${gap.reason}`);
|
|
14285
13065
|
}));
|
|
14286
13066
|
traceCmd.command("stop").description("end the root span, send what is left, and revoke this machine's grant").action(run2(async () => {
|
|
14287
|
-
const { readState, record
|
|
13067
|
+
const { readState, record, flush, grantSender, clearState } = await import("./trace-CMWC4LFX.js");
|
|
14288
13068
|
const state = readState();
|
|
14289
13069
|
if (!state) throw new Error("no trace is running here");
|
|
14290
|
-
if (state.root_span)
|
|
13070
|
+
if (state.root_span) record(() => [{ span_id: state.root_span, kind: "end", outcome: "completed" }]);
|
|
14291
13071
|
const outcome = await flush(grantSender(readState() ?? state), { attempts: 4 });
|
|
14292
13072
|
await api("DELETE", `/traces/${state.trace_id}/grants/${state.grant_id}`);
|
|
14293
13073
|
clearState();
|
|
@@ -14297,7 +13077,7 @@ var recordCmd = traceCmd.command("record").description("record every Claude Code
|
|
|
14297
13077
|
const { homedir: homedir12 } = await import("os");
|
|
14298
13078
|
const { join: join21 } = await import("path");
|
|
14299
13079
|
const vault2 = await import("./trace-vault-IUNYRVGZ.js");
|
|
14300
|
-
const { installClaudeHooks, uninstallClaudeHooks } = await import("./trace-
|
|
13080
|
+
const { installClaudeHooks, uninstallClaudeHooks } = await import("./trace-CMWC4LFX.js");
|
|
14301
13081
|
const command = "sky trace record hook";
|
|
14302
13082
|
const config = vault2.loadVaultConfig();
|
|
14303
13083
|
const settings = resolve13(opts.settings ?? config.settings ?? join21(process.env.CLAUDE_CONFIG_DIR ?? join21(homedir12(), ".claude"), "settings.json"));
|
|
@@ -14361,8 +13141,8 @@ recordCmd.command("seal <session-dir>").description("seal the cut segments of on
|
|
|
14361
13141
|
vault2.markPartial(resolve13(session2, "..", "..", ".."), session2.split(/[\\/]/).filter(Boolean).pop(), error);
|
|
14362
13142
|
}
|
|
14363
13143
|
});
|
|
14364
|
-
traceCmd.command("sync [payload]").description("upload this machine's agent sessions (Claude Code, Codex, Cursor, Gemini CLI and every other agent `--agents` lists) to the matching workspace's trace library, redacted here first").option("--enable", "turn sync on for this machine").option("--disable", "turn sync off; nothing more is uploaded").option("--route <match=workspace>", "send sessions whose folder path contains <match> to <workspace> (repeatable; replaces the saved rules)", collect).option("--default <workspace>", "where a session no rule matches goes").option("--keep-local", "keep sessions no rule matches on this machine (the default)").option("--exclude <folder>", "never upload a session that ran in <folder> or below it, to the library or as a session (repeatable; shared with the AgentSky Mac app when it is installed)", collect).option("--unexclude <folder>", "stop excluding <folder> (repeatable)", collect).option("--session <ref>", "only this session: its id or transcript path (repeatable)", collect).option("--import <export>", "add a downloaded cloud export (claude.ai, ChatGPT, Gemini, Grok, DeepSeek \u2026: its .zip, folder or file) so sync uploads it (repeatable)", collect).option("--agents", "list the agents sync reads and which are on this machine").option("--full", "re-read every session, not only files that changed").option("--limit <n>", "at most this many changed sessions this run", (v) => Number.parseInt(v, 10)).option("--dry-run", "show what would be uploaded without uploading").option("--hook", "run from a Claude Code SessionEnd hook or Codex notify: upload that session in the background and return at once").option("--install-schedule", "also sweep every 15 minutes (macOS launchd)").option("--install-hooks", "also sync at the end of every Claude Code and Codex turn (their hook and notify settings)").option("--status", "what sync has done on this machine").option("--quiet", "print only failures").action(async (payload, opts) => {
|
|
14365
|
-
const lib = await import("./trace-library-
|
|
13144
|
+
traceCmd.command("sync [payload]").description("upload this machine's agent sessions (Claude Code, Codex, Cursor, Gemini CLI and every other agent `--agents` lists) to the matching workspace's trace library, redacted here first").option("--enable", "turn sync on for this machine").option("--disable", "turn sync off; nothing more is uploaded").option("--route <match=workspace>", "send sessions whose folder path contains <match> to <workspace> (repeatable; replaces the saved rules)", collect).option("--default <workspace>", "where a session no rule matches goes").option("--keep-local", "keep sessions no rule matches on this machine (the default)").option("--personal <workspace>", "your personal workspace: the only place a session holding personal data (passport, medical, insurance, phone, address \u2026) is uploaded").option("--allow-shared-private", "let sessions that hold personal data go to a workspace other than your personal one").option("--exclude <folder>", "never upload a session that ran in <folder> or below it, to the library or as a session (repeatable; shared with the AgentSky Mac app when it is installed)", collect).option("--unexclude <folder>", "stop excluding <folder> (repeatable)", collect).option("--session <ref>", "only this session: its id or transcript path (repeatable)", collect).option("--agent <id>", "only sessions of this agent (grok-bot, muse, claude_code, codex \u2026 as `--agents` lists them; repeatable)", collect).option("--import <export>", "add a downloaded cloud export (claude.ai, ChatGPT, Gemini, Grok, DeepSeek \u2026: its .zip, folder or file) so sync uploads it (repeatable)", collect).option("--agents", "list the agents sync reads and which are on this machine").option("--full", "re-read every session, not only files that changed").option("--limit <n>", "at most this many changed sessions this run", (v) => Number.parseInt(v, 10)).option("--dry-run", "show what would be uploaded without uploading").option("--hook", "run from a Claude Code SessionEnd hook or Codex notify: upload that session in the background and return at once").option("--install-schedule", "also sweep every 15 minutes (macOS launchd)").option("--install-hooks", "also sync at the end of every Claude Code and Codex turn (their hook and notify settings)").option("--status", "what sync has done on this machine").option("--quiet", "print only failures").action(async (payload, opts) => {
|
|
13145
|
+
const lib = await import("./trace-library-XVUYQB5X.js");
|
|
14366
13146
|
if (opts.hook) {
|
|
14367
13147
|
try {
|
|
14368
13148
|
let raw = payload ?? "";
|
|
@@ -14387,14 +13167,14 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14387
13167
|
return;
|
|
14388
13168
|
}
|
|
14389
13169
|
if (opts.exclude || opts.unexclude) {
|
|
14390
|
-
const { changeExclusions, macSettingsPath } = await import("./trace-exclusions-
|
|
13170
|
+
const { changeExclusions, macSettingsPath } = await import("./trace-exclusions-2KLVHVSW.js");
|
|
14391
13171
|
const { dirname: dirname13 } = await import("path");
|
|
14392
13172
|
const changed = changeExclusions(dirname13(lib.syncConfigPath()), { add: opts.exclude, remove: opts.unexclude });
|
|
14393
13173
|
console.log(changed.exclusions.folders.length ? "Sync never uploads sessions that ran in:" : "No folder is excluded.");
|
|
14394
13174
|
for (const folder of changed.exclusions.folders) console.log(` ${folder}`);
|
|
14395
13175
|
if (changed.written === "mac") console.log(`Saved in the AgentSky Mac app's settings (${macSettingsPath()}), so the app leaves them out too.`);
|
|
14396
13176
|
}
|
|
14397
|
-
const changedSettings = opts.enable || opts.route || opts.default || opts.keepLocal;
|
|
13177
|
+
const changedSettings = opts.enable || opts.route || opts.default || opts.keepLocal || opts.personal;
|
|
14398
13178
|
if (changedSettings) {
|
|
14399
13179
|
if (opts.enable && !apiToken()) throw new Error("not logged in \u2014 run `sky auth login` first");
|
|
14400
13180
|
const rules = opts.route ? opts.route.map((spec) => {
|
|
@@ -14407,7 +13187,8 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14407
13187
|
rules,
|
|
14408
13188
|
enabled: opts.enable ? true : config.enabled,
|
|
14409
13189
|
enabledAt: opts.enable ? (/* @__PURE__ */ new Date()).toISOString() : config.enabledAt,
|
|
14410
|
-
fallback: opts.keepLocal ? void 0 : opts.default ?? config.fallback
|
|
13190
|
+
fallback: opts.keepLocal ? void 0 : opts.default ?? config.fallback,
|
|
13191
|
+
personal: opts.personal ?? config.personal
|
|
14411
13192
|
};
|
|
14412
13193
|
lib.saveSyncConfig(next);
|
|
14413
13194
|
console.log(`Trace sync is ${next.enabled ? "on" : "off"} on this machine. It reads only:`);
|
|
@@ -14415,6 +13196,7 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14415
13196
|
console.log("and sends each session, redacted here first, to:");
|
|
14416
13197
|
for (const rule of next.rules) console.log(` folder path contains "${rule.match}" \u2192 ${rule.workspace}`);
|
|
14417
13198
|
console.log(` anything else \u2192 ${next.fallback ?? "stays on this machine"}`);
|
|
13199
|
+
console.log(` sessions holding personal data \u2192 ${next.personal ?? "stay on this machine (set --personal <workspace>)"} only`);
|
|
14418
13200
|
console.log(`A repository's .agentsky.json "workspace" wins over these rules.`);
|
|
14419
13201
|
if (next.sessions !== false) console.log("Each Claude Code and Codex conversation also becomes one session there, read by whoever that workspace's default for synced chats names, with the files it published, made and was given saved as its results.");
|
|
14420
13202
|
}
|
|
@@ -14428,6 +13210,11 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14428
13210
|
for (const input of opts.import ?? []) {
|
|
14429
13211
|
const imported = await lib.importExport(input);
|
|
14430
13212
|
console.log(`Added ${imported.sessions} ${imported.agent} session${imported.sessions === 1 ? "" : "s"} from ${input}.`);
|
|
13213
|
+
if (imported.sensitive) {
|
|
13214
|
+
const { describeFindings } = await import("./trace-privacy-DU3TL5EO.js");
|
|
13215
|
+
console.log(` ${imported.sensitive} of them hold personal data the export did not redact (${describeFindings({ sensitive: true, findings: imported.findings, messages_flagged: 0, messages: 0 })}).`);
|
|
13216
|
+
console.log(` Sync uploads those only to ${config.personal ?? "your personal workspace once you run `sky trace sync --personal <workspace>`"}; they stay on this computer otherwise.`);
|
|
13217
|
+
}
|
|
14431
13218
|
}
|
|
14432
13219
|
if (opts.installHooks) for (const line2 of lib.installSyncHooks()) console.log(line2);
|
|
14433
13220
|
if (opts.installSchedule) {
|
|
@@ -14458,7 +13245,7 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14458
13245
|
}
|
|
14459
13246
|
console.log(`Trace sync is ${config.enabled ? "on" : "off"}${config.enabledAt ? ` (since ${config.enabledAt})` : ""}. Last full sweep: ${state.lastFullAt ?? "never"}.`);
|
|
14460
13247
|
for (const [label, count] of [...counts].sort((a, b) => b[1] - a[1])) console.log(` ${count} ${label}`);
|
|
14461
|
-
const { loadExclusions } = await import("./trace-exclusions-
|
|
13248
|
+
const { loadExclusions } = await import("./trace-exclusions-2KLVHVSW.js");
|
|
14462
13249
|
for (const folder of loadExclusions(join21(lib.syncConfigPath(), "..")).folders) console.log(` excluded: ${folder}`);
|
|
14463
13250
|
return;
|
|
14464
13251
|
}
|
|
@@ -14468,6 +13255,8 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14468
13255
|
only: opts.session,
|
|
14469
13256
|
dryRun: opts.dryRun,
|
|
14470
13257
|
limit: opts.limit,
|
|
13258
|
+
allowSharedPrivate: opts.allowSharedPrivate,
|
|
13259
|
+
agents: opts.agent,
|
|
14471
13260
|
onProgress: opts.quiet ? void 0 : (line2) => console.log(line2)
|
|
14472
13261
|
});
|
|
14473
13262
|
if (!report) {
|
|
@@ -14475,7 +13264,7 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14475
13264
|
return;
|
|
14476
13265
|
}
|
|
14477
13266
|
if (!opts.dryRun) {
|
|
14478
|
-
const { describeLocalSkills, refreshLocalSkills } = await import("./local-skills-run-
|
|
13267
|
+
const { describeLocalSkills, refreshLocalSkills } = await import("./local-skills-run-DPAEXDNS.js");
|
|
14479
13268
|
try {
|
|
14480
13269
|
const skills2 = await refreshLocalSkills({ hook: Boolean(opts.session?.length) });
|
|
14481
13270
|
if (skills2 && !opts.quiet) for (const line2 of describeLocalSkills(skills2)) console.log(line2);
|
|
@@ -14486,20 +13275,64 @@ traceCmd.command("sync [payload]").description("upload this machine's agent sess
|
|
|
14486
13275
|
if (!opts.quiet || report.failed) {
|
|
14487
13276
|
if (report.legacySources) console.log(`Kept ${report.legacySources} unbound legacy source archives locally; no ownership was inferred.`);
|
|
14488
13277
|
const where = Object.entries(report.byWorkspace).map(([workspace2, count]) => `${count} \u2192 ${workspace2}`).join(", ");
|
|
14489
|
-
console.log(`${opts.dryRun ? "Would upload" : "Uploaded"} ${report.uploaded}${where ? ` (${where})` : ""}; unchanged ${report.unchanged}; saved as sessions ${report.sessions}; excluded ${report.excluded}; left out as paused ${report.paused}; kept local ${report.local}; empty ${report.empty}; another member's ${report.owned}; failed ${report.failed}. Scanned ${report.scanned}, ${report.changed} changed.`);
|
|
13278
|
+
console.log(`${opts.dryRun ? "Would upload" : "Uploaded"} ${report.uploaded}${where ? ` (${where})` : ""}; unchanged ${report.unchanged}; saved as sessions ${report.sessions}; excluded ${report.excluded}; left out as paused ${report.paused}; kept local ${report.local}${report.held ? ` (${report.held} of them hold personal data; rerun with --full after setting --personal to send them to it)` : ""}; empty ${report.empty}; another member's ${report.owned}; failed ${report.failed}. Scanned ${report.scanned}, ${report.changed} changed.`);
|
|
14490
13279
|
for (const error of report.errors.slice(0, 20)) console.error(` ${error}`);
|
|
14491
13280
|
}
|
|
14492
13281
|
if (!opts.session && !opts.dryRun) {
|
|
14493
|
-
const { upkeepComputer } = await import("./compute-report-
|
|
13282
|
+
const { upkeepComputer } = await import("./compute-report-GKDPX4XS.js");
|
|
14494
13283
|
const said = await upkeepComputer().catch((error) => `AgentSky could not check this computer's setup: ${error instanceof Error ? error.message : String(error)}`);
|
|
14495
13284
|
if (said) console.log(said);
|
|
14496
13285
|
}
|
|
14497
13286
|
if (report.failed) process.exitCode = 1;
|
|
14498
13287
|
})();
|
|
14499
13288
|
});
|
|
13289
|
+
traceCmd.command("handoff <session>").description("hand a collected session (Grok Bot, Muse, Instinct or any other source `trace sync --agents` lists) to Claude Code, Codex or an AgentSky agent, with its whole conversation").requiredOption("--to <target>", "claude_code | codex | agentsky | grok-bot (grok-bot: a Grok Bot trace export folder, from a Claude Code or Codex session file or any collected session; agentsky: written as a Claude Code session, then sent through `sky import`, which continues it in the cloud)").option("--dir <folder>", "the folder the engine works in", ".").option("--out <folder>", "grok-bot only: where the Grok Bot trace export (manifest.json + sessions/) is written").option("--workspace <workspace>", "agentsky only: the workspace the session goes to (default: your personal workspace)").option("--allow-shared-private", "agentsky only: let a session that holds personal data go to a workspace other than your personal one").option("--json", "print the result as JSON").action(
|
|
13290
|
+
run2(async (ref, opts) => {
|
|
13291
|
+
const handoff2 = await import("./trace-handoff-CD5LOS7B.js");
|
|
13292
|
+
if (!handoff2.HANDOFF_TARGETS.includes(opts.to)) throw new Error("--to takes claude_code, codex, agentsky or grok-bot");
|
|
13293
|
+
const lib = await import("./trace-library-XVUYQB5X.js");
|
|
13294
|
+
const store = await lib.collectorStore();
|
|
13295
|
+
const found = await handoff2.findTrace(ref, store, lib.collectorDir());
|
|
13296
|
+
if (!found) throw new Error(`no collected session "${ref}": add an export with \`sky trace sync --import <export>\` first`);
|
|
13297
|
+
const config = lib.loadSyncConfig();
|
|
13298
|
+
if (opts.to === "grok-bot") {
|
|
13299
|
+
const { writeGrokBotExport } = await import("./grok-bot-export-7LSTXWJW.js");
|
|
13300
|
+
const out = resolve13(opts.out ?? opts.dir);
|
|
13301
|
+
const written = writeGrokBotExport([found.trace], out, found.trace.harness);
|
|
13302
|
+
if (opts.json) console.log(JSON.stringify({ target: "grok-bot", ...written }));
|
|
13303
|
+
else console.log(`Wrote ${written.rows} rows to ${written.manifest} and sessions/`);
|
|
13304
|
+
return;
|
|
13305
|
+
}
|
|
13306
|
+
const engine = opts.to === "codex" ? "codex" : "claude_code";
|
|
13307
|
+
if (opts.to === "agentsky") {
|
|
13308
|
+
const hold = handoff2.agentskyHold(found.trace, opts.workspace ?? config.personal, config, opts.allowSharedPrivate);
|
|
13309
|
+
if (hold) throw new Error(hold);
|
|
13310
|
+
}
|
|
13311
|
+
const landed = handoff2.handOff(found.trace, engine, resolve13(opts.dir), { transcript: found.path });
|
|
13312
|
+
let continueUrl;
|
|
13313
|
+
if (opts.to === "agentsky") {
|
|
13314
|
+
const { execFileSync } = await import("child_process");
|
|
13315
|
+
const out = execFileSync(process.execPath, [process.argv[1], "import", "--session", landed.nativeId, "--harness", "claude_code", "--yes", "--json"], { encoding: "utf8", env: process.env });
|
|
13316
|
+
continueUrl = out.trim().split("\n").filter(Boolean).map((line2) => {
|
|
13317
|
+
try {
|
|
13318
|
+
return JSON.parse(line2);
|
|
13319
|
+
} catch {
|
|
13320
|
+
return {};
|
|
13321
|
+
}
|
|
13322
|
+
}).map((row) => row.continue_url ?? row.url).find(Boolean);
|
|
13323
|
+
}
|
|
13324
|
+
if (opts.json) {
|
|
13325
|
+
console.log(JSON.stringify({ ...landed, continue_url: continueUrl }));
|
|
13326
|
+
return;
|
|
13327
|
+
}
|
|
13328
|
+
const { toolCalls, summarised } = landed.report;
|
|
13329
|
+
console.error(`Wrote ${landed.engine === "codex" ? "Codex" : "Claude Code"} session ${landed.nativeId}: ${landed.report.messages.user + landed.report.messages.agent} messages, ${toolCalls.mapped} tool calls in its own form, ${toolCalls.asText} as text${summarised ? `; the oldest ${summarised} messages are summarised at the top` : ""}.`);
|
|
13330
|
+
console.log(continueUrl ?? landed.resume);
|
|
13331
|
+
})
|
|
13332
|
+
);
|
|
14500
13333
|
traceCmd.command("mac <machine>").description("which workspace's trace library one of your Macs fills; the AgentSky Mac app uploads that Mac's agent sessions there, redacted on the Mac first, exactly as `sky trace sync` would (machine ids: `sky api GET /desktop/machines`)").option("--on", "send this Mac's sessions to --workspace (or the current workspace), moving them from any other").option("--off", "stop this Mac's uploads to --workspace (or the current workspace)").option("--workspace <slug>", "the workspace to turn on or off (default: the current one)").option("--json", "print the answer as JSON").action(run2(async (machine, opts) => {
|
|
14501
13334
|
if (opts.on && opts.off) throw new Error("choose --on or --off");
|
|
14502
|
-
const { libraryRequest } = await import("./trace-library-
|
|
13335
|
+
const { libraryRequest } = await import("./trace-library-XVUYQB5X.js");
|
|
14503
13336
|
const workspace2 = opts.workspace ?? currentUniverse();
|
|
14504
13337
|
if (!workspace2) throw new Error("name a workspace with --workspace");
|
|
14505
13338
|
const answer = opts.on || opts.off ? await libraryRequest("PUT", `/trace-library/devices/${encodeURIComponent(machine)}`, workspace2, { enabled: Boolean(opts.on) }) : await libraryRequest("GET", `/trace-library/devices/${encodeURIComponent(machine)}`, workspace2);
|
|
@@ -14516,7 +13349,7 @@ traceCmd.command("search <query...>").description("search every session in a wor
|
|
|
14516
13349
|
console.log(opts.json ? JSON.stringify(page, null, 2) : renderContextPage(page));
|
|
14517
13350
|
}));
|
|
14518
13351
|
traceCmd.command("library").description("list the sessions in a workspace's trace library, most recently updated first").option("--workspace <slug>", "the workspace (default: the current one)").option("--limit <n>", "how many", (v) => Number.parseInt(v, 10), 20).option("--json", "print the page as JSON").action(run2(async (opts) => {
|
|
14519
|
-
const { libraryRequest } = await import("./trace-library-
|
|
13352
|
+
const { libraryRequest } = await import("./trace-library-XVUYQB5X.js");
|
|
14520
13353
|
const workspace2 = opts.workspace ?? currentUniverse();
|
|
14521
13354
|
if (!workspace2) throw new Error("name a workspace with --workspace");
|
|
14522
13355
|
const page = await libraryRequest("GET", `/trace-library?limit=${opts.limit}`, workspace2);
|