@agentsky/sky 3.45.0 → 3.47.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.
Files changed (26) hide show
  1. package/agent-plugins/plugins/meetings/.codex-plugin/plugin.json +1 -1
  2. package/agent-plugins/plugins/meetings/skills/agentsky-meetings/SKILL.md +2 -2
  3. package/dist/{chunk-7DFFA6GA.js → chunk-BIWRJ65N.js} +1 -1
  4. package/dist/{chunk-WSQZHRE4.js → chunk-C3RW65GZ.js} +2 -2
  5. package/dist/{chunk-WLTOVOTW.js → chunk-DAVMU66H.js} +1 -1
  6. package/dist/{chunk-TPDNO2LM.js → chunk-FDR6JOIJ.js} +53 -16
  7. package/dist/{chunk-UHEJFBZJ.js → chunk-IZCS7FH3.js} +5 -5
  8. package/dist/{chunk-OBRH43HE.js → chunk-LMYRAGDR.js} +10 -5
  9. package/dist/chunk-MSEGJ7V5.js +214 -0
  10. package/dist/{chunk-YYDO5WB5.js → chunk-OJ5ERABF.js} +1 -1
  11. package/dist/{chunk-OYSSK6GS.js → chunk-SJIBWHJU.js} +229 -19
  12. package/dist/{chunk-AM6GOGA6.js → chunk-W24YSGH4.js} +368 -73
  13. package/dist/{chunk-EO32DG3Z.js → chunk-Y7JBA7AC.js} +21 -19
  14. package/dist/{chunk-MXIAK52Z.js → chunk-YUZWSDVE.js} +16 -177
  15. package/dist/{compute-OZ4TQBKO.js → compute-FAXL7DAK.js} +2 -2
  16. package/dist/compute-report-XQJSIK6B.js +39 -0
  17. package/dist/index.js +1324 -862
  18. package/dist/{local-skills-E45ZCYGY.js → local-skills-DRZH2R3Q.js} +3 -3
  19. package/dist/{local-skills-run-3CCDHJ6Q.js → local-skills-run-MH2TI2UC.js} +11 -11
  20. package/dist/mcp-serve-JJD6JGYS.js +16 -0
  21. package/dist/{trace-IRBLGOPZ.js → trace-RMYKGACV.js} +3 -3
  22. package/dist/{trace-exclusions-SMBZES3R.js → trace-exclusions-JEGMUPWQ.js} +2 -2
  23. package/dist/{trace-library-CRCV5JDF.js → trace-library-QLCECTIS.js} +10 -8
  24. package/package.json +2 -2
  25. package/dist/compute-report-SGDLKR22.js +0 -34
  26. package/dist/mcp-serve-DXL7IMSU.js +0 -103
