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.
Files changed (212) hide show
  1. package/RELEASING.md +238 -238
  2. package/RELEASING.zh-CN.md +230 -230
  3. package/backend/dist/capture/recorder.js +2 -1
  4. package/backend/dist/cli/clients/base.js +8 -16
  5. package/backend/dist/cli/clients/dsh.js +8 -16
  6. package/backend/dist/cli/clients/pi.js +16 -9
  7. package/backend/dist/cli/types.d.ts +5 -0
  8. package/backend/dist/config/env.js +2 -1
  9. package/backend/dist/config/index.js +2 -0
  10. package/backend/dist/config/types.d.ts +23 -0
  11. package/backend/dist/harness/adapters/amp.d.ts +2 -0
  12. package/backend/dist/harness/adapters/amp.js +7 -0
  13. package/backend/dist/harness/adapters/claude.d.ts +2 -0
  14. package/backend/dist/harness/adapters/claude.js +7 -0
  15. package/backend/dist/harness/adapters/cline.d.ts +2 -0
  16. package/backend/dist/harness/adapters/cline.js +6 -0
  17. package/backend/dist/harness/adapters/codex.d.ts +2 -0
  18. package/backend/dist/harness/adapters/codex.js +6 -0
  19. package/backend/dist/harness/adapters/cursor.d.ts +5 -0
  20. package/backend/dist/harness/adapters/cursor.js +10 -0
  21. package/backend/dist/harness/adapters/declarative.d.ts +62 -0
  22. package/backend/dist/harness/adapters/declarative.js +202 -0
  23. package/backend/dist/harness/adapters/dsh.d.ts +5 -0
  24. package/backend/dist/harness/adapters/dsh.js +6 -0
  25. package/backend/dist/harness/adapters/gemini-cli.d.ts +2 -0
  26. package/backend/dist/harness/adapters/gemini-cli.js +7 -0
  27. package/backend/dist/harness/adapters/github-copilot.d.ts +5 -0
  28. package/backend/dist/harness/adapters/github-copilot.js +10 -0
  29. package/backend/dist/harness/adapters/index.d.ts +44 -0
  30. package/backend/dist/harness/adapters/index.js +99 -0
  31. package/backend/dist/harness/adapters/opencode.d.ts +2 -0
  32. package/backend/dist/harness/adapters/opencode.js +55 -0
  33. package/backend/dist/harness/adapters/pi.d.ts +1 -0
  34. package/backend/dist/harness/adapters/pi.js +22 -0
  35. package/backend/dist/harness/adapters/skills-paths.d.ts +15 -0
  36. package/backend/dist/harness/adapters/skills-paths.js +17 -0
  37. package/backend/dist/harness/adapters/types.d.ts +174 -0
  38. package/backend/dist/harness/adapters/types.js +12 -0
  39. package/backend/dist/harness/adapters/universal.d.ts +6 -0
  40. package/backend/dist/harness/adapters/universal.js +10 -0
  41. package/backend/dist/harness/adapters/windsurf.d.ts +2 -0
  42. package/backend/dist/harness/adapters/windsurf.js +10 -0
  43. package/backend/dist/harness/adapters/zed.d.ts +2 -0
  44. package/backend/dist/harness/adapters/zed.js +6 -0
  45. package/backend/dist/harness/awesome-opencode.d.ts +40 -0
  46. package/backend/dist/harness/awesome-opencode.js +75 -0
  47. package/backend/dist/harness/browse.d.ts +202 -0
  48. package/backend/dist/harness/browse.js +1214 -0
  49. package/backend/dist/harness/catalog-npm.d.ts +59 -0
  50. package/backend/dist/harness/catalog-npm.js +145 -0
  51. package/backend/dist/harness/clawhub.d.ts +212 -0
  52. package/backend/dist/harness/clawhub.js +426 -0
  53. package/backend/dist/harness/config-file.d.ts +29 -0
  54. package/backend/dist/harness/config-file.js +35 -0
  55. package/backend/dist/harness/detail.d.ts +74 -0
  56. package/backend/dist/harness/detail.js +330 -0
  57. package/backend/dist/harness/discover.d.ts +118 -0
  58. package/backend/dist/harness/discover.js +507 -0
  59. package/backend/dist/harness/drift.d.ts +21 -0
  60. package/backend/dist/harness/drift.js +25 -0
  61. package/backend/dist/harness/hash.d.ts +10 -0
  62. package/backend/dist/harness/hash.js +63 -0
  63. package/backend/dist/harness/hosts.d.ts +18 -0
  64. package/backend/dist/harness/hosts.js +15 -0
  65. package/backend/dist/harness/install.d.ts +88 -0
  66. package/backend/dist/harness/install.js +301 -0
  67. package/backend/dist/harness/inventory.d.ts +10 -0
  68. package/backend/dist/harness/inventory.js +198 -0
  69. package/backend/dist/harness/ledger.d.ts +39 -0
  70. package/backend/dist/harness/ledger.js +83 -0
  71. package/backend/dist/harness/maintenance.d.ts +115 -0
  72. package/backend/dist/harness/maintenance.js +603 -0
  73. package/backend/dist/harness/manifest.d.ts +31 -0
  74. package/backend/dist/harness/manifest.js +234 -0
  75. package/backend/dist/harness/net.d.ts +86 -0
  76. package/backend/dist/harness/net.js +113 -0
  77. package/backend/dist/harness/opencode-cafe.d.ts +40 -0
  78. package/backend/dist/harness/opencode-cafe.js +85 -0
  79. package/backend/dist/harness/opencode-ecosystem.d.ts +34 -0
  80. package/backend/dist/harness/opencode-ecosystem.js +246 -0
  81. package/backend/dist/harness/pi-dev.d.ts +81 -0
  82. package/backend/dist/harness/pi-dev.js +187 -0
  83. package/backend/dist/harness/probe.d.ts +33 -0
  84. package/backend/dist/harness/probe.js +85 -0
  85. package/backend/dist/harness/registry.d.ts +2 -0
  86. package/backend/dist/harness/registry.js +26 -0
  87. package/backend/dist/harness/scopes.d.ts +21 -0
  88. package/backend/dist/harness/scopes.js +22 -0
  89. package/backend/dist/harness/skill-md.d.ts +18 -0
  90. package/backend/dist/harness/skill-md.js +71 -0
  91. package/backend/dist/harness/skills-sh.d.ts +109 -0
  92. package/backend/dist/harness/skills-sh.js +178 -0
  93. package/backend/dist/harness/smithery.d.ts +64 -0
  94. package/backend/dist/harness/smithery.js +146 -0
  95. package/backend/dist/harness/sources/awesome-opencode.d.ts +11 -0
  96. package/backend/dist/harness/sources/awesome-opencode.js +39 -0
  97. package/backend/dist/harness/sources/clawhub.d.ts +2 -0
  98. package/backend/dist/harness/sources/clawhub.js +83 -0
  99. package/backend/dist/harness/sources/github.d.ts +9 -0
  100. package/backend/dist/harness/sources/github.js +202 -0
  101. package/backend/dist/harness/sources/mcp-official.d.ts +2 -0
  102. package/backend/dist/harness/sources/mcp-official.js +110 -0
  103. package/backend/dist/harness/sources/npm.d.ts +2 -0
  104. package/backend/dist/harness/sources/npm.js +152 -0
  105. package/backend/dist/harness/sources/opencode-cafe.d.ts +11 -0
  106. package/backend/dist/harness/sources/opencode-cafe.js +41 -0
  107. package/backend/dist/harness/sources/smithery.d.ts +2 -0
  108. package/backend/dist/harness/sources/smithery.js +81 -0
  109. package/backend/dist/harness/spi.d.ts +98 -0
  110. package/backend/dist/harness/spi.js +8 -0
  111. package/backend/dist/harness/stars.d.ts +70 -0
  112. package/backend/dist/harness/stars.js +202 -0
  113. package/backend/dist/harness/translation.d.ts +142 -0
  114. package/backend/dist/harness/translation.js +567 -0
  115. package/backend/dist/harness/tree.d.ts +13 -0
  116. package/backend/dist/harness/tree.js +19 -0
  117. package/backend/dist/harness/types.d.ts +286 -0
  118. package/backend/dist/harness/types.js +8 -0
  119. package/backend/dist/harness/writers/extension.d.ts +116 -0
  120. package/backend/dist/harness/writers/extension.js +219 -0
  121. package/backend/dist/harness/writers/mcp.d.ts +72 -0
  122. package/backend/dist/harness/writers/mcp.js +195 -0
  123. package/backend/dist/harness/writers/skill.d.ts +60 -0
  124. package/backend/dist/harness/writers/skill.js +146 -0
  125. package/backend/dist/opencode/agents.d.ts +5 -0
  126. package/backend/dist/opencode/agents.js +10 -1
  127. package/backend/dist/opencode/catalog/cache.js +2 -1
  128. package/backend/dist/opencode/catalog/logos.js +2 -1
  129. package/backend/dist/opencode/catalog/ocr-store.js +2 -1
  130. package/backend/dist/opencode/catalog/overrides-store.js +2 -1
  131. package/backend/dist/opencode/credentials/factory.js +10 -27
  132. package/backend/dist/opencode/credentials/ocr-store.js +2 -1
  133. package/backend/dist/opencode/provider-defs.js +2 -1
  134. package/backend/dist/opencode/user-config.js +8 -16
  135. package/backend/dist/providers/registry.d.ts +15 -4
  136. package/backend/dist/providers/registry.js +29 -5
  137. package/backend/dist/providers/virtual-meta.d.ts +13 -0
  138. package/backend/dist/providers/virtual-meta.js +18 -0
  139. package/backend/dist/quota/store.js +2 -1
  140. package/backend/dist/resilience/breaker-state.js +2 -1
  141. package/backend/dist/resilience/credential-state.js +2 -1
  142. package/backend/dist/routes/console.js +137 -15
  143. package/backend/dist/routes/harness.d.ts +2 -0
  144. package/backend/dist/routes/harness.js +622 -0
  145. package/backend/dist/server.js +4 -0
  146. package/backend/dist/session/session-manager.js +2 -1
  147. package/backend/dist/surfaces/systemone-probe.d.ts +25 -0
  148. package/backend/dist/surfaces/systemone-probe.js +74 -0
  149. package/backend/dist/utils/atomic-write.d.ts +12 -0
  150. package/backend/dist/utils/atomic-write.js +29 -0
  151. package/bin/ocr.js +2 -2
  152. package/frontend/dist/assets/{index-DEo2iAT7.css → index-1o7qI-KJ.css} +1 -1
  153. package/frontend/dist/assets/index-DvXKvNxl.js +962 -0
  154. package/frontend/dist/index.html +2 -2
  155. package/package.json +87 -87
  156. package/backend/dist/budget/budget-manager.d.ts +0 -25
  157. package/backend/dist/budget/budget-manager.js +0 -54
  158. package/backend/dist/config/governance-limits.d.ts +0 -68
  159. package/backend/dist/config/governance-limits.js +0 -261
  160. package/backend/dist/flywheel/collector.d.ts +0 -74
  161. package/backend/dist/flywheel/collector.js +0 -235
  162. package/backend/dist/flywheel/dataset.d.ts +0 -130
  163. package/backend/dist/flywheel/dataset.js +0 -638
  164. package/backend/dist/flywheel/decision-capture.d.ts +0 -68
  165. package/backend/dist/flywheel/decision-capture.js +0 -85
  166. package/backend/dist/flywheel/prune.d.ts +0 -133
  167. package/backend/dist/flywheel/prune.js +0 -495
  168. package/backend/dist/flywheel/schema.d.ts +0 -108
  169. package/backend/dist/flywheel/schema.js +0 -117
  170. package/backend/dist/flywheel/trainer.d.ts +0 -84
  171. package/backend/dist/flywheel/trainer.js +0 -198
  172. package/backend/dist/opencode/catalog/custom-store.d.ts +0 -50
  173. package/backend/dist/opencode/catalog/custom-store.js +0 -144
  174. package/backend/dist/opencode/credentials/push.d.ts +0 -38
  175. package/backend/dist/opencode/credentials/push.js +0 -116
  176. package/backend/dist/opencode/credentials/reconcile.d.ts +0 -49
  177. package/backend/dist/opencode/credentials/reconcile.js +0 -216
  178. package/backend/dist/opencode/sync.d.ts +0 -29
  179. package/backend/dist/opencode/sync.js +0 -186
  180. package/backend/dist/pipeline/account-selection.d.ts +0 -101
  181. package/backend/dist/pipeline/account-selection.js +0 -112
  182. package/backend/dist/providers/systemone.d.ts +0 -29
  183. package/backend/dist/providers/systemone.js +0 -170
  184. package/backend/dist/ratelimit/duration.d.ts +0 -24
  185. package/backend/dist/ratelimit/duration.js +0 -43
  186. package/backend/dist/ratelimit/governance-runtime.d.ts +0 -121
  187. package/backend/dist/ratelimit/governance-runtime.js +0 -183
  188. package/backend/dist/ratelimit/index.d.ts +0 -4
  189. package/backend/dist/ratelimit/index.js +0 -4
  190. package/backend/dist/ratelimit/limiter.d.ts +0 -157
  191. package/backend/dist/ratelimit/limiter.js +0 -244
  192. package/backend/dist/ratelimit/sliding-window-counter.d.ts +0 -63
  193. package/backend/dist/ratelimit/sliding-window-counter.js +0 -103
  194. package/backend/dist/ratelimit/subject.d.ts +0 -26
  195. package/backend/dist/ratelimit/subject.js +0 -28
  196. package/backend/dist/resilience/account-state.d.ts +0 -84
  197. package/backend/dist/resilience/account-state.js +0 -228
  198. package/backend/dist/router/layer1-classifier.d.ts +0 -111
  199. package/backend/dist/router/layer1-classifier.js +0 -467
  200. package/backend/dist/router/layer2-judge.d.ts +0 -111
  201. package/backend/dist/router/layer2-judge.js +0 -373
  202. package/backend/dist/router/retry-escalation.d.ts +0 -89
  203. package/backend/dist/router/retry-escalation.js +0 -99
  204. package/backend/dist/routes/flywheel.d.ts +0 -3
  205. package/backend/dist/routes/flywheel.js +0 -268
  206. package/backend/dist/routes/systemone.d.ts +0 -3
  207. package/backend/dist/routes/systemone.js +0 -90
  208. package/backend/dist/surfaces/governance-envelope.d.ts +0 -34
  209. package/backend/dist/surfaces/governance-envelope.js +0 -47
  210. package/backend/dist/utils/token-estimator.d.ts +0 -7
  211. package/backend/dist/utils/token-estimator.js +0 -20
  212. package/frontend/dist/assets/index-nwgWkmU1.js +0 -840
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Harness domain vocabulary (ADR-0015).
3
+ *
4
+ * `client` = a runtime hooked for traffic (SupportedClient). `harness` = that runtime considered as an
5
+ * artifact host. They are deliberately different vocabularies: hosts like Cursor/Zed will never be
6
+ * traffic clients, and welding the two would pollute the traffic domain.
7
+ */
8
+ export type HarnessKind = 'skill' | 'mcp' | 'extension';
9
+ export type HarnessHostId = 'universal' | 'opencode' | 'claude' | 'codex' | 'pi' | 'dsh' | 'cursor' | 'github-copilot' | 'gemini-cli' | 'cline' | 'amp' | 'windsurf' | 'zed';
10
+ /**
11
+ * Where an artifact may be materialized: project-local or user-level.
12
+ *
13
+ * The TYPE keeps both because the adapters and writers model both; only `global` is ENABLED today
14
+ * (`ENABLED_SCOPES` in `scopes.ts`) — see ADR-0015 §D2 "Scope".
15
+ */
16
+ export type HarnessScope = 'global' | 'project';
17
+ /** Why a root exists — the resolver measures THIS PROCESS only (ADR-0015 §D2). */
18
+ export type RootOrigin = 'default' | 'env-override' | 'profile';
19
+ export interface ResolvedRoot {
20
+ root: string;
21
+ origin: RootOrigin;
22
+ /** Root kind the host actually reads; `candidate` roots are lower precedence. */
23
+ precedence: number;
24
+ }
25
+ /**
26
+ * Per-copy state vocabulary — the ONLY state words allowed on disk (ADR-0015 §D8.7).
27
+ *
28
+ * `untracked` is a statement about OWNERSHIP (no manifest entry), never a restriction: an untracked
29
+ * directory is removable like any other copy, because the removal op follows the artifact's landing
30
+ * shape rather than its provenance (ADR-0015 §D8.10).
31
+ */
32
+ export type CopyState = 'clean' | 'dirty' | 'missing' | 'foreign' | 'untracked';
33
+ /** Orthogonal to CopyState: what was proven about loading, not about content. */
34
+ export type CopyPlacement = 'materialized' | 'verified' | 'unverified';
35
+ export type TrustTier = 'official' | 'aggregator' | 'community' | 'manual';
36
+ export interface CopyRecord {
37
+ scope: HarnessScope;
38
+ host: HarnessHostId;
39
+ /** Display hint only — the absolute `path` is the reconcile identity. */
40
+ rootId: string;
41
+ /**
42
+ * Absolute on-disk path for a copy we materialized. For an `external` copy this is an OPAQUE
43
+ * IDENTITY TOKEN (`<canonicalKey>#<harness>`), NOT a filesystem path — see `external`.
44
+ */
45
+ path: string;
46
+ /**
47
+ * Package-manager-managed copy with no path of our own (today: the `pi` subprocess install, which
48
+ * materializes into the runtime's own store). Inventory must not stat/hash it and removal must not
49
+ * move it — the apply-time subprocess exit code is the only proof, and the package is uninstalled
50
+ * by the runtime's own package manager, not by us.
51
+ */
52
+ external?: boolean;
53
+ contentHash: string;
54
+ placement: CopyPlacement;
55
+ /** Fast-path fingerprint: unchanged mtime+size means clean without re-hashing. */
56
+ mtimeMs?: number;
57
+ bytes?: number;
58
+ installedAt: string;
59
+ }
60
+ /** Pinned provenance. A package has no commit; a repo has no integrity; a ClawHub skill pins the
61
+ * registry version whose deterministic archive was downloaded. */
62
+ export type Pin = {
63
+ git: {
64
+ commitSha: string;
65
+ };
66
+ } | {
67
+ npm: {
68
+ integrity: string;
69
+ };
70
+ } | {
71
+ clawhub: {
72
+ slug: string;
73
+ version: string;
74
+ };
75
+ } | {
76
+ adopted: true;
77
+ };
78
+ export interface ArtifactRecord {
79
+ /**
80
+ * `extension:<harness>:<canonicalKey>` for kind `extension` — the runtime is part of the identity,
81
+ * because an extension is code against ONE runtime's plugin API (one package installed into two
82
+ * runtimes is two artifacts). `<kind>:<canonicalKey>` for every other kind (ADR-0015 §D7).
83
+ */
84
+ id: string;
85
+ canonicalKey: string;
86
+ kind: HarnessKind;
87
+ /**
88
+ * The runtime this artifact is an extension OF; present iff `kind === 'extension'` (ADR-0015 §D2:
89
+ * an artifact declares its compatible hosts). For skill/mcp the host is a landing choice recorded
90
+ * per copy, so no artifact-level harness exists.
91
+ */
92
+ harness?: HarnessHostId;
93
+ name: string;
94
+ /**
95
+ * One-line description the SOURCE claimed at resolve time, recorded so an installed row can show
96
+ * what the market showed. Absent on manifests written before this field existed, and unnecessary
97
+ * for kinds whose text is readable from the installed content (a skill's `SKILL.md`): the view
98
+ * prefers the installed text and falls back here (`inventory.ts` `toView`).
99
+ */
100
+ description?: string | null;
101
+ sourceId: string;
102
+ ref?: string;
103
+ pin: Pin;
104
+ contentHash: string;
105
+ storeRef?: string;
106
+ listedOn: string[];
107
+ trust: TrustTier;
108
+ copies: CopyRecord[];
109
+ }
110
+ export interface ManifestFile {
111
+ /** v2 added the artifact-level `harness` dimension for extensions; v1 manifests migrate on read. */
112
+ version: 1 | 2;
113
+ artifacts: ArtifactRecord[];
114
+ }
115
+ /** `<ocrHome>/harness/claims.json` — one materialized path, one owning environment. */
116
+ export interface ClaimsFile {
117
+ version: 1;
118
+ claims: Record<string, {
119
+ env: string;
120
+ artifactId: string;
121
+ }>;
122
+ }
123
+ export interface CopyView {
124
+ scope: HarnessScope;
125
+ host: HarnessHostId;
126
+ rootId: string;
127
+ /** Identity token, not a location, when `external` is true. */
128
+ path: string;
129
+ /** Package-manager-managed (no own path) — the console shows "managed by the runtime", never a path. */
130
+ external?: boolean;
131
+ state: CopyState;
132
+ placement: CopyPlacement;
133
+ contentHash?: string;
134
+ /**
135
+ * Skill copies only: every host whose skills roots resolve to this directory, owner FIRST.
136
+ *
137
+ * `host` answers ownership (one directory, one owner — install/claims/removal), this answers
138
+ * READERSHIP (the cross-agent `.agents/skills` tree is read by up to nine runtimes). Absent for
139
+ * config-shaped copies, where the file IS the landing and its host is the only reader.
140
+ */
141
+ readers?: HarnessHostId[];
142
+ }
143
+ export interface ArtifactView {
144
+ id: string;
145
+ canonicalKey: string;
146
+ kind: HarnessKind;
147
+ /** The runtime an extension is written for; absent for skill/mcp (host lives per copy). */
148
+ harness?: HarnessHostId;
149
+ name: string;
150
+ /**
151
+ * One-line description: the copy's own readable text when it has one (a skill's `SKILL.md`), else
152
+ * the line the source or the package manifest recorded. Null when neither exists.
153
+ */
154
+ description: string | null;
155
+ /** Source that produced this artifact; null for a purely local directory. */
156
+ sourceId: string | null;
157
+ /**
158
+ * Surfaces this artifact was listed on when the install was requested, writer source first
159
+ * (`['npm','pi-dev']` for a package taken from the Pi catalog). `sourceId` stays the identity of
160
+ * the payload; this is the discovery facet the console's source chips narrow by.
161
+ */
162
+ listedOn: string[];
163
+ trust: TrustTier;
164
+ audit: {
165
+ status: 'pass' | 'warn' | 'fail';
166
+ summary: string;
167
+ } | null;
168
+ copies: CopyView[];
169
+ /** Derived rollup, never persisted. */
170
+ rollup: 'clean' | 'partial' | 'dirty' | 'missing' | 'shadowed';
171
+ }
172
+ export interface HarnessSourceView {
173
+ id: string;
174
+ label: string;
175
+ kinds: HarnessKind[];
176
+ trust: TrustTier;
177
+ /** Credential the source's OWN API demands (`oidc` = skills.sh's closed endpoint); `none` otherwise.
178
+ * Every source offered today is readable anonymously, so this is a declaration, not a gate. */
179
+ auth: 'none' | 'oidc';
180
+ /**
181
+ * Harnesses this source's artifacts are bound to. ABSENT = the source is harness-agnostic
182
+ * (skills/MCP land on whichever host the operator picks); present = the console may offer it only
183
+ * for those harnesses (ADR-0015 §D2: a free checkbox list is forbidden).
184
+ */
185
+ hosts?: HarnessHostId[];
186
+ enabled: boolean;
187
+ /** True when this source has a browse adapter, i.e. a market chip for it can show results. */
188
+ browsable?: boolean;
189
+ /** Present when the source cannot answer right now — measured, not guessed. */
190
+ unavailableReason?: string;
191
+ /**
192
+ * The orderings this source OFFICIALLY offers when browsing (ADR-0015 §D6), best default first.
193
+ *
194
+ * The console renders exactly this list and sends the chosen key back on `/browse` — it never
195
+ * invents an order the upstream cannot serve, because a page-local re-sort of a paged catalog
196
+ * would claim a global ranking nobody computed. `undefined` = one order only: the catalog's own.
197
+ */
198
+ sorts?: string[];
199
+ lastSyncAt?: number;
200
+ }
201
+ /** Where a discovered row was read from — the runtime's own record, never a manifest entry. */
202
+ export type ExtDiscoveryOrigin = 'runtime-store' | 'config-array' | 'local-file';
203
+ /**
204
+ * How to undo a runtime's own install record (ADR-0015 §D8.10).
205
+ *
206
+ * A discovered row has no manifest entry, so removal is not "delete our copy" — it is the inverse of
207
+ * the shape the runtime landed it in. The descriptor travels WITH the row so the console never has to
208
+ * guess, and so the plan can name the exact file and container it will touch:
209
+ * · `trash-path` — a real file/dir on disk (a loose `extensions/*.ts`, a path-shaped `plugin[]`
210
+ * entry). Reversible through the trash.
211
+ * · `drop-entry` — one string inside a JSON string array (`plugin[]`, pi's `packages[]`). Dropping
212
+ * the string is the inverse of installing it; for a package it removes the DECLARATION, not the
213
+ * bytes the runtime's package manager already put in its own store.
214
+ * · `drop-server` — one MEMBER of a JSON object (a server key inside the host's `mcp` container).
215
+ * Same principle as `drop-entry` with a different container shape: the key goes, its siblings and
216
+ * every hand-written comment in the runtime's file stay.
217
+ */
218
+ export type DiscoveredRemoval = {
219
+ op: 'trash-path';
220
+ path: string;
221
+ } | {
222
+ op: 'drop-entry';
223
+ file: string;
224
+ container: string;
225
+ entry: string;
226
+ } | {
227
+ op: 'drop-server';
228
+ file: string;
229
+ container: string;
230
+ entry: string;
231
+ };
232
+ export interface DiscoveredArtifact {
233
+ /**
234
+ * Which kind the row belongs to. Discovery is ONE channel for every kind (a skill directory, a
235
+ * package the runtime's manager installed, a loose extension file), so the console can filter a
236
+ * landing page without a second scan endpoint.
237
+ */
238
+ kind: HarnessKind;
239
+ /**
240
+ * The runtime whose own record the row was read from: set for `extension` (its store /
241
+ * declaration / loose directory) and for `mcp` (the `mcp` container of its config file). Absent for
242
+ * `skill`, whose copies are grouped per directory NAME across every host that reads them.
243
+ */
244
+ harness?: HarnessHostId;
245
+ /** Skill directory name / package name / loose file basename — the only identity available. */
246
+ name: string;
247
+ /**
248
+ * One line read from the row's OWN material, null when that material carries none: a skill's
249
+ * `SKILL.md` frontmatter, an installed package's `package.json`, a local file's header comment.
250
+ * No registry round-trip — discovery stays a local scan.
251
+ */
252
+ description: string | null;
253
+ /** One row per directory/package found; several hosts commonly read the same skill. */
254
+ copies: CopyView[];
255
+ hosts: HarnessHostId[];
256
+ /**
257
+ * Provenance of a discovered row: which of the runtime's own records produced it — its store, its
258
+ * config array (`plugin[]`), its `mcp` container, or a loose file on disk. Display only — the row is
259
+ * NEVER promoted to a manifest artifact (ADR-0015 §D8.10).
260
+ */
261
+ origin?: ExtDiscoveryOrigin;
262
+ /** The file/dir the row was read from — a tooltip, never a reconcile identity. */
263
+ observedFrom?: string;
264
+ /** Version the runtime's own store records (its lock file), when one is available. */
265
+ version?: string;
266
+ /** Identity in the same namespace as `ArtifactRecord.canonicalKey`, when the row has one. */
267
+ canonicalKey?: string;
268
+ /**
269
+ * The inverse of the runtime's own install record (ADR-0015 §D8.10). Present whenever the shape is
270
+ * known, and ABSENT only when it is not — a row without it cannot be removed from this console.
271
+ */
272
+ removal?: DiscoveredRemoval;
273
+ }
274
+ export interface InventoryResponse {
275
+ envName: string;
276
+ envRoot: string;
277
+ hostsScanned: number;
278
+ artifacts: ArtifactView[];
279
+ /**
280
+ * On-disk rows with no manifest entry, for every kind — skills grouped per skill (NOT per
281
+ * directory), extensions one row per package/file the runtime's own store declares.
282
+ */
283
+ discovered: DiscoveredArtifact[];
284
+ /** Total copies behind `discovered` (a skill may live in several roots). */
285
+ discoveredCopies: number;
286
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Harness domain vocabulary (ADR-0015).
3
+ *
4
+ * `client` = a runtime hooked for traffic (SupportedClient). `harness` = that runtime considered as an
5
+ * artifact host. They are deliberately different vocabularies: hosts like Cursor/Zed will never be
6
+ * traffic clients, and welding the two would pollute the traffic domain.
7
+ */
8
+ export {};
@@ -0,0 +1,116 @@
1
+ import type { InstallSkipped } from './skill.js';
2
+ import type { HarnessHostId, HarnessScope, Pin, TrustTier } from '../types.js';
3
+ /**
4
+ * Extension kind writer (ADR-0015 §D8) — package install or `plugin[]` array edit.
5
+ *
6
+ * One request targets exactly ONE harness: an extension is code written against that runtime's
7
+ * plugin API, so the harness is part of the artifact identity (`extension:<harness>:<canonicalKey>`)
8
+ * and is never a multi-select landing choice (ADR-0015 §D2).
9
+ *
10
+ * Gate 3, verbatim discipline: a package install EXECUTES THIRD-PARTY CODE (npm lifecycle scripts).
11
+ * The plan echoes the EXACT command; the orchestrator refuses to apply without the caller's
12
+ * confirmation; the runner never appends `-y`/`--yes`, runs with a hard timeout, and captures
13
+ * stdout/stderr for the ledger.
14
+ *
15
+ * `plugin[]` edits are plain config merges with the same backup + atomic-rename discipline as the
16
+ * MCP writer (`createBackup` + `safeWriteJson`), refusing anything a JSON round-trip would mangle.
17
+ */
18
+ export interface ExtensionApplyRequest {
19
+ sourceId: string;
20
+ canonicalKey: string;
21
+ /**
22
+ * The source's one-line description; persisted so an installed package row can show what the
23
+ * market showed (an `external` copy has no file of ours to read prose from).
24
+ */
25
+ description?: string | null;
26
+ /** Package spec (npm name@range / URL) — inserted verbatim, never interpolated into a shell. */
27
+ spec: string;
28
+ trust: TrustTier;
29
+ /** Listing surfaces recorded with the manifest (writer source first); absent = `[sourceId]`. */
30
+ listedOn?: string[];
31
+ /**
32
+ * Provenance the source adapter resolved for this exact spec (`{npm:{integrity}}`), written to the
33
+ * manifest verbatim. Absent = the caller has no provenance to claim (the manual escape hatch), and
34
+ * the writer records `{adopted:true}` — it must never pretend a pin exists.
35
+ */
36
+ pin?: Pin;
37
+ /**
38
+ * The ONE runtime this extension is written for. An extension is code against a specific plugin
39
+ * API, so the harness is part of the artifact's identity — never a multi-select landing choice.
40
+ */
41
+ harness: HarnessHostId;
42
+ scope: HarnessScope;
43
+ projectRoot?: string;
44
+ /** Injectable process runner (house test style); defaults to a spawn-based impl. */
45
+ execImpl?: ExecImpl;
46
+ /** Hard timeout for one subprocess run. */
47
+ timeoutMs?: number;
48
+ }
49
+ export type ExecImpl = (command: string, args: string[], timeoutMs: number) => Promise<{
50
+ code: number;
51
+ stdout: string;
52
+ stderr: string;
53
+ }>;
54
+ export interface ExtensionTargetPlan {
55
+ host: HarnessHostId;
56
+ /** `subprocess` (package install) or `config` (`plugin[]` merge). */
57
+ op: 'subprocess' | 'config';
58
+ file?: string;
59
+ container?: string;
60
+ /** Structured command for subprocess targets — apply runs THIS, `echo` is display-only. */
61
+ command?: string;
62
+ args?: string[];
63
+ /** The EXACT command that apply will run — gate 3 says it verbatim, never paraphrased. */
64
+ echo?: string;
65
+ refused?: string;
66
+ added: boolean;
67
+ }
68
+ export type ExtensionPlan = {
69
+ ok: true;
70
+ targets: ExtensionTargetPlan[];
71
+ } | {
72
+ ok: false;
73
+ code: 'bad_request';
74
+ message: string;
75
+ };
76
+ export type ExtensionApplyResult = {
77
+ ok: true;
78
+ artifactId: string;
79
+ name: string;
80
+ /** `external` marks a package-manager-owned copy: `path` is an identity token, not a location. */
81
+ copies: {
82
+ host: string;
83
+ path?: string;
84
+ external?: boolean;
85
+ }[];
86
+ /** Captured subprocess output, forwarded to the apply ledger. */
87
+ runs: {
88
+ host: string;
89
+ command: string;
90
+ code: number;
91
+ stdout: string;
92
+ stderr: string;
93
+ }[];
94
+ skipped: InstallSkipped[];
95
+ } | {
96
+ ok: false;
97
+ code: 'no_target' | 'exists' | 'foreign' | 'bad_request' | 'upstream';
98
+ message: string;
99
+ skipped?: InstallSkipped[];
100
+ /** Subprocess runs from a failed apply — forwarded to the ledger for the gate-3 audit. */
101
+ runs?: {
102
+ host: string;
103
+ command: string;
104
+ code: number;
105
+ stdout: string;
106
+ stderr: string;
107
+ }[];
108
+ };
109
+ /**
110
+ * npm specs are installed verbatim; refuse anything shell-shaped or path-escaping. A leading `-` is
111
+ * refused too (an argument, never a package name), and so is any `..` segment — npm would resolve
112
+ * that as a LOCAL directory instead of a registry package.
113
+ */
114
+ export declare function safeSpec(spec: string): string | null;
115
+ export declare function planExtension(req: ExtensionApplyRequest): ExtensionPlan;
116
+ export declare function applyExtension(req: ExtensionApplyRequest): Promise<ExtensionApplyResult>;
@@ -0,0 +1,219 @@
1
+ import fs from 'node:fs';
2
+ import { spawn } from 'node:child_process';
3
+ import { hashFile } from '../hash.js';
4
+ import { adapterFor, isExtensionHost } from '../adapters/index.js';
5
+ import { claimPath, readManifest, writeManifest } from '../manifest.js';
6
+ import { createBackup, safeWriteJson } from '../../cli/clients/base.js';
7
+ const DEFAULT_TIMEOUT_MS = 120_000;
8
+ /**
9
+ * npm specs are installed verbatim; refuse anything shell-shaped or path-escaping. A leading `-` is
10
+ * refused too (an argument, never a package name), and so is any `..` segment — npm would resolve
11
+ * that as a LOCAL directory instead of a registry package.
12
+ */
13
+ export function safeSpec(spec) {
14
+ if (!/^[@\w][@\w./-]*$/.test(spec))
15
+ return null;
16
+ if (spec.includes('..'))
17
+ return null;
18
+ return spec;
19
+ }
20
+ /**
21
+ * Windows: a runtime CLI is usually an npm `.cmd` shim, which libuv cannot exec without a shell
22
+ * (`spawn('pi', …, {shell:false})` → ENOENT even though `where pi` resolves it). The line goes
23
+ * through cmd.exe and args carrying cmd metacharacters are pre-quoted for it — the same rule as
24
+ * `cli/clients/opencode-proxy.ts:runOpenCode`, and safe here because `safeSpec` already rejects
25
+ * anything shell-shaped. Other platforms spawn directly with an argv array.
26
+ */
27
+ function defaultExec(command, args, timeoutMs) {
28
+ const isWin = process.platform === 'win32';
29
+ const finalArgs = isWin ? args.map((a) => (/[\s"%^&|<>()]/.test(a) ? `"${a.replace(/"/g, '""')}"` : a)) : args;
30
+ return new Promise((resolve) => {
31
+ const child = spawn(command, finalArgs, { shell: isWin, windowsHide: true });
32
+ let stdout = '';
33
+ let stderr = '';
34
+ const timer = setTimeout(() => child.kill(), timeoutMs);
35
+ child.stdout.on('data', (chunk) => (stdout += chunk.toString('utf8')));
36
+ child.stderr.on('data', (chunk) => (stderr += chunk.toString('utf8')));
37
+ child.on('error', (e) => {
38
+ clearTimeout(timer);
39
+ // ENOENT here means the harness CLI itself is not on PATH — say that, not just `spawn failed`.
40
+ const message = e.code === 'ENOENT' ? `${command}: executable not found on PATH (${e.message})` : e.message;
41
+ resolve({ code: -1, stdout, stderr: `${stderr}${message}` });
42
+ });
43
+ child.on('close', (code) => {
44
+ clearTimeout(timer);
45
+ resolve({ code: code ?? -1, stdout, stderr });
46
+ });
47
+ });
48
+ }
49
+ function readConfigObject(file) {
50
+ try {
51
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
52
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
53
+ return { ok: false, reason: 'config root is not a JSON object' };
54
+ }
55
+ return { ok: true, config: parsed };
56
+ }
57
+ catch {
58
+ return { ok: false, reason: 'config is not valid plain JSON; refusing a lossy rewrite' };
59
+ }
60
+ }
61
+ export function planExtension(req) {
62
+ const spec = safeSpec(req.spec);
63
+ if (!spec)
64
+ return { ok: false, code: 'bad_request', message: `invalid package spec '${req.spec}'` };
65
+ const targets = [];
66
+ const host = req.harness;
67
+ const adapter = adapterFor(host);
68
+ if (!isExtensionHost(adapter)) {
69
+ targets.push({ host, op: 'config', refused: `host '${host}' has no verified extension landing`, added: false });
70
+ return { ok: true, targets };
71
+ }
72
+ const ext = adapter;
73
+ const landing = ext.writeTarget({ projectRoot: req.projectRoot ?? process.cwd() }, req.scope);
74
+ if (!landing.ok) {
75
+ targets.push({ host, op: 'config', refused: landing.reason, added: false });
76
+ return { ok: true, targets };
77
+ }
78
+ if (landing.op === 'subprocess') {
79
+ targets.push({
80
+ host,
81
+ op: 'subprocess',
82
+ command: landing.command,
83
+ args: ['install', `npm:${spec}`],
84
+ echo: `${landing.command} install npm:${spec}`,
85
+ added: true,
86
+ });
87
+ return { ok: true, targets };
88
+ }
89
+ let added = true;
90
+ let refused;
91
+ // Write into the container the file ALREADY uses (`plugins` on a v2 opencode config), falling back
92
+ // to the adapter's declared default: an install that lands in a key the runtime ignores would be
93
+ // indistinguishable from a successful one (§D8.8).
94
+ let container = landing.container;
95
+ if (fs.existsSync(landing.path)) {
96
+ const parsed = readConfigObject(landing.path);
97
+ if (!parsed.ok)
98
+ refused = parsed.reason;
99
+ else {
100
+ container = ext.containers().find((key) => Array.isArray(parsed.config[key])) ?? container;
101
+ const arr = parsed.config[container];
102
+ if (Array.isArray(arr) && arr.includes(spec))
103
+ added = false;
104
+ }
105
+ }
106
+ targets.push({ host, op: 'config', file: landing.path, container, refused, added });
107
+ return { ok: true, targets };
108
+ }
109
+ export async function applyExtension(req) {
110
+ const plan = planExtension(req);
111
+ if (!plan.ok)
112
+ return { ok: false, code: plan.code, message: plan.message };
113
+ // The harness is part of the identity: the same package installed into opencode and `pi` is two
114
+ // artifacts, because each is code against a different plugin API (ADR-0015 §D2).
115
+ const artifactId = `extension:${req.harness}:${req.canonicalKey}`;
116
+ const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;
117
+ const run = req.execImpl ?? defaultExec;
118
+ const copies = [];
119
+ const runs = [];
120
+ const skipped = [];
121
+ let firstConfigHash;
122
+ for (const target of plan.targets) {
123
+ if (target.refused) {
124
+ skipped.push({ host: target.host, code: 'bad_request', message: target.refused });
125
+ continue;
126
+ }
127
+ if (target.op === 'subprocess') {
128
+ // Gate 3: the command was echoed in the plan and confirmed; never append -y/--yes here.
129
+ const result = await run(target.command, target.args, timeoutMs);
130
+ runs.push({ host: target.host, command: target.echo, code: result.code, stdout: result.stdout, stderr: result.stderr });
131
+ if (result.code !== 0) {
132
+ skipped.push({ host: target.host, code: 'upstream', message: `${target.echo} exited ${result.code}: ${result.stderr.slice(0, 200)}` });
133
+ continue;
134
+ }
135
+ // A subprocess install materializes into the runtime's own store — no file path of ours exists,
136
+ // so the copy is marked `external` and its `path` is an opaque identity token, not a location.
137
+ // The run log above is the audit trail.
138
+ copies.push({ host: target.host, path: `${req.canonicalKey}#${target.host}`, external: true });
139
+ continue;
140
+ }
141
+ // plugin[] array edit — same ownership + backup + atomic-rename discipline as the MCP writer.
142
+ const claim = claimPath(target.file, artifactId);
143
+ if (!claim.ok) {
144
+ skipped.push({ host: target.host, code: 'foreign', message: `${target.file} is claimed by environment '${claim.env}'` });
145
+ continue;
146
+ }
147
+ const parsed = fs.existsSync(target.file)
148
+ ? readConfigObject(target.file)
149
+ : { ok: true, config: {} };
150
+ if (!parsed.ok) {
151
+ skipped.push({ host: target.host, code: 'bad_request', message: parsed.reason });
152
+ continue;
153
+ }
154
+ const container = parsed.config[target.container];
155
+ const arr = Array.isArray(container) ? container : (parsed.config[target.container] = []);
156
+ if (!arr.includes(req.spec))
157
+ arr.push(req.spec);
158
+ try {
159
+ createBackup(target.file);
160
+ safeWriteJson(target.file, parsed.config);
161
+ }
162
+ catch (e) {
163
+ skipped.push({ host: target.host, code: 'upstream', message: e instanceof Error ? e.message : String(e) });
164
+ continue;
165
+ }
166
+ firstConfigHash ??= hashFile(target.file);
167
+ copies.push({ host: target.host, path: target.file });
168
+ }
169
+ // A failed subprocess run with no successful target must NOT mint a manifest entry — the guard is
170
+ // copies-only (a failed run still fills `runs`); the runs travel on the failure variant instead.
171
+ if (copies.length === 0) {
172
+ return { ok: false, code: skipped[0]?.code ?? 'no_target', message: skipped.map((s) => `${s.host}: ${s.message}`).join('; ') || 'no extension target', skipped, runs };
173
+ }
174
+ const manifest = readManifest();
175
+ const now = new Date().toISOString();
176
+ const previous = manifest.artifacts.find((a) => a.id === artifactId);
177
+ const kept = (previous?.copies ?? []).filter((c) => !copies.some((item) => item.path && item.path === c.path));
178
+ const contentHash = firstConfigHash ?? `subprocess:${runs.map((r) => `${r.host}@${r.code}`).join(',')}`;
179
+ manifest.artifacts = [
180
+ ...manifest.artifacts.filter((a) => a.id !== artifactId),
181
+ {
182
+ id: artifactId,
183
+ canonicalKey: req.canonicalKey,
184
+ kind: 'extension',
185
+ harness: req.harness,
186
+ name: req.spec,
187
+ ...(req.description ? { description: req.description } : {}),
188
+ sourceId: req.sourceId,
189
+ // `ref` is the canonicalKey WITHOUT its `<sourceId>:` prefix. It is derived from the key, not
190
+ // from `sourceId`: a discovery source may answer ANOTHER source's identity (awesome-opencode
191
+ // resolves to `npm:<pkg>` — the artifact IS that package), and slicing by the requesting
192
+ // source's own length would then cut the ref in the wrong place.
193
+ ref: req.canonicalKey.includes(':')
194
+ ? req.canonicalKey.slice(req.canonicalKey.indexOf(':') + 1)
195
+ : req.canonicalKey,
196
+ // Provenance comes from the adapter; only a payload with no pin at all (manual spec) is
197
+ // `adopted`, and that word means exactly "no upstream claim to verify".
198
+ pin: req.pin ?? { adopted: true },
199
+ contentHash,
200
+ listedOn: req.listedOn ?? [req.sourceId],
201
+ trust: req.trust,
202
+ copies: [
203
+ ...kept,
204
+ ...copies.map((item) => ({
205
+ scope: req.scope,
206
+ host: item.host,
207
+ rootId: 'default',
208
+ path: item.path ?? `${req.canonicalKey}#${item.host}`,
209
+ ...(item.external ? { external: true } : {}),
210
+ contentHash,
211
+ placement: 'materialized',
212
+ installedAt: now,
213
+ })),
214
+ ],
215
+ },
216
+ ];
217
+ writeManifest(manifest);
218
+ return { ok: true, artifactId, name: req.spec, copies, runs, skipped };
219
+ }