@sentisec/sdk 1.1.0 → 1.1.1

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/CHANGELOG.md CHANGED
@@ -14,6 +14,23 @@ Versions that were prepared but never reached npm are listed under
14
14
 
15
15
  ## [Unreleased]
16
16
 
17
+ ## [1.1.1] — 2026-12-04
18
+
19
+ ### Fixed
20
+
21
+ - **`npm install @sentisec/sdk` gets the `sentisec` CLI when `python3` is
22
+ too new.** The install step chooses a Python the CLI is built for, in the
23
+ same order as the one-line install: `SENTISEC_PYTHON` when set; `python3`
24
+ when its version is supported; else the newest of `python3.14`,
25
+ `python3.13`, `python3.12`, `python3.11` on `PATH`. It says which one it
26
+ chose and, when that is not `python3`, why. With none of them, it says
27
+ what it found and what is supported, and the library still installs.
28
+ - **`sentisec` keeps running on the Python chosen at install.** The
29
+ launcher runs the CLI with that interpreter, recorded in
30
+ `native/<platform>/<arch>/interpreter.json`, instead of whatever
31
+ `python3` names at run time; if that Python is removed, it says so and
32
+ names `npm rebuild -g @sentisec/sdk`. The `PYMINOR` file is gone.
33
+
17
34
  ## [1.1.0] — 2026-11-22
18
35
 
19
36
  ### Added
package/bin/sentisec.js CHANGED
@@ -1,17 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  // @sentisec/sdk → bin/sentisec
3
- // Delegates to the native Sentisec CLI binary installed by
4
- // scripts/install-binary.js (npm postinstall) into
5
- // node_modules/@sentisec/sdk/native/<platform>/<arch>/<pyminor>/sentisec.
3
+ // Runs the native Sentisec CLI that scripts/install-binary.js (npm
4
+ // postinstall) placed in
5
+ // node_modules/@sentisec/sdk/native/<platform>/<arch>/<pyminor>/sentisec,
6
+ // with the interpreter that script chose and recorded in
7
+ // native/<platform>/<arch>/interpreter.json — never with whatever python3
8
+ // names at run time.
6
9
  //
7
- // Soft-fail surface: if the binary is missing (e.g., the postinstall
8
- // soft-failed because python3 was unavailable, the platform/python tuple
9
- // wasn't published, or the user set SENTISEC_SKIP_POSTINSTALL), print a
10
- // clear recovery message and exit 1. The library import path
11
- // (`import { SentisecClient } from '@sentisec/sdk'`) is unaffected.
10
+ // Soft-fail surface: if the CLI or its interpreter is missing (e.g., the
11
+ // postinstall found no supported Python, the platform/python tuple wasn't
12
+ // published, the user set SENTISEC_SKIP_POSTINSTALL, or the chosen Python
13
+ // was uninstalled since), print a clear recovery message and exit 1. The
14
+ // library import path (`import { SentisecClient } from '@sentisec/sdk'`) is
15
+ // unaffected.
12
16
 
13
17
  import { spawn } from "node:child_process";
14
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
18
+ import { existsSync, readFileSync } from "node:fs";
15
19
  import { dirname, join } from "node:path";
16
20
  import { fileURLToPath } from "node:url";
17
21
 
@@ -26,6 +30,7 @@ const SUPPORTED_ARCHES = new Set(["arm64", "x64"]);
26
30
  const platform = process.platform;
27
31
  const arch = process.arch;
28
32
 
