pico-engine 1.6.2 → 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.
Files changed (107) hide show
  1. package/README.md +117 -14
  2. package/dist/RulesetRegistryLoaderFs.js +24 -8
  3. package/dist/auth/cookies.js +32 -0
  4. package/dist/auth/index.js +6 -1
  5. package/dist/bundledKrl.js +129 -11
  6. package/dist/channelIdentityPolicy.js +22 -0
  7. package/dist/cli.js +105 -46
  8. package/dist/engineConfig.js +280 -0
  9. package/dist/identity/IdentityService.js +90 -0
  10. package/dist/identity/crossPico.js +106 -30
  11. package/dist/identity/didoModule.js +80 -18
  12. package/dist/identity/establishSubscription.js +2 -2
  13. package/dist/identity/identityPortable.js +92 -0
  14. package/dist/identity/index.js +10 -1
  15. package/dist/identity/localPeerReconcile.js +65 -0
  16. package/dist/identity/peerDid4.js +175 -0
  17. package/dist/identity/peerDid4Create.js +90 -0
  18. package/dist/identity/portableExportPrepare.js +196 -0
  19. package/dist/identity/portableMove.js +87 -0
  20. package/dist/identity/skyIntro.js +10 -4
  21. package/dist/identity/skyProtocol.js +26 -1
  22. package/dist/identity/skyRotation.js +121 -0
  23. package/dist/identity/store.js +5 -1
  24. package/dist/identity/subscriptionEntSync.js +72 -0
  25. package/dist/identity/veramoDidComm.js +41 -2
  26. package/dist/identity/webvh.js +4 -2
  27. package/dist/identity/webvhRelocation.js +115 -0
  28. package/dist/index.js +127 -34
  29. package/dist/levelDb.js +102 -0
  30. package/dist/logging.js +47 -8
  31. package/dist/oauth/OAuthService.js +12 -5
  32. package/dist/oauth/channelEligibility.js +7 -1
  33. package/dist/oauth/index.js +3 -1
  34. package/dist/policyConfigFromJson.js +112 -0
  35. package/dist/runMcp.js +27 -0
  36. package/dist/server.js +95 -24
  37. package/dist/subtreeWrangler.js +180 -0
  38. package/dist/uiChannelPolicies.js +16 -0
  39. package/krl/io.picolabs.oauth.krl +51 -5
  40. package/krl/io.picolabs.pds.krl +131 -10
  41. package/krl/io.picolabs.pico-engine-ui.krl +219 -22
  42. package/krl/io.picolabs.portable_subtree.krl +97 -0
  43. package/krl/io.picolabs.subscription.krl +226 -72
  44. package/krl/io.picolabs.wrangler.krl +300 -58
  45. package/mcp/devResources.js +118 -0
  46. package/mcp/devTools.js +351 -0
  47. package/mcp/engineClient.js +133 -0
  48. package/mcp/meshHttp.js +137 -0
  49. package/mcp/meshTools.js +189 -0
  50. package/mcp/runStdio.js +34 -0
  51. package/mcp/schemaToZod.js +56 -0
  52. package/package.json +22 -8
  53. package/public/docs/_sidebar.md +2 -1
  54. package/public/docs/llms-full.txt +479 -0
  55. package/public/docs/llms.txt +37 -0
  56. package/public/docs/openapi.yaml +78 -0
  57. package/public/docs/pico-engine.md +235 -4
  58. package/public/docs/pico-overview.md +117 -0
  59. package/public/docs/pico.md +3 -1
  60. package/public/docs/rulesets/README.md +25 -0
  61. package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
  62. package/public/docs/rulesets/io.picolabs.pds.md +327 -0
  63. package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
  64. package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
  65. package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
  66. package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
  67. package/public/pico-engine-ui.css +1 -1
  68. package/public/pico-engine-ui.js +28 -26
  69. package/src/RulesetRegistryLoaderFs.ts +43 -11
  70. package/src/auth/cookies.ts +34 -0
  71. package/src/auth/index.ts +7 -0
  72. package/src/bundledKrl.ts +150 -12
  73. package/src/channelIdentityPolicy.ts +29 -0
  74. package/src/cli.ts +98 -40
  75. package/src/engineConfig.ts +345 -0
  76. package/src/identity/IdentityService.ts +189 -1
  77. package/src/identity/crossPico.ts +161 -41
  78. package/src/identity/didoModule.ts +140 -23
  79. package/src/identity/establishSubscription.ts +2 -2
  80. package/src/identity/identityPortable.ts +153 -0
  81. package/src/identity/index.ts +14 -0
  82. package/src/identity/localPeerReconcile.ts +97 -0
  83. package/src/identity/peerDid4.ts +197 -0
  84. package/src/identity/peerDid4Create.ts +121 -0
  85. package/src/identity/portableExportPrepare.ts +302 -0
  86. package/src/identity/portableMove.ts +193 -0
  87. package/src/identity/skyIntro.ts +16 -12
  88. package/src/identity/skyProtocol.ts +46 -0
  89. package/src/identity/skyRotation.ts +211 -0
  90. package/src/identity/store.ts +5 -1
  91. package/src/identity/subscriptionEntSync.ts +97 -0
  92. package/src/identity/veramoDidComm.ts +52 -2
  93. package/src/identity/webvh.ts +4 -4
  94. package/src/identity/webvhRelocation.ts +167 -0
  95. package/src/index.ts +179 -39
  96. package/src/levelDb.ts +122 -0
  97. package/src/logging.ts +63 -11
  98. package/src/oauth/OAuthService.ts +20 -6
  99. package/src/oauth/channelEligibility.ts +9 -0
  100. package/src/oauth/index.ts +7 -1
  101. package/src/policyConfigFromJson.ts +131 -0
  102. package/src/runMcp.ts +30 -0
  103. package/src/server.ts +133 -27
  104. package/src/subtreeWrangler.ts +278 -0
  105. package/src/uiChannelPolicies.ts +16 -0
  106. package/krl/io.picolabs.did-o.krl +0 -349
  107. package/krl/test/didtestdid.krl +0 -78
