@thevinci/web 1.0.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/README.md +197 -0
- package/bin/cli-entry.js +55 -0
- package/bin/cli-output.js +145 -0
- package/bin/cli.js +4887 -0
- package/bin/cli.test.js +64 -0
- package/dist/apple-touch-icon-120x120.png +0 -0
- package/dist/apple-touch-icon-152x152.png +0 -0
- package/dist/apple-touch-icon-167x167.png +0 -0
- package/dist/apple-touch-icon-180x180.png +0 -0
- package/dist/apple-touch-icon.png +0 -0
- package/dist/apple-touch-icon.svg +528 -0
- package/dist/assets/JsonTreeView-CSm9OzXG.js +1 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/MarkdownRendererImpl-DensKOLc.js +6 -0
- package/dist/assets/MultiRunWindow-Bo7THayo.js +1 -0
- package/dist/assets/OnboardingScreen-BDqmzTVR.js +2 -0
- package/dist/assets/SettingsWindow-coz__Ykw.js +1 -0
- package/dist/assets/TerminalView-DrZ-i3Dr.js +1 -0
- package/dist/assets/ToolOutputDialog-Eglzslt3.js +16 -0
- package/dist/assets/es-4o9ciP61.js +15 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/dist/assets/index-DLTDToSP.css +1 -0
- package/dist/assets/index-DgiFEKGN.js +1 -0
- package/dist/assets/ko-B20imCHE.js +15 -0
- package/dist/assets/main-BV3KOtdA.css +1 -0
- package/dist/assets/main-CDKJj0sH.js +226 -0
- package/dist/assets/main-LC-PSNVM.js +2 -0
- package/dist/assets/miniChat-CQUiG_cr.js +2 -0
- package/dist/assets/modelPrefsAutoSave-Dm799vzR.js +6986 -0
- package/dist/assets/pl-DQJ7LSzj.js +15 -0
- package/dist/assets/pt-BR-OmjHUz9y.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-CARbeW0G.js +2 -0
- package/dist/assets/uk-BNFxOlO4.js +15 -0
- package/dist/assets/vendor--DBfsbEis.css +1 -0
- package/dist/assets/vendor-.bun-B9l0ZNi2.js +4094 -0
- package/dist/assets/wasm-CG6Dc4jp.js +1 -0
- package/dist/assets/wasmSttWorker-Dtlxac_K.js +1 -0
- package/dist/assets/wasmSttWorker-oo7Dm_jy.js +1806 -0
- package/dist/assets/worker-CbT6TVo7.js +155 -0
- package/dist/assets/zh-CN-C6T-Ac7F.js +15 -0
- package/dist/favicon-16.png +0 -0
- package/dist/favicon-32.png +0 -0
- package/dist/favicon.png +0 -0
- package/dist/favicon.svg +528 -0
- package/dist/index.html +607 -0
- package/dist/logo-dark-192x192.png +0 -0
- package/dist/logo-dark-512x512.png +0 -0
- package/dist/logo-dark-512x512.svg +528 -0
- package/dist/logo-light-192x192.png +0 -0
- package/dist/logo-light-512x512.png +0 -0
- package/dist/logo-light-512x512.svg +528 -0
- package/dist/mini-chat.html +16 -0
- package/dist/pwa-192.png +0 -0
- package/dist/pwa-512.png +0 -0
- package/dist/pwa-maskable-192.png +0 -0
- package/dist/pwa-maskable-512.png +0 -0
- package/dist/site.webmanifest +21 -0
- package/dist/sw.js +1 -0
- package/package.json +118 -0
- package/public/apple-touch-icon-120x120.png +0 -0
- package/public/apple-touch-icon-152x152.png +0 -0
- package/public/apple-touch-icon-167x167.png +0 -0
- package/public/apple-touch-icon-180x180.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/apple-touch-icon.svg +528 -0
- package/public/favicon-16.png +0 -0
- package/public/favicon-32.png +0 -0
- package/public/favicon.png +0 -0
- package/public/favicon.svg +528 -0
- package/public/logo-dark-192x192.png +0 -0
- package/public/logo-dark-512x512.png +0 -0
- package/public/logo-dark-512x512.svg +528 -0
- package/public/logo-light-192x192.png +0 -0
- package/public/logo-light-512x512.png +0 -0
- package/public/logo-light-512x512.svg +528 -0
- package/public/pwa-192.png +0 -0
- package/public/pwa-512.png +0 -0
- package/public/pwa-maskable-192.png +0 -0
- package/public/pwa-maskable-512.png +0 -0
- package/public/site.webmanifest +21 -0
- package/server/TERMINAL_WS_PROTOCOL.md +48 -0
- package/server/index.d.ts +39 -0
- package/server/index.js +1311 -0
- package/server/lib/cloudflare-tunnel.js +650 -0
- package/server/lib/event-stream/DOCUMENTATION.md +61 -0
- package/server/lib/event-stream/directory-ws-bridge.js +185 -0
- package/server/lib/event-stream/global-hub.js +158 -0
- package/server/lib/event-stream/global-hub.test.js +140 -0
- package/server/lib/event-stream/global-ws-bridge.js +206 -0
- package/server/lib/event-stream/index.js +25 -0
- package/server/lib/event-stream/protocol.js +131 -0
- package/server/lib/event-stream/protocol.test.js +182 -0
- package/server/lib/event-stream/runtime.js +180 -0
- package/server/lib/event-stream/runtime.test.js +512 -0
- package/server/lib/event-stream/upstream-reader.js +226 -0
- package/server/lib/event-stream/upstream-reader.test.js +276 -0
- package/server/lib/fs/DOCUMENTATION.md +36 -0
- package/server/lib/fs/routes.js +1040 -0
- package/server/lib/fs/search.js +238 -0
- package/server/lib/git/DOCUMENTATION.md +152 -0
- package/server/lib/git/credentials.js +74 -0
- package/server/lib/git/identity-storage.js +112 -0
- package/server/lib/git/index.js +6 -0
- package/server/lib/git/routes.js +972 -0
- package/server/lib/git/service.js +3432 -0
- package/server/lib/git/service.test.js +39 -0
- package/server/lib/github/DOCUMENTATION.md +171 -0
- package/server/lib/github/auth.js +307 -0
- package/server/lib/github/device-flow.js +50 -0
- package/server/lib/github/index.js +24 -0
- package/server/lib/github/octokit.js +10 -0
- package/server/lib/github/pr-status.js +519 -0
- package/server/lib/github/repo/fork-detection.js +102 -0
- package/server/lib/github/repo/index.js +55 -0
- package/server/lib/github/routes.js +1560 -0
- package/server/lib/magic-prompts/routes.js +63 -0
- package/server/lib/magic-prompts/runtime.js +119 -0
- package/server/lib/notifications/DOCUMENTATION.md +122 -0
- package/server/lib/notifications/emitter-runtime.js +102 -0
- package/server/lib/notifications/index.js +4 -0
- package/server/lib/notifications/message.js +52 -0
- package/server/lib/notifications/message.test.js +34 -0
- package/server/lib/notifications/push-runtime.js +304 -0
- package/server/lib/notifications/routes.js +315 -0
- package/server/lib/notifications/runtime.js +566 -0
- package/server/lib/notifications/template-runtime.js +349 -0
- package/server/lib/notifications/template-runtime.test.js +26 -0
- package/server/lib/opencode/DOCUMENTATION.md +362 -0
- package/server/lib/opencode/agents.js +634 -0
- package/server/lib/opencode/auth-state-runtime.js +88 -0
- package/server/lib/opencode/auth.js +83 -0
- package/server/lib/opencode/bootstrap-runtime.js +131 -0
- package/server/lib/opencode/cli-entry-runtime.js +43 -0
- package/server/lib/opencode/cli-options.js +128 -0
- package/server/lib/opencode/commands.js +339 -0
- package/server/lib/opencode/config-entity-routes.js +370 -0
- package/server/lib/opencode/core-routes.js +500 -0
- package/server/lib/opencode/core-routes.test.js +26 -0
- package/server/lib/opencode/env-config.js +74 -0
- package/server/lib/opencode/env-keys.js +68 -0
- package/server/lib/opencode/env-runtime.js +1162 -0
- package/server/lib/opencode/env-runtime.test.js +116 -0
- package/server/lib/opencode/feature-routes-runtime.js +244 -0
- package/server/lib/opencode/hmr-state-runtime.js +85 -0
- package/server/lib/opencode/index.js +66 -0
- package/server/lib/opencode/lifecycle.js +1019 -0
- package/server/lib/opencode/lifecycle.test.js +240 -0
- package/server/lib/opencode/mcp.js +278 -0
- package/server/lib/opencode/network-runtime.js +104 -0
- package/server/lib/opencode/network-runtime.test.js +37 -0
- package/server/lib/opencode/opencode-resolution-runtime.js +71 -0
- package/server/lib/opencode/path-utils.js +100 -0
- package/server/lib/opencode/path-utils.test.js +71 -0
- package/server/lib/opencode/project-directory-runtime.js +124 -0
- package/server/lib/opencode/project-icon-routes.js +399 -0
- package/server/lib/opencode/project-icon-routes.test.js +107 -0
- package/server/lib/opencode/providers.js +96 -0
- package/server/lib/opencode/proxy.js +445 -0
- package/server/lib/opencode/pwa-manifest-routes.js +257 -0
- package/server/lib/opencode/pwa-manifest-routes.test.js +133 -0
- package/server/lib/opencode/routes.js +541 -0
- package/server/lib/opencode/server-startup-runtime.js +156 -0
- package/server/lib/opencode/server-utils-runtime.js +168 -0
- package/server/lib/opencode/server-utils-runtime.test.js +135 -0
- package/server/lib/opencode/session-runtime.js +356 -0
- package/server/lib/opencode/session-runtime.test.js +151 -0
- package/server/lib/opencode/settings-helpers.js +770 -0
- package/server/lib/opencode/settings-helpers.test.js +109 -0
- package/server/lib/opencode/settings-normalization-runtime.js +428 -0
- package/server/lib/opencode/settings-runtime.js +826 -0
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +615 -0
- package/server/lib/opencode/shutdown-runtime.js +139 -0
- package/server/lib/opencode/shutdown-runtime.test.js +58 -0
- package/server/lib/opencode/skill-routes.js +701 -0
- package/server/lib/opencode/skills.js +548 -0
- package/server/lib/opencode/startup-pipeline-runtime.js +130 -0
- package/server/lib/opencode/static-routes-runtime.js +65 -0
- package/server/lib/opencode/theme-runtime.js +167 -0
- package/server/lib/opencode/tunnel-auth.js +591 -0
- package/server/lib/opencode/tunnel-wiring-runtime.js +94 -0
- package/server/lib/opencode/vinci-routes.js +76 -0
- package/server/lib/opencode/watcher.js +115 -0
- package/server/lib/opencode/watcher.test.js +239 -0
- package/server/lib/preview/proxy-runtime.js +1333 -0
- package/server/lib/preview/proxy-runtime.test.js +144 -0
- package/server/lib/projects/project-config.js +567 -0
- package/server/lib/projects/project-config.test.js +175 -0
- package/server/lib/projects/project-id.js +13 -0
- package/server/lib/quota/DOCUMENTATION.md +58 -0
- package/server/lib/quota/index.js +25 -0
- package/server/lib/quota/providers/claude.js +107 -0
- package/server/lib/quota/providers/codex.js +113 -0
- package/server/lib/quota/providers/copilot.js +165 -0
- package/server/lib/quota/providers/google/api.js +92 -0
- package/server/lib/quota/providers/google/auth.js +108 -0
- package/server/lib/quota/providers/google/index.js +124 -0
- package/server/lib/quota/providers/google/transforms.js +109 -0
- package/server/lib/quota/providers/index.js +168 -0
- package/server/lib/quota/providers/interface.js +55 -0
- package/server/lib/quota/providers/kimi.js +108 -0
- package/server/lib/quota/providers/minimax-cn-coding-plan.js +140 -0
- package/server/lib/quota/providers/minimax-coding-plan.js +139 -0
- package/server/lib/quota/providers/nanogpt.js +124 -0
- package/server/lib/quota/providers/ollama-cloud.js +112 -0
- package/server/lib/quota/providers/openai.js +91 -0
- package/server/lib/quota/providers/openrouter.js +92 -0
- package/server/lib/quota/providers/zai.js +91 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +133 -0
- package/server/lib/quota/providers/zhipuai.js +114 -0
- package/server/lib/quota/routes.js +27 -0
- package/server/lib/quota/utils/auth.js +50 -0
- package/server/lib/quota/utils/formatters.js +85 -0
- package/server/lib/quota/utils/formatters.test.js +54 -0
- package/server/lib/quota/utils/index.js +10 -0
- package/server/lib/quota/utils/transformers.js +55 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +44 -0
- package/server/lib/scheduled-tasks/routes.js +235 -0
- package/server/lib/scheduled-tasks/runtime.js +773 -0
- package/server/lib/scheduled-tasks/runtime.test.js +100 -0
- package/server/lib/security/request-security.js +115 -0
- package/server/lib/session-folders/routes.js +63 -0
- package/server/lib/session-folders/routes.test.js +102 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +178 -0
- package/server/lib/skills-catalog/cache.js +29 -0
- package/server/lib/skills-catalog/clawdhub/api.js +158 -0
- package/server/lib/skills-catalog/clawdhub/index.js +30 -0
- package/server/lib/skills-catalog/clawdhub/install.js +238 -0
- package/server/lib/skills-catalog/clawdhub/scan.js +113 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -0
- package/server/lib/skills-catalog/git.js +77 -0
- package/server/lib/skills-catalog/index.js +42 -0
- package/server/lib/skills-catalog/install.js +294 -0
- package/server/lib/skills-catalog/scan.js +221 -0
- package/server/lib/skills-catalog/source.js +87 -0
- package/server/lib/terminal/DOCUMENTATION.md +76 -0
- package/server/lib/terminal/index.js +31 -0
- package/server/lib/terminal/output-replay-buffer.js +78 -0
- package/server/lib/terminal/output-replay-buffer.test.js +75 -0
- package/server/lib/terminal/runtime.js +850 -0
- package/server/lib/terminal/runtime.test.js +96 -0
- package/server/lib/terminal/terminal-ws-protocol.js +68 -0
- package/server/lib/terminal/terminal-ws-protocol.test.js +145 -0
- package/server/lib/text/DOCUMENTATION.md +35 -0
- package/server/lib/text/summarization.js +138 -0
- package/server/lib/text/summarization.test.js +34 -0
- package/server/lib/tts/DOCUMENTATION.md +146 -0
- package/server/lib/tts/base-url.js +62 -0
- package/server/lib/tts/capability-runtime.js +31 -0
- package/server/lib/tts/index.js +19 -0
- package/server/lib/tts/routes.js +261 -0
- package/server/lib/tts/routes.test.js +53 -0
- package/server/lib/tts/service.js +178 -0
- package/server/lib/tts/stt.js +75 -0
- package/server/lib/tunnels/DOCUMENTATION.md +18 -0
- package/server/lib/tunnels/index.js +166 -0
- package/server/lib/tunnels/managed-config.js +201 -0
- package/server/lib/tunnels/providers/cloudflare.js +260 -0
- package/server/lib/tunnels/registry.js +51 -0
- package/server/lib/tunnels/routes.js +605 -0
- package/server/lib/tunnels/types.js +219 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +38 -0
- package/server/lib/ui-auth/ui-auth.js +673 -0
- package/server/lib/ui-auth/ui-passkeys.js +545 -0
- package/server/opencode-proxy.test.js +151 -0
- package/server/proxy-headers.js +61 -0
- package/server/proxy-headers.test.js +58 -0
- package/server/sse-routes.test.js +152 -0
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import {
|
|
5
|
+
SKILL_DIR,
|
|
6
|
+
OPENCODE_CONFIG_DIR,
|
|
7
|
+
SKILL_SCOPE,
|
|
8
|
+
ensureDirs,
|
|
9
|
+
parseMdFile,
|
|
10
|
+
writeMdFile,
|
|
11
|
+
readConfigLayers,
|
|
12
|
+
readConfig,
|
|
13
|
+
walkSkillMdFiles,
|
|
14
|
+
addSkillFromMdFile,
|
|
15
|
+
resolveSkillSearchDirectories,
|
|
16
|
+
listSkillSupportingFiles,
|
|
17
|
+
readSkillSupportingFile,
|
|
18
|
+
writeSkillSupportingFile,
|
|
19
|
+
deleteSkillSupportingFile,
|
|
20
|
+
getAncestors,
|
|
21
|
+
findWorktreeRoot,
|
|
22
|
+
} from './shared.js';
|
|
23
|
+
|
|
24
|
+
function ensureProjectSkillDir(workingDirectory) {
|
|
25
|
+
const projectSkillDir = path.join(workingDirectory, '.opencode', 'skills');
|
|
26
|
+
if (!fs.existsSync(projectSkillDir)) {
|
|
27
|
+
fs.mkdirSync(projectSkillDir, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
const legacyProjectSkillDir = path.join(workingDirectory, '.opencode', 'skill');
|
|
30
|
+
if (!fs.existsSync(legacyProjectSkillDir)) {
|
|
31
|
+
fs.mkdirSync(legacyProjectSkillDir, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
return projectSkillDir;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getProjectSkillDir(workingDirectory, skillName) {
|
|
37
|
+
const pluralPath = path.join(workingDirectory, '.opencode', 'skills', skillName);
|
|
38
|
+
const legacyPath = path.join(workingDirectory, '.opencode', 'skill', skillName);
|
|
39
|
+
if (fs.existsSync(legacyPath) && !fs.existsSync(pluralPath)) return legacyPath;
|
|
40
|
+
return pluralPath;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getProjectSkillPath(workingDirectory, skillName) {
|
|
44
|
+
const pluralPath = path.join(workingDirectory, '.opencode', 'skills', skillName, 'SKILL.md');
|
|
45
|
+
const legacyPath = path.join(workingDirectory, '.opencode', 'skill', skillName, 'SKILL.md');
|
|
46
|
+
if (fs.existsSync(legacyPath) && !fs.existsSync(pluralPath)) return legacyPath;
|
|
47
|
+
return pluralPath;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getUserSkillDir(skillName) {
|
|
51
|
+
const pluralPath = path.join(SKILL_DIR, skillName);
|
|
52
|
+
const legacyPath = path.join(OPENCODE_CONFIG_DIR, 'skill', skillName);
|
|
53
|
+
if (fs.existsSync(legacyPath) && !fs.existsSync(pluralPath)) return legacyPath;
|
|
54
|
+
return pluralPath;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getUserSkillPath(skillName) {
|
|
58
|
+
const pluralPath = path.join(SKILL_DIR, skillName, 'SKILL.md');
|
|
59
|
+
const legacyPath = path.join(OPENCODE_CONFIG_DIR, 'skill', skillName, 'SKILL.md');
|
|
60
|
+
if (fs.existsSync(legacyPath) && !fs.existsSync(pluralPath)) return legacyPath;
|
|
61
|
+
return pluralPath;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getClaudeSkillDir(workingDirectory, skillName) {
|
|
65
|
+
return path.join(workingDirectory, '.claude', 'skills', skillName);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getClaudeSkillPath(workingDirectory, skillName) {
|
|
69
|
+
return path.join(getClaudeSkillDir(workingDirectory, skillName), 'SKILL.md');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getUserClaudeSkillDir(skillName) {
|
|
73
|
+
return path.join(os.homedir(), '.claude', 'skills', skillName);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getUserClaudeSkillPath(skillName) {
|
|
77
|
+
return path.join(getUserClaudeSkillDir(skillName), 'SKILL.md');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getUserAgentsSkillDir(skillName) {
|
|
81
|
+
return path.join(os.homedir(), '.agents', 'skills', skillName);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getUserAgentsSkillPath(skillName) {
|
|
85
|
+
return path.join(getUserAgentsSkillDir(skillName), 'SKILL.md');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getProjectAgentsSkillDir(workingDirectory, skillName) {
|
|
89
|
+
return path.join(workingDirectory, '.agents', 'skills', skillName);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getProjectAgentsSkillPath(workingDirectory, skillName) {
|
|
93
|
+
return path.join(getProjectAgentsSkillDir(workingDirectory, skillName), 'SKILL.md');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getSkillScope(skillName, workingDirectory) {
|
|
97
|
+
const discovered = discoverSkills(workingDirectory).find((skill) => skill.name === skillName);
|
|
98
|
+
if (discovered?.path) {
|
|
99
|
+
return { scope: discovered.scope || null, path: discovered.path, source: discovered.source || null };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (workingDirectory) {
|
|
103
|
+
const projectPath = getProjectSkillPath(workingDirectory, skillName);
|
|
104
|
+
if (fs.existsSync(projectPath)) {
|
|
105
|
+
return { scope: SKILL_SCOPE.PROJECT, path: projectPath, source: 'opencode' };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const claudePath = getClaudeSkillPath(workingDirectory, skillName);
|
|
109
|
+
if (fs.existsSync(claudePath)) {
|
|
110
|
+
return { scope: SKILL_SCOPE.PROJECT, path: claudePath, source: 'claude' };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const userPath = getUserSkillPath(skillName);
|
|
115
|
+
if (fs.existsSync(userPath)) {
|
|
116
|
+
return { scope: SKILL_SCOPE.USER, path: userPath, source: 'opencode' };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const userClaudePath = getUserClaudeSkillPath(skillName);
|
|
120
|
+
if (fs.existsSync(userClaudePath)) {
|
|
121
|
+
return { scope: SKILL_SCOPE.USER, path: userClaudePath, source: 'claude' };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const userAgentsPath = getUserAgentsSkillPath(skillName);
|
|
125
|
+
if (fs.existsSync(userAgentsPath)) {
|
|
126
|
+
return { scope: SKILL_SCOPE.USER, path: userAgentsPath, source: 'agents' };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return { scope: null, path: null, source: null };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getSkillWritePath(skillName, workingDirectory, requestedScope) {
|
|
133
|
+
const existing = getSkillScope(skillName, workingDirectory);
|
|
134
|
+
if (existing.path) {
|
|
135
|
+
return existing;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const scope = requestedScope || SKILL_SCOPE.USER;
|
|
139
|
+
if (scope === SKILL_SCOPE.PROJECT && workingDirectory) {
|
|
140
|
+
return {
|
|
141
|
+
scope: SKILL_SCOPE.PROJECT,
|
|
142
|
+
path: getProjectSkillPath(workingDirectory, skillName),
|
|
143
|
+
source: 'opencode'
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
scope: SKILL_SCOPE.USER,
|
|
149
|
+
path: getUserSkillPath(skillName),
|
|
150
|
+
source: 'opencode'
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function discoverSkills(workingDirectory) {
|
|
155
|
+
const skills = new Map();
|
|
156
|
+
|
|
157
|
+
for (const externalRootName of ['.claude', '.agents']) {
|
|
158
|
+
const homeRoot = path.join(os.homedir(), externalRootName, 'skills');
|
|
159
|
+
const source = externalRootName === '.agents' ? 'agents' : 'claude';
|
|
160
|
+
for (const skillMdPath of walkSkillMdFiles(homeRoot)) {
|
|
161
|
+
addSkillFromMdFile(skills, skillMdPath, SKILL_SCOPE.USER, source);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (workingDirectory) {
|
|
166
|
+
const worktreeRoot = findWorktreeRoot(workingDirectory) || path.resolve(workingDirectory);
|
|
167
|
+
const ancestors = getAncestors(workingDirectory, worktreeRoot);
|
|
168
|
+
for (const ancestor of ancestors) {
|
|
169
|
+
for (const externalRootName of ['.claude', '.agents']) {
|
|
170
|
+
const source = externalRootName === '.agents' ? 'agents' : 'claude';
|
|
171
|
+
const externalSkillsRoot = path.join(ancestor, externalRootName, 'skills');
|
|
172
|
+
for (const skillMdPath of walkSkillMdFiles(externalSkillsRoot)) {
|
|
173
|
+
addSkillFromMdFile(skills, skillMdPath, SKILL_SCOPE.PROJECT, source);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const configDirectories = resolveSkillSearchDirectories(workingDirectory);
|
|
180
|
+
const homeOpencodeDir = path.resolve(path.join(os.homedir(), '.opencode'));
|
|
181
|
+
const customConfigDir = process.env.OPENCODE_CONFIG_DIR
|
|
182
|
+
? path.resolve(process.env.OPENCODE_CONFIG_DIR)
|
|
183
|
+
: null;
|
|
184
|
+
for (const dir of configDirectories) {
|
|
185
|
+
for (const subDir of ['skill', 'skills']) {
|
|
186
|
+
const root = path.join(dir, subDir);
|
|
187
|
+
for (const skillMdPath of walkSkillMdFiles(root)) {
|
|
188
|
+
const isUserConfigDir = dir === OPENCODE_CONFIG_DIR
|
|
189
|
+
|| dir === homeOpencodeDir
|
|
190
|
+
|| (customConfigDir && dir === customConfigDir);
|
|
191
|
+
const scope = isUserConfigDir ? SKILL_SCOPE.USER : SKILL_SCOPE.PROJECT;
|
|
192
|
+
addSkillFromMdFile(skills, skillMdPath, scope, 'opencode');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let configuredPaths = [];
|
|
198
|
+
try {
|
|
199
|
+
const config = readConfig(workingDirectory);
|
|
200
|
+
configuredPaths = Array.isArray(config?.skills?.paths) ? config.skills.paths : [];
|
|
201
|
+
} catch {
|
|
202
|
+
configuredPaths = [];
|
|
203
|
+
}
|
|
204
|
+
for (const skillPath of configuredPaths) {
|
|
205
|
+
if (typeof skillPath !== 'string' || !skillPath.trim()) continue;
|
|
206
|
+
const expanded = skillPath.startsWith('~/')
|
|
207
|
+
? path.join(os.homedir(), skillPath.slice(2))
|
|
208
|
+
: skillPath;
|
|
209
|
+
const resolved = path.isAbsolute(expanded)
|
|
210
|
+
? path.resolve(expanded)
|
|
211
|
+
: path.resolve(workingDirectory || process.cwd(), expanded);
|
|
212
|
+
for (const skillMdPath of walkSkillMdFiles(resolved)) {
|
|
213
|
+
addSkillFromMdFile(skills, skillMdPath, SKILL_SCOPE.PROJECT, 'opencode');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const cacheCandidates = [];
|
|
218
|
+
if (process.env.XDG_CACHE_HOME) {
|
|
219
|
+
cacheCandidates.push(path.join(process.env.XDG_CACHE_HOME, 'opencode', 'skills'));
|
|
220
|
+
}
|
|
221
|
+
cacheCandidates.push(path.join(os.homedir(), '.cache', 'opencode', 'skills'));
|
|
222
|
+
cacheCandidates.push(path.join(os.homedir(), 'Library', 'Caches', 'opencode', 'skills'));
|
|
223
|
+
|
|
224
|
+
for (const cacheRoot of cacheCandidates) {
|
|
225
|
+
if (!fs.existsSync(cacheRoot)) continue;
|
|
226
|
+
const entries = fs.readdirSync(cacheRoot, { withFileTypes: true });
|
|
227
|
+
for (const entry of entries) {
|
|
228
|
+
if (!entry.isDirectory()) continue;
|
|
229
|
+
const skillRoot = path.join(cacheRoot, entry.name);
|
|
230
|
+
for (const skillMdPath of walkSkillMdFiles(skillRoot)) {
|
|
231
|
+
addSkillFromMdFile(skills, skillMdPath, SKILL_SCOPE.USER, 'opencode');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return Array.from(skills.values());
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function getSkillSources(skillName, workingDirectory, discoveredSkill = null) {
|
|
240
|
+
const projectPath = workingDirectory ? getProjectSkillPath(workingDirectory, skillName) : null;
|
|
241
|
+
const projectExists = projectPath && fs.existsSync(projectPath);
|
|
242
|
+
const projectDir = projectExists ? path.dirname(projectPath) : null;
|
|
243
|
+
|
|
244
|
+
const claudePath = workingDirectory ? getClaudeSkillPath(workingDirectory, skillName) : null;
|
|
245
|
+
const claudeExists = claudePath && fs.existsSync(claudePath);
|
|
246
|
+
const claudeDir = claudeExists ? path.dirname(claudePath) : null;
|
|
247
|
+
const userClaudePath = getUserClaudeSkillPath(skillName);
|
|
248
|
+
const userClaudeExists = fs.existsSync(userClaudePath);
|
|
249
|
+
const userClaudeDir = userClaudeExists ? path.dirname(userClaudePath) : null;
|
|
250
|
+
|
|
251
|
+
const userPath = getUserSkillPath(skillName);
|
|
252
|
+
const userExists = fs.existsSync(userPath);
|
|
253
|
+
const userDir = userExists ? path.dirname(userPath) : null;
|
|
254
|
+
|
|
255
|
+
const userAgentsPath = getUserAgentsSkillPath(skillName);
|
|
256
|
+
const userAgentsExists = fs.existsSync(userAgentsPath);
|
|
257
|
+
const userAgentsDir = userAgentsExists ? path.dirname(userAgentsPath) : null;
|
|
258
|
+
|
|
259
|
+
const matchedDiscovered = discoveredSkill && discoveredSkill.name === skillName
|
|
260
|
+
? discoveredSkill
|
|
261
|
+
: discoverSkills(workingDirectory).find((skill) => skill.name === skillName);
|
|
262
|
+
|
|
263
|
+
let mdPath = null;
|
|
264
|
+
let mdScope = null;
|
|
265
|
+
let mdSource = null;
|
|
266
|
+
let mdDir = null;
|
|
267
|
+
|
|
268
|
+
if (matchedDiscovered?.path) {
|
|
269
|
+
mdPath = matchedDiscovered.path;
|
|
270
|
+
mdScope = matchedDiscovered.scope || null;
|
|
271
|
+
mdSource = matchedDiscovered.source || null;
|
|
272
|
+
mdDir = path.dirname(matchedDiscovered.path);
|
|
273
|
+
} else if (projectExists) {
|
|
274
|
+
mdPath = projectPath;
|
|
275
|
+
mdScope = SKILL_SCOPE.PROJECT;
|
|
276
|
+
mdSource = 'opencode';
|
|
277
|
+
mdDir = projectDir;
|
|
278
|
+
} else if (claudeExists) {
|
|
279
|
+
mdPath = claudePath;
|
|
280
|
+
mdScope = SKILL_SCOPE.PROJECT;
|
|
281
|
+
mdSource = 'claude';
|
|
282
|
+
mdDir = claudeDir;
|
|
283
|
+
} else if (userExists) {
|
|
284
|
+
mdPath = userPath;
|
|
285
|
+
mdScope = SKILL_SCOPE.USER;
|
|
286
|
+
mdSource = 'opencode';
|
|
287
|
+
mdDir = userDir;
|
|
288
|
+
} else if (userClaudeExists) {
|
|
289
|
+
mdPath = userClaudePath;
|
|
290
|
+
mdScope = SKILL_SCOPE.USER;
|
|
291
|
+
mdSource = 'claude';
|
|
292
|
+
mdDir = userClaudeDir;
|
|
293
|
+
} else if (userAgentsExists) {
|
|
294
|
+
mdPath = userAgentsPath;
|
|
295
|
+
mdScope = SKILL_SCOPE.USER;
|
|
296
|
+
mdSource = 'agents';
|
|
297
|
+
mdDir = userAgentsDir;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const mdExists = !!mdPath && fs.existsSync(mdPath);
|
|
301
|
+
if (!mdExists) {
|
|
302
|
+
mdPath = null;
|
|
303
|
+
mdDir = null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const sources = {
|
|
307
|
+
md: {
|
|
308
|
+
exists: mdExists,
|
|
309
|
+
path: mdPath,
|
|
310
|
+
dir: mdDir,
|
|
311
|
+
scope: mdScope,
|
|
312
|
+
source: mdSource,
|
|
313
|
+
fields: [],
|
|
314
|
+
supportingFiles: []
|
|
315
|
+
},
|
|
316
|
+
projectMd: {
|
|
317
|
+
exists: projectExists,
|
|
318
|
+
path: projectPath,
|
|
319
|
+
dir: projectDir
|
|
320
|
+
},
|
|
321
|
+
claudeMd: {
|
|
322
|
+
exists: claudeExists,
|
|
323
|
+
path: claudePath,
|
|
324
|
+
dir: claudeDir
|
|
325
|
+
},
|
|
326
|
+
userMd: {
|
|
327
|
+
exists: userExists,
|
|
328
|
+
path: userPath,
|
|
329
|
+
dir: userDir
|
|
330
|
+
},
|
|
331
|
+
userClaudeMd: {
|
|
332
|
+
exists: userClaudeExists,
|
|
333
|
+
path: userClaudePath,
|
|
334
|
+
dir: userClaudeDir
|
|
335
|
+
},
|
|
336
|
+
userAgentsMd: {
|
|
337
|
+
exists: userAgentsExists,
|
|
338
|
+
path: userAgentsPath,
|
|
339
|
+
dir: userAgentsDir
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
if (mdExists && mdDir) {
|
|
344
|
+
const { frontmatter, body } = parseMdFile(mdPath);
|
|
345
|
+
sources.md.fields = Object.keys(frontmatter);
|
|
346
|
+
sources.md.description = frontmatter.description || '';
|
|
347
|
+
sources.md.name = frontmatter.name || skillName;
|
|
348
|
+
if (body) {
|
|
349
|
+
sources.md.fields.push('instructions');
|
|
350
|
+
sources.md.instructions = body;
|
|
351
|
+
} else {
|
|
352
|
+
sources.md.instructions = '';
|
|
353
|
+
}
|
|
354
|
+
sources.md.supportingFiles = listSkillSupportingFiles(mdDir);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return sources;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function createSkill(skillName, config, workingDirectory, scope) {
|
|
361
|
+
ensureDirs();
|
|
362
|
+
|
|
363
|
+
if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(skillName) || skillName.length > 64) {
|
|
364
|
+
throw new Error(`Invalid skill name "${skillName}". Must be 1-64 lowercase alphanumeric characters with hyphens, cannot start or end with hyphen.`);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const existing = getSkillScope(skillName, workingDirectory);
|
|
368
|
+
if (existing.path) {
|
|
369
|
+
throw new Error(`Skill ${skillName} already exists at ${existing.path}`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
let targetDir;
|
|
373
|
+
let targetPath;
|
|
374
|
+
let targetScope;
|
|
375
|
+
|
|
376
|
+
const requestedScope = scope === SKILL_SCOPE.PROJECT ? SKILL_SCOPE.PROJECT : SKILL_SCOPE.USER;
|
|
377
|
+
const requestedSource = config?.source === 'agents' ? 'agents' : 'opencode';
|
|
378
|
+
|
|
379
|
+
if (requestedScope === SKILL_SCOPE.PROJECT && workingDirectory) {
|
|
380
|
+
ensureProjectSkillDir(workingDirectory);
|
|
381
|
+
if (requestedSource === 'agents') {
|
|
382
|
+
targetDir = getProjectAgentsSkillDir(workingDirectory, skillName);
|
|
383
|
+
targetPath = getProjectAgentsSkillPath(workingDirectory, skillName);
|
|
384
|
+
} else {
|
|
385
|
+
targetDir = getProjectSkillDir(workingDirectory, skillName);
|
|
386
|
+
targetPath = getProjectSkillPath(workingDirectory, skillName);
|
|
387
|
+
}
|
|
388
|
+
targetScope = SKILL_SCOPE.PROJECT;
|
|
389
|
+
} else {
|
|
390
|
+
if (requestedSource === 'agents') {
|
|
391
|
+
targetDir = getUserAgentsSkillDir(skillName);
|
|
392
|
+
targetPath = getUserAgentsSkillPath(skillName);
|
|
393
|
+
} else {
|
|
394
|
+
targetDir = getUserSkillDir(skillName);
|
|
395
|
+
targetPath = getUserSkillPath(skillName);
|
|
396
|
+
}
|
|
397
|
+
targetScope = SKILL_SCOPE.USER;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
401
|
+
|
|
402
|
+
const { instructions, scope: _scopeFromConfig, source: _sourceFromConfig, supportingFiles, ...frontmatter } = config;
|
|
403
|
+
void _scopeFromConfig;
|
|
404
|
+
void _sourceFromConfig;
|
|
405
|
+
|
|
406
|
+
if (!frontmatter.name) {
|
|
407
|
+
frontmatter.name = skillName;
|
|
408
|
+
}
|
|
409
|
+
if (!frontmatter.description) {
|
|
410
|
+
throw new Error('Skill description is required');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
writeMdFile(targetPath, frontmatter, instructions || '');
|
|
414
|
+
|
|
415
|
+
if (supportingFiles && Array.isArray(supportingFiles)) {
|
|
416
|
+
for (const file of supportingFiles) {
|
|
417
|
+
if (file.path && file.content !== undefined) {
|
|
418
|
+
writeSkillSupportingFile(targetDir, file.path, file.content);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
console.log(`Created new skill: ${skillName} (scope: ${targetScope}, path: ${targetPath})`);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function updateSkill(skillName, updates, workingDirectory, targetPath = null) {
|
|
427
|
+
ensureDirs();
|
|
428
|
+
|
|
429
|
+
const requestedPath = typeof targetPath === 'string' && targetPath.trim()
|
|
430
|
+
? path.resolve(targetPath.trim())
|
|
431
|
+
: null;
|
|
432
|
+
const existing = requestedPath && fs.existsSync(requestedPath)
|
|
433
|
+
? { scope: null, path: requestedPath, source: null }
|
|
434
|
+
: getSkillScope(skillName, workingDirectory);
|
|
435
|
+
if (!existing.path) {
|
|
436
|
+
throw new Error(`Skill "${skillName}" not found`);
|
|
437
|
+
}
|
|
438
|
+
if (path.basename(existing.path) !== 'SKILL.md') {
|
|
439
|
+
throw new Error(`Skill "${skillName}" target must be a SKILL.md file`);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const mdPath = existing.path;
|
|
443
|
+
const mdDir = path.dirname(mdPath);
|
|
444
|
+
const mdData = parseMdFile(mdPath);
|
|
445
|
+
const frontmatterName = typeof mdData.frontmatter?.name === 'string' ? mdData.frontmatter.name : skillName;
|
|
446
|
+
if (frontmatterName !== skillName) {
|
|
447
|
+
throw new Error(`Skill "${skillName}" does not match ${mdPath}`);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
let mdModified = false;
|
|
451
|
+
|
|
452
|
+
for (const [field, value] of Object.entries(updates)) {
|
|
453
|
+
if (field === 'scope' || field === 'source' || field === 'targetPath') {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (field === 'instructions') {
|
|
458
|
+
const normalizedValue = typeof value === 'string' ? value : (value == null ? '' : String(value));
|
|
459
|
+
mdData.body = normalizedValue;
|
|
460
|
+
mdModified = true;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (field === 'supportingFiles') {
|
|
465
|
+
if (Array.isArray(value)) {
|
|
466
|
+
for (const file of value) {
|
|
467
|
+
if (file.delete && file.path) {
|
|
468
|
+
deleteSkillSupportingFile(mdDir, file.path);
|
|
469
|
+
} else if (file.path && file.content !== undefined) {
|
|
470
|
+
writeSkillSupportingFile(mdDir, file.path, file.content);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
mdData.frontmatter[field] = value;
|
|
478
|
+
mdModified = true;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (mdModified) {
|
|
482
|
+
writeMdFile(mdPath, mdData.frontmatter, mdData.body);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
console.log(`Updated skill: ${skillName} (path: ${mdPath})`);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function deleteSkill(skillName, workingDirectory) {
|
|
489
|
+
let deleted = false;
|
|
490
|
+
|
|
491
|
+
if (workingDirectory) {
|
|
492
|
+
const projectDir = getProjectSkillDir(workingDirectory, skillName);
|
|
493
|
+
if (fs.existsSync(projectDir)) {
|
|
494
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
495
|
+
console.log(`Deleted project-level skill directory: ${projectDir}`);
|
|
496
|
+
deleted = true;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const claudeDir = getClaudeSkillDir(workingDirectory, skillName);
|
|
500
|
+
if (fs.existsSync(claudeDir)) {
|
|
501
|
+
fs.rmSync(claudeDir, { recursive: true, force: true });
|
|
502
|
+
console.log(`Deleted claude-compat skill directory: ${claudeDir}`);
|
|
503
|
+
deleted = true;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const projectAgentsDir = getProjectAgentsSkillDir(workingDirectory, skillName);
|
|
507
|
+
if (fs.existsSync(projectAgentsDir)) {
|
|
508
|
+
fs.rmSync(projectAgentsDir, { recursive: true, force: true });
|
|
509
|
+
console.log(`Deleted project-level agents skill directory: ${projectAgentsDir}`);
|
|
510
|
+
deleted = true;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const userDir = getUserSkillDir(skillName);
|
|
515
|
+
if (fs.existsSync(userDir)) {
|
|
516
|
+
fs.rmSync(userDir, { recursive: true, force: true });
|
|
517
|
+
console.log(`Deleted user-level skill directory: ${userDir}`);
|
|
518
|
+
deleted = true;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const userAgentsDir = getUserAgentsSkillDir(skillName);
|
|
522
|
+
if (fs.existsSync(userAgentsDir)) {
|
|
523
|
+
fs.rmSync(userAgentsDir, { recursive: true, force: true });
|
|
524
|
+
console.log(`Deleted user-level agents skill directory: ${userAgentsDir}`);
|
|
525
|
+
deleted = true;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const userClaudeDir = getUserClaudeSkillDir(skillName);
|
|
529
|
+
if (fs.existsSync(userClaudeDir)) {
|
|
530
|
+
fs.rmSync(userClaudeDir, { recursive: true, force: true });
|
|
531
|
+
console.log(`Deleted user-level claude skill directory: ${userClaudeDir}`);
|
|
532
|
+
deleted = true;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (!deleted) {
|
|
536
|
+
throw new Error(`Skill "${skillName}" not found`);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export {
|
|
541
|
+
getSkillSources,
|
|
542
|
+
getSkillScope,
|
|
543
|
+
getSkillWritePath,
|
|
544
|
+
discoverSkills,
|
|
545
|
+
createSkill,
|
|
546
|
+
updateSkill,
|
|
547
|
+
deleteSkill,
|
|
548
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export const createStartupPipelineRuntime = (dependencies) => {
|
|
2
|
+
const {
|
|
3
|
+
createTerminalRuntime,
|
|
4
|
+
createMessageStreamWsRuntime,
|
|
5
|
+
createServerStartupRuntime,
|
|
6
|
+
} = dependencies;
|
|
7
|
+
|
|
8
|
+
const run = async (options) => {
|
|
9
|
+
const {
|
|
10
|
+
app,
|
|
11
|
+
server,
|
|
12
|
+
express,
|
|
13
|
+
fs,
|
|
14
|
+
path,
|
|
15
|
+
uiAuthController,
|
|
16
|
+
buildAugmentedPath,
|
|
17
|
+
searchPathFor,
|
|
18
|
+
isExecutable,
|
|
19
|
+
isRequestOriginAllowed,
|
|
20
|
+
rejectWebSocketUpgrade,
|
|
21
|
+
buildOpenCodeUrl,
|
|
22
|
+
getOpenCodeAuthHeaders,
|
|
23
|
+
globalEventHub,
|
|
24
|
+
processForwardedEventPayload,
|
|
25
|
+
messageStreamWsClients,
|
|
26
|
+
triggerHealthCheck,
|
|
27
|
+
upstreamStallTimeoutMs,
|
|
28
|
+
terminalHeartbeatIntervalMs,
|
|
29
|
+
terminalRebindWindowMs,
|
|
30
|
+
terminalMaxRebindsPerWindow,
|
|
31
|
+
setupProxy,
|
|
32
|
+
scheduleOpenCodeApiDetection,
|
|
33
|
+
bootstrapOpenCodeAtStartup,
|
|
34
|
+
staticRoutesRuntime,
|
|
35
|
+
process,
|
|
36
|
+
crypto,
|
|
37
|
+
normalizeTunnelBootstrapTtlMs,
|
|
38
|
+
readSettingsFromDiskMigrated,
|
|
39
|
+
tunnelAuthController,
|
|
40
|
+
startTunnelWithNormalizedRequest,
|
|
41
|
+
gracefulShutdown,
|
|
42
|
+
getSignalsAttached,
|
|
43
|
+
setSignalsAttached,
|
|
44
|
+
syncToHmrState,
|
|
45
|
+
TUNNEL_MODE_QUICK,
|
|
46
|
+
TUNNEL_MODE_MANAGED_LOCAL,
|
|
47
|
+
TUNNEL_MODE_MANAGED_REMOTE,
|
|
48
|
+
host,
|
|
49
|
+
port,
|
|
50
|
+
startupTunnelRequest,
|
|
51
|
+
onTunnelReady,
|
|
52
|
+
tunnelRuntimeContext,
|
|
53
|
+
attachSignals,
|
|
54
|
+
} = options;
|
|
55
|
+
|
|
56
|
+
const terminalRuntime = createTerminalRuntime({
|
|
57
|
+
app,
|
|
58
|
+
server,
|
|
59
|
+
express,
|
|
60
|
+
fs,
|
|
61
|
+
path,
|
|
62
|
+
uiAuthController,
|
|
63
|
+
buildAugmentedPath,
|
|
64
|
+
searchPathFor,
|
|
65
|
+
isExecutable,
|
|
66
|
+
isRequestOriginAllowed,
|
|
67
|
+
rejectWebSocketUpgrade,
|
|
68
|
+
TERMINAL_INPUT_WS_HEARTBEAT_INTERVAL_MS: terminalHeartbeatIntervalMs,
|
|
69
|
+
TERMINAL_INPUT_WS_REBIND_WINDOW_MS: terminalRebindWindowMs,
|
|
70
|
+
TERMINAL_INPUT_WS_MAX_REBINDS_PER_WINDOW: terminalMaxRebindsPerWindow,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const messageStreamRuntime = createMessageStreamWsRuntime({
|
|
74
|
+
server,
|
|
75
|
+
uiAuthController,
|
|
76
|
+
isRequestOriginAllowed,
|
|
77
|
+
rejectWebSocketUpgrade,
|
|
78
|
+
buildOpenCodeUrl,
|
|
79
|
+
getOpenCodeAuthHeaders,
|
|
80
|
+
globalEventHub,
|
|
81
|
+
processForwardedEventPayload,
|
|
82
|
+
wsClients: messageStreamWsClients,
|
|
83
|
+
triggerHealthCheck,
|
|
84
|
+
upstreamStallTimeoutMs,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
setupProxy(app);
|
|
88
|
+
scheduleOpenCodeApiDetection();
|
|
89
|
+
void bootstrapOpenCodeAtStartup();
|
|
90
|
+
|
|
91
|
+
staticRoutesRuntime.registerStaticRoutes(app);
|
|
92
|
+
|
|
93
|
+
const serverStartupRuntime = createServerStartupRuntime({
|
|
94
|
+
process,
|
|
95
|
+
crypto,
|
|
96
|
+
server,
|
|
97
|
+
normalizeTunnelBootstrapTtlMs,
|
|
98
|
+
readSettingsFromDiskMigrated,
|
|
99
|
+
tunnelAuthController,
|
|
100
|
+
startTunnelWithNormalizedRequest,
|
|
101
|
+
gracefulShutdown,
|
|
102
|
+
getSignalsAttached,
|
|
103
|
+
setSignalsAttached,
|
|
104
|
+
syncToHmrState,
|
|
105
|
+
TUNNEL_MODE_QUICK,
|
|
106
|
+
TUNNEL_MODE_MANAGED_LOCAL,
|
|
107
|
+
TUNNEL_MODE_MANAGED_REMOTE,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const bindHost = serverStartupRuntime.resolveBindHost(host);
|
|
111
|
+
const startupResult = await serverStartupRuntime.startListeningAndMaybeTunnel({
|
|
112
|
+
port,
|
|
113
|
+
bindHost,
|
|
114
|
+
startupTunnelRequest,
|
|
115
|
+
onTunnelReady,
|
|
116
|
+
});
|
|
117
|
+
tunnelRuntimeContext.setActivePort(startupResult.activePort);
|
|
118
|
+
|
|
119
|
+
serverStartupRuntime.attachProcessHandlers({ attachSignals });
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
terminalRuntime,
|
|
123
|
+
messageStreamRuntime,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
run,
|
|
129
|
+
};
|
|
130
|
+
};
|