@mhome/core-protocol 1.61.0 → 1.66.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.
@@ -0,0 +1,107 @@
1
+ # Space-owned Integration source reads
2
+
3
+ `extension_sources` defines the compiler's source-read callback, not publication,
4
+ installation authority, or an Integration business lifecycle. The caller supplies
5
+ tenant/Space through the existing authenticated Bridge envelope. Neither payload
6
+ accepts caller-controlled tenant/Space fields.
7
+
8
+ | Route | Request | Response |
9
+ | --- | --- | --- |
10
+ | `/dispatch/extension/sources/snapshot` | `{}` | `SpaceSources` |
11
+ | `/dispatch/extension/sources/read` | `SourceReadRequest` | `SourceReadResponse` |
12
+ | `/dispatch/extension/acquire` | `{integrations: string[]}` | `true` after preparation/activation |
13
+ | `/dispatch/extension/resources/plan` | `{capabilityId, role, source}` | `{invokePlan}` from the exact local cache |
14
+ | `/dispatch/extension/resources/guides` | `{keys: [{capabilityId, version?, snapshot?, type}]}` | `{guides: [{key, guide}]}` from the exact local cache |
15
+
16
+ Local Spaces own these records on their bound Hub. Cloud Spaces own published
17
+ selections in a separate Space-partitioned cloud table and cannot select a local
18
+ preview. Published package bodies remain in the release registry/object store.
19
+ The developer's desktop Host may differ from that Hub. Preview material is
20
+ transferred as content, not as a desktop-local pathname. Native Plugin installation
21
+ and its Space binding remain separate from this source-read protocol.
22
+
23
+ A source contains `integrationId`, `type` (`standard` or `composite`), and exactly
24
+ one content identity: a positive signed-32-bit `version` for a registry release,
25
+ or a lowercase SHA-256 `snapshot` for Preview. Preview has no numeric version and
26
+ cannot replace `base` or a composite package. Neither identity may substitute for
27
+ the other.
28
+
29
+ `SpaceSources` contains a safe-integer `revision` and up to 1,000 `integrations`,
30
+ with at most 256 KiB of encoded selection metadata on both storage platforms.
31
+ There is at most one published source and one Preview override per
32
+ `(integrationId, type)`. The shared resolver selects Preview first regardless of
33
+ list order. Updating a published source does not displace its override; exiting
34
+ Preview removes only that override and resolves the ordinary source again. Without
35
+ an ordinary source, the ID is unavailable. The complete selection is
36
+ replaced using its expected revision; a stale writer fails without partial edits.
37
+ Revision zero and an empty list represent a Space with no selections. Acquiring a
38
+ package and creating its business Connection remain separate operations.
39
+
40
+ The read request contains one exact `source`. The response echoes that exact
41
+ source, `schemas` (normalized relative YAML paths to UTF-8 text), and
42
+ `scriptDigests` (function name to lowercase SHA-256), and required `i18n`
43
+ (language tag to intro-translation YAML; an empty map is valid). English remains
44
+ in the schema. Language tags follow the existing intro-i18n grammar; path-like,
45
+ empty, or malformed tags and empty content are rejected. Relative paths may include
46
+ directories but reject empty/dot/parent segments, backslashes, colons and NULs.
47
+ Each inventory has at most 1,000 members; the encoded material is at most
48
+ 16 MiB, below the existing general Bridge payload ceiling. Its normal bulk
49
+ transport handles large responses. No JavaScript body or credentials are sent
50
+ to the compiler by this callback.
51
+
52
+ Preparation stores immutable candidate material without changing availability.
53
+ Core stores compiler material as bounded, digest-checked files under its workdir's
54
+ `packages/extensions/preview/sources/`; database rows retain identities and hashes,
55
+ not duplicate Schema bodies. Files must be complete before recording references.
56
+ The compiler can read that exact candidate while preparation waits for validation.
57
+ Source and resource read handlers do not compile, call the cloud, or acquire Automation/lifecycle/cache
58
+ locks. They only read the selected Space's stored material. Missing or mismatched
59
+ material fails; there is no owner-catalog or latest-version fallback.
60
+
61
+ Removing a selection does not delete immutable material required by cleanup or
62
+ saved plans. Preview and published Integrations use the same disconnect/uninstall
63
+ business lifecycle; these read routes do not delete Connections or rewrite user
64
+ Automations. Resource retention and invocation admission belong to the resource
65
+ and lifecycle consumers, not this read protocol.
66
+
67
+ Preview compilation uses the exact candidate plus explicitly acquired dependency
68
+ materials. Its result must retain every source identity; numeric versions and
69
+ staging/prod channel names do not identify Preview bytes. Channels choose release
70
+ heads/configuration, and promotion does not change the immutable release identity.
71
+ The complete material set for one compilation is bounded to 16 MiB of encoded
72
+ material. Translation contents contribute to the material hash and byte bounds.
73
+
74
+ Provider configuration is not compiler material. Preview provider vars are supplied
75
+ explicitly to the owning Hub through a separate configuration operation, remain
76
+ Space-scoped, and are never part of this source callback or a publication artifact.
77
+ Omitted configuration on repeated Preview preserves existing values; explicit
78
+ updates/deletions are validated against the candidate schema. That configuration
79
+ consumer, compiled-result transport and runtime activation are subsequent work.
80
+
81
+ ## Runtime preparation
82
+
83
+ `/bridge/schema/prepare` carries the Hub's current `SpaceSources`, requested package
84
+ IDs, and known model content hashes. Lion acquires latest published dependencies,
85
+ keeps Preview overrides, and prepares one exact graph without saving the selection.
86
+ The response includes the candidate selection, manifest, complete model identities,
87
+ changed models, published provider configuration and affected derived plans/guides.
88
+ A source or publication head changing during preparation fails the response.
89
+ Core stores immutable resources first, then commits selection and matching runtime
90
+ models/provider data under one local transaction. A stale selection revision rolls
91
+ back that transaction. Projection refresh remains the existing retryable operation.
92
+
93
+ Runtime `PlanSource` contains exactly one positive `version` or lowercase SHA-256
94
+ `snapshot`, plus `type` and `archived`. Plan cache keys use `v<version>` or
95
+ `p<snapshot>`; guide keys and frozen invocation references carry the same source.
96
+ Derived snapshots cover exact dependency material, environment and compiler/protocol
97
+ identity. Unaffected published packages retain their released keys. A missing Preview
98
+ plan/guide/script is an error, never a registry lookup or published fallback.
99
+
100
+ Acquisition is the mutating route above; it is distinct from source/resource read
101
+ callbacks and shares the caller's deadline. It finishes before installation or
102
+ connection reads its first runtime model. Catalog browsing does not acquire packages.
103
+ Catalog guide reads may supply `integrationIds` to `/bridge/schema/manifest`;
104
+ Lion returns the prospective package/dependency selection without activating it.
105
+ An empty list reads the current Space selection. Installed guide reads continue to
106
+ use committed local sources, including while offline. Public Preview commands and
107
+ configuration activation remain a later slice.
@@ -0,0 +1,200 @@
1
+ # Storage capability, version 1
2
+
3
+ `mhome-storage-api` owns logical Folder and object contracts, usage,
4
+ path validation and structured errors. It has no Catalog, filesystem or network
5
+ implementation. Core API re-exports it and adds binding and Host TLS messages;
6
+ App Facade API re-exports the same contracts for `/app/object-storage/`.
7
+
8
+ The wire generation is `storage.v1`; package versions independently identify
9
+ published build artifacts. During development, providers and consumers are
10
+ updated together. Earlier development contracts are not negotiated or served.
11
+
12
+ ## Names and ownership
13
+
14
+ A Folder's immutable `id` is its exact case-sensitive UTF-8 path within one
15
+ (tenant, Space). Names are never normalized or silently trimmed. Use `home/<path>`,
16
+ `plugin/<unique-plugin-name>/<bound-instance>/<path>`, or `core/<module>/<path>`.
17
+ Segments contain 1–80 Unicode characters, with no edge whitespace, control
18
+ characters, backslash, empty segments, `.` or `..`. Paths contain at most 16
19
+ segments and 1024 UTF-8 bytes; no leading or trailing slash. These logical paths
20
+ are never joined to disk paths. Unicode spellings remain distinct exact IDs.
21
+
22
+ `folders/create` takes `folderId`, is idempotent, and creates missing parents
23
+ below the namespace root in one transaction. Namespace roots themselves are
24
+ virtual and cannot be created or deleted. `folders/get` and `folders/list` return
25
+ path IDs, system/deleting flags, timestamps, direct usage and subtree quota
26
+ snapshots. Paths have no display-name alias or rename endpoint. Storage does not
27
+ automatically evict data or infer consumer-folder mappings.
28
+
29
+ App/CLI/Agent users may create, delete and acquire data sessions only under
30
+ `home/`. Space-authorized diagnostics may list Plugin/system Folder usage.
31
+ Bound Plugins may create multiple Folders, read and acquire sessions, or delete
32
+ only inside `plugin/<name>/<instance>/`. Core derives the name from verified
33
+ binding metadata and the instance from authenticated context; `nodeType`, a
34
+ request path or a caller-supplied name is not ownership proof. Core internal
35
+ modules use `core/<module>/...`. The protected `artifact` Folder is created and
36
+ used only through Artifact APIs; it has no ordinary sessions or Storage settings.
37
+
38
+ ## Folder quota settings
39
+
40
+ `folders/set-limit` takes exactly `{ "folderId": "<path>", "maxBytes": "<bytes>" }`.
41
+ Both fields are required. `maxBytes` is a canonical positive decimal string in
42
+ 1..9223372036854775807, or explicit `null` to remove this Folder's own limit.
43
+ The result is the updated Folder. App Facade uses
44
+ `/app/object-storage/folders/set-limit`; authenticated Node requests use the same
45
+ target with Plugin context derived by Core. Space members can change any ordinary Folder
46
+ setting, including Plugin Folders, without acquiring content mutation permission.
47
+ Plugins can change only their own authenticated namespace. System `artifact` and
48
+ deleting Folders reject settings. There is no version check: last committed write wins.
49
+
50
+ Limits cover a Folder and all descendants across every physical repository.
51
+ Every limited ancestor applies even if a child has no own limit. `quota` contains
52
+ `maxBytes` (own setting), `usedBytes` (subtree committed bytes), `reservedBytes`
53
+ (subtree admitted/uncertain/cleanup writes), `remainingBytes` (minimum remaining
54
+ allowance across this Folder and limited ancestors, or null if none), and
55
+ `exceeded` (any applicable limit is below its charged usage). All byte fields use
56
+ decimal strings. Existing top-level `usedBytes`, `reservedBytes`, and `objectCount`
57
+ continue to describe only the Folder's direct objects.
58
+
59
+ Core checks and reserves the declared object length atomically against all
60
+ applicable limits before physical write preparation. Concurrent descendants cannot
61
+ spend the same allowance. Publication transfers reserved to used; confirmed
62
+ physical deletion/retirement releases the corresponding charge. Lost responses,
63
+ offline repositories, restarts and failed cleanup do not free unconfirmed bytes.
64
+ Immutable-object retries keep their original reservation and do not charge twice.
65
+ `QUOTA_EXCEEDED` is a typed refusal (HTTP 507), distinct from physical `VOLUME_FULL`.
66
+
67
+ Lowering below used plus reserved saves immediately. Existing objects and admitted
68
+ uploads remain; new admissions fail until enough charged bytes are removed or the
69
+ limit increases. Storage never deletes content in response to a setting change.
70
+ Null removes only this Folder's limit; ancestor limits, physical reserves and
71
+ staging requirements still apply. New Folders start with no own limit.
72
+
73
+ ## Deletion and lifetime
74
+
75
+ `folders/delete` takes `folderId` and `recursive` (false by default). False
76
+ requires an empty Folder with no descendants or active/cleanup writes. True
77
+ explicitly removes all its contents and descendants. Physical cleanup must
78
+ succeed before the Folder tree is removed; failure can leave earlier physical
79
+ deletions applied. Remaining objects and staged bytes remain indexed and counted.
80
+ A persistent deletion fence blocks new writes and descendant creation until
81
+ cleanup is retried and finishes. The response is `{ "deleted": true }`; an
82
+ already absent path returns false. `deleting` exposes incomplete cleanup.
83
+
84
+ The catalog retains a private creation incarnation for object ownership and
85
+ sessions, separate from the public path. Reusing a deleted path creates a new
86
+ incarnation; old sessions cannot read, delete or write into it. A fresh management
87
+ delete always addresses the current path, so callers inspect state after an
88
+ uncertain response before retrying. Scope/Core removal stops ordinary access and
89
+ waits for all physical repositories, including offline repositories, to be cleaned.
90
+
91
+ ## Placement and capacity
92
+
93
+ For SDK writes, Core prefers a healthy external repository on the authenticated
94
+ source Host, then another external repository, and finally its internal disk.
95
+ Within each external group, writable staging bytes descending and stable repository/
96
+ binding identities decide the order. An unknown source Host has no local preference.
97
+ Existing objects keep their recorded repository UUID; enabling a Plugin never moves
98
+ them. Discovery excludes unavailable or insufficient candidates. Once selected,
99
+ preparation or transfer failure fails this write: there is no Core byte relay,
100
+ cross-repository replay, persistent sender spool or automatic media retransmission.
101
+ Uncertain results remain pinned to that repository until publication or cleanup.
102
+ Core-internal Artifact consumers retain their existing engine write/recovery path.
103
+
104
+ All Folders share available capacity. Host physical reserves and staging space
105
+ still apply. A write validates full size and SHA-256; no staging space means
106
+ failure without deleting old data. Storage never infers business references.
107
+ Camera owns retention, pinned clips and shared segments, using the recording
108
+ Folder quota with no separate default byte budget. Temporary Artifact content
109
+ retains its transient store and idle TTL. Logically unlimited Artifact storage still needs real space.
110
+
111
+ Object keys are immutable: the same key, size and SHA-256 is an idempotent retry;
112
+ new content requires a new key. Management byte counts and timestamps are decimal
113
+ strings; object/physical receipts use JSON u64.
114
+
115
+ ## Folder SDK and internal transport
116
+
117
+ Business callers use `ensureFolder` (explicit, idempotent creation), `openFolder`
118
+ (existing only), Folder listing/deletion and overview. A Folder handle provides
119
+ put/get/stat/list/delete. The existing Node SDK owns the Plugin client, and the
120
+ App SDK owns the `home/` client. Core internal consumers call the engine directly.
121
+ Camera retains recording retention and shared-segment references.
122
+
123
+ Object HEAD/stat verifies the selected physical repository, not just its Catalog
124
+ receipt. Confirmed physical absence returns 404 (`NOT_FOUND` for GET); a missing
125
+ repository, transport failure or timeout remains unavailable, never absence.
126
+ Length/hash declaration mismatches remain integrity errors. Existence probes do
127
+ not remove receipts or release quota charges: only confirmed deletion does that.
128
+ SDK HEAD maps 404 to no object, and reads preserve the typed `NOT_FOUND` failure.
129
+
130
+ `/app/object-storage/session/acquire` is an internal transport operation, with
131
+ `folderId` and optional `expectedIncarnation`. It accepts no `permissions` or
132
+ `ttlSeconds`. An authorized namespace owner receives all object operations for
133
+ that Folder; the fixed 15-minute expiry is not a business setting. Its Core API
134
+ response includes `folderIncarnation`, HTTPS endpoint, token, Host identity and
135
+ expiry. SDKs keep these private and renew shortly before expiry. The incarnation
136
+ is an opaque transport fence, not another public Folder ID.
137
+
138
+ Each handle binds to its originating Space and owner. Renewals send the original
139
+ creation identity and never call Folder creation. A deleted/recreated path cannot
140
+ replace an existing handle. App login/Space changes retire handles and active
141
+ transfers; Plugin context changes reject the old binding. Reopen explicitly after
142
+ an authorization refusal. HTTP 401 `SESSION_EXPIRED` is raised before object
143
+ mutation and permits one retry after refresh. HTTP 403 remains terminal. Other
144
+ failures, including uncertain writes, are returned without automatic replay.
145
+ Retried uploads retain their original key, length and SHA-256. Native file tickets
146
+ are owned per transfer: renewal leaves an admitted read alive, and completion,
147
+ cancellation or SDK disposal releases its ticket.
148
+
149
+ Object data uses SDK-owned direct transfers. POST to the session's
150
+ `objects/<key>` URL carries a Core API `StorageObjectControl`: `prepare`
151
+ (`sizeBytes`, `sha256`, `contentType`, `localImport`), `complete`, `status`, or
152
+ `abort` (each with `uploadId`), or `read`. Prepare reserves quota once and returns
153
+ an already-published receipt or the exact repository transfer. A transfer contains
154
+ its URL, token, Host TLS identity, expiry and an optional local capability.
155
+ The SDK sends bytes to that repository and completes through Core. Only Core's
156
+ published receipt is success. Complete verifies physical metadata rather than
157
+ trusting the client. Aborting a published upload leaves its object intact.
158
+ Unfinished/cancelled writes remain charged until confirmed cleanup; existing
159
+ recovery may publish verified bytes after a lost response. Terminal journals have
160
+ a 24-hour cleanup window; the immutable object receipt remains accessible by key.
161
+
162
+ Read obtains the selected repository's grant and streams directly, including HTTP
163
+ Range. Session HEAD/list/delete remain Core metadata/management operations. Session
164
+ PUT only accepts a prepared internal-disk upload; external data cannot be relayed
165
+ through the Core Folder gateway. Old SDK byte routes are not served in parallel.
166
+
167
+ The Node SDK writes byte buffers without a temporary file and reuses pinned HTTPS
168
+ connections without sharing request authorization. A local capability is projected
169
+ only for a verified same-Host Plugin. Its private Unix socket accepts one authorized
170
+ object stream, or a read-only source file descriptor for import. Source pathnames
171
+ and repository directory access are never transferred. Import clones on supported
172
+ filesystems or allocates/copies locally, verifies the result, and preserves the
173
+ source. Inaccessible local namespaces may use HTTPS to the same selected repository
174
+ before a local request starts. App WebViews use the native pinned file bridge;
175
+ exact-object upload tickets permit PUT only. No offline quota delegation is added.
176
+
177
+ These logical sessions do not replace physical backend grants. Physical read,
178
+ stat, delete and prepared-write grants remain separate, including Artifact read
179
+ and removal-only cleanup authority.
180
+
181
+ ## Physical backend and reads
182
+
183
+ `storage.backend.v2` remains separate from the public `storage.v1` capability.
184
+ Describe reports capacity; grant authorizes stat/read/delete; prepare-write reserves
185
+ space for an immutable Blob before issuing a write grant. A lost reply can have
186
+ reserved bytes. Receipts are resolved before changing repositories. Issued grants survive temporary Core control disconnection until normal expiry;
187
+ explicit binding removal still revokes unused grants. TLS is pinned,
188
+ with redirects and proxy inheritance disabled. Core's internal `mhome-storage-disk`
189
+ source crate (`publish = false`) owns disk durability, repository identity,
190
+ reservations and idempotent unlink. Core and the Storage Plugin reuse this code;
191
+ it has no independent public package release.
192
+
193
+ Errors carry `code`, `detail` and `outcome` (`notApplied`, `partial`, `unknown`),
194
+ with optional `deletedObjects` for confirmed per-attempt deletions. Unknown
195
+ transport results are not proof of failure. Range reads do not hash the whole
196
+ file first. Full Artifact streams can check integrity incrementally, withholding
197
+ the last bytes until verification succeeds.
198
+
199
+ This version supports new databases only. Edit complete baselines; never convert
200
+ old data at startup. Preserve old databases/files for a separately authorized import.