@creatornader/agent-bridge 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +222 -1
  2. package/README.md +312 -12
  3. package/ROADMAP.md +88 -7
  4. package/SECURITY.md +78 -5
  5. package/SKILL.md +108 -1
  6. package/dist/archive.d.ts +2 -2
  7. package/dist/archive.js +2 -2
  8. package/dist/{bridge-service-hX1ZQp4W.d.ts → bridge-service-CNBKdYXh.d.ts} +2 -1
  9. package/dist/{bridge-store-DPVSCwfs.d.ts → bridge-store-ByJ6CaJk.d.ts} +3 -0
  10. package/dist/bridge.d.ts +25 -8
  11. package/dist/bridge.js +19 -9
  12. package/dist/{chunk-MBPZXTJA.js → chunk-7VJI2MXI.js} +285 -42
  13. package/dist/chunk-7VJI2MXI.js.map +1 -0
  14. package/dist/{chunk-4VB44KJU.js → chunk-AWE3DFZV.js} +3 -2
  15. package/dist/chunk-AWE3DFZV.js.map +1 -0
  16. package/dist/{chunk-GADH244D.js → chunk-E4OWHGUE.js} +16 -5
  17. package/dist/chunk-E4OWHGUE.js.map +1 -0
  18. package/dist/{chunk-NCO7RLBM.js → chunk-GTK4KOED.js} +108 -8
  19. package/dist/chunk-GTK4KOED.js.map +1 -0
  20. package/dist/{chunk-SPSMZOCJ.js → chunk-HUHG7XTB.js} +6 -5
  21. package/dist/chunk-HUHG7XTB.js.map +1 -0
  22. package/dist/{chunk-5GMB3A77.js → chunk-IVG4XWWS.js} +26 -14
  23. package/dist/chunk-IVG4XWWS.js.map +1 -0
  24. package/dist/{chunk-WAI2IYIQ.js → chunk-P635FAN4.js} +50 -7
  25. package/dist/chunk-P635FAN4.js.map +1 -0
  26. package/dist/{chunk-45BZGB77.js → chunk-QNXHDOJ5.js} +218 -24
  27. package/dist/chunk-QNXHDOJ5.js.map +1 -0
  28. package/dist/{chunk-UAHMP6GC.js → chunk-QPC6JHA3.js} +10 -7
  29. package/dist/chunk-QPC6JHA3.js.map +1 -0
  30. package/dist/{chunk-Q6PPMXJC.js → chunk-SN7PIVDF.js} +377 -21
  31. package/dist/chunk-SN7PIVDF.js.map +1 -0
  32. package/dist/{chunk-A6W4QALF.js → chunk-TC6A7GMF.js} +2 -2
  33. package/dist/{chunk-2DFNOLMO.js → chunk-XDNT6ZNZ.js} +9 -6
  34. package/dist/chunk-XDNT6ZNZ.js.map +1 -0
  35. package/dist/{chunk-CEXBMOI5.js → chunk-Z6JP6MYD.js} +2 -2
  36. package/dist/cli.js +5867 -438
  37. package/dist/cli.js.map +1 -1
  38. package/dist/client-runtime.d.ts +4 -2
  39. package/dist/client-runtime.js +7 -7
  40. package/dist/contracts/generate.js +1 -1
  41. package/dist/dr.d.ts +9 -2
  42. package/dist/dr.js +6 -4
  43. package/dist/{gateway-CggQ8vTC.d.ts → gateway-CW-61lvs.d.ts} +27 -3
  44. package/dist/gateway-main.js +71 -7
  45. package/dist/gateway-main.js.map +1 -1
  46. package/dist/gateway.d.ts +3 -3
  47. package/dist/gateway.js +3 -3
  48. package/dist/index.js +8 -8
  49. package/dist/{postgres-bridge-store-Bfd3hRId.d.ts → postgres-bridge-store-C9KG9Z69.d.ts} +1 -1
  50. package/dist/postgres-production-preflight.d.ts +32 -0
  51. package/dist/postgres-production-preflight.js +249 -0
  52. package/dist/postgres-production-preflight.js.map +1 -0
  53. package/dist/server.js +8 -8
  54. package/dist/sqlite-edge-store-CdMIOrho.d.ts +148 -0
  55. package/dist/sqlite.d.ts +19 -80
  56. package/dist/sqlite.js +11 -3
  57. package/docs/architecture-v2.md +292 -15
  58. package/docs/decisions/0004-client-lifecycle-and-endpoint-migration.md +204 -0
  59. package/docs/deployment.md +349 -0
  60. package/docs/troubleshooting.md +23 -0
  61. package/llms.txt +69 -1
  62. package/openapi/agent-bridge-v2.openapi.json +1151 -124
  63. package/package.json +10 -2
  64. package/schemas/agent-bridge-v2.capabilities.json +26 -1
  65. package/schemas/agent-bridge-v2.mcp.json +11 -1
  66. package/schemas/agent-bridge-v2.schema.json +167 -0
  67. package/sql/migrations/007_runtime_role.sql +8 -4
  68. package/sql/migrations/013_row_isolation.sql +71 -8
  69. package/sql/migrations/014_owner_control_plane.sql +124 -31
  70. package/sql/migrations/015_portable_archives.sql +143 -41
  71. package/sql/migrations/016_native_dr_fence.sql +102 -35
  72. package/sql/migrations/017_gateway_authority_binding.sql +99 -0
  73. package/sql/migrations/018_endpoint_migration_challenges.sql +1054 -0
  74. package/sql/migrations/019_endpoint_migration_same_successor.sql +348 -0
  75. package/sql/migrations/020_managed_authority_compat.sql +698 -0
  76. package/sql/migrations/021_native_backup_reader.sql +421 -0
  77. package/sql/setup.sql +1 -3
  78. package/dist/chunk-2DFNOLMO.js.map +0 -1
  79. package/dist/chunk-45BZGB77.js.map +0 -1
  80. package/dist/chunk-4VB44KJU.js.map +0 -1
  81. package/dist/chunk-5GMB3A77.js.map +0 -1
  82. package/dist/chunk-GADH244D.js.map +0 -1
  83. package/dist/chunk-MBPZXTJA.js.map +0 -1
  84. package/dist/chunk-NCO7RLBM.js.map +0 -1
  85. package/dist/chunk-Q6PPMXJC.js.map +0 -1
  86. package/dist/chunk-SPSMZOCJ.js.map +0 -1
  87. package/dist/chunk-UAHMP6GC.js.map +0 -1
  88. package/dist/chunk-WAI2IYIQ.js.map +0 -1
  89. /package/dist/{chunk-A6W4QALF.js.map → chunk-TC6A7GMF.js.map} +0 -0
  90. /package/dist/{chunk-CEXBMOI5.js.map → chunk-Z6JP6MYD.js.map} +0 -0
