pico-engine 1.6.4 → 1.8.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/README.md +13 -8
- package/dist/RulesetRegistryLoaderFs.js +14 -2
- package/dist/auth/cookies.js +32 -0
- package/dist/auth/index.js +6 -1
- package/dist/channelIdentityPolicy.js +22 -0
- package/dist/cli.js +104 -69
- package/dist/engineConfig.js +280 -0
- package/dist/identity/IdentityService.js +90 -0
- package/dist/identity/crossPico.js +24 -8
- package/dist/identity/didoModule.js +80 -18
- package/dist/identity/establishSubscription.js +2 -2
- package/dist/identity/identityPortable.js +92 -0
- package/dist/identity/index.js +10 -1
- package/dist/identity/localPeerReconcile.js +65 -0
- package/dist/identity/peerDid4.js +175 -0
- package/dist/identity/peerDid4Create.js +90 -0
- package/dist/identity/portableExportPrepare.js +196 -0
- package/dist/identity/portableMove.js +87 -0
- package/dist/identity/skyIntro.js +6 -3
- package/dist/identity/skyProtocol.js +26 -1
- package/dist/identity/skyRotation.js +121 -0
- package/dist/identity/store.js +5 -1
- package/dist/identity/subscriptionEntSync.js +72 -0
- package/dist/identity/veramoDidComm.js +41 -2
- package/dist/identity/webvh.js +4 -2
- package/dist/identity/webvhRelocation.js +115 -0
- package/dist/index.js +82 -22
- package/dist/logging.js +8 -12
- package/dist/oauth/OAuthService.js +6 -2
- package/dist/policyConfigFromJson.js +112 -0
- package/dist/runMcp.js +27 -0
- package/dist/server.js +56 -24
- package/dist/subtreeWrangler.js +180 -0
- package/dist/uiChannelPolicies.js +15 -0
- package/krl/io.picolabs.oauth.krl +41 -2
- package/krl/io.picolabs.pds.krl +131 -10
- package/krl/io.picolabs.pico-engine-ui.krl +209 -21
- package/krl/io.picolabs.portable_subtree.krl +97 -0
- package/krl/io.picolabs.subscription.krl +180 -72
- package/krl/io.picolabs.wrangler.krl +296 -57
- package/mcp/devResources.js +118 -0
- package/mcp/devTools.js +351 -0
- package/mcp/engineClient.js +133 -0
- package/mcp/meshHttp.js +137 -0
- package/mcp/meshTools.js +189 -0
- package/mcp/runStdio.js +34 -0
- package/mcp/schemaToZod.js +56 -0
- package/package.json +20 -8
- package/public/docs/_sidebar.md +2 -1
- package/public/docs/llms-full.txt +479 -0
- package/public/docs/llms.txt +37 -0
- package/public/docs/openapi.yaml +78 -0
- package/public/docs/pico-engine.md +235 -4
- package/public/docs/pico-overview.md +117 -0
- package/public/docs/pico.md +3 -1
- package/public/docs/rulesets/README.md +25 -0
- package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
- package/public/docs/rulesets/io.picolabs.pds.md +327 -0
- package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
- package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
- package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
- package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +28 -26
- package/src/RulesetRegistryLoaderFs.ts +18 -3
- package/src/auth/cookies.ts +34 -0
- package/src/auth/index.ts +7 -0
- package/src/channelIdentityPolicy.ts +29 -0
- package/src/cli.ts +68 -37
- package/src/engineConfig.ts +345 -0
- package/src/identity/IdentityService.ts +189 -1
- package/src/identity/crossPico.ts +57 -8
- package/src/identity/didoModule.ts +140 -23
- package/src/identity/establishSubscription.ts +2 -2
- package/src/identity/identityPortable.ts +153 -0
- package/src/identity/index.ts +14 -0
- package/src/identity/localPeerReconcile.ts +97 -0
- package/src/identity/peerDid4.ts +197 -0
- package/src/identity/peerDid4Create.ts +121 -0
- package/src/identity/portableExportPrepare.ts +302 -0
- package/src/identity/portableMove.ts +193 -0
- package/src/identity/skyIntro.ts +11 -11
- package/src/identity/skyProtocol.ts +46 -0
- package/src/identity/skyRotation.ts +211 -0
- package/src/identity/store.ts +5 -1
- package/src/identity/subscriptionEntSync.ts +97 -0
- package/src/identity/veramoDidComm.ts +52 -2
- package/src/identity/webvh.ts +4 -4
- package/src/identity/webvhRelocation.ts +167 -0
- package/src/index.ts +119 -25
- package/src/logging.ts +8 -14
- package/src/oauth/OAuthService.ts +11 -3
- package/src/policyConfigFromJson.ts +131 -0
- package/src/runMcp.ts +30 -0
- package/src/server.ts +79 -26
- package/src/subtreeWrangler.ts +278 -0
- package/src/uiChannelPolicies.ts +15 -0
- package/krl/io.picolabs.did-o.krl +0 -349
package/src/index.ts
CHANGED
|
@@ -4,9 +4,20 @@ import * as makeDir from "make-dir";
|
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import type { Server } from "http";
|
|
6
6
|
import { PicoEngineCore, RulesetRegistry } from "pico-engine-core";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
EventPolicyRule,
|
|
9
|
+
PicoDbKey,
|
|
10
|
+
PicoFramework,
|
|
11
|
+
PolicyCeiling,
|
|
12
|
+
QueryPolicyRule,
|
|
13
|
+
} from "pico-framework";
|
|
8
14
|
import { AuthService, WebAuthnAdapter, makeWebAuthnAdapter } from "./auth";
|
|
9
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
IdentityStore,
|
|
17
|
+
IdentityService,
|
|
18
|
+
initDidoModule,
|
|
19
|
+
createSubtreePortableHooks,
|
|
20
|
+
} from "./identity";
|
|
10
21
|
import { registerWebvhRoutes } from "./identity/webvhRoutes";
|
|
11
22
|
import { OAuthService, initOAuthModule } from "./oauth";
|
|
12
23
|
import {
|
|
@@ -17,11 +28,16 @@ import {
|
|
|
17
28
|
import { openClassicLevelWithRecovery } from "./levelDb";
|
|
18
29
|
import { provisionRoot, uiECIForRoot } from "./provisionRoot";
|
|
19
30
|
import { createRulesetRegistryLoaderFs } from "./RulesetRegistryLoaderFs";
|
|
31
|
+
import { resolveBundledKrlUrl } from "./bundledKrl";
|
|
32
|
+
import { wranglerSubtreeImportServices } from "./subtreeWrangler";
|
|
20
33
|
import { server } from "./server";
|
|
34
|
+
import {
|
|
35
|
+
installEngineRuntimeSettings,
|
|
36
|
+
resolveEngineSettings,
|
|
37
|
+
} from "./engineConfig";
|
|
21
38
|
const charwise = require("charwise");
|
|
22
39
|
const safeJsonCodec = require("level-json-coerce-null");
|
|
23
40
|
|
|
24
|
-
const homeDir = require("home-dir");
|
|
25
41
|
const version = require("../package.json").version;
|
|
26
42
|
|
|
27
43
|
/**
|
|
@@ -99,6 +115,15 @@ export interface PicoEngineConfiguration {
|
|
|
99
115
|
* Tests may set this to true.
|
|
100
116
|
*/
|
|
101
117
|
autoCreateRootPico?: boolean;
|
|
118
|
+
|
|
119
|
+
/** Default max channel policy for root picos (1.8 policy ceiling). */
|
|
120
|
+
defaultRootPolicyCeiling?: PolicyCeiling;
|
|
121
|
+
|
|
122
|
+
/** Engine-wide event denies on every channel ECI (1.8). */
|
|
123
|
+
globalEventDeny?: EventPolicyRule[];
|
|
124
|
+
|
|
125
|
+
/** Engine-wide query denies on every channel ECI (1.8). */
|
|
126
|
+
globalQueryDeny?: QueryPolicyRule[];
|
|
102
127
|
}
|
|
103
128
|
|
|
104
129
|
export interface PicoEngine {
|
|
@@ -109,6 +134,7 @@ export interface PicoEngine {
|
|
|
109
134
|
base_url: string;
|
|
110
135
|
|
|
111
136
|
pf: PicoFramework;
|
|
137
|
+
core: PicoEngineCore;
|
|
112
138
|
/** UI channel for the session root; null when no roots exist yet at boot. */
|
|
113
139
|
uiECI: string | null;
|
|
114
140
|
rsRegistry: RulesetRegistry;
|
|
@@ -121,24 +147,46 @@ export interface PicoEngine {
|
|
|
121
147
|
shutdown(): Promise<void>;
|
|
122
148
|
}
|
|
123
149
|
|
|
150
|
+
/** Integration harnesses (e.g. manifold-api Docker tests): boot with one root, no passkey. */
|
|
151
|
+
function autoCreateRootFromEnv(): boolean | undefined {
|
|
152
|
+
const v = process.env.PICO_ENGINE_AUTO_CREATE_ROOT;
|
|
153
|
+
if (typeof v !== "string" || v.trim().length === 0) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
const s = v.trim().toLowerCase();
|
|
157
|
+
if (s === "1" || s === "true" || s === "yes") {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (s === "0" || s === "false" || s === "no") {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
124
166
|
export async function startEngine(
|
|
125
167
|
configuration: PicoEngineConfiguration = {}
|
|
126
168
|
): Promise<PicoEngine> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
169
|
+
const settings = resolveEngineSettings({
|
|
170
|
+
home: configuration.home,
|
|
171
|
+
port: configuration.port,
|
|
172
|
+
base_url: configuration.base_url,
|
|
173
|
+
rpID: configuration.rpID,
|
|
174
|
+
rpName: configuration.rpName,
|
|
175
|
+
origin: configuration.origin,
|
|
176
|
+
allowSelfSignup: configuration.allowSelfSignup,
|
|
177
|
+
defaultRootPolicyCeiling: configuration.defaultRootPolicyCeiling,
|
|
178
|
+
globalEventDeny: configuration.globalEventDeny,
|
|
179
|
+
globalQueryDeny: configuration.globalQueryDeny,
|
|
180
|
+
});
|
|
181
|
+
installEngineRuntimeSettings(settings);
|
|
182
|
+
|
|
183
|
+
const home = settings.home;
|
|
184
|
+
let port = configuration.port ?? settings.port;
|
|
185
|
+
const baseUrlFromCaller = configuration.base_url;
|
|
186
|
+
/** Filled after listen when using port 0 or when config baseUrl port does not match. */
|
|
187
|
+
let base_url: string | undefined = baseUrlFromCaller;
|
|
188
|
+
if (base_url == null && port > 0) {
|
|
189
|
+
base_url = settings.baseUrl;
|
|
142
190
|
}
|
|
143
191
|
await makeDir(home);
|
|
144
192
|
|
|
@@ -163,7 +211,15 @@ export async function startEngine(
|
|
|
163
211
|
log,
|
|
164
212
|
modules: configuration.modules,
|
|
165
213
|
useEventInputTime: configuration.useEventInputTime,
|
|
166
|
-
autoCreateRootPico:
|
|
214
|
+
autoCreateRootPico:
|
|
215
|
+
configuration.autoCreateRootPico ??
|
|
216
|
+
autoCreateRootFromEnv() ??
|
|
217
|
+
false,
|
|
218
|
+
defaultRootPolicyCeiling:
|
|
219
|
+
configuration.defaultRootPolicyCeiling ??
|
|
220
|
+
settings.defaultRootPolicyCeiling,
|
|
221
|
+
globalEventDeny: configuration.globalEventDeny ?? settings.globalEventDeny,
|
|
222
|
+
globalQueryDeny: configuration.globalQueryDeny ?? settings.globalQueryDeny,
|
|
167
223
|
getPicoLogs(picoId) {
|
|
168
224
|
if (!logFilePath) {
|
|
169
225
|
return Promise.resolve([]);
|
|
@@ -172,18 +228,49 @@ export async function startEngine(
|
|
|
172
228
|
},
|
|
173
229
|
});
|
|
174
230
|
const pf = core.picoFramework;
|
|
231
|
+
core.resolveBundledRulesetUrl = resolveBundledKrlUrl;
|
|
232
|
+
core.subtreeImportServices = wranglerSubtreeImportServices(core.rsRegistry);
|
|
175
233
|
const identity = new IdentityStore({ db: pf.db });
|
|
176
234
|
let identityService!: IdentityService;
|
|
235
|
+
const onPicoCreated = async (
|
|
236
|
+
picoId: string,
|
|
237
|
+
ctx: { isRoot: boolean; parentPicoId: string }
|
|
238
|
+
) => {
|
|
239
|
+
if (core.base_url) {
|
|
240
|
+
await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
|
|
241
|
+
}
|
|
242
|
+
};
|
|
177
243
|
identityService = new IdentityService({
|
|
178
244
|
store: identity,
|
|
179
245
|
getBaseUrl: () => core.base_url || base_url || "",
|
|
180
246
|
pf,
|
|
247
|
+
rsRegistry: core.rsRegistry,
|
|
248
|
+
resolveBundledRulesetUrl: resolveBundledKrlUrl,
|
|
249
|
+
reloadImportedSchedules: (picoIds) => core.reloadImportedSchedules(picoIds),
|
|
250
|
+
firePicoImported: async (result) => {
|
|
251
|
+
const importedRoot = pf.getPico(result.newRootPicoId);
|
|
252
|
+
if (!importedRoot) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
await importedRoot.event({
|
|
256
|
+
eci: result.newRootEci,
|
|
257
|
+
domain: "wrangler",
|
|
258
|
+
name: "pico_imported",
|
|
259
|
+
data: {
|
|
260
|
+
attrs: {
|
|
261
|
+
oldRootPicoId: result.oldRootPicoId,
|
|
262
|
+
newRootPicoId: result.newRootPicoId,
|
|
263
|
+
eciMap: result.eciMap,
|
|
264
|
+
picoIdMap: result.picoIdMap,
|
|
265
|
+
portableIdentity: true,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
time: Date.now(),
|
|
269
|
+
});
|
|
270
|
+
},
|
|
181
271
|
});
|
|
182
|
-
core.onPicoCreated =
|
|
183
|
-
|
|
184
|
-
await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
|
|
185
|
-
}
|
|
186
|
-
};
|
|
272
|
+
core.onPicoCreated = onPicoCreated;
|
|
273
|
+
core.subtreePortableHooks = createSubtreePortableHooks(identity, pf);
|
|
187
274
|
core.modules["dido"] = initDidoModule(identityService);
|
|
188
275
|
|
|
189
276
|
try {
|
|
@@ -212,7 +299,8 @@ export async function startEngine(
|
|
|
212
299
|
rpID: configuration.rpID,
|
|
213
300
|
rpName: configuration.rpName,
|
|
214
301
|
origin: configuration.origin,
|
|
215
|
-
allowSelfSignup:
|
|
302
|
+
allowSelfSignup:
|
|
303
|
+
configuration.allowSelfSignup ?? settings.allowSelfSignup,
|
|
216
304
|
flushBootstrapUrl: async (url) => {
|
|
217
305
|
const flushed = await rsRegistry.flush(url);
|
|
218
306
|
return { rid: flushed.rid };
|
|
@@ -273,6 +361,11 @@ export async function startEngine(
|
|
|
273
361
|
});
|
|
274
362
|
if (typeof base_url !== "string") {
|
|
275
363
|
base_url = `http://localhost:${port}`;
|
|
364
|
+
} else if (
|
|
365
|
+
baseUrlFromCaller == null &&
|
|
366
|
+
(configuration.port === 0 || port !== settings.port)
|
|
367
|
+
) {
|
|
368
|
+
base_url = `http://localhost:${port}`;
|
|
276
369
|
}
|
|
277
370
|
core.base_url = base_url;
|
|
278
371
|
|
|
@@ -319,6 +412,7 @@ export async function startEngine(
|
|
|
319
412
|
base_url,
|
|
320
413
|
|
|
321
414
|
pf,
|
|
415
|
+
core,
|
|
322
416
|
uiECI,
|
|
323
417
|
rsRegistry,
|
|
324
418
|
auth,
|
package/src/logging.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as readline from "readline";
|
|
3
3
|
import { krlLogLevelCodeToHuman, PicoLogEntry } from "krl-stdlib";
|
|
4
4
|
import * as path from "path";
|
|
5
|
+
import { getEngineRuntimeSettings } from "./engineConfig";
|
|
5
6
|
|
|
6
7
|
const rfs = require("rotating-file-stream");
|
|
7
8
|
|
|
@@ -50,17 +51,12 @@ function getRotatingFileStream(filePath: string): NodeJS.WritableStream {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export function resolveEngineLogFilePath(home: string): string | null {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
configured === "0" ||
|
|
56
|
-
configured === "-" ||
|
|
57
|
-
configured === "stdout" ||
|
|
58
|
-
configured === ""
|
|
59
|
-
) {
|
|
54
|
+
const settings = getEngineRuntimeSettings();
|
|
55
|
+
if (settings.logToStdout) {
|
|
60
56
|
return null;
|
|
61
57
|
}
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
58
|
+
if (settings.logFile) {
|
|
59
|
+
return settings.logFile;
|
|
64
60
|
}
|
|
65
61
|
return path.resolve(home, "pico-engine.log");
|
|
66
62
|
}
|
|
@@ -111,21 +107,19 @@ export async function getPicoLogs(
|
|
|
111
107
|
});
|
|
112
108
|
|
|
113
109
|
for await (const line of rl) {
|
|
114
|
-
// Each line in the readline input will be successively available here as
|
|
115
|
-
// `line`.
|
|
116
110
|
if (line.indexOf(picoId) < 0) {
|
|
117
|
-
continue;
|
|
111
|
+
continue;
|
|
118
112
|
}
|
|
119
113
|
let entry;
|
|
120
114
|
try {
|
|
121
115
|
entry = JSON.parse(line);
|
|
122
116
|
} catch (err) {}
|
|
123
117
|
if (!entry || entry.picoId !== picoId) {
|
|
124
|
-
continue;
|
|
118
|
+
continue;
|
|
125
119
|
}
|
|
126
120
|
const time = new Date(entry.time);
|
|
127
121
|
if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
|
|
128
|
-
continue;
|
|
122
|
+
continue;
|
|
129
123
|
}
|
|
130
124
|
|
|
131
125
|
const out: PicoLogEntry = {
|
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
} from "./channelEligibility";
|
|
8
8
|
import { OAuthError } from "./errors";
|
|
9
9
|
import { isChannelUnderRoot, meshRequiresOAuth as meshRequiresOAuthForEci } from "./meshOAuth";
|
|
10
|
+
import {
|
|
11
|
+
channelHasUnrestrictedAllow,
|
|
12
|
+
isDidcommIngressChannel,
|
|
13
|
+
wildcardSkyRequireBearerEnabled,
|
|
14
|
+
} from "../channelIdentityPolicy";
|
|
10
15
|
|
|
11
16
|
const OAUTH_CHANNEL_PREFIX = "oauth-channel";
|
|
12
17
|
const OAUTH_TOKEN_PREFIX = "oauth-token";
|
|
@@ -237,11 +242,14 @@ export class OAuthService {
|
|
|
237
242
|
async skyRequiresBearer(eci: string): Promise<boolean> {
|
|
238
243
|
try {
|
|
239
244
|
const channel = this.lookupChannelReadOnly(eci);
|
|
245
|
+
if (isDidcommIngressChannel(channel)) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
240
248
|
if (
|
|
241
|
-
|
|
242
|
-
channel
|
|
249
|
+
wildcardSkyRequireBearerEnabled() &&
|
|
250
|
+
channelHasUnrestrictedAllow(channel)
|
|
243
251
|
) {
|
|
244
|
-
return
|
|
252
|
+
return true;
|
|
245
253
|
}
|
|
246
254
|
if (isOAuthEligibleChannel(channel)) {
|
|
247
255
|
return true;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventPolicy,
|
|
3
|
+
EventPolicyRule,
|
|
4
|
+
PolicyCeiling,
|
|
5
|
+
QueryPolicy,
|
|
6
|
+
QueryPolicyRule,
|
|
7
|
+
} from "pico-framework";
|
|
8
|
+
|
|
9
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
10
|
+
return v != null && typeof v === "object" && !Array.isArray(v);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function cleanEventPolicyFromJson(orig: unknown): EventPolicy {
|
|
14
|
+
if (
|
|
15
|
+
!isRecord(orig) ||
|
|
16
|
+
!Array.isArray(orig.allow) ||
|
|
17
|
+
!Array.isArray(orig.deny)
|
|
18
|
+
) {
|
|
19
|
+
throw new TypeError(
|
|
20
|
+
"eventPolicy expects { allow: EventPolicyRule[], deny: EventPolicyRule[] }",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const allow: EventPolicyRule[] = [];
|
|
24
|
+
for (const item of orig.allow) {
|
|
25
|
+
if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
|
|
26
|
+
throw new TypeError("eventPolicy allow entries need domain and name strings");
|
|
27
|
+
}
|
|
28
|
+
allow.push({ domain: item.domain.trim(), name: item.name.trim() });
|
|
29
|
+
}
|
|
30
|
+
const deny: EventPolicyRule[] = [];
|
|
31
|
+
for (const item of orig.deny) {
|
|
32
|
+
if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
|
|
33
|
+
throw new TypeError("eventPolicy deny entries need domain and name strings");
|
|
34
|
+
}
|
|
35
|
+
deny.push({ domain: item.domain.trim(), name: item.name.trim() });
|
|
36
|
+
}
|
|
37
|
+
return { allow, deny };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function cleanQueryPolicyFromJson(orig: unknown): QueryPolicy {
|
|
41
|
+
if (
|
|
42
|
+
!isRecord(orig) ||
|
|
43
|
+
!Array.isArray(orig.allow) ||
|
|
44
|
+
!Array.isArray(orig.deny)
|
|
45
|
+
) {
|
|
46
|
+
throw new TypeError(
|
|
47
|
+
"queryPolicy expects { allow: QueryPolicyRule[], deny: QueryPolicyRule[] }",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const allow: QueryPolicyRule[] = [];
|
|
51
|
+
for (const item of orig.allow) {
|
|
52
|
+
if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
|
|
53
|
+
throw new TypeError("queryPolicy allow entries need rid and name strings");
|
|
54
|
+
}
|
|
55
|
+
allow.push({ rid: item.rid.trim(), name: item.name.trim() });
|
|
56
|
+
}
|
|
57
|
+
const deny: QueryPolicyRule[] = [];
|
|
58
|
+
for (const item of orig.deny) {
|
|
59
|
+
if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
|
|
60
|
+
throw new TypeError("queryPolicy deny entries need rid and name strings");
|
|
61
|
+
}
|
|
62
|
+
deny.push({ rid: item.rid.trim(), name: item.name.trim() });
|
|
63
|
+
}
|
|
64
|
+
return { allow, deny };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseEventRule(v: unknown): EventPolicyRule | null {
|
|
68
|
+
if (!isRecord(v)) return null;
|
|
69
|
+
if (typeof v.domain !== "string" || typeof v.name !== "string") return null;
|
|
70
|
+
return { domain: v.domain, name: v.name };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function parseQueryRule(v: unknown): QueryPolicyRule | null {
|
|
74
|
+
if (!isRecord(v)) return null;
|
|
75
|
+
if (typeof v.rid !== "string" || typeof v.name !== "string") return null;
|
|
76
|
+
return { rid: v.rid, name: v.name };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function parsePolicyCeilingFromJson(
|
|
80
|
+
val: unknown,
|
|
81
|
+
fieldName: string,
|
|
82
|
+
): PolicyCeiling | undefined {
|
|
83
|
+
if (val === undefined || val === null) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (!isRecord(val) || !val.eventPolicy || !val.queryPolicy) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`${fieldName} must be { eventPolicy: { allow, deny }, queryPolicy: { allow, deny } }`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
eventPolicy: cleanEventPolicyFromJson(val.eventPolicy),
|
|
93
|
+
queryPolicy: cleanQueryPolicyFromJson(val.queryPolicy),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function parseGlobalEventDenyFromJson(val: unknown): EventPolicyRule[] | undefined {
|
|
98
|
+
if (val === undefined || val === null) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
if (!Array.isArray(val)) {
|
|
102
|
+
throw new Error("globalEventDeny must be an array of { domain, name } rules");
|
|
103
|
+
}
|
|
104
|
+
const rules: EventPolicyRule[] = [];
|
|
105
|
+
for (const item of val) {
|
|
106
|
+
const rule = parseEventRule(item);
|
|
107
|
+
if (!rule) {
|
|
108
|
+
throw new Error("globalEventDeny: each entry needs domain and name strings");
|
|
109
|
+
}
|
|
110
|
+
rules.push(rule);
|
|
111
|
+
}
|
|
112
|
+
return rules;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function parseGlobalQueryDenyFromJson(val: unknown): QueryPolicyRule[] | undefined {
|
|
116
|
+
if (val === undefined || val === null) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(val)) {
|
|
120
|
+
throw new Error("globalQueryDeny must be an array of { rid, name } rules");
|
|
121
|
+
}
|
|
122
|
+
const rules: QueryPolicyRule[] = [];
|
|
123
|
+
for (const item of val) {
|
|
124
|
+
const rule = parseQueryRule(item);
|
|
125
|
+
if (!rule) {
|
|
126
|
+
throw new Error("globalQueryDeny: each entry needs rid and name strings");
|
|
127
|
+
}
|
|
128
|
+
rules.push(rule);
|
|
129
|
+
}
|
|
130
|
+
return rules;
|
|
131
|
+
}
|
package/src/runMcp.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installEngineRuntimeSettings,
|
|
3
|
+
resolveEngineSettings,
|
|
4
|
+
} from "./engineConfig";
|
|
5
|
+
|
|
6
|
+
/** Dev MCP stdio entry (pico-engine mcp --stdio). */
|
|
7
|
+
export async function runMcpCli(argv: string[]): Promise<void> {
|
|
8
|
+
const settings = resolveEngineSettings({});
|
|
9
|
+
installEngineRuntimeSettings(settings);
|
|
10
|
+
if (!process.env.PICO_ENGINE_BASE_URL) {
|
|
11
|
+
process.env.PICO_ENGINE_BASE_URL = settings.baseUrl;
|
|
12
|
+
}
|
|
13
|
+
if (!process.env.PICO_ENGINE_HOME) {
|
|
14
|
+
process.env.PICO_ENGINE_HOME = settings.home;
|
|
15
|
+
}
|
|
16
|
+
const args = argv.slice(1);
|
|
17
|
+
const stdio = args.includes("--stdio") || args.length === 0;
|
|
18
|
+
if (!stdio) {
|
|
19
|
+
console.error("Usage: pico-engine mcp --stdio");
|
|
20
|
+
console.error("");
|
|
21
|
+
console.error("Connects to a running local engine (PICO_ENGINE_BASE_URL).");
|
|
22
|
+
console.error("Requires localhost /c access or PICO_ENGINE_UI_ECI.");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
// JS (not tsc): avoids pulling MCP SDK types into the main compile.
|
|
26
|
+
const { runDevMcpStdio } = require("../mcp/runStdio.js") as {
|
|
27
|
+
runDevMcpStdio: () => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
await runDevMcpStdio();
|
|
30
|
+
}
|