create-cs-object 0.1.1 → 0.1.3
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 +47 -2
- package/dist/cli.js +29 -2
- package/package.json +5 -2
- package/template/.gitattributes +2 -0
- package/template/AGENTS.md +11 -2
- package/template/README.md +60 -2
- package/template/authoring.md +247 -18
- package/template/components.json +25 -0
- package/template/gitignore +1 -0
- package/template/index.html +12 -0
- package/template/references/README.md +134 -0
- package/template/reports.json +8 -0
- package/template/scripts/dev.ts +104 -33
- package/template/scripts/reports.ts +24 -0
- package/template/src/App.tsx +681 -0
- package/template/src/components/theme-provider.tsx +230 -0
- package/template/src/components/ui/badge.tsx +51 -0
- package/template/src/components/ui/button.tsx +55 -0
- package/template/src/components/ui/card.tsx +102 -0
- package/template/src/components/ui/dropdown-menu.tsx +274 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/label.tsx +17 -0
- package/template/src/components/ui/separator.tsx +22 -0
- package/template/src/components/ui/sheet.tsx +137 -0
- package/template/src/hooks/use-mobile.ts +19 -0
- package/template/src/index.css +131 -0
- package/template/src/lib/utils.ts +1 -0
- package/template/src/main.tsx +9 -0
- package/template/tsconfig.app.json +29 -0
- package/template/tsconfig.json +12 -0
- package/template/tsconfig.node.json +24 -0
- package/template/vite.config.ts +144 -0
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.
|
|
@@ -16,8 +53,16 @@ Existing destinations are never overwritten.
|
|
|
16
53
|
|
|
17
54
|
Use `--skip-install` to create files without installing dependencies.
|
|
18
55
|
The generated project contains a synthetic rectangle calculation, an editable
|
|
19
|
-
brief, reference storage, and agent-neutral authoring guidance.
|
|
20
|
-
|
|
56
|
+
brief, reference storage, and agent-neutral authoring guidance. Its editable
|
|
57
|
+
React and TypeScript page uses Vite, Tailwind and the selected shadcn preset.
|
|
58
|
+
`npm run dev` starts that page and the CLI calculation and report API on localhost.
|
|
59
|
+
The initializer contains no calculation server implementation.
|
|
60
|
+
The page's navbar report menu reads `reports.json`; each configured report runs
|
|
61
|
+
through its own local CLI process.
|
|
21
62
|
|
|
22
63
|
Package tests execute a real npm archive in a temporary consumer. Full runtime
|
|
23
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
|
@@ -37,9 +37,36 @@ try {
|
|
|
37
37
|
engines: { node: ">=24" },
|
|
38
38
|
scripts: {
|
|
39
39
|
setup: "npm install && node scripts/setup.ts",
|
|
40
|
-
dev: "node scripts/dev.ts"
|
|
40
|
+
dev: "node scripts/dev.ts",
|
|
41
|
+
build: "tsc -b && vite build",
|
|
42
|
+
typecheck: "tsc -b --pretty false"
|
|
41
43
|
},
|
|
42
|
-
dependencies: {
|
|
44
|
+
dependencies: {
|
|
45
|
+
"@cs-object/cli": "0.1.1",
|
|
46
|
+
"@cs-object/core": "0.1.0",
|
|
47
|
+
"@base-ui/react": "^1.8.0",
|
|
48
|
+
"@fontsource-variable/geist-mono": "^5.3.0",
|
|
49
|
+
"@fontsource-variable/raleway": "^5.3.0",
|
|
50
|
+
"@hugeicons/core-free-icons": "^4.3.5",
|
|
51
|
+
"@hugeicons/react": "^1.1.10",
|
|
52
|
+
"@tailwindcss/vite": "^4",
|
|
53
|
+
"class-variance-authority": "^0.7.1",
|
|
54
|
+
cn: "^0.4.0",
|
|
55
|
+
react: "^19.2.8",
|
|
56
|
+
"react-dom": "^19.2.8",
|
|
57
|
+
shadcn: "^4.21.0",
|
|
58
|
+
tailwindcss: "^4",
|
|
59
|
+
"tw-animate-css": "^1.4.0",
|
|
60
|
+
vite: "^8",
|
|
61
|
+
zod: "^4.6.5"
|
|
62
|
+
},
|
|
63
|
+
devDependencies: {
|
|
64
|
+
"@types/node": "^24",
|
|
65
|
+
"@types/react": "^19",
|
|
66
|
+
"@types/react-dom": "^19",
|
|
67
|
+
"@vitejs/plugin-react": "^6",
|
|
68
|
+
typescript: "^5"
|
|
69
|
+
}
|
|
43
70
|
},
|
|
44
71
|
null,
|
|
45
72
|
2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cs-object",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Create a local CalculationSourceObject report project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -30,9 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@biomejs/biome": "2.5.14",
|
|
33
|
+
"@cs-object/core": "0.1.0",
|
|
33
34
|
"@types/node": "^26",
|
|
34
35
|
"tsup": "^8.5.1",
|
|
35
|
-
"typescript": "^5"
|
|
36
|
+
"typescript": "^5",
|
|
37
|
+
"vite": "^8.3.1",
|
|
38
|
+
"zod": "^4.6.5"
|
|
36
39
|
},
|
|
37
40
|
"repository": {
|
|
38
41
|
"type": "git",
|
package/template/AGENTS.md
CHANGED
|
@@ -6,12 +6,21 @@ the result, units, load case, or acceptance criteria. Record the agreed scope
|
|
|
6
6
|
in the brief and cite the source of each engineering requirement.
|
|
7
7
|
|
|
8
8
|
Edit formulas in `calculations/report.cso.py`; the browser edits numeric inputs.
|
|
9
|
+
Edit page layout in `src/App.tsx`, theme tokens in `src/index.css`, and shared UI
|
|
10
|
+
components in `src/components/ui/`. Keep numeric input names and validation
|
|
11
|
+
derived from the Python definition. Add shadcn components with
|
|
12
|
+
`npx shadcn@latest add <component>`.
|
|
13
|
+
Add each runnable report to `reports.json` with a unique ID, title, source path
|
|
14
|
+
and entry function. Restart the local server to update the report menu.
|
|
9
15
|
Read [authoring.md](authoring.md) before changing source or notation. Keep inputs,
|
|
10
16
|
units, assumptions, intermediate steps, references, and outputs inspectable.
|
|
11
17
|
|
|
12
|
-
|
|
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.
|
|
13
21
|
Report source-to-document consistency, independent numerical agreement, and
|
|
14
22
|
human engineering approval separately. Establish expected reference values
|
|
15
|
-
independently of the execution under test.
|
|
23
|
+
independently of the execution under test. When delivering a PDF, inspect every
|
|
24
|
+
page before delivery.
|
|
16
25
|
|
|
17
26
|
This project runs on localhost. Deployment is outside its calculation workflow.
|
package/template/README.md
CHANGED
|
@@ -7,12 +7,56 @@ 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
|
|
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
|
|
|
20
|
+
Customize the page in `src/App.tsx` and its theme in `src/index.css`. The
|
|
21
|
+
components in `src/components/ui/` are owned by this project. To add another
|
|
22
|
+
shadcn component, run `npx shadcn@latest add <component>` and edit the page to
|
|
23
|
+
use it. `components.json` records the chosen Vite, Base UI and Lyra preset.
|
|
24
|
+
The input fields still come from the Python definition; page edits do not change
|
|
25
|
+
the calculation or API validation. `npm run build` checks and builds the Vite
|
|
26
|
+
frontend, but the local API and PDF routes still require `npm run dev`.
|
|
27
|
+
|
|
28
|
+
The navbar menu lists runnable reports from [reports.json](reports.json).
|
|
29
|
+
To add one, put its `.cso.py` source under `calculations/` and add an entry with
|
|
30
|
+
a unique URL-safe `id`, a display `title`, the relative `source` path and its
|
|
31
|
+
entry `function`. Add `reference` when the report has an independent numerical
|
|
32
|
+
reference file. Restart `npm run dev` after editing the list. Each entry gets
|
|
33
|
+
its own verified local API at `/api/reports/<id>/`; the menu switches between
|
|
34
|
+
them without changing the input or report UI code.
|
|
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
|
+
|
|
16
60
|
To choose a port, run `npm run dev -- --port 4173`. Use port `0` to select an
|
|
17
61
|
available port. Stop the server with Ctrl+C and use the same command to restart.
|
|
18
62
|
|
|
@@ -20,6 +64,20 @@ If setup failed or you used `--skip-install`, run `npm run setup`.
|
|
|
20
64
|
Set `PYTHON` to a Python executable if automatic detection cannot find Python
|
|
21
65
|
3.11 or newer. Setup can be run again without replacing calculation files.
|
|
22
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
|
+
|
|
23
81
|
Before replacing the starter, update [the brief](brief.md), collect
|
|
24
82
|
[references](references/README.md), and read [the authoring notes](authoring.md).
|
|
25
83
|
Source-to-document consistency checks that the documented formulas agree with
|
package/template/authoring.md
CHANGED
|
@@ -1,18 +1,247 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
# Author calculations
|
|
2
|
+
|
|
3
|
+
This guide ships with the generated project. Write constrained Python in
|
|
4
|
+
`calculations/*.cso.py`; the installed `cs-object` package captures the same
|
|
5
|
+
source for numerical execution and the report. Start with
|
|
6
|
+
[`calculations/report.cso.py`](calculations/report.cso.py), then replace the
|
|
7
|
+
rectangle example with the calculation in [brief.md](brief.md). Keep the
|
|
8
|
+
brief, sources and reviewable report consistent.
|
|
9
|
+
|
|
10
|
+
## Before writing formulas
|
|
11
|
+
|
|
12
|
+
State the purpose, input ranges, units, assumptions, required outputs and
|
|
13
|
+
acceptance cases in [brief.md](brief.md). Keep source documents or links under
|
|
14
|
+
[`references/`](references/README.md), with the edition, page or clause and the
|
|
15
|
+
assumption each supports. Ask for a decision when a missing assumption would
|
|
16
|
+
change the result. Establish expected numerical values independently of the
|
|
17
|
+
calculation being checked; formula agreement alone does not establish
|
|
18
|
+
engineering correctness.
|
|
19
|
+
|
|
20
|
+
## Define a report
|
|
21
|
+
|
|
22
|
+
The starter shows the full pattern:
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from typing import Annotated
|
|
26
|
+
from cso_python import calculation, section, symbol, text
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@calculation(id="rectangle-area", title="Rectangle area")
|
|
30
|
+
@section(title="Rectangle", root=True)
|
|
31
|
+
def calculate(
|
|
32
|
+
width: Annotated[float, symbol(glyph="w_{rect}", description="Rectangle width", unit="m")] = 2.0,
|
|
33
|
+
height: Annotated[float, symbol(glyph="h_{rect}", description="Rectangle height", unit="m")] = 3.0,
|
|
34
|
+
):
|
|
35
|
+
text(id="assumptions", content="Assume perpendicular sides and positive dimensions. The qualifier rect means rectangle.")
|
|
36
|
+
text(id="reference", content="Area equals width multiplied by height; see brief.md for the project scope.")
|
|
37
|
+
area: Annotated[float, symbol(glyph="A_{rect}", description="Rectangle area", unit="m^2")] = width * height
|
|
38
|
+
return {"area": area}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each runnable function needs `@calculation`, `@section`, documented numeric
|
|
42
|
+
parameters and a final dictionary of public results. Put arithmetic in
|
|
43
|
+
annotated assignments before the return. The return selects existing
|
|
44
|
+
quantities; it does not replace their documented formula rows. Source order
|
|
45
|
+
sets report order, while return order sets the public output order. Intermediate
|
|
46
|
+
annotated quantities remain in the report even when they are not returned.
|
|
47
|
+
|
|
48
|
+
Use descriptive Python names such as `total_area`, not one-letter identifiers.
|
|
49
|
+
Give every quantity a glyph, description and unit. Qualify variable glyphs,
|
|
50
|
+
including diagram labels: `A_{rect}`, `w_{pan}` and `\rho_{mat}` distinguish
|
|
51
|
+
their meanings. Explain qualifiers in the report. Standard unit symbols such as
|
|
52
|
+
`m` and `kg` need no qualifier. Use raw strings for backslash Greek names,
|
|
53
|
+
for example `r"\rho_{mat}"`. The notation parser is not a LaTeX engine:
|
|
54
|
+
`\mathrm` and `\frac` are unsupported. When reproducing an identified
|
|
55
|
+
external calculation, its original glyphs may be retained with a recorded
|
|
56
|
+
source URL and explanation of any repeated notation.
|
|
57
|
+
|
|
58
|
+
Signature metadata creates an input row, including when the parameter is not
|
|
59
|
+
used in a formula. A plain `float` or `int` parameter instead needs one
|
|
60
|
+
annotated `given(parameter)` assignment; do not document the same parameter
|
|
61
|
+
both ways. Give inputs finite literal defaults. Declare `float` when division
|
|
62
|
+
or another operation can produce a fractional value. An `int` declaration
|
|
63
|
+
requires an actual Python integer; a `float` declaration accepts finite
|
|
64
|
+
Python integers and floats. Exact integers must fit within ±(2**53 - 1);
|
|
65
|
+
finite Python floats may use the binary64 range. Booleans are not numeric
|
|
66
|
+
inputs or results. Execution preserves the actual numeric kind and does not
|
|
67
|
+
coerce values to satisfy an annotation.
|
|
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
|
+
|
|
75
|
+
## Supported formulas and content
|
|
76
|
+
|
|
77
|
+
Supported expressions include finite numeric literals, earlier documented
|
|
78
|
+
quantities, unary minus, `+`, `-`, `*`, `/`, `**`, `sqrt`, `math.pi`, `ceil`,
|
|
79
|
+
`floor`, `exp`, `log`, `abs`, `min`, `max`, `round`, trigonometric functions,
|
|
80
|
+
`atan2` and `hypot`. Import math functions from `math` or call them through
|
|
81
|
+
`math`. Trigonometric functions use radians; declare angle units explicitly.
|
|
82
|
+
`log(value)` is natural logarithm. `round` follows Python's ties-to-even
|
|
83
|
+
behavior for represented binary64 values. Invalid domains and non-finite
|
|
84
|
+
results fail verification.
|
|
85
|
+
|
|
86
|
+
Numeric conditional expressions can use `<`, `<=`, `>`, `>=`, `==`, `!=`,
|
|
87
|
+
comparison chains and `and` / `or` between comparisons. Only the chosen
|
|
88
|
+
numeric branch executes. Bare numeric conditions, boolean quantities,
|
|
89
|
+
`value or fallback`, iterable or keyword forms of `min` / `max` / `hypot`,
|
|
90
|
+
and arbitrary Python statements are outside the supported source subset.
|
|
91
|
+
Run the calculation to detect unsupported syntax; a valid Python expression
|
|
92
|
+
is not necessarily a supported documented formula. This is trusted local
|
|
93
|
+
authoring, not a sandbox for untrusted Python.
|
|
94
|
+
|
|
95
|
+
Place literal `text(id=..., content=...)` calls beside the formulas they
|
|
96
|
+
explain. Document assumptions, limits and reference clauses in the report,
|
|
97
|
+
not only in comments. `figure(...)` accepts a module-relative PNG, JPEG or
|
|
98
|
+
SVG path, caption and alt text. Keep the asset inside the calculation
|
|
99
|
+
directory, for example `calculations/assets/section.svg`:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from cso_python import figure
|
|
103
|
+
|
|
104
|
+
figure(
|
|
105
|
+
id="section-diagram",
|
|
106
|
+
path="assets/section.svg",
|
|
107
|
+
media_type="image/svg+xml",
|
|
108
|
+
caption="Section dimensions and axes",
|
|
109
|
+
alt="Dimensioned section with x and y axes",
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Missing or invalid assets fail instead of silently disappearing. A
|
|
114
|
+
`with document_section(id="...", title="..."):` block can group one level
|
|
115
|
+
of symbols, text and figures. Nested groups, calculation calls and returns
|
|
116
|
+
do not belong inside that block.
|
|
117
|
+
|
|
118
|
+
## Reuse calculations
|
|
119
|
+
|
|
120
|
+
Keep common `Annotated` metadata or `TypeAlias` declarations in a local
|
|
121
|
+
Python module, then use the same alias for a quantity passed between
|
|
122
|
+
calculations. Generate typed handles before importing another `.cso.py`
|
|
123
|
+
function:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
./.venv/bin/python -m cso_python bindings calculations
|
|
127
|
+
./.venv/bin/python -m cso_python bindings calculations --check
|
|
128
|
+
```
|
|
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
|
+
|
|
142
|
+
For a file `calculations/geometry.cso.py` with a public function
|
|
143
|
+
`rectangle`, a parent in that directory can import and call it:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from _cso_bindings.geometry import rectangle
|
|
147
|
+
|
|
148
|
+
first_panel = rectangle(width=width, height=first_panel_height)
|
|
149
|
+
second_panel = rectangle(width=width, height=second_panel_height)
|
|
150
|
+
total_area: TotalPanelArea = first_panel["area"] + second_panel["area"]
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`TotalPanelArea` must be declared in the shared metadata module. Calls take
|
|
154
|
+
named arguments. Each call adds a child section at its source location;
|
|
155
|
+
documented intermediate results stay visible even if the child does not
|
|
156
|
+
select them as public outputs. Forwarded quantities retain their identity,
|
|
157
|
+
description, glyph and unit. Callee units must match exactly; write an
|
|
158
|
+
explicit annotated conversion when needed. Equal numeric values do not make
|
|
159
|
+
two quantities identical.
|
|
160
|
+
|
|
161
|
+
Generate bindings from a directory containing the parent and its local
|
|
162
|
+
dependencies. Source paths below it must use Python identifiers, such as
|
|
163
|
+
`steel_sections/calculate.cso.py`. Imports follow those paths. The generated
|
|
164
|
+
`_cso_bindings/` directory must exist at runtime; do not edit its files.
|
|
165
|
+
Regenerate after changing parameters, numeric declarations, defaults,
|
|
166
|
+
metadata or public output selections. Formula-only edits may leave the
|
|
167
|
+
interface current. Generation validates definitions but does not execute
|
|
168
|
+
formulas. A missing or stale handle will not regenerate itself.
|
|
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
|
+
|
|
175
|
+
Each distinct quantity needs distinct displayed notation. Repeated child
|
|
176
|
+
calls qualify child glyphs using their call names. When a reference
|
|
177
|
+
deliberately reuses a glyph in separate contexts, set a meaningful
|
|
178
|
+
`notation_scope` in `symbol(...)` and explain that scope in a description or
|
|
179
|
+
section title. Collisions within one scope fail.
|
|
180
|
+
|
|
181
|
+
## Check the result
|
|
182
|
+
|
|
183
|
+
Add each top-level runnable function to [reports.json](reports.json) with its
|
|
184
|
+
ID, title, source path and function name, then restart `npm run dev`. The
|
|
185
|
+
browser derives editable inputs from the Python definition and calls the
|
|
186
|
+
verified local API. Recalculate with representative and boundary inputs.
|
|
187
|
+
Review every input, unit, intermediate formula, explanation, figure and
|
|
188
|
+
returned result in the report. Check that the displayed substitutions and
|
|
189
|
+
outputs match the intended engineering method.
|
|
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
|
+
|
|
232
|
+
Keep three judgments separate: source-to-document consistency, agreement
|
|
233
|
+
with independently established numerical cases, and human engineering
|
|
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).
|
|
237
|
+
Formula or text edits change captured source identity and can invalidate
|
|
238
|
+
reference bindings; review and explicitly rebind them while preserving
|
|
239
|
+
independently established expected values. Never obtain expected values by
|
|
240
|
+
copying the execution being tested.
|
|
241
|
+
|
|
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.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "base-lyra",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/index.css",
|
|
9
|
+
"baseColor": "taupe",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"iconLibrary": "hugeicons",
|
|
14
|
+
"rtl": false,
|
|
15
|
+
"aliases": {
|
|
16
|
+
"components": "@/components",
|
|
17
|
+
"utils": "@/lib/utils",
|
|
18
|
+
"ui": "@/components/ui",
|
|
19
|
+
"lib": "@/lib",
|
|
20
|
+
"hooks": "@/hooks"
|
|
21
|
+
},
|
|
22
|
+
"menuColor": "default-translucent",
|
|
23
|
+
"menuAccent": "subtle",
|
|
24
|
+
"registries": {}
|
|
25
|
+
}
|
package/template/gitignore
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Calculation report</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|