pico-engine 1.6.4 → 1.9.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 (108) hide show
  1. package/README.md +16 -9
  2. package/dist/RulesetRegistryLoaderFs.js +60 -6
  3. package/dist/auth/cookies.js +32 -0
  4. package/dist/auth/index.js +6 -1
  5. package/dist/channelIdentityPolicy.js +22 -0
  6. package/dist/cli.js +106 -69
  7. package/dist/engineConfig.js +291 -0
  8. package/dist/identity/IdentityService.js +90 -0
  9. package/dist/identity/crossPico.js +24 -8
  10. package/dist/identity/didoModule.js +80 -18
  11. package/dist/identity/establishSubscription.js +2 -2
  12. package/dist/identity/identityPortable.js +92 -0
  13. package/dist/identity/index.js +10 -1
  14. package/dist/identity/localPeerReconcile.js +65 -0
  15. package/dist/identity/peerDid4.js +175 -0
  16. package/dist/identity/peerDid4Create.js +90 -0
  17. package/dist/identity/portableExportPrepare.js +196 -0
  18. package/dist/identity/portableMove.js +87 -0
  19. package/dist/identity/skyIntro.js +6 -3
  20. package/dist/identity/skyProtocol.js +26 -1
  21. package/dist/identity/skyRotation.js +121 -0
  22. package/dist/identity/store.js +5 -1
  23. package/dist/identity/subscriptionEntSync.js +72 -0
  24. package/dist/identity/veramoDidComm.js +41 -2
  25. package/dist/identity/webvh.js +4 -2
  26. package/dist/identity/webvhRelocation.js +115 -0
  27. package/dist/index.js +84 -27
  28. package/dist/logging.js +156 -16
  29. package/dist/oauth/OAuthService.js +6 -2
  30. package/dist/policyConfigFromJson.js +112 -0
  31. package/dist/runMcp.js +27 -0
  32. package/dist/server.js +261 -24
  33. package/dist/stageKrl.js +26 -0
  34. package/dist/subtreeWrangler.js +180 -0
  35. package/dist/uiChannelPolicies.js +15 -0
  36. package/dist/xmluiRuntime.js +68 -0
  37. package/krl/io.picolabs.oauth.krl +41 -2
  38. package/krl/io.picolabs.pds.krl +131 -10
  39. package/krl/io.picolabs.pico-engine-ui.krl +217 -94
  40. package/krl/io.picolabs.portable_subtree.krl +97 -0
  41. package/krl/io.picolabs.subscription.krl +180 -72
  42. package/krl/io.picolabs.wrangler.krl +313 -57
  43. package/krl/io.picolabs.xmlui.krl +295 -0
  44. package/mcp/devResources.js +118 -0
  45. package/mcp/devTools.js +351 -0
  46. package/mcp/engineClient.js +133 -0
  47. package/mcp/meshHttp.js +137 -0
  48. package/mcp/meshTools.js +189 -0
  49. package/mcp/runStdio.js +34 -0
  50. package/mcp/schemaToZod.js +56 -0
  51. package/package.json +24 -9
  52. package/public/.DS_Store +0 -0
  53. package/public/docs/_sidebar.md +3 -1
  54. package/public/docs/llms-full.txt +630 -0
  55. package/public/docs/llms.txt +38 -0
  56. package/public/docs/openapi.yaml +78 -0
  57. package/public/docs/pico-engine.md +239 -4
  58. package/public/docs/pico-overview.md +117 -0
  59. package/public/docs/pico-views-xmlui.md +5 -0
  60. package/public/docs/pico-views.md +140 -0
  61. package/public/docs/pico.md +3 -1
  62. package/public/docs/rulesets/README.md +26 -0
  63. package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
  64. package/public/docs/rulesets/io.picolabs.pds.md +327 -0
  65. package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
  66. package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
  67. package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
  68. package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
  69. package/public/pico-engine-ui.css +1 -1
  70. package/public/pico-engine-ui.js +27 -23
  71. package/public/xmlui/0.12.7.js +419 -0
  72. package/public/xmlui/pico-view-boot.js +153 -0
  73. package/src/RulesetRegistryLoaderFs.ts +66 -7
  74. package/src/auth/cookies.ts +34 -0
  75. package/src/auth/index.ts +7 -0
  76. package/src/channelIdentityPolicy.ts +29 -0
  77. package/src/cli.ts +70 -37
  78. package/src/engineConfig.ts +363 -0
  79. package/src/identity/IdentityService.ts +189 -1
  80. package/src/identity/crossPico.ts +57 -8
  81. package/src/identity/didoModule.ts +140 -23
  82. package/src/identity/establishSubscription.ts +2 -2
  83. package/src/identity/identityPortable.ts +153 -0
  84. package/src/identity/index.ts +14 -0
  85. package/src/identity/localPeerReconcile.ts +97 -0
  86. package/src/identity/peerDid4.ts +197 -0
  87. package/src/identity/peerDid4Create.ts +121 -0
  88. package/src/identity/portableExportPrepare.ts +302 -0
  89. package/src/identity/portableMove.ts +193 -0
  90. package/src/identity/skyIntro.ts +11 -11
  91. package/src/identity/skyProtocol.ts +46 -0
  92. package/src/identity/skyRotation.ts +211 -0
  93. package/src/identity/store.ts +5 -1
  94. package/src/identity/subscriptionEntSync.ts +97 -0
  95. package/src/identity/veramoDidComm.ts +52 -2
  96. package/src/identity/webvh.ts +4 -4
  97. package/src/identity/webvhRelocation.ts +167 -0
  98. package/src/index.ts +123 -31
  99. package/src/logging.ts +173 -18
  100. package/src/oauth/OAuthService.ts +11 -3
  101. package/src/policyConfigFromJson.ts +131 -0
  102. package/src/runMcp.ts +30 -0
  103. package/src/server.ts +328 -27
  104. package/src/stageKrl.ts +26 -0
  105. package/src/subtreeWrangler.ts +278 -0
  106. package/src/uiChannelPolicies.ts +15 -0
  107. package/src/xmluiRuntime.ts +66 -0
  108. package/krl/io.picolabs.did-o.krl +0 -349
