crudecode 0.1.0a1__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 (39) hide show
  1. crudecode-0.1.0a1/.gitignore +5 -0
  2. crudecode-0.1.0a1/LICENSE +201 -0
  3. crudecode-0.1.0a1/PKG-INFO +43 -0
  4. crudecode-0.1.0a1/README.md +22 -0
  5. crudecode-0.1.0a1/pyproject.toml +51 -0
  6. crudecode-0.1.0a1/src/crudecode/GUIDE.md +103 -0
  7. crudecode-0.1.0a1/src/crudecode/__init__.py +4 -0
  8. crudecode-0.1.0a1/src/crudecode/__main__.py +3 -0
  9. crudecode-0.1.0a1/src/crudecode/cli.py +151 -0
  10. crudecode-0.1.0a1/src/crudecode/engine/__init__.py +3 -0
  11. crudecode-0.1.0a1/src/crudecode/engine/assumptions.py +223 -0
  12. crudecode-0.1.0a1/src/crudecode/engine/consequences.py +106 -0
  13. crudecode-0.1.0a1/src/crudecode/engine/curves.py +88 -0
  14. crudecode-0.1.0a1/src/crudecode/engine/deal.py +447 -0
  15. crudecode-0.1.0a1/src/crudecode/engine/economics.py +290 -0
  16. crudecode-0.1.0a1/src/crudecode/forecasting/GUIDE.md +706 -0
  17. crudecode-0.1.0a1/src/crudecode/forecasting/__init__.py +2 -0
  18. crudecode-0.1.0a1/src/crudecode/forecasting/check.py +154 -0
  19. crudecode-0.1.0a1/src/crudecode/valuation/GUIDE.md +334 -0
  20. crudecode-0.1.0a1/src/crudecode/valuation/__init__.py +2 -0
  21. crudecode-0.1.0a1/src/crudecode/valuation/assumptions.default.toml +37 -0
  22. crudecode-0.1.0a1/src/crudecode/valuation/examples/assumptions.toml +24 -0
  23. crudecode-0.1.0a1/src/crudecode/valuation/examples/deal.json +62 -0
  24. crudecode-0.1.0a1/src/crudecode/valuation/examples/output/README.md +72 -0
  25. crudecode-0.1.0a1/src/crudecode/valuation/examples/output/parameters.csv +9 -0
  26. crudecode-0.1.0a1/src/crudecode/valuation/examples/output/summary.txt +12 -0
  27. crudecode-0.1.0a1/src/crudecode/valuation/examples/output/wells_monthly.csv +1441 -0
  28. crudecode-0.1.0a1/src/crudecode/valuation/outputs.py +233 -0
  29. crudecode-0.1.0a1/src/crudecode/valuation/run.py +72 -0
  30. crudecode-0.1.0a1/src/crudecode/valuation/schema.json +117 -0
  31. crudecode-0.1.0a1/tests/helpers.py +39 -0
  32. crudecode-0.1.0a1/tests/test_assumptions.py +98 -0
  33. crudecode-0.1.0a1/tests/test_cli.py +209 -0
  34. crudecode-0.1.0a1/tests/test_deal.py +272 -0
  35. crudecode-0.1.0a1/tests/test_engine.py +129 -0
  36. crudecode-0.1.0a1/tests/test_example.py +36 -0
  37. crudecode-0.1.0a1/tests/test_guides.py +128 -0
  38. crudecode-0.1.0a1/tests/test_schema.py +81 -0
  39. crudecode-0.1.0a1/tests/test_standalone.py +59 -0