@@ -10,7 +10,7 @@
10
10
  "interface": {
11
11
  "displayName": "Meetings",
12
12
  "shortDescription": "Notes for every call",
13
- "longDescription": "Meetings notices a call in WeChat, Tencent Meeting, Zoom, Lark, Feishu, Teams, Chrome or Safari, records both sides and transcribes it on your Mac. Each call becomes one note with a summary and action items, named from your Google or Outlook calendar or your Mac's own Calendar (where a Lark calendar can be synced) and shared with your workspace as a document, where the workspace's other plugins can pick it up. For meetings you take elsewhere, a recorder can join Zoom, Meet and Teams as “AgentSky Notetaker”. In Zoom it also records the call window, what you share and what you do in it, kept closed at the end of the note; in Lark and Feishu it records the meeting window, not yet what you share. Each recording is deleted from your Mac once its call is transcribed, unless you keep recordings for 30 days; notes are kept. The menu bar shows ● Notes while a call is recorded.",
13
+ "longDescription": "Meetings notices a call in WeChat, Tencent Meeting, Zoom, Lark, Feishu, Teams, a Slack huddle, Chrome or Safari, records both sides and transcribes it on your Mac. Each call becomes one note with a summary and action items, named from your Google or Outlook calendar or your Mac's own Calendar (where a Lark calendar can be synced) and shared with your workspace as a document, where the workspace's other plugins can pick it up. For meetings you take elsewhere, a recorder can join Zoom, Meet and Teams as “AgentSky Notetaker”. In Zoom it also records the call window, what you share and what you do in it, kept closed at the end of the note; in Lark and Feishu it records the meeting window, not yet what you share. Each recording is deleted from your Mac once its call is transcribed, unless you keep recordings for 30 days; notes are kept. The menu bar shows ● Notes while a call is recorded.",
14
14
  "developerName": "AgentSky",
15
15
  "category": "Meetings & calls",
16
16
  "capabilities": [],
@@ -5,7 +5,7 @@ description: "AI meeting notes for every call you take on your Mac, from WeChat
5
5
 
6
6
  # Meetings (AgentSky)
7
7
 
8
- Meetings notices a call in WeChat, Tencent Meeting, Zoom, Lark, Feishu, Teams, Chrome or Safari, records both sides and transcribes it on your Mac. Each call becomes one note with a summary and action items, named from your Google or Outlook calendar or your Mac's own Calendar (where a Lark calendar can be synced) and shared with your workspace as a document, where the workspace's other plugins can pick it up. For meetings you take elsewhere, a recorder can join Zoom, Meet and Teams as “AgentSky Notetaker”. In Zoom it also records the call window, what you share and what you do in it, kept closed at the end of the note; in Lark and Feishu it records the meeting window, not yet what you share. Each recording is deleted from your Mac once its call is transcribed, unless you keep recordings for 30 days; notes are kept. The menu bar shows ● Notes while a call is recorded.
8
+ Meetings notices a call in WeChat, Tencent Meeting, Zoom, Lark, Feishu, Teams, a Slack huddle, Chrome or Safari, records both sides and transcribes it on your Mac. Each call becomes one note with a summary and action items, named from your Google or Outlook calendar or your Mac's own Calendar (where a Lark calendar can be synced) and shared with your workspace as a document, where the workspace's other plugins can pick it up. For meetings you take elsewhere, a recorder can join Zoom, Meet and Teams as “AgentSky Notetaker”. In Zoom it also records the call window, what you share and what you do in it, kept closed at the end of the note; in Lark and Feishu it records the meeting window, not yet what you share. Each recording is deleted from your Mac once its call is transcribed, unless you keep recordings for 30 days; notes are kept. The menu bar shows ● Notes while a call is recorded.
9
9
 
10
10
  ## Use it
11
11
 
@@ -16,7 +16,7 @@ Meetings notices a call in WeChat, Tencent Meeting, Zoom, Lark, Feishu, Teams, C
16
16
  - `name_call_note` records who a call was with when the note could not tell.
17
17
  - `publish_call_note` shares it as the workspace's Library document; `run_call_follow_up` runs the person's chosen follow-up agent on it.
18
18
  - Delete a note (`delete_call_note`) only when the person asks for it: it cannot be undone.
19
- - For meetings away from your Mac, a recorder can join the video meetings on the person's calendars. Read it with `read_meeting_auto_join` or `sky meetings auto-join`. It records video, audio and a transcript, everyone in the call sees it and is told in the chat, and the workspace pays for each recording, so tell the person this and have their go-ahead before `set_meeting_auto_join`. `cancel_meeting_recorder` withdraws one recorder.
19
+ - For meetings away from your Mac, a recorder can join the video meetings on the person's calendars. Read it with `read_meeting_auto_join` or `sky meetings auto-join`. It records video, audio and a transcript, everyone in the call sees it and is told in the chat, and the workspace pays for each recording, so tell the person this and have their go-ahead before `set_meeting_auto_join`. `cancel_meeting_recorder` withdraws one recorder. To start a video meeting now or at a time, use `create_meeting` (or `sky meetings start`): it creates a Zoom link anyone can start, invites people by email from the person's calendar and records it for a meeting note unless `notetaker` is false; pass `session_id` so the note comes back to this chat, and tell the person the invitees get an email and the meeting is recorded.
20
20
 
21
21
  ## When a call fails
22
22
 
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var CLI_VERSION = "3.45.0";
2
+ var CLI_VERSION = "3.47.1";
3
3
  var USER_AGENT = `sky-cli/${CLI_VERSION} (${process.platform}; node/${process.versions.node})`;
4
4
 
5
5
  export {
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  SKILL_MARKER,
3
3
  SKILL_NAME
4
- } from "./chunk-OBRH43HE.js";
4
+ } from "./chunk-LMYRAGDR.js";
5
5
  import {
6
6
  CLI_VERSION
7
- } from "./chunk-7DFFA6GA.js";
7
+ } from "./chunk-BIWRJ65N.js";
8
8
  import {
9
9
  configPath
10
10
  } from "./chunk-XHZJG3QT.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  USER_AGENT
