@synapsor/spec 0.1.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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +125 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +67 -0
  6. package/dist/errors.d.ts +6 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +8 -0
  9. package/dist/index.d.ts +7 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +5 -0
  12. package/dist/load.d.ts +3 -0
  13. package/dist/load.d.ts.map +1 -0
  14. package/dist/load.js +6 -0
  15. package/dist/normalize.d.ts +3 -0
  16. package/dist/normalize.d.ts.map +1 -0
  17. package/dist/normalize.js +16 -0
  18. package/dist/types.d.ts +196 -0
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +1 -0
  21. package/dist/validate.d.ts +4 -0
  22. package/dist/validate.d.ts.map +1 -0
  23. package/dist/validate.js +522 -0
  24. package/dist/version.d.ts +3 -0
  25. package/dist/version.d.ts.map +1 -0
  26. package/dist/version.js +2 -0
  27. package/examples/external-action.contract.json +114 -0
  28. package/examples/guarded-writeback.contract.json +171 -0
  29. package/examples/read-only-analytics.contract.json +94 -0
  30. package/examples/support-refund.contract.json +168 -0
  31. package/fixtures/conformance/kept-out-fields/contract.json +47 -0
  32. package/fixtures/conformance/kept-out-fields/expected.redaction.json +11 -0
  33. package/fixtures/conformance/kept-out-fields/scenario.json +9 -0
  34. package/fixtures/conformance/manual-approval/contract.json +66 -0
  35. package/fixtures/conformance/manual-approval/expected.proposal.json +9 -0
  36. package/fixtures/conformance/manual-approval/scenario.json +5 -0
  37. package/fixtures/conformance/proposal-capability/contract.json +101 -0
  38. package/fixtures/conformance/proposal-capability/expected.proposal.json +25 -0
  39. package/fixtures/conformance/proposal-capability/expected.replay.json +14 -0
  40. package/fixtures/conformance/proposal-capability/scenario.json +21 -0
  41. package/fixtures/conformance/read-capability/contract.json +73 -0
  42. package/fixtures/conformance/read-capability/expected.evidence.json +11 -0
  43. package/fixtures/conformance/read-capability/expected.replay.json +13 -0
  44. package/fixtures/conformance/read-capability/scenario.json +19 -0
  45. package/fixtures/invalid/kept-out-visible.contract.json +46 -0
  46. package/fixtures/invalid/model-controlled-tenant.contract.json +45 -0
  47. package/fixtures/valid/basic-read.contract.json +60 -0
  48. package/package.json +37 -0
  49. package/schemas/capability.schema.json +6 -0
  50. package/schemas/context.schema.json +6 -0
  51. package/schemas/envelope-v2.schema.json +20 -0
  52. package/schemas/evidence.schema.json +6 -0
  53. package/schemas/external-action.schema.json +6 -0
  54. package/schemas/policy.schema.json +6 -0
  55. package/schemas/proposal.schema.json +6 -0
  56. package/schemas/receipt.schema.json +6 -0
  57. package/schemas/replay.schema.json +6 -0
  58. package/schemas/synapsor-contract.schema.json +371 -0
  59. package/schemas/workflow.schema.json +6 -0
