arcane-os 0.69.0 → 0.70.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -1
  3. package/browser-runtime/ai/browser-decisions.mjs +46 -2
  4. package/browser-runtime/ai/browser-speech-artifacts.mjs +58 -62
  5. package/browser-runtime/ai/browser-speech-providers.mjs +3 -0
  6. package/browser-runtime/ai/browser-wasm-llm-provider.mjs +76 -164
  7. package/browser-runtime/ai/dbopfs-model-parts.mjs +344 -0
  8. package/browser-runtime/ai/dbopfs-model-resources.mjs +190 -0
  9. package/browser-runtime/ai/decision-runtime.mjs +17 -1
  10. package/browser-runtime/ai/decision-worker.mjs +21 -1
  11. package/browser-runtime/ai/model-resource-bridge.mjs +231 -0
  12. package/browser-runtime/ai/speech-worker-client.mjs +68 -28
  13. package/browser-runtime/ai/speech-worker-runtime.mjs +212 -97
  14. package/browser-runtime/core/contracts.mjs +1 -1
  15. package/docs/reference/ai/browser-decisions.md +57 -3
  16. package/docs/reference/ai/browser-speech.md +45 -17
  17. package/docs/reference/ai/browser-wasm.md +28 -20
  18. package/docs/reference/core-native-packaging.md +13 -0
  19. package/docs/reference/core-runtime.md +9 -0
  20. package/docs/reference/core-shared-host.md +190 -0
  21. package/docs/reference/inventory/runtime-modules.json +3 -3
  22. package/docs/reference/runtime-modules.md +97 -7
  23. package/docs/reference/sdk-api.md +41 -30
  24. package/package.json +2 -2
  25. package/runtime/arcane/modules/AI.js +2 -18
  26. package/runtime/arcane/modules/AIProviderRuntime.js +77 -3
  27. package/runtime/arcane/modules/DBOPFS.js +180 -26
  28. package/src/core/host.mjs +2 -0
  29. package/src/core/runtime.mjs +9 -4
  30. package/src/core/services/packaged-web.mjs +8 -1
  31. package/src/core/shared-host.mjs +500 -0
  32. package/src/native/portable-layout.mjs +66 -34
@@ -842,6 +842,14 @@ cancellation signal. Cancelling one handle detaches that caller; the shared
842
842
  preparation is aborted only when its last pending caller cancels. Different AI
843
843
  instances do not share an in-flight synthesis operation. Complete stored
844
844
  results remain reusable through the same application storage.
845
+
846
+ Missing audio participates in the provider runtime's shared TTS activation with
847
+ the preparation's cancellation signal. Cancelling the final pending interest
848
+ aborts that activation; another preparation, explicit playback activation, or
849
+ direct TTS load joining it keeps the load alive. Cancellation does not unload a
850
+ model whose activation has already completed. A complete audio-cache hit never
851
+ requests model activation. Provider cancellation and cleanup remain cooperative;
852
+ an aborted caller wait alone is not evidence that native work has stopped.
845
853
  After a durable preparation completes, a later preparation call rereads its
846
854
  manifest and saved-file presence, regenerating only missing segments. A
847
855
  completed preparation without storage reuses its retained Blobs.
@@ -874,9 +882,10 @@ The supplied signal observes preparation until `ready` settles. Manual
874
882
  handle. If a raw audio write has already begun when cancellation arrives,
875
883
  its metadata transaction finishes so that successful audio can be reused;
876
884
  no later queued write starts for that cancelled preparation.
877
- Cancelling preparation prevents later synthesis, but the existing shared
878
- provider load/unmute operation has no per-preparation signal and may finish.
879
- Cancellation does not claim to stop an already-started shared model load.
885
+ Cancelling preparation prevents later synthesis and releases its pending
886
+ activation interest. Other pending interests retain the shared load; cancelling
887
+ the final interest forwards abort to its provider-owned activation. Actual
888
+ provider cleanup remains observable through that operation's settlement.
880
889
 
881
890
  ### Playback controls and independent lifetimes
882
891
 
@@ -1497,23 +1506,39 @@ The Worker installs one private module router before importing the entrypoint:
1497
1506
  - a dynamic import whose target is known imports the materialized URL;
1498
1507
  - a fetch whose target is known reads the materialized URL;
1499
1508
  - a Worker whose target is known starts the SDK role Worker and imports the
1500
- materialized target there; and
1501
- - a Cache match whose target is known returns the materialized file.
1509
+ materialized target there.
1502
1510
 
1503
- Every unmapped operation keeps ordinary browser behavior:
1511
+ Resource ownership extends to ordinary self-contained speech runtimes as well
1512
+ as graph runtimes:
1504
1513
 
1505
1514
  - an unmapped relative or URL-like import resolves against the calling module's
1506
1515
  original source URL, while a bare specifier remains unchanged for native
1507
1516
  import-map resolution;
