@clawos-dev/clawd 0.2.133-beta.275.ba80f7e → 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 -1120
- 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,436 +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
|
-
respond(id, result) {
|
|
35245
|
-
this.write({ id, result });
|
|
35246
|
-
}
|
|
35247
|
-
onLine(line) {
|
|
35248
|
-
const t = line.trim();
|
|
35249
|
-
if (!t) return;
|
|
35250
|
-
let m2;
|
|
35251
|
-
try {
|
|
35252
|
-
m2 = JSON.parse(t);
|
|
35253
|
-
} catch {
|
|
35254
|
-
return;
|
|
35255
|
-
}
|
|
35256
|
-
if (!isRecord(m2)) return;
|
|
35257
|
-
const hasId = typeof m2.id === "number", hasMethod = typeof m2.method === "string";
|
|
35258
|
-
if (hasId && !hasMethod) {
|
|
35259
|
-
const p2 = this.pending.get(m2.id);
|
|
35260
|
-
if (!p2) return;
|
|
35261
|
-
this.pending.delete(m2.id);
|
|
35262
|
-
if (m2.error) {
|
|
35263
|
-
const e = isRecord(m2.error) ? m2.error : {};
|
|
35264
|
-
p2.reject(new Error(typeof e.message === "string" ? e.message : "app-server error"));
|
|
35265
|
-
} else p2.resolve(m2.result);
|
|
35266
|
-
return;
|
|
35267
|
-
}
|
|
35268
|
-
if (hasId && hasMethod) {
|
|
35269
|
-
this.opts.onServerRequest?.(m2.id, m2.method, m2.params);
|
|
35270
|
-
return;
|
|
35271
|
-
}
|
|
35272
|
-
if (hasMethod) this.opts.onNotification?.(m2.method, m2.params);
|
|
35273
|
-
}
|
|
35274
|
-
write(o) {
|
|
35275
|
-
this.proc.stdin.write(JSON.stringify(o) + "\n");
|
|
35276
|
-
}
|
|
35277
|
-
};
|
|
35278
|
-
function isRecord(v2) {
|
|
35279
|
-
return typeof v2 === "object" && v2 !== null;
|
|
35280
|
-
}
|
|
35281
|
-
|
|
35282
|
-
// src/tools/codex-app-server-events.ts
|
|
35283
|
-
function translateNotification(method, params) {
|
|
35284
|
-
const p2 = rec(params);
|
|
35285
|
-
switch (method) {
|
|
35286
|
-
case "thread/started": {
|
|
35287
|
-
const id = str(rec(p2?.thread)?.id);
|
|
35288
|
-
return id ? [{ kind: "session_init", toolSessionId: id }] : [];
|
|
35289
|
-
}
|
|
35290
|
-
case "item/agentMessage/delta": {
|
|
35291
|
-
const text = str(p2?.delta);
|
|
35292
|
-
const id = str(p2?.itemId);
|
|
35293
|
-
return text ? [{ kind: "text", text, ...id ? { partialId: id } : {} }] : [];
|
|
35294
|
-
}
|
|
35295
|
-
case "item/reasoning/textDelta":
|
|
35296
|
-
case "item/reasoning/summaryTextDelta": {
|
|
35297
|
-
const text = str(p2?.delta);
|
|
35298
|
-
const id = str(p2?.itemId);
|
|
35299
|
-
return text ? [{ kind: "thinking", text, ...id ? { partialId: id } : {} }] : [];
|
|
35300
|
-
}
|
|
35301
|
-
case "item/commandExecution/outputDelta":
|
|
35302
|
-
return [];
|
|
35303
|
-
// 命令输出增量 v1 不逐字(完成时整段给)
|
|
35304
|
-
case "item/started":
|
|
35305
|
-
return itemStarted(rec(p2?.item));
|
|
35306
|
-
case "item/completed":
|
|
35307
|
-
return itemCompleted(rec(p2?.item));
|
|
35308
|
-
case "thread/tokenUsage/updated":
|
|
35309
|
-
return tokenUsage(rec(rec(p2?.tokenUsage)));
|
|
35310
|
-
case "turn/completed":
|
|
35311
|
-
return turnCompleted(rec(p2?.turn));
|
|
35312
|
-
default:
|
|
35313
|
-
return [];
|
|
35314
|
-
}
|
|
35315
|
-
}
|
|
35316
|
-
function itemStarted(item) {
|
|
35317
|
-
if (!item || item.type !== "commandExecution") return [];
|
|
35318
|
-
const id = str(item.id);
|
|
35319
|
-
if (!id) return [];
|
|
35320
|
-
return [{ kind: "tool_call", toolUseId: id, tool: "commandExecution", toolKind: "codex", input: { command: str(item.command) ?? "" } }];
|
|
35321
|
-
}
|
|
35322
|
-
function itemCompleted(item) {
|
|
35323
|
-
if (!item) return [];
|
|
35324
|
-
switch (item.type) {
|
|
35325
|
-
case "userMessage":
|
|
35326
|
-
return [];
|
|
35327
|
-
// 用户输入回显, clawd 自己 synthesize user_text
|
|
35328
|
-
case "agentMessage": {
|
|
35329
|
-
const text = str(item.text);
|
|
35330
|
-
return text ? [{ kind: "text", text }] : [];
|
|
35331
|
-
}
|
|
35332
|
-
case "reasoning": {
|
|
35333
|
-
const text = str(item.text);
|
|
35334
|
-
return text ? [{ kind: "thinking", text }] : [];
|
|
35335
|
-
}
|
|
35336
|
-
case "commandExecution": {
|
|
35337
|
-
const id = str(item.id);
|
|
35338
|
-
if (!id) return [];
|
|
35339
|
-
const exit = num(item.exitCode);
|
|
35340
|
-
const ev = { kind: "tool_result", toolUseId: id, output: str(item.aggregatedOutput ?? item.output) ?? "" };
|
|
35341
|
-
if (exit !== void 0 && exit !== 0) ev.error = `exit ${exit}`;
|
|
35342
|
-
return [ev];
|
|
35343
|
-
}
|
|
35344
|
-
default:
|
|
35345
|
-
return [];
|
|
35346
|
-
}
|
|
35347
|
-
}
|
|
35348
|
-
function tokenUsage(usage) {
|
|
35349
|
-
if (!usage) return [];
|
|
35350
|
-
const last = rec(usage.last);
|
|
35351
|
-
if (!last) return [];
|
|
35352
|
-
const i = num(last.inputTokens), o = num(last.outputTokens);
|
|
35353
|
-
const patch = {};
|
|
35354
|
-
if (i !== void 0 && o !== void 0) patch.contextUsage = { inputTokens: i, outputTokens: o };
|
|
35355
|
-
const w2 = num(usage.modelContextWindow);
|
|
35356
|
-
if (w2 !== void 0) patch.contextWindowSize = w2;
|
|
35357
|
-
return Object.keys(patch).length ? [{ kind: "meta_update", patch }] : [];
|
|
35358
|
-
}
|
|
35359
|
-
function turnCompleted(turn) {
|
|
35360
|
-
if (turn?.status === "failed") return [{ kind: "error", message: str(rec(turn.error)?.message) ?? "codex turn failed" }, { kind: "turn_end" }];
|
|
35361
|
-
return [{ kind: "turn_end" }];
|
|
35362
|
-
}
|
|
35363
|
-
function rec(v2) {
|
|
35364
|
-
return typeof v2 === "object" && v2 !== null ? v2 : void 0;
|
|
35365
|
-
}
|
|
35366
|
-
function str(v2) {
|
|
35367
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
35368
|
-
}
|
|
35369
|
-
function num(v2) {
|
|
35370
|
-
return typeof v2 === "number" ? v2 : void 0;
|
|
35371
|
-
}
|
|
35372
|
-
|
|
35373
|
-
// src/tools/codex-app-server-params.ts
|
|
35374
|
-
function resolveSandbox(ctx) {
|
|
35375
|
-
if (ctx.personaMode === "guest") throw new Error("codex \u6682\u4E0D\u652F\u6301 guest persona session\uFF1B\u8BF7\u7528 claude \u6216 owner");
|
|
35376
|
-
return "danger-full-access";
|
|
35377
|
-
}
|
|
35378
|
-
function resolveApprovalPolicy(ctx) {
|
|
35379
|
-
const m2 = ctx.permissionMode ?? "";
|
|
35380
|
-
if (m2 === "untrusted" || m2 === "on-failure" || m2 === "on-request" || m2 === "never") return m2;
|
|
35381
|
-
return "on-request";
|
|
35382
|
-
}
|
|
35383
|
-
function threadStartParams(ctx) {
|
|
35384
|
-
return {
|
|
35385
|
-
cwd: ctx.cwd,
|
|
35386
|
-
sandbox: resolveSandbox(ctx),
|
|
35387
|
-
// persona 侧
|
|
35388
|
-
approvalPolicy: resolveApprovalPolicy(ctx),
|
|
35389
|
-
// 会话设置侧
|
|
35390
|
-
approvalsReviewer: "user",
|
|
35391
|
-
...ctx.model ? { model: ctx.model } : {}
|
|
35392
|
-
};
|
|
35393
|
-
}
|
|
35394
|
-
var ATTACHMENT_RE2 = /\[attachment:(image|file):([^\]]+)\]/g;
|
|
35395
|
-
var SKILL_RE = /\[skill:(.+?):(\/[^\]]+)\]/g;
|
|
35396
|
-
function turnStartInput(text) {
|
|
35397
|
-
const items = [];
|
|
35398
|
-
let leftover = text;
|
|
35399
|
-
for (const m2 of text.matchAll(SKILL_RE)) {
|
|
35400
|
-
const [marker, name, path59] = m2;
|
|
35401
|
-
items.push({ type: "skill", name, path: path59 });
|
|
35402
|
-
leftover = leftover.replace(marker, "");
|
|
35403
|
-
}
|
|
35404
|
-
for (const m2 of text.matchAll(ATTACHMENT_RE2)) {
|
|
35405
|
-
const [marker, kind, url] = m2;
|
|
35406
|
-
if (kind === "image") {
|
|
35407
|
-
items.push({ type: "image", url });
|
|
35408
|
-
leftover = leftover.replace(marker, "");
|
|
35409
|
-
}
|
|
35410
|
-
}
|
|
35411
|
-
const trimmed = leftover.trim();
|
|
35412
|
-
if (trimmed || items.length === 0) items.push({ type: "text", text: trimmed, text_elements: [] });
|
|
35413
|
-
return items;
|
|
35414
|
-
}
|
|
35415
|
-
|
|
35416
|
-
// src/tools/codex-session.ts
|
|
35417
|
-
function createCodexSession(ctx, sink, deps = {}) {
|
|
35418
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
35419
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
35420
|
-
const env = { ...process.env, ...ctx.env };
|
|
35421
|
-
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"] });
|
|
35422
|
-
let threadId = ctx.toolSessionId;
|
|
35423
|
-
let turnId;
|
|
35424
|
-
const approvalIds = /* @__PURE__ */ new Map();
|
|
35425
|
-
const pendingQuestions = /* @__PURE__ */ new Map();
|
|
35426
|
-
let pendingSystemPrompt = ctx.toolSessionId ? void 0 : ctx.extraSystemPrompt;
|
|
35427
|
-
const effort = ctx.effort;
|
|
35428
|
-
let exited = false;
|
|
35429
|
-
const finish = (code) => {
|
|
35430
|
-
if (exited) return;
|
|
35431
|
-
exited = true;
|
|
35432
|
-
sink.onExit(code);
|
|
35433
|
-
};
|
|
35434
|
-
const client = new CodexAppServerClient(proc, {
|
|
35435
|
-
onNotification: (method, params) => {
|
|
35436
|
-
if (method === "turn/started") {
|
|
35437
|
-
const id = params?.turn?.id;
|
|
35438
|
-
if (id) turnId = id;
|
|
35439
|
-
}
|
|
35440
|
-
const events = translateNotification(method, params);
|
|
35441
|
-
if (events.length) sink.pushEvents(events);
|
|
35442
|
-
},
|
|
35443
|
-
onServerRequest: (id, method, params) => {
|
|
35444
|
-
const p2 = params ?? {};
|
|
35445
|
-
if (method === "item/commandExecution/requestApproval" || method === "item/fileChange/requestApproval") {
|
|
35446
|
-
const reqId = String(id);
|
|
35447
|
-
approvalIds.set(reqId, id);
|
|
35448
|
-
sink.pushEvents([
|
|
35449
|
-
{
|
|
35450
|
-
kind: "permission_request",
|
|
35451
|
-
requestId: reqId,
|
|
35452
|
-
tool: method.includes("fileChange") ? "fileChange" : "commandExecution",
|
|
35453
|
-
input: p2,
|
|
35454
|
-
...typeof p2.itemId === "string" ? { toolUseId: p2.itemId } : {}
|
|
35455
|
-
}
|
|
35456
|
-
]);
|
|
35457
|
-
return;
|
|
35458
|
-
}
|
|
35459
|
-
if (method === "tool/requestUserInput") {
|
|
35460
|
-
const reqId = String(id);
|
|
35461
|
-
approvalIds.set(reqId, id);
|
|
35462
|
-
const texts = Array.isArray(p2.questions) ? p2.questions.map((q) => String(q.question ?? "")) : [];
|
|
35463
|
-
pendingQuestions.set(reqId, texts);
|
|
35464
|
-
const questions = texts.map((question) => ({
|
|
35465
|
-
question,
|
|
35466
|
-
multiSelect: false,
|
|
35467
|
-
options: []
|
|
35468
|
-
}));
|
|
35469
|
-
sink.pushEvents([{ kind: "ask_user_question", toolUseId: reqId, questions }]);
|
|
35470
|
-
return;
|
|
35471
|
-
}
|
|
35472
|
-
client.respond(id, "cancel");
|
|
35473
|
-
},
|
|
35474
|
-
onClose: () => finish(proc.exitCode)
|
|
35475
|
-
});
|
|
35476
|
-
proc.stderr?.on(
|
|
35477
|
-
"data",
|
|
35478
|
-
(c) => deps.logger?.warn("codex app-server stderr", { line: c.toString().slice(0, 500) })
|
|
35479
|
-
);
|
|
35480
|
-
proc.on("exit", (code) => finish(code));
|
|
35481
|
-
const ready = (async () => {
|
|
35482
|
-
await client.request("initialize", {
|
|
35483
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
35484
|
-
capabilities: null
|
|
35485
|
-
});
|
|
35486
|
-
client.notify("initialized", {});
|
|
35487
|
-
if (threadId) {
|
|
35488
|
-
await client.request("thread/resume", { threadId });
|
|
35489
|
-
} else {
|
|
35490
|
-
const res = await client.request("thread/start", threadStartParams(ctx));
|
|
35491
|
-
threadId = res?.thread?.id;
|
|
35492
|
-
if (threadId) sink.pushEvents([{ kind: "session_init", toolSessionId: threadId }]);
|
|
35493
|
-
}
|
|
35494
|
-
})().catch((e) => sink.onError(`codex app-server init failed: ${e.message}`));
|
|
35495
|
-
return {
|
|
35496
|
-
startTurn(text) {
|
|
35497
|
-
const body = pendingSystemPrompt ? `${pendingSystemPrompt}
|
|
35498
|
-
|
|
35499
|
-
${text}` : text;
|
|
35500
|
-
pendingSystemPrompt = void 0;
|
|
35501
|
-
void ready.then(() => {
|
|
35502
|
-
if (threadId)
|
|
35503
|
-
void client.request("turn/start", {
|
|
35504
|
-
threadId,
|
|
35505
|
-
input: turnStartInput(body),
|
|
35506
|
-
...effort ? { reasoningEffort: effort } : {}
|
|
35507
|
-
}).catch((e) => sink.onError(`turn/start failed: ${e.message}`));
|
|
35508
|
-
});
|
|
35509
|
-
},
|
|
35510
|
-
respondPermission(requestId, allow) {
|
|
35511
|
-
const id = approvalIds.get(requestId);
|
|
35512
|
-
if (id === void 0) return;
|
|
35513
|
-
approvalIds.delete(requestId);
|
|
35514
|
-
client.respond(id, allow ? "accept" : "cancel");
|
|
35515
|
-
},
|
|
35516
|
-
answerQuestion(requestId, answers) {
|
|
35517
|
-
const id = approvalIds.get(requestId);
|
|
35518
|
-
if (id === void 0) return;
|
|
35519
|
-
approvalIds.delete(requestId);
|
|
35520
|
-
const qs = pendingQuestions.get(requestId) ?? [];
|
|
35521
|
-
pendingQuestions.delete(requestId);
|
|
35522
|
-
client.respond(id, { answers: qs.map((q) => answers[q] ?? "") });
|
|
35523
|
-
},
|
|
35524
|
-
interrupt() {
|
|
35525
|
-
if (threadId && turnId) void client.request("turn/interrupt", { threadId, turnId }).catch(() => {
|
|
35526
|
-
});
|
|
35527
|
-
},
|
|
35528
|
-
async stop() {
|
|
35529
|
-
this.interrupt();
|
|
35530
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
35531
|
-
}
|
|
35532
|
-
};
|
|
35533
|
-
}
|
|
35534
|
-
|
|
35535
|
-
// src/tools/codex.ts
|
|
35536
|
-
var CODEX_MODELS = [
|
|
35537
|
-
{ id: "", label: "Default", description: "codex config.toml \u9ED8\u8BA4", contextWindowSize: 258400, default: true },
|
|
35538
|
-
{ id: "gpt-5.5", label: "GPT-5.5", description: "Frontier model for complex coding", contextWindowSize: 258400 },
|
|
35539
|
-
{ id: "gpt-5.4", label: "GPT-5.4", contextWindowSize: 258400 },
|
|
35540
|
-
{ id: "gpt-5.4-mini", label: "GPT-5.4-Mini", contextWindowSize: 258400 }
|
|
35541
|
-
];
|
|
35542
|
-
var CODEX_EFFORTS = [
|
|
35543
|
-
{ value: "low", label: "Low", description: "Fast responses with lighter reasoning" },
|
|
35544
|
-
{ value: "medium", label: "Medium", description: "Balances speed and reasoning depth for everyday tasks" },
|
|
35545
|
-
{ value: "high", label: "High", description: "Greater reasoning depth for complex problems" },
|
|
35546
|
-
{ value: "xhigh", label: "Extra high", description: "Extra high reasoning depth for complex problems" }
|
|
35547
|
-
];
|
|
35548
|
-
var CODEX_APPROVAL_PRESETS = [
|
|
35549
|
-
{ id: "untrusted", label: "Ask for approval", description: "\u51E0\u4E4E\u6BCF\u6761\u547D\u4EE4\u90FD\u95EE\u4F60\uFF08\u6700\u8C28\u614E\uFF09" },
|
|
35550
|
-
{ 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" },
|
|
35551
|
-
{ id: "never", label: "Full Access", description: "\u4ECE\u4E0D\u8BE2\u95EE\uFF0C\u81EA\u4E3B\u6267\u884C" }
|
|
35552
|
-
];
|
|
35553
|
-
var CODEX_CAPABILITIES = {
|
|
35554
|
-
tool: "codex",
|
|
35555
|
-
toolSessionIdLabel: "Codex Thread ID",
|
|
35556
|
-
models: CODEX_MODELS,
|
|
35557
|
-
permissionModes: CODEX_APPROVAL_PRESETS,
|
|
35558
|
-
// codex 不支持这些 clawd 功能(rewind 无 file-snapshot / 无子 agent / 无 TUI pty /
|
|
35559
|
-
// 无 observe 推送 / 无文件分享);UI 据此 gate 入口。
|
|
35560
|
-
features: { rewind: false, subagents: false, tui: false, observe: false, fileSharing: false },
|
|
35561
|
-
configSchema: [
|
|
35562
|
-
{
|
|
35563
|
-
name: "model",
|
|
35564
|
-
type: "select",
|
|
35565
|
-
label: "Model",
|
|
35566
|
-
scope: "core",
|
|
35567
|
-
options: CODEX_MODELS.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35568
|
-
default: ""
|
|
35569
|
-
},
|
|
35570
|
-
{
|
|
35571
|
-
name: "permissionMode",
|
|
35572
|
-
type: "select",
|
|
35573
|
-
label: "Approval",
|
|
35574
|
-
scope: "core",
|
|
35575
|
-
options: CODEX_APPROVAL_PRESETS.map((m2) => ({ value: m2.id, label: m2.label, description: m2.description })),
|
|
35576
|
-
default: "on-request"
|
|
35577
|
-
},
|
|
35578
|
-
{
|
|
35579
|
-
name: "effort",
|
|
35580
|
-
type: "select",
|
|
35581
|
-
label: "Reasoning effort",
|
|
35582
|
-
scope: "tool-specific",
|
|
35583
|
-
// 渲染在 Advanced 区(与 claude effort 一致)
|
|
35584
|
-
options: CODEX_EFFORTS,
|
|
35585
|
-
default: "medium"
|
|
35586
|
-
}
|
|
35587
|
-
]
|
|
35588
|
-
};
|
|
35589
|
-
async function probeCodex(env = process.env) {
|
|
35590
|
-
if (env.CODEX_BIN && import_node_fs10.default.existsSync(env.CODEX_BIN)) return { available: true, path: env.CODEX_BIN };
|
|
35591
|
-
try {
|
|
35592
|
-
const out = (0, import_node_child_process4.execFileSync)("which", ["codex"], { encoding: "utf8" }).trim();
|
|
35593
|
-
if (out && import_node_fs10.default.existsSync(out)) return { available: true, path: out };
|
|
35594
|
-
} catch {
|
|
35595
|
-
}
|
|
35596
|
-
return { available: false };
|
|
35597
|
-
}
|
|
35598
|
-
var CodexAdapter = class {
|
|
35599
|
-
id = "codex";
|
|
35600
|
-
// 历史读取器:history:read 按 session.tool 路由到这里(thread/read)。
|
|
35601
|
-
historyReader;
|
|
35602
|
-
probeCache = null;
|
|
35603
|
-
logger;
|
|
35604
|
-
probeOverride;
|
|
35605
|
-
constructor(opts = {}) {
|
|
35606
|
-
this.logger = opts.logger;
|
|
35607
|
-
this.probeOverride = opts.probeOverride;
|
|
35608
|
-
this.historyReader = opts.historyReader;
|
|
35609
|
-
}
|
|
35610
|
-
async probe() {
|
|
35611
|
-
if (this.probeCache) return this.probeCache;
|
|
35612
|
-
this.probeCache = this.probeOverride ? await this.probeOverride() : await probeCodex();
|
|
35613
|
-
return this.probeCache;
|
|
35614
|
-
}
|
|
35615
|
-
async capabilities() {
|
|
35616
|
-
return CODEX_CAPABILITIES;
|
|
35617
|
-
}
|
|
35618
|
-
resolveContextWindow(modelId) {
|
|
35619
|
-
return (CODEX_MODELS.find((m2) => m2.id === (modelId ?? "")) ?? CODEX_MODELS[0]).contextWindowSize;
|
|
35620
|
-
}
|
|
35621
|
-
createSession(ctx, sink) {
|
|
35622
|
-
return createCodexSession(ctx, sink, { logger: this.logger });
|
|
35623
|
-
}
|
|
35624
|
-
spawn(_ctx) {
|
|
35625
|
-
throw new Error("CodexAdapter uses createSession, not spawn");
|
|
35626
|
-
}
|
|
35627
|
-
parseLine(_line) {
|
|
35628
|
-
return [];
|
|
35629
|
-
}
|
|
35630
|
-
// 原样返回带 marker 的文本;附件 marker → codex image 多模态由 turnStartInput 解析
|
|
35631
|
-
// (codex-app-server-params.ts, PR1)。encodeStdin 不动 markers。
|
|
35632
|
-
encodeStdin(text, _ctx) {
|
|
35633
|
-
return text;
|
|
35634
|
-
}
|
|
35635
|
-
};
|
|
35636
|
-
|
|
35637
35157
|
// src/tools/claude-tui.ts
|
|
35638
|
-
var
|
|
35158
|
+
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
35639
35159
|
var import_node_os5 = __toESM(require("os"), 1);
|
|
35640
35160
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
35641
35161
|
var import_headless = __toESM(require_xterm_headless(), 1);
|
|
@@ -36619,7 +36139,7 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36619
36139
|
const home = import_node_os5.default.homedir();
|
|
36620
36140
|
const file = import_node_path10.default.join(home, ".claude", "projects", cwdToHashDir(ctx.cwd), `${ctx.toolSessionId}.jsonl`);
|
|
36621
36141
|
try {
|
|
36622
|
-
return
|
|
36142
|
+
return import_node_fs10.default.statSync(file).isFile();
|
|
36623
36143
|
} catch {
|
|
36624
36144
|
return false;
|
|
36625
36145
|
}
|
|
@@ -36628,236 +36148,8 @@ function jsonlExistsForCtx(ctx) {
|
|
|
36628
36148
|
// src/index.ts
|
|
36629
36149
|
init_claude_history();
|
|
36630
36150
|
|
|
36631
|
-
// src/tools/codex-history.ts
|
|
36632
|
-
var import_node_child_process5 = require("child_process");
|
|
36633
|
-
var DEFAULT_TIMEOUT_MS = 8e3;
|
|
36634
|
-
function rec2(v2) {
|
|
36635
|
-
return v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : void 0;
|
|
36636
|
-
}
|
|
36637
|
-
function str2(v2) {
|
|
36638
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
36639
|
-
}
|
|
36640
|
-
function num2(v2) {
|
|
36641
|
-
return typeof v2 === "number" && Number.isFinite(v2) ? v2 : void 0;
|
|
36642
|
-
}
|
|
36643
|
-
function userInputText(content) {
|
|
36644
|
-
if (!Array.isArray(content)) return "";
|
|
36645
|
-
return content.map((c) => {
|
|
36646
|
-
const r = rec2(c);
|
|
36647
|
-
return r && r.type === "text" ? str2(r.text) ?? "" : "";
|
|
36648
|
-
}).filter(Boolean).join("");
|
|
36649
|
-
}
|
|
36650
|
-
function threadItemToHistoryMessages(item) {
|
|
36651
|
-
const it = rec2(item);
|
|
36652
|
-
if (!it) return [];
|
|
36653
|
-
switch (it.type) {
|
|
36654
|
-
case "userMessage": {
|
|
36655
|
-
const text = userInputText(it.content);
|
|
36656
|
-
return text ? [{ kind: "user-text", text, raw: item }] : [];
|
|
36657
|
-
}
|
|
36658
|
-
case "agentMessage": {
|
|
36659
|
-
const text = str2(it.text);
|
|
36660
|
-
return text ? [{ kind: "assistant-text", text, raw: item }] : [];
|
|
36661
|
-
}
|
|
36662
|
-
case "commandExecution": {
|
|
36663
|
-
const id = str2(it.id);
|
|
36664
|
-
if (!id) return [];
|
|
36665
|
-
const msgs = [
|
|
36666
|
-
{
|
|
36667
|
-
kind: "tool_call",
|
|
36668
|
-
tool: "commandExecution",
|
|
36669
|
-
toolUseId: id,
|
|
36670
|
-
input: { command: str2(it.command) ?? "" },
|
|
36671
|
-
raw: item
|
|
36672
|
-
}
|
|
36673
|
-
];
|
|
36674
|
-
if (it.status === "completed" || it.aggregatedOutput != null || it.exitCode != null) {
|
|
36675
|
-
const exit = num2(it.exitCode);
|
|
36676
|
-
const result = {
|
|
36677
|
-
kind: "tool_result",
|
|
36678
|
-
toolUseId: id,
|
|
36679
|
-
output: str2(it.aggregatedOutput) ?? "",
|
|
36680
|
-
raw: item
|
|
36681
|
-
};
|
|
36682
|
-
if (exit !== void 0 && exit !== 0) result.output = `${result.output ?? ""}
|
|
36683
|
-
(exit ${exit})`;
|
|
36684
|
-
msgs.push(result);
|
|
36685
|
-
}
|
|
36686
|
-
return msgs;
|
|
36687
|
-
}
|
|
36688
|
-
default:
|
|
36689
|
-
return [];
|
|
36690
|
-
}
|
|
36691
|
-
}
|
|
36692
|
-
async function queryCodexAppServer(cwd, method, params, deps) {
|
|
36693
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
36694
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
36695
|
-
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"] });
|
|
36696
|
-
const client = new CodexAppServerClient(proc, {});
|
|
36697
|
-
const timeoutMs = deps.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
36698
|
-
let timer;
|
|
36699
|
-
const timeout = new Promise((_2, reject) => {
|
|
36700
|
-
timer = setTimeout(() => reject(new Error(`codex app-server ${method} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
36701
|
-
});
|
|
36702
|
-
try {
|
|
36703
|
-
await Promise.race([
|
|
36704
|
-
(async () => {
|
|
36705
|
-
await client.request("initialize", {
|
|
36706
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
36707
|
-
capabilities: null
|
|
36708
|
-
});
|
|
36709
|
-
client.notify("initialized", {});
|
|
36710
|
-
})(),
|
|
36711
|
-
timeout
|
|
36712
|
-
]);
|
|
36713
|
-
return await Promise.race([client.request(method, params), timeout]);
|
|
36714
|
-
} finally {
|
|
36715
|
-
if (timer) clearTimeout(timer);
|
|
36716
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
36717
|
-
}
|
|
36718
|
-
}
|
|
36719
|
-
var CodexHistoryReader = class {
|
|
36720
|
-
deps;
|
|
36721
|
-
constructor(deps = {}) {
|
|
36722
|
-
this.deps = deps;
|
|
36723
|
-
}
|
|
36724
|
-
// v1 先返回 []:projects/list 非 session-scoped、不知 tool,跨-tool 项目浏览器合并排后续。
|
|
36725
|
-
// codex 旧会话仍能经 clawd 活跃列表(session:list, tool-agnostic) + read 打开。
|
|
36726
|
-
async listProjects() {
|
|
36727
|
-
return [];
|
|
36728
|
-
}
|
|
36729
|
-
async listSessions(args) {
|
|
36730
|
-
const res = rec2(
|
|
36731
|
-
await queryCodexAppServer(
|
|
36732
|
-
args.projectPath,
|
|
36733
|
-
"thread/list",
|
|
36734
|
-
{
|
|
36735
|
-
limit: 100,
|
|
36736
|
-
sortKey: "updated_at",
|
|
36737
|
-
sortDirection: "desc",
|
|
36738
|
-
archived: false,
|
|
36739
|
-
cwd: args.projectPath,
|
|
36740
|
-
useStateDbOnly: true
|
|
36741
|
-
},
|
|
36742
|
-
this.deps
|
|
36743
|
-
)
|
|
36744
|
-
);
|
|
36745
|
-
const data = res && Array.isArray(res.data) ? res.data : [];
|
|
36746
|
-
const out = [];
|
|
36747
|
-
for (const entry of data) {
|
|
36748
|
-
const e = rec2(entry);
|
|
36749
|
-
const id = e && str2(e.id);
|
|
36750
|
-
if (!e || !id) continue;
|
|
36751
|
-
const updatedAtMs = Math.round((num2(e.updatedAt) ?? 0) * 1e3);
|
|
36752
|
-
out.push({
|
|
36753
|
-
toolSessionId: id,
|
|
36754
|
-
summary: str2(e.preview) || "(\u7A7A\u4F1A\u8BDD)",
|
|
36755
|
-
messageCount: 0,
|
|
36756
|
-
// thread/list 不提供条数;活跃/read 时才知
|
|
36757
|
-
updatedAt: new Date(updatedAtMs).toISOString()
|
|
36758
|
-
});
|
|
36759
|
-
}
|
|
36760
|
-
return out;
|
|
36761
|
-
}
|
|
36762
|
-
async read(args) {
|
|
36763
|
-
const res = rec2(
|
|
36764
|
-
await queryCodexAppServer(
|
|
36765
|
-
args.cwd,
|
|
36766
|
-
"thread/read",
|
|
36767
|
-
{ threadId: args.toolSessionId, includeTurns: true },
|
|
36768
|
-
this.deps
|
|
36769
|
-
)
|
|
36770
|
-
);
|
|
36771
|
-
const thread = res && rec2(res.thread);
|
|
36772
|
-
const turns = thread && Array.isArray(thread.turns) ? thread.turns : [];
|
|
36773
|
-
const messages = [];
|
|
36774
|
-
for (const turn of turns) {
|
|
36775
|
-
const t = rec2(turn);
|
|
36776
|
-
const items = t && Array.isArray(t.items) ? t.items : [];
|
|
36777
|
-
for (const item of items) messages.push(...threadItemToHistoryMessages(item));
|
|
36778
|
-
}
|
|
36779
|
-
const total = messages.length;
|
|
36780
|
-
const limit = args.limit ?? total;
|
|
36781
|
-
const offset = typeof args.offset === "number" ? Math.min(Math.max(0, args.offset), total) : Math.max(0, total - limit);
|
|
36782
|
-
return { messages: messages.slice(offset, offset + limit), total, offset };
|
|
36783
|
-
}
|
|
36784
|
-
// codex 无 sidechain 子 agent / file-history-snapshot → 全 stub 空(对齐 claude-history 同方法空返回)
|
|
36785
|
-
async listSubagents() {
|
|
36786
|
-
return [];
|
|
36787
|
-
}
|
|
36788
|
-
async readSubagent() {
|
|
36789
|
-
return { messages: [] };
|
|
36790
|
-
}
|
|
36791
|
-
computeRewindDiff() {
|
|
36792
|
-
return { canRewind: false, files: [], totalInsertions: 0, totalDeletions: 0 };
|
|
36793
|
-
}
|
|
36794
|
-
listRewindableUserMessageIds() {
|
|
36795
|
-
return [];
|
|
36796
|
-
}
|
|
36797
|
-
};
|
|
36798
|
-
|
|
36799
|
-
// src/tools/codex-skills.ts
|
|
36800
|
-
var import_node_child_process6 = require("child_process");
|
|
36801
|
-
var DEFAULT_TIMEOUT_MS2 = 8e3;
|
|
36802
|
-
function str3(v2) {
|
|
36803
|
-
return typeof v2 === "string" ? v2 : void 0;
|
|
36804
|
-
}
|
|
36805
|
-
function mapSkillsListResponse(res) {
|
|
36806
|
-
const data = res?.data;
|
|
36807
|
-
if (!Array.isArray(data)) return [];
|
|
36808
|
-
const out = [];
|
|
36809
|
-
for (const entry of data) {
|
|
36810
|
-
const skills = entry?.skills;
|
|
36811
|
-
if (!Array.isArray(skills)) continue;
|
|
36812
|
-
for (const s of skills) {
|
|
36813
|
-
const r = s ?? {};
|
|
36814
|
-
const name = str3(r.name);
|
|
36815
|
-
if (!name) continue;
|
|
36816
|
-
const path59 = str3(r.path);
|
|
36817
|
-
const description = str3(r.description);
|
|
36818
|
-
const isPlugin = name.includes(":");
|
|
36819
|
-
out.push({
|
|
36820
|
-
name,
|
|
36821
|
-
source: isPlugin ? "plugin" : "project",
|
|
36822
|
-
...path59 ? { path: path59 } : {},
|
|
36823
|
-
...description ? { description } : {},
|
|
36824
|
-
...isPlugin ? { plugin: name.split(":")[0] } : {}
|
|
36825
|
-
});
|
|
36826
|
-
}
|
|
36827
|
-
}
|
|
36828
|
-
return out;
|
|
36829
|
-
}
|
|
36830
|
-
async function listCodexSkills(cwd, deps = {}) {
|
|
36831
|
-
const cmd = process.env.CODEX_BIN ?? "codex";
|
|
36832
|
-
const args = ["app-server", "--listen", "stdio://"];
|
|
36833
|
-
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"] });
|
|
36834
|
-
const client = new CodexAppServerClient(proc, {});
|
|
36835
|
-
const timeoutMs = deps.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
36836
|
-
let timer;
|
|
36837
|
-
const timeout = new Promise((_2, reject) => {
|
|
36838
|
-
timer = setTimeout(() => reject(new Error(`codex app-server skills/list timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
36839
|
-
});
|
|
36840
|
-
try {
|
|
36841
|
-
await Promise.race([
|
|
36842
|
-
(async () => {
|
|
36843
|
-
await client.request("initialize", {
|
|
36844
|
-
clientInfo: { name: "clawd", title: "clawd", version: "0" },
|
|
36845
|
-
capabilities: null
|
|
36846
|
-
});
|
|
36847
|
-
client.notify("initialized", {});
|
|
36848
|
-
})(),
|
|
36849
|
-
timeout
|
|
36850
|
-
]);
|
|
36851
|
-
const res = await Promise.race([client.request("skills/list", { cwds: [cwd] }), timeout]);
|
|
36852
|
-
return mapSkillsListResponse(res);
|
|
36853
|
-
} finally {
|
|
36854
|
-
if (timer) clearTimeout(timer);
|
|
36855
|
-
if (proc.exitCode === null && proc.signalCode === null) proc.kill("SIGTERM");
|
|
36856
|
-
}
|
|
36857
|
-
}
|
|
36858
|
-
|
|
36859
36151
|
// src/workspace/browser.ts
|
|
36860
|
-
var
|
|
36152
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
36861
36153
|
var import_node_os6 = __toESM(require("os"), 1);
|
|
36862
36154
|
var import_node_path11 = __toESM(require("path"), 1);
|
|
36863
36155
|
init_protocol();
|
|
@@ -36873,7 +36165,7 @@ function resolveInsideCwd(cwd, subpath) {
|
|
|
36873
36165
|
}
|
|
36874
36166
|
function ensureCwd(cwd) {
|
|
36875
36167
|
try {
|
|
36876
|
-
const stat =
|
|
36168
|
+
const stat = import_node_fs11.default.statSync(cwd);
|
|
36877
36169
|
if (!stat.isDirectory()) {
|
|
36878
36170
|
throw new ClawdError(ERROR_CODES.INVALID_CWD, `not a directory: ${cwd}`);
|
|
36879
36171
|
}
|
|
@@ -36887,7 +36179,7 @@ var WorkspaceBrowser = class {
|
|
|
36887
36179
|
const cwd = args.cwd && args.cwd.length > 0 ? args.cwd : import_node_os6.default.homedir();
|
|
36888
36180
|
ensureCwd(cwd);
|
|
36889
36181
|
const full = resolveInsideCwd(cwd, args.path);
|
|
36890
|
-
const dirents =
|
|
36182
|
+
const dirents = import_node_fs11.default.readdirSync(full, { withFileTypes: true });
|
|
36891
36183
|
const entries = [];
|
|
36892
36184
|
for (const d of dirents) {
|
|
36893
36185
|
if (!args.showHidden && d.name.startsWith(".")) continue;
|
|
@@ -36897,7 +36189,7 @@ var WorkspaceBrowser = class {
|
|
|
36897
36189
|
mtime: ""
|
|
36898
36190
|
};
|
|
36899
36191
|
try {
|
|
36900
|
-
const st =
|
|
36192
|
+
const st = import_node_fs11.default.statSync(import_node_path11.default.join(full, d.name));
|
|
36901
36193
|
entry.mtime = new Date(st.mtimeMs).toISOString();
|
|
36902
36194
|
if (d.isFile()) entry.size = st.size;
|
|
36903
36195
|
} catch {
|
|
@@ -36913,14 +36205,14 @@ var WorkspaceBrowser = class {
|
|
|
36913
36205
|
read(args) {
|
|
36914
36206
|
ensureCwd(args.cwd);
|
|
36915
36207
|
const full = resolveInsideCwd(args.cwd, args.path);
|
|
36916
|
-
const st =
|
|
36208
|
+
const st = import_node_fs11.default.statSync(full);
|
|
36917
36209
|
if (!st.isFile()) {
|
|
36918
36210
|
throw new ClawdError(ERROR_CODES.INVALID_PATH, `not a file: ${args.path}`);
|
|
36919
36211
|
}
|
|
36920
36212
|
if (st.size > MAX_FILE_BYTES) {
|
|
36921
36213
|
throw new ClawdError(ERROR_CODES.FILE_TOO_LARGE, `file > ${MAX_FILE_BYTES} bytes`);
|
|
36922
36214
|
}
|
|
36923
|
-
const buf =
|
|
36215
|
+
const buf = import_node_fs11.default.readFileSync(full);
|
|
36924
36216
|
const isBinary = buf.includes(0);
|
|
36925
36217
|
if (isBinary) {
|
|
36926
36218
|
return {
|
|
@@ -36942,20 +36234,20 @@ var WorkspaceBrowser = class {
|
|
|
36942
36234
|
};
|
|
36943
36235
|
|
|
36944
36236
|
// src/skills/agents-scanner.ts
|
|
36945
|
-
var
|
|
36237
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
36946
36238
|
var import_node_os7 = __toESM(require("os"), 1);
|
|
36947
36239
|
var import_node_path12 = __toESM(require("path"), 1);
|
|
36948
36240
|
var DEFAULT_POLICY_DIR_DARWIN = "/Library/Application Support/ClaudeCode/.claude/agents";
|
|
36949
36241
|
function isDirLikeSync2(p2) {
|
|
36950
36242
|
try {
|
|
36951
|
-
return
|
|
36243
|
+
return import_node_fs12.default.statSync(p2).isDirectory();
|
|
36952
36244
|
} catch {
|
|
36953
36245
|
return false;
|
|
36954
36246
|
}
|
|
36955
36247
|
}
|
|
36956
36248
|
function fileExistsSync(p2) {
|
|
36957
36249
|
try {
|
|
36958
|
-
return
|
|
36250
|
+
return import_node_fs12.default.statSync(p2).isFile();
|
|
36959
36251
|
} catch {
|
|
36960
36252
|
return false;
|
|
36961
36253
|
}
|
|
@@ -36963,7 +36255,7 @@ function fileExistsSync(p2) {
|
|
|
36963
36255
|
function parseAgentFile(filePath) {
|
|
36964
36256
|
let content;
|
|
36965
36257
|
try {
|
|
36966
|
-
content =
|
|
36258
|
+
content = import_node_fs12.default.readFileSync(filePath, "utf8");
|
|
36967
36259
|
} catch {
|
|
36968
36260
|
return {};
|
|
36969
36261
|
}
|
|
@@ -36976,7 +36268,7 @@ function parseAgentFile(filePath) {
|
|
|
36976
36268
|
function scanAgentsDir(dir, source, seen, out) {
|
|
36977
36269
|
let entries;
|
|
36978
36270
|
try {
|
|
36979
|
-
entries =
|
|
36271
|
+
entries = import_node_fs12.default.readdirSync(dir, { withFileTypes: true });
|
|
36980
36272
|
} catch {
|
|
36981
36273
|
return;
|
|
36982
36274
|
}
|
|
@@ -37003,7 +36295,7 @@ function scanPluginAgentsTree(root, pluginName, seen, out) {
|
|
|
37003
36295
|
function walk2(dir, namespaces) {
|
|
37004
36296
|
let entries;
|
|
37005
36297
|
try {
|
|
37006
|
-
entries =
|
|
36298
|
+
entries = import_node_fs12.default.readdirSync(dir, { withFileTypes: true });
|
|
37007
36299
|
} catch {
|
|
37008
36300
|
return;
|
|
37009
36301
|
}
|
|
@@ -37039,7 +36331,7 @@ function readInstalledPlugins2(home) {
|
|
|
37039
36331
|
let raw = null;
|
|
37040
36332
|
for (const candidate of [v2, v1]) {
|
|
37041
36333
|
try {
|
|
37042
|
-
raw =
|
|
36334
|
+
raw = import_node_fs12.default.readFileSync(candidate, "utf8");
|
|
37043
36335
|
break;
|
|
37044
36336
|
} catch {
|
|
37045
36337
|
}
|
|
@@ -37070,7 +36362,7 @@ function walkUpProjectAgentsDirs(startCwd, home, seen, out) {
|
|
|
37070
36362
|
scanAgentsDir(import_node_path12.default.join(cur, ".claude", "agents"), "project", seen, out);
|
|
37071
36363
|
let hasGit = false;
|
|
37072
36364
|
try {
|
|
37073
|
-
hasGit =
|
|
36365
|
+
hasGit = import_node_fs12.default.existsSync(import_node_path12.default.join(cur, ".git"));
|
|
37074
36366
|
} catch {
|
|
37075
36367
|
}
|
|
37076
36368
|
if (hasGit) return;
|
|
@@ -37133,13 +36425,13 @@ var AgentsScanner = class {
|
|
|
37133
36425
|
};
|
|
37134
36426
|
|
|
37135
36427
|
// src/observer/session-observer.ts
|
|
37136
|
-
var
|
|
36428
|
+
var import_node_fs14 = __toESM(require("fs"), 1);
|
|
37137
36429
|
var import_node_os9 = __toESM(require("os"), 1);
|
|
37138
36430
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
37139
36431
|
init_claude_history();
|
|
37140
36432
|
|
|
37141
36433
|
// src/observer/subagent-meta-observer.ts
|
|
37142
|
-
var
|
|
36434
|
+
var import_node_fs13 = __toESM(require("fs"), 1);
|
|
37143
36435
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
37144
36436
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
37145
36437
|
init_claude_history();
|
|
@@ -37184,7 +36476,7 @@ var SubagentMetaObserver = class {
|
|
|
37184
36476
|
attachWatcher(w2) {
|
|
37185
36477
|
if (w2.watcher) return;
|
|
37186
36478
|
try {
|
|
37187
|
-
w2.watcher =
|
|
36479
|
+
w2.watcher = import_node_fs13.default.watch(w2.dirPath, { persistent: false }, (_evt, name) => {
|
|
37188
36480
|
if (!name) return;
|
|
37189
36481
|
const m2 = META_RE.exec(String(name));
|
|
37190
36482
|
if (!m2) return;
|
|
@@ -37196,7 +36488,7 @@ var SubagentMetaObserver = class {
|
|
|
37196
36488
|
scan(w2) {
|
|
37197
36489
|
let entries;
|
|
37198
36490
|
try {
|
|
37199
|
-
entries =
|
|
36491
|
+
entries = import_node_fs13.default.readdirSync(w2.dirPath);
|
|
37200
36492
|
} catch {
|
|
37201
36493
|
return;
|
|
37202
36494
|
}
|
|
@@ -37213,7 +36505,7 @@ var SubagentMetaObserver = class {
|
|
|
37213
36505
|
const file = import_node_path13.default.join(w2.dirPath, name);
|
|
37214
36506
|
let raw;
|
|
37215
36507
|
try {
|
|
37216
|
-
raw =
|
|
36508
|
+
raw = import_node_fs13.default.readFileSync(file, "utf8");
|
|
37217
36509
|
} catch {
|
|
37218
36510
|
return;
|
|
37219
36511
|
}
|
|
@@ -37277,7 +36569,7 @@ var SessionObserver = class {
|
|
|
37277
36569
|
const filePath = this.resolveJsonlPath(args.cwd, args.toolSessionId, args.jsonlPath);
|
|
37278
36570
|
let size = 0;
|
|
37279
36571
|
try {
|
|
37280
|
-
size =
|
|
36572
|
+
size = import_node_fs14.default.statSync(filePath).size;
|
|
37281
36573
|
} catch {
|
|
37282
36574
|
}
|
|
37283
36575
|
const w2 = {
|
|
@@ -37291,10 +36583,10 @@ var SessionObserver = class {
|
|
|
37291
36583
|
prevIsRejectSentinel: false
|
|
37292
36584
|
};
|
|
37293
36585
|
try {
|
|
37294
|
-
|
|
36586
|
+
import_node_fs14.default.mkdirSync(import_node_path14.default.dirname(filePath), { recursive: true });
|
|
37295
36587
|
} catch {
|
|
37296
36588
|
}
|
|
37297
|
-
w2.watcher =
|
|
36589
|
+
w2.watcher = import_node_fs14.default.watch(import_node_path14.default.dirname(filePath), { persistent: false }, (_event, changedName) => {
|
|
37298
36590
|
if (!changedName || !filePath.endsWith(changedName)) return;
|
|
37299
36591
|
this.poll(w2);
|
|
37300
36592
|
});
|
|
@@ -37317,7 +36609,7 @@ var SessionObserver = class {
|
|
|
37317
36609
|
// 异常静默吞,不阻塞 watcher 启动
|
|
37318
36610
|
hydrateMetaTail(w2, maxLines = 200) {
|
|
37319
36611
|
try {
|
|
37320
|
-
const raw =
|
|
36612
|
+
const raw = import_node_fs14.default.readFileSync(w2.filePath, "utf8");
|
|
37321
36613
|
if (!raw) return;
|
|
37322
36614
|
const allLines = raw.split("\n").filter((l) => l.trim().length > 0);
|
|
37323
36615
|
if (allLines.length === 0) return;
|
|
@@ -37341,7 +36633,7 @@ var SessionObserver = class {
|
|
|
37341
36633
|
poll(w2) {
|
|
37342
36634
|
let size = 0;
|
|
37343
36635
|
try {
|
|
37344
|
-
size =
|
|
36636
|
+
size = import_node_fs14.default.statSync(w2.filePath).size;
|
|
37345
36637
|
} catch {
|
|
37346
36638
|
return;
|
|
37347
36639
|
}
|
|
@@ -37350,11 +36642,11 @@ var SessionObserver = class {
|
|
|
37350
36642
|
w2.buf = "";
|
|
37351
36643
|
}
|
|
37352
36644
|
if (size === w2.lastSize) return;
|
|
37353
|
-
const fd =
|
|
36645
|
+
const fd = import_node_fs14.default.openSync(w2.filePath, "r");
|
|
37354
36646
|
try {
|
|
37355
36647
|
const len = size - w2.lastSize;
|
|
37356
36648
|
const buf = Buffer.alloc(len);
|
|
37357
|
-
|
|
36649
|
+
import_node_fs14.default.readSync(fd, buf, 0, len, w2.lastSize);
|
|
37358
36650
|
w2.lastSize = size;
|
|
37359
36651
|
w2.buf += buf.toString("utf8");
|
|
37360
36652
|
let newlineIndex;
|
|
@@ -37377,7 +36669,7 @@ var SessionObserver = class {
|
|
|
37377
36669
|
}
|
|
37378
36670
|
}
|
|
37379
36671
|
} finally {
|
|
37380
|
-
|
|
36672
|
+
import_node_fs14.default.closeSync(fd);
|
|
37381
36673
|
}
|
|
37382
36674
|
}
|
|
37383
36675
|
// 解析 JSONL 单行:仅当是主链 user 文本行(非 sidechain / 非 sub-agent / message.role='user'
|
|
@@ -38100,14 +37392,14 @@ async function authenticate(token, deps) {
|
|
|
38100
37392
|
}
|
|
38101
37393
|
|
|
38102
37394
|
// src/permission/capability-store.ts
|
|
38103
|
-
var
|
|
37395
|
+
var fs17 = __toESM(require("fs"), 1);
|
|
38104
37396
|
var path19 = __toESM(require("path"), 1);
|
|
38105
37397
|
var CAPABILITIES_FILE_NAME = "capabilities.json";
|
|
38106
37398
|
var FILE_VERSION = 1;
|
|
38107
37399
|
var CapabilityStore = class {
|
|
38108
37400
|
constructor(dataDir) {
|
|
38109
37401
|
this.dataDir = dataDir;
|
|
38110
|
-
|
|
37402
|
+
fs17.mkdirSync(dataDir, { recursive: true });
|
|
38111
37403
|
this.cache = this.readFromDisk();
|
|
38112
37404
|
}
|
|
38113
37405
|
dataDir;
|
|
@@ -38137,7 +37429,7 @@ var CapabilityStore = class {
|
|
|
38137
37429
|
const file = this.filePath();
|
|
38138
37430
|
let raw;
|
|
38139
37431
|
try {
|
|
38140
|
-
raw =
|
|
37432
|
+
raw = fs17.readFileSync(file, "utf8");
|
|
38141
37433
|
} catch (err) {
|
|
38142
37434
|
if (err?.code === "ENOENT") return [];
|
|
38143
37435
|
return [];
|
|
@@ -38165,10 +37457,10 @@ var CapabilityStore = class {
|
|
|
38165
37457
|
}
|
|
38166
37458
|
atomicWrite(file, content) {
|
|
38167
37459
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
38168
|
-
|
|
38169
|
-
|
|
37460
|
+
fs17.writeFileSync(tmp, content, { mode: 384 });
|
|
37461
|
+
fs17.renameSync(tmp, file);
|
|
38170
37462
|
try {
|
|
38171
|
-
|
|
37463
|
+
fs17.chmodSync(file, 384);
|
|
38172
37464
|
} catch {
|
|
38173
37465
|
}
|
|
38174
37466
|
}
|
|
@@ -38261,14 +37553,14 @@ var CapabilityManager = class {
|
|
|
38261
37553
|
};
|
|
38262
37554
|
|
|
38263
37555
|
// src/permission/cleanup.ts
|
|
38264
|
-
var
|
|
37556
|
+
var fs18 = __toESM(require("fs"), 1);
|
|
38265
37557
|
function cleanupGuestSessionsForCapability(cap, factory) {
|
|
38266
37558
|
const removed = [];
|
|
38267
37559
|
for (const g2 of cap.grants) {
|
|
38268
37560
|
if (g2.resource.type !== "persona") continue;
|
|
38269
37561
|
const dir = factory.vmGuestRoot(g2.resource.id, cap.id);
|
|
38270
37562
|
try {
|
|
38271
|
-
|
|
37563
|
+
fs18.rmSync(dir, { recursive: true, force: true });
|
|
38272
37564
|
removed.push(dir);
|
|
38273
37565
|
} catch {
|
|
38274
37566
|
}
|
|
@@ -38277,13 +37569,13 @@ function cleanupGuestSessionsForCapability(cap, factory) {
|
|
|
38277
37569
|
}
|
|
38278
37570
|
|
|
38279
37571
|
// src/inbox/inbox-store.ts
|
|
38280
|
-
var
|
|
37572
|
+
var fs19 = __toESM(require("fs"), 1);
|
|
38281
37573
|
var path20 = __toESM(require("path"), 1);
|
|
38282
37574
|
var INBOX_SUBDIR = "inbox";
|
|
38283
37575
|
var InboxStore = class {
|
|
38284
37576
|
constructor(dataDir) {
|
|
38285
37577
|
this.dataDir = dataDir;
|
|
38286
|
-
|
|
37578
|
+
fs19.mkdirSync(this.dirPath(), { recursive: true });
|
|
38287
37579
|
}
|
|
38288
37580
|
dataDir;
|
|
38289
37581
|
/**
|
|
@@ -38295,7 +37587,7 @@ var InboxStore = class {
|
|
|
38295
37587
|
const file = this.filePath(peerDeviceId);
|
|
38296
37588
|
let raw;
|
|
38297
37589
|
try {
|
|
38298
|
-
raw =
|
|
37590
|
+
raw = fs19.readFileSync(file, "utf8");
|
|
38299
37591
|
} catch (err) {
|
|
38300
37592
|
if (err?.code === "ENOENT") return [];
|
|
38301
37593
|
return [];
|
|
@@ -38311,7 +37603,7 @@ var InboxStore = class {
|
|
|
38311
37603
|
const dir = this.dirPath();
|
|
38312
37604
|
let entries;
|
|
38313
37605
|
try {
|
|
38314
|
-
entries =
|
|
37606
|
+
entries = fs19.readdirSync(dir);
|
|
38315
37607
|
} catch (err) {
|
|
38316
37608
|
if (err?.code === "ENOENT") return [];
|
|
38317
37609
|
return [];
|
|
@@ -38327,9 +37619,9 @@ var InboxStore = class {
|
|
|
38327
37619
|
if (existing.some((m2) => m2.id === message.id)) return;
|
|
38328
37620
|
const file = this.filePath(message.peerDeviceId);
|
|
38329
37621
|
const line = JSON.stringify(message) + "\n";
|
|
38330
|
-
|
|
37622
|
+
fs19.appendFileSync(file, line, { mode: 384 });
|
|
38331
37623
|
try {
|
|
38332
|
-
|
|
37624
|
+
fs19.chmodSync(file, 384);
|
|
38333
37625
|
} catch {
|
|
38334
37626
|
}
|
|
38335
37627
|
}
|
|
@@ -38359,7 +37651,7 @@ var InboxStore = class {
|
|
|
38359
37651
|
removeByPeerDeviceId(peerDeviceId) {
|
|
38360
37652
|
const file = this.filePath(peerDeviceId);
|
|
38361
37653
|
try {
|
|
38362
|
-
|
|
37654
|
+
fs19.unlinkSync(file);
|
|
38363
37655
|
} catch (err) {
|
|
38364
37656
|
if (err?.code === "ENOENT") return;
|
|
38365
37657
|
}
|
|
@@ -38368,10 +37660,10 @@ var InboxStore = class {
|
|
|
38368
37660
|
const file = this.filePath(peerDeviceId);
|
|
38369
37661
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
38370
37662
|
const content = messages.map((m2) => JSON.stringify(m2)).join("\n") + (messages.length > 0 ? "\n" : "");
|
|
38371
|
-
|
|
38372
|
-
|
|
37663
|
+
fs19.writeFileSync(tmp, content, { mode: 384 });
|
|
37664
|
+
fs19.renameSync(tmp, file);
|
|
38373
37665
|
try {
|
|
38374
|
-
|
|
37666
|
+
fs19.chmodSync(file, 384);
|
|
38375
37667
|
} catch {
|
|
38376
37668
|
}
|
|
38377
37669
|
}
|
|
@@ -38466,7 +37758,7 @@ var InboxManager = class {
|
|
|
38466
37758
|
};
|
|
38467
37759
|
|
|
38468
37760
|
// src/state/contact-store.ts
|
|
38469
|
-
var
|
|
37761
|
+
var fs20 = __toESM(require("fs"), 1);
|
|
38470
37762
|
var path21 = __toESM(require("path"), 1);
|
|
38471
37763
|
var FILE_NAME = "contacts.json";
|
|
38472
37764
|
var ContactStore = class {
|
|
@@ -38480,7 +37772,7 @@ var ContactStore = class {
|
|
|
38480
37772
|
const file = path21.join(this.dataDir, FILE_NAME);
|
|
38481
37773
|
let raw;
|
|
38482
37774
|
try {
|
|
38483
|
-
raw =
|
|
37775
|
+
raw = fs20.readFileSync(file, "utf8");
|
|
38484
37776
|
} catch (err) {
|
|
38485
37777
|
if (err?.code !== "ENOENT") this.renameBak(file);
|
|
38486
37778
|
return;
|
|
@@ -38530,13 +37822,13 @@ var ContactStore = class {
|
|
|
38530
37822
|
null,
|
|
38531
37823
|
2
|
|
38532
37824
|
);
|
|
38533
|
-
|
|
38534
|
-
|
|
38535
|
-
|
|
37825
|
+
fs20.mkdirSync(this.dataDir, { recursive: true });
|
|
37826
|
+
fs20.writeFileSync(tmp, content, { mode: 384 });
|
|
37827
|
+
fs20.renameSync(tmp, file);
|
|
38536
37828
|
}
|
|
38537
37829
|
renameBak(file) {
|
|
38538
37830
|
try {
|
|
38539
|
-
|
|
37831
|
+
fs20.renameSync(file, `${file}.bak`);
|
|
38540
37832
|
} catch {
|
|
38541
37833
|
}
|
|
38542
37834
|
}
|
|
@@ -38671,7 +37963,7 @@ async function autoReverseContact(args) {
|
|
|
38671
37963
|
}
|
|
38672
37964
|
|
|
38673
37965
|
// src/migrations/2026-05-20-flatten-sessions.ts
|
|
38674
|
-
var
|
|
37966
|
+
var fs21 = __toESM(require("fs"), 1);
|
|
38675
37967
|
var path22 = __toESM(require("path"), 1);
|
|
38676
37968
|
var MIGRATION_FLAG_NAME = ".migration.v1.done";
|
|
38677
37969
|
function migrateFlattenSessions(opts) {
|
|
@@ -38691,7 +37983,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38691
37983
|
if (!entry.endsWith(".json")) continue;
|
|
38692
37984
|
const src = path22.join(defaultDir, entry);
|
|
38693
37985
|
const dst = path22.join(sessionsDir, entry);
|
|
38694
|
-
|
|
37986
|
+
fs21.renameSync(src, dst);
|
|
38695
37987
|
movedBare += 1;
|
|
38696
37988
|
}
|
|
38697
37989
|
rmdirIfEmpty(defaultDir);
|
|
@@ -38703,10 +37995,10 @@ function migrateFlattenSessions(opts) {
|
|
|
38703
37995
|
const ownerSrc = path22.join(personaDir, "owner");
|
|
38704
37996
|
if (existsSync3(ownerSrc) && isDir(ownerSrc)) {
|
|
38705
37997
|
const ownerDst = path22.join(dataDir, "personas", pid, ".clawd", "sessions", "owner");
|
|
38706
|
-
|
|
37998
|
+
fs21.mkdirSync(ownerDst, { recursive: true });
|
|
38707
37999
|
for (const file of readdirSafe(ownerSrc)) {
|
|
38708
38000
|
if (!file.endsWith(".json")) continue;
|
|
38709
|
-
|
|
38001
|
+
fs21.renameSync(path22.join(ownerSrc, file), path22.join(ownerDst, file));
|
|
38710
38002
|
movedVmOwner += 1;
|
|
38711
38003
|
}
|
|
38712
38004
|
rmdirIfEmpty(ownerSrc);
|
|
@@ -38714,18 +38006,18 @@ function migrateFlattenSessions(opts) {
|
|
|
38714
38006
|
const listenerSrc = path22.join(personaDir, "listener");
|
|
38715
38007
|
if (existsSync3(listenerSrc) && isDir(listenerSrc)) {
|
|
38716
38008
|
const archiveDst = path22.join(dataDir, ".legacy", `listener-${pid}`);
|
|
38717
|
-
|
|
38009
|
+
fs21.mkdirSync(archiveDst, { recursive: true });
|
|
38718
38010
|
for (const file of readdirSafe(listenerSrc)) {
|
|
38719
38011
|
if (!file.endsWith(".json")) continue;
|
|
38720
|
-
|
|
38012
|
+
fs21.renameSync(path22.join(listenerSrc, file), path22.join(archiveDst, file));
|
|
38721
38013
|
archivedListener += 1;
|
|
38722
38014
|
}
|
|
38723
38015
|
rmdirIfEmpty(listenerSrc);
|
|
38724
38016
|
}
|
|
38725
38017
|
rmdirIfEmpty(personaDir);
|
|
38726
38018
|
}
|
|
38727
|
-
|
|
38728
|
-
|
|
38019
|
+
fs21.mkdirSync(sessionsDir, { recursive: true });
|
|
38020
|
+
fs21.writeFileSync(flagPath, JSON.stringify({ migratedAt: now() }, null, 2));
|
|
38729
38021
|
return {
|
|
38730
38022
|
skipped: false,
|
|
38731
38023
|
flagWritten: true,
|
|
@@ -38736,7 +38028,7 @@ function migrateFlattenSessions(opts) {
|
|
|
38736
38028
|
}
|
|
38737
38029
|
function existsSync3(p2) {
|
|
38738
38030
|
try {
|
|
38739
|
-
|
|
38031
|
+
fs21.statSync(p2);
|
|
38740
38032
|
return true;
|
|
38741
38033
|
} catch {
|
|
38742
38034
|
return false;
|
|
@@ -38744,27 +38036,27 @@ function existsSync3(p2) {
|
|
|
38744
38036
|
}
|
|
38745
38037
|
function isDir(p2) {
|
|
38746
38038
|
try {
|
|
38747
|
-
return
|
|
38039
|
+
return fs21.statSync(p2).isDirectory();
|
|
38748
38040
|
} catch {
|
|
38749
38041
|
return false;
|
|
38750
38042
|
}
|
|
38751
38043
|
}
|
|
38752
38044
|
function readdirSafe(p2) {
|
|
38753
38045
|
try {
|
|
38754
|
-
return
|
|
38046
|
+
return fs21.readdirSync(p2);
|
|
38755
38047
|
} catch {
|
|
38756
38048
|
return [];
|
|
38757
38049
|
}
|
|
38758
38050
|
}
|
|
38759
38051
|
function rmdirIfEmpty(p2) {
|
|
38760
38052
|
try {
|
|
38761
|
-
|
|
38053
|
+
fs21.rmdirSync(p2);
|
|
38762
38054
|
} catch {
|
|
38763
38055
|
}
|
|
38764
38056
|
}
|
|
38765
38057
|
|
|
38766
38058
|
// src/transport/http-router.ts
|
|
38767
|
-
var
|
|
38059
|
+
var import_node_fs16 = __toESM(require("fs"), 1);
|
|
38768
38060
|
var import_node_path18 = __toESM(require("path"), 1);
|
|
38769
38061
|
|
|
38770
38062
|
// src/attachment/mime.ts
|
|
@@ -38944,7 +38236,7 @@ function verifySignedUrl(secret, absPath, eRaw, s, now = Date.now) {
|
|
|
38944
38236
|
}
|
|
38945
38237
|
|
|
38946
38238
|
// src/attachment/upload.ts
|
|
38947
|
-
var
|
|
38239
|
+
var import_node_fs15 = __toESM(require("fs"), 1);
|
|
38948
38240
|
var import_node_path16 = __toESM(require("path"), 1);
|
|
38949
38241
|
var import_node_crypto5 = __toESM(require("crypto"), 1);
|
|
38950
38242
|
var import_promises = require("stream/promises");
|
|
@@ -38966,7 +38258,7 @@ async function writeUploadedAttachment(args) {
|
|
|
38966
38258
|
assertValidFileName(args.fileName);
|
|
38967
38259
|
const attachmentsRoot = import_node_path16.default.join(args.sessionDir, ".attachments");
|
|
38968
38260
|
try {
|
|
38969
|
-
|
|
38261
|
+
import_node_fs15.default.mkdirSync(attachmentsRoot, { recursive: true });
|
|
38970
38262
|
} catch (err) {
|
|
38971
38263
|
throw new UploadError("STORAGE_ERROR", `mkdir failed: ${err.message}`);
|
|
38972
38264
|
}
|
|
@@ -38987,18 +38279,18 @@ async function writeUploadedAttachment(args) {
|
|
|
38987
38279
|
yield buf;
|
|
38988
38280
|
}
|
|
38989
38281
|
},
|
|
38990
|
-
|
|
38282
|
+
import_node_fs15.default.createWriteStream(tmpPath, { mode: 384 })
|
|
38991
38283
|
);
|
|
38992
38284
|
} catch (err) {
|
|
38993
38285
|
try {
|
|
38994
|
-
|
|
38286
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
38995
38287
|
} catch {
|
|
38996
38288
|
}
|
|
38997
38289
|
throw new UploadError("STORAGE_ERROR", `write failed: ${err.message}`);
|
|
38998
38290
|
}
|
|
38999
38291
|
if (actualSize !== args.contentLength) {
|
|
39000
38292
|
try {
|
|
39001
|
-
|
|
38293
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39002
38294
|
} catch {
|
|
39003
38295
|
}
|
|
39004
38296
|
throw new UploadError(
|
|
@@ -39011,24 +38303,24 @@ async function writeUploadedAttachment(args) {
|
|
|
39011
38303
|
let finalFileName;
|
|
39012
38304
|
let hashDirExists = false;
|
|
39013
38305
|
try {
|
|
39014
|
-
hashDirExists =
|
|
38306
|
+
hashDirExists = import_node_fs15.default.statSync(hashDir).isDirectory();
|
|
39015
38307
|
} catch {
|
|
39016
38308
|
}
|
|
39017
38309
|
if (hashDirExists) {
|
|
39018
|
-
const existing =
|
|
38310
|
+
const existing = import_node_fs15.default.readdirSync(hashDir).filter((n) => !n.startsWith("."));
|
|
39019
38311
|
finalFileName = existing[0] ?? args.fileName;
|
|
39020
38312
|
try {
|
|
39021
|
-
|
|
38313
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39022
38314
|
} catch {
|
|
39023
38315
|
}
|
|
39024
38316
|
} else {
|
|
39025
38317
|
try {
|
|
39026
|
-
|
|
38318
|
+
import_node_fs15.default.mkdirSync(hashDir, { recursive: true });
|
|
39027
38319
|
finalFileName = args.fileName;
|
|
39028
|
-
|
|
38320
|
+
import_node_fs15.default.renameSync(tmpPath, import_node_path16.default.join(hashDir, finalFileName));
|
|
39029
38321
|
} catch (err) {
|
|
39030
38322
|
try {
|
|
39031
|
-
|
|
38323
|
+
import_node_fs15.default.unlinkSync(tmpPath);
|
|
39032
38324
|
} catch {
|
|
39033
38325
|
}
|
|
39034
38326
|
throw new UploadError("STORAGE_ERROR", `rename failed: ${err.message}`);
|
|
@@ -39552,7 +38844,7 @@ function withCtx(ctx, body) {
|
|
|
39552
38844
|
function streamFile(res, absPath, logger) {
|
|
39553
38845
|
let stat;
|
|
39554
38846
|
try {
|
|
39555
|
-
stat =
|
|
38847
|
+
stat = import_node_fs16.default.statSync(absPath);
|
|
39556
38848
|
} catch (err) {
|
|
39557
38849
|
const code = err?.code;
|
|
39558
38850
|
if (code === "ENOENT") {
|
|
@@ -39575,7 +38867,7 @@ function streamFile(res, absPath, logger) {
|
|
|
39575
38867
|
// 防止浏览器把任意 mime 当 html 渲染
|
|
39576
38868
|
"X-Content-Type-Options": "nosniff"
|
|
39577
38869
|
});
|
|
39578
|
-
const stream =
|
|
38870
|
+
const stream = import_node_fs16.default.createReadStream(absPath);
|
|
39579
38871
|
stream.on("error", (err) => {
|
|
39580
38872
|
logger?.warn("streamFile read error", { absPath, err: err.message });
|
|
39581
38873
|
res.destroy();
|
|
@@ -39584,7 +38876,7 @@ function streamFile(res, absPath, logger) {
|
|
|
39584
38876
|
}
|
|
39585
38877
|
|
|
39586
38878
|
// src/attachment/gc.ts
|
|
39587
|
-
var
|
|
38879
|
+
var import_node_fs17 = __toESM(require("fs"), 1);
|
|
39588
38880
|
var import_node_path19 = __toESM(require("path"), 1);
|
|
39589
38881
|
var DEFAULT_TTL_MS = 30 * 24 * 3600 * 1e3;
|
|
39590
38882
|
function runAttachmentGc(args) {
|
|
@@ -39607,7 +38899,7 @@ function runAttachmentGc(args) {
|
|
|
39607
38899
|
const attRoot = import_node_path19.default.join(sessionDir, ".attachments");
|
|
39608
38900
|
let hashDirs;
|
|
39609
38901
|
try {
|
|
39610
|
-
hashDirs =
|
|
38902
|
+
hashDirs = import_node_fs17.default.readdirSync(attRoot);
|
|
39611
38903
|
} catch (err) {
|
|
39612
38904
|
if (err.code === "ENOENT") continue;
|
|
39613
38905
|
args.logger?.warn("attachment gc: readdir failed", { attRoot, err: err.message });
|
|
@@ -39617,7 +38909,7 @@ function runAttachmentGc(args) {
|
|
|
39617
38909
|
const hashDirAbs = import_node_path19.default.join(attRoot, hashDir);
|
|
39618
38910
|
let files;
|
|
39619
38911
|
try {
|
|
39620
|
-
files =
|
|
38912
|
+
files = import_node_fs17.default.readdirSync(hashDirAbs);
|
|
39621
38913
|
} catch {
|
|
39622
38914
|
continue;
|
|
39623
38915
|
}
|
|
@@ -39625,7 +38917,7 @@ function runAttachmentGc(args) {
|
|
|
39625
38917
|
const file = import_node_path19.default.join(hashDirAbs, name);
|
|
39626
38918
|
let stat;
|
|
39627
38919
|
try {
|
|
39628
|
-
stat =
|
|
38920
|
+
stat = import_node_fs17.default.statSync(file);
|
|
39629
38921
|
} catch {
|
|
39630
38922
|
continue;
|
|
39631
38923
|
}
|
|
@@ -39634,25 +38926,25 @@ function runAttachmentGc(args) {
|
|
|
39634
38926
|
if (age < ttlMs) continue;
|
|
39635
38927
|
if (liveAbs.has(file)) continue;
|
|
39636
38928
|
try {
|
|
39637
|
-
|
|
38929
|
+
import_node_fs17.default.unlinkSync(file);
|
|
39638
38930
|
} catch (err) {
|
|
39639
38931
|
args.logger?.warn("attachment gc: unlink failed", { file, err: err.message });
|
|
39640
38932
|
}
|
|
39641
38933
|
}
|
|
39642
38934
|
try {
|
|
39643
|
-
if (
|
|
38935
|
+
if (import_node_fs17.default.readdirSync(hashDirAbs).length === 0) import_node_fs17.default.rmdirSync(hashDirAbs);
|
|
39644
38936
|
} catch {
|
|
39645
38937
|
}
|
|
39646
38938
|
}
|
|
39647
38939
|
try {
|
|
39648
|
-
if (
|
|
38940
|
+
if (import_node_fs17.default.readdirSync(attRoot).length === 0) import_node_fs17.default.rmdirSync(attRoot);
|
|
39649
38941
|
} catch {
|
|
39650
38942
|
}
|
|
39651
38943
|
}
|
|
39652
38944
|
}
|
|
39653
38945
|
|
|
39654
38946
|
// src/attachment/group.ts
|
|
39655
|
-
var
|
|
38947
|
+
var import_node_fs18 = __toESM(require("fs"), 1);
|
|
39656
38948
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
39657
38949
|
var import_node_crypto6 = __toESM(require("crypto"), 1);
|
|
39658
38950
|
init_protocol();
|
|
@@ -39678,7 +38970,7 @@ var GroupFileStore = class {
|
|
|
39678
38970
|
readFile(scope, sessionId) {
|
|
39679
38971
|
const file = this.filePath(scope, sessionId);
|
|
39680
38972
|
try {
|
|
39681
|
-
const raw =
|
|
38973
|
+
const raw = import_node_fs18.default.readFileSync(file, "utf8");
|
|
39682
38974
|
const parsed = JSON.parse(raw);
|
|
39683
38975
|
if (!Array.isArray(parsed)) {
|
|
39684
38976
|
this.logger?.warn("GroupFileStore.readFile: not an array; resetting session entries", {
|
|
@@ -39704,10 +38996,10 @@ var GroupFileStore = class {
|
|
|
39704
38996
|
}
|
|
39705
38997
|
writeFile(scope, sessionId, entries) {
|
|
39706
38998
|
const file = this.filePath(scope, sessionId);
|
|
39707
|
-
|
|
38999
|
+
import_node_fs18.default.mkdirSync(import_node_path20.default.dirname(file), { recursive: true });
|
|
39708
39000
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
39709
|
-
|
|
39710
|
-
|
|
39001
|
+
import_node_fs18.default.writeFileSync(tmp, JSON.stringify(entries, null, 2), { mode: 384 });
|
|
39002
|
+
import_node_fs18.default.renameSync(tmp, file);
|
|
39711
39003
|
}
|
|
39712
39004
|
/** 拉一份当前 session 的清单。读盘 → cache;之后调用复用 cache */
|
|
39713
39005
|
list(scope, sessionId) {
|
|
@@ -39793,7 +39085,7 @@ var GroupFileStore = class {
|
|
|
39793
39085
|
};
|
|
39794
39086
|
|
|
39795
39087
|
// src/discovery/state-file.ts
|
|
39796
|
-
var
|
|
39088
|
+
var import_node_fs19 = __toESM(require("fs"), 1);
|
|
39797
39089
|
var import_node_path21 = __toESM(require("path"), 1);
|
|
39798
39090
|
function defaultStateFilePath(dataDir) {
|
|
39799
39091
|
return import_node_path21.default.join(dataDir, "state.json");
|
|
@@ -39818,7 +39110,7 @@ var StateFileManager = class {
|
|
|
39818
39110
|
}
|
|
39819
39111
|
read() {
|
|
39820
39112
|
try {
|
|
39821
|
-
const raw =
|
|
39113
|
+
const raw = import_node_fs19.default.readFileSync(this.file, "utf8");
|
|
39822
39114
|
const parsed = JSON.parse(raw);
|
|
39823
39115
|
return parsed;
|
|
39824
39116
|
} catch {
|
|
@@ -39832,33 +39124,41 @@ var StateFileManager = class {
|
|
|
39832
39124
|
return { status: "stale", existing };
|
|
39833
39125
|
}
|
|
39834
39126
|
write(state) {
|
|
39835
|
-
|
|
39127
|
+
import_node_fs19.default.mkdirSync(import_node_path21.default.dirname(this.file), { recursive: true });
|
|
39836
39128
|
const tmp = `${this.file}.tmp.${process.pid}.${Date.now()}`;
|
|
39837
|
-
|
|
39838
|
-
|
|
39129
|
+
import_node_fs19.default.writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 384 });
|
|
39130
|
+
import_node_fs19.default.renameSync(tmp, this.file);
|
|
39839
39131
|
if (process.platform !== "win32") {
|
|
39840
39132
|
try {
|
|
39841
|
-
|
|
39133
|
+
import_node_fs19.default.chmodSync(this.file, 384);
|
|
39842
39134
|
} catch {
|
|
39843
39135
|
}
|
|
39844
39136
|
}
|
|
39845
39137
|
}
|
|
39846
39138
|
delete() {
|
|
39847
39139
|
try {
|
|
39848
|
-
|
|
39140
|
+
import_node_fs19.default.unlinkSync(this.file);
|
|
39849
39141
|
} catch {
|
|
39850
39142
|
}
|
|
39851
39143
|
}
|
|
39852
39144
|
};
|
|
39853
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
|
+
|
|
39854
39154
|
// src/tunnel/tunnel-manager.ts
|
|
39855
|
-
var
|
|
39155
|
+
var import_node_fs23 = __toESM(require("fs"), 1);
|
|
39856
39156
|
var import_node_path25 = __toESM(require("path"), 1);
|
|
39857
39157
|
var import_node_crypto7 = __toESM(require("crypto"), 1);
|
|
39858
|
-
var
|
|
39158
|
+
var import_node_child_process5 = require("child_process");
|
|
39859
39159
|
|
|
39860
39160
|
// src/tunnel/tunnel-store.ts
|
|
39861
|
-
var
|
|
39161
|
+
var import_node_fs20 = __toESM(require("fs"), 1);
|
|
39862
39162
|
var import_node_path22 = __toESM(require("path"), 1);
|
|
39863
39163
|
var TunnelStore = class {
|
|
39864
39164
|
constructor(filePath) {
|
|
@@ -39867,7 +39167,7 @@ var TunnelStore = class {
|
|
|
39867
39167
|
filePath;
|
|
39868
39168
|
async get() {
|
|
39869
39169
|
try {
|
|
39870
|
-
const raw = await
|
|
39170
|
+
const raw = await import_node_fs20.default.promises.readFile(this.filePath, "utf8");
|
|
39871
39171
|
const obj = JSON.parse(raw);
|
|
39872
39172
|
if (!isPersistedTunnel(obj)) return null;
|
|
39873
39173
|
return obj;
|
|
@@ -39879,21 +39179,21 @@ var TunnelStore = class {
|
|
|
39879
39179
|
}
|
|
39880
39180
|
async set(v2) {
|
|
39881
39181
|
const dir = import_node_path22.default.dirname(this.filePath);
|
|
39882
|
-
await
|
|
39182
|
+
await import_node_fs20.default.promises.mkdir(dir, { recursive: true });
|
|
39883
39183
|
const data = JSON.stringify(v2, null, 2);
|
|
39884
39184
|
const tmp = `${this.filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
39885
|
-
await
|
|
39185
|
+
await import_node_fs20.default.promises.writeFile(tmp, data, { mode: 384 });
|
|
39886
39186
|
if (process.platform !== "win32") {
|
|
39887
39187
|
try {
|
|
39888
|
-
await
|
|
39188
|
+
await import_node_fs20.default.promises.chmod(tmp, 384);
|
|
39889
39189
|
} catch {
|
|
39890
39190
|
}
|
|
39891
39191
|
}
|
|
39892
|
-
await
|
|
39192
|
+
await import_node_fs20.default.promises.rename(tmp, this.filePath);
|
|
39893
39193
|
}
|
|
39894
39194
|
async clear() {
|
|
39895
39195
|
try {
|
|
39896
|
-
await
|
|
39196
|
+
await import_node_fs20.default.promises.unlink(this.filePath);
|
|
39897
39197
|
} catch (err) {
|
|
39898
39198
|
const code = err?.code;
|
|
39899
39199
|
if (code !== "ENOENT") throw err;
|
|
@@ -39988,10 +39288,10 @@ function escape(v2) {
|
|
|
39988
39288
|
}
|
|
39989
39289
|
|
|
39990
39290
|
// src/tunnel/frpc-binary.ts
|
|
39991
|
-
var
|
|
39291
|
+
var import_node_fs21 = __toESM(require("fs"), 1);
|
|
39992
39292
|
var import_node_os11 = __toESM(require("os"), 1);
|
|
39993
39293
|
var import_node_path23 = __toESM(require("path"), 1);
|
|
39994
|
-
var
|
|
39294
|
+
var import_node_child_process3 = require("child_process");
|
|
39995
39295
|
var import_node_stream2 = require("stream");
|
|
39996
39296
|
var import_promises3 = require("stream/promises");
|
|
39997
39297
|
var FRPC_VERSION = "0.68.0";
|
|
@@ -40022,7 +39322,7 @@ function frpcDownloadUrl(version2, p2) {
|
|
|
40022
39322
|
}
|
|
40023
39323
|
async function ensureFrpcBinary(opts) {
|
|
40024
39324
|
if (opts.override) {
|
|
40025
|
-
if (!
|
|
39325
|
+
if (!import_node_fs21.default.existsSync(opts.override)) {
|
|
40026
39326
|
throw new Error(`frpc binary not found at override path: ${opts.override}`);
|
|
40027
39327
|
}
|
|
40028
39328
|
return opts.override;
|
|
@@ -40030,10 +39330,10 @@ async function ensureFrpcBinary(opts) {
|
|
|
40030
39330
|
const version2 = opts.version ?? FRPC_VERSION;
|
|
40031
39331
|
const platform = opts.platform ?? detectPlatform();
|
|
40032
39332
|
const binDir = import_node_path23.default.join(opts.dataDir, "bin");
|
|
40033
|
-
|
|
39333
|
+
import_node_fs21.default.mkdirSync(binDir, { recursive: true });
|
|
40034
39334
|
cleanupStaleArtifacts(binDir);
|
|
40035
39335
|
const stableBin = import_node_path23.default.join(binDir, "frpc");
|
|
40036
|
-
if (
|
|
39336
|
+
if (import_node_fs21.default.existsSync(stableBin)) return stableBin;
|
|
40037
39337
|
const partialBin = `${stableBin}.partial`;
|
|
40038
39338
|
const tarballPath = import_node_path23.default.join(binDir, `frp_${version2}_${platform.os}_${platform.arch}.tar.gz.partial`);
|
|
40039
39339
|
try {
|
|
@@ -40044,8 +39344,8 @@ async function ensureFrpcBinary(opts) {
|
|
|
40044
39344
|
} else {
|
|
40045
39345
|
await extractFrpcFromTarball(tarballPath, binDir, version2, platform, partialBin);
|
|
40046
39346
|
}
|
|
40047
|
-
|
|
40048
|
-
|
|
39347
|
+
import_node_fs21.default.chmodSync(partialBin, 493);
|
|
39348
|
+
import_node_fs21.default.renameSync(partialBin, stableBin);
|
|
40049
39349
|
} finally {
|
|
40050
39350
|
safeUnlink(tarballPath);
|
|
40051
39351
|
safeUnlink(partialBin);
|
|
@@ -40055,7 +39355,7 @@ async function ensureFrpcBinary(opts) {
|
|
|
40055
39355
|
function cleanupStaleArtifacts(binDir) {
|
|
40056
39356
|
let entries;
|
|
40057
39357
|
try {
|
|
40058
|
-
entries =
|
|
39358
|
+
entries = import_node_fs21.default.readdirSync(binDir);
|
|
40059
39359
|
} catch {
|
|
40060
39360
|
return;
|
|
40061
39361
|
}
|
|
@@ -40063,7 +39363,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
40063
39363
|
if (name.endsWith(".partial") || name.startsWith("extract-")) {
|
|
40064
39364
|
const full = import_node_path23.default.join(binDir, name);
|
|
40065
39365
|
try {
|
|
40066
|
-
|
|
39366
|
+
import_node_fs21.default.rmSync(full, { recursive: true, force: true });
|
|
40067
39367
|
} catch {
|
|
40068
39368
|
}
|
|
40069
39369
|
}
|
|
@@ -40071,7 +39371,7 @@ function cleanupStaleArtifacts(binDir) {
|
|
|
40071
39371
|
}
|
|
40072
39372
|
function safeUnlink(p2) {
|
|
40073
39373
|
try {
|
|
40074
|
-
|
|
39374
|
+
import_node_fs21.default.unlinkSync(p2);
|
|
40075
39375
|
} catch {
|
|
40076
39376
|
}
|
|
40077
39377
|
}
|
|
@@ -40082,46 +39382,46 @@ async function downloadToFile(url, dest, fetchImpl) {
|
|
|
40082
39382
|
if (!res.ok || !res.body) {
|
|
40083
39383
|
throw new Error(`download failed: ${res.status} ${res.statusText}`);
|
|
40084
39384
|
}
|
|
40085
|
-
const out =
|
|
39385
|
+
const out = import_node_fs21.default.createWriteStream(dest);
|
|
40086
39386
|
const nodeStream = import_node_stream2.Readable.fromWeb(res.body);
|
|
40087
39387
|
await (0, import_promises3.pipeline)(nodeStream, out);
|
|
40088
39388
|
}
|
|
40089
39389
|
async function extractFrpcFromTarball(tarball, binDir, version2, platform, destBin) {
|
|
40090
39390
|
const work = import_node_path23.default.join(binDir, `extract-${process.pid}-${Date.now()}`);
|
|
40091
|
-
|
|
39391
|
+
import_node_fs21.default.mkdirSync(work, { recursive: true });
|
|
40092
39392
|
try {
|
|
40093
39393
|
await new Promise((resolve6, reject) => {
|
|
40094
|
-
const proc = (0,
|
|
39394
|
+
const proc = (0, import_node_child_process3.spawn)("tar", ["xzf", tarball, "-C", work], { stdio: "pipe" });
|
|
40095
39395
|
proc.on("error", reject);
|
|
40096
39396
|
proc.on("exit", (code) => code === 0 ? resolve6() : reject(new Error(`tar exited ${code}`)));
|
|
40097
39397
|
});
|
|
40098
39398
|
const dirName = `frp_${version2}_${platform.os}_${platform.arch}`;
|
|
40099
39399
|
const src = import_node_path23.default.join(work, dirName, "frpc");
|
|
40100
|
-
if (!
|
|
39400
|
+
if (!import_node_fs21.default.existsSync(src)) {
|
|
40101
39401
|
throw new Error(`frpc not found inside tarball at ${src}`);
|
|
40102
39402
|
}
|
|
40103
|
-
|
|
39403
|
+
import_node_fs21.default.copyFileSync(src, destBin);
|
|
40104
39404
|
} finally {
|
|
40105
|
-
|
|
39405
|
+
import_node_fs21.default.rmSync(work, { recursive: true, force: true });
|
|
40106
39406
|
}
|
|
40107
39407
|
}
|
|
40108
39408
|
|
|
40109
39409
|
// src/tunnel/frpc-process.ts
|
|
40110
|
-
var
|
|
39410
|
+
var import_node_fs22 = __toESM(require("fs"), 1);
|
|
40111
39411
|
var import_node_path24 = __toESM(require("path"), 1);
|
|
40112
|
-
var
|
|
39412
|
+
var import_node_child_process4 = require("child_process");
|
|
40113
39413
|
function frpcPidFilePath(dataDir) {
|
|
40114
39414
|
return import_node_path24.default.join(dataDir, "frpc.pid");
|
|
40115
39415
|
}
|
|
40116
39416
|
function writeFrpcPid(dataDir, pid) {
|
|
40117
39417
|
try {
|
|
40118
|
-
|
|
39418
|
+
import_node_fs22.default.writeFileSync(frpcPidFilePath(dataDir), String(pid), { mode: 384 });
|
|
40119
39419
|
} catch {
|
|
40120
39420
|
}
|
|
40121
39421
|
}
|
|
40122
39422
|
function clearFrpcPid(dataDir) {
|
|
40123
39423
|
try {
|
|
40124
|
-
|
|
39424
|
+
import_node_fs22.default.unlinkSync(frpcPidFilePath(dataDir));
|
|
40125
39425
|
} catch {
|
|
40126
39426
|
}
|
|
40127
39427
|
}
|
|
@@ -40137,7 +39437,7 @@ function defaultIsPidAlive(pid) {
|
|
|
40137
39437
|
}
|
|
40138
39438
|
function defaultReadPidFile(file) {
|
|
40139
39439
|
try {
|
|
40140
|
-
return
|
|
39440
|
+
return import_node_fs22.default.readFileSync(file, "utf8");
|
|
40141
39441
|
} catch {
|
|
40142
39442
|
return null;
|
|
40143
39443
|
}
|
|
@@ -40177,7 +39477,7 @@ async function killStaleFrpc(deps) {
|
|
|
40177
39477
|
}
|
|
40178
39478
|
if (victims.size === 0) {
|
|
40179
39479
|
try {
|
|
40180
|
-
|
|
39480
|
+
import_node_fs22.default.unlinkSync(pidFile);
|
|
40181
39481
|
} catch {
|
|
40182
39482
|
}
|
|
40183
39483
|
return;
|
|
@@ -40188,14 +39488,14 @@ async function killStaleFrpc(deps) {
|
|
|
40188
39488
|
}
|
|
40189
39489
|
await sleep(deps.reapWaitMs ?? 300);
|
|
40190
39490
|
try {
|
|
40191
|
-
|
|
39491
|
+
import_node_fs22.default.unlinkSync(pidFile);
|
|
40192
39492
|
} catch {
|
|
40193
39493
|
}
|
|
40194
39494
|
}
|
|
40195
39495
|
async function defaultScanFrpcPidsByCmdline(tomlPath, logger) {
|
|
40196
39496
|
if (process.platform === "win32") return [];
|
|
40197
39497
|
return new Promise((resolve6) => {
|
|
40198
|
-
const ps = (0,
|
|
39498
|
+
const ps = (0, import_node_child_process4.spawn)("ps", ["-axo", "pid=,command="], { stdio: ["ignore", "pipe", "ignore"] });
|
|
40199
39499
|
let buf = "";
|
|
40200
39500
|
ps.stdout.on("data", (c) => {
|
|
40201
39501
|
buf += c.toString();
|
|
@@ -40363,12 +39663,12 @@ var TunnelManager = class {
|
|
|
40363
39663
|
localPort,
|
|
40364
39664
|
logLevel: "info"
|
|
40365
39665
|
});
|
|
40366
|
-
await
|
|
40367
|
-
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], {
|
|
40368
39668
|
stdio: ["ignore", "pipe", "pipe"]
|
|
40369
39669
|
});
|
|
40370
39670
|
const logFilePath = import_node_path25.default.join(this.deps.dataDir, "frpc.log");
|
|
40371
|
-
const logStream =
|
|
39671
|
+
const logStream = import_node_fs23.default.createWriteStream(logFilePath, { flags: "a", mode: 384 });
|
|
40372
39672
|
logStream.on("error", () => {
|
|
40373
39673
|
});
|
|
40374
39674
|
const tee = (chunk) => {
|
|
@@ -40466,7 +39766,7 @@ function deriveStableDeviceKey(opts = {}) {
|
|
|
40466
39766
|
}
|
|
40467
39767
|
|
|
40468
39768
|
// src/auth-store.ts
|
|
40469
|
-
var
|
|
39769
|
+
var import_node_fs24 = __toESM(require("fs"), 1);
|
|
40470
39770
|
var import_node_path27 = __toESM(require("path"), 1);
|
|
40471
39771
|
var import_node_crypto9 = __toESM(require("crypto"), 1);
|
|
40472
39772
|
var AUTH_FILE_NAME = "auth.json";
|
|
@@ -40505,7 +39805,7 @@ function defaultGenerateOwnerPrincipalId() {
|
|
|
40505
39805
|
}
|
|
40506
39806
|
function readAuthFile(file) {
|
|
40507
39807
|
try {
|
|
40508
|
-
const raw =
|
|
39808
|
+
const raw = import_node_fs24.default.readFileSync(file, "utf8");
|
|
40509
39809
|
const parsed = JSON.parse(raw);
|
|
40510
39810
|
if (typeof parsed?.token !== "string" || parsed.token.length === 0) {
|
|
40511
39811
|
return null;
|
|
@@ -40524,16 +39824,16 @@ function readAuthFile(file) {
|
|
|
40524
39824
|
}
|
|
40525
39825
|
}
|
|
40526
39826
|
function writeAuthFile(file, content) {
|
|
40527
|
-
|
|
40528
|
-
|
|
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 });
|
|
40529
39829
|
try {
|
|
40530
|
-
|
|
39830
|
+
import_node_fs24.default.chmodSync(file, 384);
|
|
40531
39831
|
} catch {
|
|
40532
39832
|
}
|
|
40533
39833
|
}
|
|
40534
39834
|
|
|
40535
39835
|
// src/owner-profile.ts
|
|
40536
|
-
var
|
|
39836
|
+
var import_node_fs25 = __toESM(require("fs"), 1);
|
|
40537
39837
|
var import_node_os13 = __toESM(require("os"), 1);
|
|
40538
39838
|
var import_node_path28 = __toESM(require("path"), 1);
|
|
40539
39839
|
var PROFILE_FILENAME = "profile.json";
|
|
@@ -40542,7 +39842,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
40542
39842
|
const profilePath = import_node_path28.default.join(dataDir, PROFILE_FILENAME);
|
|
40543
39843
|
let raw;
|
|
40544
39844
|
try {
|
|
40545
|
-
raw =
|
|
39845
|
+
raw = import_node_fs25.default.readFileSync(profilePath, "utf8");
|
|
40546
39846
|
} catch {
|
|
40547
39847
|
return fallback;
|
|
40548
39848
|
}
|
|
@@ -40565,7 +39865,7 @@ function loadOwnerDisplayName(dataDir) {
|
|
|
40565
39865
|
}
|
|
40566
39866
|
|
|
40567
39867
|
// src/feishu-auth/owner-identity-store.ts
|
|
40568
|
-
var
|
|
39868
|
+
var import_node_fs26 = __toESM(require("fs"), 1);
|
|
40569
39869
|
var import_node_path29 = __toESM(require("path"), 1);
|
|
40570
39870
|
var OWNER_IDENTITY_FILE_NAME = "owner-identity.json";
|
|
40571
39871
|
var OwnerIdentityStore = class {
|
|
@@ -40576,7 +39876,7 @@ var OwnerIdentityStore = class {
|
|
|
40576
39876
|
read() {
|
|
40577
39877
|
let raw;
|
|
40578
39878
|
try {
|
|
40579
|
-
raw =
|
|
39879
|
+
raw = import_node_fs26.default.readFileSync(this.file, "utf8");
|
|
40580
39880
|
} catch {
|
|
40581
39881
|
return null;
|
|
40582
39882
|
}
|
|
@@ -40603,16 +39903,16 @@ var OwnerIdentityStore = class {
|
|
|
40603
39903
|
};
|
|
40604
39904
|
}
|
|
40605
39905
|
write(record) {
|
|
40606
|
-
|
|
40607
|
-
|
|
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 });
|
|
40608
39908
|
try {
|
|
40609
|
-
|
|
39909
|
+
import_node_fs26.default.chmodSync(this.file, 384);
|
|
40610
39910
|
} catch {
|
|
40611
39911
|
}
|
|
40612
39912
|
}
|
|
40613
39913
|
clear() {
|
|
40614
39914
|
try {
|
|
40615
|
-
|
|
39915
|
+
import_node_fs26.default.unlinkSync(this.file);
|
|
40616
39916
|
} catch (err) {
|
|
40617
39917
|
const code = err?.code;
|
|
40618
39918
|
if (code !== "ENOENT") throw err;
|
|
@@ -40875,7 +40175,7 @@ function verifyConnectToken(args) {
|
|
|
40875
40175
|
}
|
|
40876
40176
|
|
|
40877
40177
|
// src/feishu-auth/server-key.ts
|
|
40878
|
-
var
|
|
40178
|
+
var fs35 = __toESM(require("fs"), 1);
|
|
40879
40179
|
var path38 = __toESM(require("path"), 1);
|
|
40880
40180
|
var FILE_NAME2 = "server-signing-key.json";
|
|
40881
40181
|
var ServerKeyStore = class {
|
|
@@ -40889,7 +40189,7 @@ var ServerKeyStore = class {
|
|
|
40889
40189
|
/** 读缓存的公钥;无缓存 / 损坏 → null(调用方决定是否触发拉取) */
|
|
40890
40190
|
read() {
|
|
40891
40191
|
try {
|
|
40892
|
-
const raw =
|
|
40192
|
+
const raw = fs35.readFileSync(this.filePath(), "utf8");
|
|
40893
40193
|
const parsed = JSON.parse(raw);
|
|
40894
40194
|
if (typeof parsed.publicKeyPem === "string" && parsed.publicKeyPem.includes("PUBLIC KEY")) {
|
|
40895
40195
|
return parsed.publicKeyPem;
|
|
@@ -40904,12 +40204,12 @@ var ServerKeyStore = class {
|
|
|
40904
40204
|
publicKeyPem,
|
|
40905
40205
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
40906
40206
|
};
|
|
40907
|
-
|
|
40908
|
-
|
|
40207
|
+
fs35.mkdirSync(this.dataDir, { recursive: true });
|
|
40208
|
+
fs35.writeFileSync(this.filePath(), JSON.stringify(content, null, 2), { mode: 384 });
|
|
40909
40209
|
}
|
|
40910
40210
|
clear() {
|
|
40911
40211
|
try {
|
|
40912
|
-
|
|
40212
|
+
fs35.unlinkSync(this.filePath());
|
|
40913
40213
|
} catch {
|
|
40914
40214
|
}
|
|
40915
40215
|
}
|
|
@@ -40922,12 +40222,12 @@ init_protocol();
|
|
|
40922
40222
|
init_protocol();
|
|
40923
40223
|
|
|
40924
40224
|
// src/session/fork.ts
|
|
40925
|
-
var
|
|
40225
|
+
var import_node_fs27 = __toESM(require("fs"), 1);
|
|
40926
40226
|
var import_node_os14 = __toESM(require("os"), 1);
|
|
40927
40227
|
var import_node_path30 = __toESM(require("path"), 1);
|
|
40928
40228
|
init_claude_history();
|
|
40929
40229
|
function readJsonlEntries(file) {
|
|
40930
|
-
const raw =
|
|
40230
|
+
const raw = import_node_fs27.default.readFileSync(file, "utf8");
|
|
40931
40231
|
const out = [];
|
|
40932
40232
|
for (const line of raw.split("\n")) {
|
|
40933
40233
|
const t = line.trim();
|
|
@@ -40943,7 +40243,7 @@ function forkSession(input) {
|
|
|
40943
40243
|
const baseDir = input.baseDir ?? import_node_path30.default.join(import_node_os14.default.homedir(), ".claude");
|
|
40944
40244
|
const projectDir = import_node_path30.default.join(baseDir, "projects", cwdToHashDir(input.cwd));
|
|
40945
40245
|
const sourceFile = import_node_path30.default.join(projectDir, `${input.toolSessionId}.jsonl`);
|
|
40946
|
-
if (!
|
|
40246
|
+
if (!import_node_fs27.default.existsSync(sourceFile)) {
|
|
40947
40247
|
throw new Error(`fork: source transcript not found: ${sourceFile}`);
|
|
40948
40248
|
}
|
|
40949
40249
|
const entries = readJsonlEntries(sourceFile);
|
|
@@ -40974,8 +40274,8 @@ function forkSession(input) {
|
|
|
40974
40274
|
forkedLines.push(JSON.stringify(forked));
|
|
40975
40275
|
}
|
|
40976
40276
|
const forkedFilePath = import_node_path30.default.join(projectDir, `${forkedToolSessionId}.jsonl`);
|
|
40977
|
-
|
|
40978
|
-
|
|
40277
|
+
import_node_fs27.default.mkdirSync(projectDir, { recursive: true });
|
|
40278
|
+
import_node_fs27.default.writeFileSync(forkedFilePath, forkedLines.join("\n") + "\n", { mode: 384 });
|
|
40979
40279
|
return { forkedToolSessionId, forkedFilePath };
|
|
40980
40280
|
}
|
|
40981
40281
|
|
|
@@ -41165,13 +40465,6 @@ function buildSessionHandlers(deps) {
|
|
|
41165
40465
|
const sessionFile = file;
|
|
41166
40466
|
manager.ensureSession(sessionFile);
|
|
41167
40467
|
const adapter = getAdapter2(sessionFile.tool ?? "claude");
|
|
41168
|
-
const caps = await adapter.capabilities();
|
|
41169
|
-
if (caps.features.observe === false) {
|
|
41170
|
-
throw new ClawdError(
|
|
41171
|
-
ERROR_CODES.TOOL_NOT_SUPPORTED,
|
|
41172
|
-
`tool ${sessionFile.tool ?? "claude"} does not support observe`
|
|
41173
|
-
);
|
|
41174
|
-
}
|
|
41175
40468
|
observer.start({
|
|
41176
40469
|
sessionId: args.sessionId,
|
|
41177
40470
|
cwd: sessionFile.cwd,
|
|
@@ -41421,7 +40714,7 @@ function assertGuestPath(ctx, absPath, personaRoot, method, usersRoot) {
|
|
|
41421
40714
|
}
|
|
41422
40715
|
}
|
|
41423
40716
|
function buildHistoryHandlers(deps) {
|
|
41424
|
-
const { manager, history,
|
|
40717
|
+
const { manager, history, store, personaRoot, usersRoot } = deps;
|
|
41425
40718
|
const projects = async (_frame, _client, ctx) => {
|
|
41426
40719
|
const list2 = await history.listProjects();
|
|
41427
40720
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
@@ -41465,7 +40758,7 @@ function buildHistoryHandlers(deps) {
|
|
|
41465
40758
|
response: { type: "history:read", messages: [], total: 0, offset: 0 }
|
|
41466
40759
|
};
|
|
41467
40760
|
}
|
|
41468
|
-
const res = await
|
|
40761
|
+
const res = await history.read({
|
|
41469
40762
|
cwd: f.cwd,
|
|
41470
40763
|
toolSessionId: f.toolSessionId,
|
|
41471
40764
|
limit: args.limit,
|
|
@@ -41544,7 +40837,7 @@ function assertGuestPath2(ctx, absPath, personaRoot, method, usersRoot) {
|
|
|
41544
40837
|
}
|
|
41545
40838
|
}
|
|
41546
40839
|
function buildWorkspaceHandlers(deps) {
|
|
41547
|
-
const { workspace, skills, agents,
|
|
40840
|
+
const { workspace, skills, agents, personaRoot, personaManager, usersRoot } = deps;
|
|
41548
40841
|
const list = async (frame, _client, ctx) => {
|
|
41549
40842
|
const args = WorkspaceListArgs.parse(frame);
|
|
41550
40843
|
const isGuest = ctx?.principal.kind === "guest";
|
|
@@ -41566,7 +40859,7 @@ function buildWorkspaceHandlers(deps) {
|
|
|
41566
40859
|
const args = SkillsListArgs.parse(frame);
|
|
41567
40860
|
const cwdAbs = path42.resolve(args.cwd);
|
|
41568
40861
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "skills:list", usersRoot);
|
|
41569
|
-
const list2 =
|
|
40862
|
+
const list2 = skills.list(args);
|
|
41570
40863
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
41571
40864
|
const personaId = personaIdFromPath(cwdAbs, personaRoot);
|
|
41572
40865
|
const enabled = personaId ? buildEnabledPluginNames(personaManager, personaId) : /* @__PURE__ */ new Set();
|
|
@@ -41578,9 +40871,6 @@ function buildWorkspaceHandlers(deps) {
|
|
|
41578
40871
|
const args = AgentsListArgs.parse(frame);
|
|
41579
40872
|
const cwdAbs = path42.resolve(args.cwd);
|
|
41580
40873
|
assertGuestPath2(ctx, cwdAbs, personaRoot, "agents:list", usersRoot);
|
|
41581
|
-
if (args.tool === "codex") {
|
|
41582
|
-
return { response: { type: "agents:list", agents: [] } };
|
|
41583
|
-
}
|
|
41584
40874
|
const list2 = agents.list(args);
|
|
41585
40875
|
if (ctx?.principal.kind === "guest" && personaRoot) {
|
|
41586
40876
|
const personaId = personaIdFromPath(cwdAbs, personaRoot);
|
|
@@ -41603,15 +40893,15 @@ init_protocol();
|
|
|
41603
40893
|
init_protocol();
|
|
41604
40894
|
|
|
41605
40895
|
// src/workspace/git.ts
|
|
41606
|
-
var
|
|
41607
|
-
var
|
|
40896
|
+
var import_node_child_process6 = require("child_process");
|
|
40897
|
+
var import_node_fs28 = __toESM(require("fs"), 1);
|
|
41608
40898
|
var import_node_path31 = __toESM(require("path"), 1);
|
|
41609
40899
|
var import_node_util = require("util");
|
|
41610
|
-
var pexec = (0, import_node_util.promisify)(
|
|
40900
|
+
var pexec = (0, import_node_util.promisify)(import_node_child_process6.execFile);
|
|
41611
40901
|
function normalizePath(p2) {
|
|
41612
40902
|
const resolved = import_node_path31.default.resolve(p2);
|
|
41613
40903
|
try {
|
|
41614
|
-
return
|
|
40904
|
+
return import_node_fs28.default.realpathSync(resolved);
|
|
41615
40905
|
} catch {
|
|
41616
40906
|
return resolved;
|
|
41617
40907
|
}
|
|
@@ -42801,22 +42091,22 @@ function pickExtId(frame) {
|
|
|
42801
42091
|
}
|
|
42802
42092
|
return extId;
|
|
42803
42093
|
}
|
|
42804
|
-
function composeState(
|
|
42805
|
-
if (
|
|
42806
|
-
if (manifestMode(
|
|
42094
|
+
function composeState(rec, running, crashed, getPort) {
|
|
42095
|
+
if (rec.state === "invalid") return rec;
|
|
42096
|
+
if (manifestMode(rec.manifest) === "hosted") {
|
|
42807
42097
|
return {
|
|
42808
|
-
...
|
|
42098
|
+
...rec,
|
|
42809
42099
|
state: "running",
|
|
42810
|
-
target: { kind: "hosted", url:
|
|
42100
|
+
target: { kind: "hosted", url: rec.manifest.entry.url }
|
|
42811
42101
|
};
|
|
42812
42102
|
}
|
|
42813
|
-
if (running.has(
|
|
42814
|
-
const port = getPort(
|
|
42815
|
-
if (port == null) return
|
|
42816
|
-
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 } };
|
|
42817
42107
|
}
|
|
42818
|
-
if (crashed.has(
|
|
42819
|
-
return
|
|
42108
|
+
if (crashed.has(rec.extId)) return { ...rec, state: "crashed" };
|
|
42109
|
+
return rec;
|
|
42820
42110
|
}
|
|
42821
42111
|
function buildExtensionHandlers(deps) {
|
|
42822
42112
|
const list = async (_frame, _client, ctx) => {
|
|
@@ -43033,7 +42323,7 @@ function buildExtensionHandlers(deps) {
|
|
|
43033
42323
|
}
|
|
43034
42324
|
|
|
43035
42325
|
// src/app-builder/kill-port.ts
|
|
43036
|
-
var
|
|
42326
|
+
var import_node_child_process7 = require("child_process");
|
|
43037
42327
|
async function killPortOccupants(port, ownedPids, logger) {
|
|
43038
42328
|
let pids;
|
|
43039
42329
|
try {
|
|
@@ -43075,7 +42365,7 @@ async function killPortOccupants(port, ownedPids, logger) {
|
|
|
43075
42365
|
}
|
|
43076
42366
|
function listPidsOnPort(port) {
|
|
43077
42367
|
return new Promise((resolve6, reject) => {
|
|
43078
|
-
(0,
|
|
42368
|
+
(0, import_node_child_process7.execFile)(
|
|
43079
42369
|
"lsof",
|
|
43080
42370
|
["-ti", `:${port}`],
|
|
43081
42371
|
{ timeout: 3e3 },
|
|
@@ -43147,8 +42437,8 @@ var PublishJobRegistry = class {
|
|
|
43147
42437
|
};
|
|
43148
42438
|
|
|
43149
42439
|
// src/app-builder/publish-job-runner.ts
|
|
43150
|
-
var
|
|
43151
|
-
var
|
|
42440
|
+
var import_node_child_process8 = require("child_process");
|
|
42441
|
+
var import_node_fs29 = require("fs");
|
|
43152
42442
|
var import_node_path38 = require("path");
|
|
43153
42443
|
|
|
43154
42444
|
// src/app-builder/publish-stage-parser.ts
|
|
@@ -43176,7 +42466,7 @@ function tailStderrLines(buf, n) {
|
|
|
43176
42466
|
// src/app-builder/publish-job-runner.ts
|
|
43177
42467
|
async function startPublishJob(deps, args) {
|
|
43178
42468
|
const { registry: registry2, projectDir } = deps;
|
|
43179
|
-
const
|
|
42469
|
+
const spawn9 = deps.spawnImpl ?? import_node_child_process8.spawn;
|
|
43180
42470
|
if (registry2.has(args.name)) {
|
|
43181
42471
|
return { jobId: registry2.get(args.name).jobId, status: "already-publishing" };
|
|
43182
42472
|
}
|
|
@@ -43184,11 +42474,11 @@ async function startPublishJob(deps, args) {
|
|
|
43184
42474
|
const logPath = (0, import_node_path38.join)(projDir, ".publish.log");
|
|
43185
42475
|
let logStream = null;
|
|
43186
42476
|
try {
|
|
43187
|
-
logStream = (0,
|
|
42477
|
+
logStream = (0, import_node_fs29.createWriteStream)(logPath, { flags: "w" });
|
|
43188
42478
|
} catch {
|
|
43189
42479
|
logStream = null;
|
|
43190
42480
|
}
|
|
43191
|
-
const child =
|
|
42481
|
+
const child = spawn9("bash", [args.scriptPath, projDir], {
|
|
43192
42482
|
cwd: projDir,
|
|
43193
42483
|
env: process.env,
|
|
43194
42484
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -43442,7 +42732,7 @@ async function recoverInterruptedJobs(deps) {
|
|
|
43442
42732
|
// src/handlers/app-builder.ts
|
|
43443
42733
|
init_protocol();
|
|
43444
42734
|
var import_node_path39 = require("path");
|
|
43445
|
-
var
|
|
42735
|
+
var import_node_fs30 = require("fs");
|
|
43446
42736
|
var APP_BUILDER_PERSONAS = ["persona-app-builder"];
|
|
43447
42737
|
var PUBLISH_SCRIPT_REL = "extension-kit/scripts/publish.sh";
|
|
43448
42738
|
var DEV_SERVER_READY_TIMEOUT_MS = 3e4;
|
|
@@ -43524,7 +42814,7 @@ function buildAppBuilderHandlers(deps) {
|
|
|
43524
42814
|
async function listAllUsersProjects() {
|
|
43525
42815
|
if (!deps.usersRoot || !deps.getStore) return [];
|
|
43526
42816
|
const getStore = deps.getStore;
|
|
43527
|
-
const userIds = await
|
|
42817
|
+
const userIds = await import_node_fs30.promises.readdir(deps.usersRoot).catch(() => []);
|
|
43528
42818
|
const perUser = await Promise.all(
|
|
43529
42819
|
userIds.map((uid) => getStore(uid).list().catch(() => []))
|
|
43530
42820
|
);
|
|
@@ -44064,8 +43354,8 @@ function buildMethodHandlers(deps) {
|
|
|
44064
43354
|
}
|
|
44065
43355
|
|
|
44066
43356
|
// src/app-builder/project-store.ts
|
|
44067
|
-
var
|
|
44068
|
-
var
|
|
43357
|
+
var import_node_fs31 = require("fs");
|
|
43358
|
+
var import_node_child_process9 = require("child_process");
|
|
44069
43359
|
var import_node_path42 = require("path");
|
|
44070
43360
|
init_protocol();
|
|
44071
43361
|
var PROJECTS_DIR = "projects";
|
|
@@ -44093,7 +43383,7 @@ var ProjectStore = class {
|
|
|
44093
43383
|
async list() {
|
|
44094
43384
|
let entries;
|
|
44095
43385
|
try {
|
|
44096
|
-
entries = await
|
|
43386
|
+
entries = await import_node_fs31.promises.readdir(this.projectsRoot());
|
|
44097
43387
|
} catch (err) {
|
|
44098
43388
|
if (err.code === "ENOENT") return [];
|
|
44099
43389
|
throw err;
|
|
@@ -44101,7 +43391,7 @@ var ProjectStore = class {
|
|
|
44101
43391
|
const out = [];
|
|
44102
43392
|
for (const name of entries) {
|
|
44103
43393
|
try {
|
|
44104
|
-
const raw = await
|
|
43394
|
+
const raw = await import_node_fs31.promises.readFile(this.metaPath(name), "utf8");
|
|
44105
43395
|
const json = JSON.parse(raw);
|
|
44106
43396
|
let migrated = false;
|
|
44107
43397
|
if (typeof json.devCommand !== "string" || json.devCommand.length === 0) {
|
|
@@ -44112,7 +43402,7 @@ var ProjectStore = class {
|
|
|
44112
43402
|
if (parsed.success) {
|
|
44113
43403
|
out.push(parsed.data);
|
|
44114
43404
|
if (migrated) {
|
|
44115
|
-
void
|
|
43405
|
+
void import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(parsed.data, null, 2) + "\n", "utf8").catch(() => {
|
|
44116
43406
|
});
|
|
44117
43407
|
}
|
|
44118
43408
|
}
|
|
@@ -44156,8 +43446,8 @@ var ProjectStore = class {
|
|
|
44156
43446
|
throw new Error(`invalid name "${name}": ${validated.error.message}`);
|
|
44157
43447
|
}
|
|
44158
43448
|
const dir = this.projectDir(name);
|
|
44159
|
-
await
|
|
44160
|
-
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");
|
|
44161
43451
|
return meta;
|
|
44162
43452
|
}
|
|
44163
43453
|
/**
|
|
@@ -44172,7 +43462,7 @@ var ProjectStore = class {
|
|
|
44172
43462
|
const scriptPath = (0, import_node_path42.join)(personaRoot, SCAFFOLD_SCRIPT_REL);
|
|
44173
43463
|
const destDir = this.projectDir(name);
|
|
44174
43464
|
return await new Promise((resolve6, reject) => {
|
|
44175
|
-
const child = (0,
|
|
43465
|
+
const child = (0, import_node_child_process9.spawn)("bash", [scriptPath, name, template, destDir], {
|
|
44176
43466
|
cwd: personaRoot,
|
|
44177
43467
|
env: { ...process.env, PATH: process.env.PATH ?? "" },
|
|
44178
43468
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -44202,7 +43492,7 @@ var ProjectStore = class {
|
|
|
44202
43492
|
}
|
|
44203
43493
|
async delete(name) {
|
|
44204
43494
|
const dir = this.projectDir(name);
|
|
44205
|
-
await
|
|
43495
|
+
await import_node_fs31.promises.rm(dir, { recursive: true, force: true });
|
|
44206
43496
|
}
|
|
44207
43497
|
async updatePort(name, newPort) {
|
|
44208
43498
|
if (newPort < PROJECT_PORT_MIN || newPort > PROJECT_PORT_MAX) {
|
|
@@ -44218,7 +43508,7 @@ var ProjectStore = class {
|
|
|
44218
43508
|
throw new Error(`port ${newPort} already used / \u5DF2\u88AB project "${conflict.name}" \u5360\u7528`);
|
|
44219
43509
|
}
|
|
44220
43510
|
const updated = { ...target, port: newPort };
|
|
44221
|
-
await
|
|
43511
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
44222
43512
|
return updated;
|
|
44223
43513
|
}
|
|
44224
43514
|
/**
|
|
@@ -44235,7 +43525,7 @@ var ProjectStore = class {
|
|
|
44235
43525
|
if (!validated.success) {
|
|
44236
43526
|
throw new Error(`invalid prodUrl "${url}": ${validated.error.message}`);
|
|
44237
43527
|
}
|
|
44238
|
-
await
|
|
43528
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44239
43529
|
return validated.data;
|
|
44240
43530
|
}
|
|
44241
43531
|
/**
|
|
@@ -44256,7 +43546,7 @@ var ProjectStore = class {
|
|
|
44256
43546
|
if (!validated.success) {
|
|
44257
43547
|
throw new Error(`invalid publishJob: ${validated.error.message}`);
|
|
44258
43548
|
}
|
|
44259
|
-
await
|
|
43549
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44260
43550
|
return validated.data;
|
|
44261
43551
|
}
|
|
44262
43552
|
/** 清掉 .clawd-project.json.publishJob 字段。其他字段保持原样。 */
|
|
@@ -44271,13 +43561,13 @@ var ProjectStore = class {
|
|
|
44271
43561
|
if (!validated.success) {
|
|
44272
43562
|
throw new Error(`failed to clear publishJob: ${validated.error.message}`);
|
|
44273
43563
|
}
|
|
44274
|
-
await
|
|
43564
|
+
await import_node_fs31.promises.writeFile(this.metaPath(name), JSON.stringify(validated.data, null, 2) + "\n", "utf8");
|
|
44275
43565
|
return validated.data;
|
|
44276
43566
|
}
|
|
44277
43567
|
};
|
|
44278
43568
|
|
|
44279
43569
|
// src/app-builder/dev-server-supervisor.ts
|
|
44280
|
-
var
|
|
43570
|
+
var import_node_child_process10 = require("child_process");
|
|
44281
43571
|
var import_node_events2 = require("events");
|
|
44282
43572
|
var DEFAULT_READY_PATTERN = /Local:\s+https?:\/\/|Nest application successfully started|server listening on/i;
|
|
44283
43573
|
var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
@@ -44314,7 +43604,7 @@ var DevServerSupervisor = class extends import_node_events2.EventEmitter {
|
|
|
44314
43604
|
tunnelHost: args.tunnelHost,
|
|
44315
43605
|
devCommand: cmd
|
|
44316
43606
|
});
|
|
44317
|
-
const child = (0,
|
|
43607
|
+
const child = (0, import_node_child_process10.spawn)("sh", ["-c", cmd], {
|
|
44318
43608
|
cwd: args.cwd,
|
|
44319
43609
|
env,
|
|
44320
43610
|
stdio: "pipe",
|
|
@@ -44706,7 +43996,7 @@ function computeGrantForFrame(method, frame) {
|
|
|
44706
43996
|
}
|
|
44707
43997
|
|
|
44708
43998
|
// src/extension/runtime.ts
|
|
44709
|
-
var
|
|
43999
|
+
var import_node_child_process11 = require("child_process");
|
|
44710
44000
|
var import_node_path43 = __toESM(require("path"), 1);
|
|
44711
44001
|
var import_promises10 = require("timers/promises");
|
|
44712
44002
|
|
|
@@ -44793,17 +44083,17 @@ var Runtime = class {
|
|
|
44793
44083
|
const existing = this.handles.get(extId);
|
|
44794
44084
|
if (existing) return { kind: "local", port: existing.port };
|
|
44795
44085
|
const records = await loadAll(this.root);
|
|
44796
|
-
const
|
|
44797
|
-
if (!
|
|
44798
|
-
if (
|
|
44799
|
-
throw new RuntimeError("INVALID_MANIFEST",
|
|
44800
|
-
if (manifestMode(
|
|
44801
|
-
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 };
|
|
44802
44092
|
}
|
|
44803
44093
|
const port = await this.allocator.allocate().catch(() => {
|
|
44804
44094
|
throw new RuntimeError("PORT_EXHAUSTED", "no free port in configured range");
|
|
44805
44095
|
});
|
|
44806
|
-
const startCommand =
|
|
44096
|
+
const startCommand = rec.manifest.runtime.startCommand;
|
|
44807
44097
|
const cmd = startCommand.replace(
|
|
44808
44098
|
/\$CLAWOS_EXT_PORT/g,
|
|
44809
44099
|
String(port)
|
|
@@ -44814,7 +44104,7 @@ var Runtime = class {
|
|
|
44814
44104
|
CLAWOS_EXT_PORT: String(port),
|
|
44815
44105
|
CLAWOS_EXT_ID: extId
|
|
44816
44106
|
};
|
|
44817
|
-
const child = (0,
|
|
44107
|
+
const child = (0, import_node_child_process11.spawn)("sh", ["-c", cmd], {
|
|
44818
44108
|
cwd: dir,
|
|
44819
44109
|
env,
|
|
44820
44110
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -45250,7 +44540,7 @@ async function startDaemon(config) {
|
|
|
45250
44540
|
const absPath = import_node_path46.default.isAbsolute(input.relPath) ? input.relPath : import_node_path46.default.join(input.cwd, input.relPath);
|
|
45251
44541
|
let size = 0;
|
|
45252
44542
|
try {
|
|
45253
|
-
size =
|
|
44543
|
+
size = import_node_fs32.default.statSync(absPath).size;
|
|
45254
44544
|
} catch (err) {
|
|
45255
44545
|
logger.warn("attachment.onFileEdit stat failed", {
|
|
45256
44546
|
sessionId: input.sessionId,
|
|
@@ -45320,7 +44610,6 @@ async function startDaemon(config) {
|
|
|
45320
44610
|
onReady: (tsid) => manager.dispatchReadyDetected(tsid)
|
|
45321
44611
|
}) : new ClaudeAdapter({ logger, historyReader: new ClaudeHistoryReader() });
|
|
45322
44612
|
registerAdapter("claude", claudeAdapter);
|
|
45323
|
-
registerAdapter("codex", new CodexAdapter({ logger, historyReader: new CodexHistoryReader() }));
|
|
45324
44613
|
const personaRegistry = new PersonaRegistry(personaStore);
|
|
45325
44614
|
const personaManager = new PersonaManager({
|
|
45326
44615
|
store: personaStore,
|
|
@@ -45399,11 +44688,7 @@ async function startDaemon(config) {
|
|
|
45399
44688
|
workspace,
|
|
45400
44689
|
skills,
|
|
45401
44690
|
agents,
|
|
45402
|
-
// skills:list 按 tool 路由:codex → app-server skills/list;缺省 claude → SkillsScanner(同步包成 Promise)。
|
|
45403
|
-
getSkillsForTool: (tool, cwd) => tool === "codex" ? listCodexSkills(cwd) : Promise.resolve(skills.list({ cwd })),
|
|
45404
44691
|
history,
|
|
45405
|
-
// history:read 按 session.tool 路由:codex → adapter.historyReader(CodexHistoryReader);缺省 claude。
|
|
45406
|
-
getHistoryReader: (tool) => getAdapter(tool).historyReader ?? history,
|
|
45407
44692
|
observer,
|
|
45408
44693
|
getAdapter,
|
|
45409
44694
|
store,
|
|
@@ -45742,7 +45027,8 @@ async function startDaemon(config) {
|
|
|
45742
45027
|
protocolVersion: PROTOCOL_VERSION,
|
|
45743
45028
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
45744
45029
|
authMode,
|
|
45745
|
-
authToken: resolvedAuthToken ?? void 0
|
|
45030
|
+
authToken: resolvedAuthToken ?? void 0,
|
|
45031
|
+
source: readDaemonSourceFromEnv()
|
|
45746
45032
|
};
|
|
45747
45033
|
stateMgr.write(stateSnapshot);
|
|
45748
45034
|
process.stdout.write(`Ready: ${url}
|
|
@@ -45793,7 +45079,7 @@ ${bar}
|
|
|
45793
45079
|
`);
|
|
45794
45080
|
try {
|
|
45795
45081
|
const connectPath = import_node_path46.default.join(config.dataDir, "connect.txt");
|
|
45796
|
-
|
|
45082
|
+
import_node_fs32.default.writeFileSync(connectPath, lines.join("\n") + "\n", { mode: 384 });
|
|
45797
45083
|
} catch {
|
|
45798
45084
|
}
|
|
45799
45085
|
} catch (err) {
|
|
@@ -45866,7 +45152,7 @@ ${bar}
|
|
|
45866
45152
|
function migrateDropPersonsDir(dataDir) {
|
|
45867
45153
|
const dir = import_node_path46.default.join(dataDir, "persons");
|
|
45868
45154
|
try {
|
|
45869
|
-
|
|
45155
|
+
import_node_fs32.default.rmSync(dir, { recursive: true, force: true });
|
|
45870
45156
|
} catch {
|
|
45871
45157
|
}
|
|
45872
45158
|
}
|