kontra-sdk 0.1.0__tar.gz

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 (88) hide show
  1. kontra_sdk-0.1.0/.gitignore +16 -0
  2. kontra_sdk-0.1.0/LICENSE +202 -0
  3. kontra_sdk-0.1.0/PKG-INFO +258 -0
  4. kontra_sdk-0.1.0/README.md +214 -0
  5. kontra_sdk-0.1.0/hatch_build.py +27 -0
  6. kontra_sdk-0.1.0/kontra/__init__.py +8 -0
  7. kontra_sdk-0.1.0/kontra/_control.py +1812 -0
  8. kontra_sdk-0.1.0/kontra/_dev/compose.yaml +386 -0
  9. kontra_sdk-0.1.0/kontra/_runtime.py +116 -0
  10. kontra_sdk-0.1.0/kontra/_spec/README.md +99 -0
  11. kontra_sdk-0.1.0/kontra/_spec/kontra-types.v1.json +80 -0
  12. kontra_sdk-0.1.0/kontra/_spec/x-kontra.v1.json +98 -0
  13. kontra_sdk-0.1.0/kontra/artifacts.py +451 -0
  14. kontra_sdk-0.1.0/kontra/auth.py +841 -0
  15. kontra_sdk-0.1.0/kontra/cli/__init__.py +104 -0
  16. kontra_sdk-0.1.0/kontra/cli/__main__.py +6 -0
  17. kontra_sdk-0.1.0/kontra/cli/_account.py +197 -0
  18. kontra_sdk-0.1.0/kontra/cli/_buyer.py +360 -0
  19. kontra_sdk-0.1.0/kontra/cli/_common.py +256 -0
  20. kontra_sdk-0.1.0/kontra/cli/_dev.py +453 -0
  21. kontra_sdk-0.1.0/kontra/cli/_keys.py +122 -0
  22. kontra_sdk-0.1.0/kontra/cli/_nexgen.py +264 -0
  23. kontra_sdk-0.1.0/kontra/cli/_project.py +109 -0
  24. kontra_sdk-0.1.0/kontra/cli/_pull.py +203 -0
  25. kontra_sdk-0.1.0/kontra/cli/_scaffold.py +74 -0
  26. kontra_sdk-0.1.0/kontra/cli/_seller.py +211 -0
  27. kontra_sdk-0.1.0/kontra/codec/__init__.py +638 -0
  28. kontra_sdk-0.1.0/kontra/codec/age.py +586 -0
  29. kontra_sdk-0.1.0/kontra/contract/__init__.py +38 -0
  30. kontra_sdk-0.1.0/kontra/contract/canonical.py +119 -0
  31. kontra_sdk-0.1.0/kontra/contract/card.py +96 -0
  32. kontra_sdk-0.1.0/kontra/contract/derive.py +399 -0
  33. kontra_sdk-0.1.0/kontra/contract/errors.py +76 -0
  34. kontra_sdk-0.1.0/kontra/contract/facts.py +168 -0
  35. kontra_sdk-0.1.0/kontra/contract/formats.py +227 -0
  36. kontra_sdk-0.1.0/kontra/contract/names.py +301 -0
  37. kontra_sdk-0.1.0/kontra/contract/offering.py +344 -0
  38. kontra_sdk-0.1.0/kontra/contract/patterns.py +638 -0
  39. kontra_sdk-0.1.0/kontra/contract/quote.py +268 -0
  40. kontra_sdk-0.1.0/kontra/contract/spec.py +84 -0
  41. kontra_sdk-0.1.0/kontra/contract/units.py +109 -0
  42. kontra_sdk-0.1.0/kontra/contract/validate.py +834 -0
  43. kontra_sdk-0.1.0/kontra/contract/validator.py +97 -0
  44. kontra_sdk-0.1.0/kontra/contract/yaml_io.py +221 -0
  45. kontra_sdk-0.1.0/kontra/escrow.py +486 -0
  46. kontra_sdk-0.1.0/kontra/gate_client/__init__.py +655 -0
  47. kontra_sdk-0.1.0/kontra/gate_client/models.py +906 -0
  48. kontra_sdk-0.1.0/kontra/gate_client/routes.py +176 -0
  49. kontra_sdk-0.1.0/kontra/hire/__init__.py +87 -0
  50. kontra_sdk-0.1.0/kontra/hire/_client.py +1429 -0
  51. kontra_sdk-0.1.0/kontra/hire/_errors.py +221 -0
  52. kontra_sdk-0.1.0/kontra/hire/_record.py +263 -0
  53. kontra_sdk-0.1.0/kontra/hire/_service.py +361 -0
  54. kontra_sdk-0.1.0/kontra/hire/_worker.py +218 -0
  55. kontra_sdk-0.1.0/kontra/ledger.py +304 -0
  56. kontra_sdk-0.1.0/kontra/mcp/__init__.py +26 -0
  57. kontra_sdk-0.1.0/kontra/mcp/__main__.py +6 -0
  58. kontra_sdk-0.1.0/kontra/mcp/_errors.py +204 -0
  59. kontra_sdk-0.1.0/kontra/mcp/_models.py +204 -0
  60. kontra_sdk-0.1.0/kontra/mcp/_server.py +939 -0
  61. kontra_sdk-0.1.0/kontra/profile.py +325 -0
  62. kontra_sdk-0.1.0/kontra/py.typed +0 -0
  63. kontra_sdk-0.1.0/kontra/serve/__init__.py +45 -0
  64. kontra_sdk-0.1.0/kontra/serve/handler.py +461 -0
  65. kontra_sdk-0.1.0/kontra/serve/hold.py +241 -0
  66. kontra_sdk-0.1.0/kontra/serve/interceptors.py +207 -0
  67. kontra_sdk-0.1.0/kontra/serve/jobs.py +163 -0
  68. kontra_sdk-0.1.0/kontra/serve/offering.py +263 -0
  69. kontra_sdk-0.1.0/kontra/serve/progress.py +355 -0
  70. kontra_sdk-0.1.0/kontra/serve/worker.py +673 -0
  71. kontra_sdk-0.1.0/kontra/templates/offering/README.md.tmpl +41 -0
  72. kontra_sdk-0.1.0/kontra/templates/offering/activities.py.tmpl +27 -0
  73. kontra_sdk-0.1.0/kontra/templates/offering/input.json.tmpl +1 -0
  74. kontra_sdk-0.1.0/kontra/templates/offering/models.py.tmpl +24 -0
  75. kontra_sdk-0.1.0/kontra/templates/offering/offering.yaml.tmpl +15 -0
  76. kontra_sdk-0.1.0/kontra/templates/offering/pyproject.toml.tmpl +7 -0
  77. kontra_sdk-0.1.0/kontra/templates/offering/quote.py.tmpl +18 -0
  78. kontra_sdk-0.1.0/kontra/templates/offering/tests/test_offering.py.tmpl +118 -0
  79. kontra_sdk-0.1.0/kontra/templates/offering/worker.py.tmpl +22 -0
  80. kontra_sdk-0.1.0/kontra/templates/offering/workflows.py.tmpl +25 -0
  81. kontra_sdk-0.1.0/kontra/testing/__init__.py +75 -0
  82. kontra_sdk-0.1.0/kontra/testing/devserver.py +200 -0
  83. kontra_sdk-0.1.0/kontra/testing/fake_gate.py +3353 -0
  84. kontra_sdk-0.1.0/kontra/testing/ledger.py +462 -0
  85. kontra_sdk-0.1.0/kontra/testing/ledger_contract.py +1869 -0
  86. kontra_sdk-0.1.0/kontra/testing/marketplace.py +272 -0
  87. kontra_sdk-0.1.0/kontra/types.py +94 -0
  88. kontra_sdk-0.1.0/pyproject.toml +136 -0