33
+ /** @param {string} reason @returns {never} */
29
34
  function printRecoveryAndExit(reason) {
30
35
  const lines = [
31
36
  `[sentisec] ${reason}`,
@@ -38,7 +43,7 @@ function printRecoveryAndExit(reason) {
38
43
  `[sentisec] pipx install sentisec-sdk`,
39
44
  `[sentisec]`,
40
45
  `[sentisec] Or re-run the npm postinstall after fixing the root cause:`,
41
- `[sentisec] npm rebuild @sentisec/sdk`,
46
+ `[sentisec] npm rebuild -g @sentisec/sdk (without -g for a project install)`,
42
47
  ];
43
48
  process.stderr.write(lines.join("\n") + "\n");
44
49
  process.exit(1);
@@ -60,65 +65,46 @@ if (!existsSync(nativeRoot)) {
60
65
  );
61
66
  }
62
67
 
63
- // Resolve which python-minor was installed. Prefer the PYMINOR marker file
64
- // written by install-binary.js; fall back to the highest py-minor directory
65
- // present (so the shim still works if a maintainer hand-dropped a binary).
66
- function resolvePyMinor() {
67
- const markerPath = join(nativeRoot, "PYMINOR");
68
- if (existsSync(markerPath)) {
69
- try {
70
- const value = readFileSync(markerPath, "utf8").trim();
71
- if (/^\d+\.\d+$/.test(value)) return value;
72
- } catch {
73
- // fall through to scan
74
- }
75
- }
76
- // Scan native/<platform>/<arch>/ for `3.11` / `3.12` / `3.13` subdirs.
77
- let candidates;
68
+ // Written by scripts/install-binary.js: { "python": <path>, "minor": "3.13" }.
69
+ const INTERPRETER_MARKER = "interpreter.json";
70
+
71
+ function readInterpreter() {
78
72
  try {
79
- candidates = readdirSync(nativeRoot).filter(
80
- (name) =>
81
- /^3\.\d+$/.test(name) &&
82
- (() => {
83
- try {
84
- return statSync(join(nativeRoot, name)).isDirectory();
85
- } catch {
86
- return false;
87
- }
88
- })()
89
- );
73
+ const data = JSON.parse(readFileSync(join(nativeRoot, INTERPRETER_MARKER), "utf8"));
74
+ if (typeof data?.python === "string" && /^\d+\.\d+$/.test(data?.minor ?? "")) {
75
+ return data;
76
+ }
90
77
  } catch {
91
- return null;
78
+ // missing or unreadable: reported below
92
79
  }
93
- if (candidates.length === 0) return null;
94
- // Highest minor wins (e.g., 3.13 > 3.12 > 3.11).
95
- candidates.sort((a, b) => {
96
- const am = parseInt(a.split(".")[1], 10);
97
- const bm = parseInt(b.split(".")[1], 10);
98
- return bm - am;
99
- });
100
- return candidates[0];
80
+ return null;
101
81
  }
102
82
 
103
- const pyMinor = resolvePyMinor();
104
- if (!pyMinor) {
83
+ const interpreter = readInterpreter();
84
+ if (!interpreter) {
105
85
  printRecoveryAndExit(
106
- `No installed CLI binary found under ${nativeRoot}. ` +
107
- `The npm postinstall fetcher did not place a binary here.`
86
+ `No installed CLI found under ${nativeRoot}: ${INTERPRETER_MARKER} is missing. ` +
87
+ `The npm postinstall did not place the CLI here.`
108
88
  );
109
89
  }
110
90
 
111
- const binaryPath = join(nativeRoot, pyMinor, "sentisec");
91
+ const binaryPath = join(nativeRoot, interpreter.minor, "sentisec");
112
92
  if (!existsSync(binaryPath)) {
93
+ printRecoveryAndExit(`Native CLI binary missing at ${binaryPath}.`);
94
+ }
95
+ if (!existsSync(interpreter.python)) {
113
96
  printRecoveryAndExit(
114
- `Native CLI binary missing at ${binaryPath}. ` +
115
- `The PYMINOR marker (${pyMinor}) points at a non-existent install.`
97
+ `The Python chosen at install, ${interpreter.python}, is no longer there.`
116
98
  );
117
99
  }
118
100
 
119
- const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
101
+ const child = spawn(interpreter.python, [binaryPath, ...process.argv.slice(2)], {
102
+ stdio: "inherit",
103
+ });
120
104
  child.on("error", (err) => {
121
- process.stderr.write(`[sentisec] Failed to launch ${binaryPath}: ${err.message}\n`);
105
+ process.stderr.write(
106
+ `[sentisec] Failed to launch ${interpreter.python} ${binaryPath}: ${err.message}\n`
107
+ );
122
108
  process.exit(1);
123
109
  });
124
110
  child.on("exit", (code, signal) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentisec/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Sentisec TypeScript SDK — cognitive integrity monitoring for autonomous agents. Monitor + wrap(...) for OpenAI / Anthropic agent loops with SSE streaming support.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -2,20 +2,23 @@
2
2
  // @sentisec/sdk → scripts/install-binary.js
3
3
  // npm postinstall fetcher for the Sentisec CLI native binary.
4
4
  //
5
- // Behavior contract (mission card P-INST-04):
6
- // * Downloads the right tarball from GitHub Releases for the host
7
- // (platform, arch, python-minor) triple.
8
- // * Verifies sha256 against sha256sums.txt (mandatory).
5
+ // Behavior contract:
6
+ // * Chooses a Python the CLI is built for, in the one-line installer's
7
+ // order: SENTISEC_PYTHON when set; python3 when its version is
8
+ // supported; else the newest supported python3.<minor> on PATH; else a
9
+ // refusal naming what was found and what is supported.
10
+ // * Downloads the right tarball for the host (platform, arch, python-minor)
11
+ // triple and verifies sha256 against sha256sums.txt (mandatory).
9
12
  // * Extracts to node_modules/@sentisec/sdk/native/<platform>/<arch>/<pyminor>/
10
- // and writes a sibling PYMINOR marker file for bin/sentisec.js.
13
+ // and writes native/<platform>/<arch>/interpreter.json: the chosen
14
+ // interpreter, which bin/sentisec.js runs the CLI with.
11
15
  // * Zero external runtime deps. Uses node:https + node:crypto + spawned tar.
12
16
  //
13
17
  // Soft-fail policy (exit 0, npm install succeeds, library still usable):
14
18
  // * SENTISEC_SKIP_POSTINSTALL truthy → dev override
15
19
  // * CI && !SENTISEC_NPM_FETCH_IN_CI truthy → CI caches stay clean
16
20
  // * unsupported platform / arch → leave SDK as library-only
17
- // * python3 not on PATH → user can install python3 later
18
- // * python minor not in {3.11, 3.12, 3.13, 3.14} → no binary for their python
21
+ // * no supported Python found → user can install one later
19
22
  // * network failure (DNS / timeout / 5xx) → try again next install
20
23
  // * tuple missing from latest-versions.json → that cell didn't build
21
24
  //
@@ -25,16 +28,19 @@
25
28
  import { spawnSync } from "node:child_process";
26
29
  import { createHash } from "node:crypto";
27
30
  import {
31
+ accessSync,
28
32
  chmodSync,
33
+ constants as fsConstants,
29
34
  createWriteStream,
30
35
  existsSync,
31
36
  mkdirSync,
32
37
  readFileSync,
33
38
  rmSync,
39
+ statSync,
34
40
  writeFileSync,
35
41
  } from "node:fs";
36
42
  import { tmpdir } from "node:os";
37
- import { dirname, join } from "node:path";
43
+ import { delimiter, dirname, join } from "node:path";
38
44
  import { pipeline } from "node:stream/promises";
39
45
  import { fileURLToPath, URL } from "node:url";
40
46
  import https from "node:https";
@@ -56,7 +62,19 @@ const SUPPORTED_ARCHES = {
56
62
  arm64: "arm64",
57
63
  x64: "x64",
58
64
  };
59
- const SUPPORTED_PY_MINORS = new Set(["3.11", "3.12", "3.13", "3.14"]);
65
+ // The Python minors the CLI is built for, newest first. The only place they
66
+ // are written in this package.
67
+ const SUPPORTED_PY_MINORS = ["3.14", "3.13", "3.12", "3.11"];
68
+ const NEWEST_PY = SUPPORTED_PY_MINORS[0];
69
+ const SUPPORTED_RANGE = `${SUPPORTED_PY_MINORS.at(-1)} to ${NEWEST_PY}`;
70
+
71
+ // Read by bin/sentisec.js: { "python": <interpreter path>, "minor": "3.13" }.
72
+ const INTERPRETER_MARKER = "interpreter.json";
73
+
74
+ // The command that re-runs this script, for a global or a project install.
75
+ const REBUILD = `npm rebuild${
76
+ process.env.npm_config_global === "true" ? " -g" : ""
77
+ } @sentisec/sdk`;
60
78
 
61
79
  // Public release mirror. Cloudflare R2 (sentisec-releases bucket, public,
62
80
  // served by Pages at https://releases.sentisec.ch). The release-cli.yml
@@ -77,12 +95,14 @@ const SOFT_FAIL_RECOVERY = [
77
95
  `${LOG_PREFIX} pipx install sentisec-sdk`,
78
96
  ].join("\n");
79
97
 
98
+ /** @param {string} reason @returns {never} */
80
99
  function softFail(reason) {
81
100
  warn(reason);
82
101
  process.stderr.write(SOFT_FAIL_RECOVERY + "\n");
83
102
  process.exit(0);
84
103
  }
85
104
 
105
+ /** @param {string} reason @returns {never} */
86
106
  function hardFail(reason) {
87
107
  warn(`FATAL: ${reason}`);
88
108
  process.exit(1);
@@ -120,38 +140,111 @@ if (!platformName || !archName) {
120
140
  }
121
141
  const platformKey = `${platformName}-${archName}`;
122
142
 
123
- // --- detect python3 ------------------------------------------------------
143
+ // --- choose a python -----------------------------------------------------
144
+
145
+ // The first executable file called `name` on PATH, or null.
146
+ function findOnPath(name) {
147
+ for (const dir of (process.env.PATH || "").split(delimiter)) {
148
+ if (!dir) continue;
149
+ const candidate = join(dir, name);
150
+ try {
151
+ if (!statSync(candidate).isFile()) continue;
152
+ accessSync(candidate, fsConstants.X_OK);
153
+ return candidate;
154
+ } catch {
155
+ // not here
156
+ }
157
+ }
158
+ return null;
159
+ }
124
160
 
125
- function detectPyMinor() {
161
+ // { minor: "3.13", executable } for an interpreter that answers, else null.
162
+ // `executable` is the interpreter's own sys.executable: the path that keeps
163
+ // naming this version when `python3` later names another one.
164
+ function askPython(path) {
126
165
  const result = spawnSync(
127
- "python3",
128
- [
129
- "-c",
130
- "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')",
131
- ],
166
+ path,
167
+ ["-c", "import sys; print('%d.%d' % sys.version_info[:2]); print(sys.executable)"],
132
168
  { encoding: "utf8" }
133
169
  );
134
170
  if (result.error || result.status !== 0) return null;
135
- return result.stdout.trim();
171
+ const [minor = "", executable = ""] = result.stdout.trim().split(/\r?\n/);
172
+ if (!/^\d+\.\d+$/.test(minor)) return null;
173
+ return { minor, executable: executable || path };
136
174
  }
137
175
 
138
- const pyMinor = detectPyMinor();
139
- if (!pyMinor) {
140
- softFail(
141
- `python3 not found on PATH — the sentisec CLI binary requires ` +
142
- `Python 3.11-3.14. Install python3 and re-run ` +
143
- `'npm rebuild @sentisec/sdk' to get the CLI, OR use the SDK as a library only.`
144
- );
176
+ function pythonInstallHint() {
177
+ if (process.platform === "darwin") return `brew install python@${NEWEST_PY}`;
178
+ if (findOnPath("apt")) return `sudo apt install python${NEWEST_PY}`;
179
+ if (findOnPath("dnf")) return `sudo dnf install python${NEWEST_PY}`;
180
+ if (findOnPath("pacman")) return "sudo pacman -S python";
181
+ return "your distro's package manager";
145
182
  }
146
183
 
147
- if (!SUPPORTED_PY_MINORS.has(pyMinor)) {
184
+ // { path, minor, executable, why }: `why` is set when the choice is not
185
+ // python3, and says why.
186
+ function choosePython() {
187
+ const override = process.env.SENTISEC_PYTHON;
188
+ if (override) {
189
+ const path = override.includes("/") ? override : findOnPath(override);
190
+ const answer = path ? askPython(path) : null;
191
+ if (!answer) {
192
+ softFail(
193
+ `SENTISEC_PYTHON='${override}' is not a Python that runs. ` +
194
+ `Point it at a Python from ${SUPPORTED_RANGE}, or unset it, then run '${REBUILD}'.`
195
+ );
196
+ }
197
+ if (!SUPPORTED_PY_MINORS.includes(answer.minor)) {
198
+ softFail(
199
+ `SENTISEC_PYTHON='${override}' is Python ${answer.minor}; the Sentisec CLI ` +
200
+ `is built for Python ${SUPPORTED_RANGE}. Point it at one of those, or unset it, ` +
201
+ `then run '${REBUILD}'.`
202
+ );
203
+ }
204
+ return { path, ...answer, why: "set by SENTISEC_PYTHON" };
205
+ }
206
+
207
+ let found;
208
+ const python3 = findOnPath("python3");
209
+ if (python3) {
210
+ const answer = askPython(python3);
211
+ if (answer && SUPPORTED_PY_MINORS.includes(answer.minor)) {
212
+ return { path: python3, ...answer, why: null };
213
+ }
214
+ found = answer
215
+ ? `python3 (${python3}) is Python ${answer.minor}`
216
+ : `python3 (${python3}) did not report its version`;
217
+ } else {
218
+ found = "there is no python3 on PATH";
219
+ }
220
+
221
+ for (const minor of SUPPORTED_PY_MINORS) {
222
+ const path = findOnPath(`python${minor}`);
223
+ if (!path) continue;
224
+ // A shim can carry the name of a version it does not run: ask it.
225
+ const answer = askPython(path);
226
+ if (!answer || answer.minor !== minor) continue;
227
+ return {
228
+ path,
229
+ ...answer,
230
+ why: `${found}; the Sentisec CLI is built for Python ${SUPPORTED_RANGE}`,
231
+ };
232
+ }
233
+
234
+ const tried = SUPPORTED_PY_MINORS.map((minor) => `python${minor}`).join(", ");
148
235
  softFail(
149
- `Detected python3 ${pyMinor}; only 3.11 / 3.12 / 3.13 / 3.14 are supported. ` +
150
- `CLI not installed. Install a supported python (e.g. 'brew install python@3.12') ` +
151
- `and re-run 'npm rebuild @sentisec/sdk'.`
236
+ `No Python the Sentisec CLI can run on: ${found}, and none of ${tried} is on PATH. ` +
237
+ `Supported: Python ${SUPPORTED_RANGE}. Install one ('${pythonInstallHint()}') ` +
238
+ `and run '${REBUILD}', or set SENTISEC_PYTHON=/path/to/python${NEWEST_PY}.`
152
239
  );
153
240
  }
154
241
 
242
+ const python = choosePython();
243
+ const pyMinor = python.minor;
244
+ log(
245
+ `Using python: ${python.path} (${pyMinor})${python.why ? ` — ${python.why}` : ""}`
246
+ );
247
+
155
248
  // --- resolve CLI release version -----------------------------------------
156
249
  //
157
250
  // The npm SDK version (e.g., 0.1.0-rc.2) and the CLI release version
@@ -469,16 +562,22 @@ try {
469
562
  softFail(`Failed to chmod ${binaryPath}: ${err.message}. CLI not installed.`);
470
563
  }
471
564
 
472
- // Write PYMINOR marker for the bin shim to read.
565
+ // Record the interpreter for bin/sentisec.js, which runs the CLI with it
566
+ // rather than with whatever python3 is at run time.
473
567
  try {
474
- writeFileSync(join(installRoot, "PYMINOR"), `${pyMinor}\n`, "utf8");
568
+ writeFileSync(
569
+ join(installRoot, INTERPRETER_MARKER),
570
+ JSON.stringify({ python: python.executable, minor: pyMinor }) + "\n",
571
+ "utf8"
572
+ );
475
573
  } catch (err) {
476
574
  cleanupStaging();
477
- softFail(`Failed to write PYMINOR marker: ${err.message}. CLI not installed.`);
575
+ softFail(`Failed to write ${INTERPRETER_MARKER}: ${err.message}. CLI not installed.`);
478
576
  }
479
577
 
480
578
  cleanupStaging();
481
579
  log(
482
580
  `CLI binary installed: native/${platformName}/${archName}/${pyMinor}/sentisec (py${pyMinor})`
483
581
  );
582
+ log(`sentisec will run on ${python.executable}`);
484
583
  process.exit(0);