somora 2026.930.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +364 -0
- package/bin/node-version.d.mts +3 -0
- package/bin/node-version.mjs +45 -0
- package/bin/somora.mjs +77 -0
- package/config.example.yaml +896 -0
- package/docs/agents.md +677 -0
- package/docs/api.md +3194 -0
- package/docs/browser.md +317 -0
- package/docs/builder.md +331 -0
- package/docs/cache-strategy.md +373 -0
- package/docs/compaction.md +253 -0
- package/docs/display.md +154 -0
- package/docs/dream-phases.md +891 -0
- package/docs/files.md +387 -0
- package/docs/imagegen.md +366 -0
- package/docs/images/somora-hero.png +0 -0
- package/docs/images/somora-mobile-2026-05-23.png +0 -0
- package/docs/images/somora-tui-2026-05-23.png +0 -0
- package/docs/images/somora-web-2026-05-23.png +0 -0
- package/docs/index.md +178 -0
- package/docs/lsp.md +93 -0
- package/docs/mcp.md +332 -0
- package/docs/memory.md +407 -0
- package/docs/mobile.md +310 -0
- package/docs/models.md +379 -0
- package/docs/projects.md +425 -0
- package/docs/realtime-voice.md +293 -0
- package/docs/resources.md +230 -0
- package/docs/sampling.md +128 -0
- package/docs/security.md +189 -0
- package/docs/sentinel.md +295 -0
- package/docs/setup.md +1217 -0
- package/docs/skills.md +501 -0
- package/docs/team.md +189 -0
- package/docs/thinking.md +463 -0
- package/docs/tmux.md +399 -0
- package/docs/tools.md +117 -0
- package/docs/videogen.md +191 -0
- package/docs/voice.md +288 -0
- package/docs/web.md +893 -0
- package/docs/wiki.md +583 -0
- package/npm-shrinkwrap.json +5670 -0
- package/package.json +116 -0
- package/src/attachments/store.ts +196 -0
- package/src/browser/change-stream.ts +31 -0
- package/src/browser/display.ts +108 -0
- package/src/browser/policy.ts +121 -0
- package/src/browser/screencast.ts +374 -0
- package/src/browser/service.ts +1337 -0
- package/src/browser/session.ts +15 -0
- package/src/browser/snapshot.ts +40 -0
- package/src/cli/auth.ts +117 -0
- package/src/cli/codex.ts +41 -0
- package/src/cli/lsp.ts +71 -0
- package/src/cli/resolvers/clawhub.ts +400 -0
- package/src/cli/setup.ts +835 -0
- package/src/cli/skill.ts +619 -0
- package/src/cli/somora.ts +548 -0
- package/src/cli/systemd-unit.ts +72 -0
- package/src/cli/team.ts +148 -0
- package/src/cli/tui/activity-stream.ts +121 -0
- package/src/cli/tui/api.ts +479 -0
- package/src/cli/tui/app.tsx +1169 -0
- package/src/cli/tui/autocomplete.tsx +55 -0
- package/src/cli/tui/commands.ts +913 -0
- package/src/cli/tui/dream-glyphs.ts +22 -0
- package/src/cli/tui/footer.tsx +15 -0
- package/src/cli/tui/format.ts +28 -0
- package/src/cli/tui/header.tsx +279 -0
- package/src/cli/tui/index.tsx +120 -0
- package/src/cli/tui/markdown.tsx +63 -0
- package/src/cli/tui/sampling.ts +162 -0
- package/src/cli/tui/separator.tsx +13 -0
- package/src/cli/tui/state.ts +42 -0
- package/src/cli/tui/stream.ts +330 -0
- package/src/cli/tui/thinking-text.ts +54 -0
- package/src/cli/tui/turn-views.tsx +499 -0
- package/src/cli/tui/types.ts +410 -0
- package/src/cli/tui/work-queue.ts +161 -0
- package/src/cli/update-args.ts +55 -0
- package/src/cli/wiki.ts +406 -0
- package/src/compaction/index.ts +28 -0
- package/src/compaction/midturn.ts +210 -0
- package/src/compaction/policy.ts +154 -0
- package/src/compaction/summarize.ts +691 -0
- package/src/compaction/template.ts +90 -0
- package/src/compaction/types.ts +148 -0
- package/src/config/loader.ts +276 -0
- package/src/config/reload.ts +43 -0
- package/src/config/types.ts +2292 -0
- package/src/dream/deep-actions.ts +324 -0
- package/src/dream/deep-dispatcher.ts +237 -0
- package/src/dream/deep-llm.ts +388 -0
- package/src/dream/deep-prompts.ts +106 -0
- package/src/dream/deep-runner.ts +757 -0
- package/src/dream/deep-skip-cache.ts +199 -0
- package/src/dream/deep-worker.ts +229 -0
- package/src/dream/json-salvage.ts +34 -0
- package/src/dream/judge.ts +188 -0
- package/src/dream/loop-state.ts +286 -0
- package/src/dream/lucid-actions.ts +303 -0
- package/src/dream/lucid-batches.ts +94 -0
- package/src/dream/lucid-prompt.ts +82 -0
- package/src/dream/lucid-runner.ts +744 -0
- package/src/dream/lucid-storage.ts +277 -0
- package/src/dream/lucid-structure.ts +102 -0
- package/src/dream/lucid-types.ts +137 -0
- package/src/dream/lucid-worker.ts +224 -0
- package/src/dream/rem-dedup.ts +502 -0
- package/src/dream/rem-extract.ts +782 -0
- package/src/dream/rem-reset-run.ts +67 -0
- package/src/dream/rem-runner.ts +696 -0
- package/src/dream/rem-worker.ts +527 -0
- package/src/dream/review-window.ts +71 -0
- package/src/dream/scheduler-state.ts +129 -0
- package/src/dream/storage.ts +497 -0
- package/src/dream/types.ts +133 -0
- package/src/dream/wiki-context.ts +133 -0
- package/src/engine/a2a.ts +33 -0
- package/src/engine/availability.ts +63 -0
- package/src/engine/claude-cli.ts +969 -0
- package/src/engine/codex-app-server-client.ts +294 -0
- package/src/engine/codex-bin.ts +49 -0
- package/src/engine/codex-cli.ts +1014 -0
- package/src/engine/codex-dynamic-tools.ts +239 -0
- package/src/engine/codex-home.ts +63 -0
- package/src/engine/codex-thread-config.ts +74 -0
- package/src/engine/context-budget.ts +257 -0
- package/src/engine/engine-meta-labels.ts +211 -0
- package/src/engine/grok-cli.ts +941 -0
- package/src/engine/inline-think.ts +59 -0
- package/src/engine/model-availability.ts +105 -0
- package/src/engine/openai-compatible.ts +2464 -0
- package/src/engine/reasoning-retry.ts +83 -0
- package/src/engine/registry.ts +13 -0
- package/src/engine/replay.ts +195 -0
- package/src/engine/sampling.ts +90 -0
- package/src/engine/thinking-params.ts +264 -0
- package/src/engine/types.ts +269 -0
- package/src/engine/user-tag.ts +24 -0
- package/src/imagegen/aspect.ts +128 -0
- package/src/imagegen/generate.ts +642 -0
- package/src/imagegen/references.ts +75 -0
- package/src/imagegen/types.ts +154 -0
- package/src/lsp/client.ts +183 -0
- package/src/lsp/fake-server.helper.mjs +42 -0
- package/src/lsp/format.ts +29 -0
- package/src/lsp/index.ts +21 -0
- package/src/lsp/manager.ts +238 -0
- package/src/lsp/registry.ts +151 -0
- package/src/mcp/config.ts +117 -0
- package/src/mcp/hub/audit.ts +55 -0
- package/src/mcp/hub/bridge.ts +115 -0
- package/src/mcp/hub/catalog.ts +69 -0
- package/src/mcp/hub/credentials.ts +406 -0
- package/src/mcp/hub/env-expand.ts +14 -0
- package/src/mcp/hub/manager.ts +770 -0
- package/src/mcp/hub/normalize.ts +213 -0
- package/src/mcp/server.ts +368 -0
- package/src/mcp/tool-schema.ts +20 -0
- package/src/media/capabilities.ts +392 -0
- package/src/media/records.ts +175 -0
- package/src/media/store.ts +217 -0
- package/src/media/types.ts +69 -0
- package/src/memory/chunking.ts +168 -0
- package/src/memory/embeddings.ts +262 -0
- package/src/memory/index.ts +15 -0
- package/src/memory/inject.ts +197 -0
- package/src/memory/manager.ts +996 -0
- package/src/memory/registry.ts +176 -0
- package/src/memory/rescan.ts +101 -0
- package/src/memory/retrieval.ts +586 -0
- package/src/memory/shared-index.ts +372 -0
- package/src/memory/slug.ts +39 -0
- package/src/memory/storage.ts +385 -0
- package/src/memory/watcher.ts +134 -0
- package/src/multimodal/blocks.ts +101 -0
- package/src/multimodal/dimensions.ts +214 -0
- package/src/multimodal/load.ts +86 -0
- package/src/multimodal/mime.ts +135 -0
- package/src/multimodal/pdf-render.ts +80 -0
- package/src/multimodal/user-content.ts +266 -0
- package/src/persona/files.ts +144 -0
- package/src/persona/loader.ts +598 -0
- package/src/persona/skill-gating-store.ts +59 -0
- package/src/persona/tool-gating-store.ts +113 -0
- package/src/projects/focus.ts +186 -0
- package/src/projects/prompt-block.ts +106 -0
- package/src/projects/scheme.ts +107 -0
- package/src/projects/store.ts +144 -0
- package/src/projects/types.ts +73 -0
- package/src/sentinel/dispatcher.ts +97 -0
- package/src/sentinel/schedule.ts +271 -0
- package/src/sentinel/scheduler.ts +840 -0
- package/src/sentinel/store.ts +259 -0
- package/src/sentinel/types.ts +221 -0
- package/src/server/activity-stream.ts +160 -0
- package/src/server/ask-calls.ts +137 -0
- package/src/server/ask-wait-graph.ts +171 -0
- package/src/server/async-tasks.ts +199 -0
- package/src/server/builder-busy.ts +86 -0
- package/src/server/builder-prompt.ts +204 -0
- package/src/server/builder-questions.ts +117 -0
- package/src/server/builder-session.ts +249 -0
- package/src/server/chat-aborts.ts +83 -0
- package/src/server/claude-config-dir.ts +71 -0
- package/src/server/claude-credential-sync.ts +454 -0
- package/src/server/env-file.ts +100 -0
- package/src/server/env.ts +115 -0
- package/src/server/heal-session.ts +151 -0
- package/src/server/history-page.ts +46 -0
- package/src/server/index.ts +7244 -0
- package/src/server/lockfile.ts +89 -0
- package/src/server/logger.ts +67 -0
- package/src/server/logs.ts +187 -0
- package/src/server/loopback-fetch.ts +130 -0
- package/src/server/openai-client.ts +89 -0
- package/src/server/prompt-assembly.ts +334 -0
- package/src/server/restart-reconcile.ts +139 -0
- package/src/server/run-turn-fallback.ts +275 -0
- package/src/server/run-turn-types.ts +91 -0
- package/src/server/run-turn.ts +1474 -0
- package/src/server/sanitize-assistant-text.ts +112 -0
- package/src/server/session-export.ts +220 -0
- package/src/server/session-queue.ts +376 -0
- package/src/server/session-workdir.ts +49 -0
- package/src/server/sse-h2-safe.ts +61 -0
- package/src/server/sse-liveness.ts +162 -0
- package/src/server/sse-serializer.ts +161 -0
- package/src/server/start-turn.ts +249 -0
- package/src/server/steer-inbox.ts +107 -0
- package/src/server/tls-keeper.ts +153 -0
- package/src/server/tool-format.ts +167 -0
- package/src/server/turn-framing.ts +52 -0
- package/src/server/turn-origin-kind.ts +74 -0
- package/src/server/turn-origin.ts +40 -0
- package/src/server/work-ledger.ts +975 -0
- package/src/server/workspace.ts +114 -0
- package/src/setup/config-edit.ts +201 -0
- package/src/setup/presets.ts +71 -0
- package/src/setup/prompt.ts +163 -0
- package/src/setup/tailscale.ts +44 -0
- package/src/skills/bin-checks.ts +227 -0
- package/src/skills/bootstrap.ts +347 -0
- package/src/skills/env-scope.ts +175 -0
- package/src/skills/gating.ts +71 -0
- package/src/skills/lint.ts +202 -0
- package/src/skills/load.ts +368 -0
- package/src/skills/path-helpers.ts +102 -0
- package/src/skills/registry.ts +178 -0
- package/src/ssh/exec.ts +142 -0
- package/src/ssh/index.ts +12 -0
- package/src/ssh/known-hosts.ts +109 -0
- package/src/ssh/pool.ts +307 -0
- package/src/storage/sessions.ts +602 -0
- package/src/team/render.ts +149 -0
- package/src/team/resolve.ts +122 -0
- package/src/team/store.ts +124 -0
- package/src/team/types.ts +111 -0
- package/src/team/write.ts +95 -0
- package/src/testing/isolated-home.mts +46 -0
- package/src/tmux/attention-watcher.ts +272 -0
- package/src/tmux/attention.ts +336 -0
- package/src/tmux/list.ts +91 -0
- package/src/tmux/origin-store.ts +102 -0
- package/src/tmux/tui-markers.ts +267 -0
- package/src/tools/agents/ask-cancel.ts +94 -0
- package/src/tools/agents/ask-result.ts +235 -0
- package/src/tools/agents/ask.ts +704 -0
- package/src/tools/agents/builder-dispatch.ts +217 -0
- package/src/tools/agents/images.ts +104 -0
- package/src/tools/agents/index.ts +42 -0
- package/src/tools/agents/long-task-timeouts.ts +39 -0
- package/src/tools/agents/session-list.ts +136 -0
- package/src/tools/agents/session-model.ts +106 -0
- package/src/tools/agents/spawn.ts +845 -0
- package/src/tools/agents/status.ts +589 -0
- package/src/tools/browser/index.ts +6 -0
- package/src/tools/browser/ops.ts +145 -0
- package/src/tools/browser/tools.ts +184 -0
- package/src/tools/builder/short-descriptions.ts +80 -0
- package/src/tools/builder/tools.ts +222 -0
- package/src/tools/docs/index.ts +1 -0
- package/src/tools/docs/tools.ts +228 -0
- package/src/tools/dream/index.ts +11 -0
- package/src/tools/dream/tools.ts +1002 -0
- package/src/tools/exec/allowlist.ts +233 -0
- package/src/tools/exec/background-detach.helper.mts +27 -0
- package/src/tools/exec/blacklist.ts +336 -0
- package/src/tools/exec/concurrency.ts +150 -0
- package/src/tools/exec/fit-output.ts +82 -0
- package/src/tools/exec/index.ts +7 -0
- package/src/tools/exec/internal-env.ts +89 -0
- package/src/tools/exec/job-store.ts +403 -0
- package/src/tools/exec/local.ts +649 -0
- package/src/tools/exec/remote.ts +399 -0
- package/src/tools/exec/tools.ts +934 -0
- package/src/tools/file/analyze.ts +378 -0
- package/src/tools/file/index.ts +2 -0
- package/src/tools/file/local.ts +707 -0
- package/src/tools/file/lsp-hook.ts +72 -0
- package/src/tools/file/persona-guard.ts +61 -0
- package/src/tools/file/policy.ts +292 -0
- package/src/tools/file/read-format.ts +129 -0
- package/src/tools/file/remote.ts +680 -0
- package/src/tools/file/replace.ts +507 -0
- package/src/tools/file/search-window.ts +224 -0
- package/src/tools/file/tools.ts +658 -0
- package/src/tools/file/write-scope.ts +182 -0
- package/src/tools/gating.ts +106 -0
- package/src/tools/image/budget.ts +82 -0
- package/src/tools/image/index.ts +7 -0
- package/src/tools/image/tools.ts +601 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/memory/index.ts +12 -0
- package/src/tools/memory/tools.ts +399 -0
- package/src/tools/projects/index.ts +1 -0
- package/src/tools/projects/tools.ts +643 -0
- package/src/tools/registry.ts +427 -0
- package/src/tools/resources/index.ts +8 -0
- package/src/tools/resources/tools.ts +176 -0
- package/src/tools/resources/visibility.ts +60 -0
- package/src/tools/sentinel/index.ts +1 -0
- package/src/tools/sentinel/tools.ts +592 -0
- package/src/tools/skill/index.ts +4 -0
- package/src/tools/skill/tools.ts +285 -0
- package/src/tools/time/index.ts +5 -0
- package/src/tools/time/tools.ts +123 -0
- package/src/tools/tmux/index.ts +1 -0
- package/src/tools/tmux/local.ts +277 -0
- package/src/tools/tmux/remote.ts +168 -0
- package/src/tools/tmux/tools.ts +1064 -0
- package/src/tools/tool-output.ts +97 -0
- package/src/tools/types.ts +227 -0
- package/src/tools/video/index.ts +1 -0
- package/src/tools/video/tools.ts +425 -0
- package/src/tools/web/fetch.ts +337 -0
- package/src/tools/web/index.ts +4 -0
- package/src/tools/web/tools.ts +186 -0
- package/src/tools/wiki/index.ts +1 -0
- package/src/tools/wiki/tools.ts +445 -0
- package/src/tts/cache-gc.ts +128 -0
- package/src/tts/prepare-for-tts.ts +114 -0
- package/src/tts/service.ts +332 -0
- package/src/types/events.ts +695 -0
- package/src/types/turn-origin.ts +53 -0
- package/src/version.ts +21 -0
- package/src/videogen/dialects.ts +222 -0
- package/src/videogen/generate.ts +484 -0
- package/src/videogen/jobs.ts +178 -0
- package/src/videogen/runner.ts +125 -0
- package/src/videogen/wake.ts +119 -0
- package/src/voice/realtime/call.ts +948 -0
- package/src/voice/realtime/consult.ts +293 -0
- package/src/voice/realtime/fake-provider.ts +134 -0
- package/src/voice/realtime/manager.ts +384 -0
- package/src/voice/realtime/openai-provider.ts +471 -0
- package/src/voice/realtime/persona.ts +227 -0
- package/src/voice/realtime/session-match.ts +116 -0
- package/src/voice/realtime/types.ts +182 -0
- package/src/wiki/conflict.ts +113 -0
- package/src/wiki/explorer.ts +578 -0
- package/src/wiki/index-builder.ts +172 -0
- package/src/wiki/language.ts +134 -0
- package/src/wiki/log-builder.ts +150 -0
- package/src/wiki/map.ts +258 -0
- package/src/wiki/migration/analyze.ts +304 -0
- package/src/wiki/migration/execute.ts +689 -0
- package/src/wiki/migration/refine.ts +402 -0
- package/src/wiki/migration/store.ts +100 -0
- package/src/wiki/move-page.ts +57 -0
- package/src/wiki/structure-file.ts +192 -0
- package/src/wiki/taxonomy.ts +140 -0
- package/src/wiki/templates.ts +163 -0
- package/src/wiki/types.ts +133 -0
- package/templates/skills/README.md +24 -0
- package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
- package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
- package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
- package/templates/skills/_templates/default/SKILL.md +25 -0
- package/templates/skills/builder-handover/SKILL.md +96 -0
- package/templates/skills/builder-handover/assets/ORDER.md +12 -0
- package/templates/skills/skill-author/SKILL.md +110 -0
- package/tsconfig.json +22 -0
- package/web/dist/assets/index-BaVv6pB2.js +631 -0
- package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
- package/web/dist/assets/index-V3FV3Z25.css +32 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +20 -0
- package/web/package.json +36 -0
- package/web/tsconfig.json +25 -0
- package/web-mobile/dist/apple-touch-icon.png +0 -0
- package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
- package/web-mobile/dist/favicon.svg +8 -0
- package/web-mobile/dist/icon-192.png +0 -0
- package/web-mobile/dist/icon-512.png +0 -0
- package/web-mobile/dist/index.html +27 -0
- package/web-mobile/dist/manifest.webmanifest +32 -0
- package/web-mobile/dist/service-worker.js +90 -0
- package/web-mobile/package.json +28 -0
- package/web-mobile/tsconfig.json +25 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// ClawHub skill resolver.
|
|
2
|
+
//
|
|
3
|
+
// ClawHub (https://clawhub.ai, repo openclaw/clawhub) is OpenClaw's public
|
|
4
|
+
// skill marketplace. It serves a stable, OpenAPI-documented HTTP API and
|
|
5
|
+
// explicitly invites third-party clients to consume it (see docs/http-api.md
|
|
6
|
+
// "Public catalog reuse" section).
|
|
7
|
+
//
|
|
8
|
+
// What this resolver does:
|
|
9
|
+
// 1. Match a URL like `https://clawhub.ai/<owner>/<slug>` (or `…/<slug>`)
|
|
10
|
+
// and extract the slug.
|
|
11
|
+
// 2. Fetch the metadata via `GET /api/v1/skills/<slug>` to canonicalize the
|
|
12
|
+
// slug (handles owner rename / merge / slug-alias).
|
|
13
|
+
// 3. Fetch the zipped skill bundle via `GET /api/v1/download?slug=<canon>`.
|
|
14
|
+
// 4. Extract SKILL.md (or skill.md) + any text sub-resources from the zip.
|
|
15
|
+
// 5. Translate `metadata.openclaw.*` frontmatter into `metadata.somora.*`
|
|
16
|
+
// so somora's loader picks up the requires.bins / env_vars / when_to_use
|
|
17
|
+
// runtime checks.
|
|
18
|
+
// 6. Return the rewritten SKILL.md content + the sub-resource buffers.
|
|
19
|
+
//
|
|
20
|
+
// Rate limits: ClawHub enforces 30 anonymous req/min on the download endpoint
|
|
21
|
+
// and 600 anonymous req/min on read endpoints. 429 responses include a
|
|
22
|
+
// Retry-After header — we surface it in the error so the caller knows how
|
|
23
|
+
// long to wait.
|
|
24
|
+
//
|
|
25
|
+
// Why a separate resolver module (not inline in skill.ts): if a second
|
|
26
|
+
// marketplace shows up, the call-site in cmdAdd stays unchanged — only the
|
|
27
|
+
// dispatch list grows. The cmdAdd flow (lint, atomic write, post-write
|
|
28
|
+
// verify) is identical for all sources.
|
|
29
|
+
|
|
30
|
+
import AdmZip from 'adm-zip';
|
|
31
|
+
import matter from 'gray-matter';
|
|
32
|
+
|
|
33
|
+
const CLAWHUB_HOSTS = new Set(['clawhub.ai', 'www.clawhub.ai']);
|
|
34
|
+
const CLAWHUB_API_BASE = 'https://clawhub.ai/api/v1';
|
|
35
|
+
const MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024; // matches ClawHub's server-side limit
|
|
36
|
+
const DOWNLOAD_TIMEOUT_MS = 60_000;
|
|
37
|
+
const META_TIMEOUT_MS = 15_000;
|
|
38
|
+
|
|
39
|
+
// Text-file extension allowlist mirrors ClawHub's `TEXT_FILE_EXTENSIONS`
|
|
40
|
+
// (packages/schema/src/textFiles.ts in their repo). We use it defensively
|
|
41
|
+
// even though the registry already enforces it server-side — a future ZIP
|
|
42
|
+
// from a less-trusted source should still get the same filter.
|
|
43
|
+
const ALLOWED_EXT = new Set([
|
|
44
|
+
'.md', '.markdown', '.txt', '.json', '.yaml', '.yml', '.toml',
|
|
45
|
+
'.js', '.mjs', '.cjs', '.ts', '.mts', '.cts',
|
|
46
|
+
'.sh', '.bash', '.zsh', '.fish',
|
|
47
|
+
'.py', '.rb', '.go', '.rs',
|
|
48
|
+
'.html', '.htm', '.css', '.svg',
|
|
49
|
+
'.ps1', '.psm1', '.psd1',
|
|
50
|
+
'.env.example', '.gitignore', '.clawhubignore', '.clawdhubignore',
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
export interface ClawHubResolution {
|
|
54
|
+
/** Rewritten SKILL.md text content (frontmatter translated to somora-shape). */
|
|
55
|
+
skillMd: string;
|
|
56
|
+
/** Sub-resources from the zip — relative paths under the skill folder. */
|
|
57
|
+
extraFiles: Array<{ relPath: string; content: Buffer }>;
|
|
58
|
+
/** Canonical slug as reported by ClawHub (may differ from URL slug after rename). */
|
|
59
|
+
canonicalSlug: string;
|
|
60
|
+
/** Resolved version (semver string) we just downloaded. */
|
|
61
|
+
version: string;
|
|
62
|
+
/** Human-readable source label for log messages. */
|
|
63
|
+
sourceLabel: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Returns true if the URL points at ClawHub. The caller uses this to decide
|
|
67
|
+
* whether to route through this resolver instead of the plain HTTP path. */
|
|
68
|
+
export function isClawHubUrl(url: string): boolean {
|
|
69
|
+
try {
|
|
70
|
+
const u = new URL(url);
|
|
71
|
+
return CLAWHUB_HOSTS.has(u.hostname);
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Parse slug + owner from a ClawHub web URL. Accepted shapes:
|
|
78
|
+
* /<slug> (slug shortcut)
|
|
79
|
+
* /<owner>/<slug> (older canonical web URL)
|
|
80
|
+
* /<owner>/skills/<slug> (current canonical web URL)
|
|
81
|
+
* /skills/<slug> (owner-less skills path)
|
|
82
|
+
* The owner is a REQUIRED disambiguator on the API side whenever a slug
|
|
83
|
+
* is taken by multiple owners (409 AMBIGUOUS_SKILL_SLUG otherwise) —
|
|
84
|
+
* dropping it from the URL made `somora skill install
|
|
85
|
+
* https://clawhub.ai/steipete/skills/gog` fail on any contested slug
|
|
86
|
+
* (Lucy case study 2026-07-24). Returns null on unrecognized shapes. */
|
|
87
|
+
export function parseClawHubUrl(url: string): { slug: string; owner?: string } | null {
|
|
88
|
+
let u: URL;
|
|
89
|
+
try {
|
|
90
|
+
u = new URL(url);
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const parts = u.pathname.split('/').filter((p) => p.length > 0);
|
|
95
|
+
const last = parts[parts.length - 1];
|
|
96
|
+
if (!last) return null;
|
|
97
|
+
// ClawHub slugs: lowercase, URL-safe (`^[a-z0-9][a-z0-9-]*$`).
|
|
98
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(last)) return null;
|
|
99
|
+
let owner: string | undefined;
|
|
100
|
+
if (parts.length === 2 && parts[0] !== 'skills') owner = parts[0];
|
|
101
|
+
else if (parts.length === 3 && parts[1] === 'skills') owner = parts[0];
|
|
102
|
+
else if (parts.length > 1 && !(parts.length === 2 && parts[0] === 'skills')) return null;
|
|
103
|
+
if (owner !== undefined && !/^[a-z0-9][a-z0-9._-]*$/i.test(owner)) return null;
|
|
104
|
+
return { slug: last, ...(owner ? { owner } : {}) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Run a fetch with an explicit AbortController-based timeout. We don't reuse
|
|
108
|
+
* the openai-compat patient client because that one disables timeouts entirely
|
|
109
|
+
* — for ClawHub's small REST calls a 15-60s cap is much more appropriate. */
|
|
110
|
+
async function fetchWithTimeout(url: string, timeoutMs: number): Promise<Response> {
|
|
111
|
+
const ac = new AbortController();
|
|
112
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
113
|
+
try {
|
|
114
|
+
return await fetch(url, {
|
|
115
|
+
signal: ac.signal,
|
|
116
|
+
headers: {
|
|
117
|
+
// Identify ourselves so ClawHub can attribute traffic. Doesn't replace
|
|
118
|
+
// a real Bearer token but is useful for both sides.
|
|
119
|
+
'User-Agent': 'somora-skill-cli (https://github.com/thenaxon/somora_agent)',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
} finally {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface ClawHubMetaResponse {
|
|
128
|
+
skill?: {
|
|
129
|
+
slug?: string;
|
|
130
|
+
displayName?: string;
|
|
131
|
+
summary?: string;
|
|
132
|
+
};
|
|
133
|
+
latestVersion?: {
|
|
134
|
+
version?: string;
|
|
135
|
+
};
|
|
136
|
+
moderation?: {
|
|
137
|
+
isMalwareBlocked?: boolean;
|
|
138
|
+
verdict?: string;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Shape of ClawHub's 409 AMBIGUOUS_SKILL_SLUG body (verified live
|
|
143
|
+
* 2026-07-27): lists every owner holding the slug. */
|
|
144
|
+
interface ClawHubAmbiguousResponse {
|
|
145
|
+
code?: string;
|
|
146
|
+
matches?: Array<{ ownerHandle?: string; slug?: string; url?: string }>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function ambiguousSlugError(slug: string, res: Response): Promise<Error> {
|
|
150
|
+
let candidates = '';
|
|
151
|
+
try {
|
|
152
|
+
const body = (await res.json()) as ClawHubAmbiguousResponse;
|
|
153
|
+
if (Array.isArray(body.matches) && body.matches.length > 0) {
|
|
154
|
+
candidates =
|
|
155
|
+
' Candidates:\n' +
|
|
156
|
+
body.matches
|
|
157
|
+
.map((m) => ` - ${m.url ?? `https://clawhub.ai/${m.ownerHandle}/skills/${m.slug ?? slug}`}`)
|
|
158
|
+
.join('\n');
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
/* non-JSON body — generic message below is still actionable */
|
|
162
|
+
}
|
|
163
|
+
return new Error(
|
|
164
|
+
`ClawHub: slug '${slug}' is taken by multiple owners (409). ` +
|
|
165
|
+
`Re-run with the owner-qualified URL (https://clawhub.ai/<owner>/skills/${slug}).${candidates}`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function fetchMeta(slug: string, owner?: string): Promise<ClawHubMetaResponse> {
|
|
170
|
+
const ownerQs = owner ? `?owner=${encodeURIComponent(owner)}` : '';
|
|
171
|
+
const url = `${CLAWHUB_API_BASE}/skills/${encodeURIComponent(slug)}${ownerQs}`;
|
|
172
|
+
const res = await fetchWithTimeout(url, META_TIMEOUT_MS);
|
|
173
|
+
if (res.status === 404) {
|
|
174
|
+
throw new Error(`ClawHub: skill '${owner ? `${owner}/` : ''}${slug}' not found (404)`);
|
|
175
|
+
}
|
|
176
|
+
if (res.status === 409) {
|
|
177
|
+
throw await ambiguousSlugError(slug, res);
|
|
178
|
+
}
|
|
179
|
+
if (res.status === 429) {
|
|
180
|
+
const retryAfter = res.headers.get('retry-after') ?? '?';
|
|
181
|
+
throw new Error(
|
|
182
|
+
`ClawHub: rate-limited on metadata fetch (429). Retry after ${retryAfter}s.`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (!res.ok) {
|
|
186
|
+
throw new Error(`ClawHub: GET /skills/${slug} returned ${res.status} ${res.statusText}`);
|
|
187
|
+
}
|
|
188
|
+
const body = (await res.json()) as ClawHubMetaResponse;
|
|
189
|
+
if (body.moderation?.isMalwareBlocked) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`ClawHub: skill '${slug}' is currently malware-blocked by ClawHub's moderation system — refusing to install.`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return body;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function fetchZip(slug: string, owner?: string): Promise<Buffer> {
|
|
198
|
+
const ownerQs = owner ? `&owner=${encodeURIComponent(owner)}` : '';
|
|
199
|
+
const url = `${CLAWHUB_API_BASE}/download?slug=${encodeURIComponent(slug)}${ownerQs}`;
|
|
200
|
+
const res = await fetchWithTimeout(url, DOWNLOAD_TIMEOUT_MS);
|
|
201
|
+
if (res.status === 410) {
|
|
202
|
+
throw new Error(`ClawHub: requested skill version is soft-deleted (410).`);
|
|
203
|
+
}
|
|
204
|
+
if (res.status === 409) {
|
|
205
|
+
throw await ambiguousSlugError(slug, res);
|
|
206
|
+
}
|
|
207
|
+
if (res.status === 429) {
|
|
208
|
+
const retryAfter = res.headers.get('retry-after') ?? '?';
|
|
209
|
+
throw new Error(
|
|
210
|
+
`ClawHub: rate-limited on download (429). Retry after ${retryAfter}s.`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (!res.ok) {
|
|
214
|
+
throw new Error(`ClawHub: download returned ${res.status} ${res.statusText}`);
|
|
215
|
+
}
|
|
216
|
+
const contentLength = res.headers.get('content-length');
|
|
217
|
+
if (contentLength && Number(contentLength) > MAX_DOWNLOAD_BYTES) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`ClawHub: download size ${contentLength} bytes exceeds limit ${MAX_DOWNLOAD_BYTES}.`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
223
|
+
if (buf.byteLength > MAX_DOWNLOAD_BYTES) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`ClawHub: download size ${buf.byteLength} bytes exceeds limit ${MAX_DOWNLOAD_BYTES}.`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (buf.byteLength < 4 || buf[0] !== 0x50 || buf[1] !== 0x4b) {
|
|
229
|
+
// ZIP local-file-header signature is 0x50 0x4B 0x03 0x04. If we got
|
|
230
|
+
// something else, the registry returned non-zip content (HTML error
|
|
231
|
+
// page, JSON wrapper). Surface honestly.
|
|
232
|
+
throw new Error(
|
|
233
|
+
`ClawHub: response did not look like a ZIP (first bytes ${buf.slice(0, 4).toString('hex')}).`,
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
return buf;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Sanitize a ZIP entry path. Rejects absolute paths, parent-dir traversal,
|
|
240
|
+
* and any path that escapes the skill root. Returns the normalized relative
|
|
241
|
+
* path or null if the entry should be dropped silently. */
|
|
242
|
+
function safeRelPath(rawName: string): string | null {
|
|
243
|
+
// Use forward slashes, drop leading slashes.
|
|
244
|
+
let p = rawName.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
245
|
+
// Reject any parent-dir traversal.
|
|
246
|
+
if (p.includes('..')) return null;
|
|
247
|
+
// Skip directory entries (zip uses trailing slash for dirs).
|
|
248
|
+
if (p.endsWith('/')) return null;
|
|
249
|
+
// Skip empty + absolute-like paths.
|
|
250
|
+
if (!p || p.startsWith('/')) return null;
|
|
251
|
+
// ClawHub bundles often have a top-level folder named after the skill.
|
|
252
|
+
// Strip exactly ONE leading folder if all entries share it — caller does
|
|
253
|
+
// that pass; here we just normalize. (Caller handles the prefix strip.)
|
|
254
|
+
return p;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Strip a common top-level folder if every entry shares it. ClawHub's
|
|
258
|
+
* download zip typically wraps the skill in `<slug>/...` — we want
|
|
259
|
+
* `SKILL.md` at the root of our extraction, not `<slug>/SKILL.md`. */
|
|
260
|
+
function commonPrefix(paths: string[]): string | null {
|
|
261
|
+
if (paths.length === 0) return null;
|
|
262
|
+
const first = paths[0];
|
|
263
|
+
if (first === undefined) return null;
|
|
264
|
+
const slash = first.indexOf('/');
|
|
265
|
+
if (slash <= 0) return null;
|
|
266
|
+
const prefix = first.slice(0, slash + 1);
|
|
267
|
+
for (const p of paths) {
|
|
268
|
+
if (!p.startsWith(prefix)) return null;
|
|
269
|
+
}
|
|
270
|
+
return prefix;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface ExtractedFiles {
|
|
274
|
+
/** Path → buffer, paths normalized (no leading prefix). */
|
|
275
|
+
byPath: Map<string, Buffer>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function extractZip(buf: Buffer): ExtractedFiles {
|
|
279
|
+
const zip = new AdmZip(buf);
|
|
280
|
+
const entries = zip.getEntries();
|
|
281
|
+
const tmp = new Map<string, Buffer>();
|
|
282
|
+
for (const e of entries) {
|
|
283
|
+
if (e.isDirectory) continue;
|
|
284
|
+
const rel = safeRelPath(e.entryName);
|
|
285
|
+
if (!rel) continue;
|
|
286
|
+
const ext = '.' + (rel.split('.').pop() ?? '').toLowerCase();
|
|
287
|
+
// Allowlist filter is defensive — registry enforces it server-side.
|
|
288
|
+
// Skip files outside the allowlist instead of erroring; the SKILL.md is
|
|
289
|
+
// the only required entry and the linter will catch missing pieces.
|
|
290
|
+
if (!ALLOWED_EXT.has(ext) && rel !== '.gitignore' && rel !== '.clawhubignore') continue;
|
|
291
|
+
tmp.set(rel, e.getData());
|
|
292
|
+
}
|
|
293
|
+
// Strip the common top-level folder if every entry shares it.
|
|
294
|
+
const prefix = commonPrefix([...tmp.keys()]);
|
|
295
|
+
if (prefix) {
|
|
296
|
+
const stripped = new Map<string, Buffer>();
|
|
297
|
+
for (const [k, v] of tmp) {
|
|
298
|
+
stripped.set(k.slice(prefix.length), v);
|
|
299
|
+
}
|
|
300
|
+
return { byPath: stripped };
|
|
301
|
+
}
|
|
302
|
+
return { byPath: tmp };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Find the SKILL.md (or skill.md) entry in the extracted zip. Per the
|
|
306
|
+
* ClawHub format spec it MUST exist at the skill folder root. */
|
|
307
|
+
function findSkillMd(files: ExtractedFiles): { path: string; buffer: Buffer } | null {
|
|
308
|
+
for (const candidate of ['SKILL.md', 'skill.md']) {
|
|
309
|
+
const buf = files.byPath.get(candidate);
|
|
310
|
+
if (buf) return { path: candidate, buffer: buf };
|
|
311
|
+
}
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Translate ClawHub-shape frontmatter into somora-shape so somora's loader
|
|
316
|
+
* recognizes requires.bins / env_vars / when_to_use checks at load time.
|
|
317
|
+
* The body itself is unchanged. ClawHub uses `metadata.openclaw.*`, somora
|
|
318
|
+
* uses `metadata.somora.*`; the field names are mostly identical except
|
|
319
|
+
* ClawHub's `requires.env` is somora's `requires.env_vars`. We keep the
|
|
320
|
+
* original `metadata.openclaw` block intact in addition to the translated
|
|
321
|
+
* somora block, so the file remains valid in both ecosystems. */
|
|
322
|
+
function translateFrontmatter(skillMdText: string, slug: string): string {
|
|
323
|
+
const parsed = matter(skillMdText);
|
|
324
|
+
const data = (parsed.data ?? {}) as Record<string, unknown>;
|
|
325
|
+
const metadata = (data.metadata ?? {}) as Record<string, unknown>;
|
|
326
|
+
const clawhub =
|
|
327
|
+
(metadata.openclaw as Record<string, unknown> | undefined) ??
|
|
328
|
+
(metadata.clawdbot as Record<string, unknown> | undefined) ??
|
|
329
|
+
(metadata.clawdis as Record<string, unknown> | undefined);
|
|
330
|
+
|
|
331
|
+
// Build a somora-shape block, preferring existing metadata.somora if the
|
|
332
|
+
// skill already has one (rare — usually it has openclaw-only).
|
|
333
|
+
const existingSomora = (metadata.somora as Record<string, unknown> | undefined) ?? {};
|
|
334
|
+
const somoraOut: Record<string, unknown> = { ...existingSomora };
|
|
335
|
+
|
|
336
|
+
if (clawhub) {
|
|
337
|
+
const requires = (clawhub.requires as Record<string, unknown> | undefined) ?? {};
|
|
338
|
+
const reqEnv = requires.env;
|
|
339
|
+
const reqBins = requires.bins;
|
|
340
|
+
const reqConfig = requires.config;
|
|
341
|
+
const requiresOut: Record<string, unknown> = {};
|
|
342
|
+
if (Array.isArray(reqBins) && reqBins.length > 0) requiresOut.bins = reqBins;
|
|
343
|
+
if (Array.isArray(reqEnv) && reqEnv.length > 0) requiresOut.env_vars = reqEnv;
|
|
344
|
+
if (Array.isArray(reqConfig) && reqConfig.length > 0) requiresOut.config = reqConfig;
|
|
345
|
+
if (Object.keys(requiresOut).length > 0) {
|
|
346
|
+
somoraOut.requires = { ...(somoraOut.requires as object | undefined), ...requiresOut };
|
|
347
|
+
}
|
|
348
|
+
// ClawHub has no direct when_to_use — keep any existing somora value.
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const newData: Record<string, unknown> = {
|
|
352
|
+
...data,
|
|
353
|
+
name: slug, // canonicalize: somora's loader requires name === parent dir
|
|
354
|
+
metadata: {
|
|
355
|
+
...metadata,
|
|
356
|
+
...(Object.keys(somoraOut).length > 0 ? { somora: somoraOut } : {}),
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
return matter.stringify(parsed.content, newData);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Main entry point. Given a ClawHub URL, return an installable resolution
|
|
364
|
+
* the caller can pass straight into its pre-flight lint + atomic write
|
|
365
|
+
* flow. The caller still chooses the destination slug — usually it should
|
|
366
|
+
* match `canonicalSlug` returned here, but a `--force` rename is allowed. */
|
|
367
|
+
export async function resolveClawHubUrl(url: string): Promise<ClawHubResolution> {
|
|
368
|
+
const ref = parseClawHubUrl(url);
|
|
369
|
+
if (!ref) {
|
|
370
|
+
throw new Error(`Unrecognized ClawHub URL shape: ${url}`);
|
|
371
|
+
}
|
|
372
|
+
// Canonicalize via metadata fetch. Handles rename / merge / alias.
|
|
373
|
+
// The owner from the URL rides along on BOTH calls — it's the only
|
|
374
|
+
// disambiguator the API accepts when a slug is contested.
|
|
375
|
+
const meta = await fetchMeta(ref.slug, ref.owner);
|
|
376
|
+
const canonicalSlug = meta.skill?.slug ?? ref.slug;
|
|
377
|
+
const version = meta.latestVersion?.version ?? 'unknown';
|
|
378
|
+
// Download the zipped bundle.
|
|
379
|
+
const zipBuf = await fetchZip(canonicalSlug, ref.owner);
|
|
380
|
+
const extracted = extractZip(zipBuf);
|
|
381
|
+
const skillEntry = findSkillMd(extracted);
|
|
382
|
+
if (!skillEntry) {
|
|
383
|
+
throw new Error(
|
|
384
|
+
`ClawHub: downloaded zip for '${canonicalSlug}' does not contain SKILL.md at the root.`,
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
const rewrittenSkillMd = translateFrontmatter(skillEntry.buffer.toString('utf8'), canonicalSlug);
|
|
388
|
+
const extraFiles: Array<{ relPath: string; content: Buffer }> = [];
|
|
389
|
+
for (const [path, buf] of extracted.byPath) {
|
|
390
|
+
if (path === skillEntry.path) continue;
|
|
391
|
+
extraFiles.push({ relPath: path, content: buf });
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
skillMd: rewrittenSkillMd,
|
|
395
|
+
extraFiles,
|
|
396
|
+
canonicalSlug,
|
|
397
|
+
version,
|
|
398
|
+
sourceLabel: `ClawHub: ${canonicalSlug}@${version} (${url})`,
|
|
399
|
+
};
|
|
400
|
+
}
|