@nuwax-ai/nuwax-harness 0.0.0-stage → 0.18.14
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 +31 -2
- package/bin/nuwax-codex.js +3 -0
- package/bin/nuwax-harness.js +18 -0
- package/bin/postinstall.js +11 -0
- package/bin/runtime.js +152 -0
- package/package.json +46 -4
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Nuwax Harness
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
通过环境变量接入自定义 OpenAI Chat、OpenAI Responses 和 Anthropic Messages 模型。
|
|
4
|
+
默认使用 rig,也可选择上游原生 Responses 通路。
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install -g @nuwax-ai/nuwax-harness@latest
|
|
8
|
+
nuwax-harness --version
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
npm 包名为 `@nuwax-ai/nuwax-harness`,主命令和下载的主二进制为 `nuwax-harness`。
|
|
12
|
+
该组织包只导出 `nuwax-harness` 命令;Rust 内部程序名保持不变。
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
export NUWAX_BASE_URL='https://your-provider.example/v1'
|
|
17
|
+
export NUWAX_WIRE_API='chat'
|
|
18
|
+
export NUWAX_MODEL='your-model-id'
|
|
19
|
+
export NUWAX_BRIDGE='rig'
|
|
20
|
+
# 从你的受保护环境注入 NUWAX_API_KEY。
|
|
21
|
+
nuwax-harness
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Anthropic 使用 `NUWAX_WIRE_API=anthropic`;原生 Responses 使用
|
|
25
|
+
`NUWAX_WIRE_API=responses` 和 `NUWAX_BRIDGE=native`,并换成相应的基址及模型。
|
|
26
|
+
|
|
27
|
+
默认数据目录为 `~/.nuwax-harness`;显式 `CODEX_HOME` 优先且须为已存在目录。
|
|
28
|
+
不读取或迁移旧数据目录。下载缓存为 `~/.nuwax-harness-cache`,包含同版本的配套辅助程序,
|
|
29
|
+
请勿只复制主二进制而丢弃 helper。
|
|
30
|
+
|
|
31
|
+
完整参数、ACP 启动、Linux/容器、Windows 与排查示例见
|
|
32
|
+
[环境变量启动指南](https://github.com/nuwax-ai/codex/tree/test/docs/nuwax-harness)。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { ensureBinary } from "./runtime.js";
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const binaryPath = await ensureBinary();
|
|
7
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
8
|
+
stdio: "inherit",
|
|
9
|
+
windowsHide: true,
|
|
10
|
+
// Internal install detection and updates continue targeting nuwax-codex.
|
|
11
|
+
env: { ...process.env, CODEX_INSTALL_SOURCE: "npm_nuwax" },
|
|
12
|
+
});
|
|
13
|
+
if (result.error) throw result.error;
|
|
14
|
+
process.exitCode = result.status ?? 1;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error(`nuwax-harness: ${error.message}`);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { ensureBinary } from "./runtime.js";
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
const binaryPath = await ensureBinary();
|
|
6
|
+
console.error(`nuwax-harness ready at ${binaryPath}`);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
// Installation remains usable offline: the launcher retries on first use.
|
|
9
|
+
// An incomplete archive/cache is never reported as ready.
|
|
10
|
+
console.error(`nuwax-harness postinstall: ${error.message}`);
|
|
11
|
+
}
|
package/bin/runtime.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Shared native bundle installer for postinstall and both npm commands.
|
|
2
|
+
import { createWriteStream, existsSync, mkdirSync, mkdtempSync, renameSync, rmdirSync, rmSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, dirname, join } from "node:path";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { pipeline } from "node:stream/promises";
|
|
8
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
9
|
+
import { familySync } from "detect-libc";
|
|
10
|
+
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const VERSION = require("../package.json").version;
|
|
13
|
+
const OSS_CDN_BASE = "https://nuwa-packages.oss-rg-china-mainland.aliyuncs.com/nuwax-codex";
|
|
14
|
+
|
|
15
|
+
export function getTargetTriple(platform = process.platform, arch = process.arch, libc = familySync()) {
|
|
16
|
+
if (platform === "darwin") {
|
|
17
|
+
if (arch === "arm64") return "aarch64-apple-darwin";
|
|
18
|
+
if (arch === "x64") return "x86_64-apple-darwin";
|
|
19
|
+
} else if (platform === "linux") {
|
|
20
|
+
if (arch === "arm64") return "aarch64-unknown-linux-musl";
|
|
21
|
+
if (arch === "x64") {
|
|
22
|
+
return libc === "musl" ? "x86_64-unknown-linux-musl" : "x86_64-unknown-linux-gnu";
|
|
23
|
+
}
|
|
24
|
+
} else if (platform === "win32") {
|
|
25
|
+
if (arch === "arm64") return "aarch64-pc-windows-msvc";
|
|
26
|
+
if (arch === "x64") return "x86_64-pc-windows-msvc";
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Unsupported platform/architecture: ${platform}/${arch}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function requiredBundleFiles(platform = process.platform) {
|
|
32
|
+
const ext = platform === "win32" ? ".exe" : "";
|
|
33
|
+
const files = [`nuwax-harness${ext}`, `codex-code-mode-host${ext}`];
|
|
34
|
+
if (platform === "linux") files.push("codex-resources/bwrap");
|
|
35
|
+
if (platform === "win32") files.push("codex-windows-sandbox-setup.exe", "codex-command-runner.exe");
|
|
36
|
+
return files;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function missingBundleFiles(directory) {
|
|
40
|
+
return requiredBundleFiles().filter((name) => {
|
|
41
|
+
try {
|
|
42
|
+
return !statSync(join(directory, name)).isFile();
|
|
43
|
+
} catch {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function extractArchive(archivePath, destination) {
|
|
50
|
+
if (process.platform !== "win32") {
|
|
51
|
+
const tar = await import("tar");
|
|
52
|
+
await tar.x({ file: archivePath, cwd: destination, gzip: true });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const yauzl = await import("yauzl");
|
|
56
|
+
await new Promise((resolve, reject) => {
|
|
57
|
+
yauzl.open(archivePath, { lazyEntries: true, autoClose: true, strictFileNames: true }, (error, archive) => {
|
|
58
|
+
if (error) return reject(error);
|
|
59
|
+
const fail = (failure) => {
|
|
60
|
+
archive.close();
|
|
61
|
+
reject(failure);
|
|
62
|
+
};
|
|
63
|
+
archive.on("error", fail);
|
|
64
|
+
archive.on("entry", (entry) => {
|
|
65
|
+
try {
|
|
66
|
+
if (!entry.fileName || entry.fileName.includes("\\") || entry.fileName.includes("\0") || entry.fileName.startsWith("/") || /^[a-zA-Z]:/.test(entry.fileName) || entry.fileName.split("/").includes("..")) {
|
|
67
|
+
throw new Error(`Unsafe ZIP entry: ${entry.fileName}`);
|
|
68
|
+
}
|
|
69
|
+
const destinationPath = join(destination, entry.fileName);
|
|
70
|
+
if (entry.fileName.endsWith("/")) {
|
|
71
|
+
mkdirSync(destinationPath, { recursive: true });
|
|
72
|
+
archive.readEntry();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
mkdirSync(dirname(destinationPath), { recursive: true });
|
|
76
|
+
archive.openReadStream(entry, (readError, stream) => {
|
|
77
|
+
if (readError) return fail(readError);
|
|
78
|
+
pipeline(stream, createWriteStream(destinationPath)).then(() => archive.readEntry()).catch(fail);
|
|
79
|
+
});
|
|
80
|
+
} catch (entryError) {
|
|
81
|
+
fail(entryError);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// On Windows the archive cannot be removed until yauzl closes its fd.
|
|
85
|
+
archive.on("close", resolve);
|
|
86
|
+
archive.readEntry();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function publishBundle(stagingDirectory, directory, stagingRoot) {
|
|
92
|
+
const lock = `${directory}.publish-lock`;
|
|
93
|
+
let acquired = false;
|
|
94
|
+
// Only serialize the short publication step; downloads/extraction stay parallel.
|
|
95
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
96
|
+
try {
|
|
97
|
+
mkdirSync(lock);
|
|
98
|
+
acquired = true;
|
|
99
|
+
break;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error.code !== "EEXIST") throw error;
|
|
102
|
+
}
|
|
103
|
+
await delay(50);
|
|
104
|
+
}
|
|
105
|
+
if (!acquired) {
|
|
106
|
+
throw new Error(`Native bundle publish lock is busy: ${lock}. Retry after the other installer exits; an interrupted installer may leave this empty lock directory behind.`);
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
// A concurrent install may already have published the same complete bundle.
|
|
110
|
+
if (missingBundleFiles(directory).length === 0) return;
|
|
111
|
+
if (existsSync(directory)) renameSync(directory, join(stagingRoot, "previous-incomplete-cache"));
|
|
112
|
+
renameSync(stagingDirectory, directory);
|
|
113
|
+
if (missingBundleFiles(directory).length > 0) throw new Error("Native bundle cache is incomplete after installation");
|
|
114
|
+
} finally {
|
|
115
|
+
rmdirSync(lock);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function ensureBinary() {
|
|
120
|
+
const target = getTargetTriple();
|
|
121
|
+
const directory = join(homedir(), ".nuwax-harness-cache", VERSION, target);
|
|
122
|
+
const binaryPath = join(directory, requiredBundleFiles()[0]);
|
|
123
|
+
if (missingBundleFiles(directory).length === 0) return binaryPath;
|
|
124
|
+
|
|
125
|
+
// Archive names and the OSS namespace stay compatible with existing clients.
|
|
126
|
+
const ext = process.platform === "win32" ? "zip" : "tar.gz";
|
|
127
|
+
const url = `${OSS_CDN_BASE}/v${VERSION}/nuwax-codex-${VERSION}-${target}.${ext}`;
|
|
128
|
+
console.error(`Downloading nuwax-harness ${VERSION} for ${target} …`);
|
|
129
|
+
mkdirSync(dirname(directory), { recursive: true });
|
|
130
|
+
const stagingRoot = mkdtempSync(`${directory}.stage-`);
|
|
131
|
+
const stagingDirectory = join(stagingRoot, "bundle");
|
|
132
|
+
const archivePath = join(stagingRoot, `nuwax-codex.${ext}`);
|
|
133
|
+
mkdirSync(stagingDirectory, { recursive: true });
|
|
134
|
+
try {
|
|
135
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
136
|
+
if (!response.ok || !response.body) {
|
|
137
|
+
throw new Error(`Failed to download ${basename(archivePath)}: HTTP ${response.status}`);
|
|
138
|
+
}
|
|
139
|
+
// pipeline waits for disk writes/close and propagates ENOSPC/EACCES.
|
|
140
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(archivePath));
|
|
141
|
+
await extractArchive(archivePath, stagingDirectory);
|
|
142
|
+
const missing = missingBundleFiles(stagingDirectory);
|
|
143
|
+
if (missing.length > 0) throw new Error(`Incomplete native bundle: missing ${missing.join(", ")}`);
|
|
144
|
+
|
|
145
|
+
// Check again under a bounded lock before atomically quarantining a bad
|
|
146
|
+
// cache. One repair must never remove another installer's complete winner.
|
|
147
|
+
await publishBundle(stagingDirectory, directory, stagingRoot);
|
|
148
|
+
return binaryPath;
|
|
149
|
+
} finally {
|
|
150
|
+
rmSync(stagingRoot, { recursive: true, force: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuwax-ai/nuwax-harness",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.18.14",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Nuwax Harness: Codex agent with custom OpenAI and Anthropic models via rig",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "soddygo <soddygo@qq.com>",
|
|
8
|
+
"homepage": "https://github.com/nuwax-ai/codex",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/nuwax-ai/codex.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/nuwax-ai/codex/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"codex",
|
|
18
|
+
"agent",
|
|
19
|
+
"coding",
|
|
20
|
+
"ai",
|
|
21
|
+
"assistant",
|
|
22
|
+
"llm",
|
|
23
|
+
"rig",
|
|
24
|
+
"anthropic",
|
|
25
|
+
"openai"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"postinstall": "node bin/postinstall.js"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"nuwax-harness": "bin/nuwax-harness.js"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"bin"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"detect-libc": "^2.0.0",
|
|
41
|
+
"tar": "^7.0.0",
|
|
42
|
+
"yauzl": "^3.1.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org"
|
|
47
|
+
}
|
|
48
|
+
}
|