create-cs-object 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -9,6 +9,43 @@ cd my-report
9
9
  npm run dev
10
10
  ```
11
11
 
12
+ In PowerShell 5.1 or 7, select Python 3.11+ and run the setup steps explicitly:
13
+
14
+ ```powershell
15
+ $env:PYTHON = Get-Command python -CommandType Application | Select-Object -First 1 -ExpandProperty Source
16
+ & $env:PYTHON --version
17
+ ```
18
+
19
+ <!-- docs:project-create:start -->
20
+ ```powershell
21
+ npm.cmd create cs-object my-report -- --skip-install
22
+ if ($LASTEXITCODE -ne 0) { throw 'Project creation failed.' }
23
+ Set-Location my-report
24
+ ```
25
+ <!-- docs:project-create:end -->
26
+
27
+ <!-- docs:project-setup:start -->
28
+ ```powershell
29
+ npm.cmd run setup
30
+ if ($LASTEXITCODE -ne 0) { throw 'Project setup failed.' }
31
+ ```
32
+ <!-- docs:project-setup:end -->
33
+
34
+ <!-- docs:project-dev:start -->
35
+ ```powershell
36
+ npm.cmd run dev -- --port 4173
37
+ if ($LASTEXITCODE -ne 0) { throw 'The development server failed.' }
38
+ ```
39
+ <!-- docs:project-dev:end -->
40
+
41
+ Use an absolute Python executable path for `PYTHON` if the interpreter is not
42
+ on PATH. A launcher-only installation can supply that path with
43
+ `$env:PYTHON = py -3.11 -c 'import json, sys; print(json.dumps(sys.executable))' | ConvertFrom-Json`.
44
+ The JSON capture preserves Unicode executable paths under legacy console encodings.
45
+ `PYTHON` is an executable path, not a command such as `py -3.11`.
46
+ The project uses its own `.venv`; activation and execution-policy changes are
47
+ unnecessary. See the generated project's `README.md` for browser and API usage.
48
+
12
49
  The initializer creates an owned project template, installs its exact CLI
13
50
  dependency, prepares `.venv`, and installs Chromium. It preserves generated
14
51
  files after setup failure; run `npm run setup` in the project to retry.
@@ -25,3 +62,7 @@ through its own local CLI process.
25
62
 
26
63
  Package tests execute a real npm archive in a temporary consumer. Full runtime
27
64
  acceptance belongs to the repository's installed integration checks.
65
+ Before a registry release, use the repository's
66
+ [local archive workflow](../../docs/development.md#local-package-consumers).
67
+ An initializer archive alone still installs the dependency versions named by
68
+ its template; it does not select sibling archives automatically.
package/dist/cli.js CHANGED
@@ -42,7 +42,7 @@ try {
42
42
  typecheck: "tsc -b --pretty false"
43
43
  },
44
44
  dependencies: {
45
- "@cs-object/cli": "0.1.1",
45
+ "@cs-object/cli": "0.1.2",
46
46
  "@cs-object/core": "0.1.0",
47
47
  "@base-ui/react": "^1.8.0",
48
48
  "@fontsource-variable/geist-mono": "^5.3.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cs-object",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Create a local CalculationSourceObject report project.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -0,0 +1,2 @@
1
+ *.py text eol=lf
2
+ *.pyi text eol=lf
@@ -15,9 +15,12 @@ and entry function. Restart the local server to update the report menu.
15
15
  Read [authoring.md](authoring.md) before changing source or notation. Keep inputs,
16
16
  units, assumptions, intermediate steps, references, and outputs inspectable.
17
17
 
18
- Run the calculation with representative inputs and review its rendered report.
18
+ For verification commands and completion criteria, follow
19
+ [Check the result](authoring.md#check-the-result). Run the calculation with
20
+ representative inputs and review its rendered report.
19
21
  Report source-to-document consistency, independent numerical agreement, and
20
22
  human engineering approval separately. Establish expected reference values
21
- independently of the execution under test. Inspect every PDF page before delivery.
23
+ independently of the execution under test. When delivering a PDF, inspect every
24
+ page before delivery.
22
25
 
23
26
  This project runs on localhost. Deployment is outside its calculation workflow.
@@ -7,9 +7,13 @@ Node dependencies, creates a private `.venv`, and installs Chromium for PDF outp
7
7
  npm run dev
8
8
  ```
9
9
 
