@clawos-dev/clawd 0.2.2-beta.1.e86e2eb → 0.2.2-beta.3.49c2b71
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/dist/cli.cjs +69 -37
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1205,7 +1205,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
1205
1205
|
var require_sonic_boom = __commonJS({
|
|
1206
1206
|
"../node_modules/.pnpm/sonic-boom@4.2.1/node_modules/sonic-boom/index.js"(exports2, module2) {
|
|
1207
1207
|
"use strict";
|
|
1208
|
-
var
|
|
1208
|
+
var fs17 = require("fs");
|
|
1209
1209
|
var EventEmitter = require("events");
|
|
1210
1210
|
var inherits = require("util").inherits;
|
|
1211
1211
|
var path16 = require("path");
|
|
@@ -1262,20 +1262,20 @@ var require_sonic_boom = __commonJS({
|
|
|
1262
1262
|
const mode = sonic.mode;
|
|
1263
1263
|
if (sonic.sync) {
|
|
1264
1264
|
try {
|
|
1265
|
-
if (sonic.mkdir)
|
|
1266
|
-
const fd =
|
|
1265
|
+
if (sonic.mkdir) fs17.mkdirSync(path16.dirname(file), { recursive: true });
|
|
1266
|
+
const fd = fs17.openSync(file, flags, mode);
|
|
1267
1267
|
fileOpened(null, fd);
|
|
1268
1268
|
} catch (err) {
|
|
1269
1269
|
fileOpened(err);
|
|
1270
1270
|
throw err;
|
|
1271
1271
|
}
|
|
1272
1272
|
} else if (sonic.mkdir) {
|
|
1273
|
-
|
|
1273
|
+
fs17.mkdir(path16.dirname(file), { recursive: true }, (err) => {
|
|
1274
1274
|
if (err) return fileOpened(err);
|
|
1275
|
-
|
|
1275
|
+
fs17.open(file, flags, mode, fileOpened);
|
|
1276
1276
|
});
|
|
1277
1277
|
} else {
|
|
1278
|
-
|
|
1278
|
+
fs17.open(file, flags, mode, fileOpened);
|
|
1279
1279
|
}
|
|
1280
1280
|
}
|
|
1281
1281
|
function SonicBoom(opts) {
|
|
@@ -1316,8 +1316,8 @@ var require_sonic_boom = __commonJS({
|
|
|
1316
1316
|
this.flush = flushBuffer;
|
|
1317
1317
|
this.flushSync = flushBufferSync;
|
|
1318
1318
|
this._actualWrite = actualWriteBuffer;
|
|
1319
|
-
fsWriteSync = () =>
|
|
1320
|
-
fsWrite = () =>
|
|
1319
|
+
fsWriteSync = () => fs17.writeSync(this.fd, this._writingBuf);
|
|
1320
|
+
fsWrite = () => fs17.write(this.fd, this._writingBuf, this.release);
|
|
1321
1321
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
1322
1322
|
this._writingBuf = "";
|
|
1323
1323
|
this.write = write;
|
|
@@ -1326,15 +1326,15 @@ var require_sonic_boom = __commonJS({
|
|
|
1326
1326
|
this._actualWrite = actualWrite;
|
|
1327
1327
|
fsWriteSync = () => {
|
|
1328
1328
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
1329
|
-
return
|
|
1329
|
+
return fs17.writeSync(this.fd, this._writingBuf);
|
|
1330
1330
|
}
|
|
1331
|
-
return
|
|
1331
|
+
return fs17.writeSync(this.fd, this._writingBuf, "utf8");
|
|
1332
1332
|
};
|
|
1333
1333
|
fsWrite = () => {
|
|
1334
1334
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
1335
|
-
return
|
|
1335
|
+
return fs17.write(this.fd, this._writingBuf, this.release);
|
|
1336
1336
|
}
|
|
1337
|
-
return
|
|
1337
|
+
return fs17.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
1338
1338
|
};
|
|
1339
1339
|
} else {
|
|
1340
1340
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -1391,7 +1391,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1391
1391
|
}
|
|
1392
1392
|
}
|
|
1393
1393
|
if (this._fsync) {
|
|
1394
|
-
|
|
1394
|
+
fs17.fsyncSync(this.fd);
|
|
1395
1395
|
}
|
|
1396
1396
|
const len = this._len;
|
|
1397
1397
|
if (this._reopening) {
|
|
@@ -1505,7 +1505,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1505
1505
|
const onDrain = () => {
|
|
1506
1506
|
if (!this._fsync) {
|
|
1507
1507
|
try {
|
|
1508
|
-
|
|
1508
|
+
fs17.fsync(this.fd, (err) => {
|
|
1509
1509
|
this._flushPending = false;
|
|
1510
1510
|
cb(err);
|
|
1511
1511
|
});
|
|
@@ -1607,7 +1607,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1607
1607
|
const fd = this.fd;
|
|
1608
1608
|
this.once("ready", () => {
|
|
1609
1609
|
if (fd !== this.fd) {
|
|
1610
|
-
|
|
1610
|
+
fs17.close(fd, (err) => {
|
|
1611
1611
|
if (err) {
|
|
1612
1612
|
return this.emit("error", err);
|
|
1613
1613
|
}
|
|
@@ -1656,7 +1656,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1656
1656
|
buf = this._bufs[0];
|
|
1657
1657
|
}
|
|
1658
1658
|
try {
|
|
1659
|
-
const n = Buffer.isBuffer(buf) ?
|
|
1659
|
+
const n = Buffer.isBuffer(buf) ? fs17.writeSync(this.fd, buf) : fs17.writeSync(this.fd, buf, "utf8");
|
|
1660
1660
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
1661
1661
|
buf = releasedBufObj.writingBuf;
|
|
1662
1662
|
this._len = releasedBufObj.len;
|
|
@@ -1672,7 +1672,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1672
1672
|
}
|
|
1673
1673
|
}
|
|
1674
1674
|
try {
|
|
1675
|
-
|
|
1675
|
+
fs17.fsyncSync(this.fd);
|
|
1676
1676
|
} catch {
|
|
1677
1677
|
}
|
|
1678
1678
|
}
|
|
@@ -1693,7 +1693,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1693
1693
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
1694
1694
|
}
|
|
1695
1695
|
try {
|
|
1696
|
-
const n =
|
|
1696
|
+
const n = fs17.writeSync(this.fd, buf);
|
|
1697
1697
|
buf = buf.subarray(n);
|
|
1698
1698
|
this._len = Math.max(this._len - n, 0);
|
|
1699
1699
|
if (buf.length <= 0) {
|
|
@@ -1721,13 +1721,13 @@ var require_sonic_boom = __commonJS({
|
|
|
1721
1721
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
1722
1722
|
if (this.sync) {
|
|
1723
1723
|
try {
|
|
1724
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
1724
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs17.writeSync(this.fd, this._writingBuf) : fs17.writeSync(this.fd, this._writingBuf, "utf8");
|
|
1725
1725
|
release(null, written);
|
|
1726
1726
|
} catch (err) {
|
|
1727
1727
|
release(err);
|
|
1728
1728
|
}
|
|
1729
1729
|
} else {
|
|
1730
|
-
|
|
1730
|
+
fs17.write(this.fd, this._writingBuf, release);
|
|
1731
1731
|
}
|
|
1732
1732
|
}
|
|
1733
1733
|
function actualWriteBuffer() {
|
|
@@ -1736,7 +1736,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1736
1736
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
1737
1737
|
if (this.sync) {
|
|
1738
1738
|
try {
|
|
1739
|
-
const written =
|
|
1739
|
+
const written = fs17.writeSync(this.fd, this._writingBuf);
|
|
1740
1740
|
release(null, written);
|
|
1741
1741
|
} catch (err) {
|
|
1742
1742
|
release(err);
|
|
@@ -1745,7 +1745,7 @@ var require_sonic_boom = __commonJS({
|
|
|
1745
1745
|
if (kCopyBuffer) {
|
|
1746
1746
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
1747
1747
|
}
|
|
1748
|
-
|
|
1748
|
+
fs17.write(this.fd, this._writingBuf, release);
|
|
1749
1749
|
}
|
|
1750
1750
|
}
|
|
1751
1751
|
function actualClose(sonic) {
|
|
@@ -1761,12 +1761,12 @@ var require_sonic_boom = __commonJS({
|
|
|
1761
1761
|
sonic._lens = [];
|
|
1762
1762
|
assert(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
1763
1763
|
try {
|
|
1764
|
-
|
|
1764
|
+
fs17.fsync(sonic.fd, closeWrapped);
|
|
1765
1765
|
} catch {
|
|
1766
1766
|
}
|
|
1767
1767
|
function closeWrapped() {
|
|
1768
1768
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
1769
|
-
|
|
1769
|
+
fs17.close(sonic.fd, done);
|
|
1770
1770
|
} else {
|
|
1771
1771
|
done();
|
|
1772
1772
|
}
|
|
@@ -8077,6 +8077,7 @@ Env (advanced):
|
|
|
8077
8077
|
// src/index.ts
|
|
8078
8078
|
var import_node_os10 = __toESM(require("os"), 1);
|
|
8079
8079
|
var import_node_path15 = __toESM(require("path"), 1);
|
|
8080
|
+
var import_node_fs16 = __toESM(require("fs"), 1);
|
|
8080
8081
|
|
|
8081
8082
|
// src/logger.ts
|
|
8082
8083
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
@@ -16587,6 +16588,7 @@ var StateFileManager = class {
|
|
|
16587
16588
|
// src/tunnel/tunnel-manager.ts
|
|
16588
16589
|
var import_node_fs13 = __toESM(require("fs"), 1);
|
|
16589
16590
|
var import_node_path12 = __toESM(require("path"), 1);
|
|
16591
|
+
var import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
16590
16592
|
var import_node_child_process4 = require("child_process");
|
|
16591
16593
|
|
|
16592
16594
|
// src/tunnel/tunnel-store.ts
|
|
@@ -16961,11 +16963,12 @@ var TunnelManager = class {
|
|
|
16961
16963
|
override: this.deps.frpcBinaryOverride ?? void 0
|
|
16962
16964
|
});
|
|
16963
16965
|
const tomlPath = import_node_path12.default.join(this.deps.dataDir, "frpc.toml");
|
|
16966
|
+
const proxyName = `clawd-${t.subdomain}-${localPort}-${import_node_crypto3.default.randomBytes(3).toString("hex")}`;
|
|
16964
16967
|
const toml = buildFrpcToml({
|
|
16965
16968
|
serverAddr: t.frpsHost,
|
|
16966
16969
|
serverPort: t.frpsPort,
|
|
16967
16970
|
authToken: t.frpsToken,
|
|
16968
|
-
proxyName
|
|
16971
|
+
proxyName,
|
|
16969
16972
|
subdomain: t.subdomain,
|
|
16970
16973
|
localPort,
|
|
16971
16974
|
logLevel: "info"
|
|
@@ -16992,7 +16995,10 @@ var TunnelManager = class {
|
|
|
16992
16995
|
proc.kill("SIGTERM");
|
|
16993
16996
|
} catch {
|
|
16994
16997
|
}
|
|
16995
|
-
|
|
16998
|
+
const tail = formatFrpcTail(ready.output);
|
|
16999
|
+
const msg = tail ? `${ready.error}
|
|
17000
|
+
${tail}` : ready.error;
|
|
17001
|
+
return { ok: false, error: new Error(msg) };
|
|
16996
17002
|
}
|
|
16997
17003
|
this.deps.logger?.info("tunnel: frpc up", { subdomain: t.subdomain, url: t.url });
|
|
16998
17004
|
return { ok: true, proc };
|
|
@@ -17002,6 +17008,13 @@ var TunnelManager = class {
|
|
|
17002
17008
|
}
|
|
17003
17009
|
}
|
|
17004
17010
|
};
|
|
17011
|
+
function formatFrpcTail(raw, maxLines = 12) {
|
|
17012
|
+
const stripped = raw.replace(/\[[0-9;]*[A-Za-z]/g, "");
|
|
17013
|
+
const lines = stripped.split("\n").filter((l) => l.trim().length > 0);
|
|
17014
|
+
if (lines.length === 0) return "";
|
|
17015
|
+
const tail = lines.slice(-maxLines).join("\n");
|
|
17016
|
+
return ["\u2500\u2500\u2500 frpc output (last lines) \u2500\u2500\u2500", tail, "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"].join("\n");
|
|
17017
|
+
}
|
|
17005
17018
|
async function waitForFrpcReady(proc, timeoutMs) {
|
|
17006
17019
|
return new Promise((resolve) => {
|
|
17007
17020
|
let settled = false;
|
|
@@ -17018,13 +17031,16 @@ async function waitForFrpcReady(proc, timeoutMs) {
|
|
|
17018
17031
|
finish({ ok: true });
|
|
17019
17032
|
}
|
|
17020
17033
|
if (/login to server failed|authentication failed/i.test(buf)) {
|
|
17021
|
-
finish({ ok: false, error:
|
|
17034
|
+
finish({ ok: false, error: "frpc handshake failed", output: buf });
|
|
17035
|
+
}
|
|
17036
|
+
if (/start error: proxy \[[^\]]+\] already exists/i.test(buf)) {
|
|
17037
|
+
finish({ ok: false, error: "frpc proxy name conflict", output: buf });
|
|
17022
17038
|
}
|
|
17023
17039
|
};
|
|
17024
17040
|
const onExit = (code) => {
|
|
17025
|
-
finish({ ok: false, error: `frpc exited before ready (code=${code})
|
|
17041
|
+
finish({ ok: false, error: `frpc exited before ready (code=${code})`, output: buf });
|
|
17026
17042
|
};
|
|
17027
|
-
const onErr = (err) => finish({ ok: false, error: `frpc spawn error: ${err.message}
|
|
17043
|
+
const onErr = (err) => finish({ ok: false, error: `frpc spawn error: ${err.message}`, output: buf });
|
|
17028
17044
|
const cleanup = () => {
|
|
17029
17045
|
proc.stdout?.off("data", onData);
|
|
17030
17046
|
proc.stderr?.off("data", onData);
|
|
@@ -17037,26 +17053,26 @@ async function waitForFrpcReady(proc, timeoutMs) {
|
|
|
17037
17053
|
proc.on("exit", onExit);
|
|
17038
17054
|
proc.on("error", onErr);
|
|
17039
17055
|
const timer = setTimeout(() => {
|
|
17040
|
-
finish({ ok: false, error: `frpc startup timeout after ${timeoutMs}ms
|
|
17056
|
+
finish({ ok: false, error: `frpc startup timeout after ${timeoutMs}ms`, output: buf });
|
|
17041
17057
|
}, timeoutMs);
|
|
17042
17058
|
});
|
|
17043
17059
|
}
|
|
17044
17060
|
|
|
17045
17061
|
// src/tunnel/device-key.ts
|
|
17046
17062
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
17047
|
-
var
|
|
17063
|
+
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
17048
17064
|
var DERIVE_SALT = "clawd-tunnel-device-v1";
|
|
17049
17065
|
function deriveStableDeviceKey(opts = {}) {
|
|
17050
17066
|
const hostname = opts.hostname ?? import_node_os8.default.hostname();
|
|
17051
17067
|
const uid = opts.uid ?? (typeof import_node_os8.default.userInfo === "function" ? import_node_os8.default.userInfo().uid : 0);
|
|
17052
17068
|
const input = `${hostname}::${uid}`;
|
|
17053
|
-
return
|
|
17069
|
+
return import_node_crypto4.default.createHmac("sha256", DERIVE_SALT).update(input).digest("hex").slice(0, 32);
|
|
17054
17070
|
}
|
|
17055
17071
|
|
|
17056
17072
|
// src/auth-store.ts
|
|
17057
17073
|
var import_node_fs14 = __toESM(require("fs"), 1);
|
|
17058
17074
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
17059
|
-
var
|
|
17075
|
+
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
17060
17076
|
var AUTH_FILE_NAME = "auth.json";
|
|
17061
17077
|
function authFilePath(dataDir) {
|
|
17062
17078
|
return import_node_path13.default.join(dataDir, AUTH_FILE_NAME);
|
|
@@ -17071,7 +17087,7 @@ function loadOrCreateAuthToken(opts) {
|
|
|
17071
17087
|
return token;
|
|
17072
17088
|
}
|
|
17073
17089
|
function defaultGenerate() {
|
|
17074
|
-
return
|
|
17090
|
+
return import_node_crypto5.default.randomBytes(32).toString("base64url");
|
|
17075
17091
|
}
|
|
17076
17092
|
function readAuthFile(file) {
|
|
17077
17093
|
try {
|
|
@@ -17488,11 +17504,27 @@ async function startDaemon(config) {
|
|
|
17488
17504
|
const r = await tunnelMgr.start({ localPort: config.port });
|
|
17489
17505
|
stateSnapshot = { ...stateSnapshot, tunnelUrl: r.url };
|
|
17490
17506
|
stateMgr.write(stateSnapshot);
|
|
17491
|
-
|
|
17507
|
+
const connectUrl = resolvedAuthToken ? `${r.url}#token=${resolvedAuthToken}` : r.url;
|
|
17508
|
+
const lines = [
|
|
17509
|
+
`Tunnel: ${r.url}`,
|
|
17510
|
+
...resolvedAuthToken ? [`Connect: ${connectUrl}`] : [],
|
|
17511
|
+
`Frpc config: ${import_node_path15.default.join(config.dataDir, "frpc.toml")}`,
|
|
17512
|
+
`Frpc log: ${import_node_path15.default.join(config.dataDir, "frpc.log")}`
|
|
17513
|
+
];
|
|
17514
|
+
const width = Math.max(...lines.map((l) => l.length));
|
|
17515
|
+
const bar = "\u2550".repeat(width + 4);
|
|
17516
|
+
process.stdout.write(`
|
|
17517
|
+
${bar}
|
|
17518
|
+
`);
|
|
17519
|
+
for (const l of lines) process.stdout.write(` ${l}
|
|
17492
17520
|
`);
|
|
17493
|
-
|
|
17494
|
-
|
|
17521
|
+
process.stdout.write(`${bar}
|
|
17522
|
+
|
|
17495
17523
|
`);
|
|
17524
|
+
try {
|
|
17525
|
+
const connectPath = import_node_path15.default.join(config.dataDir, "connect.txt");
|
|
17526
|
+
import_node_fs16.default.writeFileSync(connectPath, lines.join("\n") + "\n", { mode: 384 });
|
|
17527
|
+
} catch {
|
|
17496
17528
|
}
|
|
17497
17529
|
} catch (err) {
|
|
17498
17530
|
try {
|
package/package.json
CHANGED