@synapsor/runner 0.1.0 → 0.1.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 (33) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +750 -245
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/runner.mjs +1621 -163
  5. package/docs/README.md +85 -47
  6. package/docs/conformance.md +91 -0
  7. package/docs/migrating-to-synapsor-spec.md +191 -0
  8. package/docs/production.md +289 -0
  9. package/docs/release-notes.md +32 -0
  10. package/examples/app-owned-writeback/command-handler.mjs +0 -0
  11. package/examples/claude-desktop-postgres/Makefile +6 -0
  12. package/examples/claude-desktop-postgres/README.md +40 -0
  13. package/examples/cursor-postgres/Makefile +6 -0
  14. package/examples/cursor-postgres/README.md +30 -0
  15. package/examples/mcp-postgres-billing-app-handler/scripts/run-demo.sh +0 -0
  16. package/examples/mysql-refund-agent/Makefile +4 -0
  17. package/examples/mysql-refund-agent/README.md +36 -0
  18. package/examples/openai-agents-http/Makefile +6 -0
  19. package/examples/openai-agents-http/README.md +14 -0
  20. package/examples/openai-agents-stdio/Makefile +6 -0
  21. package/examples/openai-agents-stdio/README.md +14 -0
  22. package/examples/raw-sql-vs-synapsor/Makefile +11 -0
  23. package/examples/raw-sql-vs-synapsor/README.md +41 -0
  24. package/examples/reference-support-billing-app/scripts/run-demo.sh +0 -0
  25. package/examples/support-billing-agent/Makefile +19 -0
  26. package/examples/support-billing-agent/README.md +89 -0
  27. package/examples/support-billing-agent/app/README.md +13 -0
  28. package/examples/support-billing-agent/db/schema.sql +91 -0
  29. package/examples/support-billing-agent/db/seed.sql +43 -0
  30. package/examples/support-billing-agent/docker-compose.yml +13 -0
  31. package/examples/support-billing-agent/scripts/run-demo.sh +15 -0
  32. package/examples/support-billing-agent/synapsor.runner.json +233 -0
  33. package/package.json +27 -10
package/docs/README.md CHANGED
@@ -1,74 +1,112 @@
1
1
  # Synapsor Runner Docs
2
2
 
3
- Start with the README. Use these docs only when you need the next level of
4
- detail.
3
+ Start with the README. Use this index when you need the task-specific next
4
+ step. The order is intentional: run something first, wire your database second,
5
+ then read the concepts once the safety boundary is visible.
5
6
 
6
- ## First Setup
7
+ ## 01 Quickstart
8
+
9
+ - [README](../README.md): wedge, no-DB quick demo, five-line model, and the
10
+ shortest own-database path.
11
+ - [Troubleshooting First Run](troubleshooting-first-run.md): common first-run
12
+ failures, redacted diagnostics, and fixes.
13
+
14
+ ## 02 Why Raw SQL Is Dangerous
15
+
16
+ - [Security Boundary](security-boundary.md): what the model can and cannot see.
17
+ - [MCP Audit](mcp-audit.md): static review for risky database MCP tools such as
18
+ `execute_sql`, broad query tools, model-controlled tenant filters, or
19
+ model-facing approval/commit tools.
20
+
21
+ ## 03 Run The Demo
22
+
23
+ - `examples/support-billing-agent/`: flagship support/billing agent demo with
24
+ `make demo`, expected output, and the raw-SQL-vs-Synapsor contrast.
25
+ - `examples/raw-sql-vs-synapsor/`: no-database fear/fix demo.
26
+ - `examples/reference-support-billing-app/`: shared fixture used by the
27
+ flagship demo and package smoke tests.
28
+
29
+ ## 04 Connect Your DB
7
30
 
8
31
  - [Connect Your Own Database](getting-started-own-database.md): inspect a
9
32
  staging Postgres/MySQL database, generate `synapsor.runner.json`, preview
10
33
  semantic tools, and serve them over MCP.
11
34
  - [Use Your Own Database](use-your-own-database.md): short entry point that
12
35
  links to the canonical own-database guide.