package/src/levelDb.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { ClassicLevel } from "classic-level";
2
+ import * as fs from "fs/promises";
3
+ import * as makeDir from "make-dir";
4
+ import * as path from "path";
5
+ import type { KrlLogger } from "krl-stdlib";
6
+
7
+ export type ClassicLevelOptions = ConstructorParameters<typeof ClassicLevel>[1];
8
+
9
+ function errCode(err: unknown): string | undefined {
10
+ if (err && typeof err === "object" && "code" in err) {
11
+ const code = (err as { code?: unknown }).code;
12
+ return typeof code === "string" ? code : undefined;
13
+ }
14
+ return undefined;
15
+ }
16
+
17
+ function errMessage(err: unknown): string {
18
+ if (err instanceof Error) {
19
+ return err.message;
20
+ }
21
+ return String(err);
22
+ }
23
+
24
+ export function isLevelDbOpenError(err: unknown): boolean {
25
+ const code = errCode(err);
26
+ if (code === "LEVEL_LOCKED") {
27
+ return true;
28
+ }
29
+ const message = errMessage(err);
30
+ return /LOCK|corrupt|IO error|database/i.test(message);
31
+ }
32
+
33
+ async function removeStaleLockFile(
34
+ location: string,
35
+ log?: KrlLogger
36
+ ): Promise<void> {
37
+ const lockPath = path.join(location, "LOCK");
38
+ try {
39
+ await fs.unlink(lockPath);
40
+ log?.info("Removed stale LevelDB LOCK file", { location });
41
+ } catch (err: any) {
42
+ if (err?.code !== "ENOENT") {
43
+ throw err;
44
+ }
45
+ }
46
+ }
47
+
48
+ async function closeClassicLevelQuietly(
49
+ db: ClassicLevel<any, any>
50
+ ): Promise<void> {
51
+ try {
52
+ await db.close();
53
+ } catch {
54
+ // May never have opened.
55
+ }
56
+ }
57
+
58
+ async function openOnce<K = any, V = any>(
59
+ location: string,
60
+ options?: ClassicLevelOptions
61
+ ): Promise<ClassicLevel<K, V>> {
62
+ const db = new ClassicLevel<K, V>(
63
+ location,
64
+ options as ConstructorParameters<typeof ClassicLevel<K, V>>[1]
65
+ );
66
+ try {
67
+ await db.open();
68
+ return db;
69
+ } catch (err) {
70
+ // A failed open can still leave a handle; if it is GC'd later it closes
71
+ // the underlying store and breaks a subsequent successful open on the same path.
72
+ await closeClassicLevelQuietly(db);
73
+ throw err;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Open a ClassicLevel database, recovering from stale locks or minor corruption
79
+ * left by an unclean shutdown (e.g. container SIGKILL).
80
+ *
81
+ * Recovery order (non-destructive first):
82
+ * 1. Normal open
83
+ * 2. Remove stale LOCK and retry
84
+ * 3. LevelDB repair and retry
85
+ */
86
+ export async function openClassicLevelWithRecovery<K = any, V = any>(
87
+ location: string,
88
+ options?: ClassicLevelOptions,
89
+ log?: KrlLogger
90
+ ): Promise<ClassicLevel<K, V>> {
91
+ await makeDir(location);
92
+
93
+ try {
94
+ return await openOnce(location, options);
95
+ } catch (firstErr) {
96
+ if (!isLevelDbOpenError(firstErr)) {
97
+ throw firstErr;
98
+ }
99
+ log?.warn("LevelDB open failed; attempting recovery", {
100
+ location,
101
+ error: firstErr,
102
+ });
103
+ }
104
+
105
+ await removeStaleLockFile(location, log);
106
+ try {
107
+ return await openOnce(location, options);
108
+ } catch (secondErr) {
109
+ if (!isLevelDbOpenError(secondErr)) {
110
+ throw secondErr;
111
+ }
112
+ log?.warn("LevelDB open failed after lock cleanup; running repair", {
113
+ location,
114
+ error: secondErr,
115
+ });
116
+ }
117
+
118
+ await ClassicLevel.repair(location);
119
+ log?.info("LevelDB repair finished", { location });
120
+
121
+ return openOnce(location, options);
122
+ }
package/src/logging.ts CHANGED
@@ -2,14 +2,36 @@ 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
 
8
9
  const logStreams: { [filePath: string]: NodeJS.WritableStream } = {};
10
+
11
+ function stdoutOnlyLogWriter(): (line: string) => void {
12
+ const isTest = process.env.NODE_ENV === "test";
13
+ return (line: string) => {
14
+ if (!isTest) {
15
+ process.stdout.write(line);
16
+ }
17
+ };
18
+ }
19
+
20
+ function attachSafeLogStreamHandlers(
21
+ fileStream: NodeJS.WritableStream,
22
+ filePath: string
23
+ ): void {
24
+ fileStream.on("error", (err: Error) => {
25
+ process.stderr.write(
26
+ `pico-engine log file write failed (${filePath}): ${err.message}\n`
27
+ );
28
+ });
29
+ }
30
+
9
31
  function getRotatingFileStream(filePath: string): NodeJS.WritableStream {
10
32
  if (!logStreams[filePath]) {
11
33
  const filename = path.basename(filePath);
12
- logStreams[filePath] = rfs(
34
+ const fileStream = rfs(
13
35
  (time: Date, index: number) => {
14
36
  if (!time) return filename;
15
37
 
@@ -18,16 +40,38 @@ function getRotatingFileStream(filePath: string): NodeJS.WritableStream {
18
40
  {
19
41
  path: path.dirname(filePath),
20
42
 
21
- size: "100M", // rotate every 10 MegaBytes written
43
+ size: "100M", // rotate every 100 MegaBytes written
22
44
  maxFiles: 12,
23
- },
45
+ }
24
46
  ) as NodeJS.WritableStream;
47
+ attachSafeLogStreamHandlers(fileStream, filePath);
48
+ logStreams[filePath] = fileStream;
25
49
  }
26
50
  return logStreams[filePath];
27
51
  }
28
52
 
53
+ export function resolveEngineLogFilePath(home: string): string | null {
54
+ const settings = getEngineRuntimeSettings();
55
+ if (settings.logToStdout) {
56
+ return null;
57
+ }
58
+ if (settings.logFile) {
59
+ return settings.logFile;
60
+ }
61
+ return path.resolve(home, "pico-engine.log");
62
+ }
63
+
64
+ export function makeEngineLogWriter(
65
+ filePath: string | null
66
+ ): (line: string) => void {
67
+ if (!filePath) {
68
+ return stdoutOnlyLogWriter();
69
+ }
70
+ return makeRotatingFileLogWriter(filePath);
71
+ }
72
+
29
73
  export function makeRotatingFileLogWriter(
30
- filePath: string,
74
+ filePath: string
31
75
  ): (line: string) => void {
32
76
  const fileStream = getRotatingFileStream(filePath);
33
77
  const isTest = process.env.NODE_ENV === "test";
@@ -36,7 +80,13 @@ export function makeRotatingFileLogWriter(
36
80
  if (!isTest) {
37
81
  process.stdout.write(line);
38
82
  }
39
- fileStream.write(line);
83
+ fileStream.write(line, (err?: Error | null) => {
84
+ if (err) {
85
+ process.stderr.write(
86
+ `pico-engine log file write failed (${filePath}): ${err.message}\n`
87
+ );
88
+ }
89
+ });
40
90
  }
41
91
 
42
92
  return write;
@@ -44,30 +94,32 @@ export function makeRotatingFileLogWriter(
44
94
 
45
95
  export async function getPicoLogs(
46
96
  filePath: string,
47
- picoId: string,
97
+ picoId: string
48
98
  ): Promise<PicoLogEntry[]> {
49
99
  const output: PicoLogEntry[] = [];
50
100
 
101
+ if (!(await fs.promises.stat(filePath).catch(() => null))) {
102
+ return output;
103
+ }
104
+
51
105
  const rl = readline.createInterface({
52
106
  input: fs.createReadStream(filePath),
53
107
  });
54
108
 
55
109
  for await (const line of rl) {
56
- // Each line in the readline input will be successively available here as
57
- // `line`.
58
110
  if (line.indexOf(picoId) < 0) {
59
- continue; // not my pico
111
+ continue;
60
112
  }
61
113
  let entry;
62
114
  try {
63
115
  entry = JSON.parse(line);
64
116
  } catch (err) {}
65
117
  if (!entry || entry.picoId !== picoId) {
66
- continue; // not my pico
118
+ continue;
67
119
  }
68
120
  const time = new Date(entry.time);
69
121
  if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
70
- continue; // too old
122
+ continue;
71
123
  }
72
124
 
73
125
  const out: PicoLogEntry = {
@@ -1,9 +1,17 @@
1
1
  import * as crypto from "crypto";
2
2
  import { ChannelReadOnly, PicoDb, PicoDbKey, PicoFramework } from "pico-framework";
3
3
  import * as acg from "./acg";
4
- import { isOAuthEligibleChannel } from "./channelEligibility";
4
+ import {
5
+ isMeshOAuthExemptChannel,
6
+ isOAuthEligibleChannel,
7
+ } from "./channelEligibility";
5
8
  import { OAuthError } from "./errors";
6
9
  import { isChannelUnderRoot, meshRequiresOAuth as meshRequiresOAuthForEci } from "./meshOAuth";
10
+ import {
11
+ channelHasUnrestrictedAllow,
12
+ isDidcommIngressChannel,
13
+ wildcardSkyRequireBearerEnabled,
14
+ } from "../channelIdentityPolicy";
7
15
 
8
16
  const OAUTH_CHANNEL_PREFIX = "oauth-channel";
9
17
  const OAUTH_TOKEN_PREFIX = "oauth-token";
@@ -234,18 +242,24 @@ export class OAuthService {
234
242
  async skyRequiresBearer(eci: string): Promise<boolean> {
235
243
  try {
236
244
  const channel = this.lookupChannelReadOnly(eci);
245
+ if (isDidcommIngressChannel(channel)) {
246
+ return false;
247
+ }
237
248
  if (
238
- channel.tags.includes("didcomm") &&
239
- channel.tags.includes("ingress")
249
+ wildcardSkyRequireBearerEnabled() &&
250
+ channelHasUnrestrictedAllow(channel)
240
251
  ) {
252
+ return true;
253
+ }
254
+ if (isOAuthEligibleChannel(channel)) {
255
+ return true;
256
+ }
257
+ if (isMeshOAuthExemptChannel(channel)) {
241
258
  return false;
242
259
  }
243
260
  } catch (_e) {
244
261
  // channel not found — fall through
245
262
  }
246
- if (await this.channelRequiresBearer(eci)) {
247
- return true;
248
- }
249
263
  return this.meshRequiresOAuth(eci);
250
264
  }
251
265
 
@@ -2,6 +2,9 @@ import { ChannelReadOnly } from "pico-framework";
2
2
 
3
3
  export const OAUTH_WEBHOOK_TAG = "oauth-webhook";
4
4
 
5
+ /** Opt out of mesh-wide /sky/* OAuth when the root has io.picolabs.oauth installed. */
6
+ export const MESH_OAUTH_EXEMPT_TAG = "mesh-oauth-exempt";
7
+
5
8
  const SUBSCRIPTION_CHANNEL_TAGS = new Set([
6
9
  "wellknown_rx",
7
10
  "tx_rx",
@@ -24,3 +27,9 @@ export function isOAuthEligibleChannel(channel: ChannelReadOnly): boolean {
24
27
  }
25
28
  return channel.tags.includes(OAUTH_WEBHOOK_TAG);
26
29
  }
30
+
31
+ export function isMeshOAuthExemptChannel(channel: ChannelReadOnly): boolean {
32
+ return channel.tags.some(
33
+ (tag) => tag.toLowerCase() === MESH_OAUTH_EXEMPT_TAG
34
+ );
35
+ }
@@ -9,6 +9,12 @@ export {
9
9
  parseAuthorizeQuery,
10
10
  renderConsentHtml,
11
11
  } from "./OAuthService";
12
- export { OAUTH_WEBHOOK_TAG, isOAuthEligibleChannel, isSubscriptionChannel } from "./channelEligibility";
12
+ export {
13
+ OAUTH_WEBHOOK_TAG,
14
+ MESH_OAUTH_EXEMPT_TAG,
15
+ isOAuthEligibleChannel,
16
+ isMeshOAuthExemptChannel,
17
+ isSubscriptionChannel,
18
+ } from "./channelEligibility";
13
19
  export { OAUTH_MESH_RULESET_RID, meshRequiresOAuth, rootHasOAuthMeshRuleset, rootPicoIdForChannelEci, isChannelUnderRoot } from "./meshOAuth";
14
20
  export { default as initOAuthModule } from "./krlModule";
@@ -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
+ }