@clawos-dev/clawd 0.2.133-beta.276.da37eee → 0.2.133-beta.277.252bfcb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +406 -1126
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -4579,7 +4579,7 @@ var init_persona_schemas = __esm({
|
|
|
4579
4579
|
});
|
|
4580
4580
|
|
|
4581
4581
|
// ../protocol/src/schemas.ts
|
|
4582
|
-
var SessionStatusSchema, UsageSchema, ContextUsageSchema, sessionMetaShape, SessionMetaSchema, ModelInfoSchema, ModeInfoSchema, ConfigFieldSchemaSchema, CapabilitiesGetArgs,
|
|
4582
|
+
var SessionStatusSchema, UsageSchema, ContextUsageSchema, sessionMetaShape, SessionMetaSchema, ModelInfoSchema, ModeInfoSchema, ConfigFieldSchemaSchema, CapabilitiesGetArgs, CapabilitiesResponseSchema, AllowRuleSchema, SessionFileSchema, ParsedEventBase, HistoryUserMetaSchema, SubagentToolStatsSchema, StructuredPatchHunkSchema, ToolResultExtraSchema, MemoryEntrySchema, AskQuestionOptionSchema, AskQuestionItemSchema, ParsedEventSchema, SessionCreateArgs, SessionIdArgs, SessionUpdateArgs, SessionSendArgs, SessionRewindArgs, SessionRewindResponseSchema, SessionRewindDiffArgs, RewindDiffHunkSchema, RewindDiffFileSchema, SessionRewindDiffResponseSchema, SessionRewindableMessageIdsArgs, SessionRewindableMessageIdsResponseSchema, SessionResumeArgs, SessionForkArgs, SessionForkResponseSchema, SessionObserveArgs, SessionEventsArgs, PermissionRespondArgs, HistoryListArgs, HistoryReadArgs, HistorySubagentsArgs, HistorySubagentReadArgs, WorkspaceListArgs, WorkspaceReadArgs, SkillsListArgs, SkillEntrySchema, AgentEntrySchema, AgentsListArgs, AgentsListResponseSchema, SessionSubscribeArgs, SessionPinArgs, PeerSessionUpsertArgs, PeerSessionUpsertResponseSchema, PeerSessionRemoveArgs, PeerSessionRemoveResponseSchema, SessionReorderPinsArgs, GitRootArgs, GitRootResponseSchema, GitBranchArgs, GitBranchResponseSchema, GitBranchesArgs, GitBranchesResponseSchema, HistoryRecentDirsArgs, RecentDirEntrySchema, HistoryRecentDirsResponseSchema, SessionQuestionFrameSchema, SessionQuestionClearedFrameSchema, AnswerQuestionArgs, AnswerQuestionResponseSchema, CancelQuestionArgs, CancelQuestionResponseSchema, AuthRequestFrameSchema, AuthOkFrameSchema, TunnelReadyEventSchema, TunnelExitedEventSchema, TunnelUnavailableEventSchema, InfoRunningSessionSchema, InfoResponseSchema, PROJECT_PORT_MIN, PROJECT_PORT_MAX, projectNameRegex, DEFAULT_DEV_COMMAND, ProjectMetadataSchema, PROJECT_STAGE_VALUES, ProjectStageSchema, ProjectWithStatusSchema, ListProjectsArgsSchema, ListProjectsResultSchema, GetProjectArgsSchema, GetProjectResultSchema, CreateProjectArgsSchema, CreateProjectResultSchema, DeleteProjectArgsSchema, DeleteProjectResultSchema, UpdateProjectPortArgsSchema, UpdateProjectPortResultSchema, SetProdUrlArgsSchema, SetProdUrlResultSchema, StartDevServerArgsSchema, StartDevServerResultSchema, ASSISTANT_REPORTABLE_STAGES, ReportStageArgsSchema, ReportStageResultSchema, StopDevServerArgsSchema, StopDevServerResultSchema, AppBuilderProjectUpdatedEventSchema, PublishArgsSchema, PublishResultSchema, DismissPublishJobArgsSchema, DismissPublishJobResultSchema, AppBuilderPublishProgressEventSchema, AppBuilderPublishFailedEventSchema;
|
|
4583
4583
|
var init_schemas = __esm({
|
|
4584
4584
|
"../protocol/src/schemas.ts"() {
|
|
4585
4585
|
"use strict";
|
|
@@ -4637,20 +4637,12 @@ var init_schemas = __esm({
|
|
|
4637
4637
|
CapabilitiesGetArgs = external_exports.object({
|
|
4638
4638
|
tool: external_exports.string().min(1)
|
|
4639
4639
|
});
|
|
4640
|
-
ToolFeaturesSchema = external_exports.object({
|
|
4641
|
-
rewind: external_exports.boolean(),
|
|
4642
|
-
subagents: external_exports.boolean(),
|
|
4643
|
-
tui: external_exports.boolean(),
|
|
4644
|
-
observe: external_exports.boolean(),
|
|
4645
|
-
fileSharing: external_exports.boolean()
|
|
4646
|
-
});
|
|
4647
4640
|
CapabilitiesResponseSchema = external_exports.object({
|
|
4648
4641
|
tool: external_exports.string().min(1),
|
|
4649
4642
|
toolSessionIdLabel: external_exports.string().optional(),
|
|
4650
4643
|
models: external_exports.array(ModelInfoSchema),
|
|
4651
4644
|
permissionModes: external_exports.array(ModeInfoSchema),
|
|
4652
|
-
configSchema: external_exports.array(ConfigFieldSchemaSchema)
|
|
4653
|
-
features: ToolFeaturesSchema
|
|
4645
|
+
configSchema: external_exports.array(ConfigFieldSchemaSchema)
|
|
4654
4646
|
});
|
|
4655
4647
|
AllowRuleSchema = external_exports.object({
|
|
4656
4648
|
tool: external_exports.string().min(1),
|
|
@@ -5073,7 +5065,7 @@ var init_schemas = __esm({
|
|
|
5073
5065
|
cwd: external_exports.string().min(1),
|
|
5074
5066
|
path: external_exports.string().min(1)
|
|
5075
5067
|
});
|
|
5076
|
-
SkillsListArgs = external_exports.object({ cwd: external_exports.string().min(1)
|
|
5068
|
+
SkillsListArgs = external_exports.object({ cwd: external_exports.string().min(1) });
|
|
5077
5069
|
SkillEntrySchema = external_exports.object({
|
|
5078
5070
|
name: external_exports.string().min(1),
|
|
5079
5071
|
source: external_exports.enum(SKILL_SOURCE_VALUES),
|
|
@@ -5089,7 +5081,7 @@ var init_schemas = __esm({
|
|
|
5089
5081
|
whenToUse: external_exports.string().optional(),
|
|
5090
5082
|
plugin: external_exports.string().optional()
|
|
5091
5083
|
});
|
|
5092
|
-
AgentsListArgs = external_exports.object({ cwd: external_exports.string().min(1)
|
|
5084
|
+
AgentsListArgs = external_exports.object({ cwd: external_exports.string().min(1) });
|
|
5093
5085
|
AgentsListResponseSchema = external_exports.object({
|
|
5094
5086
|
agents: external_exports.array(AgentEntrySchema)
|
|
5095
5087
|
});
|
|
@@ -6850,10 +6842,10 @@ var require_redaction = __commonJS({
|
|
|
6850
6842
|
var strict = false;
|
|
6851
6843
|
function redaction(opts, serialize) {
|
|
6852
6844
|
const { paths, censor, remove } = handle(opts);
|
|
6853
|
-
const shape = paths.reduce((o,
|
|
6845
|
+
const shape = paths.reduce((o, str) => {
|
|
6854
6846
|
rx.lastIndex = 0;
|
|
6855
|
-
const first = rx.exec(
|
|
6856
|
-
const next = rx.exec(
|
|
6847
|
+
const first = rx.exec(str);
|
|
6848
|
+
const next = rx.exec(str);
|
|
6857
6849
|
let ns = first[1] !== void 0 ? first[1].replace(/^(?:"|'|`)(.*)(?:"|'|`)$/, "$1") : first[0];
|
|
6858
6850
|
if (ns === "*") {
|
|
6859
6851
|
ns = wildcardFirstSym;
|
|
@@ -6866,7 +6858,7 @@ var require_redaction = __commonJS({
|
|
|
6866
6858
|
return o;
|
|
6867
6859
|
}
|
|
6868
6860
|
const { index } = next;
|
|
6869
|
-
const nextPath = `${
|
|
6861
|
+
const nextPath = `${str.substr(index, str.length - 1)}`;
|
|
6870
6862
|
o[ns] = o[ns] || [];
|
|
6871
6863
|
if (ns !== wildcardFirstSym && o[ns].length === 0) {
|
|
6872
6864
|
o[ns].push(...o[wildcardFirstSym] || []);
|
|
@@ -6982,7 +6974,7 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
6982
6974
|
}
|
|
6983
6975
|
var argLen = args.length;
|
|
6984
6976
|
if (argLen === 0) return f;
|
|
6985
|
-
var
|
|
6977
|
+
var str = "";
|
|
6986
6978
|
var a = 1 - offset;
|
|
6987
6979
|
var lastPos = -1;
|
|
6988
6980
|
var flen = f && f.length || 0;
|
|
@@ -6997,8 +6989,8 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
6997
6989
|
break;
|
|
6998
6990
|
if (args[a] == null) break;
|
|
6999
6991
|
if (lastPos < i)
|
|
7000
|
-
|
|
7001
|
-
|
|
6992
|
+
str += f.slice(lastPos, i);
|
|
6993
|
+
str += Number(args[a]);
|
|
7002
6994
|
lastPos = i + 2;
|
|
7003
6995
|
i++;
|
|
7004
6996
|
break;
|
|
@@ -7007,8 +6999,8 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7007
6999
|
break;
|
|
7008
7000
|
if (args[a] == null) break;
|
|
7009
7001
|
if (lastPos < i)
|
|
7010
|
-
|
|
7011
|
-
|
|
7002
|
+
str += f.slice(lastPos, i);
|
|
7003
|
+
str += Math.floor(Number(args[a]));
|
|
7012
7004
|
lastPos = i + 2;
|
|
7013
7005
|
i++;
|
|
7014
7006
|
break;
|
|
@@ -7021,21 +7013,21 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7021
7013
|
break;
|
|
7022
7014
|
if (args[a] === void 0) break;
|
|
7023
7015
|
if (lastPos < i)
|
|
7024
|
-
|
|
7016
|
+
str += f.slice(lastPos, i);
|
|
7025
7017
|
var type = typeof args[a];
|
|
7026
7018
|
if (type === "string") {
|
|
7027
|
-
|
|
7019
|
+
str += "'" + args[a] + "'";
|
|
7028
7020
|
lastPos = i + 2;
|
|
7029
7021
|
i++;
|
|
7030
7022
|
break;
|
|
7031
7023
|
}
|
|
7032
7024
|
if (type === "function") {
|
|
7033
|
-
|
|
7025
|
+
str += args[a].name || "<anonymous>";
|
|
7034
7026
|
lastPos = i + 2;
|
|
7035
7027
|
i++;
|
|
7036
7028
|
break;
|
|
7037
7029
|
}
|
|
7038
|
-
|
|
7030
|
+
str += ss(args[a]);
|
|
7039
7031
|
lastPos = i + 2;
|
|
7040
7032
|
i++;
|
|
7041
7033
|
break;
|
|
@@ -7043,15 +7035,15 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7043
7035
|
if (a >= argLen)
|
|
7044
7036
|
break;
|
|
7045
7037
|
if (lastPos < i)
|
|
7046
|
-
|
|
7047
|
-
|
|
7038
|
+
str += f.slice(lastPos, i);
|
|
7039
|
+
str += String(args[a]);
|
|
7048
7040
|
lastPos = i + 2;
|
|
7049
7041
|
i++;
|
|
7050
7042
|
break;
|
|
7051
7043
|
case 37:
|
|
7052
7044
|
if (lastPos < i)
|
|
7053
|
-
|
|
7054
|
-
|
|
7045
|
+
str += f.slice(lastPos, i);
|
|
7046
|
+
str += "%";
|
|
7055
7047
|
lastPos = i + 2;
|
|
7056
7048
|
i++;
|
|
7057
7049
|
a--;
|
|
@@ -7064,9 +7056,9 @@ var require_quick_format_unescaped = __commonJS({
|
|
|
7064
7056
|
if (lastPos === -1)
|
|
7065
7057
|
return f;
|
|
7066
7058
|
else if (lastPos < flen) {
|
|
7067
|
-
|
|
7059
|
+
str += f.slice(lastPos);
|
|
7068
7060
|
}
|
|
7069
|
-
return
|
|
7061
|
+
return str;
|
|
7070
7062
|
}
|
|
7071
7063
|
}
|
|
7072
7064
|
});
|
|
@@ -7110,7 +7102,7 @@ var require_atomic_sleep = __commonJS({
|
|
|
7110
7102
|
var require_sonic_boom = __commonJS({
|
|
7111
7103
|
"../node_modules/.pnpm/sonic-boom@4.2.1/node_modules/sonic-boom/index.js"(exports2, module2) {
|
|
7112
7104
|
"use strict";
|
|
7113
|
-
var
|
|
7105
|
+
var fs50 = require("fs");
|
|
7114
7106
|
var EventEmitter3 = require("events");
|
|
7115
7107
|
var inherits = require("util").inherits;
|
|
7116
7108
|
var path59 = require("path");
|
|
@@ -7167,20 +7159,20 @@ var require_sonic_boom = __commonJS({
|
|
|
7167
7159
|
const mode = sonic.mode;
|
|
7168
7160
|
if (sonic.sync) {
|
|
7169
7161
|
try {
|
|
7170
|
-
if (sonic.mkdir)
|
|
7171
|
-
const fd =
|
|
7162
|
+
if (sonic.mkdir) fs50.mkdirSync(path59.dirname(file), { recursive: true });
|
|
7163
|
+
const fd = fs50.openSync(file, flags, mode);
|
|
7172
7164
|
fileOpened(null, fd);
|
|
7173
7165
|
} catch (err) {
|
|
7174
7166
|
fileOpened(err);
|
|
7175
7167
|
throw err;
|
|
7176
7168
|
}
|
|
7177
7169
|
} else if (sonic.mkdir) {
|
|
7178
|
-
|
|
7170
|
+
fs50.mkdir(path59.dirname(file), { recursive: true }, (err) => {
|
|
7179
7171
|
if (err) return fileOpened(err);
|
|
7180
|
-
|
|
7172
|
+
fs50.open(file, flags, mode, fileOpened);
|
|
7181
7173
|
});
|
|
7182
7174
|
} else {
|
|
7183
|
-
|
|
7175
|
+
fs50.open(file, flags, mode, fileOpened);
|
|
7184
7176
|
}
|
|
7185
7177
|
}
|
|
7186
7178
|
function SonicBoom(opts) {
|
|
@@ -7221,8 +7213,8 @@ var require_sonic_boom = __commonJS({
|
|
|
7221
7213
|
this.flush = flushBuffer;
|
|
7222
7214
|
this.flushSync = flushBufferSync;
|
|
7223
7215
|
this._actualWrite = actualWriteBuffer;
|
|
7224
|
-
fsWriteSync = () =>
|
|
7225
|
-
fsWrite = () =>
|
|
7216
|
+
fsWriteSync = () => fs50.writeSync(this.fd, this._writingBuf);
|
|
7217
|
+
fsWrite = () => fs50.write(this.fd, this._writingBuf, this.release);
|
|
7226
7218
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
7227
7219
|
this._writingBuf = "";
|
|
7228
7220
|
this.write = write;
|
|
@@ -7231,15 +7223,15 @@ var require_sonic_boom = __commonJS({
|
|
|
7231
7223
|
this._actualWrite = actualWrite;
|
|
7232
7224
|
fsWriteSync = () => {
|
|
7233
7225
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7234
|
-
return
|
|
7226
|
+
return fs50.writeSync(this.fd, this._writingBuf);
|
|
7235
7227
|
}
|
|
7236
|
-
return
|
|
7228
|
+
return fs50.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7237
7229
|
};
|
|
7238
7230
|
fsWrite = () => {
|
|
7239
7231
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
7240
|
-
return
|
|
7232
|
+
return fs50.write(this.fd, this._writingBuf, this.release);
|
|
7241
7233
|
}
|
|
7242
|
-
return
|
|
7234
|
+
return fs50.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
7243
7235
|
};
|
|
7244
7236
|
} else {
|
|
7245
7237
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -7296,7 +7288,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7296
7288
|
}
|
|
7297
7289
|
}
|
|
7298
7290
|
if (this._fsync) {
|
|
7299
|
-
|
|
7291
|
+
fs50.fsyncSync(this.fd);
|
|
7300
7292
|
}
|
|
7301
7293
|
const len = this._len;
|
|
7302
7294
|
if (this._reopening) {
|
|
@@ -7410,7 +7402,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7410
7402
|
const onDrain = () => {
|
|
7411
7403
|
if (!this._fsync) {
|
|
7412
7404
|
try {
|
|
7413
|
-
|
|
7405
|
+
fs50.fsync(this.fd, (err) => {
|
|
7414
7406
|
this._flushPending = false;
|
|
7415
7407
|
cb(err);
|
|
7416
7408
|
});
|
|
@@ -7512,7 +7504,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7512
7504
|
const fd = this.fd;
|
|
7513
7505
|
this.once("ready", () => {
|
|
7514
7506
|
if (fd !== this.fd) {
|
|
7515
|
-
|
|
7507
|
+
fs50.close(fd, (err) => {
|
|
7516
7508
|
if (err) {
|
|
7517
7509
|
return this.emit("error", err);
|
|
7518
7510
|
}
|
|
@@ -7561,7 +7553,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7561
7553
|
buf = this._bufs[0];
|
|
7562
7554
|
}
|
|
7563
7555
|
try {
|
|
7564
|
-
const n = Buffer.isBuffer(buf) ?
|
|
7556
|
+
const n = Buffer.isBuffer(buf) ? fs50.writeSync(this.fd, buf) : fs50.writeSync(this.fd, buf, "utf8");
|
|
7565
7557
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
7566
7558
|
buf = releasedBufObj.writingBuf;
|
|
7567
7559
|
this._len = releasedBufObj.len;
|
|
@@ -7577,7 +7569,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7577
7569
|
}
|
|
7578
7570
|
}
|
|
7579
7571
|
try {
|
|
7580
|
-
|
|
7572
|
+
fs50.fsyncSync(this.fd);
|
|
7581
7573
|
} catch {
|
|
7582
7574
|
}
|
|
7583
7575
|
}
|
|
@@ -7598,7 +7590,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7598
7590
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
7599
7591
|
}
|
|
7600
7592
|
try {
|
|
7601
|
-
const n =
|
|
7593
|
+
const n = fs50.writeSync(this.fd, buf);
|
|
7602
7594
|
buf = buf.subarray(n);
|
|
7603
7595
|
this._len = Math.max(this._len - n, 0);
|
|
7604
7596
|
if (buf.length <= 0) {
|
|
@@ -7626,13 +7618,13 @@ var require_sonic_boom = __commonJS({
|
|
|
7626
7618
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
7627
7619
|
if (this.sync) {
|
|
7628
7620
|
try {
|
|
7629
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
7621
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs50.writeSync(this.fd, this._writingBuf) : fs50.writeSync(this.fd, this._writingBuf, "utf8");
|
|
7630
7622
|
release(null, written);
|
|
7631
7623
|
} catch (err) {
|
|
7632
7624
|
release(err);
|
|
7633
7625
|
}
|
|
7634
7626
|
} else {
|
|
7635
|
-
|
|
7627
|
+
fs50.write(this.fd, this._writingBuf, release);
|
|
7636
7628
|
}
|
|
7637
7629
|
}
|
|
7638
7630
|
function actualWriteBuffer() {
|
|
@@ -7641,7 +7633,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7641
7633
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
7642
7634
|
if (this.sync) {
|
|
7643
7635
|
try {
|
|
7644
|
-
const written =
|
|
7636
|
+
const written = fs50.writeSync(this.fd, this._writingBuf);
|
|
7645
7637
|
release(null, written);
|
|
7646
7638
|
} catch (err) {
|
|
7647
7639
|
release(err);
|
|
@@ -7650,7 +7642,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7650
7642
|
if (kCopyBuffer) {
|
|
7651
7643
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
7652
7644
|
}
|
|
7653
|
-
|
|
7645
|
+
fs50.write(this.fd, this._writingBuf, release);
|
|
7654
7646
|
}
|
|
7655
7647
|
}
|
|
7656
7648
|
function actualClose(sonic) {
|
|
@@ -7666,12 +7658,12 @@ var require_sonic_boom = __commonJS({
|
|
|
7666
7658
|
sonic._lens = [];
|
|
7667
7659
|
assert(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
7668
7660
|
try {
|
|
7669
|
-
|
|
7661
|
+
fs50.fsync(sonic.fd, closeWrapped);
|
|
7670
7662
|
} catch {
|
|
7671
7663
|
}
|
|
7672
7664
|
function closeWrapped() {
|
|
7673
7665
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
7674
|
-
|
|
7666
|
+
fs50.close(sonic.fd, done);
|
|
7675
7667
|
} else {
|
|
7676
7668
|
done();
|
|
7677
7669
|
}
|
|
@@ -8552,38 +8544,38 @@ var require_tools = __commonJS({
|
|
|
8552
8544
|
}
|
|
8553
8545
|
}
|
|
8554
8546
|
}
|
|
8555
|
-
function asString(
|
|
8547
|
+
function asString(str) {
|
|
8556
8548
|
let result = "";
|
|
8557
8549
|
let last = 0;
|
|
8558
8550
|
let found = false;
|
|
8559
8551
|
let point = 255;
|
|
8560
|
-
const l =
|
|
8552
|
+
const l = str.length;
|
|
8561
8553
|
if (l > 100) {
|
|
8562
|
-
return JSON.stringify(
|
|
8554
|
+
return JSON.stringify(str);
|
|
8563
8555
|
}
|
|
8564
8556
|
for (var i = 0; i < l && point >= 32; i++) {
|
|
8565
|
-
point =
|
|
8557
|
+
point = str.charCodeAt(i);
|
|
8566
8558
|
if (point === 34 || point === 92) {
|
|
8567
|
-
result +=
|
|
8559
|
+
result += str.slice(last, i) + "\\";
|
|
8568
8560
|
last = i;
|
|
8569
8561
|
found = true;
|
|
8570
8562
|
}
|
|
8571
8563
|
}
|
|
8572
8564
|
if (!found) {
|
|
8573
|
-
result =
|
|
8565
|
+
result = str;
|
|
8574
8566
|
} else {
|
|
8575
|
-
result +=
|
|
8567
|
+
result += str.slice(last);
|
|
8576
8568
|
}
|
|
8577
|
-
return point < 32 ? JSON.stringify(
|
|
8569
|
+
return point < 32 ? JSON.stringify(str) : '"' + result + '"';
|
|
8578
8570
|
}
|
|
8579
|
-
function asJson(obj, msg,
|
|
8571
|
+
function asJson(obj, msg, num, time) {
|
|
8580
8572
|
if (asJsonChan.hasSubscribers === false) {
|
|
8581
|
-
return _asJson.call(this, obj, msg,
|
|
8573
|
+
return _asJson.call(this, obj, msg, num, time);
|
|
8582
8574
|
}
|
|
8583
8575
|
const store = { instance: this, arguments };
|
|
8584
|
-
return asJsonChan.traceSync(_asJson, store, this, obj, msg,
|
|
8576
|
+
return asJsonChan.traceSync(_asJson, store, this, obj, msg, num, time);
|
|
8585
8577
|
}
|
|
8586
|
-
function _asJson(obj, msg,
|
|
8578
|
+
function _asJson(obj, msg, num, time) {
|
|
8587
8579
|
const stringify2 = this[stringifySym];
|
|
8588
8580
|
const stringifySafe = this[stringifySafeSym];
|
|
8589
8581
|
const stringifiers = this[stringifiersSym];
|
|
@@ -8593,7 +8585,7 @@ var require_tools = __commonJS({
|
|
|
8593
8585
|
const formatters = this[formattersSym];
|
|
8594
8586
|
const messageKey = this[messageKeySym];
|
|
8595
8587
|
const errorKey = this[errorKeySym];
|
|
8596
|
-
let data = this[lsCacheSym][
|
|
8588
|
+
let data = this[lsCacheSym][num] + time;
|
|
8597
8589
|
data = data + chindings;
|
|
8598
8590
|
let value;
|
|
8599
8591
|
if (formatters.log) {
|
|
@@ -9220,7 +9212,7 @@ var require_proto = __commonJS({
|
|
|
9220
9212
|
function defaultMixinMergeStrategy(mergeObject, mixinObject) {
|
|
9221
9213
|
return Object.assign(mixinObject, mergeObject);
|
|
9222
9214
|
}
|
|
9223
|
-
function write(_obj, msg,
|
|
9215
|
+
function write(_obj, msg, num) {
|
|
9224
9216
|
const t = this[timeSym]();
|
|
9225
9217
|
const mixin = this[mixinSym];
|
|
9226
9218
|
const errorKey = this[errorKeySym];
|
|
@@ -9242,12 +9234,12 @@ var require_proto = __commonJS({
|
|
|
9242
9234
|
}
|
|
9243
9235
|
}
|
|
9244
9236
|
if (mixin) {
|
|
9245
|
-
obj = mixinMergeStrategy(obj, mixin(obj,
|
|
9237
|
+
obj = mixinMergeStrategy(obj, mixin(obj, num, this));
|
|
9246
9238
|
}
|
|
9247
|
-
const s = this[asJsonSym](obj, msg,
|
|
9239
|
+
const s = this[asJsonSym](obj, msg, num, t);
|
|
9248
9240
|
const stream = this[streamSym];
|
|
9249
9241
|
if (stream[needsMetadataGsym] === true) {
|
|
9250
|
-
stream.lastLevel =
|
|
9242
|
+
stream.lastLevel = num;
|
|
9251
9243
|
stream.lastObj = obj;
|
|
9252
9244
|
stream.lastMsg = msg;
|
|
9253
9245
|
stream.lastTime = t.slice(this[timeSliceIndexSym]);
|
|
@@ -9280,11 +9272,11 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
9280
9272
|
exports2.configure = configure;
|
|
9281
9273
|
module2.exports = stringify;
|
|
9282
9274
|
var strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
|
|
9283
|
-
function strEscape(
|
|
9284
|
-
if (
|
|
9285
|
-
return `"${
|
|
9275
|
+
function strEscape(str) {
|
|
9276
|
+
if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
|
|
9277
|
+
return `"${str}"`;
|
|
9286
9278
|
}
|
|
9287
|
-
return JSON.stringify(
|
|
9279
|
+
return JSON.stringify(str);
|
|
9288
9280
|
}
|
|
9289
9281
|
function sort(array, comparator) {
|
|
9290
9282
|
if (array.length > 200 || comparator) {
|
|
@@ -10241,23 +10233,6 @@ var require_pino = __commonJS({
|
|
|
10241
10233
|
}
|
|
10242
10234
|
});
|
|
10243
10235
|
|
|
10244
|
-
// src/session/stdout-splitter.ts
|
|
10245
|
-
function splitStdoutChunk(buf, chunk) {
|
|
10246
|
-
let next = buf + (typeof chunk === "string" ? chunk : chunk.toString("utf8"));
|
|
10247
|
-
const lines = [];
|
|
10248
|
-
let idx;
|
|
10249
|
-
while ((idx = next.indexOf("\n")) >= 0) {
|
|
10250
|
-
lines.push(next.slice(0, idx));
|
|
10251
|
-
next = next.slice(idx + 1);
|
|
10252
|
-
}
|
|
10253
|
-
return { newBuf: next, lines };
|
|
10254
|
-
}
|
|
10255
|
-
var init_stdout_splitter = __esm({
|
|
10256
|
-
"src/session/stdout-splitter.ts"() {
|
|
10257
|
-
"use strict";
|
|
10258
|
-
}
|
|
10259
|
-
});
|
|
10260
|
-
|
|
10261
10236
|
// src/session/permission-stdio.ts
|
|
10262
10237
|
function encodePermissionResponse(requestId, approved, input, message) {
|
|
10263
10238
|
const innerResponse = approved ? {
|
|
@@ -10280,6 +10255,23 @@ var init_permission_stdio = __esm({
|
|
|
10280
10255
|
}
|
|
10281
10256
|
});
|
|
10282
10257
|
|
|
10258
|
+
// src/session/stdout-splitter.ts
|
|
10259
|
+
function splitStdoutChunk(buf, chunk) {
|
|
10260
|
+
let next = buf + (typeof chunk === "string" ? chunk : chunk.toString("utf8"));
|
|
10261
|
+
const lines = [];
|
|
10262
|
+
let idx;
|
|
10263
|
+
while ((idx = next.indexOf("\n")) >= 0) {
|
|
10264
|
+
lines.push(next.slice(0, idx));
|
|
10265
|
+
next = next.slice(idx + 1);
|
|
10266
|
+
}
|
|
10267
|
+
return { newBuf: next, lines };
|
|
10268
|
+
}
|
|
10269
|
+
var init_stdout_splitter = __esm({
|
|
10270
|
+
"src/session/stdout-splitter.ts"() {
|
|
10271
|
+
"use strict";
|
|
10272
|
+
}
|
|
10273
|
+
});
|
|
10274
|
+
|
|
10283
10275
|
// ../node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.mjs
|
|
10284
10276
|
function Diff() {
|
|
10285
10277
|
}
|
|
@@ -10318,22 +10310,22 @@ function buildValues(diff2, lastComponent, newString, oldString, useLongestToken
|
|
|
10318
10310
|
}
|
|
10319
10311
|
return components;
|
|
10320
10312
|
}
|
|
10321
|
-
function longestCommonPrefix(str1,
|
|
10313
|
+
function longestCommonPrefix(str1, str2) {
|
|
10322
10314
|
var i;
|
|
10323
|
-
for (i = 0; i < str1.length && i <
|
|
10324
|
-
if (str1[i] !=
|
|
10315
|
+
for (i = 0; i < str1.length && i < str2.length; i++) {
|
|
10316
|
+
if (str1[i] != str2[i]) {
|
|
10325
10317
|
return str1.slice(0, i);
|
|
10326
10318
|
}
|
|
10327
10319
|
}
|
|
10328
10320
|
return str1.slice(0, i);
|
|
10329
10321
|
}
|
|
10330
|
-
function longestCommonSuffix(str1,
|
|
10322
|
+
function longestCommonSuffix(str1, str2) {
|
|
10331
10323
|
var i;
|
|
10332
|
-
if (!str1 || !
|
|
10324
|
+
if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
|
|
10333
10325
|
return "";
|
|
10334
10326
|
}
|
|
10335
|
-
for (i = 0; i < str1.length && i <
|
|
10336
|
-
if (str1[str1.length - (i + 1)] !=
|
|
10327
|
+
for (i = 0; i < str1.length && i < str2.length; i++) {
|
|
10328
|
+
if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
|
|
10337
10329
|
return str1.slice(-i);
|
|
10338
10330
|
}
|
|
10339
10331
|
}
|
|
@@ -11265,12 +11257,12 @@ function attachmentToHistoryMessage(o, ts) {
|
|
|
11265
11257
|
const raw = Array.isArray(a.memories) ? a.memories : [];
|
|
11266
11258
|
const memories = raw.map((m2) => {
|
|
11267
11259
|
if (!m2 || typeof m2 !== "object") return null;
|
|
11268
|
-
const
|
|
11269
|
-
const path59 = typeof
|
|
11270
|
-
const content = typeof
|
|
11260
|
+
const rec = m2;
|
|
11261
|
+
const path59 = typeof rec.path === "string" ? rec.path : null;
|
|
11262
|
+
const content = typeof rec.content === "string" ? rec.content : null;
|
|
11271
11263
|
if (!path59 || content == null) return null;
|
|
11272
11264
|
const entry = { path: path59, content };
|
|
11273
|
-
if (typeof
|
|
11265
|
+
if (typeof rec.mtimeMs === "number") entry.mtimeMs = rec.mtimeMs;
|
|
11274
11266
|
return entry;
|
|
11275
11267
|
}).filter((m2) => m2 !== null);
|
|
11276
11268
|
if (memories.length === 0) return null;
|
|
@@ -12080,12 +12072,12 @@ function parseAttachment(obj) {
|
|
|
12080
12072
|
const raw = Array.isArray(a.memories) ? a.memories : [];
|
|
12081
12073
|
const memories = raw.map((m2) => {
|
|
12082
12074
|
if (!m2 || typeof m2 !== "object") return null;
|
|
12083
|
-
const
|
|
12084
|
-
const path59 = typeof
|
|
12085
|
-
const content = typeof
|
|
12075
|
+
const rec = m2;
|
|
12076
|
+
const path59 = typeof rec.path === "string" ? rec.path : null;
|
|
12077
|
+
const content = typeof rec.content === "string" ? rec.content : null;
|
|
12086
12078
|
if (!path59 || content == null) return null;
|
|
12087
12079
|
const out = { path: path59, content };
|
|
12088
|
-
if (typeof
|
|
12080
|
+
if (typeof rec.mtimeMs === "number") out.mtimeMs = rec.mtimeMs;
|
|
12089
12081
|
return out;
|
|
12090
12082
|
}).filter((m2) => m2 !== null);
|
|
12091
12083
|
if (memories.length === 0) return null;
|
|
@@ -12232,7 +12224,6 @@ var init_claude = __esm({
|
|
|
12232
12224
|
toolSessionIdLabel: "Claude Session ID",
|
|
12233
12225
|
models: CLAUDE_MODELS,
|
|
12234
12226
|
permissionModes: CLAUDE_PERMISSION_MODES,
|
|
12235
|
-
features: { rewind: true, subagents: true, tui: true, observe: true, fileSharing: true },
|
|
12236
12227
|
configSchema: [
|
|
12237
12228
|
{
|
|
12238
12229
|
name: "model",
|
|
@@ -17721,26 +17712,26 @@ var require_permessage_deflate = __commonJS({
|
|
|
17721
17712
|
value = value[0];
|
|
17722
17713
|
if (key === "client_max_window_bits") {
|
|
17723
17714
|
if (value !== true) {
|
|
17724
|
-
const
|
|
17725
|
-
if (!Number.isInteger(
|
|
17715
|
+
const num = +value;
|
|
17716
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
17726
17717
|
throw new TypeError(
|
|
17727
17718
|
`Invalid value for parameter "${key}": ${value}`
|
|
17728
17719
|
);
|
|
17729
17720
|
}
|
|
17730
|
-
value =
|
|
17721
|
+
value = num;
|
|
17731
17722
|
} else if (!this._isServer) {
|
|
17732
17723
|
throw new TypeError(
|
|
17733
17724
|
`Invalid value for parameter "${key}": ${value}`
|
|
17734
17725
|
);
|
|
17735
17726
|
}
|
|
17736
17727
|
} else if (key === "server_max_window_bits") {
|
|
17737
|
-
const
|
|
17738
|
-
if (!Number.isInteger(
|
|
17728
|
+
const num = +value;
|
|
17729
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
17739
17730
|
throw new TypeError(
|
|
17740
17731
|
`Invalid value for parameter "${key}": ${value}`
|
|
17741
17732
|
);
|
|
17742
17733
|
}
|
|
17743
|
-
value =
|
|
17734
|
+
value = num;
|
|
17744
17735
|
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
17745
17736
|
if (value !== true) {
|
|
17746
17737
|
throw new TypeError(
|
|
@@ -18435,8 +18426,8 @@ var require_receiver = __commonJS({
|
|
|
18435
18426
|
return;
|
|
18436
18427
|
}
|
|
18437
18428
|
const buf = this.consume(8);
|
|
18438
|
-
const
|
|
18439
|
-
if (
|
|
18429
|
+
const num = buf.readUInt32BE(0);
|
|
18430
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
18440
18431
|
const error = this.createError(
|
|
18441
18432
|
RangeError,
|
|
18442
18433
|
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
@@ -18447,7 +18438,7 @@ var require_receiver = __commonJS({
|
|
|
18447
18438
|
cb(error);
|
|
18448
18439
|
return;
|
|
18449
18440
|
}
|
|
18450
|
-
this._payloadLength =
|
|
18441
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
18451
18442
|
this.haveLength(cb);
|
|
18452
18443
|
}
|
|
18453
18444
|
/**
|
|
@@ -22761,19 +22752,19 @@ var require_stream_readable = __commonJS({
|
|
|
22761
22752
|
var ret = p2.data;
|
|
22762
22753
|
n -= ret.length;
|
|
22763
22754
|
while (p2 = p2.next) {
|
|
22764
|
-
var
|
|
22765
|
-
var nb = n >
|
|
22766
|
-
if (nb ===
|
|
22767
|
-
else ret +=
|
|
22755
|
+
var str = p2.data;
|
|
22756
|
+
var nb = n > str.length ? str.length : n;
|
|
22757
|
+
if (nb === str.length) ret += str;
|
|
22758
|
+
else ret += str.slice(0, n);
|
|
22768
22759
|
n -= nb;
|
|
22769
22760
|
if (n === 0) {
|
|
22770
|
-
if (nb ===
|
|
22761
|
+
if (nb === str.length) {
|
|
22771
22762
|
++c;
|
|
22772
22763
|
if (p2.next) list.head = p2.next;
|
|
22773
22764
|
else list.head = list.tail = null;
|
|
22774
22765
|
} else {
|
|
22775
22766
|
list.head = p2;
|
|
22776
|
-
p2.data =
|
|
22767
|
+
p2.data = str.slice(nb);
|
|
22777
22768
|
}
|
|
22778
22769
|
break;
|
|
22779
22770
|
}
|
|
@@ -23669,14 +23660,14 @@ var require_utils = __commonJS({
|
|
|
23669
23660
|
var nodejsUtils = require_nodejsUtils();
|
|
23670
23661
|
var external = require_external();
|
|
23671
23662
|
require_setImmediate();
|
|
23672
|
-
function string2binary(
|
|
23663
|
+
function string2binary(str) {
|
|
23673
23664
|
var result = null;
|
|
23674
23665
|
if (support.uint8array) {
|
|
23675
|
-
result = new Uint8Array(
|
|
23666
|
+
result = new Uint8Array(str.length);
|
|
23676
23667
|
} else {
|
|
23677
|
-
result = new Array(
|
|
23668
|
+
result = new Array(str.length);
|
|
23678
23669
|
}
|
|
23679
|
-
return stringToArrayLike(
|
|
23670
|
+
return stringToArrayLike(str, result);
|
|
23680
23671
|
}
|
|
23681
23672
|
exports2.newBlob = function(part, type) {
|
|
23682
23673
|
exports2.checkSupport("blob");
|
|
@@ -23698,9 +23689,9 @@ var require_utils = __commonJS({
|
|
|
23698
23689
|
function identity(input) {
|
|
23699
23690
|
return input;
|
|
23700
23691
|
}
|
|
23701
|
-
function stringToArrayLike(
|
|
23702
|
-
for (var i = 0; i <
|
|
23703
|
-
array[i] =
|
|
23692
|
+
function stringToArrayLike(str, array) {
|
|
23693
|
+
for (var i = 0; i < str.length; ++i) {
|
|
23694
|
+
array[i] = str.charCodeAt(i) & 255;
|
|
23704
23695
|
}
|
|
23705
23696
|
return array;
|
|
23706
23697
|
}
|
|
@@ -23913,10 +23904,10 @@ var require_utils = __commonJS({
|
|
|
23913
23904
|
};
|
|
23914
23905
|
exports2.MAX_VALUE_16BITS = 65535;
|
|
23915
23906
|
exports2.MAX_VALUE_32BITS = -1;
|
|
23916
|
-
exports2.pretty = function(
|
|
23907
|
+
exports2.pretty = function(str) {
|
|
23917
23908
|
var res = "", code, i;
|
|
23918
|
-
for (i = 0; i < (
|
|
23919
|
-
code =
|
|
23909
|
+
for (i = 0; i < (str || "").length; i++) {
|
|
23910
|
+
code = str.charCodeAt(i);
|
|
23920
23911
|
res += "\\x" + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
|
|
23921
23912
|
}
|
|
23922
23913
|
return res;
|
|
@@ -24226,12 +24217,12 @@ var require_utf8 = __commonJS({
|
|
|
24226
24217
|
}
|
|
24227
24218
|
var i;
|
|
24228
24219
|
_utf8len[254] = _utf8len[254] = 1;
|
|
24229
|
-
var string2buf = function(
|
|
24230
|
-
var buf, c, c2, m_pos, i2, str_len =
|
|
24220
|
+
var string2buf = function(str) {
|
|
24221
|
+
var buf, c, c2, m_pos, i2, str_len = str.length, buf_len = 0;
|
|
24231
24222
|
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
|
24232
|
-
c =
|
|
24223
|
+
c = str.charCodeAt(m_pos);
|
|
24233
24224
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
24234
|
-
c2 =
|
|
24225
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
24235
24226
|
if ((c2 & 64512) === 56320) {
|
|
24236
24227
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
24237
24228
|
m_pos++;
|
|
@@ -24245,9 +24236,9 @@ var require_utf8 = __commonJS({
|
|
|
24245
24236
|
buf = new Array(buf_len);
|
|
24246
24237
|
}
|
|
24247
24238
|
for (i2 = 0, m_pos = 0; i2 < buf_len; m_pos++) {
|
|
24248
|
-
c =
|
|
24239
|
+
c = str.charCodeAt(m_pos);
|
|
24249
24240
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
24250
|
-
c2 =
|
|
24241
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
24251
24242
|
if ((c2 & 64512) === 56320) {
|
|
24252
24243
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
24253
24244
|
m_pos++;
|
|
@@ -24331,11 +24322,11 @@ var require_utf8 = __commonJS({
|
|
|
24331
24322
|
}
|
|
24332
24323
|
return utils.applyFromCharCode(utf16buf);
|
|
24333
24324
|
};
|
|
24334
|
-
exports2.utf8encode = function utf8encode(
|
|
24325
|
+
exports2.utf8encode = function utf8encode(str) {
|
|
24335
24326
|
if (support.nodebuffer) {
|
|
24336
|
-
return nodejsUtils.newBufferFrom(
|
|
24327
|
+
return nodejsUtils.newBufferFrom(str, "utf-8");
|
|
24337
24328
|
}
|
|
24338
|
-
return string2buf(
|
|
24329
|
+
return string2buf(str);
|
|
24339
24330
|
};
|
|
24340
24331
|
exports2.utf8decode = function utf8decode(buf) {
|
|
24341
24332
|
if (support.nodebuffer) {
|
|
@@ -24744,11 +24735,11 @@ var require_crc32 = __commonJS({
|
|
|
24744
24735
|
}
|
|
24745
24736
|
return crc ^ -1;
|
|
24746
24737
|
}
|
|
24747
|
-
function crc32str(crc,
|
|
24738
|
+
function crc32str(crc, str, len, pos) {
|
|
24748
24739
|
var t = crcTable, end = pos + len;
|
|
24749
24740
|
crc = crc ^ -1;
|
|
24750
24741
|
for (var i = pos; i < end; i++) {
|
|
24751
|
-
crc = crc >>> 8 ^ t[(crc ^
|
|
24742
|
+
crc = crc >>> 8 ^ t[(crc ^ str.charCodeAt(i)) & 255];
|
|
24752
24743
|
}
|
|
24753
24744
|
return crc ^ -1;
|
|
24754
24745
|
}
|
|
@@ -25945,7 +25936,7 @@ var require_deflate = __commonJS({
|
|
|
25945
25936
|
}
|
|
25946
25937
|
function fill_window(s) {
|
|
25947
25938
|
var _w_size = s.w_size;
|
|
25948
|
-
var p2, n, m2, more,
|
|
25939
|
+
var p2, n, m2, more, str;
|
|
25949
25940
|
do {
|
|
25950
25941
|
more = s.window_size - s.lookahead - s.strstart;
|
|
25951
25942
|
if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
|
|
@@ -25973,14 +25964,14 @@ var require_deflate = __commonJS({
|
|
|
25973
25964
|
n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
|
|
25974
25965
|
s.lookahead += n;
|
|
25975
25966
|
if (s.lookahead + s.insert >= MIN_MATCH) {
|
|
25976
|
-
|
|
25977
|
-
s.ins_h = s.window[
|
|
25978
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
25967
|
+
str = s.strstart - s.insert;
|
|
25968
|
+
s.ins_h = s.window[str];
|
|
25969
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask;
|
|
25979
25970
|
while (s.insert) {
|
|
25980
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
25981
|
-
s.prev[
|
|
25982
|
-
s.head[s.ins_h] =
|
|
25983
|
-
|
|
25971
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
25972
|
+
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
25973
|
+
s.head[s.ins_h] = str;
|
|
25974
|
+
str++;
|
|
25984
25975
|
s.insert--;
|
|
25985
25976
|
if (s.lookahead + s.insert < MIN_MATCH) {
|
|
25986
25977
|
break;
|
|
@@ -26756,7 +26747,7 @@ var require_deflate = __commonJS({
|
|
|
26756
26747
|
function deflateSetDictionary(strm, dictionary) {
|
|
26757
26748
|
var dictLength = dictionary.length;
|
|
26758
26749
|
var s;
|
|
26759
|
-
var
|
|
26750
|
+
var str, n;
|
|
26760
26751
|
var wrap2;
|
|
26761
26752
|
var avail;
|
|
26762
26753
|
var next;
|
|
@@ -26794,15 +26785,15 @@ var require_deflate = __commonJS({
|
|
|
26794
26785
|
strm.input = dictionary;
|
|
26795
26786
|
fill_window(s);
|
|
26796
26787
|
while (s.lookahead >= MIN_MATCH) {
|
|
26797
|
-
|
|
26788
|
+
str = s.strstart;
|
|
26798
26789
|
n = s.lookahead - (MIN_MATCH - 1);
|
|
26799
26790
|
do {
|
|
26800
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[
|
|
26801
|
-
s.prev[
|
|
26802
|
-
s.head[s.ins_h] =
|
|
26803
|
-
|
|
26791
|
+
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
26792
|
+
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
26793
|
+
s.head[s.ins_h] = str;
|
|
26794
|
+
str++;
|
|
26804
26795
|
} while (--n);
|
|
26805
|
-
s.strstart =
|
|
26796
|
+
s.strstart = str;
|
|
26806
26797
|
s.lookahead = MIN_MATCH - 1;
|
|
26807
26798
|
fill_window(s);
|
|
26808
26799
|
}
|
|
@@ -26853,12 +26844,12 @@ var require_strings = __commonJS({
|
|
|
26853
26844
|
}
|
|
26854
26845
|
var q;
|
|
26855
26846
|
_utf8len[254] = _utf8len[254] = 1;
|
|
26856
|
-
exports2.string2buf = function(
|
|
26857
|
-
var buf, c, c2, m_pos, i, str_len =
|
|
26847
|
+
exports2.string2buf = function(str) {
|
|
26848
|
+
var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
|
|
26858
26849
|
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
|
26859
|
-
c =
|
|
26850
|
+
c = str.charCodeAt(m_pos);
|
|
26860
26851
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
26861
|
-
c2 =
|
|
26852
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
26862
26853
|
if ((c2 & 64512) === 56320) {
|
|
26863
26854
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
26864
26855
|
m_pos++;
|
|
@@ -26868,9 +26859,9 @@ var require_strings = __commonJS({
|
|
|
26868
26859
|
}
|
|
26869
26860
|
buf = new utils.Buf8(buf_len);
|
|
26870
26861
|
for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
|
|
26871
|
-
c =
|
|
26862
|
+
c = str.charCodeAt(m_pos);
|
|
26872
26863
|
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
26873
|
-
c2 =
|
|
26864
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
26874
26865
|
if ((c2 & 64512) === 56320) {
|
|
26875
26866
|
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
26876
26867
|
m_pos++;
|
|
@@ -26909,10 +26900,10 @@ var require_strings = __commonJS({
|
|
|
26909
26900
|
exports2.buf2binstring = function(buf) {
|
|
26910
26901
|
return buf2binstring(buf, buf.length);
|
|
26911
26902
|
};
|
|
26912
|
-
exports2.binstring2buf = function(
|
|
26913
|
-
var buf = new utils.Buf8(
|
|
26903
|
+
exports2.binstring2buf = function(str) {
|
|
26904
|
+
var buf = new utils.Buf8(str.length);
|
|
26914
26905
|
for (var i = 0, len = buf.length; i < len; i++) {
|
|
26915
|
-
buf[i] =
|
|
26906
|
+
buf[i] = str.charCodeAt(i);
|
|
26916
26907
|
}
|
|
26917
26908
|
return buf;
|
|
26918
26909
|
};
|
|
@@ -30754,8 +30745,8 @@ function startRunCaseRecorder(opts) {
|
|
|
30754
30745
|
});
|
|
30755
30746
|
const ensureStream = () => {
|
|
30756
30747
|
if (stream) return stream;
|
|
30757
|
-
|
|
30758
|
-
stream =
|
|
30748
|
+
import_node_fs33.default.mkdirSync(dir, { recursive: true });
|
|
30749
|
+
stream = import_node_fs33.default.createWriteStream(opts.recordPath, { flags: "a" });
|
|
30759
30750
|
stream.on("close", () => closedResolve());
|
|
30760
30751
|
return stream;
|
|
30761
30752
|
};
|
|
@@ -30780,11 +30771,11 @@ function startRunCaseRecorder(opts) {
|
|
|
30780
30771
|
};
|
|
30781
30772
|
return { tap, close, closed };
|
|
30782
30773
|
}
|
|
30783
|
-
var
|
|
30774
|
+
var import_node_fs33, import_node_path47;
|
|
30784
30775
|
var init_recorder = __esm({
|
|
30785
30776
|
"src/run-case/recorder.ts"() {
|
|
30786
30777
|
"use strict";
|
|
30787
|
-
|
|
30778
|
+
import_node_fs33 = __toESM(require("fs"), 1);
|
|
30788
30779
|
import_node_path47 = __toESM(require("path"), 1);
|
|
30789
30780
|
}
|
|
30790
30781
|
});
|
|
@@ -30828,7 +30819,7 @@ var init_wire = __esm({
|
|
|
30828
30819
|
// src/run-case/controller.ts
|
|
30829
30820
|
async function runController(opts) {
|
|
30830
30821
|
const now = opts.now ?? Date.now;
|
|
30831
|
-
const cwd = opts.cwd ?? (0,
|
|
30822
|
+
const cwd = opts.cwd ?? (0, import_node_fs34.mkdtempSync)(import_node_path48.default.join(import_node_os19.default.tmpdir(), "clawd-runcase-"));
|
|
30832
30823
|
const ownsCwd = opts.cwd === void 0;
|
|
30833
30824
|
const recorder = startRunCaseRecorder({ recordPath: opts.record, now });
|
|
30834
30825
|
const spawnCtx = { cwd };
|
|
@@ -30989,17 +30980,17 @@ async function runController(opts) {
|
|
|
30989
30980
|
if (sigintHandler) process.off("SIGINT", sigintHandler);
|
|
30990
30981
|
if (ownsCwd) {
|
|
30991
30982
|
try {
|
|
30992
|
-
(0,
|
|
30983
|
+
(0, import_node_fs34.rmSync)(cwd, { recursive: true, force: true });
|
|
30993
30984
|
} catch {
|
|
30994
30985
|
}
|
|
30995
30986
|
}
|
|
30996
30987
|
return exitCode ?? 0;
|
|
30997
30988
|
}
|
|
30998
|
-
var
|
|
30989
|
+
var import_node_fs34, import_node_os19, import_node_path48;
|
|
30999
30990
|
var init_controller = __esm({
|
|
31000
30991
|
"src/run-case/controller.ts"() {
|
|
31001
30992
|
"use strict";
|
|
31002
|
-
|
|
30993
|
+
import_node_fs34 = require("fs");
|
|
31003
30994
|
import_node_os19 = __toESM(require("os"), 1);
|
|
31004
30995
|
import_node_path48 = __toESM(require("path"), 1);
|
|
31005
30996
|
init_claude();
|
|
@@ -31237,7 +31228,7 @@ Env (advanced):
|
|
|
31237
31228
|
|
|
31238
31229
|
// src/index.ts
|
|
31239
31230
|
var import_node_path46 = __toESM(require("path"), 1);
|
|
31240
|
-
var
|
|
31231
|
+
var import_node_fs32 = __toESM(require("fs"), 1);
|
|
31241
31232
|
|
|
31242
31233
|
// src/logger.ts
|
|
31243
31234
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
@@ -31634,6 +31625,9 @@ function buildRule(tool, input) {
|
|
|
31634
31625
|
return { tool, pattern, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
31635
31626
|
}
|
|
31636
31627
|
|
|
31628
|
+
// src/session/reducer.ts
|
|
31629
|
+
init_permission_stdio();
|
|
31630
|
+
|
|
31637
31631
|
// src/persona/connection-prompt.ts
|
|
31638
31632
|
var OWNER_TEMPLATE = `# \u8FDE\u63A5\u4E0A\u4E0B\u6587
|
|
31639
31633
|
\u4F60\u73B0\u5728\u4EE5 Owner \u8EAB\u4EFD\u88AB\u8FDE\u63A5\uFF0C\u5BF9\u65B9\u5C31\u662F owner \u672C\u4EBA\uFF08{ownerLabel}\uFF09\u3002
|
|
@@ -31820,7 +31814,10 @@ function applyParsedEvent(state, event, deps) {
|
|
|
31820
31814
|
effects.push(...pushed2.effects);
|
|
31821
31815
|
const hit = matchesAnyRule(next.file.permissionRules, tool, input);
|
|
31822
31816
|
if (hit) {
|
|
31823
|
-
effects.push({
|
|
31817
|
+
effects.push({
|
|
31818
|
+
kind: "write-stdin",
|
|
31819
|
+
payload: encodePermissionResponse(requestId, true, input)
|
|
31820
|
+
});
|
|
31824
31821
|
} else {
|
|
31825
31822
|
const pending = {
|
|
31826
31823
|
tool,
|
|
@@ -32213,11 +32210,13 @@ function reduceSession(state, input, deps) {
|
|
|
32213
32210
|
next.pendingPermissions = nextPending;
|
|
32214
32211
|
const effects = [
|
|
32215
32212
|
{
|
|
32216
|
-
kind: "
|
|
32217
|
-
|
|
32218
|
-
|
|
32219
|
-
|
|
32220
|
-
|
|
32213
|
+
kind: "write-stdin",
|
|
32214
|
+
payload: encodePermissionResponse(
|
|
32215
|
+
input.requestId,
|
|
32216
|
+
input.allow,
|
|
32217
|
+
pending.input,
|
|
32218
|
+
input.message
|
|
32219
|
+
)
|
|
32221
32220
|
}
|
|
32222
32221
|
];
|
|
32223
32222
|
if (input.allow && input.permanent) {
|
|
@@ -32357,7 +32356,6 @@ function reduceSession(state, input, deps) {
|
|
|
32357
32356
|
|
|
32358
32357
|
// src/session/runner.ts
|
|
32359
32358
|
init_stdout_splitter();
|
|
32360
|
-
init_permission_stdio();
|
|
32361
32359
|
|
|
32362
32360
|
// src/ipc-recorder.ts
|
|
32363
32361
|
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
@@ -32465,9 +32463,6 @@ var SessionRunner = class {
|
|
|
32465
32463
|
hooks;
|
|
32466
32464
|
state;
|
|
32467
32465
|
proc = null;
|
|
32468
|
-
// JSON-RPC 类 agent(codex app-server) 的 per-session 驱动器;非 null 时 runner 不用 spawn()/ChildProcess,
|
|
32469
|
-
// effect 路由到 session 一等方法(startTurn/respondPermission/answerQuestion/interrupt/stop)。claude 恒 null。
|
|
32470
|
-
session = null;
|
|
32471
32466
|
stdoutBuf = "";
|
|
32472
32467
|
// 未决 control_request 表;key = request_id
|
|
32473
32468
|
pendingControlRequests = /* @__PURE__ */ new Map();
|
|
@@ -32576,15 +32571,6 @@ var SessionRunner = class {
|
|
|
32576
32571
|
if (this.hooks.onFileEdit) this.observeForFileEdit(events);
|
|
32577
32572
|
this.input({ kind: "inject-events", events });
|
|
32578
32573
|
}
|
|
32579
|
-
// session:interrupt 的 SDK 通道分流:codex → AgentSession.interrupt();claude → control_request('interrupt')。
|
|
32580
|
-
// TUI(pty) 路径在 manager.dispatchInterrupt 里先于此处理,不进这里。
|
|
32581
|
-
async interrupt() {
|
|
32582
|
-
if (this.session) {
|
|
32583
|
-
this.session.interrupt();
|
|
32584
|
-
return;
|
|
32585
|
-
}
|
|
32586
|
-
await this.sendControlRequest("interrupt");
|
|
32587
|
-
}
|
|
32588
32574
|
/**
|
|
32589
32575
|
* file-sharing tool_use ↔ tool_result 配对(spec §6 PR 3)。
|
|
32590
32576
|
*
|
|
@@ -32709,17 +32695,9 @@ var SessionRunner = class {
|
|
|
32709
32695
|
this.doSpawn(effect.ctx);
|
|
32710
32696
|
break;
|
|
32711
32697
|
case "kill":
|
|
32712
|
-
if (this.session) {
|
|
32713
|
-
void this.session.stop();
|
|
32714
|
-
break;
|
|
32715
|
-
}
|
|
32716
32698
|
this.doKill(effect.signal);
|
|
32717
32699
|
break;
|
|
32718
32700
|
case "write-stdin":
|
|
32719
|
-
if (this.session) {
|
|
32720
|
-
this.session.startTurn(effect.payload);
|
|
32721
|
-
break;
|
|
32722
|
-
}
|
|
32723
32701
|
this.hooks.logger?.debug("[RG] write-stdin", {
|
|
32724
32702
|
procAlive: !!this.proc,
|
|
32725
32703
|
stdinWritable: !!this.proc?.stdin,
|
|
@@ -32729,21 +32707,7 @@ var SessionRunner = class {
|
|
|
32729
32707
|
this.proc?.stdin?.write(effect.payload);
|
|
32730
32708
|
this.recorder?.tapStdinWrite(effect.payload);
|
|
32731
32709
|
break;
|
|
32732
|
-
case "respond-permission": {
|
|
32733
|
-
if (this.session) {
|
|
32734
|
-
this.session.respondPermission(effect.requestId, effect.allow);
|
|
32735
|
-
break;
|
|
32736
|
-
}
|
|
32737
|
-
const payload = encodePermissionResponse(effect.requestId, effect.allow, effect.input, effect.message);
|
|
32738
|
-
this.proc?.stdin?.write(payload);
|
|
32739
|
-
this.recorder?.tapStdinWrite(payload);
|
|
32740
|
-
break;
|
|
32741
|
-
}
|
|
32742
32710
|
case "send-control-response-allow-with-input": {
|
|
32743
|
-
if (this.session) {
|
|
32744
|
-
this.session.answerQuestion(effect.requestId, effect.updatedInput);
|
|
32745
|
-
break;
|
|
32746
|
-
}
|
|
32747
32711
|
const payload = encodeAllowWithInputControlResponse(effect.requestId, effect.updatedInput);
|
|
32748
32712
|
this.proc?.stdin?.write(payload);
|
|
32749
32713
|
this.recorder?.tapStdinWrite(payload);
|
|
@@ -32800,22 +32764,6 @@ var SessionRunner = class {
|
|
|
32800
32764
|
}
|
|
32801
32765
|
// 启动子进程,绑定 stdout line buffer → 回灌 reducer
|
|
32802
32766
|
doSpawn(ctx) {
|
|
32803
|
-
if (this.hooks.adapter.createSession) {
|
|
32804
|
-
this.session = this.hooks.adapter.createSession(ctx, {
|
|
32805
|
-
pushEvents: (events) => {
|
|
32806
|
-
if (events.length === 0) return;
|
|
32807
|
-
const uuid = (this.hooks.genUuid ?? v4_default)();
|
|
32808
|
-
this.input({ kind: "inject-events", events: events.map((e) => e.uuid ? e : { ...e, uuid }) });
|
|
32809
|
-
},
|
|
32810
|
-
onExit: (code) => {
|
|
32811
|
-
this.session = null;
|
|
32812
|
-
this.clearIdleKillTimers();
|
|
32813
|
-
this.input({ kind: "proc-exit", code });
|
|
32814
|
-
},
|
|
32815
|
-
onError: (message) => this.input({ kind: "proc-error", message })
|
|
32816
|
-
});
|
|
32817
|
-
return;
|
|
32818
|
-
}
|
|
32819
32767
|
const proc = this.hooks.spawnOverride ? this.hooks.spawnOverride(ctx) : this.hooks.adapter.spawn(ctx);
|
|
32820
32768
|
this.proc = proc;
|
|
32821
32769
|
this.stdoutBuf = "";
|
|
@@ -33686,7 +33634,7 @@ var SessionManager = class {
|
|
|
33686
33634
|
tsid,
|
|
33687
33635
|
mode: this.deps.mode
|
|
33688
33636
|
});
|
|
33689
|
-
await runner.interrupt
|
|
33637
|
+
await runner.sendControlRequest("interrupt");
|
|
33690
33638
|
}
|
|
33691
33639
|
// 批量版本:UI 打开 session 时一次性拿到"磁盘和快照有差异"的 user message id 集合,
|
|
33692
33640
|
// 用来在消息流里精准控制 rewind 按钮的显示。session 没 toolSessionId 时返回空
|
|
@@ -35206,442 +35154,8 @@ function refreshDaemonManagedDirs(args) {
|
|
|
35206
35154
|
// src/index.ts
|
|
35207
35155
|
init_claude();
|
|
35208
35156
|
|
|
35209
|
-
// src/tools/codex.ts
|
|
35210
|
-
var import_node_child_process4 = require("child_process");
|
|
35211
|
-
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
35212
|
-
|
|
35213
|
-
// src/tools/codex-session.ts
|
|
35214
|
-
var import_node_child_process3 = require("child_process");
|
|
35215
|
-
|
|
35216
|
-
// src/tools/codex-app-server-client.ts
|
|
35217
|
-
var import_node_readline = require("readline");
|
|
35218
|
-
var CodexAppServerClient = class {
|
|
35219
|
-
constructor(proc, opts = {}) {
|
|
35220
|
-
this.proc = proc;
|
|
35221
|
-
this.opts = opts;
|
|
35222
|
-
const rl = (0, import_node_readline.createInterface)({ input: proc.stdout, crlfDelay: Infinity });
|
|
35223
|
-
rl.on("line", (l) => this.onLine(l));
|
|
35224
|
-
rl.on("close", () => {
|
|
35225
|
-
for (const p2 of this.pending.values()) p2.reject(new Error("app-server connection closed"));
|
|
35226
|
-
this.pending.clear();
|
|
35227
|
-
this.opts.onClose?.();
|
|
35228
|
-
});
|
|
35229
|
-
}
|
|
35230
|
-
proc;
|
|
35231
|
-
opts;
|
|
35232
|
-
nextId = 1;
|
|
35233
|
-
pending = /* @__PURE__ */ new Map();
|
|
35234
|
-
request(method, params) {
|
|
35235
|
-
const id = this.nextId++;
|
|
35236
|
-
return new Promise((resolve6, reject) => {
|
|
35237
|
-
this.pending.set(id, { resolve: resolve6, reject });
|
|
35238
|
-
this.write({ jsonrpc: "2.0", method, id, params });
|
|
35239
|
-
});
|
|
35240
|
-
}
|
|
35241
|
-
notify(method, params) {
|
|
35242
|
-
this.write({ jsonrpc: "2.0", method, params });
|
|
35243
|
-
}
|
|
35244
|
-
// server-request 的响应也必须带 jsonrpc:'2.0',否则 codex app-server 忽略它 → 审批/问答永远卡住。
|
|
35245
|
-
respond(id, result) {
|
|
35246
|
-
this.write({ jsonrpc: "2.0", id, result });
|
|
35247
|
-
}
|
|
35248
|
-
onLine(line) {
|
|
35249
|
-
const t = line.trim();
|
|
35250
|
-
if (!t) return;
|
|
35251
|
-
let m2;
|
|
35252
|
-
try {
|
|
35253
|
-
m2 = JSON.parse(t);
|
|
35254
|
-
} catch {
|
|
35255
|
-
return;
|
|
35256
|
-
}
|
|
35257
|
-
if (!isRecord(m2)) return;
|
|
35258
|
-
const hasId = typeof m2.id === "number", hasMethod = typeof m2.method === "string";
|
|
35259
|
-
if (hasId && !hasMethod) {
|
|
35260
|
-
const p2 = this.pending.get(m2.id);
|
|
35261
|
-
if (!p2) return;
|
|
35262
|
-
this.pending.delete(m2.id);
|
|
35263
|
-
if (m2.error) {
|
|
35264
|
-
const e = isRecord(m2.error) ? m2.error : {};
|
|
35265
|
-
p2.reject(new Error(typeof e.message === "string" ? e.message : "app-server error"));
|
|
35266
|
-
} else p2.resolve(m2.result);
|
|
35267
|
-
return;
|
|
35268
|
-
}
|
|
35269
|
-
if (hasId && hasMethod) {
|
|
35270
|
-
this.opts.onServerRequest?.(m2.id, m2.method, m2.params);
|
|
35271
|
-
return;
|
|
35272
|
-
}
|
|
35273
|
-
if (hasMethod) this.opts.onNotification?.(m2.method, m2.params);
|
|
35274
|
-
}
|
|
35275
|
-
write(o) {
|
|
35276
|
-
this.proc.stdin.write(JSON.stringify(o) + "\n");
|
|
35277
|
-
}
|
|
35278
|
-
};
|
|
35279
|
-
function isRecord(v2) {
|
|
35280
|
-
return typeof v2 === "object" && v2 !== null;
|
|
35281
|
-
}
|
|
35282
|
-
|
|
35283
|
-
// src/tools/codex-app-server-events.ts
|
|
35284
|
-
function translateNotification(method, params) {
|
|
35285
|
-
const p2 = rec(params);
|
|
35286
|
-
switch (method) {
|
|
35287
|
-
case "thread/started": {
|
|
35288
|
-
const id = str(rec(p2?.thread)?.id);
|
|
35289
|
-
return id ? [{ kind: "session_init", toolSessionId: id }] : [];
|
|
35290
|
-
}
|
|
35291
|
-
case "item/agentMessage/delta": {
|
|
35292
|
-
const text = str(p2?.delta);
|
|
35293
|
-
const id = str(p2?.itemId);
|
|
35294
|
-
return text ? [{ kind: "text", text, ...id ? { partialId: id } : {} }] : [];
|
|
35295
|
-
}
|
|
35296
|
-
case "item/reasoning/textDelta":
|
|
35297
|
-
case "item/reasoning/summaryTextDelta": {
|
|
35298
|
-
const text = str(p2?.delta);
|
|
35299
|
-
const id = str(p2?.itemId);
|
|
35300
|
-
return text ? [{ kind: "thinking", text, ...id ? { partialId: id } : {} }] : [];
|
|
35301
|
-
}
|
|
35302
|
-
case "item/commandExecution/outputDelta":
|
|
35303
|
-
return [];
|
|
35304
|
-
// 命令输出增量 v1 不逐字(完成时整段给)
|
|
35305
|
-
case "item/started":
|
|
35306
|
-
return itemStarted(rec(p2?.item));
|
|
35307
|
-
case "item/completed":
|
|
35308
|
-
return itemCompleted(rec(p2?.item));
|
|
35309
|
-
case "thread/tokenUsage/updated":
|
|
35310
|
-
return tokenUsage(rec(rec(p2?.tokenUsage)));
|
|
35311
|
-
case "turn/completed":
|
|
35312
|
-
return turnCompleted(rec(p2?.turn));
|
|
35313
|
-
default:
|
|
35314
|
-
return [];
|
|
35315
|
-
}
|
|
35316
|
-
}
|
|
35317
|
-
function itemStarted(item) {
|
|
35318
|
-
if (!item || item.type !== "commandExecution") return [];
|
|
35319
|
-
const id = str(item.id);
|
|
35320
|
-
if (!id) return [];
|
|
35321
|
-
return [{ kind: "tool_call", toolUseId: id, tool: "commandExecution", toolKind: "codex", input: { command: str(item.command) ?? "" } }];
|
|
35322
|
-
}
|
|
35323
|
-
function itemCompleted(item) {
|
|
35324
|
-
if (!item) return [];
|
|
35325
|
-
switch (item.type) {
|
|
35326
|
-
case "userMessage":
|
|
35327
|
-
return [];
|
|
35328
|
-
// 用户输入回显, clawd 自己 synthesize user_text
|
|
35329
|
-
case "agentMessage": {
|
|
35330
|
-
const text = str(item.text);
|
|
35331
|
-
return text ? [{ kind: "text", text }] : [];
|
|
35332
|
-
}
|
|
35333
|
-
case "reasoning": {
|
|
35334
|
-
const text = str(item.text);
|
|
35335
|
-
return text ? [{ kind: "thinking", text }] : [];
|
|
35336
|
-
}
|
|
35337
|
-
case "commandExecution": {
|
|
35338
|
-
const id = str(item.id);
|
|
35339
|
-
if (!id) return [];
|
|
35340
|
-
const exit = num(item.exitCode);
|
|
35341
|
-
const ev = { kind: "tool_result", toolUseId: id, output: str(item.aggregatedOutput ?? item.output) ?? "" };
|
|
35342
|
-
if (exit !== void 0 && exit !== 0) ev.error = `exit ${exit}`;
|
|
35343
|
-
return [ev];
|
|
35344
|
-
}
|
|
35345
|
-
default:
|
|
35346
|
-
return [];
|
|
35347
|
-
}
|
|
35348
|
-
}
|
|
35349
|
-
function tokenUsage(usage) {
|
|
35350
|
-
if (!usage) return [];
|
|
35351
|
-
const last = rec(usage.last);
|
|
35352
|
-
if (!last) return [];
|
|
35353
|
-
const i = num(last.inputTokens), o = num(last.outputTokens);
|
|
35354
|
-
const patch = {};
|
|
35355
|
-
if (i !== void 0 && o !== void 0) patch.contextUsage = { inputTokens: i, outputTokens: o };
|
|
35356
|
-
const w2 = num(usage.modelContextWindow);
|
|
35357
|
-
if (w2 !== void 0) patch.contextWindowSize = w2;
|
|
35358
|
-
return Object.keys(patch).length ? [{ kind: "meta_update", patch }] : [];
|
|
35359
|
-
}
|
|
35360
|
-
function turnCompleted(turn) {
|
|
35361
|
-
if (turn?.status === "failed") return [{ kind: "error", message: str(rec(turn.error)?.message) ?? "codex turn failed" }, { kind: "turn_end" }];
|
|
35362
|
-
return [{ kind: "turn_end" }];
|
|
35363
|
-
}
|
|
35364
|
-
function rec(v2) {
|
|
35365
|
-
return typeof v2 === "object" && v2 !== null ? v2 : void 0;
|
|
35366
|
-
}
|
|
35367
|
-
function str(v2) {
|
|
35368
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
35369
|
-
}
|
|
35370
|
-
function num(v2) {
|
|
35371
|
-
return typeof v2 === "number" ? v2 : void 0;
|
|
35372
|
-
}
|
|
35373
|
-
|
|
35374
|
-
// src/tools/codex-app-server-params.ts
|
|
35375
|
-
function resolveSandbox(ctx) {
|
|
35376
|
-
if (ctx.personaMode === "guest") throw new Error("codex \u6682\u4E0D\u652F\u6301 guest persona session\uFF1B\u8BF7\u7528 claude \u6216 owner");
|
|
35377
|
-
return "danger-full-access";
|
|
35378
|
-
}
|
|
35379
|
-
function resolveApprovalPolicy(ctx) {
|
|
35380
|
-
const m2 = ctx.permissionMode ?? "";
|
|
35381
|
-
if (m2 === "untrusted" || m2 === "on-failure" || m2 === "on-request" || m2 === "never") return m2;
|
|
35382
|
-
return "on-request";
|
|
35383
|
-
}
|
|
35384
|
-
function threadStartParams(ctx) {
|
|
35385
|
-
return {
|
|
35386
|
-
cwd: ctx.cwd,
|
|
35387
|
-
sandbox: resolveSandbox(ctx),
|
|
35388
|
-
// persona 侧
|
|
35389
|
-
approvalPolicy: resolveApprovalPolicy(ctx),
|
|
35390
|
-
// 会话设置侧
|
|
35391
|
-
approvalsReviewer: "user",
|
|
35392
|
-
...ctx.model ? { model: ctx.model } : {}
|
|
35393
|
-
};
|
|
35394
|
-
}
|
|
35395
|
-
var ATTACHMENT_RE2 = /\[attachment:(image|file):([^\]]+)\]/g;
|
|
35396
|
-
var SKILL_RE = /\[skill:(.+?):(\/[^\]]+)\]/g;
|
|
35397
|
-
function turnStartInput(text) {
|
|
35398
|
-
const items = [];
|
|
35399
|
-
let leftover = text;
|
|
35400
|
-
for (const m2 of text.matchAll(SKILL_RE)) {
|
|
35401
|
-
const [marker, name, path59] = m2;
|
|
35402
|
-
items.push({ type: "skill", name, path: path59 });
|
|
35403
|
-
leftover = leftover.replace(marker, "");
|
|
35404
|
-
}
|
|
35405
|
-
for (const m2 of text.matchAll(ATTACHMENT_RE2)) {
|
|
35406
|
-
const [marker, kind, url] = m2;
|
|
35407
|
-
if (kind === "image") {
|
|
35408
|
-
items.push({ type: "image", url });
|
|
35409
|
-
leftover = leftover.replace(marker, "");
|
|
35410
|
-
}
|
|
35411
|
-
}
|
|
35412
|
-
const trimmed = leftover.trim();
|
|
35413
|
-
if (trimmed || items.length === 0) items.push({ type: "text", text: trimmed, text_elements: [] });
|
|
35414
|
-
return items;
|
|
35415
|
-
}
|
|
35416
|
-
|
|
35417
|
-
// src/tools/codex-session.ts
|
|
35418
|
-
function createCodexSession(ctx, sink, deps = {}) {
|
|
35419
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
35420
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
35421
|
-
const env = { ...process.env, ...ctx.env };
|
|
35422
|
-
const proc = deps.spawnOverride ? deps.spawnOverride(cmd, args, ctx.cwd, env) : (0, import_node_child_process3.spawn)(cmd, args, { cwd: ctx.cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
35423
|
-
let threadId = ctx.toolSessionId;
|
|
35424
|
-
let turnId;
|
|
35425
|
-
const approvalIds = /* @__PURE__ */ new Map();
|
|
35426
|
-
const pendingQuestions = /* @__PURE__ */ new Map();
|
|
35427
|
-
let pendingSystemPrompt = ctx.toolSessionId ? void 0 : ctx.extraSystemPrompt;
|
|
35428
|
-
const effort = ctx.effort;
|
|
35429
|
-
let exited = false;
|
|
35430
|
-
const finish = (code) => {
|
|
35431
|
-
if (exited) return;
|
|
35432
|
-
exited = true;
|
|
35433
|
-
sink.onExit(code);
|
|
35434
|
-
};
|
|
35435
|
-
const client = new CodexAppServerClient(proc, {
|
|
35436
|
-
onNotification: (method, params) => {
|
|
35437
|
-
if (method === "turn/started") {
|
|
35438
|
-
const id = params?.turn?.id;
|
|
35439
|
-
if (id) turnId = id;
|
|
35440
|
-
}
|
|
35441
|
-
const events = translateNotification(method, params);
|
|
35442
|
-
if (events.length) sink.pushEvents(events);
|
|
35443
|
-
},
|
|
35444
|
-
onServerRequest: (id, method, params) => {
|
|
35445
|
-
const p2 = params ?? {};
|
|
35446
|
-
if (method === "item/commandExecution/requestApproval" || method === "item/fileChange/requestApproval") {
|
|
35447
|
-
const reqId = String(id);
|
|
35448
|
-
approvalIds.set(reqId, id);
|
|
35449
|
-
sink.pushEvents([
|
|
35450
|
-
{
|
|
35451
|
-
kind: "permission_request",
|
|
35452
|
-
requestId: reqId,
|
|
35453
|
-
tool: method.includes("fileChange") ? "fileChange" : "commandExecution",
|
|
35454
|
-
input: p2,
|
|
35455
|
-
...typeof p2.itemId === "string" ? { toolUseId: p2.itemId } : {}
|
|
35456
|
-
}
|
|
35457
|
-
]);
|
|
35458
|
-
return;
|
|
35459
|
-
}
|
|
35460
|
-
if (method === "tool/requestUserInput") {
|
|
35461
|
-
const reqId = String(id);
|
|
35462
|
-
approvalIds.set(reqId, id);
|
|
35463
|
-
const qs = Array.isArray(p2.questions) ? p2.questions.map((q) => ({
|
|
35464
|
-
id: String(q.id ?? ""),
|
|
35465
|
-
question: String(q.question ?? "")
|
|
35466
|
-
})) : [];
|
|
35467
|
-
pendingQuestions.set(reqId, qs);
|
|
35468
|
-
const questions = qs.map(({ question }) => ({
|
|
35469
|
-
question,
|
|
35470
|
-
multiSelect: false,
|
|
35471
|
-
options: []
|
|
35472
|
-
}));
|
|
35473
|
-
sink.pushEvents([{ kind: "ask_user_question", toolUseId: reqId, questions }]);
|
|
35474
|
-
return;
|
|
35475
|
-
}
|
|
35476
|
-
client.respond(id, "cancel");
|
|
35477
|
-
},
|
|
35478
|
-
onClose: () => finish(proc.exitCode)
|
|
35479
|
-
});
|
|
35480
|
-
proc.stderr?.on(
|
|
35481
|
-
"data",
|
|
35482
|
-
(c) => deps.logger?.warn("codex app-server stderr", { line: c.toString().slice(0, 500) })
|
|
35483
|
-
);
|
|
35484
|
-
proc.on("exit", (code) => finish(code));
|
|
35485
|
-
const ready = (async () => {
|
|
35486
|
-
await client.request("initialize", {
|
|
35487
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
35488
|
-
capabilities: null
|
|
35489
|
-
});
|
|
35490
|
-
client.notify("initialized", {});
|
|
35491
|
-
if (threadId) {
|
|
35492
|
-
await client.request("thread/resume", { threadId });
|
|
35493
|
-
} else {
|
|
35494
|
-
const res = await client.request("thread/start", threadStartParams(ctx));
|
|
35495
|
-
threadId = res?.thread?.id;
|
|
35496
|
-
if (threadId) sink.pushEvents([{ kind: "session_init", toolSessionId: threadId }]);
|
|
35497
|
-
}
|
|
35498
|
-
})().catch((e) => sink.onError(`codex app-server init failed: ${e.message}`));
|
|
35499
|
-
return {
|
|
35500
|
-
startTurn(text) {
|
|
35501
|
-
const body = pendingSystemPrompt ? `${pendingSystemPrompt}
|
|
35502
|
-
|
|
35503
|
-
${text}` : text;
|
|
35504
|
-
pendingSystemPrompt = void 0;
|
|
35505
|
-
void ready.then(() => {
|
|
35506
|
-
if (threadId)
|
|
35507
|
-
void client.request("turn/start", {
|
|
35508
|
-
threadId,
|
|
35509
|
-
input: turnStartInput(body),
|
|
35510
|
-
...effort ? { reasoningEffort: effort } : {}
|
|
35511
|
-
}).catch((e) => sink.onError(`turn/start failed: ${e.message}`));
|
|
35512
|
-
});
|
|
35513
|
-
},
|
|
35514
|
-
respondPermission(requestId, allow) {
|
|
35515
|
-
const id = approvalIds.get(requestId);
|
|
35516
|
-
if (id === void 0) return;
|
|
35517
|
-
approvalIds.delete(requestId);
|
|
35518
|
-
client.respond(id, { decision: allow ? "accept" : "decline" });
|
|
35519
|
-
},
|
|
35520
|
-
answerQuestion(requestId, answers) {
|
|
35521
|
-
const id = approvalIds.get(requestId);
|
|
35522
|
-
if (id === void 0) return;
|
|
35523
|
-
approvalIds.delete(requestId);
|
|
35524
|
-
const qs = pendingQuestions.get(requestId) ?? [];
|
|
35525
|
-
pendingQuestions.delete(requestId);
|
|
35526
|
-
const answerMap = {};
|
|
35527
|
-
for (const q of qs) answerMap[q.id] = { answers: [answers[q.question] ?? ""] };
|
|
35528
|
-
client.respond(id, { answers: answerMap });
|
|
35529
|
-
},
|
|
35530
|
-
interrupt() {
|
|
35531
|
-
if (threadId && turnId) void client.request("turn/interrupt", { threadId, turnId }).catch(() => {
|
|
35532
|
-
});
|
|
35533
|
-
},
|
|
35534
|
-
async stop() {
|
|
35535
|
-
this.interrupt();
|
|
35536
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
35537
|
-
}
|
|
35538
|
-
};
|
|
35539
|
-
}
|
|
35540
|
-
|
|
35541
|
-
// src/tools/codex.ts
|
|
35542
|
-
var CODEX_MODELS = [
|
|
35543
|
-
{ id: "", label: "Default", description: "codex config.toml \u9ED8\u8BA4", contextWindowSize: 258400, default: true },
|
|
35544
|
-
{ id: "gpt-5.5", label: "GPT-5.5", description: "Frontier model for complex coding", contextWindowSize: 258400 },
|
|
35545
|
-
{ id: "gpt-5.4", label: "GPT-5.4", contextWindowSize: 258400 },
|
|
35546
|
-
{ id: "gpt-5.4-mini", label: "GPT-5.4-Mini", contextWindowSize: 258400 }
|
|
35547
|
-
];
|
|
35548
|
-
var CODEX_EFFORTS = [
|
|
35549
|
-
{ value: "low", label: "Low", description: "Fast responses with lighter reasoning" },
|
|
35550
|
-
{ value: "medium", label: "Medium", description: "Balances speed and reasoning depth for everyday tasks" },
|
|
35551
|
-
{ value: "high", label: "High", description: "Greater reasoning depth for complex problems" },
|
|
35552
|
-
{ value: "xhigh", label: "Extra high", description: "Extra high reasoning depth for complex problems" }
|
|
35553
|
-
];
|
|
35554
|
-
var CODEX_APPROVAL_PRESETS = [
|
|
35555
|
-
{ id: "untrusted", label: "Ask for approval", description: "\u51E0\u4E4E\u6BCF\u6761\u547D\u4EE4\u90FD\u95EE\u4F60\uFF08\u6700\u8C28\u614E\uFF09" },
|
|
35556
|
-
{ id: "on-request", label: "Approve for me", description: "\u6A21\u578B\u81EA\u5DF1\u5224\u65AD\uFF0C\u53EA\u5BF9\u9AD8\u98CE\u9669\u64CD\u4F5C\u95EE\u4F60\uFF08\u9ED8\u8BA4\uFF09" },
|
|
35557
|
-
{ id: "never", label: "Full Access", description: "\u4ECE\u4E0D\u8BE2\u95EE\uFF0C\u81EA\u4E3B\u6267\u884C" }
|
|
35558
|
-
];
|
|
35559
|
-
var CODEX_CAPABILITIES = {
|
|
35560
|
-
tool: "codex",
|
|
35561
|
-
toolSessionIdLabel: "Codex Thread ID",
|
|
35562
|
-
models: CODEX_MODELS,
|
|
35563
|
-
permissionModes: CODEX_APPROVAL_PRESETS,
|
|
35564
|
-
// codex 不支持这些 clawd 功能(rewind 无 file-snapshot / 无子 agent / 无 TUI pty /
|
|
35565
|
-
// 无 observe 推送 / 无文件分享);UI 据此 gate 入口。
|
|
35566
|
-
features: { rewind: false, subagents: false, tui: false, observe: false, fileSharing: false },
|
|
35567
|
-
configSchema: [
|
|
35568
|
-
{
|
|
35569
|
-
name: "model",
|
|
35570
|
-
type: "select",
|
|
35571
|
-
label: "Model",
|
|
35572
|
-
scope: "core",
|
|
35573
|
-
options: CODEX_MODELS.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35574
|
-
default: ""
|
|
35575
|
-
},
|
|
35576
|
-
{
|
|
35577
|
-
name: "permissionMode",
|
|
35578
|
-
type: "select",
|
|
35579
|
-
label: "Approval",
|
|
35580
|
-
scope: "core",
|
|
35581
|
-
options: CODEX_APPROVAL_PRESETS.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35582
|
-
default: "on-request"
|
|
35583
|
-
},
|
|
35584
|
-
{
|
|
35585
|
-
name: "effort",
|
|
35586
|
-
type: "select",
|
|
35587
|
-
label: "Reasoning effort",
|
|
35588
|
-
scope: "tool-specific",
|
|
35589
|
-
// 渲染在 Advanced 区(与 claude effort 一致)
|
|
35590
|
-
options: CODEX_EFFORTS,
|
|
35591
|
-
default: "medium"
|
|
35592
|
-
}
|
|
35593
|
-
]
|
|
35594
|
-
};
|
|
35595
|
-
async function probeCodex(env = process.env) {
|
|
35596
|
-
if (env.CODEX_BIN && import_node_fs10.default.existsSync(env.CODEX_BIN)) return { available: true, path: env.CODEX_BIN };
|
|
35597
|
-
try {
|
|
35598
|
-
const out = (0, import_node_child_process4.execFileSync)("which", ["codex"], { encoding: "utf8" }).trim();
|
|
35599
|
-
if (out && import_node_fs10.default.existsSync(out)) return { available: true, path: out };
|
|
35600
|
-
} catch {
|
|
35601
|
-
}
|
|
35602
|
-
return { available: false };
|
|
35603
|
-
}
|
|
35604
|
-
var CodexAdapter = class {
|
|
35605
|
-
id = "codex";
|
|
35606
|
-
// 历史读取器:history:read 按 session.tool 路由到这里(thread/read)。
|
|
35607
|
-
historyReader;
|
|
35608
|
-
probeCache = null;
|
|
35609
|
-
logger;
|
|
35610
|
-
probeOverride;
|
|
35611
|
-
constructor(opts = {}) {
|
|
35612
|
-
this.logger = opts.logger;
|
|
35613
|
-
this.probeOverride = opts.probeOverride;
|
|
35614
|
-
this.historyReader = opts.historyReader;
|
|
35615
|
-
}
|
|
35616
|
-
async probe() {
|
|
35617
|
-
if (this.probeCache) return this.probeCache;
|
|
35618
|
-
this.probeCache = this.probeOverride ? await this.probeOverride() : await probeCodex();
|
|
35619
|
-
return this.probeCache;
|
|
35620
|
-
}
|
|
35621
|
-
async capabilities() {
|
|
35622
|
-
return CODEX_CAPABILITIES;
|
|
35623
|
-
}
|
|
35624
|
-
resolveContextWindow(modelId) {
|
|
35625
|
-
return (CODEX_MODELS.find((m2) => m2.id === (modelId ?? "")) ?? CODEX_MODELS[0]).contextWindowSize;
|
|
35626
|
-
}
|
|
35627
|
-
createSession(ctx, sink) {
|
|
35628
|
-
return createCodexSession(ctx, sink, { logger: this.logger });
|
|
35629
|
-
}
|
|
35630
|
-
spawn(_ctx) {
|
|
35631
|
-
throw new Error("CodexAdapter uses createSession, not spawn");
|
|
35632
|
-
}
|
|
35633
|
-
parseLine(_line) {
|
|
35634
|
-
return [];
|
|
35635
|
-
}
|
|
35636
|
-
// 原样返回带 marker 的文本;附件 marker → codex image 多模态由 turnStartInput 解析
|
|
35637
|
-
// (codex-app-server-params.ts, PR1)。encodeStdin 不动 markers。
|
|
35638
|
-
encodeStdin(text, _ctx) {
|
|
35639
|
-
return text;
|
|
35640
|
-
}
|
|
35641
|
-
};
|
|
35642
|
-
|
|
35643
35157
|
// src/tools/claude-tui.ts
|
|
35644
|
-
var
|
|
35158
|
+
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
35645
35159
|
var import_node_os5 = __toESM(require("os"), 1);
|
|
35646
35160
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
35647
35161
|
var import_headless = __toESM(require_xterm_headless(), 1);
|
|
@@ -36625,7 +36139,7 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36625
36139
|
const home = import_node_os5.default.homedir();
|
|
36626
36140
|
const file = import_node_path10.default.join(home, ".claude", "projects", cwdToHashDir(ctx.cwd), `${ctx.toolSessionId}.jsonl`);
|
|
36627
36141
|
try {
|
|
36628
|
-
return
|
|
36142
|
+
return import_node_fs10.default.statSync(file).isFile();
|
|
36629
36143
|
} catch {
|
|
36630
36144
|
return false;
|
|
36631
36145
|
}
|
|
@@ -36634,236 +36148,8 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36634
36148
|
// src/index.ts
|
|
36635
36149
|
init_claude_history();
|
|
36636
36150
|
|
|
36637
|
-
// src/tools/codex-history.ts
|
|
36638
|
-
var import_node_child_process5 = require("child_process");
|
|
36639
|
-
var DEFAULT_TIMEOUT_MS = 8e3;
|
|
36640
|
-
function rec2(v2) {
|
|
36641
|
-
return v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : void 0;
|
|
36642
|
-
}
|
|
36643
|
-
function str2(v2) {
|
|
36644
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
36645
|
-
}
|
|
36646
|
-
function num2(v2) {
|
|
36647
|
-
return typeof v2 === "number" && Number.isFinite(v2) ? v2 : void 0;
|
|
36648
|
-
}
|
|
36649
|
-
function userInputText(content) {
|
|
36650
|
-
if (!Array.isArray(content)) return "";
|
|
36651
|
-
return content.map((c) => {
|
|
36652
|
-
const r = rec2(c);
|
|
36653
|
-
return r && r.type === "text" ? str2(r.text) ?? "" : "";
|
|
36654
|
-
}).filter(Boolean).join("");
|
|
36655
|
-
}
|
|
36656
|
-
function threadItemToHistoryMessages(item) {
|
|
36657
|
-
const it = rec2(item);
|
|
36658
|
-
if (!it) return [];
|
|
36659
|
-
switch (it.type) {
|
|
36660
|
-
case "userMessage": {
|
|
36661
|
-
const text = userInputText(it.content);
|
|
36662
|
-
return text ? [{ kind: "user-text", text, raw: item }] : [];
|
|
36663
|
-
}
|
|
36664
|
-
case "agentMessage": {
|
|
36665
|
-
const text = str2(it.text);
|
|
36666
|
-
return text ? [{ kind: "assistant-text", text, raw: item }] : [];
|
|
36667
|
-
}
|
|
36668
|
-
case "commandExecution": {
|
|
36669
|
-
const id = str2(it.id);
|
|
36670
|
-
if (!id) return [];
|
|
36671
|
-
const msgs = [
|
|
36672
|
-
{
|
|
36673
|
-
kind: "tool_call",
|
|
36674
|
-
tool: "commandExecution",
|
|
36675
|
-
toolUseId: id,
|
|
36676
|
-
input: { command: str2(it.command) ?? "" },
|
|
36677
|
-
raw: item
|
|
36678
|
-
}
|
|
36679
|
-
];
|
|
36680
|
-
if (it.status === "completed" || it.aggregatedOutput != null || it.exitCode != null) {
|
|
36681
|
-
const exit = num2(it.exitCode);
|
|
36682
|
-
const result = {
|
|
36683
|
-
kind: "tool_result",
|
|
36684
|
-
toolUseId: id,
|
|
36685
|
-
output: str2(it.aggregatedOutput) ?? "",
|
|
36686
|
-
raw: item
|
|
36687
|
-
};
|
|
36688
|
-
if (exit !== void 0 && exit !== 0) result.output = `${result.output ?? ""}
|
|
36689
|
-
(exit ${exit})`;
|
|
36690
|
-
msgs.push(result);
|
|
36691
|
-
}
|
|
36692
|
-
return msgs;
|
|
36693
|
-
}
|
|
36694
|
-
default:
|
|
36695
|
-
return [];
|
|
36696
|
-
}
|
|
36697
|
-
}
|
|
36698
|
-
async function queryCodexAppServer(cwd, method, params, deps) {
|
|
36699
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
36700
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
36701
|
-
const proc = deps.spawnOverride ? deps.spawnOverride(cmd, args, cwd) : (0, import_node_child_process5.spawn)(cmd, args, { cwd, env: process.env, stdio: ["pipe", "pipe", "pipe"] });
|
|
36702
|
-
const client = new CodexAppServerClient(proc, {});
|
|
36703
|
-
const timeoutMs = deps.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
36704
|
-
let timer;
|
|
36705
|
-
const timeout = new Promise((_2, reject) => {
|
|
36706
|
-
timer = setTimeout(() => reject(new Error(`codex app-server ${method} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
36707
|
-
});
|
|
36708
|
-
try {
|
|
36709
|
-
await Promise.race([
|
|
36710
|
-
(async () => {
|
|
36711
|
-
await client.request("initialize", {
|
|
36712
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
36713
|
-
capabilities: null
|
|
36714
|
-
});
|
|
36715
|
-
client.notify("initialized", {});
|
|
36716
|
-
})(),
|
|
36717
|
-
timeout
|
|
36718
|
-
]);
|
|
36719
|
-
return await Promise.race([client.request(method, params), timeout]);
|
|
36720
|
-
} finally {
|
|
36721
|
-
if (timer) clearTimeout(timer);
|
|
36722
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
36723
|
-
}
|
|
36724
|
-
}
|
|
36725
|
-
var CodexHistoryReader = class {
|
|
36726
|
-
deps;
|
|
36727
|
-
constructor(deps = {}) {
|
|
36728
|
-
this.deps = deps;
|
|
36729
|
-
}
|
|
36730
|
-
// v1 先返回 []:projects/list 非 session-scoped、不知 tool,跨-tool 项目浏览器合并排后续。
|
|
36731
|
-
// codex 旧会话仍能经 clawd 活跃列表(session:list, tool-agnostic) + read 打开。
|
|
36732
|
-
async listProjects() {
|
|
36733
|
-
return [];
|
|
36734
|
-
}
|
|
36735
|
-
async listSessions(args) {
|
|
36736
|
-
const res = rec2(
|
|
36737
|
-
await queryCodexAppServer(
|
|
36738
|
-
args.projectPath,
|
|
36739
|
-
"thread/list",
|
|
36740
|
-
{
|
|
36741
|
-
limit: 100,
|
|
36742
|
-
sortKey: "updated_at",
|
|
36743
|
-
sortDirection: "desc",
|
|
36744
|
-
archived: false,
|
|
36745
|
-
cwd: args.projectPath,
|
|
36746
|
-
useStateDbOnly: true
|
|
36747
|
-
},
|
|
36748
|
-
this.deps
|
|
36749
|
-
)
|
|
36750
|
-
);
|
|
36751
|
-
const data = res && Array.isArray(res.data) ? res.data : [];
|
|
36752
|
-
const out = [];
|
|
36753
|
-
for (const entry of data) {
|
|
36754
|
-
const e = rec2(entry);
|
|
36755
|
-
const id = e && str2(e.id);
|
|
36756
|
-
if (!e || !id) continue;
|
|
36757
|
-
const updatedAtMs = Math.round((num2(e.updatedAt) ?? 0) * 1e3);
|
|
36758
|
-
out.push({
|
|
36759
|
-
toolSessionId: id,
|
|
36760
|
-
summary: str2(e.preview) || "(\u7A7A\u4F1A\u8BDD)",
|
|
36761
|
-
messageCount: 0,
|
|
36762
|
-
// thread/list 不提供条数;活跃/read 时才知
|
|
36763
|
-
updatedAt: new Date(updatedAtMs).toISOString()
|
|
36764
|
-
});
|
|
36765
|
-
}
|
|
36766
|
-
return out;
|
|
36767
|
-
}
|
|
36768
|
-
async read(args) {
|
|
36769
|
-
const res = rec2(
|
|
36770
|
-
await queryCodexAppServer(
|
|
36771
|
-
args.cwd,
|
|
36772
|
-
"thread/read",
|
|
36773
|
-
{ threadId: args.toolSessionId, includeTurns: true },
|
|
36774
|
-
this.deps
|
|
36775
|
-
)
|
|
36776
|
-
);
|
|
36777
|
-
const thread = res && rec2(res.thread);
|
|
36778
|
-
const turns = thread && Array.isArray(thread.turns) ? thread.turns : [];
|
|
36779
|
-
const messages = [];
|
|
36780
|
-
for (const turn of turns) {
|
|
36781
|
-
const t = rec2(turn);
|
|
36782
|
-
const items = t && Array.isArray(t.items) ? t.items : [];
|
|
36783
|
-
for (const item of items) messages.push(...threadItemToHistoryMessages(item));
|
|
36784
|
-
}
|
|
36785
|
-
const total = messages.length;
|
|
36786
|
-
const limit = args.limit ?? total;
|
|
36787
|
-
const offset = typeof args.offset === "number" ? Math.min(Math.max(0, args.offset), total) : Math.max(0, total - limit);
|
|
36788
|
-
return { messages: messages.slice(offset, offset + limit), total, offset };
|
|
36789
|
-
}
|
|
36790
|
-
// codex 无 sidechain 子 agent / file-history-snapshot → 全 stub 空(对齐 claude-history 同方法空返回)
|
|
36791
|
-
async listSubagents() {
|
|
36792
|
-
return [];
|
|
36793
|
-
}
|
|
36794
|
-
async readSubagent() {
|
|
36795
|
-
return { messages: [] };
|
|
36796
|
-
}
|
|
36797
|
-
computeRewindDiff() {
|
|
36798
|
-
return { canRewind: false, files: [], totalInsertions: 0, totalDeletions: 0 };
|
|
36799
|
-
}
|
|
36800
|
-
listRewindableUserMessageIds() {
|
|
36801
|
-
return [];
|
|
36802
|
-
}
|
|
36803
|
-
};
|
|
36804
|
-
|
|
36805
|
-
// src/tools/codex-skills.ts
|
|
36806
|
-
var import_node_child_process6 = require("child_process");
|
|
36807
|
-
var DEFAULT_TIMEOUT_MS2 = 8e3;
|
|
36808
|
-
function str3(v2) {
|
|
36809
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
36810
|
-
}
|
|
36811
|
-
function mapSkillsListResponse(res) {
|
|
36812
|
-
const data = res?.data;
|
|
36813
|
-
if (!Array.isArray(data)) return [];
|
|
36814
|
-
const out = [];
|
|
36815
|
-
for (const entry of data) {
|
|
36816
|
-
const skills = entry?.skills;
|
|
36817
|
-
if (!Array.isArray(skills)) continue;
|
|
36818
|
-
for (const s of skills) {
|
|
36819
|
-
const r = s ?? {};
|
|
36820
|
-
const name = str3(r.name);
|
|
36821
|
-
if (!name) continue;
|
|
36822
|
-
const path59 = str3(r.path);
|
|
36823
|
-
const description = str3(r.description);
|
|
36824
|
-
const isPlugin = name.includes(":");
|
|
36825
|
-
out.push({
|
|
36826
|
-
name,
|
|
36827
|
-
source: isPlugin ? "plugin" : "project",
|
|
36828
|
-
...path59 ? { path: path59 } : {},
|
|
36829
|
-
...description ? { description } : {},
|
|
36830
|
-
...isPlugin ? { plugin: name.split(":")[0] } : {}
|
|
36831
|
-
});
|
|
36832
|
-
}
|
|
36833
|
-
}
|
|
36834
|
-
return out;
|
|
36835
|
-
}
|
|
36836
|
-
async function listCodexSkills(cwd, deps = {}) {
|
|
36837
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
36838
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
36839
|
-
const proc = deps.spawnOverride ? deps.spawnOverride(cmd, args, cwd) : (0, import_node_child_process6.spawn)(cmd, args, { cwd, env: process.env, stdio: ["pipe", "pipe", "pipe"] });
|
|
36840
|
-
const client = new CodexAppServerClient(proc, {});
|
|
36841
|
-
const timeoutMs = deps.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
36842
|
-
let timer;
|
|
36843
|
-
const timeout = new Promise((_2, reject) => {
|
|
36844
|
-
timer = setTimeout(() => reject(new Error(`codex app-server skills/list timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
36845
|
-
});
|
|
36846
|
-
try {
|
|
36847
|
-
await Promise.race([
|
|
36848
|
-
(async () => {
|
|
36849
|
-
await client.request("initialize", {
|
|
36850
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
36851
|
-
capabilities: null
|
|
36852
|
-
});
|
|
36853
|
-
client.notify("initialized", {});
|
|
36854
|
-
})(),
|
|
36855
|
-
timeout
|
|
36856
|
-
]);
|
|
36857
|
-
const res = await Promise.race([client.request("skills/list", { cwds: [cwd] }), timeout]);
|
|
36858
|
-
return mapSkillsListResponse(res);
|
|
36859
|
-
} finally {
|
|
36860
|
-
if (timer) clearTimeout(timer);
|
|
36861
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
36862
|
-
}
|
|
36863
|
-
}
|
|
36864
|
-
|
|
36865
36151
|
// src/workspace/browser.ts
|
|
36866
|
-
var
|
|
36152
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
36867
36153
|
var import_node_os6 = __toESM(require("os"), 1);
|
|
36868
36154
|
var import_node_path11 = __toESM(require("path"), 1);
|
|
36869
36155
|
init_protocol();
|
|
@@ -36879,7 +36165,7 @@ function resolveInsideCwd(cwd, subpath) {
|
|
|
36879
36165
|
}
|
|
36880
36166
|
function ensureCwd(cwd) {
|
|
36881
36167
|
try {
|
|
36882
|
-
const stat =
|
|
36168
|
+
const stat = import_node_fs11.default.statSync(cwd);
|
|
36883
36169
|
if (!stat.isDirectory()) {
|
|
36884
36170
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${cwd}`);
|
|
36885
36171
|
}
|
|
@@ -36893,7 +36179,7 @@ var WorkspaceBrowser = class {
|
|
|
36893
36179
|
const cwd = args.cwd && args.cwd.length > 0 ? args.cwd : import_node_os6.default.homedir();
|
|
36894
36180
|
ensureCwd(cwd);
|
|
36895
36181
|
const full = resolveInsideCwd(cwd, args.path);
|
|
36896
|
-
const dirents =
|
|
36182
|
+
const dirents = import_node_fs11.default.readdirSync(full, { withFileTypes: true });
|
|
36897
36183
|
const entries = [];
|
|
36898
36184
|
for (const d of dirents) {
|
|
36899
36185
|
if (!args.showHidden && d.name.startsWith(".")) continue;
|
|
@@ -36903,7 +36189,7 @@ var WorkspaceBrowser = class {
|
|
|
36903
36189
|
mtime: ""
|
|
36904
36190
|
};
|
|
36905
36191
|
try {
|
|
36906
|
-
const st =
|
|
36192
|
+
const st = import_node_fs11.default.statSync(import_node_path11.default.join(full, d.name));
|
|
36907
36193
|
entry.mtime = new Date(st.mtimeMs).toISOString();
|
|
36908
36194
|
if (d.isFile()) entry.size = st.size;
|
|
36909
36195
|
} catch {
|
|
@@ -36919,14 +36205,14 @@ var WorkspaceBrowser = class {
|
|
|
36919
36205
|
read(args) {
|
|
36920
36206
|
ensureCwd(args.cwd);
|
|
36921
36207
|
const full = resolveInsideCwd(args.cwd, args.path);
|
|
36922
|
-
const st =
|
|
36208
|
+
const st = import_node_fs11.default.statSync(full);
|
|
36923
36209
|
if (!st.isFile()) {
|
|
36924
36210
|
throw new ClawdError(ERROR_CODES.INVALID_PATH, `not a file: ${args.path}`);
|
|
36925
36211
|
}
|
|
36926
36212
|
if (st.size > MAX_FILE_BYTES) {
|
|
36927
36213
|
throw new ClawdError(ERROR_CODES.FILE_TOO_LARGE, `file > ${MAX_FILE_BYTES} bytes`);
|
|
36928
36214
|
}
|
|
36929
|
-
const buf =
|
|
36215
|
+
const buf = import_node_fs11.default.readFileSync(full);
|
|
36930
36216
|
const isBinary = buf.includes(0);
|
|
36931
36217
|
if (isBinary) {
|
|
36932
36218
|
return {
|
|
@@ -36948,20 +36234,20 @@ var WorkspaceBrowser = class {
|
|
|
36948
36234
|
};
|
|
36949
36235
|
|
|
36950
36236
|
// src/skills/agents-scanner.ts
|
|
36951
|
-
var
|
|
36237
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
36952
36238
|
var import_node_os7 = __toESM(require("os"), 1);
|
|
36953
36239
|
var import_node_path12 = __toESM(require("path"), 1);
|
|
36954
36240
|
var DEFAULT_POLICY_DIR_DARWIN = "/Library/Application Support/ClaudeCode/.claude/agents";
|
|
36955
36241
|
function isDirLikeSync2(p2) {
|
|
36956
36242
|
try {
|
|
36957
|
-
return
|
|
36243
|
+
return import_node_fs12.default.statSync(p2).isDirectory();
|
|
36958
36244
|
} catch {
|
|
36959
36245
|
return false;
|
|
36960
36246
|
}
|
|
36961
36247
|
}
|
|
36962
36248
|
function fileExistsSync(p2) {
|
|
36963
36249
|
try {
|
|
36964
|
-
return
|
|
36250
|
+
return import_node_fs12.default.statSync(p2).isFile();
|
|
36965
36251
|
} catch {
|
|
36966
36252
|
return false;
|
|
36967
36253
|
}
|
|
@@ -36969,7 +36255,7 @@ function fileExistsSync(p2) {
|
|
|
36969
36255
|
function parseAgentFile(filePath) {
|
|
36970
36256
|
let content;
|
|
36971
36257
|
try {
|
|
36972
|
-
content =
|
|
36258
|
+
content = import_node_fs12.default.readFileSync(filePath, "utf8");
|
|
36973
36259
|
} catch {
|
|
36974
36260
|
return {};
|
|
36975
36261
|
}
|
|
@@ -36982,7 +36268,7 @@ function parseAgentFile(filePath) {
|
|
|
36982
36268
|
function scanAgentsDir(dir, source, seen, out) {
|
|
36983
36269
|
let entries;
|
|
36984
36270
|
try {
|
|
36985
|
-
entries =
|
|
36271
|
+
entries = import_node_fs12.default.readdirSync(dir, { withFileTypes: true });
|
|
36986
36272
|
} catch {
|
|
36987
36273
|
return;
|
|
36988
36274
|
}
|
|
@@ -37009,7 +36295,7 @@ function scanPluginAgentsTree(root, pluginName, seen, out) {
|
|
|
37009
36295
|
function walk2(dir, namespaces) {
|
|
37010
36296
|
let entries;
|
|
37011
36297
|
try {
|
|
37012
|
-
entries =
|
|
36298
|
+
entries = import_node_fs12.default.readdirSync(dir, { withFileTypes: true });
|
|
37013
36299
|
} catch {
|
|
37014
36300
|
return;
|
|
37015
36301
|
}
|
|
@@ -37045,7 +36331,7 @@ function readInstalledPlugins2(home) {
|
|
|
37045
36331
|
let raw = null;
|
|
37046
36332
|
for (const candidate of [v2, v1]) {
|
|
37047
36333
|
try {
|
|
37048
|
-
raw =
|
|
36334
|
+
raw = import_node_fs12.default.readFileSync(candidate, "utf8");
|
|
37049
36335
|
break;
|
|
37050
36336
|
} catch {
|
|
37051
36337
|
}
|
|
@@ -37076,7 +36362,7 @@ function walkUpProjectAgentsDirs(startCwd, home, seen, out) {
|
|
|
37076
36362
|
scanAgentsDir(import_node_path12.default.join(cur, ".claude", "agents"), "project", seen, out);
|
|
37077
36363
|
let hasGit = false;
|
|
37078
36364
|
try {
|
|
37079
|
-
hasGit =
|
|
36365
|
+
hasGit = import_node_fs12.default.existsSync(import_node_path12.default.join(cur, ".git"));
|
|
37080
36366
|
} catch {
|
|
37081
36367
|
}
|
|
37082
36368
|
if (hasGit) return;
|
|
@@ -37139,13 +36425,13 @@ var AgentsScanner = class {
|
|
|
37139
36425
|
};
|
|
37140
36426
|
|
|
37141
36427
|
// src/observer/session-observer.ts
|
|
37142
|
-
var
|
|
36428
|
+
var import_node_fs14 = __toESM(require("fs"), 1);
|
|
37143
36429
|
var import_node_os9 = __toESM(require("os"), 1);
|
|
37144
36430
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
37145
36431
|
init_claude_history();
|
|
37146
36432
|
|
|
37147
36433
|
// src/observer/subagent-meta-observer.ts
|
|
37148
|
-
var
|
|
36434
|
+
var import_node_fs13 = __toESM(require("fs"), 1);
|
|
37149
36435
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
37150
36436
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
37151
36437
|
init_claude_history();
|
|
@@ -37190,7 +36476,7 @@ var SubagentMetaObserver = class {
|
|
|
37190
36476
|
attachWatcher(w2) {
|
|
37191
36477
|
if (w2.watcher) return;
|
|
37192
36478
|
try {
|
|
37193
|
-
w2.watcher =
|
|
36479
|
+
w2.watcher = import_node_fs13.default.watch(w2.dirPath, { persistent: false }, (_evt, name) => {
|
|
37194
36480
|
if (!name) return;
|
|
37195
36481
|
const m2 = META_RE.exec(String(name));
|
|
37196
36482
|
if (!m2) return;
|
|
@@ -37202,7 +36488,7 @@ var SubagentMetaObserver = class {
|
|
|
37202
36488
|
scan(w2) {
|
|
37203
36489
|
let entries;
|
|
37204
36490
|
try {
|
|
37205
|
-
entries =
|
|
36491
|
+
entries = import_node_fs13.default.readdirSync(w2.dirPath);
|
|
37206
36492
|
} catch {
|
|
37207
36493
|
return;
|
|
37208
36494
|
}
|
|
@@ -37219,7 +36505,7 @@ var SubagentMetaObserver = class {
|
|
|
37219
36505
|
const file = import_node_path13.default.join(w2.dirPath, name);
|
|
37220
36506
|
let raw;
|
|
37221
36507
|
try {
|
|
37222
|
-
raw =
|
|
36508
|
+
raw = import_node_fs13.default.readFileSync(file, "utf8");
|
|
37223
36509
|
} catch {
|
|
37224
36510
|
return;
|
|
37225
36511
|
}
|
|
@@ -37283,7 +36569,7 @@ var SessionObserver = class {
|
|
|
37283
36569
|
const filePath = this.resolveJsonlPath(args.cwd, args.toolSessionId, args.jsonlPath);
|
|
37284
36570
|
let size = 0;
|
|
37285
36571
|
try {
|
|
37286
|
-
size =
|
|
36572
|
+
size = import_node_fs14.default.statSync(filePath).size;
|
|
37287
36573
|
} catch {
|
|
37288
36574
|
}
|
|
37289
36575
|
const w2 = {
|
|
@@ -37297,10 +36583,10 @@ var SessionObserver = class {
|
|
|
37297
36583
|
prevIsRejectSentinel: false
|
|
37298
36584
|
};
|
|
37299
36585
|
try {
|
|
37300
|
-
|
|
36586
|
+
import_node_fs14.default.mkdirSync(import_node_path14.default.dirname(filePath), { recursive: true });
|
|
37301
36587
|
} catch {
|
|
37302
36588
|
}
|
|
37303
|
-
w2.watcher =
|
|
36589
|
+
w2.watcher = import_node_fs14.default.watch(import_node_path14.default.dirname(filePath), { persistent: false }, (_event, changedName) => {
|
|
37304
36590
|
if (!changedName || !filePath.endsWith(changedName)) return;
|
|
37305
36591
|
this.poll(w2);
|
|
37306
36592
|
});
|
|
@@ -37323,7 +36609,7 @@ var SessionObserver = class {
|
|
|
37323
36609
|
// 异常静默吞,不阻塞 watcher 启动
|
|
37324
36610
|
hydrateMetaTail(w2, maxLines = 200) {
|
|
37325
36611
|
try {
|
|
37326
|
-
const raw =
|
|
36612
|
+
const raw = import_node_fs14.default.readFileSync(w2.filePath, "utf8");
|
|
37327
36613
|
if (!raw) return;
|
|
37328
36614
|
const allLines = raw.split("\n").filter((l) => l.trim().length > 0);
|
|
37329
36615
|
if (allLines.length === 0) return;
|
|
@@ -37347,7 +36633,7 @@ var SessionObserver = class {
|
|
|
37347
36633
|
poll(w2) {
|
|
37348
36634
|
let size = 0;
|
|
37349
36635
|
try {
|
|
37350
|
-
size =
|
|
36636
|
+
size = import_node_fs14.default.statSync(w2.filePath).size;
|
|
37351
36637
|
} catch {
|
|
37352
36638
|
return;
|
|
37353
36639
|
}
|
|
@@ -37356,11 +36642,11 @@ var SessionObserver = class {
|
|
|
37356
36642
|
w2.buf = "";
|
|
37357
36643
|
}
|
|
37358
36644
|
if (size === w2.lastSize) return;
|
|
37359
|
-
const fd =
|
|
36645
|
+
const fd = import_node_fs14.default.openSync(w2.filePath, "r");
|
|
37360
36646
|
try {
|
|
37361
36647
|
const len = size - w2.lastSize;
|
|
37362
36648
|
const buf = Buffer.alloc(len);
|
|
37363
|
-
|
|
36649
|
+
import_node_fs14.default.readSync(fd, buf, 0, len, w2.lastSize);
|
|
37364
36650
|
w2.lastSize = size;
|
|
37365
36651
|
w2.buf += buf.toString("utf8");
|
|
37366
36652
|
let newlineIndex;
|
|
@@ -37383,7 +36669,7 @@ var SessionObserver = class {
|
|
|
37383
36669
|
}
|
|
37384
36670
|
}
|
|
37385
36671
|
} finally {
|
|
37386
|
-
|
|
36672
|
+
import_node_fs14.default.closeSync(fd);
|
|
37387
36673
|
}
|
|
37388
36674
|
}
|
|
37389
36675
|
// 解析 JSONL 单行:仅当是主链 user 文本行(非 sidechain / 非 sub-agent / message.role='user'
|
|
@@ -38106,14 +37392,14 @@ async function authenticate(token, deps) {
|
|
|
38106
37392
|
}
|
|
38107
37393
|
|
|
38108
37394
|
// src/permission/capability-store.ts
|
|
38109
|
-
var
|
|
37395
|
+
var fs17 = __toESM(require("fs"), 1);
|
|
38110
37396
|
var path19 = __toESM(require("path"), 1);
|
|
38111
37397
|
var CAPABILITIES_FILE_NAME = "capabilities.json";
|
|
38112
37398
|
var FILE_VERSION = 1;
|
|
38113
37399
|
var CapabilityStore = class {
|
|
38114
37400
|
constructor(dataDir) {
|
|
38115
37401
|
this.dataDir = dataDir;
|
|
38116
|
-
|
|
37402
|
+
fs17.mkdirSync(dataDir, { recursive: true });
|
|
38117
37403
|
this.cache = this.readFromDisk();
|
|
38118
37404
|
}
|
|
38119
37405
|
dataDir;
|
|
@@ -38143,7 +37429,7 @@ var CapabilityStore = class {
|
|
|
38143
37429
|
const file = this.filePath();
|
|
38144
37430
|
let raw;
|
|
38145
37431
|
try {
|
|
38146
|
-
raw =
|
|
37432
|
+
raw = fs17.readFileSync(file, "utf8");
|
|
38147
37433
|
} catch (err) {
|
|
38148
37434
|
if (err?.code === "ENOENT") return [];
|
|
38149
37435
|
return [];
|
|
@@ -38171,10 +37457,10 @@ var CapabilityStore = class {
|
|
|
38171
37457
|
}
|
|
38172
37458
|
atomicWrite(file, content) {
|
|
38173
37459
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
38174
|
-
|
|
38175
|
-
|
|
37460
|
+
fs17.writeFileSync(tmp, content, { mode: 384 });
|
|
37461
|
+
fs17.renameSync(tmp, file);
|
|
38176
37462
|
try {
|
|
38177
|
-
|
|
37463
|
+
fs17.chmodSync(file, 384);
|
|
38178
37464
|
} catch {
|
|
38179
37465
|
}
|
|
38180
37466
|
}
|
|
@@ -38267,14 +37553,14 @@ var CapabilityManager = class {
|
|
|
38267
37553
|
};
|
|
38268
37554
|
|
|
38269
37555
|
// src/permission/cleanup.ts
|
|
38270
|
-
var
|
|
37556
|
+
var fs18 = __toESM(require("fs"), 1);
|
|
38271
37557
|
function cleanupGuestSessionsForCapability(cap, factory) {
|
|
38272
37558
|
const removed = [];
|
|
38273
37559
|
for (const g2 of cap.grants) {
|
|
38274
37560
|
if (g2.resource.type !== "persona") continue;
|
|
38275
37561
|
const dir = factory.vmGuestRoot(g2.resource.id, cap.id);
|
|
38276
37562
|
try {
|
|
38277
|
-
|
|
37563
|
+
fs18.rmSync(dir, { recursive: true, force: true });
|
|
38278
37564
|
removed.push(dir);
|
|
38279
37565
|
} catch {
|
|
38280
37566
|
}
|
|
@@ -38283,13 +37569,13 @@ function cleanupGuestSessionsForCapability(cap, factory) {
|
|
|
38283
37569
|
}
|
|
38284
37570
|
|
|
38285
37571
|
// src/inbox/inbox-store.ts
|
|
38286
|
-
var
|
|
37572
|
+
var fs19 = __toESM(require("fs"), 1);
|
|
38287
37573
|
var path20 = __toESM(require("path"), 1);
|
|
38288
37574
|
var INBOX_SUBDIR = "inbox";
|
|
38289
37575
|
var InboxStore = class {
|
|
38290
37576
|
constructor(dataDir) {
|
|
38291
37577
|
this.dataDir = dataDir;
|
|
38292
|
-
|
|
37578
|
+
fs19.mkdirSync(this.dirPath(), { recursive: true });
|
|
38293
37579
|
}
|
|
38294
37580
|
dataDir;
|
|
38295
37581
|
/**
|
|
@@ -38301,7 +37587,7 @@ var InboxStore = class {
|
|
|
38301
37587
|
const file = this.filePath(peerDeviceId);
|
|
38302
37588
|
let raw;
|
|
38303
37589
|
try {
|
|
38304
|
-
raw =
|
|
37590
|
+
raw = fs19.readFileSync(file, "utf8");
|
|
38305
37591
|
} catch (err) {
|
|
38306
37592
|
if (err?.code === "ENOENT") return [];
|
|
38307
37593
|
return [];
|
|
@@ -38317,7 +37603,7 @@ var InboxStore = class {
|
|
|
38317
37603
|
const dir = this.dirPath();
|
|
38318
37604
|
let entries;
|
|
38319
37605
|
try {
|
|
38320
|
-
entries =
|
|
37606
|
+
entries = fs19.readdirSync(dir);
|
|
38321
37607
|
} catch (err) {
|
|
38322
37608
|
if (err?.code === "ENOENT") return [];
|
|
38323
37609
|
return [];
|
|
@@ -38333,9 +37619,9 @@ var InboxStore = class {
|
|
|
38333
37619
|
if (existing.some((m2) => m2.id === message.id)) return;
|
|
38334
37620
|
const file = this.filePath(message.peerDeviceId);
|
|
38335
37621
|
const line = JSON.stringify(message) + "\n";
|
|
38336
|
-
|
|
37622
|
+
fs19.appendFileSync(file, line, { mode: 384 });
|
|
38337
37623
|
try {
|
|
38338
|
-
|
|
37624
|
+
fs19.chmodSync(file, 384);
|
|
38339
37625
|
} catch {
|
|
38340
37626
|
}
|
|
38341
37627
|
}
|
|
@@ -38365,7 +37651,7 @@ var InboxStore = class {
|
|
|
38365
37651
|
removeByPeerDeviceId(peerDeviceId) {
|
|
38366
37652
|
const file = this.filePath(peerDeviceId);
|
|
38367
37653
|
try {
|
|
38368
|
-
|
|
37654
|
+
fs19.unlinkSync(file);
|
|
38369
37655
|
} catch (err) {
|
|
38370
37656
|
if (err?.code === "ENOENT") return;
|
|
38371
37657
|
}
|
|
@@ -38374,10 +37660,10 @@ var InboxStore = class {
|
|
|
38374
37660
|
const file = this.filePath(peerDeviceId);
|
|
38375
37661
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
38376
37662
|
const content = messages.map((m2) => JSON.stringify(m2)).join("\n") + (messages.length > 0 ? "\n" : "");
|
|
38377
|
-
|
|
38378
|
-
|
|
37663
|
+
fs19.writeFileSync(tmp, content, { mode: 384 });
|
|
37664
|
+
fs19.renameSync(tmp, file);
|
|
38379
37665
|
try {
|
|
38380
|
-
|
|
37666
|
+
fs19.chmodSync(file, 384);
|
|
38381
37667
|
} catch {
|
|
38382
37668
|
}
|
|
38383
37669
|
}
|
|
@@ -38472,7 +37758,7 @@ var InboxManager = class {
|
|
|
38472
37758
|
};
|
|
38473
37759
|
|
|
38474
37760
|
// src/state/contact-store.ts
|
|
38475
|
-
var
|
|
37761
|
+
var fs20 = __toESM(require("fs"), 1);
|
|
38476
37762
|
var path21 = __toESM(require("path"), 1);
|
|
38477
37763
|
var FILE_NAME = "contacts.json";
|
|
38478
37764
|
var ContactStore = class {
|
|
@@ -38486,7 +37772,7 @@ var ContactStore = class {
|
|
|
38486
37772
|
const file = path21.join(this.dataDir, FILE_NAME);
|
|
38487
37773
|
let raw;
|
|
38488
37774
|
try {
|
|
38489
|
-
raw =
|
|
37775
|
+
raw = fs20.readFileSync(file, "utf8");
|
|
38490
37776
|
} catch (err) {
|
|
38491
37777
|
if (err?.code !== "ENOENT") this.renameBak(file);
|
|
38492
37778
|
return;
|
|
@@ -38536,13 +37822,13 @@ var ContactStore = class {
|
|
|
38536
37822
|
null,
|
|
38537
37823
|
2
|
|
38538
37824
|
);
|
|
38539
|
-
|
|
38540
|
-
|
|
38541
|
-
|
|
37825
|
+
fs20.mkdirSync(this.dataDir, { recursive: true });
|
|
37826
|
+
fs20.writeFileSync(tmp, content, { mode: 384 });
|
|
37827
|
+
fs20.renameSync(tmp, file);
|
|
38542
37828
|
}
|
|
38543
37829
|
renameBak(file) {
|
|
38544
37830
|
try {
|
|
38545
|
-
|
|
37831
|
+
fs20.renameSync(file, `${file}.bak`);
|
|
38546
37832
|
} catch {
|
|
38547
37833
|
}
|
|
38548
37834
|
}
|
|
@@ -38677,7 +37963,7 @@ async function autoReverseContact(args) {
|
|
|
38677
37963
|
}
|
|
38678
37964
|
|
|
38679
37965
|
// src/migrations/2026-05-20-flatten-sessions.ts
|
|
38680
|
-
var
|
|
37966
|
+
var fs21 = __toESM(require("fs"), 1);
|
|
38681
37967
|
var path22 = __toESM(require("path"), 1);
|
|
38682
37968
|
var MIGRATION_FLAG_NAME = ".migration.v1.done";
|
|
38683
37969
|
function migrateFlattenSessions(opts) {
|
|
@@ -38697,7 +37983,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38697
37983
|
if (!entry.endsWith(".json")) continue;
|
|
38698
37984
|
const src = path22.join(defaultDir, entry);
|
|
38699
37985
|
const dst = path22.join(sessionsDir, entry);
|
|
38700
|
-
|
|
37986
|
+
fs21.renameSync(src, dst);
|
|
38701
37987
|
movedBare += 1;
|
|
38702
37988
|
}
|
|
38703
37989
|
rmdirIfEmpty(defaultDir);
|
|
@@ -38709,10 +37995,10 @@ function migrateFlattenSessions(opts) {
|
|
|
38709
37995
|
const ownerSrc = path22.join(personaDir, "owner");
|
|
38710
37996
|
if (existsSync3(ownerSrc) && isDir(ownerSrc)) {
|
|
38711
37997
|
const ownerDst = path22.join(dataDir, "personas", pid, ".clawd", "sessions", "owner");
|
|
38712
|
-
|
|
37998
|
+
fs21.mkdirSync(ownerDst, { recursive: true });
|
|
38713
37999
|
for (const file of readdirSafe(ownerSrc)) {
|
|
38714
38000
|
if (!file.endsWith(".json")) continue;
|
|
38715
|
-
|
|
38001
|
+
fs21.renameSync(path22.join(ownerSrc, file), path22.join(ownerDst, file));
|
|
38716
38002
|
movedVmOwner += 1;
|
|
38717
38003
|
}
|
|
38718
38004
|
rmdirIfEmpty(ownerSrc);
|
|
@@ -38720,18 +38006,18 @@ function migrateFlattenSessions(opts) {
|
|
|
38720
38006
|
const listenerSrc = path22.join(personaDir, "listener");
|
|
38721
38007
|
if (existsSync3(listenerSrc) && isDir(listenerSrc)) {
|
|
38722
38008
|
const archiveDst = path22.join(dataDir, ".legacy", `listener-${pid}`);
|
|
38723
|
-
|
|
38009
|
+
fs21.mkdirSync(archiveDst, { recursive: true });
|
|
38724
38010
|
for (const file of readdirSafe(listenerSrc)) {
|
|
38725
38011
|
if (!file.endsWith(".json")) continue;
|
|
38726
|
-
|
|
38012
|
+
fs21.renameSync(path22.join(listenerSrc, file), path22.join(archiveDst, file));
|
|
38727
38013
|
archivedListener += 1;
|
|
38728
38014
|
}
|
|
38729
38015
|
rmdirIfEmpty(listenerSrc);
|
|
38730
38016
|
}
|
|
38731
38017
|
rmdirIfEmpty(personaDir);
|
|
38732
38018
|
}
|
|
38733
|
-
|
|
38734
|
-
|
|
38019
|
+
fs21.mkdirSync(sessionsDir, { recursive: true });
|
|
38020
|
+
fs21.writeFileSync(flagPath, JSON.stringify({ migratedAt: now() }, null, 2));
|
|
38735
38021
|
return {
|
|
38736
38022
|
skipped: false,
|
|
38737
38023
|
flagWritten: true,
|
|
@@ -38742,7 +38028,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38742
38028
|
}
|
|
38743
38029
|
function existsSync3(p2) {
|
|
38744
38030
|
try {
|
|
38745
|
-
|
|
38031
|
+
fs21.statSync(p2);
|
|
38746
38032
|
return true;
|
|
38747
38033
|
} catch {
|
|
38748
38034
|
return false;
|
|
@@ -38750,27 +38036,27 @@ function existsSync3(p2) {
|
|
|
38750
38036
|
}
|
|
38751
38037
|
function isDir(p2) {
|
|
38752
38038
|
try {
|
|
38753
|
-
return
|
|
38039
|
+
return fs21.statSync(p2).isDirectory();
|
|
38754
38040
|
} catch {
|
|
38755
38041
|
return false;
|
|
38756
38042
|
}
|
|
38757
38043
|
}
|
|
38758
38044
|
function readdirSafe(p2) {
|
|
38759
38045
|
try {
|
|
38760
|
-
return
|
|
38046
|
+
return fs21.readdirSync(p2);
|
|
38761
38047
|
} catch {
|
|
38762
38048
|
return [];
|
|
38763
38049
|
}
|
|
38764
38050
|
}
|
|
38765
38051
|
function rmdirIfEmpty(p2) {
|
|
38766
38052
|
try {
|
|
38767
|
-
|
|
38053
|
+
fs21.rmdirSync(p2);
|
|
38768
38054
|
} catch {
|
|
38769
38055
|
}
|
|
38770
38056
|
}
|
|
38771
38057
|
|
|
38772
38058
|
// src/transport/http-router.ts
|
|
38773
|
-
var
|
|
38059
|
+
var import_node_fs16 = __toESM(require("fs"), 1);
|
|
38774
38060
|
var import_node_path18 = __toESM(require("path"), 1);
|
|
38775
38061
|
|
|
38776
38062
|
// src/attachment/mime.ts
|
|
@@ -38950,7 +38236,7 @@ function verifySignedUrl(secret, absPath, eRaw, s, now = Date.now) {
|
|
|
38950
38236
|
}
|
|
38951
38237
|
|
|
38952
38238
|
// src/attachment/upload.ts
|
|
38953
|
-
var
|
|
38239
|
+
var import_node_fs15 = __toESM(require("fs"), 1);
|
|
38954
38240
|
var import_node_path16 = __toESM(require("path"), 1);
|
|
38955
38241
|
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
38956
38242
|
var import_promises = require("stream/promises");
|
|
@@ -38972,7 +38258,7 @@ async function writeUploadedAttachment(args) {
|
|
|
38972
38258
|
assertValidFileName(args.fileName);
|
|
38973
38259
|
const attachmentsRoot = import_node_path16.default.join(args.sessionDir, ".attachments");
|
|
38974
38260
|
try {
|
|
38975
|
-
|
|
38261
|
+
import_node_fs15.default.mkdirSync(attachmentsRoot, { recursive: true });
|
|
38976
38262
|
} catch (err) {
|
|
38977
38263
|
throw new UploadError("STORAGE_ERROR", `mkdir failed: ${err.message}`);
|
|
38978
38264
|
}
|
|
@@ -38993,18 +38279,18 @@ async function writeUploadedAttachment(args) {
|
|
|
38993
38279
|
yield buf;
|
|
38994
38280
|
}
|
|
38995
38281
|
},
|
|
38996
|
-
|
|
38282
|
+
import_node_fs15.default.createWriteStream(tmpPath, { mode: 384 })
|
|
38997
38283
|
);
|
|
38998
38284
|
} catch (err) {
|
|
38999
38285
|
try {
|
|
39000
|
-
|
|
38286
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39001
38287
|
} catch {
|
|
39002
38288
|
}
|
|
39003
38289
|
throw new UploadError("STORAGE_ERROR", `write failed: ${err.message}`);
|
|
39004
38290
|
}
|
|
39005
38291
|
if (actualSize !== args.contentLength) {
|
|
39006
38292
|
try {
|
|
39007
|
-
|
|
38293
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39008
38294
|
} catch {
|
|
39009
38295
|
}
|
|
39010
38296
|
throw new UploadError(
|
|
@@ -39017,24 +38303,24 @@ async function writeUploadedAttachment(args) {
|
|
|
39017
38303
|
let finalFileName;
|
|
39018
38304
|
let hashDirExists = false;
|
|
39019
38305
|
try {
|
|
39020
|
-
hashDirExists =
|
|
38306
|
+
hashDirExists = import_node_fs15.default.statSync(hashDir).isDirectory();
|
|
39021
38307
|
} catch {
|
|
39022
38308
|
}
|
|
39023
38309
|
if (hashDirExists) {
|
|
39024
|
-
const existing =
|
|
38310
|
+
const existing = import_node_fs15.default.readdirSync(hashDir).filter((n) => !n.startsWith("."));
|
|
39025
38311
|
finalFileName = existing[0] ?? args.fileName;
|
|
39026
38312
|
try {
|
|
39027
|
-
|
|
38313
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39028
38314
|
} catch {
|
|
39029
38315
|
}
|
|
39030
38316
|
} else {
|
|
39031
38317
|
try {
|
|
39032
|
-
|
|
38318
|
+
import_node_fs15.default.mkdirSync(hashDir, { recursive: true });
|
|
39033
38319
|
finalFileName = args.fileName;
|
|
39034
|
-
|
|
38320
|
+
import_node_fs15.default.renameSync(tmpPath, import_node_path16.default.join(hashDir, finalFileName));
|
|
39035
38321
|
} catch (err) {
|
|
39036
38322
|
try {
|
|
39037
|
-
|
|
38323
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39038
38324
|
} catch {
|
|
39039
38325
|
}
|
|
39040
38326
|
throw new UploadError("STORAGE_ERROR", `rename failed: ${err.message}`);
|
|
@@ -39558,7 +38844,7 @@ function withCtx(ctx, body) {
|
|
|
39558
38844
|
function streamFile(res, absPath, logger) {
|
|
39559
38845
|
let stat;
|
|
39560
38846
|
try {
|
|
39561
|
-
stat =
|
|
38847
|
+
stat = import_node_fs16.default.statSync(absPath);
|
|
39562
38848
|
} catch (err) {
|
|
39563
38849
|
const code = err?.code;
|
|
39564
38850
|
if (code === "ENOENT") {
|
|
@@ -39581,7 +38867,7 @@ function streamFile(res, absPath, logger) {
|
|
|
39581
38867
|
// 防止浏览器把任意 mime 当 html 渲染
|
|
39582
38868
|
"X-Content-Type-Options": "nosniff"
|
|
39583
38869
|
});
|
|
39584
|
-
const stream =
|
|
38870
|
+
const stream = import_node_fs16.default.createReadStream(absPath);
|
|
39585
38871
|
stream.on("error", (err) => {
|
|
39586
38872
|
logger?.warn("streamFile read error", { absPath, err: err.message });
|
|
39587
38873
|
res.destroy();
|
|
@@ -39590,7 +38876,7 @@ function streamFile(res, absPath, logger) {
|
|
|
39590
38876
|
}
|
|
39591
38877
|
|
|
39592
38878
|
// src/attachment/gc.ts
|
|
39593
|
-
var
|
|
38879
|
+
var import_node_fs17 = __toESM(require("fs"), 1);
|
|
39594
38880
|
var import_node_path19 = __toESM(require("path"), 1);
|
|
39595
38881
|
var DEFAULT_TTL_MS = 30 * 24 * 3600 * 1e3;
|
|
39596
38882
|
function runAttachmentGc(args) {
|
|
@@ -39613,7 +38899,7 @@ function runAttachmentGc(args) {
|
|
|
39613
38899
|
const attRoot = import_node_path19.default.join(sessionDir, ".attachments");
|
|
39614
38900
|
let hashDirs;
|
|
39615
38901
|
try {
|
|
39616
|
-
hashDirs =
|
|
38902
|
+
hashDirs = import_node_fs17.default.readdirSync(attRoot);
|
|
39617
38903
|
} catch (err) {
|
|
39618
38904
|
if (err.code === "ENOENT") continue;
|
|
39619
38905
|
args.logger?.warn("attachment gc: readdir failed", { attRoot, err: err.message });
|
|
@@ -39623,7 +38909,7 @@ function runAttachmentGc(args) {
|
|
|
39623
38909
|
const hashDirAbs = import_node_path19.default.join(attRoot, hashDir);
|
|
39624
38910
|
let files;
|
|
39625
38911
|
try {
|
|
39626
|
-
files =
|
|
38912
|
+
files = import_node_fs17.default.readdirSync(hashDirAbs);
|
|
39627
38913
|
} catch {
|
|
39628
38914
|
continue;
|
|
39629
38915
|
}
|
|
@@ -39631,7 +38917,7 @@ function runAttachmentGc(args) {
|
|
|
39631
38917
|
const file = import_node_path19.default.join(hashDirAbs, name);
|
|
39632
38918
|
let stat;
|
|
39633
38919
|
try {
|
|
39634
|
-
stat =
|
|
38920
|
+
stat = import_node_fs17.default.statSync(file);
|
|
39635
38921
|
} catch {
|
|
39636
38922
|
continue;
|
|
39637
38923
|
}
|
|
@@ -39640,25 +38926,25 @@ function runAttachmentGc(args) {
|
|
|
39640
38926
|
if (age < ttlMs) continue;
|
|
39641
38927
|
if (liveAbs.has(file)) continue;
|
|
39642
38928
|
try {
|
|
39643
|
-
|
|
38929
|
+
import_node_fs17.default.unlinkSync(file);
|
|
39644
38930
|
} catch (err) {
|
|
39645
38931
|
args.logger?.warn("attachment gc: unlink failed", { file, err: err.message });
|
|
39646
38932
|
}
|
|
39647
38933
|
}
|
|
39648
38934
|
try {
|
|
39649
|
-
if (
|
|
38935
|
+
if (import_node_fs17.default.readdirSync(hashDirAbs).length === 0) import_node_fs17.default.rmdirSync(hashDirAbs);
|
|
39650
38936
|
} catch {
|
|
39651
38937
|
}
|
|
39652
38938
|
}
|
|
39653
38939
|
try {
|
|
39654
|
-
if (
|
|
38940
|
+
if (import_node_fs17.default.readdirSync(attRoot).length === 0) import_node_fs17.default.rmdirSync(attRoot);
|
|
39655
38941
|
} catch {
|
|
39656
38942
|
}
|
|
39657
38943
|
}
|
|
39658
38944
|
}
|
|
39659
38945
|
|
|
39660
38946
|
// src/attachment/group.ts
|
|
39661
|
-
var
|
|
38947
|
+
var import_node_fs18 = __toESM(require("fs"), 1);
|
|
39662
38948
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
39663
38949
|
var import_node_crypto6 = __toESM(require("crypto"), 1);
|
|
39664
38950
|
init_protocol();
|
|
@@ -39684,7 +38970,7 @@ var GroupFileStore = class {
|
|
|
39684
38970
|
readFile(scope, sessionId) {
|
|
39685
38971
|
const file = this.filePath(scope, sessionId);
|
|
39686
38972
|
try {
|
|
39687
|
-
const raw =
|
|
38973
|
+
const raw = import_node_fs18.default.readFileSync(file, "utf8");
|
|
39688
38974
|
const parsed = JSON.parse(raw);
|
|
39689
38975
|
if (!Array.isArray(parsed)) {
|
|
39690
38976
|
this.logger?.warn("GroupFileStore.readFile: not an array; resetting session entries", {
|
|
@@ -39710,10 +38996,10 @@ var GroupFileStore = class {
|
|
|
39710
38996
|
}
|
|
39711
38997
|
writeFile(scope, sessionId, entries) {
|
|
39712
38998
|
const file = this.filePath(scope, sessionId);
|
|
39713
|
-
|
|
38999
|
+
import_node_fs18.default.mkdirSync(import_node_path20.default.dirname(file), { recursive: true });
|
|
39714
39000
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
39715
|
-
|
|
39716
|
-
|
|
39001
|
+
import_node_fs18.default.writeFileSync(tmp, JSON.stringify(entries, null, 2), { mode: 384 });
|
|
39002
|
+
import_node_fs18.default.renameSync(tmp, file);
|
|
39717
39003
|
}
|
|
39718
39004
|
/** 拉一份当前 session 的清单。读盘 → cache;之后调用复用 cache */
|
|
39719
39005
|
list(scope, sessionId) {
|
|
@@ -39799,7 +39085,7 @@ var GroupFileStore = class {
|
|
|
39799
39085
|
};
|
|
39800
39086
|
|
|
39801
39087
|
// src/discovery/state-file.ts
|
|
39802
|
-
var
|
|
39088
|
+
var import_node_fs19 = __toESM(require("fs"), 1);
|
|
39803
39089
|
var import_node_path21 = __toESM(require("path"), 1);
|
|
39804
39090
|
function defaultStateFilePath(dataDir) {
|
|
39805
39091
|
return import_node_path21.default.join(dataDir, "state.json");
|
|
@@ -39824,7 +39110,7 @@ var StateFileManager = class {
|
|
|
39824
39110
|
}
|
|
39825
39111
|
read() {
|
|
39826
39112
|
try {
|
|
39827
|
-
const raw =
|
|
39113
|
+
const raw = import_node_fs19.default.readFileSync(this.file, "utf8");
|
|
39828
39114
|
const parsed = JSON.parse(raw);
|
|
39829
39115
|
return parsed;
|
|
39830
39116
|
} catch {
|
|
@@ -39838,33 +39124,41 @@ var StateFileManager = class {
|
|
|
39838
39124
|
return { status: "stale", existing };
|
|
39839
39125
|
}
|
|
39840
39126
|
write(state) {
|
|
39841
|
-
|
|
39127
|
+
import_node_fs19.default.mkdirSync(import_node_path21.default.dirname(this.file), { recursive: true });
|
|
39842
39128
|
const tmp = `${this.file}.tmp.${process.pid}.${Date.now()}`;
|
|
39843
|
-
|
|
39844
|
-
|
|
39129
|
+
import_node_fs19.default.writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 384 });
|
|
39130
|
+
import_node_fs19.default.renameSync(tmp, this.file);
|
|
39845
39131
|
if (process.platform !== "win32") {
|
|
39846
39132
|
try {
|
|
39847
|
-
|
|
39133
|
+
import_node_fs19.default.chmodSync(this.file, 384);
|
|
39848
39134
|
} catch {
|
|
39849
39135
|
}
|
|
39850
39136
|
}
|
|
39851
39137
|
}
|
|
39852
39138
|
delete() {
|
|
39853
39139
|
try {
|
|
39854
|
-
|
|
39140
|
+
import_node_fs19.default.unlinkSync(this.file);
|
|
39855
39141
|
} catch {
|
|
39856
39142
|
}
|
|
39857
39143
|
}
|
|
39858
39144
|
};
|
|
39859
39145
|
|
|
39146
|
+
// src/discovery/source-from-env.ts
|
|
39147
|
+
function readDaemonSourceFromEnv(env = process.env) {
|
|
39148
|
+
const v2 = env.CLAWD_DAEMON_SOURCE;
|
|
39149
|
+
if (typeof v2 !== "string") return void 0;
|
|
39150
|
+
const trimmed = v2.trim();
|
|
39151
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
39152
|
+
}
|
|
39153
|
+
|
|
39860
39154
|
// src/tunnel/tunnel-manager.ts
|
|
39861
|
-
var
|
|
39155
|
+
var import_node_fs23 = __toESM(require("fs"), 1);
|
|
39862
39156
|
var import_node_path25 = __toESM(require("path"), 1);
|
|
39863
39157
|
var import_node_crypto7 = __toESM(require("crypto"), 1);
|
|
39864
|
-
var
|
|
39158
|
+
var import_node_child_process5 = require("child_process");
|
|
39865
39159
|
|
|
39866
39160
|
// src/tunnel/tunnel-store.ts
|
|
39867
|
-
var
|
|
39161
|
+
var import_node_fs20 = __toESM(require("fs"), 1);
|
|
39868
39162
|
var import_node_path22 = __toESM(require("path"), 1);
|
|
39869
39163
|
var TunnelStore = class {
|
|
39870
39164
|
constructor(filePath) {
|
|
@@ -39873,7 +39167,7 @@ var TunnelStore = class {
|
|
|
39873
39167
|
filePath;
|
|
39874
39168
|
async get() {
|
|
39875
39169
|
try {
|
|
39876
|
-
const raw = await
|
|
39170
|
+
const raw = await import_node_fs20.default.promises.readFile(this.filePath, "utf8");
|
|
39877
39171
|
const obj = JSON.parse(raw);
|
|
39878
39172
|
if (!isPersistedTunnel(obj)) return null;
|
|
39879
39173
|
return obj;
|
|
@@ -39885,21 +39179,21 @@ var TunnelStore = class {
|
|
|
39885
39179
|
}
|
|
39886
39180
|
async set(v2) {
|
|
39887
39181
|
const dir = import_node_path22.default.dirname(this.filePath);
|
|
39888
|
-
await
|
|
39182
|
+
await import_node_fs20.default.promises.mkdir(dir, { recursive: true });
|
|
39889
39183
|
const data = JSON.stringify(v2, null, 2);
|
|
39890
39184
|
const tmp = `${this.filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
39891
|
-
await
|
|
39185
|
+
await import_node_fs20.default.promises.writeFile(tmp, data, { mode: 384 });
|
|
39892
39186
|
if (process.platform !== "win32") {
|
|
39893
39187
|
try {
|
|
39894
|
-
await
|
|
39188
|
+
await import_node_fs20.default.promises.chmod(tmp, 384);
|
|
39895
39189
|
} catch {
|
|
39896
39190
|
}
|
|
39897
39191
|
}
|
|
39898
|
-
await
|
|
39192
|
+
await import_node_fs20.default.promises.rename(tmp, this.filePath);
|
|
39899
39193
|
}
|
|
39900
39194
|
async clear() {
|
|
39901
39195
|
try {
|
|
39902
|
-
await
|
|
39196
|
+
await import_node_fs20.default.promises.unlink(this.filePath);
|
|
39903
39197
|
} catch (err) {
|
|
39904
39198
|
const code = err?.code;
|
|
39905
39199
|
if (code !== "ENOENT") throw err;
|
|
@@ -39994,10 +39288,10 @@ function escape(v2) {
|
|
|
39994
39288
|
}
|
|
39995
39289
|
|
|
39996
39290
|
// src/tunnel/frpc-binary.ts
|
|
39997
|
-
var
|
|
39291
|
+
var import_node_fs21 = __toESM(require("fs"), 1);
|
|
39998
39292
|
var import_node_os11 = __toESM(require("os"), 1);
|
|
39999
39293
|
var import_node_path23 = __toESM(require("path"), 1);
|
|
40000
|
-
var
|
|
39294
|
+
var import_node_child_process3 = require("child_process");
|
|
40001
39295
|
var import_node_stream2 = require("stream");
|
|
40002
39296
|
var import_promises3 = require("stream/promises");
|
|
40003
39297
|
var FRPC_VERSION = "0.68.0";
|
|
@@ -40028,7 +39322,7 @@ function frpcDownloadUrl(version2, p2) {
|
|
|
40028
39322
|
}
|
|
40029
39323
|
async function ensureFrpcBinary(opts) {
|
|
40030
39324
|
if (opts.override) {
|
|
40031
|
-
if (!
|
|
39325
|
+
if (!import_node_fs21.default.existsSync(opts.override)) {
|
|
40032
39326
|
throw new Error(`frpc binary not found at override path: ${opts.override}`);
|
|
40033
39327
|
}
|
|
40034
39328
|
return opts.override;
|
|
@@ -40036,10 +39330,10 @@ async function ensureFrpcBinary(opts) {
|
|
|
40036
39330
|
const version2 = opts.version ?? FRPC_VERSION;
|
|
40037
39331
|
const platform = opts.platform ?? detectPlatform();
|
|
40038
39332
|
const binDir = import_node_path23.default.join(opts.dataDir, "bin");
|
|
40039
|
-
|
|
39333
|
+
import_node_fs21.default.mkdirSync(binDir, { recursive: true });
|
|
40040
39334
|
cleanupStaleArtifacts(binDir);
|
|
40041
39335
|
const stableBin = import_node_path23.default.join(binDir, "frpc");
|
|
40042
|
-
if (
|
|
39336
|
+
if (import_node_fs21.default.existsSync(stableBin)) return stableBin;
|
|
40043
39337
|
const partialBin = `${stableBin}.partial`;
|
|
40044
39338
|
const tarballPath = import_node_path23.default.join(binDir, `frp_${version2}_${platform.os}_${platform.arch}.tar.gz.partial`);
|
|
40045
39339
|
try {
|
|
@@ -40050,8 +39344,8 @@ async function ensureFrpcBinary(opts) {
|
|
|
40050
39344
|
} else {
|
|
40051
39345
|
await extractFrpcFromTarball(tarballPath, binDir, version2, platform, partialBin);
|
|
40052
39346
|
}
|
|
40053
|
-
|
|
40054
|
-
|
|
39347
|
+
import_node_fs21.default.chmodSync(partialBin, 493);
|
|
39348
|
+
import_node_fs21.default.renameSync(partialBin, stableBin);
|
|
40055
39349
|
} finally {
|
|
40056
39350
|
safeUnlink(tarballPath);
|
|
40057
39351
|
safeUnlink(partialBin);
|
|
@@ -40061,7 +39355,7 @@ async function ensureFrpcBinary(opts) {
|
|
|
40061
39355
|
function cleanupStaleArtifacts(binDir) {
|
|
40062
39356
|
let entries;
|
|
40063
39357
|
try {
|
|
40064
|
-
entries =
|
|
39358
|
+
entries = import_node_fs21.default.readdirSync(binDir);
|
|
40065
39359
|
} catch {
|
|
40066
39360
|
return;
|
|
40067
39361
|
}
|
|
@@ -40069,7 +39363,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
40069
39363
|
if (name.endsWith(".partial") || name.startsWith("extract-")) {
|
|
40070
39364
|
const full = import_node_path23.default.join(binDir, name);
|
|
40071
39365
|
try {
|
|
40072
|
-
|
|
39366
|
+
import_node_fs21.default.rmSync(full, { recursive: true, force: true });
|
|
40073
39367
|
} catch {
|
|
40074
39368
|
}
|
|
40075
39369
|
}
|
|
@@ -40077,7 +39371,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
40077
39371
|
}
|
|
40078
39372
|
function safeUnlink(p2) {
|
|
40079
39373
|
try {
|
|
40080
|
-
|
|
39374
|
+
import_node_fs21.default.unlinkSync(p2);
|
|
40081
39375
|
} catch {
|
|
40082
39376
|
}
|
|
40083
39377
|
}
|
|
@@ -40088,46 +39382,46 @@ async function downloadToFile(url, dest, fetchImpl) {
|
|
|
40088
39382
|
if (!res.ok || !res.body) {
|
|
40089
39383
|
throw new Error(`download failed: ${res.status} ${res.statusText}`);
|
|
40090
39384
|
}
|
|
40091
|
-
const out =
|
|
39385
|
+
const out = import_node_fs21.default.createWriteStream(dest);
|
|
40092
39386
|
const nodeStream = import_node_stream2.Readable.fromWeb(res.body);
|
|
40093
39387
|
await (0, import_promises3.pipeline)(nodeStream, out);
|
|
40094
39388
|
}
|
|
40095
39389
|
async function extractFrpcFromTarball(tarball, binDir, version2, platform, destBin) {
|
|
40096
39390
|
const work = import_node_path23.default.join(binDir, `extract-${process.pid}-${Date.now()}`);
|
|
40097
|
-
|
|
39391
|
+
import_node_fs21.default.mkdirSync(work, { recursive: true });
|
|
40098
39392
|
try {
|
|
40099
39393
|
await new Promise((resolve6, reject) => {
|
|
40100
|
-
const proc = (0,
|
|
39394
|
+
const proc = (0, import_node_child_process3.spawn)("tar", ["xzf", tarball, "-C", work], { stdio: "pipe" });
|
|
40101
39395
|
proc.on("error", reject);
|
|
40102
39396
|
proc.on("exit", (code) => code === 0 ? resolve6() : reject(new Error(`tar exited ${code}`)));
|
|
40103
39397
|
});
|
|
40104
39398
|
const dirName = `frp_${version2}_${platform.os}_${platform.arch}`;
|
|
40105
39399
|
const src = import_node_path23.default.join(work, dirName, "frpc");
|
|
40106
|
-
if (!
|
|
39400
|
+
if (!import_node_fs21.default.existsSync(src)) {
|
|
40107
39401
|
throw new Error(`frpc not found inside tarball at ${src}`);
|
|
40108
39402
|
}
|
|
40109
|
-
|
|
39403
|
+
import_node_fs21.default.copyFileSync(src, destBin);
|
|
40110
39404
|
} finally {
|
|
40111
|
-
|
|
39405
|
+
import_node_fs21.default.rmSync(work, { recursive: true, force: true });
|
|
40112
39406
|
}
|
|
40113
39407
|
}
|
|
40114
39408
|
|
|
40115
39409
|
// src/tunnel/frpc-process.ts
|
|
40116
|
-
var
|
|
39410
|
+
var import_node_fs22 = __toESM(require("fs"), 1);
|
|
40117
39411
|
var import_node_path24 = __toESM(require("path"), 1);
|
|
40118
|
-
var
|
|
39412
|
+
var import_node_child_process4 = require("child_process");
|
|
40119
39413
|
function frpcPidFilePath(dataDir) {
|
|
40120
39414
|
return import_node_path24.default.join(dataDir, "frpc.pid");
|
|
40121
39415
|
}
|
|
40122
39416
|
function writeFrpcPid(dataDir, pid) {
|
|
40123
39417
|
try {
|
|
40124
|
-
|
|
39418
|
+
import_node_fs22.default.writeFileSync(frpcPidFilePath(dataDir), String(pid), { mode: 384 });
|
|
40125
39419
|
} catch {
|
|
40126
39420
|
}
|
|
40127
39421
|
}
|
|
40128
39422
|
function clearFrpcPid(dataDir) {
|
|
40129
39423
|
try {
|
|
40130
|
-
|
|
39424
|
+
import_node_fs22.default.unlinkSync(frpcPidFilePath(dataDir));
|
|
40131
39425
|
} catch {
|
|
40132
39426
|
}
|
|
40133
39427
|
}
|
|
@@ -40143,7 +39437,7 @@ function defaultIsPidAlive(pid) {
|
|
|
40143
39437
|
}
|
|
40144
39438
|
function defaultReadPidFile(file) {
|
|
40145
39439
|
try {
|
|
40146
|
-
return
|
|
39440
|
+
return import_node_fs22.default.readFileSync(file, "utf8");
|
|
40147
39441
|
} catch {
|
|
40148
39442
|
return null;
|
|
40149
39443
|
}
|
|
@@ -40183,7 +39477,7 @@ async function killStaleFrpc(deps) {
|
|
|
40183
39477
|
}
|
|
40184
39478
|
if (victims.size === 0) {
|
|
40185
39479
|
try {
|
|
40186
|
-
|
|
39480
|
+
import_node_fs22.default.unlinkSync(pidFile);
|
|
40187
39481
|
} catch {
|
|
40188
39482
|
}
|
|
40189
39483
|
return;
|
|
@@ -40194,14 +39488,14 @@ async function killStaleFrpc(deps) {
|
|
|
40194
39488
|
}
|
|
40195
39489
|
await sleep(deps.reapWaitMs ?? 300);
|
|
40196
39490
|
try {
|
|
40197
|
-
|
|
39491
|
+
import_node_fs22.default.unlinkSync(pidFile);
|
|
40198
39492
|
} catch {
|
|
40199
39493
|
}
|
|
40200
39494
|
}
|
|
40201
39495
|
async function defaultScanFrpcPidsByCmdline(tomlPath, logger) {
|
|
40202
39496
|
if (process.platform === "win32") return [];
|
|
40203
39497
|
return new Promise((resolve6) => {
|
|
40204
|
-
const ps = (0,
|
|
39498
|
+
const ps = (0, import_node_child_process4.spawn)("ps", ["-axo", "pid=,command="], { stdio: ["ignore", "pipe", "ignore"] });
|
|
40205
39499
|
let buf = "";
|
|
40206
39500
|
ps.stdout.on("data", (c) => {
|
|
40207
39501
|
buf += c.toString();
|
|
@@ -40369,12 +39663,12 @@ var TunnelManager = class {
|
|
|
40369
39663
|
localPort,
|
|
40370
39664
|
logLevel: "info"
|
|
40371
39665
|
});
|
|
40372
|
-
await
|
|
40373
|
-
const proc = (this.deps.spawnImpl ??
|
|
39666
|
+
await import_node_fs23.default.promises.writeFile(tomlPath, toml, { mode: 384 });
|
|
39667
|
+
const proc = (this.deps.spawnImpl ?? import_node_child_process5.spawn)(frpcBin, ["-c", tomlPath], {
|
|
40374
39668
|
stdio: ["ignore", "pipe", "pipe"]
|
|
40375
39669
|
});
|
|
40376
39670
|
const logFilePath = import_node_path25.default.join(this.deps.dataDir, "frpc.log");
|
|
40377
|
-
const logStream =
|
|
39671
|
+
const logStream = import_node_fs23.default.createWriteStream(logFilePath, { flags: "a", mode: 384 });
|
|
40378
39672
|
logStream.on("error", () => {
|
|
40379
39673
|
});
|
|
40380
39674
|
const tee = (chunk) => {
|
|
@@ -40472,7 +39766,7 @@ function deriveStableDeviceKey(opts = {}) {
|
|
|
40472
39766
|
}
|
|
40473
39767
|
|
|
40474
39768
|
// src/auth-store.ts
|
|
40475
|
-
var
|
|
39769
|
+
var import_node_fs24 = __toESM(require("fs"), 1);
|
|
40476
39770
|
var import_node_path27 = __toESM(require("path"), 1);
|
|
40477
39771
|
var import_node_crypto9 = __toESM(require("crypto"), 1);
|
|
40478
39772
|
var AUTH_FILE_NAME = "auth.json";
|
|
@@ -40511,7 +39805,7 @@ function defaultGenerateOwnerPrincipalId() {
|
|
|
40511
39805
|
}
|
|
40512
39806
|
function readAuthFile(file) {
|
|
40513
39807
|
try {
|
|
40514
|
-
const raw =
|
|
39808
|
+
const raw = import_node_fs24.default.readFileSync(file, "utf8");
|
|
40515
39809
|
const parsed = JSON.parse(raw);
|
|
40516
39810
|
if (typeof parsed?.token !== "string" || parsed.token.length === 0) {
|
|
40517
39811
|
return null;
|
|
@@ -40530,16 +39824,16 @@ function readAuthFile(file) {
|
|
|
40530
39824
|
}
|
|
40531
39825
|
}
|
|
40532
39826
|
function writeAuthFile(file, content) {
|
|
40533
|
-
|
|
40534
|
-
|
|
39827
|
+
import_node_fs24.default.mkdirSync(import_node_path27.default.dirname(file), { recursive: true });
|
|
39828
|
+
import_node_fs24.default.writeFileSync(file, JSON.stringify(content, null, 2), { mode: 384 });
|
|
40535
39829
|
try {
|
|
40536
|
-
|
|
39830
|
+
import_node_fs24.default.chmodSync(file, 384);
|
|
40537
39831
|
} catch {
|
|
40538
39832
|
}
|
|
40539
39833
|
}
|
|
40540
39834
|
|
|
40541
39835
|
// src/owner-profile.ts
|
|
40542
|
-
var
|
|
39836
|
+
var import_node_fs25 = __toESM(require("fs"), 1);
|
|
40543
39837
|
var import_node_os13 = __toESM(require("os"), 1);
|
|
40544
39838
|
var import_node_path28 = __toESM(require("path"), 1);
|
|
40545
39839
|
var PROFILE_FILENAME = "profile.json";
|
|
@@ -40548,7 +39842,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
40548
39842
|
const profilePath = import_node_path28.default.join(dataDir, PROFILE_FILENAME);
|
|
40549
39843
|
let raw;
|
|
40550
39844
|
try {
|
|
40551
|
-
raw =
|
|
39845
|
+
raw = import_node_fs25.default.readFileSync(profilePath, "utf8");
|
|
40552
39846
|
} catch {
|
|
40553
39847
|
return fallback;
|
|
40554
39848
|
}
|
|
@@ -40571,7 +39865,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
40571
39865
|
}
|
|
40572
39866
|
|
|
40573
39867
|
// src/feishu-auth/owner-identity-store.ts
|
|
40574
|
-
var
|
|
39868
|
+
var import_node_fs26 = __toESM(require("fs"), 1);
|
|
40575
39869
|
var import_node_path29 = __toESM(require("path"), 1);
|
|
40576
39870
|
var OWNER_IDENTITY_FILE_NAME = "owner-identity.json";
|
|
40577
39871
|
var OwnerIdentityStore = class {
|
|
@@ -40582,7 +39876,7 @@ var OwnerIdentityStore = class {
|
|
|
40582
39876
|
read() {
|
|
40583
39877
|
let raw;
|
|
40584
39878
|
try {
|
|
40585
|
-
raw =
|
|
39879
|
+
raw = import_node_fs26.default.readFileSync(this.file, "utf8");
|
|
40586
39880
|
} catch {
|
|
40587
39881
|
return null;
|
|
40588
39882
|
}
|
|
@@ -40609,16 +39903,16 @@ var OwnerIdentityStore = class {
|
|
|
40609
39903
|
};
|
|
40610
39904
|
}
|
|
40611
39905
|
write(record) {
|
|
40612
|
-
|
|
40613
|
-
|
|
39906
|
+
import_node_fs26.default.mkdirSync(import_node_path29.default.dirname(this.file), { recursive: true });
|
|
39907
|
+
import_node_fs26.default.writeFileSync(this.file, JSON.stringify(record, null, 2), { mode: 384 });
|
|
40614
39908
|
try {
|
|
40615
|
-
|
|
39909
|
+
import_node_fs26.default.chmodSync(this.file, 384);
|
|
40616
39910
|
} catch {
|
|
40617
39911
|
}
|
|
40618
39912
|
}
|
|
40619
39913
|
clear() {
|
|
40620
39914
|
try {
|
|
40621
|
-
|
|
39915
|
+
import_node_fs26.default.unlinkSync(this.file);
|
|
40622
39916
|
} catch (err) {
|
|
40623
39917
|
const code = err?.code;
|
|
40624
39918
|
if (code !== "ENOENT") throw err;
|
|
@@ -40881,7 +40175,7 @@ function verifyConnectToken(args) {
|
|
|
40881
40175
|
}
|
|
40882
40176
|
|
|
40883
40177
|
// src/feishu-auth/server-key.ts
|
|
40884
|
-
var
|
|
40178
|
+
var fs35 = __toESM(require("fs"), 1);
|
|
40885
40179
|
var path38 = __toESM(require("path"), 1);
|
|
40886
40180
|
var FILE_NAME2 = "server-signing-key.json";
|
|
40887
40181
|
var ServerKeyStore = class {
|
|
@@ -40895,7 +40189,7 @@ var ServerKeyStore = class {
|
|
|
40895
40189
|
/** 读缓存的公钥;无缓存 / 损坏 → null(调用方决定是否触发拉取) */
|
|
40896
40190
|
read() {
|
|
40897
40191
|
try {
|
|
40898
|
-
const raw =
|
|
40192
|
+
const raw = fs35.readFileSync(this.filePath(), "utf8");
|
|
40899
40193
|
const parsed = JSON.parse(raw);
|
|
40900
40194
|
if (typeof parsed.publicKeyPem === "string" && parsed.publicKeyPem.includes("PUBLIC KEY")) {
|
|
40901
40195
|
return parsed.publicKeyPem;
|
|
@@ -40910,12 +40204,12 @@ var ServerKeyStore = class {
|
|
|
40910
40204
|
publicKeyPem,
|
|
40911
40205
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
40912
40206
|
};
|
|
40913
|
-
|
|
40914
|
-
|
|
40207
|
+
fs35.mkdirSync(this.dataDir, { recursive: true });
|
|
40208
|
+
fs35.writeFileSync(this.filePath(), JSON.stringify(content, null, 2), { mode: 384 });
|
|
40915
40209
|
}
|
|
40916
40210
|
clear() {
|
|
40917
40211
|
try {
|
|
40918
|
-
|
|
40212
|
+
fs35.unlinkSync(this.filePath());
|
|
40919
40213
|
} catch {
|
|
40920
40214
|
}
|
|
40921
40215
|
}
|
|
@@ -40928,12 +40222,12 @@ init_protocol();
|
|
|
40928
40222
|
init_protocol();
|
|
40929
40223
|
|
|
40930
40224
|
// src/session/fork.ts
|
|
40931
|
-
var
|
|
40225
|
+
var import_node_fs27 = __toESM(require("fs"), 1);
|
|
40932
40226
|
var import_node_os14 = __toESM(require("os"), 1);
|
|
40933
40227
|
var import_node_path30 = __toESM(require("path"), 1);
|
|
40934
40228
|
init_claude_history();
|
|
40935
40229
|
function readJsonlEntries(file) {
|
|
40936
|
-
const raw =
|
|
40230
|
+
const raw = import_node_fs27.default.readFileSync(file, "utf8");
|
|
40937
40231
|
const out = [];
|
|
40938
40232
|
for (const line of raw.split("\n")) {
|
|
40939
40233
|
const t = line.trim();
|
|
@@ -40949,7 +40243,7 @@ function forkSession(input) {
|
|
|
40949
40243
|
const baseDir = input.baseDir ?? import_node_path30.default.join(import_node_os14.default.homedir(), ".claude");
|
|
40950
40244
|
const projectDir = import_node_path30.default.join(baseDir, "projects", cwdToHashDir(input.cwd));
|
|
40951
40245
|
const sourceFile = import_node_path30.default.join(projectDir, `${input.toolSessionId}.jsonl`);
|
|
40952
|
-
if (!
|
|
40246
|
+
if (!import_node_fs27.default.existsSync(sourceFile)) {
|
|
40953
40247
|
throw new Error(`fork: source transcript not found: ${sourceFile}`);
|
|
40954
40248
|
}
|
|
40955
40249
|
const entries = readJsonlEntries(sourceFile);
|
|
@@ -40980,8 +40274,8 @@ function forkSession(input) {
|
|
|
40980
40274
|
forkedLines.push(JSON.stringify(forked));
|
|
40981
40275
|
}
|
|
40982
40276
|
const forkedFilePath = import_node_path30.default.join(projectDir, `${forkedToolSessionId}.jsonl`);
|
|
40983
|
-
|
|
40984
|
-
|
|
40277
|
+
import_node_fs27.default.mkdirSync(projectDir, { recursive: true });
|
|
40278
|
+
import_node_fs27.default.writeFileSync(forkedFilePath, forkedLines.join("\n") + "\n", { mode: 384 });
|
|
40985
40279
|
return { forkedToolSessionId, forkedFilePath };
|
|
40986
40280
|
}
|
|
40987
40281
|
|
|
@@ -41171,13 +40465,6 @@ function buildSessionHandlers(deps) {
|
|
|
41171
40465
|
const sessionFile = file;
|
|
41172
40466
|
manager.ensureSession(sessionFile);
|
|
41173
40467
|
const adapter = getAdapter2(sessionFile.tool ?? "claude");
|
|
41174
|
-
const caps = await adapter.capabilities();
|
|
41175
|
-
if (caps.features.observe === false) {
|
|
41176
|
-
throw new ClawdError(
|
|
41177
|
-
ERROR_CODES.TOOL_NOT_SUPPORTED,
|
|
41178
|
-
`tool ${sessionFile.tool ?? "claude"} does not support observe`
|
|
41179
|
-
);
|
|
41180
|
-
}
|
|
41181
40468
|
observer.start({
|
|
41182
40469
|
sessionId: args.sessionId,
|
|
41183
40470
|
cwd: sessionFile.cwd,
|
|
@@ -41427,7 +40714,7 @@ function assertGuestPath(ctx, absPath, personaRoot, method, usersRoot) {
|
|
|
41427
40714
|
}
|
|
41428
40715
|
}
|
|
41429
40716
|
function buildHistoryHandlers(deps) {
|
|
41430
|
-
const { manager, history,
|
|
40717
|
+
const { manager, history, store, personaRoot, usersRoot } = deps;
|
|
41431
40718
|
const projects = async (_frame, _client, ctx) => {
|
|
41432
40719
|
const list2 = await history.listProjects();
|
|
41433
40720
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
@@ -41471,7 +40758,7 @@ function buildHistoryHandlers(deps) {
|
|
|
41471
40758
|
response: { type: "history:read", messages: [], total: 0, offset: 0 }
|
|
41472
40759
|
};
|
|
41473
40760
|
}
|
|
41474
|
-
const res = await
|
|
40761
|
+
const res = await history.read({
|
|
41475
40762
|
cwd: f.cwd,
|
|
41476
40763
|
toolSessionId: f.toolSessionId,
|
|
41477
40764
|
limit: args.limit,
|
|
@@ -41550,7 +40837,7 @@ function assertGuestPath2(ctx, absPath, personaRoot, method, usersRoot) {
|
|
|
41550
40837
|
}
|
|
41551
40838
|
}
|
|
41552
40839
|
function buildWorkspaceHandlers(deps) {
|
|
41553
|
-
const { workspace, skills, agents,
|
|
40840
|
+
const { workspace, skills, agents, personaRoot, personaManager, usersRoot } = deps;
|
|
41554
40841
|
const list = async (frame, _client, ctx) => {
|
|
41555
40842
|
const args = WorkspaceListArgs.parse(frame);
|
|
41556
40843
|
const isGuest = ctx?.principal.kind === "guest";
|
|
@@ -41572,7 +40859,7 @@ function buildWorkspaceHandlers(deps) {
|
|
|
41572
40859
|
const args = SkillsListArgs.parse(frame);
|
|
41573
40860
|
const cwdAbs = path42.resolve(args.cwd);
|
|
41574
40861
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "skills:list", usersRoot);
|
|
41575
|
-
const list2 =
|
|
40862
|
+
const list2 = skills.list(args);
|
|
41576
40863
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
41577
40864
|
const personaId = personaIdFromPath(cwdAbs, personaRoot);
|
|
41578
40865
|
const enabled = personaId ? buildEnabledPluginNames(personaManager, personaId) : /* @__PURE__ */ new Set();
|
|
@@ -41584,9 +40871,6 @@ function buildWorkspaceHandlers(deps) {
|
|
|
41584
40871
|
const args = AgentsListArgs.parse(frame);
|
|
41585
40872
|
const cwdAbs = path42.resolve(args.cwd);
|
|
41586
40873
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "agents:list", usersRoot);
|
|
41587
|
-
if (args.tool === "codex") {
|
|
41588
|
-
return { response: { type: "agents:list", agents: [] } };
|
|
41589
|
-
}
|
|
41590
40874
|
const list2 = agents.list(args);
|
|
41591
40875
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
41592
40876
|
const personaId = personaIdFromPath(cwdAbs, personaRoot);
|
|
@@ -41609,15 +40893,15 @@ init_protocol();
|
|
|
41609
40893
|
init_protocol();
|
|
41610
40894
|
|
|
41611
40895
|
// src/workspace/git.ts
|
|
41612
|
-
var
|
|
41613
|
-
var
|
|
40896
|
+
var import_node_child_process6 = require("child_process");
|
|
40897
|
+
var import_node_fs28 = __toESM(require("fs"), 1);
|
|
41614
40898
|
var import_node_path31 = __toESM(require("path"), 1);
|
|
41615
40899
|
var import_node_util = require("util");
|
|
41616
|
-
var pexec = (0, import_node_util.promisify)(
|
|
40900
|
+
var pexec = (0, import_node_util.promisify)(import_node_child_process6.execFile);
|
|
41617
40901
|
function normalizePath(p2) {
|
|
41618
40902
|
const resolved = import_node_path31.default.resolve(p2);
|
|
41619
40903
|
try {
|
|
41620
|
-
return
|
|
40904
|
+
return import_node_fs28.default.realpathSync(resolved);
|
|
41621
40905
|
} catch {
|
|
41622
40906
|
return resolved;
|
|
41623
40907
|
}
|
|
@@ -42807,22 +42091,22 @@ function pickExtId(frame) {
|
|
|
42807
42091
|
}
|
|
42808
42092
|
return extId;
|
|
42809
42093
|
}
|
|
42810
|
-
function composeState(
|
|
42811
|
-
if (
|
|
42812
|
-
if (manifestMode(
|
|
42094
|
+
function composeState(rec, running, crashed, getPort) {
|
|
42095
|
+
if (rec.state === "invalid") return rec;
|
|
42096
|
+
if (manifestMode(rec.manifest) === "hosted") {
|
|
42813
42097
|
return {
|
|
42814
|
-
...
|
|
42098
|
+
...rec,
|
|
42815
42099
|
state: "running",
|
|
42816
|
-
target: { kind: "hosted", url:
|
|
42100
|
+
target: { kind: "hosted", url: rec.manifest.entry.url }
|
|
42817
42101
|
};
|
|
42818
42102
|
}
|
|
42819
|
-
if (running.has(
|
|
42820
|
-
const port = getPort(
|
|
42821
|
-
if (port == null) return
|
|
42822
|
-
return { ...
|
|
42103
|
+
if (running.has(rec.extId)) {
|
|
42104
|
+
const port = getPort(rec.extId);
|
|
42105
|
+
if (port == null) return rec;
|
|
42106
|
+
return { ...rec, state: "running", target: { kind: "local", port } };
|
|
42823
42107
|
}
|
|
42824
|
-
if (crashed.has(
|
|
42825
|
-
return
|
|
42108
|
+
if (crashed.has(rec.extId)) return { ...rec, state: "crashed" };
|
|
42109
|
+
return rec;
|
|
42826
42110
|
}
|
|
42827
42111
|
function buildExtensionHandlers(deps) {
|
|
42828
42112
|
const list = async (_frame, _client, ctx) => {
|
|
@@ -43039,7 +42323,7 @@ function buildExtensionHandlers(deps) {
|
|
|
43039
42323
|
}
|
|
43040
42324
|
|
|
43041
42325
|
// src/app-builder/kill-port.ts
|
|
43042
|
-
var
|
|
42326
|
+
var import_node_child_process7 = require("child_process");
|
|
43043
42327
|
async function killPortOccupants(port, ownedPids, logger) {
|
|
43044
42328
|
let pids;
|
|
43045
42329
|
try {
|
|
@@ -43081,7 +42365,7 @@ async function killPortOccupants(port, ownedPids, logger) {
|
|
|
43081
42365
|
}
|
|
43082
42366
|
function listPidsOnPort(port) {
|
|
43083
42367
|
return new Promise((resolve6, reject) => {
|
|
43084
|
-
(0,
|
|
42368
|
+
(0, import_node_child_process7.execFile)(
|
|
43085
42369
|
"lsof",
|
|
43086
42370
|
["-ti", `:${port}`],
|
|
43087
42371
|
{ timeout: 3e3 },
|
|
@@ -43153,8 +42437,8 @@ var PublishJobRegistry = class {
|
|
|
43153
42437
|
};
|
|
43154
42438
|
|
|
43155
42439
|
// src/app-builder/publish-job-runner.ts
|
|
43156
|
-
var
|
|
43157
|
-
var
|
|
42440
|
+
var import_node_child_process8 = require("child_process");
|
|
42441
|
+
var import_node_fs29 = require("fs");
|
|
43158
42442
|
var import_node_path38 = require("path");
|
|
43159
42443
|
|
|
43160
42444
|
// src/app-builder/publish-stage-parser.ts
|
|
@@ -43182,7 +42466,7 @@ function tailStderrLines(buf, n) {
|
|
|
43182
42466
|
// src/app-builder/publish-job-runner.ts
|
|
43183
42467
|
async function startPublishJob(deps, args) {
|
|
43184
42468
|
const { registry: registry2, projectDir } = deps;
|
|
43185
|
-
const
|
|
42469
|
+
const spawn9 = deps.spawnImpl ?? import_node_child_process8.spawn;
|
|
43186
42470
|
if (registry2.has(args.name)) {
|
|
43187
42471
|
return { jobId: registry2.get(args.name).jobId, status: "already-publishing" };
|
|
43188
42472
|
}
|
|
@@ -43190,11 +42474,11 @@ async function startPublishJob(deps, args) {
|
|
|
43190
42474
|
const logPath = (0, import_node_path38.join)(projDir, ".publish.log");
|
|
43191
42475
|
let logStream = null;
|
|
43192
42476
|
try {
|
|
43193
|
-
logStream = (0,
|
|
42477
|
+
logStream = (0, import_node_fs29.createWriteStream)(logPath, { flags: "w" });
|
|
43194
42478
|
} catch {
|
|
43195
42479
|
logStream = null;
|
|
43196
42480
|
}
|
|
43197
|
-
const child =
|
|
42481
|
+
const child = spawn9("bash", [args.scriptPath, projDir], {
|
|
43198
42482
|
cwd: projDir,
|
|
43199
42483
|
env: process.env,
|
|
43200
42484
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -43448,7 +42732,7 @@ async function recoverInterruptedJobs(deps) {
|
|
|
43448
42732
|
// src/handlers/app-builder.ts
|
|
43449
42733
|
init_protocol();
|
|
43450
42734
|
var import_node_path39 = require("path");
|
|
43451
|
-
var
|
|
42735
|
+
var import_node_fs30 = require("fs");
|
|
43452
42736
|
var APP_BUILDER_PERSONAS = ["persona-app-builder"];
|
|
43453
42737
|
var PUBLISH_SCRIPT_REL = "extension-kit/scripts/publish.sh";
|
|
43454
42738
|
var DEV_SERVER_READY_TIMEOUT_MS = 3e4;
|
|
@@ -43530,7 +42814,7 @@ function buildAppBuilderHandlers(deps) {
|
|
|
43530
42814
|
async function listAllUsersProjects() {
|
|
43531
42815
|
if (!deps.usersRoot || !deps.getStore) return [];
|
|
43532
42816
|
const getStore = deps.getStore;
|
|
43533
|
-
const userIds = await
|
|
42817
|
+
const userIds = await import_node_fs30.promises.readdir(deps.usersRoot).catch(() => []);
|
|
43534
42818
|
const perUser = await Promise.all(
|
|
43535
42819
|
userIds.map((uid) => getStore(uid).list().catch(() => []))
|
|
43536
42820
|
);
|
|
@@ -44070,8 +43354,8 @@ function buildMethodHandlers(deps) {
|
|
|
44070
43354
|
}
|
|
44071
43355
|
|
|
44072
43356
|
// src/app-builder/project-store.ts
|
|
44073
|
-
var
|
|
44074
|
-
var
|
|
43357
|
+
var import_node_fs31 = require("fs");
|
|
43358
|
+
var import_node_child_process9 = require("child_process");
|
|
44075
43359
|
var import_node_path42 = require("path");
|
|
44076
43360
|
init_protocol();
|
|
44077
43361
|
var PROJECTS_DIR = "projects";
|
|
@@ -44099,7 +43383,7 @@ var ProjectStore = class {
|
|
|
44099
43383
|
async list() {
|
|
44100
43384
|
let entries;
|
|
44101
43385
|
try {
|
|
44102
|
-
entries = await
|
|
43386
|
+
entries = await import_node_fs31.promises.readdir(this.projectsRoot());
|
|
44103
43387
|
} catch (err) {
|
|
44104
43388
|
if (err.code === "ENOENT") return [];
|
|
44105
43389
|
throw err;
|
|
@@ -44107,7 +43391,7 @@ var ProjectStore = class {
|
|
|
44107
43391
|
const out = [];
|
|
44108
43392
|
for (const name of entries) {
|
|
44109
43393
|
try {
|
|
44110
|
-
const raw = await
|
|
43394
|
+
const raw = await import_node_fs31.promises.readFile(this.metaPath(name), "utf8");
|
|
44111
43395
|
const json = JSON.parse(raw);
|
|
44112
43396
|
let migrated = false;
|
|
44113
43397
|
if (typeof json.devCommand !== "string" || json.devCommand.length === 0) {
|
|
@@ -44118,7 +43402,7 @@ var ProjectStore = class {
|
|
|
44118
43402
|
if (parsed.success) {
|
|
44119
43403
|
out.push(parsed.data);
|
|
44120
43404
|
if (migrated) {
|
|
44121
|
-
void
|
|
43405
|
+
void import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(parsed.data, null, 2) + "\n", "utf8").catch(() => {
|
|
44122
43406
|
});
|
|
44123
43407
|
}
|
|
44124
43408
|
}
|
|
@@ -44162,8 +43446,8 @@ var ProjectStore = class {
|
|
|
44162
43446
|
throw new Error(`invalid name "${name}": ${validated.error.message}`);
|
|
44163
43447
|
}
|
|
44164
43448
|
const dir = this.projectDir(name);
|
|
44165
|
-
await
|
|
44166
|
-
await
|
|
43449
|
+
await import_node_fs31.promises.mkdir(dir, { recursive: true });
|
|
43450
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
44167
43451
|
return meta;
|
|
44168
43452
|
}
|
|
44169
43453
|
/**
|
|
@@ -44178,7 +43462,7 @@ var ProjectStore = class {
|
|
|
44178
43462
|
const scriptPath = (0, import_node_path42.join)(personaRoot, SCAFFOLD_SCRIPT_REL);
|
|
44179
43463
|
const destDir = this.projectDir(name);
|
|
44180
43464
|
return await new Promise((resolve6, reject) => {
|
|
44181
|
-
const child = (0,
|
|
43465
|
+
const child = (0, import_node_child_process9.spawn)("bash", [scriptPath, name, template, destDir], {
|
|
44182
43466
|
cwd: personaRoot,
|
|
44183
43467
|
env: { ...process.env, PATH: process.env.PATH ?? "" },
|
|
44184
43468
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -44208,7 +43492,7 @@ var ProjectStore = class {
|
|
|
44208
43492
|
}
|
|
44209
43493
|
async delete(name) {
|
|
44210
43494
|
const dir = this.projectDir(name);
|
|
44211
|
-
await
|
|
43495
|
+
await import_node_fs31.promises.rm(dir, { recursive: true, force: true });
|
|
44212
43496
|
}
|
|
44213
43497
|
async updatePort(name, newPort) {
|
|
44214
43498
|
if (newPort < PROJECT_PORT_MIN || newPort > PROJECT_PORT_MAX) {
|
|
@@ -44224,7 +43508,7 @@ var ProjectStore = class {
|
|
|
44224
43508
|
throw new Error(`port ${newPort} already used / \u5DF2\u88AB project "${conflict.name}" \u5360\u7528`);
|
|
44225
43509
|
}
|
|
44226
43510
|
const updated = { ...target, port: newPort };
|
|
44227
|
-
await
|
|
43511
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
44228
43512
|
return updated;
|
|
44229
43513
|
}
|
|
44230
43514
|
/**
|
|
@@ -44241,7 +43525,7 @@ var ProjectStore = class {
|
|
|
44241
43525
|
if (!validated.success) {
|
|
44242
43526
|
throw new Error(`invalid prodUrl "${url}": ${validated.error.message}`);
|
|
44243
43527
|
}
|
|
44244
|
-
await
|
|
43528
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44245
43529
|
return validated.data;
|
|
44246
43530
|
}
|
|
44247
43531
|
/**
|
|
@@ -44262,7 +43546,7 @@ var ProjectStore = class {
|
|
|
44262
43546
|
if (!validated.success) {
|
|
44263
43547
|
throw new Error(`invalid publishJob: ${validated.error.message}`);
|
|
44264
43548
|
}
|
|
44265
|
-
await
|
|
43549
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44266
43550
|
return validated.data;
|
|
44267
43551
|
}
|
|
44268
43552
|
/** 清掉 .clawd-project.json.publishJob 字段。其他字段保持原样。 */
|
|
@@ -44277,13 +43561,13 @@ var ProjectStore = class {
|
|
|
44277
43561
|
if (!validated.success) {
|
|
44278
43562
|
throw new Error(`failed to clear publishJob: ${validated.error.message}`);
|
|
44279
43563
|
}
|
|
44280
|
-
await
|
|
43564
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44281
43565
|
return validated.data;
|
|
44282
43566
|
}
|
|
44283
43567
|
};
|
|
44284
43568
|
|
|
44285
43569
|
// src/app-builder/dev-server-supervisor.ts
|
|
44286
|
-
var
|
|
43570
|
+
var import_node_child_process10 = require("child_process");
|
|
44287
43571
|
var import_node_events2 = require("events");
|
|
44288
43572
|
var DEFAULT_READY_PATTERN = /Local:\s+https?:\/\/|Nest application successfully started|server listening on/i;
|
|
44289
43573
|
var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
@@ -44320,7 +43604,7 @@ var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
|
44320
43604
|
tunnelHost: args.tunnelHost,
|
|
44321
43605
|
devCommand: cmd
|
|
44322
43606
|
});
|
|
44323
|
-
const child = (0,
|
|
43607
|
+
const child = (0, import_node_child_process10.spawn)("sh", ["-c", cmd], {
|
|
44324
43608
|
cwd: args.cwd,
|
|
44325
43609
|
env,
|
|
44326
43610
|
stdio: "pipe",
|
|
@@ -44712,7 +43996,7 @@ function computeGrantForFrame(method, frame) {
|
|
|
44712
43996
|
}
|
|
44713
43997
|
|
|
44714
43998
|
// src/extension/runtime.ts
|
|
44715
|
-
var
|
|
43999
|
+
var import_node_child_process11 = require("child_process");
|
|
44716
44000
|
var import_node_path43 = __toESM(require("path"), 1);
|
|
44717
44001
|
var import_promises10 = require("timers/promises");
|
|
44718
44002
|
|
|
@@ -44799,17 +44083,17 @@ var Runtime = class {
|
|
|
44799
44083
|
const existing = this.handles.get(extId);
|
|
44800
44084
|
if (existing) return { kind: "local", port: existing.port };
|
|
44801
44085
|
const records = await loadAll(this.root);
|
|
44802
|
-
const
|
|
44803
|
-
if (!
|
|
44804
|
-
if (
|
|
44805
|
-
throw new RuntimeError("INVALID_MANIFEST",
|
|
44806
|
-
if (manifestMode(
|
|
44807
|
-
return { kind: "hosted", url:
|
|
44086
|
+
const rec = records.find((r) => r.extId === extId);
|
|
44087
|
+
if (!rec) throw new RuntimeError("NOT_FOUND", `extension ${extId} not installed`);
|
|
44088
|
+
if (rec.state === "invalid")
|
|
44089
|
+
throw new RuntimeError("INVALID_MANIFEST", rec.invalidReason);
|
|
44090
|
+
if (manifestMode(rec.manifest) === "hosted") {
|
|
44091
|
+
return { kind: "hosted", url: rec.manifest.entry.url };
|
|
44808
44092
|
}
|
|
44809
44093
|
const port = await this.allocator.allocate().catch(() => {
|
|
44810
44094
|
throw new RuntimeError("PORT_EXHAUSTED", "no free port in configured range");
|
|
44811
44095
|
});
|
|
44812
|
-
const startCommand =
|
|
44096
|
+
const startCommand = rec.manifest.runtime.startCommand;
|
|
44813
44097
|
const cmd = startCommand.replace(
|
|
44814
44098
|
/\$CLAWOS_EXT_PORT/g,
|
|
44815
44099
|
String(port)
|
|
@@ -44820,7 +44104,7 @@ var Runtime = class {
|
|
|
44820
44104
|
CLAWOS_EXT_PORT: String(port),
|
|
44821
44105
|
CLAWOS_EXT_ID: extId
|
|
44822
44106
|
};
|
|
44823
|
-
const child = (0,
|
|
44107
|
+
const child = (0, import_node_child_process11.spawn)("sh", ["-c", cmd], {
|
|
44824
44108
|
cwd: dir,
|
|
44825
44109
|
env,
|
|
44826
44110
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -45256,7 +44540,7 @@ async function startDaemon(config) {
|
|
|
45256
44540
|
const absPath = import_node_path46.default.isAbsolute(input.relPath) ? input.relPath : import_node_path46.default.join(input.cwd, input.relPath);
|
|
45257
44541
|
let size = 0;
|
|
45258
44542
|
try {
|
|
45259
|
-
size =
|
|
44543
|
+
size = import_node_fs32.default.statSync(absPath).size;
|
|
45260
44544
|
} catch (err) {
|
|
45261
44545
|
logger.warn("attachment.onFileEdit stat failed", {
|
|
45262
44546
|
sessionId: input.sessionId,
|
|
@@ -45326,7 +44610,6 @@ async function startDaemon(config) {
|
|
|
45326
44610
|
onReady: (tsid) => manager.dispatchReadyDetected(tsid)
|
|
45327
44611
|
}) : new ClaudeAdapter({ logger, historyReader: new ClaudeHistoryReader() });
|
|
45328
44612
|
registerAdapter("claude", claudeAdapter);
|
|
45329
|
-
registerAdapter("codex", new CodexAdapter({ logger, historyReader: new CodexHistoryReader() }));
|
|
45330
44613
|
const personaRegistry = new PersonaRegistry(personaStore);
|
|
45331
44614
|
const personaManager = new PersonaManager({
|
|
45332
44615
|
store: personaStore,
|
|
@@ -45405,11 +44688,7 @@ async function startDaemon(config) {
|
|
|
45405
44688
|
workspace,
|
|
45406
44689
|
skills,
|
|
45407
44690
|
agents,
|
|
45408
|
-
// skills:list 按 tool 路由:codex → app-server skills/list;缺省 claude → SkillsScanner(同步包成 Promise)。
|
|
45409
|
-
getSkillsForTool: (tool, cwd) => tool === "codex" ? listCodexSkills(cwd) : Promise.resolve(skills.list({ cwd })),
|
|
45410
44691
|
history,
|
|
45411
|
-
// history:read 按 session.tool 路由:codex → adapter.historyReader(CodexHistoryReader);缺省 claude。
|
|
45412
|
-
getHistoryReader: (tool) => getAdapter(tool).historyReader ?? history,
|
|
45413
44692
|
observer,
|
|
45414
44693
|
getAdapter,
|
|
45415
44694
|
store,
|
|
@@ -45748,7 +45027,8 @@ async function startDaemon(config) {
|
|
|
45748
45027
|
protocolVersion: PROTOCOL_VERSION,
|
|
45749
45028
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
45750
45029
|
authMode,
|
|
45751
|
-
authToken: resolvedAuthToken ?? void 0
|
|
45030
|
+
authToken: resolvedAuthToken ?? void 0,
|
|
45031
|
+
source: readDaemonSourceFromEnv()
|
|
45752
45032
|
};
|
|
45753
45033
|
stateMgr.write(stateSnapshot);
|
|
45754
45034
|
process.stdout.write(`Ready: ${url}
|
|
@@ -45799,7 +45079,7 @@ ${bar}
|
|
|
45799
45079
|
`);
|
|
45800
45080
|
try {
|
|
45801
45081
|
const connectPath = import_node_path46.default.join(config.dataDir, "connect.txt");
|
|
45802
|
-
|
|
45082
|
+
import_node_fs32.default.writeFileSync(connectPath, lines.join("\n") + "\n", { mode: 384 });
|
|
45803
45083
|
} catch {
|
|
45804
45084
|
}
|
|
45805
45085
|
} catch (err) {
|
|
@@ -45872,7 +45152,7 @@ ${bar}
|
|
|
45872
45152
|
function migrateDropPersonsDir(dataDir) {
|
|
45873
45153
|
const dir = import_node_path46.default.join(dataDir, "persons");
|
|
45874
45154
|
try {
|
|
45875
|
-
|
|
45155
|
+
import_node_fs32.default.rmSync(dir, { recursive: true, force: true });
|
|
45876
45156
|
} catch {
|
|
45877
45157
|
}
|
|
45878
45158
|
}
|