36
+ - [Doctor](doctor.md): redacted setup checks, handler probes, direct SQL
37
+ writeback probes, and receipt-table guidance.
38
+
39
+ ## 05 Generate Capabilities
40
+
41
+ - [Capability Authoring](capability-authoring.md): define read/proposal
42
+ capabilities, model-facing descriptions, result envelopes, trusted context,
43
+ and writeback guards.
44
+ - [Recipes](recipes.md): starter business-capability templates.
45
+ - [JSON Schema](../schemas/synapsor.runner.schema.json): editor validation for
46
+ `synapsor.runner.json`.
47
+
48
+ ## 06 Serve MCP
49
+
13
50
  - [MCP Client Setup](mcp-client-setup.md): connect Claude, Cursor, VS Code, or
14
51
  another stdio MCP client.
52
+ - `examples/claude-desktop-postgres/`: copy-paste Claude Desktop config for the
53
+ Postgres billing fixture.
54
+ - `examples/cursor-postgres/`: copy-paste Cursor config for the Postgres
55
+ billing fixture.
15
56
  - [HTTP MCP](http-mcp.md): run Synapsor Runner as an authenticated HTTP MCP
16
57
  service for app/server agents.
17
58
  - [OpenAI Agents SDK](openai-agents-sdk.md): use Streamable HTTP MCP with
18
59
  OpenAI-safe tool aliases.
19
- - [Capability Authoring](capability-authoring.md): define read/proposal
20
- capabilities, model-facing descriptions, result envelopes, trusted context,
21
- and writeback guards. JSON Schema:
22
- `../schemas/synapsor.runner.schema.json`.
23
- - [Result Envelope v2](result-envelope-v2.md): the generated-config default
24
- `ok`/`summary`/`data`/`proposal`/`error` response shape for MCP tools.
25
- - [Handler Helper](handler-helper.md): TypeScript helper for safe app-owned
26
- rich-write handlers.
27
- - RFC source context:
28
- [001 result envelope](rfcs/001-result-envelope-v2.md),
29
- [002 handler helper](rfcs/002-app-owned-handler-helper.md),
30
- [003 integrator teardown](rfcs/003-integrator-feedback-teardown.md).
31
60
 
32
- ## Safety And Operations
61
+ ## 07 Propose, Approve, Apply
33
62
 
34
- - [Security Boundary](security-boundary.md): what the model can and cannot see.
35
- - [Current Limitations](limitations.md): current alpha scope.
36
- - [Current Scope](current-scope.md): compact alpha scope summary.
37
- - [Cloud Mode](cloud-mode.md): what stays local and what Cloud-linked mode adds.
38
- - [Release Notes](release-notes.md): alpha behavior, breaking changes, and the
39
- stable release policy.
40
- - [Release Policy](release-policy.md): alpha expectations, stable gates,
41
- result envelope migration, and publish verification.
42
- - [Licensing](licensing.md): Apache-2.0 scope, trademark boundary, and what is
43
- not included in this runner repo.
44
- - [Dependency License Inventory](dependency-license-inventory.md): current
45
- dependency license summary for release review.
46
- - [Troubleshooting First Run](troubleshooting-first-run.md): common setup
47
- failures and fixes.
48
- - [Doctor](doctor.md): redacted setup checks, handler probes, direct SQL
49
- writeback probes, and receipt-table guidance.
50
63
  - [Local Mode](local-mode.md): local store, proposals, approval, replay, and
51
64
  writeback flow.
52
- - [Store Lifecycle](store-lifecycle.md): active-store leases, prune safety,
53
- deleted-store behavior, and concurrent server guardrails.
54
-
55
- ## Features
56
-
57
- - [MCP Audit](mcp-audit.md): static risk review for database MCP tools.
58
- - [Recipes](recipes.md): starter business-capability templates.
59
65
  - [Writeback Executors](writeback-executors.md): app-owned writeback handlers
60
66
  for approved proposals.
61
67
  - [App-Owned Executors](app-owned-executors.md): short entry point for rich
62
68
  business transactions handled by your app.
63
- - `synapsor-runner events tail` and `events webhook`: local lifecycle events
64
- such as `proposal_created`, `proposal_approved`, `writeback_applied`, and
65
- `writeback_conflict`.
69
+ - [Handler Helper](handler-helper.md): TypeScript helper for safe app-owned
70
+ rich-write handlers.
66
71
 
67
- Useful examples:
72
+ ## 08 Replay And Audit
68
73
 
