@mhome/app-facade-protocol 1.152.2 → 1.154.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.
package/README.md CHANGED
@@ -28,6 +28,10 @@ Device-only rendering, online rows and chart series use the
28
28
  See [Agent LLM settings](contract/agent-llm-v1.md) for active-mode reads,
29
29
  independent saved configuration and Provider Operation boundaries.
30
30
 
31
+ See the [Suggestion contract](contract/suggestion-v1.md) for generic multi-type
32
+ results, complete Automation drafts, run/handling semantics and payment rules.
33
+ These declarations precede runtime route and product integration.
34
+
31
35
  See [Group operation state](contract/groups-v1.md) for incomplete application,
32
36
  manual reapplication, deletion and name-update outcomes.
33
37
 
@@ -6,9 +6,17 @@ A missing, internal, ambiguous or unplaced Card returns `NOT_FOUND`.
6
6
 
7
7
  The Facade owns the complete response: `spaceId`, `cardId`, `canvasId`, `title`,
8
8
  `primaryViewId` and `views: [{id, name, patternId}]`. Nullable fields are explicit.
9
- Views preserve order and identity. Weather views use `default.basic.weather`;
10
- automation-only Cards expose a synthetic `automation` pattern without a view ID.
11
- Unknown patterns remain null; consumers must not infer them from device names.
9
+ Views preserve order and identity. `patternId` uses the same canonical identifier
10
+ as the Card DevKit and renderer binding. Blueprint IDs remain exact and case-sensitive
11
+ (for example `basic.device.onoff_brightness_color`); there is no UI-base prefix.
12
+ Weather views use `basic.weather`; automation-only Cards expose a synthetic
13
+ `automation` pattern without a view ID. Generic Widget data types use lowercase
14
+ intrinsic IDs (`Number` → `number`, `Button` → `button`, `Select[]` → `select[]`),
15
+ with terminal `_R`/`_W` presentation markers removed. `Circadian` maps to
16
+ `basic.circadian`, `TemperatureDifference` to `temperaturediff`, and `AutomationTitle`
17
+ to `automation`. These are Widget type projections, not Blueprint aliases.
18
+ Missing patterns remain null; consumers must not infer them from device names.
19
+ An unfamiliar Blueprint ID remains exact; this read does not invent its renderer contract.
12
20
  Device values, resource references, layouts and renderer implementation data are
13
21
  excluded. Full and Essential preserve the same business fields.
14
22
 
