better-dsh 0.3.1 → 0.3.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 +6 -5
- package/cordis.patch.yml +14 -9
- package/docs/20_specs/kernel-provisioning/spec.md +2 -0
- package/docs/remote-tools.md +15 -9
- package/docs/specs/kernel-provisioning/spec.md +12 -40
- package/docs/specs/omp-python-repl-port/runtime-guide.md +3 -1
- package/docs/specs/omp-python-repl-port/spec.md +7 -0
- package/docs/specs/remote-pty-label/spec.md +2 -0
- package/docs/specs/remote-tool-enhancement/spec.md +1 -0
- package/lib/BrowserWebSocketTransport.js +4 -0
- package/lib/{BrowserWebSocketTransport-wm99h94r.js → BrowserWebSocketTransport2.js} +1 -1
- package/lib/LaunchOptions.js +4 -0
- package/lib/{LaunchOptions-5eg7E0ye.js → LaunchOptions2.js} +1 -1
- package/lib/{NodeWebSocketTransport-D9ysYGLM.js → NodeWebSocketTransport.js} +2 -2
- package/lib/NodeWebSocketTransport2.js +4 -0
- package/lib/{bidi-CwabFH07.js → bidi.js} +4 -4
- package/lib/client/index.js +59 -6
- package/lib/compaction/index.d.ts +1 -1
- package/lib/compaction/index.js +1 -1
- package/lib/failover/index.d.ts +1 -1
- package/lib/failover/index.js +1 -1
- package/lib/fs-aware/sandbox-plugin.js +1 -1
- package/lib/{index-browser-B-9jm12n.js → index-browser.js} +6 -6
- package/lib/index.d.ts +2 -12
- package/lib/index.js +58 -62
- package/lib/kernel-env.d.ts +5 -15
- package/lib/kernel-env.js +2 -2
- package/lib/kernel-env2.js +76 -0
- package/lib/{lsp-server-registry-BcdkHROD.js → lsp-server-registry2.js} +1 -1
- package/lib/{main-BeCgUd20.js → main.js} +1 -1
- package/lib/{main-Dv_UQqG2.js → main2.js} +1 -1
- package/lib/mobile/plugin.d.ts +2 -2
- package/lib/mobile/plugin.js +2 -2
- package/lib/{puppeteer-core-Dnd7eqel.js → puppeteer-core.js} +9 -9
- package/lib/py-sdk.js +1 -1
- package/lib/remote/helper-bin/MANIFEST.json +35 -0
- package/lib/remote/helper-bin/aarch64-apple-darwin/BUILT-VER +1 -0
- package/lib/remote/helper-bin/aarch64-apple-darwin/superd-run +0 -0
- package/lib/remote/helper-bin/aarch64-unknown-linux-musl/BUILT-VER +1 -0
- package/lib/remote/helper-bin/aarch64-unknown-linux-musl/superd-run +0 -0
- package/lib/remote/helper-bin/x86_64-pc-windows-gnu/BUILT-VER +1 -0
- package/lib/remote/helper-bin/x86_64-pc-windows-gnu/superd-run.exe +0 -0
- package/lib/remote/helper-bin/x86_64-unknown-linux-musl/BUILT-VER +1 -0
- package/lib/remote/helper-bin/x86_64-unknown-linux-musl/superd-run +0 -0
- package/lib/remote/plugin.d.ts +172 -51
- package/lib/remote/plugin.js +2168 -718
- package/lib/url-schemes/index.d.ts +11 -11
- package/lib/url-schemes/index.js +12 -12
- package/lib/{wasm_bg-CNXhHjVg.js → wasm_bg.js} +1 -1
- package/lib/web-password.d.ts +7 -7
- package/lib/web-password.js +1 -1
- package/lib/web-trust.d.ts +1 -1
- package/lib/web-trust.js +2 -2
- package/lib/{web-trust-D6gJpUMf.js → web-trust2.js} +20 -8
- package/lib/welcome-notice.js +1 -1
- package/package.json +4 -4
- package/scripts/kernel-check.mjs +5 -0
- package/lib/BrowserWebSocketTransport-D1aFReu_.js +0 -4
- package/lib/LaunchOptions-DxQQ0s-A.js +0 -4
- package/lib/NodeWebSocketTransport-BRLjmu2R.js +0 -4
- package/lib/kernel-env-BOF0fNHn.js +0 -91
- package/scripts/kernel-provision.mjs +0 -5
- /package/lib/{chunk-DQxbwPpZ.js → chunk.js} +0 -0
- /package/lib/{index-DTDXUe6m.d.ts → index2.d.ts} +0 -0
- /package/lib/{lib-C8_jXvwA.js → lib.js} +0 -0
- /package/lib/{lsp-server-registry-D4VLs1Sm.js → lsp-server-registry.js} +0 -0
- /package/lib/{native-capture-BEByDXYM.js → native-capture.js} +0 -0
- /package/lib/{py-sdk-D7klhpWb.js → py-sdk2.js} +0 -0
- /package/lib/{util-BHL_dfV_.js → util.js} +0 -0
- /package/lib/{web-tree-sitter-CPrPD4J2.js → web-tree-sitter.js} +0 -0
- /package/lib/{web-trust-CwZrTBcl.d.ts → web-trust2.d.ts} +0 -0
- /package/lib/{wrap-0VA0uFx8.js → wrap.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import { ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _deepseek_ai_schemastery11 from "@deepseek-ai/schemastery";
|
|
4
4
|
|
|
5
5
|
//#region src/url-schemes/tools/write.d.ts
|
|
6
6
|
|
|
@@ -50,12 +50,12 @@ declare const inject: string[];
|
|
|
50
50
|
* real patch-line config. Schema-level defaults (both ON — the service is
|
|
51
51
|
* opt-out) survive every overlay layer, per the v0.2.2a ruling.
|
|
52
52
|
*/
|
|
53
|
-
declare const Config:
|
|
54
|
-
urlSchemes:
|
|
55
|
-
hashline:
|
|
53
|
+
declare const Config: _deepseek_ai_schemastery11.default<Schemastery.ObjectS<NoInfer<{
|
|
54
|
+
urlSchemes: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
55
|
+
hashline: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
56
56
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
57
|
-
urlSchemes:
|
|
58
|
-
hashline:
|
|
57
|
+
urlSchemes: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
58
|
+
hashline: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
59
59
|
}>>, "plain">;
|
|
60
60
|
/** Register the four URL-aware tools on one agent's own scope layer. */
|
|
61
61
|
/**
|
|
@@ -75,12 +75,12 @@ declare function apply(ctx: Context, config: UrlSchemesConfig | undefined): void
|
|
|
75
75
|
declare const _default: {
|
|
76
76
|
name: string;
|
|
77
77
|
inject: string[];
|
|
78
|
-
Config:
|
|
79
|
-
urlSchemes:
|
|
80
|
-
hashline:
|
|
78
|
+
Config: _deepseek_ai_schemastery11.default<Schemastery.ObjectS<NoInfer<{
|
|
79
|
+
urlSchemes: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
80
|
+
hashline: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
81
81
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
82
|
-
urlSchemes:
|
|
83
|
-
hashline:
|
|
82
|
+
urlSchemes: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
83
|
+
hashline: _deepseek_ai_schemastery11.default<boolean, boolean, "defined">;
|
|
84
84
|
}>>, "plain">;
|
|
85
85
|
apply: typeof apply;
|
|
86
86
|
};
|
package/lib/url-schemes/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { r as __toESM, t as __commonJS } from "../chunk
|
|
2
|
-
import { t as Schema } from "../lib
|
|
3
|
-
import {
|
|
4
|
-
import { n as captureNativeTools } from "../native-capture
|
|
5
|
-
import { a as createHttpHandler, c as listDvcDevices, d as UrlResolver, f as UrlSchemesError, h as SCHEME_NAMES, i as HTTP_SCHEMES, l as registerDvcDevice, m as parseUrl, n as wrapFsWithSchemes, o as createDvcHandler, p as applySelector, r as resolveDocsDir, s as dispatchDvcWrite, u as createDshHandler } from "../wrap
|
|
6
|
-
import { n as Parser } from "../web-tree-sitter
|
|
7
|
-
import { a as primaryServerForFile, c as serversForFile, n as findWorkspaceRoot, o as resolveCommandPath, r as installHintFor, s as serverByName } from "../lsp-server-registry
|
|
1
|
+
import { r as __toESM, t as __commonJS } from "../chunk.js";
|
|
2
|
+
import { t as Schema } from "../lib.js";
|
|
3
|
+
import { t as PACKAGE_ROOT } from "../kernel-env2.js";
|
|
4
|
+
import { n as captureNativeTools } from "../native-capture.js";
|
|
5
|
+
import { a as createHttpHandler, c as listDvcDevices, d as UrlResolver, f as UrlSchemesError, h as SCHEME_NAMES, i as HTTP_SCHEMES, l as registerDvcDevice, m as parseUrl, n as wrapFsWithSchemes, o as createDvcHandler, p as applySelector, r as resolveDocsDir, s as dispatchDvcWrite, u as createDshHandler } from "../wrap.js";
|
|
6
|
+
import { n as Parser } from "../web-tree-sitter.js";
|
|
7
|
+
import { a as primaryServerForFile, c as serversForFile, n as findWorkspaceRoot, o as resolveCommandPath, r as installHintFor, s as serverByName } from "../lsp-server-registry.js";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { createHash, randomUUID } from "node:crypto";
|
|
10
10
|
import { accessSync, constants, existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -12,12 +12,12 @@ import * as path$1 from "node:path";
|
|
|
12
12
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
13
13
|
import { spawn } from "node:child_process";
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
|
+
import { homedir, tmpdir } from "node:os";
|
|
15
16
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
16
17
|
import * as fsPromises from "node:fs/promises";
|
|
17
18
|
import { lstat, mkdir, mkdtemp, readFile, readdir, readlink, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
18
19
|
import { FsError } from "@deepseek-ai/dsh-fs";
|
|
19
20
|
import { ESCALATION_TARGETS, approveEscalation, escalationHintMarker, sandboxDenialMarker, validateEscalationArgs } from "@deepseek-ai/dsh-sandbox";
|
|
20
|
-
import { homedir, tmpdir } from "node:os";
|
|
21
21
|
import { gunzipSync } from "node:zlib";
|
|
22
22
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
23
23
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
@@ -133,7 +133,7 @@ function astEngine() {
|
|
|
133
133
|
return enginePromise;
|
|
134
134
|
}
|
|
135
135
|
async function boot() {
|
|
136
|
-
const bg = await import("../wasm_bg
|
|
136
|
+
const bg = await import("../wasm_bg.js");
|
|
137
137
|
const bytes = await readAsset(ASTGREP_WASM.file);
|
|
138
138
|
const { instance } = await WebAssemblyGlobal.instantiate(bytes, { "./wasm_bg.js": bg });
|
|
139
139
|
bg.__wbg_set_wasm(instance.exports);
|
|
@@ -1435,7 +1435,7 @@ const PUPPETEER_CORE_VERSION = "25.3.0";
|
|
|
1435
1435
|
*/
|
|
1436
1436
|
async function loadPuppeteer() {
|
|
1437
1437
|
if (puppeteerModule === void 0) try {
|
|
1438
|
-
puppeteerModule = await import("../puppeteer-core
|
|
1438
|
+
puppeteerModule = await import("../puppeteer-core.js");
|
|
1439
1439
|
} catch {
|
|
1440
1440
|
try {
|
|
1441
1441
|
puppeteerModule = await import(pathToFileURL((await ensureVendored({
|
|
@@ -2500,7 +2500,7 @@ function ensureMustHave(gate, language) {
|
|
|
2500
2500
|
if (!MUST_HAVE.has(language) || gate.installTried.has(language)) return;
|
|
2501
2501
|
gate.installTried.add(language);
|
|
2502
2502
|
(async () => {
|
|
2503
|
-
const registry = await import("../lsp-server-
|
|
2503
|
+
const registry = await import("../lsp-server-registry2.js");
|
|
2504
2504
|
const probePath = `/tmp/x.${language === "python" ? "py" : "ts"}`;
|
|
2505
2505
|
const primary = registry.primaryServerForFile(probePath);
|
|
2506
2506
|
if (primary === null) return;
|
|
@@ -3189,7 +3189,7 @@ async function lspDeviceRead(subpath, session) {
|
|
|
3189
3189
|
if (parsed === void 0) return `unknown read path dvc://lsp/${subpath} — reads: status | diagnostics?file=…[&all=1] | definition?file=&line=[&character=|&symbol=] | references?… | hover?…`;
|
|
3190
3190
|
if (parsed.action === "status") {
|
|
3191
3191
|
const availability = {};
|
|
3192
|
-
const registry = await import("../lsp-server-
|
|
3192
|
+
const registry = await import("../lsp-server-registry2.js");
|
|
3193
3193
|
for (const language of [
|
|
3194
3194
|
"python",
|
|
3195
3195
|
"typescript",
|
package/lib/web-password.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import { IncomingMessage } from "node:http";
|
|
3
3
|
import { CredentialRecord } from "@deepseek-ai/dsh-credentials";
|
|
4
|
-
import * as
|
|
4
|
+
import * as _deepseek_ai_schemastery21 from "@deepseek-ai/schemastery";
|
|
5
5
|
|
|
6
6
|
//#region src/web-password.d.ts
|
|
7
7
|
|
|
@@ -123,10 +123,10 @@ interface WebPasswordConfig {
|
|
|
123
123
|
/** Absolute browser-session lifetime in days. Default: 30 (the native default). */
|
|
124
124
|
cookieMaxAgeDays?: number;
|
|
125
125
|
}
|
|
126
|
-
declare const Config:
|
|
127
|
-
cookieMaxAgeDays:
|
|
126
|
+
declare const Config: _deepseek_ai_schemastery21.default<Schemastery.ObjectS<NoInfer<{
|
|
127
|
+
cookieMaxAgeDays: _deepseek_ai_schemastery21.default<number, number, "defined">;
|
|
128
128
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
129
|
-
cookieMaxAgeDays:
|
|
129
|
+
cookieMaxAgeDays: _deepseek_ai_schemastery21.default<number, number, "defined">;
|
|
130
130
|
}>>, "plain">;
|
|
131
131
|
/** Cordis plugin name; also the scope of this row's credential record. */
|
|
132
132
|
declare const name = "dashr-web-password";
|
|
@@ -145,10 +145,10 @@ declare function apply(ctx: Context, config?: WebPasswordConfig): void;
|
|
|
145
145
|
declare const _default: {
|
|
146
146
|
name: string;
|
|
147
147
|
inject: string[];
|
|
148
|
-
Config:
|
|
149
|
-
cookieMaxAgeDays:
|
|
148
|
+
Config: _deepseek_ai_schemastery21.default<Schemastery.ObjectS<NoInfer<{
|
|
149
|
+
cookieMaxAgeDays: _deepseek_ai_schemastery21.default<number, number, "defined">;
|
|
150
150
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
151
|
-
cookieMaxAgeDays:
|
|
151
|
+
cookieMaxAgeDays: _deepseek_ai_schemastery21.default<number, number, "defined">;
|
|
152
152
|
}>>, "plain">;
|
|
153
153
|
apply: typeof apply;
|
|
154
154
|
};
|
package/lib/web-password.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Schema } from "./lib
|
|
1
|
+
import { t as Schema } from "./lib.js";
|
|
2
2
|
import { createHash, createHmac, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { credentialKey } from "@deepseek-ai/dsh-credentials";
|
package/lib/web-trust.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as _default, c as buildTrustScript, d as name, i as TrustConfig, l as deriveDefaultPageAuthorities, n as Config, o as apply, r as MobileConfig, s as buildMobileScript, t as BootScriptRow, u as inject } from "./web-
|
|
1
|
+
import { a as _default, c as buildTrustScript, d as name, i as TrustConfig, l as deriveDefaultPageAuthorities, n as Config, o as apply, r as MobileConfig, s as buildMobileScript, t as BootScriptRow, u as inject } from "./web-trust2.js";
|
|
2
2
|
export { BootScriptRow, Config, MobileConfig, TrustConfig, apply, buildMobileScript, buildTrustScript, _default as default, deriveDefaultPageAuthorities, inject, name };
|
package/lib/web-trust.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./lib
|
|
2
|
-
import { a as deriveDefaultPageAuthorities, c as web_trust_default, i as buildTrustScript, n as apply, o as inject, r as buildMobileScript, s as name, t as Config } from "./web-
|
|
1
|
+
import "./lib.js";
|
|
2
|
+
import { a as deriveDefaultPageAuthorities, c as web_trust_default, i as buildTrustScript, n as apply, o as inject, r as buildMobileScript, s as name, t as Config } from "./web-trust2.js";
|
|
3
3
|
|
|
4
4
|
export { Config, apply, buildMobileScript, buildTrustScript, web_trust_default as default, deriveDefaultPageAuthorities, inject, name };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Schema } from "./lib
|
|
1
|
+
import { t as Schema } from "./lib.js";
|
|
2
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
3
3
|
|
|
4
4
|
//#region src/mobile/zoom-guard.ts
|
|
@@ -252,20 +252,32 @@ function buildZoomGuardSection() {
|
|
|
252
252
|
* A fixed, query-free index path prevents token exchange or redirects here;
|
|
253
253
|
* original Host and Cookie headers preserve the native authority binding and
|
|
254
254
|
* lifetime. No upstream private fields or cookie-format copies are needed.
|
|
255
|
+
*
|
|
256
|
+
* 0.2.1: the fence core is `admit()` — the HTTP bridge calls it directly and
|
|
257
|
+
* `requestRejection()` is a thin wrapper over it, so overriding the public
|
|
258
|
+
* `admit` is the one seam that still steers both paths. A fence rejection
|
|
259
|
+
* (403) is retried as cookie-only admission; every other verdict (a live
|
|
260
|
+
* peer, 401 from failed native authentication, disposed) passes through
|
|
261
|
+
* untouched. An accepted cookie admits as the shared browser peer — the same
|
|
262
|
+
* scope native browser authentication grants.
|
|
255
263
|
*/
|
|
256
264
|
function installAuthenticationOnlyAdmission(connection) {
|
|
257
|
-
const original = connection.
|
|
265
|
+
const original = connection.admit;
|
|
258
266
|
const response = {
|
|
259
267
|
writeHead() {},
|
|
260
268
|
end() {}
|
|
261
269
|
};
|
|
262
|
-
connection.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
270
|
+
connection.admit = (request) => {
|
|
271
|
+
const admission = original.call(connection, request);
|
|
272
|
+
if (!("rejection" in admission) || admission.rejection !== 403) return admission;
|
|
273
|
+
return connection.authorizeIndex({
|
|
274
|
+
headers: request.headers,
|
|
275
|
+
method: "GET",
|
|
276
|
+
url: "/index.html"
|
|
277
|
+
}, response) ? { peer: connection.browserPeer } : { rejection: 401 };
|
|
278
|
+
};
|
|
267
279
|
return () => {
|
|
268
|
-
connection.
|
|
280
|
+
connection.admit = original;
|
|
269
281
|
};
|
|
270
282
|
}
|
|
271
283
|
|
package/lib/welcome-notice.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-dsh",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Make your dsh ready for serious coding tasks. (Tools x Schemas)^REPL. `skill://`, `ctx://`, `agent://`, `dvc://`, `dsh://`, Python REPL, Context as Variables, cross compactions recallable, full context revive. `hash-edit`, `dvc://browser`, subagent as function, workflow as function.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -71,17 +71,17 @@
|
|
|
71
71
|
"cordis.patch.yml",
|
|
72
72
|
"eval-description.md",
|
|
73
73
|
"url-schemes-instruction.md",
|
|
74
|
-
"scripts/kernel-
|
|
74
|
+
"scripts/kernel-check.mjs"
|
|
75
75
|
],
|
|
76
76
|
"scripts": {
|
|
77
77
|
"prebuild": "node scripts/copy-docs.mjs",
|
|
78
|
-
"build": "tsdown && npm run build-client && node scripts/copy-kernel-bridge.mjs && node scripts/copy-ast-assets.mjs",
|
|
78
|
+
"build": "tsdown && npm run build-client && node scripts/copy-kernel-bridge.mjs && node scripts/copy-ast-assets.mjs && node scripts/copy-helper-bins.mjs",
|
|
79
79
|
"typecheck": "npm run typecheck:host && npm run typecheck:client",
|
|
80
80
|
"typecheck:host": "tsc --noEmit",
|
|
81
81
|
"typecheck:client": "tsc -p tsconfig.client.json",
|
|
82
82
|
"test": "vitest --run",
|
|
83
83
|
"test:watch": "vitest",
|
|
84
|
-
"kernel:
|
|
84
|
+
"kernel:check": "node scripts/kernel-check.mjs",
|
|
85
85
|
"build-client": "tsx scripts/build-client.ts"
|
|
86
86
|
},
|
|
87
87
|
"license": "MIT",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Check an existing interpreter; never install Python or create an environment. */
|
|
3
|
+
const { resolveKernelEnv } = await import(new URL('../lib/kernel-env.js', import.meta.url).href)
|
|
4
|
+
const env = await resolveKernelEnv({ python: process.env.DASHR_KERNEL_PYTHON })
|
|
5
|
+
console.log(`Better Python REPL ready: Python ${env.version} at ${env.python}`)
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
-
import { execFile } from "node:child_process";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
|
-
|
|
7
|
-
//#region src/kernel-env.ts
|
|
8
|
-
const exec = promisify(execFile);
|
|
9
|
-
const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
-
const AUTO_PYTHON_SENTINEL = "python3";
|
|
11
|
-
const DEFAULT_KERNEL_PYTHON_VERSION = "3.11";
|
|
12
|
-
const DILL_VERSION = "0.4.1";
|
|
13
|
-
function uvToolEnv(venvDir) {
|
|
14
|
-
const cache = join(dirname(venvDir), ".uv-cache");
|
|
15
|
-
return {
|
|
16
|
-
...process.env,
|
|
17
|
-
UV_CACHE_DIR: cache,
|
|
18
|
-
UV_PYTHON_INSTALL_DIR: join(cache, "python"),
|
|
19
|
-
UV_LINK_MODE: "copy"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function uvVenvArgs(dir, version) {
|
|
23
|
-
return [
|
|
24
|
-
"venv",
|
|
25
|
-
dir,
|
|
26
|
-
"--python",
|
|
27
|
-
version
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
function venvFallbackArgs(dir) {
|
|
31
|
-
return [
|
|
32
|
-
"-m",
|
|
33
|
-
"venv",
|
|
34
|
-
"--without-pip",
|
|
35
|
-
dir
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
function venvPython(dir) {
|
|
39
|
-
return join(dir, process.platform === "win32" ? "Scripts/python.exe" : "bin/python");
|
|
40
|
-
}
|
|
41
|
-
async function probe(python) {
|
|
42
|
-
try {
|
|
43
|
-
const { stdout } = await exec(python, ["-c", "import ast, asyncio, json, sys; assert sys.version_info >= (3, 9), \"Python >=3.9 required\"; print(json.dumps(sys.version.split()[0]))"], {
|
|
44
|
-
timeout: 15e3,
|
|
45
|
-
env: {
|
|
46
|
-
...process.env,
|
|
47
|
-
PYTHONDONTWRITEBYTECODE: "1"
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return JSON.parse(stdout.trim());
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new Error(`Better Python REPL requires Python >=3.9. Could not use ${JSON.stringify(python)}: ${error instanceof Error ? error.message : String(error)}. Configure python with a working interpreter path.`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function resolveKernelEnv(options = {}) {
|
|
56
|
-
if (options.python && options.python !== AUTO_PYTHON_SENTINEL) return {
|
|
57
|
-
python: options.python,
|
|
58
|
-
managed: false,
|
|
59
|
-
venvDir: void 0,
|
|
60
|
-
dill: true,
|
|
61
|
-
version: await probe(options.python)
|
|
62
|
-
};
|
|
63
|
-
const venvDir = options.venvDir ?? join(PACKAGE_ROOT, ".venv-kernel");
|
|
64
|
-
const python = venvPython(venvDir);
|
|
65
|
-
if (!existsSync(python)) {
|
|
66
|
-
if (options.autoInstall === false) throw new Error(`Better Python REPL managed interpreter is missing at ${python}; configure python or run npm run kernel:venv`);
|
|
67
|
-
options.log?.("info", `Creating stdlib-only Python environment at ${venvDir} (no pip packages)`);
|
|
68
|
-
let uv = false;
|
|
69
|
-
try {
|
|
70
|
-
await exec("uv", ["--version"], { timeout: 1e4 });
|
|
71
|
-
uv = true;
|
|
72
|
-
} catch {}
|
|
73
|
-
if (uv) {
|
|
74
|
-
mkdirSync(join(dirname(venvDir), ".uv-cache"), { recursive: true });
|
|
75
|
-
await exec("uv", uvVenvArgs(venvDir, options.pythonVersion ?? DEFAULT_KERNEL_PYTHON_VERSION), {
|
|
76
|
-
timeout: 12e4,
|
|
77
|
-
env: uvToolEnv(venvDir)
|
|
78
|
-
});
|
|
79
|
-
} else await exec("python3", venvFallbackArgs(venvDir), { timeout: 12e4 });
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
python,
|
|
83
|
-
managed: true,
|
|
84
|
-
venvDir,
|
|
85
|
-
dill: true,
|
|
86
|
-
version: await probe(python)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
export { resolveKernelEnv as a, venvFallbackArgs as c, PACKAGE_ROOT as i, DEFAULT_KERNEL_PYTHON_VERSION as n, uvToolEnv as o, DILL_VERSION as r, uvVenvArgs as s, AUTO_PYTHON_SENTINEL as t };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/** Explicit compatibility command: prepare only a stdlib Python environment, never pip packages. */
|
|
3
|
-
const { resolveKernelEnv } = await import(new URL('../lib/kernel-env.js', import.meta.url).href)
|
|
4
|
-
const env = await resolveKernelEnv({ log: (level, message) => console[level === 'warn' ? 'warn' : 'log'](message) })
|
|
5
|
-
console.log(`Better Python REPL ready: Python ${env.version} at ${env.python}`)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|