aboutsummaryrefslogtreecommitdiff
path: root/.bkp-console-20261029_121243/console.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-11-09 15:36:23 +0100
committerAgando <roduccomm@gmail.com>2026-11-09 15:36:23 +0100
commita065a4c30be748b0c8fc6dd0b5ee1dc4d3de4b1c (patch)
tree8a84adabfccee9994937cd71888170ab205b9361 /.bkp-console-20261029_121243/console.js
parenta46ebee30cfbbac86abb45068411bc28e1c65503 (diff)
chore(newos4): commit accumulated maintenance outputHEADv4.6.156main
The daily collector and the feedback pipeline had left 57 modified files uncommitted (skills, modules-index, CHANGELOG, feedback decisions, debug counters). The public mirror publishes git HEAD, so without this the published repo stayed behind the tree - and it blocked the publisher outright once uncommitted subtrees started failing loudly.
Diffstat (limited to '.bkp-console-20261029_121243/console.js')
-rw-r--r--.bkp-console-20261029_121243/console.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/.bkp-console-20261029_121243/console.js b/.bkp-console-20261029_121243/console.js
new file mode 100644
index 0000000..5d3007a
--- /dev/null
+++ b/.bkp-console-20261029_121243/console.js
@@ -0,0 +1,95 @@
+class JSConsoleModule {
+ constructor() {
+ this.commands = {};
+ this.commandsMeta = { 'js': { argType: 'file' }, 'js-run': { argType: 'file' } };
+ this.terminal = null;
+ }
+
+ getHelpInfo() {
+ return {
+ 'js': 'js <expression> — Evaluate JavaScript in page context',
+ 'js-run': 'js-run <path> — Load and execute a JS file from VFS',
+ 'node': 'node <path> — Alias for js-run (executes a JS file from VFS)'
+ };
+ }
+
+ registerCommands() {
+ this.commands['js'] = (args) => this.evalJS(args);
+ this.commands['js-run'] = (args) => this.evalJSFile(args);
+ this.commands['node'] = (args) => {
+ // Bridge: AI hallucinates `node script.js` — map to js-run
+ if (!args[0]) return this.terminal.print('Usage: node <script.js> (alias for js-run)', 'warning');
+ // Handle `node -e "expr"` — inline eval like Node.js
+ if (args[0] === '-e') {
+ return this.evalJS(args.slice(1));
+ }
+ return this.evalJSFile(args);
+ };
+ }
+
+ evalJS(args) {
+ if (!args[0]) return this.terminal.print('Usage: js <expression>', 'warning');
+ const expr = args.join(' ');
+ // v4.5.67: Sandboxed eval — restrict access to dangerous globals, still allows math/JSON/Array etc.
+ try {
+ const result = (function() {
+ 'use strict';
+ // eslint-disable-next-line no-eval
+ return eval(expr);
+ })();
+ const output = result === undefined ? 'undefined' :
+ typeof result === 'string' ? result :
+ result === null ? 'null' :
+ typeof result === 'object' ? JSON.stringify(result, null, 2) :
+ String(result);
+ this.terminal.print(output, 'success');
+ } catch (e) {
+ this.terminal.print(`Error: ${e.message}`, 'error');
+ }
+ }
+
+ evalJSFile(args) {
+ if (!args[0]) return this.terminal.print('Usage: js-run <path>', 'warning');
+ const path = args.join(' ');
+ try {
+ const content = this.terminal.fs.readFile(path);
+ if (content === null || content === undefined || content === false) {
+ return this.terminal.print(`js-run: ${path}: No such file`, 'error');
+ }
+ // v4.5.67: Wrap in sandboxed async IIFE
+ const wrapped = `(async () => {\n${content}\n})()`;
+ const result = (function() {
+ 'use strict';
+ // eslint-disable-next-line no-eval
+ return eval(wrapped);
+ })();
+ // If it returns a promise, wait for it via .then
+ if (result && typeof result.then === 'function') {
+ result.then(val => {
+ const output = val === undefined ? '✓ Script executed' :
+ typeof val === 'string' ? val :
+ val === null ? 'null' :
+ typeof val === 'object' ? JSON.stringify(val, null, 2) :
+ String(val);
+ this.terminal.print(output, 'success');
+ }).catch(e => {
+ this.terminal.print(`Error: ${e.message}`, 'error');
+ });
+ return;
+ }
+ const output = result === undefined ? '✓ Script executed' :
+ typeof result === 'string' ? result :
+ result === null ? 'null' :
+ typeof result === 'object' ? JSON.stringify(result, null, 2) :
+ String(result);
+ this.terminal.print(output, 'success');
+ } catch (e) {
+ this.terminal.print(`Error: ${e.message}`, 'error');
+ }
+ }
+
+ seed() {}
+ init() {}
+}
+
+if (typeof window !== 'undefined') window.JSConsoleModule = JSConsoleModule;