@cs-object/cli 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.
package/LICENSE ADDED
@@ -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.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ CalculationSourceObject
2
+ Copyright 2026 Viktar Beliakou
3
+
4
+ Third-party components retain their own licenses and attribution notices.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # Calculation CLI
2
+
3
+ `cso verify` captures one Python execution and independently checks its formulas.
4
+ `cso html` and `cso pdf` verify that same execution before preparing a document.
5
+ `cso bindings` generates typed calculation handles. `dev-export` and `dev-render`
6
+ retain the unverified development paths.
7
+
8
+ ## Run
9
+
10
+ Follow [setup](../../docs/development.md#setup). In the workspace use
11
+ `node packages/cso-cli/dist/cli.js`; an installed consumer uses `cso`.
12
+ `PYTHON` selects the interpreter with the installed `cso-python` wheel.
13
+
14
+ ```sh
15
+ cso bindings examples/two-panel
16
+ cso verify examples/two-panel/estimate.cso.py \
17
+ --function estimate --input width=2 --reference examples/two-panel/reference.json --format json
18
+ cso html examples/two-panel/estimate.cso.py \
19
+ --function estimate --input width=2 --out output/panels.html --check-layout --format json
20
+ cso pdf examples/two-panel/estimate.cso.py \
21
+ --function estimate --input width=2 --reference examples/two-panel/reference.json \
22
+ --out output/panels.pdf --format json
23
+ ```
24
+
25
+ Use `cso <command> --help` for current options. Source, reference and output paths
26
+ resolve against the invoking directory. Repeat `--input name=value` for distinct
27
+ parameters. Duplicate/unknown inputs and invalid numeric values are usage errors.
28
+ The [argument parser](src/verified-arguments.ts) is authoritative for syntax.
29
+
30
+ Verified commands write one structured JSON report to stdout and operational
31
+ messages to stderr. Exit 0 means success, 1 means verification/generation failure,
32
+ and 2 means invalid usage. Reports retain known source hashes, function, inputs,
33
+ versions and diagnostics; successful HTML/PDF reports include output path and hash.
34
+ Unknown provenance is not fabricated. See [report schemas](../../packages/cso-core/src/contracts/reports.ts).
35
+
36
+ ## Numerical checks
37
+
38
+ [verifyExecution](../../packages/cso-core/src/verification/verify.ts) checks inputs,
39
+ constants, formulas, caches and v2 public outputs. It evaluates formulas without
40
+ using cached results as operands and compares them with actual Python observations.
41
+ Hidden documented intermediates remain covered. V1 has no public-output evidence,
42
+ so its output check is not applicable.
43
+
44
+ The [numeric implementation](../../packages/cso-core/src/verification/numeric.ts)
45
+ uses finite binary64 floats and exact Python integers within the safe integer
46
+ range. New captures retain actual numeric kinds through literals, bindings,
47
+ observations and public outputs. Core propagates kinds independently through
48
+ formulas; division and square roots produce floats. Older captures without kind
49
+ evidence retain the conservative integer-valued range limit. Conditional formulas
50
+ evaluate only their selected branch after checking the complete graph structure.
51
+ The [authoring guide](../../docs/authoring.md#supported-source-and-document-content)
52
+ lists supported functions. The fixed comparison is:
53
+
54
+ ```text
55
+ abs(actual - expected) <= max(1e-9, 1e-12 * max(abs(actual), abs(expected)))
56
+ ```
57
+
58
+ An absolute difference outside the finite binary64 range is reported as
59
+ `absoluteError: "overflow"` and fails agreement. Reference expected values may
60
+ include `numericKind: "float"` for finite values beyond the safe integer range.
61
+
62
+ Mismatch diagnostics retain compared values, error, tolerances, symbol and
63
+ available source location. The absolute tolerance applies in the declared unit.
64
+ There is no automatic unit conversion or dimensional/capacity assessment.
65
+ Unsupported formulas, invalid intermediate values and `documented_result` cannot
66
+ pass verified generation. Rendering supports more notation than this evaluator.
67
+
68
+ An explicit `--reference` file supplies independently established expected values.
69
+ [Reference binding](../../packages/cso-core/src/contracts/reference.ts) uses the
70
+ complete source closure, selected function and resolved inputs. Positive and
71
+ negative zero have distinct identities; input-key order does not affect identity.
72
+ A matching case must cover every calculated symbol and match its declared unit.
73
+ No match is `not_applicable`, never a pass. A failed matching reference blocks
74
+ success; absence of a match alone does not block an otherwise consistent PDF.
75
+
76
+ The CLI captures reference bytes once. Source edits, including numerically
77
+ equivalent edits, invalidate reference bindings until an explicit reviewed
78
+ revision. Never regenerate expected numbers from the execution being verified.
79
+
80
+ ## HTML preview
81
+
82
+ `cso html` writes a standalone page with embedded CSS and captured images. Open it
83
+ directly in a browser. Its screen layout uses the 190 mm print content width and
84
+ the same prepared document renderer as PDF. It contains the full calculation
85
+ narrative, including formulas, substitutions, units, explanations and results.
86
+
87
+ Without `--check-layout`, no browser runs. Execution and prepared-document checks
88
+ must pass; `rendering` is `not_applicable` and `visualInspection` is `pending`.
89
+ This mode permits inspection of a layout that needs repair. Image signatures are checked during capture and
90
+ source bindings during document preparation; image decoding, passive SVG policy
91
+ and browser presentation checks require `--check-layout`.
92
+
93
+ `--check-layout` uses Chromium to check assets, presentation and MathML bounds in
94
+ screen and print media. Failures report `DOCUMENT_LAYOUT_OVERFLOW` with placement,
95
+ selector, bounds, media and overflow distance under `diagnostics[].layout`.
96
+ A failed check preserves existing HTML. Both modes retain evidence by default;
97
+ `--no-evidence` writes only the page. The evidence manifest uses `html` for the
98
+ output binding and records automatic presentation as `not_applicable` when no
99
+ browser check ran. Geometry checks do not certify pagination or visual acceptance.
100
+
101
+ See the [HTML workflow](../../docs/rendering.md#html-iteration) for development
102
+ and the [check selection](../../docs/rendering.md#choose-verification-by-change)
103
+ for when PDF inspection is needed.
104
+
105
+ ## Document and evidence publication
106
+
107
+ The [document coordinator](src/document.ts) uses one execution for verification and
108
+ preparation. [Asset capture](src/assets.ts) checks module-relative containment,
109
+ hashes and media signatures. Browser checks for PDF and checked HTML additionally
110
+ require PNG/JPEG decode and passive SVG policy. Symlink escapes and active or
111
+ external SVG content fail those checks. The browser uses captured data URLs,
112
+ waits for fonts/images and checks mathematical descendants against row and sheet
113
+ bounds. [HTML construction](src/prepared-html.ts) and
114
+ [browser inspection](src/pdf-rendering.ts) are shared by both commands.
115
+
116
+ For output P, [evidence publication](src/evidence.ts) writes `P.evidence/H/`,
117
+ where H hashes the exact manifest bytes. Stderr reports its location/hash.
118
+ Payloads retain raw execution and supplied reference bytes, verification,
119
+ prepared data with captured assets, and a field/disposition mapping. Generated
120
+ JSON preserves negative zero. Source hashes identify captured Python files;
121
+ the bundle does not contain their original source bytes.
122
+
123
+ The manifest binds payloads, the document and prospective successful stdout bytes. Complete
124
+ evidence is published before the final atomic output replacement. Verification,
125
+ preparation, rendering or evidence-write failure preserves an existing output and
126
+ cleans owned temporary files. A failed final rename can leave an unused complete
127
+ bundle; require an actual successful report and matching output before treating it
128
+ as a receipt. Stdout failure after replacement cannot roll back that commit.
129
+ `--no-evidence` retains verification and atomic replacement but creates no
130
+ sibling evidence bundle.
131
+
132
+ New document reports leave visual inspection `pending`. Use the
133
+ [delivery guide](../../docs/rendering.md#printing-and-inspection). Keep source consistency, independent
134
+ agreement, content retention, rendering and visual inspection separate.
135
+ Generation and historical source reviews do not establish human approval.
136
+
137
+ ## Check the implementation
138
+
139
+ [App tests](tests/) cover arguments, reports and evidence behavior.
140
+ [Installed verification](../../tests/integration/installed/verify-consumer.mjs),
141
+ [PDF failures](../../tests/integration/installed/pdf-consumer.mjs) and
142
+ [signed-zero cases](../../tests/integration/installed/signed-zero-consumer.mjs)
143
+ exercise actual packages. See [integration commands](../../tests/integration/README.md)
144
+ for fresh archive/wheel consumers and retained acceptance records.
145
+
146
+ ## Work on a localhost calculation
147
+
148
+ Start one fixed source path and function with `cso dev calculations/report.cso.py
149
+ --function calculate --port 3000`. Port `0` selects an available port. The server
150
+ prints its `http://127.0.0.1:<port>` address. It uses the installed interpreter
151
+ selected by `PYTHON` and the CLI's Playwright Chromium for PDF output.
152
+
153
+ The browser builds its input form from the static Python definition. It shows
154
+ verified outputs, an embedded report, a curl request and PDF/evidence downloads.
155
+ Edit formulas in the source file and calculate again to capture the changes.
156
+ Editing browser inputs immediately clears the previous report and download link.
157
+ Reload the page after changing input declarations, names, defaults or metadata.
158
+
159
+ For a rectangle calculation with `width` and `height` inputs:
160
+
161
+ ```sh
162
+ curl -sS --fail-with-body http://127.0.0.1:3000/api/calculate \
163
+ -H 'Content-Type: application/json' \
164
+ -d '{"inputs":{"width":4,"height":3}}'
165
+ ```
166
+
167
+ A successful calculation response contains only named public outputs, such as
168
+ `{"area":12}`. Requests contain exactly one `inputs` object. Inputs may omit
169
+ parameters with defaults. Unknown fields, duplicate JSON keys, booleans,
170
+ nonfinite numbers and invalid integer values fail before execution. Finite
171
+ floating-point inputs may use the full binary64 range. Use a decimal or exponent
172
+ for floats outside the safe integer range; bare unsafe integer tokens are rejected.
173
+ Requests cannot select source paths, functions or server configuration.
174
+
175
+ `POST /api/runs` accepts the same request and returns an opaque run ID, outputs,
176
+ review checks and report/PDF/evidence URLs. Each run captures execution, assets,
177
+ the prepared document and HTML once. PDF generation uses that exact HTML, including
178
+ its captured CSS, and memoizes the result. Source edits never change an earlier
179
+ run's report or PDF. The PDF response includes `X-CSO-PDF-SHA256`. Its evidence JSON
180
+ binds the retained execution and document to the HTML/PDF hashes and automated
181
+ presentation findings. Browser evidence is an ephemeral download, separate from
182
+ the filesystem evidence bundles published by `cso html` and `cso pdf`.
183
+
184
+ Missing independent references appear as pending in the UI and report. Matching
185
+ reference failures block success. Human visual inspection remains pending, and
186
+ none of these checks establishes engineering approval. A PDF download succeeds only
187
+ after the maintained automatic presentation checks pass.
188
+
189
+ The server binds only to IPv4 loopback and rejects foreign Host/Origin headers.
190
+ It executes trusted local calculation sources. Python requests have a 30-second
191
+ deadline and bounded output. Execution is synchronous, so the local server pauses
192
+ while Python runs. One PDF renders at a time, with a 90-second deadline. Retention
193
+ is limited to 10 runs, 128 MiB of serialized report data, and 30 minutes. Expired or evicted
194
+ run URLs return 404. Request bodies are limited to 64 KiB. Stop with Ctrl+C;
195
+ restarting creates a new session and releases earlier run URLs.