@agentshouse/kit 0.0.1 → 0.1.0-alpha.2

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1696 -2
  3. package/bin/connect-linux.sh +127 -0
  4. package/bin/kit.js +1023 -0
  5. package/package.json +33 -3
  6. package/src/acp.js +99 -0
  7. package/src/adapter-mcp.js +44 -0
  8. package/src/adapter.js +252 -0
  9. package/src/agent-logins.js +65 -0
  10. package/src/agents.js +449 -0
  11. package/src/apply.js +29 -0
  12. package/src/attach.js +52 -0
  13. package/src/binding.js +90 -0
  14. package/src/blocks.js +156 -0
  15. package/src/bridge.js +449 -0
  16. package/src/bytes.js +89 -0
  17. package/src/channel.js +37 -0
  18. package/src/command.js +109 -0
  19. package/src/configuration.js +465 -0
  20. package/src/connector-login.js +91 -0
  21. package/src/connector.js +107 -0
  22. package/src/continuation.js +61 -0
  23. package/src/contract.js +363 -0
  24. package/src/conversation-originals.js +143 -0
  25. package/src/custom/authorization.js +63 -0
  26. package/src/declaration.js +35 -0
  27. package/src/delivery.js +191 -0
  28. package/src/directory.js +102 -0
  29. package/src/draft.js +89 -0
  30. package/src/google/calendar.js +177 -0
  31. package/src/google/declared.js +146 -0
  32. package/src/google/drive.js +435 -0
  33. package/src/google/gateway.js +166 -0
  34. package/src/google/gmail.js +249 -0
  35. package/src/google/id.js +1 -0
  36. package/src/google/oauth.js +273 -0
  37. package/src/google/source.js +25 -0
  38. package/src/hook.js +376 -0
  39. package/src/host.js +121 -0
  40. package/src/house-main.js +79 -0
  41. package/src/house.js +1085 -0
  42. package/src/inbound.js +175 -0
  43. package/src/instance/google.js +1 -0
  44. package/src/launcher-main.js +19 -0
  45. package/src/launcher.js +276 -0
  46. package/src/local-files.js +113 -0
  47. package/src/login.js +274 -0
  48. package/src/mcp.js +71 -0
  49. package/src/migrator.js +248 -0
  50. package/src/mount.js +582 -0
  51. package/src/operation.js +20 -0
  52. package/src/original.js +631 -0
  53. package/src/peer.js +124 -0
  54. package/src/plan.js +57 -0
  55. package/src/question.js +316 -0
  56. package/src/refusal.js +79 -0
  57. package/src/repository.js +521 -0
  58. package/src/session-bin/house +2 -0
  59. package/src/settlement.js +57 -0
  60. package/src/setup.js +185 -0
  61. package/src/source-originals.js +116 -0
  62. package/src/source.js +286 -0
  63. package/src/starter-set/grilling/LICENSE +21 -0
  64. package/src/starter-set/grilling/SKILL.md +30 -0
  65. package/src/starter-set/grilling/agents/openai.yaml +3 -0
  66. package/src/starter-set.js +17 -0
  67. package/src/state.js +157 -0
  68. package/src/sync-library.js +293 -0
  69. package/src/sync-state.js +116 -0
  70. package/src/sync.js +477 -0
  71. package/src/telegram.js +1045 -0
  72. package/src/terminal.js +57 -0
  73. package/src/tmux.js +119 -0
  74. package/src/worker.js +756 -0
  75. package/src/workspace.js +500 -0
package/README.md CHANGED
@@ -1,3 +1,1697 @@
1
- # @agentshouse/kit
1
+ # House Kit
2
2
 
