@clawos-dev/clawd 0.2.573 → 0.2.574
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/app-builder-plugin/mcp-server.cjs +2 -2
- package/dist/cli.cjs +850 -904
- package/dist/dispatch/mcp-server.cjs +2 -2
- package/dist/persona-defaults/persona-app-builder/mcp/clawd-app-builder/mcp-server.cjs +2 -2
- package/dist/persona-defaults/persona-clawd-butler/.claude/skills/scan-persona-for-deploy/SKILL.md +39 -29
- package/dist/persona-defaults/persona-dataclaw-builder/mcp/clawd-app-builder/mcp-server.cjs +2 -2
- package/dist/share-ui/assets/{guest-CRh5Qm47.js → guest-Co-OS509.js} +1 -1
- package/dist/share-ui/guest.html +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -450,8 +450,8 @@ var init_parseUtil = __esm({
|
|
|
450
450
|
init_errors();
|
|
451
451
|
init_en();
|
|
452
452
|
makeIssue = (params) => {
|
|
453
|
-
const { data, path:
|
|
454
|
-
const fullPath = [...
|
|
453
|
+
const { data, path: path100, errorMaps, issueData } = params;
|
|
454
|
+
const fullPath = [...path100, ...issueData.path || []];
|
|
455
455
|
const fullIssue = {
|
|
456
456
|
...issueData,
|
|
457
457
|
path: fullPath
|
|
@@ -762,11 +762,11 @@ var init_types = __esm({
|
|
|
762
762
|
init_parseUtil();
|
|
763
763
|
init_util();
|
|
764
764
|
ParseInputLazyPath = class {
|
|
765
|
-
constructor(parent, value,
|
|
765
|
+
constructor(parent, value, path100, key) {
|
|
766
766
|
this._cachedPath = [];
|
|
767
767
|
this.parent = parent;
|
|
768
768
|
this.data = value;
|
|
769
|
-
this._path =
|
|
769
|
+
this._path = path100;
|
|
770
770
|
this._key = key;
|
|
771
771
|
}
|
|
772
772
|
get path() {
|
|
@@ -5998,8 +5998,8 @@ var init_environment_schemas = __esm({
|
|
|
5998
5998
|
url: external_exports.string().url(),
|
|
5999
5999
|
// 包内可执行文件的路径(`hbi` / `dist/bin/x`);空串 = 裸二进制
|
|
6000
6000
|
bin: external_exports.string(),
|
|
6001
|
-
sha256: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
6002
|
-
size: external_exports.number().int().positive()
|
|
6001
|
+
sha256: external_exports.string().regex(/^[0-9a-f]{64}$/).optional(),
|
|
6002
|
+
size: external_exports.number().int().positive().optional()
|
|
6003
6003
|
});
|
|
6004
6004
|
EnvPackageSchema = external_exports.object({
|
|
6005
6005
|
// 装完后在 PATH 里能直接调到的名字('aliyun' / 's' / 'pnpm' / 'python3');npm 包报 bin 名,包名进 from
|
|
@@ -10109,8 +10109,8 @@ var require_req = __commonJS({
|
|
|
10109
10109
|
if (req.originalUrl) {
|
|
10110
10110
|
_req.url = req.originalUrl;
|
|
10111
10111
|
} else {
|
|
10112
|
-
const
|
|
10113
|
-
_req.url = typeof
|
|
10112
|
+
const path100 = req.path;
|
|
10113
|
+
_req.url = typeof path100 === "string" ? path100 : req.url ? req.url.path || req.url : void 0;
|
|
10114
10114
|
}
|
|
10115
10115
|
if (req.query) {
|
|
10116
10116
|
_req.query = req.query;
|
|
@@ -10275,14 +10275,14 @@ var require_redact = __commonJS({
|
|
|
10275
10275
|
}
|
|
10276
10276
|
return obj;
|
|
10277
10277
|
}
|
|
10278
|
-
function parsePath(
|
|
10278
|
+
function parsePath(path100) {
|
|
10279
10279
|
const parts = [];
|
|
10280
10280
|
let current = "";
|
|
10281
10281
|
let inBrackets = false;
|
|
10282
10282
|
let inQuotes = false;
|
|
10283
10283
|
let quoteChar = "";
|
|
10284
|
-
for (let i2 = 0; i2 <
|
|
10285
|
-
const char =
|
|
10284
|
+
for (let i2 = 0; i2 < path100.length; i2++) {
|
|
10285
|
+
const char = path100[i2];
|
|
10286
10286
|
if (!inBrackets && char === ".") {
|
|
10287
10287
|
if (current) {
|
|
10288
10288
|
parts.push(current);
|
|
@@ -10413,10 +10413,10 @@ var require_redact = __commonJS({
|
|
|
10413
10413
|
return current;
|
|
10414
10414
|
}
|
|
10415
10415
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
10416
|
-
for (const
|
|
10417
|
-
const parts = parsePath(
|
|
10416
|
+
for (const path100 of paths) {
|
|
10417
|
+
const parts = parsePath(path100);
|
|
10418
10418
|
if (parts.includes("*")) {
|
|
10419
|
-
redactWildcardPath(obj, parts, censor,
|
|
10419
|
+
redactWildcardPath(obj, parts, censor, path100, remove);
|
|
10420
10420
|
} else {
|
|
10421
10421
|
if (remove) {
|
|
10422
10422
|
removeKey(obj, parts);
|
|
@@ -10501,8 +10501,8 @@ var require_redact = __commonJS({
|
|
|
10501
10501
|
}
|
|
10502
10502
|
} else {
|
|
10503
10503
|
if (afterWildcard.includes("*")) {
|
|
10504
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
10505
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
10504
|
+
const wrappedCensor = typeof censor === "function" ? (value, path100) => {
|
|
10505
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path100];
|
|
10506
10506
|
return censor(value, fullPath);
|
|
10507
10507
|
} : censor;
|
|
10508
10508
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -10537,8 +10537,8 @@ var require_redact = __commonJS({
|
|
|
10537
10537
|
return null;
|
|
10538
10538
|
}
|
|
10539
10539
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
10540
|
-
for (const
|
|
10541
|
-
const parts = parsePath(
|
|
10540
|
+
for (const path100 of pathsToClone) {
|
|
10541
|
+
const parts = parsePath(path100);
|
|
10542
10542
|
let current = pathStructure;
|
|
10543
10543
|
for (let i2 = 0; i2 < parts.length; i2++) {
|
|
10544
10544
|
const part = parts[i2];
|
|
@@ -10590,24 +10590,24 @@ var require_redact = __commonJS({
|
|
|
10590
10590
|
}
|
|
10591
10591
|
return cloneSelectively(obj, pathStructure);
|
|
10592
10592
|
}
|
|
10593
|
-
function validatePath(
|
|
10594
|
-
if (typeof
|
|
10593
|
+
function validatePath(path100) {
|
|
10594
|
+
if (typeof path100 !== "string") {
|
|
10595
10595
|
throw new Error("Paths must be (non-empty) strings");
|
|
10596
10596
|
}
|
|
10597
|
-
if (
|
|
10597
|
+
if (path100 === "") {
|
|
10598
10598
|
throw new Error("Invalid redaction path ()");
|
|
10599
10599
|
}
|
|
10600
|
-
if (
|
|
10601
|
-
throw new Error(`Invalid redaction path (${
|
|
10600
|
+
if (path100.includes("..")) {
|
|
10601
|
+
throw new Error(`Invalid redaction path (${path100})`);
|
|
10602
10602
|
}
|
|
10603
|
-
if (
|
|
10604
|
-
throw new Error(`Invalid redaction path (${
|
|
10603
|
+
if (path100.includes(",")) {
|
|
10604
|
+
throw new Error(`Invalid redaction path (${path100})`);
|
|
10605
10605
|
}
|
|
10606
10606
|
let bracketCount = 0;
|
|
10607
10607
|
let inQuotes = false;
|
|
10608
10608
|
let quoteChar = "";
|
|
10609
|
-
for (let i2 = 0; i2 <
|
|
10610
|
-
const char =
|
|
10609
|
+
for (let i2 = 0; i2 < path100.length; i2++) {
|
|
10610
|
+
const char = path100[i2];
|
|
10611
10611
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
10612
10612
|
if (!inQuotes) {
|
|
10613
10613
|
inQuotes = true;
|
|
@@ -10621,20 +10621,20 @@ var require_redact = __commonJS({
|
|
|
10621
10621
|
} else if (char === "]" && !inQuotes) {
|
|
10622
10622
|
bracketCount--;
|
|
10623
10623
|
if (bracketCount < 0) {
|
|
10624
|
-
throw new Error(`Invalid redaction path (${
|
|
10624
|
+
throw new Error(`Invalid redaction path (${path100})`);
|
|
10625
10625
|
}
|
|
10626
10626
|
}
|
|
10627
10627
|
}
|
|
10628
10628
|
if (bracketCount !== 0) {
|
|
10629
|
-
throw new Error(`Invalid redaction path (${
|
|
10629
|
+
throw new Error(`Invalid redaction path (${path100})`);
|
|
10630
10630
|
}
|
|
10631
10631
|
}
|
|
10632
10632
|
function validatePaths(paths) {
|
|
10633
10633
|
if (!Array.isArray(paths)) {
|
|
10634
10634
|
throw new TypeError("paths must be an array");
|
|
10635
10635
|
}
|
|
10636
|
-
for (const
|
|
10637
|
-
validatePath(
|
|
10636
|
+
for (const path100 of paths) {
|
|
10637
|
+
validatePath(path100);
|
|
10638
10638
|
}
|
|
10639
10639
|
}
|
|
10640
10640
|
function slowRedact(options = {}) {
|
|
@@ -10802,8 +10802,8 @@ var require_redaction = __commonJS({
|
|
|
10802
10802
|
if (shape[k3] === null) {
|
|
10803
10803
|
o2[k3] = (value) => topCensor(value, [k3]);
|
|
10804
10804
|
} else {
|
|
10805
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
10806
|
-
return censor(value, [k3, ...
|
|
10805
|
+
const wrappedCensor = typeof censor === "function" ? (value, path100) => {
|
|
10806
|
+
return censor(value, [k3, ...path100]);
|
|
10807
10807
|
} : censor;
|
|
10808
10808
|
o2[k3] = Redact({
|
|
10809
10809
|
paths: shape[k3],
|
|
@@ -11021,10 +11021,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
11021
11021
|
var require_sonic_boom = __commonJS({
|
|
11022
11022
|
"../node_modules/.pnpm/sonic-boom@4.2.1/node_modules/sonic-boom/index.js"(exports2, module2) {
|
|
11023
11023
|
"use strict";
|
|
11024
|
-
var
|
|
11024
|
+
var fs90 = require("fs");
|
|
11025
11025
|
var EventEmitter2 = require("events");
|
|
11026
11026
|
var inherits = require("util").inherits;
|
|
11027
|
-
var
|
|
11027
|
+
var path100 = require("path");
|
|
11028
11028
|
var sleep2 = require_atomic_sleep();
|
|
11029
11029
|
var assert = require("assert");
|
|
11030
11030
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -11078,20 +11078,20 @@ var require_sonic_boom = __commonJS({
|
|
|
11078
11078
|
const mode = sonic.mode;
|
|
11079
11079
|
if (sonic.sync) {
|
|
11080
11080
|
try {
|
|
11081
|
-
if (sonic.mkdir)
|
|
11082
|
-
const fd =
|
|
11081
|
+
if (sonic.mkdir) fs90.mkdirSync(path100.dirname(file), { recursive: true });
|
|
11082
|
+
const fd = fs90.openSync(file, flags, mode);
|
|
11083
11083
|
fileOpened(null, fd);
|
|
11084
11084
|
} catch (err) {
|
|
11085
11085
|
fileOpened(err);
|
|
11086
11086
|
throw err;
|
|
11087
11087
|
}
|
|
11088
11088
|
} else if (sonic.mkdir) {
|
|
11089
|
-
|
|
11089
|
+
fs90.mkdir(path100.dirname(file), { recursive: true }, (err) => {
|
|
11090
11090
|
if (err) return fileOpened(err);
|
|
11091
|
-
|
|
11091
|
+
fs90.open(file, flags, mode, fileOpened);
|
|
11092
11092
|
});
|
|
11093
11093
|
} else {
|
|
11094
|
-
|
|
11094
|
+
fs90.open(file, flags, mode, fileOpened);
|
|
11095
11095
|
}
|
|
11096
11096
|
}
|
|
11097
11097
|
function SonicBoom(opts) {
|
|
@@ -11132,8 +11132,8 @@ var require_sonic_boom = __commonJS({
|
|
|
11132
11132
|
this.flush = flushBuffer;
|
|
11133
11133
|
this.flushSync = flushBufferSync;
|
|
11134
11134
|
this._actualWrite = actualWriteBuffer;
|
|
11135
|
-
fsWriteSync = () =>
|
|
11136
|
-
fsWrite = () =>
|
|
11135
|
+
fsWriteSync = () => fs90.writeSync(this.fd, this._writingBuf);
|
|
11136
|
+
fsWrite = () => fs90.write(this.fd, this._writingBuf, this.release);
|
|
11137
11137
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
11138
11138
|
this._writingBuf = "";
|
|
11139
11139
|
this.write = write;
|
|
@@ -11142,15 +11142,15 @@ var require_sonic_boom = __commonJS({
|
|
|
11142
11142
|
this._actualWrite = actualWrite;
|
|
11143
11143
|
fsWriteSync = () => {
|
|
11144
11144
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
11145
|
-
return
|
|
11145
|
+
return fs90.writeSync(this.fd, this._writingBuf);
|
|
11146
11146
|
}
|
|
11147
|
-
return
|
|
11147
|
+
return fs90.writeSync(this.fd, this._writingBuf, "utf8");
|
|
11148
11148
|
};
|
|
11149
11149
|
fsWrite = () => {
|
|
11150
11150
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
11151
|
-
return
|
|
11151
|
+
return fs90.write(this.fd, this._writingBuf, this.release);
|
|
11152
11152
|
}
|
|
11153
|
-
return
|
|
11153
|
+
return fs90.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
11154
11154
|
};
|
|
11155
11155
|
} else {
|
|
11156
11156
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -11207,7 +11207,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11207
11207
|
}
|
|
11208
11208
|
}
|
|
11209
11209
|
if (this._fsync) {
|
|
11210
|
-
|
|
11210
|
+
fs90.fsyncSync(this.fd);
|
|
11211
11211
|
}
|
|
11212
11212
|
const len = this._len;
|
|
11213
11213
|
if (this._reopening) {
|
|
@@ -11321,7 +11321,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11321
11321
|
const onDrain = () => {
|
|
11322
11322
|
if (!this._fsync) {
|
|
11323
11323
|
try {
|
|
11324
|
-
|
|
11324
|
+
fs90.fsync(this.fd, (err) => {
|
|
11325
11325
|
this._flushPending = false;
|
|
11326
11326
|
cb(err);
|
|
11327
11327
|
});
|
|
@@ -11423,7 +11423,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11423
11423
|
const fd = this.fd;
|
|
11424
11424
|
this.once("ready", () => {
|
|
11425
11425
|
if (fd !== this.fd) {
|
|
11426
|
-
|
|
11426
|
+
fs90.close(fd, (err) => {
|
|
11427
11427
|
if (err) {
|
|
11428
11428
|
return this.emit("error", err);
|
|
11429
11429
|
}
|
|
@@ -11472,7 +11472,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11472
11472
|
buf = this._bufs[0];
|
|
11473
11473
|
}
|
|
11474
11474
|
try {
|
|
11475
|
-
const n2 = Buffer.isBuffer(buf) ?
|
|
11475
|
+
const n2 = Buffer.isBuffer(buf) ? fs90.writeSync(this.fd, buf) : fs90.writeSync(this.fd, buf, "utf8");
|
|
11476
11476
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n2);
|
|
11477
11477
|
buf = releasedBufObj.writingBuf;
|
|
11478
11478
|
this._len = releasedBufObj.len;
|
|
@@ -11488,7 +11488,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11488
11488
|
}
|
|
11489
11489
|
}
|
|
11490
11490
|
try {
|
|
11491
|
-
|
|
11491
|
+
fs90.fsyncSync(this.fd);
|
|
11492
11492
|
} catch {
|
|
11493
11493
|
}
|
|
11494
11494
|
}
|
|
@@ -11509,7 +11509,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11509
11509
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
11510
11510
|
}
|
|
11511
11511
|
try {
|
|
11512
|
-
const n2 =
|
|
11512
|
+
const n2 = fs90.writeSync(this.fd, buf);
|
|
11513
11513
|
buf = buf.subarray(n2);
|
|
11514
11514
|
this._len = Math.max(this._len - n2, 0);
|
|
11515
11515
|
if (buf.length <= 0) {
|
|
@@ -11537,13 +11537,13 @@ var require_sonic_boom = __commonJS({
|
|
|
11537
11537
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
11538
11538
|
if (this.sync) {
|
|
11539
11539
|
try {
|
|
11540
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
11540
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs90.writeSync(this.fd, this._writingBuf) : fs90.writeSync(this.fd, this._writingBuf, "utf8");
|
|
11541
11541
|
release2(null, written);
|
|
11542
11542
|
} catch (err) {
|
|
11543
11543
|
release2(err);
|
|
11544
11544
|
}
|
|
11545
11545
|
} else {
|
|
11546
|
-
|
|
11546
|
+
fs90.write(this.fd, this._writingBuf, release2);
|
|
11547
11547
|
}
|
|
11548
11548
|
}
|
|
11549
11549
|
function actualWriteBuffer() {
|
|
@@ -11552,7 +11552,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11552
11552
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
11553
11553
|
if (this.sync) {
|
|
11554
11554
|
try {
|
|
11555
|
-
const written =
|
|
11555
|
+
const written = fs90.writeSync(this.fd, this._writingBuf);
|
|
11556
11556
|
release2(null, written);
|
|
11557
11557
|
} catch (err) {
|
|
11558
11558
|
release2(err);
|
|
@@ -11561,7 +11561,7 @@ var require_sonic_boom = __commonJS({
|
|
|
11561
11561
|
if (kCopyBuffer) {
|
|
11562
11562
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
11563
11563
|
}
|
|
11564
|
-
|
|
11564
|
+
fs90.write(this.fd, this._writingBuf, release2);
|
|
11565
11565
|
}
|
|
11566
11566
|
}
|
|
11567
11567
|
function actualClose(sonic) {
|
|
@@ -11577,12 +11577,12 @@ var require_sonic_boom = __commonJS({
|
|
|
11577
11577
|
sonic._lens = [];
|
|
11578
11578
|
assert(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
11579
11579
|
try {
|
|
11580
|
-
|
|
11580
|
+
fs90.fsync(sonic.fd, closeWrapped);
|
|
11581
11581
|
} catch {
|
|
11582
11582
|
}
|
|
11583
11583
|
function closeWrapped() {
|
|
11584
11584
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
11585
|
-
|
|
11585
|
+
fs90.close(sonic.fd, done);
|
|
11586
11586
|
} else {
|
|
11587
11587
|
done();
|
|
11588
11588
|
}
|
|
@@ -12313,7 +12313,7 @@ var require_transport = __commonJS({
|
|
|
12313
12313
|
stream.flushSync();
|
|
12314
12314
|
}
|
|
12315
12315
|
function transport(fullOptions) {
|
|
12316
|
-
const { pipeline:
|
|
12316
|
+
const { pipeline: pipeline3, targets, levels, dedupe, worker = {}, caller = getCallers(), sync = false } = fullOptions;
|
|
12317
12317
|
const options = {
|
|
12318
12318
|
...fullOptions.options
|
|
12319
12319
|
};
|
|
@@ -12341,9 +12341,9 @@ var require_transport = __commonJS({
|
|
|
12341
12341
|
};
|
|
12342
12342
|
});
|
|
12343
12343
|
});
|
|
12344
|
-
} else if (
|
|
12344
|
+
} else if (pipeline3) {
|
|
12345
12345
|
target = bundlerOverrides["pino-worker"] || join17(__dirname, "worker.js");
|
|
12346
|
-
options.pipelines = [
|
|
12346
|
+
options.pipelines = [pipeline3.map((dest) => {
|
|
12347
12347
|
return {
|
|
12348
12348
|
...dest,
|
|
12349
12349
|
target: fixTarget(dest.target)
|
|
@@ -13946,7 +13946,7 @@ var require_multistream = __commonJS({
|
|
|
13946
13946
|
var require_pino = __commonJS({
|
|
13947
13947
|
"../node_modules/.pnpm/pino@9.14.0/node_modules/pino/pino.js"(exports2, module2) {
|
|
13948
13948
|
"use strict";
|
|
13949
|
-
var
|
|
13949
|
+
var os33 = require("os");
|
|
13950
13950
|
var stdSerializers = require_pino_std_serializers();
|
|
13951
13951
|
var caller = require_caller();
|
|
13952
13952
|
var redaction = require_redaction();
|
|
@@ -13993,7 +13993,7 @@ var require_pino = __commonJS({
|
|
|
13993
13993
|
} = symbols;
|
|
13994
13994
|
var { epochTime, nullTime } = time;
|
|
13995
13995
|
var { pid } = process;
|
|
13996
|
-
var hostname =
|
|
13996
|
+
var hostname = os33.hostname();
|
|
13997
13997
|
var defaultErrorSerializer = stdSerializers.err;
|
|
13998
13998
|
var defaultOptions2 = {
|
|
13999
13999
|
level: "info",
|
|
@@ -14717,11 +14717,11 @@ var init_lib = __esm({
|
|
|
14717
14717
|
}
|
|
14718
14718
|
}
|
|
14719
14719
|
},
|
|
14720
|
-
addToPath: function addToPath(
|
|
14721
|
-
var last =
|
|
14720
|
+
addToPath: function addToPath(path100, added, removed, oldPosInc, options) {
|
|
14721
|
+
var last = path100.lastComponent;
|
|
14722
14722
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
14723
14723
|
return {
|
|
14724
|
-
oldPos:
|
|
14724
|
+
oldPos: path100.oldPos + oldPosInc,
|
|
14725
14725
|
lastComponent: {
|
|
14726
14726
|
count: last.count + 1,
|
|
14727
14727
|
added,
|
|
@@ -14731,7 +14731,7 @@ var init_lib = __esm({
|
|
|
14731
14731
|
};
|
|
14732
14732
|
} else {
|
|
14733
14733
|
return {
|
|
14734
|
-
oldPos:
|
|
14734
|
+
oldPos: path100.oldPos + oldPosInc,
|
|
14735
14735
|
lastComponent: {
|
|
14736
14736
|
count: 1,
|
|
14737
14737
|
added,
|
|
@@ -15313,10 +15313,10 @@ function attachmentToHistoryMessage(o2, ts) {
|
|
|
15313
15313
|
const memories = raw.map((m3) => {
|
|
15314
15314
|
if (!m3 || typeof m3 !== "object") return null;
|
|
15315
15315
|
const rec6 = m3;
|
|
15316
|
-
const
|
|
15316
|
+
const path100 = typeof rec6.path === "string" ? rec6.path : null;
|
|
15317
15317
|
const content = typeof rec6.content === "string" ? rec6.content : null;
|
|
15318
|
-
if (!
|
|
15319
|
-
const entry = { path:
|
|
15318
|
+
if (!path100 || content == null) return null;
|
|
15319
|
+
const entry = { path: path100, content };
|
|
15320
15320
|
if (typeof rec6.mtimeMs === "number") entry.mtimeMs = rec6.mtimeMs;
|
|
15321
15321
|
return entry;
|
|
15322
15322
|
}).filter((m3) => m3 !== null);
|
|
@@ -16182,10 +16182,10 @@ function parseAttachment(obj) {
|
|
|
16182
16182
|
const memories = raw.map((m3) => {
|
|
16183
16183
|
if (!m3 || typeof m3 !== "object") return null;
|
|
16184
16184
|
const rec6 = m3;
|
|
16185
|
-
const
|
|
16185
|
+
const path100 = typeof rec6.path === "string" ? rec6.path : null;
|
|
16186
16186
|
const content = typeof rec6.content === "string" ? rec6.content : null;
|
|
16187
|
-
if (!
|
|
16188
|
-
const out = { path:
|
|
16187
|
+
if (!path100 || content == null) return null;
|
|
16188
|
+
const out = { path: path100, content };
|
|
16189
16189
|
if (typeof rec6.mtimeMs === "number") out.mtimeMs = rec6.mtimeMs;
|
|
16190
16190
|
return out;
|
|
16191
16191
|
}).filter((m3) => m3 !== null);
|
|
@@ -32869,8 +32869,8 @@ var require_websocket = __commonJS({
|
|
|
32869
32869
|
var http2 = require("http");
|
|
32870
32870
|
var net2 = require("net");
|
|
32871
32871
|
var tls = require("tls");
|
|
32872
|
-
var { randomBytes: randomBytes2, createHash:
|
|
32873
|
-
var { Duplex, Readable:
|
|
32872
|
+
var { randomBytes: randomBytes2, createHash: createHash2 } = require("crypto");
|
|
32873
|
+
var { Duplex, Readable: Readable3 } = require("stream");
|
|
32874
32874
|
var { URL: URL2 } = require("url");
|
|
32875
32875
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
32876
32876
|
var Receiver2 = require_receiver();
|
|
@@ -33529,7 +33529,7 @@ var require_websocket = __commonJS({
|
|
|
33529
33529
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
33530
33530
|
return;
|
|
33531
33531
|
}
|
|
33532
|
-
const digest =
|
|
33532
|
+
const digest = createHash2("sha1").update(key + GUID).digest("base64");
|
|
33533
33533
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
33534
33534
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
33535
33535
|
return;
|
|
@@ -33896,7 +33896,7 @@ var require_websocket_server = __commonJS({
|
|
|
33896
33896
|
var EventEmitter2 = require("events");
|
|
33897
33897
|
var http2 = require("http");
|
|
33898
33898
|
var { Duplex } = require("stream");
|
|
33899
|
-
var { createHash:
|
|
33899
|
+
var { createHash: createHash2 } = require("crypto");
|
|
33900
33900
|
var extension2 = require_extension();
|
|
33901
33901
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
33902
33902
|
var subprotocol2 = require_subprotocol();
|
|
@@ -34197,7 +34197,7 @@ var require_websocket_server = __commonJS({
|
|
|
34197
34197
|
);
|
|
34198
34198
|
}
|
|
34199
34199
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
34200
|
-
const digest =
|
|
34200
|
+
const digest = createHash2("sha1").update(key + GUID).digest("base64");
|
|
34201
34201
|
const headers = [
|
|
34202
34202
|
"HTTP/1.1 101 Switching Protocols",
|
|
34203
34203
|
"Upgrade: websocket",
|
|
@@ -35133,9 +35133,9 @@ var require_stream_duplex = __commonJS({
|
|
|
35133
35133
|
module2.exports = Duplex;
|
|
35134
35134
|
var util2 = Object.create(require_util());
|
|
35135
35135
|
util2.inherits = require_inherits();
|
|
35136
|
-
var
|
|
35136
|
+
var Readable3 = require_stream_readable();
|
|
35137
35137
|
var Writable3 = require_stream_writable();
|
|
35138
|
-
util2.inherits(Duplex,
|
|
35138
|
+
util2.inherits(Duplex, Readable3);
|
|
35139
35139
|
{
|
|
35140
35140
|
keys = objectKeys(Writable3.prototype);
|
|
35141
35141
|
for (v3 = 0; v3 < keys.length; v3++) {
|
|
@@ -35148,7 +35148,7 @@ var require_stream_duplex = __commonJS({
|
|
|
35148
35148
|
var v3;
|
|
35149
35149
|
function Duplex(options) {
|
|
35150
35150
|
if (!(this instanceof Duplex)) return new Duplex(options);
|
|
35151
|
-
|
|
35151
|
+
Readable3.call(this, options);
|
|
35152
35152
|
Writable3.call(this, options);
|
|
35153
35153
|
if (options && options.readable === false) this.readable = false;
|
|
35154
35154
|
if (options && options.writable === false) this.writable = false;
|
|
@@ -35438,10 +35438,10 @@ var require_stream_readable = __commonJS({
|
|
|
35438
35438
|
"../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js"(exports2, module2) {
|
|
35439
35439
|
"use strict";
|
|
35440
35440
|
var pna = require_process_nextick_args();
|
|
35441
|
-
module2.exports =
|
|
35441
|
+
module2.exports = Readable3;
|
|
35442
35442
|
var isArray = require_isarray();
|
|
35443
35443
|
var Duplex;
|
|
35444
|
-
|
|
35444
|
+
Readable3.ReadableState = ReadableState;
|
|
35445
35445
|
var EE = require("events").EventEmitter;
|
|
35446
35446
|
var EElistenerCount = function(emitter, type) {
|
|
35447
35447
|
return emitter.listeners(type).length;
|
|
@@ -35469,7 +35469,7 @@ var require_stream_readable = __commonJS({
|
|
|
35469
35469
|
var BufferList = require_BufferList();
|
|
35470
35470
|
var destroyImpl = require_destroy();
|
|
35471
35471
|
var StringDecoder2;
|
|
35472
|
-
util2.inherits(
|
|
35472
|
+
util2.inherits(Readable3, Stream);
|
|
35473
35473
|
var kProxyEvents = ["error", "close", "destroy", "pause", "resume"];
|
|
35474
35474
|
function prependListener(emitter, event, fn) {
|
|
35475
35475
|
if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn);
|
|
@@ -35515,9 +35515,9 @@ var require_stream_readable = __commonJS({
|
|
|
35515
35515
|
this.encoding = options.encoding;
|
|
35516
35516
|
}
|
|
35517
35517
|
}
|
|
35518
|
-
function
|
|
35518
|
+
function Readable3(options) {
|
|
35519
35519
|
Duplex = Duplex || require_stream_duplex();
|
|
35520
|
-
if (!(this instanceof
|
|
35520
|
+
if (!(this instanceof Readable3)) return new Readable3(options);
|
|
35521
35521
|
this._readableState = new ReadableState(options, this);
|
|
35522
35522
|
this.readable = true;
|
|
35523
35523
|
if (options) {
|
|
@@ -35526,7 +35526,7 @@ var require_stream_readable = __commonJS({
|
|
|
35526
35526
|
}
|
|
35527
35527
|
Stream.call(this);
|
|
35528
35528
|
}
|
|
35529
|
-
Object.defineProperty(
|
|
35529
|
+
Object.defineProperty(Readable3.prototype, "destroyed", {
|
|
35530
35530
|
get: function() {
|
|
35531
35531
|
if (this._readableState === void 0) {
|
|
35532
35532
|
return false;
|
|
@@ -35540,13 +35540,13 @@ var require_stream_readable = __commonJS({
|
|
|
35540
35540
|
this._readableState.destroyed = value;
|
|
35541
35541
|
}
|
|
35542
35542
|
});
|
|
35543
|
-
|
|
35544
|
-
|
|
35545
|
-
|
|
35543
|
+
Readable3.prototype.destroy = destroyImpl.destroy;
|
|
35544
|
+
Readable3.prototype._undestroy = destroyImpl.undestroy;
|
|
35545
|
+
Readable3.prototype._destroy = function(err, cb) {
|
|
35546
35546
|
this.push(null);
|
|
35547
35547
|
cb(err);
|
|
35548
35548
|
};
|
|
35549
|
-
|
|
35549
|
+
Readable3.prototype.push = function(chunk, encoding) {
|
|
35550
35550
|
var state = this._readableState;
|
|
35551
35551
|
var skipChunkCheck;
|
|
35552
35552
|
if (!state.objectMode) {
|
|
@@ -35563,7 +35563,7 @@ var require_stream_readable = __commonJS({
|
|
|
35563
35563
|
}
|
|
35564
35564
|
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
|
35565
35565
|
};
|
|
35566
|
-
|
|
35566
|
+
Readable3.prototype.unshift = function(chunk) {
|
|
35567
35567
|
return readableAddChunk(this, chunk, null, true, false);
|
|
35568
35568
|
};
|
|
35569
35569
|
function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
|
@@ -35623,10 +35623,10 @@ var require_stream_readable = __commonJS({
|
|
|
35623
35623
|
function needMoreData(state) {
|
|
35624
35624
|
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
|
35625
35625
|
}
|
|
35626
|
-
|
|
35626
|
+
Readable3.prototype.isPaused = function() {
|
|
35627
35627
|
return this._readableState.flowing === false;
|
|
35628
35628
|
};
|
|
35629
|
-
|
|
35629
|
+
Readable3.prototype.setEncoding = function(enc) {
|
|
35630
35630
|
if (!StringDecoder2) StringDecoder2 = require_string_decoder().StringDecoder;
|
|
35631
35631
|
this._readableState.decoder = new StringDecoder2(enc);
|
|
35632
35632
|
this._readableState.encoding = enc;
|
|
@@ -35662,7 +35662,7 @@ var require_stream_readable = __commonJS({
|
|
|
35662
35662
|
}
|
|
35663
35663
|
return state.length;
|
|
35664
35664
|
}
|
|
35665
|
-
|
|
35665
|
+
Readable3.prototype.read = function(n2) {
|
|
35666
35666
|
debug("read", n2);
|
|
35667
35667
|
n2 = parseInt(n2, 10);
|
|
35668
35668
|
var state = this._readableState;
|
|
@@ -35757,10 +35757,10 @@ var require_stream_readable = __commonJS({
|
|
|
35757
35757
|
}
|
|
35758
35758
|
state.readingMore = false;
|
|
35759
35759
|
}
|
|
35760
|
-
|
|
35760
|
+
Readable3.prototype._read = function(n2) {
|
|
35761
35761
|
this.emit("error", new Error("_read() is not implemented"));
|
|
35762
35762
|
};
|
|
35763
|
-
|
|
35763
|
+
Readable3.prototype.pipe = function(dest, pipeOpts) {
|
|
35764
35764
|
var src = this;
|
|
35765
35765
|
var state = this._readableState;
|
|
35766
35766
|
switch (state.pipesCount) {
|
|
@@ -35865,7 +35865,7 @@ var require_stream_readable = __commonJS({
|
|
|
35865
35865
|
}
|
|
35866
35866
|
};
|
|
35867
35867
|
}
|
|
35868
|
-
|
|
35868
|
+
Readable3.prototype.unpipe = function(dest) {
|
|
35869
35869
|
var state = this._readableState;
|
|
35870
35870
|
var unpipeInfo = { hasUnpiped: false };
|
|
35871
35871
|
if (state.pipesCount === 0) return this;
|
|
@@ -35897,7 +35897,7 @@ var require_stream_readable = __commonJS({
|
|
|
35897
35897
|
dest.emit("unpipe", this, unpipeInfo);
|
|
35898
35898
|
return this;
|
|
35899
35899
|
};
|
|
35900
|
-
|
|
35900
|
+
Readable3.prototype.on = function(ev, fn) {
|
|
35901
35901
|
var res = Stream.prototype.on.call(this, ev, fn);
|
|
35902
35902
|
if (ev === "data") {
|
|
35903
35903
|
if (this._readableState.flowing !== false) this.resume();
|
|
@@ -35915,12 +35915,12 @@ var require_stream_readable = __commonJS({
|
|
|
35915
35915
|
}
|
|
35916
35916
|
return res;
|
|
35917
35917
|
};
|
|
35918
|
-
|
|
35918
|
+
Readable3.prototype.addListener = Readable3.prototype.on;
|
|
35919
35919
|
function nReadingNextTick(self2) {
|
|
35920
35920
|
debug("readable nexttick read 0");
|
|
35921
35921
|
self2.read(0);
|
|
35922
35922
|
}
|
|
35923
|
-
|
|
35923
|
+
Readable3.prototype.resume = function() {
|
|
35924
35924
|
var state = this._readableState;
|
|
35925
35925
|
if (!state.flowing) {
|
|
35926
35926
|
debug("resume");
|
|
@@ -35946,7 +35946,7 @@ var require_stream_readable = __commonJS({
|
|
|
35946
35946
|
flow(stream);
|
|
35947
35947
|
if (state.flowing && !state.reading) stream.read(0);
|
|
35948
35948
|
}
|
|
35949
|
-
|
|
35949
|
+
Readable3.prototype.pause = function() {
|
|
35950
35950
|
debug("call pause flowing=%j", this._readableState.flowing);
|
|
35951
35951
|
if (false !== this._readableState.flowing) {
|
|
35952
35952
|
debug("pause");
|
|
@@ -35961,7 +35961,7 @@ var require_stream_readable = __commonJS({
|
|
|
35961
35961
|
while (state.flowing && stream.read() !== null) {
|
|
35962
35962
|
}
|
|
35963
35963
|
}
|
|
35964
|
-
|
|
35964
|
+
Readable3.prototype.wrap = function(stream) {
|
|
35965
35965
|
var _this = this;
|
|
35966
35966
|
var state = this._readableState;
|
|
35967
35967
|
var paused = false;
|
|
@@ -36005,7 +36005,7 @@ var require_stream_readable = __commonJS({
|
|
|
36005
36005
|
};
|
|
36006
36006
|
return this;
|
|
36007
36007
|
};
|
|
36008
|
-
Object.defineProperty(
|
|
36008
|
+
Object.defineProperty(Readable3.prototype, "readableHighWaterMark", {
|
|
36009
36009
|
// making it explicit this property is not enumerable
|
|
36010
36010
|
// because otherwise some prototype manipulation in
|
|
36011
36011
|
// userland will fail
|
|
@@ -36014,7 +36014,7 @@ var require_stream_readable = __commonJS({
|
|
|
36014
36014
|
return this._readableState.highWaterMark;
|
|
36015
36015
|
}
|
|
36016
36016
|
});
|
|
36017
|
-
|
|
36017
|
+
Readable3._fromList = fromList;
|
|
36018
36018
|
function fromList(n2, state) {
|
|
36019
36019
|
if (state.length === 0) return null;
|
|
36020
36020
|
var ret;
|
|
@@ -36123,11 +36123,11 @@ var require_stream_readable = __commonJS({
|
|
|
36123
36123
|
var require_stream_transform = __commonJS({
|
|
36124
36124
|
"../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_transform.js"(exports2, module2) {
|
|
36125
36125
|
"use strict";
|
|
36126
|
-
module2.exports =
|
|
36126
|
+
module2.exports = Transform;
|
|
36127
36127
|
var Duplex = require_stream_duplex();
|
|
36128
36128
|
var util2 = Object.create(require_util());
|
|
36129
36129
|
util2.inherits = require_inherits();
|
|
36130
|
-
util2.inherits(
|
|
36130
|
+
util2.inherits(Transform, Duplex);
|
|
36131
36131
|
function afterTransform(er2, data) {
|
|
36132
36132
|
var ts = this._transformState;
|
|
36133
36133
|
ts.transforming = false;
|
|
@@ -36146,8 +36146,8 @@ var require_stream_transform = __commonJS({
|
|
|
36146
36146
|
this._read(rs.highWaterMark);
|
|
36147
36147
|
}
|
|
36148
36148
|
}
|
|
36149
|
-
function
|
|
36150
|
-
if (!(this instanceof
|
|
36149
|
+
function Transform(options) {
|
|
36150
|
+
if (!(this instanceof Transform)) return new Transform(options);
|
|
36151
36151
|
Duplex.call(this, options);
|
|
36152
36152
|
this._transformState = {
|
|
36153
36153
|
afterTransform: afterTransform.bind(this),
|
|
@@ -36175,14 +36175,14 @@ var require_stream_transform = __commonJS({
|
|
|
36175
36175
|
done(this, null, null);
|
|
36176
36176
|
}
|
|
36177
36177
|
}
|
|
36178
|
-
|
|
36178
|
+
Transform.prototype.push = function(chunk, encoding) {
|
|
36179
36179
|
this._transformState.needTransform = false;
|
|
36180
36180
|
return Duplex.prototype.push.call(this, chunk, encoding);
|
|
36181
36181
|
};
|
|
36182
|
-
|
|
36182
|
+
Transform.prototype._transform = function(chunk, encoding, cb) {
|
|
36183
36183
|
throw new Error("_transform() is not implemented");
|
|
36184
36184
|
};
|
|
36185
|
-
|
|
36185
|
+
Transform.prototype._write = function(chunk, encoding, cb) {
|
|
36186
36186
|
var ts = this._transformState;
|
|
36187
36187
|
ts.writecb = cb;
|
|
36188
36188
|
ts.writechunk = chunk;
|
|
@@ -36192,7 +36192,7 @@ var require_stream_transform = __commonJS({
|
|
|
36192
36192
|
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
|
36193
36193
|
}
|
|
36194
36194
|
};
|
|
36195
|
-
|
|
36195
|
+
Transform.prototype._read = function(n2) {
|
|
36196
36196
|
var ts = this._transformState;
|
|
36197
36197
|
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
|
36198
36198
|
ts.transforming = true;
|
|
@@ -36201,7 +36201,7 @@ var require_stream_transform = __commonJS({
|
|
|
36201
36201
|
ts.needTransform = true;
|
|
36202
36202
|
}
|
|
36203
36203
|
};
|
|
36204
|
-
|
|
36204
|
+
Transform.prototype._destroy = function(err, cb) {
|
|
36205
36205
|
var _this2 = this;
|
|
36206
36206
|
Duplex.prototype._destroy.call(this, err, function(err2) {
|
|
36207
36207
|
cb(err2);
|
|
@@ -36224,13 +36224,13 @@ var require_stream_passthrough = __commonJS({
|
|
|
36224
36224
|
"../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_passthrough.js"(exports2, module2) {
|
|
36225
36225
|
"use strict";
|
|
36226
36226
|
module2.exports = PassThrough;
|
|
36227
|
-
var
|
|
36227
|
+
var Transform = require_stream_transform();
|
|
36228
36228
|
var util2 = Object.create(require_util());
|
|
36229
36229
|
util2.inherits = require_inherits();
|
|
36230
|
-
util2.inherits(PassThrough,
|
|
36230
|
+
util2.inherits(PassThrough, Transform);
|
|
36231
36231
|
function PassThrough(options) {
|
|
36232
36232
|
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
|
36233
|
-
|
|
36233
|
+
Transform.call(this, options);
|
|
36234
36234
|
}
|
|
36235
36235
|
PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
|
36236
36236
|
cb(null, chunk);
|
|
@@ -37159,8 +37159,8 @@ var require_utils = __commonJS({
|
|
|
37159
37159
|
var result = transform[inputType][outputType](input);
|
|
37160
37160
|
return result;
|
|
37161
37161
|
};
|
|
37162
|
-
exports2.resolve = function(
|
|
37163
|
-
var parts =
|
|
37162
|
+
exports2.resolve = function(path100) {
|
|
37163
|
+
var parts = path100.split("/");
|
|
37164
37164
|
var result = [];
|
|
37165
37165
|
for (var index = 0; index < parts.length; index++) {
|
|
37166
37166
|
var part = parts[index];
|
|
@@ -37713,11 +37713,11 @@ var require_ConvertWorker = __commonJS({
|
|
|
37713
37713
|
var require_NodejsStreamOutputAdapter = __commonJS({
|
|
37714
37714
|
"../node_modules/.pnpm/jszip@3.10.1/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js"(exports2, module2) {
|
|
37715
37715
|
"use strict";
|
|
37716
|
-
var
|
|
37716
|
+
var Readable3 = require_readable().Readable;
|
|
37717
37717
|
var utils = require_utils();
|
|
37718
|
-
utils.inherits(NodejsStreamOutputAdapter,
|
|
37718
|
+
utils.inherits(NodejsStreamOutputAdapter, Readable3);
|
|
37719
37719
|
function NodejsStreamOutputAdapter(helper, options, updateCb) {
|
|
37720
|
-
|
|
37720
|
+
Readable3.call(this, options);
|
|
37721
37721
|
this._helper = helper;
|
|
37722
37722
|
var self2 = this;
|
|
37723
37723
|
helper.on("data", function(data, meta) {
|
|
@@ -43013,18 +43013,18 @@ var require_object = __commonJS({
|
|
|
43013
43013
|
var object = new ZipObject(name, zipObjectContent, o2);
|
|
43014
43014
|
this.files[name] = object;
|
|
43015
43015
|
};
|
|
43016
|
-
var parentFolder = function(
|
|
43017
|
-
if (
|
|
43018
|
-
|
|
43016
|
+
var parentFolder = function(path100) {
|
|
43017
|
+
if (path100.slice(-1) === "/") {
|
|
43018
|
+
path100 = path100.substring(0, path100.length - 1);
|
|
43019
43019
|
}
|
|
43020
|
-
var lastSlash =
|
|
43021
|
-
return lastSlash > 0 ?
|
|
43020
|
+
var lastSlash = path100.lastIndexOf("/");
|
|
43021
|
+
return lastSlash > 0 ? path100.substring(0, lastSlash) : "";
|
|
43022
43022
|
};
|
|
43023
|
-
var forceTrailingSlash = function(
|
|
43024
|
-
if (
|
|
43025
|
-
|
|
43023
|
+
var forceTrailingSlash = function(path100) {
|
|
43024
|
+
if (path100.slice(-1) !== "/") {
|
|
43025
|
+
path100 += "/";
|
|
43026
43026
|
}
|
|
43027
|
-
return
|
|
43027
|
+
return path100;
|
|
43028
43028
|
};
|
|
43029
43029
|
var folderAdd = function(name, createFolders) {
|
|
43030
43030
|
createFolders = typeof createFolders !== "undefined" ? createFolders : defaults.createFolders;
|
|
@@ -44026,7 +44026,7 @@ var require_lib3 = __commonJS({
|
|
|
44026
44026
|
// src/run-case/recorder.ts
|
|
44027
44027
|
function startRunCaseRecorder(opts) {
|
|
44028
44028
|
const now = opts.now ?? Date.now;
|
|
44029
|
-
const dir =
|
|
44029
|
+
const dir = import_node_path79.default.dirname(opts.recordPath);
|
|
44030
44030
|
let stream = null;
|
|
44031
44031
|
let closing = false;
|
|
44032
44032
|
let closedSettled = false;
|
|
@@ -44040,8 +44040,8 @@ function startRunCaseRecorder(opts) {
|
|
|
44040
44040
|
});
|
|
44041
44041
|
const ensureStream = () => {
|
|
44042
44042
|
if (stream) return stream;
|
|
44043
|
-
|
|
44044
|
-
stream =
|
|
44043
|
+
import_node_fs61.default.mkdirSync(dir, { recursive: true });
|
|
44044
|
+
stream = import_node_fs61.default.createWriteStream(opts.recordPath, { flags: "a" });
|
|
44045
44045
|
stream.on("close", () => closedResolve());
|
|
44046
44046
|
return stream;
|
|
44047
44047
|
};
|
|
@@ -44066,12 +44066,12 @@ function startRunCaseRecorder(opts) {
|
|
|
44066
44066
|
};
|
|
44067
44067
|
return { tap, close, closed };
|
|
44068
44068
|
}
|
|
44069
|
-
var
|
|
44069
|
+
var import_node_fs61, import_node_path79;
|
|
44070
44070
|
var init_recorder = __esm({
|
|
44071
44071
|
"src/run-case/recorder.ts"() {
|
|
44072
44072
|
"use strict";
|
|
44073
|
-
|
|
44074
|
-
|
|
44073
|
+
import_node_fs61 = __toESM(require("fs"), 1);
|
|
44074
|
+
import_node_path79 = __toESM(require("path"), 1);
|
|
44075
44075
|
}
|
|
44076
44076
|
});
|
|
44077
44077
|
|
|
@@ -44114,7 +44114,7 @@ var init_wire = __esm({
|
|
|
44114
44114
|
// src/run-case/controller.ts
|
|
44115
44115
|
async function runController(opts) {
|
|
44116
44116
|
const now = opts.now ?? Date.now;
|
|
44117
|
-
const cwd = opts.cwd ?? (0,
|
|
44117
|
+
const cwd = opts.cwd ?? (0, import_node_fs62.mkdtempSync)(import_node_path80.default.join(import_node_os29.default.tmpdir(), "clawd-runcase-"));
|
|
44118
44118
|
const ownsCwd = opts.cwd === void 0;
|
|
44119
44119
|
const recorder = startRunCaseRecorder({ recordPath: opts.record, now });
|
|
44120
44120
|
const spawnCtx = { cwd };
|
|
@@ -44275,19 +44275,19 @@ async function runController(opts) {
|
|
|
44275
44275
|
if (sigintHandler) process.off("SIGINT", sigintHandler);
|
|
44276
44276
|
if (ownsCwd) {
|
|
44277
44277
|
try {
|
|
44278
|
-
(0,
|
|
44278
|
+
(0, import_node_fs62.rmSync)(cwd, { recursive: true, force: true });
|
|
44279
44279
|
} catch {
|
|
44280
44280
|
}
|
|
44281
44281
|
}
|
|
44282
44282
|
return exitCode ?? 0;
|
|
44283
44283
|
}
|
|
44284
|
-
var
|
|
44284
|
+
var import_node_fs62, import_node_os29, import_node_path80;
|
|
44285
44285
|
var init_controller = __esm({
|
|
44286
44286
|
"src/run-case/controller.ts"() {
|
|
44287
44287
|
"use strict";
|
|
44288
|
-
|
|
44289
|
-
|
|
44290
|
-
|
|
44288
|
+
import_node_fs62 = require("fs");
|
|
44289
|
+
import_node_os29 = __toESM(require("os"), 1);
|
|
44290
|
+
import_node_path80 = __toESM(require("path"), 1);
|
|
44291
44291
|
init_claude();
|
|
44292
44292
|
init_stdout_splitter();
|
|
44293
44293
|
init_permission_stdio();
|
|
@@ -44559,10 +44559,10 @@ Env (advanced):
|
|
|
44559
44559
|
`;
|
|
44560
44560
|
|
|
44561
44561
|
// src/index.ts
|
|
44562
|
-
var
|
|
44563
|
-
var
|
|
44564
|
-
var
|
|
44565
|
-
var
|
|
44562
|
+
var import_node_path78 = __toESM(require("path"), 1);
|
|
44563
|
+
var import_node_fs60 = __toESM(require("fs"), 1);
|
|
44564
|
+
var import_node_os28 = __toESM(require("os"), 1);
|
|
44565
|
+
var import_node_crypto24 = require("crypto");
|
|
44566
44566
|
var import_node_url5 = require("url");
|
|
44567
44567
|
|
|
44568
44568
|
// src/logger.ts
|
|
@@ -51873,8 +51873,8 @@ function turnStartInput(text, resolveImage) {
|
|
|
51873
51873
|
const items = [];
|
|
51874
51874
|
let leftover = text;
|
|
51875
51875
|
for (const m3 of text.matchAll(SKILL_RE)) {
|
|
51876
|
-
const [marker, name,
|
|
51877
|
-
items.push({ type: "skill", name, path:
|
|
51876
|
+
const [marker, name, path100] = m3;
|
|
51877
|
+
items.push({ type: "skill", name, path: path100 });
|
|
51878
51878
|
leftover = leftover.replace(marker, "");
|
|
51879
51879
|
}
|
|
51880
51880
|
for (const m3 of text.matchAll(ATTACHMENT_RE2)) {
|
|
@@ -55695,14 +55695,6 @@ function requiredEnvNames(manifest) {
|
|
|
55695
55695
|
}
|
|
55696
55696
|
|
|
55697
55697
|
// src/deploy/artifact.ts
|
|
55698
|
-
var import_node_crypto9 = require("crypto");
|
|
55699
|
-
var import_node_fs30 = __toESM(require("fs"), 1);
|
|
55700
|
-
var import_node_os10 = __toESM(require("os"), 1);
|
|
55701
|
-
var import_node_path34 = __toESM(require("path"), 1);
|
|
55702
|
-
var import_node_stream3 = require("stream");
|
|
55703
|
-
var import_promises5 = require("stream/promises");
|
|
55704
|
-
var ARTIFACT_MAX_BYTES = 200 * 1024 * 1024;
|
|
55705
|
-
var ARTIFACT_TIMEOUT_MS = 6e4;
|
|
55706
55698
|
function artifactKind(url, bin) {
|
|
55707
55699
|
const u2 = new URL(url);
|
|
55708
55700
|
if (u2.protocol !== "https:") throw new Error(`\u8D44\u4EA7\u53EA\u6536 https \u76F4\u94FE\uFF1A${url}`);
|
|
@@ -55714,54 +55706,10 @@ function artifactKind(url, bin) {
|
|
|
55714
55706
|
if (bin === "") return "bare";
|
|
55715
55707
|
throw new Error(`\u8D44\u4EA7\u53EA\u8BA4 .tar.gz / .tgz\uFF0C\u6216\u88F8\u4E8C\u8FDB\u5236\uFF08bin \u7559\u7A7A\uFF09\uFF1A${url}`);
|
|
55716
55708
|
}
|
|
55717
|
-
async function verifyArtifact(fetchArtifact, a2) {
|
|
55718
|
-
const kind = artifactKind(a2.url, a2.bin);
|
|
55719
|
-
const got = await fetchArtifact(a2.url, { listEntries: kind === "tgz" });
|
|
55720
|
-
if (kind === "tgz") {
|
|
55721
|
-
const names = (got.entries ?? []).map((e) => e.replace(/^\.\//, ""));
|
|
55722
|
-
if (!names.includes(a2.bin)) {
|
|
55723
|
-
const shown = names.slice(0, 10).join(", ") + (names.length > 10 ? "\u2026" : "");
|
|
55724
|
-
throw new Error(`\u538B\u7F29\u5305\u91CC\u6CA1\u6709 \`${a2.bin}\`\uFF1A${a2.url}\uFF08\u5305\u91CC\u6709\uFF1A${shown}\uFF09`);
|
|
55725
|
-
}
|
|
55726
|
-
}
|
|
55727
|
-
return { sha256: got.sha256, size: got.size };
|
|
55728
|
-
}
|
|
55729
|
-
function downloadArtifact(exec) {
|
|
55730
|
-
return async (url, { listEntries }) => {
|
|
55731
|
-
const res = await fetch(url, { signal: AbortSignal.timeout(ARTIFACT_TIMEOUT_MS), redirect: "follow" });
|
|
55732
|
-
if (!res.ok || !res.body) throw new Error(`\u4E0B\u8F7D\u5931\u8D25 HTTP ${res.status}\uFF1A${url}`);
|
|
55733
|
-
const declared = Number(res.headers.get("content-length") ?? 0);
|
|
55734
|
-
if (declared > ARTIFACT_MAX_BYTES) throw new Error(`\u8D44\u4EA7 ${declared} \u5B57\u8282\uFF0C\u8D85\u8FC7\u4E0A\u9650 ${ARTIFACT_MAX_BYTES}\uFF1A${url}`);
|
|
55735
|
-
const dir = await import_node_fs30.default.promises.mkdtemp(import_node_path34.default.join(import_node_os10.default.tmpdir(), "clawd-artifact-"));
|
|
55736
|
-
const file = import_node_path34.default.join(dir, "pkg");
|
|
55737
|
-
const hash = (0, import_node_crypto9.createHash)("sha256");
|
|
55738
|
-
let size = 0;
|
|
55739
|
-
const meter = new import_node_stream3.Transform({
|
|
55740
|
-
transform(chunk, _enc, cb) {
|
|
55741
|
-
size += chunk.length;
|
|
55742
|
-
if (size > ARTIFACT_MAX_BYTES) return cb(new Error(`\u8D44\u4EA7\u8D85\u8FC7\u4E0A\u9650 ${ARTIFACT_MAX_BYTES} \u5B57\u8282\uFF1A${url}`));
|
|
55743
|
-
hash.update(chunk);
|
|
55744
|
-
cb(null, chunk);
|
|
55745
|
-
}
|
|
55746
|
-
});
|
|
55747
|
-
try {
|
|
55748
|
-
await (0, import_promises5.pipeline)(import_node_stream3.Readable.fromWeb(res.body), meter, import_node_fs30.default.createWriteStream(file));
|
|
55749
|
-
let entries;
|
|
55750
|
-
if (listEntries) {
|
|
55751
|
-
const r2 = await exec("tar", ["-tzf", file], { timeoutMs: 3e4 });
|
|
55752
|
-
if (r2.code !== 0) throw new Error(`\u4E0D\u662F\u5408\u6CD5\u7684 tar.gz\uFF1A${url}\uFF08${r2.stderr.trim()}\uFF09`);
|
|
55753
|
-
entries = r2.stdout.split("\n").filter(Boolean);
|
|
55754
|
-
}
|
|
55755
|
-
return { sha256: hash.digest("hex"), size, ...entries ? { entries } : {} };
|
|
55756
|
-
} finally {
|
|
55757
|
-
await import_node_fs30.default.promises.rm(dir, { recursive: true, force: true });
|
|
55758
|
-
}
|
|
55759
|
-
};
|
|
55760
|
-
}
|
|
55761
55709
|
|
|
55762
55710
|
// src/deploy/repo.ts
|
|
55763
|
-
var
|
|
55764
|
-
var
|
|
55711
|
+
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
55712
|
+
var import_node_path34 = __toESM(require("path"), 1);
|
|
55765
55713
|
init_protocol();
|
|
55766
55714
|
|
|
55767
55715
|
// ../node_modules/.pnpm/libsodium@0.8.4/node_modules/libsodium/dist/modules-esm/libsodium.mjs
|
|
@@ -59222,10 +59170,10 @@ function createGithubApi(args) {
|
|
|
59222
59170
|
const doFetch = args.fetch ?? fetch;
|
|
59223
59171
|
const seal = args.seal ?? sealWithSodium;
|
|
59224
59172
|
const timeoutMs = args.timeoutMs ?? TIMEOUT_MS;
|
|
59225
|
-
async function request(method,
|
|
59173
|
+
async function request(method, path100, body) {
|
|
59226
59174
|
let res;
|
|
59227
59175
|
try {
|
|
59228
|
-
res = await doFetch(`${API}${
|
|
59176
|
+
res = await doFetch(`${API}${path100}`, {
|
|
59229
59177
|
method,
|
|
59230
59178
|
headers: {
|
|
59231
59179
|
Authorization: `Bearer ${args.token}`,
|
|
@@ -59250,8 +59198,8 @@ function createGithubApi(args) {
|
|
|
59250
59198
|
}
|
|
59251
59199
|
return { status: res.status, json };
|
|
59252
59200
|
}
|
|
59253
|
-
async function must(method,
|
|
59254
|
-
const r2 = await request(method,
|
|
59201
|
+
async function must(method, path100, what, body) {
|
|
59202
|
+
const r2 = await request(method, path100, body);
|
|
59255
59203
|
if (r2.status < 200 || r2.status >= 300) throw new GithubApiError(r2.status, explain(r2.status, what, r2.json));
|
|
59256
59204
|
return r2.json;
|
|
59257
59205
|
}
|
|
@@ -59291,9 +59239,9 @@ function createGithubApi(args) {
|
|
|
59291
59239
|
return { env: x2.name, ...Number.isFinite(at3) ? { setAt: at3 } : {} };
|
|
59292
59240
|
});
|
|
59293
59241
|
},
|
|
59294
|
-
async getJson(
|
|
59242
|
+
async getJson(path100) {
|
|
59295
59243
|
try {
|
|
59296
|
-
const r2 = await request("GET",
|
|
59244
|
+
const r2 = await request("GET", path100);
|
|
59297
59245
|
return r2.status >= 200 && r2.status < 300 ? r2.json : void 0;
|
|
59298
59246
|
} catch {
|
|
59299
59247
|
return void 0;
|
|
@@ -59658,7 +59606,7 @@ var runCommand = (cmd, args, opts = {}) => new Promise((resolve9) => {
|
|
|
59658
59606
|
});
|
|
59659
59607
|
|
|
59660
59608
|
// src/deploy/repo.ts
|
|
59661
|
-
var DEPLOY_FILE_REL = DEPLOY_FILE.split(
|
|
59609
|
+
var DEPLOY_FILE_REL = DEPLOY_FILE.split(import_node_path34.default.sep).join("/");
|
|
59662
59610
|
var PERSONA_FILE_REL = ".clawd/persona.json";
|
|
59663
59611
|
var DIRTY_IGNORED = [DEPLOY_FILE_REL, PERSONA_FILE_REL];
|
|
59664
59612
|
var RepoError = class extends Error {
|
|
@@ -59695,9 +59643,9 @@ async function isToplevel(exec, dir) {
|
|
|
59695
59643
|
async function samePath(a2, b3) {
|
|
59696
59644
|
const real = async (x2) => {
|
|
59697
59645
|
try {
|
|
59698
|
-
return await
|
|
59646
|
+
return await import_promises5.default.realpath(x2);
|
|
59699
59647
|
} catch {
|
|
59700
|
-
return
|
|
59648
|
+
return import_node_path34.default.resolve(x2);
|
|
59701
59649
|
}
|
|
59702
59650
|
};
|
|
59703
59651
|
return await real(a2) === await real(b3);
|
|
@@ -59723,23 +59671,23 @@ async function identityArgs(exec, dir) {
|
|
|
59723
59671
|
return ["-c", "user.name=clawd", "-c", "user.email=clawd@clawos.local"];
|
|
59724
59672
|
}
|
|
59725
59673
|
async function writeGitignore(dir) {
|
|
59726
|
-
const gi =
|
|
59674
|
+
const gi = import_node_path34.default.join(dir, ".gitignore");
|
|
59727
59675
|
let existing;
|
|
59728
59676
|
try {
|
|
59729
|
-
existing = await
|
|
59677
|
+
existing = await import_promises5.default.readFile(gi, "utf8");
|
|
59730
59678
|
} catch {
|
|
59731
59679
|
existing = void 0;
|
|
59732
59680
|
}
|
|
59733
|
-
await
|
|
59681
|
+
await import_promises5.default.writeFile(gi, mergeGitignore(existing));
|
|
59734
59682
|
}
|
|
59735
59683
|
async function writeWorkflow(dir) {
|
|
59736
|
-
const wf =
|
|
59737
|
-
await
|
|
59738
|
-
await
|
|
59684
|
+
const wf = import_node_path34.default.join(dir, WORKFLOW_PATH);
|
|
59685
|
+
await import_promises5.default.mkdir(import_node_path34.default.dirname(wf), { recursive: true });
|
|
59686
|
+
await import_promises5.default.writeFile(wf, WORKFLOW_TEMPLATE);
|
|
59739
59687
|
}
|
|
59740
59688
|
async function writeDockerfile(dir, personaId2) {
|
|
59741
|
-
await
|
|
59742
|
-
await
|
|
59689
|
+
await import_promises5.default.writeFile(import_node_path34.default.join(dir, DOCKERFILE_PATH), renderDockerfile(personaId2));
|
|
59690
|
+
await import_promises5.default.writeFile(import_node_path34.default.join(dir, DOCKERIGNORE_PATH), DOCKERIGNORE_TEMPLATE);
|
|
59743
59691
|
}
|
|
59744
59692
|
var RepoAlreadyExistsError = class extends RepoError {
|
|
59745
59693
|
constructor(slug) {
|
|
@@ -59776,7 +59724,7 @@ async function ensureRepo(exec, api, args) {
|
|
|
59776
59724
|
const existing = await repoInfo(exec, dir);
|
|
59777
59725
|
if (existing) return { created: false, url: existing.url };
|
|
59778
59726
|
await writeGitignore(dir);
|
|
59779
|
-
await
|
|
59727
|
+
await import_promises5.default.rm(import_node_path34.default.join(dir, WORKFLOW_PATH), { force: true });
|
|
59780
59728
|
let created;
|
|
59781
59729
|
try {
|
|
59782
59730
|
created = await createOrgRepo(exec, api, { dir, org, repoName: personaId2, message: "clawd: \u4E0A\u4E91", auth: args.auth });
|
|
@@ -60169,13 +60117,12 @@ function buildDeployHandlers(deps) {
|
|
|
60169
60117
|
if (!reported) return out;
|
|
60170
60118
|
if (!pkg.version) throw invalid(`\u9489\u8D44\u4EA7\u8981\u5148\u8BF4\u6E05\u662F\u54EA\u4E2A\u7248\u672C\u7684\uFF1A\`${pkg.name}\` \u5E26 artifact \u7684\u4E0A\u62A5\u5FC5\u987B\u540C\u65F6\u5E26 version`);
|
|
60171
60119
|
if (pkg.version !== version2) throw invalid(`\u672C\u673A\u88C5\u7684 \`${pkg.name}\` \u662F ${version2}\uFF0C\u4F60\u6309 ${pkg.version} \u627E\u7684\u8D44\u4EA7\uFF1B\u6309 ${version2} \u91CD\u627E`);
|
|
60172
|
-
let verified;
|
|
60173
60120
|
try {
|
|
60174
|
-
|
|
60121
|
+
artifactKind(reported.url, reported.bin);
|
|
60175
60122
|
} catch (err) {
|
|
60176
|
-
throw invalid(`\`${pkg.name}\` \u7684\u8D44\u4EA7\
|
|
60123
|
+
throw invalid(`\`${pkg.name}\` \u7684\u8D44\u4EA7\u4E0D\u5408\u5F62\u72B6\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
60177
60124
|
}
|
|
60178
|
-
return { ...out, artifact:
|
|
60125
|
+
return { ...out, artifact: reported };
|
|
60179
60126
|
}
|
|
60180
60127
|
const reportFinding = async (frame, _client, ctx) => {
|
|
60181
60128
|
ensureOwner(ctx);
|
|
@@ -60388,18 +60335,18 @@ async function probeLocalVersion(exec, pkg) {
|
|
|
60388
60335
|
|
|
60389
60336
|
// src/tools/shell-path.ts
|
|
60390
60337
|
var import_node_child_process10 = require("child_process");
|
|
60391
|
-
var
|
|
60338
|
+
var import_node_os10 = __toESM(require("os"), 1);
|
|
60392
60339
|
function refreshPathFromLoginShell() {
|
|
60393
60340
|
if (process.platform === "win32") return;
|
|
60394
|
-
const shell = process.env.SHELL ??
|
|
60341
|
+
const shell = process.env.SHELL ?? import_node_os10.default.userInfo().shell ?? "/bin/zsh";
|
|
60395
60342
|
try {
|
|
60396
60343
|
const out = (0, import_node_child_process10.execFileSync)(shell, ["-ilc", 'command echo -n "$PATH"'], {
|
|
60397
60344
|
encoding: "utf8",
|
|
60398
60345
|
timeout: 3e3,
|
|
60399
60346
|
stdio: ["ignore", "pipe", "ignore"]
|
|
60400
60347
|
});
|
|
60401
|
-
const
|
|
60402
|
-
if (
|
|
60348
|
+
const path100 = out.trim();
|
|
60349
|
+
if (path100) process.env.PATH = path100;
|
|
60403
60350
|
} catch {
|
|
60404
60351
|
}
|
|
60405
60352
|
}
|
|
@@ -60937,15 +60884,15 @@ async function refreshTunnelUrlOnStartup(deps) {
|
|
|
60937
60884
|
}
|
|
60938
60885
|
|
|
60939
60886
|
// src/lark-bot-connector/binding-store.ts
|
|
60940
|
-
var
|
|
60941
|
-
var
|
|
60887
|
+
var import_node_fs30 = __toESM(require("fs"), 1);
|
|
60888
|
+
var import_node_path35 = __toESM(require("path"), 1);
|
|
60942
60889
|
function createLarkBotBindingStore(personaRoot) {
|
|
60943
|
-
const filePath = (personaId2) =>
|
|
60890
|
+
const filePath = (personaId2) => import_node_path35.default.join(personaRoot, safeFileName(personaId2), ".clawd", "lark-bot.json");
|
|
60944
60891
|
const read = (personaId2) => {
|
|
60945
60892
|
const file = filePath(personaId2);
|
|
60946
|
-
if (!
|
|
60893
|
+
if (!import_node_fs30.default.existsSync(file)) return null;
|
|
60947
60894
|
try {
|
|
60948
|
-
const raw = JSON.parse(
|
|
60895
|
+
const raw = JSON.parse(import_node_fs30.default.readFileSync(file, "utf8"));
|
|
60949
60896
|
if (typeof raw?.appId !== "string" || raw.appId.length === 0) return null;
|
|
60950
60897
|
return raw;
|
|
60951
60898
|
} catch {
|
|
@@ -60954,16 +60901,16 @@ function createLarkBotBindingStore(personaRoot) {
|
|
|
60954
60901
|
};
|
|
60955
60902
|
const write = (personaId2, meta) => {
|
|
60956
60903
|
const file = filePath(personaId2);
|
|
60957
|
-
|
|
60904
|
+
import_node_fs30.default.mkdirSync(import_node_path35.default.dirname(file), { recursive: true });
|
|
60958
60905
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
60959
|
-
|
|
60960
|
-
|
|
60906
|
+
import_node_fs30.default.writeFileSync(tmp, JSON.stringify(meta, null, 2), { mode: 384 });
|
|
60907
|
+
import_node_fs30.default.renameSync(tmp, file);
|
|
60961
60908
|
};
|
|
60962
60909
|
return {
|
|
60963
60910
|
read,
|
|
60964
60911
|
write,
|
|
60965
60912
|
remove(personaId2) {
|
|
60966
|
-
|
|
60913
|
+
import_node_fs30.default.rmSync(filePath(personaId2), { force: true });
|
|
60967
60914
|
},
|
|
60968
60915
|
addRemovedChat(personaId2, chatId) {
|
|
60969
60916
|
const meta = read(personaId2);
|
|
@@ -61115,8 +61062,8 @@ function createLarkBotCloudClient(opts) {
|
|
|
61115
61062
|
}
|
|
61116
61063
|
|
|
61117
61064
|
// src/lark-bot-connector/chat-router.ts
|
|
61118
|
-
var
|
|
61119
|
-
var
|
|
61065
|
+
var import_node_fs31 = __toESM(require("fs"), 1);
|
|
61066
|
+
var import_node_path36 = __toESM(require("path"), 1);
|
|
61120
61067
|
init_protocol();
|
|
61121
61068
|
var ERROR_REPLY_TEXT = "\u5904\u7406\u51FA\u9519\u4E86\uFF0C\u8BF7\u91CD\u8BD5";
|
|
61122
61069
|
var LOCAL_TURN_RETRIES = 2;
|
|
@@ -61194,9 +61141,9 @@ function createLarkChatRouter(deps) {
|
|
|
61194
61141
|
continue;
|
|
61195
61142
|
}
|
|
61196
61143
|
const dir = deps.mediaRootFor(env.chatId);
|
|
61197
|
-
|
|
61198
|
-
const p3 =
|
|
61199
|
-
|
|
61144
|
+
import_node_fs31.default.mkdirSync(dir, { recursive: true });
|
|
61145
|
+
const p3 = import_node_path36.default.join(dir, `${safeMediaName(ownerMessageId)}-${i2}.${ext}`);
|
|
61146
|
+
import_node_fs31.default.writeFileSync(p3, r2.data);
|
|
61200
61147
|
lines.push(`[\u56FE\u7247: ${p3}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
|
|
61201
61148
|
} catch (err) {
|
|
61202
61149
|
deps.logger?.warn(`larkBot image fetch failed ${key}: ${err.message}`);
|
|
@@ -61217,9 +61164,9 @@ function createLarkChatRouter(deps) {
|
|
|
61217
61164
|
continue;
|
|
61218
61165
|
}
|
|
61219
61166
|
const dir = deps.mediaRootFor(env.chatId);
|
|
61220
|
-
|
|
61221
|
-
const p3 =
|
|
61222
|
-
|
|
61167
|
+
import_node_fs31.default.mkdirSync(dir, { recursive: true });
|
|
61168
|
+
const p3 = import_node_path36.default.join(dir, `${safeMediaName(ownerMessageId)}-${i2}-${safeAttachmentName(f2.name)}`);
|
|
61169
|
+
import_node_fs31.default.writeFileSync(p3, r2.data);
|
|
61223
61170
|
lines.push(`[\u6587\u4EF6: ${p3}]\uFF08\u7528 Read \u5DE5\u5177\u67E5\u770B\uFF09`);
|
|
61224
61171
|
} catch (err) {
|
|
61225
61172
|
deps.logger?.warn(`larkBot file fetch failed ${f2.key}: ${err.message}`);
|
|
@@ -61433,7 +61380,7 @@ ${formatLarkSpeakerReminder(speaker)}`
|
|
|
61433
61380
|
}
|
|
61434
61381
|
|
|
61435
61382
|
// src/lark-bot-connector/envelope.ts
|
|
61436
|
-
var
|
|
61383
|
+
var import_node_crypto9 = require("crypto");
|
|
61437
61384
|
var LARK_ENVELOPE_PREFIX = "clawdlbe1";
|
|
61438
61385
|
function verifyLarkEventEnvelope(args) {
|
|
61439
61386
|
const { token, publicKeyPem } = args;
|
|
@@ -61452,7 +61399,7 @@ function verifyLarkEventEnvelope(args) {
|
|
|
61452
61399
|
const data = Buffer.from(`${prefix}.${payloadB64}`, "utf8");
|
|
61453
61400
|
let sigOk = false;
|
|
61454
61401
|
try {
|
|
61455
|
-
sigOk = (0,
|
|
61402
|
+
sigOk = (0, import_node_crypto9.verify)(null, data, publicKeyPem, Buffer.from(sigB64, "base64url"));
|
|
61456
61403
|
} catch {
|
|
61457
61404
|
sigOk = false;
|
|
61458
61405
|
}
|
|
@@ -62043,12 +61990,12 @@ async function forwardPeerExecToPeer(args) {
|
|
|
62043
61990
|
}
|
|
62044
61991
|
|
|
62045
61992
|
// src/tools/codex-history.ts
|
|
62046
|
-
var import_node_fs34 = __toESM(require("fs"), 1);
|
|
62047
|
-
var import_node_path39 = __toESM(require("path"), 1);
|
|
62048
|
-
|
|
62049
|
-
// src/tools/transcript-search.ts
|
|
62050
61993
|
var import_node_fs33 = __toESM(require("fs"), 1);
|
|
62051
61994
|
var import_node_path38 = __toESM(require("path"), 1);
|
|
61995
|
+
|
|
61996
|
+
// src/tools/transcript-search.ts
|
|
61997
|
+
var import_node_fs32 = __toESM(require("fs"), 1);
|
|
61998
|
+
var import_node_path37 = __toESM(require("path"), 1);
|
|
62052
61999
|
var SNIPPET_PAD = 60;
|
|
62053
62000
|
var INJECTED_ENVELOPE_RE = /^<(system-reminder|command-name|command-message|command-args|local-command-stdout|local-command-stderr|task-notification|user-prompt-submit-hook|environment_context|user_instructions)\b/;
|
|
62054
62001
|
var CODEX_WRAPPER_RE = /<(related-dir|environment_context|user_instructions)>[\s\S]*?<\/\1>/g;
|
|
@@ -62103,7 +62050,7 @@ function makeSnippet(text, at3, needleLength) {
|
|
|
62103
62050
|
function searchTranscriptFile(file, query) {
|
|
62104
62051
|
let buf;
|
|
62105
62052
|
try {
|
|
62106
|
-
buf =
|
|
62053
|
+
buf = import_node_fs32.default.readFileSync(file);
|
|
62107
62054
|
} catch {
|
|
62108
62055
|
return null;
|
|
62109
62056
|
}
|
|
@@ -62136,12 +62083,12 @@ function createCodexRolloutLocator(roots) {
|
|
|
62136
62083
|
const walk2 = (dir, into) => {
|
|
62137
62084
|
let entries;
|
|
62138
62085
|
try {
|
|
62139
|
-
entries =
|
|
62086
|
+
entries = import_node_fs32.default.readdirSync(dir, { withFileTypes: true });
|
|
62140
62087
|
} catch {
|
|
62141
62088
|
return;
|
|
62142
62089
|
}
|
|
62143
62090
|
for (const entry of entries) {
|
|
62144
|
-
const full =
|
|
62091
|
+
const full = import_node_path37.default.join(dir, entry.name);
|
|
62145
62092
|
if (entry.isDirectory()) {
|
|
62146
62093
|
walk2(full, into);
|
|
62147
62094
|
continue;
|
|
@@ -62363,18 +62310,18 @@ var TITLE_BYTES = 256 * 1024;
|
|
|
62363
62310
|
function readHead(file, bytes) {
|
|
62364
62311
|
let fd;
|
|
62365
62312
|
try {
|
|
62366
|
-
fd =
|
|
62313
|
+
fd = import_node_fs33.default.openSync(file, "r");
|
|
62367
62314
|
} catch {
|
|
62368
62315
|
return null;
|
|
62369
62316
|
}
|
|
62370
62317
|
try {
|
|
62371
62318
|
const buf = Buffer.alloc(bytes);
|
|
62372
|
-
const n2 =
|
|
62319
|
+
const n2 = import_node_fs33.default.readSync(fd, buf, 0, bytes, 0);
|
|
62373
62320
|
return buf.subarray(0, n2).toString("utf8");
|
|
62374
62321
|
} catch {
|
|
62375
62322
|
return null;
|
|
62376
62323
|
} finally {
|
|
62377
|
-
|
|
62324
|
+
import_node_fs33.default.closeSync(fd);
|
|
62378
62325
|
}
|
|
62379
62326
|
}
|
|
62380
62327
|
function peekSessionCwd(head) {
|
|
@@ -62390,7 +62337,7 @@ function peekSessionCwd(head) {
|
|
|
62390
62337
|
function readFirstLine(file, max = 512 * 1024) {
|
|
62391
62338
|
let fd;
|
|
62392
62339
|
try {
|
|
62393
|
-
fd =
|
|
62340
|
+
fd = import_node_fs33.default.openSync(file, "r");
|
|
62394
62341
|
} catch {
|
|
62395
62342
|
return null;
|
|
62396
62343
|
}
|
|
@@ -62399,7 +62346,7 @@ function readFirstLine(file, max = 512 * 1024) {
|
|
|
62399
62346
|
const parts = [];
|
|
62400
62347
|
let total = 0;
|
|
62401
62348
|
while (total < max) {
|
|
62402
|
-
const n2 =
|
|
62349
|
+
const n2 = import_node_fs33.default.readSync(fd, chunk, 0, chunk.length, total);
|
|
62403
62350
|
if (n2 <= 0) break;
|
|
62404
62351
|
const nl = chunk.subarray(0, n2).indexOf(10);
|
|
62405
62352
|
if (nl >= 0) {
|
|
@@ -62413,7 +62360,7 @@ function readFirstLine(file, max = 512 * 1024) {
|
|
|
62413
62360
|
} catch {
|
|
62414
62361
|
return null;
|
|
62415
62362
|
} finally {
|
|
62416
|
-
|
|
62363
|
+
import_node_fs33.default.closeSync(fd);
|
|
62417
62364
|
}
|
|
62418
62365
|
}
|
|
62419
62366
|
function readThreadNames(sharedHome) {
|
|
@@ -62421,7 +62368,7 @@ function readThreadNames(sharedHome) {
|
|
|
62421
62368
|
if (!sharedHome) return names;
|
|
62422
62369
|
let raw;
|
|
62423
62370
|
try {
|
|
62424
|
-
raw =
|
|
62371
|
+
raw = import_node_fs33.default.readFileSync(import_node_path38.default.join(sharedHome, "session_index.jsonl"), "utf8");
|
|
62425
62372
|
} catch {
|
|
62426
62373
|
return names;
|
|
62427
62374
|
}
|
|
@@ -62440,13 +62387,13 @@ function readThreadNames(sharedHome) {
|
|
|
62440
62387
|
function walkRollouts(dir, visit) {
|
|
62441
62388
|
let entries;
|
|
62442
62389
|
try {
|
|
62443
|
-
entries =
|
|
62390
|
+
entries = import_node_fs33.default.readdirSync(dir, { withFileTypes: true });
|
|
62444
62391
|
} catch {
|
|
62445
62392
|
return true;
|
|
62446
62393
|
}
|
|
62447
62394
|
entries.sort((a2, b3) => a2.name < b3.name ? 1 : a2.name > b3.name ? -1 : 0);
|
|
62448
62395
|
for (const entry of entries) {
|
|
62449
|
-
const full =
|
|
62396
|
+
const full = import_node_path38.default.join(dir, entry.name);
|
|
62450
62397
|
if (entry.isDirectory()) {
|
|
62451
62398
|
if (!walkRollouts(full, visit)) return false;
|
|
62452
62399
|
} else if (ROLLOUT_NAME_RE.test(entry.name)) {
|
|
@@ -62514,7 +62461,7 @@ var CodexHistoryReader = class {
|
|
|
62514
62461
|
return [];
|
|
62515
62462
|
}
|
|
62516
62463
|
async listSessions(args) {
|
|
62517
|
-
const want =
|
|
62464
|
+
const want = import_node_path38.default.resolve(args.projectPath);
|
|
62518
62465
|
const names = readThreadNames(this.deps.sharedHome);
|
|
62519
62466
|
const found = [];
|
|
62520
62467
|
let scanned = 0;
|
|
@@ -62523,13 +62470,13 @@ var CodexHistoryReader = class {
|
|
|
62523
62470
|
if (++scanned > CODEX_LIST_SESSIONS_SCAN_CAP) return false;
|
|
62524
62471
|
const head = readHead(file, PEEK_BYTES);
|
|
62525
62472
|
const cwd = head === null ? null : peekSessionCwd(head);
|
|
62526
|
-
if (!cwd ||
|
|
62473
|
+
if (!cwd || import_node_path38.default.resolve(cwd) !== want) return;
|
|
62527
62474
|
const first = readFirstLine(file);
|
|
62528
62475
|
const meta = first === null ? null : parseCodexRolloutMeta(first);
|
|
62529
62476
|
if (!meta) return;
|
|
62530
62477
|
let mtimeMs;
|
|
62531
62478
|
try {
|
|
62532
|
-
mtimeMs =
|
|
62479
|
+
mtimeMs = import_node_fs33.default.statSync(file).mtimeMs;
|
|
62533
62480
|
} catch {
|
|
62534
62481
|
return;
|
|
62535
62482
|
}
|
|
@@ -62561,7 +62508,7 @@ var CodexHistoryReader = class {
|
|
|
62561
62508
|
args.toolSessionId,
|
|
62562
62509
|
async (agentId) => {
|
|
62563
62510
|
const file = locate(agentId);
|
|
62564
|
-
return file ?
|
|
62511
|
+
return file ? import_node_fs33.default.readFileSync(file, "utf8") : null;
|
|
62565
62512
|
},
|
|
62566
62513
|
this.deps.logger
|
|
62567
62514
|
);
|
|
@@ -62588,7 +62535,7 @@ var CodexHistoryReader = class {
|
|
|
62588
62535
|
parseThread(locate, threadId) {
|
|
62589
62536
|
const file = locate(threadId);
|
|
62590
62537
|
if (!file) throw new Error(`Codex rollout not found for thread ${threadId}`);
|
|
62591
|
-
return parseCodexRollout(
|
|
62538
|
+
return parseCodexRollout(import_node_fs33.default.readFileSync(file, "utf8"));
|
|
62592
62539
|
}
|
|
62593
62540
|
};
|
|
62594
62541
|
|
|
@@ -62607,9 +62554,9 @@ var CentralClientError = class extends Error {
|
|
|
62607
62554
|
code;
|
|
62608
62555
|
cause;
|
|
62609
62556
|
};
|
|
62610
|
-
async function centralRequest(opts,
|
|
62557
|
+
async function centralRequest(opts, path100, init) {
|
|
62611
62558
|
const f2 = opts.fetchImpl ?? globalThis.fetch;
|
|
62612
|
-
const url = `${opts.api.replace(/\/+$/, "")}${
|
|
62559
|
+
const url = `${opts.api.replace(/\/+$/, "")}${path100}`;
|
|
62613
62560
|
const ctrl = new AbortController();
|
|
62614
62561
|
const timer = setTimeout(() => ctrl.abort(), opts.timeoutMs ?? 15e3);
|
|
62615
62562
|
let res;
|
|
@@ -63143,7 +63090,7 @@ function openHttpLineStream(opts) {
|
|
|
63143
63090
|
init_protocol();
|
|
63144
63091
|
|
|
63145
63092
|
// src/tools/codex-cloud-session.ts
|
|
63146
|
-
var
|
|
63093
|
+
var import_node_fs34 = __toESM(require("fs"), 1);
|
|
63147
63094
|
|
|
63148
63095
|
// src/tools/codex-cloud-history.ts
|
|
63149
63096
|
function personaIdFromCloudCwd(cwd) {
|
|
@@ -63261,7 +63208,7 @@ function cloudImageInput(deps) {
|
|
|
63261
63208
|
const mime = lookupMime(p3);
|
|
63262
63209
|
if (!mime.startsWith("image/")) return null;
|
|
63263
63210
|
try {
|
|
63264
|
-
const bytes = (deps.readFile ??
|
|
63211
|
+
const bytes = (deps.readFile ?? import_node_fs34.default.readFileSync)(p3);
|
|
63265
63212
|
return { type: "image", url: `data:${mime};base64,${bytes.toString("base64")}` };
|
|
63266
63213
|
} catch (e) {
|
|
63267
63214
|
deps.logger?.warn("cloud image attachment unreadable", { path: p3, message: e.message });
|
|
@@ -63391,7 +63338,7 @@ init_protocol();
|
|
|
63391
63338
|
|
|
63392
63339
|
// src/tools/pi.ts
|
|
63393
63340
|
var import_node_child_process12 = require("child_process");
|
|
63394
|
-
var
|
|
63341
|
+
var import_node_fs37 = __toESM(require("fs"), 1);
|
|
63395
63342
|
init_protocol();
|
|
63396
63343
|
|
|
63397
63344
|
// src/tools/pi-rpc-client.ts
|
|
@@ -63491,9 +63438,9 @@ var PiRpcClient = class {
|
|
|
63491
63438
|
|
|
63492
63439
|
// src/tools/pi-session.ts
|
|
63493
63440
|
var import_node_child_process11 = require("child_process");
|
|
63494
|
-
var
|
|
63495
|
-
var
|
|
63496
|
-
var
|
|
63441
|
+
var import_node_crypto10 = require("crypto");
|
|
63442
|
+
var import_node_fs35 = __toESM(require("fs"), 1);
|
|
63443
|
+
var import_node_path39 = __toESM(require("path"), 1);
|
|
63497
63444
|
|
|
63498
63445
|
// src/tools/pi-events.ts
|
|
63499
63446
|
init_protocol();
|
|
@@ -63760,9 +63707,9 @@ ${dirs.map((d2) => `- ${d2}`).join("\n")}`;
|
|
|
63760
63707
|
}
|
|
63761
63708
|
function createPiSession(ctx, sink, deps = {}) {
|
|
63762
63709
|
const cmd = process.env.PI_BIN ?? "pi";
|
|
63763
|
-
const sessionId = ctx.toolSessionId ?? (0,
|
|
63764
|
-
const skillsDir =
|
|
63765
|
-
const exists = deps.skillsDirExists ?? ((d2) =>
|
|
63710
|
+
const sessionId = ctx.toolSessionId ?? (0, import_node_crypto10.randomUUID)();
|
|
63711
|
+
const skillsDir = import_node_path39.default.join(ctx.cwd, ".claude", "skills");
|
|
63712
|
+
const exists = deps.skillsDirExists ?? ((d2) => import_node_fs35.default.existsSync(d2));
|
|
63766
63713
|
const args = buildPiArgs(ctx, {
|
|
63767
63714
|
sessionId,
|
|
63768
63715
|
skillsDir: exists(skillsDir) ? skillsDir : void 0,
|
|
@@ -63806,45 +63753,45 @@ function createPiSession(ctx, sink, deps = {}) {
|
|
|
63806
63753
|
}
|
|
63807
63754
|
|
|
63808
63755
|
// src/tools/pi-history.ts
|
|
63809
|
-
var
|
|
63810
|
-
var
|
|
63811
|
-
var
|
|
63756
|
+
var import_node_fs36 = __toESM(require("fs"), 1);
|
|
63757
|
+
var import_node_os11 = __toESM(require("os"), 1);
|
|
63758
|
+
var import_node_path40 = __toESM(require("path"), 1);
|
|
63812
63759
|
var PI_LIST_SESSIONS_LIMIT = 100;
|
|
63813
63760
|
var PI_LIST_SESSIONS_SCAN_CAP = 4e3;
|
|
63814
63761
|
function piAgentDir(env = process.env) {
|
|
63815
|
-
return env.PI_CODING_AGENT_DIR ||
|
|
63762
|
+
return env.PI_CODING_AGENT_DIR || import_node_path40.default.join(import_node_os11.default.homedir(), ".pi", "agent");
|
|
63816
63763
|
}
|
|
63817
63764
|
function piSessionsRoot(env = process.env) {
|
|
63818
|
-
return
|
|
63765
|
+
return import_node_path40.default.join(piAgentDir(env), "sessions");
|
|
63819
63766
|
}
|
|
63820
63767
|
function encodePiCwd(cwd) {
|
|
63821
63768
|
return `--${cwd.replace(/^[\\/]+/, "").replace(/[\\/:]/g, "-")}--`;
|
|
63822
63769
|
}
|
|
63823
63770
|
function piProjectSessionDir(sessionsRoot, cwd) {
|
|
63824
|
-
return
|
|
63771
|
+
return import_node_path40.default.join(sessionsRoot, encodePiCwd(cwd));
|
|
63825
63772
|
}
|
|
63826
63773
|
function findInDir(dir, toolSessionId) {
|
|
63827
63774
|
let names;
|
|
63828
63775
|
try {
|
|
63829
|
-
names =
|
|
63776
|
+
names = import_node_fs36.default.readdirSync(dir);
|
|
63830
63777
|
} catch {
|
|
63831
63778
|
return null;
|
|
63832
63779
|
}
|
|
63833
63780
|
const suffix = `_${toolSessionId}.jsonl`;
|
|
63834
63781
|
const hit = names.filter((n2) => n2.endsWith(suffix)).sort().at(-1);
|
|
63835
|
-
return hit ?
|
|
63782
|
+
return hit ? import_node_path40.default.join(dir, hit) : null;
|
|
63836
63783
|
}
|
|
63837
63784
|
function locatePiSessionFile(sessionsRoot, cwd, toolSessionId) {
|
|
63838
63785
|
const direct = findInDir(piProjectSessionDir(sessionsRoot, cwd), toolSessionId);
|
|
63839
63786
|
if (direct) return direct;
|
|
63840
63787
|
let dirs;
|
|
63841
63788
|
try {
|
|
63842
|
-
dirs =
|
|
63789
|
+
dirs = import_node_fs36.default.readdirSync(sessionsRoot, { withFileTypes: true }).filter((d2) => d2.isDirectory()).map((d2) => d2.name);
|
|
63843
63790
|
} catch {
|
|
63844
63791
|
return null;
|
|
63845
63792
|
}
|
|
63846
63793
|
for (const d2 of dirs) {
|
|
63847
|
-
const hit = findInDir(
|
|
63794
|
+
const hit = findInDir(import_node_path40.default.join(sessionsRoot, d2), toolSessionId);
|
|
63848
63795
|
if (hit) return hit;
|
|
63849
63796
|
}
|
|
63850
63797
|
return null;
|
|
@@ -63943,11 +63890,11 @@ var PiHistoryReader = class {
|
|
|
63943
63890
|
return [];
|
|
63944
63891
|
}
|
|
63945
63892
|
async listSessions(args) {
|
|
63946
|
-
const want =
|
|
63893
|
+
const want = import_node_path40.default.resolve(args.projectPath);
|
|
63947
63894
|
const dir = piProjectSessionDir(this.deps.sessionsRoot, want);
|
|
63948
63895
|
let names;
|
|
63949
63896
|
try {
|
|
63950
|
-
names =
|
|
63897
|
+
names = import_node_fs36.default.readdirSync(dir).filter((n2) => n2.endsWith(".jsonl"));
|
|
63951
63898
|
} catch {
|
|
63952
63899
|
return [];
|
|
63953
63900
|
}
|
|
@@ -63955,15 +63902,15 @@ var PiHistoryReader = class {
|
|
|
63955
63902
|
let scanned = 0;
|
|
63956
63903
|
for (const n2 of names) {
|
|
63957
63904
|
if (++scanned > PI_LIST_SESSIONS_SCAN_CAP) break;
|
|
63958
|
-
const file =
|
|
63905
|
+
const file = import_node_path40.default.join(dir, n2);
|
|
63959
63906
|
const head = parseLine2(readFirstLine(file) ?? "");
|
|
63960
63907
|
if (!head || head.type !== "session") continue;
|
|
63961
63908
|
const cwd = str3(head.cwd);
|
|
63962
63909
|
const id = str3(head.id);
|
|
63963
|
-
if (!cwd || !id ||
|
|
63910
|
+
if (!cwd || !id || import_node_path40.default.resolve(cwd) !== want) continue;
|
|
63964
63911
|
let mtimeMs;
|
|
63965
63912
|
try {
|
|
63966
|
-
mtimeMs =
|
|
63913
|
+
mtimeMs = import_node_fs36.default.statSync(file).mtimeMs;
|
|
63967
63914
|
} catch {
|
|
63968
63915
|
continue;
|
|
63969
63916
|
}
|
|
@@ -63971,7 +63918,7 @@ var PiHistoryReader = class {
|
|
|
63971
63918
|
}
|
|
63972
63919
|
found.sort((a2, b3) => b3.mtimeMs - a2.mtimeMs);
|
|
63973
63920
|
return found.slice(0, PI_LIST_SESSIONS_LIMIT).map((f2) => {
|
|
63974
|
-
const parsed = parsePiSession(
|
|
63921
|
+
const parsed = parsePiSession(import_node_fs36.default.readFileSync(f2.file, "utf8"));
|
|
63975
63922
|
const firstUser = parsed.messages.find((m3) => m3.kind === "user-text");
|
|
63976
63923
|
return {
|
|
63977
63924
|
toolSessionId: f2.id,
|
|
@@ -63984,7 +63931,7 @@ var PiHistoryReader = class {
|
|
|
63984
63931
|
async read(args) {
|
|
63985
63932
|
const file = locatePiSessionFile(this.deps.sessionsRoot, args.cwd, args.toolSessionId);
|
|
63986
63933
|
if (!file) throw new Error(`pi session not found for ${args.toolSessionId}`);
|
|
63987
|
-
return pageMessages(parsePiSession(
|
|
63934
|
+
return pageMessages(parsePiSession(import_node_fs36.default.readFileSync(file, "utf8")).messages, args);
|
|
63988
63935
|
}
|
|
63989
63936
|
async listSubagents(_args) {
|
|
63990
63937
|
return [];
|
|
@@ -64019,10 +63966,10 @@ var PI_DEFAULT_MODEL_ENTRY = {
|
|
|
64019
63966
|
};
|
|
64020
63967
|
var PI_FULL_ACCESS = { id: "never", label: "Full Access", description: "pi \u65E0\u5BA1\u6279\uFF1A\u4ECE\u4E0D\u8BE2\u95EE\uFF0C\u81EA\u4E3B\u6267\u884C" };
|
|
64021
63968
|
async function probePi(env = process.env) {
|
|
64022
|
-
if (env.PI_BIN &&
|
|
63969
|
+
if (env.PI_BIN && import_node_fs37.default.existsSync(env.PI_BIN)) return { available: true, path: env.PI_BIN };
|
|
64023
63970
|
try {
|
|
64024
63971
|
const out = (0, import_node_child_process12.execFileSync)("which", ["pi"], { encoding: "utf8" }).trim();
|
|
64025
|
-
if (out &&
|
|
63972
|
+
if (out && import_node_fs37.default.existsSync(out)) return { available: true, path: out };
|
|
64026
63973
|
} catch {
|
|
64027
63974
|
}
|
|
64028
63975
|
return { available: false };
|
|
@@ -64192,13 +64139,13 @@ var PiAdapter = class {
|
|
|
64192
64139
|
};
|
|
64193
64140
|
|
|
64194
64141
|
// src/tools/pi-cloud-session.ts
|
|
64195
|
-
var
|
|
64142
|
+
var import_node_crypto11 = require("crypto");
|
|
64196
64143
|
function cloudPiInstructions(ctx) {
|
|
64197
64144
|
return [ctx.extraSystemPrompt, workDirPrompt(CLOUD_WORKSPACE_SLOT, ctx.personaMode ?? "owner")].filter((x2) => Boolean(x2)).join("\n\n");
|
|
64198
64145
|
}
|
|
64199
64146
|
function createCloudPiSession(ctx, sink, deps) {
|
|
64200
64147
|
const personaId2 = personaIdFromCloudCwd(ctx.cwd);
|
|
64201
|
-
const sessionId = ctx.toolSessionId ?? (0,
|
|
64148
|
+
const sessionId = ctx.toolSessionId ?? (0, import_node_crypto11.randomUUID)();
|
|
64202
64149
|
const stream = deferredLineStream();
|
|
64203
64150
|
let channel = null;
|
|
64204
64151
|
const driver = drivePiSession({
|
|
@@ -64341,7 +64288,7 @@ var CloudPiAdapter = class {
|
|
|
64341
64288
|
init_protocol();
|
|
64342
64289
|
|
|
64343
64290
|
// src/tools/codex-skills.ts
|
|
64344
|
-
var
|
|
64291
|
+
var import_node_path41 = __toESM(require("path"), 1);
|
|
64345
64292
|
function str4(v3) {
|
|
64346
64293
|
return typeof v3 === "string" ? v3 : void 0;
|
|
64347
64294
|
}
|
|
@@ -64356,13 +64303,13 @@ function mapSkillsListResponse(res) {
|
|
|
64356
64303
|
const r2 = s2 ?? {};
|
|
64357
64304
|
const name = str4(r2.name);
|
|
64358
64305
|
if (!name) continue;
|
|
64359
|
-
const
|
|
64306
|
+
const path100 = str4(r2.path);
|
|
64360
64307
|
const description = str4(r2.description);
|
|
64361
64308
|
const isPlugin = name.includes(":");
|
|
64362
64309
|
out.push({
|
|
64363
64310
|
name,
|
|
64364
64311
|
source: isPlugin ? "plugin" : "project",
|
|
64365
|
-
...
|
|
64312
|
+
...path100 ? { path: path100 } : {},
|
|
64366
64313
|
...description ? { description } : {},
|
|
64367
64314
|
...isPlugin ? { plugin: name.split(":")[0] } : {}
|
|
64368
64315
|
});
|
|
@@ -64378,14 +64325,14 @@ async function listCodexSkills(cwd, deps = {}) {
|
|
|
64378
64325
|
// 先写 extraRoots 再写 list(stdio 按写入顺序处理,fire-and-forget 不 await 回包;
|
|
64379
64326
|
// codex-session.ts ready 序列同款,两处保持一致)。失败不阻塞 list。
|
|
64380
64327
|
beforeRequest: (client) => {
|
|
64381
|
-
void client.request("skills/extraRoots/set", { extraRoots: [
|
|
64328
|
+
void client.request("skills/extraRoots/set", { extraRoots: [import_node_path41.default.join(cwd, ".claude", "skills")] }).catch(() => void 0);
|
|
64382
64329
|
}
|
|
64383
64330
|
});
|
|
64384
64331
|
return mapSkillsListResponse(res);
|
|
64385
64332
|
}
|
|
64386
64333
|
|
|
64387
64334
|
// src/tools/codex-turn-context.ts
|
|
64388
|
-
var
|
|
64335
|
+
var import_promises6 = __toESM(require("fs/promises"), 1);
|
|
64389
64336
|
function parseTurnContextFromRollout(raw) {
|
|
64390
64337
|
const lines = raw.split("\n");
|
|
64391
64338
|
for (let i2 = lines.length - 1; i2 >= 0; i2--) {
|
|
@@ -64412,7 +64359,7 @@ function parseTurnContextFromRollout(raw) {
|
|
|
64412
64359
|
async function readCodexTurnContext(args, deps) {
|
|
64413
64360
|
const rolloutPath = createCodexRolloutLocator(deps.roots)(args.threadId);
|
|
64414
64361
|
if (!rolloutPath) return null;
|
|
64415
|
-
return parseTurnContextFromRollout(await
|
|
64362
|
+
return parseTurnContextFromRollout(await import_promises6.default.readFile(rolloutPath, "utf8"));
|
|
64416
64363
|
}
|
|
64417
64364
|
function createCodexResolvedMetaHydrator(deps) {
|
|
64418
64365
|
const fetchedThreadIds = /* @__PURE__ */ new Set();
|
|
@@ -64452,23 +64399,23 @@ function rec4(v3) {
|
|
|
64452
64399
|
}
|
|
64453
64400
|
|
|
64454
64401
|
// src/workspace/browser.ts
|
|
64455
|
-
var
|
|
64456
|
-
var
|
|
64457
|
-
var
|
|
64402
|
+
var import_node_fs38 = __toESM(require("fs"), 1);
|
|
64403
|
+
var import_node_os12 = __toESM(require("os"), 1);
|
|
64404
|
+
var import_node_path42 = __toESM(require("path"), 1);
|
|
64458
64405
|
init_protocol();
|
|
64459
64406
|
var MAX_FILE_BYTES2 = 2 * 1024 * 1024;
|
|
64460
64407
|
function resolveInsideCwd(cwd, subpath) {
|
|
64461
|
-
const absCwd =
|
|
64462
|
-
const joined =
|
|
64463
|
-
const rel =
|
|
64464
|
-
if (rel.startsWith("..") ||
|
|
64408
|
+
const absCwd = import_node_path42.default.resolve(cwd);
|
|
64409
|
+
const joined = import_node_path42.default.resolve(absCwd, subpath ?? ".");
|
|
64410
|
+
const rel = import_node_path42.default.relative(absCwd, joined);
|
|
64411
|
+
if (rel.startsWith("..") || import_node_path42.default.isAbsolute(rel)) {
|
|
64465
64412
|
throw new ClawdError(ERROR_CODES.INVALID_PATH, `path escapes cwd: ${subpath}`);
|
|
64466
64413
|
}
|
|
64467
64414
|
return joined;
|
|
64468
64415
|
}
|
|
64469
64416
|
function ensureCwd(cwd) {
|
|
64470
64417
|
try {
|
|
64471
|
-
const stat =
|
|
64418
|
+
const stat = import_node_fs38.default.statSync(cwd);
|
|
64472
64419
|
if (!stat.isDirectory()) {
|
|
64473
64420
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${cwd}`);
|
|
64474
64421
|
}
|
|
@@ -64479,10 +64426,10 @@ function ensureCwd(cwd) {
|
|
|
64479
64426
|
}
|
|
64480
64427
|
var WorkspaceBrowser = class {
|
|
64481
64428
|
list(args) {
|
|
64482
|
-
const cwd = args.cwd && args.cwd.length > 0 ? args.cwd :
|
|
64429
|
+
const cwd = args.cwd && args.cwd.length > 0 ? args.cwd : import_node_os12.default.homedir();
|
|
64483
64430
|
ensureCwd(cwd);
|
|
64484
64431
|
const full = resolveInsideCwd(cwd, args.path);
|
|
64485
|
-
const dirents =
|
|
64432
|
+
const dirents = import_node_fs38.default.readdirSync(full, { withFileTypes: true });
|
|
64486
64433
|
const entries = [];
|
|
64487
64434
|
for (const d2 of dirents) {
|
|
64488
64435
|
if (!args.showHidden && d2.name.startsWith(".")) continue;
|
|
@@ -64492,7 +64439,7 @@ var WorkspaceBrowser = class {
|
|
|
64492
64439
|
mtime: ""
|
|
64493
64440
|
};
|
|
64494
64441
|
try {
|
|
64495
|
-
const st2 =
|
|
64442
|
+
const st2 = import_node_fs38.default.statSync(import_node_path42.default.join(full, d2.name));
|
|
64496
64443
|
entry.mtime = new Date(st2.mtimeMs).toISOString();
|
|
64497
64444
|
if (d2.isFile()) entry.size = st2.size;
|
|
64498
64445
|
} catch {
|
|
@@ -64508,14 +64455,14 @@ var WorkspaceBrowser = class {
|
|
|
64508
64455
|
read(args) {
|
|
64509
64456
|
ensureCwd(args.cwd);
|
|
64510
64457
|
const full = resolveInsideCwd(args.cwd, args.path);
|
|
64511
|
-
const st2 =
|
|
64458
|
+
const st2 = import_node_fs38.default.statSync(full);
|
|
64512
64459
|
if (!st2.isFile()) {
|
|
64513
64460
|
throw new ClawdError(ERROR_CODES.INVALID_PATH, `not a file: ${args.path}`);
|
|
64514
64461
|
}
|
|
64515
64462
|
if (st2.size > MAX_FILE_BYTES2) {
|
|
64516
64463
|
throw new ClawdError(ERROR_CODES.FILE_TOO_LARGE, `file > ${MAX_FILE_BYTES2} bytes`);
|
|
64517
64464
|
}
|
|
64518
|
-
const buf =
|
|
64465
|
+
const buf = import_node_fs38.default.readFileSync(full);
|
|
64519
64466
|
const isBinary = buf.includes(0);
|
|
64520
64467
|
if (isBinary) {
|
|
64521
64468
|
return {
|
|
@@ -64537,20 +64484,20 @@ var WorkspaceBrowser = class {
|
|
|
64537
64484
|
};
|
|
64538
64485
|
|
|
64539
64486
|
// src/skills/agents-scanner.ts
|
|
64540
|
-
var
|
|
64541
|
-
var
|
|
64542
|
-
var
|
|
64487
|
+
var import_node_fs39 = __toESM(require("fs"), 1);
|
|
64488
|
+
var import_node_os13 = __toESM(require("os"), 1);
|
|
64489
|
+
var import_node_path43 = __toESM(require("path"), 1);
|
|
64543
64490
|
var DEFAULT_POLICY_DIR_DARWIN = "/Library/Application Support/ClaudeCode/.claude/agents";
|
|
64544
64491
|
function isDirLikeSync2(p3) {
|
|
64545
64492
|
try {
|
|
64546
|
-
return
|
|
64493
|
+
return import_node_fs39.default.statSync(p3).isDirectory();
|
|
64547
64494
|
} catch {
|
|
64548
64495
|
return false;
|
|
64549
64496
|
}
|
|
64550
64497
|
}
|
|
64551
64498
|
function fileExistsSync(p3) {
|
|
64552
64499
|
try {
|
|
64553
|
-
return
|
|
64500
|
+
return import_node_fs39.default.statSync(p3).isFile();
|
|
64554
64501
|
} catch {
|
|
64555
64502
|
return false;
|
|
64556
64503
|
}
|
|
@@ -64558,7 +64505,7 @@ function fileExistsSync(p3) {
|
|
|
64558
64505
|
function parseAgentFile(filePath) {
|
|
64559
64506
|
let content;
|
|
64560
64507
|
try {
|
|
64561
|
-
content =
|
|
64508
|
+
content = import_node_fs39.default.readFileSync(filePath, "utf8");
|
|
64562
64509
|
} catch {
|
|
64563
64510
|
return {};
|
|
64564
64511
|
}
|
|
@@ -64571,16 +64518,16 @@ function parseAgentFile(filePath) {
|
|
|
64571
64518
|
function scanAgentsDir(dir, source, seen, out) {
|
|
64572
64519
|
let entries;
|
|
64573
64520
|
try {
|
|
64574
|
-
entries =
|
|
64521
|
+
entries = import_node_fs39.default.readdirSync(dir, { withFileTypes: true });
|
|
64575
64522
|
} catch {
|
|
64576
64523
|
return;
|
|
64577
64524
|
}
|
|
64578
64525
|
for (const ent of entries) {
|
|
64579
64526
|
if (!ent.name.endsWith(".md")) continue;
|
|
64580
|
-
if (!ent.isFile() && !(ent.isSymbolicLink() && fileExistsSync(
|
|
64527
|
+
if (!ent.isFile() && !(ent.isSymbolicLink() && fileExistsSync(import_node_path43.default.join(dir, ent.name)))) {
|
|
64581
64528
|
continue;
|
|
64582
64529
|
}
|
|
64583
|
-
const filePath =
|
|
64530
|
+
const filePath = import_node_path43.default.join(dir, ent.name);
|
|
64584
64531
|
const baseName = ent.name.replace(/\.md$/, "");
|
|
64585
64532
|
if (seen.has(baseName)) continue;
|
|
64586
64533
|
seen.add(baseName);
|
|
@@ -64598,12 +64545,12 @@ function scanPluginAgentsTree(root, pluginName, seen, out) {
|
|
|
64598
64545
|
function walk2(dir, namespaces) {
|
|
64599
64546
|
let entries;
|
|
64600
64547
|
try {
|
|
64601
|
-
entries =
|
|
64548
|
+
entries = import_node_fs39.default.readdirSync(dir, { withFileTypes: true });
|
|
64602
64549
|
} catch {
|
|
64603
64550
|
return;
|
|
64604
64551
|
}
|
|
64605
64552
|
for (const ent of entries) {
|
|
64606
|
-
const childPath =
|
|
64553
|
+
const childPath = import_node_path43.default.join(dir, ent.name);
|
|
64607
64554
|
if (ent.isDirectory() || ent.isSymbolicLink() && isDirLikeSync2(childPath)) {
|
|
64608
64555
|
walk2(childPath, [...namespaces, ent.name]);
|
|
64609
64556
|
continue;
|
|
@@ -64628,13 +64575,13 @@ function scanPluginAgentsTree(root, pluginName, seen, out) {
|
|
|
64628
64575
|
walk2(root, []);
|
|
64629
64576
|
}
|
|
64630
64577
|
function readInstalledPlugins2(home) {
|
|
64631
|
-
const pluginsDir =
|
|
64632
|
-
const v22 =
|
|
64633
|
-
const v1 =
|
|
64578
|
+
const pluginsDir = import_node_path43.default.join(home, ".claude", "plugins");
|
|
64579
|
+
const v22 = import_node_path43.default.join(pluginsDir, "installed_plugins_v2.json");
|
|
64580
|
+
const v1 = import_node_path43.default.join(pluginsDir, "installed_plugins.json");
|
|
64634
64581
|
let raw = null;
|
|
64635
64582
|
for (const candidate of [v22, v1]) {
|
|
64636
64583
|
try {
|
|
64637
|
-
raw =
|
|
64584
|
+
raw = import_node_fs39.default.readFileSync(candidate, "utf8");
|
|
64638
64585
|
break;
|
|
64639
64586
|
} catch {
|
|
64640
64587
|
}
|
|
@@ -64659,19 +64606,19 @@ function readInstalledPlugins2(home) {
|
|
|
64659
64606
|
return out;
|
|
64660
64607
|
}
|
|
64661
64608
|
function walkUpProjectAgentsDirs(startCwd, home, seen, out) {
|
|
64662
|
-
let cur =
|
|
64663
|
-
const fsRoot =
|
|
64609
|
+
let cur = import_node_path43.default.resolve(startCwd);
|
|
64610
|
+
const fsRoot = import_node_path43.default.parse(cur).root;
|
|
64664
64611
|
while (true) {
|
|
64665
|
-
scanAgentsDir(
|
|
64612
|
+
scanAgentsDir(import_node_path43.default.join(cur, ".claude", "agents"), "project", seen, out);
|
|
64666
64613
|
let hasGit = false;
|
|
64667
64614
|
try {
|
|
64668
|
-
hasGit =
|
|
64615
|
+
hasGit = import_node_fs39.default.existsSync(import_node_path43.default.join(cur, ".git"));
|
|
64669
64616
|
} catch {
|
|
64670
64617
|
}
|
|
64671
64618
|
if (hasGit) return;
|
|
64672
64619
|
if (cur === home) return;
|
|
64673
64620
|
if (cur === fsRoot) return;
|
|
64674
|
-
const parent =
|
|
64621
|
+
const parent = import_node_path43.default.dirname(cur);
|
|
64675
64622
|
if (parent === cur) return;
|
|
64676
64623
|
cur = parent;
|
|
64677
64624
|
}
|
|
@@ -64681,7 +64628,7 @@ var AgentsScanner = class {
|
|
|
64681
64628
|
extraPluginRoots;
|
|
64682
64629
|
policyDir;
|
|
64683
64630
|
constructor(opts = {}) {
|
|
64684
|
-
this.home = opts.home ?? process.env.CLAUDE_CONFIG_DIR ??
|
|
64631
|
+
this.home = opts.home ?? process.env.CLAUDE_CONFIG_DIR ?? import_node_os13.default.homedir();
|
|
64685
64632
|
this.extraPluginRoots = opts.extraPluginRoots ?? [];
|
|
64686
64633
|
if (opts.policyDir !== void 0) {
|
|
64687
64634
|
this.policyDir = opts.policyDir;
|
|
@@ -64706,7 +64653,7 @@ var AgentsScanner = class {
|
|
|
64706
64653
|
}
|
|
64707
64654
|
const fsBlock = [];
|
|
64708
64655
|
scanAgentsDir(
|
|
64709
|
-
|
|
64656
|
+
import_node_path43.default.join(this.home, ".claude", "agents"),
|
|
64710
64657
|
"global",
|
|
64711
64658
|
seen,
|
|
64712
64659
|
fsBlock
|
|
@@ -64720,7 +64667,7 @@ var AgentsScanner = class {
|
|
|
64720
64667
|
...this.extraPluginRoots
|
|
64721
64668
|
];
|
|
64722
64669
|
for (const { name, root } of plugins) {
|
|
64723
|
-
const agentsRoot =
|
|
64670
|
+
const agentsRoot = import_node_path43.default.join(root, "agents");
|
|
64724
64671
|
scanPluginAgentsTree(agentsRoot, name, seen, fsBlock);
|
|
64725
64672
|
}
|
|
64726
64673
|
return [...builtinBlock, ...fsBlock];
|
|
@@ -64728,28 +64675,28 @@ var AgentsScanner = class {
|
|
|
64728
64675
|
};
|
|
64729
64676
|
|
|
64730
64677
|
// src/observer/session-observer.ts
|
|
64731
|
-
var import_node_fs42 = __toESM(require("fs"), 1);
|
|
64732
|
-
var import_node_os16 = __toESM(require("os"), 1);
|
|
64733
|
-
var import_node_path46 = __toESM(require("path"), 1);
|
|
64734
|
-
init_claude_history();
|
|
64735
|
-
|
|
64736
|
-
// src/observer/subagent-meta-observer.ts
|
|
64737
64678
|
var import_node_fs41 = __toESM(require("fs"), 1);
|
|
64738
64679
|
var import_node_os15 = __toESM(require("os"), 1);
|
|
64739
64680
|
var import_node_path45 = __toESM(require("path"), 1);
|
|
64740
64681
|
init_claude_history();
|
|
64682
|
+
|
|
64683
|
+
// src/observer/subagent-meta-observer.ts
|
|
64684
|
+
var import_node_fs40 = __toESM(require("fs"), 1);
|
|
64685
|
+
var import_node_os14 = __toESM(require("os"), 1);
|
|
64686
|
+
var import_node_path44 = __toESM(require("path"), 1);
|
|
64687
|
+
init_claude_history();
|
|
64741
64688
|
var META_RE = /^agent-([A-Za-z0-9_-]+)\.meta\.json$/;
|
|
64742
64689
|
var SubagentMetaObserver = class {
|
|
64743
64690
|
constructor(opts) {
|
|
64744
64691
|
this.opts = opts;
|
|
64745
|
-
this.home = opts.home ??
|
|
64692
|
+
this.home = opts.home ?? import_node_os14.default.homedir();
|
|
64746
64693
|
}
|
|
64747
64694
|
opts;
|
|
64748
64695
|
home;
|
|
64749
64696
|
watches = /* @__PURE__ */ new Map();
|
|
64750
64697
|
// public for spec only:测试直接拼路径写假 meta.json;生产 start() 内部自己解析
|
|
64751
64698
|
resolveSubagentDir(cwd, toolSessionId) {
|
|
64752
|
-
return
|
|
64699
|
+
return import_node_path44.default.join(
|
|
64753
64700
|
this.home,
|
|
64754
64701
|
".claude",
|
|
64755
64702
|
"projects",
|
|
@@ -64779,7 +64726,7 @@ var SubagentMetaObserver = class {
|
|
|
64779
64726
|
attachWatcher(w3) {
|
|
64780
64727
|
if (w3.watcher) return;
|
|
64781
64728
|
try {
|
|
64782
|
-
w3.watcher =
|
|
64729
|
+
w3.watcher = import_node_fs40.default.watch(w3.dirPath, { persistent: false }, (_evt, name) => {
|
|
64783
64730
|
if (!name) return;
|
|
64784
64731
|
const m3 = META_RE.exec(String(name));
|
|
64785
64732
|
if (!m3) return;
|
|
@@ -64791,7 +64738,7 @@ var SubagentMetaObserver = class {
|
|
|
64791
64738
|
scan(w3) {
|
|
64792
64739
|
let entries;
|
|
64793
64740
|
try {
|
|
64794
|
-
entries =
|
|
64741
|
+
entries = import_node_fs40.default.readdirSync(w3.dirPath);
|
|
64795
64742
|
} catch {
|
|
64796
64743
|
return;
|
|
64797
64744
|
}
|
|
@@ -64805,10 +64752,10 @@ var SubagentMetaObserver = class {
|
|
|
64805
64752
|
if (!m3) return;
|
|
64806
64753
|
const agentId = m3[1];
|
|
64807
64754
|
if (w3.emitted.has(agentId)) return;
|
|
64808
|
-
const file =
|
|
64755
|
+
const file = import_node_path44.default.join(w3.dirPath, name);
|
|
64809
64756
|
let raw;
|
|
64810
64757
|
try {
|
|
64811
|
-
raw =
|
|
64758
|
+
raw = import_node_fs40.default.readFileSync(file, "utf8");
|
|
64812
64759
|
} catch {
|
|
64813
64760
|
return;
|
|
64814
64761
|
}
|
|
@@ -64853,7 +64800,7 @@ var SubagentMetaObserver = class {
|
|
|
64853
64800
|
var SessionObserver = class {
|
|
64854
64801
|
constructor(opts) {
|
|
64855
64802
|
this.opts = opts;
|
|
64856
|
-
this.home = opts.home ??
|
|
64803
|
+
this.home = opts.home ?? import_node_os15.default.homedir();
|
|
64857
64804
|
this.metaObserver = opts.enableSubagentMetaObserver ? new SubagentMetaObserver({ home: this.home, onEvent: opts.onEvent }) : null;
|
|
64858
64805
|
}
|
|
64859
64806
|
opts;
|
|
@@ -64865,14 +64812,14 @@ var SessionObserver = class {
|
|
|
64865
64812
|
metaObserver;
|
|
64866
64813
|
resolveJsonlPath(cwd, toolSessionId, override) {
|
|
64867
64814
|
if (override) return override;
|
|
64868
|
-
return
|
|
64815
|
+
return import_node_path45.default.join(this.home, ".claude", "projects", cwdToHashDir(cwd), `${toolSessionId}.jsonl`);
|
|
64869
64816
|
}
|
|
64870
64817
|
start(args) {
|
|
64871
64818
|
this.stop(args.sessionId);
|
|
64872
64819
|
const filePath = this.resolveJsonlPath(args.cwd, args.toolSessionId, args.jsonlPath);
|
|
64873
64820
|
let size = 0;
|
|
64874
64821
|
try {
|
|
64875
|
-
size =
|
|
64822
|
+
size = import_node_fs41.default.statSync(filePath).size;
|
|
64876
64823
|
} catch {
|
|
64877
64824
|
}
|
|
64878
64825
|
const w3 = {
|
|
@@ -64885,16 +64832,16 @@ var SessionObserver = class {
|
|
|
64885
64832
|
adapter: args.adapter,
|
|
64886
64833
|
prevIsRejectSentinel: false,
|
|
64887
64834
|
toolSessionId: args.toolSessionId,
|
|
64888
|
-
sawFile:
|
|
64835
|
+
sawFile: import_node_fs41.default.existsSync(filePath),
|
|
64889
64836
|
lastRelocateScanMs: 0,
|
|
64890
64837
|
pendingCwdDerive: false,
|
|
64891
64838
|
lastDeriveMs: 0
|
|
64892
64839
|
};
|
|
64893
64840
|
try {
|
|
64894
|
-
|
|
64841
|
+
import_node_fs41.default.mkdirSync(import_node_path45.default.dirname(filePath), { recursive: true });
|
|
64895
64842
|
} catch {
|
|
64896
64843
|
}
|
|
64897
|
-
w3.watcher =
|
|
64844
|
+
w3.watcher = import_node_fs41.default.watch(import_node_path45.default.dirname(filePath), { persistent: false }, (_event, changedName) => {
|
|
64898
64845
|
if (!changedName || !w3.filePath.endsWith(changedName)) return;
|
|
64899
64846
|
this.poll(w3);
|
|
64900
64847
|
});
|
|
@@ -64917,7 +64864,7 @@ var SessionObserver = class {
|
|
|
64917
64864
|
// 异常静默吞,不阻塞 watcher 启动
|
|
64918
64865
|
hydrateMetaTail(w3, maxLines = 200) {
|
|
64919
64866
|
try {
|
|
64920
|
-
const raw =
|
|
64867
|
+
const raw = import_node_fs41.default.readFileSync(w3.filePath, "utf8");
|
|
64921
64868
|
if (!raw) return;
|
|
64922
64869
|
const allLines = raw.split("\n").filter((l2) => l2.trim().length > 0);
|
|
64923
64870
|
if (allLines.length === 0) return;
|
|
@@ -64941,7 +64888,7 @@ var SessionObserver = class {
|
|
|
64941
64888
|
poll(w3) {
|
|
64942
64889
|
let size = 0;
|
|
64943
64890
|
try {
|
|
64944
|
-
size =
|
|
64891
|
+
size = import_node_fs41.default.statSync(w3.filePath).size;
|
|
64945
64892
|
} catch {
|
|
64946
64893
|
if (w3.sawFile) this.maybeRelocate(w3);
|
|
64947
64894
|
return;
|
|
@@ -64952,11 +64899,11 @@ var SessionObserver = class {
|
|
|
64952
64899
|
w3.buf = "";
|
|
64953
64900
|
}
|
|
64954
64901
|
if (size === w3.lastSize) return;
|
|
64955
|
-
const fd =
|
|
64902
|
+
const fd = import_node_fs41.default.openSync(w3.filePath, "r");
|
|
64956
64903
|
try {
|
|
64957
64904
|
const len = size - w3.lastSize;
|
|
64958
64905
|
const buf = Buffer.alloc(len);
|
|
64959
|
-
|
|
64906
|
+
import_node_fs41.default.readSync(fd, buf, 0, len, w3.lastSize);
|
|
64960
64907
|
w3.lastSize = size;
|
|
64961
64908
|
w3.buf += buf.toString("utf8");
|
|
64962
64909
|
let newlineIndex;
|
|
@@ -64979,7 +64926,7 @@ var SessionObserver = class {
|
|
|
64979
64926
|
}
|
|
64980
64927
|
}
|
|
64981
64928
|
} finally {
|
|
64982
|
-
|
|
64929
|
+
import_node_fs41.default.closeSync(fd);
|
|
64983
64930
|
}
|
|
64984
64931
|
if (w3.pendingCwdDerive) this.maybeDeriveCwd(w3);
|
|
64985
64932
|
}
|
|
@@ -64991,7 +64938,7 @@ var SessionObserver = class {
|
|
|
64991
64938
|
const now = Date.now();
|
|
64992
64939
|
if (now - w3.lastRelocateScanMs < 1e3) return;
|
|
64993
64940
|
w3.lastRelocateScanMs = now;
|
|
64994
|
-
const projectsRoot =
|
|
64941
|
+
const projectsRoot = import_node_path45.default.join(this.home, ".claude", "projects");
|
|
64995
64942
|
const found = findTranscriptByToolSessionId(projectsRoot, w3.toolSessionId);
|
|
64996
64943
|
if (!found || found === w3.filePath) return;
|
|
64997
64944
|
try {
|
|
@@ -65000,7 +64947,7 @@ var SessionObserver = class {
|
|
|
65000
64947
|
}
|
|
65001
64948
|
w3.filePath = found;
|
|
65002
64949
|
try {
|
|
65003
|
-
w3.watcher =
|
|
64950
|
+
w3.watcher = import_node_fs41.default.watch(import_node_path45.default.dirname(found), { persistent: false }, (_event, changedName) => {
|
|
65004
64951
|
if (!changedName || !w3.filePath.endsWith(changedName)) return;
|
|
65005
64952
|
this.poll(w3);
|
|
65006
64953
|
});
|
|
@@ -65122,9 +65069,9 @@ function listRegistered() {
|
|
|
65122
65069
|
// src/tools/title-generator.ts
|
|
65123
65070
|
var import_node_child_process13 = require("child_process");
|
|
65124
65071
|
init_protocol();
|
|
65125
|
-
var
|
|
65126
|
-
var
|
|
65127
|
-
var
|
|
65072
|
+
var import_node_fs42 = __toESM(require("fs"), 1);
|
|
65073
|
+
var import_node_os16 = __toESM(require("os"), 1);
|
|
65074
|
+
var import_node_path46 = __toESM(require("path"), 1);
|
|
65128
65075
|
var TITLE_GEN_DIR_PREFIX = "clawd-title-";
|
|
65129
65076
|
var TITLE_MODEL_BY_TOOL = {
|
|
65130
65077
|
claude: "haiku",
|
|
@@ -65195,21 +65142,21 @@ async function generateSessionTitle(tool, firstMessage, deps = {}) {
|
|
|
65195
65142
|
if (!text) return null;
|
|
65196
65143
|
let workDir;
|
|
65197
65144
|
try {
|
|
65198
|
-
workDir =
|
|
65145
|
+
workDir = import_node_fs42.default.mkdtempSync(import_node_path46.default.join(import_node_os16.default.tmpdir(), TITLE_GEN_DIR_PREFIX));
|
|
65199
65146
|
} catch {
|
|
65200
65147
|
return null;
|
|
65201
65148
|
}
|
|
65202
65149
|
const cleanupWorkDir = () => {
|
|
65203
65150
|
try {
|
|
65204
|
-
|
|
65151
|
+
import_node_fs42.default.rmSync(workDir, { recursive: true, force: true });
|
|
65205
65152
|
} catch {
|
|
65206
65153
|
}
|
|
65207
65154
|
};
|
|
65208
|
-
const outFile =
|
|
65209
|
-
const schemaFile =
|
|
65155
|
+
const outFile = import_node_path46.default.join(workDir, `codex-title-${process.pid}-${++outFileSeq}-${Date.now()}.txt`);
|
|
65156
|
+
const schemaFile = import_node_path46.default.join(workDir, "title-schema.json");
|
|
65210
65157
|
if (isCodexFamily(tool)) {
|
|
65211
65158
|
try {
|
|
65212
|
-
|
|
65159
|
+
import_node_fs42.default.writeFileSync(schemaFile, CODEX_TITLE_SCHEMA);
|
|
65213
65160
|
} catch {
|
|
65214
65161
|
cleanupWorkDir();
|
|
65215
65162
|
return null;
|
|
@@ -65259,7 +65206,7 @@ async function generateSessionTitle(tool, firstMessage, deps = {}) {
|
|
|
65259
65206
|
if (tool === "claude") return finish(parseTitleJson(stdout));
|
|
65260
65207
|
let fileText = "";
|
|
65261
65208
|
try {
|
|
65262
|
-
fileText =
|
|
65209
|
+
fileText = import_node_fs42.default.readFileSync(outFile, "utf8");
|
|
65263
65210
|
} catch {
|
|
65264
65211
|
return finish(null);
|
|
65265
65212
|
}
|
|
@@ -65281,7 +65228,7 @@ var wrapper_default = import_websocket.default;
|
|
|
65281
65228
|
|
|
65282
65229
|
// src/transport/local-ws-server.ts
|
|
65283
65230
|
var import_node_http = __toESM(require("http"), 1);
|
|
65284
|
-
var
|
|
65231
|
+
var import_node_crypto12 = require("crypto");
|
|
65285
65232
|
var LocalWsServer = class {
|
|
65286
65233
|
constructor(opts) {
|
|
65287
65234
|
this.opts = opts;
|
|
@@ -65498,7 +65445,7 @@ var LocalWsServer = class {
|
|
|
65498
65445
|
}
|
|
65499
65446
|
}
|
|
65500
65447
|
onConnection(socket, remoteAddress) {
|
|
65501
|
-
const id = (0,
|
|
65448
|
+
const id = (0, import_node_crypto12.randomUUID)();
|
|
65502
65449
|
const subscribedSessions = /* @__PURE__ */ new Map();
|
|
65503
65450
|
const handle = {
|
|
65504
65451
|
id,
|
|
@@ -65904,8 +65851,8 @@ async function authenticate(token, deps) {
|
|
|
65904
65851
|
}
|
|
65905
65852
|
|
|
65906
65853
|
// src/legacy-cleanup.ts
|
|
65907
|
-
var
|
|
65908
|
-
var
|
|
65854
|
+
var fs53 = __toESM(require("fs/promises"), 1);
|
|
65855
|
+
var path54 = __toESM(require("path"), 1);
|
|
65909
65856
|
var LEGACY_FILES = [
|
|
65910
65857
|
"personal-capability.json",
|
|
65911
65858
|
"received-capabilities.json",
|
|
@@ -65914,9 +65861,9 @@ var LEGACY_FILES = [
|
|
|
65914
65861
|
async function cleanupLegacyCapabilityFiles(dataDir, logger) {
|
|
65915
65862
|
const removed = [];
|
|
65916
65863
|
for (const name of LEGACY_FILES) {
|
|
65917
|
-
const p3 =
|
|
65864
|
+
const p3 = path54.join(dataDir, name);
|
|
65918
65865
|
try {
|
|
65919
|
-
await
|
|
65866
|
+
await fs53.unlink(p3);
|
|
65920
65867
|
removed.push(name);
|
|
65921
65868
|
logger.debug("legacy capability file removed", { file: name });
|
|
65922
65869
|
} catch (err) {
|
|
@@ -65928,13 +65875,13 @@ async function cleanupLegacyCapabilityFiles(dataDir, logger) {
|
|
|
65928
65875
|
}
|
|
65929
65876
|
|
|
65930
65877
|
// src/inbox/inbox-store.ts
|
|
65931
|
-
var
|
|
65932
|
-
var
|
|
65878
|
+
var fs54 = __toESM(require("fs"), 1);
|
|
65879
|
+
var path55 = __toESM(require("path"), 1);
|
|
65933
65880
|
var INBOX_SUBDIR = "inbox";
|
|
65934
65881
|
var InboxStore = class {
|
|
65935
65882
|
constructor(dataDir) {
|
|
65936
65883
|
this.dataDir = dataDir;
|
|
65937
|
-
|
|
65884
|
+
fs54.mkdirSync(this.dirPath(), { recursive: true });
|
|
65938
65885
|
}
|
|
65939
65886
|
dataDir;
|
|
65940
65887
|
/**
|
|
@@ -65946,7 +65893,7 @@ var InboxStore = class {
|
|
|
65946
65893
|
const file = this.filePath(peerDeviceId);
|
|
65947
65894
|
let raw;
|
|
65948
65895
|
try {
|
|
65949
|
-
raw =
|
|
65896
|
+
raw = fs54.readFileSync(file, "utf8");
|
|
65950
65897
|
} catch (err) {
|
|
65951
65898
|
if (err?.code === "ENOENT") return [];
|
|
65952
65899
|
return [];
|
|
@@ -65962,7 +65909,7 @@ var InboxStore = class {
|
|
|
65962
65909
|
const dir = this.dirPath();
|
|
65963
65910
|
let entries;
|
|
65964
65911
|
try {
|
|
65965
|
-
entries =
|
|
65912
|
+
entries = fs54.readdirSync(dir);
|
|
65966
65913
|
} catch (err) {
|
|
65967
65914
|
if (err?.code === "ENOENT") return [];
|
|
65968
65915
|
return [];
|
|
@@ -65978,9 +65925,9 @@ var InboxStore = class {
|
|
|
65978
65925
|
if (existing.some((m3) => m3.id === message.id)) return;
|
|
65979
65926
|
const file = this.filePath(message.peerDeviceId);
|
|
65980
65927
|
const line = JSON.stringify(message) + "\n";
|
|
65981
|
-
|
|
65928
|
+
fs54.appendFileSync(file, line, { mode: 384 });
|
|
65982
65929
|
try {
|
|
65983
|
-
|
|
65930
|
+
fs54.chmodSync(file, 384);
|
|
65984
65931
|
} catch {
|
|
65985
65932
|
}
|
|
65986
65933
|
}
|
|
@@ -66010,7 +65957,7 @@ var InboxStore = class {
|
|
|
66010
65957
|
removeByPeerDeviceId(peerDeviceId) {
|
|
66011
65958
|
const file = this.filePath(peerDeviceId);
|
|
66012
65959
|
try {
|
|
66013
|
-
|
|
65960
|
+
fs54.unlinkSync(file);
|
|
66014
65961
|
} catch (err) {
|
|
66015
65962
|
if (err?.code === "ENOENT") return;
|
|
66016
65963
|
}
|
|
@@ -66019,18 +65966,18 @@ var InboxStore = class {
|
|
|
66019
65966
|
const file = this.filePath(peerDeviceId);
|
|
66020
65967
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
66021
65968
|
const content = messages.map((m3) => JSON.stringify(m3)).join("\n") + (messages.length > 0 ? "\n" : "");
|
|
66022
|
-
|
|
66023
|
-
|
|
65969
|
+
fs54.writeFileSync(tmp, content, { mode: 384 });
|
|
65970
|
+
fs54.renameSync(tmp, file);
|
|
66024
65971
|
try {
|
|
66025
|
-
|
|
65972
|
+
fs54.chmodSync(file, 384);
|
|
66026
65973
|
} catch {
|
|
66027
65974
|
}
|
|
66028
65975
|
}
|
|
66029
65976
|
dirPath() {
|
|
66030
|
-
return
|
|
65977
|
+
return path55.join(this.dataDir, INBOX_SUBDIR);
|
|
66031
65978
|
}
|
|
66032
65979
|
filePath(peerDeviceId) {
|
|
66033
|
-
return
|
|
65980
|
+
return path55.join(this.dirPath(), `${peerDeviceId}.jsonl`);
|
|
66034
65981
|
}
|
|
66035
65982
|
};
|
|
66036
65983
|
function parseAllLines(raw) {
|
|
@@ -66118,8 +66065,8 @@ var InboxManager = class {
|
|
|
66118
66065
|
};
|
|
66119
66066
|
|
|
66120
66067
|
// src/state/contact-store.ts
|
|
66121
|
-
var
|
|
66122
|
-
var
|
|
66068
|
+
var fs55 = __toESM(require("fs"), 1);
|
|
66069
|
+
var path56 = __toESM(require("path"), 1);
|
|
66123
66070
|
var FILE_NAME = "contacts.json";
|
|
66124
66071
|
var ContactStore = class {
|
|
66125
66072
|
constructor(dataDir) {
|
|
@@ -66129,10 +66076,10 @@ var ContactStore = class {
|
|
|
66129
66076
|
contacts = /* @__PURE__ */ new Map();
|
|
66130
66077
|
load() {
|
|
66131
66078
|
this.contacts.clear();
|
|
66132
|
-
const file =
|
|
66079
|
+
const file = path56.join(this.dataDir, FILE_NAME);
|
|
66133
66080
|
let raw;
|
|
66134
66081
|
try {
|
|
66135
|
-
raw =
|
|
66082
|
+
raw = fs55.readFileSync(file, "utf8");
|
|
66136
66083
|
} catch (err) {
|
|
66137
66084
|
if (err?.code !== "ENOENT") this.renameBak(file);
|
|
66138
66085
|
return;
|
|
@@ -66213,20 +66160,20 @@ var ContactStore = class {
|
|
|
66213
66160
|
return true;
|
|
66214
66161
|
}
|
|
66215
66162
|
flush() {
|
|
66216
|
-
const file =
|
|
66163
|
+
const file = path56.join(this.dataDir, FILE_NAME);
|
|
66217
66164
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
66218
66165
|
const content = JSON.stringify(
|
|
66219
66166
|
{ contacts: Array.from(this.contacts.values()) },
|
|
66220
66167
|
null,
|
|
66221
66168
|
2
|
|
66222
66169
|
);
|
|
66223
|
-
|
|
66224
|
-
|
|
66225
|
-
|
|
66170
|
+
fs55.mkdirSync(this.dataDir, { recursive: true });
|
|
66171
|
+
fs55.writeFileSync(tmp, content, { mode: 384 });
|
|
66172
|
+
fs55.renameSync(tmp, file);
|
|
66226
66173
|
}
|
|
66227
66174
|
renameBak(file) {
|
|
66228
66175
|
try {
|
|
66229
|
-
|
|
66176
|
+
fs55.renameSync(file, `${file}.bak`);
|
|
66230
66177
|
} catch {
|
|
66231
66178
|
}
|
|
66232
66179
|
}
|
|
@@ -66334,61 +66281,61 @@ async function connectRemote(args) {
|
|
|
66334
66281
|
}
|
|
66335
66282
|
|
|
66336
66283
|
// src/migrations/2026-05-20-flatten-sessions.ts
|
|
66337
|
-
var
|
|
66338
|
-
var
|
|
66284
|
+
var fs56 = __toESM(require("fs"), 1);
|
|
66285
|
+
var path57 = __toESM(require("path"), 1);
|
|
66339
66286
|
var MIGRATION_FLAG_NAME = ".migration.v1.done";
|
|
66340
66287
|
function migrateFlattenSessions(opts) {
|
|
66341
66288
|
const dataDir = opts.dataDir;
|
|
66342
66289
|
const now = opts.now ?? Date.now;
|
|
66343
|
-
const sessionsDir =
|
|
66344
|
-
const flagPath =
|
|
66290
|
+
const sessionsDir = path57.join(dataDir, "sessions");
|
|
66291
|
+
const flagPath = path57.join(sessionsDir, MIGRATION_FLAG_NAME);
|
|
66345
66292
|
if (existsSync3(flagPath)) {
|
|
66346
66293
|
return { skipped: true, flagWritten: false, movedBare: 0, movedVmOwner: 0, archivedListener: 0 };
|
|
66347
66294
|
}
|
|
66348
66295
|
let movedBare = 0;
|
|
66349
66296
|
let movedVmOwner = 0;
|
|
66350
66297
|
let archivedListener = 0;
|
|
66351
|
-
const defaultDir =
|
|
66298
|
+
const defaultDir = path57.join(sessionsDir, "default");
|
|
66352
66299
|
if (existsSync3(defaultDir)) {
|
|
66353
66300
|
for (const entry of readdirSafe(defaultDir)) {
|
|
66354
66301
|
if (!entry.endsWith(".json")) continue;
|
|
66355
|
-
const src =
|
|
66356
|
-
const dst =
|
|
66357
|
-
|
|
66302
|
+
const src = path57.join(defaultDir, entry);
|
|
66303
|
+
const dst = path57.join(sessionsDir, entry);
|
|
66304
|
+
fs56.renameSync(src, dst);
|
|
66358
66305
|
movedBare += 1;
|
|
66359
66306
|
}
|
|
66360
66307
|
rmdirIfEmpty(defaultDir);
|
|
66361
66308
|
}
|
|
66362
66309
|
for (const pid of readdirSafe(sessionsDir)) {
|
|
66363
|
-
const personaDir =
|
|
66310
|
+
const personaDir = path57.join(sessionsDir, pid);
|
|
66364
66311
|
if (!isDir(personaDir)) continue;
|
|
66365
66312
|
if (pid === "default") continue;
|
|
66366
|
-
const ownerSrc =
|
|
66313
|
+
const ownerSrc = path57.join(personaDir, "owner");
|
|
66367
66314
|
if (existsSync3(ownerSrc) && isDir(ownerSrc)) {
|
|
66368
|
-
const ownerDst =
|
|
66369
|
-
|
|
66315
|
+
const ownerDst = path57.join(dataDir, "personas", pid, ".clawd", "sessions", "owner");
|
|
66316
|
+
fs56.mkdirSync(ownerDst, { recursive: true });
|
|
66370
66317
|
for (const file of readdirSafe(ownerSrc)) {
|
|
66371
66318
|
if (!file.endsWith(".json")) continue;
|
|
66372
|
-
|
|
66319
|
+
fs56.renameSync(path57.join(ownerSrc, file), path57.join(ownerDst, file));
|
|
66373
66320
|
movedVmOwner += 1;
|
|
66374
66321
|
}
|
|
66375
66322
|
rmdirIfEmpty(ownerSrc);
|
|
66376
66323
|
}
|
|
66377
|
-
const listenerSrc =
|
|
66324
|
+
const listenerSrc = path57.join(personaDir, "listener");
|
|
66378
66325
|
if (existsSync3(listenerSrc) && isDir(listenerSrc)) {
|
|
66379
|
-
const archiveDst =
|
|
66380
|
-
|
|
66326
|
+
const archiveDst = path57.join(dataDir, ".legacy", `listener-${pid}`);
|
|
66327
|
+
fs56.mkdirSync(archiveDst, { recursive: true });
|
|
66381
66328
|
for (const file of readdirSafe(listenerSrc)) {
|
|
66382
66329
|
if (!file.endsWith(".json")) continue;
|
|
66383
|
-
|
|
66330
|
+
fs56.renameSync(path57.join(listenerSrc, file), path57.join(archiveDst, file));
|
|
66384
66331
|
archivedListener += 1;
|
|
66385
66332
|
}
|
|
66386
66333
|
rmdirIfEmpty(listenerSrc);
|
|
66387
66334
|
}
|
|
66388
66335
|
rmdirIfEmpty(personaDir);
|
|
66389
66336
|
}
|
|
66390
|
-
|
|
66391
|
-
|
|
66337
|
+
fs56.mkdirSync(sessionsDir, { recursive: true });
|
|
66338
|
+
fs56.writeFileSync(flagPath, JSON.stringify({ migratedAt: now() }, null, 2));
|
|
66392
66339
|
return {
|
|
66393
66340
|
skipped: false,
|
|
66394
66341
|
flagWritten: true,
|
|
@@ -66399,7 +66346,7 @@ function migrateFlattenSessions(opts) {
|
|
|
66399
66346
|
}
|
|
66400
66347
|
function existsSync3(p3) {
|
|
66401
66348
|
try {
|
|
66402
|
-
|
|
66349
|
+
fs56.statSync(p3);
|
|
66403
66350
|
return true;
|
|
66404
66351
|
} catch {
|
|
66405
66352
|
return false;
|
|
@@ -66407,64 +66354,64 @@ function existsSync3(p3) {
|
|
|
66407
66354
|
}
|
|
66408
66355
|
function isDir(p3) {
|
|
66409
66356
|
try {
|
|
66410
|
-
return
|
|
66357
|
+
return fs56.statSync(p3).isDirectory();
|
|
66411
66358
|
} catch {
|
|
66412
66359
|
return false;
|
|
66413
66360
|
}
|
|
66414
66361
|
}
|
|
66415
66362
|
function readdirSafe(p3) {
|
|
66416
66363
|
try {
|
|
66417
|
-
return
|
|
66364
|
+
return fs56.readdirSync(p3);
|
|
66418
66365
|
} catch {
|
|
66419
66366
|
return [];
|
|
66420
66367
|
}
|
|
66421
66368
|
}
|
|
66422
66369
|
function rmdirIfEmpty(p3) {
|
|
66423
66370
|
try {
|
|
66424
|
-
|
|
66371
|
+
fs56.rmdirSync(p3);
|
|
66425
66372
|
} catch {
|
|
66426
66373
|
}
|
|
66427
66374
|
}
|
|
66428
66375
|
|
|
66429
66376
|
// src/migrations/2026-08-18-drop-seeded-projects.ts
|
|
66430
|
-
var
|
|
66431
|
-
var
|
|
66377
|
+
var fs57 = __toESM(require("fs"), 1);
|
|
66378
|
+
var path58 = __toESM(require("path"), 1);
|
|
66432
66379
|
var DROP_SEEDED_PROJECTS_FLAG = ".projects-seed-dropped.v1.done";
|
|
66433
66380
|
function dropSeededProjects(opts) {
|
|
66434
|
-
|
|
66435
|
-
const flag =
|
|
66436
|
-
if (
|
|
66437
|
-
const file =
|
|
66381
|
+
fs57.mkdirSync(opts.dataDir, { recursive: true });
|
|
66382
|
+
const flag = path58.join(opts.dataDir, DROP_SEEDED_PROJECTS_FLAG);
|
|
66383
|
+
if (fs57.existsSync(flag)) return { skipped: true, dropped: 0, backup: null };
|
|
66384
|
+
const file = path58.join(opts.dataDir, "projects.json");
|
|
66438
66385
|
let raw = null;
|
|
66439
66386
|
let dropped = 0;
|
|
66440
66387
|
try {
|
|
66441
|
-
raw =
|
|
66388
|
+
raw = fs57.readFileSync(file, "utf8");
|
|
66442
66389
|
dropped = JSON.parse(raw).projects?.length ?? 0;
|
|
66443
66390
|
} catch {
|
|
66444
66391
|
}
|
|
66445
66392
|
let backup = null;
|
|
66446
66393
|
if (raw != null && dropped > 0) {
|
|
66447
|
-
const dir =
|
|
66448
|
-
|
|
66449
|
-
backup =
|
|
66450
|
-
|
|
66394
|
+
const dir = path58.join(opts.dataDir, "backups");
|
|
66395
|
+
fs57.mkdirSync(dir, { recursive: true });
|
|
66396
|
+
backup = path58.join(dir, `projects.seed-dropped.${(opts.now ?? Date.now)()}.json`);
|
|
66397
|
+
fs57.writeFileSync(backup, raw);
|
|
66451
66398
|
}
|
|
66452
66399
|
if (raw != null || dropped > 0) {
|
|
66453
|
-
|
|
66400
|
+
fs57.writeFileSync(file, JSON.stringify({ projects: [] }, null, 2));
|
|
66454
66401
|
}
|
|
66455
|
-
|
|
66402
|
+
fs57.writeFileSync(flag, (/* @__PURE__ */ new Date()).toISOString());
|
|
66456
66403
|
return { skipped: false, dropped, backup };
|
|
66457
66404
|
}
|
|
66458
66405
|
|
|
66459
66406
|
// src/transport/http-router.ts
|
|
66460
|
-
var
|
|
66461
|
-
var
|
|
66407
|
+
var import_node_fs44 = __toESM(require("fs"), 1);
|
|
66408
|
+
var import_node_path49 = __toESM(require("path"), 1);
|
|
66462
66409
|
|
|
66463
66410
|
// src/attachment/upload.ts
|
|
66464
|
-
var
|
|
66465
|
-
var
|
|
66466
|
-
var
|
|
66467
|
-
var
|
|
66411
|
+
var import_node_fs43 = __toESM(require("fs"), 1);
|
|
66412
|
+
var import_node_path47 = __toESM(require("path"), 1);
|
|
66413
|
+
var import_node_crypto13 = __toESM(require("crypto"), 1);
|
|
66414
|
+
var import_promises7 = require("stream/promises");
|
|
66468
66415
|
var UploadError = class extends Error {
|
|
66469
66416
|
constructor(code, message) {
|
|
66470
66417
|
super(message);
|
|
@@ -66474,27 +66421,27 @@ var UploadError = class extends Error {
|
|
|
66474
66421
|
code;
|
|
66475
66422
|
};
|
|
66476
66423
|
function assertValidFileName(fileName) {
|
|
66477
|
-
if (fileName.length === 0 || fileName === "." || fileName === ".." || fileName.startsWith(".") || fileName.includes("/") || fileName.includes("\\") || fileName !==
|
|
66424
|
+
if (fileName.length === 0 || fileName === "." || fileName === ".." || fileName.startsWith(".") || fileName.includes("/") || fileName.includes("\\") || fileName !== import_node_path47.default.basename(fileName)) {
|
|
66478
66425
|
throw new UploadError("INVALID_FILENAME", `fileName must be a plain basename, got: ${fileName}`);
|
|
66479
66426
|
}
|
|
66480
66427
|
}
|
|
66481
66428
|
var HASH_PREFIX_LEN = 16;
|
|
66482
66429
|
async function writeUploadedAttachment(args) {
|
|
66483
66430
|
assertValidFileName(args.fileName);
|
|
66484
|
-
const attachmentsRoot =
|
|
66431
|
+
const attachmentsRoot = import_node_path47.default.join(args.baseDir, ".attachments");
|
|
66485
66432
|
try {
|
|
66486
|
-
|
|
66433
|
+
import_node_fs43.default.mkdirSync(attachmentsRoot, { recursive: true });
|
|
66487
66434
|
} catch (err) {
|
|
66488
66435
|
throw new UploadError("STORAGE_ERROR", `mkdir failed: ${err.message}`);
|
|
66489
66436
|
}
|
|
66490
|
-
const hasher =
|
|
66437
|
+
const hasher = import_node_crypto13.default.createHash("sha256");
|
|
66491
66438
|
let actualSize = 0;
|
|
66492
|
-
const tmpPath =
|
|
66439
|
+
const tmpPath = import_node_path47.default.join(
|
|
66493
66440
|
attachmentsRoot,
|
|
66494
|
-
`.upload-${process.pid}-${Date.now()}-${
|
|
66441
|
+
`.upload-${process.pid}-${Date.now()}-${import_node_crypto13.default.randomBytes(4).toString("hex")}`
|
|
66495
66442
|
);
|
|
66496
66443
|
try {
|
|
66497
|
-
await (0,
|
|
66444
|
+
await (0, import_promises7.pipeline)(
|
|
66498
66445
|
args.body,
|
|
66499
66446
|
async function* (source) {
|
|
66500
66447
|
for await (const chunk of source) {
|
|
@@ -66504,18 +66451,18 @@ async function writeUploadedAttachment(args) {
|
|
|
66504
66451
|
yield buf;
|
|
66505
66452
|
}
|
|
66506
66453
|
},
|
|
66507
|
-
|
|
66454
|
+
import_node_fs43.default.createWriteStream(tmpPath, { mode: 384 })
|
|
66508
66455
|
);
|
|
66509
66456
|
} catch (err) {
|
|
66510
66457
|
try {
|
|
66511
|
-
|
|
66458
|
+
import_node_fs43.default.unlinkSync(tmpPath);
|
|
66512
66459
|
} catch {
|
|
66513
66460
|
}
|
|
66514
66461
|
throw new UploadError("STORAGE_ERROR", `write failed: ${err.message}`);
|
|
66515
66462
|
}
|
|
66516
66463
|
if (actualSize !== args.contentLength) {
|
|
66517
66464
|
try {
|
|
66518
|
-
|
|
66465
|
+
import_node_fs43.default.unlinkSync(tmpPath);
|
|
66519
66466
|
} catch {
|
|
66520
66467
|
}
|
|
66521
66468
|
throw new UploadError(
|
|
@@ -66524,34 +66471,34 @@ async function writeUploadedAttachment(args) {
|
|
|
66524
66471
|
);
|
|
66525
66472
|
}
|
|
66526
66473
|
const attachmentId = hasher.digest("hex").slice(0, HASH_PREFIX_LEN);
|
|
66527
|
-
const hashDir =
|
|
66474
|
+
const hashDir = import_node_path47.default.join(attachmentsRoot, attachmentId);
|
|
66528
66475
|
let finalFileName;
|
|
66529
66476
|
let hashDirExists = false;
|
|
66530
66477
|
try {
|
|
66531
|
-
hashDirExists =
|
|
66478
|
+
hashDirExists = import_node_fs43.default.statSync(hashDir).isDirectory();
|
|
66532
66479
|
} catch {
|
|
66533
66480
|
}
|
|
66534
66481
|
if (hashDirExists) {
|
|
66535
|
-
const existing =
|
|
66482
|
+
const existing = import_node_fs43.default.readdirSync(hashDir).filter((n2) => !n2.startsWith("."));
|
|
66536
66483
|
finalFileName = existing[0] ?? args.fileName;
|
|
66537
66484
|
try {
|
|
66538
|
-
|
|
66485
|
+
import_node_fs43.default.unlinkSync(tmpPath);
|
|
66539
66486
|
} catch {
|
|
66540
66487
|
}
|
|
66541
66488
|
} else {
|
|
66542
66489
|
try {
|
|
66543
|
-
|
|
66490
|
+
import_node_fs43.default.mkdirSync(hashDir, { recursive: true });
|
|
66544
66491
|
finalFileName = args.fileName;
|
|
66545
|
-
|
|
66492
|
+
import_node_fs43.default.renameSync(tmpPath, import_node_path47.default.join(hashDir, finalFileName));
|
|
66546
66493
|
} catch (err) {
|
|
66547
66494
|
try {
|
|
66548
|
-
|
|
66495
|
+
import_node_fs43.default.unlinkSync(tmpPath);
|
|
66549
66496
|
} catch {
|
|
66550
66497
|
}
|
|
66551
66498
|
throw new UploadError("STORAGE_ERROR", `rename failed: ${err.message}`);
|
|
66552
66499
|
}
|
|
66553
66500
|
}
|
|
66554
|
-
const absPath =
|
|
66501
|
+
const absPath = import_node_path47.default.join(hashDir, finalFileName);
|
|
66555
66502
|
const relPath = absPath;
|
|
66556
66503
|
args.groupFileStore.upsert(args.scope, args.sessionId, {
|
|
66557
66504
|
relPath: absPath,
|
|
@@ -66565,9 +66512,9 @@ async function writeUploadedAttachment(args) {
|
|
|
66565
66512
|
}
|
|
66566
66513
|
|
|
66567
66514
|
// src/extension/import.ts
|
|
66568
|
-
var
|
|
66569
|
-
var
|
|
66570
|
-
var
|
|
66515
|
+
var import_promises8 = __toESM(require("fs/promises"), 1);
|
|
66516
|
+
var import_node_path48 = __toESM(require("path"), 1);
|
|
66517
|
+
var import_node_os17 = __toESM(require("os"), 1);
|
|
66571
66518
|
var import_jszip = __toESM(require_lib3(), 1);
|
|
66572
66519
|
var ImportError = class extends Error {
|
|
66573
66520
|
constructor(code, message) {
|
|
@@ -66584,7 +66531,7 @@ async function importZip(buf, root) {
|
|
|
66584
66531
|
throw new ImportError("ZIP_INVALID", `failed to load zip: ${e.message}`);
|
|
66585
66532
|
}
|
|
66586
66533
|
for (const name of Object.keys(zip.files)) {
|
|
66587
|
-
if (name.includes("..") || name.startsWith("/") ||
|
|
66534
|
+
if (name.includes("..") || name.startsWith("/") || import_node_path48.default.isAbsolute(name)) {
|
|
66588
66535
|
throw new ImportError("ZIP_INVALID", `unsafe zip entry path: ${name}`);
|
|
66589
66536
|
}
|
|
66590
66537
|
}
|
|
@@ -66617,33 +66564,33 @@ async function importZip(buf, root) {
|
|
|
66617
66564
|
);
|
|
66618
66565
|
}
|
|
66619
66566
|
}
|
|
66620
|
-
const destDir =
|
|
66567
|
+
const destDir = import_node_path48.default.join(root, manifest.id);
|
|
66621
66568
|
let destExists = false;
|
|
66622
66569
|
try {
|
|
66623
|
-
await
|
|
66570
|
+
await import_promises8.default.access(destDir);
|
|
66624
66571
|
destExists = true;
|
|
66625
66572
|
} catch {
|
|
66626
66573
|
}
|
|
66627
66574
|
if (destExists) {
|
|
66628
66575
|
throw new ImportError("ALREADY_EXISTS", `extension ${manifest.id} already installed`);
|
|
66629
66576
|
}
|
|
66630
|
-
const stage = await
|
|
66577
|
+
const stage = await import_promises8.default.mkdtemp(import_node_path48.default.join(import_node_os17.default.tmpdir(), `clawd-ext-stage-${manifest.id}-`));
|
|
66631
66578
|
try {
|
|
66632
66579
|
for (const [name, entry] of Object.entries(zip.files)) {
|
|
66633
|
-
const dest =
|
|
66580
|
+
const dest = import_node_path48.default.join(stage, name);
|
|
66634
66581
|
if (entry.dir) {
|
|
66635
|
-
await
|
|
66582
|
+
await import_promises8.default.mkdir(dest, { recursive: true });
|
|
66636
66583
|
continue;
|
|
66637
66584
|
}
|
|
66638
|
-
await
|
|
66585
|
+
await import_promises8.default.mkdir(import_node_path48.default.dirname(dest), { recursive: true });
|
|
66639
66586
|
const content = await entry.async("nodebuffer");
|
|
66640
|
-
await
|
|
66587
|
+
await import_promises8.default.writeFile(dest, content);
|
|
66641
66588
|
}
|
|
66642
|
-
await
|
|
66643
|
-
await
|
|
66589
|
+
await import_promises8.default.mkdir(root, { recursive: true });
|
|
66590
|
+
await import_promises8.default.rename(stage, destDir);
|
|
66644
66591
|
return { extId: manifest.id };
|
|
66645
66592
|
} catch (e) {
|
|
66646
|
-
await
|
|
66593
|
+
await import_promises8.default.rm(stage, { recursive: true, force: true }).catch(() => {
|
|
66647
66594
|
});
|
|
66648
66595
|
throw e;
|
|
66649
66596
|
}
|
|
@@ -66689,7 +66636,7 @@ var SHARE_UI_ASSET_MIME = {
|
|
|
66689
66636
|
".wasm": "application/wasm"
|
|
66690
66637
|
};
|
|
66691
66638
|
function shareUiAssetMime(filePath) {
|
|
66692
|
-
const ext =
|
|
66639
|
+
const ext = import_node_path49.default.extname(filePath).toLowerCase();
|
|
66693
66640
|
return SHARE_UI_ASSET_MIME[ext] ?? lookupMime(filePath);
|
|
66694
66641
|
}
|
|
66695
66642
|
var AUTHED_RPC_ROUTE_PREFIX = "/rpc/";
|
|
@@ -66788,7 +66735,7 @@ function isValidUploadFileName(fileName) {
|
|
|
66788
66735
|
if (fileName === "." || fileName === "..") return false;
|
|
66789
66736
|
if (fileName.startsWith(".")) return false;
|
|
66790
66737
|
if (fileName.includes("/") || fileName.includes("\\")) return false;
|
|
66791
|
-
return fileName ===
|
|
66738
|
+
return fileName === import_node_path49.default.basename(fileName);
|
|
66792
66739
|
}
|
|
66793
66740
|
function createHttpRouter(deps) {
|
|
66794
66741
|
return async (req, res) => {
|
|
@@ -66872,7 +66819,7 @@ function createHttpRouter(deps) {
|
|
|
66872
66819
|
}
|
|
66873
66820
|
let buf;
|
|
66874
66821
|
try {
|
|
66875
|
-
buf = await
|
|
66822
|
+
buf = await import_node_fs44.default.promises.readFile(abs);
|
|
66876
66823
|
} catch {
|
|
66877
66824
|
sendJson(res, 404, { code: "NOT_FOUND", message: "asset not found" });
|
|
66878
66825
|
return true;
|
|
@@ -67011,7 +66958,7 @@ function createHttpRouter(deps) {
|
|
|
67011
66958
|
sendHtml(res, statusByCode[r2.code], loader.renderErrorHtml(r2.code, msgByCode[r2.code]));
|
|
67012
66959
|
return true;
|
|
67013
66960
|
}
|
|
67014
|
-
sendHtml(res, 200, loader.renderViewerHtml(
|
|
66961
|
+
sendHtml(res, 200, loader.renderViewerHtml(import_node_path49.default.basename(r2.absPath)));
|
|
67015
66962
|
return true;
|
|
67016
66963
|
}
|
|
67017
66964
|
const ctx = deps.authResolver.resolveFromHeader(
|
|
@@ -67132,7 +67079,7 @@ function createHttpRouter(deps) {
|
|
|
67132
67079
|
return true;
|
|
67133
67080
|
}
|
|
67134
67081
|
let absPath;
|
|
67135
|
-
if (
|
|
67082
|
+
if (import_node_path49.default.isAbsolute(pathParam)) {
|
|
67136
67083
|
absPath = pathParam;
|
|
67137
67084
|
} else if (deps.sessionStore) {
|
|
67138
67085
|
const file = deps.sessionStore.read(sid);
|
|
@@ -67140,7 +67087,7 @@ function createHttpRouter(deps) {
|
|
|
67140
67087
|
sendJson(res, 404, { code: "NOT_FOUND", message: `session ${sid} not found` });
|
|
67141
67088
|
return true;
|
|
67142
67089
|
}
|
|
67143
|
-
absPath =
|
|
67090
|
+
absPath = import_node_path49.default.join(file.cwd, pathParam);
|
|
67144
67091
|
} else {
|
|
67145
67092
|
sendJson(res, 501, withCtx(ctx, { code: "NOT_IMPLEMENTED", message: "sessionStore not wired" }));
|
|
67146
67093
|
return true;
|
|
@@ -67224,7 +67171,7 @@ function withCtx(ctx, body) {
|
|
|
67224
67171
|
function streamFile(res, absPath, logger) {
|
|
67225
67172
|
let stat;
|
|
67226
67173
|
try {
|
|
67227
|
-
stat =
|
|
67174
|
+
stat = import_node_fs44.default.statSync(absPath);
|
|
67228
67175
|
} catch (err) {
|
|
67229
67176
|
const code = err?.code;
|
|
67230
67177
|
if (code === "ENOENT") {
|
|
@@ -67239,7 +67186,7 @@ function streamFile(res, absPath, logger) {
|
|
|
67239
67186
|
return;
|
|
67240
67187
|
}
|
|
67241
67188
|
const mime = lookupMime(absPath);
|
|
67242
|
-
const basename2 =
|
|
67189
|
+
const basename2 = import_node_path49.default.basename(absPath);
|
|
67243
67190
|
res.writeHead(200, {
|
|
67244
67191
|
"Content-Type": mime,
|
|
67245
67192
|
"Content-Length": String(stat.size),
|
|
@@ -67247,7 +67194,7 @@ function streamFile(res, absPath, logger) {
|
|
|
67247
67194
|
// 防止浏览器把任意 mime 当 html 渲染
|
|
67248
67195
|
"X-Content-Type-Options": "nosniff"
|
|
67249
67196
|
});
|
|
67250
|
-
const stream =
|
|
67197
|
+
const stream = import_node_fs44.default.createReadStream(absPath);
|
|
67251
67198
|
stream.on("error", (err) => {
|
|
67252
67199
|
logger?.warn("streamFile read error", { absPath, err: err.message });
|
|
67253
67200
|
res.destroy();
|
|
@@ -67256,8 +67203,8 @@ function streamFile(res, absPath, logger) {
|
|
|
67256
67203
|
}
|
|
67257
67204
|
|
|
67258
67205
|
// src/attachment/gc.ts
|
|
67259
|
-
var
|
|
67260
|
-
var
|
|
67206
|
+
var import_node_fs45 = __toESM(require("fs"), 1);
|
|
67207
|
+
var import_node_path50 = __toESM(require("path"), 1);
|
|
67261
67208
|
var DEFAULT_TTL_MS = 30 * 24 * 3600 * 1e3;
|
|
67262
67209
|
function runAttachmentGc(args) {
|
|
67263
67210
|
const now = (args.now ?? Date.now)();
|
|
@@ -67266,12 +67213,12 @@ function runAttachmentGc(args) {
|
|
|
67266
67213
|
for (const { scope, sessionId } of args.sessionScopes) {
|
|
67267
67214
|
for (const entry of args.groupFileStore.list(scope, sessionId)) {
|
|
67268
67215
|
if (entry.stale) continue;
|
|
67269
|
-
if (
|
|
67216
|
+
if (import_node_path50.default.isAbsolute(entry.relPath)) liveAbs.add(entry.relPath);
|
|
67270
67217
|
}
|
|
67271
67218
|
}
|
|
67272
67219
|
const visited = /* @__PURE__ */ new Set();
|
|
67273
67220
|
for (const { scope, sessionId } of args.sessionScopes) {
|
|
67274
|
-
const legacyDir = args.getSessionCwd?.(sessionId) ??
|
|
67221
|
+
const legacyDir = args.getSessionCwd?.(sessionId) ?? import_node_path50.default.join(
|
|
67275
67222
|
args.dataDir,
|
|
67276
67223
|
"sessions",
|
|
67277
67224
|
...scopeSubPath(scope).map(safeFileName),
|
|
@@ -67284,28 +67231,28 @@ function runAttachmentGc(args) {
|
|
|
67284
67231
|
return true;
|
|
67285
67232
|
});
|
|
67286
67233
|
for (const rootDir of roots) {
|
|
67287
|
-
const attRoot =
|
|
67234
|
+
const attRoot = import_node_path50.default.join(rootDir, ".attachments");
|
|
67288
67235
|
let hashDirs;
|
|
67289
67236
|
try {
|
|
67290
|
-
hashDirs =
|
|
67237
|
+
hashDirs = import_node_fs45.default.readdirSync(attRoot);
|
|
67291
67238
|
} catch (err) {
|
|
67292
67239
|
if (err.code === "ENOENT") continue;
|
|
67293
67240
|
args.logger?.warn("attachment gc: readdir failed", { attRoot, err: err.message });
|
|
67294
67241
|
continue;
|
|
67295
67242
|
}
|
|
67296
67243
|
for (const hashDir of hashDirs) {
|
|
67297
|
-
const hashDirAbs =
|
|
67244
|
+
const hashDirAbs = import_node_path50.default.join(attRoot, hashDir);
|
|
67298
67245
|
let files;
|
|
67299
67246
|
try {
|
|
67300
|
-
files =
|
|
67247
|
+
files = import_node_fs45.default.readdirSync(hashDirAbs);
|
|
67301
67248
|
} catch {
|
|
67302
67249
|
continue;
|
|
67303
67250
|
}
|
|
67304
67251
|
for (const name of files) {
|
|
67305
|
-
const file =
|
|
67252
|
+
const file = import_node_path50.default.join(hashDirAbs, name);
|
|
67306
67253
|
let stat;
|
|
67307
67254
|
try {
|
|
67308
|
-
stat =
|
|
67255
|
+
stat = import_node_fs45.default.statSync(file);
|
|
67309
67256
|
} catch {
|
|
67310
67257
|
continue;
|
|
67311
67258
|
}
|
|
@@ -67314,18 +67261,18 @@ function runAttachmentGc(args) {
|
|
|
67314
67261
|
if (age < ttlMs) continue;
|
|
67315
67262
|
if (liveAbs.has(file)) continue;
|
|
67316
67263
|
try {
|
|
67317
|
-
|
|
67264
|
+
import_node_fs45.default.unlinkSync(file);
|
|
67318
67265
|
} catch (err) {
|
|
67319
67266
|
args.logger?.warn("attachment gc: unlink failed", { file, err: err.message });
|
|
67320
67267
|
}
|
|
67321
67268
|
}
|
|
67322
67269
|
try {
|
|
67323
|
-
if (
|
|
67270
|
+
if (import_node_fs45.default.readdirSync(hashDirAbs).length === 0) import_node_fs45.default.rmdirSync(hashDirAbs);
|
|
67324
67271
|
} catch {
|
|
67325
67272
|
}
|
|
67326
67273
|
}
|
|
67327
67274
|
try {
|
|
67328
|
-
if (
|
|
67275
|
+
if (import_node_fs45.default.readdirSync(attRoot).length === 0) import_node_fs45.default.rmdirSync(attRoot);
|
|
67329
67276
|
} catch {
|
|
67330
67277
|
}
|
|
67331
67278
|
}
|
|
@@ -67333,9 +67280,9 @@ function runAttachmentGc(args) {
|
|
|
67333
67280
|
}
|
|
67334
67281
|
|
|
67335
67282
|
// src/attachment/group.ts
|
|
67336
|
-
var
|
|
67337
|
-
var
|
|
67338
|
-
var
|
|
67283
|
+
var import_node_fs46 = __toESM(require("fs"), 1);
|
|
67284
|
+
var import_node_path51 = __toESM(require("path"), 1);
|
|
67285
|
+
var import_node_crypto14 = __toESM(require("crypto"), 1);
|
|
67339
67286
|
init_protocol();
|
|
67340
67287
|
var GroupFileStore = class {
|
|
67341
67288
|
dataDir;
|
|
@@ -67346,11 +67293,11 @@ var GroupFileStore = class {
|
|
|
67346
67293
|
this.logger = opts.logger;
|
|
67347
67294
|
}
|
|
67348
67295
|
rootForScope(scope) {
|
|
67349
|
-
return
|
|
67296
|
+
return import_node_path51.default.join(this.dataDir, "sessions", ...scopeSubPath(scope).map(safeFileName));
|
|
67350
67297
|
}
|
|
67351
67298
|
/** 与 SessionStore.filePath 平级,扩展名 .group-files.json */
|
|
67352
67299
|
filePath(scope, sessionId) {
|
|
67353
|
-
return
|
|
67300
|
+
return import_node_path51.default.join(this.rootForScope(scope), `${safeFileName(sessionId)}.group-files.json`);
|
|
67354
67301
|
}
|
|
67355
67302
|
cacheKey(scope, sessionId) {
|
|
67356
67303
|
return scope.kind === "default" ? `default::${sessionId}` : `persona:${scope.personaId}:${scope.mode}::${sessionId}`;
|
|
@@ -67359,7 +67306,7 @@ var GroupFileStore = class {
|
|
|
67359
67306
|
readFile(scope, sessionId) {
|
|
67360
67307
|
const file = this.filePath(scope, sessionId);
|
|
67361
67308
|
try {
|
|
67362
|
-
const raw =
|
|
67309
|
+
const raw = import_node_fs46.default.readFileSync(file, "utf8");
|
|
67363
67310
|
const parsed = JSON.parse(raw);
|
|
67364
67311
|
if (!Array.isArray(parsed)) {
|
|
67365
67312
|
this.logger?.warn("GroupFileStore.readFile: not an array; resetting session entries", {
|
|
@@ -67385,10 +67332,10 @@ var GroupFileStore = class {
|
|
|
67385
67332
|
}
|
|
67386
67333
|
writeFile(scope, sessionId, entries) {
|
|
67387
67334
|
const file = this.filePath(scope, sessionId);
|
|
67388
|
-
|
|
67335
|
+
import_node_fs46.default.mkdirSync(import_node_path51.default.dirname(file), { recursive: true });
|
|
67389
67336
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
67390
|
-
|
|
67391
|
-
|
|
67337
|
+
import_node_fs46.default.writeFileSync(tmp, JSON.stringify(entries, null, 2), { mode: 384 });
|
|
67338
|
+
import_node_fs46.default.renameSync(tmp, file);
|
|
67392
67339
|
}
|
|
67393
67340
|
/** 拉一份当前 session 的清单。读盘 → cache;之后调用复用 cache */
|
|
67394
67341
|
list(scope, sessionId) {
|
|
@@ -67424,7 +67371,7 @@ var GroupFileStore = class {
|
|
|
67424
67371
|
entries[idx] = next;
|
|
67425
67372
|
} else {
|
|
67426
67373
|
next = {
|
|
67427
|
-
id: `gf-${
|
|
67374
|
+
id: `gf-${import_node_crypto14.default.randomBytes(6).toString("base64url")}`,
|
|
67428
67375
|
relPath: input.relPath,
|
|
67429
67376
|
from: input.from,
|
|
67430
67377
|
label: input.label,
|
|
@@ -67480,7 +67427,7 @@ var GroupFileStore = class {
|
|
|
67480
67427
|
*/
|
|
67481
67428
|
deleteSession(scope, sessionId) {
|
|
67482
67429
|
try {
|
|
67483
|
-
|
|
67430
|
+
import_node_fs46.default.unlinkSync(this.filePath(scope, sessionId));
|
|
67484
67431
|
} catch (err) {
|
|
67485
67432
|
if (err?.code !== "ENOENT") throw err;
|
|
67486
67433
|
}
|
|
@@ -67493,7 +67440,7 @@ var GroupFileStore = class {
|
|
|
67493
67440
|
* 不在 persona 目录里(见文件头的路径约定)。没树的 persona 是 noop。
|
|
67494
67441
|
*/
|
|
67495
67442
|
deletePersona(personaId2) {
|
|
67496
|
-
|
|
67443
|
+
import_node_fs46.default.rmSync(import_node_path51.default.join(this.dataDir, "sessions", safeFileName(personaId2)), { recursive: true, force: true });
|
|
67497
67444
|
const prefix = `persona:${personaId2}:`;
|
|
67498
67445
|
for (const key of this.cache.keys()) {
|
|
67499
67446
|
if (key.startsWith(prefix)) this.cache.delete(key);
|
|
@@ -67502,10 +67449,10 @@ var GroupFileStore = class {
|
|
|
67502
67449
|
};
|
|
67503
67450
|
|
|
67504
67451
|
// src/discovery/state-file.ts
|
|
67505
|
-
var
|
|
67506
|
-
var
|
|
67452
|
+
var import_node_fs47 = __toESM(require("fs"), 1);
|
|
67453
|
+
var import_node_path52 = __toESM(require("path"), 1);
|
|
67507
67454
|
function defaultStateFilePath(dataDir) {
|
|
67508
|
-
return
|
|
67455
|
+
return import_node_path52.default.join(dataDir, "state.json");
|
|
67509
67456
|
}
|
|
67510
67457
|
function isPidAlive(pid) {
|
|
67511
67458
|
if (!Number.isFinite(pid) || pid <= 0) return false;
|
|
@@ -67527,7 +67474,7 @@ var StateFileManager = class {
|
|
|
67527
67474
|
}
|
|
67528
67475
|
read() {
|
|
67529
67476
|
try {
|
|
67530
|
-
const raw =
|
|
67477
|
+
const raw = import_node_fs47.default.readFileSync(this.file, "utf8");
|
|
67531
67478
|
const parsed = JSON.parse(raw);
|
|
67532
67479
|
return parsed;
|
|
67533
67480
|
} catch {
|
|
@@ -67541,20 +67488,20 @@ var StateFileManager = class {
|
|
|
67541
67488
|
return { status: "stale", existing };
|
|
67542
67489
|
}
|
|
67543
67490
|
write(state) {
|
|
67544
|
-
|
|
67491
|
+
import_node_fs47.default.mkdirSync(import_node_path52.default.dirname(this.file), { recursive: true });
|
|
67545
67492
|
const tmp = `${this.file}.tmp.${process.pid}.${Date.now()}`;
|
|
67546
|
-
|
|
67547
|
-
|
|
67493
|
+
import_node_fs47.default.writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 384 });
|
|
67494
|
+
import_node_fs47.default.renameSync(tmp, this.file);
|
|
67548
67495
|
if (process.platform !== "win32") {
|
|
67549
67496
|
try {
|
|
67550
|
-
|
|
67497
|
+
import_node_fs47.default.chmodSync(this.file, 384);
|
|
67551
67498
|
} catch {
|
|
67552
67499
|
}
|
|
67553
67500
|
}
|
|
67554
67501
|
}
|
|
67555
67502
|
delete() {
|
|
67556
67503
|
try {
|
|
67557
|
-
|
|
67504
|
+
import_node_fs47.default.unlinkSync(this.file);
|
|
67558
67505
|
} catch {
|
|
67559
67506
|
}
|
|
67560
67507
|
}
|
|
@@ -67568,14 +67515,14 @@ function readSpawnedByDesktopFromEnv(env = process.env) {
|
|
|
67568
67515
|
}
|
|
67569
67516
|
|
|
67570
67517
|
// src/tunnel/tunnel-manager.ts
|
|
67571
|
-
var
|
|
67572
|
-
var
|
|
67573
|
-
var
|
|
67518
|
+
var import_node_fs51 = __toESM(require("fs"), 1);
|
|
67519
|
+
var import_node_path56 = __toESM(require("path"), 1);
|
|
67520
|
+
var import_node_crypto15 = __toESM(require("crypto"), 1);
|
|
67574
67521
|
var import_node_child_process16 = require("child_process");
|
|
67575
67522
|
|
|
67576
67523
|
// src/tunnel/tunnel-store.ts
|
|
67577
|
-
var
|
|
67578
|
-
var
|
|
67524
|
+
var import_node_fs48 = __toESM(require("fs"), 1);
|
|
67525
|
+
var import_node_path53 = __toESM(require("path"), 1);
|
|
67579
67526
|
var TunnelStore = class {
|
|
67580
67527
|
constructor(filePath) {
|
|
67581
67528
|
this.filePath = filePath;
|
|
@@ -67583,7 +67530,7 @@ var TunnelStore = class {
|
|
|
67583
67530
|
filePath;
|
|
67584
67531
|
async get() {
|
|
67585
67532
|
try {
|
|
67586
|
-
const raw = await
|
|
67533
|
+
const raw = await import_node_fs48.default.promises.readFile(this.filePath, "utf8");
|
|
67587
67534
|
const obj = JSON.parse(raw);
|
|
67588
67535
|
if (!isPersistedTunnel(obj)) return null;
|
|
67589
67536
|
return obj;
|
|
@@ -67594,22 +67541,22 @@ var TunnelStore = class {
|
|
|
67594
67541
|
}
|
|
67595
67542
|
}
|
|
67596
67543
|
async set(v3) {
|
|
67597
|
-
const dir =
|
|
67598
|
-
await
|
|
67544
|
+
const dir = import_node_path53.default.dirname(this.filePath);
|
|
67545
|
+
await import_node_fs48.default.promises.mkdir(dir, { recursive: true });
|
|
67599
67546
|
const data = JSON.stringify(v3, null, 2);
|
|
67600
67547
|
const tmp = `${this.filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
67601
|
-
await
|
|
67548
|
+
await import_node_fs48.default.promises.writeFile(tmp, data, { mode: 384 });
|
|
67602
67549
|
if (process.platform !== "win32") {
|
|
67603
67550
|
try {
|
|
67604
|
-
await
|
|
67551
|
+
await import_node_fs48.default.promises.chmod(tmp, 384);
|
|
67605
67552
|
} catch {
|
|
67606
67553
|
}
|
|
67607
67554
|
}
|
|
67608
|
-
await
|
|
67555
|
+
await import_node_fs48.default.promises.rename(tmp, this.filePath);
|
|
67609
67556
|
}
|
|
67610
67557
|
async clear() {
|
|
67611
67558
|
try {
|
|
67612
|
-
await
|
|
67559
|
+
await import_node_fs48.default.promises.unlink(this.filePath);
|
|
67613
67560
|
} catch (err) {
|
|
67614
67561
|
const code = err?.code;
|
|
67615
67562
|
if (code !== "ENOENT") throw err;
|
|
@@ -67704,12 +67651,12 @@ function escape2(v3) {
|
|
|
67704
67651
|
}
|
|
67705
67652
|
|
|
67706
67653
|
// src/tunnel/frpc-binary.ts
|
|
67707
|
-
var
|
|
67708
|
-
var
|
|
67709
|
-
var
|
|
67654
|
+
var import_node_fs49 = __toESM(require("fs"), 1);
|
|
67655
|
+
var import_node_os18 = __toESM(require("os"), 1);
|
|
67656
|
+
var import_node_path54 = __toESM(require("path"), 1);
|
|
67710
67657
|
var import_node_child_process14 = require("child_process");
|
|
67711
|
-
var
|
|
67712
|
-
var
|
|
67658
|
+
var import_node_stream3 = require("stream");
|
|
67659
|
+
var import_promises9 = require("stream/promises");
|
|
67713
67660
|
var FRPC_VERSION = "0.68.0";
|
|
67714
67661
|
var UnsupportedPlatformError = class extends Error {
|
|
67715
67662
|
constructor(platform, arch) {
|
|
@@ -67738,20 +67685,20 @@ function frpcDownloadUrl(version2, p3) {
|
|
|
67738
67685
|
}
|
|
67739
67686
|
async function ensureFrpcBinary(opts) {
|
|
67740
67687
|
if (opts.override) {
|
|
67741
|
-
if (!
|
|
67688
|
+
if (!import_node_fs49.default.existsSync(opts.override)) {
|
|
67742
67689
|
throw new Error(`frpc binary not found at override path: ${opts.override}`);
|
|
67743
67690
|
}
|
|
67744
67691
|
return opts.override;
|
|
67745
67692
|
}
|
|
67746
67693
|
const version2 = opts.version ?? FRPC_VERSION;
|
|
67747
67694
|
const platform = opts.platform ?? detectPlatform();
|
|
67748
|
-
const binDir =
|
|
67749
|
-
|
|
67695
|
+
const binDir = import_node_path54.default.join(opts.dataDir, "bin");
|
|
67696
|
+
import_node_fs49.default.mkdirSync(binDir, { recursive: true });
|
|
67750
67697
|
cleanupStaleArtifacts(binDir);
|
|
67751
|
-
const stableBin =
|
|
67752
|
-
if (
|
|
67698
|
+
const stableBin = import_node_path54.default.join(binDir, "frpc");
|
|
67699
|
+
if (import_node_fs49.default.existsSync(stableBin)) return stableBin;
|
|
67753
67700
|
const partialBin = `${stableBin}.partial`;
|
|
67754
|
-
const tarballPath =
|
|
67701
|
+
const tarballPath = import_node_path54.default.join(binDir, `frp_${version2}_${platform.os}_${platform.arch}.tar.gz.partial`);
|
|
67755
67702
|
try {
|
|
67756
67703
|
const url = frpcDownloadUrl(version2, platform);
|
|
67757
67704
|
await downloadToFile(url, tarballPath, opts.fetchImpl);
|
|
@@ -67760,8 +67707,8 @@ async function ensureFrpcBinary(opts) {
|
|
|
67760
67707
|
} else {
|
|
67761
67708
|
await extractFrpcFromTarball(tarballPath, binDir, version2, platform, partialBin);
|
|
67762
67709
|
}
|
|
67763
|
-
|
|
67764
|
-
|
|
67710
|
+
import_node_fs49.default.chmodSync(partialBin, 493);
|
|
67711
|
+
import_node_fs49.default.renameSync(partialBin, stableBin);
|
|
67765
67712
|
} finally {
|
|
67766
67713
|
safeUnlink(tarballPath);
|
|
67767
67714
|
safeUnlink(partialBin);
|
|
@@ -67771,15 +67718,15 @@ async function ensureFrpcBinary(opts) {
|
|
|
67771
67718
|
function cleanupStaleArtifacts(binDir) {
|
|
67772
67719
|
let entries;
|
|
67773
67720
|
try {
|
|
67774
|
-
entries =
|
|
67721
|
+
entries = import_node_fs49.default.readdirSync(binDir);
|
|
67775
67722
|
} catch {
|
|
67776
67723
|
return;
|
|
67777
67724
|
}
|
|
67778
67725
|
for (const name of entries) {
|
|
67779
67726
|
if (name.endsWith(".partial") || name.startsWith("extract-")) {
|
|
67780
|
-
const full =
|
|
67727
|
+
const full = import_node_path54.default.join(binDir, name);
|
|
67781
67728
|
try {
|
|
67782
|
-
|
|
67729
|
+
import_node_fs49.default.rmSync(full, { recursive: true, force: true });
|
|
67783
67730
|
} catch {
|
|
67784
67731
|
}
|
|
67785
67732
|
}
|
|
@@ -67787,7 +67734,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
67787
67734
|
}
|
|
67788
67735
|
function safeUnlink(p3) {
|
|
67789
67736
|
try {
|
|
67790
|
-
|
|
67737
|
+
import_node_fs49.default.unlinkSync(p3);
|
|
67791
67738
|
} catch {
|
|
67792
67739
|
}
|
|
67793
67740
|
}
|
|
@@ -67798,13 +67745,13 @@ async function downloadToFile(url, dest, fetchImpl) {
|
|
|
67798
67745
|
if (!res.ok || !res.body) {
|
|
67799
67746
|
throw new Error(`download failed: ${res.status} ${res.statusText}`);
|
|
67800
67747
|
}
|
|
67801
|
-
const out =
|
|
67802
|
-
const nodeStream =
|
|
67803
|
-
await (0,
|
|
67748
|
+
const out = import_node_fs49.default.createWriteStream(dest);
|
|
67749
|
+
const nodeStream = import_node_stream3.Readable.fromWeb(res.body);
|
|
67750
|
+
await (0, import_promises9.pipeline)(nodeStream, out);
|
|
67804
67751
|
}
|
|
67805
67752
|
async function extractFrpcFromTarball(tarball, binDir, version2, platform, destBin) {
|
|
67806
|
-
const work =
|
|
67807
|
-
|
|
67753
|
+
const work = import_node_path54.default.join(binDir, `extract-${process.pid}-${Date.now()}`);
|
|
67754
|
+
import_node_fs49.default.mkdirSync(work, { recursive: true });
|
|
67808
67755
|
try {
|
|
67809
67756
|
await new Promise((resolve9, reject) => {
|
|
67810
67757
|
const proc = (0, import_node_child_process14.spawn)("tar", ["xzf", tarball, "-C", work], { stdio: "pipe" });
|
|
@@ -67812,32 +67759,32 @@ async function extractFrpcFromTarball(tarball, binDir, version2, platform, destB
|
|
|
67812
67759
|
proc.on("exit", (code) => code === 0 ? resolve9() : reject(new Error(`tar exited ${code}`)));
|
|
67813
67760
|
});
|
|
67814
67761
|
const dirName = `frp_${version2}_${platform.os}_${platform.arch}`;
|
|
67815
|
-
const src =
|
|
67816
|
-
if (!
|
|
67762
|
+
const src = import_node_path54.default.join(work, dirName, "frpc");
|
|
67763
|
+
if (!import_node_fs49.default.existsSync(src)) {
|
|
67817
67764
|
throw new Error(`frpc not found inside tarball at ${src}`);
|
|
67818
67765
|
}
|
|
67819
|
-
|
|
67766
|
+
import_node_fs49.default.copyFileSync(src, destBin);
|
|
67820
67767
|
} finally {
|
|
67821
|
-
|
|
67768
|
+
import_node_fs49.default.rmSync(work, { recursive: true, force: true });
|
|
67822
67769
|
}
|
|
67823
67770
|
}
|
|
67824
67771
|
|
|
67825
67772
|
// src/tunnel/frpc-process.ts
|
|
67826
|
-
var
|
|
67827
|
-
var
|
|
67773
|
+
var import_node_fs50 = __toESM(require("fs"), 1);
|
|
67774
|
+
var import_node_path55 = __toESM(require("path"), 1);
|
|
67828
67775
|
var import_node_child_process15 = require("child_process");
|
|
67829
67776
|
function frpcPidFilePath(dataDir) {
|
|
67830
|
-
return
|
|
67777
|
+
return import_node_path55.default.join(dataDir, "frpc.pid");
|
|
67831
67778
|
}
|
|
67832
67779
|
function writeFrpcPid(dataDir, pid) {
|
|
67833
67780
|
try {
|
|
67834
|
-
|
|
67781
|
+
import_node_fs50.default.writeFileSync(frpcPidFilePath(dataDir), String(pid), { mode: 384 });
|
|
67835
67782
|
} catch {
|
|
67836
67783
|
}
|
|
67837
67784
|
}
|
|
67838
67785
|
function clearFrpcPid(dataDir) {
|
|
67839
67786
|
try {
|
|
67840
|
-
|
|
67787
|
+
import_node_fs50.default.unlinkSync(frpcPidFilePath(dataDir));
|
|
67841
67788
|
} catch {
|
|
67842
67789
|
}
|
|
67843
67790
|
}
|
|
@@ -67853,7 +67800,7 @@ function defaultIsPidAlive(pid) {
|
|
|
67853
67800
|
}
|
|
67854
67801
|
function defaultReadPidFile(file) {
|
|
67855
67802
|
try {
|
|
67856
|
-
return
|
|
67803
|
+
return import_node_fs50.default.readFileSync(file, "utf8");
|
|
67857
67804
|
} catch {
|
|
67858
67805
|
return null;
|
|
67859
67806
|
}
|
|
@@ -67869,7 +67816,7 @@ function defaultSleep2(ms) {
|
|
|
67869
67816
|
}
|
|
67870
67817
|
async function killStaleFrpc(deps) {
|
|
67871
67818
|
const pidFile = frpcPidFilePath(deps.dataDir);
|
|
67872
|
-
const tomlPath =
|
|
67819
|
+
const tomlPath = import_node_path55.default.join(deps.dataDir, "frpc.toml");
|
|
67873
67820
|
const readPidFile = deps.readPidFileImpl ?? defaultReadPidFile;
|
|
67874
67821
|
const isAlive = deps.isPidAliveImpl ?? defaultIsPidAlive;
|
|
67875
67822
|
const killPid = deps.killPidImpl ?? defaultKillPid;
|
|
@@ -67893,7 +67840,7 @@ async function killStaleFrpc(deps) {
|
|
|
67893
67840
|
}
|
|
67894
67841
|
if (victims.size === 0) {
|
|
67895
67842
|
try {
|
|
67896
|
-
|
|
67843
|
+
import_node_fs50.default.unlinkSync(pidFile);
|
|
67897
67844
|
} catch {
|
|
67898
67845
|
}
|
|
67899
67846
|
return;
|
|
@@ -67904,7 +67851,7 @@ async function killStaleFrpc(deps) {
|
|
|
67904
67851
|
}
|
|
67905
67852
|
await sleep2(deps.reapWaitMs ?? 300);
|
|
67906
67853
|
try {
|
|
67907
|
-
|
|
67854
|
+
import_node_fs50.default.unlinkSync(pidFile);
|
|
67908
67855
|
} catch {
|
|
67909
67856
|
}
|
|
67910
67857
|
}
|
|
@@ -67941,7 +67888,7 @@ var DEFAULT_TUNNEL_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
|
67941
67888
|
var TunnelManager = class {
|
|
67942
67889
|
constructor(deps) {
|
|
67943
67890
|
this.deps = deps;
|
|
67944
|
-
this.store = deps.store ?? new TunnelStore(
|
|
67891
|
+
this.store = deps.store ?? new TunnelStore(import_node_path56.default.join(deps.dataDir, "tunnel.json"));
|
|
67945
67892
|
this.ttlMs = deps.ttlMs ?? DEFAULT_TUNNEL_TTL_MS;
|
|
67946
67893
|
this.startupTimeoutMs = deps.startupTimeoutMs ?? 15e3;
|
|
67947
67894
|
}
|
|
@@ -68068,8 +68015,8 @@ var TunnelManager = class {
|
|
|
68068
68015
|
dataDir: this.deps.dataDir,
|
|
68069
68016
|
override: this.deps.frpcBinaryOverride ?? void 0
|
|
68070
68017
|
});
|
|
68071
|
-
const tomlPath =
|
|
68072
|
-
const proxyName = `clawd-${t2.subdomain}-${localPort}-${
|
|
68018
|
+
const tomlPath = import_node_path56.default.join(this.deps.dataDir, "frpc.toml");
|
|
68019
|
+
const proxyName = `clawd-${t2.subdomain}-${localPort}-${import_node_crypto15.default.randomBytes(3).toString("hex")}`;
|
|
68073
68020
|
const toml = buildFrpcToml({
|
|
68074
68021
|
serverAddr: t2.frpsHost,
|
|
68075
68022
|
serverPort: t2.frpsPort,
|
|
@@ -68079,14 +68026,14 @@ var TunnelManager = class {
|
|
|
68079
68026
|
localPort,
|
|
68080
68027
|
logLevel: "info"
|
|
68081
68028
|
});
|
|
68082
|
-
await
|
|
68029
|
+
await import_node_fs51.default.promises.writeFile(tomlPath, toml, { mode: 384 });
|
|
68083
68030
|
const proc = (this.deps.spawnImpl ?? import_node_child_process16.spawn)(frpcBin, ["-c", tomlPath], {
|
|
68084
68031
|
stdio: ["ignore", "pipe", "pipe"]
|
|
68085
68032
|
});
|
|
68086
|
-
const logDir =
|
|
68087
|
-
|
|
68088
|
-
const logFilePath =
|
|
68089
|
-
const logStream =
|
|
68033
|
+
const logDir = import_node_path56.default.join(this.deps.dataDir, "log");
|
|
68034
|
+
import_node_fs51.default.mkdirSync(logDir, { recursive: true });
|
|
68035
|
+
const logFilePath = import_node_path56.default.join(logDir, "frpc.log");
|
|
68036
|
+
const logStream = import_node_fs51.default.createWriteStream(logFilePath, { flags: "a", mode: 384 });
|
|
68090
68037
|
logStream.on("error", () => {
|
|
68091
68038
|
});
|
|
68092
68039
|
const tee = (chunk) => {
|
|
@@ -68168,28 +68115,28 @@ async function waitForFrpcReady(proc, timeoutMs) {
|
|
|
68168
68115
|
}
|
|
68169
68116
|
|
|
68170
68117
|
// src/tunnel/device-key.ts
|
|
68171
|
-
var
|
|
68172
|
-
var
|
|
68173
|
-
var
|
|
68118
|
+
var import_node_os19 = __toESM(require("os"), 1);
|
|
68119
|
+
var import_node_path57 = __toESM(require("path"), 1);
|
|
68120
|
+
var import_node_crypto16 = __toESM(require("crypto"), 1);
|
|
68174
68121
|
var DERIVE_SALT = "clawd-tunnel-device-v1";
|
|
68175
68122
|
function deriveStableDeviceKey(opts = {}) {
|
|
68176
|
-
const hostname = opts.hostname ??
|
|
68177
|
-
const uid = opts.uid ?? (typeof
|
|
68178
|
-
const home = opts.home ??
|
|
68179
|
-
const defaultDataDir =
|
|
68180
|
-
const normalizedDataDir = opts.dataDir ?
|
|
68123
|
+
const hostname = opts.hostname ?? import_node_os19.default.hostname();
|
|
68124
|
+
const uid = opts.uid ?? (typeof import_node_os19.default.userInfo === "function" ? import_node_os19.default.userInfo().uid : 0);
|
|
68125
|
+
const home = opts.home ?? import_node_os19.default.homedir();
|
|
68126
|
+
const defaultDataDir = import_node_path57.default.resolve(import_node_path57.default.join(home, ".clawd"));
|
|
68127
|
+
const normalizedDataDir = opts.dataDir ? import_node_path57.default.resolve(opts.dataDir) : null;
|
|
68181
68128
|
const isDefaultDir = normalizedDataDir == null || normalizedDataDir === defaultDataDir;
|
|
68182
68129
|
const input = isDefaultDir ? `${hostname}::${uid}` : `${hostname}::${uid}::${normalizedDataDir}`;
|
|
68183
|
-
return
|
|
68130
|
+
return import_node_crypto16.default.createHmac("sha256", DERIVE_SALT).update(input).digest("hex").slice(0, 32);
|
|
68184
68131
|
}
|
|
68185
68132
|
|
|
68186
68133
|
// src/auth-store.ts
|
|
68187
|
-
var
|
|
68188
|
-
var
|
|
68189
|
-
var
|
|
68134
|
+
var import_node_fs52 = __toESM(require("fs"), 1);
|
|
68135
|
+
var import_node_path58 = __toESM(require("path"), 1);
|
|
68136
|
+
var import_node_crypto17 = __toESM(require("crypto"), 1);
|
|
68190
68137
|
var AUTH_FILE_NAME = "auth.json";
|
|
68191
68138
|
function authFilePath(dataDir) {
|
|
68192
|
-
return
|
|
68139
|
+
return import_node_path58.default.join(dataDir, AUTH_FILE_NAME);
|
|
68193
68140
|
}
|
|
68194
68141
|
function loadOrCreateAuthFile(opts) {
|
|
68195
68142
|
const file = authFilePath(opts.dataDir);
|
|
@@ -68223,14 +68170,14 @@ function loadOrCreateTunnelDeviceKey(opts) {
|
|
|
68223
68170
|
return tunnelDeviceKey;
|
|
68224
68171
|
}
|
|
68225
68172
|
function defaultGenerateToken() {
|
|
68226
|
-
return
|
|
68173
|
+
return import_node_crypto17.default.randomBytes(32).toString("base64url");
|
|
68227
68174
|
}
|
|
68228
68175
|
function defaultGenerateOwnerPrincipalId() {
|
|
68229
|
-
return `owner-${
|
|
68176
|
+
return `owner-${import_node_crypto17.default.randomUUID()}`;
|
|
68230
68177
|
}
|
|
68231
68178
|
function readAuthFile(file) {
|
|
68232
68179
|
try {
|
|
68233
|
-
const raw =
|
|
68180
|
+
const raw = import_node_fs52.default.readFileSync(file, "utf8");
|
|
68234
68181
|
const parsed = JSON.parse(raw);
|
|
68235
68182
|
if (typeof parsed?.token !== "string" || parsed.token.length === 0) {
|
|
68236
68183
|
return null;
|
|
@@ -68251,26 +68198,26 @@ function readAuthFile(file) {
|
|
|
68251
68198
|
}
|
|
68252
68199
|
}
|
|
68253
68200
|
function writeAuthFile(file, content) {
|
|
68254
|
-
|
|
68255
|
-
|
|
68201
|
+
import_node_fs52.default.mkdirSync(import_node_path58.default.dirname(file), { recursive: true });
|
|
68202
|
+
import_node_fs52.default.writeFileSync(file, JSON.stringify(content, null, 2), { mode: 384 });
|
|
68256
68203
|
try {
|
|
68257
|
-
|
|
68204
|
+
import_node_fs52.default.chmodSync(file, 384);
|
|
68258
68205
|
} catch {
|
|
68259
68206
|
}
|
|
68260
68207
|
}
|
|
68261
68208
|
|
|
68262
68209
|
// src/owner-profile.ts
|
|
68263
|
-
var
|
|
68264
|
-
var
|
|
68265
|
-
var
|
|
68210
|
+
var import_node_fs53 = __toESM(require("fs"), 1);
|
|
68211
|
+
var import_node_os20 = __toESM(require("os"), 1);
|
|
68212
|
+
var import_node_path59 = __toESM(require("path"), 1);
|
|
68266
68213
|
var PROFILE_FILENAME = "profile.json";
|
|
68267
68214
|
function profilePath(dataDir) {
|
|
68268
|
-
return
|
|
68215
|
+
return import_node_path59.default.join(dataDir, PROFILE_FILENAME);
|
|
68269
68216
|
}
|
|
68270
68217
|
function loadOwnerProfile(dataDir) {
|
|
68271
68218
|
let raw;
|
|
68272
68219
|
try {
|
|
68273
|
-
raw =
|
|
68220
|
+
raw = import_node_fs53.default.readFileSync(profilePath(dataDir), "utf8");
|
|
68274
68221
|
} catch {
|
|
68275
68222
|
return {};
|
|
68276
68223
|
}
|
|
@@ -68286,11 +68233,11 @@ function loadOwnerProfile(dataDir) {
|
|
|
68286
68233
|
}
|
|
68287
68234
|
function patchOwnerProfile(dataDir, patch) {
|
|
68288
68235
|
const merged = { ...loadOwnerProfile(dataDir), ...patch };
|
|
68289
|
-
|
|
68236
|
+
import_node_fs53.default.writeFileSync(profilePath(dataDir), JSON.stringify(merged, null, 2), { encoding: "utf8", mode: 384 });
|
|
68290
68237
|
return merged;
|
|
68291
68238
|
}
|
|
68292
68239
|
function loadOwnerDisplayName(dataDir) {
|
|
68293
|
-
const fallback =
|
|
68240
|
+
const fallback = import_node_os20.default.userInfo().username;
|
|
68294
68241
|
const displayName = loadOwnerProfile(dataDir).displayName;
|
|
68295
68242
|
if (typeof displayName !== "string" || displayName.length === 0) {
|
|
68296
68243
|
if (displayName !== void 0) {
|
|
@@ -68302,18 +68249,18 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
68302
68249
|
}
|
|
68303
68250
|
|
|
68304
68251
|
// src/feishu-auth/owner-identity-store.ts
|
|
68305
|
-
var
|
|
68306
|
-
var
|
|
68252
|
+
var import_node_fs54 = __toESM(require("fs"), 1);
|
|
68253
|
+
var import_node_path60 = __toESM(require("path"), 1);
|
|
68307
68254
|
var OWNER_IDENTITY_FILE_NAME = "owner-identity.json";
|
|
68308
68255
|
var OwnerIdentityStore = class {
|
|
68309
68256
|
file;
|
|
68310
68257
|
constructor(dataDir) {
|
|
68311
|
-
this.file =
|
|
68258
|
+
this.file = import_node_path60.default.join(dataDir, OWNER_IDENTITY_FILE_NAME);
|
|
68312
68259
|
}
|
|
68313
68260
|
read() {
|
|
68314
68261
|
let raw;
|
|
68315
68262
|
try {
|
|
68316
|
-
raw =
|
|
68263
|
+
raw = import_node_fs54.default.readFileSync(this.file, "utf8");
|
|
68317
68264
|
} catch {
|
|
68318
68265
|
return null;
|
|
68319
68266
|
}
|
|
@@ -68340,16 +68287,16 @@ var OwnerIdentityStore = class {
|
|
|
68340
68287
|
};
|
|
68341
68288
|
}
|
|
68342
68289
|
write(record4) {
|
|
68343
|
-
|
|
68344
|
-
|
|
68290
|
+
import_node_fs54.default.mkdirSync(import_node_path60.default.dirname(this.file), { recursive: true });
|
|
68291
|
+
import_node_fs54.default.writeFileSync(this.file, JSON.stringify(record4, null, 2), { mode: 384 });
|
|
68345
68292
|
try {
|
|
68346
|
-
|
|
68293
|
+
import_node_fs54.default.chmodSync(this.file, 384);
|
|
68347
68294
|
} catch {
|
|
68348
68295
|
}
|
|
68349
68296
|
}
|
|
68350
68297
|
clear() {
|
|
68351
68298
|
try {
|
|
68352
|
-
|
|
68299
|
+
import_node_fs54.default.unlinkSync(this.file);
|
|
68353
68300
|
} catch (err) {
|
|
68354
68301
|
const code = err?.code;
|
|
68355
68302
|
if (code !== "ENOENT") throw err;
|
|
@@ -68358,7 +68305,7 @@ var OwnerIdentityStore = class {
|
|
|
68358
68305
|
};
|
|
68359
68306
|
|
|
68360
68307
|
// src/feishu-auth/login-flow.ts
|
|
68361
|
-
var
|
|
68308
|
+
var import_node_crypto18 = __toESM(require("crypto"), 1);
|
|
68362
68309
|
var STATE_TTL_MS = 5 * 60 * 1e3;
|
|
68363
68310
|
var LoginFlow = class {
|
|
68364
68311
|
constructor(deps) {
|
|
@@ -68367,7 +68314,7 @@ var LoginFlow = class {
|
|
|
68367
68314
|
deps;
|
|
68368
68315
|
pendingStates = /* @__PURE__ */ new Map();
|
|
68369
68316
|
start() {
|
|
68370
|
-
const state =
|
|
68317
|
+
const state = import_node_crypto18.default.randomBytes(16).toString("base64url");
|
|
68371
68318
|
const now = (this.deps.now ?? Date.now)();
|
|
68372
68319
|
this.pendingStates.set(state, now);
|
|
68373
68320
|
this.gcExpired(now);
|
|
@@ -68845,8 +68792,8 @@ function verifyConnectToken(args) {
|
|
|
68845
68792
|
}
|
|
68846
68793
|
|
|
68847
68794
|
// src/feishu-auth/server-key.ts
|
|
68848
|
-
var
|
|
68849
|
-
var
|
|
68795
|
+
var fs71 = __toESM(require("fs"), 1);
|
|
68796
|
+
var path73 = __toESM(require("path"), 1);
|
|
68850
68797
|
var FILE_NAME2 = "server-signing-key.json";
|
|
68851
68798
|
var ServerKeyStore = class {
|
|
68852
68799
|
constructor(dataDir) {
|
|
@@ -68854,12 +68801,12 @@ var ServerKeyStore = class {
|
|
|
68854
68801
|
}
|
|
68855
68802
|
dataDir;
|
|
68856
68803
|
filePath() {
|
|
68857
|
-
return
|
|
68804
|
+
return path73.join(this.dataDir, FILE_NAME2);
|
|
68858
68805
|
}
|
|
68859
68806
|
/** 读缓存的公钥;无缓存 / 损坏 → null(调用方决定是否触发拉取) */
|
|
68860
68807
|
read() {
|
|
68861
68808
|
try {
|
|
68862
|
-
const raw =
|
|
68809
|
+
const raw = fs71.readFileSync(this.filePath(), "utf8");
|
|
68863
68810
|
const parsed = JSON.parse(raw);
|
|
68864
68811
|
if (typeof parsed.publicKeyPem === "string" && parsed.publicKeyPem.includes("PUBLIC KEY")) {
|
|
68865
68812
|
return parsed.publicKeyPem;
|
|
@@ -68874,12 +68821,12 @@ var ServerKeyStore = class {
|
|
|
68874
68821
|
publicKeyPem,
|
|
68875
68822
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
68876
68823
|
};
|
|
68877
|
-
|
|
68878
|
-
|
|
68824
|
+
fs71.mkdirSync(this.dataDir, { recursive: true });
|
|
68825
|
+
fs71.writeFileSync(this.filePath(), JSON.stringify(content, null, 2), { mode: 384 });
|
|
68879
68826
|
}
|
|
68880
68827
|
clear() {
|
|
68881
68828
|
try {
|
|
68882
|
-
|
|
68829
|
+
fs71.unlinkSync(this.filePath());
|
|
68883
68830
|
} catch {
|
|
68884
68831
|
}
|
|
68885
68832
|
}
|
|
@@ -68889,19 +68836,19 @@ var ServerKeyStore = class {
|
|
|
68889
68836
|
init_protocol();
|
|
68890
68837
|
|
|
68891
68838
|
// src/handlers/index.ts
|
|
68892
|
-
var
|
|
68839
|
+
var import_node_path74 = __toESM(require("path"), 1);
|
|
68893
68840
|
|
|
68894
68841
|
// src/handlers/session.ts
|
|
68895
68842
|
init_protocol();
|
|
68896
68843
|
|
|
68897
68844
|
// src/session/fork.ts
|
|
68898
|
-
var
|
|
68899
|
-
var
|
|
68900
|
-
var
|
|
68901
|
-
var
|
|
68845
|
+
var import_node_fs55 = __toESM(require("fs"), 1);
|
|
68846
|
+
var import_node_os21 = __toESM(require("os"), 1);
|
|
68847
|
+
var import_node_path61 = __toESM(require("path"), 1);
|
|
68848
|
+
var import_node_crypto19 = require("crypto");
|
|
68902
68849
|
init_claude_history();
|
|
68903
68850
|
function readJsonlEntries(file) {
|
|
68904
|
-
const raw =
|
|
68851
|
+
const raw = import_node_fs55.default.readFileSync(file, "utf8");
|
|
68905
68852
|
const out = [];
|
|
68906
68853
|
for (const line of raw.split("\n")) {
|
|
68907
68854
|
const t2 = line.trim();
|
|
@@ -68914,19 +68861,19 @@ function readJsonlEntries(file) {
|
|
|
68914
68861
|
return out;
|
|
68915
68862
|
}
|
|
68916
68863
|
function forkSession(input) {
|
|
68917
|
-
const baseDir = input.baseDir ??
|
|
68918
|
-
let projectDir =
|
|
68919
|
-
let sourceFile =
|
|
68920
|
-
if (!
|
|
68864
|
+
const baseDir = input.baseDir ?? import_node_path61.default.join(import_node_os21.default.homedir(), ".claude");
|
|
68865
|
+
let projectDir = import_node_path61.default.join(baseDir, "projects", cwdToHashDir(input.cwd));
|
|
68866
|
+
let sourceFile = import_node_path61.default.join(projectDir, `${input.toolSessionId}.jsonl`);
|
|
68867
|
+
if (!import_node_fs55.default.existsSync(sourceFile)) {
|
|
68921
68868
|
const found = findTranscriptByToolSessionId(
|
|
68922
|
-
|
|
68869
|
+
import_node_path61.default.join(baseDir, "projects"),
|
|
68923
68870
|
input.toolSessionId
|
|
68924
68871
|
);
|
|
68925
68872
|
if (!found) {
|
|
68926
68873
|
throw new Error(`fork: source transcript not found: ${sourceFile}`);
|
|
68927
68874
|
}
|
|
68928
68875
|
sourceFile = found;
|
|
68929
|
-
projectDir =
|
|
68876
|
+
projectDir = import_node_path61.default.dirname(found);
|
|
68930
68877
|
}
|
|
68931
68878
|
const entries = readJsonlEntries(sourceFile);
|
|
68932
68879
|
const mainEntries = entries.filter((e) => e.isSidechain !== true);
|
|
@@ -68935,7 +68882,7 @@ function forkSession(input) {
|
|
|
68935
68882
|
throw new Error(`fork: messageUuid not found in transcript: ${input.messageUuid}`);
|
|
68936
68883
|
}
|
|
68937
68884
|
const sliced = mainEntries.slice(0, targetIdx + 1);
|
|
68938
|
-
const forkedToolSessionId = (0,
|
|
68885
|
+
const forkedToolSessionId = (0, import_node_crypto19.randomUUID)();
|
|
68939
68886
|
let parentUuid = null;
|
|
68940
68887
|
const forkedLines = [];
|
|
68941
68888
|
for (const entry of sliced) {
|
|
@@ -68955,27 +68902,27 @@ function forkSession(input) {
|
|
|
68955
68902
|
}
|
|
68956
68903
|
forkedLines.push(JSON.stringify(forked));
|
|
68957
68904
|
}
|
|
68958
|
-
const outDir = input.targetCwd ?
|
|
68959
|
-
const forkedFilePath =
|
|
68960
|
-
|
|
68961
|
-
|
|
68905
|
+
const outDir = input.targetCwd ? import_node_path61.default.join(baseDir, "projects", cwdToHashDir(input.targetCwd)) : projectDir;
|
|
68906
|
+
const forkedFilePath = import_node_path61.default.join(outDir, `${forkedToolSessionId}.jsonl`);
|
|
68907
|
+
import_node_fs55.default.mkdirSync(outDir, { recursive: true });
|
|
68908
|
+
import_node_fs55.default.writeFileSync(forkedFilePath, forkedLines.join("\n") + "\n", { mode: 384 });
|
|
68962
68909
|
return { forkedToolSessionId, forkedFilePath };
|
|
68963
68910
|
}
|
|
68964
68911
|
|
|
68965
68912
|
// src/session/external-scan.ts
|
|
68966
|
-
var
|
|
68967
|
-
var
|
|
68968
|
-
var
|
|
68969
|
-
var
|
|
68913
|
+
var import_node_fs56 = __toESM(require("fs"), 1);
|
|
68914
|
+
var import_promises10 = __toESM(require("fs/promises"), 1);
|
|
68915
|
+
var import_node_os22 = __toESM(require("os"), 1);
|
|
68916
|
+
var import_node_path62 = __toESM(require("path"), 1);
|
|
68970
68917
|
var import_node_module = require("module");
|
|
68971
68918
|
var import_node_child_process17 = require("child_process");
|
|
68972
68919
|
var import_meta6 = {};
|
|
68973
68920
|
function defaultRoots() {
|
|
68974
|
-
const home =
|
|
68921
|
+
const home = import_node_os22.default.homedir();
|
|
68975
68922
|
return {
|
|
68976
|
-
claudeProjectsDir:
|
|
68977
|
-
codexDir:
|
|
68978
|
-
clawdDir:
|
|
68923
|
+
claudeProjectsDir: import_node_path62.default.join(home, ".claude", "projects"),
|
|
68924
|
+
codexDir: import_node_path62.default.join(home, ".codex"),
|
|
68925
|
+
clawdDir: import_node_path62.default.join(home, ".clawd")
|
|
68979
68926
|
};
|
|
68980
68927
|
}
|
|
68981
68928
|
function width(s2) {
|
|
@@ -69003,7 +68950,7 @@ function toMs(v3) {
|
|
|
69003
68950
|
async function* jsonLines(file) {
|
|
69004
68951
|
let raw;
|
|
69005
68952
|
try {
|
|
69006
|
-
raw = await
|
|
68953
|
+
raw = await import_promises10.default.readFile(file, "utf8");
|
|
69007
68954
|
} catch {
|
|
69008
68955
|
return;
|
|
69009
68956
|
}
|
|
@@ -69026,7 +68973,7 @@ function userText(msg) {
|
|
|
69026
68973
|
}
|
|
69027
68974
|
function isDir2(p3) {
|
|
69028
68975
|
try {
|
|
69029
|
-
return
|
|
68976
|
+
return import_node_fs56.default.statSync(p3).isDirectory();
|
|
69030
68977
|
} catch {
|
|
69031
68978
|
return false;
|
|
69032
68979
|
}
|
|
@@ -69035,7 +68982,7 @@ async function scanClaude(roots) {
|
|
|
69035
68982
|
const out = [];
|
|
69036
68983
|
let dirs;
|
|
69037
68984
|
try {
|
|
69038
|
-
dirs =
|
|
68985
|
+
dirs = import_node_fs56.default.readdirSync(roots.claudeProjectsDir, { withFileTypes: true });
|
|
69039
68986
|
} catch {
|
|
69040
68987
|
return out;
|
|
69041
68988
|
}
|
|
@@ -69043,16 +68990,16 @@ async function scanClaude(roots) {
|
|
|
69043
68990
|
if (!d2.isDirectory()) continue;
|
|
69044
68991
|
let files;
|
|
69045
68992
|
try {
|
|
69046
|
-
files =
|
|
68993
|
+
files = import_node_fs56.default.readdirSync(import_node_path62.default.join(roots.claudeProjectsDir, d2.name));
|
|
69047
68994
|
} catch {
|
|
69048
68995
|
continue;
|
|
69049
68996
|
}
|
|
69050
68997
|
for (const name of files) {
|
|
69051
68998
|
if (!name.endsWith(".jsonl")) continue;
|
|
69052
|
-
const file =
|
|
68999
|
+
const file = import_node_path62.default.join(roots.claudeProjectsDir, d2.name, name);
|
|
69053
69000
|
let st2;
|
|
69054
69001
|
try {
|
|
69055
|
-
st2 =
|
|
69002
|
+
st2 = import_node_fs56.default.statSync(file);
|
|
69056
69003
|
} catch {
|
|
69057
69004
|
continue;
|
|
69058
69005
|
}
|
|
@@ -69105,7 +69052,7 @@ async function scanClaude(roots) {
|
|
|
69105
69052
|
return out;
|
|
69106
69053
|
}
|
|
69107
69054
|
async function countCodexTurns(rolloutPath) {
|
|
69108
|
-
if (!rolloutPath || !
|
|
69055
|
+
if (!rolloutPath || !import_node_fs56.default.existsSync(rolloutPath)) return { turns: 0, first: "" };
|
|
69109
69056
|
let turns = 0;
|
|
69110
69057
|
let first = "";
|
|
69111
69058
|
for await (const rec6 of jsonLines(rolloutPath)) {
|
|
@@ -69179,7 +69126,7 @@ async function codexFromRows(rows) {
|
|
|
69179
69126
|
async function scanCodex(roots) {
|
|
69180
69127
|
let dbs = [];
|
|
69181
69128
|
try {
|
|
69182
|
-
dbs =
|
|
69129
|
+
dbs = import_node_fs56.default.readdirSync(roots.codexDir).filter((n2) => /^state_.*\.sqlite$/.test(n2)).sort().map((n2) => import_node_path62.default.join(roots.codexDir, n2));
|
|
69183
69130
|
} catch {
|
|
69184
69131
|
}
|
|
69185
69132
|
if (!dbs.length) return [];
|
|
@@ -69188,14 +69135,14 @@ async function scanCodex(roots) {
|
|
|
69188
69135
|
}
|
|
69189
69136
|
async function scanExternalSessions(rootsIn) {
|
|
69190
69137
|
const roots = { ...defaultRoots(), ...rootsIn };
|
|
69191
|
-
const personaRoot =
|
|
69138
|
+
const personaRoot = import_node_path62.default.join(roots.clawdDir, "personas");
|
|
69192
69139
|
const all = [...await scanClaude(roots), ...await scanCodex(roots)];
|
|
69193
69140
|
const out = [];
|
|
69194
69141
|
for (const c2 of all) {
|
|
69195
69142
|
if (c2.skip) continue;
|
|
69196
69143
|
if (c2.turns < 1) continue;
|
|
69197
69144
|
if (!c2.cwd || !isDir2(c2.cwd)) continue;
|
|
69198
|
-
if (c2.cwd === roots.clawdDir || c2.cwd === personaRoot || c2.cwd.startsWith(personaRoot +
|
|
69145
|
+
if (c2.cwd === roots.clawdDir || c2.cwd === personaRoot || c2.cwd.startsWith(personaRoot + import_node_path62.default.sep) || c2.cwd.startsWith(roots.clawdDir + import_node_path62.default.sep)) {
|
|
69199
69146
|
continue;
|
|
69200
69147
|
}
|
|
69201
69148
|
out.push({
|
|
@@ -69212,13 +69159,13 @@ async function scanExternalSessions(rootsIn) {
|
|
|
69212
69159
|
}
|
|
69213
69160
|
|
|
69214
69161
|
// src/session/import-ledger.ts
|
|
69215
|
-
var
|
|
69216
|
-
var
|
|
69162
|
+
var import_node_fs57 = __toESM(require("fs"), 1);
|
|
69163
|
+
var import_node_path63 = __toESM(require("path"), 1);
|
|
69217
69164
|
var LEDGER_FILENAME = "session-import-ledger.json";
|
|
69218
69165
|
function readImportLedger(dataDir) {
|
|
69219
69166
|
try {
|
|
69220
69167
|
const parsed = JSON.parse(
|
|
69221
|
-
|
|
69168
|
+
import_node_fs57.default.readFileSync(import_node_path63.default.join(dataDir, LEDGER_FILENAME), "utf8")
|
|
69222
69169
|
);
|
|
69223
69170
|
return Array.isArray(parsed) ? parsed : [];
|
|
69224
69171
|
} catch {
|
|
@@ -69226,10 +69173,10 @@ function readImportLedger(dataDir) {
|
|
|
69226
69173
|
}
|
|
69227
69174
|
}
|
|
69228
69175
|
function appendImportLedger(dataDir, entry) {
|
|
69229
|
-
const file =
|
|
69176
|
+
const file = import_node_path63.default.join(dataDir, LEDGER_FILENAME);
|
|
69230
69177
|
const entries = readImportLedger(dataDir);
|
|
69231
69178
|
entries.push(entry);
|
|
69232
|
-
|
|
69179
|
+
import_node_fs57.default.writeFileSync(file, JSON.stringify(entries, null, 2), { encoding: "utf8", mode: 384 });
|
|
69233
69180
|
}
|
|
69234
69181
|
|
|
69235
69182
|
// src/handlers/session.ts
|
|
@@ -69762,7 +69709,7 @@ function buildPermissionHandlers(deps) {
|
|
|
69762
69709
|
}
|
|
69763
69710
|
|
|
69764
69711
|
// src/handlers/history.ts
|
|
69765
|
-
var
|
|
69712
|
+
var path78 = __toESM(require("path"), 1);
|
|
69766
69713
|
init_protocol();
|
|
69767
69714
|
|
|
69768
69715
|
// src/session/recent-dirs.ts
|
|
@@ -69780,7 +69727,7 @@ function listRecentDirs(store, limit = 50) {
|
|
|
69780
69727
|
}
|
|
69781
69728
|
|
|
69782
69729
|
// src/permission/persona-paths.ts
|
|
69783
|
-
var
|
|
69730
|
+
var path77 = __toESM(require("path"), 1);
|
|
69784
69731
|
function getAllowedPersonaIds(grants, action) {
|
|
69785
69732
|
const ids = /* @__PURE__ */ new Set();
|
|
69786
69733
|
for (const g3 of grants) {
|
|
@@ -69793,42 +69740,42 @@ function getAllowedPersonaIds(grants, action) {
|
|
|
69793
69740
|
return ids;
|
|
69794
69741
|
}
|
|
69795
69742
|
function isGuestPathAllowed(grants, absPath, personaRoot, action = "read", userWorkDir) {
|
|
69796
|
-
const target =
|
|
69743
|
+
const target = path77.resolve(absPath);
|
|
69797
69744
|
if (userWorkDir) {
|
|
69798
|
-
const u2 =
|
|
69799
|
-
const usep = u2.endsWith(
|
|
69745
|
+
const u2 = path77.resolve(userWorkDir);
|
|
69746
|
+
const usep = u2.endsWith(path77.sep) ? "" : path77.sep;
|
|
69800
69747
|
if (target === u2 || target.startsWith(u2 + usep)) return true;
|
|
69801
69748
|
}
|
|
69802
|
-
const root =
|
|
69803
|
-
const sep4 = root.endsWith(
|
|
69749
|
+
const root = path77.resolve(personaRoot);
|
|
69750
|
+
const sep4 = root.endsWith(path77.sep) ? "" : path77.sep;
|
|
69804
69751
|
if (!target.startsWith(root + sep4)) return false;
|
|
69805
|
-
const rel =
|
|
69752
|
+
const rel = path77.relative(root, target);
|
|
69806
69753
|
if (!rel || rel.startsWith("..")) return false;
|
|
69807
|
-
const personaId2 = rel.split(
|
|
69754
|
+
const personaId2 = rel.split(path77.sep)[0];
|
|
69808
69755
|
if (!personaId2) return false;
|
|
69809
69756
|
const allowed = getAllowedPersonaIds(grants, action);
|
|
69810
69757
|
if (allowed === "*") return true;
|
|
69811
69758
|
return allowed.has(personaId2);
|
|
69812
69759
|
}
|
|
69813
69760
|
function personaIdFromPath(absPath, personaRoot) {
|
|
69814
|
-
const root =
|
|
69815
|
-
const target =
|
|
69816
|
-
const sep4 = root.endsWith(
|
|
69761
|
+
const root = path77.resolve(personaRoot);
|
|
69762
|
+
const target = path77.resolve(absPath);
|
|
69763
|
+
const sep4 = root.endsWith(path77.sep) ? "" : path77.sep;
|
|
69817
69764
|
if (!target.startsWith(root + sep4)) return null;
|
|
69818
|
-
const rel =
|
|
69765
|
+
const rel = path77.relative(root, target);
|
|
69819
69766
|
if (!rel || rel.startsWith("..")) return null;
|
|
69820
|
-
const id = rel.split(
|
|
69767
|
+
const id = rel.split(path77.sep)[0];
|
|
69821
69768
|
return id || null;
|
|
69822
69769
|
}
|
|
69823
69770
|
function isPathWithin(dir, absPath) {
|
|
69824
|
-
const d2 =
|
|
69825
|
-
const t2 =
|
|
69826
|
-
const sep4 = d2.endsWith(
|
|
69771
|
+
const d2 = path77.resolve(dir);
|
|
69772
|
+
const t2 = path77.resolve(absPath);
|
|
69773
|
+
const sep4 = d2.endsWith(path77.sep) ? "" : path77.sep;
|
|
69827
69774
|
return t2 === d2 || t2.startsWith(d2 + sep4);
|
|
69828
69775
|
}
|
|
69829
69776
|
function isPathInGuestBoundary(personaRoot, personaId2, userWorkDir, absPath) {
|
|
69830
69777
|
if (userWorkDir && isPathWithin(userWorkDir, absPath)) return true;
|
|
69831
|
-
return personaIdFromPath(
|
|
69778
|
+
return personaIdFromPath(path77.resolve(absPath), personaRoot) === personaId2;
|
|
69832
69779
|
}
|
|
69833
69780
|
|
|
69834
69781
|
// src/handlers/history.ts
|
|
@@ -69881,7 +69828,7 @@ function buildHistoryHandlers(deps) {
|
|
|
69881
69828
|
if (!pid) return false;
|
|
69882
69829
|
return isGuestPathAllowed(
|
|
69883
69830
|
ctx.grants,
|
|
69884
|
-
|
|
69831
|
+
path78.join(personaRoot, pid),
|
|
69885
69832
|
personaRoot,
|
|
69886
69833
|
"read",
|
|
69887
69834
|
userWorkDir
|
|
@@ -69893,7 +69840,7 @@ function buildHistoryHandlers(deps) {
|
|
|
69893
69840
|
};
|
|
69894
69841
|
const list = async (frame, _client, ctx) => {
|
|
69895
69842
|
const args = HistoryListArgs.parse(frame);
|
|
69896
|
-
assertGuestPath(ctx,
|
|
69843
|
+
assertGuestPath(ctx, path78.resolve(args.projectPath), personaRoot, "history:list", usersRoot);
|
|
69897
69844
|
const sessions = await history.listSessions(args);
|
|
69898
69845
|
return { response: { type: "history:list", sessions } };
|
|
69899
69846
|
};
|
|
@@ -69941,14 +69888,14 @@ function buildHistoryHandlers(deps) {
|
|
|
69941
69888
|
};
|
|
69942
69889
|
const subagents = async (frame, _client, ctx) => {
|
|
69943
69890
|
const args = HistorySubagentsArgs.parse(frame);
|
|
69944
|
-
assertGuestPath(ctx,
|
|
69891
|
+
assertGuestPath(ctx, path78.resolve(args.cwd), personaRoot, "history:subagents", usersRoot);
|
|
69945
69892
|
assertGuestOwnsToolSession(ctx, args.toolSessionId, "history:subagents");
|
|
69946
69893
|
const subs = await historyReaderForToolSession(args.toolSessionId).listSubagents(args);
|
|
69947
69894
|
return { response: { type: "history:subagents", subagents: subs } };
|
|
69948
69895
|
};
|
|
69949
69896
|
const subagentRead = async (frame, _client, ctx) => {
|
|
69950
69897
|
const args = HistorySubagentReadArgs.parse(frame);
|
|
69951
|
-
assertGuestPath(ctx,
|
|
69898
|
+
assertGuestPath(ctx, path78.resolve(args.cwd), personaRoot, "history:subagent-read", usersRoot);
|
|
69952
69899
|
assertGuestOwnsToolSession(ctx, args.toolSessionId, "history:subagent-read");
|
|
69953
69900
|
const res = await historyReaderForToolSession(args.toolSessionId).readSubagent(args);
|
|
69954
69901
|
return { response: { type: "history:subagent-read", ...res } };
|
|
@@ -69958,7 +69905,7 @@ function buildHistoryHandlers(deps) {
|
|
|
69958
69905
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
69959
69906
|
const userWorkDir = usersRoot ? deriveUserWorkDir(ctx.principal.id, usersRoot) : void 0;
|
|
69960
69907
|
const filtered = dirs.filter(
|
|
69961
|
-
(d2) => isGuestPathAllowed(ctx.grants,
|
|
69908
|
+
(d2) => isGuestPathAllowed(ctx.grants, path78.resolve(d2.cwd), personaRoot, "read", userWorkDir)
|
|
69962
69909
|
);
|
|
69963
69910
|
return { response: { type: "history:recentDirs", dirs: filtered } };
|
|
69964
69911
|
}
|
|
@@ -69975,17 +69922,17 @@ function buildHistoryHandlers(deps) {
|
|
|
69975
69922
|
}
|
|
69976
69923
|
|
|
69977
69924
|
// src/handlers/projects.ts
|
|
69978
|
-
var
|
|
69979
|
-
var
|
|
69980
|
-
var
|
|
69925
|
+
var fs75 = __toESM(require("fs"), 1);
|
|
69926
|
+
var os24 = __toESM(require("os"), 1);
|
|
69927
|
+
var path79 = __toESM(require("path"), 1);
|
|
69981
69928
|
var import_node_child_process18 = require("child_process");
|
|
69982
69929
|
init_protocol();
|
|
69983
|
-
var DEFAULT_PROJECTS_ROOT =
|
|
69930
|
+
var DEFAULT_PROJECTS_ROOT = path79.join(os24.homedir(), "Documents", "ChatGPT");
|
|
69984
69931
|
function allocateDir(root, name) {
|
|
69985
|
-
let candidate =
|
|
69932
|
+
let candidate = path79.join(root, name);
|
|
69986
69933
|
let n2 = 2;
|
|
69987
|
-
while (
|
|
69988
|
-
candidate =
|
|
69934
|
+
while (fs75.existsSync(candidate)) {
|
|
69935
|
+
candidate = path79.join(root, `${name} ${n2}`);
|
|
69989
69936
|
n2 += 1;
|
|
69990
69937
|
}
|
|
69991
69938
|
return candidate;
|
|
@@ -70013,7 +69960,7 @@ function buildProjectHandlers(deps) {
|
|
|
70013
69960
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, "project:reveal \u4EC5\u652F\u6301 macOS");
|
|
70014
69961
|
}
|
|
70015
69962
|
try {
|
|
70016
|
-
if (!
|
|
69963
|
+
if (!fs75.statSync(args.path).isDirectory()) throw new Error("not dir");
|
|
70017
69964
|
} catch {
|
|
70018
69965
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${args.path}`);
|
|
70019
69966
|
}
|
|
@@ -70029,7 +69976,7 @@ function buildProjectHandlers(deps) {
|
|
|
70029
69976
|
let target;
|
|
70030
69977
|
if (args.path) {
|
|
70031
69978
|
try {
|
|
70032
|
-
if (!
|
|
69979
|
+
if (!fs75.statSync(args.path).isDirectory()) throw new Error("not dir");
|
|
70033
69980
|
} catch {
|
|
70034
69981
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${args.path}`);
|
|
70035
69982
|
}
|
|
@@ -70037,15 +69984,15 @@ function buildProjectHandlers(deps) {
|
|
|
70037
69984
|
} else {
|
|
70038
69985
|
const name = args.name;
|
|
70039
69986
|
try {
|
|
70040
|
-
|
|
69987
|
+
fs75.mkdirSync(root, { recursive: true });
|
|
70041
69988
|
target = allocateDir(root, name);
|
|
70042
|
-
|
|
69989
|
+
fs75.mkdirSync(target);
|
|
70043
69990
|
} catch (err) {
|
|
70044
69991
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `\u521B\u5EFA\u9879\u76EE\u76EE\u5F55\u5931\u8D25: ${String(err)}`);
|
|
70045
69992
|
}
|
|
70046
69993
|
const git2 = (0, import_node_child_process18.spawnSync)("git", ["init"], { cwd: target, stdio: "ignore" });
|
|
70047
69994
|
if (git2.status !== 0) {
|
|
70048
|
-
|
|
69995
|
+
fs75.rmSync(target, { recursive: true, force: true });
|
|
70049
69996
|
throw new ClawdError(
|
|
70050
69997
|
ERROR_CODES.INVALID_CWD,
|
|
70051
69998
|
`git init \u5931\u8D25\uFF08${git2.error ? String(git2.error) : `exit ${git2.status}`}\uFF09: ${target}`
|
|
@@ -70070,9 +70017,9 @@ function buildProjectHandlers(deps) {
|
|
|
70070
70017
|
}
|
|
70071
70018
|
|
|
70072
70019
|
// src/handlers/workspace.ts
|
|
70073
|
-
var
|
|
70020
|
+
var path80 = __toESM(require("path"), 1);
|
|
70074
70021
|
init_protocol();
|
|
70075
|
-
var
|
|
70022
|
+
var os25 = __toESM(require("os"), 1);
|
|
70076
70023
|
init_protocol();
|
|
70077
70024
|
init_protocol();
|
|
70078
70025
|
function buildEnabledPluginNames(personaManager, personaId2) {
|
|
@@ -70112,23 +70059,23 @@ function buildWorkspaceHandlers(deps) {
|
|
|
70112
70059
|
const list = async (frame, _client, ctx) => {
|
|
70113
70060
|
const args = WorkspaceListArgs.parse(frame);
|
|
70114
70061
|
const isGuest = ctx?.principal.kind === "guest";
|
|
70115
|
-
const fallbackCwd = isGuest && personaRoot ? personaRoot :
|
|
70116
|
-
const resolvedCwd =
|
|
70117
|
-
const target = args.path ?
|
|
70062
|
+
const fallbackCwd = isGuest && personaRoot ? personaRoot : os25.homedir();
|
|
70063
|
+
const resolvedCwd = path80.resolve(args.cwd ?? fallbackCwd);
|
|
70064
|
+
const target = args.path ? path80.resolve(resolvedCwd, args.path) : resolvedCwd;
|
|
70118
70065
|
assertGuestPath2(ctx, target, personaRoot, "workspace:list", usersRoot);
|
|
70119
70066
|
const res = workspace.list({ ...args, cwd: resolvedCwd });
|
|
70120
70067
|
return { response: { type: "workspace:list", ...res } };
|
|
70121
70068
|
};
|
|
70122
70069
|
const read = async (frame, _client, ctx) => {
|
|
70123
70070
|
const args = WorkspaceReadArgs.parse(frame);
|
|
70124
|
-
const target =
|
|
70071
|
+
const target = path80.isAbsolute(args.path) ? path80.resolve(args.path) : path80.resolve(args.cwd, args.path);
|
|
70125
70072
|
assertGuestPath2(ctx, target, personaRoot, "workspace:read", usersRoot);
|
|
70126
70073
|
const res = workspace.read(args);
|
|
70127
70074
|
return { response: { type: "workspace:read", ...res } };
|
|
70128
70075
|
};
|
|
70129
70076
|
const skillsList = async (frame, _client, ctx) => {
|
|
70130
70077
|
const args = SkillsListArgs.parse(frame);
|
|
70131
|
-
const cwdAbs =
|
|
70078
|
+
const cwdAbs = path80.resolve(args.cwd);
|
|
70132
70079
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "skills:list", usersRoot);
|
|
70133
70080
|
const list2 = await getSkillsForTool(args.tool ?? "claude", cwdAbs);
|
|
70134
70081
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
@@ -70140,7 +70087,7 @@ function buildWorkspaceHandlers(deps) {
|
|
|
70140
70087
|
};
|
|
70141
70088
|
const agentsList = async (frame, _client, ctx) => {
|
|
70142
70089
|
const args = AgentsListArgs.parse(frame);
|
|
70143
|
-
const cwdAbs =
|
|
70090
|
+
const cwdAbs = path80.resolve(args.cwd);
|
|
70144
70091
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "agents:list", usersRoot);
|
|
70145
70092
|
if (isCodexFamily(args.tool) || isPiFamily(args.tool)) {
|
|
70146
70093
|
return { response: { type: "agents:list", agents: [] } };
|
|
@@ -70162,20 +70109,20 @@ function buildWorkspaceHandlers(deps) {
|
|
|
70162
70109
|
}
|
|
70163
70110
|
|
|
70164
70111
|
// src/handlers/git.ts
|
|
70165
|
-
var
|
|
70112
|
+
var path82 = __toESM(require("path"), 1);
|
|
70166
70113
|
init_protocol();
|
|
70167
70114
|
init_protocol();
|
|
70168
70115
|
|
|
70169
70116
|
// src/workspace/git.ts
|
|
70170
70117
|
var import_node_child_process19 = require("child_process");
|
|
70171
|
-
var
|
|
70172
|
-
var
|
|
70118
|
+
var import_node_fs58 = __toESM(require("fs"), 1);
|
|
70119
|
+
var import_node_path64 = __toESM(require("path"), 1);
|
|
70173
70120
|
var import_node_util2 = require("util");
|
|
70174
70121
|
var pexec = (0, import_node_util2.promisify)(import_node_child_process19.execFile);
|
|
70175
70122
|
function normalizePath(p3) {
|
|
70176
|
-
const resolved =
|
|
70123
|
+
const resolved = import_node_path64.default.resolve(p3);
|
|
70177
70124
|
try {
|
|
70178
|
-
return
|
|
70125
|
+
return import_node_fs58.default.realpathSync(resolved);
|
|
70179
70126
|
} catch {
|
|
70180
70127
|
return resolved;
|
|
70181
70128
|
}
|
|
@@ -70249,7 +70196,7 @@ async function listGitBranches(cwd) {
|
|
|
70249
70196
|
function assertGuestCwd(ctx, cwd, personaRoot, method, usersRoot) {
|
|
70250
70197
|
if (!ctx || ctx.principal.kind !== "guest" || !personaRoot) return;
|
|
70251
70198
|
const userWorkDir = usersRoot ? deriveUserWorkDir(ctx.principal.id, usersRoot) : void 0;
|
|
70252
|
-
if (!isGuestPathAllowed(ctx.grants,
|
|
70199
|
+
if (!isGuestPathAllowed(ctx.grants, path82.resolve(cwd), personaRoot, "read", userWorkDir)) {
|
|
70253
70200
|
throw new ClawdError(
|
|
70254
70201
|
ERROR_CODES.UNAUTHORIZED,
|
|
70255
70202
|
`guest ${ctx.principal.id} cannot ${method} cwd ${cwd}`
|
|
@@ -70506,12 +70453,12 @@ async function queryCodexAccount(deps = {}) {
|
|
|
70506
70453
|
}
|
|
70507
70454
|
|
|
70508
70455
|
// src/tools/pi-account.ts
|
|
70509
|
-
var
|
|
70510
|
-
var
|
|
70456
|
+
var import_node_fs59 = __toESM(require("fs"), 1);
|
|
70457
|
+
var import_node_path65 = __toESM(require("path"), 1);
|
|
70511
70458
|
function readPiCredentials(agentDir) {
|
|
70512
70459
|
let raw;
|
|
70513
70460
|
try {
|
|
70514
|
-
raw = JSON.parse(
|
|
70461
|
+
raw = JSON.parse(import_node_fs59.default.readFileSync(import_node_path65.default.join(agentDir, "auth.json"), "utf8"));
|
|
70515
70462
|
} catch {
|
|
70516
70463
|
return {};
|
|
70517
70464
|
}
|
|
@@ -71193,7 +71140,7 @@ function buildCloudVolumeHandlers(deps) {
|
|
|
71193
71140
|
}
|
|
71194
71141
|
|
|
71195
71142
|
// src/handlers/meta.ts
|
|
71196
|
-
var
|
|
71143
|
+
var import_node_os23 = __toESM(require("os"), 1);
|
|
71197
71144
|
init_protocol();
|
|
71198
71145
|
|
|
71199
71146
|
// src/handlers/method-grants.ts
|
|
@@ -71503,21 +71450,21 @@ function computeMethodAccess(args) {
|
|
|
71503
71450
|
}
|
|
71504
71451
|
|
|
71505
71452
|
// src/version.ts
|
|
71506
|
-
var version = "0.2.
|
|
71453
|
+
var version = "0.2.574".length > 0 ? "0.2.574" : "dev";
|
|
71507
71454
|
|
|
71508
71455
|
// src/cli-probe/probe.ts
|
|
71509
|
-
var
|
|
71510
|
-
var
|
|
71456
|
+
var fs78 = __toESM(require("fs"), 1);
|
|
71457
|
+
var path84 = __toESM(require("path"), 1);
|
|
71511
71458
|
var PKG_NAME = "@clawos-dev/clawd";
|
|
71512
71459
|
var BIN_NAME = "clawd";
|
|
71513
71460
|
var MAX_PARENT_HOPS = 5;
|
|
71514
71461
|
function probeGlobalCli(pathEnv) {
|
|
71515
71462
|
if (!pathEnv) return null;
|
|
71516
|
-
for (const dir of pathEnv.split(
|
|
71463
|
+
for (const dir of pathEnv.split(path84.delimiter)) {
|
|
71517
71464
|
if (!dir) continue;
|
|
71518
71465
|
let real;
|
|
71519
71466
|
try {
|
|
71520
|
-
real =
|
|
71467
|
+
real = fs78.realpathSync(path84.join(dir, BIN_NAME));
|
|
71521
71468
|
} catch {
|
|
71522
71469
|
continue;
|
|
71523
71470
|
}
|
|
@@ -71527,15 +71474,15 @@ function probeGlobalCli(pathEnv) {
|
|
|
71527
71474
|
return null;
|
|
71528
71475
|
}
|
|
71529
71476
|
function readOwnPackageVersion(entryPath) {
|
|
71530
|
-
let dir =
|
|
71477
|
+
let dir = path84.dirname(entryPath);
|
|
71531
71478
|
for (let i2 = 0; i2 < MAX_PARENT_HOPS; i2++) {
|
|
71532
71479
|
try {
|
|
71533
|
-
const raw =
|
|
71480
|
+
const raw = fs78.readFileSync(path84.join(dir, "package.json"), "utf8");
|
|
71534
71481
|
const pkg = JSON.parse(raw);
|
|
71535
71482
|
if (pkg.name !== PKG_NAME) return null;
|
|
71536
71483
|
return typeof pkg.version === "string" && pkg.version ? pkg.version : null;
|
|
71537
71484
|
} catch {
|
|
71538
|
-
const parent =
|
|
71485
|
+
const parent = path84.dirname(dir);
|
|
71539
71486
|
if (parent === dir) return null;
|
|
71540
71487
|
dir = parent;
|
|
71541
71488
|
}
|
|
@@ -71571,7 +71518,7 @@ function buildReadyFrame(deps, client) {
|
|
|
71571
71518
|
return {
|
|
71572
71519
|
version,
|
|
71573
71520
|
protocolVersion: PROTOCOL_VERSION,
|
|
71574
|
-
hostname:
|
|
71521
|
+
hostname: import_node_os23.default.hostname(),
|
|
71575
71522
|
os: process.platform,
|
|
71576
71523
|
tools,
|
|
71577
71524
|
runningSessions: info.runningSessions,
|
|
@@ -71711,7 +71658,7 @@ function buildPersonaHandlers(deps) {
|
|
|
71711
71658
|
}
|
|
71712
71659
|
|
|
71713
71660
|
// src/handlers/attachment.ts
|
|
71714
|
-
var
|
|
71661
|
+
var import_node_path66 = __toESM(require("path"), 1);
|
|
71715
71662
|
init_protocol();
|
|
71716
71663
|
init_protocol();
|
|
71717
71664
|
function assertGuestAttachmentPath(ctx, absPath, personaRoot, method, usersRoot) {
|
|
@@ -71790,12 +71737,12 @@ function buildAttachmentHandlers(deps) {
|
|
|
71790
71737
|
`session ${args.sessionId} scope unresolved`
|
|
71791
71738
|
);
|
|
71792
71739
|
}
|
|
71793
|
-
const cwdAbs =
|
|
71794
|
-
const candidateAbs =
|
|
71740
|
+
const cwdAbs = import_node_path66.default.resolve(sessionFile.cwd);
|
|
71741
|
+
const candidateAbs = import_node_path66.default.isAbsolute(args.relPath) ? import_node_path66.default.resolve(args.relPath) : import_node_path66.default.resolve(cwdAbs, args.relPath);
|
|
71795
71742
|
guardAttachmentPath(ctx, args.sessionId, candidateAbs, "attachment.signUrl", "group-acl");
|
|
71796
71743
|
const entries = deps.groupFileStore.list(scope, args.sessionId);
|
|
71797
71744
|
const entry = entries.find((e) => {
|
|
71798
|
-
const storedAbs =
|
|
71745
|
+
const storedAbs = import_node_path66.default.isAbsolute(e.relPath) ? import_node_path66.default.resolve(e.relPath) : import_node_path66.default.resolve(cwdAbs, e.relPath);
|
|
71799
71746
|
return storedAbs === candidateAbs && !e.stale;
|
|
71800
71747
|
});
|
|
71801
71748
|
if (!entry) {
|
|
@@ -71819,7 +71766,7 @@ function buildAttachmentHandlers(deps) {
|
|
|
71819
71766
|
if (!ctx || ctx.principal.kind !== "guest" || !deps.personaRoot || !deps.sessionStore) return;
|
|
71820
71767
|
const f2 = deps.sessionStore.read(sessionId);
|
|
71821
71768
|
if (!f2) return;
|
|
71822
|
-
assertGuestAttachmentPath(ctx,
|
|
71769
|
+
assertGuestAttachmentPath(ctx, import_node_path66.default.resolve(f2.cwd), deps.personaRoot, method, deps.usersRoot);
|
|
71823
71770
|
}
|
|
71824
71771
|
const groupAdd = async (frame, _client, ctx) => {
|
|
71825
71772
|
if (!deps.groupFileStore || !deps.getSessionScope) {
|
|
@@ -71834,8 +71781,8 @@ function buildAttachmentHandlers(deps) {
|
|
|
71834
71781
|
if (!scope) {
|
|
71835
71782
|
throw new ClawdError(ERROR_CODES.VALIDATION_ERROR, `session ${args.sessionId} not found`);
|
|
71836
71783
|
}
|
|
71837
|
-
const cwdAbs =
|
|
71838
|
-
const candidateAbs =
|
|
71784
|
+
const cwdAbs = import_node_path66.default.resolve(deps.sessionStore?.read(args.sessionId)?.cwd ?? ".");
|
|
71785
|
+
const candidateAbs = import_node_path66.default.isAbsolute(args.relPath) ? import_node_path66.default.resolve(args.relPath) : import_node_path66.default.resolve(cwdAbs, args.relPath);
|
|
71839
71786
|
guardAttachmentPath(ctx, args.sessionId, candidateAbs, "attachment.groupAdd", "cwd-subtree");
|
|
71840
71787
|
const from = args.origin === "agent" ? "agent" : ctx?.principal.kind === "owner" ? "owner" : "agent";
|
|
71841
71788
|
const size = 0;
|
|
@@ -71893,21 +71840,21 @@ function buildAttachmentHandlers(deps) {
|
|
|
71893
71840
|
}
|
|
71894
71841
|
|
|
71895
71842
|
// src/handlers/extension.ts
|
|
71896
|
-
var
|
|
71897
|
-
var
|
|
71843
|
+
var import_promises14 = __toESM(require("fs/promises"), 1);
|
|
71844
|
+
var import_node_path71 = __toESM(require("path"), 1);
|
|
71898
71845
|
init_protocol();
|
|
71899
71846
|
|
|
71900
71847
|
// src/extension/bundle-zip.ts
|
|
71901
|
-
var
|
|
71902
|
-
var
|
|
71903
|
-
var
|
|
71848
|
+
var import_promises11 = __toESM(require("fs/promises"), 1);
|
|
71849
|
+
var import_node_path67 = __toESM(require("path"), 1);
|
|
71850
|
+
var import_node_crypto20 = __toESM(require("crypto"), 1);
|
|
71904
71851
|
var import_jszip2 = __toESM(require_lib3(), 1);
|
|
71905
71852
|
async function bundleExtensionDir(dir) {
|
|
71906
71853
|
const entries = await listFilesSorted(dir);
|
|
71907
71854
|
const zip = new import_jszip2.default();
|
|
71908
71855
|
for (const rel of entries) {
|
|
71909
|
-
const abs =
|
|
71910
|
-
const content = await
|
|
71856
|
+
const abs = import_node_path67.default.join(dir, rel);
|
|
71857
|
+
const content = await import_promises11.default.readFile(abs);
|
|
71911
71858
|
zip.file(rel, content, { date: FIXED_DATE });
|
|
71912
71859
|
}
|
|
71913
71860
|
const buffer = await zip.generateAsync({
|
|
@@ -71915,7 +71862,7 @@ async function bundleExtensionDir(dir) {
|
|
|
71915
71862
|
compression: "DEFLATE",
|
|
71916
71863
|
compressionOptions: { level: 6 }
|
|
71917
71864
|
});
|
|
71918
|
-
const sha256 =
|
|
71865
|
+
const sha256 = import_node_crypto20.default.createHash("sha256").update(buffer).digest("hex");
|
|
71919
71866
|
return { buffer, sha256 };
|
|
71920
71867
|
}
|
|
71921
71868
|
var FIXED_DATE = /* @__PURE__ */ new Date("2020-01-01T00:00:00.000Z");
|
|
@@ -71927,8 +71874,8 @@ async function listFilesSorted(rootDir) {
|
|
|
71927
71874
|
return out;
|
|
71928
71875
|
}
|
|
71929
71876
|
async function walk(absRoot, relPrefix, out) {
|
|
71930
|
-
const dirAbs =
|
|
71931
|
-
const entries = await
|
|
71877
|
+
const dirAbs = import_node_path67.default.join(absRoot, relPrefix);
|
|
71878
|
+
const entries = await import_promises11.default.readdir(dirAbs, { withFileTypes: true });
|
|
71932
71879
|
for (const e of entries) {
|
|
71933
71880
|
if (IGNORE_BASENAMES.has(e.name)) continue;
|
|
71934
71881
|
const rel = relPrefix ? `${relPrefix}/${e.name}` : e.name;
|
|
@@ -71980,26 +71927,26 @@ function computePublishCheck(args) {
|
|
|
71980
71927
|
}
|
|
71981
71928
|
|
|
71982
71929
|
// src/extension/install-flow.ts
|
|
71983
|
-
var
|
|
71984
|
-
var
|
|
71985
|
-
var
|
|
71986
|
-
var
|
|
71930
|
+
var import_promises12 = __toESM(require("fs/promises"), 1);
|
|
71931
|
+
var import_node_path69 = __toESM(require("path"), 1);
|
|
71932
|
+
var import_node_os25 = __toESM(require("os"), 1);
|
|
71933
|
+
var import_node_crypto21 = __toESM(require("crypto"), 1);
|
|
71987
71934
|
var import_jszip3 = __toESM(require_lib3(), 1);
|
|
71988
71935
|
|
|
71989
71936
|
// src/extension/paths.ts
|
|
71990
|
-
var
|
|
71991
|
-
var
|
|
71937
|
+
var import_node_os24 = __toESM(require("os"), 1);
|
|
71938
|
+
var import_node_path68 = __toESM(require("path"), 1);
|
|
71992
71939
|
function clawdHomeRoot(override) {
|
|
71993
|
-
return override ?? process.env.CLAWD_HOME ??
|
|
71940
|
+
return override ?? process.env.CLAWD_HOME ?? import_node_path68.default.join(import_node_os24.default.homedir(), ".clawd");
|
|
71994
71941
|
}
|
|
71995
71942
|
function extensionsRoot(override) {
|
|
71996
|
-
return
|
|
71943
|
+
return import_node_path68.default.join(clawdHomeRoot(override), "extensions");
|
|
71997
71944
|
}
|
|
71998
71945
|
function publishedChannelsFile(override) {
|
|
71999
|
-
return
|
|
71946
|
+
return import_node_path68.default.join(clawdHomeRoot(override), "extensions-published.json");
|
|
72000
71947
|
}
|
|
72001
71948
|
function bundleCacheRoot(override) {
|
|
72002
|
-
return
|
|
71949
|
+
return import_node_path68.default.join(clawdHomeRoot(override), "extension-bundles");
|
|
72003
71950
|
}
|
|
72004
71951
|
|
|
72005
71952
|
// src/extension/install-flow.ts
|
|
@@ -72012,7 +71959,7 @@ var InstallError = class extends Error {
|
|
|
72012
71959
|
};
|
|
72013
71960
|
async function installFromChannel(args, deps) {
|
|
72014
71961
|
const { channelRef, snapshotHash, bundleZip } = args;
|
|
72015
|
-
const computed =
|
|
71962
|
+
const computed = import_node_crypto21.default.createHash("sha256").update(bundleZip).digest("hex");
|
|
72016
71963
|
if (computed !== snapshotHash) {
|
|
72017
71964
|
throw new InstallError(
|
|
72018
71965
|
"HASH_MISMATCH",
|
|
@@ -72026,7 +71973,7 @@ async function installFromChannel(args, deps) {
|
|
|
72026
71973
|
throw new InstallError("ZIP_INVALID", `failed to load zip: ${e.message}`);
|
|
72027
71974
|
}
|
|
72028
71975
|
for (const name of Object.keys(zip.files)) {
|
|
72029
|
-
if (name.includes("..") || name.startsWith("/") ||
|
|
71976
|
+
if (name.includes("..") || name.startsWith("/") || import_node_path69.default.isAbsolute(name)) {
|
|
72030
71977
|
throw new InstallError("ZIP_INVALID", `unsafe zip entry: ${name}`);
|
|
72031
71978
|
}
|
|
72032
71979
|
}
|
|
@@ -72058,10 +72005,10 @@ async function installFromChannel(args, deps) {
|
|
|
72058
72005
|
);
|
|
72059
72006
|
}
|
|
72060
72007
|
const localExtId = namespacedExtId(ownerSlug, channelRef.ownerPrincipalId);
|
|
72061
|
-
const destDir =
|
|
72008
|
+
const destDir = import_node_path69.default.join(deps.extensionsRoot, localExtId);
|
|
72062
72009
|
let destExists = false;
|
|
72063
72010
|
try {
|
|
72064
|
-
await
|
|
72011
|
+
await import_promises12.default.access(destDir);
|
|
72065
72012
|
destExists = true;
|
|
72066
72013
|
} catch {
|
|
72067
72014
|
}
|
|
@@ -72071,28 +72018,28 @@ async function installFromChannel(args, deps) {
|
|
|
72071
72018
|
`extension ${localExtId} already installed locally (from owner ${channelRef.ownerPrincipalId})`
|
|
72072
72019
|
);
|
|
72073
72020
|
}
|
|
72074
|
-
const stage = await
|
|
72075
|
-
|
|
72021
|
+
const stage = await import_promises12.default.mkdtemp(
|
|
72022
|
+
import_node_path69.default.join(import_node_os25.default.tmpdir(), `clawd-ext-install-${localExtId}-`)
|
|
72076
72023
|
);
|
|
72077
72024
|
try {
|
|
72078
72025
|
for (const [name, entry] of Object.entries(zip.files)) {
|
|
72079
|
-
const dest =
|
|
72026
|
+
const dest = import_node_path69.default.join(stage, name);
|
|
72080
72027
|
if (entry.dir) {
|
|
72081
|
-
await
|
|
72028
|
+
await import_promises12.default.mkdir(dest, { recursive: true });
|
|
72082
72029
|
continue;
|
|
72083
72030
|
}
|
|
72084
|
-
await
|
|
72031
|
+
await import_promises12.default.mkdir(import_node_path69.default.dirname(dest), { recursive: true });
|
|
72085
72032
|
if (name === "manifest.json") {
|
|
72086
72033
|
const rewritten = { ...parsed.data, id: localExtId };
|
|
72087
|
-
await
|
|
72034
|
+
await import_promises12.default.writeFile(dest, JSON.stringify(rewritten, null, 2));
|
|
72088
72035
|
} else {
|
|
72089
|
-
await
|
|
72036
|
+
await import_promises12.default.writeFile(dest, await entry.async("nodebuffer"));
|
|
72090
72037
|
}
|
|
72091
72038
|
}
|
|
72092
|
-
await
|
|
72093
|
-
await
|
|
72039
|
+
await import_promises12.default.mkdir(deps.extensionsRoot, { recursive: true });
|
|
72040
|
+
await import_promises12.default.rename(stage, destDir);
|
|
72094
72041
|
} catch (e) {
|
|
72095
|
-
await
|
|
72042
|
+
await import_promises12.default.rm(stage, { recursive: true, force: true }).catch(() => {
|
|
72096
72043
|
});
|
|
72097
72044
|
throw e;
|
|
72098
72045
|
}
|
|
@@ -72101,10 +72048,10 @@ async function installFromChannel(args, deps) {
|
|
|
72101
72048
|
}
|
|
72102
72049
|
|
|
72103
72050
|
// src/extension/update-flow.ts
|
|
72104
|
-
var
|
|
72105
|
-
var
|
|
72106
|
-
var
|
|
72107
|
-
var
|
|
72051
|
+
var import_promises13 = __toESM(require("fs/promises"), 1);
|
|
72052
|
+
var import_node_path70 = __toESM(require("path"), 1);
|
|
72053
|
+
var import_node_os26 = __toESM(require("os"), 1);
|
|
72054
|
+
var import_node_crypto22 = __toESM(require("crypto"), 1);
|
|
72108
72055
|
var import_jszip4 = __toESM(require_lib3(), 1);
|
|
72109
72056
|
var UpdateError = class extends Error {
|
|
72110
72057
|
constructor(code, message) {
|
|
@@ -72119,11 +72066,11 @@ async function updateFromChannel(args, deps) {
|
|
|
72119
72066
|
channelRef.extId,
|
|
72120
72067
|
channelRef.ownerPrincipalId
|
|
72121
72068
|
);
|
|
72122
|
-
const liveDir =
|
|
72069
|
+
const liveDir = import_node_path70.default.join(deps.extensionsRoot, localExtId);
|
|
72123
72070
|
const prevDir = `${liveDir}.prev`;
|
|
72124
72071
|
let existingVersion;
|
|
72125
72072
|
try {
|
|
72126
|
-
const raw = await
|
|
72073
|
+
const raw = await import_promises13.default.readFile(import_node_path70.default.join(liveDir, "manifest.json"), "utf8");
|
|
72127
72074
|
const parsed2 = ExtensionManifestSchema.safeParse(JSON.parse(raw));
|
|
72128
72075
|
if (!parsed2.success) {
|
|
72129
72076
|
throw new UpdateError(
|
|
@@ -72142,7 +72089,7 @@ async function updateFromChannel(args, deps) {
|
|
|
72142
72089
|
if (e instanceof UpdateError) throw e;
|
|
72143
72090
|
throw e;
|
|
72144
72091
|
}
|
|
72145
|
-
const computed =
|
|
72092
|
+
const computed = import_node_crypto22.default.createHash("sha256").update(bundleZip).digest("hex");
|
|
72146
72093
|
if (computed !== snapshotHash) {
|
|
72147
72094
|
throw new UpdateError(
|
|
72148
72095
|
"HASH_MISMATCH",
|
|
@@ -72156,7 +72103,7 @@ async function updateFromChannel(args, deps) {
|
|
|
72156
72103
|
throw new UpdateError("ZIP_INVALID", `failed to load zip: ${e.message}`);
|
|
72157
72104
|
}
|
|
72158
72105
|
for (const name of Object.keys(zip.files)) {
|
|
72159
|
-
if (name.includes("..") || name.startsWith("/") ||
|
|
72106
|
+
if (name.includes("..") || name.startsWith("/") || import_node_path70.default.isAbsolute(name)) {
|
|
72160
72107
|
throw new UpdateError("ZIP_INVALID", `unsafe zip entry: ${name}`);
|
|
72161
72108
|
}
|
|
72162
72109
|
}
|
|
@@ -72188,31 +72135,31 @@ async function updateFromChannel(args, deps) {
|
|
|
72188
72135
|
);
|
|
72189
72136
|
}
|
|
72190
72137
|
await deps.runtime.close(localExtId);
|
|
72191
|
-
await
|
|
72192
|
-
await
|
|
72193
|
-
const stage = await
|
|
72194
|
-
|
|
72138
|
+
await import_promises13.default.rm(prevDir, { recursive: true, force: true });
|
|
72139
|
+
await import_promises13.default.rename(liveDir, prevDir);
|
|
72140
|
+
const stage = await import_promises13.default.mkdtemp(
|
|
72141
|
+
import_node_path70.default.join(import_node_os26.default.tmpdir(), `clawd-ext-update-${localExtId}-`)
|
|
72195
72142
|
);
|
|
72196
72143
|
try {
|
|
72197
72144
|
for (const [name, entry] of Object.entries(zip.files)) {
|
|
72198
|
-
const dest =
|
|
72145
|
+
const dest = import_node_path70.default.join(stage, name);
|
|
72199
72146
|
if (entry.dir) {
|
|
72200
|
-
await
|
|
72147
|
+
await import_promises13.default.mkdir(dest, { recursive: true });
|
|
72201
72148
|
continue;
|
|
72202
72149
|
}
|
|
72203
|
-
await
|
|
72150
|
+
await import_promises13.default.mkdir(import_node_path70.default.dirname(dest), { recursive: true });
|
|
72204
72151
|
if (name === "manifest.json") {
|
|
72205
72152
|
const rewritten = { ...parsed.data, id: localExtId };
|
|
72206
|
-
await
|
|
72153
|
+
await import_promises13.default.writeFile(dest, JSON.stringify(rewritten, null, 2));
|
|
72207
72154
|
} else {
|
|
72208
|
-
await
|
|
72155
|
+
await import_promises13.default.writeFile(dest, await entry.async("nodebuffer"));
|
|
72209
72156
|
}
|
|
72210
72157
|
}
|
|
72211
|
-
await
|
|
72158
|
+
await import_promises13.default.rename(stage, liveDir);
|
|
72212
72159
|
} catch (e) {
|
|
72213
|
-
await
|
|
72160
|
+
await import_promises13.default.rm(stage, { recursive: true, force: true }).catch(() => {
|
|
72214
72161
|
});
|
|
72215
|
-
await
|
|
72162
|
+
await import_promises13.default.rename(prevDir, liveDir).catch(() => {
|
|
72216
72163
|
});
|
|
72217
72164
|
await deps.runtime.open(localExtId).catch(() => {
|
|
72218
72165
|
});
|
|
@@ -72234,7 +72181,7 @@ async function updateFromChannel(args, deps) {
|
|
|
72234
72181
|
reason: e.message
|
|
72235
72182
|
};
|
|
72236
72183
|
}
|
|
72237
|
-
await
|
|
72184
|
+
await import_promises13.default.rm(prevDir, { recursive: true, force: true });
|
|
72238
72185
|
return {
|
|
72239
72186
|
kind: "updated",
|
|
72240
72187
|
extId: localExtId,
|
|
@@ -72242,9 +72189,9 @@ async function updateFromChannel(args, deps) {
|
|
|
72242
72189
|
};
|
|
72243
72190
|
}
|
|
72244
72191
|
async function rollback(deps, localExtId, liveDir, prevDir) {
|
|
72245
|
-
await
|
|
72192
|
+
await import_promises13.default.rm(liveDir, { recursive: true, force: true }).catch(() => {
|
|
72246
72193
|
});
|
|
72247
|
-
await
|
|
72194
|
+
await import_promises13.default.rename(prevDir, liveDir).catch(() => {
|
|
72248
72195
|
});
|
|
72249
72196
|
await deps.runtime.open(localExtId).catch(() => {
|
|
72250
72197
|
});
|
|
@@ -72267,18 +72214,18 @@ async function rewriteManifestVersion(root, extId, newVersion, previousPublished
|
|
|
72267
72214
|
);
|
|
72268
72215
|
}
|
|
72269
72216
|
}
|
|
72270
|
-
const manifestPath =
|
|
72217
|
+
const manifestPath = import_node_path71.default.join(root, extId, "manifest.json");
|
|
72271
72218
|
const manifest = await readManifest(root, extId);
|
|
72272
72219
|
const next = { ...manifest, version: newVersion };
|
|
72273
72220
|
const tmp = `${manifestPath}.tmp`;
|
|
72274
|
-
await
|
|
72275
|
-
await
|
|
72221
|
+
await import_promises14.default.writeFile(tmp, JSON.stringify(next, null, 2));
|
|
72222
|
+
await import_promises14.default.rename(tmp, manifestPath);
|
|
72276
72223
|
}
|
|
72277
72224
|
async function readManifest(root, extId) {
|
|
72278
|
-
const file =
|
|
72225
|
+
const file = import_node_path71.default.join(root, extId, "manifest.json");
|
|
72279
72226
|
let raw;
|
|
72280
72227
|
try {
|
|
72281
|
-
raw = await
|
|
72228
|
+
raw = await import_promises14.default.readFile(file, "utf8");
|
|
72282
72229
|
} catch (e) {
|
|
72283
72230
|
if (e.code === "ENOENT") {
|
|
72284
72231
|
throw new ClawdError(ERROR_CODES.INVALID_PARAM, `extension ${extId} not installed`);
|
|
@@ -72359,7 +72306,7 @@ function buildExtensionHandlers(deps) {
|
|
|
72359
72306
|
};
|
|
72360
72307
|
async function buildSnapshotMeta(extId) {
|
|
72361
72308
|
const manifest = await readManifest(deps.root, extId);
|
|
72362
|
-
const { sha256, buffer } = await bundleExtensionDir(
|
|
72309
|
+
const { sha256, buffer } = await bundleExtensionDir(import_node_path71.default.join(deps.root, extId));
|
|
72363
72310
|
return { manifest, contentHash: sha256, buffer };
|
|
72364
72311
|
}
|
|
72365
72312
|
const publish = async (frame, _client, ctx) => {
|
|
@@ -72864,7 +72811,7 @@ function buildTopicHandlers(deps) {
|
|
|
72864
72811
|
init_protocol();
|
|
72865
72812
|
|
|
72866
72813
|
// src/channel/authority.ts
|
|
72867
|
-
var
|
|
72814
|
+
var import_promises15 = __toESM(require("fs/promises"), 1);
|
|
72868
72815
|
init_protocol();
|
|
72869
72816
|
var DEFAULT_AUTHORITY_RULES = [
|
|
72870
72817
|
{ id: "outbound-message", desc: "\u4EE5\u8001\u677F\u540D\u4E49\u7ED9\u5176\u4ED6\u4EBA\u53D1\u6D88\u606F\uFF08IM/\u90AE\u4EF6\uFF09", action: "ask" },
|
|
@@ -72882,7 +72829,7 @@ async function resolveAuthority(args) {
|
|
|
72882
72829
|
let source;
|
|
72883
72830
|
let raw = null;
|
|
72884
72831
|
try {
|
|
72885
|
-
raw = await
|
|
72832
|
+
raw = await import_promises15.default.readFile(args.tablePath, "utf8");
|
|
72886
72833
|
} catch (e) {
|
|
72887
72834
|
if (e.code !== "ENOENT") {
|
|
72888
72835
|
return askBecause(`\u6388\u6743\u8BBE\u5B9A\u8BFB\u4E0D\u51FA\u6765\uFF08${args.tablePath}\uFF09\uFF1A${e.message}`);
|
|
@@ -73186,12 +73133,12 @@ function buildVisitorHandlers(deps) {
|
|
|
73186
73133
|
}
|
|
73187
73134
|
|
|
73188
73135
|
// src/extension/registry.ts
|
|
73189
|
-
var
|
|
73190
|
-
var
|
|
73136
|
+
var import_promises16 = __toESM(require("fs/promises"), 1);
|
|
73137
|
+
var import_node_path72 = __toESM(require("path"), 1);
|
|
73191
73138
|
async function loadAll(root) {
|
|
73192
73139
|
let entries;
|
|
73193
73140
|
try {
|
|
73194
|
-
entries = await
|
|
73141
|
+
entries = await import_promises16.default.readdir(root, { withFileTypes: true });
|
|
73195
73142
|
} catch (e) {
|
|
73196
73143
|
if (e.code === "ENOENT") return [];
|
|
73197
73144
|
throw e;
|
|
@@ -73200,16 +73147,16 @@ async function loadAll(root) {
|
|
|
73200
73147
|
for (const ent of entries) {
|
|
73201
73148
|
if (!ent.isDirectory()) continue;
|
|
73202
73149
|
if (ent.name.startsWith(".")) continue;
|
|
73203
|
-
records.push(await loadOne(
|
|
73150
|
+
records.push(await loadOne(import_node_path72.default.join(root, ent.name), ent.name));
|
|
73204
73151
|
}
|
|
73205
73152
|
records.sort((a2, b3) => a2.extId < b3.extId ? -1 : a2.extId > b3.extId ? 1 : 0);
|
|
73206
73153
|
return records;
|
|
73207
73154
|
}
|
|
73208
73155
|
async function loadOne(dir, dirName) {
|
|
73209
|
-
const manifestPath =
|
|
73156
|
+
const manifestPath = import_node_path72.default.join(dir, "manifest.json");
|
|
73210
73157
|
let raw;
|
|
73211
73158
|
try {
|
|
73212
|
-
raw = await
|
|
73159
|
+
raw = await import_promises16.default.readFile(manifestPath, "utf8");
|
|
73213
73160
|
} catch {
|
|
73214
73161
|
return {
|
|
73215
73162
|
extId: dirName,
|
|
@@ -73250,8 +73197,8 @@ async function loadOne(dir, dirName) {
|
|
|
73250
73197
|
}
|
|
73251
73198
|
|
|
73252
73199
|
// src/extension/uninstall.ts
|
|
73253
|
-
var
|
|
73254
|
-
var
|
|
73200
|
+
var import_promises17 = __toESM(require("fs/promises"), 1);
|
|
73201
|
+
var import_node_path73 = __toESM(require("path"), 1);
|
|
73255
73202
|
var UninstallError = class extends Error {
|
|
73256
73203
|
constructor(code, message) {
|
|
73257
73204
|
super(message);
|
|
@@ -73260,32 +73207,32 @@ var UninstallError = class extends Error {
|
|
|
73260
73207
|
code;
|
|
73261
73208
|
};
|
|
73262
73209
|
async function uninstall(deps) {
|
|
73263
|
-
const dir =
|
|
73210
|
+
const dir = import_node_path73.default.join(deps.root, deps.extId);
|
|
73264
73211
|
try {
|
|
73265
|
-
await
|
|
73212
|
+
await import_promises17.default.access(dir);
|
|
73266
73213
|
} catch {
|
|
73267
73214
|
throw new UninstallError("NOT_FOUND", `extension ${deps.extId} not installed`);
|
|
73268
73215
|
}
|
|
73269
73216
|
await deps.runtime.close(deps.extId);
|
|
73270
|
-
await
|
|
73217
|
+
await import_promises17.default.rm(dir, { recursive: true, force: true });
|
|
73271
73218
|
}
|
|
73272
73219
|
|
|
73273
73220
|
// src/handlers/index.ts
|
|
73274
|
-
var
|
|
73221
|
+
var import_node_crypto23 = require("crypto");
|
|
73275
73222
|
|
|
73276
73223
|
// src/handlers/peer-exec.ts
|
|
73277
73224
|
init_protocol();
|
|
73278
73225
|
|
|
73279
73226
|
// src/peer-ops/run-command.ts
|
|
73280
73227
|
var import_node_child_process23 = require("child_process");
|
|
73281
|
-
var
|
|
73228
|
+
var import_node_os27 = __toESM(require("os"), 1);
|
|
73282
73229
|
var DEFAULT_TIMEOUT_MS6 = 3e4;
|
|
73283
73230
|
var MAX_TIMEOUT_MS = 3e5;
|
|
73284
73231
|
var MAX_OUTPUT_BYTES = 1048576;
|
|
73285
73232
|
function runCommand2(command, opts = {}) {
|
|
73286
73233
|
const timeoutMs = Math.min(opts.timeoutMs ?? DEFAULT_TIMEOUT_MS6, MAX_TIMEOUT_MS);
|
|
73287
73234
|
return new Promise((resolve9) => {
|
|
73288
|
-
const child = (0, import_node_child_process23.spawn)("bash", ["-c", command], { cwd:
|
|
73235
|
+
const child = (0, import_node_child_process23.spawn)("bash", ["-c", command], { cwd: import_node_os27.default.homedir() });
|
|
73289
73236
|
const out = [];
|
|
73290
73237
|
const err = [];
|
|
73291
73238
|
let outBytes = 0;
|
|
@@ -73426,7 +73373,7 @@ function buildMethodHandlers(deps) {
|
|
|
73426
73373
|
const c2 = deps.contactStore.get(deviceId);
|
|
73427
73374
|
return c2 ? { deviceId: c2.deviceId, remoteUrl: c2.remoteUrl, connectToken: c2.connectToken } : null;
|
|
73428
73375
|
},
|
|
73429
|
-
genId: () => (0,
|
|
73376
|
+
genId: () => (0, import_node_crypto23.randomUUID)(),
|
|
73430
73377
|
now: () => Date.now(),
|
|
73431
73378
|
forwardInboxPostToPeer,
|
|
73432
73379
|
logger: deps.logger
|
|
@@ -73475,7 +73422,7 @@ function buildMethodHandlers(deps) {
|
|
|
73475
73422
|
broadcast: deps.broadcastToOwners
|
|
73476
73423
|
}),
|
|
73477
73424
|
...buildMasterHandlers({
|
|
73478
|
-
authorityTablePath:
|
|
73425
|
+
authorityTablePath: import_node_path74.default.join(deps.masterDataDir, "master-authority.json")
|
|
73479
73426
|
}),
|
|
73480
73427
|
...buildTopicHandlers({
|
|
73481
73428
|
topicStore: deps.topicStore,
|
|
@@ -73618,8 +73565,8 @@ async function dispatchRpc(method, frame, client, ctx, deps) {
|
|
|
73618
73565
|
|
|
73619
73566
|
// src/extension/runtime.ts
|
|
73620
73567
|
var import_node_child_process24 = require("child_process");
|
|
73621
|
-
var
|
|
73622
|
-
var
|
|
73568
|
+
var import_node_path75 = __toESM(require("path"), 1);
|
|
73569
|
+
var import_promises18 = require("timers/promises");
|
|
73623
73570
|
|
|
73624
73571
|
// src/extension/port-allocator.ts
|
|
73625
73572
|
var import_node_net = __toESM(require("net"), 1);
|
|
@@ -73719,7 +73666,7 @@ var Runtime = class {
|
|
|
73719
73666
|
/\$CLAWOS_EXT_PORT/g,
|
|
73720
73667
|
String(port)
|
|
73721
73668
|
);
|
|
73722
|
-
const dir =
|
|
73669
|
+
const dir = import_node_path75.default.join(this.root, extId);
|
|
73723
73670
|
const env = {
|
|
73724
73671
|
...process.env,
|
|
73725
73672
|
CLAWOS_EXT_PORT: String(port),
|
|
@@ -73795,7 +73742,7 @@ ${handle.stderrTail}`
|
|
|
73795
73742
|
if (res.ok) return;
|
|
73796
73743
|
} catch {
|
|
73797
73744
|
}
|
|
73798
|
-
await (0,
|
|
73745
|
+
await (0, import_promises18.setTimeout)(this.healthzIntervalMs);
|
|
73799
73746
|
}
|
|
73800
73747
|
throw new RuntimeError(
|
|
73801
73748
|
"HEALTHZ_FAILED",
|
|
@@ -73820,7 +73767,7 @@ ${handle.stderrTail}`
|
|
|
73820
73767
|
};
|
|
73821
73768
|
killGroup("SIGTERM");
|
|
73822
73769
|
const exited = new Promise((resolve9) => child.once("exit", () => resolve9()));
|
|
73823
|
-
const timed = (0,
|
|
73770
|
+
const timed = (0, import_promises18.setTimeout)(5e3).then(() => "timeout");
|
|
73824
73771
|
const winner = await Promise.race([exited.then(() => "exited"), timed]);
|
|
73825
73772
|
if (winner === "timeout" && child.exitCode === null) {
|
|
73826
73773
|
killGroup("SIGKILL");
|
|
@@ -73830,8 +73777,8 @@ ${handle.stderrTail}`
|
|
|
73830
73777
|
};
|
|
73831
73778
|
|
|
73832
73779
|
// src/extension/published-channels.ts
|
|
73833
|
-
var
|
|
73834
|
-
var
|
|
73780
|
+
var import_promises19 = __toESM(require("fs/promises"), 1);
|
|
73781
|
+
var import_node_path76 = __toESM(require("path"), 1);
|
|
73835
73782
|
init_zod();
|
|
73836
73783
|
var PublishedChannelsError = class extends Error {
|
|
73837
73784
|
constructor(code, message) {
|
|
@@ -73861,7 +73808,7 @@ var PublishedChannelStore = class {
|
|
|
73861
73808
|
this.channels.clear();
|
|
73862
73809
|
let raw;
|
|
73863
73810
|
try {
|
|
73864
|
-
raw = await
|
|
73811
|
+
raw = await import_promises19.default.readFile(this.filePath, "utf8");
|
|
73865
73812
|
} catch (e) {
|
|
73866
73813
|
if (e.code === "ENOENT") {
|
|
73867
73814
|
this.loaded = true;
|
|
@@ -73930,15 +73877,15 @@ var PublishedChannelStore = class {
|
|
|
73930
73877
|
)
|
|
73931
73878
|
};
|
|
73932
73879
|
const tmp = `${this.filePath}.tmp`;
|
|
73933
|
-
await
|
|
73934
|
-
await
|
|
73935
|
-
await
|
|
73880
|
+
await import_promises19.default.mkdir(import_node_path76.default.dirname(this.filePath), { recursive: true });
|
|
73881
|
+
await import_promises19.default.writeFile(tmp, JSON.stringify(data, null, 2), { mode: 384 });
|
|
73882
|
+
await import_promises19.default.rename(tmp, this.filePath);
|
|
73936
73883
|
}
|
|
73937
73884
|
};
|
|
73938
73885
|
|
|
73939
73886
|
// src/extension/bundle-cache.ts
|
|
73940
|
-
var
|
|
73941
|
-
var
|
|
73887
|
+
var import_promises20 = __toESM(require("fs/promises"), 1);
|
|
73888
|
+
var import_node_path77 = __toESM(require("path"), 1);
|
|
73942
73889
|
var BundleCache = class {
|
|
73943
73890
|
constructor(rootDir) {
|
|
73944
73891
|
this.rootDir = rootDir;
|
|
@@ -73946,17 +73893,17 @@ var BundleCache = class {
|
|
|
73946
73893
|
rootDir;
|
|
73947
73894
|
/** Atomic write: stage tmp → rename. Caller passes the hex sha256. */
|
|
73948
73895
|
async write(snapshotHash, buffer) {
|
|
73949
|
-
await
|
|
73950
|
-
const file =
|
|
73896
|
+
await import_promises20.default.mkdir(this.rootDir, { recursive: true });
|
|
73897
|
+
const file = import_node_path77.default.join(this.rootDir, `${snapshotHash}.zip`);
|
|
73951
73898
|
const tmp = `${file}.tmp`;
|
|
73952
|
-
await
|
|
73953
|
-
await
|
|
73899
|
+
await import_promises20.default.writeFile(tmp, buffer, { mode: 384 });
|
|
73900
|
+
await import_promises20.default.rename(tmp, file);
|
|
73954
73901
|
}
|
|
73955
73902
|
/** Returns the bundle bytes, or null when the file doesn't exist. */
|
|
73956
73903
|
async read(snapshotHash) {
|
|
73957
|
-
const file =
|
|
73904
|
+
const file = import_node_path77.default.join(this.rootDir, `${snapshotHash}.zip`);
|
|
73958
73905
|
try {
|
|
73959
|
-
return await
|
|
73906
|
+
return await import_promises20.default.readFile(file);
|
|
73960
73907
|
} catch (e) {
|
|
73961
73908
|
if (e.code === "ENOENT") return null;
|
|
73962
73909
|
throw e;
|
|
@@ -73964,8 +73911,8 @@ var BundleCache = class {
|
|
|
73964
73911
|
}
|
|
73965
73912
|
/** Idempotent — missing file is not an error. */
|
|
73966
73913
|
async delete(snapshotHash) {
|
|
73967
|
-
const file =
|
|
73968
|
-
await
|
|
73914
|
+
const file = import_node_path77.default.join(this.rootDir, `${snapshotHash}.zip`);
|
|
73915
|
+
await import_promises20.default.rm(file, { force: true });
|
|
73969
73916
|
}
|
|
73970
73917
|
};
|
|
73971
73918
|
|
|
@@ -73985,26 +73932,26 @@ async function startDaemon(config) {
|
|
|
73985
73932
|
},
|
|
73986
73933
|
source: "daemon",
|
|
73987
73934
|
sampling: logShippingCfg.sampling,
|
|
73988
|
-
homeDir:
|
|
73935
|
+
homeDir: import_node_os28.default.homedir()
|
|
73989
73936
|
});
|
|
73990
|
-
const logDir =
|
|
73991
|
-
|
|
73937
|
+
const logDir = import_node_path78.default.join(config.dataDir, "log");
|
|
73938
|
+
import_node_fs60.default.mkdirSync(logDir, { recursive: true });
|
|
73992
73939
|
const logger = createLogger({
|
|
73993
73940
|
level: config.logLevel,
|
|
73994
|
-
file:
|
|
73941
|
+
file: import_node_path78.default.join(logDir, "clawd.log"),
|
|
73995
73942
|
logClient
|
|
73996
73943
|
});
|
|
73997
73944
|
logger.info("starting clawd", { version, config: { port: config.port, host: config.host, dataDir: config.dataDir } });
|
|
73998
73945
|
const screenIdleProbeLogger = createFileOnlyLogger({
|
|
73999
|
-
file:
|
|
73946
|
+
file: import_node_path78.default.join(logDir, "screen-idle-probe.log"),
|
|
74000
73947
|
level: "debug"
|
|
74001
73948
|
});
|
|
74002
73949
|
logger.info("screen-idle probe logger enabled", {
|
|
74003
|
-
file:
|
|
73950
|
+
file: import_node_path78.default.join(logDir, "screen-idle-probe.log")
|
|
74004
73951
|
});
|
|
74005
73952
|
const CAP_TARGETS = [
|
|
74006
|
-
|
|
74007
|
-
|
|
73953
|
+
import_node_path78.default.join(logDir, "clawd.log"),
|
|
73954
|
+
import_node_path78.default.join(logDir, "screen-idle-probe.log")
|
|
74008
73955
|
];
|
|
74009
73956
|
const LOG_CAP_MAX_BYTES = 10 * 1024 * 1024;
|
|
74010
73957
|
const LOG_CAP_KEEP_BYTES = 5 * 1024 * 1024;
|
|
@@ -74126,8 +74073,8 @@ async function startDaemon(config) {
|
|
|
74126
74073
|
const agents = new AgentsScanner();
|
|
74127
74074
|
const history = new ClaudeHistoryReader();
|
|
74128
74075
|
let transport = null;
|
|
74129
|
-
const personaStore = new PersonaStore(
|
|
74130
|
-
const usersRoot =
|
|
74076
|
+
const personaStore = new PersonaStore(import_node_path78.default.join(config.dataDir, "personas"));
|
|
74077
|
+
const usersRoot = import_node_path78.default.join(config.dataDir, "users");
|
|
74131
74078
|
const defaultsRoot = findDefaultsRoot(logger);
|
|
74132
74079
|
if (defaultsRoot) {
|
|
74133
74080
|
seedDefaultPersonas({ store: personaStore, defaultsRoot, logger });
|
|
@@ -74144,7 +74091,7 @@ async function startDaemon(config) {
|
|
|
74144
74091
|
retirePersonaBuilder({ store: personaStore, logger });
|
|
74145
74092
|
const groupFileStore = new GroupFileStore({ dataDir: config.dataDir, logger });
|
|
74146
74093
|
const dispatchStore = createDispatchStore({
|
|
74147
|
-
filePath:
|
|
74094
|
+
filePath: import_node_path78.default.join(config.dataDir, "dispatch.json"),
|
|
74148
74095
|
now: () => Date.now(),
|
|
74149
74096
|
onFlushError: (err) => logger.error("dispatch store flush failed", {
|
|
74150
74097
|
reason: err instanceof Error ? err.message : String(err)
|
|
@@ -74153,18 +74100,18 @@ async function startDaemon(config) {
|
|
|
74153
74100
|
await dispatchStore.load();
|
|
74154
74101
|
dispatchStore.markInterruptedAsFailed((/* @__PURE__ */ new Date()).toISOString());
|
|
74155
74102
|
const channelStore = createChannelStore({
|
|
74156
|
-
filePath:
|
|
74103
|
+
filePath: import_node_path78.default.join(config.dataDir, "channels.json"),
|
|
74157
74104
|
now: () => Date.now(),
|
|
74158
|
-
genId: () => `ch-${(0,
|
|
74105
|
+
genId: () => `ch-${(0, import_node_crypto24.randomUUID)().slice(0, 8)}`,
|
|
74159
74106
|
onFlushError: (err) => logger.error("channel store flush failed", {
|
|
74160
74107
|
reason: err instanceof Error ? err.message : String(err)
|
|
74161
74108
|
})
|
|
74162
74109
|
});
|
|
74163
74110
|
await channelStore.load();
|
|
74164
74111
|
const topicStore = createTopicStore({
|
|
74165
|
-
filePath:
|
|
74112
|
+
filePath: import_node_path78.default.join(config.dataDir, "topics.json"),
|
|
74166
74113
|
now: () => Date.now(),
|
|
74167
|
-
genId: () => `tp-${(0,
|
|
74114
|
+
genId: () => `tp-${(0, import_node_crypto24.randomUUID)().slice(0, 8)}`,
|
|
74168
74115
|
onFlushError: (err) => logger.error("topic store flush failed", {
|
|
74169
74116
|
reason: err instanceof Error ? err.message : String(err)
|
|
74170
74117
|
})
|
|
@@ -74172,7 +74119,7 @@ async function startDaemon(config) {
|
|
|
74172
74119
|
await topicStore.load();
|
|
74173
74120
|
let deliverPendingRef;
|
|
74174
74121
|
const personaDispatchManager = new PersonaDispatchManager({
|
|
74175
|
-
genId: () => (0,
|
|
74122
|
+
genId: () => (0, import_node_crypto24.randomUUID)(),
|
|
74176
74123
|
store: dispatchStore,
|
|
74177
74124
|
now: () => Date.now(),
|
|
74178
74125
|
onCompleted: (sid) => deliverPendingRef?.(sid),
|
|
@@ -74189,12 +74136,12 @@ async function startDaemon(config) {
|
|
|
74189
74136
|
});
|
|
74190
74137
|
}
|
|
74191
74138
|
});
|
|
74192
|
-
const here = typeof __dirname === "string" ? __dirname :
|
|
74139
|
+
const here = typeof __dirname === "string" ? __dirname : import_node_path78.default.dirname((0, import_node_url5.fileURLToPath)(import_meta9.url));
|
|
74193
74140
|
const mcpConfigs = [];
|
|
74194
74141
|
const secretsBundleRoot = findSecretsBundleRoot(logger);
|
|
74195
|
-
const localSecretsDir =
|
|
74142
|
+
const localSecretsDir = import_node_path78.default.join(config.dataDir, LOCAL_SECRETS_DIRNAME);
|
|
74196
74143
|
const readSecrets = () => readSecretTable({ bundleRoot: secretsBundleRoot, overrideDir: localSecretsDir, logger });
|
|
74197
|
-
const githubTokenFile =
|
|
74144
|
+
const githubTokenFile = import_node_path78.default.join(localSecretsDir, GITHUB_TOKEN_FILE);
|
|
74198
74145
|
const githubIdentity = createGithubIdentity({
|
|
74199
74146
|
resolve: () => resolveGithubAuth({ exec: runCommand, fileToken: () => readEnvFileVar(githubTokenFile, GITHUB_TOKEN_VAR) }),
|
|
74200
74147
|
store: (token) => storeGithubAuth({
|
|
@@ -74232,22 +74179,22 @@ async function startDaemon(config) {
|
|
|
74232
74179
|
void githubIdentity.refresh();
|
|
74233
74180
|
return renderPersonaMcpSecrets({
|
|
74234
74181
|
personaId: personaId2,
|
|
74235
|
-
personaDir:
|
|
74182
|
+
personaDir: import_node_path78.default.join(config.dataDir, "personas", personaId2),
|
|
74236
74183
|
secrets,
|
|
74237
|
-
outDir:
|
|
74184
|
+
outDir: import_node_path78.default.join(config.dataDir, "persona-mcp"),
|
|
74238
74185
|
logger
|
|
74239
74186
|
});
|
|
74240
74187
|
};
|
|
74241
74188
|
const mcpDaemonUrl = `http://127.0.0.1:${config.port}`;
|
|
74242
74189
|
const dispatchServerCandidates = [
|
|
74243
|
-
|
|
74190
|
+
import_node_path78.default.join(here, "dispatch", "mcp-server.cjs"),
|
|
74244
74191
|
// 生产 dist/index → dist/dispatch/mcp-server.cjs
|
|
74245
|
-
|
|
74192
|
+
import_node_path78.default.join(here, "..", "dist", "dispatch", "mcp-server.cjs")
|
|
74246
74193
|
// dev tsx src/index → ../dist/dispatch/mcp-server.cjs
|
|
74247
74194
|
];
|
|
74248
|
-
const dispatchServerScriptPath = dispatchServerCandidates.find((p3) =>
|
|
74195
|
+
const dispatchServerScriptPath = dispatchServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74249
74196
|
if (dispatchServerScriptPath) {
|
|
74250
|
-
const dispatchLogPath =
|
|
74197
|
+
const dispatchLogPath = import_node_path78.default.join(logDir, "dispatch-mcp-server.log");
|
|
74251
74198
|
const dispatchCfgPath = writeDispatchMcpConfig({
|
|
74252
74199
|
dataDir: config.dataDir,
|
|
74253
74200
|
serverScriptPath: dispatchServerScriptPath,
|
|
@@ -74267,12 +74214,12 @@ async function startDaemon(config) {
|
|
|
74267
74214
|
});
|
|
74268
74215
|
}
|
|
74269
74216
|
const ticketServerCandidates = [
|
|
74270
|
-
|
|
74271
|
-
|
|
74217
|
+
import_node_path78.default.join(here, "ticket", "mcp-server.cjs"),
|
|
74218
|
+
import_node_path78.default.join(here, "..", "dist", "ticket", "mcp-server.cjs")
|
|
74272
74219
|
];
|
|
74273
|
-
const ticketServerScriptPath = ticketServerCandidates.find((p3) =>
|
|
74220
|
+
const ticketServerScriptPath = ticketServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74274
74221
|
if (ticketServerScriptPath) {
|
|
74275
|
-
const ticketLogPath =
|
|
74222
|
+
const ticketLogPath = import_node_path78.default.join(logDir, "ticket-mcp-server.log");
|
|
74276
74223
|
const ticketCfgPath = writeTicketMcpConfig({
|
|
74277
74224
|
dataDir: config.dataDir,
|
|
74278
74225
|
serverScriptPath: ticketServerScriptPath,
|
|
@@ -74294,12 +74241,12 @@ async function startDaemon(config) {
|
|
|
74294
74241
|
});
|
|
74295
74242
|
}
|
|
74296
74243
|
const shiftServerCandidates = [
|
|
74297
|
-
|
|
74298
|
-
|
|
74244
|
+
import_node_path78.default.join(here, "shift", "mcp-server.cjs"),
|
|
74245
|
+
import_node_path78.default.join(here, "..", "dist", "shift", "mcp-server.cjs")
|
|
74299
74246
|
];
|
|
74300
|
-
const shiftServerScriptPath = shiftServerCandidates.find((p3) =>
|
|
74247
|
+
const shiftServerScriptPath = shiftServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74301
74248
|
if (shiftServerScriptPath) {
|
|
74302
|
-
const shiftLogPath =
|
|
74249
|
+
const shiftLogPath = import_node_path78.default.join(logDir, "shift-mcp-server.log");
|
|
74303
74250
|
const shiftCfgPath = await writeShiftMcpConfig({
|
|
74304
74251
|
dataDir: config.dataDir,
|
|
74305
74252
|
serverScriptPath: shiftServerScriptPath,
|
|
@@ -74320,12 +74267,12 @@ async function startDaemon(config) {
|
|
|
74320
74267
|
);
|
|
74321
74268
|
}
|
|
74322
74269
|
const inboxServerCandidates = [
|
|
74323
|
-
|
|
74324
|
-
|
|
74270
|
+
import_node_path78.default.join(here, "inbox", "mcp-server.cjs"),
|
|
74271
|
+
import_node_path78.default.join(here, "..", "dist", "inbox", "mcp-server.cjs")
|
|
74325
74272
|
];
|
|
74326
|
-
const inboxServerScriptPath = inboxServerCandidates.find((p3) =>
|
|
74273
|
+
const inboxServerScriptPath = inboxServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74327
74274
|
if (inboxServerScriptPath) {
|
|
74328
|
-
const inboxLogPath =
|
|
74275
|
+
const inboxLogPath = import_node_path78.default.join(logDir, "inbox-mcp-server.log");
|
|
74329
74276
|
const inboxCfgPath = await writeInboxMcpConfig({
|
|
74330
74277
|
dataDir: config.dataDir,
|
|
74331
74278
|
serverScriptPath: inboxServerScriptPath,
|
|
@@ -74346,10 +74293,10 @@ async function startDaemon(config) {
|
|
|
74346
74293
|
);
|
|
74347
74294
|
}
|
|
74348
74295
|
const peerOpsServerCandidates = [
|
|
74349
|
-
|
|
74350
|
-
|
|
74296
|
+
import_node_path78.default.join(here, "peer-ops", "mcp-server.cjs"),
|
|
74297
|
+
import_node_path78.default.join(here, "..", "dist", "peer-ops", "mcp-server.cjs")
|
|
74351
74298
|
];
|
|
74352
|
-
const peerOpsServerScriptPath = peerOpsServerCandidates.find((p3) =>
|
|
74299
|
+
const peerOpsServerScriptPath = peerOpsServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74353
74300
|
if (peerOpsServerScriptPath) {
|
|
74354
74301
|
const peerOpsCfgPath = writePeerOpsMcpConfig({
|
|
74355
74302
|
dataDir: config.dataDir,
|
|
@@ -74369,12 +74316,12 @@ async function startDaemon(config) {
|
|
|
74369
74316
|
);
|
|
74370
74317
|
}
|
|
74371
74318
|
const rpcToolServerCandidates = [
|
|
74372
|
-
|
|
74373
|
-
|
|
74319
|
+
import_node_path78.default.join(here, "rpc-tool", "mcp-server.cjs"),
|
|
74320
|
+
import_node_path78.default.join(here, "..", "dist", "rpc-tool", "mcp-server.cjs")
|
|
74374
74321
|
];
|
|
74375
|
-
const rpcToolServerScriptPath = rpcToolServerCandidates.find((p3) =>
|
|
74322
|
+
const rpcToolServerScriptPath = rpcToolServerCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74376
74323
|
if (rpcToolServerScriptPath) {
|
|
74377
|
-
const rpcToolLogPath =
|
|
74324
|
+
const rpcToolLogPath = import_node_path78.default.join(logDir, "rpc-tool-mcp-server.log");
|
|
74378
74325
|
const rpcToolCfgPath = writeRpcToolMcpConfig({
|
|
74379
74326
|
dataDir: config.dataDir,
|
|
74380
74327
|
serverScriptPath: rpcToolServerScriptPath,
|
|
@@ -74395,7 +74342,7 @@ async function startDaemon(config) {
|
|
|
74395
74342
|
);
|
|
74396
74343
|
}
|
|
74397
74344
|
const shiftStore = createShiftStore({
|
|
74398
|
-
filePath:
|
|
74345
|
+
filePath: import_node_path78.default.join(config.dataDir, "shift.json"),
|
|
74399
74346
|
ownerIdProvider: () => ownerPrincipalId,
|
|
74400
74347
|
now: () => Date.now()
|
|
74401
74348
|
});
|
|
@@ -74417,7 +74364,7 @@ async function startDaemon(config) {
|
|
|
74417
74364
|
getAdapter,
|
|
74418
74365
|
historyReader: history,
|
|
74419
74366
|
dataDir: config.dataDir,
|
|
74420
|
-
personaRoot:
|
|
74367
|
+
personaRoot: import_node_path78.default.join(config.dataDir, "personas"),
|
|
74421
74368
|
// dispatch / shift 自动化 spawn 按 persona 绑定 tool 起 B session(codex persona 用 codex)。
|
|
74422
74369
|
// personaRegistry 声明在 manager 之后(同作用域 const,调用时机在启动完成后,无 TDZ 风险)。
|
|
74423
74370
|
getPersonaDefaults: (personaId2) => personaRegistry.get(personaId2),
|
|
@@ -74474,10 +74421,10 @@ async function startDaemon(config) {
|
|
|
74474
74421
|
// 文件可能 agent 写完又被自己删(罕见),用 size=0 / fallback mime 兜底。
|
|
74475
74422
|
attachmentGroup: {
|
|
74476
74423
|
onFileEdit: (input) => {
|
|
74477
|
-
const absPath =
|
|
74424
|
+
const absPath = import_node_path78.default.isAbsolute(input.relPath) ? input.relPath : import_node_path78.default.join(input.cwd, input.relPath);
|
|
74478
74425
|
let size = 0;
|
|
74479
74426
|
try {
|
|
74480
|
-
size =
|
|
74427
|
+
size = import_node_fs60.default.statSync(absPath).size;
|
|
74481
74428
|
} catch (err) {
|
|
74482
74429
|
logger.warn("attachment.onFileEdit stat failed", {
|
|
74483
74430
|
sessionId: input.sessionId,
|
|
@@ -74518,9 +74465,9 @@ async function startDaemon(config) {
|
|
|
74518
74465
|
logger.info("projects.seed-dropped", { dropped: droppedSeed.dropped, backup: droppedSeed.backup });
|
|
74519
74466
|
}
|
|
74520
74467
|
const projectsStore = new ProjectsStore({
|
|
74521
|
-
file:
|
|
74468
|
+
file: import_node_path78.default.join(config.dataDir, "projects.json"),
|
|
74522
74469
|
clawdDir: config.dataDir,
|
|
74523
|
-
codexStateFile:
|
|
74470
|
+
codexStateFile: import_node_path78.default.join(import_node_os28.default.homedir(), ".codex", ".codex-global-state.json"),
|
|
74524
74471
|
logger
|
|
74525
74472
|
});
|
|
74526
74473
|
const observer = new SessionObserver({
|
|
@@ -74585,13 +74532,13 @@ async function startDaemon(config) {
|
|
|
74585
74532
|
logger
|
|
74586
74533
|
});
|
|
74587
74534
|
registerAdapter("claude", claudeAdapter);
|
|
74588
|
-
const codexIsolatedHome =
|
|
74535
|
+
const codexIsolatedHome = import_node_path78.default.join(config.dataDir, "codex-home");
|
|
74589
74536
|
try {
|
|
74590
|
-
|
|
74537
|
+
import_node_fs60.default.mkdirSync(codexIsolatedHome, { recursive: true });
|
|
74591
74538
|
for (const f2 of ["auth.json", "config.toml"]) {
|
|
74592
|
-
const link =
|
|
74593
|
-
const target =
|
|
74594
|
-
if (!
|
|
74539
|
+
const link = import_node_path78.default.join(codexIsolatedHome, f2);
|
|
74540
|
+
const target = import_node_path78.default.join(import_node_os28.default.homedir(), ".codex", f2);
|
|
74541
|
+
if (!import_node_fs60.default.existsSync(link) && import_node_fs60.default.existsSync(target)) import_node_fs60.default.symlinkSync(target, link);
|
|
74595
74542
|
}
|
|
74596
74543
|
} catch (err) {
|
|
74597
74544
|
logger.warn("codex isolated home setup failed", { err: String(err) });
|
|
@@ -74602,17 +74549,17 @@ async function startDaemon(config) {
|
|
|
74602
74549
|
logger,
|
|
74603
74550
|
historyReader: new CodexHistoryReader({
|
|
74604
74551
|
roots: codexRolloutRoots(config.dataDir),
|
|
74605
|
-
sharedHome:
|
|
74552
|
+
sharedHome: import_node_path78.default.join(import_node_os28.default.homedir(), ".codex"),
|
|
74606
74553
|
logger
|
|
74607
74554
|
}),
|
|
74608
74555
|
// projectPaths 每次调用现取 —— 用户新建 project 后立即生效,不用重启 daemon
|
|
74609
74556
|
codexHomeFor: (cwd) => resolveCodexHome({
|
|
74610
74557
|
cwd,
|
|
74611
|
-
personaRoot:
|
|
74558
|
+
personaRoot: import_node_path78.default.join(config.dataDir, "personas"),
|
|
74612
74559
|
// 必须用 listMerged(Codex registry ∪ 叠加层):只用本地 list() 的话,用户在
|
|
74613
74560
|
// Codex 里建的 project 不在表里,在它下面开的会话会被误判成隔离 → Codex 侧看不到
|
|
74614
74561
|
projectPaths: projectsStore.listMerged().map((x2) => x2.path),
|
|
74615
|
-
sharedHome:
|
|
74562
|
+
sharedHome: import_node_path78.default.join(import_node_os28.default.homedir(), ".codex"),
|
|
74616
74563
|
isolatedHome: codexIsolatedHome
|
|
74617
74564
|
}),
|
|
74618
74565
|
// 附件图片验签:与 http-router /files 路由同一把 secret
|
|
@@ -74637,10 +74584,10 @@ async function startDaemon(config) {
|
|
|
74637
74584
|
);
|
|
74638
74585
|
registerAdapter(PI_CLOUD_TOOL_ID, new CloudPiAdapter({ client: cloudGateway, history: cloudHistorySource, logger }));
|
|
74639
74586
|
const piMcpBridgeCandidates = [
|
|
74640
|
-
|
|
74641
|
-
|
|
74587
|
+
import_node_path78.default.join(here, "pi-mcp-bridge", "extension.cjs"),
|
|
74588
|
+
import_node_path78.default.join(here, "..", "dist", "pi-mcp-bridge", "extension.cjs")
|
|
74642
74589
|
];
|
|
74643
|
-
const piMcpBridgePath = piMcpBridgeCandidates.find((p3) =>
|
|
74590
|
+
const piMcpBridgePath = piMcpBridgeCandidates.find((p3) => import_node_fs60.default.existsSync(p3));
|
|
74644
74591
|
if (piMcpBridgePath) {
|
|
74645
74592
|
logger.info("pi-mcp-bridge extension resolved", { path: piMcpBridgePath });
|
|
74646
74593
|
} else {
|
|
@@ -74935,11 +74882,11 @@ async function startDaemon(config) {
|
|
|
74935
74882
|
// 'persona/<pid>/owner',default 走 'default'。
|
|
74936
74883
|
getSessionScope: (sid) => manager.findOwnedSessionScope(sid),
|
|
74937
74884
|
// guest path guard:candidate 必须在 personaRoot 子树或调用者自己的 user-dir 下
|
|
74938
|
-
personaRoot:
|
|
74885
|
+
personaRoot: import_node_path78.default.join(config.dataDir, "personas"),
|
|
74939
74886
|
usersRoot
|
|
74940
74887
|
},
|
|
74941
74888
|
// workspace/git/history/skills/agents handler 共用的 guest path guard 锚点
|
|
74942
|
-
personaRoot:
|
|
74889
|
+
personaRoot: import_node_path78.default.join(config.dataDir, "personas"),
|
|
74943
74890
|
// v2 多人 persona 隔离:handler 派生 guest user-dir 放行
|
|
74944
74891
|
usersRoot,
|
|
74945
74892
|
// v2 Phase 6: whoami handler 装在 owner principal.displayName + persona 解析
|
|
@@ -75080,7 +75027,7 @@ async function startDaemon(config) {
|
|
|
75080
75027
|
sourceSessionId: args.sourceSessionId
|
|
75081
75028
|
});
|
|
75082
75029
|
const sourceFile = manager.findOwnedSession(args.sourceSessionId);
|
|
75083
|
-
const sourceJsonlPath = resolveSourceJsonlPath(sourceFile,
|
|
75030
|
+
const sourceJsonlPath = resolveSourceJsonlPath(sourceFile, import_node_os28.default.homedir());
|
|
75084
75031
|
logger.info("dispatch.spawnB.source-resolved", {
|
|
75085
75032
|
dispatchId: args.dispatchId,
|
|
75086
75033
|
sourceJsonlPath,
|
|
@@ -75172,7 +75119,6 @@ async function startDaemon(config) {
|
|
|
75172
75119
|
}
|
|
75173
75120
|
return probeLocalVersion(runCommand, pkg);
|
|
75174
75121
|
},
|
|
75175
|
-
fetchArtifact: downloadArtifact(runCommand),
|
|
75176
75122
|
githubIdentity,
|
|
75177
75123
|
githubApi: (token) => createGithubApi({ token }),
|
|
75178
75124
|
org: PERSONA_REPO_ORG,
|
|
@@ -75218,7 +75164,7 @@ async function startDaemon(config) {
|
|
|
75218
75164
|
});
|
|
75219
75165
|
shiftScheduler.start();
|
|
75220
75166
|
logger.info("shift scheduler started", { shiftCount: shiftStore.list().length });
|
|
75221
|
-
const larkBotStore = createLarkBotBindingStore(
|
|
75167
|
+
const larkBotStore = createLarkBotBindingStore(import_node_path78.default.join(config.dataDir, "personas"));
|
|
75222
75168
|
const larkBotCloud = createLarkBotCloudClient({
|
|
75223
75169
|
api: config.clawosApi ?? DEFAULT_CLAWOS_API,
|
|
75224
75170
|
getLoginPass: () => ownerIdentityStore.read()?.loginPass ?? null
|
|
@@ -75230,7 +75176,7 @@ async function startDaemon(config) {
|
|
|
75230
75176
|
store: larkBotStore,
|
|
75231
75177
|
fetchResource: (appId, messageId, fileKey, maxBytes, type) => larkBotCloud.fetchResource(appId, messageId, fileKey, maxBytes, type),
|
|
75232
75178
|
// 图片落 guest userWorkDir 下(capId = lark-<chat_id>):CC 经 --add-dir + allowRead carve 可 Read
|
|
75233
|
-
mediaRootFor: (chatId) =>
|
|
75179
|
+
mediaRootFor: (chatId) => import_node_path78.default.join(deriveUserWorkDir(`lark-${chatId}`, usersRoot), "lark-media"),
|
|
75234
75180
|
isShuttingDown: () => larkDraining,
|
|
75235
75181
|
logger: {
|
|
75236
75182
|
warn: (msg) => logger.warn(msg),
|
|
@@ -75514,8 +75460,8 @@ async function startDaemon(config) {
|
|
|
75514
75460
|
const lines = [
|
|
75515
75461
|
`Tunnel: ${r2.url}`,
|
|
75516
75462
|
...resolvedAuthToken ? [`Connect: ${connectUrl}`] : [],
|
|
75517
|
-
`Frpc config: ${
|
|
75518
|
-
`Frpc log: ${
|
|
75463
|
+
`Frpc config: ${import_node_path78.default.join(config.dataDir, "frpc.toml")}`,
|
|
75464
|
+
`Frpc log: ${import_node_path78.default.join(logDir, "frpc.log")}`
|
|
75519
75465
|
];
|
|
75520
75466
|
const width2 = Math.max(...lines.map((l2) => l2.length));
|
|
75521
75467
|
const bar = "\u2550".repeat(width2 + 4);
|
|
@@ -75528,8 +75474,8 @@ ${bar}
|
|
|
75528
75474
|
|
|
75529
75475
|
`);
|
|
75530
75476
|
try {
|
|
75531
|
-
const connectPath =
|
|
75532
|
-
|
|
75477
|
+
const connectPath = import_node_path78.default.join(config.dataDir, "connect.txt");
|
|
75478
|
+
import_node_fs60.default.writeFileSync(connectPath, lines.join("\n") + "\n", { mode: 384 });
|
|
75533
75479
|
} catch {
|
|
75534
75480
|
}
|
|
75535
75481
|
} catch (err) {
|
|
@@ -75627,9 +75573,9 @@ ${bar}
|
|
|
75627
75573
|
};
|
|
75628
75574
|
}
|
|
75629
75575
|
function migrateDropPersonsDir(dataDir) {
|
|
75630
|
-
const dir =
|
|
75576
|
+
const dir = import_node_path78.default.join(dataDir, "persons");
|
|
75631
75577
|
try {
|
|
75632
|
-
|
|
75578
|
+
import_node_fs60.default.rmSync(dir, { recursive: true, force: true });
|
|
75633
75579
|
} catch {
|
|
75634
75580
|
}
|
|
75635
75581
|
}
|