@mhome/app-facade-protocol 1.153.0 → 1.155.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
 
@@ -44,3 +44,44 @@ calls and prepared commits, in Full and Essential presentation.
44
44
  A partially deleted definition remains available for deletion with the same ID.
45
45
  Existing cleanup steps tolerate resources already removed by an earlier attempt.
46
46
  An already absent and cleaned definition is a completed delete target.
47
+
48
+ ## Single execution control and evidence
49
+
50
+ - `/app/automation/instance/list` takes `{automationId}` and returns
51
+ `{instances: [{threadId, instanceId, revision, phase, startedAt}]}`. Only active
52
+ runs are listed, oldest start first. `phase` is `EXECUTING`, `WAITING`, `QUEUEING`
53
+ or `STOPPING`. Full times are epoch milliseconds; Essential uses Home time.
54
+ - `/app/automation/instance/stop` takes `{automationId, threadId, instanceId}`.
55
+ It fences that instance, captures its execution facts durably, and closes it.
56
+ It leaves other instances and future recurring triggers enabled. The response
57
+ is `{automationId, threadId, instanceId, state, outcome}`. `STOPPING` means the
58
+ executing worker has not completed capture; repeat the same request to observe
59
+ completion. `FINISHED` reports the authoritative terminal outcome. A run that
60
+ completed before the stop request keeps its actual outcome; ordinary success
61
+ may already have discarded its details. Already performed effects are not undone.
62
+ A started external call without a result is uncertain, not a confirmed failure.
63
+ - `/app/automation/diagnostic/get` takes `{automationId}` and lists retained
64
+ execution metadata across all threads, newest first. Bodies are read separately.
65
+ - `/app/automation/diagnostic/read` takes the execution identity and optional
66
+ `cursor`, and returns `{logs, nextCursor}`. Follow the opaque cursor for older
67
+ events. Pages contain up to 100 events with a target size of 256 KiB; a single
68
+ larger event is returned intact. Pagination never removes stored content.
69
+ Missing or damaged bodies produce an error; they are never represented as an
70
+ empty successful page.
71
+
72
+ Events contain `sequence`, `timestamp`, `kind`, `operationId`, `level`, `message`
73
+ and `details`. Ordinary events describe actual action/read requests, their results,
74
+ and scheduled waits. Paired events share an operation ID. Schema-declared sensitive
75
+ request fields are excluded. DEBUG adds internal compiler/interpreter flow. JSONL
76
+ storage uses epoch milliseconds; Essential renders timestamps in Home time without
77
+ changing stored instants. Agent fetches source through the standard source interface;
78
+ execution records never duplicate the original Plan or source.
79
+
80
+ Normal success discards details. Failures/interruption, DEBUG and explicit capture
81
+ retain at most ten instances per thread across revisions. Activity summaries have
82
+ separate retention. Checkpoints persist only new immutable JSONL segments and a
83
+ constant-size head reference, plus runtime memory. An empty segment is not written.
84
+ The Plan is fetched by automation/thread and must match the run's revision; a missing
85
+ or changed Plan ends the old run. Generation and ownership checks still apply.
86
+ A process crash can lose events since its last checkpoint. Explicit stop confirms
87
+ completion only after available evidence has been saved, before checkpoint cleanup.
@@ -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.
@@ -342,11 +342,9 @@
342
342
  "threadId": 0,
343
343
  "instanceId": "run",
344
344
  "timestamp": 100,
345
- "status": "failed",
345
+ "status": "FAILED",
346
346
  "reportMode": "STD",
347
347
  "logCount": 2,
348
- "omittedLogs": 1,
349
- "truncated": true,
350
348
  "logsMissing": false,
351
349
  "failure": {
352
350
  "message": "device unavailable",
@@ -355,18 +353,7 @@
355
353
  "revision": 3,
356
354
  "startedAt": 90,
357
355
  "finishedAt": 100,
358
- "logs": [
359
- {
360
- "level": "INFO",
361
- "message": "Invoked device",
362
- "timestamp": 100
363
- },
364
- {
365
- "level": "ERROR",
366
- "message": "Timed out",
367
- "timestamp": 100
368
- }
369
- ]
356
+ "captured": false
370
357
  }