3
- } from "./chunk-7DFFA6GA.js";
3
+ } from "./chunk-BIWRJ65N.js";
4
4
  import {
5
5
  apiBase,
6
6
  apiToken,
@@ -1,13 +1,12 @@
1
- import {
2
- lastUploads,
3
- loadSyncConfig
4
- } from "./chunk-EO32DG3Z.js";
5
1
  import {
6
2
  CAPTURE_HOOK_ARGS,
7
3
  SetupJournal,
8
- isCaptureCommand,
9
- workspaceSlug
10
- } from "./chunk-MXIAK52Z.js";
4
+ isCaptureCommand
5
+ } from "./chunk-YUZWSDVE.js";
6
+ import {
7
+ localAgentKey,
8
+ shortToolCount
9
+ } from "./chunk-MSEGJ7V5.js";
11
10
  import {
12
11
  cachedSettingsBlock,
13
12
  detectClaudeApp,
@@ -23,19 +22,24 @@ import {
23
22
  renderSettingsBlock,
24
23
  settingsBlockState,
25
24
  systemCommandRunner,
25
+ workspaceSlug,
26
26
  writeSettingsBlocks
27
- } from "./chunk-OYSSK6GS.js";
27
+ } from "./chunk-SJIBWHJU.js";
28
+ import {
29
+ lastUploads,
30
+ loadSyncConfig
31
+ } from "./chunk-Y7JBA7AC.js";
28
32
  import {
29
33
  ApiError,
30
34
  api
31
- } from "./chunk-WLTOVOTW.js";
35
+ } from "./chunk-DAVMU66H.js";
32
36
  import {
33
37
  installSkill,
34
38
  skillState
35
- } from "./chunk-OBRH43HE.js";
39
+ } from "./chunk-LMYRAGDR.js";
36
40
  import {
37
41
  CLI_VERSION
38
- } from "./chunk-7DFFA6GA.js";
42
+ } from "./chunk-BIWRJ65N.js";
39
43
  import {
40
44
  apiBase,
41
45
  apiToken,
@@ -1915,7 +1919,7 @@ ${raw}` : `${line}
1915
1919
  return { trigger: "codex_notify", outcome: "installed", path };
1916
1920
  }
