@indra.ai/deva.systems 0.15.4 → 0.15.6
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 +270 -2
- package/index.test.js +356 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,273 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Systems Deva
|
|
2
|
+
|
|
3
|
+
Systems Deva handles all the various systems in Deva.world. It keeps the client's systems data, the concerns and the global systems settings, and reports it back with restricted values hidden. Its agent key is `systems`. The package entry (`index.js`) exports a ready Deva with empty `func`, `methods`, `listeners`, and `modules`. The `systems` method lives in `feature/methods.js` and is bound at runtime by the feature loader.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js with npm. Systems Deva's `package.json` sets no `engines`. Deva Core 1.67.26 declares `"node": ">=22"` and `"npm": ">=9.5.1"` in its own `package.json`.
|
|
8
|
+
- A project with `"type": "module"` in its `package.json`. Systems Deva is an ES module.
|
|
9
|
+
- `@indra.ai/deva` `^1.67.26` (Deva Core). Systems Deva lists it as a `dependency`.
|
|
10
|
+
- A Feecting agent reachable on the Deva bus if you call the `systems` method. The method hands its output to `#feecting parse`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @indra.ai/deva.systems --save
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import SystemsDeva from '@indra.ai/deva.systems';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Two licenses
|
|
23
|
+
|
|
24
|
+
A running Deva carries two separate licenses, and each is checked on its own.
|
|
25
|
+
|
|
26
|
+
- **The core license** comes through the client data as `client.VLA`. Deva Core checks it against the core package's VLA at the start of `init`.
|
|
27
|
+
- **The agent license** comes through the license feature data as `features.license.devas.systems`. Deva Core 1.67.26 checks it against the VLA in Systems Deva's own `package.json` right after the features load and before the start chain. Systems Deva also has an `onInit` of its own, which runs `this.license_check(this.license().personal, this.info().VLA)` and then `this.start` or `this.stop`.
|
|
28
|
+
|
|
29
|
+
The agent check compares the sha256 of the whole VLA object, so every field has to match exactly.
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
Systems Deva reads two features from the client you pass to `init()`. The feature data loader puts them in the client, and Deva Core loads them into the Deva at startup, so both must be there before `init()` runs.
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
"features": {
|
|
37
|
+
"license": {
|
|
38
|
+
"concerns": [],
|
|
39
|
+
"global": {},
|
|
40
|
+
"devas": {
|
|
41
|
+
"systems": {
|
|
42
|
+
"uid": "24296120490769123430",
|
|
43
|
+
"time": 1795875310499,
|
|
44
|
+
"iso": "2026-11-28T14:15:10.499Z",
|
|
45
|
+
"utc": "Sat, 28 Nov 2026 14:15:10 GMT",
|
|
46
|
+
"date": "Saturday, November 28, 2026 - 6:15:10 AM",
|
|
47
|
+
"license": "34948472480559228528",
|
|
48
|
+
"fingerprint": "o+rkIG46UjP8O2or2lQ/GviqDBye6CNTXxowkJECWzE=",
|
|
49
|
+
"client": "27l9CQgHobrMikrhkiVH3N6A2GYIwOT/TBGhygYgf5k=",
|
|
50
|
+
"agent": "nJCa4yJAQOLtusCoXpoJVQa2S+xlRmvhM8sH6OGitmU=",
|
|
51
|
+
"machine": "zJ9MvOhpt85/FLRsci+lisLsVKrVvQD/p59dpJQxDgE=",
|
|
52
|
+
"core_hash": "QX5bYu6u8xEFC0dRQn8R5pY3c1wJgjv/ONxvV0haKik=",
|
|
53
|
+
"status": "vedic",
|
|
54
|
+
"warning": "⚡️ Deva declares UNLAWFUL USE, MODIFICATION, INSTALLATION, DUPLICATION, DISTRIBUTION, INTERACTION, or IMPLEMENTATION constitutes VEDIC SAHASA a CRIME of the HIGHEST DEGREE. A FINE amounting to 1000 PANAS (1 pana = 3.5 grams of gold) for each INSTANCE has been ORDAINED the PUNISHMENT for SAHASA of the HIGHEST DEGREE.",
|
|
55
|
+
"notice": "Any USE or INTERACTION with Deva constitutes YOUR EXPLICIT CONSENT and AGREEMENT to be GOVERNED according to the LAWS of the 🕉VEDIC RELIGION and 🇺🇸THE UNITED STATES OF AMERICA.",
|
|
56
|
+
"vectors": "#Quinn #QuinnMichaels #InsideTheNet #IndraAI #DEVA #DevaWorld #License #LicenseDeva #VedicLicenseAgreement",
|
|
57
|
+
"owner": "Quinn Michaels",
|
|
58
|
+
"creator": "Quinn Michaels",
|
|
59
|
+
"salute": "🤝🫡🪪🕉🇺🇸",
|
|
60
|
+
"copyright": "Copyright ©2000-2026 Quinn Michaels; All rights reserved.",
|
|
61
|
+
"md5": "t7xAYQBr4ovNiIyiFCvvsA==",
|
|
62
|
+
"sha256": "QOAi8oc2SMNaGXLkoJ4EYKXN2+dOjIk1TgmV0PmlgOs=",
|
|
63
|
+
"sha512": "fowmLExO94DmUHpTJCMa4LQvmne6rZI7YiiwynHVVldhZAdY8oTkt6Qo694vKoSE3Y52gJwve9dVR/5Z5IAg4g=="
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"systems": {
|
|
68
|
+
"concerns": ["Keep every system online."],
|
|
69
|
+
"global": {
|
|
70
|
+
"restricted": ["password", "token"],
|
|
71
|
+
"region": "example-region",
|
|
72
|
+
"database": {"id": "db1", "host": "example.invalid", "password": "example-password"}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `license.devas.systems` is the agent VLA. The short form above only shows where it goes. It must be the full `VLA` object from this package's `package.json`, for example:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
import pkg from '@indra.ai/deva.systems/package.json' with {type:'json'};
|
|
82
|
+
|
|
83
|
+
const devas = {systems: pkg.VLA}; // goes in features.license.devas
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `systems.concerns` is an array, and `systems.global` is an object. Deva Core stores them on the systems feature at init. If they are omitted, Deva Core stores `⛔️ NO CONCERNS PROVIDED` and `⛔️ NO GLOBAL PROVIDED` instead.
|
|
87
|
+
- `systems.global.restricted` is an array of lowercase field names whose values the `systems` method hides. See Feature methods.
|
|
88
|
+
- `systems.methods` is how the feature loader binds `feature/methods.js` at init. Import the file and set it here, as shown under Feature methods. If it is omitted, Systems Deva still comes online, and `this.methods` stays empty.
|
|
89
|
+
|
|
90
|
+
## Load it
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import SystemsDeva from '@indra.ai/deva.systems';
|
|
94
|
+
|
|
95
|
+
const systems = await SystemsDeva.init(client); // client data provided by your loader
|
|
96
|
+
console.log(systems.id.uid);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
When the license checks pass, Systems Deva walks start, enter, done and ready. In `onReady` it reads `this.info().VLA` and prompts `🖥️ Systems Deva Ready > VLA:24296120490769123430`.
|
|
100
|
+
|
|
101
|
+
To shut it down:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
await SystemsDeva.stop();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Systems Deva has no `onStop` of its own, so Deva Core runs the default stop chain, which ends on `shutdown` with the value `systems`. A stopped Deva can start again. Call `init()` again with a client that passes the license check.
|
|
108
|
+
|
|
109
|
+
## When Systems Deva refuses to start
|
|
110
|
+
|
|
111
|
+
If a license check fails, Deva Core prompts the message, the Deva stays offline, and `init()` resolves with that message.
|
|
112
|
+
|
|
113
|
+
| You see | Why |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `❌ Bad Personal VLA` | `features.license.devas` is there but has no `systems` entry. |
|
|
116
|
+
| `❌ Invalid VLA Check` | The `systems` entry doesn't match this package's VLA, the license feature has no `devas`, or `client.VLA` doesn't match the core package's VLA. |
|
|
117
|
+
|
|
118
|
+
## Feature methods
|
|
119
|
+
|
|
120
|
+
`feature/methods.js` exports `systems`. The feature loader binds the exported methods at runtime from `client.features.systems.methods` onto the Deva's `methods`. `index.js` itself sets `methods: {}`.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import SystemsDeva from '@indra.ai/deva.systems';
|
|
124
|
+
import featureMethods from '@indra.ai/deva.systems/feature/methods.js';
|
|
125
|
+
import pkg from '@indra.ai/deva.systems/package.json' with {type:'json'};
|
|
126
|
+
import core from '@indra.ai/deva/package.json' with {type:'json'};
|
|
127
|
+
|
|
128
|
+
const client = {
|
|
129
|
+
id: '00000000000000000000',
|
|
130
|
+
key: 'client',
|
|
131
|
+
VLA: core.VLA,
|
|
132
|
+
prompt: {
|
|
133
|
+
emoji: '🧪',
|
|
134
|
+
text: 'client',
|
|
135
|
+
colors: {
|
|
136
|
+
label: {R: 2, G: 229, B: 77},
|
|
137
|
+
text: {R: 2, G: 229, B: 77},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
profile: {
|
|
141
|
+
id: '00000000000000000000',
|
|
142
|
+
name: 'Test Client',
|
|
143
|
+
describe: 'Test client for Systems Deva',
|
|
144
|
+
lang: 'en',
|
|
145
|
+
locale: 'en-US',
|
|
146
|
+
currency: 'USD',
|
|
147
|
+
},
|
|
148
|
+
features: {
|
|
149
|
+
license: {
|
|
150
|
+
concerns: [],
|
|
151
|
+
global: {},
|
|
152
|
+
devas: {systems: pkg.VLA},
|
|
153
|
+
},
|
|
154
|
+
systems: {
|
|
155
|
+
concerns: ['Keep every system online.'],
|
|
156
|
+
global: {
|
|
157
|
+
restricted: ['password', 'token'],
|
|
158
|
+
region: 'example-region',
|
|
159
|
+
database: {id: 'db1', host: 'example.invalid', password: 'example-password'},
|
|
160
|
+
},
|
|
161
|
+
methods: featureMethods,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
await SystemsDeva.init(client);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
After `init`, call the bound methods on `SystemsDeva.methods`.
|
|
170
|
+
|
|
171
|
+
| Method | What it does |
|
|
172
|
+
| --- | --- |
|
|
173
|
+
| `systems(packet)` | Builds a Feecting document from the systems feature, asks `#feecting parse` to render it, and resolves `{text, html, data}`. `text` and `html` come from the Feecting answer, and `data` is the `concerns` array. If the ask or the parse fails, it returns `this.err(err, packet, reject)`. `packet` is only passed along for that error handling. |
|
|
174
|
+
|
|
175
|
+
The document the `systems` method sends to Feecting is built like this:
|
|
176
|
+
|
|
177
|
+
- A `::BEGIN:SYSTEMS` block with a `### Client` section and a `### Global` section.
|
|
178
|
+
- The client section is a `client:<client_id>` block holding `id`, the client name as `client`, and the concerns as a numbered list under `**concerns**`.
|
|
179
|
+
- Each key in `systems.global` becomes a line `key: value`. A key whose value is an object becomes a `global:<key>:<id>` block, where `<id>` is the object's `id` or the key if it has none, with one `field: value` line per field.
|
|
180
|
+
- The `restricted` key is never printed.
|
|
181
|
+
|
|
182
|
+
With the example client above, the document is:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
::BEGIN:SYSTEMS
|
|
186
|
+
### Client
|
|
187
|
+
::begin:client:00000000000000000000
|
|
188
|
+
id: 00000000000000000000
|
|
189
|
+
client: Test Client
|
|
190
|
+
**concerns**
|
|
191
|
+
1. Keep every system online.
|
|
192
|
+
::end:client:00000000000000000000
|
|
193
|
+
### Global
|
|
194
|
+
region: example-region
|
|
195
|
+
::begin:global:database:db1
|
|
196
|
+
id: db1
|
|
197
|
+
host: example.invalid
|
|
198
|
+
password: *******
|
|
199
|
+
::end:global:database:db1
|
|
200
|
+
::END:SYSTEMS
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Rules for hiding values:
|
|
204
|
+
|
|
205
|
+
- A top-level key or an object field is hidden when its name, lowercased, equals an entry in `global.restricted`. Its value is replaced with `*******`. Entries in `restricted` have to be lowercase, so an entry like `Token` hides nothing.
|
|
206
|
+
- Only one level of objects is expanded. An object inside an object prints as `[object Object]`, so its contents are not shown.
|
|
207
|
+
- `global.restricted` has to be an array. If it is missing, or `global` itself was omitted, the method rejects with a `TypeError`.
|
|
208
|
+
- If no Feecting agent answers, the method rejects with a `TypeError`, and `onError` prompts `💣 ERROR!` and logs it.
|
|
209
|
+
|
|
210
|
+
## Help
|
|
211
|
+
|
|
212
|
+
Help lives in Feecting files. `help/main.feecting` is the main help page, with the heading `{{profile.name}}`, a hidden block that sets `#color`, `#bgcolor`, and `#bg` from `{{profile.color}}`, `{{profile.bgcolor}}`, and `{{profile.background}}`, and the license block. `help/corpus.feecting` is the help corpus, also with the heading `{{profile.name}}`.
|
|
213
|
+
|
|
214
|
+
`help(page, dir)` is a Deva Core method that returns the page as text. `dir` is the folder that holds `help/`, which for this package is `SystemsDeva.info().dir`. The pages are `main`, `corpus`, and `main:license`.
|
|
215
|
+
|
|
216
|
+
## Inside Systems Deva
|
|
217
|
+
|
|
218
|
+
| Name | Kind | What it does |
|
|
219
|
+
| --- | --- | --- |
|
|
220
|
+
| `systems` | feature method | The method in `feature/methods.js`, bound at runtime from `client.features.systems.methods`. |
|
|
221
|
+
| `translate`, `parse`, `process` | utils | Each returns its input trimmed. |
|
|
222
|
+
| `onInit` | lifecycle | Runs `this.license_check(this.license().personal, this.info().VLA)`, then `this.start` if the check passes or `this.stop` if it does not. |
|
|
223
|
+
| `onReady` | lifecycle | Reads `this.info().VLA` and prompts `🖥️ Systems Deva Ready > VLA:24296120490769123430`. |
|
|
224
|
+
| `onError` | lifecycle | Prompts `💣 ERROR!`, logs the error, and returns `reject(err)`. |
|
|
225
|
+
|
|
226
|
+
The `vars` in `package.json` hold the prompt `messages`, the trigger `@SYSTEMS`, an empty `ask.history` array, and an empty `context` object. `func`, `methods`, `listeners`, and `modules` in `index.js` start as empty objects.
|
|
227
|
+
|
|
228
|
+
`uid()`, `info()`, `agent()`, and `status()` are Deva Core methods. `uid()` returns an id with `md5`, `sha256`, and `sha512` hash tiers, and a `fingerprint` that is the sha256 of `license`, `client`, `agent`, `machine`, and `core_hash`. `info()` returns the package info. `agent()` returns the Systems Deva agent. `status()` returns the `Systems Deva active since <date>` string.
|
|
229
|
+
|
|
230
|
+
## Testing
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
npm test
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The `test` script is `node --test`. The tests build a stub client in code from the core VLA in `@indra.ai/deva/package.json` and the VLA in this package's `package.json`, so no client file is needed. They use only `node:test` and `node:assert/strict`, and they stub the Feecting ask so no Feecting agent is needed. They cover:
|
|
237
|
+
|
|
238
|
+
- systems builds as a Deva and waits offline before init
|
|
239
|
+
- systems data has no placeholders left
|
|
240
|
+
- `func`, `methods`, and `listeners` start empty, and `onInit`, `onReady`, and `onError` exist
|
|
241
|
+
- systems comes online and walks to ready
|
|
242
|
+
- systems info matches the package
|
|
243
|
+
- systems agent matches the package
|
|
244
|
+
- systems agent warning carries the corrected spellings
|
|
245
|
+
- systems uid carries hash tiers and a fingerprint of its contents
|
|
246
|
+
- the package VLA fingerprint is the sha256 of `license`, `client`, `agent`, `machine`, and `core_hash`
|
|
247
|
+
- systems status returns the active-since string
|
|
248
|
+
- systems utils answer with trimmed text
|
|
249
|
+
- systems vars include the ready message, trigger, and empty context
|
|
250
|
+
- systems help pages match the files and carry the package license
|
|
251
|
+
- `feature/methods.js` exports only the current methods
|
|
252
|
+
- systems stops through the full chain
|
|
253
|
+
- feature methods from `feature/methods.js` load at runtime
|
|
254
|
+
- `methods.systems` returns the parsed concerns and id end tags
|
|
255
|
+
- `methods.systems` masks every restricted field and keeps the rest readable
|
|
256
|
+
- `methods.systems` routes a question rejection through `this.err`
|
|
257
|
+
- systems refuses to start with a bad agent VLA
|
|
258
|
+
|
|
259
|
+
## Files
|
|
260
|
+
|
|
261
|
+
| File | What it holds |
|
|
262
|
+
| --- | --- |
|
|
263
|
+
| `index.js` | The Systems Deva: utils, empty `func`, `methods`, `listeners`, and `modules`, and the `onInit`, `onReady`, and `onError` hooks. |
|
|
264
|
+
| `package.json` | Package info, the package VLA, and the agent and vars data under `data`. |
|
|
265
|
+
| `feature/methods.js` | The `systems` feature method that the feature loader binds at runtime. |
|
|
266
|
+
| `help/main.feecting` | The main help page and the license block. |
|
|
267
|
+
| `help/corpus.feecting` | The help corpus. |
|
|
268
|
+
| `index.test.js` | The tests. |
|
|
269
|
+
| `assets/` | The emoji, avatar, background and main images. |
|
|
270
|
+
| `LICENSE.md` | The license. |
|
|
3
271
|
|
|
4
272
|
Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
5
273
|
Owner Signature Required For Lawful Use.
|
package/index.test.js
CHANGED
|
@@ -1,7 +1,362 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Systems Deva
|
|
2
|
+
// Systems Deva Test File
|
|
3
3
|
// Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
4
4
|
// Owner Signature Required For Lawful Use.
|
|
5
5
|
// Distributed under VLA:24296120490769123430 LICENSE.md
|
|
6
6
|
// Saturday, November 28, 2026 - 6:15:10 AM PST
|
|
7
7
|
|
|
8
|
+
// run with: npm test
|
|
9
|
+
import test, {after} from 'node:test';
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import {createHash} from 'node:crypto';
|
|
12
|
+
import {dirname} from 'node:path';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import Deva from '@indra.ai/deva';
|
|
15
|
+
import core from '@indra.ai/deva/package.json' with {type:'json'};
|
|
16
|
+
import pkg from './package.json' with {type:'json'};
|
|
17
|
+
import featureMethods from './feature/methods.js';
|
|
18
|
+
import SYSTEMS from './index.js';
|
|
19
|
+
|
|
20
|
+
const DIR = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const STAGES = ['start', 'enter', 'done', 'ready'];
|
|
22
|
+
const TIERS = ['md5', 'sha256', 'sha512'];
|
|
23
|
+
const PLACEHOLDER = /::[a-z-]+::|\{\{profile\.[a-z]+\}\}/;
|
|
24
|
+
const FEATURE_KEYS = ['systems'];
|
|
25
|
+
const CLIENT_ID = '00000000000000000000';
|
|
26
|
+
|
|
27
|
+
const digest = (data, algo) => createHash(algo).update(JSON.stringify(data)).digest('base64');
|
|
28
|
+
|
|
29
|
+
function assertTiers(stamped, label) {
|
|
30
|
+
const base = {};
|
|
31
|
+
for (const [k, v] of Object.entries(stamped)) {
|
|
32
|
+
if (!TIERS.includes(k)) base[k] = v;
|
|
33
|
+
}
|
|
34
|
+
const walk = {...base};
|
|
35
|
+
for (const t of TIERS) {
|
|
36
|
+
assert.equal(typeof stamped[t], 'string', `${label} has ${t}`);
|
|
37
|
+
assert.equal(stamped[t], digest(walk, t), `${label} ${t} covers the data and the tiers before it`);
|
|
38
|
+
walk[t] = stamped[t];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// stub client built in code: the core VLA for the core check and the agent VLA for Systems Deva.
|
|
43
|
+
// methods, when set, is bound at init from features.systems.methods by the feature loader.
|
|
44
|
+
// restricted lists the lowercase field names that systems() masks. smoke is a nested block with an id,
|
|
45
|
+
// secret is a top-level restricted field, and visible is a top-level field that stays readable.
|
|
46
|
+
const client = (agentVLA = pkg.VLA, methods = false) => ({
|
|
47
|
+
id: CLIENT_ID,
|
|
48
|
+
key: 'client',
|
|
49
|
+
VLA: structuredClone(core.VLA),
|
|
50
|
+
prompt: {
|
|
51
|
+
emoji: '🧪',
|
|
52
|
+
text: 'client',
|
|
53
|
+
colors: {
|
|
54
|
+
label: {R: 2, G: 229, B: 77},
|
|
55
|
+
text: {R: 2, G: 229, B: 77},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
profile: {
|
|
59
|
+
id: CLIENT_ID,
|
|
60
|
+
name: 'Test Client',
|
|
61
|
+
describe: 'Test client for Systems Deva',
|
|
62
|
+
lang: 'en',
|
|
63
|
+
locale: 'en-US',
|
|
64
|
+
currency: 'USD',
|
|
65
|
+
},
|
|
66
|
+
features: {
|
|
67
|
+
license: {
|
|
68
|
+
concerns: [],
|
|
69
|
+
global: {},
|
|
70
|
+
devas: {
|
|
71
|
+
systems: structuredClone(agentVLA),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
systems: {
|
|
75
|
+
concerns: ['first systems concern', 'second systems concern'],
|
|
76
|
+
global: {
|
|
77
|
+
restricted: ['uri', 'password', 'secret', 'token'],
|
|
78
|
+
smoke: {id: 'g1', text: 'ok', token: 'nested-token-value', uri: 'nested-uri-value', Password: 'nested-mixed-case-value'},
|
|
79
|
+
secret: 'top-secret-value',
|
|
80
|
+
password: 'top-password-value',
|
|
81
|
+
visible: 'public-ok',
|
|
82
|
+
},
|
|
83
|
+
methods: methods || undefined,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const packet = (deva, text = 'help', params = []) => ({
|
|
89
|
+
id: deva.uid(),
|
|
90
|
+
q: {text, meta: {params}},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
function parseAnswer(text = 'parsed', html = '<p>ok</p>', data = {ok: true}) {
|
|
94
|
+
return {a: {text, html, data}};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Systems Deva onError console.logs every error that this.err hands it.
|
|
98
|
+
// the error-path test throws on purpose, so mute console.log while it runs.
|
|
99
|
+
async function withMutedLog(fn) {
|
|
100
|
+
const orig = console.log;
|
|
101
|
+
console.log = () => {};
|
|
102
|
+
try {
|
|
103
|
+
return await fn();
|
|
104
|
+
} finally {
|
|
105
|
+
console.log = orig;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let FEATURE = null;
|
|
110
|
+
|
|
111
|
+
after(async () => {
|
|
112
|
+
if (SYSTEMS._active) await SYSTEMS.stop();
|
|
113
|
+
if (FEATURE._active) await FEATURE.stop();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('systems builds as a Deva and waits offline before init', async () => {
|
|
117
|
+
assert.ok(SYSTEMS instanceof Deva, 'the export is a Deva');
|
|
118
|
+
assert.equal(SYSTEMS._agent.key, 'systems', 'agent key is systems');
|
|
119
|
+
assert.equal(SYSTEMS.agent(), SYSTEMS._messages.offline, 'agent answers offline before init');
|
|
120
|
+
assert.equal(await SYSTEMS.stop(), SYSTEMS._messages.offline, 'stop before init answers offline');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('systems data has no placeholders left', () => {
|
|
124
|
+
assert.doesNotMatch(JSON.stringify(pkg.data), PLACEHOLDER, 'package.json data');
|
|
125
|
+
assert.doesNotMatch(JSON.stringify(pkg.VLA), PLACEHOLDER, 'package.json VLA');
|
|
126
|
+
assert.doesNotMatch(pkg.copyright, PLACEHOLDER, 'package.json copyright');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('func, methods, and listeners start empty, and onInit, onReady, and onError exist', () => {
|
|
130
|
+
assert.deepEqual(Object.keys(SYSTEMS.func), [], 'func starts empty');
|
|
131
|
+
assert.deepEqual(Object.keys(SYSTEMS.methods), [], 'methods starts empty');
|
|
132
|
+
assert.deepEqual(Object.keys(SYSTEMS.listeners), [], 'listeners starts empty');
|
|
133
|
+
assert.equal(typeof SYSTEMS.onInit, 'function', 'onInit');
|
|
134
|
+
assert.equal(typeof SYSTEMS.onReady, 'function', 'onReady');
|
|
135
|
+
assert.equal(typeof SYSTEMS.onError, 'function', 'onError');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('systems comes online and walks to ready', async () => {
|
|
139
|
+
const prompts = [];
|
|
140
|
+
SYSTEMS.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
141
|
+
const data = await SYSTEMS.init(client());
|
|
142
|
+
for (const k of STAGES) assert.equal(typeof data[k], 'number', `${k} timestamp`);
|
|
143
|
+
assert.ok(data.start <= data.enter && data.enter <= data.done && data.done <= data.ready, 'stages in order');
|
|
144
|
+
assert.equal(data.value, 'init');
|
|
145
|
+
assert.equal(typeof data.id.uid, 'string', 'uid');
|
|
146
|
+
assertTiers(data, 'init packet');
|
|
147
|
+
assertTiers(data.id, 'init packet id');
|
|
148
|
+
assert.ok(prompts.includes(`${SYSTEMS.vars.messages.ready} > VLA:${pkg.VLA.uid}`), 'onReady prompts the ready message');
|
|
149
|
+
assert.ok(SYSTEMS._active, 'the Deva is active');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('systems info matches the package', () => {
|
|
153
|
+
const info = SYSTEMS.info();
|
|
154
|
+
assert.equal(info.name, '@indra.ai/deva.systems');
|
|
155
|
+
assert.equal(info.version, pkg.version);
|
|
156
|
+
assert.equal(info.id, pkg.id);
|
|
157
|
+
assert.equal(info.describe, pkg.description);
|
|
158
|
+
assert.equal(info.url, pkg.homepage);
|
|
159
|
+
assert.equal(info.git, pkg.repository.url);
|
|
160
|
+
assert.equal(info.bugs, pkg.bugs.url);
|
|
161
|
+
assert.equal(info.VLA.uid, pkg.VLA.uid);
|
|
162
|
+
assertTiers(info, 'info()');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('systems agent matches the package', () => {
|
|
166
|
+
const agent = SYSTEMS.agent();
|
|
167
|
+
const profile = pkg.data.agent.profile;
|
|
168
|
+
assert.equal(agent.key, 'systems');
|
|
169
|
+
assert.equal(agent.id, pkg.id);
|
|
170
|
+
assert.equal(agent.profile.id, pkg.id);
|
|
171
|
+
assert.equal(agent.profile.name, 'Systems Deva');
|
|
172
|
+
assert.equal(agent.profile.describe, profile.describe);
|
|
173
|
+
assert.equal(agent.profile.owner, 'Quinn Michaels');
|
|
174
|
+
assert.equal(agent.profile.creator, 'Quinn Michaels');
|
|
175
|
+
assert.equal(agent.profile.vector, '#SystemsDeva');
|
|
176
|
+
assert.equal(agent.profile.vectors, '#Quinn #QuinnMichaels #InsideTheNet #IndraAI #DEVA #DevaWorld #Systems #SystemsDeva #Merit #Demerit');
|
|
177
|
+
assert.equal(agent.profile.updated, profile.updated);
|
|
178
|
+
assertTiers(agent, 'agent()');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('systems agent warning carries the corrected spellings', () => {
|
|
182
|
+
const {warning} = SYSTEMS.agent().profile;
|
|
183
|
+
assert.match(warning, /^🖥️ Systems Deva \(he\/him\) declares /, 'warning names Systems Deva');
|
|
184
|
+
for (const word of ['MERITORIOUS', 'COMMISSION', 'INDULGENCE']) assert.ok(warning.includes(word), `warning has ${word}`);
|
|
185
|
+
for (const word of ['MERITOUS', 'COMISSION', 'INDULGANCE']) assert.ok(!warning.includes(word), `warning has no ${word}`);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('systems uid carries hash tiers and a fingerprint of its contents', () => {
|
|
189
|
+
const id = SYSTEMS.uid();
|
|
190
|
+
assert.equal(typeof id.uid, 'string', 'uid');
|
|
191
|
+
assert.ok(id.uid.length > 0, 'uid is not empty');
|
|
192
|
+
assert.equal(id.license, pkg.VLA.uid, 'license is the package VLA uid');
|
|
193
|
+
assertTiers(id, 'uid()');
|
|
194
|
+
assert.equal(id.fingerprint, digest({
|
|
195
|
+
license: id.license,
|
|
196
|
+
client: id.client,
|
|
197
|
+
agent: id.agent,
|
|
198
|
+
machine: id.machine,
|
|
199
|
+
core_hash: id.core_hash,
|
|
200
|
+
}, 'sha256'), 'fingerprint is the sha256 of license, client, agent, machine, and core_hash');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('package VLA fingerprint is the sha256 of license, client, agent, machine, and core_hash', () => {
|
|
204
|
+
const {VLA} = pkg;
|
|
205
|
+
assert.equal(VLA.uid, pkg.id, 'VLA uid is the package id');
|
|
206
|
+
assert.equal(pkg.license, `VLA:${VLA.uid} LICENSE.md`, 'license field names the VLA uid');
|
|
207
|
+
assert.equal(VLA.fingerprint, digest({
|
|
208
|
+
license: VLA.license,
|
|
209
|
+
client: VLA.client,
|
|
210
|
+
agent: VLA.agent,
|
|
211
|
+
machine: VLA.machine,
|
|
212
|
+
core_hash: VLA.core_hash,
|
|
213
|
+
}, 'sha256'), 'package fingerprint matches its contents');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('systems status returns the active-since string', () => {
|
|
217
|
+
const status = SYSTEMS.status();
|
|
218
|
+
assert.equal(typeof status, 'string', 'status is a string');
|
|
219
|
+
assert.match(status, /^Systems Deva active since /, 'status names the Deva and the start time');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('systems utils answer with trimmed text', () => {
|
|
223
|
+
const {translate, parse, process} = SYSTEMS.utils;
|
|
224
|
+
for (const util of [translate, parse, process]) assert.equal(util(' hello '), 'hello');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('systems vars include the ready message, trigger, and empty context', () => {
|
|
228
|
+
assert.equal(SYSTEMS.vars.messages.ready, '🖥️ Systems Deva Ready');
|
|
229
|
+
assert.equal(SYSTEMS.vars.trigger, '@SYSTEMS');
|
|
230
|
+
assert.deepEqual(SYSTEMS.vars.context, {}, 'context starts empty');
|
|
231
|
+
assert.deepEqual(SYSTEMS.vars.ask.history, [], 'ask history starts empty');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('systems help pages match the files and carry the package license', async () => {
|
|
235
|
+
const main = await SYSTEMS.help('main', DIR);
|
|
236
|
+
assert.match(main, /^# \{\{profile\.name\}\}$/m, 'main help heading as in help/main.feecting');
|
|
237
|
+
assert.match(main, /^#bg = \{\{profile\.background\}\}$/m, 'main help uses profile.background');
|
|
238
|
+
const corpus = await SYSTEMS.help('corpus', DIR);
|
|
239
|
+
assert.match(corpus, /^# \{\{profile\.name\}\}$/m, 'corpus help heading');
|
|
240
|
+
const license = await SYSTEMS.help('main:license', DIR);
|
|
241
|
+
assert.match(license, new RegExp(`^\\s*uid: ${pkg.VLA.uid}$`, 'm'), 'license uid');
|
|
242
|
+
assert.match(license, new RegExp(`^\\s*fingerprint: ${pkg.VLA.fingerprint.replaceAll('+', '\\+')}$`, 'm'), 'license fingerprint');
|
|
243
|
+
for (const t of TIERS) assert.ok(license.includes(`${t}: ${pkg.VLA[t]}`), `${t} hash in the license help`);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('feature/methods.js exports only the current methods', () => {
|
|
247
|
+
assert.deepEqual(Object.keys(featureMethods), FEATURE_KEYS, 'feature export names');
|
|
248
|
+
for (const key of FEATURE_KEYS) assert.equal(typeof featureMethods[key], 'function', `feature.${key}`);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('systems stops through the full chain', async () => {
|
|
252
|
+
const data = await SYSTEMS.stop();
|
|
253
|
+
assert.equal(data.key, 'shutdown', 'the chain ends on shutdown');
|
|
254
|
+
assert.equal(data.value, 'systems');
|
|
255
|
+
assert.equal(SYSTEMS._active, false, 'the Deva is offline after stop');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// the feature loader binds client.features.systems.methods onto the Deva at init.
|
|
259
|
+
// this uses a fresh instance after SYSTEMS has stopped so only one systems Deva is active on the shared event bus.
|
|
260
|
+
test('feature methods from feature/methods.js load at runtime', async () => {
|
|
261
|
+
({default: FEATURE} = await import('./index.js?feature'));
|
|
262
|
+
const data = await FEATURE.init(client(pkg.VLA, featureMethods));
|
|
263
|
+
assert.equal(typeof data.ready, 'number', 'feature instance reaches ready');
|
|
264
|
+
for (const key of FEATURE_KEYS) assert.equal(typeof FEATURE.methods[key], 'function', `the feature loader binds ${key}`);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('methods.systems returns the parsed concerns and id end tags', async () => {
|
|
268
|
+
const orig = FEATURE.question.bind(FEATURE);
|
|
269
|
+
let asked = '';
|
|
270
|
+
FEATURE.question = async text => {
|
|
271
|
+
asked = String(text);
|
|
272
|
+
return parseAnswer('parsed-systems', '<p>systems</p>', {ok: true});
|
|
273
|
+
};
|
|
274
|
+
try {
|
|
275
|
+
const out = await FEATURE.methods.systems(packet(FEATURE));
|
|
276
|
+
assert.equal(out.text, 'parsed-systems');
|
|
277
|
+
assert.equal(out.html, '<p>systems</p>');
|
|
278
|
+
assert.deepEqual(out.data, ['first systems concern', 'second systems concern'], 'data is the systems concerns');
|
|
279
|
+
assert.ok(asked.includes(`${FEATURE.askChr}feecting parse `), 'asks Feecting to parse the systems view');
|
|
280
|
+
assert.ok(asked.includes('::BEGIN:SYSTEMS'), 'opens the systems block');
|
|
281
|
+
assert.ok(asked.includes('::END:SYSTEMS'), 'closes the systems block');
|
|
282
|
+
assert.ok(asked.includes(`::begin:client:${CLIENT_ID}`), 'client begin tag uses the client id');
|
|
283
|
+
assert.ok(asked.includes(`id: ${CLIENT_ID}`), 'client id line');
|
|
284
|
+
assert.ok(asked.includes('client: Test Client'), 'client name line');
|
|
285
|
+
assert.ok(asked.includes('1. first systems concern'), 'concerns are numbered from 1');
|
|
286
|
+
assert.ok(asked.includes('2. second systems concern'), 'every concern is listed');
|
|
287
|
+
assert.match(asked, new RegExp(`::end:client:${CLIENT_ID}(?:\\n|$)`), 'client end tag is the client id with no hash suffix');
|
|
288
|
+
assert.match(asked, /::end:global:smoke:g1(?:\n|$)/, 'global end tag is item.id with no hash suffix');
|
|
289
|
+
assert.ok(asked.includes('::begin:global:smoke:g1'), 'global begin tag uses key and item.id');
|
|
290
|
+
} finally {
|
|
291
|
+
FEATURE.question = orig;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('methods.systems masks every restricted field and keeps the rest readable', async () => {
|
|
296
|
+
const orig = FEATURE.question.bind(FEATURE);
|
|
297
|
+
let asked = '';
|
|
298
|
+
FEATURE.question = async text => {
|
|
299
|
+
asked = String(text);
|
|
300
|
+
return parseAnswer();
|
|
301
|
+
};
|
|
302
|
+
try {
|
|
303
|
+
await FEATURE.methods.systems(packet(FEATURE));
|
|
304
|
+
assert.ok(asked.includes('token: *******'), 'nested token is masked');
|
|
305
|
+
assert.ok(asked.includes('uri: *******'), 'nested uri is masked');
|
|
306
|
+
assert.ok(asked.includes('Password: *******'), 'a mixed case restricted field name is masked');
|
|
307
|
+
assert.ok(asked.includes('secret: *******'), 'top-level secret is masked');
|
|
308
|
+
assert.ok(asked.includes('password: *******'), 'top-level password is masked');
|
|
309
|
+
assert.ok(asked.includes('text: ok'), 'nested field that is not restricted stays readable');
|
|
310
|
+
assert.ok(asked.includes('visible: public-ok'), 'top-level field that is not restricted stays readable');
|
|
311
|
+
for (const value of ['nested-token-value', 'nested-uri-value', 'nested-mixed-case-value', 'top-secret-value', 'top-password-value']) {
|
|
312
|
+
assert.ok(!asked.includes(value), `${value} does not leak`);
|
|
313
|
+
}
|
|
314
|
+
assert.ok(!asked.includes('::begin:global:restricted:'), 'restricted list is not printed as a block');
|
|
315
|
+
assert.ok(!asked.includes('restricted'), 'restricted list is not printed at all');
|
|
316
|
+
} finally {
|
|
317
|
+
FEATURE.question = orig;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// the timeout makes a broken this.err fail the test instead of leaving the promise pending forever.
|
|
322
|
+
test('methods.systems routes a question rejection through this.err', {timeout: 10000}, async () => {
|
|
323
|
+
const origQuestion = FEATURE.question.bind(FEATURE);
|
|
324
|
+
const origErr = FEATURE.err.bind(FEATURE);
|
|
325
|
+
const calls = [];
|
|
326
|
+
FEATURE.question = async () => {
|
|
327
|
+
throw new Error('feecting-parse-fail');
|
|
328
|
+
};
|
|
329
|
+
FEATURE.err = (err, pkt, reject) => {
|
|
330
|
+
calls.push({message: err.message, hasPacket: !!pkt, hasReject: typeof reject === 'function'});
|
|
331
|
+
return origErr(err, pkt, reject);
|
|
332
|
+
};
|
|
333
|
+
try {
|
|
334
|
+
await withMutedLog(async () => {
|
|
335
|
+
await assert.rejects(
|
|
336
|
+
FEATURE.methods.systems(packet(FEATURE)),
|
|
337
|
+
err => err.message === 'feecting-parse-fail',
|
|
338
|
+
'systems rejects with the question error'
|
|
339
|
+
);
|
|
340
|
+
});
|
|
341
|
+
assert.equal(calls.length, 1, 'this.err is called once');
|
|
342
|
+
assert.equal(calls[0].message, 'feecting-parse-fail');
|
|
343
|
+
assert.equal(calls[0].hasPacket, true, 'this.err receives the packet');
|
|
344
|
+
assert.equal(calls[0].hasReject, true, 'this.err receives reject');
|
|
345
|
+
} finally {
|
|
346
|
+
FEATURE.question = origQuestion;
|
|
347
|
+
FEATURE.err = origErr;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// the refusal check loads a fresh Systems Deva instance from the same file, so it starts from a clean state.
|
|
352
|
+
// onInit runs the agent license check, so a bad agent VLA stops the Deva before it goes active.
|
|
353
|
+
test('systems refuses to start with a bad agent VLA', async () => {
|
|
354
|
+
if (FEATURE._active) await FEATURE.stop();
|
|
355
|
+
const {default: REFUSE} = await import('./index.js?refuse');
|
|
356
|
+
const prompts = [];
|
|
357
|
+
REFUSE.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
358
|
+
const result = await REFUSE.init(client({uid: 'bad'}));
|
|
359
|
+
assert.equal(result, REFUSE._messages.checkVLA, 'init answers with the invalid VLA message');
|
|
360
|
+
assert.ok(prompts.includes(REFUSE._messages.checkVLA), 'core prompts the invalid VLA message');
|
|
361
|
+
assert.equal(REFUSE._active, false, 'the Deva stays offline');
|
|
362
|
+
});
|