@@ -0,0 +1,185 @@
1
+ # Suggestion contract v1
2
+
3
+ This package declares the shared Suggestion data contract and proposed Facade
4
+ operations. The declarations alone do not register routes, enable scheduling,
5
+ execute models, or expose a UI. Runtime and product integrations are delivered
6
+ separately. Existing conversation and Now Attention protocols are unchanged.
7
+
8
+ ## Responsibilities
9
+
10
+ - Foundation owns these DTOs, strict schemas and shared conformance fixtures.
11
+ - Agent owns SuggestionGenerator: prompts, allowed read/validation tools,
12
+ analysis, type-specific generation and validation. Automation is the first
13
+ production content type, not a restriction of the common framework.
14
+ - The backend responsible for a Space (Core or Lion) owns admission, budgets,
15
+ authorization, persistence, run completion, feedback and business handlers.
16
+ - Tiger adapts shared Agent execution, model routing and billing for cloud
17
+ Spaces. It does not own a second Suggestion database.
18
+ - Assistant, UI and future clients consume the same business Facades. They do
19
+ not compose Automation saves, enablement and feedback writes themselves.
20
+
21
+ A local Space retains its run and Suggestion data locally even when its model
22
+ inference uses the cloud. Data follows the existing Space migration/deletion
23
+ boundary. Runtime integration must verify that boundary before enabling runs.
24
+
25
+ ## Triggers, authority and payment
26
+
27
+ Only periodic generation and an authenticated user's explicit request start a
28
+ run. No event wakeups, per-Suggestion rechecks, observation states or observation
29
+ tasks are introduced. Expiration changes applicability, not scheduling.
30
+
31
+ The trusted `SuggestionInvocationContext` in conversation-api is independent of
32
+ chat surfaces and threads. Its trigger selects payment attribution:
33
+
34
+ | Trigger | Payer | Result owner |
35
+ | --- | --- | --- |
36
+ | `EXPLICIT`, verified requesting `userId` | That user | The Space |
37
+ | `SCHEDULED` | Current Space owner, resolved by the billing adapter | The Space |
38
+
39
+ For example, if owner Alice and member Bob share a Space, a periodic run bills
40
+ Alice; Bob's explicit run bills Bob. Transferring Space ownership changes the
41
+ owner resolved for future scheduled billing admission. The billing adapter must
42
+ freeze its resolved payer consistently with existing model-accounting rules;
43
+ the public input and model output cannot select a payer. Billing failure must
44
+ not silently select another member or account.
45
+
46
+ This is a payment rule, not an authorization grant. A scheduled service is not
47
+ an enrolled `ClientPrincipal::Space`, nor a user impersonation. Core/Lion must
48
+ authenticate the internal admission, bind its Space and current execution
49
+ ownership, check enabled settings/model/budget, and restrict reads and validation
50
+ to that Space. Explicit generation additionally checks the requesting user's
51
+ Space access. Shape validation cannot substitute for those checks.
52
+
53
+ ## Generic content and validation
54
+
55
+ `SuggestionDraft<C>` contains title, summary, reasons, evidence, optional expiry,
56
+ and flattened content selected by `type`. `Suggestion<C>` adds backend-owned
57
+ identity, Space, run, version, lifecycle, millisecond timestamps and resolution.
58
+ The generator cannot assign those backend fields. A suggested expiry is checked
59
+ against admission/publication time before persistence.
60
+
61
+ Type names use `UPPER_CASE`. A registered type declares its strict content model,
62
+ validator and supported business actions. The content must serialize to an
63
+ object with the matching `type`, without shadowing common fields. Production
64
+ writers must reject unknown types and undeclared fields. The generic JSON Schema
65
+ leaves room for extension fields; passing it alone is insufficient for admission.
66
+ Validate the concrete registered type as well. Test-only `INFORMATION` fixtures
67
+ prove heterogeneous output without registering another production feature.
68
+
69
+ Extension needs are independent: a new input requires an authorized reader/tool;
70
+ a new output requires a content model, validator and appropriate consumer/handler.
71
+ Neither requires an independent scheduler or Suggestion table. Prompt changes
72
+ cannot authorize unknown executable types or arbitrary Facade targets.
73
+
74
+ Evidence preserves a source type, source identifier, optional observation time
75
+ and a concrete excerpt. The producer checks references against actual authorized
76
+ reads or already validated evidence. Missing, expired, truncated or unavailable
77
+ history must not be treated as proof that an event did not happen. Excerpts stay
78
+ with the Suggestion when raw history expires. They do not override current facts.
79
+
80
+ The Rust `validate()` methods enforce cross-field invariants as well as shape.
81
+ JSON Schema enforces portable shape/conditional rules; time ordering, same-Space
82
+ resolution actors, evidence provenance, business permissions and actual script
83
+ validity require host checks. Deserialization alone is not semantic validation. Nonblank text and identity
84
+ padding use Unicode White_Space, consistently with Rust `str::trim`; schemas
85
+ spell out that set because JavaScript `\s` treats NEXT LINE and BOM differently.
86
+
87
+ ## Automation content
88
+
89
+ `AUTOMATION` adds `operation`, `automationId`, `baseScriptHash` and `script`.
90
+
91
+ - `CREATE` has no existing Automation ID or base hash.
92
+ - `UPDATE` requires both the existing ID and the hash of its source at generation.
93
+ - `script` preserves the complete existing AutomationScript object: main `script`,
94
+ auxiliary `scripts`, optional `sdkVersion` and optional `parseResults`.
95
+ - The final source bundle must pass the existing Automation verifier before the
96
+ Suggestion is published. Nonempty source or model-supplied parse results do not
97
+ constitute verification. No Automation is saved/enabled during generation.
98
+ - Applying an update checks the base hash within the existing editing boundary.
99
+ It must not overwrite an intervening user change after a separate stale check.
100
+
101
+ The first Automation handler declares `APPLY`: a newly created Automation is
102
+ saved and enabled; an update preserves the existing Automation's enabled or
103
+ stopped state within the editing boundary. A deliberately stopped Automation must
104
+ not be re-enabled by applying an update. UI labels state the resulting action.
105
+ Save/enable failure or an unknown outcome is not a completed resolution.
106
+
107
+ Other type handlers declare their own actions. The common framework does not
108
+ equate acceptance with enabling or running a resource. UI opens the already
109
+ generated source without a new model call; handling may revalidate against
110
+ current resources and supported SDK rules.
111
+
112
+ ## Run and result semantics
113
+
114
+ One Space has at most one active run. A duplicate admission returns that run with
115
+ `accepted: false`; its focus is not incorporated and its payer is not substituted.
116
+ The host owns `SuggestionRun` status and measured model usage. The generator
117
+ returns drafts and an optional bounded context summary, never a success claim or
118
+ its own accounting. Analysis, script generation and bounded repair share one
119
+ run budget: model calls, prompt/output size, tool results and deadline.
120
+
121
+ | Status | Meaning |
122
+ | --- | --- |
123
+ | `RUNNING` | Admitted; no published result IDs or completion time yet |
124
+ | `SUCCEEDED` | Completed; zero results is normal |
125
+ | `PARTIAL` | Completed with recorded error and any independently valid results |
126
+ | `FAILED` | No published results; recorded error |
127
+ | `CANCELLED` | Stopped with no published results |
128
+
129
+ The host settles publication and run state, so a run that publishes valid results
130
+ alongside a failure is `PARTIAL`, not `FAILED`. Failure preserves existing
131
+ Suggestions and the last successful context. A process restart does not replay
132
+ model reasoning or blindly rerun writes. This contract does not require an
133
+ unbounded run log, a retry service or catch-up runs for every missed period.
134
+
135
+ ## Suggestion lifecycle and handling
136
+
137
+ `PENDING` means available for review, `RESOLVED` means the declared type action
138
+ completed, `DISMISSED` records rejection, and `EXPIRED` means no longer applicable.
139
+ Resolved/dismissed records require a backend resolution. Pending/expired records
140
+ have none. Resolution records the action, existing operation ID, time, canonical
141
+ actor and resulting resource IDs/feedback. `RESOLVED` is not proof that a physical
142
+ device reached its target. Failed or unknown outcomes cannot be marked resolved.
143
+
144
+ Handling and feedback bind `suggestionId` plus `expectedVersion` to what the
145
+ user reviewed. Business authorization and existing prepare/commit or idempotency
146
+ protocols remain authoritative. The backend checks expiry, current resources and
147
+ type-specific preconditions before performing the declared action. Repeated
148
+ requests retain the same operation identity; unknown outcomes do not justify
149
+ unconditional write replay. The model cannot create its own handler or action.
150
+
151
+ Next-run context includes current facts, pending Suggestions and recent decisions
152
+ and actual results, plus a bounded summary. Do not append all old prompts forever
153
+ or replace fresh facts with an old model summary. Existing history remains in its
154
+ own business stores. Now is a presentation consumer, not a Suggestion content type;
155
+ its deterministic Attention selection remains a separate responsibility.
156
+
157
+ ## Facade declarations
158
+
159
+ All operations use existing `FacadeCall` and `FacadeResponse`, including caller
160
+ authorization, operation identity, Full/Essential presentation and errors. Space
161
+ is supplied by authorized invocation context, not an input `spaceId` field.
162
+ The following are contract declarations, not a current support inventory.
163
+
164
+ | Target | Input | Business output |
165
+ | --- | --- | --- |
166
+ | `/app/suggestion/generate` | `GenerateInput`: optional nonblank `focus` | `GenerateOutput`: `accepted` and run |
167
+ | `/app/suggestion/generation/get` | `GenerationGetInput`: optional `runId` | `GenerationGetOutput`: current/latest run, or null before any run |
168
+ | `/app/suggestion/list` | `ListInput`: type/status filters, cursor, limit (default 50, maximum 100) | `ListOutput`: summaries and optional cursor |
169
+ | `/app/suggestion/detail/get` | `DetailInput`: `suggestionId` | Complete typed Suggestion |
170
+ | `/app/suggestion/handle` | `HandleInput`: ID, expected version, declared action | Updated Suggestion summary on completed success |
171
+ | `/app/suggestion/feedback` | `FeedbackInput`: ID, expected version, `DISMISS`, optional comment | Updated Suggestion summary on completed success |
172
+
173
+ An explicit unknown or no-longer-retained run ID returns `NOT_FOUND`; it must not
174
+ silently return an unrelated run. Lists are bounded and omit script bundles,
175
+ evidence and resolutions; detail reads return the saved complete content.
176
+ Business errors/partial or unknown outcomes use the canonical Facade result and
177
+ must not be converted to a successful lifecycle transition.
178
+
179
+ ## Conformance
180
+
181
+ `fixtures/suggestion.conformance.json` is shared by Rust and strict AJV tests.
182
+ The execution identity has a separate shared corpus in conversation-api.
183
+ These tests cover shape, multiple types, complete bundles, backend-field rejection,
184
+ status invariants and payment selection. They do not prove runtime authorization,
185
+ script compilation, billing settlement, persistence or local/cloud integration.