69
- - `examples/mcp-postgres-billing-app-handler/`: disposable Postgres app showing
70
- guarded SQL writeback and app-owned account-credit execution side by side.
74
+ - [Result Envelope v2](result-envelope-v2.md): stable
75
+ `ok`/`summary`/`data`/`proposal`/`error` MCP tool results.
76
+ - [Store Lifecycle](store-lifecycle.md): active-store leases, prune safety,
77
+ deleted-store behavior, and concurrent server guardrails.
78
+ - `synapsor-runner activity search`, `evidence`, `query-audit`, `receipts`,
79
+ `events tail`, and `events webhook`: local evidence, audit, receipt, replay,
80
+ and lifecycle inspection.
81
+ - `examples/mysql-refund-agent/`: MySQL order/refund review example using the
82
+ same proposal, approval, guarded writeback, and replay loop.
83
+
84
+ ## 09 App-Owned Handlers
85
+
86
+ - [Writeback Executors](writeback-executors.md): call direction, endpoint
87
+ contract, receipt shape, and the requirement to re-check tenant/scope,
88
+ expected version, idempotency, and allowed action inside your handler.
89
+ - [Handler Helper](handler-helper.md): helper API and examples.
90
+
91
+ ## 10 Concepts
92
+
93
+ - [Current Scope](current-scope.md): compact v0.1 scope summary.
94
+ - [Current Limitations](limitations.md): intentional safety limits.
95
+ - [Production-Candidate Guide](production.md): single-node OSS deployment
96
+ scope, database roles, receipt grants, local ledger backup, restart behavior,
97
+ Docker/systemd shapes, TLS, and release-gate expectations.
98
+ - [Cloud Mode](cloud-mode.md): what stays local and what Cloud-linked mode adds.
99
+ - [Release Notes](release-notes.md): release history and behavior changes.
100
+ - [Release Policy](release-policy.md): stable gates and publish verification.
101
+ - [Licensing](licensing.md): Apache-2.0 scope, trademark boundary, and what is
102
+ not included in this runner repo.
103
+ - [Dependency License Inventory](dependency-license-inventory.md): current
104
+ dependency license summary for release review.
105
+ - RFC source context:
106
+ [001 result envelope](rfcs/001-result-envelope-v2.md),
107
+ [002 handler helper](rfcs/002-app-owned-handler-helper.md),
108
+ [003 integrator teardown](rfcs/003-integrator-feedback-teardown.md).
71
109
 
72
- The public docs intentionally stay small. Historical implementation reports,
73
- release checklists, and internal planning notes are not part of the public
110
+ The public docs intentionally stay task-first. Historical implementation
111
+ reports, release checklists, and internal planning notes are not part of the
74
112
  getting-started path.
