@skastr0/prism-sdk 0.3.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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/compile-manifest.d.ts +293 -0
- package/dist/compile-manifest.js +232 -0
- package/dist/mcp/daemon-resolver.d.ts +100 -0
- package/dist/mcp/daemon-resolver.js +185 -0
- package/dist/mcp/shim.d.ts +155 -0
- package/dist/mcp/shim.js +434 -0
- package/dist/mcp/uds-path.d.ts +26 -0
- package/dist/mcp/uds-path.js +70 -0
- package/dist/mcp/uds-registry.d.ts +109 -0
- package/dist/mcp/uds-registry.js +270 -0
- package/dist/mcp/uds-singleton.d.ts +124 -0
- package/dist/mcp/uds-singleton.js +360 -0
- package/dist/refs.d.ts +15 -0
- package/dist/refs.js +26 -0
- package/dist/snapshot.d.ts +92 -0
- package/dist/snapshot.js +74 -0
- package/dist/stable-json.d.ts +8 -0
- package/dist/stable-json.js +27 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guilherme Castro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @skastr0/prism-sdk
|
|
2
|
+
|
|
3
|
+
Core Prism contracts and codecs shared by Prism runtimes and workflow tooling.
|
|
4
|
+
|
|
5
|
+
This package publishes compiled ESM JavaScript plus TypeScript declarations for these public export paths:
|
|
6
|
+
|
|
7
|
+
- `@skastr0/prism-sdk/compile-manifest`
|
|
8
|
+
- `@skastr0/prism-sdk/refs`
|
|
9
|
+
- `@skastr0/prism-sdk/snapshot`
|
|
10
|
+
- `@skastr0/prism-sdk/stable-json`
|
|
11
|
+
|
|
12
|
+
It has no Prism CLI dependency. Consumers should import the explicit subpath they need.
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const COMPILE_MANIFEST_VERSION: 1;
|
|
3
|
+
export declare const HarnessScopeSchema: Schema.Literal<["global", "project"]>;
|
|
4
|
+
export type HarnessScope = typeof HarnessScopeSchema.Type;
|
|
5
|
+
export declare const HarnessIdSchema: Schema.Literal<["amp-code", "antigravity-cli", "claude-code", "codex-cli", "cursor", "factory-droid", "grok", "hermes", "kimi-code", "opencode", "pi"]>;
|
|
6
|
+
export type HarnessId = typeof HarnessIdSchema.Type;
|
|
7
|
+
export declare const CompileManifestPluginSchema: Schema.Struct<{
|
|
8
|
+
version: Schema.optional<typeof Schema.String>;
|
|
9
|
+
sourceHash: typeof Schema.String;
|
|
10
|
+
}>;
|
|
11
|
+
export type CompileManifestPlugin = typeof CompileManifestPluginSchema.Type;
|
|
12
|
+
export declare const CompileManifestTargetSchema: Schema.Struct<{
|
|
13
|
+
harness: Schema.Literal<["amp-code", "antigravity-cli", "claude-code", "codex-cli", "cursor", "factory-droid", "grok", "hermes", "kimi-code", "opencode", "pi"]>;
|
|
14
|
+
scope: Schema.Literal<["global", "project"]>;
|
|
15
|
+
}>;
|
|
16
|
+
export type CompileManifestTarget = typeof CompileManifestTargetSchema.Type;
|
|
17
|
+
export declare const CompileManifestTraitSchema: Schema.Struct<{
|
|
18
|
+
id: typeof Schema.String;
|
|
19
|
+
ref: typeof Schema.String;
|
|
20
|
+
}>;
|
|
21
|
+
export type CompileManifestTrait = typeof CompileManifestTraitSchema.Type;
|
|
22
|
+
export declare const CompileManifestOrbitSchema: Schema.Struct<{
|
|
23
|
+
plugin: typeof Schema.String;
|
|
24
|
+
name: typeof Schema.String;
|
|
25
|
+
}>;
|
|
26
|
+
export type CompileManifestOrbit = typeof CompileManifestOrbitSchema.Type;
|
|
27
|
+
export declare const CompileManifestCanonicalToolSchema: Schema.Struct<{
|
|
28
|
+
plugin: typeof Schema.String;
|
|
29
|
+
name: typeof Schema.String;
|
|
30
|
+
}>;
|
|
31
|
+
export type CompileManifestCanonicalTool = typeof CompileManifestCanonicalToolSchema.Type;
|
|
32
|
+
export declare const CompileManifestToolspaceToolSchema: Schema.Struct<{
|
|
33
|
+
plugin: typeof Schema.String;
|
|
34
|
+
toolspace: typeof Schema.String;
|
|
35
|
+
name: typeof Schema.String;
|
|
36
|
+
}>;
|
|
37
|
+
export type CompileManifestToolspaceTool = typeof CompileManifestToolspaceToolSchema.Type;
|
|
38
|
+
export declare const CompileManifestGrantsSchema: Schema.Struct<{
|
|
39
|
+
tools: Schema.Array$<typeof Schema.String>;
|
|
40
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
41
|
+
}>;
|
|
42
|
+
export type CompileManifestGrants = typeof CompileManifestGrantsSchema.Type;
|
|
43
|
+
export declare const CompileManifestModelBindingsSchema: Schema.Struct<{
|
|
44
|
+
modelspace: Schema.optional<typeof Schema.String>;
|
|
45
|
+
profile: Schema.optional<typeof Schema.String>;
|
|
46
|
+
}>;
|
|
47
|
+
export type CompileManifestModelBindings = typeof CompileManifestModelBindingsSchema.Type;
|
|
48
|
+
export declare const CompileManifestModelspaceSchema: Schema.Struct<{
|
|
49
|
+
plugin: typeof Schema.String;
|
|
50
|
+
modelspace: typeof Schema.String;
|
|
51
|
+
profiles: Schema.Array$<typeof Schema.String>;
|
|
52
|
+
profilesData: Schema.optional<Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>>>;
|
|
53
|
+
}>;
|
|
54
|
+
export type CompileManifestModelspace = typeof CompileManifestModelspaceSchema.Type;
|
|
55
|
+
export declare const CompileManifestManagedSkillSchema: Schema.Struct<{
|
|
56
|
+
plugin: typeof Schema.String;
|
|
57
|
+
name: typeof Schema.String;
|
|
58
|
+
}>;
|
|
59
|
+
export type CompileManifestManagedSkill = typeof CompileManifestManagedSkillSchema.Type;
|
|
60
|
+
export declare const CompileManifestSkillspaceSchema: Schema.Struct<{
|
|
61
|
+
plugin: typeof Schema.String;
|
|
62
|
+
skillspace: typeof Schema.String;
|
|
63
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
64
|
+
}>;
|
|
65
|
+
export type CompileManifestSkillspace = typeof CompileManifestSkillspaceSchema.Type;
|
|
66
|
+
export declare const CompileManifestPerTargetSchema: Schema.Struct<{
|
|
67
|
+
scope: Schema.Literal<["global", "project"]>;
|
|
68
|
+
model: Schema.NullOr<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
69
|
+
toolGrants: Schema.Array$<typeof Schema.String>;
|
|
70
|
+
allowedTools: Schema.Array$<typeof Schema.String>;
|
|
71
|
+
allowedSkills: Schema.Array$<typeof Schema.String>;
|
|
72
|
+
}>;
|
|
73
|
+
export type CompileManifestPerTarget = typeof CompileManifestPerTargetSchema.Type;
|
|
74
|
+
export declare const CompileManifestAgentSchema: Schema.Struct<{
|
|
75
|
+
name: typeof Schema.String;
|
|
76
|
+
plugin: typeof Schema.String;
|
|
77
|
+
description: typeof Schema.String;
|
|
78
|
+
sourceHash: typeof Schema.String;
|
|
79
|
+
traits: Schema.Array$<Schema.Struct<{
|
|
80
|
+
id: typeof Schema.String;
|
|
81
|
+
ref: typeof Schema.String;
|
|
82
|
+
}>>;
|
|
83
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
84
|
+
composed: Schema.Struct<{
|
|
85
|
+
grants: Schema.Struct<{
|
|
86
|
+
tools: Schema.Array$<typeof Schema.String>;
|
|
87
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
88
|
+
}>;
|
|
89
|
+
modelBindings: Schema.Struct<{
|
|
90
|
+
modelspace: Schema.optional<typeof Schema.String>;
|
|
91
|
+
profile: Schema.optional<typeof Schema.String>;
|
|
92
|
+
}>;
|
|
93
|
+
perTarget: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
94
|
+
scope: Schema.Literal<["global", "project"]>;
|
|
95
|
+
model: Schema.NullOr<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
96
|
+
toolGrants: Schema.Array$<typeof Schema.String>;
|
|
97
|
+
allowedTools: Schema.Array$<typeof Schema.String>;
|
|
98
|
+
allowedSkills: Schema.Array$<typeof Schema.String>;
|
|
99
|
+
}>>;
|
|
100
|
+
}>;
|
|
101
|
+
manifestHash: typeof Schema.String;
|
|
102
|
+
}>;
|
|
103
|
+
export type CompileManifestAgent = typeof CompileManifestAgentSchema.Type;
|
|
104
|
+
export declare const CompileManifestSchema: Schema.Struct<{
|
|
105
|
+
version: Schema.Literal<[1]>;
|
|
106
|
+
plugins: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
107
|
+
version: Schema.optional<typeof Schema.String>;
|
|
108
|
+
sourceHash: typeof Schema.String;
|
|
109
|
+
}>>;
|
|
110
|
+
compileTargets: Schema.Array$<Schema.Struct<{
|
|
111
|
+
harness: Schema.Literal<["amp-code", "antigravity-cli", "claude-code", "codex-cli", "cursor", "factory-droid", "grok", "hermes", "kimi-code", "opencode", "pi"]>;
|
|
112
|
+
scope: Schema.Literal<["global", "project"]>;
|
|
113
|
+
}>>;
|
|
114
|
+
agents: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
115
|
+
name: typeof Schema.String;
|
|
116
|
+
plugin: typeof Schema.String;
|
|
117
|
+
description: typeof Schema.String;
|
|
118
|
+
sourceHash: typeof Schema.String;
|
|
119
|
+
traits: Schema.Array$<Schema.Struct<{
|
|
120
|
+
id: typeof Schema.String;
|
|
121
|
+
ref: typeof Schema.String;
|
|
122
|
+
}>>;
|
|
123
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
124
|
+
composed: Schema.Struct<{
|
|
125
|
+
grants: Schema.Struct<{
|
|
126
|
+
tools: Schema.Array$<typeof Schema.String>;
|
|
127
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
128
|
+
}>;
|
|
129
|
+
modelBindings: Schema.Struct<{
|
|
130
|
+
modelspace: Schema.optional<typeof Schema.String>;
|
|
131
|
+
profile: Schema.optional<typeof Schema.String>;
|
|
132
|
+
}>;
|
|
133
|
+
perTarget: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
134
|
+
scope: Schema.Literal<["global", "project"]>;
|
|
135
|
+
model: Schema.NullOr<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
136
|
+
toolGrants: Schema.Array$<typeof Schema.String>;
|
|
137
|
+
allowedTools: Schema.Array$<typeof Schema.String>;
|
|
138
|
+
allowedSkills: Schema.Array$<typeof Schema.String>;
|
|
139
|
+
}>>;
|
|
140
|
+
}>;
|
|
141
|
+
manifestHash: typeof Schema.String;
|
|
142
|
+
}>>;
|
|
143
|
+
modelspaces: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
144
|
+
plugin: typeof Schema.String;
|
|
145
|
+
modelspace: typeof Schema.String;
|
|
146
|
+
profiles: Schema.Array$<typeof Schema.String>;
|
|
147
|
+
profilesData: Schema.optional<Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>>>;
|
|
148
|
+
}>>;
|
|
149
|
+
skills: Schema.Record$<typeof Schema.String, Schema.Union<[Schema.Struct<{
|
|
150
|
+
plugin: typeof Schema.String;
|
|
151
|
+
name: typeof Schema.String;
|
|
152
|
+
}>, Schema.Struct<{
|
|
153
|
+
plugin: typeof Schema.String;
|
|
154
|
+
skillspace: typeof Schema.String;
|
|
155
|
+
skills: Schema.Array$<typeof Schema.String>;
|
|
156
|
+
}>]>>;
|
|
157
|
+
tools: Schema.Record$<typeof Schema.String, Schema.Union<[Schema.Struct<{
|
|
158
|
+
plugin: typeof Schema.String;
|
|
159
|
+
toolspace: typeof Schema.String;
|
|
160
|
+
name: typeof Schema.String;
|
|
161
|
+
}>, Schema.Struct<{
|
|
162
|
+
plugin: typeof Schema.String;
|
|
163
|
+
name: typeof Schema.String;
|
|
164
|
+
}>]>>;
|
|
165
|
+
traits: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
166
|
+
id: typeof Schema.String;
|
|
167
|
+
ref: typeof Schema.String;
|
|
168
|
+
}>>;
|
|
169
|
+
orbits: Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
170
|
+
plugin: typeof Schema.String;
|
|
171
|
+
name: typeof Schema.String;
|
|
172
|
+
}>>;
|
|
173
|
+
manifestHash: typeof Schema.String;
|
|
174
|
+
}>;
|
|
175
|
+
export type CompileManifest = typeof CompileManifestSchema.Type;
|
|
176
|
+
export interface UnsupportedCompileManifestVersion {
|
|
177
|
+
readonly _tag: "UnsupportedCompileManifestVersion";
|
|
178
|
+
readonly version: unknown;
|
|
179
|
+
readonly message: string;
|
|
180
|
+
}
|
|
181
|
+
export declare const unsupportedCompileManifestVersion: (version: unknown) => UnsupportedCompileManifestVersion;
|
|
182
|
+
declare const decodeCompileManifestPayload: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions) => import("effect/Either").Either<{
|
|
183
|
+
readonly version: 1;
|
|
184
|
+
readonly tools: {
|
|
185
|
+
readonly [x: string]: {
|
|
186
|
+
readonly plugin: string;
|
|
187
|
+
readonly name: string;
|
|
188
|
+
} | {
|
|
189
|
+
readonly plugin: string;
|
|
190
|
+
readonly name: string;
|
|
191
|
+
readonly toolspace: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
readonly skills: {
|
|
195
|
+
readonly [x: string]: {
|
|
196
|
+
readonly plugin: string;
|
|
197
|
+
readonly name: string;
|
|
198
|
+
} | {
|
|
199
|
+
readonly plugin: string;
|
|
200
|
+
readonly skills: readonly string[];
|
|
201
|
+
readonly skillspace: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
readonly traits: {
|
|
205
|
+
readonly [x: string]: {
|
|
206
|
+
readonly id: string;
|
|
207
|
+
readonly ref: string;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
readonly manifestHash: string;
|
|
211
|
+
readonly plugins: {
|
|
212
|
+
readonly [x: string]: {
|
|
213
|
+
readonly version?: string | undefined;
|
|
214
|
+
readonly sourceHash: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
readonly compileTargets: readonly {
|
|
218
|
+
readonly harness: "amp-code" | "antigravity-cli" | "claude-code" | "codex-cli" | "cursor" | "factory-droid" | "grok" | "hermes" | "kimi-code" | "opencode" | "pi";
|
|
219
|
+
readonly scope: "global" | "project";
|
|
220
|
+
}[];
|
|
221
|
+
readonly agents: {
|
|
222
|
+
readonly [x: string]: {
|
|
223
|
+
readonly sourceHash: string;
|
|
224
|
+
readonly plugin: string;
|
|
225
|
+
readonly name: string;
|
|
226
|
+
readonly skills: readonly string[];
|
|
227
|
+
readonly description: string;
|
|
228
|
+
readonly traits: readonly {
|
|
229
|
+
readonly id: string;
|
|
230
|
+
readonly ref: string;
|
|
231
|
+
}[];
|
|
232
|
+
readonly composed: {
|
|
233
|
+
readonly grants: {
|
|
234
|
+
readonly tools: readonly string[];
|
|
235
|
+
readonly skills: readonly string[];
|
|
236
|
+
};
|
|
237
|
+
readonly modelBindings: {
|
|
238
|
+
readonly modelspace?: string | undefined;
|
|
239
|
+
readonly profile?: string | undefined;
|
|
240
|
+
};
|
|
241
|
+
readonly perTarget: {
|
|
242
|
+
readonly [x: string]: {
|
|
243
|
+
readonly scope: "global" | "project";
|
|
244
|
+
readonly model: {
|
|
245
|
+
readonly [x: string]: unknown;
|
|
246
|
+
} | null;
|
|
247
|
+
readonly toolGrants: readonly string[];
|
|
248
|
+
readonly allowedTools: readonly string[];
|
|
249
|
+
readonly allowedSkills: readonly string[];
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
readonly manifestHash: string;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
readonly modelspaces: {
|
|
257
|
+
readonly [x: string]: {
|
|
258
|
+
readonly plugin: string;
|
|
259
|
+
readonly modelspace: string;
|
|
260
|
+
readonly profiles: readonly string[];
|
|
261
|
+
readonly profilesData?: {
|
|
262
|
+
readonly [x: string]: {
|
|
263
|
+
readonly [x: string]: {
|
|
264
|
+
readonly [x: string]: unknown;
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
} | undefined;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
readonly orbits: {
|
|
271
|
+
readonly [x: string]: {
|
|
272
|
+
readonly plugin: string;
|
|
273
|
+
readonly name: string;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
}, import("effect/ParseResult").ParseError>;
|
|
277
|
+
export type CompileManifestDecodeResult = ReturnType<typeof decodeCompileManifestPayload>;
|
|
278
|
+
export declare const decodeCompileManifest: (json: string) => CompileManifestDecodeResult | UnsupportedCompileManifestVersion;
|
|
279
|
+
export declare const normalizeCompileManifestForEncoding: (manifest: CompileManifest) => CompileManifest;
|
|
280
|
+
export declare const encodeCompileManifest: (manifest: CompileManifest) => string;
|
|
281
|
+
export declare const agentManifestHashInput: (agent: CompileManifestAgent) => Omit<CompileManifestAgent, "manifestHash">;
|
|
282
|
+
export declare const computeAgentManifestHash: (agent: CompileManifestAgent) => string;
|
|
283
|
+
export declare const manifestHashInput: (manifest: CompileManifest) => Omit<CompileManifest, "manifestHash">;
|
|
284
|
+
export declare const computeCompileManifestHash: (manifest: CompileManifest) => string;
|
|
285
|
+
export declare const verifyAgentManifestHash: (agent: CompileManifestAgent) => boolean;
|
|
286
|
+
export declare const verifyCompileManifestHash: (manifest: CompileManifest) => boolean;
|
|
287
|
+
export declare const getCompileManifestAgent: (manifest: CompileManifest, id: string) => CompileManifestAgent | undefined;
|
|
288
|
+
export declare const getCompileManifestAgentForTarget: (manifest: CompileManifest, id: string, harness: HarnessId) => {
|
|
289
|
+
readonly agent: CompileManifestAgent;
|
|
290
|
+
readonly target: CompileManifestPerTarget;
|
|
291
|
+
} | undefined;
|
|
292
|
+
export declare const emptyCompileManifest: () => CompileManifest;
|
|
293
|
+
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { compareCodePoint, sortStableStrings, stableJsonHash, stableJsonValue, } from "./stable-json.js";
|
|
3
|
+
export const COMPILE_MANIFEST_VERSION = 1;
|
|
4
|
+
export const HarnessScopeSchema = Schema.Literal("global", "project");
|
|
5
|
+
export const HarnessIdSchema = Schema.Literal("amp-code", "antigravity-cli", "claude-code", "codex-cli", "cursor", "factory-droid", "grok", "hermes", "kimi-code", "opencode", "pi");
|
|
6
|
+
export const CompileManifestPluginSchema = Schema.Struct({
|
|
7
|
+
version: Schema.optional(Schema.String),
|
|
8
|
+
sourceHash: Schema.String,
|
|
9
|
+
});
|
|
10
|
+
export const CompileManifestTargetSchema = Schema.Struct({
|
|
11
|
+
harness: HarnessIdSchema,
|
|
12
|
+
scope: HarnessScopeSchema,
|
|
13
|
+
});
|
|
14
|
+
export const CompileManifestTraitSchema = Schema.Struct({
|
|
15
|
+
id: Schema.String,
|
|
16
|
+
ref: Schema.String,
|
|
17
|
+
});
|
|
18
|
+
export const CompileManifestOrbitSchema = Schema.Struct({
|
|
19
|
+
plugin: Schema.String,
|
|
20
|
+
name: Schema.String,
|
|
21
|
+
});
|
|
22
|
+
export const CompileManifestCanonicalToolSchema = Schema.Struct({
|
|
23
|
+
plugin: Schema.String,
|
|
24
|
+
name: Schema.String,
|
|
25
|
+
});
|
|
26
|
+
export const CompileManifestToolspaceToolSchema = Schema.Struct({
|
|
27
|
+
plugin: Schema.String,
|
|
28
|
+
toolspace: Schema.String,
|
|
29
|
+
name: Schema.String,
|
|
30
|
+
});
|
|
31
|
+
export const CompileManifestGrantsSchema = Schema.Struct({
|
|
32
|
+
tools: Schema.Array(Schema.String),
|
|
33
|
+
skills: Schema.Array(Schema.String),
|
|
34
|
+
});
|
|
35
|
+
export const CompileManifestModelBindingsSchema = Schema.Struct({
|
|
36
|
+
modelspace: Schema.optional(Schema.String),
|
|
37
|
+
profile: Schema.optional(Schema.String),
|
|
38
|
+
});
|
|
39
|
+
export const CompileManifestModelspaceSchema = Schema.Struct({
|
|
40
|
+
plugin: Schema.String,
|
|
41
|
+
modelspace: Schema.String,
|
|
42
|
+
profiles: Schema.Array(Schema.String),
|
|
43
|
+
profilesData: Schema.optional(Schema.Record({
|
|
44
|
+
key: Schema.String,
|
|
45
|
+
value: Schema.Record({
|
|
46
|
+
key: Schema.String,
|
|
47
|
+
value: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
|
|
48
|
+
}),
|
|
49
|
+
})),
|
|
50
|
+
});
|
|
51
|
+
export const CompileManifestManagedSkillSchema = Schema.Struct({
|
|
52
|
+
plugin: Schema.String,
|
|
53
|
+
name: Schema.String,
|
|
54
|
+
});
|
|
55
|
+
export const CompileManifestSkillspaceSchema = Schema.Struct({
|
|
56
|
+
plugin: Schema.String,
|
|
57
|
+
skillspace: Schema.String,
|
|
58
|
+
skills: Schema.Array(Schema.String),
|
|
59
|
+
});
|
|
60
|
+
const JsonRecordSchema = Schema.Record({ key: Schema.String, value: Schema.Unknown });
|
|
61
|
+
export const CompileManifestPerTargetSchema = Schema.Struct({
|
|
62
|
+
scope: HarnessScopeSchema,
|
|
63
|
+
model: Schema.NullOr(JsonRecordSchema),
|
|
64
|
+
toolGrants: Schema.Array(Schema.String),
|
|
65
|
+
allowedTools: Schema.Array(Schema.String),
|
|
66
|
+
allowedSkills: Schema.Array(Schema.String),
|
|
67
|
+
});
|
|
68
|
+
export const CompileManifestAgentSchema = Schema.Struct({
|
|
69
|
+
name: Schema.String,
|
|
70
|
+
plugin: Schema.String,
|
|
71
|
+
description: Schema.String,
|
|
72
|
+
sourceHash: Schema.String,
|
|
73
|
+
traits: Schema.Array(CompileManifestTraitSchema),
|
|
74
|
+
skills: Schema.Array(Schema.String),
|
|
75
|
+
composed: Schema.Struct({
|
|
76
|
+
grants: CompileManifestGrantsSchema,
|
|
77
|
+
modelBindings: CompileManifestModelBindingsSchema,
|
|
78
|
+
perTarget: Schema.Record({ key: Schema.String, value: CompileManifestPerTargetSchema }),
|
|
79
|
+
}),
|
|
80
|
+
manifestHash: Schema.String,
|
|
81
|
+
});
|
|
82
|
+
const CompileManifestV1Schema = Schema.Struct({
|
|
83
|
+
version: Schema.Literal(COMPILE_MANIFEST_VERSION),
|
|
84
|
+
plugins: Schema.Record({ key: Schema.String, value: CompileManifestPluginSchema }),
|
|
85
|
+
compileTargets: Schema.Array(CompileManifestTargetSchema),
|
|
86
|
+
agents: Schema.Record({ key: Schema.String, value: CompileManifestAgentSchema }),
|
|
87
|
+
modelspaces: Schema.Record({ key: Schema.String, value: CompileManifestModelspaceSchema }),
|
|
88
|
+
skills: Schema.Record({ key: Schema.String, value: Schema.Union(CompileManifestManagedSkillSchema, CompileManifestSkillspaceSchema) }),
|
|
89
|
+
tools: Schema.Record({ key: Schema.String, value: Schema.Union(CompileManifestToolspaceToolSchema, CompileManifestCanonicalToolSchema) }),
|
|
90
|
+
traits: Schema.Record({ key: Schema.String, value: CompileManifestTraitSchema }),
|
|
91
|
+
orbits: Schema.Record({ key: Schema.String, value: CompileManifestOrbitSchema }),
|
|
92
|
+
manifestHash: Schema.String,
|
|
93
|
+
});
|
|
94
|
+
export const CompileManifestSchema = CompileManifestV1Schema;
|
|
95
|
+
export const unsupportedCompileManifestVersion = (version) => ({
|
|
96
|
+
_tag: "UnsupportedCompileManifestVersion",
|
|
97
|
+
version,
|
|
98
|
+
message: `Unsupported compile manifest version: ${String(version)}. Expected ${COMPILE_MANIFEST_VERSION}.`,
|
|
99
|
+
});
|
|
100
|
+
const decodeJson = (json) => JSON.parse(json);
|
|
101
|
+
const versionFromJson = (json) => {
|
|
102
|
+
const parsed = decodeJson(json);
|
|
103
|
+
return parsed && typeof parsed === "object" && "version" in parsed
|
|
104
|
+
? parsed.version
|
|
105
|
+
: undefined;
|
|
106
|
+
};
|
|
107
|
+
const decodeCompileManifestPayload = Schema.decodeUnknownEither(Schema.parseJson(CompileManifestSchema));
|
|
108
|
+
export const decodeCompileManifest = (json) => {
|
|
109
|
+
let version;
|
|
110
|
+
try {
|
|
111
|
+
version = versionFromJson(json);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return decodeCompileManifestPayload(json);
|
|
115
|
+
}
|
|
116
|
+
if (version !== COMPILE_MANIFEST_VERSION) {
|
|
117
|
+
return unsupportedCompileManifestVersion(version);
|
|
118
|
+
}
|
|
119
|
+
return decodeCompileManifestPayload(json);
|
|
120
|
+
};
|
|
121
|
+
const sortRecord = (record, normalize) => Object.fromEntries(sortStableStrings(Object.keys(record)).map((key) => [key, normalize(record[key])]));
|
|
122
|
+
const sortStrings = (values) => sortStableStrings(values);
|
|
123
|
+
const sortTargets = (targets) => [...targets].sort((left, right) => left.harness === right.harness
|
|
124
|
+
? (left.scope === right.scope ? 0 : left.scope < right.scope ? -1 : 1)
|
|
125
|
+
: left.harness < right.harness ? -1 : 1);
|
|
126
|
+
const sortTraits = (traits) => [...traits].sort((left, right) => left.id === right.id
|
|
127
|
+
? (left.ref === right.ref ? 0 : left.ref < right.ref ? -1 : 1)
|
|
128
|
+
: left.id < right.id ? -1 : 1);
|
|
129
|
+
const sortOrbits = (orbits) => [...orbits].sort((left, right) => left.plugin === right.plugin
|
|
130
|
+
? compareCodePoint(left.name, right.name)
|
|
131
|
+
: compareCodePoint(left.plugin, right.plugin));
|
|
132
|
+
const sortTools = (tools) => [...tools].sort((left, right) => left.plugin === right.plugin
|
|
133
|
+
? ("toolspace" in left && left.toolspace !== undefined
|
|
134
|
+
? ("toolspace" in right && right.toolspace !== undefined
|
|
135
|
+
? (left.toolspace === right.toolspace
|
|
136
|
+
? compareCodePoint(left.name, right.name)
|
|
137
|
+
: compareCodePoint(left.toolspace, right.toolspace))
|
|
138
|
+
: -1)
|
|
139
|
+
: ("toolspace" in right && right.toolspace !== undefined
|
|
140
|
+
? 1
|
|
141
|
+
: compareCodePoint(left.name, right.name)))
|
|
142
|
+
: compareCodePoint(left.plugin, right.plugin));
|
|
143
|
+
const normalizeAgentForEncoding = (agent) => ({
|
|
144
|
+
...agent,
|
|
145
|
+
traits: sortTraits(agent.traits),
|
|
146
|
+
skills: sortStrings(agent.skills),
|
|
147
|
+
composed: {
|
|
148
|
+
grants: {
|
|
149
|
+
tools: sortStrings(agent.composed.grants.tools),
|
|
150
|
+
skills: sortStrings(agent.composed.grants.skills),
|
|
151
|
+
},
|
|
152
|
+
modelBindings: stableJsonValue(agent.composed.modelBindings),
|
|
153
|
+
perTarget: sortRecord(agent.composed.perTarget, (slice) => ({
|
|
154
|
+
...slice,
|
|
155
|
+
model: slice.model === null ? null : stableJsonValue(slice.model),
|
|
156
|
+
toolGrants: sortStrings(slice.toolGrants),
|
|
157
|
+
allowedTools: sortStrings(slice.allowedTools),
|
|
158
|
+
allowedSkills: sortStrings(slice.allowedSkills),
|
|
159
|
+
})),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
export const normalizeCompileManifestForEncoding = (manifest) => ({
|
|
163
|
+
version: COMPILE_MANIFEST_VERSION,
|
|
164
|
+
plugins: sortRecord(manifest.plugins, (plugin) => plugin),
|
|
165
|
+
compileTargets: sortTargets(manifest.compileTargets),
|
|
166
|
+
agents: sortRecord(manifest.agents, normalizeAgentForEncoding),
|
|
167
|
+
modelspaces: sortRecord(manifest.modelspaces, (entry) => ({
|
|
168
|
+
plugin: entry.plugin,
|
|
169
|
+
modelspace: entry.modelspace,
|
|
170
|
+
profiles: sortStrings(entry.profiles),
|
|
171
|
+
profilesData: entry.profilesData
|
|
172
|
+
? sortRecord(entry.profilesData, (profileMap) => sortRecord(profileMap, (targetBlock) => stableJsonValue(targetBlock)))
|
|
173
|
+
: undefined,
|
|
174
|
+
})),
|
|
175
|
+
skills: sortRecord(manifest.skills, (entry) => "skillspace" in entry && entry.skillspace !== undefined
|
|
176
|
+
? {
|
|
177
|
+
plugin: entry.plugin,
|
|
178
|
+
skillspace: entry.skillspace,
|
|
179
|
+
skills: sortStrings(entry.skills),
|
|
180
|
+
}
|
|
181
|
+
: {
|
|
182
|
+
plugin: entry.plugin,
|
|
183
|
+
name: entry.name,
|
|
184
|
+
}),
|
|
185
|
+
tools: sortRecord(manifest.tools, (entry) => "toolspace" in entry && entry.toolspace !== undefined
|
|
186
|
+
? {
|
|
187
|
+
plugin: entry.plugin,
|
|
188
|
+
toolspace: entry.toolspace,
|
|
189
|
+
name: entry.name,
|
|
190
|
+
}
|
|
191
|
+
: {
|
|
192
|
+
plugin: entry.plugin,
|
|
193
|
+
name: entry.name,
|
|
194
|
+
}),
|
|
195
|
+
traits: sortRecord(manifest.traits, (trait) => trait),
|
|
196
|
+
orbits: sortRecord(manifest.orbits, (entry) => entry),
|
|
197
|
+
manifestHash: manifest.manifestHash,
|
|
198
|
+
});
|
|
199
|
+
export const encodeCompileManifest = (manifest) => `${JSON.stringify(normalizeCompileManifestForEncoding(manifest), null, 2)}\n`;
|
|
200
|
+
export const agentManifestHashInput = (agent) => {
|
|
201
|
+
const { manifestHash: _manifestHash, ...rest } = normalizeAgentForEncoding(agent);
|
|
202
|
+
return rest;
|
|
203
|
+
};
|
|
204
|
+
export const computeAgentManifestHash = (agent) => stableJsonHash(agentManifestHashInput(agent));
|
|
205
|
+
export const manifestHashInput = (manifest) => {
|
|
206
|
+
const { manifestHash: _manifestHash, ...rest } = normalizeCompileManifestForEncoding(manifest);
|
|
207
|
+
return rest;
|
|
208
|
+
};
|
|
209
|
+
export const computeCompileManifestHash = (manifest) => stableJsonHash(manifestHashInput(manifest));
|
|
210
|
+
export const verifyAgentManifestHash = (agent) => computeAgentManifestHash(agent) === agent.manifestHash;
|
|
211
|
+
export const verifyCompileManifestHash = (manifest) => computeCompileManifestHash(manifest) === manifest.manifestHash;
|
|
212
|
+
export const getCompileManifestAgent = (manifest, id) => manifest.agents[id];
|
|
213
|
+
export const getCompileManifestAgentForTarget = (manifest, id, harness) => {
|
|
214
|
+
const agent = getCompileManifestAgent(manifest, id);
|
|
215
|
+
const target = agent?.composed.perTarget[harness];
|
|
216
|
+
return agent && target ? { agent, target } : undefined;
|
|
217
|
+
};
|
|
218
|
+
export const emptyCompileManifest = () => {
|
|
219
|
+
const manifest = {
|
|
220
|
+
version: COMPILE_MANIFEST_VERSION,
|
|
221
|
+
plugins: {},
|
|
222
|
+
compileTargets: [],
|
|
223
|
+
agents: {},
|
|
224
|
+
modelspaces: {},
|
|
225
|
+
skills: {},
|
|
226
|
+
tools: {},
|
|
227
|
+
traits: {},
|
|
228
|
+
orbits: {},
|
|
229
|
+
manifestHash: "",
|
|
230
|
+
};
|
|
231
|
+
return { ...manifest, manifestHash: computeCompileManifestHash(manifest) };
|
|
232
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve-or-spawn: given a plugin name, produce a *live* daemon registry
|
|
3
|
+
* entry to connect to -- spawning a fresh daemon when the registry has no
|
|
4
|
+
* entry, the recorded entry is dead, or the recorded entry's bundle hash no
|
|
5
|
+
* longer matches the compiled bundle on disk (a `prism refresh` ran since
|
|
6
|
+
* that daemon started).
|
|
7
|
+
*
|
|
8
|
+
* Builds entirely on the wave-0 substrate rather than re-implementing any of
|
|
9
|
+
* it:
|
|
10
|
+
* - `getDaemon` / the per-plugin registry file (`uds-registry.ts`).
|
|
11
|
+
* - `udsPathFor`, the content-addressed socket path (`uds-path.ts`) --
|
|
12
|
+
* a different bundle hash always yields a different socket path, so a
|
|
13
|
+
* stale daemon (old hash) and a fresh one (new hash) never collide on the
|
|
14
|
+
* same file.
|
|
15
|
+
* - `probeSocketLiveness` (`uds-singleton.ts`).
|
|
16
|
+
*
|
|
17
|
+
* This module deliberately never binds a socket or acquires the bind lock
|
|
18
|
+
* itself. Every compiled bundle's own runtime already calls
|
|
19
|
+
* `bindUnixSocketSingleton` on startup (see `src/compile/mcp-bundle.ts`'s
|
|
20
|
+
* `MCP_SDK_HTTP_RUNTIME`), and *that* is what guarantees exactly one winner
|
|
21
|
+
* when N callers race to spawn the same plugin: this module just spawns
|
|
22
|
+
* (possibly redundantly) and waits for a live registry entry to show up.
|
|
23
|
+
* Losing spawns detect "already-served" inside their own bundle and
|
|
24
|
+
* `process.exit(0)` before ever registering.
|
|
25
|
+
*/
|
|
26
|
+
import { type RegistryEntry, type RegistryResult } from "./uds-registry.js";
|
|
27
|
+
import { type ProbeResult } from "./uds-singleton.js";
|
|
28
|
+
export declare class DaemonResolveError extends Error {
|
|
29
|
+
readonly pluginName: string;
|
|
30
|
+
readonly cause?: unknown | undefined;
|
|
31
|
+
readonly kind: "daemon-resolve-error";
|
|
32
|
+
constructor(pluginName: string, message: string, cause?: unknown | undefined);
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_SPAWN_TIMEOUT_MS = 15000;
|
|
35
|
+
/**
|
|
36
|
+
* `<prismHome>/runtime/mcp/<plugin>` -- the per-plugin runtime directory
|
|
37
|
+
* that owns this plugin's registry file, socket file(s), and compiled
|
|
38
|
+
* bundle. Derived from `udsPathFor` (any hash value yields the same parent
|
|
39
|
+
* directory) rather than re-deriving the layout independently.
|
|
40
|
+
*
|
|
41
|
+
* `prismHome` is threaded explicitly (never read from the environment
|
|
42
|
+
* here): the CLI edge resolves `PRISM_HOME` once via `resolvePrismHome()`
|
|
43
|
+
* and passes the result down. An omitted value falls back to the same
|
|
44
|
+
* `~/.prism` default `resolvePrismHome()` uses when unset -- `prism-sdk`
|
|
45
|
+
* cannot import that resolver itself (no dependency on the root `src/`
|
|
46
|
+
* tree).
|
|
47
|
+
*/
|
|
48
|
+
export declare const pluginRuntimeDir: (plugin: string, prismHome?: string) => string;
|
|
49
|
+
/**
|
|
50
|
+
* `<prismHome>/runtime/mcp/<plugin>/server.mjs` -- the canonical compiled
|
|
51
|
+
* bundle a `prism refresh` run produces. This module only ever reads it; it
|
|
52
|
+
* never writes or rebuilds it.
|
|
53
|
+
*/
|
|
54
|
+
export declare const pluginBundlePath: (plugin: string, prismHome?: string) => string;
|
|
55
|
+
export type GetDaemonFn = (plugin: string) => Promise<RegistryResult<RegistryEntry>>;
|
|
56
|
+
export type ProbeSocketLivenessFn = (socketPath: string) => Promise<ProbeResult>;
|
|
57
|
+
export type HashBundleFn = (bundlePath: string) => Promise<string>;
|
|
58
|
+
export type UdsPathForFn = (plugin: string, bundleHash: string) => string;
|
|
59
|
+
export interface SpawnDaemonOptions {
|
|
60
|
+
readonly plugin: string;
|
|
61
|
+
readonly bundlePath: string;
|
|
62
|
+
readonly udsPath: string;
|
|
63
|
+
readonly bundleHash: string;
|
|
64
|
+
}
|
|
65
|
+
export type SpawnDaemonFn = (options: SpawnDaemonOptions) => void;
|
|
66
|
+
export interface ResolveOrSpawnOptions {
|
|
67
|
+
readonly plugin: string;
|
|
68
|
+
/**
|
|
69
|
+
* Prism home directory, threaded from the CLI edge (`resolvePrismHome()`).
|
|
70
|
+
* Only consulted to build the *default* `bundlePathFor`/`udsPathFor`; a
|
|
71
|
+
* caller that supplies either override directly takes over that
|
|
72
|
+
* resolution entirely and this is ignored for that one.
|
|
73
|
+
*/
|
|
74
|
+
readonly prismHome?: string;
|
|
75
|
+
readonly spawnTimeoutMs?: number;
|
|
76
|
+
readonly pollIntervalMs?: number;
|
|
77
|
+
readonly getDaemon?: GetDaemonFn;
|
|
78
|
+
readonly probeSocketLiveness?: ProbeSocketLivenessFn;
|
|
79
|
+
readonly bundlePathFor?: (plugin: string) => string;
|
|
80
|
+
readonly udsPathFor?: UdsPathForFn;
|
|
81
|
+
readonly hashBundle?: HashBundleFn;
|
|
82
|
+
readonly spawnDaemon?: SpawnDaemonFn;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the live registry entry to connect to for `plugin`:
|
|
86
|
+
*
|
|
87
|
+
* registry entry present -> liveness probe
|
|
88
|
+
* live & bundle hash matches on-disk bundle -> use it
|
|
89
|
+
* dead, OR bundle hash stale -> spawn fresh
|
|
90
|
+
* registry entry absent -> spawn fresh
|
|
91
|
+
*
|
|
92
|
+
* "Spawn fresh" computes the bundle's current content hash, derives its
|
|
93
|
+
* content-addressed socket path via `udsPathFor`, launches the daemon, and
|
|
94
|
+
* polls the registry + a liveness probe until a live entry at that exact
|
|
95
|
+
* socket path appears or `spawnTimeoutMs` elapses.
|
|
96
|
+
*
|
|
97
|
+
* Throws `DaemonResolveError` when the bundle cannot be read (nothing to
|
|
98
|
+
* spawn) or the spawned daemon never becomes live in time.
|
|
99
|
+
*/
|
|
100
|
+
export declare const resolveOrSpawnDaemon: (options: ResolveOrSpawnOptions) => Promise<RegistryEntry>;
|