371
358
  ]
372
359
  },
@@ -378,11 +365,9 @@
378
365
  "threadId": 0,
379
366
  "instanceId": "run",
380
367
  "timestamp": "1970-01-01 00:00:00.100 +00:00 (UTC)",
381
- "status": "failed",
368
+ "status": "FAILED",
382
369
  "reportMode": "STD",
383
370
  "logCount": 2,
384
- "omittedLogs": 1,
385
- "truncated": true,
386
371
  "logsMissing": false,
387
372
  "failure": {
388
373
  "message": "device unavailable",
@@ -391,18 +376,7 @@
391
376
  "revision": 3,
392
377
  "startedAt": "1970-01-01 00:00:00.090 +00:00 (UTC)",
393
378
  "finishedAt": "1970-01-01 00:00:00.100 +00:00 (UTC)",
394
- "logs": [
395
- {
396
- "level": "INFO",
397
- "message": "Invoked device",
398
- "timestamp": "1970-01-01 00:00:00.100 +00:00 (UTC)"
399
- },
400
- {
401
- "level": "ERROR",
402
- "message": "Timed out",
403
- "timestamp": "1970-01-01 00:00:00.100 +00:00 (UTC)"
404
- }
405
- ]
379
+ "captured": false
406
380
  }
407
381
  ]
408
382
  }
@@ -5041,5 +5015,73 @@
5041
5015
  }
5042
5016
  },
5043
5017
  "code": "OPERATION_FAILED"
5018
+ },
5019
+ {
5020
+ "name": "automation-diagnostic-read",
5021
+ "target": "/app/automation/diagnostic/read",
5022
+ "timezone": "Asia/Shanghai",
5023
+ "status": "success",
5024
+ "data": {
5025
+ "logs": [
5026
+ {
5027
+ "sequence": 1,
5028
+ "kind": "wait.started",
5029
+ "operationId": "visit-1",
5030
+ "level": "INFO",
5031
+ "message": "Waiting",
5032
+ "timestamp": 100,
5033
+ "details": {
5034
+ "dueAt": 1200100,
5035
+ "taskId": 3
5036
+ }
5037
+ }
5038
+ ],
5039
+ "nextCursor": "opaque"
5040
+ },
5041
+ "essential": {
5042
+ "logs": [
5043
+ {
5044
+ "sequence": 1,
5045
+ "kind": "wait.started",
5046
+ "operationId": "visit-1",
5047
+ "level": "INFO",
5048
+ "message": "Waiting",
5049
+ "timestamp": "1970-01-01 08:00:00.100 +08:00 (Asia/Shanghai)",
5050
+ "details": {
5051
+ "dueAt": "1970-01-01 08:20:00.100 +08:00 (Asia/Shanghai)",
5052
+ "taskId": 3
5053
+ }
5054
+ }
5055
+ ],
5056
+ "nextCursor": "opaque"
5057
+ }
5058
+ },
5059
+ {
5060
+ "name": "automation-instance-list",
5061
+ "target": "/app/automation/instance/list",
5062
+ "timezone": "Asia/Shanghai",
5063
+ "status": "success",
5064
+ "data": {
5065
+ "instances": [
5066
+ {
5067
+ "threadId": 0,
5068
+ "instanceId": "run",
5069
+ "revision": 3,
5070
+ "phase": "STOPPING",
5071
+ "startedAt": 100
5072
+ }
5073
+ ]
5074
+ },
5075
+ "essential": {
5076
+ "instances": [
5077
+ {
5078
+ "threadId": 0,
5079
+ "instanceId": "run",
5080
+ "revision": 3,
5081
+ "phase": "STOPPING",
5082
+ "startedAt": "1970-01-01 08:00:00.100 +08:00 (Asia/Shanghai)"
5083
+ }
5084
+ ]
5085
+ }
5044
5086
  }
5045
5087
  ]