package/dist/index.js CHANGED
@@ -13,32 +13,56 @@ const logging_1 = require("./logging");
13
13
  const levelDb_1 = require("./levelDb");
14
14
  const provisionRoot_1 = require("./provisionRoot");
15
15
  const RulesetRegistryLoaderFs_1 = require("./RulesetRegistryLoaderFs");
16
+ const bundledKrl_1 = require("./bundledKrl");
17
+ const subtreeWrangler_1 = require("./subtreeWrangler");
16
18
  const server_1 = require("./server");
19
+ const engineConfig_1 = require("./engineConfig");
17
20
  const charwise = require("charwise");
18
21
  const safeJsonCodec = require("level-json-coerce-null");
19
- const homeDir = require("home-dir");
20
22
  const version = require("../package.json").version;
23
+ /** Integration harnesses (e.g. manifold-api Docker tests): boot with one root, no passkey. */
24
+ function autoCreateRootFromEnv() {
25
+ const v = process.env.PICO_ENGINE_AUTO_CREATE_ROOT;
26
+ if (typeof v !== "string" || v.trim().length === 0) {
27
+ return undefined;
28
+ }
29
+ const s = v.trim().toLowerCase();
30
+ if (s === "1" || s === "true" || s === "yes") {
31
+ return true;
32
+ }
33
+ if (s === "0" || s === "false" || s === "no") {
34
+ return false;
35
+ }
36
+ return undefined;
37
+ }
21
38
  async function startEngine(configuration = {}) {
22
- var _a, _b;
23
- let home = configuration.home;
24
- let port = configuration.port;
25
- let base_url = configuration.base_url;
26
- if (typeof home !== "string") {
27
- const envHome = process.env.PICO_ENGINE_HOME;
28
- if (typeof envHome === "string" &&
29
- envHome.length > 0 &&
30
- process.env.NODE_ENV === "test") {
31
- home = envHome;
32
- }
33
- else {
34
- home = homeDir(".pico-engine");
35
- }
39
+ var _a, _b, _c, _d, _e, _f, _g;
40
+ const settings = (0, engineConfig_1.resolveEngineSettings)({
41
+ home: configuration.home,
42
+ port: configuration.port,
43
+ base_url: configuration.base_url,
44
+ rpID: configuration.rpID,
45
+ rpName: configuration.rpName,
46
+ origin: configuration.origin,
47
+ allowSelfSignup: configuration.allowSelfSignup,
48
+ defaultRootPolicyCeiling: configuration.defaultRootPolicyCeiling,
49
+ globalEventDeny: configuration.globalEventDeny,
50
+ globalQueryDeny: configuration.globalQueryDeny,
51
+ });
52
+ (0, engineConfig_1.installEngineRuntimeSettings)(settings);
53
+ const home = settings.home;
54
+ let port = (_a = configuration.port) !== null && _a !== void 0 ? _a : settings.port;
55
+ const baseUrlFromCaller = configuration.base_url;
56
+ /** Filled after listen when using port 0 or when config baseUrl port does not match. */
57
+ let base_url = baseUrlFromCaller;
58
+ if (base_url == null && port > 0) {
59
+ base_url = settings.baseUrl;
36
60
  }
37
61
  await makeDir(home);
38
62
  const logFilePath = (0, logging_1.resolveEngineLogFilePath)(home);
39
63
  const log = configuration.log
40
64
  ? configuration.log
41
- : (0, krl_stdlib_1.makeKrlLogger)((0, logging_1.makeEngineLogWriter)(logFilePath));
65
+ : (0, krl_stdlib_1.makeKrlLogger)((0, logging_1.makeEngineLogWriter)(logFilePath, home));
42
66
  const db = await (0, levelDb_1.openClassicLevelWithRecovery)(path.resolve(home, "db"), {
43
67
  keyEncoding: charwise,
44
68
  valueEncoding: safeJsonCodec,
@@ -50,27 +74,55 @@ async function startEngine(configuration = {}) {
50
74
  log,
51
75
  modules: configuration.modules,
52
76
  useEventInputTime: configuration.useEventInputTime,
53
- autoCreateRootPico: (_a = configuration.autoCreateRootPico) !== null && _a !== void 0 ? _a : false,
77
+ autoCreateRootPico: (_c = (_b = configuration.autoCreateRootPico) !== null && _b !== void 0 ? _b : autoCreateRootFromEnv()) !== null && _c !== void 0 ? _c : false,
78
+ defaultRootPolicyCeiling: (_d = configuration.defaultRootPolicyCeiling) !== null && _d !== void 0 ? _d : settings.defaultRootPolicyCeiling,
79
+ globalEventDeny: (_e = configuration.globalEventDeny) !== null && _e !== void 0 ? _e : settings.globalEventDeny,
80
+ globalQueryDeny: (_f = configuration.globalQueryDeny) !== null && _f !== void 0 ? _f : settings.globalQueryDeny,
54
81
  getPicoLogs(picoId) {
55
- if (!logFilePath) {
56
- return Promise.resolve([]);
57
- }
58
- return (0, logging_1.getPicoLogs)(logFilePath, picoId);
82
+ return Promise.resolve((0, logging_1.picoLogEntries)(picoId));
59
83
  },
60
84
  });
61
85
  const pf = core.picoFramework;
86
+ core.resolveBundledRulesetUrl = bundledKrl_1.resolveBundledKrlUrl;
87
+ core.subtreeImportServices = (0, subtreeWrangler_1.wranglerSubtreeImportServices)(core.rsRegistry);
62
88
  const identity = new identity_1.IdentityStore({ db: pf.db });
63
89
  let identityService;
90
+ const onPicoCreated = async (picoId, ctx) => {
91
+ if (core.base_url) {
92
+ await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
93
+ }
94
+ };
64
95
  identityService = new identity_1.IdentityService({
65
96
  store: identity,
66
97
  getBaseUrl: () => core.base_url || base_url || "",
67
98
  pf,
99
+ rsRegistry: core.rsRegistry,
100
+ resolveBundledRulesetUrl: bundledKrl_1.resolveBundledKrlUrl,
101
+ reloadImportedSchedules: (picoIds) => core.reloadImportedSchedules(picoIds),
102
+ firePicoImported: async (result) => {
103
+ const importedRoot = pf.getPico(result.newRootPicoId);
104
+ if (!importedRoot) {
105
+ return;
106
+ }
107
+ await importedRoot.event({
108
+ eci: result.newRootEci,
109
+ domain: "wrangler",
110
+ name: "pico_imported",
111
+ data: {
112
+ attrs: {
113
+ oldRootPicoId: result.oldRootPicoId,
114
+ newRootPicoId: result.newRootPicoId,
115
+ eciMap: result.eciMap,
116
+ picoIdMap: result.picoIdMap,
117
+ portableIdentity: true,
118
+ },
119
+ },
120
+ time: Date.now(),
121
+ });
122
+ },
68
123
  });
69
- core.onPicoCreated = async (picoId, ctx) => {
70
- if (core.base_url) {
71
- await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
72
- }
73
- };
124
+ core.onPicoCreated = onPicoCreated;
125
+ core.subtreePortableHooks = (0, identity_1.createSubtreePortableHooks)(identity, pf);
74
126
  core.modules["dido"] = (0, identity_1.initDidoModule)(identityService);
75
127
  try {
76
128
  await core.start();
@@ -97,7 +149,7 @@ async function startEngine(configuration = {}) {
97
149
  rpID: configuration.rpID,
98
150
  rpName: configuration.rpName,
99
151
  origin: configuration.origin,
100
- allowSelfSignup: (_b = configuration.allowSelfSignup) !== null && _b !== void 0 ? _b : false,
152
+ allowSelfSignup: (_g = configuration.allowSelfSignup) !== null && _g !== void 0 ? _g : settings.allowSelfSignup,
101
153
  flushBootstrapUrl: async (url) => {
102
154
  const flushed = await rsRegistry.flush(url);
103
155
  return { rid: flushed.rid };
@@ -157,6 +209,10 @@ async function startEngine(configuration = {}) {
157
209
  if (typeof base_url !== "string") {
158
210
  base_url = `http://localhost:${port}`;
159
211
  }
212
+ else if (baseUrlFromCaller == null &&
213
+ (configuration.port === 0 || port !== settings.port)) {
214
+ base_url = `http://localhost:${port}`;
215
+ }
160
216
  core.base_url = base_url;
161
217
  await identityService.ensureWebvhForAllLoadedPicos();
162
218
  log.info(`Listening at ${base_url}`);
@@ -195,6 +251,7 @@ async function startEngine(configuration = {}) {
195
251
  port,
196
252
  base_url,
197
253
  pf,
254
+ core,
198
255
  uiECI,
199
256
  rsRegistry,
200
257
  auth,
package/dist/logging.js CHANGED
@@ -7,7 +7,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
7
7
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.subscribePicoLogRing = subscribePicoLogRing;
11
+ exports.picoLogRingLimit = picoLogRingLimit;
12
+ exports.clearPicoLogRing = clearPicoLogRing;
13
+ exports.rememberPicoLogLine = rememberPicoLogLine;
14
+ exports.picoLogEntries = picoLogEntries;
10
15
  exports.resolveEngineLogFilePath = resolveEngineLogFilePath;
16
+ exports.resolvePicoLogsReadPath = resolvePicoLogsReadPath;
11
17
  exports.makeEngineLogWriter = makeEngineLogWriter;
12
18
  exports.makeRotatingFileLogWriter = makeRotatingFileLogWriter;
13
19
  exports.getPicoLogs = getPicoLogs;
@@ -15,8 +21,110 @@ const fs = require("fs");
15
21
  const readline = require("readline");
16
22
  const krl_stdlib_1 = require("krl-stdlib");
17
23
  const path = require("path");
24
+ const engineConfig_1 = require("./engineConfig");
18
25
  const rfs = require("rotating-file-stream");
19
26
  const logStreams = {};
27
+ /** Last N transactions per pico kept for the Logging tab. A restart clears this. */
28
+ const DEFAULT_LOG_RING = 200;
29
+ const picoLogRings = new Map();
30
+ const picoLogListeners = new Set();
31
+ /** Fires when a transaction on a pico finishes (`txnDone` or `txnError`). */
32
+ function subscribePicoLogRing(listener) {
33
+ picoLogListeners.add(listener);
34
+ return () => {
35
+ picoLogListeners.delete(listener);
36
+ };
37
+ }
38
+ function notifyPicoLog(picoId, txnId) {
39
+ for (const listener of [...picoLogListeners]) {
40
+ try {
41
+ listener(picoId, txnId);
42
+ }
43
+ catch (_a) {
44
+ // One client must not stop the log writer or the other clients.
45
+ }
46
+ }
47
+ }
48
+ function picoLogRingLimit() {
49
+ const raw = process.env.PICO_ENGINE_LOG_RING;
50
+ if (raw == null || raw.trim() === "")
51
+ return DEFAULT_LOG_RING;
52
+ const n = Number(raw);
53
+ if (!Number.isFinite(n) || n < 1)
54
+ return DEFAULT_LOG_RING;
55
+ return Math.min(Math.floor(n), 10000);
56
+ }
57
+ function clearPicoLogRing() {
58
+ picoLogRings.clear();
59
+ picoLogListeners.clear();
60
+ }
61
+ /**
62
+ * Keep one structured log line for the Logging tab. Lines without a pico and
63
+ * a transaction are ignored. The oldest transaction for that pico is dropped
64
+ * once the ring is full.
65
+ */
66
+ function rememberPicoLogLine(line, limit = picoLogRingLimit()) {
67
+ const trimmed = line.trim();
68
+ if (!trimmed || trimmed[0] !== "{")
69
+ return;
70
+ let entry;
71
+ try {
72
+ entry = JSON.parse(trimmed);
73
+ }
74
+ catch (_a) {
75
+ return;
76
+ }
77
+ if (!entry ||
78
+ typeof entry.picoId !== "string" ||
79
+ entry.picoId === "" ||
80
+ typeof entry.txnId !== "string" ||
81
+ entry.txnId === "") {
82
+ return;
83
+ }
84
+ const picoId = entry.picoId;
85
+ const txnId = entry.txnId;
86
+ let ring = picoLogRings.get(picoId);
87
+ if (!ring) {
88
+ ring = { order: [], txns: new Map() };
89
+ picoLogRings.set(picoId, ring);
90
+ }
91
+ let lines = ring.txns.get(txnId);
92
+ if (!lines) {
93
+ lines = [];
94
+ ring.txns.set(txnId, lines);
95
+ ring.order.push(txnId);
96
+ while (ring.order.length > limit) {
97
+ const drop = ring.order.shift();
98
+ if (drop)
99
+ ring.txns.delete(drop);
100
+ }
101
+ }
102
+ const stored = Object.assign(Object.assign({}, entry), { level: krl_stdlib_1.krlLogLevelCodeToHuman[String(entry.level)] || `${entry.level}`, time: entry.time, txnId });
103
+ delete stored.picoId;
104
+ lines.push(stored);
105
+ if (entry.msg === "txnDone" || entry.msg === "txnError") {
106
+ notifyPicoLog(picoId, txnId);
107
+ }
108
+ }
109
+ /** Recent log lines for one pico, oldest transaction first. */
110
+ function picoLogEntries(picoId) {
111
+ const ring = picoLogRings.get(picoId);
112
+ if (!ring)
113
+ return [];
114
+ const output = [];
115
+ for (const txnId of ring.order) {
116
+ const lines = ring.txns.get(txnId);
117
+ if (lines)
118
+ output.push(...lines);
119
+ }
120
+ return output;
121
+ }
122
+ function tapLogRing(write) {
123
+ return (line) => {
124
+ rememberPicoLogLine(line);
125
+ write(line);
126
+ };
127
+ }
20
128
  function stdoutOnlyLogWriter() {
21
129
  const isTest = process.env.NODE_ENV === "test";
22
130
  return (line) => {
@@ -47,24 +155,58 @@ function getRotatingFileStream(filePath) {
47
155
  }
48
156
  return logStreams[filePath];
49
157
  }
158
+ /**
159
+ * Primary log sink: file path when logging to a file, or null when operator chose
160
+ * stdout-only (`logToStdout` / `PICO_ENGINE_LOG_FILE=stdout`).
161
+ */
50
162
  function resolveEngineLogFilePath(home) {
51
- const configured = process.env.PICO_ENGINE_LOG_FILE;
52
- if (configured === "0" ||
53
- configured === "-" ||
54
- configured === "stdout" ||
55
- configured === "") {
163
+ const settings = (0, engineConfig_1.getEngineRuntimeSettings)();
164
+ if (settings.logToStdout) {
56
165
  return null;
57
166
  }
58
- if (typeof configured === "string" && configured.length > 0) {
59
- return path.resolve(configured);
167
+ if (settings.logFile) {
168
+ return settings.logFile;
169
+ }
170
+ return path.resolve(home, "pico-engine.log");
171
+ }
172
+ /**
173
+ * Operator log file. The Logging tab reads the in-memory ring, not this file.
174
+ * When stdout-only, mirrors to `$PICO_ENGINE_HOME/pico-engine.log` unless
175
+ * `logMirror` is false (config `logMirror`, or `PICO_ENGINE_LOG_MIRROR=0`).
176
+ */
177
+ function resolvePicoLogsReadPath(home) {
178
+ const settings = (0, engineConfig_1.getEngineRuntimeSettings)();
179
+ if (settings.logToStdout) {
180
+ if (settings.logMirror === false) {
181
+ return null;
182
+ }
183
+ return path.resolve(home, "pico-engine.log");
184
+ }
185
+ if (settings.logFile) {
186
+ return settings.logFile;
60
187
  }
61
188
  return path.resolve(home, "pico-engine.log");
62
189
  }
63
- function makeEngineLogWriter(filePath) {
64
- if (!filePath) {
65
- return stdoutOnlyLogWriter();
190
+ function makeEngineLogWriter(filePath, home) {
191
+ if (filePath) {
192
+ return tapLogRing(makeRotatingFileLogWriter(filePath));
66
193
  }
67
- return makeRotatingFileLogWriter(filePath);
194
+ const mirrorPath = resolvePicoLogsReadPath(home);
195
+ if (!mirrorPath) {
196
+ return tapLogRing(stdoutOnlyLogWriter());
197
+ }
198
+ const fileStream = getRotatingFileStream(mirrorPath);
199
+ const isTest = process.env.NODE_ENV === "test";
200
+ return tapLogRing((line) => {
201
+ if (!isTest) {
202
+ process.stdout.write(line);
203
+ }
204
+ fileStream.write(line, (err) => {
205
+ if (err) {
206
+ process.stderr.write(`pico-engine log file write failed (${mirrorPath}): ${err.message}\n`);
207
+ }
208
+ });
209
+ });
68
210
  }
69
211
  function makeRotatingFileLogWriter(filePath) {
70
212
  const fileStream = getRotatingFileStream(filePath);
@@ -95,10 +237,8 @@ async function getPicoLogs(filePath, picoId) {
95
237
  _c = rl_1_1.value;
96
238
  _d = false;
97
239
  const line = _c;
98
- // Each line in the readline input will be successively available here as
99
- // `line`.
100
240
  if (line.indexOf(picoId) < 0) {
101
- continue; // not my pico
241
+ continue;
102
242
  }
103
243
  let entry;
104
244
  try {
@@ -106,11 +246,11 @@ async function getPicoLogs(filePath, picoId) {
106
246
  }
107
247
  catch (err) { }
108
248
  if (!entry || entry.picoId !== picoId) {
109
- continue; // not my pico
249
+ continue;
110
250
  }
111
251
  const time = new Date(entry.time);
112
252
  if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
113
- continue; // too old
253
+ continue;
114
254
  }
115
255
  const out = Object.assign(Object.assign({}, entry), { level: krl_stdlib_1.krlLogLevelCodeToHuman[entry.level] || `${entry.level}`, time: entry.time, txnId: entry.txnId });
116
256
  delete out.picoId;
@@ -13,6 +13,7 @@ const acg = require("./acg");
13
13
  const channelEligibility_1 = require("./channelEligibility");
14
14
  const errors_1 = require("./errors");
15
15
  const meshOAuth_1 = require("./meshOAuth");
16
+ const channelIdentityPolicy_1 = require("../channelIdentityPolicy");
16
17
  const OAUTH_CHANNEL_PREFIX = "oauth-channel";
17
18
  const OAUTH_TOKEN_PREFIX = "oauth-token";
18
19
  const DEFAULT_TOKEN_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
@@ -170,10 +171,13 @@ class OAuthService {
170
171
  async skyRequiresBearer(eci) {
171
172
  try {
172
173
  const channel = this.lookupChannelReadOnly(eci);
173
- if (channel.tags.includes("didcomm") &&
174
- channel.tags.includes("ingress")) {
174
+ if ((0, channelIdentityPolicy_1.isDidcommIngressChannel)(channel)) {
175
175
  return false;
176
176
  }
177
+ if ((0, channelIdentityPolicy_1.wildcardSkyRequireBearerEnabled)() &&
178
+ (0, channelIdentityPolicy_1.channelHasUnrestrictedAllow)(channel)) {
179
+ return true;
180
+ }
177
181
  if ((0, channelEligibility_1.isOAuthEligibleChannel)(channel)) {
178
182
  return true;
179
183
  }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePolicyCeilingFromJson = parsePolicyCeilingFromJson;
4
+ exports.parseGlobalEventDenyFromJson = parseGlobalEventDenyFromJson;
5
+ exports.parseGlobalQueryDenyFromJson = parseGlobalQueryDenyFromJson;
6
+ function isRecord(v) {
7
+ return v != null && typeof v === "object" && !Array.isArray(v);
8
+ }
9
+ function cleanEventPolicyFromJson(orig) {
10
+ if (!isRecord(orig) ||
11
+ !Array.isArray(orig.allow) ||
12
+ !Array.isArray(orig.deny)) {
13
+ throw new TypeError("eventPolicy expects { allow: EventPolicyRule[], deny: EventPolicyRule[] }");
14
+ }
15
+ const allow = [];
16
+ for (const item of orig.allow) {
17
+ if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
18
+ throw new TypeError("eventPolicy allow entries need domain and name strings");
19
+ }
20
+ allow.push({ domain: item.domain.trim(), name: item.name.trim() });
21
+ }
22
+ const deny = [];
23
+ for (const item of orig.deny) {
24
+ if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
25
+ throw new TypeError("eventPolicy deny entries need domain and name strings");
26
+ }
27
+ deny.push({ domain: item.domain.trim(), name: item.name.trim() });
28
+ }
29
+ return { allow, deny };
30
+ }
31
+ function cleanQueryPolicyFromJson(orig) {
32
+ if (!isRecord(orig) ||
33
+ !Array.isArray(orig.allow) ||
34
+ !Array.isArray(orig.deny)) {
35
+ throw new TypeError("queryPolicy expects { allow: QueryPolicyRule[], deny: QueryPolicyRule[] }");
36
+ }
37
+ const allow = [];
38
+ for (const item of orig.allow) {
39
+ if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
40
+ throw new TypeError("queryPolicy allow entries need rid and name strings");
41
+ }
42
+ allow.push({ rid: item.rid.trim(), name: item.name.trim() });
43
+ }
44
+ const deny = [];
45
+ for (const item of orig.deny) {
46
+ if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
47
+ throw new TypeError("queryPolicy deny entries need rid and name strings");
48
+ }
49
+ deny.push({ rid: item.rid.trim(), name: item.name.trim() });
50
+ }
51
+ return { allow, deny };
52
+ }
53
+ function parseEventRule(v) {
54
+ if (!isRecord(v))
55
+ return null;
56
+ if (typeof v.domain !== "string" || typeof v.name !== "string")
57
+ return null;
58
+ return { domain: v.domain, name: v.name };
59
+ }
60
+ function parseQueryRule(v) {
61
+ if (!isRecord(v))
62
+ return null;
63
+ if (typeof v.rid !== "string" || typeof v.name !== "string")
64
+ return null;
65
+ return { rid: v.rid, name: v.name };
66
+ }
67
+ function parsePolicyCeilingFromJson(val, fieldName) {
68
+ if (val === undefined || val === null) {
69
+ return undefined;
70
+ }
71
+ if (!isRecord(val) || !val.eventPolicy || !val.queryPolicy) {
72
+ throw new Error(`${fieldName} must be { eventPolicy: { allow, deny }, queryPolicy: { allow, deny } }`);
73
+ }
74
+ return {
75
+ eventPolicy: cleanEventPolicyFromJson(val.eventPolicy),
76
+ queryPolicy: cleanQueryPolicyFromJson(val.queryPolicy),
77
+ };
78
+ }
79
+ function parseGlobalEventDenyFromJson(val) {
80
+ if (val === undefined || val === null) {
81
+ return undefined;
82
+ }
83
+ if (!Array.isArray(val)) {
84
+ throw new Error("globalEventDeny must be an array of { domain, name } rules");
85
+ }
86
+ const rules = [];
87
+ for (const item of val) {
88
+ const rule = parseEventRule(item);
89
+ if (!rule) {
90
+ throw new Error("globalEventDeny: each entry needs domain and name strings");
91
+ }
92
+ rules.push(rule);
93
+ }
94
+ return rules;
95
+ }
96
+ function parseGlobalQueryDenyFromJson(val) {
97
+ if (val === undefined || val === null) {
98
+ return undefined;
99
+ }
100
+ if (!Array.isArray(val)) {
101
+ throw new Error("globalQueryDeny must be an array of { rid, name } rules");
102
+ }
103
+ const rules = [];
104
+ for (const item of val) {
105
+ const rule = parseQueryRule(item);
106
+ if (!rule) {
107
+ throw new Error("globalQueryDeny: each entry needs rid and name strings");
108
+ }
109
+ rules.push(rule);
110
+ }
111
+ return rules;
112
+ }
package/dist/runMcp.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runMcpCli = runMcpCli;
4
+ const engineConfig_1 = require("./engineConfig");
5
+ /** Dev MCP stdio entry (pico-engine mcp --stdio). */
6
+ async function runMcpCli(argv) {
7
+ const settings = (0, engineConfig_1.resolveEngineSettings)({});
8
+ (0, engineConfig_1.installEngineRuntimeSettings)(settings);
9
+ if (!process.env.PICO_ENGINE_BASE_URL) {
10
+ process.env.PICO_ENGINE_BASE_URL = settings.baseUrl;
11
+ }
12
+ if (!process.env.PICO_ENGINE_HOME) {
13
+ process.env.PICO_ENGINE_HOME = settings.home;
14
+ }
15
+ const args = argv.slice(1);
16
+ const stdio = args.includes("--stdio") || args.length === 0;
17
+ if (!stdio) {
18
+ console.error("Usage: pico-engine mcp --stdio");
19
+ console.error("");
20
+ console.error("Connects to a running local engine (PICO_ENGINE_BASE_URL).");
21
+ console.error("Requires localhost /c access or PICO_ENGINE_UI_ECI.");
22
+ process.exit(1);
23
+ }
24
+ // JS (not tsc): avoids pulling MCP SDK types into the main compile.
25
+ const { runDevMcpStdio } = require("../mcp/runStdio.js");
26
+ await runDevMcpStdio();
27
+ }