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,88 @@
|
|
|
1
|
+
import { type ProbeResult } from './probe.js';
|
|
2
|
+
import type { McpTargetPlan } from './writers/mcp.js';
|
|
3
|
+
import type { ExtensionTargetPlan } from './writers/extension.js';
|
|
4
|
+
import type { ExecImpl } from './writers/extension.js';
|
|
5
|
+
import type { McpLaunch, ResolveFailureCode } from './spi.js';
|
|
6
|
+
import { type InstallSkipped } from './writers/skill.js';
|
|
7
|
+
import type { HarnessHostId, HarnessKind, HarnessScope } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Install orchestrator (ADR-0015 §8): source adapter → normalized payload → kind writer.
|
|
10
|
+
*
|
|
11
|
+
* The orchestrator owns vocabulary only — key parsing and failure mapping. Network lives in the
|
|
12
|
+
* source adapter, disk in the writer; adding a marketplace or an artifact kind never widens this
|
|
13
|
+
* file beyond dispatch.
|
|
14
|
+
*
|
|
15
|
+
* Key grammar: `<sourceId>:<ref>` with an optional `#detail` pin on the ref
|
|
16
|
+
* (e.g. `github:owner/repo#skill-dir`). A request may instead carry the legacy `repo` +
|
|
17
|
+
* `skillDir` fields, which compose into the same key. The manual escape hatch (§D6) skips resolve
|
|
18
|
+
* entirely: `manualPayload` IS the payload, keyed `manual:<name>`.
|
|
19
|
+
*
|
|
20
|
+
* MCP writes follow plan → confirm → apply (gate 1/2): without `confirm`, a kind-'mcp' request
|
|
21
|
+
* answers `confirm_required` with the per-host merge plan (added/changed keys) and touches nothing.
|
|
22
|
+
*
|
|
23
|
+
* Extensions are harness-bound (ADR-0015 §D2): the request must name exactly ONE host, which becomes
|
|
24
|
+
* the artifact's `harness` dimension (`extension:<harness>:<canonicalKey>`), not just a landing path.
|
|
25
|
+
*/
|
|
26
|
+
export interface InstallRequest {
|
|
27
|
+
sourceId?: string;
|
|
28
|
+
/** Canonical key `<sourceId>:<ref>[#detail]`; wins over `repo`+`skillDir` when both are given. */
|
|
29
|
+
key?: string;
|
|
30
|
+
/** Legacy/compat fields: `owner/repo` + optional skill directory (github source). */
|
|
31
|
+
repo?: string;
|
|
32
|
+
skillDir?: string;
|
|
33
|
+
kind?: HarnessKind;
|
|
34
|
+
/** Manual source payload (ADR-0015 §D6) — `kind` must be `mcp`; key becomes `manual:<name>`. */
|
|
35
|
+
manualPayload?: {
|
|
36
|
+
name: string;
|
|
37
|
+
launch: McpLaunch;
|
|
38
|
+
};
|
|
39
|
+
/** Manual extension spec (ADR-0015 §D6) — `kind` must be `extension`; key becomes `manual:<spec>`. */
|
|
40
|
+
manualSpec?: string;
|
|
41
|
+
/** Confirm gate for config-merging kinds. Without it, `kind: 'mcp'` returns the plan only. */
|
|
42
|
+
confirm?: boolean;
|
|
43
|
+
/** Injectable process runner for extension subprocess installs. */
|
|
44
|
+
execImpl?: ExecImpl;
|
|
45
|
+
/** Landing hosts. `kind: 'extension'` requires EXACTLY one — the harness is part of its identity. */
|
|
46
|
+
hosts: HarnessHostId[];
|
|
47
|
+
/**
|
|
48
|
+
* Landing scope. The signature keeps the full union as the SEAM for project support, but the admin
|
|
49
|
+
* route refuses anything outside `ENABLED_SCOPES` (`harness/scopes.ts`) — today `global` only — so
|
|
50
|
+
* no request from the product can land inside a repository (ADR-0015 §D2 "Scope").
|
|
51
|
+
*/
|
|
52
|
+
scope: HarnessScope;
|
|
53
|
+
/**
|
|
54
|
+
* Other surfaces the operator found this artifact on, besides the one that writes it (`pi-dev` for
|
|
55
|
+
* a package browsed in the Pi catalog, whose install runs through `npm`). The writer source is
|
|
56
|
+
* always recorded first; ids are grammar-checked, deduped and capped, never looked up.
|
|
57
|
+
*/
|
|
58
|
+
listedOn?: string[];
|
|
59
|
+
fetchImpl?: typeof fetch;
|
|
60
|
+
/** Project root for `project` scope; defaults to this process's cwd (threaded for tests). */
|
|
61
|
+
projectRoot?: string;
|
|
62
|
+
}
|
|
63
|
+
export type InstallResult = {
|
|
64
|
+
ok: true;
|
|
65
|
+
artifactId: string;
|
|
66
|
+
name: string;
|
|
67
|
+
storeRef?: string;
|
|
68
|
+
commitSha?: string;
|
|
69
|
+
files?: number;
|
|
70
|
+
bytes?: number;
|
|
71
|
+
copies: {
|
|
72
|
+
host: string;
|
|
73
|
+
path?: string;
|
|
74
|
+
}[];
|
|
75
|
+
skipped: InstallSkipped[];
|
|
76
|
+
/** Post-apply verification — placement upgrades live in the manifest copies. */
|
|
77
|
+
probe?: ProbeResult;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
code: InstallFailureCode;
|
|
81
|
+
message: string;
|
|
82
|
+
candidates?: string[];
|
|
83
|
+
skipped?: InstallSkipped[];
|
|
84
|
+
/** Per-host merge plan for `confirm_required` (MCP gate 2: show the exact keys). */
|
|
85
|
+
plan?: McpTargetPlan[] | ExtensionTargetPlan[];
|
|
86
|
+
};
|
|
87
|
+
export type InstallFailureCode = 'bad_request' | ResolveFailureCode | 'confirm_required' | 'invalid_name' | 'no_target' | 'exists' | 'foreign';
|
|
88
|
+
export declare function installArtifact(req: InstallRequest): Promise<InstallResult>;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { getAdapter } from './registry.js';
|
|
2
|
+
import { recordApply } from './ledger.js';
|
|
3
|
+
import { probeArtifact } from './probe.js';
|
|
4
|
+
import { applyMcp, planMcp } from './writers/mcp.js';
|
|
5
|
+
import { applyExtension, planExtension, safeSpec } from './writers/extension.js';
|
|
6
|
+
import { applySkill } from './writers/skill.js';
|
|
7
|
+
/** Upper bound on the recorded listing surfaces: a row is browsed on a handful of catalogs, and an
|
|
8
|
+
* unbounded array would be a manifest field a request could grow without limit. */
|
|
9
|
+
const LISTED_ON_MAX = 8;
|
|
10
|
+
/**
|
|
11
|
+
* The listing surfaces one record keeps, writer source first.
|
|
12
|
+
*
|
|
13
|
+
* The id grammar is checked but the source REGISTRY is not: the console's chips are built from the
|
|
14
|
+
* registry, so an id that names nothing narrows nothing — it can never fabricate a chip or a label.
|
|
15
|
+
* The writer source goes first so a record's own provenance never depends on what the caller claimed.
|
|
16
|
+
*/
|
|
17
|
+
function composeListedOn(writer, extra) {
|
|
18
|
+
const ids = [writer, ...(extra ?? [])].filter((id) => /^[a-z][\w-]*$/.test(id));
|
|
19
|
+
return [...new Set(ids)].slice(0, LISTED_ON_MAX);
|
|
20
|
+
}
|
|
21
|
+
/** Shape-validate a manual launch BEFORE any writer sees it — a primitive would 500 in desiredEntry. */
|
|
22
|
+
function validLaunch(launch) {
|
|
23
|
+
if (!launch || typeof launch !== 'object')
|
|
24
|
+
return false;
|
|
25
|
+
const l = launch;
|
|
26
|
+
const stringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');
|
|
27
|
+
if (typeof l.command === 'string' && l.command.trim() !== '') {
|
|
28
|
+
return (l.args === undefined || stringArray(l.args)) && (l.envKeys === undefined || stringArray(l.envKeys));
|
|
29
|
+
}
|
|
30
|
+
if (typeof l.url === 'string' && l.url.trim() !== '') {
|
|
31
|
+
return ((l.transport === undefined || ['http', 'sse', 'stdio'].includes(l.transport)) &&
|
|
32
|
+
(l.headerKeys === undefined || stringArray(l.headerKeys)));
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/** Compose the canonical key from either request shape; validates the `#detail` segment. */
|
|
37
|
+
function composeKey(req) {
|
|
38
|
+
const kind = req.kind ?? 'skill';
|
|
39
|
+
if (req.manualPayload) {
|
|
40
|
+
if (kind !== 'mcp')
|
|
41
|
+
return { ok: false, message: 'manualPayload currently serves kind mcp only' };
|
|
42
|
+
const name = req.manualPayload.name.trim();
|
|
43
|
+
if (!name || !/^[\w.-]+$/.test(name))
|
|
44
|
+
return { ok: false, message: `invalid server name '${req.manualPayload.name}'` };
|
|
45
|
+
// A server name becomes an object KEY in the runtime's config. `__proto__` is not a key: an
|
|
46
|
+
// assignment to it rewrites the prototype, `JSON.stringify` then omits the entry, and the apply
|
|
47
|
+
// would report success over a config that never received the server.
|
|
48
|
+
if (['__proto__', 'prototype', 'constructor'].includes(name)) {
|
|
49
|
+
return { ok: false, message: `reserved server name '${name}'` };
|
|
50
|
+
}
|
|
51
|
+
if (!validLaunch(req.manualPayload.launch)) {
|
|
52
|
+
return { ok: false, message: 'invalid manual launch: expected {command, args?, envKeys?} or {url, transport?, headerKeys?}' };
|
|
53
|
+
}
|
|
54
|
+
return { ok: true, key: `manual:${name}`, kind };
|
|
55
|
+
}
|
|
56
|
+
if (req.manualSpec) {
|
|
57
|
+
if (kind !== 'extension')
|
|
58
|
+
return { ok: false, message: 'manualSpec serves kind extension only' };
|
|
59
|
+
if (!safeSpec(req.manualSpec))
|
|
60
|
+
return { ok: false, message: `invalid package spec '${req.manualSpec}'` };
|
|
61
|
+
return { ok: true, key: `manual:${req.manualSpec}`, kind };
|
|
62
|
+
}
|
|
63
|
+
if (req.key) {
|
|
64
|
+
if (!/^[a-z][\w-]*:[\s\S]+$/.test(req.key)) {
|
|
65
|
+
return { ok: false, message: `invalid key '${req.key}' (expected <sourceId>:<ref>)` };
|
|
66
|
+
}
|
|
67
|
+
// A `..` segment in the ref would resolve outside the store when an adapter later joins it
|
|
68
|
+
// into a path (`node_modules/<name>`, a landing directory).
|
|
69
|
+
if (req.key.includes('..'))
|
|
70
|
+
return { ok: false, message: `invalid key '${req.key}'` };
|
|
71
|
+
return { ok: true, key: req.key, kind };
|
|
72
|
+
}
|
|
73
|
+
const dir = req.skillDir?.trim().replace(/^\/+|\/+$/g, '') || '';
|
|
74
|
+
if (dir && !/^[\w./-]+$/.test(dir)) {
|
|
75
|
+
return { ok: false, message: `invalid skill directory '${dir}'` };
|
|
76
|
+
}
|
|
77
|
+
if (dir && dir.split('/').includes('..')) {
|
|
78
|
+
return { ok: false, message: `invalid skill directory '${dir}'` };
|
|
79
|
+
}
|
|
80
|
+
if (!req.repo)
|
|
81
|
+
return { ok: false, message: 'repo or key is required' };
|
|
82
|
+
return { ok: true, key: `github:${req.repo}${dir ? `#${dir}` : ''}`, kind };
|
|
83
|
+
}
|
|
84
|
+
export async function installArtifact(req) {
|
|
85
|
+
if (!Array.isArray(req.hosts) || req.hosts.length === 0) {
|
|
86
|
+
return { ok: false, code: 'bad_request', message: 'hosts[] must not be empty' };
|
|
87
|
+
}
|
|
88
|
+
if (req.scope !== 'global' && req.scope !== 'project') {
|
|
89
|
+
return { ok: false, code: 'bad_request', message: `invalid scope '${String(req.scope)}'` };
|
|
90
|
+
}
|
|
91
|
+
const composed = composeKey(req);
|
|
92
|
+
if (!composed.ok)
|
|
93
|
+
return { ok: false, code: 'bad_request', message: composed.message };
|
|
94
|
+
const { key, kind } = composed;
|
|
95
|
+
// An extension is code against ONE runtime's plugin API: exactly one harness per install, and the
|
|
96
|
+
// harness is part of the artifact id. Two harnesses = two installs, never one multi-host copy.
|
|
97
|
+
if (kind === 'extension' && req.hosts.length !== 1) {
|
|
98
|
+
return { ok: false, code: 'bad_request', message: 'extension installs target exactly one harness' };
|
|
99
|
+
}
|
|
100
|
+
const sep = key.indexOf(':');
|
|
101
|
+
const sourceId = key.slice(0, sep);
|
|
102
|
+
const ref = key.slice(sep + 1);
|
|
103
|
+
/** Discovery facets travel with the record: the writer source plus wherever it was browsed. */
|
|
104
|
+
const listedOn = composeListedOn(sourceId, req.listedOn);
|
|
105
|
+
const adapter = getAdapter(sourceId);
|
|
106
|
+
let canonicalKey;
|
|
107
|
+
let payloadName;
|
|
108
|
+
let launch;
|
|
109
|
+
let skillFiles;
|
|
110
|
+
/** Extension package spec (what the writer inserts verbatim); set only by an extension payload. */
|
|
111
|
+
let extSpec;
|
|
112
|
+
let storeKey;
|
|
113
|
+
let pin;
|
|
114
|
+
/** Resolved one-line description; travels to the manifest so installed rows are not blank. */
|
|
115
|
+
let description;
|
|
116
|
+
let trust;
|
|
117
|
+
if (req.manualPayload) {
|
|
118
|
+
trust = 'manual';
|
|
119
|
+
canonicalKey = key;
|
|
120
|
+
payloadName = req.manualPayload.name.trim();
|
|
121
|
+
launch = req.manualPayload.launch;
|
|
122
|
+
}
|
|
123
|
+
else if (req.manualSpec) {
|
|
124
|
+
trust = 'manual';
|
|
125
|
+
canonicalKey = key;
|
|
126
|
+
payloadName = req.manualSpec;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (!adapter) {
|
|
130
|
+
return { ok: false, code: 'unsupported_source', message: `no install adapter for source '${sourceId}'` };
|
|
131
|
+
}
|
|
132
|
+
if (!adapter.kinds.includes(kind)) {
|
|
133
|
+
return { ok: false, code: 'unsupported_kind', message: `source '${sourceId}' cannot resolve kind '${kind}'` };
|
|
134
|
+
}
|
|
135
|
+
// A source may declare the harnesses its artifacts serve (ADR-0015 §D2). An extension is
|
|
136
|
+
// harness-bound by nature, so a source that does not serve THIS runtime cannot produce its code.
|
|
137
|
+
if (kind === 'extension' && adapter.hosts) {
|
|
138
|
+
const harness = req.hosts[0];
|
|
139
|
+
if (!adapter.hosts.includes(harness)) {
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
code: 'unsupported_source',
|
|
143
|
+
message: `source '${sourceId}' does not serve extensions for harness '${harness}'`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const opts = req.fetchImpl ? { fetchImpl: req.fetchImpl } : {};
|
|
148
|
+
const resolved = await adapter.resolve(ref, kind, opts);
|
|
149
|
+
if (!resolved.ok) {
|
|
150
|
+
return { ok: false, code: resolved.code, message: resolved.message, candidates: resolved.candidates };
|
|
151
|
+
}
|
|
152
|
+
trust = adapter.trust;
|
|
153
|
+
canonicalKey = resolved.canonicalKey;
|
|
154
|
+
payloadName = resolved.payload.name;
|
|
155
|
+
storeKey = resolved.storeKey;
|
|
156
|
+
pin = resolved.pin;
|
|
157
|
+
description = resolved.description ?? null;
|
|
158
|
+
if (resolved.payload.kind === 'mcp')
|
|
159
|
+
launch = resolved.payload.launch;
|
|
160
|
+
else if (resolved.payload.kind === 'skill')
|
|
161
|
+
skillFiles = resolved.payload.files;
|
|
162
|
+
else
|
|
163
|
+
extSpec = resolved.payload.spec;
|
|
164
|
+
}
|
|
165
|
+
switch (kind) {
|
|
166
|
+
case 'skill': {
|
|
167
|
+
if (!skillFiles || !pin)
|
|
168
|
+
return { ok: false, code: 'bad_request', message: 'skill dispatch without a skill payload' };
|
|
169
|
+
const applied = applySkill({
|
|
170
|
+
sourceId,
|
|
171
|
+
canonicalKey,
|
|
172
|
+
rawName: payloadName,
|
|
173
|
+
storeKey: storeKey ?? `${sourceId}__${payloadName}`,
|
|
174
|
+
files: skillFiles,
|
|
175
|
+
pin,
|
|
176
|
+
trust,
|
|
177
|
+
listedOn,
|
|
178
|
+
hosts: req.hosts,
|
|
179
|
+
scope: req.scope,
|
|
180
|
+
projectRoot: req.projectRoot,
|
|
181
|
+
});
|
|
182
|
+
if (!applied.ok) {
|
|
183
|
+
recordApply({
|
|
184
|
+
action: 'install', kind: 'skill', artifactId: `skill:${canonicalKey}`, name: payloadName,
|
|
185
|
+
hosts: req.hosts, outcome: 'failed', message: applied.message,
|
|
186
|
+
});
|
|
187
|
+
return { ok: false, code: applied.code, message: applied.message, skipped: applied.skipped };
|
|
188
|
+
}
|
|
189
|
+
const outcome = applied.skipped.length > 0 ? 'partial' : 'ok';
|
|
190
|
+
recordApply({
|
|
191
|
+
action: 'install', kind: 'skill', artifactId: applied.artifactId, name: applied.name,
|
|
192
|
+
hosts: applied.copies.map((c) => c.host),
|
|
193
|
+
outcome,
|
|
194
|
+
message: outcome === 'partial' ? applied.skipped.map((s) => `${s.host}: ${s.message}`).join('; ') : `${applied.files} files, ${applied.bytes} bytes`,
|
|
195
|
+
});
|
|
196
|
+
const commitSha = 'git' in pin ? pin.git.commitSha : undefined;
|
|
197
|
+
const probe = probeArtifact(applied.artifactId) ?? undefined;
|
|
198
|
+
return { ...applied, commitSha, probe };
|
|
199
|
+
}
|
|
200
|
+
case 'mcp': {
|
|
201
|
+
if (!launch)
|
|
202
|
+
return { ok: false, code: 'bad_request', message: 'mcp dispatch without a launch spec' };
|
|
203
|
+
const mcpReq = {
|
|
204
|
+
sourceId,
|
|
205
|
+
canonicalKey,
|
|
206
|
+
name: payloadName,
|
|
207
|
+
...(description ? { description } : {}),
|
|
208
|
+
launch,
|
|
209
|
+
trust,
|
|
210
|
+
// Adapter provenance travels to the manifest (the same rule the extension path applies);
|
|
211
|
+
// a manual entry has none, and the writer records `adopted` for it.
|
|
212
|
+
pin: pin ?? { adopted: true },
|
|
213
|
+
listedOn,
|
|
214
|
+
hosts: req.hosts,
|
|
215
|
+
scope: req.scope,
|
|
216
|
+
projectRoot: req.projectRoot,
|
|
217
|
+
};
|
|
218
|
+
// Gate 1/2 — plan → confirm → apply. Without confirmation, NOTHING is written.
|
|
219
|
+
if (!req.confirm) {
|
|
220
|
+
const plan = planMcp(mcpReq);
|
|
221
|
+
if (!plan.ok)
|
|
222
|
+
return { ok: false, code: 'bad_request', message: plan.message };
|
|
223
|
+
return {
|
|
224
|
+
ok: false,
|
|
225
|
+
code: 'confirm_required',
|
|
226
|
+
message: `MCP install merges into ${plan.targets.filter((t) => !t.refused).length} config file(s) — confirm to apply`,
|
|
227
|
+
plan: plan.targets,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const applied = applyMcp(mcpReq);
|
|
231
|
+
if (!applied.ok) {
|
|
232
|
+
recordApply({
|
|
233
|
+
action: 'install', kind: 'mcp', artifactId: `mcp:${canonicalKey}`, name: payloadName,
|
|
234
|
+
hosts: req.hosts, outcome: 'failed', message: applied.message,
|
|
235
|
+
});
|
|
236
|
+
return { ok: false, code: applied.code, message: applied.message, skipped: applied.skipped };
|
|
237
|
+
}
|
|
238
|
+
recordApply({
|
|
239
|
+
action: 'install', kind: 'mcp', artifactId: applied.artifactId, name: applied.name,
|
|
240
|
+
hosts: applied.copies.map((c) => c.host),
|
|
241
|
+
outcome: applied.skipped.length > 0 ? 'partial' : 'ok',
|
|
242
|
+
message: applied.skipped.length > 0 ? applied.skipped.map((s) => `${s.host}: ${s.message}`).join('; ') : `merged into ${applied.copies.length} config file(s)`,
|
|
243
|
+
});
|
|
244
|
+
const probe = probeArtifact(applied.artifactId) ?? undefined;
|
|
245
|
+
return { ...applied, skipped: applied.skipped, probe };
|
|
246
|
+
}
|
|
247
|
+
case 'extension': {
|
|
248
|
+
const harness = req.hosts[0];
|
|
249
|
+
const extReq = {
|
|
250
|
+
sourceId,
|
|
251
|
+
canonicalKey,
|
|
252
|
+
// `manualSpec` IS the spec; an adapter payload answers the concrete pinned spec separately.
|
|
253
|
+
spec: extSpec ?? payloadName,
|
|
254
|
+
...(description ? { description } : {}),
|
|
255
|
+
trust,
|
|
256
|
+
listedOn,
|
|
257
|
+
// Adapter provenance travels to the manifest; a manual spec has none, so the writer records
|
|
258
|
+
// `adopted` rather than an invented pin.
|
|
259
|
+
pin: pin ?? { adopted: true },
|
|
260
|
+
harness,
|
|
261
|
+
scope: req.scope,
|
|
262
|
+
projectRoot: req.projectRoot,
|
|
263
|
+
execImpl: req.execImpl,
|
|
264
|
+
};
|
|
265
|
+
// Gate 1/3 — plan → confirm → apply; the plan echoes the EXACT third-party command.
|
|
266
|
+
if (!req.confirm) {
|
|
267
|
+
const plan = planExtension(extReq);
|
|
268
|
+
if (!plan.ok)
|
|
269
|
+
return { ok: false, code: 'bad_request', message: plan.message };
|
|
270
|
+
return {
|
|
271
|
+
ok: false,
|
|
272
|
+
code: 'confirm_required',
|
|
273
|
+
message: 'extension install executes third-party code (npm lifecycle scripts) — confirm to apply',
|
|
274
|
+
plan: plan.targets,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const applied = await applyExtension(extReq);
|
|
278
|
+
if (!applied.ok) {
|
|
279
|
+
recordApply({
|
|
280
|
+
action: 'install', kind: 'extension', artifactId: `extension:${harness}:${canonicalKey}`, name: payloadName,
|
|
281
|
+
hosts: [harness], command: applied.runs?.[0]?.command ?? '',
|
|
282
|
+
outcome: 'failed', message: applied.message,
|
|
283
|
+
});
|
|
284
|
+
return { ok: false, code: applied.code, message: applied.message, skipped: applied.skipped };
|
|
285
|
+
}
|
|
286
|
+
recordApply({
|
|
287
|
+
action: 'install', kind: 'extension', artifactId: applied.artifactId, name: applied.name,
|
|
288
|
+
hosts: [harness],
|
|
289
|
+
command: applied.runs[0]?.command ?? '',
|
|
290
|
+
outcome: applied.skipped.length > 0 ? 'partial' : 'ok',
|
|
291
|
+
message: applied.runs.length > 0
|
|
292
|
+
? applied.runs.map((r) => `${r.host}: exit ${r.code}`).join('; ')
|
|
293
|
+
: `merged into ${applied.copies.length} config file(s)`,
|
|
294
|
+
});
|
|
295
|
+
const probe = probeArtifact(applied.artifactId) ?? undefined;
|
|
296
|
+
return { ...applied, skipped: applied.skipped, probe };
|
|
297
|
+
}
|
|
298
|
+
default:
|
|
299
|
+
return { ok: false, code: 'unsupported_kind', message: `no writer for kind '${kind}'` };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HarnessHostId, HarnessScope, InventoryResponse } from './types.js';
|
|
2
|
+
/** Every skills directory the host adapters resolve, deduplicated, BOTH scopes (project roots use
|
|
3
|
+
* cwd). The scan below narrows to `ENABLED_SCOPES`; the removal guard needs the full set so a copy
|
|
4
|
+
* installed while project scope was open stays removable. */
|
|
5
|
+
export declare function skillRoots(projectRoot?: string): {
|
|
6
|
+
host: HarnessHostId;
|
|
7
|
+
scope: HarnessScope;
|
|
8
|
+
root: string;
|
|
9
|
+
}[];
|
|
10
|
+
export declare function scanInventory(projectRoot?: string): InventoryResponse;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolveEnvName, getEnvRootDir } from '../config/env.js';
|
|
4
|
+
import { copyDrift } from './drift.js';
|
|
5
|
+
import { readSkillMeta } from './skill-md.js';
|
|
6
|
+
import { adapterFor, skillLocationRoots, skillReaders } from './adapters/index.js';
|
|
7
|
+
import { claimOwner, readManifest } from './manifest.js';
|
|
8
|
+
import { discoverExtensions, discoverMcp, extensionSources, mcpSources, mcpTrackedKey, trackedKey } from './discover.js';
|
|
9
|
+
import { isEnabledScope } from './scopes.js';
|
|
10
|
+
/**
|
|
11
|
+
* Inventory — "what is installed where", reconciled against the manifest (ADR-0015 §D8.7).
|
|
12
|
+
*
|
|
13
|
+
* Read-only. A copy's state is the ONLY persisted vocabulary; `rollup` is derived here and never
|
|
14
|
+
* written. Hashing uses the mtime+size fast path first: an unchanged copy is `clean` without I/O;
|
|
15
|
+
* otherwise `copyDrift` hashes it with the algorithm its writer recorded (a tree for a skill
|
|
16
|
+
* directory, the single file for a config copy).
|
|
17
|
+
*/
|
|
18
|
+
function isSkillDir(abs) {
|
|
19
|
+
return fs.existsSync(path.join(abs, 'SKILL.md'));
|
|
20
|
+
}
|
|
21
|
+
function fingerprint(abs) {
|
|
22
|
+
try {
|
|
23
|
+
const stat = fs.statSync(abs);
|
|
24
|
+
return { mtimeMs: stat.mtimeMs, bytes: stat.size };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function copyState(copy, envName) {
|
|
31
|
+
// A package-manager-owned copy has no path of ours: `path` is an identity token, so every
|
|
32
|
+
// existence/hash check would report 'missing' (the pi-extension bug) or 'dirty'. There is no
|
|
33
|
+
// content WE own to reconcile — the runtime's own store is the truth, and the apply-time
|
|
34
|
+
// subprocess exit code already proved the install — so the copy is reported clean.
|
|
35
|
+
if (copy.external === true)
|
|
36
|
+
return 'clean';
|
|
37
|
+
if (!fs.existsSync(copy.path))
|
|
38
|
+
return 'missing';
|
|
39
|
+
const owner = claimOwner(copy.path);
|
|
40
|
+
if (owner && owner !== envName)
|
|
41
|
+
return 'foreign';
|
|
42
|
+
const fp = fingerprint(copy.path);
|
|
43
|
+
if (fp && copy.mtimeMs === fp.mtimeMs && copy.bytes === fp.bytes)
|
|
44
|
+
return 'clean';
|
|
45
|
+
try {
|
|
46
|
+
// Same algorithm the writer recorded with, chosen per copy shape (file config vs skill tree):
|
|
47
|
+
// `hashTree` on a config FILE returns the empty-tree digest and would report every MCP copy
|
|
48
|
+
// dirty as soon as another server is merged into the same file.
|
|
49
|
+
return copyDrift(copy, copy.path) ? 'dirty' : 'clean';
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return 'missing';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function rollupOf(copies) {
|
|
56
|
+
if (copies.length === 0)
|
|
57
|
+
return 'missing';
|
|
58
|
+
if (copies.some((c) => c.state === 'dirty'))
|
|
59
|
+
return 'dirty';
|
|
60
|
+
if (copies.some((c) => c.state === 'missing'))
|
|
61
|
+
return 'missing';
|
|
62
|
+
if (copies.some((c) => c.state === 'foreign'))
|
|
63
|
+
return 'partial';
|
|
64
|
+
return 'clean';
|
|
65
|
+
}
|
|
66
|
+
function toView(record, envName, projectRoot) {
|
|
67
|
+
const copies = record.copies.map((copy) => ({
|
|
68
|
+
scope: copy.scope,
|
|
69
|
+
host: copy.host,
|
|
70
|
+
rootId: copy.rootId,
|
|
71
|
+
path: copy.path,
|
|
72
|
+
...(copy.external ? { external: true } : {}),
|
|
73
|
+
state: copyState(copy, envName),
|
|
74
|
+
placement: copy.placement,
|
|
75
|
+
contentHash: copy.contentHash,
|
|
76
|
+
// Skills only: a directory is read by its owner plus every `readsUniversal` runtime, and the
|
|
77
|
+
// console's rail asks exactly that question. The ROOT is the copy's parent — a skill target is
|
|
78
|
+
// always `<root>/<name>` (enforced by `skillTarget`), never nested. Config-shaped copies carry
|
|
79
|
+
// no readers.
|
|
80
|
+
...(record.kind === 'skill' && copy.external !== true
|
|
81
|
+
? { readers: skillReaders(path.dirname(copy.path), copy.scope, projectRoot) }
|
|
82
|
+
: {}),
|
|
83
|
+
}));
|
|
84
|
+
return {
|
|
85
|
+
id: record.id,
|
|
86
|
+
canonicalKey: record.canonicalKey,
|
|
87
|
+
kind: record.kind,
|
|
88
|
+
...(record.harness ? { harness: record.harness } : {}),
|
|
89
|
+
name: record.name,
|
|
90
|
+
// Installed text wins when the copy carries it (a skill's `SKILL.md` is the authoritative prose);
|
|
91
|
+
// the manifest's recorded description is the fallback for kinds whose copy has no file of ours to
|
|
92
|
+
// read — an npm package living in the runtime's own store, an MCP entry inside a host config.
|
|
93
|
+
description: record.copies.map((c) => (fs.existsSync(c.path) ? readSkillMeta(c.path).description ?? null : null)).find((d) => d) ??
|
|
94
|
+
record.description ??
|
|
95
|
+
null,
|
|
96
|
+
sourceId: record.sourceId ?? null,
|
|
97
|
+
// A record written before the facet existed has no `listedOn`: the writer source is then the
|
|
98
|
+
// only surface it is known to have been listed on, never an empty claim.
|
|
99
|
+
listedOn: record.listedOn ?? (record.sourceId ? [record.sourceId] : []),
|
|
100
|
+
trust: record.trust,
|
|
101
|
+
audit: null,
|
|
102
|
+
copies,
|
|
103
|
+
rollup: rollupOf(copies),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Every skills directory the host adapters resolve, deduplicated, BOTH scopes (project roots use
|
|
107
|
+
* cwd). The scan below narrows to `ENABLED_SCOPES`; the removal guard needs the full set so a copy
|
|
108
|
+
* installed while project scope was open stays removable. */
|
|
109
|
+
export function skillRoots(projectRoot = process.cwd()) {
|
|
110
|
+
return skillLocationRoots(projectRoot);
|
|
111
|
+
}
|
|
112
|
+
export function scanInventory(projectRoot = process.cwd()) {
|
|
113
|
+
const envName = resolveEnvName();
|
|
114
|
+
const manifest = readManifest();
|
|
115
|
+
const artifacts = manifest.artifacts.map((record) => toView(record, envName, projectRoot));
|
|
116
|
+
const tracked = new Set();
|
|
117
|
+
for (const record of manifest.artifacts) {
|
|
118
|
+
// An `external` copy's `path` is an identity token, not a location — resolving it would put a
|
|
119
|
+
// nonsense entry in the tracked set (and could never match a scanned directory anyway).
|
|
120
|
+
for (const copy of record.copies)
|
|
121
|
+
if (copy.external !== true)
|
|
122
|
+
tracked.add(path.resolve(copy.path));
|
|
123
|
+
}
|
|
124
|
+
const untracked = [];
|
|
125
|
+
let hostsScanned = 0;
|
|
126
|
+
for (const { host, scope, root } of skillRoots(projectRoot)) {
|
|
127
|
+
// Project discovery is deferred (ADR-0015 §D2 "Scope"): an enabled-scope filter, not an adapter
|
|
128
|
+
// change — the project roots stay declared in the adapters as the seam.
|
|
129
|
+
if (!isEnabledScope(scope))
|
|
130
|
+
continue;
|
|
131
|
+
hostsScanned += 1;
|
|
132
|
+
let entries;
|
|
133
|
+
try {
|
|
134
|
+
entries = fs.readdirSync(root);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const name of entries) {
|
|
140
|
+
const abs = path.join(root, name);
|
|
141
|
+
if (tracked.has(abs) || !isSkillDir(abs))
|
|
142
|
+
continue;
|
|
143
|
+
const owner = claimOwner(abs);
|
|
144
|
+
untracked.push({
|
|
145
|
+
scope,
|
|
146
|
+
host,
|
|
147
|
+
rootId: adapterFor(host)?.configRootEnv ?? 'default',
|
|
148
|
+
path: abs,
|
|
149
|
+
state: owner ? 'foreign' : 'untracked',
|
|
150
|
+
placement: 'materialized',
|
|
151
|
+
// The same readership answer a tracked copy gets: a directory found on disk is read by every
|
|
152
|
+
// runtime whose skills roots resolve to it, not only by the adapter that reported it.
|
|
153
|
+
readers: skillReaders(root, scope, projectRoot),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Group per skill NAME, not per directory: one skill commonly lives in several host roots, and
|
|
158
|
+
// listing each directory separately turns a normal machine into a wall of duplicate paths.
|
|
159
|
+
const byName = new Map();
|
|
160
|
+
for (const copy of untracked) {
|
|
161
|
+
const name = path.basename(copy.path);
|
|
162
|
+
const entry = byName.get(name) ?? {
|
|
163
|
+
kind: 'skill',
|
|
164
|
+
name,
|
|
165
|
+
description: readSkillMeta(copy.path).description ?? null,
|
|
166
|
+
copies: [],
|
|
167
|
+
hosts: [],
|
|
168
|
+
};
|
|
169
|
+
entry.copies.push(copy);
|
|
170
|
+
if (!entry.hosts.includes(copy.host))
|
|
171
|
+
entry.hosts.push(copy.host);
|
|
172
|
+
byName.set(name, entry);
|
|
173
|
+
}
|
|
174
|
+
// Extensions get the mirror treatment (ADR-0015 §D8.10): the runtime's own store is read-only
|
|
175
|
+
// observation, and an artifact this environment already tracks is excluded so one install is
|
|
176
|
+
// never reported twice under two different owners.
|
|
177
|
+
const trackedExtensions = new Set(manifest.artifacts
|
|
178
|
+
.filter((record) => record.kind === 'extension' && record.harness)
|
|
179
|
+
.map((record) => trackedKey(record.harness, record.canonicalKey)));
|
|
180
|
+
const extensions = discoverExtensions(extensionSources(projectRoot).filter((s) => isEnabledScope(s.scope)), { tracked: trackedExtensions });
|
|
181
|
+
// MCP gets the same mirror treatment over the OBJECT-shaped landing: each server key inside a
|
|
182
|
+
// host's `mcp` container is observed, tagged with the host it was read from, and excluded when this
|
|
183
|
+
// environment already tracks that `(host, serverKey)` — see `discoverMcp`.
|
|
184
|
+
const trackedMcp = new Set(manifest.artifacts
|
|
185
|
+
.filter((record) => record.kind === 'mcp')
|
|
186
|
+
.flatMap((record) => record.copies.map((copy) => mcpTrackedKey(copy.host, record.name))));
|
|
187
|
+
const mcp = discoverMcp(mcpSources(projectRoot).filter((s) => isEnabledScope(s.scope)), { tracked: trackedMcp });
|
|
188
|
+
return {
|
|
189
|
+
envName,
|
|
190
|
+
envRoot: getEnvRootDir(),
|
|
191
|
+
hostsScanned,
|
|
192
|
+
artifacts,
|
|
193
|
+
discovered: [...byName.values()].sort((a, b) => a.name.localeCompare(b.name)).concat(extensions, mcp),
|
|
194
|
+
discoveredCopies: untracked.length +
|
|
195
|
+
extensions.reduce((total, row) => total + row.copies.length, 0) +
|
|
196
|
+
mcp.reduce((total, row) => total + row.copies.length, 0),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness apply ledger (ADR-0015) — one row per install/remove apply, on the shared
|
|
3
|
+
* event-ring skeleton (ADR-0013 precedent). The row is an OBSERVATION: what was touched, how it
|
|
4
|
+
* went, the exact subprocess command (gate 3) — never an archive of payloads or secrets.
|
|
5
|
+
*
|
|
6
|
+
* Durable mirror is a bounded JSON file under `<ocrHome>/harness/applies.json`, fail-open like every
|
|
7
|
+
* observability write: a ledger failure must never break an apply.
|
|
8
|
+
*/
|
|
9
|
+
export type HarnessApplyAction = 'install' | 'remove';
|
|
10
|
+
export type HarnessApplyOutcome = 'ok' | 'partial' | 'failed';
|
|
11
|
+
export interface HarnessApplyEvent {
|
|
12
|
+
/** Boot-epoch row key (`ha-…`), collision-free across restarts. */
|
|
13
|
+
id: string;
|
|
14
|
+
ts: number;
|
|
15
|
+
action: HarnessApplyAction;
|
|
16
|
+
kind: string;
|
|
17
|
+
artifactId: string;
|
|
18
|
+
name: string;
|
|
19
|
+
/** Comma-joined host ids touched. */
|
|
20
|
+
hosts: string;
|
|
21
|
+
/** Exact command for subprocess installs (gate 3 echo), else ''. */
|
|
22
|
+
command: string;
|
|
23
|
+
outcome: HarnessApplyOutcome;
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ApplyEventInput {
|
|
27
|
+
action: HarnessApplyAction;
|
|
28
|
+
kind: string;
|
|
29
|
+
artifactId: string;
|
|
30
|
+
name: string;
|
|
31
|
+
hosts: string[];
|
|
32
|
+
command?: string;
|
|
33
|
+
outcome: HarnessApplyOutcome;
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
/** Append one apply row; returns the row id. Never throws. */
|
|
37
|
+
export declare function recordApply(input: ApplyEventInput): string;
|
|
38
|
+
/** Newest-first rows (display order). */
|
|
39
|
+
export declare function recentApplies(limit?: number): HarnessApplyEvent[];
|