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