3
- Placeholder. Releases are published from https://github.com/agentshouse/kit.
3
+ House Kit is a public package repository. Product development is planned and
4
+ coordinated in the [Agents House repository](https://github.com/trof3039/agents.house);
5
+ this repository contains only the package source and its operator documentation.
6
+
7
+ ## Connect a Linux computer
8
+
9
+ On Linux `amd64` or `arm64` with a working Docker Engine, run the published,
10
+ versioned bootstrap once:
11
+
12
+ ```sh
13
+ bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.2/connect-linux.sh)
14
+ ```
15
+
16
+ The release asset pins one immutable multi-architecture image digest. It creates
17
+ owner-protected `~/.house-kit` and `~/AgentsHouse`, mounts those as the complete
18
+ Kit home and `/agents/house`, enrolls through House Login in the host browser,
19
+ and starts the container with Docker's `unless-stopped` lifecycle. Pass
20
+ `--workspace /absolute/path` for one other workspace root or `--manual` for
21
+ the existing URL and one-time-code login route. `--house <origin>` selects
22
+ another House and is retained in Kit home. A repeated invocation reuses the
23
+ same container, credential and Environment; a different installed image is
24
+ left for the explicit update journey.
25
+
26
+ The bootstrap does not install native Kit on an ordinary computer. The native
27
+ package remains for managed Nodes and an explicitly selected eligible Kit host.
28
+
29
+ ## Building the package
30
+
31
+ The repository checkout is the development source. Build the package
32
+ that can be published by supplying House's dedicated installed-application
33
+ Google OAuth client, its id and its client secret:
34
+
35
+ ```sh
36
+ HOUSE_KIT_GOOGLE_OAUTH_CLIENT_ID=kit-client.apps.googleusercontent.com \
37
+ HOUSE_KIT_GOOGLE_OAUTH_CLIENT_SECRET=GOCSPX-kit-installed-app \
38
+ npm run build
39
+ ```
40
+
41
+ The command writes the publishable package to `dist/package`. Both values are
42
+ public instance content fixed into that package at build time: Google issues an
43
+ installed application's client secret without treating it as confidential, and
44
+ still requires it in every token request. The installed Kit does not read either
45
+ from its runtime environment and never requests them from House.
46
+
47
+ Runtime dependencies stay minimal and exactly pinned in `package.json` and
48
+ `package-lock.json`: House's own `@agentshouse/mdmodel`, `yaml`, which reads
49
+ House's text answers, and the Agent Client Protocol SDK
50
+ `@agentclientprotocol/sdk` with its peer `zod`, which is this Kit's one protocol
51
+ client for the compiled adapter contracts. The SDK's approval
52
+ receipt is [`docs/agents/acp-sdk-dependency-approval.json`](docs/agents/acp-sdk-dependency-approval.json),
53
+ which the User wrote once this adoption's proof had passed. The adapter
54
+ packages themselves are Environment prerequisites, not Kit dependencies, and
55
+ carry no record.
56
+
57
+ The bootstrap invokes bare `kit login`. The first login names its new
58
+ Environment after the host computer and stores its Environment id in Kit home;
59
+ an explicit later login reconnects that retained id. `--environment <uuid>`
60
+ selects a different retained Environment for explicit recovery. A malformed
61
+ id or an answer naming a different Environment is refused before installation.
62
+
63
+ Use `--manual` when the browser cannot reach the Kit's loopback listener. The
64
+ command stores the issued Kit User credential in `$HOUSE_KIT_HOME/credential`
65
+ or `~/.house-kit/credential` with owner-only permissions, replacing the previous
66
+ file in one rename and leaving configuration, checkpoints, source state and
67
+ Agent relationships untouched. Reconnecting installs authority only: it starts
68
+ no Run and resumes no work, and the next `kit worker run` reconciles this
69
+ installation's bound sessions under its ordinary control rules.
70
+
71
+ If House never answers the exchange, the command refuses with
72
+ `kit_credential_not_installed` and no credential is written; the remedy is a
73
+ fresh owner-authorized `kit login` for the same Environment. The credential is
74
+ never printed by Kit.
75
+
76
+ ## Configuration
77
+
78
+ `$HOUSE_KIT_HOME/kit.json` is the one declarative configuration file. Use
79
+ `--config <path>` to name it elsewhere.
80
+
81
+ ```json
82
+ {
83
+ "availability": "continuous",
84
+ "execution_authority": "allow",
85
+ "migrators": [],
86
+ "instances": [
87
+ {
88
+ "id": "acme",
89
+ "preset": "custom",
90
+ "services": [
91
+ {
92
+ "service": "notes",
93
+ "source_ref": "src_acme_notes",
94
+ "rooms": ["work-room"],
95
+ "backfill": { "days": 30 },
96
+ "connector": {
97
+ "command": ["/usr/local/bin/acme-export", "--ndjson"],
98
+ "timeout_ms": 120000,
99
+ "environment": { "ACME_REGION": "eu" },
100
+ "secrets": {
101
+ "ACME_TOKEN": { "environment": "ACME_TOKEN_SOURCE" },
102
+ "ACME_KEY": { "file": "/run/secrets/acme-key" }
103
+ }
104
+ }
105
+ }
106
+ ]
107
+ }
108
+ ],
109
+ "clients": [
110
+ {
111
+ "kind": "claude-code",
112
+ "settings": "/home/ada/.claude/settings.json"
113
+ }
114
+ ],
115
+ "host": null
116
+ }
117
+ ```
118
+
119
+ This file is the whole desired state, so every section it declares is
120
+ reconciled and every section it omits is refused rather than assumed. The
121
+ agent CLI list is not local configuration: House owns it for this Environment,
122
+ and every controlled pass reads, installs, updates, signs in and reports exactly
123
+ the kinds House names. House also owns every Agent, its Profile and its route,
124
+ so this file declares neither Agents nor agent CLIs. The Kit runs whatever Agent
125
+ House assigns on one of House's selected kinds and refuses any other kind. The required
126
+ top-level `execution_authority` is this Environment's one answer to every agent
127
+ permission request, `"allow"` or `"refuse"`; the Agents sharing the Environment
128
+ share it. The
129
+ required top-level `availability` declares this Environment's availability
130
+ mode: `"intermittent"` for a laptop or other normally offline placement,
131
+ `"continuous"` for a server expected to stay online. Omitting it or declaring
132
+ any other value refuses as `kit_configuration_invalid`; `kit apply` sends the
133
+ declared mode with the rest of the desired state. An
134
+ instance declares one or more services, and under the `custom` preset each
135
+ service owns the command that produces it.
136
+
137
+ `host` declares the Linux host this installation measures for
138
+ [host capacity reporting](#host-capacity). `null` declares that this Kit reports
139
+ no capacity; the section is required like the others, so a host is measured only
140
+ where the Environment owner says so.
141
+
142
+ `clients` is the local Agent client catalogue and never leaves the installation.
143
+ Each entry names one client whose lifecycle hook configuration this Kit
144
+ reconciles: `kind` is `claude-code`, the one client this Kit installs a hook
145
+ into, and `settings` is the absolute path of that client's own settings
146
+ document. The section is required like the others and declares `[]` when this
147
+ Environment runs no such client. An unknown `kind`, a relative path, and two
148
+ entries naming the same document each refuse as `kit_configuration_invalid`.
149
+
150
+ A secret is never written into this file. `secrets` names either an
151
+ environment variable the Kit reads at run time or a mounted file it reads from
152
+ disk; the resolved value reaches the connector's environment and nothing else.
153
+
154
+ `backfill` is chosen once and honored on the first capture: `{ "days": 30 }`
155
+ never delivers anything observed earlier, `{ "count": 500 }` bounds the first
156
+ capture to 500 items and then continues from its cursor unbounded, and
157
+ `{ "all": true }` takes every history the connector offers. The boundary is
158
+ fixed when the service first captures, not each time a capture is attempted, so
159
+ a run that fails and is repeated days later still starts where it would have.
160
+
161
+ `timeout_ms` may shorten the connector's 120000 ms bound but never raise it. The
162
+ Kit holds this installation's Environment control lease across the connector run
163
+ and the batch it produces, and the lease has to outlive both.
164
+
165
+ Apply the declared source state to House:
166
+
167
+ ```sh
168
+ kit apply --house https://agents.house
169
+ ```
170
+
171
+ Only the state House declares - instances, services, `source_ref`, and Room
172
+ routes - leaves the installation. The connector, its secret references, and the
173
+ backfill boundary stay local.
174
+
175
+ ## The SessionStart hook
176
+
177
+ House answers `kit apply` with its current SessionStart hook: one
178
+ `{id, version, event, instruction}` document whose `instruction` tells the Agent
179
+ which Pulse and continuation reads to perform itself. The document is House's
180
+ own text under a stable `id`, versioned with the Kit contract version, and it
181
+ carries no Room content, open item, count, checkpoint, or identity.
182
+
183
+ `kit apply` writes that instruction to
184
+ `$HOUSE_KIT_HOME/state/hooks/<hook id>.txt` and installs one `SessionStart`
185
+ command hook printing it in every declared client's settings document. The
186
+ installed hook is that read and nothing else: it calls no House operation, marks
187
+ nothing seen, embeds no Room material, and infers no chat Session, so the Agent
188
+ decides what to read from the guidance it receives.
189
+
190
+ `state/hooks.json` records exactly which settings documents this installation
191
+ has written and the exact command it installed in each, so ownership is that
192
+ record and the command it names rather than any resemblance to one. An entry
193
+ whose command merely mentions the instruction is another owner's and is left
194
+ alone. `clients` is the desired state of that record: applying the same served
195
+ document again leaves each settings document byte-identical, dropping a client
196
+ from the catalogue removes this installation's entry from the document it named,
197
+ and an empty catalogue removes every entry, the record, and `state/hooks/`
198
+ without touching a hook, group, or setting the installation does not own.
199
+
200
+ One apply reaches every client or restores the ones it already wrote. Every
201
+ declared and previously recorded document is canonicalized, checked, and parsed
202
+ before House is contacted at all - including the `hooks` object and the
203
+ `SessionStart` array this Kit edits, so a document shaped differently refuses as
204
+ `kit_client_settings_unreadable` without changing anything remotely. The counters
205
+ House answers with are validated before the first local change. Each write then
206
+ re-resolves the whole declared path and re-checks the document it prepared,
207
+ refusing as `kit_client_settings_refused` when any part of the path, or the
208
+ document itself, was replaced meanwhile - a parent directory turned into a link
209
+ after preparation receives no write at all. A failed write or a cancellation
210
+ part-way restores every document already written to its previous bytes, removes
211
+ one this installation created, and names as `kit_client_settings_unrestored` any
212
+ it could not restore.
213
+ The previous instruction stays readable until the last document is written and
214
+ only then is it pruned, so a client left holding an older command still reads an
215
+ instruction that is there.
216
+
217
+ A path is canonicalized through `..` and symlinks before it is used: the Kit
218
+ writes through a symlinked settings document instead of replacing the link, and
219
+ refuses as `kit_client_settings_refused` a path that is not a regular document,
220
+ that two entries share, that resolves into this installation's own directory,
221
+ or - for a document already in the record - that no longer resolves to itself,
222
+ rather than writing through a link that replaced it. An existing document keeps
223
+ its file mode, one the client does not have yet is created owner-only, and one
224
+ the Kit cannot parse refuses as `kit_client_settings_unreadable` rather than
225
+ being replaced. Preparation reads before the Environment control lease is taken;
226
+ every write happens under that renewed lease with the apply it belongs to.
227
+
228
+ Continuity does not depend on the hook. An Agent working through any client
229
+ receives the same guidance in the server instructions and the tool descriptions,
230
+ and an installation whose catalogue is empty neither installs a hook nor needs
231
+ one served. A declared client is the opposite: an absent or malformed document
232
+ refuses as `kit_hook_rejected` instead of leaving whatever was installed before.
233
+
234
+ ## The Google preset
235
+
236
+ The published Kit is built with one House-owned Google installed-application
237
+ OAuth client. Its id and client secret are public build-time instance content,
238
+ not House secrets and not values served by House at run time. Google refresh
239
+ and access tokens remain in the installation's local credential store.
240
+
241
+ Each Google instance represents one Google account, and one Kit installation
242
+ may declare as many as the User has. Each instance owns its own local Google
243
+ authorization, selectors, Source references, Room routes, checkpoints and
244
+ health under `state/<instance>/`; the installation's one `kit login` covers
245
+ them all, and no instance can read another's provider credential.
246
+
247
+ ```json
248
+ {
249
+ "availability": "intermittent",
250
+ "execution_authority": "refuse",
251
+ "migrators": [],
252
+ "instances": [
253
+ {
254
+ "id": "google-account",
255
+ "preset": "google",
256
+ "scopes": ["https://www.googleapis.com/auth/contacts.readonly"],
257
+ "services": [
258
+ {
259
+ "service": "gmail",
260
+ "source_ref": "src_google_mail",
261
+ "rooms": ["work-room"],
262
+ "backfill": { "days": 30 },
263
+ "selection": { "labels": ["INBOX"] }
264
+ },
265
+ {
266
+ "service": "calendar",
267
+ "source_ref": "src_google_calendar",
268
+ "rooms": ["work-room"],
269
+ "backfill": { "all": true },
270
+ "selection": { "calendars": ["primary"] }
271
+ },
272
+ {
273
+ "service": "drive",
274
+ "source_ref": "src_google_drive",
275
+ "rooms": ["work-room"],
276
+ "backfill": { "count": 500 },
277
+ "selection": { "files": ["file-id"], "folders": ["folder-id"] }
278
+ }
279
+ ]
280
+ }
281
+ ],
282
+ "clients": [],
283
+ "host": null
284
+ }
285
+ ```
286
+
287
+ Google authorization is incremental. Enabling Gmail requests only Gmail's
288
+ read-only scope; Calendar and Drive request their own read-only scopes only
289
+ when enabled. Each service scope set has its own local provider grant, so a
290
+ later authorization never widens or replaces a sibling service's grant.
291
+ Additional Google API scopes are declared once on the preset instance and
292
+ remain local; a declared service names only scopes that instance already
293
+ holds. Drive requires at least one explicit file or folder selection and never
294
+ defaults to the whole account.
295
+
296
+ A Google API outside the three curated services may use the closed declared
297
+ service schema. The declaration is data only: no script or executable transform
298
+ is loaded. Its host must be a Google API domain and it runs under scopes the
299
+ instance already holds.
300
+
301
+ ```json
302
+ {
303
+ "service": "people",
304
+ "source_ref": "src_google_people",
305
+ "rooms": ["work-room"],
306
+ "backfill": { "all": true },
307
+ "declaration": {
308
+ "host": "people.googleapis.com",
309
+ "path": "/v1/people/me/connections",
310
+ "query": { "personFields": "names,emailAddresses,metadata" },
311
+ "page_size": "pageSize",
312
+ "scopes": ["https://www.googleapis.com/auth/contacts.readonly"],
313
+ "page_token": {
314
+ "request": "pageToken",
315
+ "response": "nextPageToken",
316
+ "checkpoint_request": "syncToken",
317
+ "checkpoint_response": "nextSyncToken"
318
+ },
319
+ "items": "connections",
320
+ "fields": {
321
+ "native_id": "resourceName",
322
+ "native_version": "etag",
323
+ "provider_modified_at": "metadata.sources.0.updateTime",
324
+ "observed_at": "metadata.sources.0.updateTime",
325
+ "body": ["names.0.displayName", "emailAddresses.0.value"],
326
+ "container": "metadata.sources.0.type"
327
+ }
328
+ }
329
+ }
330
+ ```
331
+
332
+ A Google instance signs in only through [Environment setup](#environment-setup),
333
+ on House's owner-authenticated page, so the owner's browser never has to reach
334
+ this Environment. For each enabled service whose scopes the instance does not
335
+ hold yet, the page links to Google's consent for exactly that service's scopes.
336
+ Google then sends the browser to a `http://127.0.0.1:<port>/` address that
337
+ nothing answers: the owner copies that whole address from the address bar and
338
+ pastes it into the page. The Kit accepts it only when it carries the state its
339
+ own consent issued, exchanges the code with its PKCE verifier and the built
340
+ client, and stores the grant locally. An address that answers another consent,
341
+ or a code Google refuses to exchange, fails the login and stores nothing; a
342
+ declined consent cancels it. Grants already completed for earlier services stay.
343
+
344
+ `kit source sign-in <instance>` signs in a custom connector instance through
345
+ its own command, described below. It skips an instance whose local
346
+ authorization is already valid and answers `ready`, `skipped`, or
347
+ `needs_attention`. A Google instance refuses it as `kit_connector_login_guided`
348
+ and names House setup.
349
+
350
+ ## Environment setup
351
+
352
+ House requests one setup when it creates a managed Environment and again when
353
+ its owner asks it to renew what the Environment holds. The Kit acts on the
354
+ request it acquires, never on its own:
355
+
356
+ ```sh
357
+ kit setup --house https://agents.house
358
+ ```
359
+
360
+ `kit worker run` performs the same step at the start of a pass, before it
361
+ hands out any work, so a managed Environment needs no terminal. The walk first
362
+ prepares the absolute `/agents/house` base, then visits every declared agent
363
+ CLI and then every connector instance, in configuration order:
364
+
365
+ - an agent CLI is installed or kept at its served release as
366
+ [the declared agent CLIs](#the-declared-agent-clis) describe; a kind no
367
+ release could be installed for needs attention as `install_failed`;
368
+ - a module whose own status check already answers signed in reports
369
+ `authenticated` to `/kit/logins/report`, which closes any renewal episode an
370
+ earlier attempt left open, and is `skipped`;
371
+ - otherwise the Kit runs the module's guided login. It reports the login to
372
+ House as `renewal_required` for `/kit/logins/report`, which opens or returns
373
+ one renewal episode, and presents the provider's steps on House's
374
+ owner-authenticated page by holding `/kit/secret-input/<episode>` until the
375
+ owner submits. Collected values go only to the waiting sign-in process; the
376
+ Kit sends none of them, and none of the sign-in's output, to any other act. A
377
+ sign-in whose status check then answers signed in reports `authenticated`
378
+ and is `ready`;
379
+ - a module without a guided route in this Kit, or one House does not advertise
380
+ (`kit_login_renewal_unsupported`), needs attention as `login_unavailable`
381
+ and opens no ceremony; a sign-in that exits without authenticating needs
382
+ attention as `login_failed`, and one that outlives its ten-minute bound as
383
+ `login_cancelled`. Either leaves its renewal episode open.
384
+
385
+ One module's failure never stops the walk. The Kit reports what it now holds
386
+ for every declared agent CLI and then the whole summary, one entry per module
387
+ with its `category`, `name`, `status` and `reason`, to `/kit/setup/report`
388
+ under the request it served, and releases its control lease. A cancelled
389
+ command reports no partial summary and releases its lease once the walk has
390
+ stopped.
391
+
392
+ Each compiled adapter contract carries the guided route its provider's own
393
+ headless sign-in offers, read from that command's output:
394
+
395
+ - `codex-acp` runs Codex's device sign-in. The page links to the provider's
396
+ device page and shows the one-time code the command printed; the owner signs
397
+ in with ChatGPT there and enters the code, and the command completes on its
398
+ own. Nothing is written back to it.
399
+ - `claude-agent-acp` runs Claude Code's sign-in. The page links to the authorize
400
+ page the command printed and collects the authentication code Claude shows
401
+ afterwards, which the Kit writes to that command alone. Claude Code answers a
402
+ code it refuses by asking for another, so the Kit ends that sign-in as soon as
403
+ the command prints `Invalid code.` and it needs attention as `login_failed`
404
+ rather than waiting out its ten-minute bound.
405
+ - `grok-build` runs Grok Build's device sign-in. The page links to the Grok
406
+ device URL and shows the anti-phishing one-time code printed by the command;
407
+ authorization completes in the browser and no secret is written back to the
408
+ process.
409
+
410
+ House offers only a route its provider evidence qualifies; one it does not
411
+ advertise stays `login_unavailable`.
412
+
413
+ ## The custom connector
414
+
415
+ Each custom service names one User-owned command. The Kit invokes it through an
416
+ argument vector, never a shell, with an environment holding only `PATH`, the
417
+ declared `environment` entries, and the resolved secrets. No House credential
418
+ and no Kit User credential is ever placed there. The request carries no service
419
+ name because the command is the service.
420
+
421
+ Stdin carries one JSON request line:
422
+
423
+ ```json
424
+ { "contract": "2026-08-22", "instance": "acme", "cursor": null, "limit": 100 }
425
+ ```
426
+
427
+ `cursor` is the opaque cursor the connector last returned, or `null` on the
428
+ first capture and after a reset. Stdout carries NDJSON: zero or more `item`
429
+ lines and at most one terminal `cursor` line.
430
+
431
+ ```
432
+ {"type":"item","namespace":"acme/notes","native_object_id":"note-91","native_version":"7","observed_at":"2026-08-20T09:15:00.000Z","body":"the note","author":"ada","url":"https://acme.example/notes/91","attachments":[{"url":"https://acme.example/files/1","name":"plan.pdf"}]}
433
+ {"type":"cursor","cursor":"page-2"}
434
+ ```
435
+
436
+ `namespace`, `native_object_id`, `observed_at`, and `body` are required;
437
+ `native_version`, `author`, `url`, and `attachments` are optional. There is no
438
+ metadata bag, no executable field, and no embedded credential. A malformed line
439
+ anywhere rejects the whole run: nothing is delivered and no checkpoint moves. A
440
+ non-zero exit status, a timeout, or output beyond the bound rejects the run the
441
+ same way.
442
+
443
+ An attachment names exactly one target. `url` is a verbatim reference House never
444
+ fetches. `file` names one work file the connector already acquired into this
445
+ Environment and declares its exact version:
446
+
447
+ ```
448
+ {"file":{"path":"/srv/acme/files/plan.pdf","bytes":48213,"sha256":"<hex>","media_type":"application/pdf"},"name":"plan.pdf"}
449
+ ```
450
+
451
+ `path` is absolute and never leaves the installation; `bytes` and `sha256`
452
+ describe the accepted version even when the connector could not download it,
453
+ and `media_type` is optional. The Kit publishes that descriptor as a retained
454
+ original on the Capture item, under an accepted version derived from the
455
+ delivery key, the attachment position and the descriptor, so reoffering the same
456
+ item always names the same version and a different descriptor under the same
457
+ delivery key is House's delivery-key conflict.
458
+
459
+ The Kit derives each item's delivery key from the instance, the service, the
460
+ declared namespace, the native object id, and the native version when present.
461
+ An object whose content changes without its native version changing keeps its
462
+ key and is refused by House as a delivery-key conflict rather than silently
463
+ overwriting the earlier Record.
464
+
465
+ The same command owns its module authorization. `kit source sign-in` and the
466
+ setup walk's status check send one JSON line
467
+ with `action: "authorization"` and `mode: "status"` or `mode: "login"`; the
468
+ command returns exactly one JSON object such as `{ "authorized": true }`.
469
+
470
+ ## The Worker runtime
471
+
472
+ ```sh
473
+ kit worker run --house https://agents.house
474
+ ```
475
+
476
+ Worker-runtime readiness validates the tmux this Kit declares support for,
477
+ reopens any already-bound live WorkerSession, brings every declared agent CLI
478
+ to its current release, starts each installed declared kind's command adapter
479
+ long enough to verify its compiled contract and read the options its own
480
+ session offers, reports what it holds to House, and only then acquires another
481
+ WorkerRun. This Kit compiles three MVP adapter kinds: `codex-acp` contract `2` selects
482
+ `@agentclientprotocol/codex-acp` `1.12.0` or a later `1.x` release, and
483
+ `claude-agent-acp` contract `1` selects
484
+ `@agentclientprotocol/claude-agent-acp` `0.79.0` or a later `0.x` release, while
485
+ `grok-build` contract `1` selects `@xai-official/grok` `1.0.41` or a later
486
+ `1.x` release and launches its native supervised ACP stdio mode. Each
487
+ contract names the adapter package, the minimum release the `initialize` answer
488
+ must reach, the executable it installs, the install recipe's own settings, the
489
+ CLI's headless sign-in command and the command that answers whether it is
490
+ signed in, the Agent Client Protocol version it speaks, its capability
491
+ descriptor - the admitted `elicitation/create` field kinds, whether the adapter
492
+ admits a declined form, and the stop-reason table of that adapter - whether the
493
+ adapter loads a session, and the identifiers of the session configuration
494
+ options the route's model and effort reach, or `null` for a field whose
495
+ adapter offers no such option. An acquired route carrying any other descriptor for
496
+ that kind refuses as `kit_adapter_contract_mismatch` before any spawn
497
+ commitment.
498
+ The `codex-acp` and `grok-build` contracts pin session loading and the
499
+ `claude-agent-acp` contract does not. The same readiness asserts that the initialize exchange Kit
500
+ wrote carried its elicitation declaration, because without it Claude Code
501
+ disables its question tool and Codex answers nothing.
502
+ An adapter whose running release is older than the contract's minimum, of
503
+ another major, mismatched, or unresponsive refuses `kit worker run` within 10
504
+ seconds per installed kind and names what it found, after the pass has reported
505
+ what it holds, and every other Kit command keeps working.
506
+
507
+ Once `initialize` passes, the Kit opens one Agent Client Protocol session with
508
+ `session/new` in its own home directory and no MCP server, reads that session's
509
+ configuration options, and stops the adapter; no prompt is sent. For each field
510
+ the contract names, it takes the `select` option carrying that identifier and
511
+ reports every value it offers with the display name the adapter gave it,
512
+ flattening option groups and keeping nothing else. A field whose identifier the
513
+ contract declares `null`, or whose option the session does not expose as a
514
+ `select`, reports none. An adapter that refuses the session with the Agent
515
+ Client Protocol's `auth_required` error, as `codex-acp` does before it is signed
516
+ in, reports no options at all and its kind stays served. A session that fails
517
+ for any other reason, does not open within 30 seconds, answers without a session
518
+ id, or offers options the Kit cannot read as values and names reports no options
519
+ either and refuses `kit worker run` as `kit_adapter_contract_mismatch`, like any
520
+ other contract failure. The Kit keeps no catalogue of these values and no copy
521
+ of them between passes: every report reads them from the adapter again.
522
+
523
+ ## Agent working directories
524
+
525
+ Connecting an installation creates `/agents/house`, the absolute base every
526
+ default Agent working directory lives under. Connecting again keeps whatever is
527
+ already under it. An installation that cannot create that directory refuses
528
+ with `kit_launch_base_unprepared` and names it, rather than substituting a
529
+ home-relative location: the Environment owner creates it once and gives the
530
+ installation write access to it.
531
+
532
+ Every acquired WorkerRun carries its Agent's absolute working directory and its
533
+ Agent id in its execution plan, and Kit launches the supervised session and its
534
+ adapter in exactly that directory. Kit recognises the Agent's own default
535
+ directory by exact equality with `/agents/house/<agent id>`, never by a
536
+ directory's mere position beneath the base: a sibling directory one level
537
+ inside `/agents/house` is somebody else's default or an owner's own workspace,
538
+ never this Agent's. Every path that is not this exact equality, one deeper
539
+ inside `/agents/house` included, must
540
+ already exist in this Environment as a directory the installation can enter;
541
+ Kit never creates or seeds it.
542
+
543
+ When the Agent's own default directory is absent, Kit builds the starter set in
544
+ a temporary directory beneath the base and renames it into place as one atomic
545
+ step, so a partly seeded directory is never visible at the default path. Two
546
+ concurrent first launches race that rename; the loser discards its temporary
547
+ directory and uses the directory the winner put there, so the pair still leaves
548
+ one complete directory and nothing partial. A present default directory -
549
+ including one whose starter files the owner edited or removed - launches
550
+ exactly as it is, and a deleted default directory is recreated with a fresh
551
+ starter set on its next launch.
552
+
553
+ The starter set is `AGENTS.md` with the single line ``The agents.house `house`
554
+ CLI is available: run `house --help`.``, `CLAUDE.md` as a relative symbolic link to it, `.agents/skills/grilling/`
555
+ vendored from [`mattpocock/skills`](https://github.com/mattpocock/skills)
556
+ `skills/productivity/grilling` at a pinned commit with its MIT license and a
557
+ provenance header naming that commit, and `.claude/skills` as a relative
558
+ symbolic link to `.agents/skills`. Once seeded the files belong to the owner:
559
+ Kit never syncs, refreshes, or restores them, and refreshing the vendored skill
560
+ for new Agents is an ordinary Kit release that never touches an already seeded
561
+ directory.
562
+
563
+ A relative, missing, inaccessible, or non-directory working directory refuses
564
+ with `kit_launch_directory_unavailable` before any provider process starts. Kit falls back to no other location - not the
565
+ base, not `$HOUSE_KIT_HOME`, and not its own current directory - and neither
566
+ connecting an installation nor launching a session moves, copies, overwrites,
567
+ or removes anything a working directory holds.
568
+
569
+ ## The declared agent CLIs
570
+
571
+ The Environment owner installs no adapter binary by hand. `kit agents update`
572
+ and every `kit worker run` bring each declared kind to the latest release its
573
+ contract serves - no older than the contract's minimum and inside that
574
+ minimum's major - under
575
+ `$HOUSE_KIT_HOME/agents/<kind>/releases/<release>/`, never touching what the
576
+ owner installed globally, and an acquired route's command is that installed
577
+ executable rather than a path anyone writes into `kit.json`.
578
+
579
+ Every candidate release is proved before it serves: the Kit installs it beside
580
+ the current release, runs the contract's own conformance check - the protocol's
581
+ `initialize` against the minimum release, the protocol version and the
582
+ capability descriptor the contract requires, and no provider-billed turn - and
583
+ switches to it only on green. On red it keeps the release it already has,
584
+ removes the candidate, and holds that kind with the refused release named in
585
+ its report until a newer candidate appears. Non-major releases advance this way
586
+ on their own; a major release waits for a contract revision. The candidate
587
+ check runs at most every six hours per kind, and `kit agents update` runs it at
588
+ once. A kind whose release lookup or installation fails keeps the release it
589
+ already has, or none, and is named with its failure; the other kinds go on,
590
+ `kit agents update` then exits non-zero, and a worker pass verifies and serves only the kinds with an installed release, so
591
+ one CLI the Kit could not install leaves only that kind's work unavailable.
592
+
593
+ The install recipe carries what the CLI needs beside its binary: for
594
+ `codex-acp` the Kit enables user-input questions in Codex's own configuration
595
+ document, because a Codex that disables them raises no `elicitation/create` and
596
+ answers nothing, and the Kit adds that setting only where the owner declared
597
+ none.
598
+
599
+ `kit agents sign-in <kind>` runs that CLI's own headless sign-in command in the
600
+ terminal it was started from, so the owner only completes it; House opens that
601
+ terminal and runs nothing itself. Both commands hold one control lease, release
602
+ it once they are done, and report to House afterwards what
603
+ this Environment now holds: per declared kind its compiled contract version,
604
+ the installed release or none, whether the contract's native readiness evidence
605
+ shows a signed-in provider, the candidate release a red conformance check refused, and the model and
606
+ effort options the installed adapter's own session offered, or `null` when no
607
+ release is installed or its session did not open. Every report, the worker pass's
608
+ and `kit setup`'s included, reads those options the same way and goes to
609
+ `POST /kit/agents/report` with one entry per declared kind:
610
+
611
+ ```json
612
+ {"agents": [{"kind": "claude-agent-acp", "contract_version": "1", "release": "0.81.2",
613
+ "signed_in": true, "hold": null,
614
+ "options": {"model": [{"value": "haiku", "name": "Haiku 4.5"}], "effort": []}}]}
615
+ ```
616
+
617
+ House knows about an agent CLI only
618
+ what this Kit reported: it probes no binary, version or login of its own, and
619
+ it refuses an Agent, an Agent Session and Agent-runtime acquisition for a kind
620
+ this Environment does not declare or this Kit has not reported installed and
621
+ signed in.
622
+
623
+ This installation owns one private tmux server namespace derived from
624
+ `$HOUSE_KIT_HOME`, so House never joins, lists, or destroys an ordinary tmux
625
+ session. Each acquired WorkerRun becomes one WorkerSession in one opaque exact
626
+ tmux session of that namespace, created from a Kit-owned configuration that
627
+ disables terminal retention. tmux owns the terminal lifecycle and nothing else:
628
+ the pane, its scrollback, and anything the adapter writes to its own stderr are
629
+ never read, stored, parsed, or answered, and no key is ever injected into a
630
+ pane.
631
+
632
+ Inside that session the Kit starts the launcher for the acquired route's
633
+ declared command adapter and hands it, over a Kit-private local channel, the
634
+ canonical request House gave the Kit and the adapter argument vector. Routine assignments carry their Routine Request.
635
+ Direct conversation assignments carry the sealed turn and its ordered messages,
636
+ and the Kit seals the reply itself on its own ingress.
637
+ An Agent resolves exactly one Execution route, so the acquisition envelope's
638
+ execution plan carries one `route` object and this Kit selects, orders, and
639
+ hands off nothing. The Kit launches that route as House admitted it and keeps
640
+ no local copy of it: an acquired route naming a kind `agents` does not declare
641
+ refuses as `kit_agent_undeclared`, and one whose kind has no installed release
642
+ as `kit_agent_not_installed`. The route names `adapter.kind` and
643
+ `adapter.contract_version`. The installed release of that kind plus the route's
644
+ `arguments` are the exact argument vector, so no route names a binary path.
645
+ The route's `model` and its `effort` or `null` are House-visible route facts in
646
+ the CLI's own vocabulary, which House stores as given and never validates; the
647
+ Kit hands them to the adapter at session start as its contract names, and a
648
+ value the CLI refuses fails the attempt with the CLI's own cause as
649
+ `kit_adapter_failed`. A route whose `effort` is `null` sets no effort, so the
650
+ CLI's own default effort applies and a model that offers no effort option
651
+ starts.
652
+ The adapter inherits only `PATH` and `HOME`, so the provider's own local
653
+ authorization stays in the Environment where its CLI already keeps it. The Kit
654
+ adds the Session's `house` CLI in front of that `PATH` and names the Session's
655
+ bridge socket and nonce in `HOUSE_KIT_BRIDGE` and `HOUSE_KIT_BRIDGE_NONCE`.
656
+
657
+ The launcher speaks the Agent Client Protocol through the protocol's official
658
+ TypeScript SDK, `@agentclientprotocol/sdk`, as this Kit's one protocol client;
659
+ the Kit frames no protocol JSON-RPC of its own. It opens the session with `session/new`
660
+ in the Environment's working directory with no MCP server, or reloads the
661
+ retained one with `session/load`, then sets the
662
+ route's model, and its effort when the route names one, through the protocol's
663
+ `session/set_config_option` with the option identifiers the adapter contract
664
+ names: `model` and
665
+ `reasoning_effort` for `codex-acp`, `model` and `effort` for
666
+ `claude-agent-acp`. Neither pinned adapter reads a model or effort flag of its
667
+ own. It carries the turn with one `session/prompt`, and maps that
668
+ prompt's stop reason through the contract's own table to one of four turn
669
+ outcomes: completed, interrupted, refused by the provider, or exhausted. A stop
670
+ reason the contract does not name, including a vendor-specific one a different
671
+ contract names, fails the turn as `kit_adapter_contract_mismatch` rather than
672
+ being guessed. It sends the request
673
+ as the first prompt block, followed by current House guidance fetched through
674
+ the Run connection. Missing or unreadable guidance refuses the turn; the
675
+ launcher does not copy the private Routine instruction into the acquisition
676
+ request. It forwards only adapter-classified User-visible assistant
677
+ text back over the local channel, and leaves reasoning, tool traces, and
678
+ terminal output where they are. The supervised process's own House calls travel
679
+ that same channel through the `house` CLI. The Kit holds the WorkerRunToken, replaces it in place when
680
+ it nears expiry without the child noticing, attaches a bridge-generated UUIDv7
681
+ to every Session mutation it forwards, and never places a House
682
+ credential in any child environment.
683
+
684
+ The Kit is the single source of assistant text: it observes the adapter, streams
685
+ what it has seen so far, and seals the turn itself. No Agent is asked to report
686
+ text a deterministic observer already sees, and no agent-facing tool admits final
687
+ text.
688
+
689
+ While the adapter generates, the Kit posts the whole User-visible assistant text
690
+ of the turn so far to `sessions/<session>/drafts` as an ephemeral draft. Only
691
+ adapter-classified assistant message text enters that stream; reasoning, tool
692
+ calls, plans, and terminal output never do. The Kit maps the structure it can
693
+ read in that text - paragraphs, headings, fenced code, ordered and unordered
694
+ lists, pipe tables, and `$$` formulas - into House's admitted blocks, and leaves
695
+ anything it did not parse as the paragraph it observed. It invents no structure
696
+ and renders nothing.
697
+
698
+ The Kit coalesces and paces that stream rather than mirroring every chunk. It
699
+ sends the first observed view at once, then at most one view every 500
700
+ milliseconds, and one more the moment the adapter completes a message; one call
701
+ is in flight at a time, so a newer view replaces the view it overtook and the
702
+ view observed last is the view House sees last. A view whose text exceeds
703
+ House's 4096-byte bound is not sent. A draft persists nowhere - not in this
704
+ Kit's local state, not as House history - is never retried, and can neither
705
+ delay nor prove turn completion: a refused, lost, or overtaken draft changes no
706
+ Run, WorkerSession, or delivery state. Ending the stream waits for no draft the
707
+ transport is still holding, so a slow or unanswered draft call cannot delay the
708
+ seal or the Run behind it.
709
+
710
+ When the adapter completes the turn, the Kit seals it with one
711
+ `sessions/<session>/assistant-messages` call carrying the same blocks and a
712
+ UUIDv7 `operation_id`. The exact request - that identity and those blocks - is
713
+ written into the WorkerSession binding before the call leaves, so a recovered
714
+ call returns the outcome House recorded and never seals a turn twice, and
715
+ House's answer names the turn it closed and the delivery it queued. An answer
716
+ the Kit never received leaves the Run unsettled with the request retained: the
717
+ next `kit worker run` replays exactly that operation and those blocks before
718
+ settling anything, rather than reporting a failure it cannot prove. A refusal
719
+ House did decide is the Run's reported failure.
720
+
721
+ That seal is the one durable record of the turn, and only a seal House accepted
722
+ completes a turn: the Kit reports whole-turn completion to House after the seal
723
+ succeeds and never otherwise. A turn whose adapter produced no User-visible text
724
+ seals nothing and claims no completed turn; the Run's own terminal outcome still
725
+ follows what the adapter reported.
726
+
727
+ The Agent reaches House only through the `house` CLI. Its verbs are the Tools
728
+ House lists to the Session, and its help is House's own: `house --help` prints
729
+ each listed Tool's name and description, and `house <verb> --help` prints that
730
+ Tool's description and input schema, all read from House's `tools/list` at the
731
+ call, so a catalogue change needs no Kit release. `house <verb>
732
+ '<arguments as one JSON object>'` calls that Tool, or `house <verb> -` with the
733
+ object on standard input for arguments longer than one command-line argument
734
+ holds. It prints House's text answer, or a refusal on standard error with a
735
+ nonzero exit status. The CLI holds
736
+ no credential: it calls over its Session's bridge, which attaches the Session
737
+ credential and refuses a caller without that Session's nonce as
738
+ `kit_bridge_unauthorized`. House network calls use only the selected
739
+ `2026-07-28` profile.
740
+
741
+ Two verbs name files on the Session's own computer: `upload_attachment` takes
742
+ one `path`, and `append_record` takes `attachments` as local paths. The CLI
743
+ resolves each path against its working directory. The bridge reads each regular
744
+ file, computes its size and SHA-256 and the media type an image's leading bytes
745
+ show, declares them beside the call, and uploads the exact bytes through the
746
+ one-use grant House answers before the call completes, so the answer carries the
747
+ attachment's `at_` reference. `append_record` uploads every file into its Room
748
+ first and names their references in the Record; a file that cannot be read or
749
+ saved appends nothing. The bridge reads House's YAML answers to
750
+ `upload_attachment`. A Room or `/private` upload ends at the byte upload rather
751
+ than at a House answer, so the bridge prints that saved answer in the same YAML;
752
+ every other answer passes through as House wrote it. With `conversation: true`
753
+ the file becomes the owner's conversation original, and the bridge calls again
754
+ and waits for House's delivery outcome. House derives the presentation from the
755
+ declared media type: an image is uploaded inline beside a link to the unmodified
756
+ original, and every other file is offered as that link alone.
757
+
758
+ The bridge retains the exact pending House request in memory before transfer.
759
+ Within the same live Kit and supervised WorkerSession, a lost response or
760
+ infrastructure failure resends that request with the same identifier. A local
761
+ socket reconnect delivers the retained outcome to the process.
762
+ A second deliberate call gets a new identifier; read-only calls carry none.
763
+ House refusals pass through to the CLI without automatic resend. [R193](https://github.com/agentshouse/core/blob/main/docs/concept/implementation/08-routine-requests-human-notifications-and-workers.md#r193)
764
+ owns recovery authority, lifetime, and refusal semantics.
765
+
766
+ The launcher speaks only what the adapter contract fixes for this build. Every
767
+ session initializes with the same fixed client capabilities: no file-system
768
+ methods, no terminal methods, and elicitation in form mode and not in URL mode.
769
+ It offers the adapter no filesystem or terminal surface of its own, so an adapter
770
+ that needs a decision the Kit cannot carry fails its turn instead of receiving a
771
+ guessed answer. Execution permission is the one decision the Environment already
772
+ settled: `kit.json` declares the Environment's `execution_authority` as `allow`
773
+ or `refuse`, and the launcher answers every adapter permission request with that
774
+ declared outcome and nothing else. The authority is a local Environment fact - it never reaches
775
+ House, and no permission request is ever projected to a human.
776
+
777
+ A task question is the decision the Environment cannot settle, so the launcher
778
+ carries it to the owner instead of answering it. The Interaction is the
779
+ protocol's own form end to end: an adapter's `elicitation/create` request in
780
+ form mode reaches House's interaction act as its `message` and its
781
+ `requested_schema`, unchanged in meaning, with the exact correlation of the
782
+ provider turn and of the adapter request that raised it. House alone judges
783
+ whether the schema is inside the flat subset it can ask; a form it admits as
784
+ unsupported, and a URL-mode request the Kit never forwards, cancel the
785
+ adapter's request with the protocol's `cancel` and ask the owner nothing.
786
+
787
+ Nothing of an adapter's native wire crosses: the Kit strips every native
788
+ `_meta` from the request, the schema, its properties and their options, and
789
+ gives a property the adapter left untitled its own name as title. Two facts
790
+ cross as House-namespaced marks instead. The batch carries
791
+ `_meta["agents.house/secret"]` when the adapter classifies the request as
792
+ secret in its own meta, as `codex-acp` does with `isSecret`; House records it
793
+ as unsupported and raises an interrupt rather than a card, so no secret prompt
794
+ is projected to a human and no secret answer travels back through House. A
795
+ choice carries `_meta["agents.house/free-text"]` when the adapter's own
796
+ convention admits the owner's words beside the listed options:
797
+ `claude-agent-acp` pairs a question with a `_askUserQuestionCustomAnswer`
798
+ companion field, and `codex-acp` pairs it with a `"None of the above"` option
799
+ and a `<id>_note` field tagged `user_note`. The companion field and the
800
+ synthetic option never reach House.
801
+
802
+ The owner's answer arrives as the `answer` command carrying the protocol's own
803
+ response, `accept` with content keyed by property name or `decline` for the
804
+ whole form, and is applied to that exact pending request; an answer naming
805
+ another turn or another correlation has no effect, so a stale or cross-Session
806
+ answer cannot reach a live adapter. A typed answer to a free-text choice goes
807
+ back through the adapter's own convention: into the companion field for
808
+ `claude-agent-acp`, and as `"None of the above"` with the typed text in the note
809
+ field for `codex-acp`. The turn waits on the adapter's own request while the
810
+ owner decides, and the Kit reports what became of each Interaction, so a
811
+ Session that ends with one outstanding expires it instead of leaving it live.
812
+
813
+ Before new execution, `kit worker run` reconciles House-authorized inbound cache
814
+ cleanup and materializes every pending conversation file House offers, ten at a
815
+ time, under `$HOUSE_KIT_HOME/conversation-inbound/<run>/<attachment>/<name>`.
816
+ House seals due input itself. The Kit uses the existing Environment lease and
817
+ byte endpoint, limits each file to 32 MiB, and reports materialization after
818
+ receiving a complete byte stream, validating any reported size, and writing the
819
+ file. A lost acknowledgement preserves the completed local file for House's
820
+ idempotent admission and later cleanup. Failed files remain pending; House's
821
+ all-files-ready gate keeps their turn unprocessed.
822
+ The provider receives absolute local paths beside the owning messages, both in
823
+ its initial prompt and in `session_get_request`. The cache persists across
824
+ turns; only House-authorized terminal Run cleanup removes its Run directory.
825
+
826
+ The accepted attachment's retained original is separate from that cache. The Kit
827
+ records a local note for the attachment before it acknowledges materialization,
828
+ then saves the exact bytes it received through House's conversation-original
829
+ door, naming only the attachment; a download that fails reports
830
+ `source_unavailable` for the same version.
831
+
832
+ A save that fails leaves one note in `state/conversation-originals/` naming the
833
+ attachment, its Run, the local file and the descriptor it declared. Each
834
+ later `kit worker run` retries it from that file without materializing or
835
+ acknowledging anything again, and reports `source_unavailable` when
836
+ the file is gone or changed rather than saving different bytes. While a
837
+ WorkerSession stays supervised the same retry runs at the heartbeat interval. The note leaves once
838
+ House records the save, once House answers that the Run is over, or when House
839
+ authorizes that Run's cache cleanup; House accepts no save for a Run that has
840
+ settled, so an unsaved original keeps its failed outcome from then on. The owner
841
+ reads every saved original through House afterwards, whether or not this
842
+ Environment still exists. `kit worker run` prints every conversation original
843
+ outcome it handled, and exits non-zero while any of them is unsaved.
844
+
845
+ One `kit worker run` then takes one House-authorized resumption, or otherwise
846
+ acquires one waiting Run, and supervises exactly that WorkerSession. A resumed
847
+ conversation loads its retained native provider session through ACP
848
+ `session/load`, receives the current input from House through
849
+ `session_get_request`, and executes one turn. Historical output replayed during
850
+ loading is not emitted as new assistant output. Missing or rejected provider
851
+ continuation never starts a replacement provider conversation in the same Run.
852
+
853
+ Continuation is per adapter. A contract that pins session loading retains the
854
+ adapter's opaque session handle between turns and resumes through it, as
855
+ `codex-acp` and `grok-build` do. A contract without it, as `claude-agent-acp`, retains nothing:
856
+ its turn reports no provider continuation, the Agent Session ends with the
857
+ reported cause `kit_provider_continuation_unavailable`, and the owner starts the
858
+ next one.
859
+
860
+ Between turns, Kit retains the opaque provider session identifier and the Run's
861
+ Worker, working directory, and route references in an owner-only local record.
862
+ The record carries no transcript or Session credential and grants no authority:
863
+ House must authorize each successor WorkerSession. A reported terminal state and
864
+ owner stops remove the record. [R199](https://github.com/agentshouse/core/blob/main/docs/concept/implementation/08-routine-requests-human-notifications-and-workers.md#r199)
865
+ owns conversation continuity.
866
+
867
+ Launcher exit is the terminal process observation. The Kit closes the local
868
+ channel, grants the launcher a fixed local exit grace, destroys the exact tmux
869
+ session if it is still there, and then reports one stopped Session at
870
+ `POST /kit/sessions/:session/stopped` and the adapter's own continuation facts at
871
+ `POST /kit/sessions/:session/continuation`, whose body is exactly
872
+ `{"provider_continuation": <bool>, "provider_capacity_exhausted": <bool>}`. No
873
+ adapter-supplied reset instant and no handoff availability is sent, and nothing
874
+ schedules a wake.
875
+
876
+ Kit, not the Agent, then reports the terminal state the execution reached at
877
+ `POST /kit/runs/:run/outcome`. No agent-facing tool posts it, and settling writes
878
+ no Record, Posting or Capture by itself: whatever the instruction wanted written
879
+ is written through the ordinary authorized Run mutations first. The body is
880
+ `{"operation_id": <uuidv7>, "outcome": "completed"}` or
881
+ `{"operation_id": <uuidv7>, "outcome": "failed", "cause": "<1-200 chars>"}`, and
882
+ the reported cause is exactly what the adapter gave. A finished turn that needed
883
+ no further Provider continuation is `completed`. A known execution failure, a
884
+ provider capacity exhaustion, a positively lost Provider continuation, and a
885
+ rejected native resume command are each `failed` with their own cause; House
886
+ notifies the owner and nothing is retried. A confirmed-stopped Session whose
887
+ Provider continuation remains available reports no terminal state at all and
888
+ leaves the Run active for an owner-originated resumption.
889
+
890
+ The Kit decides that terminal state once, records it beside its stable operation
891
+ identity before it reports it, and reports it from that record. A Run with a
892
+ supervised session records it in that session's durable local binding; a Run
893
+ whose terminal state was decided without one — a resume command this Kit rejects
894
+ because it retains no Provider continuation for the Run, or an acquired Run it
895
+ refuses before any provider process starts, which it commits and fails with the
896
+ refusal as the cause so no Run stays acquired behind it — records it in a
897
+ durable local settlement note of its own, named by the Run. A lost response is recovered by reporting that
898
+ identical body under the same operation identity on the next `kit worker run`;
899
+ House answers the committed settlement verbatim and the Agent is never executed
900
+ again. A Run House has already settled answers `worker_run_settled`, which the
901
+ Kit accepts as settled and drops the record for.
902
+
903
+ Every other refusal leaves that record exactly as it is. The Run stays bound to
904
+ this installation, `kit worker run` names the refusal House answered with and
905
+ exits non-zero, and the same decided body is reported again before anything is
906
+ acquired. Nothing is dropped locally that House did not accept, and a refused
907
+ report is never presented to the owner as a delivered one.
908
+
909
+ While a WorkerSession is supervised the Kit keeps one durable local binding
910
+ naming this installation, the WorkerRun, the WorkerSession, the exact tmux
911
+ session, and the local channel that reaches it. The binding carries no terminal
912
+ content, no prompt, and no resolved secret, and Session authority is always
913
+ reissued by House rather than recovered from disk. It is evidence for
914
+ reconciliation, never permission to resume or recreate work, and nothing keeps
915
+ it once House has answered for the Run: a settled terminal state, a confirmed
916
+ owner stop, and a retained Provider continuation each drop it.
917
+
918
+ A restarted `kit worker run` reconciles the records it kept before it acquires
919
+ anything new. It reports every retained settlement note first, because those
920
+ Runs have no session left to reconcile, and drops each note House accepts or
921
+ already settled. It next consumes the durable commands House holds for this
922
+ Environment, so a requested owner stop ends the exact tmux session before any
923
+ local channel reopens. It then considers only sessions of its own namespace
924
+ whose binding is complete, and never lists unknown sessions, scans host
925
+ processes, searches another namespace, or adopts an arbitrary process. A session
926
+ that is already gone is confirmed gone, reported as one stopped Session with no
927
+ Provider continuation, and settled as a terminal execution failure. A session
928
+ that is still running is restored only after House
929
+ positively replaces the Session authority for the same Run and Session; the Kit
930
+ then reconnects the typed adapter channel, refreshes the started observation,
931
+ and supervises that session to settlement instead of acquiring another Run. An
932
+ explicit House refusal destroys the stale tmux session and exposes no channel.
933
+ House that cannot be reached leaves the binding and the session exactly as they
934
+ are, invents no stopped, active, or authorized state, and acquires nothing.
935
+
936
+ A restore of House's database starts a new log epoch. Until this Environment
937
+ has reported in it, House refuses every act that touches a Run, acquisition and
938
+ lease release included, as `epoch_report_required` naming the epoch. The first
939
+ such refusal ends whatever the pass was doing. One raised inside a supervised
940
+ Run's bridge, while it admits or settles a question, streams a draft, or
941
+ replaces Session authority for a forwarded call, never becomes an answer to the
942
+ Agent: it ends the bridge and the pass at once. The Kit then reports, under the
943
+ lease it holds and at `POST /kit/sessions/report`, every Run it holds a spawn
944
+ commitment or a terminal outcome for: each retained binding, settlement note,
945
+ and Provider continuation, as `{"session": "<run>", "outcome": null}` while its
946
+ process runs, while it holds only its continuation, or while its outcome is
947
+ unknown, or with the held outcome it would have reported at
948
+ `POST /kit/runs/:run/outcome`, `completed` or `failed` with its cause. One
949
+ report carries at most 256 Runs, so the Kit sends as many as it needs, all
950
+ before it acquires anything. House settles every reported Run and never offers
951
+ it again, so once it has answered every report the Kit destroys each reported
952
+ tmux session still running, drops each reported Run's binding, settlement note,
953
+ and retained Provider continuation, and runs the pass again from its start. A
954
+ refused act is never a Run failure, nothing is acquired in the new epoch before
955
+ the report, and a refusal that follows the report ends the command naming it.
956
+
957
+ The launcher inside the supervised session outlives the Kit process that started
958
+ it. Its local channel reconnects to the same socket with a bounded backoff and
959
+ announces that its adapter session already exists, so a restored bridge
960
+ acknowledges the resumption instead of starting a second turn and the supervised
961
+ process never sees a second request. A call already transferred when the Kit
962
+ process ends is never automatically replayed by its successor, even when the
963
+ same local channel reopens. Pending mutation requests and identifiers are not
964
+ written into the durable binding. Reconciliation must obtain current House
965
+ authority before the live process can make further calls.
966
+
967
+ An owner stop requested through House reaches this Kit as a durable command,
968
+ both at startup and while a Session is supervised. The Kit destroys the exact
969
+ tmux session, confirms that it is gone, and reports the stopped Session. It
970
+ reports no continuation for a Run stopped by its owner and never reopens the
971
+ local channel for that Session.
972
+
973
+ ```sh
974
+ kit worker attach # the one supervised session
975
+ kit worker attach <session> # the exact session
976
+ ```
977
+
978
+ Attachment is a read-only diagnostic for the Environment owner. It reaches only
979
+ the exact tmux session of a live binding in this installation's namespace, gives
980
+ the Worker no input, makes no House call, causes no lifecycle transition, and
981
+ leaves the namespace configuration and its disabled terminal retention as they
982
+ are. Once the Session has settled or its tmux session is gone, attaching is
983
+ refused and names why.
984
+
985
+ ## Paired proof
986
+
987
+ Paired installed-CLI proof against the merged House producer is a labelled
988
+ validation build, not an npm release. From Linux Compose:
989
+
990
+ ```sh
991
+ docker build -f test/pair/producer.dockerfile -t kit-original-pair:latest .
992
+ HOUSE_CORE_ROOT=<agents.house checkout> \
993
+ docker compose -f test/pair/compose.yaml up --abort-on-container-exit --force-recreate producer
994
+ ```
995
+
996
+ It boots the real producer against a real PostgreSQL, installs the exact
997
+ candidate package, and runs `test/pair/*.vitest.ts`: the attachment doors,
998
+ a Source adapter retaining a declared file into Rooms of two owners, and an
999
+ installed Worker retaining an incoming attachment through failure, retry, Run
1000
+ settlement and cache disposal. `KIT_PAIR_SPECS`
1001
+ names the specs to run, and `HOUSE_CORE_REVISION` and `KIT_REVISION` are copied
1002
+ into the evidence each spec writes under `tmp/delivery-evidence/`.
1003
+
1004
+ ## Capturing
1005
+
1006
+ ```sh
1007
+ kit source capture acme --house https://agents.house # every declared service
1008
+ kit source capture acme notes --house https://agents.house # one service
1009
+ ```
1010
+
1011
+ Each run reads the checkpoint, acquires one bounded page, submits one batch,
1012
+ and advances the checkpoint only once every item in that batch is accepted or
1013
+ an idempotent duplicate at the House door. Every batch names the service's exact
1014
+ Source reference and its complete Room destination set, so House admits all of
1015
+ them or none: one destination the delivering User cannot currently write refuses
1016
+ the whole publication before any content changes. A refused item leaves the
1017
+ checkpoint where it was, so the next run reoffers the whole batch and converges
1018
+ on the door's own deduplication. When House stops a batch early, its answer
1019
+ settles only the prefix it reached, and the unsettled tail is reoffered with the
1020
+ rest. The loop repeats while the connector still returns items and no Room
1021
+ destination is blocked, and every run ends by writing the service's health into
1022
+ this installation's own state. House holds no preset, service, route, checkpoint
1023
+ or health of yours.
1024
+
1025
+ A Capture item that declares a `file` attachment answers one Record per Room
1026
+ destination: Rooms of one owner share that owner's Record, and a Room of another
1027
+ owner holds its own Record of the same delivery. The Kit records one retained
1028
+ reference for every destination Room and attachment in
1029
+ `state/<instance>/originals/<service>.json` before it saves anything, then
1030
+ saves that batch's references through House's captured-original door before it
1031
+ asks the connector for the next page: it reads the declared path, and uploads
1032
+ the bytes only when they still match the declared descriptor. References still
1033
+ outstanding from earlier runs are retried once the run's pages are delivered.
1034
+ A missing or changed file reports `source_unavailable` instead, so House never
1035
+ receives a substitute version. House, not the Kit, chooses where each Room
1036
+ owner's copy is kept. Every run prints each reference's save outcome beside its
1037
+ Room and Record and exits non-zero while any stays unsaved; acquisition health
1038
+ stays about acquisition, so a failed save never changes it.
1039
+
1040
+ ```sh
1041
+ kit source retry-files acme --house https://agents.house # every declared service
1042
+ kit source retry-files acme notes --house https://agents.house # one service
1043
+ ```
1044
+
1045
+ `retry-files` saves only the references still outstanding. It runs no connector,
1046
+ submits no Capture, moves no checkpoint, and keeps each reference's Record and
1047
+ accepted version; with nothing outstanding it contacts no House at all. A saved
1048
+ reference, or one whose Posting House no longer holds, leaves the local state. A
1049
+ Room whose write authority is gone answers `room_not_found` and stays outstanding
1050
+ until that authority returns.
1051
+
1052
+ ```sh
1053
+ kit source status acme # every declared service
1054
+ kit source status acme notes # one service
1055
+ ```
1056
+
1057
+ `kit source status` reads only local state: the current health and its exact
1058
+ category, the stored cursor, every open coverage gap with the recovery reference
1059
+ House returned for it, the items this installation dropped permanently, and the
1060
+ retained references still waiting to be saved.
1061
+
1062
+ Every command that changes or reads installation state takes this
1063
+ installation's exclusive Environment control lease for the length of its run
1064
+ and renews it before it expires, so two Kit commands never work against the
1065
+ same installation at once. A command that ends, or is interrupted once its work
1066
+ has stopped, releases that exact lease so the next command acquires at once; a
1067
+ refused command leaves it to expire. A `kit login` credential is presented only to take
1068
+ that lease.
1069
+
1070
+ Interrupting the command cancels the running connector without advancing the
1071
+ checkpoint.
1072
+
1073
+ ## Repository capture
1074
+
1075
+ Publish one local Git checkout as a Repository Source without giving House any
1076
+ Git credential:
1077
+
1078
+ ```sh
1079
+ kit repository capture /srv/acme \
1080
+ --room work-room \
1081
+ --source-handle acme-repository \
1082
+ --house https://agents.house
1083
+ ```
1084
+
1085
+ The command runs ordinary `git pull` in the checkout with the local User's Git
1086
+ configuration, credential helper, and SSH agent. After pull succeeds, Kit asks
1087
+ Git for tracked files plus untracked non-ignored files, hashes each selected
1088
+ file, and opens a Publication by posting that manifest - every selected path
1089
+ with its content fingerprint and byte length - to the authenticated Kit door.
1090
+ Git remains the only ignore owner.
1091
+
1092
+ House answers the Publication reference, the paths it needs, and the chunk
1093
+ bound it accepts. Kit delivers only those paths, in House's order, in chunks
1094
+ under that bound, streaming each file from disk at delivery time; it carries no
1095
+ bound, no delta, no counter and no retained archive of its own. House owns
1096
+ every tombstone, orders the Publication, and completes it in the request that
1097
+ leaves no needed path outstanding.
1098
+
1099
+ A file whose bytes disagree with the manifest House holds is refused as that
1100
+ item and the rest of the chunk stands. When a delivery round ends with refused
1101
+ items and the Publication is still active, Kit opens a new manifest of the
1102
+ current checkout and delivers again, at most three manifests per run. An
1103
+ interrupted run is never resumed: the next run opens a new manifest and House
1104
+ answers with what is still needed. The command reports the Publication
1105
+ reference, the paths delivered, the items refused and the ending.
1106
+
1107
+ ## Explicit synchronization
1108
+
1109
+ Beside the reconciling Working Copy, Kit has one explicit synchronization mode.
1110
+ It selects prefixes over the User root, materializes them into a named local
1111
+ directory, enumerates whole content and removals after the recorded positions,
1112
+ and submits a resolved exact-base change set the caller prepared. Kit does no
1113
+ local reconciliation. The mode shares no Working Copy manifest, never infers a
1114
+ removal from a locally absent file, and writes authored mutations only for the
1115
+ two Libraries and `ROOM.md`.
1116
+
1117
+ ```sh
1118
+ kit sync bootstrap ./replica \
1119
+ --house https://agents.house \
1120
+ --prefix /rooms/work/library \
1121
+ --prefix /rooms/work/capture \
1122
+ --prefix /private/library
1123
+ kit sync pull ./replica --house https://agents.house
1124
+ kit sync submit ./replica --house https://agents.house --changes ./changes.json
1125
+ kit sync rebootstrap ./replica --house https://agents.house
1126
+ ```
1127
+
1128
+ `bootstrap` writes `ROOM.md`, Library text, House-derived projections, and
1129
+ Capture text with its provenance sidecar, and records one position per selected
1130
+ authority from the bundle, with the log epoch House issued it in, together with
1131
+ the positive operation scopes House declared for it: `read`, `sync`, `write`,
1132
+ and `delete`, each a list of paths relative to the authority under which that
1133
+ operation is admitted. Managed replication needs `read` plus `sync` on a Room;
1134
+ a Room the User can only read answers `bootstrap`, `pull`, and `rebootstrap`
1135
+ with `operation_denied`. Generated `_provenance` files delivered beside authored
1136
+ Library paths are House metadata, not authored Library documents. `pull` presents
1137
+ each recorded position with its log epoch, applies each enumerated path's whole
1138
+ content or removal, and advances those positions. A position older than House's
1139
+ declared retention, or one of a log epoch before House's database was restored,
1140
+ is reported as `position_expired` with rematerialization as the remedy; only
1141
+ `rebootstrap` rebuilds the directory.
1142
+
1143
+ `submit` sends field, section, and preamble operations with that value's prior
1144
+ content as base, and whole-file, rename, and removal operations with the file
1145
+ revision. A rename of a populated directory instead carries a `base` map from
1146
+ every relative member path to its exact revision, such as
1147
+ `{"plan.md": "<revision>", "deep/log.md": "<revision>"}`, and House refuses it
1148
+ unless the map names exactly the directory's current members at their current
1149
+ revisions. Kit admits the rename at its source and destination and each named
1150
+ member at both, as House does.
1151
+ House alone validates the resulting Library: a batch it refuses answers with
1152
+ House's own file path, field, rule, and version. A refusal is reported with the
1153
+ current material House returned and the local directory is left for the caller.
1154
+ An acceptance updates the recorded position, its log epoch, and the affected
1155
+ files from the returned final content.
1156
+
1157
+ Pending submissions are written before transfer. A lost response, reconnect, or
1158
+ lease renewal recovers that exact request under the same identifier. A domain
1159
+ refusal is reported without automatic retry and without minting a replacement
1160
+ identifier. A second deliberate submit is a new identifier. After a restore of
1161
+ House's database, a request House holds no receipt for and whose identifier
1162
+ dates earlier than five minutes after the new log epoch began is answered
1163
+ `position_expired`: it wrote nothing and never will under that identifier, so
1164
+ the Kit drops it like any other refusal, `rebootstrap` rebuilds the directory,
1165
+ and a change still wanted is a new deliberate submit against the rebuilt bases.
1166
+ Once House has answered any request for a replica `position_expired`, the
1167
+ replica refuses `submit` as `position_expired` until `rebootstrap` rebuilds it.
1168
+ `rebootstrap` drops a submission still pending against the directory it
1169
+ replaces.
1170
+
1171
+ `--changes` names a JSON array of exact-base operations, or an object with a
1172
+ `changes` array. Omitting it derives field, section, preamble, create, and whole-file
1173
+ operations from local writable files against the last confirmed snapshot and
1174
+ still never infers a removal. A local edit of a selected protected path is
1175
+ refused before House is contacted as `protected_path`; a change outside the
1176
+ authority's `write` scope, or a removal outside its `delete` scope, is refused
1177
+ before House is contacted as `operation_denied`, the same code House answers
1178
+ for a batch that reaches it.
1179
+
1180
+ ## Attachments
1181
+
1182
+ Upload one local file as an attachment to a Room or to your private tree. Name
1183
+ the place explicitly. Kit sends the descriptor and the selected bytes; it does
1184
+ not scan a directory, convert a URL, or attach sibling files, credentials, or
1185
+ absolute paths.
1186
+
1187
+ ```sh
1188
+ kit attachment upload ./notes.bin \
1189
+ --house https://agents.house \
1190
+ --room room:work \
1191
+ --media-type application/pdf
1192
+
1193
+ kit attachment upload ./notes.bin \
1194
+ --house https://agents.house \
1195
+ --private
1196
+
1197
+ kit attachment get \
1198
+ --house https://agents.house \
1199
+ --attachment at_1x.q \
1200
+ --room room:work \
1201
+ --output ./notes.bin
1202
+ ```
1203
+
1204
+ `--room` and `--private` are mutually exclusive and one is required; `--name`
1205
+ defaults to the file's base name. The upload prints the attachment reference
1206
+ (`at_…`) House answered. That reference is what text links to: an attachment is
1207
+ meaningful only because a document links it, and House records those links from
1208
+ the accepted text. Retrying the same file after a lost response or failed upload
1209
+ reuses the stored version under the identical descriptor, so it completes the
1210
+ same attachment instead of creating a second one; uploading the same file to the
1211
+ same place again answers that same attachment. A changed file is a new
1212
+ attachment. HTTP 200 is not retention: only `save.status: saved` plus an
1213
+ independent download whose length and SHA-256 match counts. A failed local read
1214
+ or failed House save is not reported as saved. Transfer uses the current control
1215
+ lease and the one reusable byte client; the durable credential is presented only
1216
+ to `POST /kit/lease`. Sync commands do not fetch attachment bytes; Source and
1217
+ Worker retention save through the same byte client.
1218
+
1219
+ The same paired installed-CLI proof covers these doors; see
1220
+ [Paired proof](#paired-proof) for the command that runs it.
1221
+
1222
+ ## Persistent container Environments
1223
+
1224
+ An Always-on Linux host can run the persistent container Environments its owner
1225
+ creates in House. House owns the target: which host, the workspace name, and the
1226
+ CPU, memory and persistent-disk ceilings. This Kit owns the local lifecycle and
1227
+ reports only what it proved.
1228
+
1229
+ The supported configuration is one Linux host with
1230
+
1231
+ - cgroup v2 delegating the `cpu` and `memory` controllers, read from
1232
+ `/sys/fs/cgroup/cgroup.controllers`;
1233
+ - a reachable Docker Engine daemon;
1234
+ - `/dev/loop-control` present, so a workspace disk can carry an enforced size;
1235
+ - `host.workspace` pointing at a directory this Kit may create workspaces under;
1236
+ - `host.image` naming an image that carries Node, this Kit, `mkfs.ext4` and
1237
+ `nsenter`, and whose own entrypoint starts `kit worker run` from
1238
+ `HOUSE_KIT_HOME`.
1239
+
1240
+ Any missing prerequisite refuses the create before House ever presents the
1241
+ workspace as constrained, naming the exact missing piece.
1242
+
1243
+ ```sh
1244
+ kit workspace host --house https://agents.house
1245
+ ```
1246
+
1247
+ The command acquires this host's workspace work under its Environment control
1248
+ lease and settles each operation with what it observed:
1249
+
1250
+ - **create** formats one ext4 image of exactly the configured disk ceiling,
1251
+ mounts it as the workspace's only writable filesystem, writes that
1252
+ Environment's own Kit credential and a `kit.json` declaring the selected agent
1253
+ CLIs with `execution_authority` `allow` inside it, since nobody holds a
1254
+ terminal there to answer otherwise, and creates the container with
1255
+ `--cpus`, `--memory` and `--memory-swap` at the configured ceilings. The
1256
+ workspace is reported `stopped` with the runtime and the enforcement it
1257
+ proved. This host's own credential never enters the workspace: the only
1258
+ credential written there belongs to the Environment running inside it.
1259
+ - **start** mounts the workspace disk if the host rebooted, refuses when
1260
+ starting would leave less than the host reserve, starts the container, and
1261
+ reports `ready` only after the exact workspace proved it accepts execution.
1262
+ - **stop** stops the container and keeps the disk mounted, so ordinary files,
1263
+ installed tools and login state survive to the next start.
1264
+ - **delete** removes that exact container, unmounts that exact workspace disk and
1265
+ removes that exact directory. No other workspace, and nothing else on this
1266
+ host, is touched.
1267
+
1268
+ Every operation names one workspace this Kit created. A workspace the runtime no
1269
+ longer has is reported `absent` rather than recreated, so House ends the
1270
+ Environment visibly instead of inventing a process observation. On every pass
1271
+ this Kit reconciles its own labelled containers against the exact inventory
1272
+ House authorizes: a managed workspace House no longer authorizes to run is
1273
+ stopped, and a container this Kit did not create is never adopted, started or
1274
+ removed.
1275
+
1276
+ Ceilings are shared ceilings. The ceilings configured across one host may exceed
1277
+ that host, nothing is reserved for any workspace, and no workspace is promised
1278
+ its maximum while another one runs.
1279
+
1280
+ ## The Telegram gateway
1281
+
1282
+ House can project one owner's conversations through that owner's own Telegram
1283
+ bot. In Kit mode the BotFather token stays in one installed Environment, and
1284
+ this Kit is the only thing that calls the Bot API. House never receives the
1285
+ token: it appears in no request body, no refusal and no printed summary.
1286
+
1287
+ Exactly one Environment may be the gateway for one bot. House records that
1288
+ binding when the gateway registers, and refuses a second Environment claiming
1289
+ the same bot. Worker Environments stay unchanged: they still acquire Runs and
1290
+ materialize inbound conversation files.
1291
+ The gateway never runs a Worker's provider and a Worker never holds the token;
1292
+ the two exchange bytes only through House, which relays an inbound attachment
1293
+ from the gateway to the Worker that needs it and serves the gateway an outbound
1294
+ image from the original the Session stored.
1295
+
1296
+ Bind the bot to this Environment:
1297
+
1298
+ ```sh
1299
+ kit telegram connect --house https://agents.house
1300
+ ```
1301
+
1302
+ The command asks for the token on a hidden terminal prompt, or reads one line
1303
+ from standard input when it is not attached to a terminal. It asks Telegram `getMe`, and
1304
+ refuses a bot whose Threaded Mode is off, because House projects each
1305
+ conversation into its own forum topic. It then asks House whether this
1306
+ Environment may become the gateway, before it writes anything locally. Once
1307
+ House admits the preflight it deletes any webhook, so long polling is the only
1308
+ receiver, and proves the owner by reading one ordinary private message outside
1309
+ any topic through `getUpdates`, advancing the stored offset past it. Only then
1310
+ is the token written, and only then is the gateway registered with House. A
1311
+ setup House refuses removes the written token again, so a refused connect leaves
1312
+ no custody behind. The command prints the bot username, the bot user id and the
1313
+ proven owner's Telegram user id.
1314
+
1315
+ Run the gateway:
1316
+
1317
+ ```sh
1318
+ kit telegram serve --house https://agents.house
1319
+ ```
1320
+
1321
+ The command holds one Environment control lease for the whole run and performs
1322
+ three activities inside it, each paced on its own so none of them blocks
1323
+ another:
1324
+
1325
+ - **ingress** reads updates from the stored offset, normalizes each one into the
1326
+ update House accepts, submits it, and advances the stored offset only after
1327
+ House has taken it. A submission that fails leaves the offset where it was, so
1328
+ the same update is offered again rather than lost.
1329
+ - **inbound files** acquires the attachments House still needs, refuses anything
1330
+ reported above the 20 MiB download ceiling before calling `getFile`, downloads
1331
+ the file with the local token, and pushes the bytes to House for the Worker
1332
+ Environment that will materialize them. That push waits for the Worker to pull
1333
+ and a single failed fetch never ends the pass.
1334
+ - **outbound queue** acquires the per-bot queue in its exact order, marks each
1335
+ delivery attempted before it sends, and reports what Telegram answered:
1336
+ `delivered` with the exact message or topic Telegram returned, `failed` when
1337
+ Telegram refuses outright, and `delivery_unknown` when
1338
+ the answer is absent or unreadable. File items are pulled back from House,
1339
+ refused as `file_too_large` above the 10 MiB image ceiling, uploaded as
1340
+ `sendPhoto` with the caption House composed around the link to the retained
1341
+ original, and reported the same way; a pull that fails reports
1342
+ `transfer_failed` and an ambiguous upload answer reports `delivery_unknown`.
1343
+ Only an image ever becomes a file item, because House offers every other file
1344
+ as a `conversation_file_link` message this queue delivers like any other. Live drafts ride that same queue as their own item and are
1345
+ never reported back, because a draft has no settlement: House has already
1346
+ coalesced each conversation to its latest view, and the gateway sends the
1347
+ drafts of a pass after its durable deliveries with the Bot API's native
1348
+ `sendRichMessageDraft` on the bound forum topic thread, under the same bot-wide
1349
+ `retry_after` gate. The gateway coalesces nothing again and holds no draft for
1350
+ a later pass: a draft taken in a pass that gate closed is dropped, and the next
1351
+ view House coalesces takes its place. Pacing lives here because this is where
1352
+ the Bot API is called.
1353
+
1354
+ Each serve run first asks House to settle the attempts an earlier run abandoned,
1355
+ so a restarted gateway never leaves a delivery attempted forever. A Telegram
1356
+ `retry_after` opens one bot-wide gate: nothing is sent, fetched or polled until
1357
+ the delay Telegram supplied has passed. `--passes <count>` bounds each activity
1358
+ to that many passes and is what tests and one-shot runs use; without it the
1359
+ command is resident and stops on SIGINT or SIGTERM, printing what it settled.
1360
+
1361
+ Release the bot:
1362
+
1363
+ ```sh
1364
+ kit telegram disconnect --house https://agents.house
1365
+ ```
1366
+
1367
+ The command writes a local disconnect marker first, deletes the webhook, removes
1368
+ the token and the stored offset, tells House this Environment is no longer the
1369
+ gateway, and removes the marker last. Local custody is therefore always gone
1370
+ before House admits the change. A disconnect interrupted after the marker was
1371
+ written finishes on a later run even though the token is already gone, and a
1372
+ `kit telegram serve` that finds the marker refuses to act.
1373
+
1374
+ ## Local state
1375
+
1376
+ ```
1377
+ $HOUSE_KIT_HOME/
1378
+ credential
1379
+ kit.json
1380
+ conversation-inbound/<run>/<attachment>/<name>
1381
+ secrets/personal-telegram-bot.token
1382
+ state/telegram/get-updates-offset.json
1383
+ state/telegram/disconnecting.json
1384
+ state/hooks.json
1385
+ state/hooks/<hook id>.txt
1386
+ state/repositories/<repository identity>.json
1387
+ state/sync/<replica identity>.json
1388
+ state/sync/<replica identity>.pending.json
1389
+ state/attachments/<upload identity>.json
1390
+ state/conversation-originals/<attachment identity>.json
1391
+ state/sessions/<tmux session>.json
1392
+ state/continuations/<run identity>.json
1393
+ state/<instance>/credentials/google.json
1394
+ state/<instance>/checkpoints/<service>.json
1395
+ state/<instance>/health/<service>.json
1396
+ state/<instance>/gaps/<service>.json
1397
+ state/<instance>/dropped/<service>.json
1398
+ state/<instance>/originals/<service>.json
1399
+ ```
1400
+
1401
+ Every file is written atomically and readable only by its owner. A file the Kit
1402
+ cannot read is refused rather than treated as a service that never captured.
1403
+ Disabling a service or an instance leaves its state in place, so re-enabling
1404
+ resumes from the stored cursor instead of importing again.
1405
+
1406
+ ```sh
1407
+ kit source reset acme --house https://agents.house # every service
1408
+ kit source reset acme notes --house https://agents.house # one service
1409
+ ```
1410
+
1411
+ Reset is the only deletion of captured state. It removes the named checkpoints
1412
+ and their outstanding retained references so the next capture restarts exactly at
1413
+ the configured backfill boundary. It takes the same
1414
+ Environment control lease a capture takes, so it cannot delete a checkpoint a
1415
+ running capture is about to write back.
1416
+
1417
+ ## Host capacity
1418
+
1419
+ An owned Linux host can report what it actually has, so its owner reads real
1420
+ capacity instead of guessing from Run counts. Declare the host section:
1421
+
1422
+ ```json
1423
+ "host": {
1424
+ "workspace": "/var/lib/house-kit/workspaces",
1425
+ "maxima": {
1426
+ "cpu_millicores": 2000,
1427
+ "memory_bytes": 4294967296,
1428
+ "disk_bytes": 53687091200
1429
+ },
1430
+ "image": null
1431
+ }
1432
+ ```
1433
+
1434
+ `image` is the workspace image this host runs persistent container Environments
1435
+ from, and is only read by `kit workspace host` below; leave it `null` on a host
1436
+ that reports capacity and hosts no container. `workspace` is the absolute path of the persistent workspace directory; the
1437
+ report measures the filesystem holding it, not the root filesystem by
1438
+ assumption. `maxima` are the ceilings this host is configured to apply to
1439
+ Kit-managed workloads, and House keeps them apart from what it measured. Declare
1440
+ `"maxima": null` when this host configures no ceiling; an empty object is
1441
+ refused rather than read as no limit. A ceiling is a shared ceiling, never a
1442
+ reservation, and House infers no supported Agent count from any of these values.
1443
+
1444
+ ```sh
1445
+ kit host report --house https://agents.house
1446
+ ```
1447
+
1448
+ The command reads `/proc/stat` twice a second apart, reads `/proc/meminfo`, and
1449
+ asks the kernel for the workspace filesystem's block counts. It sends the host
1450
+ totals, what is in use, and what is available for each of processors, memory and
1451
+ that filesystem, with the instant it measured them. Nothing else is collected:
1452
+ no process list, no command line, no environment value, and no credential. A
1453
+ native source this Kit cannot read or parse refuses as
1454
+ `kit_host_unmeasurable` and sends nothing, because a host that cannot be
1455
+ measured is unknown to its owner rather than empty.
1456
+
1457
+ The report is one observation, not a stream. Run it on a timer the host owner
1458
+ owns:
1459
+
1460
+ ```
1461
+ [Unit]
1462
+ Description=Report measured host capacity to House
1463
+
1464
+ [Service]
1465
+ Type=oneshot
1466
+ User=house-kit
1467
+ ExecStart=/usr/bin/kit host report --house https://agents.house
1468
+ ```
1469
+
1470
+ ```
1471
+ [Timer]
1472
+ OnBootSec=1min
1473
+ OnUnitActiveSec=5min
1474
+ ```
1475
+
1476
+ House reads an observation as fresh only while three instants - the one this
1477
+ Kit says it measured, the one House received the report, and now - all fall
1478
+ inside one fifteen-minute window. A host that stops reporting reads as aged from
1479
+ then on, a report that was already stale when it arrived reads as aged
1480
+ immediately, and a host that never reported reads as unknown; none of them ever
1481
+ reads as a measured zero. Keep this host's clock in step with real time - a
1482
+ clock more than fifteen minutes out of step in either direction makes every
1483
+ report it sends read as aged, which is the honest answer House can give about a
1484
+ reading it cannot date, and dating a reading into the future buys no freshness
1485
+ because it widens the same window. A smaller skew is not free either: it is
1486
+ spent from the same fifteen minutes, so a clock a few minutes out of step leaves
1487
+ the timer above correspondingly less room to miss a run before House reads this
1488
+ host as aged.
1489
+
1490
+ ## Migrating authored text and linked originals
1491
+
1492
+ `kit migrate` runs under the Environment User's control lease. Its module
1493
+ category is `migrator`, declared in the required `migrators` array in `kit.json`
1494
+ (use `"migrators": []` when none are installed):
1495
+
1496
+ ```json
1497
+ {
1498
+ "id": "my-import",
1499
+ "category": "migrator",
1500
+ "command": ["/home/ada/tools/my-import"],
1501
+ "timeout_ms": 600000,
1502
+ "environment": { "EXPORT_REGION": "eu" },
1503
+ "secrets": { "EXPORT_TOKEN": { "file": "/run/secrets/export-token" } }
1504
+ }
1505
+ ```
1506
+
1507
+ The example is a user-installed module. Kit ships no concrete external-system
1508
+ migrator. Secret references resolve only in the Environment and are passed only
1509
+ to that module's process environment. The module receives neither House's
1510
+ credential nor its lease. Module output and stderr are not published or echoed;
1511
+ a module must never write an external credential into its emitted content,
1512
+ manifest, URLs, or attachments.
1513
+
1514
+ ```sh
1515
+ kit migrate emit my-import --package /home/ada/exports/project
1516
+ kit migrate mount /home/ada/exports/project --house https://agents.house \
1517
+ --subtree /rooms/work/library/project
1518
+ # Or emit and mount in one maintained mount session:
1519
+ kit migrate run my-import --package /home/ada/exports/another-project \
1520
+ --house https://agents.house --subtree /private/library/another-project
1521
+ ```
1522
+
1523
+ Emission refuses an existing output directory. The module reads one JSON line
1524
+ on stdin: `{"contract":"kit-migrator/1","migrator":"my-import","package":"/absolute/output"}`.
1525
+ It must finish writing this tree before exiting successfully:
1526
+
1527
+ ```text
1528
+ project/
1529
+ migrator.json
1530
+ model/note.md # optional independently prepared type definition
1531
+ content/page.md # UTF-8 authored Markdown
1532
+ attachments/image.png # exact downloaded original bytes
1533
+ attachments/notes.txt
1534
+ ```
1535
+
1536
+ The manifest is closed and versioned:
1537
+
1538
+ ```json
1539
+ {
1540
+ "contract": "kit-migrator/1",
1541
+ "category": "migrator",
1542
+ "migrator": "my-import",
1543
+ "attachments": [
1544
+ {
1545
+ "path": "image.png",
1546
+ "source": "https://export.example/image.png",
1547
+ "media_type": "image/png",
1548
+ "download": "downloaded",
1549
+ "referrers": ["page.md"]
1550
+ },
1551
+ {
1552
+ "source": "https://export.example/unavailable",
1553
+ "download": "unavailable",
1554
+ "failure": "not_found",
1555
+ "referrers": ["page.md"]
1556
+ }
1557
+ ]
1558
+ }
1559
+ ```
1560
+
1561
+ `path` is relative to `attachments/`; `referrers` are relative to `content/`.
1562
+ `name` optionally supplies the attachment's file name. Downloaded entries require a
1563
+ local path and forbid `failure`. Unavailable or skipped entries require
1564
+ `failure` and forbid a local path. Every downloaded attachment must be linked
1565
+ from a declared referring document, for example
1566
+ `![Image](../attachments/image.png)` in `content/page.md`. Unavailable ordinary
1567
+ Markdown URLs remain visible; they do not satisfy required typed references.
1568
+ Only Markdown enters the Library. Symlinks, invalid UTF-8, binary content, type
1569
+ aliases under `content/types/`, and generated `_provenance` are refused.
1570
+ `content/MIGRATION.md` is reserved for Kit's report.
1571
+
1572
+ Before creating the text subtree, Kit checks the House-declared MD model version
1573
+ against its exact `@agentshouse/mdmodel` dependency, which rewrites the
1574
+ package's links. House alone validates the resulting Library: a mount it
1575
+ refuses answers with House's own file path, field, rule and version, and no
1576
+ content lands. Definitions in `model/` require their own write
1577
+ grant at `/rooms/<handle>/settings/model/<type>.md` or
1578
+ `/private/settings/model/<type>.md`; a content write grant cannot prepare them.
1579
+ Kit adopts an identical existing definition and refuses a different one.
1580
+ Preparation uses the existing authored batch producer before the empty-subtree
1581
+ mount, so a missing model grant leaves no partial content tree. Independently
1582
+ prepared model definitions survive a later content-mount refusal or unmount.
1583
+
1584
+ The atomic text mount includes a report with pending transfer rows. Kit then
1585
+ uploads each downloaded file once as an attachment to the mount's Room or
1586
+ private tree, independently retrieves and compares the saved bytes, and only
1587
+ after that proof succeeds rewrites every link to it, in every referring
1588
+ document, to its attachment reference, such as `at_1x.q`. The reference is an
1589
+ identity House resolves, not an HTTP download URL. A link's query and fragment
1590
+ are kept after the reference, as in `at_1x.q#page=3`. Failed or unverified
1591
+ uploads remain source links in the authored text; their failure details appear
1592
+ only in the report. Use `kit attachment get --attachment <at_ref> --room
1593
+ <room-ref> --output <file>` (or `--private`) to retrieve the exact bytes. Binary
1594
+ bytes never enter the text replica. Migrators create no Capture, Source
1595
+ instance, or provenance.
1596
+
1597
+ The mounted `MIGRATION.md` separates local downloads from saved, pending,
1598
+ failed, and skipped attachment uploads, with source URLs, referring documents
1599
+ and the attachment reference of each saved upload.
1600
+ `MIGRATION.json` beside the emitted package preserves local pending and final
1601
+ outcomes. A failed upload leaves usable mounted text and returns a nonzero
1602
+ exit status. A failure to publish the final report also returns nonzero and
1603
+ leaves the pending mounted report plus the local outcomes. Re-migration is
1604
+ explicit unmount followed by mount.
1605
+
1606
+ ```sh
1607
+ kit migrate unmount /rooms/work/library/project --house https://agents.house
1608
+ kit migrate unmount /rooms/work/library/project --house https://agents.house \
1609
+ --confirm /rooms/work/library/project
1610
+ ```
1611
+
1612
+ The first command shows the subtree destruction summary and removes nothing.
1613
+ Confirmation must repeat the exact subtree. Kit checks discovered write/delete
1614
+ authority and protected paths for every selected target, then makes House's one
1615
+ unmount call. House rechecks authority and subtree state at commit. Each
1616
+ command requires the ordinary available Kit control lease; an already held lease
1617
+ is refused by the existing Kit rail.
1618
+
1619
+ ### Linux Compose validation
1620
+
1621
+ The test service uses the host Docker daemon, loop device availability and a
1622
+ shared `/tmp` mount because `npm test` includes Kit's real workspace-volume
1623
+ proof. It runs with an init process, because the supervised-path proofs kill a
1624
+ tmux pane whose adapter is then orphaned and has to be reaped rather than left
1625
+ as a zombie. Set `KIT_TEST_UID`, `KIT_TEST_GID`, and `KIT_TEST_DOCKER_GID` for
1626
+ the host when they differ from 1001, 1001, and 112. It starts only test-owned
1627
+ workspaces.
1628
+
1629
+ ```sh
1630
+ docker compose -f test/compose.yaml build kit
1631
+ docker compose -f test/compose.yaml run --rm kit npm test
1632
+ docker compose -f test/compose.yaml run --rm \
1633
+ -e HOUSE_KIT_GOOGLE_OAUTH_CLIENT_ID=kit-client.apps.googleusercontent.com \
1634
+ -e HOUSE_KIT_GOOGLE_OAUTH_CLIENT_SECRET=GOCSPX-kit-installed-app \
1635
+ kit npm run build
1636
+ ```
1637
+
1638
+ `test/pair/run.sh` boots real Core, Auth and PostgreSQL and runs the installed
1639
+ package against them. `HOUSE_CORE_ROOT` names the Core checkout under proof and
1640
+ `HOUSE_AUTH_ROOT` names an Auth checkout; the run exports the exact Auth revision
1641
+ Core's own `scripts/auth-pair-source.mjs` pins into `tmp/auth-pinned` and pairs
1642
+ that revision rather than whatever the checkout's working tree carries. Set
1643
+ `HOUSE_AUTH_REVISION` to name another revision when Core's pin trails the Auth
1644
+ contract that Core revision already requires. Both producer databases are
1645
+ dropped and made again before either migrates, so a run never inherits the
1646
+ schema another Core revision left behind. Every run prints the three revisions
1647
+ it paired and writes them into each evidence document.
1648
+
1649
+ The installed fixture in `test/fixtures/migrator.mjs` uses only local material
1650
+ and is excluded from the published package. Its paired proof runs from Kit:
1651
+
1652
+ ```sh
1653
+ HOUSE_CORE_ROOT=<committed-core-snapshot> HOUSE_AUTH_ROOT=<committed-auth-snapshot> \
1654
+ KIT_PAIR_SPECS=/kit/test/pair/migrator.vitest.ts bash test/pair/run.sh
1655
+ ```
1656
+
1657
+ The pair boots real Core, Auth, and PostgreSQL. It covers Room and private
1658
+ mounts, separately authorized models, House's typed refusal, exact
1659
+ attachment retrieval, failed storage, mounted reports, occupied mounts and the
1660
+ confirmed unmount. As in the other installed-CLI pair tests, the fixture expires
1661
+ the previous control lease before starting the next isolated command. Evidence
1662
+ is written to `tmp/delivery-evidence/migrator-pair.json` with producer revisions
1663
+ and the installed package digest.
1664
+
1665
+ The retained-original consumers have their own paired proofs:
1666
+
1667
+ ```sh
1668
+ HOUSE_CORE_ROOT=<core checkout> HOUSE_AUTH_ROOT=<auth checkout> \
1669
+ KIT_PAIR_SPECS="/kit/test/pair/source-originals.vitest.ts \
1670
+ /kit/test/pair/conversation-originals.vitest.ts \
1671
+ /kit/test/pair/conversation-house-storage.vitest.ts" bash test/pair/run.sh
1672
+ ```
1673
+
1674
+ `source-originals` drives a controlled local Source adapter through one
1675
+ installed Kit: it proves that the connector receives its own authorization,
1676
+ selection and cursor and never a House credential, that an unreachable House
1677
+ leaves the checkpoint where it was and converges on reconnect, that two Room
1678
+ owners hold independently owned retained copies of one delivery while one
1679
+ owner's two Rooms share a Record, that a failed save is truthful and a later
1680
+ byte retry publishes no second Capture and no substitute version, that an
1681
+ unauthorized Room destination stays outstanding while acquisition health stays
1682
+ its own, that an explicit backfill bound still holds in the installed package,
1683
+ and that interrupting the Environment stops the receiver without advancing the
1684
+ checkpoint or being woken again. After the Environment's authority is revoked
1685
+ its next capture is refused.
1686
+
1687
+ `conversation-originals` and `conversation-house-storage` drive the same
1688
+ installed personal-bot gateway and Worker over House storage. Both prove an
1689
+ incoming accepted attachment retained through the shared byte client
1690
+ independently of transport, a failed save and its retry leaving every accepted
1691
+ message identity unchanged, the Run settling and its temporary media cache being
1692
+ disposed, the owner downloading the exact original through House afterwards, and
1693
+ the Environment's next protected act being refused once its authority is gone.
1694
+ A file a Session sends to its owner's conversation through `house
1695
+ upload_attachment` is proven by Core's pair lane. Evidence is written
1696
+ to `tmp/delivery-evidence/source-originals-pair.json`,
1697
+ `conversation-originals-pair.json` and `conversation-house-storage-pair.json`.