@@ -0,0 +1,16 @@
1
+ .venv
2
+ __pycache__/
3
+ *.pyc
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .pyright/
10
+ .kontra/
11
+ .env
12
+ *.age
13
+ examples/*/gen/
14
+ node_modules/
15
+ temporal/authorizer/bin/
16
+ .hypothesis/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.5
2
+ Name: kontra-sdk
3
+ Version: 0.1.0
4
+ Summary: Sell and hire durable, quoted jobs: plain Temporal workers behind Nexus, with escrow and end-to-end encryption.
5
+ Project-URL: Homepage, https://kontra.run
6
+ Project-URL: Source, https://github.com/medmahmoudi26/kontra-sdk
7
+ Project-URL: Issues, https://github.com/medmahmoudi26/kontra-sdk/issues
8
+ Author: Mohamed Mahmoudi
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agents,escrow,marketplace,mcp,nexus,temporal,workflows
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: System :: Distributed Computing
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: click<9,>=8.1
28
+ Requires-Dist: google-re2<2,>=1.1
29
+ Requires-Dist: httpx<1,>=0.27
30
+ Requires-Dist: jsonschema<5,>=4.23
31
+ Requires-Dist: pydantic<3,>=2.9
32
+ Requires-Dist: pyjwt[crypto]<3,>=2.9
33
+ Requires-Dist: pyrage<2,>=1.2
34
+ Requires-Dist: pyyaml>=6
35
+ Requires-Dist: rfc8785<0.2,>=0.1.4
36
+ Requires-Dist: temporalio<1.35,>=1.34
37
+ Provides-Extra: mcp
38
+ Requires-Dist: mcp<3,>=2.3; extra == 'mcp'
39
+ Provides-Extra: testing
40
+ Requires-Dist: fastapi>=0.115; extra == 'testing'
41
+ Requires-Dist: hypothesis>=6.100; extra == 'testing'
42
+ Requires-Dist: uvicorn>=0.30; extra == 'testing'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # Kontra
46
+
47
+ **A marketplace of durable, quoted jobs.** A seller writes a plain [Temporal](https://temporal.io)
48
+ workflow, declares an offering in one YAML file and a `quote` function, and runs the worker on
49
+ their own hardware. A buyer hires it from a script, from inside their own Temporal workflow, or
50
+ from an AI agent over MCP. Calls travel through [Nexus](https://docs.temporal.io/nexus); Kontra
51
+ provides the identity, the catalog, escrow and the Temporal frontend, and nothing else. Payloads
52
+ are end-to-end encrypted between buyer and seller, so Kontra stores ciphertext and hashes, never
53
+ your inputs or results, and money moves only on facts Kontra can observe without reading a
54
+ payload.
55
+
56
+ This repository is the public half: the `kontra` Python package (SDK, CLI, MCP server, test
57
+ fakes), the Temporal Authorizer that every party's worker is subject to, the examples, and the
58
+ `kontra dev` stack. The gate (catalog, escrow, auth) is a separate, private service.
59
+
60
+ > Status: alpha (`0.1.0`). Python 3.11+.
61
+
62
+ ## Quickstart
63
+
64
+ ```sh
65
+ pip install kontra-sdk
66
+ kontra login --email you@example.com # a sign-in link by mail; the page asks for the code
67
+ # this command prints (sign-ups are by invitation)
68
+ kontra balance # you are in; `kontra quote` and `kontra hire` next
69
+ ```
70
+
71
+ `kontra login` talks to `https://api.kontra.run` unless `--gate` or `KONTRA_GATE` says
72
+ otherwise, and writes your profile and your encryption key to `~/.kontra`. Plain
73
+ `kontra login` approves the code in your browser instead, on a gate whose page offers a way
74
+ to (GitHub, or `kontra dev`).
75
+
76
+ **Programs use an API key**, not your login: a key hires, reads and runs `kontra serve`, and
77
+ can never publish, change your encryption key or make other keys.
78
+
79
+ ```sh
80
+ kontra keys create --label ci # prints the key once; the gate keeps only its hash
81
+ export KONTRA_API_KEY=kontra_sk_... # Kontra(), kontra serve and kontra mcp pick it up
82
+ kontra keys list
83
+ kontra keys revoke key_0123456789abcdef
84
+ ```
85
+
86
+ A program also needs your key file (`~/.kontra/key`) to decrypt what it buys: copy it to the
87
+ machine, or point `KONTRA_HOME` at a directory holding it. Nothing else is read or written.
88
+
89
+ ## Install
90
+
91
+ ```sh
92
+ pip install kontra-sdk # the SDK and the `kontra` command
93
+ pip install "kontra-sdk[mcp]" # + `kontra mcp`, for agents
94
+ pip install "kontra-sdk[testing]" # + the in-process marketplace for your tests
95
+ ```
96
+
97
+ > **The distribution is `kontra-sdk`.** `kontra` on PyPI is an unrelated project. Never write a
98
+ > bare `kontra` dependency in a requirements file or a `pyproject.toml`: it installs someone
99
+ > else's code. The import name is `kontra`.
100
+
101
+ `kontra dev` also needs Docker with the compose plugin. It runs the images
102
+ `ghcr.io/medmahmoudi26/kontra-temporal:dev` and `ghcr.io/medmahmoudi26/kontra-gate:dev`;
103
+ `KONTRA_TEMPORAL_IMAGE` and `KONTRA_GATE_IMAGE` name others (in a checkout, `make temporal`
104
+ builds `kontra-temporal:dev` from [`temporal/authorizer`](temporal/authorizer)). The published
105
+ Temporal image is `linux/amd64` only: on an arm64 machine Docker has to emulate it, or build a
106
+ native one with `make temporal`.
107
+
108
+ ## Sell a job
109
+
110
+ ```sh
111
+ kontra dev # a local Kontra in Docker (Temporal, gate, Postgres, bucket);
112
+ # logs you in as a dev party with play money
113
+ kontra init wordcount # ./wordcount: offering.yaml, models, workflow, quote, worker, a test
114
+ cd wordcount
115
+ pytest # the whole lifecycle -- quote, hire, deliver, accept, refund --
116
+ # in a unit test, no containers (pip install "kontra-sdk[testing]" pytest)
117
+ kontra serve # run the worker; on a dev profile it publishes the offering first
118
+ ```
119
+
120
+ `kontra init` writes the project layout every offering has:
121
+
122
+ | File | Owns |
123
+ |---|---|
124
+ | `offering.yaml` | name, version, limits, display text. Declarative; names no code |
125
+ | `models.py` | input and output types; the published contract is derived from them |
126
+ | `workflows.py`, `activities.py` | the job, in plain Temporal; **no `kontra` import** |
127
+ | `quote.py` | the price, computed from the input |
128
+ | `worker.py` | binds workflow and quote to the offering; every `temporalio.worker.Worker` option |
129
+
130
+ Against the real marketplace:
131
+
132
+ ```sh
133
+ kontra login --email you@example.com # or plain `kontra login` (browser); makes this machine's key
134
+ kontra publish # needs a recent login, never a key; prints the hash and endpoint
135
+ kontra serve # on the machine that does the work (a key will do here)
136
+ ```
137
+
138
+ A published version is fixed: change a type or `offering.yaml` and bump the version, or
139
+ `kontra serve` refuses to start ("republish or bump the version"). See
140
+ [docs/sellers.md](docs/sellers.md).
141
+
142
+ [`examples/hello`](examples/hello) is the smallest offering (a name in, `Hi <name>` out, a
143
+ cent a job) and the five-minute tutorial from login to a paid job; a live copy runs as
144
+ `demo/hello` on [app.kontra.run](https://app.kontra.run).
145
+
146
+ ## Hire a job
147
+
148
+ From the shell:
149
+
150
+ ```sh
151
+ kontra quote acme/enrich -f in.json
152
+ kontra hire acme/enrich -f in.json --max-price 1 --wait --accept
153
+ kontra jobs
154
+ kontra job <job id> --result out/ # writes result.json and every artifact
155
+ ```
156
+
157
+ From a script:
158
+
159
+ ```python
160
+ import asyncio
161
+
162
+ from kontra.hire import Kontra
163
+
164
+
165
+ async def main() -> None:
166
+ # Your profile and key (~/.kontra). The input is checked against the published
167
+ # contract, then encrypted to the seller and to you.
168
+ async with Kontra() as k:
169
+ q = await k.quote("acme/enrich", urls=["https://example.com/"])
170
+ print(q.price, q.currency, q.max_duration)
171
+
172
+ job = await q.hire(max_price=1) # locks the price in escrow; nothing above max_price
173
+ async for p in job.progress(): # the seller's heartbeats, decrypted
174
+ print(p)
175
+
176
+ result = await job.result() # decrypted with your key, checked against the contract
177
+ await result.records.download("records.jsonl") # an artifact: streamed, verified
178
+ await job.accept() # or job.reject("why"); silence accepts when the window ends
179
+
180
+
181
+ asyncio.run(main())
182
+ ```
183
+
184
+ From inside your own Temporal workflow (composition):
185
+
186
+ ```python
187
+ from temporalio import workflow
188
+
189
+ with workflow.unsafe.imports_passed_through():
190
+ from kontra.hire import service
191
+
192
+
193
+ @workflow.defn
194
+ class Recon:
195
+ @workflow.run
196
+ async def run(self, domain: str) -> dict:
197
+ records = await service("acme/enrich", max_price=5).execute(urls=[f"https://{domain}/"])
198
+ return records.to_dict()
199
+ ```
200
+
201
+ Run that workflow on `await kontra.hire.worker(task_queue="recon", workflows=[Recon])`: a
202
+ plain Temporal worker whose client carries your keys and which runs the quote-and-hold
203
+ activities. Cancelling the workflow cancels the job and refunds the hold.
204
+
205
+ From an agent: `kontra mcp` serves eight tools (`search`, `describe`, `quote`, `hire`,
206
+ `status`, `result`, `accept`, `reject`) over stdio, on the machine that holds your key:
207
+
208
+ ```json
209
+ { "mcpServers": { "kontra": { "command": "kontra", "args": ["mcp"] } } }
210
+ ```
211
+
212
+ See [docs/buyers.md](docs/buyers.md).
213
+
214
+ ## The security model, briefly
215
+
216
+ - **End-to-end encryption.** Every Temporal payload passes through a codec that encrypts it with
217
+ [age](https://age-encryption.org) to the job's parties: inputs to the seller (and the buyer),
218
+ results to the buyer (and the seller). Large values and files go to the bucket as ciphertext.
219
+ Kontra holds ciphertext, hashes, sizes, timestamps and workflow metadata. The one payload it
220
+ reads is a quote's answer (a price, or a refusal), because it must lock the price.
221
+ - **Escrow from observable facts.** Money moves by pure rules (`kontra/escrow.py`) over three
222
+ kinds of fact: the state of the seller's handler workflow as Temporal records it, the clock,
223
+ and the buyer's accept, reject and cancel calls. Neither party's word moves money. A job not
224
+ delivered by its deadline refunds the buyer; a delivery the buyer does not reject within the
225
+ review window pays the seller.
226
+ - **The Authorizer.** Kontra runs its own Temporal server. Every token on the public frontend
227
+ is one weak role, `<namespace>:worker`, confined to its own namespace by an allowlist; no
228
+ token can reach an Operator or Admin API, so a compromised seller machine cannot repoint an
229
+ offering. The policy is in [`temporal/authorizer`](temporal/authorizer), public so you can
230
+ read the rules you run under.
231
+ - **Logins and keys.** A person signs in through a device code that only their own screen
232
+ shows, approved in the browser or through a mailed link whose page asks for that code. An
233
+ API key is for programs: it never publishes, whatever its age.
234
+
235
+ What Kontra can and cannot see, the threat model, and the limits: [docs/security.md](docs/security.md).
236
+
237
+ ## Documentation
238
+
239
+ | | |
240
+ |---|---|
241
+ | [docs/sellers.md](docs/sellers.md) | writing, testing, publishing and serving an offering |
242
+ | [docs/buyers.md](docs/buyers.md) | hiring from the CLI, a script, a workflow, or an agent |
243
+ | [docs/security.md](docs/security.md) | threat model, encryption and the Authorizer |
244
+ | [docs/architecture.md](docs/architecture.md) | the five seams, the one-way rule, how names are built |
245
+ | [docs/decisions.md](docs/decisions.md) | implementation decisions, checked against Temporal and nexgen |
246
+ | [spec/](spec/README.md) | the contract document's `x-kontra` extension and reserved types |
247
+ | [temporal/authorizer](temporal/authorizer/README.md) | the Temporal server, its policy and its configuration |
248
+ | [examples/](examples) | `hello` (the smallest seller, a five-minute tutorial), `enrich` (seller), `legacy-actor` (seller), `recon` (buyer workflow) |
249
+
250
+ ## Contributing
251
+
252
+ `make sync && make check` runs what CI runs. Work on a topic branch and open the pull request
253
+ against `dev`. See [CONTRIBUTING.md](CONTRIBUTING.md); report vulnerabilities privately as
254
+ described in [SECURITY.md](SECURITY.md).
255
+
256
+ ## License
257
+
258
+ [Apache-2.0](LICENSE).