@agentsky/sky 3.43.0 → 3.45.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.
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  TRACE_CONTENT_SCOPES,
3
3
  redactTraceText
4
- } from "./chunk-BIZJ4VZL.js";
4
+ } from "./chunk-AM6GOGA6.js";
5
5
  import {
6
6
  USER_AGENT
7
- } from "./chunk-4A4PDUT5.js";
7
+ } from "./chunk-7DFFA6GA.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-4A4PDUT5.js";
3
+ } from "./chunk-7DFFA6GA.js";
4
4
  import {
5
5
  apiBase,
6
6
  apiToken,
@@ -0,0 +1,193 @@
1
+ import {
2
+ SKILL_MARKER,
3
+ SKILL_NAME
4
+ } from "./chunk-OBRH43HE.js";
5
+ import {
6
+ CLI_VERSION
7
+ } from "./chunk-7DFFA6GA.js";
8
+ import {
9
+ configPath
10
+ } from "./chunk-XHZJG3QT.js";
11
+
12
+ // src/local-skills.ts
13
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
14
+ import { dirname, join, resolve, sep } from "path";
15
+ var HISTORY = 20;
16
+ var SAFE_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
17
+ function localSkillStatePath() {
18
+ return join(dirname(configPath()), "local-skills.json");
19
+ }
20
+ function loadLocalSkillState(path = localSkillStatePath()) {
21
+ try {
22
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
23
+ return { version: 1, workspace: parsed.workspace, checkedAt: parsed.checkedAt, pins: parsed.pins ?? {}, skills: parsed.skills ?? {} };
24
+ } catch {
25
+ return { version: 1, pins: {}, skills: {} };
26
+ }
27
+ }
28
+ function saveLocalSkillState(state, path = localSkillStatePath()) {
29
+ mkdirSync(dirname(path), { recursive: true });
30
+ writeFileSync(path, `${JSON.stringify(state, null, 2)}
31
+ `, { mode: 384 });
32
+ }
33
+ function installedMarker(dir) {
34
+ try {
35
+ const marker = JSON.parse(readFileSync(join(dir, SKILL_MARKER), "utf8"));
36
+ if (typeof marker.version !== "string") return null;
37
+ return {
38
+ version: marker.version,
39
+ ...typeof marker.skill_id === "string" ? { skill_id: marker.skill_id } : {},
40
+ ...typeof marker.revision_id === "string" ? { revision_id: marker.revision_id } : {},
41
+ ...typeof marker.fingerprint === "string" ? { fingerprint: marker.fingerprint } : {}
42
+ };
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+ var deliveredHere = (dir) => installedMarker(dir)?.fingerprint !== void 0;
48
+ function currentEverywhere(targets, name, fingerprint) {
49
+ return targets.every((target) => installedMarker(join(target.skillsDir, name))?.fingerprint === fingerprint);
50
+ }
51
+ function writeSkillDir(dir, skill, journal) {
52
+ const root = resolve(dir);
53
+ const staging = `${root}.sky-staging`;
54
+ rmSync(staging, { recursive: true, force: true });
55
+ for (const file of skill.files ?? []) {
56
+ const target = resolve(staging, file.path);
57
+ if (!target.startsWith(`${staging}${sep}`) || file.path === SKILL_MARKER) throw new Error(`${skill.name}: refused the file ${file.path}`);
58
+ mkdirSync(dirname(target), { recursive: true });
59
+ writeFileSync(target, Buffer.from(file.contentBase64, "base64"), { mode: file.executable ? 493 : 420 });
60
+ }
61
+ writeFileSync(join(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)}
62
+ `);
63
+ journal?.own(root);
64
+ rmSync(root, { recursive: true, force: true });
65
+ renameSync(staging, root);
66
+ }
67
+ function installedFingerprints(state, targets) {
68
+ return Object.entries(state.skills).flatMap(([name, entry]) => {
69
+ const latest = entry.installs.at(-1);
70
+ return latest && currentEverywhere(targets, name, latest.fingerprint) ? [latest.fingerprint] : [];
71
+ });
72
+ }
73
+ async function syncLocalSkills(opts) {
74
+ const now = (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
75
+ const statePath = opts.statePath ?? localSkillStatePath();
76
+ const state = loadLocalSkillState(statePath);
77
+ const before = JSON.stringify({ pins: state.pins, skills: state.skills });
78
+ const have = installedFingerprints(state, opts.targets);
79
+ const answer = await opts.request("GET", `/skills/local${have.length ? `?have=${encodeURIComponent(have.join(","))}` : ""}`, opts.workspace);
80
+ const outcomes = [];
81
+ const named = /* @__PURE__ */ new Set();
82
+ for (const skill of answer.skills ?? []) {
83
+ if (!SAFE_NAME.test(skill.name) || skill.name === SKILL_NAME) {
84
+ outcomes.push({ name: skill.name, outcome: "failed", detail: "not a folder name sky writes" });
85
+ continue;
86
+ }
87
+ named.add(skill.name);
88
+ const base = { name: skill.name, revision_id: skill.revision_id, layer: skill.layer, ...skill.hides ? { hides: skill.hides.skill_id } : {} };
89
+ const pinned = state.pins[skill.name];
90
+ if (pinned && pinned !== skill.fingerprint && state.skills[skill.name]) {
91
+ outcomes.push({ ...base, revision_id: state.skills[skill.name].installs.at(-1)?.revision_id, outcome: "pinned" });
92
+ continue;
93
+ }
94
+ if (currentEverywhere(opts.targets, skill.name, skill.fingerprint)) {
95
+ outcomes.push({ ...base, outcome: "current" });
96
+ recordInstall(state, skill, now);
97
+ continue;
98
+ }
99
+ if (!skill.files) {
100
+ outcomes.push({ ...base, outcome: "failed", detail: "the files were not sent; the next sync fetches them" });
101
+ continue;
102
+ }
103
+ if (opts.dryRun) {
104
+ outcomes.push({ ...base, outcome: "planned" });
105
+ continue;
106
+ }
107
+ let wrote = false;
108
+ let kept;
109
+ try {
110
+ for (const target of opts.targets) {
111
+ const dir = join(target.skillsDir, skill.name);
112
+ if (existsSync(dir) && !deliveredHere(dir)) {
113
+ kept = dir;
114
+ continue;
115
+ }
116
+ if (installedMarker(dir)?.fingerprint === skill.fingerprint) continue;
117
+ writeSkillDir(dir, skill, opts.journal);
118
+ wrote = true;
119
+ }
120
+ } catch (error) {
121
+ outcomes.push({ ...base, outcome: "failed", detail: error instanceof Error ? error.message : String(error) });
122
+ continue;
123
+ }
124
+ const earlier = state.skills[skill.name]?.installs.length;
125
+ if (wrote || !kept) recordInstall(state, skill, now);
126
+ outcomes.push({ ...base, outcome: !wrote && kept ? "kept_yours" : earlier ? "updated" : "installed", ...kept ? { detail: `${kept} is your own; left as it is` } : {} });
127
+ }
128
+ for (const name of Object.keys(state.skills)) {
129
+ if (named.has(name) || state.pins[name]) continue;
130
+ if (!opts.dryRun) {
131
+ for (const target of opts.targets) {
132
+ const dir = join(target.skillsDir, name);
133
+ if (deliveredHere(dir)) rmSync(dir, { recursive: true, force: true });
134
+ }
135
+ delete state.skills[name];
136
+ }
137
+ outcomes.push({ name, outcome: opts.dryRun ? "planned" : "removed" });
138
+ }
139
+ const changed = JSON.stringify({ pins: state.pins, skills: state.skills }) !== before;
140
+ if (!opts.dryRun && (changed || opts.recordCheck !== false)) {
141
+ opts.journal?.own(statePath);
142
+ saveLocalSkillState({ ...state, workspace: answer.workspace ?? opts.workspace, checkedAt: now }, statePath);
143
+ }
144
+ return { workspace: answer.workspace ?? opts.workspace, checked: true, skills: outcomes };
145
+ }
146
+ function recordInstall(state, skill, at) {
147
+ const entry = state.skills[skill.name] ?? { skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides, installs: [] };
148
+ if (entry.installs.at(-1)?.fingerprint !== skill.fingerprint) entry.installs = [...entry.installs, { revision_id: skill.revision_id, fingerprint: skill.fingerprint, from: at }].slice(-HISTORY);
149
+ state.skills[skill.name] = { ...entry, skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides };
150
+ }
151
+ function pinLocalSkill(name, statePath) {
152
+ const state = loadLocalSkillState(statePath);
153
+ const latest = state.skills[name]?.installs.at(-1);
154
+ if (!latest) throw new Error(`no skill named ${name} is installed by sky on this computer; see \`sky skills local\``);
155
+ state.pins[name] = latest.fingerprint;
156
+ saveLocalSkillState(state, statePath);
157
+ return latest;
158
+ }
159
+ function unpinLocalSkill(name, statePath) {
160
+ const state = loadLocalSkillState(statePath);
161
+ if (!state.pins[name]) return false;
162
+ delete state.pins[name];
163
+ saveLocalSkillState(state, statePath);
164
+ return true;
165
+ }
166
+ function checkedWithin(ms, now = /* @__PURE__ */ new Date(), statePath) {
167
+ const at = Date.parse(loadLocalSkillState(statePath).checkedAt ?? "");
168
+ return Number.isFinite(at) && now.getTime() - at < ms;
169
+ }
170
+ function skillTargets(agents, hermesRoot) {
171
+ return [...agents.map((agent) => ({ id: agent.id, skillsDir: agent.skillsDir })), ...hermesRoot ? [{ id: "hermes", skillsDir: join(hermesRoot, "skills") }] : []];
172
+ }
173
+ function revisionAt(state, name, at) {
174
+ const installs = state.skills[name]?.installs ?? [];
175
+ const when = Date.parse(at ?? "");
176
+ if (!Number.isFinite(when)) return installs.at(-1)?.revision_id ?? null;
177
+ let found = null;
178
+ for (const install of installs) if (Date.parse(install.from) <= when) found = install.revision_id;
179
+ return found;
180
+ }
181
+
182
+ export {
183
+ localSkillStatePath,
184
+ loadLocalSkillState,
185
+ saveLocalSkillState,
186
+ installedMarker,
187
+ syncLocalSkills,
188
+ pinLocalSkill,
189
+ unpinLocalSkill,
190
+ checkedWithin,
191
+ skillTargets,
192
+ revisionAt
193
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UnsafeImportError,
3
3
  redactLine
4
- } from "./chunk-BIZJ4VZL.js";
4
+ } from "./chunk-AM6GOGA6.js";
5
5
 
6
6
  // src/trace-exclusions.ts
7
7
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
@@ -0,0 +1,35 @@
1
+ import {
2
+ api
3
+ } from "./chunk-WLTOVOTW.js";
4
+ import "./chunk-7DFFA6GA.js";
5
+ import "./chunk-XHZJG3QT.js";
6
+ import "./chunk-MLKGABMK.js";
7
+
8
+ // src/compute.ts
9
+ var MARKS = ["plugins", "skills", "capture", "settings"];
10
+ async function listComputeMachines() {
11
+ return (await api("GET", "/compute/machines")).machines;
12
+ }
13
+ async function requestRepair(id) {
14
+ return (await api("POST", `/compute/machines/${encodeURIComponent(id)}/repair`)).machine;
15
+ }
16
+ async function removeMachine(id) {
17
+ return (await api("DELETE", `/compute/machines/${encodeURIComponent(id)}`)).removed;
18
+ }
19
+ function renderMachines(machines, here) {
20
+ if (!machines.length) return "No computer is set up yet. Run `npx -y @agentsky/sky setup` on one.";
21
+ return machines.map((machine) => {
22
+ const head = `${machine.name}${machine.id === here ? " (this computer)" : ""} ${machine.id} reported ${machine.reported_at}${machine.repair_requested_at ? " repair asked" : ""}`;
23
+ const engines = machine.engines.length ? machine.engines.map((engine) => {
24
+ const problems = MARKS.filter((mark) => engine[mark] !== "current").map((mark) => `${mark} ${engine[mark]}`);
25
+ return ` ${engine.name}: ${problems.length ? problems.join(", ") : "all current"}`;
26
+ }) : [" no engine"];
27
+ return [head, ...engines].join("\n");
28
+ }).join("\n\n");
29
+ }
30
+ export {
31
+ listComputeMachines,
32
+ removeMachine,
33
+ renderMachines,
34
+ requestRepair
35
+ };
@@ -0,0 +1,34 @@
1
+ import {
2
+ MCP_ENTRY,
3
+ computerClients,
4
+ computerReport,
5
+ describeRepair,
6
+ engineReports,
7
+ machineKey,
8
+ repairComputer,
9
+ reportComputer,
10
+ upkeepComputer
11
+ } from "./chunk-TPDNO2LM.js";
12
+ import "./chunk-EO32DG3Z.js";
13
+ import "./chunk-UHEJFBZJ.js";
14
+ import "./chunk-YYDO5WB5.js";
15
+ import "./chunk-AM6GOGA6.js";
16
+ import "./chunk-MXIAK52Z.js";
17
+ import "./chunk-OYSSK6GS.js";
18
+ import "./chunk-WLTOVOTW.js";
19
+ import "./chunk-WSQZHRE4.js";
20
+ import "./chunk-OBRH43HE.js";
21
+ import "./chunk-7DFFA6GA.js";
22
+ import "./chunk-XHZJG3QT.js";
23
+ import "./chunk-MLKGABMK.js";
24
+ export {
25
+ MCP_ENTRY,
26
+ computerClients,
27
+ computerReport,
28
+ describeRepair,
29
+ engineReports,
30
+ machineKey,
31
+ repairComputer,
32
+ reportComputer,
33
+ upkeepComputer
34
+ };