1508
- - an unmapped fetch calls native `fetch` and preserves the caller's options;
1509
- - an unmapped Worker calls the native `Worker` constructor and preserves the
1510
- caller's options; and
1511
- - an unmapped Cache operation delegates to native Cache Storage.
1512
-
1513
- Cache `put`, `add`, `addAll`, `delete`, and `keys` are normal mutable browser
1514
- operations. The SDK does not replace them with a read-only cache. Relative
1515
- requests are resolved from the calling module's original source URL before the
1516
- native Cache operation.
1517
+ - an unmapped HTTP fetch preserves the caller's request options and reaches
1518
+ the parent DBOPFS resource store; Blob/data resources remain local;
1519
+ - an unmapped module Worker starts through the SDK role Worker and forwards
1520
+ its resource fetches to that same store; and
1521
+ - an unmapped classic Worker retains native execution. Its internal fetches
1522
+ are outside this module-Worker routing contract.
1523
+
1524
+ Inside the dedicated speech Worker, native CacheStorage is temporarily
1525
+ unavailable before runtime import, so the selected runtime takes its existing
1526
+ fetch path. Transformers' public browser/custom/filesystem cache switches are
1527
+ disabled there. The SDK does not fabricate Cache matches or mutation results,
1528
+ and it neither clears nor changes saved native caches. The original Worker
1529
+ environment is restored on unload or failed import. Existing explicit
1530
+ `removeBrowserSpeechModelCache()` remains a separate caller-selected operation.
1531
+
1532
+ The existing speech store exposes `fetchResource(input, options)` for its
1533
+ Worker loaders, returning `{file,status,statusText,headers,url,redirected}`.
1534
+ New declared files and fetched model, voice, configuration, and WASM resources
1535
+ stream into ordered DBOPFS parts even without a response length. Closed-part
1536
+ progress uses `unit:'shards'`; declared-file progress retains `unit:'files'`
1537
+ with the current shard record in `resource`. Complete declared peer files and
1538
+ closed resource parts survive cancellation. Existing whole-file caches remain
1539
+ readable without migration. HTTP resume is used only when the server returns
1540
+ the requested range; otherwise the complete resource is downloaded anew.
1541
+ Worker termination aborts and joins its parent-owned resource operations.
1517
1542
 
1518
1543
  Routing discovery is best effort and is not an admission gate. If the scanner
1519
1544
  cannot interpret a module, that module is left unchanged and follows its native
@@ -1535,11 +1560,14 @@ provider:
1535
1560
  `namespace.env.backends.onnx.wasm.wasmPaths = {mjs,wasm}`, keeps remote model
1536
1561
  loading enabled, and applies caller-selected `numThreads` when present.
1537
1562
 
1538
- Transformers and Kokoro keep their normal provider downloads and Cache behavior
1539
- for routes not materialized by the SDK. Kokoro voice aliases and Transformers
1563
+ Transformers and Kokoro use their normal provider request semantics through
1564
+ the selected DBOPFS resource owner. Kokoro voice aliases and Transformers
1540
1565
  model aliases may be listed in `runtimeRequestUrls` so an upstream request for a
1541
1566
  known file resolves to the already materialized local file. Model, voice, and
1542
1567
  runtime selection remains with the application and upstream publisher.
1568
+ Native ESM imports remain platform-owned; only declared runtime modules are
1569
+ materialized by artifact preparation. Custom classic Worker internals are not
1570
+ claimed as stored by this contract.
1543
1571
 
1544
1572
  ## Providers
1545
1573
 