1917
1921
  async function installSchedule(opts) {
1918
- const lib = await import("./trace-library-CRCV5JDF.js");
1922
+ const lib = await import("./trace-library-QLCECTIS.js");
1919
1923
  if ((opts.platform ?? process.platform) !== "darwin") {
1920
1924
  return { trigger: "schedule", outcome: "skipped", detail: "the 15-minute sweep is macOS only; on Linux add `*/15 * * * * sky trace sync --quiet` to your crontab. The hooks still capture each session" };
1921
1925
  }
@@ -1938,12 +1942,17 @@ async function installSchedule(opts) {
1938
1942
  return { trigger: "schedule", outcome: "installed", path };
1939
1943
  }
1940
1944
  async function installCapture(opts) {
1941
- const lib = await import("./trace-library-CRCV5JDF.js");
1945
+ const lib = await import("./trace-library-QLCECTIS.js");
1942
1946
  const config = lib.loadSyncConfig();
1943
1947
  if (!config.enabled && config.enabledAt) return { sync: "off", triggers: [] };
1944
1948
  const configFile = lib.syncConfigPath();
1945
1949
  if (!opts.dryRun) {
1946
- for (const name of ["trace-sync-state.json", "trace-pending", "trace-sync.lock"]) opts.journal.own(join2(lib.syncDir(), name));
1950
+ const madeBySetup = opts.journal.created(configFile);
1951
+ for (const name of lib.SYNC_STATE_NAMES) {
1952
+ const path = join2(lib.syncDir(), name);
1953
+ if (madeBySetup) opts.journal.adopt(path);
1954
+ else opts.journal.own(path);
1955
+ }
1947
1956
  if (!config.enabled || !config.fallback && !config.rules.length) {
1948
1957
  opts.journal.track(configFile, ["sync_config"]);
1949
1958
  lib.saveSyncConfig({ ...config, enabled: true, enabledAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(), fallback: config.fallback ?? opts.workspace });
@@ -1965,12 +1974,17 @@ var CAPTURED = ["claude_code", "codex"];
1965
1974
  function computerPath() {
1966
1975
  return join3(dirname2(configPath()), "computer.json");
1967
1976
  }
1968
- function machineKey(journal) {
1977
+ function savedMachineKey() {
1969
1978
  try {
1970
1979
  const saved = JSON.parse(readFileSync3(computerPath(), "utf8")).id;
1971
1980
  if (typeof saved === "string" && /^[A-Za-z0-9_-]{8,64}$/.test(saved)) return saved;
1972
1981
  } catch {
1973
1982
  }
1983
+ return null;
1984
+ }
1985
+ function machineKey(journal) {
1986
+ const saved = savedMachineKey();
1987
+ if (saved) return saved;
1974
1988
  const id = randomBytes(12).toString("hex");
1975
1989
  journal?.own(computerPath());
1976
1990
  mkdirSync2(dirname2(computerPath()), { recursive: true });
@@ -2045,13 +2059,22 @@ async function repairComputer(opts) {
2045
2059
  const runner = opts.runner ?? systemCommandRunner();
2046
2060
  const { agents, clients } = computerClients(opts.platform);
2047
2061
  const engines = [];
2062
+ let toolless;
2048
2063
  for (const client of clients) {
2049
2064
  const mark = pluginsMark(client);
2050
2065
  if (mark === "current") continue;
2066
+ toolless ??= await shortToolCount(token) === 0;
2067
+ if (toolless) break;
2051
2068
  const path = mcpConfigPath(client);
2052
2069
  const setUpBefore = opts.journal.tracks(path);
2053
2070
  opts.journal.track(path, [MCP_ENTRY[client.id]]);
2054
- const registered = registerMcpServer(client, { token, mcpUrl: mcpUrlFor(apiBase(), "short"), sky: opts.sky }, runner);
2071
+ let key;
2072
+ try {
2073
+ key = client.id === "claude_app" ? "" : await (opts.agentKey ?? localAgentKey)(client.id);
2074
+ } catch {
2075
+ continue;
2076
+ }
2077
+ const registered = registerMcpServer(client, { token: key, mcpUrl: mcpUrlFor(apiBase(), "short"), sky: opts.sky }, runner);
2055
2078
  if (registered.outcome === "registered") engines.push({ id: client.id, what: mark === "missing" && !setUpBefore ? "AgentSky added" : "AgentSky registration put back" });
2056
2079
  }
2057
2080
  for (const agent of agents) {
@@ -2084,6 +2107,18 @@ async function reportComputer(opts) {
2084
2107
  await api("PUT", path, computerReport(repaired, opts.platform));
2085
2108
  return { repaired };
2086
2109
  }
2110
+ async function forgetComputer() {
2111
+ const key = savedMachineKey();
2112
+ if (!key) return null;
2113
+ if (!apiToken()) return { outcome: "failed", detail: "not signed in; remove it under Settings \u203A Compute" };
2114
+ try {
2115
+ const answer = await api("DELETE", `/compute/machines/${encodeURIComponent(key)}`);
2116
+ return { outcome: answer.removed === false ? "not_listed" : "removed" };
2117
+ } catch (error) {
2118
+ if (error instanceof ApiError && error.status === 404) return { outcome: "not_listed" };
2119
+ return { outcome: "failed", detail: `${error instanceof Error ? error.message : String(error)}; remove it under Settings \u203A Compute` };
2120
+ }
2121
+ }
2087
2122
  function describeRepair(repair) {
2088
2123
  return `AgentSky repaired this computer: ${repair.engines.map((engine) => `${engine.id} (${engine.what})`).join(", ") || "everything was already current"}.`;
2089
2124
  }
@@ -2113,12 +2148,14 @@ export {
2113
2148
  skyCommand,
2114
2149
  installCapture,
2115
2150
  MCP_ENTRY,
2151
+ savedMachineKey,
2116
2152
  machineKey,
2117
2153
  computerClients,
2118
2154
  engineReports,
2119
2155
  computerReport,
2120
2156
  repairComputer,
2121
2157
  reportComputer,
2158
+ forgetComputer,
2122
2159
  describeRepair,
2123
2160
  upkeepComputer
2124
2161
  };
@@ -1,13 +1,13 @@
1
- import {
2
- TRACE_CONTENT_SCOPES,
3
- redactTraceText
4
- } from "./chunk-AM6GOGA6.js";
5
1
  import {
6
2
  USER_AGENT
7
- } from "./chunk-7DFFA6GA.js";
3
+ } from "./chunk-BIWRJ65N.js";
8
4
  import {
9
5
  configPath
10
6
  } from "./chunk-XHZJG3QT.js";
7
+ import {
8
+ TRACE_CONTENT_SCOPES,
9
+ redactTraceText
10
+ } from "./chunk-W24YSGH4.js";
11
11
 
12
12
  // src/trace.ts
13
13
  import { randomBytes } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CLI_VERSION
3
- } from "./chunk-7DFFA6GA.js";
3
+ } from "./chunk-BIWRJ65N.js";
4
4
 
5
5
  // src/skill.ts
6
6
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -91,6 +91,11 @@ account default workspace. Never ask. Pass the chosen slug as \`workspace\` on
91
91
  every MCP tool that accepts it, or as \`--workspace <slug>\` on sky commands.
92
92
  Details: \`${REFERENCES_DIR}/workspaces.md\` in this skill's folder.
93
93
 
94
+ ## Work handed to you
95
+
96
+ At the start of work, call \`list_asks\` for anything handed to you, and answer
97
+ each one you can with \`answer_ask\`.
98
+
94
99
  ## When to hire
95
100
 
96
101
  - When the person names an agent (\`@handle\`) or an engine, or asks another agent
@@ -178,9 +183,9 @@ it, and name its path in the brief.
178
183
  take a minute.
179
184
  - Run independent agents at the same time: start them all, then read each.
180
185
  - To steer or answer an agent, \`send_message\` once its turn is finished.
181
- - If \`get_session_status\` shows a request waiting on the person (a question, an approval,
186
+ - If \`list_asks\` shows a request waiting on the person (a question, an approval,
182
187
  or an app to connect with its link), show it to them and pass their answer with
183
- \`answer_request\`. Never approve spending or access on their behalf.
188
+ \`answer_ask\`. Never approve spending or access on their behalf.
184
189
  - An agent that finishes its first turn with no reply did not start properly:
185
190
  \`stop_session\` it and hire again, or do that part yourself.
186
191
 
@@ -456,8 +461,8 @@ the agent's questions, approvals, and apps to connect.
456
461
  \`POST /v1/sessions/{id}/questions/{request id}/answer\` with \`{"text": ...}\` or
457
462
  \`{"option_id": ...}\` answers one. Pass a customer's answer on only after
458
463
  your application has checked who they are. By hand: \`sky session status <id>\` and
459
- \`sky session answer <id> <request> --text "..."\` (MCP: \`get_session_status\`,
460
- \`answer_request\`).
464
+ \`sky session answer <id> <request> --text "..."\` (MCP: \`list_asks\`,
465
+ \`answer_ask\`).
461
466
 
462
467
  ## 7. What the application keeps
463
468
 
@@ -0,0 +1,214 @@
1
+ import {
2
+ cachedSettingsBlock,
3
+ mcpUrlFor,
4
+ workspaceSlug
5
+ } from "./chunk-SJIBWHJU.js";
6
+ import {
7
+ api
8
+ } from "./chunk-DAVMU66H.js";
9
+ import {
10
+ USER_AGENT
11
+ } from "./chunk-BIWRJ65N.js";
12
+ import {
13
+ apiBase,
14
+ apiToken,
15
+ configPath,
16
+ loadConfig
17
+ } from "./chunk-XHZJG3QT.js";
18
+
19
+ // src/mcp-serve.ts
20
+ import { createInterface } from "readline";
21
+
22
+ // src/local-agent-keys.ts
23
+ import { createHash } from "crypto";
24
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
25
+ import { hostname } from "os";
26
+ import { dirname, join } from "path";
27
+ var SHELL_AGENT = "shell";
28
+ function agentKeysPath() {
29
+ return join(dirname(configPath()), "agent-keys.json");
30
+ }
31
+ function readKeys() {
32
+ try {
33
+ const parsed = JSON.parse(readFileSync(agentKeysPath(), "utf8"));
34
+ if (parsed?.version === 1 && parsed.keys && typeof parsed.keys === "object") return parsed;
35
+ } catch {
36
+ }
37
+ return { version: 1, keys: {} };
38
+ }
39
+ function writeKeys(file) {
40
+ const path = agentKeysPath();
41
+ mkdirSync(dirname(path), { recursive: true });
42
+ writeFileSync(path, `${JSON.stringify(file, null, 2)}
43
+ `, { mode: 384 });
44
+ }
45
+ function slot(agent, workspace, account) {
46
+ return createHash("sha256").update([apiBase(), account, workspace, agent].join("\n")).digest("hex").slice(0, 32);
47
+ }
48
+ var AGENT_NAMES = {
49
+ claude_code: "Claude Code",
50
+ codex: "Codex",
51
+ cursor: "Cursor",
52
+ grok: "Grok",
53
+ hermes: "Hermes",
54
+ claude_app: "Claude app",
55
+ [SHELL_AGENT]: "new shells"
56
+ };
57
+ function agentKeyName(agent, host = hostname()) {
58
+ return `${AGENT_NAMES[agent] ?? agent} on ${host}`.slice(0, 60);
59
+ }
60
+ var INTERACTIVE_CLIENT_AGENTS = ["claude_code", "codex"];
61
+ var UNATTENDED_ENV = ["SKY_API_TOKEN", "E2B_SANDBOX", "CI", "AGENTSKY_HARNESS_TOKEN", "SKY_WORKER_TOKEN", "AGENTSKY_POD_ID", "AGENTSKY_SESSION_ID"];
62
+ function wantsInteractiveClientKey(agent, at) {
63
+ return INTERACTIVE_CLIENT_AGENTS.includes(agent) && at.stdinTTY && at.stdoutTTY && !at.unattended && !at.agentKeyOnly;
64
+ }
65
+ function runsUnattended(env = process.env) {
66
+ return UNATTENDED_ENV.some((name) => Boolean(env[name]?.trim()));
67
+ }
68
+ async function localAgentKey(agent, deps = {}, options = {}) {
69
+ if (!apiToken()) throw new Error("sky is not signed in on this computer: run `sky auth login`");
70
+ const workspace = await (deps.workspace ?? (() => workspaceSlug()))();
71
+ const account = (deps.account ?? (() => loadConfig().email ?? "signed-in"))();
72
+ const file = readKeys();
73
+ const key = slot(options.interactiveClient ? `${agent}:interactive_client` : agent, workspace, account);
74
+ const stored = file.keys[key];
75
+ if (stored?.secret) return stored.secret;
76
+ const mint = deps.mint ?? ((body) => api("POST", "/api_keys", body));
77
+ const made = await mint({ name: agentKeyName(agent), scopes: ["read", "write"], universe: workspace, access: "agent", agent, ...options.interactiveClient ? { interactive_client: true } : {} });
78
+ file.keys[key] = { id: made.api_key.id, secret: made.secret, workspace };
79
+ writeKeys(file);
80
+ return made.secret;
81
+ }
82
+ async function revokeLocalAgentKeys(revoke = (id) => api("POST", `/api_keys/${encodeURIComponent(id)}/revoke`)) {
83
+ const file = readKeys();
84
+ if (!Object.keys(file.keys).length) return { revoked: 0, left: 0 };
85
+ let revoked = 0;
86
+ const left = {};
87
+ for (const [key, stored] of Object.entries(file.keys)) {
88
+ try {
89
+ await revoke(stored.id);
90
+ revoked++;
91
+ } catch {
92
+ left[key] = stored;
93
+ }
94
+ }
95
+ if (Object.keys(left).length) writeKeys({ version: 1, keys: left });
96
+ else rmSync(agentKeysPath(), { force: true });
97
+ return { revoked, left: Object.keys(left).length };
98
+ }
99
+
100
+ // src/mcp-serve.ts
101
+ var defaults = () => ({
102
+ fetch,
103
+ token: async () => apiToken() ? localAgentKey("claude_app") : void 0,
104
+ url: () => mcpUrlFor(apiBase(), "short"),
105
+ settings: cachedSettingsBlock,
106
+ write: (line) => process.stdout.write(`${line}
107
+ `)
108
+ });
109
+ function failure(id, message) {
110
+ return JSON.stringify({ jsonrpc: "2.0", id: id ?? null, error: { code: -32e3, message } });
111
+ }
112
+ function answersIn(body, type) {
113
+ const texts = type?.includes("text/event-stream") ? body.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).filter(Boolean) : body.trim() ? [body] : [];
114
+ return texts.flatMap((text) => {
115
+ const parsed = JSON.parse(text);
116
+ return Array.isArray(parsed) ? parsed : [parsed];
117
+ });
118
+ }
119
+ async function shortToolCount(token, url = mcpUrlFor(apiBase(), "short"), fetchImpl = fetch) {
120
+ try {
121
+ const response = await fetchImpl(url, {
122
+ method: "POST",
123
+ headers: { "user-agent": USER_AGENT, authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json, text/event-stream" },
124
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })
125
+ });
126
+ if (!response.ok) return null;
127
+ const tools = answersIn(await response.text(), response.headers.get("content-type")).find((answer) => answer.id === 1)?.result?.tools;
128
+ return Array.isArray(tools) ? tools.length : null;
129
+ } catch {
130
+ return null;
131
+ }
132
+ }
133
+ async function forwardLine(line, deps = defaults(), protocol = {}) {
134
+ let message;
135
+ try {
136
+ message = JSON.parse(line);
137
+ } catch {
138
+ return deps.write(failure(null, "not a JSON-RPC message"));
139
+ }
140
+ const expectsAnswer = message.id !== void 0 && message.id !== null;
141
+ let token;
142
+ try {
143
+ token = await deps.token();
144
+ } catch (error) {
145
+ if (expectsAnswer) deps.write(failure(message.id, `sky could not get this app a key of its own: ${(error instanceof Error ? error.message : String(error)).split("\n")[0]}`));
146
+ return;
147
+ }
148
+ if (!token) {
149
+ if (expectsAnswer) deps.write(failure(message.id, "sky is not signed in on this computer: run `sky auth login`"));
150
+ return;
151
+ }
152
+ let response;
153
+ try {
154
+ response = await deps.fetch(deps.url(), {
155
+ method: "POST",
156
+ headers: {
157
+ "user-agent": USER_AGENT,
158
+ authorization: `Bearer ${token}`,
159
+ "content-type": "application/json",
160
+ accept: "application/json, text/event-stream",
161
+ ...protocol.version ? { "mcp-protocol-version": protocol.version } : {}
162
+ },
163
+ body: line
164
+ });
165
+ } catch (error) {
166
+ if (expectsAnswer) deps.write(failure(message.id, `AgentSky could not be reached: ${error instanceof Error ? error.message : String(error)}`));
167
+ return;
168
+ }
169
+ const body = await response.text();
170
+ if (!response.ok) {
171
+ if (expectsAnswer) deps.write(failure(message.id, `AgentSky answered ${response.status}`));
172
+ return;
173
+ }
174
+ let answers;
175
+ try {
176
+ answers = answersIn(body, response.headers.get("content-type"));
177
+ } catch {
178
+ if (expectsAnswer) deps.write(failure(message.id, "AgentSky's answer was not JSON"));
179
+ return;
180
+ }
181
+ for (const answer of answers) {
182
+ if (message.method === "initialize" && answer.result) {
183
+ const version = answer.result.protocolVersion;
184
+ if (typeof version === "string") protocol.version = version;
185
+ const settings = deps.settings();
186
+ if (settings) answer.result.instructions = `${answer.result.instructions ?? ""}
187
+
188
+ ${settings}`.trim();
189
+ }
190
+ deps.write(JSON.stringify(answer));
191
+ }
192
+ }
193
+ async function serveMcp(deps = defaults()) {
194
+ const protocol = {};
195
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
196
+ let queue = Promise.resolve();
197
+ for await (const line of lines) {
198
+ if (!line.trim()) continue;
199
+ queue = queue.then(() => forwardLine(line, deps, protocol));
200
+ }
201
+ await queue;
202
+ }
203
+
204
+ export {
205
+ SHELL_AGENT,
206
+ agentKeysPath,
207
+ wantsInteractiveClientKey,
208
+ runsUnattended,
209
+ localAgentKey,
210
+ revokeLocalAgentKeys,
211
+ shortToolCount,
212
+ forwardLine,
213
+ serveMcp
214
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UnsafeImportError,
3
3
  redactLine
4
- } from "./chunk-AM6GOGA6.js";
4
+ } from "./chunk-W24YSGH4.js";
5
5
 
6
6
  // src/trace-exclusions.ts
7
7
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";