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.
- package/README.md +16 -9
- package/dist/RulesetRegistryLoaderFs.js +60 -6
- package/dist/auth/cookies.js +32 -0
- package/dist/auth/index.js +6 -1
- package/dist/channelIdentityPolicy.js +22 -0
- package/dist/cli.js +106 -69
- package/dist/engineConfig.js +291 -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 +84 -27
- package/dist/logging.js +156 -16
- package/dist/oauth/OAuthService.js +6 -2
- package/dist/policyConfigFromJson.js +112 -0
- package/dist/runMcp.js +27 -0
- package/dist/server.js +261 -24
- package/dist/stageKrl.js +26 -0
- package/dist/subtreeWrangler.js +180 -0
- package/dist/uiChannelPolicies.js +15 -0
- package/dist/xmluiRuntime.js +68 -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 +217 -94
- package/krl/io.picolabs.portable_subtree.krl +97 -0
- package/krl/io.picolabs.subscription.krl +180 -72
- package/krl/io.picolabs.wrangler.krl +313 -57
- package/krl/io.picolabs.xmlui.krl +295 -0
- 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 +24 -9
- package/public/.DS_Store +0 -0
- package/public/docs/_sidebar.md +3 -1
- package/public/docs/llms-full.txt +630 -0
- package/public/docs/llms.txt +38 -0
- package/public/docs/openapi.yaml +78 -0
- package/public/docs/pico-engine.md +239 -4
- package/public/docs/pico-overview.md +117 -0
- package/public/docs/pico-views-xmlui.md +5 -0
- package/public/docs/pico-views.md +140 -0
- package/public/docs/pico.md +3 -1
- package/public/docs/rulesets/README.md +26 -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 +27 -23
- package/public/xmlui/0.12.7.js +419 -0
- package/public/xmlui/pico-view-boot.js +153 -0
- package/src/RulesetRegistryLoaderFs.ts +66 -7
- package/src/auth/cookies.ts +34 -0
- package/src/auth/index.ts +7 -0
- package/src/channelIdentityPolicy.ts +29 -0
- package/src/cli.ts +70 -37
- package/src/engineConfig.ts +363 -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 +123 -31
- package/src/logging.ts +173 -18
- package/src/oauth/OAuthService.ts +11 -3
- package/src/policyConfigFromJson.ts +131 -0
- package/src/runMcp.ts +30 -0
- package/src/server.ts +328 -27
- package/src/stageKrl.ts +26 -0
- package/src/subtreeWrangler.ts +278 -0
- package/src/uiChannelPolicies.ts +15 -0
- package/src/xmluiRuntime.ts +66 -0
- package/krl/io.picolabs.did-o.krl +0 -349
package/README.md
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
An implementation of the [pico-engine](http://www.windley.com/archives/2016/03/rebuilding_krl.shtml) hosted on node.js
|
|
6
6
|
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g pico-engine
|
|
11
|
+
pico-engine
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Open `http://localhost:3000` — a root pico and UI channel are created on first run. Operator settings (port, data dir, policy ceiling) live in **`~/.config/pico-engine/config.json`**; copy [`config.example.json`](config.example.json). See [`public/docs/pico-engine.md`](public/docs/pico-engine.md).
|
|
15
|
+
|
|
16
|
+
**Agents (local dev):** [`CLAUDE.md`](../../CLAUDE.md) at repo root + `pico-engine mcp --stdio` (stdio MCP to the same engine). Machine-readable docs: [`public/docs/llms.txt`](public/docs/llms.txt).
|
|
17
|
+
|
|
7
18
|
## Getting Started
|
|
8
19
|
|
|
9
20
|
### Installing
|
|
@@ -123,6 +134,7 @@ The server is configured via some environment variables.
|
|
|
123
134
|
- `PICO_ENGINE_ALLOW_SELF_SIGNUP` - Set to `"true"` or `"1"` to allow open registration after bootstrap (default: off; bootstrap and invite still work)
|
|
124
135
|
- `PICO_ENGINE_ALLOW_LOCALHOST_C` - Set to `"0"` to require passkey session on `/c/*` even from localhost (default: allow localhost without session for in-engine HTTP loops). Full registry: repo `MEMORY.md` § Engine environment variables.
|
|
125
136
|
- `PICO_ENGINE_LOG_FILE` - Log file path. Set to `stdout`, `-`, or `0` for **stdout only** (recommended on Fargate + EFS; use CloudWatch for retention). Default: `$PICO_ENGINE_HOME/pico-engine.log`.
|
|
137
|
+
- `PICO_ENGINE_LOG_MIRROR` - When stdout-only: **`true`/`1`** (default) mirrors structured JSON to **`$PICO_ENGINE_HOME/pico-engine.log`** so **`ctx:logs`** and the Developer UI **Logging** tab work; set **`false`/`0`** to skip the mirror file (e.g. avoid EFS log churn). **Config:** `logMirror` in `config.json` (see `config.example.json`).
|
|
126
138
|
|
|
127
139
|
The `PORT` is the only value used in setting up the engine’s [nodejs http server](https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback). We only specify the `port` so it listens listens to all traffic on that port, it will not filter by host.
|
|
128
140
|
|
|
@@ -148,7 +160,7 @@ The CLI handles **SIGTERM** and **SIGINT** by closing the HTTP server and both d
|
|
|
148
160
|
```yaml
|
|
149
161
|
services:
|
|
150
162
|
pico-engine:
|
|
151
|
-
image: picolabs/pico-engine:1.
|
|
163
|
+
image: picolabs/pico-engine:1.8.0
|
|
152
164
|
ports:
|
|
153
165
|
- "3001:3000"
|
|
154
166
|
environment:
|
|
@@ -178,7 +190,8 @@ EFS + LevelDB is a common deployment pattern. LevelDB expects a **single writer*
|
|
|
178
190
|
| Container port | `3000` |
|
|
179
191
|
| `PICO_ENGINE_HOME` | `/var/pico-image` |
|
|
180
192
|
| `PICO_ENGINE_BASE_URL` | Public **HTTPS** origin users hit (e.g. `https://picos.example.com`) — required for passkeys and did:webvh |
|
|
181
|
-
| `PICO_ENGINE_LOG_FILE` | `stdout` — log to CloudWatch
|
|
193
|
+
| `PICO_ENGINE_LOG_FILE` | `stdout` — log to CloudWatch |
|
|
194
|
+
| `PICO_ENGINE_LOG_MIRROR` | `0` — do **not** mirror to `pico-engine.log` on EFS when using stdout-only; or set **`logMirror: false`** in config |
|
|
182
195
|
| EFS mount | `containerPath`: `/var/pico-image` |
|
|
183
196
|
| Container `stopTimeout` | `120` (seconds) |
|
|
184
197
|
|
|
@@ -350,13 +363,7 @@ Authorization: Bearer oat_…
|
|
|
350
363
|
|
|
351
364
|
### Building the UI
|
|
352
365
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
```sh
|
|
356
|
-
cd packages/pico-engine-ui && npm run build
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
That copies the bundle into `packages/pico-engine/public/`. Restart the engine and hard-refresh the browser.
|
|
366
|
+
Repo root `npm run build` includes the UI bundle (via `lerna run build`), copied into `packages/pico-engine/public/`. Restart the engine and hard-refresh the browser after a build.
|
|
360
367
|
|
|
361
368
|
For UI development, run the engine and `npm run dev` in `packages/pico-engine-ui` in separate terminals.
|
|
362
369
|
|
|
@@ -21,6 +21,7 @@ const bundledKrl_1 = require("./bundledKrl");
|
|
|
21
21
|
const levelDb_1 = require("./levelDb");
|
|
22
22
|
const krlCompiler = require("krl-compiler");
|
|
23
23
|
const krlCompilerVersion = require("krl-compiler/package.json").version;
|
|
24
|
+
const rulesetCompileGeneration = require("krl-compiler/src/rulesetCompileGeneration");
|
|
24
25
|
const charwise = require("charwise");
|
|
25
26
|
const safeJsonCodec = require("level-json-coerce-null");
|
|
26
27
|
function getUrlFilename(url) {
|
|
@@ -33,6 +34,9 @@ function getUrlFilename(url) {
|
|
|
33
34
|
catch (err) { }
|
|
34
35
|
return null;
|
|
35
36
|
}
|
|
37
|
+
function compileGenerationDir() {
|
|
38
|
+
return rulesetCompileGeneration().replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
39
|
+
}
|
|
36
40
|
async function createRulesetRegistryLoaderFs(engineHomeDir, log) {
|
|
37
41
|
const rulesetDir = path.resolve(engineHomeDir, "rulesets");
|
|
38
42
|
const db = await (0, levelDb_1.openClassicLevelWithRecovery)(path.resolve(engineHomeDir, "rulesets-db"), {
|
|
@@ -40,12 +44,25 @@ async function createRulesetRegistryLoaderFs(engineHomeDir, log) {
|
|
|
40
44
|
valueEncoding: safeJsonCodec,
|
|
41
45
|
}, log);
|
|
42
46
|
async function compileAndLoad(url, krl, hash) {
|
|
43
|
-
const jsFile = path.resolve(rulesetDir,
|
|
47
|
+
const jsFile = path.resolve(rulesetDir, compileGenerationDir(), hash.substr(0, 2), hash.substr(2, 2), hash + ".js");
|
|
44
48
|
let compileWarnings = [];
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
let needCompile = !(await fsExist(jsFile));
|
|
50
|
+
if (!needCompile) {
|
|
51
|
+
const cached = requireRulesetModule(jsFile);
|
|
52
|
+
if (cached) {
|
|
53
|
+
const compileGeneration = rulesetCompileGeneration();
|
|
54
|
+
return {
|
|
55
|
+
ruleset: cached,
|
|
56
|
+
compiler: {
|
|
57
|
+
version: krlCompilerVersion,
|
|
58
|
+
warnings: compileWarnings,
|
|
59
|
+
compileGeneration,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
needCompile = true;
|
|
47
64
|
}
|
|
48
|
-
|
|
65
|
+
if (needCompile) {
|
|
49
66
|
const out = krlCompiler(krl, {
|
|
50
67
|
parser_options: {
|
|
51
68
|
filename: getUrlFilename(url),
|
|
@@ -61,14 +78,25 @@ async function createRulesetRegistryLoaderFs(engineHomeDir, log) {
|
|
|
61
78
|
fs.writeFile(jsFile, out.code, { encoding: "utf8" }, (err) => err ? reject(err) : resolve(undefined));
|
|
62
79
|
});
|
|
63
80
|
}
|
|
64
|
-
const ruleset =
|
|
81
|
+
const ruleset = requireRulesetModule(jsFile);
|
|
82
|
+
if (!ruleset) {
|
|
83
|
+
throw new Error(`Compiled ruleset is missing init (corrupt cache file). Delete ${jsFile} and flush again: ${url}`);
|
|
84
|
+
}
|
|
85
|
+
const compileGeneration = rulesetCompileGeneration();
|
|
65
86
|
return {
|
|
66
87
|
ruleset,
|
|
67
|
-
compiler: {
|
|
88
|
+
compiler: {
|
|
89
|
+
version: krlCompilerVersion,
|
|
90
|
+
warnings: compileWarnings,
|
|
91
|
+
compileGeneration,
|
|
92
|
+
},
|
|
68
93
|
};
|
|
69
94
|
}
|
|
70
95
|
const loader = {
|
|
71
96
|
fetchKrl,
|
|
97
|
+
getCompileGeneration() {
|
|
98
|
+
return rulesetCompileGeneration();
|
|
99
|
+
},
|
|
72
100
|
async save(_a) {
|
|
73
101
|
var { ruleset } = _a, rest = __rest(_a, ["ruleset"]);
|
|
74
102
|
let toWrite = rest;
|
|
@@ -116,6 +144,32 @@ async function fetchKrl(url) {
|
|
|
116
144
|
const krl = await res.text();
|
|
117
145
|
return krl;
|
|
118
146
|
}
|
|
147
|
+
function requireRulesetModule(jsFile) {
|
|
148
|
+
try {
|
|
149
|
+
delete require.cache[require.resolve(jsFile)];
|
|
150
|
+
}
|
|
151
|
+
catch (_a) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
let ruleset;
|
|
155
|
+
try {
|
|
156
|
+
ruleset = require(jsFile);
|
|
157
|
+
}
|
|
158
|
+
catch (_b) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
if (typeof (ruleset === null || ruleset === void 0 ? void 0 : ruleset.init) !== "function") {
|
|
162
|
+
try {
|
|
163
|
+
delete require.cache[require.resolve(jsFile)];
|
|
164
|
+
fs.unlinkSync(jsFile);
|
|
165
|
+
}
|
|
166
|
+
catch (_c) {
|
|
167
|
+
/* best effort */
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return ruleset;
|
|
172
|
+
}
|
|
119
173
|
function fsExist(filePath) {
|
|
120
174
|
return new Promise((resolve, reject) => {
|
|
121
175
|
fs.stat(filePath, function (err, stats) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CEREMONY_COOKIE = exports.DEFAULT_SESSION_COOKIE = void 0;
|
|
4
|
+
exports.authCookieNames = authCookieNames;
|
|
5
|
+
exports.sessionCookieHeader = sessionCookieHeader;
|
|
6
|
+
exports.DEFAULT_SESSION_COOKIE = "pico-session";
|
|
7
|
+
exports.DEFAULT_CEREMONY_COOKIE = "pico-ceremony";
|
|
8
|
+
/** Session/ceremony cookie names scoped by port on local dev hosts. */
|
|
9
|
+
function authCookieNames(origin) {
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(origin);
|
|
12
|
+
const local = url.hostname === "localhost" ||
|
|
13
|
+
url.hostname === "127.0.0.1" ||
|
|
14
|
+
url.hostname.endsWith(".localhost");
|
|
15
|
+
if (local && url.port) {
|
|
16
|
+
return {
|
|
17
|
+
session: `${exports.DEFAULT_SESSION_COOKIE}-${url.port}`,
|
|
18
|
+
ceremony: `${exports.DEFAULT_CEREMONY_COOKIE}-${url.port}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (_e) {
|
|
23
|
+
// fall through
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
session: exports.DEFAULT_SESSION_COOKIE,
|
|
27
|
+
ceremony: exports.DEFAULT_CEREMONY_COOKIE,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function sessionCookieHeader(origin, token) {
|
|
31
|
+
return `${authCookieNames(origin).session}=${token}`;
|
|
32
|
+
}
|
package/dist/auth/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeWebAuthnAdapter = exports.AuthError = exports.AuthService = void 0;
|
|
3
|
+
exports.DEFAULT_CEREMONY_COOKIE = exports.DEFAULT_SESSION_COOKIE = exports.sessionCookieHeader = exports.authCookieNames = exports.makeWebAuthnAdapter = exports.AuthError = exports.AuthService = void 0;
|
|
4
4
|
var AuthService_1 = require("./AuthService");
|
|
5
5
|
Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return AuthService_1.AuthService; } });
|
|
6
6
|
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return AuthService_1.AuthError; } });
|
|
7
7
|
var webauthn_1 = require("./webauthn");
|
|
8
8
|
Object.defineProperty(exports, "makeWebAuthnAdapter", { enumerable: true, get: function () { return webauthn_1.makeWebAuthnAdapter; } });
|
|
9
|
+
var cookies_1 = require("./cookies");
|
|
10
|
+
Object.defineProperty(exports, "authCookieNames", { enumerable: true, get: function () { return cookies_1.authCookieNames; } });
|
|
11
|
+
Object.defineProperty(exports, "sessionCookieHeader", { enumerable: true, get: function () { return cookies_1.sessionCookieHeader; } });
|
|
12
|
+
Object.defineProperty(exports, "DEFAULT_SESSION_COOKIE", { enumerable: true, get: function () { return cookies_1.DEFAULT_SESSION_COOKIE; } });
|
|
13
|
+
Object.defineProperty(exports, "DEFAULT_CEREMONY_COOKIE", { enumerable: true, get: function () { return cookies_1.DEFAULT_CEREMONY_COOKIE; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wildcardSkyRequireBearerEnabled = wildcardSkyRequireBearerEnabled;
|
|
4
|
+
exports.channelHasUnrestrictedAllow = channelHasUnrestrictedAllow;
|
|
5
|
+
exports.isDidcommIngressChannel = isDidcommIngressChannel;
|
|
6
|
+
const pico_framework_1 = require("pico-framework");
|
|
7
|
+
const engineConfig_1 = require("./engineConfig");
|
|
8
|
+
/** See {@link EngineSettings.wildcardSkyRequireBearer} (config file or env). */
|
|
9
|
+
function wildcardSkyRequireBearerEnabled() {
|
|
10
|
+
return (0, engineConfig_1.getEngineRuntimeSettings)().wildcardSkyRequireBearer;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* True when the channel grants unrestricted events or queries (*.* allow rules).
|
|
14
|
+
* Such channels require an authenticated HTTP caller (OAuth bearer or /c/* session).
|
|
15
|
+
*/
|
|
16
|
+
function channelHasUnrestrictedAllow(channel) {
|
|
17
|
+
return ((0, pico_framework_1.hasUnrestrictedEventAllow)(channel.eventPolicy) ||
|
|
18
|
+
(0, pico_framework_1.hasUnrestrictedQueryAllow)(channel.queryPolicy));
|
|
19
|
+
}
|
|
20
|
+
function isDidcommIngressChannel(channel) {
|
|
21
|
+
return (channel.tags.includes("didcomm") && channel.tags.includes("ingress"));
|
|
22
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -1,83 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("./index");
|
|
4
|
+
const engineConfig_1 = require("./engineConfig");
|
|
4
5
|
const version = require("../package.json").version;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
let argv;
|
|
7
|
+
try {
|
|
8
|
+
argv = (0, engineConfig_1.applyConfigCliArgs)(process.argv.slice(2));
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error(err instanceof Error ? err.message : err);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
if (argv[0] === "mcp") {
|
|
15
|
+
Promise.resolve().then(() => require("./runMcp")).then(({ runMcpCli }) => runMcpCli(argv))
|
|
16
|
+
.catch((err) => {
|
|
17
|
+
console.error(err);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else if (argv[0] === "config" && argv[1] === "path") {
|
|
22
|
+
const { resolveEngineConfigFilePath, defaultEngineConfigFilePath } = require("./engineConfig");
|
|
23
|
+
const target = resolveEngineConfigFilePath();
|
|
24
|
+
console.log(target);
|
|
25
|
+
if (target === defaultEngineConfigFilePath()) {
|
|
26
|
+
console.error("(default; copy packages/pico-engine/config.example.json here to customize)");
|
|
27
|
+
}
|
|
13
28
|
process.exit(0);
|
|
14
29
|
}
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
else {
|
|
31
|
+
startPicoEngineCli();
|
|
32
|
+
}
|
|
33
|
+
function startPicoEngineCli() {
|
|
34
|
+
const args = require("minimist")(argv, {
|
|
35
|
+
boolean: ["help", "version"],
|
|
36
|
+
alias: {
|
|
37
|
+
help: "h",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (args.version) {
|
|
41
|
+
console.log(version);
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
if (args.help) {
|
|
45
|
+
console.log(`
|
|
17
46
|
USAGE
|
|
18
47
|
|
|
19
|
-
pico-engine [--version] [--help|-h]
|
|
48
|
+
pico-engine [--config|-c <path>] [--version] [--help|-h]
|
|
49
|
+
pico-engine [--config|-c <path>] config path
|
|
50
|
+
pico-engine [--config|-c <path>] mcp --stdio
|
|
51
|
+
|
|
52
|
+
Multiple engines on one machine: use a separate config file per process (unique
|
|
53
|
+
home, port, baseUrl). Examples: packages/pico-engine/config.instances.example/
|
|
54
|
+
and docker/config/ for compose.
|
|
55
|
+
|
|
56
|
+
Configuration (preferred):
|
|
57
|
+
|
|
58
|
+
~/.config/pico-engine/config.json
|
|
59
|
+
(or --config / PICO_ENGINE_CONFIG to another file path)
|
|
20
60
|
|
|
21
|
-
|
|
61
|
+
See packages/pico-engine/config.example.json (and config.policy-ceiling.example.json for 1.8 policy fields).
|
|
62
|
+
Precedence: defaults → environment variables → config file → tests/API overrides.
|
|
63
|
+
(Config file wins over PORT and PICO_ENGINE_HOME when both are set; env fills gaps the file omits.)
|
|
22
64
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
65
|
+
Environment (optional; Docker/CI when not set in config file):
|
|
66
|
+
|
|
67
|
+
PORT - HTTP listen port
|
|
68
|
+
PICO_ENGINE_CONFIG - Path to config JSON (default ~/.config/pico-engine/config.json)
|
|
69
|
+
PICO_ENGINE_HOME - Data directory (DB, ruleset cache); overridden by config "home" when present
|
|
70
|
+
PICO_ENGINE_BASE_URL - Public URL (WebAuthn, did:webvh)
|
|
71
|
+
PICO_ENGINE_RP_ID / PICO_ENGINE_ORIGIN - WebAuthn (or use webauthn block in config file)
|
|
72
|
+
PICO_ENGINE_ALLOW_SELF_SIGNUP - "true"/"1" or "false"/"0"
|
|
73
|
+
PICO_ENGINE_ALLOW_LOCALHOST_C - "0" disables localhost /c/* bypass (see config allowLocalhostChannelBypass)
|
|
74
|
+
PICO_ENGINE_WILDCARD_SKY_REQUIRE_BEARER - "1" enables wildcard /sky/* bearer requirement
|
|
75
|
+
PICO_ENGINE_LOG_FILE - Log path, or stdout/- / 0 for console-only
|
|
76
|
+
PICO_ENGINE_LOG_MIRROR - "true"/"1" or "false"/"0" (mirror JSON lines to \$PICO_ENGINE_HOME/pico-engine.log when stdout-only; default on)
|
|
77
|
+
PICO_ENGINE_LOG_RING - how many recent transactions per pico the Logging tab keeps in memory (default 200; cleared on restart)
|
|
30
78
|
`);
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const env = {};
|
|
34
|
-
if (process.env.PORT) {
|
|
35
|
-
const port = parseInt(process.env.PORT, 10);
|
|
36
|
-
if (port > 0) {
|
|
37
|
-
env.port = port;
|
|
79
|
+
process.exit(0);
|
|
38
80
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const allowSelfSignupEnv = process.env.PICO_ENGINE_ALLOW_SELF_SIGNUP;
|
|
49
|
-
if (allowSelfSignupEnv === "true" || allowSelfSignupEnv === "1") {
|
|
50
|
-
env.allowSelfSignup = true;
|
|
51
|
-
}
|
|
52
|
-
else if (allowSelfSignupEnv === "false" || allowSelfSignupEnv === "0") {
|
|
53
|
-
env.allowSelfSignup = false;
|
|
54
|
-
}
|
|
55
|
-
function installGracefulShutdown(engine) {
|
|
56
|
-
let shuttingDown = false;
|
|
57
|
-
const onSignal = (signal) => {
|
|
58
|
-
if (shuttingDown) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
shuttingDown = true;
|
|
62
|
-
console.log(`Received ${signal}; shutting down`);
|
|
63
|
-
engine
|
|
64
|
-
.shutdown()
|
|
65
|
-
.then(() => process.exit(0))
|
|
66
|
-
.catch((err) => {
|
|
67
|
-
console.error("Shutdown failed.");
|
|
68
|
-
console.error(err);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
});
|
|
81
|
+
const settings = (0, engineConfig_1.resolveEngineSettings)({});
|
|
82
|
+
const env = {
|
|
83
|
+
home: settings.home,
|
|
84
|
+
port: settings.port,
|
|
85
|
+
base_url: settings.baseUrl,
|
|
86
|
+
rpID: settings.rpID,
|
|
87
|
+
rpName: settings.rpName,
|
|
88
|
+
origin: settings.origin,
|
|
89
|
+
allowSelfSignup: settings.allowSelfSignup,
|
|
71
90
|
};
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
function installGracefulShutdown(engine) {
|
|
92
|
+
let shuttingDown = false;
|
|
93
|
+
const onSignal = (signal) => {
|
|
94
|
+
if (shuttingDown) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
shuttingDown = true;
|
|
98
|
+
console.log(`Received ${signal}; shutting down`);
|
|
99
|
+
engine
|
|
100
|
+
.shutdown()
|
|
101
|
+
.then(() => process.exit(0))
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
console.error("Shutdown failed.");
|
|
104
|
+
console.error(err);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
process.on("SIGTERM", onSignal);
|
|
109
|
+
process.on("SIGINT", onSignal);
|
|
110
|
+
}
|
|
111
|
+
(0, index_1.startEngine)(env)
|
|
112
|
+
.then((engine) => {
|
|
113
|
+
installGracefulShutdown(engine);
|
|
114
|
+
})
|
|
115
|
+
.catch((err) => {
|
|
116
|
+
console.error("Failed to start engine.");
|
|
117
|
+
console.error(err);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
74
120
|
}
|
|
75
|
-
(0, index_1.startEngine)(env)
|
|
76
|
-
.then((engine) => {
|
|
77
|
-
installGracefulShutdown(engine);
|
|
78
|
-
})
|
|
79
|
-
.catch((err) => {
|
|
80
|
-
console.error("Failed to start engine.");
|
|
81
|
-
console.error(err);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
});
|