@baique/pi-web-sky 0.1.35 → 0.1.36

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 (294) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +16 -16
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/react-loadable-manifest.json +1 -1
  5. package/.next/required-server-files.js +1 -1
  6. package/.next/required-server-files.json +1 -1
  7. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next/server/app/_global-error.html +1 -1
  9. package/.next/server/app/_global-error.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  14. package/.next/server/app/_not-found.html +1 -1
  15. package/.next/server/app/_not-found.rsc +3 -3
  16. package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  17. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
  18. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  19. package/.next/server/app/api/agent/[id]/bash-output/route.js +1 -1
  20. package/.next/server/app/api/agent/[id]/events/route.js +1 -1
  21. package/.next/server/app/api/agent/[id]/route.js +1 -1
  22. package/.next/server/app/api/app-update/route.js +1 -1
  23. package/.next/server/app/api/auth/login/[provider]/route.js +1 -1
  24. package/.next/server/app/api/cwd/validate/route.js +1 -1
  25. package/.next/server/app/api/default-cwd/route.js +1 -1
  26. package/.next/server/app/api/file-index/route.js +1 -1
  27. package/.next/server/app/api/files/[...path]/route.js +1 -1
  28. package/.next/server/app/api/mcp/route.js +1 -1
  29. package/.next/server/app/api/models/route.js +1 -1
  30. package/.next/server/app/api/plugins/route.js +1 -1
  31. package/.next/server/app/api/project-trust/route.js +1 -1
  32. package/.next/server/app/api/search/route.js +1 -1
  33. package/.next/server/app/api/sessions/[id]/auto-name/route.js +1 -1
  34. package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
  35. package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +1 -1
  36. package/.next/server/app/api/sessions/[id]/export/route.js +1 -1
  37. package/.next/server/app/api/sessions/[id]/state/route.js +1 -1
  38. package/.next/server/app/api/sessions/[id]/todos/route.js +1 -1
  39. package/.next/server/app/api/sessions/route.js +1 -1
  40. package/.next/server/app/api/skills/check/route.js +1 -1
  41. package/.next/server/app/api/skills/check/route.js.nft.json +1 -1
  42. package/.next/server/app/api/skills/install/route.js +1 -1
  43. package/.next/server/app/api/skills/route.js +2 -31
  44. package/.next/server/app/api/skills/route.js.nft.json +1 -1
  45. package/.next/server/app/api/skills/update/route.js +1 -1
  46. package/.next/server/app/api/skills/update/route.js.nft.json +1 -1
  47. package/.next/server/app/api/worktrees/route.js +1 -1
  48. package/.next/server/app/index.html +1 -1
  49. package/.next/server/app/index.rsc +5 -5
  50. package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
  51. package/.next/server/app/index.segments/_full.segment.rsc +5 -5
  52. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  53. package/.next/server/app/page.js +2 -2
  54. package/.next/server/app/page_client-reference-manifest.js +1 -1
  55. package/.next/server/app-paths-manifest.json +16 -16
  56. package/.next/server/chunks/2404.js +1 -1
  57. package/.next/server/chunks/3500.js +30 -0
  58. package/.next/server/chunks/4226.js +2 -2
  59. package/.next/server/chunks/542.js +10 -5
  60. package/.next/server/chunks/5794.js +1 -1
  61. package/.next/server/chunks/6429.js +1 -1
  62. package/.next/server/chunks/898.js +1 -1
  63. package/.next/server/middleware-build-manifest.js +1 -1
  64. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  65. package/.next/server/pages/404.html +1 -1
  66. package/.next/server/pages/500.html +1 -1
  67. package/.next/static/chunks/5315.7e72d26a3ad3bd9a.js +4 -0
  68. package/.next/static/chunks/app/{layout-1d9a7a44fbc92d2e.js → layout-ebbc0d287267b07b.js} +1 -1
  69. package/.next/static/chunks/app/{page-6d6779a81a0a7639.js → page-e568623a44c67606.js} +2 -2
  70. package/.next/static/chunks/{webpack-fa4f40085b1ec1ac.js → webpack-2e4e348867a555cd.js} +1 -1
  71. package/.next/static/css/422c7dc0faa04d89.css +1 -0
  72. package/.next/trace +8 -9
  73. package/.next/trace-build +1 -1
  74. package/bin/pi-web-sky.js +15 -20
  75. package/lib/agent-client.test.mjs +64 -0
  76. package/lib/agent-client.ts +53 -0
  77. package/lib/agent-event-connection.test.mjs +193 -0
  78. package/lib/agent-event-connection.ts +202 -0
  79. package/lib/agent-event-stream.test.mjs +155 -0
  80. package/lib/agent-event-stream.ts +132 -0
  81. package/lib/agent-event-wire.test.mjs +278 -0
  82. package/lib/agent-event-wire.ts +107 -0
  83. package/lib/agent-phase.ts +24 -0
  84. package/lib/allowed-roots.ts +31 -0
  85. package/lib/ansi.test.mjs +52 -0
  86. package/lib/ansi.ts +211 -0
  87. package/lib/api-types.ts +139 -0
  88. package/lib/app-update.test.mjs +27 -0
  89. package/lib/app-update.ts +28 -0
  90. package/lib/atomic-file.test.mjs +37 -0
  91. package/lib/atomic-file.ts +34 -0
  92. package/lib/audit-session.ts +235 -0
  93. package/lib/bash-output.test.mjs +63 -0
  94. package/lib/bash-output.ts +53 -0
  95. package/lib/bg-image.ts +129 -0
  96. package/lib/board-events.ts +83 -0
  97. package/lib/board-purge.test.mjs +66 -0
  98. package/lib/board-purge.ts +65 -0
  99. package/lib/board-search.test.mjs +110 -0
  100. package/lib/board-search.ts +63 -0
  101. package/lib/board-store.test.mjs +542 -0
  102. package/lib/board-store.ts +794 -0
  103. package/lib/board-types.ts +96 -0
  104. package/lib/board-utils.ts +17 -0
  105. package/lib/bounded-form-data.test.mjs +54 -0
  106. package/lib/bounded-form-data.ts +49 -0
  107. package/lib/browser-notifications.test.mjs +167 -0
  108. package/lib/browser-notifications.ts +104 -0
  109. package/lib/chat-lazy-load.test.mjs +140 -0
  110. package/lib/chat-lazy-load.ts +64 -0
  111. package/lib/clipboard-paths.test.mjs +140 -0
  112. package/lib/clipboard-paths.ts +192 -0
  113. package/lib/clipboard.ts +18 -0
  114. package/lib/compaction-summary.test.mjs +44 -0
  115. package/lib/compaction-summary.ts +34 -0
  116. package/lib/custom-ui-terminal.test.mjs +32 -0
  117. package/lib/custom-ui-terminal.ts +27 -0
  118. package/lib/deepseek-pricing.test.mjs +120 -0
  119. package/lib/deepseek-pricing.ts +71 -0
  120. package/lib/directory-browser.test.mjs +60 -0
  121. package/lib/directory-browser.ts +83 -0
  122. package/lib/draft-stash.test.mjs +91 -0
  123. package/lib/draft-stash.ts +102 -0
  124. package/lib/draft-store.ts +105 -0
  125. package/lib/dropdown-direction.ts +27 -0
  126. package/lib/extension-command.test.mjs +63 -0
  127. package/lib/extension-command.ts +81 -0
  128. package/lib/file-access.test.mjs +31 -0
  129. package/lib/file-access.ts +59 -0
  130. package/lib/file-dirent.test.mjs +56 -0
  131. package/lib/file-dirent.ts +17 -0
  132. package/lib/file-explorer-state.test.mjs +63 -0
  133. package/lib/file-explorer-state.ts +36 -0
  134. package/lib/file-fuzzy.test.mjs +29 -0
  135. package/lib/file-fuzzy.ts +189 -0
  136. package/lib/file-links.test.mjs +92 -0
  137. package/lib/file-links.ts +148 -0
  138. package/lib/file-paths.ts +43 -0
  139. package/lib/file-types.test.mjs +34 -0
  140. package/lib/file-types.ts +73 -0
  141. package/lib/file-upload.test.mjs +70 -0
  142. package/lib/file-upload.ts +59 -0
  143. package/lib/file-viewer-state.test.mjs +20 -0
  144. package/lib/file-viewer-state.ts +15 -0
  145. package/lib/frontmatter.test.mjs +55 -0
  146. package/lib/frontmatter.ts +87 -0
  147. package/lib/git-changes.test.mjs +52 -0
  148. package/lib/git-changes.ts +232 -0
  149. package/lib/git-status.ts +47 -0
  150. package/lib/git-types.ts +29 -0
  151. package/lib/http-dispatcher.test.mjs +83 -0
  152. package/lib/http-dispatcher.ts +86 -0
  153. package/lib/i18n/format.test.mjs +19 -0
  154. package/lib/i18n/format.ts +60 -0
  155. package/lib/i18n/messages/en.ts +662 -0
  156. package/lib/i18n/messages/zh-CN.ts +661 -0
  157. package/lib/i18n/registry.test.mjs +32 -0
  158. package/lib/i18n/registry.ts +43 -0
  159. package/lib/i18n/types.ts +15 -0
  160. package/lib/image-attachments.test.mjs +27 -0
  161. package/lib/image-attachments.ts +56 -0
  162. package/lib/initial-navigation.test.mjs +65 -0
  163. package/lib/initial-navigation.ts +15 -0
  164. package/lib/markdown.test.mjs +104 -0
  165. package/lib/markdown.ts +347 -0
  166. package/lib/message-display.test.mjs +130 -0
  167. package/lib/message-display.ts +47 -0
  168. package/lib/model-catalog.test.mjs +327 -0
  169. package/lib/model-catalog.ts +414 -0
  170. package/lib/model-discovery-auth.ts +58 -0
  171. package/lib/model-discovery.test.mjs +50 -0
  172. package/lib/model-discovery.ts +75 -0
  173. package/lib/model-id-preference.ts +46 -0
  174. package/lib/model-scope.test.mjs +193 -0
  175. package/lib/model-scope.ts +198 -0
  176. package/lib/models-cache.test.mjs +122 -0
  177. package/lib/models-cache.ts +90 -0
  178. package/lib/models-config-store.test.mjs +200 -0
  179. package/lib/models-config-store.ts +84 -0
  180. package/lib/next-config-esm.test.mjs +14 -0
  181. package/lib/next-config.test.mjs +13 -0
  182. package/lib/node-version.test.mjs +33 -0
  183. package/lib/normalize.test.mjs +54 -0
  184. package/lib/normalize.ts +63 -0
  185. package/lib/npx.ts +62 -0
  186. package/lib/panel-layout.test.mjs +56 -0
  187. package/lib/panel-layout.ts +52 -0
  188. package/lib/patch.test.mjs +110 -0
  189. package/lib/patch.ts +134 -0
  190. package/lib/path-security.ts +42 -0
  191. package/lib/paths.test.mjs +58 -0
  192. package/lib/paths.ts +71 -0
  193. package/lib/pi-types.ts +183 -0
  194. package/lib/pi-web-options.test.mjs +63 -0
  195. package/lib/process-lifecycle.test.mjs +83 -0
  196. package/lib/project-command-env.test.mjs +298 -0
  197. package/lib/project-command-env.ts +129 -0
  198. package/lib/project-groups.test.mjs +60 -0
  199. package/lib/project-groups.ts +53 -0
  200. package/lib/project-identity.test.mjs +37 -0
  201. package/lib/project-identity.ts +26 -0
  202. package/lib/project-tree.test.mjs +115 -0
  203. package/lib/project-tree.ts +176 -0
  204. package/lib/project-trust.test.mjs +117 -0
  205. package/lib/project-trust.ts +48 -0
  206. package/lib/prompt-recovery.test.mjs +33 -0
  207. package/lib/prompt-recovery.ts +47 -0
  208. package/lib/provider-api-key-route.test.mjs +12 -0
  209. package/lib/provider-credential-store.test.mjs +126 -0
  210. package/lib/provider-credential-store.ts +114 -0
  211. package/lib/provider-listing-runtime.ts +37 -0
  212. package/lib/provider-listing.test.mjs +114 -0
  213. package/lib/provider-listing.ts +118 -0
  214. package/lib/provider-services.ts +64 -0
  215. package/lib/request-security.test.mjs +256 -0
  216. package/lib/request-security.ts +136 -0
  217. package/lib/rpc-manager-shutdown.test.mjs +372 -0
  218. package/lib/rpc-manager-widgets.test.mjs +342 -0
  219. package/lib/rpc-manager.test.mjs +139 -0
  220. package/lib/rpc-manager.ts +1703 -0
  221. package/lib/rpc-session-info.test.mjs +93 -0
  222. package/lib/session-delete.test.mjs +53 -0
  223. package/lib/session-delete.ts +86 -0
  224. package/lib/session-file-references-core.ts +82 -0
  225. package/lib/session-file-references.test.mjs +91 -0
  226. package/lib/session-file-references.ts +29 -0
  227. package/lib/session-path.test.mjs +24 -0
  228. package/lib/session-path.ts +11 -0
  229. package/lib/session-reader.pagination.test.mjs +115 -0
  230. package/lib/session-reader.test.mjs +446 -0
  231. package/lib/session-reader.ts +548 -0
  232. package/lib/session-resolve.test.mjs +65 -0
  233. package/lib/session-row-context-menu.test.mjs +46 -0
  234. package/lib/session-row-context-menu.ts +29 -0
  235. package/lib/session-scanner.test.mjs +151 -0
  236. package/lib/session-scanner.ts +238 -0
  237. package/lib/session-search.test.mjs +173 -0
  238. package/lib/session-search.ts +284 -0
  239. package/lib/session-stats.ts +26 -0
  240. package/lib/session-timing.test.mjs +107 -0
  241. package/lib/session-timing.ts +45 -0
  242. package/lib/session-title.test.mjs +284 -0
  243. package/lib/session-title.ts +255 -0
  244. package/lib/skill-frontmatter.test.mjs +75 -0
  245. package/lib/skill-frontmatter.ts +40 -0
  246. package/lib/skill-lock.test.mjs +182 -0
  247. package/lib/skill-lock.ts +146 -0
  248. package/lib/skill-updates.test.mjs +182 -0
  249. package/lib/skill-updates.ts +263 -0
  250. package/lib/skills-service.ts +16 -0
  251. package/lib/slash-display.test.mjs +122 -0
  252. package/lib/slash-display.ts +30 -0
  253. package/lib/sqlite-db.test.mjs +140 -0
  254. package/lib/sqlite-db.ts +205 -0
  255. package/lib/startup-preferences.test.mjs +130 -0
  256. package/lib/startup-preferences.ts +65 -0
  257. package/lib/streaming-message.test.mjs +212 -0
  258. package/lib/streaming-message.ts +151 -0
  259. package/lib/subagent-widget.test.mjs +87 -0
  260. package/lib/subagent-widget.ts +109 -0
  261. package/lib/sync-room-server.mjs +137 -0
  262. package/lib/task-card-store.test.mjs +309 -0
  263. package/lib/task-card-store.ts +559 -0
  264. package/lib/task-scheduler.ts +498 -0
  265. package/lib/task-store.test.mjs +216 -0
  266. package/lib/task-store.ts +271 -0
  267. package/lib/terminal-input.test.mjs +46 -0
  268. package/lib/terminal-input.ts +63 -0
  269. package/lib/terminal-manager.test.mjs +71 -0
  270. package/lib/terminal-manager.ts +245 -0
  271. package/lib/tool-execution-progress.test.mjs +32 -0
  272. package/lib/tool-execution-progress.ts +29 -0
  273. package/lib/tool-names.ts +25 -0
  274. package/lib/tool-preset-preference.test.mjs +72 -0
  275. package/lib/tool-preset-preference.ts +41 -0
  276. package/lib/tool-presets.test.mjs +56 -0
  277. package/lib/tool-presets.ts +42 -0
  278. package/lib/turn-written-files.test.mjs +137 -0
  279. package/lib/turn-written-files.ts +60 -0
  280. package/lib/types.ts +349 -0
  281. package/lib/wallpaper-settings.ts +191 -0
  282. package/lib/web-auth.test.mjs +50 -0
  283. package/lib/web-auth.ts +45 -0
  284. package/lib/workspace-memory.test.mjs +129 -0
  285. package/lib/workspace-memory.ts +98 -0
  286. package/lib/worktree.test.mjs +50 -0
  287. package/lib/worktree.ts +250 -0
  288. package/package.json +3 -1
  289. package/server.mjs +34 -0
  290. package/.next/server/chunks/7513.js +0 -30
  291. package/.next/static/chunks/5315.03de3c6abd8b283e.js +0 -4
  292. package/.next/static/css/cf25164cb7c04d95.css +0 -1
  293. /package/.next/static/{Ud6Y2ONkGuPVFbo1xZQvk → EoBw3VYlygpr1EqlVOa5b}/_buildManifest.js +0 -0
  294. /package/.next/static/{Ud6Y2ONkGuPVFbo1xZQvk → EoBw3VYlygpr1EqlVOa5b}/_ssgManifest.js +0 -0
