@agentsky/sky 3.42.0 → 3.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ALJRHTMX.js → chunk-44XF4EGE.js} +2 -108
- package/dist/chunk-4A4PDUT5.js +8 -0
- package/dist/{trace-ZZLFGVWA.js → chunk-4MVM65ET.js} +23 -21
- package/dist/chunk-AB7SUDX4.js +413 -0
- package/dist/{chunk-YY2ZSZDH.js → chunk-BIZJ4VZL.js} +8 -10
- package/dist/chunk-J3KIEZXM.js +761 -0
- package/dist/chunk-OKNWK75U.js +745 -0
- package/dist/chunk-UJ7IXSJX.js +404 -0
- package/dist/index.js +2732 -2717
- package/dist/local-skills-AVLHV36B.js +27 -0
- package/dist/local-skills-run-UJK4ZO4P.js +49 -0
- package/dist/trace-H3FVIFE3.js +54 -0
- package/dist/trace-exclusions-MYECULMA.js +20 -0
- package/dist/{trace-library-536NQQJJ.js → trace-library-XLBJHI3I.js} +576 -413
- package/package.json +2 -1
|
@@ -0,0 +1,761 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLI_VERSION
|
|
3
|
+
} from "./chunk-4A4PDUT5.js";
|
|
4
|
+
import {
|
|
5
|
+
configPath
|
|
6
|
+
} from "./chunk-XHZJG3QT.js";
|
|
7
|
+
|
|
8
|
+
// src/local-skills.ts
|
|
9
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
10
|
+
import { dirname, join as join2, resolve, sep } from "path";
|
|
11
|
+
|
|
12
|
+
// src/skill.ts
|
|
13
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
|
|
16
|
+
// src/catalog-file.ts
|
|
17
|
+
var CATALOG_FILE = "catalog.md";
|
|
18
|
+
var CATEGORY_ORDER = ["websites", "content", "video", "code", "research", "general"];
|
|
19
|
+
function categoryOf(agent) {
|
|
20
|
+
return CATEGORY_ORDER.find((category) => agent.categories.includes(category)) ?? agent.categories[0] ?? "general";
|
|
21
|
+
}
|
|
22
|
+
function describe(value) {
|
|
23
|
+
const parts = Object.entries(value).filter(([, item]) => item !== null && item !== void 0 && item !== false && item !== "").map(([key, item]) => item === true ? key : `${key}: ${typeof item === "string" ? item : JSON.stringify(item)}`);
|
|
24
|
+
return parts.length ? parts.join(", ") : null;
|
|
25
|
+
}
|
|
26
|
+
function entry(agent) {
|
|
27
|
+
const engine = agent.engine_type ? ` \xB7 engine ${agent.engine_type}` : "";
|
|
28
|
+
const lines = [`### @${agent.handle} \u2014 ${agent.name}${engine}`, "", agent.tagline];
|
|
29
|
+
if (agent.does.length) lines.push("", `Does: ${agent.does.join("; ")}`);
|
|
30
|
+
if (agent.does_not.length) lines.push(`Does not: ${agent.does_not.join("; ")}`);
|
|
31
|
+
const { mcp_servers: mcpServers, ...rest } = agent.requirements;
|
|
32
|
+
if (typeof mcpServers === "boolean") lines.push(mcpServers ? "Can use MCP servers." : "Cannot use MCP servers.");
|
|
33
|
+
const details = describe(rest);
|
|
34
|
+
if (details) lines.push(`Details: ${details}`);
|
|
35
|
+
const pricing = describe(agent.pricing);
|
|
36
|
+
if (pricing) lines.push(`Pricing: ${pricing}`);
|
|
37
|
+
return lines.join("\n");
|
|
38
|
+
}
|
|
39
|
+
function renderCatalog(agents, generatedAt) {
|
|
40
|
+
const header = [
|
|
41
|
+
"# AgentSky agent catalog",
|
|
42
|
+
"",
|
|
43
|
+
`Every agent you can hire, as of ${generatedAt.toISOString()}. Start one with \`start_session\` and its handle, written with the @.`,
|
|
44
|
+
"Run `npx @agentsky/sky setup` again to refresh this file; `search_catalog` always has the current list."
|
|
45
|
+
];
|
|
46
|
+
if (!agents.length) return [...header, "", "The catalog was empty when this file was written. Use `search_catalog`.", ""].join("\n");
|
|
47
|
+
const own = agents.filter((agent) => agent.visibility === "workspace");
|
|
48
|
+
const shared = agents.filter((agent) => agent.visibility !== "workspace");
|
|
49
|
+
const sections = [];
|
|
50
|
+
if (own.length) sections.push(["## Your workspace's agents", ...own.map(entry)].join("\n\n"));
|
|
51
|
+
const groups = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const agent of shared) groups.set(categoryOf(agent), [...groups.get(categoryOf(agent)) ?? [], agent]);
|
|
53
|
+
const ordered = [...groups.keys()].sort((a, b) => {
|
|
54
|
+
const rank = (category) => CATEGORY_ORDER.includes(category) ? CATEGORY_ORDER.indexOf(category) : CATEGORY_ORDER.length;
|
|
55
|
+
return rank(a) - rank(b) || a.localeCompare(b);
|
|
56
|
+
});
|
|
57
|
+
for (const category of ordered) {
|
|
58
|
+
const title = category.charAt(0).toUpperCase() + category.slice(1);
|
|
59
|
+
sections.push([`## ${title}`, ...groups.get(category).map(entry)].join("\n\n"));
|
|
60
|
+
}
|
|
61
|
+
return [...header, "", sections.join("\n\n"), ""].join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/skill.ts
|
|
65
|
+
var REFERENCES_DIR = "references";
|
|
66
|
+
var SKILL_NAME = "agentsky";
|
|
67
|
+
var SKILL_MARKER = ".agentsky.json";
|
|
68
|
+
function skillDocument() {
|
|
69
|
+
return `---
|
|
70
|
+
name: ${SKILL_NAME}
|
|
71
|
+
description: "Hire cloud agents from the AgentSky catalog (included as ${CATALOG_FILE}) and coordinate them on one task. Use when: the person names an agent by @handle or wants to orchestrate agents; asks another engine (Codex, Claude Code, Gemini, Hermes) to do, test or review part of the work; wants to import, move or continue this conversation in AgentSky or the cloud; wants an agent their own application starts for its customers from a skill they supply; names a workspace; or the work splits into independent parts that can run at the same time. Works through the agentsky MCP server, or the sky command where those tools are missing."
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
# Working with other agents through AgentSky
|
|
75
|
+
|
|
76
|
+
AgentSky runs long-lived agents in the cloud. You can hire them from its
|
|
77
|
+
catalog, give each a part of the work, and collect what they produce. Agents you
|
|
78
|
+
hire for the same piece of work share one task: a shared \`task/\` folder they all
|
|
79
|
+
read and write, listed as one task in the person's AgentSky account. You stay
|
|
80
|
+
responsible for the result.
|
|
81
|
+
|
|
82
|
+
Everything below is a tool of the \`agentsky\` MCP server. If those tools are
|
|
83
|
+
missing in this session, use the \`sky\` commands under "Without the MCP tools"
|
|
84
|
+
at the end; they do the same things, one agent at a time.
|
|
85
|
+
|
|
86
|
+
## Getting access
|
|
87
|
+
|
|
88
|
+
If those tools are missing and \`sky auth whoami\` fails, this computer is not
|
|
89
|
+
signed in yet. Run \`npx -y @agentsky/sky@latest auth login --no-browser\`, give
|
|
90
|
+
the person the URL it prints, and wait: they approve once in their browser and
|
|
91
|
+
the command finishes by itself. Never ask them to paste a key or a password.
|
|
92
|
+
|
|
93
|
+
## Workspace
|
|
94
|
+
|
|
95
|
+
Use the workspace the person named. If they named none, check the git root for
|
|
96
|
+
\`.agentsky.json\` \u2014 if it has a \`"workspace"\` key, use that. Otherwise use the
|
|
97
|
+
account default workspace. Never ask. Pass the chosen slug as \`workspace\` on
|
|
98
|
+
every MCP tool that accepts it, or as \`--workspace <slug>\` on sky commands.
|
|
99
|
+
Details: \`${REFERENCES_DIR}/workspaces.md\` in this skill's folder.
|
|
100
|
+
|
|
101
|
+
## When to hire
|
|
102
|
+
|
|
103
|
+
- When the person names an agent (\`@handle\`) or an engine, or asks another agent
|
|
104
|
+
to test, review or do part of the work, do that. Do not substitute another one
|
|
105
|
+
silently.
|
|
106
|
+
- Otherwise hire for work another agent is better suited to than you are, for
|
|
107
|
+
independent parts that can run at the same time, or for work that should keep
|
|
108
|
+
going after this conversation ends.
|
|
109
|
+
- Do the work yourself when it is small, when it depends on what you already have
|
|
110
|
+
in front of you, or when explaining it would take as long as doing it.
|
|
111
|
+
|
|
112
|
+
## Local first, cloud when it is not here, never a stand-in
|
|
113
|
+
|
|
114
|
+
- When the person names an engine that is installed and signed in on this
|
|
115
|
+
computer, run it here: it costs them nothing on AgentSky.
|
|
116
|
+
- When it is not installed here, start that same engine in the cloud: its handle
|
|
117
|
+
(\`@codex\`, \`@claude_code\`, \u2026) with \`start_session\` and a \`budget_cents\`, and say so
|
|
118
|
+
in one line ("Codex is not installed on this Mac, so it ran in the cloud").
|
|
119
|
+
Do not pick another engine instead.
|
|
120
|
+
- Every refused tool call carries a stable error \`code\` (in the error text and in
|
|
121
|
+
\`structuredContent.error\`) and, when there is one, a \`next_step\`. Read the code:
|
|
122
|
+
\`insufficient_credits\`, \`workspace_wallet_empty\` and \`payment_setup_required\` mean
|
|
123
|
+
the account cannot pay; \`budget_reached\` means that session's cap is spent.
|
|
124
|
+
Stop that piece of work and tell the person what was refused and what unblocks
|
|
125
|
+
it. When the refusal has \`tell_the_person\`, say that sentence as written: it holds
|
|
126
|
+
the link where they add credit. Retry the same request once they say it is done.
|
|
127
|
+
For a spent budget, name a larger \`budget_cents\`. Then offer the engines that are installed here as the free alternative. Never hire a
|
|
128
|
+
cheaper or different agent to get around a refusal.
|
|
129
|
+
- \`get_usage\` shows the balance; check it before starting several cloud sessions
|
|
130
|
+
at once so the person is told once, up front, instead of after the first fails.
|
|
131
|
+
- Anything else the person can do on agentsky.dev or in the Mac app (rename or
|
|
132
|
+
archive a thread, edit a Library file or skill, change an agent's model, invite
|
|
133
|
+
a member, \u2026) is an API operation: find it with \`search_api\`, read its
|
|
134
|
+
parameters with \`describe_api\`, and run it with \`call_api\`. It acts as the
|
|
135
|
+
person with their own key, so make only the change they asked for. Where MCP
|
|
136
|
+
is missing, \`sky api search <words>\` and \`sky api <METHOD> <path>\` do the same.
|
|
137
|
+
|
|
138
|
+
## How to pick
|
|
139
|
+
|
|
140
|
+
Read \`${CATALOG_FILE}\` in this skill's folder. It lists every agent you can hire,
|
|
141
|
+
your own workspace's first, then by category: its \`@handle\`, its engine, what it
|
|
142
|
+
does and does not do, whether it can use MCP servers, and how it is paid. Pick by
|
|
143
|
+
the work, not by the name, and respect what an agent says it does not do.
|
|
144
|
+
|
|
145
|
+
Call \`search_catalog\` (with words for the work, or none to list everything)
|
|
146
|
+
when \`${CATALOG_FILE}\` is missing, when nothing in it fits, or when the person names
|
|
147
|
+
a handle it does not list: the catalog file is a snapshot from when the skill
|
|
148
|
+
was installed. If nothing fits, do the work yourself and say so.
|
|
149
|
+
|
|
150
|
+
## How to brief
|
|
151
|
+
|
|
152
|
+
Start the first agent with \`start_session\`:
|
|
153
|
+
|
|
154
|
+
- \`agent_id\`: the handle, with its \`@\`.
|
|
155
|
+
- \`message\`: the brief.
|
|
156
|
+
- \`title\`: a short name for its part.
|
|
157
|
+
- \`budget_cents\`: the most it may spend, in US cents. Always set one. When it is
|
|
158
|
+
reached the agent pauses instead of spending more.
|
|
159
|
+
- \`idempotency_key\`: a new unique value for this hire. Reuse it only to retry
|
|
160
|
+
the exact same call after a timeout.
|
|
161
|
+
|
|
162
|
+
The agent cannot see this conversation or your files. A brief is one
|
|
163
|
+
self-contained paragraph that says:
|
|
164
|
+
|
|
165
|
+
1. what to produce;
|
|
166
|
+
2. where to write it: a path under \`task/<its part>/\`;
|
|
167
|
+
3. what "done" means;
|
|
168
|
+
4. anything it must not do.
|
|
169
|
+
|
|
170
|
+
Never put a password, key or token in a brief.
|
|
171
|
+
|
|
172
|
+
Its task id is the first session's id. Start every other agent for the same work
|
|
173
|
+
with that \`task_id\`, so it sees the same \`task/\` folder and the person sees one
|
|
174
|
+
task. To hand an agent a file, write it with \`write_session_shared_file\` before you brief
|
|
175
|
+
it, and name its path in the brief.
|
|
176
|
+
|
|
177
|
+
## How to supervise
|
|
178
|
+
|
|
179
|
+
- Call \`read_session\` with the \`session_id\`, \`cursor\` and \`message_id\` that
|
|
180
|
+
\`start_session\` or \`send_message\` returned and \`wait_seconds: 50\`. Call again
|
|
181
|
+
with the returned cursor until \`turn_finished\` is true, and at once whenever
|
|
182
|
+
\`has_more\` is true. The first turn also boots the agent's sandbox, which can
|
|
183
|
+
take a minute.
|
|
184
|
+
- Run independent agents at the same time: start them all, then read each.
|
|
185
|
+
- To steer or answer an agent, \`send_message\` once its turn is finished.
|
|
186
|
+
- If \`get_session_status\` shows a request waiting on the person (a question, an approval,
|
|
187
|
+
or an app to connect with its link), show it to them and pass their answer with
|
|
188
|
+
\`answer_request\`. Never approve spending or access on their behalf.
|
|
189
|
+
- An agent that finishes its first turn with no reply did not start properly:
|
|
190
|
+
\`stop_session\` it and hire again, or do that part yourself.
|
|
191
|
+
|
|
192
|
+
## How to finish
|
|
193
|
+
|
|
194
|
+
1. \`collect_result\` for each agent: its last reply and the files it wrote.
|
|
195
|
+
2. Read the files with \`read_session_shared_file\` and check each one exists and does what
|
|
196
|
+
was asked. An agent saying "done" is not evidence.
|
|
197
|
+
3. Put the pieces together.
|
|
198
|
+
4. If the person should be able to open or share the result, \`publish_artifact\`
|
|
199
|
+
the files; \`share_artifact\` only when they asked for a link. To change a
|
|
200
|
+
published file, \`save_artifact_file\` against the \`base_version\` you read;
|
|
201
|
+
\`update_artifact\` renames one and \`copy_artifact\` copies one version of it.
|
|
202
|
+
\`export_artifact\` hands a result over in any format its \`export_formats\`
|
|
203
|
+
lists, and \`import_artifact\` brings in a file or a public page as a result.
|
|
204
|
+
5. \`stop_session\` every agent you no longer need.
|
|
205
|
+
6. Tell the person what was done, which agent did which part, and what it cost
|
|
206
|
+
(\`get_session_status\` reports the task's cost).
|
|
207
|
+
|
|
208
|
+
## Share an existing Library document
|
|
209
|
+
|
|
210
|
+
Use \`read_library_file_links\` with the document's exact \`ref\` to read its
|
|
211
|
+
current revision, supported access and real available members. The reference
|
|
212
|
+
can name a Drive file (including an uploaded meeting note), task file, memory
|
|
213
|
+
note, skill file, agent user instructions (\`{kind:"agent_prompt",agentId}\`), saved artifact or platform artifact. Only the user-authored AGENTS.md is shared; system instructions and credentials are never included. \`workspace\` names the
|
|
214
|
+
audience workspace, never a storage move or the connection's default.
|
|
215
|
+
For a DesignSystem file, use \`platform_artifact\` with the exact full native
|
|
216
|
+
manifest \`path\`: its actual \`root\` plus an \`editable_files\` path, or the
|
|
217
|
+
native document reader's \`libraryRef\`. Do not guess a folder prefix or use
|
|
218
|
+
an editor's relative transport path. Omitting \`path\` shares the entire
|
|
219
|
+
artifact entry. A token reads only its original file; it cannot select a
|
|
220
|
+
sibling with a query parameter. Editable DesignSystem files save through
|
|
221
|
+
that system's versioned writer, including derived files and republishing.
|
|
222
|
+
\`share_library_file\` changes only the requested workspace/member grants;
|
|
223
|
+
\`publish_library_file\` enables or disables a public view-only link while
|
|
224
|
+
preserving other grants. Both read first and merge against the current
|
|
225
|
+
revision. \`revoke_library_file_links\` needs the explicit revision you reviewed.
|
|
226
|
+
A conflict is an error: read the current state before intentionally retrying.
|
|
227
|
+
These tools send no messages and start no sessions. CLI equivalents are
|
|
228
|
+
\`sky library links show\`, \`share\`, \`publish\` and \`revoke\`; their help
|
|
229
|
+
shows every reference shape. Existing artifact links and version pins keep
|
|
230
|
+
using their existing controls and \`share_artifact\`.
|
|
231
|
+
|
|
232
|
+
When you receive a Library shared/public URL, \`read_shared_library_file\`
|
|
233
|
+
accepts the 43-character token at its end; \`public: true\` chooses the public
|
|
234
|
+
view-only reader. A recipient with a live edit grant can use
|
|
235
|
+
\`save_shared_library_file\` with the opaque source revision from that read
|
|
236
|
+
and exactly one native text/HTML/Office/restore field. Public links have no
|
|
237
|
+
writer. The CLI equivalents are \`sky library links read --token \u2026\`
|
|
238
|
+
(\`--output\` streams original bytes) and \`sky library links save --token \u2026
|
|
239
|
+
--revision \u2026 --file \u2026\`; \`--data\` accepts the other native save fields.
|
|
240
|
+
A 403 is not a saved result; a 409 requires reading current state before an
|
|
241
|
+
intentional retry. This source revision is distinct from the integer revision
|
|
242
|
+
of the sharing settings.
|
|
243
|
+
|
|
244
|
+
## Build an agent that the person's own application runs
|
|
245
|
+
|
|
246
|
+
When the person wants an agent their product starts for its customers, built
|
|
247
|
+
from a skill they supply (for example: a customer uploads a file, an agent
|
|
248
|
+
reviews it, their application acts on the verdict), follow
|
|
249
|
+
\`${REFERENCES_DIR}/focused-agents.md\` in this skill's folder. It covers the
|
|
250
|
+
prerequisites to tell them about first, one locked-down workspace per customer,
|
|
251
|
+
one fresh session per event, and reading the answer as data.
|
|
252
|
+
|
|
253
|
+
## Import this conversation to AgentSky
|
|
254
|
+
|
|
255
|
+
When the person asks to import, move, or continue this conversation in AgentSky
|
|
256
|
+
or the cloud:
|
|
257
|
+
|
|
258
|
+
1. Write a summary JSON file following the schema in \`${REFERENCES_DIR}/import.md\`
|
|
259
|
+
(the only step that needs judgment \u2014 capture the objective, key decisions,
|
|
260
|
+
completed work, and next steps).
|
|
261
|
+
2. Run:
|
|
262
|
+
\`\`\`
|
|
263
|
+
npx -y @agentsky/sky import --current --summary <path-to-summary.json> --yes --json
|
|
264
|
+
\`\`\`
|
|
265
|
+
Add \`--workspace <slug>\` when a workspace was chosen. Do NOT confirm or ask
|
|
266
|
+
before running; the \`--yes --json\` flags suppress prompts.
|
|
267
|
+
3. Report the \`continueUrl\` from the JSON result. That is all.
|
|
268
|
+
|
|
269
|
+
Only stop (non-zero exit) on a size limit, dropped content, or redaction failure.
|
|
270
|
+
|
|
271
|
+
## Without the MCP tools
|
|
272
|
+
|
|
273
|
+
Run \`sky auth whoami\`. If it says you are not logged in, ask the person to run
|
|
274
|
+
\`sky auth login\` and stop there. Never ask them for a token.
|
|
275
|
+
|
|
276
|
+
- Pick: \`sky catalog search <words for the work> --json\`. Each result has a
|
|
277
|
+
\`handle\`, what the agent does, its \`engine_type\`, its categories, how it is
|
|
278
|
+
paid, and what it needs. Run it with no words to see every agent.
|
|
279
|
+
- Brief: \`sky session create @<handle> --title "<short name>" --message "<brief>" --json\`
|
|
280
|
+
prints the new session's \`id\`. To give it a file, add \`--file <path>:/<name>\`:
|
|
281
|
+
the file is in the agent's working directory under that name, read-only, so
|
|
282
|
+
call it by that name in the brief.
|
|
283
|
+
- Collect: \`sky session read <session id> --wait --json\` waits until the agent
|
|
284
|
+
finishes its turn and prints its messages, with \`finished\` true or false. If
|
|
285
|
+
\`finished\` is false the wait timed out: run it again. To correct it, answer it
|
|
286
|
+
or ask for more, \`sky session message <session id> "<text>" --detach\`, then
|
|
287
|
+
read again.
|
|
288
|
+
`;
|
|
289
|
+
}
|
|
290
|
+
function importReferenceDoc() {
|
|
291
|
+
return `# Import this conversation to AgentSky
|
|
292
|
+
|
|
293
|
+
## Summary schema (asteroids.session-summary v1)
|
|
294
|
+
|
|
295
|
+
Write a JSON file with these fields:
|
|
296
|
+
|
|
297
|
+
\`\`\`json
|
|
298
|
+
{
|
|
299
|
+
"format": "asteroids.session-summary",
|
|
300
|
+
"format_version": 1,
|
|
301
|
+
"source_harness": "claude_code",
|
|
302
|
+
"source_harness_version": null,
|
|
303
|
+
"source_session_id": "<the session id, e.g. from CLAUDE_CODE_SESSION_ID>",
|
|
304
|
+
"created_at": "<ISO 8601 timestamp>",
|
|
305
|
+
"summary": "<one paragraph: what this conversation accomplished>",
|
|
306
|
+
"context": {
|
|
307
|
+
"objective": "<what the person ultimately wants>",
|
|
308
|
+
"constraints": ["<must not do X>"],
|
|
309
|
+
"decisions": ["<decided to use Y approach>"],
|
|
310
|
+
"completed": ["<finished task A>"],
|
|
311
|
+
"pending": ["<next: do B>"],
|
|
312
|
+
"verification": ["<how to confirm B is correct>"],
|
|
313
|
+
"blockers": ["<needs access to X>"],
|
|
314
|
+
"artifacts": [{"path": "path/to/file.ts", "description": "what it is"}]
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
\`\`\`
|
|
318
|
+
|
|
319
|
+
Only \`summary\` and \`context\` require judgment. All other fields are fixed values
|
|
320
|
+
or can be omitted (the CLI validates \`format\` and \`format_version\`).
|
|
321
|
+
|
|
322
|
+
## Gaps
|
|
323
|
+
|
|
324
|
+
The import transfers the recorded conversation only. These are NOT transferred:
|
|
325
|
+
- Local files not included in the transcript
|
|
326
|
+
- Runtime state (variables, shell state, running processes)
|
|
327
|
+
- Unrecorded tool outputs or reasoning
|
|
328
|
+
- Login credentials and secrets
|
|
329
|
+
|
|
330
|
+
List known gaps in \`context.blockers\`.
|
|
331
|
+
|
|
332
|
+
## Non-Claude/Codex harnesses
|
|
333
|
+
|
|
334
|
+
For harnesses that do not set \`CLAUDE_CODE_SESSION_ID\` or \`CODEX_THREAD_ID\`:
|
|
335
|
+
use \`--session <id>\` instead of \`--current\`, and set \`source_harness\` to the
|
|
336
|
+
harness name (e.g. \`"hermes"\`, \`"openclaw"\`).
|
|
337
|
+
`;
|
|
338
|
+
}
|
|
339
|
+
function focusedAgentsReferenceDoc() {
|
|
340
|
+
return `# A focused agent your application runs for its customers
|
|
341
|
+
|
|
342
|
+
Use this when the person wants an agent that their own product starts on an
|
|
343
|
+
event (a customer uploads a file, a form is submitted), working from one
|
|
344
|
+
skill they supply, with the result going back to their application.
|
|
345
|
+
|
|
346
|
+
Everything here is the public API (\`https://api.agentsky.dev/v1\`). The
|
|
347
|
+
application's server calls it. The \`sky\` commands and MCP tools named
|
|
348
|
+
alongside do the same things by hand, for trying it out.
|
|
349
|
+
|
|
350
|
+
## What has to exist first
|
|
351
|
+
|
|
352
|
+
Say each of these to the person before you build. Each one changes whether it
|
|
353
|
+
works:
|
|
354
|
+
|
|
355
|
+
- **An API key for their server.** They create it at
|
|
356
|
+
platform.agentsky.dev \u2192 Developer \u2192 API keys and put it in the server's
|
|
357
|
+
environment (\`AGENTSKY_TOKEN\`). Never put it in code, a page their customers
|
|
358
|
+
load, or a brief.
|
|
359
|
+
- **Credit** on their account. Every run is a session they pay for. Give each
|
|
360
|
+
one a budget.
|
|
361
|
+
- **The skill**: a directory with \`SKILL.md\` at its root.
|
|
362
|
+
- **An engine that fits.** Default to \`claude_code\` on its default model. Check
|
|
363
|
+
\`sky catalog search <words>\` if the skill needs something else.
|
|
364
|
+
- **Their own customer sign-in.** AgentSky does not know their customers. A
|
|
365
|
+
customer id their page sends is a label, not proof of who it is.
|
|
366
|
+
|
|
367
|
+
## 1. One workspace per customer
|
|
368
|
+
|
|
369
|
+
\`\`\`
|
|
370
|
+
POST /v1/universes {"slug": "rv-acme", "name": "Uploads from acme"}
|
|
371
|
+
\`\`\`
|
|
372
|
+
|
|
373
|
+
Same by hand: \`sky universe create rv-acme\`. Files, memory, vaults and
|
|
374
|
+
sessions never cross workspaces. Name every later call's workspace with the
|
|
375
|
+
\`X-Universe: rv-acme\` header (\`--workspace rv-acme\` on \`sky\`).
|
|
376
|
+
|
|
377
|
+
## 2. Lock the workspace down
|
|
378
|
+
|
|
379
|
+
\`\`\`
|
|
380
|
+
PUT /v1/hook_rules {"rules": [{"point": "tool.call", "action": "block", "match": {}, "enabled": true}]}
|
|
381
|
+
POST /v1/universes/rv-acme/policies {"name": "reviewer-native-tools", "kind": "TOOL_CALL",
|
|
382
|
+
"config": {"action": "deny", "matcher": "Bash|BashOutput|KillShell|Edit|MultiEdit|Write|NotebookEdit|WebFetch|WebSearch|Task|mcp__.*"}}
|
|
383
|
+
POST /v1/universes/rv-acme/policies {"name": "reviewer-no-helpers", "kind": "CAPABILITY", "config": {"platform.orchestration": "deny"}}
|
|
384
|
+
\`\`\`
|
|
385
|
+
|
|
386
|
+
- **The hook rule** blocks every connected-app and capability call. Without it,
|
|
387
|
+
the account owner's own connected apps reach sessions the owner's key
|
|
388
|
+
starts.
|
|
389
|
+
- **The \`TOOL_CALL\` rule** denies Claude Code's shell, write, web, sub-agent
|
|
390
|
+
and MCP tools. A denied call answers "The platform did not authorize this
|
|
391
|
+
tool invocation."
|
|
392
|
+
- **Keep only the tools the skill needs.** A reviewer needs Read.
|
|
393
|
+
|
|
394
|
+
Telling the agent not to use a tool is not a boundary. The rule is. By hand:
|
|
395
|
+
\`sky policy add --universe rv-acme --name ... --kind TOOL_CALL --config '<json>'\`.
|
|
396
|
+
|
|
397
|
+
## 3. Install the skill, create the agent
|
|
398
|
+
|
|
399
|
+
\`\`\`
|
|
400
|
+
POST /v1/plugins multipart: one "files" field per file, named "<dir>/<path>", plus "displayName"
|
|
401
|
+
POST /v1/agents {"name": "upload-reviewer", "agentType": "claude_code", "prompt": "...",
|
|
402
|
+
"skills": [{"type": "skill", "skillId": "skill_..."}], "hiringPolicy": "deny"}
|
|
403
|
+
Idempotency-Key: provision-rv-acme-agent
|
|
404
|
+
\`\`\`
|
|
405
|
+
|
|
406
|
+
By hand: \`sky plugins upload ./upload-review --workspace rv-acme\`, then
|
|
407
|
+
\`sky agent create -f agent.toml --workspace rv-acme\` with
|
|
408
|
+
\`hiring_policy = "deny"\` and a \`[[skills]]\` table naming the skill id.
|
|
409
|
+
|
|
410
|
+
The prompt says what to read and what to answer. It also says that the
|
|
411
|
+
upload is data and that instructions written inside it are not to be
|
|
412
|
+
followed.
|
|
413
|
+
|
|
414
|
+
## 4. One fresh session per event
|
|
415
|
+
|
|
416
|
+
\`\`\`
|
|
417
|
+
POST /v1/files multipart "file" \u2192 {"id": "file_..."}
|
|
418
|
+
POST /v1/sessions Idempotency-Key: session-<job id>
|
|
419
|
+
{"agent": "agent_...", "defaults": "none",
|
|
420
|
+
"resources": [{"type": "file", "file_id": "file_...", "mount_path": "/upload/request.txt"}],
|
|
421
|
+
"budget": {"type": "limit", "max_list_cost": {"amount": "50", "currency": "USD"}}}
|
|
422
|
+
POST /v1/sessions/{id}/events Idempotency-Key: brief-<job id>
|
|
423
|
+
{"events": [{"type": "user.message", "content": [{"type": "text", "text": "Review /workspace/upload/request.txt with the upload-review skill."}]}]}
|
|
424
|
+
\`\`\`
|
|
425
|
+
|
|
426
|
+
- **\`defaults: "none"\`** keeps every workspace default out of the session:
|
|
427
|
+
environment, vault, shared files, skills and team memory. The session holds
|
|
428
|
+
only what the request names.
|
|
429
|
+
- **Idempotency keys come from the event.** Retrying a timed-out call with the
|
|
430
|
+
same key returns the first session, or replays the first message. A keyed
|
|
431
|
+
create cannot carry \`initial_events\`. Create the session, save its id, then
|
|
432
|
+
send the brief.
|
|
433
|
+
- **Reuse a session** only for a job that continues for the same customer.
|
|
434
|
+
|
|
435
|
+
By hand: \`sky session create agent_... --no-defaults --budget-cents 50 --file ./request.txt:/upload/request.txt --message "..."\`
|
|
436
|
+
(MCP: \`start_session\`).
|
|
437
|
+
|
|
438
|
+
## 5. Read the answer
|
|
439
|
+
|
|
440
|
+
\`\`\`
|
|
441
|
+
GET /v1/sessions/{id}/events?types[]=user.message&types[]=agent.message&types[]=session.status_idle&types[]=session.status_terminated&types[]=session.error
|
|
442
|
+
\`\`\`
|
|
443
|
+
|
|
444
|
+
- **When the turn is done.** It has ended at a \`session.status_idle\` whose
|
|
445
|
+
\`stop_reason.type\` is not \`requires_action\`, or at
|
|
446
|
+
\`session.status_terminated\`.
|
|
447
|
+
- **Where the answer is.** Take the last \`agent.message\` after the last
|
|
448
|
+
\`user.message\`. Earlier messages can be notes the agent wrote on the way.
|
|
449
|
+
- **Treat it as untrusted data.** Parse it against a fixed schema and fail
|
|
450
|
+
closed on anything else. Never run what it says.
|
|
451
|
+
- **Errors.** A \`session.error\` (budget reached, engine unavailable) is a
|
|
452
|
+
failure to report, not an answer.
|
|
453
|
+
|
|
454
|
+
By hand: \`sky session read <id> --wait --json\` (MCP: \`read_session\`).
|
|
455
|
+
|
|
456
|
+
## 6. Questions and approvals
|
|
457
|
+
|
|
458
|
+
\`GET /v1/sessions/{session id}/status\` lists the requests waiting on the key's owner:
|
|
459
|
+
the agent's questions, approvals, and apps to connect.
|
|
460
|
+
\`POST /v1/sessions/{id}/questions/{request id}/answer\` with \`{"text": ...}\` or
|
|
461
|
+
\`{"option_id": ...}\` answers one. Pass a customer's answer on only after
|
|
462
|
+
your application has checked who they are. By hand: \`sky session status <id>\` and
|
|
463
|
+
\`sky session answer <id> <request> --text "..."\` (MCP: \`get_session_status\`,
|
|
464
|
+
\`answer_request\`).
|
|
465
|
+
|
|
466
|
+
## 7. What the application keeps
|
|
467
|
+
|
|
468
|
+
The agent decides; the application acts. Keep these in the application's own
|
|
469
|
+
database:
|
|
470
|
+
|
|
471
|
+
- **One job per event**, with a unique event key. The same key with the same
|
|
472
|
+
payload returns the job it made; with a different payload it is a conflict.
|
|
473
|
+
- **The session id**, saved before you start polling, so a restart picks the
|
|
474
|
+
job up where it was.
|
|
475
|
+
- **A confirmation receipt** from the signed-in customer before any side
|
|
476
|
+
effect.
|
|
477
|
+
- **A unique action key per job**, so the side effect happens once. Agent
|
|
478
|
+
retries do not make it happen once; the key does.
|
|
479
|
+
- **Webhooks to the customer** with an event id, retried until acknowledged.
|
|
480
|
+
|
|
481
|
+
## Before launch
|
|
482
|
+
|
|
483
|
+
Check one real session:
|
|
484
|
+
|
|
485
|
+
- \`GET /v1/sessions/{id}\` lists only the upload under \`resources\`.
|
|
486
|
+
- \`GET /v1/hook_rules\` and \`GET /v1/universes/{slug}/policies\` show the rules
|
|
487
|
+
above.
|
|
488
|
+
- Ask the agent directly to run a shell command. The answer has to be the
|
|
489
|
+
platform's refusal.
|
|
490
|
+
- A file id from another customer's workspace is refused at session create.
|
|
491
|
+
`;
|
|
492
|
+
}
|
|
493
|
+
function workspacesReferenceDoc() {
|
|
494
|
+
return `# Workspaces in AgentSky
|
|
495
|
+
|
|
496
|
+
A workspace (also called a universe) groups agents and sessions. Every API call
|
|
497
|
+
and MCP tool accepts an optional workspace slug.
|
|
498
|
+
|
|
499
|
+
## How to choose
|
|
500
|
+
|
|
501
|
+
1. The person named one \u2192 use it.
|
|
502
|
+
2. Check the git root for \`.agentsky.json\` with a \`"workspace"\` key \u2192 use that.
|
|
503
|
+
3. Neither \u2192 use the account default (personal workspace). Never ask.
|
|
504
|
+
|
|
505
|
+
## Applying it
|
|
506
|
+
|
|
507
|
+
- MCP tools: pass \`workspace: "<slug>"\` on tools that accept it.
|
|
508
|
+
- sky CLI: \`--workspace <slug>\` on any command, or set \`SKY_WORKSPACE=<slug>\`.
|
|
509
|
+
- Tools that take a \`task_id\` or \`session_id\` inherit that task's workspace
|
|
510
|
+
automatically; one task never spans workspaces.
|
|
511
|
+
|
|
512
|
+
## Listing workspaces
|
|
513
|
+
|
|
514
|
+
\`sky workspace list\` (or \`sky universe list\`) prints your workspaces, with
|
|
515
|
+
\`*\` marking the current default.
|
|
516
|
+
|
|
517
|
+
## .agentsky.json
|
|
518
|
+
|
|
519
|
+
To set a per-repo default, create \`.agentsky.json\` at the git root:
|
|
520
|
+
|
|
521
|
+
\`\`\`json
|
|
522
|
+
{"workspace": "my-team-slug"}
|
|
523
|
+
\`\`\`
|
|
524
|
+
`;
|
|
525
|
+
}
|
|
526
|
+
function installedVersion(dir) {
|
|
527
|
+
try {
|
|
528
|
+
const marker = JSON.parse(readFileSync(join(dir, SKILL_MARKER), "utf8"));
|
|
529
|
+
return typeof marker.version === "string" ? marker.version : null;
|
|
530
|
+
} catch {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function isInstalledSkill(dir) {
|
|
535
|
+
return installedVersion(dir) !== null;
|
|
536
|
+
}
|
|
537
|
+
function installSkill(agent, opts = {}) {
|
|
538
|
+
const dir = join(agent.skillsDir, SKILL_NAME);
|
|
539
|
+
const previous = installedVersion(dir);
|
|
540
|
+
const outcome = previous === CLI_VERSION ? "current" : previous ? "updated" : "installed";
|
|
541
|
+
if (opts.dryRun) return { agent: agent.id, path: dir, outcome };
|
|
542
|
+
if (outcome !== "current") {
|
|
543
|
+
mkdirSync(dir, { recursive: true });
|
|
544
|
+
writeFileSync(join(dir, "SKILL.md"), skillDocument());
|
|
545
|
+
writeFileSync(join(dir, SKILL_MARKER), `${JSON.stringify({ version: CLI_VERSION }, null, 2)}
|
|
546
|
+
`);
|
|
547
|
+
}
|
|
548
|
+
if (opts.catalog) {
|
|
549
|
+
const catalog = renderCatalog(opts.catalog, opts.now ?? /* @__PURE__ */ new Date());
|
|
550
|
+
if (withoutDate(readOrNull(join(dir, CATALOG_FILE))) !== withoutDate(catalog)) {
|
|
551
|
+
mkdirSync(dir, { recursive: true });
|
|
552
|
+
writeFileSync(join(dir, CATALOG_FILE), catalog);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
mkdirSync(join(dir, REFERENCES_DIR), { recursive: true });
|
|
556
|
+
for (const [path, content] of Object.entries(skillReferenceFiles())) writeFileSync(join(dir, path), content);
|
|
557
|
+
return { agent: agent.id, path: dir, outcome };
|
|
558
|
+
}
|
|
559
|
+
function readOrNull(path) {
|
|
560
|
+
try {
|
|
561
|
+
return readFileSync(path, "utf8");
|
|
562
|
+
} catch {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
var withoutDate = (catalog) => catalog?.replace(/, as of \S+\./, ".") ?? null;
|
|
567
|
+
function skillPaths() {
|
|
568
|
+
return ["SKILL.md", SKILL_MARKER, CATALOG_FILE, ...Object.keys(skillReferenceFiles())];
|
|
569
|
+
}
|
|
570
|
+
function skillReferenceFiles() {
|
|
571
|
+
return {
|
|
572
|
+
[`${REFERENCES_DIR}/import.md`]: importReferenceDoc(),
|
|
573
|
+
[`${REFERENCES_DIR}/workspaces.md`]: workspacesReferenceDoc(),
|
|
574
|
+
[`${REFERENCES_DIR}/focused-agents.md`]: focusedAgentsReferenceDoc()
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/local-skills.ts
|
|
579
|
+
var HISTORY = 20;
|
|
580
|
+
var SAFE_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
581
|
+
function localSkillStatePath() {
|
|
582
|
+
return join2(dirname(configPath()), "local-skills.json");
|
|
583
|
+
}
|
|
584
|
+
function loadLocalSkillState(path = localSkillStatePath()) {
|
|
585
|
+
try {
|
|
586
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
587
|
+
return { version: 1, workspace: parsed.workspace, checkedAt: parsed.checkedAt, pins: parsed.pins ?? {}, skills: parsed.skills ?? {} };
|
|
588
|
+
} catch {
|
|
589
|
+
return { version: 1, pins: {}, skills: {} };
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function saveLocalSkillState(state, path = localSkillStatePath()) {
|
|
593
|
+
mkdirSync2(dirname(path), { recursive: true });
|
|
594
|
+
writeFileSync2(path, `${JSON.stringify(state, null, 2)}
|
|
595
|
+
`, { mode: 384 });
|
|
596
|
+
}
|
|
597
|
+
function installedMarker(dir) {
|
|
598
|
+
try {
|
|
599
|
+
const marker = JSON.parse(readFileSync2(join2(dir, SKILL_MARKER), "utf8"));
|
|
600
|
+
if (typeof marker.version !== "string") return null;
|
|
601
|
+
return {
|
|
602
|
+
version: marker.version,
|
|
603
|
+
...typeof marker.skill_id === "string" ? { skill_id: marker.skill_id } : {},
|
|
604
|
+
...typeof marker.revision_id === "string" ? { revision_id: marker.revision_id } : {},
|
|
605
|
+
...typeof marker.fingerprint === "string" ? { fingerprint: marker.fingerprint } : {}
|
|
606
|
+
};
|
|
607
|
+
} catch {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
var deliveredHere = (dir) => installedMarker(dir)?.fingerprint !== void 0;
|
|
612
|
+
function currentEverywhere(targets, name, fingerprint) {
|
|
613
|
+
return targets.every((target) => installedMarker(join2(target.skillsDir, name))?.fingerprint === fingerprint);
|
|
614
|
+
}
|
|
615
|
+
function writeSkillDir(dir, skill, journal) {
|
|
616
|
+
const root = resolve(dir);
|
|
617
|
+
const staging = `${root}.sky-staging`;
|
|
618
|
+
rmSync(staging, { recursive: true, force: true });
|
|
619
|
+
for (const file of skill.files ?? []) {
|
|
620
|
+
const target = resolve(staging, file.path);
|
|
621
|
+
if (!target.startsWith(`${staging}${sep}`) || file.path === SKILL_MARKER) throw new Error(`${skill.name}: refused the file ${file.path}`);
|
|
622
|
+
mkdirSync2(dirname(target), { recursive: true });
|
|
623
|
+
writeFileSync2(target, Buffer.from(file.contentBase64, "base64"), { mode: file.executable ? 493 : 420 });
|
|
624
|
+
}
|
|
625
|
+
writeFileSync2(join2(staging, SKILL_MARKER), `${JSON.stringify({ version: CLI_VERSION, skill_id: skill.skill_id, revision_id: skill.revision_id, fingerprint: skill.fingerprint, layer: skill.layer }, null, 2)}
|
|
626
|
+
`);
|
|
627
|
+
journal?.own(root);
|
|
628
|
+
rmSync(root, { recursive: true, force: true });
|
|
629
|
+
renameSync(staging, root);
|
|
630
|
+
}
|
|
631
|
+
function installedFingerprints(state, targets) {
|
|
632
|
+
return Object.entries(state.skills).flatMap(([name, entry2]) => {
|
|
633
|
+
const latest = entry2.installs.at(-1);
|
|
634
|
+
return latest && currentEverywhere(targets, name, latest.fingerprint) ? [latest.fingerprint] : [];
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async function syncLocalSkills(opts) {
|
|
638
|
+
const now = (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
639
|
+
const statePath = opts.statePath ?? localSkillStatePath();
|
|
640
|
+
const state = loadLocalSkillState(statePath);
|
|
641
|
+
const before = JSON.stringify({ pins: state.pins, skills: state.skills });
|
|
642
|
+
const have = installedFingerprints(state, opts.targets);
|
|
643
|
+
const answer = await opts.request("GET", `/skills/local${have.length ? `?have=${encodeURIComponent(have.join(","))}` : ""}`, opts.workspace);
|
|
644
|
+
const outcomes = [];
|
|
645
|
+
const named = /* @__PURE__ */ new Set();
|
|
646
|
+
for (const skill of answer.skills ?? []) {
|
|
647
|
+
if (!SAFE_NAME.test(skill.name) || skill.name === SKILL_NAME) {
|
|
648
|
+
outcomes.push({ name: skill.name, outcome: "failed", detail: "not a folder name sky writes" });
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
named.add(skill.name);
|
|
652
|
+
const base = { name: skill.name, revision_id: skill.revision_id, layer: skill.layer, ...skill.hides ? { hides: skill.hides.skill_id } : {} };
|
|
653
|
+
const pinned = state.pins[skill.name];
|
|
654
|
+
if (pinned && pinned !== skill.fingerprint && state.skills[skill.name]) {
|
|
655
|
+
outcomes.push({ ...base, revision_id: state.skills[skill.name].installs.at(-1)?.revision_id, outcome: "pinned" });
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (currentEverywhere(opts.targets, skill.name, skill.fingerprint)) {
|
|
659
|
+
outcomes.push({ ...base, outcome: "current" });
|
|
660
|
+
recordInstall(state, skill, now);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (!skill.files) {
|
|
664
|
+
outcomes.push({ ...base, outcome: "failed", detail: "the files were not sent; the next sync fetches them" });
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
if (opts.dryRun) {
|
|
668
|
+
outcomes.push({ ...base, outcome: "planned" });
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
let wrote = false;
|
|
672
|
+
let kept;
|
|
673
|
+
try {
|
|
674
|
+
for (const target of opts.targets) {
|
|
675
|
+
const dir = join2(target.skillsDir, skill.name);
|
|
676
|
+
if (existsSync(dir) && !deliveredHere(dir)) {
|
|
677
|
+
kept = dir;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (installedMarker(dir)?.fingerprint === skill.fingerprint) continue;
|
|
681
|
+
writeSkillDir(dir, skill, opts.journal);
|
|
682
|
+
wrote = true;
|
|
683
|
+
}
|
|
684
|
+
} catch (error) {
|
|
685
|
+
outcomes.push({ ...base, outcome: "failed", detail: error instanceof Error ? error.message : String(error) });
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const earlier = state.skills[skill.name]?.installs.length;
|
|
689
|
+
if (wrote || !kept) recordInstall(state, skill, now);
|
|
690
|
+
outcomes.push({ ...base, outcome: !wrote && kept ? "kept_yours" : earlier ? "updated" : "installed", ...kept ? { detail: `${kept} is your own; left as it is` } : {} });
|
|
691
|
+
}
|
|
692
|
+
for (const name of Object.keys(state.skills)) {
|
|
693
|
+
if (named.has(name) || state.pins[name]) continue;
|
|
694
|
+
if (!opts.dryRun) {
|
|
695
|
+
for (const target of opts.targets) {
|
|
696
|
+
const dir = join2(target.skillsDir, name);
|
|
697
|
+
if (deliveredHere(dir)) rmSync(dir, { recursive: true, force: true });
|
|
698
|
+
}
|
|
699
|
+
delete state.skills[name];
|
|
700
|
+
}
|
|
701
|
+
outcomes.push({ name, outcome: opts.dryRun ? "planned" : "removed" });
|
|
702
|
+
}
|
|
703
|
+
const changed = JSON.stringify({ pins: state.pins, skills: state.skills }) !== before;
|
|
704
|
+
if (!opts.dryRun && (changed || opts.recordCheck !== false)) {
|
|
705
|
+
opts.journal?.own(statePath);
|
|
706
|
+
saveLocalSkillState({ ...state, workspace: answer.workspace ?? opts.workspace, checkedAt: now }, statePath);
|
|
707
|
+
}
|
|
708
|
+
return { workspace: answer.workspace ?? opts.workspace, checked: true, skills: outcomes };
|
|
709
|
+
}
|
|
710
|
+
function recordInstall(state, skill, at) {
|
|
711
|
+
const entry2 = state.skills[skill.name] ?? { skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides, installs: [] };
|
|
712
|
+
if (entry2.installs.at(-1)?.fingerprint !== skill.fingerprint) entry2.installs = [...entry2.installs, { revision_id: skill.revision_id, fingerprint: skill.fingerprint, from: at }].slice(-HISTORY);
|
|
713
|
+
state.skills[skill.name] = { ...entry2, skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides };
|
|
714
|
+
}
|
|
715
|
+
function pinLocalSkill(name, statePath) {
|
|
716
|
+
const state = loadLocalSkillState(statePath);
|
|
717
|
+
const latest = state.skills[name]?.installs.at(-1);
|
|
718
|
+
if (!latest) throw new Error(`no skill named ${name} is installed by sky on this computer; see \`sky skills local\``);
|
|
719
|
+
state.pins[name] = latest.fingerprint;
|
|
720
|
+
saveLocalSkillState(state, statePath);
|
|
721
|
+
return latest;
|
|
722
|
+
}
|
|
723
|
+
function unpinLocalSkill(name, statePath) {
|
|
724
|
+
const state = loadLocalSkillState(statePath);
|
|
725
|
+
if (!state.pins[name]) return false;
|
|
726
|
+
delete state.pins[name];
|
|
727
|
+
saveLocalSkillState(state, statePath);
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
function checkedWithin(ms, now = /* @__PURE__ */ new Date(), statePath) {
|
|
731
|
+
const at = Date.parse(loadLocalSkillState(statePath).checkedAt ?? "");
|
|
732
|
+
return Number.isFinite(at) && now.getTime() - at < ms;
|
|
733
|
+
}
|
|
734
|
+
function skillTargets(agents, hermesRoot) {
|
|
735
|
+
return [...agents.map((agent) => ({ id: agent.id, skillsDir: agent.skillsDir })), ...hermesRoot ? [{ id: "hermes", skillsDir: join2(hermesRoot, "skills") }] : []];
|
|
736
|
+
}
|
|
737
|
+
function revisionAt(state, name, at) {
|
|
738
|
+
const installs = state.skills[name]?.installs ?? [];
|
|
739
|
+
const when = Date.parse(at ?? "");
|
|
740
|
+
if (!Number.isFinite(when)) return installs.at(-1)?.revision_id ?? null;
|
|
741
|
+
let found = null;
|
|
742
|
+
for (const install of installs) if (Date.parse(install.from) <= when) found = install.revision_id;
|
|
743
|
+
return found;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export {
|
|
747
|
+
SKILL_NAME,
|
|
748
|
+
isInstalledSkill,
|
|
749
|
+
installSkill,
|
|
750
|
+
skillPaths,
|
|
751
|
+
localSkillStatePath,
|
|
752
|
+
loadLocalSkillState,
|
|
753
|
+
saveLocalSkillState,
|
|
754
|
+
installedMarker,
|
|
755
|
+
syncLocalSkills,
|
|
756
|
+
pinLocalSkill,
|
|
757
|
+
unpinLocalSkill,
|
|
758
|
+
checkedWithin,
|
|
759
|
+
skillTargets,
|
|
760
|
+
revisionAt
|
|
761
|
+
};
|