@cs-object/cli 0.1.1 → 0.1.2

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
@@ -33,6 +33,38 @@ and 2 means invalid usage. Reports retain known source hashes, function, inputs,
33
33
  versions and diagnostics; successful HTML/PDF reports include output path and hash.
34
34
  Unknown provenance is not fabricated. See [report schemas](../../packages/cso-core/src/contracts/reports.ts).
35
35
 
36
+ ### PowerShell 5.1 and 7
37
+
38
+ Complete [repository setup](../../docs/development.md#setup), then run these
39
+ commands from its root. They use the local CLI wrapper and the installed wheel
40
+ in `.venv`. A generated project's corresponding commands are in its `authoring.md`.
41
+
42
+ <!-- docs:canonical-report:start -->
43
+ ```powershell
44
+ $env:PYTHON = Join-Path $PWD '.venv\Scripts\python.exe'
45
+ $cso = Join-Path $PWD 'packages\cso-cli\dist\cli.js'
46
+ $source = Join-Path $PWD 'examples\two-panel\estimate.cso.py'
47
+ $reference = Join-Path $PWD 'examples\two-panel\reference.json'
48
+ & node.exe $cso bindings (Join-Path $PWD 'examples\two-panel')
49
+ if ($LASTEXITCODE -ne 0) { throw 'Binding generation failed.' }
50
+ & node.exe $cso verify $source --function estimate --input width=2 --reference $reference --format json
51
+ if ($LASTEXITCODE -ne 0) { throw 'Calculation verification failed.' }
52
+ New-Item -ItemType Directory -Force (Join-Path $PWD 'output') | Out-Null
53
+ & node.exe $cso html $source --function estimate --input width=2 --reference $reference --out (Join-Path $PWD 'output\panels.html') --check-layout --format json
54
+ if ($LASTEXITCODE -ne 0) { throw 'Checked HTML generation failed.' }
55
+ & node.exe $cso pdf $source --function estimate --input width=2 --reference $reference --out (Join-Path $PWD 'output\panels.pdf') --format json
56
+ if ($LASTEXITCODE -ne 0) { throw 'PDF generation failed.' }
57
+ ```
58
+ <!-- docs:canonical-report:end -->
59
+
60
+ Keep `PYTHON` as one executable path and invoke path variables with `&`.
61
+ For a standalone install, point it at the environment containing `cs-object`.
62
+ Use `--input name=value` to avoid shell-dependent JSON quoting.
63
+ If you save stdout, select UTF-8 explicitly; the generated project's
64
+ [reference recipe](../create-cs-object/template/references/README.md#bind-an-independent-case)
65
+ shows a PowerShell 5.1/7 capture and BOM-free UTF-8/LF write. Do not use
66
+ PowerShell 5.1 redirection to write source or JSON files.
67
+
36
68
  ## Numerical checks
37
69
 
38
70
  [verifyExecution](../../packages/cso-core/src/verification/verify.ts) checks inputs,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  parseStrictJson
3
- } from "./chunk-SCZCL6WF.js";
3
+ } from "./chunk-O4PZOHKA.js";
4
4
  import {
5
5
  stringifyJson
6
- } from "./chunk-MOM6Q2VG.js";
6
+ } from "./chunk-DIYNSURK.js";
7
7
 
8
8
  // src/evidence.ts
