mikser-io 11.7.0 → 11.9.0

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.
@@ -1044,6 +1044,7 @@ distinction is the whole of [Faults](#faults) above.
1044
1044
  | Code | Severity | Means |
1045
1045
  | --- | --- | --- |
1046
1046
  | `config-coverage-partial` | warn | This Node build has no module loader hooks, so the config stamp covers the entry file alone. Editing an imported module will not invalidate the cache. |
1047
+ | `config-stale-in-process` | warn | A config file changed on disk while `--watch` is running. Node has the module cached and config is only read at startup, so this rebuild and every one after it uses the logic the process booted with. Restart to pick it up. |
1047
1048
  | `durable-open` | error | The durable store could not be opened. Auth grants and the change-set log are unavailable. |
1048
1049
  | `durable-migration` | error | A registered migration failed. |
1049
1050
  | `durable-gitignore` | error | The durable store could not be added to `.gitignore` — it holds credentials and the working folder is usually a repo. |
@@ -1063,6 +1064,7 @@ distinction is the whole of [Faults](#faults) above.
1063
1064
 
1064
1065
  | Code | Severity | Means |
1065
1066
  | --- | --- | --- |
1067
+ | `source-content-not-text` | warn | A `sources()` collection with `content: true` loaded a file whose bytes are not text. They are decoded as UTF-8 and stored mangled, and every consumer inherits that. Set `content: false` to catalogue the files by path instead — `entity.uri` still points at them. Once per collection. |
1066
1068
  | `observer-bad-uri` | warn | An observer's `uri` is not an absolute URL, so no webhook can be routed to it. |
1067
1069
  | `untracked-file-read` | warn | A template read a file outside every folder mikser takes entities from, so it has no entity and changing it invalidates nothing. |
1068
1070
  | `progress` | info | A long phase reporting where it has got to. See [Progress](#progress). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mikser-io",
3
- "version": "11.7.0",
3
+ "version": "11.9.0",
4
4
  "files": [
5
5
  "app.js",
6
6
  "index.js",
package/src/instance.js CHANGED
@@ -288,7 +288,7 @@ function configMismatch(theirs) {
288
288
  // configCoverage lists every local module the config graph pulled in, so a
289
289
  // stat over that list catches an edit to an imported module — which a
290
290
  // client-side checksum of the entry file would miss entirely.
291
- async function configStale() {
291
+ export async function configStale() {
292
292
  const covered = runtime.options.configCoverage?.files ?? []
293
293
  if (!covered.length) return null
294
294
  const { stat } = await import('node:fs/promises')
package/src/manager.js CHANGED
@@ -4,6 +4,7 @@ import cron from 'node-cron'
4
4
  import { onProcess, onFinalized } from './lifecycle.js'
5
5
  import { resetReport } from './report.js'
6
6
  import { useLogger } from './engine/index.js'
7
+ import { configStale } from './instance.js'
7
8
  import { ACTION } from './constants.js'
8
9
  import { junkFilter } from './utils/index.js'
9
10
 
@@ -22,12 +23,52 @@ const tasks = []
22
23
  // would wipe it out of a one-shot build's report.
23
24
  function scheduleProcess() {
24
25
  clearTimeout(runtime.engine.processTimeout)
25
- runtime.engine.processTimeout = setTimeout(() => {
26
+ runtime.engine.processTimeout = setTimeout(async () => {
27
+ await warnConfigStale()
26
28
  resetReport()
27
29
  runtime.process()
28
30
  }, 1000)
29
31
  }
30
32
 
33
+ // Editing config/*.js while watching changes nothing, and says nothing.
34
+ //
35
+ // Node has the module cached, and the config stamp is only compared at
36
+ // startup — that is where "Config changed since the last run. Wiping the
37
+ // cache…" comes from. So a watch process keeps running the logic it booted
38
+ // with, rebuilds happily, and reports green. Reported after it cost a
39
+ // consumer several rounds: a derivation plugin they had already fixed kept
40
+ // producing the old output, every symptom pointed at the data rather than at
41
+ // the process, and they reported it as broken twice before finding it.
42
+ //
43
+ // The check already exists — instance.js compares mtimes across
44
+ // configCoverage.files to refuse a forwarded command against drifted config.
45
+ // It just never ran on this path, where no client is asking.
46
+ //
47
+ // A warning, not a reload: re-importing a config module does not re-run the
48
+ // plugin registration that happened at boot, so a "reload" that only
49
+ // refreshed the module would be a more convincing version of the same lie.
50
+ // Restarting is the honest fix, and mikser_ping already reports `stale` for
51
+ // packages installed since boot on exactly this reasoning.
52
+ async function warnConfigStale() {
53
+ if (runtime.options.watch !== true) return
54
+ let changed = null
55
+ try {
56
+ changed = await configStale()
57
+ } catch { return } // never let a diagnostic break the rebuild
58
+ if (!changed || changed === configStaleReported) return
59
+ configStaleReported = changed
60
+ useLogger().warn(
61
+ { code: 'config-stale-in-process', file: changed },
62
+ 'Config changed on disk (%s) but this process is still running the version it started with — '
63
+ + 'Node has the module cached and config is only re-read at startup. This rebuild, and every one '
64
+ + 'after it, uses the OLD logic. Restart to pick it up.',
65
+ changed)
66
+ }
67
+
68
+ // One warning per file, so a watch session editing the same module in a loop
69
+ // does not print it on every save — and a DIFFERENT file still speaks up.
70
+ let configStaleReported = null
71
+
31
72
  export async function createdHook(name, context) {
32
73
  if (!runtime.started) return
33
74
 
package/src/source.js CHANGED
@@ -44,7 +44,7 @@ import pMap from 'p-map'
44
44
  import runtime from './runtime.js'
45
45
  import { useLogger } from './engine/index.js'
46
46
  import { ACTION } from './constants.js'
47
- import { checksum as fileChecksum, checksumOf, junkIgnore } from './utils/index.js'
47
+ import { checksum as fileChecksum, checksumOf, junkIgnore, looksTextual } from './utils/index.js'
48
48
  import { reportGated, reportChanged } from './report.js'
49
49
  import { findById, findEntities, checksumsByCollection } from './catalog.js'
50
50
  import { bypassReason } from './invalidation.js'
@@ -293,6 +293,39 @@ export function scanSummary({ cap, loaded, emitted = 0, skipped = 0, deleted = 0
293
293
  * called per file; returned object is merged onto the base entity.
294
294
  * Return null to skip a file.
295
295
  */
296
+ // Collections already warned about a `content: true` binary. Module-level so
297
+ // the warning survives across cycles — a watch rebuild re-reads the same
298
+ // files, and repeating it every cycle is how a warning gets filtered out.
299
+ const binaryWarned = new Set()
300
+
301
+ // `content: true` is right for the CSS and template parts useSource was built
302
+ // for, and wrong in silence for a binary. `toString('utf8')` never fails: it
303
+ // substitutes U+FFFD and returns a string, so a 4 MB PDF becomes 4 MB of
304
+ // mangled text and every consumer downstream inherits it.
305
+ //
306
+ // Reported by mikser-io-ocr, which sent one as a prompt and got back "Your
307
+ // input exceeds the context window of this model" — an error that names the
308
+ // document, so the reader goes and looks at the PDF rather than at the
309
+ // collection's config.
310
+ //
311
+ // Returns whether it warned, so the decision is testable without reading logs.
312
+ export function warnIfNotText(collection, name, bytes, logger) {
313
+ if (binaryWarned.has(collection)) return false
314
+ if (looksTextual(bytes.subarray(0, SNIFF_BYTES))) return false
315
+ binaryWarned.add(collection)
316
+ logger?.warn(
317
+ { code: 'source-content-not-text', collection, sample: name },
318
+ 'Source %j has `content: true` but %j is not text — its bytes are being decoded as UTF-8 and stored ' +
319
+ 'mangled. Set `content: false` on the collection to catalogue these files by path instead ' +
320
+ '(entity.uri still points at them).',
321
+ collection, name)
322
+ return true
323
+ }
324
+
325
+ // Same prefix the filesystem provider sniffs (src/utils/entity.js). Enough
326
+ // to see a file header without decoding a whole document twice.
327
+ const SNIFF_BYTES = 8 * 1024
328
+
296
329
  export function useSource(core, options) {
297
330
  const {
298
331
  runtime,
@@ -559,6 +592,20 @@ export function useSource(core, options) {
559
592
  // Decoded from the bytes the checksum was taken over — not
560
593
  // re-read. See the gate above.
561
594
  base.content = bytes.toString('utf8')
595
+
596
+ // `content: true` is right for the CSS and template parts this
597
+ // was built for, and wrong in silence for a binary. toString
598
+ // never fails: it substitutes U+FFFD and hands back a string, so
599
+ // a 4 MB PDF becomes 4 MB of mangled text and every consumer
600
+ // downstream inherits it. Reported by mikser-io-ocr, which sent
601
+ // one as a prompt and got back "Your input exceeds the context
602
+ // window of this model" — an error that names the document and
603
+ // sends the reader to the PDF rather than to this line.
604
+ //
605
+ // Once per collection, not per file: a media folder catalogued
606
+ // this way is all binaries, and the fix is one setting either
607
+ // way.
608
+ warnIfNotText(collection, name, bytes, logger)
562
609
  }
563
610
  try {
564
611
  const extra = await load({ file, name, relativePath, entity: base })