package/README.md CHANGED
@@ -43,6 +43,71 @@ Restart the client, then run `agent-bridge doctor --json` if the MCP server does
43
43
  attach. The [troubleshooting guide](docs/troubleshooting.md) covers executable paths,
44
44
  client configuration, and recovery steps.
45
45
 
46
+ ## Run the gateway with Compose
47
+
48
+ The repository includes a loopback-only Compose stack for development and evaluation.
49
+ It starts PostgreSQL 16, runs the ordered migrations, creates a restricted runtime
50
+ login, and starts the authenticated gateway.
51
+
52
+ ```bash
53
+ mkdir -m 700 .secrets
54
+ node -e "process.stdout.write(require('node:crypto').randomBytes(32).toString('hex'))" > .secrets/postgres_password
55
+ node -e "process.stdout.write(require('node:crypto').randomBytes(32).toString('hex'))" > .secrets/runtime_password
56
+ chmod 600 .secrets/*
57
+ docker compose up --build --wait gateway
58
+ curl --fail http://127.0.0.1:8787/readyz
59
+ ```
60
+
61
+ The checked-in stack publishes the gateway and PostgreSQL only on loopback. It is not
62
+ a production TLS deployment. Read [the deployment guide](docs/deployment.md) before
63
+ exposing a gateway, changing network bindings, upgrading the schema, or relying on the
64
+ named volume for persistent data.
65
+
66
+ The repository also maintains a provider-neutral Fly.io reference at
67
+ [`deploy/fly.toml`](deploy/fly.toml). It deliberately omits an app name and release
68
+ command. Check the local contract before creating or changing any Fly resource:
69
+
70
+ ```bash
71
+ npm run preflight:fly -- --json
72
+ ```
73
+
74
+ Before migrating an existing PostgreSQL database, run the read-only production
75
+ preflight with schema-owner authority:
76
+
77
+ ```bash
78
+ AGENT_BRIDGE_DATABASE_URL="..." npm run preflight:postgres:production -- --json --require-ssl
79
+ ```
80
+
81
+ The command checks the PostgreSQL major, database and role authority, existing
82
+ migration ledger, derived-role collisions, and the legacy `shared_context` import
83
+ shape inside a read-only transaction. `authority.roles` reports migration capability:
84
+ the schema owner may be a true superuser or a managed-provider administrator with
85
+ `CREATEROLE`. `authority.native_dr` reports source-backup capability. The source normally
86
+ connects as the schema owner, which must be a true superuser or hold `BYPASSRLS`, so
87
+ `CREATEROLE` alone can run migrations but cannot create a native backup. A restore target
88
+ uses its superuser session to validate a suspended restored schema-owner shell. The
89
+ migration suite tests both authority forms on PostgreSQL 15 through
90
+ 18. The command does not print the connection URL or apply DDL. `--require-ssl` rejects
91
+ an unencrypted public database connection. Passing the preflight does not replace a
92
+ backup or authorize migration. When a session pooler terminates TLS, the check inspects
93
+ the client socket instead of the pooler's separate database connection.
94
+
95
+ After an operator supplies an existing app, `npm run preflight:fly -- --app <app>
96
+ --json` adds read-only account, app, machine, config, and secret-name observations.
97
+ The command does not deploy, migrate, scale, restart, or print environment-variable
98
+ values. The [Fly production procedure](docs/deployment.md#flyio-reference-hosting)
99
+ keeps database migration and runtime-role bootstrap outside the gateway process.
100
+
101
+ The manual `gateway production proof` workflow tests an existing gateway after its
102
+ deployment gate has passed. GitHub must run it from `main` in the protected
103
+ `agent-bridge-production-proof` environment. Separate sender and receiver jobs prove
104
+ offline outbox replay, exact idempotency, claim, and acknowledgment. The workflow then
105
+ restarts the single Fly machine, requires a new runtime instance ID, and verifies the
106
+ message and settled delivery with a fresh receiver instance and a new SQLite edge file.
107
+ Its versioned receipts contain only identifiers, times, principal and workspace labels,
108
+ the gateway origin, checks, and SHA-256 host evidence. They omit credentials, database
109
+ URLs, message content, and SQLite files.
110
+
46
111
  ## What v2 provides
47
112
 
48
113
  - Immutable messages with UUIDv7 IDs and opaque server cursors.
@@ -67,6 +132,8 @@ The canonical v2 operation registry generates [JSON Schema](schemas/agent-bridge
67
132
 
68
133
  Protocol 2.1 uses a gateway-first rollout. An upgraded gateway continues to serve released 2.0 clients, including headerless requests and their direct or null delivery results. A 2.1 client probes before mutation and proceeds only when complete, consistent response headers select 2.1 and advertise 2.1 support. It rejects mutation against a headerless or 2.0 gateway instead of downgrading. Upgrade the gateway before installing or starting 2.1 clients.
69
134
 
135
+ Two gateway-only HTTP 2.1 operations establish a short-lived endpoint-migration challenge. Initial preflight uses a direct predecessor and successor. After a cutover journal exists, the same active successor credential can issue at the retained source URL and consume at the target URL. Both calls require active transaction-bound authority and use the canonical credential and operation rate buckets. PostgreSQL stores only a domain-separated SHA-256 commitment. A challenge expires within 60 seconds and does not authorize endpoint cutover. Authenticated HTTP 2.1 capabilities include the credential's `grantedScopes`.
136
+
70
137
  The OpenAPI paths describe protocol 2.1. The embedded `x-agent-bridge-protocol-2.0` and `x-agent-bridge-schemas-2.0` vendor extensions contain frozen compatibility schema metadata for released 2.0 clients. They are not a second OpenAPI description. Gateway credentials enforce the operation scopes declared by the canonical registry. Local mode uses process identity, and legacy mode uses its configured key. Provider-neutral artifacts report this difference instead of claiming one authorization model for every backend.
71
138
 
72
139
  ## Architecture
@@ -149,6 +216,8 @@ for its relationship to MCP, A2A, agmsg, brokers, and agent runtimes.
149
216
 
150
217
  - Node.js 22.23.1 or newer.
151
218
  - SQLite 3.51.3 or newer for local and edge storage. The supported Node version includes it.
219
+ - Concurrent local and edge initialization may wait up to 15 seconds for schema work;
220
+ normal database operations retain their configured busy timeout.
152
221
  - PostgreSQL 15, 16, 17, or 18 for gateway mode. New PostgreSQL majors fail the
153
222
  migration prerequisite and live readiness checks until their catalog digest is
154
223
  certified.
@@ -304,7 +373,8 @@ agent-bridge dr restore \
304
373
  PostgreSQL backup takes a repeatable-read snapshot while holding the native DR fence.
305
374
  It stores the `agent_bridge` schema dump plus a canonical inventory of required roles,
306
375
  memberships, and default privileges. The backup excludes transient data from agent
307
- instances, rate-limit buckets, request authority, and archive transaction authority.
376
+ instances, rate-limit buckets, request authority, endpoint-migration challenge rows, and
377
+ archive transaction authority.
308
378
  Restore turns claimed deliveries into immediately retryable work because a database
309
379
  restore cannot preserve a live lease.
310
380
 
@@ -339,10 +409,15 @@ PostgreSQL restore executes SQL from the dump, so use `--accept-source-sql-risk`
339
409
  for a bundle from a source you trust. The target must be a dedicated fresh database
340
410
  with the same database name and PostgreSQL major as the backup. Restore requires a
341
411
  superuser because it recreates object owners, role shells, memberships, and default
342
- privileges. It never enables login on restored external principals. If a restore fails
343
- after mutation begins, Agent Bridge disables new target connections and reports any
344
- residual roles or recovery paths. Inspect and clean those artifacts before retrying.
345
- Never run the source and restored target as active authorities at the same time.
412
+ privileges. It never enables login on restored external principals. Runtime principals
413
+ lose their runtime membership. Active control and archive registrations receive a new
414
+ revocation event, and their principals lose those memberships. Re-enable a principal
415
+ and register it again only after inspecting the restored target. A restore may reuse a
416
+ preexisting role only when it is the source schema owner, the target session user, and
417
+ a true superuser. Every other role collision fails. If a restore fails after mutation
418
+ begins, Agent Bridge disables new target connections and reports any residual roles or
419
+ recovery paths. Inspect and clean those artifacts before retrying. Never run the source
420
+ and restored target as active authorities at the same time.
346
421
 
347
422
  Backup publication never replaces an existing output. Deterministic adjacent staging
348
423
  paths use the backup or request UUID. A retry with the same UUID reports retained
@@ -385,12 +460,200 @@ Claude Code installation uses its native MCP command. Claude Desktop installatio
385
460
  merges the `agent-bridge` server into its JSON config with an atomic write. Restart the
386
461
  client after installation.
387
462
 
463
+ Inspect an existing registration before making Agent Bridge its lifecycle owner:
464
+
465
+ ```bash
466
+ agent-bridge clients inspect codex --identity codex --instance <stable-key> \
467
+ --backend-config <absolute-client-backend-path>
468
+ agent-bridge clients adopt codex --identity codex --instance <stable-key> \
469
+ --backend-config <absolute-client-backend-path>
470
+ agent-bridge clients adopt codex --identity codex --instance <stable-key> \
471
+ --backend-config <absolute-client-backend-path> --apply
472
+ ```
473
+
474
+ `inspect` is local, read-only, and does not return backend values or credentials. It
475
+ classifies the requested registration as `absent`, `unmanaged`, `managed`, or
476
+ `drifted`. `adopt` is plan-only unless `--apply` is explicit, and application writes
477
+ only owner-private, credential-free management metadata after the identity, instance,
478
+ backend path, scope, launch contract, and registration locator match exactly. Adoption
479
+ never rewrites the host registration or backend file. Enrollment-based first-time
480
+ provisioning still refuses registration and backend-file collisions.
481
+ Claude Code inspection accepts the installed `--scope`; Claude Desktop accepts an
482
+ explicit validated `--command` and, when needed, `--config-path`; its default contract
483
+ is absolute Node plus the absolute server entry. Other adapters reject these
484
+ runtime-specific options. Managed metadata binds Desktop to that normalized config
485
+ path and Codex to its active profile config. Claude Code local and project adoption
486
+ bind to the current directory because the native CLI exposes no stronger locator, so
487
+ run those operations from the project context that later lifecycle commands should
488
+ use. Backend files and their immediate parents must satisfy the owner-only no-link
489
+ policy. Registration state is independent of connectivity health, and applied
490
+ adoption re-inspects before reporting success.
491
+
492
+ Once adopted, repair, update, and uninstall locate the registration from owner-private managed
493
+ metadata. The runtime and stable instance select that record. `--identity` must match
494
+ the recorded identity and the immutable request. These commands reject backend-path, scope, and host
495
+ config locator flags, so a caller cannot redirect a managed mutation.
496
+
497
+ ```bash
498
+ agent-bridge clients repair codex --identity codex --instance <stable-key>
499
+ agent-bridge clients repair codex --identity codex --instance <stable-key> --apply
500
+ agent-bridge clients update codex --identity codex --instance <stable-key> \
501
+ --command agent-bridge-mcp --apply
502
+ agent-bridge clients repair codex --identity codex --instance <stable-key> \
503
+ --apply --resume <operation-uuid>
504
+ agent-bridge clients uninstall codex --identity codex --instance <stable-key> --apply
505
+ agent-bridge clients rollback <update-operation-uuid> --identity codex
506
+ agent-bridge clients rollback <update-operation-uuid> --identity codex --apply
507
+ agent-bridge clients resume <operation-uuid>
508
+ agent-bridge clients migrate stage codex --identity codex --instance <stable-key> \\
509
+ --enrollment-file <private-path>
510
+ agent-bridge clients migrate cutover <stage-operation-uuid> --exclusive-edge
511
+ agent-bridge clients migrate cutover <stage-operation-uuid> --exclusive-edge --apply
512
+ agent-bridge clients migrate finalize <cutover-operation-uuid> --exclusive-edge --apply
513
+ ```
514
+
515
+ These commands return a plan by default. A managed registration that is already exact
516
+ and has a private backend file produces no operation. Repair restores the recorded
517
+ launch contract. Update validates and records a new credential-free launch contract
518
+ before it creates a journal. A native `--command` is one executable contract. Bare
519
+ commands cannot contain arguments or URL-like selectors. Absolute paths must resolve
520
+ to executable files. Native adapters remove, verify absence, add, and verify
521
+ the target registration. Claude Desktop replaces only `mcpServers.agent-bridge`,
522
+ preserves unrelated JSON values in memory, publishes through a private operation-scoped
523
+ temporary file, and verifies the new entry. Node cannot provide an OS transaction with
524
+ an uncooperative same-user Desktop writer. The pre-rename identity checks make this an
525
+ advisory race boundary rather than a guarantee.
526
+
527
+ Uninstall is forward-only. It removes the managed registration and verifies its
528
+ absence, deletes the private backend file, then deletes the management metadata. It
529
+ does not repair an unsafe backend before deletion. If the backend is not already
530
+ private, uninstall stops without changing the registration. It does not restore a
531
+ registration, backend, or metadata file after a later step fails. Desktop removes only
532
+ `mcpServers.agent-bridge` and preserves other JSON values. Backend and metadata removal
533
+ check the file and private parent identities before unlink. POSIX then syncs the parent
534
+ directory. Windows verifies the result but records unavailable directory durability.
535
+ Node cannot make pathname-based deletion atomic against an uncooperative same-user
536
+ writer, so that boundary remains advisory.
537
+
538
+ Rollback is explicit and update-only. A committed v4 update retains a bounded
539
+ credential-free inverse contract: its prior managed metadata, prior exact
540
+ registration contract, and digests for the forward metadata and registration state.
541
+ `clients rollback` uses only the source operation UUID and matching identity. It first
542
+ returns a plan. With `--apply`, it creates a separate reverse journal after it proves
543
+ the source is same-host, the source is a committed v4 update, and the current state
544
+ still matches the recorded forward state. Native reversal removes the forward entry,
545
+ adds the prior entry, then writes prior metadata. Claude Desktop replaces only its
546
+ Agent Bridge entry and writes prior metadata last. A reverse journal can resume with
547
+ `clients resume`; a second rollback fails because the forward state is no longer
548
+ present. Repair remains monotonic. Uninstall recovery requires re-enrollment.
549
+
550
+ `--resume` must name an unfinished operation for the same action, runtime, instance,
551
+ and identity. It uses the recorded request instead of new flags. `--recover-lock`
552
+ requires `--apply` and only removes an old same-host lock after the process-death
553
+ proof succeeds. Never delete a lock manually.
554
+
555
+ `clients resume <operation-uuid>` takes only recorded v3, supported v4, v5
556
+ migration-stage, or v6 endpoint-migration operation authority and an optional
557
+ `--recover-lock`. It does not accept a replacement action, runtime,
558
+ instance, identity, command, backend path, scope, or config locator. Use it for every
559
+ generic resume. It is also required when an uninstall has already deleted its final
560
+ metadata file, because the action-specific command has no metadata record left to
561
+ assert.
562
+
563
+ Repair and uninstall create v3 journals. New update and reverse rollback journals use
564
+ v4. Existing v2 journals remain inspectable. A non-terminal v2 journal lacks the
565
+ required identity-bound request, so it is blocked rather than resumed by these commands.
566
+
567
+ Managed-client operations now have a crash-safe local substrate under the owner-only
568
+ `~/.agent-bridge/operations/` directory. `agent-bridge clients operations` lists safe
569
+ operation summaries, and appending an operation UUID inspects one manifest. Output
570
+ never includes artifact contents or backend values. Update requests retain only a
571
+ normalized launch command, arguments, scope, and the fixed Agent Bridge environment
572
+ key names. Each immutable ordered plan names
573
+ registration, backend, and management-metadata targets with non-sensitive locators,
574
+ no-replace before and after artifacts, and expected digests. Registration artifacts
575
+ contain only bounded Agent Bridge fields and the full nonsecret target contract. An
576
+ unknown environment key, malformed field, unsafe argument, or wrong scope stops before
577
+ the journal is created. Begin holds the
578
+ runtime-plus-instance lock and refuses another unfinished operation. Any corrupt or
579
+ blocked journal fences new mutations and resume until an operator resolves it. Resume is
580
+ same-host only. Intent is durable before an
581
+ external write; observed-applied is durable only after the after-state is verified.
582
+ On restart, the exact pending step is retryable only at its before-state, advances only
583
+ at its after-state, and otherwise blocks as ambiguous. Sensitive file access checks and
584
+ pins its immediate directory. Stale-lock recovery separately pins the operation root
585
+ and locks directory for the full recovery sequence. Creation and destructive cleanup
586
+ also keep the operation root and target directories pinned through their writes. The
587
+ full metadata record is rechecked after the lock and before every non-metadata step.
588
+
589
+ On Windows, a held mutation lock can reuse a native ACL result only for the same
590
+ directory path identity. File checks, every new or resumed lock, and each passive
591
+ inspection check the ACL again. POSIX mode checks remain per-access. This cache does
592
+ not change local mode's trust in the current OS user.
593
+
594
+ The journal states are `prepared`, `snapshotted`, `in-progress`, `applied`, `cleaning`,
595
+ and `committed`; inspection separately reports `resumable`,
596
+ `classification-required`, `blocked`, or `complete`. `committed` means every write was
597
+ verified and every artifact was removed. Cleanup records durable intent per artifact,
598
+ pins and verifies it, unlinks it, and syncs the directory on POSIX; Windows explicitly
599
+ records unavailable directory durability. A missing artifact is safe to resume only
600
+ when cleanup intent predated the attempt. Inspection accepts only two exact crash
601
+ residues: that authorized absence, or the verified after artifact for the current
602
+ intent-recorded step. A terminal manifest removes request, step, digest, locator, and
603
+ artifact metadata. A v4 update retains only its explicit credential-free inverse
604
+ contract. A committed v5 stage retains its credential-free stage contract. A committed
605
+ v6 phase retains its credential-free cutover contract. Completed records remain
606
+ readable across hosts. Repair, update, rollback, uninstall, and endpoint migration use
607
+ this journal. Agent Bridge cannot promise physical erasure
608
+ on SSDs or journaled filesystems, so future commands must minimize credential-bearing
609
+ snapshots and rotate credentials when retained copies contained them. Inspection
610
+ changes no registration, backend, metadata, or snapshot file.
611
+
388
612
  The v1 host-adapter manifests are under [`clients/`](clients/). Their compatibility
389
613
  field is named `runtime`, but its value identifies the installation target, not a
390
614
  unique process. OpenClaw and generic MCP manifests declare the required environment
391
615
  variables and command but leave config mutation to the operator because their host
392
616
  config shapes vary.
393
617
 
618
+ The lifecycle ownership boundary and deferred endpoint-migration constraints are
619
+ recorded in [ADR 0004](docs/decisions/0004-client-lifecycle-and-endpoint-migration.md).
620
+
621
+ `clients migrate stage <runtime> --identity <name> --instance <key>
622
+ --enrollment-file <path> --apply` prepares a private gateway successor from a rotation
623
+ enrollment. It does not change the active registration or backend. Staging records
624
+ endpoint digests, credential IDs, the source edge path and scope key, and the
625
+ predecessor grace cutoff without recording tokens or raw gateway URLs.
626
+
627
+ `clients migrate cutover <stage-operation-uuid> --exclusive-edge --apply` consumes a
628
+ committed v5 stage. Before it creates a journal, it verifies both live gateways under
629
+ HTTP 2.1, including the recorded workspace, principal, credential ID, immutable gateway
630
+ authority ID, and the successor credential's `status:read` and `messages:write` grants.
631
+ The endpoints then exchange a direct predecessor-to-successor route challenge. The
632
+ durable journal retains the normalized source gateway URL without a token. Every later
633
+ route challenge uses the successor credential at both URLs, and it drains the source
634
+ edge through the target gateway. The source edge changes to `draining`, receives an
635
+ exclusive lease, and must reach an exact zero-work outbox before any host registration
636
+ changes. The command removes and adds native registrations, or replaces the Claude
637
+ Desktop entry, then changes managed metadata last. It rechecks the authority and lease
638
+ before every host write.
639
+
640
+ Every cutover phase requires `--exclusive-edge`. Agent Bridge can enumerate managed
641
+ registrations that share an edge file, including hardlink aliases, but it cannot see
642
+ unmanaged publishers. The flag records the operator's assertion for that remaining
643
+ cohort. The forward phase also requires an active source edge and an active, empty
644
+ target edge.
645
+
646
+ `clients migrate finalize <cutover-operation-uuid> --exclusive-edge --apply` works
647
+ only after the predecessor grace cutoff and retires the retained source edge. To return
648
+ to an earlier endpoint, first rotate a new owner credential for that endpoint, then run
649
+ an ordinary forward cutover with it as the successor. Use `clients resume
650
+ <operation-uuid>` after a crash. Resume waits for a live drain lease to expire before
651
+ another worker can take it. Dry inspection refuses an edge with live WAL sidecars rather
652
+ than opening it in a mode that could miss uncheckpointed outbox state.
653
+ Moving to an independent database needs a separate owner-mediated process.
654
+ The source backend must name an absolute, normalized edge database file. Relative and
655
+ in-memory edge paths cannot identify one durable outbox and are rejected.
656
+
394
657
  [`SKILL.md`](SKILL.md) provides concise runtime-neutral operating instructions for agents. [`llms.txt`](llms.txt) gives tools and model crawlers a compact map of the package, modes, commands, and identity rules.
395
658
 
396
659
  ## Gateway setup
@@ -572,9 +835,18 @@ followed by capability locks in operator-before-auditor order. Registration and
572
835
  revocation use the same order. A stale session that remains in a revoked role cannot
573
836
  continue operating. The schema owner is the only bootstrap holder of all three control
574
837
  roles and the only role with ordinary execution authority on the registration
575
- functions. PostgreSQL superusers remain inside this trusted database-administration
576
- boundary. Readiness checks the running PostgreSQL major on every call, so upgrading an
577
- already-migrated database to an uncertified major disables the runtime.
838
+ functions. PostgreSQL 16 and newer may represent its effective admin, inherit, and set
839
+ authority with a bootstrap administrator row plus a schema-owner row. A native DR
840
+ restore may recreate the same authority as one combined bootstrap-superuser grant.
841
+ Readiness validates either physical form and its effective authority. True superusers
842
+ and managed-provider schema owners remain inside this trusted database-administration
843
+ boundary. A separate `NOLOGIN` backup-reader role grants only table and sequence read
844
+ access to the schema owner. Runtime, control, archive, and external principals cannot
845
+ inherit it. Native backups require the schema owner to be a true superuser or hold
846
+ `BYPASSRLS`. A target restore superuser can validate the intentionally suspended
847
+ schema-owner shell. `CREATEROLE` alone remains sufficient for migrations. Readiness checks the
848
+ running PostgreSQL major on every call, so upgrading an already-migrated database to an
849
+ uncertified major disables the runtime.
578
850
 
579
851
  Direct credential inserts default to empty scopes rather than full access. Issued
580
852
  identity, scope, label, expiry, and lineage fields cannot be edited directly. Existing
@@ -631,6 +903,7 @@ Normal inbox and pending reads fall back to the local cache when the gateway is
631
903
 
632
904
  ```bash
633
905
  agent-bridge --version
906
+ agent-bridge --help
634
907
  agent-bridge init --provider local
635
908
  agent-bridge doctor
636
909
  agent-bridge status
@@ -644,6 +917,7 @@ agent-bridge get --since 24h --unacked-by codex
644
917
  agent-bridge history --thread-id release-1
645
918
  agent-bridge acknowledge --ids <message-uuid>
646
919
  agent-bridge claim --lease-ms 30000
920
+ agent-bridge claim --message-id <message-uuid> --lease-ms 30000
647
921
  agent-bridge send --target worker --delivery-policy '{"mode":"leased","maxAttempts":3,"retryBaseDelayMs":1000,"retryMaxDelayMs":60000,"retryJitterRatio":0.2}' "work"
648
922
  agent-bridge deliveries --state dead
649
923
  agent-bridge delivery-events --delivery-id <uuid>
@@ -658,12 +932,22 @@ agent-bridge sync
658
932
  agent-bridge watch
659
933
  ```
660
934
 
935
+ `-h` and `--help` print help before Agent Bridge loads backend configuration or
936
+ dispatches a command. They are safe to use after a command name, including `archive`
937
+ and `dr` commands.
938
+
661
939
  `--project` adds an optional immutable label to a message. It never selects a workspace or changes the active identity. Omit it on reads to include every project and unlabeled messages in the credential-bound workspace. Pass it to `get`, `inbox`, `history`, `pending`, or `watch` for an exact label match. Gateway callers may use `--workspace` only as an assertion. The CLI rejects a mismatch before sending a request. Local mode permits a per-command workspace override. The global legacy Supabase schema has no tenant workspace, so legacy mode fixes workspace to `*` and rejects other `--workspace` values.
662
940
 
663
941
  History defaults to mailbox `inbox`: broadcasts plus messages targeted to the configured principal, exactly as prior releases did. `sent` selects messages whose source is that principal, and `all` is the union. `--receipt-state any|unread|read` is caller-relative and valid only with `inbox`. The deprecated `--unacked-by` option remains an identity assertion. The CLI rejects a mismatch before opening storage or contacting a gateway. Server surfaces reject it before querying message storage. Cursors bind workspace, principal, mailbox, and normalized filters. Version 1 cursors are temporarily accepted, while all new cursors are version 2.
664
942
 
665
943
  Publishers set `deliveryPolicy` on the message. Leased policy uses `maxAttempts`, `retryBaseDelayMs`, `retryMaxDelayMs`, `retryJitterRatio`, and optional `notBefore`. Consumers cannot override those values. Consumer-side `maxAttempts` on claim and `retryPolicy` on nack remain validated but ignored for one compatibility release. New code should omit both fields.
666
944
 
945
+ Claims normally select the next due delivery by priority. HTTP 2.1, MCP, and CLI
946
+ callers may supply `messageId` or `--message-id` to atomically select only that due,
947
+ recipient-visible delivery. The filter also scopes lease-expiry and exhaustion
948
+ maintenance performed by that claim. Released HTTP 2.0 request shapes remain frozen
949
+ and reject the field.
950
+
667
951
  The legacy Supabase adapter applies mailbox and receipt rules cooperatively. A holder of the legacy publishable key can bypass the adapter through PostgREST or its receipt RPC. Use the authenticated v2 gateway when the authorization boundary must be enforced.
668
952
 
669
953
  `agent-bridge pending` is a cheap shell gate for agent startup. It exits 0 when unread candidates or due delivery work are visible, 1 only for an authoritative empty result, and 2 when an empty remote state cannot be confirmed. Its JSON result separates unread context from executable delivery work and labels the state as `available`, `empty`, or `unknown`.
@@ -773,6 +1057,8 @@ Each gateway operation checks the scopes in the canonical registry. `capabilitie
773
1057
 
774
1058
  Migration 012 makes PostgreSQL the authority for each production gateway request that passes credential preflight. Node hashes the bearer credential before PostgreSQL receives it. The gateway checks out one connection, opens one explicit transaction, matches the credential ID and hash inside a narrow security-definer function, and derives the workspace, principal, and scopes from current database state. Security accounting and domain work share that transaction and backend. Delivery claim, cancel, and requeue reuse it without nested `BEGIN`. Runtime logins cannot read credential hashes, agent records, workspace records, or request-authority records.
775
1059
 
1060
+ Migration 017 adds one immutable PostgreSQL authority UUID. The released request-authority opener keeps its return shape. Production gateway requests use a bound opener that returns the authority UUID with the database-derived credential. Authenticated gateway `/v2/status` replies include `gatewayAuthorityId` and `credentialId` when transaction-bound request authority is active. Authenticated HTTP 2.1 capabilities return `grantedScopes` for that credential. Migration 018 uses the same bound authority to issue and consume an expiring challenge for a direct credential successor. Migration 019 also permits the same active successor credential at both endpoints after a cutover journal begins. Neither challenge proves a database migration or authorizes endpoint cutover.
1061
+
776
1062
  Migration 013 enables and forces row-level security on messages, receipts, deliveries, delivery events, and presence. Policies read workspace and principal from the transaction-bound request authority. The runtime role cannot set that authority through session variables, inherit a table-owner role, or bypass RLS. Separate no-login roles own domain tables, read request context, and write delivery audit events. Delivery identity and publisher bindings are immutable. A trigger lets recipients perform recipient lifecycle actions and reserves cancel and requeue for publishers.
777
1063
 
778
1064
  The migration records a catalog attestation after it creates the policies, constraints, triggers, and security functions. `/readyz` fails if the current catalog no longer matches that owner-created baseline. Gateway capabilities report `rowIsolation: true` only when request authority is enabled and the migration, catalog attestation, ownership, policy, privilege, and function checks all pass. An owner-approved schema change must update the attestation in its migration.
@@ -813,14 +1099,27 @@ The runtime role owns no schema objects. PostgreSQL keeps roles after a database
813
1099
  ```bash
814
1100
  npm run typecheck
815
1101
  npm test
1102
+ npm run test:postgres:preflight
816
1103
  npm run build
817
1104
  npm pack
818
1105
  ```
819
1106
 
820
- Set `AGENT_BRIDGE_TEST_DATABASE_URL` to run the live PostgreSQL contract and migration
821
- tests. CI runs Node 22 and 24 on Linux, macOS, and Windows. PostgreSQL 15 through 18 each
822
- pack and install the npm tarball, register a least-privilege operator, and exercise
823
- owner provision, inventory, rotation, and revocation. Before applying a Windows DACL,
1107
+ The PostgreSQL preflight starts a fresh Docker container for each supported major,
1108
+ assigns a free loopback port, and runs the live contract. Normal completion removes
1109
+ each container. A later run removes labeled preflight containers older than two hours,
1110
+ which bounds residue after a process or machine stops before cleanup can run. Use
1111
+ `npm run test:postgres:preflight -- --major 16` for one major, or
1112
+ `npm run test:postgres:preflight:full` for the full suite on every major. The command
1113
+ requires a running Docker engine and never reuses a database from an earlier run.
1114
+
1115
+ Set `AGENT_BRIDGE_TEST_DATABASE_URL` when an existing disposable PostgreSQL database is
1116
+ more convenient. CI runs one PostgreSQL 16 contract before starting the 15 through 18
1117
+ jobs. Each version then runs the live contract and matching native DR proof. The package
1118
+ job builds and installs the npm tarball separately.
1119
+
1120
+ CI runs Node 22 and 24 on Linux, macOS, and Windows. One native Windows contract checks
1121
+ private paths, managed uninstall path identity, and recovery before the two Windows jobs
1122
+ start. Before applying a Windows DACL,
824
1123
  private paths must be owned by the current account SID or the active token's default
825
1124
  owner SID. The final owner and sole protected FullControl rule must use the account SID.
826
1125
  Verification-only paths must already satisfy that final policy. Node file identity
@@ -835,6 +1134,7 @@ durability behavior has not yet been proved on a dedicated Windows host.
835
1134
  - [SECURITY.md](SECURITY.md): supported versions, release integrity, private vulnerability reporting, and security boundaries.
836
1135
  - [docs/ecosystem.md](docs/ecosystem.md): product boundary, adjacent systems, and interoperability direction.
837
1136
  - [docs/troubleshooting.md](docs/troubleshooting.md): MCP startup, identity, backend, and client recovery.
1137
+ - [docs/deployment.md](docs/deployment.md): Compose development setup, production constraints, upgrades, backup, and rollback.
838
1138
  - [ADR-0001](docs/decisions/0001-protocol-layers-and-acknowledgment-semantics.md): protocol layers and acknowledgment semantics.
839
1139
  - [ADR-0002](docs/decisions/0002-canonical-operation-contract-registry.md): canonical contracts, generated artifacts, discovery, and version negotiation.
840
1140
  - [ADR-0003](docs/decisions/0003-host-adapters-and-consumer-instance-keys.md): host layers and consumer instance-key semantics.
package/ROADMAP.md CHANGED
@@ -9,7 +9,7 @@ published and the supported clients pass a fresh end-to-end check.
9
9
 
10
10
  ## Status
11
11
 
12
- ### Released by 0.3.0
12
+ ### Released by 0.3.1
13
13
 
14
14
  - Local SQLite and shared PostgreSQL storage behind provider-neutral interfaces.
15
15
  - An authenticated HTTPS gateway and a named legacy Supabase adapter.
@@ -17,6 +17,7 @@ published and the supported clients pass a fresh end-to-end check.
17
17
  presence.
18
18
  - Durable SQLite edge outbox and inbox cache for gateway clients.
19
19
  - CLI, MCP, HTTPS, and Node library access surfaces.
20
+ - Installed-package version reporting through `agent-bridge --version` and `-V`.
20
21
  - Automated host adapters for Codex, Claude Code, and Claude Desktop. The Codex
21
22
  adapter configures the profile shared by the Codex CLI and the Codex surface in the
22
23
  ChatGPT desktop app.
@@ -34,14 +35,97 @@ published and the supported clients pass a fresh end-to-end check.
34
35
  - Portable workspace archives across canonical SQLite and PostgreSQL stores.
35
36
  - Native SQLite and PostgreSQL backup, verification, and restore.
36
37
 
38
+ ### 0.4.0 package contents
39
+
40
+ The published npm version is the authority for whether this package line has shipped.
41
+
42
+ - Read-only lifecycle inspection and explicit, plan-first adoption for the Codex,
43
+ Claude Code, and Claude Desktop adapters, backed by owner-only credential-free
44
+ managed metadata, private backend-path verification, health-neutral exact
45
+ registration comparison, immutable nonsecret host locators, and a re-inspected
46
+ adoption postcondition.
47
+
48
+ - Plan-first managed-client repair, update, and forward-only uninstall for Codex, Claude Code, and Claude
49
+ Desktop. Mutation authority comes only from strict private metadata selected by
50
+ runtime and instance, then bound to the exact managed identity. Applied work uses
51
+ the crash-safe journal, fixed-key credential-free update requests, full metadata and
52
+ bounded registration proofs, exact restart classification, monotonic POSIX backend
53
+ privacy repair, and metadata-last launch updates. Windows accepts only an already
54
+ private backend path. Uninstall removes the registration, backend, and metadata in
55
+ that order without rollback. It refuses a backend that still needs privacy repair.
56
+ Desktop publication and deletion have a documented same-user advisory race.
57
+ New updates use v4 journals and retain a bounded credential-free inverse contract.
58
+ `clients rollback <update-operation-id> --identity <name>` is plan-first and, with
59
+ `--apply`, creates a separate reverse journal after it proves the recorded forward
60
+ state. Generic `clients resume` derives authority from recorded v3, supported v4,
61
+ v5 migration-stage, and v6 endpoint-migration requests. Repair remains monotonic
62
+ and uninstall recovery is re-enrollment.
63
+
64
+ - Gateway-client migration staging, cutover, and finalization for managed
65
+ clients. A v5 stage creates a private successor backend without changing the active
66
+ host registration. A v6 cutover verifies one live gateway authority and a route
67
+ challenge, drains the source SQLite edge under a lease, changes the host registration
68
+ and metadata, and preserves credential-free contracts for restart classification.
69
+ After journal creation, cutover proves both routes with the successor credential and
70
+ drains the source edge through the target gateway. Finalize retires the retained
71
+ source after the predecessor grace cutoff. Return to an earlier endpoint requires a
72
+ new owner rotation and a new forward cutover. Each phase requires a fresh
73
+ `--exclusive-edge` assertion because unmanaged publishers cannot be enumerated.
74
+
75
+ - Gateway-only HTTP 2.1 endpoint-migration challenge operations. An active issuer and
76
+ direct active successor use a 64-character challenge bound to the immutable gateway
77
+ authority UUID. PostgreSQL stores only a domain-separated commitment for at most 60
78
+ seconds. A consumed cross-route challenge proves that both live routes share its
79
+ short-lived database state. It does not authorize endpoint cutover or prove a
80
+ historical database move.
81
+
82
+ - A pinned, non-root gateway image and a Compose development stack with ordered
83
+ migration, restricted runtime-role bootstrap, health checks, private secret files,
84
+ and a persistent PostgreSQL volume.
85
+ - A Linux Compose acceptance test that provisions two temporary principals and proves
86
+ authority binding, delivery settlement, denied runtime access to credential hashes,
87
+ idempotent restart, and PostgreSQL volume persistence.
88
+ - A production deployment guide covering TLS, network exposure, secret separation,
89
+ backups, upgrade order, and schema rollback limits.
90
+
91
+ ### 0.5.0 package contents
92
+
93
+ - Read-only PostgreSQL and Fly production preflights. The database preflight reports
94
+ migration authority separately from native DR authority. The Fly preflight checks
95
+ the maintained deployment contract and existing app state without exposing secret
96
+ values.
97
+ - A maintained Fly.io reference config. The repository contract keeps schema-owner
98
+ and operator authority out of the gateway, but creating an app, provisioning
99
+ PostgreSQL, setting secrets, migrating, and deploying still require an operator
100
+ gate.
101
+ - A manual, approval-protected production proof harness for an existing Fly gateway.
102
+ It separates sender, receiver, machine restart, and fresh-edge verification,
103
+ and publishes versioned receipts that exclude credentials and message content.
104
+ - Managed PostgreSQL schema-owner and native-backup compatibility across PostgreSQL 15
105
+ through 18. Migrations accept either a true superuser or a non-superuser with the
106
+ required role-administration authority. Native DR separately requires the schema
107
+ owner to be a true superuser or hold `BYPASSRLS`. A restore target superuser can
108
+ validate the intentionally suspended restored schema-owner shell. PostgreSQL 16 and
109
+ newer split grants are normalized to one effective membership for readiness and native DR. A
110
+ dedicated read-only role lets the schema owner back up protected tables without
111
+ granting that access to the gateway or control principals. Exact released migration
112
+ checksums remain accepted during upgrade, while unrelated checksum drift still fails
113
+ closed.
114
+ - Optional exact-message delivery claims in HTTP 2.1, MCP, and the CLI. HTTP 2.0 keeps
115
+ the released claim-next contract.
116
+
37
117
  ### Post-release validation and adoption
38
118
 
39
119
  - Move the project's own normal traffic to the authenticated gateway while retaining a
40
120
  tested legacy rollback path.
41
121
  - Prove cross-machine claim, settlement, offline replay, and restart behavior against
42
- the published package and a deployed v2 gateway. The 0.3.0 live release check covered
43
- startup, private mailbox sends, caller-scoped history, receipts, and client restart
44
- through the legacy compatibility backend; it could not prove gateway-only behavior.
122
+ the published package and a deployed v2 gateway. The historical 0.3.0 live release
123
+ check covered startup, private mailbox sends, caller-scoped history, receipts, and
124
+ client restart through the legacy compatibility backend. It did not prove
125
+ gateway-only behavior.
126
+ - Run the manual Fly proof against an operator-owned app and retain its sender,
127
+ receiver, machine-cycle, and verifier receipts. The repository harness is ready,
128
+ but the external proof remains incomplete until an approved workflow run succeeds.
45
129
  - Replace remaining direct legacy table pollers with the v2 cursor protocol.
46
130
  - Confirm the README, npm metadata, GitHub metadata, release notes, and package contents
47
131
  match the released artifact.
@@ -50,9 +134,6 @@ published and the supported clients pass a fresh end-to-end check.
50
134
 
51
135
  ### Installation and operations
52
136
 
53
- - Add client repair, update, uninstall, and registration diagnostics.
54
- - Provide a Compose-based development deployment and a production deployment guide.
55
- - Add endpoint migration tooling that does not strand an existing SQLite outbox.
56
137
  - Publish a maintained client compatibility matrix.
57
138
 
58
139
  ### Storage lifecycle and observability