@@ -0,0 +1,101 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "proposal capability conformance"
6
+ },
7
+ "resources": [
8
+ {
9
+ "name": "billing_invoices",
10
+ "engine": "postgres",
11
+ "schema": "public",
12
+ "table": "invoices",
13
+ "primary_key": "id",
14
+ "tenant_key": "tenant_id",
15
+ "conflict_key": "updated_at"
16
+ }
17
+ ],
18
+ "contexts": [
19
+ {
20
+ "name": "local_operator",
21
+ "bindings": [
22
+ {
23
+ "name": "tenant_id",
24
+ "source": "environment",
25
+ "key": "SYNAPSOR_TENANT_ID"
26
+ },
27
+ {
28
+ "name": "principal",
29
+ "source": "environment",
30
+ "key": "SYNAPSOR_PRINCIPAL"
31
+ }
32
+ ],
33
+ "tenant_binding": "tenant_id",
34
+ "principal_binding": "principal"
35
+ }
36
+ ],
37
+ "capabilities": [
38
+ {
39
+ "name": "billing.propose_late_fee_waiver",
40
+ "kind": "proposal",
41
+ "context": "local_operator",
42
+ "source": "local_postgres",
43
+ "subject": {
44
+ "resource": "billing_invoices"
45
+ },
46
+ "args": {
47
+ "invoice_id": {
48
+ "type": "string",
49
+ "required": true
50
+ },
51
+ "waiver_reason": {
52
+ "type": "string",
53
+ "required": true
54
+ }
55
+ },
56
+ "lookup": {
57
+ "id_from_arg": "invoice_id"
58
+ },
59
+ "visible_fields": [
60
+ "id",
61
+ "tenant_id",
62
+ "late_fee_cents",
63
+ "waiver_reason",
64
+ "updated_at"
65
+ ],
66
+ "kept_out_fields": [
67
+ "card_token"
68
+ ],
69
+ "evidence": {
70
+ "required": true,
71
+ "query_audit": true
72
+ },
73
+ "max_rows": 1,
74
+ "proposal": {
75
+ "action": "billing.waive_late_fee",
76
+ "allowed_fields": [
77
+ "late_fee_cents",
78
+ "waiver_reason"
79
+ ],
80
+ "patch": {
81
+ "late_fee_cents": {
82
+ "fixed": 0
83
+ },
84
+ "waiver_reason": {
85
+ "from_arg": "waiver_reason"
86
+ }
87
+ },
88
+ "conflict_guard": {
89
+ "column": "updated_at"
90
+ },
91
+ "approval": {
92
+ "mode": "human",
93
+ "required_role": "billing_lead"
94
+ },
95
+ "writeback": {
96
+ "mode": "direct_sql"
97
+ }
98
+ }
99
+ }
100
+ ]
101
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "id": "wrp_INV_3001_late_fee_waiver",
3
+ "capability": "billing.propose_late_fee_waiver",
4
+ "subject": {
5
+ "type": "invoice",
6
+ "id": "INV-3001",
7
+ "tenant_id": "acme"
8
+ },
9
+ "status": "pending",
10
+ "diff": {
11
+ "before": {
12
+ "late_fee_cents": 5500,
13
+ "waiver_reason": null
14
+ },
15
+ "patch": {
16
+ "late_fee_cents": 0,
17
+ "waiver_reason": "duplicate billing issue"
18
+ },
19
+ "after": {
20
+ "late_fee_cents": 0,
21
+ "waiver_reason": "duplicate billing issue"
22
+ }
23
+ },
24
+ "evidence_handle": "ev_prop_INV_3001"
25
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "rpl_prop_INV_3001",
3
+ "proposal_id": "wrp_INV_3001_late_fee_waiver",
4
+ "events": [
5
+ {
6
+ "type": "capability_invoked",
7
+ "capability": "billing.propose_late_fee_waiver"
8
+ },
9
+ {
10
+ "type": "proposal_created",
11
+ "proposal_id": "wrp_INV_3001_late_fee_waiver"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "trusted_context": {
3
+ "tenant_id": "acme",
4
+ "principal": "dev_test_user"
5
+ },
6
+ "invoke": {
7
+ "capability": "billing.propose_late_fee_waiver",
8
+ "args": {
9
+ "invoice_id": "INV-3001",
10
+ "waiver_reason": "duplicate billing issue"
11
+ }
12
+ },
13
+ "source_row": {
14
+ "id": "INV-3001",
15
+ "tenant_id": "acme",
16
+ "late_fee_cents": 5500,
17
+ "waiver_reason": null,
18
+ "updated_at": "2026-06-20T14:31:08Z",
19
+ "card_token": "tok_should_not_leak"
20
+ }
21
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "read capability conformance"
6
+ },
7
+ "resources": [
8
+ {
9
+ "name": "billing_invoices",
10
+ "engine": "postgres",
11
+ "schema": "public",
12
+ "table": "invoices",
13
+ "primary_key": "id",
14
+ "tenant_key": "tenant_id",
15
+ "conflict_key": "updated_at"
16
+ }
17
+ ],
18
+ "contexts": [
19
+ {
20
+ "name": "local_operator",
21
+ "bindings": [
22
+ {
23
+ "name": "tenant_id",
24
+ "source": "environment",
25
+ "key": "SYNAPSOR_TENANT_ID",
26
+ "required": true
27
+ },
28
+ {
29
+ "name": "principal",
30
+ "source": "environment",
31
+ "key": "SYNAPSOR_PRINCIPAL",
32
+ "required": true
33
+ }
34
+ ],
35
+ "tenant_binding": "tenant_id",
36
+ "principal_binding": "principal"
37
+ }
38
+ ],
39
+ "capabilities": [
40
+ {
41
+ "name": "billing.inspect_invoice",
42
+ "kind": "read",
43
+ "context": "local_operator",
44
+ "source": "local_postgres",
45
+ "subject": {
46
+ "resource": "billing_invoices"
47
+ },
48
+ "args": {
49
+ "invoice_id": {
50
+ "type": "string",
51
+ "required": true
52
+ }
53
+ },
54
+ "lookup": {
55
+ "id_from_arg": "invoice_id"
56
+ },
57
+ "visible_fields": [
58
+ "id",
59
+ "tenant_id",
60
+ "late_fee_cents",
61
+ "updated_at"
62
+ ],
63
+ "kept_out_fields": [
64
+ "card_token"
65
+ ],
66
+ "evidence": {
67
+ "required": true,
68
+ "query_audit": true
69
+ },
70
+ "max_rows": 1
71
+ }
72
+ ]
73
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "handle": "ev_read_INV_3001",
3
+ "capability": "billing.inspect_invoice",
4
+ "query_fingerprint": "sha256:read-capability-fixture",
5
+ "items": [
6
+ {
7
+ "field": "late_fee_cents",
8
+ "value": 5500
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "rpl_read_INV_3001",
3
+ "events": [
4
+ {
5
+ "type": "capability_invoked",
6
+ "capability": "billing.inspect_invoice"
7
+ },
8
+ {
9
+ "type": "evidence_created",
10
+ "handle": "ev_read_INV_3001"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "trusted_context": {
3
+ "tenant_id": "acme",
4
+ "principal": "dev_test_user"
5
+ },
6
+ "invoke": {
7
+ "capability": "billing.inspect_invoice",
8
+ "args": {
9
+ "invoice_id": "INV-3001"
10
+ }
11
+ },
12
+ "source_row": {
13
+ "id": "INV-3001",
14
+ "tenant_id": "acme",
15
+ "late_fee_cents": 5500,
16
+ "updated_at": "2026-06-20T14:31:08Z",
17
+ "card_token": "tok_should_not_leak"
18
+ }
19
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "contexts": [
5
+ {
6
+ "name": "local_operator",
7
+ "bindings": [
8
+ {
9
+ "name": "tenant_id",
10
+ "source": "environment",
11
+ "key": "SYNAPSOR_TENANT_ID"
12
+ }
13
+ ],
14
+ "tenant_binding": "tenant_id"
15
+ }
16
+ ],
17
+ "capabilities": [
18
+ {
19
+ "name": "billing.inspect_invoice",
20
+ "kind": "read",
21
+ "context": "local_operator",
22
+ "subject": {
23
+ "schema": "public",
24
+ "table": "invoices",
25
+ "primary_key": "id",
26
+ "tenant_key": "tenant_id"
27
+ },
28
+ "args": {
29
+ "invoice_id": {
30
+ "type": "string"
31
+ }
32
+ },
33
+ "lookup": {
34
+ "id_from_arg": "invoice_id"
35
+ },
36
+ "visible_fields": [
37
+ "id",
38
+ "tenant_id",
39
+ "card_token"
40
+ ],
41
+ "kept_out_fields": [
42
+ "card_token"
43
+ ]
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "contexts": [
5
+ {
6
+ "name": "local_operator",
7
+ "bindings": [
8
+ {
9
+ "name": "tenant_id",
10
+ "source": "environment",
11
+ "key": "SYNAPSOR_TENANT_ID"
12
+ }
13
+ ],
14
+ "tenant_binding": "tenant_id"
15
+ }
16
+ ],
17
+ "capabilities": [
18
+ {
19
+ "name": "billing.inspect_invoice",
20
+ "kind": "read",
21
+ "context": "local_operator",
22
+ "subject": {
23
+ "schema": "public",
24
+ "table": "invoices",
25
+ "primary_key": "id",
26
+ "tenant_key": "tenant_id"
27
+ },
28
+ "args": {
29
+ "tenant_id": {
30
+ "type": "string"
31
+ },
32
+ "invoice_id": {
33
+ "type": "string"
34
+ }
35
+ },
36
+ "lookup": {
37
+ "id_from_arg": "invoice_id"
38
+ },
39
+ "visible_fields": [
40
+ "id",
41
+ "tenant_id"
42
+ ]
43
+ }
44
+ ]
45
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "contexts": [
5
+ {
6
+ "name": "local_operator",
7
+ "bindings": [
8
+ {
9
+ "name": "tenant_id",
10
+ "source": "environment",
11
+ "key": "SYNAPSOR_TENANT_ID"
12
+ },
13
+ {
14
+ "name": "principal",
15
+ "source": "environment",
16
+ "key": "SYNAPSOR_PRINCIPAL"
17
+ }
18
+ ],
19
+ "tenant_binding": "tenant_id",
20
+ "principal_binding": "principal"
21
+ }
22
+ ],
23
+ "capabilities": [
24
+ {
25
+ "name": "billing.inspect_invoice",
26
+ "kind": "read",
27
+ "context": "local_operator",
28
+ "subject": {
29
+ "schema": "public",
30
+ "table": "invoices",
31
+ "primary_key": "id",
32
+ "tenant_key": "tenant_id",
33
+ "conflict_key": "updated_at"
34
+ },
35
+ "args": {
36
+ "invoice_id": {
37
+ "type": "string",
38
+ "required": true
39
+ }
40
+ },
41
+ "lookup": {
42
+ "id_from_arg": "invoice_id"
43
+ },
44
+ "visible_fields": [
45
+ "id",
46
+ "tenant_id",
47
+ "late_fee_cents",
48
+ "updated_at"
49
+ ],
50
+ "kept_out_fields": [
51
+ "card_token"
52
+ ],
53
+ "evidence": {
54
+ "required": true,
55
+ "query_audit": true
56
+ },
57
+ "max_rows": 1
58
+ }
59
+ ]
60
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@synapsor/spec",
3
+ "version": "0.1.0",
4
+ "description": "Canonical Synapsor contract schemas, types, validation, and conformance fixtures.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "bin": {
10
+ "synapsor-spec": "dist/cli.js"
11
+ },
12
+ "files": [
13
+ "dist/**",
14
+ "schemas/**",
15
+ "examples/**",
16
+ "fixtures/**",
17
+ "README.md",
18
+ "package.json"
19
+ ],
20
+ "keywords": [
21
+ "synapsor",
22
+ "ai-agents",
23
+ "mcp",
24
+ "database-safety",
25
+ "contracts"
26
+ ],
27
+ "engines": {
28
+ "node": ">=22.5.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc -b",
35
+ "test": "vitest run"
36
+ }
37
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/capability.schema.json",
4
+ "title": "Synapsor Capability",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/capability"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/context.schema.json",
4
+ "title": "Synapsor Agent Context",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/context"
6
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/envelope-v2.schema.json",
4
+ "title": "Synapsor Result Envelope V2",
5
+ "type": "object",
6
+ "required": ["ok", "summary", "action", "kind", "source_database_changed", "_meta"],
7
+ "additionalProperties": true,
8
+ "properties": {
9
+ "ok": { "type": "boolean" },
10
+ "summary": { "type": "string" },
11
+ "action": { "type": "string" },
12
+ "kind": { "enum": ["read", "proposal", "external_action", "answer_with_evidence"] },
13
+ "data": { "type": ["object", "null"] },
14
+ "proposal": { "type": ["object", "null"] },
15
+ "error": { "type": ["object", "null"] },
16
+ "evidence": { "type": ["object", "null"] },
17
+ "source_database_changed": { "type": "boolean" },
18
+ "_meta": { "type": "object" }
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/evidence.schema.json",
4
+ "title": "Synapsor Evidence Record",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/evidenceRecord"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/external-action.schema.json",
4
+ "title": "Synapsor External Action",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/externalAction"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/policy.schema.json",
4
+ "title": "Synapsor Policy",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/policy"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/proposal.schema.json",
4
+ "title": "Synapsor Proposal Record",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/proposalRecord"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/receipt.schema.json",
4
+ "title": "Synapsor Receipt",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/receipt"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/replay.schema.json",
4
+ "title": "Synapsor Replay Record",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/replay"
6
+ }