@indra.ai/deva.report 0.24.3 → 0.24.5
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 +186 -3
- package/feature/methods.js +4 -5
- package/index.js +72 -84
- package/index.test.js +234 -1
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -1,7 +1,190 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Report Deva
|
|
2
|
+
|
|
3
|
+
Report Deva is the chain-of-custody reporting agent for Indra.ai and Deva.world. Its agent key is `report`. It writes report packets into a MongoDB `reports` collection. Commands talk to it directly with `/write` or, from another Deva, with `#report write`.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js with npm. Report 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`. Report Deva is an ES module.
|
|
9
|
+
- `@indra.ai/deva` `^1.67.26` (Deva Core) and `mongodb` `^6.1.0`. Both install with Report Deva.
|
|
10
|
+
- A MongoDB server if you want reports saved. A local `mongod` at `mongodb://127.0.0.1:27017` is enough.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @indra.ai/deva.report --save
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import ReportDeva from '@indra.ai/deva.report';
|
|
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.report`. Deva Core 1.67.26 checks it against the VLA in Report Deva's own `package.json` right after the features load and before `onInit`. Report Deva has no `onInit` of its own, so it has no license check of its own to change or remove.
|
|
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
|
+
Report 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
|
+
"report": {"uid": "28986758608512849090"}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"report": {
|
|
45
|
+
"concerns": [],
|
|
46
|
+
"global": {
|
|
47
|
+
"mongo": {
|
|
48
|
+
"uri": "mongodb://127.0.0.1:27017",
|
|
49
|
+
"database": "ReportDeva"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"devas": {
|
|
53
|
+
"report": {
|
|
54
|
+
"mongo": {
|
|
55
|
+
"uri": "mongodb://127.0.0.1:27017",
|
|
56
|
+
"database": "ReportDeva"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- `license.devas.report` 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:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import pkg from '@indra.ai/deva.report/package.json' with {type:'json'};
|
|
68
|
+
|
|
69
|
+
const devas = {report: pkg.VLA}; // goes in features.license.devas
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- `report.global.mongo.uri` is the MongoDB connection string. If it is not set, Report Deva still comes online but builds no MongoDB client, and `write` rejects.
|
|
73
|
+
- `report.global.mongo.database` is the database name. `onReady` stores it in `this.vars.database`. `write` inserts into the `reports` collection in that database.
|
|
74
|
+
- The tests also set `report.devas.report` with the same `{uri, database}` shape. That is the personal record for this agent (`agent.key` is `report`). Deva Core exposes it as `this.report().personal`. `onReady` and `write` read only `this.report().global?.mongo`. They do not use the personal record.
|
|
75
|
+
|
|
76
|
+
## Load it
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import ReportDeva from '@indra.ai/deva.report';
|
|
80
|
+
|
|
81
|
+
const report = await ReportDeva.init(client); // client data provided by your loader
|
|
82
|
+
console.log(report.id.uid);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
When the license checks pass, Report Deva walks start, enter, done and ready. In `onReady` it reads `this.report().global?.mongo`, builds a `MongoClient` in `this.modules.client` when `uri` is set, keeps `database` in `this.vars.database`, and prompts `📊 Report Deva Ready > VLA:28986758608512849090`.
|
|
86
|
+
|
|
87
|
+
To shut it down:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
await ReportDeva.stop();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`onStop` closes the MongoDB client, if there is one, then calls `this.close(data, resolve)`. If there is no client, it calls `this.close(data, resolve)` directly. A stopped Deva can start again. Call `init()` again with a client that passes the license check. Report Deva builds a new MongoDB client in `onReady`.
|
|
94
|
+
|
|
95
|
+
## When Report Deva refuses to start
|
|
96
|
+
|
|
97
|
+
If the agent license check fails, Deva Core prompts the message, stops the Deva, and `init()` resolves with that message.
|
|
98
|
+
|
|
99
|
+
| You see | Why |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `❌ Bad Personal VLA` | `features.license.devas` is there but has no `report` entry. |
|
|
102
|
+
| `❌ Invalid VLA Check` | The `report` entry doesn't match this package's VLA, or the license feature has no `devas`. |
|
|
103
|
+
|
|
104
|
+
## Commands
|
|
105
|
+
|
|
106
|
+
Talk to Report Deva with `/write` when it is the current agent, or with `#report write` from another Deva.
|
|
107
|
+
|
|
108
|
+
| Command | What it does |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `/write` | Inserts the command packet into the `reports` collection of `this.vars.database`. It returns `{text: 'see data', html: '<p>see data</p>', data}`, where `data` is the MongoDB `insertOne` result (`acknowledged` and `insertedId`). |
|
|
111
|
+
|
|
112
|
+
`methods.write(packet)` is the method behind that command. It always calls `func.write('reports', packet)` and returns that same `{text, html, data}` object. The packet is stored as it was passed in. If there is no MongoDB client, or the insert fails, `methods.write` catches the error and returns `this.err(err, packet)`, which goes through `onError`. The write rejects. It does not hang, and it does not resolve with empty data.
|
|
113
|
+
|
|
114
|
+
## Functions
|
|
115
|
+
|
|
116
|
+
| Func | What it does |
|
|
117
|
+
| --- | --- |
|
|
118
|
+
| `write` | Inserts `packet` into collection `type` in `this.vars.database`, using the one `MongoClient` in `this.modules.client`. It returns the `insertOne` result. `methods.write` always calls it with `type` set to `reports`. There is no try/catch in `func.write`; a missing client or a failed insert throws, and `methods.write` handles it. |
|
|
119
|
+
|
|
120
|
+
## Feature methods
|
|
121
|
+
|
|
122
|
+
`feature/methods.js` exports a `report(packet)` method. The feature loader binds it at runtime from `client.features.report.methods` onto the Deva's `methods`. In 0.24.4 the method returns `{}`.
|
|
123
|
+
|
|
124
|
+
## Help
|
|
125
|
+
|
|
126
|
+
Help lives in two Feecting files. `help/main.feecting` is the main help page, with the heading `{{profile.name}}`, and it also holds the license block. `help/corpus.feecting` is the help corpus. The tests check that the main heading is there and that the license page carries this package's VLA uid and hash tiers.
|
|
127
|
+
|
|
128
|
+
## Inside Report Deva
|
|
129
|
+
|
|
130
|
+
| Name | Kind | What it does |
|
|
131
|
+
| --- | --- | --- |
|
|
132
|
+
| `write` | func | Inserts a packet into a named collection, as described above. It lives in `index.js`. |
|
|
133
|
+
| `write` | method | The `/write` command, also in `index.js`. |
|
|
134
|
+
| `translate`, `parse`, `process` | utils | Each returns its input trimmed. |
|
|
135
|
+
| `onReady` | lifecycle | Builds the MongoDB client from the report feature's `global.mongo` and prompts the ready message. |
|
|
136
|
+
| `onStop` | lifecycle | Closes the MongoDB client, if there is one, then calls `this.close(data, resolve)`. |
|
|
137
|
+
| `onError` | lifecycle | Prompts `💣 ERROR!`, logs the error, and returns `reject(err)` or `Promise.reject(err)`. |
|
|
138
|
+
| `modules.client` | module | The `MongoClient`, set in `onReady` when a `uri` is given. |
|
|
139
|
+
|
|
140
|
+
The `vars` in `package.json` hold the prompt `messages`. `this.vars.database` is set in `onReady` from `global.mongo.database`.
|
|
141
|
+
|
|
142
|
+
## Testing
|
|
143
|
+
|
|
144
|
+
Start a local MongoDB, then run:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
node --test
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The package.json `test` script is `node --test`, so `npm test` runs the same file. The tests use `mongodb://127.0.0.1:27017` by default. To use another server, set `MONGO_URI`:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
MONGO_URI="mongodb://127.0.0.1:27018" node --test
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The tests always write to their own database, `deva_report_test`, and drop it when they finish. Only the server can change, so the cleanup never touches another database. If MongoDB can't be reached, the MongoDB tests are skipped with a message and the rest still run, including the check that `write` rejects when no MongoDB client is built.
|
|
157
|
+
|
|
158
|
+
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 cover:
|
|
159
|
+
|
|
160
|
+
- report builds as a Deva and waits offline before init
|
|
161
|
+
- report data has no placeholders left
|
|
162
|
+
- `methods.write`, `func.write`, `onReady`, `onStop`, and `onError` exist
|
|
163
|
+
- report comes online and walks to ready
|
|
164
|
+
- report agent matches the package
|
|
165
|
+
- report utils answer with trimmed text
|
|
166
|
+
- report help pages name the Deva and carry the package license
|
|
167
|
+
- feature methods from `feature/methods.js` load at runtime
|
|
168
|
+
- `write` inserts a document into the `reports` collection (MongoDB)
|
|
169
|
+
- `write` rejects when no MongoDB client is built
|
|
170
|
+
- a stop and `init` restart builds a new MongoClient and can write again (MongoDB)
|
|
171
|
+
- report stops through the full chain
|
|
172
|
+
- report refuses to start with a bad agent VLA
|
|
173
|
+
|
|
174
|
+
## Files
|
|
175
|
+
|
|
176
|
+
| File | What it holds |
|
|
177
|
+
| --- | --- |
|
|
178
|
+
| `index.js` | The Report Deva: utils, `func.write`, `methods.write`, and the lifecycle hooks. |
|
|
179
|
+
| `package.json` | Package info, the package VLA, and the agent and vars data under `data`. |
|
|
180
|
+
| `feature/methods.js` | The `report(packet)` feature method that the feature loader binds at runtime. |
|
|
181
|
+
| `help/main.feecting` | The main help page and the license block. |
|
|
182
|
+
| `help/corpus.feecting` | The help corpus. |
|
|
183
|
+
| `index.test.js` | The tests. |
|
|
184
|
+
| `assets/` | The emoji, avatar, background and main images. |
|
|
185
|
+
| `LICENSE.md` | The license. |
|
|
3
186
|
|
|
4
187
|
Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
5
188
|
Owner Signature Required For Lawful Use.
|
|
6
189
|
Distributed under VLA:28986758608512849090 LICENSE.md
|
|
7
|
-
Tuesday, November 24, 2026 - 11:57:52 AM PST
|
|
190
|
+
Tuesday, November 24, 2026 - 11:57:52 AM PST
|
package/feature/methods.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Report Deva Feature Methods
|
|
3
|
-
// Copyright ©2000-2026 Quinn
|
|
3
|
+
// Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
4
4
|
// Owner Signature Required For Lawful Use.
|
|
5
|
-
// Distributed under VLA:
|
|
6
|
-
//
|
|
5
|
+
// Distributed under VLA:28986758608512849090 LICENSE.md
|
|
6
|
+
// Tuesday, November 24, 2026 - 11:57:52 AM PST
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
async report(packet) {
|
|
10
|
-
|
|
11
|
-
return report;
|
|
10
|
+
return {};
|
|
12
11
|
}
|
|
13
12
|
};
|
package/index.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// Tuesday, November 24, 2026 - 11:57:52 AM PST
|
|
7
7
|
|
|
8
8
|
import Deva from '@indra.ai/deva';
|
|
9
|
-
// import research from '/Users/quinnmichaels/Dev/deva.space/devas/deva.research/index.js'
|
|
10
9
|
|
|
11
10
|
import {MongoClient} from 'mongodb';
|
|
12
11
|
import pkg from './package.json' with {type:'json'};
|
|
@@ -17,91 +16,80 @@ import {fileURLToPath} from 'node:url';
|
|
|
17
16
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
17
|
|
|
19
18
|
const info = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
id: pkg.id,
|
|
20
|
+
name: pkg.name,
|
|
21
|
+
version: pkg.version,
|
|
22
|
+
author: pkg.author,
|
|
23
|
+
describe: pkg.description,
|
|
24
|
+
dir: __dirname,
|
|
25
|
+
url: pkg.homepage,
|
|
26
|
+
git: pkg.repository.url,
|
|
27
|
+
bugs: pkg.bugs.url,
|
|
28
|
+
license: pkg.license,
|
|
29
|
+
VLA: pkg.VLA,
|
|
30
|
+
copyright: pkg.copyright,
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
const ReportDeva = new Deva({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
onStop(data, resolve) {
|
|
97
|
-
const {client} = this.modules;
|
|
98
|
-
if (!client) return this.close(data, resolve);
|
|
99
|
-
return client.close().then(() => this.close(data, resolve)); // close the database before shutdown
|
|
100
|
-
},
|
|
101
|
-
onError(err, data, reject) {
|
|
102
|
-
this.prompt(this.vars.messages.error);
|
|
103
|
-
console.log(err);
|
|
104
|
-
return reject ? reject(err) : Promise.reject(err);
|
|
105
|
-
}
|
|
34
|
+
info,
|
|
35
|
+
agent,
|
|
36
|
+
vars,
|
|
37
|
+
utils: {
|
|
38
|
+
translate(input) {return input.trim();},
|
|
39
|
+
parse(input) {return input.trim();},
|
|
40
|
+
process(input) {return input.trim();}
|
|
41
|
+
},
|
|
42
|
+
listeners: {},
|
|
43
|
+
devas: {
|
|
44
|
+
// research,
|
|
45
|
+
},
|
|
46
|
+
modules: {
|
|
47
|
+
client: false,
|
|
48
|
+
},
|
|
49
|
+
func: {
|
|
50
|
+
/**************
|
|
51
|
+
func: write
|
|
52
|
+
params: type, packet
|
|
53
|
+
describe: this is the log file writer function that handles writing
|
|
54
|
+
the interactions to json log file.
|
|
55
|
+
***************/
|
|
56
|
+
async write(type, packet) {
|
|
57
|
+
const database = this.modules.client.db(this.vars.database);
|
|
58
|
+
const collection = database.collection(type);
|
|
59
|
+
return await collection.insertOne(packet);
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
methods: {
|
|
63
|
+
async write(packet) {
|
|
64
|
+
try {
|
|
65
|
+
const report = await this.func.write('reports', packet);
|
|
66
|
+
return {
|
|
67
|
+
text: 'see data',
|
|
68
|
+
html: '<p>see data</p>',
|
|
69
|
+
data: report,
|
|
70
|
+
};
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return this.err(err, packet);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
onReady(data, resolve) {
|
|
77
|
+
const {VLA} = this.info();
|
|
78
|
+
const {uri,database} = this.report().global?.mongo || {};
|
|
79
|
+
if (uri) this.modules.client = new MongoClient(uri); // build the client if uri is set
|
|
80
|
+
this.vars.database = database;
|
|
81
|
+
this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
|
|
82
|
+
return resolve(data);
|
|
83
|
+
},
|
|
84
|
+
onStop(data, resolve) {
|
|
85
|
+
const {client} = this.modules;
|
|
86
|
+
if (!client) return this.close(data, resolve);
|
|
87
|
+
return client.close().then(() => this.close(data, resolve)); // close the database before shutdown
|
|
88
|
+
},
|
|
89
|
+
onError(err, data, reject) {
|
|
90
|
+
this.prompt(this.vars.messages.error);
|
|
91
|
+
console.log(err);
|
|
92
|
+
return reject ? reject(err) : Promise.reject(err);
|
|
93
|
+
}
|
|
106
94
|
});
|
|
107
95
|
export default ReportDeva
|
package/index.test.js
CHANGED
|
@@ -1,7 +1,240 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Report Deva Test File
|
|
3
|
-
// Copyright ©2000-2026 Quinn
|
|
3
|
+
// Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
4
4
|
// Owner Signature Required For Lawful Use.
|
|
5
5
|
// Distributed under VLA:28986758608512849090 LICENSE.md
|
|
6
6
|
// Tuesday, November 24, 2026 - 11:57:52 AM PST
|
|
7
7
|
|
|
8
|
+
// run with: npm test
|
|
9
|
+
// MongoDB tests use a local server at mongodb://127.0.0.1:27017 by default. Set MONGO_URI to use another one.
|
|
10
|
+
// They skip with a message when MongoDB can't be reached.
|
|
11
|
+
import test, {after} from 'node:test';
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import {execFile} from 'node:child_process';
|
|
14
|
+
import {promisify} from 'node:util';
|
|
15
|
+
import {dirname} from 'node:path';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {MongoClient} from 'mongodb';
|
|
18
|
+
import Deva from '@indra.ai/deva';
|
|
19
|
+
import core from '@indra.ai/deva/package.json' with {type:'json'};
|
|
20
|
+
import pkg from './package.json' with {type:'json'};
|
|
21
|
+
import featureMethods from './feature/methods.js';
|
|
22
|
+
import REPORT from './index.js';
|
|
23
|
+
|
|
24
|
+
const DIR = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const STAGES = ['start', 'enter', 'done', 'ready'];
|
|
26
|
+
const TIERS = ['md5', 'sha256', 'sha512'];
|
|
27
|
+
const PLACEHOLDER = /::[a-z-]+::|\{\{profile\.[a-z]+\}\}/;
|
|
28
|
+
|
|
29
|
+
// test database: the uri can change, the database name is fixed so the after hook only ever drops the test database.
|
|
30
|
+
const MONGO_URI = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017';
|
|
31
|
+
const REPORT_DB = 'deva_report_test';
|
|
32
|
+
|
|
33
|
+
// check the server once before the tests are defined so the MongoDB tests can skip cleanly.
|
|
34
|
+
const mongo = new MongoClient(MONGO_URI, {serverSelectionTimeoutMS: 2000});
|
|
35
|
+
const MONGO_SKIP = await mongo.db('admin').command({ping: 1}).then(
|
|
36
|
+
() => false,
|
|
37
|
+
err => `MongoDB is not reachable at ${MONGO_URI} (${err.message}). Start a local mongod or set MONGO_URI.`
|
|
38
|
+
);
|
|
39
|
+
if (MONGO_SKIP) console.log(`⏭️ ${MONGO_SKIP}`);
|
|
40
|
+
|
|
41
|
+
// stub client built in code: the core VLA for the core check, the agent VLA for Report Deva
|
|
42
|
+
// and the mongo settings for the report feature. useMongo false leaves the report feature without a database.
|
|
43
|
+
const client = (agentVLA = pkg.VLA, useMongo = true, uri = MONGO_URI, methods = false) => ({
|
|
44
|
+
id: '00000000000000000000',
|
|
45
|
+
key: 'client',
|
|
46
|
+
VLA: structuredClone(core.VLA),
|
|
47
|
+
prompt: {
|
|
48
|
+
emoji: '🧪',
|
|
49
|
+
text: 'client',
|
|
50
|
+
colors: {
|
|
51
|
+
label: {R: 2, G: 229, B: 77},
|
|
52
|
+
text: {R: 2, G: 229, B: 77},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
profile: {
|
|
56
|
+
id: '00000000000000000000',
|
|
57
|
+
name: 'Test Client',
|
|
58
|
+
describe: 'Test client for Report Deva',
|
|
59
|
+
lang: 'en',
|
|
60
|
+
locale: 'en-US',
|
|
61
|
+
currency: 'USD',
|
|
62
|
+
},
|
|
63
|
+
features: {
|
|
64
|
+
license: {
|
|
65
|
+
concerns: [],
|
|
66
|
+
global: [],
|
|
67
|
+
devas: {
|
|
68
|
+
report: structuredClone(agentVLA),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
report: {
|
|
72
|
+
concerns: [],
|
|
73
|
+
global: useMongo ? {mongo: {uri, database: REPORT_DB}} : {},
|
|
74
|
+
devas: useMongo ? {report: {mongo: {uri, database: REPORT_DB}}} : {},
|
|
75
|
+
methods: methods || undefined,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let reportClient = false; // Report Deva's own MongoClient, kept so the after hook can close it.
|
|
81
|
+
|
|
82
|
+
after(async () => {
|
|
83
|
+
if (!MONGO_SKIP) {
|
|
84
|
+
await mongo.db(REPORT_DB).dropDatabase();
|
|
85
|
+
}
|
|
86
|
+
await mongo.close();
|
|
87
|
+
if (reportClient) await reportClient.close();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('report builds as a Deva and waits offline before init', async () => {
|
|
91
|
+
assert.ok(REPORT instanceof Deva, 'the export is a Deva');
|
|
92
|
+
assert.equal(await REPORT.stop(), REPORT._messages.offline, 'stop before init answers offline');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('report data has no placeholders left', () => {
|
|
96
|
+
assert.doesNotMatch(JSON.stringify(pkg.data), PLACEHOLDER, 'package.json data');
|
|
97
|
+
assert.doesNotMatch(JSON.stringify(pkg.VLA), PLACEHOLDER, 'package.json VLA');
|
|
98
|
+
assert.doesNotMatch(pkg.copyright, PLACEHOLDER, 'package.json copyright');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('methods.write, func.write, onReady, onStop, and onError exist', () => {
|
|
102
|
+
assert.equal(typeof REPORT.methods.write, 'function', 'methods.write');
|
|
103
|
+
assert.equal(typeof REPORT.func.write, 'function', 'func.write');
|
|
104
|
+
assert.equal(typeof REPORT.onReady, 'function', 'onReady');
|
|
105
|
+
assert.equal(typeof REPORT.onStop, 'function', 'onStop');
|
|
106
|
+
assert.equal(typeof REPORT.onError, 'function', 'onError');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('report comes online and walks to ready', async () => {
|
|
110
|
+
const prompts = [];
|
|
111
|
+
REPORT.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
112
|
+
const data = await REPORT.init(client());
|
|
113
|
+
for (const k of STAGES) assert.equal(typeof data[k], 'number', `${k} timestamp`);
|
|
114
|
+
assert.ok(data.start <= data.enter && data.enter <= data.done && data.done <= data.ready, 'stages in order');
|
|
115
|
+
assert.equal(typeof data.id.uid, 'string', 'uid');
|
|
116
|
+
for (const t of TIERS) assert.equal(typeof data[t], 'string', `${t} hash`);
|
|
117
|
+
assert.ok(prompts.includes(`${REPORT.vars.messages.ready} > VLA:${pkg.VLA.uid}`), 'onReady prompts the ready message');
|
|
118
|
+
assert.ok(REPORT.modules.client instanceof MongoClient, 'onReady builds the MongoClient');
|
|
119
|
+
assert.equal(REPORT.vars.database, REPORT_DB, 'onReady sets the report database');
|
|
120
|
+
reportClient = REPORT.modules.client;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('report agent matches the package', () => {
|
|
124
|
+
const agent = REPORT.agent();
|
|
125
|
+
assert.equal(agent.key, 'report');
|
|
126
|
+
assert.equal(agent.id, pkg.id);
|
|
127
|
+
assert.equal(agent.profile.id, pkg.id);
|
|
128
|
+
assert.equal(agent.profile.name, 'Report Deva');
|
|
129
|
+
assert.equal(agent.profile.owner, 'Quinn Michaels');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('report utils answer with trimmed text', () => {
|
|
133
|
+
const {translate, parse, process} = REPORT.utils;
|
|
134
|
+
for (const util of [translate, parse, process]) assert.equal(util(' hello '), 'hello');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('report help pages name the Deva and carry the package license', async () => {
|
|
138
|
+
const main = await REPORT.help('main', DIR);
|
|
139
|
+
assert.match(main, /^# \{\{profile\.name\}\}$/m, 'main help heading');
|
|
140
|
+
const license = await REPORT.help('main:license', DIR);
|
|
141
|
+
assert.match(license, new RegExp(`^uid: ${pkg.VLA.uid}$`, 'm'), 'license uid');
|
|
142
|
+
for (const t of TIERS) assert.ok(license.includes(`${t}: ${pkg.VLA[t]}`), `${t} hash in the license help`);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// the feature loader binds client.features.report.methods onto the Deva at init.
|
|
146
|
+
// this uses a fresh instance so it does not change the methods on REPORT.
|
|
147
|
+
test('feature methods from feature/methods.js load at runtime', async () => {
|
|
148
|
+
assert.deepEqual(Object.keys(featureMethods), ['report'], 'feature export names');
|
|
149
|
+
assert.equal(typeof featureMethods.report, 'function', 'feature.report');
|
|
150
|
+
const {default: FEATURE} = await import('./index.js?feature');
|
|
151
|
+
const data = await FEATURE.init(client(pkg.VLA, false, MONGO_URI, featureMethods));
|
|
152
|
+
assert.equal(typeof data.ready, 'number', 'feature instance reaches ready');
|
|
153
|
+
assert.equal(typeof FEATURE.methods.report, 'function', 'the feature loader binds report');
|
|
154
|
+
assert.equal(typeof FEATURE.methods.write, 'function', 'write stays on methods');
|
|
155
|
+
await FEATURE.stop();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('write inserts a document into the reports collection', {skip: MONGO_SKIP}, async () => {
|
|
159
|
+
const payload = {id: {uid: 'write-test-1'}, content: 'hello report', created: Date.now()};
|
|
160
|
+
const ans = await REPORT.methods.write(payload);
|
|
161
|
+
assert.equal(ans.text, 'see data');
|
|
162
|
+
assert.equal(ans.data.acknowledged, true);
|
|
163
|
+
const doc = await mongo.db(REPORT_DB).collection('reports').findOne({'id.uid': 'write-test-1'});
|
|
164
|
+
assert.equal(doc?.content, 'hello report');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// runs in a child process with a fresh Report Deva and no database, so it does not
|
|
168
|
+
// share the bound func object or MongoClient with the tests that use REPORT.
|
|
169
|
+
test('write rejects when no MongoDB client is built', async () => {
|
|
170
|
+
const code = [
|
|
171
|
+
`const {default: REPORT} = await import(${JSON.stringify(new URL('./index.js', import.meta.url).href)});`,
|
|
172
|
+
'await REPORT.init(JSON.parse(process.env.REPORT_TEST_CLIENT));',
|
|
173
|
+
"const payload = {id: {uid: 'write-missing-1'}, content: 'no mongo'};",
|
|
174
|
+
'for (const [label, run] of [',
|
|
175
|
+
" ['func.write', () => REPORT.func.write('reports', payload)],",
|
|
176
|
+
" ['methods.write', () => REPORT.methods.write(payload)],",
|
|
177
|
+
" ['/write', () => REPORT.question('/write', payload)],",
|
|
178
|
+
']) {',
|
|
179
|
+
' try {',
|
|
180
|
+
' let timer;',
|
|
181
|
+
' await Promise.race([',
|
|
182
|
+
' run(),',
|
|
183
|
+
' new Promise((_, reject) => {timer = setTimeout(() => reject(new Error("TIMEOUT")), 8000);}),',
|
|
184
|
+
' ]).finally(() => clearTimeout(timer));',
|
|
185
|
+
' console.log(`RESOLVED:${label}`);',
|
|
186
|
+
' process.exit(2);',
|
|
187
|
+
' } catch (err) {',
|
|
188
|
+
' if (/TIMEOUT/.test(err.message)) {',
|
|
189
|
+
' console.log(`BAD:${label}:${err.message}`);',
|
|
190
|
+
' process.exit(3);',
|
|
191
|
+
' }',
|
|
192
|
+
' console.log(`REJECTED:${label}`);',
|
|
193
|
+
' }',
|
|
194
|
+
'}',
|
|
195
|
+
'await REPORT.stop();',
|
|
196
|
+
'console.log("RESULT:ok");',
|
|
197
|
+
].join('\n');
|
|
198
|
+
const env = {PATH: process.env.PATH, REPORT_TEST_CLIENT: JSON.stringify(client(pkg.VLA, false))};
|
|
199
|
+
const run = promisify(execFile)(process.execPath, ['--input-type=module', '-e', code], {cwd: DIR, env, timeout: 20000, killSignal: 'SIGKILL'});
|
|
200
|
+
const {stdout} = await run.catch(err => {
|
|
201
|
+
if (err.stdout) assert.fail(err.stdout.trim());
|
|
202
|
+
const why = err.killed ? 'did not return within 20 seconds' : `failed: ${err.message}`;
|
|
203
|
+
assert.fail(`write without a MongoDB client ${why}`);
|
|
204
|
+
});
|
|
205
|
+
assert.match(stdout, /^RESULT:ok$/m, 'every write rejected without hanging');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('a stop and init restart builds a new MongoClient and can write again', {skip: MONGO_SKIP}, async () => {
|
|
209
|
+
const before = REPORT.modules.client;
|
|
210
|
+
await REPORT.stop();
|
|
211
|
+
const data = await REPORT.init(client());
|
|
212
|
+
assert.equal(typeof data.ready, 'number', 'restart reaches ready');
|
|
213
|
+
assert.ok(REPORT.modules.client instanceof MongoClient, 'restart builds a MongoClient');
|
|
214
|
+
assert.notEqual(REPORT.modules.client, before, 'the MongoClient is new');
|
|
215
|
+
reportClient = REPORT.modules.client;
|
|
216
|
+
const payload = {id: {uid: 'write-restart-1'}, content: 'after restart', created: Date.now()};
|
|
217
|
+
const ans = await REPORT.methods.write(payload);
|
|
218
|
+
assert.equal(ans.data.acknowledged, true);
|
|
219
|
+
const doc = await mongo.db(REPORT_DB).collection('reports').findOne({'id.uid': 'write-restart-1'});
|
|
220
|
+
assert.equal(doc?.content, 'after restart');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('report stops through the full chain', async () => {
|
|
224
|
+
const data = await REPORT.stop();
|
|
225
|
+
assert.equal(data.key, 'shutdown', 'the chain ends on shutdown');
|
|
226
|
+
assert.equal(data.value, 'report');
|
|
227
|
+
reportClient = false;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// the refusal check loads a fresh Report Deva instance from the same file, so it starts from a clean state.
|
|
231
|
+
test('report refuses to start with a bad agent VLA', async () => {
|
|
232
|
+
const {default: REFUSE} = await import('./index.js?refuse');
|
|
233
|
+
const prompts = [];
|
|
234
|
+
REFUSE.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
235
|
+
const result = await REFUSE.init(client({uid: 'bad'}));
|
|
236
|
+
assert.equal(result, REFUSE._messages.checkVLA, 'init answers with the invalid VLA message');
|
|
237
|
+
assert.ok(prompts.includes(REFUSE._messages.checkVLA), 'core prompts the invalid VLA message');
|
|
238
|
+
assert.equal(REFUSE._active, false, 'the Deva stays offline');
|
|
239
|
+
if (REFUSE.modules?.client) await REFUSE.modules.client.close();
|
|
240
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "28986758608512849090",
|
|
3
3
|
"name": "@indra.ai/deva.report",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.5",
|
|
5
5
|
"license": "VLA:28986758608512849090 LICENSE.md",
|
|
6
6
|
"VLA": {
|
|
7
7
|
"uid": "28986758608512849090",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
}
|
|
45
45
|
],
|
|
46
46
|
"copyright": "Copyright ©2000-2026 Quinn Michaels; All rights reserved.",
|
|
47
|
-
"description": "The Report Deva is the manager of legal lawful chain of custody reporting in Indra.ai
|
|
47
|
+
"description": "The Report Deva is the manager of legal lawful chain of custody reporting in Indra.ai and Deva.world.",
|
|
48
48
|
"homepage": "https://github.com/indraai/deva.report#readme",
|
|
49
49
|
"main": "index.js",
|
|
50
50
|
"type": "module",
|
|
51
51
|
"scripts": {
|
|
52
52
|
"latest": "npm i @indra.ai/deva@latest --save",
|
|
53
|
-
"test": "
|
|
53
|
+
"test": "node --test"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
@@ -61,8 +61,6 @@
|
|
|
61
61
|
"Deva",
|
|
62
62
|
"Report Deva",
|
|
63
63
|
"Indra.ai",
|
|
64
|
-
"Deva.space",
|
|
65
|
-
"Deva.cloud",
|
|
66
64
|
"Deva.world",
|
|
67
65
|
"Quinn Michaels",
|
|
68
66
|
"Quinn A Michaels",
|
|
@@ -104,7 +102,7 @@
|
|
|
104
102
|
"title": "Report Deva",
|
|
105
103
|
"subtitle": "Report manage in Deva.world",
|
|
106
104
|
"describe": "Report Deva manages the Reports.",
|
|
107
|
-
"tweet": "Report Deva manages the Reports in Indra.ai
|
|
105
|
+
"tweet": "Report Deva manages the Reports in Indra.ai and Deva.world.",
|
|
108
106
|
"vectors": "#Quinn #QuinnMichaels #InsideTheNet #IndraAI #DEVA #DevaWorld #ReportDeva #RigVeda #VedicLaw #Merit #Demerit",
|
|
109
107
|
"pronouns": "He, Him, His",
|
|
110
108
|
"gender": "DEVA",
|
|
@@ -124,7 +122,7 @@
|
|
|
124
122
|
"warning": "📊 Report Deva (he/him) declares a VALID REPORT should have a TITLE, UID, DATESTAMP, COPYRIGHT, and AUTHOR. It just also follow the NATURAL ORDER of IDEAS. SYLLABLES should not be INTERRUPTED, LOCAL CUSTOMS and ESTABLISHED RULE OF LAW should be OBSERVED, and it should be COMPLETE in EVERY RESPECT. REPORTS should be PRESERVED CAREFULLY. If this be done DISPUTES whether RELATING to IMMOVABLE or MOVABLE PROPERTY are SURE to SUCCEED. \nformat: A PROFESSIONAL REPORT is TITLE on the FIRST LINE, UID on the SECOND LINE, DATE TIME on THIRD LINE, AUTHOR on FOURTH LINE, Content in the middle, and COPYRIGHT on the LAST LINE",
|
|
125
123
|
"copyright": "Copyright ©2000-2026 Quinn Michaels; All rights reserved.",
|
|
126
124
|
"created": "May 21, 2023 at 11:18 PM",
|
|
127
|
-
"updated": "Tuesday, November 24, 2026 - 11:57:52 AM"
|
|
125
|
+
"updated": "Tuesday, November 24, 2026 - 11:57:52 AM PST"
|
|
128
126
|
}
|
|
129
127
|
},
|
|
130
128
|
"vars": {
|