omnicell-router 0.1.0 → 0.2.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/RELEASING.md +238 -238
- package/RELEASING.zh-CN.md +230 -230
- package/backend/dist/capture/recorder.js +2 -1
- package/backend/dist/cli/clients/base.js +8 -16
- package/backend/dist/cli/clients/dsh.js +8 -16
- package/backend/dist/cli/clients/pi.js +16 -9
- package/backend/dist/cli/types.d.ts +5 -0
- package/backend/dist/config/env.js +2 -1
- package/backend/dist/config/index.js +2 -0
- package/backend/dist/config/types.d.ts +23 -0
- package/backend/dist/harness/adapters/amp.d.ts +2 -0
- package/backend/dist/harness/adapters/amp.js +7 -0
- package/backend/dist/harness/adapters/claude.d.ts +2 -0
- package/backend/dist/harness/adapters/claude.js +7 -0
- package/backend/dist/harness/adapters/cline.d.ts +2 -0
- package/backend/dist/harness/adapters/cline.js +6 -0
- package/backend/dist/harness/adapters/codex.d.ts +2 -0
- package/backend/dist/harness/adapters/codex.js +6 -0
- package/backend/dist/harness/adapters/cursor.d.ts +5 -0
- package/backend/dist/harness/adapters/cursor.js +10 -0
- package/backend/dist/harness/adapters/declarative.d.ts +62 -0
- package/backend/dist/harness/adapters/declarative.js +202 -0
- package/backend/dist/harness/adapters/dsh.d.ts +5 -0
- package/backend/dist/harness/adapters/dsh.js +6 -0
- package/backend/dist/harness/adapters/gemini-cli.d.ts +2 -0
- package/backend/dist/harness/adapters/gemini-cli.js +7 -0
- package/backend/dist/harness/adapters/github-copilot.d.ts +5 -0
- package/backend/dist/harness/adapters/github-copilot.js +10 -0
- package/backend/dist/harness/adapters/index.d.ts +44 -0
- package/backend/dist/harness/adapters/index.js +99 -0
- package/backend/dist/harness/adapters/opencode.d.ts +2 -0
- package/backend/dist/harness/adapters/opencode.js +55 -0
- package/backend/dist/harness/adapters/pi.d.ts +1 -0
- package/backend/dist/harness/adapters/pi.js +22 -0
- package/backend/dist/harness/adapters/skills-paths.d.ts +15 -0
- package/backend/dist/harness/adapters/skills-paths.js +17 -0
- package/backend/dist/harness/adapters/types.d.ts +174 -0
- package/backend/dist/harness/adapters/types.js +12 -0
- package/backend/dist/harness/adapters/universal.d.ts +6 -0
- package/backend/dist/harness/adapters/universal.js +10 -0
- package/backend/dist/harness/adapters/windsurf.d.ts +2 -0
- package/backend/dist/harness/adapters/windsurf.js +10 -0
- package/backend/dist/harness/adapters/zed.d.ts +2 -0
- package/backend/dist/harness/adapters/zed.js +6 -0
- package/backend/dist/harness/awesome-opencode.d.ts +40 -0
- package/backend/dist/harness/awesome-opencode.js +75 -0
- package/backend/dist/harness/browse.d.ts +202 -0
- package/backend/dist/harness/browse.js +1214 -0
- package/backend/dist/harness/catalog-npm.d.ts +59 -0
- package/backend/dist/harness/catalog-npm.js +145 -0
- package/backend/dist/harness/clawhub.d.ts +212 -0
- package/backend/dist/harness/clawhub.js +426 -0
- package/backend/dist/harness/config-file.d.ts +29 -0
- package/backend/dist/harness/config-file.js +35 -0
- package/backend/dist/harness/detail.d.ts +74 -0
- package/backend/dist/harness/detail.js +330 -0
- package/backend/dist/harness/discover.d.ts +118 -0
- package/backend/dist/harness/discover.js +507 -0
- package/backend/dist/harness/drift.d.ts +21 -0
- package/backend/dist/harness/drift.js +25 -0
- package/backend/dist/harness/hash.d.ts +10 -0
- package/backend/dist/harness/hash.js +63 -0
- package/backend/dist/harness/hosts.d.ts +18 -0
- package/backend/dist/harness/hosts.js +15 -0
- package/backend/dist/harness/install.d.ts +88 -0
- package/backend/dist/harness/install.js +301 -0
- package/backend/dist/harness/inventory.d.ts +10 -0
- package/backend/dist/harness/inventory.js +198 -0
- package/backend/dist/harness/ledger.d.ts +39 -0
- package/backend/dist/harness/ledger.js +83 -0
- package/backend/dist/harness/maintenance.d.ts +115 -0
- package/backend/dist/harness/maintenance.js +603 -0
- package/backend/dist/harness/manifest.d.ts +31 -0
- package/backend/dist/harness/manifest.js +234 -0
- package/backend/dist/harness/net.d.ts +86 -0
- package/backend/dist/harness/net.js +113 -0
- package/backend/dist/harness/opencode-cafe.d.ts +40 -0
- package/backend/dist/harness/opencode-cafe.js +85 -0
- package/backend/dist/harness/opencode-ecosystem.d.ts +34 -0
- package/backend/dist/harness/opencode-ecosystem.js +246 -0
- package/backend/dist/harness/pi-dev.d.ts +81 -0
- package/backend/dist/harness/pi-dev.js +187 -0
- package/backend/dist/harness/probe.d.ts +33 -0
- package/backend/dist/harness/probe.js +85 -0
- package/backend/dist/harness/registry.d.ts +2 -0
- package/backend/dist/harness/registry.js +26 -0
- package/backend/dist/harness/scopes.d.ts +21 -0
- package/backend/dist/harness/scopes.js +22 -0
- package/backend/dist/harness/skill-md.d.ts +18 -0
- package/backend/dist/harness/skill-md.js +71 -0
- package/backend/dist/harness/skills-sh.d.ts +109 -0
- package/backend/dist/harness/skills-sh.js +178 -0
- package/backend/dist/harness/smithery.d.ts +64 -0
- package/backend/dist/harness/smithery.js +146 -0
- package/backend/dist/harness/sources/awesome-opencode.d.ts +11 -0
- package/backend/dist/harness/sources/awesome-opencode.js +39 -0
- package/backend/dist/harness/sources/clawhub.d.ts +2 -0
- package/backend/dist/harness/sources/clawhub.js +83 -0
- package/backend/dist/harness/sources/github.d.ts +9 -0
- package/backend/dist/harness/sources/github.js +202 -0
- package/backend/dist/harness/sources/mcp-official.d.ts +2 -0
- package/backend/dist/harness/sources/mcp-official.js +110 -0
- package/backend/dist/harness/sources/npm.d.ts +2 -0
- package/backend/dist/harness/sources/npm.js +152 -0
- package/backend/dist/harness/sources/opencode-cafe.d.ts +11 -0
- package/backend/dist/harness/sources/opencode-cafe.js +41 -0
- package/backend/dist/harness/sources/smithery.d.ts +2 -0
- package/backend/dist/harness/sources/smithery.js +81 -0
- package/backend/dist/harness/spi.d.ts +98 -0
- package/backend/dist/harness/spi.js +8 -0
- package/backend/dist/harness/stars.d.ts +70 -0
- package/backend/dist/harness/stars.js +202 -0
- package/backend/dist/harness/translation.d.ts +142 -0
- package/backend/dist/harness/translation.js +567 -0
- package/backend/dist/harness/tree.d.ts +13 -0
- package/backend/dist/harness/tree.js +19 -0
- package/backend/dist/harness/types.d.ts +286 -0
- package/backend/dist/harness/types.js +8 -0
- package/backend/dist/harness/writers/extension.d.ts +116 -0
- package/backend/dist/harness/writers/extension.js +219 -0
- package/backend/dist/harness/writers/mcp.d.ts +72 -0
- package/backend/dist/harness/writers/mcp.js +195 -0
- package/backend/dist/harness/writers/skill.d.ts +60 -0
- package/backend/dist/harness/writers/skill.js +146 -0
- package/backend/dist/opencode/agents.d.ts +5 -0
- package/backend/dist/opencode/agents.js +10 -1
- package/backend/dist/opencode/catalog/cache.js +2 -1
- package/backend/dist/opencode/catalog/logos.js +2 -1
- package/backend/dist/opencode/catalog/ocr-store.js +2 -1
- package/backend/dist/opencode/catalog/overrides-store.js +2 -1
- package/backend/dist/opencode/credentials/factory.js +10 -27
- package/backend/dist/opencode/credentials/ocr-store.js +2 -1
- package/backend/dist/opencode/provider-defs.js +2 -1
- package/backend/dist/opencode/user-config.js +8 -16
- package/backend/dist/providers/registry.d.ts +15 -4
- package/backend/dist/providers/registry.js +29 -5
- package/backend/dist/providers/virtual-meta.d.ts +13 -0
- package/backend/dist/providers/virtual-meta.js +18 -0
- package/backend/dist/quota/store.js +2 -1
- package/backend/dist/resilience/breaker-state.js +2 -1
- package/backend/dist/resilience/credential-state.js +2 -1
- package/backend/dist/routes/console.js +137 -15
- package/backend/dist/routes/harness.d.ts +2 -0
- package/backend/dist/routes/harness.js +622 -0
- package/backend/dist/server.js +4 -0
- package/backend/dist/session/session-manager.js +2 -1
- package/backend/dist/surfaces/systemone-probe.d.ts +25 -0
- package/backend/dist/surfaces/systemone-probe.js +74 -0
- package/backend/dist/utils/atomic-write.d.ts +12 -0
- package/backend/dist/utils/atomic-write.js +29 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/{index-DEo2iAT7.css → index-1o7qI-KJ.css} +1 -1
- package/frontend/dist/assets/index-DvXKvNxl.js +962 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +87 -87
- package/backend/dist/budget/budget-manager.d.ts +0 -25
- package/backend/dist/budget/budget-manager.js +0 -54
- package/backend/dist/config/governance-limits.d.ts +0 -68
- package/backend/dist/config/governance-limits.js +0 -261
- package/backend/dist/flywheel/collector.d.ts +0 -74
- package/backend/dist/flywheel/collector.js +0 -235
- package/backend/dist/flywheel/dataset.d.ts +0 -130
- package/backend/dist/flywheel/dataset.js +0 -638
- package/backend/dist/flywheel/decision-capture.d.ts +0 -68
- package/backend/dist/flywheel/decision-capture.js +0 -85
- package/backend/dist/flywheel/prune.d.ts +0 -133
- package/backend/dist/flywheel/prune.js +0 -495
- package/backend/dist/flywheel/schema.d.ts +0 -108
- package/backend/dist/flywheel/schema.js +0 -117
- package/backend/dist/flywheel/trainer.d.ts +0 -84
- package/backend/dist/flywheel/trainer.js +0 -198
- package/backend/dist/opencode/catalog/custom-store.d.ts +0 -50
- package/backend/dist/opencode/catalog/custom-store.js +0 -144
- package/backend/dist/opencode/credentials/push.d.ts +0 -38
- package/backend/dist/opencode/credentials/push.js +0 -116
- package/backend/dist/opencode/credentials/reconcile.d.ts +0 -49
- package/backend/dist/opencode/credentials/reconcile.js +0 -216
- package/backend/dist/opencode/sync.d.ts +0 -29
- package/backend/dist/opencode/sync.js +0 -186
- package/backend/dist/pipeline/account-selection.d.ts +0 -101
- package/backend/dist/pipeline/account-selection.js +0 -112
- package/backend/dist/providers/systemone.d.ts +0 -29
- package/backend/dist/providers/systemone.js +0 -170
- package/backend/dist/ratelimit/duration.d.ts +0 -24
- package/backend/dist/ratelimit/duration.js +0 -43
- package/backend/dist/ratelimit/governance-runtime.d.ts +0 -121
- package/backend/dist/ratelimit/governance-runtime.js +0 -183
- package/backend/dist/ratelimit/index.d.ts +0 -4
- package/backend/dist/ratelimit/index.js +0 -4
- package/backend/dist/ratelimit/limiter.d.ts +0 -157
- package/backend/dist/ratelimit/limiter.js +0 -244
- package/backend/dist/ratelimit/sliding-window-counter.d.ts +0 -63
- package/backend/dist/ratelimit/sliding-window-counter.js +0 -103
- package/backend/dist/ratelimit/subject.d.ts +0 -26
- package/backend/dist/ratelimit/subject.js +0 -28
- package/backend/dist/resilience/account-state.d.ts +0 -84
- package/backend/dist/resilience/account-state.js +0 -228
- package/backend/dist/router/layer1-classifier.d.ts +0 -111
- package/backend/dist/router/layer1-classifier.js +0 -467
- package/backend/dist/router/layer2-judge.d.ts +0 -111
- package/backend/dist/router/layer2-judge.js +0 -373
- package/backend/dist/router/retry-escalation.d.ts +0 -89
- package/backend/dist/router/retry-escalation.js +0 -99
- package/backend/dist/routes/flywheel.d.ts +0 -3
- package/backend/dist/routes/flywheel.js +0 -268
- package/backend/dist/routes/systemone.d.ts +0 -3
- package/backend/dist/routes/systemone.js +0 -90
- package/backend/dist/surfaces/governance-envelope.d.ts +0 -34
- package/backend/dist/surfaces/governance-envelope.js +0 -47
- package/backend/dist/utils/token-estimator.d.ts +0 -7
- package/backend/dist/utils/token-estimator.js +0 -20
- package/frontend/dist/assets/index-nwgWkmU1.js +0 -840
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
import { HOSTS } from '../harness/hosts.js';
|
|
2
|
+
import { adapterFor, isExtensionHost, isMcpHost, isSkillsHost, skillOwner, skillRootsFor, } from '../harness/adapters/index.js';
|
|
3
|
+
import { scanInventory } from '../harness/inventory.js';
|
|
4
|
+
import { claimsPath, manifestPath } from '../harness/manifest.js';
|
|
5
|
+
import { applyRemove, planRemove } from '../harness/maintenance.js';
|
|
6
|
+
import { pruneTranslationStore, probeTranslationChain, readCachedTranslations, translateDescription, translateMarkdown, } from '../harness/translation.js';
|
|
7
|
+
import { probeSystemoneDefault } from '../surfaces/systemone-probe.js';
|
|
8
|
+
import { browseSource } from '../harness/browse.js';
|
|
9
|
+
import { fetchRepoStars, peekStarCache } from '../harness/stars.js';
|
|
10
|
+
import { readMarketDetail } from '../harness/detail.js';
|
|
11
|
+
import { installArtifact } from '../harness/install.js';
|
|
12
|
+
import { recentApplies } from '../harness/ledger.js';
|
|
13
|
+
import { ENABLED_SCOPES, isEnabledScope } from '../harness/scopes.js';
|
|
14
|
+
/**
|
|
15
|
+
* Harness admin surface (ADR-0015): sources, hosts, inventory, install, uninstall, translate.
|
|
16
|
+
*
|
|
17
|
+
* Install goes through the source SPI (adapter.resolve → kind writer). MCP/extension writers land
|
|
18
|
+
* with their milestones; a request they cannot serve answers `unsupported_source`/`unsupported_kind`
|
|
19
|
+
* — an endpoint that accepts a plan it cannot execute would be worse than a typed refusal.
|
|
20
|
+
*
|
|
21
|
+
* Measured accessibility, 2026-10-24: skills.sh API 401 (Vercel OIDC only), MCP official registry 200
|
|
22
|
+
* anonymous, Smithery 200 anonymous, PulseMCP 410 (retired),
|
|
23
|
+
* mcp.so 404, npm registry 200 anonymous. Measured 2026-10-25: `pi.dev/packages` 200 anonymous
|
|
24
|
+
* (server-rendered HTML, no JSON API — the reader keys off the catalog's own card attributes), and
|
|
25
|
+
* `skills.sh`'s leaderboard PAGES 200 anonymous (`/`, `/trending`, `/hot`, each shipping its 600-row
|
|
26
|
+
* board in the RSC flight payload) and so does its own search endpoint (`/api/search`, 200 anonymous,
|
|
27
|
+
* capped at 200 rows per query) even though its API stays closed. Measured the same day, ClawHub's
|
|
28
|
+
* public v1 API (`clawhub.ai`) answers 200 anonymous throughout — cursor-paged catalog, capped
|
|
29
|
+
* whole-catalog search, and deterministic per-version ZIP downloads (3000 reads/min/IP).
|
|
30
|
+
* The curated OpenCode catalog is
|
|
31
|
+
* NOT a network source: it ships as a snapshot
|
|
32
|
+
* (`harness/opencode-ecosystem.ts`), because `raw.githubusercontent.com` and `cdn.jsdelivr.net` both
|
|
33
|
+
* reset the connection from here.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* The array order IS the console's display order and landing priority: per axis, the chip row
|
|
37
|
+
* follows this sequence and the market opens on the FIRST enabled+browsable source for that axis.
|
|
38
|
+
* The principle is low-noise first — within an axis, the order follows how far a row's claim
|
|
39
|
+
* reaches: a catalog whose row IS the artifact (an official catalog, a curated snapshot, a
|
|
40
|
+
* leaderboard entry) outranks a search over containers that CARRY the artifact (github's
|
|
41
|
+
* topic-qualified repo search — the topic is self-declared, the stars reward the repo), which
|
|
42
|
+
* outranks the one source that searches an entire package registry: npm, the wide net, is LAST
|
|
43
|
+
* on purpose.
|
|
44
|
+
*/
|
|
45
|
+
const SOURCES = [
|
|
46
|
+
{
|
|
47
|
+
id: 'skills-sh',
|
|
48
|
+
label: 'skills.sh',
|
|
49
|
+
kinds: ['skill'],
|
|
50
|
+
trust: 'aggregator',
|
|
51
|
+
// `auth` describes the API (`/api/v1/skills` = 401 without a Vercel workload token), which this
|
|
52
|
+
// console never calls. The market reads the endpoint the SITE's own browser reads, so it needs no
|
|
53
|
+
// credential: measured 2026-10-25, `GET /api/skills/<view>/<page>` answers 200 anonymously with
|
|
54
|
+
// 200 rows per (0-based) page, its own `total` (9 911 on All-time) and `hasMore`
|
|
55
|
+
// (`harness/skills-sh.ts`).
|
|
56
|
+
auth: 'oidc',
|
|
57
|
+
enabled: true,
|
|
58
|
+
browsable: true,
|
|
59
|
+
// The site's three leaderboards in its own tab order. An empty query lands on the chosen board; a
|
|
60
|
+
// query of 2+ characters goes to the site's own search endpoint (`/api/search`, anonymous, whole
|
|
61
|
+
// catalog, capped at 200 rows). Rows install as `github:<owner/repo>#<skill-dir>` — the site's own
|
|
62
|
+
// `npx skills add` identity.
|
|
63
|
+
sorts: ['all-time', 'trending', 'hot'],
|
|
64
|
+
// FIRST on the skills axis on purpose: a row here IS a skill directory, ranked by the site's
|
|
65
|
+
// own install tally. github's topic-qualified search answers with REPOS that self-declare the
|
|
66
|
+
// topic — a noisier unit, one repo holding any number of skills or none — and npm's
|
|
67
|
+
// registry-wide keyword search (whose rows cannot install as skills at all) is the wide net
|
|
68
|
+
// below that.
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'clawhub',
|
|
72
|
+
label: 'ClawHub',
|
|
73
|
+
kinds: ['skill'],
|
|
74
|
+
trust: 'community',
|
|
75
|
+
auth: 'none',
|
|
76
|
+
enabled: true,
|
|
77
|
+
browsable: true,
|
|
78
|
+
// OpenClaw's public skill registry (`clawhub.ai`), measured 2026-10-25: `GET /api/v1/skills`
|
|
79
|
+
// pages by opaque CURSOR with its own `sort` enum, `GET /api/v1/search` covers the whole catalog
|
|
80
|
+
// with NO paging parameter (a `totalScope: 'window'` answer, like skills.sh's search), and
|
|
81
|
+
// `GET /api/v1/download?slug=&ownerHandle=&version=` answers deterministic ZIP bytes. Install
|
|
82
|
+
// reads the newest published semver, downloads THAT version, and pins `{ clawhub: { slug,
|
|
83
|
+
// version } }` — a registry-version pin, not a commit. `ownerHandle` is the disambiguator the
|
|
84
|
+
// registry's own 409 error names; it is undocumented on the endpoints but measured working.
|
|
85
|
+
// AFTER skills-sh, BEFORE github on the skills axis on purpose: a row here IS a skill (a slug
|
|
86
|
+
// in a dedicated registry), while github's search answers with REPOS that self-declare the
|
|
87
|
+
// topic and npm's registry-wide search is the wide net. Rows carry no GitHub repo, so no star
|
|
88
|
+
// count is ever claimed for them.
|
|
89
|
+
sorts: ['downloads', 'stars', 'updated'],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'mcp-official',
|
|
93
|
+
label: 'MCP official registry',
|
|
94
|
+
kinds: ['mcp'],
|
|
95
|
+
trust: 'official',
|
|
96
|
+
auth: 'none',
|
|
97
|
+
enabled: true,
|
|
98
|
+
browsable: true,
|
|
99
|
+
// Browse reads `GET /v0/servers?limit=&search=&cursor=&version=latest` (200 anonymous, measured
|
|
100
|
+
// 2026-10-25) and pages by opaque CURSOR, so a market page number walks a chain rather than an
|
|
101
|
+
// offset. No `sorts`: the registry publishes no ordering parameter. Install resolves ONE record
|
|
102
|
+
// through `/v0/servers/<name>/versions/latest` — the bare `/v0/servers/<name>` path answers 404.
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'smithery',
|
|
106
|
+
label: 'Smithery',
|
|
107
|
+
kinds: ['mcp'],
|
|
108
|
+
trust: 'aggregator',
|
|
109
|
+
auth: 'none',
|
|
110
|
+
enabled: true,
|
|
111
|
+
browsable: true,
|
|
112
|
+
// Browse reads `GET /servers?page=&pageSize=&q=` (200 anonymous, measured 2026-10-25). No `sorts`:
|
|
113
|
+
// the registry publishes one order (its own usage ranking) and no parameter to change it. The
|
|
114
|
+
// listing serves 500 rows at most while claiming ~20 765, so the market reports the REACHABLE count
|
|
115
|
+
// and says so (`noteCode: 'smithery-window'`). Install resolves `GET /servers/<qualifiedName>` and
|
|
116
|
+
// emits the HOSTED deployment plus an `Authorization` env reference — Smithery hosts these servers,
|
|
117
|
+
// which is why it is the one aggregator allowed to supply a launch spec (ADR-0015 §D6).
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'pi-dev',
|
|
121
|
+
label: 'pi.dev (official)',
|
|
122
|
+
kinds: ['extension'],
|
|
123
|
+
trust: 'official',
|
|
124
|
+
auth: 'none',
|
|
125
|
+
enabled: true,
|
|
126
|
+
browsable: true,
|
|
127
|
+
// The official Pi package catalog (`pi.dev/packages`): extensions plus untyped Pi packages, every
|
|
128
|
+
// row printed with its own `pi install npm:<pkg>` command. Rows therefore carry an `npm:<pkg>`
|
|
129
|
+
// handle and install through the npm source — one package, ONE identity, and the console's
|
|
130
|
+
// installed-state join stays exact. This source produces no payload of its own (browse-only).
|
|
131
|
+
//
|
|
132
|
+
// First for the extension axis on purpose: a pi page should open on its own official catalog, not
|
|
133
|
+
// on a keyword search of the whole npm registry.
|
|
134
|
+
hosts: ['pi'],
|
|
135
|
+
// The catalog's sort CONTROL offers three orders (`Most downloads` / `Recently published` / `A-Z`),
|
|
136
|
+
// which map to `?sort=downloads|recent|name` — measured 2026-10-25: each reorders the page, and an
|
|
137
|
+
// unknown value silently falls back to downloads. Those three are the source's whole official set.
|
|
138
|
+
sorts: ['downloads', 'recent', 'name'],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'github',
|
|
142
|
+
label: 'GitHub',
|
|
143
|
+
kinds: ['skill'],
|
|
144
|
+
trust: 'community',
|
|
145
|
+
auth: 'none',
|
|
146
|
+
enabled: true,
|
|
147
|
+
browsable: true,
|
|
148
|
+
// AFTER skills-sh and clawhub on the skills axis on purpose: both answer with rows that ARE
|
|
149
|
+
// skills — the leaderboard ranked by installs, the registry by its own tally — while a topic
|
|
150
|
+
// is self-declared on the REPO and a star count rewards the repo, not the skill. github is
|
|
151
|
+
// the wider net here, and npm — whose rows cannot install as skills at all — stays below it.
|
|
152
|
+
//
|
|
153
|
+
// GitHub search repositories is the ONE market source with a published ordering contract:
|
|
154
|
+
// `sort=stars|forks|help-wanted-issues|updated` (+ best-match when the parameter is omitted).
|
|
155
|
+
// ALL of them are offered — the official set is the ceiling, not a curation of it; `stars` stays
|
|
156
|
+
// first because it is what this market has always shown.
|
|
157
|
+
sorts: ['stars', 'best-match', 'forks', 'updated', 'help-wanted-issues'],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'static-opencode',
|
|
161
|
+
label: 'OpenCode ecosystem (curated)',
|
|
162
|
+
kinds: ['extension'],
|
|
163
|
+
trust: 'community',
|
|
164
|
+
auth: 'none',
|
|
165
|
+
enabled: true,
|
|
166
|
+
browsable: true,
|
|
167
|
+
// The curated list is OpenCode's own plugin catalog: those packages are written against the
|
|
168
|
+
// OpenCode plugin API, so the source is bound to that one harness (ADR-0015 §D2 — no free host
|
|
169
|
+
// checkbox list). Browse reads a shipped snapshot (no network); a row that has a verified npm
|
|
170
|
+
// package name carries an `npm:<pkg>` install key, so installing it runs the npm source — this
|
|
171
|
+
// source produces no payload of its own and has no install adapter.
|
|
172
|
+
//
|
|
173
|
+
// First of the opencode cluster on purpose: a curated snapshot whose rows were verified
|
|
174
|
+
// against the registry is the lowest-noise answer for this runtime, so an opencode page opens
|
|
175
|
+
// on it — the community catalogs follow, and npm's registry-wide search closes the axis.
|
|
176
|
+
hosts: ['opencode'],
|
|
177
|
+
// Full-catalog sources are read WHOLE by the backend before paging, so an order computed here is
|
|
178
|
+
// global and honest (unlike a console-side re-sort of the visible page). `catalog` is the
|
|
179
|
+
// snapshot's own order; `name` is the one dimension these rows all carry.
|
|
180
|
+
sorts: ['catalog', 'name'],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: 'awesome-opencode',
|
|
184
|
+
label: 'awesome-opencode (community)',
|
|
185
|
+
kinds: ['extension'],
|
|
186
|
+
trust: 'community',
|
|
187
|
+
auth: 'none',
|
|
188
|
+
enabled: true,
|
|
189
|
+
browsable: true,
|
|
190
|
+
// The community list publishes `dist/registry.json` — a flat array with a declared shape
|
|
191
|
+
// (`data/schema.json`), generated from one YAML file per entry. It is read through the GitHub
|
|
192
|
+
// contents API (raw mirrors reset from this environment). Entries carry no package name, so the
|
|
193
|
+
// install adapter resolves one on demand (declared name → repository-verified candidate) and
|
|
194
|
+
// answers the npm identity; the row's key stays this source's until install time.
|
|
195
|
+
hosts: ['opencode'],
|
|
196
|
+
sorts: ['catalog', 'name'],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: 'opencode-cafe',
|
|
200
|
+
label: 'opencode.cafe (community)',
|
|
201
|
+
kinds: ['extension'],
|
|
202
|
+
trust: 'community',
|
|
203
|
+
auth: 'none',
|
|
204
|
+
enabled: true,
|
|
205
|
+
browsable: true,
|
|
206
|
+
// A Next.js site over a Convex deployment; the catalog query (`extensions:listAllApproved`) is
|
|
207
|
+
// anonymously readable and is read directly with a POST. Undocumented contract: a re-provisioned
|
|
208
|
+
// deployment answers `upstream`, never an empty catalog. Only `type: 'plugin'` rows are
|
|
209
|
+
// extensions. The public query ships author e-mail addresses, which `opencode-cafe.ts` narrows
|
|
210
|
+
// away before anything else sees a row.
|
|
211
|
+
hosts: ['opencode'],
|
|
212
|
+
sorts: ['catalog', 'name'],
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: 'npm',
|
|
216
|
+
label: 'npm registry',
|
|
217
|
+
kinds: ['skill', 'extension', 'mcp'],
|
|
218
|
+
trust: 'community',
|
|
219
|
+
auth: 'none',
|
|
220
|
+
enabled: true,
|
|
221
|
+
browsable: true,
|
|
222
|
+
// LAST in the array on purpose — the noisiest surface in the registry. An empty query is a
|
|
223
|
+
// relevance guess across the WHOLE npm registry (the pinned per-runtime tag below narrows it),
|
|
224
|
+
// it is bound to no runtime, and its search serves the most rows. Every source above pins its
|
|
225
|
+
// rows to the artifact kind harder than npm does, so npm is the wide net an operator opts
|
|
226
|
+
// into, never the landing state.
|
|
227
|
+
//
|
|
228
|
+
// npm's registry search has NO `sort` and its documented ranking weights are inert today
|
|
229
|
+
// (measured 2026-10-25). `name`/`updated` are therefore ordered by the BACKEND over one maximum
|
|
230
|
+
// window of the registry's own ranking — server-side, not in the page, and the note names the
|
|
231
|
+
// window. `relevance` is the registry's untouched order.
|
|
232
|
+
sorts: ['relevance', 'updated', 'name'],
|
|
233
|
+
// The MCP axis opens on the author's own `mcp-server` tag (measured 2026-10-25: 10 501
|
|
234
|
+
// packages; the wider `model-context-protocol` tag at 41 344 is mostly SDKs and clients), and
|
|
235
|
+
// an mcp row resolves to a launch over the pinned spec (`npx -y <pkg@version>` + integrity).
|
|
236
|
+
// No `hosts`: a package is not bound to a runtime until the operator names the harness, and
|
|
237
|
+
// only a runtime with a verified package-manager landing can take it.
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
export function registerHarnessRoutes(app) {
|
|
241
|
+
// Source registry + health. The console derives its tab row from this, never from a hardcoded list.
|
|
242
|
+
app.get('/api/admin/harness/sources', async () => ({ status: 'ok', sources: SOURCES }));
|
|
243
|
+
// Host catalog + resolved roots. `origin` explains why a path is what it is.
|
|
244
|
+
app.get('/api/admin/harness/hosts', async () => ({
|
|
245
|
+
status: 'ok',
|
|
246
|
+
// The scopes this build accepts (ADR-0015 §D2 "Scope"). A consumer must read this instead of
|
|
247
|
+
// assuming a `project` landing exists: project support is deferred, and `roots` below carries
|
|
248
|
+
// exactly the scopes named here.
|
|
249
|
+
scopes: [...ENABLED_SCOPES],
|
|
250
|
+
hosts: HOSTS.map((host) => {
|
|
251
|
+
const roots = {
|
|
252
|
+
global: skillRootsFor(host.id, 'global'),
|
|
253
|
+
};
|
|
254
|
+
// `owner` names the host a copy would be recorded under in that scope. A host that is not its
|
|
255
|
+
// own owner is an alias: it reads a directory another host already owns.
|
|
256
|
+
return {
|
|
257
|
+
id: host.id,
|
|
258
|
+
label: host.label,
|
|
259
|
+
hasSkills: isSkillsHost(adapterFor(host.id)),
|
|
260
|
+
/** MCP-capable host: its adapter implements the MCP landing capability. */
|
|
261
|
+
hasMcp: isMcpHost(adapterFor(host.id)),
|
|
262
|
+
/** Extension-capable host: its adapter implements the extension landing capability. */
|
|
263
|
+
hasExt: isExtensionHost(adapterFor(host.id)),
|
|
264
|
+
roots,
|
|
265
|
+
owner: {
|
|
266
|
+
global: roots.global[0] ? skillOwner(roots.global[0].root, 'global') : null,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}),
|
|
270
|
+
}));
|
|
271
|
+
// Apply ledger — the audit trail behind every install/remove (ADR-0015 apply ledger).
|
|
272
|
+
app.get('/api/admin/harness/applies', async () => ({ status: 'ok', applies: recentApplies(100) }));
|
|
273
|
+
// Installed artifacts + untracked directories, reconciled per copy.
|
|
274
|
+
app.get('/api/admin/harness/inventory', async () => {
|
|
275
|
+
const inventory = scanInventory();
|
|
276
|
+
return {
|
|
277
|
+
status: 'ok',
|
|
278
|
+
...inventory,
|
|
279
|
+
paths: { manifest: manifestPath(), claims: claimsPath() },
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
// Dry run: nothing is written, and the plan expires in 10 minutes.
|
|
283
|
+
app.post('/api/admin/harness/plan', async (req, reply) => {
|
|
284
|
+
const body = (req.body || {});
|
|
285
|
+
if (body.action !== 'remove') {
|
|
286
|
+
reply.code(400);
|
|
287
|
+
return { status: 'error', code: 'unsupported_action', message: "only 'remove' is implemented" };
|
|
288
|
+
}
|
|
289
|
+
if (!Array.isArray(body.items) || body.items.length === 0) {
|
|
290
|
+
reply.code(400);
|
|
291
|
+
return { status: 'error', code: 'bad_request', message: 'items[] is required' };
|
|
292
|
+
}
|
|
293
|
+
// `planRemove` dereferences `item.copies` and `removal.op` directly; a shape check here turns a
|
|
294
|
+
// malformed body into a 400 instead of a TypeError surfacing as a 500.
|
|
295
|
+
for (const raw of body.items) {
|
|
296
|
+
const item = raw;
|
|
297
|
+
if (!item || typeof item !== 'object') {
|
|
298
|
+
reply.code(400);
|
|
299
|
+
return { status: 'error', code: 'bad_request', message: 'items[] entries must be objects' };
|
|
300
|
+
}
|
|
301
|
+
if (!Array.isArray(item.copies)) {
|
|
302
|
+
reply.code(400);
|
|
303
|
+
return { status: 'error', code: 'bad_request', message: 'items[].copies[] is required' };
|
|
304
|
+
}
|
|
305
|
+
if (item.removal !== undefined) {
|
|
306
|
+
const op = item.removal?.op;
|
|
307
|
+
if (op !== 'trash-path' && op !== 'drop-entry' && op !== 'drop-server') {
|
|
308
|
+
reply.code(400);
|
|
309
|
+
return { status: 'error', code: 'bad_request', message: `unknown removal op '${String(op)}'` };
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// artifactId null = a directory with no manifest entry; root containment is the guard.
|
|
314
|
+
const plan = planRemove(body.items);
|
|
315
|
+
if ('error' in plan) {
|
|
316
|
+
reply.code(400);
|
|
317
|
+
return { status: 'error', code: 'plan_rejected', message: plan.error };
|
|
318
|
+
}
|
|
319
|
+
return { status: 'ok', plan };
|
|
320
|
+
});
|
|
321
|
+
// Marketplace browse. An unavailable source answers with its reason instead of an empty list:
|
|
322
|
+
// an empty market reads as "nothing exists", which is a different (and false) claim.
|
|
323
|
+
app.get('/api/admin/harness/browse', async (req, reply) => {
|
|
324
|
+
const query = (req.query || {});
|
|
325
|
+
const source = SOURCES.find((s) => s.id === (query.source || 'github'));
|
|
326
|
+
if (!source) {
|
|
327
|
+
reply.code(404);
|
|
328
|
+
return { status: 'error', code: 'unknown_source', message: `unknown source '${query.source}'` };
|
|
329
|
+
}
|
|
330
|
+
// The market axis the console is browsing. Only npm forks on it today (default query + row
|
|
331
|
+
// install kind); a value outside the kind vocabulary is dropped, never forwarded.
|
|
332
|
+
const kind = ['skill', 'mcp', 'extension'].includes(query.kind ?? '')
|
|
333
|
+
? query.kind
|
|
334
|
+
: undefined;
|
|
335
|
+
// `page` is 1-based; a nonsense value falls back to the first page rather than answering empty.
|
|
336
|
+
const page = Math.max(Number(query.page) || 1, 1);
|
|
337
|
+
const result = await browseSource(source, query.q || '', Number(query.limit) || 24, {
|
|
338
|
+
...(query.harness ? { harness: query.harness } : {}),
|
|
339
|
+
...(kind ? { kind } : {}),
|
|
340
|
+
page,
|
|
341
|
+
// `sort` is validated against the source's OWN declared orderings inside `browseSource`: an
|
|
342
|
+
// order the upstream cannot serve is dropped, never forwarded as a guess.
|
|
343
|
+
...(query.sort ? { sort: query.sort } : {}),
|
|
344
|
+
// `refresh=1` is the console's explicit "ask again" — it drops this source's 60 s window so the
|
|
345
|
+
// answer is a new read, never a cached one. Anything else keeps the read-through.
|
|
346
|
+
...(query.refresh === '1' ? { refresh: true } : {}),
|
|
347
|
+
});
|
|
348
|
+
if (!result.ok) {
|
|
349
|
+
reply.code(result.code === 'unavailable' ? 409 : 502);
|
|
350
|
+
return {
|
|
351
|
+
status: 'error',
|
|
352
|
+
code: result.code,
|
|
353
|
+
// The console translates `reason`; `message` is the English fallback and the diagnostic.
|
|
354
|
+
...(result.reason ? { reason: result.reason } : {}),
|
|
355
|
+
...(result.reasonParams ? { reasonParams: result.reasonParams } : {}),
|
|
356
|
+
message: result.message,
|
|
357
|
+
source: source.id,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
status: 'ok',
|
|
362
|
+
source: source.id,
|
|
363
|
+
page,
|
|
364
|
+
items: result.items,
|
|
365
|
+
hasMore: result.hasMore,
|
|
366
|
+
...(result.total !== undefined ? { total: result.total } : {}),
|
|
367
|
+
note: result.note,
|
|
368
|
+
noteCode: result.noteCode,
|
|
369
|
+
noteParams: result.noteParams,
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
// On-demand GitHub stars for market rows — the popularity half most catalogs never publish.
|
|
373
|
+
//
|
|
374
|
+
// The market itself is read-only enrichment-free (a browse never spends star quota), so this is a
|
|
375
|
+
// SEPARATE, explicit call: the operator clicks, the console sends the repositories of the rows it is
|
|
376
|
+
// showing, and one batched search answers them. `missing` is named rather than absorbed: a row whose
|
|
377
|
+
// repo GitHub does not index keeps "unknown" instead of a fabricated 0.
|
|
378
|
+
//
|
|
379
|
+
// `cachedOnly: true` is the same read with the network REMOVED: it answers what the in-process star
|
|
380
|
+
// cache already holds, so the console can show a cached count the moment a page renders instead of
|
|
381
|
+
// asking for a click it would not spend (no unasked upstream spend, no held-back data).
|
|
382
|
+
app.post('/api/admin/harness/market/stars', async (req, reply) => {
|
|
383
|
+
const body = (req.body || {});
|
|
384
|
+
if (!Array.isArray(body.repos) || body.repos.length === 0) {
|
|
385
|
+
reply.code(400);
|
|
386
|
+
return { status: 'error', code: 'bad_request', message: "'repos' must be a non-empty array of `owner/repo` strings" };
|
|
387
|
+
}
|
|
388
|
+
const repos = body.repos.filter((v) => typeof v === 'string');
|
|
389
|
+
if (repos.length === 0) {
|
|
390
|
+
reply.code(400);
|
|
391
|
+
return { status: 'error', code: 'bad_request', message: "'repos' carried no strings" };
|
|
392
|
+
}
|
|
393
|
+
if (body.cachedOnly === true) {
|
|
394
|
+
return { status: 'ok', ...peekStarCache(repos) };
|
|
395
|
+
}
|
|
396
|
+
const result = await fetchRepoStars(repos);
|
|
397
|
+
if (!result.ok) {
|
|
398
|
+
reply.code(result.code === 'unavailable' ? 409 : 502);
|
|
399
|
+
return {
|
|
400
|
+
status: 'error',
|
|
401
|
+
code: result.code,
|
|
402
|
+
...(result.reason ? { reason: result.reason } : {}),
|
|
403
|
+
...(result.reasonParams ? { reasonParams: result.reasonParams } : {}),
|
|
404
|
+
message: result.message,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
return { status: 'ok', stars: result.stars, missing: result.missing, cached: result.cached };
|
|
408
|
+
});
|
|
409
|
+
// Market-row detail — the long-form half of a browse answer (README, licence, version).
|
|
410
|
+
//
|
|
411
|
+
// The console renders this in a native dialog rather than an iframe because the sources refuse
|
|
412
|
+
// framing: measured 2026-10-25, github.com answers `X-Frame-Options: deny`, npmjs.com
|
|
413
|
+
// `SAMEORIGIN` (plus a Cloudflare challenge) and pi.dev `SAMEORIGIN`. The endpoint therefore reads
|
|
414
|
+
// upstreams it chooses itself — the package name parsed out of `npm:<name>`, a validated
|
|
415
|
+
// `owner/repo`, or a `clawhub:<owner>/<slug>` pair — and NEVER follows a caller-supplied URL: that
|
|
416
|
+
// would turn an admin GET into an arbitrary-URL proxy.
|
|
417
|
+
app.get('/api/admin/harness/detail', async (req, reply) => {
|
|
418
|
+
const query = (req.query || {});
|
|
419
|
+
const source = SOURCES.find((s) => s.id === (query.source || 'github'));
|
|
420
|
+
if (!source) {
|
|
421
|
+
reply.code(404);
|
|
422
|
+
return { status: 'error', code: 'unknown_source', message: `unknown source '${query.source}'` };
|
|
423
|
+
}
|
|
424
|
+
const detail = await readMarketDetail({
|
|
425
|
+
...(query.key ? { key: query.key } : {}),
|
|
426
|
+
...(query.repo ? { repo: query.repo } : {}),
|
|
427
|
+
});
|
|
428
|
+
return { status: 'ok', source: source.id, detail };
|
|
429
|
+
});
|
|
430
|
+
// Install one artifact into one or more host locations — one store entry, N copies. The route
|
|
431
|
+
// speaks keys (`<sourceId>:<ref>[#detail]`); the SPI resolves the payload, the kind writer does
|
|
432
|
+
// the disk work. An `ambiguous` answer carries `candidates` — the console picks one and retries
|
|
433
|
+
// with a `#detail`-pinned key.
|
|
434
|
+
app.post('/api/admin/harness/install', async (req, reply) => {
|
|
435
|
+
const body = (req.body || {});
|
|
436
|
+
const hosts = Array.isArray(body.hosts) ? body.hosts.filter((h) => typeof h === 'string') : [];
|
|
437
|
+
if (hosts.length === 0 || !body.scope) {
|
|
438
|
+
reply.code(400);
|
|
439
|
+
return { status: 'error', code: 'bad_request', message: 'hosts[] and scope are required' };
|
|
440
|
+
}
|
|
441
|
+
// Scope is a capability, not a free-form field: this build installs to the user-level roots only
|
|
442
|
+
// (ADR-0015 §D2 "Scope"). The orchestrator keeps `scope` as the seam, so the refusal lives here —
|
|
443
|
+
// a request naming `project` must not reach a writer that would happily land inside the repo.
|
|
444
|
+
if (!isEnabledScope(body.scope)) {
|
|
445
|
+
reply.code(400);
|
|
446
|
+
return {
|
|
447
|
+
status: 'error',
|
|
448
|
+
code: 'unsupported_scope',
|
|
449
|
+
message: `scope '${body.scope}' is not supported — installs target ${ENABLED_SCOPES.join(', ')} scope`,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
// Validate the host catalog HERE, at the trust boundary: an unknown id would otherwise travel
|
|
453
|
+
// through resolve/write and fail deep inside a writer with a message about the wrong thing.
|
|
454
|
+
const unknown = hosts.find((id) => !HOSTS.some((host) => host.id === id));
|
|
455
|
+
if (unknown !== undefined) {
|
|
456
|
+
reply.code(400);
|
|
457
|
+
return { status: 'error', code: 'bad_request', message: `unknown host '${unknown}'` };
|
|
458
|
+
}
|
|
459
|
+
// The unknown-host check above already proved membership; this is the type narrowing, not a
|
|
460
|
+
// second validation.
|
|
461
|
+
const hostIds = hosts;
|
|
462
|
+
if (!body.key && !body.repo && !body.manualPayload && !body.manualSpec) {
|
|
463
|
+
reply.code(400);
|
|
464
|
+
return { status: 'error', code: 'bad_request', message: 'key, repo, manualPayload or manualSpec is required' };
|
|
465
|
+
}
|
|
466
|
+
// Kind is validated HERE, at the trust boundary, for the same reason as hosts above: an unknown
|
|
467
|
+
// kind must fail with a message about kind, not deep inside the orchestrator's default branch.
|
|
468
|
+
if (body.kind !== 'skill' && body.kind !== 'mcp' && body.kind !== 'extension') {
|
|
469
|
+
reply.code(400);
|
|
470
|
+
return { status: 'error', code: 'bad_request', message: `unknown kind '${body.kind}'` };
|
|
471
|
+
}
|
|
472
|
+
const kind = body.kind;
|
|
473
|
+
const manualPayload = body.manualPayload && typeof body.manualPayload.name === 'string' && body.manualPayload.launch
|
|
474
|
+
? { name: body.manualPayload.name, launch: body.manualPayload.launch }
|
|
475
|
+
: undefined;
|
|
476
|
+
// Listing surfaces are validated HERE, at the trust boundary, against the same registry the
|
|
477
|
+
// console builds its source chips from: a claim about where a row was browsed must name a source
|
|
478
|
+
// this gateway declares, or it is dropped rather than recorded.
|
|
479
|
+
const listedOn = Array.isArray(body.listedOn)
|
|
480
|
+
? body.listedOn.filter((id) => typeof id === 'string' && SOURCES.some((s) => s.id === id))
|
|
481
|
+
: undefined;
|
|
482
|
+
const result = await installArtifact({
|
|
483
|
+
sourceId: body.sourceId,
|
|
484
|
+
key: body.key,
|
|
485
|
+
repo: body.repo,
|
|
486
|
+
kind,
|
|
487
|
+
skillDir: body.skillDir,
|
|
488
|
+
manualPayload,
|
|
489
|
+
manualSpec: typeof body.manualSpec === 'string' ? body.manualSpec : undefined,
|
|
490
|
+
confirm: body.confirm === true,
|
|
491
|
+
listedOn,
|
|
492
|
+
hosts: hostIds,
|
|
493
|
+
scope: body.scope,
|
|
494
|
+
});
|
|
495
|
+
if (!result.ok) {
|
|
496
|
+
const status = result.code === 'exists' || result.code === 'foreign' || result.code === 'confirm_required'
|
|
497
|
+
? 409
|
|
498
|
+
: result.code === 'upstream' || result.code === 'unavailable'
|
|
499
|
+
? 502
|
|
500
|
+
: 400;
|
|
501
|
+
reply.code(status);
|
|
502
|
+
return { status: 'error', ...result };
|
|
503
|
+
}
|
|
504
|
+
return { status: 'ok', ...result };
|
|
505
|
+
});
|
|
506
|
+
// Description translation (derived cache; the model call goes through this gateway's own /v1).
|
|
507
|
+
// `format: 'markdown'` switches to the long-form contract: a README is a document, so it is
|
|
508
|
+
// translated in chunked prose runs (fenced code preserved verbatim) under its own cache namespace
|
|
509
|
+
// and a length budget — the description prompt would answer a 3 000-word page with two sentences.
|
|
510
|
+
app.post('/api/admin/harness/translate', async (req, reply) => {
|
|
511
|
+
const body = (req.body || {});
|
|
512
|
+
const text = (body.text || '').trim();
|
|
513
|
+
if (!text) {
|
|
514
|
+
reply.code(400);
|
|
515
|
+
return { status: 'error', code: 'bad_request', message: 'text is required' };
|
|
516
|
+
}
|
|
517
|
+
if (!body.lang) {
|
|
518
|
+
reply.code(400);
|
|
519
|
+
return { status: 'error', code: 'bad_request', message: 'lang is required' };
|
|
520
|
+
}
|
|
521
|
+
const result = body.format === 'markdown'
|
|
522
|
+
? await translateMarkdown(text, body.lang)
|
|
523
|
+
: await translateDescription(text, body.lang);
|
|
524
|
+
if ('code' in result) {
|
|
525
|
+
reply.code(result.code === 'no_api_key' ? 409 : 502);
|
|
526
|
+
return { status: 'error', ...result };
|
|
527
|
+
}
|
|
528
|
+
return { status: 'ok', ...result };
|
|
529
|
+
});
|
|
530
|
+
// Batch translation. One chunk per call, small in-process pool: the console walks the list in
|
|
531
|
+
// chunks so a slow tier never turns one request into a 60-second hang, and a dropped connection
|
|
532
|
+
// resumes from the cache instead of losing everything.
|
|
533
|
+
app.post('/api/admin/harness/translate-batch', async (req, reply) => {
|
|
534
|
+
const body = (req.body || {});
|
|
535
|
+
if (!body.lang || !Array.isArray(body.texts)) {
|
|
536
|
+
reply.code(400);
|
|
537
|
+
return { status: 'error', code: 'bad_request', message: 'lang and texts[] are required' };
|
|
538
|
+
}
|
|
539
|
+
const texts = [
|
|
540
|
+
...new Set(body.texts.filter((x) => typeof x === 'string' && x.trim().length > 0).map((x) => x.trim())),
|
|
541
|
+
].slice(0, 50);
|
|
542
|
+
if (texts.length === 0)
|
|
543
|
+
return { status: 'ok', results: {}, errors: [] };
|
|
544
|
+
const results = {};
|
|
545
|
+
const errors = [];
|
|
546
|
+
let cursor = 0;
|
|
547
|
+
const worker = async () => {
|
|
548
|
+
while (cursor < texts.length) {
|
|
549
|
+
const text = texts[cursor++];
|
|
550
|
+
const result = await translateDescription(text, body.lang);
|
|
551
|
+
if ('code' in result)
|
|
552
|
+
errors.push({ text, code: result.code, message: result.message });
|
|
553
|
+
else
|
|
554
|
+
results[text] = result;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
await Promise.all(Array.from({ length: Math.min(3, texts.length) }, worker));
|
|
558
|
+
// No key = every item fails the same way; say it once instead of 50 identical rows.
|
|
559
|
+
if (errors.length === texts.length && errors.every((e) => e.code === 'no_api_key')) {
|
|
560
|
+
reply.code(409);
|
|
561
|
+
return { status: 'error', code: 'no_api_key', message: errors[0].message };
|
|
562
|
+
}
|
|
563
|
+
return { status: 'ok', results, errors };
|
|
564
|
+
});
|
|
565
|
+
// Cache-only lookup: the console seeds every already-translated description on mount, no spend.
|
|
566
|
+
app.post('/api/admin/harness/translations', async (req, reply) => {
|
|
567
|
+
const body = (req.body || {});
|
|
568
|
+
if (!body.lang || !Array.isArray(body.texts)) {
|
|
569
|
+
reply.code(400);
|
|
570
|
+
return { status: 'error', code: 'bad_request', message: 'lang and texts[] are required' };
|
|
571
|
+
}
|
|
572
|
+
const texts = body.texts
|
|
573
|
+
.filter((x) => typeof x === 'string' && x.trim().length > 0)
|
|
574
|
+
.slice(0, 500);
|
|
575
|
+
return {
|
|
576
|
+
status: 'ok',
|
|
577
|
+
translations: readCachedTranslations(texts, body.lang, body.format === 'markdown' ? 'readme' : 'descriptions'),
|
|
578
|
+
};
|
|
579
|
+
});
|
|
580
|
+
// Housekeeping on the derived translation store: age expiry, then oldest-first trimming under the
|
|
581
|
+
// size budget. Writes sweep on a throttle; this is the manual lever for an operator (or a future
|
|
582
|
+
// console button) that wants it now. Nothing here is correctness-bearing — the cache is derived.
|
|
583
|
+
app.post('/api/admin/harness/translations/prune', async (req) => {
|
|
584
|
+
const body = (req.body || {});
|
|
585
|
+
const maxAgeDays = typeof body.maxAgeDays === 'number' ? body.maxAgeDays : undefined;
|
|
586
|
+
const maxBytes = typeof body.maxBytes === 'number' ? body.maxBytes : undefined;
|
|
587
|
+
const stats = pruneTranslationStore({
|
|
588
|
+
...(maxAgeDays !== undefined ? { maxAgeMs: Math.max(maxAgeDays, 0) * 24 * 60 * 60 * 1000 } : {}),
|
|
589
|
+
...(maxBytes !== undefined ? { maxBytes: Math.max(maxBytes, 0) } : {}),
|
|
590
|
+
});
|
|
591
|
+
return { status: 'ok', ...stats };
|
|
592
|
+
});
|
|
593
|
+
// Chain probe behind the console's default-model "test" buttons. `model` in the body carries the
|
|
594
|
+
// PICKER'S PENDING value (test BEFORE save; empty string = "as if unset"); absent → the saved
|
|
595
|
+
// config. Both probes under one diagnostic contract: explicit click = explicit one-call spend,
|
|
596
|
+
// honest verdicts, nothing persisted by the probe itself.
|
|
597
|
+
app.post('/api/admin/harness/translations/probe', async (req) => {
|
|
598
|
+
const body = (req.body || {});
|
|
599
|
+
return probeTranslationChain(typeof body.lang === 'string' ? body.lang : 'en', typeof body.model === 'string' ? body.model : undefined);
|
|
600
|
+
});
|
|
601
|
+
// System One default-model probe — the Settings "默认模型" card's second "test" button. Fires
|
|
602
|
+
// the REAL /v1/systemone fallback path; with a pending selection it rides as an explicit
|
|
603
|
+
// `model` through the surface's own admission gates.
|
|
604
|
+
app.post('/api/admin/systemone/probe', async (req) => {
|
|
605
|
+
const body = (req.body || {});
|
|
606
|
+
return probeSystemoneDefault(typeof body.model === 'string' ? body.model : undefined);
|
|
607
|
+
});
|
|
608
|
+
// Execute a plan. 409 for every refusal — the plan is stale, unknown, or needs a discard flag.
|
|
609
|
+
app.post('/api/admin/harness/apply', async (req, reply) => {
|
|
610
|
+
const body = (req.body || {});
|
|
611
|
+
if (!body.planId) {
|
|
612
|
+
reply.code(400);
|
|
613
|
+
return { status: 'error', code: 'bad_request', message: 'planId is required' };
|
|
614
|
+
}
|
|
615
|
+
const result = applyRemove(body.planId, { discardLocalEdits: body.discardLocalEdits === true });
|
|
616
|
+
if (!result.ok) {
|
|
617
|
+
reply.code(409);
|
|
618
|
+
return { status: 'error', code: result.code, message: result.message };
|
|
619
|
+
}
|
|
620
|
+
return { status: 'ok', ...result };
|
|
621
|
+
});
|
|
622
|
+
}
|
package/backend/dist/server.js
CHANGED
|
@@ -6,6 +6,7 @@ import { getRateLimiter, apiKeySubject } from './ratelimit/rate-limiter.js';
|
|
|
6
6
|
import { getRateLimitEventLog, recordRateLimitEvent } from './ratelimit/event-log.js';
|
|
7
7
|
import { getFailureEventLog } from './observability/failure-events.js';
|
|
8
8
|
import { registerEnvironmentRoutes } from './routes/environments.js';
|
|
9
|
+
import { registerHarnessRoutes } from './routes/harness.js';
|
|
9
10
|
import { SURFACES } from './surfaces/table.js';
|
|
10
11
|
import { createFastifyTransport } from './surfaces/transport-fastify.js';
|
|
11
12
|
import { dispatchSurface } from './surfaces/dispatch.js';
|
|
@@ -608,6 +609,9 @@ providerConfigs = []) {
|
|
|
608
609
|
const removed = getFailureEventLog().remove(id);
|
|
609
610
|
return { status: 'ok', removed };
|
|
610
611
|
});
|
|
612
|
+
// Harness domain (ADR-0015) — source registry, host catalog, inventory, market browse/detail,
|
|
613
|
+
// install + remove writers, and the derived-translation store.
|
|
614
|
+
registerHarnessRoutes(app);
|
|
611
615
|
// 1C. Reset Tripped Circuit Breakers (Admin recovery after quota top-up)
|
|
612
616
|
// optional `scope` (default 'model' = legacy behavior):
|
|
613
617
|
// model -> the model breaker (bare modelId); no model = reset everything
|
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { TIER_RANK } from '../types/router.js';
|
|
5
|
+
import { renameWithRetry } from '../utils/atomic-write.js';
|
|
5
6
|
// Memory/safety bounds — intentionally NOT config-exposed: they tune memory,
|
|
6
7
|
// not product behavior.
|
|
7
8
|
const TAIL_WINDOW = 8; // messages per registered tail window
|
|
@@ -790,7 +791,7 @@ export class SessionManager {
|
|
|
790
791
|
fs.mkdirSync(path.dirname(this.persistPath), { recursive: true });
|
|
791
792
|
const tmp = `${this.persistPath}.tmp`;
|
|
792
793
|
fs.writeFileSync(tmp, JSON.stringify(data), 'utf8');
|
|
793
|
-
|
|
794
|
+
renameWithRetry(tmp, this.persistPath);
|
|
794
795
|
}
|
|
795
796
|
catch {
|
|
796
797
|
// Fail-open: persistence is best-effort continuity, never a hot-path error.
|