@@ -0,0 +1,5 @@
1
+ dist/
2
+ build/
3
+ *.egg-info/
4
+ __pycache__/
5
+ .pytest_cache/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Crude Code
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.5
2
+ Name: crudecode
3
+ Version: 0.1.0a1
4
+ Summary: The method for oil & gas analysis with LLMs: guides, decline-curve forecast checks and well-level valuation economics. Pairs with the Crude Code MCP data server.
5
+ Project-URL: Homepage, https://crudecode.dev
6
+ Author: Crude Code
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: decline curve,llm,mcp,npv,oil and gas,valuation
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: numpy>=1.26
19
+ Requires-Dist: python-dateutil>=2.8
20
+ Description-Content-Type: text/markdown
21
+
22
+ # crudecode
23
+
24
+ The method half of Crude Code. The [Crude Code MCP server](https://crudecode.dev)
25
+ serves US well data from state filings; this package is what an LLM (any LLM
26
+ with a Python sandbox) uses to turn that data into forecasts and valuations:
27
+ guides, code and default assumptions.
28
+
29
+ ```bash
30
+ pip install --break-system-packages crudecode==0.1.0a1
31
+ crudecode guide # start here
32
+ ```
33
+
34
+ * `crudecode guide [name]` prints a guide (`forecasting`, `valuation`, `schema`, `example`).
35
+ * `crudecode forecast check deal.json` validates asserted decline curves and echoes what they imply.
36
+ * `crudecode assumptions init assumptions.toml` writes the default economic assumptions.
37
+ * `crudecode value deal.json --assumptions assumptions.toml --out out/` runs the economics.
38
+
39
+ The kit is standalone: two dependencies (numpy, python-dateutil), no network
40
+ calls, plain CSV/JSON/Markdown outputs. Apache-2.0.
41
+
42
+ Version 0.1.0a1 covers the valuation workflow on a flat price deck. A strip
43
+ (futures) deck is not supported yet.
@@ -0,0 +1,22 @@
1
+ # crudecode
2
+
3
+ The method half of Crude Code. The [Crude Code MCP server](https://crudecode.dev)
4
+ serves US well data from state filings; this package is what an LLM (any LLM
5
+ with a Python sandbox) uses to turn that data into forecasts and valuations:
6
+ guides, code and default assumptions.
7
+
8
+ ```bash
9
+ pip install --break-system-packages crudecode==0.1.0a1
10
+ crudecode guide # start here
11
+ ```
12
+
13
+ * `crudecode guide [name]` prints a guide (`forecasting`, `valuation`, `schema`, `example`).
14
+ * `crudecode forecast check deal.json` validates asserted decline curves and echoes what they imply.
15
+ * `crudecode assumptions init assumptions.toml` writes the default economic assumptions.
16
+ * `crudecode value deal.json --assumptions assumptions.toml --out out/` runs the economics.
17
+
18
+ The kit is standalone: two dependencies (numpy, python-dateutil), no network
19
+ calls, plain CSV/JSON/Markdown outputs. Apache-2.0.
20
+
21
+ Version 0.1.0a1 covers the valuation workflow on a flat price deck. A strip
22
+ (futures) deck is not supported yet.
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "crudecode"
7
+ version = "0.1.0a1"
8
+ description = "The method for oil & gas analysis with LLMs: guides, decline-curve forecast checks and well-level valuation economics. Pairs with the Crude Code MCP data server."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Crude Code" }]
14
+ keywords = ["oil and gas", "decline curve", "valuation", "npv", "llm", "mcp"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ ]
24
+ # Runtime dependencies are exactly these two. The kit makes no network calls.
25
+ dependencies = [
26
+ "numpy>=1.26",
27
+ "python-dateutil>=2.8",
28
+ ]
29
+
30
+ [project.scripts]
31
+ crudecode = "crudecode.cli:main"
32
+
33
+ [project.urls]
34
+ Homepage = "https://crudecode.dev"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/crudecode"]
38
+
39
+ # The sdist carries the kit's own tests. The parity tests compare against the
40
+ # crude-code repo's engine and a database, so they stay in the repo.
41
+ [tool.hatch.build.targets.sdist]
42
+ include = ["src", "tests", "LICENSE", "README.md", "pyproject.toml"]
43
+ exclude = ["tests/parity_*.py", "tests/test_parity_*.py", "tests/test_drift.py"]
44
+
45
+ # Tests run from the checkout without installing: `src` for the kit, `..` (the
46
+ # crude-code repo root) only for the parity tests, which import the repo's
47
+ # ad/valuation engine and skip themselves when it is not there.
48
+ [tool.pytest.ini_options]
49
+ testpaths = ["tests"]
50
+ pythonpath = ["src", ".."]
51
+ markers = ["db: needs a live database (CC_WELLS_DB_URL or TASK_DB_URL); skipped without one"]
@@ -0,0 +1,103 @@
1
+ # crudecode: start here
2
+
3
+ `crudecode` is the method half of Crude Code. It is a small Python package you
4
+ run in your own sandbox. It gives you guides (how to forecast a well, how to
5
+ value a package), default assumptions, and the code that checks your forecasts
6
+ and does the economics. It never touches the network and it never chooses a
7
+ number for you.
8
+
9
+ The other half is the **Crude Code MCP server**, which serves the data: US well
10
+ headers and monthly production from state regulatory filings. The split is
11
+ deliberate:
12
+
13
+ | | Crude Code MCP (data) | `crudecode` (method) |
14
+ |---|---|---|
15
+ | Holds | well headers, monthly production, coverage, SQL over the warehouse | guides, decline-curve and cashflow code, default assumptions |
16
+ | You use it for | evidence: what did this well report? | judgment checks and arithmetic: what does this curve imply? what is this package worth? |
17
+ | Where it runs | the server | your sandbox |
18
+
19
+ Rule of thumb: **bulk data stays on the MCP; only small inputs reach the
20
+ sandbox, and you write them.** You do not copy production tables into the
21
+ sandbox. You read the history through the data tools, make your judgments, and
22
+ write a small file (about a few hundred bytes per well: curves, interests, a
23
+ few facts) that the kit reads.
24
+
25
+ ## The data tools (Crude Code MCP)
26
+
27
+ | Tool | Use it for |
28
+ |---|---|
29
+ | `get_coverage` | what data exists, per state; how complete each header field is. Call first when unsure a question can be answered. |
30
+ | `search` | resolve a well name, API number, operator or county to ids |
31
+ | `get_well` | full header for up to 50 wells: status, formation, lateral, key dates, cumulatives |
32
+ | `get_production` | monthly oil (bbl), gas (mcf), water, days produced for up to 50 wells, or summed across wells (`combine=true`) |
33
+ | `run_sql` | anything custom: one read-only SELECT against the warehouse (its description carries the schema). Use it for aggregates so the rows you read stay small. |
34
+
35
+ Facts you must carry with you: `api10` is the **undashed 10-digit** API number.
36
+ A **NULL volume means no number was reported, never zero**. `prod_month = 1`
37
+ is a well's first producing month (often partial). Some header columns are thin
38
+ in some states (check `get_coverage`); say so rather than presenting a partial
39
+ set as the whole.
40
+
41
+ ## Which guide for which job
42
+
43
+ | Job | Read | Commands |
44
+ |---|---|---|
45
+ | Forecast one well or many: assert decline curves and sanity-check them | `crudecode guide forecasting` | `crudecode forecast check deal.json` |
46
+ | Value a package: NPV by PDP / DUC / PUD, monthly volumes and cashflows | `crudecode guide valuation` (forecast first, then value) | `crudecode assumptions init`, `crudecode forecast check`, `crudecode value` |
47
+ | See the exact deal.json contract | `crudecode guide schema` | |
48
+ | See a worked deal.json | `crudecode guide example` (and `crudecode guide example-assumptions`) | |
49
+
50
+ A valuation always needs forecasts, so for a valuation read **forecasting
51
+ first**, then **valuation**.
52
+
53
+ ## The commands
54
+
55
+ ```
56
+ crudecode guide [forecasting|valuation|schema|example|example-assumptions]
57
+ print a guide
58
+ crudecode forecast check deal.json [--assumptions FILE] [--json]
59
+ validate asserted curves and echo what they imply
60
+ crudecode assumptions init assumptions.toml write the default economic assumptions to edit
61
+ crudecode value deal.json --assumptions assumptions.toml --out out/
62
+ run the economics; writes wells_monthly.csv,
63
+ parameters.csv, README.md into out/
64
+ ```
65
+
66
+ Exit codes: 0 fine, 1 `deal.json` failed validation (every violation is
67
+ listed at once; nothing is accepted piecemeal), 2 a file could not be read, the
68
+ assumptions file is invalid, or the command was used wrongly.
69
+
70
+ The guides are long. `crudecode guide forecasting --toc` lists a guide's
71
+ sections and `crudecode guide forecasting --section N` prints one, in case your
72
+ sandbox truncates long output.
73
+
74
+ ## Ground rules
75
+
76
+ 1. **You assert every parameter.** The kit validates sanity bounds and echoes
77
+ consequences; anything inside the bounds is your call. Write your reasoning
78
+ in each well's `rationale`.
79
+ 2. **Nothing is defaulted silently.** Every well needs an explicit bucket
80
+ (PDP, DUC or PUD). Economic assumptions come from an assumptions file you
81
+ have shown to the user. If the kit refuses an input, fix the input; do not
82
+ work around it.
83
+ 3. **Show the assumptions, get a yes, then run.** Before `crudecode value`,
84
+ present the assumptions (the valuation guide has the grid) and let the user
85
+ confirm or change them.
86
+ 4. **Units.** Oil in barrels, gas in mcf, rates per month, money in USD,
87
+ interests as fractions (0.75 = 75%), decline `di` as a nominal monthly rate.
88
+ 5. **Say what the number is.** This version prices on a **flat deck** only
89
+ (strip/futures pricing is not supported yet), models no NGLs and no
90
+ ownership or title diligence, and values what the wells' assertions say.
91
+ State those limits next to any NPV you report.
92
+ 6. **Hand over the files.** The outputs are plain CSV, JSON and Markdown. Give
93
+ the user the files as they are, and summarize the NPV in your reply.
94
+
95
+ ## Installing
96
+
97
+ ```
98
+ pip install --break-system-packages crudecode==0.1.0a1
99
+ ```
100
+
101
+ Two dependencies (numpy, python-dateutil). After install the kit needs no
102
+ network access. Problems with the kit or the data: tell the user, and use the
103
+ MCP's `message_team` tool to report them.
@@ -0,0 +1,4 @@
1
+ """crudecode: guides, forecast checks and valuation economics for oil & gas
2
+ analysis with an LLM. Pairs with the Crude Code MCP data server."""
3
+
4
+ __version__ = "0.1.0a1"
@@ -0,0 +1,3 @@
1
+ from crudecode.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,151 @@
1
+ """The `crudecode` command line.
2
+
3
+ crudecode guide [name]
4
+ crudecode forecast check deal.json [--assumptions FILE] [--json]
5
+ crudecode assumptions init FILE [--force]
6
+ crudecode value deal.json --assumptions FILE --out DIR [--json]
7
+
8
+ The kit makes no network calls and writes only the files it is told to.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import os
14
+ import sys
15
+ from importlib.resources import files
16
+
17
+ from crudecode import __version__
18
+
19
+ # `crudecode guide <name>` -> path inside the package.
20
+ _GUIDES = {
21
+ "index": ("GUIDE.md",),
22
+ "forecasting": ("forecasting", "GUIDE.md"),
23
+ "valuation": ("valuation", "GUIDE.md"),
24
+ "schema": ("valuation", "schema.json"),
25
+ "example": ("valuation", "examples", "deal.json"),
26
+ "example-assumptions": ("valuation", "examples", "assumptions.toml"),
27
+ }
28
+ _GUIDE_BLURB = {
29
+ "index": "what the kit is and which guide to read (default)",
30
+ "forecasting": "how to assert decline curves and check them",
31
+ "valuation": "how to build deal.json from the data tools, run the economics, read the results",
32
+ "schema": "the JSON Schema for deal.json",
33
+ "example": "one worked deal.json (synthetic wells)",
34
+ "example-assumptions": "the assumptions file that example was valued with",
35
+ }
36
+
37
+
38
+ def _sections(text: str) -> list[tuple[str, str]]:
39
+ """Split a Markdown guide into (heading, body) parts at its '## ' headings.
40
+ Anything before the first '## ' (title, intro) is part 0, headed by the title."""
41
+ parts: list[tuple[str, list[str]]] = [("(start)", [])]
42
+ in_fence = False
43
+ for line in text.splitlines(keepends=True):
44
+ if line.lstrip().startswith("```"):
45
+ in_fence = not in_fence
46
+ if line.startswith("## ") and not in_fence:
47
+ parts.append((line[3:].strip(), [line]))
48
+ else:
49
+ parts[-1][1].append(line)
50
+ return [(h, "".join(b)) for h, b in parts]
51
+
52
+
53
+ def _guide(name: str | None, section: str | None, toc: bool) -> int:
54
+ key = (name or "index").lower()
55
+ if key not in _GUIDES:
56
+ sys.stderr.write(f"no guide named {name!r}. Available:\n")
57
+ for k, blurb in _GUIDE_BLURB.items():
58
+ sys.stderr.write(f" crudecode guide {k:<12} {blurb}\n")
59
+ return 2
60
+ text = files("crudecode").joinpath(*_GUIDES[key]).read_text(encoding="utf-8")
61
+ if not (toc or section):
62
+ sys.stdout.write(text)
63
+ return 0
64
+ if not _GUIDES[key][-1].endswith(".md"):
65
+ sys.stderr.write(f"{key} is not a sectioned guide; print it whole\n")
66
+ return 2
67
+ parts = _sections(text)
68
+ if toc:
69
+ sys.stdout.write(f"crudecode guide {key}: {len(text):,} characters in {len(parts) - 1} sections\n")
70
+ for i, (heading, body) in enumerate(parts):
71
+ sys.stdout.write(f" {i} {heading} ({len(body):,} chars)\n")
72
+ sys.stdout.write(f"read one with: crudecode guide {key} --section N (or a word from the heading)\n")
73
+ return 0
74
+ if section.isdigit() and int(section) < len(parts):
75
+ sys.stdout.write(parts[int(section)][1])
76
+ return 0
77
+ hits = [p for p in parts[1:] if section.lower() in p[0].lower()]
78
+ if len(hits) != 1:
79
+ sys.stderr.write(f"--section {section!r} matches {len(hits)} sections; use a number from --toc\n")
80
+ return 2
81
+ sys.stdout.write(hits[0][1])
82
+ return 0
83
+
84
+
85
+ def _parser() -> argparse.ArgumentParser:
86
+ p = argparse.ArgumentParser(
87
+ prog="crudecode",
88
+ description="Guides, forecast checks and valuation economics for oil & gas analysis with an LLM. "
89
+ "Start with: crudecode guide")
90
+ p.add_argument("--version", action="version", version=f"crudecode {__version__}")
91
+ sub = p.add_subparsers(dest="cmd", metavar="command")
92
+
93
+ g = sub.add_parser("guide", help="print a guide (index, forecasting, valuation, schema, example, example-assumptions)")
94
+ g.add_argument("name", nargs="?", help="guide name; omit for the index")
95
+ g.add_argument("--toc", action="store_true", help="list the guide's sections and their sizes")
96
+ g.add_argument("--section", help="print one section only: a number from --toc, or a word from its heading")
97
+
98
+ f = sub.add_parser("forecast", help="forecast workflow")
99
+ fsub = f.add_subparsers(dest="forecast_cmd", metavar="action", required=True)
100
+ fc = fsub.add_parser("check", help="validate asserted decline curves in deal.json and echo what they imply")
101
+ fc.add_argument("deal", help="path to deal.json")
102
+ fc.add_argument("--assumptions", help="assumptions TOML (horizon, terminal decline); defaults if omitted")
103
+ fc.add_argument("--json", action="store_true", help="machine-readable output")
104
+
105
+ a = sub.add_parser("assumptions", help="economic assumptions file")
106
+ asub = a.add_subparsers(dest="assumptions_cmd", metavar="action", required=True)
107
+ ai = asub.add_parser("init", help="write the default assumptions to FILE")
108
+ ai.add_argument("file", help="where to write the TOML")
109
+ ai.add_argument("--force", action="store_true", help="overwrite an existing file")
110
+
111
+ v = sub.add_parser("value", help="run the economics for deal.json and write the result files")
112
+ v.add_argument("deal", help="path to deal.json")
113
+ v.add_argument("--assumptions", required=True,
114
+ help="assumptions TOML (create one with: crudecode assumptions init FILE)")
115
+ v.add_argument("--out", required=True, help="directory for wells_monthly.csv, parameters.csv, README.md")
116
+ v.add_argument("--json", action="store_true", help="print the summary as JSON instead of text")
117
+ return p
118
+
119
+
120
+ def main(argv: list[str] | None = None) -> int:
121
+ try:
122
+ return _run(argv)
123
+ except BrokenPipeError: # `crudecode guide forecasting | head`
124
+ os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
125
+ return 0
126
+
127
+
128
+ def _run(argv: list[str] | None) -> int:
129
+ parser = _parser()
130
+ args = parser.parse_args(argv)
131
+ if args.cmd is None:
132
+ parser.print_help()
133
+ sys.stdout.write("\nStart here: crudecode guide\n")
134
+ return 0
135
+ if args.cmd == "guide":
136
+ return _guide(args.name, args.section, args.toc)
137
+ if args.cmd == "forecast":
138
+ from crudecode.forecasting import check
139
+ return check.run(args.deal, args.assumptions, args.json)
140
+ if args.cmd == "assumptions":
141
+ from crudecode.valuation import run
142
+ return run.init_assumptions(args.file, args.force)
143
+ if args.cmd == "value":
144
+ from crudecode.valuation import run
145
+ return run.run(args.deal, args.assumptions, args.out, args.json)
146
+ parser.error(f"unknown command {args.cmd!r}")
147
+ return 2
148
+
149
+
150
+ if __name__ == "__main__":
151
+ sys.exit(main())
@@ -0,0 +1,3 @@
1
+ """Shared utilities: decline curves, forecast consequences, economics, the
2
+ assumptions loader and the deal.json parser. Workflows (forecasting/,
3
+ valuation/) import from here and never from each other."""