pico-engine 1.8.0 → 1.9.1
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 +5 -3
- package/dist/RulesetRegistryLoaderFs.js +46 -4
- package/dist/cli.js +3 -1
- package/dist/engineConfig.js +11 -0
- package/dist/index.js +2 -5
- package/dist/logging.js +148 -4
- package/dist/server.js +206 -1
- package/dist/stageKrl.js +26 -0
- package/dist/xmluiRuntime.js +68 -0
- package/krl/io.picolabs.pico-engine-ui.krl +14 -77
- package/krl/io.picolabs.wrangler.krl +28 -5
- package/krl/io.picolabs.xmlui.krl +305 -0
- package/mcp/devResources.js +17 -7
- package/mcp/docs/CLAUDE.md +85 -0
- package/{public → mcp}/docs/pico-engine.md +15 -11
- package/package.json +11 -7
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +27 -25
- package/public/xmlui/0.12.7.js +419 -0
- package/public/xmlui/pico-view-boot.js +153 -0
- package/src/RulesetRegistryLoaderFs.ts +48 -4
- package/src/cli.ts +3 -1
- package/src/engineConfig.ts +18 -0
- package/src/index.ts +4 -6
- package/src/logging.ts +165 -4
- package/src/server.ts +250 -2
- package/src/stageKrl.ts +26 -0
- package/src/xmluiRuntime.ts +66 -0
- package/public/docs/README.md +0 -9
- package/public/docs/_media/logo.png +0 -0
- package/public/docs/_sidebar.md +0 -6
- package/public/docs/contributing.md +0 -64
- package/public/docs/favicon.ico +0 -0
- package/public/docs/index.html +0 -29
- package/public/docs/krl/README.md +0 -3
- package/public/docs/krl/_sidebar.md +0 -10
- package/public/docs/krl/discovery.md +0 -144
- package/public/docs/krl/modules/ctx.md +0 -151
- package/public/docs/krl/modules/event.md +0 -70
- package/public/docs/krl/modules/http.md +0 -42
- package/public/docs/krl/modules/math.md +0 -5
- package/public/docs/krl/modules/schedule.md +0 -5
- package/public/docs/krl/modules.md +0 -11
- package/public/docs/krl/rulesets.md +0 -81
- package/public/docs/krl/stdlib.md +0 -3
- package/public/docs/llms-full.txt +0 -479
- package/public/docs/llms.txt +0 -37
- package/public/docs/openapi.yaml +0 -78
- package/public/docs/pico.md +0 -5
- package/public/docs/rulesets/README.md +0 -25
- package/public/docs/rulesets/io.picolabs.oauth.md +0 -71
- package/public/docs/rulesets/io.picolabs.pds.md +0 -327
- package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +0 -65
- package/public/docs/rulesets/io.picolabs.portable_subtree.md +0 -94
- package/public/docs/rulesets/io.picolabs.subscription.md +0 -398
- package/public/docs/rulesets/io.picolabs.wrangler.md +0 -471
- /package/{public → mcp}/docs/pico-overview.md +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XMLUI_EMPTY_CODE_BEHIND = exports.XMLUI_RUNTIME_PUBLIC_PATH = exports.XMLUI_RUNTIME_VERSION = void 0;
|
|
4
|
+
exports.isXmluiCodeBehindPath = isXmluiCodeBehindPath;
|
|
5
|
+
exports.viewComponentFileName = viewComponentFileName;
|
|
6
|
+
exports.parseComponentXmluiPath = parseComponentXmluiPath;
|
|
7
|
+
exports.isXmluiSpaClientRoute = isXmluiSpaClientRoute;
|
|
8
|
+
exports.viewQueryNameForComponent = viewQueryNameForComponent;
|
|
9
|
+
exports.contentTypeForUiPath = contentTypeForUiPath;
|
|
10
|
+
/** Pinned XMLUI standalone runtime shipped under `public/xmlui/`. */
|
|
11
|
+
exports.XMLUI_RUNTIME_VERSION = "0.12.7";
|
|
12
|
+
exports.XMLUI_RUNTIME_PUBLIC_PATH = `/xmlui/${exports.XMLUI_RUNTIME_VERSION}.js`;
|
|
13
|
+
/** XMLUI standalone always requests Main.xmlui.xs (and per-component .xmlui.xs). */
|
|
14
|
+
exports.XMLUI_EMPTY_CODE_BEHIND = "var __pico_xmlui_codebehind = 0;\n";
|
|
15
|
+
function isXmluiCodeBehindPath(relPath) {
|
|
16
|
+
if (relPath === "Main.xmlui.xs")
|
|
17
|
+
return true;
|
|
18
|
+
return /^components\/.+\.xmlui\.xs$/i.test(relPath);
|
|
19
|
+
}
|
|
20
|
+
/** Map a shared function name to the XMLUI component file name (Hello, ColorView, …). */
|
|
21
|
+
function viewComponentFileName(fnName) {
|
|
22
|
+
if (!fnName)
|
|
23
|
+
return fnName;
|
|
24
|
+
return fnName.charAt(0).toUpperCase() + fnName.slice(1);
|
|
25
|
+
}
|
|
26
|
+
function parseComponentXmluiPath(relPath) {
|
|
27
|
+
const m = /^components\/(.+)\.xmlui$/i.exec(relPath);
|
|
28
|
+
return m ? m[1] : null;
|
|
29
|
+
}
|
|
30
|
+
/** Client route segment (e.g. list, contact/abc) — not a static XMLUI asset. */
|
|
31
|
+
function isXmluiSpaClientRoute(relPath) {
|
|
32
|
+
const rel = relPath.replace(/^\/+/, "");
|
|
33
|
+
if (!rel || rel === "index.html")
|
|
34
|
+
return false;
|
|
35
|
+
if (rel === "Main.xmlui" || rel === "config.json")
|
|
36
|
+
return false;
|
|
37
|
+
if (isXmluiCodeBehindPath(rel))
|
|
38
|
+
return false;
|
|
39
|
+
if (parseComponentXmluiPath(rel))
|
|
40
|
+
return false;
|
|
41
|
+
const lastSegment = rel.split("/").pop() || "";
|
|
42
|
+
if (lastSegment.includes("."))
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function viewQueryNameForComponent(queries, appRid, componentName) {
|
|
47
|
+
var _a;
|
|
48
|
+
if (!(queries === null || queries === void 0 ? void 0 : queries.length))
|
|
49
|
+
return null;
|
|
50
|
+
const hit = queries.find((q) => q.rid === appRid &&
|
|
51
|
+
q.view != null &&
|
|
52
|
+
viewComponentFileName(q.name) === componentName);
|
|
53
|
+
return (_a = hit === null || hit === void 0 ? void 0 : hit.name) !== null && _a !== void 0 ? _a : null;
|
|
54
|
+
}
|
|
55
|
+
function contentTypeForUiPath(filePath) {
|
|
56
|
+
const lower = filePath.toLowerCase();
|
|
57
|
+
if (lower.endsWith(".html"))
|
|
58
|
+
return "text/html; charset=utf-8";
|
|
59
|
+
if (lower.endsWith(".xmlui"))
|
|
60
|
+
return "application/xml; charset=utf-8";
|
|
61
|
+
if (lower.endsWith(".xs"))
|
|
62
|
+
return "text/plain; charset=utf-8";
|
|
63
|
+
if (lower.endsWith(".json"))
|
|
64
|
+
return "application/json; charset=utf-8";
|
|
65
|
+
if (lower.endsWith(".css"))
|
|
66
|
+
return "text/css; charset=utf-8";
|
|
67
|
+
return "text/plain; charset=utf-8";
|
|
68
|
+
}
|
|
@@ -98,83 +98,13 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Recent activity on this pico,
|
|
102
|
-
*
|
|
103
|
-
* The
|
|
104
|
-
* @returns Array "[ { txnId,
|
|
101
|
+
* Recent activity on this pico, newest first. Each transaction is a list of
|
|
102
|
+
* steps (`in`, `rule`, `raise`, `klog`, `log`, `error`, `done`) assembled
|
|
103
|
+
* from the engine log. The Logging tab hides engine rulesets in the browser.
|
|
104
|
+
* @returns Array "[ { txnId, kind, start, durationMs, outcome, steps } ]"
|
|
105
105
|
*/
|
|
106
106
|
logs = function(){
|
|
107
|
-
|
|
108
|
-
entry.delete("time")
|
|
109
|
-
.delete("level")
|
|
110
|
-
.delete("msg")
|
|
111
|
-
.delete("txnId")
|
|
112
|
-
.encode()
|
|
113
|
-
}
|
|
114
|
-
logQuery = function(query){
|
|
115
|
-
args = query.get("args").delete("_headers") || {}
|
|
116
|
-
<<QUERY #{query.get("eci")} #{query.get("rid")}/#{query.get("name")} #{args.encode()}>>
|
|
117
|
-
}
|
|
118
|
-
logEvent = function(event){
|
|
119
|
-
attrs = event.get(["data","attrs"]).delete("_headers") || {}
|
|
120
|
-
<<EVENT #{event.get("eci")} #{event.get("domain")}:#{event.get("name")} #{attrs.encode()}>>
|
|
121
|
-
}
|
|
122
|
-
logFirst = function(entry){
|
|
123
|
-
txn = entry.get("txn")
|
|
124
|
-
kind = txn.get("kind")
|
|
125
|
-
kind == "query" => logQuery(txn.get("query")) |
|
|
126
|
-
kind == "event" => logEvent(txn.get("event")) |
|
|
127
|
-
logOther(entry)
|
|
128
|
-
}
|
|
129
|
-
logDetails = function(entry){
|
|
130
|
-
msg = entry.get("msg")
|
|
131
|
-
msg == "txnQueued" => logFirst(entry) |
|
|
132
|
-
msg == "event added to schedule" => entry.get("event").encode() |
|
|
133
|
-
msg == "rule selected" => <<#{entry.get("rid")} : #{entry.get("rule_name")}>> |
|
|
134
|
-
entry.get("level") == "klog" => entry.get("val").encode() || "null" |
|
|
135
|
-
msg.match(re#fired$#) => "" |
|
|
136
|
-
logOther(entry)
|
|
137
|
-
}
|
|
138
|
-
episode_line = function(x,i){
|
|
139
|
-
level = x{"level"}.uc();
|
|
140
|
-
x{"time"}.split("T")[1] +
|
|
141
|
-
" [" +
|
|
142
|
-
level +
|
|
143
|
-
"] "+
|
|
144
|
-
x{"msg"} +
|
|
145
|
-
" " +
|
|
146
|
-
logDetails(x)
|
|
147
|
-
};
|
|
148
|
-
entryMap = function(a,e){
|
|
149
|
-
// a.head() is array of entries; a[1] is whether last entry is eats
|
|
150
|
-
// a[2] is domain:name of the event
|
|
151
|
-
eats = e{"msg"} == "event added to schedule"
|
|
152
|
-
event_dt = eats => e{["event","domain"]} + ":" + e{["event","name"]}
|
|
153
|
-
| ""
|
|
154
|
-
a[1] && eats && a[2]==event_dt
|
|
155
|
-
=> [a.head(),true,event_dt] // omit a duplicate eats
|
|
156
|
-
| [a.head().append(episode_line(e)),eats,event_dt]
|
|
157
|
-
}
|
|
158
|
-
episodes = ctx:logs()
|
|
159
|
-
.collect(function(e){e.get("txnId")})
|
|
160
|
-
episodes.keys()
|
|
161
|
-
.map(function(k){
|
|
162
|
-
episode = episodes.get(k)
|
|
163
|
-
entries = episode
|
|
164
|
-
.reduce(entryMap,[[],false,""]).head()
|
|
165
|
-
return {
|
|
166
|
-
"txnId": k,
|
|
167
|
-
"time": episode.head().get("time"),
|
|
168
|
-
"header": entries.head().split(re# txnQueued #)[1],
|
|
169
|
-
"entries": entries,
|
|
170
|
-
}
|
|
171
|
-
})
|
|
172
|
-
.filter(function(g){
|
|
173
|
-
g{"header"}.match(re#^QUERY .*io.picolabs.pico-engine-ui/#) => false |
|
|
174
|
-
g{"header"}.match(re#^QUERY .*io.picolabs.subscription/established#) => false |
|
|
175
|
-
true
|
|
176
|
-
})
|
|
177
|
-
.reverse()
|
|
107
|
+
ctx:logTransactions()
|
|
178
108
|
}
|
|
179
109
|
uiChannelEventPolicy = function() {
|
|
180
110
|
{
|
|
@@ -291,12 +221,15 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
291
221
|
pre {
|
|
292
222
|
uiEci = event:attr("uiEci")
|
|
293
223
|
familyEci = event:attr("eci")
|
|
224
|
+
requestedColor = event:attrs{"backgroundColor"}
|
|
294
225
|
childIndex = childLayoutIndex(familyEci)
|
|
295
226
|
gridCol = childIndex % 4
|
|
296
227
|
gridRow = (childIndex - childIndex % 4) / 4
|
|
297
228
|
layoutX = ent:x.defaultsTo(100) + 48 + gridCol * 143
|
|
298
229
|
layoutY = ent:y.defaultsTo(100) + 48 + gridRow * 108
|
|
299
|
-
layoutColor =
|
|
230
|
+
layoutColor = requestedColor.match(re#^\#[0-9A-F]{6}$#i)
|
|
231
|
+
=> requestedColor
|
|
232
|
+
| childPalette[childIndex % childPalette.length]
|
|
300
233
|
}
|
|
301
234
|
if uiEci && familyEci then
|
|
302
235
|
ctx:event(
|
|
@@ -326,7 +259,9 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
326
259
|
gridRow = (childIndex - childIndex % 4) / 4
|
|
327
260
|
layoutX = ent:x.defaultsTo(100) + 48 + gridCol * 143
|
|
328
261
|
layoutY = ent:y.defaultsTo(100) + 48 + gridRow * 108
|
|
329
|
-
|
|
262
|
+
childBox = ctx:query(uiEci, ctx:rid, "box")
|
|
263
|
+
layoutColor = childBox{"backgroundColor"}
|
|
264
|
+
.defaultsTo(childPalette[childIndex % childPalette.length])
|
|
330
265
|
}
|
|
331
266
|
if uiEci && ctx:query(uiEci, ctx:rid, "needsStartupLayout") then
|
|
332
267
|
ctx:event(
|
|
@@ -453,6 +388,8 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
453
388
|
// url from pico(){"rulesets"}, so it is exactly the installed ruleset's url.
|
|
454
389
|
// (Previously the rid was parsed out of the url, which never matched —
|
|
455
390
|
// substr(0, 11) is "io.picolabs" without the dot — and truncated dotted rids.)
|
|
391
|
+
// install_ruleset_absolutely raises ruleset_installed only for a new rid, so
|
|
392
|
+
// this reinstall does not look like a first install.
|
|
456
393
|
rule reinstall_after_flush {
|
|
457
394
|
select when engine_ui flush_succeeded
|
|
458
395
|
pre {
|
|
@@ -160,6 +160,19 @@ ruleset io.picolabs.wrangler {
|
|
|
160
160
|
* @example "child's name" { "eci": "<child family eci>", "mod": "io.picolabs.wrangler", "func": "name" }
|
|
161
161
|
* @example "another engine" { "eci": "<eci>", "mod": "<rid>", "func": "<function>", "params": {}, "_host": "https://other.example" }
|
|
162
162
|
*/
|
|
163
|
+
/**
|
|
164
|
+
* Query through a channel on this pico (policy applies). Used by view file()
|
|
165
|
+
* to render components on the same channel as the browser request.
|
|
166
|
+
* @param eci String "channel on this pico"
|
|
167
|
+
* @param rid String "ruleset id"
|
|
168
|
+
* @param name String "shared function"
|
|
169
|
+
* @param params Map "query arguments"
|
|
170
|
+
* @returns Any
|
|
171
|
+
*/
|
|
172
|
+
channelQuery = function(eci, rid, name, params) {
|
|
173
|
+
ctx:query(eci, rid, name, params.defaultsTo({}))
|
|
174
|
+
}
|
|
175
|
+
|
|
163
176
|
picoQuery = function(eci, mod, func, params,_host,_path,_root_url) {
|
|
164
177
|
isDid = eci.match(re#^did:#)
|
|
165
178
|
thisPico = ctx:channels.any(function(c){c{"id"}==eci})
|
|
@@ -523,6 +536,13 @@ ruleset io.picolabs.wrangler {
|
|
|
523
536
|
.filter(function(c){c["tags"].sort().join(",") == "engine,ui"})
|
|
524
537
|
.map(function(c){c["id"]})
|
|
525
538
|
.head()
|
|
539
|
+
childBoxAttrs = {
|
|
540
|
+
"name": name,
|
|
541
|
+
"parentUiEci": parentUiEci
|
|
542
|
+
}
|
|
543
|
+
boxAttrs = attrs{"backgroundColor"}.match(re#^\#[0-9A-F]{6}$#i)
|
|
544
|
+
=> childBoxAttrs.put("backgroundColor", attrs{"backgroundColor"})
|
|
545
|
+
| childBoxAttrs
|
|
526
546
|
every {
|
|
527
547
|
ctx:newPico(
|
|
528
548
|
rulesets=[
|
|
@@ -548,10 +568,7 @@ ruleset io.picolabs.wrangler {
|
|
|
548
568
|
eci=newUiECI,
|
|
549
569
|
domain="engine_ui",
|
|
550
570
|
name="box",
|
|
551
|
-
attrs=
|
|
552
|
-
"name": name,
|
|
553
|
-
"parentUiEci": parentUiEci
|
|
554
|
-
}
|
|
571
|
+
attrs=boxAttrs
|
|
555
572
|
)
|
|
556
573
|
}
|
|
557
574
|
return {"eci": newEci, "uiEci": newUiECI}
|
|
@@ -608,7 +625,9 @@ ruleset io.picolabs.wrangler {
|
|
|
608
625
|
/**
|
|
609
626
|
* Install (or reinstall) a ruleset from a URL on this pico. The URL is fetched
|
|
610
627
|
* and compiled first, so this also picks up a new version. Raises
|
|
611
|
-
* wrangler:ruleset_installed with the installed rid
|
|
628
|
+
* wrangler:ruleset_installed with the installed rid only when that rid was
|
|
629
|
+
* not already on this pico. A flush reinstalls the source and does not
|
|
630
|
+
* raise it.
|
|
612
631
|
* @attr url String "URL of the .krl file"
|
|
613
632
|
* @attr config Map optional "configuration for the installed ruleset"
|
|
614
633
|
* @example "from a URL" { "url": "https://example.com/krl/<rid>.krl" }
|
|
@@ -625,6 +644,9 @@ ruleset io.picolabs.wrangler {
|
|
|
625
644
|
validate_errors = validation{"errors"}
|
|
626
645
|
validate_warnings = validation{"warnings"}
|
|
627
646
|
validate_rid = validation{"rid"}
|
|
647
|
+
already_installed = ctx:rulesets.filter(function(rs) {
|
|
648
|
+
rs{"rid"} == validate_rid
|
|
649
|
+
}).length() > 0
|
|
628
650
|
}
|
|
629
651
|
if ok then every {
|
|
630
652
|
ctx:flush(url=url)
|
|
@@ -633,6 +655,7 @@ ruleset io.picolabs.wrangler {
|
|
|
633
655
|
fired {
|
|
634
656
|
raise wrangler event "ruleset_installed" attributes
|
|
635
657
|
event:attrs.put({"rids": [rid]})
|
|
658
|
+
if not already_installed
|
|
636
659
|
}
|
|
637
660
|
else {
|
|
638
661
|
raise wrangler event "ruleset_install_failed" attributes
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
ruleset io.picolabs.xmlui {
|
|
2
|
+
meta {
|
|
3
|
+
name "XMLUI views"
|
|
4
|
+
description "Optional ruleset for pico views (XMLUI): file(), markup helpers, app channels."
|
|
5
|
+
author "PICOLABS"
|
|
6
|
+
|
|
7
|
+
use module io.picolabs.wrangler alias wrangler
|
|
8
|
+
|
|
9
|
+
provides query_url, event_url, query, event, escape, app_url, create_app_channel, rotate_app_channel, xmluiRuntimePath
|
|
10
|
+
shares file, query_url, event_url, query, event, escape, app_url, xmluiRuntimePath
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
global {
|
|
14
|
+
xmluiRuntimeVersion = "0.12.7"
|
|
15
|
+
xmluiFileRid = "io.picolabs.xmlui"
|
|
16
|
+
|
|
17
|
+
xmluiRuntimePath = function() {
|
|
18
|
+
"/xmlui/" + xmluiRuntimeVersion + ".js"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
query_url = function(name, rid, eci) {
|
|
22
|
+
"/sky/query/" + (eci || meta:eci) + "/" + (rid || meta:rid) + "/" + name
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
event_url = function(domain, type, eci) {
|
|
26
|
+
"/sky/event/" + (eci || meta:eci) + "/xmlui/" + domain + "/" + type
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
escape = function(s) {
|
|
30
|
+
s.replace("&", "&")
|
|
31
|
+
.replace("<", "<")
|
|
32
|
+
.replace(">", ">")
|
|
33
|
+
.replace("\"", """)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
escapeAttr = function(s) {
|
|
37
|
+
escape(s)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
queryArgsSuffix = function(args) {
|
|
41
|
+
args.isnull() || args == {} => "" |
|
|
42
|
+
args.keys().length() == 0 => "" |
|
|
43
|
+
"?" + args.keys()
|
|
44
|
+
.sort()
|
|
45
|
+
.map(function(k) {
|
|
46
|
+
k + "=" + args{k}
|
|
47
|
+
})
|
|
48
|
+
.join("&")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param id DataSource id
|
|
53
|
+
* @param name shared query name on app_rid
|
|
54
|
+
* @param opts rid, args (map, values may be XMLUI bindings), select
|
|
55
|
+
*/
|
|
56
|
+
query = function(id, name, opts) {
|
|
57
|
+
"<DataSource id=\"" + escapeAttr(id) + "\" url=\"" +
|
|
58
|
+
escapeAttr(
|
|
59
|
+
query_url(
|
|
60
|
+
name,
|
|
61
|
+
(opts.defaultsTo({}){"rid"} || meta:rid),
|
|
62
|
+
meta:eci
|
|
63
|
+
) + queryArgsSuffix(opts.defaultsTo({}){"args"})
|
|
64
|
+
) +
|
|
65
|
+
"\" headers=\"{appGlobals.auth}\"" +
|
|
66
|
+
(opts.defaultsTo({}){"select"}.isnull() => "" |
|
|
67
|
+
" resultSelector=\"" + escapeAttr(opts.defaultsTo({}){"select"}) + "\"") +
|
|
68
|
+
" />"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param id APICall id
|
|
73
|
+
* @param opts refresh (array of DataSource ids), confirm
|
|
74
|
+
*/
|
|
75
|
+
event = function(id, domain, type, opts) {
|
|
76
|
+
"<APICall id=\"" + escapeAttr(id) + "\" method=\"post\" url=\"" +
|
|
77
|
+
escapeAttr(event_url(domain, type, meta:eci)) +
|
|
78
|
+
"\" headers=\"{appGlobals.auth}\" body=\"{$param}\"" +
|
|
79
|
+
(opts.defaultsTo({}){"refresh"}.isnull() => "" |
|
|
80
|
+
" onSuccess=\"" + opts.defaultsTo({}){"refresh"}.map(function(ds) {
|
|
81
|
+
ds + ".refetch()"
|
|
82
|
+
}).join(";") + "\"") +
|
|
83
|
+
(opts.defaultsTo({}){"confirm"}.isnull() => "" |
|
|
84
|
+
" confirm=\"" + escapeAttr(opts.defaultsTo({}){"confirm"}) + "\"") +
|
|
85
|
+
" />"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A channel matches when it has every requested tag. Extra tags, such as
|
|
89
|
+
// oauth-webhook on the app channel, still match.
|
|
90
|
+
newestChannelWithTags = function(tags) {
|
|
91
|
+
wanted = tags.typeof() == "Array" => tags.map(function(t) { t.lc() }) |
|
|
92
|
+
tags.typeof() == "String" => tags.lc().split(",") |
|
|
93
|
+
[]
|
|
94
|
+
wrangler:channels()
|
|
95
|
+
.filter(function(c) {
|
|
96
|
+
have = c{"tags"}.defaultsTo([]).map(function(t) { t.lc() })
|
|
97
|
+
wanted.filter(function(t) { have >< t }).length() == wanted.length()
|
|
98
|
+
})
|
|
99
|
+
.sort(function(a, b) { a{"id"} cmp b{"id"} })
|
|
100
|
+
.reverse()
|
|
101
|
+
.head()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
app_url = function(tags, app_rid) {
|
|
105
|
+
newestChannelWithTags(tags).isnull() => null |
|
|
106
|
+
"/ui/" + newestChannelWithTags(tags){"id"} + "/" +
|
|
107
|
+
(app_rid || meta:rid) + "/"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
shareNamesForApp = function(app_rid) {
|
|
111
|
+
wrangler:rulesetSchema(app_rid){"queries"}
|
|
112
|
+
.defaultsTo([])
|
|
113
|
+
.map(function(q) {
|
|
114
|
+
q{"name"}
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
queryPolicyForApp = function(app_rid, queries) {
|
|
119
|
+
(queries.isnull() => shareNamesForApp(app_rid) | queries)
|
|
120
|
+
.map(function(q) {
|
|
121
|
+
{ "rid": app_rid, "name": q }
|
|
122
|
+
})
|
|
123
|
+
.append([{ "rid": xmluiFileRid, "name": "file" }])
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
eventPolicyForDomains = function(domains) {
|
|
127
|
+
{
|
|
128
|
+
"allow": domains.map(function(d) {
|
|
129
|
+
{ "domain": d, "name": "*" }
|
|
130
|
+
}),
|
|
131
|
+
"deny": []
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
create_app_channel = defaction(tags, domains, queries, app_rid) {
|
|
136
|
+
wrangler:createChannel(
|
|
137
|
+
tags,
|
|
138
|
+
eventPolicyForDomains(domains.defaultsTo([])),
|
|
139
|
+
{
|
|
140
|
+
"allow": queryPolicyForApp(app_rid || meta:rid, queries),
|
|
141
|
+
"deny": []
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
rotate_app_channel = defaction(tags) {
|
|
147
|
+
template = newestChannelWithTags(tags)
|
|
148
|
+
wrangler:createChannel(
|
|
149
|
+
template{"tags"},
|
|
150
|
+
template{"eventPolicy"},
|
|
151
|
+
template{"queryPolicy"}
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
viewComponentName = function(fn) {
|
|
156
|
+
fn.substr(0, 1).uc() + fn.substr(1)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
viewQueriesOnChannel = function(app_rid) {
|
|
160
|
+
wrangler:channelSchema(meta:eci){"queries"}
|
|
161
|
+
.defaultsTo([])
|
|
162
|
+
.filter(function(q) {
|
|
163
|
+
q{"rid"} == app_rid && not q{"view"}.isnull()
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
launcherRids = function() {
|
|
168
|
+
wrangler:channelSchema(meta:eci){"queries"}
|
|
169
|
+
.defaultsTo([])
|
|
170
|
+
.filter(function(q) {
|
|
171
|
+
not q{"view"}.isnull()
|
|
172
|
+
})
|
|
173
|
+
.map(function(q) {
|
|
174
|
+
q{"rid"}
|
|
175
|
+
})
|
|
176
|
+
.sort()
|
|
177
|
+
.reduce(function(acc, rid) {
|
|
178
|
+
acc >< rid => acc | acc.append(rid)
|
|
179
|
+
}, [])
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pageRoute = function(view, fn, multiView) {
|
|
183
|
+
not view{"path"}.isnull() => view{"path"} |
|
|
184
|
+
multiView => "/" + fn | "/"
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
navVisible = function(view) {
|
|
188
|
+
view{"path"}.isnull() => true |
|
|
189
|
+
view{"path"}.split(":").length() == 1
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
firstNavViewQuery = function(app_rid) {
|
|
193
|
+
viewQueriesOnChannel(app_rid).filter(function(q) {
|
|
194
|
+
navVisible(q{"view"})
|
|
195
|
+
}).head()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
fallbackWhenNoNavViews = function(multiView) {
|
|
199
|
+
not multiView => "/" | "/"
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
fallbackPathForApp = function(app_rid, multiView) {
|
|
203
|
+
nav = firstNavViewQuery(app_rid)
|
|
204
|
+
nav.isnull() => fallbackWhenNoNavViews(multiView) |
|
|
205
|
+
pageRoute(nav{"view"}, nav{"name"}, multiView)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
multiViewForApp = function(app_rid) {
|
|
209
|
+
viewQueriesOnChannel(app_rid).length() > 1
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
appRulesetName = function(app_rid) {
|
|
213
|
+
wrangler:rulesetMeta(app_rid).isnull() => app_rid |
|
|
214
|
+
wrangler:rulesetMeta(app_rid){"name"} || app_rid
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
indexHtml = function(app_rid) {
|
|
218
|
+
"<html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><script>window.__PUBLIC_PATH=\"/ui/" +
|
|
219
|
+
meta:eci + "/" + app_rid + "\";window.__PICO_VIEW_ECI=\"" + meta:eci +
|
|
220
|
+
"\";window.__PICO_XMLUI_SCRIPT=\"" + xmluiRuntimePath() +
|
|
221
|
+
"\";window.__XMLUI_FALLBACK_PATH=\"" +
|
|
222
|
+
escapeAttr(fallbackPathForApp(app_rid, multiViewForApp(app_rid))) +
|
|
223
|
+
"\";window.__PICO_VIEW_USE_HASH_ROUTING=\"true\";</script><base href=\"/ui/" +
|
|
224
|
+
meta:eci + "/" + app_rid +
|
|
225
|
+
"/\" /><script src=\"/xmlui/pico-view-boot.js?v=" + xmluiRuntimeVersion +
|
|
226
|
+
"-pico2\"></script></head><body></body></html>"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
launcherTitle = function(rid) {
|
|
230
|
+
wrangler:rulesetMeta(rid).isnull() => rid |
|
|
231
|
+
wrangler:rulesetMeta(rid){"name"} || rid
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
launcherHtml = function() {
|
|
235
|
+
"<html><body><ul>" +
|
|
236
|
+
launcherRids().map(function(rid) {
|
|
237
|
+
"<li><a href=\"/ui/" + meta:eci + "/" + rid + "\">" +
|
|
238
|
+
escape(launcherTitle(rid)) + "</a></li>"
|
|
239
|
+
}).join("") +
|
|
240
|
+
"</ul></body></html>"
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
navLinksForApp = function(app_rid, multiView) {
|
|
244
|
+
viewQueriesOnChannel(app_rid).filter(function(q) {
|
|
245
|
+
navVisible(q{"view"})
|
|
246
|
+
}).map(function(q) {
|
|
247
|
+
"<NavLink label=\"" + escapeAttr(q{"view"}{"title"}) + "\" to=\"" +
|
|
248
|
+
escapeAttr(pageRoute(q{"view"}, q{"name"}, multiView)) + "\" />"
|
|
249
|
+
}).join("")
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
pagesForApp = function(app_rid, multiView) {
|
|
253
|
+
viewQueriesOnChannel(app_rid).map(function(q) {
|
|
254
|
+
"<Page url=\"" + escapeAttr(pageRoute(q{"view"}, q{"name"}, multiView)) +
|
|
255
|
+
"\"><" + viewComponentName(q{"name"}) + " /></Page>"
|
|
256
|
+
}).join("")
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
navPanelForApp = function(app_rid, multiView) {
|
|
260
|
+
not multiView => "" |
|
|
261
|
+
navLinksForApp(app_rid, multiView) == "" => "" |
|
|
262
|
+
"<NavPanel>" + navLinksForApp(app_rid, multiView) + "</NavPanel>"
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// XMLUI defaults: layout condensed-sticky, scrollWholePage true. That combo
|
|
266
|
+
// mis-measures header height in WebKit (Safari) and can hide page content.
|
|
267
|
+
shellAppAttrs = function() {
|
|
268
|
+
" layout=\"vertical-sticky\" scrollWholePage=\"false\""
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
mainXmlui = function(app_rid) {
|
|
272
|
+
viewQueriesOnChannel(app_rid).length() == 0 => null |
|
|
273
|
+
"<App name=\"" + escapeAttr(appRulesetName(app_rid)) + "\"" +
|
|
274
|
+
shellAppAttrs() + ">" +
|
|
275
|
+
navPanelForApp(app_rid, multiViewForApp(app_rid)) +
|
|
276
|
+
"<Pages fallbackPath=\"" +
|
|
277
|
+
escapeAttr(fallbackPathForApp(app_rid, multiViewForApp(app_rid))) +
|
|
278
|
+
"\">" +
|
|
279
|
+
pagesForApp(app_rid, multiViewForApp(app_rid)) +
|
|
280
|
+
"</Pages></App>"
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
configJson = function(app_rid) {
|
|
284
|
+
{
|
|
285
|
+
"name": appRulesetName(app_rid),
|
|
286
|
+
"appGlobals": {
|
|
287
|
+
"eci": meta:eci,
|
|
288
|
+
"appRid": app_rid,
|
|
289
|
+
"picoName": wrangler:name(),
|
|
290
|
+
"useHashBasedRouting": true
|
|
291
|
+
},
|
|
292
|
+
"xmluiConfig": { "useHashBasedRouting": true }
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
file = function(rid, path) {
|
|
297
|
+
rid == "" => launcherHtml() |
|
|
298
|
+
path.defaultsTo("index.html") == "index.html" => indexHtml(rid) |
|
|
299
|
+
path.defaultsTo("index.html") == "Main.xmlui" => mainXmlui(rid) |
|
|
300
|
+
path.defaultsTo("index.html") == "config.json" => configJson(rid) |
|
|
301
|
+
null
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
package/mcp/devResources.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// Docs live at the repo root (docs/, CLAUDE.md). In a checkout, read them there;
|
|
7
|
+
// in an npm install, read the copies `npm pack` bundled into mcp/docs/.
|
|
8
|
+
const repoRoot = path.join(__dirname, "..", "..", "..");
|
|
9
|
+
const bundledDir = path.join(__dirname, "docs");
|
|
10
|
+
|
|
11
|
+
function readFile(filePath) {
|
|
8
12
|
try {
|
|
9
13
|
return fs.readFileSync(filePath, "utf8");
|
|
10
14
|
} catch (_e) {
|
|
@@ -12,6 +16,13 @@ function readDoc(relativeFromPackage) {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
function readDoc(relativeFromRepoRoot) {
|
|
20
|
+
return (
|
|
21
|
+
readFile(path.join(repoRoot, relativeFromRepoRoot)) ||
|
|
22
|
+
readFile(path.join(bundledDir, path.basename(relativeFromRepoRoot)))
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
function registerDevResources(server, client) {
|
|
16
27
|
server.resource(
|
|
17
28
|
"krl-conventions",
|
|
@@ -25,7 +36,7 @@ function registerDevResources(server, client) {
|
|
|
25
36
|
{
|
|
26
37
|
uri: "pico://docs/krl-conventions",
|
|
27
38
|
mimeType: "text/markdown",
|
|
28
|
-
text: readDoc("
|
|
39
|
+
text: readDoc("CLAUDE.md"),
|
|
29
40
|
},
|
|
30
41
|
],
|
|
31
42
|
})
|
|
@@ -44,8 +55,7 @@ function registerDevResources(server, client) {
|
|
|
44
55
|
uri: "pico://docs/pico-overview",
|
|
45
56
|
mimeType: "text/markdown",
|
|
46
57
|
text:
|
|
47
|
-
readDoc("
|
|
48
|
-
readDoc("../../../docs/design/pico-overview.md"),
|
|
58
|
+
readDoc("docs/pico-overview.md"),
|
|
49
59
|
},
|
|
50
60
|
],
|
|
51
61
|
})
|
|
@@ -63,7 +73,7 @@ function registerDevResources(server, client) {
|
|
|
63
73
|
{
|
|
64
74
|
uri: "pico://docs/pico-engine",
|
|
65
75
|
mimeType: "text/markdown",
|
|
66
|
-
text: readDoc("
|
|
76
|
+
text: readDoc("docs/pico-engine.md"),
|
|
67
77
|
},
|
|
68
78
|
],
|
|
69
79
|
})
|
|
@@ -93,7 +103,7 @@ function registerDevResources(server, client) {
|
|
|
93
103
|
schemaBlock = `\n\n(Could not load channel schema: ${String(err)})\n`;
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
|
-
const conventions = readDoc("
|
|
106
|
+
const conventions = readDoc("CLAUDE.md");
|
|
97
107
|
return {
|
|
98
108
|
messages: [
|
|
99
109
|
{
|