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,234 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getOcrHomeDir } from '../cli/paths.js';
|
|
4
|
+
import { getEnvRootDir, resolveEnvName } from '../config/env.js';
|
|
5
|
+
import { renameWithRetry } from '../utils/atomic-write.js';
|
|
6
|
+
/**
|
|
7
|
+
* Ownership records for harness artifacts (ADR-0015 §D4).
|
|
8
|
+
*
|
|
9
|
+
* Two layers:
|
|
10
|
+
* - intent `<env>/harness/manifest.json` — what THIS environment wants installed
|
|
11
|
+
* - claims `<ocrHome>/harness/claims.json` — which environment owns a materialized path
|
|
12
|
+
*
|
|
13
|
+
* The split is what prevents the data-loss case: two environments claiming one path would let either
|
|
14
|
+
* one delete the other's files. A foreign claim is transfer-only.
|
|
15
|
+
*
|
|
16
|
+
* Manifest v2 adds the artifact-level `harness` dimension for extensions. v1 files are migrated in
|
|
17
|
+
* memory on read and persisted as v2 by the next write — a read never rewrites `manifest.json`.
|
|
18
|
+
* The one side-file a read may append is `manifest.orphans.json`: a v1 extension record with no copy
|
|
19
|
+
* has no host, so v2 cannot name it; retiring it quietly would delete the only record that it ever
|
|
20
|
+
* existed, and keeping it in v2 would leave a row no harness page can show or remove.
|
|
21
|
+
*/
|
|
22
|
+
const EMPTY_MANIFEST = { version: 2, artifacts: [] };
|
|
23
|
+
const EMPTY_CLAIMS = { version: 1, claims: {} };
|
|
24
|
+
/** Version this process WRITES. v1 files are migrated in memory on read (see `readManifest`). */
|
|
25
|
+
const MANIFEST_VERSION = 2;
|
|
26
|
+
export function harnessEnvDir() {
|
|
27
|
+
return path.join(getEnvRootDir(), 'harness');
|
|
28
|
+
}
|
|
29
|
+
export function manifestPath() {
|
|
30
|
+
return path.join(harnessEnvDir(), 'manifest.json');
|
|
31
|
+
}
|
|
32
|
+
/** Retirement file for v1 extension records that carry no host (see `migrateV1`). */
|
|
33
|
+
export function orphansPath() {
|
|
34
|
+
return path.join(harnessEnvDir(), 'manifest.orphans.json');
|
|
35
|
+
}
|
|
36
|
+
export function claimsPath() {
|
|
37
|
+
return path.join(getOcrHomeDir(), 'harness', 'claims.json');
|
|
38
|
+
}
|
|
39
|
+
/** Move an unusable state file aside so its bytes survive the next whole-file write. */
|
|
40
|
+
function setAside(file, why) {
|
|
41
|
+
const aside = `${file}.corrupt-${Date.now()}`;
|
|
42
|
+
try {
|
|
43
|
+
fs.renameSync(file, aside);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// A rename that fails leaves the original in place — still not a reason to overwrite it.
|
|
47
|
+
throw new Error(`${path.basename(file)} is not usable (${why}) and could not be set aside`);
|
|
48
|
+
}
|
|
49
|
+
console.error(`[harness] ${path.basename(file)} is not usable (${why}); kept as ${path.basename(aside)}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read a JSON state file. Absent means "first run" and answers the fallback; everything else is a
|
|
53
|
+
* failure to report, never an empty baseline — every caller writes this file back whole, so a
|
|
54
|
+
* fallback returned over an UNREADABLE file would silently replace the ledger it could not read.
|
|
55
|
+
*
|
|
56
|
+
* · read error (EBUSY from an indexer/AV, EACCES): throw. A transient lock must fail the operation,
|
|
57
|
+
* not become a fresh empty state.
|
|
58
|
+
* · unparsable bytes: move the file aside, then answer the fallback — the next write starts a new
|
|
59
|
+
* file instead of eating it.
|
|
60
|
+
*/
|
|
61
|
+
function readJson(file, fallback) {
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
if (!fs.existsSync(file))
|
|
65
|
+
return fallback;
|
|
66
|
+
raw = fs.readFileSync(file, 'utf8');
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
throw new Error(`cannot read ${path.basename(file)}: ${e instanceof Error ? e.message : String(e)}`);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(raw);
|
|
73
|
+
return parsed ?? fallback;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
setAside(file, 'not valid JSON');
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function writeJson(file, data) {
|
|
81
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
82
|
+
const tmp = `${file}.tmp.${process.pid}.${Date.now()}`;
|
|
83
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
84
|
+
renameWithRetry(tmp, file);
|
|
85
|
+
}
|
|
86
|
+
export function readManifest() {
|
|
87
|
+
const file = manifestPath();
|
|
88
|
+
const data = readJson(file, EMPTY_MANIFEST);
|
|
89
|
+
if (!data || (data.version !== 1 && data.version !== 2) || !Array.isArray(data.artifacts)) {
|
|
90
|
+
// Present but unrecognised: the same rule as unparsable bytes — set aside, never overwrite.
|
|
91
|
+
if (fs.existsSync(file))
|
|
92
|
+
setAside(file, 'unrecognised manifest shape');
|
|
93
|
+
return EMPTY_MANIFEST;
|
|
94
|
+
}
|
|
95
|
+
return data.version === 1 ? migrateV1(data) : data;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* v1 → v2 in memory (no `manifest.json` write here; the next `writeManifest` persists it).
|
|
99
|
+
*
|
|
100
|
+
* v1 predates the harness dimension: an extension record was `extension:<canonicalKey>` with ONE
|
|
101
|
+
* copy per host, i.e. the same package installed into several runtimes shared one identity. In v2
|
|
102
|
+
* the runtime is part of the identity, so such a record SPLITS into one record per copy host —
|
|
103
|
+
* `extension:<host>:<canonicalKey>`, that host's copies only, `harness` set to that host.
|
|
104
|
+
* Every other kind is unchanged: for skills/MCP the host is a landing, never an identity.
|
|
105
|
+
*
|
|
106
|
+
* v1 also had no `external` marker: the subprocess branch recorded a placeholder token
|
|
107
|
+
* `<canonicalKey>#<host>` as if it were a location, which is why every pi extension reported
|
|
108
|
+
* 'missing'. The token was written verbatim by that branch, so an EXACT match re-marks the copy —
|
|
109
|
+
* a migrated record then behaves exactly like a fresh single-harness apply.
|
|
110
|
+
*
|
|
111
|
+
* A copy-less legacy record carries no host, so its harness is unknowable. It cannot stay in v2
|
|
112
|
+
* (`extension:<canonicalKey>` names no harness, so every harness page hides it — installed, yet
|
|
113
|
+
* invisible and unremovable) and it must not be dropped either (that erases the only record it ever
|
|
114
|
+
* existed). It is retired to `manifest.orphans.json` instead, and only then removed from v2.
|
|
115
|
+
*/
|
|
116
|
+
function migrateV1(data) {
|
|
117
|
+
const artifacts = [];
|
|
118
|
+
const orphans = [];
|
|
119
|
+
for (const record of data.artifacts) {
|
|
120
|
+
const legacyExtensionId = `extension:${record.canonicalKey}`;
|
|
121
|
+
if (record.kind !== 'extension' || record.id !== legacyExtensionId) {
|
|
122
|
+
artifacts.push(record);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const byHost = new Map();
|
|
126
|
+
for (const copy of record.copies) {
|
|
127
|
+
const migrated = copy.external === undefined && copy.path === `${record.canonicalKey}#${copy.host}`
|
|
128
|
+
? { ...copy, external: true }
|
|
129
|
+
: copy;
|
|
130
|
+
const list = byHost.get(copy.host) ?? [];
|
|
131
|
+
list.push(migrated);
|
|
132
|
+
byHost.set(copy.host, list);
|
|
133
|
+
}
|
|
134
|
+
if (byHost.size === 0) {
|
|
135
|
+
orphans.push(record);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
for (const [host, copies] of byHost) {
|
|
139
|
+
artifacts.push({
|
|
140
|
+
...record,
|
|
141
|
+
id: `extension:${host}:${record.canonicalKey}`,
|
|
142
|
+
harness: host,
|
|
143
|
+
copies,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { version: 2, artifacts: retireOrphans(orphans, artifacts) };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Persist host-less legacy records and return the v2 artifact list WITHOUT them.
|
|
151
|
+
*
|
|
152
|
+
* Losing the record is worse than leaving a ghost: if the side-file cannot be written, the records
|
|
153
|
+
* stay in the migrated manifest verbatim (and the reason is logged), because an unwritable retirement
|
|
154
|
+
* file must never turn into data loss.
|
|
155
|
+
*/
|
|
156
|
+
function retireOrphans(orphans, artifacts) {
|
|
157
|
+
if (orphans.length === 0)
|
|
158
|
+
return artifacts;
|
|
159
|
+
let appended;
|
|
160
|
+
try {
|
|
161
|
+
appended = appendOrphans(orphans);
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
// Keep the records rather than lose them: an unwritable side-file must not become data loss.
|
|
165
|
+
console.warn(`[harness] could not retire ${orphans.length} v1 extension record(s) with no host — kept in manifest.json: ${e instanceof Error ? e.message : String(e)}`);
|
|
166
|
+
return [...artifacts, ...orphans];
|
|
167
|
+
}
|
|
168
|
+
if (appended > 0) {
|
|
169
|
+
console.warn(`[harness] retired ${appended} v1 extension record(s) with no host to ${orphansPath()} (they name no harness, so no harness page can show or remove them)`);
|
|
170
|
+
}
|
|
171
|
+
return artifacts;
|
|
172
|
+
}
|
|
173
|
+
/** Append new orphans by id (idempotent: a re-read of the same v1 file adds nothing). */
|
|
174
|
+
function appendOrphans(records) {
|
|
175
|
+
const file = orphansPath();
|
|
176
|
+
const existing = readJson(file, []);
|
|
177
|
+
const rows = Array.isArray(existing) ? existing : [];
|
|
178
|
+
const known = new Set(rows.map((row) => row?.record?.id).filter((id) => typeof id === 'string'));
|
|
179
|
+
const migratedAt = new Date().toISOString();
|
|
180
|
+
const fresh = records
|
|
181
|
+
.filter((record) => !known.has(record.id))
|
|
182
|
+
.map((record) => ({ migratedAt, record }));
|
|
183
|
+
if (fresh.length === 0)
|
|
184
|
+
return 0;
|
|
185
|
+
writeJson(file, [...rows, ...fresh]);
|
|
186
|
+
return fresh.length;
|
|
187
|
+
}
|
|
188
|
+
export function writeManifest(data) {
|
|
189
|
+
// Always v2 on disk: the writer owns the version, callers never have to remember to bump it.
|
|
190
|
+
writeJson(manifestPath(), { ...data, version: MANIFEST_VERSION });
|
|
191
|
+
}
|
|
192
|
+
export function readClaims() {
|
|
193
|
+
const data = readJson(claimsPath(), EMPTY_CLAIMS);
|
|
194
|
+
if (!data || data.version !== 1 || typeof data.claims !== 'object')
|
|
195
|
+
return EMPTY_CLAIMS;
|
|
196
|
+
return data;
|
|
197
|
+
}
|
|
198
|
+
export function writeClaims(data) {
|
|
199
|
+
writeJson(claimsPath(), data);
|
|
200
|
+
}
|
|
201
|
+
/** Can the active environment own this path? */
|
|
202
|
+
export function canClaim(absPath, envName = resolveEnvName()) {
|
|
203
|
+
const claim = readClaims().claims[absPath];
|
|
204
|
+
if (!claim)
|
|
205
|
+
return { ok: true };
|
|
206
|
+
if (claim.env === envName)
|
|
207
|
+
return { ok: true };
|
|
208
|
+
return { ok: false, reason: 'foreign', env: claim.env, artifactId: claim.artifactId };
|
|
209
|
+
}
|
|
210
|
+
/** Register a claim; refuses to steal another environment's path. */
|
|
211
|
+
export function claimPath(absPath, artifactId, envName = resolveEnvName()) {
|
|
212
|
+
const verdict = canClaim(absPath, envName);
|
|
213
|
+
if (!verdict.ok)
|
|
214
|
+
return verdict;
|
|
215
|
+
const data = readClaims();
|
|
216
|
+
data.claims[absPath] = { env: envName, artifactId };
|
|
217
|
+
writeClaims(data);
|
|
218
|
+
return { ok: true };
|
|
219
|
+
}
|
|
220
|
+
export function releaseClaim(absPath, envName = resolveEnvName()) {
|
|
221
|
+
const data = readClaims();
|
|
222
|
+
const claim = data.claims[absPath];
|
|
223
|
+
if (!claim || claim.env !== envName)
|
|
224
|
+
return;
|
|
225
|
+
delete data.claims[absPath];
|
|
226
|
+
writeClaims(data);
|
|
227
|
+
}
|
|
228
|
+
/** Environment a path is claimed by, if any. */
|
|
229
|
+
export function claimOwner(absPath) {
|
|
230
|
+
return readClaims().claims[absPath]?.env ?? null;
|
|
231
|
+
}
|
|
232
|
+
export function findArtifact(artifactId) {
|
|
233
|
+
return readManifest().artifacts.find((a) => a.id === artifactId);
|
|
234
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure vocabulary shared by every reader, plus the English sentence that stands in for it, plus
|
|
3
|
+
* the ONE retry policy a market read applies before it reports that sentence.
|
|
4
|
+
*
|
|
5
|
+
* A runtime's own message ("The socket connection was closed unexpectedly. For more information, pass
|
|
6
|
+
* `verbose: true` in the second argument to fetch()") names no subject, states no consequence, and
|
|
7
|
+
* prescribes an option this console cannot set: diagnostics for us, prose for nobody. Every reader
|
|
8
|
+
* therefore reports a `FailureReason` the console can TRANSLATE, keeps `message` as the English
|
|
9
|
+
* fallback (an unmapped reason still shows a sentence, never a key), and drops the runtime text — the
|
|
10
|
+
* coarse failure class stays in `code`, which is what code branches on.
|
|
11
|
+
*/
|
|
12
|
+
export type FailureReason =
|
|
13
|
+
/** The request never reached an answer (reset, DNS, refused). */
|
|
14
|
+
'network'
|
|
15
|
+
/** The request was still running when its deadline expired. */
|
|
16
|
+
| 'timeout'
|
|
17
|
+
/** The upstream answered a status this reader cannot use; `reasonParams.status` carries it. */
|
|
18
|
+
| 'http'
|
|
19
|
+
/** The upstream asked us to slow down; a token or a later retry is the operator's move. */
|
|
20
|
+
| 'rateLimited'
|
|
21
|
+
/** Throttled or broken upstream — the same call is expected to work later. */
|
|
22
|
+
| 'unavailable'
|
|
23
|
+
/** The page answered 200 but no longer carries what this reader parses (undocumented markup). */
|
|
24
|
+
| 'markupChanged'
|
|
25
|
+
/** The answer was not the shape this reader decodes (non-JSON, wrong envelope). */
|
|
26
|
+
| 'badPayload'
|
|
27
|
+
/** No adapter serves this source at all. */
|
|
28
|
+
| 'unsupportedSource';
|
|
29
|
+
/** The reason half of a failed read, keyed to a console translation. */
|
|
30
|
+
export declare function fetchFailureReason(error: unknown): FailureReason;
|
|
31
|
+
/** The English fallback sentence for `fetchFailureReason(error)`. */
|
|
32
|
+
export declare function describeFetchFailure(subject: string, error: unknown): string;
|
|
33
|
+
/**
|
|
34
|
+
* How a market read retries a FAILED answer, declared once for every reader.
|
|
35
|
+
*
|
|
36
|
+
* A market read is an idempotent GET, so ANY failed answer earns another ask while attempts and
|
|
37
|
+
* budget last — a thrown reset, a 5xx, and also a 4xx: npm's CDN answers a transient 404 while a
|
|
38
|
+
* publish propagates, and a 403/429 can be a burst window shorter than the backoff. The one early
|
|
39
|
+
* return left is a `Retry-After` the remaining budget cannot fit: the server named a wait the
|
|
40
|
+
* policy cannot honor, so another ask is provably futile and the answer comes back at once. A
|
|
41
|
+
* `Retry-After` that DOES fit floors the next sleep instead, so the retry does not land inside
|
|
42
|
+
* the window it was told about.
|
|
43
|
+
*
|
|
44
|
+
* `attempts` is a CEILING, `budgetMs` is the contract: an attempt's deadline is whatever is left of
|
|
45
|
+
* the budget, so five attempts of a fast-failing endpoint fit inside 30 s with room to spare, while
|
|
46
|
+
* a hard timeout spends the budget on about four 6 s tries and the caller gets its `timeout` when
|
|
47
|
+
* the 30 s are gone — never later, because the budget caps the sleeps too.
|
|
48
|
+
*/
|
|
49
|
+
export interface RetryPolicy {
|
|
50
|
+
/** Attempts including the first. */
|
|
51
|
+
attempts: number;
|
|
52
|
+
/** Delay before the FIRST retry; later delays multiply by `factor`. */
|
|
53
|
+
firstDelayMs: number;
|
|
54
|
+
factor: number;
|
|
55
|
+
/** Total wall clock across every attempt and every sleep. */
|
|
56
|
+
budgetMs: number;
|
|
57
|
+
/** Per-attempt deadline (further capped by whatever remains of `budgetMs`). */
|
|
58
|
+
timeoutMs: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The market-read policy: 5 attempts, 400 ms → 800 ms → 1.6 s → 3.2 s (±20 % jitter), 6 s per
|
|
62
|
+
* attempt, 30 s total.
|
|
63
|
+
*
|
|
64
|
+
* Worst case is therefore ~30 s of operator-visible latency — the ceiling the operator accepted
|
|
65
|
+
* (2026-10-25): a hard-hanging upstream gets about four full 6 s attempts before the budget runs
|
|
66
|
+
* out, a fast-failing one (a reset after ~50 ms) gets all five asks inside ~7 s, and a single
|
|
67
|
+
* blip is still repaired in under half a second.
|
|
68
|
+
*/
|
|
69
|
+
export declare const MARKET_RETRY: RetryPolicy;
|
|
70
|
+
export interface RetryDeps {
|
|
71
|
+
/** Test seam: the existing `fetchImpl` parameter every reader already accepts. */
|
|
72
|
+
fetchImpl?: typeof fetch;
|
|
73
|
+
/** Test seam: a no-op here keeps a retry test from actually sleeping. */
|
|
74
|
+
sleep?: (ms: number) => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `fetch` with the market retry policy applied.
|
|
78
|
+
*
|
|
79
|
+
* The helper OWNS the per-attempt deadline (a caller-supplied `signal` is replaced): one shared
|
|
80
|
+
* timeout per attempt is what makes the budget arithmetic above true.
|
|
81
|
+
*
|
|
82
|
+
* It returns the LAST response whatever its status — mapping a status to `FailureReason` stays the
|
|
83
|
+
* caller's job, so no reader loses the vocabulary it already reports. When every attempt threw, the
|
|
84
|
+
* last error is rethrown and the caller's existing `catch` produces the sentence, unchanged.
|
|
85
|
+
*/
|
|
86
|
+
export declare function fetchWithRetry(input: string, init?: RequestInit, policy?: RetryPolicy, deps?: RetryDeps): Promise<Response>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** The reason half of a failed read, keyed to a console translation. */
|
|
2
|
+
export function fetchFailureReason(error) {
|
|
3
|
+
const name = error instanceof Error ? error.name : '';
|
|
4
|
+
// AbortSignal.timeout() aborts the request, so a timeout surfaces as an AbortError/TimeoutError.
|
|
5
|
+
return name === 'TimeoutError' || name === 'AbortError' ? 'timeout' : 'network';
|
|
6
|
+
}
|
|
7
|
+
/** The English fallback sentence for `fetchFailureReason(error)`. */
|
|
8
|
+
export function describeFetchFailure(subject, error) {
|
|
9
|
+
return fetchFailureReason(error) === 'timeout'
|
|
10
|
+
? `${subject} timed out — try again in a moment`
|
|
11
|
+
: `${subject} could not be reached — check the network connection and try again`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The market-read policy: 5 attempts, 400 ms → 800 ms → 1.6 s → 3.2 s (±20 % jitter), 6 s per
|
|
15
|
+
* attempt, 30 s total.
|
|
16
|
+
*
|
|
17
|
+
* Worst case is therefore ~30 s of operator-visible latency — the ceiling the operator accepted
|
|
18
|
+
* (2026-10-25): a hard-hanging upstream gets about four full 6 s attempts before the budget runs
|
|
19
|
+
* out, a fast-failing one (a reset after ~50 ms) gets all five asks inside ~7 s, and a single
|
|
20
|
+
* blip is still repaired in under half a second.
|
|
21
|
+
*/
|
|
22
|
+
export const MARKET_RETRY = {
|
|
23
|
+
attempts: 5,
|
|
24
|
+
firstDelayMs: 400,
|
|
25
|
+
factor: 2,
|
|
26
|
+
budgetMs: 30_000,
|
|
27
|
+
timeoutMs: 6_000,
|
|
28
|
+
};
|
|
29
|
+
/** An attempt is not worth starting with less than this left — it would time out on arrival. */
|
|
30
|
+
const MIN_ATTEMPT_MS = 1_000;
|
|
31
|
+
/** Jitter keeps a page that fires several reads at once from retrying in lockstep. */
|
|
32
|
+
const JITTER = 0.2;
|
|
33
|
+
/**
|
|
34
|
+
* The server's own "ask again after N seconds", or 0 when the answer carries no usable
|
|
35
|
+
* `Retry-After` (an HTTP-date is not parsed — the plain backoff applies then, bounded by the
|
|
36
|
+
* budget like everything else).
|
|
37
|
+
*/
|
|
38
|
+
function retryAfterMs(res) {
|
|
39
|
+
const raw = res.headers.get('retry-after');
|
|
40
|
+
if (!raw)
|
|
41
|
+
return 0;
|
|
42
|
+
const seconds = Number(raw);
|
|
43
|
+
return Number.isFinite(seconds) ? Math.max(0, Math.round(seconds * 1000)) : 0;
|
|
44
|
+
}
|
|
45
|
+
function defaultSleep(ms) {
|
|
46
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `fetch` with the market retry policy applied.
|
|
50
|
+
*
|
|
51
|
+
* The helper OWNS the per-attempt deadline (a caller-supplied `signal` is replaced): one shared
|
|
52
|
+
* timeout per attempt is what makes the budget arithmetic above true.
|
|
53
|
+
*
|
|
54
|
+
* It returns the LAST response whatever its status — mapping a status to `FailureReason` stays the
|
|
55
|
+
* caller's job, so no reader loses the vocabulary it already reports. When every attempt threw, the
|
|
56
|
+
* last error is rethrown and the caller's existing `catch` produces the sentence, unchanged.
|
|
57
|
+
*/
|
|
58
|
+
export async function fetchWithRetry(input, init = {}, policy = MARKET_RETRY, deps = {}) {
|
|
59
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
60
|
+
const sleep = deps.sleep ?? defaultSleep;
|
|
61
|
+
const started = Date.now();
|
|
62
|
+
let delay = policy.firstDelayMs;
|
|
63
|
+
/** A `Retry-After` the last answer asked for: the next sleep may not dip below it. */
|
|
64
|
+
let sleepFloorMs = 0;
|
|
65
|
+
let lastError;
|
|
66
|
+
let lastResponse;
|
|
67
|
+
for (let attempt = 1; attempt <= policy.attempts; attempt += 1) {
|
|
68
|
+
if (attempt > 1) {
|
|
69
|
+
const left = policy.budgetMs - (Date.now() - started);
|
|
70
|
+
if (left <= MIN_ATTEMPT_MS)
|
|
71
|
+
break;
|
|
72
|
+
// Jitter, then never sleep away the floor an attempt needs — nor below the server's ask.
|
|
73
|
+
const jittered = Math.max(delay * (1 - JITTER + Math.random() * JITTER * 2), sleepFloorMs);
|
|
74
|
+
sleepFloorMs = 0;
|
|
75
|
+
await sleep(Math.max(Math.min(jittered, left - MIN_ATTEMPT_MS), 0));
|
|
76
|
+
delay *= policy.factor;
|
|
77
|
+
}
|
|
78
|
+
const left = policy.budgetMs - (Date.now() - started);
|
|
79
|
+
const timeoutMs = Math.min(policy.timeoutMs, Math.max(left, MIN_ATTEMPT_MS));
|
|
80
|
+
try {
|
|
81
|
+
lastResponse = await fetchImpl(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
lastError = e;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// A successful answer ends the loop at once — only a FAILED one is ever asked again. The last
|
|
88
|
+
// attempt's answer, whatever its status: hand it back untouched.
|
|
89
|
+
if (lastResponse.ok || attempt === policy.attempts)
|
|
90
|
+
return lastResponse;
|
|
91
|
+
// Every OTHER answer earns another ask — but one more attempt has to fit, sleep included, and
|
|
92
|
+
// a `Retry-After` the remaining budget cannot cover makes that ask provably futile. A
|
|
93
|
+
// `Retry-After` that fits floors the upcoming sleep instead.
|
|
94
|
+
const raMs = retryAfterMs(lastResponse);
|
|
95
|
+
if (policy.budgetMs - (Date.now() - started) <= MIN_ATTEMPT_MS + Math.max(delay, raMs)) {
|
|
96
|
+
return lastResponse;
|
|
97
|
+
}
|
|
98
|
+
sleepFloorMs = raMs;
|
|
99
|
+
// Release the discarded body so the retry is not queued behind an unread socket — and drop the
|
|
100
|
+
// reference: a cancelled response must never be handed back as if it were a real answer.
|
|
101
|
+
const stale = lastResponse;
|
|
102
|
+
lastResponse = undefined;
|
|
103
|
+
try {
|
|
104
|
+
await stale.body?.cancel();
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// A body already consumed/errored needs no cancel; the retry proceeds either way.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (lastResponse)
|
|
111
|
+
return lastResponse;
|
|
112
|
+
throw lastError ?? new Error('market read failed with no attempt completed');
|
|
113
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opencode.cafe registry — a community catalog served by a Convex deployment.
|
|
3
|
+
*
|
|
4
|
+
* The site is a Next.js app whose data lives in Convex; the catalog query is ANONYMOUS and readable
|
|
5
|
+
* (`extensions:listAllApproved`, no auth check in the upstream function). The deployment URL is the
|
|
6
|
+
* one the site's own client bundle ships, so this is an undocumented contract, not a published API —
|
|
7
|
+
* if the operator re-provisions the deployment or renames the function, this source answers
|
|
8
|
+
* `upstream` and the console says so instead of pretending the catalog is empty.
|
|
9
|
+
*
|
|
10
|
+
* PRIVACY: the public query returns `author.email` for every row. This module deliberately maps each
|
|
11
|
+
* row onto a narrow shape that has no field for it — the address never reaches the market, the
|
|
12
|
+
* manifest or a log line.
|
|
13
|
+
*
|
|
14
|
+
* Caching: none here. Browsing caches the answered list in `browse.ts`; an install reads once.
|
|
15
|
+
*/
|
|
16
|
+
import { type FailureReason } from './net.js';
|
|
17
|
+
/** A catalog row, narrowed to the fields this build reads (and to no field it must not). */
|
|
18
|
+
export interface CafeEntry {
|
|
19
|
+
productId?: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
repoUrl?: string;
|
|
24
|
+
homepageUrl?: string;
|
|
25
|
+
tags?: string[];
|
|
26
|
+
/** Free-form markdown install instructions; usually names the package. */
|
|
27
|
+
installation?: string;
|
|
28
|
+
}
|
|
29
|
+
export type CafeRegistryResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
entries: CafeEntry[];
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
code: 'unavailable' | 'upstream';
|
|
35
|
+
reason: FailureReason;
|
|
36
|
+
reasonParams?: Record<string, string>;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
/** Read the approved catalog. */
|
|
40
|
+
export declare function fetchCafeExtensions(fetchImpl?: typeof fetch): Promise<CafeRegistryResult>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opencode.cafe registry — a community catalog served by a Convex deployment.
|
|
3
|
+
*
|
|
4
|
+
* The site is a Next.js app whose data lives in Convex; the catalog query is ANONYMOUS and readable
|
|
5
|
+
* (`extensions:listAllApproved`, no auth check in the upstream function). The deployment URL is the
|
|
6
|
+
* one the site's own client bundle ships, so this is an undocumented contract, not a published API —
|
|
7
|
+
* if the operator re-provisions the deployment or renames the function, this source answers
|
|
8
|
+
* `upstream` and the console says so instead of pretending the catalog is empty.
|
|
9
|
+
*
|
|
10
|
+
* PRIVACY: the public query returns `author.email` for every row. This module deliberately maps each
|
|
11
|
+
* row onto a narrow shape that has no field for it — the address never reaches the market, the
|
|
12
|
+
* manifest or a log line.
|
|
13
|
+
*
|
|
14
|
+
* Caching: none here. Browsing caches the answered list in `browse.ts`; an install reads once.
|
|
15
|
+
*/
|
|
16
|
+
import { describeFetchFailure, fetchFailureReason, fetchWithRetry } from './net.js';
|
|
17
|
+
const QUERY_URL = 'https://curious-quail-727.convex.cloud/api/query';
|
|
18
|
+
/**
|
|
19
|
+
* Copy a row onto the narrow shape. Written as an explicit field pick (not a spread) so a field the
|
|
20
|
+
* upstream adds later — a credential, an e-mail, an internal id — can never travel by accident.
|
|
21
|
+
*/
|
|
22
|
+
function narrow(row) {
|
|
23
|
+
const str = (v) => (typeof v === 'string' && v.trim() !== '' ? v : undefined);
|
|
24
|
+
return {
|
|
25
|
+
...(str(row.productId) ? { productId: str(row.productId) } : {}),
|
|
26
|
+
...(str(row.type) ? { type: str(row.type) } : {}),
|
|
27
|
+
...(str(row.displayName) ? { displayName: str(row.displayName) } : {}),
|
|
28
|
+
...(str(row.description) ? { description: str(row.description) } : {}),
|
|
29
|
+
...(str(row.repoUrl) ? { repoUrl: str(row.repoUrl).trim() } : {}),
|
|
30
|
+
...(str(row.homepageUrl) ? { homepageUrl: str(row.homepageUrl) } : {}),
|
|
31
|
+
...(str(row.installation) ? { installation: str(row.installation) } : {}),
|
|
32
|
+
...(Array.isArray(row.tags)
|
|
33
|
+
? { tags: row.tags.filter((t) => typeof t === 'string') }
|
|
34
|
+
: {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Read the approved catalog. */
|
|
38
|
+
export async function fetchCafeExtensions(fetchImpl = fetch) {
|
|
39
|
+
let res;
|
|
40
|
+
try {
|
|
41
|
+
// A Convex POST query is idempotent (a read), so a transient 5xx/reset is asked again under the
|
|
42
|
+
// shared policy; a 429/4xx is returned untouched and mapped below.
|
|
43
|
+
res = await fetchWithRetry(QUERY_URL, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'content-type': 'application/json',
|
|
47
|
+
Accept: 'application/json',
|
|
48
|
+
'User-Agent': 'omnicellrouter-harness',
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({ path: 'extensions:listAllApproved', args: {}, format: 'json' }),
|
|
51
|
+
}, undefined, { fetchImpl });
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return { ok: false, code: 'upstream', reason: fetchFailureReason(e), message: describeFetchFailure('opencode.cafe', e) };
|
|
55
|
+
}
|
|
56
|
+
if (res.status === 429 || res.status >= 500) {
|
|
57
|
+
return { ok: false, code: 'unavailable', reason: 'unavailable', message: `opencode.cafe returned HTTP ${res.status} — try again later` };
|
|
58
|
+
}
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
code: 'upstream',
|
|
63
|
+
reason: 'http',
|
|
64
|
+
reasonParams: { status: String(res.status) },
|
|
65
|
+
message: `opencode.cafe returned HTTP ${res.status}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let body;
|
|
69
|
+
try {
|
|
70
|
+
body = await res.json();
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { ok: false, code: 'upstream', reason: 'badPayload', message: 'opencode.cafe answered non-JSON content' };
|
|
74
|
+
}
|
|
75
|
+
const envelope = body;
|
|
76
|
+
if (envelope.status !== 'success' || !Array.isArray(envelope.value)) {
|
|
77
|
+
return { ok: false, code: 'upstream', reason: 'badPayload', message: 'opencode.cafe answered an unexpected payload shape' };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
entries: envelope.value
|
|
82
|
+
.filter((row) => !!row && typeof row === 'object')
|
|
83
|
+
.map(narrow),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated OpenCode ecosystem catalog — a SHIPPED SNAPSHOT, not a live fetch.
|
|
3
|
+
*
|
|
4
|
+
* Source: https://opencode.ai/docs/ecosystem/ whose upstream file is
|
|
5
|
+
* `packages/web/src/content/docs/ecosystem.mdx` in the `anomalyco/opencode` repo (a Starlight page
|
|
6
|
+
* with no JSON endpoint). Snapshot taken 2026-10-25 from the `## Plugins` table only: `## Projects`
|
|
7
|
+
* lists standalone apps (a Discord bot, editor plugins) and `## Agents` lists config bundles, so
|
|
8
|
+
* neither is an installable extension.
|
|
9
|
+
*
|
|
10
|
+
* Why a snapshot instead of fetching the mdx at runtime:
|
|
11
|
+
* - `raw.githubusercontent.com` and `cdn.jsdelivr.net` both reset the connection from this
|
|
12
|
+
* environment (measured), so a live fetch would render an empty market that looks broken;
|
|
13
|
+
* - the upstream table has no version or schema contract — a snapshot pins what an operator sees.
|
|
14
|
+
* Cost: the list goes stale. Refresh by re-copying the `## Plugins` table, and bump `SNAPSHOT_AT`.
|
|
15
|
+
*
|
|
16
|
+
* `npm` is the published package name when one was VERIFIED to exist on the registry and to belong
|
|
17
|
+
* to the same project the table links to (checked against the package's own `repository` field).
|
|
18
|
+
* Rows without it are browse-only: the table name is not an npm name, so they cannot be installed
|
|
19
|
+
* from here — the npm source is where that row is actually served (ADR-0015 §D6).
|
|
20
|
+
*/
|
|
21
|
+
export interface EcosystemEntry {
|
|
22
|
+
/** Table name, verbatim (a display label, not necessarily a package name). */
|
|
23
|
+
name: string;
|
|
24
|
+
/** `owner/repo` the table links to. */
|
|
25
|
+
repo: string;
|
|
26
|
+
/** The exact URL the table carries (may point inside the repo). */
|
|
27
|
+
url: string;
|
|
28
|
+
description: string;
|
|
29
|
+
/** Verified npm package name; absent = browse-only. */
|
|
30
|
+
npm?: string;
|
|
31
|
+
}
|
|
32
|
+
/** The day the `## Plugins` table was copied. Bump it with every refresh. */
|
|
33
|
+
export declare const SNAPSHOT_AT = "2026-10-25";
|
|
34
|
+
export declare const OPENCODE_ECOSYSTEM: EcosystemEntry[];
|