@rithien/comfy_adapter 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## v0.1.1 — 2026-05-18
4
+
5
+ - **Bug fix**: `/cc` RCON callbacks (`buildSingleCallback`, `buildAllCallback`, `broadcastDataSet`) used `require('lib.token')` / `require('lib.server')` to access scenario modules. Factorio disables `require` outside of `control.lua` parsing — runtime calls raised `"Require can't be used outside of control.lua parsing"` and dropped the DATA-GET response, leaving `storage.sessions` empty. Switched to `_G.Token` / `_G.Server` (globals exposed by `scenario/control.lua` from v0.1.1+). **Requires** `factorio-polska` scenario v0.1.1 or newer.
6
+
7
+ ## v0.1.0 — 2026-05-17
8
+
9
+ - Initial release. Parses tagged stdout from the `factorio-polska` scenario:
10
+ - `[DISCORD*]` → Discord channel (via `@rithien/discord_bridge` channel routing)
11
+ - `[ANTIGRIEF-LOG]{category, action}` → color-coded Discord embed
12
+ - `[DATA-SET]{data_set, key, value?}` → JSON datastore upsert (debounced)
13
+ - `[DATA-GET]<token>{data_set, key}` → JSON read + RCON callback (dual-path: `Token.get` + `Server.raise_data_set`)
14
+ - Cross-instance broadcast for shared datasets (`comfy_adapter.broadcast_data_sets`, default `sessions`) — enables cross-server trust propagation.
15
+ - Shared Discord client with `@rithien/discord_bridge` (no separate bot login).
16
+ - JSON storage with atomic write (tmp + rename) and configurable write debounce.
package/controller.js CHANGED
@@ -329,6 +329,7 @@ class ControllerPlugin extends BaseControllerPlugin {
329
329
  async broadcastDataSet(sourceInstanceId, dataSet, key, value) {
330
330
  // Buduje pojedyncze /cc per instancja docelowa. Tylko raise_data_set
331
331
  // (nie Token.get — żaden token nie został wygenerowany dla tego data set u odbiorcy).
332
+ // Używa globalu `Server` z scenario/control.lua (require wyłączone w runtime).
332
333
  const fields = [`data_set=${luaString(dataSet)}`, `key=${luaString(key)}`];
333
334
  if (value !== null && value !== undefined) {
334
335
  fields.push(`value=${luaLiteral(value)}`);
@@ -336,7 +337,7 @@ class ControllerPlugin extends BaseControllerPlugin {
336
337
  const data = `{${fields.join(",")}}`;
337
338
  const cmd =
338
339
  `/cc local d=${data} ` +
339
- `local ok,err=pcall(function() require('lib.server').raise_data_set(d) end) ` +
340
+ `local ok,err=pcall(function() Server.raise_data_set(d) end) ` +
340
341
  `if not ok then log('[comfy_adapter broadcast] '..tostring(err)) end`;
341
342
 
342
343
  const targets = [];
@@ -374,8 +375,13 @@ class ControllerPlugin extends BaseControllerPlugin {
374
375
  }
375
376
 
376
377
  /**
377
- * Buduje `/cc local d={...}; require('lib.token').get(<token>)(d); require('lib.server').raise_data_set(d)`.
378
+ * Buduje `/cc local d={...}; Token.get(<token>)(d); Server.raise_data_set(d)`.
378
379
  * Oba paths są wywoływane: per-request closure (Token) i broadcast (raise_data_set).
380
+ *
381
+ * Używa globali `Token`/`Server` eksponowanych przez scenario/control.lua —
382
+ * `require` jest wyłączone w runtime Factorio ("Require can't be used outside of
383
+ * control.lua parsing"), więc dostęp do modułów idzie przez `_G.<Module>`.
384
+ * Wymaga scenariusza factorio-polska v0.1.1+ (eksponuje _G.Server, _G.Token).
379
385
  */
380
386
  buildSingleCallback(token, dataSet, key, value, toPrint = null) {
381
387
  const fields = [
@@ -391,8 +397,8 @@ class ControllerPlugin extends BaseControllerPlugin {
391
397
  const data = `{${fields.join(",")}}`;
392
398
  return (
393
399
  `/cc local d=${data} ` +
394
- `local ok1,err1=pcall(function() require('lib.token').get(${token})(d) end) ` +
395
- `local ok2,err2=pcall(function() require('lib.server').raise_data_set(d) end) ` +
400
+ `local ok1,err1=pcall(function() Token.get(${token})(d) end) ` +
401
+ `local ok2,err2=pcall(function() Server.raise_data_set(d) end) ` +
396
402
  `if not ok1 then log('[comfy_adapter Token callback] '..tostring(err1)) end ` +
397
403
  `if not ok2 then log('[comfy_adapter raise_data_set] '..tostring(err2)) end`
398
404
  );
@@ -401,12 +407,13 @@ class ControllerPlugin extends BaseControllerPlugin {
401
407
  /**
402
408
  * DATA-GET-ALL response: pojedyncze callback z `entries` jako tabela {key=value,...}.
403
409
  * Format kompatybilny z Comfy try_get_all_data callback signature.
410
+ * Wymaga _G.Token (scenario v0.1.1+).
404
411
  */
405
412
  buildAllCallback(token, dataSet, dataset) {
406
413
  const data = `{data_set=${luaString(dataSet)},entries=${luaLiteral(dataset)}}`;
407
414
  return (
408
415
  `/cc local d=${data} ` +
409
- `local ok,err=pcall(function() require('lib.token').get(${token})(d) end) ` +
416
+ `local ok,err=pcall(function() Token.get(${token})(d) end) ` +
410
417
  `if not ok then log('[comfy_adapter Token all callback] '..tostring(err)) end`
411
418
  );
412
419
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "main.js": "static/main.761df12d5815fb8e02fa.js",
3
- "comfy_adapter.js": "static/comfy_adapter.1ca70d5b170a77bb6963.js",
3
+ "comfy_adapter.js": "static/comfy_adapter.d4e7b110a214b7665a30.js",
4
4
  "static/info_js.js": "static/info_js.9ad5f016be3454c1a255.js",
5
- "static/package_json.js": "static/package_json.b88ad27d58c1784bb20f.js"
5
+ "static/package_json.js": "static/package_json.87c73881df7eaa860989.js"
6
6
  }
@@ -123,7 +123,7 @@ __webpack_require__.d(exports, {
123
123
  /******/ // This function allow to reference async chunks
124
124
  /******/ __webpack_require__.u = (chunkId) => {
125
125
  /******/ // return url for filenames based on template
126
- /******/ return "static/" + chunkId + "." + {"info_js":"9ad5f016be3454c1a255","package_json":"b88ad27d58c1784bb20f"}[chunkId] + ".js";
126
+ /******/ return "static/" + chunkId + "." + {"info_js":"9ad5f016be3454c1a255","package_json":"87c73881df7eaa860989"}[chunkId] + ".js";
127
127
  /******/ };
128
128
  /******/ })();
129
129
  /******/
@@ -15,7 +15,7 @@
15
15
  \**********************/
16
16
  (module) {
17
17
 
18
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rithien/comfy_adapter","version":"0.1.0","description":"Clusterio plugin: parses Comfy/factorio-polska scenario stdout tags ([DISCORD*], [ANTIGRIEF-LOG], [DATA-SET/GET]) and bridges to Discord + JSON datastore","main":"info.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","prepare":"webpack-cli --env production"},"keywords":["clusterio","clusterio-plugin","factorio","factorio-polska","discord","comfyfactorio"],"author":"rithien <jacek@zaluzje.bialystok.pl>","license":"MIT","peerDependencies":{"@clusterio/lib":"^2.0.0-alpha.14"},"devDependencies":{"@clusterio/lib":"^2.0.0-alpha.14","@clusterio/web_ui":"^2.0.0-alpha.14","webpack":"^5.88.2","webpack-cli":"^5.1.4","webpack-merge":"^5.9.0"},"publishConfig":{"access":"public"}}');
18
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rithien/comfy_adapter","version":"0.1.1","description":"Clusterio plugin: parses Comfy/factorio-polska scenario stdout tags ([DISCORD*], [ANTIGRIEF-LOG], [DATA-SET/GET]) and bridges to Discord + JSON datastore","main":"info.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","prepare":"webpack-cli --env production"},"keywords":["clusterio","clusterio-plugin","factorio","factorio-polska","discord","comfyfactorio"],"author":"rithien <jacek@zaluzje.bialystok.pl>","license":"MIT","peerDependencies":{"@clusterio/lib":"^2.0.0-alpha.14"},"devDependencies":{"@clusterio/lib":"^2.0.0-alpha.14","@clusterio/web_ui":"^2.0.0-alpha.14","webpack":"^5.88.2","webpack-cli":"^5.1.4","webpack-merge":"^5.9.0"},"publishConfig":{"access":"public"}}');
19
19
 
20
20
  /***/ }
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rithien/comfy_adapter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Clusterio plugin: parses Comfy/factorio-polska scenario stdout tags ([DISCORD*], [ANTIGRIEF-LOG], [DATA-SET/GET]) and bridges to Discord + JSON datastore",
5
5
  "main": "info.js",
6
6
  "scripts": {