@@ -0,0 +1,182 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import { createJiti } from "jiti";
7
+
8
+ const jiti = createJiti(import.meta.url);
9
+ const { annotateSkillsWithInstallInfo, getGlobalSkillsLockPath } =
10
+ await jiti.import("./skill-lock.ts");
11
+
12
+ function writeJson(path, value) {
13
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`, "utf8");
14
+ }
15
+
16
+ function makeSkill(name, filePath, scope) {
17
+ return {
18
+ name,
19
+ description: `${name} description`,
20
+ filePath,
21
+ baseDir: filePath.slice(0, -"/SKILL.md".length),
22
+ disableModelInvocation: false,
23
+ sourceInfo: { scope },
24
+ };
25
+ }
26
+
27
+ test("uses the CLI global lock location", () => {
28
+ assert.equal(
29
+ getGlobalSkillsLockPath({ homeDir: "/home/test", xdgStateHome: undefined }),
30
+ join("/home/test", ".agents", ".skill-lock.json"),
31
+ );
32
+ assert.equal(
33
+ getGlobalSkillsLockPath({ homeDir: "/home/test", xdgStateHome: "/state" }),
34
+ join("/state", "skills", ".skill-lock.json"),
35
+ );
36
+ });
37
+
38
+ test("annotates only lock entries that exist in the matching Pi scope", () => {
39
+ const root = mkdtempSync(join(tmpdir(), "pi-web-skill-lock-"));
40
+ try {
41
+ const cwd = join(root, "project");
42
+ const agentDir = join(root, "home", ".pi", "agent");
43
+ const globalLockPath = join(root, "global-lock.json");
44
+ const projectLockPath = join(cwd, "skills-lock.json");
45
+ const globalSkillPath = join(agentDir, "skills", "edge-tts", "SKILL.md");
46
+ const projectSkillPath = join(cwd, ".pi", "skills", "find-skills", "SKILL.md");
47
+ const manualSkillPath = join(agentDir, "skills", "manual", "SKILL.md");
48
+ const otherAgentSkillPath = join(root, "other-agent", "tts", "SKILL.md");
49
+
50
+ for (const path of [globalSkillPath, projectSkillPath, manualSkillPath, otherAgentSkillPath]) {
51
+ mkdirSync(join(path, ".."), { recursive: true });
52
+ writeFileSync(path, "---\nname: test\n---\n", "utf8");
53
+ }
54
+
55
+ writeJson(globalLockPath, {
56
+ version: 3,
57
+ skills: {
58
+ "edge-tts": {
59
+ source: "https://github.com/aahl/skills.git",
60
+ sourceType: "github",
61
+ skillPath: "skills/edge-tts/SKILL.md",
62
+ skillFolderHash: "global-version",
63
+ },
64
+ tts: { source: "noizai/skills", sourceType: "github" },
65
+ },
66
+ });
67
+ writeJson(projectLockPath, {
68
+ version: 1,
69
+ skills: {
70
+ "find-skills": {
71
+ source: "vercel-labs/skills",
72
+ sourceType: "github",
73
+ skillPath: "skills/find-skills/SKILL.md",
74
+ computedHash: "project-version",
75
+ },
76
+ },
77
+ });
78
+
79
+ const annotated = annotateSkillsWithInstallInfo(
80
+ [
81
+ makeSkill("edge-tts", globalSkillPath, "user"),
82
+ makeSkill("find-skills", projectSkillPath, "project"),
83
+ makeSkill("manual", manualSkillPath, "user"),
84
+ makeSkill("tts", otherAgentSkillPath, "user"),
85
+ ],
86
+ { cwd, agentDir, globalLockPath, projectLockPath },
87
+ );
88
+
89
+ assert.deepEqual(annotated[0].install, {
90
+ package: "aahl/skills@edge-tts",
91
+ scope: "global",
92
+ source: "aahl/skills",
93
+ sourceType: "github",
94
+ skillsShUrl: "https://skills.sh/aahl/skills/edge-tts",
95
+ skillPath: "skills/edge-tts/SKILL.md",
96
+ versionHash: "global-version",
97
+ canCheckForUpdates: true,
98
+ });
99
+ assert.deepEqual(annotated[1].install, {
100
+ package: "vercel-labs/skills@find-skills",
101
+ scope: "project",
102
+ source: "vercel-labs/skills",
103
+ sourceType: "github",
104
+ skillsShUrl: "https://skills.sh/vercel-labs/skills/find-skills",
105
+ skillPath: "skills/find-skills/SKILL.md",
106
+ versionHash: "project-version",
107
+ canCheckForUpdates: true,
108
+ });
109
+ assert.equal(annotated[2].install, undefined);
110
+ assert.equal(annotated[3].install, undefined);
111
+ } finally {
112
+ rmSync(root, { recursive: true, force: true });
113
+ }
114
+ });
115
+
116
+ test("ignores stale lock entries and malformed lock files", () => {
117
+ const root = mkdtempSync(join(tmpdir(), "pi-web-skill-lock-"));
118
+ try {
119
+ const cwd = join(root, "project");
120
+ const agentDir = join(root, "agent");
121
+ const missingPath = join(agentDir, "skills", "missing", "SKILL.md");
122
+ const projectSkillPath = join(cwd, ".pi", "skills", "broken", "SKILL.md");
123
+ const globalLockPath = join(root, "global-lock.json");
124
+ const projectLockPath = join(root, "project-lock.json");
125
+ mkdirSync(join(projectSkillPath, ".."), { recursive: true });
126
+ writeFileSync(projectSkillPath, "---\nname: broken\n---\n", "utf8");
127
+ writeJson(globalLockPath, {
128
+ version: 3,
129
+ skills: {
130
+ missing: { source: "owner/repo", sourceType: "github" },
131
+ },
132
+ });
133
+ writeFileSync(projectLockPath, "not json", "utf8");
134
+
135
+ const skills = annotateSkillsWithInstallInfo(
136
+ [
137
+ makeSkill("missing", missingPath, "user"),
138
+ makeSkill("broken", projectSkillPath, "project"),
139
+ ],
140
+ { cwd, agentDir, globalLockPath, projectLockPath },
141
+ );
142
+
143
+ assert.equal(skills[0].install, undefined);
144
+ assert.equal(skills[1].install, undefined);
145
+ } finally {
146
+ rmSync(root, { recursive: true, force: true });
147
+ }
148
+ });
149
+
150
+ test("does not compare a project ref with the default skills.sh snapshot", () => {
151
+ const root = mkdtempSync(join(tmpdir(), "pi-web-skill-lock-"));
152
+ try {
153
+ const cwd = join(root, "project");
154
+ const agentDir = join(root, "agent");
155
+ const projectLockPath = join(cwd, "skills-lock.json");
156
+ const projectSkillPath = join(cwd, ".pi", "skills", "preview", "SKILL.md");
157
+ mkdirSync(join(projectSkillPath, ".."), { recursive: true });
158
+ writeFileSync(projectSkillPath, "---\nname: preview\n---\n", "utf8");
159
+ writeJson(projectLockPath, {
160
+ version: 1,
161
+ skills: {
162
+ preview: {
163
+ source: "owner/repo",
164
+ sourceType: "github",
165
+ skillPath: "skills/preview/SKILL.md",
166
+ ref: "preview",
167
+ computedHash: "project-version",
168
+ },
169
+ },
170
+ });
171
+
172
+ const [skill] = annotateSkillsWithInstallInfo(
173
+ [makeSkill("preview", projectSkillPath, "project")],
174
+ { cwd, agentDir, projectLockPath, globalLockPath: join(root, "missing.json") },
175
+ );
176
+
177
+ assert.equal(skill.install.ref, "preview");
178
+ assert.equal(skill.install.canCheckForUpdates, false);
179
+ } finally {
180
+ rmSync(root, { recursive: true, force: true });
181
+ }
182
+ });
@@ -0,0 +1,146 @@
1
+ import { existsSync, readFileSync } from "fs";
2
+ import { homedir } from "os";
3
+ import { isAbsolute, join, relative, resolve, sep } from "path";
4
+ import type { SkillInfo, SkillInstallInfo, SkillInstallScope } from "@/lib/api-types";
5
+
6
+ interface SkillLockEntry {
7
+ source?: unknown;
8
+ sourceType?: unknown;
9
+ skillPath?: unknown;
10
+ ref?: unknown;
11
+ skillFolderHash?: unknown;
12
+ computedHash?: unknown;
13
+ }
14
+
15
+ interface SkillLockFile {
16
+ skills?: Record<string, SkillLockEntry>;
17
+ }
18
+
19
+ interface GlobalLockPathOptions {
20
+ homeDir?: string;
21
+ xdgStateHome?: string;
22
+ }
23
+
24
+ interface AnnotateSkillOptions {
25
+ cwd: string;
26
+ agentDir: string;
27
+ globalLockPath?: string;
28
+ projectLockPath?: string;
29
+ }
30
+
31
+ export function getGlobalSkillsLockPath({
32
+ homeDir = homedir(),
33
+ xdgStateHome = process.env.XDG_STATE_HOME,
34
+ }: GlobalLockPathOptions = {}): string {
35
+ return xdgStateHome
36
+ ? join(xdgStateHome, "skills", ".skill-lock.json")
37
+ : join(homeDir, ".agents", ".skill-lock.json");
38
+ }
39
+
40
+ function readSkillLock(path: string): Record<string, SkillLockEntry> {
41
+ try {
42
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as SkillLockFile;
43
+ return parsed.skills && typeof parsed.skills === "object" ? parsed.skills : {};
44
+ } catch {
45
+ return {};
46
+ }
47
+ }
48
+
49
+ function isWithin(path: string, root: string): boolean {
50
+ const rel = relative(resolve(root), resolve(path));
51
+ return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
52
+ }
53
+
54
+ function findLockEntry(
55
+ entries: Record<string, SkillLockEntry>,
56
+ skillName: string,
57
+ ): SkillLockEntry | undefined {
58
+ if (entries[skillName]) return entries[skillName];
59
+ const normalizedName = skillName.toLowerCase();
60
+ const key = Object.keys(entries).find((name) => name.toLowerCase() === normalizedName);
61
+ return key ? entries[key] : undefined;
62
+ }
63
+
64
+ function normalizeSource(source: string, sourceType?: string): string {
65
+ if (sourceType !== "github") return source.replace(/\/$/, "");
66
+ return source
67
+ .replace(/^git\+/, "")
68
+ .replace(/^https?:\/\/github\.com\//, "")
69
+ .replace(/^git@github\.com:/, "")
70
+ .replace(/\.git$/, "")
71
+ .replace(/\/$/, "");
72
+ }
73
+
74
+ function buildSkillsShUrl(source: string, skillName: string): string | undefined {
75
+ if (!source || source.includes("://") || source.startsWith("git@")) return undefined;
76
+ const sourcePath = source
77
+ .split("/")
78
+ .filter(Boolean)
79
+ .map(encodeURIComponent)
80
+ .join("/");
81
+ if (!sourcePath) return undefined;
82
+ return `https://skills.sh/${sourcePath}/${encodeURIComponent(skillName)}`;
83
+ }
84
+
85
+ function getInstallInfo(
86
+ entries: Record<string, SkillLockEntry>,
87
+ skillName: string,
88
+ scope: SkillInstallScope,
89
+ ): SkillInstallInfo | undefined {
90
+ const entry = findLockEntry(entries, skillName);
91
+ if (!entry || typeof entry.source !== "string" || !entry.source.trim()) return undefined;
92
+
93
+ const sourceType = typeof entry.sourceType === "string" ? entry.sourceType : undefined;
94
+ const source = normalizeSource(entry.source.trim(), sourceType);
95
+ if (!source) return undefined;
96
+ const skillPath = typeof entry.skillPath === "string" ? entry.skillPath : undefined;
97
+ const ref = typeof entry.ref === "string" ? entry.ref : undefined;
98
+ const rawVersionHash = scope === "global" ? entry.skillFolderHash : entry.computedHash;
99
+ const versionHash = typeof rawVersionHash === "string" && rawVersionHash
100
+ ? rawVersionHash
101
+ : undefined;
102
+ const isGitHubSource =
103
+ sourceType === "github" && /^[\w.-]+\/[\w.-]+$/.test(source);
104
+ const hasComparableVersion = scope === "global" || !ref;
105
+
106
+ return {
107
+ package: `${source}@${skillName}`,
108
+ scope,
109
+ source,
110
+ sourceType,
111
+ skillsShUrl: sourceType === "local" ? undefined : buildSkillsShUrl(source, skillName),
112
+ ...(skillPath && { skillPath }),
113
+ ...(ref && { ref }),
114
+ ...(versionHash && { versionHash }),
115
+ canCheckForUpdates: Boolean(
116
+ isGitHubSource && skillPath && versionHash && hasComparableVersion,
117
+ ),
118
+ };
119
+ }
120
+
121
+ export function annotateSkillsWithInstallInfo(
122
+ skills: SkillInfo[],
123
+ {
124
+ cwd,
125
+ agentDir,
126
+ globalLockPath = getGlobalSkillsLockPath(),
127
+ projectLockPath = join(cwd, "skills-lock.json"),
128
+ }: AnnotateSkillOptions,
129
+ ): SkillInfo[] {
130
+ const globalEntries = readSkillLock(globalLockPath);
131
+ const projectEntries = readSkillLock(projectLockPath);
132
+ const globalSkillsRoot = join(agentDir, "skills");
133
+ const projectSkillsRoot = join(cwd, ".pi", "skills");
134
+
135
+ return skills.map((skill) => {
136
+ if (!existsSync(skill.filePath)) return skill;
137
+
138
+ const install = isWithin(skill.filePath, globalSkillsRoot)
139
+ ? getInstallInfo(globalEntries, skill.name, "global")
140
+ : isWithin(skill.filePath, projectSkillsRoot)
141
+ ? getInstallInfo(projectEntries, skill.name, "project")
142
+ : undefined;
143
+
144
+ return install ? { ...skill, install } : skill;
145
+ });
146
+ }
@@ -0,0 +1,182 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createJiti } from "jiti";
4
+
5
+ const jiti = createJiti(import.meta.url);
6
+ const {
7
+ buildSkillUpdateArgs,
8
+ checkSkillUpdate,
9
+ checkSkillUpdates,
10
+ skillUpdateKey,
11
+ } = await jiti.import("./skill-updates.ts");
12
+
13
+ function install(overrides = {}) {
14
+ return {
15
+ package: "owner/repo@example-skill",
16
+ scope: "global",
17
+ source: "owner/repo",
18
+ sourceType: "github",
19
+ skillsShUrl: "https://skills.sh/owner/repo/example-skill",
20
+ skillPath: "skills/example-skill/SKILL.md",
21
+ versionHash: "current-hash",
22
+ canCheckForUpdates: true,
23
+ ...overrides,
24
+ };
25
+ }
26
+
27
+ function jsonResponse(value, status = 200) {
28
+ return new Response(JSON.stringify(value), {
29
+ status,
30
+ headers: { "Content-Type": "application/json" },
31
+ });
32
+ }
33
+
34
+ test("compares a global lock version with the remote Git tree", async () => {
35
+ const seen = [];
36
+ const upToDate = await checkSkillUpdate(install(), {
37
+ fetcher: async (url) => {
38
+ seen.push(url);
39
+ return jsonResponse({
40
+ sha: "root-hash",
41
+ tree: [{ type: "tree", path: "skills/example-skill", sha: "current-hash" }],
42
+ });
43
+ },
44
+ });
45
+
46
+ assert.equal(upToDate.state, "up-to-date");
47
+ assert.equal(upToDate.latestVersion, "current-hash");
48
+ assert.match(seen[0], /repos\/owner\/repo\/git\/trees\/HEAD/);
49
+
50
+ const available = await checkSkillUpdate(install(), {
51
+ fetcher: async () => jsonResponse({
52
+ sha: "root-hash",
53
+ tree: [{ type: "tree", path: "skills/example-skill", sha: "next-hash" }],
54
+ }),
55
+ });
56
+ assert.equal(available.state, "update-available");
57
+ assert.equal(available.currentVersion, "current-hash");
58
+ assert.equal(available.latestVersion, "next-hash");
59
+ });
60
+
61
+ test("uses the repository hash for a root global skill", async () => {
62
+ const result = await checkSkillUpdate(install({ skillPath: "SKILL.md" }), {
63
+ fetcher: async () => jsonResponse({ sha: "next-root", tree: [] }),
64
+ });
65
+
66
+ assert.equal(result.state, "update-available");
67
+ assert.equal(result.latestVersion, "next-root");
68
+ });
69
+
70
+ test("compares a project lock version with the skills.sh snapshot", async () => {
71
+ let requestedUrl = "";
72
+ const result = await checkSkillUpdate(install({ scope: "project" }), {
73
+ skillsApiBase: "https://skills.test",
74
+ fetcher: async (url) => {
75
+ requestedUrl = url;
76
+ return jsonResponse({ hash: "current-hash" });
77
+ },
78
+ });
79
+
80
+ assert.equal(result.state, "up-to-date");
81
+ assert.equal(
82
+ requestedUrl,
83
+ "https://skills.test/api/download/owner/repo/example-skill",
84
+ );
85
+ });
86
+
87
+ test("returns unsupported without making a remote request", async () => {
88
+ let called = false;
89
+ const result = await checkSkillUpdate(
90
+ install({ canCheckForUpdates: false, versionHash: undefined }),
91
+ { fetcher: async () => { called = true; return jsonResponse({}); } },
92
+ );
93
+
94
+ assert.equal(result.state, "unsupported");
95
+ assert.equal(called, false);
96
+ });
97
+
98
+ test("returns a scoped error when the remote check fails", async () => {
99
+ const result = await checkSkillUpdate(install(), {
100
+ fetcher: async () => jsonResponse({}, 503),
101
+ });
102
+
103
+ assert.equal(result.state, "error");
104
+ assert.equal(result.message, "HTTP 503");
105
+ assert.equal(skillUpdateKey(install()), "global\0owner/repo@example-skill");
106
+ });
107
+
108
+ test("falls back to Git when the GitHub API is rate limited", async () => {
109
+ let resolved = false;
110
+ const result = await checkSkillUpdate(install(), {
111
+ fetcher: async () => jsonResponse({}, 403),
112
+ resolveGitTreeHash: async () => {
113
+ resolved = true;
114
+ return "next-hash";
115
+ },
116
+ });
117
+
118
+ assert.equal(resolved, true);
119
+ assert.equal(result.state, "update-available");
120
+ assert.equal(result.latestVersion, "next-hash");
121
+ });
122
+
123
+ test("builds Pi-only update commands for each scope", () => {
124
+ assert.deepEqual(buildSkillUpdateArgs(install()), [
125
+ "skills",
126
+ "add",
127
+ "owner/repo/skills/example-skill",
128
+ "--skill",
129
+ "example-skill",
130
+ "-y",
131
+ "--agent",
132
+ "pi",
133
+ "-g",
134
+ ]);
135
+ assert.deepEqual(buildSkillUpdateArgs(install({ scope: "project" })), [
136
+ "skills",
137
+ "add",
138
+ "owner/repo/skills/example-skill",
139
+ "--skill",
140
+ "example-skill",
141
+ "-y",
142
+ "--agent",
143
+ "pi",
144
+ ]);
145
+ assert.deepEqual(buildSkillUpdateArgs(install({ ref: "release/v2" })), [
146
+ "skills",
147
+ "add",
148
+ "owner/repo/skills/example-skill#release%2Fv2",
149
+ "--skill",
150
+ "example-skill",
151
+ "-y",
152
+ "--agent",
153
+ "pi",
154
+ "-g",
155
+ ]);
156
+ });
157
+
158
+ test("reuses one remote request for skills from the same GitHub source", async () => {
159
+ let requests = 0;
160
+ const results = await checkSkillUpdates([
161
+ install(),
162
+ install({
163
+ package: "owner/repo@another-skill",
164
+ skillPath: "skills/another-skill/SKILL.md",
165
+ versionHash: "another-hash",
166
+ }),
167
+ ], {
168
+ fetcher: async () => {
169
+ requests++;
170
+ return jsonResponse({
171
+ sha: "root-hash",
172
+ tree: [
173
+ { type: "tree", path: "skills/example-skill", sha: "current-hash" },
174
+ { type: "tree", path: "skills/another-skill", sha: "another-hash" },
175
+ ],
176
+ });
177
+ },
178
+ });
179
+
180
+ assert.equal(requests, 1);
181
+ assert.deepEqual(results.map((item) => item.state), ["up-to-date", "up-to-date"]);
182
+ });