@xpell/core 2.0.0-alpha.10 → 2.0.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 +100 -61
- package/dist/XCommand.d.ts +2 -2
- package/dist/XData.d.ts +1 -0
- package/dist/XDataModule.d.ts +41 -0
- package/dist/XEvenetManagerModule.d.ts +10 -0
- package/dist/XEventManager.d.ts +3 -6
- package/dist/XModule.d.ts +14 -1
- package/dist/XNanoCommands.d.ts +6 -34
- package/dist/XObject.d.ts +28 -14
- package/dist/XObjectManager.d.ts +2 -0
- package/dist/XParams.d.ts +1 -1
- package/dist/XRuntime.d.ts +2 -0
- package/dist/XSkills.d.ts +47 -0
- package/dist/XUtils.d.ts +35 -0
- package/dist/Xpell.d.ts +31 -8
- package/dist/xpell-core.cjs.js +2 -2
- package/dist/xpell-core.es.js +1518 -644
- package/docs/Codex_Skills/SKILL.md +184 -0
- package/docs/Codex_Skills/SKILL_API_MAP.md +122 -0
- package/docs/Codex_Skills/SKILL_CHECKLIST.md +18 -0
- package/docs/nano-commands2.md +457 -0
- package/package.json +5 -5
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
# Nano-Commands v2 (JSON + Sequences) — Xpell 2 Contract
|
|
2
|
+
|
|
3
|
+
This document is the **canonical contract** for how Xpell 2 executes *nano-commands* from:
|
|
4
|
+
- **DB-stored views**
|
|
5
|
+
- **agent edits**
|
|
6
|
+
- **schema-generated UI**
|
|
7
|
+
- **runtime events** (`_on_click`, `_on_data`, `_on_show`, …)
|
|
8
|
+
|
|
9
|
+
Goal: **data-only intent** instead of JS functions, while keeping execution **small, deterministic, and auditable**.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Why this matters
|
|
14
|
+
|
|
15
|
+
Historically, handlers were either:
|
|
16
|
+
- **Functions** (powerful, but not serializable / not DB-safe)
|
|
17
|
+
- **String nano-commands** (simple, but awkward for complex parameters)
|
|
18
|
+
|
|
19
|
+
Xpell 2 upgrades handlers with two capabilities:
|
|
20
|
+
|
|
21
|
+
1) **JSON Command Handlers** — structured `XCommandData` (pure data)
|
|
22
|
+
2) **Sequence Handlers** — arrays of handlers executed **in order** (awaited)
|
|
23
|
+
|
|
24
|
+
This enables **dynamic views** stored in XDB/files and real-time “vibe coding” without embedding code.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Handler formats (what you can put in object JSON)
|
|
29
|
+
|
|
30
|
+
A “handler” field (e.g. `_on_click`, `_on_show`, `_on_hide`, `_on_data`, `_on_mount`, `_on_frame`) can be:
|
|
31
|
+
|
|
32
|
+
### A) Function (dev-only)
|
|
33
|
+
Use only in developer-authored object packs.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
_on_click: async (obj, e) => {
|
|
37
|
+
// custom code (NOT DB-safe)
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### B) String nano-command (legacy / shorthand)
|
|
42
|
+
For simple actions.
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
"_on_click": "hide"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### C) JSON command (canonical)
|
|
49
|
+
For DB-stored, agent-editable views.
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
"_on_click": { "_op": "hide" }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or with parameters:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
"_on_click": { "_op": "set-text", "_params": { "text": "ok" } }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### D) Sequence (canonical composition)
|
|
62
|
+
Multi-step flows as data (no scripting language).
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
"_on_click": [
|
|
66
|
+
{ "_op": "hide" },
|
|
67
|
+
{ "_op": "set-text", "_params": { "text": "Hidden" } },
|
|
68
|
+
{ "_op": "show" }
|
|
69
|
+
]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Sequence semantics:**
|
|
73
|
+
- Execute **in order**
|
|
74
|
+
- Each item is **awaited**
|
|
75
|
+
- Default: **abort on thrown error** (consistent with your runtime error logging)
|
|
76
|
+
|
|
77
|
+
> If you need shared state between steps, use **XData** keys (recommended).
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## JSON command format (XCommandData)
|
|
82
|
+
|
|
83
|
+
A JSON command is the canonical runtime intent shape:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"_op": "set-text",
|
|
88
|
+
"_params": { "text": "hello" }
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Optional fields (tooling + future evolution):
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"_module": "xui",
|
|
97
|
+
"_object": "this",
|
|
98
|
+
"_op": "hide",
|
|
99
|
+
"_params": {}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Important runtime note (today)
|
|
104
|
+
In current Xpell 2 runtime, command resolution is **object-local**:
|
|
105
|
+
- `XObject.execute()` resolves `_op` against nano-command packs registered on the **target object**
|
|
106
|
+
- `_module` is treated as **semantic metadata** (helpful for tools/agents), not required for execution
|
|
107
|
+
|
|
108
|
+
### `_object` target rule
|
|
109
|
+
- If `_object` is omitted or `"this"`, the target is the **current object** (recommended for DB-stored handlers)
|
|
110
|
+
- Cross-object targeting may be constrained by policy; keep DB handlers **local by default**
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Payload injection (passing data/events into JSON handlers)
|
|
115
|
+
|
|
116
|
+
When a handler is invoked with a payload (e.g. `onData(data)` or click event `e`), the runtime may inject:
|
|
117
|
+
|
|
118
|
+
- `cmd._params.data = payload` **only if** `data` is not already provided.
|
|
119
|
+
|
|
120
|
+
This enables structured value passing without JSON-in-string escaping.
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
"_on_data": { "_op": "set-text-from-data", "_params": { "pattern": "FPS: $data" } }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Examples
|
|
131
|
+
|
|
132
|
+
### 1) XUIObject — simple click hide (string)
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"_id": "btn-close",
|
|
136
|
+
"_type": "button",
|
|
137
|
+
"_text": "Close",
|
|
138
|
+
"_on_click": "hide"
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 2) XUIObject — set text on click (JSON)
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"_id": "btn-ok",
|
|
146
|
+
"_type": "button",
|
|
147
|
+
"_text": "OK",
|
|
148
|
+
"_on_click": { "_op": "set-text", "_params": { "text": "ok" } }
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 3) XUIObject — hide then show (sequence)
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"_id": "panel",
|
|
156
|
+
"_type": "view",
|
|
157
|
+
"_on_click": [
|
|
158
|
+
{ "_op": "hide" },
|
|
159
|
+
{ "_op": "show" }
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 4) XObject — onData drives UI (sequence)
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"_id": "fps-label",
|
|
168
|
+
"_type": "label",
|
|
169
|
+
"_data_source": "engine:fps",
|
|
170
|
+
"_on_data": [
|
|
171
|
+
{ "_op": "set-text-from-data", "_params": { "pattern": "FPS: $data" } }
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Design rule: no `run-seq` nano command
|
|
179
|
+
|
|
180
|
+
Xpell 2 **does not** introduce a `run-seq` nano command.
|
|
181
|
+
|
|
182
|
+
Sequencing is structural at the handler level:
|
|
183
|
+
- handlers may be arrays
|
|
184
|
+
- each item is executed in order
|
|
185
|
+
|
|
186
|
+
This keeps nano-commands:
|
|
187
|
+
- **atomic**
|
|
188
|
+
- **auditable**
|
|
189
|
+
- **non-scriptable**
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Security notes
|
|
194
|
+
|
|
195
|
+
This upgrade is explicitly designed to avoid “code in DB”:
|
|
196
|
+
|
|
197
|
+
- ✅ JSON commands are **whitelisted ops** (`_op` on a known nano-command pack)
|
|
198
|
+
- ✅ parameters are **data**, not executable code
|
|
199
|
+
- ✅ runtime can enforce:
|
|
200
|
+
- allowed ops
|
|
201
|
+
- allowed targets
|
|
202
|
+
- capability checks
|
|
203
|
+
- rate limits
|
|
204
|
+
- ❌ avoid `eval` / `new Function` / code-in-JSON
|
|
205
|
+
|
|
206
|
+
**Rule:** if a view is stored in DB and editable by an agent, handlers must be **data-only** (no functions).
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Recommended next steps (implementation checklist)
|
|
211
|
+
|
|
212
|
+
1) Ensure `checkAndRunInternalFunction()` supports:
|
|
213
|
+
- `XCommandData` objects (`{ _op, _params }`)
|
|
214
|
+
- sequences (arrays of handlers)
|
|
215
|
+
2) Ensure event dispatch sites call:
|
|
216
|
+
- `checkAndRunInternalFunction(handler, payload)`
|
|
217
|
+
for non-function handlers as well.
|
|
218
|
+
3) Add capability/allowlist enforcement at the command runner boundary.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Changelog (conceptual)
|
|
223
|
+
|
|
224
|
+
- **v1:** strings + dev-only functions
|
|
225
|
+
- **v2:** JSON commands + sequences for DB-stored realtime views
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
-- Commands:
|
|
229
|
+
```md
|
|
230
|
+
# Codex Prompt — Xpell Nano Commands (Authoritative List)
|
|
231
|
+
|
|
232
|
+
Use **nano commands only** for runtime behavior.
|
|
233
|
+
Do NOT emit JavaScript functions for DB-stored views.
|
|
234
|
+
All actions must map to whitelisted nano commands.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## @xpell/core — XObject (available on ALL objects)
|
|
239
|
+
|
|
240
|
+
### info
|
|
241
|
+
Logs the object id.
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
info
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### log
|
|
249
|
+
Logs a value or the object itself.
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
log 'hello'
|
|
253
|
+
log
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### fire
|
|
258
|
+
Fires a global event via XEventManager.
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
fire event:'my-event' data:'payload'
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### set-attr
|
|
266
|
+
Sets a safe attribute on the object instance.
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
set-attr name:'_name' value:'test'
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### delete-attr
|
|
274
|
+
Deletes a safe attribute from the object instance.
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
delete-attr name:'_name'
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## @xpell/ui — XUIObject (UI-only)
|
|
284
|
+
|
|
285
|
+
### hide
|
|
286
|
+
Hides the UI object.
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
hide
|
|
290
|
+
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### show
|
|
294
|
+
Shows the UI object.
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
show
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### toggle
|
|
302
|
+
Toggles visibility.
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
toggle
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### set-text
|
|
310
|
+
Sets text content.
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
set-text text:'Hello'
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### set (legacy alias)
|
|
318
|
+
Sets text if `text` param exists.
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
set text:'Hello'
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### set-text-from-data
|
|
326
|
+
Sets text from incoming data payload.
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
set-text-from-data pattern:'Value: $data'
|
|
330
|
+
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### set-text-from-frame
|
|
334
|
+
Sets text from frame counter.
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
set-text-from-frame pattern:'Frame $data'
|
|
338
|
+
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### add-class
|
|
342
|
+
Adds a CSS class.
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
add-class class:'active'
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### remove-class
|
|
350
|
+
Removes a CSS class.
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
remove-class class:'active'
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### toggle-class
|
|
358
|
+
Toggles a CSS class.
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
toggle-class class:'active'
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### set-style
|
|
366
|
+
Sets an inline style.
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
set-style name:'color' value:'red'
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### set-attr
|
|
374
|
+
Sets a DOM attribute.
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
set-attr name:'aria-label' value:'Close'
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### remove-attr
|
|
382
|
+
Removes a DOM attribute.
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
remove-attr name:'aria-label'
|
|
386
|
+
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## @xpell/3d — X3DObject (3D-only)
|
|
392
|
+
|
|
393
|
+
### rotation
|
|
394
|
+
Sets or increments rotation axes.
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
rotation x:0.1 y:++0.02 z:--0.01
|
|
398
|
+
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### spin
|
|
402
|
+
Applies continuous rotation via on-frame hook.
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
spin y:0.01
|
|
406
|
+
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### stop
|
|
410
|
+
Stops on-frame behavior.
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
stop
|
|
414
|
+
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### follow-joystick
|
|
418
|
+
Moves object using joystick data from XData.
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
follow-joystick
|
|
422
|
+
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### orbit
|
|
426
|
+
Moves object in an orbit.
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
orbit radius:2 speed:0.02
|
|
430
|
+
|
|
431
|
+
````
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
## Sequences (native, no extra command)
|
|
436
|
+
|
|
437
|
+
Multiple nano commands can be executed in order using arrays:
|
|
438
|
+
|
|
439
|
+
```json
|
|
440
|
+
[
|
|
441
|
+
{ "_op": "hide" },
|
|
442
|
+
{ "_op": "set-text", "_params": { "text": "Hidden" } },
|
|
443
|
+
{ "_op": "show" }
|
|
444
|
+
]
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## Rules (MANDATORY)
|
|
450
|
+
|
|
451
|
+
* Prefer **JSON commands** for DB-stored views
|
|
452
|
+
* Use **strings only for trivial actions**
|
|
453
|
+
* Use **arrays instead of `;` or scripting**
|
|
454
|
+
* Never emit `eval`, `new Function`, or inline JS
|
|
455
|
+
* If output is stored → it MUST be data-only
|
|
456
|
+
|
|
457
|
+
This list is the **single source of truth** for Codex and agents.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpell/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.01",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"url": "https://github.com/xpell-ai/xpell-core.git"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"typedoc": "^0.27.
|
|
54
|
-
"typescript": "^5.
|
|
55
|
-
"vite": "^7.2
|
|
53
|
+
"typedoc": "^0.27.9",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"vite": "^7.3.2"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"dev": "vite",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
"docs:api": "typedoc",
|
|
62
62
|
"docs": "pnpm run docs:api",
|
|
63
63
|
"test": "echo \"No tests yet\" && exit 0",
|
|
64
|
-
"publish-alpha-next": "pnpm version prerelease --preid=alpha
|
|
64
|
+
"publish-alpha-next": "pnpm version prerelease --preid=alpha && pnpm publish --tag alpha"
|
|
65
65
|
}
|
|
66
66
|
}
|