@indra.ai/deva.report 0.24.2 → 0.24.4

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 CHANGED
@@ -4,4 +4,4 @@ The Report Deva
4
4
  Copyright ©2000-2026 Quinn Michaels; All rights reserved.
5
5
  Owner Signature Required For Lawful Use.
6
6
  Distributed under VLA:28986758608512849090 LICENSE.md
7
- Tuesday, November 24, 2026 - 11:57:52 AM
7
+ Tuesday, November 24, 2026 - 11:57:52 AM PST
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  // Report Deva Feature Methods
3
- // Copyright ©2000-2026 Quinn Arjuna America Michaels; All rights reserved.
3
+ // Copyright ©2000-2026 Quinn Michaels; All rights reserved.
4
4
  // Owner Signature Required For Lawful Use.
5
- // Distributed under VLA:47204973893606085061 LICENSE.md
6
- // Monday, September 28, 2026 - 6:05:25 AM PST
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
- const report = await this.methods.sign('report', 'default', packet);
11
- return report;
10
+ return {};
12
11
  }
13
12
  };
@@ -5,7 +5,7 @@
5
5
  // Tuesday, November 24, 2026 - 11:57:52 AM PST
6
6
 
7
7
  ::BEGIN:MAIN
8
- # {{profile.ename}}
8
+ # {{profile.name}}
9
9
 
10
10
  {{profile}}
11
11
 
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
- id: pkg.id,
21
- name: pkg.name,
22
- version: pkg.version,
23
- author: pkg.author,
24
- describe: pkg.description,
25
- dir: __dirname,
26
- url: pkg.homepage,
27
- git: pkg.repository.url,
28
- bugs: pkg.bugs.url,
29
- license: pkg.license,
30
- VLA: pkg.VLA,
31
- copyright: pkg.copyright,
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
- info,
36
- agent,
37
- vars,
38
- utils: {
39
- translate(input) {return input.trim();},
40
- parse(input) {return input.trim();},
41
- process(input) {return input.trim();}
42
- },
43
- listeners: {},
44
- devas: {
45
- // research,
46
- },
47
- modules: {
48
- client: false,
49
- },
50
- func: {
51
- /**************
52
- func: report_write
53
- params: type, packet
54
- describe: this is the log file writer function that handles writing
55
- the interactions to json log file.
56
- ***************/
57
- async write(type, packet) {
58
- let result = false;
59
- try {
60
- const database = this.modules.client.db(this.vars.database);
61
- const collection = database.collection(type);
62
- result = await collection.insertOne(packet);
63
- } catch (e) {
64
- return this.error(e, packet, false);
65
- } finally {
66
- return result;
67
- }
68
- },
69
-
70
- },
71
- methods: {
72
- write(packet) {
73
- return new Promise((resolve, reject) => {
74
- try {
75
- this.func.write('reports', packet).then(report => {
76
- return resolve({
77
- text: 'see data',
78
- html: '<p>see data</p>',
79
- data: report,
80
- });
81
- });
82
- } catch (err) {
83
- return this.error(err, packet, reject);
84
- }
85
- });
86
- }
87
- },
88
- onReady(data, resolve) {
89
- const {VLA} = this.info();
90
- const {uri,database} = this.report().global?.mongo || {};
91
- if (uri) this.modules.client = new MongoClient(uri); // build the client if uri is set
92
- this.vars.database = database;
93
- this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
94
- return resolve(data);
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 Arjuna America Michaels; All rights reserved.
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.2",
4
+ "version": "0.24.4",
5
5
  "license": "VLA:28986758608512849090 LICENSE.md",
6
6
  "VLA": {
7
7
  "uid": "28986758608512849090",
@@ -50,7 +50,7 @@
50
50
  "type": "module",
51
51
  "scripts": {
52
52
  "latest": "npm i @indra.ai/deva@latest --save",
53
- "test": "echo \"Error: no test specified\" && exit 1"
53
+ "test": "node --test"
54
54
  },
55
55
  "repository": {
56
56
  "type": "git",
@@ -124,7 +124,7 @@
124
124
  "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
125
  "copyright": "Copyright ©2000-2026 Quinn Michaels; All rights reserved.",
126
126
  "created": "May 21, 2023 at 11:18 PM",
127
- "updated": "Tuesday, November 24, 2026 - 11:57:52 AM"
127
+ "updated": "Tuesday, November 24, 2026 - 11:57:52 AM PST"
128
128
  }
129
129
  },
130
130
  "vars": {