@clawos-dev/clawd 0.2.133-beta.265.f727e25 → 0.2.133-beta.266.ebdcb8e
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 +740 -349
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -6842,10 +6842,10 @@ var require_redaction = __commonJS({
|
|
|
6842
6842
|
var strict = false;
|
|
6843
6843
|
function redaction(opts, serialize) {
|
|
6844
6844
|
const { paths, censor, remove } = handle(opts);
|
|
6845
|
-
const shape = paths.reduce((o,
|
|
6845
|
+
const shape = paths.reduce((o, str2) => {
|
|
6846
6846
|
rx.lastIndex = 0;
|
|
6847
|
-
const first = rx.exec(
|
|
6848
|
-
const next = rx.exec(
|
|
6847
|
+
const first = rx.exec(str2);
|
|
6848
|
+
const next = rx.exec(str2);
|
|
6849
6849
|
let ns = first[1] !== void 0 ? first[1].replace(/^(?:"|'|`)(.*)(?:"|'|`)$/, "$1") : first[0];
|
|
6850
6850
|
if (ns === "*") {
|
|
6851
6851
|
ns = wildcardFirstSym;
|
|
@@ -6858,7 +6858,7 @@ var require_redaction = __commonJS({
|
|
|
6858
6858
|
return o;
|
|
6859
6859
|
}
|
|
6860
6860
|
const { index } = next;
|
|
6861
|
-
const nextPath = `${
|
|
6861
|
+
const nextPath = `${str2.substr(index, str2.length - 1)}`;
|
|
6862
6862
|
o[ns] = o[ns] || [];
|
|
6863
6863
|
if (ns !== wildcardFirstSym && o[ns].length === 0) {
|
|
6864
6864
|
o[ns].push(...o[wildcardFirstSym] || []);
|
|
@@ -6974,7 +6974,7 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
6974
6974
|
}
|
|
6975
6975
|
var argLen = args.length;
|
|
6976
6976
|
if (argLen === 0) return f;
|
|
6977
|
-
var
|
|
6977
|
+
var str2 = "";
|
|
6978
6978
|
var a = 1 - offset;
|
|
6979
6979
|
var lastPos = -1;
|
|
6980
6980
|
var flen = f && f.length || 0;
|
|
@@ -6989,8 +6989,8 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
6989
6989
|
break;
|
|
6990
6990
|
if (args[a] == null) break;
|
|
6991
6991
|
if (lastPos < i)
|
|
6992
|
-
|
|
6993
|
-
|
|
6992
|
+
str2 += f.slice(lastPos, i);
|
|
6993
|
+
str2 += Number(args[a]);
|
|
6994
6994
|
lastPos = i + 2;
|
|
6995
6995
|
i++;
|
|
6996
6996
|
break;
|
|
@@ -6999,8 +6999,8 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
6999
6999
|
break;
|
|
7000
7000
|
if (args[a] == null) break;
|
|
7001
7001
|
if (lastPos < i)
|
|
7002
|
-
|
|
7003
|
-
|
|
7002
|
+
str2 += f.slice(lastPos, i);
|
|
7003
|
+
str2 += Math.floor(Number(args[a]));
|
|
7004
7004
|
lastPos = i + 2;
|
|
7005
7005
|
i++;
|
|
7006
7006
|
break;
|
|
@@ -7013,21 +7013,21 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7013
7013
|
break;
|
|
7014
7014
|
if (args[a] === void 0) break;
|
|
7015
7015
|
if (lastPos < i)
|
|
7016
|
-
|
|
7016
|
+
str2 += f.slice(lastPos, i);
|
|
7017
7017
|
var type = typeof args[a];
|
|
7018
7018
|
if (type === "string") {
|
|
7019
|
-
|
|
7019
|
+
str2 += "'" + args[a] + "'";
|
|
7020
7020
|
lastPos = i + 2;
|
|
7021
7021
|
i++;
|
|
7022
7022
|
break;
|
|
7023
7023
|
}
|
|
7024
7024
|
if (type === "function") {
|
|
7025
|
-
|
|
7025
|
+
str2 += args[a].name || "<anonymous>";
|
|
7026
7026
|
lastPos = i + 2;
|
|
7027
7027
|
i++;
|
|
7028
7028
|
break;
|
|
7029
7029
|
}
|
|
7030
|
-
|
|
7030
|
+
str2 += ss(args[a]);
|
|
7031
7031
|
lastPos = i + 2;
|
|
7032
7032
|
i++;
|
|
7033
7033
|
break;
|
|
@@ -7035,15 +7035,15 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7035
7035
|
if (a >= argLen)
|
|
7036
7036
|
break;
|
|
7037
7037
|
if (lastPos < i)
|
|
7038
|
-
|
|
7039
|
-
|
|
7038
|
+
str2 += f.slice(lastPos, i);
|
|
7039
|
+
str2 += String(args[a]);
|
|
7040
7040
|
lastPos = i + 2;
|
|
7041
7041
|
i++;
|
|
7042
7042
|
break;
|
|
7043
7043
|
case 37:
|
|
7044
7044
|
if (lastPos < i)
|
|
7045
|
-
|
|
7046
|
-
|
|
7045
|
+
str2 += f.slice(lastPos, i);
|
|
7046
|
+
str2 += "%";
|
|
7047
7047
|
lastPos = i + 2;
|
|
7048
7048
|
i++;
|
|
7049
7049
|
a--;
|
|
@@ -7056,9 +7056,9 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7056
7056
|
if (lastPos === -1)
|
|
7057
7057
|
return f;
|
|
7058
7058
|
else if (lastPos < flen) {
|
|
7059
|
-
|
|
7059
|
+
str2 += f.slice(lastPos);
|
|
7060
7060
|
}
|
|
7061
|
-
return
|
|
7061
|
+
return str2;
|
|
7062
7062
|
}
|
|
7063
7063
|
}
|
|
7064
7064
|
});
|
|
@@ -7102,7 +7102,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
7102
7102
|
var require_sonic_boom = __commonJS({
|
|
7103
7103
|
"../node_modules/.pnpm/sonic-boom@4.2.1/node_modules/sonic-boom/index.js"(exports2, module2) {
|
|
7104
7104
|
"use strict";
|
|
7105
|
-
var
|
|
7105
|
+
var fs51 = require("fs");
|
|
7106
7106
|
var EventEmitter3 = require("events");
|
|
7107
7107
|
var inherits = require("util").inherits;
|
|
7108
7108
|
var path59 = require("path");
|
|
@@ -7159,20 +7159,20 @@ var require_sonic_boom = __commonJS({
|
|
|
7159
7159
|
const mode = sonic.mode;
|
|
7160
7160
|
if (sonic.sync) {
|
|
7161
7161
|
try {
|
|
7162
|
-
if (sonic.mkdir)
|
|
7163
|
-
const fd =
|
|
7162
|
+
if (sonic.mkdir) fs51.mkdirSync(path59.dirname(file), { recursive: true });
|
|
7163
|
+
const fd = fs51.openSync(file, flags, mode);
|
|
7164
7164
|
fileOpened(null, fd);
|
|
7165
7165
|
} catch (err) {
|
|
7166
7166
|
fileOpened(err);
|
|
7167
7167
|
throw err;
|
|
7168
7168
|
}
|
|
7169
7169
|
} else if (sonic.mkdir) {
|
|
7170
|
-
|
|
7170
|
+
fs51.mkdir(path59.dirname(file), { recursive: true }, (err) => {
|
|
7171
7171
|
if (err) return fileOpened(err);
|
|
7172
|
-
|
|
7172
|
+
fs51.open(file, flags, mode, fileOpened);
|
|
7173
7173
|
});
|
|
7174
7174
|
} else {
|
|
7175
|
-
|
|
7175
|
+
fs51.open(file, flags, mode, fileOpened);
|
|
7176
7176
|
}
|
|
7177
7177
|
}
|
|
7178
7178
|
function SonicBoom(opts) {
|
|
@@ -7213,8 +7213,8 @@ var require_sonic_boom = __commonJS({
|
|
|
7213
7213
|
this.flush = flushBuffer;
|
|
7214
7214
|
this.flushSync = flushBufferSync;
|
|
7215
7215
|
this._actualWrite = actualWriteBuffer;
|
|
7216
|
-
fsWriteSync = () =>
|
|
7217
|
-
fsWrite = () =>
|
|
7216
|
+
fsWriteSync = () => fs51.writeSync(this.fd, this._writingBuf);
|
|
7217
|
+
fsWrite = () => fs51.write(this.fd, this._writingBuf, this.release);
|
|
7218
7218
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
7219
7219
|
this._writingBuf = "";
|
|
7220
7220
|
this.write = write;
|
|
@@ -7223,15 +7223,15 @@ var require_sonic_boom = __commonJS({
|
|
|
7223
7223
|
this._actualWrite = actualWrite;
|
|
7224
7224
|
fsWriteSync = () => {
|
|
7225
7225
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7226
|
-
return
|
|
7226
|
+
return fs51.writeSync(this.fd, this._writingBuf);
|
|
7227
7227
|
}
|
|
7228
|
-
return
|
|
7228
|
+
return fs51.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7229
7229
|
};
|
|
7230
7230
|
fsWrite = () => {
|
|
7231
7231
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7232
|
-
return
|
|
7232
|
+
return fs51.write(this.fd, this._writingBuf, this.release);
|
|
7233
7233
|
}
|
|
7234
|
-
return
|
|
7234
|
+
return fs51.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
7235
7235
|
};
|
|
7236
7236
|
} else {
|
|
7237
7237
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -7288,7 +7288,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7288
7288
|
}
|
|
7289
7289
|
}
|
|
7290
7290
|
if (this._fsync) {
|
|
7291
|
-
|
|
7291
|
+
fs51.fsyncSync(this.fd);
|
|
7292
7292
|
}
|
|
7293
7293
|
const len = this._len;
|
|
7294
7294
|
if (this._reopening) {
|
|
@@ -7402,7 +7402,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7402
7402
|
const onDrain = () => {
|
|
7403
7403
|
if (!this._fsync) {
|
|
7404
7404
|
try {
|
|
7405
|
-
|
|
7405
|
+
fs51.fsync(this.fd, (err) => {
|
|
7406
7406
|
this._flushPending = false;
|
|
7407
7407
|
cb(err);
|
|
7408
7408
|
});
|
|
@@ -7504,7 +7504,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7504
7504
|
const fd = this.fd;
|
|
7505
7505
|
this.once("ready", () => {
|
|
7506
7506
|
if (fd !== this.fd) {
|
|
7507
|
-
|
|
7507
|
+
fs51.close(fd, (err) => {
|
|
7508
7508
|
if (err) {
|
|
7509
7509
|
return this.emit("error", err);
|
|
7510
7510
|
}
|
|
@@ -7553,7 +7553,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7553
7553
|
buf = this._bufs[0];
|
|
7554
7554
|
}
|
|
7555
7555
|
try {
|
|
7556
|
-
const n = Buffer.isBuffer(buf) ?
|
|
7556
|
+
const n = Buffer.isBuffer(buf) ? fs51.writeSync(this.fd, buf) : fs51.writeSync(this.fd, buf, "utf8");
|
|
7557
7557
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
7558
7558
|
buf = releasedBufObj.writingBuf;
|
|
7559
7559
|
this._len = releasedBufObj.len;
|
|
@@ -7569,7 +7569,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7569
7569
|
}
|
|
7570
7570
|
}
|
|
7571
7571
|
try {
|
|
7572
|
-
|
|
7572
|
+
fs51.fsyncSync(this.fd);
|
|
7573
7573
|
} catch {
|
|
7574
7574
|
}
|
|
7575
7575
|
}
|
|
@@ -7590,7 +7590,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7590
7590
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
7591
7591
|
}
|
|
7592
7592
|
try {
|
|
7593
|
-
const n =
|
|
7593
|
+
const n = fs51.writeSync(this.fd, buf);
|
|
7594
7594
|
buf = buf.subarray(n);
|
|
7595
7595
|
this._len = Math.max(this._len - n, 0);
|
|
7596
7596
|
if (buf.length <= 0) {
|
|
@@ -7618,13 +7618,13 @@ var require_sonic_boom = __commonJS({
|
|
|
7618
7618
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
7619
7619
|
if (this.sync) {
|
|
7620
7620
|
try {
|
|
7621
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
7621
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs51.writeSync(this.fd, this._writingBuf) : fs51.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7622
7622
|
release(null, written);
|
|
7623
7623
|
} catch (err) {
|
|
7624
7624
|
release(err);
|
|
7625
7625
|
}
|
|
7626
7626
|
} else {
|
|
7627
|
-
|
|
7627
|
+
fs51.write(this.fd, this._writingBuf, release);
|
|
7628
7628
|
}
|
|
7629
7629
|
}
|
|
7630
7630
|
function actualWriteBuffer() {
|
|
@@ -7633,7 +7633,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7633
7633
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
7634
7634
|
if (this.sync) {
|
|
7635
7635
|
try {
|
|
7636
|
-
const written =
|
|
7636
|
+
const written = fs51.writeSync(this.fd, this._writingBuf);
|
|
7637
7637
|
release(null, written);
|
|
7638
7638
|
} catch (err) {
|
|
7639
7639
|
release(err);
|
|
@@ -7642,7 +7642,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7642
7642
|
if (kCopyBuffer) {
|
|
7643
7643
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
7644
7644
|
}
|
|
7645
|
-
|
|
7645
|
+
fs51.write(this.fd, this._writingBuf, release);
|
|
7646
7646
|
}
|
|
7647
7647
|
}
|
|
7648
7648
|
function actualClose(sonic) {
|
|
@@ -7658,12 +7658,12 @@ var require_sonic_boom = __commonJS({
|
|
|
7658
7658
|
sonic._lens = [];
|
|
7659
7659
|
assert(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
7660
7660
|
try {
|
|
7661
|
-
|
|
7661
|
+
fs51.fsync(sonic.fd, closeWrapped);
|
|
7662
7662
|
} catch {
|
|
7663
7663
|
}
|
|
7664
7664
|
function closeWrapped() {
|
|
7665
7665
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
7666
|
-
|
|
7666
|
+
fs51.close(sonic.fd, done);
|
|
7667
7667
|
} else {
|
|
7668
7668
|
done();
|
|
7669
7669
|
}
|
|
@@ -8544,38 +8544,38 @@ var require_tools = __commonJS({
|
|
|
8544
8544
|
}
|
|
8545
8545
|
}
|
|
8546
8546
|
}
|
|
8547
|
-
function asString(
|
|
8547
|
+
function asString(str2) {
|
|
8548
8548
|
let result = "";
|
|
8549
8549
|
let last = 0;
|
|
8550
8550
|
let found = false;
|
|
8551
8551
|
let point = 255;
|
|
8552
|
-
const l =
|
|
8552
|
+
const l = str2.length;
|
|
8553
8553
|
if (l > 100) {
|
|
8554
|
-
return JSON.stringify(
|
|
8554
|
+
return JSON.stringify(str2);
|
|
8555
8555
|
}
|
|
8556
8556
|
for (var i = 0; i < l && point >= 32; i++) {
|
|
8557
|
-
point =
|
|
8557
|
+
point = str2.charCodeAt(i);
|
|
8558
8558
|
if (point === 34 || point === 92) {
|
|
8559
|
-
result +=
|
|
8559
|
+
result += str2.slice(last, i) + "\\";
|
|
8560
8560
|
last = i;
|
|
8561
8561
|
found = true;
|
|
8562
8562
|
}
|
|
8563
8563
|
}
|
|
8564
8564
|
if (!found) {
|
|
8565
|
-
result =
|
|
8565
|
+
result = str2;
|
|
8566
8566
|
} else {
|
|
8567
|
-
result +=
|
|
8567
|
+
result += str2.slice(last);
|
|
8568
8568
|
}
|
|
8569
|
-
return point < 32 ? JSON.stringify(
|
|
8569
|
+
return point < 32 ? JSON.stringify(str2) : '"' + result + '"';
|
|
8570
8570
|
}
|
|
8571
|
-
function asJson(obj, msg,
|
|
8571
|
+
function asJson(obj, msg, num2, time) {
|
|
8572
8572
|
if (asJsonChan.hasSubscribers === false) {
|
|
8573
|
-
return _asJson.call(this, obj, msg,
|
|
8573
|
+
return _asJson.call(this, obj, msg, num2, time);
|
|
8574
8574
|
}
|
|
8575
8575
|
const store = { instance: this, arguments };
|
|
8576
|
-
return asJsonChan.traceSync(_asJson, store, this, obj, msg,
|
|
8576
|
+
return asJsonChan.traceSync(_asJson, store, this, obj, msg, num2, time);
|
|
8577
8577
|
}
|
|
8578
|
-
function _asJson(obj, msg,
|
|
8578
|
+
function _asJson(obj, msg, num2, time) {
|
|
8579
8579
|
const stringify2 = this[stringifySym];
|
|
8580
8580
|
const stringifySafe = this[stringifySafeSym];
|
|
8581
8581
|
const stringifiers = this[stringifiersSym];
|
|
@@ -8585,7 +8585,7 @@ var require_tools = __commonJS({
|
|
|
8585
8585
|
const formatters = this[formattersSym];
|
|
8586
8586
|
const messageKey = this[messageKeySym];
|
|
8587
8587
|
const errorKey = this[errorKeySym];
|
|
8588
|
-
let data = this[lsCacheSym][
|
|
8588
|
+
let data = this[lsCacheSym][num2] + time;
|
|
8589
8589
|
data = data + chindings;
|
|
8590
8590
|
let value;
|
|
8591
8591
|
if (formatters.log) {
|
|
@@ -9212,7 +9212,7 @@ var require_proto = __commonJS({
|
|
|
9212
9212
|
function defaultMixinMergeStrategy(mergeObject, mixinObject) {
|
|
9213
9213
|
return Object.assign(mixinObject, mergeObject);
|
|
9214
9214
|
}
|
|
9215
|
-
function write(_obj, msg,
|
|
9215
|
+
function write(_obj, msg, num2) {
|
|
9216
9216
|
const t = this[timeSym]();
|
|
9217
9217
|
const mixin = this[mixinSym];
|
|
9218
9218
|
const errorKey = this[errorKeySym];
|
|
@@ -9234,12 +9234,12 @@ var require_proto = __commonJS({
|
|
|
9234
9234
|
}
|
|
9235
9235
|
}
|
|
9236
9236
|
if (mixin) {
|
|
9237
|
-
obj = mixinMergeStrategy(obj, mixin(obj,
|
|
9237
|
+
obj = mixinMergeStrategy(obj, mixin(obj, num2, this));
|
|
9238
9238
|
}
|
|
9239
|
-
const s = this[asJsonSym](obj, msg,
|
|
9239
|
+
const s = this[asJsonSym](obj, msg, num2, t);
|
|
9240
9240
|
const stream = this[streamSym];
|
|
9241
9241
|
if (stream[needsMetadataGsym] === true) {
|
|
9242
|
-
stream.lastLevel =
|
|
9242
|
+
stream.lastLevel = num2;
|
|
9243
9243
|
stream.lastObj = obj;
|
|
9244
9244
|
stream.lastMsg = msg;
|
|
9245
9245
|
stream.lastTime = t.slice(this[timeSliceIndexSym]);
|
|
@@ -9272,11 +9272,11 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
9272
9272
|
exports2.configure = configure;
|
|
9273
9273
|
module2.exports = stringify;
|
|
9274
9274
|
var strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
|
|
9275
|
-
function strEscape(
|
|
9276
|
-
if (
|
|
9277
|
-
return `"${
|
|
9275
|
+
function strEscape(str2) {
|
|
9276
|
+
if (str2.length < 5e3 && !strEscapeSequencesRegExp.test(str2)) {
|
|
9277
|
+
return `"${str2}"`;
|
|
9278
9278
|
}
|
|
9279
|
-
return JSON.stringify(
|
|
9279
|
+
return JSON.stringify(str2);
|
|
9280
9280
|
}
|
|
9281
9281
|
function sort(array, comparator) {
|
|
9282
9282
|
if (array.length > 200 || comparator) {
|
|
@@ -11257,12 +11257,12 @@ function attachmentToHistoryMessage(o, ts) {
|
|
|
11257
11257
|
const raw = Array.isArray(a.memories) ? a.memories : [];
|
|
11258
11258
|
const memories = raw.map((m2) => {
|
|
11259
11259
|
if (!m2 || typeof m2 !== "object") return null;
|
|
11260
|
-
const
|
|
11261
|
-
const path59 = typeof
|
|
11262
|
-
const content = typeof
|
|
11260
|
+
const rec2 = m2;
|
|
11261
|
+
const path59 = typeof rec2.path === "string" ? rec2.path : null;
|
|
11262
|
+
const content = typeof rec2.content === "string" ? rec2.content : null;
|
|
11263
11263
|
if (!path59 || content == null) return null;
|
|
11264
11264
|
const entry = { path: path59, content };
|
|
11265
|
-
if (typeof
|
|
11265
|
+
if (typeof rec2.mtimeMs === "number") entry.mtimeMs = rec2.mtimeMs;
|
|
11266
11266
|
return entry;
|
|
11267
11267
|
}).filter((m2) => m2 !== null);
|
|
11268
11268
|
if (memories.length === 0) return null;
|
|
@@ -12072,12 +12072,12 @@ function parseAttachment(obj) {
|
|
|
12072
12072
|
const raw = Array.isArray(a.memories) ? a.memories : [];
|
|
12073
12073
|
const memories = raw.map((m2) => {
|
|
12074
12074
|
if (!m2 || typeof m2 !== "object") return null;
|
|
12075
|
-
const
|
|
12076
|
-
const path59 = typeof
|
|
12077
|
-
const content = typeof
|
|
12075
|
+
const rec2 = m2;
|
|
12076
|
+
const path59 = typeof rec2.path === "string" ? rec2.path : null;
|
|
12077
|
+
const content = typeof rec2.content === "string" ? rec2.content : null;
|
|
12078
12078
|
if (!path59 || content == null) return null;
|
|
12079
12079
|
const out = { path: path59, content };
|
|
12080
|
-
if (typeof
|
|
12080
|
+
if (typeof rec2.mtimeMs === "number") out.mtimeMs = rec2.mtimeMs;
|
|
12081
12081
|
return out;
|
|
12082
12082
|
}).filter((m2) => m2 !== null);
|
|
12083
12083
|
if (memories.length === 0) return null;
|
|
@@ -17712,26 +17712,26 @@ var require_permessage_deflate = __commonJS({
|
|
|
17712
17712
|
value = value[0];
|
|
17713
17713
|
if (key === "client_max_window_bits") {
|
|
17714
17714
|
if (value !== true) {
|
|
17715
|
-
const
|
|
17716
|
-
if (!Number.isInteger(
|
|
17715
|
+
const num2 = +value;
|
|
17716
|
+
if (!Number.isInteger(num2) || num2 < 8 || num2 > 15) {
|
|
17717
17717
|
throw new TypeError(
|
|
17718
17718
|
`Invalid value for parameter "${key}": ${value}`
|
|
17719
17719
|
);
|
|
17720
17720
|
}
|
|
17721
|
-
value =
|
|
17721
|
+
value = num2;
|
|
17722
17722
|
} else if (!this._isServer) {
|
|
17723
17723
|
throw new TypeError(
|
|
17724
17724
|
`Invalid value for parameter "${key}": ${value}`
|
|
17725
17725
|
);
|
|
17726
17726
|
}
|
|
17727
17727
|
} else if (key === "server_max_window_bits") {
|
|
17728
|
-
const
|
|
17729
|
-
if (!Number.isInteger(
|
|
17728
|
+
const num2 = +value;
|
|
17729
|
+
if (!Number.isInteger(num2) || num2 < 8 || num2 > 15) {
|
|
17730
17730
|
throw new TypeError(
|
|
17731
17731
|
`Invalid value for parameter "${key}": ${value}`
|
|
17732
17732
|
);
|
|
17733
17733
|
}
|
|
17734
|
-
value =
|
|
17734
|
+
value = num2;
|
|
17735
17735
|
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
17736
17736
|
if (value !== true) {
|
|
17737
17737
|
throw new TypeError(
|
|
@@ -18426,8 +18426,8 @@ var require_receiver = __commonJS({
|
|
|
18426
18426
|
return;
|
|
18427
18427
|
}
|
|
18428
18428
|
const buf = this.consume(8);
|
|
18429
|
-
const
|
|
18430
|
-
if (
|
|
18429
|
+
const num2 = buf.readUInt32BE(0);
|
|
18430
|
+
if (num2 > Math.pow(2, 53 - 32) - 1) {
|
|
18431
18431
|
const error = this.createError(
|
|
18432
18432
|
RangeError,
|
|
18433
18433
|
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
@@ -18438,7 +18438,7 @@ var require_receiver = __commonJS({
|
|
|
18438
18438
|
cb(error);
|
|
18439
18439
|
return;
|
|
18440
18440
|
}
|
|
18441
|
-
this._payloadLength =
|
|
18441
|
+
this._payloadLength = num2 * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
18442
18442
|
this.haveLength(cb);
|
|
18443
18443
|
}
|
|
18444
18444
|
/**
|
|
@@ -22752,19 +22752,19 @@ var require_stream_readable = __commonJS({
|
|
|
22752
22752
|
var ret = p2.data;
|
|
22753
22753
|
n -= ret.length;
|
|
22754
22754
|
while (p2 = p2.next) {
|
|
22755
|
-
var
|
|
22756
|
-
var nb = n >
|
|
22757
|
-
if (nb ===
|
|
22758
|
-
else ret +=
|
|
22755
|
+
var str2 = p2.data;
|
|
22756
|
+
var nb = n > str2.length ? str2.length : n;
|
|
22757
|
+
if (nb === str2.length) ret += str2;
|
|
22758
|
+
else ret += str2.slice(0, n);
|
|
22759
22759
|
n -= nb;
|
|
22760
22760
|
if (n === 0) {
|
|
22761
|
-
if (nb ===
|
|
22761
|
+
if (nb === str2.length) {
|
|
22762
22762
|
++c;
|
|
22763
22763
|
if (p2.next) list.head = p2.next;
|
|
22764
22764
|
else list.head = list.tail = null;
|
|
22765
22765
|
} else {
|
|
22766
22766
|
list.head = p2;
|
|
22767
|
-
p2.data =
|
|
22767
|
+
p2.data = str2.slice(nb);
|
|
22768
22768
|
}
|
|
22769
22769
|
break;
|
|
22770
22770
|
}
|
|
@@ -23660,14 +23660,14 @@ var require_utils = __commonJS({
|
|
|
23660
23660
|
var nodejsUtils = require_nodejsUtils();
|
|
23661
23661
|
var external = require_external();
|
|
23662
23662
|
require_setImmediate();
|
|
23663
|
-
function string2binary(
|
|
23663
|
+
function string2binary(str2) {
|
|
23664
23664
|
var result = null;
|
|
23665
23665
|
if (support.uint8array) {
|
|
23666
|
-
result = new Uint8Array(
|
|
23666
|
+
result = new Uint8Array(str2.length);
|
|
23667
23667
|
} else {
|
|
23668
|
-
result = new Array(
|
|
23668
|
+
result = new Array(str2.length);
|
|
23669
23669
|
}
|
|
23670
|
-
return stringToArrayLike(
|
|
23670
|
+
return stringToArrayLike(str2, result);
|
|
23671
23671
|
}
|
|
23672
23672
|
exports2.newBlob = function(part, type) {
|
|
23673
23673
|
exports2.checkSupport("blob");
|
|
@@ -23689,9 +23689,9 @@ var require_utils = __commonJS({
|
|
|
23689
23689
|
function identity(input) {
|
|
23690
23690
|
return input;
|
|
23691
23691
|
}
|
|
23692
|
-
function stringToArrayLike(
|
|
23693
|
-
for (var i = 0; i <
|
|
23694
|
-
array[i] =
|
|
23692
|
+
function stringToArrayLike(str2, array) {
|
|
23693
|
+
for (var i = 0; i < str2.length; ++i) {
|
|
23694
|
+
array[i] = str2.charCodeAt(i) & 255;
|
|
23695
23695
|
}
|
|
23696
23696
|
return array;
|
|
23697
23697
|
}
|
|
@@ -23904,10 +23904,10 @@ var require_utils = __commonJS({
|
|
|
23904
23904
|
};
|
|
23905
23905
|
exports2.MAX_VALUE_16BITS = 65535;
|
|
23906
23906
|
exports2.MAX_VALUE_32BITS = -1;
|
|
23907
|
-
exports2.pretty = function(
|
|
23907
|
+
exports2.pretty = function(str2) {
|
|
23908
23908
|
var res = "", code, i;
|
|
23909
|
-
for (i = 0; i < (
|
|
23910
|
-
code =
|
|
23909
|
+
for (i = 0; i < (str2 || "").length; i++) {
|
|
23910
|
+
code = str2.charCodeAt(i);
|
|
23911
23911
|
res += "\\x" + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
|
|
23912
23912
|
}
|
|
23913
23913
|
return res;
|
|
@@ -24217,12 +24217,12 @@ var require_utf8 = __commonJS({
|
|
|
24217
24217
|
}
|
|
24218
24218
|
var i;
|
|
24219
24219
|
_utf8len[254] = _utf8len[254] = 1;
|
|
24220
|
-
var string2buf = function(
|
|
24221
|
-
var buf, c, c2, m_pos, i2, str_len =
|
|
24220
|
+
var string2buf = function(str2) {
|
|
24221
|
+
var buf, c, c2, m_pos, i2, str_len = str2.length, buf_len = 0;
|
|
24222
24222
|
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
|
24223
|
-
c =
|
|
24223
|
+
c = str2.charCodeAt(m_pos);
|
|
24224
24224
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
24225
|
-
c2 =
|
|
24225
|
+
c2 = str2.charCodeAt(m_pos + 1);
|
|
24226
24226
|
if ((c2 & 64512) === 56320) {
|
|
24227
24227
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
24228
24228
|
m_pos++;
|
|
@@ -24236,9 +24236,9 @@ var require_utf8 = __commonJS({
|
|
|
24236
24236
|
buf = new Array(buf_len);
|
|
24237
24237
|
}
|
|
24238
24238
|
for (i2 = 0, m_pos = 0; i2 < buf_len; m_pos++) {
|
|
24239
|
-
c =
|
|
24239
|
+
c = str2.charCodeAt(m_pos);
|
|
24240
24240
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
24241
|
-
c2 =
|
|
24241
|
+
c2 = str2.charCodeAt(m_pos + 1);
|
|
24242
24242
|
if ((c2 & 64512) === 56320) {
|
|
24243
24243
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
24244
24244
|
m_pos++;
|
|
@@ -24322,11 +24322,11 @@ var require_utf8 = __commonJS({
|
|
|
24322
24322
|
}
|
|
24323
24323
|
return utils.applyFromCharCode(utf16buf);
|
|
24324
24324
|
};
|
|
24325
|
-
exports2.utf8encode = function utf8encode(
|
|
24325
|
+
exports2.utf8encode = function utf8encode(str2) {
|
|
24326
24326
|
if (support.nodebuffer) {
|
|
24327
|
-
return nodejsUtils.newBufferFrom(
|
|
24327
|
+
return nodejsUtils.newBufferFrom(str2, "utf-8");
|
|
24328
24328
|
}
|
|
24329
|
-
return string2buf(
|
|
24329
|
+
return string2buf(str2);
|
|
24330
24330
|
};
|
|
24331
24331
|
exports2.utf8decode = function utf8decode(buf) {
|
|
24332
24332
|
if (support.nodebuffer) {
|
|
@@ -24735,11 +24735,11 @@ var require_crc32 = __commonJS({
|
|
|
24735
24735
|
}
|
|
24736
24736
|
return crc ^ -1;
|
|
24737
24737
|
}
|
|
24738
|
-
function crc32str(crc,
|
|
24738
|
+
function crc32str(crc, str2, len, pos) {
|
|
24739
24739
|
var t = crcTable, end = pos + len;
|
|
24740
24740
|
crc = crc ^ -1;
|
|
24741
24741
|
for (var i = pos; i < end; i++) {
|
|
24742
|
-
crc = crc >>> 8 ^ t[(crc ^
|
|
24742
|
+
crc = crc >>> 8 ^ t[(crc ^ str2.charCodeAt(i)) & 255];
|
|
24743
24743
|
}
|
|
24744
24744
|
return crc ^ -1;
|
|
24745
24745
|
}
|
|
@@ -25936,7 +25936,7 @@ var require_deflate = __commonJS({
|
|
|
25936
25936
|
}
|
|
25937
25937
|
function fill_window(s) {
|
|
25938
25938
|
var _w_size = s.w_size;
|
|
25939
|
-
var p2, n, m2, more,
|
|
25939
|
+
var p2, n, m2, more, str2;
|
|
25940
25940
|
do {
|
|
25941
25941
|
more = s.window_size - s.lookahead - s.strstart;
|
|
25942
25942
|
if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
|
|
@@ -25964,14 +25964,14 @@ var require_deflate = __commonJS({
|
|
|
25964
25964
|
n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
|
|
25965
25965
|
s.lookahead += n;
|
|
25966
25966
|
if (s.lookahead + s.insert >= MIN_MATCH) {
|
|
25967
|
-
|
|
25968
|
-
s.ins_h = s.window[
|
|
25969
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
25967
|
+
str2 = s.strstart - s.insert;
|
|
25968
|
+
s.ins_h = s.window[str2];
|
|
25969
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str2 + 1]) & s.hash_mask;
|
|
25970
25970
|
while (s.insert) {
|
|
25971
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
25972
|
-
s.prev[
|
|
25973
|
-
s.head[s.ins_h] =
|
|
25974
|
-
|
|
25971
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str2 + MIN_MATCH - 1]) & s.hash_mask;
|
|
25972
|
+
s.prev[str2 & s.w_mask] = s.head[s.ins_h];
|
|
25973
|
+
s.head[s.ins_h] = str2;
|
|
25974
|
+
str2++;
|
|
25975
25975
|
s.insert--;
|
|
25976
25976
|
if (s.lookahead + s.insert < MIN_MATCH) {
|
|
25977
25977
|
break;
|
|
@@ -26747,7 +26747,7 @@ var require_deflate = __commonJS({
|
|
|
26747
26747
|
function deflateSetDictionary(strm, dictionary) {
|
|
26748
26748
|
var dictLength = dictionary.length;
|
|
26749
26749
|
var s;
|
|
26750
|
-
var
|
|
26750
|
+
var str2, n;
|
|
26751
26751
|
var wrap2;
|
|
26752
26752
|
var avail;
|
|
26753
26753
|
var next;
|
|
@@ -26785,15 +26785,15 @@ var require_deflate = __commonJS({
|
|
|
26785
26785
|
strm.input = dictionary;
|
|
26786
26786
|
fill_window(s);
|
|
26787
26787
|
while (s.lookahead >= MIN_MATCH) {
|
|
26788
|
-
|
|
26788
|
+
str2 = s.strstart;
|
|
26789
26789
|
n = s.lookahead - (MIN_MATCH - 1);
|
|
26790
26790
|
do {
|
|
26791
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
26792
|
-
s.prev[
|
|
26793
|
-
s.head[s.ins_h] =
|
|
26794
|
-
|
|
26791
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str2 + MIN_MATCH - 1]) & s.hash_mask;
|
|
26792
|
+
s.prev[str2 & s.w_mask] = s.head[s.ins_h];
|
|
26793
|
+
s.head[s.ins_h] = str2;
|
|
26794
|
+
str2++;
|
|
26795
26795
|
} while (--n);
|
|
26796
|
-
s.strstart =
|
|
26796
|
+
s.strstart = str2;
|
|
26797
26797
|
s.lookahead = MIN_MATCH - 1;
|
|
26798
26798
|
fill_window(s);
|
|
26799
26799
|
}
|
|
@@ -26844,12 +26844,12 @@ var require_strings = __commonJS({
|
|
|
26844
26844
|
}
|
|
26845
26845
|
var q;
|
|
26846
26846
|
_utf8len[254] = _utf8len[254] = 1;
|
|
26847
|
-
exports2.string2buf = function(
|
|
26848
|
-
var buf, c, c2, m_pos, i, str_len =
|
|
26847
|
+
exports2.string2buf = function(str2) {
|
|
26848
|
+
var buf, c, c2, m_pos, i, str_len = str2.length, buf_len = 0;
|
|
26849
26849
|
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
|
26850
|
-
c =
|
|
26850
|
+
c = str2.charCodeAt(m_pos);
|
|
26851
26851
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
26852
|
-
c2 =
|
|
26852
|
+
c2 = str2.charCodeAt(m_pos + 1);
|
|
26853
26853
|
if ((c2 & 64512) === 56320) {
|
|
26854
26854
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
26855
26855
|
m_pos++;
|
|
@@ -26859,9 +26859,9 @@ var require_strings = __commonJS({
|
|
|
26859
26859
|
}
|
|
26860
26860
|
buf = new utils.Buf8(buf_len);
|
|
26861
26861
|
for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
|
|
26862
|
-
c =
|
|
26862
|
+
c = str2.charCodeAt(m_pos);
|
|
26863
26863
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
26864
|
-
c2 =
|
|
26864
|
+
c2 = str2.charCodeAt(m_pos + 1);
|
|
26865
26865
|
if ((c2 & 64512) === 56320) {
|
|
26866
26866
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
26867
26867
|
m_pos++;
|
|
@@ -26900,10 +26900,10 @@ var require_strings = __commonJS({
|
|
|
26900
26900
|
exports2.buf2binstring = function(buf) {
|
|
26901
26901
|
return buf2binstring(buf, buf.length);
|
|
26902
26902
|
};
|
|
26903
|
-
exports2.binstring2buf = function(
|
|
26904
|
-
var buf = new utils.Buf8(
|
|
26903
|
+
exports2.binstring2buf = function(str2) {
|
|
26904
|
+
var buf = new utils.Buf8(str2.length);
|
|
26905
26905
|
for (var i = 0, len = buf.length; i < len; i++) {
|
|
26906
|
-
buf[i] =
|
|
26906
|
+
buf[i] = str2.charCodeAt(i);
|
|
26907
26907
|
}
|
|
26908
26908
|
return buf;
|
|
26909
26909
|
};
|
|
@@ -30745,8 +30745,8 @@ function startRunCaseRecorder(opts) {
|
|
|
30745
30745
|
});
|
|
30746
30746
|
const ensureStream = () => {
|
|
30747
30747
|
if (stream) return stream;
|
|
30748
|
-
|
|
30749
|
-
stream =
|
|
30748
|
+
import_node_fs34.default.mkdirSync(dir, { recursive: true });
|
|
30749
|
+
stream = import_node_fs34.default.createWriteStream(opts.recordPath, { flags: "a" });
|
|
30750
30750
|
stream.on("close", () => closedResolve());
|
|
30751
30751
|
return stream;
|
|
30752
30752
|
};
|
|
@@ -30771,11 +30771,11 @@ function startRunCaseRecorder(opts) {
|
|
|
30771
30771
|
};
|
|
30772
30772
|
return { tap, close, closed };
|
|
30773
30773
|
}
|
|
30774
|
-
var
|
|
30774
|
+
var import_node_fs34, import_node_path47;
|
|
30775
30775
|
var init_recorder = __esm({
|
|
30776
30776
|
"src/run-case/recorder.ts"() {
|
|
30777
30777
|
"use strict";
|
|
30778
|
-
|
|
30778
|
+
import_node_fs34 = __toESM(require("fs"), 1);
|
|
30779
30779
|
import_node_path47 = __toESM(require("path"), 1);
|
|
30780
30780
|
}
|
|
30781
30781
|
});
|
|
@@ -30819,7 +30819,7 @@ var init_wire = __esm({
|
|
|
30819
30819
|
// src/run-case/controller.ts
|
|
30820
30820
|
async function runController(opts) {
|
|
30821
30821
|
const now = opts.now ?? Date.now;
|
|
30822
|
-
const cwd = opts.cwd ?? (0,
|
|
30822
|
+
const cwd = opts.cwd ?? (0, import_node_fs35.mkdtempSync)(import_node_path48.default.join(import_node_os19.default.tmpdir(), "clawd-runcase-"));
|
|
30823
30823
|
const ownsCwd = opts.cwd === void 0;
|
|
30824
30824
|
const recorder = startRunCaseRecorder({ recordPath: opts.record, now });
|
|
30825
30825
|
const spawnCtx = { cwd };
|
|
@@ -30980,17 +30980,17 @@ async function runController(opts) {
|
|
|
30980
30980
|
if (sigintHandler) process.off("SIGINT", sigintHandler);
|
|
30981
30981
|
if (ownsCwd) {
|
|
30982
30982
|
try {
|
|
30983
|
-
(0,
|
|
30983
|
+
(0, import_node_fs35.rmSync)(cwd, { recursive: true, force: true });
|
|
30984
30984
|
} catch {
|
|
30985
30985
|
}
|
|
30986
30986
|
}
|
|
30987
30987
|
return exitCode ?? 0;
|
|
30988
30988
|
}
|
|
30989
|
-
var
|
|
30989
|
+
var import_node_fs35, import_node_os19, import_node_path48;
|
|
30990
30990
|
var init_controller = __esm({
|
|
30991
30991
|
"src/run-case/controller.ts"() {
|
|
30992
30992
|
"use strict";
|
|
30993
|
-
|
|
30993
|
+
import_node_fs35 = require("fs");
|
|
30994
30994
|
import_node_os19 = __toESM(require("os"), 1);
|
|
30995
30995
|
import_node_path48 = __toESM(require("path"), 1);
|
|
30996
30996
|
init_claude();
|
|
@@ -31228,7 +31228,7 @@ Env (advanced):
|
|
|
31228
31228
|
|
|
31229
31229
|
// src/index.ts
|
|
31230
31230
|
var import_node_path46 = __toESM(require("path"), 1);
|
|
31231
|
-
var
|
|
31231
|
+
var import_node_fs33 = __toESM(require("fs"), 1);
|
|
31232
31232
|
|
|
31233
31233
|
// src/logger.ts
|
|
31234
31234
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
@@ -35197,8 +35197,398 @@ function refreshDaemonManagedDirs(args) {
|
|
|
35197
35197
|
// src/index.ts
|
|
35198
35198
|
init_claude();
|
|
35199
35199
|
|
|
35200
|
-
// src/tools/
|
|
35200
|
+
// src/tools/codex.ts
|
|
35201
|
+
var import_node_child_process4 = require("child_process");
|
|
35201
35202
|
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
35203
|
+
|
|
35204
|
+
// src/tools/codex-session.ts
|
|
35205
|
+
var import_node_child_process3 = require("child_process");
|
|
35206
|
+
|
|
35207
|
+
// src/tools/codex-app-server-client.ts
|
|
35208
|
+
var import_node_readline = require("readline");
|
|
35209
|
+
var CodexAppServerClient = class {
|
|
35210
|
+
constructor(proc, opts = {}) {
|
|
35211
|
+
this.proc = proc;
|
|
35212
|
+
this.opts = opts;
|
|
35213
|
+
const rl = (0, import_node_readline.createInterface)({ input: proc.stdout, crlfDelay: Infinity });
|
|
35214
|
+
rl.on("line", (l) => this.onLine(l));
|
|
35215
|
+
rl.on("close", () => {
|
|
35216
|
+
for (const p2 of this.pending.values()) p2.reject(new Error("app-server connection closed"));
|
|
35217
|
+
this.pending.clear();
|
|
35218
|
+
this.opts.onClose?.();
|
|
35219
|
+
});
|
|
35220
|
+
}
|
|
35221
|
+
proc;
|
|
35222
|
+
opts;
|
|
35223
|
+
nextId = 1;
|
|
35224
|
+
pending = /* @__PURE__ */ new Map();
|
|
35225
|
+
request(method, params) {
|
|
35226
|
+
const id = this.nextId++;
|
|
35227
|
+
return new Promise((resolve6, reject) => {
|
|
35228
|
+
this.pending.set(id, { resolve: resolve6, reject });
|
|
35229
|
+
this.write({ jsonrpc: "2.0", method, id, params });
|
|
35230
|
+
});
|
|
35231
|
+
}
|
|
35232
|
+
notify(method, params) {
|
|
35233
|
+
this.write({ jsonrpc: "2.0", method, params });
|
|
35234
|
+
}
|
|
35235
|
+
respond(id, result) {
|
|
35236
|
+
this.write({ id, result });
|
|
35237
|
+
}
|
|
35238
|
+
onLine(line) {
|
|
35239
|
+
const t = line.trim();
|
|
35240
|
+
if (!t) return;
|
|
35241
|
+
let m2;
|
|
35242
|
+
try {
|
|
35243
|
+
m2 = JSON.parse(t);
|
|
35244
|
+
} catch {
|
|
35245
|
+
return;
|
|
35246
|
+
}
|
|
35247
|
+
if (!isRecord(m2)) return;
|
|
35248
|
+
const hasId = typeof m2.id === "number", hasMethod = typeof m2.method === "string";
|
|
35249
|
+
if (hasId && !hasMethod) {
|
|
35250
|
+
const p2 = this.pending.get(m2.id);
|
|
35251
|
+
if (!p2) return;
|
|
35252
|
+
this.pending.delete(m2.id);
|
|
35253
|
+
if (m2.error) {
|
|
35254
|
+
const e = isRecord(m2.error) ? m2.error : {};
|
|
35255
|
+
p2.reject(new Error(typeof e.message === "string" ? e.message : "app-server error"));
|
|
35256
|
+
} else p2.resolve(m2.result);
|
|
35257
|
+
return;
|
|
35258
|
+
}
|
|
35259
|
+
if (hasId && hasMethod) {
|
|
35260
|
+
this.opts.onServerRequest?.(m2.id, m2.method, m2.params);
|
|
35261
|
+
return;
|
|
35262
|
+
}
|
|
35263
|
+
if (hasMethod) this.opts.onNotification?.(m2.method, m2.params);
|
|
35264
|
+
}
|
|
35265
|
+
write(o) {
|
|
35266
|
+
this.proc.stdin.write(JSON.stringify(o) + "\n");
|
|
35267
|
+
}
|
|
35268
|
+
};
|
|
35269
|
+
function isRecord(v2) {
|
|
35270
|
+
return typeof v2 === "object" && v2 !== null;
|
|
35271
|
+
}
|
|
35272
|
+
|
|
35273
|
+
// src/tools/codex-app-server-events.ts
|
|
35274
|
+
function translateNotification(method, params) {
|
|
35275
|
+
const p2 = rec(params);
|
|
35276
|
+
switch (method) {
|
|
35277
|
+
case "thread/started": {
|
|
35278
|
+
const id = str(rec(p2?.thread)?.id);
|
|
35279
|
+
return id ? [{ kind: "session_init", toolSessionId: id }] : [];
|
|
35280
|
+
}
|
|
35281
|
+
case "item/agentMessage/delta": {
|
|
35282
|
+
const text = str(p2?.delta);
|
|
35283
|
+
const id = str(p2?.itemId);
|
|
35284
|
+
return text ? [{ kind: "text", text, ...id ? { partialId: id } : {} }] : [];
|
|
35285
|
+
}
|
|
35286
|
+
case "item/reasoning/textDelta":
|
|
35287
|
+
case "item/reasoning/summaryTextDelta": {
|
|
35288
|
+
const text = str(p2?.delta);
|
|
35289
|
+
const id = str(p2?.itemId);
|
|
35290
|
+
return text ? [{ kind: "thinking", text, ...id ? { partialId: id } : {} }] : [];
|
|
35291
|
+
}
|
|
35292
|
+
case "item/commandExecution/outputDelta":
|
|
35293
|
+
return [];
|
|
35294
|
+
// 命令输出增量 v1 不逐字(完成时整段给)
|
|
35295
|
+
case "item/started":
|
|
35296
|
+
return itemStarted(rec(p2?.item));
|
|
35297
|
+
case "item/completed":
|
|
35298
|
+
return itemCompleted(rec(p2?.item));
|
|
35299
|
+
case "thread/tokenUsage/updated":
|
|
35300
|
+
return tokenUsage(rec(rec(p2?.tokenUsage)));
|
|
35301
|
+
case "turn/completed":
|
|
35302
|
+
return turnCompleted(rec(p2?.turn));
|
|
35303
|
+
default:
|
|
35304
|
+
return [];
|
|
35305
|
+
}
|
|
35306
|
+
}
|
|
35307
|
+
function itemStarted(item) {
|
|
35308
|
+
if (!item || item.type !== "commandExecution") return [];
|
|
35309
|
+
const id = str(item.id);
|
|
35310
|
+
if (!id) return [];
|
|
35311
|
+
return [{ kind: "tool_call", toolUseId: id, tool: "commandExecution", toolKind: "codex", input: { command: str(item.command) ?? "" } }];
|
|
35312
|
+
}
|
|
35313
|
+
function itemCompleted(item) {
|
|
35314
|
+
if (!item) return [];
|
|
35315
|
+
switch (item.type) {
|
|
35316
|
+
case "userMessage":
|
|
35317
|
+
return [];
|
|
35318
|
+
// 用户输入回显, clawd 自己 synthesize user_text
|
|
35319
|
+
case "agentMessage": {
|
|
35320
|
+
const text = str(item.text);
|
|
35321
|
+
return text ? [{ kind: "text", text }] : [];
|
|
35322
|
+
}
|
|
35323
|
+
case "reasoning": {
|
|
35324
|
+
const text = str(item.text);
|
|
35325
|
+
return text ? [{ kind: "thinking", text }] : [];
|
|
35326
|
+
}
|
|
35327
|
+
case "commandExecution": {
|
|
35328
|
+
const id = str(item.id);
|
|
35329
|
+
if (!id) return [];
|
|
35330
|
+
const exit = num(item.exitCode);
|
|
35331
|
+
const ev = { kind: "tool_result", toolUseId: id, output: str(item.aggregatedOutput ?? item.output) ?? "" };
|
|
35332
|
+
if (exit !== void 0 && exit !== 0) ev.error = `exit ${exit}`;
|
|
35333
|
+
return [ev];
|
|
35334
|
+
}
|
|
35335
|
+
default:
|
|
35336
|
+
return [];
|
|
35337
|
+
}
|
|
35338
|
+
}
|
|
35339
|
+
function tokenUsage(usage) {
|
|
35340
|
+
if (!usage) return [];
|
|
35341
|
+
const total = rec(usage.total);
|
|
35342
|
+
if (!total) return [];
|
|
35343
|
+
const i = num(total.inputTokens), o = num(total.outputTokens), c = num(total.cachedInputTokens);
|
|
35344
|
+
const patch = {};
|
|
35345
|
+
if (i !== void 0 && o !== void 0) patch.contextUsage = { inputTokens: i, outputTokens: o, ...c !== void 0 ? { cacheReadTokens: c } : {} };
|
|
35346
|
+
const w2 = num(usage.modelContextWindow);
|
|
35347
|
+
if (w2 !== void 0) patch.contextWindowSize = w2;
|
|
35348
|
+
return Object.keys(patch).length ? [{ kind: "meta_update", patch }] : [];
|
|
35349
|
+
}
|
|
35350
|
+
function turnCompleted(turn) {
|
|
35351
|
+
if (turn?.status === "failed") return [{ kind: "error", message: str(rec(turn.error)?.message) ?? "codex turn failed" }, { kind: "turn_end" }];
|
|
35352
|
+
return [{ kind: "turn_end" }];
|
|
35353
|
+
}
|
|
35354
|
+
function rec(v2) {
|
|
35355
|
+
return typeof v2 === "object" && v2 !== null ? v2 : void 0;
|
|
35356
|
+
}
|
|
35357
|
+
function str(v2) {
|
|
35358
|
+
return typeof v2 === "string" ? v2 : void 0;
|
|
35359
|
+
}
|
|
35360
|
+
function num(v2) {
|
|
35361
|
+
return typeof v2 === "number" ? v2 : void 0;
|
|
35362
|
+
}
|
|
35363
|
+
|
|
35364
|
+
// src/tools/codex-app-server-params.ts
|
|
35365
|
+
function resolveSandbox(ctx) {
|
|
35366
|
+
if (ctx.personaMode === "guest") throw new Error("codex \u6682\u4E0D\u652F\u6301 guest persona session\uFF1B\u8BF7\u7528 claude \u6216 owner");
|
|
35367
|
+
if (ctx.personaMode === "owner") return "danger-full-access";
|
|
35368
|
+
const m2 = ctx.permissionMode ?? "";
|
|
35369
|
+
if (m2 === "") return "workspace-write";
|
|
35370
|
+
if (m2 === "read-only" || m2 === "workspace-write" || m2 === "danger-full-access") return m2;
|
|
35371
|
+
throw new Error(`unknown codex sandbox/permissionMode: ${m2}`);
|
|
35372
|
+
}
|
|
35373
|
+
function threadStartParams(ctx) {
|
|
35374
|
+
return {
|
|
35375
|
+
cwd: ctx.cwd,
|
|
35376
|
+
sandbox: resolveSandbox(ctx),
|
|
35377
|
+
approvalPolicy: ctx.personaMode === "owner" ? "never" : "on-request",
|
|
35378
|
+
approvalsReviewer: "user",
|
|
35379
|
+
...ctx.model ? { model: ctx.model } : {}
|
|
35380
|
+
};
|
|
35381
|
+
}
|
|
35382
|
+
var ATTACHMENT_RE2 = /\[attachment:(image|file):([^\]]+)\]/g;
|
|
35383
|
+
function turnStartInput(text) {
|
|
35384
|
+
const items = [];
|
|
35385
|
+
let leftover = text;
|
|
35386
|
+
for (const m2 of text.matchAll(ATTACHMENT_RE2)) {
|
|
35387
|
+
const [marker, kind, url] = m2;
|
|
35388
|
+
if (kind === "image") {
|
|
35389
|
+
items.push({ type: "image", url });
|
|
35390
|
+
leftover = leftover.replace(marker, "");
|
|
35391
|
+
}
|
|
35392
|
+
}
|
|
35393
|
+
const trimmed = leftover.trim();
|
|
35394
|
+
if (trimmed || items.length === 0) items.push({ type: "text", text: trimmed, text_elements: [] });
|
|
35395
|
+
return items;
|
|
35396
|
+
}
|
|
35397
|
+
|
|
35398
|
+
// src/tools/codex-session.ts
|
|
35399
|
+
function createCodexSession(ctx, sink, deps = {}) {
|
|
35400
|
+
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
35401
|
+
const args = ["app-server", "--listen", "stdio://"];
|
|
35402
|
+
const env = { ...process.env, ...ctx.env };
|
|
35403
|
+
const proc = deps.spawnOverride ? deps.spawnOverride(cmd, args, ctx.cwd, env) : (0, import_node_child_process3.spawn)(cmd, args, { cwd: ctx.cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
35404
|
+
let threadId = ctx.toolSessionId;
|
|
35405
|
+
let turnId;
|
|
35406
|
+
const approvalIds = /* @__PURE__ */ new Map();
|
|
35407
|
+
const pendingQuestions = /* @__PURE__ */ new Map();
|
|
35408
|
+
let pendingSystemPrompt = ctx.toolSessionId ? void 0 : ctx.extraSystemPrompt;
|
|
35409
|
+
let exited = false;
|
|
35410
|
+
const finish = (code) => {
|
|
35411
|
+
if (exited) return;
|
|
35412
|
+
exited = true;
|
|
35413
|
+
sink.onExit(code);
|
|
35414
|
+
};
|
|
35415
|
+
const client = new CodexAppServerClient(proc, {
|
|
35416
|
+
onNotification: (method, params) => {
|
|
35417
|
+
if (method === "turn/started") {
|
|
35418
|
+
const id = params?.turn?.id;
|
|
35419
|
+
if (id) turnId = id;
|
|
35420
|
+
}
|
|
35421
|
+
const events = translateNotification(method, params);
|
|
35422
|
+
if (events.length) sink.pushEvents(events);
|
|
35423
|
+
},
|
|
35424
|
+
onServerRequest: (id, method, params) => {
|
|
35425
|
+
const p2 = params ?? {};
|
|
35426
|
+
if (method === "item/commandExecution/requestApproval" || method === "item/fileChange/requestApproval") {
|
|
35427
|
+
const reqId = String(id);
|
|
35428
|
+
approvalIds.set(reqId, id);
|
|
35429
|
+
sink.pushEvents([
|
|
35430
|
+
{
|
|
35431
|
+
kind: "permission_request",
|
|
35432
|
+
requestId: reqId,
|
|
35433
|
+
tool: method.includes("fileChange") ? "fileChange" : "commandExecution",
|
|
35434
|
+
input: p2,
|
|
35435
|
+
...typeof p2.itemId === "string" ? { toolUseId: p2.itemId } : {}
|
|
35436
|
+
}
|
|
35437
|
+
]);
|
|
35438
|
+
return;
|
|
35439
|
+
}
|
|
35440
|
+
if (method === "tool/requestUserInput") {
|
|
35441
|
+
const reqId = String(id);
|
|
35442
|
+
approvalIds.set(reqId, id);
|
|
35443
|
+
const texts = Array.isArray(p2.questions) ? p2.questions.map((q) => String(q.question ?? "")) : [];
|
|
35444
|
+
pendingQuestions.set(reqId, texts);
|
|
35445
|
+
const questions = texts.map((question) => ({
|
|
35446
|
+
question,
|
|
35447
|
+
multiSelect: false,
|
|
35448
|
+
options: []
|
|
35449
|
+
}));
|
|
35450
|
+
sink.pushEvents([{ kind: "ask_user_question", toolUseId: reqId, questions }]);
|
|
35451
|
+
return;
|
|
35452
|
+
}
|
|
35453
|
+
client.respond(id, "cancel");
|
|
35454
|
+
},
|
|
35455
|
+
onClose: () => finish(proc.exitCode)
|
|
35456
|
+
});
|
|
35457
|
+
proc.stderr?.on(
|
|
35458
|
+
"data",
|
|
35459
|
+
(c) => deps.logger?.warn("codex app-server stderr", { line: c.toString().slice(0, 500) })
|
|
35460
|
+
);
|
|
35461
|
+
proc.on("exit", (code) => finish(code));
|
|
35462
|
+
const ready = (async () => {
|
|
35463
|
+
await client.request("initialize", {
|
|
35464
|
+
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
35465
|
+
capabilities: null
|
|
35466
|
+
});
|
|
35467
|
+
client.notify("initialized", {});
|
|
35468
|
+
if (threadId) {
|
|
35469
|
+
await client.request("thread/resume", { threadId });
|
|
35470
|
+
} else {
|
|
35471
|
+
const res = await client.request("thread/start", threadStartParams(ctx));
|
|
35472
|
+
threadId = res?.thread?.id;
|
|
35473
|
+
if (threadId) sink.pushEvents([{ kind: "session_init", toolSessionId: threadId }]);
|
|
35474
|
+
}
|
|
35475
|
+
})().catch((e) => sink.onError(`codex app-server init failed: ${e.message}`));
|
|
35476
|
+
return {
|
|
35477
|
+
startTurn(text) {
|
|
35478
|
+
const body = pendingSystemPrompt ? `${pendingSystemPrompt}
|
|
35479
|
+
|
|
35480
|
+
${text}` : text;
|
|
35481
|
+
pendingSystemPrompt = void 0;
|
|
35482
|
+
void ready.then(() => {
|
|
35483
|
+
if (threadId)
|
|
35484
|
+
void client.request("turn/start", { threadId, input: turnStartInput(body) }).catch((e) => sink.onError(`turn/start failed: ${e.message}`));
|
|
35485
|
+
});
|
|
35486
|
+
},
|
|
35487
|
+
respondPermission(requestId, allow) {
|
|
35488
|
+
const id = approvalIds.get(requestId);
|
|
35489
|
+
if (id === void 0) return;
|
|
35490
|
+
approvalIds.delete(requestId);
|
|
35491
|
+
client.respond(id, allow ? "accept" : "cancel");
|
|
35492
|
+
},
|
|
35493
|
+
answerQuestion(requestId, answers) {
|
|
35494
|
+
const id = approvalIds.get(requestId);
|
|
35495
|
+
if (id === void 0) return;
|
|
35496
|
+
approvalIds.delete(requestId);
|
|
35497
|
+
const qs = pendingQuestions.get(requestId) ?? [];
|
|
35498
|
+
pendingQuestions.delete(requestId);
|
|
35499
|
+
client.respond(id, { answers: qs.map((q) => answers[q] ?? "") });
|
|
35500
|
+
},
|
|
35501
|
+
interrupt() {
|
|
35502
|
+
if (threadId && turnId) void client.request("turn/interrupt", { threadId, turnId }).catch(() => {
|
|
35503
|
+
});
|
|
35504
|
+
},
|
|
35505
|
+
async stop() {
|
|
35506
|
+
this.interrupt();
|
|
35507
|
+
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
35508
|
+
}
|
|
35509
|
+
};
|
|
35510
|
+
}
|
|
35511
|
+
|
|
35512
|
+
// src/tools/codex.ts
|
|
35513
|
+
var CODEX_MODELS = [
|
|
35514
|
+
{ id: "", label: "Default", description: "codex \u9ED8\u8BA4 model(config.toml)", contextWindowSize: 258400, default: true }
|
|
35515
|
+
];
|
|
35516
|
+
var CODEX_SANDBOX_MODES = [
|
|
35517
|
+
{ id: "read-only", label: "Read-only", description: "\u53EA\u8BFB" },
|
|
35518
|
+
{ id: "workspace-write", label: "Workspace", description: "\u53EF\u5199\u5DE5\u4F5C\u533A + \u672C\u5730\u547D\u4EE4(\u9ED8\u8BA4)" },
|
|
35519
|
+
{ id: "danger-full-access", label: "Full access", description: "\u65E0\u6C99\u7BB1(\u542B\u7F51\u7EDC)" }
|
|
35520
|
+
];
|
|
35521
|
+
var CODEX_CAPABILITIES = {
|
|
35522
|
+
tool: "codex",
|
|
35523
|
+
toolSessionIdLabel: "Codex Thread ID",
|
|
35524
|
+
models: CODEX_MODELS,
|
|
35525
|
+
permissionModes: CODEX_SANDBOX_MODES,
|
|
35526
|
+
configSchema: [
|
|
35527
|
+
{
|
|
35528
|
+
name: "model",
|
|
35529
|
+
type: "select",
|
|
35530
|
+
label: "Model",
|
|
35531
|
+
scope: "core",
|
|
35532
|
+
options: CODEX_MODELS.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35533
|
+
default: ""
|
|
35534
|
+
},
|
|
35535
|
+
{
|
|
35536
|
+
name: "permissionMode",
|
|
35537
|
+
type: "select",
|
|
35538
|
+
label: "Sandbox",
|
|
35539
|
+
scope: "core",
|
|
35540
|
+
options: CODEX_SANDBOX_MODES.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35541
|
+
default: "workspace-write"
|
|
35542
|
+
}
|
|
35543
|
+
]
|
|
35544
|
+
};
|
|
35545
|
+
async function probeCodex(env = process.env) {
|
|
35546
|
+
if (env.CODEX_BIN && import_node_fs10.default.existsSync(env.CODEX_BIN)) return { available: true, path: env.CODEX_BIN };
|
|
35547
|
+
try {
|
|
35548
|
+
const out = (0, import_node_child_process4.execFileSync)("which", ["codex"], { encoding: "utf8" }).trim();
|
|
35549
|
+
if (out && import_node_fs10.default.existsSync(out)) return { available: true, path: out };
|
|
35550
|
+
} catch {
|
|
35551
|
+
}
|
|
35552
|
+
return { available: false };
|
|
35553
|
+
}
|
|
35554
|
+
var CodexAdapter = class {
|
|
35555
|
+
id = "codex";
|
|
35556
|
+
probeCache = null;
|
|
35557
|
+
logger;
|
|
35558
|
+
probeOverride;
|
|
35559
|
+
constructor(opts = {}) {
|
|
35560
|
+
this.logger = opts.logger;
|
|
35561
|
+
this.probeOverride = opts.probeOverride;
|
|
35562
|
+
}
|
|
35563
|
+
async probe() {
|
|
35564
|
+
if (this.probeCache) return this.probeCache;
|
|
35565
|
+
this.probeCache = this.probeOverride ? await this.probeOverride() : await probeCodex();
|
|
35566
|
+
return this.probeCache;
|
|
35567
|
+
}
|
|
35568
|
+
async capabilities() {
|
|
35569
|
+
return CODEX_CAPABILITIES;
|
|
35570
|
+
}
|
|
35571
|
+
resolveContextWindow(modelId) {
|
|
35572
|
+
return (CODEX_MODELS.find((m2) => m2.id === (modelId ?? "")) ?? CODEX_MODELS[0]).contextWindowSize;
|
|
35573
|
+
}
|
|
35574
|
+
createSession(ctx, sink) {
|
|
35575
|
+
return createCodexSession(ctx, sink, { logger: this.logger });
|
|
35576
|
+
}
|
|
35577
|
+
spawn(_ctx) {
|
|
35578
|
+
throw new Error("CodexAdapter uses createSession, not spawn");
|
|
35579
|
+
}
|
|
35580
|
+
parseLine(_line) {
|
|
35581
|
+
return [];
|
|
35582
|
+
}
|
|
35583
|
+
// 原样返回带 marker 的文本;附件 marker → codex image 多模态由 turnStartInput 解析
|
|
35584
|
+
// (codex-app-server-params.ts, PR1)。encodeStdin 不动 markers。
|
|
35585
|
+
encodeStdin(text, _ctx) {
|
|
35586
|
+
return text;
|
|
35587
|
+
}
|
|
35588
|
+
};
|
|
35589
|
+
|
|
35590
|
+
// src/tools/claude-tui.ts
|
|
35591
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
35202
35592
|
var import_node_os5 = __toESM(require("os"), 1);
|
|
35203
35593
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
35204
35594
|
var import_headless = __toESM(require_xterm_headless(), 1);
|
|
@@ -36182,7 +36572,7 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36182
36572
|
const home = import_node_os5.default.homedir();
|
|
36183
36573
|
const file = import_node_path10.default.join(home, ".claude", "projects", cwdToHashDir(ctx.cwd), `${ctx.toolSessionId}.jsonl`);
|
|
36184
36574
|
try {
|
|
36185
|
-
return
|
|
36575
|
+
return import_node_fs11.default.statSync(file).isFile();
|
|
36186
36576
|
} catch {
|
|
36187
36577
|
return false;
|
|
36188
36578
|
}
|
|
@@ -36192,7 +36582,7 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36192
36582
|
init_claude_history();
|
|
36193
36583
|
|
|
36194
36584
|
// src/workspace/browser.ts
|
|
36195
|
-
var
|
|
36585
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
36196
36586
|
var import_node_os6 = __toESM(require("os"), 1);
|
|
36197
36587
|
var import_node_path11 = __toESM(require("path"), 1);
|
|
36198
36588
|
init_protocol();
|
|
@@ -36208,7 +36598,7 @@ function resolveInsideCwd(cwd, subpath) {
|
|
|
36208
36598
|
}
|
|
36209
36599
|
function ensureCwd(cwd) {
|
|
36210
36600
|
try {
|
|
36211
|
-
const stat =
|
|
36601
|
+
const stat = import_node_fs12.default.statSync(cwd);
|
|
36212
36602
|
if (!stat.isDirectory()) {
|
|
36213
36603
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${cwd}`);
|
|
36214
36604
|
}
|
|
@@ -36222,7 +36612,7 @@ var WorkspaceBrowser = class {
|
|
|
36222
36612
|
const cwd = args.cwd && args.cwd.length > 0 ? args.cwd : import_node_os6.default.homedir();
|
|
36223
36613
|
ensureCwd(cwd);
|
|
36224
36614
|
const full = resolveInsideCwd(cwd, args.path);
|
|
36225
|
-
const dirents =
|
|
36615
|
+
const dirents = import_node_fs12.default.readdirSync(full, { withFileTypes: true });
|
|
36226
36616
|
const entries = [];
|
|
36227
36617
|
for (const d of dirents) {
|
|
36228
36618
|
if (!args.showHidden && d.name.startsWith(".")) continue;
|
|
@@ -36232,7 +36622,7 @@ var WorkspaceBrowser = class {
|
|
|
36232
36622
|
mtime: ""
|
|
36233
36623
|
};
|
|
36234
36624
|
try {
|
|
36235
|
-
const st =
|
|
36625
|
+
const st = import_node_fs12.default.statSync(import_node_path11.default.join(full, d.name));
|
|
36236
36626
|
entry.mtime = new Date(st.mtimeMs).toISOString();
|
|
36237
36627
|
if (d.isFile()) entry.size = st.size;
|
|
36238
36628
|
} catch {
|
|
@@ -36248,14 +36638,14 @@ var WorkspaceBrowser = class {
|
|
|
36248
36638
|
read(args) {
|
|
36249
36639
|
ensureCwd(args.cwd);
|
|
36250
36640
|
const full = resolveInsideCwd(args.cwd, args.path);
|
|
36251
|
-
const st =
|
|
36641
|
+
const st = import_node_fs12.default.statSync(full);
|
|
36252
36642
|
if (!st.isFile()) {
|
|
36253
36643
|
throw new ClawdError(ERROR_CODES.INVALID_PATH, `not a file: ${args.path}`);
|
|
36254
36644
|
}
|
|
36255
36645
|
if (st.size > MAX_FILE_BYTES) {
|
|
36256
36646
|
throw new ClawdError(ERROR_CODES.FILE_TOO_LARGE, `file > ${MAX_FILE_BYTES} bytes`);
|
|
36257
36647
|
}
|
|
36258
|
-
const buf =
|
|
36648
|
+
const buf = import_node_fs12.default.readFileSync(full);
|
|
36259
36649
|
const isBinary = buf.includes(0);
|
|
36260
36650
|
if (isBinary) {
|
|
36261
36651
|
return {
|
|
@@ -36277,20 +36667,20 @@ var WorkspaceBrowser = class {
|
|
|
36277
36667
|
};
|
|
36278
36668
|
|
|
36279
36669
|
// src/skills/agents-scanner.ts
|
|
36280
|
-
var
|
|
36670
|
+
var import_node_fs13 = __toESM(require("fs"), 1);
|
|
36281
36671
|
var import_node_os7 = __toESM(require("os"), 1);
|
|
36282
36672
|
var import_node_path12 = __toESM(require("path"), 1);
|
|
36283
36673
|
var DEFAULT_POLICY_DIR_DARWIN = "/Library/Application Support/ClaudeCode/.claude/agents";
|
|
36284
36674
|
function isDirLikeSync2(p2) {
|
|
36285
36675
|
try {
|
|
36286
|
-
return
|
|
36676
|
+
return import_node_fs13.default.statSync(p2).isDirectory();
|
|
36287
36677
|
} catch {
|
|
36288
36678
|
return false;
|
|
36289
36679
|
}
|
|
36290
36680
|
}
|
|
36291
36681
|
function fileExistsSync(p2) {
|
|
36292
36682
|
try {
|
|
36293
|
-
return
|
|
36683
|
+
return import_node_fs13.default.statSync(p2).isFile();
|
|
36294
36684
|
} catch {
|
|
36295
36685
|
return false;
|
|
36296
36686
|
}
|
|
@@ -36298,7 +36688,7 @@ function fileExistsSync(p2) {
|
|
|
36298
36688
|
function parseAgentFile(filePath) {
|
|
36299
36689
|
let content;
|
|
36300
36690
|
try {
|
|
36301
|
-
content =
|
|
36691
|
+
content = import_node_fs13.default.readFileSync(filePath, "utf8");
|
|
36302
36692
|
} catch {
|
|
36303
36693
|
return {};
|
|
36304
36694
|
}
|
|
@@ -36311,7 +36701,7 @@ function parseAgentFile(filePath) {
|
|
|
36311
36701
|
function scanAgentsDir(dir, source, seen, out) {
|
|
36312
36702
|
let entries;
|
|
36313
36703
|
try {
|
|
36314
|
-
entries =
|
|
36704
|
+
entries = import_node_fs13.default.readdirSync(dir, { withFileTypes: true });
|
|
36315
36705
|
} catch {
|
|
36316
36706
|
return;
|
|
36317
36707
|
}
|
|
@@ -36338,7 +36728,7 @@ function scanPluginAgentsTree(root, pluginName, seen, out) {
|
|
|
36338
36728
|
function walk2(dir, namespaces) {
|
|
36339
36729
|
let entries;
|
|
36340
36730
|
try {
|
|
36341
|
-
entries =
|
|
36731
|
+
entries = import_node_fs13.default.readdirSync(dir, { withFileTypes: true });
|
|
36342
36732
|
} catch {
|
|
36343
36733
|
return;
|
|
36344
36734
|
}
|
|
@@ -36374,7 +36764,7 @@ function readInstalledPlugins2(home) {
|
|
|
36374
36764
|
let raw = null;
|
|
36375
36765
|
for (const candidate of [v2, v1]) {
|
|
36376
36766
|
try {
|
|
36377
|
-
raw =
|
|
36767
|
+
raw = import_node_fs13.default.readFileSync(candidate, "utf8");
|
|
36378
36768
|
break;
|
|
36379
36769
|
} catch {
|
|
36380
36770
|
}
|
|
@@ -36405,7 +36795,7 @@ function walkUpProjectAgentsDirs(startCwd, home, seen, out) {
|
|
|
36405
36795
|
scanAgentsDir(import_node_path12.default.join(cur, ".claude", "agents"), "project", seen, out);
|
|
36406
36796
|
let hasGit = false;
|
|
36407
36797
|
try {
|
|
36408
|
-
hasGit =
|
|
36798
|
+
hasGit = import_node_fs13.default.existsSync(import_node_path12.default.join(cur, ".git"));
|
|
36409
36799
|
} catch {
|
|
36410
36800
|
}
|
|
36411
36801
|
if (hasGit) return;
|
|
@@ -36468,13 +36858,13 @@ var AgentsScanner = class {
|
|
|
36468
36858
|
};
|
|
36469
36859
|
|
|
36470
36860
|
// src/observer/session-observer.ts
|
|
36471
|
-
var
|
|
36861
|
+
var import_node_fs15 = __toESM(require("fs"), 1);
|
|
36472
36862
|
var import_node_os9 = __toESM(require("os"), 1);
|
|
36473
36863
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
36474
36864
|
init_claude_history();
|
|
36475
36865
|
|
|
36476
36866
|
// src/observer/subagent-meta-observer.ts
|
|
36477
|
-
var
|
|
36867
|
+
var import_node_fs14 = __toESM(require("fs"), 1);
|
|
36478
36868
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
36479
36869
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
36480
36870
|
init_claude_history();
|
|
@@ -36519,7 +36909,7 @@ var SubagentMetaObserver = class {
|
|
|
36519
36909
|
attachWatcher(w2) {
|
|
36520
36910
|
if (w2.watcher) return;
|
|
36521
36911
|
try {
|
|
36522
|
-
w2.watcher =
|
|
36912
|
+
w2.watcher = import_node_fs14.default.watch(w2.dirPath, { persistent: false }, (_evt, name) => {
|
|
36523
36913
|
if (!name) return;
|
|
36524
36914
|
const m2 = META_RE.exec(String(name));
|
|
36525
36915
|
if (!m2) return;
|
|
@@ -36531,7 +36921,7 @@ var SubagentMetaObserver = class {
|
|
|
36531
36921
|
scan(w2) {
|
|
36532
36922
|
let entries;
|
|
36533
36923
|
try {
|
|
36534
|
-
entries =
|
|
36924
|
+
entries = import_node_fs14.default.readdirSync(w2.dirPath);
|
|
36535
36925
|
} catch {
|
|
36536
36926
|
return;
|
|
36537
36927
|
}
|
|
@@ -36548,7 +36938,7 @@ var SubagentMetaObserver = class {
|
|
|
36548
36938
|
const file = import_node_path13.default.join(w2.dirPath, name);
|
|
36549
36939
|
let raw;
|
|
36550
36940
|
try {
|
|
36551
|
-
raw =
|
|
36941
|
+
raw = import_node_fs14.default.readFileSync(file, "utf8");
|
|
36552
36942
|
} catch {
|
|
36553
36943
|
return;
|
|
36554
36944
|
}
|
|
@@ -36612,7 +37002,7 @@ var SessionObserver = class {
|
|
|
36612
37002
|
const filePath = this.resolveJsonlPath(args.cwd, args.toolSessionId, args.jsonlPath);
|
|
36613
37003
|
let size = 0;
|
|
36614
37004
|
try {
|
|
36615
|
-
size =
|
|
37005
|
+
size = import_node_fs15.default.statSync(filePath).size;
|
|
36616
37006
|
} catch {
|
|
36617
37007
|
}
|
|
36618
37008
|
const w2 = {
|
|
@@ -36626,10 +37016,10 @@ var SessionObserver = class {
|
|
|
36626
37016
|
prevIsRejectSentinel: false
|
|
36627
37017
|
};
|
|
36628
37018
|
try {
|
|
36629
|
-
|
|
37019
|
+
import_node_fs15.default.mkdirSync(import_node_path14.default.dirname(filePath), { recursive: true });
|
|
36630
37020
|
} catch {
|
|
36631
37021
|
}
|
|
36632
|
-
w2.watcher =
|
|
37022
|
+
w2.watcher = import_node_fs15.default.watch(import_node_path14.default.dirname(filePath), { persistent: false }, (_event, changedName) => {
|
|
36633
37023
|
if (!changedName || !filePath.endsWith(changedName)) return;
|
|
36634
37024
|
this.poll(w2);
|
|
36635
37025
|
});
|
|
@@ -36652,7 +37042,7 @@ var SessionObserver = class {
|
|
|
36652
37042
|
// 异常静默吞,不阻塞 watcher 启动
|
|
36653
37043
|
hydrateMetaTail(w2, maxLines = 200) {
|
|
36654
37044
|
try {
|
|
36655
|
-
const raw =
|
|
37045
|
+
const raw = import_node_fs15.default.readFileSync(w2.filePath, "utf8");
|
|
36656
37046
|
if (!raw) return;
|
|
36657
37047
|
const allLines = raw.split("\n").filter((l) => l.trim().length > 0);
|
|
36658
37048
|
if (allLines.length === 0) return;
|
|
@@ -36676,7 +37066,7 @@ var SessionObserver = class {
|
|
|
36676
37066
|
poll(w2) {
|
|
36677
37067
|
let size = 0;
|
|
36678
37068
|
try {
|
|
36679
|
-
size =
|
|
37069
|
+
size = import_node_fs15.default.statSync(w2.filePath).size;
|
|
36680
37070
|
} catch {
|
|
36681
37071
|
return;
|
|
36682
37072
|
}
|
|
@@ -36685,11 +37075,11 @@ var SessionObserver = class {
|
|
|
36685
37075
|
w2.buf = "";
|
|
36686
37076
|
}
|
|
36687
37077
|
if (size === w2.lastSize) return;
|
|
36688
|
-
const fd =
|
|
37078
|
+
const fd = import_node_fs15.default.openSync(w2.filePath, "r");
|
|
36689
37079
|
try {
|
|
36690
37080
|
const len = size - w2.lastSize;
|
|
36691
37081
|
const buf = Buffer.alloc(len);
|
|
36692
|
-
|
|
37082
|
+
import_node_fs15.default.readSync(fd, buf, 0, len, w2.lastSize);
|
|
36693
37083
|
w2.lastSize = size;
|
|
36694
37084
|
w2.buf += buf.toString("utf8");
|
|
36695
37085
|
let newlineIndex;
|
|
@@ -36712,7 +37102,7 @@ var SessionObserver = class {
|
|
|
36712
37102
|
}
|
|
36713
37103
|
}
|
|
36714
37104
|
} finally {
|
|
36715
|
-
|
|
37105
|
+
import_node_fs15.default.closeSync(fd);
|
|
36716
37106
|
}
|
|
36717
37107
|
}
|
|
36718
37108
|
// 解析 JSONL 单行:仅当是主链 user 文本行(非 sidechain / 非 sub-agent / message.role='user'
|
|
@@ -37435,14 +37825,14 @@ async function authenticate(token, deps) {
|
|
|
37435
37825
|
}
|
|
37436
37826
|
|
|
37437
37827
|
// src/permission/capability-store.ts
|
|
37438
|
-
var
|
|
37828
|
+
var fs18 = __toESM(require("fs"), 1);
|
|
37439
37829
|
var path19 = __toESM(require("path"), 1);
|
|
37440
37830
|
var CAPABILITIES_FILE_NAME = "capabilities.json";
|
|
37441
37831
|
var FILE_VERSION = 1;
|
|
37442
37832
|
var CapabilityStore = class {
|
|
37443
37833
|
constructor(dataDir) {
|
|
37444
37834
|
this.dataDir = dataDir;
|
|
37445
|
-
|
|
37835
|
+
fs18.mkdirSync(dataDir, { recursive: true });
|
|
37446
37836
|
this.cache = this.readFromDisk();
|
|
37447
37837
|
}
|
|
37448
37838
|
dataDir;
|
|
@@ -37472,7 +37862,7 @@ var CapabilityStore = class {
|
|
|
37472
37862
|
const file = this.filePath();
|
|
37473
37863
|
let raw;
|
|
37474
37864
|
try {
|
|
37475
|
-
raw =
|
|
37865
|
+
raw = fs18.readFileSync(file, "utf8");
|
|
37476
37866
|
} catch (err) {
|
|
37477
37867
|
if (err?.code === "ENOENT") return [];
|
|
37478
37868
|
return [];
|
|
@@ -37500,10 +37890,10 @@ var CapabilityStore = class {
|
|
|
37500
37890
|
}
|
|
37501
37891
|
atomicWrite(file, content) {
|
|
37502
37892
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
37503
|
-
|
|
37504
|
-
|
|
37893
|
+
fs18.writeFileSync(tmp, content, { mode: 384 });
|
|
37894
|
+
fs18.renameSync(tmp, file);
|
|
37505
37895
|
try {
|
|
37506
|
-
|
|
37896
|
+
fs18.chmodSync(file, 384);
|
|
37507
37897
|
} catch {
|
|
37508
37898
|
}
|
|
37509
37899
|
}
|
|
@@ -37596,14 +37986,14 @@ var CapabilityManager = class {
|
|
|
37596
37986
|
};
|
|
37597
37987
|
|
|
37598
37988
|
// src/permission/cleanup.ts
|
|
37599
|
-
var
|
|
37989
|
+
var fs19 = __toESM(require("fs"), 1);
|
|
37600
37990
|
function cleanupGuestSessionsForCapability(cap, factory) {
|
|
37601
37991
|
const removed = [];
|
|
37602
37992
|
for (const g2 of cap.grants) {
|
|
37603
37993
|
if (g2.resource.type !== "persona") continue;
|
|
37604
37994
|
const dir = factory.vmGuestRoot(g2.resource.id, cap.id);
|
|
37605
37995
|
try {
|
|
37606
|
-
|
|
37996
|
+
fs19.rmSync(dir, { recursive: true, force: true });
|
|
37607
37997
|
removed.push(dir);
|
|
37608
37998
|
} catch {
|
|
37609
37999
|
}
|
|
@@ -37612,13 +38002,13 @@ function cleanupGuestSessionsForCapability(cap, factory) {
|
|
|
37612
38002
|
}
|
|
37613
38003
|
|
|
37614
38004
|
// src/inbox/inbox-store.ts
|
|
37615
|
-
var
|
|
38005
|
+
var fs20 = __toESM(require("fs"), 1);
|
|
37616
38006
|
var path20 = __toESM(require("path"), 1);
|
|
37617
38007
|
var INBOX_SUBDIR = "inbox";
|
|
37618
38008
|
var InboxStore = class {
|
|
37619
38009
|
constructor(dataDir) {
|
|
37620
38010
|
this.dataDir = dataDir;
|
|
37621
|
-
|
|
38011
|
+
fs20.mkdirSync(this.dirPath(), { recursive: true });
|
|
37622
38012
|
}
|
|
37623
38013
|
dataDir;
|
|
37624
38014
|
/**
|
|
@@ -37630,7 +38020,7 @@ var InboxStore = class {
|
|
|
37630
38020
|
const file = this.filePath(peerDeviceId);
|
|
37631
38021
|
let raw;
|
|
37632
38022
|
try {
|
|
37633
|
-
raw =
|
|
38023
|
+
raw = fs20.readFileSync(file, "utf8");
|
|
37634
38024
|
} catch (err) {
|
|
37635
38025
|
if (err?.code === "ENOENT") return [];
|
|
37636
38026
|
return [];
|
|
@@ -37646,7 +38036,7 @@ var InboxStore = class {
|
|
|
37646
38036
|
const dir = this.dirPath();
|
|
37647
38037
|
let entries;
|
|
37648
38038
|
try {
|
|
37649
|
-
entries =
|
|
38039
|
+
entries = fs20.readdirSync(dir);
|
|
37650
38040
|
} catch (err) {
|
|
37651
38041
|
if (err?.code === "ENOENT") return [];
|
|
37652
38042
|
return [];
|
|
@@ -37662,9 +38052,9 @@ var InboxStore = class {
|
|
|
37662
38052
|
if (existing.some((m2) => m2.id === message.id)) return;
|
|
37663
38053
|
const file = this.filePath(message.peerDeviceId);
|
|
37664
38054
|
const line = JSON.stringify(message) + "\n";
|
|
37665
|
-
|
|
38055
|
+
fs20.appendFileSync(file, line, { mode: 384 });
|
|
37666
38056
|
try {
|
|
37667
|
-
|
|
38057
|
+
fs20.chmodSync(file, 384);
|
|
37668
38058
|
} catch {
|
|
37669
38059
|
}
|
|
37670
38060
|
}
|
|
@@ -37694,7 +38084,7 @@ var InboxStore = class {
|
|
|
37694
38084
|
removeByPeerDeviceId(peerDeviceId) {
|
|
37695
38085
|
const file = this.filePath(peerDeviceId);
|
|
37696
38086
|
try {
|
|
37697
|
-
|
|
38087
|
+
fs20.unlinkSync(file);
|
|
37698
38088
|
} catch (err) {
|
|
37699
38089
|
if (err?.code === "ENOENT") return;
|
|
37700
38090
|
}
|
|
@@ -37703,10 +38093,10 @@ var InboxStore = class {
|
|
|
37703
38093
|
const file = this.filePath(peerDeviceId);
|
|
37704
38094
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
37705
38095
|
const content = messages.map((m2) => JSON.stringify(m2)).join("\n") + (messages.length > 0 ? "\n" : "");
|
|
37706
|
-
|
|
37707
|
-
|
|
38096
|
+
fs20.writeFileSync(tmp, content, { mode: 384 });
|
|
38097
|
+
fs20.renameSync(tmp, file);
|
|
37708
38098
|
try {
|
|
37709
|
-
|
|
38099
|
+
fs20.chmodSync(file, 384);
|
|
37710
38100
|
} catch {
|
|
37711
38101
|
}
|
|
37712
38102
|
}
|
|
@@ -37801,7 +38191,7 @@ var InboxManager = class {
|
|
|
37801
38191
|
};
|
|
37802
38192
|
|
|
37803
38193
|
// src/state/contact-store.ts
|
|
37804
|
-
var
|
|
38194
|
+
var fs21 = __toESM(require("fs"), 1);
|
|
37805
38195
|
var path21 = __toESM(require("path"), 1);
|
|
37806
38196
|
var FILE_NAME = "contacts.json";
|
|
37807
38197
|
var ContactStore = class {
|
|
@@ -37815,7 +38205,7 @@ var ContactStore = class {
|
|
|
37815
38205
|
const file = path21.join(this.dataDir, FILE_NAME);
|
|
37816
38206
|
let raw;
|
|
37817
38207
|
try {
|
|
37818
|
-
raw =
|
|
38208
|
+
raw = fs21.readFileSync(file, "utf8");
|
|
37819
38209
|
} catch (err) {
|
|
37820
38210
|
if (err?.code !== "ENOENT") this.renameBak(file);
|
|
37821
38211
|
return;
|
|
@@ -37865,13 +38255,13 @@ var ContactStore = class {
|
|
|
37865
38255
|
null,
|
|
37866
38256
|
2
|
|
37867
38257
|
);
|
|
37868
|
-
|
|
37869
|
-
|
|
37870
|
-
|
|
38258
|
+
fs21.mkdirSync(this.dataDir, { recursive: true });
|
|
38259
|
+
fs21.writeFileSync(tmp, content, { mode: 384 });
|
|
38260
|
+
fs21.renameSync(tmp, file);
|
|
37871
38261
|
}
|
|
37872
38262
|
renameBak(file) {
|
|
37873
38263
|
try {
|
|
37874
|
-
|
|
38264
|
+
fs21.renameSync(file, `${file}.bak`);
|
|
37875
38265
|
} catch {
|
|
37876
38266
|
}
|
|
37877
38267
|
}
|
|
@@ -38006,7 +38396,7 @@ async function autoReverseContact(args) {
|
|
|
38006
38396
|
}
|
|
38007
38397
|
|
|
38008
38398
|
// src/migrations/2026-05-20-flatten-sessions.ts
|
|
38009
|
-
var
|
|
38399
|
+
var fs22 = __toESM(require("fs"), 1);
|
|
38010
38400
|
var path22 = __toESM(require("path"), 1);
|
|
38011
38401
|
var MIGRATION_FLAG_NAME = ".migration.v1.done";
|
|
38012
38402
|
function migrateFlattenSessions(opts) {
|
|
@@ -38026,7 +38416,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38026
38416
|
if (!entry.endsWith(".json")) continue;
|
|
38027
38417
|
const src = path22.join(defaultDir, entry);
|
|
38028
38418
|
const dst = path22.join(sessionsDir, entry);
|
|
38029
|
-
|
|
38419
|
+
fs22.renameSync(src, dst);
|
|
38030
38420
|
movedBare += 1;
|
|
38031
38421
|
}
|
|
38032
38422
|
rmdirIfEmpty(defaultDir);
|
|
@@ -38038,10 +38428,10 @@ function migrateFlattenSessions(opts) {
|
|
|
38038
38428
|
const ownerSrc = path22.join(personaDir, "owner");
|
|
38039
38429
|
if (existsSync3(ownerSrc) && isDir(ownerSrc)) {
|
|
38040
38430
|
const ownerDst = path22.join(dataDir, "personas", pid, ".clawd", "sessions", "owner");
|
|
38041
|
-
|
|
38431
|
+
fs22.mkdirSync(ownerDst, { recursive: true });
|
|
38042
38432
|
for (const file of readdirSafe(ownerSrc)) {
|
|
38043
38433
|
if (!file.endsWith(".json")) continue;
|
|
38044
|
-
|
|
38434
|
+
fs22.renameSync(path22.join(ownerSrc, file), path22.join(ownerDst, file));
|
|
38045
38435
|
movedVmOwner += 1;
|
|
38046
38436
|
}
|
|
38047
38437
|
rmdirIfEmpty(ownerSrc);
|
|
@@ -38049,18 +38439,18 @@ function migrateFlattenSessions(opts) {
|
|
|
38049
38439
|
const listenerSrc = path22.join(personaDir, "listener");
|
|
38050
38440
|
if (existsSync3(listenerSrc) && isDir(listenerSrc)) {
|
|
38051
38441
|
const archiveDst = path22.join(dataDir, ".legacy", `listener-${pid}`);
|
|
38052
|
-
|
|
38442
|
+
fs22.mkdirSync(archiveDst, { recursive: true });
|
|
38053
38443
|
for (const file of readdirSafe(listenerSrc)) {
|
|
38054
38444
|
if (!file.endsWith(".json")) continue;
|
|
38055
|
-
|
|
38445
|
+
fs22.renameSync(path22.join(listenerSrc, file), path22.join(archiveDst, file));
|
|
38056
38446
|
archivedListener += 1;
|
|
38057
38447
|
}
|
|
38058
38448
|
rmdirIfEmpty(listenerSrc);
|
|
38059
38449
|
}
|
|
38060
38450
|
rmdirIfEmpty(personaDir);
|
|
38061
38451
|
}
|
|
38062
|
-
|
|
38063
|
-
|
|
38452
|
+
fs22.mkdirSync(sessionsDir, { recursive: true });
|
|
38453
|
+
fs22.writeFileSync(flagPath, JSON.stringify({ migratedAt: now() }, null, 2));
|
|
38064
38454
|
return {
|
|
38065
38455
|
skipped: false,
|
|
38066
38456
|
flagWritten: true,
|
|
@@ -38071,7 +38461,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38071
38461
|
}
|
|
38072
38462
|
function existsSync3(p2) {
|
|
38073
38463
|
try {
|
|
38074
|
-
|
|
38464
|
+
fs22.statSync(p2);
|
|
38075
38465
|
return true;
|
|
38076
38466
|
} catch {
|
|
38077
38467
|
return false;
|
|
@@ -38079,27 +38469,27 @@ function existsSync3(p2) {
|
|
|
38079
38469
|
}
|
|
38080
38470
|
function isDir(p2) {
|
|
38081
38471
|
try {
|
|
38082
|
-
return
|
|
38472
|
+
return fs22.statSync(p2).isDirectory();
|
|
38083
38473
|
} catch {
|
|
38084
38474
|
return false;
|
|
38085
38475
|
}
|
|
38086
38476
|
}
|
|
38087
38477
|
function readdirSafe(p2) {
|
|
38088
38478
|
try {
|
|
38089
|
-
return
|
|
38479
|
+
return fs22.readdirSync(p2);
|
|
38090
38480
|
} catch {
|
|
38091
38481
|
return [];
|
|
38092
38482
|
}
|
|
38093
38483
|
}
|
|
38094
38484
|
function rmdirIfEmpty(p2) {
|
|
38095
38485
|
try {
|
|
38096
|
-
|
|
38486
|
+
fs22.rmdirSync(p2);
|
|
38097
38487
|
} catch {
|
|
38098
38488
|
}
|
|
38099
38489
|
}
|
|
38100
38490
|
|
|
38101
38491
|
// src/transport/http-router.ts
|
|
38102
|
-
var
|
|
38492
|
+
var import_node_fs17 = __toESM(require("fs"), 1);
|
|
38103
38493
|
var import_node_path18 = __toESM(require("path"), 1);
|
|
38104
38494
|
|
|
38105
38495
|
// src/attachment/mime.ts
|
|
@@ -38279,7 +38669,7 @@ function verifySignedUrl(secret, absPath, eRaw, s, now = Date.now) {
|
|
|
38279
38669
|
}
|
|
38280
38670
|
|
|
38281
38671
|
// src/attachment/upload.ts
|
|
38282
|
-
var
|
|
38672
|
+
var import_node_fs16 = __toESM(require("fs"), 1);
|
|
38283
38673
|
var import_node_path16 = __toESM(require("path"), 1);
|
|
38284
38674
|
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
38285
38675
|
var import_promises = require("stream/promises");
|
|
@@ -38301,7 +38691,7 @@ async function writeUploadedAttachment(args) {
|
|
|
38301
38691
|
assertValidFileName(args.fileName);
|
|
38302
38692
|
const attachmentsRoot = import_node_path16.default.join(args.sessionDir, ".attachments");
|
|
38303
38693
|
try {
|
|
38304
|
-
|
|
38694
|
+
import_node_fs16.default.mkdirSync(attachmentsRoot, { recursive: true });
|
|
38305
38695
|
} catch (err) {
|
|
38306
38696
|
throw new UploadError("STORAGE_ERROR", `mkdir failed: ${err.message}`);
|
|
38307
38697
|
}
|
|
@@ -38322,18 +38712,18 @@ async function writeUploadedAttachment(args) {
|
|
|
38322
38712
|
yield buf;
|
|
38323
38713
|
}
|
|
38324
38714
|
},
|
|
38325
|
-
|
|
38715
|
+
import_node_fs16.default.createWriteStream(tmpPath, { mode: 384 })
|
|
38326
38716
|
);
|
|
38327
38717
|
} catch (err) {
|
|
38328
38718
|
try {
|
|
38329
|
-
|
|
38719
|
+
import_node_fs16.default.unlinkSync(tmpPath);
|
|
38330
38720
|
} catch {
|
|
38331
38721
|
}
|
|
38332
38722
|
throw new UploadError("STORAGE_ERROR", `write failed: ${err.message}`);
|
|
38333
38723
|
}
|
|
38334
38724
|
if (actualSize !== args.contentLength) {
|
|
38335
38725
|
try {
|
|
38336
|
-
|
|
38726
|
+
import_node_fs16.default.unlinkSync(tmpPath);
|
|
38337
38727
|
} catch {
|
|
38338
38728
|
}
|
|
38339
38729
|
throw new UploadError(
|
|
@@ -38346,24 +38736,24 @@ async function writeUploadedAttachment(args) {
|
|
|
38346
38736
|
let finalFileName;
|
|
38347
38737
|
let hashDirExists = false;
|
|
38348
38738
|
try {
|
|
38349
|
-
hashDirExists =
|
|
38739
|
+
hashDirExists = import_node_fs16.default.statSync(hashDir).isDirectory();
|
|
38350
38740
|
} catch {
|
|
38351
38741
|
}
|
|
38352
38742
|
if (hashDirExists) {
|
|
38353
|
-
const existing =
|
|
38743
|
+
const existing = import_node_fs16.default.readdirSync(hashDir).filter((n) => !n.startsWith("."));
|
|
38354
38744
|
finalFileName = existing[0] ?? args.fileName;
|
|
38355
38745
|
try {
|
|
38356
|
-
|
|
38746
|
+
import_node_fs16.default.unlinkSync(tmpPath);
|
|
38357
38747
|
} catch {
|
|
38358
38748
|
}
|
|
38359
38749
|
} else {
|
|
38360
38750
|
try {
|
|
38361
|
-
|
|
38751
|
+
import_node_fs16.default.mkdirSync(hashDir, { recursive: true });
|
|
38362
38752
|
finalFileName = args.fileName;
|
|
38363
|
-
|
|
38753
|
+
import_node_fs16.default.renameSync(tmpPath, import_node_path16.default.join(hashDir, finalFileName));
|
|
38364
38754
|
} catch (err) {
|
|
38365
38755
|
try {
|
|
38366
|
-
|
|
38756
|
+
import_node_fs16.default.unlinkSync(tmpPath);
|
|
38367
38757
|
} catch {
|
|
38368
38758
|
}
|
|
38369
38759
|
throw new UploadError("STORAGE_ERROR", `rename failed: ${err.message}`);
|
|
@@ -38887,7 +39277,7 @@ function withCtx(ctx, body) {
|
|
|
38887
39277
|
function streamFile(res, absPath, logger) {
|
|
38888
39278
|
let stat;
|
|
38889
39279
|
try {
|
|
38890
|
-
stat =
|
|
39280
|
+
stat = import_node_fs17.default.statSync(absPath);
|
|
38891
39281
|
} catch (err) {
|
|
38892
39282
|
const code = err?.code;
|
|
38893
39283
|
if (code === "ENOENT") {
|
|
@@ -38910,7 +39300,7 @@ function streamFile(res, absPath, logger) {
|
|
|
38910
39300
|
// 防止浏览器把任意 mime 当 html 渲染
|
|
38911
39301
|
"X-Content-Type-Options": "nosniff"
|
|
38912
39302
|
});
|
|
38913
|
-
const stream =
|
|
39303
|
+
const stream = import_node_fs17.default.createReadStream(absPath);
|
|
38914
39304
|
stream.on("error", (err) => {
|
|
38915
39305
|
logger?.warn("streamFile read error", { absPath, err: err.message });
|
|
38916
39306
|
res.destroy();
|
|
@@ -38919,7 +39309,7 @@ function streamFile(res, absPath, logger) {
|
|
|
38919
39309
|
}
|
|
38920
39310
|
|
|
38921
39311
|
// src/attachment/gc.ts
|
|
38922
|
-
var
|
|
39312
|
+
var import_node_fs18 = __toESM(require("fs"), 1);
|
|
38923
39313
|
var import_node_path19 = __toESM(require("path"), 1);
|
|
38924
39314
|
var DEFAULT_TTL_MS = 30 * 24 * 3600 * 1e3;
|
|
38925
39315
|
function runAttachmentGc(args) {
|
|
@@ -38942,7 +39332,7 @@ function runAttachmentGc(args) {
|
|
|
38942
39332
|
const attRoot = import_node_path19.default.join(sessionDir, ".attachments");
|
|
38943
39333
|
let hashDirs;
|
|
38944
39334
|
try {
|
|
38945
|
-
hashDirs =
|
|
39335
|
+
hashDirs = import_node_fs18.default.readdirSync(attRoot);
|
|
38946
39336
|
} catch (err) {
|
|
38947
39337
|
if (err.code === "ENOENT") continue;
|
|
38948
39338
|
args.logger?.warn("attachment gc: readdir failed", { attRoot, err: err.message });
|
|
@@ -38952,7 +39342,7 @@ function runAttachmentGc(args) {
|
|
|
38952
39342
|
const hashDirAbs = import_node_path19.default.join(attRoot, hashDir);
|
|
38953
39343
|
let files;
|
|
38954
39344
|
try {
|
|
38955
|
-
files =
|
|
39345
|
+
files = import_node_fs18.default.readdirSync(hashDirAbs);
|
|
38956
39346
|
} catch {
|
|
38957
39347
|
continue;
|
|
38958
39348
|
}
|
|
@@ -38960,7 +39350,7 @@ function runAttachmentGc(args) {
|
|
|
38960
39350
|
const file = import_node_path19.default.join(hashDirAbs, name);
|
|
38961
39351
|
let stat;
|
|
38962
39352
|
try {
|
|
38963
|
-
stat =
|
|
39353
|
+
stat = import_node_fs18.default.statSync(file);
|
|
38964
39354
|
} catch {
|
|
38965
39355
|
continue;
|
|
38966
39356
|
}
|
|
@@ -38969,25 +39359,25 @@ function runAttachmentGc(args) {
|
|
|
38969
39359
|
if (age < ttlMs) continue;
|
|
38970
39360
|
if (liveAbs.has(file)) continue;
|
|
38971
39361
|
try {
|
|
38972
|
-
|
|
39362
|
+
import_node_fs18.default.unlinkSync(file);
|
|
38973
39363
|
} catch (err) {
|
|
38974
39364
|
args.logger?.warn("attachment gc: unlink failed", { file, err: err.message });
|
|
38975
39365
|
}
|
|
38976
39366
|
}
|
|
38977
39367
|
try {
|
|
38978
|
-
if (
|
|
39368
|
+
if (import_node_fs18.default.readdirSync(hashDirAbs).length === 0) import_node_fs18.default.rmdirSync(hashDirAbs);
|
|
38979
39369
|
} catch {
|
|
38980
39370
|
}
|
|
38981
39371
|
}
|
|
38982
39372
|
try {
|
|
38983
|
-
if (
|
|
39373
|
+
if (import_node_fs18.default.readdirSync(attRoot).length === 0) import_node_fs18.default.rmdirSync(attRoot);
|
|
38984
39374
|
} catch {
|
|
38985
39375
|
}
|
|
38986
39376
|
}
|
|
38987
39377
|
}
|
|
38988
39378
|
|
|
38989
39379
|
// src/attachment/group.ts
|
|
38990
|
-
var
|
|
39380
|
+
var import_node_fs19 = __toESM(require("fs"), 1);
|
|
38991
39381
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
38992
39382
|
var import_node_crypto6 = __toESM(require("crypto"), 1);
|
|
38993
39383
|
init_protocol();
|
|
@@ -39013,7 +39403,7 @@ var GroupFileStore = class {
|
|
|
39013
39403
|
readFile(scope, sessionId) {
|
|
39014
39404
|
const file = this.filePath(scope, sessionId);
|
|
39015
39405
|
try {
|
|
39016
|
-
const raw =
|
|
39406
|
+
const raw = import_node_fs19.default.readFileSync(file, "utf8");
|
|
39017
39407
|
const parsed = JSON.parse(raw);
|
|
39018
39408
|
if (!Array.isArray(parsed)) {
|
|
39019
39409
|
this.logger?.warn("GroupFileStore.readFile: not an array; resetting session entries", {
|
|
@@ -39039,10 +39429,10 @@ var GroupFileStore = class {
|
|
|
39039
39429
|
}
|
|
39040
39430
|
writeFile(scope, sessionId, entries) {
|
|
39041
39431
|
const file = this.filePath(scope, sessionId);
|
|
39042
|
-
|
|
39432
|
+
import_node_fs19.default.mkdirSync(import_node_path20.default.dirname(file), { recursive: true });
|
|
39043
39433
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
39044
|
-
|
|
39045
|
-
|
|
39434
|
+
import_node_fs19.default.writeFileSync(tmp, JSON.stringify(entries, null, 2), { mode: 384 });
|
|
39435
|
+
import_node_fs19.default.renameSync(tmp, file);
|
|
39046
39436
|
}
|
|
39047
39437
|
/** 拉一份当前 session 的清单。读盘 → cache;之后调用复用 cache */
|
|
39048
39438
|
list(scope, sessionId) {
|
|
@@ -39128,7 +39518,7 @@ var GroupFileStore = class {
|
|
|
39128
39518
|
};
|
|
39129
39519
|
|
|
39130
39520
|
// src/discovery/state-file.ts
|
|
39131
|
-
var
|
|
39521
|
+
var import_node_fs20 = __toESM(require("fs"), 1);
|
|
39132
39522
|
var import_node_path21 = __toESM(require("path"), 1);
|
|
39133
39523
|
function defaultStateFilePath(dataDir) {
|
|
39134
39524
|
return import_node_path21.default.join(dataDir, "state.json");
|
|
@@ -39153,7 +39543,7 @@ var StateFileManager = class {
|
|
|
39153
39543
|
}
|
|
39154
39544
|
read() {
|
|
39155
39545
|
try {
|
|
39156
|
-
const raw =
|
|
39546
|
+
const raw = import_node_fs20.default.readFileSync(this.file, "utf8");
|
|
39157
39547
|
const parsed = JSON.parse(raw);
|
|
39158
39548
|
return parsed;
|
|
39159
39549
|
} catch {
|
|
@@ -39167,33 +39557,33 @@ var StateFileManager = class {
|
|
|
39167
39557
|
return { status: "stale", existing };
|
|
39168
39558
|
}
|
|
39169
39559
|
write(state) {
|
|
39170
|
-
|
|
39560
|
+
import_node_fs20.default.mkdirSync(import_node_path21.default.dirname(this.file), { recursive: true });
|
|
39171
39561
|
const tmp = `${this.file}.tmp.${process.pid}.${Date.now()}`;
|
|
39172
|
-
|
|
39173
|
-
|
|
39562
|
+
import_node_fs20.default.writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 384 });
|
|
39563
|
+
import_node_fs20.default.renameSync(tmp, this.file);
|
|
39174
39564
|
if (process.platform !== "win32") {
|
|
39175
39565
|
try {
|
|
39176
|
-
|
|
39566
|
+
import_node_fs20.default.chmodSync(this.file, 384);
|
|
39177
39567
|
} catch {
|
|
39178
39568
|
}
|
|
39179
39569
|
}
|
|
39180
39570
|
}
|
|
39181
39571
|
delete() {
|
|
39182
39572
|
try {
|
|
39183
|
-
|
|
39573
|
+
import_node_fs20.default.unlinkSync(this.file);
|
|
39184
39574
|
} catch {
|
|
39185
39575
|
}
|
|
39186
39576
|
}
|
|
39187
39577
|
};
|
|
39188
39578
|
|
|
39189
39579
|
// src/tunnel/tunnel-manager.ts
|
|
39190
|
-
var
|
|
39580
|
+
var import_node_fs24 = __toESM(require("fs"), 1);
|
|
39191
39581
|
var import_node_path25 = __toESM(require("path"), 1);
|
|
39192
39582
|
var import_node_crypto7 = __toESM(require("crypto"), 1);
|
|
39193
|
-
var
|
|
39583
|
+
var import_node_child_process7 = require("child_process");
|
|
39194
39584
|
|
|
39195
39585
|
// src/tunnel/tunnel-store.ts
|
|
39196
|
-
var
|
|
39586
|
+
var import_node_fs21 = __toESM(require("fs"), 1);
|
|
39197
39587
|
var import_node_path22 = __toESM(require("path"), 1);
|
|
39198
39588
|
var TunnelStore = class {
|
|
39199
39589
|
constructor(filePath) {
|
|
@@ -39202,7 +39592,7 @@ var TunnelStore = class {
|
|
|
39202
39592
|
filePath;
|
|
39203
39593
|
async get() {
|
|
39204
39594
|
try {
|
|
39205
|
-
const raw = await
|
|
39595
|
+
const raw = await import_node_fs21.default.promises.readFile(this.filePath, "utf8");
|
|
39206
39596
|
const obj = JSON.parse(raw);
|
|
39207
39597
|
if (!isPersistedTunnel(obj)) return null;
|
|
39208
39598
|
return obj;
|
|
@@ -39214,21 +39604,21 @@ var TunnelStore = class {
|
|
|
39214
39604
|
}
|
|
39215
39605
|
async set(v2) {
|
|
39216
39606
|
const dir = import_node_path22.default.dirname(this.filePath);
|
|
39217
|
-
await
|
|
39607
|
+
await import_node_fs21.default.promises.mkdir(dir, { recursive: true });
|
|
39218
39608
|
const data = JSON.stringify(v2, null, 2);
|
|
39219
39609
|
const tmp = `${this.filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
39220
|
-
await
|
|
39610
|
+
await import_node_fs21.default.promises.writeFile(tmp, data, { mode: 384 });
|
|
39221
39611
|
if (process.platform !== "win32") {
|
|
39222
39612
|
try {
|
|
39223
|
-
await
|
|
39613
|
+
await import_node_fs21.default.promises.chmod(tmp, 384);
|
|
39224
39614
|
} catch {
|
|
39225
39615
|
}
|
|
39226
39616
|
}
|
|
39227
|
-
await
|
|
39617
|
+
await import_node_fs21.default.promises.rename(tmp, this.filePath);
|
|
39228
39618
|
}
|
|
39229
39619
|
async clear() {
|
|
39230
39620
|
try {
|
|
39231
|
-
await
|
|
39621
|
+
await import_node_fs21.default.promises.unlink(this.filePath);
|
|
39232
39622
|
} catch (err) {
|
|
39233
39623
|
const code = err?.code;
|
|
39234
39624
|
if (code !== "ENOENT") throw err;
|
|
@@ -39323,10 +39713,10 @@ function escape(v2) {
|
|
|
39323
39713
|
}
|
|
39324
39714
|
|
|
39325
39715
|
// src/tunnel/frpc-binary.ts
|
|
39326
|
-
var
|
|
39716
|
+
var import_node_fs22 = __toESM(require("fs"), 1);
|
|
39327
39717
|
var import_node_os11 = __toESM(require("os"), 1);
|
|
39328
39718
|
var import_node_path23 = __toESM(require("path"), 1);
|
|
39329
|
-
var
|
|
39719
|
+
var import_node_child_process5 = require("child_process");
|
|
39330
39720
|
var import_node_stream2 = require("stream");
|
|
39331
39721
|
var import_promises3 = require("stream/promises");
|
|
39332
39722
|
var FRPC_VERSION = "0.68.0";
|
|
@@ -39357,7 +39747,7 @@ function frpcDownloadUrl(version2, p2) {
|
|
|
39357
39747
|
}
|
|
39358
39748
|
async function ensureFrpcBinary(opts) {
|
|
39359
39749
|
if (opts.override) {
|
|
39360
|
-
if (!
|
|
39750
|
+
if (!import_node_fs22.default.existsSync(opts.override)) {
|
|
39361
39751
|
throw new Error(`frpc binary not found at override path: ${opts.override}`);
|
|
39362
39752
|
}
|
|
39363
39753
|
return opts.override;
|
|
@@ -39365,10 +39755,10 @@ async function ensureFrpcBinary(opts) {
|
|
|
39365
39755
|
const version2 = opts.version ?? FRPC_VERSION;
|
|
39366
39756
|
const platform = opts.platform ?? detectPlatform();
|
|
39367
39757
|
const binDir = import_node_path23.default.join(opts.dataDir, "bin");
|
|
39368
|
-
|
|
39758
|
+
import_node_fs22.default.mkdirSync(binDir, { recursive: true });
|
|
39369
39759
|
cleanupStaleArtifacts(binDir);
|
|
39370
39760
|
const stableBin = import_node_path23.default.join(binDir, "frpc");
|
|
39371
|
-
if (
|
|
39761
|
+
if (import_node_fs22.default.existsSync(stableBin)) return stableBin;
|
|
39372
39762
|
const partialBin = `${stableBin}.partial`;
|
|
39373
39763
|
const tarballPath = import_node_path23.default.join(binDir, `frp_${version2}_${platform.os}_${platform.arch}.tar.gz.partial`);
|
|
39374
39764
|
try {
|
|
@@ -39379,8 +39769,8 @@ async function ensureFrpcBinary(opts) {
|
|
|
39379
39769
|
} else {
|
|
39380
39770
|
await extractFrpcFromTarball(tarballPath, binDir, version2, platform, partialBin);
|
|
39381
39771
|
}
|
|
39382
|
-
|
|
39383
|
-
|
|
39772
|
+
import_node_fs22.default.chmodSync(partialBin, 493);
|
|
39773
|
+
import_node_fs22.default.renameSync(partialBin, stableBin);
|
|
39384
39774
|
} finally {
|
|
39385
39775
|
safeUnlink(tarballPath);
|
|
39386
39776
|
safeUnlink(partialBin);
|
|
@@ -39390,7 +39780,7 @@ async function ensureFrpcBinary(opts) {
|
|
|
39390
39780
|
function cleanupStaleArtifacts(binDir) {
|
|
39391
39781
|
let entries;
|
|
39392
39782
|
try {
|
|
39393
|
-
entries =
|
|
39783
|
+
entries = import_node_fs22.default.readdirSync(binDir);
|
|
39394
39784
|
} catch {
|
|
39395
39785
|
return;
|
|
39396
39786
|
}
|
|
@@ -39398,7 +39788,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
39398
39788
|
if (name.endsWith(".partial") || name.startsWith("extract-")) {
|
|
39399
39789
|
const full = import_node_path23.default.join(binDir, name);
|
|
39400
39790
|
try {
|
|
39401
|
-
|
|
39791
|
+
import_node_fs22.default.rmSync(full, { recursive: true, force: true });
|
|
39402
39792
|
} catch {
|
|
39403
39793
|
}
|
|
39404
39794
|
}
|
|
@@ -39406,7 +39796,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
39406
39796
|
}
|
|
39407
39797
|
function safeUnlink(p2) {
|
|
39408
39798
|
try {
|
|
39409
|
-
|
|
39799
|
+
import_node_fs22.default.unlinkSync(p2);
|
|
39410
39800
|
} catch {
|
|
39411
39801
|
}
|
|
39412
39802
|
}
|
|
@@ -39417,46 +39807,46 @@ async function downloadToFile(url, dest, fetchImpl) {
|
|
|
39417
39807
|
if (!res.ok || !res.body) {
|
|
39418
39808
|
throw new Error(`download failed: ${res.status} ${res.statusText}`);
|
|
39419
39809
|
}
|
|
39420
|
-
const out =
|
|
39810
|
+
const out = import_node_fs22.default.createWriteStream(dest);
|
|
39421
39811
|
const nodeStream = import_node_stream2.Readable.fromWeb(res.body);
|
|
39422
39812
|
await (0, import_promises3.pipeline)(nodeStream, out);
|
|
39423
39813
|
}
|
|
39424
39814
|
async function extractFrpcFromTarball(tarball, binDir, version2, platform, destBin) {
|
|
39425
39815
|
const work = import_node_path23.default.join(binDir, `extract-${process.pid}-${Date.now()}`);
|
|
39426
|
-
|
|
39816
|
+
import_node_fs22.default.mkdirSync(work, { recursive: true });
|
|
39427
39817
|
try {
|
|
39428
39818
|
await new Promise((resolve6, reject) => {
|
|
39429
|
-
const proc = (0,
|
|
39819
|
+
const proc = (0, import_node_child_process5.spawn)("tar", ["xzf", tarball, "-C", work], { stdio: "pipe" });
|
|
39430
39820
|
proc.on("error", reject);
|
|
39431
39821
|
proc.on("exit", (code) => code === 0 ? resolve6() : reject(new Error(`tar exited ${code}`)));
|
|
39432
39822
|
});
|
|
39433
39823
|
const dirName = `frp_${version2}_${platform.os}_${platform.arch}`;
|
|
39434
39824
|
const src = import_node_path23.default.join(work, dirName, "frpc");
|
|
39435
|
-
if (!
|
|
39825
|
+
if (!import_node_fs22.default.existsSync(src)) {
|
|
39436
39826
|
throw new Error(`frpc not found inside tarball at ${src}`);
|
|
39437
39827
|
}
|
|
39438
|
-
|
|
39828
|
+
import_node_fs22.default.copyFileSync(src, destBin);
|
|
39439
39829
|
} finally {
|
|
39440
|
-
|
|
39830
|
+
import_node_fs22.default.rmSync(work, { recursive: true, force: true });
|
|
39441
39831
|
}
|
|
39442
39832
|
}
|
|
39443
39833
|
|
|
39444
39834
|
// src/tunnel/frpc-process.ts
|
|
39445
|
-
var
|
|
39835
|
+
var import_node_fs23 = __toESM(require("fs"), 1);
|
|
39446
39836
|
var import_node_path24 = __toESM(require("path"), 1);
|
|
39447
|
-
var
|
|
39837
|
+
var import_node_child_process6 = require("child_process");
|
|
39448
39838
|
function frpcPidFilePath(dataDir) {
|
|
39449
39839
|
return import_node_path24.default.join(dataDir, "frpc.pid");
|
|
39450
39840
|
}
|
|
39451
39841
|
function writeFrpcPid(dataDir, pid) {
|
|
39452
39842
|
try {
|
|
39453
|
-
|
|
39843
|
+
import_node_fs23.default.writeFileSync(frpcPidFilePath(dataDir), String(pid), { mode: 384 });
|
|
39454
39844
|
} catch {
|
|
39455
39845
|
}
|
|
39456
39846
|
}
|
|
39457
39847
|
function clearFrpcPid(dataDir) {
|
|
39458
39848
|
try {
|
|
39459
|
-
|
|
39849
|
+
import_node_fs23.default.unlinkSync(frpcPidFilePath(dataDir));
|
|
39460
39850
|
} catch {
|
|
39461
39851
|
}
|
|
39462
39852
|
}
|
|
@@ -39472,7 +39862,7 @@ function defaultIsPidAlive(pid) {
|
|
|
39472
39862
|
}
|
|
39473
39863
|
function defaultReadPidFile(file) {
|
|
39474
39864
|
try {
|
|
39475
|
-
return
|
|
39865
|
+
return import_node_fs23.default.readFileSync(file, "utf8");
|
|
39476
39866
|
} catch {
|
|
39477
39867
|
return null;
|
|
39478
39868
|
}
|
|
@@ -39512,7 +39902,7 @@ async function killStaleFrpc(deps) {
|
|
|
39512
39902
|
}
|
|
39513
39903
|
if (victims.size === 0) {
|
|
39514
39904
|
try {
|
|
39515
|
-
|
|
39905
|
+
import_node_fs23.default.unlinkSync(pidFile);
|
|
39516
39906
|
} catch {
|
|
39517
39907
|
}
|
|
39518
39908
|
return;
|
|
@@ -39523,14 +39913,14 @@ async function killStaleFrpc(deps) {
|
|
|
39523
39913
|
}
|
|
39524
39914
|
await sleep(deps.reapWaitMs ?? 300);
|
|
39525
39915
|
try {
|
|
39526
|
-
|
|
39916
|
+
import_node_fs23.default.unlinkSync(pidFile);
|
|
39527
39917
|
} catch {
|
|
39528
39918
|
}
|
|
39529
39919
|
}
|
|
39530
39920
|
async function defaultScanFrpcPidsByCmdline(tomlPath, logger) {
|
|
39531
39921
|
if (process.platform === "win32") return [];
|
|
39532
39922
|
return new Promise((resolve6) => {
|
|
39533
|
-
const ps = (0,
|
|
39923
|
+
const ps = (0, import_node_child_process6.spawn)("ps", ["-axo", "pid=,command="], { stdio: ["ignore", "pipe", "ignore"] });
|
|
39534
39924
|
let buf = "";
|
|
39535
39925
|
ps.stdout.on("data", (c) => {
|
|
39536
39926
|
buf += c.toString();
|
|
@@ -39698,12 +40088,12 @@ var TunnelManager = class {
|
|
|
39698
40088
|
localPort,
|
|
39699
40089
|
logLevel: "info"
|
|
39700
40090
|
});
|
|
39701
|
-
await
|
|
39702
|
-
const proc = (this.deps.spawnImpl ??
|
|
40091
|
+
await import_node_fs24.default.promises.writeFile(tomlPath, toml, { mode: 384 });
|
|
40092
|
+
const proc = (this.deps.spawnImpl ?? import_node_child_process7.spawn)(frpcBin, ["-c", tomlPath], {
|
|
39703
40093
|
stdio: ["ignore", "pipe", "pipe"]
|
|
39704
40094
|
});
|
|
39705
40095
|
const logFilePath = import_node_path25.default.join(this.deps.dataDir, "frpc.log");
|
|
39706
|
-
const logStream =
|
|
40096
|
+
const logStream = import_node_fs24.default.createWriteStream(logFilePath, { flags: "a", mode: 384 });
|
|
39707
40097
|
logStream.on("error", () => {
|
|
39708
40098
|
});
|
|
39709
40099
|
const tee = (chunk) => {
|
|
@@ -39801,7 +40191,7 @@ function deriveStableDeviceKey(opts = {}) {
|
|
|
39801
40191
|
}
|
|
39802
40192
|
|
|
39803
40193
|
// src/auth-store.ts
|
|
39804
|
-
var
|
|
40194
|
+
var import_node_fs25 = __toESM(require("fs"), 1);
|
|
39805
40195
|
var import_node_path27 = __toESM(require("path"), 1);
|
|
39806
40196
|
var import_node_crypto9 = __toESM(require("crypto"), 1);
|
|
39807
40197
|
var AUTH_FILE_NAME = "auth.json";
|
|
@@ -39840,7 +40230,7 @@ function defaultGenerateOwnerPrincipalId() {
|
|
|
39840
40230
|
}
|
|
39841
40231
|
function readAuthFile(file) {
|
|
39842
40232
|
try {
|
|
39843
|
-
const raw =
|
|
40233
|
+
const raw = import_node_fs25.default.readFileSync(file, "utf8");
|
|
39844
40234
|
const parsed = JSON.parse(raw);
|
|
39845
40235
|
if (typeof parsed?.token !== "string" || parsed.token.length === 0) {
|
|
39846
40236
|
return null;
|
|
@@ -39859,16 +40249,16 @@ function readAuthFile(file) {
|
|
|
39859
40249
|
}
|
|
39860
40250
|
}
|
|
39861
40251
|
function writeAuthFile(file, content) {
|
|
39862
|
-
|
|
39863
|
-
|
|
40252
|
+
import_node_fs25.default.mkdirSync(import_node_path27.default.dirname(file), { recursive: true });
|
|
40253
|
+
import_node_fs25.default.writeFileSync(file, JSON.stringify(content, null, 2), { mode: 384 });
|
|
39864
40254
|
try {
|
|
39865
|
-
|
|
40255
|
+
import_node_fs25.default.chmodSync(file, 384);
|
|
39866
40256
|
} catch {
|
|
39867
40257
|
}
|
|
39868
40258
|
}
|
|
39869
40259
|
|
|
39870
40260
|
// src/owner-profile.ts
|
|
39871
|
-
var
|
|
40261
|
+
var import_node_fs26 = __toESM(require("fs"), 1);
|
|
39872
40262
|
var import_node_os13 = __toESM(require("os"), 1);
|
|
39873
40263
|
var import_node_path28 = __toESM(require("path"), 1);
|
|
39874
40264
|
var PROFILE_FILENAME = "profile.json";
|
|
@@ -39877,7 +40267,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
39877
40267
|
const profilePath = import_node_path28.default.join(dataDir, PROFILE_FILENAME);
|
|
39878
40268
|
let raw;
|
|
39879
40269
|
try {
|
|
39880
|
-
raw =
|
|
40270
|
+
raw = import_node_fs26.default.readFileSync(profilePath, "utf8");
|
|
39881
40271
|
} catch {
|
|
39882
40272
|
return fallback;
|
|
39883
40273
|
}
|
|
@@ -39900,7 +40290,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
39900
40290
|
}
|
|
39901
40291
|
|
|
39902
40292
|
// src/feishu-auth/owner-identity-store.ts
|
|
39903
|
-
var
|
|
40293
|
+
var import_node_fs27 = __toESM(require("fs"), 1);
|
|
39904
40294
|
var import_node_path29 = __toESM(require("path"), 1);
|
|
39905
40295
|
var OWNER_IDENTITY_FILE_NAME = "owner-identity.json";
|
|
39906
40296
|
var OwnerIdentityStore = class {
|
|
@@ -39911,7 +40301,7 @@ var OwnerIdentityStore = class {
|
|
|
39911
40301
|
read() {
|
|
39912
40302
|
let raw;
|
|
39913
40303
|
try {
|
|
39914
|
-
raw =
|
|
40304
|
+
raw = import_node_fs27.default.readFileSync(this.file, "utf8");
|
|
39915
40305
|
} catch {
|
|
39916
40306
|
return null;
|
|
39917
40307
|
}
|
|
@@ -39938,16 +40328,16 @@ var OwnerIdentityStore = class {
|
|
|
39938
40328
|
};
|
|
39939
40329
|
}
|
|
39940
40330
|
write(record) {
|
|
39941
|
-
|
|
39942
|
-
|
|
40331
|
+
import_node_fs27.default.mkdirSync(import_node_path29.default.dirname(this.file), { recursive: true });
|
|
40332
|
+
import_node_fs27.default.writeFileSync(this.file, JSON.stringify(record, null, 2), { mode: 384 });
|
|
39943
40333
|
try {
|
|
39944
|
-
|
|
40334
|
+
import_node_fs27.default.chmodSync(this.file, 384);
|
|
39945
40335
|
} catch {
|
|
39946
40336
|
}
|
|
39947
40337
|
}
|
|
39948
40338
|
clear() {
|
|
39949
40339
|
try {
|
|
39950
|
-
|
|
40340
|
+
import_node_fs27.default.unlinkSync(this.file);
|
|
39951
40341
|
} catch (err) {
|
|
39952
40342
|
const code = err?.code;
|
|
39953
40343
|
if (code !== "ENOENT") throw err;
|
|
@@ -40210,7 +40600,7 @@ function verifyConnectToken(args) {
|
|
|
40210
40600
|
}
|
|
40211
40601
|
|
|
40212
40602
|
// src/feishu-auth/server-key.ts
|
|
40213
|
-
var
|
|
40603
|
+
var fs36 = __toESM(require("fs"), 1);
|
|
40214
40604
|
var path38 = __toESM(require("path"), 1);
|
|
40215
40605
|
var FILE_NAME2 = "server-signing-key.json";
|
|
40216
40606
|
var ServerKeyStore = class {
|
|
@@ -40224,7 +40614,7 @@ var ServerKeyStore = class {
|
|
|
40224
40614
|
/** 读缓存的公钥;无缓存 / 损坏 → null(调用方决定是否触发拉取) */
|
|
40225
40615
|
read() {
|
|
40226
40616
|
try {
|
|
40227
|
-
const raw =
|
|
40617
|
+
const raw = fs36.readFileSync(this.filePath(), "utf8");
|
|
40228
40618
|
const parsed = JSON.parse(raw);
|
|
40229
40619
|
if (typeof parsed.publicKeyPem === "string" && parsed.publicKeyPem.includes("PUBLIC KEY")) {
|
|
40230
40620
|
return parsed.publicKeyPem;
|
|
@@ -40239,12 +40629,12 @@ var ServerKeyStore = class {
|
|
|
40239
40629
|
publicKeyPem,
|
|
40240
40630
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
40241
40631
|
};
|
|
40242
|
-
|
|
40243
|
-
|
|
40632
|
+
fs36.mkdirSync(this.dataDir, { recursive: true });
|
|
40633
|
+
fs36.writeFileSync(this.filePath(), JSON.stringify(content, null, 2), { mode: 384 });
|
|
40244
40634
|
}
|
|
40245
40635
|
clear() {
|
|
40246
40636
|
try {
|
|
40247
|
-
|
|
40637
|
+
fs36.unlinkSync(this.filePath());
|
|
40248
40638
|
} catch {
|
|
40249
40639
|
}
|
|
40250
40640
|
}
|
|
@@ -40257,12 +40647,12 @@ init_protocol();
|
|
|
40257
40647
|
init_protocol();
|
|
40258
40648
|
|
|
40259
40649
|
// src/session/fork.ts
|
|
40260
|
-
var
|
|
40650
|
+
var import_node_fs28 = __toESM(require("fs"), 1);
|
|
40261
40651
|
var import_node_os14 = __toESM(require("os"), 1);
|
|
40262
40652
|
var import_node_path30 = __toESM(require("path"), 1);
|
|
40263
40653
|
init_claude_history();
|
|
40264
40654
|
function readJsonlEntries(file) {
|
|
40265
|
-
const raw =
|
|
40655
|
+
const raw = import_node_fs28.default.readFileSync(file, "utf8");
|
|
40266
40656
|
const out = [];
|
|
40267
40657
|
for (const line of raw.split("\n")) {
|
|
40268
40658
|
const t = line.trim();
|
|
@@ -40278,7 +40668,7 @@ function forkSession(input) {
|
|
|
40278
40668
|
const baseDir = input.baseDir ?? import_node_path30.default.join(import_node_os14.default.homedir(), ".claude");
|
|
40279
40669
|
const projectDir = import_node_path30.default.join(baseDir, "projects", cwdToHashDir(input.cwd));
|
|
40280
40670
|
const sourceFile = import_node_path30.default.join(projectDir, `${input.toolSessionId}.jsonl`);
|
|
40281
|
-
if (!
|
|
40671
|
+
if (!import_node_fs28.default.existsSync(sourceFile)) {
|
|
40282
40672
|
throw new Error(`fork: source transcript not found: ${sourceFile}`);
|
|
40283
40673
|
}
|
|
40284
40674
|
const entries = readJsonlEntries(sourceFile);
|
|
@@ -40309,8 +40699,8 @@ function forkSession(input) {
|
|
|
40309
40699
|
forkedLines.push(JSON.stringify(forked));
|
|
40310
40700
|
}
|
|
40311
40701
|
const forkedFilePath = import_node_path30.default.join(projectDir, `${forkedToolSessionId}.jsonl`);
|
|
40312
|
-
|
|
40313
|
-
|
|
40702
|
+
import_node_fs28.default.mkdirSync(projectDir, { recursive: true });
|
|
40703
|
+
import_node_fs28.default.writeFileSync(forkedFilePath, forkedLines.join("\n") + "\n", { mode: 384 });
|
|
40314
40704
|
return { forkedToolSessionId, forkedFilePath };
|
|
40315
40705
|
}
|
|
40316
40706
|
|
|
@@ -40928,15 +41318,15 @@ init_protocol();
|
|
|
40928
41318
|
init_protocol();
|
|
40929
41319
|
|
|
40930
41320
|
// src/workspace/git.ts
|
|
40931
|
-
var
|
|
40932
|
-
var
|
|
41321
|
+
var import_node_child_process8 = require("child_process");
|
|
41322
|
+
var import_node_fs29 = __toESM(require("fs"), 1);
|
|
40933
41323
|
var import_node_path31 = __toESM(require("path"), 1);
|
|
40934
41324
|
var import_node_util = require("util");
|
|
40935
|
-
var pexec = (0, import_node_util.promisify)(
|
|
41325
|
+
var pexec = (0, import_node_util.promisify)(import_node_child_process8.execFile);
|
|
40936
41326
|
function normalizePath(p2) {
|
|
40937
41327
|
const resolved = import_node_path31.default.resolve(p2);
|
|
40938
41328
|
try {
|
|
40939
|
-
return
|
|
41329
|
+
return import_node_fs29.default.realpathSync(resolved);
|
|
40940
41330
|
} catch {
|
|
40941
41331
|
return resolved;
|
|
40942
41332
|
}
|
|
@@ -42126,22 +42516,22 @@ function pickExtId(frame) {
|
|
|
42126
42516
|
}
|
|
42127
42517
|
return extId;
|
|
42128
42518
|
}
|
|
42129
|
-
function composeState(
|
|
42130
|
-
if (
|
|
42131
|
-
if (manifestMode(
|
|
42519
|
+
function composeState(rec2, running, crashed, getPort) {
|
|
42520
|
+
if (rec2.state === "invalid") return rec2;
|
|
42521
|
+
if (manifestMode(rec2.manifest) === "hosted") {
|
|
42132
42522
|
return {
|
|
42133
|
-
...
|
|
42523
|
+
...rec2,
|
|
42134
42524
|
state: "running",
|
|
42135
|
-
target: { kind: "hosted", url:
|
|
42525
|
+
target: { kind: "hosted", url: rec2.manifest.entry.url }
|
|
42136
42526
|
};
|
|
42137
42527
|
}
|
|
42138
|
-
if (running.has(
|
|
42139
|
-
const port = getPort(
|
|
42140
|
-
if (port == null) return
|
|
42141
|
-
return { ...
|
|
42528
|
+
if (running.has(rec2.extId)) {
|
|
42529
|
+
const port = getPort(rec2.extId);
|
|
42530
|
+
if (port == null) return rec2;
|
|
42531
|
+
return { ...rec2, state: "running", target: { kind: "local", port } };
|
|
42142
42532
|
}
|
|
42143
|
-
if (crashed.has(
|
|
42144
|
-
return
|
|
42533
|
+
if (crashed.has(rec2.extId)) return { ...rec2, state: "crashed" };
|
|
42534
|
+
return rec2;
|
|
42145
42535
|
}
|
|
42146
42536
|
function buildExtensionHandlers(deps) {
|
|
42147
42537
|
const list = async (_frame, _client, ctx) => {
|
|
@@ -42358,7 +42748,7 @@ function buildExtensionHandlers(deps) {
|
|
|
42358
42748
|
}
|
|
42359
42749
|
|
|
42360
42750
|
// src/app-builder/kill-port.ts
|
|
42361
|
-
var
|
|
42751
|
+
var import_node_child_process9 = require("child_process");
|
|
42362
42752
|
async function killPortOccupants(port, ownedPids, logger) {
|
|
42363
42753
|
let pids;
|
|
42364
42754
|
try {
|
|
@@ -42400,7 +42790,7 @@ async function killPortOccupants(port, ownedPids, logger) {
|
|
|
42400
42790
|
}
|
|
42401
42791
|
function listPidsOnPort(port) {
|
|
42402
42792
|
return new Promise((resolve6, reject) => {
|
|
42403
|
-
(0,
|
|
42793
|
+
(0, import_node_child_process9.execFile)(
|
|
42404
42794
|
"lsof",
|
|
42405
42795
|
["-ti", `:${port}`],
|
|
42406
42796
|
{ timeout: 3e3 },
|
|
@@ -42472,8 +42862,8 @@ var PublishJobRegistry = class {
|
|
|
42472
42862
|
};
|
|
42473
42863
|
|
|
42474
42864
|
// src/app-builder/publish-job-runner.ts
|
|
42475
|
-
var
|
|
42476
|
-
var
|
|
42865
|
+
var import_node_child_process10 = require("child_process");
|
|
42866
|
+
var import_node_fs30 = require("fs");
|
|
42477
42867
|
var import_node_path38 = require("path");
|
|
42478
42868
|
|
|
42479
42869
|
// src/app-builder/publish-stage-parser.ts
|
|
@@ -42501,7 +42891,7 @@ function tailStderrLines(buf, n) {
|
|
|
42501
42891
|
// src/app-builder/publish-job-runner.ts
|
|
42502
42892
|
async function startPublishJob(deps, args) {
|
|
42503
42893
|
const { registry: registry2, projectDir } = deps;
|
|
42504
|
-
const
|
|
42894
|
+
const spawn10 = deps.spawnImpl ?? import_node_child_process10.spawn;
|
|
42505
42895
|
if (registry2.has(args.name)) {
|
|
42506
42896
|
return { jobId: registry2.get(args.name).jobId, status: "already-publishing" };
|
|
42507
42897
|
}
|
|
@@ -42509,11 +42899,11 @@ async function startPublishJob(deps, args) {
|
|
|
42509
42899
|
const logPath = (0, import_node_path38.join)(projDir, ".publish.log");
|
|
42510
42900
|
let logStream = null;
|
|
42511
42901
|
try {
|
|
42512
|
-
logStream = (0,
|
|
42902
|
+
logStream = (0, import_node_fs30.createWriteStream)(logPath, { flags: "w" });
|
|
42513
42903
|
} catch {
|
|
42514
42904
|
logStream = null;
|
|
42515
42905
|
}
|
|
42516
|
-
const child =
|
|
42906
|
+
const child = spawn10("bash", [args.scriptPath, projDir], {
|
|
42517
42907
|
cwd: projDir,
|
|
42518
42908
|
env: process.env,
|
|
42519
42909
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -42767,7 +43157,7 @@ async function recoverInterruptedJobs(deps) {
|
|
|
42767
43157
|
// src/handlers/app-builder.ts
|
|
42768
43158
|
init_protocol();
|
|
42769
43159
|
var import_node_path39 = require("path");
|
|
42770
|
-
var
|
|
43160
|
+
var import_node_fs31 = require("fs");
|
|
42771
43161
|
var APP_BUILDER_PERSONAS = ["persona-app-builder"];
|
|
42772
43162
|
var PUBLISH_SCRIPT_REL = "extension-kit/scripts/publish.sh";
|
|
42773
43163
|
var DEV_SERVER_READY_TIMEOUT_MS = 3e4;
|
|
@@ -42849,7 +43239,7 @@ function buildAppBuilderHandlers(deps) {
|
|
|
42849
43239
|
async function listAllUsersProjects() {
|
|
42850
43240
|
if (!deps.usersRoot || !deps.getStore) return [];
|
|
42851
43241
|
const getStore = deps.getStore;
|
|
42852
|
-
const userIds = await
|
|
43242
|
+
const userIds = await import_node_fs31.promises.readdir(deps.usersRoot).catch(() => []);
|
|
42853
43243
|
const perUser = await Promise.all(
|
|
42854
43244
|
userIds.map((uid) => getStore(uid).list().catch(() => []))
|
|
42855
43245
|
);
|
|
@@ -43389,8 +43779,8 @@ function buildMethodHandlers(deps) {
|
|
|
43389
43779
|
}
|
|
43390
43780
|
|
|
43391
43781
|
// src/app-builder/project-store.ts
|
|
43392
|
-
var
|
|
43393
|
-
var
|
|
43782
|
+
var import_node_fs32 = require("fs");
|
|
43783
|
+
var import_node_child_process11 = require("child_process");
|
|
43394
43784
|
var import_node_path42 = require("path");
|
|
43395
43785
|
init_protocol();
|
|
43396
43786
|
var PROJECTS_DIR = "projects";
|
|
@@ -43418,7 +43808,7 @@ var ProjectStore = class {
|
|
|
43418
43808
|
async list() {
|
|
43419
43809
|
let entries;
|
|
43420
43810
|
try {
|
|
43421
|
-
entries = await
|
|
43811
|
+
entries = await import_node_fs32.promises.readdir(this.projectsRoot());
|
|
43422
43812
|
} catch (err) {
|
|
43423
43813
|
if (err.code === "ENOENT") return [];
|
|
43424
43814
|
throw err;
|
|
@@ -43426,7 +43816,7 @@ var ProjectStore = class {
|
|
|
43426
43816
|
const out = [];
|
|
43427
43817
|
for (const name of entries) {
|
|
43428
43818
|
try {
|
|
43429
|
-
const raw = await
|
|
43819
|
+
const raw = await import_node_fs32.promises.readFile(this.metaPath(name), "utf8");
|
|
43430
43820
|
const json = JSON.parse(raw);
|
|
43431
43821
|
let migrated = false;
|
|
43432
43822
|
if (typeof json.devCommand !== "string" || json.devCommand.length === 0) {
|
|
@@ -43437,7 +43827,7 @@ var ProjectStore = class {
|
|
|
43437
43827
|
if (parsed.success) {
|
|
43438
43828
|
out.push(parsed.data);
|
|
43439
43829
|
if (migrated) {
|
|
43440
|
-
void
|
|
43830
|
+
void import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(parsed.data, null, 2) + "\n", "utf8").catch(() => {
|
|
43441
43831
|
});
|
|
43442
43832
|
}
|
|
43443
43833
|
}
|
|
@@ -43481,8 +43871,8 @@ var ProjectStore = class {
|
|
|
43481
43871
|
throw new Error(`invalid name "${name}": ${validated.error.message}`);
|
|
43482
43872
|
}
|
|
43483
43873
|
const dir = this.projectDir(name);
|
|
43484
|
-
await
|
|
43485
|
-
await
|
|
43874
|
+
await import_node_fs32.promises.mkdir(dir, { recursive: true });
|
|
43875
|
+
await import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
43486
43876
|
return meta;
|
|
43487
43877
|
}
|
|
43488
43878
|
/**
|
|
@@ -43497,7 +43887,7 @@ var ProjectStore = class {
|
|
|
43497
43887
|
const scriptPath = (0, import_node_path42.join)(personaRoot, SCAFFOLD_SCRIPT_REL);
|
|
43498
43888
|
const destDir = this.projectDir(name);
|
|
43499
43889
|
return await new Promise((resolve6, reject) => {
|
|
43500
|
-
const child = (0,
|
|
43890
|
+
const child = (0, import_node_child_process11.spawn)("bash", [scriptPath, name, template, destDir], {
|
|
43501
43891
|
cwd: personaRoot,
|
|
43502
43892
|
env: { ...process.env, PATH: process.env.PATH ?? "" },
|
|
43503
43893
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -43527,7 +43917,7 @@ var ProjectStore = class {
|
|
|
43527
43917
|
}
|
|
43528
43918
|
async delete(name) {
|
|
43529
43919
|
const dir = this.projectDir(name);
|
|
43530
|
-
await
|
|
43920
|
+
await import_node_fs32.promises.rm(dir, { recursive: true, force: true });
|
|
43531
43921
|
}
|
|
43532
43922
|
async updatePort(name, newPort) {
|
|
43533
43923
|
if (newPort < PROJECT_PORT_MIN || newPort > PROJECT_PORT_MAX) {
|
|
@@ -43543,7 +43933,7 @@ var ProjectStore = class {
|
|
|
43543
43933
|
throw new Error(`port ${newPort} already used / \u5DF2\u88AB project "${conflict.name}" \u5360\u7528`);
|
|
43544
43934
|
}
|
|
43545
43935
|
const updated = { ...target, port: newPort };
|
|
43546
|
-
await
|
|
43936
|
+
await import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
43547
43937
|
return updated;
|
|
43548
43938
|
}
|
|
43549
43939
|
/**
|
|
@@ -43560,7 +43950,7 @@ var ProjectStore = class {
|
|
|
43560
43950
|
if (!validated.success) {
|
|
43561
43951
|
throw new Error(`invalid prodUrl "${url}": ${validated.error.message}`);
|
|
43562
43952
|
}
|
|
43563
|
-
await
|
|
43953
|
+
await import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
43564
43954
|
return validated.data;
|
|
43565
43955
|
}
|
|
43566
43956
|
/**
|
|
@@ -43581,7 +43971,7 @@ var ProjectStore = class {
|
|
|
43581
43971
|
if (!validated.success) {
|
|
43582
43972
|
throw new Error(`invalid publishJob: ${validated.error.message}`);
|
|
43583
43973
|
}
|
|
43584
|
-
await
|
|
43974
|
+
await import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
43585
43975
|
return validated.data;
|
|
43586
43976
|
}
|
|
43587
43977
|
/** 清掉 .clawd-project.json.publishJob 字段。其他字段保持原样。 */
|
|
@@ -43596,13 +43986,13 @@ var ProjectStore = class {
|
|
|
43596
43986
|
if (!validated.success) {
|
|
43597
43987
|
throw new Error(`failed to clear publishJob: ${validated.error.message}`);
|
|
43598
43988
|
}
|
|
43599
|
-
await
|
|
43989
|
+
await import_node_fs32.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
43600
43990
|
return validated.data;
|
|
43601
43991
|
}
|
|
43602
43992
|
};
|
|
43603
43993
|
|
|
43604
43994
|
// src/app-builder/dev-server-supervisor.ts
|
|
43605
|
-
var
|
|
43995
|
+
var import_node_child_process12 = require("child_process");
|
|
43606
43996
|
var import_node_events2 = require("events");
|
|
43607
43997
|
var DEFAULT_READY_PATTERN = /Local:\s+https?:\/\/|Nest application successfully started|server listening on/i;
|
|
43608
43998
|
var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
@@ -43639,7 +44029,7 @@ var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
|
43639
44029
|
tunnelHost: args.tunnelHost,
|
|
43640
44030
|
devCommand: cmd
|
|
43641
44031
|
});
|
|
43642
|
-
const child = (0,
|
|
44032
|
+
const child = (0, import_node_child_process12.spawn)("sh", ["-c", cmd], {
|
|
43643
44033
|
cwd: args.cwd,
|
|
43644
44034
|
env,
|
|
43645
44035
|
stdio: "pipe",
|
|
@@ -44031,7 +44421,7 @@ function computeGrantForFrame(method, frame) {
|
|
|
44031
44421
|
}
|
|
44032
44422
|
|
|
44033
44423
|
// src/extension/runtime.ts
|
|
44034
|
-
var
|
|
44424
|
+
var import_node_child_process13 = require("child_process");
|
|
44035
44425
|
var import_node_path43 = __toESM(require("path"), 1);
|
|
44036
44426
|
var import_promises10 = require("timers/promises");
|
|
44037
44427
|
|
|
@@ -44118,17 +44508,17 @@ var Runtime = class {
|
|
|
44118
44508
|
const existing = this.handles.get(extId);
|
|
44119
44509
|
if (existing) return { kind: "local", port: existing.port };
|
|
44120
44510
|
const records = await loadAll(this.root);
|
|
44121
|
-
const
|
|
44122
|
-
if (!
|
|
44123
|
-
if (
|
|
44124
|
-
throw new RuntimeError("INVALID_MANIFEST",
|
|
44125
|
-
if (manifestMode(
|
|
44126
|
-
return { kind: "hosted", url:
|
|
44511
|
+
const rec2 = records.find((r) => r.extId === extId);
|
|
44512
|
+
if (!rec2) throw new RuntimeError("NOT_FOUND", `extension ${extId} not installed`);
|
|
44513
|
+
if (rec2.state === "invalid")
|
|
44514
|
+
throw new RuntimeError("INVALID_MANIFEST", rec2.invalidReason);
|
|
44515
|
+
if (manifestMode(rec2.manifest) === "hosted") {
|
|
44516
|
+
return { kind: "hosted", url: rec2.manifest.entry.url };
|
|
44127
44517
|
}
|
|
44128
44518
|
const port = await this.allocator.allocate().catch(() => {
|
|
44129
44519
|
throw new RuntimeError("PORT_EXHAUSTED", "no free port in configured range");
|
|
44130
44520
|
});
|
|
44131
|
-
const startCommand =
|
|
44521
|
+
const startCommand = rec2.manifest.runtime.startCommand;
|
|
44132
44522
|
const cmd = startCommand.replace(
|
|
44133
44523
|
/\$CLAWOS_EXT_PORT/g,
|
|
44134
44524
|
String(port)
|
|
@@ -44139,7 +44529,7 @@ var Runtime = class {
|
|
|
44139
44529
|
CLAWOS_EXT_PORT: String(port),
|
|
44140
44530
|
CLAWOS_EXT_ID: extId
|
|
44141
44531
|
};
|
|
44142
|
-
const child = (0,
|
|
44532
|
+
const child = (0, import_node_child_process13.spawn)("sh", ["-c", cmd], {
|
|
44143
44533
|
cwd: dir,
|
|
44144
44534
|
env,
|
|
44145
44535
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -44575,7 +44965,7 @@ async function startDaemon(config) {
|
|
|
44575
44965
|
const absPath = import_node_path46.default.isAbsolute(input.relPath) ? input.relPath : import_node_path46.default.join(input.cwd, input.relPath);
|
|
44576
44966
|
let size = 0;
|
|
44577
44967
|
try {
|
|
44578
|
-
size =
|
|
44968
|
+
size = import_node_fs33.default.statSync(absPath).size;
|
|
44579
44969
|
} catch (err) {
|
|
44580
44970
|
logger.warn("attachment.onFileEdit stat failed", {
|
|
44581
44971
|
sessionId: input.sessionId,
|
|
@@ -44645,6 +45035,7 @@ async function startDaemon(config) {
|
|
|
44645
45035
|
onReady: (tsid) => manager.dispatchReadyDetected(tsid)
|
|
44646
45036
|
}) : new ClaudeAdapter({ logger, historyReader: new ClaudeHistoryReader() });
|
|
44647
45037
|
registerAdapter("claude", claudeAdapter);
|
|
45038
|
+
registerAdapter("codex", new CodexAdapter({ logger }));
|
|
44648
45039
|
const personaRegistry = new PersonaRegistry(personaStore);
|
|
44649
45040
|
const personaManager = new PersonaManager({
|
|
44650
45041
|
store: personaStore,
|
|
@@ -45113,7 +45504,7 @@ ${bar}
|
|
|
45113
45504
|
`);
|
|
45114
45505
|
try {
|
|
45115
45506
|
const connectPath = import_node_path46.default.join(config.dataDir, "connect.txt");
|
|
45116
|
-
|
|
45507
|
+
import_node_fs33.default.writeFileSync(connectPath, lines.join("\n") + "\n", { mode: 384 });
|
|
45117
45508
|
} catch {
|
|
45118
45509
|
}
|
|
45119
45510
|
} catch (err) {
|
|
@@ -45186,7 +45577,7 @@ ${bar}
|
|
|
45186
45577
|
function migrateDropPersonsDir(dataDir) {
|
|
45187
45578
|
const dir = import_node_path46.default.join(dataDir, "persons");
|
|
45188
45579
|
try {
|
|
45189
|
-
|
|
45580
|
+
import_node_fs33.default.rmSync(dir, { recursive: true, force: true });
|
|
45190
45581
|
} catch {
|
|
45191
45582
|
}
|
|
45192
45583
|
}
|