@@ -117,21 +117,15 @@ current mutable status snapshot. Provider states are `unloaded`, `loading`, `rea
117
117
 
118
118
  Browser-WASM model loads report `cache-check`, `download`, and `initialize`
119
119
  phases. Download records preserve the ordered model-file fields `completed`,
120
- `total`, and `unit:'files'`. They add `loadedBytes`, `totalBytes`,
121
- `remainingBytes`, `bytesPerSecond`, `etaSeconds`, `activeTransfers`,
122
- `transferLimit`, and `transferMode`. `loadedBytes` is aggregate downloaded or
123
- restored progress for the current install. Active partial writes count while
124
- they are staged, then are removed from that total if their transfer fails;
125
- completed shards or Range parts reused from an interrupted attempt remain
126
- counted. Unknown totals, remaining counts, rates, and ETAs are `null`;
127
- once known, byte values and seconds are nonnegative numbers. `activeTransfers`
128
- is the current transfer-worker count, `transferLimit` is the selected concurrency
129
- bound, and `transferMode` identifies `probing`, `files`, `ranges`, or `single`.
130
- The store coalesces chunk-driven changes on a 250 ms cadence and publishes
131
- immediately when download starts, the transfer plan or total becomes known,
132
- active-worker count changes, and the download completes. At known completion, remaining bytes and ETA are zero
133
- and active transfers are zero. Applications format the raw measures into B,
134
- KB, MB, GB, transfer-rate, and duration labels.
120
+ `total`, and `unit:'files'`. Their ordered `members` records contain each file's
121
+ `name`, committed-part `completed`, `total`, and `unit:'shards'`. A streaming
122
+ response has `total:null` until its end is observed; completion then supplies
123
+ the actual committed-part count. Previously complete members identify
124
+ `state:'cached'`. `activeTransfers` is the current transfer-worker count,
125
+ `transferLimit` is the selected concurrency, and `transferMode` identifies
126
+ `probing`, `files`, `ranges`, or `single`. No byte progress, rate, or estimated
127
+ completion time is produced. Closed-part and lifecycle changes publish promptly;
128
+ the existing 250 ms heartbeat retains the current semantic state.
135
129
 
136
130
  Initialization keeps `phase:'initialize'` and reports a `stage` and a readable
137
131
  `message` from the packaged runtime's existing log signals: runtime startup,
@@ -172,8 +166,11 @@ optional descriptor `bytes` divides that member into deterministic contiguous
172
166
  parts of roughly 4 MB each, up to 4,096 parts. Each exact completed part is
173
167
  committed separately in OPFS, so retry or refresh fetches only the small
174
168
  in-flight parts plus any other missing parts; the ordered parts are exposed to
175
- Wllama as one logical model Blob. Range offsets remain transport-local; only
176
- aggregate transfer telemetry is public.
169
+ Wllama as one logical model Blob. Ordinary full responses, including unknown
170
+ content lengths and single-file models, also stream directly into ordered OPFS
171
+ parts. Model data is not accumulated in one JavaScript buffer. Range offsets
172
+ and physical part framing remain storage/transport-local; progress describes
173
+ completed files and parts.
177
174
 
178
175
  ## Model selection, optional hardening, and cache
179
176
 
@@ -181,7 +178,7 @@ The canonical model descriptor is
181
178
  `{id, files:[{name?,url,bytes?},...]}`. The ordered `files` array is nonempty;
182
179
  names and URLs are unique. Each URL must be absolute HTTPS without credentials
183
180
  or a fragment. An optional positive safe-integer `bytes` value is used only for
184
- progress and HTTP Range planning. Missing or unusable metadata never blocks a
181
+ HTTP Range planning. Missing or unusable metadata never blocks a
185
182
  download, and a declared value is not a content-length check.
186
183
 
187
184
  Fetch follows HTTPS redirects and records the requested and final HTTPS URL. A
@@ -205,11 +202,22 @@ admission work. Observational byte counting and exact HTTP Range framing remain
205
202
  transport-local. A load succeeds only after Wllama reports that the model is
206
203
  loaded.
207
204
 
208
- The DBOPFS adapter commits each complete member or Range part independently and
209
- exposes only a complete ordered model set as a cache hit.
205
+ The DBOPFS adapter commits ordered parts independently and exposes only a
206
+ complete ordered model set as a cache hit. Existing whole-file and Range-part
207
+ caches remain readable without migration. Closed parts survive interrupted
208
+ writes; a source without supported resume starts that member's next transfer
209
+ from its beginning. Complete peer members remain cached.
210
210
  `load({offline:true})` never performs a model request; it uses a compatible
211
211
  cached entry or rejects with `ARCANE_AI_MODEL_OFFLINE_MISS`.
212
212
 
213
+ The same store exposes `fetchResource(input, options)` for SDK-owned browser
214
+ model loaders. It returns `{file,status,statusText,headers,url,redirected}`
215
+ after storing the complete response through the shared part owner. Ordinary
216
+ Fetch request options, `signal`, and semantic `onProgress` are supported.
217
+ The browser decision model accepts this store through its additive `store`
218
+ option; resource acquisition stays with the SDK while model selection stays
219
+ with the application. See [browser decisions](browser-decisions.md).
220
+
213
221
  ```javascript
214
222
  const {security, cache} = ai.status().llm;
215
223
  console.log(security?.secure === true); // false when the optional field is absent
@@ -210,6 +210,19 @@ details and [the client contract](core-client.md) for native bridge integration.
210
210
 
211
211
  ## Launch-time locations
212
212
 
213
+ For one app-owned Core shared by the native window and a separate MCP process,
214
+ the launch context may explicitly select `sharedHost:{endpoint,logFile}`. The
215
+ generated native child then connects through a stdio bridge, starting an
216
+ independent headless Core only when the selected endpoint is absent. Its
217
+ endpoint claim precedes application service imports/factories. Closing a native
218
+ window disconnects its bridge; explicit shared-host shutdown drains services.
219
+ Omitting `sharedHost` preserves the existing stdio-owned Core lifetime.
220
+ See [shared Core host ownership](core-shared-host.md) for exact startup,
221
+ connection, cancellation, diagnostics, endpoint, and platform contracts.
222
+ The packaged-web service exposes `current()` as its active `{origin,url,port}`
223
+ or `null`; the shared host replays that current listener to a newly attached
224
+ macOS bridge, without restarting the server or retaining historical events.
225
+
213
226
  The generated Core entry accepts `--arcane-launch-config <path>`. The public
214
227
  `readCoreLaunchContext({argv=process.argv.slice(2)}={})` function in