@@ -0,0 +1,91 @@
1
+ # Conformance Fixtures
2
+
3
+ Conformance fixtures prove behavior, not just JSON shape.
4
+
5
+ `@synapsor/spec` owns the fixtures under:
6
+
7
+ ```text
8
+ packages/spec/fixtures/conformance/
9
+ ```
10
+
11
+ Each fixture contains:
12
+
13
+ - `contract.json`: canonical `@synapsor/spec` contract;
14
+ - `scenario.json`: trusted context, invocation, and mocked source data;
15
+ - `expected.*.json`: expected evidence, proposal, receipt, replay, redaction,
16
+ or external action result.
17
+
18
+ Current fixture groups:
19
+
20
+ - `read-capability`
21
+ - `proposal-capability`
22
+ - `kept-out-fields`
23
+ - `manual-approval`
24
+
25
+ The fixture set is intentionally small in 0.1. It covers the runner-supported
26
+ semantic surface first: trusted context, scoped reads, evidence handles,
27
+ proposal boundaries, kept-out fields, manual approval, and replay envelopes.
28
+
29
+ ## Runner Usage
30
+
31
+ Runner tests load every conformance `contract.json` and verify that the MCP
32
+ runtime can expose the contract as semantic tools without exposing raw SQL,
33
+ approval, commit, or writeback tools.
34
+
35
+ Run:
36
+
37
+ ```bash
38
+ corepack pnpm --filter @synapsor-runner/mcp-server test
39
+ ```
40
+
41
+ The spec package also validates every conformance contract:
42
+
43
+ ```bash
44
+ corepack pnpm --filter @synapsor/spec test
45
+ ```
46
+
47
+ ## Cloud/C++ Usage
48
+
49
+ The proprietary Cloud/C++ engine uses the same fixture contracts for
50
+ import/export alignment of the 0.1 overlapping subset:
51
+
52
+ 1. load `contract.json`;
53
+ 2. validate the 0.1 core fields and extension policy;
54
+ 3. compile the overlapping subset to internal context/capability/workflow
55
+ models;
56
+ 4. emit normalized `@synapsor/spec` JSON;
57
+ 5. compare unsupported fields and extension handling explicitly.
58
+
59
+ The main Synapsor repo also keeps C++ export fixtures under:
60
+
61
+ ```text
62
+ tests/fixtures/synapsor_contract_exports/
63
+ ```
64
+
65
+ Those exported contracts are validated by `@synapsor/spec` and loaded by
66
+ `@synapsor/runner` through the main repo verifier:
67
+
68
+ ```bash
69
+ SYNAPSOR_RUNNER_REPO=/path/to/synapsor-runner \
70
+ ./scripts/verify_contract_roundtrip.sh
71
+ ```
72
+
73
+ Full runtime parity is not required for every Cloud-only feature in 0.1, but
74
+ unsupported fields must fail clearly or be represented through documented
75
+ `x-cloud-*` extensions.
76
+
77
+ ## Add A Fixture
78
+
79
+ 1. Create a new directory under `packages/spec/fixtures/conformance/<name>/`.
80
+ 2. Add a valid `contract.json`.
81
+ 3. Add a minimal `scenario.json`.
82
+ 4. Add one or more `expected.*.json` files.
83
+ 5. Run:
84
+
85
+ ```bash
86
+ corepack pnpm --filter @synapsor/spec test
87
+ corepack pnpm --filter @synapsor-runner/mcp-server test
88
+ ```
89
+
90
+ Keep fixtures deterministic. Do not include secrets, database URLs, live table
91
+ rows, bearer tokens, or customer data.
@@ -0,0 +1,191 @@
1
+ # Migrating To `@synapsor/spec`
2
+
3
+ `@synapsor/spec` is the canonical Synapsor contract format.
4
+
5
+ Older Runner configs may still embed capabilities directly inside
6
+ `synapsor.runner.json`. That remains supported. New projects should separate
7
+ the portable business contract from local runtime wiring.
8
+
9
+ ## Old Shape
10
+
11
+ ```json
12
+ {
13
+ "version": 1,
14
+ "mode": "review",
15
+ "storage": { "sqlite_path": "./.synapsor/local.db" },
16
+ "sources": {
17
+ "local_postgres": {
18
+ "engine": "postgres",
19
+ "read_url_env": "DATABASE_URL"
20
+ }
21
+ },
22
+ "trusted_context": {
23
+ "provider": "environment",
24
+ "values": {
25
+ "tenant_id_env": "SYNAPSOR_TENANT_ID",
26
+ "principal_env": "SYNAPSOR_PRINCIPAL"
27
+ }
28
+ },
29
+ "capabilities": [
30
+ {
31
+ "name": "billing.inspect_invoice",
32
+ "kind": "read",
33
+ "source": "local_postgres",
34
+ "target": {
35
+ "schema": "public",
36
+ "table": "invoices",
37
+ "primary_key": "id",
38
+ "tenant_key": "tenant_id"
39
+ },
40
+ "args": {
41
+ "invoice_id": { "type": "string", "required": true }
42
+ },
43
+ "lookup": { "id_from_arg": "invoice_id" },
44
+ "visible_columns": ["id", "tenant_id", "status", "late_fee_cents"],
45
+ "evidence": "required",
46
+ "max_rows": 1
47
+ }
48
+ ]
49
+ }
50
+ ```
51
+
52
+ ## New Shape
53
+
54
+ Put context, resources, capabilities, workflows, evidence requirements,
55
+ proposal boundaries, and kept-out fields in `synapsor.contract.json`.
56
+
57
+ ```json
58
+ {
59
+ "spec_version": "0.1",
60
+ "kind": "SynapsorContract",
61
+ "metadata": {
62
+ "name": "billing invoice review",
63
+ "version": "0.1.0"
64
+ },
65
+ "resources": [
66
+ {
67
+ "name": "billing_invoices",
68
+ "engine": "postgres",
69
+ "schema": "public",
70
+ "table": "invoices",
71
+ "primary_key": "id",
72
+ "tenant_key": "tenant_id",
73
+ "conflict_key": "updated_at"
74
+ }
75
+ ],
76
+ "contexts": [
77
+ {
78
+ "name": "local_operator",
79
+ "tenant_binding": "tenant_id",
80
+ "principal_binding": "principal",
81
+ "bindings": [
82
+ { "name": "tenant_id", "source": "environment", "key": "SYNAPSOR_TENANT_ID", "required": true },
83
+ { "name": "principal", "source": "environment", "key": "SYNAPSOR_PRINCIPAL", "required": true }
84
+ ]
85
+ }
86
+ ],
87
+ "capabilities": [
88
+ {
89
+ "name": "billing.inspect_invoice",
90
+ "kind": "read",
91
+ "context": "local_operator",
92
+ "source": "local_postgres",
93
+ "subject": {
94
+ "resource": "billing_invoices"
95
+ },
96
+ "args": {
97
+ "invoice_id": { "type": "string", "required": true, "max_length": 128 }
98
+ },
99
+ "lookup": { "id_from_arg": "invoice_id" },
100
+ "visible_fields": ["id", "tenant_id", "status", "late_fee_cents", "updated_at"],
101
+ "kept_out_fields": ["internal_notes"],
102
+ "evidence": { "required": true, "query_audit": true },
103
+ "max_rows": 1
104
+ }
105
+ ]
106
+ }
107
+ ```
108
+
109
+ Then keep only local wiring in `synapsor.runner.json`.
110
+
111
+ ```json
112
+ {
113
+ "version": 1,
114
+ "mode": "read_only",
115
+ "result_format": 2,
116
+ "storage": {
117
+ "sqlite_path": "./.synapsor/local.db"
118
+ },
119
+ "contracts": ["./synapsor.contract.json"],
120
+ "sources": {
121
+ "local_postgres": {
122
+ "engine": "postgres",
123
+ "read_url_env": "DATABASE_URL",
124
+ "statement_timeout_ms": 3000
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## Validate
131
+
132
+ ```bash
133
+ synapsor-runner contract validate ./synapsor.contract.json
134
+ synapsor-runner contract normalize ./synapsor.contract.json --out ./synapsor.contract.normalized.json
135
+ synapsor-runner tools preview --config ./synapsor.runner.json --store ./.synapsor/local.db
136
+ ```
137
+
138
+ You can also compile from the SQL-like authoring layer:
139
+
140
+ ```bash
141
+ synapsor-runner dsl validate ./contract.synapsor
142
+ synapsor-runner dsl compile ./contract.synapsor --out ./synapsor.contract.json
143
+ ```
144
+
145
+ ## Bundle For Local Runner
146
+
147
+ Cloud/exported or hand-written contracts can become a local Runner bundle:
148
+
149
+ ```bash
150
+ synapsor-runner contract bundle ./synapsor.contract.json --out ./synapsor-runner-bundle
151
+ ```
152
+
153
+ The bundle includes:
154
+
155
+ - `synapsor.contract.json`
156
+ - `synapsor.runner.json`
157
+ - `.env.example`
158
+ - `README.md`
159
+ - `mcp-client-examples/generic-stdio.json`
160
+
161
+ It does not include database passwords, write credentials, bearer tokens,
162
+ customer rows, or table data.
163
+
164
+ ## Common Errors
165
+
166
+ `UNKNOWN_FIELD`
167
+
168
+ The contract has a field outside the 0.1 core schema. Use explicit extension
169
+ fields such as `x-cloud-*`, `x-runner-*`, or `x-experimental-*`.
170
+
171
+ `MODEL_CONTROLLED_TRUST_SCOPE`
172
+
173
+ A capability argument tries to accept trusted scope from the model, such as
174
+ `tenant_id`, `principal`, table names, column names, or `expected_version`.
175
+ Bind those values from trusted context instead.
176
+
177
+ `KEPT_OUT_VISIBLE_CONFLICT`
178
+
179
+ A field appears in both `visible_fields` and `kept_out_fields`. Remove it from
180
+ `visible_fields`. Kept-out fields must not reach evidence, proposals, or replay.
181
+
182
+ `PROPOSAL_CONFLICT_GUARD_REQUIRED`
183
+
184
+ A proposal capability needs a conflict guard, or an explicit weak-guard
185
+ acknowledgement for a known dev-only path.
186
+
187
+ ## Compatibility
188
+
189
+ Embedded Runner capabilities are still supported for existing users. The new
190
+ contract split is the forward path because it lets OSS Runner, Cloud, C++ import
191
+ tests, and the DSL compiler all validate the same canonical shape.