10
+ In PowerShell 5.1 or 7, use `npm.cmd run dev`. Commands that invoke the installed
11
+ CLI directly use `.\node_modules\.bin\cso.cmd`; see
12
+ [Check the result](authoring.md#check-the-result).
13
+
10
14
  Open the localhost address printed in the terminal. Edit numeric inputs in the
11
- browser, calculate, review the report, and download its PDF. Change formulas in
12
- `calculations/report.cso.py`, then calculate again. If you change the declared
15
+ browser, calculate, and review the report. Download its PDF when needed. Change
16
+ formulas in `calculations/report.cso.py`, then calculate again. If you change the declared
13
17
  inputs, reload the browser page to rebuild its form. Existing report downloads
14
18
  remain tied to their captured run until that run expires or the server stops.
15
19
 
@@ -29,6 +33,30 @@ reference file. Restart `npm run dev` after editing the list. Each entry gets
29
33
  its own verified local API at `/api/reports/<id>/`; the menu switches between
30
34
  them without changing the input or report UI code.
31
35
 
36
+ For the starter, send inputs to the frontend's `/api/reports/rectangle-area/calculate`
37
+ route. Replace the origin with the address printed by `npm run dev`:
38
+
39
+ ```sh
40
+ curl --fail-with-body http://127.0.0.1:5173/api/reports/rectangle-area/calculate \
41
+ -H 'Content-Type: application/json' \
42
+ -d '{"inputs":{"width":2,"height":3}}'
43
+ ```
44
+
45
+ The result is `{"area":6}`. Use the report ID from `reports.json` in place of
46
+ `rectangle-area` after replacing the starter. `POST /api/reports/<id>/runs`
47
+ accepts the same body and returns a captured run with report and download links.
48
+ Wait for the initial report to load before testing input edits in the browser.
49
+
50
+ In PowerShell 5.1 or 7, the equivalent request avoids native-shell JSON quoting:
51
+
52
+ ```powershell
53
+ $request = @{ inputs = @{ width = 2; height = 3 } } | ConvertTo-Json
54
+ Invoke-RestMethod -Uri 'http://127.0.0.1:5173/api/reports/rectangle-area/calculate' -Method Post -ContentType 'application/json; charset=utf-8' -Body $request
55
+ ```
56
+
57
+ Use the port printed by your development server, such as `4173` when you select
58
+ that port explicitly. The response's `area` property is `6`.
59
+
32
60
  To choose a port, run `npm run dev -- --port 4173`. Use port `0` to select an
33
61
  available port. Stop the server with Ctrl+C and use the same command to restart.
34
62
 
@@ -36,6 +64,20 @@ If setup failed or you used `--skip-install`, run `npm run setup`.
36
64
  Set `PYTHON` to a Python executable if automatic detection cannot find Python
37
65
  3.11 or newer. Setup can be run again without replacing calculation files.
38
66
 
67
+ In PowerShell, retry with `npm.cmd run setup`. `PYTHON` accepts one absolute
68
+ executable path, including a path with spaces. Use
69
+ `& $env:PYTHON --version` to inspect it. Setup creates `.venv\Scripts\python.exe`.
70
+ You do not need to activate the environment or change an execution policy.
71
+
72
+ Build the frontend from PowerShell with:
73
+
74
+ <!-- docs:project-build:start -->
75
+ ```powershell
76
+ npm.cmd run build
77
+ if ($LASTEXITCODE -ne 0) { throw 'The frontend build failed.' }
78
+ ```
79
+ <!-- docs:project-build:end -->
80
+
39
81
  Before replacing the starter, update [the brief](brief.md), collect
40
82
  [references](references/README.md), and read [the authoring notes](authoring.md).
41
83
  Source-to-document consistency checks that the documented formulas agree with
@@ -66,6 +66,12 @@ finite Python floats may use the binary64 range. Booleans are not numeric
66
66
  inputs or results. Execution preserves the actual numeric kind and does not
67
67
  coerce values to satisfy an annotation.
68
68
 
69
+ Numeric input validation checks types and finite values. Documented physical
70
+ ranges, such as positive lengths or a maximum temperature, are assumptions;
71
+ declaring them in the brief does not enforce them in the API or browser.
72
+ Test valid boundary cases and report any physical limits that remain unenforced.
73
+ Record required range enforcement in the brief as an implementation requirement.
74
+
69
75
  ## Supported formulas and content
70
76
 
71
77
  Supported expressions include finite numeric literals, earlier documented
@@ -121,6 +127,18 @@ function:
121
127
  ./.venv/bin/python -m cso_python bindings calculations --check
122
128
  ```
123
129
 
130
+ In PowerShell 5.1 or 7, use the project's interpreter directly:
131
+
132
+ <!-- docs:project-bindings:start -->
133
+ ```powershell
134
+ $env:PYTHON = Join-Path $PWD '.venv\Scripts\python.exe'
135
+ & $env:PYTHON -I -X utf8 -m cso_python bindings calculations
136
+ if ($LASTEXITCODE -ne 0) { throw 'Binding generation failed.' }
137
+ & $env:PYTHON -I -X utf8 -m cso_python bindings calculations --check
138
+ if ($LASTEXITCODE -ne 0) { throw 'Bindings are stale.' }
139
+ ```
140
+ <!-- docs:project-bindings:end -->
141
+
124
142
  For a file `calculations/geometry.cso.py` with a public function
125
143
  `rectangle`, a parent in that directory can import and call it:
126
144
 
@@ -149,6 +167,11 @@ metadata or public output selections. Formula-only edits may leave the
149
167
  interface current. Generation validates definitions but does not execute
150
168
  formulas. A missing or stale handle will not regenerate itself.
151
169
 
170
+ Save authored Python as UTF-8 with LF line endings. The project's `.gitattributes`
171
+ keeps Python and stub files at LF on Git checkout. Generated bindings already
172
+ use UTF-8/LF. Source hashes cover exact bytes, so an editor's encoding or newline
173
+ change can invalidate a reference even when the formula is unchanged.
174
+
152
175
  Each distinct quantity needs distinct displayed notation. Repeated child
153
176
  calls qualify child glyphs using their call names. When a reference
154
177
  deliberately reuses a glyph in separate contexts, set a meaningful
@@ -165,15 +188,60 @@ Review every input, unit, intermediate formula, explanation, figure and
165
188
  returned result in the report. Check that the displayed substitutions and
166
189
  outputs match the intended engineering method.
167
190
 
191
+ From the project root, verify one execution and generate checked HTML with the
192
+ project's Python interpreter. In a POSIX shell:
193
+
194
+ ```sh
195
+ PYTHON="$PWD/.venv/bin/python" npx --no-install cso verify calculations/report.cso.py \
196
+ --function calculate --format json
197
+ mkdir -p output
198
+ PYTHON="$PWD/.venv/bin/python" npx --no-install cso html calculations/report.cso.py \
199
+ --function calculate --out output/report.html --check-layout --format json
200
+ ```
201
+
202
+ For the unchanged rectangle starter, these PowerShell 5.1 and 7 commands verify
203
+ width 2 and height 3, then write checked HTML and a PDF:
204
+
205
+ <!-- docs:project-report:start -->
206
+ ```powershell
207
+ $env:PYTHON = Join-Path $PWD '.venv\Scripts\python.exe'
208
+ $cso = Join-Path $PWD 'node_modules\.bin\cso.cmd'
209
+ $source = Join-Path $PWD 'calculations\report.cso.py'
210
+ & $cso verify $source --function calculate --input width=2 --input height=3 --format json
211
+ if ($LASTEXITCODE -ne 0) { throw 'Calculation verification failed.' }
212
+ New-Item -ItemType Directory -Force (Join-Path $PWD 'output') | Out-Null
213
+ & $cso html $source --function calculate --input width=2 --input height=3 --out (Join-Path $PWD 'output\report.html') --check-layout --format json
214
+ if ($LASTEXITCODE -ne 0) { throw 'Checked HTML generation failed.' }
215
+ & $cso pdf $source --function calculate --input width=2 --input height=3 --out (Join-Path $PWD 'output\report.pdf') --format json
216
+ if ($LASTEXITCODE -ne 0) { throw 'PDF generation failed.' }
217
+ ```
218
+ <!-- docs:project-report:end -->
219
+
220
+ Use `&` when invoking an executable stored in a variable. These commands use the
221
+ project's installed CLI and managed interpreter, including when the project
222
+ path contains spaces. Setup installs the matching Chromium used by both report
223
+ commands. The [reference recipe](references/README.md#bind-an-independent-case)
224
+ shows how to save structured JSON as UTF-8 without a BOM in either PowerShell.
225
+
226
+ Repeat verification with `--input name=value` for representative and boundary
227
+ cases. Check each command's exit status and report diagnostics. Open the HTML
228
+ and inspect its content; automated layout checks leave visual inspection pending.
229
+ Use `npm run dev` to test browser input edits and `npm run build` to check the
230
+ frontend. A frontend build alone does not verify the calculation.
231
+
168
232
  Keep three judgments separate: source-to-document consistency, agreement
169
233
  with independently established numerical cases, and human engineering
170
234
  approval. A pending reference check is not a passing reference check.
235
+ For a bound reference file and browser registration, follow the
236
+ [worked reference recipe](references/README.md#bind-an-independent-case).
171
237
  Formula or text edits change captured source identity and can invalidate
172
238
  reference bindings; review and explicitly rebind them while preserving
173
239
  independently established expected values. Never obtain expected values by
174
240
  copying the execution being tested.
175
241
 
176
- Download and inspect every PDF page at normal size for missing steps,
177
- unreadable notation, clipped content and pagination. The browser and PDF
178
- need the same run and inputs. See [README.md](README.md) for local setup,
179
- report registration and UI customization.
242
+ When delivering a PDF, download and inspect every page at normal size for
243
+ missing steps, unreadable notation, clipped content and pagination. The browser
244
+ and PDF need the same run and inputs. HTML-only work can finish with checked
245
+ HTML and visual inspection. Report what passed, failed or was not checked;
246
+ successful generation does not establish human engineering approval.
247
+ See [README.md](README.md) for local setup, report registration and UI customization.
@@ -3,3 +3,137 @@
3
3
  Keep source documents or links here. Record the relevant page or clause, edition,
4
4
  and the assumptions each source supports. The starter uses the elementary
5
5
  rectangle area relation and has no external engineering reference case.
6
+
7
+ ## Bind an independent case
8
+
9
+ A CLI reference file contains `referenceVersion: "1"` and a `cases` array.
10
+ Each case records an ID, revision, independent basis, source/input binding,
11
+ and expected values for every calculated symbol, including intermediates.
12
+ Each expected entry needs the captured symbol ID, independently established
13
+ value and matching unit. A comparison of only public outputs is a separate
14
+ numerical check; it does not provide complete CLI reference coverage.
15
+
16
+ This recipe is for the unchanged rectangle starter. Establish its expected
17
+ area independently first: a 2 m by 3 m rectangle has area 6 m². The verification
18
+ report supplies only source hashes, function and input metadata for binding;
19
+ the expected value below is the hand-derived 6, not a captured result.
20
+
21
+ From the project root in a POSIX shell:
22
+
23
+ ```sh
24
+ PYTHON="$PWD/.venv/bin/python" npx --no-install cso verify calculations/report.cso.py \
25
+ --function calculate --input width=2 --input height=3 --format json \
26
+ > references/rectangle-check.json
27
+ ```
28
+
29
+ Create `references/rectangle-reference.json` with the full case shape:
30
+
31
+ ```sh
32
+ ./.venv/bin/python - <<'PY'
33
+ import json
34
+ from pathlib import Path
35
+
36
+ report = json.loads(Path("references/rectangle-check.json").read_text(encoding="utf-8"))
37
+ if not report["ok"]:
38
+ raise SystemExit("Resolve verification diagnostics before binding a case")
39
+ fields = (
40
+ "entryModuleId", "entrySourceHash", "sourceClosureHash", "function",
41
+ "resolvedInputs", "resolvedInputKinds",
42
+ )
43
+ reference = {
44
+ "referenceVersion": "1",
45
+ "cases": [{
46
+ "id": "rectangle-2-by-3",
47
+ "revision": "1",
48
+ "basis": {
49
+ "method": "Hand-derived rectangle area",
50
+ "derivation": "Perpendicular sides: 2 m times 3 m equals 6 m^2.",
51
+ "sourceDescription": "Elementary geometry for the stated rectangle.",
52
+ },
53
+ "binding": {name: report["provenance"][name] for name in fields},
54
+ "expected": [{
55
+ "symbolId": '["symbol","root","area"]',
56
+ "value": 6,
57
+ "unit": "m^2",
58
+ }],
59
+ }],
60
+ }
61
+ Path("references/rectangle-reference.json").write_text(
62
+ json.dumps(reference, indent=2) + "\n", encoding="utf-8", newline="\n"
63
+ )
64
+ PY
65
+ PYTHON="$PWD/.venv/bin/python" npx --no-install cso verify calculations/report.cso.py \
66
+ --function calculate --input width=2 --input height=3 \
67
+ --reference references/rectangle-reference.json --format json
68
+ ```
69
+
70
+ In PowerShell 5.1 or 7, run the following block instead. It captures only the
71
+ verification metadata needed to bind the independently derived value `6`.
72
+ The JSON stays inside PowerShell until the file write, so native argument
73
+ quoting cannot alter it. `Join-Path $PWD` gives the .NET writer an absolute path.
74
+
75
+ <!-- docs:reference-authoring:start -->
76
+ ```powershell
77
+ $env:PYTHON = Join-Path $PWD '.venv\Scripts\python.exe'
78
+ $cso = Join-Path $PWD 'node_modules\.bin\cso.cmd'
79
+ $source = Join-Path $PWD 'calculations\report.cso.py'
80
+ $utf8 = [System.Text.UTF8Encoding]::new($false)
81
+ [Console]::OutputEncoding = $utf8
82
+ $reportText = & $cso verify $source --function calculate --input width=2 --input height=3 --format json
83
+ if ($LASTEXITCODE -ne 0) { throw 'Calculation verification failed.' }
84
+ $report = ($reportText -join "`n") | ConvertFrom-Json
85
+ if (-not $report.ok) { throw 'Resolve verification diagnostics before binding a case.' }
86
+ $binding = [ordered]@{}
87
+ foreach ($name in @('entryModuleId', 'entrySourceHash', 'sourceClosureHash', 'function', 'resolvedInputs', 'resolvedInputKinds')) {
88
+ $binding[$name] = $report.provenance.$name
89
+ }
90
+ $reference = [ordered]@{
91
+ referenceVersion = '1'
92
+ cases = @([ordered]@{
93
+ id = 'rectangle-2-by-3'
94
+ revision = '1'
95
+ basis = [ordered]@{
96
+ method = 'Hand-derived rectangle area'
97
+ derivation = 'Perpendicular sides: 2 m times 3 m equals 6 m^2.'
98
+ sourceDescription = 'Elementary geometry for the stated rectangle.'
99
+ }
100
+ binding = $binding
101
+ expected = @([ordered]@{
102
+ symbolId = '["symbol","root","area"]'
103
+ value = 6
104
+ unit = 'm^2'
105
+ })
106
+ })
107
+ }
108
+ $referencePath = Join-Path $PWD 'references\rectangle-reference.json'
109
+ $json = ($reference | ConvertTo-Json -Depth 20).Replace("`r`n", "`n") + "`n"
110
+ [System.IO.File]::WriteAllText($referencePath, $json, $utf8)
111
+ & $cso verify $source --function calculate --input width=2 --input height=3 --reference $referencePath --format json
112
+ if ($LASTEXITCODE -ne 0) { throw 'Independent reference verification failed.' }
113
+ ```
114
+ <!-- docs:reference-authoring:end -->
115
+
116
+ This writer produces UTF-8 without a BOM and uses LF. Do not use `>` or
117
+ `Out-File` to save source or JSON in Windows PowerShell 5.1; their default
118
+ encoding differs from this file format. The console encoding assignment makes
119
+ UTF-8 CLI output safe to capture before `ConvertFrom-Json`, including Unicode
120
+ paths and diagnostics.
121
+
122
+ Check that `checks.independentReferenceAgreement.status` is `passed` with one checked
123
+ symbol. To use the case in the browser, add
124
+ `"reference": "references/rectangle-reference.json"` to the starter entry in
125
+ `reports.json`, restart `npm run dev`, and calculate with width 2 and height 3.
126
+ The same `--reference` option works with `cso html` and `cso pdf`.
127
+
128
+ For a replacement calculation, establish expected values for all calculated
129
+ symbols from a cited method or independent implementation. Use the symbol IDs
130
+ from its execution evidence, exact documented units, and the binding for that
131
+ source, function and input case. Check the reference against that execution.
132
+ Different inputs need their own cases; an unmatched case is `not_applicable` in
133
+ CLI reports and remains pending in the browser.
134
+
135
+ Source edits invalidate a binding, including edits to explanation text. After
136
+ reviewing a change, explicitly revise the binding and case revision while
137
+ preserving independently established expected values. Update expected values
138
+ only when their independent derivation changes, and record why. Reference
139
+ agreement does not establish human engineering approval.
@@ -1 +1 @@
1
- cs-object==0.1.0
1
+ cs-object==0.1.1