215
228
  `arcane-os/core/host` reads that explicitly selected JSON object. A native host
@@ -71,6 +71,15 @@ receives `(parameters, {application, service, emit, getService, requestId, signa
71
71
  `this` bound to its service definition. A hook or handler may publish a complete
72
72
  service-owned event through `emit(event, data)`.
73
73
 
74
+ A request handler's `emit` places its owning request ID in the event frame's
75
+ optional top-level `requestId`, leaving `data` unchanged. Multi-connection hosts
76
+ can route those frames to the requesting connection even when different clients
77
+ choose the same application `streamId`. Lifecycle-hook `emit` and public
78
+ `runtime.emit` remain uncorrelated service-wide events. Retain that service
79
+ context when an application intentionally publishes a change to every client;
80
+ request-context events belong to the originating request. The ordinary Core
81
+ client still delivers the complete original event data to its listeners.
82
+
74
83
  ### Native service composition
75
84
 
76
85
  `await runtime.getService(name)` and `await context.getService(name)` return the
@@ -0,0 +1,190 @@
1
+ # One application, one shared Core host
2
+
3
+ `arcane-os/core/host` provides a Node local-IPC owner for applications whose
4
+ native UI and separate MCP process use the same catalog, drafts, review queue,
5
+ and Git service. The application chooses one endpoint and one set of services.
6
+ The endpoint is a nonempty local pipe/socket path. The SDK connects to it,
7
+ optionally starts an explicit headless entry,
8
+ and keeps client disconnection separate from service shutdown.
9
+
10
+ This is an explicit same-application connection. It does not scan applications
11
+ or processes, share preference files, copy a catalog, retry requests, or retain
12
+ event history. Application methods and policy stay in the application services.
13
+ Use the [MCP server](mcp-stdio.md) for external MCP framing; local Core continues
14
+ to use the existing `arcane/1` protocol and Content-Length stream framing.
15
+
16
+ ## Host entry
17
+
18
+ ```js
19
+ import {runSharedCoreHost} from 'arcane-os/core/host';
20
+
21
+ const host = await runSharedCoreHost({
22
+ endpoint: process.env.MOON_CORE_ENDPOINT,
23
+ application: {id: 'moon-cheese-ledger'},
24
+ version: '1.0.0',
25
+ async configure(runtime, {signal}) {
26
+ // Only the successful endpoint owner imports and constructs services.
27
+ const {default: createLedger} = await import('./ledger.mjs');
28
+ signal.throwIfAborted();
29
+ runtime.registerService(createLedger());
30
+ }
31
+ });
32
+ await host?.closed;
33
+ ```
34
+
35
+ `startSharedCoreHost({endpoint,application,version,configure,getReplayEvents,
36
+ signal,onError})` binds the selected endpoint **before** calling `configure`.
37
+ The callback receives the existing runtime and the host's lifetime signal.
38
+ Register each service as it is constructed so its drain/disposal belongs to the
39
+ runtime even if a later factory fails. Put asynchronous service initialization
40
+ in `start`, as with ordinary Core composition. Factory imports can run
41
+ concurrently; requests wait for composition, then only their own service's
42
+ startup. Dispatcher readiness does not claim model or service readiness.
43
+
44
+ It resolves to `{runtime,endpoint,closed,close}`. `close()` rejects new work,
45
+ joins composition, closes the runtime, drains complete queued frames, and
46
+ closes its connections. It retains the endpoint claim through service cleanup
47
+ before stopping the listener, so a new launcher cannot start a second service
48
+ owner during an accepted save. Accepted service-lifetime requests finish
49
+ before service drain/disposal. A supplied signal begins this same shutdown;
50
+ the lazy factory receives cancellation and is joined before cleanup. Register
51
+ resources before rejecting after creation. Startup and shutdown errors remain
52
+ observable; `closed` rejects on host shutdown failure. `onError` observes
53
+ transport/background errors, with console diagnostics by default.
54
+
55
+ An endpoint already in use rejects with the native `EADDRINUSE` error and
56
+ `coreHostPhase:'listen'`, without invoking the factory.
57
+ `runSharedCoreHost(options)` adds the explicit headless startup handshake: a
58
+ losing launcher connects to the existing owner and confirms dispatcher response
59
+ without importing its own application service modules. It returns `null` in
60
+ that case. The winning launcher returns the same host object. It reports startup
61
+ success or the complete failure to a parent Node IPC channel when present and
62
+ never calls `process.exit()`.
63
+
64
+ ## Connect, reuse, or start headlessly
65
+
66
+ ```js
67
+ import {connectSharedCoreHost} from 'arcane-os/core/host';
68
+
69
+ const connection = await connectSharedCoreHost({
70
+ endpoint: selectedEndpoint,
71
+ start: {
72
+ command: process.execPath,
73
+ args: [selectedHostEntry],
74
+ logFile: selectedDiagnosticLog
75
+ }
76
+ });
77
+ const catalog = await connection.client.invoke('catalog.read', {});
78
+ // The UI or MCP process is finished. Shared services remain alive.
79
+ await connection.close();
80
+ ```
81
+
82
+ `connectSharedCoreHost({endpoint,start,signal,onError})` first connects to the
83
+ selected endpoint. Only connection absence (`ENOENT` or `ECONNREFUSED`) selects
84
+ `start`; other errors propagate unchanged. Omit `start` for connect-only use.
85
+ The optional record is `{command,args=[],cwd,env,logFile}`. Its arguments and
86
+ environment are captured at acceptance. The selected entry must call
87
+ `runSharedCoreHost`. Parent directories for the endpoint and diagnostic file
88
+ must already exist. No shell, runtime installer, service manager, or automatic
89
+ request retry is involved.
90
+
91
+ Headless startup uses an independent child with ignored stdin and complete
92
+ stdout/stderr appended to the explicit diagnostic file. The child reports its
93
+ endpoint claim/composition result through its startup IPC channel; the launcher
94
+ then disconnects that channel and releases the child process reference. An
95
+ aborted connection/start wait rejects or closes the connecting client; it does
96
+ not kill a host that another connection may already use. The host may therefore
97
+ continue running after a launch wait is cancelled. Startup diagnostics and the
98
+ endpoint remain the actual outcome owners. No startup timeout is imposed by
99
+ this layer; supply a signal when the caller needs a bounded wait.
100
+
101
+ The result is `{client,endpoint,closed,close,shutdown}`. `client` is the existing
102
+ [Core client](core-client.md), with full invoke/cancellation/event behavior and
103
+ current-runtime replay enabled. A connected transport is not a ready model.
104
+ `close()` and `client.close()` cancel this connection's request-lifetime work
105
+ and disconnect it. They leave accepted service-lifetime work and the host
106
+ running. `closed` observes connection termination and rejects on a transport
107
+ error. A subsequent connection uses the still-running owner. Reconnection is
108
+ explicit; failed or uncertain requests are never resubmitted.
109
+
110
+ `await connection.shutdown(invokeOptions)` explicitly invokes the host-owned
111
+ `core.host.shutdown` operation. It drains the shared runtime, returns
112
+ `{state:'closed'}` after successful service cleanup, then closes the connection.
113
+ A drain failure returns the full Core error. Shutdown affects **all** clients
114
+ of that app endpoint and belongs to the application owner's explicit lifecycle,
115
+ not ordinary UI/MCP cleanup. The host reserves this one method; application
116
+ services should use their own namespaces. Cancelling the caller's invoke wait
117
+ after shutdown acceptance does not undo the shared shutdown.
118
+
119
+ ## Correlation, events, and state
120
+
121
+ Each connection has its own request-ID space. The transport substitutes an
122
+ internal Core request ID and restores the originating ID on responses and
123
+ the optional top-level event `requestId`. Existing `data.requestId` values that
124
+ carry that same Core correlation ID are restored too. `parameters`, returned results, schemas,
125
+ documents, and content remain complete and unchanged. A handler's
126
+ `context.requestId` is the Core-side correlation ID; put it in the event's
127
+ separate `requestId` field, not inside application content.
128
+
129
+ Responses and request-context events go to the originating connection in
130
+ order. Core supplies the top-level request correlation outside `data`, so two
131
+ clients may choose the same `streamId` without receiving each other's chunks.
132
+ Retired request frames are never routed to another connection. Ordinary
133
+ application/service events from the lifecycle context or `runtime.emit` are broadcast to
134
+ connected clients. Runtime state includes all active work and translates this
135
+ connection's IDs; other connections' active requests retain Core-side IDs.
136
+ `request.cancel` and `requests.cancelAll` affect only the sending connection's
137
+ requests. A disconnect performs the same scoped cancellation. The underlying
138
+ runtime continues to preserve service-lifetime acceptance.
139
+
140
+ `runtime.replay` sends only that connection the current `core.ready`,
141
+ `core.state`, and `core.service.state` snapshot. Optional synchronous
142
+ `getReplayEvents()` returns current `{event,data}` records from their actual
143
+ service owners. It is for current domain state, not historical chunks or
144
+ retired requests. Subscribe before requesting a domain snapshot when its live
145
+ events may change; applications own those domain methods and state.
146
+
147
+ ## Native launch and platforms
148
+
149
+ The generated portable Core entry keeps ordinary stdio behavior unless the
150
+ explicit launch context contains:
151
+
152
+ ```json
153
+ {
154
+ "sharedHost": {
155
+ "endpoint": "APPLICATION-SELECTED-LOCAL-ENDPOINT",
156
+ "logFile": "APPLICATION-SELECTED-DIAGNOSTIC-FILE"
157
+ }
158
+ }
159
+ ```
160
+
161
+ Both native UI and external MCP clients select the same endpoint. With this
162
+ option, the native Core child is a stdio-to-shared-Core bridge. It connects or
163
+ launches the same entry with `--arcane-core-headless`; the headless entry claims
164
+ the endpoint before importing services. Closing the native window ends its
165
+ bridge, while the independent Core host remains available. Service options and
166
+ the complete launch context retain their existing values. There is no implicit
167
+ shared mode or new application descriptor field.
168
+
169
+ `startSharedCoreBridge({endpoint,start,input=process.stdin,
170
+ output=process.stdout,signal,onError})` is also public. It returns
171
+ `{endpoint,closed,close}` and forwards full framed requests, events, and
172
+ responses. EOF or bridge cancellation disconnects that client only. Terminal
173
+ stream errors settle pending writes and reject `closed`; output is neither
174
+ truncated nor replaced with a fabricated response.
175
+
176
+ On Windows use an app-selected named pipe such as
177
+ `\\.\pipe\moon-cheese-core`; on Linux/macOS use an app-selected Unix-domain
178
+ socket path in an existing writable directory. Select the same absolute Unix
179
+ path across UI and MCP launch contexts so differing working directories do not
180
+ select different endpoints. Node and the operating system
181
+ own their native endpoint requirements. A Unix socket left after an abnormal
182
+ host exit is reported as a connection/bind failure; the SDK does not delete an
183
+ existing endpoint to take ownership. The app owner can resolve that actual
184
+ stale endpoint after establishing its stopped lifecycle. Android requires its
185
+ host adaptation for local IPC and independent process ownership; application
186
+ services and `arcane/1` client semantics remain the shared boundary.
187
+
188
+ This source contract is distinct from a selected package/native artifact or
189
+ execution on a particular platform. Applications adopt it through the published
190
+ SDK and their corresponding native package build, not by copying this source.
@@ -578,11 +578,11 @@
578
578
  "DBOPFS_REASONS",
579
579
  "default"
580
580
  ],
581
- "summary": "Provides app-scoped OPFS tables, explicit non-recursive empty-table removal, worker I/O, backup/restore, compression, and CRUD/batch APIs.",
581
+ "summary": "Provides app-scoped OPFS tables, committed-change subscriptions with targeted cache freshness, explicit non-recursive empty-table removal, worker I/O, backup/restore, compression, and CRUD/batch APIs.",
582
582
  "availability": "Browser / native WebView",
583
- "protocol": "OPFS, DBOPFSWorker, Compression Streams, and per-realm globalThis.arcaneEvents authority",
583
+ "protocol": "OPFS, DBOPFSWorker, Compression Streams, per-realm globalThis.arcaneEvents authority, and native BroadcastChannel for live same-app/storage-partition committed changes",
584
584
  "normalization": "App scope and recognized file parsing are normalized; nonblank unreadable JSONL rows remain complete raw strings, empty-table removal reports removed, absent, or not-empty after a create:false directory lookup and without scanning or recursively clearing a directory, same-named files are preserved, aliases and cached handles are invalidated only when the directory is gone, and unexpected DOM/storage errors are preserved.",
585
- "surface": "default `DBOPFS`; installs `window.dbopfs`, emits `dbopfs-ready`; table/file/backup APIs including removeEmptyTable(tableName). createCompressedPNG({tableNames,additionalTables,signal}) returns a PNG Blob without download or record writes; omitted names select all, [] none, and supplied tables replace matching saved tables in the export. downloadCompressedPNG(name,options) reuses the same preparation and initiates one download; cancellation prevents it. restoreFromPNG(file,{selectTables}) closes the decoded image after pixel extraction, awaits the optional caller selection/projection before any writes, and rejects DBOPFS_RESTORE_WRITE_FAILED AggregateError after all selected table batches settle when records fail, preserving original errors and failures {tableName,fileName,reason}; successful writes remain. No-options restore and setMany retain their contracts."
585
+ "surface": "default `DBOPFS`; installs `window.dbopfs`, emits `dbopfs-ready`; subscribeChanges(listener,{signal,once}) observes DBOPFS_EVENT_TYPES.change (dbopfs-change), returns idempotent unsubscribe/.dispose, and publishes metadata {applicationId,storagePath,tableName,directoryName,fileName,action,originId,sequence,changeId,remote} after successful storage commits only. Actions are write/append/delete/table-delete; batches preserve partial success, remote receipts invalidate targeted aliases before local publication and never rebroadcast, and pagehide/pageshow closes/reopens the native channel and clears memory caches without replay or fabricated changes. Local subscription/storage continue when BroadcastChannel is unavailable. Table/file/backup APIs include removeEmptyTable(tableName). createCompressedPNG({tableNames,additionalTables,signal}) returns a PNG Blob without download or record writes; omitted names select all, [] none, and supplied tables replace matching saved tables in the export. downloadCompressedPNG(name,options) reuses the same preparation and initiates one download; cancellation prevents it. restoreFromPNG(file,{selectTables}) closes the decoded image after pixel extraction, awaits the optional caller selection/projection before any writes, and rejects DBOPFS_RESTORE_WRITE_FAILED AggregateError after all selected table batches settle when records fail, preserving original errors and failures {tableName,fileName,reason}; successful writes remain. No-options restore and setMany retain their contracts."
586
586
  },
587
587
  {
588
588
  "file": "runtime/arcane/modules/DBOPFSDocumentLibrary.js",
@@ -477,6 +477,13 @@ the caller's ready DBOPFS instance; the separate JSON-compatible `identity`
477
477
  adds application-owned semantic context. Reuse compares complete inputs rather
478
478
  than an SDK version alone.
479
479
 
480
+ Only missing audio joins TTS activation. Each preparation supplies its own
481
+ cancellation lifetime to the existing provider runtime. The last pending
482
+ activation interest cancels the owned load; other preparation/playback or
483
+ joining direct-load interests preserve it. Cache-only preparation never loads
484
+ the model, and cancelling after activation does not unload an already-ready
485
+ model. Provider work owns actual cancellation and cleanup completion.
486
+
480
487
  `state` is `queued`, `preparing`, `ready`, `error`, or `cancelled`.
481
488
  `onState({state,completed,total,segments,error})` synchronously observes
482
489
  preparation progress. `ready` resolves the complete record after every segment
@@ -486,8 +493,8 @@ the retained MIME type. Preparation failure rejects; cancellation rejects as
486
493
  `AbortError` and preserves successfully stored segments. Matching pending
487
494
  requests share synthesis only on the same AI instance and storage group;
488
495
  cancelling one handle does not cancel another active matching caller.
489
- Preparation cancellation prevents later synthesis, but an already-started
490
- shared provider load/unmute has no per-preparation signal and may finish.
496
+ Preparation cancellation prevents later synthesis and releases its activation
497
+ interest. The provider's operation remains responsible for actual cleanup.
491
498
 
492
499
  `playPreparedTTS(prepared,{signal,onState})` can attach immediately. Its returned
493
500
  `{state,error,finished,pause(),resume(),stop()}` handle schedules segments in
@@ -1024,9 +1031,20 @@ The singleton exposes read-only `protocol`, `configured`, and `speechMuted`;
1024
1031
  `supportsTranscriptionCapture(providerId=null)`;
1025
1032
  `createTranscriptionCapture(options={})`;
1026
1033
  `synthesize(payload,options={},preparation={})`; and
1027
- `setSpeechMuted(muted)`. Provider payloads must be data-only; callbacks,
1034
+ `setSpeechMuted(muted,{signal}={})`. Provider payloads must be data-only; callbacks,
1028
1035
  accessors, symbols, and cycles are rejected at the provider boundary.
1029
1036
 
1037
+ `setSpeechMuted(false,{signal})` shares pending activation while retaining an
1038
+ independent interest for each caller. Aborting one signal rejects only that
1039
+ caller's wait. When no pending interests remain, abort reaches the owned load.
1040
+ No-signal callers and direct `load('tts',...)` calls joining that activation
1041
+ also retain it. A rejected load preserves its complete error for the remaining
1042
+ callers. An already-aborted signal rejects before changing mute intent.
1043
+ Explicit `setSpeechMuted(true)` still cancels shared activation and unloads TTS;
1044
+ once accepted, that mute cleanup runs to completion rather than being undone
1045
+ by cancellation of its caller's signal. Completed activation is not unloaded
1046
+ merely because a former observer later aborts.
1047
+
1030
1048
  Selection options admit `localOnly=false`; inspection admits
1031
1049
  `{localOnly=false,signal=null}`; startup admits
1032
1050
  `{startLanguageModel=true,startMuted=true,startTranscription=false,signal=null}` (including an omitted
@@ -2203,6 +2221,59 @@ default `DBOPFS`; installs `window.dbopfs`, emits `dbopfs-ready`; table/file/bac
2203
2221
 
2204
2222
  Exact exports: `DBOPFS_EVENT_TYPES`, `DBOPFS_REASONS`, `default`.
2205
2223
 
2224
+ `subscribeChanges(listener, {signal, once})` observes
2225
+ `DBOPFS_EVENT_TYPES.change` (`dbopfs-change`) through the existing canonical
2226
+ `arcane-os/event-manager` source. It returns an idempotent unsubscribe function
2227
+ with `.dispose()`; aborting the supplied signal also removes the subscription.
2228
+ Each listener receives an event whose `detail` contains:
2229
+
2230
+ | Field | Meaning |
2231
+ | --- | --- |
2232
+ | `applicationId`, `storagePath` | Existing application identity and `apps/<application-id>` OPFS scope. |
2233
+ | `tableName`, `directoryName` | Logical table and physical directory; `memories` / `memory` retain their existing alias. |
2234
+ | `fileName` | Complete record filename, or `null` for a removed table. |
2235
+ | `action` | `write`, `append`, `delete`, or `table-delete`. A write does not claim whether a record was newly created. |
2236
+ | `originId`, `sequence`, `changeId` | Per-document origin and incrementing committed occurrence, shared by local and remote notifications for that occurrence. These are correlation fields, separate from realm-local canonical event-source IDs. |
2237
+ | `remote` | `false` at the writing DBOPFS source, `true` when received from another live document. |
2238
+
2239
+ A write is published after writable-stream `close()` succeeds, or after the
2240
+ existing OPFS worker acknowledges its completed write/flush/close. A removal
2241
+ is published after OPFS removes the record or table. The affected cached record
2242
+ or table, including alias keys and removed-table handles, is invalidated before
2243
+ listeners run. A read already in progress may still resolve its earlier
2244
+ snapshot; it cannot repopulate the cache after an intervening delivered change.
2245
+ Notification metadata does not contain, rewrite, or reread record bodies.
2246
+
2247
+ `set()` and raw `writeFile()` publish one occurrence per completed write;
2248
+ `setMany()`, `deleteMany()`, clear operations, and restore retain their existing
2249
+ per-record results and publish only their actual successful mutations. A
2250
+ partial batch is not a transaction: successful records are announced even when
2251
+ siblings fail. Missing records, absent/non-empty empty-table removal, failed
2252
+ writes/removals, and reads emit no committed-change event. `deleteTable()` keeps
2253
+ its existing return/error-reporting behavior; its returned `true` alone does
2254
+ not imply that a committed-change event was emitted.
2255
+
2256
+ Within one document, subscribe through this source or the canonical event
2257
+ manager, rather than consuming both as separate changes. Across documents,
2258
+ DBOPFS owns one native `BroadcastChannel` named from the application storage
2259
+ path. Native storage-partition matching plus that path selects the receiving
2260
+ documents. A remote receiver invalidates its affected cache before publishing
2261
+ locally and never rebroadcasts the occurrence. There is no echo back to the
2262
+ writing DBOPFS source. Ordinary storage success remains success if a transport
2263
+ notification fails; the notification error is reported separately.
2264
+
2265
+ Subscriptions are live-only: subscribe before the application's initial read,
2266
+ then let the application map the table/file/action to its own records and UI.
2267
+ DBOPFS performs no polling, initial full-table read, automatic picker refresh,
2268
+ or event-history replay. The channel lasts for the owning page, independent of
2269
+ individual listener lifetimes, so a document that only writes still announces
2270
+ its commits. `pagehide` closes the channel; `pageshow` after suspension reopens
2271
+ it and clears only that document's in-memory caches. Resuming a page does not
2272
+ fabricate a storage mutation. Applications own any resume-time view refresh.
2273
+ Missed events during suspension, process termination, or realm loss are not
2274
+ replayed; the stored records remain the authority. Direct OPFS writes made
2275
+ outside DBOPFS are not observed by this contract.
2276
+
2206
2277
  `createCompressedPNG({tableNames, additionalTables, signal})` returns an
2207
2278
  `image/png` Blob without downloading or writing records. Omitted `tableNames`
2208
2279
  selects all discovered saved tables; `[]` selects none. Named absent tables
@@ -2244,16 +2315,35 @@ unreadable row remains in its original string form so the owning application
2244
2315
  can display, diagnose, or recover it without silent data loss. DOM and storage
2245
2316
  errors remain observable. The logical `memories` table continues to map to the
2246
2317
  physical `memory` directory, and successful or already-absent empty-table
2247
- removal invalidates both alias and cached-handle state. Transport: OPFS,
2248
- DBOPFSWorker, Compression Streams.
2318
+ removal invalidates both alias and cached-handle state. Cross-document change
2319
+ delivery requires native `BroadcastChannel` in the same origin and storage
2320
+ partition, with the same application scope; separate WebView profiles do not
2321
+ share this transport. If it is unavailable, local change subscriptions and
2322
+ ordinary DBOPFS storage continue, without cross-document notification or a
2323
+ polling replacement. Transport: OPFS, DBOPFSWorker, Compression Streams, native
2324
+ BroadcastChannel, and the existing event-pubsub-backed canonical event owner.
2249
2325
  [Deep protocol details](protocols.md).
2250
2326
 
2251
2327
  ### Example
2252
2328
 
2253
2329
  ```javascript
2254
- import * as module from '/arcane/modules/DBOPFS.js';
2330
+ import '/arcane/modules/DBOPFS.js';
2331
+
2332
+ await dbopfs.readyPromise;
2333
+ const lifetime = new AbortController();
2334
+ const stop = dbopfs.subscribeChanges(function showCommittedParade(event) {
2335
+ const change = event.detail;
2336
+ if (change.tableName === 'moon_bus') {
2337
+ console.log(change.action, change.fileName, change.remote);
2338
+ }
2339
+ }, {signal: lifetime.signal});
2255
2340
 
2256
- console.log(Object.keys(module));
2341
+ await dbopfs.set('moon_bus', 'squid-parade.json', {
2342
+ destination: 'The moon', passengers: ['Captain Squid', 'One confused lobster']
2343
+ });
2344
+ // Another live page using this app/storage scope receives the same occurrence.
2345
+ // The application can read that one record when its view needs the body.
2346
+ stop(); // lifetime.abort() is the equivalent subscription cleanup.
2257
2347
  ```
2258
2348
 
2259
2349
  ## DBOPFSDocumentLibrary.js