9
9
  import {
@@ -25,7 +25,7 @@ import {
25
25
 
26
26
  // src/assets.ts
27
27
  import { readFileSync, realpathSync, statSync } from "fs";
28
- import { dirname, isAbsolute, relative, resolve } from "path";
28
+ import { dirname, isAbsolute, relative, resolve, sep } from "path";
29
29
  import { createHash } from "crypto";
30
30
  import {
31
31
  ResolvedAssetSchema
@@ -41,7 +41,7 @@ function captureAssets(sourcePath, execution) {
41
41
  resolve(root, dirname(asset.moduleId), asset.path)
42
42
  );
43
43
  const within = relative(root, path);
44
- if (within === ".." || within.startsWith("../") || isAbsolute(within))
44
+ if (within === ".." || within.startsWith(`..${sep}`) || isAbsolute(within))
45
45
  throw new Error("Asset resolves outside the entry source directory");
46
46
  if (!statSync(path).isFile())
47
47
  throw new Error("Asset is not a regular file");
@@ -39,6 +39,28 @@ function stringifyJson(value) {
39
39
  return encoded;
40
40
  }
41
41
 
42
+ // src/python-process.ts
43
+ import { spawnSync } from "child_process";
44
+ function isolatedEnvironment() {
45
+ const environment = { ...process.env };
46
+ for (const key of ["PYTHONPATH", "PYTHONHOME", "NODE_PATH"])
47
+ Reflect.deleteProperty(environment, key);
48
+ return environment;
49
+ }
50
+ function runPythonProcess({
51
+ command,
52
+ args,
53
+ ...limits
54
+ }) {
55
+ return spawnSync(
56
+ process.env.PYTHON ?? "python3",
57
+ ["-I", "-X", "utf8", "-m", "cso_python", command, ...args],
58
+ { env: isolatedEnvironment(), ...limits }
59
+ );
60
+ }
61
+
42
62
  export {
43
- stringifyJson
63
+ stringifyJson,
64
+ isolatedEnvironment,
65
+ runPythonProcess
44
66
  };
@@ -1,12 +1,13 @@
1
1
  import {
2
+ runPythonProcess,
2
3
  stringifyJson
3
- } from "./chunk-MOM6Q2VG.js";
4
+ } from "./chunk-DIYNSURK.js";
4
5
 
5
6
  // src/reports.ts
6
7
  import { CommandReportSchema } from "@cs-object/core";
7
8
 
8
9
  // package.json
9
- var version = "0.1.1";
10
+ var version = "0.1.2";
10
11
 
11
12
  // src/reports.ts
12
13
  function initialReport(command) {
@@ -165,37 +166,25 @@ function captureReference(path, execution) {
165
166
  }
166
167
 
167
168
  // src/execution.ts
168
- import { spawnSync } from "child_process";
169
169
  import {
170
170
  ExecutionResponseSchema,
171
171
  contractIssuesToDiagnostics as contractIssuesToDiagnostics2
172
172
  } from "@cs-object/core";
173
173
  var message = (error) => error instanceof Error ? error.message : String(error);
174
174
  function runPythonExecution(options, timeoutMs) {
175
- const environment = { ...process.env };
176
- for (const key of ["PYTHONPATH", "PYTHONHOME", "NODE_PATH"]) {
177
- Reflect.deleteProperty(environment, key);
178
- }
179
- const result = spawnSync(
180
- process.env.PYTHON ?? "python3",
181
- [
182
- "-I",
183
- "-m",
184
- "cso_python",
185
- "execute",
175
+ const result = runPythonProcess({
176
+ command: "execute",
177
+ args: [
186
178
  options.sourcePath,
187
179
  "--function",
188
180
  options.functionName,
189
181
  "--inputs-json",
190
182
  stringifyJson(options.inputs)
191
183
  ],
192
- {
193
- env: environment,
194
- maxBuffer: 64 * 1024 * 1024,
195
- timeout: timeoutMs,
196
- killSignal: "SIGKILL"
197
- }
198
- );
184
+ maxBuffer: 64 * 1024 * 1024,
185
+ timeout: timeoutMs,
186
+ killSignal: "SIGKILL"
187
+ });
199
188
  if (result.stderr) {
200
189
  process.stderr.write(result.stderr);
201
190
  }
@@ -8,10 +8,10 @@ import {
8
8
  renderPreparedPdf,
9
9
  retainSource,
10
10
  sha256
11
- } from "./chunk-2IRNUHX6.js";
11
+ } from "./chunk-74QLD4IY.js";
12
12
  import {
13
13
  executeAndVerify
14
- } from "./chunk-SCZCL6WF.js";
14
+ } from "./chunk-O4PZOHKA.js";
15
15
 
16
16
  // src/document.ts
17
17
  import { CommandReportSchema } from "@cs-object/core";
package/dist/cli.js CHANGED
@@ -8,10 +8,11 @@ import {
8
8
  initialReport,
9
9
  usageReport,
10
10
  verifyCommand
11
- } from "./chunk-SCZCL6WF.js";
11
+ } from "./chunk-O4PZOHKA.js";
12
12
  import {
13
+ runPythonProcess,
13
14
  stringifyJson
14
- } from "./chunk-MOM6Q2VG.js";
15
+ } from "./chunk-DIYNSURK.js";
15
16
 
16
17
  // src/cli.ts
17
18
  import { CommandReportSchema } from "@cs-object/core";
@@ -124,7 +125,6 @@ ${command2 === "pdf" ? "PDF evidence is retained at <output>.evidence/<manifest-
124
125
  }
125
126
 
126
127
  // src/bindings.ts
127
- import { spawnSync } from "child_process";
128
128
  var bindingsHelp = `Usage: cso bindings <directory> [--check]
129
129
 
130
130
  Generate importable _cso_bindings modules and typed signatures from .cso.py files.
@@ -134,15 +134,11 @@ Set PYTHON to the interpreter with cs-object installed.
134
134
  Exit codes: 0 current/generated, 1 stale/source/write failure, 2 invalid usage.
135
135
  `;
136
136
  function bindingsCommand(args2) {
137
- const environment = { ...process.env };
138
- for (const key of ["PYTHONPATH", "PYTHONHOME", "NODE_PATH"]) {
139
- Reflect.deleteProperty(environment, key);
140
- }
141
- const result = spawnSync(
142
- process.env.PYTHON ?? "python3",
143
- ["-I", "-m", "cso_python", "bindings", ...args2],
144
- { env: environment, maxBuffer: 64 * 1024 * 1024 }
145
- );
137
+ const result = runPythonProcess({
138
+ command: "bindings",
139
+ args: args2,
140
+ maxBuffer: 64 * 1024 * 1024
141
+ });
146
142
  if (result.stderr) process.stderr.write(result.stderr);
147
143
  if (result.error || result.signal) {
148
144
  process.stdout.write(
@@ -175,11 +171,11 @@ if (command === "--help" || command === void 0 || [
175
171
  "dev-render"
176
172
  ].includes(command) && args.includes("--help")) {
177
173
  process.stdout.write(
178
- command === "verify" || command === "pdf" || command === "html" ? verifiedHelp(command) : command === "dev" ? (await import("./dev-server-PBQWZU63.js")).devHelp : command === "bindings" ? bindingsHelp : help
174
+ command === "verify" || command === "pdf" || command === "html" ? verifiedHelp(command) : command === "dev" ? (await import("./dev-server-IP2WWWK2.js")).devHelp : command === "bindings" ? bindingsHelp : help
179
175
  );
180
176
  } else if (command === "dev") {
181
177
  try {
182
- const { devCommand } = await import("./dev-server-PBQWZU63.js");
178
+ const { devCommand } = await import("./dev-server-IP2WWWK2.js");
183
179
  await devCommand(args);
184
180
  } catch (error) {
185
181
  process.stderr.write(
@@ -195,10 +191,10 @@ if (command === "--help" || command === void 0 || [
195
191
  try {
196
192
  const options = parseVerifiedArgs(command, args);
197
193
  if (options.command === "html") {
198
- const { htmlCommand } = await import("./html-WL2NAGRV.js");
194
+ const { htmlCommand } = await import("./html-H5XKL7IB.js");
199
195
  outcome = await htmlCommand(options);
200
196
  } else if (options.command === "pdf") {
201
- const { pdfCommand } = await import("./pdf-AQCYVWRF.js");
197
+ const { pdfCommand } = await import("./pdf-6NJX7NN3.js");
202
198
  outcome = await pdfCommand(options);
203
199
  } else {
204
200
  outcome = verifyCommand(options);
@@ -8,12 +8,14 @@ import {
8
8
  jsonBytes,
9
9
  renderPreparedPdf,
10
10
  sha256
11
- } from "./chunk-2IRNUHX6.js";
11
+ } from "./chunk-74QLD4IY.js";
12
12
  import {
13
13
  executeAndVerify,
14
14
  parseStrictJson
15
- } from "./chunk-SCZCL6WF.js";
16
- import "./chunk-MOM6Q2VG.js";
15
+ } from "./chunk-O4PZOHKA.js";
16
+ import {
17
+ runPythonProcess
18
+ } from "./chunk-DIYNSURK.js";
17
19
 
18
20
  // src/dev-server.ts
19
21
  import {
@@ -34,7 +36,6 @@ var HttpError = class extends Error {
34
36
  };
35
37
 
36
38
  // src/dev-runtime.ts
37
- import { spawnSync } from "child_process";
38
39
  import { randomUUID } from "crypto";
39
40
  import {
40
41
  CalculationDefinitionResponseSchema
@@ -49,27 +50,13 @@ var defaults = {
49
50
  maximumAgeMs: 30 * 6e4
50
51
  };
51
52
  function describe(options) {
52
- const env = { ...process.env };
53
- for (const key of ["PYTHONPATH", "PYTHONHOME", "NODE_PATH"])
54
- Reflect.deleteProperty(env, key);
55
- const result = spawnSync(
56
- process.env.PYTHON ?? "python3",
57
- [
58
- "-I",
59
- "-m",
60
- "cso_python",
61
- "describe",
62
- options.sourcePath,
63
- "--function",
64
- options.functionName
65
- ],
66
- {
67
- env,
68
- timeout: 3e4,
69
- killSignal: "SIGKILL",
70
- maxBuffer: 4 * 1024 * 1024
71
- }
72
- );
53
+ const result = runPythonProcess({
54
+ command: "describe",
55
+ args: [options.sourcePath, "--function", options.functionName],
56
+ timeout: 3e4,
57
+ killSignal: "SIGKILL",
58
+ maxBuffer: 4 * 1024 * 1024
59
+ });
73
60
  if (result.error || result.signal)
74
61
  throw new HttpError(
75
62
  422,
@@ -3,11 +3,12 @@ import {
3
3
  parseCliArgs
4
4
  } from "./chunk-PC7UAF4D.js";
5
5
  import {
6
+ isolatedEnvironment,
7
+ runPythonProcess,
6
8
  stringifyJson
7
- } from "./chunk-MOM6Q2VG.js";
9
+ } from "./chunk-DIYNSURK.js";
8
10
 
9
11
  // src/development.ts
10
- import { spawnSync } from "child_process";
11
12
  import {
12
13
  existsSync,
13
14
  mkdirSync,
@@ -31,13 +32,6 @@ var defaultCssPath = createRequire(import.meta.url).resolve(
31
32
  "@cs-object/react/style.css"
32
33
  );
33
34
  var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
34
- function isolatedEnvironment() {
35
- const environment = { ...process.env };
36
- Reflect.deleteProperty(environment, "NODE_PATH");
37
- Reflect.deleteProperty(environment, "PYTHONPATH");
38
- Reflect.deleteProperty(environment, "PYTHONHOME");
39
- return environment;
40
- }
41
35
  function writeAtomically(outPath, bytes) {
42
36
  mkdirSync(dirname(outPath), { recursive: true });
43
37
  const temporary = join(
@@ -56,37 +50,31 @@ var runPythonExporter = ({
56
50
  inputs,
57
51
  sourcePath
58
52
  }) => {
59
- const result = spawnSync(
60
- process.env.PYTHON ?? "python3",
61
- [
62
- "-I",
63
- "-m",
64
- "cso_python",
65
- "export",
53
+ const result = runPythonProcess({
54
+ command: "export",
55
+ args: [
66
56
  sourcePath,
67
57
  "--function",
68
58
  functionName,
69
59
  "--inputs-json",
70
60
  stringifyJson(inputs)
71
61
  ],
72
- {
73
- encoding: "utf8",
74
- env: isolatedEnvironment(),
75
- maxBuffer: 32 * 1024 * 1024
76
- }
77
- );
62
+ maxBuffer: 32 * 1024 * 1024
63
+ });
78
64
  if (result.error) {
79
65
  throw result.error;
80
66
  }
81
67
  if (result.status !== 0) {
82
- const message = result.stderr.trim() || "Python exporter failed";
68
+ const message = result.stderr.toString("utf8").trim() || "Python exporter failed";
83
69
  if (result.status === 2) throw new UsageError(message);
84
70
  throw new Error(message);
85
71
  }
86
72
  if (result.stderr) {
87
73
  process.stderr.write(result.stderr);
88
74
  }
89
- return CalculationSourceObjectSchema.parse(JSON.parse(result.stdout));
75
+ return CalculationSourceObjectSchema.parse(
76
+ JSON.parse(result.stdout.toString("utf8"))
77
+ );
90
78
  };
91
79
  var renderFormulaSheetHtml = (sheet, { css, title }) => {
92
80
  const sheetMarkup = renderToStaticMarkup(
@@ -0,0 +1,9 @@
1
+ import {
2
+ documentCommand
3
+ } from "./chunk-PXJXS4ZR.js";
4
+ import "./chunk-74QLD4IY.js";
5
+ import "./chunk-O4PZOHKA.js";
6
+ import "./chunk-DIYNSURK.js";
7
+ export {
8
+ documentCommand as htmlCommand
9
+ };
@@ -0,0 +1,9 @@
1
+ import {
2
+ documentCommand
3
+ } from "./chunk-PXJXS4ZR.js";
4
+ import "./chunk-74QLD4IY.js";
5
+ import "./chunk-O4PZOHKA.js";
6
+ import "./chunk-DIYNSURK.js";
7
+ export {
8
+ documentCommand as pdfCommand
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cs-object/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Installed calculation verification and development export/render commands.",
@@ -1,9 +0,0 @@
1
- import {
2
- documentCommand
3
- } from "./chunk-KZZ2NIR7.js";
4
- import "./chunk-2IRNUHX6.js";
5
- import "./chunk-SCZCL6WF.js";
6
- import "./chunk-MOM6Q2VG.js";
7
- export {
8
- documentCommand as htmlCommand
9
- };
@@ -1,9 +0,0 @@
1
- import {
2
- documentCommand
3
- } from "./chunk-KZZ2NIR7.js";
4
- import "./chunk-2IRNUHX6.js";
5
- import "./chunk-SCZCL6WF.js";
6
- import "./chunk-MOM6Q2VG.js";
7
- export {
8
- documentCommand as pdfCommand
9
- };